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
;
38 extern int DEBUGLEVEL
;
41 extern file_info def_finfo
;
43 #define CNV_LANG(s) dos2unix_format(s,False)
44 #define CNV_INPUT(s) unix2dos_format(s,True)
46 static struct cli_state smbcli
;
47 struct cli_state
*smb_cli
= &smbcli
;
51 static pstring password
; /* local copy only, if one is entered */
53 /****************************************************************************
54 initialise smb client structure
55 ****************************************************************************/
56 void rpcclient_init(void)
58 memset((char *)smb_cli
, '\0', sizeof(smb_cli
));
59 cli_initialise(smb_cli
);
60 smb_cli
->capabilities
|= CAP_NT_SMBS
;
63 /****************************************************************************
64 make smb client connection
65 ****************************************************************************/
66 static BOOL
rpcclient_connect(struct client_info
*info
)
68 struct nmb_name calling
;
69 struct nmb_name called
;
71 make_nmb_name(&called
, dns_to_netbios_name(info
->dest_host
), info
->name_type
);
72 make_nmb_name(&calling
, dns_to_netbios_name(info
->myhostname
), 0x0);
74 if (!cli_establish_connection(smb_cli
,
75 info
->dest_host
, &info
->dest_ip
,
77 info
->share
, info
->svc_type
,
80 DEBUG(0,("rpcclient_connect: connection failed\n"));
81 cli_shutdown(smb_cli
);
88 /****************************************************************************
89 stop the smb connection(s?)
90 ****************************************************************************/
91 static void rpcclient_stop(void)
93 cli_shutdown(smb_cli
);
96 /****************************************************************************
97 log in as an nt user, log out again.
98 ****************************************************************************/
99 void run_enums_test(int num_ops
, struct client_info
*cli_info
, struct cli_state
*cli
)
104 /* establish connections. nothing to stop these being re-established. */
105 rpcclient_connect(cli_info
);
107 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli
->fd
));
110 fprintf(out_hnd
, "warning: connection could not be established to %s<%02x>\n",
111 cli_info
->dest_host
, cli_info
->name_type
);
115 for (i
= 0; i
< num_ops
; i
++)
118 cmd_srv_enum_sess(cli_info
);
120 cmd_srv_enum_shares(cli_info
);
122 cmd_srv_enum_files(cli_info
);
124 if (password
[0] != 0)
126 slprintf(cmd
, sizeof(cmd
)-1, "1");
127 set_first_token(cmd
);
133 cmd_srv_enum_conn(cli_info
);
140 /****************************************************************************
141 log in as an nt user, log out again.
142 ****************************************************************************/
143 void run_ntlogin_test(int num_ops
, struct client_info
*cli_info
, struct cli_state
*cli
)
148 /* establish connections. nothing to stop these being re-established. */
149 rpcclient_connect(cli_info
);
151 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli
->fd
));
154 fprintf(out_hnd
, "warning: connection could not be established to %s<%02x>\n",
155 cli_info
->dest_host
, cli_info
->name_type
);
159 for (i
= 0; i
< num_ops
; i
++)
161 slprintf(cmd
, sizeof(cmd
)-1, "%s %s", cli
->user_name
, password
);
162 set_first_token(cmd
);
164 cmd_netlogon_login_test(cli_info
);
171 /****************************************************************************
172 runs n simultaneous functions.
173 ****************************************************************************/
174 static void create_procs(int nprocs
, int numops
,
175 struct client_info
*cli_info
, struct cli_state
*cli
,
176 void (*fn
)(int, struct client_info
*, struct cli_state
*))
180 for (i
=0;i
<nprocs
;i
++)
184 pid_t mypid
= getpid();
185 sys_srandom(mypid
^ time(NULL
));
186 fn(numops
, cli_info
, cli
);
192 for (i
=0;i
<nprocs
;i
++)
194 waitpid(0, &status
, 0);
197 /****************************************************************************
198 usage on the program - OUT OF DATE!
199 ****************************************************************************/
200 static void usage(char *pname
)
202 fprintf(out_hnd
, "Usage: %s service <password> [-d debuglevel] [-l log] ",
205 fprintf(out_hnd
, "\nVersion %s\n",VERSION
);
206 fprintf(out_hnd
, "\t-d debuglevel set the debuglevel\n");
207 fprintf(out_hnd
, "\t-l log basename. Basename for log/debug files\n");
208 fprintf(out_hnd
, "\t-n netbios name. Use this name as my netbios name\n");
209 fprintf(out_hnd
, "\t-m max protocol set the max protocol level\n");
210 fprintf(out_hnd
, "\t-I dest IP use this IP to connect to\n");
211 fprintf(out_hnd
, "\t-E write messages to stderr instead of stdout\n");
212 fprintf(out_hnd
, "\t-U username set the network username\n");
213 fprintf(out_hnd
, "\t-W workgroup set the workgroup name\n");
214 fprintf(out_hnd
, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
215 fprintf(out_hnd
, "\n");
225 /****************************************************************************
227 ****************************************************************************/
228 int main(int argc
,char *argv
[])
230 char *pname
= argv
[0];
235 static pstring servicesf
= CONFIGFILE
;
237 BOOL got_pass
= False
;
239 mode_t myumask
= 0755;
240 enum client_action cli_action
= CLIENT_NONE
;
244 struct client_info cli_info
;
251 pstrcpy(term_code
, KANJI
);
256 if (!lp_load(servicesf
,True
, False
, False
))
258 fprintf(stderr
, "Can't load %s - run testparm to debug it\n", servicesf
);
261 codepage_initialise(lp_client_code_page());
265 cli_info
.put_total_size
= 0;
266 cli_info
.put_total_time_ms
= 0;
267 cli_info
.get_total_size
= 0;
268 cli_info
.get_total_time_ms
= 0;
270 cli_info
.dir_total
= 0;
271 cli_info
.newer_than
= 0;
272 cli_info
.archive_level
= 0;
273 cli_info
.print_mode
= 1;
275 cli_info
.translation
= False
;
276 cli_info
.recurse_dir
= False
;
277 cli_info
.lowercase
= False
;
278 cli_info
.prompt
= True
;
279 cli_info
.abort_mget
= True
;
281 cli_info
.dest_ip
.s_addr
= 0;
282 cli_info
.name_type
= 0x20;
284 pstrcpy(cli_info
.cur_dir
, "\\");
285 pstrcpy(cli_info
.file_sel
, "");
286 pstrcpy(cli_info
.base_dir
, "");
287 pstrcpy(smb_cli
->domain
, "");
288 pstrcpy(smb_cli
->user_name
, "");
289 pstrcpy(cli_info
.myhostname
, "");
290 pstrcpy(cli_info
.dest_host
, "");
292 pstrcpy(cli_info
.svc_type
, "A:");
293 pstrcpy(cli_info
.share
, "");
294 pstrcpy(cli_info
.service
, "");
296 ZERO_STRUCT(cli_info
.dom
.level3_sid
);
297 pstrcpy(cli_info
.dom
.level3_dom
, "");
298 ZERO_STRUCT(cli_info
.dom
.level5_sid
);
299 pstrcpy(cli_info
.dom
.level5_dom
, "");
301 smb_cli
->nt_pipe_fnum
= 0xffff;
303 setup_logging(pname
, True
);
306 charset_initialise();
311 if (!get_myname(global_myname
))
313 fprintf(stderr
, "Failed to get my hostname.\n");
326 pstrcpy(cli_info
.service
, argv
[1]);
327 /* Convert any '/' characters in the service name to '\' characters */
328 string_replace( cli_info
.service
, '/','\\');
332 DEBUG(1,("service: %s\n", cli_info
.service
));
334 if (count_chars(cli_info
.service
,'\\') < 3)
337 printf("\n%s: Not enough '\\' characters in service\n", cli_info
.service
);
342 if (count_chars(cli_info.service,'\\') > 3)
345 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
350 if (argc
> 1 && (*argv
[1] != '-'))
353 pstrcpy(password
,argv
[1]);
354 memset(argv
[1],'X',strlen(argv
[1]));
359 cli_action
= CLIENT_SVC
;
362 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
)
368 /* FIXME ... max_protocol seems to be funny here */
370 int max_protocol
= 0;
371 max_protocol
= interpret_protocol(optarg
,max_protocol
);
372 fprintf(stderr
, "max protocol not currently supported\n");
378 pstrcpy(user_socket_options
,optarg
);
384 pstrcpy(cli_info
.dest_host
,optarg
);
385 strupper(cli_info
.dest_host
);
386 cli_action
= CLIENT_IPC
;
392 pstrcpy(scope
, optarg
);
399 pstrcpy(smb_cli
->user_name
,optarg
);
400 if ((lp
=strchr(smb_cli
->user_name
,'%')))
403 pstrcpy(password
,lp
+1);
405 memset(strchr(optarg
,'%')+1,'X',strlen(password
));
412 pstrcpy(smb_cli
->domain
,optarg
);
424 cli_info
.dest_ip
= *interpret_addr2(optarg
);
425 if (zero_ip(cli_info
.dest_ip
))
434 nprocs
= atoi(optarg
);
440 numops
= atoi(optarg
);
446 fstrcpy(global_myname
, optarg
);
455 DEBUGLEVEL
= atoi(optarg
);
461 slprintf(debugf
, sizeof(debugf
)-1,
482 pstrcpy(servicesf
, optarg
);
488 pstrcpy(term_code
, optarg
);
501 if (cli_action
== CLIENT_NONE
)
507 strupper(global_myname
);
508 fstrcpy(cli_info
.myhostname
, global_myname
);
510 DEBUG(3,("%s client started (version %s)\n",timestring(False
),VERSION
));
512 if (*smb_cli
->domain
== 0)
514 pstrcpy(smb_cli
->domain
,lp_workgroup());
516 strupper(smb_cli
->domain
);
520 if (cli_action
== CLIENT_IPC
)
522 pstrcpy(cli_info
.share
, "IPC$");
523 pstrcpy(cli_info
.svc_type
, "IPC");
526 fstrcpy(cli_info
.mach_acct
, cli_info
.myhostname
);
527 strupper(cli_info
.mach_acct
);
528 fstrcat(cli_info
.mach_acct
, "$");
530 /* set the password cache info */
533 if (password
[0] == 0)
535 pwd_set_nullpwd(&(smb_cli
->pwd
));
539 pwd_make_lm_nt_16(&(smb_cli
->pwd
), password
); /* generate 16 byte hashes */
544 char *pwd
= getpass("Enter Password:");
545 safe_strcpy(password
, pwd
, sizeof(password
));
546 pwd_make_lm_nt_16(&(smb_cli
->pwd
), password
); /* generate 16 byte hashes */
549 create_procs(nprocs
, numops
, &cli_info
, smb_cli
, run_enums_test
);
551 if (password
[0] != 0)
553 create_procs(nprocs
, numops
, &cli_info
, smb_cli
, run_ntlogin_test
);