source: vendor/current/source3/lib/netapi/examples/common.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 1.5 KB
RevLine 
[414]1#include <stdlib.h>
2#include <string.h>
3#include <sys/types.h>
4#include <inttypes.h>
5
6#include <popt.h>
7#include <netapi.h>
8
[988]9#include "common.h"
10
[414]11void popt_common_callback(poptContext con,
12 enum poptCallbackReason reason,
13 const struct poptOption *opt,
14 const char *arg, const void *data)
15{
16 struct libnetapi_ctx *ctx = NULL;
17
18 libnetapi_getctx(&ctx);
19
20 if (reason == POPT_CALLBACK_REASON_PRE) {
21 }
22
23 if (reason == POPT_CALLBACK_REASON_POST) {
24 }
25
26 if (!opt) {
27 return;
28 }
29 switch (opt->val) {
30 case 'U': {
31 char *puser = strdup(arg);
32 char *p = NULL;
33
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);
43 }
44 free(puser);
45 break;
46 }
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;
56 }
57}
58
59struct 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
66};
67
Note: See TracBrowser for help on using the repository browser.