Skip to content

Commit

Permalink
fix: Fix issue with user.conf (#31)
Browse files Browse the repository at this point in the history
1.Previously, when using read, if the last line did not have a newline character, it would not be read. An additional check has been added to separately determine if the last line has an end-of-file character, ensuring that all content is correctly read.
2.A different method has been used to split the content by : to improve stability.
  • Loading branch information
HanLiQL authored Jan 13, 2025
1 parent 8ed9e45 commit 17f13d6
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,13 @@ fi
# Check if multi-user mode is enabled
if [ -f "$users" ] && [ -s "$users" ]; then

while read -r line; do
while IFS= read -r line || [[ -n ${line} ]]; do

# Skip lines that are comments or empty
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue

# Split each line by colon and assign to variables
username=$(echo "$line" | cut -d':' -f1)
uid=$(echo "$line" | cut -d':' -f2)
groupname=$(echo "$line" | cut -d':' -f3)
gid=$(echo "$line" | cut -d':' -f4)
password=$(echo "$line" | cut -d':' -f5)
IFS=':' read -r username uid groupname gid password <<< "$line"

# Check if all required fields are present
if [[ -z "$username" || -z "$uid" || -z "$groupname" || -z "$gid" || -z "$password" ]]; then
Expand Down

0 comments on commit 17f13d6

Please sign in to comment.