smbd: Use leases_db_set()
authorVolker Lendecke <vl@samba.org>
Mon, 8 Apr 2019 14:21:41 +0000 (16:21 +0200)
committerChristof Schmitt <cs@samba.org>
Sun, 14 Apr 2019 04:01:30 +0000 (04:01 +0000)
Whenever we update the share_mode_lease struct, also update the leases.tdb
entry.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/smbd/open.c
source3/smbd/oplock.c

index 3791df4..cdef53c 100644 (file)
@@ -2099,6 +2099,26 @@ static NTSTATUS grant_fsp_lease(struct files_struct *fsp,
                        l->epoch += 1;
                }
 
+               {
+                       NTSTATUS set_status;
+
+                       set_status = leases_db_set(
+                               client_guid,
+                               &lease->lease_key,
+                               l->current_state,
+                               l->breaking,
+                               l->breaking_to_requested,
+                               l->breaking_to_required,
+                               l->lease_version,
+                               l->epoch);
+
+                       if (!NT_STATUS_IS_OK(set_status)) {
+                               DBG_DEBUG("leases_db_set failed: %s\n",
+                                         nt_errstr(set_status));
+                               return set_status;
+                       }
+               }
+
                /* Ensure we're in sync with current lease state. */
                fsp_lease_update(lck, fsp_client_guid(fsp), fsp->lease);
                return NT_STATUS_OK;
index cb471fa..7dfe186 100644 (file)
@@ -25,6 +25,7 @@
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
 #include "messages.h"
+#include "locking/leases_db.h"
 #include "../librpc/gen_ndr/ndr_open_files.h"
 
 /*
@@ -647,6 +648,27 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
                        l->breaking = false;
 
                        lck->data->modified = true;
+
+                       {
+                               NTSTATUS set_status;
+
+                               set_status = leases_db_set(
+                                       &sconn->client->connections->
+                                       smb2.client.guid,
+                                       key,
+                                       l->current_state,
+                                       l->breaking,
+                                       l->breaking_to_requested,
+                                       l->breaking_to_required,
+                                       l->lease_version,
+                                       l->epoch);
+
+                               if (!NT_STATUS_IS_OK(set_status)) {
+                                       DBG_DEBUG("leases_db_set failed: %s\n",
+                                                 nt_errstr(set_status));
+                                       return set_status;
+                               }
+                       }
                }
 
                tevent_schedule_immediate(state->im,
@@ -669,6 +691,26 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
                d->modified = true;
        }
 
+       {
+               NTSTATUS set_status;
+
+               set_status = leases_db_set(
+                       &sconn->client->connections->smb2.client.guid,
+                       key,
+                       l->current_state,
+                       l->breaking,
+                       l->breaking_to_requested,
+                       l->breaking_to_required,
+                       l->lease_version,
+                       l->epoch);
+
+               if (!NT_STATUS_IS_OK(set_status)) {
+                       DBG_DEBUG("leases_db_set failed: %s\n",
+                                 nt_errstr(set_status));
+                       return set_status;
+               }
+       }
+
        DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__,
                   file_id_string_tos(&id), (unsigned)lease_state, nt_errstr(status)));
 
@@ -996,6 +1038,27 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
                                lck->data->modified = true;
                        }
 
+                       {
+                               NTSTATUS set_status;
+
+                               set_status = leases_db_set(
+                                       &sconn->client->connections->
+                                       smb2.client.guid,
+                                       &fsp->lease->lease.lease_key,
+                                       l->current_state,
+                                       l->breaking,
+                                       l->breaking_to_requested,
+                                       l->breaking_to_required,
+                                       l->lease_version,
+                                       l->epoch);
+
+                               if (!NT_STATUS_IS_OK(set_status)) {
+                                       DBG_DEBUG("leases_db_set failed: %s\n",
+                                                 nt_errstr(set_status));
+                                       return;
+                               }
+                       }
+
                        /* Ensure we're in sync with current lease state. */
                        fsp_lease_update(lck, fsp_client_guid(fsp), fsp->lease);
                }