smbd: let unix_convert() fail early if initial stat fails with EACCES
authorRalph Boehme <slow@samba.org>
Wed, 22 Apr 2020 13:13:04 +0000 (15:13 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 22 Apr 2020 21:08:39 +0000 (21:08 +0000)
Doing directory scans on the path components is not going to change this, so
give up early. No change in behaviour, as we would just fail later in
get_real_filename() otherwise.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Apr 22 21:08:39 UTC 2020 on sn-devel-184

source3/smbd/filename.c

index 9faff9da45afc237c2f92cd72880a060c2da5f00..8030e50431720a6899d6cf4510411b9ff612cc75 100644 (file)
@@ -700,6 +700,18 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                /* Stat failed - ensure we don't use it. */
                SET_STAT_INVALID(smb_fname->st);
 
+               if (errno == EACCES) {
+                       /*
+                        * Early exit on access denied. Walking
+                        * the path won't fix that.
+                        */
+                       DBG_DEBUG("stat [%s]: %s\n",
+                                 smb_fname_str_dbg(smb_fname),
+                                 strerror(errno));
+                       status = NT_STATUS_ACCESS_DENIED;
+                       goto fail;
+               }
+
                if (errno == ENOENT) {
                        /* Optimization when creating a new file - only
                           the last component doesn't exist.