dac64a22e3a854f9faa0b3ece9b0122968dad7f5
[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         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);
304
305                 do_random_rpc(smb_cli, 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);
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         int i;
326
327         DEBUG(0,("starting random rpc test on %s\n", pipe_name));
328
329         /* establish connections.  nothing to stop these being re-established. */
330         if (!rpcclient_connect(cli_info))
331         {
332                 DEBUG(0,("random rpc test: connection failed\n"));
333                 return;
334         }
335
336         /* open session.  */
337         if (!cli_nt_session_open(smb_cli, pipe_name))
338         {
339                 DEBUG(0,("random rpc test: session open failed\n"));
340                 return;
341         }
342
343         for (i = 1; i <= numops * 100; i++)
344         {
345                 do_random_rpc(smb_cli, 8192);
346                 if (i % 500 == 0)
347                 {
348                         DEBUG(0,("calls: %i\n", i));
349                 }
350         }
351
352         /* close the session */
353         cli_nt_session_close(smb_cli);
354
355         /* close the rpc pipe */
356         rpcclient_stop();
357
358         DEBUG(0,("finished random rpc test on %s\n", pipe_name));
359 }
360
361 static void run_randomrpc(int numops, struct client_info *cli_info)
362 {
363         char *pipes[] =
364         {
365                 PIPE_SAMR     ,
366                 PIPE_WINREG   ,
367                 PIPE_SRVSVC   ,
368                 PIPE_WKSSVC   ,
369                 PIPE_NETLOGON ,
370                 PIPE_NTSVCS   ,
371                 PIPE_LSARPC   ,
372                 NULL
373         };
374
375         int i = 0;
376
377         while (pipes[i] != NULL)
378         {
379                 random_rpc_pipe(pipes[i], cli_info, numops);
380 #if 0
381                 random_rpc_pipe_enc(pipes[i], cli_info, numops);
382 #endif
383
384                 i++;
385         }
386 }
387
388
389 static void run_samhandles(int numops, struct client_info *cli_info)
390 {
391         int i;
392         int count = 0;
393         int failed = 0;
394         int retry = 500;
395         fstring srv_name;
396         fstrcpy(srv_name, "\\\\");
397         fstrcat(srv_name, cli_info->dest_host);
398         strupper(srv_name);
399
400         DEBUG(0,("starting sam handle test\n"));
401
402         /* establish connections.  nothing to stop these being re-established. */
403         while (retry > 0 && !rpcclient_connect(cli_info))
404         {
405                 retry--;
406         }
407
408         if (retry == 0)
409         {
410                 DEBUG(0,("samhandle test: connection failed\n"));
411                 return;
412         }
413
414         /* open session.  */
415         if (!cli_nt_session_open(smb_cli, PIPE_SAMR))
416         {
417                 DEBUG(0,("samhandle test: session open failed\n"));
418                 return;
419         }
420
421         for (i = 1; i <= numops * 100; i++)
422         {
423                 POLICY_HND pol;
424                 POLICY_HND dom;
425                 if (!do_samr_connect(smb_cli, srv_name, 0x20, &pol))
426                 {
427                         failed++;
428                 }
429 /*
430                 if (!do_samr_open_domain(smb_cli, srv_name, 0x00000020, &pol))
431                 {
432                         DEBUG(0,("samhandle domain open test (%i): failed\n", i));
433                 }
434  */
435                 if (i % 500 == 0)
436                 {
437                         DEBUG(0,("calls: %i\n", i));
438                 }
439                 count++;
440         }
441
442         /* close the session */
443         cli_nt_session_close(smb_cli);
444
445         /* close the rpc pipe */
446         rpcclient_stop();
447
448         DEBUG(0,("finished samhandle test.  count: %d failed: %d\n", count, failed));
449 }
450
451
452 static void run_lsahandles(int numops, struct client_info *cli_info)
453 {
454         int i;
455         int count = 0;
456         int failed = 0;
457         int retry = 500;
458         fstring srv_name;
459         fstrcpy(srv_name, "\\\\");
460         fstrcat(srv_name, cli_info->myhostname);
461         strupper(srv_name);
462
463         DEBUG(0,("starting lsa handle test\n"));
464
465         /* establish connections.  nothing to stop these being re-established. */
466         while (retry > 0 && !rpcclient_connect(cli_info))
467         {
468                 retry--;
469         }
470
471         if (retry == 0)
472         {
473                 DEBUG(0,("lsahandle test: connection failed\n"));
474                 return;
475         }
476         /* open session.  */
477         if (!cli_nt_session_open(smb_cli, PIPE_LSARPC))
478         {
479                 DEBUG(0,("lsahandle test: session open failed\n"));
480                 return;
481         }
482
483         for (i = 1; i <= numops * 100; i++)
484         {
485                 POLICY_HND pol;
486                 if (!do_lsa_open_policy(smb_cli, 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 session */
498         cli_nt_session_close(smb_cli);
499
500         /* close the rpc pipe */
501         rpcclient_stop();
502
503         DEBUG(0,("finished lsahandle test.  count: %d failed: %d\n", count, failed));
504 }
505
506
507 static void run_pipegobble(int numops, struct client_info *cli_info, char *pipe_name)
508 {
509         int i;
510         int count = 0;
511         int failed = 0;
512         int retry = 500;
513         fstring srv_name;
514         fstrcpy(srv_name, "\\\\");
515         fstrcat(srv_name, cli_info->myhostname);
516         strupper(srv_name);
517
518         DEBUG(0,("starting pipe gobble test (%s)\n", pipe_name));
519
520         /* establish connections.  nothing to stop these being re-established. */
521         while (retry > 0 && !rpcclient_connect(cli_info))
522         {
523                 retry--;
524         }
525
526         if (retry == 0)
527         {
528                 DEBUG(0,("pipe gobble test: connection failed\n"));
529                 return;
530         }
531         for (i = 1; i <= numops * 100; i++)
532         {
533                 /* open session.  */
534                 if (!cli_nt_session_open(smb_cli, pipe_name))
535                 {
536                         DEBUG(0,("pipe gobble test: session open failed\n"));
537                 }
538
539                 if (i % 500 == 0)
540                 {
541                         DEBUG(0,("calls: %i\n", i));
542                 }
543                 count++;
544         }
545
546         rpcclient_stop();
547
548         DEBUG(0,("finished pipe gobble test (%s).  count: %d failed: %d\n",
549                   pipe_name, count, failed));
550 }
551
552
553 static void run_handles(int numops, struct client_info *cli_info)
554 {
555         run_samhandles(numops, cli_info);
556         run_lsahandles(numops, cli_info);
557 }
558
559 static void run_pipegobbler(int numops, struct client_info *cli_info)
560 {
561 /*
562         run_pipegobble(numops, cli_info, PIPE_SAMR);
563 */
564         run_pipegobble(numops, cli_info, PIPE_LSARPC);
565 }
566
567 /****************************************************************************
568 make tcp connection
569 ****************************************************************************/
570 static void run_tcpconnect(int numops, struct client_info *info)
571 {
572         int i;
573         int failed = 0;
574
575         for (i = 0; i < numops; i++)
576         {
577                 rpcclient_init();
578
579                 if (!cli_connect(smb_cli, info->dest_host, &info->dest_ip))
580                 {
581                         failed++;
582                 }
583                 cli_shutdown(smb_cli);
584         }
585
586         DEBUG(0,("tcp connections: count: %d failed: %d\n", numops, failed));
587 }
588
589 /****************************************************************************
590   runs n simultaneous functions.
591 ****************************************************************************/
592 static void create_procs(int nprocs, int numops, 
593                 struct client_info *cli_info,
594                 void (*fn)(int, struct client_info *))
595 {
596         int i, status;
597
598         for (i=0;i<nprocs;i++)
599         {
600                 if (fork() == 0)
601                 {
602                         int mypid = getpid();
603                         sys_srandom(mypid ^ time(NULL));
604                         fn(numops, cli_info);
605                         dbgflush();
606                         _exit(0);
607                 }
608         }
609
610         for (i=0;i<nprocs;i++)
611         {
612                 waitpid(0, &status, 0);
613         }
614 }
615
616
617 /****************************************************************************
618 usage on the program - OUT OF DATE!
619 ****************************************************************************/
620 static void usage(char *pname)
621 {
622   fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
623            pname);
624
625   fprintf(out_hnd, "\nVersion %s\n",VERSION);
626   fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
627   fprintf(out_hnd, "\t-l log basename.      Basename for log/debug files\n");
628   fprintf(out_hnd, "\t-n netbios name.      Use this name as my netbios name\n");
629   fprintf(out_hnd, "\t-m max protocol       set the max protocol level\n");
630   fprintf(out_hnd, "\t-I dest IP            use this IP to connect to\n");
631   fprintf(out_hnd, "\t-E                    write messages to stderr instead of stdout\n");
632   fprintf(out_hnd, "\t-U username           set the network username\n");
633   fprintf(out_hnd, "\t-W workgroup          set the workgroup name\n");
634   fprintf(out_hnd, "\t-t terminal code      terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
635   fprintf(out_hnd, "\n");
636 }
637
638 enum client_action
639 {
640         CLIENT_NONE,
641         CLIENT_IPC,
642         CLIENT_SVC
643 };
644
645 /****************************************************************************
646   main program
647 ****************************************************************************/
648  int main(int argc,char *argv[])
649 {
650         char *pname = argv[0];
651         int opt;
652         extern FILE *dbf;
653         extern char *optarg;
654         extern int optind;
655         static pstring servicesf = CONFIGFILE;
656         pstring term_code;
657         char *cmd_str="";
658         mode_t myumask = 0755;
659         enum client_action cli_action = CLIENT_NONE;
660         int nprocs = 1;
661         int numops = 100;
662
663         struct client_info cli_info;
664
665         out_hnd = stdout;
666
667 #ifdef KANJI
668         pstrcpy(term_code, KANJI);
669 #else /* KANJI */
670         *term_code = 0;
671 #endif /* KANJI */
672
673         if (!lp_load(servicesf,True, False, False))
674         {
675                 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
676         }
677
678         codepage_initialise(lp_client_code_page());
679
680         DEBUGLEVEL = 0;
681
682         cli_info.put_total_size = 0;
683         cli_info.put_total_time_ms = 0;
684         cli_info.get_total_size = 0;
685         cli_info.get_total_time_ms = 0;
686
687         cli_info.dir_total = 0;
688         cli_info.newer_than = 0;
689         cli_info.archive_level = 0;
690         cli_info.print_mode = 1;
691
692         cli_info.translation = False;
693         cli_info.recurse_dir = False;
694         cli_info.lowercase = False;
695         cli_info.prompt = True;
696         cli_info.abort_mget = True;
697
698         cli_info.dest_ip.s_addr = 0;
699         cli_info.name_type = 0x20;
700
701         pstrcpy(cli_info.cur_dir , "\\");
702         pstrcpy(cli_info.file_sel, "");
703         pstrcpy(cli_info.base_dir, "");
704         pstrcpy(cli_info.myhostname, "");
705         pstrcpy(cli_info.dest_host, "");
706
707         pstrcpy(cli_info.svc_type, "A:");
708         pstrcpy(cli_info.share, "");
709         pstrcpy(cli_info.service, "");
710
711         ZERO_STRUCT(cli_info.dom.level3_sid);
712         pstrcpy(cli_info.dom.level3_dom, "");
713         ZERO_STRUCT(cli_info.dom.level5_sid);
714         pstrcpy(cli_info.dom.level5_dom, "");
715
716
717         setup_logging(pname, True);
718
719         TimeInit();
720         charset_initialise();
721
722         myumask = umask(0);
723         umask(myumask);
724
725         if (!get_myname(global_myname, NULL))
726         {
727                 fprintf(stderr, "Failed to get my hostname.\n");
728         }
729
730         password[0] = 0;
731
732         if (argc < 2)
733         {
734                 usage(pname);
735                 exit(1);
736         }
737
738         if (*argv[1] != '-')
739         {
740                 pstrcpy(cli_info.service, argv[1]);  
741                 /* Convert any '/' characters in the service name to '\' characters */
742                 string_replace( cli_info.service, '/','\\');
743                 argc--;
744                 argv++;
745
746                 DEBUG(1,("service: %s\n", cli_info.service));
747
748                 if (count_chars(cli_info.service,'\\') < 3)
749                 {
750                         usage(pname);
751                         printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
752                         exit(1);
753                 }
754
755                 /*
756                 if (count_chars(cli_info.service,'\\') > 3)
757                 {
758                         usage(pname);
759                         printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
760                         exit(1);
761                 }
762                 */
763
764                 if (argc > 1 && (*argv[1] != '-'))
765                 {
766                         got_pass = True;
767                         pstrcpy(password,argv[1]);  
768                         memset(argv[1],'X',strlen(argv[1]));
769                         argc--;
770                         argv++;
771                 }
772
773                 cli_action = CLIENT_SVC;
774         }
775
776         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)
777         {
778                 switch (opt)
779                 {
780                         case 'm':
781                         {
782                                 /* FIXME ... max_protocol seems to be funny here */
783
784                                 int max_protocol = 0;
785                                 max_protocol = interpret_protocol(optarg,max_protocol);
786                                 fprintf(stderr, "max protocol not currently supported\n");
787                                 break;
788                         }
789
790                         case 'O':
791                         {
792                                 pstrcpy(user_socket_options,optarg);
793                                 break;  
794                         }
795
796                         case 'S':
797                         {
798                                 pstrcpy(cli_info.dest_host,optarg);
799                                 strupper(cli_info.dest_host);
800                                 cli_action = CLIENT_IPC;
801                                 break;
802                         }
803
804                         case 'B':
805                         {
806                                 iface_set_default(NULL,optarg,NULL);
807                                 break;
808                         }
809
810                         case 'i':
811                         {
812                                 pstrcpy(scope, optarg);
813                                 break;
814                         }
815
816                         case 'U':
817                         {
818                                 char *lp;
819                                 pstrcpy(user_name,optarg);
820                                 if ((lp=strchr(user_name,'%')))
821                                 {
822                                         *lp = 0;
823                                         pstrcpy(password,lp+1);
824                                         got_pass = True;
825                                         memset(strchr(optarg,'%')+1,'X',strlen(password));
826                                 }
827                                 break;
828                         }
829
830                         case 'W':
831                         {
832                                 pstrcpy(domain,optarg);
833                                 break;
834                         }
835
836                         case 'E':
837                         {
838                                 dbf = stderr;
839                                 break;
840                         }
841
842                         case 'I':
843                         {
844                                 cli_info.dest_ip = *interpret_addr2(optarg);
845                                 if (zero_ip(cli_info.dest_ip))
846                                 {
847                                         exit(1);
848                                 }
849                                 break;
850                         }
851
852                         case 'N':
853                         {
854                                 nprocs = atoi(optarg);
855                                 break;
856                         }
857
858                         case 'o':
859                         {
860                                 numops = atoi(optarg);
861                                 break;
862                         }
863
864                         case 'n':
865                         {
866                                 fstrcpy(global_myname, optarg);
867                                 break;
868                         }
869
870                         case 'd':
871                         {
872                                 if (*optarg == 'A')
873                                         DEBUGLEVEL = 10000;
874                                 else
875                                         DEBUGLEVEL = atoi(optarg);
876                                 break;
877                         }
878
879                         case 'l':
880                         {
881                                 slprintf(debugf, sizeof(debugf)-1,
882                                          "%s.client",optarg);
883                                 break;
884                         }
885
886                         case 'c':
887                         {
888                                 cmd_str = optarg;
889                                 got_pass = True;
890                                 break;
891                         }
892
893                         case 'h':
894                         {
895                                 usage(pname);
896                                 exit(0);
897                                 break;
898                         }
899
900                         case 's':
901                         {
902                                 pstrcpy(servicesf, optarg);
903                                 break;
904                         }
905
906                         case 't':
907                         {
908                                 pstrcpy(term_code, optarg);
909                                 break;
910                         }
911
912                         default:
913                         {
914                                 usage(pname);
915                                 exit(1);
916                                 break;
917                         }
918                 }
919         }
920
921         if (cli_action == CLIENT_NONE)
922         {
923                 usage(pname);
924                 exit(1);
925         }
926
927         strupper(global_myname);
928         fstrcpy(cli_info.myhostname, global_myname);
929
930         DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
931
932         load_interfaces();
933
934         if (cli_action == CLIENT_IPC)
935         {
936                 pstrcpy(cli_info.share, "IPC$");
937                 pstrcpy(cli_info.svc_type, "IPC");
938         }
939
940         fstrcpy(cli_info.mach_acct, cli_info.myhostname);
941         strupper(cli_info.mach_acct);
942         fstrcat(cli_info.mach_acct, "$");
943
944         make_nmb_name(&called , dns_to_netbios_name(cli_info.dest_host ), cli_info.name_type, scope);
945         make_nmb_name(&calling, dns_to_netbios_name(cli_info.myhostname), 0x0               , scope);
946
947         get_passwd();
948 /*
949         create_procs(nprocs, numops, &cli_info, run_enums_test);
950
951         if (password[0] != 0)
952         {
953                 create_procs(nprocs, numops, &cli_info, run_ntlogin_test);
954         }
955 */
956
957         create_procs(nprocs, numops, &cli_info, run_tcpconnect);
958 /*
959         create_procs(nprocs, numops, &cli_info, run_pipegobbler);
960         create_procs(nprocs, numops, &cli_info, run_handles);
961         create_procs(nprocs, numops, &cli_info, run_randomrpc);
962 */
963
964         fflush(out_hnd);
965
966         return(0);
967 }