From: Ralph Boehme Date: Wed, 21 May 2025 17:17:54 +0000 (+0200) Subject: smbd: add has_delete_access_opens() X-Git-Tag: samba-4.22.2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b8ac68790ff3b8d2ce5bcdc509bf3417b6f9dcb;p=thirdparty%2Fsamba.git smbd: add has_delete_access_opens() BUG: https://bugzilla.samba.org/show_bug.cgi?id=15861 Signed-off-by: Ralph Boehme Reviewed-by: Bjoern Jacke (cherry picked from commit 1351b613679acb063d7ef8bc63d438e1ec973a9a) --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index cf0e0e6419d..53032a345f0 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -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 = {}; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index b5704aeefff..9c89bcc96f5 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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 */