From: Andreas Schneider Date: Thu, 14 Jan 2021 09:43:33 +0000 (+0100) Subject: s4:utils: Migrate oLschema2ldif to new cmdline option parser X-Git-Tag: tevent-0.11.0~281 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=91c8c480f6f7b05cc86b55160b224cd489af95e4;p=thirdparty%2Fsamba.git s4:utils: Migrate oLschema2ldif to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source4/utils/oLschema2ldif/main.c b/source4/utils/oLschema2ldif/main.c index a3445f8ffe6..c312298d623 100644 --- a/source4/utils/oLschema2ldif/main.c +++ b/source4/utils/oLschema2ldif/main.c @@ -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 \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", diff --git a/source4/utils/oLschema2ldif/wscript_build b/source4/utils/oLschema2ldif/wscript_build index e8ee31a7f8f..bb39bae90d8 100644 --- a/source4/utils/oLschema2ldif/wscript_build +++ b/source4/utils/oLschema2ldif/wscript_build @@ -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',