2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1998-2000
7 Copyright (C) Gerald Carter 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include "rpc_parse.h"
35 extern pstring debugf;
36 extern pstring global_myname;
38 extern pstring user_socket_options;
40 /* found in rpc_client/cli_connect.c */
41 extern struct user_creds *usr_creds;
44 #define CNV_LANG(s) dos2unix_format(s,False)
45 #define CNV_INPUT(s) unix2dos_format(s,True)
47 static int process_tok(fstring tok);
48 static uint32 cmd_help(struct client_info *info, int argc, char *argv[]);
49 static uint32 cmd_quit(struct client_info *info, int argc, char *argv[]);
50 static uint32 cmd_set(struct client_info *info, int argc, char *argv[]);
51 static uint32 cmd_use(struct client_info *info, int argc, char *argv[]);
53 static struct user_creds usr;
55 struct client_info cli_info;
57 char **cmd_argv = NULL;
63 static void cmd_set_free(struct command_set *item)
66 SAFE_FREE(item->name);
71 static struct command_set *cmd_set_dup(const struct command_set *from)
75 struct command_set *copy;
77 copy = (struct command_set*)malloc(sizeof(struct command_set));
80 memcpy(copy, from, sizeof(struct command_set));
81 if (from->name != NULL)
82 copy->name = strdup(from->name);
89 void free_cmd_set_array(uint32 num_entries, struct command_set **entries)
91 void (*fn) (void *) = (void (*)(void *))&cmd_set_free;
92 free_void_array(num_entries, (void **)entries, *fn);
95 struct command_set *add_cmd_set_to_array(uint32 *len, struct command_set ***array,
96 const struct command_set *cmd)
98 void *(*fn) (const void *) = (void *(*)(const void *))&cmd_set_dup;
99 return (struct command_set *)add_copy_to_array(len, (void ***)array,
100 (const void *)cmd, *fn,
105 static struct command_set **commands = NULL;
106 static uint32 num_commands = 0;
108 /****************************************************************************
109 add in individual command-sets.
110 ****************************************************************************/
111 void add_command_set(const struct command_set *cmds)
113 while (! ((cmds->fn==NULL) && (strlen(cmds->name)==0)))
115 add_cmd_set_to_array(&num_commands, &commands, cmds);
120 /****************************************************************************
121 This defines the commands supported by this client
122 ****************************************************************************/
123 static struct command_set general_commands[] = {
128 {"General", NULL, NULL, {NULL, NULL}},
131 "run rpcclient inside rpcclient (change options etc.)",
136 "net use and net view",
166 "[command] give help on a command",
170 "[command] give help on a command",
179 "run a shell command on the local system",
193 /****************************************************************************
194 do a (presumably graceful) quit...
195 ****************************************************************************/
196 static uint32 cmd_quit(struct client_info *info, int argc, char *argv[])
205 /****************************************************************************
207 ****************************************************************************/
208 static uint32 cmd_help(struct client_info *info, int argc, char *argv[])
212 /* get help on a specific command */
215 if ((i = process_tok(argv[0])) >= 0)
217 fprintf(out_hnd, "HELP %s:\n\t%s\n\n", commands[i]->name,
218 commands[i]->description);
224 /* Print out the list of available commands */
225 for (i = 0; i < num_commands; i++)
227 if (commands[i]->fn == NULL)
228 fprintf (out_hnd, "\n");
230 fprintf (out_hnd, "\t");
232 fprintf(out_hnd, "%s\n", commands[i]->name);
238 /*******************************************************************
239 lookup a command string in the list of commands, including
241 ******************************************************************/
242 static int process_tok(char *tok)
244 int i = 0, matches = 0;
246 int tok_len = strlen(tok);
248 for (i = 0; i < num_commands; i++)
250 if (strequal(commands[i]->name, tok))
256 else if (strnequal(commands[i]->name, tok, tok_len))
265 else if (matches == 1)
271 /****************************************************************************
272 turn command line into command argument array
273 ****************************************************************************/
274 static BOOL get_cmd_args(char *line)
281 /* get the first part of the command */
282 if (!next_token_nr(&ptr, tok, NULL, sizeof(tok)))
287 add_chars_to_array(&cmd_argc, &cmd_argv, tok);
289 while (next_token_nr(NULL, tok, NULL, sizeof(tok)));
291 add_chars_to_array(&cmd_argc, &cmd_argv, NULL);
296 /* command options mask */
297 static uint32 cmd_set_options = 0xffffffff;
299 /****************************************************************************
300 process commands from the client
301 ****************************************************************************/
302 static uint32 do_command(struct client_info *info, char *line)
304 NTSTATUS status = 0x0;
307 if (!get_cmd_args(line))
313 i = process_tok(cmd_argv[0]);
316 int argc = ((int)cmd_argc);
317 char **argv = cmd_argv;
320 status = commands[i]->fn(info, argc, argv);
324 fprintf(out_hnd, "%s: command abbreviation ambiguous\n",
325 CNV_LANG(cmd_argv[0]));
329 fprintf(out_hnd, "%s: command not found\n",
330 CNV_LANG(cmd_argv[0]));
333 free_char_array(cmd_argc, cmd_argv);
334 parse_talloc_free(); /* Free up init_XXX memory. */
340 /****************************************************************************
341 process commands from the client
342 ****************************************************************************/
343 static uint32 process(struct client_info *info, char *cmd_str)
351 while (cmd[0] != '\0')
355 if ((p = strchr_m(cmd, ';')) == 0)
357 strncpy(line, cmd, 999);
365 strncpy(line, cmd, p - cmd);
366 line[p - cmd] = '\0';
370 /* input language code to internal one */
373 status = do_command(info, line);
384 #ifdef HAVE_LIBREADLINE
391 if (info->show_prompt)
393 safe_strcat(pline, "[", sizeof(pline) - 1);
394 if (usr.ntc.domain[0] != 0)
396 safe_strcat(pline, usr.ntc.domain,
398 safe_strcat(pline, "\\", sizeof(pline) - 1);
401 if (usr.ntc.user_name[0] != 0)
403 safe_strcat(pline, usr.ntc.user_name,
408 safe_strcat(pline, "@", sizeof(pline) - 1);
410 safe_strcat(pline, cli_info.dest_host,
412 safe_strcat(pline, "]$ ", sizeof(pline) - 1);
414 #ifndef HAVE_LIBREADLINE
416 /* display a prompt */
417 fprintf(out_hnd, "%s", CNV_LANG(pline));
420 cli_use_wait_keyboard();
422 /* and get a response */
423 if (!fgets(line, 1000, stdin))
428 #else /* HAVE_LIBREADLINE */
430 if (!(ret_line = readline(pline)))
434 /* Copy read line to samba buffer */
436 pstrcpy(line, rl_line_buffer);
440 if (strlen(line) > 0)
443 /* input language code to internal one */
446 /* special case - first char is ! */
453 fprintf(out_hnd, "%s\n", line);
455 status = do_command(info, line);
465 /****************************************************************************
467 ****************************************************************************/
468 static void usage(char *pname)
471 "Usage: %s [\\server] [password] [-U user] -[W domain] [-l log] ",
474 fprintf(out_hnd, "\nVersion %s\n", VERSION);
475 fprintf(out_hnd, "\t-d debuglevel set the debuglevel\n");
477 "\t-S <\\>server Server to connect to\n");
479 "\t-l log basename. Basename for log/debug files\n");
481 "\t-n netbios name. Use this name as my netbios name\n");
483 "\t-N don't ask for a password\n");
485 "\t-m max protocol set the max protocol level\n");
487 "\t-I dest IP use this IP to connect to\n");
489 "\t-E write messages to stderr instead of stdout\n");
491 "\t-A filename file from which to read the authentication credentials\n");
493 "\t-P hide prompt (used for shell scripts)\n");
495 "\t-U username set the network username\n");
497 "\t-U username%%pass set the network username and password\n");
498 fprintf(out_hnd, "\t-W domain set the domain name\n");
500 "\t-c 'command string' execute semicolon separated commands\n");
502 "\t-t terminal code terminal i/o code {sjis|euc|jis7|jis8|junet|hex}\n");
503 fprintf(out_hnd, "\n");
506 #ifdef HAVE_LIBREADLINE
508 /****************************************************************************
509 GNU readline completion functions
510 ****************************************************************************/
512 /* Complete an rpcclient command */
514 static char *complete_cmd(char *text, int state)
516 static int cmd_index;
524 /* Return the next name which partially matches the list of commands */
526 while ((cmd_index < num_commands)
527 && (strlen(name = commands[cmd_index++]->name) > 0))
529 if (strncmp(name, text, strlen(text)) == 0)
536 /* Main completion function */
538 static char **completion_fn(char *text, int start, int end)
547 (void)get_cmd_args(rl_line_buffer);
549 safe_strcpy(cmd_partial, rl_line_buffer,
550 MAX(sizeof(cmd_partial), end) - 1);
552 /* Complete rpcclient command */
555 return completion_matches(text, complete_cmd);
557 /* Count # of words in command */
560 for (i = 0; i <= end; i++)
562 if ((rl_line_buffer[i] != ' ') && (lastch == ' '))
564 lastch = rl_line_buffer[i];
567 if (rl_line_buffer[end] == ' ')
570 /* Work out which command we are completing for */
572 for (cmd_index = 0; cmd_index < num_commands; cmd_index++)
575 /* Check each command in array */
577 if (strncmp(rl_line_buffer, commands[cmd_index]->name,
578 strlen(commands[cmd_index]->name)) == 0)
580 /* Call appropriate completion function */
582 if (num_words == 2 || num_words == 3)
584 char *(*fn) (char *, int);
585 fn = commands[cmd_index]->compl_args[num_words - 2];
587 return completion_matches(text, fn);
596 /* To avoid filename completion being activated when no valid
597 completions are found, we assign this stub completion function
598 to the rl_completion_entry_function variable. */
600 static char *complete_cmd_null(char *text, int state)
605 #endif /* HAVE_LIBREADLINE */
607 static void set_user_password(struct ntuser_creds *u,
608 BOOL got_pass, char *password)
610 /* set the password cache info */
613 if (password == NULL)
615 DEBUG(10, ("set_user_password: NULL pwd\n"));
616 pwd_set_nullpwd(&u->pwd);
620 /* generate 16 byte hashes */
621 DEBUG(10, ("set_user_password: generate\n"));
622 if (lp_encrypted_passwords())
623 pwd_make_lm_nt_16(&u->pwd, password);
625 pwd_set_cleartext(&u->pwd, password);
630 DEBUG(10, ("set_user_password: read\n"));
631 pwd_read(&u->pwd, "Enter Password:", True);
635 static uint32 cmd_use(struct client_info *info, int argc, char *argv[])
638 BOOL net_use = False;
639 BOOL net_use_add = True;
640 BOOL force_close = False;
643 BOOL null_pwd = False;
644 BOOL got_pwd = False;
648 if (usr_creds != NULL)
649 copy_nt_creds(&usr.ntc, &usr_creds->ntc);
651 copy_nt_creds(&usr.ntc, NULL);
653 pstrcpy(dest_host, cli_info.dest_host);
654 pstrcpy(usr.ntc.user_name, optarg);
660 "net [\\\\Server] [-U user%%pass] [-W domain] [-d] [-f]\n");
661 report(out_hnd, " -d Deletes a connection\n");
662 report(out_hnd, " -f Forcibly deletes a connection\n");
663 report(out_hnd, "net -u Shows all connections\n");
667 if (argc > 1 && (*argv[1] != '-'))
669 if (strnequal("\\\\", argv[1], 2) ||
670 strnequal("//", argv[1], 2))
672 pstrcpy(dest_host, argv[1] + 2);
678 while ((opt = getopt(argc, argv, "udU:W:")) != EOF)
691 pstrcpy(usr.ntc.user_name, optarg);
692 if ((lp = strchr_m(usr.ntc.user_name, '%')))
695 pstrcpy(password, lp + 1);
696 memset(strchr_m(optarg, '%') + 1, 'X',
700 if (usr.ntc.user_name[0] == 0
714 pstrcpy(usr.ntc.domain, optarg);
733 "net -S \\server [-U user%%pass] [-W domain] [-d] [-f]\n");
734 report(out_hnd, "net -u\n");
740 if (strnequal("\\\\", dest_host, 2))
742 fstrcpy(srv_name, dest_host);
746 fstrcpy(srv_name, "\\\\");
747 fstrcat(srv_name, dest_host);
755 struct use_info **use;
756 cli_net_use_enum(&num_uses, &use);
760 report(out_hnd, "No connections\n");
764 report(out_hnd, "Connections:\n");
766 for (i = 0; i < num_uses; i++)
768 if (use[i] != NULL && use[i]->connected)
770 report(out_hnd, "Server:\t%s\t",use[i]->srv_name);
771 report(out_hnd, "Key:\t[%d,%x]\t",use[i]->key.pid, use[i]->key.vuid);
772 report(out_hnd, "User:\t%s\t", use[i]->user_name);
773 report(out_hnd, "Domain:\t%s\n", use[i]->domain);
778 else if (net_use_add)
782 set_user_password(&usr.ntc, True, NULL);
784 set_user_password(&usr.ntc, got_pwd, password);
786 /* paranoia: destroy the local copy of the password */
787 ZERO_STRUCT(password);
789 report(out_hnd, "Server:\t%s:\tUser:\t%s\tDomain:\t%s\n",
790 srv_name, usr.ntc.user_name, usr.ntc.domain);
791 report(out_hnd, "Connection:\t");
793 if (cli_net_use_add(srv_name, &usr.ntc, info->reuse, &isnew) != NULL)
794 report(out_hnd, "OK\n");
796 report(out_hnd, "FAILED\n");
801 report(out_hnd, "Server:\t%s:\tUser:\t%s\tDomain:\t%s\n",
802 srv_name, usr.ntc.user_name, usr.ntc.domain);
803 report(out_hnd, "Connection:\t");
805 if (!cli_net_use_del(srv_name, &usr.ntc, force_close, &closed))
806 report(out_hnd, ": Does not exist\n");
807 else if (force_close && closed)
808 report(out_hnd, ": Forcibly terminated\n");
810 report(out_hnd, ": Terminated\n");
812 report(out_hnd, ": Unlinked\n");
815 /* paranoia: destroy the local copy of the password */
816 ZERO_STRUCT(password);
821 /******************************************************************
822 allow or disallow automatic connections. rpctorture, because it
823 does not reestablish connections after sys_fork(), fails unless the
824 connection is established AFTER the sys_fork()
825 ******************************************************************/
826 static BOOL auto_connect = True;
827 void cmd_set_no_autoconnect(void)
829 auto_connect = False;
836 #define CMD_PASS 0x10
837 #define CMD_USER 0x20
838 #define CMD_NOPW 0x40
839 #define CMD_DBLV 0x80
840 #define CMD_HELP 0x100
841 #define CMD_SOCK 0x200
842 #define CMD_IFACE 0x400
843 #define CMD_DOM 0x800
844 #define CMD_IP 0x1000
845 #define CMD_HOST 0x2000
846 #define CMD_NAME 0x4000
847 #define CMD_DBG 0x8000
848 #define CMD_SCOPE 0x10000
849 #define CMD_INTER 0x20000
851 static void read_authfile (char *filename, char* username, char* password)
856 char *ptr, *val, *param;
858 if ((auth=sys_fopen(filename, "r")) == NULL)
860 /* fail if we can't open the credentials file */
861 DEBUG(0,("ERROR: Unable to open credentials file!\n"));
867 /* get a line from the file */
868 if (!fgets (buf, sizeof(buf), auth))
873 /* skip empty lines */
874 if ((len) && (buf[len-1]=='\n'))
882 /* break up the line into parameter & value.
883 will need to eat a little whitespace possibly */
885 if (!(ptr = strchr_m(buf, '=')))
890 /* eat leading white space */
891 while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
894 if (strwicmp("password", param) == 0)
896 pstrcpy(password, val);
897 cmd_set_options |= CMD_PASS;
899 else if (strwicmp("username", param) == 0)
901 pstrcpy(username, val);
902 cmd_set_options |= CMD_USER;
905 memset(buf, 0, sizeof(buf));
912 static uint32 cmd_set(CLIENT_INFO *info, int argc, char *argv[])
914 BOOL interactive = True;
915 char *cmd_str = NULL;
918 static pstring servicesf = CONFIGFILE;
920 pstring password; /* local copy only, if one is entered */
922 int new_debuglevel = -1;
928 pstrcpy(term_code, KANJI);
933 if (argc > 1 && (*argv[1] != '-'))
935 if (strnequal("\\\\", argv[1], 2) ||
936 strnequal("//", argv[1], 2))
938 cmd_set_options |= CMD_HOST;
939 pstrcpy(cli_info.dest_host, argv[1] + 2);
940 strupper(cli_info.dest_host);
946 if (argc > 1 && (*argv[1] != '-'))
948 cmd_set_options |= CMD_PASS;
949 pstrcpy(password, argv[1]);
950 memset(argv[1], 'X', strlen(argv[1]));
955 while ((opt = getopt(argc, argv,"PRs:O:M:S:i:Nn:d:l:hI:EB:U:L:t:m:W:T:D:c:A:")) != EOF)
959 /* reuse connections in the case of a previous authentication */
969 /* FIXME ... max_protocol seems to be funny here */
971 int max_protocol = 0;
972 max_protocol = interpret_protocol(optarg, max_protocol);
973 fprintf(stderr, "max protocol not currently supported\n");
980 cmd_set_options |= CMD_SOCK;
981 pstrcpy(user_socket_options, optarg);
985 /* define the server to connect to */
988 cmd_set_options |= CMD_HOST;
989 pstrcpy(cli_info.dest_host, optarg);
990 strupper(cli_info.dest_host);
994 /* username for the connection -- support the
995 username%password format as well */
999 cmd_set_options |= CMD_USER;
1000 pstrcpy(usr.ntc.user_name, optarg);
1001 if ((lp = strchr_m(usr.ntc.user_name, '%')))
1004 pstrcpy(password, lp + 1);
1005 cmd_set_options |= CMD_PASS;
1006 memset(lp+1, 'X', strlen(password));
1011 /* authfile -- only get the username and password from the file */
1014 read_authfile (optarg, usr.ntc.user_name, password);
1018 /* define the workgroup/domain name */
1021 cmd_set_options |= CMD_DOM;
1022 pstrcpy(usr.ntc.domain, optarg);
1026 /* should we display a command prompt at all */
1028 { /* optarg == prompt string ? */
1029 info->show_prompt = False;
1033 /* send to stderr instaed of stdout */
1036 cmd_set_options |= CMD_DBG;
1041 /* IP address of destination host */
1044 cmd_set_options |= CMD_IP;
1045 cli_info.dest_ip = *interpret_addr2(optarg);
1046 if (zero_ip(cli_info.dest_ip))
1054 /* define netbios name of client machine we are on */
1057 cmd_set_options |= CMD_NAME;
1058 fstrcpy(global_myname, optarg);
1062 /* do not prompt for a password. Implies anonymous connection
1063 unless the password was passed in username%password form */
1066 cmd_set_options |= CMD_NOPW | CMD_PASS;
1073 cmd_set_options |= CMD_DBLV;
1075 new_debuglevel = 10000;
1077 new_debuglevel = atoi(optarg);
1084 cmd_set_options |= CMD_INTER;
1085 slprintf(debugf, sizeof(debugf) - 1, "%s.client", optarg);
1086 interactive = False;
1090 /* command string to be executed */
1093 cmd_set_options |= CMD_STR;
1098 /* program usage/help screen */
1101 cmd_set_options |= CMD_HELP;
1106 /* config file to use */
1109 cmd_set_options |= CMD_SVC;
1110 pstrcpy(servicesf, optarg);
1117 cmd_set_options |= CMD_TERM;
1118 pstrcpy(term_code, optarg);
1124 cmd_set_options |= CMD_HELP;
1132 if (cmd_set_options & CMD_INTER)
1134 setup_logging(debugf, interactive);
1139 strupper(global_myname);
1140 fstrcpy(cli_info.myhostname, global_myname);
1142 if (cmd_set_options & CMD_SVC)
1144 if (!lp_load(servicesf, True, False, False))
1146 fprintf(stderr, "Can't load %s - run testparm to debug it\n",
1152 if (new_debuglevel != -1) {
1153 DEBUGLEVEL = new_debuglevel;
1156 if (cmd_set_options & CMD_INTER)
1161 DEBUG(10, ("cmd_set: options: %x\n", cmd_set_options));
1163 if (cmd_set_options & CMD_HELP) {
1167 /* NULL password if specified or is username is empty */
1168 if ((cmd_set_options & CMD_NOPW) || (strlen(usr.ntc.user_name) == 0))
1169 set_user_password(&usr.ntc, True, NULL);
1171 set_user_password(&usr.ntc, ((cmd_set_options & CMD_PASS) != 0), password);
1173 /* paranoia: destroy the local copy of the password */
1174 ZERO_STRUCT(password);
1176 if (strcmp(cli_info.dest_host, "*") == 0)
1178 /* special case - we want the PDC */
1180 if (!resolve_srv_name(cli_info.dest_host, cli_info.dest_host, &ip)) {
1181 report(out_hnd, "ERROR: Failed to find the PDC\n");
1186 fstrcpy(srv_name, "\\\\");
1187 fstrcat(srv_name, cli_info.dest_host);
1194 report(out_hnd, "Server:\t%s:\tUser:\t%s\tDomain:\t%s\n",
1195 srv_name, usr.ntc.user_name, usr.ntc.domain);
1196 report(out_hnd, "Connection:\t");
1198 if (cli_net_use_add(srv_name, &usr.ntc, info->reuse, &isnew) != NULL)
1200 report(out_hnd, "OK\n");
1204 report(out_hnd, "FAILED\n");
1207 usr_creds = NULL; */
1210 if (cmd_str != NULL)
1211 return process(&cli_info, cmd_str);
1216 static void read_user_env(struct ntuser_creds *u)
1225 pstrcpy(u->user_name, getenv("USER"));
1227 /* modification to support userid%passwd syntax in the USER var
1228 25.Aug.97, jdblair@uab.edu */
1230 if ((p = strchr_m(u->user_name, '%')))
1233 pstrcpy(password, p + 1);
1234 memset(strchr_m(getenv("USER"), '%') + 1, 'X',
1239 /* modification to support PASSWD environmental var
1240 25.Aug.97, jdblair@uab.edu */
1241 if (getenv("PASSWD"))
1242 pstrcpy(password, getenv("PASSWD"));
1244 if (*u->user_name == 0 && getenv("LOGNAME"))
1245 pstrcpy(u->user_name, getenv("LOGNAME"));
1247 set_user_password(u, True, password);
1249 /* paranoia: destroy the local copy of the password */
1250 ZERO_STRUCT(password);
1253 static void readline_init(void)
1255 #ifdef HAVE_LIBREADLINE
1256 /* Initialise GNU Readline */ rl_readline_name = "rpcclient";
1257 rl_attempted_completion_function = completion_fn;
1258 rl_completion_entry_function = (Function *) complete_cmd_null;
1260 /* Initialise history list */
1266 x = 0; /* stop compiler warnings */
1267 #endif /* HAVE_LIBREADLINE */
1270 /****************************************************************************
1272 ****************************************************************************/
1273 int command_main(int argc, char *argv[])
1276 mode_t myumask = 0755;
1277 char progname[255], path[255], *s;
1282 /* add in the internal command set and the various
1283 client RPC groups--spoolss, lsa, etc... */
1284 add_command_set(general_commands);
1286 /* usr_creds is a global most recently used set of user credentials
1287 retrieved from the connection list. */
1288 copy_user_creds(&usr, NULL);
1294 /* retrieve the binary name used when invoking the program
1295 for instances like samedit, etc... */
1296 strncpy(path, argv[0], 255);
1297 for (s = strtok(path, "/"); s; s = strtok(NULL, "/"))
1298 fstrcpy(progname, s);
1300 slprintf(debugf, sizeof(debugf) - 1,
1301 "%s/log.%s", LOGFILEBASE, progname);
1303 /* initialize usr */
1304 pstrcpy(usr.ntc.domain, "");
1305 pstrcpy(usr.ntc.user_name, "");
1306 pstrcpy(cli_info.myhostname, "");
1307 pstrcpy(cli_info.dest_host, "");
1309 /* init client_info struct */
1310 cli_info.dest_ip.s_addr = 0;
1311 cli_info.show_prompt = True;
1312 ZERO_STRUCT(cli_info.dom.level3_sid);
1313 ZERO_STRUCT(cli_info.dom.level5_sid);
1314 fstrcpy(cli_info.dom.level3_dom, "");
1315 fstrcpy(cli_info.dom.level5_dom, "");
1324 if (!get_myname(global_myname))
1326 fprintf(stderr, "Failed to get my hostname.\n");
1336 read_user_env(&usr.ntc);
1338 cmd_set_options &= ~CMD_HELP;
1339 cmd_set_options &= ~CMD_STR;
1340 cmd_set_options &= ~CMD_NOPW;
1341 cmd_set_options &= ~CMD_USER;
1342 cmd_set_options &= ~CMD_PASS;
1344 /* parse the command line args
1345 init the first connection if possible
1346 process a command if passed in on the command line */
1347 status = cmd_set(&cli_info, argc, argv);
1349 /* Should we exit? Are we done? */
1350 if (cmd_set_options & (CMD_HELP|CMD_STR)) {
1352 get_nt_error_msg(status, msg, sizeof(msg));
1354 report(out_hnd, "Exit Status: %s\n", msg);
1355 /* unix only has 8 bit error codes - blergh */
1356 exit(status & 0xFF);
1359 DEBUG(3, ("%s client started (version %s)\n",
1360 timestring(False), VERSION));
1362 /* enter shell mode */
1363 status = process(&cli_info, NULL);
1367 free_cmd_set_array(num_commands, commands);
1371 /* report and exit */
1372 get_nt_error_msg(status, msg, sizeof(msg));
1373 report(out_hnd, "Exit Status: %s\n", msg);