diff options
author | Volker Lendecke <vl@samba.org> | 2019-08-26 17:09:57 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-09-17 22:49:38 +0000 |
commit | 72a019d4e32d46ae160ecfe2c90348d005ec2449 (patch) | |
tree | bde884b599971b340528bb806880c2ee3c32cafe /source3/locking | |
parent | 4d512f40f9f6c1689cc4e0ace541079fda98c611 (diff) | |
download | samba-72a019d4e32d46ae160ecfe2c90348d005ec2449.tar.gz |
smbd: Use share_mode_forall_entries() in remove_lease_if_stale()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/locking')
-rw-r--r-- | source3/locking/locking.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c index c5bbb6d502b..a24d5b68048 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -674,33 +674,55 @@ bool is_valid_share_mode_entry(const struct share_mode_entry *e) return (num_props != 0); } +struct find_lease_ref_state { + const struct GUID *client_guid; + const struct smb2_lease_key *lease_key; + bool found_same; +}; + +static bool find_lease_ref_fn( + struct share_mode_entry *e, + bool *modified, + void *private_data) +{ + struct find_lease_ref_state *state = private_data; + + if (e->stale) { + return false; + } + if (e->op_type != LEASE_OPLOCK) { + return false; + } + + state->found_same = smb2_lease_equal( + &e->client_guid, + &e->lease_key, + state->client_guid, + state->lease_key); + /* + * If we found a lease reference, look no further (i.e. return true) + */ + return state->found_same; +} + NTSTATUS remove_lease_if_stale(struct share_mode_lock *lck, const struct GUID *client_guid, const struct smb2_lease_key *lease_key) { + struct find_lease_ref_state state = { + .client_guid = client_guid, .lease_key = lease_key, + }; struct share_mode_data *d = lck->data; - uint32_t i; NTSTATUS status; + bool ok; - for (i=0; i<d->num_share_modes; i++) { - const struct share_mode_entry *e = &d->share_modes[i]; - bool same; - - if (e->stale) { - continue; - } - if (e->op_type != LEASE_OPLOCK) { - continue; - } + ok = share_mode_forall_entries(lck, find_lease_ref_fn, &state); + if (!ok) { + return NT_STATUS_INTERNAL_ERROR; + } - same = smb2_lease_equal( - &e->client_guid, - &e->lease_key, - client_guid, - lease_key); - if (same) { - return NT_STATUS_RESOURCE_IN_USE; - } + if (state.found_same) { + return NT_STATUS_RESOURCE_IN_USE; } status = leases_db_del(client_guid, lease_key, &d->id); |