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 *, const char *,
41 struct cli_state *, TALLOC_CTX *, int, const char **);
44 * Many of the RPC functions need the domain sid. This function gets
45 * it at the start of every run
47 * @param cli A cli_state already connected to the remote machine
49 * @return The Domain SID of the remote machine.
52 static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx, char **domain_name)
56 NTSTATUS result = NT_STATUS_OK;
57 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;
112 /* make use of cli_state handed over as an argument, if possible */
114 cli = net_make_ipc_connection(conn_flags);
124 if (!(mem_ctx = talloc_init("run_rpc_command"))) {
125 DEBUG(0, ("talloc_init() failed\n"));
130 domain_sid = net_get_remote_domain_sid(cli, mem_ctx, &domain_name);
132 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
133 if (!cli_nt_session_open(cli, pipe_idx)) {
134 DEBUG(0, ("Could not initialise pipe\n"));
138 nt_status = fn(domain_sid, domain_name, cli, mem_ctx, argc, argv);
140 if (!NT_STATUS_IS_OK(nt_status)) {
141 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status)));
143 DEBUG(5, ("rpc command function succedded\n"));
146 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
147 if (cli->nt_pipe_fnum)
148 cli_nt_session_close(cli);
151 /* close the connection only if it was opened here */
155 talloc_destroy(mem_ctx);
157 return (!NT_STATUS_IS_OK(nt_status));
161 /****************************************************************************/
165 * Force a change of the trust acccount password.
167 * All parameters are provided by the run_rpc_command function, except for
168 * argc, argv which are passes through.
170 * @param domain_sid The domain sid aquired from the remote server
171 * @param cli A cli_state connected to the server.
172 * @param mem_ctx Talloc context, destoyed on compleation of the function.
173 * @param argc Standard main() style argc
174 * @param argc Standard main() style argv. Initial components are already
177 * @return Normal NTSTATUS return.
180 static NTSTATUS rpc_changetrustpw_internals(const DOM_SID *domain_sid, const char *domain_name,
181 struct cli_state *cli, TALLOC_CTX *mem_ctx,
182 int argc, const char **argv) {
184 return trust_pw_find_change_and_store_it(cli, mem_ctx, opt_target_workgroup);
188 * Force a change of the trust acccount password.
190 * @param argc Standard main() style argc
191 * @param argc Standard main() style argv. Initial components are already
194 * @return A shell status integer (0 for success)
197 int net_rpc_changetrustpw(int argc, const char **argv)
199 return run_rpc_command(NULL, PI_NETLOGON, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
200 rpc_changetrustpw_internals,
205 /****************************************************************************/
209 * Join a domain, the old way.
211 * This uses 'machinename' as the inital password, and changes it.
213 * The password should be created with 'server manager' or equiv first.
215 * All parameters are provided by the run_rpc_command function, except for
216 * argc, argv which are passes through.
218 * @param domain_sid The domain sid aquired from the remote server
219 * @param cli A cli_state connected to the server.
220 * @param mem_ctx Talloc context, destoyed on compleation of the function.
221 * @param argc Standard main() style argc
222 * @param argc Standard main() style argv. Initial components are already
225 * @return Normal NTSTATUS return.
228 static NTSTATUS rpc_oldjoin_internals(const DOM_SID *domain_sid, const char *domain_name,
229 struct cli_state *cli,
231 int argc, const char **argv) {
233 fstring trust_passwd;
234 unsigned char orig_trust_passwd_hash[16];
236 uint32 sec_channel_type;
239 check what type of join - if the user want's to join as
240 a BDC, the server must agree that we are a BDC.
243 sec_channel_type = get_sec_channel_type(argv[0]);
245 sec_channel_type = get_sec_channel_type(NULL);
248 fstrcpy(trust_passwd, global_myname());
249 strlower_m(trust_passwd);
252 * Machine names can be 15 characters, but the max length on
253 * a password is 14. --jerry
256 trust_passwd[14] = '\0';
258 E_md4hash(trust_passwd, orig_trust_passwd_hash);
260 result = trust_pw_change_and_store_it(cli, mem_ctx, opt_target_workgroup,
261 orig_trust_passwd_hash,
264 if (NT_STATUS_IS_OK(result))
265 printf("Joined domain %s.\n",opt_target_workgroup);
268 if (!secrets_store_domain_sid(opt_target_workgroup, domain_sid)) {
269 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup));
270 result = NT_STATUS_UNSUCCESSFUL;
277 * Join a domain, the old way.
279 * @param argc Standard main() style argc
280 * @param argc Standard main() style argv. Initial components are already
283 * @return A shell status integer (0 for success)
286 static int net_rpc_perform_oldjoin(int argc, const char **argv)
288 return run_rpc_command(NULL, PI_NETLOGON,
289 NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
290 rpc_oldjoin_internals,
295 * Join a domain, the old way. This function exists to allow
296 * the message to be displayed when oldjoin was explicitly
297 * requested, but not when it was implied by "net rpc join"
299 * @param argc Standard main() style argc
300 * @param argc Standard main() style argv. Initial components are already
303 * @return A shell status integer (0 for success)
306 static int net_rpc_oldjoin(int argc, const char **argv)
308 int rc = net_rpc_perform_oldjoin(argc, argv);
311 d_printf("Failed to join domain\n");
318 * Basic usage function for 'net rpc join'
319 * @param argc Standard main() style argc
320 * @param argc Standard main() style argv. Initial components are already
324 static int rpc_join_usage(int argc, const char **argv)
326 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
327 "\t to join a domain with admin username & password\n"\
328 "\t\t password will be prompted if needed and none is specified\n"\
329 "\t <type> can be (default MEMBER)\n"\
330 "\t\t BDC - Join as a BDC\n"\
331 "\t\t PDC - Join as a PDC\n"\
332 "\t\t MEMBER - Join as a MEMBER server\n");
334 net_common_flags_usage(argc, argv);
339 * 'net rpc join' entrypoint.
340 * @param argc Standard main() style argc
341 * @param argc Standard main() style argv. Initial components are already
344 * Main 'net_rpc_join()' (where the admain username/password is used) is
346 * Try to just change the password, but if that doesn't work, use/prompt
347 * for a username/password.
350 int net_rpc_join(int argc, const char **argv)
352 if ((net_rpc_perform_oldjoin(argc, argv) == 0))
355 return net_rpc_join_newstyle(argc, argv);
361 * display info about a rpc domain
363 * All parameters are provided by the run_rpc_command function, except for
364 * argc, argv which are passed through.
366 * @param domain_sid The domain sid acquired from the remote server
367 * @param cli A cli_state connected to the server.
368 * @param mem_ctx Talloc context, destoyed on completion of the function.
369 * @param argc Standard main() style argc
370 * @param argv Standard main() style argv. Initial components are already
373 * @return Normal NTSTATUS return.
377 rpc_info_internals(const DOM_SID *domain_sid, const char *domain_name,
378 struct cli_state *cli,
379 TALLOC_CTX *mem_ctx, int argc, const char **argv)
381 POLICY_HND connect_pol, domain_pol;
382 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
386 sid_to_string(sid_str, domain_sid);
388 /* Get sam policy handle */
389 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
391 if (!NT_STATUS_IS_OK(result)) {
395 /* Get domain policy handle */
396 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
397 MAXIMUM_ALLOWED_ACCESS,
398 domain_sid, &domain_pol);
399 if (!NT_STATUS_IS_OK(result)) {
404 result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
406 if (NT_STATUS_IS_OK(result)) {
407 TALLOC_CTX *ctx = talloc_init("rpc_info_internals");
408 d_printf("Domain Name: %s\n", unistr2_tdup(ctx, &ctr.info.inf2.uni_domain));
409 d_printf("Domain SID: %s\n", sid_str);
410 d_printf("Sequence number: %u\n", ctr.info.inf2.seq_num);
411 d_printf("Num users: %u\n", ctr.info.inf2.num_domain_usrs);
412 d_printf("Num domain groups: %u\n", ctr.info.inf2.num_domain_grps);
413 d_printf("Num local groups: %u\n", ctr.info.inf2.num_local_grps);
423 * 'net rpc info' entrypoint.
424 * @param argc Standard main() style argc
425 * @param argc Standard main() style argv. Initial components are already
428 int net_rpc_info(int argc, const char **argv)
430 return run_rpc_command(NULL, PI_SAMR, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
437 * Fetch domain SID into the local secrets.tdb
439 * All parameters are provided by the run_rpc_command function, except for
440 * argc, argv which are passes through.
442 * @param domain_sid The domain sid acquired from the remote server
443 * @param cli A cli_state connected to the server.
444 * @param mem_ctx Talloc context, destoyed on completion of the function.
445 * @param argc Standard main() style argc
446 * @param argv Standard main() style argv. Initial components are already
449 * @return Normal NTSTATUS return.
453 rpc_getsid_internals(const DOM_SID *domain_sid, const char *domain_name,
454 struct cli_state *cli,
455 TALLOC_CTX *mem_ctx, int argc, const char **argv)
459 sid_to_string(sid_str, domain_sid);
460 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
461 sid_str, domain_name);
463 if (!secrets_store_domain_sid(domain_name, domain_sid)) {
464 DEBUG(0,("Can't store domain SID\n"));
465 return NT_STATUS_UNSUCCESSFUL;
473 * 'net rpc getsid' entrypoint.
474 * @param argc Standard main() style argc
475 * @param argc Standard main() style argv. Initial components are already
478 int net_rpc_getsid(int argc, const char **argv)
480 return run_rpc_command(NULL, PI_SAMR, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
481 rpc_getsid_internals,
486 /****************************************************************************/
489 * Basic usage function for 'net rpc user'
490 * @param argc Standard main() style argc.
491 * @param argv Standard main() style argv. Initial components are already
495 static int rpc_user_usage(int argc, const char **argv)
497 return net_help_user(argc, argv);
501 * Add a new user to a remote RPC server
503 * All parameters are provided by the run_rpc_command function, except for
504 * argc, argv which are passes through.
506 * @param domain_sid The domain sid acquired from the remote server
507 * @param cli A cli_state connected to the server.
508 * @param mem_ctx Talloc context, destoyed on completion of the function.
509 * @param argc Standard main() style argc
510 * @param argv Standard main() style argv. Initial components are already
513 * @return Normal NTSTATUS return.
516 static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid, const char *domain_name,
517 struct cli_state *cli, TALLOC_CTX *mem_ctx,
518 int argc, const char **argv) {
520 POLICY_HND connect_pol, domain_pol, user_pol;
521 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
522 const char *acct_name;
524 uint32 unknown, user_rid;
527 d_printf("User must be specified\n");
528 rpc_user_usage(argc, argv);
534 /* Get sam policy handle */
536 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
538 if (!NT_STATUS_IS_OK(result)) {
542 /* Get domain policy handle */
544 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
545 MAXIMUM_ALLOWED_ACCESS,
546 domain_sid, &domain_pol);
547 if (!NT_STATUS_IS_OK(result)) {
551 /* Create domain user */
553 acb_info = ACB_NORMAL;
554 unknown = 0xe005000b; /* No idea what this is - a permission mask? */
556 result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
557 acct_name, acb_info, unknown,
558 &user_pol, &user_rid);
559 if (!NT_STATUS_IS_OK(result)) {
564 if (!NT_STATUS_IS_OK(result)) {
565 d_printf("Failed to add user %s - %s\n", acct_name,
568 d_printf("Added user %s\n", acct_name);
574 * Add a new user to a remote RPC server
576 * @param argc Standard main() style argc
577 * @param argv Standard main() style argv. Initial components are already
580 * @return A shell status integer (0 for success)
583 static int rpc_user_add(int argc, const char **argv)
585 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_add_internals,
590 * Delete a user from a remote RPC server
592 * All parameters are provided by the run_rpc_command function, except for
593 * argc, argv which are passes through.
595 * @param domain_sid The domain sid acquired from the remote server
596 * @param cli A cli_state connected to the server.
597 * @param mem_ctx Talloc context, destoyed on completion of the function.
598 * @param argc Standard main() style argc
599 * @param argv Standard main() style argv. Initial components are already
602 * @return Normal NTSTATUS return.
605 static NTSTATUS rpc_user_del_internals(const DOM_SID *domain_sid,
606 const char *domain_name,
607 struct cli_state *cli,
609 int argc, const char **argv)
611 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
612 POLICY_HND connect_pol, domain_pol, user_pol;
615 d_printf("User must be specified\n");
616 rpc_user_usage(argc, argv);
619 /* Get sam policy and domain handles */
621 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
624 if (!NT_STATUS_IS_OK(result)) {
628 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
629 MAXIMUM_ALLOWED_ACCESS,
630 domain_sid, &domain_pol);
632 if (!NT_STATUS_IS_OK(result)) {
636 /* Get handle on user */
639 uint32 *user_rids, num_rids, *name_types;
640 uint32 flags = 0x000003e8; /* Unknown */
642 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
644 &num_rids, &user_rids,
647 if (!NT_STATUS_IS_OK(result)) {
651 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
652 MAXIMUM_ALLOWED_ACCESS,
653 user_rids[0], &user_pol);
655 if (!NT_STATUS_IS_OK(result)) {
662 result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
664 if (!NT_STATUS_IS_OK(result)) {
668 /* Display results */
676 * Delete a user from a remote RPC server
678 * @param argc Standard main() style argc
679 * @param argv Standard main() style argv. Initial components are already
682 * @return A shell status integer (0 for success)
685 static int rpc_user_delete(int argc, const char **argv)
687 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_del_internals,
692 * Set a password for a user on a remote RPC server
694 * All parameters are provided by the run_rpc_command function, except for
695 * argc, argv which are passes through.
697 * @param domain_sid The domain sid acquired from the remote server
698 * @param cli A cli_state connected to the server.
699 * @param mem_ctx Talloc context, destoyed on completion of the function.
700 * @param argc Standard main() style argc
701 * @param argv Standard main() style argv. Initial components are already
704 * @return Normal NTSTATUS return.
707 static NTSTATUS rpc_user_password_internals(const DOM_SID *domain_sid,
708 const char *domain_name,
709 struct cli_state *cli,
711 int argc, const char **argv)
713 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
714 POLICY_HND connect_pol, domain_pol, user_pol;
715 SAM_USERINFO_CTR ctr;
716 SAM_USER_INFO_24 p24;
719 const char *new_password;
723 d_printf("User must be specified\n");
724 rpc_user_usage(argc, argv);
731 new_password = argv[1];
733 asprintf(&prompt, "Enter new password for %s:", user);
734 new_password = getpass(prompt);
738 /* Get sam policy and domain handles */
740 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
743 if (!NT_STATUS_IS_OK(result)) {
747 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
748 MAXIMUM_ALLOWED_ACCESS,
749 domain_sid, &domain_pol);
751 if (!NT_STATUS_IS_OK(result)) {
755 /* Get handle on user */
758 uint32 *user_rids, num_rids, *name_types;
759 uint32 flags = 0x000003e8; /* Unknown */
761 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
763 &num_rids, &user_rids,
766 if (!NT_STATUS_IS_OK(result)) {
770 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
771 MAXIMUM_ALLOWED_ACCESS,
772 user_rids[0], &user_pol);
774 if (!NT_STATUS_IS_OK(result)) {
779 /* Set password on account */
784 encode_pw_buffer(pwbuf, new_password, STR_UNICODE);
786 init_sam_user_info24(&p24, (char *)pwbuf,24);
788 ctr.switch_value = 24;
789 ctr.info.id24 = &p24;
791 result = cli_samr_set_userinfo(cli, mem_ctx, &user_pol, 24,
792 &cli->user_session_key, &ctr);
794 if (!NT_STATUS_IS_OK(result)) {
798 /* Display results */
806 * Set a user's password on a remote RPC server
808 * @param argc Standard main() style argc
809 * @param argv Standard main() style argv. Initial components are already
812 * @return A shell status integer (0 for success)
815 static int rpc_user_password(int argc, const char **argv)
817 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_password_internals,
822 * List user's groups on a remote RPC server
824 * All parameters are provided by the run_rpc_command function, except for
825 * argc, argv which are passes through.
827 * @param domain_sid The domain sid acquired from the remote server
828 * @param cli A cli_state connected to the server.
829 * @param mem_ctx Talloc context, destoyed on completion of the function.
830 * @param argc Standard main() style argc
831 * @param argv Standard main() style argv. Initial components are already
834 * @return Normal NTSTATUS return.
838 rpc_user_info_internals(const DOM_SID *domain_sid, const char *domain_name,
839 struct cli_state *cli,
840 TALLOC_CTX *mem_ctx, int argc, const char **argv)
842 POLICY_HND connect_pol, domain_pol, user_pol;
843 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
844 uint32 *rids, num_rids, *name_types, num_names;
845 uint32 flags = 0x000003e8; /* Unknown */
851 d_printf("User must be specified\n");
852 rpc_user_usage(argc, argv);
855 /* Get sam policy handle */
857 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
859 if (!NT_STATUS_IS_OK(result)) goto done;
861 /* Get domain policy handle */
863 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
864 MAXIMUM_ALLOWED_ACCESS,
865 domain_sid, &domain_pol);
866 if (!NT_STATUS_IS_OK(result)) goto done;
868 /* Get handle on user */
870 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
872 &num_rids, &rids, &name_types);
874 if (!NT_STATUS_IS_OK(result)) goto done;
876 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
877 MAXIMUM_ALLOWED_ACCESS,
879 if (!NT_STATUS_IS_OK(result)) goto done;
881 result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
882 &num_rids, &user_gids);
886 rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
888 for (i = 0; i < num_rids; i++)
889 rids[i] = user_gids[i].g_rid;
891 result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol,
892 flags, num_rids, rids,
893 &num_names, &names, &name_types);
895 if (!NT_STATUS_IS_OK(result)) {
899 /* Display results */
901 for (i = 0; i < num_names; i++)
902 printf("%s\n", names[i]);
909 * List a user's groups from a remote RPC server
911 * @param argc Standard main() style argc
912 * @param argv Standard main() style argv. Initial components are already
915 * @return A shell status integer (0 for success)
918 static int rpc_user_info(int argc, const char **argv)
920 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_info_internals,
925 * List users on a remote RPC server
927 * All parameters are provided by the run_rpc_command function, except for
928 * argc, argv which are passes through.
930 * @param domain_sid The domain sid acquired from the remote server
931 * @param cli A cli_state connected to the server.
932 * @param mem_ctx Talloc context, destoyed on completion of the function.
933 * @param argc Standard main() style argc
934 * @param argv Standard main() style argv. Initial components are already
937 * @return Normal NTSTATUS return.
941 rpc_user_list_internals(const DOM_SID *domain_sid, const char *domain_name,
942 struct cli_state *cli,
943 TALLOC_CTX *mem_ctx, int argc, const char **argv)
945 POLICY_HND connect_pol, domain_pol;
946 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
947 uint32 start_idx=0, num_entries, i, loop_count = 0;
948 SAM_DISPINFO_CTR ctr;
949 SAM_DISPINFO_1 info1;
951 /* Get sam policy handle */
953 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
955 if (!NT_STATUS_IS_OK(result)) {
959 /* Get domain policy handle */
961 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
962 MAXIMUM_ALLOWED_ACCESS,
963 domain_sid, &domain_pol);
964 if (!NT_STATUS_IS_OK(result)) {
968 /* Query domain users */
971 ctr.sam.info1 = &info1;
972 if (opt_long_list_entries)
973 d_printf("\nUser name Comment"\
974 "\n-----------------------------\n");
977 uint32 max_entries, max_size;
979 get_query_dispinfo_params(
980 loop_count, &max_entries, &max_size);
982 result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
983 &start_idx, 1, &num_entries,
984 max_entries, max_size, &ctr);
987 for (i = 0; i < num_entries; i++) {
988 unistr2_to_ascii(user, &(&ctr.sam.info1->str[i])->uni_acct_name, sizeof(user)-1);
989 if (opt_long_list_entries)
990 unistr2_to_ascii(desc, &(&ctr.sam.info1->str[i])->uni_acct_desc, sizeof(desc)-1);
992 if (opt_long_list_entries)
993 printf("%-21.21s %s\n", user, desc);
995 printf("%s\n", user);
997 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1004 * 'net rpc user' entrypoint.
1005 * @param argc Standard main() style argc
1006 * @param argc Standard main() style argv. Initial components are already
1010 int net_rpc_user(int argc, const char **argv)
1012 struct functable func[] = {
1013 {"add", rpc_user_add},
1014 {"info", rpc_user_info},
1015 {"delete", rpc_user_delete},
1016 {"password", rpc_user_password},
1021 if (opt_long_list_entries) {
1024 return run_rpc_command(NULL,PI_SAMR, 0,
1025 rpc_user_list_internals,
1029 return net_run_function(argc, argv, func, rpc_user_usage);
1033 /****************************************************************************/
1036 * Basic usage function for 'net rpc group'
1037 * @param argc Standard main() style argc.
1038 * @param argv Standard main() style argv. Initial components are already
1042 static int rpc_group_usage(int argc, const char **argv)
1044 return net_help_group(argc, argv);
1048 * List groups on a remote RPC server
1050 * All parameters are provided by the run_rpc_command function, except for
1051 * argc, argv which are passes through.
1053 * @param domain_sid The domain sid acquired from the remote server
1054 * @param cli A cli_state connected to the server.
1055 * @param mem_ctx Talloc context, destoyed on completion of the function.
1056 * @param argc Standard main() style argc
1057 * @param argv Standard main() style argv. Initial components are already
1060 * @return Normal NTSTATUS return.
1064 rpc_group_list_internals(const DOM_SID *domain_sid, const char *domain_name,
1065 struct cli_state *cli,
1066 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1068 POLICY_HND connect_pol, domain_pol;
1069 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1070 uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
1071 struct acct_info *groups;
1072 DOM_SID global_sid_Builtin;
1073 BOOL global = False;
1075 BOOL builtin = False;
1083 for (i=0; i<argc; i++) {
1084 if (strequal(argv[i], "global"))
1087 if (strequal(argv[i], "local"))
1090 if (strequal(argv[i], "builtin"))
1094 string_to_sid(&global_sid_Builtin, "S-1-5-32");
1096 /* Get sam policy handle */
1098 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1100 if (!NT_STATUS_IS_OK(result)) {
1104 /* Get domain policy handle */
1106 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1107 MAXIMUM_ALLOWED_ACCESS,
1108 domain_sid, &domain_pol);
1109 if (!NT_STATUS_IS_OK(result)) {
1113 /* Query domain groups */
1114 if (opt_long_list_entries)
1115 d_printf("\nGroup name Comment"\
1116 "\n-----------------------------\n");
1118 SAM_DISPINFO_CTR ctr;
1119 SAM_DISPINFO_3 info3;
1124 ctr.sam.info3 = &info3;
1128 get_query_dispinfo_params(
1129 loop_count, &max_entries, &max_size);
1131 result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
1132 &start_idx, 3, &num_entries,
1133 max_entries, max_size, &ctr);
1135 for (i = 0; i < num_entries; i++) {
1137 fstring group, desc;
1139 unistr2_to_ascii(group, &(&ctr.sam.info3->str[i])->uni_grp_name, sizeof(group)-1);
1140 unistr2_to_ascii(desc, &(&ctr.sam.info3->str[i])->uni_grp_desc, sizeof(desc)-1);
1142 if (opt_long_list_entries)
1143 printf("%-21.21s %-50.50s\n",
1146 printf("%s\n", group);
1148 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1149 /* query domain aliases */
1154 result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
1155 &start_idx, max_entries,
1156 &groups, &num_entries);
1158 for (i = 0; i < num_entries; i++) {
1160 char *description = NULL;
1162 if (opt_long_list_entries) {
1164 POLICY_HND alias_pol;
1167 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli, mem_ctx,
1172 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli, mem_ctx,
1175 (NT_STATUS_IS_OK(cli_samr_close(cli, mem_ctx,
1177 description = unistr2_tdup(mem_ctx,
1178 &ctr.alias.info3.uni_acct_desc);
1182 if (description != NULL) {
1183 printf("%-21.21s %-50.50s\n",
1184 groups[i].acct_name,
1187 printf("%s\n", groups[i].acct_name);
1190 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1191 cli_samr_close(cli, mem_ctx, &domain_pol);
1192 /* Get builtin policy handle */
1194 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1195 MAXIMUM_ALLOWED_ACCESS,
1196 &global_sid_Builtin, &domain_pol);
1197 if (!NT_STATUS_IS_OK(result)) {
1200 /* query builtin aliases */
1203 if (!builtin) break;
1205 result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
1206 &start_idx, max_entries,
1207 &groups, &num_entries);
1209 for (i = 0; i < num_entries; i++) {
1211 char *description = NULL;
1213 if (opt_long_list_entries) {
1215 POLICY_HND alias_pol;
1218 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli, mem_ctx,
1223 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli, mem_ctx,
1226 (NT_STATUS_IS_OK(cli_samr_close(cli, mem_ctx,
1228 description = unistr2_tdup(mem_ctx,
1229 &ctr.alias.info3.uni_acct_desc);
1233 if (description != NULL) {
1234 printf("%-21.21s %-50.50s\n",
1235 groups[i].acct_name,
1238 printf("%s\n", groups[i].acct_name);
1241 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1247 static int rpc_group_list(int argc, const char **argv)
1249 return run_rpc_command(NULL, PI_SAMR, 0,
1250 rpc_group_list_internals,
1255 rpc_group_members_internals(const DOM_SID *domain_sid, const char *domain_name,
1256 struct cli_state *cli,
1257 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1260 POLICY_HND connect_pol, domain_pol, group_pol;
1261 uint32 num_rids, *rids, *rid_types;
1262 uint32 num_members, *group_rids, *group_attrs;
1268 /* Get sam policy handle */
1270 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1272 if (!NT_STATUS_IS_OK(result)) {
1276 /* Get domain policy handle */
1278 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1279 MAXIMUM_ALLOWED_ACCESS,
1280 domain_sid, &domain_pol);
1281 if (!NT_STATUS_IS_OK(result)) {
1285 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol, 1000,
1286 1, argv, &num_rids, &rids, &rid_types);
1288 if (!NT_STATUS_IS_OK(result)) {
1292 if (num_rids != 1) {
1293 d_printf("Could not find group %s\n", argv[0]);
1297 if (rid_types[0] != SID_NAME_DOM_GRP) {
1298 d_printf("%s is not a domain group\n", argv[0]);
1302 result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
1303 MAXIMUM_ALLOWED_ACCESS,
1304 rids[0], &group_pol);
1306 if (!NT_STATUS_IS_OK(result))
1309 result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
1310 &num_members, &group_rids,
1313 if (!NT_STATUS_IS_OK(result))
1316 while (num_members > 0) {
1317 int this_time = 512;
1319 if (num_members < this_time)
1320 this_time = num_members;
1322 result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol, 1000,
1323 this_time, group_rids,
1324 &num_names, &names, &name_types);
1326 if (!NT_STATUS_IS_OK(result))
1329 for (i = 0; i < this_time; i++) {
1330 printf("%s\n", names[i]);
1333 num_members -= this_time;
1341 static int rpc_group_members(int argc, const char **argv)
1344 return rpc_group_usage(argc, argv);
1347 return run_rpc_command(NULL, PI_SAMR, 0,
1348 rpc_group_members_internals,
1353 * 'net rpc group' entrypoint.
1354 * @param argc Standard main() style argc
1355 * @param argc Standard main() style argv. Initial components are already
1359 int net_rpc_group(int argc, const char **argv)
1361 struct functable func[] = {
1363 {"add", rpc_group_add},
1364 {"delete", rpc_group_delete},
1366 {"list", rpc_group_list},
1367 {"members", rpc_group_members},
1372 if (opt_long_list_entries) {
1375 return run_rpc_command(NULL, PI_SAMR, 0,
1376 rpc_group_list_internals,
1380 return net_run_function(argc, argv, func, rpc_group_usage);
1383 /****************************************************************************/
1385 static int rpc_share_usage(int argc, const char **argv)
1387 return net_help_share(argc, argv);
1391 * Add a share on a remote RPC server
1393 * All parameters are provided by the run_rpc_command function, except for
1394 * argc, argv which are passes through.
1396 * @param domain_sid The domain sid acquired from the remote server
1397 * @param cli A cli_state connected to the server.
1398 * @param mem_ctx Talloc context, destoyed on completion of the function.
1399 * @param argc Standard main() style argc
1400 * @param argv Standard main() style argv. Initial components are already
1403 * @return Normal NTSTATUS return.
1406 rpc_share_add_internals(const DOM_SID *domain_sid, const char *domain_name,
1407 struct cli_state *cli,
1408 TALLOC_CTX *mem_ctx,int argc, const char **argv)
1411 char *sharename=talloc_strdup(mem_ctx, argv[0]);
1413 uint32 type=0; /* only allow disk shares to be added */
1414 uint32 num_users=0, perms=0;
1415 char *password=NULL; /* don't allow a share password */
1417 path = strchr(sharename, '=');
1419 return NT_STATUS_UNSUCCESSFUL;
1422 result = cli_srvsvc_net_share_add(cli, mem_ctx, sharename, type,
1423 opt_comment, perms, opt_maxusers,
1424 num_users, path, password);
1425 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1428 static int rpc_share_add(int argc, const char **argv)
1430 if ((argc < 1) || !strchr(argv[0], '=')) {
1431 DEBUG(1,("Sharename or path not specified on add\n"));
1432 return rpc_share_usage(argc, argv);
1434 return run_rpc_command(NULL, PI_SRVSVC, 0,
1435 rpc_share_add_internals,
1440 * Delete a share on a remote RPC server
1442 * All parameters are provided by the run_rpc_command function, except for
1443 * argc, argv which are passes through.
1445 * @param domain_sid The domain sid acquired from the remote server
1446 * @param cli A cli_state connected to the server.
1447 * @param mem_ctx Talloc context, destoyed on completion of the function.
1448 * @param argc Standard main() style argc
1449 * @param argv Standard main() style argv. Initial components are already
1452 * @return Normal NTSTATUS return.
1455 rpc_share_del_internals(const DOM_SID *domain_sid, const char *domain_name,
1456 struct cli_state *cli,
1457 TALLOC_CTX *mem_ctx,int argc, const char **argv)
1461 result = cli_srvsvc_net_share_del(cli, mem_ctx, argv[0]);
1462 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1466 * Delete a share on a remote RPC server
1468 * @param domain_sid The domain sid acquired from the remote server
1469 * @param argc Standard main() style argc
1470 * @param argv Standard main() style argv. Initial components are already
1473 * @return A shell status integer (0 for success)
1475 static int rpc_share_delete(int argc, const char **argv)
1478 DEBUG(1,("Sharename not specified on delete\n"));
1479 return rpc_share_usage(argc, argv);
1481 return run_rpc_command(NULL, PI_SRVSVC, 0,
1482 rpc_share_del_internals,
1487 * Formatted print of share info
1489 * @param info1 pointer to SRV_SHARE_INFO_1 to format
1492 static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
1494 fstring netname = "", remark = "";
1496 rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
1497 rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
1499 if (opt_long_list_entries) {
1500 d_printf("%-12.12s %-8.8s %-50.50s\n",
1501 netname, share_type[info1->info_1.type], remark);
1503 d_printf("%-12.12s\n", netname);
1509 * List shares on a remote RPC server
1511 * All parameters are provided by the run_rpc_command function, except for
1512 * argc, argv which are passes through.
1514 * @param domain_sid The domain sid acquired from the remote server
1515 * @param cli A cli_state connected to the server.
1516 * @param mem_ctx Talloc context, destoyed on completion of the function.
1517 * @param argc Standard main() style argc
1518 * @param argv Standard main() style argv. Initial components are already
1521 * @return Normal NTSTATUS return.
1525 rpc_share_list_internals(const DOM_SID *domain_sid, const char *domain_name,
1526 struct cli_state *cli,
1527 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1529 SRV_SHARE_INFO_CTR ctr;
1532 uint32 preferred_len = 0xffffffff, i;
1534 init_enum_hnd(&hnd, 0);
1536 result = cli_srvsvc_net_share_enum(
1537 cli, mem_ctx, 1, &ctr, preferred_len, &hnd);
1539 if (!W_ERROR_IS_OK(result))
1542 /* Display results */
1544 if (opt_long_list_entries) {
1546 "\nEnumerating shared resources (exports) on remote server:\n\n"\
1547 "\nShare name Type Description\n"\
1548 "---------- ---- -----------\n");
1550 for (i = 0; i < ctr.num_entries; i++)
1551 display_share_info_1(&ctr.share.info1[i]);
1553 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1557 * 'net rpc share' entrypoint.
1558 * @param argc Standard main() style argc
1559 * @param argv Standard main() style argv. Initial components are already
1563 int net_rpc_share(int argc, const char **argv)
1565 struct functable func[] = {
1566 {"add", rpc_share_add},
1567 {"delete", rpc_share_delete},
1572 return run_rpc_command(NULL, PI_SRVSVC, 0,
1573 rpc_share_list_internals,
1576 return net_run_function(argc, argv, func, rpc_share_usage);
1579 /****************************************************************************/
1581 static int rpc_file_usage(int argc, const char **argv)
1583 return net_help_file(argc, argv);
1587 * Close a file on a remote RPC server
1589 * All parameters are provided by the run_rpc_command function, except for
1590 * argc, argv which are passes through.
1592 * @param domain_sid The domain sid acquired from the remote server
1593 * @param cli A cli_state connected to the server.
1594 * @param mem_ctx Talloc context, destoyed on completion of the function.
1595 * @param argc Standard main() style argc
1596 * @param argv Standard main() style argv. Initial components are already
1599 * @return Normal NTSTATUS return.
1602 rpc_file_close_internals(const DOM_SID *domain_sid, const char *domain_name,
1603 struct cli_state *cli,
1604 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1607 result = cli_srvsvc_net_file_close(cli, mem_ctx, atoi(argv[0]));
1608 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1612 * Close a file on a remote RPC server
1614 * @param argc Standard main() style argc
1615 * @param argv Standard main() style argv. Initial components are already
1618 * @return A shell status integer (0 for success)
1620 static int rpc_file_close(int argc, const char **argv)
1623 DEBUG(1, ("No fileid given on close\n"));
1624 return(rpc_file_usage(argc, argv));
1627 return run_rpc_command(NULL, PI_SRVSVC, 0,
1628 rpc_file_close_internals,
1633 * Formatted print of open file info
1635 * @param info3 FILE_INFO_3 contents
1636 * @param str3 strings for FILE_INFO_3
1639 static void display_file_info_3(FILE_INFO_3 *info3, FILE_INFO_3_STR *str3)
1641 fstring user = "", path = "";
1643 rpcstr_pull_unistr2_fstring(user, &str3->uni_user_name);
1644 rpcstr_pull_unistr2_fstring(path, &str3->uni_path_name);
1646 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
1647 info3->id, user, info3->perms, info3->num_locks, path);
1651 * List open files on a remote RPC server
1653 * All parameters are provided by the run_rpc_command function, except for
1654 * argc, argv which are passes through.
1656 * @param domain_sid The domain sid acquired from the remote server
1657 * @param cli A cli_state connected to the server.
1658 * @param mem_ctx Talloc context, destoyed on completion of the function.
1659 * @param argc Standard main() style argc
1660 * @param argv Standard main() style argv. Initial components are already
1663 * @return Normal NTSTATUS return.
1667 rpc_file_list_internals(const DOM_SID *domain_sid, const char *domain_name,
1668 struct cli_state *cli,
1669 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1671 SRV_FILE_INFO_CTR ctr;
1674 uint32 preferred_len = 0xffffffff, i;
1675 const char *username=NULL;
1677 init_enum_hnd(&hnd, 0);
1679 /* if argc > 0, must be user command */
1681 username = smb_xstrdup(argv[0]);
1683 result = cli_srvsvc_net_file_enum(
1684 cli, mem_ctx, 3, username, &ctr, preferred_len, &hnd);
1686 if (!W_ERROR_IS_OK(result))
1689 /* Display results */
1692 "\nEnumerating open files on remote server:\n\n"\
1693 "\nFileId Opened by Perms Locks Path"\
1694 "\n------ --------- ----- ----- ---- \n");
1695 for (i = 0; i < ctr.num_entries; i++)
1696 display_file_info_3(&ctr.file.info3[i].info_3,
1697 &ctr.file.info3[i].info_3_str);
1699 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1704 * List files for a user on a remote RPC server
1706 * @param argc Standard main() style argc
1707 * @param argv Standard main() style argv. Initial components are already
1710 * @return A shell status integer (0 for success)
1712 static int rpc_file_user(int argc, const char **argv)
1715 DEBUG(1, ("No username given\n"));
1716 return(rpc_file_usage(argc, argv));
1719 return run_rpc_command(NULL, PI_SRVSVC, 0,
1720 rpc_file_list_internals,
1726 * 'net rpc file' entrypoint.
1727 * @param argc Standard main() style argc
1728 * @param argv Standard main() style argv. Initial components are already
1732 int net_rpc_file(int argc, const char **argv)
1734 struct functable func[] = {
1735 {"close", rpc_file_close},
1736 {"user", rpc_file_user},
1738 {"info", rpc_file_info},
1744 return run_rpc_command(NULL, PI_SRVSVC, 0,
1745 rpc_file_list_internals,
1748 return net_run_function(argc, argv, func, rpc_file_usage);
1751 /****************************************************************************/
1756 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
1758 * All parameters are provided by the run_rpc_command function, except for
1759 * argc, argv which are passed through.
1761 * @param domain_sid The domain sid aquired from the remote server
1762 * @param cli A cli_state connected to the server.
1763 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1764 * @param argc Standard main() style argc
1765 * @param argv Standard main() style argv. Initial components are already
1768 * @return Normal NTSTATUS return.
1771 static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid,
1772 const char *domain_name,
1773 struct cli_state *cli,
1774 TALLOC_CTX *mem_ctx,
1775 int argc, const char **argv)
1777 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1779 result = cli_shutdown_abort(cli, mem_ctx);
1781 if (NT_STATUS_IS_OK(result))
1782 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
1784 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
1791 * ABORT the shutdown of a remote RPC Server, over winreg pipe
1793 * All parameters are provided by the run_rpc_command function, except for
1794 * argc, argv which are passed through.
1796 * @param domain_sid The domain sid aquired from the remote server
1797 * @param cli A cli_state connected to the server.
1798 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1799 * @param argc Standard main() style argc
1800 * @param argv Standard main() style argv. Initial components are already
1803 * @return Normal NTSTATUS return.
1806 static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid,
1807 const char *domain_name,
1808 struct cli_state *cli,
1809 TALLOC_CTX *mem_ctx,
1810 int argc, const char **argv)
1812 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1814 result = cli_reg_abort_shutdown(cli, mem_ctx);
1816 if (NT_STATUS_IS_OK(result))
1817 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
1819 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
1825 * ABORT the Shut down of a remote RPC server
1827 * @param argc Standard main() style argc
1828 * @param argv Standard main() style argv. Initial components are already
1831 * @return A shell status integer (0 for success)
1834 static int rpc_shutdown_abort(int argc, const char **argv)
1836 int rc = run_rpc_command(NULL, PI_SHUTDOWN, 0,
1837 rpc_shutdown_abort_internals,
1843 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
1845 return run_rpc_command(NULL, PI_WINREG, 0,
1846 rpc_reg_shutdown_abort_internals,
1851 * Shut down a remote RPC Server
1853 * All parameters are provided by the run_rpc_command function, except for
1854 * argc, argv which are passes through.
1856 * @param domain_sid The domain sid aquired from the remote server
1857 * @param cli A cli_state connected to the server.
1858 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1859 * @param argc Standard main() style argc
1860 * @param argc Standard main() style argv. Initial components are already
1863 * @return Normal NTSTATUS return.
1866 static NTSTATUS rpc_shutdown_internals(const DOM_SID *domain_sid,
1867 const char *domain_name,
1868 struct cli_state *cli, TALLOC_CTX *mem_ctx,
1869 int argc, const char **argv)
1871 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1872 const char *msg = "This machine will be shutdown shortly";
1873 uint32 timeout = 20;
1878 struct poptOption long_options[] = {
1879 {"message", 'm', POPT_ARG_STRING, &msg},
1880 {"timeout", 't', POPT_ARG_INT, &timeout},
1881 {"reboot", 'r', POPT_ARG_NONE, &reboot},
1882 {"force", 'f', POPT_ARG_NONE, &force},
1886 pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
1887 POPT_CONTEXT_KEEP_FIRST);
1889 rc = poptGetNextOpt(pc);
1892 /* an error occurred during option processing */
1893 DEBUG(0, ("%s: %s\n",
1894 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1896 return NT_STATUS_INVALID_PARAMETER;
1903 timeout = opt_timeout;
1906 /* create an entry */
1907 result = cli_reg_shutdown(cli, mem_ctx, msg, timeout, opt_reboot, opt_force);
1909 if (NT_STATUS_IS_OK(result))
1910 DEBUG(5,("Shutdown of remote machine succeeded\n"));
1912 DEBUG(0,("Shutdown of remote machine failed!\n"));
1918 * Shut down a remote RPC server
1920 * @param argc Standard main() style argc
1921 * @param argc Standard main() style argv. Initial components are already
1924 * @return A shell status integer (0 for success)
1927 static int rpc_shutdown(int argc, const char **argv)
1929 return run_rpc_command(NULL, PI_WINREG, 0, rpc_shutdown_internals,
1933 /***************************************************************************
1934 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
1936 ***************************************************************************/
1939 * Add interdomain trust account to the RPC server.
1940 * All parameters (except for argc and argv) are passed by run_rpc_command
1943 * @param domain_sid The domain sid acquired from the server
1944 * @param cli A cli_state connected to the server.
1945 * @param mem_ctx Talloc context, destoyed on completion of the function.
1946 * @param argc Standard main() style argc
1947 * @param argc Standard main() style argv. Initial components are already
1950 * @return normal NTSTATUS return code
1953 static NTSTATUS rpc_trustdom_add_internals(const DOM_SID *domain_sid,
1954 const char *domain_name,
1955 struct cli_state *cli, TALLOC_CTX *mem_ctx,
1956 int argc, const char **argv) {
1958 POLICY_HND connect_pol, domain_pol, user_pol;
1959 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1962 uint32 unknown, user_rid;
1965 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
1966 return NT_STATUS_INVALID_PARAMETER;
1970 * Make valid trusting domain account (ie. uppercased and with '$' appended)
1973 if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
1974 return NT_STATUS_NO_MEMORY;
1977 strupper_m(acct_name);
1979 /* Get samr policy handle */
1980 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1982 if (!NT_STATUS_IS_OK(result)) {
1986 /* Get domain policy handle */
1987 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1988 MAXIMUM_ALLOWED_ACCESS,
1989 domain_sid, &domain_pol);
1990 if (!NT_STATUS_IS_OK(result)) {
1994 /* Create trusting domain's account */
1995 acb_info = ACB_DOMTRUST;
1996 unknown = 0xe00500b0; /* No idea what this is - a permission mask?
1997 mimir: yes, most probably it is */
1999 result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
2000 acct_name, acb_info, unknown,
2001 &user_pol, &user_rid);
2002 if (!NT_STATUS_IS_OK(result)) {
2007 SAM_USERINFO_CTR ctr;
2008 SAM_USER_INFO_24 p24;
2011 encode_pw_buffer((char *)pwbuf, argv[1], STR_UNICODE);
2016 init_sam_user_info24(&p24, (char *)pwbuf, 24);
2018 ctr.switch_value = 24;
2019 ctr.info.id24 = &p24;
2021 result = cli_samr_set_userinfo(cli, mem_ctx, &user_pol, 24,
2022 &cli->user_session_key, &ctr);
2024 if (!NT_STATUS_IS_OK(result)) {
2025 DEBUG(0,("Could not set trust account password: %s\n",
2026 nt_errstr(result)));
2032 SAFE_FREE(acct_name);
2037 * Create interdomain trust account for a remote domain.
2039 * @param argc standard argc
2040 * @param argv standard argv without initial components
2042 * @return Integer status (0 means success)
2045 static int rpc_trustdom_add(int argc, const char **argv)
2048 return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
2051 d_printf("Usage: net rpc trustdom add <domain>\n");
2058 * Delete interdomain trust account for a remote domain.
2060 * @param argc standard argc
2061 * @param argv standard argv without initial components
2063 * @return Integer status (0 means success)
2066 static int rpc_trustdom_del(int argc, const char **argv)
2068 d_printf("Sorry, not yet implemented.\n");
2069 d_printf("Use 'smbpasswd -x -i' instead.\n");
2075 * Establish trust relationship to a trusting domain.
2076 * Interdomain account must already be created on remote PDC.
2078 * @param argc standard argc
2079 * @param argv standard argv without initial components
2081 * @return Integer status (0 means success)
2084 static int rpc_trustdom_establish(int argc, const char **argv)
2086 struct cli_state *cli;
2087 struct in_addr server_ip;
2088 POLICY_HND connect_hnd;
2089 TALLOC_CTX *mem_ctx;
2091 DOM_SID *domain_sid;
2092 WKS_INFO_100 wks_info;
2095 char* domain_name_pol;
2100 * Connect to \\server\ipc$ as 'our domain' account with password
2104 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
2108 domain_name = smb_xstrdup(argv[0]);
2109 strupper_m(domain_name);
2111 /* account name used at first is our domain's name with '$' */
2112 asprintf(&acct_name, "%s$", lp_workgroup());
2113 strupper_m(acct_name);
2116 * opt_workgroup will be used by connection functions further,
2117 * hence it should be set to remote domain name instead of ours
2119 if (opt_workgroup) {
2120 opt_workgroup = smb_xstrdup(domain_name);
2123 opt_user_name = acct_name;
2125 /* find the domain controller */
2126 if (!net_find_pdc(&server_ip, pdc_name, domain_name)) {
2127 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
2131 /* connect to ipc$ as username/password */
2132 nt_status = connect_to_ipc(&cli, &server_ip, pdc_name);
2133 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
2135 /* Is it trusting domain account for sure ? */
2136 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
2137 nt_errstr(nt_status)));
2142 * Connect to \\server\ipc$ again (this time anonymously)
2145 nt_status = connect_to_ipc_anonymous(&cli, &server_ip, (char*)pdc_name);
2147 if (NT_STATUS_IS_ERR(nt_status)) {
2148 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
2149 domain_name, nt_errstr(nt_status)));
2153 * Use NetServerEnum2 to make sure we're talking to a proper server
2156 if (!cli_get_pdc_name(cli, domain_name, (char*)pdc_name)) {
2157 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
2158 for domain %s\n", domain_name));
2162 * Call WksQueryInfo to check remote server's capabilities
2163 * note: It is now used only to get unicode domain name
2166 if (!cli_nt_session_open(cli, PI_WKSSVC)) {
2167 DEBUG(0, ("Couldn't not initialise wkssvc pipe\n"));
2171 if (!(mem_ctx = talloc_init("establishing trust relationship to domain %s",
2173 DEBUG(0, ("talloc_init() failed\n"));
2178 nt_status = cli_wks_query_info(cli, mem_ctx, &wks_info);
2180 if (NT_STATUS_IS_ERR(nt_status)) {
2181 DEBUG(0, ("WksQueryInfo call failed.\n"));
2185 if (cli->nt_pipe_fnum)
2186 cli_nt_session_close(cli);
2190 * Call LsaOpenPolicy and LsaQueryInfo
2193 if (!(mem_ctx = talloc_init("rpc_trustdom_establish"))) {
2194 DEBUG(0, ("talloc_init() failed\n"));
2199 if (!cli_nt_session_open(cli, PI_LSARPC)) {
2200 DEBUG(0, ("Could not initialise lsa pipe\n"));
2205 nt_status = cli_lsa_open_policy2(cli, mem_ctx, True, SEC_RIGHTS_QUERY_VALUE,
2207 if (NT_STATUS_IS_ERR(nt_status)) {
2208 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
2209 nt_errstr(nt_status)));
2213 /* Querying info level 5 */
2215 nt_status = cli_lsa_query_info_policy(cli, mem_ctx, &connect_hnd,
2216 5 /* info level */, &domain_name_pol,
2218 if (NT_STATUS_IS_ERR(nt_status)) {
2219 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
2220 nt_errstr(nt_status)));
2227 /* There should be actually query info level 3 (following nt serv behaviour),
2228 but I still don't know if it's _really_ necessary */
2231 * Store the password in secrets db
2234 if (!secrets_store_trusted_domain_password(domain_name, wks_info.uni_lan_grp.buffer,
2235 wks_info.uni_lan_grp.uni_str_len, opt_password,
2237 DEBUG(0, ("Storing password for trusted domain failed.\n"));
2242 * Close the pipes and clean up
2245 nt_status = cli_lsa_close(cli, mem_ctx, &connect_hnd);
2246 if (NT_STATUS_IS_ERR(nt_status)) {
2247 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
2248 nt_errstr(nt_status)));
2252 if (cli->nt_pipe_fnum)
2253 cli_nt_session_close(cli);
2255 talloc_destroy(mem_ctx);
2257 DEBUG(0, ("Success!\n"));
2262 * Revoke trust relationship to the remote domain
2264 * @param argc standard argc
2265 * @param argv standard argv without initial components
2267 * @return Integer status (0 means success)
2270 static int rpc_trustdom_revoke(int argc, const char **argv)
2274 if (argc < 1) return -1;
2276 /* generate upper cased domain name */
2277 domain_name = smb_xstrdup(argv[0]);
2278 strupper_m(domain_name);
2280 /* delete password of the trust */
2281 if (!trusted_domain_password_delete(domain_name)) {
2282 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
2291 * Usage for 'net rpc trustdom' command
2293 * @param argc standard argc
2294 * @param argv standard argv without inital components
2296 * @return Integer status returned to shell
2299 static int rpc_trustdom_usage(int argc, const char **argv)
2301 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
2302 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
2303 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
2304 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
2305 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
2310 static NTSTATUS rpc_query_domain_sid(const DOM_SID *domain_sid,
2311 const char *domain_name,
2312 struct cli_state *cli, TALLOC_CTX *mem_ctx,
2313 int argc, const char **argv)
2316 sid_to_string(str_sid, domain_sid);
2317 d_printf("%s\n", str_sid);
2318 return NT_STATUS_OK;
2322 static int rpc_trustdom_list(int argc, const char **argv)
2324 /* common variables */
2325 TALLOC_CTX* mem_ctx;
2326 struct cli_state *cli, *remote_cli;
2328 const char *domain_name = NULL;
2329 DOM_SID *queried_dom_sid;
2330 fstring ascii_sid, padding;
2331 int ascii_dom_name_len;
2332 POLICY_HND connect_hnd;
2334 /* trusted domains listing variables */
2335 unsigned int num_domains, enum_ctx = 0;
2336 int i, pad_len, col_len = 20;
2337 DOM_SID *domain_sids;
2338 char **trusted_dom_names;
2342 /* trusting domains listing variables */
2343 POLICY_HND domain_hnd;
2344 char **trusting_dom_names;
2345 uint32 *trusting_dom_rids;
2348 * Listing trusted domains (stored in secrets.tdb, if local)
2351 mem_ctx = talloc_init("trust relationships listing");
2354 * set domain and pdc name to local samba server (default)
2355 * or to remote one given in command line
2358 if (StrCaseCmp(opt_workgroup, lp_workgroup())) {
2359 domain_name = opt_workgroup;
2360 opt_target_workgroup = opt_workgroup;
2362 fstrcpy(pdc_name, global_myname());
2363 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
2364 opt_target_workgroup = domain_name;
2367 /* open \PIPE\lsarpc and open policy handle */
2368 if (!(cli = net_make_ipc_connection(NET_FLAGS_PDC))) {
2369 DEBUG(0, ("Couldn't connect to domain controller\n"));
2373 if (!cli_nt_session_open(cli, PI_LSARPC)) {
2374 DEBUG(0, ("Could not initialise lsa pipe\n"));
2378 nt_status = cli_lsa_open_policy2(cli, mem_ctx, False, SEC_RIGHTS_QUERY_VALUE,
2380 if (NT_STATUS_IS_ERR(nt_status)) {
2381 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
2382 nt_errstr(nt_status)));
2386 /* query info level 5 to obtain sid of a domain being queried */
2387 nt_status = cli_lsa_query_info_policy(
2388 cli, mem_ctx, &connect_hnd, 5 /* info level */,
2389 &dummy, &queried_dom_sid);
2391 if (NT_STATUS_IS_ERR(nt_status)) {
2392 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
2393 nt_errstr(nt_status)));
2398 * Keep calling LsaEnumTrustdom over opened pipe until
2399 * the end of enumeration is reached
2402 d_printf("Trusted domains list:\n\n");
2405 nt_status = cli_lsa_enum_trust_dom(cli, mem_ctx, &connect_hnd, &enum_ctx,
2407 &trusted_dom_names, &domain_sids);
2409 if (NT_STATUS_IS_ERR(nt_status)) {
2410 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
2411 nt_errstr(nt_status)));
2415 for (i = 0; i < num_domains; i++) {
2416 /* convert sid into ascii string */
2417 sid_to_string(ascii_sid, &(domain_sids[i]));
2419 /* calculate padding space for d_printf to look nicer */
2420 pad_len = col_len - strlen(trusted_dom_names[i]);
2421 padding[pad_len] = 0;
2422 do padding[--pad_len] = ' '; while (pad_len);
2424 d_printf("%s%s%s\n", trusted_dom_names[i], padding, ascii_sid);
2428 * in case of no trusted domains say something rather
2429 * than just display blank line
2431 if (!num_domains) d_printf("none\n");
2433 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
2435 /* close this connection before doing next one */
2436 nt_status = cli_lsa_close(cli, mem_ctx, &connect_hnd);
2437 if (NT_STATUS_IS_ERR(nt_status)) {
2438 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
2439 nt_errstr(nt_status)));
2443 cli_nt_session_close(cli);
2446 * Listing trusting domains (stored in passdb backend, if local)
2449 d_printf("\nTrusting domains list:\n\n");
2452 * Open \PIPE\samr and get needed policy handles
2454 if (!cli_nt_session_open(cli, PI_SAMR)) {
2455 DEBUG(0, ("Could not initialise samr pipe\n"));
2460 nt_status = cli_samr_connect(cli, mem_ctx, SA_RIGHT_SAM_OPEN_DOMAIN,
2462 if (!NT_STATUS_IS_OK(nt_status)) {
2463 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
2464 nt_errstr(nt_status)));
2468 /* SamrOpenDomain - we have to open domain policy handle in order to be
2469 able to enumerate accounts*/
2470 nt_status = cli_samr_open_domain(cli, mem_ctx, &connect_hnd,
2471 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
2472 queried_dom_sid, &domain_hnd);
2473 if (!NT_STATUS_IS_OK(nt_status)) {
2474 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
2475 nt_errstr(nt_status)));
2480 * perform actual enumeration
2483 enum_ctx = 0; /* reset enumeration context from last enumeration */
2486 nt_status = cli_samr_enum_dom_users(cli, mem_ctx, &domain_hnd,
2487 &enum_ctx, ACB_DOMTRUST, 0xffff,
2488 &trusting_dom_names, &trusting_dom_rids,
2490 if (NT_STATUS_IS_ERR(nt_status)) {
2491 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
2492 nt_errstr(nt_status)));
2496 for (i = 0; i < num_domains; i++) {
2499 * get each single domain's sid (do we _really_ need this ?):
2500 * 1) connect to domain's pdc
2501 * 2) query the pdc for domain's sid
2504 /* get rid of '$' tail */
2505 ascii_dom_name_len = strlen(trusting_dom_names[i]);
2506 if (ascii_dom_name_len && ascii_dom_name_len < FSTRING_LEN)
2507 trusting_dom_names[i][ascii_dom_name_len - 1] = '\0';
2509 /* calculate padding space for d_printf to look nicer */
2510 pad_len = col_len - strlen(trusting_dom_names[i]);
2511 padding[pad_len] = 0;
2512 do padding[--pad_len] = ' '; while (pad_len);
2514 /* set opt_* variables to remote domain */
2515 strupper_m(trusting_dom_names[i]);
2516 opt_workgroup = talloc_strdup(mem_ctx, trusting_dom_names[i]);
2517 opt_target_workgroup = opt_workgroup;
2519 d_printf("%s%s", trusting_dom_names[i], padding);
2521 /* connect to remote domain controller */
2522 remote_cli = net_make_ipc_connection(NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS);
2524 /* query for domain's sid */
2525 if (run_rpc_command(remote_cli, PI_LSARPC, 0, rpc_query_domain_sid, argc, argv))
2526 d_printf("couldn't get domain's sid\n");
2528 cli_shutdown(remote_cli);
2531 d_printf("domain controller is not responding\n");
2535 if (!num_domains) d_printf("none\n");
2537 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
2539 /* close opened samr and domain policy handles */
2540 nt_status = cli_samr_close(cli, mem_ctx, &domain_hnd);
2541 if (!NT_STATUS_IS_OK(nt_status)) {
2542 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
2545 nt_status = cli_samr_close(cli, mem_ctx, &connect_hnd);
2546 if (!NT_STATUS_IS_OK(nt_status)) {
2547 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
2550 /* close samr pipe and connection to IPC$ */
2551 cli_nt_session_close(cli);
2554 talloc_destroy(mem_ctx);
2559 * Entrypoint for 'net rpc trustdom' code
2561 * @param argc standard argc
2562 * @param argv standard argv without initial components
2564 * @return Integer status (0 means success)
2567 static int rpc_trustdom(int argc, const char **argv)
2569 struct functable func[] = {
2570 {"add", rpc_trustdom_add},
2571 {"del", rpc_trustdom_del},
2572 {"establish", rpc_trustdom_establish},
2573 {"revoke", rpc_trustdom_revoke},
2574 {"help", rpc_trustdom_usage},
2575 {"list", rpc_trustdom_list},
2580 rpc_trustdom_usage(argc, argv);
2584 return (net_run_function(argc, argv, func, rpc_user_usage));
2588 * Check if a server will take rpc commands
2589 * @param flags Type of server to connect to (PDC, DMB, localhost)
2590 * if the host is not explicitly specified
2591 * @return BOOL (true means rpc supported)
2593 BOOL net_rpc_check(unsigned flags)
2595 struct cli_state cli;
2597 struct in_addr server_ip;
2598 char *server_name = NULL;
2600 /* flags (i.e. server type) may depend on command */
2601 if (!net_find_server(flags, &server_ip, &server_name))
2605 if (cli_initialise(&cli) == False)
2608 if (!cli_connect(&cli, server_name, &server_ip))
2610 if (!attempt_netbios_session_request(&cli, global_myname(),
2611 server_name, &server_ip))
2613 if (!cli_negprot(&cli))
2615 if (cli.protocol < PROTOCOL_NT1)
2624 /* dump sam database via samsync rpc calls */
2625 static int rpc_samdump(int argc, const char **argv) {
2626 return run_rpc_command(NULL, PI_NETLOGON, NET_FLAGS_ANONYMOUS, rpc_samdump_internals,
2630 /* syncronise sam database via samsync rpc calls */
2631 static int rpc_vampire(int argc, const char **argv) {
2632 return run_rpc_command(NULL, PI_NETLOGON, NET_FLAGS_ANONYMOUS, rpc_vampire_internals,
2635 /****************************************************************************/
2639 * Basic usage function for 'net rpc'
2640 * @param argc Standard main() style argc
2641 * @param argv Standard main() style argv. Initial components are already
2645 int net_rpc_usage(int argc, const char **argv)
2647 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
2648 d_printf(" net rpc join \t\t\tto join a domain \n");
2649 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n\n\n");
2650 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
2651 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
2652 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass");
2653 d_printf(" net rpc group \t\tto list groups\n");
2654 d_printf(" net rpc share \t\tto add, delete, and list shares\n");
2655 d_printf(" net rpc file \t\t\tto list open files\n");
2656 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
2657 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
2658 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
2659 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
2660 d_printf(" net rpc trustdom \t\tto create trusting domain's account\n"
2661 "\t\t\t\t\tor establish trust\n");
2662 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
2663 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
2665 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
2666 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
2667 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
2668 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
2669 d_printf("\t-c or --comment=<message>\ttext message to display on impending shutdown\n");
2675 * Help function for 'net rpc'. Calls command specific help if requested
2676 * or displays usage of net rpc
2677 * @param argc Standard main() style argc
2678 * @param argv Standard main() style argv. Initial components are already
2682 int net_rpc_help(int argc, const char **argv)
2684 struct functable func[] = {
2685 {"join", rpc_join_usage},
2686 {"user", rpc_user_usage},
2687 {"group", rpc_group_usage},
2688 {"share", rpc_share_usage},
2689 /*{"changetrustpw", rpc_changetrustpw_usage}, */
2690 {"trustdom", rpc_trustdom_usage},
2691 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
2692 /*{"shutdown", rpc_shutdown_usage}, */
2697 net_rpc_usage(argc, argv);
2701 return (net_run_function(argc, argv, func, rpc_user_usage));
2706 * 'net rpc' entrypoint.
2707 * @param argc Standard main() style argc
2708 * @param argv Standard main() style argv. Initial components are already
2712 int net_rpc(int argc, const char **argv)
2714 struct functable func[] = {
2715 {"info", net_rpc_info},
2716 {"join", net_rpc_join},
2717 {"oldjoin", net_rpc_oldjoin},
2718 {"testjoin", net_rpc_testjoin},
2719 {"user", net_rpc_user},
2720 {"password", rpc_user_password},
2721 {"group", net_rpc_group},
2722 {"share", net_rpc_share},
2723 {"file", net_rpc_file},
2724 {"changetrustpw", net_rpc_changetrustpw},
2725 {"trustdom", rpc_trustdom},
2726 {"abortshutdown", rpc_shutdown_abort},
2727 {"shutdown", rpc_shutdown},
2728 {"samdump", rpc_samdump},
2729 {"vampire", rpc_vampire},
2730 {"getsid", net_rpc_getsid},
2731 {"help", net_rpc_help},
2734 return net_run_function(argc, argv, func, net_rpc_usage);