A fix to allow configure to find iconv on a number of systems including those
[Samba/gebeck_regimport.git] / source3 / torture / rpctorture.c
blobd95c0cee0fe98d41e8a61dd988e19f2bf2e9b392
1 /*
2 Unix SMB/CIFS implementation.
3 SMB client
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.
21 #include "includes.h"
23 #ifndef REGISTER
24 #define REGISTER 0
25 #endif
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;
40 FILE *out_hnd;
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,
67 &calling, &called,
68 info->share, info->svc_type,
69 False, True))
71 DEBUG(0,("rpcclient_connect: connection failed\n"));
72 cli_shutdown(smb_cli);
73 return False;
76 return True;
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)
92 pstring cmd;
93 int i;
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));
99 if (cli->fd <= 0)
101 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
102 cli_info->dest_host, cli_info->name_type);
103 return;
106 for (i = 0; i < num_ops; i++)
108 set_first_token("");
109 cmd_srv_enum_sess(cli_info);
110 set_first_token("");
111 cmd_srv_enum_shares(cli_info);
112 set_first_token("");
113 cmd_srv_enum_files(cli_info);
115 if (password[0] != 0)
117 slprintf(cmd, sizeof(cmd)-1, "1");
118 set_first_token(cmd);
120 else
122 set_first_token("");
124 cmd_srv_enum_conn(cli_info);
127 rpcclient_stop();
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)
136 pstring cmd;
137 int i;
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));
143 if (cli->fd <= 0)
145 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
146 cli_info->dest_host, cli_info->name_type);
147 return;
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);
158 rpcclient_stop();
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 *))
169 int i, status;
171 for (i=0;i<nprocs;i++)
173 if (fork() == 0)
175 pid_t mypid = getpid();
176 sys_srandom(mypid ^ time(NULL));
177 fn(numops, cli_info, cli);
178 fflush(out_hnd);
179 _exit(0);
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] ",
194 pname);
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");
209 enum client_action
211 CLIENT_NONE,
212 CLIENT_IPC,
213 CLIENT_SVC
216 /****************************************************************************
217 main program
218 ****************************************************************************/
219 int main(int argc,char *argv[])
221 char *pname = argv[0];
222 int opt;
223 extern char *optarg;
224 extern int optind;
225 pstring term_code;
226 BOOL got_pass = False;
227 char *cmd_str="";
228 enum client_action cli_action = CLIENT_NONE;
229 int nprocs = 1;
230 int numops = 100;
231 pstring logfile;
233 struct client_info cli_info;
235 out_hnd = stdout;
237 rpcclient_init();
239 #ifdef KANJI
240 pstrcpy(term_code, KANJI);
241 #else /* KANJI */
242 *term_code = 0;
243 #endif /* 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);
250 DEBUGLEVEL = 0;
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");
297 password[0] = 0;
299 if (argc < 2)
301 usage(pname);
302 exit(1);
305 if (*argv[1] != '-')
307 pstrcpy(cli_info.service, argv[1]);
308 /* Convert any '/' characters in the service name to '\' characters */
309 string_replace( cli_info.service, '/','\\');
310 argc--;
311 argv++;
313 DEBUG(1,("service: %s\n", cli_info.service));
315 if (count_chars(cli_info.service,'\\') < 3)
317 usage(pname);
318 printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
319 exit(1);
323 if (count_chars(cli_info.service,'\\') > 3)
325 usage(pname);
326 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
327 exit(1);
331 if (argc > 1 && (*argv[1] != '-'))
333 got_pass = True;
334 pstrcpy(password,argv[1]);
335 memset(argv[1],'X',strlen(argv[1]));
336 argc--;
337 argv++;
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)
345 switch (opt)
347 case 'm':
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");
354 break;
357 case 'O':
359 pstrcpy(user_socket_options,optarg);
360 break;
363 case 'S':
365 pstrcpy(cli_info.dest_host,optarg);
366 strupper_m(cli_info.dest_host);
367 cli_action = CLIENT_IPC;
368 break;
371 case 'i':
373 pstrcpy(scope, optarg);
374 break;
377 case 'U':
379 char *lp;
380 pstrcpy(smb_cli->user_name,optarg);
381 if ((lp=strchr_m(smb_cli->user_name,'%')))
383 *lp = 0;
384 pstrcpy(password,lp+1);
385 got_pass = True;
386 memset(strchr_m(optarg,'%')+1,'X',strlen(password));
388 break;
391 case 'W':
393 pstrcpy(smb_cli->domain,optarg);
394 break;
397 case 'E':
399 dbf = x_stderr;
400 break;
403 case 'I':
405 cli_info.dest_ip = *interpret_addr2(optarg);
406 if (is_zero_ip(cli_info.dest_ip))
408 exit(1);
410 break;
413 case 'N':
415 nprocs = atoi(optarg);
416 break;
419 case 'o':
421 numops = atoi(optarg);
422 break;
425 case 'n':
427 fstrcpy(global_myname, optarg);
428 break;
431 case 'd':
433 if (*optarg == 'A')
434 DEBUGLEVEL = 10000;
435 else
436 DEBUGLEVEL = atoi(optarg);
437 break;
440 case 'l':
442 slprintf(logfile, sizeof(logfile)-1,
443 "%s.client",optarg);
444 lp_set_logfile(logfile);
445 break;
448 case 'c':
450 cmd_str = optarg;
451 got_pass = True;
452 break;
455 case 'h':
457 usage(pname);
458 exit(0);
459 break;
462 case 's':
464 pstrcpy(dyn_CONFIGFILE, optarg);
465 break;
468 case 't':
470 pstrcpy(term_code, optarg);
471 break;
474 default:
476 usage(pname);
477 exit(1);
478 break;
483 if (cli_action == CLIENT_NONE)
485 usage(pname);
486 exit(1);
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);
500 load_interfaces();
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 */
513 if (got_pass)
515 if (password[0] == 0)
517 pwd_set_nullpwd(&(smb_cli->pwd));
519 else
521 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
524 else
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);
538 fflush(out_hnd);
540 return(0);