1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

s4:utils: Migrate oLschema2ldif to new cmdline option parser

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Andreas Schneider 2021-01-14 10:43:33 +01:00 committed by Andrew Bartlett
parent 12ba3d9d8f
commit 91c8c480f6
2 changed files with 27 additions and 21 deletions

View 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",

View 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',