Minor comment updates ...
[Samba/gebeck_regimport.git] / source3 / utils / net_rpc.c
blob298e8ff6690772bf9431bfce80da1c93e791d624
1 /*
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. */
21 #include "includes.h"
22 #include "../utils/net.h"
24 /**
25 * @file net_rpc.c
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.
36 **/
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 **);
42 /**
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.
49 **/
51 static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli)
53 DOM_SID *domain_sid;
54 POLICY_HND pol;
55 NTSTATUS result = NT_STATUS_OK;
56 uint32 info_class = 5;
57 fstring domain_name;
58 TALLOC_CTX *mem_ctx;
60 if (!(domain_sid = malloc(sizeof(DOM_SID)))){
61 DEBUG(0,("net_get_remote_domain_sid: malloc returned NULL!\n"));
62 goto error;
65 if (!(mem_ctx=talloc_init("net_get_remote_domain_sid")))
67 DEBUG(0,("net_get_remote_domain_sid: talloc_init returned NULL!\n"));
68 goto error;
72 if (!cli_nt_session_open (cli, PI_LSARPC)) {
73 fprintf(stderr, "could not initialise lsa pipe\n");
74 goto error;
77 result = cli_lsa_open_policy(cli, mem_ctx, False,
78 SEC_RIGHTS_MAXIMUM_ALLOWED,
79 &pol);
80 if (!NT_STATUS_IS_OK(result)) {
81 goto error;
84 result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
85 domain_name, domain_sid);
86 if (!NT_STATUS_IS_OK(result)) {
87 error:
88 fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
90 if (!NT_STATUS_IS_OK(result)) {
91 fprintf(stderr, "error: %s\n", nt_errstr(result));
94 exit(1);
97 cli_lsa_close(cli, mem_ctx, &pol);
98 cli_nt_session_close(cli);
99 talloc_destroy(mem_ctx);
101 return domain_sid;
105 * Run a single RPC command, from start to finish.
107 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
108 * @param conn_flag a NET_FLAG_ combination. Passed to
109 * net_make_ipc_connection.
110 * @param argc Standard main() style argc
111 * @param argc Standard main() style argv. Initial components are already
112 * stripped
113 * @return A shell status integer (0 for success)
116 static int run_rpc_command(struct cli_state *cli_arg, const int pipe_idx, int conn_flags,
117 rpc_command_fn fn,
118 int argc, const char **argv)
120 struct cli_state *cli = NULL;
121 TALLOC_CTX *mem_ctx;
122 NTSTATUS nt_status;
123 DOM_SID *domain_sid;
125 /* make use of cli_state handed over as an argument, if possible */
126 if (!cli_arg)
127 cli = net_make_ipc_connection(conn_flags);
128 else
129 cli = cli_arg;
131 if (!cli) {
132 return -1;
135 domain_sid = net_get_remote_domain_sid(cli);
137 /* Create mem_ctx */
139 if (!(mem_ctx = talloc_init("run_rpc_command"))) {
140 DEBUG(0, ("talloc_init() failed\n"));
141 cli_shutdown(cli);
142 return -1;
145 if (!cli_nt_session_open(cli, pipe_idx)) {
146 DEBUG(0, ("Could not initialise pipe\n"));
149 nt_status = fn(domain_sid, cli, mem_ctx, argc, argv);
151 if (!NT_STATUS_IS_OK(nt_status)) {
152 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status)));
153 } else {
154 DEBUG(5, ("rpc command function succedded\n"));
158 if (cli->nt_pipe_fnum)
159 cli_nt_session_close(cli);
161 /* close the connection only if it was opened here */
162 if (!cli_arg)
163 cli_shutdown(cli);
165 talloc_destroy(mem_ctx);
167 return (!NT_STATUS_IS_OK(nt_status));
171 /****************************************************************************/
174 /**
175 * Force a change of the trust acccount password.
177 * All parameters are provided by the run_rpc_command function, except for
178 * argc, argv which are passes through.
180 * @param domain_sid The domain sid aquired from the remote server
181 * @param cli A cli_state connected to the server.
182 * @param mem_ctx Talloc context, destoyed on compleation of the function.
183 * @param argc Standard main() style argc
184 * @param argc Standard main() style argv. Initial components are already
185 * stripped
187 * @return Normal NTSTATUS return.
190 static NTSTATUS rpc_changetrustpw_internals(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx,
191 int argc, const char **argv) {
193 return trust_pw_find_change_and_store_it(cli, mem_ctx, opt_target_workgroup);
196 /**
197 * Force a change of the trust acccount password.
199 * @param argc Standard main() style argc
200 * @param argc Standard main() style argv. Initial components are already
201 * stripped
203 * @return A shell status integer (0 for success)
206 int net_rpc_changetrustpw(int argc, const char **argv)
208 return run_rpc_command(NULL, PI_NETLOGON, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC, rpc_changetrustpw_internals,
209 argc, argv);
213 /****************************************************************************/
216 /**
217 * Join a domain, the old way.
219 * This uses 'machinename' as the inital password, and changes it.
221 * The password should be created with 'server manager' or equiv first.
223 * All parameters are provided by the run_rpc_command function, except for
224 * argc, argv which are passes through.
226 * @param domain_sid The domain sid aquired from the remote server
227 * @param cli A cli_state connected to the server.
228 * @param mem_ctx Talloc context, destoyed on compleation of the function.
229 * @param argc Standard main() style argc
230 * @param argc Standard main() style argv. Initial components are already
231 * stripped
233 * @return Normal NTSTATUS return.
236 static NTSTATUS rpc_oldjoin_internals(const DOM_SID *domain_sid, struct cli_state *cli,
237 TALLOC_CTX *mem_ctx,
238 int argc, const char **argv) {
240 fstring trust_passwd;
241 unsigned char orig_trust_passwd_hash[16];
242 NTSTATUS result;
243 uint32 sec_channel_type;
246 check what type of join - if the user want's to join as
247 a BDC, the server must agree that we are a BDC.
249 if (argc >= 0) {
250 sec_channel_type = get_sec_channel_type(argv[0]);
251 } else {
252 sec_channel_type = get_sec_channel_type(NULL);
255 fstrcpy(trust_passwd, global_myname());
256 strlower_m(trust_passwd);
259 * Machine names can be 15 characters, but the max length on
260 * a password is 14. --jerry
263 trust_passwd[14] = '\0';
265 E_md4hash(trust_passwd, orig_trust_passwd_hash);
267 result = trust_pw_change_and_store_it(cli, mem_ctx, opt_target_workgroup,
268 orig_trust_passwd_hash,
269 sec_channel_type);
271 if (NT_STATUS_IS_OK(result))
272 printf("Joined domain %s.\n",opt_target_workgroup);
275 if (!secrets_store_domain_sid(opt_target_workgroup, domain_sid)) {
276 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup));
277 result = NT_STATUS_UNSUCCESSFUL;
280 return result;
283 /**
284 * Join a domain, the old way.
286 * @param argc Standard main() style argc
287 * @param argc Standard main() style argv. Initial components are already
288 * stripped
290 * @return A shell status integer (0 for success)
293 static int net_rpc_oldjoin(int argc, const char **argv)
295 return run_rpc_command(NULL, PI_NETLOGON,
296 NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
297 rpc_oldjoin_internals,
298 argc, argv);
301 /**
302 * Basic usage function for 'net rpc join'
303 * @param argc Standard main() style argc
304 * @param argc Standard main() style argv. Initial components are already
305 * stripped
308 static int rpc_join_usage(int argc, const char **argv)
310 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
311 "\t to join a domain with admin username & password\n"\
312 "\t\t password will be prompted if needed and none is specified\n"\
313 "\t <type> can be (default MEMBER)\n"\
314 "\t\t BDC - Join as a BDC\n"\
315 "\t\t PDC - Join as a PDC\n"\
316 "\t\t MEMBER - Join as a MEMBER server\n");
318 net_common_flags_usage(argc, argv);
319 return -1;
322 /**
323 * 'net rpc join' entrypoint.
324 * @param argc Standard main() style argc
325 * @param argc Standard main() style argv. Initial components are already
326 * stripped
328 * Main 'net_rpc_join()' (where the admain username/password is used) is
329 * in net_rpc_join.c
330 * Try to just change the password, but if that doesn't work, use/prompt
331 * for a username/password.
334 int net_rpc_join(int argc, const char **argv)
336 if ((net_rpc_oldjoin(argc, argv) == 0))
337 return 0;
339 return net_rpc_join_newstyle(argc, argv);
344 /**
345 * display info about a rpc domain
347 * All parameters are provided by the run_rpc_command function, except for
348 * argc, argv which are passed through.
350 * @param domain_sid The domain sid acquired from the remote server
351 * @param cli A cli_state connected to the server.
352 * @param mem_ctx Talloc context, destoyed on completion of the function.
353 * @param argc Standard main() style argc
354 * @param argv Standard main() style argv. Initial components are already
355 * stripped
357 * @return Normal NTSTATUS return.
360 static NTSTATUS
361 rpc_info_internals(const DOM_SID *domain_sid, struct cli_state *cli,
362 TALLOC_CTX *mem_ctx, int argc, const char **argv)
364 POLICY_HND connect_pol, domain_pol;
365 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
366 SAM_UNK_CTR ctr;
367 fstring sid_str;
369 sid_to_string(sid_str, domain_sid);
371 /* Get sam policy handle */
372 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
373 &connect_pol);
374 if (!NT_STATUS_IS_OK(result)) {
375 goto done;
378 /* Get domain policy handle */
379 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
380 MAXIMUM_ALLOWED_ACCESS,
381 domain_sid, &domain_pol);
382 if (!NT_STATUS_IS_OK(result)) {
383 goto done;
386 ZERO_STRUCT(ctr);
387 result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
388 2, &ctr);
389 if (NT_STATUS_IS_OK(result)) {
390 TALLOC_CTX *ctx = talloc_init("rpc_info_internals");
391 d_printf("Domain Name: %s\n", unistr2_tdup(ctx, &ctr.info.inf2.uni_domain));
392 d_printf("Domain SID: %s\n", sid_str);
393 d_printf("Sequence number: %u\n", ctr.info.inf2.seq_num);
394 d_printf("Num users: %u\n", ctr.info.inf2.num_domain_usrs);
395 d_printf("Num domain groups: %u\n", ctr.info.inf2.num_domain_grps);
396 d_printf("Num local groups: %u\n", ctr.info.inf2.num_local_grps);
397 talloc_destroy(ctx);
400 done:
401 return result;
405 /**
406 * 'net rpc info' entrypoint.
407 * @param argc Standard main() style argc
408 * @param argc Standard main() style argv. Initial components are already
409 * stripped
411 int net_rpc_info(int argc, const char **argv)
413 return run_rpc_command(NULL, PI_SAMR, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
414 rpc_info_internals,
415 argc, argv);
419 /**
420 * Fetch domain SID into the local secrets.tdb
422 * All parameters are provided by the run_rpc_command function, except for
423 * argc, argv which are passes through.
425 * @param domain_sid The domain sid acquired from the remote server
426 * @param cli A cli_state connected to the server.
427 * @param mem_ctx Talloc context, destoyed on completion of the function.
428 * @param argc Standard main() style argc
429 * @param argv Standard main() style argv. Initial components are already
430 * stripped
432 * @return Normal NTSTATUS return.
435 static NTSTATUS
436 rpc_getsid_internals(const DOM_SID *domain_sid, struct cli_state *cli,
437 TALLOC_CTX *mem_ctx, int argc, const char **argv)
439 fstring sid_str;
441 sid_to_string(sid_str, domain_sid);
442 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
443 sid_str, lp_workgroup());
445 if (!secrets_store_domain_sid(global_myname(), domain_sid)) {
446 DEBUG(0,("Can't store domain SID\n"));
447 return NT_STATUS_UNSUCCESSFUL;
450 return NT_STATUS_OK;
454 /**
455 * 'net rpc getsid' entrypoint.
456 * @param argc Standard main() style argc
457 * @param argc Standard main() style argv. Initial components are already
458 * stripped
460 int net_rpc_getsid(int argc, const char **argv)
462 return run_rpc_command(NULL, PI_SAMR, NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
463 rpc_getsid_internals,
464 argc, argv);
468 /****************************************************************************/
471 * Basic usage function for 'net rpc user'
472 * @param argc Standard main() style argc.
473 * @param argv Standard main() style argv. Initial components are already
474 * stripped.
477 static int rpc_user_usage(int argc, const char **argv)
479 return net_help_user(argc, argv);
482 /**
483 * Add a new user to a remote RPC server
485 * All parameters are provided by the run_rpc_command function, except for
486 * argc, argv which are passes through.
488 * @param domain_sid The domain sid acquired from the remote server
489 * @param cli A cli_state connected to the server.
490 * @param mem_ctx Talloc context, destoyed on completion of the function.
491 * @param argc Standard main() style argc
492 * @param argv Standard main() style argv. Initial components are already
493 * stripped
495 * @return Normal NTSTATUS return.
498 static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx,
499 int argc, const char **argv) {
501 POLICY_HND connect_pol, domain_pol, user_pol;
502 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
503 const char *acct_name;
504 uint16 acb_info;
505 uint32 unknown, user_rid;
507 if (argc != 1) {
508 d_printf("User must be specified\n");
509 rpc_user_usage(argc, argv);
510 return NT_STATUS_OK;
513 acct_name = argv[0];
515 /* Get sam policy handle */
517 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
518 &connect_pol);
519 if (!NT_STATUS_IS_OK(result)) {
520 goto done;
523 /* Get domain policy handle */
525 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
526 MAXIMUM_ALLOWED_ACCESS,
527 domain_sid, &domain_pol);
528 if (!NT_STATUS_IS_OK(result)) {
529 goto done;
532 /* Create domain user */
534 acb_info = ACB_NORMAL;
535 unknown = 0xe005000b; /* No idea what this is - a permission mask? */
537 result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
538 acct_name, acb_info, unknown,
539 &user_pol, &user_rid);
540 if (!NT_STATUS_IS_OK(result)) {
541 goto done;
544 done:
545 if (!NT_STATUS_IS_OK(result)) {
546 d_printf("Failed to add user %s - %s\n", acct_name,
547 nt_errstr(result));
548 } else {
549 d_printf("Added user %s\n", acct_name);
551 return result;
554 /**
555 * Add a new user to a remote RPC server
557 * @param argc Standard main() style argc
558 * @param argv Standard main() style argv. Initial components are already
559 * stripped
561 * @return A shell status integer (0 for success)
564 static int rpc_user_add(int argc, const char **argv)
566 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_add_internals,
567 argc, argv);
570 /**
571 * Delete a user from a remote RPC server
573 * All parameters are provided by the run_rpc_command function, except for
574 * argc, argv which are passes through.
576 * @param domain_sid The domain sid acquired from the remote server
577 * @param cli A cli_state connected to the server.
578 * @param mem_ctx Talloc context, destoyed on completion of the function.
579 * @param argc Standard main() style argc
580 * @param argv Standard main() style argv. Initial components are already
581 * stripped
583 * @return Normal NTSTATUS return.
586 static NTSTATUS rpc_user_del_internals(const DOM_SID *domain_sid,
587 struct cli_state *cli,
588 TALLOC_CTX *mem_ctx,
589 int argc, const char **argv)
591 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
592 POLICY_HND connect_pol, domain_pol, user_pol;
594 if (argc < 1) {
595 d_printf("User must be specified\n");
596 rpc_user_usage(argc, argv);
597 return NT_STATUS_OK;
599 /* Get sam policy and domain handles */
601 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
602 &connect_pol);
604 if (!NT_STATUS_IS_OK(result)) {
605 goto done;
608 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
609 MAXIMUM_ALLOWED_ACCESS,
610 domain_sid, &domain_pol);
612 if (!NT_STATUS_IS_OK(result)) {
613 goto done;
616 /* Get handle on user */
619 uint32 *user_rids, num_rids, *name_types;
620 uint32 flags = 0x000003e8; /* Unknown */
622 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
623 flags, 1, &argv[0],
624 &num_rids, &user_rids,
625 &name_types);
627 if (!NT_STATUS_IS_OK(result)) {
628 goto done;
631 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
632 MAXIMUM_ALLOWED_ACCESS,
633 user_rids[0], &user_pol);
635 if (!NT_STATUS_IS_OK(result)) {
636 goto done;
640 /* Delete user */
642 result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
644 if (!NT_STATUS_IS_OK(result)) {
645 goto done;
648 /* Display results */
650 done:
651 return result;
655 /**
656 * Delete a user from a remote RPC server
658 * @param argc Standard main() style argc
659 * @param argv Standard main() style argv. Initial components are already
660 * stripped
662 * @return A shell status integer (0 for success)
665 static int rpc_user_delete(int argc, const char **argv)
667 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_del_internals,
668 argc, argv);
671 /**
672 * List user's groups on a remote RPC server
674 * All parameters are provided by the run_rpc_command function, except for
675 * argc, argv which are passes through.
677 * @param domain_sid The domain sid acquired from the remote server
678 * @param cli A cli_state connected to the server.
679 * @param mem_ctx Talloc context, destoyed on completion of the function.
680 * @param argc Standard main() style argc
681 * @param argv Standard main() style argv. Initial components are already
682 * stripped
684 * @return Normal NTSTATUS return.
687 static NTSTATUS
688 rpc_user_info_internals(const DOM_SID *domain_sid, struct cli_state *cli,
689 TALLOC_CTX *mem_ctx, int argc, const char **argv)
691 POLICY_HND connect_pol, domain_pol, user_pol;
692 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
693 uint32 *rids, num_rids, *name_types, num_names;
694 uint32 flags = 0x000003e8; /* Unknown */
695 int i;
696 char **names;
697 DOM_GID *user_gids;
699 if (argc < 1) {
700 d_printf("User must be specified\n");
701 rpc_user_usage(argc, argv);
702 return NT_STATUS_OK;
704 /* Get sam policy handle */
706 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
707 &connect_pol);
708 if (!NT_STATUS_IS_OK(result)) goto done;
710 /* Get domain policy handle */
712 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
713 MAXIMUM_ALLOWED_ACCESS,
714 domain_sid, &domain_pol);
715 if (!NT_STATUS_IS_OK(result)) goto done;
717 /* Get handle on user */
719 result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
720 flags, 1, &argv[0],
721 &num_rids, &rids, &name_types);
723 if (!NT_STATUS_IS_OK(result)) goto done;
725 result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
726 MAXIMUM_ALLOWED_ACCESS,
727 rids[0], &user_pol);
728 if (!NT_STATUS_IS_OK(result)) goto done;
730 result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
731 &num_rids, &user_gids);
733 /* Look up rids */
735 rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
737 for (i = 0; i < num_rids; i++)
738 rids[i] = user_gids[i].g_rid;
740 result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol,
741 flags, num_rids, rids,
742 &num_names, &names, &name_types);
744 if (!NT_STATUS_IS_OK(result)) {
745 goto done;
748 /* Display results */
750 for (i = 0; i < num_names; i++)
751 printf("%s\n", names[i]);
753 done:
754 return result;
757 /**
758 * List a user's groups from a remote RPC server
760 * @param argc Standard main() style argc
761 * @param argv Standard main() style argv. Initial components are already
762 * stripped
764 * @return A shell status integer (0 for success)
767 static int rpc_user_info(int argc, const char **argv)
769 return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_info_internals,
770 argc, argv);
773 /**
774 * List users on a remote RPC server
776 * All parameters are provided by the run_rpc_command function, except for
777 * argc, argv which are passes through.
779 * @param domain_sid The domain sid acquired from the remote server
780 * @param cli A cli_state connected to the server.
781 * @param mem_ctx Talloc context, destoyed on completion of the function.
782 * @param argc Standard main() style argc
783 * @param argv Standard main() style argv. Initial components are already
784 * stripped
786 * @return Normal NTSTATUS return.
789 static NTSTATUS
790 rpc_user_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
791 TALLOC_CTX *mem_ctx, int argc, const char **argv)
793 POLICY_HND connect_pol, domain_pol;
794 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
795 uint32 start_idx=0, num_entries, i, loop_count = 0;
796 SAM_DISPINFO_CTR ctr;
797 SAM_DISPINFO_1 info1;
799 /* Get sam policy handle */
801 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
802 &connect_pol);
803 if (!NT_STATUS_IS_OK(result)) {
804 goto done;
807 /* Get domain policy handle */
809 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
810 MAXIMUM_ALLOWED_ACCESS,
811 domain_sid, &domain_pol);
812 if (!NT_STATUS_IS_OK(result)) {
813 goto done;
816 /* Query domain users */
817 ZERO_STRUCT(ctr);
818 ZERO_STRUCT(info1);
819 ctr.sam.info1 = &info1;
820 if (opt_long_list_entries)
821 d_printf("\nUser name Comment"\
822 "\n-----------------------------\n");
823 do {
824 fstring user, desc;
825 uint32 max_entries, max_size;
827 get_query_dispinfo_params(
828 loop_count, &max_entries, &max_size);
830 result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
831 &start_idx, 1, &num_entries,
832 max_entries, max_size, &ctr);
833 loop_count++;
835 for (i = 0; i < num_entries; i++) {
836 unistr2_to_ascii(user, &(&ctr.sam.info1->str[i])->uni_acct_name, sizeof(user)-1);
837 if (opt_long_list_entries)
838 unistr2_to_ascii(desc, &(&ctr.sam.info1->str[i])->uni_acct_desc, sizeof(desc)-1);
840 if (opt_long_list_entries)
841 printf("%-21.21s %s\n", user, desc);
842 else
843 printf("%s\n", user);
845 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
847 done:
848 return result;
851 /**
852 * 'net rpc user' entrypoint.
853 * @param argc Standard main() style argc
854 * @param argc Standard main() style argv. Initial components are already
855 * stripped
858 int net_rpc_user(int argc, const char **argv)
860 struct functable func[] = {
861 {"add", rpc_user_add},
862 {"info", rpc_user_info},
863 {"delete", rpc_user_delete},
864 {NULL, NULL}
867 if (argc == 0) {
868 if (opt_long_list_entries) {
869 } else {
871 return run_rpc_command(NULL,PI_SAMR, 0,
872 rpc_user_list_internals,
873 argc, argv);
876 return net_run_function(argc, argv, func, rpc_user_usage);
880 /****************************************************************************/
883 * Basic usage function for 'net rpc group'
884 * @param argc Standard main() style argc.
885 * @param argv Standard main() style argv. Initial components are already
886 * stripped.
889 static int rpc_group_usage(int argc, const char **argv)
891 return net_help_group(argc, argv);
894 /**
895 * List groups on a remote RPC server
897 * All parameters are provided by the run_rpc_command function, except for
898 * argc, argv which are passes through.
900 * @param domain_sid The domain sid acquired from the remote server
901 * @param cli A cli_state connected to the server.
902 * @param mem_ctx Talloc context, destoyed on completion of the function.
903 * @param argc Standard main() style argc
904 * @param argv Standard main() style argv. Initial components are already
905 * stripped
907 * @return Normal NTSTATUS return.
910 static NTSTATUS
911 rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
912 TALLOC_CTX *mem_ctx, int argc, const char **argv)
914 POLICY_HND connect_pol, domain_pol;
915 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
916 uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
917 struct acct_info *groups;
918 DOM_SID global_sid_Builtin;
920 string_to_sid(&global_sid_Builtin, "S-1-5-32");
922 /* Get sam policy handle */
924 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
925 &connect_pol);
926 if (!NT_STATUS_IS_OK(result)) {
927 goto done;
930 /* Get domain policy handle */
932 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
933 MAXIMUM_ALLOWED_ACCESS,
934 domain_sid, &domain_pol);
935 if (!NT_STATUS_IS_OK(result)) {
936 goto done;
939 /* Query domain groups */
940 if (opt_long_list_entries)
941 d_printf("\nGroup name Comment"\
942 "\n-----------------------------\n");
943 do {
944 SAM_DISPINFO_CTR ctr;
945 SAM_DISPINFO_3 info3;
946 uint32 max_size;
948 ZERO_STRUCT(ctr);
949 ZERO_STRUCT(info3);
950 ctr.sam.info3 = &info3;
952 get_query_dispinfo_params(
953 loop_count, &max_entries, &max_size);
955 result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
956 &start_idx, 3, &num_entries,
957 max_entries, max_size, &ctr);
959 for (i = 0; i < num_entries; i++) {
961 fstring group, desc;
963 unistr2_to_ascii(group, &(&ctr.sam.info3->str[i])->uni_grp_name, sizeof(group)-1);
964 unistr2_to_ascii(desc, &(&ctr.sam.info3->str[i])->uni_grp_desc, sizeof(desc)-1);
966 if (opt_long_list_entries)
967 printf("%-21.21s %-50.50s\n",
968 group, desc);
969 else
970 printf("%-21.21s\n", group);
972 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
973 /* query domain aliases */
974 start_idx = 0;
975 do {
976 result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
977 &start_idx, max_entries,
978 &groups, &num_entries);
980 for (i = 0; i < num_entries; i++) {
982 char *description = NULL;
984 if (opt_long_list_entries) {
986 POLICY_HND alias_pol;
987 ALIAS_INFO_CTR ctr;
989 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli, mem_ctx,
990 &domain_pol,
991 0x8,
992 groups[i].rid,
993 &alias_pol))) &&
994 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli, mem_ctx,
995 &alias_pol, 3,
996 &ctr))) &&
997 (NT_STATUS_IS_OK(cli_samr_close(cli, mem_ctx,
998 &alias_pol)))) {
999 description = unistr2_tdup(mem_ctx,
1000 &ctr.alias.info3.uni_acct_desc);
1004 if (description != NULL) {
1005 printf("%-21.21s %-50.50s\n",
1006 groups[i].acct_name,
1007 description);
1008 } else {
1009 printf("%-21.21s\n", groups[i].acct_name);
1012 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1013 cli_samr_close(cli, mem_ctx, &domain_pol);
1014 /* Get builtin policy handle */
1016 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1017 MAXIMUM_ALLOWED_ACCESS,
1018 &global_sid_Builtin, &domain_pol);
1019 if (!NT_STATUS_IS_OK(result)) {
1020 goto done;
1022 /* query builtin aliases */
1023 start_idx = 0;
1024 do {
1025 result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
1026 &start_idx, max_entries,
1027 &groups, &num_entries);
1029 for (i = 0; i < num_entries; i++) {
1031 char *description = NULL;
1033 if (opt_long_list_entries) {
1035 POLICY_HND alias_pol;
1036 ALIAS_INFO_CTR ctr;
1038 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli, mem_ctx,
1039 &domain_pol,
1040 0x8,
1041 groups[i].rid,
1042 &alias_pol))) &&
1043 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli, mem_ctx,
1044 &alias_pol, 3,
1045 &ctr))) &&
1046 (NT_STATUS_IS_OK(cli_samr_close(cli, mem_ctx,
1047 &alias_pol)))) {
1048 description = unistr2_tdup(mem_ctx,
1049 &ctr.alias.info3.uni_acct_desc);
1053 if (description != NULL) {
1054 printf("%-21.21s %-50.50s\n",
1055 groups[i].acct_name,
1056 description);
1057 } else {
1058 printf("%-21.21s\n", groups[i].acct_name);
1061 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1063 done:
1064 return result;
1067 /**
1068 * 'net rpc group' entrypoint.
1069 * @param argc Standard main() style argc
1070 * @param argc Standard main() style argv. Initial components are already
1071 * stripped
1074 int net_rpc_group(int argc, const char **argv)
1076 struct functable func[] = {
1077 #if 0
1078 {"add", rpc_group_add},
1079 {"delete", rpc_group_delete},
1080 #endif
1081 {NULL, NULL}
1084 if (argc == 0) {
1085 if (opt_long_list_entries) {
1086 } else {
1088 return run_rpc_command(NULL, PI_SAMR, 0,
1089 rpc_group_list_internals,
1090 argc, argv);
1093 return net_run_function(argc, argv, func, rpc_group_usage);
1096 /****************************************************************************/
1098 static int rpc_share_usage(int argc, const char **argv)
1100 return net_help_share(argc, argv);
1103 /**
1104 * Add a share on a remote RPC server
1106 * All parameters are provided by the run_rpc_command function, except for
1107 * argc, argv which are passes through.
1109 * @param domain_sid The domain sid acquired from the remote server
1110 * @param cli A cli_state connected to the server.
1111 * @param mem_ctx Talloc context, destoyed on completion of the function.
1112 * @param argc Standard main() style argc
1113 * @param argv Standard main() style argv. Initial components are already
1114 * stripped
1116 * @return Normal NTSTATUS return.
1118 static NTSTATUS
1119 rpc_share_add_internals(const DOM_SID *domain_sid, struct cli_state *cli,
1120 TALLOC_CTX *mem_ctx,int argc, const char **argv)
1122 WERROR result;
1123 char *sharename=talloc_strdup(mem_ctx, argv[0]);
1124 char *path;
1125 uint32 type=0; /* only allow disk shares to be added */
1126 uint32 num_users=0, perms=0;
1127 char *password=NULL; /* don't allow a share password */
1129 path = strchr(sharename, '=');
1130 if (!path)
1131 return NT_STATUS_UNSUCCESSFUL;
1132 *path++ = '\0';
1134 result = cli_srvsvc_net_share_add(cli, mem_ctx, sharename, type,
1135 opt_comment, perms, opt_maxusers,
1136 num_users, path, password);
1137 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1140 static int rpc_share_add(int argc, const char **argv)
1142 if ((argc < 1) || !strchr(argv[0], '=')) {
1143 DEBUG(1,("Sharename or path not specified on add\n"));
1144 return rpc_share_usage(argc, argv);
1146 return run_rpc_command(NULL, PI_SRVSVC, 0,
1147 rpc_share_add_internals,
1148 argc, argv);
1151 /**
1152 * Delete a share on a remote RPC server
1154 * All parameters are provided by the run_rpc_command function, except for
1155 * argc, argv which are passes through.
1157 * @param domain_sid The domain sid acquired from the remote server
1158 * @param cli A cli_state connected to the server.
1159 * @param mem_ctx Talloc context, destoyed on completion of the function.
1160 * @param argc Standard main() style argc
1161 * @param argv Standard main() style argv. Initial components are already
1162 * stripped
1164 * @return Normal NTSTATUS return.
1166 static NTSTATUS
1167 rpc_share_del_internals(const DOM_SID *domain_sid, struct cli_state *cli,
1168 TALLOC_CTX *mem_ctx,int argc, const char **argv)
1170 WERROR result;
1172 result = cli_srvsvc_net_share_del(cli, mem_ctx, argv[0]);
1173 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1176 /**
1177 * Delete a share on a remote RPC server
1179 * @param domain_sid The domain sid acquired from the remote server
1180 * @param argc Standard main() style argc
1181 * @param argv Standard main() style argv. Initial components are already
1182 * stripped
1184 * @return A shell status integer (0 for success)
1186 static int rpc_share_delete(int argc, const char **argv)
1188 if (argc < 1) {
1189 DEBUG(1,("Sharename not specified on delete\n"));
1190 return rpc_share_usage(argc, argv);
1192 return run_rpc_command(NULL, PI_SRVSVC, 0,
1193 rpc_share_del_internals,
1194 argc, argv);
1198 * Formatted print of share info
1200 * @param info1 pointer to SRV_SHARE_INFO_1 to format
1203 static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
1205 fstring netname = "", remark = "";
1207 rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
1208 rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
1210 if (opt_long_list_entries) {
1211 d_printf("%-12.12s %-8.8s %-50.50s\n",
1212 netname, share_type[info1->info_1.type], remark);
1213 } else {
1214 d_printf("%-12.12s\n", netname);
1219 /**
1220 * List shares on a remote RPC server
1222 * All parameters are provided by the run_rpc_command function, except for
1223 * argc, argv which are passes through.
1225 * @param domain_sid The domain sid acquired from the remote server
1226 * @param cli A cli_state connected to the server.
1227 * @param mem_ctx Talloc context, destoyed on completion of the function.
1228 * @param argc Standard main() style argc
1229 * @param argv Standard main() style argv. Initial components are already
1230 * stripped
1232 * @return Normal NTSTATUS return.
1235 static NTSTATUS
1236 rpc_share_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
1237 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1239 SRV_SHARE_INFO_CTR ctr;
1240 WERROR result;
1241 ENUM_HND hnd;
1242 uint32 preferred_len = 0xffffffff, i;
1244 init_enum_hnd(&hnd, 0);
1246 result = cli_srvsvc_net_share_enum(
1247 cli, mem_ctx, 1, &ctr, preferred_len, &hnd);
1249 if (!W_ERROR_IS_OK(result))
1250 goto done;
1252 /* Display results */
1254 if (opt_long_list_entries) {
1255 d_printf(
1256 "\nEnumerating shared resources (exports) on remote server:\n\n"\
1257 "\nShare name Type Description\n"\
1258 "---------- ---- -----------\n");
1260 for (i = 0; i < ctr.num_entries; i++)
1261 display_share_info_1(&ctr.share.info1[i]);
1262 done:
1263 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1266 /**
1267 * 'net rpc share' entrypoint.
1268 * @param argc Standard main() style argc
1269 * @param argv Standard main() style argv. Initial components are already
1270 * stripped
1273 int net_rpc_share(int argc, const char **argv)
1275 struct functable func[] = {
1276 {"add", rpc_share_add},
1277 {"delete", rpc_share_delete},
1278 {NULL, NULL}
1281 if (argc == 0)
1282 return run_rpc_command(NULL, PI_SRVSVC, 0,
1283 rpc_share_list_internals,
1284 argc, argv);
1286 return net_run_function(argc, argv, func, rpc_share_usage);
1289 /****************************************************************************/
1291 static int rpc_file_usage(int argc, const char **argv)
1293 return net_help_file(argc, argv);
1296 /**
1297 * Close a file on a remote RPC server
1299 * All parameters are provided by the run_rpc_command function, except for
1300 * argc, argv which are passes through.
1302 * @param domain_sid The domain sid acquired from the remote server
1303 * @param cli A cli_state connected to the server.
1304 * @param mem_ctx Talloc context, destoyed on completion of the function.
1305 * @param argc Standard main() style argc
1306 * @param argv Standard main() style argv. Initial components are already
1307 * stripped
1309 * @return Normal NTSTATUS return.
1311 static NTSTATUS
1312 rpc_file_close_internals(const DOM_SID *domain_sid, struct cli_state *cli,
1313 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1315 WERROR result;
1316 result = cli_srvsvc_net_file_close(cli, mem_ctx, atoi(argv[0]));
1317 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1320 /**
1321 * Close a file on a remote RPC server
1323 * @param argc Standard main() style argc
1324 * @param argv Standard main() style argv. Initial components are already
1325 * stripped
1327 * @return A shell status integer (0 for success)
1329 static int rpc_file_close(int argc, const char **argv)
1331 if (argc < 1) {
1332 DEBUG(1, ("No fileid given on close\n"));
1333 return(rpc_file_usage(argc, argv));
1336 return run_rpc_command(NULL, PI_SRVSVC, 0,
1337 rpc_file_close_internals,
1338 argc, argv);
1341 /**
1342 * Formatted print of open file info
1344 * @param info3 FILE_INFO_3 contents
1345 * @param str3 strings for FILE_INFO_3
1348 static void display_file_info_3(FILE_INFO_3 *info3, FILE_INFO_3_STR *str3)
1350 fstring user = "", path = "";
1352 rpcstr_pull_unistr2_fstring(user, &str3->uni_user_name);
1353 rpcstr_pull_unistr2_fstring(path, &str3->uni_path_name);
1355 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
1356 info3->id, user, info3->perms, info3->num_locks, path);
1359 /**
1360 * List open files on a remote RPC server
1362 * All parameters are provided by the run_rpc_command function, except for
1363 * argc, argv which are passes through.
1365 * @param domain_sid The domain sid acquired from the remote server
1366 * @param cli A cli_state connected to the server.
1367 * @param mem_ctx Talloc context, destoyed on completion of the function.
1368 * @param argc Standard main() style argc
1369 * @param argv Standard main() style argv. Initial components are already
1370 * stripped
1372 * @return Normal NTSTATUS return.
1375 static NTSTATUS
1376 rpc_file_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
1377 TALLOC_CTX *mem_ctx, int argc, const char **argv)
1379 SRV_FILE_INFO_CTR ctr;
1380 WERROR result;
1381 ENUM_HND hnd;
1382 uint32 preferred_len = 0xffffffff, i;
1383 const char *username=NULL;
1385 init_enum_hnd(&hnd, 0);
1387 /* if argc > 0, must be user command */
1388 if (argc > 0)
1389 username = smb_xstrdup(argv[0]);
1391 result = cli_srvsvc_net_file_enum(
1392 cli, mem_ctx, 3, username, &ctr, preferred_len, &hnd);
1394 if (!W_ERROR_IS_OK(result))
1395 goto done;
1397 /* Display results */
1399 d_printf(
1400 "\nEnumerating open files on remote server:\n\n"\
1401 "\nFileId Opened by Perms Locks Path"\
1402 "\n------ --------- ----- ----- ---- \n");
1403 for (i = 0; i < ctr.num_entries; i++)
1404 display_file_info_3(&ctr.file.info3[i].info_3,
1405 &ctr.file.info3[i].info_3_str);
1406 done:
1407 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1411 /**
1412 * List files for a user on a remote RPC server
1414 * @param argc Standard main() style argc
1415 * @param argv Standard main() style argv. Initial components are already
1416 * stripped
1418 * @return A shell status integer (0 for success)
1420 static int rpc_file_user(int argc, const char **argv)
1422 if (argc < 1) {
1423 DEBUG(1, ("No username given\n"));
1424 return(rpc_file_usage(argc, argv));
1427 return run_rpc_command(NULL, PI_SRVSVC, 0,
1428 rpc_file_list_internals,
1429 argc, argv);
1433 /**
1434 * 'net rpc file' entrypoint.
1435 * @param argc Standard main() style argc
1436 * @param argv Standard main() style argv. Initial components are already
1437 * stripped
1440 int net_rpc_file(int argc, const char **argv)
1442 struct functable func[] = {
1443 {"close", rpc_file_close},
1444 {"user", rpc_file_user},
1445 #if 0
1446 {"info", rpc_file_info},
1447 #endif
1448 {NULL, NULL}
1451 if (argc == 0)
1452 return run_rpc_command(NULL, PI_SRVSVC, 0,
1453 rpc_file_list_internals,
1454 argc, argv);
1456 return net_run_function(argc, argv, func, rpc_file_usage);
1459 /****************************************************************************/
1463 /**
1464 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
1466 * All parameters are provided by the run_rpc_command function, except for
1467 * argc, argv which are passed through.
1469 * @param domain_sid The domain sid aquired from the remote server
1470 * @param cli A cli_state connected to the server.
1471 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1472 * @param argc Standard main() style argc
1473 * @param argv Standard main() style argv. Initial components are already
1474 * stripped
1476 * @return Normal NTSTATUS return.
1479 static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid,
1480 struct cli_state *cli,
1481 TALLOC_CTX *mem_ctx,
1482 int argc, const char **argv)
1484 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1486 result = cli_shutdown_abort(cli, mem_ctx);
1488 if (NT_STATUS_IS_OK(result))
1489 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
1490 else
1491 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
1493 return result;
1497 /**
1498 * ABORT the shutdown of a remote RPC Server, over winreg pipe
1500 * All parameters are provided by the run_rpc_command function, except for
1501 * argc, argv which are passed through.
1503 * @param domain_sid The domain sid aquired from the remote server
1504 * @param cli A cli_state connected to the server.
1505 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1506 * @param argc Standard main() style argc
1507 * @param argv Standard main() style argv. Initial components are already
1508 * stripped
1510 * @return Normal NTSTATUS return.
1513 static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid,
1514 struct cli_state *cli,
1515 TALLOC_CTX *mem_ctx,
1516 int argc, const char **argv)
1518 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1520 result = cli_reg_abort_shutdown(cli, mem_ctx);
1522 if (NT_STATUS_IS_OK(result))
1523 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
1524 else
1525 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
1527 return result;
1530 /**
1531 * ABORT the Shut down of a remote RPC server
1533 * @param argc Standard main() style argc
1534 * @param argv Standard main() style argv. Initial components are already
1535 * stripped
1537 * @return A shell status integer (0 for success)
1540 static int rpc_shutdown_abort(int argc, const char **argv)
1542 int rc = run_rpc_command(NULL, PI_SHUTDOWN, 0,
1543 rpc_shutdown_abort_internals,
1544 argc, argv);
1546 if (rc == 0)
1547 return rc;
1549 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
1551 return run_rpc_command(NULL, PI_WINREG, 0,
1552 rpc_reg_shutdown_abort_internals,
1553 argc, argv);
1556 /**
1557 * Shut down a remote RPC Server
1559 * All parameters are provided by the run_rpc_command function, except for
1560 * argc, argv which are passes through.
1562 * @param domain_sid The domain sid aquired from the remote server
1563 * @param cli A cli_state connected to the server.
1564 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1565 * @param argc Standard main() style argc
1566 * @param argc Standard main() style argv. Initial components are already
1567 * stripped
1569 * @return Normal NTSTATUS return.
1572 static NTSTATUS rpc_shutdown_internals(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx,
1573 int argc, const char **argv)
1575 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1576 const char *msg = "This machine will be shutdown shortly";
1577 uint32 timeout = 20;
1578 #if 0
1579 poptContext pc;
1580 int rc;
1582 struct poptOption long_options[] = {
1583 {"message", 'm', POPT_ARG_STRING, &msg},
1584 {"timeout", 't', POPT_ARG_INT, &timeout},
1585 {"reboot", 'r', POPT_ARG_NONE, &reboot},
1586 {"force", 'f', POPT_ARG_NONE, &force},
1587 { 0, 0, 0, 0}
1590 pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
1591 POPT_CONTEXT_KEEP_FIRST);
1593 rc = poptGetNextOpt(pc);
1595 if (rc < -1) {
1596 /* an error occurred during option processing */
1597 DEBUG(0, ("%s: %s\n",
1598 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1599 poptStrerror(rc)));
1600 return NT_STATUS_INVALID_PARAMETER;
1602 #endif
1603 if (opt_comment) {
1604 msg = opt_comment;
1606 if (opt_timeout) {
1607 timeout = opt_timeout;
1610 /* create an entry */
1611 result = cli_reg_shutdown(cli, mem_ctx, msg, timeout, opt_reboot, opt_force);
1613 if (NT_STATUS_IS_OK(result))
1614 DEBUG(5,("Shutdown of remote machine succeeded\n"));
1615 else
1616 DEBUG(0,("Shutdown of remote machine failed!\n"));
1618 return result;
1621 /**
1622 * Shut down a remote RPC server
1624 * @param argc Standard main() style argc
1625 * @param argc Standard main() style argv. Initial components are already
1626 * stripped
1628 * @return A shell status integer (0 for success)
1631 static int rpc_shutdown(int argc, const char **argv)
1633 return run_rpc_command(NULL, PI_WINREG, 0, rpc_shutdown_internals,
1634 argc, argv);
1637 /***************************************************************************
1638 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
1640 ***************************************************************************/
1643 * Add interdomain trust account to the RPC server.
1644 * All parameters (except for argc and argv) are passed by run_rpc_command
1645 * function.
1647 * @param domain_sid The domain sid acquired from the server
1648 * @param cli A cli_state connected to the server.
1649 * @param mem_ctx Talloc context, destoyed on completion of the function.
1650 * @param argc Standard main() style argc
1651 * @param argc Standard main() style argv. Initial components are already
1652 * stripped
1654 * @return normal NTSTATUS return code
1657 static NTSTATUS rpc_trustdom_add_internals(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx,
1658 int argc, const char **argv) {
1660 POLICY_HND connect_pol, domain_pol, user_pol;
1661 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1662 char *acct_name;
1663 uint16 acb_info;
1664 uint32 unknown, user_rid;
1666 if (argc != 2) {
1667 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
1668 return NT_STATUS_INVALID_PARAMETER;
1672 * Make valid trusting domain account (ie. uppercased and with '$' appended)
1675 if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
1676 return NT_STATUS_NO_MEMORY;
1679 strupper_m(acct_name);
1681 /* Get samr policy handle */
1682 result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
1683 &connect_pol);
1684 if (!NT_STATUS_IS_OK(result)) {
1685 goto done;
1688 /* Get domain policy handle */
1689 result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
1690 MAXIMUM_ALLOWED_ACCESS,
1691 domain_sid, &domain_pol);
1692 if (!NT_STATUS_IS_OK(result)) {
1693 goto done;
1696 /* Create trusting domain's account */
1697 acb_info = ACB_DOMTRUST;
1698 unknown = 0xe00500b0; /* No idea what this is - a permission mask?
1699 mimir: yes, most probably it is */
1701 result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
1702 acct_name, acb_info, unknown,
1703 &user_pol, &user_rid);
1704 if (!NT_STATUS_IS_OK(result)) {
1705 goto done;
1709 SAM_USERINFO_CTR ctr;
1710 SAM_USER_INFO_24 p24;
1711 fstring ucs2_trust_password;
1712 int ucs2_pw_len;
1713 uchar pwbuf[516];
1715 ucs2_pw_len = push_ucs2(NULL, ucs2_trust_password, argv[1],
1716 sizeof(ucs2_trust_password), 0);
1718 encode_pw_buffer((char *)pwbuf, ucs2_trust_password,
1719 ucs2_pw_len);
1721 ZERO_STRUCT(ctr);
1722 ZERO_STRUCT(p24);
1724 init_sam_user_info24(&p24, (char *)pwbuf, 24);
1726 ctr.switch_value = 24;
1727 ctr.info.id24 = &p24;
1729 result = cli_samr_set_userinfo(cli, mem_ctx, &user_pol, 24,
1730 cli->user_session_key, &ctr);
1732 if (!NT_STATUS_IS_OK(result)) {
1733 DEBUG(0,("Could not set trust account password: %s\n",
1734 nt_errstr(result)));
1735 goto done;
1739 done:
1740 SAFE_FREE(acct_name);
1741 return result;
1745 * Create interdomain trust account for a remote domain.
1747 * @param argc standard argc
1748 * @param argv standard argv without initial components
1750 * @return Integer status (0 means success)
1753 static int rpc_trustdom_add(int argc, const char **argv)
1755 if (argc > 0) {
1756 return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
1757 argc, argv);
1758 } else {
1759 d_printf("Usage: net rpc trustdom add <domain>\n");
1760 return -1;
1766 * Delete interdomain trust account for a remote domain.
1768 * @param argc standard argc
1769 * @param argv standard argv without initial components
1771 * @return Integer status (0 means success)
1774 static int rpc_trustdom_del(int argc, const char **argv)
1776 d_printf("Sorry, not yet implemented.\n");
1777 d_printf("Use 'smbpasswd -x -i' instead.\n");
1778 return -1;
1783 * Establish trust relationship to a trusting domain.
1784 * Interdomain account must already be created on remote PDC.
1786 * @param argc standard argc
1787 * @param argv standard argv without initial components
1789 * @return Integer status (0 means success)
1792 static int rpc_trustdom_establish(int argc, const char **argv)
1794 struct cli_state *cli;
1795 struct in_addr server_ip;
1796 POLICY_HND connect_hnd;
1797 TALLOC_CTX *mem_ctx;
1798 NTSTATUS nt_status;
1799 DOM_SID domain_sid;
1800 WKS_INFO_100 wks_info;
1802 char* domain_name;
1803 char* acct_name;
1804 fstring pdc_name;
1807 * Connect to \\server\ipc$ as 'our domain' account with password
1810 if (argc != 1) {
1811 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
1812 return -1;
1815 domain_name = smb_xstrdup(argv[0]);
1816 strupper_m(domain_name);
1818 /* account name used at first is our domain's name with '$' */
1819 asprintf(&acct_name, "%s$", lp_workgroup());
1820 strupper_m(acct_name);
1823 * opt_workgroup will be used by connection functions further,
1824 * hence it should be set to remote domain name instead of ours
1826 if (opt_workgroup) {
1827 opt_workgroup = smb_xstrdup(domain_name);
1830 opt_user_name = acct_name;
1832 /* find the domain controller */
1833 if (!net_find_pdc(&server_ip, pdc_name, domain_name)) {
1834 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
1835 return -1;
1838 /* connect to ipc$ as username/password */
1839 nt_status = connect_to_ipc(&cli, &server_ip, pdc_name);
1840 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
1842 /* Is it trusting domain account for sure ? */
1843 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
1844 nt_errstr(nt_status)));
1845 return -1;
1849 * Connect to \\server\ipc$ again (this time anonymously)
1852 nt_status = connect_to_ipc_anonymous(&cli, &server_ip, (char*)pdc_name);
1854 if (NT_STATUS_IS_ERR(nt_status)) {
1855 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
1856 domain_name, nt_errstr(nt_status)));
1860 * Use NetServerEnum2 to make sure we're talking to a proper server
1863 if (!cli_get_pdc_name(cli, domain_name, (char*)pdc_name)) {
1864 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
1865 for domain %s\n", domain_name));
1869 * Call WksQueryInfo to check remote server's capabilities
1870 * note: It is now used only to get unicode domain name
1873 if (!cli_nt_session_open(cli, PI_WKSSVC)) {
1874 DEBUG(0, ("Couldn't not initialise wkssvc pipe\n"));
1875 return -1;
1878 if (!(mem_ctx = talloc_init("establishing trust relationship to domain %s",
1879 domain_name))) {
1880 DEBUG(0, ("talloc_init() failed\n"));
1881 cli_shutdown(cli);
1882 return -1;
1885 nt_status = cli_wks_query_info(cli, mem_ctx, &wks_info);
1887 if (NT_STATUS_IS_ERR(nt_status)) {
1888 DEBUG(0, ("WksQueryInfo call failed.\n"));
1889 return -1;
1892 if (cli->nt_pipe_fnum)
1893 cli_nt_session_close(cli);
1897 * Call LsaOpenPolicy and LsaQueryInfo
1900 if (!(mem_ctx = talloc_init("rpc_trustdom_establish"))) {
1901 DEBUG(0, ("talloc_init() failed\n"));
1902 cli_shutdown(cli);
1903 return -1;
1906 if (!cli_nt_session_open(cli, PI_LSARPC)) {
1907 DEBUG(0, ("Could not initialise lsa pipe\n"));
1908 cli_shutdown(cli);
1909 return -1;
1912 nt_status = cli_lsa_open_policy2(cli, mem_ctx, True, SEC_RIGHTS_QUERY_VALUE,
1913 &connect_hnd);
1914 if (NT_STATUS_IS_ERR(nt_status)) {
1915 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
1916 nt_errstr(nt_status)));
1917 return -1;
1920 /* Querying info level 5 */
1922 nt_status = cli_lsa_query_info_policy(cli, mem_ctx, &connect_hnd,
1923 5 /* info level */, domain_name,
1924 &domain_sid);
1925 if (NT_STATUS_IS_ERR(nt_status)) {
1926 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
1927 nt_errstr(nt_status)));
1928 return -1;
1934 /* There should be actually query info level 3 (following nt serv behaviour),
1935 but I still don't know if it's _really_ necessary */
1938 * Store the password in secrets db
1941 if (!secrets_store_trusted_domain_password(domain_name, wks_info.uni_lan_grp.buffer,
1942 wks_info.uni_lan_grp.uni_str_len, opt_password,
1943 domain_sid)) {
1944 DEBUG(0, ("Storing password for trusted domain failed.\n"));
1945 return -1;
1949 * Close the pipes and clean up
1952 nt_status = cli_lsa_close(cli, mem_ctx, &connect_hnd);
1953 if (NT_STATUS_IS_ERR(nt_status)) {
1954 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
1955 nt_errstr(nt_status)));
1956 return -1;
1959 if (cli->nt_pipe_fnum)
1960 cli_nt_session_close(cli);
1962 talloc_destroy(mem_ctx);
1964 DEBUG(0, ("Success!\n"));
1965 return 0;
1969 * Revoke trust relationship to the remote domain
1971 * @param argc standard argc
1972 * @param argv standard argv without initial components
1974 * @return Integer status (0 means success)
1977 static int rpc_trustdom_revoke(int argc, const char **argv)
1979 char* domain_name;
1981 if (argc < 1) return -1;
1983 /* generate upper cased domain name */
1984 domain_name = smb_xstrdup(argv[0]);
1985 strupper_m(domain_name);
1987 /* delete password of the trust */
1988 if (!trusted_domain_password_delete(domain_name)) {
1989 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
1990 domain_name));
1991 return -1;
1994 return 0;
1998 * Usage for 'net rpc trustdom' command
2000 * @param argc standard argc
2001 * @param argv standard argv without inital components
2003 * @return Integer status returned to shell
2006 static int rpc_trustdom_usage(int argc, const char **argv)
2008 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
2009 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
2010 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
2011 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
2012 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
2013 return -1;
2017 static NTSTATUS rpc_query_domain_sid(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx,
2018 int argc, const char **argv)
2020 fstring str_sid;
2021 sid_to_string(str_sid, domain_sid);
2022 d_printf("%s\n", str_sid);
2023 return NT_STATUS_OK;
2027 static int rpc_trustdom_list(int argc, const char **argv)
2029 /* common variables */
2030 TALLOC_CTX* mem_ctx;
2031 struct cli_state *cli, *remote_cli;
2032 NTSTATUS nt_status;
2033 const char *domain_name = NULL;
2034 DOM_SID queried_dom_sid;
2035 fstring ascii_sid, padding;
2036 int ascii_dom_name_len;
2037 POLICY_HND connect_hnd;
2039 /* trusted domains listing variables */
2040 unsigned int num_domains, enum_ctx = 0;
2041 int i, pad_len, col_len = 20;
2042 DOM_SID *domain_sids;
2043 char **trusted_dom_names;
2044 fstring pdc_name, dummy;
2046 /* trusting domains listing variables */
2047 POLICY_HND domain_hnd;
2048 char **trusting_dom_names;
2049 uint32 *trusting_dom_rids;
2052 * Listing trusted domains (stored in secrets.tdb, if local)
2055 mem_ctx = talloc_init("trust relationships listing");
2058 * set domain and pdc name to local samba server (default)
2059 * or to remote one given in command line
2062 if (StrCaseCmp(opt_workgroup, lp_workgroup())) {
2063 domain_name = opt_workgroup;
2064 opt_target_workgroup = opt_workgroup;
2065 } else {
2066 fstrcpy(pdc_name, global_myname());
2067 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
2068 opt_target_workgroup = domain_name;
2071 /* open \PIPE\lsarpc and open policy handle */
2072 if (!(cli = net_make_ipc_connection(NET_FLAGS_PDC))) {
2073 DEBUG(0, ("Couldn't connect to domain controller\n"));
2074 return -1;
2077 if (!cli_nt_session_open(cli, PI_LSARPC)) {
2078 DEBUG(0, ("Could not initialise lsa pipe\n"));
2079 return -1;
2082 nt_status = cli_lsa_open_policy2(cli, mem_ctx, False, SEC_RIGHTS_QUERY_VALUE,
2083 &connect_hnd);
2084 if (NT_STATUS_IS_ERR(nt_status)) {
2085 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
2086 nt_errstr(nt_status)));
2087 return -1;
2090 /* query info level 5 to obtain sid of a domain being queried */
2091 nt_status = cli_lsa_query_info_policy(
2092 cli, mem_ctx, &connect_hnd, 5 /* info level */,
2093 dummy, &queried_dom_sid);
2095 if (NT_STATUS_IS_ERR(nt_status)) {
2096 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
2097 nt_errstr(nt_status)));
2098 return -1;
2102 * Keep calling LsaEnumTrustdom over opened pipe until
2103 * the end of enumeration is reached
2106 d_printf("Trusted domains list:\n\n");
2108 do {
2109 nt_status = cli_lsa_enum_trust_dom(cli, mem_ctx, &connect_hnd, &enum_ctx,
2110 &num_domains,
2111 &trusted_dom_names, &domain_sids);
2113 if (NT_STATUS_IS_ERR(nt_status)) {
2114 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
2115 nt_errstr(nt_status)));
2116 return -1;
2119 for (i = 0; i < num_domains; i++) {
2120 /* convert sid into ascii string */
2121 sid_to_string(ascii_sid, &(domain_sids[i]));
2123 /* calculate padding space for d_printf to look nicer */
2124 pad_len = col_len - strlen(trusted_dom_names[i]);
2125 padding[pad_len] = 0;
2126 do padding[--pad_len] = ' '; while (pad_len);
2128 d_printf("%s%s%s\n", trusted_dom_names[i], padding, ascii_sid);
2132 * in case of no trusted domains say something rather
2133 * than just display blank line
2135 if (!num_domains) d_printf("none\n");
2137 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
2139 /* close this connection before doing next one */
2140 nt_status = cli_lsa_close(cli, mem_ctx, &connect_hnd);
2141 if (NT_STATUS_IS_ERR(nt_status)) {
2142 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
2143 nt_errstr(nt_status)));
2144 return -1;
2147 cli_nt_session_close(cli);
2150 * Listing trusting domains (stored in passdb backend, if local)
2153 d_printf("\nTrusting domains list:\n\n");
2156 * Open \PIPE\samr and get needed policy handles
2158 if (!cli_nt_session_open(cli, PI_SAMR)) {
2159 DEBUG(0, ("Could not initialise samr pipe\n"));
2160 return -1;
2163 /* SamrConnect */
2164 nt_status = cli_samr_connect(cli, mem_ctx, SA_RIGHT_SAM_OPEN_DOMAIN,
2165 &connect_hnd);
2166 if (!NT_STATUS_IS_OK(nt_status)) {
2167 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
2168 nt_errstr(nt_status)));
2169 return -1;
2172 /* SamrOpenDomain - we have to open domain policy handle in order to be
2173 able to enumerate accounts*/
2174 nt_status = cli_samr_open_domain(cli, mem_ctx, &connect_hnd,
2175 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
2176 &queried_dom_sid, &domain_hnd);
2177 if (!NT_STATUS_IS_OK(nt_status)) {
2178 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
2179 nt_errstr(nt_status)));
2180 return -1;
2184 * perform actual enumeration
2187 enum_ctx = 0; /* reset enumeration context from last enumeration */
2188 do {
2190 nt_status = cli_samr_enum_dom_users(cli, mem_ctx, &domain_hnd,
2191 &enum_ctx, ACB_DOMTRUST, 0xffff,
2192 &trusting_dom_names, &trusting_dom_rids,
2193 &num_domains);
2194 if (NT_STATUS_IS_ERR(nt_status)) {
2195 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
2196 nt_errstr(nt_status)));
2197 return -1;
2200 for (i = 0; i < num_domains; i++) {
2203 * get each single domain's sid (do we _really_ need this ?):
2204 * 1) connect to domain's pdc
2205 * 2) query the pdc for domain's sid
2208 /* get rid of '$' tail */
2209 ascii_dom_name_len = strlen(trusting_dom_names[i]);
2210 if (ascii_dom_name_len && ascii_dom_name_len < FSTRING_LEN)
2211 trusting_dom_names[i][ascii_dom_name_len - 1] = '\0';
2213 /* calculate padding space for d_printf to look nicer */
2214 pad_len = col_len - strlen(trusting_dom_names[i]);
2215 padding[pad_len] = 0;
2216 do padding[--pad_len] = ' '; while (pad_len);
2218 /* set opt_* variables to remote domain */
2219 strupper_m(trusting_dom_names[i]);
2220 opt_workgroup = talloc_strdup(mem_ctx, trusting_dom_names[i]);
2221 opt_target_workgroup = opt_workgroup;
2223 d_printf("%s%s", trusting_dom_names[i], padding);
2225 /* connect to remote domain controller */
2226 remote_cli = net_make_ipc_connection(NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS);
2227 if (remote_cli) {
2228 /* query for domain's sid */
2229 if (run_rpc_command(remote_cli, PI_LSARPC, 0, rpc_query_domain_sid, argc, argv))
2230 d_printf("couldn't get domain's sid\n");
2232 cli_shutdown(remote_cli);
2234 } else {
2235 d_printf("domain controller is not responding\n");
2239 if (!num_domains) d_printf("none\n");
2241 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
2243 /* close opened samr and domain policy handles */
2244 nt_status = cli_samr_close(cli, mem_ctx, &domain_hnd);
2245 if (!NT_STATUS_IS_OK(nt_status)) {
2246 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
2249 nt_status = cli_samr_close(cli, mem_ctx, &connect_hnd);
2250 if (!NT_STATUS_IS_OK(nt_status)) {
2251 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
2254 /* close samr pipe and connection to IPC$ */
2255 cli_nt_session_close(cli);
2256 cli_shutdown(cli);
2258 talloc_destroy(mem_ctx);
2259 return 0;
2263 * Entrypoint for 'net rpc trustdom' code
2265 * @param argc standard argc
2266 * @param argv standard argv without initial components
2268 * @return Integer status (0 means success)
2271 static int rpc_trustdom(int argc, const char **argv)
2273 struct functable func[] = {
2274 {"add", rpc_trustdom_add},
2275 {"del", rpc_trustdom_del},
2276 {"establish", rpc_trustdom_establish},
2277 {"revoke", rpc_trustdom_revoke},
2278 {"help", rpc_trustdom_usage},
2279 {"list", rpc_trustdom_list},
2280 {NULL, NULL}
2283 if (argc == 0) {
2284 rpc_trustdom_usage(argc, argv);
2285 return -1;
2288 return (net_run_function(argc, argv, func, rpc_user_usage));
2292 * Check if a server will take rpc commands
2293 * @param flags Type of server to connect to (PDC, DMB, localhost)
2294 * if the host is not explicitly specified
2295 * @return BOOL (true means rpc supported)
2297 BOOL net_rpc_check(unsigned flags)
2299 struct cli_state cli;
2300 BOOL ret = False;
2301 struct in_addr server_ip;
2302 char *server_name = NULL;
2304 /* flags (i.e. server type) may depend on command */
2305 if (!net_find_server(flags, &server_ip, &server_name))
2306 return False;
2308 ZERO_STRUCT(cli);
2309 if (cli_initialise(&cli) == False)
2310 return False;
2312 if (!cli_connect(&cli, server_name, &server_ip))
2313 goto done;
2314 if (!attempt_netbios_session_request(&cli, global_myname(),
2315 server_name, &server_ip))
2316 goto done;
2317 if (!cli_negprot(&cli))
2318 goto done;
2319 if (cli.protocol < PROTOCOL_NT1)
2320 goto done;
2322 ret = True;
2323 done:
2324 cli_shutdown(&cli);
2325 return ret;
2329 /****************************************************************************/
2332 /**
2333 * Basic usage function for 'net rpc'
2334 * @param argc Standard main() style argc
2335 * @param argv Standard main() style argv. Initial components are already
2336 * stripped
2339 int net_rpc_usage(int argc, const char **argv)
2341 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
2342 d_printf(" net rpc join \t\t\tto join a domain \n");
2343 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n\n\n");
2344 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
2345 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
2346 d_printf(" net rpc group \t\tto list groups\n");
2347 d_printf(" net rpc share \t\tto add, delete, and list shares\n");
2348 d_printf(" net rpc file \t\t\tto list open files\n");
2349 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
2350 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
2351 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
2352 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
2353 d_printf(" net rpc trustdom \t\tto create trusting domain's account\n"
2354 "\t\t\t\t\tor establish trust\n");
2355 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
2356 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
2357 d_printf("\n");
2358 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
2359 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
2360 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
2361 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
2362 d_printf("\t-c or --comment=<message>\ttext message to display on impending shutdown\n");
2363 return -1;
2368 * Help function for 'net rpc'. Calls command specific help if requested
2369 * or displays usage of net rpc
2370 * @param argc Standard main() style argc
2371 * @param argv Standard main() style argv. Initial components are already
2372 * stripped
2375 int net_rpc_help(int argc, const char **argv)
2377 struct functable func[] = {
2378 {"join", rpc_join_usage},
2379 {"user", rpc_user_usage},
2380 {"group", rpc_group_usage},
2381 {"share", rpc_share_usage},
2382 /*{"changetrustpw", rpc_changetrustpw_usage}, */
2383 {"trustdom", rpc_trustdom_usage},
2384 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
2385 /*{"shutdown", rpc_shutdown_usage}, */
2386 {NULL, NULL}
2389 if (argc == 0) {
2390 net_rpc_usage(argc, argv);
2391 return -1;
2394 return (net_run_function(argc, argv, func, rpc_user_usage));
2398 /**
2399 * 'net rpc' entrypoint.
2400 * @param argc Standard main() style argc
2401 * @param argv Standard main() style argv. Initial components are already
2402 * stripped
2405 int net_rpc(int argc, const char **argv)
2407 struct functable func[] = {
2408 {"info", net_rpc_info},
2409 {"join", net_rpc_join},
2410 {"oldjoin", net_rpc_oldjoin},
2411 {"testjoin", net_rpc_testjoin},
2412 {"user", net_rpc_user},
2413 {"group", net_rpc_group},
2414 {"share", net_rpc_share},
2415 {"file", net_rpc_file},
2416 {"changetrustpw", net_rpc_changetrustpw},
2417 {"trustdom", rpc_trustdom},
2418 {"abortshutdown", rpc_shutdown_abort},
2419 {"shutdown", rpc_shutdown},
2420 {"samdump", rpc_samdump},
2421 {"vampire", rpc_vampire},
2422 {"getsid", net_rpc_getsid},
2423 {"help", net_rpc_help},
2424 {NULL, NULL}
2426 return net_run_function(argc, argv, func, net_rpc_usage);