From 580d691c9bbd65a7ce0e28ff9f4ed2acc4fdf51a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 May 2021 12:02:22 -0700 Subject: [PATCH] s3: smbd: Change refuse_symlink() -> refuse_symlink_fsp() Simplify the interals to check for everything that would make an fsp something that is open on a symlink. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- source3/smbd/trans2.c | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 9d8bbdf84ec..2f978cebd8f 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -59,36 +59,19 @@ static char *store_file_unix_basic_info2(connection_struct *conn, const SMB_STRUCT_STAT *psbuf); /**************************************************************************** - Check if an open file handle or smb_fname is a symlink. + Check if an open file handle is a symlink. ****************************************************************************/ -static NTSTATUS refuse_symlink(connection_struct *conn, - const files_struct *fsp, - const struct smb_filename *smb_fname) +static NTSTATUS refuse_symlink_fsp(const files_struct *fsp) { - SMB_STRUCT_STAT sbuf; - const SMB_STRUCT_STAT *pst = NULL; - if (fsp) { - pst = &fsp->fsp_name->st; - } else { - pst = &smb_fname->st; + if (!VALID_STAT(fsp->fsp_name->st)) { + return NT_STATUS_ACCESS_DENIED; } - - if (!VALID_STAT(*pst)) { - int ret = vfs_stat_smb_basename(conn, - smb_fname, - &sbuf); - if (ret == -1 && errno != ENOENT) { - return map_nt_error_from_unix(errno); - } else if (ret == -1) { - /* it's not a symlink.. */ - return NT_STATUS_OK; - } - pst = &sbuf; + if (S_ISLNK(fsp->fsp_name->st.st_ex_mode)) { + return NT_STATUS_ACCESS_DENIED; } - - if (S_ISLNK(pst->st_ex_mode)) { + if (fsp_get_pathref_fd(fsp) == -1) { return NT_STATUS_ACCESS_DENIED; } return NT_STATUS_OK; @@ -762,7 +745,7 @@ NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, posix_pathnames = (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH); - status = refuse_symlink(conn, fsp, fsp->fsp_name); + status = refuse_symlink_fsp(fsp); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -5008,9 +4991,7 @@ static NTSTATUS smb_query_posix_acl(connection_struct *conn, SMB_ASSERT(fsp != NULL); - status = refuse_symlink(conn, - fsp, - fsp->fsp_name); + status = refuse_symlink_fsp(fsp); if (!NT_STATUS_IS_OK(status)) { goto out; } @@ -7662,7 +7643,7 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn, /* Here we know fsp != NULL */ SMB_ASSERT(fsp != NULL); - status = refuse_symlink(conn, fsp, fsp->fsp_name); + status = refuse_symlink_fsp(fsp); if (!NT_STATUS_IS_OK(status)) { goto out; } -- 2.47.3