From 443d8fd05e6aa558c218d843f98c3ce3ae6d4963 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Sep 2004 12:39:41 +0000 Subject: r2726: added a -r option to ldbdel to allow easy delete of a whole subtree. Useful when cleaning up a mess after testing. (This used to be commit 476674af5519960300c0a07349c7cdf307af3822) --- source4/lib/ldb/tools/ldbdel.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools') diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index 2977357ced..d36db5429a 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -34,10 +34,35 @@ #include "includes.h" +static int ldb_delete_recursive(struct ldb_context *ldb, const char *dn) +{ + int ret, i, total=0; + const char *attrs[] = { "dn", NULL }; + struct ldb_message **res; + + ret = ldb_search(ldb, dn, LDB_SCOPE_SUBTREE, "dn=*", attrs, &res); + if (ret <= 0) return -1; + + for (i=0;idn) == 0) { + total++; + } + } + + ldb_search_free(ldb, res); + + if (total == 0) { + return -1; + } + printf("Deleted %d records\n", total); + return 0; +} + static void usage(void) { printf("Usage: ldbdel \n"); printf("Options:\n"); + printf(" -r recursively delete the given subtree\n"); printf(" -H ldb_url choose the database (or $LDB_URL)\n"); printf("\n"); printf("Deletes records from a ldb\n\n"); @@ -49,16 +74,20 @@ static void usage(void) struct ldb_context *ldb; int ret, i; const char *ldb_url; - int opt; + int opt, recursive=0; ldb_url = getenv("LDB_URL"); - while ((opt = getopt(argc, argv, "hH:")) != EOF) { + while ((opt = getopt(argc, argv, "hH:r")) != EOF) { switch (opt) { case 'H': ldb_url = optarg; break; + case 'r': + recursive=1; + break; + case 'h': default: usage(); @@ -88,7 +117,14 @@ static void usage(void) ldb_set_debug_stderr(ldb); for (i=0;i