[PATCH 1/2] s4: make ldbadd/ldbmodify/ldbdelete really use the --controls switch

Matthieu Patou mat at matws.net
Sat Dec 5 06:51:15 MST 2009


---
 source4/lib/ldb/common/ldb.c      |   25 ++++++++++++++++++++++---
 source4/lib/ldb/tools/ldbadd.c    |    8 +++++++-
 source4/lib/ldb/tools/ldbdel.c    |   13 +++++++++----
 source4/lib/ldb/tools/ldbmodify.c |   13 +++++++++----
 4 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 94a5fb2..a15dcbe 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -1363,6 +1363,16 @@ done:
 int ldb_add(struct ldb_context *ldb,
 	    const struct ldb_message *message)
 {
+	return ldb_add_ctrl(ldb,message,NULL);
+}
+
+/*
+  Same as ldb_add but accept control
+*/
+int ldb_add_ctrl(struct ldb_context *ldb,
+		const struct ldb_message *message,
+		struct ldb_control **controls)
+{
 	struct ldb_request *req;
 	int ret;
 
@@ -1373,7 +1383,7 @@ int ldb_add(struct ldb_context *ldb,
 
 	ret = ldb_build_add_req(&req, ldb, ldb,
 					message,
-					NULL,
+					controls,
 					NULL,
 					ldb_op_default_callback,
 					NULL);
@@ -1386,7 +1396,6 @@ int ldb_add(struct ldb_context *ldb,
 	talloc_free(req);
 	return ret;
 }
-
 /*
   same as ldb_modify, but accepts controls
 */
@@ -1432,12 +1441,21 @@ int ldb_modify(struct ldb_context *ldb,
 */
 int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn)
 {
+	return ldb_delete_ctrl(ldb, dn, NULL);
+}
+
+/*
+  same as ldb_delete but accept control
+*/
+int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
+		struct ldb_control **controls)
+{
 	struct ldb_request *req;
 	int ret;
 
 	ret = ldb_build_del_req(&req, ldb, ldb,
 					dn,
-					NULL,
+					controls,
 					NULL,
 					ldb_op_default_callback,
 					NULL);
@@ -1451,6 +1469,7 @@ int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn)
 	return ret;
 }
 
+
 /*
   rename a record in the database
 */
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index a87c99a..748fe30 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -53,6 +53,12 @@ static int process_file(struct ldb_context *ldb, FILE *f, int *count)
 {
 	struct ldb_ldif *ldif;
 	int ret = LDB_SUCCESS;
+        struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls);
+	if (options->controls != NULL &&  req_ctrls== NULL) {
+		printf("parsing controls failed: %s\n", ldb_errstring(ldb));
+		return -1;
+	}
+
 
 	while ((ldif = ldb_ldif_read_file(ldb, f))) {
 		if (ldif->changetype != LDB_CHANGETYPE_ADD &&
@@ -63,7 +69,7 @@ static int process_file(struct ldb_context *ldb, FILE *f, int *count)
 
 		ldif->msg = ldb_msg_canonicalize(ldb, ldif->msg);
 
-		ret = ldb_add(ldb, ldif->msg);
+		ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls);
 		if (ret != LDB_SUCCESS) {
 			fprintf(stderr, "ERR: \"%s\" on DN %s\n", 
 				ldb_errstring(ldb), ldb_dn_get_linearized(ldif->msg->dn));
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index ddf168d..da5f907 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -34,7 +34,7 @@
 #include "ldb.h"
 #include "tools/cmdline.h"
 
-static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)
+static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
 {
 	int ret, i, total=0;
 	const char *attrs[] = { NULL };
@@ -44,7 +44,7 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)
 	if (ret != LDB_SUCCESS) return -1;
 
 	for (i = 0; i < res->count; i++) {
-		if (ldb_delete(ldb, res->msgs[i]->dn) == 0) {
+		if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == 0) {
 			total++;
 		}
 	}
@@ -80,6 +80,11 @@ int main(int argc, const char **argv)
 		usage();
 		exit(1);
 	}
+        struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls);
+	if (options->controls != NULL &&  req_ctrls== NULL) {
+		printf("parsing controls failed: %s\n", ldb_errstring(ldb));
+		return -1;
+	}
 
 	for (i=0;i<options->argc;i++) {
 		struct ldb_dn *dn;
@@ -90,9 +95,9 @@ int main(int argc, const char **argv)
 			exit(1);
 		}
 		if (options->recursive) {
-			ret = ldb_delete_recursive(ldb, dn);
+			ret = ldb_delete_recursive(ldb, dn,req_ctrls);
 		} else {
-			ret = ldb_delete(ldb, dn);
+			ret = ldb_delete_ctrl(ldb, dn,req_ctrls);
 			if (ret == 0) {
 				printf("Deleted 1 record\n");
 			}
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index 4936880..f9e654a 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -52,18 +52,23 @@ static int process_file(struct ldb_context *ldb, FILE *f, int *count)
 {
 	struct ldb_ldif *ldif;
 	int ret = LDB_SUCCESS;
-	
+	struct ldb_control **req_ctrls = ldb_parse_control_strings(ldb, ldb, (const char **)options->controls);
+	if (options->controls != NULL &&  req_ctrls== NULL) {
+		printf("parsing controls failed: %s\n", ldb_errstring(ldb));
+		return -1;
+	}
+
 	while ((ldif = ldb_ldif_read_file(ldb, f))) {
 		switch (ldif->changetype) {
 		case LDB_CHANGETYPE_NONE:
 		case LDB_CHANGETYPE_ADD:
-			ret = ldb_add(ldb, ldif->msg);
+			ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls);
 			break;
 		case LDB_CHANGETYPE_DELETE:
-			ret = ldb_delete(ldb, ldif->msg->dn);
+			ret = ldb_delete_ctrl(ldb, ldif->msg->dn,req_ctrls);
 			break;
 		case LDB_CHANGETYPE_MODIFY:
-			ret = ldb_modify(ldb, ldif->msg);
+			ret = ldb_modify_ctrl(ldb, ldif->msg,req_ctrls);
 			break;
 		}
 		if (ret != LDB_SUCCESS) {
-- 
1.6.3.3


--------------090300080104080000030609--


More information about the samba-technical mailing list