From cccaef9e0896e9a3fcf9b860283543fd35d3f248 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 8 Apr 2008 14:34:30 +0200 Subject: Use popt in libetapi example code. Guenther (This used to be commit 6f239df3f5a57c9549f1637e53fd42d2ed604c3f) --- .../examples/getjoinableous/getjoinableous.c | 76 ++++++++++------------ 1 file changed, 33 insertions(+), 43 deletions(-) (limited to 'source3/lib/netapi/examples/getjoinableous') diff --git a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c index be95198bcf..732f73dd57 100644 --- a/source3/lib/netapi/examples/getjoinableous/getjoinableous.c +++ b/source3/lib/netapi/examples/getjoinableous/getjoinableous.c @@ -19,72 +19,61 @@ #include #include +#include #include #include -char *get_string_param(const char *param) -{ - char *p; - - p = strchr(param, '='); - if (!p) { - return NULL; - } - - return (p+1); -} +#include "common.h" -int main(int argc, char **argv) +int main(int argc, const char **argv) { NET_API_STATUS status; - const char *server_name = NULL; + const char *host_name = NULL; const char *domain_name = NULL; - const char *account = NULL; - const char *password = NULL; const char **ous = NULL; uint32_t num_ous = 0; struct libnetapi_ctx *ctx = NULL; int i; + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "domain", 0, POPT_ARG_STRING, NULL, 'D', "Domain name", "DOMAIN" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + status = libnetapi_init(&ctx); if (status != 0) { return status; } - if (argc < 2) { - printf("usage: getjoinableous\n"); - printf("\t [domain=DOMAIN] \n"); - return 0; - } + pc = poptGetContext("getjoinableous", argc, argv, long_options, 0); - if (argc > 2) { - server_name = argv[1]; + poptSetOtherOptionHelp(pc, "hostname domainname"); + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'D': + domain_name = poptGetOptArg(pc); + break; + } } - for (i=0; iusername, + ctx->password, &num_ous, &ous); if (status != 0) { @@ -97,9 +86,10 @@ int main(int argc, char **argv) } } + out: NetApiBufferFree(ous); - libnetapi_free(ctx); + poptFreeContext(pc); return status; } -- cgit