dsdb-acl: talloc_free the private context when we pass to the next module
[Samba/gebeck_regimport.git] / source3 / lib / netapi / examples / common.c
blobbdc866926b0cf8b61d4451ea70e69199c7104762
1 #include <stdlib.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <inttypes.h>
6 #include <popt.h>
7 #include <netapi.h>
9 #include "common.h"
11 void popt_common_callback(poptContext con,
12 enum poptCallbackReason reason,
13 const struct poptOption *opt,
14 const char *arg, const void *data)
16 struct libnetapi_ctx *ctx = NULL;
18 libnetapi_getctx(&ctx);
20 if (reason == POPT_CALLBACK_REASON_PRE) {
23 if (reason == POPT_CALLBACK_REASON_POST) {
26 if (!opt) {
27 return;
29 switch (opt->val) {
30 case 'U': {
31 char *puser = strdup(arg);
32 char *p = NULL;
34 if ((p = strchr(puser,'%'))) {
35 size_t len;
36 *p = 0;
37 libnetapi_set_username(ctx, puser);
38 libnetapi_set_password(ctx, p+1);
39 len = strlen(p+1);
40 memset(strchr(arg,'%')+1,'X',len);
41 } else {
42 libnetapi_set_username(ctx, puser);
44 free(puser);
45 break;
47 case 'd':
48 libnetapi_set_debuglevel(ctx, arg);
49 break;
50 case 'p':
51 libnetapi_set_password(ctx, arg);
52 break;
53 case 'k':
54 libnetapi_set_use_kerberos(ctx);
55 break;
59 struct poptOption popt_common_netapi_examples[] = {
60 { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback },
61 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" },
62 { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" },
63 { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" },
64 { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL },
65 POPT_TABLEEND