diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-09-28 12:39:41 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:27 -0500 |
commit | 443d8fd05e6aa558c218d843f98c3ce3ae6d4963 (patch) | |
tree | 5b3b1eacb5a4e4ece3ebd6b0c076fbab88f79043 /source4 | |
parent | ca3765ca7834e4184745b861d3a9e3e7db19bd14 (diff) | |
download | samba-443d8fd05e6aa558c218d843f98c3ce3ae6d4963.tar.gz samba-443d8fd05e6aa558c218d843f98c3ce3ae6d4963.tar.bz2 samba-443d8fd05e6aa558c218d843f98c3ce3ae6d4963.zip |
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)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/ldb/tools/ldbdel.c | 42 |
1 files changed, 39 insertions, 3 deletions
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;i<ret;i++) { + if (ldb_delete(ldb, res[i]->dn) == 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 <options> <DN...>\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<argc;i++) { - ret = ldb_delete(ldb, argv[i]); + if (recursive) { + ret = ldb_delete_recursive(ldb, argv[i]); + } else { + ret = ldb_delete(ldb, argv[i]); + if (ret == 0) { + printf("Deleted 1 record\n"); + } + } if (ret != 0) { printf("delete of '%s' failed - %s\n", argv[i], ldb_errstring(ldb)); |