From 14750139639b3531e57a3ca3f9e481d6e458dc06 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 4 May 2011 10:28:15 +1000 Subject: lib/util Move source3 tdb_wrap_open() into the common code. This #if _SAMBA_BUILD == 3 is very unfortunate, as it means that in the top level build, these options are not available for these databases. However, having two different tdb_wrap lists is a worse fate, so this will do for now. Andrew Bartlett --- source4/lib/messaging/messaging.c | 2 +- source4/lib/tdb_wrap.c | 117 -------------------------------------- source4/lib/tdb_wrap.h | 45 --------------- source4/lib/wscript_build | 9 --- 4 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 source4/lib/tdb_wrap.c delete mode 100644 source4/lib/tdb_wrap.h (limited to 'source4/lib') diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 1b0fc1291c..3a330d5794 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -27,7 +27,7 @@ #include "lib/socket/socket.h" #include "librpc/gen_ndr/ndr_irpc.h" #include "lib/messaging/irpc.h" -#include "tdb_wrap.h" +#include "lib/util/tdb_wrap.h" #include "../lib/util/unix_privs.h" #include "librpc/rpc/dcerpc.h" #include diff --git a/source4/lib/tdb_wrap.c b/source4/lib/tdb_wrap.c deleted file mode 100644 index 97294e13d3..0000000000 --- a/source4/lib/tdb_wrap.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - Unix SMB/CIFS implementation. - TDB wrap functions - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include -#include "../lib/util/dlinklist.h" -#include "tdb_wrap.h" -#include - -static struct tdb_wrap *tdb_list; - -/* destroy the last connection to a tdb */ -static int tdb_wrap_destructor(struct tdb_wrap *w) -{ - tdb_close(w->tdb); - DLIST_REMOVE(tdb_list, w); - return 0; -} - -/* - Log tdb messages via DEBUG(). -*/ -static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, - const char *format, ...) PRINTF_ATTRIBUTE(3,4); - -static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, - const char *format, ...) -{ - va_list ap; - char *ptr = NULL; - int dl; - - va_start(ap, format); - vasprintf(&ptr, format, ap); - va_end(ap); - - switch (level) { - case TDB_DEBUG_FATAL: - dl = 0; - break; - case TDB_DEBUG_ERROR: - dl = 1; - break; - case TDB_DEBUG_WARNING: - dl = 2; - break; - case TDB_DEBUG_TRACE: - dl = 5; - break; - default: - dl = 0; - } - - if (ptr != NULL) { - const char *name = tdb_name(tdb); - DEBUG(dl, ("tdb(%s): %s", name ? name : "unnamed", ptr)); - free(ptr); - } -} - - -/* - wrapped connection to a tdb database - to close just talloc_free() the tdb_wrap pointer - */ -struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) -{ - struct tdb_wrap *w; - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_wrap_log; - - for (w=tdb_list;w;w=w->next) { - if (strcmp(name, w->name) == 0) { - return talloc_reference(mem_ctx, w); - } - } - - w = talloc(mem_ctx, struct tdb_wrap); - if (w == NULL) { - return NULL; - } - - w->name = talloc_strdup(w, name); - - w->tdb = tdb_open_ex(name, hash_size, tdb_flags, - open_flags, mode, &log_ctx, NULL); - if (w->tdb == NULL) { - talloc_free(w); - return NULL; - } - - talloc_set_destructor(w, tdb_wrap_destructor); - - DLIST_ADD(tdb_list, w); - - return w; -} diff --git a/source4/lib/tdb_wrap.h b/source4/lib/tdb_wrap.h deleted file mode 100644 index 94035c1bea..0000000000 --- a/source4/lib/tdb_wrap.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - database wrap headers - - Copyright (C) Andrew Tridgell 2004 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/* IMPORTANT: tdb_wrap should be always preferred over tdb_context for end consumer functions - it's because if the code will be running inside smbd, then we must use the linked list - of open tdb files, to determine if the tdb we desire is already open - as otherwise, when you close the tdb (even on a different file descriptor), - ALL LOCKS are lost (due to a real screwup in the POSIX specification that nobody has been able to get fixed) -*/ - -#ifndef _TDB_WRAP_H_ -#define _TDB_WRAP_H_ - -#include - -struct tdb_wrap { - struct tdb_context *tdb; - - const char *name; - struct tdb_wrap *next, *prev; -}; - -struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); - -#endif /* _TDB_WRAP_H_ */ diff --git a/source4/lib/wscript_build b/source4/lib/wscript_build index 872259d670..cf60820da7 100644 --- a/source4/lib/wscript_build +++ b/source4/lib/wscript_build @@ -5,12 +5,3 @@ bld.SAMBA_SUBSYSTEM('GENCACHE', enabled=False, deps='tdb-wrap' ) - - -bld.SAMBA_LIBRARY('tdb-wrap', - source='tdb_wrap.c', - deps='tdb talloc samba-util', - public_headers='tdb_wrap.h', - private_library=True - ) - -- cgit