From: Ralph Boehme Date: Wed, 28 Oct 2020 11:24:14 +0000 (+0100) Subject: smbd: use fsp in smb_set_file_time() X-Git-Tag: samba-4.14.0rc1~302 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4ac20da4b9104fbfb63de09745a89a234441320b;p=thirdparty%2Fsamba.git smbd: use fsp in smb_set_file_time() Ensure we have a valid fsp whos name we pass to file_ntimes(). Remember, file_ntimes() by default ends up calling SMB_VFS_GET_DOS_ATTRIBUTES() under the hood in order to get/set the creation date. As any fsp->fsp_name contains a backpointer to the fsp ie fsp->fsp_name->fsp == fsp passing set_fsp->fsp_name to file_ntimes() allows replacing the path based SMB_VFS_GET_DOS_ATTRIBUTES() with SMB_VFS_FGET_DOS_ATTRIBUTES() under the hoods. Also use the base_fsp->fsp_name for the base name in case of setting the timestamps on a stream. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 9eec006b639..83f2fa06a5f 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -6526,17 +6526,25 @@ NTSTATUS smb_set_file_time(connection_struct *conn, struct smb_file_time *ft, bool setting_write_time) { - struct smb_filename smb_fname_base; + struct files_struct *set_fsp = NULL; struct timeval_buf tbuf[4]; uint32_t action = FILE_NOTIFY_CHANGE_LAST_ACCESS |FILE_NOTIFY_CHANGE_LAST_WRITE |FILE_NOTIFY_CHANGE_CREATION; + int ret; if (!VALID_STAT(smb_fname->st)) { return NT_STATUS_OBJECT_NAME_NOT_FOUND; } + if (fsp == NULL) { + /* A symlink */ + return NT_STATUS_OK; + } + + set_fsp = fsp->base_fsp == NULL ? fsp : fsp->base_fsp; + /* get some defaults (no modifications) if any info is zero or -1. */ if (is_omit_timespec(&ft->create_time)) { action &= ~FILE_NOTIFY_CHANGE_CREATION; @@ -6586,13 +6594,8 @@ NTSTATUS smb_set_file_time(connection_struct *conn, DBG_DEBUG("setting pending modtime to %s\n", timespec_string_buf(&ft->mtime, true, &tbuf[0])); - if (fsp != NULL) { - if (fsp->base_fsp) { - set_sticky_write_time_fsp(fsp->base_fsp, - ft->mtime); - } else { - set_sticky_write_time_fsp(fsp, ft->mtime); - } + if (set_fsp != NULL) { + set_sticky_write_time_fsp(set_fsp, ft->mtime); } else { set_sticky_write_time_path( vfs_file_id_from_sbuf(conn, &smb_fname->st), @@ -6602,11 +6605,8 @@ NTSTATUS smb_set_file_time(connection_struct *conn, DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n")); - /* Always call ntimes on the base, even if a stream was passed in. */ - smb_fname_base = *smb_fname; - smb_fname_base.stream_name = NULL; - - if(file_ntimes(conn, &smb_fname_base, ft)!=0) { + ret = file_ntimes(conn, set_fsp->fsp_name, ft); + if (ret != 0) { return map_nt_error_from_unix(errno); }