Duplicate Share Definition Silently Overrides the Samba Config
fileserv runs RHEL 8 with Samba 4.13 in standalone mode (security = user, tdbsam backend). The share [projects] must be read-write for the local group devs (GID 10001). /srv/projects is owned root:devs with mode 2775; SELinux is enforcing, the tree carries the samba_share_t label with a persistent rule, and getsebool shows samba_export_all_rw off, which has never mattered before.
Users in devs can browse the share and open files, but saving returns "Access is denied". The main /etc/samba/smb.conf defines the share with read only = no, valid users = @devs and create mask = 0660. Near the end of smb.conf there is a line include = /etc/samba/conf.d/*.conf, a directory introduced years ago by a contractor. Samba's log at level 1 contains no errors.
smbclient //localhost/projects -U alice connects, ls lists files, but put fails with NT_STATUS_ACCESS_DENIED. getfacl /srv/projects shows rwxrwxr-x for root:devs with no ACL entries. Disk space and inodes are fine.
1. testparm reports the share twice with conflicting values. Explain why that changes behaviour, how you determine which definition wins, and what you would change.
Read the worked answer
smb.conf is parsed top to bottom and include is a textual expansion at the point where it appears, with globs expanded in alphabetical order. When the same section name appears a second time, Samba does not create a second share: the parameters are merged into the existing service, and for any parameter given twice the last value read wins. So a leftover file matched by /etc/samba/conf.d/*.conf that redefines [projects] with read only = yes silently overrides the read only = no earlier in the main file. Nothing is logged at level 1 because the resulting configuration is perfectly valid - it is simply not what the author of smb.conf intended.
How to pin it down:
testparm -sprints the merged effective configuration; look at the[projects]block and noteread only = Yesor a differentvalid users.grep -rn '\[projects\]' /etc/samba/lists every definition, andgrep -rn include /etc/samba/smb.confshows where the glob is expanded.testparm -vshows defaults as well, so you can see parameters nobody set explicitly.
Fix by deleting or renaming the stale file (for example to 90-legacy.conf.disabled, which the glob no longer matches), or by removing only its duplicate section. Re-run testparm -s to confirm a single, correct definition, then systemctl reload smb - a reload affects new connections while existing sessions keep their old parameters, so have alice reconnect before retesting. Then repeat the smbclient ... -c 'put /etc/hostname test.txt' check.
2. Writing now works, but files alice creates land as mode 0600 and colleagues in devs cannot edit them. Which Samba parameters control this, and what exactly would you set?
Read the worked answer
Two different mechanisms are at work and they are easy to confuse. create mask / directory mask are ANDed with the permissions the client asks for - they can only remove bits. force create mode / force directory mode are ORed in afterwards - they add bits regardless of what the client requested. A create mask = 0660 therefore does not produce group-writable files when the Windows client requests 0644: the AND yields 0640 and the group write bit is gone.
For a shared group directory, set on the [projects] share:
create mask = 0660
force create mode = 0660
directory mask = 2770
force directory mode = 2770
force group = devs
The 2 in 2770 sets the setgid bit so new subdirectories inherit the devs group. If you would rather have everything mirror the parent directory, inherit permissions = yes is the alternative: it takes mode and group from the parent and makes the mask parameters irrelevant - do not mix the two approaches without deciding which one owns the policy.
Expect files to sometimes show 0740 or 0770 rather than 0660. That is map archive = yes (the default), which maps the DOS archive attribute onto the owner execute bit. store dos attributes = yes turns that mapping off and is the usual choice for POSIX-consistent permissions. The Linux umask is not involved for share files, because Samba applies these masks itself.
Verify with smbclient //localhost/projects -U alice -c 'put /etc/hostname t.txt', then getfacl /srv/projects/t.txt as root, and have a second member of devs edit the file.
3. One subdirectory under /srv/projects still denies writes for the same users even after the configuration is corrected. What would you check, in order?
Read the worked answer
Since the parent works and one subtree does not, the difference is almost certainly metadata on that subtree rather than share configuration.
- SELinux label.
ls -Zd /srv/projects/problemdirshould showsamba_share_t. A directory created from an unpacked tarball, an rsync run as root, or a copy from /home commonly inheritsdefault_t,user_home_toradmin_home_t.semanage fcontextrules only apply when a relabel runs, sorestorecon -Rv /srv/projectsfixes it. Confirm the denial withausearch -m AVC -ts recentorjournalctl -t setroubleshoot; an AVC naming smbd and that path settles it. - POSIX ACL mask.
getfaclon the directory shows an effectivemask::line; if a default ACL was applied to the subtree, the mask can strip group write even though the group entry says rwx. Fix withsetfacl -m m::rwxor by removing the stray default ACL. - Ownership and mode. A subdirectory owned by root with mode 0755 blocks writes for everyone in devs regardless of Samba settings; compare
statoutput against the working parent. - Whether the client is still on an old session.
smbstatusshows the connection's share parameters; a session opened before the reload keeps the old ones, so have the user disconnect and remap.
Also check mount options for a bind mount under the share, and whether the subtree is on a filesystem mounted ro. Fix the label or ACL, relabel, and retest with smbclient before telling the user.