s4:dsdb/subtree_delete: delete from the leafs to the root (bug #7711)
authorStefan Metzmacher <metze@samba.org>
Sat, 24 Nov 2012 09:16:45 +0000 (10:16 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 30 Nov 2012 16:17:21 +0000 (17:17 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source4/dsdb/samdb/ldb_modules/subtree_delete.c

index f041b7e66ea19a75424fba14f13c65cff4b07890..b1f87f77b544ef99c15fc059c046902ef21e7ddd 100644 (file)
 #include "dsdb/common/util.h"
 
 
+static int subtree_delete_sort(struct ldb_message **m1,
+                              struct ldb_message **m2,
+                              void *private_data)
+{
+       struct ldb_dn *dn1 = (*m1)->dn;
+       struct ldb_dn *dn2 = (*m2)->dn;
+
+       /*
+        * This sorts in tree order, children first
+        */
+       return ldb_dn_compare(dn1, dn2);
+}
+
 static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
 {
        static const char * const attrs[] = { NULL };
@@ -79,6 +92,12 @@ static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
                return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF;
        }
 
+       /*
+        * First we sort the results from the leaf to the root
+        */
+       LDB_TYPESAFE_QSORT(res->msgs, res->count, NULL,
+                          subtree_delete_sort);
+
        /*
         * we need to start from the top since other LDB modules could
         * enforce constraints (eg "objectclass" and "samldb" do so).