smbd: expect valid stat info in openat_pathref_fsp()
authorRalph Boehme <slow@samba.org>
Mon, 1 Feb 2021 09:17:13 +0000 (10:17 +0100)
committerKarolin Seeger <kseeger@samba.org>
Thu, 10 Jun 2021 09:31:12 +0000 (09:31 +0000)
We're never creating files here, so instead of waiting for the underlying open()
to return ENOENT, just check that we have valid stat info, expecting all callers
to have called SMB_VFS_[L]STAT() on the smb_fname.

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 48bc561d1a8bb5ce99663b58a2e5e9aa344af96a)

source3/smbd/files.c

index 02442a962ed69cc997504947dd1ac76f0c22309c..ee1afece33f24d8a313eec322891b5e3e1fe92f4 100644 (file)
@@ -441,7 +441,6 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
 {
        connection_struct *conn = dirfsp->conn;
        struct smb_filename *full_fname = NULL;
-       bool file_existed = VALID_STAT(smb_fname->st);
        struct files_struct *fsp = NULL;
        int open_flags = O_RDONLY;
        NTSTATUS status;
@@ -455,7 +454,11 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                return NT_STATUS_OK;
        }
 
-       if (file_existed && S_ISLNK(smb_fname->st.st_ex_mode)) {
+       if (!VALID_STAT(smb_fname->st)) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
+       if (S_ISLNK(smb_fname->st.st_ex_mode)) {
                return NT_STATUS_STOPPED_ON_SYMLINK;
        }
 
@@ -540,9 +543,7 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
-       if (file_existed &&
-           !check_same_dev_ino(&smb_fname->st, &fsp->fsp_name->st))
-       {
+       if (!check_same_dev_ino(&smb_fname->st, &fsp->fsp_name->st)) {
                DBG_DEBUG("file [%s] - dev/ino mismatch. "
                          "Old (dev=%ju, ino=%ju). "
                          "New (dev=%ju, ino=%ju).\n",