summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2014-12-05 12:47:52 -0800
committerKarolin Seeger <kseeger@samba.org>2014-12-09 21:40:12 +0100
commit434edebd769b061ba85355a961bb2999efa0f084 (patch)
treec4cc4be6afe556770d2dec70b39a4c435365d30f /source3/locking
parent0547beb9dec40a6a39db482d2a2255ee5e67f008 (diff)
downloadsamba-434edebd769b061ba85355a961bb2999efa0f084.tar.gz
s3:locking: Change the data model for leases_db to cope with dynamic path renames.
interface leases_db { typedef [public] struct { GUID client_guid; smb2_lease_key lease_key; } leases_db_key; typedef [public] struct { file_id id; [string,charset(UTF8)] char *servicepath; [string,charset(UTF8)] char *base_name; [string,charset(UTF8)] char *stream_name; } leases_db_file; typedef [public] struct { uint32 num_files; [size_is(num_files)] leases_db_file files[]; } leases_db_value; } As designed by metze. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Dec 9 03:44:04 CET 2014 on sn-devel-104 (cherry picked from commit 5ebb1903858b4d1aadfa4e04644ec1b2b218b914) The last 5 patches address BUG: https://bugzilla.samba.org/show_bug.cgi?id=10911 SMB2 leases are not yet supported.
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/leases_db.c62
-rw-r--r--source3/locking/leases_db.h6
2 files changed, 37 insertions, 31 deletions
diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c
index a9e25666523..0700ba94b87 100644
--- a/source3/locking/leases_db.c
+++ b/source3/locking/leases_db.c
@@ -86,7 +86,7 @@ NTSTATUS leases_db_add(const struct GUID *client_guid,
const struct smb2_lease_key *lease_key,
const struct file_id *id,
const char *servicepath,
- const char *filename,
+ const char *base_name,
const char *stream_name)
{
TDB_DATA db_key, db_value;
@@ -95,6 +95,7 @@ NTSTATUS leases_db_add(const struct GUID *client_guid,
NTSTATUS status;
bool ok;
struct leases_db_value new_value;
+ struct leases_db_file new_file;
struct leases_db_value *value = NULL;
enum ndr_err_code ndr_err;
@@ -140,31 +141,40 @@ NTSTATUS leases_db_add(const struct GUID *client_guid,
}
/* id must be unique. */
- for (i = 0; i < value->num_file_ids; i++) {
- if (file_id_equal(id, &value->ids[i])) {
+ for (i = 0; i < value->num_files; i++) {
+ if (file_id_equal(id, &value->files[i].id)) {
status = NT_STATUS_OBJECT_NAME_COLLISION;
goto out;
}
}
- value->ids = talloc_realloc(value, value->ids, struct file_id,
- value->num_file_ids + 1);
- if (value->ids == NULL) {
+ value->files = talloc_realloc(value, value->files,
+ struct leases_db_file,
+ value->num_files + 1);
+ if (value->files == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
- value->ids[value->num_file_ids] = *id;
- value->num_file_ids += 1;
+ value->files[value->num_files].id = *id;
+ value->files[value->num_files].servicepath = servicepath;
+ value->files[value->num_files].base_name = base_name;
+ value->files[value->num_files].stream_name = stream_name;
+ value->num_files += 1;
} else {
DEBUG(10, ("%s: new record\n", __func__));
- new_value = (struct leases_db_value) {
- .num_file_ids = 1,
- .ids = discard_const_p(struct file_id, id),
- .filename = filename,
+ new_file = (struct leases_db_file) {
+ .id = *id,
+ .servicepath = servicepath,
+ .base_name = base_name,
.stream_name = stream_name,
};
+
+ new_value = (struct leases_db_value) {
+ .num_files = 1,
+ .files = &new_file,
+ };
value = &new_value;
}
@@ -253,21 +263,21 @@ NTSTATUS leases_db_del(const struct GUID *client_guid,
}
/* id must exist. */
- for (i = 0; i < value->num_file_ids; i++) {
- if (file_id_equal(id, &value->ids[i])) {
+ for (i = 0; i < value->num_files; i++) {
+ if (file_id_equal(id, &value->files[i].id)) {
break;
}
}
- if (i == value->num_file_ids) {
+ if (i == value->num_files) {
status = NT_STATUS_NOT_FOUND;
goto out;
}
- value->ids[i] = value->ids[value->num_file_ids-1];
- value->num_file_ids -= 1;
+ value->files[i] = value->files[value->num_files-1];
+ value->num_files -= 1;
- if (value->num_file_ids == 0) {
+ if (value->num_files == 0) {
DEBUG(10, ("%s: deleting record\n", __func__));
status = dbwrap_record_delete(rec);
} else {
@@ -304,9 +314,9 @@ NTSTATUS leases_db_del(const struct GUID *client_guid,
}
struct leases_db_fetch_state {
- void (*parser)(uint32_t num_file_ids,
- struct file_id *ids, const char *filename,
- const char *stream_name, void *private_data);
+ void (*parser)(uint32_t num_files,
+ const struct leases_db_file *files,
+ void *private_data);
void *private_data;
NTSTATUS status;
};
@@ -341,8 +351,8 @@ static void leases_db_parser(TDB_DATA key, TDB_DATA data, void *private_data)
NDR_PRINT_DEBUG(leases_db_value, value);
}
- state->parser(value->num_file_ids,
- value->ids, value->filename, value->stream_name,
+ state->parser(value->num_files,
+ value->files,
state->private_data);
TALLOC_FREE(value);
@@ -351,10 +361,8 @@ static void leases_db_parser(TDB_DATA key, TDB_DATA data, void *private_data)
NTSTATUS leases_db_parse(const struct GUID *client_guid,
const struct smb2_lease_key *lease_key,
- void (*parser)(uint32_t num_file_ids,
- struct file_id *ids,
- const char *filename,
- const char *stream_name,
+ void (*parser)(uint32_t num_files,
+ const struct leases_db_file *files,
void *private_data),
void *private_data)
{
diff --git a/source3/locking/leases_db.h b/source3/locking/leases_db.h
index 20ec5229209..383575a2d88 100644
--- a/source3/locking/leases_db.h
+++ b/source3/locking/leases_db.h
@@ -38,10 +38,8 @@ NTSTATUS leases_db_del(const struct GUID *client_guid,
const struct file_id *id);
NTSTATUS leases_db_parse(const struct GUID *client_guid,
const struct smb2_lease_key *lease_key,
- void (*parser)(uint32_t num_file_ids,
- struct file_id *ids,
- const char *filename,
- const char *stream_name,
+ void (*parser)(uint32_t num_files,
+ const struct leases_db_file *files,
void *private_data),
void *private_data);
NTSTATUS leases_db_rename(const struct GUID *client_guid,