#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "messages.h"
-#include "../librpc/gen_ndr/open_files.h"
#include "../librpc/gen_ndr/ndr_open_files.h"
/*
return;
}
+ /*
+ * Paranoia check: There can only be one fsp_lease per lease
+ * key
+ */
+ SMB_ASSERT(fsp->lease == lease);
+
lck = get_existing_share_mode_lock(
talloc_tos(), fsp->file_id);
if (lck == NULL) {
struct share_mode_lease *l = NULL;
idx = find_share_mode_lease(d, client_guid, &lease->lease.lease_key);
- if (idx != -1) {
- l = &d->leases[idx];
- }
-
- if (l == NULL) {
+ if (idx == -1) {
DEBUG(1, ("%s: Could not find lease entry\n", __func__));
TALLOC_FREE(lease->timeout);
lease->lease.lease_state = SMB2_LEASE_NONE;
return false;
}
+ l = &d->leases[idx];
+
DEBUG(10,("%s: refresh lease state\n", __func__));
/* Ensure we're in sync with current lease state. */
return NULL;
}
+static NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
+ struct share_mode_lock *lck,
+ const struct smb2_lease_key *key,
+ uint32_t new_lease_state,
+ struct share_mode_lease **_l)
+{
+ struct share_mode_data *d = lck->data;
+ struct share_mode_lease *l;
+ int idx;
+
+ *_l = NULL;
+
+ idx = find_share_mode_lease(
+ d, &sconn->client->connections->smb2.client.guid, key);
+ if (idx == -1) {
+ DEBUG(10, ("lease not found\n"));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ l = &d->leases[idx];
+
+ if (!l->breaking) {
+ DBG_WARNING("Attempt to break from %"PRIu32" to %"PRIu32" - "
+ "but we're not in breaking state\n",
+ l->current_state, new_lease_state);
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ /*
+ * Can't upgrade anything: l->breaking_to_requested (and l->current_state)
+ * must be a strict bitwise superset of new_lease_state
+ */
+ if ((new_lease_state & l->breaking_to_requested) != new_lease_state) {
+ DBG_WARNING("Attempt to upgrade from %"PRIu32" to %"PRIu32" "
+ "- expected %"PRIu32"\n",
+ l->current_state, new_lease_state,
+ l->breaking_to_requested);
+ return NT_STATUS_REQUEST_NOT_ACCEPTED;
+ }
+
+ if (l->current_state != new_lease_state) {
+ l->current_state = new_lease_state;
+ d->modified = true;
+ }
+
+ if ((new_lease_state & ~l->breaking_to_required) != 0) {
+ DBG_INFO("lease state %"PRIu32" not fully broken from "
+ "%"PRIu32" to %"PRIu32"\n",
+ new_lease_state,
+ l->current_state,
+ l->breaking_to_required);
+ l->breaking_to_requested = l->breaking_to_required;
+ if (l->current_state & (~SMB2_LEASE_READ)) {
+ /*
+ * Here we break in steps, as windows does
+ * see the breaking3 and v2_breaking3 tests.
+ */
+ l->breaking_to_requested |= SMB2_LEASE_READ;
+ }
+ d->modified = true;
+ *_l = l;
+ return NT_STATUS_OPLOCK_BREAK_IN_PROGRESS;
+ }
+
+ DBG_DEBUG("breaking from %"PRIu32" to %"PRIu32" - "
+ "expected %"PRIu32"\n",
+ l->current_state,
+ new_lease_state,
+ l->breaking_to_requested);
+
+ l->breaking_to_requested = 0;
+ l->breaking_to_required = 0;
+ l->breaking = false;
+
+ d->modified = true;
+
+ return NT_STATUS_OK;
+}
+
NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
uint32_t num_file_ids,
const struct file_id *ids,
}
state->xconn = xconn;
- if (l->current_state & (~SMB2_LEASE_READ)) {
- state->break_flags = SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED;
- }
state->lease_key = l->lease_key;
state->break_from = l->current_state;
state->break_to = l->breaking_to_requested;
state->new_epoch = l->epoch;
}
- if (state->break_flags == 0) {
+ if (l->current_state & (~SMB2_LEASE_READ)) {
+ state->break_flags =
+ SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED;
+ } else {
/*
* This is an async break without
* SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED
add_oplock_timeout_handler(fsp);
}
+static bool file_has_read_oplocks(struct files_struct *fsp)
+{
+ struct byte_range_lock *brl;
+ uint32_t num_read_oplocks = 0;
+
+ brl = brl_get_locks_readonly(fsp);
+ if (brl == NULL) {
+ return false;
+ }
+
+ num_read_oplocks = brl_num_read_oplocks(brl);
+
+ DBG_DEBUG("num_read_oplocks = %"PRIu32"\n", num_read_oplocks);
+
+ return (num_read_oplocks != 0);
+}
+
struct break_to_none_state {
struct smbd_server_connection *sconn;
struct file_id id;
struct smbd_server_connection *sconn = fsp->conn->sconn;
struct tevent_immediate *im;
struct break_to_none_state *state;
- struct byte_range_lock *brl;
- uint32_t num_read_oplocks = 0;
+ bool has_read_oplocks;
/*
* If this file is level II oplocked then we need
return;
}
- brl = brl_get_locks_readonly(fsp);
- if (brl != NULL) {
- num_read_oplocks = brl_num_read_oplocks(brl);
- }
-
- DEBUG(10, ("num_read_oplocks = %"PRIu32"\n", num_read_oplocks));
-
- if (num_read_oplocks == 0) {
+ has_read_oplocks = file_has_read_oplocks(fsp);
+ if (!has_read_oplocks) {
DEBUG(10, ("No read oplocks around\n"));
return;
}