smbd: Add update_share_mode_lease_from_db()
authorVolker Lendecke <vl@samba.org>
Wed, 19 Sep 2018 08:25:31 +0000 (10:25 +0200)
committerChristof Schmitt <cs@samba.org>
Sun, 14 Apr 2019 04:01:32 +0000 (04:01 +0000)
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 <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/smbd/open.c
source3/smbd/proto.h

index f1d39d46f27f4f3af04f7ca7612e35e9bd0150be..26782bf5d309482fd850fc541d4760033fbf89ad 100644 (file)
@@ -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,
+                              &current_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,
index 962707007bd98ca37f4234978dbf3803040d9d6b..e246645605b858a77678142c6306beb45853a4c5 100644 (file)
@@ -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,