From: Volker Lendecke Date: Fri, 16 Aug 2019 13:56:23 +0000 (+0200) Subject: smbd: Use share_mode_forall_entries() in file_has_open_streams() X-Git-Tag: talloc-2.3.1~804 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=18c8b46e8176ea56f24a853d1f6c5ca484df7d81;p=thirdparty%2Fsamba.git smbd: Use share_mode_forall_entries() in file_has_open_streams() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 58546538500..f26f5821a5e 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -1269,35 +1269,50 @@ struct timespec get_share_mode_write_time(struct share_mode_lock *lck) return d->old_write_time; } +struct file_has_open_streams_state { + bool found_one; +}; + +static bool file_has_open_streams_fn( + struct share_mode_entry *e, + bool *modified, + void *private_data) +{ + struct file_has_open_streams_state *state = private_data; + + if ((e->private_options & + NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN) == 0) { + return false; + } + + if (share_entry_stale_pid(e)) { + return false; + } + + state->found_one = true; + return true; +} + bool file_has_open_streams(files_struct *fsp) { + struct file_has_open_streams_state state = { .found_one = false }; struct share_mode_lock *lock = NULL; - struct share_mode_data *d = NULL; - uint32_t i; + bool ok; lock = get_existing_share_mode_lock(talloc_tos(), fsp->file_id); if (lock == NULL) { return false; } - d = lock->data; - - for (i = 0; i < d->num_share_modes; i++) { - struct share_mode_entry *e = &d->share_modes[i]; - if (share_mode_stale_pid(d, i)) { - continue; - } + ok = share_mode_forall_entries( + lock, file_has_open_streams_fn, &state); + TALLOC_FREE(lock); - if (e->private_options & - NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN) - { - TALLOC_FREE(lock); - return true; - } + if (!ok) { + DBG_DEBUG("share_mode_forall_entries failed\n"); + return false; } - - TALLOC_FREE(lock); - return false; + return state.found_one; } bool share_mode_forall_entries(