]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: use fsp in smb_set_file_time()
authorRalph Boehme <slow@samba.org>
Wed, 28 Oct 2020 11:24:14 +0000 (12:24 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:31 +0000 (09:08 +0000)
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 <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/trans2.c

index 9eec006b639c131e434792d5058f3e00e3279b2f..83f2fa06a5f57f77b9a1bedfa6d185c7ab3d9101 100644 (file)
@@ -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);
        }