r9623: samba3dump now generates LDIF for the registry hives from registry.tdb
[kai/samba.git] / source4 / lib / db_wrap.c
index c277f2d9752beb7dd6b9b5b7f79eab68c25b6b5b..8698e9affdd5b1c7de3f519ac11b157c3721fe95 100644 (file)
 #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;
 
 /*
@@ -62,14 +54,6 @@ 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;
-       DLIST_REMOVE(ldb_list, w);
-       return 0;
-}                               
-
 /*
   wrapped connection to a ldb database
   to close just talloc_free() the returned ldb_context
@@ -80,18 +64,11 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
                                     const char *options[])
 {
        struct ldb_context *ldb;
-       struct ldb_wrap *w;
        int ret;
        struct event_context *ev;
+       char *real_url = NULL;
 
-
-       for (w = ldb_list; w; w = w->next) {
-               if (strcmp(url, w->url) == 0) {
-                       return talloc_reference(mem_ctx, w->ldb);
-               }
-       }
-
-       ldb = ldb_init(talloc_autofree_context());
+       ldb = ldb_init(mem_ctx);
        if (ldb == NULL) {
                return NULL;
        }
@@ -102,28 +79,32 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
        ev = talloc_find_parent_bytype(mem_ctx, struct event_context);
        if (ev) {
                ldb_set_opaque(ldb, "EventContext", ev);
+       } else {
+               DEBUG(5,("WARNING: event_context not found\n"));
        }
-       
-       ret = ldb_connect(ldb, url, flags, options);
+
+       ret = ldb_register_samba_handlers(ldb);
        if (ret == -1) {
                talloc_free(ldb);
                return NULL;
        }
 
-       w = talloc(ldb, struct ldb_wrap);
-       if (w == NULL) {
+       real_url = private_path(ldb, url);
+       if (real_url == NULL) {
+               talloc_free(ldb);
+               return NULL;
+       }
+       
+       ret = ldb_connect(ldb, real_url, flags, options);
+       if (ret == -1) {
                talloc_free(ldb);
                return NULL;
        }
 
-       w->ldb = ldb;
-       w->url = talloc_strdup(w, url);
+       talloc_free(real_url);
 
-       talloc_set_destructor(w, ldb_wrap_destructor);
        ldb_set_debug(ldb, ldb_wrap_debug, NULL);
 
-       DLIST_ADD(ldb_list, w);
-
        return ldb;
 }