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 ntuser_creds 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 "[[DOMAIN\\]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);
722 /****************************************************************************
723 process commands from the client
724 ****************************************************************************/
725 static BOOL process( struct client_info *info, char *cmd_str)
732 while (cmd[0] != '\0')
736 if ((p = strchr(cmd, ';')) == 0)
738 strncpy(line, cmd, 999);
744 if (p - cmd > 999) p = cmd + 999;
745 strncpy(line, cmd, p - cmd);
746 line[p - cmd] = '\0';
750 /* input language code to internal one */
753 if (!do_command(info, line)) continue;
756 else while (!feof(stdin))
761 safe_strcat(pline, "[", sizeof(pline)-1);
762 if (usr.domain[0] != 0)
764 safe_strcat(pline, usr.domain, sizeof(pline)-1);
765 safe_strcat(pline, "\\", sizeof(pline)-1);
768 if (usr.user_name[0] != 0)
770 safe_strcat(pline, usr.user_name, sizeof(pline)-1);
775 safe_strcat(pline, "@", sizeof(pline)-1);
778 safe_strcat(pline, cli_info.dest_host, sizeof(pline)-1);
779 safe_strcat(pline, "]$ ", sizeof(pline)-1);
781 #ifndef HAVE_LIBREADLINE
783 /* display a prompt */
784 fprintf(out_hnd, "%s", CNV_LANG(pline));
787 cli_use_wait_keyboard();
789 /* and get a response */
790 if (!fgets(line,1000,stdin))
795 #else /* HAVE_LIBREADLINE */
797 if (!readline(pline))
800 /* Copy read line to samba buffer */
802 pstrcpy(line, rl_line_buffer);
806 if (strlen(line) > 0)
809 /* input language code to internal one */
812 /* special case - first char is ! */
819 fprintf(out_hnd, "%s\n", line);
821 if (!do_command(info, line)) continue;
827 /****************************************************************************
829 ****************************************************************************/
830 static void usage(char *pname)
832 fprintf(out_hnd, "Usage: %s [password] [-S server] [-U user] -[W domain] [-l log] ",
835 fprintf(out_hnd, "\nVersion %s\n",VERSION);
836 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
837 fprintf(out_hnd, "\t-S server connect to \\\\server\\IPC$ \n");
838 fprintf(out_hnd, "\t-l log basename. Basename for log/debug files\n");
839 fprintf(out_hnd, "\t-n netbios name. Use this name as my netbios name\n");
840 fprintf(out_hnd, "\t-N don't ask for a password\n");
841 fprintf(out_hnd, "\t-m max protocol set the max protocol level\n");
842 fprintf(out_hnd, "\t-I dest IP use this IP to connect to\n");
843 fprintf(out_hnd, "\t-E write messages to stderr instead of stdout\n");
844 fprintf(out_hnd, "\t-U username set the network username\n");
845 fprintf(out_hnd, "\t-U username%%pass set the network username and password\n");
846 fprintf(out_hnd, "\t-W domain set the domain name\n");
847 fprintf(out_hnd, "\t-c 'command string' execute semicolon separated commands\n");
848 fprintf(out_hnd, "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
849 fprintf(out_hnd, "\n");
852 #ifdef HAVE_LIBREADLINE
854 /****************************************************************************
855 GNU readline completion functions
856 ****************************************************************************/
858 /* Complete a remote registry enum */
860 static uint32 reg_list_len = 0;
861 static char **reg_name = NULL;
863 static void reg_init(int val, const char *full_keyname, int num)
869 free_char_array(reg_list_len, reg_name);
881 static void reg_key_list(const char *full_name,
882 const char *name, time_t key_mod_time)
885 slprintf(key_name, sizeof(key_name)-1, "%s\\", name);
886 add_chars_to_array(®_list_len, ®_name, key_name);
889 static void reg_val_list(const char *full_name,
892 const BUFFER2 *value)
894 add_chars_to_array(®_list_len, ®_name, name);
897 static char *complete_regenum(char *text, int state)
899 pstring full_keyname;
905 fstrcpy(srv_name, "\\\\");
906 fstrcat(srv_name, cli_info.dest_host);
909 if (cmd_argc >= 2 && cmd_argv != NULL && cmd_argv[1] != NULL)
912 split_server_keyname(srv_name, full_keyname,
915 sep = strrchr(full_keyname, '\\');
922 /* Iterate all keys / values */
923 if (!msrpc_reg_enum_key(srv_name, full_keyname,
924 reg_init, reg_key_list, reg_val_list))
932 for (; i < reg_list_len; i++)
934 if (text == NULL || text[0] == 0 ||
935 strnequal(text, reg_name[i], strlen(text)))
937 char *name = strdup(reg_name[i]);
947 static char *complete_samenum_usr(char *text, int state)
950 static uint32 num_usrs = 0;
951 static struct acct_info *sam = NULL;
959 sid_copy(&sid1, &cli_info.dom.level5_sid);
960 sid_to_string(sid, &sid1);
961 fstrcpy(domain, cli_info.dom.level5_dom);
963 if (sid1.num_auths == 0)
968 fstrcpy(srv_name, "\\\\");
969 fstrcat(srv_name, cli_info.dest_host);
976 /* Iterate all users */
977 if (msrpc_sam_enum_users(srv_name, domain, &sid1,
979 NULL, NULL, NULL, NULL) == 0)
987 for (; i < num_usrs; i++)
989 char *usr_name = sam[i].acct_name;
990 if (text == NULL || text[0] == 0 ||
991 strnequal(text, usr_name, strlen(text)))
993 char *name = strdup(usr_name);
1002 static char *complete_samenum_als(char *text, int state)
1004 static uint32 i = 0;
1005 static uint32 num_als = 0;
1006 static struct acct_info *sam = NULL;
1014 sid_copy(&sid1, &cli_info.dom.level5_sid);
1015 sid_to_string(sid, &sid1);
1016 fstrcpy(domain, cli_info.dom.level5_dom);
1018 if (sid1.num_auths == 0)
1023 fstrcpy(srv_name, "\\\\");
1024 fstrcat(srv_name, cli_info.dest_host);
1031 /* Iterate all aliases */
1032 if (msrpc_sam_enum_aliases(srv_name, domain, &sid1,
1034 NULL, NULL, NULL) == 0)
1042 for (; i < num_als; i++)
1044 char *als_name = sam[i].acct_name;
1045 if (text == NULL || text[0] == 0 ||
1046 strnequal(text, als_name, strlen(text)))
1048 char *name = strdup(als_name);
1057 static char *complete_samenum_grp(char *text, int state)
1059 static uint32 i = 0;
1060 static uint32 num_grps = 0;
1061 static struct acct_info *sam = NULL;
1069 sid_copy(&sid1, &cli_info.dom.level5_sid);
1070 sid_to_string(sid, &sid1);
1071 fstrcpy(domain, cli_info.dom.level5_dom);
1073 if (sid1.num_auths == 0)
1078 fstrcpy(srv_name, "\\\\");
1079 fstrcat(srv_name, cli_info.dest_host);
1086 /* Iterate all groups */
1087 if (msrpc_sam_enum_groups(srv_name,
1090 NULL, NULL, NULL) == 0)
1098 for (; i < num_grps; i++)
1100 char *grp_name = sam[i].acct_name;
1101 if (text == NULL || text[0] == 0 ||
1102 strnequal(text, grp_name, strlen(text)))
1104 char *name = strdup(grp_name);
1113 static char *complete_svcenum(char *text, int state)
1115 static uint32 i = 0;
1116 static uint32 num_svcs = 0;
1117 static ENUM_SRVC_STATUS *svc = NULL;
1120 fstrcpy(srv_name, "\\\\");
1121 fstrcat(srv_name, cli_info.dest_host);
1131 /* Iterate all users */
1132 if (msrpc_svc_enum(srv_name, &svc, &num_svcs,
1141 for (; i < num_svcs; i++)
1144 unistr_to_ascii(svc_name, svc[i].uni_srvc_name.buffer,
1145 sizeof(svc_name)-1);
1147 if (text == NULL || text[0] == 0 ||
1148 strnequal(text, svc_name, strlen(text)))
1150 char *name = strdup(svc_name);
1159 static char *complete_printersenum(char *text, int state)
1161 static uint32 i = 0;
1162 static uint32 num = 0;
1163 static PRINTER_INFO_1 **ctr = NULL;
1168 fstrcpy(srv_name, "\\\\");
1169 fstrcat(srv_name, cli_info.dest_host);
1172 free_print1_array(num, ctr);
1176 /* Iterate all users */
1177 if (!msrpc_spoolss_enum_printers(srv_name,
1178 1, &num, (void***)&ctr,
1187 for (; i < num; i++)
1190 unistr_to_ascii(name, ctr[i]->name.buffer,
1193 if (text == NULL || text[0] == 0 ||
1194 strnequal(text, name, strlen(text)))
1196 char *copy = strdup(name);
1205 /* Complete an rpcclient command */
1207 static char *complete_cmd(char *text, int state)
1209 static int cmd_index;
1218 /* Return the next name which partially matches the list of commands */
1220 while (strlen(name = commands[cmd_index++].name) > 0) {
1221 if (strncmp(name, text, strlen(text)) == 0) {
1222 return strdup(name);
1229 /* Main completion function */
1231 static char **completion_fn(char *text, int start, int end)
1233 pstring cmd_partial;
1240 (void)get_cmd_args(rl_line_buffer);
1242 safe_strcpy(cmd_partial, rl_line_buffer,
1243 MAX(sizeof(cmd_partial),end)-1);
1245 /* Complete rpcclient command */
1249 return completion_matches(text, complete_cmd);
1252 /* Count # of words in command */
1255 for (i = 0; i <= end; i++) {
1256 if ((rl_line_buffer[i] != ' ') && (lastch == ' '))
1260 lastch = rl_line_buffer[i];
1263 if (rl_line_buffer[end] == ' ')
1266 /* Work out which command we are completing for */
1268 for (cmd_index = 0; strcmp(commands[cmd_index].name, "") != 0;
1271 /* Check each command in array */
1273 if (strncmp(rl_line_buffer, commands[cmd_index].name,
1274 strlen(commands[cmd_index].name)) == 0) {
1276 /* Call appropriate completion function */
1278 if (num_words == 2 || num_words == 3)
1280 switch (commands[cmd_index].compl_args[num_words - 2])
1284 return completion_matches(text, complete_samenum_grp);
1287 return completion_matches(text, complete_samenum_als);
1290 return completion_matches(text, complete_samenum_usr);
1293 return completion_matches(text, complete_svcenum);
1296 return completion_matches(text, complete_printersenum);
1299 return completion_matches(text, complete_regenum);
1302 /* An invalid completion type */
1314 /* To avoid filename completion being activated when no valid
1315 completions are found, we assign this stub completion function
1316 to the rl_completion_entry_function variable. */
1318 static char *complete_cmd_null(char *text, int state)
1323 #endif /* HAVE_LIBREADLINE */
1325 static void set_user_password(struct ntuser_creds *u,
1326 BOOL got_pass, char *password)
1328 /* set the password cache info */
1331 if (password == NULL)
1333 pwd_set_nullpwd(&(u->pwd));
1337 /* generate 16 byte hashes */
1338 pwd_make_lm_nt_16(&(u->pwd), password);
1343 pwd_read(&(u->pwd), "Enter Password:", True);
1347 static void cmd_net(struct client_info *info, int argc, char *argv[])
1350 BOOL net_use = False;
1351 BOOL net_use_add = True;
1352 BOOL force_close = False;
1353 struct ntuser_creds u;
1356 BOOL null_pwd = False;
1357 BOOL got_pwd = False;
1359 extern struct ntuser_creds *usr_creds;
1361 copy_nt_creds(&u, usr_creds);
1363 pstrcpy(dest_host, cli_info.dest_host);
1364 pstrcpy(u.user_name,optarg);
1365 info->reuse = False;
1369 report(out_hnd, "net -S \\server [-U user%%pass] [-W domain] [-d] [-f]\n");
1370 report(out_hnd, "net -u\n");
1373 while ((opt = getopt(argc, argv, "udS:U:W:")) != EOF)
1385 pstrcpy(dest_host, optarg);
1392 pstrcpy(u.user_name,optarg);
1393 if ((lp=strchr(u.user_name,'%')))
1396 pstrcpy(password,lp+1);
1397 memset(strchr(optarg,'%')+1,'X',
1401 if (u.user_name[0] == 0 && password[0] == 0)
1414 pstrcpy(u.domain,optarg);
1420 net_use_add = False;
1432 report(out_hnd, "net -S \\server [-U user%%pass] [-W domain] [-d] [-f]\n");
1433 report(out_hnd, "net -u\n");
1439 if (strnequal("\\\\", dest_host, 2))
1441 fstrcpy(srv_name, dest_host);
1445 fstrcpy(srv_name, "\\\\");
1446 fstrcat(srv_name, dest_host);
1454 struct use_info **use;
1455 cli_net_use_enum(&num_uses, &use);
1459 report(out_hnd, "No connections\n");
1463 report(out_hnd, "Connections:\n");
1465 for (i = 0; i < num_uses; i++)
1467 if (use[i] != NULL && use[i]->connected)
1469 report(out_hnd, "Server:\t%s\t",
1471 report(out_hnd, "User:\t%s\t",
1473 report(out_hnd, "Domain:\t%s\n",
1479 else if (net_use_add)
1483 set_user_password(&u, True, NULL);
1487 set_user_password(&u, got_pwd, password);
1490 /* paranoia: destroy the local copy of the password */
1491 bzero(password, sizeof(password));
1493 report(out_hnd, "Server:\t%s:\tUser:\t%s\tDomain:\t%s\n",
1494 srv_name, u.user_name, u.domain);
1495 report(out_hnd, "Connection:\t");
1497 if (cli_net_use_add(srv_name, &u, True, info->reuse) != NULL)
1499 report(out_hnd, "OK\n");
1503 report(out_hnd, "FAILED\n");
1509 report(out_hnd, "Server:\t%s:\tUser:\t%s\tDomain:\t%s\n",
1510 srv_name, u.user_name, u.domain);
1511 report(out_hnd, "Connection:\t");
1513 if (!cli_net_use_del(srv_name, &u, force_close, &closed))
1515 report(out_hnd, ": Does not exist\n");
1517 else if (force_close && closed)
1519 report(out_hnd, ": Forcibly terminated\n");
1523 report(out_hnd, ": Terminated\n");
1527 report(out_hnd, ": Unlinked\n");
1531 /* paranoia: destroy the local copy of the password */
1532 bzero(password, sizeof(password));
1538 #define CMD_TERM 0x8
1539 #define CMD_PASS 0x10
1540 #define CMD_USER 0x20
1541 #define CMD_NOPW 0x40
1542 #define CMD_DBLV 0x80
1543 #define CMD_HELP 0x100
1544 #define CMD_SOCK 0x200
1545 #define CMD_IFACE 0x400
1546 #define CMD_DOM 0x800
1547 #define CMD_IP 0x1000
1548 #define CMD_HOST 0x2000
1549 #define CMD_NAME 0x4000
1550 #define CMD_DBG 0x8000
1551 #define CMD_SCOPE 0x10000
1552 #define CMD_INTER 0x20000
1554 static void cmd_set(struct client_info *info, int argc, char *argv[])
1556 BOOL interactive = True;
1557 char *cmd_str = NULL;
1560 extern char *optarg;
1561 static pstring servicesf = CONFIGFILE;
1563 pstring password; /* local copy only, if one is entered */
1564 info->reuse = False;
1567 pstrcpy(term_code, KANJI);
1573 if (argc > 1 && *argv[1] != '-')
1575 if (argc > 1 && (*argv[1] != '-'))
1577 cmd_set_options |= CMD_PASS;
1578 pstrcpy(password,argv[1]);
1579 memset(argv[1],'X',strlen(argv[1]));
1585 while ((opt = getopt(argc, argv, "Rs:B:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
1597 /* FIXME ... max_protocol seems to be funny here */
1599 int max_protocol = 0;
1600 max_protocol = interpret_protocol(optarg,max_protocol);
1601 fprintf(stderr, "max protocol not currently supported\n");
1607 cmd_set_options |= CMD_SOCK;
1608 pstrcpy(user_socket_options,optarg);
1614 cmd_set_options |= CMD_HOST;
1615 pstrcpy(cli_info.dest_host,optarg);
1616 strupper(cli_info.dest_host);
1622 cmd_set_options |= CMD_IFACE;
1623 iface_set_default(NULL,optarg,NULL);
1629 cmd_set_options |= CMD_SCOPE;
1630 pstrcpy(scope, optarg);
1637 cmd_set_options |= CMD_USER;
1638 pstrcpy(usr.user_name,optarg);
1639 if ((lp=strchr(usr.user_name,'%')))
1642 pstrcpy(password,lp+1);
1643 cmd_set_options |= CMD_PASS;
1644 memset(strchr(optarg,'%')+1,'X',strlen(password));
1646 if (usr.user_name[0] == 0 && password[0] == 0)
1648 cmd_set_options |= CMD_NOPW;
1655 cmd_set_options |= CMD_DOM;
1656 pstrcpy(usr.domain,optarg);
1662 cmd_set_options |= CMD_DBG;
1669 cmd_set_options |= CMD_IP;
1670 cli_info.dest_ip = *interpret_addr2(optarg);
1671 if (zero_ip(cli_info.dest_ip))
1681 cmd_set_options |= CMD_NAME;
1682 fstrcpy(global_myname, optarg);
1688 cmd_set_options |= CMD_NOPW | CMD_PASS;
1694 cmd_set_options |= CMD_DBLV;
1698 DEBUGLEVEL = atoi(optarg);
1704 cmd_set_options |= CMD_INTER;
1705 slprintf(debugf, sizeof(debugf)-1,
1706 "%s.client", optarg);
1707 interactive = False;
1713 cmd_set_options |= CMD_STR | CMD_PASS;
1720 cmd_set_options |= CMD_HELP;
1727 cmd_set_options |= CMD_SVC;
1728 pstrcpy(servicesf, optarg);
1734 cmd_set_options |= CMD_TERM;
1735 pstrcpy(term_code, optarg);
1741 cmd_set_options |= CMD_HELP;
1748 DEBUG(10,("cmd_set: options: %x\n", cmd_set_options));
1750 if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
1755 if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
1757 setup_logging(debugf, interactive);
1761 if (IS_BITS_SET_ALL(cmd_set_options, CMD_NOPW))
1763 set_user_password(&usr, True, NULL);
1765 else if (IS_BITS_SET_ALL(cmd_set_options, CMD_PASS))
1767 set_user_password(&usr, True, password);
1770 /* paranoia: destroy the local copy of the password */
1771 bzero(password, sizeof(password));
1773 strupper(global_myname);
1774 fstrcpy(cli_info.myhostname, global_myname);
1776 if (IS_BITS_SET_ALL(cmd_set_options, CMD_SVC))
1778 if (!lp_load(servicesf,True, False, False))
1780 fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
1785 if (IS_BITS_SET_ALL(cmd_set_options, CMD_INTER))
1790 if (cmd_str != NULL)
1792 process(&cli_info, cmd_str);
1796 static void read_user_env(struct ntuser_creds *u)
1805 pstrcpy(u->user_name,getenv("USER"));
1807 /* modification to support userid%passwd syntax in the USER var
1808 25.Aug.97, jdblair@uab.edu */
1810 if ((p=strchr(u->user_name,'%')))
1813 pstrcpy(password,p+1);
1814 memset(strchr(getenv("USER"),'%')+1,'X',strlen(password));
1816 strupper(u->user_name);
1819 /* modification to support PASSWD environmental var
1820 25.Aug.97, jdblair@uab.edu */
1821 if (getenv("PASSWD"))
1823 pstrcpy(password,getenv("PASSWD"));
1826 if (*u->user_name == 0 && getenv("LOGNAME"))
1828 pstrcpy(u->user_name,getenv("LOGNAME"));
1829 strupper(u->user_name);
1832 set_user_password(u, True, password);
1834 /* paranoia: destroy the local copy of the password */
1835 bzero(password, sizeof(password));
1838 void readline_init(void)
1840 #ifdef HAVE_LIBREADLINE
1842 /* Initialise GNU Readline */
1844 rl_readline_name = "rpcclient";
1845 rl_attempted_completion_function = completion_fn;
1846 rl_completion_entry_function = (Function *)complete_cmd_null;
1848 /* Initialise history list */
1854 x = 0; /* stop compiler warnings */
1855 #endif /* HAVE_LIBREADLINE */
1858 /****************************************************************************
1860 ****************************************************************************/
1861 int main(int argc,char *argv[])
1863 extern struct ntuser_creds *usr_creds;
1864 mode_t myumask = 0755;
1868 usr.ntlmssp_flags = 0x0;
1872 fstrcpy(debugf, argv[0]);
1874 init_policy_hnd(64);
1876 pstrcpy(usr.domain, "");
1877 pstrcpy(usr.user_name, "");
1879 pstrcpy(cli_info.myhostname, "");
1880 pstrcpy(cli_info.dest_host, "");
1881 cli_info.dest_ip.s_addr = 0;
1883 ZERO_STRUCT(cli_info.dom.level3_sid);
1884 ZERO_STRUCT(cli_info.dom.level5_sid);
1885 fstrcpy(cli_info.dom.level3_dom, "");
1886 fstrcpy(cli_info.dom.level5_dom, "");
1890 charset_initialise();
1896 if (!get_myname(global_myname, NULL))
1898 fprintf(stderr, "Failed to get my hostname.\n");
1908 read_user_env(&usr);
1910 cmd_set_options &= ~CMD_HELP;
1911 cmd_set_options &= ~CMD_NOPW;
1913 cmd_set(&cli_info, argc, argv);
1915 if (IS_BITS_SET_ALL(cmd_set_options, CMD_HELP))
1921 codepage_initialise(lp_client_code_page());
1923 DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
1925 process(&cli_info, NULL);