From 48bc561d1a8bb5ce99663b58a2e5e9aa344af96a Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 1 Feb 2021 10:17:13 +0100 Subject: [PATCH] smbd: expect valid stat info in openat_pathref_fsp() 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 Reviewed-by: Jeremy Allison --- source3/smbd/files.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 40af56402e4..8d7ecabe285 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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", -- 2.47.3