svn commit: samba r7711 - in branches/SAMBA_4_0/source: ldap_server lib

tridge at samba.org tridge at samba.org
Sat Jun 18 07:44:37 GMT 2005


Author: tridge
Date: 2005-06-18 07:44:36 +0000 (Sat, 18 Jun 2005)
New Revision: 7711

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

Log:
update callers of ldb_connect() for new syntax


Modified:
   branches/SAMBA_4_0/source/ldap_server/ldap_rootdse.c
   branches/SAMBA_4_0/source/lib/db_wrap.c


Changeset:
Modified: branches/SAMBA_4_0/source/ldap_server/ldap_rootdse.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_rootdse.c	2005-06-18 07:43:52 UTC (rev 7710)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_rootdse.c	2005-06-18 07:44:36 UTC (rev 7711)
@@ -33,11 +33,6 @@
 	attr->values = blob;\
 } while(0)
 
-struct rootdse_db_context {
-	struct ldb_context *ldb;
-	struct rootdse_db_context **static_ptr;
-};
-
 /*
   this is used to catch debug messages from ldb
 */
@@ -55,60 +50,28 @@
 }
 
 
-/* destroy the last connection to the sam */
-static int rootdse_db_destructor(void *ctx)
-{
-	struct rootdse_db_context *rd_ctx = ctx;
-	talloc_free(rd_ctx->ldb);
-	*(rd_ctx->static_ptr) = NULL;
-	return 0;
-}				 
-
 /*
   connect to the SAM database
-  return an opaque context pointer on success, or NULL on failure
  */
-static void *rootdse_db_connect(TALLOC_CTX *mem_ctx)
+static struct ldb_context *rootdse_db_connect(TALLOC_CTX *mem_ctx)
 {
-	static struct rootdse_db_context *ctx;
 	char *db_path;
-	/*
-	  the way that unix fcntl locking works forces us to have a
-	  static ldb handle here rather than a much more sensible
-	  approach of having the ldb handle as part of the
-	  ldap base structures. Otherwise we would try to open
-	  the ldb more than once, and tdb would rightly refuse the
-	  second open due to the broken nature of unix locking.
-	*/
-	if (ctx != NULL) {
-		return talloc_reference(mem_ctx, ctx);
-	}
+	struct ldb_context *ldb;
 
-	ctx = talloc(mem_ctx, struct rootdse_db_context);
-	if (ctx == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-
-	ctx->static_ptr = &ctx;
-
-	db_path = talloc_asprintf(ctx, "tdb://%s", private_path(ctx, "rootdse.ldb"));
+	db_path = talloc_asprintf(mem_ctx, "tdb://%s", 
+				  private_path(mem_ctx, "rootdse.ldb"));
 	if (db_path == NULL) {
-		errno = ENOMEM;
 		return NULL;
 	}
 
-	DEBUG(10, ("opening %s\n", db_path));
-	ctx->ldb = ldb_connect(db_path, 0, NULL);
-	if (ctx->ldb == NULL) {
-		talloc_free(ctx);
+	ldb = ldb_wrap_connect(mem_ctx, db_path, 0, NULL);
+	if (ldb == NULL) {
 		return NULL;
 	}
 
-	talloc_set_destructor(ctx, rootdse_db_destructor);
-	ldb_set_debug(ctx->ldb, rootdse_db_debug, NULL);
+	ldb_set_debug(ldb, rootdse_db_debug, NULL);
 
-	return ctx;
+	return ldb;
 }
 
 
@@ -305,7 +268,7 @@
 	struct ldb_message **res = NULL;
 	int result = LDAP_SUCCESS;
 	struct ldapsrv_reply *ent_r, *done_r;
-	struct	rootdse_db_context *rootdsedb;
+	struct ldb_context *ldb;
 	const char *errstr = NULL;
 	int count, j, y;
 	const char **attrs = NULL;
@@ -317,11 +280,11 @@
 	local_ctx = talloc_named(call, 0, "rootdse_Search local memory context");
 	NT_STATUS_HAVE_NO_MEMORY(local_ctx);
 
-	rootdsedb = rootdse_db_connect(local_ctx);
-	NT_STATUS_HAVE_NO_MEMORY(rootdsedb);
+	ldb = rootdse_db_connect(local_ctx);
+	NT_STATUS_HAVE_NO_MEMORY(ldb);
 
 	if (r->num_attributes >= 1) {
-		attrs = talloc_array(rootdsedb, const char *, r->num_attributes+1);
+		attrs = talloc_array(ldb, const char *, r->num_attributes+1);
 		NT_STATUS_HAVE_NO_MEMORY(attrs);
 
 		for (j=0; j < r->num_attributes; j++) {
@@ -331,8 +294,8 @@
 		attrs[j] = NULL;
 	}
 
-	count = ldb_search(rootdsedb->ldb, NULL, 0, "dn=cn=rootDSE", attrs, &res);
-	talloc_steal(rootdsedb, res);
+	count = ldb_search(ldb, NULL, 0, "dn=cn=rootDSE", attrs, &res);
+	talloc_steal(local_ctx, res);
 
 	if (count == 1) {
 		ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
@@ -387,7 +350,7 @@
 	} else if (count == 0) {
 		DEBUG(10,("rootdse_Search: no results\n"));
 		result = LDAP_NO_SUCH_OBJECT;
-		errstr = ldb_errstring(rootdsedb->ldb);
+		errstr = ldb_errstring(ldb);
 	} else if (count > 1) {
 		DEBUG(10,("rootdse_Search: too many results[%d]\n", count));
 		result = LDAP_OTHER; 
@@ -395,7 +358,7 @@
 	} else if (count == -1) {
 		DEBUG(10,("rootdse_Search: error\n"));
 		result = LDAP_OTHER;
-		errstr = ldb_errstring(rootdsedb->ldb);
+		errstr = ldb_errstring(ldb);
 	}
 
 	done = &done_r->msg->r.SearchResultDone;

Modified: branches/SAMBA_4_0/source/lib/db_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/db_wrap.c	2005-06-18 07:43:52 UTC (rev 7710)
+++ branches/SAMBA_4_0/source/lib/db_wrap.c	2005-06-18 07:44:36 UTC (rev 7711)
@@ -75,12 +75,13 @@
   to close just talloc_free() the returned ldb_context
  */
 struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
-				  const char *url,
-				  unsigned int flags,
-				  const char *options[])
+				     const char *url,
+				     unsigned int flags,
+				     const char *options[])
 {
 	struct ldb_context *ldb;
 	struct ldb_wrap *w;
+	int ret;
 
 	for (w = ldb_list; w; w = w->next) {
 		if (strcmp(url, w->url) == 0) {
@@ -88,10 +89,16 @@
 		}
 	}
 
-	ldb = ldb_connect(url, flags, options);
+	ldb = ldb_init(talloc_autofree_context());
 	if (ldb == NULL) {
 		return NULL;
 	}
+	
+	ret = ldb_connect(ldb, url, flags, options);
+	if (ret == -1) {
+		talloc_free(ldb);
+		return NULL;
+	}
 
 	w = talloc(ldb, struct ldb_wrap);
 	if (w == NULL) {



More information about the samba-cvs mailing list