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[]);
48 static void cmd_set (struct client_info *info, int argc, char *argv[]);
49 static void cmd_net (struct client_info *info, int argc, char *argv[]);
51 static struct user_credentials usr;
53 static struct client_info cli_info;
55 static char **cmd_argv = NULL;
56 static uint32 cmd_argc = 0;
61 #define COMPL_REGKEY 1
62 #define COMPL_SAMUSR 3
63 #define COMPL_SAMGRP 4
64 #define COMPL_SAMALS 5
65 #define COMPL_SVCLST 6
66 #define COMPL_PRTLST 7
68 /****************************************************************************
69 This defines the commands supported by this client
70 ****************************************************************************/
71 struct command_set commands[] =
81 {COMPL_NONE, COMPL_NONE}
91 "[-i] Lists Services Manager",
92 {COMPL_NONE, COMPL_NONE}
98 "<service> Service Information",
99 {COMPL_SVCLST, COMPL_NONE}
105 "<service> [arg 0] [arg 1] ... Start Service",
106 {COMPL_SVCLST, COMPL_NONE}
112 "<service> Test Set Service",
113 {COMPL_SVCLST, COMPL_NONE}
119 "<service> Stop Service",
120 {COMPL_SVCLST, COMPL_NONE}
130 "Scheduler control (at /? for syntax)",
131 {COMPL_NONE, COMPL_NONE}
141 "<keyname> Registry Enumeration (keys, values)",
142 {COMPL_REGKEY, COMPL_NONE}
147 "<keyname> Registry Key Delete",
148 {COMPL_REGKEY, COMPL_NONE}
153 "<keyname> [keyclass] Registry Key Create",
154 {COMPL_REGKEY, COMPL_NONE}
159 "[-m message] [-t timeout] [-r or --reboot] [-f or --force-close] Remote Shutdown",
160 {COMPL_NONE, COMPL_NONE}
165 "<valname> Registry Value Query",
166 {COMPL_REGKEY, COMPL_NONE}
171 "<keyname> Registry Key Query",
172 {COMPL_REGKEY, COMPL_NONE}
177 "<valname> Registry Value Delete",
178 {COMPL_REGKEY, COMPL_REGKEY}
183 "<valname> <valtype> <value> Registry Key Create",
184 {COMPL_REGKEY, COMPL_NONE}
189 "<keyname> Registry Key Security",
190 {COMPL_REGKEY, COMPL_NONE}
194 cmd_reg_test_key_sec,
195 "<keyname> Test Registry Key Security",
196 {COMPL_REGKEY, COMPL_NONE}
205 cmd_spoolss_enum_printers,
206 "Enumerate Printers",
207 {COMPL_NONE, COMPL_NONE}
211 cmd_spoolss_enum_jobs,
212 "<printer name> Enumerate Printer Jobs",
213 {COMPL_PRTLST, COMPL_NONE}
217 cmd_spoolss_open_printer_ex,
218 "<printer name> Spool Printer Open Test",
219 {COMPL_PRTLST, COMPL_NONE}
227 "Display remote time",
228 {COMPL_NONE, COMPL_NONE}
233 "Browser Query Info",
234 {COMPL_NONE, COMPL_NONE}
239 "Workstation Query Info",
240 {COMPL_NONE, COMPL_NONE}
246 {COMPL_NONE, COMPL_NONE}
251 "List sessions on a server",
252 {COMPL_NONE, COMPL_NONE}
257 "List shares on a server",
258 {COMPL_NONE, COMPL_NONE}
263 "List transports on a server",
264 {COMPL_NONE, COMPL_NONE}
269 "List connections on a server",
270 {COMPL_NONE, COMPL_NONE}
275 "List files on a server",
276 {COMPL_NONE, COMPL_NONE}
286 "Query Info Policy (domain member or server)",
287 {COMPL_NONE, COMPL_NONE}
291 cmd_lsa_enum_trust_dom,
292 "Enumerate Trusted Domains",
293 {COMPL_NONE, COMPL_NONE}
298 "Resolve names from SIDs",
299 {COMPL_NONE, COMPL_NONE}
303 cmd_lsa_lookup_names,
304 "Resolve SIDs from names",
305 {COMPL_NONE, COMPL_NONE}
309 cmd_lsa_query_secret,
310 "LSA Query Secret (developer use)",
311 {COMPL_NONE, COMPL_NONE}
320 cmd_netlogon_login_test,
321 "[username] [password] NT Domain login test",
322 {COMPL_NONE, COMPL_NONE}
326 cmd_netlogon_domain_test,
327 "<domain> NT Inter-Domain test",
328 {COMPL_NONE, COMPL_NONE}
337 cmd_sam_lookup_domain,
338 "Obtain SID for a local domain",
339 {COMPL_NONE, COMPL_NONE}
344 "SAM User Database Query (experimental!)",
345 {COMPL_NONE, COMPL_NONE}
349 cmd_sam_add_groupmem,
350 "<group rid> [user] [user] ... SAM Add Domain Group Member",
351 {COMPL_SAMGRP, COMPL_SAMUSR}
356 cmd_sam_add_aliasmem,
357 "<alias rid> [member sid1] [member sid2] ... SAM Add Domain Alias Member",
358 {COMPL_SAMALS, COMPL_NONE}
362 cmd_sam_del_groupmem,
363 "<group rid> [user] [user] ... SAM Delete Domain Group Member",
364 {COMPL_SAMGRP, COMPL_SAMUSR}
368 cmd_sam_del_aliasmem,
369 "<alias rid> [member sid1] [member sid2] ... SAM Delete Domain Alias Member",
370 {COMPL_SAMALS, COMPL_NONE}
374 cmd_sam_create_dom_group,
375 "SAM Create Domain Group",
376 {COMPL_NONE, COMPL_NONE}
380 cmd_sam_create_dom_alias,
381 "SAM Create Domain Alias",
382 {COMPL_NONE, COMPL_NONE}
386 cmd_sam_create_dom_user,
387 "<username> SAM Create Domain User",
388 {COMPL_NONE, COMPL_NONE}
392 cmd_sam_delete_dom_group,
393 "SAM Delete Domain Group",
394 {COMPL_SAMGRP, COMPL_NONE}
398 cmd_sam_delete_dom_alias,
399 "SAM Delete Domain Alias",
400 {COMPL_SAMALS, COMPL_NONE}
404 cmd_sam_ntchange_pwd,
405 "NT SAM Password Change",
406 {COMPL_NONE, COMPL_NONE}
410 cmd_sam_set_userinfo2,
411 "<username> [-s acb_bits] SAM User Set Info 2 (experimental!)",
412 {COMPL_SAMUSR, COMPL_NONE}
416 cmd_sam_set_userinfo,
417 "<username> [-p password] SAM User Set Info (experimental!)",
418 {COMPL_SAMUSR, COMPL_NONE}
423 "<username> [-g] [-u] [-a] SAM User Query (experimental!)",
424 {COMPL_SAMUSR, COMPL_NONE}
429 "<groupname> SAM Group Query (experimental!)",
430 {COMPL_SAMGRP, COMPL_NONE}
435 "<aliasname> SAM Alias Query",
436 {COMPL_SAMALS, COMPL_NONE}
440 cmd_sam_query_aliasmem,
441 "<aliasname> SAM Alias Members",
442 {COMPL_SAMALS, COMPL_NONE}
446 cmd_sam_query_groupmem,
448 {COMPL_SAMGRP, COMPL_NONE}
453 "SAM User Encrypted RPC test (experimental!)",
454 {COMPL_NONE, COMPL_NONE}
458 cmd_sam_enum_aliases,
459 "SAM Aliases Database Query (experimental!)",
460 {COMPL_NONE, COMPL_NONE}
464 cmd_sam_enum_domains,
465 "SAM Domains Database Query (experimental!)",
466 {COMPL_NONE, COMPL_NONE}
471 "SAM Group Database Query (experimental!)",
472 {COMPL_NONE, COMPL_NONE}
476 cmd_sam_query_dominfo,
477 "SAM Query Domain Info",
478 {COMPL_NONE, COMPL_NONE}
482 cmd_sam_query_dispinfo,
483 "SAM Query Display Info",
484 {COMPL_NONE, COMPL_NONE}
489 "SAM Synchronization Test (experimental)",
490 {COMPL_NONE, COMPL_NONE}
498 "run rpcclient inside rpcclient (change options etc.)",
499 {COMPL_NONE, COMPL_NONE}
505 "net use and net view",
506 {COMPL_NONE, COMPL_NONE}
516 {COMPL_NONE, COMPL_NONE}
522 {COMPL_NONE, COMPL_NONE}
528 {COMPL_NONE, COMPL_NONE}
534 {COMPL_NONE, COMPL_NONE}
544 "[command] give help on a command",
545 {COMPL_NONE, COMPL_NONE}
550 "[command] give help on a command",
551 {COMPL_NONE, COMPL_NONE}
561 "run a shell command on the local system",
562 {COMPL_NONE, COMPL_NONE}
573 {COMPL_NONE, COMPL_NONE}
578 /****************************************************************************
579 do a (presumably graceful) quit...
580 ****************************************************************************/
581 static void cmd_quit(struct client_info *info, int argc, char *argv[])
586 smb_mem_write_status(dbf);
587 smb_mem_write_errors(dbf);
588 smb_mem_write_verbose(dbf);
596 /****************************************************************************
598 ****************************************************************************/
599 static void cmd_help(struct client_info *info, int argc, char *argv[])
605 if ((i = process_tok(argv[1])) >= 0)
606 fprintf(out_hnd, "HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
609 while (commands[i].description)
611 for (j=0; commands[i].description && (j<5); j++) {
612 fprintf(out_hnd, "%-15s",commands[i].name);
615 fprintf(out_hnd, "\n");
619 /*******************************************************************
620 lookup a command string in the list of commands, including
622 ******************************************************************/
623 static int process_tok(char *tok)
625 int i = 0, matches = 0;
627 int tok_len = strlen(tok);
629 while (commands[i].fn != NULL)
631 if (strequal(commands[i].name,tok))
637 else if (strnequal(commands[i].name, tok, tok_len))
647 else if (matches == 1)
653 /****************************************************************************
654 turn command line into command argument array
655 ****************************************************************************/
656 static BOOL get_cmd_args(char *line)
663 /* get the first part of the command */
664 if (!next_token(&ptr,tok,NULL, sizeof(tok)))
671 add_chars_to_array(&cmd_argc, &cmd_argv, tok);
673 } while (next_token(NULL, tok, NULL, sizeof(tok)));
678 /* command options mask */
679 static uint32 cmd_set_options = 0xffffffff;
681 /****************************************************************************
682 process commands from the client
683 ****************************************************************************/
684 static BOOL do_command(struct client_info *info, char *line)
688 if (!get_cmd_args(line)) return False;
695 cmd_set_options = 0x0;
697 if ((i = process_tok(cmd_argv[0])) >= 0)
699 int argc = (int)cmd_argc;
700 char **argv = cmd_argv;
703 commands[i].fn(info, argc, argv);
707 fprintf(out_hnd, "%s: command abbreviation ambiguous\n",
708 CNV_LANG(cmd_argv[0]));
712 fprintf(out_hnd, "%s: command not found\n",
713 CNV_LANG(cmd_argv[0]));
716 free_char_array(cmd_argc, cmd_argv);
721 #ifndef HAVE_LIBREADLINE
722 /****************************************************************************
723 wait for keyboard activity, swallowing network packets
724 ****************************************************************************/
725 static void wait_keyboard(struct cli_state *cli)
728 struct timeval timeout;
732 FD_SET(cli->fd,&fds);
733 FD_SET(fileno(stdin),&fds);
737 sys_select(MAX(cli->fd,fileno(stdin))+1,NULL, &fds,&timeout);
739 if (FD_ISSET(fileno(stdin),&fds))
742 /* We deliberately use receive_smb instead of
743 client_receive_smb as we want to receive
744 session keepalives and then drop them here.
746 if (FD_ISSET(cli->fd,&fds))
747 receive_smb(cli->fd,cli->inbuf,0);
752 /****************************************************************************
753 process commands from the client
754 ****************************************************************************/
755 static BOOL process( struct client_info *info, char *cmd_str)
762 while (cmd[0] != '\0')
766 if ((p = strchr(cmd, ';')) == 0)
768 strncpy(line, cmd, 999);
774 if (p - cmd > 999) p = cmd + 999;
775 strncpy(line, cmd, p - cmd);
776 line[p - cmd] = '\0';
780 /* input language code to internal one */
783 if (!do_command(info, line)) continue;
786 else while (!feof(stdin))
788 #ifdef HAVE_LIBREADLINE
792 #ifndef HAVE_LIBREADLINE
794 /* display a prompt */
795 fprintf(out_hnd, "%s$ ", CNV_LANG(cli_info.dest_host));
799 line[0] = wait_keyboard(NULL);
800 /* this might not be such a good idea... */
809 /* and get a response */
811 fgets( &line[1],999, stdin);
813 if (!fgets(line,1000,stdin))
819 #else /* HAVE_LIBREADLINE */
821 slprintf(promptline, sizeof(promptline) - 1, "%s$ ",
822 CNV_LANG(cli_info.dest_host));
824 if (!readline(promptline))
827 /* Copy read line to samba buffer */
829 pstrcpy(line, rl_line_buffer);
833 if (strlen(line) > 0)
836 /* input language code to internal one */
839 /* special case - first char is ! */
846 fprintf(out_hnd, "%s\n", line);
848 if (!do_command(info, line)) continue;
854 /****************************************************************************
856 ****************************************************************************/
857 static void usage(char *pname)
859 fprintf(out_hnd, "Usage: %s [password] [-S server] [-U user] -[W domain] [-l log] ",
862 fprintf(out_hnd, "\nVersion %s\n",VERSION);
863 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
864 fprintf(out_hnd, "\t-S server connect to \\\\server\\IPC$ \n");
865 fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
866 fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
867 fprintf(out_hnd, "\t-N don't ask for a password\n");
868 fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
869 fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
870 fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
871 fprintf(out_hnd, "\t-U username set the network username\n");
872 fprintf(out_hnd, "\t-U username%%pass set the network username and password\n");
873 fprintf(out_hnd, "\t-W domain set the domain name\n");
874 fprintf(out_hnd, "\t-c 'command string' execute semicolon separated commands\n");
875 fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
876 fprintf(out_hnd, "\n");
879 #ifdef HAVE_LIBREADLINE
881 /****************************************************************************
882 GNU readline completion functions
883 ****************************************************************************/
885 /* Complete a remote registry enum */
887 static uint32 reg_list_len = 0;
888 static char **reg_name = NULL;
890 static void reg_init(int val, const char *full_keyname, int num)
896 free_char_array(reg_list_len, reg_name);
908 static void reg_key_list(const char *full_name,
909 const char *name, time_t key_mod_time)
912 slprintf(key_name, sizeof(key_name)-1, "%s\\", name);
913 add_chars_to_array(®_list_len, ®_name, key_name);
916 static void reg_val_list(const char *full_name,
919 const BUFFER2 *value)
921 add_chars_to_array(®_list_len, ®_name, name);
924 static char *complete_regenum(char *text, int state)
926 pstring full_keyname;
932 fstrcpy(srv_name, "\\\\");
933 fstrcat(srv_name, cli_info.dest_host);
936 if (cmd_argc >= 2 && cmd_argv != NULL && cmd_argv[1] != NULL)
939 split_server_keyname(srv_name, full_keyname,
942 sep = strrchr(full_keyname, '\\');
949 /* Iterate all keys / values */
950 if (!msrpc_reg_enum_key(srv_name, full_keyname,
951 reg_init, reg_key_list, reg_val_list))
959 for (; i < reg_list_len; i++)
961 if (text == NULL || text[0] == 0 ||
962 strnequal(text, reg_name[i], strlen(text)))
964 char *name = strdup(reg_name[i]);
974 static char *complete_samenum_usr(char *text, int state)
977 static uint32 num_usrs = 0;
978 static struct acct_info *sam = NULL;
986 sid_copy(&sid1, &cli_info.dom.level5_sid);
987 sid_to_string(sid, &sid1);
988 fstrcpy(domain, cli_info.dom.level5_dom);
990 if (sid1.num_auths == 0)
995 fstrcpy(srv_name, "\\\\");
996 fstrcat(srv_name, cli_info.dest_host);
1003 /* Iterate all users */
1004 if (msrpc_sam_enum_users(srv_name, domain, &sid1,
1006 NULL, NULL, NULL, NULL) == 0)
1014 for (; i < num_usrs; i++)
1016 char *usr_name = sam[i].acct_name;
1017 if (text == NULL || text[0] == 0 ||
1018 strnequal(text, usr_name, strlen(text)))
1020 char *name = strdup(usr_name);
1029 static char *complete_samenum_als(char *text, int state)
1031 static uint32 i = 0;
1032 static uint32 num_als = 0;
1033 static struct acct_info *sam = NULL;
1041 sid_copy(&sid1, &cli_info.dom.level5_sid);
1042 sid_to_string(sid, &sid1);
1043 fstrcpy(domain, cli_info.dom.level5_dom);
1045 if (sid1.num_auths == 0)
1050 fstrcpy(srv_name, "\\\\");
1051 fstrcat(srv_name, cli_info.dest_host);
1058 /* Iterate all aliases */
1059 if (msrpc_sam_enum_aliases(srv_name, domain, &sid1,
1061 NULL, NULL, NULL) == 0)
1069 for (; i < num_als; i++)
1071 char *als_name = sam[i].acct_name;
1072 if (text == NULL || text[0] == 0 ||
1073 strnequal(text, als_name, strlen(text)))
1075 char *name = strdup(als_name);
1084 static char *complete_samenum_grp(char *text, int state)
1086 static uint32 i = 0;
1087 static uint32 num_grps = 0;
1088 static struct acct_info *sam = NULL;
1096 sid_copy(&sid1, &cli_info.dom.level5_sid);
1097 sid_to_string(sid, &sid1);
1098 fstrcpy(domain, cli_info.dom.level5_dom);
1100 if (sid1.num_auths == 0)
1105 fstrcpy(srv_name, "\\\\");
1106 fstrcat(srv_name, cli_info.dest_host);
1113 /* Iterate all groups */
1114 if (msrpc_sam_enum_groups(srv_name,
1117 NULL, NULL, NULL) == 0)
1125 for (; i < num_grps; i++)
1127 char *grp_name = sam[i].acct_name;
1128 if (text == NULL || text[0] == 0 ||
1129 strnequal(text, grp_name, strlen(text)))
1131 char *name = strdup(grp_name);
1140 static char *complete_svcenum(char *text, int state)
1142 static uint32 i = 0;
1143 static uint32 num_svcs = 0;
1144 static ENUM_SRVC_STATUS *svc = NULL;
1147 fstrcpy(srv_name, "\\\\");
1148 fstrcat(srv_name, cli_info.dest_host);
1158 /* Iterate all users */
1159 if (msrpc_svc_enum(srv_name, &svc, &num_svcs,
1168 for (; i < num_svcs; i++)
1171 unistr_to_ascii(svc_name, svc[i].uni_srvc_name.buffer,
1172 sizeof(svc_name)-1);
1174 if (text == NULL || text[0] == 0 ||
1175 strnequal(text, svc_name, strlen(text)))
1177 char *name = strdup(svc_name);
1186 static char *complete_printersenum(char *text, int state)
1188 static uint32 i = 0;
1189 static uint32 num = 0;
1190 static PRINTER_INFO_1 **ctr = NULL;
1195 fstrcpy(srv_name, "\\\\");
1196 fstrcat(srv_name, cli_info.dest_host);
1199 free_print1_array(num, ctr);
1203 /* Iterate all users */
1204 if (!msrpc_spoolss_enum_printers(srv_name,
1205 1, &num, (void***)&ctr,
1214 for (; i < num; i++)
1217 unistr_to_ascii(name, ctr[i]->name.buffer,
1220 if (text == NULL || text[0] == 0 ||
1221 strnequal(text, name, strlen(text)))
1223 char *copy = strdup(name);
1232 /* Complete an rpcclient command */
1234 static char *complete_cmd(char *text, int state)
1236 static int cmd_index;
1245 /* Return the next name which partially matches the list of commands */
1247 while (strlen(name = commands[cmd_index++].name) > 0) {
1248 if (strncmp(name, text, strlen(text)) == 0) {
1249 return strdup(name);
1256 /* Main completion function */
1258 static char **completion_fn(char *text, int start, int end)
1260 pstring cmd_partial;
1267 (void)get_cmd_args(rl_line_buffer);
1269 safe_strcpy(cmd_partial, rl_line_buffer,
1270 MAX(sizeof(cmd_partial),end)-1);
1272 /* Complete rpcclient command */
1276 return completion_matches(text, complete_cmd);
1279 /* Count # of words in command */
1282 for (i = 0; i <= end; i++) {
1283 if ((rl_line_buffer[i] != ' ') && (lastch == ' '))
1287 lastch = rl_line_buffer[i];
1290 if (rl_line_buffer[end] == ' ')
1293 /* Work out which command we are completing for */
1295 for (cmd_index = 0; strcmp(commands[cmd_index].name, "") != 0;
1298 /* Check each command in array */
1300 if (strncmp(rl_line_buffer, commands[cmd_index].name,
1301 strlen(commands[cmd_index].name)) == 0) {
1303 /* Call appropriate completion function */
1305 if (num_words == 2 || num_words == 3)
1307 switch (commands[cmd_index].compl_args[num_words - 2])
1311 return completion_matches(text, complete_samenum_grp);
1314 return completion_matches(text, complete_samenum_als);
1317 return completion_matches(text, complete_samenum_usr);
1320 return completion_matches(text, complete_svcenum);
1323 return completion_matches(text, complete_printersenum);
1326 return completion_matches(text, complete_regenum);
1329 /* An invalid completion type */
1341 /* To avoid filename completion being activated when no valid
1342 completions are found, we assign this stub completion function
1343 to the rl_completion_entry_function variable. */
1345 static char *complete_cmd_null(char *text, int state)
1350 #endif /* HAVE_LIBREADLINE */
1352 static void cmd_net(struct client_info *info, int argc, char *argv[])
1355 BOOL net_use = False;
1356 BOOL net_use_del = False;
1357 BOOL net_use_add = False;
1359 while ((opt = getopt(argc, argv, "udS:U:W:")) != EOF)
1371 report(out_hnd, "net -S \\server [-U user%%pass] [-W domain] [-d]\n");
1372 report(out_hnd, "net -u\n");
1382 struct use_info **use;
1383 cli_net_use_enum(&num_uses, &use);
1387 report(out_hnd, "No connections\n");
1391 report(out_hnd, "Connections:\n");
1393 for (i = 0; i < num_uses; i++)
1395 if (use[i] != NULL && use[i]->connected)
1397 report(out_hnd, "Server:\t%s\t",
1399 report(out_hnd, "User:\t%s\t",
1401 report(out_hnd, "Domain:\t%s\n",
1409 static void set_user_password(struct user_credentials *u,
1410 BOOL got_pass, char *password)
1412 /* set the password cache info */
1415 if (password == NULL)
1417 pwd_set_nullpwd(&(u->pwd));
1421 /* generate 16 byte hashes */
1422 pwd_make_lm_nt_16(&(u->pwd), password);
1427 pwd_read(&(u->pwd), "Enter Password:", True);
1434 #define CMD_TERM 0x8
1435 #define CMD_PASS 0x10
1436 #define CMD_USER 0x20
1437 #define CMD_NOPW 0x40
1438 #define CMD_DBLV 0x80
1439 #define CMD_HELP 0x100
1440 #define CMD_SOCK 0x200
1441 #define CMD_IFACE 0x400
1442 #define CMD_DOM 0x800
1443 #define CMD_IP 0x1000
1444 #define CMD_HOST 0x2000
1445 #define CMD_NAME 0x4000
1446 #define CMD_DBG 0x8000
1447 #define CMD_SCOPE 0x10000
1448 #define CMD_INTER 0x20000
1450 static void cmd_set(struct client_info *info, int argc, char *argv[])
1452 BOOL interactive = True;
1453 char *cmd_str = NULL;
1456 extern char *optarg;
1457 static pstring servicesf = CONFIGFILE;
1459 pstring password; /* local copy only, if one is entered */
1462 pstrcpy(term_code, KANJI);
1467 if (argc > 1 && *argv[1] != '-')
1469 if (argc > 1 && (*argv[1] != '-'))
1471 cmd_set_options |= CMD_PASS;
1472 pstrcpy(password,argv[1]);
1473 memset(argv[1],'X',strlen(argv[1]));
1479 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)
1485 /* FIXME ... max_protocol seems to be funny here */
1487 int max_protocol = 0;
1488 max_protocol = interpret_protocol(optarg,max_protocol);
1489 fprintf(stderr, "max protocol not currently supported\n");
1495 cmd_set_options |= CMD_SOCK;
1496 pstrcpy(user_socket_options,optarg);
1502 cmd_set_options |= CMD_HOST;
1503 pstrcpy(cli_info.dest_host,optarg);
1504 strupper(cli_info.dest_host);
1510 cmd_set_options |= CMD_IFACE;
1511 iface_set_default(NULL,optarg,NULL);
1517 cmd_set_options |= CMD_SCOPE;
1518 pstrcpy(scope, optarg);
1525 cmd_set_options |= CMD_USER;
1526 pstrcpy(usr.user_name,optarg);
1527 if ((lp=strchr(usr.user_name,'%')))
1530 pstrcpy(password,lp+1);
1531 cmd_set_options |= CMD_PASS;
1532 memset(strchr(optarg,'%')+1,'X',strlen(password));
1534 if (usr.user_name[0] == 0 && password[0] == 0)
1536 cmd_set_options |= CMD_NOPW;
1543 cmd_set_options |= CMD_DOM;
1544 pstrcpy(usr.domain,optarg);
1550 cmd_set_options |= CMD_DBG;
1557 cmd_set_options |= CMD_IP;
1558 cli_info.dest_ip = *interpret_addr2(optarg);
1559 if (zero_ip(cli_info.dest_ip))
1569 cmd_set_options |= CMD_NAME;
1570 fstrcpy(global_myname, optarg);
1576 cmd_set_options |= CMD_NOPW | CMD_PASS;
1582 cmd_set_options |= CMD_DBLV;
1586 DEBUGLEVEL = atoi(optarg);
1592 cmd_set_options |= CMD_INTER;
1593 slprintf(debugf, sizeof(debugf)-1,
1594 "%s.client", optarg);
1595 interactive = False;
1601 cmd_set_options |= CMD_STR | CMD_PASS;
1608 cmd_set_options |= CMD_HELP;
1615 cmd_set_options |= CMD_SVC;
1616 pstrcpy(servicesf, optarg);
1622 cmd_set_options |= CMD_TERM;
1623 pstrcpy(term_code, optarg);
1629 cmd_set_options |= CMD_HELP;
1636 DEBUG(10,("cmd_set: options: %x\n", cmd_set_options));
1638 if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
1643 if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
1645 setup_logging(debugf, interactive);
1649 if (IS_BITS_SET_ALL(cmd_set_options, CMD_NOPW))
1651 set_user_password(&usr, True, NULL);
1653 else if (IS_BITS_SET_ALL(cmd_set_options, CMD_PASS))
1655 set_user_password(&usr, True, password);
1658 /* paranoia: destroy the local copy of the password */
1659 bzero(password, sizeof(password));
1661 strupper(global_myname);
1662 fstrcpy(cli_info.myhostname, global_myname);
1664 if (IS_BITS_SET_ALL(cmd_set_options, CMD_SVC))
1666 if (!lp_load(servicesf,True, False, False))
1668 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
1673 if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
1678 if (cmd_str != NULL)
1680 process(&cli_info, cmd_str);
1684 static void read_user_env(struct user_credentials *u)
1693 pstrcpy(u->user_name,getenv("USER"));
1695 /* modification to support userid%passwd syntax in the USER var
1696 25.Aug.97, jdblair@uab.edu */
1698 if ((p=strchr(u->user_name,'%')))
1701 pstrcpy(password,p+1);
1702 memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
1704 strupper(u->user_name);
1707 /* modification to support PASSWD environmental var
1708 25.Aug.97, jdblair@uab.edu */
1709 if (getenv("PASSWD"))
1711 pstrcpy(password,getenv("PASSWD"));
1714 if (*u->user_name == 0 && getenv("LOGNAME"))
1716 pstrcpy(u->user_name,getenv("LOGNAME"));
1717 strupper(u->user_name);
1720 set_user_password(u, True, password);
1722 /* paranoia: destroy the local copy of the password */
1723 bzero(password, sizeof(password));
1726 void readline_init(void)
1728 #ifdef HAVE_LIBREADLINE
1730 /* Initialise GNU Readline */
1732 rl_readline_name = "rpcclient";
1733 rl_attempted_completion_function = completion_fn;
1734 rl_completion_entry_function = (Function *)complete_cmd_null;
1736 /* Initialise history list */
1742 x = 0; /* stop compiler warnings */
1743 #endif /* HAVE_LIBREADLINE */
1746 /****************************************************************************
1748 ****************************************************************************/
1749 int main(int argc,char *argv[])
1751 extern struct user_credentials *usr_creds;
1752 mode_t myumask = 0755;
1756 usr.ntlmssp_flags = 0x0;
1760 fstrcpy(debugf, argv[0]);
1762 init_policy_hnd(64);
1764 pstrcpy(usr.domain, "");
1765 pstrcpy(usr.user_name, "");
1767 pstrcpy(cli_info.myhostname, "");
1768 pstrcpy(cli_info.dest_host, "");
1769 cli_info.dest_ip.s_addr = 0;
1771 ZERO_STRUCT(cli_info.dom.level3_sid);
1772 ZERO_STRUCT(cli_info.dom.level5_sid);
1773 fstrcpy(cli_info.dom.level3_dom, "");
1774 fstrcpy(cli_info.dom.level5_dom, "");
1778 charset_initialise();
1784 if (!get_myname(global_myname, NULL))
1786 fprintf(stderr, "Failed to get my hostname.\n");
1796 read_user_env(&usr);
1798 cmd_set_options &= ~CMD_HELP;
1799 cmd_set_options &= ~CMD_NOPW;
1801 cmd_set(&cli_info, argc, argv);
1803 if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
1809 codepage_initialise(lp_client_code_page());
1811 DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
1813 process(&cli_info, NULL);