]> 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)
committerJule Anger <janger@samba.org>
Thu, 5 Jun 2025 10:57:15 +0000 (10:57 +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>
(cherry picked from commit 1351b613679acb063d7ef8bc63d438e1ec973a9a)

source3/smbd/close.c
source3/smbd/proto.h

index cf0e0e6419db555b46e7fd6a6af81ed39d04f7a6..53032a345f0b3c19943e026b843ea7c61ea536d9 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 b5704aeefff1bff9aaa7c72aea0c536a1b755000..9c89bcc96f57666325818bea8b22dde6fbcfd57d 100644 (file)
@@ -145,6 +145,10 @@ NTSTATUS recursive_rmdir(TALLOC_CTX *ctx,
 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  */