From: Volker Lendecke Date: Mon, 14 Mar 2022 21:52:11 +0000 (+0100) Subject: smbd: Pass up stat-info from openat_pathref_fsp() on error X-Git-Tag: talloc-2.3.4~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=804a19ca5d6c8155f7b35304ce457203453ccd60;p=thirdparty%2Fsamba.git smbd: Pass up stat-info from openat_pathref_fsp() on error If openat_pathref_fsp() fails, callers might want to inspect the stat info. If we really failed on STOPPED_ON_SYMLINK, the caller might need to know this, although openat_pathref_fsp() masked this error. As there is no smb_fname->fsp returned from openat_pathref_fsp() on error, we need to pass this up in smb_fname itself. This essentially reverts de439cd03047, which does basically the same thing but is too specific. We need to cover the general !O_PATH case more broadly. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 0c82de8b48c..542f1fe4181 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -493,6 +493,9 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp, status = fd_openat(dirfsp, smb_fname, fsp, open_flags, 0); if (!NT_STATUS_IS_OK(status)) { + + smb_fname->st = fsp->fsp_name->st; + if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND) || NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND) || NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 8048063dd0a..056fa470b0d 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -807,6 +807,7 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp, strerror(errno)); goto out; } + orig_fsp_name->st = fsp->fsp_name->st; } if (fd != -1) { @@ -856,11 +857,7 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp, saved_status = status; if (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH) { - /* Never follow symlinks on posix open, .. but - * pass the fact it's a symlink in - * smb_fname->st - */ - smb_fname->st = fsp->fsp_name->st; + /* Never follow symlinks on posix open. */ goto out; } if (!lp_follow_symlinks(SNUM(conn))) {