s3:locking: make use of share_mode_do_locked_vfs_denied() in set_sticky_write_time()
authorStefan Metzmacher <metze@samba.org>
Thu, 1 Sep 2022 10:54:35 +0000 (12:54 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 20 Sep 2022 00:34:35 +0000 (00:34 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/locking/locking.c

index a06a1418e32ae68c5b9323e846b522e8f06c1b7d..a65124403cff1d3435cd95307cd967e26a8fa946 100644 (file)
@@ -1078,23 +1078,53 @@ bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash)
        return find_delete_on_close_token(d, name_hash) != NULL;
 }
 
-bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
+struct set_sticky_write_time_state {
+       struct file_id fileid;
+       struct timespec write_time;
+       bool ok;
+};
+
+static void set_sticky_write_time_fn(struct share_mode_lock *lck,
+                                    void *private_data)
 {
-       struct share_mode_lock *lck;
+       struct set_sticky_write_time_state *state = private_data;
        struct share_mode_data *d = NULL;
        struct file_id_buf ftmp;
        struct timeval_buf tbuf;
        NTSTATUS status;
 
-       lck = get_existing_share_mode_lock(talloc_tos(), fileid);
-       if (lck == NULL) {
-               return False;
-       }
-
        status = share_mode_lock_access_private_data(lck, &d);
        if (!NT_STATUS_IS_OK(status)) {
                /* Any error recovery possible here ? */
                DBG_ERR("share_mode_lock_access_private_data() failed for "
+                       "%s id=%s - %s\n",
+                       timespec_string_buf(&state->write_time, true, &tbuf),
+                       file_id_str_buf(state->fileid, &ftmp),
+                       nt_errstr(status));
+               return;
+       }
+
+       share_mode_set_changed_write_time(lck, state->write_time);
+
+       state->ok = true;
+}
+
+bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
+{
+       struct set_sticky_write_time_state state = {
+               .fileid = fileid,
+               .write_time = write_time,
+       };
+       struct file_id_buf ftmp;
+       struct timeval_buf tbuf;
+       NTSTATUS status;
+
+       status = share_mode_do_locked_vfs_denied(fileid,
+                                                set_sticky_write_time_fn,
+                                                &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               /* Any error recovery possible here ? */
+               DBG_ERR("share_mode_do_locked_vfs_denied() failed for "
                        "%s id=%s - %s\n",
                        timespec_string_buf(&write_time, true, &tbuf),
                        file_id_str_buf(fileid, &ftmp),
@@ -1102,10 +1132,7 @@ bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
                return false;
        }
 
-       share_mode_set_changed_write_time(lck, write_time);
-
-       TALLOC_FREE(lck);
-       return True;
+       return state.ok;
 }
 
 struct set_write_time_state {