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 debugf;
34 extern pstring global_myname;
36 extern pstring user_socket_options;
39 extern int DEBUGLEVEL;
42 #define CNV_LANG(s) dos2unix_format(s,False)
43 #define CNV_INPUT(s) unix2dos_format(s,True)
45 static int process_tok(fstring tok);
46 static void cmd_help(struct client_info *info, int argc, char *argv[]);
47 static void cmd_quit(struct client_info *info, int argc, char *argv[]);
49 static struct cli_state smbcli;
50 struct cli_state *smb_cli = &smbcli;
52 static struct client_info cli_info;
54 static char **cmd_argv = NULL;
55 static uint32 cmd_argc = 0;
59 /****************************************************************************
60 initialise smb client structure
61 ****************************************************************************/
62 void rpcclient_init(void)
64 bzero(smb_cli, sizeof(smb_cli));
65 cli_initialise(smb_cli);
66 smb_cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
69 /****************************************************************************
70 make smb client connection
71 ****************************************************************************/
72 static BOOL rpcclient_connect(struct client_info *info)
74 struct nmb_name calling;
75 struct nmb_name called;
77 make_nmb_name(&called , dns_to_netbios_name(info->dest_host ), info->name_type, scope);
78 make_nmb_name(&calling, dns_to_netbios_name(info->myhostname), 0x0 , scope);
80 smb_cli->use_ntlmv2 = lp_client_ntlmv2();
82 if (!cli_establish_connection(smb_cli,
83 info->dest_host, &info->dest_ip,
85 info->share, info->svc_type,
88 DEBUG(0,("rpcclient_connect: connection failed\n"));
89 cli_shutdown(smb_cli);
96 /****************************************************************************
97 stop the smb connection(s?)
98 ****************************************************************************/
99 static void rpcclient_stop(void)
101 cli_shutdown(smb_cli);
105 #define COMPL_REGKEY 1
106 #define COMPL_SAMUSR 3
107 #define COMPL_SAMGRP 4
108 #define COMPL_SAMALS 5
109 #define COMPL_SVCLST 6
110 #define COMPL_PRTLST 7
112 /****************************************************************************
113 This defines the commands supported by this client
114 ****************************************************************************/
118 void (*fn)(struct client_info*, int, char*[]);
132 {COMPL_NONE, COMPL_NONE}
142 "[-i] Lists Services Manager",
143 {COMPL_NONE, COMPL_NONE}
149 "<service> Service Information",
150 {COMPL_SVCLST, COMPL_NONE}
156 "<service> [arg 0] [arg 1] ... Start Service",
157 {COMPL_SVCLST, COMPL_NONE}
163 "<service> Stop Service",
164 {COMPL_SVCLST, COMPL_NONE}
174 "Scheduler control (at /? for syntax)",
175 {COMPL_NONE, COMPL_NONE}
185 "<keyname> Registry Enumeration (keys, values)",
186 {COMPL_REGKEY, COMPL_NONE}
191 "<keyname> Registry Key Delete",
192 {COMPL_REGKEY, COMPL_NONE}
197 "<keyname> [keyclass] Registry Key Create",
198 {COMPL_REGKEY, COMPL_NONE}
203 "[-m message] [-t timeout] [-r or --reboot] [-f or --force-close] Remote Shutdown",
204 {COMPL_NONE, COMPL_NONE}
209 "<valname> Registry Value Query",
210 {COMPL_REGKEY, COMPL_NONE}
215 "<keyname> Registry Key Query",
216 {COMPL_REGKEY, COMPL_NONE}
221 "<valname> Registry Value Delete",
222 {COMPL_REGKEY, COMPL_REGKEY}
227 "<valname> <valtype> <value> Registry Key Create",
228 {COMPL_REGKEY, COMPL_NONE}
233 "<keyname> Registry Key Security",
234 {COMPL_REGKEY, COMPL_NONE}
238 cmd_reg_test_key_sec,
239 "<keyname> Test Registry Key Security",
240 {COMPL_REGKEY, COMPL_NONE}
249 cmd_spoolss_enum_printers,
250 "Enumerate Printers",
251 {COMPL_NONE, COMPL_NONE}
255 cmd_spoolss_enum_jobs,
256 "<printer name> Enumerate Printer Jobs",
257 {COMPL_PRTLST, COMPL_NONE}
261 cmd_spoolss_open_printer_ex,
262 "<printer name> Spool Printer Open Test",
263 {COMPL_PRTLST, COMPL_NONE}
271 "Display remote time",
272 {COMPL_NONE, COMPL_NONE}
277 "Browser Query Info",
278 {COMPL_NONE, COMPL_NONE}
283 "Workstation Query Info",
284 {COMPL_NONE, COMPL_NONE}
290 {COMPL_NONE, COMPL_NONE}
295 "List sessions on a server",
296 {COMPL_NONE, COMPL_NONE}
301 "List shares on a server",
302 {COMPL_NONE, COMPL_NONE}
307 "List transports on a server",
308 {COMPL_NONE, COMPL_NONE}
313 "List connections on a server",
314 {COMPL_NONE, COMPL_NONE}
319 "List files on a server",
320 {COMPL_NONE, COMPL_NONE}
330 "Query Info Policy (domain member or server)",
331 {COMPL_NONE, COMPL_NONE}
335 cmd_lsa_enum_trust_dom,
336 "Enumerate Trusted Domains",
337 {COMPL_NONE, COMPL_NONE}
342 "Resolve names from SIDs",
343 {COMPL_NONE, COMPL_NONE}
347 cmd_lsa_lookup_names,
348 "Resolve SIDs from names",
349 {COMPL_NONE, COMPL_NONE}
353 cmd_lsa_query_secret,
354 "LSA Query Secret (developer use)",
355 {COMPL_NONE, COMPL_NONE}
364 cmd_netlogon_login_test,
365 "[username] [password] NT Domain login test",
366 {COMPL_NONE, COMPL_NONE}
370 cmd_netlogon_domain_test,
371 "<domain> NT Inter-Domain test",
372 {COMPL_NONE, COMPL_NONE}
381 cmd_sam_lookup_domain,
382 "Obtain SID for a local domain",
383 {COMPL_NONE, COMPL_NONE}
388 "SAM User Database Query (experimental!)",
389 {COMPL_NONE, COMPL_NONE}
393 cmd_sam_add_groupmem,
394 "<group rid> [user] [user] ... SAM Add Domain Group Member",
395 {COMPL_SAMGRP, COMPL_SAMUSR}
400 cmd_sam_add_aliasmem,
401 "<alias rid> [member sid1] [member sid2] ... SAM Add Domain Alias Member",
402 {COMPL_SAMALS, COMPL_NONE}
406 cmd_sam_del_groupmem,
407 "<group rid> [user] [user] ... SAM Delete Domain Group Member",
408 {COMPL_SAMGRP, COMPL_SAMUSR}
412 cmd_sam_del_aliasmem,
413 "<alias rid> [member sid1] [member sid2] ... SAM Delete Domain Alias Member",
414 {COMPL_SAMALS, COMPL_NONE}
418 cmd_sam_create_dom_group,
419 "SAM Create Domain Group",
420 {COMPL_NONE, COMPL_NONE}
424 cmd_sam_create_dom_alias,
425 "SAM Create Domain Alias",
426 {COMPL_NONE, COMPL_NONE}
430 cmd_sam_create_dom_user,
431 "<username> SAM Create Domain User",
432 {COMPL_NONE, COMPL_NONE}
436 cmd_sam_delete_dom_group,
437 "SAM Delete Domain Group",
438 {COMPL_SAMGRP, COMPL_NONE}
442 cmd_sam_delete_dom_alias,
443 "SAM Delete Domain Alias",
444 {COMPL_SAMALS, COMPL_NONE}
448 cmd_sam_ntchange_pwd,
449 "NT SAM Password Change",
450 {COMPL_NONE, COMPL_NONE}
454 cmd_sam_set_userinfo2,
455 "<username> [-s acb_bits] SAM User Set Info 2 (experimental!)",
456 {COMPL_SAMUSR, COMPL_NONE}
460 cmd_sam_set_userinfo,
461 "<username> [-p password] SAM User Set Info (experimental!)",
462 {COMPL_SAMUSR, COMPL_NONE}
467 "<username> SAM User Query (experimental!)",
468 {COMPL_SAMUSR, COMPL_NONE}
473 "<groupname> SAM Group Query (experimental!)",
474 {COMPL_SAMGRP, COMPL_NONE}
479 "<aliasname> SAM Alias Query",
480 {COMPL_SAMALS, COMPL_NONE}
484 cmd_sam_query_aliasmem,
485 "<aliasname> SAM Alias Members",
486 {COMPL_SAMALS, COMPL_NONE}
490 cmd_sam_query_groupmem,
492 {COMPL_SAMGRP, COMPL_NONE}
497 "SAM User Encrypted RPC test (experimental!)",
498 {COMPL_NONE, COMPL_NONE}
502 cmd_sam_enum_aliases,
503 "SAM Aliases Database Query (experimental!)",
504 {COMPL_NONE, COMPL_NONE}
508 cmd_sam_enum_domains,
509 "SAM Domains Database Query (experimental!)",
510 {COMPL_NONE, COMPL_NONE}
515 "SAM Group Database Query (experimental!)",
516 {COMPL_NONE, COMPL_NONE}
520 cmd_sam_query_dominfo,
521 "SAM Query Domain Info",
522 {COMPL_NONE, COMPL_NONE}
526 cmd_sam_query_dispinfo,
527 "SAM Query Display Info",
528 {COMPL_NONE, COMPL_NONE}
533 "SAM Synchronization Test (experimental)",
534 {COMPL_NONE, COMPL_NONE}
545 {COMPL_NONE, COMPL_NONE}
551 {COMPL_NONE, COMPL_NONE}
557 {COMPL_NONE, COMPL_NONE}
563 {COMPL_NONE, COMPL_NONE}
573 "[command] give help on a command",
574 {COMPL_NONE, COMPL_NONE}
579 "[command] give help on a command",
580 {COMPL_NONE, COMPL_NONE}
590 "run a shell command on the local system",
591 {COMPL_NONE, COMPL_NONE}
602 {COMPL_NONE, COMPL_NONE}
607 /****************************************************************************
608 do a (presumably graceful) quit...
609 ****************************************************************************/
610 static void cmd_quit(struct client_info *info, int argc, char *argv[])
616 smb_mem_write_status(dbf);
617 smb_mem_write_errors(dbf);
618 smb_mem_write_verbose(dbf);
625 /****************************************************************************
627 ****************************************************************************/
628 static void cmd_help(struct client_info *info, int argc, char *argv[])
634 if ((i = process_tok(argv[1])) >= 0)
635 fprintf(out_hnd, "HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
638 while (commands[i].description)
640 for (j=0; commands[i].description && (j<5); j++) {
641 fprintf(out_hnd, "%-15s",commands[i].name);
644 fprintf(out_hnd, "\n");
648 /*******************************************************************
649 lookup a command string in the list of commands, including
651 ******************************************************************/
652 static int process_tok(char *tok)
654 int i = 0, matches = 0;
656 int tok_len = strlen(tok);
658 while (commands[i].fn != NULL)
660 if (strequal(commands[i].name,tok))
666 else if (strnequal(commands[i].name, tok, tok_len))
676 else if (matches == 1)
682 /****************************************************************************
683 process commands from the client
684 ****************************************************************************/
685 static BOOL do_command(struct client_info *info, char *line)
691 /* get the first part of the command */
692 if (!next_token(&ptr,tok,NULL, sizeof(tok)))
699 add_chars_to_array(&cmd_argc, &cmd_argv, tok);
701 } while (next_token(NULL, tok, NULL, sizeof(tok)));
708 if ((i = process_tok(cmd_argv[0])) >= 0)
711 commands[i].fn(info, (uint32)cmd_argc, cmd_argv);
715 fprintf(out_hnd, "%s: command abbreviation ambiguous\n", CNV_LANG(tok));
719 fprintf(out_hnd, "%s: command not found\n", CNV_LANG(tok));
722 free_char_array(cmd_argc, cmd_argv);
729 #ifndef HAVE_LIBREADLINE
730 /****************************************************************************
731 wait for keyboard activity, swallowing network packets
732 ****************************************************************************/
733 static void wait_keyboard(struct cli_state *cli)
736 struct timeval timeout;
740 FD_SET(cli->fd,&fds);
741 FD_SET(fileno(stdin),&fds);
745 sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
747 if (FD_ISSET(fileno(stdin),&fds))
750 /* We deliberately use receive_smb instead of
751 client_receive_smb as we want to receive
752 session keepalives and then drop them here.
754 if (FD_ISSET(cli->fd,&fds))
755 receive_smb(cli->fd,cli->inbuf,0);
760 /****************************************************************************
761 process commands from the client
762 ****************************************************************************/
763 static BOOL process( struct client_info *info, char *cmd_str)
768 if (cmd[0] != '\0') while (cmd[0] != '\0')
772 if ((p = strchr(cmd, ';')) == 0)
774 strncpy(line, cmd, 999);
780 if (p - cmd > 999) p = cmd + 999;
781 strncpy(line, cmd, p - cmd);
782 line[p - cmd] = '\0';
786 /* input language code to internal one */
789 if (!do_command(info, line)) continue;
791 else while (!feof(stdin))
793 #ifdef HAVE_LIBREADLINE
797 #ifndef HAVE_LIBREADLINE
799 /* display a prompt */
800 fprintf(out_hnd, "smb: %s> ", CNV_LANG(info->cur_dir));
804 line[0] = wait_keyboard(smb_cli);
805 /* this might not be such a good idea... */
811 wait_keyboard(smb_cli);
814 /* and get a response */
816 fgets( &line[1],999, stdin);
818 if (!fgets(line,1000,stdin))
824 #else /* HAVE_LIBREADLINE */
826 slprintf(promptline, sizeof(promptline) - 1, "smb: %s> ",
827 CNV_LANG(info->cur_dir));
829 if (!readline(promptline))
832 /* Copy read line to samba buffer */
834 pstrcpy(line, rl_line_buffer);
838 if (strlen(line) > 0)
841 /* input language code to internal one */
844 /* special case - first char is ! */
851 fprintf(out_hnd, "%s\n", line);
853 if (!do_command(info, line)) continue;
859 /****************************************************************************
861 ****************************************************************************/
862 static void usage(char *pname)
864 fprintf(out_hnd, "Usage: %s [service] [-S server] [-d debuglevel] [-l log] ",
867 fprintf(out_hnd, "\nVersion %s\n",VERSION);
868 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
869 fprintf(out_hnd, "\tservice connect to \\\\server\\share \n");
870 fprintf(out_hnd, "\t-S server connect to \\\\server\\IPC$ \n");
871 fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
872 fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
873 fprintf(out_hnd, "\t-N don't ask for a password\n");
874 fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
875 fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
876 fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
877 fprintf(out_hnd, "\t-U username set the network username\n");
878 fprintf(out_hnd, "\t-W domain set the domain name\n");
879 fprintf(out_hnd, "\t-c command string execute semicolon separated commands\n");
880 fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
881 fprintf(out_hnd, "\n");
891 #ifdef HAVE_LIBREADLINE
893 /****************************************************************************
894 GNU readline completion functions
895 ****************************************************************************/
897 /* Complete a remote registry enum */
899 static uint32 reg_list_len = 0;
900 static char **reg_name = NULL;
902 static void reg_init(int val, const char *full_keyname, int num)
908 free_char_array(reg_list_len, reg_name);
920 static void reg_key_list(const char *full_name,
921 const char *name, time_t key_mod_time)
924 slprintf(key_name, sizeof(key_name)-1, "%s\\", name);
925 add_chars_to_array(®_list_len, ®_name, key_name);
928 static void reg_val_list(const char *full_name,
931 const BUFFER2 *value)
933 add_chars_to_array(®_list_len, ®_name, name);
936 static char *complete_regenum(char *text, int state)
938 pstring full_keyname;
943 if (cmd_argc >= 2 && cmd_argv != NULL && cmd_argv[1] != NULL)
946 pstrcpy(full_keyname, cmd_argv[1]);
947 sep = strrchr(full_keyname, '\\');
954 /* Iterate all keys / values */
955 if (!msrpc_reg_enum_key(smb_cli, full_keyname,
956 reg_init, reg_key_list, reg_val_list))
964 for (; i < reg_list_len; i++)
966 if (text == NULL || text[0] == 0 ||
967 strnequal(text, reg_name[i], strlen(text)))
969 char *name = strdup(reg_name[i]);
979 static char *complete_samenum_usr(char *text, int state)
982 static uint32 num_usrs = 0;
983 static struct acct_info *sam = NULL;
991 sid_copy(&sid1, &cli_info.dom.level5_sid);
992 sid_to_string(sid, &sid1);
993 fstrcpy(domain, cli_info.dom.level5_dom);
995 if (sid1.num_auths == 0)
1000 fstrcpy(srv_name, "\\\\");
1001 fstrcat(srv_name, cli_info.dest_host);
1008 /* Iterate all users */
1009 if (msrpc_sam_enum_users(smb_cli,
1010 domain, &sid1, srv_name,
1012 NULL, NULL, NULL, NULL) == 0)
1020 for (; i < num_usrs; i++)
1022 char *usr_name = sam[i].acct_name;
1023 if (text == NULL || text[0] == 0 ||
1024 strnequal(text, usr_name, strlen(text)))
1026 char *name = strdup(usr_name);
1035 static char *complete_samenum_als(char *text, int state)
1037 static uint32 i = 0;
1038 static uint32 num_als = 0;
1039 static struct acct_info *sam = NULL;
1047 sid_copy(&sid1, &cli_info.dom.level5_sid);
1048 sid_to_string(sid, &sid1);
1049 fstrcpy(domain, cli_info.dom.level5_dom);
1051 if (sid1.num_auths == 0)
1056 fstrcpy(srv_name, "\\\\");
1057 fstrcat(srv_name, cli_info.dest_host);
1064 /* Iterate all aliases */
1065 if (msrpc_sam_enum_aliases(smb_cli,
1066 domain, &sid1, srv_name,
1068 NULL, NULL, NULL) == 0)
1076 for (; i < num_als; i++)
1078 char *als_name = sam[i].acct_name;
1079 if (text == NULL || text[0] == 0 ||
1080 strnequal(text, als_name, strlen(text)))
1082 char *name = strdup(als_name);
1091 static char *complete_samenum_grp(char *text, int state)
1093 static uint32 i = 0;
1094 static uint32 num_grps = 0;
1095 static struct acct_info *sam = NULL;
1103 sid_copy(&sid1, &cli_info.dom.level5_sid);
1104 sid_to_string(sid, &sid1);
1105 fstrcpy(domain, cli_info.dom.level5_dom);
1107 if (sid1.num_auths == 0)
1112 fstrcpy(srv_name, "\\\\");
1113 fstrcat(srv_name, cli_info.dest_host);
1120 /* Iterate all groups */
1121 if (msrpc_sam_enum_groups(smb_cli,
1122 domain, &sid1, srv_name,
1124 NULL, NULL, NULL) == 0)
1132 for (; i < num_grps; i++)
1134 char *grp_name = sam[i].acct_name;
1135 if (text == NULL || text[0] == 0 ||
1136 strnequal(text, grp_name, strlen(text)))
1138 char *name = strdup(grp_name);
1147 static char *complete_svcenum(char *text, int state)
1149 static uint32 i = 0;
1150 static uint32 num_svcs = 0;
1151 static ENUM_SRVC_STATUS *svc = NULL;
1159 /* Iterate all users */
1160 if (msrpc_svc_enum(&cli_info, &svc, &num_svcs,
1169 for (; i < num_svcs; i++)
1172 unistr_to_ascii(svc_name, svc[i].uni_srvc_name.buffer,
1173 sizeof(svc_name)-1);
1175 if (text == NULL || text[0] == 0 ||
1176 strnequal(text, svc_name, strlen(text)))
1178 char *name = strdup(svc_name);
1187 static char *complete_printersenum(char *text, int state)
1189 static uint32 i = 0;
1190 static uint32 num = 0;
1191 static PRINTER_INFO_1 **ctr = NULL;
1196 fstrcpy(srv_name, "\\\\");
1197 fstrcat(srv_name, smb_cli->desthost);
1200 free_print1_array(num, ctr);
1204 /* Iterate all users */
1205 if (!msrpc_spoolss_enum_printers(smb_cli, srv_name,
1206 1, &num, (void***)&ctr,
1215 for (; i < num; i++)
1218 unistr_to_ascii(name, ctr[i]->name.buffer,
1221 if (text == NULL || text[0] == 0 ||
1222 strnequal(text, name, strlen(text)))
1224 char *copy = strdup(name);
1233 /* Complete an rpcclient command */
1235 static char *complete_cmd(char *text, int state)
1237 static int cmd_index;
1246 /* Return the next name which partially matches the list of commands */
1248 while (strlen(name = commands[cmd_index++].name) > 0) {
1249 if (strncmp(name, text, strlen(text)) == 0) {
1250 return strdup(name);
1257 /* Main completion function */
1259 static char **completion_fn(char *text, int start, int end)
1261 pstring cmd_partial;
1268 safe_strcpy(cmd_partial, rl_line_buffer,
1269 MAX(sizeof(cmd_partial),end)-1);
1271 /* Complete rpcclient command */
1275 return completion_matches(text, complete_cmd);
1278 /* Count # of words in command */
1281 for (i = 0; i <= end; i++) {
1282 if ((rl_line_buffer[i] != ' ') && (lastch == ' '))
1286 lastch = rl_line_buffer[i];
1289 if (rl_line_buffer[end] == ' ')
1292 /* Work out which command we are completing for */
1294 for (cmd_index = 0; strcmp(commands[cmd_index].name, "") != 0;
1297 /* Check each command in array */
1299 if (strncmp(rl_line_buffer, commands[cmd_index].name,
1300 strlen(commands[cmd_index].name)) == 0) {
1302 /* Call appropriate completion function */
1304 if (num_words == 2 || num_words == 3)
1306 switch (commands[cmd_index].compl_args[num_words - 2])
1310 return completion_matches(text, complete_samenum_grp);
1313 return completion_matches(text, complete_samenum_als);
1316 return completion_matches(text, complete_samenum_usr);
1319 return completion_matches(text, complete_svcenum);
1322 return completion_matches(text, complete_printersenum);
1325 return completion_matches(text, complete_regenum);
1328 /* An invalid completion type */
1340 /* To avoid filename completion being activated when no valid
1341 completions are found, we assign this stub completion function
1342 to the rl_completion_entry_function variable. */
1344 static char *complete_cmd_null(char *text, int state)
1349 #endif /* HAVE_LIBREADLINE */
1351 /****************************************************************************
1353 ****************************************************************************/
1354 int main(int argc,char *argv[])
1356 BOOL interactive = True;
1360 extern char *optarg;
1362 static pstring servicesf = CONFIGFILE;
1365 BOOL got_pass = False;
1367 mode_t myumask = 0755;
1368 enum client_action cli_action = CLIENT_NONE;
1370 pstring password; /* local copy only, if one is entered */
1373 fstrcpy(debugf, argv[0]);
1378 pstrcpy(term_code, KANJI);
1385 cli_info.put_total_size = 0;
1386 cli_info.put_total_time_ms = 0;
1387 cli_info.get_total_size = 0;
1388 cli_info.get_total_time_ms = 0;
1390 cli_info.dir_total = 0;
1391 cli_info.newer_than = 0;
1392 cli_info.archive_level = 0;
1393 cli_info.print_mode = 1;
1395 cli_info.translation = False;
1396 cli_info.recurse_dir = False;
1397 cli_info.lowercase = False;
1398 cli_info.prompt = True;
1399 cli_info.abort_mget = True;
1401 cli_info.dest_ip.s_addr = 0;
1402 cli_info.name_type = 0x20;
1404 pstrcpy(cli_info.cur_dir , "\\");
1405 pstrcpy(cli_info.file_sel, "");
1406 pstrcpy(cli_info.base_dir, "");
1407 pstrcpy(smb_cli->domain, "");
1408 pstrcpy(smb_cli->user_name, "");
1409 pstrcpy(cli_info.myhostname, "");
1410 pstrcpy(cli_info.dest_host, "");
1412 pstrcpy(cli_info.svc_type, "A:");
1413 pstrcpy(cli_info.share, "");
1414 pstrcpy(cli_info.service, "");
1416 ZERO_STRUCT(cli_info.dom.level3_sid);
1417 ZERO_STRUCT(cli_info.dom.level5_sid);
1418 fstrcpy(cli_info.dom.level3_dom, "");
1419 fstrcpy(cli_info.dom.level5_dom, "");
1421 #ifdef HAVE_LIBREADLINE
1423 /* Initialise GNU Readline */
1425 rl_readline_name = "rpcclient";
1426 rl_attempted_completion_function = completion_fn;
1427 rl_completion_entry_function = (Function *)complete_cmd_null;
1429 /* Initialise history list */
1433 #endif /* HAVE_LIBREADLINE */
1436 charset_initialise();
1441 if (!get_myname(global_myname, NULL))
1443 fprintf(stderr, "Failed to get my hostname.\n");
1448 pstrcpy(smb_cli->user_name,getenv("USER"));
1450 /* modification to support userid%passwd syntax in the USER var
1451 25.Aug.97, jdblair@uab.edu */
1453 if ((p=strchr(smb_cli->user_name,'%')))
1456 pstrcpy(password,p+1);
1458 memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
1460 strupper(smb_cli->user_name);
1465 /* modification to support PASSWD environmental var
1466 25.Aug.97, jdblair@uab.edu */
1467 if (getenv("PASSWD"))
1469 pstrcpy(password,getenv("PASSWD"));
1472 if (*smb_cli->user_name == 0 && getenv("LOGNAME"))
1474 pstrcpy(smb_cli->user_name,getenv("LOGNAME"));
1475 strupper(smb_cli->user_name);
1484 if (*argv[1] != '-')
1487 pstrcpy(cli_info.service, argv[1]);
1488 /* Convert any '/' characters in the service name to '\' characters */
1489 string_replace( cli_info.service, '/','\\');
1493 fprintf(out_hnd, "service: %s\n", cli_info.service);
1495 if (count_chars(cli_info.service,'\\') < 3)
1498 printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
1503 if (count_chars(cli_info.service,'\\') > 3)
1506 printf("\n%s: Too many '\\' characters in service\n", cli_info.service);
1511 if (argc > 1 && (*argv[1] != '-'))
1514 pstrcpy(password,argv[1]);
1515 memset(argv[1],'X',strlen(argv[1]));
1520 cli_action = CLIENT_SVC;
1523 while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
1529 /* FIXME ... max_protocol seems to be funny here */
1531 int max_protocol = 0;
1532 max_protocol = interpret_protocol(optarg,max_protocol);
1533 fprintf(stderr, "max protocol not currently supported\n");
1539 pstrcpy(user_socket_options,optarg);
1545 pstrcpy(cli_info.dest_host,optarg);
1546 strupper(cli_info.dest_host);
1547 cli_action = CLIENT_IPC;
1553 iface_set_default(NULL,optarg,NULL);
1559 pstrcpy(scope, optarg);
1566 pstrcpy(smb_cli->user_name,optarg);
1567 if ((lp=strchr(smb_cli->user_name,'%')))
1570 pstrcpy(password,lp+1);
1572 memset(strchr(optarg,'%')+1,'X',strlen(password));
1579 pstrcpy(smb_cli->domain,optarg);
1591 cli_info.dest_ip = *interpret_addr2(optarg);
1592 if (zero_ip(cli_info.dest_ip))
1601 fstrcpy(global_myname, optarg);
1616 DEBUGLEVEL = atoi(optarg);
1622 slprintf(debugf, sizeof(debugf)-1,
1623 "%s.client", optarg);
1624 interactive = False;
1644 pstrcpy(servicesf, optarg);
1650 pstrcpy(term_code, optarg);
1663 setup_logging(debugf, interactive);
1665 if (cli_action == CLIENT_NONE)
1671 strupper(global_myname);
1672 fstrcpy(cli_info.myhostname, global_myname);
1674 DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
1676 if (!lp_load(servicesf,True, False, False))
1678 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
1681 codepage_initialise(lp_client_code_page());
1685 if (cli_action == CLIENT_IPC)
1687 pstrcpy(cli_info.share, "IPC$");
1688 pstrcpy(cli_info.svc_type, "IPC");
1691 fstrcpy(cli_info.mach_acct, cli_info.myhostname);
1692 strupper(cli_info.mach_acct);
1693 fstrcat(cli_info.mach_acct, "$");
1695 /* set the password cache info */
1698 if (password[0] == 0)
1700 pwd_set_nullpwd(&(smb_cli->pwd));
1704 /* generate 16 byte hashes */
1705 pwd_make_lm_nt_16(&(smb_cli->pwd), password);
1710 pwd_read(&(smb_cli->pwd), "Enter Password:", True);
1713 mdfour(smb_cli->sess_key, smb_cli->pwd.smb_nt_pwd, 16);
1715 /* paranoia: destroy the local copy of the password */
1716 bzero(password, sizeof(password));
1718 /* establish connections. nothing to stop these being re-established. */
1719 rpcclient_connect(&cli_info);
1721 smb_cli->ntlmssp_cli_flgs = 0x0;
1723 DEBUG(5,("rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd));
1724 if (smb_cli->fd <= 0)
1726 fprintf(stderr, "warning: connection could not be established to %s<%02x>\n",
1727 cli_info.dest_host, cli_info.name_type);
1728 fprintf(stderr, "this version of smbclient may crash if you proceed\n");
1736 process(&cli_info, cmd_str);
1742 fprintf(stderr, "unknown client action requested\n");