2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1994-1998
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.
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.
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.
32 extern pstring global_myname;
34 extern pstring user_socket_options;
37 extern pstring debugf;
39 extern file_info def_finfo;
41 #define CNV_LANG(s) dos2unix_format(s,False)
42 #define CNV_INPUT(s) unix2dos_format(s,True)
44 static struct cli_state smbcli;
45 struct cli_state *smb_cli = &smbcli;
49 static pstring password; /* local copy only, if one is entered */
51 /****************************************************************************
52 initialise smb client structure
53 ****************************************************************************/
54 void rpcclient_init(void)
56 memset((char *)smb_cli, '\0', sizeof(smb_cli));
57 cli_initialise(smb_cli);
58 smb_cli->capabilities |= CAP_NT_SMBS;
61 /****************************************************************************
62 make smb client connection
63 ****************************************************************************/
64 static BOOL rpcclient_connect(struct client_info *info)
66 struct nmb_name calling;
67 struct nmb_name called;
69 make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type);
70 make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0);
72 if (!cli_establish_connection(smb_cli,
73 info->dest_host, &info->dest_ip,
75 info->share, info->svc_type,
78 DEBUG(0,("rpcclient_connect: connection failed\n"));
79 cli_shutdown(smb_cli);
86 /****************************************************************************
87 stop the smb connection(s?)
88 ****************************************************************************/
89 static void rpcclient_stop(void)
91 cli_shutdown(smb_cli);
94 /****************************************************************************
95 log in as an nt user, log out again.
96 ****************************************************************************/
97 void run_enums_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
102 /* establish connections. nothing to stop these being re-established. */
103 rpcclient_connect(cli_info);
105 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
108 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
109 cli_info->dest_host, cli_info->name_type);
113 for (i = 0; i < num_ops; i++)
116 cmd_srv_enum_sess(cli_info);
118 cmd_srv_enum_shares(cli_info);
120 cmd_srv_enum_files(cli_info);
122 if (password[0] != 0)
124 slprintf(cmd, sizeof(cmd)-1, "1");
125 set_first_token(cmd);
131 cmd_srv_enum_conn(cli_info);
138 /****************************************************************************
139 log in as an nt user, log out again.
140 ****************************************************************************/
141 void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
146 /* establish connections. nothing to stop these being re-established. */
147 rpcclient_connect(cli_info);
149 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
152 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
153 cli_info->dest_host, cli_info->name_type);
157 for (i = 0; i < num_ops; i++)
159 slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password);
160 set_first_token(cmd);
162 cmd_netlogon_login_test(cli_info);
169 /****************************************************************************
170 runs n simultaneous functions.
171 ****************************************************************************/
172 static void create_procs(int nprocs, int numops,
173 struct client_info *cli_info, struct cli_state *cli,
174 void (*fn)(int, struct client_info *, struct cli_state *))
178 for (i=0;i<nprocs;i++)
182 pid_t mypid = getpid();
183 sys_srandom(mypid ^ time(NULL));
184 fn(numops, cli_info, cli);
190 for (i=0;i<nprocs;i++)
192 waitpid(0, &status, 0);
195 /****************************************************************************
196 usage on the program - OUT OF DATE!
197 ****************************************************************************/
198 static void usage(char *pname)
200 fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
203 fprintf(out_hnd, "\nVersion %s\n",VERSION);
204 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
205 fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
206 fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
207 fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
208 fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
209 fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
210 fprintf(out_hnd, "\t-U username set the network username\n");
211 fprintf(out_hnd, "\t-W workgroup set the workgroup name\n");
212 fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
213 fprintf(out_hnd, "\n");
223 /****************************************************************************
225 ****************************************************************************/
226 int main(int argc,char *argv[])
228 char *pname = argv[0];
232 static pstring servicesf = CONFIGFILE;
234 BOOL got_pass = False;
236 mode_t myumask = 0755;
237 enum client_action cli_action = CLIENT_NONE;
241 struct client_info cli_info;
248 pstrcpy(term_code, KANJI);
253 if (!lp_load(servicesf,True, False, False))
255 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
260 cli_info.put_total_size = 0;
261 cli_info.put_total_time_ms = 0;
262 cli_info.get_total_size = 0;
263 cli_info.get_total_time_ms = 0;
265 cli_info.dir_total = 0;
266 cli_info.newer_than = 0;
267 cli_info.archive_level = 0;
268 cli_info.print_mode = 1;
270 cli_info.translation = False;
271 cli_info.recurse_dir = False;
272 cli_info.lowercase = False;
273 cli_info.prompt = True;
274 cli_info.abort_mget = True;
276 cli_info.dest_ip.s_addr = 0;
277 cli_info.name_type = 0x20;
279 pstrcpy(cli_info.cur_dir , "\\");
280 pstrcpy(cli_info.file_sel, "");
281 pstrcpy(cli_info.base_dir, "");
282 pstrcpy(smb_cli->domain, "");
283 pstrcpy(smb_cli->user_name, "");
284 pstrcpy(cli_info.myhostname, "");
285 pstrcpy(cli_info.dest_host, "");
287 pstrcpy(cli_info.svc_type, "A:");
288 pstrcpy(cli_info.share, "");
289 pstrcpy(cli_info.service, "");
291 ZERO_STRUCT(cli_info.dom.level3_sid);
292 pstrcpy(cli_info.dom.level3_dom, "");
293 ZERO_STRUCT(cli_info.dom.level5_sid);
294 pstrcpy(cli_info.dom.level5_dom, "");
296 smb_cli->nt_pipe_fnum = 0xffff;
298 setup_logging(pname, True);
305 if (!get_myname(global_myname))
307 fprintf(stderr, "Failed to get my hostname.\n");
320 pstrcpy(cli_info.service, argv[1]);
321 /* Convert any '/' characters in the service name to '\' characters */
322 string_replace( cli_info.service, '/','\\');
326 DEBUG(1,("service: %s\n", cli_info.service));
328 if (count_chars(cli_info.service,'\\') < 3)
331 printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
336 if (count_chars(cli_info.service,'\\') > 3)
339 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
344 if (argc > 1 && (*argv[1] != '-'))
347 pstrcpy(password,argv[1]);
348 memset(argv[1],'X',strlen(argv[1]));
353 cli_action = CLIENT_SVC;
356 while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
362 /* FIXME ... max_protocol seems to be funny here */
364 int max_protocol = 0;
365 max_protocol = interpret_protocol(optarg,max_protocol);
366 fprintf(stderr, "max protocol not currently supported\n");
372 pstrcpy(user_socket_options,optarg);
378 pstrcpy(cli_info.dest_host,optarg);
379 strupper(cli_info.dest_host);
380 cli_action = CLIENT_IPC;
386 pstrcpy(scope, optarg);
393 pstrcpy(smb_cli->user_name,optarg);
394 if ((lp=strchr_m(smb_cli->user_name,'%')))
397 pstrcpy(password,lp+1);
399 memset(strchr_m(optarg,'%')+1,'X',strlen(password));
406 pstrcpy(smb_cli->domain,optarg);
418 cli_info.dest_ip = *interpret_addr2(optarg);
419 if (zero_ip(cli_info.dest_ip))
428 nprocs = atoi(optarg);
434 numops = atoi(optarg);
440 fstrcpy(global_myname, optarg);
449 DEBUGLEVEL = atoi(optarg);
455 slprintf(debugf, sizeof(debugf)-1,
476 pstrcpy(servicesf, optarg);
482 pstrcpy(term_code, optarg);
495 if (cli_action == CLIENT_NONE)
501 strupper(global_myname);
502 fstrcpy(cli_info.myhostname, global_myname);
504 DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION));
506 if (*smb_cli->domain == 0)
508 pstrcpy(smb_cli->domain,lp_workgroup());
510 strupper(smb_cli->domain);
514 if (cli_action == CLIENT_IPC)
516 pstrcpy(cli_info.share, "IPC$");
517 pstrcpy(cli_info.svc_type, "IPC");
520 fstrcpy(cli_info.mach_acct, cli_info.myhostname);
521 strupper(cli_info.mach_acct);
522 fstrcat(cli_info.mach_acct, "$");
524 /* set the password cache info */
527 if (password[0] == 0)
529 pwd_set_nullpwd(&(smb_cli->pwd));
533 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
538 char *pwd = getpass("Enter Password:");
539 safe_strcpy(password, pwd, sizeof(password));
540 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
543 create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test);
545 if (password[0] != 0)
547 create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test);