tevent: add tevent_req_defer_callback()
[Samba/gebeck_regimport.git] / source3 / lib / netapi / examples / common.c
blob74e28616bfe7d018eb52ce81461882606c618097
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 void popt_common_callback(poptContext con,
10 enum poptCallbackReason reason,
11 const struct poptOption *opt,
12 const char *arg, const void *data)
14 struct libnetapi_ctx *ctx = NULL;
16 libnetapi_getctx(&ctx);
18 if (reason == POPT_CALLBACK_REASON_PRE) {
21 if (reason == POPT_CALLBACK_REASON_POST) {
24 if (!opt) {
25 return;
27 switch (opt->val) {
28 case 'U': {
29 char *puser = strdup(arg);
30 char *p = NULL;
32 if ((p = strchr(puser,'%'))) {
33 size_t len;
34 *p = 0;
35 libnetapi_set_username(ctx, puser);
36 libnetapi_set_password(ctx, p+1);
37 len = strlen(p+1);
38 memset(strchr(arg,'%')+1,'X',len);
39 } else {
40 libnetapi_set_username(ctx, puser);
42 free(puser);
43 break;
45 case 'd':
46 libnetapi_set_debuglevel(ctx, arg);
47 break;
48 case 'p':
49 libnetapi_set_password(ctx, arg);
50 break;
51 case 'k':
52 libnetapi_set_use_kerberos(ctx);
53 break;
57 struct poptOption popt_common_netapi_examples[] = {
58 { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback },
59 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" },
60 { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" },
61 { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" },
62 { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL },
63 POPT_TABLEEND