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
= talloc_strdup(c
, getpass(prompt
));
799 if (u1003
.usri1003_password
== NULL
) {
804 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
806 /* Display results */
809 _("Failed to set password for '%s' with error: %s.\n"),
810 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
819 * List a user's groups from a remote RPC server.
821 * @param argc Standard main() style argc.
822 * @param argv Standard main() style argv. Initial components are already
825 * @return A shell status integer (0 for success)
828 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
831 NET_API_STATUS status
;
832 struct GROUP_USERS_INFO_0
*u0
= NULL
;
833 uint32_t entries_read
= 0;
834 uint32_t total_entries
= 0;
838 if (argc
< 1 || c
->display_usage
) {
839 rpc_user_usage(c
, argc
, argv
);
843 status
= NetUserGetGroups(c
->opt_host
,
846 (uint8_t **)(void *)&u0
,
852 _("Failed to get groups for '%s' with error: %s.\n"),
853 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
858 for (i
=0; i
< entries_read
; i
++) {
859 printf("%s\n", u0
->grui0_name
);
867 * List users on a remote RPC server.
869 * All parameters are provided by the run_rpc_command function, except for
870 * argc, argv which are passed through.
872 * @param domain_sid The domain sid acquired from the remote server.
873 * @param cli A cli_state connected to the server.
874 * @param mem_ctx Talloc context, destroyed on completion of the function.
875 * @param argc Standard main() style argc.
876 * @param argv Standard main() style argv. Initial components are already
879 * @return Normal NTSTATUS return.
882 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
884 NET_API_STATUS status
;
885 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
886 struct NET_DISPLAY_USER
*info
= NULL
;
889 /* Query domain users */
890 if (c
->opt_long_list_entries
)
891 d_printf(_("\nUser name Comment"
892 "\n-----------------------------\n"));
894 uint32_t max_entries
, max_size
;
896 get_query_dispinfo_params(
897 loop_count
, &max_entries
, &max_size
);
899 status
= NetQueryDisplayInformation(c
->opt_host
,
906 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
910 info
= (struct NET_DISPLAY_USER
*)buffer
;
912 for (i
= 0; i
< num_entries
; i
++) {
914 if (c
->opt_long_list_entries
)
915 printf("%-21.21s %s\n", info
->usri1_name
,
916 info
->usri1_comment
);
918 printf("%s\n", info
->usri1_name
);
922 NetApiBufferFree(buffer
);
925 start_idx
+= num_entries
;
927 } while (status
== ERROR_MORE_DATA
);
933 * 'net rpc user' entrypoint.
934 * @param argc Standard main() style argc.
935 * @param argv Standard main() style argv. Initial components are already
939 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
941 NET_API_STATUS status
;
943 struct functable func
[] = {
948 N_("Add specified user"),
949 N_("net rpc user add\n"
950 " Add specified user")
956 N_("List domain groups of user"),
957 N_("net rpc user info\n"
958 " Lis domain groups of user")
964 N_("Remove specified user"),
965 N_("net rpc user delete\n"
966 " Remove specified user")
972 N_("Change user password"),
973 N_("net rpc user password\n"
974 " Change user password")
980 N_("Rename specified user"),
981 N_("net rpc user rename\n"
982 " Rename specified user")
984 {NULL
, NULL
, 0, NULL
, NULL
}
987 status
= libnetapi_init(&c
->netapi_ctx
);
991 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
992 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
993 if (c
->opt_kerberos
) {
994 libnetapi_set_use_kerberos(c
->netapi_ctx
);
998 if (c
->display_usage
) {
1003 _("List all users"));
1004 net_display_usage_from_functable(func
);
1008 return rpc_user_list(c
, argc
, argv
);
1011 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
1014 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
1015 TALLOC_CTX
*mem_ctx
,
1016 struct rpc_sh_ctx
*ctx
,
1017 struct rpc_pipe_client
*pipe_hnd
,
1018 int argc
, const char **argv
)
1020 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
1023 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
1024 TALLOC_CTX
*mem_ctx
,
1025 struct rpc_sh_ctx
*ctx
,
1026 struct rpc_pipe_client
*pipe_hnd
,
1027 int argc
, const char **argv
)
1029 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1032 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1033 TALLOC_CTX
*mem_ctx
,
1034 struct rpc_sh_ctx
*ctx
,
1035 struct rpc_pipe_client
*pipe_hnd
,
1036 int argc
, const char **argv
,
1038 struct net_context
*c
,
1039 TALLOC_CTX
*mem_ctx
,
1040 struct rpc_sh_ctx
*ctx
,
1041 struct rpc_pipe_client
*pipe_hnd
,
1042 struct policy_handle
*user_hnd
,
1043 int argc
, const char **argv
))
1045 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1046 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1049 enum lsa_SidType type
;
1052 d_fprintf(stderr
, "%s %s <username>\n", _("Usage:"),
1054 return NT_STATUS_INVALID_PARAMETER
;
1057 ZERO_STRUCT(connect_pol
);
1058 ZERO_STRUCT(domain_pol
);
1059 ZERO_STRUCT(user_pol
);
1061 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1062 argv
[0], NULL
, NULL
, &sid
, &type
);
1063 if (!NT_STATUS_IS_OK(result
)) {
1064 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1069 if (type
!= SID_NAME_USER
) {
1070 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1071 sid_type_lookup(type
));
1072 result
= NT_STATUS_NO_SUCH_USER
;
1076 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1077 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1078 result
= NT_STATUS_NO_SUCH_USER
;
1082 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1084 MAXIMUM_ALLOWED_ACCESS
,
1086 if (!NT_STATUS_IS_OK(result
)) {
1090 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1092 MAXIMUM_ALLOWED_ACCESS
,
1095 if (!NT_STATUS_IS_OK(result
)) {
1099 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1101 MAXIMUM_ALLOWED_ACCESS
,
1104 if (!NT_STATUS_IS_OK(result
)) {
1108 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1111 if (is_valid_policy_hnd(&user_pol
)) {
1112 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1114 if (is_valid_policy_hnd(&domain_pol
)) {
1115 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1117 if (is_valid_policy_hnd(&connect_pol
)) {
1118 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1123 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1124 TALLOC_CTX
*mem_ctx
,
1125 struct rpc_sh_ctx
*ctx
,
1126 struct rpc_pipe_client
*pipe_hnd
,
1127 struct policy_handle
*user_hnd
,
1128 int argc
, const char **argv
)
1131 union samr_UserInfo
*info
= NULL
;
1134 d_fprintf(stderr
, "%s %s show <username>\n", _("Usage:"),
1136 return NT_STATUS_INVALID_PARAMETER
;
1139 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1143 if (!NT_STATUS_IS_OK(result
)) {
1147 d_printf(_("user rid: %d, group rid: %d\n"),
1149 info
->info21
.primary_gid
);
1154 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1155 TALLOC_CTX
*mem_ctx
,
1156 struct rpc_sh_ctx
*ctx
,
1157 struct rpc_pipe_client
*pipe_hnd
,
1158 int argc
, const char **argv
)
1160 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1161 rpc_sh_user_show_internals
);
1164 #define FETCHSTR(name, rec) \
1165 do { if (strequal(ctx->thiscmd, name)) { \
1166 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1169 #define SETSTR(name, rec, flag) \
1170 do { if (strequal(ctx->thiscmd, name)) { \
1171 init_lsa_String(&(info->info21.rec), argv[0]); \
1172 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1175 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1176 TALLOC_CTX
*mem_ctx
,
1177 struct rpc_sh_ctx
*ctx
,
1178 struct rpc_pipe_client
*pipe_hnd
,
1179 struct policy_handle
*user_hnd
,
1180 int argc
, const char **argv
)
1183 const char *username
;
1184 const char *oldval
= "";
1185 union samr_UserInfo
*info
= NULL
;
1188 d_fprintf(stderr
, "%s %s <username> [new value|NULL]\n",
1189 _("Usage:"), ctx
->whoami
);
1190 return NT_STATUS_INVALID_PARAMETER
;
1193 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1197 if (!NT_STATUS_IS_OK(result
)) {
1201 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1203 FETCHSTR("fullname", full_name
);
1204 FETCHSTR("homedir", home_directory
);
1205 FETCHSTR("homedrive", home_drive
);
1206 FETCHSTR("logonscript", logon_script
);
1207 FETCHSTR("profilepath", profile_path
);
1208 FETCHSTR("description", description
);
1211 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1215 if (strcmp(argv
[0], "NULL") == 0) {
1219 ZERO_STRUCT(info
->info21
);
1221 SETSTR("fullname", full_name
, FULL_NAME
);
1222 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1223 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1224 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1225 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1226 SETSTR("description", description
, DESCRIPTION
);
1228 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1233 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1234 ctx
->thiscmd
, oldval
, argv
[0]);
1241 #define HANDLEFLG(name, rec) \
1242 do { if (strequal(ctx->thiscmd, name)) { \
1243 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1245 newflags = oldflags | ACB_##rec; \
1247 newflags = oldflags & ~ACB_##rec; \
1250 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1251 TALLOC_CTX
*mem_ctx
,
1252 struct rpc_sh_ctx
*ctx
,
1253 struct rpc_pipe_client
*pipe_hnd
,
1254 int argc
, const char **argv
)
1256 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1257 rpc_sh_user_str_edit_internals
);
1260 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1261 TALLOC_CTX
*mem_ctx
,
1262 struct rpc_sh_ctx
*ctx
,
1263 struct rpc_pipe_client
*pipe_hnd
,
1264 struct policy_handle
*user_hnd
,
1265 int argc
, const char **argv
)
1268 const char *username
;
1269 const char *oldval
= "unknown";
1270 uint32 oldflags
, newflags
;
1272 union samr_UserInfo
*info
= NULL
;
1275 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1276 !strequal(argv
[0], "no"))) {
1277 /* TRANSATORS: The yes|no here are program keywords. Please do
1279 d_fprintf(stderr
, _("Usage: %s <username> [yes|no]\n"),
1281 return NT_STATUS_INVALID_PARAMETER
;
1284 newval
= strequal(argv
[0], "yes");
1286 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1290 if (!NT_STATUS_IS_OK(result
)) {
1294 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1295 oldflags
= info
->info21
.acct_flags
;
1296 newflags
= info
->info21
.acct_flags
;
1298 HANDLEFLG("disabled", DISABLED
);
1299 HANDLEFLG("pwnotreq", PWNOTREQ
);
1300 HANDLEFLG("autolock", AUTOLOCK
);
1301 HANDLEFLG("pwnoexp", PWNOEXP
);
1304 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1309 ZERO_STRUCT(info
->info21
);
1311 info
->info21
.acct_flags
= newflags
;
1312 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1314 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1319 if (NT_STATUS_IS_OK(result
)) {
1320 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1321 ctx
->thiscmd
, oldval
, argv
[0]);
1329 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1330 TALLOC_CTX
*mem_ctx
,
1331 struct rpc_sh_ctx
*ctx
,
1332 struct rpc_pipe_client
*pipe_hnd
,
1333 int argc
, const char **argv
)
1335 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1336 rpc_sh_user_flag_edit_internals
);
1339 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1340 TALLOC_CTX
*mem_ctx
,
1341 struct rpc_sh_ctx
*ctx
)
1343 static struct rpc_sh_cmd cmds
[] = {
1345 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1346 N_("Show/Set a user's full name") },
1348 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1349 N_("Show/Set a user's home directory") },
1351 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1352 N_("Show/Set a user's home drive") },
1354 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1355 N_("Show/Set a user's logon script") },
1357 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1358 N_("Show/Set a user's profile path") },
1360 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1361 N_("Show/Set a user's description") },
1363 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1364 N_("Show/Set whether a user is disabled") },
1366 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1367 N_("Show/Set whether a user locked out") },
1369 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1370 N_("Show/Set whether a user does not need a password") },
1372 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1373 N_("Show/Set whether a user's password does not expire") },
1375 { NULL
, NULL
, 0, NULL
, NULL
}
1381 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1382 TALLOC_CTX
*mem_ctx
,
1383 struct rpc_sh_ctx
*ctx
)
1385 static struct rpc_sh_cmd cmds
[] = {
1387 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1388 N_("List available users") },
1390 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1391 N_("List the domain groups a user is member of") },
1393 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1394 N_("Show info about a user") },
1396 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1397 N_("Show/Modify a user's fields") },
1399 { NULL
, NULL
, 0, NULL
, NULL
}
1405 /****************************************************************************/
1408 * Basic usage function for 'net rpc group'.
1409 * @param argc Standard main() style argc.
1410 * @param argv Standard main() style argv. Initial components are already
1414 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1416 return net_group_usage(c
, argc
, argv
);
1420 * Delete group on a remote RPC server.
1422 * All parameters are provided by the run_rpc_command function, except for
1423 * argc, argv which are passed through.
1425 * @param domain_sid The domain sid acquired from the remote server.
1426 * @param cli A cli_state connected to the server.
1427 * @param mem_ctx Talloc context, destroyed on completion of the function.
1428 * @param argc Standard main() style argc.
1429 * @param argv Standard main() style argv. Initial components are already
1432 * @return Normal NTSTATUS return.
1435 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1436 const DOM_SID
*domain_sid
,
1437 const char *domain_name
,
1438 struct cli_state
*cli
,
1439 struct rpc_pipe_client
*pipe_hnd
,
1440 TALLOC_CTX
*mem_ctx
,
1444 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1445 bool group_is_primary
= false;
1446 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1448 struct samr_RidTypeArray
*rids
= NULL
;
1451 /* struct samr_RidWithAttribute *user_gids; */
1453 struct samr_Ids group_rids
, name_types
;
1454 struct lsa_String lsa_acct_name
;
1455 union samr_UserInfo
*info
= NULL
;
1457 if (argc
< 1 || c
->display_usage
) {
1458 rpc_group_usage(c
, argc
,argv
);
1459 return NT_STATUS_OK
; /* ok? */
1462 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1464 MAXIMUM_ALLOWED_ACCESS
,
1467 if (!NT_STATUS_IS_OK(result
)) {
1468 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1472 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1474 MAXIMUM_ALLOWED_ACCESS
,
1475 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1478 if (!NT_STATUS_IS_OK(result
)) {
1479 d_fprintf(stderr
, _("Request open_domain failed\n"));
1483 init_lsa_String(&lsa_acct_name
, argv
[0]);
1485 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1491 if (!NT_STATUS_IS_OK(result
)) {
1492 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1496 switch (name_types
.ids
[0])
1498 case SID_NAME_DOM_GRP
:
1499 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1501 MAXIMUM_ALLOWED_ACCESS
,
1504 if (!NT_STATUS_IS_OK(result
)) {
1505 d_fprintf(stderr
, _("Request open_group failed"));
1509 group_rid
= group_rids
.ids
[0];
1511 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1515 if (!NT_STATUS_IS_OK(result
)) {
1517 _("Unable to query group members of %s"),
1522 if (c
->opt_verbose
) {
1524 _("Domain Group %s (rid: %d) has %d members\n"),
1525 argv
[0],group_rid
, rids
->count
);
1528 /* Check if group is anyone's primary group */
1529 for (i
= 0; i
< rids
->count
; i
++)
1531 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1533 MAXIMUM_ALLOWED_ACCESS
,
1537 if (!NT_STATUS_IS_OK(result
)) {
1539 _("Unable to open group member %d\n"),
1544 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1549 if (!NT_STATUS_IS_OK(result
)) {
1551 _("Unable to lookup userinfo for group "
1557 if (info
->info21
.primary_gid
== group_rid
) {
1558 if (c
->opt_verbose
) {
1559 d_printf(_("Group is primary group "
1561 info
->info21
.account_name
.string
);
1563 group_is_primary
= true;
1566 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1569 if (group_is_primary
) {
1570 d_fprintf(stderr
, _("Unable to delete group because "
1571 "some of it's members have it as primary "
1573 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1577 /* remove all group members */
1578 for (i
= 0; i
< rids
->count
; i
++)
1581 d_printf(_("Remove group member %d..."),
1583 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1587 if (NT_STATUS_IS_OK(result
)) {
1589 d_printf(_("ok\n"));
1592 d_printf("%s\n", _("failed"));
1597 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1601 /* removing a local group is easier... */
1602 case SID_NAME_ALIAS
:
1603 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1605 MAXIMUM_ALLOWED_ACCESS
,
1609 if (!NT_STATUS_IS_OK(result
)) {
1610 d_fprintf(stderr
, _("Request open_alias failed\n"));
1614 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1618 d_fprintf(stderr
, _("%s is of type %s. This command is only "
1619 "for deleting local or global groups\n"),
1620 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1621 result
= NT_STATUS_UNSUCCESSFUL
;
1625 if (NT_STATUS_IS_OK(result
)) {
1627 d_printf(_("Deleted %s '%s'\n"),
1628 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
1630 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
1631 get_friendly_nt_error_msg(result
));
1639 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1641 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1642 rpc_group_delete_internals
, argc
,argv
);
1645 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1647 NET_API_STATUS status
;
1648 struct GROUP_INFO_1 info1
;
1649 uint32_t parm_error
= 0;
1651 if (argc
!= 1 || c
->display_usage
) {
1652 rpc_group_usage(c
, argc
, argv
);
1658 info1
.grpi1_name
= argv
[0];
1659 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1660 info1
.grpi1_comment
= c
->opt_comment
;
1663 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1667 _("Failed to add group '%s' with error: %s.\n"),
1668 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1672 d_printf(_("Added group '%s'.\n"), argv
[0]);
1678 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1680 NET_API_STATUS status
;
1681 struct LOCALGROUP_INFO_1 info1
;
1682 uint32_t parm_error
= 0;
1684 if (argc
!= 1 || c
->display_usage
) {
1685 rpc_group_usage(c
, argc
, argv
);
1691 info1
.lgrpi1_name
= argv
[0];
1692 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1693 info1
.lgrpi1_comment
= c
->opt_comment
;
1696 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1700 _("Failed to add alias '%s' with error: %s.\n"),
1701 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1705 d_printf(_("Added alias '%s'.\n"), argv
[0]);
1711 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1713 if (c
->opt_localgroup
)
1714 return rpc_alias_add_internals(c
, argc
, argv
);
1716 return rpc_group_add_internals(c
, argc
, argv
);
1719 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1720 TALLOC_CTX
*mem_ctx
,
1723 enum lsa_SidType
*type
)
1725 DOM_SID
*sids
= NULL
;
1726 enum lsa_SidType
*types
= NULL
;
1727 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1728 struct policy_handle lsa_pol
;
1729 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1731 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1733 if (!NT_STATUS_IS_OK(result
)) {
1737 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1738 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
1740 if (!NT_STATUS_IS_OK(result
)) {
1744 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1745 &name
, NULL
, 1, &sids
, &types
);
1747 if (NT_STATUS_IS_OK(result
)) {
1748 sid_copy(sid
, &sids
[0]);
1752 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1756 TALLOC_FREE(pipe_hnd
);
1759 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1761 /* Try as S-1-5-whatever */
1765 if (string_to_sid(&tmp_sid
, name
)) {
1766 sid_copy(sid
, &tmp_sid
);
1767 *type
= SID_NAME_UNKNOWN
;
1768 result
= NT_STATUS_OK
;
1775 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1776 TALLOC_CTX
*mem_ctx
,
1777 const DOM_SID
*group_sid
,
1780 struct policy_handle connect_pol
, domain_pol
;
1783 struct policy_handle group_pol
;
1785 struct samr_Ids rids
, rid_types
;
1786 struct lsa_String lsa_acct_name
;
1790 sid_copy(&sid
, group_sid
);
1792 if (!sid_split_rid(&sid
, &group_rid
)) {
1793 return NT_STATUS_UNSUCCESSFUL
;
1796 /* Get sam policy handle */
1797 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1799 MAXIMUM_ALLOWED_ACCESS
,
1801 if (!NT_STATUS_IS_OK(result
)) {
1805 /* Get domain policy handle */
1806 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1808 MAXIMUM_ALLOWED_ACCESS
,
1811 if (!NT_STATUS_IS_OK(result
)) {
1815 init_lsa_String(&lsa_acct_name
, member
);
1817 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1824 if (!NT_STATUS_IS_OK(result
)) {
1825 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1830 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1832 MAXIMUM_ALLOWED_ACCESS
,
1836 if (!NT_STATUS_IS_OK(result
)) {
1840 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1843 0x0005); /* unknown flags */
1846 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1850 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1851 TALLOC_CTX
*mem_ctx
,
1852 const DOM_SID
*alias_sid
,
1855 struct policy_handle connect_pol
, domain_pol
;
1858 struct policy_handle alias_pol
;
1861 enum lsa_SidType member_type
;
1865 sid_copy(&sid
, alias_sid
);
1867 if (!sid_split_rid(&sid
, &alias_rid
)) {
1868 return NT_STATUS_UNSUCCESSFUL
;
1871 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1872 member
, &member_sid
, &member_type
);
1874 if (!NT_STATUS_IS_OK(result
)) {
1875 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1880 /* Get sam policy handle */
1881 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1883 MAXIMUM_ALLOWED_ACCESS
,
1885 if (!NT_STATUS_IS_OK(result
)) {
1889 /* Get domain policy handle */
1890 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1892 MAXIMUM_ALLOWED_ACCESS
,
1895 if (!NT_STATUS_IS_OK(result
)) {
1899 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1901 MAXIMUM_ALLOWED_ACCESS
,
1905 if (!NT_STATUS_IS_OK(result
)) {
1909 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1913 if (!NT_STATUS_IS_OK(result
)) {
1918 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1922 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1923 const DOM_SID
*domain_sid
,
1924 const char *domain_name
,
1925 struct cli_state
*cli
,
1926 struct rpc_pipe_client
*pipe_hnd
,
1927 TALLOC_CTX
*mem_ctx
,
1932 enum lsa_SidType group_type
;
1934 if (argc
!= 2 || c
->display_usage
) {
1937 _("net rpc group addmem <group> <member>\n"
1938 " Add a member to a group\n"
1939 " group\tGroup to add member to\n"
1940 " member\tMember to add to group\n"));
1941 return NT_STATUS_UNSUCCESSFUL
;
1944 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1945 &group_sid
, &group_type
))) {
1946 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
1948 return NT_STATUS_UNSUCCESSFUL
;
1951 if (group_type
== SID_NAME_DOM_GRP
) {
1952 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1953 &group_sid
, argv
[1]);
1955 if (!NT_STATUS_IS_OK(result
)) {
1956 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1957 argv
[1], argv
[0], nt_errstr(result
));
1962 if (group_type
== SID_NAME_ALIAS
) {
1963 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1964 &group_sid
, argv
[1]);
1966 if (!NT_STATUS_IS_OK(result
)) {
1967 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1968 argv
[1], argv
[0], nt_errstr(result
));
1973 d_fprintf(stderr
, _("Can only add members to global or local groups "
1974 "which %s is not\n"), argv
[0]);
1976 return NT_STATUS_UNSUCCESSFUL
;
1979 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1981 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1982 rpc_group_addmem_internals
,
1986 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1987 struct rpc_pipe_client
*pipe_hnd
,
1988 TALLOC_CTX
*mem_ctx
,
1989 const DOM_SID
*group_sid
,
1992 struct policy_handle connect_pol
, domain_pol
;
1995 struct policy_handle group_pol
;
1997 struct samr_Ids rids
, rid_types
;
1998 struct lsa_String lsa_acct_name
;
2002 sid_copy(&sid
, group_sid
);
2004 if (!sid_split_rid(&sid
, &group_rid
))
2005 return NT_STATUS_UNSUCCESSFUL
;
2007 /* Get sam policy handle */
2008 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2010 MAXIMUM_ALLOWED_ACCESS
,
2012 if (!NT_STATUS_IS_OK(result
))
2015 /* Get domain policy handle */
2016 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2018 MAXIMUM_ALLOWED_ACCESS
,
2021 if (!NT_STATUS_IS_OK(result
))
2024 init_lsa_String(&lsa_acct_name
, member
);
2026 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2032 if (!NT_STATUS_IS_OK(result
)) {
2033 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2038 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2040 MAXIMUM_ALLOWED_ACCESS
,
2044 if (!NT_STATUS_IS_OK(result
))
2047 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2052 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2056 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2057 TALLOC_CTX
*mem_ctx
,
2058 const DOM_SID
*alias_sid
,
2061 struct policy_handle connect_pol
, domain_pol
;
2064 struct policy_handle alias_pol
;
2067 enum lsa_SidType member_type
;
2071 sid_copy(&sid
, alias_sid
);
2073 if (!sid_split_rid(&sid
, &alias_rid
))
2074 return NT_STATUS_UNSUCCESSFUL
;
2076 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2077 member
, &member_sid
, &member_type
);
2079 if (!NT_STATUS_IS_OK(result
)) {
2080 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2085 /* Get sam policy handle */
2086 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2088 MAXIMUM_ALLOWED_ACCESS
,
2090 if (!NT_STATUS_IS_OK(result
)) {
2094 /* Get domain policy handle */
2095 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2097 MAXIMUM_ALLOWED_ACCESS
,
2100 if (!NT_STATUS_IS_OK(result
)) {
2104 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2106 MAXIMUM_ALLOWED_ACCESS
,
2110 if (!NT_STATUS_IS_OK(result
))
2113 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2117 if (!NT_STATUS_IS_OK(result
))
2121 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2125 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2126 const DOM_SID
*domain_sid
,
2127 const char *domain_name
,
2128 struct cli_state
*cli
,
2129 struct rpc_pipe_client
*pipe_hnd
,
2130 TALLOC_CTX
*mem_ctx
,
2135 enum lsa_SidType group_type
;
2137 if (argc
!= 2 || c
->display_usage
) {
2140 _("net rpc group delmem <group> <member>\n"
2141 " Delete a member from a group\n"
2142 " group\tGroup to delete member from\n"
2143 " member\tMember to delete from group\n"));
2144 return NT_STATUS_UNSUCCESSFUL
;
2147 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2148 &group_sid
, &group_type
))) {
2149 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2151 return NT_STATUS_UNSUCCESSFUL
;
2154 if (group_type
== SID_NAME_DOM_GRP
) {
2155 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2156 &group_sid
, argv
[1]);
2158 if (!NT_STATUS_IS_OK(result
)) {
2159 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2160 argv
[1], argv
[0], nt_errstr(result
));
2165 if (group_type
== SID_NAME_ALIAS
) {
2166 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2167 &group_sid
, argv
[1]);
2169 if (!NT_STATUS_IS_OK(result
)) {
2170 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2171 argv
[1], argv
[0], nt_errstr(result
));
2176 d_fprintf(stderr
, _("Can only delete members from global or local "
2177 "groups which %s is not\n"), argv
[0]);
2179 return NT_STATUS_UNSUCCESSFUL
;
2182 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2184 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2185 rpc_group_delmem_internals
,
2190 * List groups on a remote RPC server.
2192 * All parameters are provided by the run_rpc_command function, except for
2193 * argc, argv which are passes through.
2195 * @param domain_sid The domain sid acquired from the remote server.
2196 * @param cli A cli_state connected to the server.
2197 * @param mem_ctx Talloc context, destroyed on completion of the function.
2198 * @param argc Standard main() style argc.
2199 * @param argv Standard main() style argv. Initial components are already
2202 * @return Normal NTSTATUS return.
2205 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2206 const DOM_SID
*domain_sid
,
2207 const char *domain_name
,
2208 struct cli_state
*cli
,
2209 struct rpc_pipe_client
*pipe_hnd
,
2210 TALLOC_CTX
*mem_ctx
,
2214 struct policy_handle connect_pol
, domain_pol
;
2215 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2216 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2217 struct samr_SamArray
*groups
= NULL
;
2218 bool global
= false;
2220 bool builtin
= false;
2222 if (c
->display_usage
) {
2225 _("net rpc group list [global] [local] [builtin]\n"
2226 " List groups on RPC server\n"
2227 " global\tList global groups\n"
2228 " local\tList local groups\n"
2229 " builtin\tList builtin groups\n"
2230 " If none of global, local or builtin is "
2231 "specified, all three options are considered "
2233 return NT_STATUS_OK
;
2242 for (i
=0; i
<argc
; i
++) {
2243 if (strequal(argv
[i
], "global"))
2246 if (strequal(argv
[i
], "local"))
2249 if (strequal(argv
[i
], "builtin"))
2253 /* Get sam policy handle */
2255 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2257 MAXIMUM_ALLOWED_ACCESS
,
2259 if (!NT_STATUS_IS_OK(result
)) {
2263 /* Get domain policy handle */
2265 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2267 MAXIMUM_ALLOWED_ACCESS
,
2268 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2270 if (!NT_STATUS_IS_OK(result
)) {
2274 /* Query domain groups */
2275 if (c
->opt_long_list_entries
)
2276 d_printf(_("\nGroup name Comment"
2277 "\n-----------------------------\n"));
2279 uint32_t max_size
, total_size
, returned_size
;
2280 union samr_DispInfo info
;
2284 get_query_dispinfo_params(
2285 loop_count
, &max_entries
, &max_size
);
2287 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2296 num_entries
= info
.info3
.count
;
2297 start_idx
+= info
.info3
.count
;
2299 if (!NT_STATUS_IS_OK(result
) &&
2300 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2303 for (i
= 0; i
< num_entries
; i
++) {
2305 const char *group
= NULL
;
2306 const char *desc
= NULL
;
2308 group
= info
.info3
.entries
[i
].account_name
.string
;
2309 desc
= info
.info3
.entries
[i
].description
.string
;
2311 if (c
->opt_long_list_entries
)
2312 printf("%-21.21s %-50.50s\n",
2315 printf("%s\n", group
);
2317 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2318 /* query domain aliases */
2323 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2329 if (!NT_STATUS_IS_OK(result
) &&
2330 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2333 for (i
= 0; i
< num_entries
; i
++) {
2335 const char *description
= NULL
;
2337 if (c
->opt_long_list_entries
) {
2339 struct policy_handle alias_pol
;
2340 union samr_AliasInfo
*info
= NULL
;
2342 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2345 groups
->entries
[i
].idx
,
2347 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2351 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2353 description
= info
->description
.string
;
2357 if (description
!= NULL
) {
2358 printf("%-21.21s %-50.50s\n",
2359 groups
->entries
[i
].name
.string
,
2362 printf("%s\n", groups
->entries
[i
].name
.string
);
2365 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2366 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2367 /* Get builtin policy handle */
2369 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2371 MAXIMUM_ALLOWED_ACCESS
,
2372 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2374 if (!NT_STATUS_IS_OK(result
)) {
2377 /* query builtin aliases */
2380 if (!builtin
) break;
2382 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2388 if (!NT_STATUS_IS_OK(result
) &&
2389 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2392 for (i
= 0; i
< num_entries
; i
++) {
2394 const char *description
= NULL
;
2396 if (c
->opt_long_list_entries
) {
2398 struct policy_handle alias_pol
;
2399 union samr_AliasInfo
*info
= NULL
;
2401 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2404 groups
->entries
[i
].idx
,
2406 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2410 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2412 description
= info
->description
.string
;
2416 if (description
!= NULL
) {
2417 printf("%-21.21s %-50.50s\n",
2418 groups
->entries
[i
].name
.string
,
2421 printf("%s\n", groups
->entries
[i
].name
.string
);
2424 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2430 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2432 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2433 rpc_group_list_internals
,
2437 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2438 struct rpc_pipe_client
*pipe_hnd
,
2439 TALLOC_CTX
*mem_ctx
,
2440 const char *domain_name
,
2441 const DOM_SID
*domain_sid
,
2442 struct policy_handle
*domain_pol
,
2446 struct policy_handle group_pol
;
2447 uint32 num_members
, *group_rids
;
2449 struct samr_RidTypeArray
*rids
= NULL
;
2450 struct lsa_Strings names
;
2451 struct samr_Ids types
;
2454 sid_to_fstring(sid_str
, domain_sid
);
2456 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2458 MAXIMUM_ALLOWED_ACCESS
,
2462 if (!NT_STATUS_IS_OK(result
))
2465 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2469 if (!NT_STATUS_IS_OK(result
))
2472 num_members
= rids
->count
;
2473 group_rids
= rids
->rids
;
2475 while (num_members
> 0) {
2476 int this_time
= 512;
2478 if (num_members
< this_time
)
2479 this_time
= num_members
;
2481 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2488 if (!NT_STATUS_IS_OK(result
))
2491 /* We only have users as members, but make the output
2492 the same as the output of alias members */
2494 for (i
= 0; i
< this_time
; i
++) {
2496 if (c
->opt_long_list_entries
) {
2497 printf("%s-%d %s\\%s %d\n", sid_str
,
2498 group_rids
[i
], domain_name
,
2499 names
.names
[i
].string
,
2502 printf("%s\\%s\n", domain_name
,
2503 names
.names
[i
].string
);
2507 num_members
-= this_time
;
2511 return NT_STATUS_OK
;
2514 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2515 struct rpc_pipe_client
*pipe_hnd
,
2516 TALLOC_CTX
*mem_ctx
,
2517 struct policy_handle
*domain_pol
,
2521 struct rpc_pipe_client
*lsa_pipe
;
2522 struct policy_handle alias_pol
, lsa_pol
;
2524 DOM_SID
*alias_sids
;
2527 enum lsa_SidType
*types
;
2529 struct lsa_SidArray sid_array
;
2531 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2533 MAXIMUM_ALLOWED_ACCESS
,
2537 if (!NT_STATUS_IS_OK(result
))
2540 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2544 if (!NT_STATUS_IS_OK(result
)) {
2545 d_fprintf(stderr
, _("Couldn't list alias members\n"));
2549 num_members
= sid_array
.num_sids
;
2551 if (num_members
== 0) {
2552 return NT_STATUS_OK
;
2555 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2556 &ndr_table_lsarpc
.syntax_id
,
2558 if (!NT_STATUS_IS_OK(result
)) {
2559 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
2560 nt_errstr(result
) );
2564 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2565 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2567 if (!NT_STATUS_IS_OK(result
)) {
2568 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
2569 TALLOC_FREE(lsa_pipe
);
2573 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2575 d_fprintf(stderr
, _("Out of memory\n"));
2576 TALLOC_FREE(lsa_pipe
);
2577 return NT_STATUS_NO_MEMORY
;
2580 for (i
=0; i
<num_members
; i
++) {
2581 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2584 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2585 num_members
, alias_sids
,
2586 &domains
, &names
, &types
);
2588 if (!NT_STATUS_IS_OK(result
) &&
2589 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2590 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
2591 TALLOC_FREE(lsa_pipe
);
2595 for (i
= 0; i
< num_members
; i
++) {
2597 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2599 if (c
->opt_long_list_entries
) {
2600 printf("%s %s\\%s %d\n", sid_str
,
2601 domains
[i
] ? domains
[i
] : _("*unknown*"),
2602 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
2605 printf("%s\\%s\n", domains
[i
], names
[i
]);
2607 printf("%s\n", sid_str
);
2611 TALLOC_FREE(lsa_pipe
);
2612 return NT_STATUS_OK
;
2615 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2616 const DOM_SID
*domain_sid
,
2617 const char *domain_name
,
2618 struct cli_state
*cli
,
2619 struct rpc_pipe_client
*pipe_hnd
,
2620 TALLOC_CTX
*mem_ctx
,
2625 struct policy_handle connect_pol
, domain_pol
;
2626 struct samr_Ids rids
, rid_types
;
2627 struct lsa_String lsa_acct_name
;
2629 /* Get sam policy handle */
2631 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2633 MAXIMUM_ALLOWED_ACCESS
,
2636 if (!NT_STATUS_IS_OK(result
))
2639 /* Get domain policy handle */
2641 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2643 MAXIMUM_ALLOWED_ACCESS
,
2644 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2647 if (!NT_STATUS_IS_OK(result
))
2650 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2652 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2659 if (!NT_STATUS_IS_OK(result
)) {
2661 /* Ok, did not find it in the global sam, try with builtin */
2663 DOM_SID sid_Builtin
;
2665 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2667 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2669 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2671 MAXIMUM_ALLOWED_ACCESS
,
2675 if (!NT_STATUS_IS_OK(result
)) {
2676 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2681 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2688 if (!NT_STATUS_IS_OK(result
)) {
2689 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2695 if (rids
.count
!= 1) {
2696 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2701 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2702 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2703 domain_sid
, &domain_pol
,
2707 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2708 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2712 return NT_STATUS_NO_SUCH_GROUP
;
2715 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2717 if (argc
!= 1 || c
->display_usage
) {
2718 return rpc_group_usage(c
, argc
, argv
);
2721 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2722 rpc_group_members_internals
,
2726 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2728 NET_API_STATUS status
;
2729 struct GROUP_INFO_0 g0
;
2733 d_printf(_("Usage:\n"));
2734 d_printf("net rpc group rename group newname\n");
2738 g0
.grpi0_name
= argv
[1];
2740 status
= NetGroupSetInfo(c
->opt_host
,
2747 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
2748 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2756 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2758 if (argc
!= 2 || c
->display_usage
) {
2759 return rpc_group_usage(c
, argc
, argv
);
2762 return rpc_group_rename_internals(c
, argc
, argv
);
2766 * 'net rpc group' entrypoint.
2767 * @param argc Standard main() style argc.
2768 * @param argv Standard main() style argv. Initial components are already
2772 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2774 NET_API_STATUS status
;
2776 struct functable func
[] = {
2781 N_("Create specified group"),
2782 N_("net rpc group add\n"
2783 " Create specified group")
2789 N_("Delete specified group"),
2790 N_("net rpc group delete\n"
2791 " Delete specified group")
2797 N_("Add member to group"),
2798 N_("net rpc group addmem\n"
2799 " Add member to group")
2805 N_("Remove member from group"),
2806 N_("net rpc group delmem\n"
2807 " Remove member from group")
2814 N_("net rpc group list\n"
2821 N_("List group members"),
2822 N_("net rpc group members\n"
2823 " List group members")
2830 N_("net rpc group rename\n"
2833 {NULL
, NULL
, 0, NULL
, NULL
}
2836 status
= libnetapi_init(&c
->netapi_ctx
);
2840 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2841 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2842 if (c
->opt_kerberos
) {
2843 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2847 if (c
->display_usage
) {
2848 d_printf(_("Usage:\n"));
2849 d_printf(_("net rpc group\n"
2850 " Alias for net rpc group list global "
2851 "local builtin\n"));
2852 net_display_usage_from_functable(func
);
2856 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2857 rpc_group_list_internals
,
2861 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2864 /****************************************************************************/
2866 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2868 return net_share_usage(c
, argc
, argv
);
2872 * Add a share on a remote RPC server.
2874 * @param argc Standard main() style argc.
2875 * @param argv Standard main() style argv. Initial components are already
2878 * @return A shell status integer (0 for success).
2881 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2883 NET_API_STATUS status
;
2886 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2887 uint32 num_users
=0, perms
=0;
2888 char *password
=NULL
; /* don't allow a share password */
2889 struct SHARE_INFO_2 i2
;
2890 uint32_t parm_error
= 0;
2892 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2893 return rpc_share_usage(c
, argc
, argv
);
2896 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2900 path
= strchr(sharename
, '=');
2907 i2
.shi2_netname
= sharename
;
2908 i2
.shi2_type
= type
;
2909 i2
.shi2_remark
= c
->opt_comment
;
2910 i2
.shi2_permissions
= perms
;
2911 i2
.shi2_max_uses
= c
->opt_maxusers
;
2912 i2
.shi2_current_uses
= num_users
;
2913 i2
.shi2_path
= path
;
2914 i2
.shi2_passwd
= password
;
2916 status
= NetShareAdd(c
->opt_host
,
2921 printf(_("NetShareAdd failed with: %s\n"),
2922 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2929 * Delete a share on a remote RPC server.
2931 * @param domain_sid The domain sid acquired from the remote server.
2932 * @param argc Standard main() style argc.
2933 * @param argv Standard main() style argv. Initial components are already
2936 * @return A shell status integer (0 for success).
2938 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2940 if (argc
< 1 || c
->display_usage
) {
2941 return rpc_share_usage(c
, argc
, argv
);
2944 return NetShareDel(c
->opt_host
, argv
[0], 0);
2948 * Formatted print of share info
2950 * @param r pointer to SHARE_INFO_1 to format
2953 static void display_share_info_1(struct net_context
*c
,
2954 struct SHARE_INFO_1
*r
)
2956 if (c
->opt_long_list_entries
) {
2957 d_printf("%-12s %-8.8s %-50s\n",
2959 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2962 d_printf("%s\n", r
->shi1_netname
);
2966 static WERROR
get_share_info(struct net_context
*c
,
2967 struct rpc_pipe_client
*pipe_hnd
,
2968 TALLOC_CTX
*mem_ctx
,
2972 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2976 union srvsvc_NetShareInfo info
;
2978 /* no specific share requested, enumerate all */
2981 uint32_t preferred_len
= 0xffffffff;
2982 uint32_t total_entries
= 0;
2983 uint32_t resume_handle
= 0;
2985 info_ctr
->level
= level
;
2987 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2997 /* request just one share */
2998 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
3005 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
3010 ZERO_STRUCTP(info_ctr
);
3012 info_ctr
->level
= level
;
3017 struct srvsvc_NetShareCtr1
*ctr1
;
3019 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
3020 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3023 ctr1
->array
= info
.info1
;
3025 info_ctr
->ctr
.ctr1
= ctr1
;
3029 struct srvsvc_NetShareCtr2
*ctr2
;
3031 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
3032 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3035 ctr2
->array
= info
.info2
;
3037 info_ctr
->ctr
.ctr2
= ctr2
;
3041 struct srvsvc_NetShareCtr502
*ctr502
;
3043 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3044 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3047 ctr502
->array
= info
.info502
;
3049 info_ctr
->ctr
.ctr502
= ctr502
;
3057 * 'net rpc share list' entrypoint.
3058 * @param argc Standard main() style argc.
3059 * @param argv Standard main() style argv. Initial components are already
3062 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3064 NET_API_STATUS status
;
3065 struct SHARE_INFO_1
*i1
= NULL
;
3066 uint32_t entries_read
= 0;
3067 uint32_t total_entries
= 0;
3068 uint32_t resume_handle
= 0;
3069 uint32_t i
, level
= 1;
3071 if (c
->display_usage
) {
3073 "net rpc share list\n"
3076 _("List shares on remote server"));
3080 status
= NetShareEnum(c
->opt_host
,
3082 (uint8_t **)(void *)&i1
,
3091 /* Display results */
3093 if (c
->opt_long_list_entries
) {
3095 "\nEnumerating shared resources (exports) on remote server:\n\n"
3096 "\nShare name Type Description\n"
3097 "---------- ---- -----------\n"));
3099 for (i
= 0; i
< entries_read
; i
++)
3100 display_share_info_1(c
, &i1
[i
]);
3105 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3107 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3108 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3118 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3119 const char *netname
, uint32 type
)
3121 /* only support disk shares */
3122 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3123 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3128 /* skip builtin shares */
3129 /* FIXME: should print$ be added too ? */
3130 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3131 strequal(netname
,"global"))
3134 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3135 printf(_("excluding [%s]\n"), netname
);
3139 return check_share_availability(cli
, netname
);
3143 * Migrate shares from a remote RPC server to the local RPC server.
3145 * All parameters are provided by the run_rpc_command function, except for
3146 * argc, argv which are passed through.
3148 * @param domain_sid The domain sid acquired from the remote server.
3149 * @param cli A cli_state connected to the server.
3150 * @param mem_ctx Talloc context, destroyed on completion of the function.
3151 * @param argc Standard main() style argc.
3152 * @param argv Standard main() style argv. Initial components are already
3155 * @return Normal NTSTATUS return.
3158 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3159 const DOM_SID
*domain_sid
,
3160 const char *domain_name
,
3161 struct cli_state
*cli
,
3162 struct rpc_pipe_client
*pipe_hnd
,
3163 TALLOC_CTX
*mem_ctx
,
3168 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3169 struct srvsvc_NetShareInfoCtr ctr_src
;
3171 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3172 struct cli_state
*cli_dst
= NULL
;
3173 uint32 level
= 502; /* includes secdesc */
3174 uint32_t parm_error
= 0;
3176 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3178 if (!W_ERROR_IS_OK(result
))
3181 /* connect destination PI_SRVSVC */
3182 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3183 &ndr_table_srvsvc
.syntax_id
);
3184 if (!NT_STATUS_IS_OK(nt_status
))
3188 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3190 union srvsvc_NetShareInfo info
;
3191 struct srvsvc_NetShareInfo502 info502
=
3192 ctr_src
.ctr
.ctr502
->array
[i
];
3194 /* reset error-code */
3195 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3197 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3200 /* finally add the share on the dst server */
3202 printf(_("migrating: [%s], path: %s, comment: %s, without "
3204 info502
.name
, info502
.path
, info502
.comment
);
3206 info
.info502
= &info502
;
3208 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3209 srvsvc_pipe
->desthost
,
3215 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3216 printf(_(" [%s] does already exist\n"),
3221 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3222 printf(_("cannot add share: %s\n"), win_errstr(result
));
3228 nt_status
= NT_STATUS_OK
;
3232 cli_shutdown(cli_dst
);
3240 * Migrate shares from a RPC server to another.
3242 * @param argc Standard main() style argc.
3243 * @param argv Standard main() style argv. Initial components are already
3246 * @return A shell status integer (0 for success).
3248 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3251 if (c
->display_usage
) {
3253 "net rpc share migrate shares\n"
3256 _("Migrate shares to local server"));
3261 printf(_("no server to migrate\n"));
3265 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3266 rpc_share_migrate_shares_internals
,
3273 * @param f file_info
3274 * @param mask current search mask
3275 * @param state arg-pointer
3278 static void copy_fn(const char *mnt
, file_info
*f
,
3279 const char *mask
, void *state
)
3281 static NTSTATUS nt_status
;
3282 static struct copy_clistate
*local_state
;
3283 static fstring filename
, new_mask
;
3286 struct net_context
*c
;
3288 local_state
= (struct copy_clistate
*)state
;
3289 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3293 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3296 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3299 if (f
->mode
& aDIR
) {
3301 DEBUG(3,("got dir: %s\n", f
->name
));
3303 fstrcpy(dir
, local_state
->cwd
);
3305 fstrcat(dir
, f
->name
);
3307 switch (net_mode_share
)
3309 case NET_MODE_SHARE_MIGRATE
:
3310 /* create that directory */
3311 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3312 local_state
->cli_share_src
,
3313 local_state
->cli_share_dst
,
3315 c
->opt_acls
? true : false,
3316 c
->opt_attrs
? true : false,
3317 c
->opt_timestamps
? true:false,
3321 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3325 if (!NT_STATUS_IS_OK(nt_status
))
3326 printf(_("could not handle dir %s: %s\n"),
3327 dir
, nt_errstr(nt_status
));
3329 /* search below that directory */
3330 fstrcpy(new_mask
, dir
);
3331 fstrcat(new_mask
, "\\*");
3333 old_dir
= local_state
->cwd
;
3334 local_state
->cwd
= dir
;
3335 if (!sync_files(local_state
, new_mask
))
3336 printf(_("could not handle files\n"));
3337 local_state
->cwd
= old_dir
;
3344 fstrcpy(filename
, local_state
->cwd
);
3345 fstrcat(filename
, "\\");
3346 fstrcat(filename
, f
->name
);
3348 DEBUG(3,("got file: %s\n", filename
));
3350 switch (net_mode_share
)
3352 case NET_MODE_SHARE_MIGRATE
:
3353 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3354 local_state
->cli_share_src
,
3355 local_state
->cli_share_dst
,
3357 c
->opt_acls
? true : false,
3358 c
->opt_attrs
? true : false,
3359 c
->opt_timestamps
? true: false,
3363 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
3368 if (!NT_STATUS_IS_OK(nt_status
))
3369 printf(_("could not handle file %s: %s\n"),
3370 filename
, nt_errstr(nt_status
));
3375 * sync files, can be called recursivly to list files
3376 * and then call copy_fn for each file
3378 * @param cp_clistate pointer to the copy_clistate we work with
3379 * @param mask the current search mask
3381 * @return Boolean result
3383 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3385 struct cli_state
*targetcli
;
3386 char *targetpath
= NULL
;
3388 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3390 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3391 mask
, &targetcli
, &targetpath
) ) {
3392 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
3394 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3398 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3399 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
3400 mask
, cli_errstr(targetcli
));
3409 * Set the top level directory permissions before we do any further copies.
3410 * Should set up ACL inheritance.
3413 bool copy_top_level_perms(struct net_context
*c
,
3414 struct copy_clistate
*cp_clistate
,
3415 const char *sharename
)
3417 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3419 switch (net_mode_share
) {
3420 case NET_MODE_SHARE_MIGRATE
:
3421 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3422 nt_status
= net_copy_fileattr(c
,
3423 cp_clistate
->mem_ctx
,
3424 cp_clistate
->cli_share_src
,
3425 cp_clistate
->cli_share_dst
,
3427 c
->opt_acls
? true : false,
3428 c
->opt_attrs
? true : false,
3429 c
->opt_timestamps
? true: false,
3433 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3437 if (!NT_STATUS_IS_OK(nt_status
)) {
3438 printf(_("Could handle directory attributes for top level "
3439 "directory of share %s. Error %s\n"),
3440 sharename
, nt_errstr(nt_status
));
3448 * Sync all files inside a remote share to another share (over smb).
3450 * All parameters are provided by the run_rpc_command function, except for
3451 * argc, argv which are passed through.
3453 * @param domain_sid The domain sid acquired from the remote server.
3454 * @param cli A cli_state connected to the server.
3455 * @param mem_ctx Talloc context, destroyed on completion of the function.
3456 * @param argc Standard main() style argc.
3457 * @param argv Standard main() style argv. Initial components are already
3460 * @return Normal NTSTATUS return.
3463 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3464 const DOM_SID
*domain_sid
,
3465 const char *domain_name
,
3466 struct cli_state
*cli
,
3467 struct rpc_pipe_client
*pipe_hnd
,
3468 TALLOC_CTX
*mem_ctx
,
3473 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3474 struct srvsvc_NetShareInfoCtr ctr_src
;
3477 struct copy_clistate cp_clistate
;
3478 bool got_src_share
= false;
3479 bool got_dst_share
= false;
3480 const char *mask
= "\\*";
3483 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3485 nt_status
= NT_STATUS_NO_MEMORY
;
3489 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3492 if (!W_ERROR_IS_OK(result
))
3495 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3497 struct srvsvc_NetShareInfo502 info502
=
3498 ctr_src
.ctr
.ctr502
->array
[i
];
3500 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3503 /* one might not want to mirror whole discs :) */
3504 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3505 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3510 switch (net_mode_share
)
3512 case NET_MODE_SHARE_MIGRATE
:
3516 d_fprintf(stderr
, _("Unsupported mode %d\n"),
3520 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3523 c
->opt_acls
? _("including") : _("without"),
3524 c
->opt_attrs
? _("including") : _("without"),
3525 c
->opt_timestamps
? _("(preserving timestamps)") : "");
3527 cp_clistate
.mem_ctx
= mem_ctx
;
3528 cp_clistate
.cli_share_src
= NULL
;
3529 cp_clistate
.cli_share_dst
= NULL
;
3530 cp_clistate
.cwd
= NULL
;
3531 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3534 /* open share source */
3535 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3536 &cli
->dest_ss
, cli
->desthost
,
3537 info502
.name
, "A:");
3538 if (!NT_STATUS_IS_OK(nt_status
))
3541 got_src_share
= true;
3543 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3544 /* open share destination */
3545 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3546 NULL
, dst
, info502
.name
, "A:");
3547 if (!NT_STATUS_IS_OK(nt_status
))
3550 got_dst_share
= true;
3553 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3554 d_fprintf(stderr
, _("Could not handle the top level "
3555 "directory permissions for the "
3556 "share: %s\n"), info502
.name
);
3557 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3561 if (!sync_files(&cp_clistate
, mask
)) {
3562 d_fprintf(stderr
, _("could not handle files for share: "
3563 "%s\n"), info502
.name
);
3564 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3569 nt_status
= NT_STATUS_OK
;
3574 cli_shutdown(cp_clistate
.cli_share_src
);
3577 cli_shutdown(cp_clistate
.cli_share_dst
);
3584 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3586 if (c
->display_usage
) {
3588 "net share migrate files\n"
3591 _("Migrate files to local server"));
3596 d_printf(_("no server to migrate\n"));
3600 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3601 rpc_share_migrate_files_internals
,
3606 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3608 * All parameters are provided by the run_rpc_command function, except for
3609 * argc, argv which are passed through.
3611 * @param domain_sid The domain sid acquired from the remote server.
3612 * @param cli A cli_state connected to the server.
3613 * @param mem_ctx Talloc context, destroyed on completion of the function.
3614 * @param argc Standard main() style argc.
3615 * @param argv Standard main() style argv. Initial components are already
3618 * @return Normal NTSTATUS return.
3621 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3622 const DOM_SID
*domain_sid
,
3623 const char *domain_name
,
3624 struct cli_state
*cli
,
3625 struct rpc_pipe_client
*pipe_hnd
,
3626 TALLOC_CTX
*mem_ctx
,
3631 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3632 struct srvsvc_NetShareInfoCtr ctr_src
;
3633 union srvsvc_NetShareInfo info
;
3635 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3636 struct cli_state
*cli_dst
= NULL
;
3637 uint32 level
= 502; /* includes secdesc */
3638 uint32_t parm_error
= 0;
3640 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3643 if (!W_ERROR_IS_OK(result
))
3646 /* connect destination PI_SRVSVC */
3647 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3648 &ndr_table_srvsvc
.syntax_id
);
3649 if (!NT_STATUS_IS_OK(nt_status
))
3653 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3655 struct srvsvc_NetShareInfo502 info502
=
3656 ctr_src
.ctr
.ctr502
->array
[i
];
3658 /* reset error-code */
3659 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3661 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3664 printf(_("migrating: [%s], path: %s, comment: %s, including "
3666 info502
.name
, info502
.path
, info502
.comment
);
3669 display_sec_desc(info502
.sd_buf
.sd
);
3671 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3672 info
.info502
= &info502
;
3674 /* finally modify the share on the dst server */
3675 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3676 srvsvc_pipe
->desthost
,
3682 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3683 printf(_("cannot set share-acl: %s\n"),
3684 win_errstr(result
));
3690 nt_status
= NT_STATUS_OK
;
3694 cli_shutdown(cli_dst
);
3702 * Migrate share-acls from a RPC server to another.
3704 * @param argc Standard main() style argc.
3705 * @param argv Standard main() style argv. Initial components are already
3708 * @return A shell status integer (0 for success).
3710 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3713 if (c
->display_usage
) {
3715 "net rpc share migrate security\n"
3718 _("Migrate share-acls to local server"));
3723 d_printf(_("no server to migrate\n"));
3727 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3728 rpc_share_migrate_security_internals
,
3733 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3734 * from one server to another.
3736 * @param argc Standard main() style argc.
3737 * @param argv Standard main() style argv. Initial components are already
3740 * @return A shell status integer (0 for success).
3743 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3748 if (c
->display_usage
) {
3750 "net rpc share migrate all\n"
3753 _("Migrates shares including all share settings"));
3758 d_printf(_("no server to migrate\n"));
3762 /* order is important. we don't want to be locked out by the share-acl
3763 * before copying files - gd */
3765 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3766 rpc_share_migrate_shares_internals
, argc
, argv
);
3770 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3771 rpc_share_migrate_files_internals
, argc
, argv
);
3775 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3776 rpc_share_migrate_security_internals
, argc
,
3782 * 'net rpc share migrate' entrypoint.
3783 * @param argc Standard main() style argc.
3784 * @param argv Standard main() style argv. Initial components are already
3787 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3790 struct functable func
[] = {
3793 rpc_share_migrate_all
,
3795 N_("Migrate shares from remote to local server"),
3796 N_("net rpc share migrate all\n"
3797 " Migrate shares from remote to local server")
3801 rpc_share_migrate_files
,
3803 N_("Migrate files from remote to local server"),
3804 N_("net rpc share migrate files\n"
3805 " Migrate files from remote to local server")
3809 rpc_share_migrate_security
,
3811 N_("Migrate share-ACLs from remote to local server"),
3812 N_("net rpc share migrate security\n"
3813 " Migrate share-ACLs from remote to local server")
3817 rpc_share_migrate_shares
,
3819 N_("Migrate shares from remote to local server"),
3820 N_("net rpc share migrate shares\n"
3821 " Migrate shares from remote to local server")
3823 {NULL
, NULL
, 0, NULL
, NULL
}
3826 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3828 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3837 static int num_server_aliases
;
3838 static struct full_alias
*server_aliases
;
3841 * Add an alias to the static list.
3843 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3845 if (server_aliases
== NULL
)
3846 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3848 server_aliases
[num_server_aliases
] = *alias
;
3849 num_server_aliases
+= 1;
3853 * For a specific domain on the server, fetch all the aliases
3854 * and their members. Add all of them to the server_aliases.
3857 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3858 TALLOC_CTX
*mem_ctx
,
3859 struct policy_handle
*connect_pol
,
3860 const DOM_SID
*domain_sid
)
3862 uint32 start_idx
, max_entries
, num_entries
, i
;
3863 struct samr_SamArray
*groups
= NULL
;
3865 struct policy_handle domain_pol
;
3867 /* Get domain policy handle */
3869 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3871 MAXIMUM_ALLOWED_ACCESS
,
3872 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3874 if (!NT_STATUS_IS_OK(result
))
3881 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3887 for (i
= 0; i
< num_entries
; i
++) {
3889 struct policy_handle alias_pol
;
3890 struct full_alias alias
;
3891 struct lsa_SidArray sid_array
;
3894 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3896 MAXIMUM_ALLOWED_ACCESS
,
3897 groups
->entries
[i
].idx
,
3899 if (!NT_STATUS_IS_OK(result
))
3902 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3905 if (!NT_STATUS_IS_OK(result
))
3908 alias
.num_members
= sid_array
.num_sids
;
3910 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3911 if (!NT_STATUS_IS_OK(result
))
3914 alias
.members
= NULL
;
3916 if (alias
.num_members
> 0) {
3917 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3919 for (j
= 0; j
< alias
.num_members
; j
++)
3920 sid_copy(&alias
.members
[j
],
3921 sid_array
.sids
[j
].sid
);
3924 sid_copy(&alias
.sid
, domain_sid
);
3925 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3927 push_alias(mem_ctx
, &alias
);
3929 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3931 result
= NT_STATUS_OK
;
3934 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3940 * Dump server_aliases as names for debugging purposes.
3943 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3944 const DOM_SID
*domain_sid
,
3945 const char *domain_name
,
3946 struct cli_state
*cli
,
3947 struct rpc_pipe_client
*pipe_hnd
,
3948 TALLOC_CTX
*mem_ctx
,
3954 struct policy_handle lsa_pol
;
3956 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3957 SEC_FLAG_MAXIMUM_ALLOWED
,
3959 if (!NT_STATUS_IS_OK(result
))
3962 for (i
=0; i
<num_server_aliases
; i
++) {
3965 enum lsa_SidType
*types
;
3968 struct full_alias
*alias
= &server_aliases
[i
];
3970 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3972 &domains
, &names
, &types
);
3973 if (!NT_STATUS_IS_OK(result
))
3976 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3978 if (alias
->num_members
== 0) {
3983 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3986 &domains
, &names
, &types
);
3988 if (!NT_STATUS_IS_OK(result
) &&
3989 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3992 for (j
=0; j
<alias
->num_members
; j
++)
3993 DEBUG(1, ("%s\\%s (%d); ",
3994 domains
[j
] ? domains
[j
] : "*unknown*",
3995 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3999 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4001 return NT_STATUS_OK
;
4005 * Fetch a list of all server aliases and their members into
4009 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4010 const DOM_SID
*domain_sid
,
4011 const char *domain_name
,
4012 struct cli_state
*cli
,
4013 struct rpc_pipe_client
*pipe_hnd
,
4014 TALLOC_CTX
*mem_ctx
,
4019 struct policy_handle connect_pol
;
4021 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4023 MAXIMUM_ALLOWED_ACCESS
,
4026 if (!NT_STATUS_IS_OK(result
))
4029 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4030 &global_sid_Builtin
);
4032 if (!NT_STATUS_IS_OK(result
))
4035 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4038 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4043 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4045 token
->num_sids
= 4;
4047 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4048 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4049 token
->num_sids
= 0;
4053 token
->user_sids
[0] = *user_sid
;
4054 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4055 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4056 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4059 static void free_user_token(NT_USER_TOKEN
*token
)
4061 SAFE_FREE(token
->user_sids
);
4064 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4066 if (is_sid_in_token(token
, sid
))
4069 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4070 if (!token
->user_sids
) {
4074 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4076 token
->num_sids
+= 1;
4081 NT_USER_TOKEN token
;
4084 static void dump_user_token(struct user_token
*token
)
4088 d_printf("%s\n", token
->name
);
4090 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4091 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4095 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4099 for (i
=0; i
<alias
->num_members
; i
++) {
4100 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4107 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4111 for (i
=0; i
<num_server_aliases
; i
++) {
4112 if (is_alias_member(&sid
, &server_aliases
[i
]))
4113 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4118 * We got a user token with all the SIDs we can know about without asking the
4119 * server directly. These are the user and domain group sids. All of these can
4120 * be members of aliases. So scan the list of aliases for each of the SIDs and
4121 * add them to the token.
4124 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4126 int num_global_sids
= token
->num_sids
;
4129 for (i
=0; i
<num_global_sids
; i
++) {
4130 collect_sid_memberships(token
, token
->user_sids
[i
]);
4134 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4136 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4137 enum wbcSidType type
;
4139 struct wbcDomainSid wsid
;
4140 char *sid_str
= NULL
;
4142 uint32_t num_groups
;
4143 gid_t
*groups
= NULL
;
4146 fstr_sprintf(full_name
, "%s%c%s",
4147 domain
, *lp_winbind_separator(), user
);
4149 /* First let's find out the user sid */
4151 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4153 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4154 DEBUG(1, ("winbind could not find %s: %s\n",
4155 full_name
, wbcErrorString(wbc_status
)));
4159 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4160 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4164 if (type
!= SID_NAME_USER
) {
4165 wbcFreeMemory(sid_str
);
4166 DEBUG(1, ("%s is not a user\n", full_name
));
4170 if (!string_to_sid(&user_sid
, sid_str
)) {
4171 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4175 wbcFreeMemory(sid_str
);
4178 init_user_token(token
, &user_sid
);
4180 /* And now the groups winbind knows about */
4182 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4183 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4184 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4185 full_name
, wbcErrorString(wbc_status
)));
4189 for (i
= 0; i
< num_groups
; i
++) {
4190 gid_t gid
= groups
[i
];
4193 wbc_status
= wbcGidToSid(gid
, &wsid
);
4194 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4195 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4196 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4197 wbcFreeMemory(groups
);
4201 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4202 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4203 wbcFreeMemory(groups
);
4207 DEBUG(3, (" %s\n", sid_str
));
4209 string_to_sid(&sid
, sid_str
);
4210 wbcFreeMemory(sid_str
);
4213 add_sid_to_token(token
, &sid
);
4215 wbcFreeMemory(groups
);
4221 * Get a list of all user tokens we want to look at
4224 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4225 struct user_token
**user_tokens
)
4227 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4228 uint32_t i
, num_users
;
4230 struct user_token
*result
;
4231 TALLOC_CTX
*frame
= NULL
;
4233 if (lp_winbind_use_default_domain() &&
4234 (c
->opt_target_workgroup
== NULL
)) {
4235 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4236 "please specify a workgroup\n"));
4240 /* Send request to winbind daemon */
4242 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4243 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4244 DEBUG(1, (_("winbind could not list users: %s\n"),
4245 wbcErrorString(wbc_status
)));
4249 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4251 if (result
== NULL
) {
4252 DEBUG(1, ("Could not malloc sid array\n"));
4253 wbcFreeMemory(users
);
4257 frame
= talloc_stackframe();
4258 for (i
=0; i
< num_users
; i
++) {
4259 fstring domain
, user
;
4262 fstrcpy(result
[i
].name
, users
[i
]);
4264 p
= strchr(users
[i
], *lp_winbind_separator());
4266 DEBUG(3, ("%s\n", users
[i
]));
4269 fstrcpy(domain
, c
->opt_target_workgroup
);
4270 fstrcpy(user
, users
[i
]);
4273 fstrcpy(domain
, users
[i
]);
4278 get_user_sids(domain
, user
, &(result
[i
].token
));
4282 wbcFreeMemory(users
);
4284 *num_tokens
= num_users
;
4285 *user_tokens
= result
;
4290 static bool get_user_tokens_from_file(FILE *f
,
4292 struct user_token
**tokens
)
4294 struct user_token
*token
= NULL
;
4299 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4303 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
4304 line
[strlen(line
)-1] = '\0';
4307 if (line
[0] == ' ') {
4311 if(!string_to_sid(&sid
, &line
[1])) {
4312 DEBUG(1,("get_user_tokens_from_file: Could "
4313 "not convert sid %s \n",&line
[1]));
4317 if (token
== NULL
) {
4318 DEBUG(0, ("File does not begin with username"));
4322 add_sid_to_token(&token
->token
, &sid
);
4326 /* And a new user... */
4329 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4330 if (*tokens
== NULL
) {
4331 DEBUG(0, ("Could not realloc tokens\n"));
4335 token
= &((*tokens
)[*num_tokens
-1]);
4337 fstrcpy(token
->name
, line
);
4338 token
->token
.num_sids
= 0;
4339 token
->token
.user_sids
= NULL
;
4348 * Show the list of all users that have access to a share
4351 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4352 TALLOC_CTX
*mem_ctx
,
4353 const char *netname
,
4355 struct user_token
*tokens
)
4358 SEC_DESC
*share_sd
= NULL
;
4359 SEC_DESC
*root_sd
= NULL
;
4360 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4362 union srvsvc_NetShareInfo info
;
4367 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4374 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4375 DEBUG(1, ("Coult not query secdesc for share %s\n",
4380 share_sd
= info
.info502
->sd_buf
.sd
;
4381 if (share_sd
== NULL
) {
4382 DEBUG(1, ("Got no secdesc for share %s\n",
4388 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4392 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
4393 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
4394 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4397 for (i
=0; i
<num_tokens
; i
++) {
4400 if (share_sd
!= NULL
) {
4401 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4404 if (!NT_STATUS_IS_OK(status
)) {
4405 DEBUG(1, ("Could not check share_sd for "
4412 if (root_sd
== NULL
) {
4413 d_printf(" %s\n", tokens
[i
].name
);
4417 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4419 if (!NT_STATUS_IS_OK(status
)) {
4420 DEBUG(1, ("Could not check root_sd for user %s\n",
4424 d_printf(" %s\n", tokens
[i
].name
);
4427 if (fnum
!= (uint16_t)-1)
4428 cli_close(cli
, fnum
);
4440 static void collect_share(const char *name
, uint32 m
,
4441 const char *comment
, void *state
)
4443 struct share_list
*share_list
= (struct share_list
*)state
;
4445 if (m
!= STYPE_DISKTREE
)
4448 share_list
->num_shares
+= 1;
4449 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4450 if (!share_list
->shares
) {
4451 share_list
->num_shares
= 0;
4454 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4458 * List shares on a remote RPC server, including the security descriptors.
4460 * All parameters are provided by the run_rpc_command function, except for
4461 * argc, argv which are passed through.
4463 * @param domain_sid The domain sid acquired from the remote server.
4464 * @param cli A cli_state connected to the server.
4465 * @param mem_ctx Talloc context, destroyed on completion of the function.
4466 * @param argc Standard main() style argc.
4467 * @param argv Standard main() style argv. Initial components are already
4470 * @return Normal NTSTATUS return.
4473 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4474 const DOM_SID
*domain_sid
,
4475 const char *domain_name
,
4476 struct cli_state
*cli
,
4477 struct rpc_pipe_client
*pipe_hnd
,
4478 TALLOC_CTX
*mem_ctx
,
4487 struct user_token
*tokens
= NULL
;
4490 struct share_list share_list
;
4495 f
= fopen(argv
[0], "r");
4499 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4500 return NT_STATUS_UNSUCCESSFUL
;
4503 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4509 DEBUG(0, ("Could not read users from file\n"));
4510 return NT_STATUS_UNSUCCESSFUL
;
4513 for (i
=0; i
<num_tokens
; i
++)
4514 collect_alias_memberships(&tokens
[i
].token
);
4516 share_list
.num_shares
= 0;
4517 share_list
.shares
= NULL
;
4519 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4522 DEBUG(0, ("Error returning browse list: %s\n",
4527 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4528 char *netname
= share_list
.shares
[i
];
4530 if (netname
[strlen(netname
)-1] == '$')
4533 d_printf("%s\n", netname
);
4535 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4536 num_tokens
, tokens
);
4539 for (i
=0; i
<num_tokens
; i
++) {
4540 free_user_token(&tokens
[i
].token
);
4543 SAFE_FREE(share_list
.shares
);
4545 return NT_STATUS_OK
;
4548 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4553 if (c
->display_usage
) {
4555 "net rpc share allowedusers\n"
4558 _("List allowed users"));
4562 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4563 rpc_aliaslist_internals
,
4568 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4574 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4575 rpc_share_allowedusers_internals
,
4579 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4582 struct user_token
*tokens
= NULL
;
4586 net_usersidlist_usage(c
, argc
, argv
);
4590 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4591 DEBUG(0, ("Could not get the user/sid list\n"));
4595 for (i
=0; i
<num_tokens
; i
++) {
4596 dump_user_token(&tokens
[i
]);
4597 free_user_token(&tokens
[i
].token
);
4604 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4606 d_printf(_("net usersidlist\n"
4607 "\tprints out a list of all users the running winbind knows\n"
4608 "\tabout, together with all their SIDs. This is used as\n"
4609 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
4611 net_common_flags_usage(c
, argc
, argv
);
4616 * 'net rpc share' entrypoint.
4617 * @param argc Standard main() style argc.
4618 * @param argv Standard main() style argv. Initial components are already
4622 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4624 NET_API_STATUS status
;
4626 struct functable func
[] = {
4632 N_("net rpc share add\n"
4640 N_("net rpc share delete\n"
4645 rpc_share_allowedusers
,
4647 N_("Modify allowed users"),
4648 N_("net rpc share allowedusers\n"
4649 " Modify allowed users")
4655 N_("Migrate share to local server"),
4656 N_("net rpc share migrate\n"
4657 " Migrate share to local server")
4664 N_("net rpc share list\n"
4667 {NULL
, NULL
, 0, NULL
, NULL
}
4670 status
= libnetapi_init(&c
->netapi_ctx
);
4674 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4675 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4676 if (c
->opt_kerberos
) {
4677 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4681 if (c
->display_usage
) {
4686 " Alias for net rpc share list\n"));
4687 net_display_usage_from_functable(func
);
4691 return rpc_share_list(c
, argc
, argv
);
4694 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4697 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4698 TALLOC_CTX
*mem_ctx
,
4699 struct rpc_sh_ctx
*ctx
,
4700 struct rpc_pipe_client
*pipe_hnd
,
4701 int argc
, const char **argv
)
4704 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4707 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4708 TALLOC_CTX
*mem_ctx
,
4709 struct rpc_sh_ctx
*ctx
,
4710 struct rpc_pipe_client
*pipe_hnd
,
4711 int argc
, const char **argv
)
4713 NET_API_STATUS status
;
4714 uint32_t parm_err
= 0;
4715 struct SHARE_INFO_2 i2
;
4717 if ((argc
< 2) || (argc
> 3)) {
4718 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
4720 return NT_STATUS_INVALID_PARAMETER
;
4723 i2
.shi2_netname
= argv
[0];
4724 i2
.shi2_type
= STYPE_DISKTREE
;
4725 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4726 i2
.shi2_permissions
= 0;
4727 i2
.shi2_max_uses
= 0;
4728 i2
.shi2_current_uses
= 0;
4729 i2
.shi2_path
= argv
[1];
4730 i2
.shi2_passwd
= NULL
;
4732 status
= NetShareAdd(pipe_hnd
->desthost
,
4737 return werror_to_ntstatus(W_ERROR(status
));
4740 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4741 TALLOC_CTX
*mem_ctx
,
4742 struct rpc_sh_ctx
*ctx
,
4743 struct rpc_pipe_client
*pipe_hnd
,
4744 int argc
, const char **argv
)
4747 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4748 return NT_STATUS_INVALID_PARAMETER
;
4751 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4754 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4755 TALLOC_CTX
*mem_ctx
,
4756 struct rpc_sh_ctx
*ctx
,
4757 struct rpc_pipe_client
*pipe_hnd
,
4758 int argc
, const char **argv
)
4760 union srvsvc_NetShareInfo info
;
4765 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
4766 return NT_STATUS_INVALID_PARAMETER
;
4769 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4775 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4779 d_printf(_("Name: %s\n"), info
.info2
->name
);
4780 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
4781 d_printf(_("Path: %s\n"), info
.info2
->path
);
4782 d_printf(_("Password: %s\n"), info
.info2
->password
);
4785 return werror_to_ntstatus(result
);
4788 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4789 struct rpc_sh_ctx
*ctx
)
4791 static struct rpc_sh_cmd cmds
[] = {
4793 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4794 N_("List available shares") },
4796 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4797 N_("Add a share") },
4799 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4800 N_("Delete a share") },
4802 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4803 N_("Get information about a share") },
4805 { NULL
, NULL
, 0, NULL
, NULL
}
4811 /****************************************************************************/
4813 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4815 return net_file_usage(c
, argc
, argv
);
4819 * Close a file on a remote RPC server.
4821 * @param argc Standard main() style argc.
4822 * @param argv Standard main() style argv. Initial components are already
4825 * @return A shell status integer (0 for success).
4827 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4829 if (argc
< 1 || c
->display_usage
) {
4830 return rpc_file_usage(c
, argc
, argv
);
4833 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4837 * Formatted print of open file info
4839 * @param r struct FILE_INFO_3 contents
4842 static void display_file_info_3(struct FILE_INFO_3
*r
)
4844 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4845 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4846 r
->fi3_num_locks
, r
->fi3_pathname
);
4850 * List files for a user on a remote RPC server.
4852 * @param argc Standard main() style argc.
4853 * @param argv Standard main() style argv. Initial components are already
4856 * @return A shell status integer (0 for success)..
4859 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4861 NET_API_STATUS status
;
4862 uint32 preferred_len
= 0xffffffff, i
;
4863 const char *username
=NULL
;
4864 uint32_t total_entries
= 0;
4865 uint32_t entries_read
= 0;
4866 uint32_t resume_handle
= 0;
4867 struct FILE_INFO_3
*i3
= NULL
;
4869 if (c
->display_usage
) {
4870 return rpc_file_usage(c
, argc
, argv
);
4873 /* if argc > 0, must be user command */
4875 username
= smb_xstrdup(argv
[0]);
4878 status
= NetFileEnum(c
->opt_host
,
4882 (uint8_t **)(void *)&i3
,
4892 /* Display results */
4895 "\nEnumerating open files on remote server:\n\n"
4896 "\nFileId Opened by Perms Locks Path"
4897 "\n------ --------- ----- ----- ---- \n"));
4898 for (i
= 0; i
< entries_read
; i
++) {
4899 display_file_info_3(&i3
[i
]);
4906 * 'net rpc file' entrypoint.
4907 * @param argc Standard main() style argc.
4908 * @param argv Standard main() style argv. Initial components are already
4912 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4914 NET_API_STATUS status
;
4916 struct functable func
[] = {
4921 N_("Close opened file"),
4922 N_("net rpc file close\n"
4923 " Close opened file")
4929 N_("List files opened by user"),
4930 N_("net rpc file user\n"
4931 " List files opened by user")
4938 N_("Display information about opened file"),
4939 N_("net rpc file info\n"
4940 " Display information about opened file")
4943 {NULL
, NULL
, 0, NULL
, NULL
}
4946 status
= libnetapi_init(&c
->netapi_ctx
);
4950 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4951 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4952 if (c
->opt_kerberos
) {
4953 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4957 if (c
->display_usage
) {
4958 d_printf(_("Usage:\n"));
4959 d_printf(_("net rpc file\n"
4960 " List opened files\n"));
4961 net_display_usage_from_functable(func
);
4965 return rpc_file_user(c
, argc
, argv
);
4968 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4972 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4974 * All parameters are provided by the run_rpc_command function, except for
4975 * argc, argv which are passed through.
4977 * @param c A net_context structure.
4978 * @param domain_sid The domain sid acquired from the remote server.
4979 * @param cli A cli_state connected to the server.
4980 * @param mem_ctx Talloc context, destroyed on completion of the function.
4981 * @param argc Standard main() style argc.
4982 * @param argv Standard main() style argv. Initial components are already
4985 * @return Normal NTSTATUS return.
4988 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4989 const DOM_SID
*domain_sid
,
4990 const char *domain_name
,
4991 struct cli_state
*cli
,
4992 struct rpc_pipe_client
*pipe_hnd
,
4993 TALLOC_CTX
*mem_ctx
,
4997 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4999 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5001 if (NT_STATUS_IS_OK(result
)) {
5002 d_printf(_("\nShutdown successfully aborted\n"));
5003 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5005 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5011 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5013 * All parameters are provided by the run_rpc_command function, except for
5014 * argc, argv which are passed through.
5016 * @param c A net_context structure.
5017 * @param domain_sid The domain sid acquired from the remote server.
5018 * @param cli A cli_state connected to the server.
5019 * @param mem_ctx Talloc context, destroyed on completion of the function.
5020 * @param argc Standard main() style argc.
5021 * @param argv Standard main() style argv. Initial components are already
5024 * @return Normal NTSTATUS return.
5027 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5028 const DOM_SID
*domain_sid
,
5029 const char *domain_name
,
5030 struct cli_state
*cli
,
5031 struct rpc_pipe_client
*pipe_hnd
,
5032 TALLOC_CTX
*mem_ctx
,
5036 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5038 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5040 if (NT_STATUS_IS_OK(result
)) {
5041 d_printf(_("\nShutdown successfully aborted\n"));
5042 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5044 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5050 * ABORT the shutdown of a remote RPC server.
5052 * @param argc Standard main() style argc.
5053 * @param argv Standard main() style argv. Initial components are already
5056 * @return A shell status integer (0 for success).
5059 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5064 if (c
->display_usage
) {
5066 "net rpc abortshutdown\n"
5069 _("Abort a scheduled shutdown"));
5073 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5074 rpc_shutdown_abort_internals
, argc
, argv
);
5079 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5081 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5082 rpc_reg_shutdown_abort_internals
,
5087 * Shut down a remote RPC Server via initshutdown pipe.
5089 * All parameters are provided by the run_rpc_command function, except for
5090 * argc, argv which are passed through.
5092 * @param c A net_context structure.
5093 * @param domain_sid The domain sid acquired from the remote server.
5094 * @param cli A cli_state connected to the server.
5095 * @param mem_ctx Talloc context, destroyed on completion of the function.
5096 * @param argc Standard main() style argc.
5097 * @param argv Standard main() style argv. Initial components are already
5100 * @return Normal NTSTATUS return.
5103 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5104 const DOM_SID
*domain_sid
,
5105 const char *domain_name
,
5106 struct cli_state
*cli
,
5107 struct rpc_pipe_client
*pipe_hnd
,
5108 TALLOC_CTX
*mem_ctx
,
5112 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5113 const char *msg
= N_("This machine will be shutdown shortly");
5114 uint32 timeout
= 20;
5115 struct lsa_StringLarge msg_string
;
5117 if (c
->opt_comment
) {
5118 msg
= c
->opt_comment
;
5120 if (c
->opt_timeout
) {
5121 timeout
= c
->opt_timeout
;
5124 msg_string
.string
= msg
;
5126 /* create an entry */
5127 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5128 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5131 if (NT_STATUS_IS_OK(result
)) {
5132 d_printf(_("\nShutdown of remote machine succeeded\n"));
5133 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5135 DEBUG(1,("Shutdown of remote machine failed!\n"));
5141 * Shut down a remote RPC Server via winreg pipe.
5143 * All parameters are provided by the run_rpc_command function, except for
5144 * argc, argv which are passed through.
5146 * @param c A net_context structure.
5147 * @param domain_sid The domain sid acquired from the remote server.
5148 * @param cli A cli_state connected to the server.
5149 * @param mem_ctx Talloc context, destroyed on completion of the function.
5150 * @param argc Standard main() style argc.
5151 * @param argv Standard main() style argv. Initial components are already
5154 * @return Normal NTSTATUS return.
5157 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5158 const DOM_SID
*domain_sid
,
5159 const char *domain_name
,
5160 struct cli_state
*cli
,
5161 struct rpc_pipe_client
*pipe_hnd
,
5162 TALLOC_CTX
*mem_ctx
,
5166 const char *msg
= N_("This machine will be shutdown shortly");
5167 uint32 timeout
= 20;
5168 struct lsa_StringLarge msg_string
;
5172 if (c
->opt_comment
) {
5173 msg
= c
->opt_comment
;
5175 msg_string
.string
= msg
;
5177 if (c
->opt_timeout
) {
5178 timeout
= c
->opt_timeout
;
5181 /* create an entry */
5182 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5183 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5186 if (NT_STATUS_IS_OK(result
)) {
5187 d_printf(_("\nShutdown of remote machine succeeded\n"));
5189 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5190 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5191 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5193 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5200 * Shut down a remote RPC server.
5202 * @param argc Standard main() style argc.
5203 * @param argv Standard main() style argv. Initial components are already
5206 * @return A shell status integer (0 for success).
5209 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5213 if (c
->display_usage
) {
5215 "net rpc shutdown\n"
5218 _("Shut down a remote RPC server"));
5222 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5223 rpc_init_shutdown_internals
, argc
, argv
);
5226 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5227 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5228 rpc_reg_shutdown_internals
, argc
, argv
);
5234 /***************************************************************************
5235 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5236 ***************************************************************************/
5239 * Add interdomain trust account to the RPC server.
5240 * All parameters (except for argc and argv) are passed by run_rpc_command
5243 * @param c A net_context structure.
5244 * @param domain_sid The domain sid acquired from the server.
5245 * @param cli A cli_state connected to the server.
5246 * @param mem_ctx Talloc context, destroyed on completion of the function.
5247 * @param argc Standard main() style argc.
5248 * @param argv Standard main() style argv. Initial components are already
5251 * @return normal NTSTATUS return code.
5254 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5255 const DOM_SID
*domain_sid
,
5256 const char *domain_name
,
5257 struct cli_state
*cli
,
5258 struct rpc_pipe_client
*pipe_hnd
,
5259 TALLOC_CTX
*mem_ctx
,
5263 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5264 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5266 struct lsa_String lsa_acct_name
;
5268 uint32 acct_flags
=0;
5270 uint32_t access_granted
= 0;
5271 union samr_UserInfo info
;
5272 unsigned int orig_timeout
;
5277 _(" net rpc trustdom add <domain_name> "
5278 "<trust password>\n"));
5279 return NT_STATUS_INVALID_PARAMETER
;
5283 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5286 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5287 return NT_STATUS_NO_MEMORY
;
5290 strupper_m(acct_name
);
5292 init_lsa_String(&lsa_acct_name
, acct_name
);
5294 /* Get samr policy handle */
5295 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5297 MAXIMUM_ALLOWED_ACCESS
,
5299 if (!NT_STATUS_IS_OK(result
)) {
5303 /* Get domain policy handle */
5304 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5306 MAXIMUM_ALLOWED_ACCESS
,
5307 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5309 if (!NT_STATUS_IS_OK(result
)) {
5313 /* This call can take a long time - allow the server to time out.
5314 * 35 seconds should do it. */
5316 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5318 /* Create trusting domain's account */
5319 acb_info
= ACB_NORMAL
;
5320 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5321 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5322 SAMR_USER_ACCESS_SET_PASSWORD
|
5323 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5324 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5326 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5335 /* And restore our original timeout. */
5336 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5338 if (!NT_STATUS_IS_OK(result
)) {
5339 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5340 acct_name
, nt_errstr(result
));
5345 struct samr_CryptPassword crypt_pwd
;
5347 ZERO_STRUCT(info
.info23
);
5349 init_samr_CryptPassword(argv
[1],
5350 &cli
->user_session_key
,
5353 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5354 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5355 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5356 info
.info23
.password
= crypt_pwd
;
5358 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5363 if (!NT_STATUS_IS_OK(result
)) {
5364 DEBUG(0,("Could not set trust account password: %s\n",
5365 nt_errstr(result
)));
5371 SAFE_FREE(acct_name
);
5376 * Create interdomain trust account for a remote domain.
5378 * @param argc Standard argc.
5379 * @param argv Standard argv without initial components.
5381 * @return Integer status (0 means success).
5384 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5386 if (argc
> 0 && !c
->display_usage
) {
5387 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5388 rpc_trustdom_add_internals
, argc
, argv
);
5392 _("net rpc trustdom add <domain_name> <trust "
5400 * Remove interdomain trust account from the RPC server.
5401 * All parameters (except for argc and argv) are passed by run_rpc_command
5404 * @param c A net_context structure.
5405 * @param domain_sid The domain sid acquired from the server.
5406 * @param cli A cli_state connected to the server.
5407 * @param mem_ctx Talloc context, destroyed on completion of the function.
5408 * @param argc Standard main() style argc.
5409 * @param argv Standard main() style argv. Initial components are already
5412 * @return normal NTSTATUS return code.
5415 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5416 const DOM_SID
*domain_sid
,
5417 const char *domain_name
,
5418 struct cli_state
*cli
,
5419 struct rpc_pipe_client
*pipe_hnd
,
5420 TALLOC_CTX
*mem_ctx
,
5424 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5425 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5427 DOM_SID trust_acct_sid
;
5428 struct samr_Ids user_rids
, name_types
;
5429 struct lsa_String lsa_acct_name
;
5434 _(" net rpc trustdom del <domain_name>\n"));
5435 return NT_STATUS_INVALID_PARAMETER
;
5439 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5441 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5443 if (acct_name
== NULL
)
5444 return NT_STATUS_NO_MEMORY
;
5446 strupper_m(acct_name
);
5448 /* Get samr policy handle */
5449 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5451 MAXIMUM_ALLOWED_ACCESS
,
5453 if (!NT_STATUS_IS_OK(result
)) {
5457 /* Get domain policy handle */
5458 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5460 MAXIMUM_ALLOWED_ACCESS
,
5461 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5463 if (!NT_STATUS_IS_OK(result
)) {
5467 init_lsa_String(&lsa_acct_name
, acct_name
);
5469 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5476 if (!NT_STATUS_IS_OK(result
)) {
5477 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5479 acct_name
, nt_errstr(result
) );
5483 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5485 MAXIMUM_ALLOWED_ACCESS
,
5489 if (!NT_STATUS_IS_OK(result
)) {
5490 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5492 acct_name
, nt_errstr(result
) );
5496 /* append the rid to the domain sid */
5497 sid_copy(&trust_acct_sid
, domain_sid
);
5498 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5502 /* remove the sid */
5504 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5507 if (!NT_STATUS_IS_OK(result
)) {
5508 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5509 " on user %s failed %s\n"),
5510 acct_name
, nt_errstr(result
) );
5516 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5519 if (!NT_STATUS_IS_OK(result
)) {
5520 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5522 acct_name
, nt_errstr(result
) );
5526 if (!NT_STATUS_IS_OK(result
)) {
5527 d_printf(_("Could not set trust account password: %s\n"),
5537 * Delete interdomain trust account for a remote domain.
5539 * @param argc Standard argc.
5540 * @param argv Standard argv without initial components.
5542 * @return Integer status (0 means success).
5545 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5547 if (argc
> 0 && !c
->display_usage
) {
5548 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5549 rpc_trustdom_del_internals
, argc
, argv
);
5553 _("net rpc trustdom del <domain>\n"));
5558 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5559 struct cli_state
*cli
,
5560 TALLOC_CTX
*mem_ctx
,
5561 const char *domain_name
)
5563 char *dc_name
= NULL
;
5564 const char *buffer
= NULL
;
5565 struct rpc_pipe_client
*netr
;
5568 /* Use NetServerEnum2 */
5570 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5572 return NT_STATUS_OK
;
5575 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5576 for domain %s\n", domain_name
));
5578 /* Try netr_GetDcName */
5580 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5582 if (!NT_STATUS_IS_OK(status
)) {
5586 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5593 if (NT_STATUS_IS_OK(status
)) {
5597 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5598 for domain %s\n", domain_name
));
5604 * Establish trust relationship to a trusting domain.
5605 * Interdomain account must already be created on remote PDC.
5607 * @param c A net_context structure.
5608 * @param argc Standard argc.
5609 * @param argv Standard argv without initial components.
5611 * @return Integer status (0 means success).
5614 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5617 struct cli_state
*cli
= NULL
;
5618 struct sockaddr_storage server_ss
;
5619 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5620 struct policy_handle connect_hnd
;
5621 TALLOC_CTX
*mem_ctx
;
5623 DOM_SID
*domain_sid
;
5628 union lsa_PolicyInformation
*info
= NULL
;
5631 * Connect to \\server\ipc$ as 'our domain' account with password
5634 if (argc
!= 1 || c
->display_usage
) {
5637 _("net rpc trustdom establish <domain_name>\n"));
5641 domain_name
= smb_xstrdup(argv
[0]);
5642 strupper_m(domain_name
);
5644 /* account name used at first is our domain's name with '$' */
5645 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5648 strupper_m(acct_name
);
5651 * opt_workgroup will be used by connection functions further,
5652 * hence it should be set to remote domain name instead of ours
5654 if (c
->opt_workgroup
) {
5655 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5658 c
->opt_user_name
= acct_name
;
5660 /* find the domain controller */
5661 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5662 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5666 /* connect to ipc$ as username/password */
5667 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5668 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5670 /* Is it trusting domain account for sure ? */
5671 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5672 nt_errstr(nt_status
)));
5676 /* store who we connected to */
5678 saf_store( domain_name
, pdc_name
);
5681 * Connect to \\server\ipc$ again (this time anonymously)
5684 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5687 if (NT_STATUS_IS_ERR(nt_status
)) {
5688 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5689 domain_name
, nt_errstr(nt_status
)));
5693 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5694 "domain %s", domain_name
))) {
5695 DEBUG(0, ("talloc_init() failed\n"));
5700 /* Make sure we're talking to a proper server */
5702 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5703 if (!NT_STATUS_IS_OK(nt_status
)) {
5705 talloc_destroy(mem_ctx
);
5710 * Call LsaOpenPolicy and LsaQueryInfo
5713 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5715 if (!NT_STATUS_IS_OK(nt_status
)) {
5716 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5718 talloc_destroy(mem_ctx
);
5722 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5724 if (NT_STATUS_IS_ERR(nt_status
)) {
5725 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5726 nt_errstr(nt_status
)));
5728 talloc_destroy(mem_ctx
);
5732 /* Querying info level 5 */
5734 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5736 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5738 if (NT_STATUS_IS_ERR(nt_status
)) {
5739 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5740 nt_errstr(nt_status
)));
5742 talloc_destroy(mem_ctx
);
5746 domain_sid
= info
->account_domain
.sid
;
5748 /* There should be actually query info level 3 (following nt serv behaviour),
5749 but I still don't know if it's _really_ necessary */
5752 * Store the password in secrets db
5755 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5756 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5758 talloc_destroy(mem_ctx
);
5763 * Close the pipes and clean up
5766 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5767 if (NT_STATUS_IS_ERR(nt_status
)) {
5768 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5769 nt_errstr(nt_status
)));
5771 talloc_destroy(mem_ctx
);
5777 talloc_destroy(mem_ctx
);
5779 d_printf(_("Trust to domain %s established\n"), domain_name
);
5784 * Revoke trust relationship to the remote domain.
5786 * @param c A net_context structure.
5787 * @param argc Standard argc.
5788 * @param argv Standard argv without initial components.
5790 * @return Integer status (0 means success).
5793 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5799 if (argc
< 1 || c
->display_usage
) {
5802 _("net rpc trustdom revoke <domain_name>\n"
5803 " Revoke trust relationship\n"
5804 " domain_name\tName of domain to revoke trust\n"));
5808 /* generate upper cased domain name */
5809 domain_name
= smb_xstrdup(argv
[0]);
5810 strupper_m(domain_name
);
5812 /* delete password of the trust */
5813 if (!pdb_del_trusteddom_pw(domain_name
)) {
5814 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5821 SAFE_FREE(domain_name
);
5825 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5826 const DOM_SID
*domain_sid
,
5827 const char *domain_name
,
5828 struct cli_state
*cli
,
5829 struct rpc_pipe_client
*pipe_hnd
,
5830 TALLOC_CTX
*mem_ctx
,
5835 if (!sid_to_fstring(str_sid
, domain_sid
)) {
5836 return NT_STATUS_UNSUCCESSFUL
;
5838 d_printf("%s\n", str_sid
);
5839 return NT_STATUS_OK
;
5842 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5846 /* convert sid into ascii string */
5847 sid_to_fstring(ascii_sid
, dom_sid
);
5849 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
5852 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5853 TALLOC_CTX
*mem_ctx
,
5854 struct policy_handle
*pol
,
5856 const char *trusted_dom_name
)
5859 union lsa_TrustedDomainInfo
*info
= NULL
;
5860 char *cleartextpwd
= NULL
;
5861 uint8_t session_key
[16];
5862 DATA_BLOB session_key_blob
;
5863 DATA_BLOB data
= data_blob_null
;
5865 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5868 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5870 if (NT_STATUS_IS_ERR(nt_status
)) {
5871 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5872 nt_errstr(nt_status
)));
5876 data
= data_blob(info
->password
.password
->data
,
5877 info
->password
.password
->length
);
5879 if (!rpccli_get_pwd_hash(pipe_hnd
, session_key
)) {
5880 DEBUG(0, ("Could not retrieve password hash\n"));
5884 session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
5885 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key_blob
);
5887 if (cleartextpwd
== NULL
) {
5888 DEBUG(0,("retrieved NULL password\n"));
5889 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5893 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5894 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5895 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5899 #ifdef DEBUG_PASSWORD
5900 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5901 "password: [%s]\n", trusted_dom_name
,
5902 sid_string_dbg(&dom_sid
), cleartextpwd
));
5906 SAFE_FREE(cleartextpwd
);
5907 data_blob_free(&data
);
5912 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5915 /* common variables */
5916 TALLOC_CTX
* mem_ctx
;
5917 struct cli_state
*cli
= NULL
;
5918 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5920 const char *domain_name
= NULL
;
5921 DOM_SID
*queried_dom_sid
;
5922 struct policy_handle connect_hnd
;
5923 union lsa_PolicyInformation
*info
= NULL
;
5925 /* trusted domains listing variables */
5926 unsigned int enum_ctx
= 0;
5928 struct lsa_DomainList dom_list
;
5931 if (c
->display_usage
) {
5933 "net rpc trustdom vampire\n"
5936 _("Vampire trust relationship from remote server"));
5941 * Listing trusted domains (stored in secrets.tdb, if local)
5944 mem_ctx
= talloc_init("trust relationships vampire");
5947 * set domain and pdc name to local samba server (default)
5948 * or to remote one given in command line
5951 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5952 domain_name
= c
->opt_workgroup
;
5953 c
->opt_target_workgroup
= c
->opt_workgroup
;
5955 fstrcpy(pdc_name
, global_myname());
5956 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5957 c
->opt_target_workgroup
= domain_name
;
5960 /* open \PIPE\lsarpc and open policy handle */
5961 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5962 if (!NT_STATUS_IS_OK(nt_status
)) {
5963 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5964 nt_errstr(nt_status
)));
5965 talloc_destroy(mem_ctx
);
5969 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5971 if (!NT_STATUS_IS_OK(nt_status
)) {
5972 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5973 nt_errstr(nt_status
) ));
5975 talloc_destroy(mem_ctx
);
5979 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5981 if (NT_STATUS_IS_ERR(nt_status
)) {
5982 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5983 nt_errstr(nt_status
)));
5985 talloc_destroy(mem_ctx
);
5989 /* query info level 5 to obtain sid of a domain being queried */
5990 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5992 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5995 if (NT_STATUS_IS_ERR(nt_status
)) {
5996 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5997 nt_errstr(nt_status
)));
5999 talloc_destroy(mem_ctx
);
6003 queried_dom_sid
= info
->account_domain
.sid
;
6006 * Keep calling LsaEnumTrustdom over opened pipe until
6007 * the end of enumeration is reached
6010 d_printf(_("Vampire trusted domains:\n\n"));
6013 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6018 if (NT_STATUS_IS_ERR(nt_status
)) {
6019 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6020 nt_errstr(nt_status
)));
6022 talloc_destroy(mem_ctx
);
6026 for (i
= 0; i
< dom_list
.count
; i
++) {
6028 print_trusted_domain(dom_list
.domains
[i
].sid
,
6029 dom_list
.domains
[i
].name
.string
);
6031 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6032 *dom_list
.domains
[i
].sid
,
6033 dom_list
.domains
[i
].name
.string
);
6034 if (!NT_STATUS_IS_OK(nt_status
)) {
6036 talloc_destroy(mem_ctx
);
6042 * in case of no trusted domains say something rather
6043 * than just display blank line
6045 if (!dom_list
.count
) d_printf(_("none\n"));
6047 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6049 /* close this connection before doing next one */
6050 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6051 if (NT_STATUS_IS_ERR(nt_status
)) {
6052 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6053 nt_errstr(nt_status
)));
6055 talloc_destroy(mem_ctx
);
6059 /* close lsarpc pipe and connection to IPC$ */
6062 talloc_destroy(mem_ctx
);
6066 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6068 /* common variables */
6069 TALLOC_CTX
* mem_ctx
;
6070 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6071 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6073 const char *domain_name
= NULL
;
6074 DOM_SID
*queried_dom_sid
;
6075 int ascii_dom_name_len
;
6076 struct policy_handle connect_hnd
;
6077 union lsa_PolicyInformation
*info
= NULL
;
6079 /* trusted domains listing variables */
6080 unsigned int num_domains
, enum_ctx
= 0;
6082 struct lsa_DomainList dom_list
;
6086 /* trusting domains listing variables */
6087 struct policy_handle domain_hnd
;
6088 struct samr_SamArray
*trusts
= NULL
;
6090 if (c
->display_usage
) {
6092 "net rpc trustdom list\n"
6095 _("List incoming and outgoing trust relationships"));
6100 * Listing trusted domains (stored in secrets.tdb, if local)
6103 mem_ctx
= talloc_init("trust relationships listing");
6106 * set domain and pdc name to local samba server (default)
6107 * or to remote one given in command line
6110 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6111 domain_name
= c
->opt_workgroup
;
6112 c
->opt_target_workgroup
= c
->opt_workgroup
;
6114 fstrcpy(pdc_name
, global_myname());
6115 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6116 c
->opt_target_workgroup
= domain_name
;
6119 /* open \PIPE\lsarpc and open policy handle */
6120 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6121 if (!NT_STATUS_IS_OK(nt_status
)) {
6122 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6123 nt_errstr(nt_status
)));
6124 talloc_destroy(mem_ctx
);
6128 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6130 if (!NT_STATUS_IS_OK(nt_status
)) {
6131 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6132 nt_errstr(nt_status
) ));
6134 talloc_destroy(mem_ctx
);
6138 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6140 if (NT_STATUS_IS_ERR(nt_status
)) {
6141 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6142 nt_errstr(nt_status
)));
6144 talloc_destroy(mem_ctx
);
6148 /* query info level 5 to obtain sid of a domain being queried */
6149 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6151 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6154 if (NT_STATUS_IS_ERR(nt_status
)) {
6155 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6156 nt_errstr(nt_status
)));
6158 talloc_destroy(mem_ctx
);
6162 queried_dom_sid
= info
->account_domain
.sid
;
6165 * Keep calling LsaEnumTrustdom over opened pipe until
6166 * the end of enumeration is reached
6169 d_printf(_("Trusted domains list:\n\n"));
6171 found_domain
= false;
6174 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6179 if (NT_STATUS_IS_ERR(nt_status
)) {
6180 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6181 nt_errstr(nt_status
)));
6183 talloc_destroy(mem_ctx
);
6187 for (i
= 0; i
< dom_list
.count
; i
++) {
6188 print_trusted_domain(dom_list
.domains
[i
].sid
,
6189 dom_list
.domains
[i
].name
.string
);
6190 found_domain
= true;
6194 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6197 * in case of no trusted domains say something rather
6198 * than just display blank line
6200 if (!found_domain
) {
6201 d_printf(_("none\n"));
6204 /* close this connection before doing next one */
6205 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6206 if (NT_STATUS_IS_ERR(nt_status
)) {
6207 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6208 nt_errstr(nt_status
)));
6210 talloc_destroy(mem_ctx
);
6214 TALLOC_FREE(pipe_hnd
);
6217 * Listing trusting domains (stored in passdb backend, if local)
6220 d_printf(_("\nTrusting domains list:\n\n"));
6223 * Open \PIPE\samr and get needed policy handles
6225 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6227 if (!NT_STATUS_IS_OK(nt_status
)) {
6228 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6230 talloc_destroy(mem_ctx
);
6235 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6237 SAMR_ACCESS_LOOKUP_DOMAIN
,
6239 if (!NT_STATUS_IS_OK(nt_status
)) {
6240 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6241 nt_errstr(nt_status
)));
6243 talloc_destroy(mem_ctx
);
6247 /* SamrOpenDomain - we have to open domain policy handle in order to be
6248 able to enumerate accounts*/
6249 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6251 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6254 if (!NT_STATUS_IS_OK(nt_status
)) {
6255 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6256 nt_errstr(nt_status
)));
6258 talloc_destroy(mem_ctx
);
6263 * perform actual enumeration
6266 found_domain
= false;
6268 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6271 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6278 if (NT_STATUS_IS_ERR(nt_status
)) {
6279 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6280 nt_errstr(nt_status
)));
6282 talloc_destroy(mem_ctx
);
6286 for (i
= 0; i
< num_domains
; i
++) {
6288 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6290 found_domain
= true;
6293 * get each single domain's sid (do we _really_ need this ?):
6294 * 1) connect to domain's pdc
6295 * 2) query the pdc for domain's sid
6298 /* get rid of '$' tail */
6299 ascii_dom_name_len
= strlen(str
);
6300 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6301 str
[ascii_dom_name_len
- 1] = '\0';
6303 /* set opt_* variables to remote domain */
6305 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6306 c
->opt_target_workgroup
= c
->opt_workgroup
;
6308 d_printf("%-20s", str
);
6310 /* connect to remote domain controller */
6311 nt_status
= net_make_ipc_connection(c
,
6312 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6314 if (NT_STATUS_IS_OK(nt_status
)) {
6315 /* query for domain's sid */
6316 if (run_rpc_command(
6318 &ndr_table_lsarpc
.syntax_id
, 0,
6319 rpc_query_domain_sid
, argc
,
6321 d_printf(_("strange - couldn't get domain's sid\n"));
6323 cli_shutdown(remote_cli
);
6326 d_fprintf(stderr
, _("domain controller is not "
6327 "responding: %s\n"),
6328 nt_errstr(nt_status
));
6329 d_printf(_("couldn't get domain's sid\n"));
6333 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6335 if (!found_domain
) {
6339 /* close opened samr and domain policy handles */
6340 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6341 if (!NT_STATUS_IS_OK(nt_status
)) {
6342 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6345 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6346 if (!NT_STATUS_IS_OK(nt_status
)) {
6347 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6350 /* close samr pipe and connection to IPC$ */
6353 talloc_destroy(mem_ctx
);
6358 * Entrypoint for 'net rpc trustdom' code.
6360 * @param argc Standard argc.
6361 * @param argv Standard argv without initial components.
6363 * @return Integer status (0 means success).
6366 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6368 struct functable func
[] = {
6373 N_("Add trusting domain's account"),
6374 N_("net rpc trustdom add\n"
6375 " Add trusting domain's account")
6381 N_("Remove trusting domain's account"),
6382 N_("net rpc trustdom del\n"
6383 " Remove trusting domain's account")
6387 rpc_trustdom_establish
,
6389 N_("Establish outgoing trust relationship"),
6390 N_("net rpc trustdom establish\n"
6391 " Establish outgoing trust relationship")
6395 rpc_trustdom_revoke
,
6397 N_("Revoke outgoing trust relationship"),
6398 N_("net rpc trustdom revoke\n"
6399 " Revoke outgoing trust relationship")
6405 N_("List in- and outgoing domain trusts"),
6406 N_("net rpc trustdom list\n"
6407 " List in- and outgoing domain trusts")
6411 rpc_trustdom_vampire
,
6413 N_("Vampire trusts from remote server"),
6414 N_("net rpc trustdom vampire\n"
6415 " Vampire trusts from remote server")
6417 {NULL
, NULL
, 0, NULL
, NULL
}
6420 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6424 * Check if a server will take rpc commands
6425 * @param flags Type of server to connect to (PDC, DMB, localhost)
6426 * if the host is not explicitly specified
6427 * @return bool (true means rpc supported)
6429 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6431 struct cli_state
*cli
;
6433 struct sockaddr_storage server_ss
;
6434 char *server_name
= NULL
;
6437 /* flags (i.e. server type) may depend on command */
6438 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6441 if ((cli
= cli_initialise()) == NULL
) {
6445 status
= cli_connect(cli
, server_name
, &server_ss
);
6446 if (!NT_STATUS_IS_OK(status
))
6448 if (!attempt_netbios_session_request(&cli
, global_myname(),
6449 server_name
, &server_ss
))
6451 status
= cli_negprot(cli
);
6452 if (!NT_STATUS_IS_OK(status
))
6454 if (cli
->protocol
< PROTOCOL_NT1
)
6463 /* dump sam database via samsync rpc calls */
6464 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6465 if (c
->display_usage
) {
6470 _("Dump remote SAM database"));
6474 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6475 NET_FLAGS_ANONYMOUS
,
6476 rpc_samdump_internals
, argc
, argv
);
6479 /* syncronise sam database via samsync rpc calls */
6480 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6482 struct functable func
[] = {
6487 N_("Dump remote SAM database to ldif"),
6488 N_("net rpc vampire ldif\n"
6489 " Dump remote SAM database to LDIF file or "
6496 N_("Dump remote SAM database to Kerberos Keytab"),
6497 N_("net rpc vampire keytab\n"
6498 " Dump remote SAM database to Kerberos keytab "
6505 N_("Dump remote SAM database to passdb"),
6506 N_("net rpc vampire passdb\n"
6507 " Dump remote SAM database to passdb")
6510 {NULL
, NULL
, 0, NULL
, NULL
}
6514 if (c
->display_usage
) {
6519 _("Vampire remote SAM database"));
6523 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6524 NET_FLAGS_ANONYMOUS
,
6525 rpc_vampire_internals
,
6529 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6533 * Migrate everything from a print server.
6535 * @param c A net_context structure.
6536 * @param argc Standard main() style argc.
6537 * @param argv Standard main() style argv. Initial components are already
6540 * @return A shell status integer (0 for success).
6542 * The order is important !
6543 * To successfully add drivers the print queues have to exist !
6544 * Applying ACLs should be the last step, because you're easily locked out.
6547 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6552 if (c
->display_usage
) {
6554 "net rpc printer migrate all\n"
6557 _("Migrate everything from a print server"));
6562 d_printf(_("no server to migrate\n"));
6566 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6567 rpc_printer_migrate_printers_internals
, argc
,
6572 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6573 rpc_printer_migrate_drivers_internals
, argc
,
6578 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6579 rpc_printer_migrate_forms_internals
, argc
, argv
);
6583 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6584 rpc_printer_migrate_settings_internals
, argc
,
6589 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6590 rpc_printer_migrate_security_internals
, argc
,
6596 * Migrate print drivers from a print server.
6598 * @param c A net_context structure.
6599 * @param argc Standard main() style argc.
6600 * @param argv Standard main() style argv. Initial components are already
6603 * @return A shell status integer (0 for success).
6605 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6608 if (c
->display_usage
) {
6610 "net rpc printer migrate drivers\n"
6613 _("Migrate print-drivers from a print-server"));
6618 d_printf(_("no server to migrate\n"));
6622 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6623 rpc_printer_migrate_drivers_internals
,
6628 * Migrate print-forms from a print-server.
6630 * @param c A net_context structure.
6631 * @param argc Standard main() style argc.
6632 * @param argv Standard main() style argv. Initial components are already
6635 * @return A shell status integer (0 for success).
6637 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6640 if (c
->display_usage
) {
6642 "net rpc printer migrate forms\n"
6645 _("Migrate print-forms from a print-server"));
6650 d_printf(_("no server to migrate\n"));
6654 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6655 rpc_printer_migrate_forms_internals
,
6660 * Migrate printers from a print-server.
6662 * @param c A net_context structure.
6663 * @param argc Standard main() style argc.
6664 * @param argv Standard main() style argv. Initial components are already
6667 * @return A shell status integer (0 for success).
6669 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6672 if (c
->display_usage
) {
6674 "net rpc printer migrate printers\n"
6677 _("Migrate printers from a print-server"));
6682 d_printf(_("no server to migrate\n"));
6686 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6687 rpc_printer_migrate_printers_internals
,
6692 * Migrate printer-ACLs from a print-server
6694 * @param c A net_context structure.
6695 * @param argc Standard main() style argc.
6696 * @param argv Standard main() style argv. Initial components are already
6699 * @return A shell status integer (0 for success).
6701 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6704 if (c
->display_usage
) {
6706 "net rpc printer migrate security\n"
6709 _("Migrate printer-ACLs from a print-server"));
6714 d_printf(_("no server to migrate\n"));
6718 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6719 rpc_printer_migrate_security_internals
,
6724 * Migrate printer-settings from a print-server.
6726 * @param c A net_context structure.
6727 * @param argc Standard main() style argc.
6728 * @param argv Standard main() style argv. Initial components are already
6731 * @return A shell status integer (0 for success).
6733 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6736 if (c
->display_usage
) {
6738 "net rpc printer migrate settings\n"
6741 _("Migrate printer-settings from a "
6747 d_printf(_("no server to migrate\n"));
6751 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6752 rpc_printer_migrate_settings_internals
,
6757 * 'net rpc printer' entrypoint.
6759 * @param c A net_context structure.
6760 * @param argc Standard main() style argc.
6761 * @param argv Standard main() style argv. Initial components are already
6765 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6768 /* ouch: when addriver and setdriver are called from within
6769 rpc_printer_migrate_drivers_internals, the printer-queue already
6772 struct functable func
[] = {
6775 rpc_printer_migrate_all
,
6777 N_("Migrate all from remote to local print server"),
6778 N_("net rpc printer migrate all\n"
6779 " Migrate all from remote to local print server")
6783 rpc_printer_migrate_drivers
,
6785 N_("Migrate drivers to local server"),
6786 N_("net rpc printer migrate drivers\n"
6787 " Migrate drivers to local server")
6791 rpc_printer_migrate_forms
,
6793 N_("Migrate froms to local server"),
6794 N_("net rpc printer migrate forms\n"
6795 " Migrate froms to local server")
6799 rpc_printer_migrate_printers
,
6801 N_("Migrate printers to local server"),
6802 N_("net rpc printer migrate printers\n"
6803 " Migrate printers to local server")
6807 rpc_printer_migrate_security
,
6809 N_("Mirgate printer ACLs to local server"),
6810 N_("net rpc printer migrate security\n"
6811 " Mirgate printer ACLs to local server")
6815 rpc_printer_migrate_settings
,
6817 N_("Migrate printer settings to local server"),
6818 N_("net rpc printer migrate settings\n"
6819 " Migrate printer settings to local server")
6821 {NULL
, NULL
, 0, NULL
, NULL
}
6824 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6829 * List printers on a remote RPC server.
6831 * @param c A net_context structure.
6832 * @param argc Standard main() style argc.
6833 * @param argv Standard main() style argv. Initial components are already
6836 * @return A shell status integer (0 for success).
6838 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6840 if (c
->display_usage
) {
6842 "net rpc printer list\n"
6845 _("List printers on a remote RPC server"));
6849 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6850 rpc_printer_list_internals
,
6855 * List printer-drivers on a remote RPC server.
6857 * @param c A net_context structure.
6858 * @param argc Standard main() style argc.
6859 * @param argv Standard main() style argv. Initial components are already
6862 * @return A shell status integer (0 for success).
6864 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6867 if (c
->display_usage
) {
6869 "net rpc printer driver\n"
6872 _("List printer-drivers on a remote RPC server"));
6876 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6877 rpc_printer_driver_list_internals
,
6882 * Publish printer in ADS via MSRPC.
6884 * @param c A net_context structure.
6885 * @param argc Standard main() style argc.
6886 * @param argv Standard main() style argv. Initial components are already
6889 * @return A shell status integer (0 for success).
6891 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6894 if (c
->display_usage
) {
6896 "net rpc printer publish publish\n"
6899 _("Publish printer in ADS via MSRPC"));
6903 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6904 rpc_printer_publish_publish_internals
,
6909 * Update printer in ADS via MSRPC.
6911 * @param c A net_context structure.
6912 * @param argc Standard main() style argc.
6913 * @param argv Standard main() style argv. Initial components are already
6916 * @return A shell status integer (0 for success).
6918 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6920 if (c
->display_usage
) {
6922 "net rpc printer publish update\n"
6925 _("Update printer in ADS via MSRPC"));
6929 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6930 rpc_printer_publish_update_internals
,
6935 * UnPublish printer in ADS via MSRPC.
6937 * @param c A net_context structure.
6938 * @param argc Standard main() style argc.
6939 * @param argv Standard main() style argv. Initial components are already
6942 * @return A shell status integer (0 for success).
6944 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6947 if (c
->display_usage
) {
6949 "net rpc printer publish unpublish\n"
6952 _("UnPublish printer in ADS via MSRPC"));
6956 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6957 rpc_printer_publish_unpublish_internals
,
6962 * List published printers via MSRPC.
6964 * @param c A net_context structure.
6965 * @param argc Standard main() style argc.
6966 * @param argv Standard main() style argv. Initial components are already
6969 * @return A shell status integer (0 for success).
6971 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6974 if (c
->display_usage
) {
6976 "net rpc printer publish list\n"
6979 _("List published printers via MSRPC"));
6983 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6984 rpc_printer_publish_list_internals
,
6990 * Publish printer in ADS.
6992 * @param c A net_context structure.
6993 * @param argc Standard main() style argc.
6994 * @param argv Standard main() style argv. Initial components are already
6997 * @return A shell status integer (0 for success).
6999 static int rpc_printer_publish(struct net_context
*c
, int argc
,
7003 struct functable func
[] = {
7006 rpc_printer_publish_publish
,
7008 N_("Publish printer in AD"),
7009 N_("net rpc printer publish publish\n"
7010 " Publish printer in AD")
7014 rpc_printer_publish_update
,
7016 N_("Update printer in AD"),
7017 N_("net rpc printer publish update\n"
7018 " Update printer in AD")
7022 rpc_printer_publish_unpublish
,
7024 N_("Unpublish printer"),
7025 N_("net rpc printer publish unpublish\n"
7026 " Unpublish printer")
7030 rpc_printer_publish_list
,
7032 N_("List published printers"),
7033 N_("net rpc printer publish list\n"
7034 " List published printers")
7036 {NULL
, NULL
, 0, NULL
, NULL
}
7040 if (c
->display_usage
) {
7041 d_printf(_("Usage:\n"));
7042 d_printf(_("net rpc printer publish\n"
7043 " List published printers\n"
7044 " Alias of net rpc printer publish "
7046 net_display_usage_from_functable(func
);
7049 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7050 rpc_printer_publish_list_internals
,
7054 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
7060 * Display rpc printer help page.
7062 * @param c A net_context structure.
7063 * @param argc Standard main() style argc.
7064 * @param argv Standard main() style argv. Initial components are already
7067 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
7069 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
7070 "\tlists all printers on print-server\n\n"));
7071 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7072 "\tlists all printer-drivers on print-server\n\n"));
7073 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7074 "\tpublishes printer settings in Active Directory\n"
7075 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
7076 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7077 "\n\tmigrates printers from remote to local server\n\n"));
7078 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7079 "\n\tmigrates printer-settings from remote to local server\n\n"));
7080 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7081 "\n\tmigrates printer-drivers from remote to local server\n\n"));
7082 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7083 "\n\tmigrates printer-forms from remote to local server\n\n"));
7084 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7085 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
7086 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7087 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7088 "\tremote to local print-server\n\n"));
7089 net_common_methods_usage(c
, argc
, argv
);
7090 net_common_flags_usage(c
, argc
, argv
);
7092 "\t-v or --verbose\t\t\tgive verbose output\n"
7093 "\t --destination\t\tmigration target server (default: localhost)\n"));
7099 * 'net rpc printer' entrypoint.
7101 * @param c A net_context structure.
7102 * @param argc Standard main() style argc.
7103 * @param argv Standard main() style argv. Initial components are already
7106 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
7108 struct functable func
[] = {
7113 N_("List all printers on print server"),
7114 N_("net rpc printer list\n"
7115 " List all printers on print server")
7119 rpc_printer_migrate
,
7121 N_("Migrate printer to local server"),
7122 N_("net rpc printer migrate\n"
7123 " Migrate printer to local server")
7127 rpc_printer_driver_list
,
7129 N_("List printer drivers"),
7130 N_("net rpc printer driver\n"
7131 " List printer drivers")
7135 rpc_printer_publish
,
7137 N_("Publish printer in AD"),
7138 N_("net rpc printer publish\n"
7139 " Publish printer in AD")
7141 {NULL
, NULL
, 0, NULL
, NULL
}
7145 if (c
->display_usage
) {
7146 d_printf(_("Usage:\n"));
7147 d_printf(_("net rpc printer\n"
7148 " List printers\n"));
7149 net_display_usage_from_functable(func
);
7152 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7153 rpc_printer_list_internals
,
7157 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7161 * 'net rpc' entrypoint.
7163 * @param c A net_context structure.
7164 * @param argc Standard main() style argc.
7165 * @param argv Standard main() style argv. Initial components are already
7169 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7171 NET_API_STATUS status
;
7173 struct functable func
[] = {
7178 N_("Modify global audit settings"),
7179 N_("net rpc audit\n"
7180 " Modify global audit settings")
7186 N_("Show basic info about a domain"),
7188 " Show basic info about a domain")
7194 N_("Join a domain"),
7202 N_("Join a domain created in server manager"),
7203 N_("net rpc oldjoin\n"
7204 " Join a domain created in server manager")
7210 N_("Test that a join is valid"),
7211 N_("net rpc testjoin\n"
7212 " Test that a join is valid")
7218 N_("List/modify users"),
7220 " List/modify users")
7226 N_("Change a user password"),
7227 N_("net rpc password\n"
7228 " Change a user password\n"
7229 " Alias for net rpc user password")
7235 N_("List/modify groups"),
7236 N_("net rpc group\n"
7237 " List/modify groups")
7243 N_("List/modify shares"),
7244 N_("net rpc share\n"
7245 " List/modify shares")
7251 N_("List open files"),
7259 N_("List/modify printers"),
7260 N_("net rpc printer\n"
7261 " List/modify printers")
7265 net_rpc_changetrustpw
,
7267 N_("Change trust account password"),
7268 N_("net rpc changetrustpw\n"
7269 " Change trust account password")
7275 N_("Modify domain trusts"),
7276 N_("net rpc trustdom\n"
7277 " Modify domain trusts")
7283 N_("Abort a remote shutdown"),
7284 N_("net rpc abortshutdown\n"
7285 " Abort a remote shutdown")
7291 N_("Shutdown a remote server"),
7292 N_("net rpc shutdown\n"
7293 " Shutdown a remote server")
7299 N_("Dump SAM data of remote NT PDC"),
7300 N_("net rpc samdump\n"
7301 " Dump SAM data of remote NT PDC")
7307 N_("Sync a remote NT PDC's data into local passdb"),
7308 N_("net rpc vampire\n"
7309 " Sync a remote NT PDC's data into local passdb")
7315 N_("Fetch the domain sid into local secrets.tdb"),
7316 N_("net rpc getsid\n"
7317 " Fetch the domain sid into local secrets.tdb")
7323 N_("Manage privileges assigned to SID"),
7324 N_("net rpc rights\n"
7325 " Manage privileges assigned to SID")
7331 N_("Start/stop/query remote services"),
7332 N_("net rpc service\n"
7333 " Start/stop/query remote services")
7339 N_("Manage registry hives"),
7340 N_("net rpc registry\n"
7341 " Manage registry hives")
7347 N_("Open interactive shell on remote server"),
7348 N_("net rpc shell\n"
7349 " Open interactive shell on remote server")
7351 {NULL
, NULL
, 0, NULL
, NULL
}
7354 status
= libnetapi_init(&c
->netapi_ctx
);
7358 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7359 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7360 if (c
->opt_kerberos
) {
7361 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7363 if (c
->opt_ccache
) {
7364 libnetapi_set_use_ccache(c
->netapi_ctx
);
7367 return net_run_function(c
, argc
, argv
, "net rpc", func
);