smbd: stat path before calling openat_pathref_fsp() in smbd_dirptr_get_entry()
authorRalph Boehme <slow@samba.org>
Mon, 1 Feb 2021 11:09:39 +0000 (12:09 +0100)
committerKarolin Seeger <kseeger@samba.org>
Thu, 10 Jun 2021 09:31:12 +0000 (09:31 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14730

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 87e97e1b519159b5f4c5ed4ef684783855e79ac3)

source3/smbd/dir.c

index f562cda6beefa8d727f207a79cdd9a53e2300710..dc53fc0b30d2f0d6c0ed4be54622d6ed3635eafb 100644 (file)
@@ -793,6 +793,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
        const char *dpath = dirptr->smb_dname->base_name;
        bool dirptr_path_is_dot = ISDOT(dpath);
        NTSTATUS status;
+       int ret;
 
        *_smb_fname = NULL;
        *_mode = 0;
@@ -887,11 +888,27 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                        return false;
                }
 
+               if (!VALID_STAT(smb_fname->st)) {
+                       /*
+                        * If stat() fails with ENOENT it might be a
+                        * msdfs-symlink in Windows context, this is checked
+                        * below, for now we just want to fill stat info as good
+                        * as we can.
+                        */
+                       ret = vfs_stat(conn, smb_fname);
+                       if (ret != 0 && errno != ENOENT) {
+                               TALLOC_FREE(smb_fname);
+                               TALLOC_FREE(dname);
+                               TALLOC_FREE(fname);
+                               continue;
+                       }
+               }
+
                /* Create smb_fname with NULL stream_name. */
                atname = synthetic_smb_fname(talloc_tos(),
                                             dname,
                                             NULL,
-                                            &sbuf,
+                                            &smb_fname->st,
                                             dirptr->smb_dname->twrp,
                                             dirptr->smb_dname->flags);
                if (atname == NULL) {