-
Notifications
You must be signed in to change notification settings - Fork 1
Fix: Resolve multi-user write permission issues in Samba server #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,4 +54,20 @@ while IFS=':' read -r username password; do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done < <(grep -E '^[^#\[].*:.*' /etc/samba/users.conf) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Set proper ownership for each user's directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Setting proper ownership for user directories..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while read -r line; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Look for share section headers [sharename] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ $line =~ ^\[([^]]+)\]$ ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| share_name="${BASH_REMATCH[1]}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| share_dir="/mount/storage/$share_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -d "$share_dir" ] && id "$share_name" &>/dev/null; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -d "$share_dir" ] && id "$share_name" &>/dev/null; then | |
| # Only set ownership if share_name is in the created users list | |
| if [ -d "$share_dir" ] && grep -qx "$share_name" "$created_users_tmp"; then |
Copilot
AI
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern assumes share names in brackets correspond to usernames, but this may not always be true in Samba configurations. Share names and usernames can be different. Consider verifying that the share_name is actually a valid user before proceeding.
| while read -r line; do | |
| # Look for share section headers [sharename] | |
| if [[ $line =~ ^\[([^]]+)\]$ ]]; then | |
| share_name="${BASH_REMATCH[1]}" | |
| share_dir="/mount/storage/$share_name" | |
| if [ -d "$share_dir" ] && id "$share_name" &>/dev/null; then | |
| echo "Setting ownership for $share_dir to $share_name:$share_name" | |
| chown -R "$share_name:$share_name" "$share_dir" | |
| chmod -R 775 "$share_dir" | |
| fi | |
| fi | |
| done < /etc/samba/users.conf | |
| # Parse users.conf to map shares to valid users and set ownership accordingly | |
| current_share="" | |
| valid_user="" | |
| while IFS= read -r line; do | |
| # Look for share section headers [sharename] | |
| if [[ $line =~ ^\[([^]]+)\]$ ]]; then | |
| # If we have a previous share and valid user, set ownership | |
| if [[ -n "$current_share" && -n "$valid_user" ]]; then | |
| share_dir="/mount/storage/$current_share" | |
| if [ -d "$share_dir" ] && id "$valid_user" &>/dev/null; then | |
| echo "Setting ownership for $share_dir to $valid_user:$valid_user" | |
| chown -R "$valid_user:$valid_user" "$share_dir" | |
| chmod -R 775 "$share_dir" | |
| fi | |
| fi | |
| current_share="${BASH_REMATCH[1]}" | |
| valid_user="" | |
| elif [[ $line =~ ^[[:space:]]*valid[[:space:]]+users[[:space:]]*=[[:space:]]*([^[:space:]]+) ]]; then | |
| # Extract the first username from the valid users line | |
| valid_user="${BASH_REMATCH[1]}" | |
| fi | |
| done < /etc/samba/users.conf | |
| # After the loop, handle the last share section | |
| if [[ -n "$current_share" && -n "$valid_user" ]]; then | |
| share_dir="/mount/storage/$current_share" | |
| if [ -d "$share_dir" ] && id "$valid_user" &>/dev/null; then | |
| echo "Setting ownership for $share_dir to $valid_user:$valid_user" | |
| chown -R "$valid_user:$valid_user" "$share_dir" | |
| chmod -R 775 "$share_dir" | |
| fi | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The while loop reads from /etc/samba/users.conf without proper error handling. If the file doesn't exist or is empty, the loop will fail silently. Consider adding a check to ensure the file exists before processing.