The Samba-Bugzilla – Bug 11440
s3: smbd returned 'Permission denied' after copied a file to the read-only share.
Last modified: 2017-04-21 08:21:05 UTC
When trying to to delete a file on a read-only share it does give the expected 'Read-only file system' error message.
When using a Linux (CentOS 7) or Windows 2008/Cygwin client, 'cp' gives 'Permission denied' when trying to write to a read-only share.
The error message is slightly misleading in this case, as it would make the user think that there is a file (directory) permission issue, when in fact, it is a file-system level access issue.
It looks like Samba checks the requested access mask against the share access mask through source3/smbd/open.c::smbd_calculate_access_mask(). It will return NT_STATUS_ACCESS_DENIED, which is mapped to EPERM. It doesn't differentiate whether it is a WRITE on a read-only or any other access mask denied error.
(In reply to Warren from comment #0)
> When trying to to delete a file on a read-only share it does give the
> expected 'Read-only file system' error message.
> When using a Linux (CentOS 7) or Windows 2008/Cygwin client, 'cp' gives
> 'Permission denied' when trying to write to a read-only share.
Whilst the second statement (regarding writing) is correct, unfortunately Warren was provided with unclear test results when filing this bug, and as a result the first statement (regarding delete) is somewhat misleading, as it doesn't explain what client was being used, and in fact it seems to only apply to a limited set of clients.
When attempting to delete a file from a read-only share served by Samba 4.1.12, some CentOS 6 systems will report "Read-only file system" as stated above, but others will report "Permission denied". It appears that it doesn't matter whether or not the cifs-utils package is installed.
"Permission denied" is also reported when running 'rm' using Cygwin on Windows Server 2008.
When using smbclient 3.6.23-36.el6_8 (from CentOS 6), this output is seen:
smb: \> del test
NT_STATUS_MEDIA_WRITE_PROTECTED deleting remote file \test
NT_STATUS_MEDIA_WRITE_PROTECTED listing \test
It could be imagined that that could be mapped to "Read-only file system" rather than simply "Permission denied".
It appears that the Linux kernel in CentOS 6, smbclient and Windows Server 2008 each use a different way of deleting files, which is probably why different error messages are returned in different cases.