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,
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;
2801 sid_to_fstring(sid_str, domain_sid);
2803 result = rpccli_samr_OpenGroup(pipe_hnd, mem_ctx,
2805 MAXIMUM_ALLOWED_ACCESS,
2809 if (!NT_STATUS_IS_OK(result))
2812 result = rpccli_samr_QueryGroupMember(pipe_hnd, mem_ctx,
2816 if (!NT_STATUS_IS_OK(result))
2819 num_members = rids->count;
2820 group_rids = rids->rids;
2822 while (num_members > 0) {
2823 int this_time = 512;
2825 if (num_members < this_time)
2826 this_time = num_members;
2828 result = rpccli_samr_LookupRids(pipe_hnd, mem_ctx,
2835 if (!NT_STATUS_IS_OK(result))
2838 /* We only have users as members, but make the output
2839 the same as the output of alias members */
2841 for (i = 0; i < this_time; i++) {
2843 if (c->opt_long_list_entries) {
2844 printf("%s-%d %s\\%s %d\n", sid_str,
2845 group_rids[i], domain_name,
2846 names.names[i].string,
2849 printf("%s\\%s\n", domain_name,
2850 names.names[i].string);
2854 num_members -= this_time;
2858 return NT_STATUS_OK;
2861 static NTSTATUS rpc_list_alias_members(struct net_context *c,
2862 struct rpc_pipe_client *pipe_hnd,
2863 TALLOC_CTX *mem_ctx,
2864 struct policy_handle *domain_pol,
2868 struct rpc_pipe_client *lsa_pipe;
2869 struct policy_handle alias_pol, lsa_pol;
2871 struct dom_sid *alias_sids;
2874 enum lsa_SidType *types;
2876 struct lsa_SidArray sid_array;
2878 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
2880 MAXIMUM_ALLOWED_ACCESS,
2884 if (!NT_STATUS_IS_OK(result))
2887 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
2891 if (!NT_STATUS_IS_OK(result)) {
2892 d_fprintf(stderr, _("Couldn't list alias members\n"));
2896 num_members = sid_array.num_sids;
2898 if (num_members == 0) {
2899 return NT_STATUS_OK;
2902 result = cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd),
2903 &ndr_table_lsarpc.syntax_id,
2905 if (!NT_STATUS_IS_OK(result)) {
2906 d_fprintf(stderr, _("Couldn't open LSA pipe. Error was %s\n"),
2907 nt_errstr(result) );
2911 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, true,
2912 SEC_FLAG_MAXIMUM_ALLOWED, &lsa_pol);
2914 if (!NT_STATUS_IS_OK(result)) {
2915 d_fprintf(stderr, _("Couldn't open LSA policy handle\n"));
2916 TALLOC_FREE(lsa_pipe);
2920 alias_sids = TALLOC_ZERO_ARRAY(mem_ctx, struct dom_sid, num_members);
2922 d_fprintf(stderr, _("Out of memory\n"));
2923 TALLOC_FREE(lsa_pipe);
2924 return NT_STATUS_NO_MEMORY;
2927 for (i=0; i<num_members; i++) {
2928 sid_copy(&alias_sids[i], sid_array.sids[i].sid);
2931 result = rpccli_lsa_lookup_sids(lsa_pipe, mem_ctx, &lsa_pol,
2932 num_members, alias_sids,
2933 &domains, &names, &types);
2935 if (!NT_STATUS_IS_OK(result) &&
2936 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
2937 d_fprintf(stderr, _("Couldn't lookup SIDs\n"));
2938 TALLOC_FREE(lsa_pipe);
2942 for (i = 0; i < num_members; i++) {
2944 sid_to_fstring(sid_str, &alias_sids[i]);
2946 if (c->opt_long_list_entries) {
2947 printf("%s %s\\%s %d\n", sid_str,
2948 domains[i] ? domains[i] : _("*unknown*"),
2949 names[i] ? names[i] : _("*unknown*"), types[i]);
2952 printf("%s\\%s\n", domains[i], names[i]);
2954 printf("%s\n", sid_str);
2958 TALLOC_FREE(lsa_pipe);
2959 return NT_STATUS_OK;
2962 static NTSTATUS rpc_group_members_internals(struct net_context *c,
2963 const struct dom_sid *domain_sid,
2964 const char *domain_name,
2965 struct cli_state *cli,
2966 struct rpc_pipe_client *pipe_hnd,
2967 TALLOC_CTX *mem_ctx,
2972 struct policy_handle connect_pol, domain_pol;
2973 struct samr_Ids rids, rid_types;
2974 struct lsa_String lsa_acct_name;
2976 /* Get sam policy handle */
2978 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
2980 MAXIMUM_ALLOWED_ACCESS,
2983 if (!NT_STATUS_IS_OK(result))
2986 /* Get domain policy handle */
2988 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
2990 MAXIMUM_ALLOWED_ACCESS,
2991 CONST_DISCARD(struct dom_sid2 *, domain_sid),
2994 if (!NT_STATUS_IS_OK(result))
2997 init_lsa_String(&lsa_acct_name, argv[0]); /* sure? */
2999 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
3006 if (!NT_STATUS_IS_OK(result)) {
3008 /* Ok, did not find it in the global sam, try with builtin */
3010 struct dom_sid sid_Builtin;
3012 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
3014 sid_copy(&sid_Builtin, &global_sid_Builtin);
3016 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
3018 MAXIMUM_ALLOWED_ACCESS,
3022 if (!NT_STATUS_IS_OK(result)) {
3023 d_fprintf(stderr, _("Couldn't find group %s\n"),
3028 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
3035 if (!NT_STATUS_IS_OK(result)) {
3036 d_fprintf(stderr, _("Couldn't find group %s\n"),
3042 if (rids.count != 1) {
3043 d_fprintf(stderr, _("Couldn't find group %s\n"),
3048 if (rid_types.ids[0] == SID_NAME_DOM_GRP) {
3049 return rpc_list_group_members(c, pipe_hnd, mem_ctx, domain_name,
3050 domain_sid, &domain_pol,
3054 if (rid_types.ids[0] == SID_NAME_ALIAS) {
3055 return rpc_list_alias_members(c, pipe_hnd, mem_ctx, &domain_pol,
3059 return NT_STATUS_NO_SUCH_GROUP;
3062 static int rpc_group_members(struct net_context *c, int argc, const char **argv)
3064 if (argc != 1 || c->display_usage) {
3065 return rpc_group_usage(c, argc, argv);
3068 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
3069 rpc_group_members_internals,
3073 static int rpc_group_rename_internals(struct net_context *c, int argc, const char **argv)
3075 NET_API_STATUS status;
3076 struct GROUP_INFO_0 g0;
3080 d_printf(_("Usage:\n"));
3081 d_printf("net rpc group rename group newname\n");
3085 g0.grpi0_name = argv[1];
3087 status = NetGroupSetInfo(c->opt_host,
3094 d_fprintf(stderr, _("Renaming group %s failed with: %s\n"),
3095 argv[0], libnetapi_get_error_string(c->netapi_ctx,
3103 static int rpc_group_rename(struct net_context *c, int argc, const char **argv)
3105 if (argc != 2 || c->display_usage) {
3106 return rpc_group_usage(c, argc, argv);
3109 return rpc_group_rename_internals(c, argc, argv);
3113 * 'net rpc group' entrypoint.
3114 * @param argc Standard main() style argc.
3115 * @param argv Standard main() style argv. Initial components are already
3119 int net_rpc_group(struct net_context *c, int argc, const char **argv)
3121 NET_API_STATUS status;
3123 struct functable func[] = {
3128 N_("Create specified group"),
3129 N_("net rpc group add\n"
3130 " Create specified group")
3136 N_("Delete specified group"),
3137 N_("net rpc group delete\n"
3138 " Delete specified group")
3144 N_("Add member to group"),
3145 N_("net rpc group addmem\n"
3146 " Add member to group")
3152 N_("Remove member from group"),
3153 N_("net rpc group delmem\n"
3154 " Remove member from group")
3161 N_("net rpc group list\n"
3168 N_("List group members"),
3169 N_("net rpc group members\n"
3170 " List group members")
3177 N_("net rpc group rename\n"
3180 {NULL, NULL, 0, NULL, NULL}
3183 status = libnetapi_net_init(&c->netapi_ctx);
3187 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
3188 libnetapi_set_password(c->netapi_ctx, c->opt_password);
3189 if (c->opt_kerberos) {
3190 libnetapi_set_use_kerberos(c->netapi_ctx);
3194 if (c->display_usage) {
3195 d_printf(_("Usage:\n"));
3196 d_printf(_("net rpc group\n"
3197 " Alias for net rpc group list global "
3198 "local builtin\n"));
3199 net_display_usage_from_functable(func);
3203 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
3204 rpc_group_list_internals,
3208 return net_run_function(c, argc, argv, "net rpc group", func);
3211 /****************************************************************************/
3213 static int rpc_share_usage(struct net_context *c, int argc, const char **argv)
3215 return net_share_usage(c, argc, argv);
3219 * Add a share on a remote RPC server.
3221 * @param argc Standard main() style argc.
3222 * @param argv Standard main() style argv. Initial components are already
3225 * @return A shell status integer (0 for success).
3228 static int rpc_share_add(struct net_context *c, int argc, const char **argv)
3230 NET_API_STATUS status;
3233 uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
3234 uint32 num_users=0, perms=0;
3235 char *password=NULL; /* don't allow a share password */
3236 struct SHARE_INFO_2 i2;
3237 uint32_t parm_error = 0;
3239 if ((argc < 1) || !strchr(argv[0], '=') || c->display_usage) {
3240 return rpc_share_usage(c, argc, argv);
3243 if ((sharename = talloc_strdup(c, argv[0])) == NULL) {
3247 path = strchr(sharename, '=');
3254 i2.shi2_netname = sharename;
3255 i2.shi2_type = type;
3256 i2.shi2_remark = c->opt_comment;
3257 i2.shi2_permissions = perms;
3258 i2.shi2_max_uses = c->opt_maxusers;
3259 i2.shi2_current_uses = num_users;
3260 i2.shi2_path = path;
3261 i2.shi2_passwd = password;
3263 status = NetShareAdd(c->opt_host,
3268 printf(_("NetShareAdd failed with: %s\n"),
3269 libnetapi_get_error_string(c->netapi_ctx, status));
3276 * Delete a share on a remote RPC server.
3278 * @param domain_sid The domain sid acquired from the remote server.
3279 * @param argc Standard main() style argc.
3280 * @param argv Standard main() style argv. Initial components are already
3283 * @return A shell status integer (0 for success).
3285 static int rpc_share_delete(struct net_context *c, int argc, const char **argv)
3287 if (argc < 1 || c->display_usage) {
3288 return rpc_share_usage(c, argc, argv);
3291 return NetShareDel(c->opt_host, argv[0], 0);
3295 * Formatted print of share info
3297 * @param r pointer to SHARE_INFO_1 to format
3300 static void display_share_info_1(struct net_context *c,
3301 struct SHARE_INFO_1 *r)
3303 if (c->opt_long_list_entries) {
3304 d_printf("%-12s %-8.8s %-50s\n",
3306 net_share_type_str(r->shi1_type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)),
3309 d_printf("%s\n", r->shi1_netname);
3313 static WERROR get_share_info(struct net_context *c,
3314 struct rpc_pipe_client *pipe_hnd,
3315 TALLOC_CTX *mem_ctx,
3319 struct srvsvc_NetShareInfoCtr *info_ctr)
3323 union srvsvc_NetShareInfo info;
3324 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
3326 /* no specific share requested, enumerate all */
3329 uint32_t preferred_len = 0xffffffff;
3330 uint32_t total_entries = 0;
3331 uint32_t resume_handle = 0;
3333 info_ctr->level = level;
3335 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
3342 if (!NT_STATUS_IS_OK(status)) {
3343 return ntstatus_to_werror(status);
3348 /* request just one share */
3349 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
3356 if (!NT_STATUS_IS_OK(status)) {
3357 result = ntstatus_to_werror(status);
3361 if (!W_ERROR_IS_OK(result)) {
3366 ZERO_STRUCTP(info_ctr);
3368 info_ctr->level = level;
3373 struct srvsvc_NetShareCtr1 *ctr1;
3375 ctr1 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr1);
3376 W_ERROR_HAVE_NO_MEMORY(ctr1);
3379 ctr1->array = info.info1;
3381 info_ctr->ctr.ctr1 = ctr1;
3387 struct srvsvc_NetShareCtr2 *ctr2;
3389 ctr2 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr2);
3390 W_ERROR_HAVE_NO_MEMORY(ctr2);
3393 ctr2->array = info.info2;
3395 info_ctr->ctr.ctr2 = ctr2;
3401 struct srvsvc_NetShareCtr502 *ctr502;
3403 ctr502 = TALLOC_ZERO_P(mem_ctx, struct srvsvc_NetShareCtr502);
3404 W_ERROR_HAVE_NO_MEMORY(ctr502);
3407 ctr502->array = info.info502;
3409 info_ctr->ctr.ctr502 = ctr502;
3419 * 'net rpc share list' entrypoint.
3420 * @param argc Standard main() style argc.
3421 * @param argv Standard main() style argv. Initial components are already
3424 static int rpc_share_list(struct net_context *c, int argc, const char **argv)
3426 NET_API_STATUS status;
3427 struct SHARE_INFO_1 *i1 = NULL;
3428 uint32_t entries_read = 0;
3429 uint32_t total_entries = 0;
3430 uint32_t resume_handle = 0;
3431 uint32_t i, level = 1;
3433 if (c->display_usage) {
3435 "net rpc share list\n"
3438 _("List shares on remote server"));
3442 status = NetShareEnum(c->opt_host,
3444 (uint8_t **)(void *)&i1,
3453 /* Display results */
3455 if (c->opt_long_list_entries) {
3457 "\nEnumerating shared resources (exports) on remote server:\n\n"
3458 "\nShare name Type Description\n"
3459 "---------- ---- -----------\n"));
3461 for (i = 0; i < entries_read; i++)
3462 display_share_info_1(c, &i1[i]);
3467 static bool check_share_availability(struct cli_state *cli, const char *netname)
3471 status = cli_tcon_andx(cli, netname, "A:", "", 0);
3472 if (!NT_STATUS_IS_OK(status)) {
3473 d_printf(_("skipping [%s]: not a file share.\n"), netname);
3477 status = cli_tdis(cli);
3478 if (!NT_STATUS_IS_OK(status)) {
3479 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status));
3486 static bool check_share_sanity(struct net_context *c, struct cli_state *cli,
3487 const char *netname, uint32 type)
3489 /* only support disk shares */
3490 if (! ( type == STYPE_DISKTREE || type == (STYPE_DISKTREE | STYPE_HIDDEN)) ) {
3491 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname,
3496 /* skip builtin shares */
3497 /* FIXME: should print$ be added too ? */
3498 if (strequal(netname,"IPC$") || strequal(netname,"ADMIN$") ||
3499 strequal(netname,"global"))
3502 if (c->opt_exclude && in_list(netname, c->opt_exclude, false)) {
3503 printf(_("excluding [%s]\n"), netname);
3507 return check_share_availability(cli, netname);
3511 * Migrate shares from a remote RPC server to the local RPC server.
3513 * All parameters are provided by the run_rpc_command function, except for
3514 * argc, argv which are passed through.
3516 * @param domain_sid The domain sid acquired from the remote server.
3517 * @param cli A cli_state connected to the server.
3518 * @param mem_ctx Talloc context, destroyed on completion of the function.
3519 * @param argc Standard main() style argc.
3520 * @param argv Standard main() style argv. Initial components are already
3523 * @return Normal NTSTATUS return.
3526 static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c,
3527 const struct dom_sid *domain_sid,
3528 const char *domain_name,
3529 struct cli_state *cli,
3530 struct rpc_pipe_client *pipe_hnd,
3531 TALLOC_CTX *mem_ctx,
3536 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3537 struct srvsvc_NetShareInfoCtr ctr_src;
3539 struct rpc_pipe_client *srvsvc_pipe = NULL;
3540 struct cli_state *cli_dst = NULL;
3541 uint32 level = 502; /* includes secdesc */
3542 uint32_t parm_error = 0;
3543 struct dcerpc_binding_handle *b;
3545 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3547 if (!W_ERROR_IS_OK(result))
3550 /* connect destination PI_SRVSVC */
3551 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe,
3552 &ndr_table_srvsvc.syntax_id);
3553 if (!NT_STATUS_IS_OK(nt_status))
3556 b = srvsvc_pipe->binding_handle;
3558 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3560 union srvsvc_NetShareInfo info;
3561 struct srvsvc_NetShareInfo502 info502 =
3562 ctr_src.ctr.ctr502->array[i];
3564 /* reset error-code */
3565 nt_status = NT_STATUS_UNSUCCESSFUL;
3567 if (!check_share_sanity(c, cli, info502.name, info502.type))
3570 /* finally add the share on the dst server */
3572 printf(_("migrating: [%s], path: %s, comment: %s, without "
3574 info502.name, info502.path, info502.comment);
3576 info.info502 = &info502;
3578 nt_status = dcerpc_srvsvc_NetShareAdd(b, mem_ctx,
3579 srvsvc_pipe->desthost,
3584 if (!NT_STATUS_IS_OK(nt_status)) {
3585 printf(_("cannot add share: %s\n"),
3586 nt_errstr(nt_status));
3589 if (W_ERROR_V(result) == W_ERROR_V(WERR_FILE_EXISTS)) {
3590 printf(_(" [%s] does already exist\n"),
3595 if (!W_ERROR_IS_OK(result)) {
3596 nt_status = werror_to_ntstatus(result);
3597 printf(_("cannot add share: %s\n"),
3598 win_errstr(result));
3604 nt_status = NT_STATUS_OK;
3608 cli_shutdown(cli_dst);
3616 * Migrate shares from a RPC server to another.
3618 * @param argc Standard main() style argc.
3619 * @param argv Standard main() style argv. Initial components are already
3622 * @return A shell status integer (0 for success).
3624 static int rpc_share_migrate_shares(struct net_context *c, int argc,
3627 if (c->display_usage) {
3629 "net rpc share migrate shares\n"
3632 _("Migrate shares to local server"));
3637 printf(_("no server to migrate\n"));
3641 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3642 rpc_share_migrate_shares_internals,
3649 * @param f file_info
3650 * @param mask current search mask
3651 * @param state arg-pointer
3654 static NTSTATUS copy_fn(const char *mnt, struct file_info *f,
3655 const char *mask, void *state)
3657 static NTSTATUS nt_status;
3658 static struct copy_clistate *local_state;
3659 static fstring filename, new_mask;
3662 struct net_context *c;
3664 local_state = (struct copy_clistate *)state;
3665 nt_status = NT_STATUS_UNSUCCESSFUL;
3669 if (strequal(f->name, ".") || strequal(f->name, ".."))
3670 return NT_STATUS_OK;
3672 DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
3675 if (f->mode & aDIR) {
3677 DEBUG(3,("got dir: %s\n", f->name));
3679 fstrcpy(dir, local_state->cwd);
3681 fstrcat(dir, f->name);
3683 switch (net_mode_share)
3685 case NET_MODE_SHARE_MIGRATE:
3686 /* create that directory */
3687 nt_status = net_copy_file(c, local_state->mem_ctx,
3688 local_state->cli_share_src,
3689 local_state->cli_share_dst,
3691 c->opt_acls? true : false,
3692 c->opt_attrs? true : false,
3693 c->opt_timestamps? true:false,
3697 d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
3698 return NT_STATUS_INTERNAL_ERROR;
3701 if (!NT_STATUS_IS_OK(nt_status)) {
3702 printf(_("could not handle dir %s: %s\n"),
3703 dir, nt_errstr(nt_status));
3707 /* search below that directory */
3708 fstrcpy(new_mask, dir);
3709 fstrcat(new_mask, "\\*");
3711 old_dir = local_state->cwd;
3712 local_state->cwd = dir;
3713 nt_status = sync_files(local_state, new_mask);
3714 if (!NT_STATUS_IS_OK(nt_status)) {
3715 printf(_("could not handle files\n"));
3717 local_state->cwd = old_dir;
3724 fstrcpy(filename, local_state->cwd);
3725 fstrcat(filename, "\\");
3726 fstrcat(filename, f->name);
3728 DEBUG(3,("got file: %s\n", filename));
3730 switch (net_mode_share)
3732 case NET_MODE_SHARE_MIGRATE:
3733 nt_status = net_copy_file(c, local_state->mem_ctx,
3734 local_state->cli_share_src,
3735 local_state->cli_share_dst,
3737 c->opt_acls? true : false,
3738 c->opt_attrs? true : false,
3739 c->opt_timestamps? true: false,
3743 d_fprintf(stderr, _("Unsupported file mode %d\n"),
3745 return NT_STATUS_INTERNAL_ERROR;
3748 if (!NT_STATUS_IS_OK(nt_status))
3749 printf(_("could not handle file %s: %s\n"),
3750 filename, nt_errstr(nt_status));
3755 * sync files, can be called recursivly to list files
3756 * and then call copy_fn for each file
3758 * @param cp_clistate pointer to the copy_clistate we work with
3759 * @param mask the current search mask
3761 * @return Boolean result
3763 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask)
3765 struct cli_state *targetcli;
3766 char *targetpath = NULL;
3769 DEBUG(3,("calling cli_list with mask: %s\n", mask));
3771 if ( !cli_resolve_path(talloc_tos(), "", NULL, cp_clistate->cli_share_src,
3772 mask, &targetcli, &targetpath ) ) {
3773 d_fprintf(stderr, _("cli_resolve_path %s failed with error: "
3775 mask, cli_errstr(cp_clistate->cli_share_src));
3776 return cli_nt_error(cp_clistate->cli_share_src);
3779 status = cli_list(targetcli, targetpath, cp_clistate->attribute,
3780 copy_fn, cp_clistate);
3781 if (!NT_STATUS_IS_OK(status)) {
3782 d_fprintf(stderr, _("listing %s failed with error: %s\n"),
3783 mask, nt_errstr(status));
3791 * Set the top level directory permissions before we do any further copies.
3792 * Should set up ACL inheritance.
3795 bool copy_top_level_perms(struct net_context *c,
3796 struct copy_clistate *cp_clistate,
3797 const char *sharename)
3799 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3801 switch (net_mode_share) {
3802 case NET_MODE_SHARE_MIGRATE:
3803 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename));
3804 nt_status = net_copy_fileattr(c,
3805 cp_clistate->mem_ctx,
3806 cp_clistate->cli_share_src,
3807 cp_clistate->cli_share_dst,
3809 c->opt_acls? true : false,
3810 c->opt_attrs? true : false,
3811 c->opt_timestamps? true: false,
3815 d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
3819 if (!NT_STATUS_IS_OK(nt_status)) {
3820 printf(_("Could handle directory attributes for top level "
3821 "directory of share %s. Error %s\n"),
3822 sharename, nt_errstr(nt_status));
3830 * Sync all files inside a remote share to another share (over smb).
3832 * All parameters are provided by the run_rpc_command function, except for
3833 * argc, argv which are passed through.
3835 * @param domain_sid The domain sid acquired from the remote server.
3836 * @param cli A cli_state connected to the server.
3837 * @param mem_ctx Talloc context, destroyed on completion of the function.
3838 * @param argc Standard main() style argc.
3839 * @param argv Standard main() style argv. Initial components are already
3842 * @return Normal NTSTATUS return.
3845 static NTSTATUS rpc_share_migrate_files_internals(struct net_context *c,
3846 const struct dom_sid *domain_sid,
3847 const char *domain_name,
3848 struct cli_state *cli,
3849 struct rpc_pipe_client *pipe_hnd,
3850 TALLOC_CTX *mem_ctx,
3855 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
3856 struct srvsvc_NetShareInfoCtr ctr_src;
3859 struct copy_clistate cp_clistate;
3860 bool got_src_share = false;
3861 bool got_dst_share = false;
3862 const char *mask = "\\*";
3865 dst = SMB_STRDUP(c->opt_destination?c->opt_destination:"127.0.0.1");
3867 nt_status = NT_STATUS_NO_MEMORY;
3871 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
3874 if (!W_ERROR_IS_OK(result))
3877 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
3879 struct srvsvc_NetShareInfo502 info502 =
3880 ctr_src.ctr.ctr502->array[i];
3882 if (!check_share_sanity(c, cli, info502.name, info502.type))
3885 /* one might not want to mirror whole discs :) */
3886 if (strequal(info502.name, "print$") || info502.name[1] == '$') {
3887 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3892 switch (net_mode_share)
3894 case NET_MODE_SHARE_MIGRATE:
3898 d_fprintf(stderr, _("Unsupported mode %d\n"),
3902 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3905 c->opt_acls ? _("including") : _("without"),
3906 c->opt_attrs ? _("including") : _("without"),
3907 c->opt_timestamps ? _("(preserving timestamps)") : "");
3909 cp_clistate.mem_ctx = mem_ctx;
3910 cp_clistate.cli_share_src = NULL;
3911 cp_clistate.cli_share_dst = NULL;
3912 cp_clistate.cwd = NULL;
3913 cp_clistate.attribute = aSYSTEM | aHIDDEN | aDIR;
3916 /* open share source */
3917 nt_status = connect_to_service(c, &cp_clistate.cli_share_src,
3918 &cli->dest_ss, cli->desthost,
3919 info502.name, "A:");
3920 if (!NT_STATUS_IS_OK(nt_status))
3923 got_src_share = true;
3925 if (net_mode_share == NET_MODE_SHARE_MIGRATE) {
3926 /* open share destination */
3927 nt_status = connect_to_service(c, &cp_clistate.cli_share_dst,
3928 NULL, dst, info502.name, "A:");
3929 if (!NT_STATUS_IS_OK(nt_status))
3932 got_dst_share = true;
3935 if (!copy_top_level_perms(c, &cp_clistate, info502.name)) {
3936 d_fprintf(stderr, _("Could not handle the top level "
3937 "directory permissions for the "
3938 "share: %s\n"), info502.name);
3939 nt_status = NT_STATUS_UNSUCCESSFUL;
3943 nt_status = sync_files(&cp_clistate, mask);
3944 if (!NT_STATUS_IS_OK(nt_status)) {
3945 d_fprintf(stderr, _("could not handle files for share: "
3946 "%s\n"), info502.name);
3951 nt_status = NT_STATUS_OK;
3956 cli_shutdown(cp_clistate.cli_share_src);
3959 cli_shutdown(cp_clistate.cli_share_dst);
3966 static int rpc_share_migrate_files(struct net_context *c, int argc, const char **argv)
3968 if (c->display_usage) {
3970 "net share migrate files\n"
3973 _("Migrate files to local server"));
3978 d_printf(_("no server to migrate\n"));
3982 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
3983 rpc_share_migrate_files_internals,
3988 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3990 * All parameters are provided by the run_rpc_command function, except for
3991 * argc, argv which are passed through.
3993 * @param domain_sid The domain sid acquired from the remote server.
3994 * @param cli A cli_state connected to the server.
3995 * @param mem_ctx Talloc context, destroyed on completion of the function.
3996 * @param argc Standard main() style argc.
3997 * @param argv Standard main() style argv. Initial components are already
4000 * @return Normal NTSTATUS return.
4003 static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c,
4004 const struct dom_sid *domain_sid,
4005 const char *domain_name,
4006 struct cli_state *cli,
4007 struct rpc_pipe_client *pipe_hnd,
4008 TALLOC_CTX *mem_ctx,
4013 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
4014 struct srvsvc_NetShareInfoCtr ctr_src;
4015 union srvsvc_NetShareInfo info;
4017 struct rpc_pipe_client *srvsvc_pipe = NULL;
4018 struct cli_state *cli_dst = NULL;
4019 uint32 level = 502; /* includes secdesc */
4020 uint32_t parm_error = 0;
4021 struct dcerpc_binding_handle *b;
4023 result = get_share_info(c, pipe_hnd, mem_ctx, level, argc, argv,
4026 if (!W_ERROR_IS_OK(result))
4029 /* connect destination PI_SRVSVC */
4030 nt_status = connect_dst_pipe(c, &cli_dst, &srvsvc_pipe,
4031 &ndr_table_srvsvc.syntax_id);
4032 if (!NT_STATUS_IS_OK(nt_status))
4035 b = srvsvc_pipe->binding_handle;
4037 for (i = 0; i < ctr_src.ctr.ctr502->count; i++) {
4039 struct srvsvc_NetShareInfo502 info502 =
4040 ctr_src.ctr.ctr502->array[i];
4042 /* reset error-code */
4043 nt_status = NT_STATUS_UNSUCCESSFUL;
4045 if (!check_share_sanity(c, cli, info502.name, info502.type))
4048 printf(_("migrating: [%s], path: %s, comment: %s, including "
4050 info502.name, info502.path, info502.comment);
4053 display_sec_desc(info502.sd_buf.sd);
4055 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4056 info.info502 = &info502;
4058 /* finally modify the share on the dst server */
4059 nt_status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
4060 srvsvc_pipe->desthost,
4066 if (!NT_STATUS_IS_OK(nt_status)) {
4067 printf(_("cannot set share-acl: %s\n"),
4068 nt_errstr(nt_status));
4071 if (!W_ERROR_IS_OK(result)) {
4072 nt_status = werror_to_ntstatus(result);
4073 printf(_("cannot set share-acl: %s\n"),
4074 win_errstr(result));
4080 nt_status = NT_STATUS_OK;
4084 cli_shutdown(cli_dst);
4092 * Migrate share-acls from a RPC server to another.
4094 * @param argc Standard main() style argc.
4095 * @param argv Standard main() style argv. Initial components are already
4098 * @return A shell status integer (0 for success).
4100 static int rpc_share_migrate_security(struct net_context *c, int argc,
4103 if (c->display_usage) {
4105 "net rpc share migrate security\n"
4108 _("Migrate share-acls to local server"));
4113 d_printf(_("no server to migrate\n"));
4117 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4118 rpc_share_migrate_security_internals,
4123 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4124 * from one server to another.
4126 * @param argc Standard main() style argc.
4127 * @param argv Standard main() style argv. Initial components are already
4130 * @return A shell status integer (0 for success).
4133 static int rpc_share_migrate_all(struct net_context *c, int argc,
4138 if (c->display_usage) {
4140 "net rpc share migrate all\n"
4143 _("Migrates shares including all share settings"));
4148 d_printf(_("no server to migrate\n"));
4152 /* order is important. we don't want to be locked out by the share-acl
4153 * before copying files - gd */
4155 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4156 rpc_share_migrate_shares_internals, argc, argv);
4160 ret = run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4161 rpc_share_migrate_files_internals, argc, argv);
4165 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4166 rpc_share_migrate_security_internals, argc,
4172 * 'net rpc share migrate' entrypoint.
4173 * @param argc Standard main() style argc.
4174 * @param argv Standard main() style argv. Initial components are already
4177 static int rpc_share_migrate(struct net_context *c, int argc, const char **argv)
4180 struct functable func[] = {
4183 rpc_share_migrate_all,
4185 N_("Migrate shares from remote to local server"),
4186 N_("net rpc share migrate all\n"
4187 " Migrate shares from remote to local server")
4191 rpc_share_migrate_files,
4193 N_("Migrate files from remote to local server"),
4194 N_("net rpc share migrate files\n"
4195 " Migrate files from remote to local server")
4199 rpc_share_migrate_security,
4201 N_("Migrate share-ACLs from remote to local server"),
4202 N_("net rpc share migrate security\n"
4203 " Migrate share-ACLs from remote to local server")
4207 rpc_share_migrate_shares,
4209 N_("Migrate shares from remote to local server"),
4210 N_("net rpc share migrate shares\n"
4211 " Migrate shares from remote to local server")
4213 {NULL, NULL, 0, NULL, NULL}
4216 net_mode_share = NET_MODE_SHARE_MIGRATE;
4218 return net_run_function(c, argc, argv, "net rpc share migrate", func);
4224 struct dom_sid *members;
4227 static int num_server_aliases;
4228 static struct full_alias *server_aliases;
4231 * Add an alias to the static list.
4233 static void push_alias(TALLOC_CTX *mem_ctx, struct full_alias *alias)
4235 if (server_aliases == NULL)
4236 server_aliases = SMB_MALLOC_ARRAY(struct full_alias, 100);
4238 server_aliases[num_server_aliases] = *alias;
4239 num_server_aliases += 1;
4243 * For a specific domain on the server, fetch all the aliases
4244 * and their members. Add all of them to the server_aliases.
4247 static NTSTATUS rpc_fetch_domain_aliases(struct rpc_pipe_client *pipe_hnd,
4248 TALLOC_CTX *mem_ctx,
4249 struct policy_handle *connect_pol,
4250 const struct dom_sid *domain_sid)
4252 uint32 start_idx, max_entries, num_entries, i;
4253 struct samr_SamArray *groups = NULL;
4255 struct policy_handle domain_pol;
4257 /* Get domain policy handle */
4259 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
4261 MAXIMUM_ALLOWED_ACCESS,
4262 CONST_DISCARD(struct dom_sid2 *, domain_sid),
4264 if (!NT_STATUS_IS_OK(result))
4271 result = rpccli_samr_EnumDomainAliases(pipe_hnd, mem_ctx,
4277 for (i = 0; i < num_entries; i++) {
4279 struct policy_handle alias_pol;
4280 struct full_alias alias;
4281 struct lsa_SidArray sid_array;
4284 result = rpccli_samr_OpenAlias(pipe_hnd, mem_ctx,
4286 MAXIMUM_ALLOWED_ACCESS,
4287 groups->entries[i].idx,
4289 if (!NT_STATUS_IS_OK(result))
4292 result = rpccli_samr_GetMembersInAlias(pipe_hnd, mem_ctx,
4295 if (!NT_STATUS_IS_OK(result))
4298 alias.num_members = sid_array.num_sids;
4300 result = rpccli_samr_Close(pipe_hnd, mem_ctx, &alias_pol);
4301 if (!NT_STATUS_IS_OK(result))
4304 alias.members = NULL;
4306 if (alias.num_members > 0) {
4307 alias.members = SMB_MALLOC_ARRAY(struct dom_sid, alias.num_members);
4309 for (j = 0; j < alias.num_members; j++)
4310 sid_copy(&alias.members[j],
4311 sid_array.sids[j].sid);
4314 sid_compose(&alias.sid, domain_sid,
4315 groups->entries[i].idx);
4317 push_alias(mem_ctx, &alias);
4319 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
4321 result = NT_STATUS_OK;
4324 rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_pol);
4330 * Dump server_aliases as names for debugging purposes.
4333 static NTSTATUS rpc_aliaslist_dump(struct net_context *c,
4334 const struct dom_sid *domain_sid,
4335 const char *domain_name,
4336 struct cli_state *cli,
4337 struct rpc_pipe_client *pipe_hnd,
4338 TALLOC_CTX *mem_ctx,
4344 struct policy_handle lsa_pol;
4346 result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
4347 SEC_FLAG_MAXIMUM_ALLOWED,
4349 if (!NT_STATUS_IS_OK(result))
4352 for (i=0; i<num_server_aliases; i++) {
4355 enum lsa_SidType *types;
4358 struct full_alias *alias = &server_aliases[i];
4360 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol, 1,
4362 &domains, &names, &types);
4363 if (!NT_STATUS_IS_OK(result))
4366 DEBUG(1, ("%s\\%s %d: ", domains[0], names[0], types[0]));
4368 if (alias->num_members == 0) {
4373 result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &lsa_pol,
4376 &domains, &names, &types);
4378 if (!NT_STATUS_IS_OK(result) &&
4379 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
4382 for (j=0; j<alias->num_members; j++)
4383 DEBUG(1, ("%s\\%s (%d); ",
4384 domains[j] ? domains[j] : "*unknown*",
4385 names[j] ? names[j] : "*unknown*",types[j]));
4389 rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
4391 return NT_STATUS_OK;
4395 * Fetch a list of all server aliases and their members into
4399 static NTSTATUS rpc_aliaslist_internals(struct net_context *c,
4400 const struct dom_sid *domain_sid,
4401 const char *domain_name,
4402 struct cli_state *cli,
4403 struct rpc_pipe_client *pipe_hnd,
4404 TALLOC_CTX *mem_ctx,
4409 struct policy_handle connect_pol;
4411 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
4413 MAXIMUM_ALLOWED_ACCESS,
4416 if (!NT_STATUS_IS_OK(result))
4419 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4420 &global_sid_Builtin);
4422 if (!NT_STATUS_IS_OK(result))
4425 result = rpc_fetch_domain_aliases(pipe_hnd, mem_ctx, &connect_pol,
4428 rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_pol);
4433 static void init_user_token(struct security_token *token, struct dom_sid *user_sid)
4435 token->num_sids = 4;
4437 if (!(token->sids = SMB_MALLOC_ARRAY(struct dom_sid, 4))) {
4438 d_fprintf(stderr, "malloc %s\n",_("failed"));
4439 token->num_sids = 0;
4443 token->sids[0] = *user_sid;
4444 sid_copy(&token->sids[1], &global_sid_World);
4445 sid_copy(&token->sids[2], &global_sid_Network);
4446 sid_copy(&token->sids[3], &global_sid_Authenticated_Users);
4449 static void free_user_token(struct security_token *token)
4451 SAFE_FREE(token->sids);
4454 static void add_sid_to_token(struct security_token *token, struct dom_sid *sid)
4456 if (security_token_has_sid(token, sid))
4459 token->sids = SMB_REALLOC_ARRAY(token->sids, struct dom_sid, token->num_sids+1);
4464 sid_copy(&token->sids[token->num_sids], sid);
4466 token->num_sids += 1;
4471 struct security_token token;
4474 static void dump_user_token(struct user_token *token)
4478 d_printf("%s\n", token->name);
4480 for (i=0; i<token->token.num_sids; i++) {
4481 d_printf(" %s\n", sid_string_tos(&token->token.sids[i]));
4485 static bool is_alias_member(struct dom_sid *sid, struct full_alias *alias)
4489 for (i=0; i<alias->num_members; i++) {
4490 if (dom_sid_compare(sid, &alias->members[i]) == 0)
4497 static void collect_sid_memberships(struct security_token *token, struct dom_sid sid)
4501 for (i=0; i<num_server_aliases; i++) {
4502 if (is_alias_member(&sid, &server_aliases[i]))
4503 add_sid_to_token(token, &server_aliases[i].sid);
4508 * We got a user token with all the SIDs we can know about without asking the
4509 * server directly. These are the user and domain group sids. All of these can
4510 * be members of aliases. So scan the list of aliases for each of the SIDs and
4511 * add them to the token.
4514 static void collect_alias_memberships(struct security_token *token)
4516 int num_global_sids = token->num_sids;
4519 for (i=0; i<num_global_sids; i++) {
4520 collect_sid_memberships(token, token->sids[i]);
4524 static bool get_user_sids(const char *domain, const char *user, struct security_token *token)
4526 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4527 enum wbcSidType type;
4529 struct wbcDomainSid wsid;
4530 char *sid_str = NULL;
4531 struct dom_sid user_sid;
4532 uint32_t num_groups;
4533 gid_t *groups = NULL;
4536 fstr_sprintf(full_name, "%s%c%s",
4537 domain, *lp_winbind_separator(), user);
4539 /* First let's find out the user sid */
4541 wbc_status = wbcLookupName(domain, user, &wsid, &type);
4543 if (!WBC_ERROR_IS_OK(wbc_status)) {
4544 DEBUG(1, ("winbind could not find %s: %s\n",
4545 full_name, wbcErrorString(wbc_status)));
4549 wbc_status = wbcSidToString(&wsid, &sid_str);
4550 if (!WBC_ERROR_IS_OK(wbc_status)) {
4554 if (type != WBC_SID_NAME_USER) {
4555 wbcFreeMemory(sid_str);
4556 DEBUG(1, ("%s is not a user\n", full_name));
4560 if (!string_to_sid(&user_sid, sid_str)) {
4561 DEBUG(1,("Could not convert sid %s from string\n", sid_str));
4565 wbcFreeMemory(sid_str);
4568 init_user_token(token, &user_sid);
4570 /* And now the groups winbind knows about */
4572 wbc_status = wbcGetGroups(full_name, &num_groups, &groups);
4573 if (!WBC_ERROR_IS_OK(wbc_status)) {
4574 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4575 full_name, wbcErrorString(wbc_status)));
4579 for (i = 0; i < num_groups; i++) {
4580 gid_t gid = groups[i];
4583 wbc_status = wbcGidToSid(gid, &wsid);
4584 if (!WBC_ERROR_IS_OK(wbc_status)) {
4585 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4586 (unsigned int)gid, wbcErrorString(wbc_status)));
4587 wbcFreeMemory(groups);
4591 wbc_status = wbcSidToString(&wsid, &sid_str);
4592 if (!WBC_ERROR_IS_OK(wbc_status)) {
4593 wbcFreeMemory(groups);
4597 DEBUG(3, (" %s\n", sid_str));
4599 string_to_sid(&sid, sid_str);
4600 wbcFreeMemory(sid_str);
4603 add_sid_to_token(token, &sid);
4605 wbcFreeMemory(groups);
4611 * Get a list of all user tokens we want to look at
4614 static bool get_user_tokens(struct net_context *c, int *num_tokens,
4615 struct user_token **user_tokens)
4617 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
4618 uint32_t i, num_users;
4620 struct user_token *result;
4621 TALLOC_CTX *frame = NULL;
4623 if (lp_winbind_use_default_domain() &&
4624 (c->opt_target_workgroup == NULL)) {
4625 d_fprintf(stderr, _("winbind use default domain = yes set, "
4626 "please specify a workgroup\n"));
4630 /* Send request to winbind daemon */
4632 wbc_status = wbcListUsers(NULL, &num_users, &users);
4633 if (!WBC_ERROR_IS_OK(wbc_status)) {
4634 DEBUG(1, (_("winbind could not list users: %s\n"),
4635 wbcErrorString(wbc_status)));
4639 result = SMB_MALLOC_ARRAY(struct user_token, num_users);
4641 if (result == NULL) {
4642 DEBUG(1, ("Could not malloc sid array\n"));
4643 wbcFreeMemory(users);
4647 frame = talloc_stackframe();
4648 for (i=0; i < num_users; i++) {
4649 fstring domain, user;
4652 fstrcpy(result[i].name, users[i]);
4654 p = strchr(users[i], *lp_winbind_separator());
4656 DEBUG(3, ("%s\n", users[i]));
4659 fstrcpy(domain, c->opt_target_workgroup);
4660 fstrcpy(user, users[i]);
4663 fstrcpy(domain, users[i]);
4668 get_user_sids(domain, user, &(result[i].token));
4671 wbcFreeMemory(users);
4673 *num_tokens = num_users;
4674 *user_tokens = result;
4679 static bool get_user_tokens_from_file(FILE *f,
4681 struct user_token **tokens)
4683 struct user_token *token = NULL;
4688 if (fgets(line, sizeof(line)-1, f) == NULL) {
4692 if ((strlen(line) > 0) && (line[strlen(line)-1] == '\n')) {
4693 line[strlen(line)-1] = '\0';
4696 if (line[0] == ' ') {
4700 if(!string_to_sid(&sid, &line[1])) {
4701 DEBUG(1,("get_user_tokens_from_file: Could "
4702 "not convert sid %s \n",&line[1]));
4706 if (token == NULL) {
4707 DEBUG(0, ("File does not begin with username"));
4711 add_sid_to_token(&token->token, &sid);
4715 /* And a new user... */
4718 *tokens = SMB_REALLOC_ARRAY(*tokens, struct user_token, *num_tokens);
4719 if (*tokens == NULL) {
4720 DEBUG(0, ("Could not realloc tokens\n"));
4724 token = &((*tokens)[*num_tokens-1]);
4726 fstrcpy(token->name, line);
4727 token->token.num_sids = 0;
4728 token->token.sids = NULL;
4737 * Show the list of all users that have access to a share
4740 static void show_userlist(struct rpc_pipe_client *pipe_hnd,
4741 TALLOC_CTX *mem_ctx,
4742 const char *netname,
4744 struct user_token *tokens)
4747 struct security_descriptor *share_sd = NULL;
4748 struct security_descriptor *root_sd = NULL;
4749 struct cli_state *cli = rpc_pipe_np_smb_conn(pipe_hnd);
4751 union srvsvc_NetShareInfo info;
4755 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
4757 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
4764 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
4765 DEBUG(1, ("Coult not query secdesc for share %s\n",
4770 share_sd = info.info502->sd_buf.sd;
4771 if (share_sd == NULL) {
4772 DEBUG(1, ("Got no secdesc for share %s\n",
4778 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
4782 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, "\\", 0, READ_CONTROL_ACCESS, 0,
4783 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
4784 root_sd = cli_query_secdesc(cli, fnum, mem_ctx);
4787 for (i=0; i<num_tokens; i++) {
4790 if (share_sd != NULL) {
4791 status = se_access_check(share_sd, &tokens[i].token,
4794 if (!NT_STATUS_IS_OK(status)) {
4795 DEBUG(1, ("Could not check share_sd for "
4802 if (root_sd == NULL) {
4803 d_printf(" %s\n", tokens[i].name);
4807 status = se_access_check(root_sd, &tokens[i].token,
4809 if (!NT_STATUS_IS_OK(status)) {
4810 DEBUG(1, ("Could not check root_sd for user %s\n",
4814 d_printf(" %s\n", tokens[i].name);
4817 if (fnum != (uint16_t)-1)
4818 cli_close(cli, fnum);
4830 static void collect_share(const char *name, uint32 m,
4831 const char *comment, void *state)
4833 struct share_list *share_list = (struct share_list *)state;
4835 if (m != STYPE_DISKTREE)
4838 share_list->num_shares += 1;
4839 share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares);
4840 if (!share_list->shares) {
4841 share_list->num_shares = 0;
4844 share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name);
4848 * List shares on a remote RPC server, including the security descriptors.
4850 * All parameters are provided by the run_rpc_command function, except for
4851 * argc, argv which are passed through.
4853 * @param domain_sid The domain sid acquired from the remote server.
4854 * @param cli A cli_state connected to the server.
4855 * @param mem_ctx Talloc context, destroyed on completion of the function.
4856 * @param argc Standard main() style argc.
4857 * @param argv Standard main() style argv. Initial components are already
4860 * @return Normal NTSTATUS return.
4863 static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
4864 const struct dom_sid *domain_sid,
4865 const char *domain_name,
4866 struct cli_state *cli,
4867 struct rpc_pipe_client *pipe_hnd,
4868 TALLOC_CTX *mem_ctx,
4877 struct user_token *tokens = NULL;
4880 struct share_list share_list;
4885 f = fopen(argv[0], "r");
4889 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno)));
4890 return NT_STATUS_UNSUCCESSFUL;
4893 r = get_user_tokens_from_file(f, &num_tokens, &tokens);
4899 DEBUG(0, ("Could not read users from file\n"));
4900 return NT_STATUS_UNSUCCESSFUL;
4903 for (i=0; i<num_tokens; i++)
4904 collect_alias_memberships(&tokens[i].token);
4906 share_list.num_shares = 0;
4907 share_list.shares = NULL;
4909 ret = cli_RNetShareEnum(cli, collect_share, &share_list);
4912 DEBUG(0, ("Error returning browse list: %s\n",
4917 for (i = 0; i < share_list.num_shares; i++) {
4918 char *netname = share_list.shares[i];
4920 if (netname[strlen(netname)-1] == '$')
4923 d_printf("%s\n", netname);
4925 show_userlist(pipe_hnd, mem_ctx, netname,
4926 num_tokens, tokens);
4929 for (i=0; i<num_tokens; i++) {
4930 free_user_token(&tokens[i].token);
4933 SAFE_FREE(share_list.shares);
4935 return NT_STATUS_OK;
4938 static int rpc_share_allowedusers(struct net_context *c, int argc,
4943 if (c->display_usage) {
4945 "net rpc share allowedusers\n"
4948 _("List allowed users"));
4952 result = run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
4953 rpc_aliaslist_internals,
4958 result = run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
4964 return run_rpc_command(c, NULL, &ndr_table_srvsvc.syntax_id, 0,
4965 rpc_share_allowedusers_internals,
4969 int net_usersidlist(struct net_context *c, int argc, const char **argv)
4972 struct user_token *tokens = NULL;
4976 net_usersidlist_usage(c, argc, argv);
4980 if (!get_user_tokens(c, &num_tokens, &tokens)) {
4981 DEBUG(0, ("Could not get the user/sid list\n"));
4985 for (i=0; i<num_tokens; i++) {
4986 dump_user_token(&tokens[i]);
4987 free_user_token(&tokens[i].token);
4994 int net_usersidlist_usage(struct net_context *c, int argc, const char **argv)
4996 d_printf(_("net usersidlist\n"
4997 "\tprints out a list of all users the running winbind knows\n"
4998 "\tabout, together with all their SIDs. This is used as\n"
4999 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
5001 net_common_flags_usage(c, argc, argv);
5006 * 'net rpc share' entrypoint.
5007 * @param argc Standard main() style argc.
5008 * @param argv Standard main() style argv. Initial components are already
5012 int net_rpc_share(struct net_context *c, int argc, const char **argv)
5014 NET_API_STATUS status;
5016 struct functable func[] = {
5022 N_("net rpc share add\n"
5030 N_("net rpc share delete\n"
5035 rpc_share_allowedusers,
5037 N_("Modify allowed users"),
5038 N_("net rpc share allowedusers\n"
5039 " Modify allowed users")
5045 N_("Migrate share to local server"),
5046 N_("net rpc share migrate\n"
5047 " Migrate share to local server")
5054 N_("net rpc share list\n"
5057 {NULL, NULL, 0, NULL, NULL}
5060 status = libnetapi_net_init(&c->netapi_ctx);
5064 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
5065 libnetapi_set_password(c->netapi_ctx, c->opt_password);
5066 if (c->opt_kerberos) {
5067 libnetapi_set_use_kerberos(c->netapi_ctx);
5071 if (c->display_usage) {
5076 " Alias for net rpc share list\n"));
5077 net_display_usage_from_functable(func);
5081 return rpc_share_list(c, argc, argv);
5084 return net_run_function(c, argc, argv, "net rpc share", func);
5087 static NTSTATUS rpc_sh_share_list(struct net_context *c,
5088 TALLOC_CTX *mem_ctx,
5089 struct rpc_sh_ctx *ctx,
5090 struct rpc_pipe_client *pipe_hnd,
5091 int argc, const char **argv)
5094 return werror_to_ntstatus(W_ERROR(rpc_share_list(c, argc, argv)));
5097 static NTSTATUS rpc_sh_share_add(struct net_context *c,
5098 TALLOC_CTX *mem_ctx,
5099 struct rpc_sh_ctx *ctx,
5100 struct rpc_pipe_client *pipe_hnd,
5101 int argc, const char **argv)
5103 NET_API_STATUS status;
5104 uint32_t parm_err = 0;
5105 struct SHARE_INFO_2 i2;
5107 if ((argc < 2) || (argc > 3)) {
5108 d_fprintf(stderr, _("Usage: %s <share> <path> [comment]\n"),
5110 return NT_STATUS_INVALID_PARAMETER;
5113 i2.shi2_netname = argv[0];
5114 i2.shi2_type = STYPE_DISKTREE;
5115 i2.shi2_remark = (argc == 3) ? argv[2] : "";
5116 i2.shi2_permissions = 0;
5117 i2.shi2_max_uses = 0;
5118 i2.shi2_current_uses = 0;
5119 i2.shi2_path = argv[1];
5120 i2.shi2_passwd = NULL;
5122 status = NetShareAdd(pipe_hnd->desthost,
5127 return werror_to_ntstatus(W_ERROR(status));
5130 static NTSTATUS rpc_sh_share_delete(struct net_context *c,
5131 TALLOC_CTX *mem_ctx,
5132 struct rpc_sh_ctx *ctx,
5133 struct rpc_pipe_client *pipe_hnd,
5134 int argc, const char **argv)
5137 d_fprintf(stderr, "%s %s <share>\n", _("Usage:"), ctx->whoami);
5138 return NT_STATUS_INVALID_PARAMETER;
5141 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd->desthost, argv[0], 0)));
5144 static NTSTATUS rpc_sh_share_info(struct net_context *c,
5145 TALLOC_CTX *mem_ctx,
5146 struct rpc_sh_ctx *ctx,
5147 struct rpc_pipe_client *pipe_hnd,
5148 int argc, const char **argv)
5150 union srvsvc_NetShareInfo info;
5153 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5156 d_fprintf(stderr, "%s %s <share>\n", _("Usage:"), ctx->whoami);
5157 return NT_STATUS_INVALID_PARAMETER;
5160 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
5166 if (!NT_STATUS_IS_OK(status)) {
5167 result = ntstatus_to_werror(status);
5170 if (!W_ERROR_IS_OK(result)) {
5174 d_printf(_("Name: %s\n"), info.info2->name);
5175 d_printf(_("Comment: %s\n"), info.info2->comment);
5176 d_printf(_("Path: %s\n"), info.info2->path);
5177 d_printf(_("Password: %s\n"), info.info2->password);
5180 return werror_to_ntstatus(result);
5183 struct rpc_sh_cmd *net_rpc_share_cmds(struct net_context *c, TALLOC_CTX *mem_ctx,
5184 struct rpc_sh_ctx *ctx)
5186 static struct rpc_sh_cmd cmds[] = {
5188 { "list", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_list,
5189 N_("List available shares") },
5191 { "add", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_add,
5192 N_("Add a share") },
5194 { "delete", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_delete,
5195 N_("Delete a share") },
5197 { "info", NULL, &ndr_table_srvsvc.syntax_id, rpc_sh_share_info,
5198 N_("Get information about a share") },
5200 { NULL, NULL, 0, NULL, NULL }
5206 /****************************************************************************/
5208 static int rpc_file_usage(struct net_context *c, int argc, const char **argv)
5210 return net_file_usage(c, argc, argv);
5214 * Close a file on a remote RPC server.
5216 * @param argc Standard main() style argc.
5217 * @param argv Standard main() style argv. Initial components are already
5220 * @return A shell status integer (0 for success).
5222 static int rpc_file_close(struct net_context *c, int argc, const char **argv)
5224 if (argc < 1 || c->display_usage) {
5225 return rpc_file_usage(c, argc, argv);
5228 return NetFileClose(c->opt_host, atoi(argv[0]));
5232 * Formatted print of open file info
5234 * @param r struct FILE_INFO_3 contents
5237 static void display_file_info_3(struct FILE_INFO_3 *r)
5239 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5240 r->fi3_id, r->fi3_username, r->fi3_permissions,
5241 r->fi3_num_locks, r->fi3_pathname);
5245 * List files for a user on a remote RPC server.
5247 * @param argc Standard main() style argc.
5248 * @param argv Standard main() style argv. Initial components are already
5251 * @return A shell status integer (0 for success)..
5254 static int rpc_file_user(struct net_context *c, int argc, const char **argv)
5256 NET_API_STATUS status;
5257 uint32 preferred_len = 0xffffffff, i;
5258 const char *username=NULL;
5259 uint32_t total_entries = 0;
5260 uint32_t entries_read = 0;
5261 uint32_t resume_handle = 0;
5262 struct FILE_INFO_3 *i3 = NULL;
5264 if (c->display_usage) {
5265 return rpc_file_usage(c, argc, argv);
5268 /* if argc > 0, must be user command */
5270 username = smb_xstrdup(argv[0]);
5273 status = NetFileEnum(c->opt_host,
5277 (uint8_t **)(void *)&i3,
5287 /* Display results */
5290 "\nEnumerating open files on remote server:\n\n"
5291 "\nFileId Opened by Perms Locks Path"
5292 "\n------ --------- ----- ----- ---- \n"));
5293 for (i = 0; i < entries_read; i++) {
5294 display_file_info_3(&i3[i]);
5301 * 'net rpc file' entrypoint.
5302 * @param argc Standard main() style argc.
5303 * @param argv Standard main() style argv. Initial components are already
5307 int net_rpc_file(struct net_context *c, int argc, const char **argv)
5309 NET_API_STATUS status;
5311 struct functable func[] = {
5316 N_("Close opened file"),
5317 N_("net rpc file close\n"
5318 " Close opened file")
5324 N_("List files opened by user"),
5325 N_("net rpc file user\n"
5326 " List files opened by user")
5333 N_("Display information about opened file"),
5334 N_("net rpc file info\n"
5335 " Display information about opened file")
5338 {NULL, NULL, 0, NULL, NULL}
5341 status = libnetapi_net_init(&c->netapi_ctx);
5345 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
5346 libnetapi_set_password(c->netapi_ctx, c->opt_password);
5347 if (c->opt_kerberos) {
5348 libnetapi_set_use_kerberos(c->netapi_ctx);
5352 if (c->display_usage) {
5353 d_printf(_("Usage:\n"));
5354 d_printf(_("net rpc file\n"
5355 " List opened files\n"));
5356 net_display_usage_from_functable(func);
5360 return rpc_file_user(c, argc, argv);
5363 return net_run_function(c, argc, argv, "net rpc file", func);
5367 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5369 * All parameters are provided by the run_rpc_command function, except for
5370 * argc, argv which are passed through.
5372 * @param c A net_context structure.
5373 * @param domain_sid The domain sid acquired from the remote server.
5374 * @param cli A cli_state connected to the server.
5375 * @param mem_ctx Talloc context, destroyed on completion of the function.
5376 * @param argc Standard main() style argc.
5377 * @param argv Standard main() style argv. Initial components are already
5380 * @return Normal NTSTATUS return.
5383 static NTSTATUS rpc_shutdown_abort_internals(struct net_context *c,
5384 const struct dom_sid *domain_sid,
5385 const char *domain_name,
5386 struct cli_state *cli,
5387 struct rpc_pipe_client *pipe_hnd,
5388 TALLOC_CTX *mem_ctx,
5392 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
5394 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5396 status = dcerpc_initshutdown_Abort(b, mem_ctx, NULL, &result);
5397 if (!NT_STATUS_IS_OK(status)) {
5400 if (W_ERROR_IS_OK(result)) {
5401 d_printf(_("\nShutdown successfully aborted\n"));
5402 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5404 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5406 return werror_to_ntstatus(result);
5410 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5412 * All parameters are provided by the run_rpc_command function, except for
5413 * argc, argv which are passed through.
5415 * @param c A net_context structure.
5416 * @param domain_sid The domain sid acquired from the remote server.
5417 * @param cli A cli_state connected to the server.
5418 * @param mem_ctx Talloc context, destroyed on completion of the function.
5419 * @param argc Standard main() style argc.
5420 * @param argv Standard main() style argv. Initial components are already
5423 * @return Normal NTSTATUS return.
5426 static NTSTATUS rpc_reg_shutdown_abort_internals(struct net_context *c,
5427 const struct dom_sid *domain_sid,
5428 const char *domain_name,
5429 struct cli_state *cli,
5430 struct rpc_pipe_client *pipe_hnd,
5431 TALLOC_CTX *mem_ctx,
5435 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5437 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5439 result = dcerpc_winreg_AbortSystemShutdown(b, mem_ctx, NULL, &werr);
5441 if (!NT_STATUS_IS_OK(result)) {
5442 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5445 if (W_ERROR_IS_OK(werr)) {
5446 d_printf(_("\nShutdown successfully aborted\n"));
5447 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5449 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5451 return werror_to_ntstatus(werr);
5455 * ABORT the shutdown of a remote RPC server.
5457 * @param argc Standard main() style argc.
5458 * @param argv Standard main() style argv. Initial components are already
5461 * @return A shell status integer (0 for success).
5464 static int rpc_shutdown_abort(struct net_context *c, int argc,
5469 if (c->display_usage) {
5471 "net rpc abortshutdown\n"
5474 _("Abort a scheduled shutdown"));
5478 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5479 rpc_shutdown_abort_internals, argc, argv);
5484 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5486 return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5487 rpc_reg_shutdown_abort_internals,
5492 * Shut down a remote RPC Server via initshutdown pipe.
5494 * All parameters are provided by the run_rpc_command function, except for
5495 * argc, argv which are passed through.
5497 * @param c A net_context structure.
5498 * @param domain_sid The domain sid acquired from the remote server.
5499 * @param cli A cli_state connected to the server.
5500 * @param mem_ctx Talloc context, destroyed on completion of the function.
5501 * @param argc Standard main() style argc.
5502 * @param argv Standard main() style argv. Initial components are already
5505 * @return Normal NTSTATUS return.
5508 NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
5509 const struct dom_sid *domain_sid,
5510 const char *domain_name,
5511 struct cli_state *cli,
5512 struct rpc_pipe_client *pipe_hnd,
5513 TALLOC_CTX *mem_ctx,
5517 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
5519 const char *msg = N_("This machine will be shutdown shortly");
5520 uint32 timeout = 20;
5521 struct lsa_StringLarge msg_string;
5522 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5524 if (c->opt_comment) {
5525 msg = c->opt_comment;
5527 if (c->opt_timeout) {
5528 timeout = c->opt_timeout;
5531 msg_string.string = msg;
5533 /* create an entry */
5534 status = dcerpc_initshutdown_Init(b, mem_ctx, NULL,
5535 &msg_string, timeout, c->opt_force, c->opt_reboot,
5537 if (!NT_STATUS_IS_OK(status)) {
5540 if (W_ERROR_IS_OK(result)) {
5541 d_printf(_("\nShutdown of remote machine succeeded\n"));
5542 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5544 DEBUG(1,("Shutdown of remote machine failed!\n"));
5546 return werror_to_ntstatus(result);
5550 * Shut down a remote RPC Server via winreg pipe.
5552 * All parameters are provided by the run_rpc_command function, except for
5553 * argc, argv which are passed through.
5555 * @param c A net_context structure.
5556 * @param domain_sid The domain sid acquired from the remote server.
5557 * @param cli A cli_state connected to the server.
5558 * @param mem_ctx Talloc context, destroyed on completion of the function.
5559 * @param argc Standard main() style argc.
5560 * @param argv Standard main() style argv. Initial components are already
5563 * @return Normal NTSTATUS return.
5566 NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
5567 const struct dom_sid *domain_sid,
5568 const char *domain_name,
5569 struct cli_state *cli,
5570 struct rpc_pipe_client *pipe_hnd,
5571 TALLOC_CTX *mem_ctx,
5575 const char *msg = N_("This machine will be shutdown shortly");
5576 uint32 timeout = 20;
5577 struct lsa_StringLarge msg_string;
5580 struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
5582 if (c->opt_comment) {
5583 msg = c->opt_comment;
5585 msg_string.string = msg;
5587 if (c->opt_timeout) {
5588 timeout = c->opt_timeout;
5591 /* create an entry */
5592 result = dcerpc_winreg_InitiateSystemShutdown(b, mem_ctx, NULL,
5593 &msg_string, timeout, c->opt_force, c->opt_reboot,
5595 if (!NT_STATUS_IS_OK(result)) {
5596 d_fprintf(stderr, "\nShutdown of remote machine failed\n");
5600 if (W_ERROR_IS_OK(werr)) {
5601 d_printf(_("\nShutdown of remote machine succeeded\n"));
5603 d_fprintf(stderr, "\nShutdown of remote machine failed\n");
5604 if ( W_ERROR_EQUAL(werr, WERR_MACHINE_LOCKED) )
5605 d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
5607 d_fprintf(stderr, "\nresult was: %s\n", win_errstr(werr));
5610 return werror_to_ntstatus(werr);
5614 * Shut down a remote RPC server.
5616 * @param argc Standard main() style argc.
5617 * @param argv Standard main() style argv. Initial components are already
5620 * @return A shell status integer (0 for success).
5623 static int rpc_shutdown(struct net_context *c, int argc, const char **argv)
5627 if (c->display_usage) {
5629 "net rpc shutdown\n"
5632 _("Shut down a remote RPC server"));
5636 rc = run_rpc_command(c, NULL, &ndr_table_initshutdown.syntax_id, 0,
5637 rpc_init_shutdown_internals, argc, argv);
5640 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5641 rc = run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0,
5642 rpc_reg_shutdown_internals, argc, argv);
5648 /***************************************************************************
5649 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5650 ***************************************************************************/
5653 * Add interdomain trust account to the RPC server.
5654 * All parameters (except for argc and argv) are passed by run_rpc_command
5657 * @param c A net_context structure.
5658 * @param domain_sid The domain sid acquired from the server.
5659 * @param cli A cli_state connected to the server.
5660 * @param mem_ctx Talloc context, destroyed on completion of the function.
5661 * @param argc Standard main() style argc.
5662 * @param argv Standard main() style argv. Initial components are already
5665 * @return normal NTSTATUS return code.
5668 static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
5669 const struct dom_sid *domain_sid,
5670 const char *domain_name,
5671 struct cli_state *cli,
5672 struct rpc_pipe_client *pipe_hnd,
5673 TALLOC_CTX *mem_ctx,
5677 struct policy_handle connect_pol, domain_pol, user_pol;
5678 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5680 struct lsa_String lsa_acct_name;
5682 uint32 acct_flags=0;
5684 uint32_t access_granted = 0;
5685 union samr_UserInfo info;
5686 unsigned int orig_timeout;
5691 _(" net rpc trustdom add <domain_name> "
5692 "<trust password>\n"));
5693 return NT_STATUS_INVALID_PARAMETER;
5697 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5700 if (asprintf(&acct_name, "%s$", argv[0]) < 0) {
5701 return NT_STATUS_NO_MEMORY;
5704 strupper_m(acct_name);
5706 init_lsa_String(&lsa_acct_name, acct_name);
5708 /* Get samr policy handle */
5709 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5711 MAXIMUM_ALLOWED_ACCESS,
5713 if (!NT_STATUS_IS_OK(result)) {
5717 /* Get domain policy handle */
5718 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5720 MAXIMUM_ALLOWED_ACCESS,
5721 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5723 if (!NT_STATUS_IS_OK(result)) {
5727 /* This call can take a long time - allow the server to time out.
5728 * 35 seconds should do it. */
5730 orig_timeout = rpccli_set_timeout(pipe_hnd, 35000);
5732 /* Create trusting domain's account */
5733 acb_info = ACB_NORMAL;
5734 acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
5735 SEC_STD_WRITE_DAC | SEC_STD_DELETE |
5736 SAMR_USER_ACCESS_SET_PASSWORD |
5737 SAMR_USER_ACCESS_GET_ATTRIBUTES |
5738 SAMR_USER_ACCESS_SET_ATTRIBUTES;
5740 result = rpccli_samr_CreateUser2(pipe_hnd, mem_ctx,
5749 /* And restore our original timeout. */
5750 rpccli_set_timeout(pipe_hnd, orig_timeout);
5752 if (!NT_STATUS_IS_OK(result)) {
5753 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5754 acct_name, nt_errstr(result));
5759 struct samr_CryptPassword crypt_pwd;
5761 ZERO_STRUCT(info.info23);
5763 init_samr_CryptPassword(argv[1],
5764 &cli->user_session_key,
5767 info.info23.info.fields_present = SAMR_FIELD_ACCT_FLAGS |
5768 SAMR_FIELD_NT_PASSWORD_PRESENT;
5769 info.info23.info.acct_flags = ACB_DOMTRUST;
5770 info.info23.password = crypt_pwd;
5772 result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
5777 if (!NT_STATUS_IS_OK(result)) {
5778 DEBUG(0,("Could not set trust account password: %s\n",
5779 nt_errstr(result)));
5785 SAFE_FREE(acct_name);
5790 * Create interdomain trust account for a remote domain.
5792 * @param argc Standard argc.
5793 * @param argv Standard argv without initial components.
5795 * @return Integer status (0 means success).
5798 static int rpc_trustdom_add(struct net_context *c, int argc, const char **argv)
5800 if (argc > 0 && !c->display_usage) {
5801 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5802 rpc_trustdom_add_internals, argc, argv);
5806 _("net rpc trustdom add <domain_name> <trust "
5814 * Remove interdomain trust account from the RPC server.
5815 * All parameters (except for argc and argv) are passed by run_rpc_command
5818 * @param c A net_context structure.
5819 * @param domain_sid The domain sid acquired from the server.
5820 * @param cli A cli_state connected to the server.
5821 * @param mem_ctx Talloc context, destroyed on completion of the function.
5822 * @param argc Standard main() style argc.
5823 * @param argv Standard main() style argv. Initial components are already
5826 * @return normal NTSTATUS return code.
5829 static NTSTATUS rpc_trustdom_del_internals(struct net_context *c,
5830 const struct dom_sid *domain_sid,
5831 const char *domain_name,
5832 struct cli_state *cli,
5833 struct rpc_pipe_client *pipe_hnd,
5834 TALLOC_CTX *mem_ctx,
5838 struct policy_handle connect_pol, domain_pol, user_pol;
5839 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
5841 struct dom_sid trust_acct_sid;
5842 struct samr_Ids user_rids, name_types;
5843 struct lsa_String lsa_acct_name;
5848 _(" net rpc trustdom del <domain_name>\n"));
5849 return NT_STATUS_INVALID_PARAMETER;
5853 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5855 acct_name = talloc_asprintf(mem_ctx, "%s$", argv[0]);
5857 if (acct_name == NULL)
5858 return NT_STATUS_NO_MEMORY;
5860 strupper_m(acct_name);
5862 /* Get samr policy handle */
5863 result = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
5865 MAXIMUM_ALLOWED_ACCESS,
5867 if (!NT_STATUS_IS_OK(result)) {
5871 /* Get domain policy handle */
5872 result = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
5874 MAXIMUM_ALLOWED_ACCESS,
5875 CONST_DISCARD(struct dom_sid2 *, domain_sid),
5877 if (!NT_STATUS_IS_OK(result)) {
5881 init_lsa_String(&lsa_acct_name, acct_name);
5883 result = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
5890 if (!NT_STATUS_IS_OK(result)) {
5891 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5893 acct_name, nt_errstr(result) );
5897 result = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
5899 MAXIMUM_ALLOWED_ACCESS,
5903 if (!NT_STATUS_IS_OK(result)) {
5904 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5906 acct_name, nt_errstr(result) );
5910 /* append the rid to the domain sid */
5911 if (!sid_compose(&trust_acct_sid, domain_sid, user_rids.ids[0])) {
5915 /* remove the sid */
5917 result = rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd, mem_ctx,
5920 if (!NT_STATUS_IS_OK(result)) {
5921 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5922 " on user %s failed %s\n"),
5923 acct_name, nt_errstr(result) );
5929 result = rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
5932 if (!NT_STATUS_IS_OK(result)) {
5933 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5935 acct_name, nt_errstr(result) );
5939 if (!NT_STATUS_IS_OK(result)) {
5940 d_printf(_("Could not set trust account password: %s\n"),
5950 * Delete interdomain trust account for a remote domain.
5952 * @param argc Standard argc.
5953 * @param argv Standard argv without initial components.
5955 * @return Integer status (0 means success).
5958 static int rpc_trustdom_del(struct net_context *c, int argc, const char **argv)
5960 if (argc > 0 && !c->display_usage) {
5961 return run_rpc_command(c, NULL, &ndr_table_samr.syntax_id, 0,
5962 rpc_trustdom_del_internals, argc, argv);
5966 _("net rpc trustdom del <domain>\n"));
5971 static NTSTATUS rpc_trustdom_get_pdc(struct net_context *c,
5972 struct cli_state *cli,
5973 TALLOC_CTX *mem_ctx,
5974 const char *domain_name)
5976 char *dc_name = NULL;
5977 const char *buffer = NULL;
5978 struct rpc_pipe_client *netr;
5981 struct dcerpc_binding_handle *b;
5983 /* Use NetServerEnum2 */
5985 if (cli_get_pdc_name(cli, domain_name, &dc_name)) {
5987 return NT_STATUS_OK;
5990 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5991 for domain %s\n", domain_name));
5993 /* Try netr_GetDcName */
5995 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_netlogon.syntax_id,
5997 if (!NT_STATUS_IS_OK(status)) {
6001 b = netr->binding_handle;
6003 status = dcerpc_netr_GetDcName(b, mem_ctx,
6010 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
6014 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
6015 for domain %s\n", domain_name));
6017 if (!NT_STATUS_IS_OK(status)) {
6021 return werror_to_ntstatus(result);
6025 * Establish trust relationship to a trusting domain.
6026 * Interdomain account must already be created on remote PDC.
6028 * @param c A net_context structure.
6029 * @param argc Standard argc.
6030 * @param argv Standard argv without initial components.
6032 * @return Integer status (0 means success).
6035 static int rpc_trustdom_establish(struct net_context *c, int argc,
6038 struct cli_state *cli = NULL;
6039 struct sockaddr_storage server_ss;
6040 struct rpc_pipe_client *pipe_hnd = NULL;
6041 struct policy_handle connect_hnd;
6042 TALLOC_CTX *mem_ctx;
6044 struct dom_sid *domain_sid;
6049 union lsa_PolicyInformation *info = NULL;
6052 * Connect to \\server\ipc$ as 'our domain' account with password
6055 if (argc != 1 || c->display_usage) {
6058 _("net rpc trustdom establish <domain_name>\n"));
6062 domain_name = smb_xstrdup(argv[0]);
6063 strupper_m(domain_name);
6065 /* account name used at first is our domain's name with '$' */
6066 if (asprintf(&acct_name, "%s$", lp_workgroup()) == -1) {
6069 strupper_m(acct_name);
6072 * opt_workgroup will be used by connection functions further,
6073 * hence it should be set to remote domain name instead of ours
6075 if (c->opt_workgroup) {
6076 c->opt_workgroup = smb_xstrdup(domain_name);
6079 c->opt_user_name = acct_name;
6081 /* find the domain controller */
6082 if (!net_find_pdc(&server_ss, pdc_name, domain_name)) {
6083 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
6087 /* connect to ipc$ as username/password */
6088 nt_status = connect_to_ipc(c, &cli, &server_ss, pdc_name);
6089 if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) {
6091 /* Is it trusting domain account for sure ? */
6092 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6093 nt_errstr(nt_status)));
6097 /* store who we connected to */
6099 saf_store( domain_name, pdc_name );
6102 * Connect to \\server\ipc$ again (this time anonymously)
6105 nt_status = connect_to_ipc_anonymous(c, &cli, &server_ss,
6108 if (NT_STATUS_IS_ERR(nt_status)) {
6109 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6110 domain_name, nt_errstr(nt_status)));
6114 if (!(mem_ctx = talloc_init("establishing trust relationship to "
6115 "domain %s", domain_name))) {
6116 DEBUG(0, ("talloc_init() failed\n"));
6121 /* Make sure we're talking to a proper server */
6123 nt_status = rpc_trustdom_get_pdc(c, cli, mem_ctx, domain_name);
6124 if (!NT_STATUS_IS_OK(nt_status)) {
6126 talloc_destroy(mem_ctx);
6131 * Call LsaOpenPolicy and LsaQueryInfo
6134 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6136 if (!NT_STATUS_IS_OK(nt_status)) {
6137 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status) ));
6139 talloc_destroy(mem_ctx);
6143 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true, KEY_QUERY_VALUE,
6145 if (NT_STATUS_IS_ERR(nt_status)) {
6146 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6147 nt_errstr(nt_status)));
6149 talloc_destroy(mem_ctx);
6153 /* Querying info level 5 */
6155 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6157 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6159 if (NT_STATUS_IS_ERR(nt_status)) {
6160 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6161 nt_errstr(nt_status)));
6163 talloc_destroy(mem_ctx);
6167 domain_sid = info->account_domain.sid;
6169 /* There should be actually query info level 3 (following nt serv behaviour),
6170 but I still don't know if it's _really_ necessary */
6173 * Store the password in secrets db
6176 if (!pdb_set_trusteddom_pw(domain_name, c->opt_password, domain_sid)) {
6177 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6179 talloc_destroy(mem_ctx);
6184 * Close the pipes and clean up
6187 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6188 if (NT_STATUS_IS_ERR(nt_status)) {
6189 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6190 nt_errstr(nt_status)));
6192 talloc_destroy(mem_ctx);
6198 talloc_destroy(mem_ctx);
6200 d_printf(_("Trust to domain %s established\n"), domain_name);
6205 * Revoke trust relationship to the remote domain.
6207 * @param c A net_context structure.
6208 * @param argc Standard argc.
6209 * @param argv Standard argv without initial components.
6211 * @return Integer status (0 means success).
6214 static int rpc_trustdom_revoke(struct net_context *c, int argc,
6220 if (argc < 1 || c->display_usage) {
6223 _("net rpc trustdom revoke <domain_name>\n"
6224 " Revoke trust relationship\n"
6225 " domain_name\tName of domain to revoke trust\n"));
6229 /* generate upper cased domain name */
6230 domain_name = smb_xstrdup(argv[0]);
6231 strupper_m(domain_name);
6233 /* delete password of the trust */
6234 if (!pdb_del_trusteddom_pw(domain_name)) {
6235 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6242 SAFE_FREE(domain_name);
6246 static NTSTATUS rpc_query_domain_sid(struct net_context *c,
6247 const struct dom_sid *domain_sid,
6248 const char *domain_name,
6249 struct cli_state *cli,
6250 struct rpc_pipe_client *pipe_hnd,
6251 TALLOC_CTX *mem_ctx,
6256 if (!sid_to_fstring(str_sid, domain_sid)) {
6257 return NT_STATUS_UNSUCCESSFUL;
6259 d_printf("%s\n", str_sid);
6260 return NT_STATUS_OK;
6263 static void print_trusted_domain(struct dom_sid *dom_sid, const char *trusted_dom_name)
6267 /* convert sid into ascii string */
6268 sid_to_fstring(ascii_sid, dom_sid);
6270 d_printf("%-20s%s\n", trusted_dom_name, ascii_sid);
6273 static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
6274 TALLOC_CTX *mem_ctx,
6275 struct policy_handle *pol,
6276 struct dom_sid dom_sid,
6277 const char *trusted_dom_name)
6280 union lsa_TrustedDomainInfo *info = NULL;
6281 char *cleartextpwd = NULL;
6282 uint8_t session_key[16];
6283 DATA_BLOB session_key_blob;
6284 DATA_BLOB data = data_blob_null;
6286 nt_status = rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd, mem_ctx,
6289 LSA_TRUSTED_DOMAIN_INFO_PASSWORD,
6291 if (NT_STATUS_IS_ERR(nt_status)) {
6292 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6293 nt_errstr(nt_status)));
6297 data = data_blob(info->password.password->data,
6298 info->password.password->length);
6300 if (!rpccli_get_pwd_hash(pipe_hnd, session_key)) {
6301 DEBUG(0, ("Could not retrieve password hash\n"));
6305 session_key_blob = data_blob_const(session_key, sizeof(session_key));
6306 cleartextpwd = sess_decrypt_string(mem_ctx, &data, &session_key_blob);
6308 if (cleartextpwd == NULL) {
6309 DEBUG(0,("retrieved NULL password\n"));
6310 nt_status = NT_STATUS_UNSUCCESSFUL;
6314 if (!pdb_set_trusteddom_pw(trusted_dom_name, cleartextpwd, &dom_sid)) {
6315 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6316 nt_status = NT_STATUS_UNSUCCESSFUL;
6320 #ifdef DEBUG_PASSWORD
6321 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6322 "password: [%s]\n", trusted_dom_name,
6323 sid_string_dbg(&dom_sid), cleartextpwd));
6327 SAFE_FREE(cleartextpwd);
6328 data_blob_free(&data);
6333 static int rpc_trustdom_vampire(struct net_context *c, int argc,
6336 /* common variables */
6337 TALLOC_CTX* mem_ctx;
6338 struct cli_state *cli = NULL;
6339 struct rpc_pipe_client *pipe_hnd = NULL;
6341 const char *domain_name = NULL;
6342 struct dom_sid *queried_dom_sid;
6343 struct policy_handle connect_hnd;
6344 union lsa_PolicyInformation *info = NULL;
6346 /* trusted domains listing variables */
6347 unsigned int enum_ctx = 0;
6349 struct lsa_DomainList dom_list;
6352 if (c->display_usage) {
6354 "net rpc trustdom vampire\n"
6357 _("Vampire trust relationship from remote server"));
6362 * Listing trusted domains (stored in secrets.tdb, if local)
6365 mem_ctx = talloc_init("trust relationships vampire");
6368 * set domain and pdc name to local samba server (default)
6369 * or to remote one given in command line
6372 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6373 domain_name = c->opt_workgroup;
6374 c->opt_target_workgroup = c->opt_workgroup;
6376 fstrcpy(pdc_name, global_myname());
6377 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6378 c->opt_target_workgroup = domain_name;
6381 /* open \PIPE\lsarpc and open policy handle */
6382 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6383 if (!NT_STATUS_IS_OK(nt_status)) {
6384 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6385 nt_errstr(nt_status)));
6386 talloc_destroy(mem_ctx);
6390 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6392 if (!NT_STATUS_IS_OK(nt_status)) {
6393 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6394 nt_errstr(nt_status) ));
6396 talloc_destroy(mem_ctx);
6400 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
6402 if (NT_STATUS_IS_ERR(nt_status)) {
6403 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6404 nt_errstr(nt_status)));
6406 talloc_destroy(mem_ctx);
6410 /* query info level 5 to obtain sid of a domain being queried */
6411 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6413 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6416 if (NT_STATUS_IS_ERR(nt_status)) {
6417 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6418 nt_errstr(nt_status)));
6420 talloc_destroy(mem_ctx);
6424 queried_dom_sid = info->account_domain.sid;
6427 * Keep calling LsaEnumTrustdom over opened pipe until
6428 * the end of enumeration is reached
6431 d_printf(_("Vampire trusted domains:\n\n"));
6434 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6439 if (NT_STATUS_IS_ERR(nt_status)) {
6440 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6441 nt_errstr(nt_status)));
6443 talloc_destroy(mem_ctx);
6447 for (i = 0; i < dom_list.count; i++) {
6449 print_trusted_domain(dom_list.domains[i].sid,
6450 dom_list.domains[i].name.string);
6452 nt_status = vampire_trusted_domain(pipe_hnd, mem_ctx, &connect_hnd,
6453 *dom_list.domains[i].sid,
6454 dom_list.domains[i].name.string);
6455 if (!NT_STATUS_IS_OK(nt_status)) {
6457 talloc_destroy(mem_ctx);
6463 * in case of no trusted domains say something rather
6464 * than just display blank line
6466 if (!dom_list.count) d_printf(_("none\n"));
6468 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6470 /* close this connection before doing next one */
6471 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6472 if (NT_STATUS_IS_ERR(nt_status)) {
6473 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6474 nt_errstr(nt_status)));
6476 talloc_destroy(mem_ctx);
6480 /* close lsarpc pipe and connection to IPC$ */
6483 talloc_destroy(mem_ctx);
6487 static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
6489 /* common variables */
6490 TALLOC_CTX* mem_ctx;
6491 struct cli_state *cli = NULL, *remote_cli = NULL;
6492 struct rpc_pipe_client *pipe_hnd = NULL;
6494 const char *domain_name = NULL;
6495 struct dom_sid *queried_dom_sid;
6496 int ascii_dom_name_len;
6497 struct policy_handle connect_hnd;
6498 union lsa_PolicyInformation *info = NULL;
6500 /* trusted domains listing variables */
6501 unsigned int num_domains, enum_ctx = 0;
6503 struct lsa_DomainList dom_list;
6507 /* trusting domains listing variables */
6508 struct policy_handle domain_hnd;
6509 struct samr_SamArray *trusts = NULL;
6511 if (c->display_usage) {
6513 "net rpc trustdom list\n"
6516 _("List incoming and outgoing trust relationships"));
6521 * Listing trusted domains (stored in secrets.tdb, if local)
6524 mem_ctx = talloc_init("trust relationships listing");
6527 * set domain and pdc name to local samba server (default)
6528 * or to remote one given in command line
6531 if (StrCaseCmp(c->opt_workgroup, lp_workgroup())) {
6532 domain_name = c->opt_workgroup;
6533 c->opt_target_workgroup = c->opt_workgroup;
6535 fstrcpy(pdc_name, global_myname());
6536 domain_name = talloc_strdup(mem_ctx, lp_workgroup());
6537 c->opt_target_workgroup = domain_name;
6540 /* open \PIPE\lsarpc and open policy handle */
6541 nt_status = net_make_ipc_connection(c, NET_FLAGS_PDC, &cli);
6542 if (!NT_STATUS_IS_OK(nt_status)) {
6543 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6544 nt_errstr(nt_status)));
6545 talloc_destroy(mem_ctx);
6549 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc.syntax_id,
6551 if (!NT_STATUS_IS_OK(nt_status)) {
6552 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6553 nt_errstr(nt_status) ));
6555 talloc_destroy(mem_ctx);
6559 nt_status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, false, KEY_QUERY_VALUE,
6561 if (NT_STATUS_IS_ERR(nt_status)) {
6562 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6563 nt_errstr(nt_status)));
6565 talloc_destroy(mem_ctx);
6569 /* query info level 5 to obtain sid of a domain being queried */
6570 nt_status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
6572 LSA_POLICY_INFO_ACCOUNT_DOMAIN,
6575 if (NT_STATUS_IS_ERR(nt_status)) {
6576 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6577 nt_errstr(nt_status)));
6579 talloc_destroy(mem_ctx);
6583 queried_dom_sid = info->account_domain.sid;
6586 * Keep calling LsaEnumTrustdom over opened pipe until
6587 * the end of enumeration is reached
6590 d_printf(_("Trusted domains list:\n\n"));
6592 found_domain = false;
6595 nt_status = rpccli_lsa_EnumTrustDom(pipe_hnd, mem_ctx,
6600 if (NT_STATUS_IS_ERR(nt_status)) {
6601 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6602 nt_errstr(nt_status)));
6604 talloc_destroy(mem_ctx);
6608 for (i = 0; i < dom_list.count; i++) {
6609 print_trusted_domain(dom_list.domains[i].sid,
6610 dom_list.domains[i].name.string);
6611 found_domain = true;
6615 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6618 * in case of no trusted domains say something rather
6619 * than just display blank line
6621 if (!found_domain) {
6622 d_printf(_("none\n"));
6625 /* close this connection before doing next one */
6626 nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
6627 if (NT_STATUS_IS_ERR(nt_status)) {
6628 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6629 nt_errstr(nt_status)));
6631 talloc_destroy(mem_ctx);
6635 TALLOC_FREE(pipe_hnd);
6638 * Listing trusting domains (stored in passdb backend, if local)
6641 d_printf(_("\nTrusting domains list:\n\n"));
6644 * Open \PIPE\samr and get needed policy handles
6646 nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_samr.syntax_id,
6648 if (!NT_STATUS_IS_OK(nt_status)) {
6649 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status)));
6651 talloc_destroy(mem_ctx);
6656 nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
6658 SAMR_ACCESS_LOOKUP_DOMAIN,
6660 if (!NT_STATUS_IS_OK(nt_status)) {
6661 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6662 nt_errstr(nt_status)));
6664 talloc_destroy(mem_ctx);
6668 /* SamrOpenDomain - we have to open domain policy handle in order to be
6669 able to enumerate accounts*/
6670 nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
6672 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
6675 if (!NT_STATUS_IS_OK(nt_status)) {
6676 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6677 nt_errstr(nt_status)));
6679 talloc_destroy(mem_ctx);
6684 * perform actual enumeration
6687 found_domain = false;
6689 enum_ctx = 0; /* reset enumeration context from last enumeration */
6692 nt_status = rpccli_samr_EnumDomainUsers(pipe_hnd, mem_ctx,
6699 if (NT_STATUS_IS_ERR(nt_status)) {
6700 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6701 nt_errstr(nt_status)));
6703 talloc_destroy(mem_ctx);
6707 for (i = 0; i < num_domains; i++) {
6709 char *str = CONST_DISCARD(char *, trusts->entries[i].name.string);
6711 found_domain = true;
6714 * get each single domain's sid (do we _really_ need this ?):
6715 * 1) connect to domain's pdc
6716 * 2) query the pdc for domain's sid
6719 /* get rid of '$' tail */
6720 ascii_dom_name_len = strlen(str);
6721 if (ascii_dom_name_len && ascii_dom_name_len < FSTRING_LEN)
6722 str[ascii_dom_name_len - 1] = '\0';
6724 /* set opt_* variables to remote domain */
6726 c->opt_workgroup = talloc_strdup(mem_ctx, str);
6727 c->opt_target_workgroup = c->opt_workgroup;
6729 d_printf("%-20s", str);
6731 /* connect to remote domain controller */
6732 nt_status = net_make_ipc_connection(c,
6733 NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS,
6735 if (NT_STATUS_IS_OK(nt_status)) {
6736 /* query for domain's sid */
6737 if (run_rpc_command(
6739 &ndr_table_lsarpc.syntax_id, 0,
6740 rpc_query_domain_sid, argc,
6742 d_printf(_("strange - couldn't get domain's sid\n"));
6744 cli_shutdown(remote_cli);
6747 d_fprintf(stderr, _("domain controller is not "
6748 "responding: %s\n"),
6749 nt_errstr(nt_status));
6750 d_printf(_("couldn't get domain's sid\n"));
6754 } while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
6756 if (!found_domain) {
6760 /* close opened samr and domain policy handles */
6761 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &domain_hnd);
6762 if (!NT_STATUS_IS_OK(nt_status)) {
6763 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name));
6766 nt_status = rpccli_samr_Close(pipe_hnd, mem_ctx, &connect_hnd);
6767 if (!NT_STATUS_IS_OK(nt_status)) {
6768 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name));
6771 /* close samr pipe and connection to IPC$ */
6774 talloc_destroy(mem_ctx);
6779 * Entrypoint for 'net rpc trustdom' code.
6781 * @param argc Standard argc.
6782 * @param argv Standard argv without initial components.
6784 * @return Integer status (0 means success).
6787 static int rpc_trustdom(struct net_context *c, int argc, const char **argv)
6789 struct functable func[] = {
6794 N_("Add trusting domain's account"),
6795 N_("net rpc trustdom add\n"
6796 " Add trusting domain's account")
6802 N_("Remove trusting domain's account"),
6803 N_("net rpc trustdom del\n"
6804 " Remove trusting domain's account")
6808 rpc_trustdom_establish,
6810 N_("Establish outgoing trust relationship"),
6811 N_("net rpc trustdom establish\n"
6812 " Establish outgoing trust relationship")
6816 rpc_trustdom_revoke,
6818 N_("Revoke outgoing trust relationship"),
6819 N_("net rpc trustdom revoke\n"
6820 " Revoke outgoing trust relationship")
6826 N_("List in- and outgoing domain trusts"),
6827 N_("net rpc trustdom list\n"
6828 " List in- and outgoing domain trusts")
6832 rpc_trustdom_vampire,
6834 N_("Vampire trusts from remote server"),
6835 N_("net rpc trustdom vampire\n"
6836 " Vampire trusts from remote server")
6838 {NULL, NULL, 0, NULL, NULL}
6841 return net_run_function(c, argc, argv, "net rpc trustdom", func);
6845 * Check if a server will take rpc commands
6846 * @param flags Type of server to connect to (PDC, DMB, localhost)
6847 * if the host is not explicitly specified
6848 * @return bool (true means rpc supported)
6850 bool net_rpc_check(struct net_context *c, unsigned flags)
6852 struct cli_state *cli;
6854 struct sockaddr_storage server_ss;
6855 char *server_name = NULL;
6858 /* flags (i.e. server type) may depend on command */
6859 if (!net_find_server(c, NULL, flags, &server_ss, &server_name))
6862 if ((cli = cli_initialise()) == NULL) {
6866 status = cli_connect(cli, server_name, &server_ss);
6867 if (!NT_STATUS_IS_OK(status))
6869 if (!attempt_netbios_session_request(&cli, global_myname(),
6870 server_name, &server_ss))
6872 status = cli_negprot(cli);
6873 if (!NT_STATUS_IS_OK(status))
6875 if (cli->protocol < PROTOCOL_NT1)
6884 /* dump sam database via samsync rpc calls */
6885 static int rpc_samdump(struct net_context *c, int argc, const char **argv) {
6886 if (c->display_usage) {
6891 _("Dump remote SAM database"));
6895 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6896 NET_FLAGS_ANONYMOUS,
6897 rpc_samdump_internals, argc, argv);
6900 /* syncronise sam database via samsync rpc calls */
6901 static int rpc_vampire(struct net_context *c, int argc, const char **argv)
6903 struct functable func[] = {
6908 N_("Dump remote SAM database to ldif"),
6909 N_("net rpc vampire ldif\n"
6910 " Dump remote SAM database to LDIF file or "
6917 N_("Dump remote SAM database to Kerberos Keytab"),
6918 N_("net rpc vampire keytab\n"
6919 " Dump remote SAM database to Kerberos keytab "
6926 N_("Dump remote SAM database to passdb"),
6927 N_("net rpc vampire passdb\n"
6928 " Dump remote SAM database to passdb")
6931 {NULL, NULL, 0, NULL, NULL}
6935 if (c->display_usage) {
6940 _("Vampire remote SAM database"));
6944 return run_rpc_command(c, NULL, &ndr_table_netlogon.syntax_id,
6945 NET_FLAGS_ANONYMOUS,
6946 rpc_vampire_internals,
6950 return net_run_function(c, argc, argv, "net rpc vampire", func);
6954 * Migrate everything from a print server.
6956 * @param c A net_context structure.
6957 * @param argc Standard main() style argc.
6958 * @param argv Standard main() style argv. Initial components are already
6961 * @return A shell status integer (0 for success).
6963 * The order is important !
6964 * To successfully add drivers the print queues have to exist !
6965 * Applying ACLs should be the last step, because you're easily locked out.
6968 static int rpc_printer_migrate_all(struct net_context *c, int argc,
6973 if (c->display_usage) {
6975 "net rpc printer migrate all\n"
6978 _("Migrate everything from a print server"));
6983 d_printf(_("no server to migrate\n"));
6987 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
6988 rpc_printer_migrate_printers_internals, argc,
6993 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
6994 rpc_printer_migrate_drivers_internals, argc,
6999 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7000 rpc_printer_migrate_forms_internals, argc, argv);
7004 ret = run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7005 rpc_printer_migrate_settings_internals, argc,
7010 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7011 rpc_printer_migrate_security_internals, argc,
7017 * Migrate print drivers from a print server.
7019 * @param c A net_context structure.
7020 * @param argc Standard main() style argc.
7021 * @param argv Standard main() style argv. Initial components are already
7024 * @return A shell status integer (0 for success).
7026 static int rpc_printer_migrate_drivers(struct net_context *c, int argc,
7029 if (c->display_usage) {
7031 "net rpc printer migrate drivers\n"
7034 _("Migrate print-drivers from a print-server"));
7039 d_printf(_("no server to migrate\n"));
7043 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7044 rpc_printer_migrate_drivers_internals,
7049 * Migrate print-forms from a print-server.
7051 * @param c A net_context structure.
7052 * @param argc Standard main() style argc.
7053 * @param argv Standard main() style argv. Initial components are already
7056 * @return A shell status integer (0 for success).
7058 static int rpc_printer_migrate_forms(struct net_context *c, int argc,
7061 if (c->display_usage) {
7063 "net rpc printer migrate forms\n"
7066 _("Migrate print-forms from a print-server"));
7071 d_printf(_("no server to migrate\n"));
7075 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7076 rpc_printer_migrate_forms_internals,
7081 * Migrate printers from a print-server.
7083 * @param c A net_context structure.
7084 * @param argc Standard main() style argc.
7085 * @param argv Standard main() style argv. Initial components are already
7088 * @return A shell status integer (0 for success).
7090 static int rpc_printer_migrate_printers(struct net_context *c, int argc,
7093 if (c->display_usage) {
7095 "net rpc printer migrate printers\n"
7098 _("Migrate printers from a print-server"));
7103 d_printf(_("no server to migrate\n"));
7107 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7108 rpc_printer_migrate_printers_internals,
7113 * Migrate printer-ACLs from a print-server
7115 * @param c A net_context structure.
7116 * @param argc Standard main() style argc.
7117 * @param argv Standard main() style argv. Initial components are already
7120 * @return A shell status integer (0 for success).
7122 static int rpc_printer_migrate_security(struct net_context *c, int argc,
7125 if (c->display_usage) {
7127 "net rpc printer migrate security\n"
7130 _("Migrate printer-ACLs from a print-server"));
7135 d_printf(_("no server to migrate\n"));
7139 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7140 rpc_printer_migrate_security_internals,
7145 * Migrate printer-settings from a print-server.
7147 * @param c A net_context structure.
7148 * @param argc Standard main() style argc.
7149 * @param argv Standard main() style argv. Initial components are already
7152 * @return A shell status integer (0 for success).
7154 static int rpc_printer_migrate_settings(struct net_context *c, int argc,
7157 if (c->display_usage) {
7159 "net rpc printer migrate settings\n"
7162 _("Migrate printer-settings from a "
7168 d_printf(_("no server to migrate\n"));
7172 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7173 rpc_printer_migrate_settings_internals,
7178 * 'net rpc printer' entrypoint.
7180 * @param c A net_context structure.
7181 * @param argc Standard main() style argc.
7182 * @param argv Standard main() style argv. Initial components are already
7186 int rpc_printer_migrate(struct net_context *c, int argc, const char **argv)
7189 /* ouch: when addriver and setdriver are called from within
7190 rpc_printer_migrate_drivers_internals, the printer-queue already
7193 struct functable func[] = {
7196 rpc_printer_migrate_all,
7198 N_("Migrate all from remote to local print server"),
7199 N_("net rpc printer migrate all\n"
7200 " Migrate all from remote to local print server")
7204 rpc_printer_migrate_drivers,
7206 N_("Migrate drivers to local server"),
7207 N_("net rpc printer migrate drivers\n"
7208 " Migrate drivers to local server")
7212 rpc_printer_migrate_forms,
7214 N_("Migrate froms to local server"),
7215 N_("net rpc printer migrate forms\n"
7216 " Migrate froms to local server")
7220 rpc_printer_migrate_printers,
7222 N_("Migrate printers to local server"),
7223 N_("net rpc printer migrate printers\n"
7224 " Migrate printers to local server")
7228 rpc_printer_migrate_security,
7230 N_("Mirgate printer ACLs to local server"),
7231 N_("net rpc printer migrate security\n"
7232 " Mirgate printer ACLs to local server")
7236 rpc_printer_migrate_settings,
7238 N_("Migrate printer settings to local server"),
7239 N_("net rpc printer migrate settings\n"
7240 " Migrate printer settings to local server")
7242 {NULL, NULL, 0, NULL, NULL}
7245 return net_run_function(c, argc, argv, "net rpc printer migrate",func);
7250 * List printers on a remote RPC server.
7252 * @param c A net_context structure.
7253 * @param argc Standard main() style argc.
7254 * @param argv Standard main() style argv. Initial components are already
7257 * @return A shell status integer (0 for success).
7259 static int rpc_printer_list(struct net_context *c, int argc, const char **argv)
7261 if (c->display_usage) {
7263 "net rpc printer list\n"
7266 _("List printers on a remote RPC server"));
7270 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7271 rpc_printer_list_internals,
7276 * List printer-drivers on a remote RPC server.
7278 * @param c A net_context structure.
7279 * @param argc Standard main() style argc.
7280 * @param argv Standard main() style argv. Initial components are already
7283 * @return A shell status integer (0 for success).
7285 static int rpc_printer_driver_list(struct net_context *c, int argc,
7288 if (c->display_usage) {
7290 "net rpc printer driver\n"
7293 _("List printer-drivers on a remote RPC server"));
7297 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7298 rpc_printer_driver_list_internals,
7303 * Publish printer in ADS via MSRPC.
7305 * @param c A net_context structure.
7306 * @param argc Standard main() style argc.
7307 * @param argv Standard main() style argv. Initial components are already
7310 * @return A shell status integer (0 for success).
7312 static int rpc_printer_publish_publish(struct net_context *c, int argc,
7315 if (c->display_usage) {
7317 "net rpc printer publish publish\n"
7320 _("Publish printer in ADS via MSRPC"));
7324 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7325 rpc_printer_publish_publish_internals,
7330 * Update printer in ADS via MSRPC.
7332 * @param c A net_context structure.
7333 * @param argc Standard main() style argc.
7334 * @param argv Standard main() style argv. Initial components are already
7337 * @return A shell status integer (0 for success).
7339 static int rpc_printer_publish_update(struct net_context *c, int argc, const char **argv)
7341 if (c->display_usage) {
7343 "net rpc printer publish update\n"
7346 _("Update printer in ADS via MSRPC"));
7350 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7351 rpc_printer_publish_update_internals,
7356 * UnPublish printer in ADS via MSRPC.
7358 * @param c A net_context structure.
7359 * @param argc Standard main() style argc.
7360 * @param argv Standard main() style argv. Initial components are already
7363 * @return A shell status integer (0 for success).
7365 static int rpc_printer_publish_unpublish(struct net_context *c, int argc,
7368 if (c->display_usage) {
7370 "net rpc printer publish unpublish\n"
7373 _("UnPublish printer in ADS via MSRPC"));
7377 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7378 rpc_printer_publish_unpublish_internals,
7383 * List published printers via MSRPC.
7385 * @param c A net_context structure.
7386 * @param argc Standard main() style argc.
7387 * @param argv Standard main() style argv. Initial components are already
7390 * @return A shell status integer (0 for success).
7392 static int rpc_printer_publish_list(struct net_context *c, int argc,
7395 if (c->display_usage) {
7397 "net rpc printer publish list\n"
7400 _("List published printers via MSRPC"));
7404 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7405 rpc_printer_publish_list_internals,
7411 * Publish printer in ADS.
7413 * @param c A net_context structure.
7414 * @param argc Standard main() style argc.
7415 * @param argv Standard main() style argv. Initial components are already
7418 * @return A shell status integer (0 for success).
7420 static int rpc_printer_publish(struct net_context *c, int argc,
7424 struct functable func[] = {
7427 rpc_printer_publish_publish,
7429 N_("Publish printer in AD"),
7430 N_("net rpc printer publish publish\n"
7431 " Publish printer in AD")
7435 rpc_printer_publish_update,
7437 N_("Update printer in AD"),
7438 N_("net rpc printer publish update\n"
7439 " Update printer in AD")
7443 rpc_printer_publish_unpublish,
7445 N_("Unpublish printer"),
7446 N_("net rpc printer publish unpublish\n"
7447 " Unpublish printer")
7451 rpc_printer_publish_list,
7453 N_("List published printers"),
7454 N_("net rpc printer publish list\n"
7455 " List published printers")
7457 {NULL, NULL, 0, NULL, NULL}
7461 if (c->display_usage) {
7462 d_printf(_("Usage:\n"));
7463 d_printf(_("net rpc printer publish\n"
7464 " List published printers\n"
7465 " Alias of net rpc printer publish "
7467 net_display_usage_from_functable(func);
7470 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7471 rpc_printer_publish_list_internals,
7475 return net_run_function(c, argc, argv, "net rpc printer publish",func);
7481 * Display rpc printer help page.
7483 * @param c A net_context structure.
7484 * @param argc Standard main() style argc.
7485 * @param argv Standard main() style argv. Initial components are already
7488 int rpc_printer_usage(struct net_context *c, int argc, const char **argv)
7490 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
7491 "\tlists all printers on print-server\n\n"));
7492 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7493 "\tlists all printer-drivers on print-server\n\n"));
7494 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7495 "\tpublishes printer settings in Active Directory\n"
7496 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
7497 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7498 "\n\tmigrates printers from remote to local server\n\n"));
7499 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7500 "\n\tmigrates printer-settings from remote to local server\n\n"));
7501 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7502 "\n\tmigrates printer-drivers from remote to local server\n\n"));
7503 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7504 "\n\tmigrates printer-forms from remote to local server\n\n"));
7505 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7506 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
7507 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7508 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7509 "\tremote to local print-server\n\n"));
7510 net_common_methods_usage(c, argc, argv);
7511 net_common_flags_usage(c, argc, argv);
7513 "\t-v or --verbose\t\t\tgive verbose output\n"
7514 "\t --destination\t\tmigration target server (default: localhost)\n"));
7520 * 'net rpc printer' entrypoint.
7522 * @param c A net_context structure.
7523 * @param argc Standard main() style argc.
7524 * @param argv Standard main() style argv. Initial components are already
7527 int net_rpc_printer(struct net_context *c, int argc, const char **argv)
7529 struct functable func[] = {
7534 N_("List all printers on print server"),
7535 N_("net rpc printer list\n"
7536 " List all printers on print server")
7540 rpc_printer_migrate,
7542 N_("Migrate printer to local server"),
7543 N_("net rpc printer migrate\n"
7544 " Migrate printer to local server")
7548 rpc_printer_driver_list,
7550 N_("List printer drivers"),
7551 N_("net rpc printer driver\n"
7552 " List printer drivers")
7556 rpc_printer_publish,
7558 N_("Publish printer in AD"),
7559 N_("net rpc printer publish\n"
7560 " Publish printer in AD")
7562 {NULL, NULL, 0, NULL, NULL}
7566 if (c->display_usage) {
7567 d_printf(_("Usage:\n"));
7568 d_printf(_("net rpc printer\n"
7569 " List printers\n"));
7570 net_display_usage_from_functable(func);
7573 return run_rpc_command(c, NULL, &ndr_table_spoolss.syntax_id, 0,
7574 rpc_printer_list_internals,
7578 return net_run_function(c, argc, argv, "net rpc printer", func);
7582 * 'net rpc' entrypoint.
7584 * @param c A net_context structure.
7585 * @param argc Standard main() style argc.
7586 * @param argv Standard main() style argv. Initial components are already
7590 int net_rpc(struct net_context *c, int argc, const char **argv)
7592 NET_API_STATUS status;
7594 struct functable func[] = {
7599 N_("Modify global audit settings"),
7600 N_("net rpc audit\n"
7601 " Modify global audit settings")
7607 N_("Show basic info about a domain"),
7609 " Show basic info about a domain")
7615 N_("Join a domain"),
7623 N_("Join a domain created in server manager"),
7624 N_("net rpc oldjoin\n"
7625 " Join a domain created in server manager")
7631 N_("Test that a join is valid"),
7632 N_("net rpc testjoin\n"
7633 " Test that a join is valid")
7639 N_("List/modify users"),
7641 " List/modify users")
7647 N_("Change a user password"),
7648 N_("net rpc password\n"
7649 " Change a user password\n"
7650 " Alias for net rpc user password")
7656 N_("List/modify groups"),
7657 N_("net rpc group\n"
7658 " List/modify groups")
7664 N_("List/modify shares"),
7665 N_("net rpc share\n"
7666 " List/modify shares")
7672 N_("List open files"),
7680 N_("List/modify printers"),
7681 N_("net rpc printer\n"
7682 " List/modify printers")
7686 net_rpc_changetrustpw,
7688 N_("Change trust account password"),
7689 N_("net rpc changetrustpw\n"
7690 " Change trust account password")
7696 N_("Modify domain trusts"),
7697 N_("net rpc trustdom\n"
7698 " Modify domain trusts")
7704 N_("Abort a remote shutdown"),
7705 N_("net rpc abortshutdown\n"
7706 " Abort a remote shutdown")
7712 N_("Shutdown a remote server"),
7713 N_("net rpc shutdown\n"
7714 " Shutdown a remote server")
7720 N_("Dump SAM data of remote NT PDC"),
7721 N_("net rpc samdump\n"
7722 " Dump SAM data of remote NT PDC")
7728 N_("Sync a remote NT PDC's data into local passdb"),
7729 N_("net rpc vampire\n"
7730 " Sync a remote NT PDC's data into local passdb")
7736 N_("Fetch the domain sid into local secrets.tdb"),
7737 N_("net rpc getsid\n"
7738 " Fetch the domain sid into local secrets.tdb")
7744 N_("Manage privileges assigned to SID"),
7745 N_("net rpc rights\n"
7746 " Manage privileges assigned to SID")
7752 N_("Start/stop/query remote services"),
7753 N_("net rpc service\n"
7754 " Start/stop/query remote services")
7760 N_("Manage registry hives"),
7761 N_("net rpc registry\n"
7762 " Manage registry hives")
7768 N_("Open interactive shell on remote server"),
7769 N_("net rpc shell\n"
7770 " Open interactive shell on remote server")
7772 {NULL, NULL, 0, NULL, NULL}
7775 status = libnetapi_net_init(&c->netapi_ctx);
7779 libnetapi_set_username(c->netapi_ctx, c->opt_user_name);
7780 libnetapi_set_password(c->netapi_ctx, c->opt_password);
7781 if (c->opt_kerberos) {
7782 libnetapi_set_use_kerberos(c->netapi_ctx);
7784 if (c->opt_ccache) {
7785 libnetapi_set_use_ccache(c->netapi_ctx);
7788 return net_run_function(c, argc, argv, "net rpc", func);