diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-06-18 07:42:21 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:18:24 -0500 |
commit | ed3d8091ce2b2014350a2f7f22202dde6846a130 (patch) | |
tree | 8c1d6ee74907c2c0c2e82b9476ad1db08d7a2179 /source4/lib/ldb/tools/ldbdel.c | |
parent | d4d6d0d2e54510690fa3f868ad02625bc24e5b9d (diff) | |
download | samba-ed3d8091ce2b2014350a2f7f22202dde6846a130.tar.gz samba-ed3d8091ce2b2014350a2f7f22202dde6846a130.tar.bz2 samba-ed3d8091ce2b2014350a2f7f22202dde6846a130.zip |
r7709: - convert ldb to use popt, so that it can interact with the samba
cmdline credentials code (which will be done soon)
- added a ldb_init() call, and changed ldb_connect() to take a ldb
context. This allows for much better error handling in
ldb_connect(), and also made the popt conversion easier
- fixed up all the existing backends with the new syntax
- improved error handling in *_connect()
- fixed a crash bug in the new case_fold_required() code
- ensured that ltdb_rename() and all ltdb_search() paths get the read lock
- added a ldb_oom() macro to make it easier to report out of memory
situations in ldb code
(This used to be commit f648fdf187669d6d87d01dd4e786b03cd420f220)
Diffstat (limited to 'source4/lib/ldb/tools/ldbdel.c')
-rw-r--r-- | source4/lib/ldb/tools/ldbdel.c | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index ec2e302b20..fcf1d26d53 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -35,6 +35,7 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" +#include "ldb/tools/cmdline.h" #ifdef _SAMBA_BUILD_ #include "system/filesys.h" @@ -77,72 +78,41 @@ static void usage(void) exit(1); } - int main(int argc, char * const argv[]) + int main(int argc, const char **argv) { struct ldb_context *ldb; - const char **options = NULL; - int ldbopts; int ret, i; - const char *ldb_url; - int opt, recursive=0; - - ldb_url = getenv("LDB_URL"); - - ldbopts = 0; - while ((opt = getopt(argc, argv, "hH:ro:")) != EOF) { - switch (opt) { - case 'H': - ldb_url = optarg; - break; - - case 'r': - recursive=1; - break; - - case 'o': - options = ldb_options_parse(options, &ldbopts, optarg); - break; - - case 'h': - default: - usage(); - break; - } - } + struct ldb_cmdline *options; - if (!ldb_url) { - fprintf(stderr, "You must specify a ldb URL\n\n"); - usage(); - } + ldb = ldb_init(NULL); - argc -= optind; - argv += optind; + options = ldb_cmdline_process(ldb, argc, argv, usage); - if (argc < 1) { + if (options->argc < 1) { usage(); exit(1); } - ldb = ldb_connect(ldb_url, 0, options); - if (!ldb) { - perror("ldb_connect"); + ret = ldb_connect(ldb, options->url, 0, options->options); + if (ret != 0) { + fprintf(stderr, "Failed to connect to %s - %s\n", + options->url, ldb_errstring(ldb)); + talloc_free(ldb); exit(1); } - ldb_set_debug_stderr(ldb); - - for (i=0;i<argc;i++) { - if (recursive) { - ret = ldb_delete_recursive(ldb, argv[i]); + for (i=0;i<options->argc;i++) { + const char *dn = options->argv[i]; + if (options->recursive) { + ret = ldb_delete_recursive(ldb, dn); } else { - ret = ldb_delete(ldb, argv[i]); + ret = ldb_delete(ldb, dn); if (ret == 0) { printf("Deleted 1 record\n"); } } if (ret != 0) { - printf("delete of '%s' failed - %s\n", - argv[i], ldb_errstring(ldb)); + printf("delete of '%s' failed - %s\n", dn, ldb_errstring(ldb)); } } |