From 1351b613679acb063d7ef8bc63d438e1ec973a9a Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 21 May 2025 19:17:54 +0200 Subject: [PATCH] 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 --- source3/smbd/close.c | 41 +++++++++++++++++++++++++++++++++++++++++ source3/smbd/proto.h | 4 ++++ 2 files changed, 45 insertions(+) diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 6addab5b4c1..e0fc4618209 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 866999b32f1..1befef66ede 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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 */ -- 2.47.3