2
Unix SMB/CIFS implementation.
4
Copyright (C) Andrew Tridgell 1994-1998
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 2 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, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
extern pstring global_myname;
29
extern pstring user_socket_options;
32
extern file_info def_finfo;
34
#define CNV_LANG(s) dos2unix_format(s,False)
35
#define CNV_INPUT(s) unix2dos_format(s,True)
37
static struct cli_state smbcli;
38
struct cli_state *smb_cli = &smbcli;
42
static pstring password; /* local copy only, if one is entered */
44
/****************************************************************************
45
initialise smb client structure
46
****************************************************************************/
47
void rpcclient_init(void)
49
memset((char *)smb_cli, '\0', sizeof(smb_cli));
50
cli_initialise(smb_cli);
51
smb_cli->capabilities |= CAP_NT_SMBS;
54
/****************************************************************************
55
make smb client connection
56
****************************************************************************/
57
static BOOL rpcclient_connect(struct client_info *info)
59
struct nmb_name calling;
60
struct nmb_name called;
62
make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type);
63
make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0);
65
if (!cli_establish_connection(smb_cli,
66
info->dest_host, &info->dest_ip,
68
info->share, info->svc_type,
71
DEBUG(0,("rpcclient_connect: connection failed\n"));
72
cli_shutdown(smb_cli);
79
/****************************************************************************
80
stop the smb connection(s?)
81
****************************************************************************/
82
static void rpcclient_stop(void)
84
cli_shutdown(smb_cli);
87
/****************************************************************************
88
log in as an nt user, log out again.
89
****************************************************************************/
90
void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
95
/* establish connections. nothing to stop these being re-established. */
96
rpcclient_connect(cli_info);
98
DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
101
fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
102
cli_info->dest_host, cli_info->name_type);
106
for (i = 0; i < num_ops; i++)
109
cmd_srv_enum_sess(cli_info);
111
cmd_srv_enum_shares(cli_info);
113
cmd_srv_enum_files(cli_info);
115
if (password[0] != 0)
117
slprintf(cmd, sizeof(cmd)-1, "1");
118
set_first_token(cmd);
124
cmd_srv_enum_conn(cli_info);
131
/****************************************************************************
132
log in as an nt user, log out again.
133
****************************************************************************/
134
void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
139
/* establish connections. nothing to stop these being re-established. */
140
rpcclient_connect(cli_info);
142
DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
145
fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
146
cli_info->dest_host, cli_info->name_type);
150
for (i = 0; i < num_ops; i++)
152
slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password);
153
set_first_token(cmd);
155
cmd_netlogon_login_test(cli_info);
162
/****************************************************************************
163
runs n simultaneous functions.
164
****************************************************************************/
165
static void create_procs(int nprocs, int numops,
166
struct client_info *cli_info, struct cli_state *cli,
167
void (*fn)(int, struct client_info *, struct cli_state *))
171
for (i=0;i<nprocs;i++)
175
pid_t mypid = getpid();
176
sys_srandom(mypid ^ time(NULL));
177
fn(numops, cli_info, cli);
183
for (i=0;i<nprocs;i++)
185
waitpid(0, &status, 0);
188
/****************************************************************************
189
usage on the program - OUT OF DATE!
190
****************************************************************************/
191
static void usage(char *pname)
193
fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
196
fprintf(out_hnd, "\nVersion %s\n",SAMBA_VERSION_STRING);
197
fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
198
fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
199
fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
200
fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
201
fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
202
fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
203
fprintf(out_hnd, "\t-U username set the network username\n");
204
fprintf(out_hnd, "\t-W workgroup set the workgroup name\n");
205
fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
206
fprintf(out_hnd, "\n");
216
/****************************************************************************
218
****************************************************************************/
219
int main(int argc,char *argv[])
221
char *pname = argv[0];
226
BOOL got_pass = False;
228
enum client_action cli_action = CLIENT_NONE;
233
struct client_info cli_info;
240
pstrcpy(term_code, KANJI);
245
if (!lp_load(dyn_CONFIGFILE,True, False, False))
247
fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
252
cli_info.put_total_size = 0;
253
cli_info.put_total_time_ms = 0;
254
cli_info.get_total_size = 0;
255
cli_info.get_total_time_ms = 0;
257
cli_info.dir_total = 0;
258
cli_info.newer_than = 0;
259
cli_info.archive_level = 0;
260
cli_info.print_mode = 1;
262
cli_info.translation = False;
263
cli_info.recurse_dir = False;
264
cli_info.lowercase = False;
265
cli_info.prompt = True;
266
cli_info.abort_mget = True;
268
cli_info.dest_ip.s_addr = 0;
269
cli_info.name_type = 0x20;
271
pstrcpy(cli_info.cur_dir , "\\");
272
pstrcpy(cli_info.file_sel, "");
273
pstrcpy(cli_info.base_dir, "");
274
pstrcpy(smb_cli->domain, "");
275
pstrcpy(smb_cli->user_name, "");
276
pstrcpy(cli_info.myhostname, "");
277
pstrcpy(cli_info.dest_host, "");
279
pstrcpy(cli_info.svc_type, "A:");
280
pstrcpy(cli_info.share, "");
281
pstrcpy(cli_info.service, "");
283
ZERO_STRUCT(cli_info.dom.level3_sid);
284
pstrcpy(cli_info.dom.level3_dom, "");
285
ZERO_STRUCT(cli_info.dom.level5_sid);
286
pstrcpy(cli_info.dom.level5_dom, "");
288
smb_cli->nt_pipe_fnum = 0xffff;
290
setup_logging(pname, True);
292
if (!get_myname(global_myname))
294
fprintf(stderr, "Failed to get my hostname.\n");
307
pstrcpy(cli_info.service, argv[1]);
308
/* Convert any '/' characters in the service name to '\' characters */
309
string_replace( cli_info.service, '/','\\');
313
DEBUG(1,("service: %s\n", cli_info.service));
315
if (count_chars(cli_info.service,'\\') < 3)
318
printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
323
if (count_chars(cli_info.service,'\\') > 3)
326
printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
331
if (argc > 1 && (*argv[1] != '-'))
334
pstrcpy(password,argv[1]);
335
memset(argv[1],'X',strlen(argv[1]));
340
cli_action = CLIENT_SVC;
343
while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
349
/* FIXME ... max_protocol seems to be funny here */
351
int max_protocol = 0;
352
max_protocol = interpret_protocol(optarg,max_protocol);
353
fprintf(stderr, "max protocol not currently supported\n");
359
pstrcpy(user_socket_options,optarg);
365
pstrcpy(cli_info.dest_host,optarg);
366
strupper_m(cli_info.dest_host);
367
cli_action = CLIENT_IPC;
373
pstrcpy(scope, optarg);
380
pstrcpy(smb_cli->user_name,optarg);
381
if ((lp=strchr_m(smb_cli->user_name,'%')))
384
pstrcpy(password,lp+1);
386
memset(strchr_m(optarg,'%')+1,'X',strlen(password));
393
pstrcpy(smb_cli->domain,optarg);
405
cli_info.dest_ip = *interpret_addr2(optarg);
406
if (is_zero_ip(cli_info.dest_ip))
415
nprocs = atoi(optarg);
421
numops = atoi(optarg);
427
fstrcpy(global_myname, optarg);
436
DEBUGLEVEL = atoi(optarg);
442
slprintf(logfile, sizeof(logfile)-1,
444
lp_set_logfile(logfile);
464
pstrcpy(dyn_CONFIGFILE, optarg);
470
pstrcpy(term_code, optarg);
483
if (cli_action == CLIENT_NONE)
489
strupper_m(global_myname);
490
fstrcpy(cli_info.myhostname, global_myname);
492
DEBUG(3,("%s client started (version %s)\n",timestring(False),SAMBA_VERSION_STRING));
494
if (*smb_cli->domain == 0)
496
pstrcpy(smb_cli->domain,lp_workgroup());
498
strupper_m(smb_cli->domain);
502
if (cli_action == CLIENT_IPC)
504
pstrcpy(cli_info.share, "IPC$");
505
pstrcpy(cli_info.svc_type, "IPC");
508
fstrcpy(cli_info.mach_acct, cli_info.myhostname);
509
strupper_m(cli_info.mach_acct);
510
fstrcat(cli_info.mach_acct, "$");
512
/* set the password cache info */
515
if (password[0] == 0)
517
pwd_set_nullpwd(&(smb_cli->pwd));
521
pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
526
char *pwd = getpass("Enter Password:");
527
safe_strcpy(password, pwd, sizeof(password));
528
pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
531
create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test);
533
if (password[0] != 0)
535
create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test);