]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
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)
committerRalph Boehme <slow@samba.org>
Fri, 5 Feb 2021 06:22:35 +0000 (06:22 +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.

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

index 40af56402e42eed8ad637f1799b1f306b92259a9..8d7ecabe2851e5b2d8c70b378129fbb15c5d52a2 100644 (file)
@@ -438,7 +438,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;
@@ -452,7 +451,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;
        }
 
@@ -537,9 +540,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",