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 "rpc_client/cli_pipe.h"
26 #include "../libcli/auth/libcli_auth.h"
27 #include "../librpc/gen_ndr/ndr_samr_c.h"
28 #include "rpc_client/cli_samr.h"
29 #include "rpc_client/init_samr.h"
30 #include "../librpc/gen_ndr/ndr_lsa_c.h"
31 #include "rpc_client/cli_lsarpc.h"
32 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
33 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
34 #include "../librpc/gen_ndr/ndr_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_initshutdown_c.h"
36 #include "../librpc/gen_ndr/ndr_winreg_c.h"
38 #include "lib/netapi/netapi.h"
39 #include "lib/netapi/netapi_net.h"
40 #include "librpc/gen_ndr/libnet_join.h"
41 #include "libnet/libnet_join.h"
42 #include "rpc_client/init_lsa.h"
43 #include "../libcli/security/security.h"
44 #include "libsmb/libsmb.h"
45 #include "libsmb/clirap.h"
46 #include "nsswitch/libwbclient/wbclient.h"
48 #include "../libcli/smb/smbXcli_base.h"
50 static int net_mode_share
;
51 static NTSTATUS
sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
56 * @brief RPC based subcommands for the 'net' utility.
58 * This file should contain much of the functionality that used to
59 * be found in rpcclient, execpt that the commands should change
60 * less often, and the fucntionality should be sane (the user is not
61 * expected to know a rid/sid before they conduct an operation etc.)
63 * @todo Perhaps eventually these should be split out into a number
64 * of files, as this could get quite big.
69 * Many of the RPC functions need the domain sid. This function gets
70 * it at the start of every run
72 * @param cli A cli_state already connected to the remote machine
74 * @return The Domain SID of the remote machine.
77 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
78 struct dom_sid
**domain_sid
,
79 const char **domain_name
)
81 struct rpc_pipe_client
*lsa_pipe
= NULL
;
82 struct policy_handle pol
;
83 NTSTATUS status
, result
;
84 union lsa_PolicyInformation
*info
= NULL
;
85 struct dcerpc_binding_handle
*b
;
87 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
89 if (!NT_STATUS_IS_OK(status
)) {
90 d_fprintf(stderr
, _("Could not initialise lsa pipe\n"));
94 b
= lsa_pipe
->binding_handle
;
96 status
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
97 SEC_FLAG_MAXIMUM_ALLOWED
,
99 if (!NT_STATUS_IS_OK(status
)) {
100 d_fprintf(stderr
, "open_policy %s: %s\n",
106 status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
108 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
111 if (!NT_STATUS_IS_OK(status
)) {
112 d_fprintf(stderr
, "lsaquery %s: %s\n",
117 if (!NT_STATUS_IS_OK(result
)) {
118 d_fprintf(stderr
, "lsaquery %s: %s\n",
124 *domain_name
= info
->account_domain
.name
.string
;
125 *domain_sid
= info
->account_domain
.sid
;
127 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
128 TALLOC_FREE(lsa_pipe
);
134 * Run a single RPC command, from start to finish.
136 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
137 * @param conn_flag a NET_FLAG_ combination. Passed to
138 * net_make_ipc_connection.
139 * @param argc Standard main() style argc.
140 * @param argv Standard main() style argv. Initial components are already
142 * @return A shell status integer (0 for success).
145 int run_rpc_command(struct net_context
*c
,
146 struct cli_state
*cli_arg
,
147 const struct ndr_interface_table
*table
,
153 struct cli_state
*cli
= NULL
;
154 struct rpc_pipe_client
*pipe_hnd
= NULL
;
157 struct dom_sid
*domain_sid
;
158 const char *domain_name
;
161 /* make use of cli_state handed over as an argument, if possible */
163 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
164 if (!NT_STATUS_IS_OK(nt_status
)) {
165 DEBUG(1, ("failed to make ipc connection: %s\n",
166 nt_errstr(nt_status
)));
179 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
180 DEBUG(0, ("talloc_init() failed\n"));
184 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
186 if (!NT_STATUS_IS_OK(nt_status
)) {
190 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
191 if (lp_client_schannel()
192 && (ndr_syntax_id_equal(&table
->syntax_id
,
193 &ndr_table_netlogon
.syntax_id
))) {
194 /* Always try and create an schannel netlogon pipe. */
195 TALLOC_FREE(c
->netlogon_creds
);
196 nt_status
= cli_rpc_pipe_open_schannel(
197 cli
, c
->msg_ctx
, table
, NCACN_NP
,
198 DCERPC_AUTH_LEVEL_PRIVACY
, domain_name
,
199 &pipe_hnd
, c
, &c
->netlogon_creds
);
200 if (!NT_STATUS_IS_OK(nt_status
)) {
201 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
202 nt_errstr(nt_status
) ));
206 if (conn_flags
& NET_FLAGS_SEAL
) {
207 nt_status
= cli_rpc_pipe_open_generic_auth(
209 (conn_flags
& NET_FLAGS_TCP
) ?
210 NCACN_IP_TCP
: NCACN_NP
,
211 CRED_DONT_USE_KERBEROS
,
212 DCERPC_AUTH_TYPE_NTLMSSP
,
213 DCERPC_AUTH_LEVEL_PRIVACY
,
214 smbXcli_conn_remote_name(cli
->conn
),
215 lp_workgroup(), c
->opt_user_name
,
216 c
->opt_password
, &pipe_hnd
);
218 nt_status
= cli_rpc_pipe_open_noauth(
222 if (!NT_STATUS_IS_OK(nt_status
)) {
223 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
225 nt_errstr(nt_status
) ));
231 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
233 if (!NT_STATUS_IS_OK(nt_status
)) {
234 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
237 DEBUG(5, ("rpc command function succedded\n"));
240 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
242 TALLOC_FREE(pipe_hnd
);
247 /* close the connection only if it was opened here */
252 talloc_destroy(mem_ctx
);
257 * Force a change of the trust acccount password.
259 * All parameters are provided by the run_rpc_command function, except for
260 * argc, argv which are passed through.
262 * @param domain_sid The domain sid acquired from the remote server.
263 * @param cli A cli_state connected to the server.
264 * @param mem_ctx Talloc context, destroyed on completion of the function.
265 * @param argc Standard main() style argc.
266 * @param argv Standard main() style argv. Initial components are already
269 * @return Normal NTSTATUS return.
272 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
273 const struct dom_sid
*domain_sid
,
274 const char *domain_name
,
275 struct cli_state
*cli
,
276 struct rpc_pipe_client
*pipe_hnd
,
283 status
= trust_pw_change(c
->netlogon_creds
,
285 pipe_hnd
->binding_handle
,
286 c
->opt_target_workgroup
,
288 if (!NT_STATUS_IS_OK(status
)) {
289 d_fprintf(stderr
, _("Failed to change machine account password: %s\n"),
298 * Force a change of the trust acccount password.
300 * @param argc Standard main() style argc.
301 * @param argv Standard main() style argv. Initial components are already
304 * @return A shell status integer (0 for success).
307 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
309 if (c
->display_usage
) {
311 "net rpc changetrustpw\n"
314 _("Change the machine trust password"));
318 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
,
319 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
320 rpc_changetrustpw_internals
,
325 * Join a domain, the old way. This function exists to allow
326 * the message to be displayed when oldjoin was explicitly
327 * requested, but not when it was implied by "net rpc join".
329 * This uses 'machinename' as the inital password, and changes it.
331 * The password should be created with 'server manager' or equiv first.
333 * @param argc Standard main() style argc.
334 * @param argv Standard main() style argv. Initial components are already
337 * @return A shell status integer (0 for success).
340 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
342 struct libnet_JoinCtx
*r
= NULL
;
345 const char *domain
= lp_workgroup(); /* FIXME */
346 bool modify_config
= lp_config_backend_is_registry();
347 enum netr_SchannelType sec_chan_type
;
350 if (c
->display_usage
) {
353 " Join a domain the old way\n");
357 mem_ctx
= talloc_init("net_rpc_oldjoin");
362 werr
= libnet_init_JoinCtx(mem_ctx
, &r
);
363 if (!W_ERROR_IS_OK(werr
)) {
368 check what type of join - if the user want's to join as
369 a BDC, the server must agree that we are a BDC.
372 sec_chan_type
= get_sec_channel_type(argv
[0]);
374 sec_chan_type
= get_sec_channel_type(NULL
);
378 d_fprintf(stderr
, _("Could not initialise message context. "
379 "Try running as root\n"));
380 werr
= WERR_ACCESS_DENIED
;
384 pw
= talloc_strndup(r
, lp_netbios_name(), 14);
390 r
->in
.msg_ctx
= c
->msg_ctx
;
391 r
->in
.domain_name
= domain
;
392 r
->in
.secure_channel_type
= sec_chan_type
;
393 r
->in
.dc_name
= c
->opt_host
;
394 r
->in
.admin_account
= "";
395 r
->in
.admin_password
= strlower_talloc(r
, pw
);
396 if (r
->in
.admin_password
== NULL
) {
401 r
->in
.modify_config
= modify_config
;
402 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
403 WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
|
404 WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED
;
406 werr
= libnet_Join(mem_ctx
, r
);
407 if (!W_ERROR_IS_OK(werr
)) {
411 /* Check the short name of the domain */
413 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
414 d_printf("The workgroup in %s does not match the short\n", get_dyn_CONFIGFILE());
415 d_printf("domain name obtained from the server.\n");
416 d_printf("Using the name [%s] from the server.\n", r
->out
.netbios_domain_name
);
417 d_printf("You should set \"workgroup = %s\" in %s.\n",
418 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
421 d_printf("Using short domain name -- %s\n", r
->out
.netbios_domain_name
);
423 if (r
->out
.dns_domain_name
) {
424 d_printf("Joined '%s' to realm '%s'\n", r
->in
.machine_name
,
425 r
->out
.dns_domain_name
);
427 d_printf("Joined '%s' to domain '%s'\n", r
->in
.machine_name
,
428 r
->out
.netbios_domain_name
);
431 TALLOC_FREE(mem_ctx
);
436 if (c
->opt_flags
& NET_FLAGS_EXPECT_FALLBACK
) {
440 /* issue an overall failure message at the end. */
441 d_fprintf(stderr
, _("Failed to join domain: %s\n"),
442 r
&& r
->out
.error_string
? r
->out
.error_string
:
443 get_friendly_werror_msg(werr
));
446 TALLOC_FREE(mem_ctx
);
452 * check that a join is OK
454 * @return A shell status integer (0 for success)
457 int net_rpc_testjoin(struct net_context
*c
, int argc
, const char **argv
)
461 const char *domain
= c
->opt_target_workgroup
;
462 const char *dc
= c
->opt_host
;
464 if (c
->display_usage
) {
467 " Test if a join is OK\n");
471 mem_ctx
= talloc_init("net_rpc_testjoin");
477 struct netr_DsRGetDCNameInfo
*info
;
480 d_fprintf(stderr
, _("Could not initialise message context. "
481 "Try running as root\n"));
482 talloc_destroy(mem_ctx
);
486 status
= dsgetdcname(mem_ctx
,
493 if (!NT_STATUS_IS_OK(status
)) {
494 talloc_destroy(mem_ctx
);
498 dc
= strip_hostname(info
->dc_unc
);
501 /* Display success or failure */
502 status
= libnet_join_ok(c
->msg_ctx
,
506 if (!NT_STATUS_IS_OK(status
)) {
507 fprintf(stderr
,"Join to domain '%s' is not valid: %s\n",
508 domain
, nt_errstr(status
));
509 talloc_destroy(mem_ctx
);
513 printf("Join to '%s' is OK\n",domain
);
514 talloc_destroy(mem_ctx
);
520 * Join a domain using the administrator username and password
522 * @param argc Standard main() style argc
523 * @param argc Standard main() style argv. Initial components are already
524 * stripped. Currently not used.
525 * @return A shell status integer (0 for success)
529 static int net_rpc_join_newstyle(struct net_context
*c
, int argc
, const char **argv
)
531 struct libnet_JoinCtx
*r
= NULL
;
534 const char *domain
= lp_workgroup(); /* FIXME */
535 bool modify_config
= lp_config_backend_is_registry();
536 enum netr_SchannelType sec_chan_type
;
538 if (c
->display_usage
) {
541 " Join a domain the new way\n");
545 mem_ctx
= talloc_init("net_rpc_join_newstyle");
550 werr
= libnet_init_JoinCtx(mem_ctx
, &r
);
551 if (!W_ERROR_IS_OK(werr
)) {
556 check what type of join - if the user want's to join as
557 a BDC, the server must agree that we are a BDC.
560 sec_chan_type
= get_sec_channel_type(argv
[0]);
562 sec_chan_type
= get_sec_channel_type(NULL
);
566 d_fprintf(stderr
, _("Could not initialise message context. "
567 "Try running as root\n"));
568 werr
= WERR_ACCESS_DENIED
;
572 r
->in
.msg_ctx
= c
->msg_ctx
;
573 r
->in
.domain_name
= domain
;
574 r
->in
.secure_channel_type
= sec_chan_type
;
575 r
->in
.dc_name
= c
->opt_host
;
576 r
->in
.admin_account
= c
->opt_user_name
;
577 r
->in
.admin_password
= net_prompt_pass(c
, c
->opt_user_name
);
579 r
->in
.use_kerberos
= c
->opt_kerberos
;
580 r
->in
.modify_config
= modify_config
;
581 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
582 WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
583 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
585 werr
= libnet_Join(mem_ctx
, r
);
586 if (!W_ERROR_IS_OK(werr
)) {
590 /* Check the short name of the domain */
592 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
593 d_printf("The workgroup in %s does not match the short\n", get_dyn_CONFIGFILE());
594 d_printf("domain name obtained from the server.\n");
595 d_printf("Using the name [%s] from the server.\n", r
->out
.netbios_domain_name
);
596 d_printf("You should set \"workgroup = %s\" in %s.\n",
597 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
600 d_printf("Using short domain name -- %s\n", r
->out
.netbios_domain_name
);
602 if (r
->out
.dns_domain_name
) {
603 d_printf("Joined '%s' to realm '%s'\n", r
->in
.machine_name
,
604 r
->out
.dns_domain_name
);
606 d_printf("Joined '%s' to domain '%s'\n", r
->in
.machine_name
,
607 r
->out
.netbios_domain_name
);
610 TALLOC_FREE(mem_ctx
);
615 /* issue an overall failure message at the end. */
616 d_printf("Failed to join domain: %s\n",
617 r
&& r
->out
.error_string
? r
->out
.error_string
:
618 get_friendly_werror_msg(werr
));
620 TALLOC_FREE(mem_ctx
);
626 * 'net rpc join' entrypoint.
627 * @param argc Standard main() style argc.
628 * @param argv Standard main() style argv. Initial components are already
631 * Main 'net_rpc_join()' (where the admin username/password is used) is
633 * Try to just change the password, but if that doesn't work, use/prompt
634 * for a username/password.
637 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
641 if (c
->display_usage
) {
644 _("net rpc join -U <username>[%%password] <type>\n"
646 " username\tName of the admin user"
647 " password\tPassword of the admin user, will "
648 "prompt if not specified\n"
649 " type\tCan be one of the following:\n"
650 "\t\tMEMBER\tJoin as member server (default)\n"
651 "\t\tBDC\tJoin as BDC\n"
652 "\t\tPDC\tJoin as PDC\n"));
656 if (lp_server_role() == ROLE_STANDALONE
) {
657 d_printf(_("cannot join as standalone machine\n"));
661 if (strlen(lp_netbios_name()) > 15) {
662 d_printf(_("Our netbios name can be at most 15 chars long, "
663 "\"%s\" is %u chars long\n"),
664 lp_netbios_name(), (unsigned int)strlen(lp_netbios_name()));
668 c
->opt_flags
|= NET_FLAGS_EXPECT_FALLBACK
;
669 ret
= net_rpc_oldjoin(c
, argc
, argv
);
670 c
->opt_flags
&= ~NET_FLAGS_EXPECT_FALLBACK
;
675 return net_rpc_join_newstyle(c
, argc
, argv
);
679 * display info about a rpc domain
681 * All parameters are provided by the run_rpc_command function, except for
682 * argc, argv which are passed through.
684 * @param domain_sid The domain sid acquired from the remote server
685 * @param cli A cli_state connected to the server.
686 * @param mem_ctx Talloc context, destroyed on completion of the function.
687 * @param argc Standard main() style argc.
688 * @param argv Standard main() style argv. Initial components are already
691 * @return Normal NTSTATUS return.
694 NTSTATUS
rpc_info_internals(struct net_context
*c
,
695 const struct dom_sid
*domain_sid
,
696 const char *domain_name
,
697 struct cli_state
*cli
,
698 struct rpc_pipe_client
*pipe_hnd
,
703 struct policy_handle connect_pol
, domain_pol
;
704 NTSTATUS status
, result
;
705 union samr_DomainInfo
*info
= NULL
;
707 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
709 sid_to_fstring(sid_str
, domain_sid
);
711 /* Get sam policy handle */
712 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
714 MAXIMUM_ALLOWED_ACCESS
,
717 if (!NT_STATUS_IS_OK(status
)) {
718 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
723 if (!NT_STATUS_IS_OK(result
)) {
725 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
730 /* Get domain policy handle */
731 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
733 MAXIMUM_ALLOWED_ACCESS
,
734 discard_const_p(struct dom_sid2
, domain_sid
),
737 if (!NT_STATUS_IS_OK(status
)) {
738 d_fprintf(stderr
, _("Could not open domain: %s\n"),
742 if (!NT_STATUS_IS_OK(result
)) {
744 d_fprintf(stderr
, _("Could not open domain: %s\n"),
749 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
754 if (!NT_STATUS_IS_OK(status
)) {
758 if (NT_STATUS_IS_OK(result
)) {
759 d_printf(_("Domain Name: %s\n"),
760 info
->general
.domain_name
.string
);
761 d_printf(_("Domain SID: %s\n"), sid_str
);
762 d_printf(_("Sequence number: %llu\n"),
763 (unsigned long long)info
->general
.sequence_num
);
764 d_printf(_("Num users: %u\n"), info
->general
.num_users
);
765 d_printf(_("Num domain groups: %u\n"),info
->general
.num_groups
);
766 d_printf(_("Num local groups: %u\n"),info
->general
.num_aliases
);
774 * 'net rpc info' entrypoint.
775 * @param argc Standard main() style argc.
776 * @param argv Standard main() style argv. Initial components are already
780 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
782 if (c
->display_usage
) {
787 _("Display information about the domain"));
791 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
792 NET_FLAGS_PDC
, rpc_info_internals
,
797 * Fetch domain SID into the local secrets.tdb.
799 * All parameters are provided by the run_rpc_command function, except for
800 * argc, argv which are passed through.
802 * @param domain_sid The domain sid acquired from the remote server.
803 * @param cli A cli_state connected to the server.
804 * @param mem_ctx Talloc context, destroyed on completion of the function.
805 * @param argc Standard main() style argc.
806 * @param argv Standard main() style argv. Initial components are already
809 * @return Normal NTSTATUS return.
812 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
813 const struct dom_sid
*domain_sid
,
814 const char *domain_name
,
815 struct cli_state
*cli
,
816 struct rpc_pipe_client
*pipe_hnd
,
823 sid_to_fstring(sid_str
, domain_sid
);
824 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
825 sid_str
, domain_name
);
827 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
828 DEBUG(0,("Can't store domain SID\n"));
829 return NT_STATUS_UNSUCCESSFUL
;
836 * 'net rpc getsid' entrypoint.
837 * @param argc Standard main() style argc.
838 * @param argv Standard main() style argv. Initial components are already
842 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
844 int conn_flags
= NET_FLAGS_PDC
;
846 if (!c
->opt_user_specified
) {
847 conn_flags
|= NET_FLAGS_ANONYMOUS
;
850 if (c
->display_usage
) {
855 _("Fetch domain SID into local secrets.tdb"));
859 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
861 rpc_getsid_internals
,
865 /****************************************************************************/
868 * Basic usage function for 'net rpc user'.
869 * @param argc Standard main() style argc.
870 * @param argv Standard main() style argv. Initial components are already
874 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
876 return net_user_usage(c
, argc
, argv
);
880 * Add a new user to a remote RPC server.
882 * @param argc Standard main() style argc.
883 * @param argv Standard main() style argv. Initial components are already
886 * @return A shell status integer (0 for success).
889 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
891 NET_API_STATUS status
;
892 struct USER_INFO_1 info1
;
893 uint32_t parm_error
= 0;
895 if (argc
< 1 || c
->display_usage
) {
896 rpc_user_usage(c
, argc
, argv
);
902 info1
.usri1_name
= argv
[0];
904 info1
.usri1_password
= argv
[1];
907 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
910 d_fprintf(stderr
,_("Failed to add user '%s' with error: %s.\n"),
911 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
915 d_printf(_("Added user '%s'.\n"), argv
[0]);
922 * Rename a user on a remote RPC server.
924 * @param argc Standard main() style argc.
925 * @param argv Standard main() style argv. Initial components are already
928 * @return A shell status integer (0 for success).
931 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
933 NET_API_STATUS status
;
934 struct USER_INFO_0 u0
;
935 uint32_t parm_err
= 0;
937 if (argc
!= 2 || c
->display_usage
) {
938 rpc_user_usage(c
, argc
, argv
);
942 u0
.usri0_name
= argv
[1];
944 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
945 0, (uint8_t *)&u0
, &parm_err
);
948 _("Failed to rename user from %s to %s - %s\n"),
950 libnetapi_get_error_string(c
->netapi_ctx
, status
));
952 d_printf(_("Renamed user from %s to %s\n"), argv
[0], argv
[1]);
959 * Set a user's primary group
961 * @param argc Standard main() style argc.
962 * @param argv Standard main() style argv. Initial components are already
965 * @return A shell status integer (0 for success).
968 static int rpc_user_setprimarygroup(struct net_context
*c
, int argc
,
971 NET_API_STATUS status
;
973 struct GROUP_INFO_2
*g2
;
974 struct USER_INFO_1051 u1051
;
975 uint32_t parm_err
= 0;
977 if (argc
!= 2 || c
->display_usage
) {
978 rpc_user_usage(c
, argc
, argv
);
982 status
= NetGroupGetInfo(c
->opt_host
, argv
[1], 2, &buffer
);
984 d_fprintf(stderr
, _("Failed to find group name %s -- %s\n"),
986 libnetapi_get_error_string(c
->netapi_ctx
, status
));
989 g2
= (struct GROUP_INFO_2
*)buffer
;
991 u1051
.usri1051_primary_group_id
= g2
->grpi2_group_id
;
993 NetApiBufferFree(buffer
);
995 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1051,
996 (uint8_t *)&u1051
, &parm_err
);
999 _("Failed to set user's primary group %s to %s - "
1000 "%s\n"), argv
[0], argv
[1],
1001 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1003 d_printf(_("Set primary group of user %s to %s\n"), argv
[0],
1010 * Delete a user from a remote RPC server.
1012 * @param argc Standard main() style argc.
1013 * @param argv Standard main() style argv. Initial components are already
1016 * @return A shell status integer (0 for success).
1019 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
1021 NET_API_STATUS status
;
1023 if (argc
< 1 || c
->display_usage
) {
1024 rpc_user_usage(c
, argc
, argv
);
1028 status
= NetUserDel(c
->opt_host
, argv
[0]);
1031 d_fprintf(stderr
, _("Failed to delete user '%s' with: %s.\n"),
1033 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1036 d_printf(_("Deleted user '%s'.\n"), argv
[0]);
1043 * Set a user's password on a remote RPC server.
1045 * @param argc Standard main() style argc.
1046 * @param argv Standard main() style argv. Initial components are already
1049 * @return A shell status integer (0 for success).
1052 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
1054 NET_API_STATUS status
;
1055 char *prompt
= NULL
;
1056 struct USER_INFO_1003 u1003
;
1057 uint32_t parm_err
= 0;
1060 if (argc
< 1 || c
->display_usage
) {
1061 rpc_user_usage(c
, argc
, argv
);
1066 u1003
.usri1003_password
= argv
[1];
1068 char pwd
[256] = {0};
1069 ret
= asprintf(&prompt
, _("Enter new password for %s:"),
1075 ret
= samba_getpass(prompt
, pwd
, sizeof(pwd
), false, false);
1081 u1003
.usri1003_password
= talloc_strdup(c
, pwd
);
1082 if (u1003
.usri1003_password
== NULL
) {
1087 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
1089 /* Display results */
1092 _("Failed to set password for '%s' with error: %s.\n"),
1093 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1102 * List a user's groups from a remote RPC server.
1104 * @param argc Standard main() style argc.
1105 * @param argv Standard main() style argv. Initial components are already
1108 * @return A shell status integer (0 for success)
1111 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
1114 NET_API_STATUS status
;
1115 struct GROUP_USERS_INFO_0
*u0
= NULL
;
1116 uint32_t entries_read
= 0;
1117 uint32_t total_entries
= 0;
1121 if (argc
< 1 || c
->display_usage
) {
1122 rpc_user_usage(c
, argc
, argv
);
1126 status
= NetUserGetGroups(c
->opt_host
,
1129 (uint8_t **)(void *)&u0
,
1135 _("Failed to get groups for '%s' with error: %s.\n"),
1136 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1141 for (i
=0; i
< entries_read
; i
++) {
1142 printf("%s\n", u0
->grui0_name
);
1150 * List users on a remote RPC server.
1152 * All parameters are provided by the run_rpc_command function, except for
1153 * argc, argv which are passed through.
1155 * @param domain_sid The domain sid acquired from the remote server.
1156 * @param cli A cli_state connected to the server.
1157 * @param mem_ctx Talloc context, destroyed on completion of the function.
1158 * @param argc Standard main() style argc.
1159 * @param argv Standard main() style argv. Initial components are already
1162 * @return Normal NTSTATUS return.
1165 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
1167 NET_API_STATUS status
;
1168 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
1169 struct NET_DISPLAY_USER
*info
= NULL
;
1170 void *buffer
= NULL
;
1172 /* Query domain users */
1173 if (c
->opt_long_list_entries
)
1174 d_printf(_("\nUser name Comment"
1175 "\n-----------------------------\n"));
1177 uint32_t max_entries
, max_size
;
1179 dcerpc_get_query_dispinfo_params(
1180 loop_count
, &max_entries
, &max_size
);
1182 status
= NetQueryDisplayInformation(c
->opt_host
,
1189 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
1193 info
= (struct NET_DISPLAY_USER
*)buffer
;
1195 for (i
= 0; i
< num_entries
; i
++) {
1197 if (c
->opt_long_list_entries
)
1198 printf("%-21.21s %s\n", info
->usri1_name
,
1199 info
->usri1_comment
);
1201 printf("%s\n", info
->usri1_name
);
1205 NetApiBufferFree(buffer
);
1208 start_idx
+= num_entries
;
1210 } while (status
== ERROR_MORE_DATA
);
1216 * 'net rpc user' entrypoint.
1217 * @param argc Standard main() style argc.
1218 * @param argv Standard main() style argv. Initial components are already
1222 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
1224 NET_API_STATUS status
;
1226 struct functable func
[] = {
1231 N_("Add specified user"),
1232 N_("net rpc user add\n"
1233 " Add specified user")
1239 N_("List domain groups of user"),
1240 N_("net rpc user info\n"
1241 " List domain groups of user")
1247 N_("Remove specified user"),
1248 N_("net rpc user delete\n"
1249 " Remove specified user")
1255 N_("Change user password"),
1256 N_("net rpc user password\n"
1257 " Change user password")
1263 N_("Rename specified user"),
1264 N_("net rpc user rename\n"
1265 " Rename specified user")
1269 rpc_user_setprimarygroup
,
1271 "Set a user's primary group",
1272 "net rpc user setprimarygroup\n"
1273 " Set a user's primary group"
1275 {NULL
, NULL
, 0, NULL
, NULL
}
1278 status
= libnetapi_net_init(&c
->netapi_ctx
);
1282 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
1283 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
1284 if (c
->opt_kerberos
) {
1285 libnetapi_set_use_kerberos(c
->netapi_ctx
);
1289 if (c
->display_usage
) {
1294 _("List all users"));
1295 net_display_usage_from_functable(func
);
1299 return rpc_user_list(c
, argc
, argv
);
1302 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
1305 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
1306 TALLOC_CTX
*mem_ctx
,
1307 struct rpc_sh_ctx
*ctx
,
1308 struct rpc_pipe_client
*pipe_hnd
,
1309 int argc
, const char **argv
)
1311 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
1314 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
1315 TALLOC_CTX
*mem_ctx
,
1316 struct rpc_sh_ctx
*ctx
,
1317 struct rpc_pipe_client
*pipe_hnd
,
1318 int argc
, const char **argv
)
1320 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1323 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1324 TALLOC_CTX
*mem_ctx
,
1325 struct rpc_sh_ctx
*ctx
,
1326 struct rpc_pipe_client
*pipe_hnd
,
1327 int argc
, const char **argv
,
1329 struct net_context
*c
,
1330 TALLOC_CTX
*mem_ctx
,
1331 struct rpc_sh_ctx
*ctx
,
1332 struct rpc_pipe_client
*pipe_hnd
,
1333 struct policy_handle
*user_hnd
,
1334 int argc
, const char **argv
))
1336 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1337 NTSTATUS status
, result
;
1340 enum lsa_SidType type
;
1341 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1344 d_fprintf(stderr
, "%s %s <username>\n", _("Usage:"),
1346 return NT_STATUS_INVALID_PARAMETER
;
1349 ZERO_STRUCT(connect_pol
);
1350 ZERO_STRUCT(domain_pol
);
1351 ZERO_STRUCT(user_pol
);
1353 status
= net_rpc_lookup_name(c
, mem_ctx
, ctx
->cli
,
1354 argv
[0], NULL
, NULL
, &sid
, &type
);
1355 if (!NT_STATUS_IS_OK(status
)) {
1356 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1361 if (type
!= SID_NAME_USER
) {
1362 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1363 sid_type_lookup(type
));
1364 status
= NT_STATUS_NO_SUCH_USER
;
1368 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1369 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1370 status
= NT_STATUS_NO_SUCH_USER
;
1374 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1376 MAXIMUM_ALLOWED_ACCESS
,
1379 if (!NT_STATUS_IS_OK(status
)) {
1382 if (!NT_STATUS_IS_OK(result
)) {
1387 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1389 MAXIMUM_ALLOWED_ACCESS
,
1393 if (!NT_STATUS_IS_OK(status
)) {
1396 if (!NT_STATUS_IS_OK(result
)) {
1401 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1403 MAXIMUM_ALLOWED_ACCESS
,
1407 if (!NT_STATUS_IS_OK(status
)) {
1410 if (!NT_STATUS_IS_OK(result
)) {
1415 status
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1418 if (is_valid_policy_hnd(&user_pol
)) {
1419 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1421 if (is_valid_policy_hnd(&domain_pol
)) {
1422 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1424 if (is_valid_policy_hnd(&connect_pol
)) {
1425 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1430 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1431 TALLOC_CTX
*mem_ctx
,
1432 struct rpc_sh_ctx
*ctx
,
1433 struct rpc_pipe_client
*pipe_hnd
,
1434 struct policy_handle
*user_hnd
,
1435 int argc
, const char **argv
)
1437 NTSTATUS status
, result
;
1438 union samr_UserInfo
*info
= NULL
;
1439 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1442 d_fprintf(stderr
, "%s %s show <username>\n", _("Usage:"),
1444 return NT_STATUS_INVALID_PARAMETER
;
1447 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1452 if (!NT_STATUS_IS_OK(status
)) {
1455 if (!NT_STATUS_IS_OK(result
)) {
1459 d_printf(_("user rid: %d, group rid: %d\n"),
1461 info
->info21
.primary_gid
);
1466 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1467 TALLOC_CTX
*mem_ctx
,
1468 struct rpc_sh_ctx
*ctx
,
1469 struct rpc_pipe_client
*pipe_hnd
,
1470 int argc
, const char **argv
)
1472 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1473 rpc_sh_user_show_internals
);
1476 #define FETCHSTR(name, rec) \
1477 do { if (strequal(ctx->thiscmd, name)) { \
1478 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1481 #define SETSTR(name, rec, flag) \
1482 do { if (strequal(ctx->thiscmd, name)) { \
1483 init_lsa_String(&(info->info21.rec), argv[0]); \
1484 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1487 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1488 TALLOC_CTX
*mem_ctx
,
1489 struct rpc_sh_ctx
*ctx
,
1490 struct rpc_pipe_client
*pipe_hnd
,
1491 struct policy_handle
*user_hnd
,
1492 int argc
, const char **argv
)
1494 NTSTATUS status
, result
;
1495 const char *username
;
1496 const char *oldval
= "";
1497 union samr_UserInfo
*info
= NULL
;
1498 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1501 d_fprintf(stderr
, "%s %s <username> [new value|NULL]\n",
1502 _("Usage:"), ctx
->whoami
);
1503 return NT_STATUS_INVALID_PARAMETER
;
1506 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1511 if (!NT_STATUS_IS_OK(status
)) {
1514 if (!NT_STATUS_IS_OK(result
)) {
1518 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1520 FETCHSTR("fullname", full_name
);
1521 FETCHSTR("homedir", home_directory
);
1522 FETCHSTR("homedrive", home_drive
);
1523 FETCHSTR("logonscript", logon_script
);
1524 FETCHSTR("profilepath", profile_path
);
1525 FETCHSTR("description", description
);
1528 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1532 if (strcmp(argv
[0], "NULL") == 0) {
1536 ZERO_STRUCT(info
->info21
);
1538 SETSTR("fullname", full_name
, FULL_NAME
);
1539 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1540 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1541 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1542 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1543 SETSTR("description", description
, DESCRIPTION
);
1545 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1550 if (!NT_STATUS_IS_OK(status
)) {
1556 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1557 ctx
->thiscmd
, oldval
, argv
[0]);
1564 #define HANDLEFLG(name, rec) \
1565 do { if (strequal(ctx->thiscmd, name)) { \
1566 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1568 newflags = oldflags | ACB_##rec; \
1570 newflags = oldflags & ~ACB_##rec; \
1573 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1574 TALLOC_CTX
*mem_ctx
,
1575 struct rpc_sh_ctx
*ctx
,
1576 struct rpc_pipe_client
*pipe_hnd
,
1577 int argc
, const char **argv
)
1579 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1580 rpc_sh_user_str_edit_internals
);
1583 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1584 TALLOC_CTX
*mem_ctx
,
1585 struct rpc_sh_ctx
*ctx
,
1586 struct rpc_pipe_client
*pipe_hnd
,
1587 struct policy_handle
*user_hnd
,
1588 int argc
, const char **argv
)
1590 NTSTATUS status
, result
;
1591 const char *username
;
1592 const char *oldval
= "unknown";
1593 uint32 oldflags
, newflags
;
1595 union samr_UserInfo
*info
= NULL
;
1596 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1599 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1600 !strequal(argv
[0], "no"))) {
1601 /* TRANSATORS: The yes|no here are program keywords. Please do
1603 d_fprintf(stderr
, _("Usage: %s <username> [yes|no]\n"),
1605 return NT_STATUS_INVALID_PARAMETER
;
1608 newval
= strequal(argv
[0], "yes");
1610 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1615 if (!NT_STATUS_IS_OK(status
)) {
1618 if (!NT_STATUS_IS_OK(result
)) {
1622 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1623 oldflags
= info
->info21
.acct_flags
;
1624 newflags
= info
->info21
.acct_flags
;
1626 HANDLEFLG("disabled", DISABLED
);
1627 HANDLEFLG("pwnotreq", PWNOTREQ
);
1628 HANDLEFLG("autolock", AUTOLOCK
);
1629 HANDLEFLG("pwnoexp", PWNOEXP
);
1632 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1637 ZERO_STRUCT(info
->info21
);
1639 info
->info21
.acct_flags
= newflags
;
1640 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1642 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1647 if (!NT_STATUS_IS_OK(status
)) {
1651 if (NT_STATUS_IS_OK(result
)) {
1652 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1653 ctx
->thiscmd
, oldval
, argv
[0]);
1661 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1662 TALLOC_CTX
*mem_ctx
,
1663 struct rpc_sh_ctx
*ctx
,
1664 struct rpc_pipe_client
*pipe_hnd
,
1665 int argc
, const char **argv
)
1667 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1668 rpc_sh_user_flag_edit_internals
);
1671 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1672 TALLOC_CTX
*mem_ctx
,
1673 struct rpc_sh_ctx
*ctx
)
1675 static struct rpc_sh_cmd cmds
[] = {
1677 { "fullname", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1678 N_("Show/Set a user's full name") },
1680 { "homedir", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1681 N_("Show/Set a user's home directory") },
1683 { "homedrive", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1684 N_("Show/Set a user's home drive") },
1686 { "logonscript", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1687 N_("Show/Set a user's logon script") },
1689 { "profilepath", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1690 N_("Show/Set a user's profile path") },
1692 { "description", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1693 N_("Show/Set a user's description") },
1695 { "disabled", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1696 N_("Show/Set whether a user is disabled") },
1698 { "autolock", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1699 N_("Show/Set whether a user locked out") },
1701 { "pwnotreq", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1702 N_("Show/Set whether a user does not need a password") },
1704 { "pwnoexp", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1705 N_("Show/Set whether a user's password does not expire") },
1707 { NULL
, NULL
, 0, NULL
, NULL
}
1713 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1714 TALLOC_CTX
*mem_ctx
,
1715 struct rpc_sh_ctx
*ctx
)
1717 static struct rpc_sh_cmd cmds
[] = {
1719 { "list", NULL
, &ndr_table_samr
, rpc_sh_user_list
,
1720 N_("List available users") },
1722 { "info", NULL
, &ndr_table_samr
, rpc_sh_user_info
,
1723 N_("List the domain groups a user is member of") },
1725 { "show", NULL
, &ndr_table_samr
, rpc_sh_user_show
,
1726 N_("Show info about a user") },
1728 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1729 N_("Show/Modify a user's fields") },
1731 { NULL
, NULL
, 0, NULL
, NULL
}
1737 /****************************************************************************/
1740 * Basic usage function for 'net rpc group'.
1741 * @param argc Standard main() style argc.
1742 * @param argv Standard main() style argv. Initial components are already
1746 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1748 return net_group_usage(c
, argc
, argv
);
1752 * Delete group on a remote RPC server.
1754 * All parameters are provided by the run_rpc_command function, except for
1755 * argc, argv which are passed through.
1757 * @param domain_sid The domain sid acquired from the remote server.
1758 * @param cli A cli_state connected to the server.
1759 * @param mem_ctx Talloc context, destroyed on completion of the function.
1760 * @param argc Standard main() style argc.
1761 * @param argv Standard main() style argv. Initial components are already
1764 * @return Normal NTSTATUS return.
1767 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1768 const struct dom_sid
*domain_sid
,
1769 const char *domain_name
,
1770 struct cli_state
*cli
,
1771 struct rpc_pipe_client
*pipe_hnd
,
1772 TALLOC_CTX
*mem_ctx
,
1776 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1777 bool group_is_primary
= false;
1778 NTSTATUS status
, result
;
1780 struct samr_RidAttrArray
*rids
= NULL
;
1783 /* struct samr_RidWithAttribute *user_gids; */
1784 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1786 struct samr_Ids group_rids
, name_types
;
1787 struct lsa_String lsa_acct_name
;
1788 union samr_UserInfo
*info
= NULL
;
1790 if (argc
< 1 || c
->display_usage
) {
1791 rpc_group_usage(c
, argc
,argv
);
1792 return NT_STATUS_OK
; /* ok? */
1795 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1797 MAXIMUM_ALLOWED_ACCESS
,
1800 if (!NT_STATUS_IS_OK(status
)) {
1801 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1805 if (!NT_STATUS_IS_OK(result
)) {
1807 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1811 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1813 MAXIMUM_ALLOWED_ACCESS
,
1814 discard_const_p(struct dom_sid2
, domain_sid
),
1817 if (!NT_STATUS_IS_OK(status
)) {
1818 d_fprintf(stderr
, _("Request open_domain failed\n"));
1822 if (!NT_STATUS_IS_OK(result
)) {
1824 d_fprintf(stderr
, _("Request open_domain failed\n"));
1828 init_lsa_String(&lsa_acct_name
, argv
[0]);
1830 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1842 if (!NT_STATUS_IS_OK(result
)) {
1844 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1847 if (group_rids
.count
!= 1) {
1848 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1851 if (name_types
.count
!= 1) {
1852 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1856 switch (name_types
.ids
[0])
1858 case SID_NAME_DOM_GRP
:
1859 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
1861 MAXIMUM_ALLOWED_ACCESS
,
1865 if (!NT_STATUS_IS_OK(status
)) {
1866 d_fprintf(stderr
, _("Request open_group failed"));
1870 if (!NT_STATUS_IS_OK(result
)) {
1872 d_fprintf(stderr
, _("Request open_group failed"));
1876 group_rid
= group_rids
.ids
[0];
1878 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
1882 if (!NT_STATUS_IS_OK(status
)) {
1884 _("Unable to query group members of %s"),
1889 if (!NT_STATUS_IS_OK(result
)) {
1892 _("Unable to query group members of %s"),
1897 if (c
->opt_verbose
) {
1899 _("Domain Group %s (rid: %d) has %d members\n"),
1900 argv
[0],group_rid
, rids
->count
);
1903 /* Check if group is anyone's primary group */
1904 for (i
= 0; i
< rids
->count
; i
++)
1906 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1908 MAXIMUM_ALLOWED_ACCESS
,
1912 if (!NT_STATUS_IS_OK(status
)) {
1914 _("Unable to open group member %d\n"),
1919 if (!NT_STATUS_IS_OK(result
)) {
1922 _("Unable to open group member %d\n"),
1927 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1932 if (!NT_STATUS_IS_OK(status
)) {
1934 _("Unable to lookup userinfo for group "
1940 if (!NT_STATUS_IS_OK(result
)) {
1943 _("Unable to lookup userinfo for group "
1949 if (info
->info21
.primary_gid
== group_rid
) {
1950 if (c
->opt_verbose
) {
1951 d_printf(_("Group is primary group "
1953 info
->info21
.account_name
.string
);
1955 group_is_primary
= true;
1958 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1961 if (group_is_primary
) {
1962 d_fprintf(stderr
, _("Unable to delete group because "
1963 "some of it's members have it as primary "
1965 status
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1969 /* remove all group members */
1970 for (i
= 0; i
< rids
->count
; i
++)
1973 d_printf(_("Remove group member %d..."),
1975 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
1979 if (!NT_STATUS_IS_OK(status
)) {
1983 if (NT_STATUS_IS_OK(result
)) {
1985 d_printf(_("ok\n"));
1988 d_printf("%s\n", _("failed"));
1993 status
= dcerpc_samr_DeleteDomainGroup(b
, mem_ctx
,
1996 if (!NT_STATUS_IS_OK(status
)) {
2003 /* removing a local group is easier... */
2004 case SID_NAME_ALIAS
:
2005 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2007 MAXIMUM_ALLOWED_ACCESS
,
2011 if (!NT_STATUS_IS_OK(status
)) {
2012 d_fprintf(stderr
, _("Request open_alias failed\n"));
2015 if (!NT_STATUS_IS_OK(result
)) {
2017 d_fprintf(stderr
, _("Request open_alias failed\n"));
2021 status
= dcerpc_samr_DeleteDomAlias(b
, mem_ctx
,
2024 if (!NT_STATUS_IS_OK(status
)) {
2032 d_fprintf(stderr
, _("%s is of type %s. This command is only "
2033 "for deleting local or global groups\n"),
2034 argv
[0],sid_type_lookup(name_types
.ids
[0]));
2035 status
= NT_STATUS_UNSUCCESSFUL
;
2039 if (NT_STATUS_IS_OK(status
)) {
2041 d_printf(_("Deleted %s '%s'\n"),
2042 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
2044 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
2045 get_friendly_nt_error_msg(status
));
2053 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
2055 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2056 rpc_group_delete_internals
, argc
,argv
);
2059 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2061 NET_API_STATUS status
;
2062 struct GROUP_INFO_1 info1
;
2063 uint32_t parm_error
= 0;
2065 if (argc
!= 1 || c
->display_usage
) {
2066 rpc_group_usage(c
, argc
, argv
);
2072 info1
.grpi1_name
= argv
[0];
2073 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2074 info1
.grpi1_comment
= c
->opt_comment
;
2077 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2081 _("Failed to add group '%s' with error: %s.\n"),
2082 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2086 d_printf(_("Added group '%s'.\n"), argv
[0]);
2092 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2094 NET_API_STATUS status
;
2095 struct LOCALGROUP_INFO_1 info1
;
2096 uint32_t parm_error
= 0;
2098 if (argc
!= 1 || c
->display_usage
) {
2099 rpc_group_usage(c
, argc
, argv
);
2105 info1
.lgrpi1_name
= argv
[0];
2106 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2107 info1
.lgrpi1_comment
= c
->opt_comment
;
2110 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2114 _("Failed to add alias '%s' with error: %s.\n"),
2115 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2119 d_printf(_("Added alias '%s'.\n"), argv
[0]);
2125 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
2127 if (c
->opt_localgroup
)
2128 return rpc_alias_add_internals(c
, argc
, argv
);
2130 return rpc_group_add_internals(c
, argc
, argv
);
2133 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
2134 TALLOC_CTX
*mem_ctx
,
2136 struct dom_sid
*sid
,
2137 enum lsa_SidType
*type
)
2139 struct dom_sid
*sids
= NULL
;
2140 enum lsa_SidType
*types
= NULL
;
2141 struct rpc_pipe_client
*pipe_hnd
= NULL
;
2142 struct policy_handle lsa_pol
;
2143 NTSTATUS status
, result
;
2144 struct dcerpc_binding_handle
*b
;
2146 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
2148 if (!NT_STATUS_IS_OK(status
)) {
2152 b
= pipe_hnd
->binding_handle
;
2154 status
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
2155 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2157 if (!NT_STATUS_IS_OK(status
)) {
2161 status
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
2162 &name
, NULL
, 1, &sids
, &types
);
2164 if (NT_STATUS_IS_OK(status
)) {
2165 sid_copy(sid
, &sids
[0]);
2169 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
2173 TALLOC_FREE(pipe_hnd
);
2176 if (!NT_STATUS_IS_OK(status
) && (strncasecmp_m(name
, "S-", 2) == 0)) {
2178 /* Try as S-1-5-whatever */
2180 struct dom_sid tmp_sid
;
2182 if (string_to_sid(&tmp_sid
, name
)) {
2183 sid_copy(sid
, &tmp_sid
);
2184 *type
= SID_NAME_UNKNOWN
;
2185 status
= NT_STATUS_OK
;
2192 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2193 TALLOC_CTX
*mem_ctx
,
2194 const struct dom_sid
*group_sid
,
2197 struct policy_handle connect_pol
, domain_pol
;
2198 NTSTATUS status
, result
;
2200 struct policy_handle group_pol
;
2201 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2203 struct samr_Ids rids
, rid_types
;
2204 struct lsa_String lsa_acct_name
;
2208 sid_copy(&sid
, group_sid
);
2210 if (!sid_split_rid(&sid
, &group_rid
)) {
2211 return NT_STATUS_UNSUCCESSFUL
;
2214 /* Get sam policy handle */
2215 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2217 MAXIMUM_ALLOWED_ACCESS
,
2220 if (!NT_STATUS_IS_OK(status
)) {
2223 if (!NT_STATUS_IS_OK(result
)) {
2227 /* Get domain policy handle */
2228 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2230 MAXIMUM_ALLOWED_ACCESS
,
2234 if (!NT_STATUS_IS_OK(status
)) {
2237 if (!NT_STATUS_IS_OK(result
)) {
2241 init_lsa_String(&lsa_acct_name
, member
);
2243 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2250 if (!NT_STATUS_IS_OK(status
)) {
2251 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2256 if (!NT_STATUS_IS_OK(result
)) {
2258 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2262 if (rids
.count
!= 1) {
2263 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2266 if (rid_types
.count
!= 1) {
2267 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2271 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2273 MAXIMUM_ALLOWED_ACCESS
,
2277 if (!NT_STATUS_IS_OK(status
)) {
2281 if (!NT_STATUS_IS_OK(result
)) {
2286 status
= dcerpc_samr_AddGroupMember(b
, mem_ctx
,
2289 0x0005, /* unknown flags */
2291 if (!NT_STATUS_IS_OK(status
)) {
2298 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2302 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2303 struct cli_state
*cli
,
2304 TALLOC_CTX
*mem_ctx
,
2305 const struct dom_sid
*alias_sid
,
2308 struct policy_handle connect_pol
, domain_pol
;
2309 NTSTATUS status
, result
;
2311 struct policy_handle alias_pol
;
2312 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2314 struct dom_sid member_sid
;
2315 enum lsa_SidType member_type
;
2319 sid_copy(&sid
, alias_sid
);
2321 if (!sid_split_rid(&sid
, &alias_rid
)) {
2322 return NT_STATUS_UNSUCCESSFUL
;
2325 result
= get_sid_from_name(cli
, mem_ctx
,
2326 member
, &member_sid
, &member_type
);
2328 if (!NT_STATUS_IS_OK(result
)) {
2329 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2334 /* Get sam policy handle */
2335 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2337 MAXIMUM_ALLOWED_ACCESS
,
2340 if (!NT_STATUS_IS_OK(status
)) {
2343 if (!NT_STATUS_IS_OK(result
)) {
2348 /* Get domain policy handle */
2349 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2351 MAXIMUM_ALLOWED_ACCESS
,
2355 if (!NT_STATUS_IS_OK(status
)) {
2358 if (!NT_STATUS_IS_OK(result
)) {
2363 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2365 MAXIMUM_ALLOWED_ACCESS
,
2369 if (!NT_STATUS_IS_OK(status
)) {
2372 if (!NT_STATUS_IS_OK(result
)) {
2376 status
= dcerpc_samr_AddAliasMember(b
, mem_ctx
,
2380 if (!NT_STATUS_IS_OK(status
)) {
2387 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2391 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
2392 const struct dom_sid
*domain_sid
,
2393 const char *domain_name
,
2394 struct cli_state
*cli
,
2395 struct rpc_pipe_client
*pipe_hnd
,
2396 TALLOC_CTX
*mem_ctx
,
2400 struct dom_sid group_sid
;
2401 enum lsa_SidType group_type
;
2403 if (argc
!= 2 || c
->display_usage
) {
2406 _("net rpc group addmem <group> <member>\n"
2407 " Add a member to a group\n"
2408 " group\tGroup to add member to\n"
2409 " member\tMember to add to group\n"));
2410 return NT_STATUS_UNSUCCESSFUL
;
2413 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2414 &group_sid
, &group_type
))) {
2415 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2417 return NT_STATUS_UNSUCCESSFUL
;
2420 if (group_type
== SID_NAME_DOM_GRP
) {
2421 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2422 &group_sid
, argv
[1]);
2424 if (!NT_STATUS_IS_OK(result
)) {
2425 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2426 argv
[1], argv
[0], nt_errstr(result
));
2431 if (group_type
== SID_NAME_ALIAS
) {
2432 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2433 &group_sid
, argv
[1]);
2435 if (!NT_STATUS_IS_OK(result
)) {
2436 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2437 argv
[1], argv
[0], nt_errstr(result
));
2442 d_fprintf(stderr
, _("Can only add members to global or local groups "
2443 "which %s is not\n"), argv
[0]);
2445 return NT_STATUS_UNSUCCESSFUL
;
2448 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
2450 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2451 rpc_group_addmem_internals
,
2455 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
2456 struct rpc_pipe_client
*pipe_hnd
,
2457 TALLOC_CTX
*mem_ctx
,
2458 const struct dom_sid
*group_sid
,
2461 struct policy_handle connect_pol
, domain_pol
;
2462 NTSTATUS status
, result
;
2464 struct policy_handle group_pol
;
2465 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2467 struct samr_Ids rids
, rid_types
;
2468 struct lsa_String lsa_acct_name
;
2472 sid_copy(&sid
, group_sid
);
2474 if (!sid_split_rid(&sid
, &group_rid
))
2475 return NT_STATUS_UNSUCCESSFUL
;
2477 /* Get sam policy handle */
2478 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2480 MAXIMUM_ALLOWED_ACCESS
,
2483 if (!NT_STATUS_IS_OK(status
)) {
2486 if (!NT_STATUS_IS_OK(result
)) {
2491 /* Get domain policy handle */
2492 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2494 MAXIMUM_ALLOWED_ACCESS
,
2498 if (!NT_STATUS_IS_OK(status
)) {
2501 if (!NT_STATUS_IS_OK(result
)) {
2505 init_lsa_String(&lsa_acct_name
, member
);
2507 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2514 if (!NT_STATUS_IS_OK(status
)) {
2515 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2520 if (!NT_STATUS_IS_OK(result
)) {
2522 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2526 if (rids
.count
!= 1) {
2527 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2530 if (rid_types
.count
!= 1) {
2531 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2535 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2537 MAXIMUM_ALLOWED_ACCESS
,
2541 if (!NT_STATUS_IS_OK(status
)) {
2544 if (!NT_STATUS_IS_OK(result
)) {
2549 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
2553 if (!NT_STATUS_IS_OK(status
)) {
2559 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2563 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2564 struct cli_state
*cli
,
2565 TALLOC_CTX
*mem_ctx
,
2566 const struct dom_sid
*alias_sid
,
2569 struct policy_handle connect_pol
, domain_pol
;
2570 NTSTATUS status
, result
;
2572 struct policy_handle alias_pol
;
2573 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2575 struct dom_sid member_sid
;
2576 enum lsa_SidType member_type
;
2580 sid_copy(&sid
, alias_sid
);
2582 if (!sid_split_rid(&sid
, &alias_rid
))
2583 return NT_STATUS_UNSUCCESSFUL
;
2585 result
= get_sid_from_name(cli
, mem_ctx
,
2586 member
, &member_sid
, &member_type
);
2588 if (!NT_STATUS_IS_OK(result
)) {
2589 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2594 /* Get sam policy handle */
2595 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2597 MAXIMUM_ALLOWED_ACCESS
,
2600 if (!NT_STATUS_IS_OK(status
)) {
2603 if (!NT_STATUS_IS_OK(result
)) {
2608 /* Get domain policy handle */
2609 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2611 MAXIMUM_ALLOWED_ACCESS
,
2615 if (!NT_STATUS_IS_OK(status
)) {
2618 if (!NT_STATUS_IS_OK(result
)) {
2623 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2625 MAXIMUM_ALLOWED_ACCESS
,
2629 if (!NT_STATUS_IS_OK(status
)) {
2633 if (!NT_STATUS_IS_OK(result
)) {
2637 status
= dcerpc_samr_DeleteAliasMember(b
, mem_ctx
,
2642 if (!NT_STATUS_IS_OK(status
)) {
2649 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2653 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2654 const struct dom_sid
*domain_sid
,
2655 const char *domain_name
,
2656 struct cli_state
*cli
,
2657 struct rpc_pipe_client
*pipe_hnd
,
2658 TALLOC_CTX
*mem_ctx
,
2662 struct dom_sid group_sid
;
2663 enum lsa_SidType group_type
;
2665 if (argc
!= 2 || c
->display_usage
) {
2668 _("net rpc group delmem <group> <member>\n"
2669 " Delete a member from a group\n"
2670 " group\tGroup to delete member from\n"
2671 " member\tMember to delete from group\n"));
2672 return NT_STATUS_UNSUCCESSFUL
;
2675 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2676 &group_sid
, &group_type
))) {
2677 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2679 return NT_STATUS_UNSUCCESSFUL
;
2682 if (group_type
== SID_NAME_DOM_GRP
) {
2683 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2684 &group_sid
, argv
[1]);
2686 if (!NT_STATUS_IS_OK(result
)) {
2687 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2688 argv
[1], argv
[0], nt_errstr(result
));
2693 if (group_type
== SID_NAME_ALIAS
) {
2694 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2695 &group_sid
, argv
[1]);
2697 if (!NT_STATUS_IS_OK(result
)) {
2698 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2699 argv
[1], argv
[0], nt_errstr(result
));
2704 d_fprintf(stderr
, _("Can only delete members from global or local "
2705 "groups which %s is not\n"), argv
[0]);
2707 return NT_STATUS_UNSUCCESSFUL
;
2710 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2712 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2713 rpc_group_delmem_internals
,
2718 * List groups on a remote RPC server.
2720 * All parameters are provided by the run_rpc_command function, except for
2721 * argc, argv which are passes through.
2723 * @param domain_sid The domain sid acquired from the remote server.
2724 * @param cli A cli_state connected to the server.
2725 * @param mem_ctx Talloc context, destroyed on completion of the function.
2726 * @param argc Standard main() style argc.
2727 * @param argv Standard main() style argv. Initial components are already
2730 * @return Normal NTSTATUS return.
2733 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2734 const struct dom_sid
*domain_sid
,
2735 const char *domain_name
,
2736 struct cli_state
*cli
,
2737 struct rpc_pipe_client
*pipe_hnd
,
2738 TALLOC_CTX
*mem_ctx
,
2742 struct policy_handle connect_pol
, domain_pol
;
2743 NTSTATUS status
, result
;
2744 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2745 struct samr_SamArray
*groups
= NULL
;
2746 bool global
= false;
2748 bool builtin
= false;
2749 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2751 if (c
->display_usage
) {
2754 _("net rpc group list [global] [local] [builtin]\n"
2755 " List groups on RPC server\n"
2756 " global\tList global groups\n"
2757 " local\tList local groups\n"
2758 " builtin\tList builtin groups\n"
2759 " If none of global, local or builtin is "
2760 "specified, all three options are considered "
2762 return NT_STATUS_OK
;
2771 for (i
=0; i
<argc
; i
++) {
2772 if (strequal(argv
[i
], "global"))
2775 if (strequal(argv
[i
], "local"))
2778 if (strequal(argv
[i
], "builtin"))
2782 /* Get sam policy handle */
2784 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2786 MAXIMUM_ALLOWED_ACCESS
,
2789 if (!NT_STATUS_IS_OK(status
)) {
2792 if (!NT_STATUS_IS_OK(result
)) {
2797 /* Get domain policy handle */
2799 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2801 MAXIMUM_ALLOWED_ACCESS
,
2802 discard_const_p(struct dom_sid2
, domain_sid
),
2805 if (!NT_STATUS_IS_OK(status
)) {
2808 if (!NT_STATUS_IS_OK(result
)) {
2813 /* Query domain groups */
2814 if (c
->opt_long_list_entries
)
2815 d_printf(_("\nGroup name Comment"
2816 "\n-----------------------------\n"));
2818 uint32_t max_size
, total_size
, returned_size
;
2819 union samr_DispInfo info
;
2823 dcerpc_get_query_dispinfo_params(
2824 loop_count
, &max_entries
, &max_size
);
2826 status
= dcerpc_samr_QueryDisplayInfo(b
, mem_ctx
,
2836 if (!NT_STATUS_IS_OK(status
)) {
2839 num_entries
= info
.info3
.count
;
2840 start_idx
+= info
.info3
.count
;
2842 if (!NT_STATUS_IS_OK(result
) &&
2843 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2846 for (i
= 0; i
< num_entries
; i
++) {
2848 const char *group
= NULL
;
2849 const char *desc
= NULL
;
2851 group
= info
.info3
.entries
[i
].account_name
.string
;
2852 desc
= info
.info3
.entries
[i
].description
.string
;
2854 if (c
->opt_long_list_entries
)
2855 printf("%-21.21s %-50.50s\n",
2858 printf("%s\n", group
);
2860 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2861 /* query domain aliases */
2866 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2873 if (!NT_STATUS_IS_OK(status
)) {
2876 if (!NT_STATUS_IS_OK(result
) &&
2877 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2880 for (i
= 0; i
< num_entries
; i
++) {
2882 const char *description
= NULL
;
2884 if (c
->opt_long_list_entries
) {
2886 struct policy_handle alias_pol
;
2887 union samr_AliasInfo
*info
= NULL
;
2890 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2893 groups
->entries
[i
].idx
,
2896 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2897 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
2902 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2903 status
= dcerpc_samr_Close(b
, mem_ctx
,
2906 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2907 description
= info
->description
.string
;
2913 if (description
!= NULL
) {
2914 printf("%-21.21s %-50.50s\n",
2915 groups
->entries
[i
].name
.string
,
2918 printf("%s\n", groups
->entries
[i
].name
.string
);
2921 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2922 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2923 /* Get builtin policy handle */
2925 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2927 MAXIMUM_ALLOWED_ACCESS
,
2928 discard_const_p(struct dom_sid2
, &global_sid_Builtin
),
2931 if (!NT_STATUS_IS_OK(status
)) {
2934 if (!NT_STATUS_IS_OK(result
)) {
2939 /* query builtin aliases */
2942 if (!builtin
) break;
2944 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2951 if (!NT_STATUS_IS_OK(status
)) {
2954 if (!NT_STATUS_IS_OK(result
) &&
2955 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
2960 for (i
= 0; i
< num_entries
; i
++) {
2962 const char *description
= NULL
;
2964 if (c
->opt_long_list_entries
) {
2966 struct policy_handle alias_pol
;
2967 union samr_AliasInfo
*info
= NULL
;
2970 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2973 groups
->entries
[i
].idx
,
2976 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2977 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
2982 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2983 status
= dcerpc_samr_Close(b
, mem_ctx
,
2986 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2987 description
= info
->description
.string
;
2993 if (description
!= NULL
) {
2994 printf("%-21.21s %-50.50s\n",
2995 groups
->entries
[i
].name
.string
,
2998 printf("%s\n", groups
->entries
[i
].name
.string
);
3001 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3009 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
3011 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3012 rpc_group_list_internals
,
3016 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
3017 struct rpc_pipe_client
*pipe_hnd
,
3018 TALLOC_CTX
*mem_ctx
,
3019 const char *domain_name
,
3020 const struct dom_sid
*domain_sid
,
3021 struct policy_handle
*domain_pol
,
3024 NTSTATUS result
, status
;
3025 struct policy_handle group_pol
;
3026 uint32 num_members
, *group_rids
;
3028 struct samr_RidAttrArray
*rids
= NULL
;
3029 struct lsa_Strings names
;
3030 struct samr_Ids types
;
3031 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3034 sid_to_fstring(sid_str
, domain_sid
);
3036 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
3038 MAXIMUM_ALLOWED_ACCESS
,
3042 if (!NT_STATUS_IS_OK(status
)) {
3045 if (!NT_STATUS_IS_OK(result
)) {
3049 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
3053 if (!NT_STATUS_IS_OK(status
)) {
3056 if (!NT_STATUS_IS_OK(result
)) {
3060 num_members
= rids
->count
;
3061 group_rids
= rids
->rids
;
3063 while (num_members
> 0) {
3064 int this_time
= 512;
3066 if (num_members
< this_time
)
3067 this_time
= num_members
;
3069 status
= dcerpc_samr_LookupRids(b
, mem_ctx
,
3076 if (!NT_STATUS_IS_OK(status
)) {
3079 if (!NT_STATUS_IS_OK(result
)) {
3082 if (names
.count
!= this_time
) {
3083 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3085 if (types
.count
!= this_time
) {
3086 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3088 /* We only have users as members, but make the output
3089 the same as the output of alias members */
3091 for (i
= 0; i
< this_time
; i
++) {
3093 if (c
->opt_long_list_entries
) {
3094 printf("%s-%d %s\\%s %d\n", sid_str
,
3095 group_rids
[i
], domain_name
,
3096 names
.names
[i
].string
,
3099 printf("%s\\%s\n", domain_name
,
3100 names
.names
[i
].string
);
3104 num_members
-= this_time
;
3108 return NT_STATUS_OK
;
3111 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
3112 struct rpc_pipe_client
*pipe_hnd
,
3113 struct cli_state
*cli
,
3114 TALLOC_CTX
*mem_ctx
,
3115 struct policy_handle
*domain_pol
,
3118 NTSTATUS result
, status
;
3119 struct rpc_pipe_client
*lsa_pipe
;
3120 struct policy_handle alias_pol
, lsa_pol
;
3122 struct dom_sid
*alias_sids
;
3125 enum lsa_SidType
*types
;
3127 struct lsa_SidArray sid_array
;
3128 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3130 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
3132 MAXIMUM_ALLOWED_ACCESS
,
3136 if (!NT_STATUS_IS_OK(status
)) {
3139 if (!NT_STATUS_IS_OK(result
)) {
3143 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
3147 if (!NT_STATUS_IS_OK(status
)) {
3148 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3151 if (!NT_STATUS_IS_OK(result
)) {
3152 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3156 num_members
= sid_array
.num_sids
;
3158 if (num_members
== 0) {
3159 return NT_STATUS_OK
;
3162 result
= cli_rpc_pipe_open_noauth(cli
,
3165 if (!NT_STATUS_IS_OK(result
)) {
3166 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
3167 nt_errstr(result
) );
3171 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
3172 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
3174 if (!NT_STATUS_IS_OK(result
)) {
3175 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
3176 TALLOC_FREE(lsa_pipe
);
3180 alias_sids
= talloc_zero_array(mem_ctx
, struct dom_sid
, num_members
);
3182 d_fprintf(stderr
, _("Out of memory\n"));
3183 TALLOC_FREE(lsa_pipe
);
3184 return NT_STATUS_NO_MEMORY
;
3187 for (i
=0; i
<num_members
; i
++) {
3188 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
3191 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
3192 num_members
, alias_sids
,
3193 &domains
, &names
, &types
);
3195 if (!NT_STATUS_IS_OK(result
) &&
3196 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
3197 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
3198 TALLOC_FREE(lsa_pipe
);
3202 for (i
= 0; i
< num_members
; i
++) {
3204 sid_to_fstring(sid_str
, &alias_sids
[i
]);
3206 if (c
->opt_long_list_entries
) {
3207 printf("%s %s\\%s %d\n", sid_str
,
3208 domains
[i
] ? domains
[i
] : _("*unknown*"),
3209 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
3212 printf("%s\\%s\n", domains
[i
], names
[i
]);
3214 printf("%s\n", sid_str
);
3218 TALLOC_FREE(lsa_pipe
);
3219 return NT_STATUS_OK
;
3222 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
3223 const struct dom_sid
*domain_sid
,
3224 const char *domain_name
,
3225 struct cli_state
*cli
,
3226 struct rpc_pipe_client
*pipe_hnd
,
3227 TALLOC_CTX
*mem_ctx
,
3231 NTSTATUS result
, status
;
3232 struct policy_handle connect_pol
, domain_pol
;
3233 struct samr_Ids rids
, rid_types
;
3234 struct lsa_String lsa_acct_name
;
3235 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3237 /* Get sam policy handle */
3239 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
3241 MAXIMUM_ALLOWED_ACCESS
,
3244 if (!NT_STATUS_IS_OK(status
)) {
3247 if (!NT_STATUS_IS_OK(result
)) {
3251 /* Get domain policy handle */
3253 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3255 MAXIMUM_ALLOWED_ACCESS
,
3256 discard_const_p(struct dom_sid2
, domain_sid
),
3259 if (!NT_STATUS_IS_OK(status
)) {
3262 if (!NT_STATUS_IS_OK(result
)) {
3266 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
3268 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3275 if (!NT_STATUS_IS_OK(status
)) {
3279 if (!NT_STATUS_IS_OK(result
)) {
3281 /* Ok, did not find it in the global sam, try with builtin */
3283 struct dom_sid sid_Builtin
;
3285 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
3287 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
3289 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3291 MAXIMUM_ALLOWED_ACCESS
,
3295 if (!NT_STATUS_IS_OK(status
)) {
3298 if (!NT_STATUS_IS_OK(result
)) {
3299 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3304 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3311 if (!NT_STATUS_IS_OK(status
)) {
3314 if (!NT_STATUS_IS_OK(result
)) {
3315 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3321 if (rids
.count
!= 1) {
3322 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3324 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3326 if (rid_types
.count
!= 1) {
3327 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3329 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3333 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
3334 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
3335 domain_sid
, &domain_pol
,
3339 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
3340 return rpc_list_alias_members(c
, pipe_hnd
, cli
, mem_ctx
, &domain_pol
,
3344 return NT_STATUS_NO_SUCH_GROUP
;
3347 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
3349 if (argc
!= 1 || c
->display_usage
) {
3350 return rpc_group_usage(c
, argc
, argv
);
3353 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3354 rpc_group_members_internals
,
3358 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
3360 NET_API_STATUS status
;
3361 struct GROUP_INFO_0 g0
;
3365 d_printf(_("Usage:\n"));
3366 d_printf("net rpc group rename group newname\n");
3370 g0
.grpi0_name
= argv
[1];
3372 status
= NetGroupSetInfo(c
->opt_host
,
3379 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
3380 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
3388 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
3390 if (argc
!= 2 || c
->display_usage
) {
3391 return rpc_group_usage(c
, argc
, argv
);
3394 return rpc_group_rename_internals(c
, argc
, argv
);
3398 * 'net rpc group' entrypoint.
3399 * @param argc Standard main() style argc.
3400 * @param argv Standard main() style argv. Initial components are already
3404 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
3406 NET_API_STATUS status
;
3408 struct functable func
[] = {
3413 N_("Create specified group"),
3414 N_("net rpc group add\n"
3415 " Create specified group")
3421 N_("Delete specified group"),
3422 N_("net rpc group delete\n"
3423 " Delete specified group")
3429 N_("Add member to group"),
3430 N_("net rpc group addmem\n"
3431 " Add member to group")
3437 N_("Remove member from group"),
3438 N_("net rpc group delmem\n"
3439 " Remove member from group")
3446 N_("net rpc group list\n"
3453 N_("List group members"),
3454 N_("net rpc group members\n"
3455 " List group members")
3462 N_("net rpc group rename\n"
3465 {NULL
, NULL
, 0, NULL
, NULL
}
3468 status
= libnetapi_net_init(&c
->netapi_ctx
);
3472 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
3473 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
3474 if (c
->opt_kerberos
) {
3475 libnetapi_set_use_kerberos(c
->netapi_ctx
);
3479 if (c
->display_usage
) {
3480 d_printf(_("Usage:\n"));
3481 d_printf(_("net rpc group\n"
3482 " Alias for net rpc group list global "
3483 "local builtin\n"));
3484 net_display_usage_from_functable(func
);
3488 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3489 rpc_group_list_internals
,
3493 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
3496 /****************************************************************************/
3498 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
3500 return net_share_usage(c
, argc
, argv
);
3504 * Add a share on a remote RPC server.
3506 * @param argc Standard main() style argc.
3507 * @param argv Standard main() style argv. Initial components are already
3510 * @return A shell status integer (0 for success).
3513 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
3515 NET_API_STATUS status
;
3518 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3519 uint32 num_users
=0, perms
=0;
3520 char *password
=NULL
; /* don't allow a share password */
3521 struct SHARE_INFO_2 i2
;
3522 uint32_t parm_error
= 0;
3524 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
3525 return rpc_share_usage(c
, argc
, argv
);
3528 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
3532 path
= strchr(sharename
, '=');
3539 i2
.shi2_netname
= sharename
;
3540 i2
.shi2_type
= type
;
3541 i2
.shi2_remark
= c
->opt_comment
;
3542 i2
.shi2_permissions
= perms
;
3543 i2
.shi2_max_uses
= c
->opt_maxusers
;
3544 i2
.shi2_current_uses
= num_users
;
3545 i2
.shi2_path
= path
;
3546 i2
.shi2_passwd
= password
;
3548 status
= NetShareAdd(c
->opt_host
,
3553 printf(_("NetShareAdd failed with: %s\n"),
3554 libnetapi_get_error_string(c
->netapi_ctx
, status
));
3561 * Delete a share on a remote RPC server.
3563 * @param domain_sid The domain sid acquired from the remote server.
3564 * @param argc Standard main() style argc.
3565 * @param argv Standard main() style argv. Initial components are already
3568 * @return A shell status integer (0 for success).
3570 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
3572 if (argc
< 1 || c
->display_usage
) {
3573 return rpc_share_usage(c
, argc
, argv
);
3576 return NetShareDel(c
->opt_host
, argv
[0], 0);
3580 * Formatted print of share info
3582 * @param r pointer to SHARE_INFO_1 to format
3585 static void display_share_info_1(struct net_context
*c
,
3586 struct SHARE_INFO_1
*r
)
3588 if (c
->opt_long_list_entries
) {
3589 d_printf("%-12s %-8.8s %-50s\n",
3591 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
3594 d_printf("%s\n", r
->shi1_netname
);
3598 static WERROR
get_share_info(struct net_context
*c
,
3599 struct rpc_pipe_client
*pipe_hnd
,
3600 TALLOC_CTX
*mem_ctx
,
3604 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3608 union srvsvc_NetShareInfo info
;
3609 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3611 /* no specific share requested, enumerate all */
3614 uint32_t preferred_len
= 0xffffffff;
3615 uint32_t total_entries
= 0;
3616 uint32_t resume_handle
= 0;
3618 info_ctr
->level
= level
;
3620 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
3627 if (!NT_STATUS_IS_OK(status
)) {
3628 return ntstatus_to_werror(status
);
3633 /* request just one share */
3634 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
3641 if (!NT_STATUS_IS_OK(status
)) {
3642 result
= ntstatus_to_werror(status
);
3646 if (!W_ERROR_IS_OK(result
)) {
3651 ZERO_STRUCTP(info_ctr
);
3653 info_ctr
->level
= level
;
3658 struct srvsvc_NetShareCtr1
*ctr1
;
3660 ctr1
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr1
);
3661 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3664 ctr1
->array
= info
.info1
;
3666 info_ctr
->ctr
.ctr1
= ctr1
;
3672 struct srvsvc_NetShareCtr2
*ctr2
;
3674 ctr2
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr2
);
3675 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3678 ctr2
->array
= info
.info2
;
3680 info_ctr
->ctr
.ctr2
= ctr2
;
3686 struct srvsvc_NetShareCtr502
*ctr502
;
3688 ctr502
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr502
);
3689 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3692 ctr502
->array
= info
.info502
;
3694 info_ctr
->ctr
.ctr502
= ctr502
;
3704 * 'net rpc share list' entrypoint.
3705 * @param argc Standard main() style argc.
3706 * @param argv Standard main() style argv. Initial components are already
3709 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3711 NET_API_STATUS status
;
3712 struct SHARE_INFO_1
*i1
= NULL
;
3713 uint32_t entries_read
= 0;
3714 uint32_t total_entries
= 0;
3715 uint32_t resume_handle
= 0;
3716 uint32_t i
, level
= 1;
3718 if (c
->display_usage
) {
3720 "net rpc share list\n"
3723 _("List shares on remote server"));
3727 status
= NetShareEnum(c
->opt_host
,
3729 (uint8_t **)(void *)&i1
,
3738 /* Display results */
3740 if (c
->opt_long_list_entries
) {
3742 "\nEnumerating shared resources (exports) on remote server:\n\n"
3743 "\nShare name Type Description\n"
3744 "---------- ---- -----------\n"));
3746 for (i
= 0; i
< entries_read
; i
++)
3747 display_share_info_1(c
, &i1
[i
]);
3752 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3756 status
= cli_tree_connect(cli
, netname
, "A:", "", 0);
3757 if (!NT_STATUS_IS_OK(status
)) {
3758 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3762 status
= cli_tdis(cli
);
3763 if (!NT_STATUS_IS_OK(status
)) {
3764 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status
));
3771 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3772 const char *netname
, uint32 type
)
3774 /* only support disk shares */
3775 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3776 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3781 /* skip builtin shares */
3782 /* FIXME: should print$ be added too ? */
3783 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3784 strequal(netname
,"global"))
3787 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3788 printf(_("excluding [%s]\n"), netname
);
3792 return check_share_availability(cli
, netname
);
3796 * Migrate shares from a remote RPC server to the local RPC server.
3798 * All parameters are provided by the run_rpc_command function, except for
3799 * argc, argv which are passed through.
3801 * @param domain_sid The domain sid acquired from the remote server.
3802 * @param cli A cli_state connected to the server.
3803 * @param mem_ctx Talloc context, destroyed on completion of the function.
3804 * @param argc Standard main() style argc.
3805 * @param argv Standard main() style argv. Initial components are already
3808 * @return Normal NTSTATUS return.
3811 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3812 const struct dom_sid
*domain_sid
,
3813 const char *domain_name
,
3814 struct cli_state
*cli
,
3815 struct rpc_pipe_client
*pipe_hnd
,
3816 TALLOC_CTX
*mem_ctx
,
3821 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3822 struct srvsvc_NetShareInfoCtr ctr_src
;
3824 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3825 struct cli_state
*cli_dst
= NULL
;
3826 uint32 level
= 502; /* includes secdesc */
3827 uint32_t parm_error
= 0;
3828 struct dcerpc_binding_handle
*b
;
3830 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3832 if (!W_ERROR_IS_OK(result
))
3835 /* connect destination PI_SRVSVC */
3836 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3838 if (!NT_STATUS_IS_OK(nt_status
))
3841 b
= srvsvc_pipe
->binding_handle
;
3843 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3845 union srvsvc_NetShareInfo info
;
3846 struct srvsvc_NetShareInfo502 info502
=
3847 ctr_src
.ctr
.ctr502
->array
[i
];
3849 /* reset error-code */
3850 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3852 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3855 /* finally add the share on the dst server */
3857 printf(_("migrating: [%s], path: %s, comment: %s, without "
3859 info502
.name
, info502
.path
, info502
.comment
);
3861 info
.info502
= &info502
;
3863 nt_status
= dcerpc_srvsvc_NetShareAdd(b
, mem_ctx
,
3864 srvsvc_pipe
->desthost
,
3869 if (!NT_STATUS_IS_OK(nt_status
)) {
3870 printf(_("cannot add share: %s\n"),
3871 nt_errstr(nt_status
));
3874 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3875 printf(_(" [%s] does already exist\n"),
3880 if (!W_ERROR_IS_OK(result
)) {
3881 nt_status
= werror_to_ntstatus(result
);
3882 printf(_("cannot add share: %s\n"),
3883 win_errstr(result
));
3889 nt_status
= NT_STATUS_OK
;
3893 cli_shutdown(cli_dst
);
3901 * Migrate shares from a RPC server to another.
3903 * @param argc Standard main() style argc.
3904 * @param argv Standard main() style argv. Initial components are already
3907 * @return A shell status integer (0 for success).
3909 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3912 if (c
->display_usage
) {
3914 "net rpc share migrate shares\n"
3917 _("Migrate shares to local server"));
3922 printf(_("no server to migrate\n"));
3926 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
3927 rpc_share_migrate_shares_internals
,
3934 * @param f file_info
3935 * @param mask current search mask
3936 * @param state arg-pointer
3939 static NTSTATUS
copy_fn(const char *mnt
, struct file_info
*f
,
3940 const char *mask
, void *state
)
3942 static NTSTATUS nt_status
;
3943 static struct copy_clistate
*local_state
;
3944 static fstring filename
, new_mask
;
3947 struct net_context
*c
;
3949 local_state
= (struct copy_clistate
*)state
;
3950 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3954 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3955 return NT_STATUS_OK
;
3957 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3960 if (f
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
3962 DEBUG(3,("got dir: %s\n", f
->name
));
3964 fstrcpy(dir
, local_state
->cwd
);
3966 fstrcat(dir
, f
->name
);
3968 switch (net_mode_share
)
3970 case NET_MODE_SHARE_MIGRATE
:
3971 /* create that directory */
3972 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3973 local_state
->cli_share_src
,
3974 local_state
->cli_share_dst
,
3976 c
->opt_acls
? true : false,
3977 c
->opt_attrs
? true : false,
3978 c
->opt_timestamps
? true:false,
3982 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3983 return NT_STATUS_INTERNAL_ERROR
;
3986 if (!NT_STATUS_IS_OK(nt_status
)) {
3987 printf(_("could not handle dir %s: %s\n"),
3988 dir
, nt_errstr(nt_status
));
3992 /* search below that directory */
3993 if (strlcpy(new_mask
, dir
, sizeof(new_mask
)) >= sizeof(new_mask
)) {
3994 return NT_STATUS_NO_MEMORY
;
3996 if (strlcat(new_mask
, "\\*", sizeof(new_mask
)) >= sizeof(new_mask
)) {
3997 return NT_STATUS_NO_MEMORY
;
4000 old_dir
= local_state
->cwd
;
4001 local_state
->cwd
= dir
;
4002 nt_status
= sync_files(local_state
, new_mask
);
4003 if (!NT_STATUS_IS_OK(nt_status
)) {
4004 printf(_("could not handle files\n"));
4006 local_state
->cwd
= old_dir
;
4013 fstrcpy(filename
, local_state
->cwd
);
4014 fstrcat(filename
, "\\");
4015 fstrcat(filename
, f
->name
);
4017 DEBUG(3,("got file: %s\n", filename
));
4019 switch (net_mode_share
)
4021 case NET_MODE_SHARE_MIGRATE
:
4022 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
4023 local_state
->cli_share_src
,
4024 local_state
->cli_share_dst
,
4026 c
->opt_acls
? true : false,
4027 c
->opt_attrs
? true : false,
4028 c
->opt_timestamps
? true: false,
4032 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
4034 return NT_STATUS_INTERNAL_ERROR
;
4037 if (!NT_STATUS_IS_OK(nt_status
))
4038 printf(_("could not handle file %s: %s\n"),
4039 filename
, nt_errstr(nt_status
));
4044 * sync files, can be called recursivly to list files
4045 * and then call copy_fn for each file
4047 * @param cp_clistate pointer to the copy_clistate we work with
4048 * @param mask the current search mask
4050 * @return Boolean result
4052 static NTSTATUS
sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
4054 struct cli_state
*targetcli
;
4055 char *targetpath
= NULL
;
4058 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
4060 status
= cli_resolve_path(talloc_tos(), "", NULL
,
4061 cp_clistate
->cli_share_src
,
4062 mask
, &targetcli
, &targetpath
);
4063 if (!NT_STATUS_IS_OK(status
)) {
4064 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
4066 mask
, nt_errstr(status
));
4070 status
= cli_list(targetcli
, targetpath
, cp_clistate
->attribute
,
4071 copy_fn
, cp_clistate
);
4072 if (!NT_STATUS_IS_OK(status
)) {
4073 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
4074 mask
, nt_errstr(status
));
4082 * Set the top level directory permissions before we do any further copies.
4083 * Should set up ACL inheritance.
4086 bool copy_top_level_perms(struct net_context
*c
,
4087 struct copy_clistate
*cp_clistate
,
4088 const char *sharename
)
4090 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4092 switch (net_mode_share
) {
4093 case NET_MODE_SHARE_MIGRATE
:
4094 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
4095 nt_status
= net_copy_fileattr(c
,
4096 cp_clistate
->mem_ctx
,
4097 cp_clistate
->cli_share_src
,
4098 cp_clistate
->cli_share_dst
,
4100 c
->opt_acls
? true : false,
4101 c
->opt_attrs
? true : false,
4102 c
->opt_timestamps
? true: false,
4106 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
4110 if (!NT_STATUS_IS_OK(nt_status
)) {
4111 printf(_("Could handle directory attributes for top level "
4112 "directory of share %s. Error %s\n"),
4113 sharename
, nt_errstr(nt_status
));
4121 * Sync all files inside a remote share to another share (over smb).
4123 * All parameters are provided by the run_rpc_command function, except for
4124 * argc, argv which are passed through.
4126 * @param domain_sid The domain sid acquired from the remote server.
4127 * @param cli A cli_state connected to the server.
4128 * @param mem_ctx Talloc context, destroyed on completion of the function.
4129 * @param argc Standard main() style argc.
4130 * @param argv Standard main() style argv. Initial components are already
4133 * @return Normal NTSTATUS return.
4136 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
4137 const struct dom_sid
*domain_sid
,
4138 const char *domain_name
,
4139 struct cli_state
*cli
,
4140 struct rpc_pipe_client
*pipe_hnd
,
4141 TALLOC_CTX
*mem_ctx
,
4146 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4147 struct srvsvc_NetShareInfoCtr ctr_src
;
4150 struct copy_clistate cp_clistate
;
4151 bool got_src_share
= false;
4152 bool got_dst_share
= false;
4153 const char *mask
= "\\*";
4156 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
4158 nt_status
= NT_STATUS_NO_MEMORY
;
4162 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4165 if (!W_ERROR_IS_OK(result
))
4168 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4170 struct srvsvc_NetShareInfo502 info502
=
4171 ctr_src
.ctr
.ctr502
->array
[i
];
4173 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4176 /* one might not want to mirror whole discs :) */
4177 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
4178 d_printf(_("skipping [%s]: builtin/hidden share\n"),
4183 switch (net_mode_share
)
4185 case NET_MODE_SHARE_MIGRATE
:
4189 d_fprintf(stderr
, _("Unsupported mode %d\n"),
4193 printf(_(" [%s] files and directories %s ACLs, %s DOS "
4196 c
->opt_acls
? _("including") : _("without"),
4197 c
->opt_attrs
? _("including") : _("without"),
4198 c
->opt_timestamps
? _("(preserving timestamps)") : "");
4200 cp_clistate
.mem_ctx
= mem_ctx
;
4201 cp_clistate
.cli_share_src
= NULL
;
4202 cp_clistate
.cli_share_dst
= NULL
;
4203 cp_clistate
.cwd
= NULL
;
4204 cp_clistate
.attribute
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
;
4207 /* open share source */
4208 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
4209 smbXcli_conn_remote_sockaddr(cli
->conn
),
4210 smbXcli_conn_remote_name(cli
->conn
),
4211 info502
.name
, "A:");
4212 if (!NT_STATUS_IS_OK(nt_status
))
4215 got_src_share
= true;
4217 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
4218 /* open share destination */
4219 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
4220 NULL
, dst
, info502
.name
, "A:");
4221 if (!NT_STATUS_IS_OK(nt_status
))
4224 got_dst_share
= true;
4227 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
4228 d_fprintf(stderr
, _("Could not handle the top level "
4229 "directory permissions for the "
4230 "share: %s\n"), info502
.name
);
4231 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4235 nt_status
= sync_files(&cp_clistate
, mask
);
4236 if (!NT_STATUS_IS_OK(nt_status
)) {
4237 d_fprintf(stderr
, _("could not handle files for share: "
4238 "%s\n"), info502
.name
);
4243 nt_status
= NT_STATUS_OK
;
4248 cli_shutdown(cp_clistate
.cli_share_src
);
4251 cli_shutdown(cp_clistate
.cli_share_dst
);
4258 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
4260 if (c
->display_usage
) {
4262 "net share migrate files\n"
4265 _("Migrate files to local server"));
4270 d_printf(_("no server to migrate\n"));
4274 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4275 rpc_share_migrate_files_internals
,
4280 * Migrate share-ACLs from a remote RPC server to the local RPC server.
4282 * All parameters are provided by the run_rpc_command function, except for
4283 * argc, argv which are passed through.
4285 * @param domain_sid The domain sid acquired from the remote server.
4286 * @param cli A cli_state connected to the server.
4287 * @param mem_ctx Talloc context, destroyed on completion of the function.
4288 * @param argc Standard main() style argc.
4289 * @param argv Standard main() style argv. Initial components are already
4292 * @return Normal NTSTATUS return.
4295 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
4296 const struct dom_sid
*domain_sid
,
4297 const char *domain_name
,
4298 struct cli_state
*cli
,
4299 struct rpc_pipe_client
*pipe_hnd
,
4300 TALLOC_CTX
*mem_ctx
,
4305 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4306 struct srvsvc_NetShareInfoCtr ctr_src
;
4307 union srvsvc_NetShareInfo info
;
4309 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
4310 struct cli_state
*cli_dst
= NULL
;
4311 uint32 level
= 502; /* includes secdesc */
4312 uint32_t parm_error
= 0;
4313 struct dcerpc_binding_handle
*b
;
4315 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4318 if (!W_ERROR_IS_OK(result
))
4321 /* connect destination PI_SRVSVC */
4322 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
4324 if (!NT_STATUS_IS_OK(nt_status
))
4327 b
= srvsvc_pipe
->binding_handle
;
4329 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4331 struct srvsvc_NetShareInfo502 info502
=
4332 ctr_src
.ctr
.ctr502
->array
[i
];
4334 /* reset error-code */
4335 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4337 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4340 printf(_("migrating: [%s], path: %s, comment: %s, including "
4342 info502
.name
, info502
.path
, info502
.comment
);
4345 display_sec_desc(info502
.sd_buf
.sd
);
4347 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4348 info
.info502
= &info502
;
4350 /* finally modify the share on the dst server */
4351 nt_status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
4352 srvsvc_pipe
->desthost
,
4358 if (!NT_STATUS_IS_OK(nt_status
)) {
4359 printf(_("cannot set share-acl: %s\n"),
4360 nt_errstr(nt_status
));
4363 if (!W_ERROR_IS_OK(result
)) {
4364 nt_status
= werror_to_ntstatus(result
);
4365 printf(_("cannot set share-acl: %s\n"),
4366 win_errstr(result
));
4372 nt_status
= NT_STATUS_OK
;
4376 cli_shutdown(cli_dst
);
4384 * Migrate share-acls from a RPC server to another.
4386 * @param argc Standard main() style argc.
4387 * @param argv Standard main() style argv. Initial components are already
4390 * @return A shell status integer (0 for success).
4392 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
4395 if (c
->display_usage
) {
4397 "net rpc share migrate security\n"
4400 _("Migrate share-acls to local server"));
4405 d_printf(_("no server to migrate\n"));
4409 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4410 rpc_share_migrate_security_internals
,
4415 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4416 * from one server to another.
4418 * @param argc Standard main() style argc.
4419 * @param argv Standard main() style argv. Initial components are already
4422 * @return A shell status integer (0 for success).
4425 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
4430 if (c
->display_usage
) {
4432 "net rpc share migrate all\n"
4435 _("Migrates shares including all share settings"));
4440 d_printf(_("no server to migrate\n"));
4444 /* order is important. we don't want to be locked out by the share-acl
4445 * before copying files - gd */
4447 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4448 rpc_share_migrate_shares_internals
, argc
, argv
);
4452 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4453 rpc_share_migrate_files_internals
, argc
, argv
);
4457 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4458 rpc_share_migrate_security_internals
, argc
,
4464 * 'net rpc share migrate' entrypoint.
4465 * @param argc Standard main() style argc.
4466 * @param argv Standard main() style argv. Initial components are already
4469 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
4472 struct functable func
[] = {
4475 rpc_share_migrate_all
,
4477 N_("Migrate shares from remote to local server"),
4478 N_("net rpc share migrate all\n"
4479 " Migrate shares from remote to local server")
4483 rpc_share_migrate_files
,
4485 N_("Migrate files from remote to local server"),
4486 N_("net rpc share migrate files\n"
4487 " Migrate files from remote to local server")
4491 rpc_share_migrate_security
,
4493 N_("Migrate share-ACLs from remote to local server"),
4494 N_("net rpc share migrate security\n"
4495 " Migrate share-ACLs from remote to local server")
4499 rpc_share_migrate_shares
,
4501 N_("Migrate shares from remote to local server"),
4502 N_("net rpc share migrate shares\n"
4503 " Migrate shares from remote to local server")
4505 {NULL
, NULL
, 0, NULL
, NULL
}
4508 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
4510 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
4516 struct dom_sid
*members
;
4519 static int num_server_aliases
;
4520 static struct full_alias
*server_aliases
;
4523 * Add an alias to the static list.
4525 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
4527 if (server_aliases
== NULL
)
4528 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
4530 server_aliases
[num_server_aliases
] = *alias
;
4531 num_server_aliases
+= 1;
4535 * For a specific domain on the server, fetch all the aliases
4536 * and their members. Add all of them to the server_aliases.
4539 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
4540 TALLOC_CTX
*mem_ctx
,
4541 struct policy_handle
*connect_pol
,
4542 const struct dom_sid
*domain_sid
)
4544 uint32 start_idx
, max_entries
, num_entries
, i
;
4545 struct samr_SamArray
*groups
= NULL
;
4546 NTSTATUS result
, status
;
4547 struct policy_handle domain_pol
;
4548 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4550 /* Get domain policy handle */
4552 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
4554 MAXIMUM_ALLOWED_ACCESS
,
4555 discard_const_p(struct dom_sid2
, domain_sid
),
4558 if (!NT_STATUS_IS_OK(status
)) {
4561 if (!NT_STATUS_IS_OK(result
)) {
4569 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
4576 if (!NT_STATUS_IS_OK(status
)) {
4579 for (i
= 0; i
< num_entries
; i
++) {
4581 struct policy_handle alias_pol
;
4582 struct full_alias alias
;
4583 struct lsa_SidArray sid_array
;
4587 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
4589 MAXIMUM_ALLOWED_ACCESS
,
4590 groups
->entries
[i
].idx
,
4593 if (!NT_STATUS_IS_OK(status
)) {
4596 if (!NT_STATUS_IS_OK(_result
)) {
4601 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
4605 if (!NT_STATUS_IS_OK(status
)) {
4608 if (!NT_STATUS_IS_OK(_result
)) {
4613 alias
.num_members
= sid_array
.num_sids
;
4615 status
= dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &_result
);
4616 if (!NT_STATUS_IS_OK(status
)) {
4619 if (!NT_STATUS_IS_OK(_result
)) {
4624 alias
.members
= NULL
;
4626 if (alias
.num_members
> 0) {
4627 alias
.members
= SMB_MALLOC_ARRAY(struct dom_sid
, alias
.num_members
);
4629 for (j
= 0; j
< alias
.num_members
; j
++)
4630 sid_copy(&alias
.members
[j
],
4631 sid_array
.sids
[j
].sid
);
4634 sid_compose(&alias
.sid
, domain_sid
,
4635 groups
->entries
[i
].idx
);
4637 push_alias(mem_ctx
, &alias
);
4639 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4641 status
= NT_STATUS_OK
;
4644 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
4650 * Dump server_aliases as names for debugging purposes.
4653 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
4654 const struct dom_sid
*domain_sid
,
4655 const char *domain_name
,
4656 struct cli_state
*cli
,
4657 struct rpc_pipe_client
*pipe_hnd
,
4658 TALLOC_CTX
*mem_ctx
,
4664 struct policy_handle lsa_pol
;
4665 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4667 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
4668 SEC_FLAG_MAXIMUM_ALLOWED
,
4670 if (!NT_STATUS_IS_OK(result
))
4673 for (i
=0; i
<num_server_aliases
; i
++) {
4676 enum lsa_SidType
*types
;
4679 struct full_alias
*alias
= &server_aliases
[i
];
4681 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4683 &domains
, &names
, &types
);
4684 if (!NT_STATUS_IS_OK(result
))
4687 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4689 if (alias
->num_members
== 0) {
4694 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4697 &domains
, &names
, &types
);
4699 if (!NT_STATUS_IS_OK(result
) &&
4700 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4703 for (j
=0; j
<alias
->num_members
; j
++)
4704 DEBUG(1, ("%s\\%s (%d); ",
4705 domains
[j
] ? domains
[j
] : "*unknown*",
4706 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4710 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
4712 return NT_STATUS_OK
;
4716 * Fetch a list of all server aliases and their members into
4720 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4721 const struct dom_sid
*domain_sid
,
4722 const char *domain_name
,
4723 struct cli_state
*cli
,
4724 struct rpc_pipe_client
*pipe_hnd
,
4725 TALLOC_CTX
*mem_ctx
,
4729 NTSTATUS result
, status
;
4730 struct policy_handle connect_pol
;
4731 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4733 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
4735 MAXIMUM_ALLOWED_ACCESS
,
4738 if (!NT_STATUS_IS_OK(status
)) {
4741 if (!NT_STATUS_IS_OK(result
)) {
4746 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4747 &global_sid_Builtin
);
4748 if (!NT_STATUS_IS_OK(status
)) {
4752 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4755 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
4760 static void init_user_token(struct security_token
*token
, struct dom_sid
*user_sid
)
4762 token
->num_sids
= 4;
4764 if (!(token
->sids
= SMB_MALLOC_ARRAY(struct dom_sid
, 4))) {
4765 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4766 token
->num_sids
= 0;
4770 token
->sids
[0] = *user_sid
;
4771 sid_copy(&token
->sids
[1], &global_sid_World
);
4772 sid_copy(&token
->sids
[2], &global_sid_Network
);
4773 sid_copy(&token
->sids
[3], &global_sid_Authenticated_Users
);
4776 static void free_user_token(struct security_token
*token
)
4778 SAFE_FREE(token
->sids
);
4781 static void add_sid_to_token(struct security_token
*token
, struct dom_sid
*sid
)
4783 if (security_token_has_sid(token
, sid
))
4786 token
->sids
= SMB_REALLOC_ARRAY(token
->sids
, struct dom_sid
, token
->num_sids
+1);
4791 sid_copy(&token
->sids
[token
->num_sids
], sid
);
4793 token
->num_sids
+= 1;
4798 struct security_token token
;
4801 static void dump_user_token(struct user_token
*token
)
4805 d_printf("%s\n", token
->name
);
4807 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4808 d_printf(" %s\n", sid_string_tos(&token
->token
.sids
[i
]));
4812 static bool is_alias_member(struct dom_sid
*sid
, struct full_alias
*alias
)
4816 for (i
=0; i
<alias
->num_members
; i
++) {
4817 if (dom_sid_compare(sid
, &alias
->members
[i
]) == 0)
4824 static void collect_sid_memberships(struct security_token
*token
, struct dom_sid sid
)
4828 for (i
=0; i
<num_server_aliases
; i
++) {
4829 if (is_alias_member(&sid
, &server_aliases
[i
]))
4830 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4835 * We got a user token with all the SIDs we can know about without asking the
4836 * server directly. These are the user and domain group sids. All of these can
4837 * be members of aliases. So scan the list of aliases for each of the SIDs and
4838 * add them to the token.
4841 static void collect_alias_memberships(struct security_token
*token
)
4843 int num_global_sids
= token
->num_sids
;
4846 for (i
=0; i
<num_global_sids
; i
++) {
4847 collect_sid_memberships(token
, token
->sids
[i
]);
4851 static bool get_user_sids(const char *domain
, const char *user
, struct security_token
*token
)
4853 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4854 enum wbcSidType type
;
4856 struct wbcDomainSid wsid
;
4857 char sid_str
[WBC_SID_STRING_BUFLEN
];
4858 struct dom_sid user_sid
;
4859 uint32_t num_groups
;
4860 gid_t
*groups
= NULL
;
4863 fstr_sprintf(full_name
, "%s%c%s",
4864 domain
, *lp_winbind_separator(), user
);
4866 /* First let's find out the user sid */
4868 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4870 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4871 DEBUG(1, ("winbind could not find %s: %s\n",
4872 full_name
, wbcErrorString(wbc_status
)));
4876 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4878 if (type
!= WBC_SID_NAME_USER
) {
4879 DEBUG(1, ("%s is not a user\n", full_name
));
4883 if (!string_to_sid(&user_sid
, sid_str
)) {
4884 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4888 init_user_token(token
, &user_sid
);
4890 /* And now the groups winbind knows about */
4892 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4893 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4894 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4895 full_name
, wbcErrorString(wbc_status
)));
4899 for (i
= 0; i
< num_groups
; i
++) {
4900 gid_t gid
= groups
[i
];
4904 wbc_status
= wbcGidToSid(gid
, &wsid
);
4905 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4906 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4907 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4908 wbcFreeMemory(groups
);
4912 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4914 DEBUG(3, (" %s\n", sid_str
));
4916 ok
= string_to_sid(&sid
, sid_str
);
4918 DEBUG(1, ("Failed to convert string to SID\n"));
4919 wbcFreeMemory(groups
);
4922 add_sid_to_token(token
, &sid
);
4924 wbcFreeMemory(groups
);
4930 * Get a list of all user tokens we want to look at
4933 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4934 struct user_token
**user_tokens
)
4936 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4937 uint32_t i
, num_users
;
4939 struct user_token
*result
;
4940 TALLOC_CTX
*frame
= NULL
;
4942 if (lp_winbind_use_default_domain() &&
4943 (c
->opt_target_workgroup
== NULL
)) {
4944 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4945 "please specify a workgroup\n"));
4949 /* Send request to winbind daemon */
4951 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4952 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4953 DEBUG(1, (_("winbind could not list users: %s\n"),
4954 wbcErrorString(wbc_status
)));
4958 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4960 if (result
== NULL
) {
4961 DEBUG(1, ("Could not malloc sid array\n"));
4962 wbcFreeMemory(users
);
4966 frame
= talloc_stackframe();
4967 for (i
=0; i
< num_users
; i
++) {
4968 fstring domain
, user
;
4971 fstrcpy(result
[i
].name
, users
[i
]);
4973 p
= strchr(users
[i
], *lp_winbind_separator());
4975 DEBUG(3, ("%s\n", users
[i
]));
4978 fstrcpy(domain
, c
->opt_target_workgroup
);
4979 fstrcpy(user
, users
[i
]);
4982 fstrcpy(domain
, users
[i
]);
4983 if (!strupper_m(domain
)) {
4984 DEBUG(1, ("strupper_m %s failed\n", domain
));
4985 wbcFreeMemory(users
);
4991 get_user_sids(domain
, user
, &(result
[i
].token
));
4994 wbcFreeMemory(users
);
4996 *num_tokens
= num_users
;
4997 *user_tokens
= result
;
5002 static bool get_user_tokens_from_file(FILE *f
,
5004 struct user_token
**tokens
)
5006 struct user_token
*token
= NULL
;
5011 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
5015 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
5016 line
[strlen(line
)-1] = '\0';
5019 if (line
[0] == ' ') {
5023 if(!string_to_sid(&sid
, &line
[1])) {
5024 DEBUG(1,("get_user_tokens_from_file: Could "
5025 "not convert sid %s \n",&line
[1]));
5029 if (token
== NULL
) {
5030 DEBUG(0, ("File does not begin with username"));
5034 add_sid_to_token(&token
->token
, &sid
);
5038 /* And a new user... */
5041 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
5042 if (*tokens
== NULL
) {
5043 DEBUG(0, ("Could not realloc tokens\n"));
5047 token
= &((*tokens
)[*num_tokens
-1]);
5049 if (strlcpy(token
->name
, line
, sizeof(token
->name
)) >= sizeof(token
->name
)) {
5052 token
->token
.num_sids
= 0;
5053 token
->token
.sids
= NULL
;
5062 * Show the list of all users that have access to a share
5065 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
5066 struct cli_state
*cli
,
5067 TALLOC_CTX
*mem_ctx
,
5068 const char *netname
,
5070 struct user_token
*tokens
)
5073 struct security_descriptor
*share_sd
= NULL
;
5074 struct security_descriptor
*root_sd
= NULL
;
5076 union srvsvc_NetShareInfo info
;
5080 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5082 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5089 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
5090 DEBUG(1, ("Coult not query secdesc for share %s\n",
5095 share_sd
= info
.info502
->sd_buf
.sd
;
5096 if (share_sd
== NULL
) {
5097 DEBUG(1, ("Got no secdesc for share %s\n",
5101 cnum
= cli_state_get_tid(cli
);
5103 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, netname
, "A:", "", 0))) {
5107 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
5108 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
5109 FILE_OPEN
, 0x0, 0x0, &fnum
, NULL
))) {
5110 cli_query_secdesc(cli
, fnum
, mem_ctx
, &root_sd
);
5113 for (i
=0; i
<num_tokens
; i
++) {
5116 if (share_sd
!= NULL
) {
5117 status
= se_access_check(share_sd
, &tokens
[i
].token
,
5120 if (!NT_STATUS_IS_OK(status
)) {
5121 DEBUG(1, ("Could not check share_sd for "
5128 if (root_sd
== NULL
) {
5129 d_printf(" %s\n", tokens
[i
].name
);
5133 status
= se_access_check(root_sd
, &tokens
[i
].token
,
5135 if (!NT_STATUS_IS_OK(status
)) {
5136 DEBUG(1, ("Could not check root_sd for user %s\n",
5140 d_printf(" %s\n", tokens
[i
].name
);
5143 if (fnum
!= (uint16_t)-1)
5144 cli_close(cli
, fnum
);
5146 cli_state_set_tid(cli
, cnum
);
5152 * List shares on a remote RPC server, including the security descriptors.
5154 * All parameters are provided by the run_rpc_command function, except for
5155 * argc, argv which are passed through.
5157 * @param domain_sid The domain sid acquired from the remote server.
5158 * @param cli A cli_state connected to the server.
5159 * @param mem_ctx Talloc context, destroyed on completion of the function.
5160 * @param argc Standard main() style argc.
5161 * @param argv Standard main() style argv. Initial components are already
5164 * @return Normal NTSTATUS return.
5167 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
5168 const struct dom_sid
*domain_sid
,
5169 const char *domain_name
,
5170 struct cli_state
*cli
,
5171 struct rpc_pipe_client
*pipe_hnd
,
5172 TALLOC_CTX
*mem_ctx
,
5178 NTSTATUS nt_status
= NT_STATUS_OK
;
5179 uint32_t total_entries
= 0;
5180 uint32_t resume_handle
= 0;
5181 uint32_t preferred_len
= 0xffffffff;
5183 struct dcerpc_binding_handle
*b
= NULL
;
5184 struct srvsvc_NetShareInfoCtr info_ctr
;
5185 struct srvsvc_NetShareCtr1 ctr1
;
5188 struct user_token
*tokens
= NULL
;
5194 f
= fopen(argv
[0], "r");
5198 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
5199 return NT_STATUS_UNSUCCESSFUL
;
5202 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
5208 DEBUG(0, ("Could not read users from file\n"));
5209 return NT_STATUS_UNSUCCESSFUL
;
5212 for (i
=0; i
<num_tokens
; i
++)
5213 collect_alias_memberships(&tokens
[i
].token
);
5215 ZERO_STRUCT(info_ctr
);
5219 info_ctr
.ctr
.ctr1
= &ctr1
;
5221 b
= pipe_hnd
->binding_handle
;
5223 /* Issue the NetShareEnum RPC call and retrieve the response */
5224 nt_status
= dcerpc_srvsvc_NetShareEnumAll(b
,
5233 /* Was it successful? */
5234 if (!NT_STATUS_IS_OK(nt_status
)) {
5235 /* Nope. Go clean up. */
5239 if (!W_ERROR_IS_OK(result
)) {
5240 /* Nope. Go clean up. */
5241 nt_status
= werror_to_ntstatus(result
);
5245 if (total_entries
== 0) {
5249 /* For each returned entry... */
5250 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
5251 const char *netname
= info_ctr
.ctr
.ctr1
->array
[i
].name
;
5253 if (info_ctr
.ctr
.ctr1
->array
[i
].type
!= STYPE_DISKTREE
) {
5257 d_printf("%s\n", netname
);
5259 show_userlist(pipe_hnd
, cli
, mem_ctx
, netname
,
5260 num_tokens
, tokens
);
5263 for (i
=0; i
<num_tokens
; i
++) {
5264 free_user_token(&tokens
[i
].token
);
5271 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
5276 if (c
->display_usage
) {
5278 "net rpc share allowedusers\n"
5281 _("List allowed users"));
5285 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
5286 rpc_aliaslist_internals
,
5291 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
, 0,
5297 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
5298 rpc_share_allowedusers_internals
,
5302 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
5305 struct user_token
*tokens
= NULL
;
5309 net_usersidlist_usage(c
, argc
, argv
);
5313 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
5314 DEBUG(0, ("Could not get the user/sid list\n"));
5318 for (i
=0; i
<num_tokens
; i
++) {
5319 dump_user_token(&tokens
[i
]);
5320 free_user_token(&tokens
[i
].token
);
5327 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
5329 d_printf(_("net usersidlist\n"
5330 "\tprints out a list of all users the running winbind knows\n"
5331 "\tabout, together with all their SIDs. This is used as\n"
5332 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
5334 net_common_flags_usage(c
, argc
, argv
);
5339 * 'net rpc share' entrypoint.
5340 * @param argc Standard main() style argc.
5341 * @param argv Standard main() style argv. Initial components are already
5345 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
5347 NET_API_STATUS status
;
5349 struct functable func
[] = {
5355 N_("net rpc share add\n"
5363 N_("net rpc share delete\n"
5368 rpc_share_allowedusers
,
5370 N_("Modify allowed users"),
5371 N_("net rpc share allowedusers\n"
5372 " Modify allowed users")
5378 N_("Migrate share to local server"),
5379 N_("net rpc share migrate\n"
5380 " Migrate share to local server")
5387 N_("net rpc share list\n"
5390 {NULL
, NULL
, 0, NULL
, NULL
}
5393 status
= libnetapi_net_init(&c
->netapi_ctx
);
5397 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
5398 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
5399 if (c
->opt_kerberos
) {
5400 libnetapi_set_use_kerberos(c
->netapi_ctx
);
5404 if (c
->display_usage
) {
5409 " Alias for net rpc share list\n"));
5410 net_display_usage_from_functable(func
);
5414 return rpc_share_list(c
, argc
, argv
);
5417 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
5420 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
5421 TALLOC_CTX
*mem_ctx
,
5422 struct rpc_sh_ctx
*ctx
,
5423 struct rpc_pipe_client
*pipe_hnd
,
5424 int argc
, const char **argv
)
5427 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
5430 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
5431 TALLOC_CTX
*mem_ctx
,
5432 struct rpc_sh_ctx
*ctx
,
5433 struct rpc_pipe_client
*pipe_hnd
,
5434 int argc
, const char **argv
)
5436 NET_API_STATUS status
;
5437 uint32_t parm_err
= 0;
5438 struct SHARE_INFO_2 i2
;
5440 if ((argc
< 2) || (argc
> 3)) {
5441 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
5443 return NT_STATUS_INVALID_PARAMETER
;
5446 i2
.shi2_netname
= argv
[0];
5447 i2
.shi2_type
= STYPE_DISKTREE
;
5448 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
5449 i2
.shi2_permissions
= 0;
5450 i2
.shi2_max_uses
= 0;
5451 i2
.shi2_current_uses
= 0;
5452 i2
.shi2_path
= argv
[1];
5453 i2
.shi2_passwd
= NULL
;
5455 status
= NetShareAdd(pipe_hnd
->desthost
,
5460 return werror_to_ntstatus(W_ERROR(status
));
5463 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
5464 TALLOC_CTX
*mem_ctx
,
5465 struct rpc_sh_ctx
*ctx
,
5466 struct rpc_pipe_client
*pipe_hnd
,
5467 int argc
, const char **argv
)
5470 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5471 return NT_STATUS_INVALID_PARAMETER
;
5474 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
5477 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
5478 TALLOC_CTX
*mem_ctx
,
5479 struct rpc_sh_ctx
*ctx
,
5480 struct rpc_pipe_client
*pipe_hnd
,
5481 int argc
, const char **argv
)
5483 union srvsvc_NetShareInfo info
;
5486 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5489 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5490 return NT_STATUS_INVALID_PARAMETER
;
5493 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5499 if (!NT_STATUS_IS_OK(status
)) {
5500 result
= ntstatus_to_werror(status
);
5503 if (!W_ERROR_IS_OK(result
)) {
5507 d_printf(_("Name: %s\n"), info
.info2
->name
);
5508 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
5509 d_printf(_("Path: %s\n"), info
.info2
->path
);
5510 d_printf(_("Password: %s\n"), info
.info2
->password
);
5513 return werror_to_ntstatus(result
);
5516 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
5517 struct rpc_sh_ctx
*ctx
)
5519 static struct rpc_sh_cmd cmds
[] = {
5521 { "list", NULL
, &ndr_table_srvsvc
, rpc_sh_share_list
,
5522 N_("List available shares") },
5524 { "add", NULL
, &ndr_table_srvsvc
, rpc_sh_share_add
,
5525 N_("Add a share") },
5527 { "delete", NULL
, &ndr_table_srvsvc
, rpc_sh_share_delete
,
5528 N_("Delete a share") },
5530 { "info", NULL
, &ndr_table_srvsvc
, rpc_sh_share_info
,
5531 N_("Get information about a share") },
5533 { NULL
, NULL
, 0, NULL
, NULL
}
5539 /****************************************************************************/
5541 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
5543 return net_file_usage(c
, argc
, argv
);
5547 * Close a file on a remote RPC server.
5549 * @param argc Standard main() style argc.
5550 * @param argv Standard main() style argv. Initial components are already
5553 * @return A shell status integer (0 for success).
5555 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
5557 if (argc
< 1 || c
->display_usage
) {
5558 return rpc_file_usage(c
, argc
, argv
);
5561 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
5565 * Formatted print of open file info
5567 * @param r struct FILE_INFO_3 contents
5570 static void display_file_info_3(struct FILE_INFO_3
*r
)
5572 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5573 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
5574 r
->fi3_num_locks
, r
->fi3_pathname
);
5578 * List files for a user on a remote RPC server.
5580 * @param argc Standard main() style argc.
5581 * @param argv Standard main() style argv. Initial components are already
5584 * @return A shell status integer (0 for success)..
5587 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
5589 NET_API_STATUS status
;
5590 uint32 preferred_len
= 0xffffffff, i
;
5591 char *username
=NULL
;
5592 uint32_t total_entries
= 0;
5593 uint32_t entries_read
= 0;
5594 uint32_t resume_handle
= 0;
5595 struct FILE_INFO_3
*i3
= NULL
;
5597 if (c
->display_usage
) {
5598 return rpc_file_usage(c
, argc
, argv
);
5601 /* if argc > 0, must be user command */
5603 username
= smb_xstrdup(argv
[0]);
5606 status
= NetFileEnum(c
->opt_host
,
5610 (uint8_t **)(void *)&i3
,
5620 /* Display results */
5623 "\nEnumerating open files on remote server:\n\n"
5624 "\nFileId Opened by Perms Locks Path"
5625 "\n------ --------- ----- ----- ---- \n"));
5626 for (i
= 0; i
< entries_read
; i
++) {
5627 display_file_info_3(&i3
[i
]);
5630 SAFE_FREE(username
);
5635 * 'net rpc file' entrypoint.
5636 * @param argc Standard main() style argc.
5637 * @param argv Standard main() style argv. Initial components are already
5641 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
5643 NET_API_STATUS status
;
5645 struct functable func
[] = {
5650 N_("Close opened file"),
5651 N_("net rpc file close\n"
5652 " Close opened file")
5658 N_("List files opened by user"),
5659 N_("net rpc file user\n"
5660 " List files opened by user")
5667 N_("Display information about opened file"),
5668 N_("net rpc file info\n"
5669 " Display information about opened file")
5672 {NULL
, NULL
, 0, NULL
, NULL
}
5675 status
= libnetapi_net_init(&c
->netapi_ctx
);
5679 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
5680 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
5681 if (c
->opt_kerberos
) {
5682 libnetapi_set_use_kerberos(c
->netapi_ctx
);
5686 if (c
->display_usage
) {
5687 d_printf(_("Usage:\n"));
5688 d_printf(_("net rpc file\n"
5689 " List opened files\n"));
5690 net_display_usage_from_functable(func
);
5694 return rpc_file_user(c
, argc
, argv
);
5697 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
5701 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5703 * All parameters are provided by the run_rpc_command function, except for
5704 * argc, argv which are passed through.
5706 * @param c A net_context structure.
5707 * @param domain_sid The domain sid acquired from the remote server.
5708 * @param cli A cli_state connected to the server.
5709 * @param mem_ctx Talloc context, destroyed on completion of the function.
5710 * @param argc Standard main() style argc.
5711 * @param argv Standard main() style argv. Initial components are already
5714 * @return Normal NTSTATUS return.
5717 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
5718 const struct dom_sid
*domain_sid
,
5719 const char *domain_name
,
5720 struct cli_state
*cli
,
5721 struct rpc_pipe_client
*pipe_hnd
,
5722 TALLOC_CTX
*mem_ctx
,
5726 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5728 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5730 status
= dcerpc_initshutdown_Abort(b
, mem_ctx
, NULL
, &result
);
5731 if (!NT_STATUS_IS_OK(status
)) {
5734 if (W_ERROR_IS_OK(result
)) {
5735 d_printf(_("\nShutdown successfully aborted\n"));
5736 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5738 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5740 return werror_to_ntstatus(result
);
5744 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5746 * All parameters are provided by the run_rpc_command function, except for
5747 * argc, argv which are passed through.
5749 * @param c A net_context structure.
5750 * @param domain_sid The domain sid acquired from the remote server.
5751 * @param cli A cli_state connected to the server.
5752 * @param mem_ctx Talloc context, destroyed on completion of the function.
5753 * @param argc Standard main() style argc.
5754 * @param argv Standard main() style argv. Initial components are already
5757 * @return Normal NTSTATUS return.
5760 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5761 const struct dom_sid
*domain_sid
,
5762 const char *domain_name
,
5763 struct cli_state
*cli
,
5764 struct rpc_pipe_client
*pipe_hnd
,
5765 TALLOC_CTX
*mem_ctx
,
5769 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5771 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5773 result
= dcerpc_winreg_AbortSystemShutdown(b
, mem_ctx
, NULL
, &werr
);
5775 if (!NT_STATUS_IS_OK(result
)) {
5776 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5779 if (W_ERROR_IS_OK(werr
)) {
5780 d_printf(_("\nShutdown successfully aborted\n"));
5781 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5783 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5785 return werror_to_ntstatus(werr
);
5789 * ABORT the shutdown of a remote RPC server.
5791 * @param argc Standard main() style argc.
5792 * @param argv Standard main() style argv. Initial components are already
5795 * @return A shell status integer (0 for success).
5798 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5803 if (c
->display_usage
) {
5805 "net rpc abortshutdown\n"
5808 _("Abort a scheduled shutdown"));
5812 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
5813 rpc_shutdown_abort_internals
, argc
, argv
);
5818 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5820 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
5821 rpc_reg_shutdown_abort_internals
,
5826 * Shut down a remote RPC Server via initshutdown pipe.
5828 * All parameters are provided by the run_rpc_command function, except for
5829 * argc, argv which are passed through.
5831 * @param c A net_context structure.
5832 * @param domain_sid The domain sid acquired from the remote server.
5833 * @param cli A cli_state connected to the server.
5834 * @param mem_ctx Talloc context, destroyed on completion of the function.
5835 * @param argc Standard main() style argc.
5836 * @param argv Standard main() style argv. Initial components are already
5839 * @return Normal NTSTATUS return.
5842 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5843 const struct dom_sid
*domain_sid
,
5844 const char *domain_name
,
5845 struct cli_state
*cli
,
5846 struct rpc_pipe_client
*pipe_hnd
,
5847 TALLOC_CTX
*mem_ctx
,
5851 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5853 const char *msg
= N_("This machine will be shutdown shortly");
5854 uint32 timeout
= 20;
5855 struct lsa_StringLarge msg_string
;
5856 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5858 if (c
->opt_comment
) {
5859 msg
= c
->opt_comment
;
5861 if (c
->opt_timeout
) {
5862 timeout
= c
->opt_timeout
;
5865 msg_string
.string
= msg
;
5867 /* create an entry */
5868 status
= dcerpc_initshutdown_Init(b
, mem_ctx
, NULL
,
5869 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5871 if (!NT_STATUS_IS_OK(status
)) {
5874 if (W_ERROR_IS_OK(result
)) {
5875 d_printf(_("\nShutdown of remote machine succeeded\n"));
5876 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5878 DEBUG(1,("Shutdown of remote machine failed!\n"));
5880 return werror_to_ntstatus(result
);
5884 * Shut down a remote RPC Server via winreg pipe.
5886 * All parameters are provided by the run_rpc_command function, except for
5887 * argc, argv which are passed through.
5889 * @param c A net_context structure.
5890 * @param domain_sid The domain sid acquired from the remote server.
5891 * @param cli A cli_state connected to the server.
5892 * @param mem_ctx Talloc context, destroyed on completion of the function.
5893 * @param argc Standard main() style argc.
5894 * @param argv Standard main() style argv. Initial components are already
5897 * @return Normal NTSTATUS return.
5900 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5901 const struct dom_sid
*domain_sid
,
5902 const char *domain_name
,
5903 struct cli_state
*cli
,
5904 struct rpc_pipe_client
*pipe_hnd
,
5905 TALLOC_CTX
*mem_ctx
,
5909 const char *msg
= N_("This machine will be shutdown shortly");
5910 uint32 timeout
= 20;
5911 struct lsa_StringLarge msg_string
;
5914 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5916 if (c
->opt_comment
) {
5917 msg
= c
->opt_comment
;
5919 msg_string
.string
= msg
;
5921 if (c
->opt_timeout
) {
5922 timeout
= c
->opt_timeout
;
5925 /* create an entry */
5926 result
= dcerpc_winreg_InitiateSystemShutdown(b
, mem_ctx
, NULL
,
5927 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5929 if (!NT_STATUS_IS_OK(result
)) {
5930 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5934 if (W_ERROR_IS_OK(werr
)) {
5935 d_printf(_("\nShutdown of remote machine succeeded\n"));
5937 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5938 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5939 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5941 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5944 return werror_to_ntstatus(werr
);
5948 * Shut down a remote RPC server.
5950 * @param argc Standard main() style argc.
5951 * @param argv Standard main() style argv. Initial components are already
5954 * @return A shell status integer (0 for success).
5957 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5961 if (c
->display_usage
) {
5963 "net rpc shutdown\n"
5966 _("Shut down a remote RPC server"));
5970 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
5971 rpc_init_shutdown_internals
, argc
, argv
);
5974 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5975 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
5976 rpc_reg_shutdown_internals
, argc
, argv
);
5982 /***************************************************************************
5983 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5984 ***************************************************************************/
5987 * Add interdomain trust account to the RPC server.
5988 * All parameters (except for argc and argv) are passed by run_rpc_command
5991 * @param c A net_context structure.
5992 * @param domain_sid The domain sid acquired from the server.
5993 * @param cli A cli_state connected to the server.
5994 * @param mem_ctx Talloc context, destroyed on completion of the function.
5995 * @param argc Standard main() style argc.
5996 * @param argv Standard main() style argv. Initial components are already
5999 * @return normal NTSTATUS return code.
6002 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
6003 const struct dom_sid
*domain_sid
,
6004 const char *domain_name
,
6005 struct cli_state
*cli
,
6006 struct rpc_pipe_client
*pipe_hnd
,
6007 TALLOC_CTX
*mem_ctx
,
6011 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6012 NTSTATUS status
, result
;
6014 struct lsa_String lsa_acct_name
;
6016 uint32 acct_flags
=0;
6018 uint32_t access_granted
= 0;
6019 union samr_UserInfo info
;
6020 unsigned int orig_timeout
;
6021 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6022 DATA_BLOB session_key
= data_blob_null
;
6027 _(" net rpc trustdom add <domain_name> "
6028 "<trust password>\n"));
6029 return NT_STATUS_INVALID_PARAMETER
;
6033 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6036 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
6037 return NT_STATUS_NO_MEMORY
;
6040 if (!strupper_m(acct_name
)) {
6041 SAFE_FREE(acct_name
);
6042 return NT_STATUS_INVALID_PARAMETER
;
6045 init_lsa_String(&lsa_acct_name
, acct_name
);
6047 status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
6048 if (!NT_STATUS_IS_OK(status
)) {
6049 DEBUG(0,("Error getting session_key of SAM pipe. Error was %s\n",
6050 nt_errstr(status
)));
6054 /* Get samr policy handle */
6055 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
6057 MAXIMUM_ALLOWED_ACCESS
,
6060 if (!NT_STATUS_IS_OK(status
)) {
6063 if (!NT_STATUS_IS_OK(result
)) {
6068 /* Get domain policy handle */
6069 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
6071 MAXIMUM_ALLOWED_ACCESS
,
6072 discard_const_p(struct dom_sid2
, domain_sid
),
6075 if (!NT_STATUS_IS_OK(status
)) {
6078 if (!NT_STATUS_IS_OK(result
)) {
6083 /* This call can take a long time - allow the server to time out.
6084 * 35 seconds should do it. */
6086 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
6088 /* Create trusting domain's account */
6089 acb_info
= ACB_NORMAL
;
6090 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
6091 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
6092 SAMR_USER_ACCESS_SET_PASSWORD
|
6093 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
6094 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
6096 status
= dcerpc_samr_CreateUser2(b
, mem_ctx
,
6105 if (!NT_STATUS_IS_OK(status
)) {
6108 /* And restore our original timeout. */
6109 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
6111 if (!NT_STATUS_IS_OK(result
)) {
6113 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
6114 acct_name
, nt_errstr(result
));
6119 struct samr_CryptPassword crypt_pwd
;
6121 ZERO_STRUCT(info
.info23
);
6123 init_samr_CryptPassword(argv
[1],
6127 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
6128 SAMR_FIELD_NT_PASSWORD_PRESENT
;
6129 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
6130 info
.info23
.password
= crypt_pwd
;
6132 status
= dcerpc_samr_SetUserInfo2(b
, mem_ctx
,
6137 if (!NT_STATUS_IS_OK(status
)) {
6141 if (!NT_STATUS_IS_OK(result
)) {
6143 DEBUG(0,("Could not set trust account password: %s\n",
6144 nt_errstr(result
)));
6150 SAFE_FREE(acct_name
);
6151 data_blob_clear_free(&session_key
);
6156 * Create interdomain trust account for a remote domain.
6158 * @param argc Standard argc.
6159 * @param argv Standard argv without initial components.
6161 * @return Integer status (0 means success).
6164 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
6166 if (argc
> 0 && !c
->display_usage
) {
6167 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6168 rpc_trustdom_add_internals
, argc
, argv
);
6172 _("net rpc trustdom add <domain_name> <trust "
6180 * Remove interdomain trust account from the RPC server.
6181 * All parameters (except for argc and argv) are passed by run_rpc_command
6184 * @param c A net_context structure.
6185 * @param domain_sid The domain sid acquired from the server.
6186 * @param cli A cli_state connected to the server.
6187 * @param mem_ctx Talloc context, destroyed on completion of the function.
6188 * @param argc Standard main() style argc.
6189 * @param argv Standard main() style argv. Initial components are already
6192 * @return normal NTSTATUS return code.
6195 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
6196 const struct dom_sid
*domain_sid
,
6197 const char *domain_name
,
6198 struct cli_state
*cli
,
6199 struct rpc_pipe_client
*pipe_hnd
,
6200 TALLOC_CTX
*mem_ctx
,
6204 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6205 NTSTATUS status
, result
;
6207 struct dom_sid trust_acct_sid
;
6208 struct samr_Ids user_rids
, name_types
;
6209 struct lsa_String lsa_acct_name
;
6210 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6215 _(" net rpc trustdom del <domain_name>\n"));
6216 return NT_STATUS_INVALID_PARAMETER
;
6220 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6222 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
6224 if (acct_name
== NULL
)
6225 return NT_STATUS_NO_MEMORY
;
6227 if (!strupper_m(acct_name
)) {
6228 TALLOC_FREE(acct_name
);
6229 return NT_STATUS_INVALID_PARAMETER
;
6232 /* Get samr policy handle */
6233 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
6235 MAXIMUM_ALLOWED_ACCESS
,
6238 if (!NT_STATUS_IS_OK(status
)) {
6241 if (!NT_STATUS_IS_OK(result
)) {
6246 /* Get domain policy handle */
6247 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
6249 MAXIMUM_ALLOWED_ACCESS
,
6250 discard_const_p(struct dom_sid2
, domain_sid
),
6253 if (!NT_STATUS_IS_OK(status
)) {
6256 if (!NT_STATUS_IS_OK(result
)) {
6261 init_lsa_String(&lsa_acct_name
, acct_name
);
6263 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
6270 if (!NT_STATUS_IS_OK(status
)) {
6271 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6273 acct_name
, nt_errstr(status
));
6276 if (!NT_STATUS_IS_OK(result
)) {
6278 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6280 acct_name
, nt_errstr(result
) );
6283 if (user_rids
.count
!= 1) {
6284 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6287 if (name_types
.count
!= 1) {
6288 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6292 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
6294 MAXIMUM_ALLOWED_ACCESS
,
6298 if (!NT_STATUS_IS_OK(status
)) {
6299 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6301 acct_name
, nt_errstr(status
) );
6305 if (!NT_STATUS_IS_OK(result
)) {
6307 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6309 acct_name
, nt_errstr(result
) );
6313 /* append the rid to the domain sid */
6314 if (!sid_compose(&trust_acct_sid
, domain_sid
, user_rids
.ids
[0])) {
6318 /* remove the sid */
6320 status
= dcerpc_samr_RemoveMemberFromForeignDomain(b
, mem_ctx
,
6324 if (!NT_STATUS_IS_OK(status
)) {
6325 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6326 " on user %s failed %s\n"),
6327 acct_name
, nt_errstr(status
));
6330 if (!NT_STATUS_IS_OK(result
)) {
6332 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6333 " on user %s failed %s\n"),
6334 acct_name
, nt_errstr(result
) );
6341 status
= dcerpc_samr_DeleteUser(b
, mem_ctx
,
6344 if (!NT_STATUS_IS_OK(status
)) {
6345 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6347 acct_name
, nt_errstr(status
));
6351 if (!NT_STATUS_IS_OK(result
)) {
6353 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6355 acct_name
, nt_errstr(result
) );
6359 if (!NT_STATUS_IS_OK(result
)) {
6360 d_printf(_("Could not set trust account password: %s\n"),
6370 * Delete interdomain trust account for a remote domain.
6372 * @param argc Standard argc.
6373 * @param argv Standard argv without initial components.
6375 * @return Integer status (0 means success).
6378 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
6380 if (argc
> 0 && !c
->display_usage
) {
6381 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6382 rpc_trustdom_del_internals
, argc
, argv
);
6386 _("net rpc trustdom del <domain>\n"));
6391 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
6392 struct cli_state
*cli
,
6393 TALLOC_CTX
*mem_ctx
,
6394 const char *domain_name
)
6396 char *dc_name
= NULL
;
6397 const char *buffer
= NULL
;
6398 struct rpc_pipe_client
*netr
;
6401 struct dcerpc_binding_handle
*b
;
6403 /* Use NetServerEnum2 */
6405 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
6407 return NT_STATUS_OK
;
6410 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
6411 for domain %s\n", domain_name
));
6413 /* Try netr_GetDcName */
6415 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
,
6417 if (!NT_STATUS_IS_OK(status
)) {
6421 b
= netr
->binding_handle
;
6423 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
6430 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(result
)) {
6434 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
6435 for domain %s\n", domain_name
));
6437 if (!NT_STATUS_IS_OK(status
)) {
6441 return werror_to_ntstatus(result
);
6445 * Establish trust relationship to a trusting domain.
6446 * Interdomain account must already be created on remote PDC.
6448 * @param c A net_context structure.
6449 * @param argc Standard argc.
6450 * @param argv Standard argv without initial components.
6452 * @return Integer status (0 means success).
6455 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
6458 struct cli_state
*cli
= NULL
;
6459 struct sockaddr_storage server_ss
;
6460 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6461 struct policy_handle connect_hnd
;
6462 TALLOC_CTX
*mem_ctx
;
6463 NTSTATUS nt_status
, result
;
6464 struct dom_sid
*domain_sid
;
6469 union lsa_PolicyInformation
*info
= NULL
;
6470 struct dcerpc_binding_handle
*b
;
6473 * Connect to \\server\ipc$ as 'our domain' account with password
6476 if (argc
!= 1 || c
->display_usage
) {
6479 _("net rpc trustdom establish <domain_name>\n"));
6483 domain_name
= smb_xstrdup(argv
[0]);
6484 if (!strupper_m(domain_name
)) {
6485 SAFE_FREE(domain_name
);
6489 /* account name used at first is our domain's name with '$' */
6490 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
6493 if (!strupper_m(acct_name
)) {
6494 SAFE_FREE(domain_name
);
6495 SAFE_FREE(acct_name
);
6500 * opt_workgroup will be used by connection functions further,
6501 * hence it should be set to remote domain name instead of ours
6503 if (c
->opt_workgroup
) {
6504 c
->opt_workgroup
= smb_xstrdup(domain_name
);
6507 c
->opt_user_name
= acct_name
;
6509 /* find the domain controller */
6510 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
6511 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
6515 /* connect to ipc$ as username/password */
6516 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
6517 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
6519 /* Is it trusting domain account for sure ? */
6520 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6521 nt_errstr(nt_status
)));
6525 /* store who we connected to */
6527 saf_store( domain_name
, pdc_name
);
6530 * Connect to \\server\ipc$ again (this time anonymously)
6533 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
6536 if (NT_STATUS_IS_ERR(nt_status
)) {
6537 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6538 domain_name
, nt_errstr(nt_status
)));
6542 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
6543 "domain %s", domain_name
))) {
6544 DEBUG(0, ("talloc_init() failed\n"));
6549 /* Make sure we're talking to a proper server */
6551 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
6552 if (!NT_STATUS_IS_OK(nt_status
)) {
6554 talloc_destroy(mem_ctx
);
6559 * Call LsaOpenPolicy and LsaQueryInfo
6562 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6564 if (!NT_STATUS_IS_OK(nt_status
)) {
6565 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
6567 talloc_destroy(mem_ctx
);
6571 b
= pipe_hnd
->binding_handle
;
6573 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
6575 if (NT_STATUS_IS_ERR(nt_status
)) {
6576 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6577 nt_errstr(nt_status
)));
6579 talloc_destroy(mem_ctx
);
6583 /* Querying info level 5 */
6585 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6587 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6590 if (NT_STATUS_IS_ERR(nt_status
)) {
6591 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6592 nt_errstr(nt_status
)));
6594 talloc_destroy(mem_ctx
);
6597 if (NT_STATUS_IS_ERR(result
)) {
6598 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6599 nt_errstr(result
)));
6601 talloc_destroy(mem_ctx
);
6605 domain_sid
= info
->account_domain
.sid
;
6607 /* There should be actually query info level 3 (following nt serv behaviour),
6608 but I still don't know if it's _really_ necessary */
6611 * Store the password in secrets db
6614 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
6615 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6617 talloc_destroy(mem_ctx
);
6622 * Close the pipes and clean up
6625 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
6626 if (NT_STATUS_IS_ERR(nt_status
)) {
6627 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6628 nt_errstr(nt_status
)));
6630 talloc_destroy(mem_ctx
);
6636 talloc_destroy(mem_ctx
);
6638 d_printf(_("Trust to domain %s established\n"), domain_name
);
6643 * Revoke trust relationship to the remote domain.
6645 * @param c A net_context structure.
6646 * @param argc Standard argc.
6647 * @param argv Standard argv without initial components.
6649 * @return Integer status (0 means success).
6652 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
6658 if (argc
< 1 || c
->display_usage
) {
6661 _("net rpc trustdom revoke <domain_name>\n"
6662 " Revoke trust relationship\n"
6663 " domain_name\tName of domain to revoke trust\n"));
6667 /* generate upper cased domain name */
6668 domain_name
= smb_xstrdup(argv
[0]);
6669 if (!strupper_m(domain_name
)) {
6670 SAFE_FREE(domain_name
);
6674 /* delete password of the trust */
6675 if (!pdb_del_trusteddom_pw(domain_name
)) {
6676 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6683 SAFE_FREE(domain_name
);
6687 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
6688 const struct dom_sid
*domain_sid
,
6689 const char *domain_name
,
6690 struct cli_state
*cli
,
6691 struct rpc_pipe_client
*pipe_hnd
,
6692 TALLOC_CTX
*mem_ctx
,
6697 if (!sid_to_fstring(str_sid
, domain_sid
)) {
6698 return NT_STATUS_UNSUCCESSFUL
;
6700 d_printf("%s\n", str_sid
);
6701 return NT_STATUS_OK
;
6704 static void print_trusted_domain(struct dom_sid
*dom_sid
, const char *trusted_dom_name
)
6708 /* convert sid into ascii string */
6709 sid_to_fstring(ascii_sid
, dom_sid
);
6711 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
6714 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
6715 TALLOC_CTX
*mem_ctx
,
6716 struct policy_handle
*pol
,
6717 struct dom_sid dom_sid
,
6718 const char *trusted_dom_name
)
6720 NTSTATUS nt_status
, result
;
6721 union lsa_TrustedDomainInfo
*info
= NULL
;
6722 char *cleartextpwd
= NULL
;
6723 DATA_BLOB session_key
;
6724 DATA_BLOB data
= data_blob_null
;
6725 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6727 nt_status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
6730 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
6733 if (NT_STATUS_IS_ERR(nt_status
)) {
6734 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6735 nt_errstr(nt_status
)));
6738 if (NT_STATUS_IS_ERR(result
)) {
6740 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6741 nt_errstr(result
)));
6745 data
= data_blob(info
->password
.password
->data
,
6746 info
->password
.password
->length
);
6748 nt_status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
6749 if (!NT_STATUS_IS_OK(nt_status
)) {
6750 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(nt_status
)));
6754 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key
);
6755 data_blob_free(&session_key
);
6757 if (cleartextpwd
== NULL
) {
6758 DEBUG(0,("retrieved NULL password\n"));
6759 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6763 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
6764 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6765 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6769 #ifdef DEBUG_PASSWORD
6770 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6771 "password: [%s]\n", trusted_dom_name
,
6772 sid_string_dbg(&dom_sid
), cleartextpwd
));
6776 SAFE_FREE(cleartextpwd
);
6777 data_blob_free(&data
);
6782 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
6785 /* common variables */
6786 TALLOC_CTX
* mem_ctx
;
6787 struct cli_state
*cli
= NULL
;
6788 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6789 NTSTATUS nt_status
, result
;
6790 const char *domain_name
= NULL
;
6791 struct policy_handle connect_hnd
;
6792 union lsa_PolicyInformation
*info
= NULL
;
6794 /* trusted domains listing variables */
6795 unsigned int enum_ctx
= 0;
6797 struct lsa_DomainList dom_list
;
6799 struct dcerpc_binding_handle
*b
;
6801 if (c
->display_usage
) {
6803 "net rpc trustdom vampire\n"
6806 _("Vampire trust relationship from remote server"));
6811 * Listing trusted domains (stored in secrets.tdb, if local)
6814 mem_ctx
= talloc_init("trust relationships vampire");
6817 * set domain and pdc name to local samba server (default)
6818 * or to remote one given in command line
6821 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
6822 domain_name
= c
->opt_workgroup
;
6823 c
->opt_target_workgroup
= c
->opt_workgroup
;
6825 fstrcpy(pdc_name
, lp_netbios_name());
6826 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6827 c
->opt_target_workgroup
= domain_name
;
6830 /* open \PIPE\lsarpc and open policy handle */
6831 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6832 if (!NT_STATUS_IS_OK(nt_status
)) {
6833 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6834 nt_errstr(nt_status
)));
6835 talloc_destroy(mem_ctx
);
6839 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6841 if (!NT_STATUS_IS_OK(nt_status
)) {
6842 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6843 nt_errstr(nt_status
) ));
6845 talloc_destroy(mem_ctx
);
6849 b
= pipe_hnd
->binding_handle
;
6851 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6853 if (NT_STATUS_IS_ERR(nt_status
)) {
6854 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6855 nt_errstr(nt_status
)));
6857 talloc_destroy(mem_ctx
);
6861 /* query info level 5 to obtain sid of a domain being queried */
6862 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6864 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6868 if (NT_STATUS_IS_ERR(nt_status
)) {
6869 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6870 nt_errstr(nt_status
)));
6872 talloc_destroy(mem_ctx
);
6875 if (NT_STATUS_IS_ERR(result
)) {
6876 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6877 nt_errstr(result
)));
6879 talloc_destroy(mem_ctx
);
6884 * Keep calling LsaEnumTrustdom over opened pipe until
6885 * the end of enumeration is reached
6888 d_printf(_("Vampire trusted domains:\n\n"));
6891 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
6897 if (NT_STATUS_IS_ERR(nt_status
)) {
6898 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6899 nt_errstr(nt_status
)));
6901 talloc_destroy(mem_ctx
);
6904 if (NT_STATUS_IS_ERR(result
)) {
6906 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6907 nt_errstr(result
)));
6909 talloc_destroy(mem_ctx
);
6914 for (i
= 0; i
< dom_list
.count
; i
++) {
6916 print_trusted_domain(dom_list
.domains
[i
].sid
,
6917 dom_list
.domains
[i
].name
.string
);
6919 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6920 *dom_list
.domains
[i
].sid
,
6921 dom_list
.domains
[i
].name
.string
);
6922 if (!NT_STATUS_IS_OK(nt_status
)) {
6924 talloc_destroy(mem_ctx
);
6930 * in case of no trusted domains say something rather
6931 * than just display blank line
6933 if (!dom_list
.count
) d_printf(_("none\n"));
6935 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6937 /* close this connection before doing next one */
6938 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
6939 if (NT_STATUS_IS_ERR(nt_status
)) {
6940 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6941 nt_errstr(nt_status
)));
6943 talloc_destroy(mem_ctx
);
6947 /* close lsarpc pipe and connection to IPC$ */
6950 talloc_destroy(mem_ctx
);
6954 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6956 /* common variables */
6957 TALLOC_CTX
* mem_ctx
;
6958 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6959 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6960 NTSTATUS nt_status
, result
;
6961 const char *domain_name
= NULL
;
6962 struct dom_sid
*queried_dom_sid
;
6963 int ascii_dom_name_len
;
6964 struct policy_handle connect_hnd
;
6965 union lsa_PolicyInformation
*info
= NULL
;
6966 struct dcerpc_binding_handle
*b
= NULL
;
6968 /* trusted domains listing variables */
6969 unsigned int num_domains
, enum_ctx
= 0;
6971 struct lsa_DomainList dom_list
;
6975 /* trusting domains listing variables */
6976 struct policy_handle domain_hnd
;
6977 struct samr_SamArray
*trusts
= NULL
;
6979 if (c
->display_usage
) {
6981 "net rpc trustdom list\n"
6984 _("List incoming and outgoing trust relationships"));
6989 * Listing trusted domains (stored in secrets.tdb, if local)
6992 mem_ctx
= talloc_init("trust relationships listing");
6995 * set domain and pdc name to local samba server (default)
6996 * or to remote one given in command line
6999 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
7000 domain_name
= c
->opt_workgroup
;
7001 c
->opt_target_workgroup
= c
->opt_workgroup
;
7003 fstrcpy(pdc_name
, lp_netbios_name());
7004 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
7005 c
->opt_target_workgroup
= domain_name
;
7008 /* open \PIPE\lsarpc and open policy handle */
7009 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
7010 if (!NT_STATUS_IS_OK(nt_status
)) {
7011 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
7012 nt_errstr(nt_status
)));
7013 talloc_destroy(mem_ctx
);
7017 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
7019 if (!NT_STATUS_IS_OK(nt_status
)) {
7020 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
7021 nt_errstr(nt_status
) ));
7023 talloc_destroy(mem_ctx
);
7027 b
= pipe_hnd
->binding_handle
;
7029 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
7031 if (NT_STATUS_IS_ERR(nt_status
)) {
7032 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
7033 nt_errstr(nt_status
)));
7035 talloc_destroy(mem_ctx
);
7039 /* query info level 5 to obtain sid of a domain being queried */
7040 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
7042 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
7046 if (NT_STATUS_IS_ERR(nt_status
)) {
7047 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7048 nt_errstr(nt_status
)));
7050 talloc_destroy(mem_ctx
);
7053 if (NT_STATUS_IS_ERR(result
)) {
7054 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7055 nt_errstr(result
)));
7057 talloc_destroy(mem_ctx
);
7061 queried_dom_sid
= info
->account_domain
.sid
;
7064 * Keep calling LsaEnumTrustdom over opened pipe until
7065 * the end of enumeration is reached
7068 d_printf(_("Trusted domains list:\n\n"));
7070 found_domain
= false;
7073 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
7079 if (NT_STATUS_IS_ERR(nt_status
)) {
7080 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7081 nt_errstr(nt_status
)));
7083 talloc_destroy(mem_ctx
);
7086 if (NT_STATUS_IS_ERR(result
)) {
7087 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7088 nt_errstr(result
)));
7090 talloc_destroy(mem_ctx
);
7095 for (i
= 0; i
< dom_list
.count
; i
++) {
7096 print_trusted_domain(dom_list
.domains
[i
].sid
,
7097 dom_list
.domains
[i
].name
.string
);
7098 found_domain
= true;
7102 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
7105 * in case of no trusted domains say something rather
7106 * than just display blank line
7108 if (!found_domain
) {
7109 d_printf(_("none\n"));
7112 /* close this connection before doing next one */
7113 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7114 if (NT_STATUS_IS_ERR(nt_status
)) {
7115 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
7116 nt_errstr(nt_status
)));
7118 talloc_destroy(mem_ctx
);
7122 TALLOC_FREE(pipe_hnd
);
7125 * Listing trusting domains (stored in passdb backend, if local)
7128 d_printf(_("\nTrusting domains list:\n\n"));
7131 * Open \PIPE\samr and get needed policy handles
7133 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
,
7135 if (!NT_STATUS_IS_OK(nt_status
)) {
7136 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
7138 talloc_destroy(mem_ctx
);
7142 b
= pipe_hnd
->binding_handle
;
7145 nt_status
= dcerpc_samr_Connect2(b
, mem_ctx
,
7147 SAMR_ACCESS_LOOKUP_DOMAIN
,
7150 if (!NT_STATUS_IS_OK(nt_status
)) {
7151 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7152 nt_errstr(nt_status
)));
7154 talloc_destroy(mem_ctx
);
7157 if (!NT_STATUS_IS_OK(result
)) {
7159 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7160 nt_errstr(result
)));
7162 talloc_destroy(mem_ctx
);
7166 /* SamrOpenDomain - we have to open domain policy handle in order to be
7167 able to enumerate accounts*/
7168 nt_status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
7170 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
7174 if (!NT_STATUS_IS_OK(nt_status
)) {
7175 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7176 nt_errstr(nt_status
)));
7178 talloc_destroy(mem_ctx
);
7181 if (!NT_STATUS_IS_OK(result
)) {
7183 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7184 nt_errstr(result
)));
7186 talloc_destroy(mem_ctx
);
7191 * perform actual enumeration
7194 found_domain
= false;
7196 enum_ctx
= 0; /* reset enumeration context from last enumeration */
7199 nt_status
= dcerpc_samr_EnumDomainUsers(b
, mem_ctx
,
7207 if (NT_STATUS_IS_ERR(nt_status
)) {
7208 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7209 nt_errstr(nt_status
)));
7211 talloc_destroy(mem_ctx
);
7214 if (NT_STATUS_IS_ERR(result
)) {
7216 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7217 nt_errstr(result
)));
7219 talloc_destroy(mem_ctx
);
7223 for (i
= 0; i
< num_domains
; i
++) {
7225 char *str
= discard_const_p(char, trusts
->entries
[i
].name
.string
);
7227 found_domain
= true;
7230 * get each single domain's sid (do we _really_ need this ?):
7231 * 1) connect to domain's pdc
7232 * 2) query the pdc for domain's sid
7235 /* get rid of '$' tail */
7236 ascii_dom_name_len
= strlen(str
);
7237 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
7238 str
[ascii_dom_name_len
- 1] = '\0';
7240 /* set opt_* variables to remote domain */
7241 if (!strupper_m(str
)) {
7243 talloc_destroy(mem_ctx
);
7246 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
7247 c
->opt_target_workgroup
= c
->opt_workgroup
;
7249 d_printf("%-20s", str
);
7251 /* connect to remote domain controller */
7252 nt_status
= net_make_ipc_connection(c
,
7253 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
7255 if (NT_STATUS_IS_OK(nt_status
)) {
7256 /* query for domain's sid */
7257 if (run_rpc_command(
7259 &ndr_table_lsarpc
, 0,
7260 rpc_query_domain_sid
, argc
,
7262 d_printf(_("strange - couldn't get domain's sid\n"));
7264 cli_shutdown(remote_cli
);
7267 d_fprintf(stderr
, _("domain controller is not "
7268 "responding: %s\n"),
7269 nt_errstr(nt_status
));
7270 d_printf(_("couldn't get domain's sid\n"));
7274 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
7276 if (!found_domain
) {
7280 /* close opened samr and domain policy handles */
7281 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_hnd
, &result
);
7282 if (!NT_STATUS_IS_OK(nt_status
)) {
7283 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
7286 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7287 if (!NT_STATUS_IS_OK(nt_status
)) {
7288 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
7291 /* close samr pipe and connection to IPC$ */
7294 talloc_destroy(mem_ctx
);
7299 * Entrypoint for 'net rpc trustdom' code.
7301 * @param argc Standard argc.
7302 * @param argv Standard argv without initial components.
7304 * @return Integer status (0 means success).
7307 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
7309 struct functable func
[] = {
7314 N_("Add trusting domain's account"),
7315 N_("net rpc trustdom add\n"
7316 " Add trusting domain's account")
7322 N_("Remove trusting domain's account"),
7323 N_("net rpc trustdom del\n"
7324 " Remove trusting domain's account")
7328 rpc_trustdom_establish
,
7330 N_("Establish outgoing trust relationship"),
7331 N_("net rpc trustdom establish\n"
7332 " Establish outgoing trust relationship")
7336 rpc_trustdom_revoke
,
7338 N_("Revoke outgoing trust relationship"),
7339 N_("net rpc trustdom revoke\n"
7340 " Revoke outgoing trust relationship")
7346 N_("List in- and outgoing domain trusts"),
7347 N_("net rpc trustdom list\n"
7348 " List in- and outgoing domain trusts")
7352 rpc_trustdom_vampire
,
7354 N_("Vampire trusts from remote server"),
7355 N_("net rpc trustdom vampire\n"
7356 " Vampire trusts from remote server")
7358 {NULL
, NULL
, 0, NULL
, NULL
}
7361 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
7365 * Check if a server will take rpc commands
7366 * @param flags Type of server to connect to (PDC, DMB, localhost)
7367 * if the host is not explicitly specified
7368 * @return bool (true means rpc supported)
7370 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
7372 struct cli_state
*cli
;
7374 struct sockaddr_storage server_ss
;
7375 char *server_name
= NULL
;
7378 /* flags (i.e. server type) may depend on command */
7379 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
7382 status
= cli_connect_nb(server_name
, &server_ss
, 0, 0x20,
7383 lp_netbios_name(), SMB_SIGNING_DEFAULT
,
7385 if (!NT_STATUS_IS_OK(status
)) {
7388 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
, PROTOCOL_CORE
,
7390 if (!NT_STATUS_IS_OK(status
))
7392 if (smbXcli_conn_protocol(cli
->conn
) < PROTOCOL_NT1
)
7401 /* dump sam database via samsync rpc calls */
7402 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
7403 if (c
->display_usage
) {
7408 _("Dump remote SAM database"));
7412 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
,
7413 NET_FLAGS_ANONYMOUS
,
7414 rpc_samdump_internals
, argc
, argv
);
7417 /* syncronise sam database via samsync rpc calls */
7418 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
7420 struct functable func
[] = {
7425 N_("Dump remote SAM database to ldif"),
7426 N_("net rpc vampire ldif\n"
7427 " Dump remote SAM database to LDIF file or "
7434 N_("Dump remote SAM database to Kerberos Keytab"),
7435 N_("net rpc vampire keytab\n"
7436 " Dump remote SAM database to Kerberos keytab "
7443 N_("Dump remote SAM database to passdb"),
7444 N_("net rpc vampire passdb\n"
7445 " Dump remote SAM database to passdb")
7448 {NULL
, NULL
, 0, NULL
, NULL
}
7452 if (c
->display_usage
) {
7457 _("Vampire remote SAM database"));
7461 return rpc_vampire_passdb(c
, argc
, argv
);
7464 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
7468 * Migrate everything from a print server.
7470 * @param c A net_context structure.
7471 * @param argc Standard main() style argc.
7472 * @param argv Standard main() style argv. Initial components are already
7475 * @return A shell status integer (0 for success).
7477 * The order is important !
7478 * To successfully add drivers the print queues have to exist !
7479 * Applying ACLs should be the last step, because you're easily locked out.
7482 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
7487 if (c
->display_usage
) {
7489 "net rpc printer migrate all\n"
7492 _("Migrate everything from a print server"));
7497 d_printf(_("no server to migrate\n"));
7501 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7502 rpc_printer_migrate_printers_internals
, argc
,
7507 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7508 rpc_printer_migrate_drivers_internals
, argc
,
7513 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7514 rpc_printer_migrate_forms_internals
, argc
, argv
);
7518 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7519 rpc_printer_migrate_settings_internals
, argc
,
7524 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7525 rpc_printer_migrate_security_internals
, argc
,
7531 * Migrate print drivers from a print server.
7533 * @param c A net_context structure.
7534 * @param argc Standard main() style argc.
7535 * @param argv Standard main() style argv. Initial components are already
7538 * @return A shell status integer (0 for success).
7540 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
7543 if (c
->display_usage
) {
7545 "net rpc printer migrate drivers\n"
7548 _("Migrate print-drivers from a print-server"));
7553 d_printf(_("no server to migrate\n"));
7557 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7558 rpc_printer_migrate_drivers_internals
,
7563 * Migrate print-forms from a print-server.
7565 * @param c A net_context structure.
7566 * @param argc Standard main() style argc.
7567 * @param argv Standard main() style argv. Initial components are already
7570 * @return A shell status integer (0 for success).
7572 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
7575 if (c
->display_usage
) {
7577 "net rpc printer migrate forms\n"
7580 _("Migrate print-forms from a print-server"));
7585 d_printf(_("no server to migrate\n"));
7589 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7590 rpc_printer_migrate_forms_internals
,
7595 * Migrate printers from a print-server.
7597 * @param c A net_context structure.
7598 * @param argc Standard main() style argc.
7599 * @param argv Standard main() style argv. Initial components are already
7602 * @return A shell status integer (0 for success).
7604 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
7607 if (c
->display_usage
) {
7609 "net rpc printer migrate printers\n"
7612 _("Migrate printers from a print-server"));
7617 d_printf(_("no server to migrate\n"));
7621 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7622 rpc_printer_migrate_printers_internals
,
7627 * Migrate printer-ACLs from a print-server
7629 * @param c A net_context structure.
7630 * @param argc Standard main() style argc.
7631 * @param argv Standard main() style argv. Initial components are already
7634 * @return A shell status integer (0 for success).
7636 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
7639 if (c
->display_usage
) {
7641 "net rpc printer migrate security\n"
7644 _("Migrate printer-ACLs from a print-server"));
7649 d_printf(_("no server to migrate\n"));
7653 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7654 rpc_printer_migrate_security_internals
,
7659 * Migrate printer-settings from a print-server.
7661 * @param c A net_context structure.
7662 * @param argc Standard main() style argc.
7663 * @param argv Standard main() style argv. Initial components are already
7666 * @return A shell status integer (0 for success).
7668 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
7671 if (c
->display_usage
) {
7673 "net rpc printer migrate settings\n"
7676 _("Migrate printer-settings from a "
7682 d_printf(_("no server to migrate\n"));
7686 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7687 rpc_printer_migrate_settings_internals
,
7692 * 'net rpc printer' entrypoint.
7694 * @param c A net_context structure.
7695 * @param argc Standard main() style argc.
7696 * @param argv Standard main() style argv. Initial components are already
7700 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
7703 /* ouch: when addriver and setdriver are called from within
7704 rpc_printer_migrate_drivers_internals, the printer-queue already
7707 struct functable func
[] = {
7710 rpc_printer_migrate_all
,
7712 N_("Migrate all from remote to local print server"),
7713 N_("net rpc printer migrate all\n"
7714 " Migrate all from remote to local print server")
7718 rpc_printer_migrate_drivers
,
7720 N_("Migrate drivers to local server"),
7721 N_("net rpc printer migrate drivers\n"
7722 " Migrate drivers to local server")
7726 rpc_printer_migrate_forms
,
7728 N_("Migrate froms to local server"),
7729 N_("net rpc printer migrate forms\n"
7730 " Migrate froms to local server")
7734 rpc_printer_migrate_printers
,
7736 N_("Migrate printers to local server"),
7737 N_("net rpc printer migrate printers\n"
7738 " Migrate printers to local server")
7742 rpc_printer_migrate_security
,
7744 N_("Mirgate printer ACLs to local server"),
7745 N_("net rpc printer migrate security\n"
7746 " Mirgate printer ACLs to local server")
7750 rpc_printer_migrate_settings
,
7752 N_("Migrate printer settings to local server"),
7753 N_("net rpc printer migrate settings\n"
7754 " Migrate printer settings to local server")
7756 {NULL
, NULL
, 0, NULL
, NULL
}
7759 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
7764 * List printers on a remote RPC server.
7766 * @param c A net_context structure.
7767 * @param argc Standard main() style argc.
7768 * @param argv Standard main() style argv. Initial components are already
7771 * @return A shell status integer (0 for success).
7773 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
7775 if (c
->display_usage
) {
7777 "net rpc printer list\n"
7780 _("List printers on a remote RPC server"));
7784 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7785 rpc_printer_list_internals
,
7790 * List printer-drivers on a remote RPC server.
7792 * @param c A net_context structure.
7793 * @param argc Standard main() style argc.
7794 * @param argv Standard main() style argv. Initial components are already
7797 * @return A shell status integer (0 for success).
7799 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
7802 if (c
->display_usage
) {
7804 "net rpc printer driver\n"
7807 _("List printer-drivers on a remote RPC server"));
7811 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7812 rpc_printer_driver_list_internals
,
7817 * Publish printer in ADS via MSRPC.
7819 * @param c A net_context structure.
7820 * @param argc Standard main() style argc.
7821 * @param argv Standard main() style argv. Initial components are already
7824 * @return A shell status integer (0 for success).
7826 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
7829 if (c
->display_usage
) {
7831 "net rpc printer publish publish\n"
7834 _("Publish printer in ADS via MSRPC"));
7838 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7839 rpc_printer_publish_publish_internals
,
7844 * Update printer in ADS via MSRPC.
7846 * @param c A net_context structure.
7847 * @param argc Standard main() style argc.
7848 * @param argv Standard main() style argv. Initial components are already
7851 * @return A shell status integer (0 for success).
7853 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
7855 if (c
->display_usage
) {
7857 "net rpc printer publish update\n"
7860 _("Update printer in ADS via MSRPC"));
7864 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7865 rpc_printer_publish_update_internals
,
7870 * UnPublish printer in ADS via MSRPC.
7872 * @param c A net_context structure.
7873 * @param argc Standard main() style argc.
7874 * @param argv Standard main() style argv. Initial components are already
7877 * @return A shell status integer (0 for success).
7879 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
7882 if (c
->display_usage
) {
7884 "net rpc printer publish unpublish\n"
7887 _("UnPublish printer in ADS via MSRPC"));
7891 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7892 rpc_printer_publish_unpublish_internals
,
7897 * List published printers via MSRPC.
7899 * @param c A net_context structure.
7900 * @param argc Standard main() style argc.
7901 * @param argv Standard main() style argv. Initial components are already
7904 * @return A shell status integer (0 for success).
7906 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
7909 if (c
->display_usage
) {
7911 "net rpc printer publish list\n"
7914 _("List published printers via MSRPC"));
7918 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7919 rpc_printer_publish_list_internals
,
7925 * Publish printer in ADS.
7927 * @param c A net_context structure.
7928 * @param argc Standard main() style argc.
7929 * @param argv Standard main() style argv. Initial components are already
7932 * @return A shell status integer (0 for success).
7934 static int rpc_printer_publish(struct net_context
*c
, int argc
,
7938 struct functable func
[] = {
7941 rpc_printer_publish_publish
,
7943 N_("Publish printer in AD"),
7944 N_("net rpc printer publish publish\n"
7945 " Publish printer in AD")
7949 rpc_printer_publish_update
,
7951 N_("Update printer in AD"),
7952 N_("net rpc printer publish update\n"
7953 " Update printer in AD")
7957 rpc_printer_publish_unpublish
,
7959 N_("Unpublish printer"),
7960 N_("net rpc printer publish unpublish\n"
7961 " Unpublish printer")
7965 rpc_printer_publish_list
,
7967 N_("List published printers"),
7968 N_("net rpc printer publish list\n"
7969 " List published printers")
7971 {NULL
, NULL
, 0, NULL
, NULL
}
7975 if (c
->display_usage
) {
7976 d_printf(_("Usage:\n"));
7977 d_printf(_("net rpc printer publish\n"
7978 " List published printers\n"
7979 " Alias of net rpc printer publish "
7981 net_display_usage_from_functable(func
);
7984 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7985 rpc_printer_publish_list_internals
,
7989 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
7995 * Display rpc printer help page.
7997 * @param c A net_context structure.
7998 * @param argc Standard main() style argc.
7999 * @param argv Standard main() style argv. Initial components are already
8002 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
8004 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
8005 "\tlists all printers on print-server\n\n"));
8006 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
8007 "\tlists all printer-drivers on print-server\n\n"));
8008 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
8009 "\tpublishes printer settings in Active Directory\n"
8010 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
8011 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
8012 "\n\tmigrates printers from remote to local server\n\n"));
8013 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
8014 "\n\tmigrates printer-settings from remote to local server\n\n"));
8015 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
8016 "\n\tmigrates printer-drivers from remote to local server\n\n"));
8017 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
8018 "\n\tmigrates printer-forms from remote to local server\n\n"));
8019 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
8020 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
8021 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
8022 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
8023 "\tremote to local print-server\n\n"));
8024 net_common_methods_usage(c
, argc
, argv
);
8025 net_common_flags_usage(c
, argc
, argv
);
8027 "\t-v or --verbose\t\t\tgive verbose output\n"
8028 "\t --destination\t\tmigration target server (default: localhost)\n"));
8034 * 'net rpc printer' entrypoint.
8036 * @param c A net_context structure.
8037 * @param argc Standard main() style argc.
8038 * @param argv Standard main() style argv. Initial components are already
8041 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
8043 struct functable func
[] = {
8048 N_("List all printers on print server"),
8049 N_("net rpc printer list\n"
8050 " List all printers on print server")
8054 rpc_printer_migrate
,
8056 N_("Migrate printer to local server"),
8057 N_("net rpc printer migrate\n"
8058 " Migrate printer to local server")
8062 rpc_printer_driver_list
,
8064 N_("List printer drivers"),
8065 N_("net rpc printer driver\n"
8066 " List printer drivers")
8070 rpc_printer_publish
,
8072 N_("Publish printer in AD"),
8073 N_("net rpc printer publish\n"
8074 " Publish printer in AD")
8076 {NULL
, NULL
, 0, NULL
, NULL
}
8080 if (c
->display_usage
) {
8081 d_printf(_("Usage:\n"));
8082 d_printf(_("net rpc printer\n"
8083 " List printers\n"));
8084 net_display_usage_from_functable(func
);
8087 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
8088 rpc_printer_list_internals
,
8092 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
8096 * 'net rpc' entrypoint.
8098 * @param c A net_context structure.
8099 * @param argc Standard main() style argc.
8100 * @param argv Standard main() style argv. Initial components are already
8104 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
8106 NET_API_STATUS status
;
8108 struct functable func
[] = {
8113 N_("Modify global audit settings"),
8114 N_("net rpc audit\n"
8115 " Modify global audit settings")
8121 N_("Show basic info about a domain"),
8123 " Show basic info about a domain")
8129 N_("Join a domain"),
8137 N_("Join a domain created in server manager"),
8138 N_("net rpc oldjoin\n"
8139 " Join a domain created in server manager")
8145 N_("Test that a join is valid"),
8146 N_("net rpc testjoin\n"
8147 " Test that a join is valid")
8153 N_("List/modify users"),
8155 " List/modify users")
8161 N_("Change a user password"),
8162 N_("net rpc password\n"
8163 " Change a user password\n"
8164 " Alias for net rpc user password")
8170 N_("List/modify groups"),
8171 N_("net rpc group\n"
8172 " List/modify groups")
8178 N_("List/modify shares"),
8179 N_("net rpc share\n"
8180 " List/modify shares")
8186 N_("List open files"),
8194 N_("List/modify printers"),
8195 N_("net rpc printer\n"
8196 " List/modify printers")
8200 net_rpc_changetrustpw
,
8202 N_("Change trust account password"),
8203 N_("net rpc changetrustpw\n"
8204 " Change trust account password")
8210 N_("Modify domain trusts"),
8211 N_("net rpc trustdom\n"
8212 " Modify domain trusts")
8218 N_("Abort a remote shutdown"),
8219 N_("net rpc abortshutdown\n"
8220 " Abort a remote shutdown")
8226 N_("Shutdown a remote server"),
8227 N_("net rpc shutdown\n"
8228 " Shutdown a remote server")
8234 N_("Dump SAM data of remote NT PDC"),
8235 N_("net rpc samdump\n"
8236 " Dump SAM data of remote NT PDC")
8242 N_("Sync a remote NT PDC's data into local passdb"),
8243 N_("net rpc vampire\n"
8244 " Sync a remote NT PDC's data into local passdb")
8250 N_("Fetch the domain sid into local secrets.tdb"),
8251 N_("net rpc getsid\n"
8252 " Fetch the domain sid into local secrets.tdb")
8258 N_("Manage privileges assigned to SID"),
8259 N_("net rpc rights\n"
8260 " Manage privileges assigned to SID")
8266 N_("Start/stop/query remote services"),
8267 N_("net rpc service\n"
8268 " Start/stop/query remote services")
8274 N_("Manage registry hives"),
8275 N_("net rpc registry\n"
8276 " Manage registry hives")
8282 N_("Open interactive shell on remote server"),
8283 N_("net rpc shell\n"
8284 " Open interactive shell on remote server")
8290 N_("Manage trusts"),
8291 N_("net rpc trust\n"
8298 N_("Configure a remote samba server"),
8300 " Configure a remote samba server")
8302 {NULL
, NULL
, 0, NULL
, NULL
}
8305 status
= libnetapi_net_init(&c
->netapi_ctx
);
8309 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
8310 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
8311 if (c
->opt_kerberos
) {
8312 libnetapi_set_use_kerberos(c
->netapi_ctx
);
8314 if (c
->opt_ccache
) {
8315 libnetapi_set_use_ccache(c
->netapi_ctx
);
8318 return net_run_function(c
, argc
, argv
, "net rpc", func
);