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"
28 static enum pipe_auth_type pipe_default_auth_type
= PIPE_AUTH_TYPE_NONE
;
29 static enum pipe_auth_level pipe_default_auth_level
= PIPE_AUTH_LEVEL_NONE
;
30 static unsigned int timeout
= 0;
32 struct user_auth_info
*rpcclient_auth_info
;
34 /* List to hold groups of commands.
36 * Commands are defined in a list of arrays: arrays are easy to
37 * statically declare, and lists are easier to dynamically extend.
40 static struct cmd_list
{
41 struct cmd_list
*prev
, *next
;
42 struct cmd_set
*cmd_set
;
45 /****************************************************************************
46 handle completion of commands for readline
47 ****************************************************************************/
48 static char **completion_fn(const char *text
, int start
, int end
)
50 #define MAX_COMPLETIONS 100
53 struct cmd_list
*commands
= cmd_list
;
56 /* FIXME!!! -- what to do when completing argument? */
57 /* for words not at the start of the line fallback
58 to filename completion */
63 /* make sure we have a list of valid commands */
68 matches
= SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS
);
73 matches
[count
++] = SMB_STRDUP(text
);
79 while (commands
&& count
< MAX_COMPLETIONS
-1) {
80 if (!commands
->cmd_set
) {
84 for (i
=0; commands
->cmd_set
[i
].name
; i
++) {
85 if ((strncmp(text
, commands
->cmd_set
[i
].name
, strlen(text
)) == 0) &&
86 (( commands
->cmd_set
[i
].returntype
== RPC_RTYPE_NTSTATUS
&&
87 commands
->cmd_set
[i
].ntfn
) ||
88 ( commands
->cmd_set
[i
].returntype
== RPC_RTYPE_WERROR
&&
89 commands
->cmd_set
[i
].wfn
))) {
90 matches
[count
] = SMB_STRDUP(commands
->cmd_set
[i
].name
);
91 if (!matches
[count
]) {
92 for (i
= 0; i
< count
; i
++) {
93 SAFE_FREE(matches
[count
]);
101 commands
= commands
->next
;
106 SAFE_FREE(matches
[0]);
107 matches
[0] = SMB_STRDUP(matches
[1]);
109 matches
[count
] = NULL
;
113 static char *next_command (char **cmdstr
)
118 if (!cmdstr
|| !(*cmdstr
))
121 p
= strchr_m(*cmdstr
, ';');
124 command
= SMB_STRDUP(*cmdstr
);
133 /* Fetch the SID for this computer */
135 static void fetch_machine_sid(struct cli_state
*cli
)
137 struct policy_handle pol
;
138 NTSTATUS result
= NT_STATUS_OK
;
139 static bool got_domain_sid
;
141 struct rpc_pipe_client
*lsapipe
= NULL
;
142 union lsa_PolicyInformation
*info
= NULL
;
144 if (got_domain_sid
) return;
146 if (!(mem_ctx
=talloc_init("fetch_machine_sid"))) {
147 DEBUG(0,("fetch_machine_sid: talloc_init returned NULL!\n"));
151 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
153 if (!NT_STATUS_IS_OK(result
)) {
154 fprintf(stderr
, "could not initialise lsa pipe. Error was %s\n", nt_errstr(result
) );
158 result
= rpccli_lsa_open_policy(lsapipe
, mem_ctx
, True
,
159 SEC_FLAG_MAXIMUM_ALLOWED
,
161 if (!NT_STATUS_IS_OK(result
)) {
165 result
= rpccli_lsa_QueryInfoPolicy(lsapipe
, mem_ctx
,
167 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
169 if (!NT_STATUS_IS_OK(result
)) {
173 got_domain_sid
= True
;
174 sid_copy(&domain_sid
, info
->account_domain
.sid
);
176 rpccli_lsa_Close(lsapipe
, mem_ctx
, &pol
);
177 TALLOC_FREE(lsapipe
);
178 talloc_destroy(mem_ctx
);
185 TALLOC_FREE(lsapipe
);
188 fprintf(stderr
, "could not obtain sid for domain %s\n", cli
->domain
);
190 if (!NT_STATUS_IS_OK(result
)) {
191 fprintf(stderr
, "error: %s\n", nt_errstr(result
));
197 /* List the available commands on a given pipe */
199 static NTSTATUS
cmd_listcommands(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
200 int argc
, const char **argv
)
202 struct cmd_list
*tmp
;
203 struct cmd_set
*tmp_set
;
209 printf("Usage: %s <pipe>\n", argv
[0]);
213 /* Help on one command */
215 for (tmp
= cmd_list
; tmp
; tmp
= tmp
->next
)
217 tmp_set
= tmp
->cmd_set
;
219 if (!StrCaseCmp(argv
[1], tmp_set
->name
))
221 printf("Available commands on the %s pipe:\n\n", tmp_set
->name
);
225 while(tmp_set
->name
) {
226 printf("%30s", tmp_set
->name
);
233 /* drop out of the loop */
242 /* Display help on commands */
244 static NTSTATUS
cmd_help(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
245 int argc
, const char **argv
)
247 struct cmd_list
*tmp
;
248 struct cmd_set
*tmp_set
;
253 printf("Usage: %s [command]\n", argv
[0]);
257 /* Help on one command */
260 for (tmp
= cmd_list
; tmp
; tmp
= tmp
->next
) {
262 tmp_set
= tmp
->cmd_set
;
264 while(tmp_set
->name
) {
265 if (strequal(argv
[1], tmp_set
->name
)) {
266 if (tmp_set
->usage
&&
268 printf("%s\n", tmp_set
->usage
);
270 printf("No help for %s\n", tmp_set
->name
);
279 printf("No such command: %s\n", argv
[1]);
283 /* List all commands */
285 for (tmp
= cmd_list
; tmp
; tmp
= tmp
->next
) {
287 tmp_set
= tmp
->cmd_set
;
289 while(tmp_set
->name
) {
291 printf("%15s\t\t%s\n", tmp_set
->name
,
292 tmp_set
->description
? tmp_set
->description
:
302 /* Change the debug level */
304 static NTSTATUS
cmd_debuglevel(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
305 int argc
, const char **argv
)
308 printf("Usage: %s [debuglevel]\n", argv
[0]);
313 DEBUGLEVEL
= atoi(argv
[1]);
316 printf("debuglevel is %d\n", DEBUGLEVEL
);
321 static NTSTATUS
cmd_quit(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
322 int argc
, const char **argv
)
325 return NT_STATUS_OK
; /* NOTREACHED */
328 static NTSTATUS
cmd_set_ss_level(void)
330 struct cmd_list
*tmp
;
332 /* Close any existing connections not at this level. */
334 for (tmp
= cmd_list
; tmp
; tmp
= tmp
->next
) {
335 struct cmd_set
*tmp_set
;
337 for (tmp_set
= tmp
->cmd_set
; tmp_set
->name
; tmp_set
++) {
338 if (tmp_set
->rpc_pipe
== NULL
) {
342 if ((tmp_set
->rpc_pipe
->auth
->auth_type
343 != pipe_default_auth_type
)
344 || (tmp_set
->rpc_pipe
->auth
->auth_level
345 != pipe_default_auth_level
)) {
346 TALLOC_FREE(tmp_set
->rpc_pipe
);
347 tmp_set
->rpc_pipe
= NULL
;
354 static NTSTATUS
cmd_sign(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
355 int argc
, const char **argv
)
357 const char *type
= "NTLMSSP";
359 pipe_default_auth_level
= PIPE_AUTH_LEVEL_INTEGRITY
;
360 pipe_default_auth_type
= PIPE_AUTH_TYPE_NTLMSSP
;
363 printf("Usage: %s [NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL]\n", argv
[0]);
369 if (strequal(type
, "NTLMSSP")) {
370 pipe_default_auth_type
= PIPE_AUTH_TYPE_NTLMSSP
;
371 } else if (strequal(type
, "NTLMSSP_SPNEGO")) {
372 pipe_default_auth_type
= PIPE_AUTH_TYPE_SPNEGO_NTLMSSP
;
373 } else if (strequal(type
, "SCHANNEL")) {
374 pipe_default_auth_type
= PIPE_AUTH_TYPE_SCHANNEL
;
376 printf("unknown type %s\n", type
);
377 return NT_STATUS_INVALID_LEVEL
;
381 d_printf("Setting %s - sign\n", type
);
383 return cmd_set_ss_level();
386 static NTSTATUS
cmd_seal(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
387 int argc
, const char **argv
)
389 const char *type
= "NTLMSSP";
391 pipe_default_auth_level
= PIPE_AUTH_LEVEL_PRIVACY
;
392 pipe_default_auth_type
= PIPE_AUTH_TYPE_NTLMSSP
;
395 printf("Usage: %s [NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL]\n", argv
[0]);
401 if (strequal(type
, "NTLMSSP")) {
402 pipe_default_auth_type
= PIPE_AUTH_TYPE_NTLMSSP
;
403 } else if (strequal(type
, "NTLMSSP_SPNEGO")) {
404 pipe_default_auth_type
= PIPE_AUTH_TYPE_SPNEGO_NTLMSSP
;
405 } else if (strequal(type
, "SCHANNEL")) {
406 pipe_default_auth_type
= PIPE_AUTH_TYPE_SCHANNEL
;
408 printf("unknown type %s\n", type
);
409 return NT_STATUS_INVALID_LEVEL
;
413 d_printf("Setting %s - sign and seal\n", type
);
415 return cmd_set_ss_level();
418 static NTSTATUS
cmd_timeout(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
419 int argc
, const char **argv
)
421 struct cmd_list
*tmp
;
424 printf("Usage: %s timeout\n", argv
[0]);
429 timeout
= atoi(argv
[1]);
431 for (tmp
= cmd_list
; tmp
; tmp
= tmp
->next
) {
433 struct cmd_set
*tmp_set
;
435 for (tmp_set
= tmp
->cmd_set
; tmp_set
->name
; tmp_set
++) {
436 if (tmp_set
->rpc_pipe
== NULL
) {
440 rpccli_set_timeout(tmp_set
->rpc_pipe
, timeout
);
445 printf("timeout is %d\n", timeout
);
451 static NTSTATUS
cmd_none(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
452 int argc
, const char **argv
)
454 pipe_default_auth_level
= PIPE_AUTH_LEVEL_NONE
;
455 pipe_default_auth_type
= PIPE_AUTH_TYPE_NONE
;
457 return cmd_set_ss_level();
460 static NTSTATUS
cmd_schannel(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
461 int argc
, const char **argv
)
463 d_printf("Setting schannel - sign and seal\n");
464 pipe_default_auth_level
= PIPE_AUTH_LEVEL_PRIVACY
;
465 pipe_default_auth_type
= PIPE_AUTH_TYPE_SCHANNEL
;
467 return cmd_set_ss_level();
470 static NTSTATUS
cmd_schannel_sign(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
471 int argc
, const char **argv
)
473 d_printf("Setting schannel - sign only\n");
474 pipe_default_auth_level
= PIPE_AUTH_LEVEL_INTEGRITY
;
475 pipe_default_auth_type
= PIPE_AUTH_TYPE_SCHANNEL
;
477 return cmd_set_ss_level();
481 /* Built in rpcclient commands */
483 static struct cmd_set rpcclient_commands
[] = {
485 { "GENERAL OPTIONS" },
487 { "help", RPC_RTYPE_NTSTATUS
, cmd_help
, NULL
, NULL
, NULL
, "Get help on commands", "[command]" },
488 { "?", RPC_RTYPE_NTSTATUS
, cmd_help
, NULL
, NULL
, NULL
, "Get help on commands", "[command]" },
489 { "debuglevel", RPC_RTYPE_NTSTATUS
, cmd_debuglevel
, NULL
, NULL
, NULL
, "Set debug level", "level" },
490 { "debug", RPC_RTYPE_NTSTATUS
, cmd_debuglevel
, NULL
, NULL
, NULL
, "Set debug level", "level" },
491 { "list", RPC_RTYPE_NTSTATUS
, cmd_listcommands
, NULL
, NULL
, NULL
, "List available commands on <pipe>", "pipe" },
492 { "exit", RPC_RTYPE_NTSTATUS
, cmd_quit
, NULL
, NULL
, NULL
, "Exit program", "" },
493 { "quit", RPC_RTYPE_NTSTATUS
, cmd_quit
, NULL
, NULL
, NULL
, "Exit program", "" },
494 { "sign", RPC_RTYPE_NTSTATUS
, cmd_sign
, NULL
, NULL
, NULL
, "Force RPC pipe connections to be signed", "" },
495 { "seal", RPC_RTYPE_NTSTATUS
, cmd_seal
, NULL
, NULL
, NULL
, "Force RPC pipe connections to be sealed", "" },
496 { "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.", "" },
497 { "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.", "" },
498 { "timeout", RPC_RTYPE_NTSTATUS
, cmd_timeout
, NULL
, NULL
, NULL
, "Set timeout (in milliseonds) for RPC operations", "" },
499 { "none", RPC_RTYPE_NTSTATUS
, cmd_none
, NULL
, NULL
, NULL
, "Force RPC pipe connections to have no special properties", "" },
504 static struct cmd_set separator_command
[] = {
505 { "---------------", MAX_RPC_RETURN_TYPE
, NULL
, NULL
, NULL
, NULL
, "----------------------" },
510 /* Various pipe commands */
512 extern struct cmd_set lsarpc_commands
[];
513 extern struct cmd_set samr_commands
[];
514 extern struct cmd_set spoolss_commands
[];
515 extern struct cmd_set netlogon_commands
[];
516 extern struct cmd_set srvsvc_commands
[];
517 extern struct cmd_set dfs_commands
[];
518 extern struct cmd_set ds_commands
[];
519 extern struct cmd_set echo_commands
[];
520 extern struct cmd_set epmapper_commands
[];
521 extern struct cmd_set shutdown_commands
[];
522 extern struct cmd_set test_commands
[];
523 extern struct cmd_set wkssvc_commands
[];
524 extern struct cmd_set ntsvcs_commands
[];
525 extern struct cmd_set drsuapi_commands
[];
526 extern struct cmd_set eventlog_commands
[];
528 static struct cmd_set
*rpcclient_command_list
[] = {
548 static void add_command_set(struct cmd_set
*cmd_set
)
550 struct cmd_list
*entry
;
552 if (!(entry
= SMB_MALLOC_P(struct cmd_list
))) {
553 DEBUG(0, ("out of memory\n"));
559 entry
->cmd_set
= cmd_set
;
560 DLIST_ADD(cmd_list
, entry
);
565 * Call an rpcclient function, passing an argv array.
567 * @param cmd Command to run, as a single string.
569 static NTSTATUS
do_cmd(struct cli_state
*cli
,
570 struct user_auth_info
*auth_info
,
571 struct cmd_set
*cmd_entry
,
572 int argc
, char **argv
)
581 if (!(mem_ctx
= talloc_init("do_cmd"))) {
582 DEBUG(0, ("talloc_init() failed\n"));
583 return NT_STATUS_NO_MEMORY
;
588 if ((cmd_entry
->interface
!= NULL
) && (cmd_entry
->rpc_pipe
== NULL
)) {
589 switch (pipe_default_auth_type
) {
590 case PIPE_AUTH_TYPE_NONE
:
591 ntresult
= cli_rpc_pipe_open_noauth(
592 cli
, cmd_entry
->interface
,
593 &cmd_entry
->rpc_pipe
);
595 case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP
:
596 ntresult
= cli_rpc_pipe_open_spnego_ntlmssp(
597 cli
, cmd_entry
->interface
,
598 pipe_default_auth_level
,
600 get_cmdline_auth_info_username(auth_info
),
601 get_cmdline_auth_info_password(auth_info
),
602 &cmd_entry
->rpc_pipe
);
604 case PIPE_AUTH_TYPE_NTLMSSP
:
605 ntresult
= cli_rpc_pipe_open_ntlmssp(
606 cli
, cmd_entry
->interface
,
607 pipe_default_auth_level
,
609 get_cmdline_auth_info_username(auth_info
),
610 get_cmdline_auth_info_password(auth_info
),
611 &cmd_entry
->rpc_pipe
);
613 case PIPE_AUTH_TYPE_SCHANNEL
:
614 ntresult
= cli_rpc_pipe_open_schannel(
615 cli
, cmd_entry
->interface
,
616 pipe_default_auth_level
,
618 &cmd_entry
->rpc_pipe
);
621 DEBUG(0, ("Could not initialise %s. Invalid "
623 get_pipe_name_from_iface(
624 cmd_entry
->interface
),
625 pipe_default_auth_type
));
626 return NT_STATUS_UNSUCCESSFUL
;
628 if (!NT_STATUS_IS_OK(ntresult
)) {
629 DEBUG(0, ("Could not initialise %s. Error was %s\n",
630 get_pipe_name_from_iface(
631 cmd_entry
->interface
),
632 nt_errstr(ntresult
) ));
636 if (ndr_syntax_id_equal(cmd_entry
->interface
,
637 &ndr_table_netlogon
.syntax_id
)) {
638 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
639 uint32 sec_channel_type
;
640 uchar trust_password
[16];
642 if (!secrets_fetch_trust_account_password(lp_workgroup(),
644 NULL
, &sec_channel_type
)) {
645 return NT_STATUS_UNSUCCESSFUL
;
648 ntresult
= rpccli_netlogon_setup_creds(cmd_entry
->rpc_pipe
,
649 cli
->desthost
, /* server name */
650 lp_workgroup(), /* domain */
651 global_myname(), /* client name */
652 global_myname(), /* machine account name */
657 if (!NT_STATUS_IS_OK(ntresult
)) {
658 DEBUG(0, ("Could not initialise credentials for %s.\n",
659 get_pipe_name_from_iface(
660 cmd_entry
->interface
)));
668 if ( cmd_entry
->returntype
== RPC_RTYPE_NTSTATUS
) {
669 ntresult
= cmd_entry
->ntfn(cmd_entry
->rpc_pipe
, mem_ctx
, argc
, (const char **) argv
);
670 if (!NT_STATUS_IS_OK(ntresult
)) {
671 printf("result was %s\n", nt_errstr(ntresult
));
674 wresult
= cmd_entry
->wfn(cmd_entry
->rpc_pipe
, mem_ctx
, argc
, (const char **) argv
);
675 /* print out the DOS error */
676 if (!W_ERROR_IS_OK(wresult
)) {
677 printf( "result was %s\n", win_errstr(wresult
));
679 ntresult
= W_ERROR_IS_OK(wresult
)?NT_STATUS_OK
:NT_STATUS_UNSUCCESSFUL
;
684 talloc_destroy(mem_ctx
);
691 * Process a command entered at the prompt or as part of -c
693 * @returns The NTSTATUS from running the command.
695 static NTSTATUS
process_cmd(struct user_auth_info
*auth_info
,
696 struct cli_state
*cli
, char *cmd
)
698 struct cmd_list
*temp_list
;
699 NTSTATUS result
= NT_STATUS_OK
;
704 if ((ret
= poptParseArgvString(cmd
, &argc
, (const char ***) &argv
)) != 0) {
705 fprintf(stderr
, "rpcclient: %s\n", poptStrerror(ret
));
706 return NT_STATUS_UNSUCCESSFUL
;
710 /* Walk through a dlist of arrays of commands. */
711 for (temp_list
= cmd_list
; temp_list
; temp_list
= temp_list
->next
) {
712 struct cmd_set
*temp_set
= temp_list
->cmd_set
;
714 while (temp_set
->name
) {
715 if (strequal(argv
[0], temp_set
->name
)) {
716 if (!(temp_set
->returntype
== RPC_RTYPE_NTSTATUS
&& temp_set
->ntfn
) &&
717 !(temp_set
->returntype
== RPC_RTYPE_WERROR
&& temp_set
->wfn
)) {
718 fprintf (stderr
, "Invalid command\n");
722 result
= do_cmd(cli
, auth_info
, temp_set
,
732 printf("command not found: %s\n", argv
[0]);
737 if (!NT_STATUS_IS_OK(result)) {
738 printf("result was %s\n", nt_errstr(result));
742 /* NOTE: popt allocates the whole argv, including the
743 * strings, as a single block. So a single free is
744 * enough to release it -- we don't free the
745 * individual strings. rtfm. */
754 int main(int argc
, char *argv
[])
757 static char *cmdstr
= NULL
;
759 struct cli_state
*cli
= NULL
;
760 static char *opt_ipaddr
=NULL
;
761 struct cmd_set
**cmd_set
;
762 struct sockaddr_storage server_ss
;
764 static int opt_port
= 0;
765 fstring new_workgroup
;
767 TALLOC_CTX
*frame
= talloc_stackframe();
770 /* make sure the vars that get altered (4th field) are in
771 a fixed location or certain compilers complain */
773 struct poptOption long_options
[] = {
775 {"command", 'c', POPT_ARG_STRING
, &cmdstr
, 'c', "Execute semicolon separated cmds", "COMMANDS"},
776 {"dest-ip", 'I', POPT_ARG_STRING
, &opt_ipaddr
, 'I', "Specify destination IP address", "IP"},
777 {"port", 'p', POPT_ARG_INT
, &opt_port
, 'p', "Specify port number", "PORT"},
779 POPT_COMMON_CONNECTION
780 POPT_COMMON_CREDENTIALS
786 zero_sockaddr(&server_ss
);
790 /* the following functions are part of the Samba debugging
791 facilities. See lib/debug.c */
792 setup_logging("rpcclient", True
);
794 rpcclient_auth_info
= user_auth_info_init(frame
);
795 if (rpcclient_auth_info
== NULL
) {
798 popt_common_set_auth_info(rpcclient_auth_info
);
802 pc
= poptGetContext("rpcclient", argc
, (const char **) argv
,
806 poptPrintHelp(pc
, stderr
, 0);
810 while((opt
= poptGetNextOpt(pc
)) != -1) {
814 if (!interpret_string_addr(&server_ss
,
817 fprintf(stderr
, "%s not a valid IP address\n",
825 /* Get server as remaining unparsed argument. Print usage if more
826 than one unparsed argument is present. */
828 server
= poptGetArg(pc
);
830 if (!server
|| poptGetArg(pc
)) {
831 poptPrintHelp(pc
, stderr
, 0);
845 /* save the workgroup...
847 FIXME!! do we need to do this for other options as well
848 (or maybe a generic way to keep lp_load() from overwriting
851 fstrcpy( new_workgroup
, lp_workgroup() );
853 /* Load smb.conf file */
855 if (!lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
))
856 fprintf(stderr
, "Can't load %s\n", get_dyn_CONFIGFILE());
858 if ( strlen(new_workgroup
) != 0 )
859 set_global_myworkgroup( new_workgroup
);
863 * from stdin if necessary
866 if (get_cmdline_auth_info_use_machine_account(rpcclient_auth_info
) &&
867 !set_cmdline_auth_info_machine_account_creds(rpcclient_auth_info
)) {
872 set_cmdline_auth_info_getpass(rpcclient_auth_info
);
874 if ((server
[0] == '/' && server
[1] == '/') ||
875 (server
[0] == '\\' && server
[1] == '\\')) {
879 if (get_cmdline_auth_info_use_kerberos(rpcclient_auth_info
)) {
880 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
|
881 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS
;
885 nt_status
= cli_full_connection(&cli
, global_myname(), server
,
886 opt_ipaddr
? &server_ss
: NULL
, opt_port
,
888 get_cmdline_auth_info_username(rpcclient_auth_info
),
890 get_cmdline_auth_info_password(rpcclient_auth_info
),
892 get_cmdline_auth_info_signing_state(rpcclient_auth_info
),
895 if (!NT_STATUS_IS_OK(nt_status
)) {
896 DEBUG(0,("Cannot connect to server. Error was %s\n", nt_errstr(nt_status
)));
901 if (get_cmdline_auth_info_smb_encrypt(rpcclient_auth_info
)) {
902 nt_status
= cli_cm_force_encryption(cli
,
903 get_cmdline_auth_info_username(rpcclient_auth_info
),
904 get_cmdline_auth_info_password(rpcclient_auth_info
),
907 if (!NT_STATUS_IS_OK(nt_status
)) {
913 #if 0 /* COMMENT OUT FOR TESTING */
914 memset(cmdline_auth_info
.password
,'X',sizeof(cmdline_auth_info
.password
));
917 /* Load command lists */
919 timeout
= cli_set_timeout(cli
, 10000);
921 cmd_set
= rpcclient_command_list
;
924 add_command_set(*cmd_set
);
925 add_command_set(separator_command
);
929 fetch_machine_sid(cli
);
931 /* Do anything specified with -c */
932 if (cmdstr
&& cmdstr
[0]) {
938 while((cmd
=next_command(&p
)) != NULL
) {
939 NTSTATUS cmd_result
= process_cmd(rpcclient_auth_info
, cli
, cmd
);
941 result
= NT_STATUS_IS_ERR(cmd_result
);
947 /* Loop around accepting commands */
952 line
= smb_readline("rpcclient $> ", NULL
, completion_fn
);
958 process_cmd(rpcclient_auth_info
, cli
, line
);