s3: smbd: Update file times right before closing the underlying fd
authorSamuel Cabrero <scabrero@samba.org>
Thu, 15 Apr 2021 09:53:13 +0000 (11:53 +0200)
committerSamuel Cabrero <scabrero@sn-devel-184>
Mon, 19 Apr 2021 12:28:30 +0000 (12:28 +0000)
Next commits will update file_ntimes() to use handle-based SMB_VFS_FNTIMES().
Move the update_write_time_on_close() call immediately before closing the fd.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/close.c

index d4f236e3de9c3926ba7558e0cb22a972ac624ad3..4e062f470ec1a285ccf8c74bb7b00b787f08323b 100644 (file)
@@ -807,30 +807,29 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
 
        locking_close_file(fsp, close_type);
 
-       tmp = fd_close(fsp);
-       status = ntstatus_keeperror(status, tmp);
-
-       /* check for magic scripts */
-       if (close_type == NORMAL_CLOSE) {
-               tmp = check_magic(fsp);
-               status = ntstatus_keeperror(status, tmp);
-       }
-
        /*
-        * Ensure pending modtime is set after close.
+        * Ensure pending modtime is set before closing underlying fd.
         */
 
        tmp = update_write_time_on_close(fsp);
        if (NT_STATUS_EQUAL(tmp, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
-               /* Someone renamed the file or a parent directory containing
-                * this file. We can't do anything about this, we don't have
-                * an "update timestamp by fd" call in POSIX. Eat the error. */
-
+               /*
+                * Someone renamed the file or a parent directory containing
+                * this file. We can't do anything about this, eat the error.
+                */
                tmp = NT_STATUS_OK;
        }
+       status = ntstatus_keeperror(status, tmp);
 
+       tmp = fd_close(fsp);
        status = ntstatus_keeperror(status, tmp);
 
+       /* check for magic scripts */
+       if (close_type == NORMAL_CLOSE) {
+               tmp = check_magic(fsp);
+               status = ntstatus_keeperror(status, tmp);
+       }
+
        DEBUG(2,("%s closed file %s (numopen=%d) %s\n",
                conn->session_info->unix_info->unix_name, fsp_str_dbg(fsp),
                conn->num_files_open - 1,