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)
6 Copyright (C) 2004,2008 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2005 Jeremy Allison (jra@samba.org)
8 Copyright (C) 2006 Jelmer Vernooij (jelmer@samba.org)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "utils/net.h"
26 static int net_mode_share;
27 static bool sync_files(struct copy_clistate *cp_clistate, const char *mask);
32 * @brief RPC based subcommands for the 'net' utility.
34 * This file should contain much of the functionality that used to
35 * be found in rpcclient, execpt that the commands should change
36 * less often, and the fucntionality should be sane (the user is not
37 * expected to know a rid/sid before they conduct an operation etc.)
39 * @todo Perhaps eventually these should be split out into a number
40 * of files, as this could get quite big.
45 * Many of the RPC functions need the domain sid. This function gets
46 * it at the start of every run
48 * @param cli A cli_state already connected to the remote machine
50 * @return The Domain SID of the remote machine.
53 NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
55 const char **domain_name)
57 struct rpc_pipe_client *lsa_pipe;
59 NTSTATUS result = NT_STATUS_OK;
60 union lsa_PolicyInformation *info = NULL;
62 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
64 if (!NT_STATUS_IS_OK(result)) {
65 d_fprintf(stderr, "Could not initialise lsa pipe\n");
69 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
70 SEC_RIGHTS_MAXIMUM_ALLOWED,
72 if (!NT_STATUS_IS_OK(result)) {
73 d_fprintf(stderr, "open_policy failed: %s\n",
78 result = rpccli_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx,
80 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
82 if (!NT_STATUS_IS_OK(result)) {
83 d_fprintf(stderr, "lsaquery failed: %s\n",
88 *domain_name = info->account_domain.name.string;
89 *domain_sid = info->account_domain.sid;
91 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
92 TALLOC_FREE(lsa_pipe);
98 * Run a single RPC command, from start to finish.
100 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
101 * @param conn_flag a NET_FLAG_ combination. Passed to
102 * net_make_ipc_connection.
103 * @param argc Standard main() style argc.
104 * @param argv Standard main() style argv. Initial components are already
106 * @return A shell status integer (0 for success).
109 int run_rpc_command(struct net_context *c,
110 struct cli_state *cli_arg,
111 const struct ndr_syntax_id *interface,
117 struct cli_state *cli = NULL;
118 struct rpc_pipe_client *pipe_hnd = NULL;
122 const char *domain_name;
124 /* make use of cli_state handed over as an argument, if possible */
126 nt_status = net_make_ipc_connection(c, conn_flags, &cli);
127 if (!NT_STATUS_IS_OK(nt_status)) {
128 DEBUG(1, ("failed to make ipc connection: %s\n",
129 nt_errstr(nt_status)));
142 if (!(mem_ctx = talloc_init("run_rpc_command"))) {
143 DEBUG(0, ("talloc_init() failed\n"));
148 nt_status = net_get_remote_domain_sid(cli, mem_ctx, &domain_sid,
150 if (!NT_STATUS_IS_OK(nt_status)) {
155 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
156 if (lp_client_schannel()
157 && (ndr_syntax_id_equal(interface,
158 &ndr_table_netlogon.syntax_id))) {
159 /* Always try and create an schannel netlogon pipe. */
160 nt_status = cli_rpc_pipe_open_schannel(
162 PIPE_AUTH_LEVEL_PRIVACY, domain_name,
164 if (!NT_STATUS_IS_OK(nt_status)) {
165 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
166 nt_errstr(nt_status) ));
171 if (conn_flags & NET_FLAGS_SEAL) {
172 nt_status = cli_rpc_pipe_open_ntlmssp(
174 PIPE_AUTH_LEVEL_PRIVACY,
175 lp_workgroup(), c->opt_user_name,
176 c->opt_password, &pipe_hnd);
178 nt_status = cli_rpc_pipe_open_noauth(
182 if (!NT_STATUS_IS_OK(nt_status)) {
183 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
184 cli_get_pipe_name_from_iface(
185 debug_ctx(), cli, interface),
186 nt_errstr(nt_status) ));
193 nt_status = fn(c, domain_sid, domain_name, cli, pipe_hnd, mem_ctx, argc, argv);
195 if (!NT_STATUS_IS_OK(nt_status)) {
196 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status)));
198 DEBUG(5, ("rpc command function succedded\n"));
201 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
203 TALLOC_FREE(pipe_hnd);
207 /* close the connection only if it was opened here */
212 talloc_destroy(mem_ctx);
213 return (!NT_STATUS_IS_OK(nt_status));
217 * Force a change of the trust acccount password.
219 * All parameters are provided by the run_rpc_command function, except for
220 * argc, argv which are passed through.
222 * @param domain_sid The domain sid acquired from the remote server.
223 * @param cli A cli_state connected to the server.
224 * @param mem_ctx Talloc context, destroyed on completion of the function.
225 * @param argc Standard main() style argc.
226 * @param argv Standard main() style argv. Initial components are already
229 * @return Normal NTSTATUS return.
232 static NTSTATUS rpc_changetrustpw_internals(struct net_context *c,
233 const DOM_SID *domain_sid,
234 const char *domain_name,
235 struct cli_state *cli,
236 struct rpc_pipe_client *pipe_hnd,
242 return trust_pw_find_change_and_store_it(pipe_hnd, mem_ctx, c->opt_target_workgroup);
246 * Force a change of the trust acccount password.
248 * @param argc Standard main() style argc.
249 * @param argv Standard main() style argv. Initial components are already
252 * @return A shell status integer (0 for success).
255 int net_rpc_changetrustpw(struct net_context *c, int argc, const char **argv)
257 if (c->display_usage) {
259 "net rpc changetrustpw\n"
260 " Change the machine trust password\n");
264 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
265 NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
266 rpc_changetrustpw_internals,
271 * Join a domain, the old way.
273 * This uses 'machinename' as the inital password, and changes it.
275 * The password should be created with 'server manager' or equiv first.
277 * All parameters are provided by the run_rpc_command function, except for
278 * argc, argv which are passed through.
280 * @param domain_sid The domain sid acquired from the remote server.
281 * @param cli A cli_state connected to the server.
282 * @param mem_ctx Talloc context, destroyed on completion of the function.
283 * @param argc Standard main() style argc.
284 * @param argv Standard main() style argv. Initial components are already
287 * @return Normal NTSTATUS return.
290 static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
291 const DOM_SID *domain_sid,
292 const char *domain_name,
293 struct cli_state *cli,
294 struct rpc_pipe_client *pipe_hnd,
300 fstring trust_passwd;
301 unsigned char orig_trust_passwd_hash[16];
303 uint32 sec_channel_type;
305 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
307 if (!NT_STATUS_IS_OK(result)) {
308 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
311 nt_errstr(result) ));
316 check what type of join - if the user want's to join as
317 a BDC, the server must agree that we are a BDC.
320 sec_channel_type = get_sec_channel_type(argv[0]);
322 sec_channel_type = get_sec_channel_type(NULL);
325 fstrcpy(trust_passwd, global_myname());
326 strlower_m(trust_passwd);
329 * Machine names can be 15 characters, but the max length on
330 * a password is 14. --jerry
333 trust_passwd[14] = '\0';
335 E_md4hash(trust_passwd, orig_trust_passwd_hash);
337 result = trust_pw_change_and_store_it(pipe_hnd, mem_ctx, c->opt_target_workgroup,
338 orig_trust_passwd_hash,
341 if (NT_STATUS_IS_OK(result))
342 printf("Joined domain %s.\n", c->opt_target_workgroup);
345 if (!secrets_store_domain_sid(c->opt_target_workgroup, domain_sid)) {
346 DEBUG(0, ("error storing domain sid for %s\n", c->opt_target_workgroup));
347 result = NT_STATUS_UNSUCCESSFUL;
354 * Join a domain, the old way.
356 * @param argc Standard main() style argc.
357 * @param argv Standard main() style argv. Initial components are already
360 * @return A shell status integer (0 for success).
363 static int net_rpc_perform_oldjoin(struct net_context *c, int argc, const char **argv)
365 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
366 NET_FLAGS_NO_PIPE | NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
367 rpc_oldjoin_internals,
372 * Join a domain, the old way. This function exists to allow
373 * the message to be displayed when oldjoin was explicitly
374 * requested, but not when it was implied by "net rpc join".
376 * @param argc Standard main() style argc.
377 * @param argv Standard main() style argv. Initial components are already
380 * @return A shell status integer (0 for success).
383 static int net_rpc_oldjoin(struct net_context *c, int argc, const char **argv)
387 if (c->display_usage) {
390 " Join a domain the old way\n");
394 rc = net_rpc_perform_oldjoin(c, argc, argv);
397 d_fprintf(stderr, "Failed to join domain\n");
404 * 'net rpc join' entrypoint.
405 * @param argc Standard main() style argc.
406 * @param argv Standard main() style argv. Initial components are already
409 * Main 'net_rpc_join()' (where the admin username/password is used) is
411 * Try to just change the password, but if that doesn't work, use/prompt
412 * for a username/password.
415 int net_rpc_join(struct net_context *c, int argc, const char **argv)
417 if (c->display_usage) {
419 "net rpc join -U <username>[%%password] <type>\n"
421 " username\tName of the admin user"
422 " password\tPassword of the admin user, will "
423 "prompt if not specified\n"
424 " type\tCan be one of the following:\n"
425 "\t\tMEMBER\tJoin as member server (default)\n"
426 "\t\tBDC\tJoin as BDC\n"
427 "\t\tPDC\tJoin as PDC\n");
431 if (lp_server_role() == ROLE_STANDALONE) {
432 d_printf("cannot join as standalone machine\n");
436 if (strlen(global_myname()) > 15) {
437 d_printf("Our netbios name can be at most 15 chars long, "
438 "\"%s\" is %u chars long\n",
439 global_myname(), (unsigned int)strlen(global_myname()));
443 if ((net_rpc_perform_oldjoin(c, argc, argv) == 0))
446 return net_rpc_join_newstyle(c, argc, argv);
450 * display info about a rpc domain
452 * All parameters are provided by the run_rpc_command function, except for
453 * argc, argv which are passed through.
455 * @param domain_sid The domain sid acquired from the remote server
456 * @param cli A cli_state connected to the server.
457 * @param mem_ctx Talloc context, destroyed on completion of the function.
458 * @param argc Standard main() style argc.
459 * @param argv Standard main() style argv. Initial components are already
462 * @return Normal NTSTATUS return.
465 NTSTATUS rpc_info_internals(struct net_context *c,
466 const DOM_SID *domain_sid,
467 const char *domain_name,
468 struct cli_state *cli,
469 struct rpc_pipe_client *pipe_hnd,
474 POLICY_HND connect_pol, domain_pol;
475 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
476 union samr_DomainInfo *info = NULL;
479 sid_to_fstring(sid_str, domain_sid);
481 /* Get sam policy handle */
482 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
484 MAXIMUM_ALLOWED_ACCESS,
486 if (!NT_STATUS_IS_OK(result)) {
487 d_fprintf(stderr, "Could not connect to SAM: %s\n", nt_errstr(result));
491 /* Get domain policy handle */
492 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
494 MAXIMUM_ALLOWED_ACCESS,
495 CONST_DISCARD(struct dom_sid2 *, domain_sid),
497 if (!NT_STATUS_IS_OK(result)) {
498 d_fprintf(stderr, "Could not open domain: %s\n", nt_errstr(result));
502 result = rpccli_samr_QueryDomainInfo(pipe_hnd, mem_ctx,
506 if (NT_STATUS_IS_OK(result)) {
507 d_printf("Domain Name: %s\n", info->info2.domain_name.string);
508 d_printf("Domain SID: %s\n", sid_str);
509 d_printf("Sequence number: %llu\n",
510 (unsigned long long)info->info2.sequence_num);
511 d_printf("Num users: %u\n", info->info2.num_users);
512 d_printf("Num domain groups: %u\n", info->info2.num_groups);
513 d_printf("Num local groups: %u\n", info->info2.num_aliases);
521 * 'net rpc info' entrypoint.
522 * @param argc Standard main() style argc.
523 * @param argv Standard main() style argv. Initial components are already
527 int net_rpc_info(struct net_context *c, int argc, const char **argv)
529 if (c->display_usage) {
532 " Display information about the domain\n");
536 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id,
537 NET_FLAGS_PDC, rpc_info_internals,
542 * Fetch domain SID into the local secrets.tdb.
544 * All parameters are provided by the run_rpc_command function, except for
545 * argc, argv which are passed through.
547 * @param domain_sid The domain sid acquired from the remote server.
548 * @param cli A cli_state connected to the server.
549 * @param mem_ctx Talloc context, destroyed on completion of the function.
550 * @param argc Standard main() style argc.
551 * @param argv Standard main() style argv. Initial components are already
554 * @return Normal NTSTATUS return.
557 static NTSTATUS rpc_getsid_internals(struct net_context *c,
558 const DOM_SID *domain_sid,
559 const char *domain_name,
560 struct cli_state *cli,
561 struct rpc_pipe_client *pipe_hnd,
568 sid_to_fstring(sid_str, domain_sid);
569 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
570 sid_str, domain_name);
572 if (!secrets_store_domain_sid(domain_name, domain_sid)) {
573 DEBUG(0,("Can't store domain SID\n"));
574 return NT_STATUS_UNSUCCESSFUL;
581 * 'net rpc getsid' entrypoint.
582 * @param argc Standard main() style argc.
583 * @param argv Standard main() style argv. Initial components are already
587 int net_rpc_getsid(struct net_context *c, int argc, const char **argv)
589 if (c->display_usage) {
592 " Fetch domain SID into local secrets.tdb\n");
596 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id,
597 NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
598 rpc_getsid_internals,
602 /****************************************************************************/
605 * Basic usage function for 'net rpc user'.
606 * @param argc Standard main() style argc.
607 * @param argv Standard main() style argv. Initial components are already
611 static int rpc_user_usage(struct net_context *c, int argc, const char **argv)
613 return net_user_usage(c, argc, argv);
617 * Add a new user to a remote RPC server.
619 * @param argc Standard main() style argc.
620 * @param argv Standard main() style argv. Initial components are already
623 * @return A shell status integer (0 for success).
626 static int rpc_user_add(struct net_context *c, int argc, const char **argv)
628 NET_API_STATUS status;
629 struct USER_INFO_1 info1;
630 uint32_t parm_error = 0;
632 if (argc < 1 || c->display_usage) {
633 rpc_user_usage(c, argc, argv);
639 info1.usri1_name = argv[0];
641 info1.usri1_password = argv[1];
644 status = NetUserAdd(c->opt_host, 1, (uint8_t *)&info1, &parm_error);
647 d_fprintf(stderr, "Failed to add user '%s' with: %s.\n",
648 argv[0], libnetapi_get_error_string(c->netapi_ctx,
652 d_printf("Added user '%s'.\n", argv[0]);
659 * Rename a user on a remote RPC server.
661 * All parameters are provided by the run_rpc_command function, except for
662 * argc, argv which are passed through.
664 * @param domain_sid The domain sid acquired from the remote server.
665 * @param cli A cli_state connected to the server.
666 * @param mem_ctx Talloc context, destroyed on completion of the function.
667 * @param argc Standard main() style argc.
668 * @param argv Standard main() style argv. Initial components are already
671 * @return Normal NTSTATUS return.
674 static NTSTATUS rpc_user_rename_internals(struct net_context *c,
675 const DOM_SID *domain_sid,
676 const char *domain_name,
677 struct cli_state *cli,
678 struct rpc_pipe_client *pipe_hnd,
683 POLICY_HND connect_pol, domain_pol, user_pol;
684 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
685 uint32 info_level = 7;
686 const char *old_name, *new_name;
687 struct samr_Ids user_rids, name_types;
688 struct lsa_String lsa_acct_name;
689 union samr_UserInfo *info = NULL;
691 if (argc != 2 || c->display_usage) {
692 rpc_user_usage(c, argc, argv);
699 /* Get sam policy handle */
701 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
703 MAXIMUM_ALLOWED_ACCESS,
706 if (!NT_STATUS_IS_OK(result)) {
710 /* Get domain policy handle */
712 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
714 MAXIMUM_ALLOWED_ACCESS,
715 CONST_DISCARD(struct dom_sid2 *, domain_sid),
717 if (!NT_STATUS_IS_OK(result)) {
721 init_lsa_String(&lsa_acct_name, old_name);
723 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
729 if (!NT_STATUS_IS_OK(result)) {
733 /* Open domain user */
734 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
736 MAXIMUM_ALLOWED_ACCESS,
740 if (!NT_STATUS_IS_OK(result)) {
744 /* Query user info */
745 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
750 if (!NT_STATUS_IS_OK(result)) {
754 init_samr_user_info7(&info->info7, new_name);
757 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
762 if (!NT_STATUS_IS_OK(result)) {
767 if (!NT_STATUS_IS_OK(result)) {
768 d_fprintf(stderr, "Failed to rename user from %s to %s - %s\n", old_name, new_name,
771 d_printf("Renamed user from %s to %s\n", old_name, new_name);
777 * Rename a user on a remote RPC server.
779 * @param argc Standard main() style argc.
780 * @param argv Standard main() style argv. Initial components are already
783 * @return A shell status integer (0 for success).
786 static int rpc_user_rename(struct net_context *c, int argc, const char **argv)
788 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
789 rpc_user_rename_internals, argc, argv);
793 * Delete a user from a remote RPC server.
795 * @param argc Standard main() style argc.
796 * @param argv Standard main() style argv. Initial components are already
799 * @return A shell status integer (0 for success).
802 static int rpc_user_delete(struct net_context *c, int argc, const char **argv)
804 NET_API_STATUS status;
806 if (argc < 1 || c->display_usage) {
807 rpc_user_usage(c, argc, argv);
811 status = NetUserDel(c->opt_host, argv[0]);
814 d_fprintf(stderr, "Failed to delete user '%s' with: %s.\n",
816 libnetapi_get_error_string(c->netapi_ctx, status));
819 d_printf("Deleted user '%s'.\n", argv[0]);
826 * Set a password for a user on a remote RPC server.
828 * All parameters are provided by the run_rpc_command function, except for
829 * argc, argv which are passed through.
831 * @param domain_sid The domain sid acquired from the remote server.
832 * @param cli A cli_state connected to the server.
833 * @param mem_ctx Talloc context, destroyed on completion of the function.
834 * @param argc Standard main() style argc.
835 * @param argv Standard main() style argv. Initial components are already
838 * @return Normal NTSTATUS return.
841 static NTSTATUS rpc_user_password_internals(struct net_context *c,
842 const DOM_SID *domain_sid,
843 const char *domain_name,
844 struct cli_state *cli,
845 struct rpc_pipe_client *pipe_hnd,
850 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
851 POLICY_HND connect_pol, domain_pol, user_pol;
854 const char *new_password;
856 union samr_UserInfo info;
858 if (argc < 1 || c->display_usage) {
859 rpc_user_usage(c, argc, argv);
866 new_password = argv[1];
868 asprintf(&prompt, "Enter new password for %s:", user);
869 new_password = getpass(prompt);
873 /* Get sam policy and domain handles */
875 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
877 MAXIMUM_ALLOWED_ACCESS,
880 if (!NT_STATUS_IS_OK(result)) {
884 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
886 MAXIMUM_ALLOWED_ACCESS,
887 CONST_DISCARD(struct dom_sid2 *, domain_sid),
890 if (!NT_STATUS_IS_OK(result)) {
894 /* Get handle on user */
897 struct samr_Ids user_rids, name_types;
898 struct lsa_String lsa_acct_name;
900 init_lsa_String(&lsa_acct_name, user);
902 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
908 if (!NT_STATUS_IS_OK(result)) {
912 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
914 MAXIMUM_ALLOWED_ACCESS,
918 if (!NT_STATUS_IS_OK(result)) {
923 /* Set password on account */
925 encode_pw_buffer(pwbuf, new_password, STR_UNICODE);
927 init_samr_user_info24(&info.info24, pwbuf, 24);
929 SamOEMhashBlob(info.info24.password.data, 516,
930 &cli->user_session_key);
932 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
937 if (!NT_STATUS_IS_OK(result)) {
941 /* Display results */
949 * Set a user's password on a remote RPC server.
951 * @param argc Standard main() style argc.
952 * @param argv Standard main() style argv. Initial components are already
955 * @return A shell status integer (0 for success).
958 static int rpc_user_password(struct net_context *c, int argc, const char **argv)
960 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
961 rpc_user_password_internals, argc, argv);
965 * List user's groups on a remote RPC server.
967 * All parameters are provided by the run_rpc_command function, except for
968 * argc, argv which are passed through.
970 * @param domain_sid The domain sid acquired from the remote server.
971 * @param cli A cli_state connected to the server.
972 * @param mem_ctx Talloc context, destroyed on completion of the function.
973 * @param argc Standard main() style argc.
974 * @param argv Standard main() style argv. Initial components are already
977 * @return Normal NTSTATUS return.
980 static NTSTATUS rpc_user_info_internals(struct net_context *c,
981 const DOM_SID *domain_sid,
982 const char *domain_name,
983 struct cli_state *cli,
984 struct rpc_pipe_client *pipe_hnd,
989 POLICY_HND connect_pol, domain_pol, user_pol;
990 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
992 struct samr_RidWithAttributeArray *rid_array = NULL;
993 struct lsa_Strings names;
994 struct samr_Ids types;
995 uint32_t *lrids = NULL;
996 struct samr_Ids rids, name_types;
997 struct lsa_String lsa_acct_name;
1000 if (argc < 1 || c->display_usage) {
1001 rpc_user_usage(c, argc, argv);
1002 return NT_STATUS_OK;
1004 /* Get sam policy handle */
1006 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
1008 MAXIMUM_ALLOWED_ACCESS,
1010 if (!NT_STATUS_IS_OK(result)) goto done;
1012 /* Get domain policy handle */
1014 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
1016 MAXIMUM_ALLOWED_ACCESS,
1017 CONST_DISCARD(struct dom_sid2 *, domain_sid),
1019 if (!NT_STATUS_IS_OK(result)) goto done;
1021 /* Get handle on user */
1023 init_lsa_String(&lsa_acct_name, argv[0]);
1025 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
1032 if (!NT_STATUS_IS_OK(result)) goto done;
1034 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
1036 MAXIMUM_ALLOWED_ACCESS,
1039 if (!NT_STATUS_IS_OK(result)) goto done;
1041 result = rpccli_samr_GetGroupsForUser(pipe_hnd, mem_ctx,
1045 if (!NT_STATUS_IS_OK(result)) goto done;
1049 if (rid_array->count) {
1050 if ((lrids = TALLOC_ARRAY(mem_ctx, uint32, rid_array->count)) == NULL) {
1051 result = NT_STATUS_NO_MEMORY;
1055 for (i = 0; i < rid_array->count; i++)
1056 lrids[i] = rid_array->rids[i].rid;
1058 result = rpccli_samr_LookupRids(pipe_hnd, mem_ctx,
1065 if (!NT_STATUS_IS_OK(result)) {
1069 /* Display results */
1071 for (i = 0; i < names.count; i++)
1072 printf("%s\n", names.names[i].string);
1079 * List a user's groups from a remote RPC server.
1081 * @param argc Standard main() style argc.
1082 * @param argv Standard main() style argv. Initial components are already
1085 * @return A shell status integer (0 for success)
1088 static int rpc_user_info(struct net_context *c, int argc, const char **argv)
1090 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
1091 rpc_user_info_internals, argc, argv);
1095 * List users on a remote RPC server.
1097 * All parameters are provided by the run_rpc_command function, except for
1098 * argc, argv which are passed through.
1100 * @param domain_sid The domain sid acquired from the remote server.
1101 * @param cli A cli_state connected to the server.
1102 * @param mem_ctx Talloc context, destroyed on completion of the function.
1103 * @param argc Standard main() style argc.
1104 * @param argv Standard main() style argv. Initial components are already
1107 * @return Normal NTSTATUS return.
1110 static NTSTATUS rpc_user_list_internals(struct net_context *c,
1111 const DOM_SID *domain_sid,
1112 const char *domain_name,
1113 struct cli_state *cli,
1114 struct rpc_pipe_client *pipe_hnd,
1115 TALLOC_CTX *mem_ctx,
1119 POLICY_HND connect_pol, domain_pol;
1120 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1121 uint32 start_idx=0, num_entries, i, loop_count = 0;
1123 /* Get sam policy handle */
1125 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
1127 MAXIMUM_ALLOWED_ACCESS,
1129 if (!NT_STATUS_IS_OK(result)) {
1133 /* Get domain policy handle */
1135 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
1137 MAXIMUM_ALLOWED_ACCESS,
1138 CONST_DISCARD(struct dom_sid2 *, domain_sid),
1140 if (!NT_STATUS_IS_OK(result)) {
1144 /* Query domain users */
1145 if (c->opt_long_list_entries)
1146 d_printf("\nUser name Comment"
1147 "\n-----------------------------\n");
1149 const char *user = NULL;
1150 const char *desc = NULL;
1151 uint32 max_entries, max_size;
1152 uint32_t total_size, returned_size;
1153 union samr_DispInfo info;
1155 get_query_dispinfo_params(
1156 loop_count, &max_entries, &max_size);
1158 result = rpccli_samr_QueryDisplayInfo(pipe_hnd, mem_ctx,
1168 start_idx += info.info1.count;
1169 num_entries = info.info1.count;
1171 for (i = 0; i < num_entries; i++) {
1172 user = info.info1.entries[i].account_name.string;
1173 if (c->opt_long_list_entries)
1174 desc = info.info1.entries[i].description.string;
1175 if (c->opt_long_list_entries)
1176 printf("%-21.21s %s\n", user, desc);
1178 printf("%s\n", user);
1180 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
1187 * 'net rpc user' entrypoint.
1188 * @param argc Standard main() style argc.
1189 * @param argv Standard main() style argv. Initial components are already
1193 int net_rpc_user(struct net_context *c, int argc, const char **argv)
1195 NET_API_STATUS status;
1197 struct functable func[] = {
1202 "Add specified user",
1203 "net rpc user add\n"
1204 " Add specified user"
1210 "List domain groups of user",
1211 "net rpc user info\n"
1212 " Lis domain groups of user"
1218 "Remove specified user",
1219 "net rpc user delete\n"
1220 " Remove specified user"
1226 "Change user password",
1227 "net rpc user password\n"
1228 " Change user password"
1234 "Rename specified user",
1235 "net rpc user rename\n"
1236 " Rename specified user"
1238 {NULL, NULL, 0, NULL, NULL}
1241 status = libnetapi_init(&c->netapi_ctx);
1245 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
1246 libnetapi_set_password(c->netapi_ctx, c->opt_password);
1249 if (c->display_usage) {
1250 d_printf("Usage:\n");
1251 d_printf("net rpc user\n"
1252 " List all users\n");
1253 net_display_usage_from_functable(func);
1257 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
1258 rpc_user_list_internals,
1262 return net_run_function(c, argc, argv, "net rpc user", func);
1265 static NTSTATUS rpc_sh_user_list(struct net_context *c,
1266 TALLOC_CTX *mem_ctx,
1267 struct rpc_sh_ctx *ctx,
1268 struct rpc_pipe_client *pipe_hnd,
1269 int argc, const char **argv)
1271 return rpc_user_list_internals(c, ctx->domain_sid, ctx->domain_name,
1272 ctx->cli, pipe_hnd, mem_ctx,
1276 static NTSTATUS rpc_sh_user_info(struct net_context *c,
1277 TALLOC_CTX *mem_ctx,
1278 struct rpc_sh_ctx *ctx,
1279 struct rpc_pipe_client *pipe_hnd,
1280 int argc, const char **argv)
1282 return rpc_user_info_internals(c, ctx->domain_sid, ctx->domain_name,
1283 ctx->cli, pipe_hnd, mem_ctx,
1287 static NTSTATUS rpc_sh_handle_user(struct net_context *c,
1288 TALLOC_CTX *mem_ctx,
1289 struct rpc_sh_ctx *ctx,
1290 struct rpc_pipe_client *pipe_hnd,
1291 int argc, const char **argv,
1293 struct net_context *c,
1294 TALLOC_CTX *mem_ctx,
1295 struct rpc_sh_ctx *ctx,
1296 struct rpc_pipe_client *pipe_hnd,
1297 POLICY_HND *user_hnd,
1298 int argc, const char **argv))
1300 POLICY_HND connect_pol, domain_pol, user_pol;
1301 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1304 enum lsa_SidType type;
1307 d_fprintf(stderr, "usage: %s <username>\n", ctx->whoami);
1308 return NT_STATUS_INVALID_PARAMETER;
1311 ZERO_STRUCT(connect_pol);
1312 ZERO_STRUCT(domain_pol);
1313 ZERO_STRUCT(user_pol);
1315 result = net_rpc_lookup_name(c, mem_ctx, rpc_pipe_np_smb_conn(pipe_hnd),
1316 argv[0], NULL, NULL, &sid, &type);
1317 if (!NT_STATUS_IS_OK(result)) {
1318 d_fprintf(stderr, "Could not lookup %s: %s\n", argv[0],
1323 if (type != SID_NAME_USER) {
1324 d_fprintf(stderr, "%s is a %s, not a user\n", argv[0],
1325 sid_type_lookup(type));
1326 result = NT_STATUS_NO_SUCH_USER;
1330 if (!sid_peek_check_rid(ctx->domain_sid, &sid, &rid)) {
1331 d_fprintf(stderr, "%s is not in our domain\n", argv[0]);
1332 result = NT_STATUS_NO_SUCH_USER;
1336 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
1338 MAXIMUM_ALLOWED_ACCESS,
1340 if (!NT_STATUS_IS_OK(result)) {
1344 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
1346 MAXIMUM_ALLOWED_ACCESS,
1349 if (!NT_STATUS_IS_OK(result)) {
1353 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
1355 MAXIMUM_ALLOWED_ACCESS,
1358 if (!NT_STATUS_IS_OK(result)) {
1362 result = fn(c, mem_ctx, ctx, pipe_hnd, &user_pol, argc-1, argv+1);
1365 if (is_valid_policy_hnd(&user_pol)) {
1366 rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
1368 if (is_valid_policy_hnd(&domain_pol)) {
1369 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
1371 if (is_valid_policy_hnd(&connect_pol)) {
1372 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
1377 static NTSTATUS rpc_sh_user_show_internals(struct net_context *c,
1378 TALLOC_CTX *mem_ctx,
1379 struct rpc_sh_ctx *ctx,
1380 struct rpc_pipe_client *pipe_hnd,
1381 POLICY_HND *user_hnd,
1382 int argc, const char **argv)
1385 union samr_UserInfo *info = NULL;
1388 d_fprintf(stderr, "usage: %s show <username>\n", ctx->whoami);
1389 return NT_STATUS_INVALID_PARAMETER;
1392 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
1396 if (!NT_STATUS_IS_OK(result)) {
1400 d_printf("user rid: %d, group rid: %d\n",
1402 info->info21.primary_gid);
1407 static NTSTATUS rpc_sh_user_show(struct net_context *c,
1408 TALLOC_CTX *mem_ctx,
1409 struct rpc_sh_ctx *ctx,
1410 struct rpc_pipe_client *pipe_hnd,
1411 int argc, const char **argv)
1413 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1414 rpc_sh_user_show_internals);
1417 #define FETCHSTR(name, rec) \
1418 do { if (strequal(ctx->thiscmd, name)) { \
1419 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1422 #define SETSTR(name, rec, flag) \
1423 do { if (strequal(ctx->thiscmd, name)) { \
1424 init_lsa_String(&(info->info21.rec), argv[0]); \
1425 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1428 static NTSTATUS rpc_sh_user_str_edit_internals(struct net_context *c,
1429 TALLOC_CTX *mem_ctx,
1430 struct rpc_sh_ctx *ctx,
1431 struct rpc_pipe_client *pipe_hnd,
1432 POLICY_HND *user_hnd,
1433 int argc, const char **argv)
1436 const char *username;
1437 const char *oldval = "";
1438 union samr_UserInfo *info = NULL;
1441 d_fprintf(stderr, "usage: %s <username> [new value|NULL]\n",
1443 return NT_STATUS_INVALID_PARAMETER;
1446 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
1450 if (!NT_STATUS_IS_OK(result)) {
1454 username = talloc_strdup(mem_ctx, info->info21.account_name.string);
1456 FETCHSTR("fullname", full_name);
1457 FETCHSTR("homedir", home_directory);
1458 FETCHSTR("homedrive", home_drive);
1459 FETCHSTR("logonscript", logon_script);
1460 FETCHSTR("profilepath", profile_path);
1461 FETCHSTR("description", description);
1464 d_printf("%s's %s: [%s]\n", username, ctx->thiscmd, oldval);
1468 if (strcmp(argv[0], "NULL") == 0) {
1472 ZERO_STRUCT(info->info21);
1474 SETSTR("fullname", full_name, FULL_NAME);
1475 SETSTR("homedir", home_directory, HOME_DIRECTORY);
1476 SETSTR("homedrive", home_drive, HOME_DRIVE);
1477 SETSTR("logonscript", logon_script, LOGON_SCRIPT);
1478 SETSTR("profilepath", profile_path, PROFILE_PATH);
1479 SETSTR("description", description, DESCRIPTION);
1481 result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
1486 d_printf("Set %s's %s from [%s] to [%s]\n", username,
1487 ctx->thiscmd, oldval, argv[0]);
1494 #define HANDLEFLG(name, rec) \
1495 do { if (strequal(ctx->thiscmd, name)) { \
1496 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1498 newflags = oldflags | ACB_##rec; \
1500 newflags = oldflags & ~ACB_##rec; \
1503 static NTSTATUS rpc_sh_user_str_edit(struct net_context *c,
1504 TALLOC_CTX *mem_ctx,
1505 struct rpc_sh_ctx *ctx,
1506 struct rpc_pipe_client *pipe_hnd,
1507 int argc, const char **argv)
1509 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1510 rpc_sh_user_str_edit_internals);
1513 static NTSTATUS rpc_sh_user_flag_edit_internals(struct net_context *c,
1514 TALLOC_CTX *mem_ctx,
1515 struct rpc_sh_ctx *ctx,
1516 struct rpc_pipe_client *pipe_hnd,
1517 POLICY_HND *user_hnd,
1518 int argc, const char **argv)
1521 const char *username;
1522 const char *oldval = "unknown";
1523 uint32 oldflags, newflags;
1525 union samr_UserInfo *info = NULL;
1528 ((argc == 1) && !strequal(argv[0], "yes") &&
1529 !strequal(argv[0], "no"))) {
1530 d_fprintf(stderr, "usage: %s <username> [yes|no]\n",
1532 return NT_STATUS_INVALID_PARAMETER;
1535 newval = strequal(argv[0], "yes");
1537 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
1541 if (!NT_STATUS_IS_OK(result)) {
1545 username = talloc_strdup(mem_ctx, info->info21.account_name.string);
1546 oldflags = info->info21.acct_flags;
1547 newflags = info->info21.acct_flags;
1549 HANDLEFLG("disabled", DISABLED);
1550 HANDLEFLG("pwnotreq", PWNOTREQ);
1551 HANDLEFLG("autolock", AUTOLOCK);
1552 HANDLEFLG("pwnoexp", PWNOEXP);
1555 d_printf("%s's %s flag: %s\n", username, ctx->thiscmd, oldval);
1559 ZERO_STRUCT(info->info21);
1561 info->info21.acct_flags = newflags;
1562 info->info21.fields_present = SAMR_FIELD_ACCT_FLAGS;
1564 result = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
1569 if (NT_STATUS_IS_OK(result)) {
1570 d_printf("Set %s's %s flag from [%s] to [%s]\n", username,
1571 ctx->thiscmd, oldval, argv[0]);
1579 static NTSTATUS rpc_sh_user_flag_edit(struct net_context *c,
1580 TALLOC_CTX *mem_ctx,
1581 struct rpc_sh_ctx *ctx,
1582 struct rpc_pipe_client *pipe_hnd,
1583 int argc, const char **argv)
1585 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1586 rpc_sh_user_flag_edit_internals);
1589 struct rpc_sh_cmd *net_rpc_user_edit_cmds(struct net_context *c,
1590 TALLOC_CTX *mem_ctx,
1591 struct rpc_sh_ctx *ctx)
1593 static struct rpc_sh_cmd cmds[] = {
1595 { "fullname", NULL, PI_SAMR, rpc_sh_user_str_edit,
1596 "Show/Set a user's full name" },
1598 { "homedir", NULL, PI_SAMR, rpc_sh_user_str_edit,
1599 "Show/Set a user's home directory" },
1601 { "homedrive", NULL, PI_SAMR, rpc_sh_user_str_edit,
1602 "Show/Set a user's home drive" },
1604 { "logonscript", NULL, PI_SAMR, rpc_sh_user_str_edit,
1605 "Show/Set a user's logon script" },
1607 { "profilepath", NULL, PI_SAMR, rpc_sh_user_str_edit,
1608 "Show/Set a user's profile path" },
1610 { "description", NULL, PI_SAMR, rpc_sh_user_str_edit,
1611 "Show/Set a user's description" },
1613 { "disabled", NULL, PI_SAMR, rpc_sh_user_flag_edit,
1614 "Show/Set whether a user is disabled" },
1616 { "autolock", NULL, PI_SAMR, rpc_sh_user_flag_edit,
1617 "Show/Set whether a user locked out" },
1619 { "pwnotreq", NULL, PI_SAMR, rpc_sh_user_flag_edit,
1620 "Show/Set whether a user does not need a password" },
1622 { "pwnoexp", NULL, PI_SAMR, rpc_sh_user_flag_edit,
1623 "Show/Set whether a user's password does not expire" },
1625 { NULL, NULL, 0, NULL, NULL }
1631 struct rpc_sh_cmd *net_rpc_user_cmds(struct net_context *c,
1632 TALLOC_CTX *mem_ctx,
1633 struct rpc_sh_ctx *ctx)
1635 static struct rpc_sh_cmd cmds[] = {
1637 { "list", NULL, PI_SAMR, rpc_sh_user_list,
1638 "List available users" },
1640 { "info", NULL, PI_SAMR, rpc_sh_user_info,
1641 "List the domain groups a user is member of" },
1643 { "show", NULL, PI_SAMR, rpc_sh_user_show,
1644 "Show info about a user" },
1646 { "edit", net_rpc_user_edit_cmds, 0, NULL,
1647 "Show/Modify a user's fields" },
1649 { NULL, NULL, 0, NULL, NULL }
1655 /****************************************************************************/
1658 * Basic usage function for 'net rpc group'.
1659 * @param argc Standard main() style argc.
1660 * @param argv Standard main() style argv. Initial components are already
1664 static int rpc_group_usage(struct net_context *c, int argc, const char **argv)
1666 return net_group_usage(c, argc, argv);
1670 * Delete group on a remote RPC server.
1672 * All parameters are provided by the run_rpc_command function, except for
1673 * argc, argv which are passed through.
1675 * @param domain_sid The domain sid acquired from the remote server.
1676 * @param cli A cli_state connected to the server.
1677 * @param mem_ctx Talloc context, destroyed on completion of the function.
1678 * @param argc Standard main() style argc.
1679 * @param argv Standard main() style argv. Initial components are already
1682 * @return Normal NTSTATUS return.
1685 static NTSTATUS rpc_group_delete_internals(struct net_context *c,
1686 const DOM_SID *domain_sid,
1687 const char *domain_name,
1688 struct cli_state *cli,
1689 struct rpc_pipe_client *pipe_hnd,
1690 TALLOC_CTX *mem_ctx,
1694 POLICY_HND connect_pol, domain_pol, group_pol, user_pol;
1695 bool group_is_primary = false;
1696 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1698 struct samr_RidTypeArray *rids = NULL;
1701 /* DOM_GID *user_gids; */
1703 struct samr_Ids group_rids, name_types;
1704 struct lsa_String lsa_acct_name;
1705 union samr_UserInfo *info = NULL;
1707 if (argc < 1 || c->display_usage) {
1708 rpc_group_usage(c, argc,argv);
1709 return NT_STATUS_OK; /* ok? */
1712 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
1714 MAXIMUM_ALLOWED_ACCESS,
1717 if (!NT_STATUS_IS_OK(result)) {
1718 d_fprintf(stderr, "Request samr_Connect2 failed\n");
1722 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
1724 MAXIMUM_ALLOWED_ACCESS,
1725 CONST_DISCARD(struct dom_sid2 *, domain_sid),
1728 if (!NT_STATUS_IS_OK(result)) {
1729 d_fprintf(stderr, "Request open_domain failed\n");
1733 init_lsa_String(&lsa_acct_name, argv[0]);
1735 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
1741 if (!NT_STATUS_IS_OK(result)) {
1742 d_fprintf(stderr, "Lookup of '%s' failed\n",argv[0]);
1746 switch (name_types.ids[0])
1748 case SID_NAME_DOM_GRP:
1749 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
1751 MAXIMUM_ALLOWED_ACCESS,
1754 if (!NT_STATUS_IS_OK(result)) {
1755 d_fprintf(stderr, "Request open_group failed");
1759 group_rid = group_rids.ids[0];
1761 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,
1765 if (!NT_STATUS_IS_OK(result)) {
1766 d_fprintf(stderr, "Unable to query group members of %s",argv[0]);
1770 if (c->opt_verbose) {
1771 d_printf("Domain Group %s (rid: %d) has %d members\n",
1772 argv[0],group_rid, rids->count);
1775 /* Check if group is anyone's primary group */
1776 for (i = 0; i < rids->count; i++)
1778 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
1780 MAXIMUM_ALLOWED_ACCESS,
1784 if (!NT_STATUS_IS_OK(result)) {
1785 d_fprintf(stderr, "Unable to open group member %d\n",
1790 result = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
1795 if (!NT_STATUS_IS_OK(result)) {
1796 d_fprintf(stderr, "Unable to lookup userinfo for group member %d\n",
1801 if (info->info21.primary_gid == group_rid) {
1802 if (c->opt_verbose) {
1803 d_printf("Group is primary group of %s\n",
1804 info->info21.account_name.string);
1806 group_is_primary = true;
1809 rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
1812 if (group_is_primary) {
1813 d_fprintf(stderr, "Unable to delete group because some "
1814 "of it's members have it as primary group\n");
1815 result = NT_STATUS_MEMBERS_PRIMARY_GROUP;
1819 /* remove all group members */
1820 for (i = 0; i < rids->count; i++)
1823 d_printf("Remove group member %d...",
1825 result = rpccli_samr_DeleteGroupMember(pipe_hnd, mem_ctx,
1829 if (NT_STATUS_IS_OK(result)) {
1834 d_printf("failed\n");
1839 result = rpccli_samr_DeleteDomainGroup(pipe_hnd, mem_ctx,
1843 /* removing a local group is easier... */
1844 case SID_NAME_ALIAS:
1845 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
1847 MAXIMUM_ALLOWED_ACCESS,
1851 if (!NT_STATUS_IS_OK(result)) {
1852 d_fprintf(stderr, "Request open_alias failed\n");
1856 result = rpccli_samr_DeleteDomAlias(pipe_hnd, mem_ctx,
1860 d_fprintf(stderr, "%s is of type %s. This command is only for deleting local or global groups\n",
1861 argv[0],sid_type_lookup(name_types.ids[0]));
1862 result = NT_STATUS_UNSUCCESSFUL;
1866 if (NT_STATUS_IS_OK(result)) {
1868 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types.ids[0]),argv[0]);
1870 d_fprintf(stderr, "Deleting of %s failed: %s\n",argv[0],
1871 get_friendly_nt_error_msg(result));
1879 static int rpc_group_delete(struct net_context *c, int argc, const char **argv)
1881 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
1882 rpc_group_delete_internals, argc,argv);
1885 static int rpc_group_add_internals(struct net_context *c, int argc, const char **argv)
1887 NET_API_STATUS status;
1888 struct GROUP_INFO_1 info1;
1889 uint32_t parm_error = 0;
1891 if (argc != 1 || c->display_usage) {
1892 rpc_group_usage(c, argc, argv);
1898 info1.grpi1_name = argv[0];
1899 if (c->opt_comment && strlen(c->opt_comment) > 0) {
1900 info1.grpi1_comment = c->opt_comment;
1903 status = NetGroupAdd(c->opt_host, 1, (uint8_t *)&info1, &parm_error);
1906 d_fprintf(stderr, "Failed to add group '%s' with: %s.\n",
1907 argv[0], libnetapi_get_error_string(c->netapi_ctx,
1911 d_printf("Added group '%s'.\n", argv[0]);
1917 static NTSTATUS rpc_alias_add_internals(struct net_context *c,
1918 const DOM_SID *domain_sid,
1919 const char *domain_name,
1920 struct cli_state *cli,
1921 struct rpc_pipe_client *pipe_hnd,
1922 TALLOC_CTX *mem_ctx,
1926 POLICY_HND connect_pol, domain_pol, alias_pol;
1927 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1928 union samr_AliasInfo alias_info;
1929 struct lsa_String alias_name;
1932 if (argc != 1 || c->display_usage) {
1933 rpc_group_usage(c, argc, argv);
1934 return NT_STATUS_OK;
1937 init_lsa_String(&alias_name, argv[0]);
1939 /* Get sam policy handle */
1941 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
1943 MAXIMUM_ALLOWED_ACCESS,
1945 if (!NT_STATUS_IS_OK(result)) goto done;
1947 /* Get domain policy handle */
1949 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
1951 MAXIMUM_ALLOWED_ACCESS,
1952 CONST_DISCARD(struct dom_sid2 *, domain_sid),
1954 if (!NT_STATUS_IS_OK(result)) goto done;
1956 /* Create the group */
1958 result = rpccli_samr_CreateDomAlias(pipe_hnd, mem_ctx,
1961 MAXIMUM_ALLOWED_ACCESS,
1964 if (!NT_STATUS_IS_OK(result)) goto done;
1966 if (strlen(c->opt_comment) == 0) goto done;
1968 /* We've got a comment to set */
1970 init_lsa_String(&alias_info.description, c->opt_comment);
1972 result = rpccli_samr_SetAliasInfo(pipe_hnd, mem_ctx,
1977 if (!NT_STATUS_IS_OK(result)) goto done;
1980 if (NT_STATUS_IS_OK(result))
1981 DEBUG(5, ("add alias succeeded\n"));
1983 d_fprintf(stderr, "add alias failed: %s\n", nt_errstr(result));
1988 static int rpc_group_add(struct net_context *c, int argc, const char **argv)
1990 if (c->opt_localgroup)
1991 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
1992 rpc_alias_add_internals,
1995 return rpc_group_add_internals(c, argc, argv);
1998 static NTSTATUS get_sid_from_name(struct cli_state *cli,
1999 TALLOC_CTX *mem_ctx,
2002 enum lsa_SidType *type)
2004 DOM_SID *sids = NULL;
2005 enum lsa_SidType *types = NULL;
2006 struct rpc_pipe_client *pipe_hnd;
2008 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2010 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
2012 if (!NT_STATUS_IS_OK(result)) {
2016 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, false,
2017 SEC_RIGHTS_MAXIMUM_ALLOWED, &lsa_pol);
2019 if (!NT_STATUS_IS_OK(result)) {
2023 result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
2024 &name, NULL, 1, &sids, &types);
2026 if (NT_STATUS_IS_OK(result)) {
2027 sid_copy(sid, &sids[0]);
2031 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
2035 TALLOC_FREE(pipe_hnd);
2038 if (!NT_STATUS_IS_OK(result) && (StrnCaseCmp(name, "S-", 2) == 0)) {
2040 /* Try as S-1-5-whatever */
2044 if (string_to_sid(&tmp_sid, name)) {
2045 sid_copy(sid, &tmp_sid);
2046 *type = SID_NAME_UNKNOWN;
2047 result = NT_STATUS_OK;
2054 static NTSTATUS rpc_add_groupmem(struct rpc_pipe_client *pipe_hnd,
2055 TALLOC_CTX *mem_ctx,
2056 const DOM_SID *group_sid,
2059 POLICY_HND connect_pol, domain_pol;
2062 POLICY_HND group_pol;
2064 struct samr_Ids rids, rid_types;
2065 struct lsa_String lsa_acct_name;
2069 sid_copy(&sid, group_sid);
2071 if (!sid_split_rid(&sid, &group_rid)) {
2072 return NT_STATUS_UNSUCCESSFUL;
2075 /* Get sam policy handle */
2076 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2078 MAXIMUM_ALLOWED_ACCESS,
2080 if (!NT_STATUS_IS_OK(result)) {
2084 /* Get domain policy handle */
2085 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2087 MAXIMUM_ALLOWED_ACCESS,
2090 if (!NT_STATUS_IS_OK(result)) {
2094 init_lsa_String(&lsa_acct_name, member);
2096 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
2103 if (!NT_STATUS_IS_OK(result)) {
2104 d_fprintf(stderr, "Could not lookup up group member %s\n", member);
2108 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
2110 MAXIMUM_ALLOWED_ACCESS,
2114 if (!NT_STATUS_IS_OK(result)) {
2118 result = rpccli_samr_AddGroupMember(pipe_hnd, mem_ctx,
2121 0x0005); /* unknown flags */
2124 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
2128 static NTSTATUS rpc_add_aliasmem(struct rpc_pipe_client *pipe_hnd,
2129 TALLOC_CTX *mem_ctx,
2130 const DOM_SID *alias_sid,
2133 POLICY_HND connect_pol, domain_pol;
2136 POLICY_HND alias_pol;
2139 enum lsa_SidType member_type;
2143 sid_copy(&sid, alias_sid);
2145 if (!sid_split_rid(&sid, &alias_rid)) {
2146 return NT_STATUS_UNSUCCESSFUL;
2149 result = get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd), mem_ctx,
2150 member, &member_sid, &member_type);
2152 if (!NT_STATUS_IS_OK(result)) {
2153 d_fprintf(stderr, "Could not lookup up group member %s\n", member);
2157 /* Get sam policy handle */
2158 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2160 MAXIMUM_ALLOWED_ACCESS,
2162 if (!NT_STATUS_IS_OK(result)) {
2166 /* Get domain policy handle */
2167 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2169 MAXIMUM_ALLOWED_ACCESS,
2172 if (!NT_STATUS_IS_OK(result)) {
2176 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2178 MAXIMUM_ALLOWED_ACCESS,
2182 if (!NT_STATUS_IS_OK(result)) {
2186 result = rpccli_samr_AddAliasMember(pipe_hnd, mem_ctx,
2190 if (!NT_STATUS_IS_OK(result)) {
2195 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
2199 static NTSTATUS rpc_group_addmem_internals(struct net_context *c,
2200 const DOM_SID *domain_sid,
2201 const char *domain_name,
2202 struct cli_state *cli,
2203 struct rpc_pipe_client *pipe_hnd,
2204 TALLOC_CTX *mem_ctx,
2209 enum lsa_SidType group_type;
2211 if (argc != 2 || c->display_usage) {
2213 "net rpc group addmem <group> <member>\n"
2214 " Add a member to a group\n"
2215 " group\tGroup to add member to\n"
2216 " member\tMember to add to group\n");
2217 return NT_STATUS_UNSUCCESSFUL;
2220 if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
2221 &group_sid, &group_type))) {
2222 d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]);
2223 return NT_STATUS_UNSUCCESSFUL;
2226 if (group_type == SID_NAME_DOM_GRP) {
2227 NTSTATUS result = rpc_add_groupmem(pipe_hnd, mem_ctx,
2228 &group_sid, argv[1]);
2230 if (!NT_STATUS_IS_OK(result)) {
2231 d_fprintf(stderr, "Could not add %s to %s: %s\n",
2232 argv[1], argv[0], nt_errstr(result));
2237 if (group_type == SID_NAME_ALIAS) {
2238 NTSTATUS result = rpc_add_aliasmem(pipe_hnd, mem_ctx,
2239 &group_sid, argv[1]);
2241 if (!NT_STATUS_IS_OK(result)) {
2242 d_fprintf(stderr, "Could not add %s to %s: %s\n",
2243 argv[1], argv[0], nt_errstr(result));
2248 d_fprintf(stderr, "Can only add members to global or local groups "
2249 "which %s is not\n", argv[0]);
2251 return NT_STATUS_UNSUCCESSFUL;
2254 static int rpc_group_addmem(struct net_context *c, int argc, const char **argv)
2256 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2257 rpc_group_addmem_internals,
2261 static NTSTATUS rpc_del_groupmem(struct net_context *c,
2262 struct rpc_pipe_client *pipe_hnd,
2263 TALLOC_CTX *mem_ctx,
2264 const DOM_SID *group_sid,
2267 POLICY_HND connect_pol, domain_pol;
2270 POLICY_HND group_pol;
2272 struct samr_Ids rids, rid_types;
2273 struct lsa_String lsa_acct_name;
2277 sid_copy(&sid, group_sid);
2279 if (!sid_split_rid(&sid, &group_rid))
2280 return NT_STATUS_UNSUCCESSFUL;
2282 /* Get sam policy handle */
2283 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2285 MAXIMUM_ALLOWED_ACCESS,
2287 if (!NT_STATUS_IS_OK(result))
2290 /* Get domain policy handle */
2291 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2293 MAXIMUM_ALLOWED_ACCESS,
2296 if (!NT_STATUS_IS_OK(result))
2299 init_lsa_String(&lsa_acct_name, member);
2301 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
2307 if (!NT_STATUS_IS_OK(result)) {
2308 d_fprintf(stderr, "Could not lookup up group member %s\n", member);
2312 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
2314 MAXIMUM_ALLOWED_ACCESS,
2318 if (!NT_STATUS_IS_OK(result))
2321 result = rpccli_samr_DeleteGroupMember(pipe_hnd, mem_ctx,
2326 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
2330 static NTSTATUS rpc_del_aliasmem(struct rpc_pipe_client *pipe_hnd,
2331 TALLOC_CTX *mem_ctx,
2332 const DOM_SID *alias_sid,
2335 POLICY_HND connect_pol, domain_pol;
2338 POLICY_HND alias_pol;
2341 enum lsa_SidType member_type;
2345 sid_copy(&sid, alias_sid);
2347 if (!sid_split_rid(&sid, &alias_rid))
2348 return NT_STATUS_UNSUCCESSFUL;
2350 result = get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd), mem_ctx,
2351 member, &member_sid, &member_type);
2353 if (!NT_STATUS_IS_OK(result)) {
2354 d_fprintf(stderr, "Could not lookup up group member %s\n", member);
2358 /* Get sam policy handle */
2359 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2361 MAXIMUM_ALLOWED_ACCESS,
2363 if (!NT_STATUS_IS_OK(result)) {
2367 /* Get domain policy handle */
2368 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2370 MAXIMUM_ALLOWED_ACCESS,
2373 if (!NT_STATUS_IS_OK(result)) {
2377 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2379 MAXIMUM_ALLOWED_ACCESS,
2383 if (!NT_STATUS_IS_OK(result))
2386 result = rpccli_samr_DeleteAliasMember(pipe_hnd, mem_ctx,
2390 if (!NT_STATUS_IS_OK(result))
2394 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
2398 static NTSTATUS rpc_group_delmem_internals(struct net_context *c,
2399 const DOM_SID *domain_sid,
2400 const char *domain_name,
2401 struct cli_state *cli,
2402 struct rpc_pipe_client *pipe_hnd,
2403 TALLOC_CTX *mem_ctx,
2408 enum lsa_SidType group_type;
2410 if (argc != 2 || c->display_usage) {
2412 "net rpc group delmem <group> <member>\n"
2413 " Delete a member from a group\n"
2414 " group\tGroup to delete member from\n"
2415 " member\tMember to delete from group\n");
2416 return NT_STATUS_UNSUCCESSFUL;
2419 if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
2420 &group_sid, &group_type))) {
2421 d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]);
2422 return NT_STATUS_UNSUCCESSFUL;
2425 if (group_type == SID_NAME_DOM_GRP) {
2426 NTSTATUS result = rpc_del_groupmem(c, pipe_hnd, mem_ctx,
2427 &group_sid, argv[1]);
2429 if (!NT_STATUS_IS_OK(result)) {
2430 d_fprintf(stderr, "Could not del %s from %s: %s\n",
2431 argv[1], argv[0], nt_errstr(result));
2436 if (group_type == SID_NAME_ALIAS) {
2437 NTSTATUS result = rpc_del_aliasmem(pipe_hnd, mem_ctx,
2438 &group_sid, argv[1]);
2440 if (!NT_STATUS_IS_OK(result)) {
2441 d_fprintf(stderr, "Could not del %s from %s: %s\n",
2442 argv[1], argv[0], nt_errstr(result));
2447 d_fprintf(stderr, "Can only delete members from global or local groups "
2448 "which %s is not\n", argv[0]);
2450 return NT_STATUS_UNSUCCESSFUL;
2453 static int rpc_group_delmem(struct net_context *c, int argc, const char **argv)
2455 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2456 rpc_group_delmem_internals,
2461 * List groups on a remote RPC server.
2463 * All parameters are provided by the run_rpc_command function, except for
2464 * argc, argv which are passes through.
2466 * @param domain_sid The domain sid acquired from the remote server.
2467 * @param cli A cli_state connected to the server.
2468 * @param mem_ctx Talloc context, destroyed on completion of the function.
2469 * @param argc Standard main() style argc.
2470 * @param argv Standard main() style argv. Initial components are already
2473 * @return Normal NTSTATUS return.
2476 static NTSTATUS rpc_group_list_internals(struct net_context *c,
2477 const DOM_SID *domain_sid,
2478 const char *domain_name,
2479 struct cli_state *cli,
2480 struct rpc_pipe_client *pipe_hnd,
2481 TALLOC_CTX *mem_ctx,
2485 POLICY_HND connect_pol, domain_pol;
2486 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
2487 uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
2488 struct samr_SamArray *groups = NULL;
2489 bool global = false;
2491 bool builtin = false;
2493 if (c->display_usage) {
2495 "net rpc group list [global] [local] [builtin]\n"
2496 " List groups on RPC server\n"
2497 " global\tList global groups\n"
2498 " local\tList local groups\n"
2499 " builtin\tList builtin groups\n"
2500 " If none of global, local or builtin is "
2501 "specified, all three options are considered set\n");
2502 return NT_STATUS_OK;
2511 for (i=0; i<argc; i++) {
2512 if (strequal(argv[i], "global"))
2515 if (strequal(argv[i], "local"))
2518 if (strequal(argv[i], "builtin"))
2522 /* Get sam policy handle */
2524 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2526 MAXIMUM_ALLOWED_ACCESS,
2528 if (!NT_STATUS_IS_OK(result)) {
2532 /* Get domain policy handle */
2534 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2536 MAXIMUM_ALLOWED_ACCESS,
2537 CONST_DISCARD(struct dom_sid2 *, domain_sid),
2539 if (!NT_STATUS_IS_OK(result)) {
2543 /* Query domain groups */
2544 if (c->opt_long_list_entries)
2545 d_printf("\nGroup name Comment"
2546 "\n-----------------------------\n");
2548 uint32_t max_size, total_size, returned_size;
2549 union samr_DispInfo info;
2553 get_query_dispinfo_params(
2554 loop_count, &max_entries, &max_size);
2556 result = rpccli_samr_QueryDisplayInfo(pipe_hnd, mem_ctx,
2565 num_entries = info.info3.count;
2566 start_idx += info.info3.count;
2568 if (!NT_STATUS_IS_OK(result) &&
2569 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
2572 for (i = 0; i < num_entries; i++) {
2574 const char *group = NULL;
2575 const char *desc = NULL;
2577 group = info.info3.entries[i].account_name.string;
2578 desc = info.info3.entries[i].description.string;
2580 if (c->opt_long_list_entries)
2581 printf("%-21.21s %-50.50s\n",
2584 printf("%s\n", group);
2586 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2587 /* query domain aliases */
2592 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
2598 if (!NT_STATUS_IS_OK(result) &&
2599 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
2602 for (i = 0; i < num_entries; i++) {
2604 const char *description = NULL;
2606 if (c->opt_long_list_entries) {
2608 POLICY_HND alias_pol;
2609 union samr_AliasInfo *info = NULL;
2611 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2614 groups->entries[i].idx,
2616 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd, mem_ctx,
2620 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd, mem_ctx,
2622 description = info->description.string;
2626 if (description != NULL) {
2627 printf("%-21.21s %-50.50s\n",
2628 groups->entries[i].name.string,
2631 printf("%s\n", groups->entries[i].name.string);
2634 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2635 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
2636 /* Get builtin policy handle */
2638 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2640 MAXIMUM_ALLOWED_ACCESS,
2641 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
2643 if (!NT_STATUS_IS_OK(result)) {
2646 /* query builtin aliases */
2649 if (!builtin) break;
2651 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
2657 if (!NT_STATUS_IS_OK(result) &&
2658 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
2661 for (i = 0; i < num_entries; i++) {
2663 const char *description = NULL;
2665 if (c->opt_long_list_entries) {
2667 POLICY_HND alias_pol;
2668 union samr_AliasInfo *info = NULL;
2670 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2673 groups->entries[i].idx,
2675 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd, mem_ctx,
2679 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd, mem_ctx,
2681 description = info->description.string;
2685 if (description != NULL) {
2686 printf("%-21.21s %-50.50s\n",
2687 groups->entries[i].name.string,
2690 printf("%s\n", groups->entries[i].name.string);
2693 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2699 static int rpc_group_list(struct net_context *c, int argc, const char **argv)
2701 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2702 rpc_group_list_internals,
2706 static NTSTATUS rpc_list_group_members(struct net_context *c,
2707 struct rpc_pipe_client *pipe_hnd,
2708 TALLOC_CTX *mem_ctx,
2709 const char *domain_name,
2710 const DOM_SID *domain_sid,
2711 POLICY_HND *domain_pol,
2715 POLICY_HND group_pol;
2716 uint32 num_members, *group_rids;
2718 struct samr_RidTypeArray *rids = NULL;
2719 struct lsa_Strings names;
2720 struct samr_Ids types;
2723 sid_to_fstring(sid_str, domain_sid);
2725 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
2727 MAXIMUM_ALLOWED_ACCESS,
2731 if (!NT_STATUS_IS_OK(result))
2734 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,
2738 if (!NT_STATUS_IS_OK(result))
2741 num_members = rids->count;
2742 group_rids = rids->rids;
2744 while (num_members > 0) {
2745 int this_time = 512;
2747 if (num_members < this_time)
2748 this_time = num_members;
2750 result = rpccli_samr_LookupRids(pipe_hnd, mem_ctx,
2757 if (!NT_STATUS_IS_OK(result))
2760 /* We only have users as members, but make the output
2761 the same as the output of alias members */
2763 for (i = 0; i < this_time; i++) {
2765 if (c->opt_long_list_entries) {
2766 printf("%s-%d %s\\%s %d\n", sid_str,
2767 group_rids[i], domain_name,
2768 names.names[i].string,
2771 printf("%s\\%s\n", domain_name,
2772 names.names[i].string);
2776 num_members -= this_time;
2780 return NT_STATUS_OK;
2783 static NTSTATUS rpc_list_alias_members(struct net_context *c,
2784 struct rpc_pipe_client *pipe_hnd,
2785 TALLOC_CTX *mem_ctx,
2786 POLICY_HND *domain_pol,
2790 struct rpc_pipe_client *lsa_pipe;
2791 POLICY_HND alias_pol, lsa_pol;
2793 DOM_SID *alias_sids;
2796 enum lsa_SidType *types;
2798 struct lsa_SidArray sid_array;
2800 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2802 MAXIMUM_ALLOWED_ACCESS,
2806 if (!NT_STATUS_IS_OK(result))
2809 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
2813 if (!NT_STATUS_IS_OK(result)) {
2814 d_fprintf(stderr, "Couldn't list alias members\n");
2818 num_members = sid_array.num_sids;
2820 if (num_members == 0) {
2821 return NT_STATUS_OK;
2824 result = cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd),
2825 &ndr_table_lsarpc.syntax_id,
2827 if (!NT_STATUS_IS_OK(result)) {
2828 d_fprintf(stderr, "Couldn't open LSA pipe. Error was %s\n",
2829 nt_errstr(result) );
2833 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, true,
2834 SEC_RIGHTS_MAXIMUM_ALLOWED, &lsa_pol);
2836 if (!NT_STATUS_IS_OK(result)) {
2837 d_fprintf(stderr, "Couldn't open LSA policy handle\n");
2838 TALLOC_FREE(lsa_pipe);
2842 alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members);
2844 d_fprintf(stderr, "Out of memory\n");
2845 TALLOC_FREE(lsa_pipe);
2846 return NT_STATUS_NO_MEMORY;
2849 for (i=0; i<num_members; i++) {
2850 sid_copy(&alias_sids[i], sid_array.sids[i].sid);
2853 result = rpccli_lsa_lookup_sids(lsa_pipe, mem_ctx, &lsa_pol,
2854 num_members, alias_sids,
2855 &domains, &names, &types);
2857 if (!NT_STATUS_IS_OK(result) &&
2858 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
2859 d_fprintf(stderr, "Couldn't lookup SIDs\n");
2860 TALLOC_FREE(lsa_pipe);
2864 for (i = 0; i < num_members; i++) {
2866 sid_to_fstring(sid_str, &alias_sids[i]);
2868 if (c->opt_long_list_entries) {
2869 printf("%s %s\\%s %d\n", sid_str,
2870 domains[i] ? domains[i] : "*unknown*",
2871 names[i] ? names[i] : "*unknown*", types[i]);
2874 printf("%s\\%s\n", domains[i], names[i]);
2876 printf("%s\n", sid_str);
2880 TALLOC_FREE(lsa_pipe);
2881 return NT_STATUS_OK;
2884 static NTSTATUS rpc_group_members_internals(struct net_context *c,
2885 const DOM_SID *domain_sid,
2886 const char *domain_name,
2887 struct cli_state *cli,
2888 struct rpc_pipe_client *pipe_hnd,
2889 TALLOC_CTX *mem_ctx,
2894 POLICY_HND connect_pol, domain_pol;
2895 struct samr_Ids rids, rid_types;
2896 struct lsa_String lsa_acct_name;
2898 /* Get sam policy handle */
2900 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2902 MAXIMUM_ALLOWED_ACCESS,
2905 if (!NT_STATUS_IS_OK(result))
2908 /* Get domain policy handle */
2910 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2912 MAXIMUM_ALLOWED_ACCESS,
2913 CONST_DISCARD(struct dom_sid2 *, domain_sid),
2916 if (!NT_STATUS_IS_OK(result))
2919 init_lsa_String(&lsa_acct_name, argv[0]); /* sure? */
2921 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
2928 if (!NT_STATUS_IS_OK(result)) {
2930 /* Ok, did not find it in the global sam, try with builtin */
2932 DOM_SID sid_Builtin;
2934 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
2936 sid_copy(&sid_Builtin, &global_sid_Builtin);
2938 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2940 MAXIMUM_ALLOWED_ACCESS,
2944 if (!NT_STATUS_IS_OK(result)) {
2945 d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
2949 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
2956 if (!NT_STATUS_IS_OK(result)) {
2957 d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
2962 if (rids.count != 1) {
2963 d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
2967 if (rid_types.ids[0] == SID_NAME_DOM_GRP) {
2968 return rpc_list_group_members(c, pipe_hnd, mem_ctx, domain_name,
2969 domain_sid, &domain_pol,
2973 if (rid_types.ids[0] == SID_NAME_ALIAS) {
2974 return rpc_list_alias_members(c, pipe_hnd, mem_ctx, &domain_pol,
2978 return NT_STATUS_NO_SUCH_GROUP;
2981 static int rpc_group_members(struct net_context *c, int argc, const char **argv)
2983 if (argc != 1 || c->display_usage) {
2984 return rpc_group_usage(c, argc, argv);
2987 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2988 rpc_group_members_internals,
2992 static int rpc_group_rename_internals(struct net_context *c, int argc, const char **argv)
2994 NET_API_STATUS status;
2995 struct GROUP_INFO_0 g0;
2999 d_printf("Usage: 'net rpc group rename group newname'\n");
3003 g0.grpi0_name = argv[1];
3005 status = NetGroupSetInfo(c->opt_host,
3012 d_fprintf(stderr, "Renaming group %s failed with: %s\n",
3013 argv[0], libnetapi_get_error_string(c->netapi_ctx,
3021 static int rpc_group_rename(struct net_context *c, int argc, const char **argv)
3023 if (argc != 2 || c->display_usage) {
3024 return rpc_group_usage(c, argc, argv);
3027 return rpc_group_rename_internals(c, argc, argv);
3031 * 'net rpc group' entrypoint.
3032 * @param argc Standard main() style argc.
3033 * @param argv Standard main() style argv. Initial components are already
3037 int net_rpc_group(struct net_context *c, int argc, const char **argv)
3039 NET_API_STATUS status;
3041 struct functable func[] = {
3046 "Create specified group",
3047 "net rpc group add\n"
3048 " Create specified group"
3054 "Delete specified group",
3055 "net rpc group delete\n"
3056 " Delete specified group"
3062 "Add member to group",
3063 "net rpc group addmem\n"
3064 " Add member to group"
3070 "Remove member from group",
3071 "net rpc group delmem\n"
3072 " Remove member from group"
3079 "net rpc group list\n"
3086 "List group members",
3087 "net rpc group members\n"
3088 " List group members"
3095 "net rpc group rename\n"
3098 {NULL, NULL, 0, NULL, NULL}
3101 status = libnetapi_init(&c->netapi_ctx);
3105 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
3106 libnetapi_set_password(c->netapi_ctx, c->opt_password);
3109 if (c->display_usage) {
3110 d_printf("Usage:\n");
3111 d_printf("net rpc group\n"
3112 " Alias for net rpc group list global local "
3114 net_display_usage_from_functable(func);
3118 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
3119 rpc_group_list_internals,
3123 return net_run_function(c, argc, argv, "net rpc group", func);
3126 /****************************************************************************/
3128 static int rpc_share_usage(struct net_context *c, int argc, const char **argv)
3130 return net_share_usage(c, argc, argv);
3134 * Add a share on a remote RPC server.
3136 * All parameters are provided by the run_rpc_command function, except for
3137 * argc, argv which are passed through.
3139 * @param domain_sid The domain sid acquired from the remote server.
3140 * @param cli A cli_state connected to the server.
3141 * @param mem_ctx Talloc context, destroyed on completion of the function.
3142 * @param argc Standard main() style argc.
3143 * @param argv Standard main() style argv. Initial components are already
3146 * @return Normal NTSTATUS return.
3148 static NTSTATUS rpc_share_add_internals(struct net_context *c,
3149 const DOM_SID *domain_sid,
3150 const char *domain_name,
3151 struct cli_state *cli,
3152 struct rpc_pipe_client *pipe_hnd,
3153 TALLOC_CTX *mem_ctx,int argc,
3160 uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
3161 uint32 num_users=0, perms=0;
3162 char *password=NULL; /* don't allow a share password */
3164 union srvsvc_NetShareInfo info;
3165 struct srvsvc_NetShareInfo2 info2;
3166 uint32_t parm_error = 0;
3168 if ((sharename = talloc_strdup(mem_ctx, argv[0])) == NULL) {
3169 return NT_STATUS_NO_MEMORY;
3172 path = strchr(sharename, '=');
3174 return NT_STATUS_UNSUCCESSFUL;
3177 info2.name = sharename;
3179 info2.comment = c->opt_comment;
3180 info2.permissions = perms;
3181 info2.max_users = c->opt_maxusers;
3182 info2.current_users = num_users;
3184 info2.password = password;
3186 info.info2 = &info2;
3188 status = rpccli_srvsvc_NetShareAdd(pipe_hnd, mem_ctx,
3197 static int rpc_share_add(struct net_context *c, int argc, const char **argv)
3199 if ((argc < 1) || !strchr(argv[0], '=') || c->display_usage) {
3200 return rpc_share_usage(c, argc, argv);
3202 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3203 rpc_share_add_internals,
3208 * Delete a share on a remote RPC server.
3210 * All parameters are provided by the run_rpc_command function, except for
3211 * argc, argv which are passed through.
3213 * @param domain_sid The domain sid acquired from the remote server.
3214 * @param cli A cli_state connected to the server.
3215 * @param mem_ctx Talloc context, destroyed on completion of the function.
3216 * @param argc Standard main() style argc.
3217 * @param argv Standard main() style argv. Initial components are already
3220 * @return Normal NTSTATUS return.
3222 static NTSTATUS rpc_share_del_internals(struct net_context *c,
3223 const DOM_SID *domain_sid,
3224 const char *domain_name,
3225 struct cli_state *cli,
3226 struct rpc_pipe_client *pipe_hnd,
3227 TALLOC_CTX *mem_ctx,
3233 return rpccli_srvsvc_NetShareDel(pipe_hnd, mem_ctx,
3241 * Delete a share on a remote RPC server.
3243 * @param domain_sid The domain sid acquired from the remote server.
3244 * @param argc Standard main() style argc.
3245 * @param argv Standard main() style argv. Initial components are already
3248 * @return A shell status integer (0 for success).
3250 static int rpc_share_delete(struct net_context *c, int argc, const char **argv)
3252 if (argc < 1 || c->display_usage) {
3253 return rpc_share_usage(c, argc, argv);
3255 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3256 rpc_share_del_internals,
3261 * Formatted print of share info
3263 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3266 static void display_share_info_1(struct net_context *c,
3267 struct srvsvc_NetShareInfo1 *r)
3269 if (c->opt_long_list_entries) {
3270 d_printf("%-12s %-8.8s %-50s\n",
3272 c->share_type[r->type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)],
3275 d_printf("%s\n", r->name);
3279 static WERROR get_share_info(struct net_context *c,
3280 struct rpc_pipe_client *pipe_hnd,
3281 TALLOC_CTX *mem_ctx,
3285 struct srvsvc_NetShareInfoCtr *info_ctr)
3289 union srvsvc_NetShareInfo info;
3291 /* no specific share requested, enumerate all */
3294 uint32_t preferred_len = 0xffffffff;
3295 uint32_t total_entries = 0;
3296 uint32_t resume_handle = 0;
3298 info_ctr->level = level;
3300 status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, mem_ctx,
3310 /* request just one share */
3311 status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
3318 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
3323 ZERO_STRUCTP(info_ctr);
3325 info_ctr->level = level;
3330 struct srvsvc_NetShareCtr1 *ctr1;
3332 ctr1 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr1);
3333 W_ERROR_HAVE_NO_MEMORY(ctr1);
3336 ctr1->array = info.info1;
3338 info_ctr->ctr.ctr1 = ctr1;
3342 struct srvsvc_NetShareCtr2 *ctr2;
3344 ctr2 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr2);
3345 W_ERROR_HAVE_NO_MEMORY(ctr2);
3348 ctr2->array = info.info2;
3350 info_ctr->ctr.ctr2 = ctr2;
3354 struct srvsvc_NetShareCtr502 *ctr502;
3356 ctr502 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr502);
3357 W_ERROR_HAVE_NO_MEMORY(ctr502);
3360 ctr502->array = info.info502;
3362 info_ctr->ctr.ctr502 = ctr502;
3370 * List shares on a remote RPC server.
3372 * All parameters are provided by the run_rpc_command function, except for
3373 * argc, argv which are passed through.
3375 * @param domain_sid The domain sid acquired from the remote server.
3376 * @param cli A cli_state connected to the server.
3377 * @param mem_ctx Talloc context, destroyed on completion of the function.
3378 * @param argc Standard main() style argc.
3379 * @param argv Standard main() style argv. Initial components are already
3382 * @return Normal NTSTATUS return.
3385 static NTSTATUS rpc_share_list_internals(struct net_context *c,
3386 const DOM_SID *domain_sid,
3387 const char *domain_name,
3388 struct cli_state *cli,
3389 struct rpc_pipe_client *pipe_hnd,
3390 TALLOC_CTX *mem_ctx,
3394 struct srvsvc_NetShareInfoCtr info_ctr;
3395 struct srvsvc_NetShareCtr1 ctr1;
3397 uint32 i, level = 1;
3399 ZERO_STRUCT(info_ctr);
3403 info_ctr.ctr.ctr1 = &ctr1;
3405 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3407 if (!W_ERROR_IS_OK(result))
3410 /* Display results */
3412 if (c->opt_long_list_entries) {
3414 "\nEnumerating shared resources (exports) on remote server:\n\n"
3415 "\nShare name Type Description\n"
3416 "---------- ---- -----------\n");
3418 for (i = 0; i < info_ctr.ctr.ctr1->count; i++)
3419 display_share_info_1(c, &info_ctr.ctr.ctr1->array[i]);
3421 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
3425 * 'net rpc share list' entrypoint.
3426 * @param argc Standard main() style argc.
3427 * @param argv Standard main() style argv. Initial components are already
3430 static int rpc_share_list(struct net_context *c, int argc, const char **argv)
3432 if (c->display_usage) {
3434 "net rpc share list\n"
3435 " List shares on remote server\n");
3439 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3440 rpc_share_list_internals, argc, argv);
3443 static bool check_share_availability(struct cli_state *cli, const char *netname)
3445 if (!cli_send_tconX(cli, netname, "A:", "", 0)) {
3446 d_printf("skipping [%s]: not a file share.\n", netname);
3456 static bool check_share_sanity(struct net_context *c, struct cli_state *cli,
3457 const char *netname, uint32 type)
3459 /* only support disk shares */
3460 if (! ( type == STYPE_DISKTREE || type == (STYPE_DISKTREE | STYPE_HIDDEN)) ) {
3461 printf("share [%s] is not a diskshare (type: %x)\n", netname, type);
3465 /* skip builtin shares */
3466 /* FIXME: should print$ be added too ? */
3467 if (strequal(netname,"IPC$") || strequal(netname,"ADMIN$") ||
3468 strequal(netname,"global"))
3471 if (c->opt_exclude && in_list(netname, c->opt_exclude, false)) {
3472 printf("excluding [%s]\n", netname);
3476 return check_share_availability(cli, netname);
3480 * Migrate shares from a remote RPC server to the local RPC server.
3482 * All parameters are provided by the run_rpc_command function, except for
3483 * argc, argv which are passed through.
3485 * @param domain_sid The domain sid acquired from the remote server.
3486 * @param cli A cli_state connected to the server.
3487 * @param mem_ctx Talloc context, destroyed on completion of the function.
3488 * @param argc Standard main() style argc.
3489 * @param argv Standard main() style argv. Initial components are already
3492 * @return Normal NTSTATUS return.
3495 static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c,
3496 const DOM_SID *domain_sid,
3497 const char *domain_name,
3498 struct cli_state *cli,
3499 struct rpc_pipe_client *pipe_hnd,
3500 TALLOC_CTX *mem_ctx,
3505 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3506 struct srvsvc_NetShareInfoCtr ctr_src;
3508 struct rpc_pipe_client *srvsvc_pipe = NULL;
3509 struct cli_state *cli_dst = NULL;
3510 uint32 level = 502; /* includes secdesc */
3511 uint32_t parm_error = 0;
3513 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3515 if (!W_ERROR_IS_OK(result))
3518 /* connect destination PI_SRVSVC */
3519 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe, PI_SRVSVC);
3520 if (!NT_STATUS_IS_OK(nt_status))
3524 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3526 union srvsvc_NetShareInfo info;
3527 struct srvsvc_NetShareInfo502 info502 =
3528 ctr_src.ctr.ctr502->array[i];
3530 /* reset error-code */
3531 nt_status = NT_STATUS_UNSUCCESSFUL;
3533 if (!check_share_sanity(c, cli, info502.name, info502.type))
3536 /* finally add the share on the dst server */
3538 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3539 info502.name, info502.path, info502.comment);
3541 info.info502 = &info502;
3543 nt_status = rpccli_srvsvc_NetShareAdd(srvsvc_pipe, mem_ctx,
3544 srvsvc_pipe->desthost,
3550 if (W_ERROR_V(result) == W_ERROR_V(WERR_ALREADY_EXISTS)) {
3551 printf(" [%s] does already exist\n",
3556 if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
3557 printf("cannot add share: %s\n", dos_errstr(result));
3563 nt_status = NT_STATUS_OK;
3567 cli_shutdown(cli_dst);
3575 * Migrate shares from a RPC server to another.
3577 * @param argc Standard main() style argc.
3578 * @param argv Standard main() style argv. Initial components are already
3581 * @return A shell status integer (0 for success).
3583 static int rpc_share_migrate_shares(struct net_context *c, int argc,
3586 if (c->display_usage) {
3588 "net rpc share migrate shares\n"
3589 " Migrate shares to local server\n");
3594 printf("no server to migrate\n");
3598 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3599 rpc_share_migrate_shares_internals,
3606 * @param f file_info
3607 * @param mask current search mask
3608 * @param state arg-pointer
3611 static void copy_fn(const char *mnt, file_info *f,
3612 const char *mask, void *state)
3614 static NTSTATUS nt_status;
3615 static struct copy_clistate *local_state;
3616 static fstring filename, new_mask;
3619 struct net_context *c;
3621 local_state = (struct copy_clistate *)state;
3622 nt_status = NT_STATUS_UNSUCCESSFUL;
3626 if (strequal(f->name, ".") || strequal(f->name, ".."))
3629 DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
3632 if (f->mode & aDIR) {
3634 DEBUG(3,("got dir: %s\n", f->name));
3636 fstrcpy(dir, local_state->cwd);
3638 fstrcat(dir, f->name);
3640 switch (net_mode_share)
3642 case NET_MODE_SHARE_MIGRATE:
3643 /* create that directory */
3644 nt_status = net_copy_file(c, local_state->mem_ctx,
3645 local_state->cli_share_src,
3646 local_state->cli_share_dst,
3648 c->opt_acls? true : false,
3649 c->opt_attrs? true : false,
3650 c->opt_timestamps? true:false,
3654 d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
3658 if (!NT_STATUS_IS_OK(nt_status))
3659 printf("could not handle dir %s: %s\n",
3660 dir, nt_errstr(nt_status));
3662 /* search below that directory */
3663 fstrcpy(new_mask, dir);
3664 fstrcat(new_mask, "\\*");
3666 old_dir = local_state->cwd;
3667 local_state->cwd = dir;
3668 if (!sync_files(local_state, new_mask))
3669 printf("could not handle files\n");
3670 local_state->cwd = old_dir;
3677 fstrcpy(filename, local_state->cwd);
3678 fstrcat(filename, "\\");
3679 fstrcat(filename, f->name);
3681 DEBUG(3,("got file: %s\n", filename));
3683 switch (net_mode_share)
3685 case NET_MODE_SHARE_MIGRATE:
3686 nt_status = net_copy_file(c, local_state->mem_ctx,
3687 local_state->cli_share_src,
3688 local_state->cli_share_dst,
3690 c->opt_acls? true : false,
3691 c->opt_attrs? true : false,
3692 c->opt_timestamps? true: false,
3696 d_fprintf(stderr, "Unsupported file mode %d\n", net_mode_share);
3700 if (!NT_STATUS_IS_OK(nt_status))
3701 printf("could not handle file %s: %s\n",
3702 filename, nt_errstr(nt_status));
3707 * sync files, can be called recursivly to list files
3708 * and then call copy_fn for each file
3710 * @param cp_clistate pointer to the copy_clistate we work with
3711 * @param mask the current search mask
3713 * @return Boolean result
3715 static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
3717 struct cli_state *targetcli;
3718 char *targetpath = NULL;
3720 DEBUG(3,("calling cli_list with mask: %s\n", mask));
3722 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate->cli_share_src,
3723 mask, &targetcli, &targetpath ) ) {
3724 d_fprintf(stderr, "cli_resolve_path %s failed with error: %s\n",
3725 mask, cli_errstr(cp_clistate->cli_share_src));
3729 if (cli_list(targetcli, targetpath, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
3730 d_fprintf(stderr, "listing %s failed with error: %s\n",
3731 mask, cli_errstr(targetcli));
3740 * Set the top level directory permissions before we do any further copies.
3741 * Should set up ACL inheritance.
3744 bool copy_top_level_perms(struct net_context *c,
3745 struct copy_clistate *cp_clistate,
3746 const char *sharename)
3748 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3750 switch (net_mode_share) {
3751 case NET_MODE_SHARE_MIGRATE:
3752 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename));
3753 nt_status = net_copy_fileattr(c,
3754 cp_clistate->mem_ctx,
3755 cp_clistate->cli_share_src,
3756 cp_clistate->cli_share_dst,
3758 c->opt_acls? true : false,
3759 c->opt_attrs? true : false,
3760 c->opt_timestamps? true: false,
3764 d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
3768 if (!NT_STATUS_IS_OK(nt_status)) {
3769 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3770 sharename, nt_errstr(nt_status));
3778 * Sync all files inside a remote share to another share (over smb).
3780 * All parameters are provided by the run_rpc_command function, except for
3781 * argc, argv which are passed through.
3783 * @param domain_sid The domain sid acquired from the remote server.
3784 * @param cli A cli_state connected to the server.
3785 * @param mem_ctx Talloc context, destroyed on completion of the function.
3786 * @param argc Standard main() style argc.
3787 * @param argv Standard main() style argv. Initial components are already
3790 * @return Normal NTSTATUS return.
3793 static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c,
3794 const DOM_SID *domain_sid,
3795 const char *domain_name,
3796 struct cli_state *cli,
3797 struct rpc_pipe_client *pipe_hnd,
3798 TALLOC_CTX *mem_ctx,
3803 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3804 struct srvsvc_NetShareInfoCtr ctr_src;
3807 struct copy_clistate cp_clistate;
3808 bool got_src_share = false;
3809 bool got_dst_share = false;
3810 const char *mask = "\\*";
3813 dst = SMB_STRDUP(c->opt_destination?c->opt_destination:"127.0.0.1");
3815 nt_status = NT_STATUS_NO_MEMORY;
3819 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3822 if (!W_ERROR_IS_OK(result))
3825 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3827 struct srvsvc_NetShareInfo502 info502 =
3828 ctr_src.ctr.ctr502->array[i];
3830 if (!check_share_sanity(c, cli, info502.name, info502.type))
3833 /* one might not want to mirror whole discs :) */
3834 if (strequal(info502.name, "print$") || info502.name[1] == '$') {
3835 d_printf("skipping [%s]: builtin/hidden share\n", info502.name);
3839 switch (net_mode_share)
3841 case NET_MODE_SHARE_MIGRATE:
3845 d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
3848 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3850 c->opt_acls ? "including" : "without",
3851 c->opt_attrs ? "including" : "without",
3852 c->opt_timestamps ? "(preserving timestamps)" : "");
3854 cp_clistate.mem_ctx = mem_ctx;
3855 cp_clistate.cli_share_src = NULL;
3856 cp_clistate.cli_share_dst = NULL;
3857 cp_clistate.cwd = NULL;
3858 cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;
3861 /* open share source */
3862 nt_status = connect_to_service(c, &cp_clistate.cli_share_src,
3863 &cli->dest_ss, cli->desthost,
3864 info502.name, "A:");
3865 if (!NT_STATUS_IS_OK(nt_status))
3868 got_src_share = true;
3870 if (net_mode_share == NET_MODE_SHARE_MIGRATE) {
3871 /* open share destination */
3872 nt_status = connect_to_service(c, &cp_clistate.cli_share_dst,
3873 NULL, dst, info502.name, "A:");
3874 if (!NT_STATUS_IS_OK(nt_status))
3877 got_dst_share = true;
3880 if (!copy_top_level_perms(c, &cp_clistate, info502.name)) {
3881 d_fprintf(stderr, "Could not handle the top level directory permissions for the share: %s\n", info502.name);
3882 nt_status = NT_STATUS_UNSUCCESSFUL;
3886 if (!sync_files(&cp_clistate, mask)) {
3887 d_fprintf(stderr, "could not handle files for share: %s\n", info502.name);
3888 nt_status = NT_STATUS_UNSUCCESSFUL;
3893 nt_status = NT_STATUS_OK;
3898 cli_shutdown(cp_clistate.cli_share_src);
3901 cli_shutdown(cp_clistate.cli_share_dst);
3908 static int rpc_share_migrate_files(struct net_context *c, int argc, const char **argv)
3910 if (c->display_usage) {
3912 "net share migrate files\n"
3913 " Migrate files to local server\n");
3918 d_printf("no server to migrate\n");
3922 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3923 rpc_share_migrate_files_internals,
3928 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3930 * All parameters are provided by the run_rpc_command function, except for
3931 * argc, argv which are passed through.
3933 * @param domain_sid The domain sid acquired from the remote server.
3934 * @param cli A cli_state connected to the server.
3935 * @param mem_ctx Talloc context, destroyed on completion of the function.
3936 * @param argc Standard main() style argc.
3937 * @param argv Standard main() style argv. Initial components are already
3940 * @return Normal NTSTATUS return.
3943 static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c,
3944 const DOM_SID *domain_sid,
3945 const char *domain_name,
3946 struct cli_state *cli,
3947 struct rpc_pipe_client *pipe_hnd,
3948 TALLOC_CTX *mem_ctx,
3953 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3954 struct srvsvc_NetShareInfoCtr ctr_src;
3955 union srvsvc_NetShareInfo info;
3957 struct rpc_pipe_client *srvsvc_pipe = NULL;
3958 struct cli_state *cli_dst = NULL;
3959 uint32 level = 502; /* includes secdesc */
3960 uint32_t parm_error = 0;
3962 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3965 if (!W_ERROR_IS_OK(result))
3968 /* connect destination PI_SRVSVC */
3969 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe, PI_SRVSVC);
3970 if (!NT_STATUS_IS_OK(nt_status))
3974 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3976 struct srvsvc_NetShareInfo502 info502 =
3977 ctr_src.ctr.ctr502->array[i];
3979 /* reset error-code */
3980 nt_status = NT_STATUS_UNSUCCESSFUL;
3982 if (!check_share_sanity(c, cli, info502.name, info502.type))
3985 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3986 info502.name, info502.path, info502.comment);
3989 display_sec_desc(info502.sd_buf.sd);
3991 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3992 info.info502 = &info502;
3994 /* finally modify the share on the dst server */
3995 nt_status = rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe, mem_ctx,
3996 srvsvc_pipe->desthost,
4002 if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
4003 printf("cannot set share-acl: %s\n", dos_errstr(result));
4009 nt_status = NT_STATUS_OK;
4013 cli_shutdown(cli_dst);
4021 * Migrate share-acls from a RPC server to another.
4023 * @param argc Standard main() style argc.
4024 * @param argv Standard main() style argv. Initial components are already
4027 * @return A shell status integer (0 for success).
4029 static int rpc_share_migrate_security(struct net_context *c, int argc,
4032 if (c->display_usage) {
4034 "net rpc share migrate security\n"
4035 " Migrate share-acls to local server\n");
4040 d_printf("no server to migrate\n");
4044 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4045 rpc_share_migrate_security_internals,
4050 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4051 * from one server to another.
4053 * @param argc Standard main() style argc.
4054 * @param argv Standard main() style argv. Initial components are already
4057 * @return A shell status integer (0 for success).
4060 static int rpc_share_migrate_all(struct net_context *c, int argc,
4065 if (c->display_usage) {
4067 "net rpc share migrate all\n"
4068 " Migrates shares including all share settings\n");
4073 d_printf("no server to migrate\n");
4077 /* order is important. we don't want to be locked out by the share-acl
4078 * before copying files - gd */
4080 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4081 rpc_share_migrate_shares_internals, argc, argv);
4085 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4086 rpc_share_migrate_files_internals, argc, argv);
4090 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4091 rpc_share_migrate_security_internals, argc,
4097 * 'net rpc share migrate' entrypoint.
4098 * @param argc Standard main() style argc.
4099 * @param argv Standard main() style argv. Initial components are already
4102 static int rpc_share_migrate(struct net_context *c, int argc, const char **argv)
4105 struct functable func[] = {
4108 rpc_share_migrate_all,
4110 "Migrate shares from remote to local server",
4111 "net rpc share migrate all\n"
4112 " Migrate shares from remote to local server"
4116 rpc_share_migrate_files,
4118 "Migrate files from remote to local server",
4119 "net rpc share migrate files\n"
4120 " Migrate files from remote to local server"
4124 rpc_share_migrate_security,
4126 "Migrate share-ACLs from remote to local server",
4127 "net rpc share migrate security\n"
4128 " Migrate share-ACLs from remote to local server"
4132 rpc_share_migrate_shares,
4134 "Migrate shares from remote to local server",
4135 "net rpc share migrate shares\n"
4136 " Migrate shares from remote to local server"
4138 {NULL, NULL, 0, NULL, NULL}
4141 net_mode_share = NET_MODE_SHARE_MIGRATE;
4143 return net_run_function(c, argc, argv, "net rpc share migrate", func);
4152 static int num_server_aliases;
4153 static struct full_alias *server_aliases;
4156 * Add an alias to the static list.
4158 static void push_alias(TALLOC_CTX *mem_ctx, struct full_alias *alias)
4160 if (server_aliases == NULL)
4161 server_aliases = SMB_MALLOC_ARRAY(struct full_alias, 100);
4163 server_aliases[num_server_aliases] = *alias;
4164 num_server_aliases += 1;
4168 * For a specific domain on the server, fetch all the aliases
4169 * and their members. Add all of them to the server_aliases.
4172 static NTSTATUS rpc_fetch_domain_aliases(struct rpc_pipe_client *pipe_hnd,
4173 TALLOC_CTX *mem_ctx,
4174 POLICY_HND *connect_pol,
4175 const DOM_SID *domain_sid)
4177 uint32 start_idx, max_entries, num_entries, i;
4178 struct samr_SamArray *groups = NULL;
4180 POLICY_HND domain_pol;
4182 /* Get domain policy handle */
4184 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
4186 MAXIMUM_ALLOWED_ACCESS,
4187 CONST_DISCARD(struct dom_sid2 *, domain_sid),
4189 if (!NT_STATUS_IS_OK(result))
4196 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
4202 for (i = 0; i < num_entries; i++) {
4204 POLICY_HND alias_pol;
4205 struct full_alias alias;
4206 struct lsa_SidArray sid_array;
4209 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
4211 MAXIMUM_ALLOWED_ACCESS,
4212 groups->entries[i].idx,
4214 if (!NT_STATUS_IS_OK(result))
4217 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
4220 if (!NT_STATUS_IS_OK(result))
4223 alias.num_members = sid_array.num_sids;
4225 result = rpccli_samr_Close(pipe_hnd, mem_ctx, &alias_pol);
4226 if (!NT_STATUS_IS_OK(result))
4229 alias.members = NULL;
4231 if (alias.num_members > 0) {
4232 alias.members = SMB_MALLOC_ARRAY(DOM_SID, alias.num_members);
4234 for (j = 0; j < alias.num_members; j++)
4235 sid_copy(&alias.members[j],
4236 sid_array.sids[j].sid);
4239 sid_copy(&alias.sid, domain_sid);
4240 sid_append_rid(&alias.sid, groups->entries[i].idx);
4242 push_alias(mem_ctx, &alias);
4244 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
4246 result = NT_STATUS_OK;
4249 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
4255 * Dump server_aliases as names for debugging purposes.
4258 static NTSTATUS rpc_aliaslist_dump(struct net_context *c,
4259 const DOM_SID *domain_sid,
4260 const char *domain_name,
4261 struct cli_state *cli,
4262 struct rpc_pipe_client *pipe_hnd,
4263 TALLOC_CTX *mem_ctx,
4271 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
4272 SEC_RIGHTS_MAXIMUM_ALLOWED,
4274 if (!NT_STATUS_IS_OK(result))
4277 for (i=0; i<num_server_aliases; i++) {
4280 enum lsa_SidType *types;
4283 struct full_alias *alias = &server_aliases[i];
4285 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol, 1,
4287 &domains, &names, &types);
4288 if (!NT_STATUS_IS_OK(result))
4291 DEBUG(1, ("%s\\%s %d: ", domains[0], names[0], types[0]));
4293 if (alias->num_members == 0) {
4298 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol,
4301 &domains, &names, &types);
4303 if (!NT_STATUS_IS_OK(result) &&
4304 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
4307 for (j=0; j<alias->num_members; j++)
4308 DEBUG(1, ("%s\\%s (%d); ",
4309 domains[j] ? domains[j] : "*unknown*",
4310 names[j] ? names[j] : "*unknown*",types[j]));
4314 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
4316 return NT_STATUS_OK;
4320 * Fetch a list of all server aliases and their members into
4324 static NTSTATUS rpc_aliaslist_internals(struct net_context *c,
4325 const DOM_SID *domain_sid,
4326 const char *domain_name,
4327 struct cli_state *cli,
4328 struct rpc_pipe_client *pipe_hnd,
4329 TALLOC_CTX *mem_ctx,
4334 POLICY_HND connect_pol;
4336 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
4338 MAXIMUM_ALLOWED_ACCESS,
4341 if (!NT_STATUS_IS_OK(result))
4344 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4345 &global_sid_Builtin);
4347 if (!NT_STATUS_IS_OK(result))
4350 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4353 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
4358 static void init_user_token(NT_USER_TOKEN *token, DOM_SID *user_sid)
4360 token->num_sids = 4;
4362 if (!(token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4))) {
4363 d_fprintf(stderr, "malloc failed\n");
4364 token->num_sids = 0;
4368 token->user_sids[0] = *user_sid;
4369 sid_copy(&token->user_sids[1], &global_sid_World);
4370 sid_copy(&token->user_sids[2], &global_sid_Network);
4371 sid_copy(&token->user_sids[3], &global_sid_Authenticated_Users);
4374 static void free_user_token(NT_USER_TOKEN *token)
4376 SAFE_FREE(token->user_sids);
4379 static bool is_sid_in_token(NT_USER_TOKEN *token, DOM_SID *sid)
4383 for (i=0; i<token->num_sids; i++) {
4384 if (sid_compare(sid, &token->user_sids[i]) == 0)
4390 static void add_sid_to_token(NT_USER_TOKEN *token, DOM_SID *sid)
4392 if (is_sid_in_token(token, sid))
4395 token->user_sids = SMB_REALLOC_ARRAY(token->user_sids, DOM_SID, token->num_sids+1);
4396 if (!token->user_sids) {
4400 sid_copy(&token->user_sids[token->num_sids], sid);
4402 token->num_sids += 1;
4407 NT_USER_TOKEN token;
4410 static void dump_user_token(struct user_token *token)
4414 d_printf("%s\n", token->name);
4416 for (i=0; i<token->token.num_sids; i++) {
4417 d_printf(" %s\n", sid_string_tos(&token->token.user_sids[i]));
4421 static bool is_alias_member(DOM_SID *sid, struct full_alias *alias)
4425 for (i=0; i<alias->num_members; i++) {
4426 if (sid_compare(sid, &alias->members[i]) == 0)
4433 static void collect_sid_memberships(NT_USER_TOKEN *token, DOM_SID sid)
4437 for (i=0; i<num_server_aliases; i++) {
4438 if (is_alias_member(&sid, &server_aliases[i]))
4439 add_sid_to_token(token, &server_aliases[i].sid);
4444 * We got a user token with all the SIDs we can know about without asking the
4445 * server directly. These are the user and domain group sids. All of these can
4446 * be members of aliases. So scan the list of aliases for each of the SIDs and
4447 * add them to the token.
4450 static void collect_alias_memberships(NT_USER_TOKEN *token)
4452 int num_global_sids = token->num_sids;
4455 for (i=0; i<num_global_sids; i++) {
4456 collect_sid_memberships(token, token->user_sids[i]);
4460 static bool get_user_sids(const char *domain, const char *user, NT_USER_TOKEN *token)
4462 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4463 enum wbcSidType type;
4465 struct wbcDomainSid wsid;
4466 char *sid_str = NULL;
4468 uint32_t num_groups;
4469 gid_t *groups = NULL;
4472 fstr_sprintf(full_name, "%s%c%s",
4473 domain, *lp_winbind_separator(), user);
4475 /* First let's find out the user sid */
4477 wbc_status = wbcLookupName(domain, user, &wsid, &type);
4479 if (!WBC_ERROR_IS_OK(wbc_status)) {
4480 DEBUG(1, ("winbind could not find %s: %s\n",
4481 full_name, wbcErrorString(wbc_status)));
4485 wbc_status = wbcSidToString(&wsid, &sid_str);
4486 if (!WBC_ERROR_IS_OK(wbc_status)) {
4490 if (type != SID_NAME_USER) {
4491 wbcFreeMemory(sid_str);
4492 DEBUG(1, ("%s is not a user\n", full_name));
4496 string_to_sid(&user_sid, sid_str);
4497 wbcFreeMemory(sid_str);
4500 init_user_token(token, &user_sid);
4502 /* And now the groups winbind knows about */
4504 wbc_status = wbcGetGroups(full_name, &num_groups, &groups);
4505 if (!WBC_ERROR_IS_OK(wbc_status)) {
4506 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4507 full_name, wbcErrorString(wbc_status)));
4511 for (i = 0; i < num_groups; i++) {
4512 gid_t gid = groups[i];
4515 wbc_status = wbcGidToSid(gid, &wsid);
4516 if (!WBC_ERROR_IS_OK(wbc_status)) {
4517 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4518 gid, wbcErrorString(wbc_status)));
4519 wbcFreeMemory(groups);
4523 wbc_status = wbcSidToString(&wsid, &sid_str);
4524 if (!WBC_ERROR_IS_OK(wbc_status)) {
4525 wbcFreeMemory(groups);
4529 DEBUG(3, (" %s\n", sid_str));
4531 string_to_sid(&sid, sid_str);
4532 wbcFreeMemory(sid_str);
4535 add_sid_to_token(token, &sid);
4537 wbcFreeMemory(groups);
4543 * Get a list of all user tokens we want to look at
4546 static bool get_user_tokens(struct net_context *c, int *num_tokens,
4547 struct user_token **user_tokens)
4549 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4550 uint32_t i, num_users;
4552 struct user_token *result;
4553 TALLOC_CTX *frame = NULL;
4555 if (lp_winbind_use_default_domain() &&
4556 (c->opt_target_workgroup == NULL)) {
4557 d_fprintf(stderr, "winbind use default domain = yes set, "
4558 "please specify a workgroup\n");
4562 /* Send request to winbind daemon */
4564 wbc_status = wbcListUsers(NULL, &num_users, &users);
4565 if (!WBC_ERROR_IS_OK(wbc_status)) {
4566 DEBUG(1, ("winbind could not list users: %s\n",
4567 wbcErrorString(wbc_status)));
4571 result = SMB_MALLOC_ARRAY(struct user_token, num_users);
4573 if (result == NULL) {
4574 DEBUG(1, ("Could not malloc sid array\n"));
4575 wbcFreeMemory(users);
4579 frame = talloc_stackframe();
4580 for (i=0; i < num_users; i++) {
4581 fstring domain, user;
4584 fstrcpy(result[i].name, users[i]);
4586 p = strchr(users[i], *lp_winbind_separator());
4588 DEBUG(3, ("%s\n", users[i]));
4591 fstrcpy(domain, c->opt_target_workgroup);
4592 fstrcpy(user, users[i]);
4595 fstrcpy(domain, users[i]);
4600 get_user_sids(domain, user, &(result[i].token));
4604 wbcFreeMemory(users);
4606 *num_tokens = num_users;
4607 *user_tokens = result;
4612 static bool get_user_tokens_from_file(FILE *f,
4614 struct user_token **tokens)
4616 struct user_token *token = NULL;
4621 if (fgets(line, sizeof(line)-1, f) == NULL) {
4625 if (line[strlen(line)-1] == '\n')
4626 line[strlen(line)-1] = '\0';
4628 if (line[0] == ' ') {
4632 string_to_sid(&sid, &line[1]);
4634 if (token == NULL) {
4635 DEBUG(0, ("File does not begin with username"));
4639 add_sid_to_token(&token->token, &sid);
4643 /* And a new user... */
4646 *tokens = SMB_REALLOC_ARRAY(*tokens, struct user_token, *num_tokens);
4647 if (*tokens == NULL) {
4648 DEBUG(0, ("Could not realloc tokens\n"));
4652 token = &((*tokens)[*num_tokens-1]);
4654 fstrcpy(token->name, line);
4655 token->token.num_sids = 0;
4656 token->token.user_sids = NULL;
4665 * Show the list of all users that have access to a share
4668 static void show_userlist(struct rpc_pipe_client *pipe_hnd,
4669 TALLOC_CTX *mem_ctx,
4670 const char *netname,
4672 struct user_token *tokens)
4675 SEC_DESC *share_sd = NULL;
4676 SEC_DESC *root_sd = NULL;
4677 struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd);
4679 union srvsvc_NetShareInfo info;
4684 status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
4691 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
4692 DEBUG(1, ("Coult not query secdesc for share %s\n",
4697 share_sd = info.info502->sd_buf.sd;
4698 if (share_sd == NULL) {
4699 DEBUG(1, ("Got no secdesc for share %s\n",
4705 if (!cli_send_tconX(cli, netname, "A:", "", 0)) {
4709 fnum = cli_nt_create(cli, "\\", READ_CONTROL_ACCESS);
4712 root_sd = cli_query_secdesc(cli, fnum, mem_ctx);
4715 for (i=0; i<num_tokens; i++) {
4718 if (share_sd != NULL) {
4719 if (!se_access_check(share_sd, &tokens[i].token,
4720 1, &acc_granted, &status)) {
4721 DEBUG(1, ("Could not check share_sd for "
4727 if (!NT_STATUS_IS_OK(status))
4731 if (root_sd == NULL) {
4732 d_printf(" %s\n", tokens[i].name);
4736 if (!se_access_check(root_sd, &tokens[i].token,
4737 1, &acc_granted, &status)) {
4738 DEBUG(1, ("Could not check root_sd for user %s\n",
4743 if (!NT_STATUS_IS_OK(status))
4746 d_printf(" %s\n", tokens[i].name);
4750 cli_close(cli, fnum);
4762 static void collect_share(const char *name, uint32 m,
4763 const char *comment, void *state)
4765 struct share_list *share_list = (struct share_list *)state;
4767 if (m != STYPE_DISKTREE)
4770 share_list->num_shares += 1;
4771 share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares);
4772 if (!share_list->shares) {
4773 share_list->num_shares = 0;
4776 share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name);
4780 * List shares on a remote RPC server, including the security descriptors.
4782 * All parameters are provided by the run_rpc_command function, except for
4783 * argc, argv which are passed through.
4785 * @param domain_sid The domain sid acquired from the remote server.
4786 * @param cli A cli_state connected to the server.
4787 * @param mem_ctx Talloc context, destroyed on completion of the function.
4788 * @param argc Standard main() style argc.
4789 * @param argv Standard main() style argv. Initial components are already
4792 * @return Normal NTSTATUS return.
4795 static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
4796 const DOM_SID *domain_sid,
4797 const char *domain_name,
4798 struct cli_state *cli,
4799 struct rpc_pipe_client *pipe_hnd,
4800 TALLOC_CTX *mem_ctx,
4810 struct user_token *tokens = NULL;
4813 struct share_list share_list;
4818 f = fopen(argv[0], "r");
4822 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno)));
4823 return NT_STATUS_UNSUCCESSFUL;
4826 r = get_user_tokens_from_file(f, &num_tokens, &tokens);
4832 DEBUG(0, ("Could not read users from file\n"));
4833 return NT_STATUS_UNSUCCESSFUL;
4836 for (i=0; i<num_tokens; i++)
4837 collect_alias_memberships(&tokens[i].token);
4839 init_enum_hnd(&hnd, 0);
4841 share_list.num_shares = 0;
4842 share_list.shares = NULL;
4844 ret = cli_RNetShareEnum(cli, collect_share, &share_list);
4847 DEBUG(0, ("Error returning browse list: %s\n",
4852 for (i = 0; i < share_list.num_shares; i++) {
4853 char *netname = share_list.shares[i];
4855 if (netname[strlen(netname)-1] == '$')
4858 d_printf("%s\n", netname);
4860 show_userlist(pipe_hnd, mem_ctx, netname,
4861 num_tokens, tokens);
4864 for (i=0; i<num_tokens; i++) {
4865 free_user_token(&tokens[i].token);
4868 SAFE_FREE(share_list.shares);
4870 return NT_STATUS_OK;
4873 static int rpc_share_allowedusers(struct net_context *c, int argc,
4878 if (c->display_usage) {
4880 "net rpc share allowedusers\n"
4881 " List allowed users\n");
4885 result = run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
4886 rpc_aliaslist_internals,
4891 result = run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
4897 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4898 rpc_share_allowedusers_internals,
4902 int net_usersidlist(struct net_context *c, int argc, const char **argv)
4905 struct user_token *tokens = NULL;
4909 net_usersidlist_usage(c, argc, argv);
4913 if (!get_user_tokens(c, &num_tokens, &tokens)) {
4914 DEBUG(0, ("Could not get the user/sid list\n"));
4918 for (i=0; i<num_tokens; i++) {
4919 dump_user_token(&tokens[i]);
4920 free_user_token(&tokens[i].token);
4927 int net_usersidlist_usage(struct net_context *c, int argc, const char **argv)
4929 d_printf("net usersidlist\n"
4930 "\tprints out a list of all users the running winbind knows\n"
4931 "\tabout, together with all their SIDs. This is used as\n"
4932 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4934 net_common_flags_usage(c, argc, argv);
4939 * 'net rpc share' entrypoint.
4940 * @param argc Standard main() style argc.
4941 * @param argv Standard main() style argv. Initial components are already
4945 int net_rpc_share(struct net_context *c, int argc, const char **argv)
4947 struct functable func[] = {
4953 "net rpc share add\n"
4961 "net rpc share delete\n"
4966 rpc_share_allowedusers,
4968 "Modify allowed users",
4969 "net rpc share allowedusers\n"
4970 " Modify allowed users"
4976 "Migrate share to local server",
4977 "net rpc share migrate\n"
4978 " Migrate share to local server"
4985 "net rpc share list\n"
4988 {NULL, NULL, 0, NULL, NULL}
4993 if (c->display_usage) {
4997 " Alias for net rpc share list\n");
4998 net_display_usage_from_functable(func);
5002 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
5003 rpc_share_list_internals,
5007 return net_run_function(c, argc, argv, "net rpc share", func);
5010 static NTSTATUS rpc_sh_share_list(struct net_context *c,
5011 TALLOC_CTX *mem_ctx,
5012 struct rpc_sh_ctx *ctx,
5013 struct rpc_pipe_client *pipe_hnd,
5014 int argc, const char **argv)
5016 return rpc_share_list_internals(c, ctx->domain_sid, ctx->domain_name,
5017 ctx->cli, pipe_hnd, mem_ctx,
5021 static NTSTATUS rpc_sh_share_add(struct net_context *c,
5022 TALLOC_CTX *mem_ctx,
5023 struct rpc_sh_ctx *ctx,
5024 struct rpc_pipe_client *pipe_hnd,
5025 int argc, const char **argv)
5029 uint32_t parm_err = 0;
5030 union srvsvc_NetShareInfo info;
5031 struct srvsvc_NetShareInfo2 info2;
5033 if ((argc < 2) || (argc > 3)) {
5034 d_fprintf(stderr, "usage: %s <share> <path> [comment]\n",
5036 return NT_STATUS_INVALID_PARAMETER;
5039 info2.name = argv[0];
5040 info2.type = STYPE_DISKTREE;
5041 info2.comment = (argc == 3) ? argv[2] : "";
5042 info2.permissions = 0;
5043 info2.max_users = 0;
5044 info2.current_users = 0;
5045 info2.path = argv[1];
5046 info2.password = NULL;
5048 info.info2 = &info2;
5050 status = rpccli_srvsvc_NetShareAdd(pipe_hnd, mem_ctx,
5060 static NTSTATUS rpc_sh_share_delete(struct net_context *c,
5061 TALLOC_CTX *mem_ctx,
5062 struct rpc_sh_ctx *ctx,
5063 struct rpc_pipe_client *pipe_hnd,
5064 int argc, const char **argv)
5070 d_fprintf(stderr, "usage: %s <share>\n", ctx->whoami);
5071 return NT_STATUS_INVALID_PARAMETER;
5074 status = rpccli_srvsvc_NetShareDel(pipe_hnd, mem_ctx,
5083 static NTSTATUS rpc_sh_share_info(struct net_context *c,
5084 TALLOC_CTX *mem_ctx,
5085 struct rpc_sh_ctx *ctx,
5086 struct rpc_pipe_client *pipe_hnd,
5087 int argc, const char **argv)
5089 union srvsvc_NetShareInfo info;
5094 d_fprintf(stderr, "usage: %s <share>\n", ctx->whoami);
5095 return NT_STATUS_INVALID_PARAMETER;
5098 status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx,
5104 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
5108 d_printf("Name: %s\n", info.info2->name);
5109 d_printf("Comment: %s\n", info.info2->comment);
5110 d_printf("Path: %s\n", info.info2->path);
5111 d_printf("Password: %s\n", info.info2->password);
5114 return werror_to_ntstatus(result);
5117 struct rpc_sh_cmd *net_rpc_share_cmds(struct net_context *c, TALLOC_CTX *mem_ctx,
5118 struct rpc_sh_ctx *ctx)
5120 static struct rpc_sh_cmd cmds[] = {
5122 { "list", NULL, PI_SRVSVC, rpc_sh_share_list,
5123 "List available shares" },
5125 { "add", NULL, PI_SRVSVC, rpc_sh_share_add,
5128 { "delete", NULL, PI_SRVSVC, rpc_sh_share_delete,
5131 { "info", NULL, PI_SRVSVC, rpc_sh_share_info,
5132 "Get information about a share" },
5134 { NULL, NULL, 0, NULL, NULL }
5140 /****************************************************************************/
5142 static int rpc_file_usage(struct net_context *c, int argc, const char **argv)
5144 return net_file_usage(c, argc, argv);
5148 * Close a file on a remote RPC server.
5150 * All parameters are provided by the run_rpc_command function, except for
5151 * argc, argv which are passed through.
5153 * @param c A net_context structure.
5154 * @param domain_sid The domain sid acquired from the remote server.
5155 * @param cli A cli_state connected to the server.
5156 * @param mem_ctx Talloc context, destroyed on completion of the function.
5157 * @param argc Standard main() style argc.
5158 * @param argv Standard main() style argv. Initial components are already
5161 * @return Normal NTSTATUS return.
5163 static NTSTATUS rpc_file_close_internals(struct net_context *c,
5164 const DOM_SID *domain_sid,
5165 const char *domain_name,
5166 struct cli_state *cli,
5167 struct rpc_pipe_client *pipe_hnd,
5168 TALLOC_CTX *mem_ctx,
5172 return rpccli_srvsvc_NetFileClose(pipe_hnd, mem_ctx,
5174 atoi(argv[0]), NULL);
5178 * Close a file on a remote RPC server.
5180 * @param argc Standard main() style argc.
5181 * @param argv Standard main() style argv. Initial components are already
5184 * @return A shell status integer (0 for success).
5186 static int rpc_file_close(struct net_context *c, int argc, const char **argv)
5188 if (argc < 1 || c->display_usage) {
5189 return rpc_file_usage(c, argc, argv);
5192 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
5193 rpc_file_close_internals,
5198 * Formatted print of open file info
5200 * @param r struct srvsvc_NetFileInfo3 contents
5203 static void display_file_info_3(struct srvsvc_NetFileInfo3 *r)
5205 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5206 r->fid, r->user, r->permissions, r->num_locks, r->path);
5210 * List open files on a remote RPC server.
5212 * All parameters are provided by the run_rpc_command function, except for
5213 * argc, argv which are passed through.
5215 * @param c A net_context structure.
5216 * @param domain_sid The domain sid acquired from the remote server.
5217 * @param cli A cli_state connected to the server.
5218 * @param mem_ctx Talloc context, destroyed on completion of the function.
5219 * @param argc Standard main() style argc.
5220 * @param argv Standard main() style argv. Initial components are already
5223 * @return Normal NTSTATUS return.
5226 static NTSTATUS rpc_file_list_internals(struct net_context *c,
5227 const DOM_SID *domain_sid,
5228 const char *domain_name,
5229 struct cli_state *cli,
5230 struct rpc_pipe_client *pipe_hnd,
5231 TALLOC_CTX *mem_ctx,
5235 struct srvsvc_NetFileInfoCtr info_ctr;
5236 struct srvsvc_NetFileCtr3 ctr3;
5239 uint32 preferred_len = 0xffffffff, i;
5240 const char *username=NULL;
5241 uint32_t total_entries = 0;
5242 uint32_t resume_handle = 0;
5244 /* if argc > 0, must be user command */
5246 username = smb_xstrdup(argv[0]);
5248 ZERO_STRUCT(info_ctr);
5252 info_ctr.ctr.ctr3 = &ctr3;
5254 status = rpccli_srvsvc_NetFileEnum(pipe_hnd, mem_ctx,
5264 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
5267 /* Display results */
5270 "\nEnumerating open files on remote server:\n\n"
5271 "\nFileId Opened by Perms Locks Path"
5272 "\n------ --------- ----- ----- ---- \n");
5273 for (i = 0; i < total_entries; i++)
5274 display_file_info_3(&info_ctr.ctr.ctr3->array[i]);
5276 return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
5280 * List files for a user on a remote RPC server.
5282 * @param argc Standard main() style argc.
5283 * @param argv Standard main() style argv. Initial components are already
5286 * @return A shell status integer (0 for success)..
5289 static int rpc_file_user(struct net_context *c, int argc, const char **argv)
5291 if (argc < 1 || c->display_usage) {
5292 return rpc_file_usage(c, argc, argv);
5295 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
5296 rpc_file_list_internals,
5301 * 'net rpc file' entrypoint.
5302 * @param argc Standard main() style argc.
5303 * @param argv Standard main() style argv. Initial components are already
5307 int net_rpc_file(struct net_context *c, int argc, const char **argv)
5309 struct functable func[] = {
5314 "Close opened file",
5315 "net rpc file close\n"
5316 " Close opened file"
5322 "List files opened by user",
5323 "net rpc file user\n"
5324 " List files opened by user"
5331 "Display information about opened file",
5332 "net rpc file info\n"
5333 " Display information about opened file"
5336 {NULL, NULL, 0, NULL, NULL}
5340 if (c->display_usage) {
5341 d_printf("Usage:\n");
5342 d_printf("net rpc file\n"
5343 " List opened files\n");
5344 net_display_usage_from_functable(func);
5348 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
5349 rpc_file_list_internals,
5353 return net_run_function(c, argc, argv, "net rpc file", func);
5357 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5359 * All parameters are provided by the run_rpc_command function, except for
5360 * argc, argv which are passed through.
5362 * @param c A net_context structure.
5363 * @param domain_sid The domain sid acquired from the remote server.
5364 * @param cli A cli_state connected to the server.
5365 * @param mem_ctx Talloc context, destroyed on completion of the function.
5366 * @param argc Standard main() style argc.
5367 * @param argv Standard main() style argv. Initial components are already
5370 * @return Normal NTSTATUS return.
5373 static NTSTATUS rpc_shutdown_abort_internals(struct net_context *c,
5374 const DOM_SID *domain_sid,
5375 const char *domain_name,
5376 struct cli_state *cli,
5377 struct rpc_pipe_client *pipe_hnd,
5378 TALLOC_CTX *mem_ctx,
5382 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5384 result = rpccli_initshutdown_Abort(pipe_hnd, mem_ctx, NULL, NULL);
5386 if (NT_STATUS_IS_OK(result)) {
5387 d_printf("\nShutdown successfully aborted\n");
5388 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5390 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5396 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5398 * All parameters are provided by the run_rpc_command function, except for
5399 * argc, argv which are passed through.
5401 * @param c A net_context structure.
5402 * @param domain_sid The domain sid acquired from the remote server.
5403 * @param cli A cli_state connected to the server.
5404 * @param mem_ctx Talloc context, destroyed on completion of the function.
5405 * @param argc Standard main() style argc.
5406 * @param argv Standard main() style argv. Initial components are already
5409 * @return Normal NTSTATUS return.
5412 static NTSTATUS rpc_reg_shutdown_abort_internals(struct net_context *c,
5413 const DOM_SID *domain_sid,
5414 const char *domain_name,
5415 struct cli_state *cli,
5416 struct rpc_pipe_client *pipe_hnd,
5417 TALLOC_CTX *mem_ctx,
5421 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5423 result = rpccli_winreg_AbortSystemShutdown(pipe_hnd, mem_ctx, NULL, NULL);
5425 if (NT_STATUS_IS_OK(result)) {
5426 d_printf("\nShutdown successfully aborted\n");
5427 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5429 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5435 * ABORT the shutdown of a remote RPC server.
5437 * @param argc Standard main() style argc.
5438 * @param argv Standard main() style argv. Initial components are already
5441 * @return A shell status integer (0 for success).
5444 static int rpc_shutdown_abort(struct net_context *c, int argc,
5449 if (c->display_usage) {
5451 "net rpc abortshutdown\n"
5452 " Abort a scheduled shutdown\n");
5456 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5457 rpc_shutdown_abort_internals, argc, argv);
5462 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5464 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5465 rpc_reg_shutdown_abort_internals,
5470 * Shut down a remote RPC Server via initshutdown pipe.
5472 * All parameters are provided by the run_rpc_command function, except for
5473 * argc, argv which are passed through.
5475 * @param c A net_context structure.
5476 * @param domain_sid The domain sid acquired from the remote server.
5477 * @param cli A cli_state connected to the server.
5478 * @param mem_ctx Talloc context, destroyed on completion of the function.
5479 * @param argc Standard main() style argc.
5480 * @param argv Standard main() style argv. Initial components are already
5483 * @return Normal NTSTATUS return.
5486 NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
5487 const DOM_SID *domain_sid,
5488 const char *domain_name,
5489 struct cli_state *cli,
5490 struct rpc_pipe_client *pipe_hnd,
5491 TALLOC_CTX *mem_ctx,
5495 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5496 const char *msg = "This machine will be shutdown shortly";
5497 uint32 timeout = 20;
5498 struct initshutdown_String msg_string;
5499 struct initshutdown_String_sub s;
5501 if (c->opt_comment) {
5502 msg = c->opt_comment;
5504 if (c->opt_timeout) {
5505 timeout = c->opt_timeout;
5509 msg_string.name = &s;
5511 /* create an entry */
5512 result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,
5513 &msg_string, timeout, c->opt_force, c->opt_reboot,
5516 if (NT_STATUS_IS_OK(result)) {
5517 d_printf("\nShutdown of remote machine succeeded\n");
5518 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5520 DEBUG(1,("Shutdown of remote machine failed!\n"));
5526 * Shut down a remote RPC Server via winreg pipe.
5528 * All parameters are provided by the run_rpc_command function, except for
5529 * argc, argv which are passed through.
5531 * @param c A net_context structure.
5532 * @param domain_sid The domain sid acquired from the remote server.
5533 * @param cli A cli_state connected to the server.
5534 * @param mem_ctx Talloc context, destroyed on completion of the function.
5535 * @param argc Standard main() style argc.
5536 * @param argv Standard main() style argv. Initial components are already
5539 * @return Normal NTSTATUS return.
5542 NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
5543 const DOM_SID *domain_sid,
5544 const char *domain_name,
5545 struct cli_state *cli,
5546 struct rpc_pipe_client *pipe_hnd,
5547 TALLOC_CTX *mem_ctx,
5551 const char *msg = "This machine will be shutdown shortly";
5552 uint32 timeout = 20;
5553 struct initshutdown_String msg_string;
5554 struct initshutdown_String_sub s;
5558 if (c->opt_comment) {
5559 msg = c->opt_comment;
5562 msg_string.name = &s;
5564 if (c->opt_timeout) {
5565 timeout = c->opt_timeout;
5568 /* create an entry */
5569 result = rpccli_winreg_InitiateSystemShutdown(pipe_hnd, mem_ctx, NULL,
5570 &msg_string, timeout, c->opt_force, c->opt_reboot,
5573 if (NT_STATUS_IS_OK(result)) {
5574 d_printf("\nShutdown of remote machine succeeded\n");
5576 d_fprintf(stderr, "\nShutdown of remote machine failed\n");
5577 if ( W_ERROR_EQUAL(werr, WERR_MACHINE_LOCKED) )
5578 d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
5580 d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(werr));
5587 * Shut down a remote RPC server.
5589 * @param argc Standard main() style argc.
5590 * @param argv Standard main() style argv. Initial components are already
5593 * @return A shell status integer (0 for success).
5596 static int rpc_shutdown(struct net_context *c, int argc, const char **argv)
5600 if (c->display_usage) {
5602 "net rpc shutdown\n"
5603 " Shut down a remote RPC server\n");
5607 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5608 rpc_init_shutdown_internals, argc, argv);
5611 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5612 rc = run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5613 rpc_reg_shutdown_internals, argc, argv);
5619 /***************************************************************************
5620 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5621 ***************************************************************************/
5624 * Add interdomain trust account to the RPC server.
5625 * All parameters (except for argc and argv) are passed by run_rpc_command
5628 * @param c A net_context structure.
5629 * @param domain_sid The domain sid acquired from the server.
5630 * @param cli A cli_state connected to the server.
5631 * @param mem_ctx Talloc context, destroyed on completion of the function.
5632 * @param argc Standard main() style argc.
5633 * @param argv Standard main() style argv. Initial components are already
5636 * @return normal NTSTATUS return code.
5639 static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
5640 const DOM_SID *domain_sid,
5641 const char *domain_name,
5642 struct cli_state *cli,
5643 struct rpc_pipe_client *pipe_hnd,
5644 TALLOC_CTX *mem_ctx,
5648 POLICY_HND connect_pol, domain_pol, user_pol;
5649 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5651 struct lsa_String lsa_acct_name;
5653 uint32 acct_flags=0;
5655 uint32_t access_granted = 0;
5656 union samr_UserInfo info;
5657 unsigned int orig_timeout;
5660 d_printf("Usage: net rpc trustdom add <domain_name> "
5661 "<trust password>\n");
5662 return NT_STATUS_INVALID_PARAMETER;
5666 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5669 if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
5670 return NT_STATUS_NO_MEMORY;
5673 strupper_m(acct_name);
5675 init_lsa_String(&lsa_acct_name, acct_name);
5677 /* Get samr policy handle */
5678 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5680 MAXIMUM_ALLOWED_ACCESS,
5682 if (!NT_STATUS_IS_OK(result)) {
5686 /* Get domain policy handle */
5687 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5689 MAXIMUM_ALLOWED_ACCESS,
5690 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5692 if (!NT_STATUS_IS_OK(result)) {
5696 /* This call can take a long time - allow the server to time out.
5697 * 35 seconds should do it. */
5699 orig_timeout = rpccli_set_timeout(pipe_hnd, 35000);
5701 /* Create trusting domain's account */
5702 acb_info = ACB_NORMAL;
5703 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
5704 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
5705 SAMR_USER_ACCESS_SET_PASSWORD |
5706 SAMR_USER_ACCESS_GET_ATTRIBUTES |
5707 SAMR_USER_ACCESS_SET_ATTRIBUTES;
5709 result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
5718 /* And restore our original timeout. */
5719 rpccli_set_timeout(pipe_hnd, orig_timeout);
5721 if (!NT_STATUS_IS_OK(result)) {
5722 d_printf("net rpc trustdom add: create user %s failed %s\n",
5723 acct_name, nt_errstr(result));
5729 struct samr_LogonHours hours;
5730 struct lsa_BinaryString parameters;
5731 const int units_per_week = 168;
5734 encode_pw_buffer(pwbuf, argv[1], STR_UNICODE);
5736 ZERO_STRUCT(notime);
5738 ZERO_STRUCT(parameters);
5740 hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week);
5742 result = NT_STATUS_NO_MEMORY;
5745 hours.units_per_week = units_per_week;
5746 memset(hours.bits, 0xFF, units_per_week);
5748 init_samr_user_info23(&info.info23,
5749 notime, notime, notime,
5750 notime, notime, notime,
5751 NULL, NULL, NULL, NULL, NULL,
5752 NULL, NULL, NULL, NULL, ¶meters,
5753 0, 0, ACB_DOMTRUST, SAMR_FIELD_ACCT_FLAGS,
5755 0, 0, 0, 0, 0, 0, 0,
5758 SamOEMhashBlob(info.info23.password.data, 516,
5759 &cli->user_session_key);
5761 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
5766 if (!NT_STATUS_IS_OK(result)) {
5767 DEBUG(0,("Could not set trust account password: %s\n",
5768 nt_errstr(result)));
5774 SAFE_FREE(acct_name);
5779 * Create interdomain trust account for a remote domain.
5781 * @param argc Standard argc.
5782 * @param argv Standard argv without initial components.
5784 * @return Integer status (0 means success).
5787 static int rpc_trustdom_add(struct net_context *c, int argc, const char **argv)
5789 if (argc > 0 && !c->display_usage) {
5790 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5791 rpc_trustdom_add_internals, argc, argv);
5794 "net rpc trustdom add <domain_name> <trust password>\n");
5801 * Remove interdomain trust account from the RPC server.
5802 * All parameters (except for argc and argv) are passed by run_rpc_command
5805 * @param c A net_context structure.
5806 * @param domain_sid The domain sid acquired from the server.
5807 * @param cli A cli_state connected to the server.
5808 * @param mem_ctx Talloc context, destroyed on completion of the function.
5809 * @param argc Standard main() style argc.
5810 * @param argv Standard main() style argv. Initial components are already
5813 * @return normal NTSTATUS return code.
5816 static NTSTATUS rpc_trustdom_del_internals(struct net_context *c,
5817 const DOM_SID *domain_sid,
5818 const char *domain_name,
5819 struct cli_state *cli,
5820 struct rpc_pipe_client *pipe_hnd,
5821 TALLOC_CTX *mem_ctx,
5825 POLICY_HND connect_pol, domain_pol, user_pol;
5826 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5828 DOM_SID trust_acct_sid;
5829 struct samr_Ids user_rids, name_types;
5830 struct lsa_String lsa_acct_name;
5833 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5834 return NT_STATUS_INVALID_PARAMETER;
5838 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5840 acct_name = talloc_asprintf(mem_ctx, "%s$", argv[0]);
5842 if (acct_name == NULL)
5843 return NT_STATUS_NO_MEMORY;
5845 strupper_m(acct_name);
5847 /* Get samr policy handle */
5848 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5850 MAXIMUM_ALLOWED_ACCESS,
5852 if (!NT_STATUS_IS_OK(result)) {
5856 /* Get domain policy handle */
5857 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5859 MAXIMUM_ALLOWED_ACCESS,
5860 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5862 if (!NT_STATUS_IS_OK(result)) {
5866 init_lsa_String(&lsa_acct_name, acct_name);
5868 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
5875 if (!NT_STATUS_IS_OK(result)) {
5876 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5877 acct_name, nt_errstr(result) );
5881 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
5883 MAXIMUM_ALLOWED_ACCESS,
5887 if (!NT_STATUS_IS_OK(result)) {
5888 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5889 acct_name, nt_errstr(result) );
5893 /* append the rid to the domain sid */
5894 sid_copy(&trust_acct_sid, domain_sid);
5895 if (!sid_append_rid(&trust_acct_sid, user_rids.ids[0])) {
5899 /* remove the sid */
5901 result = rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd, mem_ctx,
5904 if (!NT_STATUS_IS_OK(result)) {
5905 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5906 acct_name, nt_errstr(result) );
5912 result = rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
5915 if (!NT_STATUS_IS_OK(result)) {
5916 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5917 acct_name, nt_errstr(result) );
5921 if (!NT_STATUS_IS_OK(result)) {
5922 d_printf("Could not set trust account password: %s\n",
5932 * Delete interdomain trust account for a remote domain.
5934 * @param argc Standard argc.
5935 * @param argv Standard argv without initial components.
5937 * @return Integer status (0 means success).
5940 static int rpc_trustdom_del(struct net_context *c, int argc, const char **argv)
5942 if (argc > 0 && !c->display_usage) {
5943 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5944 rpc_trustdom_del_internals, argc, argv);
5947 "net rpc trustdom del <domain>\n");
5952 static NTSTATUS rpc_trustdom_get_pdc(struct net_context *c,
5953 struct cli_state *cli,
5954 TALLOC_CTX *mem_ctx,
5955 const char *domain_name)
5957 char *dc_name = NULL;
5958 const char *buffer = NULL;
5959 struct rpc_pipe_client *netr;
5962 /* Use NetServerEnum2 */
5964 if (cli_get_pdc_name(cli, domain_name, &dc_name)) {
5966 return NT_STATUS_OK;
5969 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5970 for domain %s\n", domain_name));
5972 /* Try netr_GetDcName */
5974 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
5976 if (!NT_STATUS_IS_OK(status)) {
5980 status = rpccli_netr_GetDcName(netr, mem_ctx,
5987 if (NT_STATUS_IS_OK(status)) {
5991 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5992 for domain %s\n", domain_name));
5998 * Establish trust relationship to a trusting domain.
5999 * Interdomain account must already be created on remote PDC.
6001 * @param c A net_context structure.
6002 * @param argc Standard argc.
6003 * @param argv Standard argv without initial components.
6005 * @return Integer status (0 means success).
6008 static int rpc_trustdom_establish(struct net_context *c, int argc,
6011 struct cli_state *cli = NULL;
6012 struct sockaddr_storage server_ss;
6013 struct rpc_pipe_client *pipe_hnd = NULL;
6014 POLICY_HND connect_hnd;
6015 TALLOC_CTX *mem_ctx;
6017 DOM_SID *domain_sid;
6022 union lsa_PolicyInformation *info = NULL;
6025 * Connect to \\server\ipc$ as 'our domain' account with password
6028 if (argc != 1 || c->display_usage) {
6030 "net rpc trustdom establish <domain_name>\n");
6034 domain_name = smb_xstrdup(argv[0]);
6035 strupper_m(domain_name);
6037 /* account name used at first is our domain's name with '$' */
6038 asprintf(&acct_name, "%s$", lp_workgroup());
6039 strupper_m(acct_name);
6042 * opt_workgroup will be used by connection functions further,
6043 * hence it should be set to remote domain name instead of ours
6045 if (c->opt_workgroup) {
6046 c->opt_workgroup = smb_xstrdup(domain_name);
6049 c->opt_user_name = acct_name;
6051 /* find the domain controller */
6052 if (!net_find_pdc(&server_ss, pdc_name, domain_name)) {
6053 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
6057 /* connect to ipc$ as username/password */
6058 nt_status = connect_to_ipc(c, &cli, &server_ss, pdc_name);
6059 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
6061 /* Is it trusting domain account for sure ? */
6062 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6063 nt_errstr(nt_status)));
6067 /* store who we connected to */
6069 saf_store( domain_name, pdc_name );
6072 * Connect to \\server\ipc$ again (this time anonymously)
6075 nt_status = connect_to_ipc_anonymous(c, &cli, &server_ss,
6078 if (NT_STATUS_IS_ERR(nt_status)) {
6079 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6080 domain_name, nt_errstr(nt_status)));
6084 if (!(mem_ctx = talloc_init("establishing trust relationship to "
6085 "domain %s", domain_name))) {
6086 DEBUG(0, ("talloc_init() failed\n"));
6091 /* Make sure we're talking to a proper server */
6093 nt_status = rpc_trustdom_get_pdc(c, cli, mem_ctx, domain_name);
6094 if (!NT_STATUS_IS_OK(nt_status)) {
6096 talloc_destroy(mem_ctx);
6101 * Call LsaOpenPolicy and LsaQueryInfo
6104 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6106 if (!NT_STATUS_IS_OK(nt_status)) {
6107 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status) ));
6109 talloc_destroy(mem_ctx);
6113 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true, SEC_RIGHTS_QUERY_VALUE,
6115 if (NT_STATUS_IS_ERR(nt_status)) {
6116 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6117 nt_errstr(nt_status)));
6119 talloc_destroy(mem_ctx);
6123 /* Querying info level 5 */
6125 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6127 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6129 if (NT_STATUS_IS_ERR(nt_status)) {
6130 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6131 nt_errstr(nt_status)));
6133 talloc_destroy(mem_ctx);
6137 domain_sid = info->account_domain.sid;
6139 /* There should be actually query info level 3 (following nt serv behaviour),
6140 but I still don't know if it's _really_ necessary */
6143 * Store the password in secrets db
6146 if (!pdb_set_trusteddom_pw(domain_name, c->opt_password, domain_sid)) {
6147 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6149 talloc_destroy(mem_ctx);
6154 * Close the pipes and clean up
6157 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6158 if (NT_STATUS_IS_ERR(nt_status)) {
6159 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6160 nt_errstr(nt_status)));
6162 talloc_destroy(mem_ctx);
6168 talloc_destroy(mem_ctx);
6170 d_printf("Trust to domain %s established\n", domain_name);
6175 * Revoke trust relationship to the remote domain.
6177 * @param c A net_context structure.
6178 * @param argc Standard argc.
6179 * @param argv Standard argv without initial components.
6181 * @return Integer status (0 means success).
6184 static int rpc_trustdom_revoke(struct net_context *c, int argc,
6190 if (argc < 1 || c->display_usage) {
6192 "net rpc trustdom revoke <domain_name>\n"
6193 " Revoke trust relationship\n"
6194 " domain_name\tName of domain to revoke trust\n");
6198 /* generate upper cased domain name */
6199 domain_name = smb_xstrdup(argv[0]);
6200 strupper_m(domain_name);
6202 /* delete password of the trust */
6203 if (!pdb_del_trusteddom_pw(domain_name)) {
6204 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6211 SAFE_FREE(domain_name);
6215 static NTSTATUS rpc_query_domain_sid(struct net_context *c,
6216 const DOM_SID *domain_sid,
6217 const char *domain_name,
6218 struct cli_state *cli,
6219 struct rpc_pipe_client *pipe_hnd,
6220 TALLOC_CTX *mem_ctx,
6225 sid_to_fstring(str_sid, domain_sid);
6226 d_printf("%s\n", str_sid);
6227 return NT_STATUS_OK;
6230 static void print_trusted_domain(DOM_SID *dom_sid, const char *trusted_dom_name)
6232 fstring ascii_sid, padding;
6233 int pad_len, col_len = 20;
6235 /* convert sid into ascii string */
6236 sid_to_fstring(ascii_sid, dom_sid);
6238 /* calculate padding space for d_printf to look nicer */
6239 pad_len = col_len - strlen(trusted_dom_name);
6240 padding[pad_len] = 0;
6241 do padding[--pad_len] = ' '; while (pad_len);
6243 d_printf("%s%s%s\n", trusted_dom_name, padding, ascii_sid);
6246 static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
6247 TALLOC_CTX *mem_ctx,
6250 const char *trusted_dom_name)
6253 union lsa_TrustedDomainInfo *info = NULL;
6254 char *cleartextpwd = NULL;
6255 uint8_t nt_hash[16];
6258 nt_status = rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd, mem_ctx,
6261 LSA_TRUSTED_DOMAIN_INFO_PASSWORD,
6263 if (NT_STATUS_IS_ERR(nt_status)) {
6264 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6265 nt_errstr(nt_status)));
6269 data = data_blob(info->password.password->data,
6270 info->password.password->length);
6272 if (!rpccli_get_pwd_hash(pipe_hnd, nt_hash)) {
6273 DEBUG(0, ("Could not retrieve password hash\n"));
6277 cleartextpwd = decrypt_trustdom_secret(nt_hash, &data);
6279 if (cleartextpwd == NULL) {
6280 DEBUG(0,("retrieved NULL password\n"));
6281 nt_status = NT_STATUS_UNSUCCESSFUL;
6285 if (!pdb_set_trusteddom_pw(trusted_dom_name, cleartextpwd, &dom_sid)) {
6286 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6287 nt_status = NT_STATUS_UNSUCCESSFUL;
6291 #ifdef DEBUG_PASSWORD
6292 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6293 "password: [%s]\n", trusted_dom_name,
6294 sid_string_dbg(&dom_sid), cleartextpwd));
6298 SAFE_FREE(cleartextpwd);
6299 data_blob_free(&data);
6304 static int rpc_trustdom_vampire(struct net_context *c, int argc,
6307 /* common variables */
6308 TALLOC_CTX* mem_ctx;
6309 struct cli_state *cli = NULL;
6310 struct rpc_pipe_client *pipe_hnd = NULL;
6312 const char *domain_name = NULL;
6313 DOM_SID *queried_dom_sid;
6314 POLICY_HND connect_hnd;
6315 union lsa_PolicyInformation *info = NULL;
6317 /* trusted domains listing variables */
6318 unsigned int enum_ctx = 0;
6320 struct lsa_DomainList dom_list;
6323 if (c->display_usage) {
6325 "net rpc trustdom vampire\n"
6326 " Vampire trust relationship from remote server\n");
6331 * Listing trusted domains (stored in secrets.tdb, if local)
6334 mem_ctx = talloc_init("trust relationships vampire");
6337 * set domain and pdc name to local samba server (default)
6338 * or to remote one given in command line
6341 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6342 domain_name = c->opt_workgroup;
6343 c->opt_target_workgroup = c->opt_workgroup;
6345 fstrcpy(pdc_name, global_myname());
6346 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6347 c->opt_target_workgroup = domain_name;
6350 /* open \PIPE\lsarpc and open policy handle */
6351 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6352 if (!NT_STATUS_IS_OK(nt_status)) {
6353 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6354 nt_errstr(nt_status)));
6355 talloc_destroy(mem_ctx);
6359 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6361 if (!NT_STATUS_IS_OK(nt_status)) {
6362 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6363 nt_errstr(nt_status) ));
6365 talloc_destroy(mem_ctx);
6369 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, SEC_RIGHTS_QUERY_VALUE,
6371 if (NT_STATUS_IS_ERR(nt_status)) {
6372 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6373 nt_errstr(nt_status)));
6375 talloc_destroy(mem_ctx);
6379 /* query info level 5 to obtain sid of a domain being queried */
6380 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6382 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6385 if (NT_STATUS_IS_ERR(nt_status)) {
6386 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6387 nt_errstr(nt_status)));
6389 talloc_destroy(mem_ctx);
6393 queried_dom_sid = info->account_domain.sid;
6396 * Keep calling LsaEnumTrustdom over opened pipe until
6397 * the end of enumeration is reached
6400 d_printf("Vampire trusted domains:\n\n");
6403 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6408 if (NT_STATUS_IS_ERR(nt_status)) {
6409 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6410 nt_errstr(nt_status)));
6412 talloc_destroy(mem_ctx);
6416 for (i = 0; i < dom_list.count; i++) {
6418 print_trusted_domain(dom_list.domains[i].sid,
6419 dom_list.domains[i].name.string);
6421 nt_status = vampire_trusted_domain(pipe_hnd, mem_ctx, &connect_hnd,
6422 *dom_list.domains[i].sid,
6423 dom_list.domains[i].name.string);
6424 if (!NT_STATUS_IS_OK(nt_status)) {
6426 talloc_destroy(mem_ctx);
6432 * in case of no trusted domains say something rather
6433 * than just display blank line
6435 if (!dom_list.count) d_printf("none\n");
6437 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6439 /* close this connection before doing next one */
6440 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6441 if (NT_STATUS_IS_ERR(nt_status)) {
6442 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6443 nt_errstr(nt_status)));
6445 talloc_destroy(mem_ctx);
6449 /* close lsarpc pipe and connection to IPC$ */
6452 talloc_destroy(mem_ctx);
6456 static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
6458 /* common variables */
6459 TALLOC_CTX* mem_ctx;
6460 struct cli_state *cli = NULL, *remote_cli = NULL;
6461 struct rpc_pipe_client *pipe_hnd = NULL;
6463 const char *domain_name = NULL;
6464 DOM_SID *queried_dom_sid;
6466 int ascii_dom_name_len;
6467 POLICY_HND connect_hnd;
6468 union lsa_PolicyInformation *info = NULL;
6470 /* trusted domains listing variables */
6471 unsigned int num_domains, enum_ctx = 0;
6472 int i, pad_len, col_len = 20;
6473 struct lsa_DomainList dom_list;
6476 /* trusting domains listing variables */
6477 POLICY_HND domain_hnd;
6478 struct samr_SamArray *trusts = NULL;
6480 if (c->display_usage) {
6482 "net rpc trustdom list\n"
6483 " List trust relationships\n");
6488 * Listing trusted domains (stored in secrets.tdb, if local)
6491 mem_ctx = talloc_init("trust relationships listing");
6494 * set domain and pdc name to local samba server (default)
6495 * or to remote one given in command line
6498 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6499 domain_name = c->opt_workgroup;
6500 c->opt_target_workgroup = c->opt_workgroup;
6502 fstrcpy(pdc_name, global_myname());
6503 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6504 c->opt_target_workgroup = domain_name;
6507 /* open \PIPE\lsarpc and open policy handle */
6508 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6509 if (!NT_STATUS_IS_OK(nt_status)) {
6510 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6511 nt_errstr(nt_status)));
6512 talloc_destroy(mem_ctx);
6516 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6518 if (!NT_STATUS_IS_OK(nt_status)) {
6519 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6520 nt_errstr(nt_status) ));
6522 talloc_destroy(mem_ctx);
6526 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, SEC_RIGHTS_QUERY_VALUE,
6528 if (NT_STATUS_IS_ERR(nt_status)) {
6529 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6530 nt_errstr(nt_status)));
6532 talloc_destroy(mem_ctx);
6536 /* query info level 5 to obtain sid of a domain being queried */
6537 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6539 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6542 if (NT_STATUS_IS_ERR(nt_status)) {
6543 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6544 nt_errstr(nt_status)));
6546 talloc_destroy(mem_ctx);
6550 queried_dom_sid = info->account_domain.sid;
6553 * Keep calling LsaEnumTrustdom over opened pipe until
6554 * the end of enumeration is reached
6557 d_printf("Trusted domains list:\n\n");
6560 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6565 if (NT_STATUS_IS_ERR(nt_status)) {
6566 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6567 nt_errstr(nt_status)));
6569 talloc_destroy(mem_ctx);
6573 for (i = 0; i < dom_list.count; i++) {
6574 print_trusted_domain(dom_list.domains[i].sid,
6575 dom_list.domains[i].name.string);
6579 * in case of no trusted domains say something rather
6580 * than just display blank line
6582 if (!dom_list.count) d_printf("none\n");
6584 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6586 /* close this connection before doing next one */
6587 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6588 if (NT_STATUS_IS_ERR(nt_status)) {
6589 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6590 nt_errstr(nt_status)));
6592 talloc_destroy(mem_ctx);
6596 TALLOC_FREE(pipe_hnd);
6599 * Listing trusting domains (stored in passdb backend, if local)
6602 d_printf("\nTrusting domains list:\n\n");
6605 * Open \PIPE\samr and get needed policy handles
6607 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_samr.syntax_id,
6609 if (!NT_STATUS_IS_OK(nt_status)) {
6610 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status)));
6612 talloc_destroy(mem_ctx);
6617 nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
6619 SA_RIGHT_SAM_OPEN_DOMAIN,
6621 if (!NT_STATUS_IS_OK(nt_status)) {
6622 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6623 nt_errstr(nt_status)));
6625 talloc_destroy(mem_ctx);
6629 /* SamrOpenDomain - we have to open domain policy handle in order to be
6630 able to enumerate accounts*/
6631 nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
6633 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
6636 if (!NT_STATUS_IS_OK(nt_status)) {
6637 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6638 nt_errstr(nt_status)));
6640 talloc_destroy(mem_ctx);
6645 * perform actual enumeration
6648 enum_ctx = 0; /* reset enumeration context from last enumeration */
6651 nt_status = rpccli_samr_EnumDomainUsers(pipe_hnd, mem_ctx,
6658 if (NT_STATUS_IS_ERR(nt_status)) {
6659 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6660 nt_errstr(nt_status)));
6662 talloc_destroy(mem_ctx);
6666 for (i = 0; i < num_domains; i++) {
6668 char *str = CONST_DISCARD(char *, trusts->entries[i].name.string);
6671 * get each single domain's sid (do we _really_ need this ?):
6672 * 1) connect to domain's pdc
6673 * 2) query the pdc for domain's sid
6676 /* get rid of '$' tail */
6677 ascii_dom_name_len = strlen(str);
6678 if (ascii_dom_name_len && ascii_dom_name_len < FSTRING_LEN)
6679 str[ascii_dom_name_len - 1] = '\0';
6681 /* calculate padding space for d_printf to look nicer */
6682 pad_len = col_len - strlen(str);
6683 padding[pad_len] = 0;
6684 do padding[--pad_len] = ' '; while (pad_len);
6686 /* set opt_* variables to remote domain */
6688 c->opt_workgroup = talloc_strdup(mem_ctx, str);
6689 c->opt_target_workgroup = c->opt_workgroup;
6691 d_printf("%s%s", str, padding);
6693 /* connect to remote domain controller */
6694 nt_status = net_make_ipc_connection(c,
6695 NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS,
6697 if (NT_STATUS_IS_OK(nt_status)) {
6698 /* query for domain's sid */
6699 if (run_rpc_command(
6701 &ndr_table_lsarpc.syntax_id, 0,
6702 rpc_query_domain_sid, argc,
6704 d_fprintf(stderr, "couldn't get domain's sid\n");
6706 cli_shutdown(remote_cli);
6709 d_fprintf(stderr, "domain controller is not "
6711 nt_errstr(nt_status));
6715 if (!num_domains) d_printf("none\n");
6717 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6719 /* close opened samr and domain policy handles */
6720 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_hnd);
6721 if (!NT_STATUS_IS_OK(nt_status)) {
6722 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
6725 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_hnd);
6726 if (!NT_STATUS_IS_OK(nt_status)) {
6727 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
6730 /* close samr pipe and connection to IPC$ */
6733 talloc_destroy(mem_ctx);
6738 * Entrypoint for 'net rpc trustdom' code.
6740 * @param argc Standard argc.
6741 * @param argv Standard argv without initial components.
6743 * @return Integer status (0 means success).
6746 static int rpc_trustdom(struct net_context *c, int argc, const char **argv)
6748 struct functable func[] = {
6753 "Add trusted domain's account",
6754 "net rpc trustdom add\n"
6755 " Add trusted domain's account"
6761 "Remove trusted domain's account",
6762 "net rpc trustdom del\n"
6763 " Remove trusted domain's account"
6767 rpc_trustdom_establish,
6769 "Establish trust relationship",
6770 "net rpc trustdom establish\n"
6771 " Establish trust relationship"
6775 rpc_trustdom_revoke,
6777 "Revoke trust relationship",
6778 "net rpc trustdom revoke\n"
6779 " Revoke trust relationship"
6785 "List domain trusts",
6786 "net rpc trustdom list\n"
6787 " List domain trusts"
6791 rpc_trustdom_vampire,
6793 "Vampire trusts from remote server",
6794 "net rpc trustdom vampire\n"
6795 " Vampire trusts from remote server"
6797 {NULL, NULL, 0, NULL, NULL}
6800 return net_run_function(c, argc, argv, "net rpc trustdom", func);
6804 * Check if a server will take rpc commands
6805 * @param flags Type of server to connect to (PDC, DMB, localhost)
6806 * if the host is not explicitly specified
6807 * @return bool (true means rpc supported)
6809 bool net_rpc_check(struct net_context *c, unsigned flags)
6811 struct cli_state *cli;
6813 struct sockaddr_storage server_ss;
6814 char *server_name = NULL;
6817 /* flags (i.e. server type) may depend on command */
6818 if (!net_find_server(c, NULL, flags, &server_ss, &server_name))
6821 if ((cli = cli_initialise()) == NULL) {
6825 status = cli_connect(cli, server_name, &server_ss);
6826 if (!NT_STATUS_IS_OK(status))
6828 if (!attempt_netbios_session_request(&cli, global_myname(),
6829 server_name, &server_ss))
6831 if (!cli_negprot(cli))
6833 if (cli->protocol < PROTOCOL_NT1)
6842 /* dump sam database via samsync rpc calls */
6843 static int rpc_samdump(struct net_context *c, int argc, const char **argv) {
6844 if (c->display_usage) {
6847 " Dump remote SAM database\n");
6851 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6852 NET_FLAGS_ANONYMOUS,
6853 rpc_samdump_internals, argc, argv);
6856 /* syncronise sam database via samsync rpc calls */
6857 static int rpc_vampire(struct net_context *c, int argc, const char **argv)
6859 struct functable func[] = {
6864 "Dump remote SAM database to ldif",
6865 "net rpc vampire ldif\n"
6866 " Dump remote SAM database to LDIF file or stdout"
6872 "Dump remote SAM database to Kerberos Keytab",
6873 "net rpc vampire keytab\n"
6874 " Dump remote SAM database to Kerberos keytab file"
6877 {NULL, NULL, 0, NULL, NULL}
6881 if (c->display_usage) {
6884 " Vampire remote SAM database\n");
6888 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6889 NET_FLAGS_ANONYMOUS,
6890 rpc_vampire_internals,
6894 return net_run_function(c, argc, argv, "net rpc vampire", func);
6898 * Migrate everything from a print server.
6900 * @param c A net_context structure.
6901 * @param argc Standard main() style argc.
6902 * @param argv Standard main() style argv. Initial components are already
6905 * @return A shell status integer (0 for success).
6907 * The order is important !
6908 * To successfully add drivers the print queues have to exist !
6909 * Applying ACLs should be the last step, because you're easily locked out.
6912 static int rpc_printer_migrate_all(struct net_context *c, int argc,
6917 if (c->display_usage) {
6919 "net rpc printer migrate all\n"
6920 " Migrate everything from a print server\n");
6925 d_printf("no server to migrate\n");
6929 ret = run_rpc_command(c, NULL, &syntax_spoolss, 0,
6930 rpc_printer_migrate_printers_internals, argc,
6935 ret = run_rpc_command(c, NULL, &syntax_spoolss, 0,
6936 rpc_printer_migrate_drivers_internals, argc,
6941 ret = run_rpc_command(c, NULL, &syntax_spoolss, 0,
6942 rpc_printer_migrate_forms_internals, argc, argv);
6946 ret = run_rpc_command(c, NULL, &syntax_spoolss, 0,
6947 rpc_printer_migrate_settings_internals, argc,
6952 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
6953 rpc_printer_migrate_security_internals, argc,
6959 * Migrate print drivers from a print server.
6961 * @param c A net_context structure.
6962 * @param argc Standard main() style argc.
6963 * @param argv Standard main() style argv. Initial components are already
6966 * @return A shell status integer (0 for success).
6968 static int rpc_printer_migrate_drivers(struct net_context *c, int argc,
6971 if (c->display_usage) {
6973 "net rpc printer migrate drivers\n"
6974 " Migrate print-drivers from a print-server\n");
6979 d_printf("no server to migrate\n");
6983 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
6984 rpc_printer_migrate_drivers_internals,
6989 * Migrate print-forms from a print-server.
6991 * @param c A net_context structure.
6992 * @param argc Standard main() style argc.
6993 * @param argv Standard main() style argv. Initial components are already
6996 * @return A shell status integer (0 for success).
6998 static int rpc_printer_migrate_forms(struct net_context *c, int argc,
7001 if (c->display_usage) {
7003 "net rpc printer migrate forms\n"
7004 " Migrate print-forms from a print-server\n");
7009 d_printf("no server to migrate\n");
7013 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7014 rpc_printer_migrate_forms_internals,
7019 * Migrate printers from a print-server.
7021 * @param c A net_context structure.
7022 * @param argc Standard main() style argc.
7023 * @param argv Standard main() style argv. Initial components are already
7026 * @return A shell status integer (0 for success).
7028 static int rpc_printer_migrate_printers(struct net_context *c, int argc,
7031 if (c->display_usage) {
7033 "net rpc printer migrate printers\n"
7034 " Migrate printers from a print-server\n");
7039 d_printf("no server to migrate\n");
7043 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7044 rpc_printer_migrate_printers_internals,
7049 * Migrate printer-ACLs from a print-server
7051 * @param c A net_context structure.
7052 * @param argc Standard main() style argc.
7053 * @param argv Standard main() style argv. Initial components are already
7056 * @return A shell status integer (0 for success).
7058 static int rpc_printer_migrate_security(struct net_context *c, int argc,
7061 if (c->display_usage) {
7063 "net rpc printer migrate security\n"
7064 " Migrate printer-ACLs from a print-server\n");
7069 d_printf("no server to migrate\n");
7073 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7074 rpc_printer_migrate_security_internals,
7079 * Migrate printer-settings from a print-server.
7081 * @param c A net_context structure.
7082 * @param argc Standard main() style argc.
7083 * @param argv Standard main() style argv. Initial components are already
7086 * @return A shell status integer (0 for success).
7088 static int rpc_printer_migrate_settings(struct net_context *c, int argc,
7091 if (c->display_usage) {
7093 "net rpc printer migrate settings\n"
7094 " Migrate printer-settings from a print-server\n");
7099 d_printf("no server to migrate\n");
7103 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7104 rpc_printer_migrate_settings_internals,
7109 * 'net rpc printer' entrypoint.
7111 * @param c A net_context structure.
7112 * @param argc Standard main() style argc.
7113 * @param argv Standard main() style argv. Initial components are already
7117 int rpc_printer_migrate(struct net_context *c, int argc, const char **argv)
7120 /* ouch: when addriver and setdriver are called from within
7121 rpc_printer_migrate_drivers_internals, the printer-queue already
7124 struct functable func[] = {
7127 rpc_printer_migrate_all,
7129 "Migrate all from remote to local print server",
7130 "net rpc printer migrate all\n"
7131 " Migrate all from remote to local print server"
7135 rpc_printer_migrate_drivers,
7137 "Migrate drivers to local server",
7138 "net rpc printer migrate drivers\n"
7139 " Migrate drivers to local server"
7143 rpc_printer_migrate_forms,
7145 "Migrate froms to local server",
7146 "net rpc printer migrate forms\n"
7147 " Migrate froms to local server"
7151 rpc_printer_migrate_printers,
7153 "Migrate printers to local server",
7154 "net rpc printer migrate printers\n"
7155 " Migrate printers to local server"
7159 rpc_printer_migrate_security,
7161 "Mirgate printer ACLs to local server",
7162 "net rpc printer migrate security\n"
7163 " Mirgate printer ACLs to local server"
7167 rpc_printer_migrate_settings,
7169 "Migrate printer settings to local server",
7170 "net rpc printer migrate settings\n"
7171 " Migrate printer settings to local server"
7173 {NULL, NULL, 0, NULL, NULL}
7176 return net_run_function(c, argc, argv, "net rpc printer migrate",func);
7181 * List printers on a remote RPC server.
7183 * @param c A net_context structure.
7184 * @param argc Standard main() style argc.
7185 * @param argv Standard main() style argv. Initial components are already
7188 * @return A shell status integer (0 for success).
7190 static int rpc_printer_list(struct net_context *c, int argc, const char **argv)
7192 if (c->display_usage) {
7194 "net rpc printer list\n"
7195 " List printers on a remote RPC server\n");
7199 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7200 rpc_printer_list_internals,
7205 * List printer-drivers on a remote RPC server.
7207 * @param c A net_context structure.
7208 * @param argc Standard main() style argc.
7209 * @param argv Standard main() style argv. Initial components are already
7212 * @return A shell status integer (0 for success).
7214 static int rpc_printer_driver_list(struct net_context *c, int argc,
7217 if (c->display_usage) {
7219 "net rpc printer driver\n"
7220 " List printer-drivers on a remote RPC server\n");
7224 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7225 rpc_printer_driver_list_internals,
7230 * Publish printer in ADS via MSRPC.
7232 * @param c A net_context structure.
7233 * @param argc Standard main() style argc.
7234 * @param argv Standard main() style argv. Initial components are already
7237 * @return A shell status integer (0 for success).
7239 static int rpc_printer_publish_publish(struct net_context *c, int argc,
7242 if (c->display_usage) {
7244 "net rpc printer publish publish\n"
7245 " Publish printer in ADS via MSRPC\n");
7249 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7250 rpc_printer_publish_publish_internals,
7255 * Update printer in ADS via MSRPC.
7257 * @param c A net_context structure.
7258 * @param argc Standard main() style argc.
7259 * @param argv Standard main() style argv. Initial components are already
7262 * @return A shell status integer (0 for success).
7264 static int rpc_printer_publish_update(struct net_context *c, int argc, const char **argv)
7266 if (c->display_usage) {
7268 "net rpc printer publish update\n"
7269 " Update printer in ADS via MSRPC\n");
7273 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7274 rpc_printer_publish_update_internals,
7279 * UnPublish printer in ADS via MSRPC.
7281 * @param c A net_context structure.
7282 * @param argc Standard main() style argc.
7283 * @param argv Standard main() style argv. Initial components are already
7286 * @return A shell status integer (0 for success).
7288 static int rpc_printer_publish_unpublish(struct net_context *c, int argc,
7291 if (c->display_usage) {
7293 "net rpc printer publish unpublish\n"
7294 " UnPublish printer in ADS via MSRPC\n");
7298 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7299 rpc_printer_publish_unpublish_internals,
7304 * List published printers via MSRPC.
7306 * @param c A net_context structure.
7307 * @param argc Standard main() style argc.
7308 * @param argv Standard main() style argv. Initial components are already
7311 * @return A shell status integer (0 for success).
7313 static int rpc_printer_publish_list(struct net_context *c, int argc,
7316 if (c->display_usage) {
7318 "net rpc printer publish list\n"
7319 " List published printers via MSRPC\n");
7323 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7324 rpc_printer_publish_list_internals,
7330 * Publish printer in ADS.
7332 * @param c A net_context structure.
7333 * @param argc Standard main() style argc.
7334 * @param argv Standard main() style argv. Initial components are already
7337 * @return A shell status integer (0 for success).
7339 static int rpc_printer_publish(struct net_context *c, int argc,
7343 struct functable func[] = {
7346 rpc_printer_publish_publish,
7348 "Publish printer in AD",
7349 "net rpc printer publish publish\n"
7350 " Publish printer in AD"
7354 rpc_printer_publish_update,
7356 "Update printer in AD",
7357 "net rpc printer publish update\n"
7358 " Update printer in AD"
7362 rpc_printer_publish_unpublish,
7364 "Unpublish printer",
7365 "net rpc printer publish unpublish\n"
7366 " Unpublish printer"
7370 rpc_printer_publish_list,
7372 "List published printers",
7373 "net rpc printer publish list\n"
7374 " List published printers"
7376 {NULL, NULL, 0, NULL, NULL}
7380 if (c->display_usage) {
7381 d_printf("Usage:\n");
7382 d_printf("net rpc printer publish\n"
7383 " List published printers\n"
7384 " Alias of net rpc printer publish list\n");
7385 net_display_usage_from_functable(func);
7388 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7389 rpc_printer_publish_list_internals,
7393 return net_run_function(c, argc, argv, "net rpc printer publish",func);
7399 * Display rpc printer help page.
7401 * @param c A net_context structure.
7402 * @param argc Standard main() style argc.
7403 * @param argv Standard main() style argv. Initial components are already
7406 int rpc_printer_usage(struct net_context *c, int argc, const char **argv)
7408 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
7409 "\tlists all printers on print-server\n\n");
7410 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7411 "\tlists all printer-drivers on print-server\n\n");
7412 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7413 "\tpublishes printer settings in Active Directory\n"
7414 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
7415 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7416 "\n\tmigrates printers from remote to local server\n\n");
7417 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7418 "\n\tmigrates printer-settings from remote to local server\n\n");
7419 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7420 "\n\tmigrates printer-drivers from remote to local server\n\n");
7421 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7422 "\n\tmigrates printer-forms from remote to local server\n\n");
7423 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7424 "\n\tmigrates printer-ACLs from remote to local server\n\n");
7425 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7426 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7427 "\tremote to local print-server\n\n");
7428 net_common_methods_usage(c, argc, argv);
7429 net_common_flags_usage(c, argc, argv);
7431 "\t-v or --verbose\t\t\tgive verbose output\n"
7432 "\t --destination\t\tmigration target server (default: localhost)\n");
7438 * 'net rpc printer' entrypoint.
7440 * @param c A net_context structure.
7441 * @param argc Standard main() style argc.
7442 * @param argv Standard main() style argv. Initial components are already
7445 int net_rpc_printer(struct net_context *c, int argc, const char **argv)
7447 struct functable func[] = {
7452 "List all printers on print server",
7453 "net rpc printer list\n"
7454 " List all printers on print server"
7458 rpc_printer_migrate,
7460 "Migrate printer to local server",
7461 "net rpc printer migrate\n"
7462 " Migrate printer to local server"
7466 rpc_printer_driver_list,
7468 "List printer drivers",
7469 "net rpc printer driver\n"
7470 " List printer drivers"
7474 rpc_printer_publish,
7476 "Publish printer in AD",
7477 "net rpc printer publish\n"
7478 " Publish printer in AD"
7480 {NULL, NULL, 0, NULL, NULL}
7484 if (c->display_usage) {
7485 d_printf("Usage:\n");
7486 d_printf("net rpc printer\n"
7487 " List printers\n");
7488 net_display_usage_from_functable(func);
7491 return run_rpc_command(c, NULL, &syntax_spoolss, 0,
7492 rpc_printer_list_internals,
7496 return net_run_function(c, argc, argv, "net rpc printer", func);
7500 * 'net rpc' entrypoint.
7502 * @param c A net_context structure.
7503 * @param argc Standard main() style argc.
7504 * @param argv Standard main() style argv. Initial components are already
7508 int net_rpc(struct net_context *c, int argc, const char **argv)
7510 struct functable func[] = {
7515 "Modify global audit settings",
7517 " Modify global audit settings"
7523 "Show basic info about a domain",
7525 " Show basic info about a domain"
7539 "Join a domain created in server manager",
7541 " Join a domain created in server manager"
7547 "Test that a join is valid",
7548 "net rpc testjoin\n"
7549 " Test that a join is valid"
7555 "List/modify users",
7557 " List/modify users"
7563 "Change a user password",
7564 "net rpc password\n"
7565 " Change a user password\n"
7566 " Alias for net rpc user password"
7572 "List/modify groups",
7574 " List/modify groups"
7580 "List/modify shares",
7582 " List/modify shares"
7596 "List/modify printers",
7598 " List/modify printers"
7602 net_rpc_changetrustpw,
7604 "Change trust account password",
7605 "net rpc changetrustpw\n"
7606 " Change trust account password"
7612 "Modify domain trusts",
7613 "net rpc trustdom\n"
7614 " Modify domain trusts"
7620 "Abort a remote shutdown",
7621 "net rpc abortshutdown\n"
7622 " Abort a remote shutdown"
7628 "Shutdown a remote server",
7629 "net rpc shutdown\n"
7630 " Shutdown a remote server"
7636 "Dump SAM data of remote NT PDC",
7638 " Dump SAM data of remote NT PDC"
7644 "Sync a remote NT PDC's data into local passdb",
7646 " Sync a remote NT PDC's data into local passdb"
7652 "Fetch the domain sid into local secrets.tdb",
7654 " Fetch the domain sid into local secrets.tdb"
7660 "Manage privileges assigned to SID",
7662 " Manage privileges assigned to SID"
7668 "Start/stop/query remote services",
7670 " Start/stop/query remote services"
7676 "Manage registry hives",
7677 "net rpc registry\n"
7678 " Manage registry hives"
7684 "Open interactive shell on remote server",
7686 " Open interactive shell on remote server"
7688 {NULL, NULL, 0, NULL, NULL}
7690 return net_run_function(c, argc, argv, "net rpc", func);