2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
5 Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
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. */
22 #include "../utils/net.h"
27 * @brief RPC based subcommands for the 'net' utility.
29 * This file should contain much of the functionality that used to
30 * be found in rpcclient, execpt that the commands should change
31 * less often, and the fucntionality should be sane (the user is not
32 * expected to know a rid/sid before they conduct an operation etc.)
34 * @todo Perhaps eventually these should be split out into a number
35 * of files, as this could get quite big.
39 /* A function of this type is passed to the 'run_rpc_command' wrapper */
40 typedef NTSTATUS (*rpc_command_fn
)(const DOM_SID
*, struct cli_state
*, TALLOC_CTX
*, int, const char **);
43 * Many of the RPC functions need the domain sid. This function gets
44 * it at the start of every run
46 * @param cli A cli_state already connected to the remote machine
48 * @return The Domain SID of the remote machine.
51 static DOM_SID
*net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
)
55 NTSTATUS result
= NT_STATUS_OK
;
56 uint32 info_class
= 5;
59 if (!cli_nt_session_open (cli
, PI_LSARPC
)) {
60 fprintf(stderr
, "could not initialise lsa pipe\n");
64 result
= cli_lsa_open_policy(cli
, mem_ctx
, False
,
65 SEC_RIGHTS_MAXIMUM_ALLOWED
,
67 if (!NT_STATUS_IS_OK(result
)) {
71 result
= cli_lsa_query_info_policy(cli
, mem_ctx
, &pol
, info_class
,
72 &domain_name
, &domain_sid
);
73 if (!NT_STATUS_IS_OK(result
)) {
75 fprintf(stderr
, "could not obtain sid for domain %s\n", cli
->domain
);
77 if (!NT_STATUS_IS_OK(result
)) {
78 fprintf(stderr
, "error: %s\n", nt_errstr(result
));
84 cli_lsa_close(cli
, mem_ctx
, &pol
);
85 cli_nt_session_close(cli
);
91 * Run a single RPC command, from start to finish.
93 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
94 * @param conn_flag a NET_FLAG_ combination. Passed to
95 * net_make_ipc_connection.
96 * @param argc Standard main() style argc
97 * @param argc Standard main() style argv. Initial components are already
99 * @return A shell status integer (0 for success)
102 static int run_rpc_command(struct cli_state
*cli_arg
, const int pipe_idx
, int conn_flags
,
104 int argc
, const char **argv
)
106 struct cli_state
*cli
= NULL
;
111 /* make use of cli_state handed over as an argument, if possible */
113 cli
= net_make_ipc_connection(conn_flags
);
123 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
124 DEBUG(0, ("talloc_init() failed\n"));
129 domain_sid
= net_get_remote_domain_sid(cli
, mem_ctx
);
131 if (!cli_nt_session_open(cli
, pipe_idx
)) {
132 DEBUG(0, ("Could not initialise pipe\n"));
135 nt_status
= fn(domain_sid
, cli
, mem_ctx
, argc
, argv
);
137 if (!NT_STATUS_IS_OK(nt_status
)) {
138 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
140 DEBUG(5, ("rpc command function succedded\n"));
144 if (cli
->nt_pipe_fnum
)
145 cli_nt_session_close(cli
);
147 /* close the connection only if it was opened here */
151 talloc_destroy(mem_ctx
);
153 return (!NT_STATUS_IS_OK(nt_status
));
157 /****************************************************************************/
161 * Force a change of the trust acccount password.
163 * All parameters are provided by the run_rpc_command function, except for
164 * argc, argv which are passes through.
166 * @param domain_sid The domain sid aquired from the remote server
167 * @param cli A cli_state connected to the server.
168 * @param mem_ctx Talloc context, destoyed on compleation of the function.
169 * @param argc Standard main() style argc
170 * @param argc Standard main() style argv. Initial components are already
173 * @return Normal NTSTATUS return.
176 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
177 int argc
, const char **argv
) {
179 return trust_pw_find_change_and_store_it(cli
, mem_ctx
, opt_target_workgroup
);
183 * Force a change of the trust acccount password.
185 * @param argc Standard main() style argc
186 * @param argc Standard main() style argv. Initial components are already
189 * @return A shell status integer (0 for success)
192 int net_rpc_changetrustpw(int argc
, const char **argv
)
194 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
, rpc_changetrustpw_internals
,
199 /****************************************************************************/
203 * Join a domain, the old way.
205 * This uses 'machinename' as the inital password, and changes it.
207 * The password should be created with 'server manager' or equiv first.
209 * All parameters are provided by the run_rpc_command function, except for
210 * argc, argv which are passes through.
212 * @param domain_sid The domain sid aquired from the remote server
213 * @param cli A cli_state connected to the server.
214 * @param mem_ctx Talloc context, destoyed on compleation of the function.
215 * @param argc Standard main() style argc
216 * @param argc Standard main() style argv. Initial components are already
219 * @return Normal NTSTATUS return.
222 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
224 int argc
, const char **argv
) {
226 fstring trust_passwd
;
227 unsigned char orig_trust_passwd_hash
[16];
229 uint32 sec_channel_type
;
232 check what type of join - if the user want's to join as
233 a BDC, the server must agree that we are a BDC.
236 sec_channel_type
= get_sec_channel_type(argv
[0]);
238 sec_channel_type
= get_sec_channel_type(NULL
);
241 fstrcpy(trust_passwd
, global_myname());
242 strlower_m(trust_passwd
);
245 * Machine names can be 15 characters, but the max length on
246 * a password is 14. --jerry
249 trust_passwd
[14] = '\0';
251 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
253 result
= trust_pw_change_and_store_it(cli
, mem_ctx
, opt_target_workgroup
,
254 orig_trust_passwd_hash
,
257 if (NT_STATUS_IS_OK(result
))
258 printf("Joined domain %s.\n",opt_target_workgroup
);
261 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
262 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
263 result
= NT_STATUS_UNSUCCESSFUL
;
270 * Join a domain, the old way.
272 * @param argc Standard main() style argc
273 * @param argc Standard main() style argv. Initial components are already
276 * @return A shell status integer (0 for success)
279 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
281 return run_rpc_command(NULL
, PI_NETLOGON
,
282 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
283 rpc_oldjoin_internals
,
288 * Join a domain, the old way. This function exists to allow
289 * the message to be displayed when oldjoin was explicitly
290 * requested, but not when it was implied by "net rpc join"
292 * @param argc Standard main() style argc
293 * @param argc Standard main() style argv. Initial components are already
296 * @return A shell status integer (0 for success)
299 static int net_rpc_oldjoin(int argc
, const char **argv
)
301 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
304 d_printf("Failed to join domain\n");
311 * Basic usage function for 'net rpc join'
312 * @param argc Standard main() style argc
313 * @param argc Standard main() style argv. Initial components are already
317 static int rpc_join_usage(int argc
, const char **argv
)
319 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
320 "\t to join a domain with admin username & password\n"\
321 "\t\t password will be prompted if needed and none is specified\n"\
322 "\t <type> can be (default MEMBER)\n"\
323 "\t\t BDC - Join as a BDC\n"\
324 "\t\t PDC - Join as a PDC\n"\
325 "\t\t MEMBER - Join as a MEMBER server\n");
327 net_common_flags_usage(argc
, argv
);
332 * 'net rpc join' entrypoint.
333 * @param argc Standard main() style argc
334 * @param argc Standard main() style argv. Initial components are already
337 * Main 'net_rpc_join()' (where the admain username/password is used) is
339 * Try to just change the password, but if that doesn't work, use/prompt
340 * for a username/password.
343 int net_rpc_join(int argc
, const char **argv
)
345 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
348 return net_rpc_join_newstyle(argc
, argv
);
354 * display info about a rpc domain
356 * All parameters are provided by the run_rpc_command function, except for
357 * argc, argv which are passed through.
359 * @param domain_sid The domain sid acquired from the remote server
360 * @param cli A cli_state connected to the server.
361 * @param mem_ctx Talloc context, destoyed on completion of the function.
362 * @param argc Standard main() style argc
363 * @param argv Standard main() style argv. Initial components are already
366 * @return Normal NTSTATUS return.
370 rpc_info_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
371 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
373 POLICY_HND connect_pol
, domain_pol
;
374 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
378 sid_to_string(sid_str
, domain_sid
);
380 /* Get sam policy handle */
381 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
383 if (!NT_STATUS_IS_OK(result
)) {
387 /* Get domain policy handle */
388 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
389 MAXIMUM_ALLOWED_ACCESS
,
390 domain_sid
, &domain_pol
);
391 if (!NT_STATUS_IS_OK(result
)) {
396 result
= cli_samr_query_dom_info(cli
, mem_ctx
, &domain_pol
,
398 if (NT_STATUS_IS_OK(result
)) {
399 TALLOC_CTX
*ctx
= talloc_init("rpc_info_internals");
400 d_printf("Domain Name: %s\n", unistr2_tdup(ctx
, &ctr
.info
.inf2
.uni_domain
));
401 d_printf("Domain SID: %s\n", sid_str
);
402 d_printf("Sequence number: %u\n", ctr
.info
.inf2
.seq_num
);
403 d_printf("Num users: %u\n", ctr
.info
.inf2
.num_domain_usrs
);
404 d_printf("Num domain groups: %u\n", ctr
.info
.inf2
.num_domain_grps
);
405 d_printf("Num local groups: %u\n", ctr
.info
.inf2
.num_local_grps
);
415 * 'net rpc info' entrypoint.
416 * @param argc Standard main() style argc
417 * @param argc Standard main() style argv. Initial components are already
420 int net_rpc_info(int argc
, const char **argv
)
422 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
429 * Fetch domain SID into the local secrets.tdb
431 * All parameters are provided by the run_rpc_command function, except for
432 * argc, argv which are passes through.
434 * @param domain_sid The domain sid acquired from the remote server
435 * @param cli A cli_state connected to the server.
436 * @param mem_ctx Talloc context, destoyed on completion of the function.
437 * @param argc Standard main() style argc
438 * @param argv Standard main() style argv. Initial components are already
441 * @return Normal NTSTATUS return.
445 rpc_getsid_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
446 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
450 sid_to_string(sid_str
, domain_sid
);
451 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
452 sid_str
, lp_workgroup());
454 if (!secrets_store_domain_sid(global_myname(), domain_sid
)) {
455 DEBUG(0,("Can't store domain SID\n"));
456 return NT_STATUS_UNSUCCESSFUL
;
464 * 'net rpc getsid' entrypoint.
465 * @param argc Standard main() style argc
466 * @param argc Standard main() style argv. Initial components are already
469 int net_rpc_getsid(int argc
, const char **argv
)
471 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
472 rpc_getsid_internals
,
477 /****************************************************************************/
480 * Basic usage function for 'net rpc user'
481 * @param argc Standard main() style argc.
482 * @param argv Standard main() style argv. Initial components are already
486 static int rpc_user_usage(int argc
, const char **argv
)
488 return net_help_user(argc
, argv
);
492 * Add a new user to a remote RPC server
494 * All parameters are provided by the run_rpc_command function, except for
495 * argc, argv which are passes through.
497 * @param domain_sid The domain sid acquired from the remote server
498 * @param cli A cli_state connected to the server.
499 * @param mem_ctx Talloc context, destoyed on completion of the function.
500 * @param argc Standard main() style argc
501 * @param argv Standard main() style argv. Initial components are already
504 * @return Normal NTSTATUS return.
507 static NTSTATUS
rpc_user_add_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
508 int argc
, const char **argv
) {
510 POLICY_HND connect_pol
, domain_pol
, user_pol
;
511 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
512 const char *acct_name
;
514 uint32 unknown
, user_rid
;
517 d_printf("User must be specified\n");
518 rpc_user_usage(argc
, argv
);
524 /* Get sam policy handle */
526 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
528 if (!NT_STATUS_IS_OK(result
)) {
532 /* Get domain policy handle */
534 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
535 MAXIMUM_ALLOWED_ACCESS
,
536 domain_sid
, &domain_pol
);
537 if (!NT_STATUS_IS_OK(result
)) {
541 /* Create domain user */
543 acb_info
= ACB_NORMAL
;
544 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
546 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
547 acct_name
, acb_info
, unknown
,
548 &user_pol
, &user_rid
);
549 if (!NT_STATUS_IS_OK(result
)) {
554 if (!NT_STATUS_IS_OK(result
)) {
555 d_printf("Failed to add user %s - %s\n", acct_name
,
558 d_printf("Added user %s\n", acct_name
);
564 * Add a new user to a remote RPC server
566 * @param argc Standard main() style argc
567 * @param argv Standard main() style argv. Initial components are already
570 * @return A shell status integer (0 for success)
573 static int rpc_user_add(int argc
, const char **argv
)
575 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_add_internals
,
580 * Delete a user from a remote RPC server
582 * All parameters are provided by the run_rpc_command function, except for
583 * argc, argv which are passes through.
585 * @param domain_sid The domain sid acquired from the remote server
586 * @param cli A cli_state connected to the server.
587 * @param mem_ctx Talloc context, destoyed on completion of the function.
588 * @param argc Standard main() style argc
589 * @param argv Standard main() style argv. Initial components are already
592 * @return Normal NTSTATUS return.
595 static NTSTATUS
rpc_user_del_internals(const DOM_SID
*domain_sid
,
596 struct cli_state
*cli
,
598 int argc
, const char **argv
)
600 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
601 POLICY_HND connect_pol
, domain_pol
, user_pol
;
604 d_printf("User must be specified\n");
605 rpc_user_usage(argc
, argv
);
608 /* Get sam policy and domain handles */
610 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
613 if (!NT_STATUS_IS_OK(result
)) {
617 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
618 MAXIMUM_ALLOWED_ACCESS
,
619 domain_sid
, &domain_pol
);
621 if (!NT_STATUS_IS_OK(result
)) {
625 /* Get handle on user */
628 uint32
*user_rids
, num_rids
, *name_types
;
629 uint32 flags
= 0x000003e8; /* Unknown */
631 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
633 &num_rids
, &user_rids
,
636 if (!NT_STATUS_IS_OK(result
)) {
640 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
641 MAXIMUM_ALLOWED_ACCESS
,
642 user_rids
[0], &user_pol
);
644 if (!NT_STATUS_IS_OK(result
)) {
651 result
= cli_samr_delete_dom_user(cli
, mem_ctx
, &user_pol
);
653 if (!NT_STATUS_IS_OK(result
)) {
657 /* Display results */
665 * Delete a user from a remote RPC server
667 * @param argc Standard main() style argc
668 * @param argv Standard main() style argv. Initial components are already
671 * @return A shell status integer (0 for success)
674 static int rpc_user_delete(int argc
, const char **argv
)
676 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_del_internals
,
681 * Set a password for a user on a remote RPC server
683 * All parameters are provided by the run_rpc_command function, except for
684 * argc, argv which are passes through.
686 * @param domain_sid The domain sid acquired from the remote server
687 * @param cli A cli_state connected to the server.
688 * @param mem_ctx Talloc context, destoyed on completion of the function.
689 * @param argc Standard main() style argc
690 * @param argv Standard main() style argv. Initial components are already
693 * @return Normal NTSTATUS return.
696 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
697 struct cli_state
*cli
,
699 int argc
, const char **argv
)
701 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
702 POLICY_HND connect_pol
, domain_pol
, user_pol
;
703 SAM_USERINFO_CTR ctr
;
704 SAM_USER_INFO_24 p24
;
707 const char *new_password
;
711 d_printf("User must be specified\n");
712 rpc_user_usage(argc
, argv
);
719 new_password
= argv
[1];
721 asprintf(&prompt
, "Enter new password for %s:", user
);
722 new_password
= getpass(prompt
);
726 /* Get sam policy and domain handles */
728 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
731 if (!NT_STATUS_IS_OK(result
)) {
735 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
736 MAXIMUM_ALLOWED_ACCESS
,
737 domain_sid
, &domain_pol
);
739 if (!NT_STATUS_IS_OK(result
)) {
743 /* Get handle on user */
746 uint32
*user_rids
, num_rids
, *name_types
;
747 uint32 flags
= 0x000003e8; /* Unknown */
749 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
751 &num_rids
, &user_rids
,
754 if (!NT_STATUS_IS_OK(result
)) {
758 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
759 MAXIMUM_ALLOWED_ACCESS
,
760 user_rids
[0], &user_pol
);
762 if (!NT_STATUS_IS_OK(result
)) {
767 /* Set password on account */
772 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
774 init_sam_user_info24(&p24
, (char *)pwbuf
,24);
776 ctr
.switch_value
= 24;
777 ctr
.info
.id24
= &p24
;
779 result
= cli_samr_set_userinfo(cli
, mem_ctx
, &user_pol
, 24,
780 &cli
->user_session_key
, &ctr
);
782 if (!NT_STATUS_IS_OK(result
)) {
786 /* Display results */
794 * Set a user's password on a remote RPC server
796 * @param argc Standard main() style argc
797 * @param argv Standard main() style argv. Initial components are already
800 * @return A shell status integer (0 for success)
803 static int rpc_user_password(int argc
, const char **argv
)
805 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
810 * List user's groups on a remote RPC server
812 * All parameters are provided by the run_rpc_command function, except for
813 * argc, argv which are passes through.
815 * @param domain_sid The domain sid acquired from the remote server
816 * @param cli A cli_state connected to the server.
817 * @param mem_ctx Talloc context, destoyed on completion of the function.
818 * @param argc Standard main() style argc
819 * @param argv Standard main() style argv. Initial components are already
822 * @return Normal NTSTATUS return.
826 rpc_user_info_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
827 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
829 POLICY_HND connect_pol
, domain_pol
, user_pol
;
830 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
831 uint32
*rids
, num_rids
, *name_types
, num_names
;
832 uint32 flags
= 0x000003e8; /* Unknown */
838 d_printf("User must be specified\n");
839 rpc_user_usage(argc
, argv
);
842 /* Get sam policy handle */
844 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
846 if (!NT_STATUS_IS_OK(result
)) goto done
;
848 /* Get domain policy handle */
850 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
851 MAXIMUM_ALLOWED_ACCESS
,
852 domain_sid
, &domain_pol
);
853 if (!NT_STATUS_IS_OK(result
)) goto done
;
855 /* Get handle on user */
857 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
859 &num_rids
, &rids
, &name_types
);
861 if (!NT_STATUS_IS_OK(result
)) goto done
;
863 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
864 MAXIMUM_ALLOWED_ACCESS
,
866 if (!NT_STATUS_IS_OK(result
)) goto done
;
868 result
= cli_samr_query_usergroups(cli
, mem_ctx
, &user_pol
,
869 &num_rids
, &user_gids
);
873 rids
= (uint32
*)talloc(mem_ctx
, sizeof(uint32
) * num_rids
);
875 for (i
= 0; i
< num_rids
; i
++)
876 rids
[i
] = user_gids
[i
].g_rid
;
878 result
= cli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
,
879 flags
, num_rids
, rids
,
880 &num_names
, &names
, &name_types
);
882 if (!NT_STATUS_IS_OK(result
)) {
886 /* Display results */
888 for (i
= 0; i
< num_names
; i
++)
889 printf("%s\n", names
[i
]);
896 * List a user's groups from a remote RPC server
898 * @param argc Standard main() style argc
899 * @param argv Standard main() style argv. Initial components are already
902 * @return A shell status integer (0 for success)
905 static int rpc_user_info(int argc
, const char **argv
)
907 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
912 * List users on a remote RPC server
914 * All parameters are provided by the run_rpc_command function, except for
915 * argc, argv which are passes through.
917 * @param domain_sid The domain sid acquired from the remote server
918 * @param cli A cli_state connected to the server.
919 * @param mem_ctx Talloc context, destoyed on completion of the function.
920 * @param argc Standard main() style argc
921 * @param argv Standard main() style argv. Initial components are already
924 * @return Normal NTSTATUS return.
928 rpc_user_list_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
929 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
931 POLICY_HND connect_pol
, domain_pol
;
932 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
933 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
934 SAM_DISPINFO_CTR ctr
;
935 SAM_DISPINFO_1 info1
;
937 /* Get sam policy handle */
939 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
941 if (!NT_STATUS_IS_OK(result
)) {
945 /* Get domain policy handle */
947 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
948 MAXIMUM_ALLOWED_ACCESS
,
949 domain_sid
, &domain_pol
);
950 if (!NT_STATUS_IS_OK(result
)) {
954 /* Query domain users */
957 ctr
.sam
.info1
= &info1
;
958 if (opt_long_list_entries
)
959 d_printf("\nUser name Comment"\
960 "\n-----------------------------\n");
963 uint32 max_entries
, max_size
;
965 get_query_dispinfo_params(
966 loop_count
, &max_entries
, &max_size
);
968 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
969 &start_idx
, 1, &num_entries
,
970 max_entries
, max_size
, &ctr
);
973 for (i
= 0; i
< num_entries
; i
++) {
974 unistr2_to_ascii(user
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_name
, sizeof(user
)-1);
975 if (opt_long_list_entries
)
976 unistr2_to_ascii(desc
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_desc
, sizeof(desc
)-1);
978 if (opt_long_list_entries
)
979 printf("%-21.21s %s\n", user
, desc
);
981 printf("%s\n", user
);
983 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
990 * 'net rpc user' entrypoint.
991 * @param argc Standard main() style argc
992 * @param argc Standard main() style argv. Initial components are already
996 int net_rpc_user(int argc
, const char **argv
)
998 struct functable func
[] = {
999 {"add", rpc_user_add
},
1000 {"info", rpc_user_info
},
1001 {"delete", rpc_user_delete
},
1002 {"password", rpc_user_password
},
1007 if (opt_long_list_entries
) {
1010 return run_rpc_command(NULL
,PI_SAMR
, 0,
1011 rpc_user_list_internals
,
1015 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1019 /****************************************************************************/
1022 * Basic usage function for 'net rpc group'
1023 * @param argc Standard main() style argc.
1024 * @param argv Standard main() style argv. Initial components are already
1028 static int rpc_group_usage(int argc
, const char **argv
)
1030 return net_help_group(argc
, argv
);
1034 * List groups on a remote RPC server
1036 * All parameters are provided by the run_rpc_command function, except for
1037 * argc, argv which are passes through.
1039 * @param domain_sid The domain sid acquired from the remote server
1040 * @param cli A cli_state connected to the server.
1041 * @param mem_ctx Talloc context, destoyed on completion of the function.
1042 * @param argc Standard main() style argc
1043 * @param argv Standard main() style argv. Initial components are already
1046 * @return Normal NTSTATUS return.
1050 rpc_group_list_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1051 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1053 POLICY_HND connect_pol
, domain_pol
;
1054 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1055 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
1056 struct acct_info
*groups
;
1057 DOM_SID global_sid_Builtin
;
1058 BOOL global
= False
;
1060 BOOL builtin
= False
;
1068 for (i
=0; i
<argc
; i
++) {
1069 if (strequal(argv
[i
], "global"))
1072 if (strequal(argv
[i
], "local"))
1075 if (strequal(argv
[i
], "builtin"))
1079 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
1081 /* Get sam policy handle */
1083 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1085 if (!NT_STATUS_IS_OK(result
)) {
1089 /* Get domain policy handle */
1091 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1092 MAXIMUM_ALLOWED_ACCESS
,
1093 domain_sid
, &domain_pol
);
1094 if (!NT_STATUS_IS_OK(result
)) {
1098 /* Query domain groups */
1099 if (opt_long_list_entries
)
1100 d_printf("\nGroup name Comment"\
1101 "\n-----------------------------\n");
1103 SAM_DISPINFO_CTR ctr
;
1104 SAM_DISPINFO_3 info3
;
1109 ctr
.sam
.info3
= &info3
;
1113 get_query_dispinfo_params(
1114 loop_count
, &max_entries
, &max_size
);
1116 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
1117 &start_idx
, 3, &num_entries
,
1118 max_entries
, max_size
, &ctr
);
1120 for (i
= 0; i
< num_entries
; i
++) {
1122 fstring group
, desc
;
1124 unistr2_to_ascii(group
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_name
, sizeof(group
)-1);
1125 unistr2_to_ascii(desc
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_desc
, sizeof(desc
)-1);
1127 if (opt_long_list_entries
)
1128 printf("%-21.21s %-50.50s\n",
1131 printf("%s\n", group
);
1133 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1134 /* query domain aliases */
1139 result
= cli_samr_enum_als_groups(cli
, mem_ctx
, &domain_pol
,
1140 &start_idx
, max_entries
,
1141 &groups
, &num_entries
);
1143 for (i
= 0; i
< num_entries
; i
++) {
1145 char *description
= NULL
;
1147 if (opt_long_list_entries
) {
1149 POLICY_HND alias_pol
;
1152 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli
, mem_ctx
,
1157 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli
, mem_ctx
,
1160 (NT_STATUS_IS_OK(cli_samr_close(cli
, mem_ctx
,
1162 description
= unistr2_tdup(mem_ctx
,
1163 &ctr
.alias
.info3
.uni_acct_desc
);
1167 if (description
!= NULL
) {
1168 printf("%-21.21s %-50.50s\n",
1169 groups
[i
].acct_name
,
1172 printf("%s\n", groups
[i
].acct_name
);
1175 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1176 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
1177 /* Get builtin policy handle */
1179 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1180 MAXIMUM_ALLOWED_ACCESS
,
1181 &global_sid_Builtin
, &domain_pol
);
1182 if (!NT_STATUS_IS_OK(result
)) {
1185 /* query builtin aliases */
1188 if (!builtin
) break;
1190 result
= cli_samr_enum_als_groups(cli
, mem_ctx
, &domain_pol
,
1191 &start_idx
, max_entries
,
1192 &groups
, &num_entries
);
1194 for (i
= 0; i
< num_entries
; i
++) {
1196 char *description
= NULL
;
1198 if (opt_long_list_entries
) {
1200 POLICY_HND alias_pol
;
1203 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli
, mem_ctx
,
1208 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli
, mem_ctx
,
1211 (NT_STATUS_IS_OK(cli_samr_close(cli
, mem_ctx
,
1213 description
= unistr2_tdup(mem_ctx
,
1214 &ctr
.alias
.info3
.uni_acct_desc
);
1218 if (description
!= NULL
) {
1219 printf("%-21.21s %-50.50s\n",
1220 groups
[i
].acct_name
,
1223 printf("%s\n", groups
[i
].acct_name
);
1226 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1232 static int rpc_group_list(int argc
, const char **argv
)
1234 return run_rpc_command(NULL
, PI_SAMR
, 0,
1235 rpc_group_list_internals
,
1240 rpc_group_members_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1241 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1244 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1245 uint32 num_rids
, *rids
, *rid_types
;
1246 uint32 num_members
, *group_rids
, *group_attrs
;
1252 /* Get sam policy handle */
1254 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1256 if (!NT_STATUS_IS_OK(result
)) {
1260 /* Get domain policy handle */
1262 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1263 MAXIMUM_ALLOWED_ACCESS
,
1264 domain_sid
, &domain_pol
);
1265 if (!NT_STATUS_IS_OK(result
)) {
1269 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
1270 1, argv
, &num_rids
, &rids
, &rid_types
);
1272 if (!NT_STATUS_IS_OK(result
)) {
1276 if (num_rids
!= 1) {
1277 d_printf("Could not find group %s\n", argv
[0]);
1281 if (rid_types
[0] != SID_NAME_DOM_GRP
) {
1282 d_printf("%s is not a domain group\n", argv
[0]);
1286 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
1287 MAXIMUM_ALLOWED_ACCESS
,
1288 rids
[0], &group_pol
);
1290 if (!NT_STATUS_IS_OK(result
))
1293 result
= cli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
1294 &num_members
, &group_rids
,
1297 if (!NT_STATUS_IS_OK(result
))
1300 while (num_members
> 0) {
1301 int this_time
= 512;
1303 if (num_members
< this_time
)
1304 this_time
= num_members
;
1306 result
= cli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
, 1000,
1307 this_time
, group_rids
,
1308 &num_names
, &names
, &name_types
);
1310 if (!NT_STATUS_IS_OK(result
))
1313 for (i
= 0; i
< this_time
; i
++) {
1314 printf("%s\n", names
[i
]);
1317 num_members
-= this_time
;
1325 static int rpc_group_members(int argc
, const char **argv
)
1328 return rpc_group_usage(argc
, argv
);
1331 return run_rpc_command(NULL
, PI_SAMR
, 0,
1332 rpc_group_members_internals
,
1337 * 'net rpc group' entrypoint.
1338 * @param argc Standard main() style argc
1339 * @param argc Standard main() style argv. Initial components are already
1343 int net_rpc_group(int argc
, const char **argv
)
1345 struct functable func
[] = {
1347 {"add", rpc_group_add
},
1348 {"delete", rpc_group_delete
},
1350 {"list", rpc_group_list
},
1351 {"members", rpc_group_members
},
1356 if (opt_long_list_entries
) {
1359 return run_rpc_command(NULL
, PI_SAMR
, 0,
1360 rpc_group_list_internals
,
1364 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
1367 /****************************************************************************/
1369 static int rpc_share_usage(int argc
, const char **argv
)
1371 return net_help_share(argc
, argv
);
1375 * Add a share on a remote RPC server
1377 * All parameters are provided by the run_rpc_command function, except for
1378 * argc, argv which are passes through.
1380 * @param domain_sid The domain sid acquired from the remote server
1381 * @param cli A cli_state connected to the server.
1382 * @param mem_ctx Talloc context, destoyed on completion of the function.
1383 * @param argc Standard main() style argc
1384 * @param argv Standard main() style argv. Initial components are already
1387 * @return Normal NTSTATUS return.
1390 rpc_share_add_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1391 TALLOC_CTX
*mem_ctx
,int argc
, const char **argv
)
1394 char *sharename
=talloc_strdup(mem_ctx
, argv
[0]);
1396 uint32 type
=0; /* only allow disk shares to be added */
1397 uint32 num_users
=0, perms
=0;
1398 char *password
=NULL
; /* don't allow a share password */
1400 path
= strchr(sharename
, '=');
1402 return NT_STATUS_UNSUCCESSFUL
;
1405 result
= cli_srvsvc_net_share_add(cli
, mem_ctx
, sharename
, type
,
1406 opt_comment
, perms
, opt_maxusers
,
1407 num_users
, path
, password
);
1408 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1411 static int rpc_share_add(int argc
, const char **argv
)
1413 if ((argc
< 1) || !strchr(argv
[0], '=')) {
1414 DEBUG(1,("Sharename or path not specified on add\n"));
1415 return rpc_share_usage(argc
, argv
);
1417 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1418 rpc_share_add_internals
,
1423 * Delete a share on a remote RPC server
1425 * All parameters are provided by the run_rpc_command function, except for
1426 * argc, argv which are passes through.
1428 * @param domain_sid The domain sid acquired from the remote server
1429 * @param cli A cli_state connected to the server.
1430 * @param mem_ctx Talloc context, destoyed on completion of the function.
1431 * @param argc Standard main() style argc
1432 * @param argv Standard main() style argv. Initial components are already
1435 * @return Normal NTSTATUS return.
1438 rpc_share_del_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1439 TALLOC_CTX
*mem_ctx
,int argc
, const char **argv
)
1443 result
= cli_srvsvc_net_share_del(cli
, mem_ctx
, argv
[0]);
1444 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1448 * Delete a share on a remote RPC server
1450 * @param domain_sid The domain sid acquired from the remote server
1451 * @param argc Standard main() style argc
1452 * @param argv Standard main() style argv. Initial components are already
1455 * @return A shell status integer (0 for success)
1457 static int rpc_share_delete(int argc
, const char **argv
)
1460 DEBUG(1,("Sharename not specified on delete\n"));
1461 return rpc_share_usage(argc
, argv
);
1463 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1464 rpc_share_del_internals
,
1469 * Formatted print of share info
1471 * @param info1 pointer to SRV_SHARE_INFO_1 to format
1474 static void display_share_info_1(SRV_SHARE_INFO_1
*info1
)
1476 fstring netname
= "", remark
= "";
1478 rpcstr_pull_unistr2_fstring(netname
, &info1
->info_1_str
.uni_netname
);
1479 rpcstr_pull_unistr2_fstring(remark
, &info1
->info_1_str
.uni_remark
);
1481 if (opt_long_list_entries
) {
1482 d_printf("%-12.12s %-8.8s %-50.50s\n",
1483 netname
, share_type
[info1
->info_1
.type
], remark
);
1485 d_printf("%-12.12s\n", netname
);
1491 * List shares on a remote RPC server
1493 * All parameters are provided by the run_rpc_command function, except for
1494 * argc, argv which are passes through.
1496 * @param domain_sid The domain sid acquired from the remote server
1497 * @param cli A cli_state connected to the server.
1498 * @param mem_ctx Talloc context, destoyed on completion of the function.
1499 * @param argc Standard main() style argc
1500 * @param argv Standard main() style argv. Initial components are already
1503 * @return Normal NTSTATUS return.
1507 rpc_share_list_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1508 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1510 SRV_SHARE_INFO_CTR ctr
;
1513 uint32 preferred_len
= 0xffffffff, i
;
1515 init_enum_hnd(&hnd
, 0);
1517 result
= cli_srvsvc_net_share_enum(
1518 cli
, mem_ctx
, 1, &ctr
, preferred_len
, &hnd
);
1520 if (!W_ERROR_IS_OK(result
))
1523 /* Display results */
1525 if (opt_long_list_entries
) {
1527 "\nEnumerating shared resources (exports) on remote server:\n\n"\
1528 "\nShare name Type Description\n"\
1529 "---------- ---- -----------\n");
1531 for (i
= 0; i
< ctr
.num_entries
; i
++)
1532 display_share_info_1(&ctr
.share
.info1
[i
]);
1534 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1538 * 'net rpc share' entrypoint.
1539 * @param argc Standard main() style argc
1540 * @param argv Standard main() style argv. Initial components are already
1544 int net_rpc_share(int argc
, const char **argv
)
1546 struct functable func
[] = {
1547 {"add", rpc_share_add
},
1548 {"delete", rpc_share_delete
},
1553 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1554 rpc_share_list_internals
,
1557 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
1560 /****************************************************************************/
1562 static int rpc_file_usage(int argc
, const char **argv
)
1564 return net_help_file(argc
, argv
);
1568 * Close a file on a remote RPC server
1570 * All parameters are provided by the run_rpc_command function, except for
1571 * argc, argv which are passes through.
1573 * @param domain_sid The domain sid acquired from the remote server
1574 * @param cli A cli_state connected to the server.
1575 * @param mem_ctx Talloc context, destoyed on completion of the function.
1576 * @param argc Standard main() style argc
1577 * @param argv Standard main() style argv. Initial components are already
1580 * @return Normal NTSTATUS return.
1583 rpc_file_close_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1584 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1587 result
= cli_srvsvc_net_file_close(cli
, mem_ctx
, atoi(argv
[0]));
1588 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1592 * Close a file on a remote RPC server
1594 * @param argc Standard main() style argc
1595 * @param argv Standard main() style argv. Initial components are already
1598 * @return A shell status integer (0 for success)
1600 static int rpc_file_close(int argc
, const char **argv
)
1603 DEBUG(1, ("No fileid given on close\n"));
1604 return(rpc_file_usage(argc
, argv
));
1607 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1608 rpc_file_close_internals
,
1613 * Formatted print of open file info
1615 * @param info3 FILE_INFO_3 contents
1616 * @param str3 strings for FILE_INFO_3
1619 static void display_file_info_3(FILE_INFO_3
*info3
, FILE_INFO_3_STR
*str3
)
1621 fstring user
= "", path
= "";
1623 rpcstr_pull_unistr2_fstring(user
, &str3
->uni_user_name
);
1624 rpcstr_pull_unistr2_fstring(path
, &str3
->uni_path_name
);
1626 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
1627 info3
->id
, user
, info3
->perms
, info3
->num_locks
, path
);
1631 * List open files on a remote RPC server
1633 * All parameters are provided by the run_rpc_command function, except for
1634 * argc, argv which are passes through.
1636 * @param domain_sid The domain sid acquired from the remote server
1637 * @param cli A cli_state connected to the server.
1638 * @param mem_ctx Talloc context, destoyed on completion of the function.
1639 * @param argc Standard main() style argc
1640 * @param argv Standard main() style argv. Initial components are already
1643 * @return Normal NTSTATUS return.
1647 rpc_file_list_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
,
1648 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1650 SRV_FILE_INFO_CTR ctr
;
1653 uint32 preferred_len
= 0xffffffff, i
;
1654 const char *username
=NULL
;
1656 init_enum_hnd(&hnd
, 0);
1658 /* if argc > 0, must be user command */
1660 username
= smb_xstrdup(argv
[0]);
1662 result
= cli_srvsvc_net_file_enum(
1663 cli
, mem_ctx
, 3, username
, &ctr
, preferred_len
, &hnd
);
1665 if (!W_ERROR_IS_OK(result
))
1668 /* Display results */
1671 "\nEnumerating open files on remote server:\n\n"\
1672 "\nFileId Opened by Perms Locks Path"\
1673 "\n------ --------- ----- ----- ---- \n");
1674 for (i
= 0; i
< ctr
.num_entries
; i
++)
1675 display_file_info_3(&ctr
.file
.info3
[i
].info_3
,
1676 &ctr
.file
.info3
[i
].info_3_str
);
1678 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1683 * List files for a user on a remote RPC server
1685 * @param argc Standard main() style argc
1686 * @param argv Standard main() style argv. Initial components are already
1689 * @return A shell status integer (0 for success)
1691 static int rpc_file_user(int argc
, const char **argv
)
1694 DEBUG(1, ("No username given\n"));
1695 return(rpc_file_usage(argc
, argv
));
1698 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1699 rpc_file_list_internals
,
1705 * 'net rpc file' entrypoint.
1706 * @param argc Standard main() style argc
1707 * @param argv Standard main() style argv. Initial components are already
1711 int net_rpc_file(int argc
, const char **argv
)
1713 struct functable func
[] = {
1714 {"close", rpc_file_close
},
1715 {"user", rpc_file_user
},
1717 {"info", rpc_file_info
},
1723 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
1724 rpc_file_list_internals
,
1727 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
1730 /****************************************************************************/
1735 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
1737 * All parameters are provided by the run_rpc_command function, except for
1738 * argc, argv which are passed through.
1740 * @param domain_sid The domain sid aquired from the remote server
1741 * @param cli A cli_state connected to the server.
1742 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1743 * @param argc Standard main() style argc
1744 * @param argv Standard main() style argv. Initial components are already
1747 * @return Normal NTSTATUS return.
1750 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
1751 struct cli_state
*cli
,
1752 TALLOC_CTX
*mem_ctx
,
1753 int argc
, const char **argv
)
1755 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1757 result
= cli_shutdown_abort(cli
, mem_ctx
);
1759 if (NT_STATUS_IS_OK(result
))
1760 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
1762 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
1769 * ABORT the shutdown of a remote RPC Server, over winreg pipe
1771 * All parameters are provided by the run_rpc_command function, except for
1772 * argc, argv which are passed through.
1774 * @param domain_sid The domain sid aquired from the remote server
1775 * @param cli A cli_state connected to the server.
1776 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1777 * @param argc Standard main() style argc
1778 * @param argv Standard main() style argv. Initial components are already
1781 * @return Normal NTSTATUS return.
1784 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
1785 struct cli_state
*cli
,
1786 TALLOC_CTX
*mem_ctx
,
1787 int argc
, const char **argv
)
1789 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1791 result
= cli_reg_abort_shutdown(cli
, mem_ctx
);
1793 if (NT_STATUS_IS_OK(result
))
1794 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
1796 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
1802 * ABORT the Shut down of a remote RPC server
1804 * @param argc Standard main() style argc
1805 * @param argv Standard main() style argv. Initial components are already
1808 * @return A shell status integer (0 for success)
1811 static int rpc_shutdown_abort(int argc
, const char **argv
)
1813 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
1814 rpc_shutdown_abort_internals
,
1820 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
1822 return run_rpc_command(NULL
, PI_WINREG
, 0,
1823 rpc_reg_shutdown_abort_internals
,
1828 * Shut down a remote RPC Server
1830 * All parameters are provided by the run_rpc_command function, except for
1831 * argc, argv which are passes through.
1833 * @param domain_sid The domain sid aquired from the remote server
1834 * @param cli A cli_state connected to the server.
1835 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1836 * @param argc Standard main() style argc
1837 * @param argc Standard main() style argv. Initial components are already
1840 * @return Normal NTSTATUS return.
1843 static NTSTATUS
rpc_shutdown_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1844 int argc
, const char **argv
)
1846 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1847 const char *msg
= "This machine will be shutdown shortly";
1848 uint32 timeout
= 20;
1853 struct poptOption long_options
[] = {
1854 {"message", 'm', POPT_ARG_STRING
, &msg
},
1855 {"timeout", 't', POPT_ARG_INT
, &timeout
},
1856 {"reboot", 'r', POPT_ARG_NONE
, &reboot
},
1857 {"force", 'f', POPT_ARG_NONE
, &force
},
1861 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
1862 POPT_CONTEXT_KEEP_FIRST
);
1864 rc
= poptGetNextOpt(pc
);
1867 /* an error occurred during option processing */
1868 DEBUG(0, ("%s: %s\n",
1869 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
1871 return NT_STATUS_INVALID_PARAMETER
;
1878 timeout
= opt_timeout
;
1881 /* create an entry */
1882 result
= cli_reg_shutdown(cli
, mem_ctx
, msg
, timeout
, opt_reboot
, opt_force
);
1884 if (NT_STATUS_IS_OK(result
))
1885 DEBUG(5,("Shutdown of remote machine succeeded\n"));
1887 DEBUG(0,("Shutdown of remote machine failed!\n"));
1893 * Shut down a remote RPC server
1895 * @param argc Standard main() style argc
1896 * @param argc Standard main() style argv. Initial components are already
1899 * @return A shell status integer (0 for success)
1902 static int rpc_shutdown(int argc
, const char **argv
)
1904 return run_rpc_command(NULL
, PI_WINREG
, 0, rpc_shutdown_internals
,
1908 /***************************************************************************
1909 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
1911 ***************************************************************************/
1914 * Add interdomain trust account to the RPC server.
1915 * All parameters (except for argc and argv) are passed by run_rpc_command
1918 * @param domain_sid The domain sid acquired from the server
1919 * @param cli A cli_state connected to the server.
1920 * @param mem_ctx Talloc context, destoyed on completion of the function.
1921 * @param argc Standard main() style argc
1922 * @param argc Standard main() style argv. Initial components are already
1925 * @return normal NTSTATUS return code
1928 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
, struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1929 int argc
, const char **argv
) {
1931 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1932 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1935 uint32 unknown
, user_rid
;
1938 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
1939 return NT_STATUS_INVALID_PARAMETER
;
1943 * Make valid trusting domain account (ie. uppercased and with '$' appended)
1946 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
1947 return NT_STATUS_NO_MEMORY
;
1950 strupper_m(acct_name
);
1952 /* Get samr policy handle */
1953 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1955 if (!NT_STATUS_IS_OK(result
)) {
1959 /* Get domain policy handle */
1960 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1961 MAXIMUM_ALLOWED_ACCESS
,
1962 domain_sid
, &domain_pol
);
1963 if (!NT_STATUS_IS_OK(result
)) {
1967 /* Create trusting domain's account */
1968 acb_info
= ACB_DOMTRUST
;
1969 unknown
= 0xe00500b0; /* No idea what this is - a permission mask?
1970 mimir: yes, most probably it is */
1972 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
1973 acct_name
, acb_info
, unknown
,
1974 &user_pol
, &user_rid
);
1975 if (!NT_STATUS_IS_OK(result
)) {
1980 SAM_USERINFO_CTR ctr
;
1981 SAM_USER_INFO_24 p24
;
1984 encode_pw_buffer((char *)pwbuf
, argv
[1], STR_UNICODE
);
1989 init_sam_user_info24(&p24
, (char *)pwbuf
, 24);
1991 ctr
.switch_value
= 24;
1992 ctr
.info
.id24
= &p24
;
1994 result
= cli_samr_set_userinfo(cli
, mem_ctx
, &user_pol
, 24,
1995 &cli
->user_session_key
, &ctr
);
1997 if (!NT_STATUS_IS_OK(result
)) {
1998 DEBUG(0,("Could not set trust account password: %s\n",
1999 nt_errstr(result
)));
2005 SAFE_FREE(acct_name
);
2010 * Create interdomain trust account for a remote domain.
2012 * @param argc standard argc
2013 * @param argv standard argv without initial components
2015 * @return Integer status (0 means success)
2018 static int rpc_trustdom_add(int argc
, const char **argv
)
2021 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
2024 d_printf("Usage: net rpc trustdom add <domain>\n");
2031 * Delete interdomain trust account for a remote domain.
2033 * @param argc standard argc
2034 * @param argv standard argv without initial components
2036 * @return Integer status (0 means success)
2039 static int rpc_trustdom_del(int argc
, const char **argv
)
2041 d_printf("Sorry, not yet implemented.\n");
2042 d_printf("Use 'smbpasswd -x -i' instead.\n");
2048 * Establish trust relationship to a trusting domain.
2049 * Interdomain account must already be created on remote PDC.
2051 * @param argc standard argc
2052 * @param argv standard argv without initial components
2054 * @return Integer status (0 means success)
2057 static int rpc_trustdom_establish(int argc
, const char **argv
)
2059 struct cli_state
*cli
;
2060 struct in_addr server_ip
;
2061 POLICY_HND connect_hnd
;
2062 TALLOC_CTX
*mem_ctx
;
2064 DOM_SID
*domain_sid
;
2065 WKS_INFO_100 wks_info
;
2068 char* domain_name_pol
;
2073 * Connect to \\server\ipc$ as 'our domain' account with password
2077 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
2081 domain_name
= smb_xstrdup(argv
[0]);
2082 strupper_m(domain_name
);
2084 /* account name used at first is our domain's name with '$' */
2085 asprintf(&acct_name
, "%s$", lp_workgroup());
2086 strupper_m(acct_name
);
2089 * opt_workgroup will be used by connection functions further,
2090 * hence it should be set to remote domain name instead of ours
2092 if (opt_workgroup
) {
2093 opt_workgroup
= smb_xstrdup(domain_name
);
2096 opt_user_name
= acct_name
;
2098 /* find the domain controller */
2099 if (!net_find_pdc(&server_ip
, pdc_name
, domain_name
)) {
2100 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
2104 /* connect to ipc$ as username/password */
2105 nt_status
= connect_to_ipc(&cli
, &server_ip
, pdc_name
);
2106 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
2108 /* Is it trusting domain account for sure ? */
2109 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
2110 nt_errstr(nt_status
)));
2115 * Connect to \\server\ipc$ again (this time anonymously)
2118 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ip
, (char*)pdc_name
);
2120 if (NT_STATUS_IS_ERR(nt_status
)) {
2121 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
2122 domain_name
, nt_errstr(nt_status
)));
2126 * Use NetServerEnum2 to make sure we're talking to a proper server
2129 if (!cli_get_pdc_name(cli
, domain_name
, (char*)pdc_name
)) {
2130 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
2131 for domain %s\n", domain_name
));
2135 * Call WksQueryInfo to check remote server's capabilities
2136 * note: It is now used only to get unicode domain name
2139 if (!cli_nt_session_open(cli
, PI_WKSSVC
)) {
2140 DEBUG(0, ("Couldn't not initialise wkssvc pipe\n"));
2144 if (!(mem_ctx
= talloc_init("establishing trust relationship to domain %s",
2146 DEBUG(0, ("talloc_init() failed\n"));
2151 nt_status
= cli_wks_query_info(cli
, mem_ctx
, &wks_info
);
2153 if (NT_STATUS_IS_ERR(nt_status
)) {
2154 DEBUG(0, ("WksQueryInfo call failed.\n"));
2158 if (cli
->nt_pipe_fnum
)
2159 cli_nt_session_close(cli
);
2163 * Call LsaOpenPolicy and LsaQueryInfo
2166 if (!(mem_ctx
= talloc_init("rpc_trustdom_establish"))) {
2167 DEBUG(0, ("talloc_init() failed\n"));
2172 if (!cli_nt_session_open(cli
, PI_LSARPC
)) {
2173 DEBUG(0, ("Could not initialise lsa pipe\n"));
2178 nt_status
= cli_lsa_open_policy2(cli
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
2180 if (NT_STATUS_IS_ERR(nt_status
)) {
2181 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
2182 nt_errstr(nt_status
)));
2186 /* Querying info level 5 */
2188 nt_status
= cli_lsa_query_info_policy(cli
, mem_ctx
, &connect_hnd
,
2189 5 /* info level */, &domain_name_pol
,
2191 if (NT_STATUS_IS_ERR(nt_status
)) {
2192 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
2193 nt_errstr(nt_status
)));
2200 /* There should be actually query info level 3 (following nt serv behaviour),
2201 but I still don't know if it's _really_ necessary */
2204 * Store the password in secrets db
2207 if (!secrets_store_trusted_domain_password(domain_name
, wks_info
.uni_lan_grp
.buffer
,
2208 wks_info
.uni_lan_grp
.uni_str_len
, opt_password
,
2210 DEBUG(0, ("Storing password for trusted domain failed.\n"));
2215 * Close the pipes and clean up
2218 nt_status
= cli_lsa_close(cli
, mem_ctx
, &connect_hnd
);
2219 if (NT_STATUS_IS_ERR(nt_status
)) {
2220 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
2221 nt_errstr(nt_status
)));
2225 if (cli
->nt_pipe_fnum
)
2226 cli_nt_session_close(cli
);
2228 talloc_destroy(mem_ctx
);
2230 DEBUG(0, ("Success!\n"));
2235 * Revoke trust relationship to the remote domain
2237 * @param argc standard argc
2238 * @param argv standard argv without initial components
2240 * @return Integer status (0 means success)
2243 static int rpc_trustdom_revoke(int argc
, const char **argv
)
2247 if (argc
< 1) return -1;
2249 /* generate upper cased domain name */
2250 domain_name
= smb_xstrdup(argv
[0]);
2251 strupper_m(domain_name
);
2253 /* delete password of the trust */
2254 if (!trusted_domain_password_delete(domain_name
)) {
2255 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
2264 * Usage for 'net rpc trustdom' command
2266 * @param argc standard argc
2267 * @param argv standard argv without inital components
2269 * @return Integer status returned to shell
2272 static int rpc_trustdom_usage(int argc
, const char **argv
)
2274 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
2275 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
2276 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
2277 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
2278 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
2283 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
, struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2284 int argc
, const char **argv
)
2287 sid_to_string(str_sid
, domain_sid
);
2288 d_printf("%s\n", str_sid
);
2289 return NT_STATUS_OK
;
2293 static int rpc_trustdom_list(int argc
, const char **argv
)
2295 /* common variables */
2296 TALLOC_CTX
* mem_ctx
;
2297 struct cli_state
*cli
, *remote_cli
;
2299 const char *domain_name
= NULL
;
2300 DOM_SID
*queried_dom_sid
;
2301 fstring ascii_sid
, padding
;
2302 int ascii_dom_name_len
;
2303 POLICY_HND connect_hnd
;
2305 /* trusted domains listing variables */
2306 unsigned int num_domains
, enum_ctx
= 0;
2307 int i
, pad_len
, col_len
= 20;
2308 DOM_SID
*domain_sids
;
2309 char **trusted_dom_names
;
2313 /* trusting domains listing variables */
2314 POLICY_HND domain_hnd
;
2315 char **trusting_dom_names
;
2316 uint32
*trusting_dom_rids
;
2319 * Listing trusted domains (stored in secrets.tdb, if local)
2322 mem_ctx
= talloc_init("trust relationships listing");
2325 * set domain and pdc name to local samba server (default)
2326 * or to remote one given in command line
2329 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
2330 domain_name
= opt_workgroup
;
2331 opt_target_workgroup
= opt_workgroup
;
2333 fstrcpy(pdc_name
, global_myname());
2334 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
2335 opt_target_workgroup
= domain_name
;
2338 /* open \PIPE\lsarpc and open policy handle */
2339 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
2340 DEBUG(0, ("Couldn't connect to domain controller\n"));
2344 if (!cli_nt_session_open(cli
, PI_LSARPC
)) {
2345 DEBUG(0, ("Could not initialise lsa pipe\n"));
2349 nt_status
= cli_lsa_open_policy2(cli
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
2351 if (NT_STATUS_IS_ERR(nt_status
)) {
2352 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
2353 nt_errstr(nt_status
)));
2357 /* query info level 5 to obtain sid of a domain being queried */
2358 nt_status
= cli_lsa_query_info_policy(
2359 cli
, mem_ctx
, &connect_hnd
, 5 /* info level */,
2360 &dummy
, &queried_dom_sid
);
2362 if (NT_STATUS_IS_ERR(nt_status
)) {
2363 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
2364 nt_errstr(nt_status
)));
2369 * Keep calling LsaEnumTrustdom over opened pipe until
2370 * the end of enumeration is reached
2373 d_printf("Trusted domains list:\n\n");
2376 nt_status
= cli_lsa_enum_trust_dom(cli
, mem_ctx
, &connect_hnd
, &enum_ctx
,
2378 &trusted_dom_names
, &domain_sids
);
2380 if (NT_STATUS_IS_ERR(nt_status
)) {
2381 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
2382 nt_errstr(nt_status
)));
2386 for (i
= 0; i
< num_domains
; i
++) {
2387 /* convert sid into ascii string */
2388 sid_to_string(ascii_sid
, &(domain_sids
[i
]));
2390 /* calculate padding space for d_printf to look nicer */
2391 pad_len
= col_len
- strlen(trusted_dom_names
[i
]);
2392 padding
[pad_len
] = 0;
2393 do padding
[--pad_len
] = ' '; while (pad_len
);
2395 d_printf("%s%s%s\n", trusted_dom_names
[i
], padding
, ascii_sid
);
2399 * in case of no trusted domains say something rather
2400 * than just display blank line
2402 if (!num_domains
) d_printf("none\n");
2404 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
2406 /* close this connection before doing next one */
2407 nt_status
= cli_lsa_close(cli
, mem_ctx
, &connect_hnd
);
2408 if (NT_STATUS_IS_ERR(nt_status
)) {
2409 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
2410 nt_errstr(nt_status
)));
2414 cli_nt_session_close(cli
);
2417 * Listing trusting domains (stored in passdb backend, if local)
2420 d_printf("\nTrusting domains list:\n\n");
2423 * Open \PIPE\samr and get needed policy handles
2425 if (!cli_nt_session_open(cli
, PI_SAMR
)) {
2426 DEBUG(0, ("Could not initialise samr pipe\n"));
2431 nt_status
= cli_samr_connect(cli
, mem_ctx
, SA_RIGHT_SAM_OPEN_DOMAIN
,
2433 if (!NT_STATUS_IS_OK(nt_status
)) {
2434 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
2435 nt_errstr(nt_status
)));
2439 /* SamrOpenDomain - we have to open domain policy handle in order to be
2440 able to enumerate accounts*/
2441 nt_status
= cli_samr_open_domain(cli
, mem_ctx
, &connect_hnd
,
2442 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
2443 queried_dom_sid
, &domain_hnd
);
2444 if (!NT_STATUS_IS_OK(nt_status
)) {
2445 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
2446 nt_errstr(nt_status
)));
2451 * perform actual enumeration
2454 enum_ctx
= 0; /* reset enumeration context from last enumeration */
2457 nt_status
= cli_samr_enum_dom_users(cli
, mem_ctx
, &domain_hnd
,
2458 &enum_ctx
, ACB_DOMTRUST
, 0xffff,
2459 &trusting_dom_names
, &trusting_dom_rids
,
2461 if (NT_STATUS_IS_ERR(nt_status
)) {
2462 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
2463 nt_errstr(nt_status
)));
2467 for (i
= 0; i
< num_domains
; i
++) {
2470 * get each single domain's sid (do we _really_ need this ?):
2471 * 1) connect to domain's pdc
2472 * 2) query the pdc for domain's sid
2475 /* get rid of '$' tail */
2476 ascii_dom_name_len
= strlen(trusting_dom_names
[i
]);
2477 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
2478 trusting_dom_names
[i
][ascii_dom_name_len
- 1] = '\0';
2480 /* calculate padding space for d_printf to look nicer */
2481 pad_len
= col_len
- strlen(trusting_dom_names
[i
]);
2482 padding
[pad_len
] = 0;
2483 do padding
[--pad_len
] = ' '; while (pad_len
);
2485 /* set opt_* variables to remote domain */
2486 strupper_m(trusting_dom_names
[i
]);
2487 opt_workgroup
= talloc_strdup(mem_ctx
, trusting_dom_names
[i
]);
2488 opt_target_workgroup
= opt_workgroup
;
2490 d_printf("%s%s", trusting_dom_names
[i
], padding
);
2492 /* connect to remote domain controller */
2493 remote_cli
= net_make_ipc_connection(NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
);
2495 /* query for domain's sid */
2496 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
2497 d_printf("couldn't get domain's sid\n");
2499 cli_shutdown(remote_cli
);
2502 d_printf("domain controller is not responding\n");
2506 if (!num_domains
) d_printf("none\n");
2508 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
2510 /* close opened samr and domain policy handles */
2511 nt_status
= cli_samr_close(cli
, mem_ctx
, &domain_hnd
);
2512 if (!NT_STATUS_IS_OK(nt_status
)) {
2513 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
2516 nt_status
= cli_samr_close(cli
, mem_ctx
, &connect_hnd
);
2517 if (!NT_STATUS_IS_OK(nt_status
)) {
2518 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
2521 /* close samr pipe and connection to IPC$ */
2522 cli_nt_session_close(cli
);
2525 talloc_destroy(mem_ctx
);
2530 * Entrypoint for 'net rpc trustdom' code
2532 * @param argc standard argc
2533 * @param argv standard argv without initial components
2535 * @return Integer status (0 means success)
2538 static int rpc_trustdom(int argc
, const char **argv
)
2540 struct functable func
[] = {
2541 {"add", rpc_trustdom_add
},
2542 {"del", rpc_trustdom_del
},
2543 {"establish", rpc_trustdom_establish
},
2544 {"revoke", rpc_trustdom_revoke
},
2545 {"help", rpc_trustdom_usage
},
2546 {"list", rpc_trustdom_list
},
2551 rpc_trustdom_usage(argc
, argv
);
2555 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
2559 * Check if a server will take rpc commands
2560 * @param flags Type of server to connect to (PDC, DMB, localhost)
2561 * if the host is not explicitly specified
2562 * @return BOOL (true means rpc supported)
2564 BOOL
net_rpc_check(unsigned flags
)
2566 struct cli_state cli
;
2568 struct in_addr server_ip
;
2569 char *server_name
= NULL
;
2571 /* flags (i.e. server type) may depend on command */
2572 if (!net_find_server(flags
, &server_ip
, &server_name
))
2576 if (cli_initialise(&cli
) == False
)
2579 if (!cli_connect(&cli
, server_name
, &server_ip
))
2581 if (!attempt_netbios_session_request(&cli
, global_myname(),
2582 server_name
, &server_ip
))
2584 if (!cli_negprot(&cli
))
2586 if (cli
.protocol
< PROTOCOL_NT1
)
2596 /****************************************************************************/
2600 * Basic usage function for 'net rpc'
2601 * @param argc Standard main() style argc
2602 * @param argv Standard main() style argv. Initial components are already
2606 int net_rpc_usage(int argc
, const char **argv
)
2608 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
2609 d_printf(" net rpc join \t\t\tto join a domain \n");
2610 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n\n\n");
2611 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
2612 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
2613 d_printf(" net rpc group \t\tto list groups\n");
2614 d_printf(" net rpc share \t\tto add, delete, and list shares\n");
2615 d_printf(" net rpc file \t\t\tto list open files\n");
2616 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
2617 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
2618 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
2619 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
2620 d_printf(" net rpc trustdom \t\tto create trusting domain's account\n"
2621 "\t\t\t\t\tor establish trust\n");
2622 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
2623 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
2625 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
2626 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
2627 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
2628 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
2629 d_printf("\t-c or --comment=<message>\ttext message to display on impending shutdown\n");
2635 * Help function for 'net rpc'. Calls command specific help if requested
2636 * or displays usage of net rpc
2637 * @param argc Standard main() style argc
2638 * @param argv Standard main() style argv. Initial components are already
2642 int net_rpc_help(int argc
, const char **argv
)
2644 struct functable func
[] = {
2645 {"join", rpc_join_usage
},
2646 {"user", rpc_user_usage
},
2647 {"group", rpc_group_usage
},
2648 {"share", rpc_share_usage
},
2649 /*{"changetrustpw", rpc_changetrustpw_usage}, */
2650 {"trustdom", rpc_trustdom_usage
},
2651 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
2652 /*{"shutdown", rpc_shutdown_usage}, */
2657 net_rpc_usage(argc
, argv
);
2661 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
2666 * 'net rpc' entrypoint.
2667 * @param argc Standard main() style argc
2668 * @param argv Standard main() style argv. Initial components are already
2672 int net_rpc(int argc
, const char **argv
)
2674 struct functable func
[] = {
2675 {"info", net_rpc_info
},
2676 {"join", net_rpc_join
},
2677 {"oldjoin", net_rpc_oldjoin
},
2678 {"testjoin", net_rpc_testjoin
},
2679 {"user", net_rpc_user
},
2680 {"password", rpc_user_password
},
2681 {"group", net_rpc_group
},
2682 {"share", net_rpc_share
},
2683 {"file", net_rpc_file
},
2684 {"changetrustpw", net_rpc_changetrustpw
},
2685 {"trustdom", rpc_trustdom
},
2686 {"abortshutdown", rpc_shutdown_abort
},
2687 {"shutdown", rpc_shutdown
},
2688 {"samdump", rpc_samdump
},
2689 {"vampire", rpc_vampire
},
2690 {"getsid", net_rpc_getsid
},
2691 {"help", net_rpc_help
},
2694 return net_run_function(argc
, argv
, func
, net_rpc_usage
);