summaryrefslogtreecommitdiff
path: root/source4/lib/db_wrap.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-02-27 11:35:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:10:55 -0500
commitb1b14817eaa6e6579596d54166e17bc8d5605c01 (patch)
treeb1af59838a0337dd52b510374b048255397dfe24 /source4/lib/db_wrap.c
parentd2dc86994e7075490f95faa1cc85008feb38f04a (diff)
downloadsamba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.gz
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.bz2
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.zip
r5585: LDB interfaces change:
changes: - ldb_wrap disappears from code and become a private structure of db_wrap.c thanks to our move to talloc in ldb code, we do not need to expose it anymore - removal of ldb_close() function form the code thanks to our move to talloc in ldb code, we do not need it anymore use talloc_free() to close and free an ldb database - some minor updates to ldb modules code to cope with the change and fix some bugs I found out during the process (This used to be commit d58be9e74b786a11a57e89df36081d55730dfe0a)
Diffstat (limited to 'source4/lib/db_wrap.c')
-rw-r--r--source4/lib/db_wrap.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/source4/lib/db_wrap.c b/source4/lib/db_wrap.c
index 0ec1e378e6..a3a9ee9b86 100644
--- a/source4/lib/db_wrap.c
+++ b/source4/lib/db_wrap.c
@@ -33,6 +33,13 @@
#include "lib/ldb/include/ldb.h"
#include "db_wrap.h"
+struct ldb_wrap {
+ struct ldb_context *ldb;
+
+ const char *url;
+ struct ldb_wrap *next, *prev;
+};
+
static struct ldb_wrap *ldb_list;
static struct tdb_wrap *tdb_list;
@@ -55,53 +62,52 @@ static void ldb_wrap_debug(void *context, enum ldb_debug_level level,
free(s);
}
-
/* destroy the last connection to a ldb */
static int ldb_wrap_destructor(void *ctx)
{
struct ldb_wrap *w = ctx;
- ldb_close(w->ldb);
DLIST_REMOVE(ldb_list, w);
return 0;
}
/*
wrapped connection to a ldb database
- to close just talloc_free() the ldb_wrap pointer
+ to close just talloc_free() the returned ldb_context
*/
-struct ldb_wrap *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
+struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
const char *url,
unsigned int flags,
const char *options[])
{
+ struct ldb_context *ldb;
struct ldb_wrap *w;
- for (w=ldb_list;w;w=w->next) {
+ for (w = ldb_list; w; w = w->next) {
if (strcmp(url, w->url) == 0) {
- return talloc_reference(mem_ctx, w);
+ return talloc_reference(mem_ctx, w->ldb);
}
}
- w = talloc(mem_ctx, struct ldb_wrap);
- if (w == NULL) {
+ ldb = ldb_connect(url, flags, options);
+ if (ldb == NULL) {
return NULL;
}
- w->url = talloc_strdup(w, url);
-
- w->ldb = ldb_connect(url, flags, options);
- if (w->ldb == NULL) {
- talloc_free(w);
+ w = talloc(ldb, struct ldb_wrap);
+ if (w == NULL) {
+ talloc_free(ldb);
return NULL;
}
- talloc_steal(w, w->ldb);
+
+ w->ldb = ldb;
+ w->url = talloc_strdup(w, url);
talloc_set_destructor(w, ldb_wrap_destructor);
- ldb_set_debug(w->ldb, ldb_wrap_debug, NULL);
+ ldb_set_debug(ldb, ldb_wrap_debug, NULL);
DLIST_ADD(ldb_list, w);
- return w;
+ return ldb;
}