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/cli_samr.h"
27 #include "../librpc/gen_ndr/cli_lsa.h"
28 #include "../librpc/gen_ndr/cli_netlogon.h"
29 #include "../librpc/gen_ndr/cli_srvsvc.h"
30 #include "../librpc/gen_ndr/cli_spoolss.h"
31 #include "../librpc/gen_ndr/cli_initshutdown.h"
32 #include "../librpc/gen_ndr/cli_winreg.h"
34 static int net_mode_share
;
35 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
40 * @brief RPC based subcommands for the 'net' utility.
42 * This file should contain much of the functionality that used to
43 * be found in rpcclient, execpt that the commands should change
44 * less often, and the fucntionality should be sane (the user is not
45 * expected to know a rid/sid before they conduct an operation etc.)
47 * @todo Perhaps eventually these should be split out into a number
48 * of files, as this could get quite big.
53 * Many of the RPC functions need the domain sid. This function gets
54 * it at the start of every run
56 * @param cli A cli_state already connected to the remote machine
58 * @return The Domain SID of the remote machine.
61 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
63 const char **domain_name
)
65 struct rpc_pipe_client
*lsa_pipe
= NULL
;
66 struct policy_handle pol
;
67 NTSTATUS result
= NT_STATUS_OK
;
68 union lsa_PolicyInformation
*info
= NULL
;
70 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
72 if (!NT_STATUS_IS_OK(result
)) {
73 d_fprintf(stderr
, _("Could not initialise lsa pipe\n"));
77 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
78 SEC_FLAG_MAXIMUM_ALLOWED
,
80 if (!NT_STATUS_IS_OK(result
)) {
81 d_fprintf(stderr
, "open_policy %s: %s\n",
87 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
89 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
91 if (!NT_STATUS_IS_OK(result
)) {
92 d_fprintf(stderr
, "lsaquery %s: %s\n",
98 *domain_name
= info
->account_domain
.name
.string
;
99 *domain_sid
= info
->account_domain
.sid
;
101 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
102 TALLOC_FREE(lsa_pipe
);
108 * Run a single RPC command, from start to finish.
110 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
111 * @param conn_flag a NET_FLAG_ combination. Passed to
112 * net_make_ipc_connection.
113 * @param argc Standard main() style argc.
114 * @param argv Standard main() style argv. Initial components are already
116 * @return A shell status integer (0 for success).
119 int run_rpc_command(struct net_context
*c
,
120 struct cli_state
*cli_arg
,
121 const struct ndr_syntax_id
*interface
,
127 struct cli_state
*cli
= NULL
;
128 struct rpc_pipe_client
*pipe_hnd
= NULL
;
132 const char *domain_name
;
135 /* make use of cli_state handed over as an argument, if possible */
137 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
138 if (!NT_STATUS_IS_OK(nt_status
)) {
139 DEBUG(1, ("failed to make ipc connection: %s\n",
140 nt_errstr(nt_status
)));
153 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
154 DEBUG(0, ("talloc_init() failed\n"));
158 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
160 if (!NT_STATUS_IS_OK(nt_status
)) {
164 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
165 if (lp_client_schannel()
166 && (ndr_syntax_id_equal(interface
,
167 &ndr_table_netlogon
.syntax_id
))) {
168 /* Always try and create an schannel netlogon pipe. */
169 nt_status
= cli_rpc_pipe_open_schannel(
170 cli
, interface
, NCACN_NP
,
171 DCERPC_AUTH_LEVEL_PRIVACY
, domain_name
,
173 if (!NT_STATUS_IS_OK(nt_status
)) {
174 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
175 nt_errstr(nt_status
) ));
179 if (conn_flags
& NET_FLAGS_SEAL
) {
180 nt_status
= cli_rpc_pipe_open_ntlmssp(
182 (conn_flags
& NET_FLAGS_TCP
) ?
183 NCACN_IP_TCP
: NCACN_NP
,
184 DCERPC_AUTH_LEVEL_PRIVACY
,
185 lp_workgroup(), c
->opt_user_name
,
186 c
->opt_password
, &pipe_hnd
);
188 nt_status
= cli_rpc_pipe_open_noauth(
192 if (!NT_STATUS_IS_OK(nt_status
)) {
193 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
194 get_pipe_name_from_syntax(
195 talloc_tos(), interface
),
196 nt_errstr(nt_status
) ));
202 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
204 if (!NT_STATUS_IS_OK(nt_status
)) {
205 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
208 DEBUG(5, ("rpc command function succedded\n"));
211 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
213 TALLOC_FREE(pipe_hnd
);
218 /* close the connection only if it was opened here */
223 talloc_destroy(mem_ctx
);
228 * Force a change of the trust acccount password.
230 * All parameters are provided by the run_rpc_command function, except for
231 * argc, argv which are passed through.
233 * @param domain_sid The domain sid acquired from the remote server.
234 * @param cli A cli_state connected to the server.
235 * @param mem_ctx Talloc context, destroyed on completion of the function.
236 * @param argc Standard main() style argc.
237 * @param argv Standard main() style argv. Initial components are already
240 * @return Normal NTSTATUS return.
243 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
244 const DOM_SID
*domain_sid
,
245 const char *domain_name
,
246 struct cli_state
*cli
,
247 struct rpc_pipe_client
*pipe_hnd
,
254 status
= trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
255 if (!NT_STATUS_IS_OK(status
)) {
256 d_fprintf(stderr
, _("Failed to change machine account password: %s\n"),
265 * Force a change of the trust acccount password.
267 * @param argc Standard main() style argc.
268 * @param argv Standard main() style argv. Initial components are already
271 * @return A shell status integer (0 for success).
274 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
276 if (c
->display_usage
) {
278 "net rpc changetrustpw\n"
281 _("Change the machine trust password"));
285 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
286 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
287 rpc_changetrustpw_internals
,
292 * Join a domain, the old way.
294 * This uses 'machinename' as the inital password, and changes it.
296 * The password should be created with 'server manager' or equiv first.
298 * All parameters are provided by the run_rpc_command function, except for
299 * argc, argv which are passed through.
301 * @param domain_sid The domain sid acquired from the remote server.
302 * @param cli A cli_state connected to the server.
303 * @param mem_ctx Talloc context, destroyed on completion of the function.
304 * @param argc Standard main() style argc.
305 * @param argv Standard main() style argv. Initial components are already
308 * @return Normal NTSTATUS return.
311 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
312 const DOM_SID
*domain_sid
,
313 const char *domain_name
,
314 struct cli_state
*cli
,
315 struct rpc_pipe_client
*pipe_hnd
,
321 fstring trust_passwd
;
322 unsigned char orig_trust_passwd_hash
[16];
324 enum netr_SchannelType sec_channel_type
;
326 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
328 if (!NT_STATUS_IS_OK(result
)) {
329 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
332 nt_errstr(result
) ));
337 check what type of join - if the user want's to join as
338 a BDC, the server must agree that we are a BDC.
341 sec_channel_type
= get_sec_channel_type(argv
[0]);
343 sec_channel_type
= get_sec_channel_type(NULL
);
346 fstrcpy(trust_passwd
, global_myname());
347 strlower_m(trust_passwd
);
350 * Machine names can be 15 characters, but the max length on
351 * a password is 14. --jerry
354 trust_passwd
[14] = '\0';
356 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
358 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
360 orig_trust_passwd_hash
,
363 if (NT_STATUS_IS_OK(result
))
364 printf(_("Joined domain %s.\n"), c
->opt_target_workgroup
);
367 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
368 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
369 result
= NT_STATUS_UNSUCCESSFUL
;
376 * Join a domain, the old way.
378 * @param argc Standard main() style argc.
379 * @param argv Standard main() style argv. Initial components are already
382 * @return A shell status integer (0 for success).
385 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
387 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
388 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
389 rpc_oldjoin_internals
,
394 * Join a domain, the old way. This function exists to allow
395 * the message to be displayed when oldjoin was explicitly
396 * requested, but not when it was implied by "net rpc join".
398 * @param argc Standard main() style argc.
399 * @param argv Standard main() style argv. Initial components are already
402 * @return A shell status integer (0 for success).
405 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
409 if (c
->display_usage
) {
414 _("Join a domain the old way"));
418 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
421 d_fprintf(stderr
, _("Failed to join domain\n"));
428 * 'net rpc join' entrypoint.
429 * @param argc Standard main() style argc.
430 * @param argv Standard main() style argv. Initial components are already
433 * Main 'net_rpc_join()' (where the admin username/password is used) is
435 * Try to just change the password, but if that doesn't work, use/prompt
436 * for a username/password.
439 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
441 if (c
->display_usage
) {
444 _("net rpc join -U <username>[%%password] <type>\n"
446 " username\tName of the admin user"
447 " password\tPassword of the admin user, will "
448 "prompt if not specified\n"
449 " type\tCan be one of the following:\n"
450 "\t\tMEMBER\tJoin as member server (default)\n"
451 "\t\tBDC\tJoin as BDC\n"
452 "\t\tPDC\tJoin as PDC\n"));
456 if (lp_server_role() == ROLE_STANDALONE
) {
457 d_printf(_("cannot join as standalone machine\n"));
461 if (strlen(global_myname()) > 15) {
462 d_printf(_("Our netbios name can be at most 15 chars long, "
463 "\"%s\" is %u chars long\n"),
464 global_myname(), (unsigned int)strlen(global_myname()));
468 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
471 return net_rpc_join_newstyle(c
, argc
, argv
);
475 * display info about a rpc domain
477 * All parameters are provided by the run_rpc_command function, except for
478 * argc, argv which are passed through.
480 * @param domain_sid The domain sid acquired from the remote server
481 * @param cli A cli_state connected to the server.
482 * @param mem_ctx Talloc context, destroyed on completion of the function.
483 * @param argc Standard main() style argc.
484 * @param argv Standard main() style argv. Initial components are already
487 * @return Normal NTSTATUS return.
490 NTSTATUS
rpc_info_internals(struct net_context
*c
,
491 const DOM_SID
*domain_sid
,
492 const char *domain_name
,
493 struct cli_state
*cli
,
494 struct rpc_pipe_client
*pipe_hnd
,
499 struct policy_handle connect_pol
, domain_pol
;
500 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
501 union samr_DomainInfo
*info
= NULL
;
504 sid_to_fstring(sid_str
, domain_sid
);
506 /* Get sam policy handle */
507 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
509 MAXIMUM_ALLOWED_ACCESS
,
511 if (!NT_STATUS_IS_OK(result
)) {
512 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
517 /* Get domain policy handle */
518 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
520 MAXIMUM_ALLOWED_ACCESS
,
521 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
523 if (!NT_STATUS_IS_OK(result
)) {
524 d_fprintf(stderr
, _("Could not open domain: %s\n"),
529 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
533 if (NT_STATUS_IS_OK(result
)) {
534 d_printf(_("Domain Name: %s\n"),
535 info
->general
.domain_name
.string
);
536 d_printf(_("Domain SID: %s\n"), sid_str
);
537 d_printf(_("Sequence number: %llu\n"),
538 (unsigned long long)info
->general
.sequence_num
);
539 d_printf(_("Num users: %u\n"), info
->general
.num_users
);
540 d_printf(_("Num domain groups: %u\n"),info
->general
.num_groups
);
541 d_printf(_("Num local groups: %u\n"),info
->general
.num_aliases
);
549 * 'net rpc info' entrypoint.
550 * @param argc Standard main() style argc.
551 * @param argv Standard main() style argv. Initial components are already
555 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
557 if (c
->display_usage
) {
562 _("Display information about the domain"));
566 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
567 NET_FLAGS_PDC
, rpc_info_internals
,
572 * Fetch domain SID into the local secrets.tdb.
574 * All parameters are provided by the run_rpc_command function, except for
575 * argc, argv which are passed through.
577 * @param domain_sid The domain sid acquired from the remote server.
578 * @param cli A cli_state connected to the server.
579 * @param mem_ctx Talloc context, destroyed on completion of the function.
580 * @param argc Standard main() style argc.
581 * @param argv Standard main() style argv. Initial components are already
584 * @return Normal NTSTATUS return.
587 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
588 const DOM_SID
*domain_sid
,
589 const char *domain_name
,
590 struct cli_state
*cli
,
591 struct rpc_pipe_client
*pipe_hnd
,
598 sid_to_fstring(sid_str
, domain_sid
);
599 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
600 sid_str
, domain_name
);
602 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
603 DEBUG(0,("Can't store domain SID\n"));
604 return NT_STATUS_UNSUCCESSFUL
;
611 * 'net rpc getsid' entrypoint.
612 * @param argc Standard main() style argc.
613 * @param argv Standard main() style argv. Initial components are already
617 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
619 int conn_flags
= NET_FLAGS_PDC
;
621 if (!c
->opt_user_specified
) {
622 conn_flags
|= NET_FLAGS_ANONYMOUS
;
625 if (c
->display_usage
) {
630 _("Fetch domain SID into local secrets.tdb"));
634 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
636 rpc_getsid_internals
,
640 /****************************************************************************/
643 * Basic usage function for 'net rpc user'.
644 * @param argc Standard main() style argc.
645 * @param argv Standard main() style argv. Initial components are already
649 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
651 return net_user_usage(c
, argc
, argv
);
655 * Add a new user to a remote RPC server.
657 * @param argc Standard main() style argc.
658 * @param argv Standard main() style argv. Initial components are already
661 * @return A shell status integer (0 for success).
664 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
666 NET_API_STATUS status
;
667 struct USER_INFO_1 info1
;
668 uint32_t parm_error
= 0;
670 if (argc
< 1 || c
->display_usage
) {
671 rpc_user_usage(c
, argc
, argv
);
677 info1
.usri1_name
= argv
[0];
679 info1
.usri1_password
= argv
[1];
682 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
685 d_fprintf(stderr
,_("Failed to add user '%s' with error: %s.\n"),
686 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
690 d_printf(_("Added user '%s'.\n"), argv
[0]);
697 * Rename a user on a remote RPC server.
699 * @param argc Standard main() style argc.
700 * @param argv Standard main() style argv. Initial components are already
703 * @return A shell status integer (0 for success).
706 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
708 NET_API_STATUS status
;
709 struct USER_INFO_0 u0
;
710 uint32_t parm_err
= 0;
712 if (argc
!= 2 || c
->display_usage
) {
713 rpc_user_usage(c
, argc
, argv
);
717 u0
.usri0_name
= argv
[1];
719 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
720 0, (uint8_t *)&u0
, &parm_err
);
723 _("Failed to rename user from %s to %s - %s\n"),
725 libnetapi_get_error_string(c
->netapi_ctx
, status
));
727 d_printf(_("Renamed user from %s to %s\n"), argv
[0], argv
[1]);
734 * Delete a user from a remote RPC server.
736 * @param argc Standard main() style argc.
737 * @param argv Standard main() style argv. Initial components are already
740 * @return A shell status integer (0 for success).
743 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
745 NET_API_STATUS status
;
747 if (argc
< 1 || c
->display_usage
) {
748 rpc_user_usage(c
, argc
, argv
);
752 status
= NetUserDel(c
->opt_host
, argv
[0]);
755 d_fprintf(stderr
, _("Failed to delete user '%s' with: %s.\n"),
757 libnetapi_get_error_string(c
->netapi_ctx
, status
));
760 d_printf(_("Deleted user '%s'.\n"), argv
[0]);
767 * Set a user's password on a remote RPC server.
769 * @param argc Standard main() style argc.
770 * @param argv Standard main() style argv. Initial components are already
773 * @return A shell status integer (0 for success).
776 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
778 NET_API_STATUS status
;
780 struct USER_INFO_1003 u1003
;
781 uint32_t parm_err
= 0;
784 if (argc
< 1 || c
->display_usage
) {
785 rpc_user_usage(c
, argc
, argv
);
790 u1003
.usri1003_password
= argv
[1];
792 ret
= asprintf(&prompt
, _("Enter new password for %s:"),
797 u1003
.usri1003_password
= getpass(prompt
);
801 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
803 /* Display results */
806 _("Failed to set password for '%s' with error: %s.\n"),
807 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
816 * List a user's groups from a remote RPC server.
818 * @param argc Standard main() style argc.
819 * @param argv Standard main() style argv. Initial components are already
822 * @return A shell status integer (0 for success)
825 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
828 NET_API_STATUS status
;
829 struct GROUP_USERS_INFO_0
*u0
= NULL
;
830 uint32_t entries_read
= 0;
831 uint32_t total_entries
= 0;
835 if (argc
< 1 || c
->display_usage
) {
836 rpc_user_usage(c
, argc
, argv
);
840 status
= NetUserGetGroups(c
->opt_host
,
843 (uint8_t **)(void *)&u0
,
849 _("Failed to get groups for '%s' with error: %s.\n"),
850 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
855 for (i
=0; i
< entries_read
; i
++) {
856 printf("%s\n", u0
->grui0_name
);
864 * List users on a remote RPC server.
866 * All parameters are provided by the run_rpc_command function, except for
867 * argc, argv which are passed through.
869 * @param domain_sid The domain sid acquired from the remote server.
870 * @param cli A cli_state connected to the server.
871 * @param mem_ctx Talloc context, destroyed on completion of the function.
872 * @param argc Standard main() style argc.
873 * @param argv Standard main() style argv. Initial components are already
876 * @return Normal NTSTATUS return.
879 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
881 NET_API_STATUS status
;
882 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
883 struct NET_DISPLAY_USER
*info
= NULL
;
886 /* Query domain users */
887 if (c
->opt_long_list_entries
)
888 d_printf(_("\nUser name Comment"
889 "\n-----------------------------\n"));
891 uint32_t max_entries
, max_size
;
893 get_query_dispinfo_params(
894 loop_count
, &max_entries
, &max_size
);
896 status
= NetQueryDisplayInformation(c
->opt_host
,
903 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
907 info
= (struct NET_DISPLAY_USER
*)buffer
;
909 for (i
= 0; i
< num_entries
; i
++) {
911 if (c
->opt_long_list_entries
)
912 printf("%-21.21s %s\n", info
->usri1_name
,
913 info
->usri1_comment
);
915 printf("%s\n", info
->usri1_name
);
919 NetApiBufferFree(buffer
);
922 start_idx
+= num_entries
;
924 } while (status
== ERROR_MORE_DATA
);
930 * 'net rpc user' entrypoint.
931 * @param argc Standard main() style argc.
932 * @param argv Standard main() style argv. Initial components are already
936 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
938 NET_API_STATUS status
;
940 struct functable func
[] = {
945 N_("Add specified user"),
946 N_("net rpc user add\n"
947 " Add specified user")
953 N_("List domain groups of user"),
954 N_("net rpc user info\n"
955 " Lis domain groups of user")
961 N_("Remove specified user"),
962 N_("net rpc user delete\n"
963 " Remove specified user")
969 N_("Change user password"),
970 N_("net rpc user password\n"
971 " Change user password")
977 N_("Rename specified user"),
978 N_("net rpc user rename\n"
979 " Rename specified user")
981 {NULL
, NULL
, 0, NULL
, NULL
}
984 status
= libnetapi_init(&c
->netapi_ctx
);
988 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
989 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
990 if (c
->opt_kerberos
) {
991 libnetapi_set_use_kerberos(c
->netapi_ctx
);
995 if (c
->display_usage
) {
1000 _("List all users"));
1001 net_display_usage_from_functable(func
);
1005 return rpc_user_list(c
, argc
, argv
);
1008 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
1011 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
1012 TALLOC_CTX
*mem_ctx
,
1013 struct rpc_sh_ctx
*ctx
,
1014 struct rpc_pipe_client
*pipe_hnd
,
1015 int argc
, const char **argv
)
1017 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
1020 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
1021 TALLOC_CTX
*mem_ctx
,
1022 struct rpc_sh_ctx
*ctx
,
1023 struct rpc_pipe_client
*pipe_hnd
,
1024 int argc
, const char **argv
)
1026 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1029 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1030 TALLOC_CTX
*mem_ctx
,
1031 struct rpc_sh_ctx
*ctx
,
1032 struct rpc_pipe_client
*pipe_hnd
,
1033 int argc
, const char **argv
,
1035 struct net_context
*c
,
1036 TALLOC_CTX
*mem_ctx
,
1037 struct rpc_sh_ctx
*ctx
,
1038 struct rpc_pipe_client
*pipe_hnd
,
1039 struct policy_handle
*user_hnd
,
1040 int argc
, const char **argv
))
1042 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1043 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1046 enum lsa_SidType type
;
1049 d_fprintf(stderr
, "%s %s <username>\n", _("Usage:"),
1051 return NT_STATUS_INVALID_PARAMETER
;
1054 ZERO_STRUCT(connect_pol
);
1055 ZERO_STRUCT(domain_pol
);
1056 ZERO_STRUCT(user_pol
);
1058 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1059 argv
[0], NULL
, NULL
, &sid
, &type
);
1060 if (!NT_STATUS_IS_OK(result
)) {
1061 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1066 if (type
!= SID_NAME_USER
) {
1067 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1068 sid_type_lookup(type
));
1069 result
= NT_STATUS_NO_SUCH_USER
;
1073 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1074 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1075 result
= NT_STATUS_NO_SUCH_USER
;
1079 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1081 MAXIMUM_ALLOWED_ACCESS
,
1083 if (!NT_STATUS_IS_OK(result
)) {
1087 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1089 MAXIMUM_ALLOWED_ACCESS
,
1092 if (!NT_STATUS_IS_OK(result
)) {
1096 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1098 MAXIMUM_ALLOWED_ACCESS
,
1101 if (!NT_STATUS_IS_OK(result
)) {
1105 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1108 if (is_valid_policy_hnd(&user_pol
)) {
1109 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1111 if (is_valid_policy_hnd(&domain_pol
)) {
1112 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1114 if (is_valid_policy_hnd(&connect_pol
)) {
1115 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1120 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1121 TALLOC_CTX
*mem_ctx
,
1122 struct rpc_sh_ctx
*ctx
,
1123 struct rpc_pipe_client
*pipe_hnd
,
1124 struct policy_handle
*user_hnd
,
1125 int argc
, const char **argv
)
1128 union samr_UserInfo
*info
= NULL
;
1131 d_fprintf(stderr
, "%s %s show <username>\n", _("Usage:"),
1133 return NT_STATUS_INVALID_PARAMETER
;
1136 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1140 if (!NT_STATUS_IS_OK(result
)) {
1144 d_printf(_("user rid: %d, group rid: %d\n"),
1146 info
->info21
.primary_gid
);
1151 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1152 TALLOC_CTX
*mem_ctx
,
1153 struct rpc_sh_ctx
*ctx
,
1154 struct rpc_pipe_client
*pipe_hnd
,
1155 int argc
, const char **argv
)
1157 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1158 rpc_sh_user_show_internals
);
1161 #define FETCHSTR(name, rec) \
1162 do { if (strequal(ctx->thiscmd, name)) { \
1163 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1166 #define SETSTR(name, rec, flag) \
1167 do { if (strequal(ctx->thiscmd, name)) { \
1168 init_lsa_String(&(info->info21.rec), argv[0]); \
1169 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1172 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1173 TALLOC_CTX
*mem_ctx
,
1174 struct rpc_sh_ctx
*ctx
,
1175 struct rpc_pipe_client
*pipe_hnd
,
1176 struct policy_handle
*user_hnd
,
1177 int argc
, const char **argv
)
1180 const char *username
;
1181 const char *oldval
= "";
1182 union samr_UserInfo
*info
= NULL
;
1185 d_fprintf(stderr
, "%s %s <username> [new value|NULL]\n",
1186 _("Usage:"), ctx
->whoami
);
1187 return NT_STATUS_INVALID_PARAMETER
;
1190 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1194 if (!NT_STATUS_IS_OK(result
)) {
1198 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1200 FETCHSTR("fullname", full_name
);
1201 FETCHSTR("homedir", home_directory
);
1202 FETCHSTR("homedrive", home_drive
);
1203 FETCHSTR("logonscript", logon_script
);
1204 FETCHSTR("profilepath", profile_path
);
1205 FETCHSTR("description", description
);
1208 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1212 if (strcmp(argv
[0], "NULL") == 0) {
1216 ZERO_STRUCT(info
->info21
);
1218 SETSTR("fullname", full_name
, FULL_NAME
);
1219 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1220 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1221 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1222 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1223 SETSTR("description", description
, DESCRIPTION
);
1225 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1230 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1231 ctx
->thiscmd
, oldval
, argv
[0]);
1238 #define HANDLEFLG(name, rec) \
1239 do { if (strequal(ctx->thiscmd, name)) { \
1240 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1242 newflags = oldflags | ACB_##rec; \
1244 newflags = oldflags & ~ACB_##rec; \
1247 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1248 TALLOC_CTX
*mem_ctx
,
1249 struct rpc_sh_ctx
*ctx
,
1250 struct rpc_pipe_client
*pipe_hnd
,
1251 int argc
, const char **argv
)
1253 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1254 rpc_sh_user_str_edit_internals
);
1257 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1258 TALLOC_CTX
*mem_ctx
,
1259 struct rpc_sh_ctx
*ctx
,
1260 struct rpc_pipe_client
*pipe_hnd
,
1261 struct policy_handle
*user_hnd
,
1262 int argc
, const char **argv
)
1265 const char *username
;
1266 const char *oldval
= "unknown";
1267 uint32 oldflags
, newflags
;
1269 union samr_UserInfo
*info
= NULL
;
1272 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1273 !strequal(argv
[0], "no"))) {
1274 /* TRANSATORS: The yes|no here are program keywords. Please do
1276 d_fprintf(stderr
, _("Usage: %s <username> [yes|no]\n"),
1278 return NT_STATUS_INVALID_PARAMETER
;
1281 newval
= strequal(argv
[0], "yes");
1283 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1287 if (!NT_STATUS_IS_OK(result
)) {
1291 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1292 oldflags
= info
->info21
.acct_flags
;
1293 newflags
= info
->info21
.acct_flags
;
1295 HANDLEFLG("disabled", DISABLED
);
1296 HANDLEFLG("pwnotreq", PWNOTREQ
);
1297 HANDLEFLG("autolock", AUTOLOCK
);
1298 HANDLEFLG("pwnoexp", PWNOEXP
);
1301 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1306 ZERO_STRUCT(info
->info21
);
1308 info
->info21
.acct_flags
= newflags
;
1309 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1311 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1316 if (NT_STATUS_IS_OK(result
)) {
1317 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1318 ctx
->thiscmd
, oldval
, argv
[0]);
1326 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1327 TALLOC_CTX
*mem_ctx
,
1328 struct rpc_sh_ctx
*ctx
,
1329 struct rpc_pipe_client
*pipe_hnd
,
1330 int argc
, const char **argv
)
1332 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1333 rpc_sh_user_flag_edit_internals
);
1336 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1337 TALLOC_CTX
*mem_ctx
,
1338 struct rpc_sh_ctx
*ctx
)
1340 static struct rpc_sh_cmd cmds
[] = {
1342 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1343 N_("Show/Set a user's full name") },
1345 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1346 N_("Show/Set a user's home directory") },
1348 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1349 N_("Show/Set a user's home drive") },
1351 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1352 N_("Show/Set a user's logon script") },
1354 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1355 N_("Show/Set a user's profile path") },
1357 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1358 N_("Show/Set a user's description") },
1360 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1361 N_("Show/Set whether a user is disabled") },
1363 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1364 N_("Show/Set whether a user locked out") },
1366 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1367 N_("Show/Set whether a user does not need a password") },
1369 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1370 N_("Show/Set whether a user's password does not expire") },
1372 { NULL
, NULL
, 0, NULL
, NULL
}
1378 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1379 TALLOC_CTX
*mem_ctx
,
1380 struct rpc_sh_ctx
*ctx
)
1382 static struct rpc_sh_cmd cmds
[] = {
1384 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1385 N_("List available users") },
1387 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1388 N_("List the domain groups a user is member of") },
1390 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1391 N_("Show info about a user") },
1393 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1394 N_("Show/Modify a user's fields") },
1396 { NULL
, NULL
, 0, NULL
, NULL
}
1402 /****************************************************************************/
1405 * Basic usage function for 'net rpc group'.
1406 * @param argc Standard main() style argc.
1407 * @param argv Standard main() style argv. Initial components are already
1411 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1413 return net_group_usage(c
, argc
, argv
);
1417 * Delete group on a remote RPC server.
1419 * All parameters are provided by the run_rpc_command function, except for
1420 * argc, argv which are passed through.
1422 * @param domain_sid The domain sid acquired from the remote server.
1423 * @param cli A cli_state connected to the server.
1424 * @param mem_ctx Talloc context, destroyed on completion of the function.
1425 * @param argc Standard main() style argc.
1426 * @param argv Standard main() style argv. Initial components are already
1429 * @return Normal NTSTATUS return.
1432 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1433 const DOM_SID
*domain_sid
,
1434 const char *domain_name
,
1435 struct cli_state
*cli
,
1436 struct rpc_pipe_client
*pipe_hnd
,
1437 TALLOC_CTX
*mem_ctx
,
1441 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1442 bool group_is_primary
= false;
1443 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1445 struct samr_RidTypeArray
*rids
= NULL
;
1448 /* struct samr_RidWithAttribute *user_gids; */
1450 struct samr_Ids group_rids
, name_types
;
1451 struct lsa_String lsa_acct_name
;
1452 union samr_UserInfo
*info
= NULL
;
1454 if (argc
< 1 || c
->display_usage
) {
1455 rpc_group_usage(c
, argc
,argv
);
1456 return NT_STATUS_OK
; /* ok? */
1459 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1461 MAXIMUM_ALLOWED_ACCESS
,
1464 if (!NT_STATUS_IS_OK(result
)) {
1465 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1469 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1471 MAXIMUM_ALLOWED_ACCESS
,
1472 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1475 if (!NT_STATUS_IS_OK(result
)) {
1476 d_fprintf(stderr
, _("Request open_domain failed\n"));
1480 init_lsa_String(&lsa_acct_name
, argv
[0]);
1482 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1488 if (!NT_STATUS_IS_OK(result
)) {
1489 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1493 switch (name_types
.ids
[0])
1495 case SID_NAME_DOM_GRP
:
1496 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1498 MAXIMUM_ALLOWED_ACCESS
,
1501 if (!NT_STATUS_IS_OK(result
)) {
1502 d_fprintf(stderr
, _("Request open_group failed"));
1506 group_rid
= group_rids
.ids
[0];
1508 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1512 if (!NT_STATUS_IS_OK(result
)) {
1514 _("Unable to query group members of %s"),
1519 if (c
->opt_verbose
) {
1521 _("Domain Group %s (rid: %d) has %d members\n"),
1522 argv
[0],group_rid
, rids
->count
);
1525 /* Check if group is anyone's primary group */
1526 for (i
= 0; i
< rids
->count
; i
++)
1528 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1530 MAXIMUM_ALLOWED_ACCESS
,
1534 if (!NT_STATUS_IS_OK(result
)) {
1536 _("Unable to open group member %d\n"),
1541 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1546 if (!NT_STATUS_IS_OK(result
)) {
1548 _("Unable to lookup userinfo for group "
1554 if (info
->info21
.primary_gid
== group_rid
) {
1555 if (c
->opt_verbose
) {
1556 d_printf(_("Group is primary group "
1558 info
->info21
.account_name
.string
);
1560 group_is_primary
= true;
1563 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1566 if (group_is_primary
) {
1567 d_fprintf(stderr
, _("Unable to delete group because "
1568 "some of it's members have it as primary "
1570 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1574 /* remove all group members */
1575 for (i
= 0; i
< rids
->count
; i
++)
1578 d_printf(_("Remove group member %d..."),
1580 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1584 if (NT_STATUS_IS_OK(result
)) {
1586 d_printf(_("ok\n"));
1589 d_printf("%s\n", _("failed"));
1594 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1598 /* removing a local group is easier... */
1599 case SID_NAME_ALIAS
:
1600 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1602 MAXIMUM_ALLOWED_ACCESS
,
1606 if (!NT_STATUS_IS_OK(result
)) {
1607 d_fprintf(stderr
, _("Request open_alias failed\n"));
1611 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1615 d_fprintf(stderr
, _("%s is of type %s. This command is only "
1616 "for deleting local or global groups\n"),
1617 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1618 result
= NT_STATUS_UNSUCCESSFUL
;
1622 if (NT_STATUS_IS_OK(result
)) {
1624 d_printf(_("Deleted %s '%s'\n"),
1625 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
1627 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
1628 get_friendly_nt_error_msg(result
));
1636 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1638 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1639 rpc_group_delete_internals
, argc
,argv
);
1642 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1644 NET_API_STATUS status
;
1645 struct GROUP_INFO_1 info1
;
1646 uint32_t parm_error
= 0;
1648 if (argc
!= 1 || c
->display_usage
) {
1649 rpc_group_usage(c
, argc
, argv
);
1655 info1
.grpi1_name
= argv
[0];
1656 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1657 info1
.grpi1_comment
= c
->opt_comment
;
1660 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1664 _("Failed to add group '%s' with error: %s.\n"),
1665 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1669 d_printf(_("Added group '%s'.\n"), argv
[0]);
1675 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1677 NET_API_STATUS status
;
1678 struct LOCALGROUP_INFO_1 info1
;
1679 uint32_t parm_error
= 0;
1681 if (argc
!= 1 || c
->display_usage
) {
1682 rpc_group_usage(c
, argc
, argv
);
1688 info1
.lgrpi1_name
= argv
[0];
1689 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1690 info1
.lgrpi1_comment
= c
->opt_comment
;
1693 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1697 _("Failed to add alias '%s' with error: %s.\n"),
1698 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1702 d_printf(_("Added alias '%s'.\n"), argv
[0]);
1708 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1710 if (c
->opt_localgroup
)
1711 return rpc_alias_add_internals(c
, argc
, argv
);
1713 return rpc_group_add_internals(c
, argc
, argv
);
1716 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1717 TALLOC_CTX
*mem_ctx
,
1720 enum lsa_SidType
*type
)
1722 DOM_SID
*sids
= NULL
;
1723 enum lsa_SidType
*types
= NULL
;
1724 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1725 struct policy_handle lsa_pol
;
1726 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1728 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1730 if (!NT_STATUS_IS_OK(result
)) {
1734 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1735 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
1737 if (!NT_STATUS_IS_OK(result
)) {
1741 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1742 &name
, NULL
, 1, &sids
, &types
);
1744 if (NT_STATUS_IS_OK(result
)) {
1745 sid_copy(sid
, &sids
[0]);
1749 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1753 TALLOC_FREE(pipe_hnd
);
1756 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1758 /* Try as S-1-5-whatever */
1762 if (string_to_sid(&tmp_sid
, name
)) {
1763 sid_copy(sid
, &tmp_sid
);
1764 *type
= SID_NAME_UNKNOWN
;
1765 result
= NT_STATUS_OK
;
1772 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1773 TALLOC_CTX
*mem_ctx
,
1774 const DOM_SID
*group_sid
,
1777 struct policy_handle connect_pol
, domain_pol
;
1780 struct policy_handle group_pol
;
1782 struct samr_Ids rids
, rid_types
;
1783 struct lsa_String lsa_acct_name
;
1787 sid_copy(&sid
, group_sid
);
1789 if (!sid_split_rid(&sid
, &group_rid
)) {
1790 return NT_STATUS_UNSUCCESSFUL
;
1793 /* Get sam policy handle */
1794 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1796 MAXIMUM_ALLOWED_ACCESS
,
1798 if (!NT_STATUS_IS_OK(result
)) {
1802 /* Get domain policy handle */
1803 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1805 MAXIMUM_ALLOWED_ACCESS
,
1808 if (!NT_STATUS_IS_OK(result
)) {
1812 init_lsa_String(&lsa_acct_name
, member
);
1814 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1821 if (!NT_STATUS_IS_OK(result
)) {
1822 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1827 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1829 MAXIMUM_ALLOWED_ACCESS
,
1833 if (!NT_STATUS_IS_OK(result
)) {
1837 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1840 0x0005); /* unknown flags */
1843 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1847 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1848 TALLOC_CTX
*mem_ctx
,
1849 const DOM_SID
*alias_sid
,
1852 struct policy_handle connect_pol
, domain_pol
;
1855 struct policy_handle alias_pol
;
1858 enum lsa_SidType member_type
;
1862 sid_copy(&sid
, alias_sid
);
1864 if (!sid_split_rid(&sid
, &alias_rid
)) {
1865 return NT_STATUS_UNSUCCESSFUL
;
1868 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1869 member
, &member_sid
, &member_type
);
1871 if (!NT_STATUS_IS_OK(result
)) {
1872 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1877 /* Get sam policy handle */
1878 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1880 MAXIMUM_ALLOWED_ACCESS
,
1882 if (!NT_STATUS_IS_OK(result
)) {
1886 /* Get domain policy handle */
1887 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1889 MAXIMUM_ALLOWED_ACCESS
,
1892 if (!NT_STATUS_IS_OK(result
)) {
1896 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1898 MAXIMUM_ALLOWED_ACCESS
,
1902 if (!NT_STATUS_IS_OK(result
)) {
1906 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1910 if (!NT_STATUS_IS_OK(result
)) {
1915 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1919 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1920 const DOM_SID
*domain_sid
,
1921 const char *domain_name
,
1922 struct cli_state
*cli
,
1923 struct rpc_pipe_client
*pipe_hnd
,
1924 TALLOC_CTX
*mem_ctx
,
1929 enum lsa_SidType group_type
;
1931 if (argc
!= 2 || c
->display_usage
) {
1934 _("net rpc group addmem <group> <member>\n"
1935 " Add a member to a group\n"
1936 " group\tGroup to add member to\n"
1937 " member\tMember to add to group\n"));
1938 return NT_STATUS_UNSUCCESSFUL
;
1941 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1942 &group_sid
, &group_type
))) {
1943 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
1945 return NT_STATUS_UNSUCCESSFUL
;
1948 if (group_type
== SID_NAME_DOM_GRP
) {
1949 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1950 &group_sid
, argv
[1]);
1952 if (!NT_STATUS_IS_OK(result
)) {
1953 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1954 argv
[1], argv
[0], nt_errstr(result
));
1959 if (group_type
== SID_NAME_ALIAS
) {
1960 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1961 &group_sid
, argv
[1]);
1963 if (!NT_STATUS_IS_OK(result
)) {
1964 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1965 argv
[1], argv
[0], nt_errstr(result
));
1970 d_fprintf(stderr
, _("Can only add members to global or local groups "
1971 "which %s is not\n"), argv
[0]);
1973 return NT_STATUS_UNSUCCESSFUL
;
1976 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1978 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1979 rpc_group_addmem_internals
,
1983 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1984 struct rpc_pipe_client
*pipe_hnd
,
1985 TALLOC_CTX
*mem_ctx
,
1986 const DOM_SID
*group_sid
,
1989 struct policy_handle connect_pol
, domain_pol
;
1992 struct policy_handle group_pol
;
1994 struct samr_Ids rids
, rid_types
;
1995 struct lsa_String lsa_acct_name
;
1999 sid_copy(&sid
, group_sid
);
2001 if (!sid_split_rid(&sid
, &group_rid
))
2002 return NT_STATUS_UNSUCCESSFUL
;
2004 /* Get sam policy handle */
2005 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2007 MAXIMUM_ALLOWED_ACCESS
,
2009 if (!NT_STATUS_IS_OK(result
))
2012 /* Get domain policy handle */
2013 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2015 MAXIMUM_ALLOWED_ACCESS
,
2018 if (!NT_STATUS_IS_OK(result
))
2021 init_lsa_String(&lsa_acct_name
, member
);
2023 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2029 if (!NT_STATUS_IS_OK(result
)) {
2030 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2035 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2037 MAXIMUM_ALLOWED_ACCESS
,
2041 if (!NT_STATUS_IS_OK(result
))
2044 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2049 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2053 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2054 TALLOC_CTX
*mem_ctx
,
2055 const DOM_SID
*alias_sid
,
2058 struct policy_handle connect_pol
, domain_pol
;
2061 struct policy_handle alias_pol
;
2064 enum lsa_SidType member_type
;
2068 sid_copy(&sid
, alias_sid
);
2070 if (!sid_split_rid(&sid
, &alias_rid
))
2071 return NT_STATUS_UNSUCCESSFUL
;
2073 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2074 member
, &member_sid
, &member_type
);
2076 if (!NT_STATUS_IS_OK(result
)) {
2077 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2082 /* Get sam policy handle */
2083 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2085 MAXIMUM_ALLOWED_ACCESS
,
2087 if (!NT_STATUS_IS_OK(result
)) {
2091 /* Get domain policy handle */
2092 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2094 MAXIMUM_ALLOWED_ACCESS
,
2097 if (!NT_STATUS_IS_OK(result
)) {
2101 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2103 MAXIMUM_ALLOWED_ACCESS
,
2107 if (!NT_STATUS_IS_OK(result
))
2110 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2114 if (!NT_STATUS_IS_OK(result
))
2118 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2122 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2123 const DOM_SID
*domain_sid
,
2124 const char *domain_name
,
2125 struct cli_state
*cli
,
2126 struct rpc_pipe_client
*pipe_hnd
,
2127 TALLOC_CTX
*mem_ctx
,
2132 enum lsa_SidType group_type
;
2134 if (argc
!= 2 || c
->display_usage
) {
2137 _("net rpc group delmem <group> <member>\n"
2138 " Delete a member from a group\n"
2139 " group\tGroup to delete member from\n"
2140 " member\tMember to delete from group\n"));
2141 return NT_STATUS_UNSUCCESSFUL
;
2144 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2145 &group_sid
, &group_type
))) {
2146 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2148 return NT_STATUS_UNSUCCESSFUL
;
2151 if (group_type
== SID_NAME_DOM_GRP
) {
2152 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2153 &group_sid
, argv
[1]);
2155 if (!NT_STATUS_IS_OK(result
)) {
2156 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2157 argv
[1], argv
[0], nt_errstr(result
));
2162 if (group_type
== SID_NAME_ALIAS
) {
2163 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2164 &group_sid
, argv
[1]);
2166 if (!NT_STATUS_IS_OK(result
)) {
2167 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2168 argv
[1], argv
[0], nt_errstr(result
));
2173 d_fprintf(stderr
, _("Can only delete members from global or local "
2174 "groups which %s is not\n"), argv
[0]);
2176 return NT_STATUS_UNSUCCESSFUL
;
2179 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2181 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2182 rpc_group_delmem_internals
,
2187 * List groups on a remote RPC server.
2189 * All parameters are provided by the run_rpc_command function, except for
2190 * argc, argv which are passes through.
2192 * @param domain_sid The domain sid acquired from the remote server.
2193 * @param cli A cli_state connected to the server.
2194 * @param mem_ctx Talloc context, destroyed on completion of the function.
2195 * @param argc Standard main() style argc.
2196 * @param argv Standard main() style argv. Initial components are already
2199 * @return Normal NTSTATUS return.
2202 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2203 const DOM_SID
*domain_sid
,
2204 const char *domain_name
,
2205 struct cli_state
*cli
,
2206 struct rpc_pipe_client
*pipe_hnd
,
2207 TALLOC_CTX
*mem_ctx
,
2211 struct policy_handle connect_pol
, domain_pol
;
2212 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2213 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2214 struct samr_SamArray
*groups
= NULL
;
2215 bool global
= false;
2217 bool builtin
= false;
2219 if (c
->display_usage
) {
2222 _("net rpc group list [global] [local] [builtin]\n"
2223 " List groups on RPC server\n"
2224 " global\tList global groups\n"
2225 " local\tList local groups\n"
2226 " builtin\tList builtin groups\n"
2227 " If none of global, local or builtin is "
2228 "specified, all three options are considered "
2230 return NT_STATUS_OK
;
2239 for (i
=0; i
<argc
; i
++) {
2240 if (strequal(argv
[i
], "global"))
2243 if (strequal(argv
[i
], "local"))
2246 if (strequal(argv
[i
], "builtin"))
2250 /* Get sam policy handle */
2252 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2254 MAXIMUM_ALLOWED_ACCESS
,
2256 if (!NT_STATUS_IS_OK(result
)) {
2260 /* Get domain policy handle */
2262 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2264 MAXIMUM_ALLOWED_ACCESS
,
2265 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2267 if (!NT_STATUS_IS_OK(result
)) {
2271 /* Query domain groups */
2272 if (c
->opt_long_list_entries
)
2273 d_printf(_("\nGroup name Comment"
2274 "\n-----------------------------\n"));
2276 uint32_t max_size
, total_size
, returned_size
;
2277 union samr_DispInfo info
;
2281 get_query_dispinfo_params(
2282 loop_count
, &max_entries
, &max_size
);
2284 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2293 num_entries
= info
.info3
.count
;
2294 start_idx
+= info
.info3
.count
;
2296 if (!NT_STATUS_IS_OK(result
) &&
2297 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2300 for (i
= 0; i
< num_entries
; i
++) {
2302 const char *group
= NULL
;
2303 const char *desc
= NULL
;
2305 group
= info
.info3
.entries
[i
].account_name
.string
;
2306 desc
= info
.info3
.entries
[i
].description
.string
;
2308 if (c
->opt_long_list_entries
)
2309 printf("%-21.21s %-50.50s\n",
2312 printf("%s\n", group
);
2314 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2315 /* query domain aliases */
2320 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2326 if (!NT_STATUS_IS_OK(result
) &&
2327 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2330 for (i
= 0; i
< num_entries
; i
++) {
2332 const char *description
= NULL
;
2334 if (c
->opt_long_list_entries
) {
2336 struct policy_handle alias_pol
;
2337 union samr_AliasInfo
*info
= NULL
;
2339 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2342 groups
->entries
[i
].idx
,
2344 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2348 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2350 description
= info
->description
.string
;
2354 if (description
!= NULL
) {
2355 printf("%-21.21s %-50.50s\n",
2356 groups
->entries
[i
].name
.string
,
2359 printf("%s\n", groups
->entries
[i
].name
.string
);
2362 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2363 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2364 /* Get builtin policy handle */
2366 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2368 MAXIMUM_ALLOWED_ACCESS
,
2369 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2371 if (!NT_STATUS_IS_OK(result
)) {
2374 /* query builtin aliases */
2377 if (!builtin
) break;
2379 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2385 if (!NT_STATUS_IS_OK(result
) &&
2386 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2389 for (i
= 0; i
< num_entries
; i
++) {
2391 const char *description
= NULL
;
2393 if (c
->opt_long_list_entries
) {
2395 struct policy_handle alias_pol
;
2396 union samr_AliasInfo
*info
= NULL
;
2398 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2401 groups
->entries
[i
].idx
,
2403 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2407 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2409 description
= info
->description
.string
;
2413 if (description
!= NULL
) {
2414 printf("%-21.21s %-50.50s\n",
2415 groups
->entries
[i
].name
.string
,
2418 printf("%s\n", groups
->entries
[i
].name
.string
);
2421 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2427 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2429 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2430 rpc_group_list_internals
,
2434 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2435 struct rpc_pipe_client
*pipe_hnd
,
2436 TALLOC_CTX
*mem_ctx
,
2437 const char *domain_name
,
2438 const DOM_SID
*domain_sid
,
2439 struct policy_handle
*domain_pol
,
2443 struct policy_handle group_pol
;
2444 uint32 num_members
, *group_rids
;
2446 struct samr_RidTypeArray
*rids
= NULL
;
2447 struct lsa_Strings names
;
2448 struct samr_Ids types
;
2451 sid_to_fstring(sid_str
, domain_sid
);
2453 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2455 MAXIMUM_ALLOWED_ACCESS
,
2459 if (!NT_STATUS_IS_OK(result
))
2462 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2466 if (!NT_STATUS_IS_OK(result
))
2469 num_members
= rids
->count
;
2470 group_rids
= rids
->rids
;
2472 while (num_members
> 0) {
2473 int this_time
= 512;
2475 if (num_members
< this_time
)
2476 this_time
= num_members
;
2478 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2485 if (!NT_STATUS_IS_OK(result
))
2488 /* We only have users as members, but make the output
2489 the same as the output of alias members */
2491 for (i
= 0; i
< this_time
; i
++) {
2493 if (c
->opt_long_list_entries
) {
2494 printf("%s-%d %s\\%s %d\n", sid_str
,
2495 group_rids
[i
], domain_name
,
2496 names
.names
[i
].string
,
2499 printf("%s\\%s\n", domain_name
,
2500 names
.names
[i
].string
);
2504 num_members
-= this_time
;
2508 return NT_STATUS_OK
;
2511 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2512 struct rpc_pipe_client
*pipe_hnd
,
2513 TALLOC_CTX
*mem_ctx
,
2514 struct policy_handle
*domain_pol
,
2518 struct rpc_pipe_client
*lsa_pipe
;
2519 struct policy_handle alias_pol
, lsa_pol
;
2521 DOM_SID
*alias_sids
;
2524 enum lsa_SidType
*types
;
2526 struct lsa_SidArray sid_array
;
2528 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2530 MAXIMUM_ALLOWED_ACCESS
,
2534 if (!NT_STATUS_IS_OK(result
))
2537 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2541 if (!NT_STATUS_IS_OK(result
)) {
2542 d_fprintf(stderr
, _("Couldn't list alias members\n"));
2546 num_members
= sid_array
.num_sids
;
2548 if (num_members
== 0) {
2549 return NT_STATUS_OK
;
2552 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2553 &ndr_table_lsarpc
.syntax_id
,
2555 if (!NT_STATUS_IS_OK(result
)) {
2556 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
2557 nt_errstr(result
) );
2561 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2562 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2564 if (!NT_STATUS_IS_OK(result
)) {
2565 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
2566 TALLOC_FREE(lsa_pipe
);
2570 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2572 d_fprintf(stderr
, _("Out of memory\n"));
2573 TALLOC_FREE(lsa_pipe
);
2574 return NT_STATUS_NO_MEMORY
;
2577 for (i
=0; i
<num_members
; i
++) {
2578 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2581 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2582 num_members
, alias_sids
,
2583 &domains
, &names
, &types
);
2585 if (!NT_STATUS_IS_OK(result
) &&
2586 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2587 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
2588 TALLOC_FREE(lsa_pipe
);
2592 for (i
= 0; i
< num_members
; i
++) {
2594 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2596 if (c
->opt_long_list_entries
) {
2597 printf("%s %s\\%s %d\n", sid_str
,
2598 domains
[i
] ? domains
[i
] : _("*unknown*"),
2599 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
2602 printf("%s\\%s\n", domains
[i
], names
[i
]);
2604 printf("%s\n", sid_str
);
2608 TALLOC_FREE(lsa_pipe
);
2609 return NT_STATUS_OK
;
2612 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2613 const DOM_SID
*domain_sid
,
2614 const char *domain_name
,
2615 struct cli_state
*cli
,
2616 struct rpc_pipe_client
*pipe_hnd
,
2617 TALLOC_CTX
*mem_ctx
,
2622 struct policy_handle connect_pol
, domain_pol
;
2623 struct samr_Ids rids
, rid_types
;
2624 struct lsa_String lsa_acct_name
;
2626 /* Get sam policy handle */
2628 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2630 MAXIMUM_ALLOWED_ACCESS
,
2633 if (!NT_STATUS_IS_OK(result
))
2636 /* Get domain policy handle */
2638 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2640 MAXIMUM_ALLOWED_ACCESS
,
2641 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2644 if (!NT_STATUS_IS_OK(result
))
2647 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2649 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2656 if (!NT_STATUS_IS_OK(result
)) {
2658 /* Ok, did not find it in the global sam, try with builtin */
2660 DOM_SID sid_Builtin
;
2662 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2664 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2666 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2668 MAXIMUM_ALLOWED_ACCESS
,
2672 if (!NT_STATUS_IS_OK(result
)) {
2673 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2678 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2685 if (!NT_STATUS_IS_OK(result
)) {
2686 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2692 if (rids
.count
!= 1) {
2693 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2698 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2699 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2700 domain_sid
, &domain_pol
,
2704 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2705 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2709 return NT_STATUS_NO_SUCH_GROUP
;
2712 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2714 if (argc
!= 1 || c
->display_usage
) {
2715 return rpc_group_usage(c
, argc
, argv
);
2718 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2719 rpc_group_members_internals
,
2723 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2725 NET_API_STATUS status
;
2726 struct GROUP_INFO_0 g0
;
2730 d_printf(_("Usage:\n"));
2731 d_printf("net rpc group rename group newname\n");
2735 g0
.grpi0_name
= argv
[1];
2737 status
= NetGroupSetInfo(c
->opt_host
,
2744 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
2745 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2753 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2755 if (argc
!= 2 || c
->display_usage
) {
2756 return rpc_group_usage(c
, argc
, argv
);
2759 return rpc_group_rename_internals(c
, argc
, argv
);
2763 * 'net rpc group' entrypoint.
2764 * @param argc Standard main() style argc.
2765 * @param argv Standard main() style argv. Initial components are already
2769 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2771 NET_API_STATUS status
;
2773 struct functable func
[] = {
2778 N_("Create specified group"),
2779 N_("net rpc group add\n"
2780 " Create specified group")
2786 N_("Delete specified group"),
2787 N_("net rpc group delete\n"
2788 " Delete specified group")
2794 N_("Add member to group"),
2795 N_("net rpc group addmem\n"
2796 " Add member to group")
2802 N_("Remove member from group"),
2803 N_("net rpc group delmem\n"
2804 " Remove member from group")
2811 N_("net rpc group list\n"
2818 N_("List group members"),
2819 N_("net rpc group members\n"
2820 " List group members")
2827 N_("net rpc group rename\n"
2830 {NULL
, NULL
, 0, NULL
, NULL
}
2833 status
= libnetapi_init(&c
->netapi_ctx
);
2837 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2838 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2839 if (c
->opt_kerberos
) {
2840 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2844 if (c
->display_usage
) {
2845 d_printf(_("Usage:\n"));
2846 d_printf(_("net rpc group\n"
2847 " Alias for net rpc group list global "
2848 "local builtin\n"));
2849 net_display_usage_from_functable(func
);
2853 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2854 rpc_group_list_internals
,
2858 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2861 /****************************************************************************/
2863 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2865 return net_share_usage(c
, argc
, argv
);
2869 * Add a share on a remote RPC server.
2871 * @param argc Standard main() style argc.
2872 * @param argv Standard main() style argv. Initial components are already
2875 * @return A shell status integer (0 for success).
2878 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2880 NET_API_STATUS status
;
2883 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2884 uint32 num_users
=0, perms
=0;
2885 char *password
=NULL
; /* don't allow a share password */
2886 struct SHARE_INFO_2 i2
;
2887 uint32_t parm_error
= 0;
2889 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2890 return rpc_share_usage(c
, argc
, argv
);
2893 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2897 path
= strchr(sharename
, '=');
2904 i2
.shi2_netname
= sharename
;
2905 i2
.shi2_type
= type
;
2906 i2
.shi2_remark
= c
->opt_comment
;
2907 i2
.shi2_permissions
= perms
;
2908 i2
.shi2_max_uses
= c
->opt_maxusers
;
2909 i2
.shi2_current_uses
= num_users
;
2910 i2
.shi2_path
= path
;
2911 i2
.shi2_passwd
= password
;
2913 status
= NetShareAdd(c
->opt_host
,
2918 printf(_("NetShareAdd failed with: %s\n"),
2919 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2926 * Delete a share on a remote RPC server.
2928 * @param domain_sid The domain sid acquired from the remote server.
2929 * @param argc Standard main() style argc.
2930 * @param argv Standard main() style argv. Initial components are already
2933 * @return A shell status integer (0 for success).
2935 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2937 if (argc
< 1 || c
->display_usage
) {
2938 return rpc_share_usage(c
, argc
, argv
);
2941 return NetShareDel(c
->opt_host
, argv
[0], 0);
2945 * Formatted print of share info
2947 * @param r pointer to SHARE_INFO_1 to format
2950 static void display_share_info_1(struct net_context
*c
,
2951 struct SHARE_INFO_1
*r
)
2953 if (c
->opt_long_list_entries
) {
2954 d_printf("%-12s %-8.8s %-50s\n",
2956 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2959 d_printf("%s\n", r
->shi1_netname
);
2963 static WERROR
get_share_info(struct net_context
*c
,
2964 struct rpc_pipe_client
*pipe_hnd
,
2965 TALLOC_CTX
*mem_ctx
,
2969 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2973 union srvsvc_NetShareInfo info
;
2975 /* no specific share requested, enumerate all */
2978 uint32_t preferred_len
= 0xffffffff;
2979 uint32_t total_entries
= 0;
2980 uint32_t resume_handle
= 0;
2982 info_ctr
->level
= level
;
2984 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2994 /* request just one share */
2995 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
3002 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
3007 ZERO_STRUCTP(info_ctr
);
3009 info_ctr
->level
= level
;
3014 struct srvsvc_NetShareCtr1
*ctr1
;
3016 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
3017 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3020 ctr1
->array
= info
.info1
;
3022 info_ctr
->ctr
.ctr1
= ctr1
;
3026 struct srvsvc_NetShareCtr2
*ctr2
;
3028 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
3029 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3032 ctr2
->array
= info
.info2
;
3034 info_ctr
->ctr
.ctr2
= ctr2
;
3038 struct srvsvc_NetShareCtr502
*ctr502
;
3040 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3041 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3044 ctr502
->array
= info
.info502
;
3046 info_ctr
->ctr
.ctr502
= ctr502
;
3054 * 'net rpc share list' entrypoint.
3055 * @param argc Standard main() style argc.
3056 * @param argv Standard main() style argv. Initial components are already
3059 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3061 NET_API_STATUS status
;
3062 struct SHARE_INFO_1
*i1
= NULL
;
3063 uint32_t entries_read
= 0;
3064 uint32_t total_entries
= 0;
3065 uint32_t resume_handle
= 0;
3066 uint32_t i
, level
= 1;
3068 if (c
->display_usage
) {
3070 "net rpc share list\n"
3073 _("List shares on remote server"));
3077 status
= NetShareEnum(c
->opt_host
,
3079 (uint8_t **)(void *)&i1
,
3088 /* Display results */
3090 if (c
->opt_long_list_entries
) {
3092 "\nEnumerating shared resources (exports) on remote server:\n\n"
3093 "\nShare name Type Description\n"
3094 "---------- ---- -----------\n"));
3096 for (i
= 0; i
< entries_read
; i
++)
3097 display_share_info_1(c
, &i1
[i
]);
3102 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3104 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3105 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3115 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3116 const char *netname
, uint32 type
)
3118 /* only support disk shares */
3119 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3120 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3125 /* skip builtin shares */
3126 /* FIXME: should print$ be added too ? */
3127 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3128 strequal(netname
,"global"))
3131 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3132 printf(_("excluding [%s]\n"), netname
);
3136 return check_share_availability(cli
, netname
);
3140 * Migrate shares from a remote RPC server to the local RPC server.
3142 * All parameters are provided by the run_rpc_command function, except for
3143 * argc, argv which are passed through.
3145 * @param domain_sid The domain sid acquired from the remote server.
3146 * @param cli A cli_state connected to the server.
3147 * @param mem_ctx Talloc context, destroyed on completion of the function.
3148 * @param argc Standard main() style argc.
3149 * @param argv Standard main() style argv. Initial components are already
3152 * @return Normal NTSTATUS return.
3155 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3156 const DOM_SID
*domain_sid
,
3157 const char *domain_name
,
3158 struct cli_state
*cli
,
3159 struct rpc_pipe_client
*pipe_hnd
,
3160 TALLOC_CTX
*mem_ctx
,
3165 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3166 struct srvsvc_NetShareInfoCtr ctr_src
;
3168 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3169 struct cli_state
*cli_dst
= NULL
;
3170 uint32 level
= 502; /* includes secdesc */
3171 uint32_t parm_error
= 0;
3173 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3175 if (!W_ERROR_IS_OK(result
))
3178 /* connect destination PI_SRVSVC */
3179 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3180 &ndr_table_srvsvc
.syntax_id
);
3181 if (!NT_STATUS_IS_OK(nt_status
))
3185 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3187 union srvsvc_NetShareInfo info
;
3188 struct srvsvc_NetShareInfo502 info502
=
3189 ctr_src
.ctr
.ctr502
->array
[i
];
3191 /* reset error-code */
3192 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3194 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3197 /* finally add the share on the dst server */
3199 printf(_("migrating: [%s], path: %s, comment: %s, without "
3201 info502
.name
, info502
.path
, info502
.comment
);
3203 info
.info502
= &info502
;
3205 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3206 srvsvc_pipe
->desthost
,
3212 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3213 printf(_(" [%s] does already exist\n"),
3218 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3219 printf(_("cannot add share: %s\n"), win_errstr(result
));
3225 nt_status
= NT_STATUS_OK
;
3229 cli_shutdown(cli_dst
);
3237 * Migrate shares from a RPC server to another.
3239 * @param argc Standard main() style argc.
3240 * @param argv Standard main() style argv. Initial components are already
3243 * @return A shell status integer (0 for success).
3245 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3248 if (c
->display_usage
) {
3250 "net rpc share migrate shares\n"
3253 _("Migrate shares to local server"));
3258 printf(_("no server to migrate\n"));
3262 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3263 rpc_share_migrate_shares_internals
,
3270 * @param f file_info
3271 * @param mask current search mask
3272 * @param state arg-pointer
3275 static void copy_fn(const char *mnt
, file_info
*f
,
3276 const char *mask
, void *state
)
3278 static NTSTATUS nt_status
;
3279 static struct copy_clistate
*local_state
;
3280 static fstring filename
, new_mask
;
3283 struct net_context
*c
;
3285 local_state
= (struct copy_clistate
*)state
;
3286 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3290 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3293 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3296 if (f
->mode
& aDIR
) {
3298 DEBUG(3,("got dir: %s\n", f
->name
));
3300 fstrcpy(dir
, local_state
->cwd
);
3302 fstrcat(dir
, f
->name
);
3304 switch (net_mode_share
)
3306 case NET_MODE_SHARE_MIGRATE
:
3307 /* create that directory */
3308 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3309 local_state
->cli_share_src
,
3310 local_state
->cli_share_dst
,
3312 c
->opt_acls
? true : false,
3313 c
->opt_attrs
? true : false,
3314 c
->opt_timestamps
? true:false,
3318 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3322 if (!NT_STATUS_IS_OK(nt_status
))
3323 printf(_("could not handle dir %s: %s\n"),
3324 dir
, nt_errstr(nt_status
));
3326 /* search below that directory */
3327 fstrcpy(new_mask
, dir
);
3328 fstrcat(new_mask
, "\\*");
3330 old_dir
= local_state
->cwd
;
3331 local_state
->cwd
= dir
;
3332 if (!sync_files(local_state
, new_mask
))
3333 printf(_("could not handle files\n"));
3334 local_state
->cwd
= old_dir
;
3341 fstrcpy(filename
, local_state
->cwd
);
3342 fstrcat(filename
, "\\");
3343 fstrcat(filename
, f
->name
);
3345 DEBUG(3,("got file: %s\n", filename
));
3347 switch (net_mode_share
)
3349 case NET_MODE_SHARE_MIGRATE
:
3350 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3351 local_state
->cli_share_src
,
3352 local_state
->cli_share_dst
,
3354 c
->opt_acls
? true : false,
3355 c
->opt_attrs
? true : false,
3356 c
->opt_timestamps
? true: false,
3360 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
3365 if (!NT_STATUS_IS_OK(nt_status
))
3366 printf(_("could not handle file %s: %s\n"),
3367 filename
, nt_errstr(nt_status
));
3372 * sync files, can be called recursivly to list files
3373 * and then call copy_fn for each file
3375 * @param cp_clistate pointer to the copy_clistate we work with
3376 * @param mask the current search mask
3378 * @return Boolean result
3380 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3382 struct cli_state
*targetcli
;
3383 char *targetpath
= NULL
;
3385 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3387 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3388 mask
, &targetcli
, &targetpath
) ) {
3389 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
3391 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3395 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3396 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
3397 mask
, cli_errstr(targetcli
));
3406 * Set the top level directory permissions before we do any further copies.
3407 * Should set up ACL inheritance.
3410 bool copy_top_level_perms(struct net_context
*c
,
3411 struct copy_clistate
*cp_clistate
,
3412 const char *sharename
)
3414 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3416 switch (net_mode_share
) {
3417 case NET_MODE_SHARE_MIGRATE
:
3418 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3419 nt_status
= net_copy_fileattr(c
,
3420 cp_clistate
->mem_ctx
,
3421 cp_clistate
->cli_share_src
,
3422 cp_clistate
->cli_share_dst
,
3424 c
->opt_acls
? true : false,
3425 c
->opt_attrs
? true : false,
3426 c
->opt_timestamps
? true: false,
3430 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3434 if (!NT_STATUS_IS_OK(nt_status
)) {
3435 printf(_("Could handle directory attributes for top level "
3436 "directory of share %s. Error %s\n"),
3437 sharename
, nt_errstr(nt_status
));
3445 * Sync all files inside a remote share to another share (over smb).
3447 * All parameters are provided by the run_rpc_command function, except for
3448 * argc, argv which are passed through.
3450 * @param domain_sid The domain sid acquired from the remote server.
3451 * @param cli A cli_state connected to the server.
3452 * @param mem_ctx Talloc context, destroyed on completion of the function.
3453 * @param argc Standard main() style argc.
3454 * @param argv Standard main() style argv. Initial components are already
3457 * @return Normal NTSTATUS return.
3460 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3461 const DOM_SID
*domain_sid
,
3462 const char *domain_name
,
3463 struct cli_state
*cli
,
3464 struct rpc_pipe_client
*pipe_hnd
,
3465 TALLOC_CTX
*mem_ctx
,
3470 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3471 struct srvsvc_NetShareInfoCtr ctr_src
;
3474 struct copy_clistate cp_clistate
;
3475 bool got_src_share
= false;
3476 bool got_dst_share
= false;
3477 const char *mask
= "\\*";
3480 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3482 nt_status
= NT_STATUS_NO_MEMORY
;
3486 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3489 if (!W_ERROR_IS_OK(result
))
3492 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3494 struct srvsvc_NetShareInfo502 info502
=
3495 ctr_src
.ctr
.ctr502
->array
[i
];
3497 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3500 /* one might not want to mirror whole discs :) */
3501 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3502 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3507 switch (net_mode_share
)
3509 case NET_MODE_SHARE_MIGRATE
:
3513 d_fprintf(stderr
, _("Unsupported mode %d\n"),
3517 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3520 c
->opt_acls
? _("including") : _("without"),
3521 c
->opt_attrs
? _("including") : _("without"),
3522 c
->opt_timestamps
? _("(preserving timestamps)") : "");
3524 cp_clistate
.mem_ctx
= mem_ctx
;
3525 cp_clistate
.cli_share_src
= NULL
;
3526 cp_clistate
.cli_share_dst
= NULL
;
3527 cp_clistate
.cwd
= NULL
;
3528 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3531 /* open share source */
3532 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3533 &cli
->dest_ss
, cli
->desthost
,
3534 info502
.name
, "A:");
3535 if (!NT_STATUS_IS_OK(nt_status
))
3538 got_src_share
= true;
3540 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3541 /* open share destination */
3542 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3543 NULL
, dst
, info502
.name
, "A:");
3544 if (!NT_STATUS_IS_OK(nt_status
))
3547 got_dst_share
= true;
3550 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3551 d_fprintf(stderr
, _("Could not handle the top level "
3552 "directory permissions for the "
3553 "share: %s\n"), info502
.name
);
3554 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3558 if (!sync_files(&cp_clistate
, mask
)) {
3559 d_fprintf(stderr
, _("could not handle files for share: "
3560 "%s\n"), info502
.name
);
3561 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3566 nt_status
= NT_STATUS_OK
;
3571 cli_shutdown(cp_clistate
.cli_share_src
);
3574 cli_shutdown(cp_clistate
.cli_share_dst
);
3581 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3583 if (c
->display_usage
) {
3585 "net share migrate files\n"
3588 _("Migrate files to local server"));
3593 d_printf(_("no server to migrate\n"));
3597 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3598 rpc_share_migrate_files_internals
,
3603 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3605 * All parameters are provided by the run_rpc_command function, except for
3606 * argc, argv which are passed through.
3608 * @param domain_sid The domain sid acquired from the remote server.
3609 * @param cli A cli_state connected to the server.
3610 * @param mem_ctx Talloc context, destroyed on completion of the function.
3611 * @param argc Standard main() style argc.
3612 * @param argv Standard main() style argv. Initial components are already
3615 * @return Normal NTSTATUS return.
3618 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3619 const DOM_SID
*domain_sid
,
3620 const char *domain_name
,
3621 struct cli_state
*cli
,
3622 struct rpc_pipe_client
*pipe_hnd
,
3623 TALLOC_CTX
*mem_ctx
,
3628 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3629 struct srvsvc_NetShareInfoCtr ctr_src
;
3630 union srvsvc_NetShareInfo info
;
3632 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3633 struct cli_state
*cli_dst
= NULL
;
3634 uint32 level
= 502; /* includes secdesc */
3635 uint32_t parm_error
= 0;
3637 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3640 if (!W_ERROR_IS_OK(result
))
3643 /* connect destination PI_SRVSVC */
3644 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3645 &ndr_table_srvsvc
.syntax_id
);
3646 if (!NT_STATUS_IS_OK(nt_status
))
3650 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3652 struct srvsvc_NetShareInfo502 info502
=
3653 ctr_src
.ctr
.ctr502
->array
[i
];
3655 /* reset error-code */
3656 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3658 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3661 printf(_("migrating: [%s], path: %s, comment: %s, including "
3663 info502
.name
, info502
.path
, info502
.comment
);
3666 display_sec_desc(info502
.sd_buf
.sd
);
3668 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3669 info
.info502
= &info502
;
3671 /* finally modify the share on the dst server */
3672 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3673 srvsvc_pipe
->desthost
,
3679 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3680 printf(_("cannot set share-acl: %s\n"),
3681 win_errstr(result
));
3687 nt_status
= NT_STATUS_OK
;
3691 cli_shutdown(cli_dst
);
3699 * Migrate share-acls from a RPC server to another.
3701 * @param argc Standard main() style argc.
3702 * @param argv Standard main() style argv. Initial components are already
3705 * @return A shell status integer (0 for success).
3707 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3710 if (c
->display_usage
) {
3712 "net rpc share migrate security\n"
3715 _("Migrate share-acls to local server"));
3720 d_printf(_("no server to migrate\n"));
3724 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3725 rpc_share_migrate_security_internals
,
3730 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3731 * from one server to another.
3733 * @param argc Standard main() style argc.
3734 * @param argv Standard main() style argv. Initial components are already
3737 * @return A shell status integer (0 for success).
3740 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3745 if (c
->display_usage
) {
3747 "net rpc share migrate all\n"
3750 _("Migrates shares including all share settings"));
3755 d_printf(_("no server to migrate\n"));
3759 /* order is important. we don't want to be locked out by the share-acl
3760 * before copying files - gd */
3762 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3763 rpc_share_migrate_shares_internals
, argc
, argv
);
3767 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3768 rpc_share_migrate_files_internals
, argc
, argv
);
3772 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3773 rpc_share_migrate_security_internals
, argc
,
3779 * 'net rpc share migrate' entrypoint.
3780 * @param argc Standard main() style argc.
3781 * @param argv Standard main() style argv. Initial components are already
3784 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3787 struct functable func
[] = {
3790 rpc_share_migrate_all
,
3792 N_("Migrate shares from remote to local server"),
3793 N_("net rpc share migrate all\n"
3794 " Migrate shares from remote to local server")
3798 rpc_share_migrate_files
,
3800 N_("Migrate files from remote to local server"),
3801 N_("net rpc share migrate files\n"
3802 " Migrate files from remote to local server")
3806 rpc_share_migrate_security
,
3808 N_("Migrate share-ACLs from remote to local server"),
3809 N_("net rpc share migrate security\n"
3810 " Migrate share-ACLs from remote to local server")
3814 rpc_share_migrate_shares
,
3816 N_("Migrate shares from remote to local server"),
3817 N_("net rpc share migrate shares\n"
3818 " Migrate shares from remote to local server")
3820 {NULL
, NULL
, 0, NULL
, NULL
}
3823 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3825 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3834 static int num_server_aliases
;
3835 static struct full_alias
*server_aliases
;
3838 * Add an alias to the static list.
3840 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3842 if (server_aliases
== NULL
)
3843 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3845 server_aliases
[num_server_aliases
] = *alias
;
3846 num_server_aliases
+= 1;
3850 * For a specific domain on the server, fetch all the aliases
3851 * and their members. Add all of them to the server_aliases.
3854 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3855 TALLOC_CTX
*mem_ctx
,
3856 struct policy_handle
*connect_pol
,
3857 const DOM_SID
*domain_sid
)
3859 uint32 start_idx
, max_entries
, num_entries
, i
;
3860 struct samr_SamArray
*groups
= NULL
;
3862 struct policy_handle domain_pol
;
3864 /* Get domain policy handle */
3866 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3868 MAXIMUM_ALLOWED_ACCESS
,
3869 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3871 if (!NT_STATUS_IS_OK(result
))
3878 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3884 for (i
= 0; i
< num_entries
; i
++) {
3886 struct policy_handle alias_pol
;
3887 struct full_alias alias
;
3888 struct lsa_SidArray sid_array
;
3891 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3893 MAXIMUM_ALLOWED_ACCESS
,
3894 groups
->entries
[i
].idx
,
3896 if (!NT_STATUS_IS_OK(result
))
3899 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3902 if (!NT_STATUS_IS_OK(result
))
3905 alias
.num_members
= sid_array
.num_sids
;
3907 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3908 if (!NT_STATUS_IS_OK(result
))
3911 alias
.members
= NULL
;
3913 if (alias
.num_members
> 0) {
3914 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3916 for (j
= 0; j
< alias
.num_members
; j
++)
3917 sid_copy(&alias
.members
[j
],
3918 sid_array
.sids
[j
].sid
);
3921 sid_copy(&alias
.sid
, domain_sid
);
3922 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3924 push_alias(mem_ctx
, &alias
);
3926 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3928 result
= NT_STATUS_OK
;
3931 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3937 * Dump server_aliases as names for debugging purposes.
3940 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3941 const DOM_SID
*domain_sid
,
3942 const char *domain_name
,
3943 struct cli_state
*cli
,
3944 struct rpc_pipe_client
*pipe_hnd
,
3945 TALLOC_CTX
*mem_ctx
,
3951 struct policy_handle lsa_pol
;
3953 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3954 SEC_FLAG_MAXIMUM_ALLOWED
,
3956 if (!NT_STATUS_IS_OK(result
))
3959 for (i
=0; i
<num_server_aliases
; i
++) {
3962 enum lsa_SidType
*types
;
3965 struct full_alias
*alias
= &server_aliases
[i
];
3967 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3969 &domains
, &names
, &types
);
3970 if (!NT_STATUS_IS_OK(result
))
3973 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3975 if (alias
->num_members
== 0) {
3980 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3983 &domains
, &names
, &types
);
3985 if (!NT_STATUS_IS_OK(result
) &&
3986 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3989 for (j
=0; j
<alias
->num_members
; j
++)
3990 DEBUG(1, ("%s\\%s (%d); ",
3991 domains
[j
] ? domains
[j
] : "*unknown*",
3992 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3996 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3998 return NT_STATUS_OK
;
4002 * Fetch a list of all server aliases and their members into
4006 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4007 const DOM_SID
*domain_sid
,
4008 const char *domain_name
,
4009 struct cli_state
*cli
,
4010 struct rpc_pipe_client
*pipe_hnd
,
4011 TALLOC_CTX
*mem_ctx
,
4016 struct policy_handle connect_pol
;
4018 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4020 MAXIMUM_ALLOWED_ACCESS
,
4023 if (!NT_STATUS_IS_OK(result
))
4026 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4027 &global_sid_Builtin
);
4029 if (!NT_STATUS_IS_OK(result
))
4032 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4035 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4040 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4042 token
->num_sids
= 4;
4044 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4045 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4046 token
->num_sids
= 0;
4050 token
->user_sids
[0] = *user_sid
;
4051 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4052 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4053 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4056 static void free_user_token(NT_USER_TOKEN
*token
)
4058 SAFE_FREE(token
->user_sids
);
4061 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4063 if (is_sid_in_token(token
, sid
))
4066 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4067 if (!token
->user_sids
) {
4071 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4073 token
->num_sids
+= 1;
4078 NT_USER_TOKEN token
;
4081 static void dump_user_token(struct user_token
*token
)
4085 d_printf("%s\n", token
->name
);
4087 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4088 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4092 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4096 for (i
=0; i
<alias
->num_members
; i
++) {
4097 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4104 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4108 for (i
=0; i
<num_server_aliases
; i
++) {
4109 if (is_alias_member(&sid
, &server_aliases
[i
]))
4110 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4115 * We got a user token with all the SIDs we can know about without asking the
4116 * server directly. These are the user and domain group sids. All of these can
4117 * be members of aliases. So scan the list of aliases for each of the SIDs and
4118 * add them to the token.
4121 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4123 int num_global_sids
= token
->num_sids
;
4126 for (i
=0; i
<num_global_sids
; i
++) {
4127 collect_sid_memberships(token
, token
->user_sids
[i
]);
4131 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4133 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4134 enum wbcSidType type
;
4136 struct wbcDomainSid wsid
;
4137 char *sid_str
= NULL
;
4139 uint32_t num_groups
;
4140 gid_t
*groups
= NULL
;
4143 fstr_sprintf(full_name
, "%s%c%s",
4144 domain
, *lp_winbind_separator(), user
);
4146 /* First let's find out the user sid */
4148 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4150 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4151 DEBUG(1, ("winbind could not find %s: %s\n",
4152 full_name
, wbcErrorString(wbc_status
)));
4156 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4157 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4161 if (type
!= SID_NAME_USER
) {
4162 wbcFreeMemory(sid_str
);
4163 DEBUG(1, ("%s is not a user\n", full_name
));
4167 if (!string_to_sid(&user_sid
, sid_str
)) {
4168 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4172 wbcFreeMemory(sid_str
);
4175 init_user_token(token
, &user_sid
);
4177 /* And now the groups winbind knows about */
4179 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4180 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4181 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4182 full_name
, wbcErrorString(wbc_status
)));
4186 for (i
= 0; i
< num_groups
; i
++) {
4187 gid_t gid
= groups
[i
];
4190 wbc_status
= wbcGidToSid(gid
, &wsid
);
4191 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4192 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4193 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4194 wbcFreeMemory(groups
);
4198 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4199 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4200 wbcFreeMemory(groups
);
4204 DEBUG(3, (" %s\n", sid_str
));
4206 string_to_sid(&sid
, sid_str
);
4207 wbcFreeMemory(sid_str
);
4210 add_sid_to_token(token
, &sid
);
4212 wbcFreeMemory(groups
);
4218 * Get a list of all user tokens we want to look at
4221 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4222 struct user_token
**user_tokens
)
4224 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4225 uint32_t i
, num_users
;
4227 struct user_token
*result
;
4228 TALLOC_CTX
*frame
= NULL
;
4230 if (lp_winbind_use_default_domain() &&
4231 (c
->opt_target_workgroup
== NULL
)) {
4232 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4233 "please specify a workgroup\n"));
4237 /* Send request to winbind daemon */
4239 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4240 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4241 DEBUG(1, (_("winbind could not list users: %s\n"),
4242 wbcErrorString(wbc_status
)));
4246 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4248 if (result
== NULL
) {
4249 DEBUG(1, ("Could not malloc sid array\n"));
4250 wbcFreeMemory(users
);
4254 frame
= talloc_stackframe();
4255 for (i
=0; i
< num_users
; i
++) {
4256 fstring domain
, user
;
4259 fstrcpy(result
[i
].name
, users
[i
]);
4261 p
= strchr(users
[i
], *lp_winbind_separator());
4263 DEBUG(3, ("%s\n", users
[i
]));
4266 fstrcpy(domain
, c
->opt_target_workgroup
);
4267 fstrcpy(user
, users
[i
]);
4270 fstrcpy(domain
, users
[i
]);
4275 get_user_sids(domain
, user
, &(result
[i
].token
));
4279 wbcFreeMemory(users
);
4281 *num_tokens
= num_users
;
4282 *user_tokens
= result
;
4287 static bool get_user_tokens_from_file(FILE *f
,
4289 struct user_token
**tokens
)
4291 struct user_token
*token
= NULL
;
4296 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4300 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
4301 line
[strlen(line
)-1] = '\0';
4304 if (line
[0] == ' ') {
4308 if(!string_to_sid(&sid
, &line
[1])) {
4309 DEBUG(1,("get_user_tokens_from_file: Could "
4310 "not convert sid %s \n",&line
[1]));
4314 if (token
== NULL
) {
4315 DEBUG(0, ("File does not begin with username"));
4319 add_sid_to_token(&token
->token
, &sid
);
4323 /* And a new user... */
4326 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4327 if (*tokens
== NULL
) {
4328 DEBUG(0, ("Could not realloc tokens\n"));
4332 token
= &((*tokens
)[*num_tokens
-1]);
4334 fstrcpy(token
->name
, line
);
4335 token
->token
.num_sids
= 0;
4336 token
->token
.user_sids
= NULL
;
4345 * Show the list of all users that have access to a share
4348 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4349 TALLOC_CTX
*mem_ctx
,
4350 const char *netname
,
4352 struct user_token
*tokens
)
4355 SEC_DESC
*share_sd
= NULL
;
4356 SEC_DESC
*root_sd
= NULL
;
4357 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4359 union srvsvc_NetShareInfo info
;
4364 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4371 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4372 DEBUG(1, ("Coult not query secdesc for share %s\n",
4377 share_sd
= info
.info502
->sd_buf
.sd
;
4378 if (share_sd
== NULL
) {
4379 DEBUG(1, ("Got no secdesc for share %s\n",
4385 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4389 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
4390 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
4391 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4394 for (i
=0; i
<num_tokens
; i
++) {
4397 if (share_sd
!= NULL
) {
4398 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4401 if (!NT_STATUS_IS_OK(status
)) {
4402 DEBUG(1, ("Could not check share_sd for "
4409 if (root_sd
== NULL
) {
4410 d_printf(" %s\n", tokens
[i
].name
);
4414 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4416 if (!NT_STATUS_IS_OK(status
)) {
4417 DEBUG(1, ("Could not check root_sd for user %s\n",
4421 d_printf(" %s\n", tokens
[i
].name
);
4424 if (fnum
!= (uint16_t)-1)
4425 cli_close(cli
, fnum
);
4437 static void collect_share(const char *name
, uint32 m
,
4438 const char *comment
, void *state
)
4440 struct share_list
*share_list
= (struct share_list
*)state
;
4442 if (m
!= STYPE_DISKTREE
)
4445 share_list
->num_shares
+= 1;
4446 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4447 if (!share_list
->shares
) {
4448 share_list
->num_shares
= 0;
4451 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4455 * List shares on a remote RPC server, including the security descriptors.
4457 * All parameters are provided by the run_rpc_command function, except for
4458 * argc, argv which are passed through.
4460 * @param domain_sid The domain sid acquired from the remote server.
4461 * @param cli A cli_state connected to the server.
4462 * @param mem_ctx Talloc context, destroyed on completion of the function.
4463 * @param argc Standard main() style argc.
4464 * @param argv Standard main() style argv. Initial components are already
4467 * @return Normal NTSTATUS return.
4470 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4471 const DOM_SID
*domain_sid
,
4472 const char *domain_name
,
4473 struct cli_state
*cli
,
4474 struct rpc_pipe_client
*pipe_hnd
,
4475 TALLOC_CTX
*mem_ctx
,
4484 struct user_token
*tokens
= NULL
;
4487 struct share_list share_list
;
4492 f
= fopen(argv
[0], "r");
4496 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4497 return NT_STATUS_UNSUCCESSFUL
;
4500 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4506 DEBUG(0, ("Could not read users from file\n"));
4507 return NT_STATUS_UNSUCCESSFUL
;
4510 for (i
=0; i
<num_tokens
; i
++)
4511 collect_alias_memberships(&tokens
[i
].token
);
4513 share_list
.num_shares
= 0;
4514 share_list
.shares
= NULL
;
4516 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4519 DEBUG(0, ("Error returning browse list: %s\n",
4524 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4525 char *netname
= share_list
.shares
[i
];
4527 if (netname
[strlen(netname
)-1] == '$')
4530 d_printf("%s\n", netname
);
4532 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4533 num_tokens
, tokens
);
4536 for (i
=0; i
<num_tokens
; i
++) {
4537 free_user_token(&tokens
[i
].token
);
4540 SAFE_FREE(share_list
.shares
);
4542 return NT_STATUS_OK
;
4545 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4550 if (c
->display_usage
) {
4552 "net rpc share allowedusers\n"
4555 _("List allowed users"));
4559 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4560 rpc_aliaslist_internals
,
4565 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4571 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4572 rpc_share_allowedusers_internals
,
4576 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4579 struct user_token
*tokens
= NULL
;
4583 net_usersidlist_usage(c
, argc
, argv
);
4587 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4588 DEBUG(0, ("Could not get the user/sid list\n"));
4592 for (i
=0; i
<num_tokens
; i
++) {
4593 dump_user_token(&tokens
[i
]);
4594 free_user_token(&tokens
[i
].token
);
4601 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4603 d_printf(_("net usersidlist\n"
4604 "\tprints out a list of all users the running winbind knows\n"
4605 "\tabout, together with all their SIDs. This is used as\n"
4606 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
4608 net_common_flags_usage(c
, argc
, argv
);
4613 * 'net rpc share' entrypoint.
4614 * @param argc Standard main() style argc.
4615 * @param argv Standard main() style argv. Initial components are already
4619 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4621 NET_API_STATUS status
;
4623 struct functable func
[] = {
4629 N_("net rpc share add\n"
4637 N_("net rpc share delete\n"
4642 rpc_share_allowedusers
,
4644 N_("Modify allowed users"),
4645 N_("net rpc share allowedusers\n"
4646 " Modify allowed users")
4652 N_("Migrate share to local server"),
4653 N_("net rpc share migrate\n"
4654 " Migrate share to local server")
4661 N_("net rpc share list\n"
4664 {NULL
, NULL
, 0, NULL
, NULL
}
4667 status
= libnetapi_init(&c
->netapi_ctx
);
4671 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4672 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4673 if (c
->opt_kerberos
) {
4674 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4678 if (c
->display_usage
) {
4683 " Alias for net rpc share list\n"));
4684 net_display_usage_from_functable(func
);
4688 return rpc_share_list(c
, argc
, argv
);
4691 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4694 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4695 TALLOC_CTX
*mem_ctx
,
4696 struct rpc_sh_ctx
*ctx
,
4697 struct rpc_pipe_client
*pipe_hnd
,
4698 int argc
, const char **argv
)
4701 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4704 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4705 TALLOC_CTX
*mem_ctx
,
4706 struct rpc_sh_ctx
*ctx
,
4707 struct rpc_pipe_client
*pipe_hnd
,
4708 int argc
, const char **argv
)
4710 NET_API_STATUS status
;
4711 uint32_t parm_err
= 0;
4712 struct SHARE_INFO_2 i2
;
4714 if ((argc
< 2) || (argc
> 3)) {
4715 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
4717 return NT_STATUS_INVALID_PARAMETER
;
4720 i2
.shi2_netname
= argv
[0];
4721 i2
.shi2_type
= STYPE_DISKTREE
;
4722 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4723 i2
.shi2_permissions
= 0;
4724 i2
.shi2_max_uses
= 0;
4725 i2
.shi2_current_uses
= 0;
4726 i2
.shi2_path
= argv
[1];
4727 i2
.shi2_passwd
= NULL
;
4729 status
= NetShareAdd(pipe_hnd
->desthost
,
4734 return werror_to_ntstatus(W_ERROR(status
));
4737 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4738 TALLOC_CTX
*mem_ctx
,
4739 struct rpc_sh_ctx
*ctx
,
4740 struct rpc_pipe_client
*pipe_hnd
,
4741 int argc
, const char **argv
)
4744 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4745 return NT_STATUS_INVALID_PARAMETER
;
4748 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4751 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4752 TALLOC_CTX
*mem_ctx
,
4753 struct rpc_sh_ctx
*ctx
,
4754 struct rpc_pipe_client
*pipe_hnd
,
4755 int argc
, const char **argv
)
4757 union srvsvc_NetShareInfo info
;
4762 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4763 return NT_STATUS_INVALID_PARAMETER
;
4766 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4772 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4776 d_printf(_("Name: %s\n"), info
.info2
->name
);
4777 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
4778 d_printf(_("Path: %s\n"), info
.info2
->path
);
4779 d_printf(_("Password: %s\n"), info
.info2
->password
);
4782 return werror_to_ntstatus(result
);
4785 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4786 struct rpc_sh_ctx
*ctx
)
4788 static struct rpc_sh_cmd cmds
[] = {
4790 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4791 N_("List available shares") },
4793 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4794 N_("Add a share") },
4796 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4797 N_("Delete a share") },
4799 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4800 N_("Get information about a share") },
4802 { NULL
, NULL
, 0, NULL
, NULL
}
4808 /****************************************************************************/
4810 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4812 return net_file_usage(c
, argc
, argv
);
4816 * Close a file on a remote RPC server.
4818 * @param argc Standard main() style argc.
4819 * @param argv Standard main() style argv. Initial components are already
4822 * @return A shell status integer (0 for success).
4824 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4826 if (argc
< 1 || c
->display_usage
) {
4827 return rpc_file_usage(c
, argc
, argv
);
4830 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4834 * Formatted print of open file info
4836 * @param r struct FILE_INFO_3 contents
4839 static void display_file_info_3(struct FILE_INFO_3
*r
)
4841 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4842 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4843 r
->fi3_num_locks
, r
->fi3_pathname
);
4847 * List files for a user on a remote RPC server.
4849 * @param argc Standard main() style argc.
4850 * @param argv Standard main() style argv. Initial components are already
4853 * @return A shell status integer (0 for success)..
4856 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4858 NET_API_STATUS status
;
4859 uint32 preferred_len
= 0xffffffff, i
;
4860 const char *username
=NULL
;
4861 uint32_t total_entries
= 0;
4862 uint32_t entries_read
= 0;
4863 uint32_t resume_handle
= 0;
4864 struct FILE_INFO_3
*i3
= NULL
;
4866 if (c
->display_usage
) {
4867 return rpc_file_usage(c
, argc
, argv
);
4870 /* if argc > 0, must be user command */
4872 username
= smb_xstrdup(argv
[0]);
4875 status
= NetFileEnum(c
->opt_host
,
4879 (uint8_t **)(void *)&i3
,
4889 /* Display results */
4892 "\nEnumerating open files on remote server:\n\n"
4893 "\nFileId Opened by Perms Locks Path"
4894 "\n------ --------- ----- ----- ---- \n"));
4895 for (i
= 0; i
< entries_read
; i
++) {
4896 display_file_info_3(&i3
[i
]);
4903 * 'net rpc file' entrypoint.
4904 * @param argc Standard main() style argc.
4905 * @param argv Standard main() style argv. Initial components are already
4909 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4911 NET_API_STATUS status
;
4913 struct functable func
[] = {
4918 N_("Close opened file"),
4919 N_("net rpc file close\n"
4920 " Close opened file")
4926 N_("List files opened by user"),
4927 N_("net rpc file user\n"
4928 " List files opened by user")
4935 N_("Display information about opened file"),
4936 N_("net rpc file info\n"
4937 " Display information about opened file")
4940 {NULL
, NULL
, 0, NULL
, NULL
}
4943 status
= libnetapi_init(&c
->netapi_ctx
);
4947 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4948 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4949 if (c
->opt_kerberos
) {
4950 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4954 if (c
->display_usage
) {
4955 d_printf(_("Usage:\n"));
4956 d_printf(_("net rpc file\n"
4957 " List opened files\n"));
4958 net_display_usage_from_functable(func
);
4962 return rpc_file_user(c
, argc
, argv
);
4965 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4969 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4971 * All parameters are provided by the run_rpc_command function, except for
4972 * argc, argv which are passed through.
4974 * @param c A net_context structure.
4975 * @param domain_sid The domain sid acquired from the remote server.
4976 * @param cli A cli_state connected to the server.
4977 * @param mem_ctx Talloc context, destroyed on completion of the function.
4978 * @param argc Standard main() style argc.
4979 * @param argv Standard main() style argv. Initial components are already
4982 * @return Normal NTSTATUS return.
4985 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4986 const DOM_SID
*domain_sid
,
4987 const char *domain_name
,
4988 struct cli_state
*cli
,
4989 struct rpc_pipe_client
*pipe_hnd
,
4990 TALLOC_CTX
*mem_ctx
,
4994 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4996 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4998 if (NT_STATUS_IS_OK(result
)) {
4999 d_printf(_("\nShutdown successfully aborted\n"));
5000 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5002 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5008 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5010 * All parameters are provided by the run_rpc_command function, except for
5011 * argc, argv which are passed through.
5013 * @param c A net_context structure.
5014 * @param domain_sid The domain sid acquired from the remote server.
5015 * @param cli A cli_state connected to the server.
5016 * @param mem_ctx Talloc context, destroyed on completion of the function.
5017 * @param argc Standard main() style argc.
5018 * @param argv Standard main() style argv. Initial components are already
5021 * @return Normal NTSTATUS return.
5024 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5025 const DOM_SID
*domain_sid
,
5026 const char *domain_name
,
5027 struct cli_state
*cli
,
5028 struct rpc_pipe_client
*pipe_hnd
,
5029 TALLOC_CTX
*mem_ctx
,
5033 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5035 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5037 if (NT_STATUS_IS_OK(result
)) {
5038 d_printf(_("\nShutdown successfully aborted\n"));
5039 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5041 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5047 * ABORT the shutdown of a remote RPC server.
5049 * @param argc Standard main() style argc.
5050 * @param argv Standard main() style argv. Initial components are already
5053 * @return A shell status integer (0 for success).
5056 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5061 if (c
->display_usage
) {
5063 "net rpc abortshutdown\n"
5066 _("Abort a scheduled shutdown"));
5070 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5071 rpc_shutdown_abort_internals
, argc
, argv
);
5076 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5078 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5079 rpc_reg_shutdown_abort_internals
,
5084 * Shut down a remote RPC Server via initshutdown pipe.
5086 * All parameters are provided by the run_rpc_command function, except for
5087 * argc, argv which are passed through.
5089 * @param c A net_context structure.
5090 * @param domain_sid The domain sid acquired from the remote server.
5091 * @param cli A cli_state connected to the server.
5092 * @param mem_ctx Talloc context, destroyed on completion of the function.
5093 * @param argc Standard main() style argc.
5094 * @param argv Standard main() style argv. Initial components are already
5097 * @return Normal NTSTATUS return.
5100 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5101 const DOM_SID
*domain_sid
,
5102 const char *domain_name
,
5103 struct cli_state
*cli
,
5104 struct rpc_pipe_client
*pipe_hnd
,
5105 TALLOC_CTX
*mem_ctx
,
5109 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5110 const char *msg
= N_("This machine will be shutdown shortly");
5111 uint32 timeout
= 20;
5112 struct lsa_StringLarge msg_string
;
5114 if (c
->opt_comment
) {
5115 msg
= c
->opt_comment
;
5117 if (c
->opt_timeout
) {
5118 timeout
= c
->opt_timeout
;
5121 msg_string
.string
= msg
;
5123 /* create an entry */
5124 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5125 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5128 if (NT_STATUS_IS_OK(result
)) {
5129 d_printf(_("\nShutdown of remote machine succeeded\n"));
5130 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5132 DEBUG(1,("Shutdown of remote machine failed!\n"));
5138 * Shut down a remote RPC Server via winreg pipe.
5140 * All parameters are provided by the run_rpc_command function, except for
5141 * argc, argv which are passed through.
5143 * @param c A net_context structure.
5144 * @param domain_sid The domain sid acquired from the remote server.
5145 * @param cli A cli_state connected to the server.
5146 * @param mem_ctx Talloc context, destroyed on completion of the function.
5147 * @param argc Standard main() style argc.
5148 * @param argv Standard main() style argv. Initial components are already
5151 * @return Normal NTSTATUS return.
5154 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5155 const DOM_SID
*domain_sid
,
5156 const char *domain_name
,
5157 struct cli_state
*cli
,
5158 struct rpc_pipe_client
*pipe_hnd
,
5159 TALLOC_CTX
*mem_ctx
,
5163 const char *msg
= N_("This machine will be shutdown shortly");
5164 uint32 timeout
= 20;
5165 struct lsa_StringLarge msg_string
;
5169 if (c
->opt_comment
) {
5170 msg
= c
->opt_comment
;
5172 msg_string
.string
= msg
;
5174 if (c
->opt_timeout
) {
5175 timeout
= c
->opt_timeout
;
5178 /* create an entry */
5179 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5180 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5183 if (NT_STATUS_IS_OK(result
)) {
5184 d_printf(_("\nShutdown of remote machine succeeded\n"));
5186 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5187 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5188 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5190 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5197 * Shut down a remote RPC server.
5199 * @param argc Standard main() style argc.
5200 * @param argv Standard main() style argv. Initial components are already
5203 * @return A shell status integer (0 for success).
5206 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5210 if (c
->display_usage
) {
5212 "net rpc shutdown\n"
5215 _("Shut down a remote RPC server"));
5219 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5220 rpc_init_shutdown_internals
, argc
, argv
);
5223 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5224 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5225 rpc_reg_shutdown_internals
, argc
, argv
);
5231 /***************************************************************************
5232 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5233 ***************************************************************************/
5236 * Add interdomain trust account to the RPC server.
5237 * All parameters (except for argc and argv) are passed by run_rpc_command
5240 * @param c A net_context structure.
5241 * @param domain_sid The domain sid acquired from the server.
5242 * @param cli A cli_state connected to the server.
5243 * @param mem_ctx Talloc context, destroyed on completion of the function.
5244 * @param argc Standard main() style argc.
5245 * @param argv Standard main() style argv. Initial components are already
5248 * @return normal NTSTATUS return code.
5251 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5252 const DOM_SID
*domain_sid
,
5253 const char *domain_name
,
5254 struct cli_state
*cli
,
5255 struct rpc_pipe_client
*pipe_hnd
,
5256 TALLOC_CTX
*mem_ctx
,
5260 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5261 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5263 struct lsa_String lsa_acct_name
;
5265 uint32 acct_flags
=0;
5267 uint32_t access_granted
= 0;
5268 union samr_UserInfo info
;
5269 unsigned int orig_timeout
;
5274 _(" net rpc trustdom add <domain_name> "
5275 "<trust password>\n"));
5276 return NT_STATUS_INVALID_PARAMETER
;
5280 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5283 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5284 return NT_STATUS_NO_MEMORY
;
5287 strupper_m(acct_name
);
5289 init_lsa_String(&lsa_acct_name
, acct_name
);
5291 /* Get samr policy handle */
5292 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5294 MAXIMUM_ALLOWED_ACCESS
,
5296 if (!NT_STATUS_IS_OK(result
)) {
5300 /* Get domain policy handle */
5301 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5303 MAXIMUM_ALLOWED_ACCESS
,
5304 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5306 if (!NT_STATUS_IS_OK(result
)) {
5310 /* This call can take a long time - allow the server to time out.
5311 * 35 seconds should do it. */
5313 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5315 /* Create trusting domain's account */
5316 acb_info
= ACB_NORMAL
;
5317 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5318 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5319 SAMR_USER_ACCESS_SET_PASSWORD
|
5320 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5321 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5323 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5332 /* And restore our original timeout. */
5333 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5335 if (!NT_STATUS_IS_OK(result
)) {
5336 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5337 acct_name
, nt_errstr(result
));
5342 struct samr_CryptPassword crypt_pwd
;
5344 ZERO_STRUCT(info
.info23
);
5346 init_samr_CryptPassword(argv
[1],
5347 &cli
->user_session_key
,
5350 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5351 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5352 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5353 info
.info23
.password
= crypt_pwd
;
5355 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5360 if (!NT_STATUS_IS_OK(result
)) {
5361 DEBUG(0,("Could not set trust account password: %s\n",
5362 nt_errstr(result
)));
5368 SAFE_FREE(acct_name
);
5373 * Create interdomain trust account for a remote domain.
5375 * @param argc Standard argc.
5376 * @param argv Standard argv without initial components.
5378 * @return Integer status (0 means success).
5381 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5383 if (argc
> 0 && !c
->display_usage
) {
5384 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5385 rpc_trustdom_add_internals
, argc
, argv
);
5389 _("net rpc trustdom add <domain_name> <trust "
5397 * Remove interdomain trust account from the RPC server.
5398 * All parameters (except for argc and argv) are passed by run_rpc_command
5401 * @param c A net_context structure.
5402 * @param domain_sid The domain sid acquired from the server.
5403 * @param cli A cli_state connected to the server.
5404 * @param mem_ctx Talloc context, destroyed on completion of the function.
5405 * @param argc Standard main() style argc.
5406 * @param argv Standard main() style argv. Initial components are already
5409 * @return normal NTSTATUS return code.
5412 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5413 const DOM_SID
*domain_sid
,
5414 const char *domain_name
,
5415 struct cli_state
*cli
,
5416 struct rpc_pipe_client
*pipe_hnd
,
5417 TALLOC_CTX
*mem_ctx
,
5421 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5422 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5424 DOM_SID trust_acct_sid
;
5425 struct samr_Ids user_rids
, name_types
;
5426 struct lsa_String lsa_acct_name
;
5431 _(" net rpc trustdom del <domain_name>\n"));
5432 return NT_STATUS_INVALID_PARAMETER
;
5436 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5438 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5440 if (acct_name
== NULL
)
5441 return NT_STATUS_NO_MEMORY
;
5443 strupper_m(acct_name
);
5445 /* Get samr policy handle */
5446 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5448 MAXIMUM_ALLOWED_ACCESS
,
5450 if (!NT_STATUS_IS_OK(result
)) {
5454 /* Get domain policy handle */
5455 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5457 MAXIMUM_ALLOWED_ACCESS
,
5458 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5460 if (!NT_STATUS_IS_OK(result
)) {
5464 init_lsa_String(&lsa_acct_name
, acct_name
);
5466 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5473 if (!NT_STATUS_IS_OK(result
)) {
5474 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5476 acct_name
, nt_errstr(result
) );
5480 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5482 MAXIMUM_ALLOWED_ACCESS
,
5486 if (!NT_STATUS_IS_OK(result
)) {
5487 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5489 acct_name
, nt_errstr(result
) );
5493 /* append the rid to the domain sid */
5494 sid_copy(&trust_acct_sid
, domain_sid
);
5495 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5499 /* remove the sid */
5501 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5504 if (!NT_STATUS_IS_OK(result
)) {
5505 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5506 " on user %s failed %s\n"),
5507 acct_name
, nt_errstr(result
) );
5513 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5516 if (!NT_STATUS_IS_OK(result
)) {
5517 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5519 acct_name
, nt_errstr(result
) );
5523 if (!NT_STATUS_IS_OK(result
)) {
5524 d_printf(_("Could not set trust account password: %s\n"),
5534 * Delete interdomain trust account for a remote domain.
5536 * @param argc Standard argc.
5537 * @param argv Standard argv without initial components.
5539 * @return Integer status (0 means success).
5542 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5544 if (argc
> 0 && !c
->display_usage
) {
5545 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5546 rpc_trustdom_del_internals
, argc
, argv
);
5550 _("net rpc trustdom del <domain>\n"));
5555 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5556 struct cli_state
*cli
,
5557 TALLOC_CTX
*mem_ctx
,
5558 const char *domain_name
)
5560 char *dc_name
= NULL
;
5561 const char *buffer
= NULL
;
5562 struct rpc_pipe_client
*netr
;
5565 /* Use NetServerEnum2 */
5567 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5569 return NT_STATUS_OK
;
5572 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5573 for domain %s\n", domain_name
));
5575 /* Try netr_GetDcName */
5577 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5579 if (!NT_STATUS_IS_OK(status
)) {
5583 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5590 if (NT_STATUS_IS_OK(status
)) {
5594 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5595 for domain %s\n", domain_name
));
5601 * Establish trust relationship to a trusting domain.
5602 * Interdomain account must already be created on remote PDC.
5604 * @param c A net_context structure.
5605 * @param argc Standard argc.
5606 * @param argv Standard argv without initial components.
5608 * @return Integer status (0 means success).
5611 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5614 struct cli_state
*cli
= NULL
;
5615 struct sockaddr_storage server_ss
;
5616 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5617 struct policy_handle connect_hnd
;
5618 TALLOC_CTX
*mem_ctx
;
5620 DOM_SID
*domain_sid
;
5625 union lsa_PolicyInformation
*info
= NULL
;
5628 * Connect to \\server\ipc$ as 'our domain' account with password
5631 if (argc
!= 1 || c
->display_usage
) {
5634 _("net rpc trustdom establish <domain_name>\n"));
5638 domain_name
= smb_xstrdup(argv
[0]);
5639 strupper_m(domain_name
);
5641 /* account name used at first is our domain's name with '$' */
5642 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5645 strupper_m(acct_name
);
5648 * opt_workgroup will be used by connection functions further,
5649 * hence it should be set to remote domain name instead of ours
5651 if (c
->opt_workgroup
) {
5652 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5655 c
->opt_user_name
= acct_name
;
5657 /* find the domain controller */
5658 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5659 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5663 /* connect to ipc$ as username/password */
5664 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5665 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5667 /* Is it trusting domain account for sure ? */
5668 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5669 nt_errstr(nt_status
)));
5673 /* store who we connected to */
5675 saf_store( domain_name
, pdc_name
);
5678 * Connect to \\server\ipc$ again (this time anonymously)
5681 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5684 if (NT_STATUS_IS_ERR(nt_status
)) {
5685 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5686 domain_name
, nt_errstr(nt_status
)));
5690 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5691 "domain %s", domain_name
))) {
5692 DEBUG(0, ("talloc_init() failed\n"));
5697 /* Make sure we're talking to a proper server */
5699 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5700 if (!NT_STATUS_IS_OK(nt_status
)) {
5702 talloc_destroy(mem_ctx
);
5707 * Call LsaOpenPolicy and LsaQueryInfo
5710 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5712 if (!NT_STATUS_IS_OK(nt_status
)) {
5713 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5715 talloc_destroy(mem_ctx
);
5719 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5721 if (NT_STATUS_IS_ERR(nt_status
)) {
5722 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5723 nt_errstr(nt_status
)));
5725 talloc_destroy(mem_ctx
);
5729 /* Querying info level 5 */
5731 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5733 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5735 if (NT_STATUS_IS_ERR(nt_status
)) {
5736 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5737 nt_errstr(nt_status
)));
5739 talloc_destroy(mem_ctx
);
5743 domain_sid
= info
->account_domain
.sid
;
5745 /* There should be actually query info level 3 (following nt serv behaviour),
5746 but I still don't know if it's _really_ necessary */
5749 * Store the password in secrets db
5752 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5753 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5755 talloc_destroy(mem_ctx
);
5760 * Close the pipes and clean up
5763 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5764 if (NT_STATUS_IS_ERR(nt_status
)) {
5765 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5766 nt_errstr(nt_status
)));
5768 talloc_destroy(mem_ctx
);
5774 talloc_destroy(mem_ctx
);
5776 d_printf(_("Trust to domain %s established\n"), domain_name
);
5781 * Revoke trust relationship to the remote domain.
5783 * @param c A net_context structure.
5784 * @param argc Standard argc.
5785 * @param argv Standard argv without initial components.
5787 * @return Integer status (0 means success).
5790 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5796 if (argc
< 1 || c
->display_usage
) {
5799 _("net rpc trustdom revoke <domain_name>\n"
5800 " Revoke trust relationship\n"
5801 " domain_name\tName of domain to revoke trust\n"));
5805 /* generate upper cased domain name */
5806 domain_name
= smb_xstrdup(argv
[0]);
5807 strupper_m(domain_name
);
5809 /* delete password of the trust */
5810 if (!pdb_del_trusteddom_pw(domain_name
)) {
5811 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5818 SAFE_FREE(domain_name
);
5822 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5823 const DOM_SID
*domain_sid
,
5824 const char *domain_name
,
5825 struct cli_state
*cli
,
5826 struct rpc_pipe_client
*pipe_hnd
,
5827 TALLOC_CTX
*mem_ctx
,
5832 if (!sid_to_fstring(str_sid
, domain_sid
)) {
5833 return NT_STATUS_UNSUCCESSFUL
;
5835 d_printf("%s\n", str_sid
);
5836 return NT_STATUS_OK
;
5839 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5843 /* convert sid into ascii string */
5844 sid_to_fstring(ascii_sid
, dom_sid
);
5846 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
5849 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5850 TALLOC_CTX
*mem_ctx
,
5851 struct policy_handle
*pol
,
5853 const char *trusted_dom_name
)
5856 union lsa_TrustedDomainInfo
*info
= NULL
;
5857 char *cleartextpwd
= NULL
;
5858 uint8_t session_key
[16];
5859 DATA_BLOB session_key_blob
;
5860 DATA_BLOB data
= data_blob_null
;
5862 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5865 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5867 if (NT_STATUS_IS_ERR(nt_status
)) {
5868 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5869 nt_errstr(nt_status
)));
5873 data
= data_blob(info
->password
.password
->data
,
5874 info
->password
.password
->length
);
5876 if (!rpccli_get_pwd_hash(pipe_hnd
, session_key
)) {
5877 DEBUG(0, ("Could not retrieve password hash\n"));
5881 session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
5882 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key_blob
);
5884 if (cleartextpwd
== NULL
) {
5885 DEBUG(0,("retrieved NULL password\n"));
5886 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5890 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5891 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5892 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5896 #ifdef DEBUG_PASSWORD
5897 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5898 "password: [%s]\n", trusted_dom_name
,
5899 sid_string_dbg(&dom_sid
), cleartextpwd
));
5903 SAFE_FREE(cleartextpwd
);
5904 data_blob_free(&data
);
5909 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5912 /* common variables */
5913 TALLOC_CTX
* mem_ctx
;
5914 struct cli_state
*cli
= NULL
;
5915 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5917 const char *domain_name
= NULL
;
5918 DOM_SID
*queried_dom_sid
;
5919 struct policy_handle connect_hnd
;
5920 union lsa_PolicyInformation
*info
= NULL
;
5922 /* trusted domains listing variables */
5923 unsigned int enum_ctx
= 0;
5925 struct lsa_DomainList dom_list
;
5928 if (c
->display_usage
) {
5930 "net rpc trustdom vampire\n"
5933 _("Vampire trust relationship from remote server"));
5938 * Listing trusted domains (stored in secrets.tdb, if local)
5941 mem_ctx
= talloc_init("trust relationships vampire");
5944 * set domain and pdc name to local samba server (default)
5945 * or to remote one given in command line
5948 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5949 domain_name
= c
->opt_workgroup
;
5950 c
->opt_target_workgroup
= c
->opt_workgroup
;
5952 fstrcpy(pdc_name
, global_myname());
5953 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5954 c
->opt_target_workgroup
= domain_name
;
5957 /* open \PIPE\lsarpc and open policy handle */
5958 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5959 if (!NT_STATUS_IS_OK(nt_status
)) {
5960 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5961 nt_errstr(nt_status
)));
5962 talloc_destroy(mem_ctx
);
5966 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5968 if (!NT_STATUS_IS_OK(nt_status
)) {
5969 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5970 nt_errstr(nt_status
) ));
5972 talloc_destroy(mem_ctx
);
5976 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5978 if (NT_STATUS_IS_ERR(nt_status
)) {
5979 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5980 nt_errstr(nt_status
)));
5982 talloc_destroy(mem_ctx
);
5986 /* query info level 5 to obtain sid of a domain being queried */
5987 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5989 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5992 if (NT_STATUS_IS_ERR(nt_status
)) {
5993 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5994 nt_errstr(nt_status
)));
5996 talloc_destroy(mem_ctx
);
6000 queried_dom_sid
= info
->account_domain
.sid
;
6003 * Keep calling LsaEnumTrustdom over opened pipe until
6004 * the end of enumeration is reached
6007 d_printf(_("Vampire trusted domains:\n\n"));
6010 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6015 if (NT_STATUS_IS_ERR(nt_status
)) {
6016 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6017 nt_errstr(nt_status
)));
6019 talloc_destroy(mem_ctx
);
6023 for (i
= 0; i
< dom_list
.count
; i
++) {
6025 print_trusted_domain(dom_list
.domains
[i
].sid
,
6026 dom_list
.domains
[i
].name
.string
);
6028 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6029 *dom_list
.domains
[i
].sid
,
6030 dom_list
.domains
[i
].name
.string
);
6031 if (!NT_STATUS_IS_OK(nt_status
)) {
6033 talloc_destroy(mem_ctx
);
6039 * in case of no trusted domains say something rather
6040 * than just display blank line
6042 if (!dom_list
.count
) d_printf(_("none\n"));
6044 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6046 /* close this connection before doing next one */
6047 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6048 if (NT_STATUS_IS_ERR(nt_status
)) {
6049 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6050 nt_errstr(nt_status
)));
6052 talloc_destroy(mem_ctx
);
6056 /* close lsarpc pipe and connection to IPC$ */
6059 talloc_destroy(mem_ctx
);
6063 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6065 /* common variables */
6066 TALLOC_CTX
* mem_ctx
;
6067 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6068 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6070 const char *domain_name
= NULL
;
6071 DOM_SID
*queried_dom_sid
;
6072 int ascii_dom_name_len
;
6073 struct policy_handle connect_hnd
;
6074 union lsa_PolicyInformation
*info
= NULL
;
6076 /* trusted domains listing variables */
6077 unsigned int num_domains
, enum_ctx
= 0;
6079 struct lsa_DomainList dom_list
;
6083 /* trusting domains listing variables */
6084 struct policy_handle domain_hnd
;
6085 struct samr_SamArray
*trusts
= NULL
;
6087 if (c
->display_usage
) {
6089 "net rpc trustdom list\n"
6092 _("List incoming and outgoing trust relationships"));
6097 * Listing trusted domains (stored in secrets.tdb, if local)
6100 mem_ctx
= talloc_init("trust relationships listing");
6103 * set domain and pdc name to local samba server (default)
6104 * or to remote one given in command line
6107 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6108 domain_name
= c
->opt_workgroup
;
6109 c
->opt_target_workgroup
= c
->opt_workgroup
;
6111 fstrcpy(pdc_name
, global_myname());
6112 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6113 c
->opt_target_workgroup
= domain_name
;
6116 /* open \PIPE\lsarpc and open policy handle */
6117 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6118 if (!NT_STATUS_IS_OK(nt_status
)) {
6119 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6120 nt_errstr(nt_status
)));
6121 talloc_destroy(mem_ctx
);
6125 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6127 if (!NT_STATUS_IS_OK(nt_status
)) {
6128 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6129 nt_errstr(nt_status
) ));
6131 talloc_destroy(mem_ctx
);
6135 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6137 if (NT_STATUS_IS_ERR(nt_status
)) {
6138 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6139 nt_errstr(nt_status
)));
6141 talloc_destroy(mem_ctx
);
6145 /* query info level 5 to obtain sid of a domain being queried */
6146 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6148 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6151 if (NT_STATUS_IS_ERR(nt_status
)) {
6152 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6153 nt_errstr(nt_status
)));
6155 talloc_destroy(mem_ctx
);
6159 queried_dom_sid
= info
->account_domain
.sid
;
6162 * Keep calling LsaEnumTrustdom over opened pipe until
6163 * the end of enumeration is reached
6166 d_printf(_("Trusted domains list:\n\n"));
6168 found_domain
= false;
6171 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6176 if (NT_STATUS_IS_ERR(nt_status
)) {
6177 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6178 nt_errstr(nt_status
)));
6180 talloc_destroy(mem_ctx
);
6184 for (i
= 0; i
< dom_list
.count
; i
++) {
6185 print_trusted_domain(dom_list
.domains
[i
].sid
,
6186 dom_list
.domains
[i
].name
.string
);
6187 found_domain
= true;
6191 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6194 * in case of no trusted domains say something rather
6195 * than just display blank line
6197 if (!found_domain
) {
6198 d_printf(_("none\n"));
6201 /* close this connection before doing next one */
6202 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6203 if (NT_STATUS_IS_ERR(nt_status
)) {
6204 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6205 nt_errstr(nt_status
)));
6207 talloc_destroy(mem_ctx
);
6211 TALLOC_FREE(pipe_hnd
);
6214 * Listing trusting domains (stored in passdb backend, if local)
6217 d_printf(_("\nTrusting domains list:\n\n"));
6220 * Open \PIPE\samr and get needed policy handles
6222 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6224 if (!NT_STATUS_IS_OK(nt_status
)) {
6225 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6227 talloc_destroy(mem_ctx
);
6232 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6234 SAMR_ACCESS_LOOKUP_DOMAIN
,
6236 if (!NT_STATUS_IS_OK(nt_status
)) {
6237 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6238 nt_errstr(nt_status
)));
6240 talloc_destroy(mem_ctx
);
6244 /* SamrOpenDomain - we have to open domain policy handle in order to be
6245 able to enumerate accounts*/
6246 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6248 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6251 if (!NT_STATUS_IS_OK(nt_status
)) {
6252 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6253 nt_errstr(nt_status
)));
6255 talloc_destroy(mem_ctx
);
6260 * perform actual enumeration
6263 found_domain
= false;
6265 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6268 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6275 if (NT_STATUS_IS_ERR(nt_status
)) {
6276 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6277 nt_errstr(nt_status
)));
6279 talloc_destroy(mem_ctx
);
6283 for (i
= 0; i
< num_domains
; i
++) {
6285 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6287 found_domain
= true;
6290 * get each single domain's sid (do we _really_ need this ?):
6291 * 1) connect to domain's pdc
6292 * 2) query the pdc for domain's sid
6295 /* get rid of '$' tail */
6296 ascii_dom_name_len
= strlen(str
);
6297 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6298 str
[ascii_dom_name_len
- 1] = '\0';
6300 /* set opt_* variables to remote domain */
6302 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6303 c
->opt_target_workgroup
= c
->opt_workgroup
;
6305 d_printf("%-20s", str
);
6307 /* connect to remote domain controller */
6308 nt_status
= net_make_ipc_connection(c
,
6309 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6311 if (NT_STATUS_IS_OK(nt_status
)) {
6312 /* query for domain's sid */
6313 if (run_rpc_command(
6315 &ndr_table_lsarpc
.syntax_id
, 0,
6316 rpc_query_domain_sid
, argc
,
6318 d_printf(_("strange - couldn't get domain's sid\n"));
6320 cli_shutdown(remote_cli
);
6323 d_fprintf(stderr
, _("domain controller is not "
6324 "responding: %s\n"),
6325 nt_errstr(nt_status
));
6326 d_printf(_("couldn't get domain's sid\n"));
6330 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6332 if (!found_domain
) {
6336 /* close opened samr and domain policy handles */
6337 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6338 if (!NT_STATUS_IS_OK(nt_status
)) {
6339 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6342 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6343 if (!NT_STATUS_IS_OK(nt_status
)) {
6344 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6347 /* close samr pipe and connection to IPC$ */
6350 talloc_destroy(mem_ctx
);
6355 * Entrypoint for 'net rpc trustdom' code.
6357 * @param argc Standard argc.
6358 * @param argv Standard argv without initial components.
6360 * @return Integer status (0 means success).
6363 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6365 struct functable func
[] = {
6370 N_("Add trusting domain's account"),
6371 N_("net rpc trustdom add\n"
6372 " Add trusting domain's account")
6378 N_("Remove trusting domain's account"),
6379 N_("net rpc trustdom del\n"
6380 " Remove trusting domain's account")
6384 rpc_trustdom_establish
,
6386 N_("Establish outgoing trust relationship"),
6387 N_("net rpc trustdom establish\n"
6388 " Establish outgoing trust relationship")
6392 rpc_trustdom_revoke
,
6394 N_("Revoke outgoing trust relationship"),
6395 N_("net rpc trustdom revoke\n"
6396 " Revoke outgoing trust relationship")
6402 N_("List in- and outgoing domain trusts"),
6403 N_("net rpc trustdom list\n"
6404 " List in- and outgoing domain trusts")
6408 rpc_trustdom_vampire
,
6410 N_("Vampire trusts from remote server"),
6411 N_("net rpc trustdom vampire\n"
6412 " Vampire trusts from remote server")
6414 {NULL
, NULL
, 0, NULL
, NULL
}
6417 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6421 * Check if a server will take rpc commands
6422 * @param flags Type of server to connect to (PDC, DMB, localhost)
6423 * if the host is not explicitly specified
6424 * @return bool (true means rpc supported)
6426 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6428 struct cli_state
*cli
;
6430 struct sockaddr_storage server_ss
;
6431 char *server_name
= NULL
;
6434 /* flags (i.e. server type) may depend on command */
6435 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6438 if ((cli
= cli_initialise()) == NULL
) {
6442 status
= cli_connect(cli
, server_name
, &server_ss
);
6443 if (!NT_STATUS_IS_OK(status
))
6445 if (!attempt_netbios_session_request(&cli
, global_myname(),
6446 server_name
, &server_ss
))
6448 status
= cli_negprot(cli
);
6449 if (!NT_STATUS_IS_OK(status
))
6451 if (cli
->protocol
< PROTOCOL_NT1
)
6460 /* dump sam database via samsync rpc calls */
6461 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6462 if (c
->display_usage
) {
6467 _("Dump remote SAM database"));
6471 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6472 NET_FLAGS_ANONYMOUS
,
6473 rpc_samdump_internals
, argc
, argv
);
6476 /* syncronise sam database via samsync rpc calls */
6477 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6479 struct functable func
[] = {
6484 N_("Dump remote SAM database to ldif"),
6485 N_("net rpc vampire ldif\n"
6486 " Dump remote SAM database to LDIF file or "
6493 N_("Dump remote SAM database to Kerberos Keytab"),
6494 N_("net rpc vampire keytab\n"
6495 " Dump remote SAM database to Kerberos keytab "
6502 N_("Dump remote SAM database to passdb"),
6503 N_("net rpc vampire passdb\n"
6504 " Dump remote SAM database to passdb")
6507 {NULL
, NULL
, 0, NULL
, NULL
}
6511 if (c
->display_usage
) {
6516 _("Vampire remote SAM database"));
6520 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6521 NET_FLAGS_ANONYMOUS
,
6522 rpc_vampire_internals
,
6526 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6530 * Migrate everything from a print server.
6532 * @param c A net_context structure.
6533 * @param argc Standard main() style argc.
6534 * @param argv Standard main() style argv. Initial components are already
6537 * @return A shell status integer (0 for success).
6539 * The order is important !
6540 * To successfully add drivers the print queues have to exist !
6541 * Applying ACLs should be the last step, because you're easily locked out.
6544 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6549 if (c
->display_usage
) {
6551 "net rpc printer migrate all\n"
6554 _("Migrate everything from a print server"));
6559 d_printf(_("no server to migrate\n"));
6563 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6564 rpc_printer_migrate_printers_internals
, argc
,
6569 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6570 rpc_printer_migrate_drivers_internals
, argc
,
6575 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6576 rpc_printer_migrate_forms_internals
, argc
, argv
);
6580 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6581 rpc_printer_migrate_settings_internals
, argc
,
6586 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6587 rpc_printer_migrate_security_internals
, argc
,
6593 * Migrate print drivers from a print server.
6595 * @param c A net_context structure.
6596 * @param argc Standard main() style argc.
6597 * @param argv Standard main() style argv. Initial components are already
6600 * @return A shell status integer (0 for success).
6602 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6605 if (c
->display_usage
) {
6607 "net rpc printer migrate drivers\n"
6610 _("Migrate print-drivers from a print-server"));
6615 d_printf(_("no server to migrate\n"));
6619 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6620 rpc_printer_migrate_drivers_internals
,
6625 * Migrate print-forms from a print-server.
6627 * @param c A net_context structure.
6628 * @param argc Standard main() style argc.
6629 * @param argv Standard main() style argv. Initial components are already
6632 * @return A shell status integer (0 for success).
6634 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6637 if (c
->display_usage
) {
6639 "net rpc printer migrate forms\n"
6642 _("Migrate print-forms from a print-server"));
6647 d_printf(_("no server to migrate\n"));
6651 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6652 rpc_printer_migrate_forms_internals
,
6657 * Migrate printers from a print-server.
6659 * @param c A net_context structure.
6660 * @param argc Standard main() style argc.
6661 * @param argv Standard main() style argv. Initial components are already
6664 * @return A shell status integer (0 for success).
6666 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6669 if (c
->display_usage
) {
6671 "net rpc printer migrate printers\n"
6674 _("Migrate printers from a print-server"));
6679 d_printf(_("no server to migrate\n"));
6683 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6684 rpc_printer_migrate_printers_internals
,
6689 * Migrate printer-ACLs from a print-server
6691 * @param c A net_context structure.
6692 * @param argc Standard main() style argc.
6693 * @param argv Standard main() style argv. Initial components are already
6696 * @return A shell status integer (0 for success).
6698 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6701 if (c
->display_usage
) {
6703 "net rpc printer migrate security\n"
6706 _("Migrate printer-ACLs from a print-server"));
6711 d_printf(_("no server to migrate\n"));
6715 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6716 rpc_printer_migrate_security_internals
,
6721 * Migrate printer-settings from a print-server.
6723 * @param c A net_context structure.
6724 * @param argc Standard main() style argc.
6725 * @param argv Standard main() style argv. Initial components are already
6728 * @return A shell status integer (0 for success).
6730 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6733 if (c
->display_usage
) {
6735 "net rpc printer migrate settings\n"
6738 _("Migrate printer-settings from a "
6744 d_printf(_("no server to migrate\n"));
6748 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6749 rpc_printer_migrate_settings_internals
,
6754 * 'net rpc printer' entrypoint.
6756 * @param c A net_context structure.
6757 * @param argc Standard main() style argc.
6758 * @param argv Standard main() style argv. Initial components are already
6762 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6765 /* ouch: when addriver and setdriver are called from within
6766 rpc_printer_migrate_drivers_internals, the printer-queue already
6769 struct functable func
[] = {
6772 rpc_printer_migrate_all
,
6774 N_("Migrate all from remote to local print server"),
6775 N_("net rpc printer migrate all\n"
6776 " Migrate all from remote to local print server")
6780 rpc_printer_migrate_drivers
,
6782 N_("Migrate drivers to local server"),
6783 N_("net rpc printer migrate drivers\n"
6784 " Migrate drivers to local server")
6788 rpc_printer_migrate_forms
,
6790 N_("Migrate froms to local server"),
6791 N_("net rpc printer migrate forms\n"
6792 " Migrate froms to local server")
6796 rpc_printer_migrate_printers
,
6798 N_("Migrate printers to local server"),
6799 N_("net rpc printer migrate printers\n"
6800 " Migrate printers to local server")
6804 rpc_printer_migrate_security
,
6806 N_("Mirgate printer ACLs to local server"),
6807 N_("net rpc printer migrate security\n"
6808 " Mirgate printer ACLs to local server")
6812 rpc_printer_migrate_settings
,
6814 N_("Migrate printer settings to local server"),
6815 N_("net rpc printer migrate settings\n"
6816 " Migrate printer settings to local server")
6818 {NULL
, NULL
, 0, NULL
, NULL
}
6821 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6826 * List printers on a remote RPC server.
6828 * @param c A net_context structure.
6829 * @param argc Standard main() style argc.
6830 * @param argv Standard main() style argv. Initial components are already
6833 * @return A shell status integer (0 for success).
6835 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6837 if (c
->display_usage
) {
6839 "net rpc printer list\n"
6842 _("List printers on a remote RPC server"));
6846 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6847 rpc_printer_list_internals
,
6852 * List printer-drivers on a remote RPC server.
6854 * @param c A net_context structure.
6855 * @param argc Standard main() style argc.
6856 * @param argv Standard main() style argv. Initial components are already
6859 * @return A shell status integer (0 for success).
6861 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6864 if (c
->display_usage
) {
6866 "net rpc printer driver\n"
6869 _("List printer-drivers on a remote RPC server"));
6873 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6874 rpc_printer_driver_list_internals
,
6879 * Publish printer in ADS via MSRPC.
6881 * @param c A net_context structure.
6882 * @param argc Standard main() style argc.
6883 * @param argv Standard main() style argv. Initial components are already
6886 * @return A shell status integer (0 for success).
6888 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6891 if (c
->display_usage
) {
6893 "net rpc printer publish publish\n"
6896 _("Publish printer in ADS via MSRPC"));
6900 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6901 rpc_printer_publish_publish_internals
,
6906 * Update printer in ADS via MSRPC.
6908 * @param c A net_context structure.
6909 * @param argc Standard main() style argc.
6910 * @param argv Standard main() style argv. Initial components are already
6913 * @return A shell status integer (0 for success).
6915 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6917 if (c
->display_usage
) {
6919 "net rpc printer publish update\n"
6922 _("Update printer in ADS via MSRPC"));
6926 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6927 rpc_printer_publish_update_internals
,
6932 * UnPublish printer in ADS via MSRPC.
6934 * @param c A net_context structure.
6935 * @param argc Standard main() style argc.
6936 * @param argv Standard main() style argv. Initial components are already
6939 * @return A shell status integer (0 for success).
6941 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6944 if (c
->display_usage
) {
6946 "net rpc printer publish unpublish\n"
6949 _("UnPublish printer in ADS via MSRPC"));
6953 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6954 rpc_printer_publish_unpublish_internals
,
6959 * List published printers via MSRPC.
6961 * @param c A net_context structure.
6962 * @param argc Standard main() style argc.
6963 * @param argv Standard main() style argv. Initial components are already
6966 * @return A shell status integer (0 for success).
6968 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6971 if (c
->display_usage
) {
6973 "net rpc printer publish list\n"
6976 _("List published printers via MSRPC"));
6980 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6981 rpc_printer_publish_list_internals
,
6987 * Publish printer in ADS.
6989 * @param c A net_context structure.
6990 * @param argc Standard main() style argc.
6991 * @param argv Standard main() style argv. Initial components are already
6994 * @return A shell status integer (0 for success).
6996 static int rpc_printer_publish(struct net_context
*c
, int argc
,
7000 struct functable func
[] = {
7003 rpc_printer_publish_publish
,
7005 N_("Publish printer in AD"),
7006 N_("net rpc printer publish publish\n"
7007 " Publish printer in AD")
7011 rpc_printer_publish_update
,
7013 N_("Update printer in AD"),
7014 N_("net rpc printer publish update\n"
7015 " Update printer in AD")
7019 rpc_printer_publish_unpublish
,
7021 N_("Unpublish printer"),
7022 N_("net rpc printer publish unpublish\n"
7023 " Unpublish printer")
7027 rpc_printer_publish_list
,
7029 N_("List published printers"),
7030 N_("net rpc printer publish list\n"
7031 " List published printers")
7033 {NULL
, NULL
, 0, NULL
, NULL
}
7037 if (c
->display_usage
) {
7038 d_printf(_("Usage:\n"));
7039 d_printf(_("net rpc printer publish\n"
7040 " List published printers\n"
7041 " Alias of net rpc printer publish "
7043 net_display_usage_from_functable(func
);
7046 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7047 rpc_printer_publish_list_internals
,
7051 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
7057 * Display rpc printer help page.
7059 * @param c A net_context structure.
7060 * @param argc Standard main() style argc.
7061 * @param argv Standard main() style argv. Initial components are already
7064 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
7066 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
7067 "\tlists all printers on print-server\n\n"));
7068 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7069 "\tlists all printer-drivers on print-server\n\n"));
7070 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7071 "\tpublishes printer settings in Active Directory\n"
7072 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
7073 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7074 "\n\tmigrates printers from remote to local server\n\n"));
7075 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7076 "\n\tmigrates printer-settings from remote to local server\n\n"));
7077 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7078 "\n\tmigrates printer-drivers from remote to local server\n\n"));
7079 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7080 "\n\tmigrates printer-forms from remote to local server\n\n"));
7081 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7082 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
7083 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7084 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7085 "\tremote to local print-server\n\n"));
7086 net_common_methods_usage(c
, argc
, argv
);
7087 net_common_flags_usage(c
, argc
, argv
);
7089 "\t-v or --verbose\t\t\tgive verbose output\n"
7090 "\t --destination\t\tmigration target server (default: localhost)\n"));
7096 * 'net rpc printer' entrypoint.
7098 * @param c A net_context structure.
7099 * @param argc Standard main() style argc.
7100 * @param argv Standard main() style argv. Initial components are already
7103 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
7105 struct functable func
[] = {
7110 N_("List all printers on print server"),
7111 N_("net rpc printer list\n"
7112 " List all printers on print server")
7116 rpc_printer_migrate
,
7118 N_("Migrate printer to local server"),
7119 N_("net rpc printer migrate\n"
7120 " Migrate printer to local server")
7124 rpc_printer_driver_list
,
7126 N_("List printer drivers"),
7127 N_("net rpc printer driver\n"
7128 " List printer drivers")
7132 rpc_printer_publish
,
7134 N_("Publish printer in AD"),
7135 N_("net rpc printer publish\n"
7136 " Publish printer in AD")
7138 {NULL
, NULL
, 0, NULL
, NULL
}
7142 if (c
->display_usage
) {
7143 d_printf(_("Usage:\n"));
7144 d_printf(_("net rpc printer\n"
7145 " List printers\n"));
7146 net_display_usage_from_functable(func
);
7149 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7150 rpc_printer_list_internals
,
7154 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7158 * 'net rpc' entrypoint.
7160 * @param c A net_context structure.
7161 * @param argc Standard main() style argc.
7162 * @param argv Standard main() style argv. Initial components are already
7166 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7168 NET_API_STATUS status
;
7170 struct functable func
[] = {
7175 N_("Modify global audit settings"),
7176 N_("net rpc audit\n"
7177 " Modify global audit settings")
7183 N_("Show basic info about a domain"),
7185 " Show basic info about a domain")
7191 N_("Join a domain"),
7199 N_("Join a domain created in server manager"),
7200 N_("net rpc oldjoin\n"
7201 " Join a domain created in server manager")
7207 N_("Test that a join is valid"),
7208 N_("net rpc testjoin\n"
7209 " Test that a join is valid")
7215 N_("List/modify users"),
7217 " List/modify users")
7223 N_("Change a user password"),
7224 N_("net rpc password\n"
7225 " Change a user password\n"
7226 " Alias for net rpc user password")
7232 N_("List/modify groups"),
7233 N_("net rpc group\n"
7234 " List/modify groups")
7240 N_("List/modify shares"),
7241 N_("net rpc share\n"
7242 " List/modify shares")
7248 N_("List open files"),
7256 N_("List/modify printers"),
7257 N_("net rpc printer\n"
7258 " List/modify printers")
7262 net_rpc_changetrustpw
,
7264 N_("Change trust account password"),
7265 N_("net rpc changetrustpw\n"
7266 " Change trust account password")
7272 N_("Modify domain trusts"),
7273 N_("net rpc trustdom\n"
7274 " Modify domain trusts")
7280 N_("Abort a remote shutdown"),
7281 N_("net rpc abortshutdown\n"
7282 " Abort a remote shutdown")
7288 N_("Shutdown a remote server"),
7289 N_("net rpc shutdown\n"
7290 " Shutdown a remote server")
7296 N_("Dump SAM data of remote NT PDC"),
7297 N_("net rpc samdump\n"
7298 " Dump SAM data of remote NT PDC")
7304 N_("Sync a remote NT PDC's data into local passdb"),
7305 N_("net rpc vampire\n"
7306 " Sync a remote NT PDC's data into local passdb")
7312 N_("Fetch the domain sid into local secrets.tdb"),
7313 N_("net rpc getsid\n"
7314 " Fetch the domain sid into local secrets.tdb")
7320 N_("Manage privileges assigned to SID"),
7321 N_("net rpc rights\n"
7322 " Manage privileges assigned to SID")
7328 N_("Start/stop/query remote services"),
7329 N_("net rpc service\n"
7330 " Start/stop/query remote services")
7336 N_("Manage registry hives"),
7337 N_("net rpc registry\n"
7338 " Manage registry hives")
7344 N_("Open interactive shell on remote server"),
7345 N_("net rpc shell\n"
7346 " Open interactive shell on remote server")
7348 {NULL
, NULL
, 0, NULL
, NULL
}
7351 status
= libnetapi_init(&c
->netapi_ctx
);
7355 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7356 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7357 if (c
->opt_kerberos
) {
7358 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7360 if (c
->opt_ccache
) {
7361 libnetapi_set_use_ccache(c
->netapi_ctx
);
7364 return net_run_function(c
, argc
, argv
, "net rpc", func
);