Skip to content

Commit

Permalink
fix: Issues with users.conf (#34)
Browse files Browse the repository at this point in the history
* fix: Add compatibility for CRLF-formatted users.conf files

1.Previously, when processing users.conf files in CRLF format, the Bash script treated the '\r' at the end of lines as part of the password. This caused incorrect passwords and login failures.
2.This issue has now been fixed by removing all '\r' characters, enhancing compatibility.
3.It is still recommended to use LF format for both smb.conf and users.conf files.

* fix: Fixed the bug where the user would be re-added after a restart.

1.Use pdb_output to first capture the result of pdbedit -s "$cfg" -L, and then check if the user exists in the output. Without this step, the first user loaded may be incorrectly identified as not existing, causing it to be re-added and triggering the log output: "User $username has been added to Samba and password set."
  • Loading branch information
HanLiQL authored Jan 20, 2025
1 parent 17f13d6 commit 3661aef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ add_user() {
fi

# Check if the user is a samba user
if pdbedit -s "$cfg" -L | grep -q "^$username:"; then
pdb_output=$(pdbedit -s "$cfg" -L) #Do not combine the two commands into one, as this could lead to issues with the execution order and proper passing of variables.
if echo "$pdb_output" | grep -q "^$username:"; then
# If the user is a samba user, update its password in case it changed
echo -e "$password\n$password" | smbpasswd -c "$cfg" -s "$username" > /dev/null || { echo "Failed to update Samba password for $username"; return 1; }
else
Expand Down Expand Up @@ -126,7 +127,7 @@ if [ -f "$users" ] && [ -s "$users" ]; then
# Call the function with extracted values
add_user "$config" "$username" "$uid" "$groupname" "$gid" "$password" || { echo "Failed to add user $username"; exit 1; }

done < "$users"
done < <(tr -d '\r' < "$users")

else

Expand Down

0 comments on commit 3661aef

Please sign in to comment.