return state.status;
}
-NTSTATUS leases_db_del(const struct GUID *client_guid,
- const struct smb2_lease_key *lease_key,
- const struct file_id *id)
-{
- struct leases_db_key_buf keybuf;
- TDB_DATA db_key = leases_db_key(&keybuf, client_guid, lease_key);
- TDB_DATA db_value;
- struct db_record *rec;
+struct leases_db_del_state {
+ const struct file_id *id;
NTSTATUS status;
- struct leases_db_value *value;
- enum ndr_err_code ndr_err;
- DATA_BLOB blob;
- uint32_t i;
-
- if (!leases_db_init(false)) {
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- rec = dbwrap_fetch_locked(leases_db, talloc_tos(), db_key);
- if (rec == NULL) {
- return NT_STATUS_NOT_FOUND;
- }
- db_value = dbwrap_record_get_value(rec);
- if (db_value.dsize == 0) {
- status = NT_STATUS_INTERNAL_ERROR;
- goto out;
- }
-
- value = talloc(rec, struct leases_db_value);
- if (value == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto out;
- }
-
- blob.data = db_value.dptr;
- blob.length = db_value.dsize;
+};
- ndr_err = ndr_pull_struct_blob_all(
- &blob, value, value,
- (ndr_pull_flags_fn_t)ndr_pull_leases_db_value);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- DEBUG(10, ("%s: ndr_pull_struct_blob_failed: %s\n",
- __func__, ndr_errstr(ndr_err)));
- status = ndr_map_error2ntstatus(ndr_err);
- goto out;
- }
+static void leases_db_del_fn(
+ struct leases_db_value *value, bool *modified, void *private_data)
+{
+ struct leases_db_del_state *state = private_data;
+ uint32_t i;
- /* id must exist. */
for (i = 0; i < value->num_files; i++) {
- if (file_id_equal(id, &value->files[i].id)) {
+ if (file_id_equal(state->id, &value->files[i].id)) {
break;
}
}
-
if (i == value->num_files) {
- status = NT_STATUS_NOT_FOUND;
- goto out;
+ state->status = NT_STATUS_NOT_FOUND;
+ return;
}
value->files[i] = value->files[value->num_files-1];
value->num_files -= 1;
- if (value->num_files == 0) {
- DEBUG(10, ("%s: deleting record\n", __func__));
- status = dbwrap_record_delete(rec);
- } else {
- DEBUG(10, ("%s: updating record\n", __func__));
- ndr_err = ndr_push_struct_blob(
- &blob, rec, value,
- (ndr_push_flags_fn_t)ndr_push_leases_db_value);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- DEBUG(10, ("%s: ndr_push_struct_blob_failed: %s\n",
- __func__, ndr_errstr(ndr_err)));
- status = ndr_map_error2ntstatus(ndr_err);
- goto out;
- }
-
- if (DEBUGLEVEL >= 10) {
- DEBUG(10, ("%s:\n", __func__));
- NDR_PRINT_DEBUG(leases_db_value, value);
- }
+ *modified = true;
+}
- db_value = make_tdb_data(blob.data, blob.length);
+NTSTATUS leases_db_del(const struct GUID *client_guid,
+ const struct smb2_lease_key *lease_key,
+ const struct file_id *id)
+{
+ struct leases_db_del_state state = { .id = id };
+ NTSTATUS status;
- status = dbwrap_record_store(rec, db_value, 0);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(10, ("%s: dbwrap_record_store returned %s\n",
- __func__, nt_errstr(status)));
- }
+ status = leases_db_do_locked(
+ client_guid, lease_key, leases_db_del_fn, &state);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_DEBUG("leases_db_do_locked failed: %s\n",
+ nt_errstr(status));
+ return status;
}
-
- out:
-
- TALLOC_FREE(rec);
- return status;
+ return state.status;
}
struct leases_db_fetch_state {