s4-dsdb: call dsdb_make_schema_global() from ldb_wrap
[ira/wip.git] / source4 / dsdb / samdb / samdb.c
index e361cc78fb9a866e760aca102d450400091c19af..b3ba63388d71e4e693b56c0e12beb96ea11cc8d6 100644 (file)
@@ -55,6 +55,9 @@ char *samdb_relative_path(struct ldb_context *ldb,
        if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
                return talloc_strdup(mem_ctx, name);
        }
+       if (strncmp("tdb://", base_url, 6) == 0) {
+               base_url = base_url+6;
+       }
        path = talloc_strdup(mem_ctx, base_url);
        if (path == NULL) {
                return NULL;
@@ -69,11 +72,29 @@ char *samdb_relative_path(struct ldb_context *ldb,
        return full_name;
 }
 
-struct cli_credentials *samdb_credentials(TALLOC_CTX *mem_ctx, 
-                                         struct tevent_context *event_ctx, 
+/*
+  make sure the static credentials are not freed
+ */
+static int samdb_credentials_destructor(struct cli_credentials *creds)
+{
+       return -1;
+}
+
+/*
+  this returns a static set of system credentials. It is static so
+  that we always get the same pointer in ldb_wrap_connect()
+ */
+struct cli_credentials *samdb_credentials(struct tevent_context *event_ctx, 
                                          struct loadparm_context *lp_ctx) 
 {
-       struct cli_credentials *cred = cli_credentials_init(mem_ctx);
+       static struct cli_credentials *static_credentials;
+       struct cli_credentials *cred;
+
+       if (static_credentials) {
+               return static_credentials;
+       }
+
+       cred = cli_credentials_init(talloc_autofree_context());
        if (!cred) {
                return NULL;
        }
@@ -87,8 +108,11 @@ struct cli_credentials *samdb_credentials(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(cli_credentials_set_secrets(cred, event_ctx, lp_ctx, NULL, NULL,
                                                         SECRETS_LDAP_FILTER))) {
                /* Perfectly OK - if not against an LDAP backend */
+               talloc_free(cred);
                return NULL;
        }
+       static_credentials = cred;
+       talloc_set_destructor(cred, samdb_credentials_destructor);
        return cred;
 }
 
@@ -104,12 +128,11 @@ struct ldb_context *samdb_connect(TALLOC_CTX *mem_ctx,
        struct ldb_context *ldb;
        ldb = ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, 
                               lp_sam_url(lp_ctx), session_info,
-                              samdb_credentials(mem_ctx, ev_ctx, lp_ctx), 
-                              0, NULL);
+                              samdb_credentials(ev_ctx, lp_ctx), 
+                              0);
        if (!ldb) {
                return NULL;
        }
-       dsdb_make_schema_global(ldb);
        return ldb;
 }