From 338c3f8523d5db2cba1b79f94ff0cecabcd9e9cd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 00:59:38 +0000 Subject: r8625: move the ldb_wrap logic into the ldb code. This logic is meant to avoid the horrors of posix locking, but it was preventing us having an ldb open twice with different options. Now each ldb open of the same file shares the same underlying tdb, but uses a different ldb structure (This used to be commit 4e090c66dfa1d2764e4693578d3845be3b8893f6) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 115 +++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c new file mode 100644 index 0000000000..f58ec7f7ff --- /dev/null +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -0,0 +1,115 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2005 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" +#include "ldb/ldb_tdb/ldb_tdb.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(void *ctx) +{ + struct ltdb_wrap *w = talloc_get_type(ctx, struct ltdb_wrap); + tdb_close(w->tdb); + if (w->next) { + w->next->prev = w->prev; + } + if (w->prev) { + w->prev->next = w->next; + } + if (w == tdb_list) { + tdb_list = w->next; + } + return 0; +} + +/* + wrapped connection to a tdb database. The caller should _not_ free + this as it is not a talloc structure (as tdb does not use talloc + yet). It will auto-close when the caller frees the mem_ctx that is + passed to this call + */ +struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, + const char *path, int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + struct ltdb_wrap *w; + struct stat st; + + if (stat(path, &st) == 0) { + for (w=tdb_list;w;w=w->next) { + if (st.st_dev == w->device && st.st_ino == w->inode) { + talloc_reference(mem_ctx, w); + return w->tdb; + } + } + } + + w = talloc(mem_ctx, struct ltdb_wrap); + if (w == NULL) { + return NULL; + } + + w->tdb = tdb_open(path, hash_size, tdb_flags, open_flags, mode); + if (w->tdb == NULL) { + talloc_free(w); + return NULL; + } + + if (fstat(w->tdb->fd, &st) != 0) { + tdb_close(w->tdb); + talloc_free(w); + return NULL; + } + + w->device = st.st_dev; + w->inode = st.st_ino; + + talloc_set_destructor(w, ltdb_wrap_destructor); + + w->next = tdb_list; + w->prev = NULL; + if (tdb_list) { + tdb_list->prev = w; + } + tdb_list = w; + + return w->tdb; +} + -- cgit From 0868b7c77d42efd5f361f605bfc0d8d46841db95 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 Sep 2005 03:52:42 +0000 Subject: r10253: a fairly large tdb cleanup and re-organise. Nearly all of this change just involves splitting up the core tdb.c code into separate files on logical boundaries, but there are some minor functional changes as well: - move the 'struct tdb_context' into tdb_private.h, hiding it from users. This was done to allow the structure to change without breaking code that uses tdb. - added accessor functions tdb_fd(), tdb_name(), and tdb_log_fn() to access the elements of struct tdb_context that were used by external code but are no longer visible - simplied tdb_append() to use tdb_fetch()/tdb_store(), which is just as good due to the way tdb locks work - changed some of the types (such as tdb_off to tdb_off_t) to make syntax highlighting work better - removed the old optional spinlock code. It was a bad idea. - fixed a bug in tdb_reopen_all() that caused tdbtorture to sometimes fail or report nasty looking errors. This is the only real bug fixed in this commit. Jeremy/Jerry, you might like to pickup this change for Samba3, as that could definately affect smbd in Samba3. The aim of all of these changes is to make the tdb transactions/journaling code I am working on easier to write. I started to write it on top of the existing tdb.c code and it got very messy. Splitting up the code makes it much easier to follow. There are more cleanups we could do in tdb, such as using uint32_t instead of u32 (suggested by metze). I'll leave those for another day. (This used to be commit 4673cdd0d261614e707b72a7a348bb0e7dbb2482) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index f58ec7f7ff..3a18f5df88 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -92,7 +92,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, return NULL; } - if (fstat(w->tdb->fd, &st) != 0) { + if (fstat(tdb_fd(w->tdb), &st) != 0) { tdb_close(w->tdb); talloc_free(w); return NULL; -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 3a18f5df88..c2e65cf825 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -24,7 +24,6 @@ #include "includes.h" #include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" /* -- cgit From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index c2e65cf825..3a18f5df88 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -24,6 +24,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" /* -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 3a18f5df88..d4fc67c2d4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -23,8 +23,8 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" + #include "ldb/ldb_tdb/ldb_tdb.h" /* -- cgit From 971d30bb201f5c3faff5f575d26882eb79f7955a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:34:11 +0000 Subject: r15854: more talloc_set_destructor() typesafe fixes (This used to be commit 61c6100617589ac6df4f527877241464cacbf8b3) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index d4fc67c2d4..fdce36b24c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -43,9 +43,8 @@ struct ltdb_wrap { static struct ltdb_wrap *tdb_list; /* destroy the last connection to a tdb */ -static int ltdb_wrap_destructor(void *ctx) +static int ltdb_wrap_destructor(struct ltdb_wrap *w) { - struct ltdb_wrap *w = talloc_get_type(ctx, struct ltdb_wrap); tdb_close(w->tdb); if (w->next) { w->next->prev = w->prev; -- cgit From d3fee429aee87e9c05a4a606fbf0b60b16dac782 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 3 Jul 2006 06:40:56 +0000 Subject: r16774: This patch modifies the tdb API to allow the logging function to be used as part of ldb. This allows tdb failures to be passed all the way up to Samba's DEBUG system, which allowed easier debugging. Unfortunately I had to extend the tdb API, as the logging function didn't have a context pointer. I've worked over the 'debug levels' in TDB. Most of them were 0, which didn't seem right, as some were trace-like messages. We didn't see any of these previously, except when accessing TDB directly. Andrew Bartlett (This used to be commit 58898092c1ce043f6d698db5065f372b79109e22) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 42 +++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index fdce36b24c..31276d3948 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -58,6 +58,40 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w) return 0; } +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, ...) +{ + va_list ap; + const char *name = tdb_name(tdb); + struct ldb_context *ldb = talloc_get_type(tdb_logging_private(tdb), struct ldb_context); + enum ldb_debug_level ldb_level; + char *message; + va_start(ap, fmt); + message = talloc_vasprintf(ldb, fmt, ap); + va_end(ap); + + switch (level) { + case TDB_DEBUG_FATAL: + ldb_level = LDB_DEBUG_FATAL; + break; + case TDB_DEBUG_ERROR: + ldb_level = LDB_DEBUG_ERROR; + break; + case TDB_DEBUG_WARNING: + ldb_level = LDB_DEBUG_WARNING; + break; + case TDB_DEBUG_TRACE: + ldb_level = LDB_DEBUG_TRACE; + break; + default: + ldb_level = LDB_DEBUG_FATAL; + } + + ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message); + talloc_free(message); +} + + /* wrapped connection to a tdb database. The caller should _not_ free this as it is not a talloc structure (as tdb does not use talloc @@ -65,8 +99,10 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w) passed to this call */ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *path, int hash_size, int tdb_flags, - int open_flags, mode_t mode) + const char *path, int hash_size, + int tdb_flags, + int open_flags, mode_t mode, + struct ldb_context *ldb) { struct ltdb_wrap *w; struct stat st; @@ -85,7 +121,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, return NULL; } - w->tdb = tdb_open(path, hash_size, tdb_flags, open_flags, mode); + w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, ltdb_log_fn, ldb, NULL); if (w->tdb == NULL) { talloc_free(w); return NULL; -- cgit From 35fda6c5f344e71b1ed0bd195a62161e31401149 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 10 Jul 2006 12:51:36 +0000 Subject: r16916: Implement metze's proposed changes to the tdb logging API. This clearly links the log function with its private pointer, and makes the argument list for tdb_open_ex a bit shorter. Andrew Bartlett (This used to be commit 5d5503e8d8a10ead3ef21a5ffda52cadb9a07727) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 31276d3948..df9cac1307 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -63,7 +63,7 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con { va_list ap; const char *name = tdb_name(tdb); - struct ldb_context *ldb = talloc_get_type(tdb_logging_private(tdb), struct ldb_context); + struct ldb_context *ldb = talloc_get_type(tdb_get_logging_private(tdb), struct ldb_context); enum ldb_debug_level ldb_level; char *message; va_start(ap, fmt); @@ -106,6 +106,9 @@ 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) { @@ -121,7 +124,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, ltdb_log_fn, ldb, NULL); + w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL); if (w->tdb == NULL) { talloc_free(w); return NULL; -- cgit From 58619eebc10cf3e1828f8ecad1362d98ca4e9845 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 22 Sep 2006 23:22:39 +0000 Subject: r18831: minor build changes for samba3. The logging changes will be removed when the tdb api is updated (This used to be commit 6ace943fac101839e35cbc83dc54fde2068f704b) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index df9cac1307..7f81949fdc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -58,6 +58,7 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w) return 0; } +#if (_SAMBA_BUILD_ >= 4) 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, ...) { @@ -90,7 +91,22 @@ 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); } - +#else +static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); +static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) +{ + /* until we merge the tdb debug changes into samba3, we don't know + how serious the error is, and we can't go via the ldb loggin code */ + va_list ap; + const char *name = tdb_name(tdb); + char *message; + va_start(ap, fmt); + message = talloc_vasprintf(NULL, fmt, ap); + va_end(ap); + DEBUG(3, ("ltdb: tdb(%s): %s", name, message)); + talloc_free(message); +} +#endif /* wrapped connection to a tdb database. The caller should _not_ free @@ -106,9 +122,14 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, { struct ltdb_wrap *w; struct stat st; +#if (_SAMBA_BUILD_ >= 4) struct tdb_logging_context log_ctx; + struct tdb_logging_context log_ctx_p = &log_ctx; log_ctx.log_fn = ltdb_log_fn; log_ctx.log_private = ldb; +#else + tdb_log_func log_ctx_p = ltdb_log_fn; +#endif if (stat(path, &st) == 0) { for (w=tdb_list;w;w=w->next) { @@ -124,7 +145,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_ex(path, hash_size, tdb_flags, open_flags, mode, log_ctx_p, NULL); if (w->tdb == NULL) { talloc_free(w); return NULL; -- cgit From 0b5e01c19b4c81fd08cfb2ef9410c03f5522d0ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 22 Sep 2006 23:25:16 +0000 Subject: r18832: fixed standalone build (This used to be commit 1ebc098b6776d38451e441280ac13664d64569f4) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 7f81949fdc..654afea2f1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -58,7 +58,22 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w) return 0; } -#if (_SAMBA_BUILD_ >= 4) +#if defined(_SAMBA_BUILD_) && (_SAMBA_BUILD_ <= 3) +static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); +static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) +{ + /* until we merge the tdb debug changes into samba3, we don't know + how serious the error is, and we can't go via the ldb loggin code */ + va_list ap; + const char *name = tdb_name(tdb); + char *message; + va_start(ap, fmt); + message = talloc_vasprintf(NULL, fmt, ap); + va_end(ap); + DEBUG(3, ("ltdb: tdb(%s): %s", name, message)); + talloc_free(message); +} +#else 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, ...) { @@ -91,21 +106,6 @@ 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); } -#else -static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); -static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) -{ - /* until we merge the tdb debug changes into samba3, we don't know - how serious the error is, and we can't go via the ldb loggin code */ - va_list ap; - const char *name = tdb_name(tdb); - char *message; - va_start(ap, fmt); - message = talloc_vasprintf(NULL, fmt, ap); - va_end(ap); - DEBUG(3, ("ltdb: tdb(%s): %s", name, message)); - talloc_free(message); -} #endif /* @@ -122,13 +122,13 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, { struct ltdb_wrap *w; struct stat st; -#if (_SAMBA_BUILD_ >= 4) +#if (_SAMBA_BUILD_ <= 3) + tdb_log_func log_ctx_p = ltdb_log_fn; +#else struct tdb_logging_context log_ctx; struct tdb_logging_context log_ctx_p = &log_ctx; log_ctx.log_fn = ltdb_log_fn; log_ctx.log_private = ldb; -#else - tdb_log_func log_ctx_p = ltdb_log_fn; #endif if (stat(path, &st) == 0) { -- cgit From 45ca27699c018423364a1307b241d6034de1332d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 23 Sep 2006 01:59:48 +0000 Subject: r18834: get the log context code right (This used to be commit b6bb5d7b772467042cee6ea372119781c42b91c1) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 654afea2f1..b28bf77450 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -122,11 +122,11 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, { struct ltdb_wrap *w; struct stat st; -#if (_SAMBA_BUILD_ <= 3) +#if defined(_SAMBA_BUILD_) && (_SAMBA_BUILD_ <= 3) tdb_log_func log_ctx_p = ltdb_log_fn; #else struct tdb_logging_context log_ctx; - struct tdb_logging_context log_ctx_p = &log_ctx; + const struct tdb_logging_context *log_ctx_p = &log_ctx; log_ctx.log_fn = ltdb_log_fn; log_ctx.log_private = ldb; #endif -- cgit From 47f90dde40cf1e31ebc570af315f7fb9f78cd79f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 6 Oct 2006 16:17:19 +0000 Subject: r19146: merge from samba3: talloc_reference() can fail metze (This used to be commit 542cd5d029e97c2e0c7c006a1ced12114c1bb6da) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index b28bf77450..c9eac013fc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -134,7 +134,9 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, if (stat(path, &st) == 0) { for (w=tdb_list;w;w=w->next) { if (st.st_dev == w->device && st.st_ino == w->inode) { - talloc_reference(mem_ctx, w); + if (!talloc_reference(mem_ctx, w)) { + return NULL; + } return w->tdb; } } -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index c9eac013fc..8c232175f4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -22,10 +22,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" -#include "ldb/ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" /* the purpose of this code is to work around the braindead posix locking -- cgit From 57dd8aeee7b2724f286092112f38d7b4e608144a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 4 Jun 2007 14:26:37 +0000 Subject: r23339: merge from SAMBA_3_0: fix a crash bug...I wonder why only HP-UX 11.00 ans 11.11 noticed it via a SIGBUS... I missed to remove the samba3 specifc code path to tdb_open_ex() when I synced lib/tdb/ with samba4. The explicit cast in on tdb_open_ex() dropped the compiler warning :-( metze (This used to be commit df6e3bec368d7d99cb1641023f4cbcd94c438e22) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 8c232175f4..10f27065e4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -57,22 +57,6 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w) return 0; } -#if defined(_SAMBA_BUILD_) && (_SAMBA_BUILD_ <= 3) -static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); -static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) -{ - /* until we merge the tdb debug changes into samba3, we don't know - how serious the error is, and we can't go via the ldb loggin code */ - va_list ap; - const char *name = tdb_name(tdb); - char *message; - va_start(ap, fmt); - message = talloc_vasprintf(NULL, fmt, ap); - va_end(ap); - DEBUG(3, ("ltdb: tdb(%s): %s", name, message)); - talloc_free(message); -} -#else 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, ...) { @@ -105,7 +89,6 @@ 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 /* wrapped connection to a tdb database. The caller should _not_ free @@ -121,14 +104,10 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, { struct ltdb_wrap *w; struct stat st; -#if defined(_SAMBA_BUILD_) && (_SAMBA_BUILD_ <= 3) - tdb_log_func log_ctx_p = ltdb_log_fn; -#else struct tdb_logging_context log_ctx; - const struct tdb_logging_context *log_ctx_p = &log_ctx; + log_ctx.log_fn = ltdb_log_fn; log_ctx.log_private = ldb; -#endif if (stat(path, &st) == 0) { for (w=tdb_list;w;w=w->next) { @@ -146,7 +125,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_p, NULL); + w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL); if (w->tdb == NULL) { talloc_free(w); return NULL; -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 10f27065e4..93933129db 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -10,7 +10,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 93933129db..654574cd2f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -18,8 +18,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ #include "ldb_includes.h" -- cgit From f2f16b45b58c2bbf3053ff55e7a290fc069e0efd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 29 Nov 2007 14:49:47 +0100 Subject: r26197: Add bindings for libsecurity. (This used to be commit 8625cd403ba3a7d2b1b1fccfeb5efd7e21de0135) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 153 --------------------------------- 1 file changed, 153 deletions(-) delete mode 100644 source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c deleted file mode 100644 index 654574cd2f..0000000000 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2005 - - ** NOTE! The following LGPL license applies to the ldb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "ldb_includes.h" - -#include "ldb_tdb.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) -{ - tdb_close(w->tdb); - if (w->next) { - w->next->prev = w->prev; - } - if (w->prev) { - w->prev->next = w->next; - } - if (w == tdb_list) { - tdb_list = w->next; - } - return 0; -} - -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, ...) -{ - va_list ap; - const char *name = tdb_name(tdb); - struct ldb_context *ldb = talloc_get_type(tdb_get_logging_private(tdb), struct ldb_context); - enum ldb_debug_level ldb_level; - char *message; - va_start(ap, fmt); - message = talloc_vasprintf(ldb, fmt, ap); - va_end(ap); - - switch (level) { - case TDB_DEBUG_FATAL: - ldb_level = LDB_DEBUG_FATAL; - break; - case TDB_DEBUG_ERROR: - ldb_level = LDB_DEBUG_ERROR; - break; - case TDB_DEBUG_WARNING: - ldb_level = LDB_DEBUG_WARNING; - break; - case TDB_DEBUG_TRACE: - ldb_level = LDB_DEBUG_TRACE; - break; - default: - ldb_level = LDB_DEBUG_FATAL; - } - - ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message); - talloc_free(message); -} - -/* - wrapped connection to a tdb database. The caller should _not_ free - this as it is not a talloc structure (as tdb does not use talloc - yet). It will auto-close when the caller frees the mem_ctx that is - passed to this call - */ -struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *path, int hash_size, - int tdb_flags, - int open_flags, mode_t mode, - struct ldb_context *ldb) -{ - 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) { - if (st.st_dev == w->device && st.st_ino == w->inode) { - if (!talloc_reference(mem_ctx, w)) { - return NULL; - } - return w->tdb; - } - } - } - - w = talloc(mem_ctx, struct ltdb_wrap); - if (w == NULL) { - return NULL; - } - - w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL); - if (w->tdb == NULL) { - talloc_free(w); - return NULL; - } - - if (fstat(tdb_fd(w->tdb), &st) != 0) { - tdb_close(w->tdb); - talloc_free(w); - return NULL; - } - - w->device = st.st_dev; - w->inode = st.st_ino; - - talloc_set_destructor(w, ltdb_wrap_destructor); - - w->next = tdb_list; - w->prev = NULL; - if (tdb_list) { - tdb_list->prev = w; - } - tdb_list = w; - - return w->tdb; -} - -- cgit From e266efffec0763651b5c5f435d2923e972714251 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 29 Nov 2007 15:08:27 +0100 Subject: r26200: Bring back some accidently removed files. (This used to be commit a71e40ab5dc7f0a5f6d2d1eb930f378cd143b186) --- source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c | 153 +++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c new file mode 100644 index 0000000000..654574cd2f --- /dev/null +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -0,0 +1,153 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2005 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . +*/ + +#include "ldb_includes.h" + +#include "ldb_tdb.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) +{ + tdb_close(w->tdb); + if (w->next) { + w->next->prev = w->prev; + } + if (w->prev) { + w->prev->next = w->next; + } + if (w == tdb_list) { + tdb_list = w->next; + } + return 0; +} + +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, ...) +{ + va_list ap; + const char *name = tdb_name(tdb); + struct ldb_context *ldb = talloc_get_type(tdb_get_logging_private(tdb), struct ldb_context); + enum ldb_debug_level ldb_level; + char *message; + va_start(ap, fmt); + message = talloc_vasprintf(ldb, fmt, ap); + va_end(ap); + + switch (level) { + case TDB_DEBUG_FATAL: + ldb_level = LDB_DEBUG_FATAL; + break; + case TDB_DEBUG_ERROR: + ldb_level = LDB_DEBUG_ERROR; + break; + case TDB_DEBUG_WARNING: + ldb_level = LDB_DEBUG_WARNING; + break; + case TDB_DEBUG_TRACE: + ldb_level = LDB_DEBUG_TRACE; + break; + default: + ldb_level = LDB_DEBUG_FATAL; + } + + ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message); + talloc_free(message); +} + +/* + wrapped connection to a tdb database. The caller should _not_ free + this as it is not a talloc structure (as tdb does not use talloc + yet). It will auto-close when the caller frees the mem_ctx that is + passed to this call + */ +struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, + const char *path, int hash_size, + int tdb_flags, + int open_flags, mode_t mode, + struct ldb_context *ldb) +{ + 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) { + if (st.st_dev == w->device && st.st_ino == w->inode) { + if (!talloc_reference(mem_ctx, w)) { + return NULL; + } + return w->tdb; + } + } + } + + w = talloc(mem_ctx, struct ltdb_wrap); + if (w == NULL) { + return NULL; + } + + w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL); + if (w->tdb == NULL) { + talloc_free(w); + return NULL; + } + + if (fstat(tdb_fd(w->tdb), &st) != 0) { + tdb_close(w->tdb); + talloc_free(w); + return NULL; + } + + w->device = st.st_dev; + w->inode = st.st_ino; + + talloc_set_destructor(w, ltdb_wrap_destructor); + + w->next = tdb_list; + w->prev = NULL; + if (tdb_list) { + tdb_list->prev = w; + } + tdb_list = w; + + return w->tdb; +} + -- cgit