From: Volker Lendecke Date: Wed, 19 Sep 2018 08:25:31 +0000 (+0200) Subject: smbd: Add update_share_mode_lease_from_db() X-Git-Tag: tdb-1.4.1~409 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa2cea30917667e1f8f084c33cbbbd564f02e452;p=thirdparty%2Fsamba.git smbd: Add update_share_mode_lease_from_db() This is an interim function supposed to be around for just a few patches as long as we have both the leases.tdb entries and the leases[] in share_mode_entries around. It makes it easier to transition to just use leases.tdb while keeping the code running. Signed-off-by: Volker Lendecke Reviewed-by: Christof Schmitt --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index f1d39d46f27..26782bf5d30 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1991,6 +1991,61 @@ int find_share_mode_lease(struct share_mode_data *d, return -1; } +NTSTATUS update_share_mode_lease_from_db( + struct share_mode_data *d, + const struct GUID *client_guid, + const struct smb2_lease_key *lease_key) +{ + int idx; + struct share_mode_lease *l; + uint32_t current_state, breaking_to_requested, breaking_to_required; + bool breaking; + uint16_t lease_version, epoch; + NTSTATUS status; + + idx = find_share_mode_lease(d, client_guid, lease_key); + if (idx == -1) { + DBG_WARNING("find_share_mode_lease failed\n"); + return NT_STATUS_NOT_FOUND; + } + l = &d->leases[idx]; + + status = leases_db_get(client_guid, + lease_key, + &d->id, + ¤t_state, + &breaking, + &breaking_to_requested, + &breaking_to_required, + &lease_version, + &epoch); + if (!NT_STATUS_IS_OK(status)) { + DBG_WARNING("leases_db_get returned %s\n", + nt_errstr(status)); + return status; + } + + if ((l->current_state == current_state) && + (l->breaking == breaking) && + (l->breaking_to_requested == breaking_to_requested) && + (l->breaking_to_required == breaking_to_required) && + (l->lease_version == lease_version) && + (l->epoch == epoch)) { + return NT_STATUS_OK; + } + + l->current_state = current_state; + l->breaking = breaking; + l->breaking_to_requested = breaking_to_requested; + l->breaking_to_required = breaking_to_required; + l->lease_version = lease_version; + l->epoch = epoch; + + d->modified = true; + + return NT_STATUS_OK; +} + struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp, const struct smb2_lease_key *key, uint32_t current_state, diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 962707007bd..e246645605b 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -695,6 +695,10 @@ int find_share_mode_lease(struct share_mode_data *d, const struct GUID *client_guid, const struct smb2_lease_key *key); struct share_mode_lease; +NTSTATUS update_share_mode_lease_from_db( + struct share_mode_data *d, + const struct GUID *client_guid, + const struct smb2_lease_key *lease_key); struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp, const struct smb2_lease_key *key, uint32_t current_state,