diff options
-rw-r--r-- | lib/util/tdb_wrap.c | 33 | ||||
-rw-r--r-- | source3/lib/util_tdb.c | 17 | ||||
-rw-r--r-- | source3/libsmb/smb_share_modes.c | 10 | ||||
-rw-r--r-- | source3/printing/tests/vlp.c | 5 | ||||
-rw-r--r-- | source3/smbd/mangle_hash.c | 5 | ||||
-rw-r--r-- | source3/torture/mangle_test.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 76 | ||||
-rw-r--r-- | source4/torture/basic/mangle_test.c | 2 | ||||
-rw-r--r-- | testsuite/printing/psec.c | 4 |
10 files changed, 107 insertions, 49 deletions
diff --git a/lib/util/tdb_wrap.c b/lib/util/tdb_wrap.c index b19b4fe67f..71aea5e36c 100644 --- a/lib/util/tdb_wrap.c +++ b/lib/util/tdb_wrap.c @@ -23,6 +23,31 @@ #include "lib/util/dlinklist.h" #include "lib/util/tdb_wrap.h" +/* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */ +#if BUILD_TDB2 +static void tdb_wrap_log(struct tdb_context *tdb, + enum tdb_log_level level, + const char *message, + void *unused) +{ + int dl; + const char *name = tdb_name(tdb); + + switch (level) { + case TDB_LOG_USE_ERROR: + case TDB_LOG_ERROR: + dl = 0; + break; + case TDB_LOG_WARNING: + dl = 2; + break; + default: + dl = 0; + } + + DEBUG(dl, ("tdb(%s): %s", name ? name : "unnamed", message)); +} +#else /* Log tdb messages via DEBUG(). */ @@ -64,6 +89,7 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, free(ptr); } } +#endif struct tdb_wrap_private { struct tdb_context *tdb; @@ -89,7 +115,6 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, mode_t mode) { struct tdb_wrap_private *result; - struct tdb_logging_context log_ctx; result = talloc(mem_ctx, struct tdb_wrap_private); if (result == NULL) { @@ -100,8 +125,6 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, goto fail; } - log_ctx.log_fn = tdb_wrap_log; - #if _SAMBA_BUILD_ == 3 /* This #if _SAMBA_BUILD == 3 is very unfortunate, as it means * that in the top level build, these options are not @@ -126,8 +149,8 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, } #endif - result->tdb = tdb_open_ex(name, hash_size, tdb_flags, - open_flags, mode, &log_ctx, NULL); + result->tdb = tdb_open_compat(name, hash_size, tdb_flags, + open_flags, mode, tdb_wrap_log, NULL); if (result->tdb == NULL) { goto fail; } diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index 92c43d8605..2d49b9e2ec 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -372,6 +372,14 @@ int tdb_unpack(const uint8 *buf, int bufsize, const char *fmt, ...) Log tdb messages via DEBUG(). ****************************************************************************/ +#ifdef BUILD_TDB2 +static void tdb_log(TDB_CONTEXT *tdb, enum tdb_log_level level, + const char *message, void *unused) +{ + DEBUG((int)level, ("tdb(%s): %s", + tdb_name(tdb) ? tdb_name(tdb) : "unnamed", message)); +} +#else static void tdb_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, const char *format, ...) { va_list ap; @@ -388,6 +396,7 @@ static void tdb_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, const char *fo DEBUG((int)level, ("tdb(%s): %s", tdb_name(tdb) ? tdb_name(tdb) : "unnamed", ptr)); SAFE_FREE(ptr); } +#endif /* TDB1 */ /**************************************************************************** Like tdb_open() but also setup a logging function that redirects to @@ -398,14 +407,10 @@ TDB_CONTEXT *tdb_open_log(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode) { TDB_CONTEXT *tdb; - struct tdb_logging_context log_ctx; if (!lp_use_mmap()) tdb_flags |= TDB_NOMMAP; - log_ctx.log_fn = tdb_log; - log_ctx.log_private = NULL; - if ((hash_size == 0) && (name != NULL)) { const char *base = strrchr_m(name, '/'); if (base != NULL) { @@ -417,8 +422,8 @@ TDB_CONTEXT *tdb_open_log(const char *name, int hash_size, int tdb_flags, hash_size = lp_parm_int(-1, "tdb_hashsize", base, 0); } - tdb = tdb_open_ex(name, hash_size, tdb_flags, - open_flags, mode, &log_ctx, NULL); + tdb = tdb_open_compat(name, hash_size, tdb_flags, + open_flags, mode, tdb_log, NULL); if (!tdb) return NULL; diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index a4a54972c9..7c0a6d2a4e 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); diff --git a/source3/printing/tests/vlp.c b/source3/printing/tests/vlp.c index 927224cb2e..66860e5ada 100644 --- a/source3/printing/tests/vlp.c +++ b/source3/printing/tests/vlp.c @@ -392,8 +392,9 @@ int main(int argc, char **argv) return 1; } - if (!(tdb = tdb_open(printdb_path, 0, 0, O_RDWR | O_CREAT, - 0666))) { + /* FIXME: We should *never* open a tdb without logging! */ + if (!(tdb = tdb_open_compat(printdb_path, 0, 0, O_RDWR | O_CREAT, + 0666, NULL, NULL))) { printf("%s: unable to open %s\n", argv[0], printdb_path); return 1; } diff --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c index 988251e878..c196a13ed0 100644 --- a/source3/smbd/mangle_hash.c +++ b/source3/smbd/mangle_hash.c @@ -773,8 +773,13 @@ const struct mangle_fns *mangle_hash_init(void) mangle_reset(); /* Create the in-memory tdb using our custom hash function. */ +#ifndef BUILD_TDB2 tdb_mangled_cache = tdb_open_ex("mangled_cache", 1031, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644, NULL, fast_string_hash); +#else + /* FIXME: We should *never* open a tdb without logging! */ + tdb_mangled_cache = tdb_open("mangled_cache", TDB_INTERNAL, 0, 0, NULL); +#endif return &mangle_hash_fns; } diff --git a/source3/torture/mangle_test.c b/source3/torture/mangle_test.c index b9e3f6a8cf..4fc91dc4b3 100644 --- a/source3/torture/mangle_test.c +++ b/source3/torture/mangle_test.c @@ -181,7 +181,7 @@ bool torture_mangle(int dummy) } /* 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; 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; diff --git a/testsuite/printing/psec.c b/testsuite/printing/psec.c index 2438614996..59205446d0 100644 --- a/testsuite/printing/psec.c +++ b/testsuite/printing/psec.c @@ -171,7 +171,7 @@ int psec_getsec(char *printer) slprintf(tdb_path, sizeof(tdb_path) - 1, "%s/ntdrivers.tdb", lp_lockdir()); - tdb = tdb_open(tdb_path, 0, 0, O_RDONLY, 0600); + tdb = tdb_open_compat(tdb_path, 0, 0, O_RDONLY, 0600, NULL, NULL); if (!tdb) { printf("psec: failed to open nt drivers database: %s\n", @@ -275,7 +275,7 @@ int psec_setsec(char *printer) slprintf(tdb_path, sizeof(tdb_path) - 1, "%s/ntdrivers.tdb", lp_lockdir()); - tdb = tdb_open(tdb_path, 0, 0, O_RDWR, 0600); + tdb = tdb_open_compat(tdb_path, 0, 0, O_RDWR, 0600, NULL, NULL); if (!tdb) { printf("psec: failed to open nt drivers database: %s\n", |