svn commit: samba r17349 - in branches/SAMBA_4_0/source/lib/ldb: ldb_ildap ldb_tdb

abartlet at samba.org abartlet at samba.org
Tue Aug 1 02:25:07 GMT 2006


Author: abartlet
Date: 2006-08-01 02:25:05 +0000 (Tue, 01 Aug 2006)
New Revision: 17349

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

Log:
We can't just return sucess here, modules below us expect the async
reply rules to be followed.

Add code to do a fake async callback on the skipped records.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c	2006-07-31 21:40:25 UTC (rev 17348)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_ildap/ldb_ildap.c	2006-08-01 02:25:05 UTC (rev 17349)
@@ -323,21 +323,18 @@
 	}
 }
 
-static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg,
-			     void *context,
-			     int (*callback)(struct ldb_context *, void *, struct ldb_reply *),
-			     int timeout,
-			     struct ldb_handle **handle)
+static struct ldb_handle *init_ildb_handle(struct ldb_module *module, 
+					   void *context,
+					   int (*callback)(struct ldb_context *, void *, struct ldb_reply *))
 {
 	struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
 	struct ildb_context *ildb_ac;
 	struct ldb_handle *h;
-	struct ldap_request *req;
 
 	h = talloc_zero(ildb->ldap, struct ldb_handle);
 	if (h == NULL) {
 		ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory"));
-		return LDB_ERR_OPERATIONS_ERROR;
+		return NULL;
 	}
 
 	h->module = module;
@@ -346,7 +343,7 @@
 	if (ildb_ac == NULL) {
 		ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory"));
 		talloc_free(h);
-		return LDB_ERR_OPERATIONS_ERROR;
+		return NULL;
 	}
 
 	h->private_data = (void *)ildb_ac;
@@ -354,6 +351,30 @@
 	h->state = LDB_ASYNC_INIT;
 	h->status = LDB_SUCCESS;
 
+	ildb_ac->module = module;
+	ildb_ac->context = context;
+	ildb_ac->callback = callback;
+
+	return h;
+}
+
+static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg,
+			     void *context,
+			     int (*callback)(struct ldb_context *, void *, struct ldb_reply *),
+			     int timeout,
+			     struct ldb_handle **handle)
+{
+	struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
+	struct ldb_handle *h = init_ildb_handle(module, context, callback);
+	struct ildb_context *ildb_ac;
+	struct ldap_request *req;
+
+	if (!h) {
+		return LDB_ERR_OPERATIONS_ERROR;		
+	}
+
+	ildb_ac = talloc_get_type(h->private_data, struct ildb_context);
+
 	req = ldap_request_send(ildb->ldap, msg);
 	if (req == NULL) {
 		ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed"));
@@ -366,13 +387,6 @@
 	}
 
 	ildb_ac->req = talloc_steal(ildb_ac, req);
-	ildb_ac->module = module;
-	ildb_ac->context = context;
-	ildb_ac->callback = callback;
-
-	req->async.fn = ildb_callback;
-	req->async.private_data = (void *)h;
-
 	talloc_free(req->time_event);
 	req->time_event = NULL;
 	if (timeout) {
@@ -381,10 +395,32 @@
 						  ildb_request_timeout, h);
 	}
 
+	req->async.fn = ildb_callback;
+	req->async.private_data = (void *)h;
+
 	*handle = h;
-
 	return LDB_SUCCESS;
+}
 
+static int ildb_request_noop(struct ldb_module *module, struct ldb_request *req) 
+{
+	struct ldb_handle *h = init_ildb_handle(module, req->context, req->callback);
+	struct ildb_context *ildb_ac;
+	int ret = LDB_SUCCESS;
+
+	if (!h) {
+		return LDB_ERR_OPERATIONS_ERROR;		
+	}
+
+	ildb_ac = talloc_get_type(h->private_data, struct ildb_context);
+	
+	req->handle = h;
+
+	if (ildb_ac->callback) {
+		ret = ildb_ac->callback(module->ldb, ildb_ac->context, NULL);
+	}
+	req->handle->state = LDB_ASYNC_DONE;
+	return ret;
 }
 
 /*
@@ -466,7 +502,7 @@
 
 	/* ignore ltdb specials */
 	if (ldb_dn_is_special(req->op.add.message->dn)) {
-		return LDB_SUCCESS;
+		return ildb_request_noop(module, req);
 	}
 
 	msg = new_ldap_message(ildb->ldap);
@@ -516,7 +552,7 @@
 
 	/* ignore ltdb specials */
 	if (ldb_dn_is_special(req->op.mod.message->dn)) {
-		return LDB_SUCCESS;
+		return ildb_request_noop(module, req);
 	}
 
 	msg = new_ldap_message(ildb->ldap);
@@ -564,7 +600,7 @@
 
 	/* ignore ltdb specials */
 	if (ldb_dn_is_special(req->op.del.dn)) {
-		return LDB_SUCCESS;
+		return ildb_request_noop(module, req);
 	}
 
 	msg = new_ldap_message(ildb->ldap);
@@ -595,7 +631,7 @@
 
 	/* ignore ltdb specials */
 	if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) {
-		return LDB_SUCCESS;
+		return ildb_request_noop(module, req);
 	}
 
 	msg = new_ldap_message(ildb->ldap);

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-07-31 21:40:25 UTC (rev 17348)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-08-01 02:25:05 UTC (rev 17349)
@@ -270,35 +270,42 @@
 	}
 
 	ret = ltdb_store(module, msg, TDB_INSERT);
-	if (ret != LDB_SUCCESS) {
-		switch (ret) {
-		case LDB_ERR_ENTRY_ALREADY_EXISTS:
-		{
-			TALLOC_CTX *mem_ctx = talloc_new(module);
-			char *errstring, *dn;
-			if (!mem_ctx) {
-				break;
-			}
-			dn = ldb_dn_linearize(mem_ctx, msg->dn);
-			if (!dn) {
-				break;
-			}
-			errstring = talloc_asprintf(mem_ctx, "Entry %s already exists",
-						    dn);
-			ldb_set_errstring(module->ldb, errstring);
-			talloc_free(mem_ctx);
+	switch (ret) {
+	case LDB_SUCCESS:
+	{
+		TALLOC_CTX *mem_ctx = talloc_new(module);
+		char *dn;
+		dn = ldb_dn_linearize(mem_ctx, msg->dn);
+		if (!dn) {
 			break;
 		}
+		ret = ltdb_modified(module, msg->dn);
+		if (ret != LDB_SUCCESS) {
+			return LDB_ERR_OPERATIONS_ERROR;
 		}
-		return ret;
+		break;
 	}
-
-	ret = ltdb_modified(module, msg->dn);
-	if (ret != LDB_SUCCESS) {
-		return LDB_ERR_OPERATIONS_ERROR;
+	case LDB_ERR_ENTRY_ALREADY_EXISTS:
+	{
+		TALLOC_CTX *mem_ctx = talloc_new(module);
+		char *errstring, *dn;
+		if (!mem_ctx) {
+			break;
+		}
+		dn = ldb_dn_linearize(mem_ctx, msg->dn);
+		if (!dn) {
+			break;
+		}
+		errstring = talloc_asprintf(mem_ctx, "Entry %s already exists",
+					    dn);
+		ldb_set_errstring(module->ldb, errstring);
+		talloc_free(mem_ctx);
+		break;
 	}
-
-	return LDB_SUCCESS;
+	default:
+		break;
+	}
+	return ret;
 }
 
 /*



More information about the samba-cvs mailing list