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
)
3106 status
= cli_tcon_andx(cli
, netname
, "A:", "", 0);
3107 if (!NT_STATUS_IS_OK(status
)) {
3108 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3112 status
= cli_tdis(cli
);
3113 if (!NT_STATUS_IS_OK(status
)) {
3114 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status
));
3121 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3122 const char *netname
, uint32 type
)
3124 /* only support disk shares */
3125 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3126 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3131 /* skip builtin shares */
3132 /* FIXME: should print$ be added too ? */
3133 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3134 strequal(netname
,"global"))
3137 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3138 printf(_("excluding [%s]\n"), netname
);
3142 return check_share_availability(cli
, netname
);
3146 * Migrate shares from a remote RPC server to the local RPC server.
3148 * All parameters are provided by the run_rpc_command function, except for
3149 * argc, argv which are passed through.
3151 * @param domain_sid The domain sid acquired from the remote server.
3152 * @param cli A cli_state connected to the server.
3153 * @param mem_ctx Talloc context, destroyed on completion of the function.
3154 * @param argc Standard main() style argc.
3155 * @param argv Standard main() style argv. Initial components are already
3158 * @return Normal NTSTATUS return.
3161 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3162 const DOM_SID
*domain_sid
,
3163 const char *domain_name
,
3164 struct cli_state
*cli
,
3165 struct rpc_pipe_client
*pipe_hnd
,
3166 TALLOC_CTX
*mem_ctx
,
3171 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3172 struct srvsvc_NetShareInfoCtr ctr_src
;
3174 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3175 struct cli_state
*cli_dst
= NULL
;
3176 uint32 level
= 502; /* includes secdesc */
3177 uint32_t parm_error
= 0;
3179 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3181 if (!W_ERROR_IS_OK(result
))
3184 /* connect destination PI_SRVSVC */
3185 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3186 &ndr_table_srvsvc
.syntax_id
);
3187 if (!NT_STATUS_IS_OK(nt_status
))
3191 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3193 union srvsvc_NetShareInfo info
;
3194 struct srvsvc_NetShareInfo502 info502
=
3195 ctr_src
.ctr
.ctr502
->array
[i
];
3197 /* reset error-code */
3198 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3200 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3203 /* finally add the share on the dst server */
3205 printf(_("migrating: [%s], path: %s, comment: %s, without "
3207 info502
.name
, info502
.path
, info502
.comment
);
3209 info
.info502
= &info502
;
3211 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3212 srvsvc_pipe
->desthost
,
3218 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3219 printf(_(" [%s] does already exist\n"),
3224 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3225 printf(_("cannot add share: %s\n"), win_errstr(result
));
3231 nt_status
= NT_STATUS_OK
;
3235 cli_shutdown(cli_dst
);
3243 * Migrate shares from a RPC server to another.
3245 * @param argc Standard main() style argc.
3246 * @param argv Standard main() style argv. Initial components are already
3249 * @return A shell status integer (0 for success).
3251 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3254 if (c
->display_usage
) {
3256 "net rpc share migrate shares\n"
3259 _("Migrate shares to local server"));
3264 printf(_("no server to migrate\n"));
3268 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3269 rpc_share_migrate_shares_internals
,
3276 * @param f file_info
3277 * @param mask current search mask
3278 * @param state arg-pointer
3281 static void copy_fn(const char *mnt
, file_info
*f
,
3282 const char *mask
, void *state
)
3284 static NTSTATUS nt_status
;
3285 static struct copy_clistate
*local_state
;
3286 static fstring filename
, new_mask
;
3289 struct net_context
*c
;
3291 local_state
= (struct copy_clistate
*)state
;
3292 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3296 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3299 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3302 if (f
->mode
& aDIR
) {
3304 DEBUG(3,("got dir: %s\n", f
->name
));
3306 fstrcpy(dir
, local_state
->cwd
);
3308 fstrcat(dir
, f
->name
);
3310 switch (net_mode_share
)
3312 case NET_MODE_SHARE_MIGRATE
:
3313 /* create that directory */
3314 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3315 local_state
->cli_share_src
,
3316 local_state
->cli_share_dst
,
3318 c
->opt_acls
? true : false,
3319 c
->opt_attrs
? true : false,
3320 c
->opt_timestamps
? true:false,
3324 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3328 if (!NT_STATUS_IS_OK(nt_status
))
3329 printf(_("could not handle dir %s: %s\n"),
3330 dir
, nt_errstr(nt_status
));
3332 /* search below that directory */
3333 fstrcpy(new_mask
, dir
);
3334 fstrcat(new_mask
, "\\*");
3336 old_dir
= local_state
->cwd
;
3337 local_state
->cwd
= dir
;
3338 if (!sync_files(local_state
, new_mask
))
3339 printf(_("could not handle files\n"));
3340 local_state
->cwd
= old_dir
;
3347 fstrcpy(filename
, local_state
->cwd
);
3348 fstrcat(filename
, "\\");
3349 fstrcat(filename
, f
->name
);
3351 DEBUG(3,("got file: %s\n", filename
));
3353 switch (net_mode_share
)
3355 case NET_MODE_SHARE_MIGRATE
:
3356 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3357 local_state
->cli_share_src
,
3358 local_state
->cli_share_dst
,
3360 c
->opt_acls
? true : false,
3361 c
->opt_attrs
? true : false,
3362 c
->opt_timestamps
? true: false,
3366 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
3371 if (!NT_STATUS_IS_OK(nt_status
))
3372 printf(_("could not handle file %s: %s\n"),
3373 filename
, nt_errstr(nt_status
));
3378 * sync files, can be called recursivly to list files
3379 * and then call copy_fn for each file
3381 * @param cp_clistate pointer to the copy_clistate we work with
3382 * @param mask the current search mask
3384 * @return Boolean result
3386 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3388 struct cli_state
*targetcli
;
3389 char *targetpath
= NULL
;
3391 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3393 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3394 mask
, &targetcli
, &targetpath
) ) {
3395 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
3397 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3401 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3402 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
3403 mask
, cli_errstr(targetcli
));
3412 * Set the top level directory permissions before we do any further copies.
3413 * Should set up ACL inheritance.
3416 bool copy_top_level_perms(struct net_context
*c
,
3417 struct copy_clistate
*cp_clistate
,
3418 const char *sharename
)
3420 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3422 switch (net_mode_share
) {
3423 case NET_MODE_SHARE_MIGRATE
:
3424 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3425 nt_status
= net_copy_fileattr(c
,
3426 cp_clistate
->mem_ctx
,
3427 cp_clistate
->cli_share_src
,
3428 cp_clistate
->cli_share_dst
,
3430 c
->opt_acls
? true : false,
3431 c
->opt_attrs
? true : false,
3432 c
->opt_timestamps
? true: false,
3436 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3440 if (!NT_STATUS_IS_OK(nt_status
)) {
3441 printf(_("Could handle directory attributes for top level "
3442 "directory of share %s. Error %s\n"),
3443 sharename
, nt_errstr(nt_status
));
3451 * Sync all files inside a remote share to another share (over smb).
3453 * All parameters are provided by the run_rpc_command function, except for
3454 * argc, argv which are passed through.
3456 * @param domain_sid The domain sid acquired from the remote server.
3457 * @param cli A cli_state connected to the server.
3458 * @param mem_ctx Talloc context, destroyed on completion of the function.
3459 * @param argc Standard main() style argc.
3460 * @param argv Standard main() style argv. Initial components are already
3463 * @return Normal NTSTATUS return.
3466 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3467 const DOM_SID
*domain_sid
,
3468 const char *domain_name
,
3469 struct cli_state
*cli
,
3470 struct rpc_pipe_client
*pipe_hnd
,
3471 TALLOC_CTX
*mem_ctx
,
3476 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3477 struct srvsvc_NetShareInfoCtr ctr_src
;
3480 struct copy_clistate cp_clistate
;
3481 bool got_src_share
= false;
3482 bool got_dst_share
= false;
3483 const char *mask
= "\\*";
3486 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3488 nt_status
= NT_STATUS_NO_MEMORY
;
3492 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3495 if (!W_ERROR_IS_OK(result
))
3498 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3500 struct srvsvc_NetShareInfo502 info502
=
3501 ctr_src
.ctr
.ctr502
->array
[i
];
3503 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3506 /* one might not want to mirror whole discs :) */
3507 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3508 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3513 switch (net_mode_share
)
3515 case NET_MODE_SHARE_MIGRATE
:
3519 d_fprintf(stderr
, _("Unsupported mode %d\n"),
3523 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3526 c
->opt_acls
? _("including") : _("without"),
3527 c
->opt_attrs
? _("including") : _("without"),
3528 c
->opt_timestamps
? _("(preserving timestamps)") : "");
3530 cp_clistate
.mem_ctx
= mem_ctx
;
3531 cp_clistate
.cli_share_src
= NULL
;
3532 cp_clistate
.cli_share_dst
= NULL
;
3533 cp_clistate
.cwd
= NULL
;
3534 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3537 /* open share source */
3538 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3539 &cli
->dest_ss
, cli
->desthost
,
3540 info502
.name
, "A:");
3541 if (!NT_STATUS_IS_OK(nt_status
))
3544 got_src_share
= true;
3546 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3547 /* open share destination */
3548 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3549 NULL
, dst
, info502
.name
, "A:");
3550 if (!NT_STATUS_IS_OK(nt_status
))
3553 got_dst_share
= true;
3556 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3557 d_fprintf(stderr
, _("Could not handle the top level "
3558 "directory permissions for the "
3559 "share: %s\n"), info502
.name
);
3560 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3564 if (!sync_files(&cp_clistate
, mask
)) {
3565 d_fprintf(stderr
, _("could not handle files for share: "
3566 "%s\n"), info502
.name
);
3567 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3572 nt_status
= NT_STATUS_OK
;
3577 cli_shutdown(cp_clistate
.cli_share_src
);
3580 cli_shutdown(cp_clistate
.cli_share_dst
);
3587 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3589 if (c
->display_usage
) {
3591 "net share migrate files\n"
3594 _("Migrate files to local server"));
3599 d_printf(_("no server to migrate\n"));
3603 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3604 rpc_share_migrate_files_internals
,
3609 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3611 * All parameters are provided by the run_rpc_command function, except for
3612 * argc, argv which are passed through.
3614 * @param domain_sid The domain sid acquired from the remote server.
3615 * @param cli A cli_state connected to the server.
3616 * @param mem_ctx Talloc context, destroyed on completion of the function.
3617 * @param argc Standard main() style argc.
3618 * @param argv Standard main() style argv. Initial components are already
3621 * @return Normal NTSTATUS return.
3624 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3625 const DOM_SID
*domain_sid
,
3626 const char *domain_name
,
3627 struct cli_state
*cli
,
3628 struct rpc_pipe_client
*pipe_hnd
,
3629 TALLOC_CTX
*mem_ctx
,
3634 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3635 struct srvsvc_NetShareInfoCtr ctr_src
;
3636 union srvsvc_NetShareInfo info
;
3638 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3639 struct cli_state
*cli_dst
= NULL
;
3640 uint32 level
= 502; /* includes secdesc */
3641 uint32_t parm_error
= 0;
3643 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3646 if (!W_ERROR_IS_OK(result
))
3649 /* connect destination PI_SRVSVC */
3650 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3651 &ndr_table_srvsvc
.syntax_id
);
3652 if (!NT_STATUS_IS_OK(nt_status
))
3656 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3658 struct srvsvc_NetShareInfo502 info502
=
3659 ctr_src
.ctr
.ctr502
->array
[i
];
3661 /* reset error-code */
3662 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3664 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3667 printf(_("migrating: [%s], path: %s, comment: %s, including "
3669 info502
.name
, info502
.path
, info502
.comment
);
3672 display_sec_desc(info502
.sd_buf
.sd
);
3674 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3675 info
.info502
= &info502
;
3677 /* finally modify the share on the dst server */
3678 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3679 srvsvc_pipe
->desthost
,
3685 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3686 printf(_("cannot set share-acl: %s\n"),
3687 win_errstr(result
));
3693 nt_status
= NT_STATUS_OK
;
3697 cli_shutdown(cli_dst
);
3705 * Migrate share-acls from a RPC server to another.
3707 * @param argc Standard main() style argc.
3708 * @param argv Standard main() style argv. Initial components are already
3711 * @return A shell status integer (0 for success).
3713 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3716 if (c
->display_usage
) {
3718 "net rpc share migrate security\n"
3721 _("Migrate share-acls to local server"));
3726 d_printf(_("no server to migrate\n"));
3730 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3731 rpc_share_migrate_security_internals
,
3736 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3737 * from one server to another.
3739 * @param argc Standard main() style argc.
3740 * @param argv Standard main() style argv. Initial components are already
3743 * @return A shell status integer (0 for success).
3746 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3751 if (c
->display_usage
) {
3753 "net rpc share migrate all\n"
3756 _("Migrates shares including all share settings"));
3761 d_printf(_("no server to migrate\n"));
3765 /* order is important. we don't want to be locked out by the share-acl
3766 * before copying files - gd */
3768 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3769 rpc_share_migrate_shares_internals
, argc
, argv
);
3773 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3774 rpc_share_migrate_files_internals
, argc
, argv
);
3778 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3779 rpc_share_migrate_security_internals
, argc
,
3785 * 'net rpc share migrate' entrypoint.
3786 * @param argc Standard main() style argc.
3787 * @param argv Standard main() style argv. Initial components are already
3790 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3793 struct functable func
[] = {
3796 rpc_share_migrate_all
,
3798 N_("Migrate shares from remote to local server"),
3799 N_("net rpc share migrate all\n"
3800 " Migrate shares from remote to local server")
3804 rpc_share_migrate_files
,
3806 N_("Migrate files from remote to local server"),
3807 N_("net rpc share migrate files\n"
3808 " Migrate files from remote to local server")
3812 rpc_share_migrate_security
,
3814 N_("Migrate share-ACLs from remote to local server"),
3815 N_("net rpc share migrate security\n"
3816 " Migrate share-ACLs from remote to local server")
3820 rpc_share_migrate_shares
,
3822 N_("Migrate shares from remote to local server"),
3823 N_("net rpc share migrate shares\n"
3824 " Migrate shares from remote to local server")
3826 {NULL
, NULL
, 0, NULL
, NULL
}
3829 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3831 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3840 static int num_server_aliases
;
3841 static struct full_alias
*server_aliases
;
3844 * Add an alias to the static list.
3846 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3848 if (server_aliases
== NULL
)
3849 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3851 server_aliases
[num_server_aliases
] = *alias
;
3852 num_server_aliases
+= 1;
3856 * For a specific domain on the server, fetch all the aliases
3857 * and their members. Add all of them to the server_aliases.
3860 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3861 TALLOC_CTX
*mem_ctx
,
3862 struct policy_handle
*connect_pol
,
3863 const DOM_SID
*domain_sid
)
3865 uint32 start_idx
, max_entries
, num_entries
, i
;
3866 struct samr_SamArray
*groups
= NULL
;
3868 struct policy_handle domain_pol
;
3870 /* Get domain policy handle */
3872 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3874 MAXIMUM_ALLOWED_ACCESS
,
3875 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3877 if (!NT_STATUS_IS_OK(result
))
3884 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3890 for (i
= 0; i
< num_entries
; i
++) {
3892 struct policy_handle alias_pol
;
3893 struct full_alias alias
;
3894 struct lsa_SidArray sid_array
;
3897 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3899 MAXIMUM_ALLOWED_ACCESS
,
3900 groups
->entries
[i
].idx
,
3902 if (!NT_STATUS_IS_OK(result
))
3905 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3908 if (!NT_STATUS_IS_OK(result
))
3911 alias
.num_members
= sid_array
.num_sids
;
3913 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3914 if (!NT_STATUS_IS_OK(result
))
3917 alias
.members
= NULL
;
3919 if (alias
.num_members
> 0) {
3920 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3922 for (j
= 0; j
< alias
.num_members
; j
++)
3923 sid_copy(&alias
.members
[j
],
3924 sid_array
.sids
[j
].sid
);
3927 sid_compose(&alias
.sid
, domain_sid
,
3928 groups
->entries
[i
].idx
);
3930 push_alias(mem_ctx
, &alias
);
3932 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3934 result
= NT_STATUS_OK
;
3937 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3943 * Dump server_aliases as names for debugging purposes.
3946 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3947 const DOM_SID
*domain_sid
,
3948 const char *domain_name
,
3949 struct cli_state
*cli
,
3950 struct rpc_pipe_client
*pipe_hnd
,
3951 TALLOC_CTX
*mem_ctx
,
3957 struct policy_handle lsa_pol
;
3959 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3960 SEC_FLAG_MAXIMUM_ALLOWED
,
3962 if (!NT_STATUS_IS_OK(result
))
3965 for (i
=0; i
<num_server_aliases
; i
++) {
3968 enum lsa_SidType
*types
;
3971 struct full_alias
*alias
= &server_aliases
[i
];
3973 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3975 &domains
, &names
, &types
);
3976 if (!NT_STATUS_IS_OK(result
))
3979 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3981 if (alias
->num_members
== 0) {
3986 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3989 &domains
, &names
, &types
);
3991 if (!NT_STATUS_IS_OK(result
) &&
3992 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3995 for (j
=0; j
<alias
->num_members
; j
++)
3996 DEBUG(1, ("%s\\%s (%d); ",
3997 domains
[j
] ? domains
[j
] : "*unknown*",
3998 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4002 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4004 return NT_STATUS_OK
;
4008 * Fetch a list of all server aliases and their members into
4012 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4013 const DOM_SID
*domain_sid
,
4014 const char *domain_name
,
4015 struct cli_state
*cli
,
4016 struct rpc_pipe_client
*pipe_hnd
,
4017 TALLOC_CTX
*mem_ctx
,
4022 struct policy_handle connect_pol
;
4024 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4026 MAXIMUM_ALLOWED_ACCESS
,
4029 if (!NT_STATUS_IS_OK(result
))
4032 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4033 &global_sid_Builtin
);
4035 if (!NT_STATUS_IS_OK(result
))
4038 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4041 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4046 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4048 token
->num_sids
= 4;
4050 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4051 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4052 token
->num_sids
= 0;
4056 token
->user_sids
[0] = *user_sid
;
4057 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4058 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4059 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4062 static void free_user_token(NT_USER_TOKEN
*token
)
4064 SAFE_FREE(token
->user_sids
);
4067 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4069 if (is_sid_in_token(token
, sid
))
4072 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4073 if (!token
->user_sids
) {
4077 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4079 token
->num_sids
+= 1;
4084 NT_USER_TOKEN token
;
4087 static void dump_user_token(struct user_token
*token
)
4091 d_printf("%s\n", token
->name
);
4093 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4094 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4098 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4102 for (i
=0; i
<alias
->num_members
; i
++) {
4103 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4110 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4114 for (i
=0; i
<num_server_aliases
; i
++) {
4115 if (is_alias_member(&sid
, &server_aliases
[i
]))
4116 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4121 * We got a user token with all the SIDs we can know about without asking the
4122 * server directly. These are the user and domain group sids. All of these can
4123 * be members of aliases. So scan the list of aliases for each of the SIDs and
4124 * add them to the token.
4127 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4129 int num_global_sids
= token
->num_sids
;
4132 for (i
=0; i
<num_global_sids
; i
++) {
4133 collect_sid_memberships(token
, token
->user_sids
[i
]);
4137 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4139 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4140 enum wbcSidType type
;
4142 struct wbcDomainSid wsid
;
4143 char *sid_str
= NULL
;
4145 uint32_t num_groups
;
4146 gid_t
*groups
= NULL
;
4149 fstr_sprintf(full_name
, "%s%c%s",
4150 domain
, *lp_winbind_separator(), user
);
4152 /* First let's find out the user sid */
4154 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4156 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4157 DEBUG(1, ("winbind could not find %s: %s\n",
4158 full_name
, wbcErrorString(wbc_status
)));
4162 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4163 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4167 if (type
!= SID_NAME_USER
) {
4168 wbcFreeMemory(sid_str
);
4169 DEBUG(1, ("%s is not a user\n", full_name
));
4173 if (!string_to_sid(&user_sid
, sid_str
)) {
4174 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4178 wbcFreeMemory(sid_str
);
4181 init_user_token(token
, &user_sid
);
4183 /* And now the groups winbind knows about */
4185 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4186 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4187 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4188 full_name
, wbcErrorString(wbc_status
)));
4192 for (i
= 0; i
< num_groups
; i
++) {
4193 gid_t gid
= groups
[i
];
4196 wbc_status
= wbcGidToSid(gid
, &wsid
);
4197 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4198 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4199 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4200 wbcFreeMemory(groups
);
4204 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4205 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4206 wbcFreeMemory(groups
);
4210 DEBUG(3, (" %s\n", sid_str
));
4212 string_to_sid(&sid
, sid_str
);
4213 wbcFreeMemory(sid_str
);
4216 add_sid_to_token(token
, &sid
);
4218 wbcFreeMemory(groups
);
4224 * Get a list of all user tokens we want to look at
4227 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4228 struct user_token
**user_tokens
)
4230 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4231 uint32_t i
, num_users
;
4233 struct user_token
*result
;
4234 TALLOC_CTX
*frame
= NULL
;
4236 if (lp_winbind_use_default_domain() &&
4237 (c
->opt_target_workgroup
== NULL
)) {
4238 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4239 "please specify a workgroup\n"));
4243 /* Send request to winbind daemon */
4245 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4246 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4247 DEBUG(1, (_("winbind could not list users: %s\n"),
4248 wbcErrorString(wbc_status
)));
4252 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4254 if (result
== NULL
) {
4255 DEBUG(1, ("Could not malloc sid array\n"));
4256 wbcFreeMemory(users
);
4260 frame
= talloc_stackframe();
4261 for (i
=0; i
< num_users
; i
++) {
4262 fstring domain
, user
;
4265 fstrcpy(result
[i
].name
, users
[i
]);
4267 p
= strchr(users
[i
], *lp_winbind_separator());
4269 DEBUG(3, ("%s\n", users
[i
]));
4272 fstrcpy(domain
, c
->opt_target_workgroup
);
4273 fstrcpy(user
, users
[i
]);
4276 fstrcpy(domain
, users
[i
]);
4281 get_user_sids(domain
, user
, &(result
[i
].token
));
4285 wbcFreeMemory(users
);
4287 *num_tokens
= num_users
;
4288 *user_tokens
= result
;
4293 static bool get_user_tokens_from_file(FILE *f
,
4295 struct user_token
**tokens
)
4297 struct user_token
*token
= NULL
;
4302 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4306 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
4307 line
[strlen(line
)-1] = '\0';
4310 if (line
[0] == ' ') {
4314 if(!string_to_sid(&sid
, &line
[1])) {
4315 DEBUG(1,("get_user_tokens_from_file: Could "
4316 "not convert sid %s \n",&line
[1]));
4320 if (token
== NULL
) {
4321 DEBUG(0, ("File does not begin with username"));
4325 add_sid_to_token(&token
->token
, &sid
);
4329 /* And a new user... */
4332 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4333 if (*tokens
== NULL
) {
4334 DEBUG(0, ("Could not realloc tokens\n"));
4338 token
= &((*tokens
)[*num_tokens
-1]);
4340 fstrcpy(token
->name
, line
);
4341 token
->token
.num_sids
= 0;
4342 token
->token
.user_sids
= NULL
;
4351 * Show the list of all users that have access to a share
4354 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4355 TALLOC_CTX
*mem_ctx
,
4356 const char *netname
,
4358 struct user_token
*tokens
)
4361 SEC_DESC
*share_sd
= NULL
;
4362 SEC_DESC
*root_sd
= NULL
;
4363 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4365 union srvsvc_NetShareInfo info
;
4370 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4377 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4378 DEBUG(1, ("Coult not query secdesc for share %s\n",
4383 share_sd
= info
.info502
->sd_buf
.sd
;
4384 if (share_sd
== NULL
) {
4385 DEBUG(1, ("Got no secdesc for share %s\n",
4391 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4395 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
4396 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
4397 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4400 for (i
=0; i
<num_tokens
; i
++) {
4403 if (share_sd
!= NULL
) {
4404 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4407 if (!NT_STATUS_IS_OK(status
)) {
4408 DEBUG(1, ("Could not check share_sd for "
4415 if (root_sd
== NULL
) {
4416 d_printf(" %s\n", tokens
[i
].name
);
4420 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4422 if (!NT_STATUS_IS_OK(status
)) {
4423 DEBUG(1, ("Could not check root_sd for user %s\n",
4427 d_printf(" %s\n", tokens
[i
].name
);
4430 if (fnum
!= (uint16_t)-1)
4431 cli_close(cli
, fnum
);
4443 static void collect_share(const char *name
, uint32 m
,
4444 const char *comment
, void *state
)
4446 struct share_list
*share_list
= (struct share_list
*)state
;
4448 if (m
!= STYPE_DISKTREE
)
4451 share_list
->num_shares
+= 1;
4452 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4453 if (!share_list
->shares
) {
4454 share_list
->num_shares
= 0;
4457 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4461 * List shares on a remote RPC server, including the security descriptors.
4463 * All parameters are provided by the run_rpc_command function, except for
4464 * argc, argv which are passed through.
4466 * @param domain_sid The domain sid acquired from the remote server.
4467 * @param cli A cli_state connected to the server.
4468 * @param mem_ctx Talloc context, destroyed on completion of the function.
4469 * @param argc Standard main() style argc.
4470 * @param argv Standard main() style argv. Initial components are already
4473 * @return Normal NTSTATUS return.
4476 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4477 const DOM_SID
*domain_sid
,
4478 const char *domain_name
,
4479 struct cli_state
*cli
,
4480 struct rpc_pipe_client
*pipe_hnd
,
4481 TALLOC_CTX
*mem_ctx
,
4490 struct user_token
*tokens
= NULL
;
4493 struct share_list share_list
;
4498 f
= fopen(argv
[0], "r");
4502 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4503 return NT_STATUS_UNSUCCESSFUL
;
4506 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4512 DEBUG(0, ("Could not read users from file\n"));
4513 return NT_STATUS_UNSUCCESSFUL
;
4516 for (i
=0; i
<num_tokens
; i
++)
4517 collect_alias_memberships(&tokens
[i
].token
);
4519 share_list
.num_shares
= 0;
4520 share_list
.shares
= NULL
;
4522 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4525 DEBUG(0, ("Error returning browse list: %s\n",
4530 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4531 char *netname
= share_list
.shares
[i
];
4533 if (netname
[strlen(netname
)-1] == '$')
4536 d_printf("%s\n", netname
);
4538 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4539 num_tokens
, tokens
);
4542 for (i
=0; i
<num_tokens
; i
++) {
4543 free_user_token(&tokens
[i
].token
);
4546 SAFE_FREE(share_list
.shares
);
4548 return NT_STATUS_OK
;
4551 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4556 if (c
->display_usage
) {
4558 "net rpc share allowedusers\n"
4561 _("List allowed users"));
4565 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4566 rpc_aliaslist_internals
,
4571 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4577 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4578 rpc_share_allowedusers_internals
,
4582 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4585 struct user_token
*tokens
= NULL
;
4589 net_usersidlist_usage(c
, argc
, argv
);
4593 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4594 DEBUG(0, ("Could not get the user/sid list\n"));
4598 for (i
=0; i
<num_tokens
; i
++) {
4599 dump_user_token(&tokens
[i
]);
4600 free_user_token(&tokens
[i
].token
);
4607 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4609 d_printf(_("net usersidlist\n"
4610 "\tprints out a list of all users the running winbind knows\n"
4611 "\tabout, together with all their SIDs. This is used as\n"
4612 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
4614 net_common_flags_usage(c
, argc
, argv
);
4619 * 'net rpc share' entrypoint.
4620 * @param argc Standard main() style argc.
4621 * @param argv Standard main() style argv. Initial components are already
4625 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4627 NET_API_STATUS status
;
4629 struct functable func
[] = {
4635 N_("net rpc share add\n"
4643 N_("net rpc share delete\n"
4648 rpc_share_allowedusers
,
4650 N_("Modify allowed users"),
4651 N_("net rpc share allowedusers\n"
4652 " Modify allowed users")
4658 N_("Migrate share to local server"),
4659 N_("net rpc share migrate\n"
4660 " Migrate share to local server")
4667 N_("net rpc share list\n"
4670 {NULL
, NULL
, 0, NULL
, NULL
}
4673 status
= libnetapi_init(&c
->netapi_ctx
);
4677 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4678 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4679 if (c
->opt_kerberos
) {
4680 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4684 if (c
->display_usage
) {
4689 " Alias for net rpc share list\n"));
4690 net_display_usage_from_functable(func
);
4694 return rpc_share_list(c
, argc
, argv
);
4697 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4700 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4701 TALLOC_CTX
*mem_ctx
,
4702 struct rpc_sh_ctx
*ctx
,
4703 struct rpc_pipe_client
*pipe_hnd
,
4704 int argc
, const char **argv
)
4707 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4710 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4711 TALLOC_CTX
*mem_ctx
,
4712 struct rpc_sh_ctx
*ctx
,
4713 struct rpc_pipe_client
*pipe_hnd
,
4714 int argc
, const char **argv
)
4716 NET_API_STATUS status
;
4717 uint32_t parm_err
= 0;
4718 struct SHARE_INFO_2 i2
;
4720 if ((argc
< 2) || (argc
> 3)) {
4721 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
4723 return NT_STATUS_INVALID_PARAMETER
;
4726 i2
.shi2_netname
= argv
[0];
4727 i2
.shi2_type
= STYPE_DISKTREE
;
4728 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4729 i2
.shi2_permissions
= 0;
4730 i2
.shi2_max_uses
= 0;
4731 i2
.shi2_current_uses
= 0;
4732 i2
.shi2_path
= argv
[1];
4733 i2
.shi2_passwd
= NULL
;
4735 status
= NetShareAdd(pipe_hnd
->desthost
,
4740 return werror_to_ntstatus(W_ERROR(status
));
4743 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4744 TALLOC_CTX
*mem_ctx
,
4745 struct rpc_sh_ctx
*ctx
,
4746 struct rpc_pipe_client
*pipe_hnd
,
4747 int argc
, const char **argv
)
4750 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4751 return NT_STATUS_INVALID_PARAMETER
;
4754 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4757 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4758 TALLOC_CTX
*mem_ctx
,
4759 struct rpc_sh_ctx
*ctx
,
4760 struct rpc_pipe_client
*pipe_hnd
,
4761 int argc
, const char **argv
)
4763 union srvsvc_NetShareInfo info
;
4768 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4769 return NT_STATUS_INVALID_PARAMETER
;
4772 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4778 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4782 d_printf(_("Name: %s\n"), info
.info2
->name
);
4783 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
4784 d_printf(_("Path: %s\n"), info
.info2
->path
);
4785 d_printf(_("Password: %s\n"), info
.info2
->password
);
4788 return werror_to_ntstatus(result
);
4791 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4792 struct rpc_sh_ctx
*ctx
)
4794 static struct rpc_sh_cmd cmds
[] = {
4796 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4797 N_("List available shares") },
4799 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4800 N_("Add a share") },
4802 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4803 N_("Delete a share") },
4805 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4806 N_("Get information about a share") },
4808 { NULL
, NULL
, 0, NULL
, NULL
}
4814 /****************************************************************************/
4816 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4818 return net_file_usage(c
, argc
, argv
);
4822 * Close a file on a remote RPC server.
4824 * @param argc Standard main() style argc.
4825 * @param argv Standard main() style argv. Initial components are already
4828 * @return A shell status integer (0 for success).
4830 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4832 if (argc
< 1 || c
->display_usage
) {
4833 return rpc_file_usage(c
, argc
, argv
);
4836 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4840 * Formatted print of open file info
4842 * @param r struct FILE_INFO_3 contents
4845 static void display_file_info_3(struct FILE_INFO_3
*r
)
4847 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4848 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4849 r
->fi3_num_locks
, r
->fi3_pathname
);
4853 * List files for a user on a remote RPC server.
4855 * @param argc Standard main() style argc.
4856 * @param argv Standard main() style argv. Initial components are already
4859 * @return A shell status integer (0 for success)..
4862 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4864 NET_API_STATUS status
;
4865 uint32 preferred_len
= 0xffffffff, i
;
4866 const char *username
=NULL
;
4867 uint32_t total_entries
= 0;
4868 uint32_t entries_read
= 0;
4869 uint32_t resume_handle
= 0;
4870 struct FILE_INFO_3
*i3
= NULL
;
4872 if (c
->display_usage
) {
4873 return rpc_file_usage(c
, argc
, argv
);
4876 /* if argc > 0, must be user command */
4878 username
= smb_xstrdup(argv
[0]);
4881 status
= NetFileEnum(c
->opt_host
,
4885 (uint8_t **)(void *)&i3
,
4895 /* Display results */
4898 "\nEnumerating open files on remote server:\n\n"
4899 "\nFileId Opened by Perms Locks Path"
4900 "\n------ --------- ----- ----- ---- \n"));
4901 for (i
= 0; i
< entries_read
; i
++) {
4902 display_file_info_3(&i3
[i
]);
4909 * 'net rpc file' entrypoint.
4910 * @param argc Standard main() style argc.
4911 * @param argv Standard main() style argv. Initial components are already
4915 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4917 NET_API_STATUS status
;
4919 struct functable func
[] = {
4924 N_("Close opened file"),
4925 N_("net rpc file close\n"
4926 " Close opened file")
4932 N_("List files opened by user"),
4933 N_("net rpc file user\n"
4934 " List files opened by user")
4941 N_("Display information about opened file"),
4942 N_("net rpc file info\n"
4943 " Display information about opened file")
4946 {NULL
, NULL
, 0, NULL
, NULL
}
4949 status
= libnetapi_init(&c
->netapi_ctx
);
4953 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4954 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4955 if (c
->opt_kerberos
) {
4956 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4960 if (c
->display_usage
) {
4961 d_printf(_("Usage:\n"));
4962 d_printf(_("net rpc file\n"
4963 " List opened files\n"));
4964 net_display_usage_from_functable(func
);
4968 return rpc_file_user(c
, argc
, argv
);
4971 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4975 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4977 * All parameters are provided by the run_rpc_command function, except for
4978 * argc, argv which are passed through.
4980 * @param c A net_context structure.
4981 * @param domain_sid The domain sid acquired from the remote server.
4982 * @param cli A cli_state connected to the server.
4983 * @param mem_ctx Talloc context, destroyed on completion of the function.
4984 * @param argc Standard main() style argc.
4985 * @param argv Standard main() style argv. Initial components are already
4988 * @return Normal NTSTATUS return.
4991 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4992 const DOM_SID
*domain_sid
,
4993 const char *domain_name
,
4994 struct cli_state
*cli
,
4995 struct rpc_pipe_client
*pipe_hnd
,
4996 TALLOC_CTX
*mem_ctx
,
5000 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5002 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5004 if (NT_STATUS_IS_OK(result
)) {
5005 d_printf(_("\nShutdown successfully aborted\n"));
5006 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5008 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5014 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5016 * All parameters are provided by the run_rpc_command function, except for
5017 * argc, argv which are passed through.
5019 * @param c A net_context structure.
5020 * @param domain_sid The domain sid acquired from the remote server.
5021 * @param cli A cli_state connected to the server.
5022 * @param mem_ctx Talloc context, destroyed on completion of the function.
5023 * @param argc Standard main() style argc.
5024 * @param argv Standard main() style argv. Initial components are already
5027 * @return Normal NTSTATUS return.
5030 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5031 const DOM_SID
*domain_sid
,
5032 const char *domain_name
,
5033 struct cli_state
*cli
,
5034 struct rpc_pipe_client
*pipe_hnd
,
5035 TALLOC_CTX
*mem_ctx
,
5039 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5041 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5043 if (NT_STATUS_IS_OK(result
)) {
5044 d_printf(_("\nShutdown successfully aborted\n"));
5045 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5047 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5053 * ABORT the shutdown of a remote RPC server.
5055 * @param argc Standard main() style argc.
5056 * @param argv Standard main() style argv. Initial components are already
5059 * @return A shell status integer (0 for success).
5062 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5067 if (c
->display_usage
) {
5069 "net rpc abortshutdown\n"
5072 _("Abort a scheduled shutdown"));
5076 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5077 rpc_shutdown_abort_internals
, argc
, argv
);
5082 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5084 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5085 rpc_reg_shutdown_abort_internals
,
5090 * Shut down a remote RPC Server via initshutdown pipe.
5092 * All parameters are provided by the run_rpc_command function, except for
5093 * argc, argv which are passed through.
5095 * @param c A net_context structure.
5096 * @param domain_sid The domain sid acquired from the remote server.
5097 * @param cli A cli_state connected to the server.
5098 * @param mem_ctx Talloc context, destroyed on completion of the function.
5099 * @param argc Standard main() style argc.
5100 * @param argv Standard main() style argv. Initial components are already
5103 * @return Normal NTSTATUS return.
5106 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5107 const DOM_SID
*domain_sid
,
5108 const char *domain_name
,
5109 struct cli_state
*cli
,
5110 struct rpc_pipe_client
*pipe_hnd
,
5111 TALLOC_CTX
*mem_ctx
,
5115 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5116 const char *msg
= N_("This machine will be shutdown shortly");
5117 uint32 timeout
= 20;
5118 struct lsa_StringLarge msg_string
;
5120 if (c
->opt_comment
) {
5121 msg
= c
->opt_comment
;
5123 if (c
->opt_timeout
) {
5124 timeout
= c
->opt_timeout
;
5127 msg_string
.string
= msg
;
5129 /* create an entry */
5130 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5131 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5134 if (NT_STATUS_IS_OK(result
)) {
5135 d_printf(_("\nShutdown of remote machine succeeded\n"));
5136 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5138 DEBUG(1,("Shutdown of remote machine failed!\n"));
5144 * Shut down a remote RPC Server via winreg pipe.
5146 * All parameters are provided by the run_rpc_command function, except for
5147 * argc, argv which are passed through.
5149 * @param c A net_context structure.
5150 * @param domain_sid The domain sid acquired from the remote server.
5151 * @param cli A cli_state connected to the server.
5152 * @param mem_ctx Talloc context, destroyed on completion of the function.
5153 * @param argc Standard main() style argc.
5154 * @param argv Standard main() style argv. Initial components are already
5157 * @return Normal NTSTATUS return.
5160 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5161 const DOM_SID
*domain_sid
,
5162 const char *domain_name
,
5163 struct cli_state
*cli
,
5164 struct rpc_pipe_client
*pipe_hnd
,
5165 TALLOC_CTX
*mem_ctx
,
5169 const char *msg
= N_("This machine will be shutdown shortly");
5170 uint32 timeout
= 20;
5171 struct lsa_StringLarge msg_string
;
5175 if (c
->opt_comment
) {
5176 msg
= c
->opt_comment
;
5178 msg_string
.string
= msg
;
5180 if (c
->opt_timeout
) {
5181 timeout
= c
->opt_timeout
;
5184 /* create an entry */
5185 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5186 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5189 if (NT_STATUS_IS_OK(result
)) {
5190 d_printf(_("\nShutdown of remote machine succeeded\n"));
5192 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5193 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5194 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5196 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5203 * Shut down a remote RPC server.
5205 * @param argc Standard main() style argc.
5206 * @param argv Standard main() style argv. Initial components are already
5209 * @return A shell status integer (0 for success).
5212 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5216 if (c
->display_usage
) {
5218 "net rpc shutdown\n"
5221 _("Shut down a remote RPC server"));
5225 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5226 rpc_init_shutdown_internals
, argc
, argv
);
5229 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5230 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5231 rpc_reg_shutdown_internals
, argc
, argv
);
5237 /***************************************************************************
5238 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5239 ***************************************************************************/
5242 * Add interdomain trust account to the RPC server.
5243 * All parameters (except for argc and argv) are passed by run_rpc_command
5246 * @param c A net_context structure.
5247 * @param domain_sid The domain sid acquired from the server.
5248 * @param cli A cli_state connected to the server.
5249 * @param mem_ctx Talloc context, destroyed on completion of the function.
5250 * @param argc Standard main() style argc.
5251 * @param argv Standard main() style argv. Initial components are already
5254 * @return normal NTSTATUS return code.
5257 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5258 const DOM_SID
*domain_sid
,
5259 const char *domain_name
,
5260 struct cli_state
*cli
,
5261 struct rpc_pipe_client
*pipe_hnd
,
5262 TALLOC_CTX
*mem_ctx
,
5266 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5267 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5269 struct lsa_String lsa_acct_name
;
5271 uint32 acct_flags
=0;
5273 uint32_t access_granted
= 0;
5274 union samr_UserInfo info
;
5275 unsigned int orig_timeout
;
5280 _(" net rpc trustdom add <domain_name> "
5281 "<trust password>\n"));
5282 return NT_STATUS_INVALID_PARAMETER
;
5286 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5289 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5290 return NT_STATUS_NO_MEMORY
;
5293 strupper_m(acct_name
);
5295 init_lsa_String(&lsa_acct_name
, acct_name
);
5297 /* Get samr policy handle */
5298 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5300 MAXIMUM_ALLOWED_ACCESS
,
5302 if (!NT_STATUS_IS_OK(result
)) {
5306 /* Get domain policy handle */
5307 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5309 MAXIMUM_ALLOWED_ACCESS
,
5310 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5312 if (!NT_STATUS_IS_OK(result
)) {
5316 /* This call can take a long time - allow the server to time out.
5317 * 35 seconds should do it. */
5319 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5321 /* Create trusting domain's account */
5322 acb_info
= ACB_NORMAL
;
5323 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5324 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5325 SAMR_USER_ACCESS_SET_PASSWORD
|
5326 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5327 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5329 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5338 /* And restore our original timeout. */
5339 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5341 if (!NT_STATUS_IS_OK(result
)) {
5342 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5343 acct_name
, nt_errstr(result
));
5348 struct samr_CryptPassword crypt_pwd
;
5350 ZERO_STRUCT(info
.info23
);
5352 init_samr_CryptPassword(argv
[1],
5353 &cli
->user_session_key
,
5356 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5357 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5358 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5359 info
.info23
.password
= crypt_pwd
;
5361 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5366 if (!NT_STATUS_IS_OK(result
)) {
5367 DEBUG(0,("Could not set trust account password: %s\n",
5368 nt_errstr(result
)));
5374 SAFE_FREE(acct_name
);
5379 * Create interdomain trust account for a remote domain.
5381 * @param argc Standard argc.
5382 * @param argv Standard argv without initial components.
5384 * @return Integer status (0 means success).
5387 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5389 if (argc
> 0 && !c
->display_usage
) {
5390 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5391 rpc_trustdom_add_internals
, argc
, argv
);
5395 _("net rpc trustdom add <domain_name> <trust "
5403 * Remove interdomain trust account from the RPC server.
5404 * All parameters (except for argc and argv) are passed by run_rpc_command
5407 * @param c A net_context structure.
5408 * @param domain_sid The domain sid acquired from the server.
5409 * @param cli A cli_state connected to the server.
5410 * @param mem_ctx Talloc context, destroyed on completion of the function.
5411 * @param argc Standard main() style argc.
5412 * @param argv Standard main() style argv. Initial components are already
5415 * @return normal NTSTATUS return code.
5418 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5419 const DOM_SID
*domain_sid
,
5420 const char *domain_name
,
5421 struct cli_state
*cli
,
5422 struct rpc_pipe_client
*pipe_hnd
,
5423 TALLOC_CTX
*mem_ctx
,
5427 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5428 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5430 DOM_SID trust_acct_sid
;
5431 struct samr_Ids user_rids
, name_types
;
5432 struct lsa_String lsa_acct_name
;
5437 _(" net rpc trustdom del <domain_name>\n"));
5438 return NT_STATUS_INVALID_PARAMETER
;
5442 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5444 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5446 if (acct_name
== NULL
)
5447 return NT_STATUS_NO_MEMORY
;
5449 strupper_m(acct_name
);
5451 /* Get samr policy handle */
5452 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5454 MAXIMUM_ALLOWED_ACCESS
,
5456 if (!NT_STATUS_IS_OK(result
)) {
5460 /* Get domain policy handle */
5461 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5463 MAXIMUM_ALLOWED_ACCESS
,
5464 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5466 if (!NT_STATUS_IS_OK(result
)) {
5470 init_lsa_String(&lsa_acct_name
, acct_name
);
5472 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5479 if (!NT_STATUS_IS_OK(result
)) {
5480 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5482 acct_name
, nt_errstr(result
) );
5486 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5488 MAXIMUM_ALLOWED_ACCESS
,
5492 if (!NT_STATUS_IS_OK(result
)) {
5493 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5495 acct_name
, nt_errstr(result
) );
5499 /* append the rid to the domain sid */
5500 if (!sid_compose(&trust_acct_sid
, domain_sid
, user_rids
.ids
[0])) {
5504 /* remove the sid */
5506 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5509 if (!NT_STATUS_IS_OK(result
)) {
5510 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5511 " on user %s failed %s\n"),
5512 acct_name
, nt_errstr(result
) );
5518 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5521 if (!NT_STATUS_IS_OK(result
)) {
5522 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5524 acct_name
, nt_errstr(result
) );
5528 if (!NT_STATUS_IS_OK(result
)) {
5529 d_printf(_("Could not set trust account password: %s\n"),
5539 * Delete interdomain trust account for a remote domain.
5541 * @param argc Standard argc.
5542 * @param argv Standard argv without initial components.
5544 * @return Integer status (0 means success).
5547 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5549 if (argc
> 0 && !c
->display_usage
) {
5550 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5551 rpc_trustdom_del_internals
, argc
, argv
);
5555 _("net rpc trustdom del <domain>\n"));
5560 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5561 struct cli_state
*cli
,
5562 TALLOC_CTX
*mem_ctx
,
5563 const char *domain_name
)
5565 char *dc_name
= NULL
;
5566 const char *buffer
= NULL
;
5567 struct rpc_pipe_client
*netr
;
5570 /* Use NetServerEnum2 */
5572 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5574 return NT_STATUS_OK
;
5577 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5578 for domain %s\n", domain_name
));
5580 /* Try netr_GetDcName */
5582 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5584 if (!NT_STATUS_IS_OK(status
)) {
5588 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5595 if (NT_STATUS_IS_OK(status
)) {
5599 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5600 for domain %s\n", domain_name
));
5606 * Establish trust relationship to a trusting domain.
5607 * Interdomain account must already be created on remote PDC.
5609 * @param c A net_context structure.
5610 * @param argc Standard argc.
5611 * @param argv Standard argv without initial components.
5613 * @return Integer status (0 means success).
5616 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5619 struct cli_state
*cli
= NULL
;
5620 struct sockaddr_storage server_ss
;
5621 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5622 struct policy_handle connect_hnd
;
5623 TALLOC_CTX
*mem_ctx
;
5625 DOM_SID
*domain_sid
;
5630 union lsa_PolicyInformation
*info
= NULL
;
5633 * Connect to \\server\ipc$ as 'our domain' account with password
5636 if (argc
!= 1 || c
->display_usage
) {
5639 _("net rpc trustdom establish <domain_name>\n"));
5643 domain_name
= smb_xstrdup(argv
[0]);
5644 strupper_m(domain_name
);
5646 /* account name used at first is our domain's name with '$' */
5647 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5650 strupper_m(acct_name
);
5653 * opt_workgroup will be used by connection functions further,
5654 * hence it should be set to remote domain name instead of ours
5656 if (c
->opt_workgroup
) {
5657 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5660 c
->opt_user_name
= acct_name
;
5662 /* find the domain controller */
5663 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5664 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5668 /* connect to ipc$ as username/password */
5669 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5670 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5672 /* Is it trusting domain account for sure ? */
5673 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5674 nt_errstr(nt_status
)));
5678 /* store who we connected to */
5680 saf_store( domain_name
, pdc_name
);
5683 * Connect to \\server\ipc$ again (this time anonymously)
5686 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5689 if (NT_STATUS_IS_ERR(nt_status
)) {
5690 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5691 domain_name
, nt_errstr(nt_status
)));
5695 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5696 "domain %s", domain_name
))) {
5697 DEBUG(0, ("talloc_init() failed\n"));
5702 /* Make sure we're talking to a proper server */
5704 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5705 if (!NT_STATUS_IS_OK(nt_status
)) {
5707 talloc_destroy(mem_ctx
);
5712 * Call LsaOpenPolicy and LsaQueryInfo
5715 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5717 if (!NT_STATUS_IS_OK(nt_status
)) {
5718 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5720 talloc_destroy(mem_ctx
);
5724 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5726 if (NT_STATUS_IS_ERR(nt_status
)) {
5727 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5728 nt_errstr(nt_status
)));
5730 talloc_destroy(mem_ctx
);
5734 /* Querying info level 5 */
5736 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5738 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5740 if (NT_STATUS_IS_ERR(nt_status
)) {
5741 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5742 nt_errstr(nt_status
)));
5744 talloc_destroy(mem_ctx
);
5748 domain_sid
= info
->account_domain
.sid
;
5750 /* There should be actually query info level 3 (following nt serv behaviour),
5751 but I still don't know if it's _really_ necessary */
5754 * Store the password in secrets db
5757 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5758 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5760 talloc_destroy(mem_ctx
);
5765 * Close the pipes and clean up
5768 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5769 if (NT_STATUS_IS_ERR(nt_status
)) {
5770 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5771 nt_errstr(nt_status
)));
5773 talloc_destroy(mem_ctx
);
5779 talloc_destroy(mem_ctx
);
5781 d_printf(_("Trust to domain %s established\n"), domain_name
);
5786 * Revoke trust relationship to the remote domain.
5788 * @param c A net_context structure.
5789 * @param argc Standard argc.
5790 * @param argv Standard argv without initial components.
5792 * @return Integer status (0 means success).
5795 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5801 if (argc
< 1 || c
->display_usage
) {
5804 _("net rpc trustdom revoke <domain_name>\n"
5805 " Revoke trust relationship\n"
5806 " domain_name\tName of domain to revoke trust\n"));
5810 /* generate upper cased domain name */
5811 domain_name
= smb_xstrdup(argv
[0]);
5812 strupper_m(domain_name
);
5814 /* delete password of the trust */
5815 if (!pdb_del_trusteddom_pw(domain_name
)) {
5816 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5823 SAFE_FREE(domain_name
);
5827 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5828 const DOM_SID
*domain_sid
,
5829 const char *domain_name
,
5830 struct cli_state
*cli
,
5831 struct rpc_pipe_client
*pipe_hnd
,
5832 TALLOC_CTX
*mem_ctx
,
5837 if (!sid_to_fstring(str_sid
, domain_sid
)) {
5838 return NT_STATUS_UNSUCCESSFUL
;
5840 d_printf("%s\n", str_sid
);
5841 return NT_STATUS_OK
;
5844 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5848 /* convert sid into ascii string */
5849 sid_to_fstring(ascii_sid
, dom_sid
);
5851 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
5854 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5855 TALLOC_CTX
*mem_ctx
,
5856 struct policy_handle
*pol
,
5858 const char *trusted_dom_name
)
5861 union lsa_TrustedDomainInfo
*info
= NULL
;
5862 char *cleartextpwd
= NULL
;
5863 uint8_t session_key
[16];
5864 DATA_BLOB session_key_blob
;
5865 DATA_BLOB data
= data_blob_null
;
5867 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5870 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5872 if (NT_STATUS_IS_ERR(nt_status
)) {
5873 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5874 nt_errstr(nt_status
)));
5878 data
= data_blob(info
->password
.password
->data
,
5879 info
->password
.password
->length
);
5881 if (!rpccli_get_pwd_hash(pipe_hnd
, session_key
)) {
5882 DEBUG(0, ("Could not retrieve password hash\n"));
5886 session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
5887 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key_blob
);
5889 if (cleartextpwd
== NULL
) {
5890 DEBUG(0,("retrieved NULL password\n"));
5891 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5895 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5896 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5897 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5901 #ifdef DEBUG_PASSWORD
5902 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5903 "password: [%s]\n", trusted_dom_name
,
5904 sid_string_dbg(&dom_sid
), cleartextpwd
));
5908 SAFE_FREE(cleartextpwd
);
5909 data_blob_free(&data
);
5914 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5917 /* common variables */
5918 TALLOC_CTX
* mem_ctx
;
5919 struct cli_state
*cli
= NULL
;
5920 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5922 const char *domain_name
= NULL
;
5923 DOM_SID
*queried_dom_sid
;
5924 struct policy_handle connect_hnd
;
5925 union lsa_PolicyInformation
*info
= NULL
;
5927 /* trusted domains listing variables */
5928 unsigned int enum_ctx
= 0;
5930 struct lsa_DomainList dom_list
;
5933 if (c
->display_usage
) {
5935 "net rpc trustdom vampire\n"
5938 _("Vampire trust relationship from remote server"));
5943 * Listing trusted domains (stored in secrets.tdb, if local)
5946 mem_ctx
= talloc_init("trust relationships vampire");
5949 * set domain and pdc name to local samba server (default)
5950 * or to remote one given in command line
5953 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5954 domain_name
= c
->opt_workgroup
;
5955 c
->opt_target_workgroup
= c
->opt_workgroup
;
5957 fstrcpy(pdc_name
, global_myname());
5958 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5959 c
->opt_target_workgroup
= domain_name
;
5962 /* open \PIPE\lsarpc and open policy handle */
5963 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5964 if (!NT_STATUS_IS_OK(nt_status
)) {
5965 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5966 nt_errstr(nt_status
)));
5967 talloc_destroy(mem_ctx
);
5971 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5973 if (!NT_STATUS_IS_OK(nt_status
)) {
5974 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5975 nt_errstr(nt_status
) ));
5977 talloc_destroy(mem_ctx
);
5981 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5983 if (NT_STATUS_IS_ERR(nt_status
)) {
5984 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5985 nt_errstr(nt_status
)));
5987 talloc_destroy(mem_ctx
);
5991 /* query info level 5 to obtain sid of a domain being queried */
5992 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5994 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5997 if (NT_STATUS_IS_ERR(nt_status
)) {
5998 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5999 nt_errstr(nt_status
)));
6001 talloc_destroy(mem_ctx
);
6005 queried_dom_sid
= info
->account_domain
.sid
;
6008 * Keep calling LsaEnumTrustdom over opened pipe until
6009 * the end of enumeration is reached
6012 d_printf(_("Vampire trusted domains:\n\n"));
6015 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6020 if (NT_STATUS_IS_ERR(nt_status
)) {
6021 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6022 nt_errstr(nt_status
)));
6024 talloc_destroy(mem_ctx
);
6028 for (i
= 0; i
< dom_list
.count
; i
++) {
6030 print_trusted_domain(dom_list
.domains
[i
].sid
,
6031 dom_list
.domains
[i
].name
.string
);
6033 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6034 *dom_list
.domains
[i
].sid
,
6035 dom_list
.domains
[i
].name
.string
);
6036 if (!NT_STATUS_IS_OK(nt_status
)) {
6038 talloc_destroy(mem_ctx
);
6044 * in case of no trusted domains say something rather
6045 * than just display blank line
6047 if (!dom_list
.count
) d_printf(_("none\n"));
6049 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6051 /* close this connection before doing next one */
6052 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6053 if (NT_STATUS_IS_ERR(nt_status
)) {
6054 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6055 nt_errstr(nt_status
)));
6057 talloc_destroy(mem_ctx
);
6061 /* close lsarpc pipe and connection to IPC$ */
6064 talloc_destroy(mem_ctx
);
6068 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6070 /* common variables */
6071 TALLOC_CTX
* mem_ctx
;
6072 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6073 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6075 const char *domain_name
= NULL
;
6076 DOM_SID
*queried_dom_sid
;
6077 int ascii_dom_name_len
;
6078 struct policy_handle connect_hnd
;
6079 union lsa_PolicyInformation
*info
= NULL
;
6081 /* trusted domains listing variables */
6082 unsigned int num_domains
, enum_ctx
= 0;
6084 struct lsa_DomainList dom_list
;
6088 /* trusting domains listing variables */
6089 struct policy_handle domain_hnd
;
6090 struct samr_SamArray
*trusts
= NULL
;
6092 if (c
->display_usage
) {
6094 "net rpc trustdom list\n"
6097 _("List incoming and outgoing trust relationships"));
6102 * Listing trusted domains (stored in secrets.tdb, if local)
6105 mem_ctx
= talloc_init("trust relationships listing");
6108 * set domain and pdc name to local samba server (default)
6109 * or to remote one given in command line
6112 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6113 domain_name
= c
->opt_workgroup
;
6114 c
->opt_target_workgroup
= c
->opt_workgroup
;
6116 fstrcpy(pdc_name
, global_myname());
6117 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6118 c
->opt_target_workgroup
= domain_name
;
6121 /* open \PIPE\lsarpc and open policy handle */
6122 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6123 if (!NT_STATUS_IS_OK(nt_status
)) {
6124 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6125 nt_errstr(nt_status
)));
6126 talloc_destroy(mem_ctx
);
6130 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6132 if (!NT_STATUS_IS_OK(nt_status
)) {
6133 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6134 nt_errstr(nt_status
) ));
6136 talloc_destroy(mem_ctx
);
6140 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6142 if (NT_STATUS_IS_ERR(nt_status
)) {
6143 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6144 nt_errstr(nt_status
)));
6146 talloc_destroy(mem_ctx
);
6150 /* query info level 5 to obtain sid of a domain being queried */
6151 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6153 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6156 if (NT_STATUS_IS_ERR(nt_status
)) {
6157 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6158 nt_errstr(nt_status
)));
6160 talloc_destroy(mem_ctx
);
6164 queried_dom_sid
= info
->account_domain
.sid
;
6167 * Keep calling LsaEnumTrustdom over opened pipe until
6168 * the end of enumeration is reached
6171 d_printf(_("Trusted domains list:\n\n"));
6173 found_domain
= false;
6176 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6181 if (NT_STATUS_IS_ERR(nt_status
)) {
6182 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6183 nt_errstr(nt_status
)));
6185 talloc_destroy(mem_ctx
);
6189 for (i
= 0; i
< dom_list
.count
; i
++) {
6190 print_trusted_domain(dom_list
.domains
[i
].sid
,
6191 dom_list
.domains
[i
].name
.string
);
6192 found_domain
= true;
6196 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6199 * in case of no trusted domains say something rather
6200 * than just display blank line
6202 if (!found_domain
) {
6203 d_printf(_("none\n"));
6206 /* close this connection before doing next one */
6207 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6208 if (NT_STATUS_IS_ERR(nt_status
)) {
6209 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6210 nt_errstr(nt_status
)));
6212 talloc_destroy(mem_ctx
);
6216 TALLOC_FREE(pipe_hnd
);
6219 * Listing trusting domains (stored in passdb backend, if local)
6222 d_printf(_("\nTrusting domains list:\n\n"));
6225 * Open \PIPE\samr and get needed policy handles
6227 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6229 if (!NT_STATUS_IS_OK(nt_status
)) {
6230 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6232 talloc_destroy(mem_ctx
);
6237 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6239 SAMR_ACCESS_LOOKUP_DOMAIN
,
6241 if (!NT_STATUS_IS_OK(nt_status
)) {
6242 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6243 nt_errstr(nt_status
)));
6245 talloc_destroy(mem_ctx
);
6249 /* SamrOpenDomain - we have to open domain policy handle in order to be
6250 able to enumerate accounts*/
6251 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6253 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6256 if (!NT_STATUS_IS_OK(nt_status
)) {
6257 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6258 nt_errstr(nt_status
)));
6260 talloc_destroy(mem_ctx
);
6265 * perform actual enumeration
6268 found_domain
= false;
6270 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6273 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6280 if (NT_STATUS_IS_ERR(nt_status
)) {
6281 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6282 nt_errstr(nt_status
)));
6284 talloc_destroy(mem_ctx
);
6288 for (i
= 0; i
< num_domains
; i
++) {
6290 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6292 found_domain
= true;
6295 * get each single domain's sid (do we _really_ need this ?):
6296 * 1) connect to domain's pdc
6297 * 2) query the pdc for domain's sid
6300 /* get rid of '$' tail */
6301 ascii_dom_name_len
= strlen(str
);
6302 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6303 str
[ascii_dom_name_len
- 1] = '\0';
6305 /* set opt_* variables to remote domain */
6307 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6308 c
->opt_target_workgroup
= c
->opt_workgroup
;
6310 d_printf("%-20s", str
);
6312 /* connect to remote domain controller */
6313 nt_status
= net_make_ipc_connection(c
,
6314 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6316 if (NT_STATUS_IS_OK(nt_status
)) {
6317 /* query for domain's sid */
6318 if (run_rpc_command(
6320 &ndr_table_lsarpc
.syntax_id
, 0,
6321 rpc_query_domain_sid
, argc
,
6323 d_printf(_("strange - couldn't get domain's sid\n"));
6325 cli_shutdown(remote_cli
);
6328 d_fprintf(stderr
, _("domain controller is not "
6329 "responding: %s\n"),
6330 nt_errstr(nt_status
));
6331 d_printf(_("couldn't get domain's sid\n"));
6335 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6337 if (!found_domain
) {
6341 /* close opened samr and domain policy handles */
6342 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6343 if (!NT_STATUS_IS_OK(nt_status
)) {
6344 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6347 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6348 if (!NT_STATUS_IS_OK(nt_status
)) {
6349 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6352 /* close samr pipe and connection to IPC$ */
6355 talloc_destroy(mem_ctx
);
6360 * Entrypoint for 'net rpc trustdom' code.
6362 * @param argc Standard argc.
6363 * @param argv Standard argv without initial components.
6365 * @return Integer status (0 means success).
6368 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6370 struct functable func
[] = {
6375 N_("Add trusting domain's account"),
6376 N_("net rpc trustdom add\n"
6377 " Add trusting domain's account")
6383 N_("Remove trusting domain's account"),
6384 N_("net rpc trustdom del\n"
6385 " Remove trusting domain's account")
6389 rpc_trustdom_establish
,
6391 N_("Establish outgoing trust relationship"),
6392 N_("net rpc trustdom establish\n"
6393 " Establish outgoing trust relationship")
6397 rpc_trustdom_revoke
,
6399 N_("Revoke outgoing trust relationship"),
6400 N_("net rpc trustdom revoke\n"
6401 " Revoke outgoing trust relationship")
6407 N_("List in- and outgoing domain trusts"),
6408 N_("net rpc trustdom list\n"
6409 " List in- and outgoing domain trusts")
6413 rpc_trustdom_vampire
,
6415 N_("Vampire trusts from remote server"),
6416 N_("net rpc trustdom vampire\n"
6417 " Vampire trusts from remote server")
6419 {NULL
, NULL
, 0, NULL
, NULL
}
6422 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6426 * Check if a server will take rpc commands
6427 * @param flags Type of server to connect to (PDC, DMB, localhost)
6428 * if the host is not explicitly specified
6429 * @return bool (true means rpc supported)
6431 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6433 struct cli_state
*cli
;
6435 struct sockaddr_storage server_ss
;
6436 char *server_name
= NULL
;
6439 /* flags (i.e. server type) may depend on command */
6440 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6443 if ((cli
= cli_initialise()) == NULL
) {
6447 status
= cli_connect(cli
, server_name
, &server_ss
);
6448 if (!NT_STATUS_IS_OK(status
))
6450 if (!attempt_netbios_session_request(&cli
, global_myname(),
6451 server_name
, &server_ss
))
6453 status
= cli_negprot(cli
);
6454 if (!NT_STATUS_IS_OK(status
))
6456 if (cli
->protocol
< PROTOCOL_NT1
)
6465 /* dump sam database via samsync rpc calls */
6466 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6467 if (c
->display_usage
) {
6472 _("Dump remote SAM database"));
6476 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6477 NET_FLAGS_ANONYMOUS
,
6478 rpc_samdump_internals
, argc
, argv
);
6481 /* syncronise sam database via samsync rpc calls */
6482 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6484 struct functable func
[] = {
6489 N_("Dump remote SAM database to ldif"),
6490 N_("net rpc vampire ldif\n"
6491 " Dump remote SAM database to LDIF file or "
6498 N_("Dump remote SAM database to Kerberos Keytab"),
6499 N_("net rpc vampire keytab\n"
6500 " Dump remote SAM database to Kerberos keytab "
6507 N_("Dump remote SAM database to passdb"),
6508 N_("net rpc vampire passdb\n"
6509 " Dump remote SAM database to passdb")
6512 {NULL
, NULL
, 0, NULL
, NULL
}
6516 if (c
->display_usage
) {
6521 _("Vampire remote SAM database"));
6525 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6526 NET_FLAGS_ANONYMOUS
,
6527 rpc_vampire_internals
,
6531 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6535 * Migrate everything from a print server.
6537 * @param c A net_context structure.
6538 * @param argc Standard main() style argc.
6539 * @param argv Standard main() style argv. Initial components are already
6542 * @return A shell status integer (0 for success).
6544 * The order is important !
6545 * To successfully add drivers the print queues have to exist !
6546 * Applying ACLs should be the last step, because you're easily locked out.
6549 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6554 if (c
->display_usage
) {
6556 "net rpc printer migrate all\n"
6559 _("Migrate everything from a print server"));
6564 d_printf(_("no server to migrate\n"));
6568 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6569 rpc_printer_migrate_printers_internals
, argc
,
6574 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6575 rpc_printer_migrate_drivers_internals
, argc
,
6580 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6581 rpc_printer_migrate_forms_internals
, argc
, argv
);
6585 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6586 rpc_printer_migrate_settings_internals
, argc
,
6591 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6592 rpc_printer_migrate_security_internals
, argc
,
6598 * Migrate print drivers from a print server.
6600 * @param c A net_context structure.
6601 * @param argc Standard main() style argc.
6602 * @param argv Standard main() style argv. Initial components are already
6605 * @return A shell status integer (0 for success).
6607 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6610 if (c
->display_usage
) {
6612 "net rpc printer migrate drivers\n"
6615 _("Migrate print-drivers from a print-server"));
6620 d_printf(_("no server to migrate\n"));
6624 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6625 rpc_printer_migrate_drivers_internals
,
6630 * Migrate print-forms from a print-server.
6632 * @param c A net_context structure.
6633 * @param argc Standard main() style argc.
6634 * @param argv Standard main() style argv. Initial components are already
6637 * @return A shell status integer (0 for success).
6639 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6642 if (c
->display_usage
) {
6644 "net rpc printer migrate forms\n"
6647 _("Migrate print-forms from a print-server"));
6652 d_printf(_("no server to migrate\n"));
6656 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6657 rpc_printer_migrate_forms_internals
,
6662 * Migrate printers from a print-server.
6664 * @param c A net_context structure.
6665 * @param argc Standard main() style argc.
6666 * @param argv Standard main() style argv. Initial components are already
6669 * @return A shell status integer (0 for success).
6671 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6674 if (c
->display_usage
) {
6676 "net rpc printer migrate printers\n"
6679 _("Migrate printers from a print-server"));
6684 d_printf(_("no server to migrate\n"));
6688 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6689 rpc_printer_migrate_printers_internals
,
6694 * Migrate printer-ACLs from a print-server
6696 * @param c A net_context structure.
6697 * @param argc Standard main() style argc.
6698 * @param argv Standard main() style argv. Initial components are already
6701 * @return A shell status integer (0 for success).
6703 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6706 if (c
->display_usage
) {
6708 "net rpc printer migrate security\n"
6711 _("Migrate printer-ACLs from a print-server"));
6716 d_printf(_("no server to migrate\n"));
6720 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6721 rpc_printer_migrate_security_internals
,
6726 * Migrate printer-settings from a print-server.
6728 * @param c A net_context structure.
6729 * @param argc Standard main() style argc.
6730 * @param argv Standard main() style argv. Initial components are already
6733 * @return A shell status integer (0 for success).
6735 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6738 if (c
->display_usage
) {
6740 "net rpc printer migrate settings\n"
6743 _("Migrate printer-settings from a "
6749 d_printf(_("no server to migrate\n"));
6753 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6754 rpc_printer_migrate_settings_internals
,
6759 * 'net rpc printer' entrypoint.
6761 * @param c A net_context structure.
6762 * @param argc Standard main() style argc.
6763 * @param argv Standard main() style argv. Initial components are already
6767 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6770 /* ouch: when addriver and setdriver are called from within
6771 rpc_printer_migrate_drivers_internals, the printer-queue already
6774 struct functable func
[] = {
6777 rpc_printer_migrate_all
,
6779 N_("Migrate all from remote to local print server"),
6780 N_("net rpc printer migrate all\n"
6781 " Migrate all from remote to local print server")
6785 rpc_printer_migrate_drivers
,
6787 N_("Migrate drivers to local server"),
6788 N_("net rpc printer migrate drivers\n"
6789 " Migrate drivers to local server")
6793 rpc_printer_migrate_forms
,
6795 N_("Migrate froms to local server"),
6796 N_("net rpc printer migrate forms\n"
6797 " Migrate froms to local server")
6801 rpc_printer_migrate_printers
,
6803 N_("Migrate printers to local server"),
6804 N_("net rpc printer migrate printers\n"
6805 " Migrate printers to local server")
6809 rpc_printer_migrate_security
,
6811 N_("Mirgate printer ACLs to local server"),
6812 N_("net rpc printer migrate security\n"
6813 " Mirgate printer ACLs to local server")
6817 rpc_printer_migrate_settings
,
6819 N_("Migrate printer settings to local server"),
6820 N_("net rpc printer migrate settings\n"
6821 " Migrate printer settings to local server")
6823 {NULL
, NULL
, 0, NULL
, NULL
}
6826 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6831 * List printers on a remote RPC server.
6833 * @param c A net_context structure.
6834 * @param argc Standard main() style argc.
6835 * @param argv Standard main() style argv. Initial components are already
6838 * @return A shell status integer (0 for success).
6840 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6842 if (c
->display_usage
) {
6844 "net rpc printer list\n"
6847 _("List printers on a remote RPC server"));
6851 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6852 rpc_printer_list_internals
,
6857 * List printer-drivers on a remote RPC server.
6859 * @param c A net_context structure.
6860 * @param argc Standard main() style argc.
6861 * @param argv Standard main() style argv. Initial components are already
6864 * @return A shell status integer (0 for success).
6866 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6869 if (c
->display_usage
) {
6871 "net rpc printer driver\n"
6874 _("List printer-drivers on a remote RPC server"));
6878 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6879 rpc_printer_driver_list_internals
,
6884 * Publish printer in ADS via MSRPC.
6886 * @param c A net_context structure.
6887 * @param argc Standard main() style argc.
6888 * @param argv Standard main() style argv. Initial components are already
6891 * @return A shell status integer (0 for success).
6893 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6896 if (c
->display_usage
) {
6898 "net rpc printer publish publish\n"
6901 _("Publish printer in ADS via MSRPC"));
6905 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6906 rpc_printer_publish_publish_internals
,
6911 * Update printer in ADS via MSRPC.
6913 * @param c A net_context structure.
6914 * @param argc Standard main() style argc.
6915 * @param argv Standard main() style argv. Initial components are already
6918 * @return A shell status integer (0 for success).
6920 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6922 if (c
->display_usage
) {
6924 "net rpc printer publish update\n"
6927 _("Update printer in ADS via MSRPC"));
6931 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6932 rpc_printer_publish_update_internals
,
6937 * UnPublish printer in ADS via MSRPC.
6939 * @param c A net_context structure.
6940 * @param argc Standard main() style argc.
6941 * @param argv Standard main() style argv. Initial components are already
6944 * @return A shell status integer (0 for success).
6946 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6949 if (c
->display_usage
) {
6951 "net rpc printer publish unpublish\n"
6954 _("UnPublish printer in ADS via MSRPC"));
6958 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6959 rpc_printer_publish_unpublish_internals
,
6964 * List published printers via MSRPC.
6966 * @param c A net_context structure.
6967 * @param argc Standard main() style argc.
6968 * @param argv Standard main() style argv. Initial components are already
6971 * @return A shell status integer (0 for success).
6973 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6976 if (c
->display_usage
) {
6978 "net rpc printer publish list\n"
6981 _("List published printers via MSRPC"));
6985 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6986 rpc_printer_publish_list_internals
,
6992 * Publish printer in ADS.
6994 * @param c A net_context structure.
6995 * @param argc Standard main() style argc.
6996 * @param argv Standard main() style argv. Initial components are already
6999 * @return A shell status integer (0 for success).
7001 static int rpc_printer_publish(struct net_context
*c
, int argc
,
7005 struct functable func
[] = {
7008 rpc_printer_publish_publish
,
7010 N_("Publish printer in AD"),
7011 N_("net rpc printer publish publish\n"
7012 " Publish printer in AD")
7016 rpc_printer_publish_update
,
7018 N_("Update printer in AD"),
7019 N_("net rpc printer publish update\n"
7020 " Update printer in AD")
7024 rpc_printer_publish_unpublish
,
7026 N_("Unpublish printer"),
7027 N_("net rpc printer publish unpublish\n"
7028 " Unpublish printer")
7032 rpc_printer_publish_list
,
7034 N_("List published printers"),
7035 N_("net rpc printer publish list\n"
7036 " List published printers")
7038 {NULL
, NULL
, 0, NULL
, NULL
}
7042 if (c
->display_usage
) {
7043 d_printf(_("Usage:\n"));
7044 d_printf(_("net rpc printer publish\n"
7045 " List published printers\n"
7046 " Alias of net rpc printer publish "
7048 net_display_usage_from_functable(func
);
7051 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7052 rpc_printer_publish_list_internals
,
7056 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
7062 * Display rpc printer help page.
7064 * @param c A net_context structure.
7065 * @param argc Standard main() style argc.
7066 * @param argv Standard main() style argv. Initial components are already
7069 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
7071 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
7072 "\tlists all printers on print-server\n\n"));
7073 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7074 "\tlists all printer-drivers on print-server\n\n"));
7075 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7076 "\tpublishes printer settings in Active Directory\n"
7077 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
7078 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7079 "\n\tmigrates printers from remote to local server\n\n"));
7080 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7081 "\n\tmigrates printer-settings from remote to local server\n\n"));
7082 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7083 "\n\tmigrates printer-drivers from remote to local server\n\n"));
7084 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7085 "\n\tmigrates printer-forms from remote to local server\n\n"));
7086 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7087 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
7088 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7089 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7090 "\tremote to local print-server\n\n"));
7091 net_common_methods_usage(c
, argc
, argv
);
7092 net_common_flags_usage(c
, argc
, argv
);
7094 "\t-v or --verbose\t\t\tgive verbose output\n"
7095 "\t --destination\t\tmigration target server (default: localhost)\n"));
7101 * 'net rpc printer' entrypoint.
7103 * @param c A net_context structure.
7104 * @param argc Standard main() style argc.
7105 * @param argv Standard main() style argv. Initial components are already
7108 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
7110 struct functable func
[] = {
7115 N_("List all printers on print server"),
7116 N_("net rpc printer list\n"
7117 " List all printers on print server")
7121 rpc_printer_migrate
,
7123 N_("Migrate printer to local server"),
7124 N_("net rpc printer migrate\n"
7125 " Migrate printer to local server")
7129 rpc_printer_driver_list
,
7131 N_("List printer drivers"),
7132 N_("net rpc printer driver\n"
7133 " List printer drivers")
7137 rpc_printer_publish
,
7139 N_("Publish printer in AD"),
7140 N_("net rpc printer publish\n"
7141 " Publish printer in AD")
7143 {NULL
, NULL
, 0, NULL
, NULL
}
7147 if (c
->display_usage
) {
7148 d_printf(_("Usage:\n"));
7149 d_printf(_("net rpc printer\n"
7150 " List printers\n"));
7151 net_display_usage_from_functable(func
);
7154 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7155 rpc_printer_list_internals
,
7159 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7163 * 'net rpc' entrypoint.
7165 * @param c A net_context structure.
7166 * @param argc Standard main() style argc.
7167 * @param argv Standard main() style argv. Initial components are already
7171 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7173 NET_API_STATUS status
;
7175 struct functable func
[] = {
7180 N_("Modify global audit settings"),
7181 N_("net rpc audit\n"
7182 " Modify global audit settings")
7188 N_("Show basic info about a domain"),
7190 " Show basic info about a domain")
7196 N_("Join a domain"),
7204 N_("Join a domain created in server manager"),
7205 N_("net rpc oldjoin\n"
7206 " Join a domain created in server manager")
7212 N_("Test that a join is valid"),
7213 N_("net rpc testjoin\n"
7214 " Test that a join is valid")
7220 N_("List/modify users"),
7222 " List/modify users")
7228 N_("Change a user password"),
7229 N_("net rpc password\n"
7230 " Change a user password\n"
7231 " Alias for net rpc user password")
7237 N_("List/modify groups"),
7238 N_("net rpc group\n"
7239 " List/modify groups")
7245 N_("List/modify shares"),
7246 N_("net rpc share\n"
7247 " List/modify shares")
7253 N_("List open files"),
7261 N_("List/modify printers"),
7262 N_("net rpc printer\n"
7263 " List/modify printers")
7267 net_rpc_changetrustpw
,
7269 N_("Change trust account password"),
7270 N_("net rpc changetrustpw\n"
7271 " Change trust account password")
7277 N_("Modify domain trusts"),
7278 N_("net rpc trustdom\n"
7279 " Modify domain trusts")
7285 N_("Abort a remote shutdown"),
7286 N_("net rpc abortshutdown\n"
7287 " Abort a remote shutdown")
7293 N_("Shutdown a remote server"),
7294 N_("net rpc shutdown\n"
7295 " Shutdown a remote server")
7301 N_("Dump SAM data of remote NT PDC"),
7302 N_("net rpc samdump\n"
7303 " Dump SAM data of remote NT PDC")
7309 N_("Sync a remote NT PDC's data into local passdb"),
7310 N_("net rpc vampire\n"
7311 " Sync a remote NT PDC's data into local passdb")
7317 N_("Fetch the domain sid into local secrets.tdb"),
7318 N_("net rpc getsid\n"
7319 " Fetch the domain sid into local secrets.tdb")
7325 N_("Manage privileges assigned to SID"),
7326 N_("net rpc rights\n"
7327 " Manage privileges assigned to SID")
7333 N_("Start/stop/query remote services"),
7334 N_("net rpc service\n"
7335 " Start/stop/query remote services")
7341 N_("Manage registry hives"),
7342 N_("net rpc registry\n"
7343 " Manage registry hives")
7349 N_("Open interactive shell on remote server"),
7350 N_("net rpc shell\n"
7351 " Open interactive shell on remote server")
7353 {NULL
, NULL
, 0, NULL
, NULL
}
7356 status
= libnetapi_init(&c
->netapi_ctx
);
7360 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7361 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7362 if (c
->opt_kerberos
) {
7363 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7365 if (c
->opt_ccache
) {
7366 libnetapi_set_use_ccache(c
->netapi_ctx
);
7369 return net_run_function(c
, argc
, argv
, "net rpc", func
);