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
,
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);
386 werr
= WERR_NOT_ENOUGH_MEMORY
;
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
) {
397 werr
= WERR_NOT_ENOUGH_MEMORY
;
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 /* print out informative error string in case there is one */
432 if (r
->out
.error_string
!= NULL
) {
433 d_printf("%s\n", r
->out
.error_string
);
436 TALLOC_FREE(mem_ctx
);
441 if (c
->opt_flags
& NET_FLAGS_EXPECT_FALLBACK
) {
445 /* issue an overall failure message at the end. */
446 d_fprintf(stderr
, _("Failed to join domain: %s\n"),
447 r
&& r
->out
.error_string
? r
->out
.error_string
:
448 get_friendly_werror_msg(werr
));
451 TALLOC_FREE(mem_ctx
);
457 * check that a join is OK
459 * @return A shell status integer (0 for success)
462 int net_rpc_testjoin(struct net_context
*c
, int argc
, const char **argv
)
466 const char *domain
= c
->opt_target_workgroup
;
467 const char *dc
= c
->opt_host
;
469 if (c
->display_usage
) {
472 " Test if a join is OK\n");
476 mem_ctx
= talloc_init("net_rpc_testjoin");
482 struct netr_DsRGetDCNameInfo
*info
;
485 d_fprintf(stderr
, _("Could not initialise message context. "
486 "Try running as root\n"));
487 talloc_destroy(mem_ctx
);
491 status
= dsgetdcname(mem_ctx
,
498 if (!NT_STATUS_IS_OK(status
)) {
499 talloc_destroy(mem_ctx
);
503 dc
= strip_hostname(info
->dc_unc
);
506 /* Display success or failure */
507 status
= libnet_join_ok(c
->msg_ctx
,
511 if (!NT_STATUS_IS_OK(status
)) {
512 fprintf(stderr
,"Join to domain '%s' is not valid: %s\n",
513 domain
, nt_errstr(status
));
514 talloc_destroy(mem_ctx
);
518 printf("Join to '%s' is OK\n",domain
);
519 talloc_destroy(mem_ctx
);
525 * Join a domain using the administrator username and password
527 * @param argc Standard main() style argc
528 * @param argc Standard main() style argv. Initial components are already
529 * stripped. Currently not used.
530 * @return A shell status integer (0 for success)
534 static int net_rpc_join_newstyle(struct net_context
*c
, int argc
, const char **argv
)
536 struct libnet_JoinCtx
*r
= NULL
;
539 const char *domain
= lp_workgroup(); /* FIXME */
540 bool modify_config
= lp_config_backend_is_registry();
541 enum netr_SchannelType sec_chan_type
;
543 if (c
->display_usage
) {
546 " Join a domain the new way\n");
550 mem_ctx
= talloc_init("net_rpc_join_newstyle");
555 werr
= libnet_init_JoinCtx(mem_ctx
, &r
);
556 if (!W_ERROR_IS_OK(werr
)) {
561 check what type of join - if the user want's to join as
562 a BDC, the server must agree that we are a BDC.
565 sec_chan_type
= get_sec_channel_type(argv
[0]);
567 sec_chan_type
= get_sec_channel_type(NULL
);
571 d_fprintf(stderr
, _("Could not initialise message context. "
572 "Try running as root\n"));
573 werr
= WERR_ACCESS_DENIED
;
577 r
->in
.msg_ctx
= c
->msg_ctx
;
578 r
->in
.domain_name
= domain
;
579 r
->in
.secure_channel_type
= sec_chan_type
;
580 r
->in
.dc_name
= c
->opt_host
;
581 r
->in
.admin_account
= c
->opt_user_name
;
582 r
->in
.admin_password
= net_prompt_pass(c
, c
->opt_user_name
);
584 r
->in
.use_kerberos
= c
->opt_kerberos
;
585 r
->in
.modify_config
= modify_config
;
586 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
587 WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
588 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
590 werr
= libnet_Join(mem_ctx
, r
);
591 if (!W_ERROR_IS_OK(werr
)) {
595 /* Check the short name of the domain */
597 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
598 d_printf("The workgroup in %s does not match the short\n", get_dyn_CONFIGFILE());
599 d_printf("domain name obtained from the server.\n");
600 d_printf("Using the name [%s] from the server.\n", r
->out
.netbios_domain_name
);
601 d_printf("You should set \"workgroup = %s\" in %s.\n",
602 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
605 d_printf("Using short domain name -- %s\n", r
->out
.netbios_domain_name
);
607 if (r
->out
.dns_domain_name
) {
608 d_printf("Joined '%s' to realm '%s'\n", r
->in
.machine_name
,
609 r
->out
.dns_domain_name
);
611 d_printf("Joined '%s' to domain '%s'\n", r
->in
.machine_name
,
612 r
->out
.netbios_domain_name
);
615 /* print out informative error string in case there is one */
616 if (r
->out
.error_string
!= NULL
) {
617 d_printf("%s\n", r
->out
.error_string
);
620 TALLOC_FREE(mem_ctx
);
625 /* issue an overall failure message at the end. */
626 d_printf("Failed to join domain: %s\n",
627 r
&& r
->out
.error_string
? r
->out
.error_string
:
628 get_friendly_werror_msg(werr
));
630 TALLOC_FREE(mem_ctx
);
636 * 'net rpc join' entrypoint.
637 * @param argc Standard main() style argc.
638 * @param argv Standard main() style argv. Initial components are already
641 * Main 'net_rpc_join()' (where the admin username/password is used) is
643 * Try to just change the password, but if that doesn't work, use/prompt
644 * for a username/password.
647 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
651 if (c
->display_usage
) {
654 _("net rpc join -U <username>[%%password] <type>\n"
656 " username\tName of the admin user"
657 " password\tPassword of the admin user, will "
658 "prompt if not specified\n"
659 " type\tCan be one of the following:\n"
660 "\t\tMEMBER\tJoin as member server (default)\n"
661 "\t\tBDC\tJoin as BDC\n"
662 "\t\tPDC\tJoin as PDC\n"));
666 if (lp_server_role() == ROLE_STANDALONE
) {
667 d_printf(_("cannot join as standalone machine\n"));
671 if (strlen(lp_netbios_name()) > 15) {
672 d_printf(_("Our netbios name can be at most 15 chars long, "
673 "\"%s\" is %u chars long\n"),
674 lp_netbios_name(), (unsigned int)strlen(lp_netbios_name()));
678 c
->opt_flags
|= NET_FLAGS_EXPECT_FALLBACK
;
679 ret
= net_rpc_oldjoin(c
, argc
, argv
);
680 c
->opt_flags
&= ~NET_FLAGS_EXPECT_FALLBACK
;
685 return net_rpc_join_newstyle(c
, argc
, argv
);
689 * display info about a rpc domain
691 * All parameters are provided by the run_rpc_command function, except for
692 * argc, argv which are passed through.
694 * @param domain_sid The domain sid acquired from the remote server
695 * @param cli A cli_state connected to the server.
696 * @param mem_ctx Talloc context, destroyed on completion of the function.
697 * @param argc Standard main() style argc.
698 * @param argv Standard main() style argv. Initial components are already
701 * @return Normal NTSTATUS return.
704 NTSTATUS
rpc_info_internals(struct net_context
*c
,
705 const struct dom_sid
*domain_sid
,
706 const char *domain_name
,
707 struct cli_state
*cli
,
708 struct rpc_pipe_client
*pipe_hnd
,
713 struct policy_handle connect_pol
, domain_pol
;
714 NTSTATUS status
, result
;
715 union samr_DomainInfo
*info
= NULL
;
717 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
719 sid_to_fstring(sid_str
, domain_sid
);
721 /* Get sam policy handle */
722 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
724 MAXIMUM_ALLOWED_ACCESS
,
727 if (!NT_STATUS_IS_OK(status
)) {
728 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
733 if (!NT_STATUS_IS_OK(result
)) {
735 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
740 /* Get domain policy handle */
741 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
743 MAXIMUM_ALLOWED_ACCESS
,
744 discard_const_p(struct dom_sid2
, domain_sid
),
747 if (!NT_STATUS_IS_OK(status
)) {
748 d_fprintf(stderr
, _("Could not open domain: %s\n"),
752 if (!NT_STATUS_IS_OK(result
)) {
754 d_fprintf(stderr
, _("Could not open domain: %s\n"),
759 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
764 if (!NT_STATUS_IS_OK(status
)) {
768 if (NT_STATUS_IS_OK(result
)) {
769 d_printf(_("Domain Name: %s\n"),
770 info
->general
.domain_name
.string
);
771 d_printf(_("Domain SID: %s\n"), sid_str
);
772 d_printf(_("Sequence number: %llu\n"),
773 (unsigned long long)info
->general
.sequence_num
);
774 d_printf(_("Num users: %u\n"), info
->general
.num_users
);
775 d_printf(_("Num domain groups: %u\n"),info
->general
.num_groups
);
776 d_printf(_("Num local groups: %u\n"),info
->general
.num_aliases
);
784 * 'net rpc info' entrypoint.
785 * @param argc Standard main() style argc.
786 * @param argv Standard main() style argv. Initial components are already
790 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
792 if (c
->display_usage
) {
797 _("Display information about the domain"));
801 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
802 NET_FLAGS_PDC
, rpc_info_internals
,
807 * Fetch domain SID into the local secrets.tdb.
809 * All parameters are provided by the run_rpc_command function, except for
810 * argc, argv which are passed through.
812 * @param domain_sid The domain sid acquired from the remote server.
813 * @param cli A cli_state connected to the server.
814 * @param mem_ctx Talloc context, destroyed on completion of the function.
815 * @param argc Standard main() style argc.
816 * @param argv Standard main() style argv. Initial components are already
819 * @return Normal NTSTATUS return.
822 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
823 const struct dom_sid
*domain_sid
,
824 const char *domain_name
,
825 struct cli_state
*cli
,
826 struct rpc_pipe_client
*pipe_hnd
,
833 sid_to_fstring(sid_str
, domain_sid
);
834 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
835 sid_str
, domain_name
);
837 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
838 DEBUG(0,("Can't store domain SID\n"));
839 return NT_STATUS_UNSUCCESSFUL
;
846 * 'net rpc getsid' entrypoint.
847 * @param argc Standard main() style argc.
848 * @param argv Standard main() style argv. Initial components are already
852 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
854 int conn_flags
= NET_FLAGS_PDC
;
856 if (!c
->opt_user_specified
) {
857 conn_flags
|= NET_FLAGS_ANONYMOUS
;
860 if (c
->display_usage
) {
865 _("Fetch domain SID into local secrets.tdb"));
869 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
871 rpc_getsid_internals
,
875 /****************************************************************************/
878 * Basic usage function for 'net rpc user'.
879 * @param argc Standard main() style argc.
880 * @param argv Standard main() style argv. Initial components are already
884 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
886 return net_user_usage(c
, argc
, argv
);
890 * Add a new user to a remote RPC server.
892 * @param argc Standard main() style argc.
893 * @param argv Standard main() style argv. Initial components are already
896 * @return A shell status integer (0 for success).
899 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
901 NET_API_STATUS status
;
902 struct USER_INFO_1 info1
;
903 uint32_t parm_error
= 0;
905 if (argc
< 1 || c
->display_usage
) {
906 rpc_user_usage(c
, argc
, argv
);
912 info1
.usri1_name
= argv
[0];
914 info1
.usri1_password
= argv
[1];
917 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
920 d_fprintf(stderr
,_("Failed to add user '%s' with error: %s.\n"),
921 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
925 d_printf(_("Added user '%s'.\n"), argv
[0]);
932 * Rename a user on a remote RPC server.
934 * @param argc Standard main() style argc.
935 * @param argv Standard main() style argv. Initial components are already
938 * @return A shell status integer (0 for success).
941 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
943 NET_API_STATUS status
;
944 struct USER_INFO_0 u0
;
945 uint32_t parm_err
= 0;
947 if (argc
!= 2 || c
->display_usage
) {
948 rpc_user_usage(c
, argc
, argv
);
952 u0
.usri0_name
= argv
[1];
954 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
955 0, (uint8_t *)&u0
, &parm_err
);
958 _("Failed to rename user from %s to %s - %s\n"),
960 libnetapi_get_error_string(c
->netapi_ctx
, status
));
962 d_printf(_("Renamed user from %s to %s\n"), argv
[0], argv
[1]);
969 * Set a user's primary group
971 * @param argc Standard main() style argc.
972 * @param argv Standard main() style argv. Initial components are already
975 * @return A shell status integer (0 for success).
978 static int rpc_user_setprimarygroup(struct net_context
*c
, int argc
,
981 NET_API_STATUS status
;
983 struct GROUP_INFO_2
*g2
;
984 struct USER_INFO_1051 u1051
;
985 uint32_t parm_err
= 0;
987 if (argc
!= 2 || c
->display_usage
) {
988 rpc_user_usage(c
, argc
, argv
);
992 status
= NetGroupGetInfo(c
->opt_host
, argv
[1], 2, &buffer
);
994 d_fprintf(stderr
, _("Failed to find group name %s -- %s\n"),
996 libnetapi_get_error_string(c
->netapi_ctx
, status
));
999 g2
= (struct GROUP_INFO_2
*)buffer
;
1001 u1051
.usri1051_primary_group_id
= g2
->grpi2_group_id
;
1003 NetApiBufferFree(buffer
);
1005 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1051,
1006 (uint8_t *)&u1051
, &parm_err
);
1009 _("Failed to set user's primary group %s to %s - "
1010 "%s\n"), argv
[0], argv
[1],
1011 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1013 d_printf(_("Set primary group of user %s to %s\n"), argv
[0],
1020 * Delete a user from a remote RPC server.
1022 * @param argc Standard main() style argc.
1023 * @param argv Standard main() style argv. Initial components are already
1026 * @return A shell status integer (0 for success).
1029 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
1031 NET_API_STATUS status
;
1033 if (argc
< 1 || c
->display_usage
) {
1034 rpc_user_usage(c
, argc
, argv
);
1038 status
= NetUserDel(c
->opt_host
, argv
[0]);
1041 d_fprintf(stderr
, _("Failed to delete user '%s' with: %s.\n"),
1043 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1046 d_printf(_("Deleted user '%s'.\n"), argv
[0]);
1053 * Set a user's password on a remote RPC server.
1055 * @param argc Standard main() style argc.
1056 * @param argv Standard main() style argv. Initial components are already
1059 * @return A shell status integer (0 for success).
1062 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
1064 NET_API_STATUS status
;
1065 char *prompt
= NULL
;
1066 struct USER_INFO_1003 u1003
;
1067 uint32_t parm_err
= 0;
1070 if (argc
< 1 || c
->display_usage
) {
1071 rpc_user_usage(c
, argc
, argv
);
1076 u1003
.usri1003_password
= argv
[1];
1078 char pwd
[256] = {0};
1079 ret
= asprintf(&prompt
, _("Enter new password for %s:"),
1085 ret
= samba_getpass(prompt
, pwd
, sizeof(pwd
), false, false);
1091 u1003
.usri1003_password
= talloc_strdup(c
, pwd
);
1092 if (u1003
.usri1003_password
== NULL
) {
1097 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
1099 /* Display results */
1102 _("Failed to set password for '%s' with error: %s.\n"),
1103 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1112 * List a user's groups from a remote RPC server.
1114 * @param argc Standard main() style argc.
1115 * @param argv Standard main() style argv. Initial components are already
1118 * @return A shell status integer (0 for success)
1121 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
1124 NET_API_STATUS status
;
1125 struct GROUP_USERS_INFO_0
*u0
= NULL
;
1126 uint32_t entries_read
= 0;
1127 uint32_t total_entries
= 0;
1131 if (argc
< 1 || c
->display_usage
) {
1132 rpc_user_usage(c
, argc
, argv
);
1136 status
= NetUserGetGroups(c
->opt_host
,
1139 (uint8_t **)(void *)&u0
,
1145 _("Failed to get groups for '%s' with error: %s.\n"),
1146 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1151 for (i
=0; i
< entries_read
; i
++) {
1152 printf("%s\n", u0
->grui0_name
);
1160 * List users on a remote RPC server.
1162 * All parameters are provided by the run_rpc_command function, except for
1163 * argc, argv which are passed through.
1165 * @param domain_sid The domain sid acquired from the remote server.
1166 * @param cli A cli_state connected to the server.
1167 * @param mem_ctx Talloc context, destroyed on completion of the function.
1168 * @param argc Standard main() style argc.
1169 * @param argv Standard main() style argv. Initial components are already
1172 * @return Normal NTSTATUS return.
1175 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
1177 NET_API_STATUS status
;
1178 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
1179 struct NET_DISPLAY_USER
*info
= NULL
;
1180 void *buffer
= NULL
;
1182 /* Query domain users */
1183 if (c
->opt_long_list_entries
)
1184 d_printf(_("\nUser name Comment"
1185 "\n-----------------------------\n"));
1187 uint32_t max_entries
, max_size
;
1189 dcerpc_get_query_dispinfo_params(
1190 loop_count
, &max_entries
, &max_size
);
1192 status
= NetQueryDisplayInformation(c
->opt_host
,
1199 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
1203 info
= (struct NET_DISPLAY_USER
*)buffer
;
1205 for (i
= 0; i
< num_entries
; i
++) {
1207 if (c
->opt_long_list_entries
)
1208 printf("%-21.21s %s\n", info
->usri1_name
,
1209 info
->usri1_comment
);
1211 printf("%s\n", info
->usri1_name
);
1215 NetApiBufferFree(buffer
);
1218 start_idx
+= num_entries
;
1220 } while (status
== ERROR_MORE_DATA
);
1226 * 'net rpc user' entrypoint.
1227 * @param argc Standard main() style argc.
1228 * @param argv Standard main() style argv. Initial components are already
1232 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
1234 NET_API_STATUS status
;
1236 struct functable func
[] = {
1241 N_("Add specified user"),
1242 N_("net rpc user add\n"
1243 " Add specified user")
1249 N_("List domain groups of user"),
1250 N_("net rpc user info\n"
1251 " List domain groups of user")
1257 N_("Remove specified user"),
1258 N_("net rpc user delete\n"
1259 " Remove specified user")
1265 N_("Change user password"),
1266 N_("net rpc user password\n"
1267 " Change user password")
1273 N_("Rename specified user"),
1274 N_("net rpc user rename\n"
1275 " Rename specified user")
1279 rpc_user_setprimarygroup
,
1281 "Set a user's primary group",
1282 "net rpc user setprimarygroup\n"
1283 " Set a user's primary group"
1285 {NULL
, NULL
, 0, NULL
, NULL
}
1288 status
= libnetapi_net_init(&c
->netapi_ctx
);
1292 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
1293 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
1294 if (c
->opt_kerberos
) {
1295 libnetapi_set_use_kerberos(c
->netapi_ctx
);
1299 if (c
->display_usage
) {
1304 _("List all users"));
1305 net_display_usage_from_functable(func
);
1309 return rpc_user_list(c
, argc
, argv
);
1312 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
1315 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
1316 TALLOC_CTX
*mem_ctx
,
1317 struct rpc_sh_ctx
*ctx
,
1318 struct rpc_pipe_client
*pipe_hnd
,
1319 int argc
, const char **argv
)
1321 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
1324 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
1325 TALLOC_CTX
*mem_ctx
,
1326 struct rpc_sh_ctx
*ctx
,
1327 struct rpc_pipe_client
*pipe_hnd
,
1328 int argc
, const char **argv
)
1330 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1333 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1334 TALLOC_CTX
*mem_ctx
,
1335 struct rpc_sh_ctx
*ctx
,
1336 struct rpc_pipe_client
*pipe_hnd
,
1337 int argc
, const char **argv
,
1339 struct net_context
*c
,
1340 TALLOC_CTX
*mem_ctx
,
1341 struct rpc_sh_ctx
*ctx
,
1342 struct rpc_pipe_client
*pipe_hnd
,
1343 struct policy_handle
*user_hnd
,
1344 int argc
, const char **argv
))
1346 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1347 NTSTATUS status
, result
;
1350 enum lsa_SidType type
;
1351 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1354 d_fprintf(stderr
, "%s %s <username>\n", _("Usage:"),
1356 return NT_STATUS_INVALID_PARAMETER
;
1359 ZERO_STRUCT(connect_pol
);
1360 ZERO_STRUCT(domain_pol
);
1361 ZERO_STRUCT(user_pol
);
1363 status
= net_rpc_lookup_name(c
, mem_ctx
, ctx
->cli
,
1364 argv
[0], NULL
, NULL
, &sid
, &type
);
1365 if (!NT_STATUS_IS_OK(status
)) {
1366 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1371 if (type
!= SID_NAME_USER
) {
1372 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1373 sid_type_lookup(type
));
1374 status
= NT_STATUS_NO_SUCH_USER
;
1378 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1379 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1380 status
= NT_STATUS_NO_SUCH_USER
;
1384 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1386 MAXIMUM_ALLOWED_ACCESS
,
1389 if (!NT_STATUS_IS_OK(status
)) {
1392 if (!NT_STATUS_IS_OK(result
)) {
1397 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1399 MAXIMUM_ALLOWED_ACCESS
,
1403 if (!NT_STATUS_IS_OK(status
)) {
1406 if (!NT_STATUS_IS_OK(result
)) {
1411 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1413 MAXIMUM_ALLOWED_ACCESS
,
1417 if (!NT_STATUS_IS_OK(status
)) {
1420 if (!NT_STATUS_IS_OK(result
)) {
1425 status
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1428 if (is_valid_policy_hnd(&user_pol
)) {
1429 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1431 if (is_valid_policy_hnd(&domain_pol
)) {
1432 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1434 if (is_valid_policy_hnd(&connect_pol
)) {
1435 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1440 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1441 TALLOC_CTX
*mem_ctx
,
1442 struct rpc_sh_ctx
*ctx
,
1443 struct rpc_pipe_client
*pipe_hnd
,
1444 struct policy_handle
*user_hnd
,
1445 int argc
, const char **argv
)
1447 NTSTATUS status
, result
;
1448 union samr_UserInfo
*info
= NULL
;
1449 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1452 d_fprintf(stderr
, "%s %s show <username>\n", _("Usage:"),
1454 return NT_STATUS_INVALID_PARAMETER
;
1457 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1462 if (!NT_STATUS_IS_OK(status
)) {
1465 if (!NT_STATUS_IS_OK(result
)) {
1469 d_printf(_("user rid: %d, group rid: %d\n"),
1471 info
->info21
.primary_gid
);
1476 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1477 TALLOC_CTX
*mem_ctx
,
1478 struct rpc_sh_ctx
*ctx
,
1479 struct rpc_pipe_client
*pipe_hnd
,
1480 int argc
, const char **argv
)
1482 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1483 rpc_sh_user_show_internals
);
1486 #define FETCHSTR(name, rec) \
1487 do { if (strequal(ctx->thiscmd, name)) { \
1488 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1491 #define SETSTR(name, rec, flag) \
1492 do { if (strequal(ctx->thiscmd, name)) { \
1493 init_lsa_String(&(info->info21.rec), argv[0]); \
1494 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1497 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1498 TALLOC_CTX
*mem_ctx
,
1499 struct rpc_sh_ctx
*ctx
,
1500 struct rpc_pipe_client
*pipe_hnd
,
1501 struct policy_handle
*user_hnd
,
1502 int argc
, const char **argv
)
1504 NTSTATUS status
, result
;
1505 const char *username
;
1506 const char *oldval
= "";
1507 union samr_UserInfo
*info
= NULL
;
1508 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1511 d_fprintf(stderr
, "%s %s <username> [new value|NULL]\n",
1512 _("Usage:"), ctx
->whoami
);
1513 return NT_STATUS_INVALID_PARAMETER
;
1516 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1521 if (!NT_STATUS_IS_OK(status
)) {
1524 if (!NT_STATUS_IS_OK(result
)) {
1528 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1530 FETCHSTR("fullname", full_name
);
1531 FETCHSTR("homedir", home_directory
);
1532 FETCHSTR("homedrive", home_drive
);
1533 FETCHSTR("logonscript", logon_script
);
1534 FETCHSTR("profilepath", profile_path
);
1535 FETCHSTR("description", description
);
1538 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1542 if (strcmp(argv
[0], "NULL") == 0) {
1546 ZERO_STRUCT(info
->info21
);
1548 SETSTR("fullname", full_name
, FULL_NAME
);
1549 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1550 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1551 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1552 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1553 SETSTR("description", description
, DESCRIPTION
);
1555 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1560 if (!NT_STATUS_IS_OK(status
)) {
1566 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1567 ctx
->thiscmd
, oldval
, argv
[0]);
1574 #define HANDLEFLG(name, rec) \
1575 do { if (strequal(ctx->thiscmd, name)) { \
1576 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1578 newflags = oldflags | ACB_##rec; \
1580 newflags = oldflags & ~ACB_##rec; \
1583 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1584 TALLOC_CTX
*mem_ctx
,
1585 struct rpc_sh_ctx
*ctx
,
1586 struct rpc_pipe_client
*pipe_hnd
,
1587 int argc
, const char **argv
)
1589 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1590 rpc_sh_user_str_edit_internals
);
1593 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1594 TALLOC_CTX
*mem_ctx
,
1595 struct rpc_sh_ctx
*ctx
,
1596 struct rpc_pipe_client
*pipe_hnd
,
1597 struct policy_handle
*user_hnd
,
1598 int argc
, const char **argv
)
1600 NTSTATUS status
, result
;
1601 const char *username
;
1602 const char *oldval
= "unknown";
1603 uint32_t oldflags
, newflags
;
1605 union samr_UserInfo
*info
= NULL
;
1606 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1609 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1610 !strequal(argv
[0], "no"))) {
1611 /* TRANSATORS: The yes|no here are program keywords. Please do
1613 d_fprintf(stderr
, _("Usage: %s <username> [yes|no]\n"),
1615 return NT_STATUS_INVALID_PARAMETER
;
1618 newval
= strequal(argv
[0], "yes");
1620 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1625 if (!NT_STATUS_IS_OK(status
)) {
1628 if (!NT_STATUS_IS_OK(result
)) {
1632 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1633 oldflags
= info
->info21
.acct_flags
;
1634 newflags
= info
->info21
.acct_flags
;
1636 HANDLEFLG("disabled", DISABLED
);
1637 HANDLEFLG("pwnotreq", PWNOTREQ
);
1638 HANDLEFLG("autolock", AUTOLOCK
);
1639 HANDLEFLG("pwnoexp", PWNOEXP
);
1642 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1647 ZERO_STRUCT(info
->info21
);
1649 info
->info21
.acct_flags
= newflags
;
1650 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1652 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1657 if (!NT_STATUS_IS_OK(status
)) {
1661 if (NT_STATUS_IS_OK(result
)) {
1662 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1663 ctx
->thiscmd
, oldval
, argv
[0]);
1671 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1672 TALLOC_CTX
*mem_ctx
,
1673 struct rpc_sh_ctx
*ctx
,
1674 struct rpc_pipe_client
*pipe_hnd
,
1675 int argc
, const char **argv
)
1677 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1678 rpc_sh_user_flag_edit_internals
);
1681 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1682 TALLOC_CTX
*mem_ctx
,
1683 struct rpc_sh_ctx
*ctx
)
1685 static struct rpc_sh_cmd cmds
[] = {
1687 { "fullname", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1688 N_("Show/Set a user's full name") },
1690 { "homedir", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1691 N_("Show/Set a user's home directory") },
1693 { "homedrive", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1694 N_("Show/Set a user's home drive") },
1696 { "logonscript", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1697 N_("Show/Set a user's logon script") },
1699 { "profilepath", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1700 N_("Show/Set a user's profile path") },
1702 { "description", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1703 N_("Show/Set a user's description") },
1705 { "disabled", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1706 N_("Show/Set whether a user is disabled") },
1708 { "autolock", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1709 N_("Show/Set whether a user locked out") },
1711 { "pwnotreq", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1712 N_("Show/Set whether a user does not need a password") },
1714 { "pwnoexp", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1715 N_("Show/Set whether a user's password does not expire") },
1717 { NULL
, NULL
, 0, NULL
, NULL
}
1723 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1724 TALLOC_CTX
*mem_ctx
,
1725 struct rpc_sh_ctx
*ctx
)
1727 static struct rpc_sh_cmd cmds
[] = {
1729 { "list", NULL
, &ndr_table_samr
, rpc_sh_user_list
,
1730 N_("List available users") },
1732 { "info", NULL
, &ndr_table_samr
, rpc_sh_user_info
,
1733 N_("List the domain groups a user is member of") },
1735 { "show", NULL
, &ndr_table_samr
, rpc_sh_user_show
,
1736 N_("Show info about a user") },
1738 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1739 N_("Show/Modify a user's fields") },
1741 { NULL
, NULL
, 0, NULL
, NULL
}
1747 /****************************************************************************/
1750 * Basic usage function for 'net rpc group'.
1751 * @param argc Standard main() style argc.
1752 * @param argv Standard main() style argv. Initial components are already
1756 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1758 return net_group_usage(c
, argc
, argv
);
1762 * Delete group on a remote RPC server.
1764 * All parameters are provided by the run_rpc_command function, except for
1765 * argc, argv which are passed through.
1767 * @param domain_sid The domain sid acquired from the remote server.
1768 * @param cli A cli_state connected to the server.
1769 * @param mem_ctx Talloc context, destroyed on completion of the function.
1770 * @param argc Standard main() style argc.
1771 * @param argv Standard main() style argv. Initial components are already
1774 * @return Normal NTSTATUS return.
1777 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1778 const struct dom_sid
*domain_sid
,
1779 const char *domain_name
,
1780 struct cli_state
*cli
,
1781 struct rpc_pipe_client
*pipe_hnd
,
1782 TALLOC_CTX
*mem_ctx
,
1786 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1787 bool group_is_primary
= false;
1788 NTSTATUS status
, result
;
1790 struct samr_RidAttrArray
*rids
= NULL
;
1793 /* struct samr_RidWithAttribute *user_gids; */
1794 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1796 struct samr_Ids group_rids
, name_types
;
1797 struct lsa_String lsa_acct_name
;
1798 union samr_UserInfo
*info
= NULL
;
1800 if (argc
< 1 || c
->display_usage
) {
1801 rpc_group_usage(c
, argc
,argv
);
1802 return NT_STATUS_OK
; /* ok? */
1805 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1807 MAXIMUM_ALLOWED_ACCESS
,
1810 if (!NT_STATUS_IS_OK(status
)) {
1811 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1815 if (!NT_STATUS_IS_OK(result
)) {
1817 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1821 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1823 MAXIMUM_ALLOWED_ACCESS
,
1824 discard_const_p(struct dom_sid2
, domain_sid
),
1827 if (!NT_STATUS_IS_OK(status
)) {
1828 d_fprintf(stderr
, _("Request open_domain failed\n"));
1832 if (!NT_STATUS_IS_OK(result
)) {
1834 d_fprintf(stderr
, _("Request open_domain failed\n"));
1838 init_lsa_String(&lsa_acct_name
, argv
[0]);
1840 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1847 if (!NT_STATUS_IS_OK(status
)) {
1848 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1852 if (!NT_STATUS_IS_OK(result
)) {
1854 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1857 if (group_rids
.count
!= 1) {
1858 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1861 if (name_types
.count
!= 1) {
1862 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1866 switch (name_types
.ids
[0])
1868 case SID_NAME_DOM_GRP
:
1869 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
1871 MAXIMUM_ALLOWED_ACCESS
,
1875 if (!NT_STATUS_IS_OK(status
)) {
1876 d_fprintf(stderr
, _("Request open_group failed"));
1880 if (!NT_STATUS_IS_OK(result
)) {
1882 d_fprintf(stderr
, _("Request open_group failed"));
1886 group_rid
= group_rids
.ids
[0];
1888 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
1892 if (!NT_STATUS_IS_OK(status
)) {
1894 _("Unable to query group members of %s"),
1899 if (!NT_STATUS_IS_OK(result
)) {
1902 _("Unable to query group members of %s"),
1907 if (c
->opt_verbose
) {
1909 _("Domain Group %s (rid: %d) has %d members\n"),
1910 argv
[0],group_rid
, rids
->count
);
1913 /* Check if group is anyone's primary group */
1914 for (i
= 0; i
< rids
->count
; i
++)
1916 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1918 MAXIMUM_ALLOWED_ACCESS
,
1922 if (!NT_STATUS_IS_OK(status
)) {
1924 _("Unable to open group member %d\n"),
1929 if (!NT_STATUS_IS_OK(result
)) {
1932 _("Unable to open group member %d\n"),
1937 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1942 if (!NT_STATUS_IS_OK(status
)) {
1944 _("Unable to lookup userinfo for group "
1950 if (!NT_STATUS_IS_OK(result
)) {
1953 _("Unable to lookup userinfo for group "
1959 if (info
->info21
.primary_gid
== group_rid
) {
1960 if (c
->opt_verbose
) {
1961 d_printf(_("Group is primary group "
1963 info
->info21
.account_name
.string
);
1965 group_is_primary
= true;
1968 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1971 if (group_is_primary
) {
1972 d_fprintf(stderr
, _("Unable to delete group because "
1973 "some of it's members have it as primary "
1975 status
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1979 /* remove all group members */
1980 for (i
= 0; i
< rids
->count
; i
++)
1983 d_printf(_("Remove group member %d..."),
1985 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
1989 if (!NT_STATUS_IS_OK(status
)) {
1993 if (NT_STATUS_IS_OK(result
)) {
1995 d_printf(_("ok\n"));
1998 d_printf("%s\n", _("failed"));
2003 status
= dcerpc_samr_DeleteDomainGroup(b
, mem_ctx
,
2006 if (!NT_STATUS_IS_OK(status
)) {
2013 /* removing a local group is easier... */
2014 case SID_NAME_ALIAS
:
2015 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2017 MAXIMUM_ALLOWED_ACCESS
,
2021 if (!NT_STATUS_IS_OK(status
)) {
2022 d_fprintf(stderr
, _("Request open_alias failed\n"));
2025 if (!NT_STATUS_IS_OK(result
)) {
2027 d_fprintf(stderr
, _("Request open_alias failed\n"));
2031 status
= dcerpc_samr_DeleteDomAlias(b
, mem_ctx
,
2034 if (!NT_STATUS_IS_OK(status
)) {
2042 d_fprintf(stderr
, _("%s is of type %s. This command is only "
2043 "for deleting local or global groups\n"),
2044 argv
[0],sid_type_lookup(name_types
.ids
[0]));
2045 status
= NT_STATUS_UNSUCCESSFUL
;
2049 if (NT_STATUS_IS_OK(status
)) {
2051 d_printf(_("Deleted %s '%s'\n"),
2052 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
2054 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
2055 get_friendly_nt_error_msg(status
));
2063 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
2065 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2066 rpc_group_delete_internals
, argc
,argv
);
2069 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2071 NET_API_STATUS status
;
2072 struct GROUP_INFO_1 info1
;
2073 uint32_t parm_error
= 0;
2075 if (argc
!= 1 || c
->display_usage
) {
2076 rpc_group_usage(c
, argc
, argv
);
2082 info1
.grpi1_name
= argv
[0];
2083 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2084 info1
.grpi1_comment
= c
->opt_comment
;
2087 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2091 _("Failed to add group '%s' with error: %s.\n"),
2092 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2096 d_printf(_("Added group '%s'.\n"), argv
[0]);
2102 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2104 NET_API_STATUS status
;
2105 struct LOCALGROUP_INFO_1 info1
;
2106 uint32_t parm_error
= 0;
2108 if (argc
!= 1 || c
->display_usage
) {
2109 rpc_group_usage(c
, argc
, argv
);
2115 info1
.lgrpi1_name
= argv
[0];
2116 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2117 info1
.lgrpi1_comment
= c
->opt_comment
;
2120 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2124 _("Failed to add alias '%s' with error: %s.\n"),
2125 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2129 d_printf(_("Added alias '%s'.\n"), argv
[0]);
2135 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
2137 if (c
->opt_localgroup
)
2138 return rpc_alias_add_internals(c
, argc
, argv
);
2140 return rpc_group_add_internals(c
, argc
, argv
);
2143 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
2144 TALLOC_CTX
*mem_ctx
,
2146 struct dom_sid
*sid
,
2147 enum lsa_SidType
*type
)
2149 struct dom_sid
*sids
= NULL
;
2150 enum lsa_SidType
*types
= NULL
;
2151 struct rpc_pipe_client
*pipe_hnd
= NULL
;
2152 struct policy_handle lsa_pol
;
2153 NTSTATUS status
, result
;
2154 struct dcerpc_binding_handle
*b
;
2156 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
2158 if (!NT_STATUS_IS_OK(status
)) {
2162 b
= pipe_hnd
->binding_handle
;
2164 status
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
2165 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2167 if (!NT_STATUS_IS_OK(status
)) {
2171 status
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
2172 &name
, NULL
, 1, &sids
, &types
);
2174 if (NT_STATUS_IS_OK(status
)) {
2175 sid_copy(sid
, &sids
[0]);
2179 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
2183 TALLOC_FREE(pipe_hnd
);
2186 if (!NT_STATUS_IS_OK(status
) && (strncasecmp_m(name
, "S-", 2) == 0)) {
2188 /* Try as S-1-5-whatever */
2190 struct dom_sid tmp_sid
;
2192 if (string_to_sid(&tmp_sid
, name
)) {
2193 sid_copy(sid
, &tmp_sid
);
2194 *type
= SID_NAME_UNKNOWN
;
2195 status
= NT_STATUS_OK
;
2202 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2203 TALLOC_CTX
*mem_ctx
,
2204 const struct dom_sid
*group_sid
,
2207 struct policy_handle connect_pol
, domain_pol
;
2208 NTSTATUS status
, result
;
2210 struct policy_handle group_pol
;
2211 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2213 struct samr_Ids rids
, rid_types
;
2214 struct lsa_String lsa_acct_name
;
2218 sid_copy(&sid
, group_sid
);
2220 if (!sid_split_rid(&sid
, &group_rid
)) {
2221 return NT_STATUS_UNSUCCESSFUL
;
2224 /* Get sam policy handle */
2225 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2227 MAXIMUM_ALLOWED_ACCESS
,
2230 if (!NT_STATUS_IS_OK(status
)) {
2233 if (!NT_STATUS_IS_OK(result
)) {
2237 /* Get domain policy handle */
2238 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2240 MAXIMUM_ALLOWED_ACCESS
,
2244 if (!NT_STATUS_IS_OK(status
)) {
2247 if (!NT_STATUS_IS_OK(result
)) {
2251 init_lsa_String(&lsa_acct_name
, member
);
2253 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2260 if (!NT_STATUS_IS_OK(status
)) {
2261 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2266 if (!NT_STATUS_IS_OK(result
)) {
2268 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2272 if (rids
.count
!= 1) {
2273 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2276 if (rid_types
.count
!= 1) {
2277 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2281 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2283 MAXIMUM_ALLOWED_ACCESS
,
2287 if (!NT_STATUS_IS_OK(status
)) {
2291 if (!NT_STATUS_IS_OK(result
)) {
2296 status
= dcerpc_samr_AddGroupMember(b
, mem_ctx
,
2299 0x0005, /* unknown flags */
2301 if (!NT_STATUS_IS_OK(status
)) {
2308 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2312 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2313 struct cli_state
*cli
,
2314 TALLOC_CTX
*mem_ctx
,
2315 const struct dom_sid
*alias_sid
,
2318 struct policy_handle connect_pol
, domain_pol
;
2319 NTSTATUS status
, result
;
2321 struct policy_handle alias_pol
;
2322 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2324 struct dom_sid member_sid
;
2325 enum lsa_SidType member_type
;
2329 sid_copy(&sid
, alias_sid
);
2331 if (!sid_split_rid(&sid
, &alias_rid
)) {
2332 return NT_STATUS_UNSUCCESSFUL
;
2335 result
= get_sid_from_name(cli
, mem_ctx
,
2336 member
, &member_sid
, &member_type
);
2338 if (!NT_STATUS_IS_OK(result
)) {
2339 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2344 /* Get sam policy handle */
2345 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2347 MAXIMUM_ALLOWED_ACCESS
,
2350 if (!NT_STATUS_IS_OK(status
)) {
2353 if (!NT_STATUS_IS_OK(result
)) {
2358 /* Get domain policy handle */
2359 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2361 MAXIMUM_ALLOWED_ACCESS
,
2365 if (!NT_STATUS_IS_OK(status
)) {
2368 if (!NT_STATUS_IS_OK(result
)) {
2373 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2375 MAXIMUM_ALLOWED_ACCESS
,
2379 if (!NT_STATUS_IS_OK(status
)) {
2382 if (!NT_STATUS_IS_OK(result
)) {
2386 status
= dcerpc_samr_AddAliasMember(b
, mem_ctx
,
2390 if (!NT_STATUS_IS_OK(status
)) {
2397 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2401 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
2402 const struct dom_sid
*domain_sid
,
2403 const char *domain_name
,
2404 struct cli_state
*cli
,
2405 struct rpc_pipe_client
*pipe_hnd
,
2406 TALLOC_CTX
*mem_ctx
,
2410 struct dom_sid group_sid
;
2411 enum lsa_SidType group_type
;
2413 if (argc
!= 2 || c
->display_usage
) {
2416 _("net rpc group addmem <group> <member>\n"
2417 " Add a member to a group\n"
2418 " group\tGroup to add member to\n"
2419 " member\tMember to add to group\n"));
2420 return NT_STATUS_UNSUCCESSFUL
;
2423 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2424 &group_sid
, &group_type
))) {
2425 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2427 return NT_STATUS_UNSUCCESSFUL
;
2430 if (group_type
== SID_NAME_DOM_GRP
) {
2431 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2432 &group_sid
, argv
[1]);
2434 if (!NT_STATUS_IS_OK(result
)) {
2435 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2436 argv
[1], argv
[0], nt_errstr(result
));
2441 if (group_type
== SID_NAME_ALIAS
) {
2442 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2443 &group_sid
, argv
[1]);
2445 if (!NT_STATUS_IS_OK(result
)) {
2446 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2447 argv
[1], argv
[0], nt_errstr(result
));
2452 d_fprintf(stderr
, _("Can only add members to global or local groups "
2453 "which %s is not\n"), argv
[0]);
2455 return NT_STATUS_UNSUCCESSFUL
;
2458 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
2460 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2461 rpc_group_addmem_internals
,
2465 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
2466 struct rpc_pipe_client
*pipe_hnd
,
2467 TALLOC_CTX
*mem_ctx
,
2468 const struct dom_sid
*group_sid
,
2471 struct policy_handle connect_pol
, domain_pol
;
2472 NTSTATUS status
, result
;
2474 struct policy_handle group_pol
;
2475 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2477 struct samr_Ids rids
, rid_types
;
2478 struct lsa_String lsa_acct_name
;
2482 sid_copy(&sid
, group_sid
);
2484 if (!sid_split_rid(&sid
, &group_rid
))
2485 return NT_STATUS_UNSUCCESSFUL
;
2487 /* Get sam policy handle */
2488 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2490 MAXIMUM_ALLOWED_ACCESS
,
2493 if (!NT_STATUS_IS_OK(status
)) {
2496 if (!NT_STATUS_IS_OK(result
)) {
2501 /* Get domain policy handle */
2502 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2504 MAXIMUM_ALLOWED_ACCESS
,
2508 if (!NT_STATUS_IS_OK(status
)) {
2511 if (!NT_STATUS_IS_OK(result
)) {
2515 init_lsa_String(&lsa_acct_name
, member
);
2517 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2524 if (!NT_STATUS_IS_OK(status
)) {
2525 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2530 if (!NT_STATUS_IS_OK(result
)) {
2532 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2536 if (rids
.count
!= 1) {
2537 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2540 if (rid_types
.count
!= 1) {
2541 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2545 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2547 MAXIMUM_ALLOWED_ACCESS
,
2551 if (!NT_STATUS_IS_OK(status
)) {
2554 if (!NT_STATUS_IS_OK(result
)) {
2559 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
2563 if (!NT_STATUS_IS_OK(status
)) {
2569 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2573 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2574 struct cli_state
*cli
,
2575 TALLOC_CTX
*mem_ctx
,
2576 const struct dom_sid
*alias_sid
,
2579 struct policy_handle connect_pol
, domain_pol
;
2580 NTSTATUS status
, result
;
2582 struct policy_handle alias_pol
;
2583 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2585 struct dom_sid member_sid
;
2586 enum lsa_SidType member_type
;
2590 sid_copy(&sid
, alias_sid
);
2592 if (!sid_split_rid(&sid
, &alias_rid
))
2593 return NT_STATUS_UNSUCCESSFUL
;
2595 result
= get_sid_from_name(cli
, mem_ctx
,
2596 member
, &member_sid
, &member_type
);
2598 if (!NT_STATUS_IS_OK(result
)) {
2599 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2604 /* Get sam policy handle */
2605 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2607 MAXIMUM_ALLOWED_ACCESS
,
2610 if (!NT_STATUS_IS_OK(status
)) {
2613 if (!NT_STATUS_IS_OK(result
)) {
2618 /* Get domain policy handle */
2619 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2621 MAXIMUM_ALLOWED_ACCESS
,
2625 if (!NT_STATUS_IS_OK(status
)) {
2628 if (!NT_STATUS_IS_OK(result
)) {
2633 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2635 MAXIMUM_ALLOWED_ACCESS
,
2639 if (!NT_STATUS_IS_OK(status
)) {
2643 if (!NT_STATUS_IS_OK(result
)) {
2647 status
= dcerpc_samr_DeleteAliasMember(b
, mem_ctx
,
2652 if (!NT_STATUS_IS_OK(status
)) {
2659 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2663 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2664 const struct dom_sid
*domain_sid
,
2665 const char *domain_name
,
2666 struct cli_state
*cli
,
2667 struct rpc_pipe_client
*pipe_hnd
,
2668 TALLOC_CTX
*mem_ctx
,
2672 struct dom_sid group_sid
;
2673 enum lsa_SidType group_type
;
2675 if (argc
!= 2 || c
->display_usage
) {
2678 _("net rpc group delmem <group> <member>\n"
2679 " Delete a member from a group\n"
2680 " group\tGroup to delete member from\n"
2681 " member\tMember to delete from group\n"));
2682 return NT_STATUS_UNSUCCESSFUL
;
2685 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2686 &group_sid
, &group_type
))) {
2687 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2689 return NT_STATUS_UNSUCCESSFUL
;
2692 if (group_type
== SID_NAME_DOM_GRP
) {
2693 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2694 &group_sid
, argv
[1]);
2696 if (!NT_STATUS_IS_OK(result
)) {
2697 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2698 argv
[1], argv
[0], nt_errstr(result
));
2703 if (group_type
== SID_NAME_ALIAS
) {
2704 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2705 &group_sid
, argv
[1]);
2707 if (!NT_STATUS_IS_OK(result
)) {
2708 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2709 argv
[1], argv
[0], nt_errstr(result
));
2714 d_fprintf(stderr
, _("Can only delete members from global or local "
2715 "groups which %s is not\n"), argv
[0]);
2717 return NT_STATUS_UNSUCCESSFUL
;
2720 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2722 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2723 rpc_group_delmem_internals
,
2728 * List groups on a remote RPC server.
2730 * All parameters are provided by the run_rpc_command function, except for
2731 * argc, argv which are passes through.
2733 * @param domain_sid The domain sid acquired from the remote server.
2734 * @param cli A cli_state connected to the server.
2735 * @param mem_ctx Talloc context, destroyed on completion of the function.
2736 * @param argc Standard main() style argc.
2737 * @param argv Standard main() style argv. Initial components are already
2740 * @return Normal NTSTATUS return.
2743 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2744 const struct dom_sid
*domain_sid
,
2745 const char *domain_name
,
2746 struct cli_state
*cli
,
2747 struct rpc_pipe_client
*pipe_hnd
,
2748 TALLOC_CTX
*mem_ctx
,
2752 struct policy_handle connect_pol
, domain_pol
;
2753 NTSTATUS status
, result
;
2754 uint32_t start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2755 struct samr_SamArray
*groups
= NULL
;
2756 bool global
= false;
2758 bool builtin
= false;
2759 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2761 if (c
->display_usage
) {
2764 _("net rpc group list [global] [local] [builtin]\n"
2765 " List groups on RPC server\n"
2766 " global\tList global groups\n"
2767 " local\tList local groups\n"
2768 " builtin\tList builtin groups\n"
2769 " If none of global, local or builtin is "
2770 "specified, all three options are considered "
2772 return NT_STATUS_OK
;
2781 for (i
=0; i
<argc
; i
++) {
2782 if (strequal(argv
[i
], "global"))
2785 if (strequal(argv
[i
], "local"))
2788 if (strequal(argv
[i
], "builtin"))
2792 /* Get sam policy handle */
2794 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2796 MAXIMUM_ALLOWED_ACCESS
,
2799 if (!NT_STATUS_IS_OK(status
)) {
2802 if (!NT_STATUS_IS_OK(result
)) {
2807 /* Get domain policy handle */
2809 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2811 MAXIMUM_ALLOWED_ACCESS
,
2812 discard_const_p(struct dom_sid2
, domain_sid
),
2815 if (!NT_STATUS_IS_OK(status
)) {
2818 if (!NT_STATUS_IS_OK(result
)) {
2823 /* Query domain groups */
2824 if (c
->opt_long_list_entries
)
2825 d_printf(_("\nGroup name Comment"
2826 "\n-----------------------------\n"));
2828 uint32_t max_size
, total_size
, returned_size
;
2829 union samr_DispInfo info
;
2833 dcerpc_get_query_dispinfo_params(
2834 loop_count
, &max_entries
, &max_size
);
2836 status
= dcerpc_samr_QueryDisplayInfo(b
, mem_ctx
,
2846 if (!NT_STATUS_IS_OK(status
)) {
2849 num_entries
= info
.info3
.count
;
2850 start_idx
+= info
.info3
.count
;
2852 if (!NT_STATUS_IS_OK(result
) &&
2853 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2856 for (i
= 0; i
< num_entries
; i
++) {
2858 const char *group
= NULL
;
2859 const char *desc
= NULL
;
2861 group
= info
.info3
.entries
[i
].account_name
.string
;
2862 desc
= info
.info3
.entries
[i
].description
.string
;
2864 if (c
->opt_long_list_entries
)
2865 printf("%-21.21s %-50.50s\n",
2868 printf("%s\n", group
);
2870 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2871 /* query domain aliases */
2876 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2883 if (!NT_STATUS_IS_OK(status
)) {
2886 if (!NT_STATUS_IS_OK(result
) &&
2887 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2890 for (i
= 0; i
< num_entries
; i
++) {
2892 const char *description
= NULL
;
2894 if (c
->opt_long_list_entries
) {
2896 struct policy_handle alias_pol
;
2897 union samr_AliasInfo
*info
= NULL
;
2900 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2903 groups
->entries
[i
].idx
,
2906 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2907 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
2912 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2913 status
= dcerpc_samr_Close(b
, mem_ctx
,
2916 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2917 description
= info
->description
.string
;
2923 if (description
!= NULL
) {
2924 printf("%-21.21s %-50.50s\n",
2925 groups
->entries
[i
].name
.string
,
2928 printf("%s\n", groups
->entries
[i
].name
.string
);
2931 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2932 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2933 /* Get builtin policy handle */
2935 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2937 MAXIMUM_ALLOWED_ACCESS
,
2938 discard_const_p(struct dom_sid2
, &global_sid_Builtin
),
2941 if (!NT_STATUS_IS_OK(status
)) {
2944 if (!NT_STATUS_IS_OK(result
)) {
2949 /* query builtin aliases */
2952 if (!builtin
) break;
2954 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2961 if (!NT_STATUS_IS_OK(status
)) {
2964 if (!NT_STATUS_IS_OK(result
) &&
2965 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
2970 for (i
= 0; i
< num_entries
; i
++) {
2972 const char *description
= NULL
;
2974 if (c
->opt_long_list_entries
) {
2976 struct policy_handle alias_pol
;
2977 union samr_AliasInfo
*info
= NULL
;
2980 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2983 groups
->entries
[i
].idx
,
2986 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2987 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
2992 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2993 status
= dcerpc_samr_Close(b
, mem_ctx
,
2996 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2997 description
= info
->description
.string
;
3003 if (description
!= NULL
) {
3004 printf("%-21.21s %-50.50s\n",
3005 groups
->entries
[i
].name
.string
,
3008 printf("%s\n", groups
->entries
[i
].name
.string
);
3011 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3019 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
3021 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3022 rpc_group_list_internals
,
3026 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
3027 struct rpc_pipe_client
*pipe_hnd
,
3028 TALLOC_CTX
*mem_ctx
,
3029 const char *domain_name
,
3030 const struct dom_sid
*domain_sid
,
3031 struct policy_handle
*domain_pol
,
3034 NTSTATUS result
, status
;
3035 struct policy_handle group_pol
;
3036 uint32_t num_members
, *group_rids
;
3038 struct samr_RidAttrArray
*rids
= NULL
;
3039 struct lsa_Strings names
;
3040 struct samr_Ids types
;
3041 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3044 sid_to_fstring(sid_str
, domain_sid
);
3046 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
3048 MAXIMUM_ALLOWED_ACCESS
,
3052 if (!NT_STATUS_IS_OK(status
)) {
3055 if (!NT_STATUS_IS_OK(result
)) {
3059 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
3063 if (!NT_STATUS_IS_OK(status
)) {
3066 if (!NT_STATUS_IS_OK(result
)) {
3070 num_members
= rids
->count
;
3071 group_rids
= rids
->rids
;
3073 while (num_members
> 0) {
3074 int this_time
= 512;
3076 if (num_members
< this_time
)
3077 this_time
= num_members
;
3079 status
= dcerpc_samr_LookupRids(b
, mem_ctx
,
3086 if (!NT_STATUS_IS_OK(status
)) {
3089 if (!NT_STATUS_IS_OK(result
)) {
3092 if (names
.count
!= this_time
) {
3093 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3095 if (types
.count
!= this_time
) {
3096 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3098 /* We only have users as members, but make the output
3099 the same as the output of alias members */
3101 for (i
= 0; i
< this_time
; i
++) {
3103 if (c
->opt_long_list_entries
) {
3104 printf("%s-%d %s\\%s %d\n", sid_str
,
3105 group_rids
[i
], domain_name
,
3106 names
.names
[i
].string
,
3109 printf("%s\\%s\n", domain_name
,
3110 names
.names
[i
].string
);
3114 num_members
-= this_time
;
3118 return NT_STATUS_OK
;
3121 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
3122 struct rpc_pipe_client
*pipe_hnd
,
3123 struct cli_state
*cli
,
3124 TALLOC_CTX
*mem_ctx
,
3125 struct policy_handle
*domain_pol
,
3128 NTSTATUS result
, status
;
3129 struct rpc_pipe_client
*lsa_pipe
;
3130 struct policy_handle alias_pol
, lsa_pol
;
3131 uint32_t num_members
;
3132 struct dom_sid
*alias_sids
;
3135 enum lsa_SidType
*types
;
3137 struct lsa_SidArray sid_array
;
3138 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3140 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
3142 MAXIMUM_ALLOWED_ACCESS
,
3146 if (!NT_STATUS_IS_OK(status
)) {
3149 if (!NT_STATUS_IS_OK(result
)) {
3153 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
3157 if (!NT_STATUS_IS_OK(status
)) {
3158 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3161 if (!NT_STATUS_IS_OK(result
)) {
3162 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3166 num_members
= sid_array
.num_sids
;
3168 if (num_members
== 0) {
3169 return NT_STATUS_OK
;
3172 result
= cli_rpc_pipe_open_noauth(cli
,
3175 if (!NT_STATUS_IS_OK(result
)) {
3176 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
3177 nt_errstr(result
) );
3181 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
3182 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
3184 if (!NT_STATUS_IS_OK(result
)) {
3185 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
3186 TALLOC_FREE(lsa_pipe
);
3190 alias_sids
= talloc_zero_array(mem_ctx
, struct dom_sid
, num_members
);
3192 d_fprintf(stderr
, _("Out of memory\n"));
3193 TALLOC_FREE(lsa_pipe
);
3194 return NT_STATUS_NO_MEMORY
;
3197 for (i
=0; i
<num_members
; i
++) {
3198 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
3201 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
3202 num_members
, alias_sids
,
3203 &domains
, &names
, &types
);
3205 if (!NT_STATUS_IS_OK(result
) &&
3206 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
3207 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
3208 TALLOC_FREE(lsa_pipe
);
3212 for (i
= 0; i
< num_members
; i
++) {
3214 sid_to_fstring(sid_str
, &alias_sids
[i
]);
3216 if (c
->opt_long_list_entries
) {
3217 printf("%s %s\\%s %d\n", sid_str
,
3218 domains
[i
] ? domains
[i
] : _("*unknown*"),
3219 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
3222 printf("%s\\%s\n", domains
[i
], names
[i
]);
3224 printf("%s\n", sid_str
);
3228 TALLOC_FREE(lsa_pipe
);
3229 return NT_STATUS_OK
;
3232 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
3233 const struct dom_sid
*domain_sid
,
3234 const char *domain_name
,
3235 struct cli_state
*cli
,
3236 struct rpc_pipe_client
*pipe_hnd
,
3237 TALLOC_CTX
*mem_ctx
,
3241 NTSTATUS result
, status
;
3242 struct policy_handle connect_pol
, domain_pol
;
3243 struct samr_Ids rids
, rid_types
;
3244 struct lsa_String lsa_acct_name
;
3245 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3247 /* Get sam policy handle */
3249 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
3251 MAXIMUM_ALLOWED_ACCESS
,
3254 if (!NT_STATUS_IS_OK(status
)) {
3257 if (!NT_STATUS_IS_OK(result
)) {
3261 /* Get domain policy handle */
3263 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3265 MAXIMUM_ALLOWED_ACCESS
,
3266 discard_const_p(struct dom_sid2
, domain_sid
),
3269 if (!NT_STATUS_IS_OK(status
)) {
3272 if (!NT_STATUS_IS_OK(result
)) {
3276 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
3278 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3285 if (!NT_STATUS_IS_OK(status
)) {
3289 if (!NT_STATUS_IS_OK(result
)) {
3291 /* Ok, did not find it in the global sam, try with builtin */
3293 struct dom_sid sid_Builtin
;
3295 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
3297 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
3299 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3301 MAXIMUM_ALLOWED_ACCESS
,
3305 if (!NT_STATUS_IS_OK(status
)) {
3308 if (!NT_STATUS_IS_OK(result
)) {
3309 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3314 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3321 if (!NT_STATUS_IS_OK(status
)) {
3324 if (!NT_STATUS_IS_OK(result
)) {
3325 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3331 if (rids
.count
!= 1) {
3332 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3334 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3336 if (rid_types
.count
!= 1) {
3337 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3339 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3343 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
3344 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
3345 domain_sid
, &domain_pol
,
3349 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
3350 return rpc_list_alias_members(c
, pipe_hnd
, cli
, mem_ctx
, &domain_pol
,
3354 return NT_STATUS_NO_SUCH_GROUP
;
3357 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
3359 if (argc
!= 1 || c
->display_usage
) {
3360 return rpc_group_usage(c
, argc
, argv
);
3363 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3364 rpc_group_members_internals
,
3368 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
3370 NET_API_STATUS status
;
3371 struct GROUP_INFO_0 g0
;
3375 d_printf(_("Usage:\n"));
3376 d_printf("net rpc group rename group newname\n");
3380 g0
.grpi0_name
= argv
[1];
3382 status
= NetGroupSetInfo(c
->opt_host
,
3389 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
3390 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
3398 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
3400 if (argc
!= 2 || c
->display_usage
) {
3401 return rpc_group_usage(c
, argc
, argv
);
3404 return rpc_group_rename_internals(c
, argc
, argv
);
3408 * 'net rpc group' entrypoint.
3409 * @param argc Standard main() style argc.
3410 * @param argv Standard main() style argv. Initial components are already
3414 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
3416 NET_API_STATUS status
;
3418 struct functable func
[] = {
3423 N_("Create specified group"),
3424 N_("net rpc group add\n"
3425 " Create specified group")
3431 N_("Delete specified group"),
3432 N_("net rpc group delete\n"
3433 " Delete specified group")
3439 N_("Add member to group"),
3440 N_("net rpc group addmem\n"
3441 " Add member to group")
3447 N_("Remove member from group"),
3448 N_("net rpc group delmem\n"
3449 " Remove member from group")
3456 N_("net rpc group list\n"
3463 N_("List group members"),
3464 N_("net rpc group members\n"
3465 " List group members")
3472 N_("net rpc group rename\n"
3475 {NULL
, NULL
, 0, NULL
, NULL
}
3478 status
= libnetapi_net_init(&c
->netapi_ctx
);
3482 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
3483 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
3484 if (c
->opt_kerberos
) {
3485 libnetapi_set_use_kerberos(c
->netapi_ctx
);
3489 if (c
->display_usage
) {
3490 d_printf(_("Usage:\n"));
3491 d_printf(_("net rpc group\n"
3492 " Alias for net rpc group list global "
3493 "local builtin\n"));
3494 net_display_usage_from_functable(func
);
3498 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3499 rpc_group_list_internals
,
3503 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
3506 /****************************************************************************/
3508 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
3510 return net_share_usage(c
, argc
, argv
);
3514 * Add a share on a remote RPC server.
3516 * @param argc Standard main() style argc.
3517 * @param argv Standard main() style argv. Initial components are already
3520 * @return A shell status integer (0 for success).
3523 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
3525 NET_API_STATUS status
;
3528 uint32_t type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3529 uint32_t num_users
=0, perms
=0;
3530 char *password
=NULL
; /* don't allow a share password */
3531 struct SHARE_INFO_2 i2
;
3532 uint32_t parm_error
= 0;
3534 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
3535 return rpc_share_usage(c
, argc
, argv
);
3538 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
3542 path
= strchr(sharename
, '=');
3549 i2
.shi2_netname
= sharename
;
3550 i2
.shi2_type
= type
;
3551 i2
.shi2_remark
= c
->opt_comment
;
3552 i2
.shi2_permissions
= perms
;
3553 i2
.shi2_max_uses
= c
->opt_maxusers
;
3554 i2
.shi2_current_uses
= num_users
;
3555 i2
.shi2_path
= path
;
3556 i2
.shi2_passwd
= password
;
3558 status
= NetShareAdd(c
->opt_host
,
3563 printf(_("NetShareAdd failed with: %s\n"),
3564 libnetapi_get_error_string(c
->netapi_ctx
, status
));
3571 * Delete a share on a remote RPC server.
3573 * @param domain_sid The domain sid acquired from the remote server.
3574 * @param argc Standard main() style argc.
3575 * @param argv Standard main() style argv. Initial components are already
3578 * @return A shell status integer (0 for success).
3580 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
3582 if (argc
< 1 || c
->display_usage
) {
3583 return rpc_share_usage(c
, argc
, argv
);
3586 return NetShareDel(c
->opt_host
, argv
[0], 0);
3590 * Formatted print of share info
3592 * @param r pointer to SHARE_INFO_1 to format
3595 static void display_share_info_1(struct net_context
*c
,
3596 struct SHARE_INFO_1
*r
)
3598 if (c
->opt_long_list_entries
) {
3599 d_printf("%-12s %-8.8s %-50s\n",
3601 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
3604 d_printf("%s\n", r
->shi1_netname
);
3608 static WERROR
get_share_info(struct net_context
*c
,
3609 struct rpc_pipe_client
*pipe_hnd
,
3610 TALLOC_CTX
*mem_ctx
,
3614 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3618 union srvsvc_NetShareInfo info
;
3619 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3621 /* no specific share requested, enumerate all */
3624 uint32_t preferred_len
= 0xffffffff;
3625 uint32_t total_entries
= 0;
3626 uint32_t resume_handle
= 0;
3628 info_ctr
->level
= level
;
3630 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
3637 if (!NT_STATUS_IS_OK(status
)) {
3638 return ntstatus_to_werror(status
);
3643 /* request just one share */
3644 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
3651 if (!NT_STATUS_IS_OK(status
)) {
3652 result
= ntstatus_to_werror(status
);
3656 if (!W_ERROR_IS_OK(result
)) {
3661 ZERO_STRUCTP(info_ctr
);
3663 info_ctr
->level
= level
;
3668 struct srvsvc_NetShareCtr1
*ctr1
;
3670 ctr1
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr1
);
3671 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3674 ctr1
->array
= info
.info1
;
3676 info_ctr
->ctr
.ctr1
= ctr1
;
3682 struct srvsvc_NetShareCtr2
*ctr2
;
3684 ctr2
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr2
);
3685 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3688 ctr2
->array
= info
.info2
;
3690 info_ctr
->ctr
.ctr2
= ctr2
;
3696 struct srvsvc_NetShareCtr502
*ctr502
;
3698 ctr502
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr502
);
3699 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3702 ctr502
->array
= info
.info502
;
3704 info_ctr
->ctr
.ctr502
= ctr502
;
3714 * 'net rpc share list' entrypoint.
3715 * @param argc Standard main() style argc.
3716 * @param argv Standard main() style argv. Initial components are already
3719 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3721 NET_API_STATUS status
;
3722 struct SHARE_INFO_1
*i1
= NULL
;
3723 uint32_t entries_read
= 0;
3724 uint32_t total_entries
= 0;
3725 uint32_t resume_handle
= 0;
3726 uint32_t i
, level
= 1;
3728 if (c
->display_usage
) {
3730 "net rpc share list\n"
3733 _("List shares on remote server"));
3737 status
= NetShareEnum(c
->opt_host
,
3739 (uint8_t **)(void *)&i1
,
3748 /* Display results */
3750 if (c
->opt_long_list_entries
) {
3752 "\nEnumerating shared resources (exports) on remote server:\n\n"
3753 "\nShare name Type Description\n"
3754 "---------- ---- -----------\n"));
3756 for (i
= 0; i
< entries_read
; i
++)
3757 display_share_info_1(c
, &i1
[i
]);
3762 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3766 status
= cli_tree_connect(cli
, netname
, "A:", NULL
);
3767 if (!NT_STATUS_IS_OK(status
)) {
3768 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3772 status
= cli_tdis(cli
);
3773 if (!NT_STATUS_IS_OK(status
)) {
3774 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status
));
3781 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3782 const char *netname
, uint32_t type
)
3784 /* only support disk shares */
3785 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3786 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3791 /* skip builtin shares */
3792 /* FIXME: should print$ be added too ? */
3793 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3794 strequal(netname
,"global"))
3797 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3798 printf(_("excluding [%s]\n"), netname
);
3802 return check_share_availability(cli
, netname
);
3806 * Migrate shares from a remote RPC server to the local RPC server.
3808 * All parameters are provided by the run_rpc_command function, except for
3809 * argc, argv which are passed through.
3811 * @param domain_sid The domain sid acquired from the remote server.
3812 * @param cli A cli_state connected to the server.
3813 * @param mem_ctx Talloc context, destroyed on completion of the function.
3814 * @param argc Standard main() style argc.
3815 * @param argv Standard main() style argv. Initial components are already
3818 * @return Normal NTSTATUS return.
3821 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3822 const struct dom_sid
*domain_sid
,
3823 const char *domain_name
,
3824 struct cli_state
*cli
,
3825 struct rpc_pipe_client
*pipe_hnd
,
3826 TALLOC_CTX
*mem_ctx
,
3831 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3832 struct srvsvc_NetShareInfoCtr ctr_src
;
3834 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3835 struct cli_state
*cli_dst
= NULL
;
3836 uint32_t level
= 502; /* includes secdesc */
3837 uint32_t parm_error
= 0;
3838 struct dcerpc_binding_handle
*b
;
3840 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3842 if (!W_ERROR_IS_OK(result
))
3845 /* connect destination PI_SRVSVC */
3846 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3848 if (!NT_STATUS_IS_OK(nt_status
))
3851 b
= srvsvc_pipe
->binding_handle
;
3853 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3855 union srvsvc_NetShareInfo info
;
3856 struct srvsvc_NetShareInfo502 info502
=
3857 ctr_src
.ctr
.ctr502
->array
[i
];
3859 /* reset error-code */
3860 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3862 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3865 /* finally add the share on the dst server */
3867 printf(_("migrating: [%s], path: %s, comment: %s, without "
3869 info502
.name
, info502
.path
, info502
.comment
);
3871 info
.info502
= &info502
;
3873 nt_status
= dcerpc_srvsvc_NetShareAdd(b
, mem_ctx
,
3874 srvsvc_pipe
->desthost
,
3879 if (!NT_STATUS_IS_OK(nt_status
)) {
3880 printf(_("cannot add share: %s\n"),
3881 nt_errstr(nt_status
));
3884 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3885 printf(_(" [%s] does already exist\n"),
3890 if (!W_ERROR_IS_OK(result
)) {
3891 nt_status
= werror_to_ntstatus(result
);
3892 printf(_("cannot add share: %s\n"),
3893 win_errstr(result
));
3899 nt_status
= NT_STATUS_OK
;
3903 cli_shutdown(cli_dst
);
3911 * Migrate shares from a RPC server to another.
3913 * @param argc Standard main() style argc.
3914 * @param argv Standard main() style argv. Initial components are already
3917 * @return A shell status integer (0 for success).
3919 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3922 if (c
->display_usage
) {
3924 "net rpc share migrate shares\n"
3927 _("Migrate shares to local server"));
3932 printf(_("no server to migrate\n"));
3936 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
3937 rpc_share_migrate_shares_internals
,
3944 * @param f file_info
3945 * @param mask current search mask
3946 * @param state arg-pointer
3949 static NTSTATUS
copy_fn(const char *mnt
, struct file_info
*f
,
3950 const char *mask
, void *state
)
3952 static NTSTATUS nt_status
;
3953 static struct copy_clistate
*local_state
;
3954 static fstring filename
, new_mask
;
3957 struct net_context
*c
;
3959 local_state
= (struct copy_clistate
*)state
;
3960 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3964 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3965 return NT_STATUS_OK
;
3967 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3970 if (f
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
3972 DEBUG(3,("got dir: %s\n", f
->name
));
3974 fstrcpy(dir
, local_state
->cwd
);
3976 fstrcat(dir
, f
->name
);
3978 switch (net_mode_share
)
3980 case NET_MODE_SHARE_MIGRATE
:
3981 /* create that directory */
3982 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3983 local_state
->cli_share_src
,
3984 local_state
->cli_share_dst
,
3986 c
->opt_acls
? true : false,
3987 c
->opt_attrs
? true : false,
3988 c
->opt_timestamps
? true:false,
3992 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3993 return NT_STATUS_INTERNAL_ERROR
;
3996 if (!NT_STATUS_IS_OK(nt_status
)) {
3997 printf(_("could not handle dir %s: %s\n"),
3998 dir
, nt_errstr(nt_status
));
4002 /* search below that directory */
4003 if (strlcpy(new_mask
, dir
, sizeof(new_mask
)) >= sizeof(new_mask
)) {
4004 return NT_STATUS_NO_MEMORY
;
4006 if (strlcat(new_mask
, "\\*", sizeof(new_mask
)) >= sizeof(new_mask
)) {
4007 return NT_STATUS_NO_MEMORY
;
4010 old_dir
= local_state
->cwd
;
4011 local_state
->cwd
= dir
;
4012 nt_status
= sync_files(local_state
, new_mask
);
4013 if (!NT_STATUS_IS_OK(nt_status
)) {
4014 printf(_("could not handle files\n"));
4016 local_state
->cwd
= old_dir
;
4023 fstrcpy(filename
, local_state
->cwd
);
4024 fstrcat(filename
, "\\");
4025 fstrcat(filename
, f
->name
);
4027 DEBUG(3,("got file: %s\n", filename
));
4029 switch (net_mode_share
)
4031 case NET_MODE_SHARE_MIGRATE
:
4032 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
4033 local_state
->cli_share_src
,
4034 local_state
->cli_share_dst
,
4036 c
->opt_acls
? true : false,
4037 c
->opt_attrs
? true : false,
4038 c
->opt_timestamps
? true: false,
4042 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
4044 return NT_STATUS_INTERNAL_ERROR
;
4047 if (!NT_STATUS_IS_OK(nt_status
))
4048 printf(_("could not handle file %s: %s\n"),
4049 filename
, nt_errstr(nt_status
));
4054 * sync files, can be called recursivly to list files
4055 * and then call copy_fn for each file
4057 * @param cp_clistate pointer to the copy_clistate we work with
4058 * @param mask the current search mask
4060 * @return Boolean result
4062 static NTSTATUS
sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
4064 struct cli_state
*targetcli
;
4065 char *targetpath
= NULL
;
4068 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
4070 status
= cli_resolve_path(talloc_tos(), "", NULL
,
4071 cp_clistate
->cli_share_src
,
4072 mask
, &targetcli
, &targetpath
);
4073 if (!NT_STATUS_IS_OK(status
)) {
4074 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
4076 mask
, nt_errstr(status
));
4080 status
= cli_list(targetcli
, targetpath
, cp_clistate
->attribute
,
4081 copy_fn
, cp_clistate
);
4082 if (!NT_STATUS_IS_OK(status
)) {
4083 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
4084 mask
, nt_errstr(status
));
4092 * Set the top level directory permissions before we do any further copies.
4093 * Should set up ACL inheritance.
4096 bool copy_top_level_perms(struct net_context
*c
,
4097 struct copy_clistate
*cp_clistate
,
4098 const char *sharename
)
4100 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4102 switch (net_mode_share
) {
4103 case NET_MODE_SHARE_MIGRATE
:
4104 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
4105 nt_status
= net_copy_fileattr(c
,
4106 cp_clistate
->mem_ctx
,
4107 cp_clistate
->cli_share_src
,
4108 cp_clistate
->cli_share_dst
,
4110 c
->opt_acls
? true : false,
4111 c
->opt_attrs
? true : false,
4112 c
->opt_timestamps
? true: false,
4116 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
4120 if (!NT_STATUS_IS_OK(nt_status
)) {
4121 printf(_("Could handle directory attributes for top level "
4122 "directory of share %s. Error %s\n"),
4123 sharename
, nt_errstr(nt_status
));
4131 * Sync all files inside a remote share to another share (over smb).
4133 * All parameters are provided by the run_rpc_command function, except for
4134 * argc, argv which are passed through.
4136 * @param domain_sid The domain sid acquired from the remote server.
4137 * @param cli A cli_state connected to the server.
4138 * @param mem_ctx Talloc context, destroyed on completion of the function.
4139 * @param argc Standard main() style argc.
4140 * @param argv Standard main() style argv. Initial components are already
4143 * @return Normal NTSTATUS return.
4146 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
4147 const struct dom_sid
*domain_sid
,
4148 const char *domain_name
,
4149 struct cli_state
*cli
,
4150 struct rpc_pipe_client
*pipe_hnd
,
4151 TALLOC_CTX
*mem_ctx
,
4156 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4157 struct srvsvc_NetShareInfoCtr ctr_src
;
4159 uint32_t level
= 502;
4160 struct copy_clistate cp_clistate
;
4161 bool got_src_share
= false;
4162 bool got_dst_share
= false;
4163 const char *mask
= "\\*";
4166 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
4168 nt_status
= NT_STATUS_NO_MEMORY
;
4172 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4175 if (!W_ERROR_IS_OK(result
))
4178 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4180 struct srvsvc_NetShareInfo502 info502
=
4181 ctr_src
.ctr
.ctr502
->array
[i
];
4183 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4186 /* one might not want to mirror whole discs :) */
4187 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
4188 d_printf(_("skipping [%s]: builtin/hidden share\n"),
4193 switch (net_mode_share
)
4195 case NET_MODE_SHARE_MIGRATE
:
4199 d_fprintf(stderr
, _("Unsupported mode %d\n"),
4203 printf(_(" [%s] files and directories %s ACLs, %s DOS "
4206 c
->opt_acls
? _("including") : _("without"),
4207 c
->opt_attrs
? _("including") : _("without"),
4208 c
->opt_timestamps
? _("(preserving timestamps)") : "");
4210 cp_clistate
.mem_ctx
= mem_ctx
;
4211 cp_clistate
.cli_share_src
= NULL
;
4212 cp_clistate
.cli_share_dst
= NULL
;
4213 cp_clistate
.cwd
= NULL
;
4214 cp_clistate
.attribute
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
;
4217 /* open share source */
4218 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
4219 smbXcli_conn_remote_sockaddr(cli
->conn
),
4220 smbXcli_conn_remote_name(cli
->conn
),
4221 info502
.name
, "A:");
4222 if (!NT_STATUS_IS_OK(nt_status
))
4225 got_src_share
= true;
4227 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
4228 /* open share destination */
4229 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
4230 NULL
, dst
, info502
.name
, "A:");
4231 if (!NT_STATUS_IS_OK(nt_status
))
4234 got_dst_share
= true;
4237 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
4238 d_fprintf(stderr
, _("Could not handle the top level "
4239 "directory permissions for the "
4240 "share: %s\n"), info502
.name
);
4241 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4245 nt_status
= sync_files(&cp_clistate
, mask
);
4246 if (!NT_STATUS_IS_OK(nt_status
)) {
4247 d_fprintf(stderr
, _("could not handle files for share: "
4248 "%s\n"), info502
.name
);
4253 nt_status
= NT_STATUS_OK
;
4258 cli_shutdown(cp_clistate
.cli_share_src
);
4261 cli_shutdown(cp_clistate
.cli_share_dst
);
4268 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
4270 if (c
->display_usage
) {
4272 "net share migrate files\n"
4275 _("Migrate files to local server"));
4280 d_printf(_("no server to migrate\n"));
4284 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4285 rpc_share_migrate_files_internals
,
4290 * Migrate share-ACLs from a remote RPC server to the local RPC server.
4292 * All parameters are provided by the run_rpc_command function, except for
4293 * argc, argv which are passed through.
4295 * @param domain_sid The domain sid acquired from the remote server.
4296 * @param cli A cli_state connected to the server.
4297 * @param mem_ctx Talloc context, destroyed on completion of the function.
4298 * @param argc Standard main() style argc.
4299 * @param argv Standard main() style argv. Initial components are already
4302 * @return Normal NTSTATUS return.
4305 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
4306 const struct dom_sid
*domain_sid
,
4307 const char *domain_name
,
4308 struct cli_state
*cli
,
4309 struct rpc_pipe_client
*pipe_hnd
,
4310 TALLOC_CTX
*mem_ctx
,
4315 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4316 struct srvsvc_NetShareInfoCtr ctr_src
;
4317 union srvsvc_NetShareInfo info
;
4319 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
4320 struct cli_state
*cli_dst
= NULL
;
4321 uint32_t level
= 502; /* includes secdesc */
4322 uint32_t parm_error
= 0;
4323 struct dcerpc_binding_handle
*b
;
4325 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4328 if (!W_ERROR_IS_OK(result
))
4331 /* connect destination PI_SRVSVC */
4332 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
4334 if (!NT_STATUS_IS_OK(nt_status
))
4337 b
= srvsvc_pipe
->binding_handle
;
4339 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4341 struct srvsvc_NetShareInfo502 info502
=
4342 ctr_src
.ctr
.ctr502
->array
[i
];
4344 /* reset error-code */
4345 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4347 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4350 printf(_("migrating: [%s], path: %s, comment: %s, including "
4352 info502
.name
, info502
.path
, info502
.comment
);
4355 display_sec_desc(info502
.sd_buf
.sd
);
4357 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4358 info
.info502
= &info502
;
4360 /* finally modify the share on the dst server */
4361 nt_status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
4362 srvsvc_pipe
->desthost
,
4368 if (!NT_STATUS_IS_OK(nt_status
)) {
4369 printf(_("cannot set share-acl: %s\n"),
4370 nt_errstr(nt_status
));
4373 if (!W_ERROR_IS_OK(result
)) {
4374 nt_status
= werror_to_ntstatus(result
);
4375 printf(_("cannot set share-acl: %s\n"),
4376 win_errstr(result
));
4382 nt_status
= NT_STATUS_OK
;
4386 cli_shutdown(cli_dst
);
4394 * Migrate share-acls from a RPC server to another.
4396 * @param argc Standard main() style argc.
4397 * @param argv Standard main() style argv. Initial components are already
4400 * @return A shell status integer (0 for success).
4402 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
4405 if (c
->display_usage
) {
4407 "net rpc share migrate security\n"
4410 _("Migrate share-acls to local server"));
4415 d_printf(_("no server to migrate\n"));
4419 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4420 rpc_share_migrate_security_internals
,
4425 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4426 * from one server to another.
4428 * @param argc Standard main() style argc.
4429 * @param argv Standard main() style argv. Initial components are already
4432 * @return A shell status integer (0 for success).
4435 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
4440 if (c
->display_usage
) {
4442 "net rpc share migrate all\n"
4445 _("Migrates shares including all share settings"));
4450 d_printf(_("no server to migrate\n"));
4454 /* order is important. we don't want to be locked out by the share-acl
4455 * before copying files - gd */
4457 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4458 rpc_share_migrate_shares_internals
, argc
, argv
);
4462 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4463 rpc_share_migrate_files_internals
, argc
, argv
);
4467 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4468 rpc_share_migrate_security_internals
, argc
,
4474 * 'net rpc share migrate' entrypoint.
4475 * @param argc Standard main() style argc.
4476 * @param argv Standard main() style argv. Initial components are already
4479 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
4482 struct functable func
[] = {
4485 rpc_share_migrate_all
,
4487 N_("Migrate shares from remote to local server"),
4488 N_("net rpc share migrate all\n"
4489 " Migrate shares from remote to local server")
4493 rpc_share_migrate_files
,
4495 N_("Migrate files from remote to local server"),
4496 N_("net rpc share migrate files\n"
4497 " Migrate files from remote to local server")
4501 rpc_share_migrate_security
,
4503 N_("Migrate share-ACLs from remote to local server"),
4504 N_("net rpc share migrate security\n"
4505 " Migrate share-ACLs from remote to local server")
4509 rpc_share_migrate_shares
,
4511 N_("Migrate shares from remote to local server"),
4512 N_("net rpc share migrate shares\n"
4513 " Migrate shares from remote to local server")
4515 {NULL
, NULL
, 0, NULL
, NULL
}
4518 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
4520 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
4525 uint32_t num_members
;
4526 struct dom_sid
*members
;
4529 static int num_server_aliases
;
4530 static struct full_alias
*server_aliases
;
4533 * Add an alias to the static list.
4535 static void push_alias(struct full_alias
*alias
)
4539 if (server_aliases
== NULL
) {
4540 server_aliases
= talloc_array(NULL
, struct full_alias
, 100);
4541 if (server_aliases
== NULL
) {
4542 smb_panic("talloc_array failed");
4546 array_size
= talloc_array_length(server_aliases
);
4547 if (array_size
== num_server_aliases
) {
4548 server_aliases
= talloc_realloc(NULL
, server_aliases
,
4549 struct full_alias
, array_size
+ 100);
4550 if (server_aliases
== NULL
) {
4551 smb_panic("talloc_realloc failed");
4555 server_aliases
[num_server_aliases
] = *alias
;
4556 num_server_aliases
+= 1;
4560 * For a specific domain on the server, fetch all the aliases
4561 * and their members. Add all of them to the server_aliases.
4564 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
4565 TALLOC_CTX
*mem_ctx
,
4566 struct policy_handle
*connect_pol
,
4567 const struct dom_sid
*domain_sid
)
4569 uint32_t start_idx
, max_entries
, num_entries
, i
;
4570 struct samr_SamArray
*groups
= NULL
;
4571 NTSTATUS result
, status
;
4572 struct policy_handle domain_pol
;
4573 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4575 /* Get domain policy handle */
4577 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
4579 MAXIMUM_ALLOWED_ACCESS
,
4580 discard_const_p(struct dom_sid2
, domain_sid
),
4583 if (!NT_STATUS_IS_OK(status
)) {
4586 if (!NT_STATUS_IS_OK(result
)) {
4594 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
4601 if (!NT_STATUS_IS_OK(status
)) {
4604 for (i
= 0; i
< num_entries
; i
++) {
4606 struct policy_handle alias_pol
;
4607 struct full_alias alias
;
4608 struct lsa_SidArray sid_array
;
4612 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
4614 MAXIMUM_ALLOWED_ACCESS
,
4615 groups
->entries
[i
].idx
,
4618 if (!NT_STATUS_IS_OK(status
)) {
4621 if (!NT_STATUS_IS_OK(_result
)) {
4626 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
4630 if (!NT_STATUS_IS_OK(status
)) {
4633 if (!NT_STATUS_IS_OK(_result
)) {
4638 alias
.num_members
= sid_array
.num_sids
;
4640 status
= dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &_result
);
4641 if (!NT_STATUS_IS_OK(status
)) {
4644 if (!NT_STATUS_IS_OK(_result
)) {
4649 alias
.members
= NULL
;
4651 if (alias
.num_members
> 0) {
4652 alias
.members
= SMB_MALLOC_ARRAY(struct dom_sid
, alias
.num_members
);
4654 for (j
= 0; j
< alias
.num_members
; j
++)
4655 sid_copy(&alias
.members
[j
],
4656 sid_array
.sids
[j
].sid
);
4659 sid_compose(&alias
.sid
, domain_sid
,
4660 groups
->entries
[i
].idx
);
4664 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4666 status
= NT_STATUS_OK
;
4669 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
4675 * Dump server_aliases as names for debugging purposes.
4678 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
4679 const struct dom_sid
*domain_sid
,
4680 const char *domain_name
,
4681 struct cli_state
*cli
,
4682 struct rpc_pipe_client
*pipe_hnd
,
4683 TALLOC_CTX
*mem_ctx
,
4689 struct policy_handle lsa_pol
;
4690 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4692 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
4693 SEC_FLAG_MAXIMUM_ALLOWED
,
4695 if (!NT_STATUS_IS_OK(result
))
4698 for (i
=0; i
<num_server_aliases
; i
++) {
4701 enum lsa_SidType
*types
;
4704 struct full_alias
*alias
= &server_aliases
[i
];
4706 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4708 &domains
, &names
, &types
);
4709 if (!NT_STATUS_IS_OK(result
))
4712 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4714 if (alias
->num_members
== 0) {
4719 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4722 &domains
, &names
, &types
);
4724 if (!NT_STATUS_IS_OK(result
) &&
4725 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4728 for (j
=0; j
<alias
->num_members
; j
++)
4729 DEBUG(1, ("%s\\%s (%d); ",
4730 domains
[j
] ? domains
[j
] : "*unknown*",
4731 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4735 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
4737 return NT_STATUS_OK
;
4741 * Fetch a list of all server aliases and their members into
4745 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4746 const struct dom_sid
*domain_sid
,
4747 const char *domain_name
,
4748 struct cli_state
*cli
,
4749 struct rpc_pipe_client
*pipe_hnd
,
4750 TALLOC_CTX
*mem_ctx
,
4754 NTSTATUS result
, status
;
4755 struct policy_handle connect_pol
;
4756 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4758 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
4760 MAXIMUM_ALLOWED_ACCESS
,
4763 if (!NT_STATUS_IS_OK(status
)) {
4766 if (!NT_STATUS_IS_OK(result
)) {
4771 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4772 &global_sid_Builtin
);
4773 if (!NT_STATUS_IS_OK(status
)) {
4777 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4780 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
4785 static void init_user_token(struct security_token
*token
, struct dom_sid
*user_sid
)
4787 token
->num_sids
= 4;
4789 if (!(token
->sids
= SMB_MALLOC_ARRAY(struct dom_sid
, 4))) {
4790 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4791 token
->num_sids
= 0;
4795 token
->sids
[0] = *user_sid
;
4796 sid_copy(&token
->sids
[1], &global_sid_World
);
4797 sid_copy(&token
->sids
[2], &global_sid_Network
);
4798 sid_copy(&token
->sids
[3], &global_sid_Authenticated_Users
);
4801 static void free_user_token(struct security_token
*token
)
4803 SAFE_FREE(token
->sids
);
4806 static void add_sid_to_token(struct security_token
*token
, struct dom_sid
*sid
)
4808 if (security_token_has_sid(token
, sid
))
4811 token
->sids
= SMB_REALLOC_ARRAY(token
->sids
, struct dom_sid
, token
->num_sids
+1);
4816 sid_copy(&token
->sids
[token
->num_sids
], sid
);
4818 token
->num_sids
+= 1;
4823 struct security_token token
;
4826 static void dump_user_token(struct user_token
*token
)
4830 d_printf("%s\n", token
->name
);
4832 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4833 d_printf(" %s\n", sid_string_tos(&token
->token
.sids
[i
]));
4837 static bool is_alias_member(struct dom_sid
*sid
, struct full_alias
*alias
)
4841 for (i
=0; i
<alias
->num_members
; i
++) {
4842 if (dom_sid_compare(sid
, &alias
->members
[i
]) == 0)
4849 static void collect_sid_memberships(struct security_token
*token
, struct dom_sid sid
)
4853 for (i
=0; i
<num_server_aliases
; i
++) {
4854 if (is_alias_member(&sid
, &server_aliases
[i
]))
4855 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4860 * We got a user token with all the SIDs we can know about without asking the
4861 * server directly. These are the user and domain group sids. All of these can
4862 * be members of aliases. So scan the list of aliases for each of the SIDs and
4863 * add them to the token.
4866 static void collect_alias_memberships(struct security_token
*token
)
4868 int num_global_sids
= token
->num_sids
;
4871 for (i
=0; i
<num_global_sids
; i
++) {
4872 collect_sid_memberships(token
, token
->sids
[i
]);
4876 static bool get_user_sids(const char *domain
, const char *user
, struct security_token
*token
)
4878 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4879 enum wbcSidType type
;
4881 struct wbcDomainSid wsid
;
4882 char sid_str
[WBC_SID_STRING_BUFLEN
];
4883 struct dom_sid user_sid
;
4884 uint32_t num_groups
;
4885 gid_t
*groups
= NULL
;
4888 fstr_sprintf(full_name
, "%s%c%s",
4889 domain
, *lp_winbind_separator(), user
);
4891 /* First let's find out the user sid */
4893 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4895 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4896 DEBUG(1, ("winbind could not find %s: %s\n",
4897 full_name
, wbcErrorString(wbc_status
)));
4901 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4903 if (type
!= WBC_SID_NAME_USER
) {
4904 DEBUG(1, ("%s is not a user\n", full_name
));
4908 if (!string_to_sid(&user_sid
, sid_str
)) {
4909 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4913 init_user_token(token
, &user_sid
);
4915 /* And now the groups winbind knows about */
4917 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4918 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4919 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4920 full_name
, wbcErrorString(wbc_status
)));
4924 for (i
= 0; i
< num_groups
; i
++) {
4925 gid_t gid
= groups
[i
];
4929 wbc_status
= wbcGidToSid(gid
, &wsid
);
4930 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4931 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4932 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4933 wbcFreeMemory(groups
);
4937 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4939 DEBUG(3, (" %s\n", sid_str
));
4941 ok
= string_to_sid(&sid
, sid_str
);
4943 DEBUG(1, ("Failed to convert string to SID\n"));
4944 wbcFreeMemory(groups
);
4947 add_sid_to_token(token
, &sid
);
4949 wbcFreeMemory(groups
);
4955 * Get a list of all user tokens we want to look at
4958 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4959 struct user_token
**user_tokens
)
4961 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4962 uint32_t i
, num_users
;
4964 struct user_token
*result
;
4965 TALLOC_CTX
*frame
= NULL
;
4967 if (lp_winbind_use_default_domain() &&
4968 (c
->opt_target_workgroup
== NULL
)) {
4969 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4970 "please specify a workgroup\n"));
4974 /* Send request to winbind daemon */
4976 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4977 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4978 DEBUG(1, (_("winbind could not list users: %s\n"),
4979 wbcErrorString(wbc_status
)));
4983 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4985 if (result
== NULL
) {
4986 DEBUG(1, ("Could not malloc sid array\n"));
4987 wbcFreeMemory(users
);
4991 frame
= talloc_stackframe();
4992 for (i
=0; i
< num_users
; i
++) {
4993 fstring domain
, user
;
4996 fstrcpy(result
[i
].name
, users
[i
]);
4998 p
= strchr(users
[i
], *lp_winbind_separator());
5000 DEBUG(3, ("%s\n", users
[i
]));
5003 fstrcpy(domain
, c
->opt_target_workgroup
);
5004 fstrcpy(user
, users
[i
]);
5007 fstrcpy(domain
, users
[i
]);
5008 if (!strupper_m(domain
)) {
5009 DEBUG(1, ("strupper_m %s failed\n", domain
));
5010 wbcFreeMemory(users
);
5016 get_user_sids(domain
, user
, &(result
[i
].token
));
5019 wbcFreeMemory(users
);
5021 *num_tokens
= num_users
;
5022 *user_tokens
= result
;
5027 static bool get_user_tokens_from_file(FILE *f
,
5029 struct user_token
**tokens
)
5031 struct user_token
*token
= NULL
;
5036 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
5040 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
5041 line
[strlen(line
)-1] = '\0';
5044 if (line
[0] == ' ') {
5048 if(!string_to_sid(&sid
, &line
[1])) {
5049 DEBUG(1,("get_user_tokens_from_file: Could "
5050 "not convert sid %s \n",&line
[1]));
5054 if (token
== NULL
) {
5055 DEBUG(0, ("File does not begin with username"));
5059 add_sid_to_token(&token
->token
, &sid
);
5063 /* And a new user... */
5066 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
5067 if (*tokens
== NULL
) {
5068 DEBUG(0, ("Could not realloc tokens\n"));
5072 token
= &((*tokens
)[*num_tokens
-1]);
5074 if (strlcpy(token
->name
, line
, sizeof(token
->name
)) >= sizeof(token
->name
)) {
5077 token
->token
.num_sids
= 0;
5078 token
->token
.sids
= NULL
;
5087 * Show the list of all users that have access to a share
5090 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
5091 struct cli_state
*cli
,
5092 TALLOC_CTX
*mem_ctx
,
5093 const char *netname
,
5095 struct user_token
*tokens
)
5098 struct security_descriptor
*share_sd
= NULL
;
5099 struct security_descriptor
*root_sd
= NULL
;
5101 union srvsvc_NetShareInfo info
;
5105 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5107 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5114 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
5115 DEBUG(1, ("Could not query secdesc for share %s\n",
5120 share_sd
= info
.info502
->sd_buf
.sd
;
5121 if (share_sd
== NULL
) {
5122 DEBUG(1, ("Got no secdesc for share %s\n",
5126 cnum
= cli_state_get_tid(cli
);
5128 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, netname
, "A:", NULL
))) {
5132 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
5133 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
5134 FILE_OPEN
, 0x0, 0x0, &fnum
, NULL
))) {
5135 cli_query_secdesc(cli
, fnum
, mem_ctx
, &root_sd
);
5138 for (i
=0; i
<num_tokens
; i
++) {
5139 uint32_t acc_granted
;
5141 if (share_sd
!= NULL
) {
5142 status
= se_access_check(share_sd
, &tokens
[i
].token
,
5145 if (!NT_STATUS_IS_OK(status
)) {
5146 DEBUG(1, ("Could not check share_sd for "
5153 if (root_sd
== NULL
) {
5154 d_printf(" %s\n", tokens
[i
].name
);
5158 status
= se_access_check(root_sd
, &tokens
[i
].token
,
5160 if (!NT_STATUS_IS_OK(status
)) {
5161 DEBUG(1, ("Could not check root_sd for user %s\n",
5165 d_printf(" %s\n", tokens
[i
].name
);
5168 if (fnum
!= (uint16_t)-1)
5169 cli_close(cli
, fnum
);
5171 cli_state_set_tid(cli
, cnum
);
5177 * List shares on a remote RPC server, including the security descriptors.
5179 * All parameters are provided by the run_rpc_command function, except for
5180 * argc, argv which are passed through.
5182 * @param domain_sid The domain sid acquired from the remote server.
5183 * @param cli A cli_state connected to the server.
5184 * @param mem_ctx Talloc context, destroyed on completion of the function.
5185 * @param argc Standard main() style argc.
5186 * @param argv Standard main() style argv. Initial components are already
5189 * @return Normal NTSTATUS return.
5192 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
5193 const struct dom_sid
*domain_sid
,
5194 const char *domain_name
,
5195 struct cli_state
*cli
,
5196 struct rpc_pipe_client
*pipe_hnd
,
5197 TALLOC_CTX
*mem_ctx
,
5203 NTSTATUS nt_status
= NT_STATUS_OK
;
5204 uint32_t total_entries
= 0;
5205 uint32_t resume_handle
= 0;
5206 uint32_t preferred_len
= 0xffffffff;
5208 struct dcerpc_binding_handle
*b
= NULL
;
5209 struct srvsvc_NetShareInfoCtr info_ctr
;
5210 struct srvsvc_NetShareCtr1 ctr1
;
5213 struct user_token
*tokens
= NULL
;
5219 f
= fopen(argv
[0], "r");
5223 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
5224 return NT_STATUS_UNSUCCESSFUL
;
5227 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
5233 DEBUG(0, ("Could not read users from file\n"));
5234 return NT_STATUS_UNSUCCESSFUL
;
5237 for (i
=0; i
<num_tokens
; i
++)
5238 collect_alias_memberships(&tokens
[i
].token
);
5240 ZERO_STRUCT(info_ctr
);
5244 info_ctr
.ctr
.ctr1
= &ctr1
;
5246 b
= pipe_hnd
->binding_handle
;
5248 /* Issue the NetShareEnum RPC call and retrieve the response */
5249 nt_status
= dcerpc_srvsvc_NetShareEnumAll(b
,
5258 /* Was it successful? */
5259 if (!NT_STATUS_IS_OK(nt_status
)) {
5260 /* Nope. Go clean up. */
5264 if (!W_ERROR_IS_OK(result
)) {
5265 /* Nope. Go clean up. */
5266 nt_status
= werror_to_ntstatus(result
);
5270 if (total_entries
== 0) {
5274 /* For each returned entry... */
5275 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
5276 const char *netname
= info_ctr
.ctr
.ctr1
->array
[i
].name
;
5278 if (info_ctr
.ctr
.ctr1
->array
[i
].type
!= STYPE_DISKTREE
) {
5282 d_printf("%s\n", netname
);
5284 show_userlist(pipe_hnd
, cli
, mem_ctx
, netname
,
5285 num_tokens
, tokens
);
5288 for (i
=0; i
<num_tokens
; i
++) {
5289 free_user_token(&tokens
[i
].token
);
5292 TALLOC_FREE(server_aliases
);
5297 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
5302 if (c
->display_usage
) {
5304 "net rpc share allowedusers\n"
5307 _("List allowed users"));
5311 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
5312 rpc_aliaslist_internals
,
5317 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
, 0,
5323 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
5324 rpc_share_allowedusers_internals
,
5328 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
5331 struct user_token
*tokens
= NULL
;
5335 net_usersidlist_usage(c
, argc
, argv
);
5339 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
5340 DEBUG(0, ("Could not get the user/sid list\n"));
5344 for (i
=0; i
<num_tokens
; i
++) {
5345 dump_user_token(&tokens
[i
]);
5346 free_user_token(&tokens
[i
].token
);
5353 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
5355 d_printf(_("net usersidlist\n"
5356 "\tprints out a list of all users the running winbind knows\n"
5357 "\tabout, together with all their SIDs. This is used as\n"
5358 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
5360 net_common_flags_usage(c
, argc
, argv
);
5365 * 'net rpc share' entrypoint.
5366 * @param argc Standard main() style argc.
5367 * @param argv Standard main() style argv. Initial components are already
5371 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
5373 NET_API_STATUS status
;
5375 struct functable func
[] = {
5381 N_("net rpc share add\n"
5389 N_("net rpc share delete\n"
5394 rpc_share_allowedusers
,
5396 N_("Modify allowed users"),
5397 N_("net rpc share allowedusers\n"
5398 " Modify allowed users")
5404 N_("Migrate share to local server"),
5405 N_("net rpc share migrate\n"
5406 " Migrate share to local server")
5413 N_("net rpc share list\n"
5416 {NULL
, NULL
, 0, NULL
, NULL
}
5419 status
= libnetapi_net_init(&c
->netapi_ctx
);
5423 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
5424 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
5425 if (c
->opt_kerberos
) {
5426 libnetapi_set_use_kerberos(c
->netapi_ctx
);
5430 if (c
->display_usage
) {
5435 " Alias for net rpc share list\n"));
5436 net_display_usage_from_functable(func
);
5440 return rpc_share_list(c
, argc
, argv
);
5443 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
5446 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
5447 TALLOC_CTX
*mem_ctx
,
5448 struct rpc_sh_ctx
*ctx
,
5449 struct rpc_pipe_client
*pipe_hnd
,
5450 int argc
, const char **argv
)
5453 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
5456 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
5457 TALLOC_CTX
*mem_ctx
,
5458 struct rpc_sh_ctx
*ctx
,
5459 struct rpc_pipe_client
*pipe_hnd
,
5460 int argc
, const char **argv
)
5462 NET_API_STATUS status
;
5463 uint32_t parm_err
= 0;
5464 struct SHARE_INFO_2 i2
;
5466 if ((argc
< 2) || (argc
> 3)) {
5467 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
5469 return NT_STATUS_INVALID_PARAMETER
;
5472 i2
.shi2_netname
= argv
[0];
5473 i2
.shi2_type
= STYPE_DISKTREE
;
5474 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
5475 i2
.shi2_permissions
= 0;
5476 i2
.shi2_max_uses
= 0;
5477 i2
.shi2_current_uses
= 0;
5478 i2
.shi2_path
= argv
[1];
5479 i2
.shi2_passwd
= NULL
;
5481 status
= NetShareAdd(pipe_hnd
->desthost
,
5486 return werror_to_ntstatus(W_ERROR(status
));
5489 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
5490 TALLOC_CTX
*mem_ctx
,
5491 struct rpc_sh_ctx
*ctx
,
5492 struct rpc_pipe_client
*pipe_hnd
,
5493 int argc
, const char **argv
)
5496 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5497 return NT_STATUS_INVALID_PARAMETER
;
5500 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
5503 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
5504 TALLOC_CTX
*mem_ctx
,
5505 struct rpc_sh_ctx
*ctx
,
5506 struct rpc_pipe_client
*pipe_hnd
,
5507 int argc
, const char **argv
)
5509 union srvsvc_NetShareInfo info
;
5512 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5515 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5516 return NT_STATUS_INVALID_PARAMETER
;
5519 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5525 if (!NT_STATUS_IS_OK(status
)) {
5526 result
= ntstatus_to_werror(status
);
5529 if (!W_ERROR_IS_OK(result
)) {
5533 d_printf(_("Name: %s\n"), info
.info2
->name
);
5534 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
5535 d_printf(_("Path: %s\n"), info
.info2
->path
);
5536 d_printf(_("Password: %s\n"), info
.info2
->password
);
5539 return werror_to_ntstatus(result
);
5542 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
5543 struct rpc_sh_ctx
*ctx
)
5545 static struct rpc_sh_cmd cmds
[] = {
5547 { "list", NULL
, &ndr_table_srvsvc
, rpc_sh_share_list
,
5548 N_("List available shares") },
5550 { "add", NULL
, &ndr_table_srvsvc
, rpc_sh_share_add
,
5551 N_("Add a share") },
5553 { "delete", NULL
, &ndr_table_srvsvc
, rpc_sh_share_delete
,
5554 N_("Delete a share") },
5556 { "info", NULL
, &ndr_table_srvsvc
, rpc_sh_share_info
,
5557 N_("Get information about a share") },
5559 { NULL
, NULL
, 0, NULL
, NULL
}
5565 /****************************************************************************/
5567 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
5569 return net_file_usage(c
, argc
, argv
);
5573 * Close a file on a remote RPC server.
5575 * @param argc Standard main() style argc.
5576 * @param argv Standard main() style argv. Initial components are already
5579 * @return A shell status integer (0 for success).
5581 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
5583 if (argc
< 1 || c
->display_usage
) {
5584 return rpc_file_usage(c
, argc
, argv
);
5587 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
5591 * Formatted print of open file info
5593 * @param r struct FILE_INFO_3 contents
5596 static void display_file_info_3(struct FILE_INFO_3
*r
)
5598 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5599 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
5600 r
->fi3_num_locks
, r
->fi3_pathname
);
5604 * List files for a user on a remote RPC server.
5606 * @param argc Standard main() style argc.
5607 * @param argv Standard main() style argv. Initial components are already
5610 * @return A shell status integer (0 for success)..
5613 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
5615 NET_API_STATUS status
;
5616 uint32_t preferred_len
= 0xffffffff, i
;
5617 char *username
=NULL
;
5618 uint32_t total_entries
= 0;
5619 uint32_t entries_read
= 0;
5620 uint32_t resume_handle
= 0;
5621 struct FILE_INFO_3
*i3
= NULL
;
5623 if (c
->display_usage
) {
5624 return rpc_file_usage(c
, argc
, argv
);
5627 /* if argc > 0, must be user command */
5629 username
= smb_xstrdup(argv
[0]);
5632 status
= NetFileEnum(c
->opt_host
,
5636 (uint8_t **)(void *)&i3
,
5646 /* Display results */
5649 "\nEnumerating open files on remote server:\n\n"
5650 "\nFileId Opened by Perms Locks Path"
5651 "\n------ --------- ----- ----- ---- \n"));
5652 for (i
= 0; i
< entries_read
; i
++) {
5653 display_file_info_3(&i3
[i
]);
5656 SAFE_FREE(username
);
5661 * 'net rpc file' entrypoint.
5662 * @param argc Standard main() style argc.
5663 * @param argv Standard main() style argv. Initial components are already
5667 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
5669 NET_API_STATUS status
;
5671 struct functable func
[] = {
5676 N_("Close opened file"),
5677 N_("net rpc file close\n"
5678 " Close opened file")
5684 N_("List files opened by user"),
5685 N_("net rpc file user\n"
5686 " List files opened by user")
5693 N_("Display information about opened file"),
5694 N_("net rpc file info\n"
5695 " Display information about opened file")
5698 {NULL
, NULL
, 0, NULL
, NULL
}
5701 status
= libnetapi_net_init(&c
->netapi_ctx
);
5705 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
5706 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
5707 if (c
->opt_kerberos
) {
5708 libnetapi_set_use_kerberos(c
->netapi_ctx
);
5712 if (c
->display_usage
) {
5713 d_printf(_("Usage:\n"));
5714 d_printf(_("net rpc file\n"
5715 " List opened files\n"));
5716 net_display_usage_from_functable(func
);
5720 return rpc_file_user(c
, argc
, argv
);
5723 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
5727 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5729 * All parameters are provided by the run_rpc_command function, except for
5730 * argc, argv which are passed through.
5732 * @param c A net_context structure.
5733 * @param domain_sid The domain sid acquired from the remote server.
5734 * @param cli A cli_state connected to the server.
5735 * @param mem_ctx Talloc context, destroyed on completion of the function.
5736 * @param argc Standard main() style argc.
5737 * @param argv Standard main() style argv. Initial components are already
5740 * @return Normal NTSTATUS return.
5743 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
5744 const struct dom_sid
*domain_sid
,
5745 const char *domain_name
,
5746 struct cli_state
*cli
,
5747 struct rpc_pipe_client
*pipe_hnd
,
5748 TALLOC_CTX
*mem_ctx
,
5752 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5754 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5756 status
= dcerpc_initshutdown_Abort(b
, mem_ctx
, NULL
, &result
);
5757 if (!NT_STATUS_IS_OK(status
)) {
5760 if (W_ERROR_IS_OK(result
)) {
5761 d_printf(_("\nShutdown successfully aborted\n"));
5762 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5764 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5766 return werror_to_ntstatus(result
);
5770 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5772 * All parameters are provided by the run_rpc_command function, except for
5773 * argc, argv which are passed through.
5775 * @param c A net_context structure.
5776 * @param domain_sid The domain sid acquired from the remote server.
5777 * @param cli A cli_state connected to the server.
5778 * @param mem_ctx Talloc context, destroyed on completion of the function.
5779 * @param argc Standard main() style argc.
5780 * @param argv Standard main() style argv. Initial components are already
5783 * @return Normal NTSTATUS return.
5786 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5787 const struct dom_sid
*domain_sid
,
5788 const char *domain_name
,
5789 struct cli_state
*cli
,
5790 struct rpc_pipe_client
*pipe_hnd
,
5791 TALLOC_CTX
*mem_ctx
,
5795 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5797 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5799 result
= dcerpc_winreg_AbortSystemShutdown(b
, mem_ctx
, NULL
, &werr
);
5801 if (!NT_STATUS_IS_OK(result
)) {
5802 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5805 if (W_ERROR_IS_OK(werr
)) {
5806 d_printf(_("\nShutdown successfully aborted\n"));
5807 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5809 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5811 return werror_to_ntstatus(werr
);
5815 * ABORT the shutdown of a remote RPC server.
5817 * @param argc Standard main() style argc.
5818 * @param argv Standard main() style argv. Initial components are already
5821 * @return A shell status integer (0 for success).
5824 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5829 if (c
->display_usage
) {
5831 "net rpc abortshutdown\n"
5834 _("Abort a scheduled shutdown"));
5838 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
5839 rpc_shutdown_abort_internals
, argc
, argv
);
5844 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5846 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
5847 rpc_reg_shutdown_abort_internals
,
5852 * Shut down a remote RPC Server via initshutdown pipe.
5854 * All parameters are provided by the run_rpc_command function, except for
5855 * argc, argv which are passed through.
5857 * @param c A net_context structure.
5858 * @param domain_sid The domain sid acquired from the remote server.
5859 * @param cli A cli_state connected to the server.
5860 * @param mem_ctx Talloc context, destroyed on completion of the function.
5861 * @param argc Standard main() style argc.
5862 * @param argv Standard main() style argv. Initial components are already
5865 * @return Normal NTSTATUS return.
5868 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5869 const struct dom_sid
*domain_sid
,
5870 const char *domain_name
,
5871 struct cli_state
*cli
,
5872 struct rpc_pipe_client
*pipe_hnd
,
5873 TALLOC_CTX
*mem_ctx
,
5877 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5879 const char *msg
= N_("This machine will be shutdown shortly");
5880 uint32_t timeout
= 20;
5881 struct lsa_StringLarge msg_string
;
5882 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5884 if (c
->opt_comment
) {
5885 msg
= c
->opt_comment
;
5887 if (c
->opt_timeout
) {
5888 timeout
= c
->opt_timeout
;
5891 msg_string
.string
= msg
;
5893 /* create an entry */
5894 status
= dcerpc_initshutdown_Init(b
, mem_ctx
, NULL
,
5895 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5897 if (!NT_STATUS_IS_OK(status
)) {
5900 if (W_ERROR_IS_OK(result
)) {
5901 d_printf(_("\nShutdown of remote machine succeeded\n"));
5902 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5904 DEBUG(1,("Shutdown of remote machine failed!\n"));
5906 return werror_to_ntstatus(result
);
5910 * Shut down a remote RPC Server via winreg pipe.
5912 * All parameters are provided by the run_rpc_command function, except for
5913 * argc, argv which are passed through.
5915 * @param c A net_context structure.
5916 * @param domain_sid The domain sid acquired from the remote server.
5917 * @param cli A cli_state connected to the server.
5918 * @param mem_ctx Talloc context, destroyed on completion of the function.
5919 * @param argc Standard main() style argc.
5920 * @param argv Standard main() style argv. Initial components are already
5923 * @return Normal NTSTATUS return.
5926 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5927 const struct dom_sid
*domain_sid
,
5928 const char *domain_name
,
5929 struct cli_state
*cli
,
5930 struct rpc_pipe_client
*pipe_hnd
,
5931 TALLOC_CTX
*mem_ctx
,
5935 const char *msg
= N_("This machine will be shutdown shortly");
5936 uint32_t timeout
= 20;
5937 struct lsa_StringLarge msg_string
;
5940 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5942 if (c
->opt_comment
) {
5943 msg
= c
->opt_comment
;
5945 msg_string
.string
= msg
;
5947 if (c
->opt_timeout
) {
5948 timeout
= c
->opt_timeout
;
5951 /* create an entry */
5952 result
= dcerpc_winreg_InitiateSystemShutdown(b
, mem_ctx
, NULL
,
5953 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5955 if (!NT_STATUS_IS_OK(result
)) {
5956 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5960 if (W_ERROR_IS_OK(werr
)) {
5961 d_printf(_("\nShutdown of remote machine succeeded\n"));
5963 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5964 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5965 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5967 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5970 return werror_to_ntstatus(werr
);
5974 * Shut down a remote RPC server.
5976 * @param argc Standard main() style argc.
5977 * @param argv Standard main() style argv. Initial components are already
5980 * @return A shell status integer (0 for success).
5983 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5987 if (c
->display_usage
) {
5989 "net rpc shutdown\n"
5992 _("Shut down a remote RPC server"));
5996 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
5997 rpc_init_shutdown_internals
, argc
, argv
);
6000 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
6001 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
6002 rpc_reg_shutdown_internals
, argc
, argv
);
6008 /***************************************************************************
6009 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
6010 ***************************************************************************/
6013 * Add interdomain trust account to the RPC server.
6014 * All parameters (except for argc and argv) are passed by run_rpc_command
6017 * @param c A net_context structure.
6018 * @param domain_sid The domain sid acquired from the server.
6019 * @param cli A cli_state connected to the server.
6020 * @param mem_ctx Talloc context, destroyed on completion of the function.
6021 * @param argc Standard main() style argc.
6022 * @param argv Standard main() style argv. Initial components are already
6025 * @return normal NTSTATUS return code.
6028 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
6029 const struct dom_sid
*domain_sid
,
6030 const char *domain_name
,
6031 struct cli_state
*cli
,
6032 struct rpc_pipe_client
*pipe_hnd
,
6033 TALLOC_CTX
*mem_ctx
,
6037 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6038 NTSTATUS status
, result
;
6040 struct lsa_String lsa_acct_name
;
6042 uint32_t acct_flags
=0;
6044 uint32_t access_granted
= 0;
6045 union samr_UserInfo info
;
6046 unsigned int orig_timeout
;
6047 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6048 DATA_BLOB session_key
= data_blob_null
;
6053 _(" net rpc trustdom add <domain_name> "
6054 "<trust password>\n"));
6055 return NT_STATUS_INVALID_PARAMETER
;
6059 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6062 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
6063 return NT_STATUS_NO_MEMORY
;
6066 if (!strupper_m(acct_name
)) {
6067 SAFE_FREE(acct_name
);
6068 return NT_STATUS_INVALID_PARAMETER
;
6071 init_lsa_String(&lsa_acct_name
, acct_name
);
6073 status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
6074 if (!NT_STATUS_IS_OK(status
)) {
6075 DEBUG(0,("Error getting session_key of SAM pipe. Error was %s\n",
6076 nt_errstr(status
)));
6080 /* Get samr policy handle */
6081 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
6083 MAXIMUM_ALLOWED_ACCESS
,
6086 if (!NT_STATUS_IS_OK(status
)) {
6089 if (!NT_STATUS_IS_OK(result
)) {
6094 /* Get domain policy handle */
6095 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
6097 MAXIMUM_ALLOWED_ACCESS
,
6098 discard_const_p(struct dom_sid2
, domain_sid
),
6101 if (!NT_STATUS_IS_OK(status
)) {
6104 if (!NT_STATUS_IS_OK(result
)) {
6109 /* This call can take a long time - allow the server to time out.
6110 * 35 seconds should do it. */
6112 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
6114 /* Create trusting domain's account */
6115 acb_info
= ACB_NORMAL
;
6116 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
6117 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
6118 SAMR_USER_ACCESS_SET_PASSWORD
|
6119 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
6120 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
6122 status
= dcerpc_samr_CreateUser2(b
, mem_ctx
,
6131 if (!NT_STATUS_IS_OK(status
)) {
6134 /* And restore our original timeout. */
6135 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
6137 if (!NT_STATUS_IS_OK(result
)) {
6139 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
6140 acct_name
, nt_errstr(result
));
6145 struct samr_CryptPassword crypt_pwd
;
6147 ZERO_STRUCT(info
.info23
);
6149 init_samr_CryptPassword(argv
[1],
6153 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
6154 SAMR_FIELD_NT_PASSWORD_PRESENT
;
6155 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
6156 info
.info23
.password
= crypt_pwd
;
6158 status
= dcerpc_samr_SetUserInfo2(b
, mem_ctx
,
6163 if (!NT_STATUS_IS_OK(status
)) {
6167 if (!NT_STATUS_IS_OK(result
)) {
6169 DEBUG(0,("Could not set trust account password: %s\n",
6170 nt_errstr(result
)));
6176 SAFE_FREE(acct_name
);
6177 data_blob_clear_free(&session_key
);
6182 * Create interdomain trust account for a remote domain.
6184 * @param argc Standard argc.
6185 * @param argv Standard argv without initial components.
6187 * @return Integer status (0 means success).
6190 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
6192 if (argc
> 0 && !c
->display_usage
) {
6193 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6194 rpc_trustdom_add_internals
, argc
, argv
);
6198 _("net rpc trustdom add <domain_name> <trust "
6206 * Remove interdomain trust account from the RPC server.
6207 * All parameters (except for argc and argv) are passed by run_rpc_command
6210 * @param c A net_context structure.
6211 * @param domain_sid The domain sid acquired from the server.
6212 * @param cli A cli_state connected to the server.
6213 * @param mem_ctx Talloc context, destroyed on completion of the function.
6214 * @param argc Standard main() style argc.
6215 * @param argv Standard main() style argv. Initial components are already
6218 * @return normal NTSTATUS return code.
6221 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
6222 const struct dom_sid
*domain_sid
,
6223 const char *domain_name
,
6224 struct cli_state
*cli
,
6225 struct rpc_pipe_client
*pipe_hnd
,
6226 TALLOC_CTX
*mem_ctx
,
6230 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6231 NTSTATUS status
, result
;
6233 struct dom_sid trust_acct_sid
;
6234 struct samr_Ids user_rids
, name_types
;
6235 struct lsa_String lsa_acct_name
;
6236 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6241 _(" net rpc trustdom del <domain_name>\n"));
6242 return NT_STATUS_INVALID_PARAMETER
;
6246 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6248 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
6250 if (acct_name
== NULL
)
6251 return NT_STATUS_NO_MEMORY
;
6253 if (!strupper_m(acct_name
)) {
6254 TALLOC_FREE(acct_name
);
6255 return NT_STATUS_INVALID_PARAMETER
;
6258 /* Get samr policy handle */
6259 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
6261 MAXIMUM_ALLOWED_ACCESS
,
6264 if (!NT_STATUS_IS_OK(status
)) {
6267 if (!NT_STATUS_IS_OK(result
)) {
6272 /* Get domain policy handle */
6273 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
6275 MAXIMUM_ALLOWED_ACCESS
,
6276 discard_const_p(struct dom_sid2
, domain_sid
),
6279 if (!NT_STATUS_IS_OK(status
)) {
6282 if (!NT_STATUS_IS_OK(result
)) {
6287 init_lsa_String(&lsa_acct_name
, acct_name
);
6289 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
6296 if (!NT_STATUS_IS_OK(status
)) {
6297 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6299 acct_name
, nt_errstr(status
));
6302 if (!NT_STATUS_IS_OK(result
)) {
6304 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6306 acct_name
, nt_errstr(result
) );
6309 if (user_rids
.count
!= 1) {
6310 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6313 if (name_types
.count
!= 1) {
6314 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6318 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
6320 MAXIMUM_ALLOWED_ACCESS
,
6324 if (!NT_STATUS_IS_OK(status
)) {
6325 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6327 acct_name
, nt_errstr(status
) );
6331 if (!NT_STATUS_IS_OK(result
)) {
6333 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6335 acct_name
, nt_errstr(result
) );
6339 /* append the rid to the domain sid */
6340 if (!sid_compose(&trust_acct_sid
, domain_sid
, user_rids
.ids
[0])) {
6344 /* remove the sid */
6346 status
= dcerpc_samr_RemoveMemberFromForeignDomain(b
, mem_ctx
,
6350 if (!NT_STATUS_IS_OK(status
)) {
6351 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6352 " on user %s failed %s\n"),
6353 acct_name
, nt_errstr(status
));
6356 if (!NT_STATUS_IS_OK(result
)) {
6358 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6359 " on user %s failed %s\n"),
6360 acct_name
, nt_errstr(result
) );
6367 status
= dcerpc_samr_DeleteUser(b
, mem_ctx
,
6370 if (!NT_STATUS_IS_OK(status
)) {
6371 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6373 acct_name
, nt_errstr(status
));
6377 if (!NT_STATUS_IS_OK(result
)) {
6379 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6381 acct_name
, nt_errstr(result
) );
6385 if (!NT_STATUS_IS_OK(result
)) {
6386 d_printf(_("Could not set trust account password: %s\n"),
6396 * Delete interdomain trust account for a remote domain.
6398 * @param argc Standard argc.
6399 * @param argv Standard argv without initial components.
6401 * @return Integer status (0 means success).
6404 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
6406 if (argc
> 0 && !c
->display_usage
) {
6407 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6408 rpc_trustdom_del_internals
, argc
, argv
);
6412 _("net rpc trustdom del <domain>\n"));
6417 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
6418 struct cli_state
*cli
,
6419 TALLOC_CTX
*mem_ctx
,
6420 const char *domain_name
)
6422 char *dc_name
= NULL
;
6423 const char *buffer
= NULL
;
6424 struct rpc_pipe_client
*netr
;
6427 struct dcerpc_binding_handle
*b
;
6429 /* Use NetServerEnum2 */
6431 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
6433 return NT_STATUS_OK
;
6436 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
6437 for domain %s\n", domain_name
));
6439 /* Try netr_GetDcName */
6441 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
,
6443 if (!NT_STATUS_IS_OK(status
)) {
6447 b
= netr
->binding_handle
;
6449 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
6456 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(result
)) {
6460 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
6461 for domain %s\n", domain_name
));
6463 if (!NT_STATUS_IS_OK(status
)) {
6467 return werror_to_ntstatus(result
);
6471 * Establish trust relationship to a trusting domain.
6472 * Interdomain account must already be created on remote PDC.
6474 * @param c A net_context structure.
6475 * @param argc Standard argc.
6476 * @param argv Standard argv without initial components.
6478 * @return Integer status (0 means success).
6481 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
6484 struct cli_state
*cli
= NULL
;
6485 struct sockaddr_storage server_ss
;
6486 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6487 struct policy_handle connect_hnd
;
6488 TALLOC_CTX
*mem_ctx
;
6489 NTSTATUS nt_status
, result
;
6490 struct dom_sid
*domain_sid
;
6495 union lsa_PolicyInformation
*info
= NULL
;
6496 struct dcerpc_binding_handle
*b
;
6499 * Connect to \\server\ipc$ as 'our domain' account with password
6502 if (argc
!= 1 || c
->display_usage
) {
6505 _("net rpc trustdom establish <domain_name>\n"));
6509 domain_name
= smb_xstrdup(argv
[0]);
6510 if (!strupper_m(domain_name
)) {
6511 SAFE_FREE(domain_name
);
6515 /* account name used at first is our domain's name with '$' */
6516 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
6519 if (!strupper_m(acct_name
)) {
6520 SAFE_FREE(domain_name
);
6521 SAFE_FREE(acct_name
);
6526 * opt_workgroup will be used by connection functions further,
6527 * hence it should be set to remote domain name instead of ours
6529 if (c
->opt_workgroup
) {
6530 c
->opt_workgroup
= smb_xstrdup(domain_name
);
6533 c
->opt_user_name
= acct_name
;
6535 /* find the domain controller */
6536 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
6537 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
6541 /* connect to ipc$ as username/password */
6542 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
6543 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
6545 /* Is it trusting domain account for sure ? */
6546 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6547 nt_errstr(nt_status
)));
6551 /* store who we connected to */
6553 saf_store( domain_name
, pdc_name
);
6556 * Connect to \\server\ipc$ again (this time anonymously)
6559 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
6562 if (NT_STATUS_IS_ERR(nt_status
)) {
6563 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6564 domain_name
, nt_errstr(nt_status
)));
6568 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
6569 "domain %s", domain_name
))) {
6570 DEBUG(0, ("talloc_init() failed\n"));
6575 /* Make sure we're talking to a proper server */
6577 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
6578 if (!NT_STATUS_IS_OK(nt_status
)) {
6580 talloc_destroy(mem_ctx
);
6585 * Call LsaOpenPolicy and LsaQueryInfo
6588 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6590 if (!NT_STATUS_IS_OK(nt_status
)) {
6591 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
6593 talloc_destroy(mem_ctx
);
6597 b
= pipe_hnd
->binding_handle
;
6599 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
6601 if (NT_STATUS_IS_ERR(nt_status
)) {
6602 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6603 nt_errstr(nt_status
)));
6605 talloc_destroy(mem_ctx
);
6609 /* Querying info level 5 */
6611 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6613 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6616 if (NT_STATUS_IS_ERR(nt_status
)) {
6617 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6618 nt_errstr(nt_status
)));
6620 talloc_destroy(mem_ctx
);
6623 if (NT_STATUS_IS_ERR(result
)) {
6624 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6625 nt_errstr(result
)));
6627 talloc_destroy(mem_ctx
);
6631 domain_sid
= info
->account_domain
.sid
;
6633 /* There should be actually query info level 3 (following nt serv behaviour),
6634 but I still don't know if it's _really_ necessary */
6637 * Store the password in secrets db
6640 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
6641 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6643 talloc_destroy(mem_ctx
);
6648 * Close the pipes and clean up
6651 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
6652 if (NT_STATUS_IS_ERR(nt_status
)) {
6653 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6654 nt_errstr(nt_status
)));
6656 talloc_destroy(mem_ctx
);
6662 talloc_destroy(mem_ctx
);
6664 d_printf(_("Trust to domain %s established\n"), domain_name
);
6669 * Revoke trust relationship to the remote domain.
6671 * @param c A net_context structure.
6672 * @param argc Standard argc.
6673 * @param argv Standard argv without initial components.
6675 * @return Integer status (0 means success).
6678 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
6684 if (argc
< 1 || c
->display_usage
) {
6687 _("net rpc trustdom revoke <domain_name>\n"
6688 " Revoke trust relationship\n"
6689 " domain_name\tName of domain to revoke trust\n"));
6693 /* generate upper cased domain name */
6694 domain_name
= smb_xstrdup(argv
[0]);
6695 if (!strupper_m(domain_name
)) {
6696 SAFE_FREE(domain_name
);
6700 /* delete password of the trust */
6701 if (!pdb_del_trusteddom_pw(domain_name
)) {
6702 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6709 SAFE_FREE(domain_name
);
6713 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
6714 const struct dom_sid
*domain_sid
,
6715 const char *domain_name
,
6716 struct cli_state
*cli
,
6717 struct rpc_pipe_client
*pipe_hnd
,
6718 TALLOC_CTX
*mem_ctx
,
6723 if (!sid_to_fstring(str_sid
, domain_sid
)) {
6724 return NT_STATUS_UNSUCCESSFUL
;
6726 d_printf("%s\n", str_sid
);
6727 return NT_STATUS_OK
;
6730 static void print_trusted_domain(struct dom_sid
*dom_sid
, const char *trusted_dom_name
)
6734 /* convert sid into ascii string */
6735 sid_to_fstring(ascii_sid
, dom_sid
);
6737 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
6740 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
6741 TALLOC_CTX
*mem_ctx
,
6742 struct policy_handle
*pol
,
6743 struct dom_sid dom_sid
,
6744 const char *trusted_dom_name
)
6746 NTSTATUS nt_status
, result
;
6747 union lsa_TrustedDomainInfo
*info
= NULL
;
6748 char *cleartextpwd
= NULL
;
6749 DATA_BLOB session_key
;
6750 DATA_BLOB data
= data_blob_null
;
6751 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6753 nt_status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
6756 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
6759 if (NT_STATUS_IS_ERR(nt_status
)) {
6760 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6761 nt_errstr(nt_status
)));
6764 if (NT_STATUS_IS_ERR(result
)) {
6766 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6767 nt_errstr(result
)));
6771 data
= data_blob(info
->password
.password
->data
,
6772 info
->password
.password
->length
);
6774 nt_status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
6775 if (!NT_STATUS_IS_OK(nt_status
)) {
6776 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(nt_status
)));
6780 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key
);
6781 data_blob_free(&session_key
);
6783 if (cleartextpwd
== NULL
) {
6784 DEBUG(0,("retrieved NULL password\n"));
6785 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6789 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
6790 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6791 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6795 #ifdef DEBUG_PASSWORD
6796 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6797 "password: [%s]\n", trusted_dom_name
,
6798 sid_string_dbg(&dom_sid
), cleartextpwd
));
6802 SAFE_FREE(cleartextpwd
);
6803 data_blob_free(&data
);
6808 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
6811 /* common variables */
6812 TALLOC_CTX
* mem_ctx
;
6813 struct cli_state
*cli
= NULL
;
6814 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6815 NTSTATUS nt_status
, result
;
6816 const char *domain_name
= NULL
;
6817 struct policy_handle connect_hnd
;
6818 union lsa_PolicyInformation
*info
= NULL
;
6820 /* trusted domains listing variables */
6821 unsigned int enum_ctx
= 0;
6823 struct lsa_DomainList dom_list
;
6825 struct dcerpc_binding_handle
*b
;
6827 if (c
->display_usage
) {
6829 "net rpc trustdom vampire\n"
6832 _("Vampire trust relationship from remote server"));
6837 * Listing trusted domains (stored in secrets.tdb, if local)
6840 mem_ctx
= talloc_init("trust relationships vampire");
6843 * set domain and pdc name to local samba server (default)
6844 * or to remote one given in command line
6847 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
6848 domain_name
= c
->opt_workgroup
;
6849 c
->opt_target_workgroup
= c
->opt_workgroup
;
6851 fstrcpy(pdc_name
, lp_netbios_name());
6852 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6853 c
->opt_target_workgroup
= domain_name
;
6856 /* open \PIPE\lsarpc and open policy handle */
6857 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6858 if (!NT_STATUS_IS_OK(nt_status
)) {
6859 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6860 nt_errstr(nt_status
)));
6861 talloc_destroy(mem_ctx
);
6865 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6867 if (!NT_STATUS_IS_OK(nt_status
)) {
6868 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6869 nt_errstr(nt_status
) ));
6871 talloc_destroy(mem_ctx
);
6875 b
= pipe_hnd
->binding_handle
;
6877 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6879 if (NT_STATUS_IS_ERR(nt_status
)) {
6880 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6881 nt_errstr(nt_status
)));
6883 talloc_destroy(mem_ctx
);
6887 /* query info level 5 to obtain sid of a domain being queried */
6888 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6890 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6894 if (NT_STATUS_IS_ERR(nt_status
)) {
6895 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6896 nt_errstr(nt_status
)));
6898 talloc_destroy(mem_ctx
);
6901 if (NT_STATUS_IS_ERR(result
)) {
6902 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6903 nt_errstr(result
)));
6905 talloc_destroy(mem_ctx
);
6910 * Keep calling LsaEnumTrustdom over opened pipe until
6911 * the end of enumeration is reached
6914 d_printf(_("Vampire trusted domains:\n\n"));
6917 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
6923 if (NT_STATUS_IS_ERR(nt_status
)) {
6924 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6925 nt_errstr(nt_status
)));
6927 talloc_destroy(mem_ctx
);
6930 if (NT_STATUS_IS_ERR(result
)) {
6932 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6933 nt_errstr(result
)));
6935 talloc_destroy(mem_ctx
);
6940 for (i
= 0; i
< dom_list
.count
; i
++) {
6942 print_trusted_domain(dom_list
.domains
[i
].sid
,
6943 dom_list
.domains
[i
].name
.string
);
6945 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6946 *dom_list
.domains
[i
].sid
,
6947 dom_list
.domains
[i
].name
.string
);
6948 if (!NT_STATUS_IS_OK(nt_status
)) {
6950 talloc_destroy(mem_ctx
);
6956 * in case of no trusted domains say something rather
6957 * than just display blank line
6959 if (!dom_list
.count
) d_printf(_("none\n"));
6961 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6963 /* close this connection before doing next one */
6964 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
6965 if (NT_STATUS_IS_ERR(nt_status
)) {
6966 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6967 nt_errstr(nt_status
)));
6969 talloc_destroy(mem_ctx
);
6973 /* close lsarpc pipe and connection to IPC$ */
6976 talloc_destroy(mem_ctx
);
6980 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6982 /* common variables */
6983 TALLOC_CTX
* mem_ctx
;
6984 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6985 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6986 NTSTATUS nt_status
, result
;
6987 const char *domain_name
= NULL
;
6988 struct dom_sid
*queried_dom_sid
;
6989 int ascii_dom_name_len
;
6990 struct policy_handle connect_hnd
;
6991 union lsa_PolicyInformation
*info
= NULL
;
6992 struct dcerpc_binding_handle
*b
= NULL
;
6994 /* trusted domains listing variables */
6995 unsigned int num_domains
, enum_ctx
= 0;
6997 struct lsa_DomainList dom_list
;
7001 /* trusting domains listing variables */
7002 struct policy_handle domain_hnd
;
7003 struct samr_SamArray
*trusts
= NULL
;
7005 if (c
->display_usage
) {
7007 "net rpc trustdom list\n"
7010 _("List incoming and outgoing trust relationships"));
7015 * Listing trusted domains (stored in secrets.tdb, if local)
7018 mem_ctx
= talloc_init("trust relationships listing");
7021 * set domain and pdc name to local samba server (default)
7022 * or to remote one given in command line
7025 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
7026 domain_name
= c
->opt_workgroup
;
7027 c
->opt_target_workgroup
= c
->opt_workgroup
;
7029 fstrcpy(pdc_name
, lp_netbios_name());
7030 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
7031 c
->opt_target_workgroup
= domain_name
;
7034 /* open \PIPE\lsarpc and open policy handle */
7035 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
7036 if (!NT_STATUS_IS_OK(nt_status
)) {
7037 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
7038 nt_errstr(nt_status
)));
7039 talloc_destroy(mem_ctx
);
7043 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
7045 if (!NT_STATUS_IS_OK(nt_status
)) {
7046 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
7047 nt_errstr(nt_status
) ));
7049 talloc_destroy(mem_ctx
);
7053 b
= pipe_hnd
->binding_handle
;
7055 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
7057 if (NT_STATUS_IS_ERR(nt_status
)) {
7058 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
7059 nt_errstr(nt_status
)));
7061 talloc_destroy(mem_ctx
);
7065 /* query info level 5 to obtain sid of a domain being queried */
7066 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
7068 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
7072 if (NT_STATUS_IS_ERR(nt_status
)) {
7073 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7074 nt_errstr(nt_status
)));
7076 talloc_destroy(mem_ctx
);
7079 if (NT_STATUS_IS_ERR(result
)) {
7080 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7081 nt_errstr(result
)));
7083 talloc_destroy(mem_ctx
);
7087 queried_dom_sid
= info
->account_domain
.sid
;
7090 * Keep calling LsaEnumTrustdom over opened pipe until
7091 * the end of enumeration is reached
7094 d_printf(_("Trusted domains list:\n\n"));
7096 found_domain
= false;
7099 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
7105 if (NT_STATUS_IS_ERR(nt_status
)) {
7106 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7107 nt_errstr(nt_status
)));
7109 talloc_destroy(mem_ctx
);
7112 if (NT_STATUS_IS_ERR(result
)) {
7113 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7114 nt_errstr(result
)));
7116 talloc_destroy(mem_ctx
);
7121 for (i
= 0; i
< dom_list
.count
; i
++) {
7122 print_trusted_domain(dom_list
.domains
[i
].sid
,
7123 dom_list
.domains
[i
].name
.string
);
7124 found_domain
= true;
7128 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
7131 * in case of no trusted domains say something rather
7132 * than just display blank line
7134 if (!found_domain
) {
7135 d_printf(_("none\n"));
7138 /* close this connection before doing next one */
7139 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7140 if (NT_STATUS_IS_ERR(nt_status
)) {
7141 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
7142 nt_errstr(nt_status
)));
7144 talloc_destroy(mem_ctx
);
7148 TALLOC_FREE(pipe_hnd
);
7151 * Listing trusting domains (stored in passdb backend, if local)
7154 d_printf(_("\nTrusting domains list:\n\n"));
7157 * Open \PIPE\samr and get needed policy handles
7159 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
,
7161 if (!NT_STATUS_IS_OK(nt_status
)) {
7162 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
7164 talloc_destroy(mem_ctx
);
7168 b
= pipe_hnd
->binding_handle
;
7171 nt_status
= dcerpc_samr_Connect2(b
, mem_ctx
,
7173 SAMR_ACCESS_LOOKUP_DOMAIN
,
7176 if (!NT_STATUS_IS_OK(nt_status
)) {
7177 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7178 nt_errstr(nt_status
)));
7180 talloc_destroy(mem_ctx
);
7183 if (!NT_STATUS_IS_OK(result
)) {
7185 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7186 nt_errstr(result
)));
7188 talloc_destroy(mem_ctx
);
7192 /* SamrOpenDomain - we have to open domain policy handle in order to be
7193 able to enumerate accounts*/
7194 nt_status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
7196 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
7200 if (!NT_STATUS_IS_OK(nt_status
)) {
7201 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7202 nt_errstr(nt_status
)));
7204 talloc_destroy(mem_ctx
);
7207 if (!NT_STATUS_IS_OK(result
)) {
7209 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7210 nt_errstr(result
)));
7212 talloc_destroy(mem_ctx
);
7217 * perform actual enumeration
7220 found_domain
= false;
7222 enum_ctx
= 0; /* reset enumeration context from last enumeration */
7225 nt_status
= dcerpc_samr_EnumDomainUsers(b
, mem_ctx
,
7233 if (NT_STATUS_IS_ERR(nt_status
)) {
7234 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7235 nt_errstr(nt_status
)));
7237 talloc_destroy(mem_ctx
);
7240 if (NT_STATUS_IS_ERR(result
)) {
7242 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7243 nt_errstr(result
)));
7245 talloc_destroy(mem_ctx
);
7249 for (i
= 0; i
< num_domains
; i
++) {
7251 char *str
= discard_const_p(char, trusts
->entries
[i
].name
.string
);
7253 found_domain
= true;
7256 * get each single domain's sid (do we _really_ need this ?):
7257 * 1) connect to domain's pdc
7258 * 2) query the pdc for domain's sid
7261 /* get rid of '$' tail */
7262 ascii_dom_name_len
= strlen(str
);
7263 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
7264 str
[ascii_dom_name_len
- 1] = '\0';
7266 /* set opt_* variables to remote domain */
7267 if (!strupper_m(str
)) {
7269 talloc_destroy(mem_ctx
);
7272 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
7273 c
->opt_target_workgroup
= c
->opt_workgroup
;
7275 d_printf("%-20s", str
);
7277 /* connect to remote domain controller */
7278 nt_status
= net_make_ipc_connection(c
,
7279 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
7281 if (NT_STATUS_IS_OK(nt_status
)) {
7282 /* query for domain's sid */
7283 if (run_rpc_command(
7285 &ndr_table_lsarpc
, 0,
7286 rpc_query_domain_sid
, argc
,
7288 d_printf(_("strange - couldn't get domain's sid\n"));
7290 cli_shutdown(remote_cli
);
7293 d_fprintf(stderr
, _("domain controller is not "
7294 "responding: %s\n"),
7295 nt_errstr(nt_status
));
7296 d_printf(_("couldn't get domain's sid\n"));
7300 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
7302 if (!found_domain
) {
7306 /* close opened samr and domain policy handles */
7307 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_hnd
, &result
);
7308 if (!NT_STATUS_IS_OK(nt_status
)) {
7309 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
7312 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7313 if (!NT_STATUS_IS_OK(nt_status
)) {
7314 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
7317 /* close samr pipe and connection to IPC$ */
7320 talloc_destroy(mem_ctx
);
7325 * Entrypoint for 'net rpc trustdom' code.
7327 * @param argc Standard argc.
7328 * @param argv Standard argv without initial components.
7330 * @return Integer status (0 means success).
7333 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
7335 struct functable func
[] = {
7340 N_("Add trusting domain's account"),
7341 N_("net rpc trustdom add\n"
7342 " Add trusting domain's account")
7348 N_("Remove trusting domain's account"),
7349 N_("net rpc trustdom del\n"
7350 " Remove trusting domain's account")
7354 rpc_trustdom_establish
,
7356 N_("Establish outgoing trust relationship"),
7357 N_("net rpc trustdom establish\n"
7358 " Establish outgoing trust relationship")
7362 rpc_trustdom_revoke
,
7364 N_("Revoke outgoing trust relationship"),
7365 N_("net rpc trustdom revoke\n"
7366 " Revoke outgoing trust relationship")
7372 N_("List in- and outgoing domain trusts"),
7373 N_("net rpc trustdom list\n"
7374 " List in- and outgoing domain trusts")
7378 rpc_trustdom_vampire
,
7380 N_("Vampire trusts from remote server"),
7381 N_("net rpc trustdom vampire\n"
7382 " Vampire trusts from remote server")
7384 {NULL
, NULL
, 0, NULL
, NULL
}
7387 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
7391 * Check if a server will take rpc commands
7392 * @param flags Type of server to connect to (PDC, DMB, localhost)
7393 * if the host is not explicitly specified
7394 * @return bool (true means rpc supported)
7396 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
7398 struct cli_state
*cli
;
7400 struct sockaddr_storage server_ss
;
7401 char *server_name
= NULL
;
7404 /* flags (i.e. server type) may depend on command */
7405 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
7408 status
= cli_connect_nb(server_name
, &server_ss
, 0, 0x20,
7409 lp_netbios_name(), SMB_SIGNING_IPC_DEFAULT
,
7411 if (!NT_STATUS_IS_OK(status
)) {
7414 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
, PROTOCOL_CORE
,
7416 if (!NT_STATUS_IS_OK(status
))
7418 if (smbXcli_conn_protocol(cli
->conn
) < PROTOCOL_NT1
)
7427 /* dump sam database via samsync rpc calls */
7428 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
7429 if (c
->display_usage
) {
7434 _("Dump remote SAM database"));
7438 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
,
7439 NET_FLAGS_ANONYMOUS
,
7440 rpc_samdump_internals
, argc
, argv
);
7443 /* syncronise sam database via samsync rpc calls */
7444 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
7446 struct functable func
[] = {
7451 N_("Dump remote SAM database to ldif"),
7452 N_("net rpc vampire ldif\n"
7453 " Dump remote SAM database to LDIF file or "
7460 N_("Dump remote SAM database to Kerberos Keytab"),
7461 N_("net rpc vampire keytab\n"
7462 " Dump remote SAM database to Kerberos keytab "
7469 N_("Dump remote SAM database to passdb"),
7470 N_("net rpc vampire passdb\n"
7471 " Dump remote SAM database to passdb")
7474 {NULL
, NULL
, 0, NULL
, NULL
}
7478 if (c
->display_usage
) {
7483 _("Vampire remote SAM database"));
7487 return rpc_vampire_passdb(c
, argc
, argv
);
7490 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
7494 * Migrate everything from a print server.
7496 * @param c A net_context structure.
7497 * @param argc Standard main() style argc.
7498 * @param argv Standard main() style argv. Initial components are already
7501 * @return A shell status integer (0 for success).
7503 * The order is important !
7504 * To successfully add drivers the print queues have to exist !
7505 * Applying ACLs should be the last step, because you're easily locked out.
7508 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
7513 if (c
->display_usage
) {
7515 "net rpc printer migrate all\n"
7518 _("Migrate everything from a print server"));
7523 d_printf(_("no server to migrate\n"));
7527 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7528 rpc_printer_migrate_printers_internals
, argc
,
7533 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7534 rpc_printer_migrate_drivers_internals
, argc
,
7539 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7540 rpc_printer_migrate_forms_internals
, argc
, argv
);
7544 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7545 rpc_printer_migrate_settings_internals
, argc
,
7550 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7551 rpc_printer_migrate_security_internals
, argc
,
7557 * Migrate print drivers from a print server.
7559 * @param c A net_context structure.
7560 * @param argc Standard main() style argc.
7561 * @param argv Standard main() style argv. Initial components are already
7564 * @return A shell status integer (0 for success).
7566 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
7569 if (c
->display_usage
) {
7571 "net rpc printer migrate drivers\n"
7574 _("Migrate print-drivers from a print-server"));
7579 d_printf(_("no server to migrate\n"));
7583 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7584 rpc_printer_migrate_drivers_internals
,
7589 * Migrate print-forms from a print-server.
7591 * @param c A net_context structure.
7592 * @param argc Standard main() style argc.
7593 * @param argv Standard main() style argv. Initial components are already
7596 * @return A shell status integer (0 for success).
7598 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
7601 if (c
->display_usage
) {
7603 "net rpc printer migrate forms\n"
7606 _("Migrate print-forms from a print-server"));
7611 d_printf(_("no server to migrate\n"));
7615 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7616 rpc_printer_migrate_forms_internals
,
7621 * Migrate printers from a print-server.
7623 * @param c A net_context structure.
7624 * @param argc Standard main() style argc.
7625 * @param argv Standard main() style argv. Initial components are already
7628 * @return A shell status integer (0 for success).
7630 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
7633 if (c
->display_usage
) {
7635 "net rpc printer migrate printers\n"
7638 _("Migrate printers from a print-server"));
7643 d_printf(_("no server to migrate\n"));
7647 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7648 rpc_printer_migrate_printers_internals
,
7653 * Migrate printer-ACLs from a print-server
7655 * @param c A net_context structure.
7656 * @param argc Standard main() style argc.
7657 * @param argv Standard main() style argv. Initial components are already
7660 * @return A shell status integer (0 for success).
7662 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
7665 if (c
->display_usage
) {
7667 "net rpc printer migrate security\n"
7670 _("Migrate printer-ACLs from a print-server"));
7675 d_printf(_("no server to migrate\n"));
7679 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7680 rpc_printer_migrate_security_internals
,
7685 * Migrate printer-settings from a print-server.
7687 * @param c A net_context structure.
7688 * @param argc Standard main() style argc.
7689 * @param argv Standard main() style argv. Initial components are already
7692 * @return A shell status integer (0 for success).
7694 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
7697 if (c
->display_usage
) {
7699 "net rpc printer migrate settings\n"
7702 _("Migrate printer-settings from a "
7708 d_printf(_("no server to migrate\n"));
7712 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7713 rpc_printer_migrate_settings_internals
,
7718 * 'net rpc printer' entrypoint.
7720 * @param c A net_context structure.
7721 * @param argc Standard main() style argc.
7722 * @param argv Standard main() style argv. Initial components are already
7726 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
7729 /* ouch: when addriver and setdriver are called from within
7730 rpc_printer_migrate_drivers_internals, the printer-queue already
7733 struct functable func
[] = {
7736 rpc_printer_migrate_all
,
7738 N_("Migrate all from remote to local print server"),
7739 N_("net rpc printer migrate all\n"
7740 " Migrate all from remote to local print server")
7744 rpc_printer_migrate_drivers
,
7746 N_("Migrate drivers to local server"),
7747 N_("net rpc printer migrate drivers\n"
7748 " Migrate drivers to local server")
7752 rpc_printer_migrate_forms
,
7754 N_("Migrate froms to local server"),
7755 N_("net rpc printer migrate forms\n"
7756 " Migrate froms to local server")
7760 rpc_printer_migrate_printers
,
7762 N_("Migrate printers to local server"),
7763 N_("net rpc printer migrate printers\n"
7764 " Migrate printers to local server")
7768 rpc_printer_migrate_security
,
7770 N_("Mirgate printer ACLs to local server"),
7771 N_("net rpc printer migrate security\n"
7772 " Mirgate printer ACLs to local server")
7776 rpc_printer_migrate_settings
,
7778 N_("Migrate printer settings to local server"),
7779 N_("net rpc printer migrate settings\n"
7780 " Migrate printer settings to local server")
7782 {NULL
, NULL
, 0, NULL
, NULL
}
7785 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
7790 * List printers 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_list(struct net_context
*c
, int argc
, const char **argv
)
7801 if (c
->display_usage
) {
7803 "net rpc printer list\n"
7806 _("List printers on a remote RPC server"));
7810 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7811 rpc_printer_list_internals
,
7816 * List printer-drivers on a remote RPC server.
7818 * @param c A net_context structure.
7819 * @param argc Standard main() style argc.
7820 * @param argv Standard main() style argv. Initial components are already
7823 * @return A shell status integer (0 for success).
7825 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
7828 if (c
->display_usage
) {
7830 "net rpc printer driver\n"
7833 _("List printer-drivers on a remote RPC server"));
7837 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7838 rpc_printer_driver_list_internals
,
7843 * Publish printer in ADS via MSRPC.
7845 * @param c A net_context structure.
7846 * @param argc Standard main() style argc.
7847 * @param argv Standard main() style argv. Initial components are already
7850 * @return A shell status integer (0 for success).
7852 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
7855 if (c
->display_usage
) {
7857 "net rpc printer publish publish\n"
7860 _("Publish printer in ADS via MSRPC"));
7864 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7865 rpc_printer_publish_publish_internals
,
7870 * Update 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_update(struct net_context
*c
, int argc
, const char **argv
)
7881 if (c
->display_usage
) {
7883 "net rpc printer publish update\n"
7886 _("Update printer in ADS via MSRPC"));
7890 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7891 rpc_printer_publish_update_internals
,
7896 * UnPublish printer in ADS via MSRPC.
7898 * @param c A net_context structure.
7899 * @param argc Standard main() style argc.
7900 * @param argv Standard main() style argv. Initial components are already
7903 * @return A shell status integer (0 for success).
7905 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
7908 if (c
->display_usage
) {
7910 "net rpc printer publish unpublish\n"
7913 _("UnPublish printer in ADS via MSRPC"));
7917 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7918 rpc_printer_publish_unpublish_internals
,
7923 * List published printers via MSRPC.
7925 * @param c A net_context structure.
7926 * @param argc Standard main() style argc.
7927 * @param argv Standard main() style argv. Initial components are already
7930 * @return A shell status integer (0 for success).
7932 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
7935 if (c
->display_usage
) {
7937 "net rpc printer publish list\n"
7940 _("List published printers via MSRPC"));
7944 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7945 rpc_printer_publish_list_internals
,
7951 * Publish printer in ADS.
7953 * @param c A net_context structure.
7954 * @param argc Standard main() style argc.
7955 * @param argv Standard main() style argv. Initial components are already
7958 * @return A shell status integer (0 for success).
7960 static int rpc_printer_publish(struct net_context
*c
, int argc
,
7964 struct functable func
[] = {
7967 rpc_printer_publish_publish
,
7969 N_("Publish printer in AD"),
7970 N_("net rpc printer publish publish\n"
7971 " Publish printer in AD")
7975 rpc_printer_publish_update
,
7977 N_("Update printer in AD"),
7978 N_("net rpc printer publish update\n"
7979 " Update printer in AD")
7983 rpc_printer_publish_unpublish
,
7985 N_("Unpublish printer"),
7986 N_("net rpc printer publish unpublish\n"
7987 " Unpublish printer")
7991 rpc_printer_publish_list
,
7993 N_("List published printers"),
7994 N_("net rpc printer publish list\n"
7995 " List published printers")
7997 {NULL
, NULL
, 0, NULL
, NULL
}
8001 if (c
->display_usage
) {
8002 d_printf(_("Usage:\n"));
8003 d_printf(_("net rpc printer publish\n"
8004 " List published printers\n"
8005 " Alias of net rpc printer publish "
8007 net_display_usage_from_functable(func
);
8010 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
8011 rpc_printer_publish_list_internals
,
8015 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
8021 * Display rpc printer help page.
8023 * @param c A net_context structure.
8024 * @param argc Standard main() style argc.
8025 * @param argv Standard main() style argv. Initial components are already
8028 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
8030 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
8031 "\tlists all printers on print-server\n\n"));
8032 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
8033 "\tlists all printer-drivers on print-server\n\n"));
8034 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
8035 "\tpublishes printer settings in Active Directory\n"
8036 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
8037 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
8038 "\n\tmigrates printers from remote to local server\n\n"));
8039 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
8040 "\n\tmigrates printer-settings from remote to local server\n\n"));
8041 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
8042 "\n\tmigrates printer-drivers from remote to local server\n\n"));
8043 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
8044 "\n\tmigrates printer-forms from remote to local server\n\n"));
8045 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
8046 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
8047 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
8048 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
8049 "\tremote to local print-server\n\n"));
8050 net_common_methods_usage(c
, argc
, argv
);
8051 net_common_flags_usage(c
, argc
, argv
);
8053 "\t-v or --verbose\t\t\tgive verbose output\n"
8054 "\t --destination\t\tmigration target server (default: localhost)\n"));
8060 * 'net rpc printer' entrypoint.
8062 * @param c A net_context structure.
8063 * @param argc Standard main() style argc.
8064 * @param argv Standard main() style argv. Initial components are already
8067 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
8069 struct functable func
[] = {
8074 N_("List all printers on print server"),
8075 N_("net rpc printer list\n"
8076 " List all printers on print server")
8080 rpc_printer_migrate
,
8082 N_("Migrate printer to local server"),
8083 N_("net rpc printer migrate\n"
8084 " Migrate printer to local server")
8088 rpc_printer_driver_list
,
8090 N_("List printer drivers"),
8091 N_("net rpc printer driver\n"
8092 " List printer drivers")
8096 rpc_printer_publish
,
8098 N_("Publish printer in AD"),
8099 N_("net rpc printer publish\n"
8100 " Publish printer in AD")
8102 {NULL
, NULL
, 0, NULL
, NULL
}
8106 if (c
->display_usage
) {
8107 d_printf(_("Usage:\n"));
8108 d_printf(_("net rpc printer\n"
8109 " List printers\n"));
8110 net_display_usage_from_functable(func
);
8113 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
8114 rpc_printer_list_internals
,
8118 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
8122 * 'net rpc' entrypoint.
8124 * @param c A net_context structure.
8125 * @param argc Standard main() style argc.
8126 * @param argv Standard main() style argv. Initial components are already
8130 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
8132 NET_API_STATUS status
;
8134 struct functable func
[] = {
8139 N_("Modify global audit settings"),
8140 N_("net rpc audit\n"
8141 " Modify global audit settings")
8147 N_("Show basic info about a domain"),
8149 " Show basic info about a domain")
8155 N_("Join a domain"),
8163 N_("Join a domain created in server manager"),
8164 N_("net rpc oldjoin\n"
8165 " Join a domain created in server manager")
8171 N_("Test that a join is valid"),
8172 N_("net rpc testjoin\n"
8173 " Test that a join is valid")
8179 N_("List/modify users"),
8181 " List/modify users")
8187 N_("Change a user password"),
8188 N_("net rpc password\n"
8189 " Change a user password\n"
8190 " Alias for net rpc user password")
8196 N_("List/modify groups"),
8197 N_("net rpc group\n"
8198 " List/modify groups")
8204 N_("List/modify shares"),
8205 N_("net rpc share\n"
8206 " List/modify shares")
8212 N_("List open files"),
8220 N_("List/modify printers"),
8221 N_("net rpc printer\n"
8222 " List/modify printers")
8226 net_rpc_changetrustpw
,
8228 N_("Change trust account password"),
8229 N_("net rpc changetrustpw\n"
8230 " Change trust account password")
8236 N_("Modify domain trusts"),
8237 N_("net rpc trustdom\n"
8238 " Modify domain trusts")
8244 N_("Abort a remote shutdown"),
8245 N_("net rpc abortshutdown\n"
8246 " Abort a remote shutdown")
8252 N_("Shutdown a remote server"),
8253 N_("net rpc shutdown\n"
8254 " Shutdown a remote server")
8260 N_("Dump SAM data of remote NT PDC"),
8261 N_("net rpc samdump\n"
8262 " Dump SAM data of remote NT PDC")
8268 N_("Sync a remote NT PDC's data into local passdb"),
8269 N_("net rpc vampire\n"
8270 " Sync a remote NT PDC's data into local passdb")
8276 N_("Fetch the domain sid into local secrets.tdb"),
8277 N_("net rpc getsid\n"
8278 " Fetch the domain sid into local secrets.tdb")
8284 N_("Manage privileges assigned to SID"),
8285 N_("net rpc rights\n"
8286 " Manage privileges assigned to SID")
8292 N_("Start/stop/query remote services"),
8293 N_("net rpc service\n"
8294 " Start/stop/query remote services")
8300 N_("Manage registry hives"),
8301 N_("net rpc registry\n"
8302 " Manage registry hives")
8308 N_("Open interactive shell on remote server"),
8309 N_("net rpc shell\n"
8310 " Open interactive shell on remote server")
8316 N_("Manage trusts"),
8317 N_("net rpc trust\n"
8324 N_("Configure a remote samba server"),
8326 " Configure a remote samba server")
8328 {NULL
, NULL
, 0, NULL
, NULL
}
8331 status
= libnetapi_net_init(&c
->netapi_ctx
);
8335 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
8336 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
8337 if (c
->opt_kerberos
) {
8338 libnetapi_set_use_kerberos(c
->netapi_ctx
);
8340 if (c
->opt_ccache
) {
8341 libnetapi_set_use_ccache(c
->netapi_ctx
);
8344 return net_run_function(c
, argc
, argv
, "net rpc", func
);