]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add has_delete_access_opens()
authorRalph Boehme <slow@samba.org>
Wed, 21 May 2025 17:17:54 +0000 (19:17 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 28 May 2025 15:06:29 +0000 (15:06 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15861

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Bjoern Jacke <bjacke@samba.org>
source3/smbd/close.c
source3/smbd/proto.h

index 6addab5b4c1ecf232b1f693366ff8bd39d88bbfa..e0fc4618209861df32e081d4bf36f01a203390cd 100644 (file)
@@ -278,6 +278,47 @@ bool has_other_nonposix_opens(struct share_mode_lock *lck,
        return state.found_another;
 }
 
+struct has_delete_access_opens_state {
+       bool delete_access;
+       bool delete_pending;
+};
+
+static bool has_delete_access_opens_fn(
+       struct share_mode_entry *e,
+       bool *modified,
+       void *private_data)
+{
+       struct has_delete_access_opens_state *state = private_data;
+
+       if (share_entry_stale_pid(e)) {
+               return false;
+       }
+
+       if (e->access_mask & SEC_STD_DELETE) {
+               state->delete_access = true;
+       }
+       return false;
+}
+
+bool has_delete_opens(struct files_struct *fsp,
+                     struct share_mode_lock *lck,
+                     bool *delete_access,
+                     bool *delete_pending)
+{
+       struct has_delete_access_opens_state state = {};
+       bool ok;
+
+       ok = share_mode_forall_entries(
+               lck, has_delete_access_opens_fn, &state);
+       if (!ok) {
+               return false;
+       }
+
+       *delete_access = state.delete_access;
+       *delete_pending = is_delete_on_close_set(lck, fsp->name_hash);
+       return true;
+}
+
 bool has_nonposix_opens(struct share_mode_lock *lck)
 {
        struct has_other_nonposix_opens_state state = {};
index 866999b32f1abdd098440179417f7e38341b1849..1befef66ede7d8e41a405afdd2b960079c0673bd 100644 (file)
@@ -143,6 +143,10 @@ NTSTATUS recursive_rmdir_fsp(struct files_struct *fsp);
 bool has_other_nonposix_opens(struct share_mode_lock *lck,
                              struct files_struct *fsp);
 bool has_nonposix_opens(struct share_mode_lock *lck);
+bool has_delete_opens(struct files_struct *fsp,
+                     struct share_mode_lock *lck,
+                     bool *delete_access,
+                     bool *delete_pending);
 
 /* The following definitions come from smbd/conn.c  */