diff options
author | Günther Deschner <gd@samba.org> | 2008-04-08 14:34:30 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2008-04-08 14:34:30 +0200 |
commit | cccaef9e0896e9a3fcf9b860283543fd35d3f248 (patch) | |
tree | ba1c3244a682376c347ab1f8974b1e19106ac0f3 /source3/lib/netapi/examples/netdomjoin/netdomjoin.c | |
parent | 0f86cc18ff2e88a0f1fe244574ff5e3fcfce2f92 (diff) | |
download | samba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.tar.gz samba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.tar.bz2 samba-cccaef9e0896e9a3fcf9b860283543fd35d3f248.zip |
Use popt in libetapi example code.
Guenther
(This used to be commit 6f239df3f5a57c9549f1637e53fd42d2ed604c3f)
Diffstat (limited to 'source3/lib/netapi/examples/netdomjoin/netdomjoin.c')
-rw-r--r-- | source3/lib/netapi/examples/netdomjoin/netdomjoin.c | 96 |
1 files changed, 39 insertions, 57 deletions
diff --git a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c index 29f66a17a2..bd7c36382a 100644 --- a/source3/lib/netapi/examples/netdomjoin/netdomjoin.c +++ b/source3/lib/netapi/examples/netdomjoin/netdomjoin.c @@ -25,96 +25,78 @@ #include <netapi.h> -char *get_string_param(const char *param) -{ - char *p; +#include "common.h" - p = strchr(param, '='); - if (!p) { - return NULL; - } +enum { + OPT_OU = 1000 +}; - return (p+1); -} - -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_ou = NULL; - const char *Account = NULL; + const char *account = NULL; const char *password = NULL; - uint32_t join_flags = 3; + uint32_t join_flags = 0x00000023; struct libnetapi_ctx *ctx = NULL; - int i; + + poptContext pc; + int opt; + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "ou", 0, POPT_ARG_STRING, &account_ou, 'U', "Account ou", "ACCOUNT_OU" }, + { "domain", 0, POPT_ARG_STRING, &domain_name, 'U', "Domain name (required)", "DOMAIN" }, + { "userd", 0, POPT_ARG_STRING, &account, 'U', "Domain admin account", "USERNAME" }, + { "passwordd", 0, POPT_ARG_STRING, &password, 'U', "Domain admin password", "PASSWORD" }, + POPT_COMMON_LIBNETAPI_EXAMPLES + POPT_TABLEEND + }; + status = libnetapi_init(&ctx); if (status != 0) { return status; } - if (argc < 2) { - printf("usage: netdomjoin\n"); - printf("\t[hostname] [domain=DOMAIN] <ou=OU> " - "<usero=USERO> <passwordo=PASSWORDO> " - "<userd=USERD> <passwordd=PASSWORDD> " - "<debug=DEBUGLEVEL>\n"); - return 0; + pc = poptGetContext("netdomjoin", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "hostname"); + while((opt = poptGetNextOpt(pc)) != -1) { } - if (argc > 2) { - server_name = argv[1]; + if (!poptPeekArg(pc)) { + poptPrintHelp(pc, stderr, 0); + goto out; } + host_name = poptGetArg(pc); - for (i=0; i<argc; i++) { - if (strncasecmp(argv[i], "ou", strlen("ou")) == 0) { - account_ou = get_string_param(argv[i]); - } - if (strncasecmp(argv[i], "domain", strlen("domain"))== 0) { - domain_name = get_string_param(argv[i]); - } - if (strncasecmp(argv[i], "userd", strlen("userd"))== 0) { - Account = get_string_param(argv[i]); - } - if (strncasecmp(argv[i], "passwordd", strlen("passwordd"))== 0) { - password = get_string_param(argv[i]); - } - if (strncasecmp(argv[i], "usero", strlen("usero"))== 0) { - const char *str = NULL; - str = get_string_param(argv[i]); - libnetapi_set_username(ctx, str); - } - if (strncasecmp(argv[i], "passwordo", strlen("passwordo"))== 0) { - const char *str = NULL; - str = get_string_param(argv[i]); - libnetapi_set_password(ctx, str); - } - if (strncasecmp(argv[i], "debug", strlen("debug"))== 0) { - const char *str = NULL; - str = get_string_param(argv[i]); - libnetapi_set_debuglevel(ctx, str); - } + if (!domain_name) { + poptPrintHelp(pc, stderr, 0); + goto out; } - status = NetJoinDomain(server_name, + /* NetJoinDomain */ + + status = NetJoinDomain(host_name, domain_name, account_ou, - Account, + account, password, join_flags); if (status != 0) { const char *errstr = NULL; errstr = libnetapi_get_error_string(ctx, status); - if (!errstr) { - errstr = libnetapi_errstr(status); - } printf("Join failed with: %s\n", errstr); } else { printf("Successfully joined\n"); } + out: libnetapi_free(ctx); + poptFreeContext(pc); return status; } |