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
;
40 extern file_info def_finfo
;
42 #define CNV_LANG(s) dos2unix_format(s,False)
43 #define CNV_INPUT(s) unix2dos_format(s,True)
45 static struct cli_state smbcli
;
46 struct cli_state
*smb_cli
= &smbcli
;
50 static pstring password
; /* local copy only, if one is entered */
52 /****************************************************************************
53 initialise smb client structure
54 ****************************************************************************/
55 void rpcclient_init(void)
57 memset((char *)smb_cli
, '\0', sizeof(smb_cli
));
58 cli_initialise(smb_cli
);
59 smb_cli
->capabilities
|= CAP_NT_SMBS
;
62 /****************************************************************************
63 make smb client connection
64 ****************************************************************************/
65 static BOOL
rpcclient_connect(struct client_info
*info
)
67 struct nmb_name calling
;
68 struct nmb_name called
;
70 make_nmb_name(&called
, dns_to_netbios_name(info
->dest_host
), info
->name_type
);
71 make_nmb_name(&calling
, dns_to_netbios_name(info
->myhostname
), 0x0);
73 if (!cli_establish_connection(smb_cli
,
74 info
->dest_host
, &info
->dest_ip
,
76 info
->share
, info
->svc_type
,
79 DEBUG(0,("rpcclient_connect: connection failed\n"));
80 cli_shutdown(smb_cli
);
87 /****************************************************************************
88 stop the smb connection(s?)
89 ****************************************************************************/
90 static void rpcclient_stop(void)
92 cli_shutdown(smb_cli
);
95 /****************************************************************************
96 log in as an nt user, log out again.
97 ****************************************************************************/
98 void run_enums_test(int num_ops
, struct client_info
*cli_info
, struct cli_state
*cli
)
103 /* establish connections. nothing to stop these being re-established. */
104 rpcclient_connect(cli_info
);
106 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli
->fd
));
109 fprintf(out_hnd
, "warning: connection could not be established to %s<%02x>\n",
110 cli_info
->dest_host
, cli_info
->name_type
);
114 for (i
= 0; i
< num_ops
; i
++)
117 cmd_srv_enum_sess(cli_info
);
119 cmd_srv_enum_shares(cli_info
);
121 cmd_srv_enum_files(cli_info
);
123 if (password
[0] != 0)
125 slprintf(cmd
, sizeof(cmd
)-1, "1");
126 set_first_token(cmd
);
132 cmd_srv_enum_conn(cli_info
);
139 /****************************************************************************
140 log in as an nt user, log out again.
141 ****************************************************************************/
142 void run_ntlogin_test(int num_ops
, struct client_info
*cli_info
, struct cli_state
*cli
)
147 /* establish connections. nothing to stop these being re-established. */
148 rpcclient_connect(cli_info
);
150 DEBUG(5,("rpcclient_connect: cli->fd:%d\n", cli
->fd
));
153 fprintf(out_hnd
, "warning: connection could not be established to %s<%02x>\n",
154 cli_info
->dest_host
, cli_info
->name_type
);
158 for (i
= 0; i
< num_ops
; i
++)
160 slprintf(cmd
, sizeof(cmd
)-1, "%s %s", cli
->user_name
, password
);
161 set_first_token(cmd
);
163 cmd_netlogon_login_test(cli_info
);
170 /****************************************************************************
171 runs n simultaneous functions.
172 ****************************************************************************/
173 static void create_procs(int nprocs
, int numops
,
174 struct client_info
*cli_info
, struct cli_state
*cli
,
175 void (*fn
)(int, struct client_info
*, struct cli_state
*))
179 for (i
=0;i
<nprocs
;i
++)
183 pid_t mypid
= getpid();
184 sys_srandom(mypid
^ time(NULL
));
185 fn(numops
, cli_info
, cli
);
191 for (i
=0;i
<nprocs
;i
++)
193 waitpid(0, &status
, 0);
196 /****************************************************************************
197 usage on the program - OUT OF DATE!
198 ****************************************************************************/
199 static void usage(char *pname
)
201 fprintf(out_hnd
, "Usage: %s service <password> [-d debuglevel] [-l log] ",
204 fprintf(out_hnd
, "\nVersion %s\n",VERSION
);
205 fprintf(out_hnd
, "\t-d debuglevel set the debuglevel\n");
206 fprintf(out_hnd
, "\t-l log basename. Basename for log/debug files\n");
207 fprintf(out_hnd
, "\t-n netbios name. Use this name as my netbios name\n");
208 fprintf(out_hnd
, "\t-m max protocol set the max protocol level\n");
209 fprintf(out_hnd
, "\t-I dest IP use this IP to connect to\n");
210 fprintf(out_hnd
, "\t-E write messages to stderr instead of stdout\n");
211 fprintf(out_hnd
, "\t-U username set the network username\n");
212 fprintf(out_hnd
, "\t-W workgroup set the workgroup name\n");
213 fprintf(out_hnd
, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
214 fprintf(out_hnd
, "\n");
224 /****************************************************************************
226 ****************************************************************************/
227 int main(int argc
,char *argv
[])
229 char *pname
= argv
[0];
234 static pstring servicesf
= CONFIGFILE
;
236 BOOL got_pass
= False
;
238 mode_t myumask
= 0755;
239 enum client_action cli_action
= CLIENT_NONE
;
243 struct client_info cli_info
;
250 pstrcpy(term_code
, KANJI
);
255 if (!lp_load(servicesf
,True
, False
, False
))
257 fprintf(stderr
, "Can't load %s - run testparm to debug it\n", servicesf
);
260 codepage_initialise(lp_client_code_page());
264 cli_info
.put_total_size
= 0;
265 cli_info
.put_total_time_ms
= 0;
266 cli_info
.get_total_size
= 0;
267 cli_info
.get_total_time_ms
= 0;
269 cli_info
.dir_total
= 0;
270 cli_info
.newer_than
= 0;
271 cli_info
.archive_level
= 0;
272 cli_info
.print_mode
= 1;
274 cli_info
.translation
= False
;
275 cli_info
.recurse_dir
= False
;
276 cli_info
.lowercase
= False
;
277 cli_info
.prompt
= True
;
278 cli_info
.abort_mget
= True
;
280 cli_info
.dest_ip
.s_addr
= 0;
281 cli_info
.name_type
= 0x20;
283 pstrcpy(cli_info
.cur_dir
, "\\");
284 pstrcpy(cli_info
.file_sel
, "");
285 pstrcpy(cli_info
.base_dir
, "");
286 pstrcpy(smb_cli
->domain
, "");
287 pstrcpy(smb_cli
->user_name
, "");
288 pstrcpy(cli_info
.myhostname
, "");
289 pstrcpy(cli_info
.dest_host
, "");
291 pstrcpy(cli_info
.svc_type
, "A:");
292 pstrcpy(cli_info
.share
, "");
293 pstrcpy(cli_info
.service
, "");
295 ZERO_STRUCT(cli_info
.dom
.level3_sid
);
296 pstrcpy(cli_info
.dom
.level3_dom
, "");
297 ZERO_STRUCT(cli_info
.dom
.level5_sid
);
298 pstrcpy(cli_info
.dom
.level5_dom
, "");
300 smb_cli
->nt_pipe_fnum
= 0xffff;
302 setup_logging(pname
, True
);
305 charset_initialise();
310 if (!get_myname(global_myname
))
312 fprintf(stderr
, "Failed to get my hostname.\n");
325 pstrcpy(cli_info
.service
, argv
[1]);
326 /* Convert any '/' characters in the service name to '\' characters */
327 string_replace( cli_info
.service
, '/','\\');
331 DEBUG(1,("service: %s\n", cli_info
.service
));
333 if (count_chars(cli_info
.service
,'\\') < 3)
336 printf("\n%s: Not enough '\\' characters in service\n", cli_info
.service
);
341 if (count_chars(cli_info.service,'\\') > 3)
344 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
349 if (argc
> 1 && (*argv
[1] != '-'))
352 pstrcpy(password
,argv
[1]);
353 memset(argv
[1],'X',strlen(argv
[1]));
358 cli_action
= CLIENT_SVC
;
361 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
)
367 /* FIXME ... max_protocol seems to be funny here */
369 int max_protocol
= 0;
370 max_protocol
= interpret_protocol(optarg
,max_protocol
);
371 fprintf(stderr
, "max protocol not currently supported\n");
377 pstrcpy(user_socket_options
,optarg
);
383 pstrcpy(cli_info
.dest_host
,optarg
);
384 strupper(cli_info
.dest_host
);
385 cli_action
= CLIENT_IPC
;
391 pstrcpy(scope
, optarg
);
398 pstrcpy(smb_cli
->user_name
,optarg
);
399 if ((lp
=strchr(smb_cli
->user_name
,'%')))
402 pstrcpy(password
,lp
+1);
404 memset(strchr(optarg
,'%')+1,'X',strlen(password
));
411 pstrcpy(smb_cli
->domain
,optarg
);
423 cli_info
.dest_ip
= *interpret_addr2(optarg
);
424 if (zero_ip(cli_info
.dest_ip
))
433 nprocs
= atoi(optarg
);
439 numops
= atoi(optarg
);
445 fstrcpy(global_myname
, optarg
);
454 DEBUGLEVEL
= atoi(optarg
);
460 slprintf(debugf
, sizeof(debugf
)-1,
481 pstrcpy(servicesf
, optarg
);
487 pstrcpy(term_code
, optarg
);
500 if (cli_action
== CLIENT_NONE
)
506 strupper(global_myname
);
507 fstrcpy(cli_info
.myhostname
, global_myname
);
509 DEBUG(3,("%s client started (version %s)\n",timestring(False
),VERSION
));
511 if (*smb_cli
->domain
== 0)
513 pstrcpy(smb_cli
->domain
,lp_workgroup());
515 strupper(smb_cli
->domain
);
519 if (cli_action
== CLIENT_IPC
)
521 pstrcpy(cli_info
.share
, "IPC$");
522 pstrcpy(cli_info
.svc_type
, "IPC");
525 fstrcpy(cli_info
.mach_acct
, cli_info
.myhostname
);
526 strupper(cli_info
.mach_acct
);
527 fstrcat(cli_info
.mach_acct
, "$");
529 /* set the password cache info */
532 if (password
[0] == 0)
534 pwd_set_nullpwd(&(smb_cli
->pwd
));
538 pwd_make_lm_nt_16(&(smb_cli
->pwd
), password
); /* generate 16 byte hashes */
543 char *pwd
= getpass("Enter Password:");
544 safe_strcpy(password
, pwd
, sizeof(password
));
545 pwd_make_lm_nt_16(&(smb_cli
->pwd
), password
); /* generate 16 byte hashes */
548 create_procs(nprocs
, numops
, &cli_info
, smb_cli
, run_enums_test
);
550 if (password
[0] != 0)
552 create_procs(nprocs
, numops
, &cli_info
, smb_cli
, run_ntlogin_test
);