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"
25 #include "../libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_samr_c.h"
27 #include "rpc_client/cli_samr.h"
28 #include "rpc_client/init_samr.h"
29 #include "../librpc/gen_ndr/cli_lsa.h"
30 #include "rpc_client/cli_lsarpc.h"
31 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
32 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
33 #include "../librpc/gen_ndr/ndr_spoolss.h"
34 #include "../librpc/gen_ndr/ndr_initshutdown_c.h"
35 #include "../librpc/gen_ndr/ndr_winreg_c.h"
37 #include "lib/netapi/netapi.h"
38 #include "lib/netapi/netapi_net.h"
39 #include "rpc_client/init_lsa.h"
40 #include "../libcli/security/security.h"
42 static int net_mode_share;
43 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask);
48 * @brief RPC based subcommands for the 'net' utility.
50 * This file should contain much of the functionality that used to
51 * be found in rpcclient, execpt that the commands should change
52 * less often, and the fucntionality should be sane (the user is not
53 * expected to know a rid/sid before they conduct an operation etc.)
55 * @todo Perhaps eventually these should be split out into a number
56 * of files, as this could get quite big.
61 * Many of the RPC functions need the domain sid. This function gets
62 * it at the start of every run
64 * @param cli A cli_state already connected to the remote machine
66 * @return The Domain SID of the remote machine.
69 NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
70 struct dom_sid **domain_sid,
71 const char **domain_name)
73 struct rpc_pipe_client *lsa_pipe = NULL;
74 struct policy_handle pol;
75 NTSTATUS result = NT_STATUS_OK;
76 union lsa_PolicyInformation *info = NULL;
78 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
80 if (!NT_STATUS_IS_OK(result)) {
81 d_fprintf(stderr, _("Could not initialise lsa pipe\n"));
85 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, false,
86 SEC_FLAG_MAXIMUM_ALLOWED,
88 if (!NT_STATUS_IS_OK(result)) {
89 d_fprintf(stderr, "open_policy %s: %s\n",
95 result = rpccli_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx,
97 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
99 if (!NT_STATUS_IS_OK(result)) {
100 d_fprintf(stderr, "lsaquery %s: %s\n",
106 *domain_name = info->account_domain.name.string;
107 *domain_sid = info->account_domain.sid;
109 rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
110 TALLOC_FREE(lsa_pipe);
116 * Run a single RPC command, from start to finish.
118 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
119 * @param conn_flag a NET_FLAG_ combination. Passed to
120 * net_make_ipc_connection.
121 * @param argc Standard main() style argc.
122 * @param argv Standard main() style argv. Initial components are already
124 * @return A shell status integer (0 for success).
127 int run_rpc_command(struct net_context *c,
128 struct cli_state *cli_arg,
129 const struct ndr_syntax_id *interface,
135 struct cli_state *cli = NULL;
136 struct rpc_pipe_client *pipe_hnd = NULL;
139 struct dom_sid *domain_sid;
140 const char *domain_name;
143 /* make use of cli_state handed over as an argument, if possible */
145 nt_status = net_make_ipc_connection(c, conn_flags, &cli);
146 if (!NT_STATUS_IS_OK(nt_status)) {
147 DEBUG(1, ("failed to make ipc connection: %s\n",
148 nt_errstr(nt_status)));
161 if (!(mem_ctx = talloc_init("run_rpc_command"))) {
162 DEBUG(0, ("talloc_init() failed\n"));
166 nt_status = net_get_remote_domain_sid(cli, mem_ctx, &domain_sid,
168 if (!NT_STATUS_IS_OK(nt_status)) {
172 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
173 if (lp_client_schannel()
174 && (ndr_syntax_id_equal(interface,
175 &ndr_table_netlogon.syntax_id))) {
176 /* Always try and create an schannel netlogon pipe. */
177 nt_status = cli_rpc_pipe_open_schannel(
178 cli, interface, NCACN_NP,
179 DCERPC_AUTH_LEVEL_PRIVACY, domain_name,
181 if (!NT_STATUS_IS_OK(nt_status)) {
182 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
183 nt_errstr(nt_status) ));
187 if (conn_flags & NET_FLAGS_SEAL) {
188 nt_status = cli_rpc_pipe_open_ntlmssp(
190 (conn_flags & NET_FLAGS_TCP) ?
191 NCACN_IP_TCP : NCACN_NP,
192 DCERPC_AUTH_LEVEL_PRIVACY,
193 lp_workgroup(), c->opt_user_name,
194 c->opt_password, &pipe_hnd);
196 nt_status = cli_rpc_pipe_open_noauth(
200 if (!NT_STATUS_IS_OK(nt_status)) {
201 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
202 get_pipe_name_from_syntax(
203 talloc_tos(), interface),
204 nt_errstr(nt_status) ));
210 nt_status = fn(c, domain_sid, domain_name, cli, pipe_hnd, mem_ctx, argc, argv);
212 if (!NT_STATUS_IS_OK(nt_status)) {
213 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status)));
216 DEBUG(5, ("rpc command function succedded\n"));
219 if (!(conn_flags & NET_FLAGS_NO_PIPE)) {
221 TALLOC_FREE(pipe_hnd);
226 /* close the connection only if it was opened here */
231 talloc_destroy(mem_ctx);
236 * Force a change of the trust acccount password.
238 * All parameters are provided by the run_rpc_command function, except for
239 * argc, argv which are passed through.
241 * @param domain_sid The domain sid acquired from the remote server.
242 * @param cli A cli_state connected to the server.
243 * @param mem_ctx Talloc context, destroyed on completion of the function.
244 * @param argc Standard main() style argc.
245 * @param argv Standard main() style argv. Initial components are already
248 * @return Normal NTSTATUS return.
251 static NTSTATUS rpc_changetrustpw_internals(struct net_context *c,
252 const struct dom_sid *domain_sid,
253 const char *domain_name,
254 struct cli_state *cli,
255 struct rpc_pipe_client *pipe_hnd,
262 status = trust_pw_find_change_and_store_it(pipe_hnd, mem_ctx, c->opt_target_workgroup);
263 if (!NT_STATUS_IS_OK(status)) {
264 d_fprintf(stderr, _("Failed to change machine account password: %s\n"),
273 * Force a change of the trust acccount password.
275 * @param argc Standard main() style argc.
276 * @param argv Standard main() style argv. Initial components are already
279 * @return A shell status integer (0 for success).
282 int net_rpc_changetrustpw(struct net_context *c, int argc, const char **argv)
284 if (c->display_usage) {
286 "net rpc changetrustpw\n"
289 _("Change the machine trust password"));
293 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
294 NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
295 rpc_changetrustpw_internals,
300 * Join a domain, the old way.
302 * This uses 'machinename' as the inital password, and changes it.
304 * The password should be created with 'server manager' or equiv first.
306 * All parameters are provided by the run_rpc_command function, except for
307 * argc, argv which are passed through.
309 * @param domain_sid The domain sid acquired from the remote server.
310 * @param cli A cli_state connected to the server.
311 * @param mem_ctx Talloc context, destroyed on completion of the function.
312 * @param argc Standard main() style argc.
313 * @param argv Standard main() style argv. Initial components are already
316 * @return Normal NTSTATUS return.
319 static NTSTATUS rpc_oldjoin_internals(struct net_context *c,
320 const struct dom_sid *domain_sid,
321 const char *domain_name,
322 struct cli_state *cli,
323 struct rpc_pipe_client *pipe_hnd,
329 fstring trust_passwd;
330 unsigned char orig_trust_passwd_hash[16];
332 enum netr_SchannelType sec_channel_type;
334 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
336 if (!NT_STATUS_IS_OK(result)) {
337 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
340 nt_errstr(result) ));
345 check what type of join - if the user want's to join as
346 a BDC, the server must agree that we are a BDC.
349 sec_channel_type = get_sec_channel_type(argv[0]);
351 sec_channel_type = get_sec_channel_type(NULL);
354 fstrcpy(trust_passwd, global_myname());
355 strlower_m(trust_passwd);
358 * Machine names can be 15 characters, but the max length on
359 * a password is 14. --jerry
362 trust_passwd[14] = '\0';
364 E_md4hash(trust_passwd, orig_trust_passwd_hash);
366 result = trust_pw_change_and_store_it(pipe_hnd, mem_ctx, c->opt_target_workgroup,
368 orig_trust_passwd_hash,
371 if (NT_STATUS_IS_OK(result))
372 printf(_("Joined domain %s.\n"), c->opt_target_workgroup);
375 if (!secrets_store_domain_sid(c->opt_target_workgroup, domain_sid)) {
376 DEBUG(0, ("error storing domain sid for %s\n", c->opt_target_workgroup));
377 result = NT_STATUS_UNSUCCESSFUL;
384 * Join a domain, the old way.
386 * @param argc Standard main() style argc.
387 * @param argv Standard main() style argv. Initial components are already
390 * @return A shell status integer (0 for success).
393 static int net_rpc_perform_oldjoin(struct net_context *c, int argc, const char **argv)
395 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
396 NET_FLAGS_NO_PIPE | NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC,
397 rpc_oldjoin_internals,
402 * Join a domain, the old way. This function exists to allow
403 * the message to be displayed when oldjoin was explicitly
404 * requested, but not when it was implied by "net rpc join".
406 * @param argc Standard main() style argc.
407 * @param argv Standard main() style argv. Initial components are already
410 * @return A shell status integer (0 for success).
413 static int net_rpc_oldjoin(struct net_context *c, int argc, const char **argv)
417 if (c->display_usage) {
422 _("Join a domain the old way"));
426 rc = net_rpc_perform_oldjoin(c, argc, argv);
429 d_fprintf(stderr, _("Failed to join domain\n"));
436 * 'net rpc join' entrypoint.
437 * @param argc Standard main() style argc.
438 * @param argv Standard main() style argv. Initial components are already
441 * Main 'net_rpc_join()' (where the admin username/password is used) is
443 * Try to just change the password, but if that doesn't work, use/prompt
444 * for a username/password.
447 int net_rpc_join(struct net_context *c, int argc, const char **argv)
449 if (c->display_usage) {
452 _("net rpc join -U <username>[%%password] <type>\n"
454 " username\tName of the admin user"
455 " password\tPassword of the admin user, will "
456 "prompt if not specified\n"
457 " type\tCan be one of the following:\n"
458 "\t\tMEMBER\tJoin as member server (default)\n"
459 "\t\tBDC\tJoin as BDC\n"
460 "\t\tPDC\tJoin as PDC\n"));
464 if (lp_server_role() == ROLE_STANDALONE) {
465 d_printf(_("cannot join as standalone machine\n"));
469 if (strlen(global_myname()) > 15) {
470 d_printf(_("Our netbios name can be at most 15 chars long, "
471 "\"%s\" is %u chars long\n"),
472 global_myname(), (unsigned int)strlen(global_myname()));
476 if ((net_rpc_perform_oldjoin(c, argc, argv) == 0))
479 return net_rpc_join_newstyle(c, argc, argv);
483 * display info about a rpc domain
485 * All parameters are provided by the run_rpc_command function, except for
486 * argc, argv which are passed through.
488 * @param domain_sid The domain sid acquired from the remote server
489 * @param cli A cli_state connected to the server.
490 * @param mem_ctx Talloc context, destroyed on completion of the function.
491 * @param argc Standard main() style argc.
492 * @param argv Standard main() style argv. Initial components are already
495 * @return Normal NTSTATUS return.
498 NTSTATUS rpc_info_internals(struct net_context *c,
499 const struct dom_sid *domain_sid,
500 const char *domain_name,
501 struct cli_state *cli,
502 struct rpc_pipe_client *pipe_hnd,
507 struct policy_handle connect_pol, domain_pol;
508 NTSTATUS status, result;
509 union samr_DomainInfo *info = NULL;
511 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
513 sid_to_fstring(sid_str, domain_sid);
515 /* Get sam policy handle */
516 status = dcerpc_samr_Connect2(b, mem_ctx,
518 MAXIMUM_ALLOWED_ACCESS,
521 if (!NT_STATUS_IS_OK(status)) {
522 d_fprintf(stderr, _("Could not connect to SAM: %s\n"),
527 if (!NT_STATUS_IS_OK(result)) {
529 d_fprintf(stderr, _("Could not connect to SAM: %s\n"),
534 /* Get domain policy handle */
535 status = dcerpc_samr_OpenDomain(b, mem_ctx,
537 MAXIMUM_ALLOWED_ACCESS,
538 CONST_DISCARD(struct dom_sid2 *, domain_sid),
541 if (!NT_STATUS_IS_OK(status)) {
542 d_fprintf(stderr, _("Could not open domain: %s\n"),
546 if (!NT_STATUS_IS_OK(result)) {
548 d_fprintf(stderr, _("Could not open domain: %s\n"),
553 status = dcerpc_samr_QueryDomainInfo(b, mem_ctx,
558 if (!NT_STATUS_IS_OK(status)) {
562 if (NT_STATUS_IS_OK(result)) {
563 d_printf(_("Domain Name: %s\n"),
564 info->general.domain_name.string);
565 d_printf(_("Domain SID: %s\n"), sid_str);
566 d_printf(_("Sequence number: %llu\n"),
567 (unsigned long long)info->general.sequence_num);
568 d_printf(_("Num users: %u\n"), info->general.num_users);
569 d_printf(_("Num domain groups: %u\n"),info->general.num_groups);
570 d_printf(_("Num local groups: %u\n"),info->general.num_aliases);
578 * 'net rpc info' entrypoint.
579 * @param argc Standard main() style argc.
580 * @param argv Standard main() style argv. Initial components are already
584 int net_rpc_info(struct net_context *c, int argc, const char **argv)
586 if (c->display_usage) {
591 _("Display information about the domain"));
595 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id,
596 NET_FLAGS_PDC, rpc_info_internals,
601 * Fetch domain SID into the local secrets.tdb.
603 * All parameters are provided by the run_rpc_command function, except for
604 * argc, argv which are passed through.
606 * @param domain_sid The domain sid acquired from the remote server.
607 * @param cli A cli_state connected to the server.
608 * @param mem_ctx Talloc context, destroyed on completion of the function.
609 * @param argc Standard main() style argc.
610 * @param argv Standard main() style argv. Initial components are already
613 * @return Normal NTSTATUS return.
616 static NTSTATUS rpc_getsid_internals(struct net_context *c,
617 const struct dom_sid *domain_sid,
618 const char *domain_name,
619 struct cli_state *cli,
620 struct rpc_pipe_client *pipe_hnd,
627 sid_to_fstring(sid_str, domain_sid);
628 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
629 sid_str, domain_name);
631 if (!secrets_store_domain_sid(domain_name, domain_sid)) {
632 DEBUG(0,("Can't store domain SID\n"));
633 return NT_STATUS_UNSUCCESSFUL;
640 * 'net rpc getsid' entrypoint.
641 * @param argc Standard main() style argc.
642 * @param argv Standard main() style argv. Initial components are already
646 int net_rpc_getsid(struct net_context *c, int argc, const char **argv)
648 int conn_flags = NET_FLAGS_PDC;
650 if (!c->opt_user_specified) {
651 conn_flags |= NET_FLAGS_ANONYMOUS;
654 if (c->display_usage) {
659 _("Fetch domain SID into local secrets.tdb"));
663 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id,
665 rpc_getsid_internals,
669 /****************************************************************************/
672 * Basic usage function for 'net rpc user'.
673 * @param argc Standard main() style argc.
674 * @param argv Standard main() style argv. Initial components are already
678 static int rpc_user_usage(struct net_context *c, int argc, const char **argv)
680 return net_user_usage(c, argc, argv);
684 * Add a new user to a remote RPC server.
686 * @param argc Standard main() style argc.
687 * @param argv Standard main() style argv. Initial components are already
690 * @return A shell status integer (0 for success).
693 static int rpc_user_add(struct net_context *c, int argc, const char **argv)
695 NET_API_STATUS status;
696 struct USER_INFO_1 info1;
697 uint32_t parm_error = 0;
699 if (argc < 1 || c->display_usage) {
700 rpc_user_usage(c, argc, argv);
706 info1.usri1_name = argv[0];
708 info1.usri1_password = argv[1];
711 status = NetUserAdd(c->opt_host, 1, (uint8_t *)&info1, &parm_error);
714 d_fprintf(stderr,_("Failed to add user '%s' with error: %s.\n"),
715 argv[0], libnetapi_get_error_string(c->netapi_ctx,
719 d_printf(_("Added user '%s'.\n"), argv[0]);
726 * Rename a user on a remote RPC server.
728 * @param argc Standard main() style argc.
729 * @param argv Standard main() style argv. Initial components are already
732 * @return A shell status integer (0 for success).
735 static int rpc_user_rename(struct net_context *c, int argc, const char **argv)
737 NET_API_STATUS status;
738 struct USER_INFO_0 u0;
739 uint32_t parm_err = 0;
741 if (argc != 2 || c->display_usage) {
742 rpc_user_usage(c, argc, argv);
746 u0.usri0_name = argv[1];
748 status = NetUserSetInfo(c->opt_host, argv[0],
749 0, (uint8_t *)&u0, &parm_err);
752 _("Failed to rename user from %s to %s - %s\n"),
754 libnetapi_get_error_string(c->netapi_ctx, status));
756 d_printf(_("Renamed user from %s to %s\n"), argv[0], argv[1]);
763 * Set a user's primary group
765 * @param argc Standard main() style argc.
766 * @param argv Standard main() style argv. Initial components are already
769 * @return A shell status integer (0 for success).
772 static int rpc_user_setprimarygroup(struct net_context *c, int argc,
775 NET_API_STATUS status;
777 struct GROUP_INFO_2 *g2;
778 struct USER_INFO_1051 u1051;
779 uint32_t parm_err = 0;
781 if (argc != 2 || c->display_usage) {
782 rpc_user_usage(c, argc, argv);
786 status = NetGroupGetInfo(c->opt_host, argv[1], 2, &buffer);
788 d_fprintf(stderr, _("Failed to find group name %s -- %s\n"),
790 libnetapi_get_error_string(c->netapi_ctx, status));
793 g2 = (struct GROUP_INFO_2 *)buffer;
795 u1051.usri1051_primary_group_id = g2->grpi2_group_id;
797 NetApiBufferFree(buffer);
799 status = NetUserSetInfo(c->opt_host, argv[0], 1051,
800 (uint8_t *)&u1051, &parm_err);
803 _("Failed to set user's primary group %s to %s - "
804 "%s\n"), argv[0], argv[1],
805 libnetapi_get_error_string(c->netapi_ctx, status));
807 d_printf(_("Set primary group of user %s to %s\n"), argv[0],
814 * Delete a user from a remote RPC server.
816 * @param argc Standard main() style argc.
817 * @param argv Standard main() style argv. Initial components are already
820 * @return A shell status integer (0 for success).
823 static int rpc_user_delete(struct net_context *c, int argc, const char **argv)
825 NET_API_STATUS status;
827 if (argc < 1 || c->display_usage) {
828 rpc_user_usage(c, argc, argv);
832 status = NetUserDel(c->opt_host, argv[0]);
835 d_fprintf(stderr, _("Failed to delete user '%s' with: %s.\n"),
837 libnetapi_get_error_string(c->netapi_ctx, status));
840 d_printf(_("Deleted user '%s'.\n"), argv[0]);
847 * Set a user's password on a remote RPC server.
849 * @param argc Standard main() style argc.
850 * @param argv Standard main() style argv. Initial components are already
853 * @return A shell status integer (0 for success).
856 static int rpc_user_password(struct net_context *c, int argc, const char **argv)
858 NET_API_STATUS status;
860 struct USER_INFO_1003 u1003;
861 uint32_t parm_err = 0;
864 if (argc < 1 || c->display_usage) {
865 rpc_user_usage(c, argc, argv);
870 u1003.usri1003_password = argv[1];
872 ret = asprintf(&prompt, _("Enter new password for %s:"),
877 u1003.usri1003_password = talloc_strdup(c, getpass(prompt));
879 if (u1003.usri1003_password == NULL) {
884 status = NetUserSetInfo(c->opt_host, argv[0], 1003, (uint8_t *)&u1003, &parm_err);
886 /* Display results */
889 _("Failed to set password for '%s' with error: %s.\n"),
890 argv[0], libnetapi_get_error_string(c->netapi_ctx,
899 * List a user's groups from a remote RPC server.
901 * @param argc Standard main() style argc.
902 * @param argv Standard main() style argv. Initial components are already
905 * @return A shell status integer (0 for success)
908 static int rpc_user_info(struct net_context *c, int argc, const char **argv)
911 NET_API_STATUS status;
912 struct GROUP_USERS_INFO_0 *u0 = NULL;
913 uint32_t entries_read = 0;
914 uint32_t total_entries = 0;
918 if (argc < 1 || c->display_usage) {
919 rpc_user_usage(c, argc, argv);
923 status = NetUserGetGroups(c->opt_host,
926 (uint8_t **)(void *)&u0,
932 _("Failed to get groups for '%s' with error: %s.\n"),
933 argv[0], libnetapi_get_error_string(c->netapi_ctx,
938 for (i=0; i < entries_read; i++) {
939 printf("%s\n", u0->grui0_name);
947 * List users on a remote RPC server.
949 * All parameters are provided by the run_rpc_command function, except for
950 * argc, argv which are passed through.
952 * @param domain_sid The domain sid acquired from the remote server.
953 * @param cli A cli_state connected to the server.
954 * @param mem_ctx Talloc context, destroyed on completion of the function.
955 * @param argc Standard main() style argc.
956 * @param argv Standard main() style argv. Initial components are already
959 * @return Normal NTSTATUS return.
962 static int rpc_user_list(struct net_context *c, int argc, const char **argv)
964 NET_API_STATUS status;
965 uint32_t start_idx=0, num_entries, i, loop_count = 0;
966 struct NET_DISPLAY_USER *info = NULL;
969 /* Query domain users */
970 if (c->opt_long_list_entries)
971 d_printf(_("\nUser name Comment"
972 "\n-----------------------------\n"));
974 uint32_t max_entries, max_size;
976 dcerpc_get_query_dispinfo_params(
977 loop_count, &max_entries, &max_size);
979 status = NetQueryDisplayInformation(c->opt_host,
986 if (status != 0 && status != ERROR_MORE_DATA) {
990 info = (struct NET_DISPLAY_USER *)buffer;
992 for (i = 0; i < num_entries; i++) {
994 if (c->opt_long_list_entries)
995 printf("%-21.21s %s\n", info->usri1_name,
996 info->usri1_comment);
998 printf("%s\n", info->usri1_name);
1002 NetApiBufferFree(buffer);
1005 start_idx += num_entries;
1007 } while (status == ERROR_MORE_DATA);
1013 * 'net rpc user' entrypoint.
1014 * @param argc Standard main() style argc.
1015 * @param argv Standard main() style argv. Initial components are already
1019 int net_rpc_user(struct net_context *c, int argc, const char **argv)
1021 NET_API_STATUS status;
1023 struct functable func[] = {
1028 N_("Add specified user"),
1029 N_("net rpc user add\n"
1030 " Add specified user")
1036 N_("List domain groups of user"),
1037 N_("net rpc user info\n"
1038 " List domain groups of user")
1044 N_("Remove specified user"),
1045 N_("net rpc user delete\n"
1046 " Remove specified user")
1052 N_("Change user password"),
1053 N_("net rpc user password\n"
1054 " Change user password")
1060 N_("Rename specified user"),
1061 N_("net rpc user rename\n"
1062 " Rename specified user")
1066 rpc_user_setprimarygroup,
1068 "Set a user's primary group",
1069 "net rpc user setprimarygroup\n"
1070 " Set a user's primary group"
1072 {NULL, NULL, 0, NULL, NULL}
1075 status = libnetapi_net_init(&c->netapi_ctx);
1079 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
1080 libnetapi_set_password(c->netapi_ctx, c->opt_password);
1081 if (c->opt_kerberos) {
1082 libnetapi_set_use_kerberos(c->netapi_ctx);
1086 if (c->display_usage) {
1091 _("List all users"));
1092 net_display_usage_from_functable(func);
1096 return rpc_user_list(c, argc, argv);
1099 return net_run_function(c, argc, argv, "net rpc user", func);
1102 static NTSTATUS rpc_sh_user_list(struct net_context *c,
1103 TALLOC_CTX *mem_ctx,
1104 struct rpc_sh_ctx *ctx,
1105 struct rpc_pipe_client *pipe_hnd,
1106 int argc, const char **argv)
1108 return werror_to_ntstatus(W_ERROR(rpc_user_list(c, argc, argv)));
1111 static NTSTATUS rpc_sh_user_info(struct net_context *c,
1112 TALLOC_CTX *mem_ctx,
1113 struct rpc_sh_ctx *ctx,
1114 struct rpc_pipe_client *pipe_hnd,
1115 int argc, const char **argv)
1117 return werror_to_ntstatus(W_ERROR(rpc_user_info(c, argc, argv)));
1120 static NTSTATUS rpc_sh_handle_user(struct net_context *c,
1121 TALLOC_CTX *mem_ctx,
1122 struct rpc_sh_ctx *ctx,
1123 struct rpc_pipe_client *pipe_hnd,
1124 int argc, const char **argv,
1126 struct net_context *c,
1127 TALLOC_CTX *mem_ctx,
1128 struct rpc_sh_ctx *ctx,
1129 struct rpc_pipe_client *pipe_hnd,
1130 struct policy_handle *user_hnd,
1131 int argc, const char **argv))
1133 struct policy_handle connect_pol, domain_pol, user_pol;
1134 NTSTATUS status, result;
1137 enum lsa_SidType type;
1138 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1141 d_fprintf(stderr, "%s %s <username>\n", _("Usage:"),
1143 return NT_STATUS_INVALID_PARAMETER;
1146 ZERO_STRUCT(connect_pol);
1147 ZERO_STRUCT(domain_pol);
1148 ZERO_STRUCT(user_pol);
1150 status = net_rpc_lookup_name(c, mem_ctx, rpc_pipe_np_smb_conn(pipe_hnd),
1151 argv[0], NULL, NULL, &sid, &type);
1152 if (!NT_STATUS_IS_OK(status)) {
1153 d_fprintf(stderr, _("Could not lookup %s: %s\n"), argv[0],
1158 if (type != SID_NAME_USER) {
1159 d_fprintf(stderr, _("%s is a %s, not a user\n"), argv[0],
1160 sid_type_lookup(type));
1161 status = NT_STATUS_NO_SUCH_USER;
1165 if (!sid_peek_check_rid(ctx->domain_sid, &sid, &rid)) {
1166 d_fprintf(stderr, _("%s is not in our domain\n"), argv[0]);
1167 status = NT_STATUS_NO_SUCH_USER;
1171 status = dcerpc_samr_Connect2(b, mem_ctx,
1173 MAXIMUM_ALLOWED_ACCESS,
1176 if (!NT_STATUS_IS_OK(status)) {
1179 if (!NT_STATUS_IS_OK(result)) {
1184 status = dcerpc_samr_OpenDomain(b, mem_ctx,
1186 MAXIMUM_ALLOWED_ACCESS,
1190 if (!NT_STATUS_IS_OK(status)) {
1193 if (!NT_STATUS_IS_OK(result)) {
1198 status = dcerpc_samr_OpenUser(b, mem_ctx,
1200 MAXIMUM_ALLOWED_ACCESS,
1204 if (!NT_STATUS_IS_OK(status)) {
1207 if (!NT_STATUS_IS_OK(result)) {
1212 status = fn(c, mem_ctx, ctx, pipe_hnd, &user_pol, argc-1, argv+1);
1215 if (is_valid_policy_hnd(&user_pol)) {
1216 dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
1218 if (is_valid_policy_hnd(&domain_pol)) {
1219 dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
1221 if (is_valid_policy_hnd(&connect_pol)) {
1222 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
1227 static NTSTATUS rpc_sh_user_show_internals(struct net_context *c,
1228 TALLOC_CTX *mem_ctx,
1229 struct rpc_sh_ctx *ctx,
1230 struct rpc_pipe_client *pipe_hnd,
1231 struct policy_handle *user_hnd,
1232 int argc, const char **argv)
1234 NTSTATUS status, result;
1235 union samr_UserInfo *info = NULL;
1236 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1239 d_fprintf(stderr, "%s %s show <username>\n", _("Usage:"),
1241 return NT_STATUS_INVALID_PARAMETER;
1244 status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
1249 if (!NT_STATUS_IS_OK(status)) {
1252 if (!NT_STATUS_IS_OK(result)) {
1256 d_printf(_("user rid: %d, group rid: %d\n"),
1258 info->info21.primary_gid);
1263 static NTSTATUS rpc_sh_user_show(struct net_context *c,
1264 TALLOC_CTX *mem_ctx,
1265 struct rpc_sh_ctx *ctx,
1266 struct rpc_pipe_client *pipe_hnd,
1267 int argc, const char **argv)
1269 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1270 rpc_sh_user_show_internals);
1273 #define FETCHSTR(name, rec) \
1274 do { if (strequal(ctx->thiscmd, name)) { \
1275 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1278 #define SETSTR(name, rec, flag) \
1279 do { if (strequal(ctx->thiscmd, name)) { \
1280 init_lsa_String(&(info->info21.rec), argv[0]); \
1281 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1284 static NTSTATUS rpc_sh_user_str_edit_internals(struct net_context *c,
1285 TALLOC_CTX *mem_ctx,
1286 struct rpc_sh_ctx *ctx,
1287 struct rpc_pipe_client *pipe_hnd,
1288 struct policy_handle *user_hnd,
1289 int argc, const char **argv)
1291 NTSTATUS status, result;
1292 const char *username;
1293 const char *oldval = "";
1294 union samr_UserInfo *info = NULL;
1295 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1298 d_fprintf(stderr, "%s %s <username> [new value|NULL]\n",
1299 _("Usage:"), ctx->whoami);
1300 return NT_STATUS_INVALID_PARAMETER;
1303 status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
1308 if (!NT_STATUS_IS_OK(status)) {
1311 if (!NT_STATUS_IS_OK(result)) {
1315 username = talloc_strdup(mem_ctx, info->info21.account_name.string);
1317 FETCHSTR("fullname", full_name);
1318 FETCHSTR("homedir", home_directory);
1319 FETCHSTR("homedrive", home_drive);
1320 FETCHSTR("logonscript", logon_script);
1321 FETCHSTR("profilepath", profile_path);
1322 FETCHSTR("description", description);
1325 d_printf(_("%s's %s: [%s]\n"), username, ctx->thiscmd, oldval);
1329 if (strcmp(argv[0], "NULL") == 0) {
1333 ZERO_STRUCT(info->info21);
1335 SETSTR("fullname", full_name, FULL_NAME);
1336 SETSTR("homedir", home_directory, HOME_DIRECTORY);
1337 SETSTR("homedrive", home_drive, HOME_DRIVE);
1338 SETSTR("logonscript", logon_script, LOGON_SCRIPT);
1339 SETSTR("profilepath", profile_path, PROFILE_PATH);
1340 SETSTR("description", description, DESCRIPTION);
1342 status = dcerpc_samr_SetUserInfo(b, mem_ctx,
1347 if (!NT_STATUS_IS_OK(status)) {
1353 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username,
1354 ctx->thiscmd, oldval, argv[0]);
1361 #define HANDLEFLG(name, rec) \
1362 do { if (strequal(ctx->thiscmd, name)) { \
1363 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1365 newflags = oldflags | ACB_##rec; \
1367 newflags = oldflags & ~ACB_##rec; \
1370 static NTSTATUS rpc_sh_user_str_edit(struct net_context *c,
1371 TALLOC_CTX *mem_ctx,
1372 struct rpc_sh_ctx *ctx,
1373 struct rpc_pipe_client *pipe_hnd,
1374 int argc, const char **argv)
1376 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1377 rpc_sh_user_str_edit_internals);
1380 static NTSTATUS rpc_sh_user_flag_edit_internals(struct net_context *c,
1381 TALLOC_CTX *mem_ctx,
1382 struct rpc_sh_ctx *ctx,
1383 struct rpc_pipe_client *pipe_hnd,
1384 struct policy_handle *user_hnd,
1385 int argc, const char **argv)
1387 NTSTATUS status, result;
1388 const char *username;
1389 const char *oldval = "unknown";
1390 uint32 oldflags, newflags;
1392 union samr_UserInfo *info = NULL;
1393 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1396 ((argc == 1) && !strequal(argv[0], "yes") &&
1397 !strequal(argv[0], "no"))) {
1398 /* TRANSATORS: The yes|no here are program keywords. Please do
1400 d_fprintf(stderr, _("Usage: %s <username> [yes|no]\n"),
1402 return NT_STATUS_INVALID_PARAMETER;
1405 newval = strequal(argv[0], "yes");
1407 status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
1412 if (!NT_STATUS_IS_OK(status)) {
1415 if (!NT_STATUS_IS_OK(result)) {
1419 username = talloc_strdup(mem_ctx, info->info21.account_name.string);
1420 oldflags = info->info21.acct_flags;
1421 newflags = info->info21.acct_flags;
1423 HANDLEFLG("disabled", DISABLED);
1424 HANDLEFLG("pwnotreq", PWNOTREQ);
1425 HANDLEFLG("autolock", AUTOLOCK);
1426 HANDLEFLG("pwnoexp", PWNOEXP);
1429 d_printf(_("%s's %s flag: %s\n"), username, ctx->thiscmd,
1434 ZERO_STRUCT(info->info21);
1436 info->info21.acct_flags = newflags;
1437 info->info21.fields_present = SAMR_FIELD_ACCT_FLAGS;
1439 status = dcerpc_samr_SetUserInfo(b, mem_ctx,
1444 if (!NT_STATUS_IS_OK(status)) {
1448 if (NT_STATUS_IS_OK(result)) {
1449 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username,
1450 ctx->thiscmd, oldval, argv[0]);
1458 static NTSTATUS rpc_sh_user_flag_edit(struct net_context *c,
1459 TALLOC_CTX *mem_ctx,
1460 struct rpc_sh_ctx *ctx,
1461 struct rpc_pipe_client *pipe_hnd,
1462 int argc, const char **argv)
1464 return rpc_sh_handle_user(c, mem_ctx, ctx, pipe_hnd, argc, argv,
1465 rpc_sh_user_flag_edit_internals);
1468 struct rpc_sh_cmd *net_rpc_user_edit_cmds(struct net_context *c,
1469 TALLOC_CTX *mem_ctx,
1470 struct rpc_sh_ctx *ctx)
1472 static struct rpc_sh_cmd cmds[] = {
1474 { "fullname", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1475 N_("Show/Set a user's full name") },
1477 { "homedir", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1478 N_("Show/Set a user's home directory") },
1480 { "homedrive", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1481 N_("Show/Set a user's home drive") },
1483 { "logonscript", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1484 N_("Show/Set a user's logon script") },
1486 { "profilepath", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1487 N_("Show/Set a user's profile path") },
1489 { "description", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_str_edit,
1490 N_("Show/Set a user's description") },
1492 { "disabled", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_flag_edit,
1493 N_("Show/Set whether a user is disabled") },
1495 { "autolock", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_flag_edit,
1496 N_("Show/Set whether a user locked out") },
1498 { "pwnotreq", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_flag_edit,
1499 N_("Show/Set whether a user does not need a password") },
1501 { "pwnoexp", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_flag_edit,
1502 N_("Show/Set whether a user's password does not expire") },
1504 { NULL, NULL, 0, NULL, NULL }
1510 struct rpc_sh_cmd *net_rpc_user_cmds(struct net_context *c,
1511 TALLOC_CTX *mem_ctx,
1512 struct rpc_sh_ctx *ctx)
1514 static struct rpc_sh_cmd cmds[] = {
1516 { "list", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_list,
1517 N_("List available users") },
1519 { "info", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_info,
1520 N_("List the domain groups a user is member of") },
1522 { "show", NULL, &ndr_table_samr.syntax_id, rpc_sh_user_show,
1523 N_("Show info about a user") },
1525 { "edit", net_rpc_user_edit_cmds, 0, NULL,
1526 N_("Show/Modify a user's fields") },
1528 { NULL, NULL, 0, NULL, NULL }
1534 /****************************************************************************/
1537 * Basic usage function for 'net rpc group'.
1538 * @param argc Standard main() style argc.
1539 * @param argv Standard main() style argv. Initial components are already
1543 static int rpc_group_usage(struct net_context *c, int argc, const char **argv)
1545 return net_group_usage(c, argc, argv);
1549 * Delete group on a remote RPC server.
1551 * All parameters are provided by the run_rpc_command function, except for
1552 * argc, argv which are passed through.
1554 * @param domain_sid The domain sid acquired from the remote server.
1555 * @param cli A cli_state connected to the server.
1556 * @param mem_ctx Talloc context, destroyed on completion of the function.
1557 * @param argc Standard main() style argc.
1558 * @param argv Standard main() style argv. Initial components are already
1561 * @return Normal NTSTATUS return.
1564 static NTSTATUS rpc_group_delete_internals(struct net_context *c,
1565 const struct dom_sid *domain_sid,
1566 const char *domain_name,
1567 struct cli_state *cli,
1568 struct rpc_pipe_client *pipe_hnd,
1569 TALLOC_CTX *mem_ctx,
1573 struct policy_handle connect_pol, domain_pol, group_pol, user_pol;
1574 bool group_is_primary = false;
1575 NTSTATUS status, result;
1577 struct samr_RidAttrArray *rids = NULL;
1580 /* struct samr_RidWithAttribute *user_gids; */
1581 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1583 struct samr_Ids group_rids, name_types;
1584 struct lsa_String lsa_acct_name;
1585 union samr_UserInfo *info = NULL;
1587 if (argc < 1 || c->display_usage) {
1588 rpc_group_usage(c, argc,argv);
1589 return NT_STATUS_OK; /* ok? */
1592 status = dcerpc_samr_Connect2(b, mem_ctx,
1594 MAXIMUM_ALLOWED_ACCESS,
1597 if (!NT_STATUS_IS_OK(status)) {
1598 d_fprintf(stderr, _("Request samr_Connect2 failed\n"));
1602 if (!NT_STATUS_IS_OK(result)) {
1604 d_fprintf(stderr, _("Request samr_Connect2 failed\n"));
1608 status = dcerpc_samr_OpenDomain(b, mem_ctx,
1610 MAXIMUM_ALLOWED_ACCESS,
1611 CONST_DISCARD(struct dom_sid2 *, domain_sid),
1614 if (!NT_STATUS_IS_OK(status)) {
1615 d_fprintf(stderr, _("Request open_domain failed\n"));
1619 if (!NT_STATUS_IS_OK(result)) {
1621 d_fprintf(stderr, _("Request open_domain failed\n"));
1625 init_lsa_String(&lsa_acct_name, argv[0]);
1627 status = dcerpc_samr_LookupNames(b, mem_ctx,
1634 if (!NT_STATUS_IS_OK(status)) {
1635 d_fprintf(stderr, _("Lookup of '%s' failed\n"),argv[0]);
1639 if (!NT_STATUS_IS_OK(result)) {
1641 d_fprintf(stderr, _("Lookup of '%s' failed\n"),argv[0]);
1645 switch (name_types.ids[0])
1647 case SID_NAME_DOM_GRP:
1648 status = dcerpc_samr_OpenGroup(b, mem_ctx,
1650 MAXIMUM_ALLOWED_ACCESS,
1654 if (!NT_STATUS_IS_OK(status)) {
1655 d_fprintf(stderr, _("Request open_group failed"));
1659 if (!NT_STATUS_IS_OK(result)) {
1661 d_fprintf(stderr, _("Request open_group failed"));
1665 group_rid = group_rids.ids[0];
1667 status = dcerpc_samr_QueryGroupMember(b, mem_ctx,
1671 if (!NT_STATUS_IS_OK(status)) {
1673 _("Unable to query group members of %s"),
1678 if (!NT_STATUS_IS_OK(result)) {
1681 _("Unable to query group members of %s"),
1686 if (c->opt_verbose) {
1688 _("Domain Group %s (rid: %d) has %d members\n"),
1689 argv[0],group_rid, rids->count);
1692 /* Check if group is anyone's primary group */
1693 for (i = 0; i < rids->count; i++)
1695 status = dcerpc_samr_OpenUser(b, mem_ctx,
1697 MAXIMUM_ALLOWED_ACCESS,
1701 if (!NT_STATUS_IS_OK(status)) {
1703 _("Unable to open group member %d\n"),
1708 if (!NT_STATUS_IS_OK(result)) {
1711 _("Unable to open group member %d\n"),
1716 status = dcerpc_samr_QueryUserInfo(b, mem_ctx,
1721 if (!NT_STATUS_IS_OK(status)) {
1723 _("Unable to lookup userinfo for group "
1729 if (!NT_STATUS_IS_OK(result)) {
1732 _("Unable to lookup userinfo for group "
1738 if (info->info21.primary_gid == group_rid) {
1739 if (c->opt_verbose) {
1740 d_printf(_("Group is primary group "
1742 info->info21.account_name.string);
1744 group_is_primary = true;
1747 dcerpc_samr_Close(b, mem_ctx, &user_pol, &result);
1750 if (group_is_primary) {
1751 d_fprintf(stderr, _("Unable to delete group because "
1752 "some of it's members have it as primary "
1754 status = NT_STATUS_MEMBERS_PRIMARY_GROUP;
1758 /* remove all group members */
1759 for (i = 0; i < rids->count; i++)
1762 d_printf(_("Remove group member %d..."),
1764 status = dcerpc_samr_DeleteGroupMember(b, mem_ctx,
1768 if (!NT_STATUS_IS_OK(status)) {
1772 if (NT_STATUS_IS_OK(result)) {
1774 d_printf(_("ok\n"));
1777 d_printf("%s\n", _("failed"));
1782 status = dcerpc_samr_DeleteDomainGroup(b, mem_ctx,
1785 if (!NT_STATUS_IS_OK(status)) {
1792 /* removing a local group is easier... */
1793 case SID_NAME_ALIAS:
1794 status = dcerpc_samr_OpenAlias(b, mem_ctx,
1796 MAXIMUM_ALLOWED_ACCESS,
1800 if (!NT_STATUS_IS_OK(status)) {
1801 d_fprintf(stderr, _("Request open_alias failed\n"));
1804 if (!NT_STATUS_IS_OK(result)) {
1806 d_fprintf(stderr, _("Request open_alias failed\n"));
1810 status = dcerpc_samr_DeleteDomAlias(b, mem_ctx,
1813 if (!NT_STATUS_IS_OK(status)) {
1821 d_fprintf(stderr, _("%s is of type %s. This command is only "
1822 "for deleting local or global groups\n"),
1823 argv[0],sid_type_lookup(name_types.ids[0]));
1824 status = NT_STATUS_UNSUCCESSFUL;
1828 if (NT_STATUS_IS_OK(status)) {
1830 d_printf(_("Deleted %s '%s'\n"),
1831 sid_type_lookup(name_types.ids[0]), argv[0]);
1833 d_fprintf(stderr, _("Deleting of %s failed: %s\n"), argv[0],
1834 get_friendly_nt_error_msg(status));
1842 static int rpc_group_delete(struct net_context *c, int argc, const char **argv)
1844 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
1845 rpc_group_delete_internals, argc,argv);
1848 static int rpc_group_add_internals(struct net_context *c, int argc, const char **argv)
1850 NET_API_STATUS status;
1851 struct GROUP_INFO_1 info1;
1852 uint32_t parm_error = 0;
1854 if (argc != 1 || c->display_usage) {
1855 rpc_group_usage(c, argc, argv);
1861 info1.grpi1_name = argv[0];
1862 if (c->opt_comment && strlen(c->opt_comment) > 0) {
1863 info1.grpi1_comment = c->opt_comment;
1866 status = NetGroupAdd(c->opt_host, 1, (uint8_t *)&info1, &parm_error);
1870 _("Failed to add group '%s' with error: %s.\n"),
1871 argv[0], libnetapi_get_error_string(c->netapi_ctx,
1875 d_printf(_("Added group '%s'.\n"), argv[0]);
1881 static int rpc_alias_add_internals(struct net_context *c, int argc, const char **argv)
1883 NET_API_STATUS status;
1884 struct LOCALGROUP_INFO_1 info1;
1885 uint32_t parm_error = 0;
1887 if (argc != 1 || c->display_usage) {
1888 rpc_group_usage(c, argc, argv);
1894 info1.lgrpi1_name = argv[0];
1895 if (c->opt_comment && strlen(c->opt_comment) > 0) {
1896 info1.lgrpi1_comment = c->opt_comment;
1899 status = NetLocalGroupAdd(c->opt_host, 1, (uint8_t *)&info1, &parm_error);
1903 _("Failed to add alias '%s' with error: %s.\n"),
1904 argv[0], libnetapi_get_error_string(c->netapi_ctx,
1908 d_printf(_("Added alias '%s'.\n"), argv[0]);
1914 static int rpc_group_add(struct net_context *c, int argc, const char **argv)
1916 if (c->opt_localgroup)
1917 return rpc_alias_add_internals(c, argc, argv);
1919 return rpc_group_add_internals(c, argc, argv);
1922 static NTSTATUS get_sid_from_name(struct cli_state *cli,
1923 TALLOC_CTX *mem_ctx,
1925 struct dom_sid *sid,
1926 enum lsa_SidType *type)
1928 struct dom_sid *sids = NULL;
1929 enum lsa_SidType *types = NULL;
1930 struct rpc_pipe_client *pipe_hnd = NULL;
1931 struct policy_handle lsa_pol;
1932 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1934 result = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
1936 if (!NT_STATUS_IS_OK(result)) {
1940 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, false,
1941 SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol);
1943 if (!NT_STATUS_IS_OK(result)) {
1947 result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
1948 &name, NULL, 1, &sids, &types);
1950 if (NT_STATUS_IS_OK(result)) {
1951 sid_copy(sid, &sids[0]);
1955 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
1959 TALLOC_FREE(pipe_hnd);
1962 if (!NT_STATUS_IS_OK(result) && (StrnCaseCmp(name, "S-", 2) == 0)) {
1964 /* Try as S-1-5-whatever */
1966 struct dom_sid tmp_sid;
1968 if (string_to_sid(&tmp_sid, name)) {
1969 sid_copy(sid, &tmp_sid);
1970 *type = SID_NAME_UNKNOWN;
1971 result = NT_STATUS_OK;
1978 static NTSTATUS rpc_add_groupmem(struct rpc_pipe_client *pipe_hnd,
1979 TALLOC_CTX *mem_ctx,
1980 const struct dom_sid *group_sid,
1983 struct policy_handle connect_pol, domain_pol;
1984 NTSTATUS status, result;
1986 struct policy_handle group_pol;
1987 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
1989 struct samr_Ids rids, rid_types;
1990 struct lsa_String lsa_acct_name;
1994 sid_copy(&sid, group_sid);
1996 if (!sid_split_rid(&sid, &group_rid)) {
1997 return NT_STATUS_UNSUCCESSFUL;
2000 /* Get sam policy handle */
2001 status = dcerpc_samr_Connect2(b, mem_ctx,
2003 MAXIMUM_ALLOWED_ACCESS,
2006 if (!NT_STATUS_IS_OK(status)) {
2009 if (!NT_STATUS_IS_OK(result)) {
2013 /* Get domain policy handle */
2014 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2016 MAXIMUM_ALLOWED_ACCESS,
2020 if (!NT_STATUS_IS_OK(status)) {
2023 if (!NT_STATUS_IS_OK(result)) {
2027 init_lsa_String(&lsa_acct_name, member);
2029 status = dcerpc_samr_LookupNames(b, mem_ctx,
2036 if (!NT_STATUS_IS_OK(status)) {
2037 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2042 if (!NT_STATUS_IS_OK(result)) {
2044 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2049 status = dcerpc_samr_OpenGroup(b, mem_ctx,
2051 MAXIMUM_ALLOWED_ACCESS,
2055 if (!NT_STATUS_IS_OK(status)) {
2059 if (!NT_STATUS_IS_OK(result)) {
2064 status = dcerpc_samr_AddGroupMember(b, mem_ctx,
2067 0x0005, /* unknown flags */
2069 if (!NT_STATUS_IS_OK(status)) {
2076 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
2080 static NTSTATUS rpc_add_aliasmem(struct rpc_pipe_client *pipe_hnd,
2081 TALLOC_CTX *mem_ctx,
2082 const struct dom_sid *alias_sid,
2085 struct policy_handle connect_pol, domain_pol;
2086 NTSTATUS status, result;
2088 struct policy_handle alias_pol;
2089 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2091 struct dom_sid member_sid;
2092 enum lsa_SidType member_type;
2096 sid_copy(&sid, alias_sid);
2098 if (!sid_split_rid(&sid, &alias_rid)) {
2099 return NT_STATUS_UNSUCCESSFUL;
2102 result = get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd), mem_ctx,
2103 member, &member_sid, &member_type);
2105 if (!NT_STATUS_IS_OK(result)) {
2106 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2111 /* Get sam policy handle */
2112 status = dcerpc_samr_Connect2(b, mem_ctx,
2114 MAXIMUM_ALLOWED_ACCESS,
2117 if (!NT_STATUS_IS_OK(status)) {
2120 if (!NT_STATUS_IS_OK(result)) {
2125 /* Get domain policy handle */
2126 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2128 MAXIMUM_ALLOWED_ACCESS,
2132 if (!NT_STATUS_IS_OK(status)) {
2135 if (!NT_STATUS_IS_OK(result)) {
2140 status = dcerpc_samr_OpenAlias(b, mem_ctx,
2142 MAXIMUM_ALLOWED_ACCESS,
2146 if (!NT_STATUS_IS_OK(status)) {
2149 if (!NT_STATUS_IS_OK(result)) {
2153 status = dcerpc_samr_AddAliasMember(b, mem_ctx,
2157 if (!NT_STATUS_IS_OK(status)) {
2164 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
2168 static NTSTATUS rpc_group_addmem_internals(struct net_context *c,
2169 const struct dom_sid *domain_sid,
2170 const char *domain_name,
2171 struct cli_state *cli,
2172 struct rpc_pipe_client *pipe_hnd,
2173 TALLOC_CTX *mem_ctx,
2177 struct dom_sid group_sid;
2178 enum lsa_SidType group_type;
2180 if (argc != 2 || c->display_usage) {
2183 _("net rpc group addmem <group> <member>\n"
2184 " Add a member to a group\n"
2185 " group\tGroup to add member to\n"
2186 " member\tMember to add to group\n"));
2187 return NT_STATUS_UNSUCCESSFUL;
2190 if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
2191 &group_sid, &group_type))) {
2192 d_fprintf(stderr, _("Could not lookup group name %s\n"),
2194 return NT_STATUS_UNSUCCESSFUL;
2197 if (group_type == SID_NAME_DOM_GRP) {
2198 NTSTATUS result = rpc_add_groupmem(pipe_hnd, mem_ctx,
2199 &group_sid, argv[1]);
2201 if (!NT_STATUS_IS_OK(result)) {
2202 d_fprintf(stderr, _("Could not add %s to %s: %s\n"),
2203 argv[1], argv[0], nt_errstr(result));
2208 if (group_type == SID_NAME_ALIAS) {
2209 NTSTATUS result = rpc_add_aliasmem(pipe_hnd, mem_ctx,
2210 &group_sid, argv[1]);
2212 if (!NT_STATUS_IS_OK(result)) {
2213 d_fprintf(stderr, _("Could not add %s to %s: %s\n"),
2214 argv[1], argv[0], nt_errstr(result));
2219 d_fprintf(stderr, _("Can only add members to global or local groups "
2220 "which %s is not\n"), argv[0]);
2222 return NT_STATUS_UNSUCCESSFUL;
2225 static int rpc_group_addmem(struct net_context *c, int argc, const char **argv)
2227 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2228 rpc_group_addmem_internals,
2232 static NTSTATUS rpc_del_groupmem(struct net_context *c,
2233 struct rpc_pipe_client *pipe_hnd,
2234 TALLOC_CTX *mem_ctx,
2235 const struct dom_sid *group_sid,
2238 struct policy_handle connect_pol, domain_pol;
2239 NTSTATUS status, result;
2241 struct policy_handle group_pol;
2242 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2244 struct samr_Ids rids, rid_types;
2245 struct lsa_String lsa_acct_name;
2249 sid_copy(&sid, group_sid);
2251 if (!sid_split_rid(&sid, &group_rid))
2252 return NT_STATUS_UNSUCCESSFUL;
2254 /* Get sam policy handle */
2255 status = dcerpc_samr_Connect2(b, mem_ctx,
2257 MAXIMUM_ALLOWED_ACCESS,
2260 if (!NT_STATUS_IS_OK(status)) {
2263 if (!NT_STATUS_IS_OK(result)) {
2268 /* Get domain policy handle */
2269 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2271 MAXIMUM_ALLOWED_ACCESS,
2275 if (!NT_STATUS_IS_OK(status)) {
2278 if (!NT_STATUS_IS_OK(result)) {
2282 init_lsa_String(&lsa_acct_name, member);
2284 status = dcerpc_samr_LookupNames(b, mem_ctx,
2291 if (!NT_STATUS_IS_OK(status)) {
2292 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2297 if (!NT_STATUS_IS_OK(result)) {
2299 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2304 status = dcerpc_samr_OpenGroup(b, mem_ctx,
2306 MAXIMUM_ALLOWED_ACCESS,
2310 if (!NT_STATUS_IS_OK(status)) {
2313 if (!NT_STATUS_IS_OK(result)) {
2318 status = dcerpc_samr_DeleteGroupMember(b, mem_ctx,
2322 if (!NT_STATUS_IS_OK(status)) {
2328 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
2332 static NTSTATUS rpc_del_aliasmem(struct rpc_pipe_client *pipe_hnd,
2333 TALLOC_CTX *mem_ctx,
2334 const struct dom_sid *alias_sid,
2337 struct policy_handle connect_pol, domain_pol;
2338 NTSTATUS status, result;
2340 struct policy_handle alias_pol;
2341 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2343 struct dom_sid member_sid;
2344 enum lsa_SidType member_type;
2348 sid_copy(&sid, alias_sid);
2350 if (!sid_split_rid(&sid, &alias_rid))
2351 return NT_STATUS_UNSUCCESSFUL;
2353 result = get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd), mem_ctx,
2354 member, &member_sid, &member_type);
2356 if (!NT_STATUS_IS_OK(result)) {
2357 d_fprintf(stderr, _("Could not lookup up group member %s\n"),
2362 /* Get sam policy handle */
2363 status = dcerpc_samr_Connect2(b, mem_ctx,
2365 MAXIMUM_ALLOWED_ACCESS,
2368 if (!NT_STATUS_IS_OK(status)) {
2371 if (!NT_STATUS_IS_OK(result)) {
2376 /* Get domain policy handle */
2377 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2379 MAXIMUM_ALLOWED_ACCESS,
2383 if (!NT_STATUS_IS_OK(status)) {
2386 if (!NT_STATUS_IS_OK(result)) {
2391 status = dcerpc_samr_OpenAlias(b, mem_ctx,
2393 MAXIMUM_ALLOWED_ACCESS,
2397 if (!NT_STATUS_IS_OK(status)) {
2401 if (!NT_STATUS_IS_OK(result)) {
2405 status = dcerpc_samr_DeleteAliasMember(b, mem_ctx,
2410 if (!NT_STATUS_IS_OK(status)) {
2417 dcerpc_samr_Close(b, mem_ctx, &connect_pol, &result);
2421 static NTSTATUS rpc_group_delmem_internals(struct net_context *c,
2422 const struct dom_sid *domain_sid,
2423 const char *domain_name,
2424 struct cli_state *cli,
2425 struct rpc_pipe_client *pipe_hnd,
2426 TALLOC_CTX *mem_ctx,
2430 struct dom_sid group_sid;
2431 enum lsa_SidType group_type;
2433 if (argc != 2 || c->display_usage) {
2436 _("net rpc group delmem <group> <member>\n"
2437 " Delete a member from a group\n"
2438 " group\tGroup to delete member from\n"
2439 " member\tMember to delete from group\n"));
2440 return NT_STATUS_UNSUCCESSFUL;
2443 if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
2444 &group_sid, &group_type))) {
2445 d_fprintf(stderr, _("Could not lookup group name %s\n"),
2447 return NT_STATUS_UNSUCCESSFUL;
2450 if (group_type == SID_NAME_DOM_GRP) {
2451 NTSTATUS result = rpc_del_groupmem(c, pipe_hnd, mem_ctx,
2452 &group_sid, argv[1]);
2454 if (!NT_STATUS_IS_OK(result)) {
2455 d_fprintf(stderr, _("Could not del %s from %s: %s\n"),
2456 argv[1], argv[0], nt_errstr(result));
2461 if (group_type == SID_NAME_ALIAS) {
2462 NTSTATUS result = rpc_del_aliasmem(pipe_hnd, mem_ctx,
2463 &group_sid, argv[1]);
2465 if (!NT_STATUS_IS_OK(result)) {
2466 d_fprintf(stderr, _("Could not del %s from %s: %s\n"),
2467 argv[1], argv[0], nt_errstr(result));
2472 d_fprintf(stderr, _("Can only delete members from global or local "
2473 "groups which %s is not\n"), argv[0]);
2475 return NT_STATUS_UNSUCCESSFUL;
2478 static int rpc_group_delmem(struct net_context *c, int argc, const char **argv)
2480 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2481 rpc_group_delmem_internals,
2486 * List groups on a remote RPC server.
2488 * All parameters are provided by the run_rpc_command function, except for
2489 * argc, argv which are passes through.
2491 * @param domain_sid The domain sid acquired from the remote server.
2492 * @param cli A cli_state connected to the server.
2493 * @param mem_ctx Talloc context, destroyed on completion of the function.
2494 * @param argc Standard main() style argc.
2495 * @param argv Standard main() style argv. Initial components are already
2498 * @return Normal NTSTATUS return.
2501 static NTSTATUS rpc_group_list_internals(struct net_context *c,
2502 const struct dom_sid *domain_sid,
2503 const char *domain_name,
2504 struct cli_state *cli,
2505 struct rpc_pipe_client *pipe_hnd,
2506 TALLOC_CTX *mem_ctx,
2510 struct policy_handle connect_pol, domain_pol;
2511 NTSTATUS status, result;
2512 uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
2513 struct samr_SamArray *groups = NULL;
2514 bool global = false;
2516 bool builtin = false;
2517 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2519 if (c->display_usage) {
2522 _("net rpc group list [global] [local] [builtin]\n"
2523 " List groups on RPC server\n"
2524 " global\tList global groups\n"
2525 " local\tList local groups\n"
2526 " builtin\tList builtin groups\n"
2527 " If none of global, local or builtin is "
2528 "specified, all three options are considered "
2530 return NT_STATUS_OK;
2539 for (i=0; i<argc; i++) {
2540 if (strequal(argv[i], "global"))
2543 if (strequal(argv[i], "local"))
2546 if (strequal(argv[i], "builtin"))
2550 /* Get sam policy handle */
2552 status = dcerpc_samr_Connect2(b, mem_ctx,
2554 MAXIMUM_ALLOWED_ACCESS,
2557 if (!NT_STATUS_IS_OK(status)) {
2560 if (!NT_STATUS_IS_OK(result)) {
2565 /* Get domain policy handle */
2567 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2569 MAXIMUM_ALLOWED_ACCESS,
2570 CONST_DISCARD(struct dom_sid2 *, domain_sid),
2573 if (!NT_STATUS_IS_OK(status)) {
2576 if (!NT_STATUS_IS_OK(result)) {
2581 /* Query domain groups */
2582 if (c->opt_long_list_entries)
2583 d_printf(_("\nGroup name Comment"
2584 "\n-----------------------------\n"));
2586 uint32_t max_size, total_size, returned_size;
2587 union samr_DispInfo info;
2591 dcerpc_get_query_dispinfo_params(
2592 loop_count, &max_entries, &max_size);
2594 status = dcerpc_samr_QueryDisplayInfo(b, mem_ctx,
2604 if (!NT_STATUS_IS_OK(status)) {
2607 num_entries = info.info3.count;
2608 start_idx += info.info3.count;
2610 if (!NT_STATUS_IS_OK(result) &&
2611 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
2614 for (i = 0; i < num_entries; i++) {
2616 const char *group = NULL;
2617 const char *desc = NULL;
2619 group = info.info3.entries[i].account_name.string;
2620 desc = info.info3.entries[i].description.string;
2622 if (c->opt_long_list_entries)
2623 printf("%-21.21s %-50.50s\n",
2626 printf("%s\n", group);
2628 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2629 /* query domain aliases */
2634 status = dcerpc_samr_EnumDomainAliases(b, mem_ctx,
2641 if (!NT_STATUS_IS_OK(status)) {
2644 if (!NT_STATUS_IS_OK(result) &&
2645 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
2648 for (i = 0; i < num_entries; i++) {
2650 const char *description = NULL;
2652 if (c->opt_long_list_entries) {
2654 struct policy_handle alias_pol;
2655 union samr_AliasInfo *info = NULL;
2658 status = dcerpc_samr_OpenAlias(b, mem_ctx,
2661 groups->entries[i].idx,
2664 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2665 status = dcerpc_samr_QueryAliasInfo(b, mem_ctx,
2670 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2671 status = dcerpc_samr_Close(b, mem_ctx,
2674 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2675 description = info->description.string;
2681 if (description != NULL) {
2682 printf("%-21.21s %-50.50s\n",
2683 groups->entries[i].name.string,
2686 printf("%s\n", groups->entries[i].name.string);
2689 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2690 dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result);
2691 /* Get builtin policy handle */
2693 status = dcerpc_samr_OpenDomain(b, mem_ctx,
2695 MAXIMUM_ALLOWED_ACCESS,
2696 CONST_DISCARD(struct dom_sid2 *, &global_sid_Builtin),
2699 if (!NT_STATUS_IS_OK(status)) {
2702 if (!NT_STATUS_IS_OK(result)) {
2707 /* query builtin aliases */
2710 if (!builtin) break;
2712 status = dcerpc_samr_EnumDomainAliases(b, mem_ctx,
2719 if (!NT_STATUS_IS_OK(status)) {
2722 if (!NT_STATUS_IS_OK(result) &&
2723 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
2728 for (i = 0; i < num_entries; i++) {
2730 const char *description = NULL;
2732 if (c->opt_long_list_entries) {
2734 struct policy_handle alias_pol;
2735 union samr_AliasInfo *info = NULL;
2738 status = dcerpc_samr_OpenAlias(b, mem_ctx,
2741 groups->entries[i].idx,
2744 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2745 status = dcerpc_samr_QueryAliasInfo(b, mem_ctx,
2750 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2751 status = dcerpc_samr_Close(b, mem_ctx,
2754 if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(_result)) {
2755 description = info->description.string;
2761 if (description != NULL) {
2762 printf("%-21.21s %-50.50s\n",
2763 groups->entries[i].name.string,
2766 printf("%s\n", groups->entries[i].name.string);
2769 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
2777 static int rpc_group_list(struct net_context *c, int argc, const char **argv)
2779 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
2780 rpc_group_list_internals,
2784 static NTSTATUS rpc_list_group_members(struct net_context *c,
2785 struct rpc_pipe_client *pipe_hnd,
2786 TALLOC_CTX *mem_ctx,
2787 const char *domain_name,
2788 const struct dom_sid *domain_sid,
2789 struct policy_handle *domain_pol,
2792 NTSTATUS result, status;
2793 struct policy_handle group_pol;
2794 uint32 num_members, *group_rids;
2796 struct samr_RidAttrArray *rids = NULL;
2797 struct lsa_Strings names;
2798 struct samr_Ids types;
2799 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
2802 sid_to_fstring(sid_str, domain_sid);
2804 status = dcerpc_samr_OpenGroup(b, mem_ctx,
2806 MAXIMUM_ALLOWED_ACCESS,
2810 if (!NT_STATUS_IS_OK(status)) {
2813 if (!NT_STATUS_IS_OK(result)) {
2817 status = dcerpc_samr_QueryGroupMember(b, mem_ctx,
2821 if (!NT_STATUS_IS_OK(status)) {
2824 if (!NT_STATUS_IS_OK(result)) {
2828 num_members = rids->count;
2829 group_rids = rids->rids;
2831 while (num_members > 0) {
2832 int this_time = 512;
2834 if (num_members < this_time)
2835 this_time = num_members;
2837 status = dcerpc_samr_LookupRids(b, mem_ctx,
2844 if (!NT_STATUS_IS_OK(status)) {
2847 if (!NT_STATUS_IS_OK(result)) {
2851 /* We only have users as members, but make the output
2852 the same as the output of alias members */
2854 for (i = 0; i < this_time; i++) {
2856 if (c->opt_long_list_entries) {
2857 printf("%s-%d %s\\%s %d\n", sid_str,
2858 group_rids[i], domain_name,
2859 names.names[i].string,
2862 printf("%s\\%s\n", domain_name,
2863 names.names[i].string);
2867 num_members -= this_time;
2871 return NT_STATUS_OK;
2874 static NTSTATUS rpc_list_alias_members(struct net_context *c,
2875 struct rpc_pipe_client *pipe_hnd,
2876 TALLOC_CTX *mem_ctx,
2877 struct policy_handle *domain_pol,
2881 struct rpc_pipe_client *lsa_pipe;
2882 struct policy_handle alias_pol, lsa_pol;
2884 struct dom_sid *alias_sids;
2887 enum lsa_SidType *types;
2889 struct lsa_SidArray sid_array;
2891 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2893 MAXIMUM_ALLOWED_ACCESS,
2897 if (!NT_STATUS_IS_OK(result))
2900 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
2904 if (!NT_STATUS_IS_OK(result)) {
2905 d_fprintf(stderr, _("Couldn't list alias members\n"));
2909 num_members = sid_array.num_sids;
2911 if (num_members == 0) {
2912 return NT_STATUS_OK;
2915 result = cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd),
2916 &ndr_table_lsarpc.syntax_id,
2918 if (!NT_STATUS_IS_OK(result)) {
2919 d_fprintf(stderr, _("Couldn't open LSA pipe. Error was %s\n"),
2920 nt_errstr(result) );
2924 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, true,
2925 SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol);
2927 if (!NT_STATUS_IS_OK(result)) {
2928 d_fprintf(stderr, _("Couldn't open LSA policy handle\n"));
2929 TALLOC_FREE(lsa_pipe);
2933 alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, struct dom_sid, num_members);
2935 d_fprintf(stderr, _("Out of memory\n"));
2936 TALLOC_FREE(lsa_pipe);
2937 return NT_STATUS_NO_MEMORY;
2940 for (i=0; i<num_members; i++) {
2941 sid_copy(&alias_sids[i], sid_array.sids[i].sid);
2944 result = rpccli_lsa_lookup_sids(lsa_pipe, mem_ctx, &lsa_pol,
2945 num_members, alias_sids,
2946 &domains, &names, &types);
2948 if (!NT_STATUS_IS_OK(result) &&
2949 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
2950 d_fprintf(stderr, _("Couldn't lookup SIDs\n"));
2951 TALLOC_FREE(lsa_pipe);
2955 for (i = 0; i < num_members; i++) {
2957 sid_to_fstring(sid_str, &alias_sids[i]);
2959 if (c->opt_long_list_entries) {
2960 printf("%s %s\\%s %d\n", sid_str,
2961 domains[i] ? domains[i] : _("*unknown*"),
2962 names[i] ? names[i] : _("*unknown*"), types[i]);
2965 printf("%s\\%s\n", domains[i], names[i]);
2967 printf("%s\n", sid_str);
2971 TALLOC_FREE(lsa_pipe);
2972 return NT_STATUS_OK;
2975 static NTSTATUS rpc_group_members_internals(struct net_context *c,
2976 const struct dom_sid *domain_sid,
2977 const char *domain_name,
2978 struct cli_state *cli,
2979 struct rpc_pipe_client *pipe_hnd,
2980 TALLOC_CTX *mem_ctx,
2985 struct policy_handle connect_pol, domain_pol;
2986 struct samr_Ids rids, rid_types;
2987 struct lsa_String lsa_acct_name;
2989 /* Get sam policy handle */
2991 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2993 MAXIMUM_ALLOWED_ACCESS,
2996 if (!NT_STATUS_IS_OK(result))
2999 /* Get domain policy handle */
3001 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
3003 MAXIMUM_ALLOWED_ACCESS,
3004 CONST_DISCARD(struct dom_sid2 *, domain_sid),
3007 if (!NT_STATUS_IS_OK(result))
3010 init_lsa_String(&lsa_acct_name, argv[0]); /* sure? */
3012 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
3019 if (!NT_STATUS_IS_OK(result)) {
3021 /* Ok, did not find it in the global sam, try with builtin */
3023 struct dom_sid sid_Builtin;
3025 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
3027 sid_copy(&sid_Builtin, &global_sid_Builtin);
3029 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
3031 MAXIMUM_ALLOWED_ACCESS,
3035 if (!NT_STATUS_IS_OK(result)) {
3036 d_fprintf(stderr, _("Couldn't find group %s\n"),
3041 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
3048 if (!NT_STATUS_IS_OK(result)) {
3049 d_fprintf(stderr, _("Couldn't find group %s\n"),
3055 if (rids.count != 1) {
3056 d_fprintf(stderr, _("Couldn't find group %s\n"),
3061 if (rid_types.ids[0] == SID_NAME_DOM_GRP) {
3062 return rpc_list_group_members(c, pipe_hnd, mem_ctx, domain_name,
3063 domain_sid, &domain_pol,
3067 if (rid_types.ids[0] == SID_NAME_ALIAS) {
3068 return rpc_list_alias_members(c, pipe_hnd, mem_ctx, &domain_pol,
3072 return NT_STATUS_NO_SUCH_GROUP;
3075 static int rpc_group_members(struct net_context *c, int argc, const char **argv)
3077 if (argc != 1 || c->display_usage) {
3078 return rpc_group_usage(c, argc, argv);
3081 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
3082 rpc_group_members_internals,
3086 static int rpc_group_rename_internals(struct net_context *c, int argc, const char **argv)
3088 NET_API_STATUS status;
3089 struct GROUP_INFO_0 g0;
3093 d_printf(_("Usage:\n"));
3094 d_printf("net rpc group rename group newname\n");
3098 g0.grpi0_name = argv[1];
3100 status = NetGroupSetInfo(c->opt_host,
3107 d_fprintf(stderr, _("Renaming group %s failed with: %s\n"),
3108 argv[0], libnetapi_get_error_string(c->netapi_ctx,
3116 static int rpc_group_rename(struct net_context *c, int argc, const char **argv)
3118 if (argc != 2 || c->display_usage) {
3119 return rpc_group_usage(c, argc, argv);
3122 return rpc_group_rename_internals(c, argc, argv);
3126 * 'net rpc group' entrypoint.
3127 * @param argc Standard main() style argc.
3128 * @param argv Standard main() style argv. Initial components are already
3132 int net_rpc_group(struct net_context *c, int argc, const char **argv)
3134 NET_API_STATUS status;
3136 struct functable func[] = {
3141 N_("Create specified group"),
3142 N_("net rpc group add\n"
3143 " Create specified group")
3149 N_("Delete specified group"),
3150 N_("net rpc group delete\n"
3151 " Delete specified group")
3157 N_("Add member to group"),
3158 N_("net rpc group addmem\n"
3159 " Add member to group")
3165 N_("Remove member from group"),
3166 N_("net rpc group delmem\n"
3167 " Remove member from group")
3174 N_("net rpc group list\n"
3181 N_("List group members"),
3182 N_("net rpc group members\n"
3183 " List group members")
3190 N_("net rpc group rename\n"
3193 {NULL, NULL, 0, NULL, NULL}
3196 status = libnetapi_net_init(&c->netapi_ctx);
3200 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
3201 libnetapi_set_password(c->netapi_ctx, c->opt_password);
3202 if (c->opt_kerberos) {
3203 libnetapi_set_use_kerberos(c->netapi_ctx);
3207 if (c->display_usage) {
3208 d_printf(_("Usage:\n"));
3209 d_printf(_("net rpc group\n"
3210 " Alias for net rpc group list global "
3211 "local builtin\n"));
3212 net_display_usage_from_functable(func);
3216 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
3217 rpc_group_list_internals,
3221 return net_run_function(c, argc, argv, "net rpc group", func);
3224 /****************************************************************************/
3226 static int rpc_share_usage(struct net_context *c, int argc, const char **argv)
3228 return net_share_usage(c, argc, argv);
3232 * Add a share on a remote RPC server.
3234 * @param argc Standard main() style argc.
3235 * @param argv Standard main() style argv. Initial components are already
3238 * @return A shell status integer (0 for success).
3241 static int rpc_share_add(struct net_context *c, int argc, const char **argv)
3243 NET_API_STATUS status;
3246 uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
3247 uint32 num_users=0, perms=0;
3248 char *password=NULL; /* don't allow a share password */
3249 struct SHARE_INFO_2 i2;
3250 uint32_t parm_error = 0;
3252 if ((argc < 1) || !strchr(argv[0], '=') || c->display_usage) {
3253 return rpc_share_usage(c, argc, argv);
3256 if ((sharename = talloc_strdup(c, argv[0])) == NULL) {
3260 path = strchr(sharename, '=');
3267 i2.shi2_netname = sharename;
3268 i2.shi2_type = type;
3269 i2.shi2_remark = c->opt_comment;
3270 i2.shi2_permissions = perms;
3271 i2.shi2_max_uses = c->opt_maxusers;
3272 i2.shi2_current_uses = num_users;
3273 i2.shi2_path = path;
3274 i2.shi2_passwd = password;
3276 status = NetShareAdd(c->opt_host,
3281 printf(_("NetShareAdd failed with: %s\n"),
3282 libnetapi_get_error_string(c->netapi_ctx, status));
3289 * Delete a share on a remote RPC server.
3291 * @param domain_sid The domain sid acquired from the remote server.
3292 * @param argc Standard main() style argc.
3293 * @param argv Standard main() style argv. Initial components are already
3296 * @return A shell status integer (0 for success).
3298 static int rpc_share_delete(struct net_context *c, int argc, const char **argv)
3300 if (argc < 1 || c->display_usage) {
3301 return rpc_share_usage(c, argc, argv);
3304 return NetShareDel(c->opt_host, argv[0], 0);
3308 * Formatted print of share info
3310 * @param r pointer to SHARE_INFO_1 to format
3313 static void display_share_info_1(struct net_context *c,
3314 struct SHARE_INFO_1 *r)
3316 if (c->opt_long_list_entries) {
3317 d_printf("%-12s %-8.8s %-50s\n",
3319 net_share_type_str(r->shi1_type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)),
3322 d_printf("%s\n", r->shi1_netname);
3326 static WERROR get_share_info(struct net_context *c,
3327 struct rpc_pipe_client *pipe_hnd,
3328 TALLOC_CTX *mem_ctx,
3332 struct srvsvc_NetShareInfoCtr *info_ctr)
3336 union srvsvc_NetShareInfo info;
3337 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
3339 /* no specific share requested, enumerate all */
3342 uint32_t preferred_len = 0xffffffff;
3343 uint32_t total_entries = 0;
3344 uint32_t resume_handle = 0;
3346 info_ctr->level = level;
3348 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
3355 if (!NT_STATUS_IS_OK(status)) {
3356 return ntstatus_to_werror(status);
3361 /* request just one share */
3362 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
3369 if (!NT_STATUS_IS_OK(status)) {
3370 result = ntstatus_to_werror(status);
3374 if (!W_ERROR_IS_OK(result)) {
3379 ZERO_STRUCTP(info_ctr);
3381 info_ctr->level = level;
3386 struct srvsvc_NetShareCtr1 *ctr1;
3388 ctr1 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr1);
3389 W_ERROR_HAVE_NO_MEMORY(ctr1);
3392 ctr1->array = info.info1;
3394 info_ctr->ctr.ctr1 = ctr1;
3400 struct srvsvc_NetShareCtr2 *ctr2;
3402 ctr2 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr2);
3403 W_ERROR_HAVE_NO_MEMORY(ctr2);
3406 ctr2->array = info.info2;
3408 info_ctr->ctr.ctr2 = ctr2;
3414 struct srvsvc_NetShareCtr502 *ctr502;
3416 ctr502 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr502);
3417 W_ERROR_HAVE_NO_MEMORY(ctr502);
3420 ctr502->array = info.info502;
3422 info_ctr->ctr.ctr502 = ctr502;
3432 * 'net rpc share list' entrypoint.
3433 * @param argc Standard main() style argc.
3434 * @param argv Standard main() style argv. Initial components are already
3437 static int rpc_share_list(struct net_context *c, int argc, const char **argv)
3439 NET_API_STATUS status;
3440 struct SHARE_INFO_1 *i1 = NULL;
3441 uint32_t entries_read = 0;
3442 uint32_t total_entries = 0;
3443 uint32_t resume_handle = 0;
3444 uint32_t i, level = 1;
3446 if (c->display_usage) {
3448 "net rpc share list\n"
3451 _("List shares on remote server"));
3455 status = NetShareEnum(c->opt_host,
3457 (uint8_t **)(void *)&i1,
3466 /* Display results */
3468 if (c->opt_long_list_entries) {
3470 "\nEnumerating shared resources (exports) on remote server:\n\n"
3471 "\nShare name Type Description\n"
3472 "---------- ---- -----------\n"));
3474 for (i = 0; i < entries_read; i++)
3475 display_share_info_1(c, &i1[i]);
3480 static bool check_share_availability(struct cli_state *cli, const char *netname)
3484 status = cli_tcon_andx(cli, netname, "A:", "", 0);
3485 if (!NT_STATUS_IS_OK(status)) {
3486 d_printf(_("skipping [%s]: not a file share.\n"), netname);
3490 status = cli_tdis(cli);
3491 if (!NT_STATUS_IS_OK(status)) {
3492 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status));
3499 static bool check_share_sanity(struct net_context *c, struct cli_state *cli,
3500 const char *netname, uint32 type)
3502 /* only support disk shares */
3503 if (! ( type == STYPE_DISKTREE || type == (STYPE_DISKTREE | STYPE_HIDDEN)) ) {
3504 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname,
3509 /* skip builtin shares */
3510 /* FIXME: should print$ be added too ? */
3511 if (strequal(netname,"IPC$") || strequal(netname,"ADMIN$") ||
3512 strequal(netname,"global"))
3515 if (c->opt_exclude && in_list(netname, c->opt_exclude, false)) {
3516 printf(_("excluding [%s]\n"), netname);
3520 return check_share_availability(cli, netname);
3524 * Migrate shares from a remote RPC server to the local RPC server.
3526 * All parameters are provided by the run_rpc_command function, except for
3527 * argc, argv which are passed through.
3529 * @param domain_sid The domain sid acquired from the remote server.
3530 * @param cli A cli_state connected to the server.
3531 * @param mem_ctx Talloc context, destroyed on completion of the function.
3532 * @param argc Standard main() style argc.
3533 * @param argv Standard main() style argv. Initial components are already
3536 * @return Normal NTSTATUS return.
3539 static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c,
3540 const struct dom_sid *domain_sid,
3541 const char *domain_name,
3542 struct cli_state *cli,
3543 struct rpc_pipe_client *pipe_hnd,
3544 TALLOC_CTX *mem_ctx,
3549 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3550 struct srvsvc_NetShareInfoCtr ctr_src;
3552 struct rpc_pipe_client *srvsvc_pipe = NULL;
3553 struct cli_state *cli_dst = NULL;
3554 uint32 level = 502; /* includes secdesc */
3555 uint32_t parm_error = 0;
3556 struct dcerpc_binding_handle *b;
3558 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3560 if (!W_ERROR_IS_OK(result))
3563 /* connect destination PI_SRVSVC */
3564 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe,
3565 &ndr_table_srvsvc.syntax_id);
3566 if (!NT_STATUS_IS_OK(nt_status))
3569 b = srvsvc_pipe->binding_handle;
3571 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3573 union srvsvc_NetShareInfo info;
3574 struct srvsvc_NetShareInfo502 info502 =
3575 ctr_src.ctr.ctr502->array[i];
3577 /* reset error-code */
3578 nt_status = NT_STATUS_UNSUCCESSFUL;
3580 if (!check_share_sanity(c, cli, info502.name, info502.type))
3583 /* finally add the share on the dst server */
3585 printf(_("migrating: [%s], path: %s, comment: %s, without "
3587 info502.name, info502.path, info502.comment);
3589 info.info502 = &info502;
3591 nt_status = dcerpc_srvsvc_NetShareAdd(b, mem_ctx,
3592 srvsvc_pipe->desthost,
3597 if (!NT_STATUS_IS_OK(nt_status)) {
3598 printf(_("cannot add share: %s\n"),
3599 nt_errstr(nt_status));
3602 if (W_ERROR_V(result) == W_ERROR_V(WERR_FILE_EXISTS)) {
3603 printf(_(" [%s] does already exist\n"),
3608 if (!W_ERROR_IS_OK(result)) {
3609 nt_status = werror_to_ntstatus(result);
3610 printf(_("cannot add share: %s\n"),
3611 win_errstr(result));
3617 nt_status = NT_STATUS_OK;
3621 cli_shutdown(cli_dst);
3629 * Migrate shares from a RPC server to another.
3631 * @param argc Standard main() style argc.
3632 * @param argv Standard main() style argv. Initial components are already
3635 * @return A shell status integer (0 for success).
3637 static int rpc_share_migrate_shares(struct net_context *c, int argc,
3640 if (c->display_usage) {
3642 "net rpc share migrate shares\n"
3645 _("Migrate shares to local server"));
3650 printf(_("no server to migrate\n"));
3654 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3655 rpc_share_migrate_shares_internals,
3662 * @param f file_info
3663 * @param mask current search mask
3664 * @param state arg-pointer
3667 static NTSTATUS copy_fn(const char *mnt, struct file_info *f,
3668 const char *mask, void *state)
3670 static NTSTATUS nt_status;
3671 static struct copy_clistate *local_state;
3672 static fstring filename, new_mask;
3675 struct net_context *c;
3677 local_state = (struct copy_clistate *)state;
3678 nt_status = NT_STATUS_UNSUCCESSFUL;
3682 if (strequal(f->name, ".") || strequal(f->name, ".."))
3683 return NT_STATUS_OK;
3685 DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
3688 if (f->mode & aDIR) {
3690 DEBUG(3,("got dir: %s\n", f->name));
3692 fstrcpy(dir, local_state->cwd);
3694 fstrcat(dir, f->name);
3696 switch (net_mode_share)
3698 case NET_MODE_SHARE_MIGRATE:
3699 /* create that directory */
3700 nt_status = net_copy_file(c, local_state->mem_ctx,
3701 local_state->cli_share_src,
3702 local_state->cli_share_dst,
3704 c->opt_acls? true : false,
3705 c->opt_attrs? true : false,
3706 c->opt_timestamps? true:false,
3710 d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
3711 return NT_STATUS_INTERNAL_ERROR;
3714 if (!NT_STATUS_IS_OK(nt_status)) {
3715 printf(_("could not handle dir %s: %s\n"),
3716 dir, nt_errstr(nt_status));
3720 /* search below that directory */
3721 fstrcpy(new_mask, dir);
3722 fstrcat(new_mask, "\\*");
3724 old_dir = local_state->cwd;
3725 local_state->cwd = dir;
3726 nt_status = sync_files(local_state, new_mask);
3727 if (!NT_STATUS_IS_OK(nt_status)) {
3728 printf(_("could not handle files\n"));
3730 local_state->cwd = old_dir;
3737 fstrcpy(filename, local_state->cwd);
3738 fstrcat(filename, "\\");
3739 fstrcat(filename, f->name);
3741 DEBUG(3,("got file: %s\n", filename));
3743 switch (net_mode_share)
3745 case NET_MODE_SHARE_MIGRATE:
3746 nt_status = net_copy_file(c, local_state->mem_ctx,
3747 local_state->cli_share_src,
3748 local_state->cli_share_dst,
3750 c->opt_acls? true : false,
3751 c->opt_attrs? true : false,
3752 c->opt_timestamps? true: false,
3756 d_fprintf(stderr, _("Unsupported file mode %d\n"),
3758 return NT_STATUS_INTERNAL_ERROR;
3761 if (!NT_STATUS_IS_OK(nt_status))
3762 printf(_("could not handle file %s: %s\n"),
3763 filename, nt_errstr(nt_status));
3768 * sync files, can be called recursivly to list files
3769 * and then call copy_fn for each file
3771 * @param cp_clistate pointer to the copy_clistate we work with
3772 * @param mask the current search mask
3774 * @return Boolean result
3776 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask)
3778 struct cli_state *targetcli;
3779 char *targetpath = NULL;
3782 DEBUG(3,("calling cli_list with mask: %s\n", mask));
3784 if ( !cli_resolve_path(talloc_tos(), "", NULL, cp_clistate->cli_share_src,
3785 mask, &targetcli, &targetpath ) ) {
3786 d_fprintf(stderr, _("cli_resolve_path %s failed with error: "
3788 mask, cli_errstr(cp_clistate->cli_share_src));
3789 return cli_nt_error(cp_clistate->cli_share_src);
3792 status = cli_list(targetcli, targetpath, cp_clistate->attribute,
3793 copy_fn, cp_clistate);
3794 if (!NT_STATUS_IS_OK(status)) {
3795 d_fprintf(stderr, _("listing %s failed with error: %s\n"),
3796 mask, nt_errstr(status));
3804 * Set the top level directory permissions before we do any further copies.
3805 * Should set up ACL inheritance.
3808 bool copy_top_level_perms(struct net_context *c,
3809 struct copy_clistate *cp_clistate,
3810 const char *sharename)
3812 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3814 switch (net_mode_share) {
3815 case NET_MODE_SHARE_MIGRATE:
3816 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename));
3817 nt_status = net_copy_fileattr(c,
3818 cp_clistate->mem_ctx,
3819 cp_clistate->cli_share_src,
3820 cp_clistate->cli_share_dst,
3822 c->opt_acls? true : false,
3823 c->opt_attrs? true : false,
3824 c->opt_timestamps? true: false,
3828 d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
3832 if (!NT_STATUS_IS_OK(nt_status)) {
3833 printf(_("Could handle directory attributes for top level "
3834 "directory of share %s. Error %s\n"),
3835 sharename, nt_errstr(nt_status));
3843 * Sync all files inside a remote share to another share (over smb).
3845 * All parameters are provided by the run_rpc_command function, except for
3846 * argc, argv which are passed through.
3848 * @param domain_sid The domain sid acquired from the remote server.
3849 * @param cli A cli_state connected to the server.
3850 * @param mem_ctx Talloc context, destroyed on completion of the function.
3851 * @param argc Standard main() style argc.
3852 * @param argv Standard main() style argv. Initial components are already
3855 * @return Normal NTSTATUS return.
3858 static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c,
3859 const struct dom_sid *domain_sid,
3860 const char *domain_name,
3861 struct cli_state *cli,
3862 struct rpc_pipe_client *pipe_hnd,
3863 TALLOC_CTX *mem_ctx,
3868 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3869 struct srvsvc_NetShareInfoCtr ctr_src;
3872 struct copy_clistate cp_clistate;
3873 bool got_src_share = false;
3874 bool got_dst_share = false;
3875 const char *mask = "\\*";
3878 dst = SMB_STRDUP(c->opt_destination?c->opt_destination:"127.0.0.1");
3880 nt_status = NT_STATUS_NO_MEMORY;
3884 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3887 if (!W_ERROR_IS_OK(result))
3890 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3892 struct srvsvc_NetShareInfo502 info502 =
3893 ctr_src.ctr.ctr502->array[i];
3895 if (!check_share_sanity(c, cli, info502.name, info502.type))
3898 /* one might not want to mirror whole discs :) */
3899 if (strequal(info502.name, "print$") || info502.name[1] == '$') {
3900 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3905 switch (net_mode_share)
3907 case NET_MODE_SHARE_MIGRATE:
3911 d_fprintf(stderr, _("Unsupported mode %d\n"),
3915 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3918 c->opt_acls ? _("including") : _("without"),
3919 c->opt_attrs ? _("including") : _("without"),
3920 c->opt_timestamps ? _("(preserving timestamps)") : "");
3922 cp_clistate.mem_ctx = mem_ctx;
3923 cp_clistate.cli_share_src = NULL;
3924 cp_clistate.cli_share_dst = NULL;
3925 cp_clistate.cwd = NULL;
3926 cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;
3929 /* open share source */
3930 nt_status = connect_to_service(c, &cp_clistate.cli_share_src,
3931 &cli->dest_ss, cli->desthost,
3932 info502.name, "A:");
3933 if (!NT_STATUS_IS_OK(nt_status))
3936 got_src_share = true;
3938 if (net_mode_share == NET_MODE_SHARE_MIGRATE) {
3939 /* open share destination */
3940 nt_status = connect_to_service(c, &cp_clistate.cli_share_dst,
3941 NULL, dst, info502.name, "A:");
3942 if (!NT_STATUS_IS_OK(nt_status))
3945 got_dst_share = true;
3948 if (!copy_top_level_perms(c, &cp_clistate, info502.name)) {
3949 d_fprintf(stderr, _("Could not handle the top level "
3950 "directory permissions for the "
3951 "share: %s\n"), info502.name);
3952 nt_status = NT_STATUS_UNSUCCESSFUL;
3956 nt_status = sync_files(&cp_clistate, mask);
3957 if (!NT_STATUS_IS_OK(nt_status)) {
3958 d_fprintf(stderr, _("could not handle files for share: "
3959 "%s\n"), info502.name);
3964 nt_status = NT_STATUS_OK;
3969 cli_shutdown(cp_clistate.cli_share_src);
3972 cli_shutdown(cp_clistate.cli_share_dst);
3979 static int rpc_share_migrate_files(struct net_context *c, int argc, const char **argv)
3981 if (c->display_usage) {
3983 "net share migrate files\n"
3986 _("Migrate files to local server"));
3991 d_printf(_("no server to migrate\n"));
3995 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3996 rpc_share_migrate_files_internals,
4001 * Migrate share-ACLs from a remote RPC server to the local RPC server.
4003 * All parameters are provided by the run_rpc_command function, except for
4004 * argc, argv which are passed through.
4006 * @param domain_sid The domain sid acquired from the remote server.
4007 * @param cli A cli_state connected to the server.
4008 * @param mem_ctx Talloc context, destroyed on completion of the function.
4009 * @param argc Standard main() style argc.
4010 * @param argv Standard main() style argv. Initial components are already
4013 * @return Normal NTSTATUS return.
4016 static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c,
4017 const struct dom_sid *domain_sid,
4018 const char *domain_name,
4019 struct cli_state *cli,
4020 struct rpc_pipe_client *pipe_hnd,
4021 TALLOC_CTX *mem_ctx,
4026 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
4027 struct srvsvc_NetShareInfoCtr ctr_src;
4028 union srvsvc_NetShareInfo info;
4030 struct rpc_pipe_client *srvsvc_pipe = NULL;
4031 struct cli_state *cli_dst = NULL;
4032 uint32 level = 502; /* includes secdesc */
4033 uint32_t parm_error = 0;
4034 struct dcerpc_binding_handle *b;
4036 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
4039 if (!W_ERROR_IS_OK(result))
4042 /* connect destination PI_SRVSVC */
4043 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe,
4044 &ndr_table_srvsvc.syntax_id);
4045 if (!NT_STATUS_IS_OK(nt_status))
4048 b = srvsvc_pipe->binding_handle;
4050 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
4052 struct srvsvc_NetShareInfo502 info502 =
4053 ctr_src.ctr.ctr502->array[i];
4055 /* reset error-code */
4056 nt_status = NT_STATUS_UNSUCCESSFUL;
4058 if (!check_share_sanity(c, cli, info502.name, info502.type))
4061 printf(_("migrating: [%s], path: %s, comment: %s, including "
4063 info502.name, info502.path, info502.comment);
4066 display_sec_desc(info502.sd_buf.sd);
4068 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4069 info.info502 = &info502;
4071 /* finally modify the share on the dst server */
4072 nt_status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
4073 srvsvc_pipe->desthost,
4079 if (!NT_STATUS_IS_OK(nt_status)) {
4080 printf(_("cannot set share-acl: %s\n"),
4081 nt_errstr(nt_status));
4084 if (!W_ERROR_IS_OK(result)) {
4085 nt_status = werror_to_ntstatus(result);
4086 printf(_("cannot set share-acl: %s\n"),
4087 win_errstr(result));
4093 nt_status = NT_STATUS_OK;
4097 cli_shutdown(cli_dst);
4105 * Migrate share-acls from a RPC server to another.
4107 * @param argc Standard main() style argc.
4108 * @param argv Standard main() style argv. Initial components are already
4111 * @return A shell status integer (0 for success).
4113 static int rpc_share_migrate_security(struct net_context *c, int argc,
4116 if (c->display_usage) {
4118 "net rpc share migrate security\n"
4121 _("Migrate share-acls to local server"));
4126 d_printf(_("no server to migrate\n"));
4130 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4131 rpc_share_migrate_security_internals,
4136 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4137 * from one server to another.
4139 * @param argc Standard main() style argc.
4140 * @param argv Standard main() style argv. Initial components are already
4143 * @return A shell status integer (0 for success).
4146 static int rpc_share_migrate_all(struct net_context *c, int argc,
4151 if (c->display_usage) {
4153 "net rpc share migrate all\n"
4156 _("Migrates shares including all share settings"));
4161 d_printf(_("no server to migrate\n"));
4165 /* order is important. we don't want to be locked out by the share-acl
4166 * before copying files - gd */
4168 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4169 rpc_share_migrate_shares_internals, argc, argv);
4173 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4174 rpc_share_migrate_files_internals, argc, argv);
4178 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4179 rpc_share_migrate_security_internals, argc,
4185 * 'net rpc share migrate' entrypoint.
4186 * @param argc Standard main() style argc.
4187 * @param argv Standard main() style argv. Initial components are already
4190 static int rpc_share_migrate(struct net_context *c, int argc, const char **argv)
4193 struct functable func[] = {
4196 rpc_share_migrate_all,
4198 N_("Migrate shares from remote to local server"),
4199 N_("net rpc share migrate all\n"
4200 " Migrate shares from remote to local server")
4204 rpc_share_migrate_files,
4206 N_("Migrate files from remote to local server"),
4207 N_("net rpc share migrate files\n"
4208 " Migrate files from remote to local server")
4212 rpc_share_migrate_security,
4214 N_("Migrate share-ACLs from remote to local server"),
4215 N_("net rpc share migrate security\n"
4216 " Migrate share-ACLs from remote to local server")
4220 rpc_share_migrate_shares,
4222 N_("Migrate shares from remote to local server"),
4223 N_("net rpc share migrate shares\n"
4224 " Migrate shares from remote to local server")
4226 {NULL, NULL, 0, NULL, NULL}
4229 net_mode_share = NET_MODE_SHARE_MIGRATE;
4231 return net_run_function(c, argc, argv, "net rpc share migrate", func);
4237 struct dom_sid *members;
4240 static int num_server_aliases;
4241 static struct full_alias *server_aliases;
4244 * Add an alias to the static list.
4246 static void push_alias(TALLOC_CTX *mem_ctx, struct full_alias *alias)
4248 if (server_aliases == NULL)
4249 server_aliases = SMB_MALLOC_ARRAY(struct full_alias, 100);
4251 server_aliases[num_server_aliases] = *alias;
4252 num_server_aliases += 1;
4256 * For a specific domain on the server, fetch all the aliases
4257 * and their members. Add all of them to the server_aliases.
4260 static NTSTATUS rpc_fetch_domain_aliases(struct rpc_pipe_client *pipe_hnd,
4261 TALLOC_CTX *mem_ctx,
4262 struct policy_handle *connect_pol,
4263 const struct dom_sid *domain_sid)
4265 uint32 start_idx, max_entries, num_entries, i;
4266 struct samr_SamArray *groups = NULL;
4268 struct policy_handle domain_pol;
4270 /* Get domain policy handle */
4272 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
4274 MAXIMUM_ALLOWED_ACCESS,
4275 CONST_DISCARD(struct dom_sid2 *, domain_sid),
4277 if (!NT_STATUS_IS_OK(result))
4284 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
4290 for (i = 0; i < num_entries; i++) {
4292 struct policy_handle alias_pol;
4293 struct full_alias alias;
4294 struct lsa_SidArray sid_array;
4297 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
4299 MAXIMUM_ALLOWED_ACCESS,
4300 groups->entries[i].idx,
4302 if (!NT_STATUS_IS_OK(result))
4305 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
4308 if (!NT_STATUS_IS_OK(result))
4311 alias.num_members = sid_array.num_sids;
4313 result = rpccli_samr_Close(pipe_hnd, mem_ctx, &alias_pol);
4314 if (!NT_STATUS_IS_OK(result))
4317 alias.members = NULL;
4319 if (alias.num_members > 0) {
4320 alias.members = SMB_MALLOC_ARRAY(struct dom_sid, alias.num_members);
4322 for (j = 0; j < alias.num_members; j++)
4323 sid_copy(&alias.members[j],
4324 sid_array.sids[j].sid);
4327 sid_compose(&alias.sid, domain_sid,
4328 groups->entries[i].idx);
4330 push_alias(mem_ctx, &alias);
4332 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
4334 result = NT_STATUS_OK;
4337 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
4343 * Dump server_aliases as names for debugging purposes.
4346 static NTSTATUS rpc_aliaslist_dump(struct net_context *c,
4347 const struct dom_sid *domain_sid,
4348 const char *domain_name,
4349 struct cli_state *cli,
4350 struct rpc_pipe_client *pipe_hnd,
4351 TALLOC_CTX *mem_ctx,
4357 struct policy_handle lsa_pol;
4359 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
4360 SEC_FLAG_MAXIMUM_ALLOWED,
4362 if (!NT_STATUS_IS_OK(result))
4365 for (i=0; i<num_server_aliases; i++) {
4368 enum lsa_SidType *types;
4371 struct full_alias *alias = &server_aliases[i];
4373 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol, 1,
4375 &domains, &names, &types);
4376 if (!NT_STATUS_IS_OK(result))
4379 DEBUG(1, ("%s\\%s %d: ", domains[0], names[0], types[0]));
4381 if (alias->num_members == 0) {
4386 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol,
4389 &domains, &names, &types);
4391 if (!NT_STATUS_IS_OK(result) &&
4392 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
4395 for (j=0; j<alias->num_members; j++)
4396 DEBUG(1, ("%s\\%s (%d); ",
4397 domains[j] ? domains[j] : "*unknown*",
4398 names[j] ? names[j] : "*unknown*",types[j]));
4402 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
4404 return NT_STATUS_OK;
4408 * Fetch a list of all server aliases and their members into
4412 static NTSTATUS rpc_aliaslist_internals(struct net_context *c,
4413 const struct dom_sid *domain_sid,
4414 const char *domain_name,
4415 struct cli_state *cli,
4416 struct rpc_pipe_client *pipe_hnd,
4417 TALLOC_CTX *mem_ctx,
4422 struct policy_handle connect_pol;
4424 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
4426 MAXIMUM_ALLOWED_ACCESS,
4429 if (!NT_STATUS_IS_OK(result))
4432 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4433 &global_sid_Builtin);
4435 if (!NT_STATUS_IS_OK(result))
4438 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4441 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
4446 static void init_user_token(struct security_token *token, struct dom_sid *user_sid)
4448 token->num_sids = 4;
4450 if (!(token->sids = SMB_MALLOC_ARRAY(struct dom_sid, 4))) {
4451 d_fprintf(stderr, "malloc %s\n",_("failed"));
4452 token->num_sids = 0;
4456 token->sids[0] = *user_sid;
4457 sid_copy(&token->sids[1], &global_sid_World);
4458 sid_copy(&token->sids[2], &global_sid_Network);
4459 sid_copy(&token->sids[3], &global_sid_Authenticated_Users);
4462 static void free_user_token(struct security_token *token)
4464 SAFE_FREE(token->sids);
4467 static void add_sid_to_token(struct security_token *token, struct dom_sid *sid)
4469 if (security_token_has_sid(token, sid))
4472 token->sids = SMB_REALLOC_ARRAY(token->sids, struct dom_sid, token->num_sids+1);
4477 sid_copy(&token->sids[token->num_sids], sid);
4479 token->num_sids += 1;
4484 struct security_token token;
4487 static void dump_user_token(struct user_token *token)
4491 d_printf("%s\n", token->name);
4493 for (i=0; i<token->token.num_sids; i++) {
4494 d_printf(" %s\n", sid_string_tos(&token->token.sids[i]));
4498 static bool is_alias_member(struct dom_sid *sid, struct full_alias *alias)
4502 for (i=0; i<alias->num_members; i++) {
4503 if (dom_sid_compare(sid, &alias->members[i]) == 0)
4510 static void collect_sid_memberships(struct security_token *token, struct dom_sid sid)
4514 for (i=0; i<num_server_aliases; i++) {
4515 if (is_alias_member(&sid, &server_aliases[i]))
4516 add_sid_to_token(token, &server_aliases[i].sid);
4521 * We got a user token with all the SIDs we can know about without asking the
4522 * server directly. These are the user and domain group sids. All of these can
4523 * be members of aliases. So scan the list of aliases for each of the SIDs and
4524 * add them to the token.
4527 static void collect_alias_memberships(struct security_token *token)
4529 int num_global_sids = token->num_sids;
4532 for (i=0; i<num_global_sids; i++) {
4533 collect_sid_memberships(token, token->sids[i]);
4537 static bool get_user_sids(const char *domain, const char *user, struct security_token *token)
4539 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4540 enum wbcSidType type;
4542 struct wbcDomainSid wsid;
4543 char *sid_str = NULL;
4544 struct dom_sid user_sid;
4545 uint32_t num_groups;
4546 gid_t *groups = NULL;
4549 fstr_sprintf(full_name, "%s%c%s",
4550 domain, *lp_winbind_separator(), user);
4552 /* First let's find out the user sid */
4554 wbc_status = wbcLookupName(domain, user, &wsid, &type);
4556 if (!WBC_ERROR_IS_OK(wbc_status)) {
4557 DEBUG(1, ("winbind could not find %s: %s\n",
4558 full_name, wbcErrorString(wbc_status)));
4562 wbc_status = wbcSidToString(&wsid, &sid_str);
4563 if (!WBC_ERROR_IS_OK(wbc_status)) {
4567 if (type != WBC_SID_NAME_USER) {
4568 wbcFreeMemory(sid_str);
4569 DEBUG(1, ("%s is not a user\n", full_name));
4573 if (!string_to_sid(&user_sid, sid_str)) {
4574 DEBUG(1,("Could not convert sid %s from string\n", sid_str));
4578 wbcFreeMemory(sid_str);
4581 init_user_token(token, &user_sid);
4583 /* And now the groups winbind knows about */
4585 wbc_status = wbcGetGroups(full_name, &num_groups, &groups);
4586 if (!WBC_ERROR_IS_OK(wbc_status)) {
4587 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4588 full_name, wbcErrorString(wbc_status)));
4592 for (i = 0; i < num_groups; i++) {
4593 gid_t gid = groups[i];
4596 wbc_status = wbcGidToSid(gid, &wsid);
4597 if (!WBC_ERROR_IS_OK(wbc_status)) {
4598 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4599 (unsigned int)gid, wbcErrorString(wbc_status)));
4600 wbcFreeMemory(groups);
4604 wbc_status = wbcSidToString(&wsid, &sid_str);
4605 if (!WBC_ERROR_IS_OK(wbc_status)) {
4606 wbcFreeMemory(groups);
4610 DEBUG(3, (" %s\n", sid_str));
4612 string_to_sid(&sid, sid_str);
4613 wbcFreeMemory(sid_str);
4616 add_sid_to_token(token, &sid);
4618 wbcFreeMemory(groups);
4624 * Get a list of all user tokens we want to look at
4627 static bool get_user_tokens(struct net_context *c, int *num_tokens,
4628 struct user_token **user_tokens)
4630 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4631 uint32_t i, num_users;
4633 struct user_token *result;
4634 TALLOC_CTX *frame = NULL;
4636 if (lp_winbind_use_default_domain() &&
4637 (c->opt_target_workgroup == NULL)) {
4638 d_fprintf(stderr, _("winbind use default domain = yes set, "
4639 "please specify a workgroup\n"));
4643 /* Send request to winbind daemon */
4645 wbc_status = wbcListUsers(NULL, &num_users, &users);
4646 if (!WBC_ERROR_IS_OK(wbc_status)) {
4647 DEBUG(1, (_("winbind could not list users: %s\n"),
4648 wbcErrorString(wbc_status)));
4652 result = SMB_MALLOC_ARRAY(struct user_token, num_users);
4654 if (result == NULL) {
4655 DEBUG(1, ("Could not malloc sid array\n"));
4656 wbcFreeMemory(users);
4660 frame = talloc_stackframe();
4661 for (i=0; i < num_users; i++) {
4662 fstring domain, user;
4665 fstrcpy(result[i].name, users[i]);
4667 p = strchr(users[i], *lp_winbind_separator());
4669 DEBUG(3, ("%s\n", users[i]));
4672 fstrcpy(domain, c->opt_target_workgroup);
4673 fstrcpy(user, users[i]);
4676 fstrcpy(domain, users[i]);
4681 get_user_sids(domain, user, &(result[i].token));
4684 wbcFreeMemory(users);
4686 *num_tokens = num_users;
4687 *user_tokens = result;
4692 static bool get_user_tokens_from_file(FILE *f,
4694 struct user_token **tokens)
4696 struct user_token *token = NULL;
4701 if (fgets(line, sizeof(line)-1, f) == NULL) {
4705 if ((strlen(line) > 0) && (line[strlen(line)-1] == '\n')) {
4706 line[strlen(line)-1] = '\0';
4709 if (line[0] == ' ') {
4713 if(!string_to_sid(&sid, &line[1])) {
4714 DEBUG(1,("get_user_tokens_from_file: Could "
4715 "not convert sid %s \n",&line[1]));
4719 if (token == NULL) {
4720 DEBUG(0, ("File does not begin with username"));
4724 add_sid_to_token(&token->token, &sid);
4728 /* And a new user... */
4731 *tokens = SMB_REALLOC_ARRAY(*tokens, struct user_token, *num_tokens);
4732 if (*tokens == NULL) {
4733 DEBUG(0, ("Could not realloc tokens\n"));
4737 token = &((*tokens)[*num_tokens-1]);
4739 fstrcpy(token->name, line);
4740 token->token.num_sids = 0;
4741 token->token.sids = NULL;
4750 * Show the list of all users that have access to a share
4753 static void show_userlist(struct rpc_pipe_client *pipe_hnd,
4754 TALLOC_CTX *mem_ctx,
4755 const char *netname,
4757 struct user_token *tokens)
4760 struct security_descriptor *share_sd = NULL;
4761 struct security_descriptor *root_sd = NULL;
4762 struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd);
4764 union srvsvc_NetShareInfo info;
4768 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
4770 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
4777 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
4778 DEBUG(1, ("Coult not query secdesc for share %s\n",
4783 share_sd = info.info502->sd_buf.sd;
4784 if (share_sd == NULL) {
4785 DEBUG(1, ("Got no secdesc for share %s\n",
4791 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
4795 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, "\\", 0, READ_CONTROL_ACCESS, 0,
4796 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
4797 root_sd = cli_query_secdesc(cli, fnum, mem_ctx);
4800 for (i=0; i<num_tokens; i++) {
4803 if (share_sd != NULL) {
4804 status = se_access_check(share_sd, &tokens[i].token,
4807 if (!NT_STATUS_IS_OK(status)) {
4808 DEBUG(1, ("Could not check share_sd for "
4815 if (root_sd == NULL) {
4816 d_printf(" %s\n", tokens[i].name);
4820 status = se_access_check(root_sd, &tokens[i].token,
4822 if (!NT_STATUS_IS_OK(status)) {
4823 DEBUG(1, ("Could not check root_sd for user %s\n",
4827 d_printf(" %s\n", tokens[i].name);
4830 if (fnum != (uint16_t)-1)
4831 cli_close(cli, fnum);
4843 static void collect_share(const char *name, uint32 m,
4844 const char *comment, void *state)
4846 struct share_list *share_list = (struct share_list *)state;
4848 if (m != STYPE_DISKTREE)
4851 share_list->num_shares += 1;
4852 share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares);
4853 if (!share_list->shares) {
4854 share_list->num_shares = 0;
4857 share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name);
4861 * List shares on a remote RPC server, including the security descriptors.
4863 * All parameters are provided by the run_rpc_command function, except for
4864 * argc, argv which are passed through.
4866 * @param domain_sid The domain sid acquired from the remote server.
4867 * @param cli A cli_state connected to the server.
4868 * @param mem_ctx Talloc context, destroyed on completion of the function.
4869 * @param argc Standard main() style argc.
4870 * @param argv Standard main() style argv. Initial components are already
4873 * @return Normal NTSTATUS return.
4876 static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
4877 const struct dom_sid *domain_sid,
4878 const char *domain_name,
4879 struct cli_state *cli,
4880 struct rpc_pipe_client *pipe_hnd,
4881 TALLOC_CTX *mem_ctx,
4890 struct user_token *tokens = NULL;
4893 struct share_list share_list;
4898 f = fopen(argv[0], "r");
4902 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno)));
4903 return NT_STATUS_UNSUCCESSFUL;
4906 r = get_user_tokens_from_file(f, &num_tokens, &tokens);
4912 DEBUG(0, ("Could not read users from file\n"));
4913 return NT_STATUS_UNSUCCESSFUL;
4916 for (i=0; i<num_tokens; i++)
4917 collect_alias_memberships(&tokens[i].token);
4919 share_list.num_shares = 0;
4920 share_list.shares = NULL;
4922 ret = cli_RNetShareEnum(cli, collect_share, &share_list);
4925 DEBUG(0, ("Error returning browse list: %s\n",
4930 for (i = 0; i < share_list.num_shares; i++) {
4931 char *netname = share_list.shares[i];
4933 if (netname[strlen(netname)-1] == '$')
4936 d_printf("%s\n", netname);
4938 show_userlist(pipe_hnd, mem_ctx, netname,
4939 num_tokens, tokens);
4942 for (i=0; i<num_tokens; i++) {
4943 free_user_token(&tokens[i].token);
4946 SAFE_FREE(share_list.shares);
4948 return NT_STATUS_OK;
4951 static int rpc_share_allowedusers(struct net_context *c, int argc,
4956 if (c->display_usage) {
4958 "net rpc share allowedusers\n"
4961 _("List allowed users"));
4965 result = run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
4966 rpc_aliaslist_internals,
4971 result = run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
4977 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4978 rpc_share_allowedusers_internals,
4982 int net_usersidlist(struct net_context *c, int argc, const char **argv)
4985 struct user_token *tokens = NULL;
4989 net_usersidlist_usage(c, argc, argv);
4993 if (!get_user_tokens(c, &num_tokens, &tokens)) {
4994 DEBUG(0, ("Could not get the user/sid list\n"));
4998 for (i=0; i<num_tokens; i++) {
4999 dump_user_token(&tokens[i]);
5000 free_user_token(&tokens[i].token);
5007 int net_usersidlist_usage(struct net_context *c, int argc, const char **argv)
5009 d_printf(_("net usersidlist\n"
5010 "\tprints out a list of all users the running winbind knows\n"
5011 "\tabout, together with all their SIDs. This is used as\n"
5012 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
5014 net_common_flags_usage(c, argc, argv);
5019 * 'net rpc share' entrypoint.
5020 * @param argc Standard main() style argc.
5021 * @param argv Standard main() style argv. Initial components are already
5025 int net_rpc_share(struct net_context *c, int argc, const char **argv)
5027 NET_API_STATUS status;
5029 struct functable func[] = {
5035 N_("net rpc share add\n"
5043 N_("net rpc share delete\n"
5048 rpc_share_allowedusers,
5050 N_("Modify allowed users"),
5051 N_("net rpc share allowedusers\n"
5052 " Modify allowed users")
5058 N_("Migrate share to local server"),
5059 N_("net rpc share migrate\n"
5060 " Migrate share to local server")
5067 N_("net rpc share list\n"
5070 {NULL, NULL, 0, NULL, NULL}
5073 status = libnetapi_net_init(&c->netapi_ctx);
5077 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
5078 libnetapi_set_password(c->netapi_ctx, c->opt_password);
5079 if (c->opt_kerberos) {
5080 libnetapi_set_use_kerberos(c->netapi_ctx);
5084 if (c->display_usage) {
5089 " Alias for net rpc share list\n"));
5090 net_display_usage_from_functable(func);
5094 return rpc_share_list(c, argc, argv);
5097 return net_run_function(c, argc, argv, "net rpc share", func);
5100 static NTSTATUS rpc_sh_share_list(struct net_context *c,
5101 TALLOC_CTX *mem_ctx,
5102 struct rpc_sh_ctx *ctx,
5103 struct rpc_pipe_client *pipe_hnd,
5104 int argc, const char **argv)
5107 return werror_to_ntstatus(W_ERROR(rpc_share_list(c, argc, argv)));
5110 static NTSTATUS rpc_sh_share_add(struct net_context *c,
5111 TALLOC_CTX *mem_ctx,
5112 struct rpc_sh_ctx *ctx,
5113 struct rpc_pipe_client *pipe_hnd,
5114 int argc, const char **argv)
5116 NET_API_STATUS status;
5117 uint32_t parm_err = 0;
5118 struct SHARE_INFO_2 i2;
5120 if ((argc < 2) || (argc > 3)) {
5121 d_fprintf(stderr, _("Usage: %s <share> <path> [comment]\n"),
5123 return NT_STATUS_INVALID_PARAMETER;
5126 i2.shi2_netname = argv[0];
5127 i2.shi2_type = STYPE_DISKTREE;
5128 i2.shi2_remark = (argc == 3) ? argv[2] : "";
5129 i2.shi2_permissions = 0;
5130 i2.shi2_max_uses = 0;
5131 i2.shi2_current_uses = 0;
5132 i2.shi2_path = argv[1];
5133 i2.shi2_passwd = NULL;
5135 status = NetShareAdd(pipe_hnd->desthost,
5140 return werror_to_ntstatus(W_ERROR(status));
5143 static NTSTATUS rpc_sh_share_delete(struct net_context *c,
5144 TALLOC_CTX *mem_ctx,
5145 struct rpc_sh_ctx *ctx,
5146 struct rpc_pipe_client *pipe_hnd,
5147 int argc, const char **argv)
5150 d_fprintf(stderr, "%s %s <share>\n", _("Usage:"), ctx->whoami);
5151 return NT_STATUS_INVALID_PARAMETER;
5154 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd->desthost, argv[0], 0)));
5157 static NTSTATUS rpc_sh_share_info(struct net_context *c,
5158 TALLOC_CTX *mem_ctx,
5159 struct rpc_sh_ctx *ctx,
5160 struct rpc_pipe_client *pipe_hnd,
5161 int argc, const char **argv)
5163 union srvsvc_NetShareInfo info;
5166 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5169 d_fprintf(stderr, "%s %s <share>\n", _("Usage:"), ctx->whoami);
5170 return NT_STATUS_INVALID_PARAMETER;
5173 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
5179 if (!NT_STATUS_IS_OK(status)) {
5180 result = ntstatus_to_werror(status);
5183 if (!W_ERROR_IS_OK(result)) {
5187 d_printf(_("Name: %s\n"), info.info2->name);
5188 d_printf(_("Comment: %s\n"), info.info2->comment);
5189 d_printf(_("Path: %s\n"), info.info2->path);
5190 d_printf(_("Password: %s\n"), info.info2->password);
5193 return werror_to_ntstatus(result);
5196 struct rpc_sh_cmd *net_rpc_share_cmds(struct net_context *c, TALLOC_CTX *mem_ctx,
5197 struct rpc_sh_ctx *ctx)
5199 static struct rpc_sh_cmd cmds[] = {
5201 { "list", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_list,
5202 N_("List available shares") },
5204 { "add", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_add,
5205 N_("Add a share") },
5207 { "delete", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_delete,
5208 N_("Delete a share") },
5210 { "info", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_info,
5211 N_("Get information about a share") },
5213 { NULL, NULL, 0, NULL, NULL }
5219 /****************************************************************************/
5221 static int rpc_file_usage(struct net_context *c, int argc, const char **argv)
5223 return net_file_usage(c, argc, argv);
5227 * Close a file on a remote RPC server.
5229 * @param argc Standard main() style argc.
5230 * @param argv Standard main() style argv. Initial components are already
5233 * @return A shell status integer (0 for success).
5235 static int rpc_file_close(struct net_context *c, int argc, const char **argv)
5237 if (argc < 1 || c->display_usage) {
5238 return rpc_file_usage(c, argc, argv);
5241 return NetFileClose(c->opt_host, atoi(argv[0]));
5245 * Formatted print of open file info
5247 * @param r struct FILE_INFO_3 contents
5250 static void display_file_info_3(struct FILE_INFO_3 *r)
5252 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5253 r->fi3_id, r->fi3_username, r->fi3_permissions,
5254 r->fi3_num_locks, r->fi3_pathname);
5258 * List files for a user on a remote RPC server.
5260 * @param argc Standard main() style argc.
5261 * @param argv Standard main() style argv. Initial components are already
5264 * @return A shell status integer (0 for success)..
5267 static int rpc_file_user(struct net_context *c, int argc, const char **argv)
5269 NET_API_STATUS status;
5270 uint32 preferred_len = 0xffffffff, i;
5271 const char *username=NULL;
5272 uint32_t total_entries = 0;
5273 uint32_t entries_read = 0;
5274 uint32_t resume_handle = 0;
5275 struct FILE_INFO_3 *i3 = NULL;
5277 if (c->display_usage) {
5278 return rpc_file_usage(c, argc, argv);
5281 /* if argc > 0, must be user command */
5283 username = smb_xstrdup(argv[0]);
5286 status = NetFileEnum(c->opt_host,
5290 (uint8_t **)(void *)&i3,
5300 /* Display results */
5303 "\nEnumerating open files on remote server:\n\n"
5304 "\nFileId Opened by Perms Locks Path"
5305 "\n------ --------- ----- ----- ---- \n"));
5306 for (i = 0; i < entries_read; i++) {
5307 display_file_info_3(&i3[i]);
5314 * 'net rpc file' entrypoint.
5315 * @param argc Standard main() style argc.
5316 * @param argv Standard main() style argv. Initial components are already
5320 int net_rpc_file(struct net_context *c, int argc, const char **argv)
5322 NET_API_STATUS status;
5324 struct functable func[] = {
5329 N_("Close opened file"),
5330 N_("net rpc file close\n"
5331 " Close opened file")
5337 N_("List files opened by user"),
5338 N_("net rpc file user\n"
5339 " List files opened by user")
5346 N_("Display information about opened file"),
5347 N_("net rpc file info\n"
5348 " Display information about opened file")
5351 {NULL, NULL, 0, NULL, NULL}
5354 status = libnetapi_net_init(&c->netapi_ctx);
5358 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
5359 libnetapi_set_password(c->netapi_ctx, c->opt_password);
5360 if (c->opt_kerberos) {
5361 libnetapi_set_use_kerberos(c->netapi_ctx);
5365 if (c->display_usage) {
5366 d_printf(_("Usage:\n"));
5367 d_printf(_("net rpc file\n"
5368 " List opened files\n"));
5369 net_display_usage_from_functable(func);
5373 return rpc_file_user(c, argc, argv);
5376 return net_run_function(c, argc, argv, "net rpc file", func);
5380 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5382 * All parameters are provided by the run_rpc_command function, except for
5383 * argc, argv which are passed through.
5385 * @param c A net_context structure.
5386 * @param domain_sid The domain sid acquired from the remote server.
5387 * @param cli A cli_state connected to the server.
5388 * @param mem_ctx Talloc context, destroyed on completion of the function.
5389 * @param argc Standard main() style argc.
5390 * @param argv Standard main() style argv. Initial components are already
5393 * @return Normal NTSTATUS return.
5396 static NTSTATUS rpc_shutdown_abort_internals(struct net_context *c,
5397 const struct dom_sid *domain_sid,
5398 const char *domain_name,
5399 struct cli_state *cli,
5400 struct rpc_pipe_client *pipe_hnd,
5401 TALLOC_CTX *mem_ctx,
5405 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
5407 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5409 status = dcerpc_initshutdown_Abort(b, mem_ctx, NULL, &result);
5410 if (!NT_STATUS_IS_OK(status)) {
5413 if (W_ERROR_IS_OK(result)) {
5414 d_printf(_("\nShutdown successfully aborted\n"));
5415 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5417 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5419 return werror_to_ntstatus(result);
5423 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5425 * All parameters are provided by the run_rpc_command function, except for
5426 * argc, argv which are passed through.
5428 * @param c A net_context structure.
5429 * @param domain_sid The domain sid acquired from the remote server.
5430 * @param cli A cli_state connected to the server.
5431 * @param mem_ctx Talloc context, destroyed on completion of the function.
5432 * @param argc Standard main() style argc.
5433 * @param argv Standard main() style argv. Initial components are already
5436 * @return Normal NTSTATUS return.
5439 static NTSTATUS rpc_reg_shutdown_abort_internals(struct net_context *c,
5440 const struct dom_sid *domain_sid,
5441 const char *domain_name,
5442 struct cli_state *cli,
5443 struct rpc_pipe_client *pipe_hnd,
5444 TALLOC_CTX *mem_ctx,
5448 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5450 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5452 result = dcerpc_winreg_AbortSystemShutdown(b, mem_ctx, NULL, &werr);
5454 if (!NT_STATUS_IS_OK(result)) {
5455 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5458 if (W_ERROR_IS_OK(werr)) {
5459 d_printf(_("\nShutdown successfully aborted\n"));
5460 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5462 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5464 return werror_to_ntstatus(werr);
5468 * ABORT the shutdown of a remote RPC server.
5470 * @param argc Standard main() style argc.
5471 * @param argv Standard main() style argv. Initial components are already
5474 * @return A shell status integer (0 for success).
5477 static int rpc_shutdown_abort(struct net_context *c, int argc,
5482 if (c->display_usage) {
5484 "net rpc abortshutdown\n"
5487 _("Abort a scheduled shutdown"));
5491 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5492 rpc_shutdown_abort_internals, argc, argv);
5497 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5499 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5500 rpc_reg_shutdown_abort_internals,
5505 * Shut down a remote RPC Server via initshutdown pipe.
5507 * All parameters are provided by the run_rpc_command function, except for
5508 * argc, argv which are passed through.
5510 * @param c A net_context structure.
5511 * @param domain_sid The domain sid acquired from the remote server.
5512 * @param cli A cli_state connected to the server.
5513 * @param mem_ctx Talloc context, destroyed on completion of the function.
5514 * @param argc Standard main() style argc.
5515 * @param argv Standard main() style argv. Initial components are already
5518 * @return Normal NTSTATUS return.
5521 NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
5522 const struct dom_sid *domain_sid,
5523 const char *domain_name,
5524 struct cli_state *cli,
5525 struct rpc_pipe_client *pipe_hnd,
5526 TALLOC_CTX *mem_ctx,
5530 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
5532 const char *msg = N_("This machine will be shutdown shortly");
5533 uint32 timeout = 20;
5534 struct lsa_StringLarge msg_string;
5535 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5537 if (c->opt_comment) {
5538 msg = c->opt_comment;
5540 if (c->opt_timeout) {
5541 timeout = c->opt_timeout;
5544 msg_string.string = msg;
5546 /* create an entry */
5547 status = dcerpc_initshutdown_Init(b, mem_ctx, NULL,
5548 &msg_string, timeout, c->opt_force, c->opt_reboot,
5550 if (!NT_STATUS_IS_OK(status)) {
5553 if (W_ERROR_IS_OK(result)) {
5554 d_printf(_("\nShutdown of remote machine succeeded\n"));
5555 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5557 DEBUG(1,("Shutdown of remote machine failed!\n"));
5559 return werror_to_ntstatus(result);
5563 * Shut down a remote RPC Server via winreg pipe.
5565 * All parameters are provided by the run_rpc_command function, except for
5566 * argc, argv which are passed through.
5568 * @param c A net_context structure.
5569 * @param domain_sid The domain sid acquired from the remote server.
5570 * @param cli A cli_state connected to the server.
5571 * @param mem_ctx Talloc context, destroyed on completion of the function.
5572 * @param argc Standard main() style argc.
5573 * @param argv Standard main() style argv. Initial components are already
5576 * @return Normal NTSTATUS return.
5579 NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
5580 const struct dom_sid *domain_sid,
5581 const char *domain_name,
5582 struct cli_state *cli,
5583 struct rpc_pipe_client *pipe_hnd,
5584 TALLOC_CTX *mem_ctx,
5588 const char *msg = N_("This machine will be shutdown shortly");
5589 uint32 timeout = 20;
5590 struct lsa_StringLarge msg_string;
5593 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5595 if (c->opt_comment) {
5596 msg = c->opt_comment;
5598 msg_string.string = msg;
5600 if (c->opt_timeout) {
5601 timeout = c->opt_timeout;
5604 /* create an entry */
5605 result = dcerpc_winreg_InitiateSystemShutdown(b, mem_ctx, NULL,
5606 &msg_string, timeout, c->opt_force, c->opt_reboot,
5608 if (!NT_STATUS_IS_OK(result)) {
5609 d_fprintf(stderr, "\nShutdown of remote machine failed\n");
5613 if (W_ERROR_IS_OK(werr)) {
5614 d_printf(_("\nShutdown of remote machine succeeded\n"));
5616 d_fprintf(stderr, "\nShutdown of remote machine failed\n");
5617 if ( W_ERROR_EQUAL(werr, WERR_MACHINE_LOCKED) )
5618 d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
5620 d_fprintf(stderr, "\nresult was: %s\n", win_errstr(werr));
5623 return werror_to_ntstatus(werr);
5627 * Shut down a remote RPC server.
5629 * @param argc Standard main() style argc.
5630 * @param argv Standard main() style argv. Initial components are already
5633 * @return A shell status integer (0 for success).
5636 static int rpc_shutdown(struct net_context *c, int argc, const char **argv)
5640 if (c->display_usage) {
5642 "net rpc shutdown\n"
5645 _("Shut down a remote RPC server"));
5649 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5650 rpc_init_shutdown_internals, argc, argv);
5653 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5654 rc = run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5655 rpc_reg_shutdown_internals, argc, argv);
5661 /***************************************************************************
5662 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5663 ***************************************************************************/
5666 * Add interdomain trust account to the RPC server.
5667 * All parameters (except for argc and argv) are passed by run_rpc_command
5670 * @param c A net_context structure.
5671 * @param domain_sid The domain sid acquired from the server.
5672 * @param cli A cli_state connected to the server.
5673 * @param mem_ctx Talloc context, destroyed on completion of the function.
5674 * @param argc Standard main() style argc.
5675 * @param argv Standard main() style argv. Initial components are already
5678 * @return normal NTSTATUS return code.
5681 static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
5682 const struct dom_sid *domain_sid,
5683 const char *domain_name,
5684 struct cli_state *cli,
5685 struct rpc_pipe_client *pipe_hnd,
5686 TALLOC_CTX *mem_ctx,
5690 struct policy_handle connect_pol, domain_pol, user_pol;
5691 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5693 struct lsa_String lsa_acct_name;
5695 uint32 acct_flags=0;
5697 uint32_t access_granted = 0;
5698 union samr_UserInfo info;
5699 unsigned int orig_timeout;
5704 _(" net rpc trustdom add <domain_name> "
5705 "<trust password>\n"));
5706 return NT_STATUS_INVALID_PARAMETER;
5710 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5713 if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
5714 return NT_STATUS_NO_MEMORY;
5717 strupper_m(acct_name);
5719 init_lsa_String(&lsa_acct_name, acct_name);
5721 /* Get samr policy handle */
5722 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5724 MAXIMUM_ALLOWED_ACCESS,
5726 if (!NT_STATUS_IS_OK(result)) {
5730 /* Get domain policy handle */
5731 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5733 MAXIMUM_ALLOWED_ACCESS,
5734 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5736 if (!NT_STATUS_IS_OK(result)) {
5740 /* This call can take a long time - allow the server to time out.
5741 * 35 seconds should do it. */
5743 orig_timeout = rpccli_set_timeout(pipe_hnd, 35000);
5745 /* Create trusting domain's account */
5746 acb_info = ACB_NORMAL;
5747 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
5748 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
5749 SAMR_USER_ACCESS_SET_PASSWORD |
5750 SAMR_USER_ACCESS_GET_ATTRIBUTES |
5751 SAMR_USER_ACCESS_SET_ATTRIBUTES;
5753 result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
5762 /* And restore our original timeout. */
5763 rpccli_set_timeout(pipe_hnd, orig_timeout);
5765 if (!NT_STATUS_IS_OK(result)) {
5766 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5767 acct_name, nt_errstr(result));
5772 struct samr_CryptPassword crypt_pwd;
5774 ZERO_STRUCT(info.info23);
5776 init_samr_CryptPassword(argv[1],
5777 &cli->user_session_key,
5780 info.info23.info.fields_present = SAMR_FIELD_ACCT_FLAGS |
5781 SAMR_FIELD_NT_PASSWORD_PRESENT;
5782 info.info23.info.acct_flags = ACB_DOMTRUST;
5783 info.info23.password = crypt_pwd;
5785 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
5790 if (!NT_STATUS_IS_OK(result)) {
5791 DEBUG(0,("Could not set trust account password: %s\n",
5792 nt_errstr(result)));
5798 SAFE_FREE(acct_name);
5803 * Create interdomain trust account for a remote domain.
5805 * @param argc Standard argc.
5806 * @param argv Standard argv without initial components.
5808 * @return Integer status (0 means success).
5811 static int rpc_trustdom_add(struct net_context *c, int argc, const char **argv)
5813 if (argc > 0 && !c->display_usage) {
5814 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5815 rpc_trustdom_add_internals, argc, argv);
5819 _("net rpc trustdom add <domain_name> <trust "
5827 * Remove interdomain trust account from the RPC server.
5828 * All parameters (except for argc and argv) are passed by run_rpc_command
5831 * @param c A net_context structure.
5832 * @param domain_sid The domain sid acquired from the server.
5833 * @param cli A cli_state connected to the server.
5834 * @param mem_ctx Talloc context, destroyed on completion of the function.
5835 * @param argc Standard main() style argc.
5836 * @param argv Standard main() style argv. Initial components are already
5839 * @return normal NTSTATUS return code.
5842 static NTSTATUS rpc_trustdom_del_internals(struct net_context *c,
5843 const struct dom_sid *domain_sid,
5844 const char *domain_name,
5845 struct cli_state *cli,
5846 struct rpc_pipe_client *pipe_hnd,
5847 TALLOC_CTX *mem_ctx,
5851 struct policy_handle connect_pol, domain_pol, user_pol;
5852 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5854 struct dom_sid trust_acct_sid;
5855 struct samr_Ids user_rids, name_types;
5856 struct lsa_String lsa_acct_name;
5861 _(" net rpc trustdom del <domain_name>\n"));
5862 return NT_STATUS_INVALID_PARAMETER;
5866 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5868 acct_name = talloc_asprintf(mem_ctx, "%s$", argv[0]);
5870 if (acct_name == NULL)
5871 return NT_STATUS_NO_MEMORY;
5873 strupper_m(acct_name);
5875 /* Get samr policy handle */
5876 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5878 MAXIMUM_ALLOWED_ACCESS,
5880 if (!NT_STATUS_IS_OK(result)) {
5884 /* Get domain policy handle */
5885 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5887 MAXIMUM_ALLOWED_ACCESS,
5888 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5890 if (!NT_STATUS_IS_OK(result)) {
5894 init_lsa_String(&lsa_acct_name, acct_name);
5896 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
5903 if (!NT_STATUS_IS_OK(result)) {
5904 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5906 acct_name, nt_errstr(result) );
5910 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
5912 MAXIMUM_ALLOWED_ACCESS,
5916 if (!NT_STATUS_IS_OK(result)) {
5917 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5919 acct_name, nt_errstr(result) );
5923 /* append the rid to the domain sid */
5924 if (!sid_compose(&trust_acct_sid, domain_sid, user_rids.ids[0])) {
5928 /* remove the sid */
5930 result = rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd, mem_ctx,
5933 if (!NT_STATUS_IS_OK(result)) {
5934 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5935 " on user %s failed %s\n"),
5936 acct_name, nt_errstr(result) );
5942 result = rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
5945 if (!NT_STATUS_IS_OK(result)) {
5946 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5948 acct_name, nt_errstr(result) );
5952 if (!NT_STATUS_IS_OK(result)) {
5953 d_printf(_("Could not set trust account password: %s\n"),
5963 * Delete interdomain trust account for a remote domain.
5965 * @param argc Standard argc.
5966 * @param argv Standard argv without initial components.
5968 * @return Integer status (0 means success).
5971 static int rpc_trustdom_del(struct net_context *c, int argc, const char **argv)
5973 if (argc > 0 && !c->display_usage) {
5974 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5975 rpc_trustdom_del_internals, argc, argv);
5979 _("net rpc trustdom del <domain>\n"));
5984 static NTSTATUS rpc_trustdom_get_pdc(struct net_context *c,
5985 struct cli_state *cli,
5986 TALLOC_CTX *mem_ctx,
5987 const char *domain_name)
5989 char *dc_name = NULL;
5990 const char *buffer = NULL;
5991 struct rpc_pipe_client *netr;
5994 struct dcerpc_binding_handle *b;
5996 /* Use NetServerEnum2 */
5998 if (cli_get_pdc_name(cli, domain_name, &dc_name)) {
6000 return NT_STATUS_OK;
6003 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
6004 for domain %s\n", domain_name));
6006 /* Try netr_GetDcName */
6008 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
6010 if (!NT_STATUS_IS_OK(status)) {
6014 b = netr->binding_handle;
6016 status = dcerpc_netr_GetDcName(b, mem_ctx,
6023 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
6027 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
6028 for domain %s\n", domain_name));
6030 if (!NT_STATUS_IS_OK(status)) {
6034 return werror_to_ntstatus(result);
6038 * Establish trust relationship to a trusting domain.
6039 * Interdomain account must already be created on remote PDC.
6041 * @param c A net_context structure.
6042 * @param argc Standard argc.
6043 * @param argv Standard argv without initial components.
6045 * @return Integer status (0 means success).
6048 static int rpc_trustdom_establish(struct net_context *c, int argc,
6051 struct cli_state *cli = NULL;
6052 struct sockaddr_storage server_ss;
6053 struct rpc_pipe_client *pipe_hnd = NULL;
6054 struct policy_handle connect_hnd;
6055 TALLOC_CTX *mem_ctx;
6057 struct dom_sid *domain_sid;
6062 union lsa_PolicyInformation *info = NULL;
6065 * Connect to \\server\ipc$ as 'our domain' account with password
6068 if (argc != 1 || c->display_usage) {
6071 _("net rpc trustdom establish <domain_name>\n"));
6075 domain_name = smb_xstrdup(argv[0]);
6076 strupper_m(domain_name);
6078 /* account name used at first is our domain's name with '$' */
6079 if (asprintf(&acct_name, "%s$", lp_workgroup()) == -1) {
6082 strupper_m(acct_name);
6085 * opt_workgroup will be used by connection functions further,
6086 * hence it should be set to remote domain name instead of ours
6088 if (c->opt_workgroup) {
6089 c->opt_workgroup = smb_xstrdup(domain_name);
6092 c->opt_user_name = acct_name;
6094 /* find the domain controller */
6095 if (!net_find_pdc(&server_ss, pdc_name, domain_name)) {
6096 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
6100 /* connect to ipc$ as username/password */
6101 nt_status = connect_to_ipc(c, &cli, &server_ss, pdc_name);
6102 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
6104 /* Is it trusting domain account for sure ? */
6105 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6106 nt_errstr(nt_status)));
6110 /* store who we connected to */
6112 saf_store( domain_name, pdc_name );
6115 * Connect to \\server\ipc$ again (this time anonymously)
6118 nt_status = connect_to_ipc_anonymous(c, &cli, &server_ss,
6121 if (NT_STATUS_IS_ERR(nt_status)) {
6122 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6123 domain_name, nt_errstr(nt_status)));
6127 if (!(mem_ctx = talloc_init("establishing trust relationship to "
6128 "domain %s", domain_name))) {
6129 DEBUG(0, ("talloc_init() failed\n"));
6134 /* Make sure we're talking to a proper server */
6136 nt_status = rpc_trustdom_get_pdc(c, cli, mem_ctx, domain_name);
6137 if (!NT_STATUS_IS_OK(nt_status)) {
6139 talloc_destroy(mem_ctx);
6144 * Call LsaOpenPolicy and LsaQueryInfo
6147 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6149 if (!NT_STATUS_IS_OK(nt_status)) {
6150 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status) ));
6152 talloc_destroy(mem_ctx);
6156 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true, KEY_QUERY_VALUE,
6158 if (NT_STATUS_IS_ERR(nt_status)) {
6159 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6160 nt_errstr(nt_status)));
6162 talloc_destroy(mem_ctx);
6166 /* Querying info level 5 */
6168 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6170 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6172 if (NT_STATUS_IS_ERR(nt_status)) {
6173 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6174 nt_errstr(nt_status)));
6176 talloc_destroy(mem_ctx);
6180 domain_sid = info->account_domain.sid;
6182 /* There should be actually query info level 3 (following nt serv behaviour),
6183 but I still don't know if it's _really_ necessary */
6186 * Store the password in secrets db
6189 if (!pdb_set_trusteddom_pw(domain_name, c->opt_password, domain_sid)) {
6190 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6192 talloc_destroy(mem_ctx);
6197 * Close the pipes and clean up
6200 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6201 if (NT_STATUS_IS_ERR(nt_status)) {
6202 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6203 nt_errstr(nt_status)));
6205 talloc_destroy(mem_ctx);
6211 talloc_destroy(mem_ctx);
6213 d_printf(_("Trust to domain %s established\n"), domain_name);
6218 * Revoke trust relationship to the remote domain.
6220 * @param c A net_context structure.
6221 * @param argc Standard argc.
6222 * @param argv Standard argv without initial components.
6224 * @return Integer status (0 means success).
6227 static int rpc_trustdom_revoke(struct net_context *c, int argc,
6233 if (argc < 1 || c->display_usage) {
6236 _("net rpc trustdom revoke <domain_name>\n"
6237 " Revoke trust relationship\n"
6238 " domain_name\tName of domain to revoke trust\n"));
6242 /* generate upper cased domain name */
6243 domain_name = smb_xstrdup(argv[0]);
6244 strupper_m(domain_name);
6246 /* delete password of the trust */
6247 if (!pdb_del_trusteddom_pw(domain_name)) {
6248 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6255 SAFE_FREE(domain_name);
6259 static NTSTATUS rpc_query_domain_sid(struct net_context *c,
6260 const struct dom_sid *domain_sid,
6261 const char *domain_name,
6262 struct cli_state *cli,
6263 struct rpc_pipe_client *pipe_hnd,
6264 TALLOC_CTX *mem_ctx,
6269 if (!sid_to_fstring(str_sid, domain_sid)) {
6270 return NT_STATUS_UNSUCCESSFUL;
6272 d_printf("%s\n", str_sid);
6273 return NT_STATUS_OK;
6276 static void print_trusted_domain(struct dom_sid *dom_sid, const char *trusted_dom_name)
6280 /* convert sid into ascii string */
6281 sid_to_fstring(ascii_sid, dom_sid);
6283 d_printf("%-20s%s\n", trusted_dom_name, ascii_sid);
6286 static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
6287 TALLOC_CTX *mem_ctx,
6288 struct policy_handle *pol,
6289 struct dom_sid dom_sid,
6290 const char *trusted_dom_name)
6293 union lsa_TrustedDomainInfo *info = NULL;
6294 char *cleartextpwd = NULL;
6295 uint8_t session_key[16];
6296 DATA_BLOB session_key_blob;
6297 DATA_BLOB data = data_blob_null;
6299 nt_status = rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd, mem_ctx,
6302 LSA_TRUSTED_DOMAIN_INFO_PASSWORD,
6304 if (NT_STATUS_IS_ERR(nt_status)) {
6305 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6306 nt_errstr(nt_status)));
6310 data = data_blob(info->password.password->data,
6311 info->password.password->length);
6313 if (!rpccli_get_pwd_hash(pipe_hnd, session_key)) {
6314 DEBUG(0, ("Could not retrieve password hash\n"));
6318 session_key_blob = data_blob_const(session_key, sizeof(session_key));
6319 cleartextpwd = sess_decrypt_string(mem_ctx, &data, &session_key_blob);
6321 if (cleartextpwd == NULL) {
6322 DEBUG(0,("retrieved NULL password\n"));
6323 nt_status = NT_STATUS_UNSUCCESSFUL;
6327 if (!pdb_set_trusteddom_pw(trusted_dom_name, cleartextpwd, &dom_sid)) {
6328 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6329 nt_status = NT_STATUS_UNSUCCESSFUL;
6333 #ifdef DEBUG_PASSWORD
6334 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6335 "password: [%s]\n", trusted_dom_name,
6336 sid_string_dbg(&dom_sid), cleartextpwd));
6340 SAFE_FREE(cleartextpwd);
6341 data_blob_free(&data);
6346 static int rpc_trustdom_vampire(struct net_context *c, int argc,
6349 /* common variables */
6350 TALLOC_CTX* mem_ctx;
6351 struct cli_state *cli = NULL;
6352 struct rpc_pipe_client *pipe_hnd = NULL;
6354 const char *domain_name = NULL;
6355 struct dom_sid *queried_dom_sid;
6356 struct policy_handle connect_hnd;
6357 union lsa_PolicyInformation *info = NULL;
6359 /* trusted domains listing variables */
6360 unsigned int enum_ctx = 0;
6362 struct lsa_DomainList dom_list;
6365 if (c->display_usage) {
6367 "net rpc trustdom vampire\n"
6370 _("Vampire trust relationship from remote server"));
6375 * Listing trusted domains (stored in secrets.tdb, if local)
6378 mem_ctx = talloc_init("trust relationships vampire");
6381 * set domain and pdc name to local samba server (default)
6382 * or to remote one given in command line
6385 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6386 domain_name = c->opt_workgroup;
6387 c->opt_target_workgroup = c->opt_workgroup;
6389 fstrcpy(pdc_name, global_myname());
6390 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6391 c->opt_target_workgroup = domain_name;
6394 /* open \PIPE\lsarpc and open policy handle */
6395 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6396 if (!NT_STATUS_IS_OK(nt_status)) {
6397 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6398 nt_errstr(nt_status)));
6399 talloc_destroy(mem_ctx);
6403 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6405 if (!NT_STATUS_IS_OK(nt_status)) {
6406 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6407 nt_errstr(nt_status) ));
6409 talloc_destroy(mem_ctx);
6413 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
6415 if (NT_STATUS_IS_ERR(nt_status)) {
6416 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6417 nt_errstr(nt_status)));
6419 talloc_destroy(mem_ctx);
6423 /* query info level 5 to obtain sid of a domain being queried */
6424 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6426 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6429 if (NT_STATUS_IS_ERR(nt_status)) {
6430 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6431 nt_errstr(nt_status)));
6433 talloc_destroy(mem_ctx);
6437 queried_dom_sid = info->account_domain.sid;
6440 * Keep calling LsaEnumTrustdom over opened pipe until
6441 * the end of enumeration is reached
6444 d_printf(_("Vampire trusted domains:\n\n"));
6447 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6452 if (NT_STATUS_IS_ERR(nt_status)) {
6453 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6454 nt_errstr(nt_status)));
6456 talloc_destroy(mem_ctx);
6460 for (i = 0; i < dom_list.count; i++) {
6462 print_trusted_domain(dom_list.domains[i].sid,
6463 dom_list.domains[i].name.string);
6465 nt_status = vampire_trusted_domain(pipe_hnd, mem_ctx, &connect_hnd,
6466 *dom_list.domains[i].sid,
6467 dom_list.domains[i].name.string);
6468 if (!NT_STATUS_IS_OK(nt_status)) {
6470 talloc_destroy(mem_ctx);
6476 * in case of no trusted domains say something rather
6477 * than just display blank line
6479 if (!dom_list.count) d_printf(_("none\n"));
6481 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6483 /* close this connection before doing next one */
6484 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6485 if (NT_STATUS_IS_ERR(nt_status)) {
6486 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6487 nt_errstr(nt_status)));
6489 talloc_destroy(mem_ctx);
6493 /* close lsarpc pipe and connection to IPC$ */
6496 talloc_destroy(mem_ctx);
6500 static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
6502 /* common variables */
6503 TALLOC_CTX* mem_ctx;
6504 struct cli_state *cli = NULL, *remote_cli = NULL;
6505 struct rpc_pipe_client *pipe_hnd = NULL;
6507 const char *domain_name = NULL;
6508 struct dom_sid *queried_dom_sid;
6509 int ascii_dom_name_len;
6510 struct policy_handle connect_hnd;
6511 union lsa_PolicyInformation *info = NULL;
6513 /* trusted domains listing variables */
6514 unsigned int num_domains, enum_ctx = 0;
6516 struct lsa_DomainList dom_list;
6520 /* trusting domains listing variables */
6521 struct policy_handle domain_hnd;
6522 struct samr_SamArray *trusts = NULL;
6524 if (c->display_usage) {
6526 "net rpc trustdom list\n"
6529 _("List incoming and outgoing trust relationships"));
6534 * Listing trusted domains (stored in secrets.tdb, if local)
6537 mem_ctx = talloc_init("trust relationships listing");
6540 * set domain and pdc name to local samba server (default)
6541 * or to remote one given in command line
6544 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6545 domain_name = c->opt_workgroup;
6546 c->opt_target_workgroup = c->opt_workgroup;
6548 fstrcpy(pdc_name, global_myname());
6549 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6550 c->opt_target_workgroup = domain_name;
6553 /* open \PIPE\lsarpc and open policy handle */
6554 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6555 if (!NT_STATUS_IS_OK(nt_status)) {
6556 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6557 nt_errstr(nt_status)));
6558 talloc_destroy(mem_ctx);
6562 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6564 if (!NT_STATUS_IS_OK(nt_status)) {
6565 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6566 nt_errstr(nt_status) ));
6568 talloc_destroy(mem_ctx);
6572 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
6574 if (NT_STATUS_IS_ERR(nt_status)) {
6575 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6576 nt_errstr(nt_status)));
6578 talloc_destroy(mem_ctx);
6582 /* query info level 5 to obtain sid of a domain being queried */
6583 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6585 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6588 if (NT_STATUS_IS_ERR(nt_status)) {
6589 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6590 nt_errstr(nt_status)));
6592 talloc_destroy(mem_ctx);
6596 queried_dom_sid = info->account_domain.sid;
6599 * Keep calling LsaEnumTrustdom over opened pipe until
6600 * the end of enumeration is reached
6603 d_printf(_("Trusted domains list:\n\n"));
6605 found_domain = false;
6608 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6613 if (NT_STATUS_IS_ERR(nt_status)) {
6614 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6615 nt_errstr(nt_status)));
6617 talloc_destroy(mem_ctx);
6621 for (i = 0; i < dom_list.count; i++) {
6622 print_trusted_domain(dom_list.domains[i].sid,
6623 dom_list.domains[i].name.string);
6624 found_domain = true;
6628 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6631 * in case of no trusted domains say something rather
6632 * than just display blank line
6634 if (!found_domain) {
6635 d_printf(_("none\n"));
6638 /* close this connection before doing next one */
6639 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6640 if (NT_STATUS_IS_ERR(nt_status)) {
6641 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6642 nt_errstr(nt_status)));
6644 talloc_destroy(mem_ctx);
6648 TALLOC_FREE(pipe_hnd);
6651 * Listing trusting domains (stored in passdb backend, if local)
6654 d_printf(_("\nTrusting domains list:\n\n"));
6657 * Open \PIPE\samr and get needed policy handles
6659 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_samr.syntax_id,
6661 if (!NT_STATUS_IS_OK(nt_status)) {
6662 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status)));
6664 talloc_destroy(mem_ctx);
6669 nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
6671 SAMR_ACCESS_LOOKUP_DOMAIN,
6673 if (!NT_STATUS_IS_OK(nt_status)) {
6674 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6675 nt_errstr(nt_status)));
6677 talloc_destroy(mem_ctx);
6681 /* SamrOpenDomain - we have to open domain policy handle in order to be
6682 able to enumerate accounts*/
6683 nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
6685 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
6688 if (!NT_STATUS_IS_OK(nt_status)) {
6689 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6690 nt_errstr(nt_status)));
6692 talloc_destroy(mem_ctx);
6697 * perform actual enumeration
6700 found_domain = false;
6702 enum_ctx = 0; /* reset enumeration context from last enumeration */
6705 nt_status = rpccli_samr_EnumDomainUsers(pipe_hnd, mem_ctx,
6712 if (NT_STATUS_IS_ERR(nt_status)) {
6713 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6714 nt_errstr(nt_status)));
6716 talloc_destroy(mem_ctx);
6720 for (i = 0; i < num_domains; i++) {
6722 char *str = CONST_DISCARD(char *, trusts->entries[i].name.string);
6724 found_domain = true;
6727 * get each single domain's sid (do we _really_ need this ?):
6728 * 1) connect to domain's pdc
6729 * 2) query the pdc for domain's sid
6732 /* get rid of '$' tail */
6733 ascii_dom_name_len = strlen(str);
6734 if (ascii_dom_name_len && ascii_dom_name_len < FSTRING_LEN)
6735 str[ascii_dom_name_len - 1] = '\0';
6737 /* set opt_* variables to remote domain */
6739 c->opt_workgroup = talloc_strdup(mem_ctx, str);
6740 c->opt_target_workgroup = c->opt_workgroup;
6742 d_printf("%-20s", str);
6744 /* connect to remote domain controller */
6745 nt_status = net_make_ipc_connection(c,
6746 NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS,
6748 if (NT_STATUS_IS_OK(nt_status)) {
6749 /* query for domain's sid */
6750 if (run_rpc_command(
6752 &ndr_table_lsarpc.syntax_id, 0,
6753 rpc_query_domain_sid, argc,
6755 d_printf(_("strange - couldn't get domain's sid\n"));
6757 cli_shutdown(remote_cli);
6760 d_fprintf(stderr, _("domain controller is not "
6761 "responding: %s\n"),
6762 nt_errstr(nt_status));
6763 d_printf(_("couldn't get domain's sid\n"));
6767 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6769 if (!found_domain) {
6773 /* close opened samr and domain policy handles */
6774 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_hnd);
6775 if (!NT_STATUS_IS_OK(nt_status)) {
6776 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
6779 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_hnd);
6780 if (!NT_STATUS_IS_OK(nt_status)) {
6781 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
6784 /* close samr pipe and connection to IPC$ */
6787 talloc_destroy(mem_ctx);
6792 * Entrypoint for 'net rpc trustdom' code.
6794 * @param argc Standard argc.
6795 * @param argv Standard argv without initial components.
6797 * @return Integer status (0 means success).
6800 static int rpc_trustdom(struct net_context *c, int argc, const char **argv)
6802 struct functable func[] = {
6807 N_("Add trusting domain's account"),
6808 N_("net rpc trustdom add\n"
6809 " Add trusting domain's account")
6815 N_("Remove trusting domain's account"),
6816 N_("net rpc trustdom del\n"
6817 " Remove trusting domain's account")
6821 rpc_trustdom_establish,
6823 N_("Establish outgoing trust relationship"),
6824 N_("net rpc trustdom establish\n"
6825 " Establish outgoing trust relationship")
6829 rpc_trustdom_revoke,
6831 N_("Revoke outgoing trust relationship"),
6832 N_("net rpc trustdom revoke\n"
6833 " Revoke outgoing trust relationship")
6839 N_("List in- and outgoing domain trusts"),
6840 N_("net rpc trustdom list\n"
6841 " List in- and outgoing domain trusts")
6845 rpc_trustdom_vampire,
6847 N_("Vampire trusts from remote server"),
6848 N_("net rpc trustdom vampire\n"
6849 " Vampire trusts from remote server")
6851 {NULL, NULL, 0, NULL, NULL}
6854 return net_run_function(c, argc, argv, "net rpc trustdom", func);
6858 * Check if a server will take rpc commands
6859 * @param flags Type of server to connect to (PDC, DMB, localhost)
6860 * if the host is not explicitly specified
6861 * @return bool (true means rpc supported)
6863 bool net_rpc_check(struct net_context *c, unsigned flags)
6865 struct cli_state *cli;
6867 struct sockaddr_storage server_ss;
6868 char *server_name = NULL;
6871 /* flags (i.e. server type) may depend on command */
6872 if (!net_find_server(c, NULL, flags, &server_ss, &server_name))
6875 if ((cli = cli_initialise()) == NULL) {
6879 status = cli_connect(cli, server_name, &server_ss);
6880 if (!NT_STATUS_IS_OK(status))
6882 if (!attempt_netbios_session_request(&cli, global_myname(),
6883 server_name, &server_ss))
6885 status = cli_negprot(cli);
6886 if (!NT_STATUS_IS_OK(status))
6888 if (cli->protocol < PROTOCOL_NT1)
6897 /* dump sam database via samsync rpc calls */
6898 static int rpc_samdump(struct net_context *c, int argc, const char **argv) {
6899 if (c->display_usage) {
6904 _("Dump remote SAM database"));
6908 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6909 NET_FLAGS_ANONYMOUS,
6910 rpc_samdump_internals, argc, argv);
6913 /* syncronise sam database via samsync rpc calls */
6914 static int rpc_vampire(struct net_context *c, int argc, const char **argv)
6916 struct functable func[] = {
6921 N_("Dump remote SAM database to ldif"),
6922 N_("net rpc vampire ldif\n"
6923 " Dump remote SAM database to LDIF file or "
6930 N_("Dump remote SAM database to Kerberos Keytab"),
6931 N_("net rpc vampire keytab\n"
6932 " Dump remote SAM database to Kerberos keytab "
6939 N_("Dump remote SAM database to passdb"),
6940 N_("net rpc vampire passdb\n"
6941 " Dump remote SAM database to passdb")
6944 {NULL, NULL, 0, NULL, NULL}
6948 if (c->display_usage) {
6953 _("Vampire remote SAM database"));
6957 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6958 NET_FLAGS_ANONYMOUS,
6959 rpc_vampire_internals,
6963 return net_run_function(c, argc, argv, "net rpc vampire", func);
6967 * Migrate everything from a print server.
6969 * @param c A net_context structure.
6970 * @param argc Standard main() style argc.
6971 * @param argv Standard main() style argv. Initial components are already
6974 * @return A shell status integer (0 for success).
6976 * The order is important !
6977 * To successfully add drivers the print queues have to exist !
6978 * Applying ACLs should be the last step, because you're easily locked out.
6981 static int rpc_printer_migrate_all(struct net_context *c, int argc,
6986 if (c->display_usage) {
6988 "net rpc printer migrate all\n"
6991 _("Migrate everything from a print server"));
6996 d_printf(_("no server to migrate\n"));
7000 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7001 rpc_printer_migrate_printers_internals, argc,
7006 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7007 rpc_printer_migrate_drivers_internals, argc,
7012 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7013 rpc_printer_migrate_forms_internals, argc, argv);
7017 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7018 rpc_printer_migrate_settings_internals, argc,
7023 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7024 rpc_printer_migrate_security_internals, argc,
7030 * Migrate print drivers from a print server.
7032 * @param c A net_context structure.
7033 * @param argc Standard main() style argc.
7034 * @param argv Standard main() style argv. Initial components are already
7037 * @return A shell status integer (0 for success).
7039 static int rpc_printer_migrate_drivers(struct net_context *c, int argc,
7042 if (c->display_usage) {
7044 "net rpc printer migrate drivers\n"
7047 _("Migrate print-drivers from a print-server"));
7052 d_printf(_("no server to migrate\n"));
7056 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7057 rpc_printer_migrate_drivers_internals,
7062 * Migrate print-forms from a print-server.
7064 * @param c A net_context structure.
7065 * @param argc Standard main() style argc.
7066 * @param argv Standard main() style argv. Initial components are already
7069 * @return A shell status integer (0 for success).
7071 static int rpc_printer_migrate_forms(struct net_context *c, int argc,
7074 if (c->display_usage) {
7076 "net rpc printer migrate forms\n"
7079 _("Migrate print-forms from a print-server"));
7084 d_printf(_("no server to migrate\n"));
7088 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7089 rpc_printer_migrate_forms_internals,
7094 * Migrate printers from a print-server.
7096 * @param c A net_context structure.
7097 * @param argc Standard main() style argc.
7098 * @param argv Standard main() style argv. Initial components are already
7101 * @return A shell status integer (0 for success).
7103 static int rpc_printer_migrate_printers(struct net_context *c, int argc,
7106 if (c->display_usage) {
7108 "net rpc printer migrate printers\n"
7111 _("Migrate printers from a print-server"));
7116 d_printf(_("no server to migrate\n"));
7120 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7121 rpc_printer_migrate_printers_internals,
7126 * Migrate printer-ACLs from a print-server
7128 * @param c A net_context structure.
7129 * @param argc Standard main() style argc.
7130 * @param argv Standard main() style argv. Initial components are already
7133 * @return A shell status integer (0 for success).
7135 static int rpc_printer_migrate_security(struct net_context *c, int argc,
7138 if (c->display_usage) {
7140 "net rpc printer migrate security\n"
7143 _("Migrate printer-ACLs from a print-server"));
7148 d_printf(_("no server to migrate\n"));
7152 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7153 rpc_printer_migrate_security_internals,
7158 * Migrate printer-settings from a print-server.
7160 * @param c A net_context structure.
7161 * @param argc Standard main() style argc.
7162 * @param argv Standard main() style argv. Initial components are already
7165 * @return A shell status integer (0 for success).
7167 static int rpc_printer_migrate_settings(struct net_context *c, int argc,
7170 if (c->display_usage) {
7172 "net rpc printer migrate settings\n"
7175 _("Migrate printer-settings from a "
7181 d_printf(_("no server to migrate\n"));
7185 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7186 rpc_printer_migrate_settings_internals,
7191 * 'net rpc printer' entrypoint.
7193 * @param c A net_context structure.
7194 * @param argc Standard main() style argc.
7195 * @param argv Standard main() style argv. Initial components are already
7199 int rpc_printer_migrate(struct net_context *c, int argc, const char **argv)
7202 /* ouch: when addriver and setdriver are called from within
7203 rpc_printer_migrate_drivers_internals, the printer-queue already
7206 struct functable func[] = {
7209 rpc_printer_migrate_all,
7211 N_("Migrate all from remote to local print server"),
7212 N_("net rpc printer migrate all\n"
7213 " Migrate all from remote to local print server")
7217 rpc_printer_migrate_drivers,
7219 N_("Migrate drivers to local server"),
7220 N_("net rpc printer migrate drivers\n"
7221 " Migrate drivers to local server")
7225 rpc_printer_migrate_forms,
7227 N_("Migrate froms to local server"),
7228 N_("net rpc printer migrate forms\n"
7229 " Migrate froms to local server")
7233 rpc_printer_migrate_printers,
7235 N_("Migrate printers to local server"),
7236 N_("net rpc printer migrate printers\n"
7237 " Migrate printers to local server")
7241 rpc_printer_migrate_security,
7243 N_("Mirgate printer ACLs to local server"),
7244 N_("net rpc printer migrate security\n"
7245 " Mirgate printer ACLs to local server")
7249 rpc_printer_migrate_settings,
7251 N_("Migrate printer settings to local server"),
7252 N_("net rpc printer migrate settings\n"
7253 " Migrate printer settings to local server")
7255 {NULL, NULL, 0, NULL, NULL}
7258 return net_run_function(c, argc, argv, "net rpc printer migrate",func);
7263 * List printers on a remote RPC server.
7265 * @param c A net_context structure.
7266 * @param argc Standard main() style argc.
7267 * @param argv Standard main() style argv. Initial components are already
7270 * @return A shell status integer (0 for success).
7272 static int rpc_printer_list(struct net_context *c, int argc, const char **argv)
7274 if (c->display_usage) {
7276 "net rpc printer list\n"
7279 _("List printers on a remote RPC server"));
7283 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7284 rpc_printer_list_internals,
7289 * List printer-drivers on a remote RPC server.
7291 * @param c A net_context structure.
7292 * @param argc Standard main() style argc.
7293 * @param argv Standard main() style argv. Initial components are already
7296 * @return A shell status integer (0 for success).
7298 static int rpc_printer_driver_list(struct net_context *c, int argc,
7301 if (c->display_usage) {
7303 "net rpc printer driver\n"
7306 _("List printer-drivers on a remote RPC server"));
7310 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7311 rpc_printer_driver_list_internals,
7316 * Publish printer in ADS via MSRPC.
7318 * @param c A net_context structure.
7319 * @param argc Standard main() style argc.
7320 * @param argv Standard main() style argv. Initial components are already
7323 * @return A shell status integer (0 for success).
7325 static int rpc_printer_publish_publish(struct net_context *c, int argc,
7328 if (c->display_usage) {
7330 "net rpc printer publish publish\n"
7333 _("Publish printer in ADS via MSRPC"));
7337 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7338 rpc_printer_publish_publish_internals,
7343 * Update printer in ADS via MSRPC.
7345 * @param c A net_context structure.
7346 * @param argc Standard main() style argc.
7347 * @param argv Standard main() style argv. Initial components are already
7350 * @return A shell status integer (0 for success).
7352 static int rpc_printer_publish_update(struct net_context *c, int argc, const char **argv)
7354 if (c->display_usage) {
7356 "net rpc printer publish update\n"
7359 _("Update printer in ADS via MSRPC"));
7363 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7364 rpc_printer_publish_update_internals,
7369 * UnPublish printer in ADS via MSRPC.
7371 * @param c A net_context structure.
7372 * @param argc Standard main() style argc.
7373 * @param argv Standard main() style argv. Initial components are already
7376 * @return A shell status integer (0 for success).
7378 static int rpc_printer_publish_unpublish(struct net_context *c, int argc,
7381 if (c->display_usage) {
7383 "net rpc printer publish unpublish\n"
7386 _("UnPublish printer in ADS via MSRPC"));
7390 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7391 rpc_printer_publish_unpublish_internals,
7396 * List published printers via MSRPC.
7398 * @param c A net_context structure.
7399 * @param argc Standard main() style argc.
7400 * @param argv Standard main() style argv. Initial components are already
7403 * @return A shell status integer (0 for success).
7405 static int rpc_printer_publish_list(struct net_context *c, int argc,
7408 if (c->display_usage) {
7410 "net rpc printer publish list\n"
7413 _("List published printers via MSRPC"));
7417 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7418 rpc_printer_publish_list_internals,
7424 * Publish printer in ADS.
7426 * @param c A net_context structure.
7427 * @param argc Standard main() style argc.
7428 * @param argv Standard main() style argv. Initial components are already
7431 * @return A shell status integer (0 for success).
7433 static int rpc_printer_publish(struct net_context *c, int argc,
7437 struct functable func[] = {
7440 rpc_printer_publish_publish,
7442 N_("Publish printer in AD"),
7443 N_("net rpc printer publish publish\n"
7444 " Publish printer in AD")
7448 rpc_printer_publish_update,
7450 N_("Update printer in AD"),
7451 N_("net rpc printer publish update\n"
7452 " Update printer in AD")
7456 rpc_printer_publish_unpublish,
7458 N_("Unpublish printer"),
7459 N_("net rpc printer publish unpublish\n"
7460 " Unpublish printer")
7464 rpc_printer_publish_list,
7466 N_("List published printers"),
7467 N_("net rpc printer publish list\n"
7468 " List published printers")
7470 {NULL, NULL, 0, NULL, NULL}
7474 if (c->display_usage) {
7475 d_printf(_("Usage:\n"));
7476 d_printf(_("net rpc printer publish\n"
7477 " List published printers\n"
7478 " Alias of net rpc printer publish "
7480 net_display_usage_from_functable(func);
7483 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7484 rpc_printer_publish_list_internals,
7488 return net_run_function(c, argc, argv, "net rpc printer publish",func);
7494 * Display rpc printer help page.
7496 * @param c A net_context structure.
7497 * @param argc Standard main() style argc.
7498 * @param argv Standard main() style argv. Initial components are already
7501 int rpc_printer_usage(struct net_context *c, int argc, const char **argv)
7503 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
7504 "\tlists all printers on print-server\n\n"));
7505 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7506 "\tlists all printer-drivers on print-server\n\n"));
7507 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7508 "\tpublishes printer settings in Active Directory\n"
7509 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
7510 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7511 "\n\tmigrates printers from remote to local server\n\n"));
7512 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7513 "\n\tmigrates printer-settings from remote to local server\n\n"));
7514 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7515 "\n\tmigrates printer-drivers from remote to local server\n\n"));
7516 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7517 "\n\tmigrates printer-forms from remote to local server\n\n"));
7518 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7519 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
7520 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7521 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7522 "\tremote to local print-server\n\n"));
7523 net_common_methods_usage(c, argc, argv);
7524 net_common_flags_usage(c, argc, argv);
7526 "\t-v or --verbose\t\t\tgive verbose output\n"
7527 "\t --destination\t\tmigration target server (default: localhost)\n"));
7533 * 'net rpc printer' entrypoint.
7535 * @param c A net_context structure.
7536 * @param argc Standard main() style argc.
7537 * @param argv Standard main() style argv. Initial components are already
7540 int net_rpc_printer(struct net_context *c, int argc, const char **argv)
7542 struct functable func[] = {
7547 N_("List all printers on print server"),
7548 N_("net rpc printer list\n"
7549 " List all printers on print server")
7553 rpc_printer_migrate,
7555 N_("Migrate printer to local server"),
7556 N_("net rpc printer migrate\n"
7557 " Migrate printer to local server")
7561 rpc_printer_driver_list,
7563 N_("List printer drivers"),
7564 N_("net rpc printer driver\n"
7565 " List printer drivers")
7569 rpc_printer_publish,
7571 N_("Publish printer in AD"),
7572 N_("net rpc printer publish\n"
7573 " Publish printer in AD")
7575 {NULL, NULL, 0, NULL, NULL}
7579 if (c->display_usage) {
7580 d_printf(_("Usage:\n"));
7581 d_printf(_("net rpc printer\n"
7582 " List printers\n"));
7583 net_display_usage_from_functable(func);
7586 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7587 rpc_printer_list_internals,
7591 return net_run_function(c, argc, argv, "net rpc printer", func);
7595 * 'net rpc' entrypoint.
7597 * @param c A net_context structure.
7598 * @param argc Standard main() style argc.
7599 * @param argv Standard main() style argv. Initial components are already
7603 int net_rpc(struct net_context *c, int argc, const char **argv)
7605 NET_API_STATUS status;
7607 struct functable func[] = {
7612 N_("Modify global audit settings"),
7613 N_("net rpc audit\n"
7614 " Modify global audit settings")
7620 N_("Show basic info about a domain"),
7622 " Show basic info about a domain")
7628 N_("Join a domain"),
7636 N_("Join a domain created in server manager"),
7637 N_("net rpc oldjoin\n"
7638 " Join a domain created in server manager")
7644 N_("Test that a join is valid"),
7645 N_("net rpc testjoin\n"
7646 " Test that a join is valid")
7652 N_("List/modify users"),
7654 " List/modify users")
7660 N_("Change a user password"),
7661 N_("net rpc password\n"
7662 " Change a user password\n"
7663 " Alias for net rpc user password")
7669 N_("List/modify groups"),
7670 N_("net rpc group\n"
7671 " List/modify groups")
7677 N_("List/modify shares"),
7678 N_("net rpc share\n"
7679 " List/modify shares")
7685 N_("List open files"),
7693 N_("List/modify printers"),
7694 N_("net rpc printer\n"
7695 " List/modify printers")
7699 net_rpc_changetrustpw,
7701 N_("Change trust account password"),
7702 N_("net rpc changetrustpw\n"
7703 " Change trust account password")
7709 N_("Modify domain trusts"),
7710 N_("net rpc trustdom\n"
7711 " Modify domain trusts")
7717 N_("Abort a remote shutdown"),
7718 N_("net rpc abortshutdown\n"
7719 " Abort a remote shutdown")
7725 N_("Shutdown a remote server"),
7726 N_("net rpc shutdown\n"
7727 " Shutdown a remote server")
7733 N_("Dump SAM data of remote NT PDC"),
7734 N_("net rpc samdump\n"
7735 " Dump SAM data of remote NT PDC")
7741 N_("Sync a remote NT PDC's data into local passdb"),
7742 N_("net rpc vampire\n"
7743 " Sync a remote NT PDC's data into local passdb")
7749 N_("Fetch the domain sid into local secrets.tdb"),
7750 N_("net rpc getsid\n"
7751 " Fetch the domain sid into local secrets.tdb")
7757 N_("Manage privileges assigned to SID"),
7758 N_("net rpc rights\n"
7759 " Manage privileges assigned to SID")
7765 N_("Start/stop/query remote services"),
7766 N_("net rpc service\n"
7767 " Start/stop/query remote services")
7773 N_("Manage registry hives"),
7774 N_("net rpc registry\n"
7775 " Manage registry hives")
7781 N_("Open interactive shell on remote server"),
7782 N_("net rpc shell\n"
7783 " Open interactive shell on remote server")
7785 {NULL, NULL, 0, NULL, NULL}
7788 status = libnetapi_net_init(&c->netapi_ctx);
7792 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
7793 libnetapi_set_password(c->netapi_ctx, c->opt_password);
7794 if (c->opt_kerberos) {
7795 libnetapi_set_use_kerberos(c->netapi_ctx);
7797 if (c->opt_ccache) {
7798 libnetapi_set_use_ccache(c->netapi_ctx);
7801 return net_run_function(c, argc, argv, "net rpc", func);