diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-11-16 20:12:00 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 05:45:40 +0100 |
commit | ca0b72a1fdb7bd965065e833df34662afef0423e (patch) | |
tree | 4030d16b135f54cdbbffa61dba2c6e9bda1766d2 /source4/lib | |
parent | b7c5d2b0c9e3366e61bf83ea7b49aff4da05ac0d (diff) | |
download | samba-ca0b72a1fdb7bd965065e833df34662afef0423e.tar.gz samba-ca0b72a1fdb7bd965065e833df34662afef0423e.tar.bz2 samba-ca0b72a1fdb7bd965065e833df34662afef0423e.zip |
r26003: Split up DB_WRAP, as first step in an attempt to sanitize dependencies.
(This used to be commit 56dfcb4f2f8e74c9d8b2fe3a0df043781188a555)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/basic.mk | 14 | ||||
-rw-r--r-- | source4/lib/dbwrap/dbwrap_tdb.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/tools/cmdline.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb_wrap.c (renamed from source4/lib/db_wrap.c) | 101 | ||||
-rw-r--r-- | source4/lib/ldb_wrap.h | 41 | ||||
-rw-r--r-- | source4/lib/messaging/config.mk | 2 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.c | 2 | ||||
-rw-r--r-- | source4/lib/registry/ldb.c | 2 | ||||
-rw-r--r-- | source4/lib/tdb_wrap.c | 117 | ||||
-rw-r--r-- | source4/lib/tdb_wrap.h (renamed from source4/lib/db_wrap.h) | 14 | ||||
-rw-r--r-- | source4/lib/util/config.mk | 10 | ||||
-rw-r--r-- | source4/lib/util/util_ldb.c (renamed from source4/lib/gendb.c) | 8 | ||||
-rw-r--r-- | source4/lib/util/util_ldb.h | 55 |
13 files changed, 251 insertions, 119 deletions
diff --git a/source4/lib/basic.mk b/source4/lib/basic.mk index d1ed7ede0d..0a0c8237ee 100644 --- a/source4/lib/basic.mk +++ b/source4/lib/basic.mk @@ -29,9 +29,13 @@ OBJ_FILES = compression/mszip.o PRIVATE_PROTO_HEADER = gencache/gencache.h OBJ_FILES = gencache/gencache.o \ -[SUBSYSTEM::DB_WRAP] -PUBLIC_PROTO_HEADER = db_wrap_proto.h -PUBLIC_HEADERS = db_wrap.h -OBJ_FILES = db_wrap.o gendb.o -PUBLIC_DEPENDENCIES = LIBTDB LIBLDB +[SUBSYSTEM::LDB_WRAP] +PUBLIC_HEADERS = ldb_wrap.h +OBJ_FILES = ldb_wrap.o +PUBLIC_DEPENDENCIES = LIBLDB PRIVATE_DEPENDENCIES = LDBSAMBA + +[SUBSYSTEM::TDB_WRAP] +PUBLIC_HEADERS = tdb_wrap.h +OBJ_FILES = tdb_wrap.o +PUBLIC_DEPENDENCIES = LIBTDB diff --git a/source4/lib/dbwrap/dbwrap_tdb.c b/source4/lib/dbwrap/dbwrap_tdb.c index b256b6ccc4..621b19532d 100644 --- a/source4/lib/dbwrap/dbwrap_tdb.c +++ b/source4/lib/dbwrap/dbwrap_tdb.c @@ -24,7 +24,7 @@ #include "lib/tdb/include/tdb.h" #include "lib/dbwrap/dbwrap.h" #include "system/filesys.h" -#include "db_wrap.h" +#include "tdb_wrap.h" #include "param/param.h" struct db_tdb_ctx { diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c index a713f54e68..01ef04f5d2 100644 --- a/source4/lib/ldb/tools/cmdline.c +++ b/source4/lib/ldb/tools/cmdline.c @@ -30,7 +30,7 @@ #include "lib/ldb-samba/ldif_handlers.h" #include "auth/gensec/gensec.h" #include "auth/auth.h" -#include "db_wrap.h" +#include "ldb_wrap.h" #endif diff --git a/source4/lib/db_wrap.c b/source4/lib/ldb_wrap.c index c33786a1e4..659b91d254 100644 --- a/source4/lib/db_wrap.c +++ b/source4/lib/ldb_wrap.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. - database wrap functions + LDB wrap functions Copyright (C) Andrew Tridgell 2004 @@ -27,18 +27,15 @@ */ #include "includes.h" -#include "lib/util/dlinklist.h" #include "lib/events/events.h" -#include "lib/tdb/include/tdb.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" #include "lib/ldb-samba/ldif_handlers.h" -#include "db_wrap.h" +#include "ldb_wrap.h" #include "dsdb/samdb/samdb.h" +#include "dsdb/schema/proto.h" #include "param/param.h" -static struct tdb_wrap *tdb_list; - /* this is used to catch debug messages from ldb */ @@ -71,11 +68,6 @@ static void ldb_wrap_debug(void *context, enum ldb_debug_level level, free(s); } -char *wrap_casefold(void *context, void *mem_ctx, const char *s) -{ - return strupper_talloc(mem_ctx, s); -} - /* check for memory leaks on the ldb context */ static int ldb_wrap_destructor(struct ldb_context *ldb) { @@ -192,91 +184,4 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx, } -/* - 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 debug_level; - - va_start(ap, format); - vasprintf(&ptr, format, ap); - va_end(ap); - - switch (level) { - case TDB_DEBUG_FATAL: - debug_level = 0; - break; - case TDB_DEBUG_ERROR: - debug_level = 1; - break; - case TDB_DEBUG_WARNING: - debug_level = 2; - break; - case TDB_DEBUG_TRACE: - debug_level = 5; - break; - default: - debug_level = 0; - } - - if (ptr != NULL) { - const char *name = tdb_name(tdb); - DEBUG(debug_level, ("tdb(%s): %s", name ? name : "unnamed", ptr)); - free(ptr); - } -} - -/* 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; -} - -/* - 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/ldb_wrap.h b/source4/lib/ldb_wrap.h new file mode 100644 index 0000000000..d3ff04b880 --- /dev/null +++ b/source4/lib/ldb_wrap.h @@ -0,0 +1,41 @@ +/* + 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef _LDB_WRAP_H_ +#define _LDB_WRAP_H_ + +struct auth_session_info; +struct ldb_message; +struct ldb_dn; +struct cli_credentials; +struct loadparm_context; + +char *wrap_casefold(void *context, void *mem_ctx, const char *s); + +struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx, + const char *url, + struct auth_session_info *session_info, + struct cli_credentials *credentials, + unsigned int flags, + const char *options[]); + +#endif /* _LDB_WRAP_H_ */ diff --git a/source4/lib/messaging/config.mk b/source4/lib/messaging/config.mk index 85a5791703..843851e853 100644 --- a/source4/lib/messaging/config.mk +++ b/source4/lib/messaging/config.mk @@ -6,7 +6,7 @@ OBJ_FILES = \ messaging.o PUBLIC_DEPENDENCIES = \ LIBSAMBA-UTIL \ - DB_WRAP \ + TDB_WRAP \ NDR_IRPC \ UNIX_PRIVS \ UTIL_TDB \ diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 963dfe4f0c..df0bfa32a6 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 "db_wrap.h" +#include "tdb_wrap.h" #include "lib/util/unix_privs.h" #include "librpc/rpc/dcerpc.h" #include "lib/tdb/include/tdb.h" diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 4a6ef65bc4..fdd4c27599 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -21,7 +21,7 @@ #include "registry.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" -#include "db_wrap.h" +#include "ldb_wrap.h" #include "librpc/gen_ndr/winreg.h" #include "param/param.h" diff --git a/source4/lib/tdb_wrap.c b/source4/lib/tdb_wrap.c new file mode 100644 index 0000000000..37095dff2c --- /dev/null +++ b/source4/lib/tdb_wrap.c @@ -0,0 +1,117 @@ +/* + Unix SMB/CIFS implementation. + TDB wrap functions + + Copyright (C) Andrew Tridgell 2004 + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "lib/tdb/include/tdb.h" +#include "lib/util/dlinklist.h" +#include "tdb_wrap.h" +#include "tdb.h" + +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 debug_level; + + va_start(ap, format); + vasprintf(&ptr, format, ap); + va_end(ap); + + switch (level) { + case TDB_DEBUG_FATAL: + debug_level = 0; + break; + case TDB_DEBUG_ERROR: + debug_level = 1; + break; + case TDB_DEBUG_WARNING: + debug_level = 2; + break; + case TDB_DEBUG_TRACE: + debug_level = 5; + break; + default: + debug_level = 0; + } + + if (ptr != NULL) { + const char *name = tdb_name(tdb); + DEBUG(debug_level, ("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/db_wrap.h b/source4/lib/tdb_wrap.h index b45a05c24f..bb36cabd40 100644 --- a/source4/lib/db_wrap.h +++ b/source4/lib/tdb_wrap.h @@ -19,6 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef _TDB_WRAP_H_ +#define _TDB_WRAP_H_ + +#include "tdb.h" struct tdb_wrap { struct tdb_context *tdb; @@ -27,10 +31,8 @@ struct tdb_wrap { struct tdb_wrap *next, *prev; }; -struct auth_session_info; -struct ldb_message; -struct ldb_dn; -struct cli_credentials; -struct loadparm_context; +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); -#include "lib/db_wrap_proto.h" +#endif /* _TDB_WRAP_H_ */ diff --git a/source4/lib/util/config.mk b/source4/lib/util/config.mk index 0691bd7889..01ad14aa95 100644 --- a/source4/lib/util/config.mk +++ b/source4/lib/util/config.mk @@ -49,12 +49,14 @@ PUBLIC_DEPENDENCIES = XATTR # End SUBSYSTEM WRAP_XATTR ################################################ -################################################ -# Start SUBSYSTEM UTIL_TDB [SUBSYSTEM::UTIL_TDB] PUBLIC_PROTO_HEADER = util_tdb.h OBJ_FILES = \ util_tdb.o PUBLIC_DEPENDENCIES = LIBTDB -# End SUBSYSTEM UTIL_TDB -################################################ + +[SUBSYSTEM::UTIL_LDB] +PUBLIC_PROTO_HEADER = util_ldb.h +OBJ_FILES = \ + util_ldb.o +PUBLIC_DEPENDENCIES = LIBLDB diff --git a/source4/lib/gendb.c b/source4/lib/util/util_ldb.c index 35b55a1fd7..ba8443c236 100644 --- a/source4/lib/gendb.c +++ b/source4/lib/util/util_ldb.c @@ -23,7 +23,6 @@ #include "includes.h" #include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" -#include "lib/db_wrap.h" /* search the sam for the specified attributes - va_list variant @@ -123,3 +122,10 @@ int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string) talloc_free(ldif); return ret; } + +char *wrap_casefold(void *context, void *mem_ctx, const char *s) +{ + return strupper_talloc(mem_ctx, s); +} + + diff --git a/source4/lib/util/util_ldb.h b/source4/lib/util/util_ldb.h new file mode 100644 index 0000000000..f4f56d6b18 --- /dev/null +++ b/source4/lib/util/util_ldb.h @@ -0,0 +1,55 @@ +#ifndef __LIB_UTIL_UTIL_LDB_H__ +#define __LIB_UTIL_UTIL_LDB_H__ + +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) PRINTF_ATTRIBUTE(a1, a2) +/* This file was automatically generated by mkproto.pl. DO NOT EDIT */ + +#ifndef _PUBLIC_ +#define _PUBLIC_ +#endif + +#ifndef _PURE_ +#define _PURE_ +#endif + +#ifndef _NORETURN_ +#define _NORETURN_ +#endif + +#ifndef _DEPRECATED_ +#define _DEPRECATED_ +#endif + +#ifndef _WARN_UNUSED_RESULT_ +#define _WARN_UNUSED_RESULT_ +#endif + + +/* The following definitions come from lib/util/util_ldb.c */ + +int gendb_search_v(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***msgs, + const char * const *attrs, + const char *format, + va_list ap) _PRINTF_ATTRIBUTE(6,0); +int gendb_search(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *basedn, + struct ldb_message ***res, + const char * const *attrs, + const char *format, ...) _PRINTF_ATTRIBUTE(6,7); +int gendb_search_dn(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_message ***res, + const char * const *attrs); +int gendb_add_ldif(struct ldb_context *ldb, const char *ldif_string); +char *wrap_casefold(void *context, void *mem_ctx, const char *s); +#undef _PRINTF_ATTRIBUTE +#define _PRINTF_ATTRIBUTE(a1, a2) + +#endif /* __LIB_UTIL_UTIL_LDB_H__ */ + |