From: Volker Lendecke Date: Wed, 14 Aug 2019 19:40:07 +0000 (+0200) Subject: smbd: Use share_mode_forall_entries() in has_other_nonposix_opens_fn() X-Git-Tag: talloc-2.3.1~809 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=14cc16948f0da00119cc85ebe7f9ab51b2275ece;p=thirdparty%2Fsamba.git smbd: Use share_mode_forall_entries() in has_other_nonposix_opens_fn() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/close.c b/source3/smbd/close.c index baae5b736ff..5b29d347732 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -233,37 +233,53 @@ NTSTATUS delete_all_streams(connection_struct *conn, return status; } -bool has_other_nonposix_opens(struct share_mode_lock *lck, - struct files_struct *fsp) +struct has_other_nonposix_opens_state { + files_struct *fsp; + bool found_another; +}; + +static bool has_other_nonposix_opens_fn( + struct share_mode_entry *e, + bool *modified, + void *private_data) { - struct share_mode_data *data = lck->data; - struct server_id self = messaging_server_id(fsp->conn->sconn->msg_ctx); - uint32_t i; - - for (i=0; inum_share_modes; i++) { - struct share_mode_entry *e = &data->share_modes[i]; + struct has_other_nonposix_opens_state *state = private_data; + struct files_struct *fsp = state->fsp; - if (!is_valid_share_mode_entry(e)) { - continue; - } - if (e->name_hash != fsp->name_hash) { - continue; - } - if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) && - (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) { - continue; - } - if (serverid_equal(&self, &e->pid) && - (e->share_file_id == fsp->fh->gen_id)) { - continue; - } - if (share_mode_stale_pid(data, i)) { - continue; + if (e->name_hash != fsp->name_hash) { + return false; + } + if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) && + (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) { + return false; + } + if (e->share_file_id == fsp->fh->gen_id) { + struct server_id self = messaging_server_id( + fsp->conn->sconn->msg_ctx); + if (server_id_equal(&self, &e->pid)) { + return false; } - return true; } + if (share_entry_stale_pid(e)) { + return false; + } + + state->found_another = true; + return true; +} - return false; +bool has_other_nonposix_opens(struct share_mode_lock *lck, + struct files_struct *fsp) +{ + struct has_other_nonposix_opens_state state = { .fsp = fsp }; + bool ok; + + ok = share_mode_forall_entries( + lck, has_other_nonposix_opens_fn, &state); + if (!ok) { + return false; + } + return state.found_another; } /****************************************************************************