r9685: Add tests for samba3sam mapping module
[sfrench/samba-autobuild/.git] / source4 / lib / ldb / tools / cmdline.c
index 31d3f2662a54adeea979d30e2db2dae680af56a3..fb0292b7d9ea8c6b9be43916e280b386ee65b0ce 100644 (file)
@@ -38,8 +38,11 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
 {
        struct ldb_cmdline options, *ret=NULL;
        poptContext pc;
-       int r, num_options = 0;
-       char opt;
+#ifdef _SAMBA_BUILD_
+       int r;
+#endif
+        int num_options = 0;
+       int opt;
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
                { "url",       'H', POPT_ARG_STRING, &options.url, 0, "database URL", "URL" },
@@ -54,6 +57,8 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                { "all", 'a',    POPT_ARG_NONE, &options.all_records, 0, "dn=*", NULL },
                { "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL },
                { "sasl-mechanism", 0, POPT_ARG_STRING, &options.sasl_mechanism, 0, "choose SASL mechanism", "MECHANISM" },
+               { "input", 'I', POPT_ARG_STRING, &options.input, 0, "Input File", "Input" },
+               { "output", 'O', POPT_ARG_STRING, &options.output, 0, "Output File", "Output" },
                { NULL,    'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
 #ifdef _SAMBA_BUILD_
                POPT_COMMON_SAMBA
@@ -119,13 +124,14 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
 
                case 'o':
                        options.options = talloc_realloc(ret, options.options, 
-                                                        const char *, num_options+2);
+                                                        const char *, num_options+3);
                        if (options.options == NULL) {
                                ldb_oom(ldb);
                                goto failed;
                        }
-                       options.options[num_options++] = poptGetOptArg(pc);
+                       options.options[num_options] = poptGetOptArg(pc);
                        options.options[num_options+1] = NULL;
+                       num_options++;
                        break;
                        
                default:
@@ -152,10 +158,12 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                goto failed;
        }
 
-       if (ldb_connect(ldb, ret->url, 0, ret->options) != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       ret->url, ldb_errstring(ldb));
-               goto failed;
+       if (strcmp(ret->url, "NONE") != 0) {
+               if (ldb_connect(ldb, ret->url, 0, ret->options) != 0) {
+                       fprintf(stderr, "Failed to connect to %s - %s\n", 
+                               ret->url, ldb_errstring(ldb));
+                       goto failed;
+               }
        }
 
        return ret;