0933cf38c1f45aac5ec9c38a4e65073c422d4de4
[jra/samba/.git] / source3 / utils / rpctorture.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB client
5    Copyright (C) Andrew Tridgell 1994-1998
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifdef SYSLOG
23 #undef SYSLOG
24 #endif
25
26 #include "includes.h"
27
28 #ifndef REGISTER
29 #define REGISTER 0
30 #endif
31
32 extern pstring scope;
33 extern pstring global_myname;
34
35 extern pstring user_socket_options;
36
37
38 extern pstring debugf;
39 extern int DEBUGLEVEL;
40
41
42 extern file_info def_finfo;
43
44 #define CNV_LANG(s) dos2unix_format(s,False)
45 #define CNV_INPUT(s) unix2dos_format(s,True)
46
47 static struct cli_state smbcli;
48 struct cli_state *smb_cli = &smbcli;
49
50 FILE *out_hnd;
51
52 static pstring user_name; /* local copy only, if one is entered */
53 static pstring password; /* local copy only, if one is entered */
54 static pstring domain; /* local copy only, if one is entered */
55 BOOL got_pass = False;
56
57 static struct nmb_name calling;
58 static struct nmb_name called;
59
60 static void get_passwd(void)
61 {
62         /* set the password cache info */
63         if (got_pass)
64         {
65                 if (password[0] == 0)
66                 {
67                         pwd_set_nullpwd(&(smb_cli->pwd));
68                 }
69                 else
70                 {
71                         pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
72                 }
73         }
74         else 
75         {
76                 char *pwd = getpass("Enter Password:");
77                 safe_strcpy(password, pwd, sizeof(password));
78                 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
79                 got_pass = True;
80         }
81 }
82
83 /****************************************************************************
84 initialise smb client structure
85 ****************************************************************************/
86 void rpcclient_init(void)
87 {
88         bzero(smb_cli, sizeof(smb_cli));
89         cli_initialise(smb_cli);
90         smb_cli->capabilities |= CAP_NT_SMBS;
91         smb_cli->capabilities |= CAP_STATUS32;
92
93         pstrcpy(smb_cli->user_name, user_name);
94
95         get_passwd();
96
97         if (*domain == 0)
98         {
99                 pstrcpy(smb_cli->domain,lp_workgroup());
100         }
101         else
102         {
103                 pstrcpy(smb_cli->domain, domain);
104         }
105
106         strupper(smb_cli->domain);
107 }
108
109 /****************************************************************************
110 make smb client connection
111 ****************************************************************************/
112 static BOOL rpcclient_connect(struct client_info *info)
113 {
114         rpcclient_init();
115
116         smb_cli->use_ntlmv2 = lp_client_ntlmv2();
117
118         if (!cli_establish_connection(smb_cli, 
119                                   info->dest_host, &info->dest_ip, 
120                                   &calling, &called,
121                                   info->share, info->svc_type,
122                                   False, True))
123         {
124                 DEBUG(0,("rpcclient_connect: connection failed\n"));
125                 cli_shutdown(smb_cli);
126                 return False;
127         }
128
129         return True;
130 }
131
132 /****************************************************************************
133 stop the smb connection(s?)
134 ****************************************************************************/
135 static void rpcclient_stop(void)
136 {
137         cli_shutdown(smb_cli);
138 }
139
140 /****************************************************************************
141   log in as an nt user, log out again. 
142 ****************************************************************************/
143 void run_enums_test(int num_ops, struct client_info *cli_info)
144 {
145         pstring cmd;
146         int i;
147
148         /* establish connections.  nothing to stop these being re-established. */
149         rpcclient_connect(cli_info);
150
151         DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd));
152         if (smb_cli->fd <= 0)
153         {
154                 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
155                                  cli_info->dest_host, cli_info->name_type);
156                 return;
157         }
158         
159         for (i = 0; i < num_ops; i++)
160         {
161                 set_first_token("");
162                 cmd_srv_enum_sess(cli_info);
163                 set_first_token("");
164                 cmd_srv_enum_shares(cli_info);
165                 set_first_token("");
166                 cmd_srv_enum_files(cli_info);
167
168                 if (password[0] != 0)
169                 {
170                         slprintf(cmd, sizeof(cmd)-1, "1");
171                         set_first_token(cmd);
172                 }
173                 else
174                 {
175                         set_first_token("");
176                 }
177                 cmd_srv_enum_conn(cli_info);
178         }
179
180         rpcclient_stop();
181
182 }
183
184 /****************************************************************************
185   log in as an nt user, log out again. 
186 ****************************************************************************/
187 void run_ntlogin_test(int num_ops, struct client_info *cli_info)
188 {
189         pstring cmd;
190         int i;
191
192         /* establish connections.  nothing to stop these being re-established. */
193         rpcclient_connect(cli_info);
194
195         DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd));
196         if (smb_cli->fd <= 0)
197         {
198                 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
199                                  cli_info->dest_host, cli_info->name_type);
200                 return;
201         }
202         
203         for (i = 0; i < num_ops; i++)
204         {
205                 slprintf(cmd, sizeof(cmd)-1, "%s %s", smb_cli->user_name, password);
206                 set_first_token(cmd);
207
208                 cmd_netlogon_login_test(cli_info);
209         }
210
211         rpcclient_stop();
212
213 }
214
215 /* generate a random buffer */
216 static void rand_buf(char *buf, int len)
217 {
218         while (len--) {
219                 *buf = sys_random();
220                 buf++;
221         }
222 }
223
224 /****************************************************************************
225 do a random rpc command
226 ****************************************************************************/
227 BOOL do_random_rpc(struct cli_state *cli, uint16 nt_pipe_fnum, int max_len)
228 {
229         prs_struct rbuf;
230         prs_struct buf; 
231         uint8 opcode;
232         int param_len;
233         BOOL response = False;
234
235         if ((sys_random() % 20) == 0)
236         {
237                 param_len = (sys_random() % 256) + 4;
238         }
239         else
240         {
241                 param_len = (sys_random() % max_len) + 4;
242         }
243
244         prs_init(&buf , param_len, 4, SAFETY_MARGIN, False);
245         prs_init(&rbuf, 0        , 4, SAFETY_MARGIN, True );
246
247         opcode = sys_random() % 256;
248
249         /* turn parameters into data stream */
250         rand_buf(mem_data(&buf.data, 0), param_len);
251         buf.offset = param_len;
252
253         /* send the data on \PIPE\ */
254         if (rpc_api_pipe_req(cli, nt_pipe_fnum, opcode, &buf, &rbuf))
255         {
256                 response = rbuf.offset != 0;
257
258                 if (response)
259                 {
260                         DEBUG(0,("response! opcode: 0x%x\n", opcode));
261                         DEBUG(0,("request: length %d\n", param_len));
262                         dump_data(0, mem_data(&buf.data , 0), MIN(param_len, 128));
263                         DEBUG(0,("response: length %d\n", rbuf.data->offset.end));
264                         dump_data(0, mem_data(&rbuf.data, 0), rbuf.data->offset.end);
265                 }
266         }
267
268         prs_mem_free(&rbuf);
269         prs_mem_free(&buf );
270
271         return response;
272 }
273
274
275 /* send random IPC commands */
276 static void random_rpc_pipe_enc(char *pipe_name, struct client_info *cli_info,
277                 int numops)
278 {
279         uint16 nt_pipe_fnum;
280         int i;
281
282         DEBUG(0,("starting random rpc test on %s (encryped)\n", pipe_name));
283
284         /* establish connections.  nothing to stop these being re-established. */
285         if (!rpcclient_connect(cli_info))
286         {
287                 DEBUG(0,("random rpc test: connection failed\n"));
288                 return;
289         }
290
291         cli_nt_set_ntlmssp_flgs(smb_cli,
292                                     NTLMSSP_NEGOTIATE_UNICODE |
293                                     NTLMSSP_NEGOTIATE_OEM |
294                                     NTLMSSP_NEGOTIATE_SIGN |
295                                     NTLMSSP_NEGOTIATE_SEAL |
296                                     NTLMSSP_NEGOTIATE_LM_KEY |
297                                     NTLMSSP_NEGOTIATE_NTLM |
298                                     NTLMSSP_NEGOTIATE_ALWAYS_SIGN |
299                                     NTLMSSP_NEGOTIATE_00001000 |
300                                     NTLMSSP_NEGOTIATE_00002000);
301
302         for (i = 1; i <= numops * 100; i++)
303         {
304                 /* open session.  */
305                 cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum);
306
307                 do_random_rpc(smb_cli, nt_pipe_fnum, 1024);
308                 if (i % 500 == 0)
309                 {
310                         DEBUG(0,("calls: %i\n", i));
311                 }
312
313                 /* close the session */
314                 cli_nt_session_close(smb_cli, nt_pipe_fnum);
315         }
316
317         /* close the rpc pipe */
318         rpcclient_stop();
319
320         DEBUG(0,("finished random rpc test on %s\n", pipe_name));
321 }
322
323 /* send random IPC commands */
324 static void random_rpc_pipe(char *pipe_name, struct client_info *cli_info,
325                 int numops)
326 {
327         uint16 nt_pipe_fnum;
328         int i;
329
330         DEBUG(0,("starting random rpc test on %s\n", pipe_name));
331
332         /* establish connections.  nothing to stop these being re-established. */
333         if (!rpcclient_connect(cli_info))
334         {
335                 DEBUG(0,("random rpc test: connection failed\n"));
336                 return;
337         }
338
339         /* open session.  */
340         if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum))
341         {
342                 DEBUG(0,("random rpc test: session open failed\n"));
343                 return;
344         }
345
346         for (i = 1; i <= numops * 100; i++)
347         {
348                 do_random_rpc(smb_cli, nt_pipe_fnum, 8192);
349                 if (i % 500 == 0)
350                 {
351                         DEBUG(0,("calls: %i\n", i));
352                 }
353         }
354
355         /* close the session */
356         cli_nt_session_close(smb_cli, nt_pipe_fnum);
357
358         /* close the rpc pipe */
359         rpcclient_stop();
360
361         DEBUG(0,("finished random rpc test on %s\n", pipe_name));
362 }
363
364 static void run_randomrpc(int numops, struct client_info *cli_info)
365 {
366         char *pipes[] =
367         {
368                 PIPE_SAMR     ,
369                 PIPE_WINREG   ,
370                 PIPE_SRVSVC   ,
371                 PIPE_WKSSVC   ,
372                 PIPE_NETLOGON ,
373                 PIPE_NTSVCS   ,
374                 PIPE_LSARPC   ,
375                 NULL
376         };
377
378         int i = 0;
379
380         while (pipes[i] != NULL)
381         {
382                 random_rpc_pipe(pipes[i], cli_info, numops);
383 #if 0
384                 random_rpc_pipe_enc(pipes[i], cli_info, numops);
385 #endif
386
387                 i++;
388         }
389 }
390
391
392 static void run_samhandles(int numops, struct client_info *cli_info)
393 {
394         uint16 nt_pipe_fnum;
395         int i;
396         int count = 0;
397         int failed = 0;
398         int retry = 500;
399         fstring srv_name;
400         fstrcpy(srv_name, "\\\\");
401         fstrcat(srv_name, cli_info->dest_host);
402         strupper(srv_name);
403
404         DEBUG(0,("starting sam handle test\n"));
405
406         /* establish connections.  nothing to stop these being re-established. */
407         while (retry > 0 && !rpcclient_connect(cli_info))
408         {
409                 retry--;
410         }
411
412         if (retry == 0)
413         {
414                 DEBUG(0,("samhandle test: connection failed\n"));
415                 return;
416         }
417
418         /* open session.  */
419         if (!cli_nt_session_open(smb_cli, PIPE_SAMR, &nt_pipe_fnum))
420         {
421                 DEBUG(0,("samhandle test: session open failed\n"));
422                 return;
423         }
424
425         for (i = 1; i <= numops * 100; i++)
426         {
427                 POLICY_HND pol;
428                 POLICY_HND dom;
429                 if (!samr_connect(smb_cli, nt_pipe_fnum, srv_name, 0x20, &pol))
430                 {
431                         failed++;
432                 }
433 /*
434                 if (!samr_open_domain(smb_cli, nt_pipe_fnum, srv_name, 0x00000020, &pol))
435                 {
436                         DEBUG(0,("samhandle domain open test (%i): failed\n", i));
437                 }
438  */
439                 if (i % 500 == 0)
440                 {
441                         DEBUG(0,("calls: %i\n", i));
442                 }
443                 count++;
444         }
445
446         /* close the session */
447         cli_nt_session_close(smb_cli, nt_pipe_fnum);
448
449         /* close the rpc pipe */
450         rpcclient_stop();
451
452         DEBUG(0,("finished samhandle test.  count: %d failed: %d\n", count, failed));
453 }
454
455
456 static void run_lsahandles(int numops, struct client_info *cli_info)
457 {
458         uint16 nt_pipe_fnum;
459         int i;
460         int count = 0;
461         int failed = 0;
462         int retry = 500;
463         fstring srv_name;
464         fstrcpy(srv_name, "\\\\");
465         fstrcat(srv_name, cli_info->myhostname);
466         strupper(srv_name);
467
468         DEBUG(0,("starting lsa handle test\n"));
469
470         /* establish connections.  nothing to stop these being re-established. */
471         while (retry > 0 && !rpcclient_connect(cli_info))
472         {
473                 retry--;
474         }
475
476         if (retry == 0)
477         {
478                 DEBUG(0,("lsahandle test: connection failed\n"));
479                 return;
480         }
481         for (i = 1; i <= numops * 100; i++)
482         {
483                 extern struct cli_state *rpc_smb_cli;
484                 rpc_smb_cli = smb_cli;
485                 POLICY_HND pol;
486                 if (!lsa_open_policy(srv_name, &pol, False))
487                 {
488                         failed++;
489                 }
490                 if (i % 500 == 0)
491                 {
492                         DEBUG(0,("calls: %i\n", i));
493                 }
494                 count++;
495         }
496
497         /* close the rpc pipe */
498         rpcclient_stop();
499
500         DEBUG(0,("finished lsahandle test.  count: %d failed: %d\n", count, failed));
501 }
502
503
504 static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name)
505 {
506         uint16 nt_pipe_fnum;
507         int i;
508         int count = 0;
509         int failed = 0;
510         int retry = 500;
511         fstring srv_name;
512         fstrcpy(srv_name, "\\\\");
513         fstrcat(srv_name, cli_info->myhostname);
514         strupper(srv_name);
515
516         DEBUG(0,("starting pipe gobble test (%s)\n", pipe_name));
517
518         /* establish connections.  nothing to stop these being re-established. */
519         while (retry > 0 && !rpcclient_connect(cli_info))
520         {
521                 retry--;
522         }
523
524         if (retry == 0)
525         {
526                 DEBUG(0,("pipe gobble test: connection failed\n"));
527                 return;
528         }
529         for (i = 1; i <= numops * 100; i++)
530         {
531                 /* open session.  */
532                 if (!cli_nt_session_open(smb_cli, pipe_name, &nt_pipe_fnum))
533                 {
534                         DEBUG(0,("pipe gobble test: session open failed\n"));
535                 }
536
537                 if (i % 500 == 0)
538                 {
539                         DEBUG(0,("calls: %i\n", i));
540                 }
541                 count++;
542         }
543
544         rpcclient_stop();
545
546         DEBUG(0,("finished pipe gobble test (%s).  count: %d failed: %d\n",
547                   pipe_name, count, failed));
548 }
549
550
551 static void run_handles(int numops, struct client_info *cli_info)
552 {
553         run_lsahandles(numops, cli_info);
554         run_samhandles(numops, cli_info);
555 }
556
557 static void run_pipegobbler(int numops, struct client_info *cli_info)
558 {
559         run_pipegobble(numops, cli_info, PIPE_SAMR);
560         run_pipegobble(numops, cli_info, PIPE_LSARPC);
561 }
562
563 /****************************************************************************
564 make tcp connection
565 ****************************************************************************/
566 static void run_tcpconnect(int numops, struct client_info *info)
567 {
568         int i;
569         int failed = 0;
570
571         for (i = 0; i < numops; i++)
572         {
573                 rpcclient_init();
574
575                 if (!cli_connect(smb_cli, info->dest_host, &info->dest_ip))
576                 {
577                         failed++;
578                 }
579                 cli_shutdown(smb_cli);
580         }
581
582         DEBUG(0,("tcp connections: count: %d failed: %d\n", numops, failed));
583 }
584
585 /****************************************************************************
586   runs n simultaneous functions.
587 ****************************************************************************/
588 static void create_procs(int nprocs, int numops, 
589                 struct client_info *cli_info,
590                 void (*fn)(int, struct client_info *))
591 {
592         int i, status;
593
594         for (i=0;i<nprocs;i++)
595         {
596                 if (fork() == 0)
597                 {
598                         int mypid = getpid();
599                         sys_srandom(mypid ^ time(NULL));
600                         fn(numops, cli_info);
601                         dbgflush();
602                         _exit(0);
603                 }
604         }
605
606         for (i=0;i<nprocs;i++)
607         {
608                 waitpid(0, &status, 0);
609         }
610 }
611
612
613 /****************************************************************************
614 usage on the program - OUT OF DATE!
615 ****************************************************************************/
616 static void usage(char *pname)
617 {
618   fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
619            pname);
620
621   fprintf(out_hnd, "\nVersion %s\n",VERSION);
622   fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
623   fprintf(out_hnd, "\t-l log basename.      Basename for log/debug files\n");
624   fprintf(out_hnd, "\t-n netbios name.      Use this name as my netbios name\n");
625   fprintf(out_hnd, "\t-m max protocol       set the max protocol level\n");
626   fprintf(out_hnd, "\t-I dest IP            use this IP to connect to\n");
627   fprintf(out_hnd, "\t-E                    write messages to stderr instead of stdout\n");
628   fprintf(out_hnd, "\t-U username           set the network username\n");
629   fprintf(out_hnd, "\t-W workgroup          set the workgroup name\n");
630   fprintf(out_hnd, "\t-t terminal code      terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
631   fprintf(out_hnd, "\t-N processes          number of processes\n");
632   fprintf(out_hnd, "\t-o operations         number of operations\n");
633   fprintf(out_hnd, "\n");
634 }
635
636 enum client_action
637 {
638         CLIENT_NONE,
639         CLIENT_IPC,
640         CLIENT_SVC
641 };
642
643 /****************************************************************************
644   main program
645 ****************************************************************************/
646  int main(int argc,char *argv[])
647 {
648         char *pname = argv[0];
649         int opt;
650         extern FILE *dbf;
651         extern char *optarg;
652         extern int optind;
653         static pstring servicesf = CONFIGFILE;
654         pstring term_code;
655         char *cmd_str="";
656         mode_t myumask = 0755;
657         enum client_action cli_action = CLIENT_NONE;
658         int nprocs = 1;
659         int numops = 100;
660
661         struct client_info cli_info;
662
663         out_hnd = stdout;
664
665 #ifdef KANJI
666         pstrcpy(term_code, KANJI);
667 #else /* KANJI */
668         *term_code = 0;
669 #endif /* KANJI */
670
671         if (!lp_load(servicesf,True, False, False))
672         {
673                 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
674         }
675
676         codepage_initialise(lp_client_code_page());
677
678         DEBUGLEVEL = 0;
679
680         cli_info.put_total_size = 0;
681         cli_info.put_total_time_ms = 0;
682         cli_info.get_total_size = 0;
683         cli_info.get_total_time_ms = 0;
684
685         cli_info.dir_total = 0;
686         cli_info.newer_than = 0;
687         cli_info.archive_level = 0;
688         cli_info.print_mode = 1;
689
690         cli_info.translation = False;
691         cli_info.recurse_dir = False;
692         cli_info.lowercase = False;
693         cli_info.prompt = True;
694         cli_info.abort_mget = True;
695
696         cli_info.dest_ip.s_addr = 0;
697         cli_info.name_type = 0x20;
698
699         pstrcpy(cli_info.cur_dir , "\\");
700         pstrcpy(cli_info.file_sel, "");
701         pstrcpy(cli_info.base_dir, "");
702         pstrcpy(cli_info.myhostname, "");
703         pstrcpy(cli_info.dest_host, "");
704
705         pstrcpy(cli_info.svc_type, "A:");
706         pstrcpy(cli_info.share, "");
707         pstrcpy(cli_info.service, "");
708
709         ZERO_STRUCT(cli_info.dom.level3_sid);
710         pstrcpy(cli_info.dom.level3_dom, "");
711         ZERO_STRUCT(cli_info.dom.level5_sid);
712         pstrcpy(cli_info.dom.level5_dom, "");
713
714
715         setup_logging(pname, True);
716
717         TimeInit();
718         charset_initialise();
719
720         myumask = umask(0);
721         umask(myumask);
722
723         if (!get_myname(global_myname, NULL))
724         {
725                 fprintf(stderr, "Failed to get my hostname.\n");
726         }
727
728         password[0] = 0;
729
730         if (argc < 2)
731         {
732                 usage(pname);
733                 exit(1);
734         }
735
736         if (*argv[1] != '-')
737         {
738                 pstrcpy(cli_info.service, argv[1]);  
739                 /* Convert any '/' characters in the service name to '\' characters */
740                 string_replace( cli_info.service, '/','\\');
741                 argc--;
742                 argv++;
743
744                 DEBUG(1,("service: %s\n", cli_info.service));
745
746                 if (count_chars(cli_info.service,'\\') < 3)
747                 {
748                         usage(pname);
749                         printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
750                         exit(1);
751                 }
752
753                 /*
754                 if (count_chars(cli_info.service,'\\') > 3)
755                 {
756                         usage(pname);
757                         printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
758                         exit(1);
759                 }
760                 */
761
762                 if (argc > 1 && (*argv[1] != '-'))
763                 {
764                         got_pass = True;
765                         pstrcpy(password,argv[1]);  
766                         memset(argv[1],'X',strlen(argv[1]));
767                         argc--;
768                         argv++;
769                 }
770
771                 cli_action = CLIENT_SVC;
772         }
773
774         while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
775         {
776                 switch (opt)
777                 {
778                         case 'm':
779                         {
780                                 /* FIXME ... max_protocol seems to be funny here */
781
782                                 int max_protocol = 0;
783                                 max_protocol = interpret_protocol(optarg,max_protocol);
784                                 fprintf(stderr, "max protocol not currently supported\n");
785                                 break;
786                         }
787
788                         case 'O':
789                         {
790                                 pstrcpy(user_socket_options,optarg);
791                                 break;  
792                         }
793
794                         case 'S':
795                         {
796                                 pstrcpy(cli_info.dest_host,optarg);
797                                 strupper(cli_info.dest_host);
798                                 cli_action = CLIENT_IPC;
799                                 break;
800                         }
801
802                         case 'B':
803                         {
804                                 iface_set_default(NULL,optarg,NULL);
805                                 break;
806                         }
807
808                         case 'i':
809                         {
810                                 pstrcpy(scope, optarg);
811                                 break;
812                         }
813
814                         case 'U':
815                         {
816                                 char *lp;
817                                 pstrcpy(user_name,optarg);
818                                 if ((lp=strchr(user_name,'%')))
819                                 {
820                                         *lp = 0;
821                                         pstrcpy(password,lp+1);
822                                         got_pass = True;
823                                         memset(strchr(optarg,'%')+1,'X',strlen(password));
824                                 }
825                                 break;
826                         }
827
828                         case 'W':
829                         {
830                                 pstrcpy(domain,optarg);
831                                 break;
832                         }
833
834                         case 'E':
835                         {
836                                 dbf = stderr;
837                                 break;
838                         }
839
840                         case 'I':
841                         {
842                                 cli_info.dest_ip = *interpret_addr2(optarg);
843                                 if (zero_ip(cli_info.dest_ip))
844                                 {
845                                         exit(1);
846                                 }
847                                 break;
848                         }
849
850                         case 'N':
851                         {
852                                 nprocs = atoi(optarg);
853                                 break;
854                         }
855
856                         case 'o':
857                         {
858                                 numops = atoi(optarg);
859                                 break;
860                         }
861
862                         case 'n':
863                         {
864                                 fstrcpy(global_myname, optarg);
865                                 break;
866                         }
867
868                         case 'd':
869                         {
870                                 if (*optarg == 'A')
871                                         DEBUGLEVEL = 10000;
872                                 else
873                                         DEBUGLEVEL = atoi(optarg);
874                                 break;
875                         }
876
877                         case 'l':
878                         {
879                                 slprintf(debugf, sizeof(debugf)-1,
880                                          "%s.client",optarg);
881                                 break;
882                         }
883
884                         case 'c':
885                         {
886                                 cmd_str = optarg;
887                                 got_pass = True;
888                                 break;
889                         }
890
891                         case 'h':
892                         {
893                                 usage(pname);
894                                 exit(0);
895                                 break;
896                         }
897
898                         case 's':
899                         {
900                                 pstrcpy(servicesf, optarg);
901                                 break;
902                         }
903
904                         case 't':
905                         {
906                                 pstrcpy(term_code, optarg);
907                                 break;
908                         }
909
910                         default:
911                         {
912                                 usage(pname);
913                                 exit(1);
914                                 break;
915                         }
916                 }
917         }
918
919         if (cli_action == CLIENT_NONE)
920         {
921                 usage(pname);
922                 exit(1);
923         }
924
925         strupper(global_myname);
926         fstrcpy(cli_info.myhostname, global_myname);
927
928         DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
929
930         load_interfaces();
931
932         if (cli_action == CLIENT_IPC)
933         {
934                 pstrcpy(cli_info.share, "IPC$");
935                 pstrcpy(cli_info.svc_type, "IPC");
936         }
937
938         fstrcpy(cli_info.mach_acct, cli_info.myhostname);
939         strupper(cli_info.mach_acct);
940         fstrcat(cli_info.mach_acct, "$");
941
942         make_nmb_name(&called , dns_to_netbios_name(cli_info.dest_host ), cli_info.name_type, scope);
943         make_nmb_name(&calling, dns_to_netbios_name(cli_info.myhostname), 0x0               , scope);
944
945         get_passwd();
946 /*
947         create_procs(nprocs, numops, &cli_info, run_enums_test);
948
949         if (password[0] != 0)
950         {
951                 create_procs(nprocs, numops, &cli_info, run_ntlogin_test);
952         }
953 */
954
955 /*
956         create_procs(nprocs, numops, &cli_info, run_randomrpc);
957         create_procs(nprocs, numops, &cli_info, run_pipegobbler);
958         create_procs(nprocs, numops, &cli_info, run_tcpconnect);
959 */
960         create_procs(nprocs, numops, &cli_info, run_handles);
961
962         fflush(out_hnd);
963
964         return(0);
965 }