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