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