r17830: Set the default_basedn (hey, it comes from the "default" naming contex :-)
authorSimo Sorce <idra@samba.org>
Fri, 25 Aug 2006 12:59:03 +0000 (12:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:16:46 +0000 (14:16 -0500)
once at connection time, after modules have been loaded.

Introduce a function to retrieve the value where needed.

source/dsdb/samdb/ldb_modules/password_hash.c
source/dsdb/samdb/samdb.c
source/lib/ldb/common/ldb.c
source/lib/ldb/include/ldb.h
source/lib/ldb/tools/ldbsearch.c

index e8b9307cf568216bbd1fff92ab9dece8b9ad353c..2fcfdff997cfb928e1aa5f4052e19253431d8b9a 100644 (file)
@@ -489,7 +489,7 @@ static int build_domain_data_request(struct ph_context *ac)
                return LDB_ERR_OPERATIONS_ERROR;
        }
        ac->dom_req->operation = LDB_SEARCH;
-       ac->dom_req->op.search.base = ldb_auto_basedn(ac->module->ldb);
+       ac->dom_req->op.search.base = ldb_get_default_basedn(ac->module->ldb);
        ac->dom_req->op.search.scope = LDB_SCOPE_SUBTREE;
 
        filter = talloc_asprintf(ac->dom_req, "(&(objectSid=%s)(|(objectClass=domain)(objectClass=builtinDomain)))", 
index dd671e6a2b991571a2bd8985bdab1a851e53661f..e57a9b1aa292110ef140a378bd15381ec99a22fa 100644 (file)
@@ -1026,7 +1026,7 @@ struct security_descriptor *samdb_default_security_descriptor(TALLOC_CTX *mem_ct
 
 const struct ldb_dn *samdb_base_dn(struct ldb_context *sam_ctx) 
 {
-       return ldb_auto_basedn(sam_ctx);
+       return ldb_get_default_basedn(sam_ctx);
 }
 
 
index db5333187b6a97fac35ba1d82ab9371bfb010dda..04ac3e7d812136115f3bf79937155f01973d7508 100644 (file)
@@ -141,6 +141,41 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
        return ret;
 }
 
+/*
+  try to autodetect a basedn if none specified. This fixes one of my
+  pet hates about ldapsearch, which is that you have to get a long,
+  complex basedn right to make any use of it.
+*/
+static const struct ldb_dn *ldb_set_default_basedn(struct ldb_context *ldb)
+{
+       TALLOC_CTX *tmp_ctx;
+       int ret;
+       static const char *attrs[] = { "defaultNamingContext", NULL };
+       struct ldb_result *res;
+       struct ldb_dn *basedn=NULL;
+
+       basedn = ldb_get_opaque(ldb, "default_baseDN");
+       if (basedn) {
+               return basedn;
+       }
+
+       tmp_ctx = talloc_new(ldb);
+       ret = ldb_search(ldb, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE, 
+                        "(objectClass=*)", attrs, &res);
+       if (ret == LDB_SUCCESS && res->count == 1) {
+               basedn = ldb_msg_find_attr_as_dn(ldb, res->msgs[0], "defaultNamingContext");
+       }
+
+       ldb_set_opaque(ldb, "default_baseDN", basedn);
+
+       talloc_free(tmp_ctx);
+       return basedn;
+}
+
+const struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
+{
+       return ldb_get_opaque(ldb, "default_baseDN");
+}
 
 /* 
  connect to a database. The URL can either be one of the following forms
@@ -171,6 +206,9 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
        /* TODO: get timeout from options if available there */
        ldb->default_timeout = 300; /* set default to 5 minutes */
 
+       /* set the default base dn */
+       ldb_set_default_basedn(ldb);
+
        return LDB_SUCCESS;
 }
 
@@ -529,37 +567,6 @@ error:
        return LDB_ERR_OPERATIONS_ERROR;
 }
 
-/*
-  try to autodetect a basedn if none specified. This fixes one of my
-  pet hates about ldapsearch, which is that you have to get a long,
-  complex basedn right to make any use of it.
-*/
-const struct ldb_dn *ldb_auto_basedn(struct ldb_context *ldb)
-{
-       TALLOC_CTX *tmp_ctx;
-       int ret;
-       static const char *attrs[] = { "defaultNamingContext", NULL };
-       struct ldb_result *res;
-       struct ldb_dn *basedn=NULL;
-
-       basedn = ldb_get_opaque(ldb, "auto_baseDN");
-       if (basedn) {
-               return basedn;
-       }
-
-       tmp_ctx = talloc_new(ldb);
-       ret = ldb_search(ldb, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE, 
-                        "(objectClass=*)", attrs, &res);
-       if (ret == LDB_SUCCESS && res->count == 1) {
-               basedn = ldb_msg_find_attr_as_dn(ldb, res->msgs[0], "defaultNamingContext");
-       }
-
-       ldb_set_opaque(ldb, "auto_baseDN", basedn);
-
-       talloc_free(tmp_ctx);
-       return basedn;
-}
-
 /*
   note that ldb_search() will automatically replace a NULL 'base' value with the 
   defaultNamingContext from the rootDSE if available.
@@ -583,7 +590,7 @@ int ldb_search(struct ldb_context *ldb,
        }
 
        if (base == NULL) {
-               base = ldb_auto_basedn(ldb);
+               base = ldb_get_default_basedn(ldb);
        }
 
        req->operation = LDB_SEARCH;
index 415eacbf610d7c33b3a4c88173c4ddafe43082ce..124cba9b66a137ec5efdaeac6f49c761e9f855af 100644 (file)
@@ -824,8 +824,9 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
 
 /*
   return an automatic baseDN from the defaultNamingContext of the rootDSE
+  This value have been set in an opaque pointer at connection time
 */
-const struct ldb_dn *ldb_auto_basedn(struct ldb_context *ldb);
+const struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb);
 
 /**
   Search the database
index f151164559dd5bae98c57848cd88db9e4003fa04..e6b8a48a95857b3915429c09abc4dee59d2efe9b 100644 (file)
@@ -219,7 +219,7 @@ static int do_search(struct ldb_context *ldb,
        sctx->refs = 0;
 
        if (basedn == NULL) {
-               basedn = ldb_auto_basedn(ldb);
+               basedn = ldb_get_default_basedn(ldb);
        }
 
        req->operation = LDB_SEARCH;