diff options
-rw-r--r-- | source4/lib/ldb/tools/ldbdel.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index ddf168d574..5740f22503 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -34,6 +34,14 @@ #include "ldb.h" #include "tools/cmdline.h" +static int dn_cmp(const void *p1, const void *p2) +{ + const struct ldb_message *msg1, *msg2; + msg1 = *(const struct ldb_message * const *)p1; + msg2 = *(const struct ldb_message * const *)p2; + return ldb_dn_compare(msg1->dn, msg2->dn); +} + static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn) { int ret, i, total=0; @@ -43,9 +51,16 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn) ret = ldb_search(ldb, ldb, &res, dn, LDB_SCOPE_SUBTREE, attrs, "distinguishedName=*"); if (ret != LDB_SUCCESS) return -1; + /* sort the DNs, deepest first */ + 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) { total++; + } else { + printf("Failed to delete '%s' - %s\n", + ldb_dn_get_linearized(res->msgs[i]->dn), + ldb_errstring(ldb)); } } |