source: branches/samba-3.3.x/source/lib/netapi/tests/common.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 16 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 2.2 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * NetApi testsuite
4 * Copyright (C) Guenther Deschner 2008
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <stdlib.h>
21#include <string.h>
22#include <sys/types.h>
23#include <inttypes.h>
24
25#include <popt.h>
26#include <netapi.h>
27
28#include "common.h"
29
30void popt_common_callback(poptContext con,
31 enum poptCallbackReason reason,
32 const struct poptOption *opt,
33 const char *arg, const void *data)
34{
35 struct libnetapi_ctx *ctx = NULL;
36
37 libnetapi_getctx(&ctx);
38
39 if (reason == POPT_CALLBACK_REASON_PRE) {
40 }
41
42 if (reason == POPT_CALLBACK_REASON_POST) {
43 }
44
45 if (!opt) {
46 return;
47 }
48 switch (opt->val) {
49 case 'U': {
50 char *puser = strdup(arg);
51 char *p = NULL;
52
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);
62 }
63 free(puser);
64 break;
65 }
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;
75 }
76}
77
78struct poptOption popt_common_netapi_examples[] = {
79 { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback },
80 { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" },
81 { "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" },
82 { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" },
83 { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL },
84 POPT_TABLEEND
85};
86
Note: See TracBrowser for help on using the repository browser.