svn commit: samba r17830 - in branches/SAMBA_4_0/source: dsdb/samdb dsdb/samdb/ldb_modules lib/ldb/common lib/ldb/include lib/ldb/tools

idra at samba.org idra at samba.org
Fri Aug 25 12:59:08 GMT 2006


Author: idra
Date: 2006-08-25 12:59:03 +0000 (Fri, 25 Aug 2006)
New Revision: 17830

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17830

Log:

Set the default_basedn (hey, it comes from the "default" naming contex :-)
once at connection time, after modules have been loaded.

Introduce a function to retrieve the value where needed.


Modified:
   branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/password_hash.c
   branches/SAMBA_4_0/source/dsdb/samdb/samdb.c
   branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/password_hash.c
===================================================================
--- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/password_hash.c	2006-08-25 12:57:12 UTC (rev 17829)
+++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/password_hash.c	2006-08-25 12:59:03 UTC (rev 17830)
@@ -489,7 +489,7 @@
 		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)))", 

Modified: branches/SAMBA_4_0/source/dsdb/samdb/samdb.c
===================================================================
--- branches/SAMBA_4_0/source/dsdb/samdb/samdb.c	2006-08-25 12:57:12 UTC (rev 17829)
+++ branches/SAMBA_4_0/source/dsdb/samdb/samdb.c	2006-08-25 12:59:03 UTC (rev 17830)
@@ -1026,7 +1026,7 @@
 
 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);
 }
 
 

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-08-25 12:57:12 UTC (rev 17829)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2006-08-25 12:59:03 UTC (rev 17830)
@@ -141,7 +141,42 @@
 	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
    ldb://path
@@ -171,6 +206,9 @@
 	/* 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;
 }
 
@@ -530,37 +568,6 @@
 }
 
 /*
-  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 @@
 	}
 
 	if (base == NULL) {
-		base = ldb_auto_basedn(ldb);
+		base = ldb_get_default_basedn(ldb);
 	}
 
 	req->operation = LDB_SEARCH;

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-08-25 12:57:12 UTC (rev 17829)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-08-25 12:59:03 UTC (rev 17830)
@@ -824,8 +824,9 @@
 
 /*
   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

Modified: branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c	2006-08-25 12:57:12 UTC (rev 17829)
+++ branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c	2006-08-25 12:59:03 UTC (rev 17830)
@@ -219,7 +219,7 @@
 	sctx->refs = 0;
 
 	if (basedn == NULL) {
-		basedn = ldb_auto_basedn(ldb);
+		basedn = ldb_get_default_basedn(ldb);
 	}
 
 	req->operation = LDB_SEARCH;



More information about the samba-cvs mailing list