ctdb-server: Clean up connection tracking functions
[samba4-gss.git] / source3 / lib / netapi / tests / common.c
bloba01a8704bb2aecbb4ac61b26fc0bebd5bd0404e8
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetApi testsuite
4 * Copyright (C) Guenther Deschner 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <inttypes.h>
25 #include <popt.h>
26 #include <netapi.h>
28 #include "common.h"
30 void popt_common_callback(poptContext con,
31 enum poptCallbackReason reason,
32 const struct poptOption *opt,
33 const char *arg, const void *data)
35 struct libnetapi_ctx *ctx = NULL;
37 libnetapi_getctx(&ctx);
39 if (reason == POPT_CALLBACK_REASON_PRE) {
42 if (reason == POPT_CALLBACK_REASON_POST) {
45 if (!opt) {
46 return;
48 switch (opt->val) {
49 case 'U': {
50 char *puser = strdup(arg);
51 char *p = NULL;
53 if ((p = strchr(puser,'%'))) {
54 size_t len;
55 *p = 0;
56 libnetapi_set_username(ctx, puser);
57 libnetapi_set_password(ctx, p+1);
58 len = strlen(p+1);
59 memset(strchr(arg,'%')+1,'X',len);
60 } else {
61 libnetapi_set_username(ctx, puser);
63 free(puser);
64 break;
66 case 'd':
67 libnetapi_set_debuglevel(ctx, arg);
68 break;
69 case 'p':
70 libnetapi_set_password(ctx, arg);
71 break;
72 case 'k':
73 libnetapi_set_use_kerberos(ctx);
74 break;
78 struct poptOption popt_common_netapi_examples[] = {
80 .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST,
81 .arg = (void *)popt_common_callback,
84 .longName = "user",
85 .shortName = 'U',
86 .argInfo = POPT_ARG_STRING,
87 .val = 'U',
88 .descrip = "Username used for connection",
89 .argDescrip = "USERNAME",
92 .longName = "password",
93 .shortName = 'p',
94 .argInfo = POPT_ARG_STRING,
95 .val = 'p',
96 .descrip = "Password used for connection",
97 .argDescrip = "PASSWORD",
100 .longName = "debuglevel",
101 .shortName = 'd',
102 .argInfo = POPT_ARG_STRING,
103 .val = 'd',
104 .descrip = "Debuglevel",
105 .argDescrip = "DEBUGLEVEL",
108 .longName = "kerberos",
109 .shortName = 'k',
110 .argInfo = POPT_ARG_NONE,
111 .val = 'k',
112 .descrip = "Use Kerberos",
114 POPT_TABLEEND