s4: make ldbadd/ldbmodify/ldbdelete really use the --controls switch
[kai/samba-autobuild/.git] / source4 / lib / ldb / tools / ldbdel.c
index 5740f22503afecb1bab536e5947a9b26729afa27..4180afb99c31ea4e5d91ca930230a9c258612ab6 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "ldb.h"
 #include "tools/cmdline.h"
+#include "ldbutil.h"
 
 static int dn_cmp(const void *p1, const void *p2)
 {
@@ -42,7 +43,7 @@ static int dn_cmp(const void *p1, const void *p2)
        return ldb_dn_compare(msg1->dn, msg2->dn);
 }
 
-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 };
@@ -55,7 +56,7 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)
        qsort(res->msgs, res->count, sizeof(res->msgs[0]), dn_cmp);
 
        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++;
                } else {
                        printf("Failed to delete '%s' - %s\n",
@@ -95,6 +96,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;
@@ -105,9 +111,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");
                        }