summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-20 18:40:32 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-20 11:18:35 +0200
commitca1936fbb26af0ee8d0421ae6a4e07a0f62311d9 (patch)
treea2173ebf5126bc9d5fbdcfddbf66e76face39482 /source4
parent9eaaf1fc67697a640260169ec26510806105e91f (diff)
downloadsamba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.tar.gz
samba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.tar.bz2
samba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.zip
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 <rusty@rustcorp.com.au>
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c2
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c76
-rw-r--r--source4/torture/basic/mangle_test.c2
3 files changed, 51 insertions, 29 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 45c36f09c9..24cc93feb9 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -261,7 +261,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
}
if (ltdb->idxptr->itdb == NULL) {
- ltdb->idxptr->itdb = tdb_open(NULL, 1000, TDB_INTERNAL, O_RDWR, 0);
+ ltdb->idxptr->itdb = tdb_open_compat(NULL, 1000, TDB_INTERNAL, O_RDWR, 0, NULL, NULL);
if (ltdb->idxptr->itdb == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
index b9f3e79f20..16a037a6c3 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c
@@ -24,29 +24,30 @@
#include "ldb_tdb.h"
#include "dlinklist.h"
-/*
- the purpose of this code is to work around the braindead posix locking
- rules, to allow us to have a ldb open more than once while allowing
- locking to work
-*/
-
-struct ltdb_wrap {
- struct ltdb_wrap *next, *prev;
- struct tdb_context *tdb;
- dev_t device;
- ino_t inode;
-};
-
-static struct ltdb_wrap *tdb_list;
-
-/* destroy the last connection to a tdb */
-static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+/* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */
+#if BUILD_TDB2
+static void ltdb_log_fn(struct tdb_context *tdb,
+ enum tdb_log_level level,
+ const char *message,
+ struct ldb_context *ldb)
{
- tdb_close(w->tdb);
- DLIST_REMOVE(tdb_list, w);
- return 0;
-}
+ enum ldb_debug_level ldb_level;
+ const char *name = tdb_name(tdb);
+
+ switch (level) {
+ case TDB_LOG_WARNING:
+ ldb_level = LDB_DEBUG_WARNING;
+ case TDB_LOG_USE_ERROR:
+ case TDB_LOG_ERROR:
+ ldb_level = LDB_DEBUG_FATAL;
+ break;
+ default:
+ ldb_level = LDB_DEBUG_FATAL;
+ }
+ ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
+}
+#else /* !TDB2 */
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
{
@@ -83,6 +84,32 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
talloc_free(message);
}
+#endif
+
+/*
+ the purpose of this code is to work around the braindead posix locking
+ rules, to allow us to have a ldb open more than once while allowing
+ locking to work
+
+ TDB2 handles multiple opens, so we don't have this problem there.
+*/
+
+struct ltdb_wrap {
+ struct ltdb_wrap *next, *prev;
+ struct tdb_context *tdb;
+ dev_t device;
+ ino_t inode;
+};
+
+static struct ltdb_wrap *tdb_list;
+
+/* destroy the last connection to a tdb */
+static int ltdb_wrap_destructor(struct ltdb_wrap *w)
+{
+ tdb_close(w->tdb);
+ DLIST_REMOVE(tdb_list, w);
+ return 0;
+}
/*
wrapped connection to a tdb database. The caller should _not_ free
@@ -98,10 +125,6 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
{
struct ltdb_wrap *w;
struct stat st;
- struct tdb_logging_context log_ctx;
-
- log_ctx.log_fn = ltdb_log_fn;
- log_ctx.log_private = ldb;
if (stat(path, &st) == 0) {
for (w=tdb_list;w;w=w->next) {
@@ -119,7 +142,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return NULL;
}
- w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL);
+ w->tdb = tdb_open_compat(path, hash_size, tdb_flags, open_flags, mode, ltdb_log_fn, ldb);
if (w->tdb == NULL) {
talloc_free(w);
return NULL;
@@ -140,4 +163,3 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
return w->tdb;
}
-
diff --git a/source4/torture/basic/mangle_test.c b/source4/torture/basic/mangle_test.c
index a15dc00939..d549a0c1eb 100644
--- a/source4/torture/basic/mangle_test.c
+++ b/source4/torture/basic/mangle_test.c
@@ -167,7 +167,7 @@ bool torture_mangle(struct torture_context *torture,
int i;
/* we will use an internal tdb to store the names we have used */
- tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0);
+ tdb = tdb_open_compat(NULL, 100000, TDB_INTERNAL, 0, 0, NULL, NULL);
if (!tdb) {
printf("ERROR: Failed to open tdb\n");
return false;