From ed3d8091ce2b2014350a2f7f22202dde6846a130 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 07:42:21 +0000 Subject: 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) --- source4/lib/ldb/tools/ldbadd.c | 78 +++++++++++++----------------------------- 1 file changed, 23 insertions(+), 55 deletions(-) (limited to 'source4/lib/ldb/tools/ldbadd.c') diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index 818c33a11d..35a41527be 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.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" @@ -86,69 +87,36 @@ static int process_file(struct ldb_context *ldb, FILE *f) - int main(int argc, char * const argv[]) + int main(int argc, const char **argv) { struct ldb_context *ldb; - int count=0; - const char *ldb_url; - const char **options = NULL; - int ldbopts; - int opt, i; - - ldb_url = getenv("LDB_URL"); - - ldbopts = 0; - while ((opt = getopt(argc, argv, "hH:o:")) != EOF) { - switch (opt) { - case 'H': - ldb_url = optarg; - break; - - case 'o': - options = ldb_options_parse(options, &ldbopts, optarg); - break; - - case 'h': - default: - usage(); - break; - } - } + int i, ret, count=0; + struct ldb_cmdline *options; - if (!ldb_url) { - fprintf(stderr, "You must specify an ldb URL\n\n"); - usage(); - } + ldb = ldb_init(NULL); - argc -= optind; - argv += optind; + options = ldb_cmdline_process(ldb, argc, argv, usage); - 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); - - if (argc == 0) { - usage(); - } - - for (i=0;iargc == 0) { + count += process_file(ldb, stdin); + } else { + for (i=0;iargc;i++) { + const char *fname = options->argv[i]; + FILE *f; + f = fopen(fname, "r"); + if (!f) { + perror(fname); + exit(1); + } + count += process_file(ldb, f); fclose(f); } } -- cgit