dosmode: retry reading dos attributes as root for unreadable files
authorBjörn Jacke <bj@sernet.de>
Thu, 4 Mar 2021 18:37:37 +0000 (19:37 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 24 Mar 2021 20:31:30 +0000 (20:31 +0000)
if there are files that the user can't access, he is still allowed to read the
dos attributes information, so we need to try reading them as root also.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14654

Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/dosmode.c

index 15676e008510a6aeecb45abc59764a1b52dee3bb..aaa0924cb9dbb70a97a9c6a7330b926cd8d3adfb 100644 (file)
@@ -382,6 +382,19 @@ NTSTATUS fget_ea_dos_attribute(struct files_struct *fsp,
                                    SAMBA_XATTR_DOS_ATTRIB,
                                    attrstr,
                                    sizeof(attrstr));
+       if (sizeret == -1 && ( errno == EPERM || errno == EACCES )) {
+               /* we may also retrieve dos attribs for unreadable files, this
+                  is why we'll retry as root. We don't use root in the first
+                  run because in cases like NFS, root might have even less
+                  rights than the real user
+               */
+               become_root();
+               sizeret = SMB_VFS_FGETXATTR(fsp->base_fsp ? fsp->base_fsp : fsp,
+                                           SAMBA_XATTR_DOS_ATTRIB,
+                                           attrstr,
+                                           sizeof(attrstr));
+               unbecome_root();
+       }
        if (sizeret == -1) {
                DBG_INFO("Cannot get attribute "
                         "from EA on file %s: Error = %s\n",