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.
33 extern pstring global_myname;
35 extern pstring user_socket_options;
38 extern pstring debugf;
39 extern int DEBUGLEVEL;
42 extern file_info def_finfo;
44 #define CNV_LANG(s) dos2unix_format(s,False)
45 #define CNV_INPUT(s) unix2dos_format(s,True)
47 static struct cli_state smbcli;
48 struct cli_state *smb_cli = &smbcli;
52 static pstring password; /* local copy only, if one is entered */
54 /****************************************************************************
55 initialise smb client structure
56 ****************************************************************************/
57 void rpcclient_init(void)
59 bzero(smb_cli, sizeof(smb_cli));
60 cli_initialise(smb_cli);
61 smb_cli->capabilities |= CAP_NT_SMBS;
64 /****************************************************************************
65 make smb client connection
66 ****************************************************************************/
67 static BOOL rpcclient_connect(struct client_info *info)
69 struct nmb_name calling;
70 struct nmb_name called;
72 make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope);
73 make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope);
75 if (!cli_establish_connection(smb_cli,
76 info->dest_host, &info->dest_ip,
78 info->share, info->svc_type,
81 DEBUG(0,("rpcclient_connect: connection failed\n"));
82 cli_shutdown(smb_cli);
89 /****************************************************************************
90 stop the smb connection(s?)
91 ****************************************************************************/
92 static void rpcclient_stop(void)
94 cli_shutdown(smb_cli);
97 /****************************************************************************
98 log in as an nt user, log out again.
99 ****************************************************************************/
100 void run_ntlogin_test(int num_ops, struct client_info *cli_info, struct cli_state *cli)
105 /* establish connections. nothing to stop these being re-established. */
106 rpcclient_connect(cli_info);
108 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli->fd));
111 fprintf(out_hnd, "warning: connection could not be established to %s<%02x>\n",
112 cli_info->dest_host, cli_info->name_type);
116 for (i = 0; i < num_ops; i++)
118 slprintf(cmd, sizeof(cmd)-1, "%s %s", cli->user_name, password);
119 set_first_token(cmd);
121 cmd_netlogon_login_test(cli_info);
128 /****************************************************************************
129 runs n simultaneous functions.
130 ****************************************************************************/
131 static void create_procs(int nprocs, int numops,
132 struct client_info *cli_info, struct cli_state *cli,
133 void (*fn)(int, struct client_info *, struct cli_state *))
137 for (i=0;i<nprocs;i++)
141 int mypid = getpid();
142 sys_srandom(mypid ^ time(NULL));
143 fn(numops, cli_info, cli);
149 for (i=0;i<nprocs;i++)
151 waitpid(0, &status, 0);
154 /****************************************************************************
155 usage on the program - OUT OF DATE!
156 ****************************************************************************/
157 static void usage(char *pname)
159 fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
162 fprintf(out_hnd, "\nVersion %s\n",VERSION);
163 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
164 fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
165 fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
166 fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
167 fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
168 fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
169 fprintf(out_hnd, "\t-U username set the network username\n");
170 fprintf(out_hnd, "\t-W workgroup set the workgroup name\n");
171 fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
172 fprintf(out_hnd, "\n");
182 /****************************************************************************
184 ****************************************************************************/
185 int main(int argc,char *argv[])
187 char *pname = argv[0];
192 static pstring servicesf = CONFIGFILE;
194 BOOL got_pass = False;
196 mode_t myumask = 0755;
197 enum client_action cli_action = CLIENT_NONE;
201 struct client_info cli_info;
208 pstrcpy(term_code, KANJI);
213 if (!lp_load(servicesf,True, False, False))
215 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
218 codepage_initialise(lp_client_code_page());
222 cli_info.put_total_size = 0;
223 cli_info.put_total_time_ms = 0;
224 cli_info.get_total_size = 0;
225 cli_info.get_total_time_ms = 0;
227 cli_info.dir_total = 0;
228 cli_info.newer_than = 0;
229 cli_info.archive_level = 0;
230 cli_info.print_mode = 1;
232 cli_info.translation = False;
233 cli_info.recurse_dir = False;
234 cli_info.lowercase = False;
235 cli_info.prompt = True;
236 cli_info.abort_mget = True;
238 cli_info.dest_ip.s_addr = 0;
239 cli_info.name_type = 0x20;
241 pstrcpy(cli_info.cur_dir , "\\");
242 pstrcpy(cli_info.file_sel, "");
243 pstrcpy(cli_info.base_dir, "");
244 pstrcpy(smb_cli->domain, "");
245 pstrcpy(smb_cli->user_name, "");
246 pstrcpy(cli_info.myhostname, "");
247 pstrcpy(cli_info.dest_host, "");
249 pstrcpy(cli_info.svc_type, "A:");
250 pstrcpy(cli_info.share, "");
251 pstrcpy(cli_info.service, "");
253 pstrcpy(cli_info.dom.level3_sid, "");
254 pstrcpy(cli_info.dom.level3_dom, "");
255 pstrcpy(cli_info.dom.level5_sid, "");
256 pstrcpy(cli_info.dom.level5_dom, "");
258 smb_cli->nt_pipe_fnum = 0xffff;
260 setup_logging(pname, True);
263 charset_initialise();
268 if (!get_myname(global_myname, NULL))
270 fprintf(stderr, "Failed to get my hostname.\n");
283 pstrcpy(cli_info.service, argv[1]);
284 /* Convert any '/' characters in the service name to '\' characters */
285 string_replace( cli_info.service, '/','\\');
289 DEBUG(1,("service: %s\n", cli_info.service));
291 if (count_chars(cli_info.service,'\\') < 3)
294 printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
299 if (count_chars(cli_info.service,'\\') > 3)
302 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
307 if (argc > 1 && (*argv[1] != '-'))
310 pstrcpy(password,argv[1]);
311 memset(argv[1],'X',strlen(argv[1]));
316 cli_action = CLIENT_SVC;
319 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)
325 /* FIXME ... max_protocol seems to be funny here */
327 int max_protocol = 0;
328 max_protocol = interpret_protocol(optarg,max_protocol);
329 fprintf(stderr, "max protocol not currently supported\n");
335 pstrcpy(user_socket_options,optarg);
341 pstrcpy(cli_info.dest_host,optarg);
342 strupper(cli_info.dest_host);
343 cli_action = CLIENT_IPC;
349 iface_set_default(NULL,optarg,NULL);
355 pstrcpy(scope, optarg);
362 pstrcpy(smb_cli->user_name,optarg);
363 if ((lp=strchr(smb_cli->user_name,'%')))
366 pstrcpy(password,lp+1);
368 memset(strchr(optarg,'%')+1,'X',strlen(password));
375 pstrcpy(smb_cli->domain,optarg);
387 cli_info.dest_ip = *interpret_addr2(optarg);
388 if (zero_ip(cli_info.dest_ip))
397 nprocs = atoi(optarg);
403 numops = atoi(optarg);
409 fstrcpy(global_myname, optarg);
418 DEBUGLEVEL = atoi(optarg);
424 slprintf(debugf, sizeof(debugf)-1,
445 pstrcpy(servicesf, optarg);
451 pstrcpy(term_code, optarg);
464 if (cli_action == CLIENT_NONE)
470 strupper(global_myname);
471 fstrcpy(cli_info.myhostname, global_myname);
473 DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
475 if (*smb_cli->domain == 0)
477 pstrcpy(smb_cli->domain,lp_workgroup());
479 strupper(smb_cli->domain);
483 if (cli_action == CLIENT_IPC)
485 pstrcpy(cli_info.share, "IPC$");
486 pstrcpy(cli_info.svc_type, "IPC");
489 fstrcpy(cli_info.mach_acct, cli_info.myhostname);
490 strupper(cli_info.mach_acct);
491 fstrcat(cli_info.mach_acct, "$");
493 /* set the password cache info */
496 if (password[0] == 0)
498 pwd_set_nullpwd(&(smb_cli->pwd));
502 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
507 char *pwd = getpass("Enter Password:");
508 safe_strcpy(password, pwd, sizeof(password));
509 pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
512 if (password[0] != 0)
514 create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test);