]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:utils: Migrate oLschema2ldif to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Thu, 14 Jan 2021 09:43:33 +0000 (10:43 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/utils/oLschema2ldif/main.c
source4/utils/oLschema2ldif/wscript_build

index a3445f8ffe67925cce04b0f80e18178b74553bd8..c312298d623488931715094a7d9545636ed03315 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "includes.h"
 #include "./lib.h"
-#include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/cmdline.h"
 
 static struct options {
        const char *basedn;
@@ -41,27 +41,11 @@ static struct options {
        const char *output;
 } options;
 
-static struct poptOption popt_options[] = {
-       POPT_AUTOHELP
-       { "basedn",    'b', POPT_ARG_STRING, &options.basedn, 0, "base DN", "DN" },
-       { "input", 'I', POPT_ARG_STRING, &options.input, 0,
-         "inputfile of OpenLDAP style schema otherwise STDIN", "inputfile"},
-       { "output", 'O', POPT_ARG_STRING, &options.output, 0,
-         "outputfile otherwise STDOUT", "outputfile"},
-       POPT_COMMON_VERSION
-       {0}
-};
-
-
 static void usage(void)
 {
-       poptContext pc;
-       printf("Usage: oLschema2ldif <options>\n");
+       printf("Usage: oLschema2ldif [OPTIONS]\n");
        printf("\nConvert OpenLDAP schema to AD-like LDIF format\n\n");
        printf("Converts records from an openLdap formatted schema to an ldif schema\n\n");
-       pc = poptGetContext("oLschema2ldif", 0, NULL, popt_options,
-                           POPT_CONTEXT_KEEP_FIRST);
-       poptPrintHelp(pc, stdout, 0);
        exit(1);
 }
 
@@ -74,12 +58,34 @@ static void usage(void)
        struct conv_options copt;
        int opt;
 
+       struct poptOption popt_options[] = {
+               POPT_AUTOHELP
+               { "basedn",    'b', POPT_ARG_STRING, &options.basedn, 0, "base DN", "DN" },
+               { "input", 'I', POPT_ARG_STRING, &options.input, 0,
+                 "inputfile of OpenLDAP style schema otherwise STDIN", "inputfile"},
+               { "output", 'O', POPT_ARG_STRING, &options.output, 0,
+                 "outputfile otherwise STDOUT", "outputfile"},
+               POPT_COMMON_VERSION
+               POPT_TABLEEND
+       };
+
        ctx = talloc_new(NULL);
+       if (ctx == NULL) {
+               exit(ENOMEM);
+       }
 
        setenv("LDB_URL", "NONE", 1);
 
-       pc = poptGetContext(argv[0], argc, argv, popt_options,
-                           POPT_CONTEXT_KEEP_FIRST);
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   argv,
+                                   popt_options,
+                                   POPT_CONTEXT_KEEP_FIRST);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               TALLOC_FREE(ctx);
+               exit(1);
+       }
 
        while((opt = poptGetNextOpt(pc)) != -1) {
                fprintf(stderr, "Invalid option %s: %s\n",
index e8ee31a7f8f356e2acce3cd00bdb3051b40286c7..bb39bae90d8632a8b200c9c32648cbd3c3752489 100644 (file)
@@ -8,7 +8,7 @@ bld.SAMBA_SUBSYSTEM('oLschema2ldif-lib',
 bld.SAMBA_BINARY('oLschema2ldif',
        source='main.c',
        manpages='oLschema2ldif.1',
-       deps='oLschema2ldif-lib POPT_SAMBA',
+       deps='oLschema2ldif-lib cmdline',
        )
 
 bld.SAMBA_BINARY('test_oLschema2ldif',