summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-12-08 14:40:20 +1100
committerAndrew Tridgell <tridge@samba.org>2009-12-08 14:43:50 +1100
commitff984cdfac3638e75fdc764d45899fbabb17d291 (patch)
tree629bbd19da2d271f3ff3b9ff135258ba61e6a5d1 /source4/lib
parentb2d8e1118dd8d7826a60ffc5759d6be30a659338 (diff)
downloadsamba-ff984cdfac3638e75fdc764d45899fbabb17d291.tar.gz
samba-ff984cdfac3638e75fdc764d45899fbabb17d291.tar.bz2
samba-ff984cdfac3638e75fdc764d45899fbabb17d291.zip
s4-ldb: fixed ldbdel with -r (recursive deletion)
We need to delete the deepest DNs first
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/tools/ldbdel.c15
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));
}
}