2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000-2001
6 Copyright (C) Martin Pool 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "rpcclient.h"
24 #include "../libcli/auth/libcli_auth.h"
25 #include "../librpc/gen_ndr/cli_lsa.h"
29 static enum pipe_auth_type pipe_default_auth_type = PIPE_AUTH_TYPE_NONE;
30 static enum dcerpc_AuthLevel pipe_default_auth_level = DCERPC_AUTH_LEVEL_NONE;
31 static unsigned int timeout = 0;
32 static enum dcerpc_transport_t default_transport = NCACN_NP;
34 struct user_auth_info *rpcclient_auth_info;
36 /* List to hold groups of commands.
38 * Commands are defined in a list of arrays: arrays are easy to
39 * statically declare, and lists are easier to dynamically extend.
42 static struct cmd_list {
43 struct cmd_list *prev, *next;
44 struct cmd_set *cmd_set;
47 /****************************************************************************
48 handle completion of commands for readline
49 ****************************************************************************/
50 static char **completion_fn(const char *text, int start, int end)
52 #define MAX_COMPLETIONS 100
55 struct cmd_list *commands = cmd_list;
58 /* FIXME!!! -- what to do when completing argument? */
59 /* for words not at the start of the line fallback
60 to filename completion */
65 /* make sure we have a list of valid commands */
70 matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
75 matches[count++] = SMB_STRDUP(text);
81 while (commands && count < MAX_COMPLETIONS-1) {
82 if (!commands->cmd_set) {
86 for (i=0; commands->cmd_set[i].name; i++) {
87 if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
88 (( commands->cmd_set[i].returntype == RPC_RTYPE_NTSTATUS &&
89 commands->cmd_set[i].ntfn ) ||
90 ( commands->cmd_set[i].returntype == RPC_RTYPE_WERROR &&
91 commands->cmd_set[i].wfn))) {
92 matches[count] = SMB_STRDUP(commands->cmd_set[i].name);
93 if (!matches[count]) {
94 for (i = 0; i < count; i++) {
95 SAFE_FREE(matches[count]);
103 commands = commands->next;
108 SAFE_FREE(matches[0]);
109 matches[0] = SMB_STRDUP(matches[1]);
111 matches[count] = NULL;
115 static char *next_command (char **cmdstr)
120 if (!cmdstr || !(*cmdstr))
123 p = strchr_m(*cmdstr, ';');
126 command = SMB_STRDUP(*cmdstr);
135 /* Fetch the SID for this computer */
137 static void fetch_machine_sid(struct cli_state *cli)
139 struct policy_handle pol;
140 NTSTATUS result = NT_STATUS_OK;
141 static bool got_domain_sid;
143 struct rpc_pipe_client *lsapipe = NULL;
144 union lsa_PolicyInformation *info = NULL;
146 if (got_domain_sid) return;
148 if (!(mem_ctx=talloc_init("fetch_machine_sid"))) {
149 DEBUG(0,("fetch_machine_sid: talloc_init returned NULL!\n"));
153 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
155 if (!NT_STATUS_IS_OK(result)) {
156 fprintf(stderr, "could not initialise lsa pipe. Error was %s\n", nt_errstr(result) );
160 result = rpccli_lsa_open_policy(lsapipe, mem_ctx, True,
161 SEC_FLAG_MAXIMUM_ALLOWED,
163 if (!NT_STATUS_IS_OK(result)) {
167 result = rpccli_lsa_QueryInfoPolicy(lsapipe, mem_ctx,
169 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
171 if (!NT_STATUS_IS_OK(result)) {
175 got_domain_sid = True;
176 sid_copy(&domain_sid, info->account_domain.sid);
178 rpccli_lsa_Close(lsapipe, mem_ctx, &pol);
179 TALLOC_FREE(lsapipe);
180 talloc_destroy(mem_ctx);
187 TALLOC_FREE(lsapipe);
190 fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
192 if (!NT_STATUS_IS_OK(result)) {
193 fprintf(stderr, "error: %s\n", nt_errstr(result));
199 /* List the available commands on a given pipe */
201 static NTSTATUS cmd_listcommands(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
202 int argc, const char **argv)
204 struct cmd_list *tmp;
205 struct cmd_set *tmp_set;
211 printf("Usage: %s <pipe>\n", argv[0]);
215 /* Help on one command */
217 for (tmp = cmd_list; tmp; tmp = tmp->next)
219 tmp_set = tmp->cmd_set;
221 if (!StrCaseCmp(argv[1], tmp_set->name))
223 printf("Available commands on the %s pipe:\n\n", tmp_set->name);
227 while(tmp_set->name) {
228 printf("%30s", tmp_set->name);
235 /* drop out of the loop */
244 /* Display help on commands */
246 static NTSTATUS cmd_help(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
247 int argc, const char **argv)
249 struct cmd_list *tmp;
250 struct cmd_set *tmp_set;
255 printf("Usage: %s [command]\n", argv[0]);
259 /* Help on one command */
262 for (tmp = cmd_list; tmp; tmp = tmp->next) {
264 tmp_set = tmp->cmd_set;
266 while(tmp_set->name) {
267 if (strequal(argv[1], tmp_set->name)) {
268 if (tmp_set->usage &&
270 printf("%s\n", tmp_set->usage);
272 printf("No help for %s\n", tmp_set->name);
281 printf("No such command: %s\n", argv[1]);
285 /* List all commands */
287 for (tmp = cmd_list; tmp; tmp = tmp->next) {
289 tmp_set = tmp->cmd_set;
291 while(tmp_set->name) {
293 printf("%15s\t\t%s\n", tmp_set->name,
294 tmp_set->description ? tmp_set->description:
304 /* Change the debug level */
306 static NTSTATUS cmd_debuglevel(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
307 int argc, const char **argv)
310 printf("Usage: %s [debuglevel]\n", argv[0]);
315 DEBUGLEVEL = atoi(argv[1]);
318 printf("debuglevel is %d\n", DEBUGLEVEL);
323 static NTSTATUS cmd_quit(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
324 int argc, const char **argv)
327 return NT_STATUS_OK; /* NOTREACHED */
330 static NTSTATUS cmd_set_ss_level(void)
332 struct cmd_list *tmp;
334 /* Close any existing connections not at this level. */
336 for (tmp = cmd_list; tmp; tmp = tmp->next) {
337 struct cmd_set *tmp_set;
339 for (tmp_set = tmp->cmd_set; tmp_set->name; tmp_set++) {
340 if (tmp_set->rpc_pipe == NULL) {
344 if ((tmp_set->rpc_pipe->auth->auth_type
345 != pipe_default_auth_type)
346 || (tmp_set->rpc_pipe->auth->auth_level
347 != pipe_default_auth_level)) {
348 TALLOC_FREE(tmp_set->rpc_pipe);
349 tmp_set->rpc_pipe = NULL;
356 static NTSTATUS cmd_set_transport(void)
358 struct cmd_list *tmp;
360 /* Close any existing connections not at this level. */
362 for (tmp = cmd_list; tmp; tmp = tmp->next) {
363 struct cmd_set *tmp_set;
365 for (tmp_set = tmp->cmd_set; tmp_set->name; tmp_set++) {
366 if (tmp_set->rpc_pipe == NULL) {
370 if (tmp_set->rpc_pipe->transport->transport != default_transport) {
371 TALLOC_FREE(tmp_set->rpc_pipe);
372 tmp_set->rpc_pipe = NULL;
379 static NTSTATUS cmd_sign(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
380 int argc, const char **argv)
382 const char *type = "NTLMSSP";
384 pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY;
385 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
388 printf("Usage: %s [NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL]\n", argv[0]);
394 if (strequal(type, "NTLMSSP")) {
395 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
396 } else if (strequal(type, "NTLMSSP_SPNEGO")) {
397 pipe_default_auth_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP;
398 } else if (strequal(type, "SCHANNEL")) {
399 pipe_default_auth_type = PIPE_AUTH_TYPE_SCHANNEL;
401 printf("unknown type %s\n", type);
402 return NT_STATUS_INVALID_LEVEL;
406 d_printf("Setting %s - sign\n", type);
408 return cmd_set_ss_level();
411 static NTSTATUS cmd_seal(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
412 int argc, const char **argv)
414 const char *type = "NTLMSSP";
416 pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY;
417 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
420 printf("Usage: %s [NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL]\n", argv[0]);
426 if (strequal(type, "NTLMSSP")) {
427 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
428 } else if (strequal(type, "NTLMSSP_SPNEGO")) {
429 pipe_default_auth_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP;
430 } else if (strequal(type, "SCHANNEL")) {
431 pipe_default_auth_type = PIPE_AUTH_TYPE_SCHANNEL;
433 printf("unknown type %s\n", type);
434 return NT_STATUS_INVALID_LEVEL;
438 d_printf("Setting %s - sign and seal\n", type);
440 return cmd_set_ss_level();
443 static NTSTATUS cmd_timeout(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
444 int argc, const char **argv)
446 struct cmd_list *tmp;
449 printf("Usage: %s timeout\n", argv[0]);
454 timeout = atoi(argv[1]);
456 for (tmp = cmd_list; tmp; tmp = tmp->next) {
458 struct cmd_set *tmp_set;
460 for (tmp_set = tmp->cmd_set; tmp_set->name; tmp_set++) {
461 if (tmp_set->rpc_pipe == NULL) {
465 rpccli_set_timeout(tmp_set->rpc_pipe, timeout);
470 printf("timeout is %d\n", timeout);
476 static NTSTATUS cmd_none(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
477 int argc, const char **argv)
479 pipe_default_auth_level = DCERPC_AUTH_LEVEL_NONE;
480 pipe_default_auth_type = PIPE_AUTH_TYPE_NONE;
482 return cmd_set_ss_level();
485 static NTSTATUS cmd_schannel(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
486 int argc, const char **argv)
488 d_printf("Setting schannel - sign and seal\n");
489 pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY;
490 pipe_default_auth_type = PIPE_AUTH_TYPE_SCHANNEL;
492 return cmd_set_ss_level();
495 static NTSTATUS cmd_schannel_sign(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
496 int argc, const char **argv)
498 d_printf("Setting schannel - sign only\n");
499 pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY;
500 pipe_default_auth_type = PIPE_AUTH_TYPE_SCHANNEL;
502 return cmd_set_ss_level();
505 static NTSTATUS cmd_choose_transport(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
506 int argc, const char **argv)
511 printf("Usage: %s [NCACN_NP|NCACN_IP_TCP]\n", argv[0]);
515 if (strequal(argv[1], "NCACN_NP")) {
516 default_transport = NCACN_NP;
517 } else if (strequal(argv[1], "NCACN_IP_TCP")) {
518 default_transport = NCACN_IP_TCP;
520 printf("transport type: %s unknown or not supported\n", argv[1]);
521 return NT_STATUS_NOT_SUPPORTED;
524 status = cmd_set_transport();
525 if (!NT_STATUS_IS_OK(status)) {
529 printf("default transport is now: %s\n", argv[1]);
534 /* Built in rpcclient commands */
536 static struct cmd_set rpcclient_commands[] = {
538 { "GENERAL OPTIONS" },
540 { "help", RPC_RTYPE_NTSTATUS, cmd_help, NULL, NULL, NULL, "Get help on commands", "[command]" },
541 { "?", RPC_RTYPE_NTSTATUS, cmd_help, NULL, NULL, NULL, "Get help on commands", "[command]" },
542 { "debuglevel", RPC_RTYPE_NTSTATUS, cmd_debuglevel, NULL, NULL, NULL, "Set debug level", "level" },
543 { "debug", RPC_RTYPE_NTSTATUS, cmd_debuglevel, NULL, NULL, NULL, "Set debug level", "level" },
544 { "list", RPC_RTYPE_NTSTATUS, cmd_listcommands, NULL, NULL, NULL, "List available commands on <pipe>", "pipe" },
545 { "exit", RPC_RTYPE_NTSTATUS, cmd_quit, NULL, NULL, NULL, "Exit program", "" },
546 { "quit", RPC_RTYPE_NTSTATUS, cmd_quit, NULL, NULL, NULL, "Exit program", "" },
547 { "sign", RPC_RTYPE_NTSTATUS, cmd_sign, NULL, NULL, NULL, "Force RPC pipe connections to be signed", "" },
548 { "seal", RPC_RTYPE_NTSTATUS, cmd_seal, NULL, NULL, NULL, "Force RPC pipe connections to be sealed", "" },
549 { "schannel", RPC_RTYPE_NTSTATUS, cmd_schannel, NULL, NULL, NULL, "Force RPC pipe connections to be sealed with 'schannel'. Assumes valid machine account to this domain controller.", "" },
550 { "schannelsign", RPC_RTYPE_NTSTATUS, cmd_schannel_sign, NULL, NULL, NULL, "Force RPC pipe connections to be signed (not sealed) with 'schannel'. Assumes valid machine account to this domain controller.", "" },
551 { "timeout", RPC_RTYPE_NTSTATUS, cmd_timeout, NULL, NULL, NULL, "Set timeout (in milliseonds) for RPC operations", "" },
552 { "transport", RPC_RTYPE_NTSTATUS, cmd_choose_transport, NULL, NULL, NULL, "Choose ncacn transport for RPC operations", "" },
553 { "none", RPC_RTYPE_NTSTATUS, cmd_none, NULL, NULL, NULL, "Force RPC pipe connections to have no special properties", "" },
558 static struct cmd_set separator_command[] = {
559 { "---------------", MAX_RPC_RETURN_TYPE, NULL, NULL, NULL, NULL, "----------------------" },
564 /* Various pipe commands */
566 extern struct cmd_set lsarpc_commands[];
567 extern struct cmd_set samr_commands[];
568 extern struct cmd_set spoolss_commands[];
569 extern struct cmd_set netlogon_commands[];
570 extern struct cmd_set srvsvc_commands[];
571 extern struct cmd_set dfs_commands[];
572 extern struct cmd_set ds_commands[];
573 extern struct cmd_set echo_commands[];
574 extern struct cmd_set epmapper_commands[];
575 extern struct cmd_set shutdown_commands[];
576 extern struct cmd_set test_commands[];
577 extern struct cmd_set wkssvc_commands[];
578 extern struct cmd_set ntsvcs_commands[];
579 extern struct cmd_set drsuapi_commands[];
580 extern struct cmd_set eventlog_commands[];
582 static struct cmd_set *rpcclient_command_list[] = {
602 static void add_command_set(struct cmd_set *cmd_set)
604 struct cmd_list *entry;
606 if (!(entry = SMB_MALLOC_P(struct cmd_list))) {
607 DEBUG(0, ("out of memory\n"));
613 entry->cmd_set = cmd_set;
614 DLIST_ADD(cmd_list, entry);
619 * Call an rpcclient function, passing an argv array.
621 * @param cmd Command to run, as a single string.
623 static NTSTATUS do_cmd(struct cli_state *cli,
624 struct user_auth_info *auth_info,
625 struct cmd_set *cmd_entry,
626 struct dcerpc_binding *binding,
627 int argc, char **argv)
636 if (!(mem_ctx = talloc_init("do_cmd"))) {
637 DEBUG(0, ("talloc_init() failed\n"));
638 return NT_STATUS_NO_MEMORY;
643 if ((cmd_entry->interface != NULL) && (cmd_entry->rpc_pipe == NULL)) {
644 switch (pipe_default_auth_type) {
645 case PIPE_AUTH_TYPE_NONE:
646 ntresult = cli_rpc_pipe_open_noauth_transport(
647 cli, default_transport,
648 cmd_entry->interface,
649 &cmd_entry->rpc_pipe);
651 case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP:
652 ntresult = cli_rpc_pipe_open_spnego_ntlmssp(
653 cli, cmd_entry->interface,
655 pipe_default_auth_level,
656 get_cmdline_auth_info_domain(auth_info),
657 get_cmdline_auth_info_username(auth_info),
658 get_cmdline_auth_info_password(auth_info),
659 &cmd_entry->rpc_pipe);
661 case PIPE_AUTH_TYPE_NTLMSSP:
662 ntresult = cli_rpc_pipe_open_ntlmssp(
663 cli, cmd_entry->interface,
665 pipe_default_auth_level,
666 get_cmdline_auth_info_domain(auth_info),
667 get_cmdline_auth_info_username(auth_info),
668 get_cmdline_auth_info_password(auth_info),
669 &cmd_entry->rpc_pipe);
671 case PIPE_AUTH_TYPE_SCHANNEL:
672 ntresult = cli_rpc_pipe_open_schannel(
673 cli, cmd_entry->interface,
675 pipe_default_auth_level,
676 get_cmdline_auth_info_domain(auth_info),
677 &cmd_entry->rpc_pipe);
680 DEBUG(0, ("Could not initialise %s. Invalid "
682 get_pipe_name_from_syntax(
684 cmd_entry->interface),
685 pipe_default_auth_type ));
686 return NT_STATUS_UNSUCCESSFUL;
688 if (!NT_STATUS_IS_OK(ntresult)) {
689 DEBUG(0, ("Could not initialise %s. Error was %s\n",
690 get_pipe_name_from_syntax(
691 talloc_tos(), cmd_entry->interface),
692 nt_errstr(ntresult) ));
696 if (ndr_syntax_id_equal(cmd_entry->interface,
697 &ndr_table_netlogon.syntax_id)) {
698 uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
699 enum netr_SchannelType sec_channel_type;
700 uchar trust_password[16];
701 const char *machine_account;
703 if (!get_trust_pw_hash(get_cmdline_auth_info_domain(auth_info),
704 trust_password, &machine_account,
707 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
710 ntresult = rpccli_netlogon_setup_creds(cmd_entry->rpc_pipe,
711 cli->desthost, /* server name */
712 get_cmdline_auth_info_domain(auth_info), /* domain */
713 global_myname(), /* client name */
714 machine_account, /* machine account name */
719 if (!NT_STATUS_IS_OK(ntresult)) {
720 DEBUG(0, ("Could not initialise credentials for %s.\n",
721 get_pipe_name_from_syntax(
723 cmd_entry->interface)));
731 if ( cmd_entry->returntype == RPC_RTYPE_NTSTATUS ) {
732 ntresult = cmd_entry->ntfn(cmd_entry->rpc_pipe, mem_ctx, argc, (const char **) argv);
733 if (!NT_STATUS_IS_OK(ntresult)) {
734 printf("result was %s\n", nt_errstr(ntresult));
737 wresult = cmd_entry->wfn(cmd_entry->rpc_pipe, mem_ctx, argc, (const char **) argv);
738 /* print out the DOS error */
739 if (!W_ERROR_IS_OK(wresult)) {
740 printf( "result was %s\n", win_errstr(wresult));
742 ntresult = W_ERROR_IS_OK(wresult)?NT_STATUS_OK:NT_STATUS_UNSUCCESSFUL;
747 talloc_destroy(mem_ctx);
754 * Process a command entered at the prompt or as part of -c
756 * @returns The NTSTATUS from running the command.
758 static NTSTATUS process_cmd(struct user_auth_info *auth_info,
759 struct cli_state *cli,
760 struct dcerpc_binding *binding,
763 struct cmd_list *temp_list;
764 NTSTATUS result = NT_STATUS_OK;
769 if ((ret = poptParseArgvString(cmd, &argc, (const char ***) &argv)) != 0) {
770 fprintf(stderr, "rpcclient: %s\n", poptStrerror(ret));
771 return NT_STATUS_UNSUCCESSFUL;
775 /* Walk through a dlist of arrays of commands. */
776 for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) {
777 struct cmd_set *temp_set = temp_list->cmd_set;
779 while (temp_set->name) {
780 if (strequal(argv[0], temp_set->name)) {
781 if (!(temp_set->returntype == RPC_RTYPE_NTSTATUS && temp_set->ntfn ) &&
782 !(temp_set->returntype == RPC_RTYPE_WERROR && temp_set->wfn )) {
783 fprintf (stderr, "Invalid command\n");
787 result = do_cmd(cli, auth_info, temp_set,
788 binding, argc, argv);
797 printf("command not found: %s\n", argv[0]);
802 if (!NT_STATUS_IS_OK(result)) {
803 printf("result was %s\n", nt_errstr(result));
807 /* NOTE: popt allocates the whole argv, including the
808 * strings, as a single block. So a single free is
809 * enough to release it -- we don't free the
810 * individual strings. rtfm. */
819 int main(int argc, char *argv[])
822 static char *cmdstr = NULL;
824 struct cli_state *cli = NULL;
825 static char *opt_ipaddr=NULL;
826 struct cmd_set **cmd_set;
827 struct sockaddr_storage server_ss;
829 static int opt_port = 0;
830 fstring new_workgroup;
832 TALLOC_CTX *frame = talloc_stackframe();
834 struct dcerpc_binding *binding = NULL;
835 const char *binding_string = NULL;
836 char *user, *domain, *q;
838 /* make sure the vars that get altered (4th field) are in
839 a fixed location or certain compilers complain */
841 struct poptOption long_options[] = {
843 {"command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated cmds", "COMMANDS"},
844 {"dest-ip", 'I', POPT_ARG_STRING, &opt_ipaddr, 'I', "Specify destination IP address", "IP"},
845 {"port", 'p', POPT_ARG_INT, &opt_port, 'p', "Specify port number", "PORT"},
847 POPT_COMMON_CONNECTION
848 POPT_COMMON_CREDENTIALS
854 zero_sockaddr(&server_ss);
858 /* the following functions are part of the Samba debugging
859 facilities. See lib/debug.c */
860 setup_logging("rpcclient", True);
862 rpcclient_auth_info = user_auth_info_init(frame);
863 if (rpcclient_auth_info == NULL) {
866 popt_common_set_auth_info(rpcclient_auth_info);
870 pc = poptGetContext("rpcclient", argc, (const char **) argv,
874 poptPrintHelp(pc, stderr, 0);
878 while((opt = poptGetNextOpt(pc)) != -1) {
882 if (!interpret_string_addr(&server_ss,
885 fprintf(stderr, "%s not a valid IP address\n",
893 /* Get server as remaining unparsed argument. Print usage if more
894 than one unparsed argument is present. */
896 server = poptGetArg(pc);
898 if (!server || poptGetArg(pc)) {
899 poptPrintHelp(pc, stderr, 0);
913 /* save the workgroup...
915 FIXME!! do we need to do this for other options as well
916 (or maybe a generic way to keep lp_load() from overwriting
919 fstrcpy( new_workgroup, lp_workgroup() );
921 /* Load smb.conf file */
923 if (!lp_load(get_dyn_CONFIGFILE(),True,False,False,True))
924 fprintf(stderr, "Can't load %s\n", get_dyn_CONFIGFILE());
926 if ( strlen(new_workgroup) != 0 )
927 set_global_myworkgroup( new_workgroup );
931 * from stdin if necessary
934 if (get_cmdline_auth_info_use_machine_account(rpcclient_auth_info) &&
935 !set_cmdline_auth_info_machine_account_creds(rpcclient_auth_info)) {
940 set_cmdline_auth_info_getpass(rpcclient_auth_info);
942 if ((server[0] == '/' && server[1] == '/') ||
943 (server[0] == '\\' && server[1] == '\\')) {
947 nt_status = dcerpc_parse_binding(frame, server, &binding);
949 if (!NT_STATUS_IS_OK(nt_status)) {
951 binding_string = talloc_asprintf(frame, "ncacn_np:%s",
952 strip_hostname(server));
953 if (!binding_string) {
958 nt_status = dcerpc_parse_binding(frame, binding_string, &binding);
959 if (!NT_STATUS_IS_OK(nt_status)) {
965 if (binding->transport == NCA_UNKNOWN) {
966 binding->transport = NCACN_NP;
969 if (binding->flags & DCERPC_SIGN) {
970 pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY;
971 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
973 if (binding->flags & DCERPC_SEAL) {
974 pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY;
975 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
977 if (binding->flags & DCERPC_AUTH_SPNEGO) {
978 pipe_default_auth_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP;
980 if (binding->flags & DCERPC_AUTH_NTLM) {
981 pipe_default_auth_type = PIPE_AUTH_TYPE_NTLMSSP;
983 if (binding->flags & DCERPC_AUTH_KRB5) {
984 pipe_default_auth_type = PIPE_AUTH_TYPE_SPNEGO_KRB5;
987 if (get_cmdline_auth_info_use_kerberos(rpcclient_auth_info)) {
988 flags |= CLI_FULL_CONNECTION_USE_KERBEROS |
989 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
991 if (get_cmdline_auth_info_use_ccache(rpcclient_auth_info)) {
992 flags |= CLI_FULL_CONNECTION_USE_CCACHE;
995 user = talloc_strdup(frame, get_cmdline_auth_info_username(rpcclient_auth_info));
996 SMB_ASSERT(user != NULL);
997 domain = talloc_strdup(frame, lp_workgroup());
998 SMB_ASSERT(domain != NULL);
999 set_cmdline_auth_info_domain(rpcclient_auth_info, domain);
1001 if ((q = strchr_m(user,'\\'))) {
1003 set_cmdline_auth_info_domain(rpcclient_auth_info, user);
1004 set_cmdline_auth_info_username(rpcclient_auth_info, q+1);
1008 nt_status = cli_full_connection(&cli, global_myname(), binding->host,
1009 opt_ipaddr ? &server_ss : NULL, opt_port,
1011 get_cmdline_auth_info_username(rpcclient_auth_info),
1012 get_cmdline_auth_info_domain(rpcclient_auth_info),
1013 get_cmdline_auth_info_password(rpcclient_auth_info),
1015 get_cmdline_auth_info_signing_state(rpcclient_auth_info),
1018 if (!NT_STATUS_IS_OK(nt_status)) {
1019 DEBUG(0,("Cannot connect to server. Error was %s\n", nt_errstr(nt_status)));
1024 if (get_cmdline_auth_info_smb_encrypt(rpcclient_auth_info)) {
1025 nt_status = cli_cm_force_encryption(cli,
1026 get_cmdline_auth_info_username(rpcclient_auth_info),
1027 get_cmdline_auth_info_password(rpcclient_auth_info),
1028 get_cmdline_auth_info_domain(rpcclient_auth_info),
1030 if (!NT_STATUS_IS_OK(nt_status)) {
1036 #if 0 /* COMMENT OUT FOR TESTING */
1037 memset(cmdline_auth_info.password,'X',sizeof(cmdline_auth_info.password));
1040 /* Load command lists */
1042 timeout = cli_set_timeout(cli, 10000);
1044 cmd_set = rpcclient_command_list;
1047 add_command_set(*cmd_set);
1048 add_command_set(separator_command);
1052 default_transport = binding->transport;
1054 fetch_machine_sid(cli);
1056 /* Do anything specified with -c */
1057 if (cmdstr && cmdstr[0]) {
1063 while((cmd=next_command(&p)) != NULL) {
1064 NTSTATUS cmd_result = process_cmd(rpcclient_auth_info, cli,
1067 result = NT_STATUS_IS_ERR(cmd_result);
1073 /* Loop around accepting commands */
1078 line = smb_readline("rpcclient $> ", NULL, completion_fn);
1083 if (line[0] != '\n')
1084 process_cmd(rpcclient_auth_info, cli, binding, line);