From d8cfca3a9bd2b6b6c562fd202377d95a98eb5472 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 5 May 2011 11:25:29 +0200 Subject: s3: only include tdb headers where needed. Guenther --- source3/libsmb/smb_share_modes.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 1a6c2123ed6..76e63e69689 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -27,6 +27,7 @@ #include "includes.h" #include "system/filesys.h" #include "smb_share_modes.h" +#include /* Database context handle. */ struct smbdb_ctx { -- cgit From 20687dcd7b66635f851f09c51f967e17203c8ab0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 16:55:15 +0930 Subject: smb_share_modes: don't use tdb_jenkins_hash. It's a nice hash, but this usage has nothing to do with TDB. So use the Jenkins hash directly from CCAN instead (it's the same one). Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 76e63e69689..133b5b82f0f 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -28,6 +28,7 @@ #include "system/filesys.h" #include "smb_share_modes.h" #include +#include /* Database context handle. */ struct smbdb_ctx { @@ -267,7 +268,6 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *err) { - TDB_DATA key; char *fullpath = NULL; size_t sharepath_size = strlen(sharepath); size_t filename_size = strlen(filename); @@ -283,9 +283,7 @@ static uint32_t smb_name_hash(const char *sharepath, const char *filename, int * fullpath[sharepath_size] = '/'; memcpy(&fullpath[sharepath_size + 1], filename, filename_size + 1); - key.dptr = (uint8_t *)fullpath; - key.dsize = strlen(fullpath) + 1; - name_hash = tdb_jenkins_hash(&key); + name_hash = hash(fullpath, strlen(fullpath) + 1, 0); free(fullpath); return name_hash; } -- cgit From 0e4c358e2710580d5aeb439d767c87aaf4c0f2f3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:25 +0930 Subject: tdb_compat.h: divert every tdb build and includes to tdb_compat We change all the headers and wscript files to use tdb_compat; this means we have one place to decide whether to use TDB1 or TDB2. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 133b5b82f0f..bb405969f37 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -27,7 +27,7 @@ #include "includes.h" #include "system/filesys.h" #include "smb_share_modes.h" -#include +#include "tdb_compat.h" #include /* Database context handle. */ -- cgit From 058c4f84924c07b88ccaf3d617f3abff797a7cc8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_fetch_compat: use instead of tdb_fetch. This is a noop for tdb1. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index bb405969f37..2bf430dfea5 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -201,8 +201,8 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, *pp_list = NULL; *p_delete_on_close = 0; - db_data = tdb_fetch(db_ctx->smb_tdb, get_locking_key(&lk, dev, ino, - extid)); + db_data = tdb_fetch_compat(db_ctx->smb_tdb, + get_locking_key(&lk, dev, ino, extid)); if (!db_data.dptr) { return 0; } @@ -315,7 +315,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, return -1; } - db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + db_data = tdb_fetch_compat(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ db_data.dptr = (uint8 *)malloc( @@ -432,7 +432,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, size_t i, num_share_modes; const uint8 *remaining_ptr = NULL; - db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + db_data = tdb_fetch_compat(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { return -1; /* Error - missing entry ! */ } @@ -534,7 +534,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, size_t i; int found_entry = 0; - db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + db_data = tdb_fetch_compat(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { return -1; /* Error - missing entry ! */ } -- cgit From 1078eb21c49d707ddeef2257353f35c10d131b9f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_delete: check returns for 0, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for != 0 instead of == -1. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 2bf430dfea5..4477da6a19c 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -450,7 +450,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* It's ours - just remove the entire record. */ free(db_data.dptr); - return tdb_delete(db_ctx->smb_tdb, locking_key); + return tdb_delete(db_ctx->smb_tdb, locking_key) ? -1 : 0; } /* More than one - allocate a new record minus the one we'll delete. */ @@ -489,7 +489,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, /* None left after pruning. Delete record. */ free(db_data.dptr); free(new_data_p); - return tdb_delete(db_ctx->smb_tdb, locking_key); + return tdb_delete(db_ctx->smb_tdb, locking_key) ? -1 : 0; } /* Copy any delete tokens plus the terminating filenames. */ -- cgit From 6bc59d77b64d1ecbe5c906ed2fa80a7b8ca5d420 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_store: check returns for 0, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for != 0 instead of == -1. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 4477da6a19c..e891b960d8a 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -344,7 +344,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, db_data.dsize = sizeof(struct locking_data) + sizeof(struct share_mode_entry) + strlen(sharepath) + 1 + strlen(filename) + 1; - if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) { + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) != 0) { free(db_data.dptr); return -1; } @@ -387,7 +387,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, db_data.dptr = new_data_p; db_data.dsize = new_data_size; - if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) != 0) { free(db_data.dptr); return -1; } @@ -510,7 +510,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, db_data.dsize = sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)) + remaining_size; - if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) != 0) { free(db_data.dptr); return -1; } @@ -565,7 +565,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Save modified data. */ - if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) != 0) { free(db_data.dptr); return -1; } -- cgit From 868d77bc5b38e628f74d5cd03c5f87eb5a666b09 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_chainlock: check returns for 0, not -1. TDB2 returns a negative error number on failure. This is compatible if we always check for != 0 instead of == -1. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index e891b960d8a..86e1a81ef12 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -122,7 +122,7 @@ int smb_lock_share_mode_entry(struct smbdb_ctx *db_ctx, { struct locking_key lk; return tdb_chainlock(db_ctx->smb_tdb, get_locking_key(&lk, dev, ino, - extid)); + extid)) == 0 ? 0 : -1; } int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, -- cgit From 9850f256337d70401d962bb1f6d5b834a221358d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:31 +0930 Subject: tdb_chainunlock: ignore return value. TDB2 returns void here. tdb_chainunlock will *always* return with the chain unlocked, but it will complain via the log function if it wasn't locked. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 86e1a81ef12..a4a54972c90 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -131,8 +131,9 @@ int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, uint64_t extid) { struct locking_key lk; - return tdb_chainunlock(db_ctx->smb_tdb, - get_locking_key(&lk, dev, ino, extid)); + tdb_chainunlock(db_ctx->smb_tdb, + get_locking_key(&lk, dev, ino, extid)); + return 0; } /* -- cgit From ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Jun 2011 18:40:32 +0930 Subject: tdb_compat: use tdb_open_compat. This is a helper for the common case of opening a tdb with a logging function, but it doesn't do all the work, since TDB1 and TDB2's log functions are different types. Signed-off-by: Rusty Russell --- source3/libsmb/smb_share_modes.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index a4a54972c90..7c0a6d2a4e6 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -69,10 +69,12 @@ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) memset(smb_db, '\0', sizeof(struct smbdb_ctx)); - smb_db->smb_tdb = tdb_open(db_path, - 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, - O_RDWR|O_CREAT, - 0644); + /* FIXME: We should *never* open a tdb without logging! */ + smb_db->smb_tdb = tdb_open_compat(db_path, + 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, + O_RDWR|O_CREAT, + 0644, + NULL, NULL); if (!smb_db->smb_tdb) { free(smb_db); -- cgit