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 "libsmb/namequery.h"
26 #include "rpc_client/cli_pipe.h"
27 #include "../libcli/auth/libcli_auth.h"
28 #include "../librpc/gen_ndr/ndr_samr_c.h"
29 #include "rpc_client/cli_samr.h"
30 #include "rpc_client/init_samr.h"
31 #include "../librpc/gen_ndr/ndr_lsa_c.h"
32 #include "rpc_client/cli_lsarpc.h"
33 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
34 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
35 #include "../librpc/gen_ndr/ndr_spoolss.h"
36 #include "../librpc/gen_ndr/ndr_initshutdown_c.h"
37 #include "../librpc/gen_ndr/ndr_winreg_c.h"
39 #include "lib/netapi/netapi.h"
40 #include "lib/netapi/netapi_net.h"
41 #include "librpc/gen_ndr/libnet_join.h"
42 #include "libnet/libnet_join.h"
43 #include "rpc_client/init_lsa.h"
44 #include "../libcli/security/security.h"
45 #include "libsmb/libsmb.h"
47 #include "nsswitch/libwbclient/wbclient.h"
49 #include "../libcli/smb/smbXcli_base.h"
50 #include "libsmb/dsgetdcname.h"
51 #include "lib/util/string_wrappers.h"
53 static int net_mode_share
;
54 static NTSTATUS
sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
59 * @brief RPC based subcommands for the 'net' utility.
61 * This file should contain much of the functionality that used to
62 * be found in rpcclient, except that the commands should change
63 * less often, and the functionality should be sane (the user is not
64 * expected to know a rid/sid before they conduct an operation etc.)
66 * @todo Perhaps eventually these should be split out into a number
67 * of files, as this could get quite big.
72 * Many of the RPC functions need the domain sid. This function gets
73 * it at the start of every run
75 * @param cli A cli_state already connected to the remote machine
77 * @return The Domain SID of the remote machine.
80 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
81 struct dom_sid
**domain_sid
,
82 const char **domain_name
)
84 struct rpc_pipe_client
*lsa_pipe
= NULL
;
85 struct policy_handle pol
;
86 NTSTATUS status
, result
;
87 union lsa_PolicyInformation
*info
= NULL
;
88 struct dcerpc_binding_handle
*b
;
90 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
92 if (!NT_STATUS_IS_OK(status
)) {
93 d_fprintf(stderr
, _("Could not initialise lsa pipe\n"));
97 b
= lsa_pipe
->binding_handle
;
99 status
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
100 SEC_FLAG_MAXIMUM_ALLOWED
,
102 if (!NT_STATUS_IS_OK(status
)) {
103 d_fprintf(stderr
, "open_policy %s: %s\n",
109 status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
111 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
114 if (any_nt_status_not_ok(status
, result
, &status
)) {
115 d_fprintf(stderr
, "lsaquery %s: %s\n",
121 *domain_name
= info
->account_domain
.name
.string
;
122 *domain_sid
= info
->account_domain
.sid
;
124 dcerpc_lsa_Close(b
, mem_ctx
, &pol
, &result
);
125 TALLOC_FREE(lsa_pipe
);
131 * Run a single RPC command, from start to finish.
133 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
134 * @param conn_flag a NET_FLAG_ combination. Passed to
135 * net_make_ipc_connection.
136 * @param argc Standard main() style argc.
137 * @param argv Standard main() style argv. Initial components are already
139 * @return A shell status integer (0 for success).
142 int run_rpc_command(struct net_context
*c
,
143 struct cli_state
*cli_arg
,
144 const struct ndr_interface_table
*table
,
150 struct cli_state
*cli
= NULL
;
151 struct rpc_pipe_client
*pipe_hnd
= NULL
;
154 struct dom_sid
*domain_sid
;
155 const char *domain_name
;
158 /* make use of cli_state handed over as an argument, if possible */
160 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
161 if (!NT_STATUS_IS_OK(nt_status
)) {
162 DEBUG(1, ("failed to make ipc connection: %s\n",
163 nt_errstr(nt_status
)));
176 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
177 DEBUG(0, ("talloc_init() failed\n"));
181 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
183 if (!NT_STATUS_IS_OK(nt_status
)) {
187 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
188 if (lp_client_schannel()
189 && (ndr_syntax_id_equal(&table
->syntax_id
,
190 &ndr_table_netlogon
.syntax_id
))) {
191 const char *remote_name
=
192 smbXcli_conn_remote_name(cli
->conn
);
193 const struct sockaddr_storage
*remote_sockaddr
=
194 smbXcli_conn_remote_sockaddr(cli
->conn
);
196 /* Always try and create an schannel netlogon pipe. */
197 TALLOC_FREE(c
->netlogon_creds
);
198 nt_status
= cli_rpc_pipe_open_schannel(
199 cli
, c
->msg_ctx
, table
, NCACN_NP
,
203 &pipe_hnd
, c
, &c
->netlogon_creds
);
204 if (!NT_STATUS_IS_OK(nt_status
)) {
205 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
206 nt_errstr(nt_status
) ));
210 if (conn_flags
& NET_FLAGS_SEAL
) {
211 nt_status
= cli_rpc_pipe_open_with_creds(
213 (conn_flags
& NET_FLAGS_TCP
) ?
214 NCACN_IP_TCP
: NCACN_NP
,
215 DCERPC_AUTH_TYPE_NTLMSSP
,
216 DCERPC_AUTH_LEVEL_PRIVACY
,
217 smbXcli_conn_remote_name(cli
->conn
),
218 smbXcli_conn_remote_sockaddr(cli
->conn
),
219 c
->creds
, &pipe_hnd
);
221 nt_status
= cli_rpc_pipe_open_noauth(
225 if (!NT_STATUS_IS_OK(nt_status
)) {
226 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
228 nt_errstr(nt_status
) ));
234 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
236 if (!NT_STATUS_IS_OK(nt_status
)) {
237 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
240 DEBUG(5, ("rpc command function succeeded\n"));
243 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
245 TALLOC_FREE(pipe_hnd
);
250 /* close the connection only if it was opened here */
255 talloc_destroy(mem_ctx
);
260 * Force a change of the trust account password.
262 * All parameters are provided by the run_rpc_command function, except for
263 * argc, argv which are passed through.
265 * @param domain_sid The domain sid acquired from the remote server.
266 * @param cli A cli_state connected to the server.
267 * @param mem_ctx Talloc context, destroyed on completion of the function.
268 * @param argc Standard main() style argc.
269 * @param argv Standard main() style argv. Initial components are already
272 * @return Normal NTSTATUS return.
275 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
276 const struct dom_sid
*domain_sid
,
277 const char *domain_name
,
278 struct cli_state
*cli
,
279 struct rpc_pipe_client
*pipe_hnd
,
285 const char *dcname
= NULL
;
288 return NT_STATUS_INTERNAL_ERROR
;
291 dcname
= smbXcli_conn_remote_name(cli
->conn
);
293 status
= trust_pw_change(c
->netlogon_creds
,
295 pipe_hnd
->binding_handle
,
296 c
->opt_target_workgroup
,
299 if (!NT_STATUS_IS_OK(status
)) {
300 d_fprintf(stderr
, _("Failed to change machine account password: %s\n"),
309 * Force a change of the trust account password.
311 * @param argc Standard main() style argc.
312 * @param argv Standard main() style argv. Initial components are already
315 * @return A shell status integer (0 for success).
318 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
320 int conn_flags
= NET_FLAGS_PDC
;
322 if (!c
->opt_user_specified
&& !c
->opt_kerberos
) {
323 conn_flags
|= NET_FLAGS_ANONYMOUS
;
326 if (c
->display_usage
) {
328 "net rpc changetrustpw\n"
331 _("Change the machine trust password"));
335 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
,
337 rpc_changetrustpw_internals
,
342 * Join a domain, the old way. This function exists to allow
343 * the message to be displayed when oldjoin was explicitly
344 * requested, but not when it was implied by "net rpc join".
346 * This uses 'machinename' as the initial password, and changes it.
348 * The password should be created with 'server manager' or equiv first.
350 * @param argc Standard main() style argc.
351 * @param argv Standard main() style argv. Initial components are already
354 * @return A shell status integer (0 for success).
357 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
359 struct libnet_JoinCtx
*r
= NULL
;
362 const char *domain
= lp_workgroup(); /* FIXME */
363 bool modify_config
= lp_config_backend_is_registry();
364 enum netr_SchannelType sec_chan_type
;
367 if (c
->display_usage
) {
370 " Join a domain the old way\n");
374 net_warn_member_options();
376 mem_ctx
= talloc_init("net_rpc_oldjoin");
381 werr
= libnet_init_JoinCtx(mem_ctx
, &r
);
382 if (!W_ERROR_IS_OK(werr
)) {
387 check what type of join - if the user wants to join as
388 a BDC, the server must agree that we are a BDC.
391 sec_chan_type
= get_sec_channel_type(argv
[0]);
393 sec_chan_type
= get_sec_channel_type(NULL
);
397 d_fprintf(stderr
, _("Could not initialise message context. "
398 "Try running as root\n"));
399 werr
= WERR_ACCESS_DENIED
;
403 pw
= talloc_strndup(r
, lp_netbios_name(), 14);
405 werr
= WERR_NOT_ENOUGH_MEMORY
;
409 r
->in
.msg_ctx
= c
->msg_ctx
;
410 r
->in
.domain_name
= domain
;
411 r
->in
.secure_channel_type
= sec_chan_type
;
412 r
->in
.dc_name
= c
->opt_host
;
413 r
->in
.admin_account
= "";
414 r
->in
.admin_password
= strlower_talloc(r
, pw
);
415 if (r
->in
.admin_password
== NULL
) {
416 werr
= WERR_NOT_ENOUGH_MEMORY
;
420 r
->in
.modify_config
= modify_config
;
421 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
422 WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
|
423 WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED
;
425 werr
= libnet_Join(mem_ctx
, r
);
426 if (!W_ERROR_IS_OK(werr
)) {
430 /* Check the short name of the domain */
432 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
433 d_printf("The workgroup in %s does not match the short\n", get_dyn_CONFIGFILE());
434 d_printf("domain name obtained from the server.\n");
435 d_printf("Using the name [%s] from the server.\n", r
->out
.netbios_domain_name
);
436 d_printf("You should set \"workgroup = %s\" in %s.\n",
437 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
440 d_printf("Using short domain name -- %s\n", r
->out
.netbios_domain_name
);
442 if (r
->out
.dns_domain_name
) {
443 d_printf("Joined '%s' to realm '%s'\n", r
->in
.machine_name
,
444 r
->out
.dns_domain_name
);
446 d_printf("Joined '%s' to domain '%s'\n", r
->in
.machine_name
,
447 r
->out
.netbios_domain_name
);
450 /* print out informative error string in case there is one */
451 if (r
->out
.error_string
!= NULL
) {
452 d_printf("%s\n", r
->out
.error_string
);
455 TALLOC_FREE(mem_ctx
);
460 if (c
->opt_flags
& NET_FLAGS_EXPECT_FALLBACK
) {
464 /* issue an overall failure message at the end. */
465 d_fprintf(stderr
, _("Failed to join domain: %s\n"),
466 r
&& r
->out
.error_string
? r
->out
.error_string
:
467 get_friendly_werror_msg(werr
));
470 TALLOC_FREE(mem_ctx
);
476 * check that a join is OK
478 * @return A shell status integer (0 for success)
481 int net_rpc_testjoin(struct net_context
*c
, int argc
, const char **argv
)
485 const char *domain
= c
->opt_target_workgroup
;
486 const char *dc
= c
->opt_host
;
488 if (c
->display_usage
) {
491 " Test if a join is OK\n");
495 net_warn_member_options();
497 mem_ctx
= talloc_init("net_rpc_testjoin");
503 struct netr_DsRGetDCNameInfo
*info
;
506 d_fprintf(stderr
, _("Could not initialise message context. "
507 "Try running as root\n"));
508 talloc_destroy(mem_ctx
);
512 status
= dsgetdcname(mem_ctx
,
519 if (!NT_STATUS_IS_OK(status
)) {
520 talloc_destroy(mem_ctx
);
524 dc
= strip_hostname(info
->dc_unc
);
527 /* Display success or failure */
528 status
= libnet_join_ok(c
->msg_ctx
,
532 if (!NT_STATUS_IS_OK(status
)) {
533 fprintf(stderr
,"Join to domain '%s' is not valid: %s\n",
534 domain
, nt_errstr(status
));
535 talloc_destroy(mem_ctx
);
539 printf("Join to '%s' is OK\n",domain
);
540 talloc_destroy(mem_ctx
);
546 * Join a domain using the administrator username and password
548 * @param argc Standard main() style argc
549 * @param argc Standard main() style argv. Initial components are already
550 * stripped. Currently not used.
551 * @return A shell status integer (0 for success)
555 static int net_rpc_join_newstyle(struct net_context
*c
, int argc
, const char **argv
)
557 struct libnet_JoinCtx
*r
= NULL
;
560 const char *domain
= lp_workgroup(); /* FIXME */
561 bool modify_config
= lp_config_backend_is_registry();
562 enum netr_SchannelType sec_chan_type
;
564 if (c
->display_usage
) {
567 " Join a domain the new way\n");
571 net_warn_member_options();
573 mem_ctx
= talloc_init("net_rpc_join_newstyle");
578 werr
= libnet_init_JoinCtx(mem_ctx
, &r
);
579 if (!W_ERROR_IS_OK(werr
)) {
584 check what type of join - if the user wants to join as
585 a BDC, the server must agree that we are a BDC.
588 sec_chan_type
= get_sec_channel_type(argv
[0]);
590 sec_chan_type
= get_sec_channel_type(NULL
);
594 d_fprintf(stderr
, _("Could not initialise message context. "
595 "Try running as root\n"));
596 werr
= WERR_ACCESS_DENIED
;
600 r
->in
.msg_ctx
= c
->msg_ctx
;
601 r
->in
.domain_name
= domain
;
602 r
->in
.secure_channel_type
= sec_chan_type
;
603 r
->in
.dc_name
= c
->opt_host
;
604 r
->in
.admin_account
= c
->opt_user_name
;
605 r
->in
.admin_password
= net_prompt_pass(c
, c
->opt_user_name
);
607 r
->in
.use_kerberos
= c
->opt_kerberos
;
608 r
->in
.modify_config
= modify_config
;
609 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
610 WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
611 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
613 werr
= libnet_Join(mem_ctx
, r
);
614 if (!W_ERROR_IS_OK(werr
)) {
618 /* Check the short name of the domain */
620 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
621 d_printf("The workgroup in %s does not match the short\n", get_dyn_CONFIGFILE());
622 d_printf("domain name obtained from the server.\n");
623 d_printf("Using the name [%s] from the server.\n", r
->out
.netbios_domain_name
);
624 d_printf("You should set \"workgroup = %s\" in %s.\n",
625 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
628 d_printf("Using short domain name -- %s\n", r
->out
.netbios_domain_name
);
630 if (r
->out
.dns_domain_name
) {
631 d_printf("Joined '%s' to realm '%s'\n", r
->in
.machine_name
,
632 r
->out
.dns_domain_name
);
634 d_printf("Joined '%s' to domain '%s'\n", r
->in
.machine_name
,
635 r
->out
.netbios_domain_name
);
638 /* print out informative error string in case there is one */
639 if (r
->out
.error_string
!= NULL
) {
640 d_printf("%s\n", r
->out
.error_string
);
643 TALLOC_FREE(mem_ctx
);
648 /* issue an overall failure message at the end. */
649 d_printf("Failed to join domain: %s\n",
650 r
&& r
->out
.error_string
? r
->out
.error_string
:
651 get_friendly_werror_msg(werr
));
653 TALLOC_FREE(mem_ctx
);
659 * 'net rpc join' entrypoint.
660 * @param argc Standard main() style argc.
661 * @param argv Standard main() style argv. Initial components are already
664 * Main 'net_rpc_join()' (where the admin username/password is used) is
666 * Try to just change the password, but if that doesn't work, use/prompt
667 * for a username/password.
670 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
674 if (c
->display_usage
) {
677 _("net rpc join -U <username>[%%password] <type>\n"
679 " username\tName of the admin user"
680 " password\tPassword of the admin user, will "
681 "prompt if not specified\n"
682 " type\tCan be one of the following:\n"
683 "\t\tMEMBER\tJoin as member server (default)\n"
684 "\t\tBDC\tJoin as BDC\n"
685 "\t\tPDC\tJoin as PDC\n"));
689 if (lp_server_role() == ROLE_STANDALONE
) {
690 d_printf(_("cannot join as standalone machine\n"));
694 net_warn_member_options();
696 if (strlen(lp_netbios_name()) > 15) {
697 d_printf(_("Our netbios name can be at most 15 chars long, "
698 "\"%s\" is %u chars long\n"),
699 lp_netbios_name(), (unsigned int)strlen(lp_netbios_name()));
703 c
->opt_flags
|= NET_FLAGS_EXPECT_FALLBACK
;
704 ret
= net_rpc_oldjoin(c
, argc
, argv
);
705 c
->opt_flags
&= ~NET_FLAGS_EXPECT_FALLBACK
;
710 return net_rpc_join_newstyle(c
, argc
, argv
);
714 * display info about a rpc domain
716 * All parameters are provided by the run_rpc_command function, except for
717 * argc, argv which are passed through.
719 * @param domain_sid The domain sid acquired from the remote server
720 * @param cli A cli_state connected to the server.
721 * @param mem_ctx Talloc context, destroyed on completion of the function.
722 * @param argc Standard main() style argc.
723 * @param argv Standard main() style argv. Initial components are already
726 * @return Normal NTSTATUS return.
729 NTSTATUS
rpc_info_internals(struct net_context
*c
,
730 const struct dom_sid
*domain_sid
,
731 const char *domain_name
,
732 struct cli_state
*cli
,
733 struct rpc_pipe_client
*pipe_hnd
,
738 struct policy_handle connect_pol
, domain_pol
;
739 NTSTATUS status
, result
;
740 union samr_DomainInfo
*info
= NULL
;
741 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
743 /* Get sam policy handle */
744 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
746 MAXIMUM_ALLOWED_ACCESS
,
749 if (!NT_STATUS_IS_OK(status
)) {
750 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
755 if (!NT_STATUS_IS_OK(result
)) {
757 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
762 /* Get domain policy handle */
763 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
765 MAXIMUM_ALLOWED_ACCESS
,
766 discard_const_p(struct dom_sid2
, domain_sid
),
769 if (!NT_STATUS_IS_OK(status
)) {
770 d_fprintf(stderr
, _("Could not open domain: %s\n"),
774 if (!NT_STATUS_IS_OK(result
)) {
776 d_fprintf(stderr
, _("Could not open domain: %s\n"),
781 status
= dcerpc_samr_QueryDomainInfo(b
, mem_ctx
,
786 if (!NT_STATUS_IS_OK(status
)) {
790 if (NT_STATUS_IS_OK(result
)) {
791 struct dom_sid_buf sid_str
;
793 d_printf(_("Domain Name: %s\n"),
794 info
->general
.domain_name
.string
);
795 d_printf(_("Domain SID: %s\n"),
796 dom_sid_str_buf(domain_sid
, &sid_str
));
797 d_printf(_("Sequence number: %llu\n"),
798 (unsigned long long)info
->general
.sequence_num
);
799 d_printf(_("Num users: %u\n"), info
->general
.num_users
);
800 d_printf(_("Num domain groups: %u\n"),info
->general
.num_groups
);
801 d_printf(_("Num local groups: %u\n"),info
->general
.num_aliases
);
809 * 'net rpc info' entrypoint.
810 * @param argc Standard main() style argc.
811 * @param argv Standard main() style argv. Initial components are already
815 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
817 if (c
->display_usage
) {
822 _("Display information about the domain"));
826 net_warn_member_options();
828 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
829 NET_FLAGS_PDC
, rpc_info_internals
,
834 * Fetch domain SID into the local secrets.tdb.
836 * All parameters are provided by the run_rpc_command function, except for
837 * argc, argv which are passed through.
839 * @param domain_sid The domain sid acquired from the remote server.
840 * @param cli A cli_state connected to the server.
841 * @param mem_ctx Talloc context, destroyed on completion of the function.
842 * @param argc Standard main() style argc.
843 * @param argv Standard main() style argv. Initial components are already
846 * @return Normal NTSTATUS return.
849 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
850 const struct dom_sid
*domain_sid
,
851 const char *domain_name
,
852 struct cli_state
*cli
,
853 struct rpc_pipe_client
*pipe_hnd
,
858 struct dom_sid_buf sid_str
;
860 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
861 dom_sid_str_buf(domain_sid
, &sid_str
),
864 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
865 DEBUG(0,("Can't store domain SID\n"));
866 return NT_STATUS_UNSUCCESSFUL
;
873 * 'net rpc getsid' entrypoint.
874 * @param argc Standard main() style argc.
875 * @param argv Standard main() style argv. Initial components are already
879 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
881 int conn_flags
= NET_FLAGS_PDC
;
883 if (!c
->opt_user_specified
&& !c
->opt_kerberos
) {
884 conn_flags
|= NET_FLAGS_ANONYMOUS
;
887 if (c
->display_usage
) {
892 _("Fetch domain SID into local secrets.tdb"));
896 return run_rpc_command(c
, NULL
, &ndr_table_samr
,
898 rpc_getsid_internals
,
902 /****************************************************************************/
905 * Basic usage function for 'net rpc user'.
906 * @param argc Standard main() style argc.
907 * @param argv Standard main() style argv. Initial components are already
911 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
913 return net_user_usage(c
, argc
, argv
);
917 * Add a new user to a remote RPC server.
919 * @param argc Standard main() style argc.
920 * @param argv Standard main() style argv. Initial components are already
923 * @return A shell status integer (0 for success).
926 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
928 NET_API_STATUS status
;
929 struct USER_INFO_1 info1
;
930 uint32_t parm_error
= 0;
932 if (argc
< 1 || c
->display_usage
) {
933 rpc_user_usage(c
, argc
, argv
);
939 info1
.usri1_name
= argv
[0];
941 info1
.usri1_password
= argv
[1];
944 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
947 d_fprintf(stderr
,_("Failed to add user '%s' with error: %s.\n"),
948 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
952 d_printf(_("Added user '%s'.\n"), argv
[0]);
959 * Rename a user on a remote RPC server.
961 * @param argc Standard main() style argc.
962 * @param argv Standard main() style argv. Initial components are already
965 * @return A shell status integer (0 for success).
968 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
970 NET_API_STATUS status
;
971 struct USER_INFO_0 u0
;
972 uint32_t parm_err
= 0;
974 if (argc
!= 2 || c
->display_usage
) {
975 rpc_user_usage(c
, argc
, argv
);
979 u0
.usri0_name
= argv
[1];
981 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
982 0, (uint8_t *)&u0
, &parm_err
);
985 _("Failed to rename user from %s to %s - %s\n"),
987 libnetapi_get_error_string(c
->netapi_ctx
, status
));
989 d_printf(_("Renamed user from %s to %s\n"), argv
[0], argv
[1]);
996 * Set a user's primary group
998 * @param argc Standard main() style argc.
999 * @param argv Standard main() style argv. Initial components are already
1002 * @return A shell status integer (0 for success).
1005 static int rpc_user_setprimarygroup(struct net_context
*c
, int argc
,
1008 NET_API_STATUS status
;
1010 struct GROUP_INFO_2
*g2
;
1011 struct USER_INFO_1051 u1051
;
1012 uint32_t parm_err
= 0;
1014 if (argc
!= 2 || c
->display_usage
) {
1015 rpc_user_usage(c
, argc
, argv
);
1019 status
= NetGroupGetInfo(c
->opt_host
, argv
[1], 2, &buffer
);
1021 d_fprintf(stderr
, _("Failed to find group name %s -- %s\n"),
1023 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1026 g2
= (struct GROUP_INFO_2
*)buffer
;
1028 u1051
.usri1051_primary_group_id
= g2
->grpi2_group_id
;
1030 NetApiBufferFree(buffer
);
1032 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1051,
1033 (uint8_t *)&u1051
, &parm_err
);
1036 _("Failed to set user's primary group %s to %s - "
1037 "%s\n"), argv
[0], argv
[1],
1038 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1040 d_printf(_("Set primary group of user %s to %s\n"), argv
[0],
1047 * Delete a user from a remote RPC server.
1049 * @param argc Standard main() style argc.
1050 * @param argv Standard main() style argv. Initial components are already
1053 * @return A shell status integer (0 for success).
1056 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
1058 NET_API_STATUS status
;
1060 if (argc
< 1 || c
->display_usage
) {
1061 rpc_user_usage(c
, argc
, argv
);
1065 status
= NetUserDel(c
->opt_host
, argv
[0]);
1068 d_fprintf(stderr
, _("Failed to delete user '%s' with: %s.\n"),
1070 libnetapi_get_error_string(c
->netapi_ctx
, status
));
1073 d_printf(_("Deleted user '%s'.\n"), argv
[0]);
1080 * Set a user's password on a remote RPC server.
1082 * @param argc Standard main() style argc.
1083 * @param argv Standard main() style argv. Initial components are already
1086 * @return A shell status integer (0 for success).
1089 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
1091 NET_API_STATUS status
;
1092 char *prompt
= NULL
;
1093 struct USER_INFO_1003 u1003
;
1094 uint32_t parm_err
= 0;
1097 if (argc
< 1 || c
->display_usage
) {
1098 rpc_user_usage(c
, argc
, argv
);
1103 u1003
.usri1003_password
= argv
[1];
1105 char pwd
[256] = {0};
1106 ret
= asprintf(&prompt
, _("Enter new password for %s:"),
1112 ret
= samba_getpass(prompt
, pwd
, sizeof(pwd
), false, false);
1118 u1003
.usri1003_password
= talloc_strdup(c
, pwd
);
1119 if (u1003
.usri1003_password
== NULL
) {
1124 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
1126 /* Display results */
1129 _("Failed to set password for '%s' with error: %s.\n"),
1130 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1139 * List a user's groups from a remote RPC server.
1141 * @param argc Standard main() style argc.
1142 * @param argv Standard main() style argv. Initial components are already
1145 * @return A shell status integer (0 for success)
1148 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
1151 NET_API_STATUS status
;
1152 struct GROUP_USERS_INFO_0
*u0
= NULL
;
1153 uint32_t entries_read
= 0;
1154 uint32_t total_entries
= 0;
1158 if (argc
< 1 || c
->display_usage
) {
1159 rpc_user_usage(c
, argc
, argv
);
1163 status
= NetUserGetGroups(c
->opt_host
,
1166 (uint8_t **)(void *)&u0
,
1172 _("Failed to get groups for '%s' with error: %s.\n"),
1173 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1178 for (i
=0; i
< entries_read
; i
++) {
1179 printf("%s\n", u0
->grui0_name
);
1187 * List users on a remote RPC server.
1189 * All parameters are provided by the run_rpc_command function, except for
1190 * argc, argv which are passed through.
1192 * @param domain_sid The domain sid acquired from the remote server.
1193 * @param cli A cli_state connected to the server.
1194 * @param mem_ctx Talloc context, destroyed on completion of the function.
1195 * @param argc Standard main() style argc.
1196 * @param argv Standard main() style argv. Initial components are already
1199 * @return Normal NTSTATUS return.
1202 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
1204 NET_API_STATUS status
;
1205 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
1206 struct NET_DISPLAY_USER
*info
= NULL
;
1207 void *buffer
= NULL
;
1209 /* Query domain users */
1210 if (c
->opt_long_list_entries
)
1211 d_printf(_("\nUser name Comment"
1212 "\n-----------------------------\n"));
1214 uint32_t max_entries
, max_size
;
1216 dcerpc_get_query_dispinfo_params(
1217 loop_count
, &max_entries
, &max_size
);
1219 status
= NetQueryDisplayInformation(c
->opt_host
,
1226 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
1230 info
= (struct NET_DISPLAY_USER
*)buffer
;
1232 for (i
= 0; i
< num_entries
; i
++) {
1234 if (c
->opt_long_list_entries
)
1235 printf("%-21.21s %s\n", info
->usri1_name
,
1236 info
->usri1_comment
);
1238 printf("%s\n", info
->usri1_name
);
1242 NetApiBufferFree(buffer
);
1245 start_idx
+= num_entries
;
1247 } while (status
== ERROR_MORE_DATA
);
1253 * 'net rpc user' entrypoint.
1254 * @param argc Standard main() style argc.
1255 * @param argv Standard main() style argv. Initial components are already
1259 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
1261 NET_API_STATUS status
;
1263 struct functable func
[] = {
1268 N_("Add specified user"),
1269 N_("net rpc user add\n"
1270 " Add specified user")
1276 N_("List domain groups of user"),
1277 N_("net rpc user info\n"
1278 " List domain groups of user")
1284 N_("Remove specified user"),
1285 N_("net rpc user delete\n"
1286 " Remove specified user")
1292 N_("Change user password"),
1293 N_("net rpc user password\n"
1294 " Change user password")
1300 N_("Rename specified user"),
1301 N_("net rpc user rename\n"
1302 " Rename specified user")
1306 rpc_user_setprimarygroup
,
1308 "Set a user's primary group",
1309 "net rpc user setprimarygroup\n"
1310 " Set a user's primary group"
1312 {NULL
, NULL
, 0, NULL
, NULL
}
1315 status
= libnetapi_net_init(&c
->netapi_ctx
);
1320 status
= libnetapi_set_creds(c
->netapi_ctx
, c
->creds
);
1326 if (c
->display_usage
) {
1331 _("List all users"));
1332 net_display_usage_from_functable(func
);
1336 return rpc_user_list(c
, argc
, argv
);
1339 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
1342 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
1343 TALLOC_CTX
*mem_ctx
,
1344 struct rpc_sh_ctx
*ctx
,
1345 struct rpc_pipe_client
*pipe_hnd
,
1346 int argc
, const char **argv
)
1348 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
1351 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
1352 TALLOC_CTX
*mem_ctx
,
1353 struct rpc_sh_ctx
*ctx
,
1354 struct rpc_pipe_client
*pipe_hnd
,
1355 int argc
, const char **argv
)
1357 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1360 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1361 TALLOC_CTX
*mem_ctx
,
1362 struct rpc_sh_ctx
*ctx
,
1363 struct rpc_pipe_client
*pipe_hnd
,
1364 int argc
, const char **argv
,
1366 struct net_context
*c
,
1367 TALLOC_CTX
*mem_ctx
,
1368 struct rpc_sh_ctx
*ctx
,
1369 struct rpc_pipe_client
*pipe_hnd
,
1370 struct policy_handle
*user_hnd
,
1371 int argc
, const char **argv
))
1373 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1374 NTSTATUS status
, result
;
1377 enum lsa_SidType type
;
1378 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1381 d_fprintf(stderr
, "%s %s <username>\n", _("Usage:"),
1383 return NT_STATUS_INVALID_PARAMETER
;
1386 ZERO_STRUCT(connect_pol
);
1387 ZERO_STRUCT(domain_pol
);
1388 ZERO_STRUCT(user_pol
);
1390 status
= net_rpc_lookup_name(c
, mem_ctx
, ctx
->cli
,
1391 argv
[0], NULL
, NULL
, &sid
, &type
);
1392 if (!NT_STATUS_IS_OK(status
)) {
1393 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1398 if (type
!= SID_NAME_USER
) {
1399 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1400 sid_type_lookup(type
));
1401 status
= NT_STATUS_NO_SUCH_USER
;
1405 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1406 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1407 status
= NT_STATUS_NO_SUCH_USER
;
1411 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1413 MAXIMUM_ALLOWED_ACCESS
,
1416 if (!NT_STATUS_IS_OK(status
)) {
1419 if (!NT_STATUS_IS_OK(result
)) {
1424 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1426 MAXIMUM_ALLOWED_ACCESS
,
1430 if (!NT_STATUS_IS_OK(status
)) {
1433 if (!NT_STATUS_IS_OK(result
)) {
1438 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1440 MAXIMUM_ALLOWED_ACCESS
,
1444 if (!NT_STATUS_IS_OK(status
)) {
1447 if (!NT_STATUS_IS_OK(result
)) {
1452 status
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1455 if (is_valid_policy_hnd(&user_pol
)) {
1456 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1458 if (is_valid_policy_hnd(&domain_pol
)) {
1459 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1461 if (is_valid_policy_hnd(&connect_pol
)) {
1462 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
1467 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1468 TALLOC_CTX
*mem_ctx
,
1469 struct rpc_sh_ctx
*ctx
,
1470 struct rpc_pipe_client
*pipe_hnd
,
1471 struct policy_handle
*user_hnd
,
1472 int argc
, const char **argv
)
1474 NTSTATUS status
, result
;
1475 union samr_UserInfo
*info
= NULL
;
1476 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1479 d_fprintf(stderr
, "%s %s show <username>\n", _("Usage:"),
1481 return NT_STATUS_INVALID_PARAMETER
;
1484 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1489 if (!NT_STATUS_IS_OK(status
)) {
1492 if (!NT_STATUS_IS_OK(result
)) {
1496 d_printf(_("user rid: %d, group rid: %d\n"),
1498 info
->info21
.primary_gid
);
1503 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1504 TALLOC_CTX
*mem_ctx
,
1505 struct rpc_sh_ctx
*ctx
,
1506 struct rpc_pipe_client
*pipe_hnd
,
1507 int argc
, const char **argv
)
1509 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1510 rpc_sh_user_show_internals
);
1513 #define FETCHSTR(name, rec) \
1514 do { if (strequal(ctx->thiscmd, name)) { \
1515 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1518 #define SETSTR(name, rec, flag) \
1519 do { if (strequal(ctx->thiscmd, name)) { \
1520 init_lsa_String(&(info->info21.rec), argv[0]); \
1521 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1524 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1525 TALLOC_CTX
*mem_ctx
,
1526 struct rpc_sh_ctx
*ctx
,
1527 struct rpc_pipe_client
*pipe_hnd
,
1528 struct policy_handle
*user_hnd
,
1529 int argc
, const char **argv
)
1531 NTSTATUS status
, result
;
1532 const char *username
;
1533 const char *oldval
= "";
1534 union samr_UserInfo
*info
= NULL
;
1535 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1538 d_fprintf(stderr
, "%s %s <username> [new value|NULL]\n",
1539 _("Usage:"), ctx
->whoami
);
1540 return NT_STATUS_INVALID_PARAMETER
;
1543 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1548 if (!NT_STATUS_IS_OK(status
)) {
1551 if (!NT_STATUS_IS_OK(result
)) {
1555 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1557 FETCHSTR("fullname", full_name
);
1558 FETCHSTR("homedir", home_directory
);
1559 FETCHSTR("homedrive", home_drive
);
1560 FETCHSTR("logonscript", logon_script
);
1561 FETCHSTR("profilepath", profile_path
);
1562 FETCHSTR("description", description
);
1565 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1569 if (strcmp(argv
[0], "NULL") == 0) {
1573 ZERO_STRUCT(info
->info21
);
1575 SETSTR("fullname", full_name
, FULL_NAME
);
1576 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1577 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1578 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1579 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1580 SETSTR("description", description
, DESCRIPTION
);
1582 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1587 if (!NT_STATUS_IS_OK(status
)) {
1593 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1594 ctx
->thiscmd
, oldval
, argv
[0]);
1601 #define HANDLEFLG(name, rec) \
1602 do { if (strequal(ctx->thiscmd, name)) { \
1603 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1605 newflags = oldflags | ACB_##rec; \
1607 newflags = oldflags & ~ACB_##rec; \
1610 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1611 TALLOC_CTX
*mem_ctx
,
1612 struct rpc_sh_ctx
*ctx
,
1613 struct rpc_pipe_client
*pipe_hnd
,
1614 int argc
, const char **argv
)
1616 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1617 rpc_sh_user_str_edit_internals
);
1620 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1621 TALLOC_CTX
*mem_ctx
,
1622 struct rpc_sh_ctx
*ctx
,
1623 struct rpc_pipe_client
*pipe_hnd
,
1624 struct policy_handle
*user_hnd
,
1625 int argc
, const char **argv
)
1627 NTSTATUS status
, result
;
1628 const char *username
;
1629 const char *oldval
= "unknown";
1630 uint32_t oldflags
, newflags
;
1632 union samr_UserInfo
*info
= NULL
;
1633 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1636 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1637 !strequal(argv
[0], "no"))) {
1638 /* TRANSATORS: The yes|no here are program keywords. Please do
1640 d_fprintf(stderr
, _("Usage: %s <username> [yes|no]\n"),
1642 return NT_STATUS_INVALID_PARAMETER
;
1645 newval
= strequal(argv
[0], "yes");
1647 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1652 if (!NT_STATUS_IS_OK(status
)) {
1655 if (!NT_STATUS_IS_OK(result
)) {
1659 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1660 oldflags
= info
->info21
.acct_flags
;
1661 newflags
= info
->info21
.acct_flags
;
1663 HANDLEFLG("disabled", DISABLED
);
1664 HANDLEFLG("pwnotreq", PWNOTREQ
);
1665 HANDLEFLG("autolock", AUTOLOCK
);
1666 HANDLEFLG("pwnoexp", PWNOEXP
);
1669 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1674 ZERO_STRUCT(info
->info21
);
1676 info
->info21
.acct_flags
= newflags
;
1677 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1679 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1684 if (!NT_STATUS_IS_OK(status
)) {
1688 if (NT_STATUS_IS_OK(result
)) {
1689 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1690 ctx
->thiscmd
, oldval
, argv
[0]);
1698 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1699 TALLOC_CTX
*mem_ctx
,
1700 struct rpc_sh_ctx
*ctx
,
1701 struct rpc_pipe_client
*pipe_hnd
,
1702 int argc
, const char **argv
)
1704 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1705 rpc_sh_user_flag_edit_internals
);
1708 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1709 TALLOC_CTX
*mem_ctx
,
1710 struct rpc_sh_ctx
*ctx
)
1712 static struct rpc_sh_cmd cmds
[] = {
1714 { "fullname", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1715 N_("Show/Set a user's full name") },
1717 { "homedir", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1718 N_("Show/Set a user's home directory") },
1720 { "homedrive", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1721 N_("Show/Set a user's home drive") },
1723 { "logonscript", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1724 N_("Show/Set a user's logon script") },
1726 { "profilepath", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1727 N_("Show/Set a user's profile path") },
1729 { "description", NULL
, &ndr_table_samr
, rpc_sh_user_str_edit
,
1730 N_("Show/Set a user's description") },
1732 { "disabled", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1733 N_("Show/Set whether a user is disabled") },
1735 { "autolock", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1736 N_("Show/Set whether a user locked out") },
1738 { "pwnotreq", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1739 N_("Show/Set whether a user does not need a password") },
1741 { "pwnoexp", NULL
, &ndr_table_samr
, rpc_sh_user_flag_edit
,
1742 N_("Show/Set whether a user's password does not expire") },
1744 { NULL
, NULL
, 0, NULL
, NULL
}
1750 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1751 TALLOC_CTX
*mem_ctx
,
1752 struct rpc_sh_ctx
*ctx
)
1754 static struct rpc_sh_cmd cmds
[] = {
1756 { "list", NULL
, &ndr_table_samr
, rpc_sh_user_list
,
1757 N_("List available users") },
1759 { "info", NULL
, &ndr_table_samr
, rpc_sh_user_info
,
1760 N_("List the domain groups a user is member of") },
1762 { "show", NULL
, &ndr_table_samr
, rpc_sh_user_show
,
1763 N_("Show info about a user") },
1765 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1766 N_("Show/Modify a user's fields") },
1768 { NULL
, NULL
, 0, NULL
, NULL
}
1774 /****************************************************************************/
1777 * Basic usage function for 'net rpc group'.
1778 * @param argc Standard main() style argc.
1779 * @param argv Standard main() style argv. Initial components are already
1783 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1785 return net_group_usage(c
, argc
, argv
);
1789 * Delete group on a remote RPC server.
1791 * All parameters are provided by the run_rpc_command function, except for
1792 * argc, argv which are passed through.
1794 * @param domain_sid The domain sid acquired from the remote server.
1795 * @param cli A cli_state connected to the server.
1796 * @param mem_ctx Talloc context, destroyed on completion of the function.
1797 * @param argc Standard main() style argc.
1798 * @param argv Standard main() style argv. Initial components are already
1801 * @return Normal NTSTATUS return.
1804 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1805 const struct dom_sid
*domain_sid
,
1806 const char *domain_name
,
1807 struct cli_state
*cli
,
1808 struct rpc_pipe_client
*pipe_hnd
,
1809 TALLOC_CTX
*mem_ctx
,
1813 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1814 bool group_is_primary
= false;
1815 NTSTATUS status
, result
;
1817 struct samr_RidAttrArray
*rids
= NULL
;
1820 /* struct samr_RidWithAttribute *user_gids; */
1821 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
1823 struct samr_Ids group_rids
, name_types
;
1824 struct lsa_String lsa_acct_name
;
1825 union samr_UserInfo
*info
= NULL
;
1827 if (argc
< 1 || c
->display_usage
) {
1828 rpc_group_usage(c
, argc
,argv
);
1829 return NT_STATUS_OK
; /* ok? */
1832 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1834 MAXIMUM_ALLOWED_ACCESS
,
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1842 if (!NT_STATUS_IS_OK(result
)) {
1844 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1848 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1850 MAXIMUM_ALLOWED_ACCESS
,
1851 discard_const_p(struct dom_sid2
, domain_sid
),
1854 if (!NT_STATUS_IS_OK(status
)) {
1855 d_fprintf(stderr
, _("Request open_domain failed\n"));
1859 if (!NT_STATUS_IS_OK(result
)) {
1861 d_fprintf(stderr
, _("Request open_domain failed\n"));
1865 init_lsa_String(&lsa_acct_name
, argv
[0]);
1867 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1874 if (!NT_STATUS_IS_OK(status
)) {
1875 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1879 if (!NT_STATUS_IS_OK(result
)) {
1881 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1884 if (group_rids
.count
!= 1) {
1885 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1888 if (name_types
.count
!= 1) {
1889 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1893 switch (name_types
.ids
[0])
1895 case SID_NAME_DOM_GRP
:
1896 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
1898 MAXIMUM_ALLOWED_ACCESS
,
1902 if (!NT_STATUS_IS_OK(status
)) {
1903 d_fprintf(stderr
, _("Request open_group failed"));
1907 if (!NT_STATUS_IS_OK(result
)) {
1909 d_fprintf(stderr
, _("Request open_group failed"));
1913 group_rid
= group_rids
.ids
[0];
1915 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
1919 if (!NT_STATUS_IS_OK(status
)) {
1921 _("Unable to query group members of %s"),
1926 if (!NT_STATUS_IS_OK(result
)) {
1929 _("Unable to query group members of %s"),
1934 if (c
->opt_verbose
) {
1936 _("Domain Group %s (rid: %d) has %d members\n"),
1937 argv
[0],group_rid
, rids
->count
);
1940 /* Check if group is anyone's primary group */
1941 for (i
= 0; i
< rids
->count
; i
++)
1943 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1945 MAXIMUM_ALLOWED_ACCESS
,
1949 if (!NT_STATUS_IS_OK(status
)) {
1951 _("Unable to open group member %d\n"),
1956 if (!NT_STATUS_IS_OK(result
)) {
1959 _("Unable to open group member %d\n"),
1964 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1969 if (!NT_STATUS_IS_OK(status
)) {
1971 _("Unable to lookup userinfo for group "
1977 if (!NT_STATUS_IS_OK(result
)) {
1980 _("Unable to lookup userinfo for group "
1986 if (info
->info21
.primary_gid
== group_rid
) {
1987 if (c
->opt_verbose
) {
1988 d_printf(_("Group is primary group "
1990 info
->info21
.account_name
.string
);
1992 group_is_primary
= true;
1995 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1998 if (group_is_primary
) {
1999 d_fprintf(stderr
, _("Unable to delete group because "
2000 "some of it's members have it as primary "
2002 status
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
2006 /* remove all group members */
2007 for (i
= 0; i
< rids
->count
; i
++)
2010 d_printf(_("Remove group member %d..."),
2012 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
2016 if (!NT_STATUS_IS_OK(status
)) {
2020 if (NT_STATUS_IS_OK(result
)) {
2022 d_printf(_("ok\n"));
2025 d_printf("%s\n", _("failed"));
2030 status
= dcerpc_samr_DeleteDomainGroup(b
, mem_ctx
,
2033 if (!NT_STATUS_IS_OK(status
)) {
2040 /* removing a local group is easier... */
2041 case SID_NAME_ALIAS
:
2042 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2044 MAXIMUM_ALLOWED_ACCESS
,
2048 if (!NT_STATUS_IS_OK(status
)) {
2049 d_fprintf(stderr
, _("Request open_alias failed\n"));
2052 if (!NT_STATUS_IS_OK(result
)) {
2054 d_fprintf(stderr
, _("Request open_alias failed\n"));
2058 status
= dcerpc_samr_DeleteDomAlias(b
, mem_ctx
,
2061 if (!NT_STATUS_IS_OK(status
)) {
2069 d_fprintf(stderr
, _("%s is of type %s. This command is only "
2070 "for deleting local or global groups\n"),
2071 argv
[0],sid_type_lookup(name_types
.ids
[0]));
2072 status
= NT_STATUS_UNSUCCESSFUL
;
2076 if (NT_STATUS_IS_OK(status
)) {
2078 d_printf(_("Deleted %s '%s'\n"),
2079 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
2081 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
2082 get_friendly_nt_error_msg(status
));
2090 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
2092 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2093 rpc_group_delete_internals
, argc
,argv
);
2096 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2098 NET_API_STATUS status
;
2099 struct GROUP_INFO_1 info1
;
2100 uint32_t parm_error
= 0;
2102 if (argc
!= 1 || c
->display_usage
) {
2103 rpc_group_usage(c
, argc
, argv
);
2109 info1
.grpi1_name
= argv
[0];
2110 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2111 info1
.grpi1_comment
= c
->opt_comment
;
2114 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2118 _("Failed to add group '%s' with error: %s.\n"),
2119 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2123 d_printf(_("Added group '%s'.\n"), argv
[0]);
2129 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
2131 NET_API_STATUS status
;
2132 struct LOCALGROUP_INFO_1 info1
;
2133 uint32_t parm_error
= 0;
2135 if (argc
!= 1 || c
->display_usage
) {
2136 rpc_group_usage(c
, argc
, argv
);
2142 info1
.lgrpi1_name
= argv
[0];
2143 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
2144 info1
.lgrpi1_comment
= c
->opt_comment
;
2147 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
2151 _("Failed to add alias '%s' with error: %s.\n"),
2152 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2156 d_printf(_("Added alias '%s'.\n"), argv
[0]);
2162 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
2164 if (c
->opt_localgroup
)
2165 return rpc_alias_add_internals(c
, argc
, argv
);
2167 return rpc_group_add_internals(c
, argc
, argv
);
2170 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
2171 TALLOC_CTX
*mem_ctx
,
2173 struct dom_sid
*sid
,
2174 enum lsa_SidType
*type
)
2176 struct dom_sid
*sids
= NULL
;
2177 enum lsa_SidType
*types
= NULL
;
2178 struct rpc_pipe_client
*pipe_hnd
= NULL
;
2179 struct policy_handle lsa_pol
;
2180 NTSTATUS status
, result
;
2181 struct dcerpc_binding_handle
*b
;
2183 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
2185 if (!NT_STATUS_IS_OK(status
)) {
2189 b
= pipe_hnd
->binding_handle
;
2191 status
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
2192 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2194 if (!NT_STATUS_IS_OK(status
)) {
2198 status
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
2199 &name
, NULL
, 1, &sids
, &types
);
2201 if (NT_STATUS_IS_OK(status
)) {
2202 sid_copy(sid
, &sids
[0]);
2206 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
2210 TALLOC_FREE(pipe_hnd
);
2213 if (!NT_STATUS_IS_OK(status
) && (strncasecmp_m(name
, "S-", 2) == 0)) {
2215 /* Try as S-1-5-whatever */
2217 struct dom_sid tmp_sid
;
2219 if (string_to_sid(&tmp_sid
, name
)) {
2220 sid_copy(sid
, &tmp_sid
);
2221 *type
= SID_NAME_UNKNOWN
;
2222 status
= NT_STATUS_OK
;
2229 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2230 TALLOC_CTX
*mem_ctx
,
2231 const struct dom_sid
*group_sid
,
2234 struct policy_handle connect_pol
, domain_pol
;
2235 NTSTATUS status
, result
;
2237 struct policy_handle group_pol
;
2238 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2240 struct samr_Ids rids
, rid_types
;
2241 struct lsa_String lsa_acct_name
;
2245 sid_copy(&sid
, group_sid
);
2247 if (!sid_split_rid(&sid
, &group_rid
)) {
2248 return NT_STATUS_UNSUCCESSFUL
;
2251 /* Get sam policy handle */
2252 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2254 MAXIMUM_ALLOWED_ACCESS
,
2257 if (!NT_STATUS_IS_OK(status
)) {
2260 if (!NT_STATUS_IS_OK(result
)) {
2264 /* Get domain policy handle */
2265 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2267 MAXIMUM_ALLOWED_ACCESS
,
2271 if (!NT_STATUS_IS_OK(status
)) {
2274 if (!NT_STATUS_IS_OK(result
)) {
2278 init_lsa_String(&lsa_acct_name
, member
);
2280 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2287 if (!NT_STATUS_IS_OK(status
)) {
2288 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2293 if (!NT_STATUS_IS_OK(result
)) {
2295 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2299 if (rids
.count
!= 1) {
2300 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2303 if (rid_types
.count
!= 1) {
2304 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2308 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2310 MAXIMUM_ALLOWED_ACCESS
,
2314 if (!NT_STATUS_IS_OK(status
)) {
2318 if (!NT_STATUS_IS_OK(result
)) {
2323 status
= dcerpc_samr_AddGroupMember(b
, mem_ctx
,
2326 0x0005, /* unknown flags */
2328 if (!NT_STATUS_IS_OK(status
)) {
2335 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2339 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2340 struct cli_state
*cli
,
2341 TALLOC_CTX
*mem_ctx
,
2342 const struct dom_sid
*alias_sid
,
2345 struct policy_handle connect_pol
, domain_pol
;
2346 NTSTATUS status
, result
;
2348 struct policy_handle alias_pol
;
2349 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2351 struct dom_sid member_sid
;
2352 enum lsa_SidType member_type
;
2356 sid_copy(&sid
, alias_sid
);
2358 if (!sid_split_rid(&sid
, &alias_rid
)) {
2359 return NT_STATUS_UNSUCCESSFUL
;
2362 result
= get_sid_from_name(cli
, mem_ctx
,
2363 member
, &member_sid
, &member_type
);
2365 if (!NT_STATUS_IS_OK(result
)) {
2366 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2371 /* Get sam policy handle */
2372 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2374 MAXIMUM_ALLOWED_ACCESS
,
2377 if (!NT_STATUS_IS_OK(status
)) {
2380 if (!NT_STATUS_IS_OK(result
)) {
2385 /* Get domain policy handle */
2386 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2388 MAXIMUM_ALLOWED_ACCESS
,
2392 if (!NT_STATUS_IS_OK(status
)) {
2395 if (!NT_STATUS_IS_OK(result
)) {
2400 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2402 MAXIMUM_ALLOWED_ACCESS
,
2406 if (!NT_STATUS_IS_OK(status
)) {
2409 if (!NT_STATUS_IS_OK(result
)) {
2413 status
= dcerpc_samr_AddAliasMember(b
, mem_ctx
,
2417 if (!NT_STATUS_IS_OK(status
)) {
2424 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2428 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
2429 const struct dom_sid
*domain_sid
,
2430 const char *domain_name
,
2431 struct cli_state
*cli
,
2432 struct rpc_pipe_client
*pipe_hnd
,
2433 TALLOC_CTX
*mem_ctx
,
2437 struct dom_sid group_sid
;
2438 enum lsa_SidType group_type
;
2440 if (argc
!= 2 || c
->display_usage
) {
2443 _("net rpc group addmem <group> <member>\n"
2444 " Add a member to a group\n"
2445 " group\tGroup to add member to\n"
2446 " member\tMember to add to group\n"));
2447 return NT_STATUS_UNSUCCESSFUL
;
2450 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2451 &group_sid
, &group_type
))) {
2452 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2454 return NT_STATUS_UNSUCCESSFUL
;
2457 if (group_type
== SID_NAME_DOM_GRP
) {
2458 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2459 &group_sid
, argv
[1]);
2461 if (!NT_STATUS_IS_OK(result
)) {
2462 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2463 argv
[1], argv
[0], nt_errstr(result
));
2468 if (group_type
== SID_NAME_ALIAS
) {
2469 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2470 &group_sid
, argv
[1]);
2472 if (!NT_STATUS_IS_OK(result
)) {
2473 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
2474 argv
[1], argv
[0], nt_errstr(result
));
2479 d_fprintf(stderr
, _("Can only add members to global or local groups "
2480 "which %s is not\n"), argv
[0]);
2482 return NT_STATUS_UNSUCCESSFUL
;
2485 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
2487 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2488 rpc_group_addmem_internals
,
2492 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
2493 struct rpc_pipe_client
*pipe_hnd
,
2494 TALLOC_CTX
*mem_ctx
,
2495 const struct dom_sid
*group_sid
,
2498 struct policy_handle connect_pol
, domain_pol
;
2499 NTSTATUS status
, result
;
2501 struct policy_handle group_pol
;
2502 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2504 struct samr_Ids rids
, rid_types
;
2505 struct lsa_String lsa_acct_name
;
2509 sid_copy(&sid
, group_sid
);
2511 if (!sid_split_rid(&sid
, &group_rid
))
2512 return NT_STATUS_UNSUCCESSFUL
;
2514 /* Get sam policy handle */
2515 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2517 MAXIMUM_ALLOWED_ACCESS
,
2520 if (!NT_STATUS_IS_OK(status
)) {
2523 if (!NT_STATUS_IS_OK(result
)) {
2528 /* Get domain policy handle */
2529 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2531 MAXIMUM_ALLOWED_ACCESS
,
2535 if (!NT_STATUS_IS_OK(status
)) {
2538 if (!NT_STATUS_IS_OK(result
)) {
2542 init_lsa_String(&lsa_acct_name
, member
);
2544 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
2551 if (!NT_STATUS_IS_OK(status
)) {
2552 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2557 if (!NT_STATUS_IS_OK(result
)) {
2559 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2563 if (rids
.count
!= 1) {
2564 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2567 if (rid_types
.count
!= 1) {
2568 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
2572 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
2574 MAXIMUM_ALLOWED_ACCESS
,
2578 if (!NT_STATUS_IS_OK(status
)) {
2581 if (!NT_STATUS_IS_OK(result
)) {
2586 status
= dcerpc_samr_DeleteGroupMember(b
, mem_ctx
,
2590 if (!NT_STATUS_IS_OK(status
)) {
2596 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2600 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2601 struct cli_state
*cli
,
2602 TALLOC_CTX
*mem_ctx
,
2603 const struct dom_sid
*alias_sid
,
2606 struct policy_handle connect_pol
, domain_pol
;
2607 NTSTATUS status
, result
;
2609 struct policy_handle alias_pol
;
2610 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2612 struct dom_sid member_sid
;
2613 enum lsa_SidType member_type
;
2617 sid_copy(&sid
, alias_sid
);
2619 if (!sid_split_rid(&sid
, &alias_rid
))
2620 return NT_STATUS_UNSUCCESSFUL
;
2622 result
= get_sid_from_name(cli
, mem_ctx
,
2623 member
, &member_sid
, &member_type
);
2625 if (!NT_STATUS_IS_OK(result
)) {
2626 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2631 /* Get sam policy handle */
2632 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2634 MAXIMUM_ALLOWED_ACCESS
,
2637 if (!NT_STATUS_IS_OK(status
)) {
2640 if (!NT_STATUS_IS_OK(result
)) {
2645 /* Get domain policy handle */
2646 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2648 MAXIMUM_ALLOWED_ACCESS
,
2652 if (!NT_STATUS_IS_OK(status
)) {
2655 if (!NT_STATUS_IS_OK(result
)) {
2660 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2662 MAXIMUM_ALLOWED_ACCESS
,
2666 if (!NT_STATUS_IS_OK(status
)) {
2670 if (!NT_STATUS_IS_OK(result
)) {
2674 status
= dcerpc_samr_DeleteAliasMember(b
, mem_ctx
,
2679 if (!NT_STATUS_IS_OK(status
)) {
2686 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
2690 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2691 const struct dom_sid
*domain_sid
,
2692 const char *domain_name
,
2693 struct cli_state
*cli
,
2694 struct rpc_pipe_client
*pipe_hnd
,
2695 TALLOC_CTX
*mem_ctx
,
2699 struct dom_sid group_sid
;
2700 enum lsa_SidType group_type
;
2702 if (argc
!= 2 || c
->display_usage
) {
2705 _("net rpc group delmem <group> <member>\n"
2706 " Delete a member from a group\n"
2707 " group\tGroup to delete member from\n"
2708 " member\tMember to delete from group\n"));
2709 return NT_STATUS_UNSUCCESSFUL
;
2712 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2713 &group_sid
, &group_type
))) {
2714 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2716 return NT_STATUS_UNSUCCESSFUL
;
2719 if (group_type
== SID_NAME_DOM_GRP
) {
2720 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2721 &group_sid
, argv
[1]);
2723 if (!NT_STATUS_IS_OK(result
)) {
2724 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2725 argv
[1], argv
[0], nt_errstr(result
));
2730 if (group_type
== SID_NAME_ALIAS
) {
2731 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, cli
, mem_ctx
,
2732 &group_sid
, argv
[1]);
2734 if (!NT_STATUS_IS_OK(result
)) {
2735 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2736 argv
[1], argv
[0], nt_errstr(result
));
2741 d_fprintf(stderr
, _("Can only delete members from global or local "
2742 "groups which %s is not\n"), argv
[0]);
2744 return NT_STATUS_UNSUCCESSFUL
;
2747 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2749 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
2750 rpc_group_delmem_internals
,
2755 * List groups on a remote RPC server.
2757 * All parameters are provided by the run_rpc_command function, except for
2758 * argc, argv which are passes through.
2760 * @param domain_sid The domain sid acquired from the remote server.
2761 * @param cli A cli_state connected to the server.
2762 * @param mem_ctx Talloc context, destroyed on completion of the function.
2763 * @param argc Standard main() style argc.
2764 * @param argv Standard main() style argv. Initial components are already
2767 * @return Normal NTSTATUS return.
2770 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2771 const struct dom_sid
*domain_sid
,
2772 const char *domain_name
,
2773 struct cli_state
*cli
,
2774 struct rpc_pipe_client
*pipe_hnd
,
2775 TALLOC_CTX
*mem_ctx
,
2779 struct policy_handle connect_pol
, domain_pol
;
2780 NTSTATUS status
, result
;
2781 uint32_t start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2782 struct samr_SamArray
*groups
= NULL
;
2783 bool global
= false;
2785 bool builtin
= false;
2786 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
2788 if (c
->display_usage
) {
2791 _("net rpc group list [global] [local] [builtin]\n"
2792 " List groups on RPC server\n"
2793 " global\tList global groups\n"
2794 " local\tList local groups\n"
2795 " builtin\tList builtin groups\n"
2796 " If none of global, local or builtin is "
2797 "specified, all three options are considered "
2799 return NT_STATUS_OK
;
2808 for (i
=0; i
<argc
; i
++) {
2809 if (strequal(argv
[i
], "global"))
2812 if (strequal(argv
[i
], "local"))
2815 if (strequal(argv
[i
], "builtin"))
2819 /* Get sam policy handle */
2821 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
2823 MAXIMUM_ALLOWED_ACCESS
,
2826 if (!NT_STATUS_IS_OK(status
)) {
2829 if (!NT_STATUS_IS_OK(result
)) {
2834 /* Get domain policy handle */
2836 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2838 MAXIMUM_ALLOWED_ACCESS
,
2839 discard_const_p(struct dom_sid2
, domain_sid
),
2842 if (!NT_STATUS_IS_OK(status
)) {
2845 if (!NT_STATUS_IS_OK(result
)) {
2850 /* Query domain groups */
2851 if (c
->opt_long_list_entries
)
2852 d_printf(_("\nGroup name Comment"
2853 "\n-----------------------------\n"));
2855 uint32_t max_size
, total_size
, returned_size
;
2856 union samr_DispInfo info
;
2860 dcerpc_get_query_dispinfo_params(
2861 loop_count
, &max_entries
, &max_size
);
2863 status
= dcerpc_samr_QueryDisplayInfo(b
, mem_ctx
,
2873 if (!NT_STATUS_IS_OK(status
)) {
2876 num_entries
= info
.info3
.count
;
2877 start_idx
+= info
.info3
.count
;
2879 if (!NT_STATUS_IS_OK(result
) &&
2880 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2883 for (i
= 0; i
< num_entries
; i
++) {
2885 const char *group
= NULL
;
2886 const char *desc
= NULL
;
2888 group
= info
.info3
.entries
[i
].account_name
.string
;
2889 desc
= info
.info3
.entries
[i
].description
.string
;
2891 if (c
->opt_long_list_entries
)
2892 printf("%-21.21s %-50.50s\n",
2895 printf("%s\n", group
);
2897 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2898 /* query domain aliases */
2903 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2910 if (!NT_STATUS_IS_OK(status
)) {
2913 if (!NT_STATUS_IS_OK(result
) &&
2914 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2917 for (i
= 0; i
< num_entries
; i
++) {
2919 const char *description
= NULL
;
2921 if (c
->opt_long_list_entries
) {
2923 struct policy_handle alias_pol
;
2924 union samr_AliasInfo
*info
= NULL
;
2927 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
2930 groups
->entries
[i
].idx
,
2933 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2934 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
2939 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2940 status
= dcerpc_samr_Close(b
, mem_ctx
,
2943 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
2944 description
= info
->description
.string
;
2950 if (description
!= NULL
) {
2951 printf("%-21.21s %-50.50s\n",
2952 groups
->entries
[i
].name
.string
,
2955 printf("%s\n", groups
->entries
[i
].name
.string
);
2958 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2959 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
2960 /* Get builtin policy handle */
2962 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
2964 MAXIMUM_ALLOWED_ACCESS
,
2965 discard_const_p(struct dom_sid2
, &global_sid_Builtin
),
2968 if (!NT_STATUS_IS_OK(status
)) {
2971 if (!NT_STATUS_IS_OK(result
)) {
2976 /* query builtin aliases */
2979 if (!builtin
) break;
2981 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
2988 if (!NT_STATUS_IS_OK(status
)) {
2991 if (!NT_STATUS_IS_OK(result
) &&
2992 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
2997 for (i
= 0; i
< num_entries
; i
++) {
2999 const char *description
= NULL
;
3001 if (c
->opt_long_list_entries
) {
3003 struct policy_handle alias_pol
;
3004 union samr_AliasInfo
*info
= NULL
;
3007 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
3010 groups
->entries
[i
].idx
,
3013 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
3014 status
= dcerpc_samr_QueryAliasInfo(b
, mem_ctx
,
3019 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
3020 status
= dcerpc_samr_Close(b
, mem_ctx
,
3023 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(_result
)) {
3024 description
= info
->description
.string
;
3030 if (description
!= NULL
) {
3031 printf("%-21.21s %-50.50s\n",
3032 groups
->entries
[i
].name
.string
,
3035 printf("%s\n", groups
->entries
[i
].name
.string
);
3038 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3046 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
3048 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3049 rpc_group_list_internals
,
3053 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
3054 struct rpc_pipe_client
*pipe_hnd
,
3055 TALLOC_CTX
*mem_ctx
,
3056 const char *domain_name
,
3057 const struct dom_sid
*domain_sid
,
3058 struct policy_handle
*domain_pol
,
3061 NTSTATUS result
, status
;
3062 struct policy_handle group_pol
;
3063 uint32_t num_members
, *group_rids
;
3065 struct samr_RidAttrArray
*rids
= NULL
;
3066 struct lsa_Strings names
;
3067 struct samr_Ids types
;
3068 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3070 status
= dcerpc_samr_OpenGroup(b
, mem_ctx
,
3072 MAXIMUM_ALLOWED_ACCESS
,
3076 if (!NT_STATUS_IS_OK(status
)) {
3079 if (!NT_STATUS_IS_OK(result
)) {
3083 status
= dcerpc_samr_QueryGroupMember(b
, mem_ctx
,
3087 if (!NT_STATUS_IS_OK(status
)) {
3090 if (!NT_STATUS_IS_OK(result
)) {
3094 num_members
= rids
->count
;
3095 group_rids
= rids
->rids
;
3097 while (num_members
> 0) {
3098 uint32_t this_time
= 512;
3100 if (num_members
< this_time
)
3101 this_time
= num_members
;
3103 status
= dcerpc_samr_LookupRids(b
, mem_ctx
,
3110 if (!NT_STATUS_IS_OK(status
)) {
3113 if (!NT_STATUS_IS_OK(result
)) {
3116 if (names
.count
!= this_time
) {
3117 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3119 if (types
.count
!= this_time
) {
3120 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3122 /* We only have users as members, but make the output
3123 the same as the output of alias members */
3125 for (i
= 0; i
< this_time
; i
++) {
3127 if (c
->opt_long_list_entries
) {
3129 struct dom_sid_buf sid_str
;
3131 sid_compose(&sid
, domain_sid
, group_rids
[i
]);
3133 printf("%s %s\\%s %d\n",
3134 dom_sid_str_buf(&sid
, &sid_str
),
3136 names
.names
[i
].string
,
3139 printf("%s\\%s\n", domain_name
,
3140 names
.names
[i
].string
);
3144 num_members
-= this_time
;
3148 return NT_STATUS_OK
;
3151 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
3152 struct rpc_pipe_client
*pipe_hnd
,
3153 struct cli_state
*cli
,
3154 TALLOC_CTX
*mem_ctx
,
3155 struct policy_handle
*domain_pol
,
3158 NTSTATUS result
, status
;
3159 struct rpc_pipe_client
*lsa_pipe
;
3160 struct policy_handle alias_pol
, lsa_pol
;
3161 uint32_t num_members
;
3162 struct dom_sid
*alias_sids
;
3165 enum lsa_SidType
*types
;
3167 struct lsa_SidArray sid_array
;
3168 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3170 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
3172 MAXIMUM_ALLOWED_ACCESS
,
3176 if (!NT_STATUS_IS_OK(status
)) {
3179 if (!NT_STATUS_IS_OK(result
)) {
3183 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
3187 if (!NT_STATUS_IS_OK(status
)) {
3188 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3191 if (!NT_STATUS_IS_OK(result
)) {
3192 d_fprintf(stderr
, _("Couldn't list alias members\n"));
3196 num_members
= sid_array
.num_sids
;
3198 if (num_members
== 0) {
3199 return NT_STATUS_OK
;
3202 result
= cli_rpc_pipe_open_noauth(cli
,
3205 if (!NT_STATUS_IS_OK(result
)) {
3206 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
3207 nt_errstr(result
) );
3211 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
3212 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
3214 if (!NT_STATUS_IS_OK(result
)) {
3215 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
3216 TALLOC_FREE(lsa_pipe
);
3220 alias_sids
= talloc_zero_array(mem_ctx
, struct dom_sid
, num_members
);
3222 d_fprintf(stderr
, _("Out of memory\n"));
3223 TALLOC_FREE(lsa_pipe
);
3224 return NT_STATUS_NO_MEMORY
;
3227 for (i
=0; i
<num_members
; i
++) {
3228 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
3231 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
3232 num_members
, alias_sids
,
3233 &domains
, &names
, &types
);
3235 if (!NT_STATUS_IS_OK(result
) &&
3236 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
3237 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
3238 TALLOC_FREE(lsa_pipe
);
3242 for (i
= 0; i
< num_members
; i
++) {
3243 struct dom_sid_buf sid_str
;
3244 dom_sid_str_buf(&alias_sids
[i
], &sid_str
);
3246 if (c
->opt_long_list_entries
) {
3247 printf("%s %s\\%s %d\n", sid_str
.buf
,
3248 domains
[i
] ? domains
[i
] : _("*unknown*"),
3249 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
3252 printf("%s\\%s\n", domains
[i
], names
[i
]);
3254 printf("%s\n", sid_str
.buf
);
3258 TALLOC_FREE(lsa_pipe
);
3259 return NT_STATUS_OK
;
3262 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
3263 const struct dom_sid
*domain_sid
,
3264 const char *domain_name
,
3265 struct cli_state
*cli
,
3266 struct rpc_pipe_client
*pipe_hnd
,
3267 TALLOC_CTX
*mem_ctx
,
3271 NTSTATUS result
, status
;
3272 struct policy_handle connect_pol
, domain_pol
;
3273 struct samr_Ids rids
, rid_types
;
3274 struct lsa_String lsa_acct_name
;
3275 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3277 /* Get sam policy handle */
3279 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
3281 MAXIMUM_ALLOWED_ACCESS
,
3284 if (!NT_STATUS_IS_OK(status
)) {
3287 if (!NT_STATUS_IS_OK(result
)) {
3291 /* Get domain policy handle */
3293 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3295 MAXIMUM_ALLOWED_ACCESS
,
3296 discard_const_p(struct dom_sid2
, domain_sid
),
3299 if (!NT_STATUS_IS_OK(status
)) {
3302 if (!NT_STATUS_IS_OK(result
)) {
3306 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
3308 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3315 if (!NT_STATUS_IS_OK(status
)) {
3319 if (!NT_STATUS_IS_OK(result
)) {
3321 /* Ok, did not find it in the global sam, try with builtin */
3323 struct dom_sid sid_Builtin
;
3325 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
3327 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
3329 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
3331 MAXIMUM_ALLOWED_ACCESS
,
3335 if (!NT_STATUS_IS_OK(status
)) {
3338 if (!NT_STATUS_IS_OK(result
)) {
3339 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3344 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
3351 if (!NT_STATUS_IS_OK(status
)) {
3354 if (!NT_STATUS_IS_OK(result
)) {
3355 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3361 if (rids
.count
!= 1) {
3362 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3364 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3366 if (rid_types
.count
!= 1) {
3367 d_fprintf(stderr
, _("Couldn't find group %s\n"),
3369 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
3373 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
3374 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
3375 domain_sid
, &domain_pol
,
3379 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
3380 return rpc_list_alias_members(c
, pipe_hnd
, cli
, mem_ctx
, &domain_pol
,
3384 return NT_STATUS_NO_SUCH_GROUP
;
3387 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
3389 if (argc
!= 1 || c
->display_usage
) {
3390 return rpc_group_usage(c
, argc
, argv
);
3393 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3394 rpc_group_members_internals
,
3398 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
3400 NET_API_STATUS status
;
3401 struct GROUP_INFO_0 g0
;
3405 d_printf(_("Usage:\n"));
3406 d_printf("net rpc group rename group newname\n");
3410 g0
.grpi0_name
= argv
[1];
3412 status
= NetGroupSetInfo(c
->opt_host
,
3419 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
3420 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
3428 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
3430 if (argc
!= 2 || c
->display_usage
) {
3431 return rpc_group_usage(c
, argc
, argv
);
3434 return rpc_group_rename_internals(c
, argc
, argv
);
3438 * 'net rpc group' entrypoint.
3439 * @param argc Standard main() style argc.
3440 * @param argv Standard main() style argv. Initial components are already
3444 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
3446 NET_API_STATUS status
;
3448 struct functable func
[] = {
3453 N_("Create specified group"),
3454 N_("net rpc group add\n"
3455 " Create specified group")
3461 N_("Delete specified group"),
3462 N_("net rpc group delete\n"
3463 " Delete specified group")
3469 N_("Add member to group"),
3470 N_("net rpc group addmem\n"
3471 " Add member to group")
3477 N_("Remove member from group"),
3478 N_("net rpc group delmem\n"
3479 " Remove member from group")
3486 N_("net rpc group list\n"
3493 N_("List group members"),
3494 N_("net rpc group members\n"
3495 " List group members")
3502 N_("net rpc group rename\n"
3505 {NULL
, NULL
, 0, NULL
, NULL
}
3508 status
= libnetapi_net_init(&c
->netapi_ctx
);
3513 status
= libnetapi_set_creds(c
->netapi_ctx
, c
->creds
);
3519 if (c
->display_usage
) {
3520 d_printf(_("Usage:\n"));
3521 d_printf(_("net rpc group\n"
3522 " Alias for net rpc group list global "
3523 "local builtin\n"));
3524 net_display_usage_from_functable(func
);
3528 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
3529 rpc_group_list_internals
,
3533 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
3536 /****************************************************************************/
3538 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
3540 return net_share_usage(c
, argc
, argv
);
3544 * Add a share on a remote RPC server.
3546 * @param argc Standard main() style argc.
3547 * @param argv Standard main() style argv. Initial components are already
3550 * @return A shell status integer (0 for success).
3553 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
3555 NET_API_STATUS status
;
3558 uint32_t type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3559 uint32_t num_users
=0, perms
=0;
3560 char *password
=NULL
; /* don't allow a share password */
3561 struct SHARE_INFO_2 i2
;
3562 uint32_t parm_error
= 0;
3564 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
3565 return rpc_share_usage(c
, argc
, argv
);
3568 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
3572 path
= strchr(sharename
, '=');
3579 i2
.shi2_netname
= sharename
;
3580 i2
.shi2_type
= type
;
3581 i2
.shi2_remark
= c
->opt_comment
;
3582 i2
.shi2_permissions
= perms
;
3583 i2
.shi2_max_uses
= c
->opt_maxusers
;
3584 i2
.shi2_current_uses
= num_users
;
3585 i2
.shi2_path
= path
;
3586 i2
.shi2_passwd
= password
;
3588 status
= NetShareAdd(c
->opt_host
,
3593 printf(_("NetShareAdd failed with: %s\n"),
3594 libnetapi_get_error_string(c
->netapi_ctx
, status
));
3601 * Delete a share on a remote RPC server.
3603 * @param domain_sid The domain sid acquired from the remote server.
3604 * @param argc Standard main() style argc.
3605 * @param argv Standard main() style argv. Initial components are already
3608 * @return A shell status integer (0 for success).
3610 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
3612 if (argc
< 1 || c
->display_usage
) {
3613 return rpc_share_usage(c
, argc
, argv
);
3616 return NetShareDel(c
->opt_host
, argv
[0], 0);
3620 * Formatted print of share info
3622 * @param r pointer to SHARE_INFO_1 to format
3625 static void display_share_info_1(struct net_context
*c
,
3626 struct SHARE_INFO_1
*r
)
3628 if (c
->opt_long_list_entries
) {
3629 d_printf("%-12s %-8.8s %-50s\n",
3631 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
3634 d_printf("%s\n", r
->shi1_netname
);
3638 static WERROR
get_share_info(struct net_context
*c
,
3639 struct rpc_pipe_client
*pipe_hnd
,
3640 TALLOC_CTX
*mem_ctx
,
3644 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3648 union srvsvc_NetShareInfo info
;
3649 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
3651 /* no specific share requested, enumerate all */
3654 uint32_t preferred_len
= 0xffffffff;
3655 uint32_t total_entries
= 0;
3656 uint32_t resume_handle
= 0;
3658 info_ctr
->level
= level
;
3660 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
3667 if (!NT_STATUS_IS_OK(status
)) {
3668 return ntstatus_to_werror(status
);
3673 /* request just one share */
3674 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
3681 if (!NT_STATUS_IS_OK(status
)) {
3682 result
= ntstatus_to_werror(status
);
3686 if (!W_ERROR_IS_OK(result
)) {
3691 ZERO_STRUCTP(info_ctr
);
3693 info_ctr
->level
= level
;
3698 struct srvsvc_NetShareCtr1
*ctr1
;
3700 ctr1
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr1
);
3701 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3704 ctr1
->array
= info
.info1
;
3706 info_ctr
->ctr
.ctr1
= ctr1
;
3712 struct srvsvc_NetShareCtr2
*ctr2
;
3714 ctr2
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr2
);
3715 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3718 ctr2
->array
= info
.info2
;
3720 info_ctr
->ctr
.ctr2
= ctr2
;
3726 struct srvsvc_NetShareCtr502
*ctr502
;
3728 ctr502
= talloc_zero(mem_ctx
, struct srvsvc_NetShareCtr502
);
3729 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3732 ctr502
->array
= info
.info502
;
3734 info_ctr
->ctr
.ctr502
= ctr502
;
3744 * 'net rpc share list' entrypoint.
3745 * @param argc Standard main() style argc.
3746 * @param argv Standard main() style argv. Initial components are already
3749 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3751 NET_API_STATUS status
;
3752 struct SHARE_INFO_1
*i1
= NULL
;
3753 uint32_t entries_read
= 0;
3754 uint32_t total_entries
= 0;
3755 uint32_t resume_handle
= 0;
3756 uint32_t i
, level
= 1;
3758 if (c
->display_usage
) {
3760 "net rpc share list\n"
3763 _("List shares on remote server"));
3767 status
= NetShareEnum(c
->opt_host
,
3769 (uint8_t **)(void *)&i1
,
3778 /* Display results */
3780 if (c
->opt_long_list_entries
) {
3782 "\nEnumerating shared resources (exports) on remote server:\n\n"
3783 "\nShare name Type Description\n"
3784 "---------- ---- -----------\n"));
3786 for (i
= 0; i
< entries_read
; i
++)
3787 display_share_info_1(c
, &i1
[i
]);
3792 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3796 status
= cli_tree_connect(cli
, netname
, "A:", NULL
);
3797 if (!NT_STATUS_IS_OK(status
)) {
3798 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3802 status
= cli_tdis(cli
);
3803 if (!NT_STATUS_IS_OK(status
)) {
3804 d_printf(_("cli_tdis returned %s\n"), nt_errstr(status
));
3811 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3812 const char *netname
, uint32_t type
)
3814 /* only support disk shares */
3815 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3816 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3821 /* skip builtin shares */
3822 /* FIXME: should print$ be added too ? */
3823 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3824 strequal(netname
,"global"))
3827 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3828 printf(_("excluding [%s]\n"), netname
);
3832 return check_share_availability(cli
, netname
);
3836 * Migrate shares from a remote RPC server to the local RPC server.
3838 * All parameters are provided by the run_rpc_command function, except for
3839 * argc, argv which are passed through.
3841 * @param domain_sid The domain sid acquired from the remote server.
3842 * @param cli A cli_state connected to the server.
3843 * @param mem_ctx Talloc context, destroyed on completion of the function.
3844 * @param argc Standard main() style argc.
3845 * @param argv Standard main() style argv. Initial components are already
3848 * @return Normal NTSTATUS return.
3851 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3852 const struct dom_sid
*domain_sid
,
3853 const char *domain_name
,
3854 struct cli_state
*cli
,
3855 struct rpc_pipe_client
*pipe_hnd
,
3856 TALLOC_CTX
*mem_ctx
,
3861 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3862 struct srvsvc_NetShareInfoCtr ctr_src
;
3864 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3865 struct cli_state
*cli_dst
= NULL
;
3866 uint32_t level
= 502; /* includes secdesc */
3867 uint32_t parm_error
= 0;
3868 struct dcerpc_binding_handle
*b
;
3870 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3872 if (!W_ERROR_IS_OK(result
))
3875 /* connect destination PI_SRVSVC */
3876 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3878 if (!NT_STATUS_IS_OK(nt_status
))
3881 b
= srvsvc_pipe
->binding_handle
;
3883 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3885 union srvsvc_NetShareInfo info
;
3886 struct srvsvc_NetShareInfo502 info502
=
3887 ctr_src
.ctr
.ctr502
->array
[i
];
3889 /* reset error-code */
3890 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3892 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3895 /* finally add the share on the dst server */
3897 printf(_("migrating: [%s], path: %s, comment: %s, without "
3899 info502
.name
, info502
.path
, info502
.comment
);
3901 info
.info502
= &info502
;
3903 nt_status
= dcerpc_srvsvc_NetShareAdd(b
, mem_ctx
,
3904 srvsvc_pipe
->desthost
,
3909 if (!NT_STATUS_IS_OK(nt_status
)) {
3910 printf(_("cannot add share: %s\n"),
3911 nt_errstr(nt_status
));
3914 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3915 printf(_(" [%s] does already exist\n"),
3920 if (!W_ERROR_IS_OK(result
)) {
3921 nt_status
= werror_to_ntstatus(result
);
3922 printf(_("cannot add share: %s\n"),
3923 win_errstr(result
));
3929 nt_status
= NT_STATUS_OK
;
3933 cli_shutdown(cli_dst
);
3941 * Migrate shares from a RPC server to another.
3943 * @param argc Standard main() style argc.
3944 * @param argv Standard main() style argv. Initial components are already
3947 * @return A shell status integer (0 for success).
3949 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3952 if (c
->display_usage
) {
3954 "net rpc share migrate shares\n"
3957 _("Migrate shares to local server"));
3962 printf(_("no server to migrate\n"));
3966 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
3967 rpc_share_migrate_shares_internals
,
3974 * @param f file_info
3975 * @param mask current search mask
3976 * @param state arg-pointer
3979 static NTSTATUS
copy_fn(struct file_info
*f
,
3980 const char *mask
, void *state
)
3982 static NTSTATUS nt_status
;
3983 static struct copy_clistate
*local_state
;
3984 static fstring filename
, new_mask
;
3987 struct net_context
*c
;
3989 local_state
= (struct copy_clistate
*)state
;
3990 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3994 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3995 return NT_STATUS_OK
;
3997 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
4000 if (f
->attr
& FILE_ATTRIBUTE_DIRECTORY
) {
4002 DEBUG(3,("got dir: %s\n", f
->name
));
4004 fstrcpy(dir
, local_state
->cwd
);
4006 fstrcat(dir
, f
->name
);
4008 switch (net_mode_share
)
4010 case NET_MODE_SHARE_MIGRATE
:
4011 /* create that directory */
4012 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
4013 local_state
->cli_share_src
,
4014 local_state
->cli_share_dst
,
4016 c
->opt_acls
? true : false,
4017 c
->opt_attrs
? true : false,
4018 c
->opt_timestamps
? true:false,
4022 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
4023 return NT_STATUS_INTERNAL_ERROR
;
4026 if (!NT_STATUS_IS_OK(nt_status
)) {
4027 printf(_("could not handle dir %s: %s\n"),
4028 dir
, nt_errstr(nt_status
));
4032 /* search below that directory */
4033 if (strlcpy(new_mask
, dir
, sizeof(new_mask
)) >= sizeof(new_mask
)) {
4034 return NT_STATUS_NO_MEMORY
;
4036 if (strlcat(new_mask
, "\\*", sizeof(new_mask
)) >= sizeof(new_mask
)) {
4037 return NT_STATUS_NO_MEMORY
;
4040 old_dir
= local_state
->cwd
;
4041 local_state
->cwd
= dir
;
4042 nt_status
= sync_files(local_state
, new_mask
);
4043 if (!NT_STATUS_IS_OK(nt_status
)) {
4044 printf(_("could not handle files\n"));
4046 local_state
->cwd
= old_dir
;
4053 fstrcpy(filename
, local_state
->cwd
);
4054 fstrcat(filename
, "\\");
4055 fstrcat(filename
, f
->name
);
4057 DEBUG(3,("got file: %s\n", filename
));
4059 switch (net_mode_share
)
4061 case NET_MODE_SHARE_MIGRATE
:
4062 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
4063 local_state
->cli_share_src
,
4064 local_state
->cli_share_dst
,
4066 c
->opt_acls
? true : false,
4067 c
->opt_attrs
? true : false,
4068 c
->opt_timestamps
? true: false,
4072 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
4074 return NT_STATUS_INTERNAL_ERROR
;
4077 if (!NT_STATUS_IS_OK(nt_status
))
4078 printf(_("could not handle file %s: %s\n"),
4079 filename
, nt_errstr(nt_status
));
4084 * sync files, can be called recursively to list files
4085 * and then call copy_fn for each file
4087 * @param cp_clistate pointer to the copy_clistate we work with
4088 * @param mask the current search mask
4090 * @return Boolean result
4092 static NTSTATUS
sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
4094 struct cli_state
*targetcli
;
4095 char *targetpath
= NULL
;
4098 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
4100 status
= cli_resolve_path(talloc_tos(), "", NULL
,
4101 cp_clistate
->cli_share_src
,
4102 mask
, &targetcli
, &targetpath
);
4103 if (!NT_STATUS_IS_OK(status
)) {
4104 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
4106 mask
, nt_errstr(status
));
4110 status
= cli_list(targetcli
, targetpath
, cp_clistate
->attribute
,
4111 copy_fn
, cp_clistate
);
4112 if (!NT_STATUS_IS_OK(status
)) {
4113 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
4114 mask
, nt_errstr(status
));
4122 * Set the top level directory permissions before we do any further copies.
4123 * Should set up ACL inheritance.
4126 bool copy_top_level_perms(struct net_context
*c
,
4127 struct copy_clistate
*cp_clistate
,
4128 const char *sharename
)
4130 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4132 switch (net_mode_share
) {
4133 case NET_MODE_SHARE_MIGRATE
:
4134 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
4135 nt_status
= net_copy_fileattr(c
,
4136 cp_clistate
->mem_ctx
,
4137 cp_clistate
->cli_share_src
,
4138 cp_clistate
->cli_share_dst
,
4140 c
->opt_acls
? true : false,
4141 c
->opt_attrs
? true : false,
4142 c
->opt_timestamps
? true: false,
4146 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
4150 if (!NT_STATUS_IS_OK(nt_status
)) {
4151 printf(_("Could handle directory attributes for top level "
4152 "directory of share %s. Error %s\n"),
4153 sharename
, nt_errstr(nt_status
));
4161 * Sync all files inside a remote share to another share (over smb).
4163 * All parameters are provided by the run_rpc_command function, except for
4164 * argc, argv which are passed through.
4166 * @param domain_sid The domain sid acquired from the remote server.
4167 * @param cli A cli_state connected to the server.
4168 * @param mem_ctx Talloc context, destroyed on completion of the function.
4169 * @param argc Standard main() style argc.
4170 * @param argv Standard main() style argv. Initial components are already
4173 * @return Normal NTSTATUS return.
4176 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
4177 const struct dom_sid
*domain_sid
,
4178 const char *domain_name
,
4179 struct cli_state
*cli
,
4180 struct rpc_pipe_client
*pipe_hnd
,
4181 TALLOC_CTX
*mem_ctx
,
4186 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4187 struct srvsvc_NetShareInfoCtr ctr_src
;
4189 uint32_t level
= 502;
4190 struct copy_clistate cp_clistate
;
4191 bool got_src_share
= false;
4192 bool got_dst_share
= false;
4193 const char *mask
= "\\*";
4196 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
4198 nt_status
= NT_STATUS_NO_MEMORY
;
4202 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4205 if (!W_ERROR_IS_OK(result
))
4208 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4210 struct srvsvc_NetShareInfo502 info502
=
4211 ctr_src
.ctr
.ctr502
->array
[i
];
4213 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4216 /* one might not want to mirror whole discs :) */
4217 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
4218 d_printf(_("skipping [%s]: builtin/hidden share\n"),
4223 switch (net_mode_share
)
4225 case NET_MODE_SHARE_MIGRATE
:
4229 d_fprintf(stderr
, _("Unsupported mode %d\n"),
4233 printf(_(" [%s] files and directories %s ACLs, %s DOS "
4236 c
->opt_acls
? _("including") : _("without"),
4237 c
->opt_attrs
? _("including") : _("without"),
4238 c
->opt_timestamps
? _("(preserving timestamps)") : "");
4240 cp_clistate
.mem_ctx
= mem_ctx
;
4241 cp_clistate
.cli_share_src
= NULL
;
4242 cp_clistate
.cli_share_dst
= NULL
;
4243 cp_clistate
.cwd
= NULL
;
4244 cp_clistate
.attribute
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
;
4247 /* open share source */
4248 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
4249 smbXcli_conn_remote_sockaddr(cli
->conn
),
4250 smbXcli_conn_remote_name(cli
->conn
),
4251 info502
.name
, "A:");
4252 if (!NT_STATUS_IS_OK(nt_status
))
4255 got_src_share
= true;
4257 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
4258 /* open share destination */
4259 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
4260 NULL
, dst
, info502
.name
, "A:");
4261 if (!NT_STATUS_IS_OK(nt_status
))
4264 got_dst_share
= true;
4267 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
4268 d_fprintf(stderr
, _("Could not handle the top level "
4269 "directory permissions for the "
4270 "share: %s\n"), info502
.name
);
4271 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4275 nt_status
= sync_files(&cp_clistate
, mask
);
4276 if (!NT_STATUS_IS_OK(nt_status
)) {
4277 d_fprintf(stderr
, _("could not handle files for share: "
4278 "%s\n"), info502
.name
);
4283 nt_status
= NT_STATUS_OK
;
4288 cli_shutdown(cp_clistate
.cli_share_src
);
4291 cli_shutdown(cp_clistate
.cli_share_dst
);
4298 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
4300 if (c
->display_usage
) {
4302 "net share migrate files\n"
4305 _("Migrate files to local server"));
4310 d_printf(_("no server to migrate\n"));
4314 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4315 rpc_share_migrate_files_internals
,
4320 * Migrate share-ACLs from a remote RPC server to the local RPC server.
4322 * All parameters are provided by the run_rpc_command function, except for
4323 * argc, argv which are passed through.
4325 * @param domain_sid The domain sid acquired from the remote server.
4326 * @param cli A cli_state connected to the server.
4327 * @param mem_ctx Talloc context, destroyed on completion of the function.
4328 * @param argc Standard main() style argc.
4329 * @param argv Standard main() style argv. Initial components are already
4332 * @return Normal NTSTATUS return.
4335 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
4336 const struct dom_sid
*domain_sid
,
4337 const char *domain_name
,
4338 struct cli_state
*cli
,
4339 struct rpc_pipe_client
*pipe_hnd
,
4340 TALLOC_CTX
*mem_ctx
,
4345 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4346 struct srvsvc_NetShareInfoCtr ctr_src
;
4347 union srvsvc_NetShareInfo info
;
4349 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
4350 struct cli_state
*cli_dst
= NULL
;
4351 uint32_t level
= 502; /* includes secdesc */
4352 uint32_t parm_error
= 0;
4353 struct dcerpc_binding_handle
*b
;
4355 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
4358 if (!W_ERROR_IS_OK(result
))
4361 /* connect destination PI_SRVSVC */
4362 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
4364 if (!NT_STATUS_IS_OK(nt_status
))
4367 b
= srvsvc_pipe
->binding_handle
;
4369 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4371 struct srvsvc_NetShareInfo502 info502
=
4372 ctr_src
.ctr
.ctr502
->array
[i
];
4374 /* reset error-code */
4375 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4377 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
4380 printf(_("migrating: [%s], path: %s, comment: %s, including "
4382 info502
.name
, info502
.path
, info502
.comment
);
4385 display_sec_desc(info502
.sd_buf
.sd
);
4387 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4388 info
.info502
= &info502
;
4390 /* finally modify the share on the dst server */
4391 nt_status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
4392 srvsvc_pipe
->desthost
,
4398 if (!NT_STATUS_IS_OK(nt_status
)) {
4399 printf(_("cannot set share-acl: %s\n"),
4400 nt_errstr(nt_status
));
4403 if (!W_ERROR_IS_OK(result
)) {
4404 nt_status
= werror_to_ntstatus(result
);
4405 printf(_("cannot set share-acl: %s\n"),
4406 win_errstr(result
));
4412 nt_status
= NT_STATUS_OK
;
4416 cli_shutdown(cli_dst
);
4424 * Migrate share-acls from a RPC server to another.
4426 * @param argc Standard main() style argc.
4427 * @param argv Standard main() style argv. Initial components are already
4430 * @return A shell status integer (0 for success).
4432 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
4435 if (c
->display_usage
) {
4437 "net rpc share migrate security\n"
4440 _("Migrate share-acls to local server"));
4445 d_printf(_("no server to migrate\n"));
4449 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4450 rpc_share_migrate_security_internals
,
4455 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4456 * from one server to another.
4458 * @param argc Standard main() style argc.
4459 * @param argv Standard main() style argv. Initial components are already
4462 * @return A shell status integer (0 for success).
4465 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
4470 if (c
->display_usage
) {
4472 "net rpc share migrate all\n"
4475 _("Migrates shares including all share settings"));
4480 d_printf(_("no server to migrate\n"));
4484 /* order is important. we don't want to be locked out by the share-acl
4485 * before copying files - gd */
4487 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4488 rpc_share_migrate_shares_internals
, argc
, argv
);
4492 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4493 rpc_share_migrate_files_internals
, argc
, argv
);
4497 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
4498 rpc_share_migrate_security_internals
, argc
,
4504 * 'net rpc share migrate' entrypoint.
4505 * @param argc Standard main() style argc.
4506 * @param argv Standard main() style argv. Initial components are already
4509 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
4512 struct functable func
[] = {
4515 rpc_share_migrate_all
,
4517 N_("Migrate shares from remote to local server"),
4518 N_("net rpc share migrate all\n"
4519 " Migrate shares from remote to local server")
4523 rpc_share_migrate_files
,
4525 N_("Migrate files from remote to local server"),
4526 N_("net rpc share migrate files\n"
4527 " Migrate files from remote to local server")
4531 rpc_share_migrate_security
,
4533 N_("Migrate share-ACLs from remote to local server"),
4534 N_("net rpc share migrate security\n"
4535 " Migrate share-ACLs from remote to local server")
4539 rpc_share_migrate_shares
,
4541 N_("Migrate shares from remote to local server"),
4542 N_("net rpc share migrate shares\n"
4543 " Migrate shares from remote to local server")
4545 {NULL
, NULL
, 0, NULL
, NULL
}
4548 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
4550 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
4555 uint32_t num_members
;
4556 struct dom_sid
*members
;
4559 static int num_server_aliases
;
4560 static struct full_alias
*server_aliases
;
4563 * Add an alias to the static list.
4565 static void push_alias(struct full_alias
*alias
)
4569 if (server_aliases
== NULL
) {
4570 server_aliases
= talloc_array(NULL
, struct full_alias
, 100);
4571 if (server_aliases
== NULL
) {
4572 smb_panic("talloc_array failed");
4576 array_size
= talloc_array_length(server_aliases
);
4577 if (array_size
== num_server_aliases
) {
4578 server_aliases
= talloc_realloc(NULL
, server_aliases
,
4579 struct full_alias
, array_size
+ 100);
4580 if (server_aliases
== NULL
) {
4581 smb_panic("talloc_realloc failed");
4585 server_aliases
[num_server_aliases
] = *alias
;
4586 num_server_aliases
+= 1;
4590 * For a specific domain on the server, fetch all the aliases
4591 * and their members. Add all of them to the server_aliases.
4594 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
4595 TALLOC_CTX
*mem_ctx
,
4596 struct policy_handle
*connect_pol
,
4597 const struct dom_sid
*domain_sid
)
4599 uint32_t start_idx
, max_entries
, num_entries
, i
;
4600 struct samr_SamArray
*groups
= NULL
;
4601 NTSTATUS result
, status
;
4602 struct policy_handle domain_pol
;
4603 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4605 /* Get domain policy handle */
4607 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
4609 MAXIMUM_ALLOWED_ACCESS
,
4610 discard_const_p(struct dom_sid2
, domain_sid
),
4613 if (!NT_STATUS_IS_OK(status
)) {
4616 if (!NT_STATUS_IS_OK(result
)) {
4624 status
= dcerpc_samr_EnumDomainAliases(b
, mem_ctx
,
4631 if (!NT_STATUS_IS_OK(status
)) {
4634 for (i
= 0; i
< num_entries
; i
++) {
4636 struct policy_handle alias_pol
;
4637 struct full_alias alias
;
4638 struct lsa_SidArray sid_array
;
4642 status
= dcerpc_samr_OpenAlias(b
, mem_ctx
,
4644 MAXIMUM_ALLOWED_ACCESS
,
4645 groups
->entries
[i
].idx
,
4648 if (!NT_STATUS_IS_OK(status
)) {
4651 if (!NT_STATUS_IS_OK(_result
)) {
4656 status
= dcerpc_samr_GetMembersInAlias(b
, mem_ctx
,
4660 if (!NT_STATUS_IS_OK(status
)) {
4663 if (!NT_STATUS_IS_OK(_result
)) {
4668 alias
.num_members
= sid_array
.num_sids
;
4670 status
= dcerpc_samr_Close(b
, mem_ctx
, &alias_pol
, &_result
);
4671 if (!NT_STATUS_IS_OK(status
)) {
4674 if (!NT_STATUS_IS_OK(_result
)) {
4679 alias
.members
= NULL
;
4681 if (alias
.num_members
> 0) {
4682 alias
.members
= SMB_MALLOC_ARRAY(struct dom_sid
, alias
.num_members
);
4683 if (alias
.members
== NULL
) {
4684 status
= NT_STATUS_NO_MEMORY
;
4688 for (j
= 0; j
< alias
.num_members
; j
++)
4689 sid_copy(&alias
.members
[j
],
4690 sid_array
.sids
[j
].sid
);
4693 sid_compose(&alias
.sid
, domain_sid
,
4694 groups
->entries
[i
].idx
);
4698 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4700 status
= NT_STATUS_OK
;
4703 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
4709 * Dump server_aliases as names for debugging purposes.
4712 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
4713 const struct dom_sid
*domain_sid
,
4714 const char *domain_name
,
4715 struct cli_state
*cli
,
4716 struct rpc_pipe_client
*pipe_hnd
,
4717 TALLOC_CTX
*mem_ctx
,
4723 struct policy_handle lsa_pol
;
4724 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4726 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
4727 SEC_FLAG_MAXIMUM_ALLOWED
,
4729 if (!NT_STATUS_IS_OK(result
))
4732 for (i
=0; i
<num_server_aliases
; i
++) {
4735 enum lsa_SidType
*types
;
4738 struct full_alias
*alias
= &server_aliases
[i
];
4740 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4742 &domains
, &names
, &types
);
4743 if (!NT_STATUS_IS_OK(result
))
4746 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4748 if (alias
->num_members
== 0) {
4753 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4756 &domains
, &names
, &types
);
4758 if (!NT_STATUS_IS_OK(result
) &&
4759 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4762 for (j
=0; j
<alias
->num_members
; j
++)
4763 DEBUG(1, ("%s\\%s (%d); ",
4764 domains
[j
] ? domains
[j
] : "*unknown*",
4765 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4769 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
4771 return NT_STATUS_OK
;
4775 * Fetch a list of all server aliases and their members into
4779 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
4780 const struct dom_sid
*domain_sid
,
4781 const char *domain_name
,
4782 struct cli_state
*cli
,
4783 struct rpc_pipe_client
*pipe_hnd
,
4784 TALLOC_CTX
*mem_ctx
,
4788 NTSTATUS result
, status
;
4789 struct policy_handle connect_pol
;
4790 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
4792 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
4794 MAXIMUM_ALLOWED_ACCESS
,
4797 if (!NT_STATUS_IS_OK(status
)) {
4800 if (!NT_STATUS_IS_OK(result
)) {
4805 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4806 &global_sid_Builtin
);
4807 if (!NT_STATUS_IS_OK(status
)) {
4811 status
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4814 dcerpc_samr_Close(b
, mem_ctx
, &connect_pol
, &result
);
4819 static void init_user_token(struct security_token
*token
, struct dom_sid
*user_sid
)
4821 token
->num_sids
= 4;
4823 if (!(token
->sids
= SMB_MALLOC_ARRAY(struct dom_sid
, 4))) {
4824 d_fprintf(stderr
, "malloc %s\n",_("failed"));
4825 token
->num_sids
= 0;
4829 token
->sids
[0] = *user_sid
;
4830 sid_copy(&token
->sids
[1], &global_sid_World
);
4831 sid_copy(&token
->sids
[2], &global_sid_Network
);
4832 sid_copy(&token
->sids
[3], &global_sid_Authenticated_Users
);
4835 static void free_user_token(struct security_token
*token
)
4837 SAFE_FREE(token
->sids
);
4840 static void add_sid_to_token(struct security_token
*token
, struct dom_sid
*sid
)
4842 if (security_token_has_sid(token
, sid
))
4845 token
->sids
= SMB_REALLOC_ARRAY(token
->sids
, struct dom_sid
, token
->num_sids
+1);
4850 sid_copy(&token
->sids
[token
->num_sids
], sid
);
4852 token
->num_sids
+= 1;
4857 struct security_token token
;
4860 static void dump_user_token(struct user_token
*token
)
4864 d_printf("%s\n", token
->name
);
4866 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4867 struct dom_sid_buf buf
;
4869 dom_sid_str_buf(&token
->token
.sids
[i
], &buf
));
4873 static bool is_alias_member(struct dom_sid
*sid
, struct full_alias
*alias
)
4877 for (i
=0; i
<alias
->num_members
; i
++) {
4878 if (dom_sid_equal(sid
, &alias
->members
[i
])) {
4886 static void collect_sid_memberships(struct security_token
*token
, struct dom_sid sid
)
4890 for (i
=0; i
<num_server_aliases
; i
++) {
4891 if (is_alias_member(&sid
, &server_aliases
[i
]))
4892 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4897 * We got a user token with all the SIDs we can know about without asking the
4898 * server directly. These are the user and domain group sids. All of these can
4899 * be members of aliases. So scan the list of aliases for each of the SIDs and
4900 * add them to the token.
4903 static void collect_alias_memberships(struct security_token
*token
)
4905 int num_global_sids
= token
->num_sids
;
4908 for (i
=0; i
<num_global_sids
; i
++) {
4909 collect_sid_memberships(token
, token
->sids
[i
]);
4913 static bool get_user_sids(const char *domain
, const char *user
, struct security_token
*token
)
4915 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4916 enum wbcSidType type
;
4918 struct wbcDomainSid wsid
;
4919 char sid_str
[WBC_SID_STRING_BUFLEN
];
4920 struct dom_sid user_sid
;
4921 uint32_t num_groups
;
4922 gid_t
*groups
= NULL
;
4925 fstr_sprintf(full_name
, "%s%c%s",
4926 domain
, *lp_winbind_separator(), user
);
4928 /* First let's find out the user sid */
4930 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4932 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4933 DEBUG(1, ("winbind could not find %s: %s\n",
4934 full_name
, wbcErrorString(wbc_status
)));
4938 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4940 if (type
!= WBC_SID_NAME_USER
) {
4941 DEBUG(1, ("%s is not a user\n", full_name
));
4945 if (!string_to_sid(&user_sid
, sid_str
)) {
4946 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4950 init_user_token(token
, &user_sid
);
4952 /* And now the groups winbind knows about */
4954 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4955 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4956 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4957 full_name
, wbcErrorString(wbc_status
)));
4961 for (i
= 0; i
< num_groups
; i
++) {
4962 gid_t gid
= groups
[i
];
4966 wbc_status
= wbcGidToSid(gid
, &wsid
);
4967 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4968 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4969 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4970 wbcFreeMemory(groups
);
4974 wbcSidToStringBuf(&wsid
, sid_str
, sizeof(sid_str
));
4976 DEBUG(3, (" %s\n", sid_str
));
4978 ok
= string_to_sid(&sid
, sid_str
);
4980 DEBUG(1, ("Failed to convert string to SID\n"));
4981 wbcFreeMemory(groups
);
4984 add_sid_to_token(token
, &sid
);
4986 wbcFreeMemory(groups
);
4992 * Get a list of all user tokens we want to look at
4995 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4996 struct user_token
**user_tokens
)
4998 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4999 uint32_t i
, num_users
;
5001 struct user_token
*result
;
5002 TALLOC_CTX
*frame
= NULL
;
5004 if (lp_winbind_use_default_domain() &&
5005 (c
->opt_target_workgroup
== NULL
)) {
5006 d_fprintf(stderr
, _("winbind use default domain = yes set, "
5007 "please specify a workgroup\n"));
5011 /* Send request to winbind daemon */
5013 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
5014 if (!WBC_ERROR_IS_OK(wbc_status
)) {
5015 DEBUG(1, (_("winbind could not list users: %s\n"),
5016 wbcErrorString(wbc_status
)));
5020 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
5022 if (result
== NULL
) {
5023 DEBUG(1, ("Could not malloc sid array\n"));
5024 wbcFreeMemory(users
);
5028 frame
= talloc_stackframe();
5029 for (i
=0; i
< num_users
; i
++) {
5030 fstring domain
, user
;
5033 fstrcpy(result
[i
].name
, users
[i
]);
5035 p
= strchr(users
[i
], *lp_winbind_separator());
5037 DEBUG(3, ("%s\n", users
[i
]));
5040 fstrcpy(domain
, c
->opt_target_workgroup
);
5041 fstrcpy(user
, users
[i
]);
5044 fstrcpy(domain
, users
[i
]);
5045 if (!strupper_m(domain
)) {
5046 DEBUG(1, ("strupper_m %s failed\n", domain
));
5047 wbcFreeMemory(users
);
5053 get_user_sids(domain
, user
, &(result
[i
].token
));
5056 wbcFreeMemory(users
);
5058 *num_tokens
= num_users
;
5059 *user_tokens
= result
;
5064 static bool get_user_tokens_from_file(FILE *f
,
5066 struct user_token
**tokens
)
5068 struct user_token
*token
= NULL
;
5073 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
5077 if ((strlen(line
) > 0) && (line
[strlen(line
)-1] == '\n')) {
5078 line
[strlen(line
)-1] = '\0';
5081 if (line
[0] == ' ') {
5085 if(!string_to_sid(&sid
, &line
[1])) {
5086 DEBUG(1,("get_user_tokens_from_file: Could "
5087 "not convert sid %s \n",&line
[1]));
5091 if (token
== NULL
) {
5092 DEBUG(0, ("File does not begin with username"));
5096 add_sid_to_token(&token
->token
, &sid
);
5100 /* And a new user... */
5103 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
5104 if (*tokens
== NULL
) {
5105 DEBUG(0, ("Could not realloc tokens\n"));
5109 token
= &((*tokens
)[*num_tokens
-1]);
5111 if (strlcpy(token
->name
, line
, sizeof(token
->name
)) >= sizeof(token
->name
)) {
5114 token
->token
.num_sids
= 0;
5115 token
->token
.sids
= NULL
;
5124 * Show the list of all users that have access to a share
5127 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
5128 struct cli_state
*cli
,
5129 TALLOC_CTX
*mem_ctx
,
5130 const char *netname
,
5132 struct user_token
*tokens
)
5135 struct security_descriptor
*share_sd
= NULL
;
5136 struct security_descriptor
*root_sd
= NULL
;
5138 union srvsvc_NetShareInfo info
;
5141 struct smbXcli_tcon
*orig_tcon
= NULL
;
5142 char *orig_share
= NULL
;
5143 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5145 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5152 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
5153 DEBUG(1, ("Could not query secdesc for share %s\n",
5158 share_sd
= info
.info502
->sd_buf
.sd
;
5159 if (share_sd
== NULL
) {
5160 DEBUG(1, ("Got no secdesc for share %s\n",
5164 if (cli_state_has_tcon(cli
)) {
5165 cli_state_save_tcon_share(cli
, &orig_tcon
, &orig_share
);
5168 if (!NT_STATUS_IS_OK(cli_tree_connect(cli
, netname
, "A:", NULL
))) {
5169 cli_state_restore_tcon_share(cli
, orig_tcon
, orig_share
);
5173 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
5174 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
5175 FILE_OPEN
, 0x0, 0x0, &fnum
, NULL
))) {
5176 cli_query_secdesc(cli
, fnum
, mem_ctx
, &root_sd
);
5179 for (i
=0; i
<num_tokens
; i
++) {
5180 uint32_t acc_granted
;
5182 if (share_sd
!= NULL
) {
5183 status
= se_access_check(share_sd
, &tokens
[i
].token
,
5186 if (!NT_STATUS_IS_OK(status
)) {
5187 DEBUG(1, ("Could not check share_sd for "
5194 if (root_sd
== NULL
) {
5195 d_printf(" %s\n", tokens
[i
].name
);
5199 status
= se_access_check(root_sd
, &tokens
[i
].token
,
5201 if (!NT_STATUS_IS_OK(status
)) {
5202 DEBUG(1, ("Could not check root_sd for user %s\n",
5206 d_printf(" %s\n", tokens
[i
].name
);
5209 if (fnum
!= (uint16_t)-1)
5210 cli_close(cli
, fnum
);
5212 cli_state_restore_tcon_share(cli
, orig_tcon
, orig_share
);
5218 * List shares on a remote RPC server, including the security descriptors.
5220 * All parameters are provided by the run_rpc_command function, except for
5221 * argc, argv which are passed through.
5223 * @param domain_sid The domain sid acquired from the remote server.
5224 * @param cli A cli_state connected to the server.
5225 * @param mem_ctx Talloc context, destroyed on completion of the function.
5226 * @param argc Standard main() style argc.
5227 * @param argv Standard main() style argv. Initial components are already
5230 * @return Normal NTSTATUS return.
5233 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
5234 const struct dom_sid
*domain_sid
,
5235 const char *domain_name
,
5236 struct cli_state
*cli
,
5237 struct rpc_pipe_client
*pipe_hnd
,
5238 TALLOC_CTX
*mem_ctx
,
5244 NTSTATUS nt_status
= NT_STATUS_OK
;
5245 uint32_t total_entries
= 0;
5246 uint32_t resume_handle
= 0;
5247 uint32_t preferred_len
= 0xffffffff;
5249 struct dcerpc_binding_handle
*b
= NULL
;
5250 struct srvsvc_NetShareInfoCtr info_ctr
;
5251 struct srvsvc_NetShareCtr1 ctr1
;
5254 struct user_token
*tokens
= NULL
;
5260 if (strequal(argv
[0], "-")) {
5263 f
= fopen(argv
[0], "r");
5270 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
5271 return NT_STATUS_UNSUCCESSFUL
;
5274 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
5280 DEBUG(0, ("Could not read users from file\n"));
5281 return NT_STATUS_UNSUCCESSFUL
;
5284 for (i
=0; i
<num_tokens
; i
++)
5285 collect_alias_memberships(&tokens
[i
].token
);
5287 ZERO_STRUCT(info_ctr
);
5291 info_ctr
.ctr
.ctr1
= &ctr1
;
5293 b
= pipe_hnd
->binding_handle
;
5296 /* Show results only for shares listed on the command line. */
5298 const char *netname
= *argv
++;
5299 d_printf("%s\n", netname
);
5300 show_userlist(pipe_hnd
, cli
, mem_ctx
, netname
,
5301 num_tokens
, tokens
);
5306 /* Issue the NetShareEnum RPC call and retrieve the response */
5307 nt_status
= dcerpc_srvsvc_NetShareEnumAll(b
,
5316 /* Was it successful? */
5317 if (!NT_STATUS_IS_OK(nt_status
)) {
5318 /* Nope. Go clean up. */
5322 if (!W_ERROR_IS_OK(result
)) {
5323 /* Nope. Go clean up. */
5324 nt_status
= werror_to_ntstatus(result
);
5328 if (total_entries
== 0) {
5332 /* For each returned entry... */
5333 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
5334 const char *netname
= info_ctr
.ctr
.ctr1
->array
[i
].name
;
5336 if (info_ctr
.ctr
.ctr1
->array
[i
].type
!= STYPE_DISKTREE
) {
5340 d_printf("%s\n", netname
);
5342 show_userlist(pipe_hnd
, cli
, mem_ctx
, netname
,
5343 num_tokens
, tokens
);
5346 for (i
=0; i
<num_tokens
; i
++) {
5347 free_user_token(&tokens
[i
].token
);
5350 TALLOC_FREE(server_aliases
);
5355 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
5360 if (c
->display_usage
) {
5362 "net rpc share allowedusers\n"
5365 _("List allowed users"));
5369 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
5370 rpc_aliaslist_internals
,
5375 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
, 0,
5381 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
, 0,
5382 rpc_share_allowedusers_internals
,
5386 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
5389 struct user_token
*tokens
= NULL
;
5393 net_usersidlist_usage(c
, argc
, argv
);
5397 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
5398 DEBUG(0, ("Could not get the user/sid list\n"));
5402 for (i
=0; i
<num_tokens
; i
++) {
5403 dump_user_token(&tokens
[i
]);
5404 free_user_token(&tokens
[i
].token
);
5411 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
5413 d_printf(_("net usersidlist\n"
5414 "\tprints out a list of all users the running winbind knows\n"
5415 "\tabout, together with all their SIDs. This is used as\n"
5416 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
5418 net_common_flags_usage(c
, argc
, argv
);
5423 * 'net rpc share' entrypoint.
5424 * @param argc Standard main() style argc.
5425 * @param argv Standard main() style argv. Initial components are already
5429 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
5431 NET_API_STATUS status
;
5433 struct functable func
[] = {
5439 N_("net rpc share add\n"
5447 N_("net rpc share delete\n"
5452 rpc_share_allowedusers
,
5454 N_("List allowed users"),
5455 N_("net rpc share allowedusers\n"
5456 " List allowed users")
5462 N_("Migrate share to local server"),
5463 N_("net rpc share migrate\n"
5464 " Migrate share to local server")
5471 N_("net rpc share list\n"
5474 {NULL
, NULL
, 0, NULL
, NULL
}
5477 status
= libnetapi_net_init(&c
->netapi_ctx
);
5482 status
= libnetapi_set_creds(c
->netapi_ctx
, c
->creds
);
5489 if (c
->display_usage
) {
5494 " Alias for net rpc share list\n"));
5495 net_display_usage_from_functable(func
);
5499 return rpc_share_list(c
, argc
, argv
);
5502 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
5505 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
5506 TALLOC_CTX
*mem_ctx
,
5507 struct rpc_sh_ctx
*ctx
,
5508 struct rpc_pipe_client
*pipe_hnd
,
5509 int argc
, const char **argv
)
5512 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
5515 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
5516 TALLOC_CTX
*mem_ctx
,
5517 struct rpc_sh_ctx
*ctx
,
5518 struct rpc_pipe_client
*pipe_hnd
,
5519 int argc
, const char **argv
)
5521 NET_API_STATUS status
;
5522 uint32_t parm_err
= 0;
5523 struct SHARE_INFO_2 i2
;
5525 if ((argc
< 2) || (argc
> 3)) {
5526 d_fprintf(stderr
, _("Usage: %s <share> <path> [comment]\n"),
5528 return NT_STATUS_INVALID_PARAMETER
;
5531 i2
.shi2_netname
= argv
[0];
5532 i2
.shi2_type
= STYPE_DISKTREE
;
5533 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
5534 i2
.shi2_permissions
= 0;
5535 i2
.shi2_max_uses
= 0;
5536 i2
.shi2_current_uses
= 0;
5537 i2
.shi2_path
= argv
[1];
5538 i2
.shi2_passwd
= NULL
;
5540 status
= NetShareAdd(pipe_hnd
->desthost
,
5545 return werror_to_ntstatus(W_ERROR(status
));
5548 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
5549 TALLOC_CTX
*mem_ctx
,
5550 struct rpc_sh_ctx
*ctx
,
5551 struct rpc_pipe_client
*pipe_hnd
,
5552 int argc
, const char **argv
)
5555 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5556 return NT_STATUS_INVALID_PARAMETER
;
5559 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
5562 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
5563 TALLOC_CTX
*mem_ctx
,
5564 struct rpc_sh_ctx
*ctx
,
5565 struct rpc_pipe_client
*pipe_hnd
,
5566 int argc
, const char **argv
)
5568 union srvsvc_NetShareInfo info
;
5571 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5574 d_fprintf(stderr
, "%s %s <share>\n", _("Usage:"), ctx
->whoami
);
5575 return NT_STATUS_INVALID_PARAMETER
;
5578 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
5584 if (!NT_STATUS_IS_OK(status
)) {
5585 result
= ntstatus_to_werror(status
);
5588 if (!W_ERROR_IS_OK(result
)) {
5592 d_printf(_("Name: %s\n"), info
.info2
->name
);
5593 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
5594 d_printf(_("Path: %s\n"), info
.info2
->path
);
5595 d_printf(_("Password: %s\n"), info
.info2
->password
);
5598 return werror_to_ntstatus(result
);
5601 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
5602 struct rpc_sh_ctx
*ctx
)
5604 static struct rpc_sh_cmd cmds
[] = {
5606 { "list", NULL
, &ndr_table_srvsvc
, rpc_sh_share_list
,
5607 N_("List available shares") },
5609 { "add", NULL
, &ndr_table_srvsvc
, rpc_sh_share_add
,
5610 N_("Add a share") },
5612 { "delete", NULL
, &ndr_table_srvsvc
, rpc_sh_share_delete
,
5613 N_("Delete a share") },
5615 { "info", NULL
, &ndr_table_srvsvc
, rpc_sh_share_info
,
5616 N_("Get information about a share") },
5618 { NULL
, NULL
, 0, NULL
, NULL
}
5624 /****************************************************************************/
5626 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
5628 return net_file_usage(c
, argc
, argv
);
5632 * Close a file on a remote RPC server.
5634 * @param argc Standard main() style argc.
5635 * @param argv Standard main() style argv. Initial components are already
5638 * @return A shell status integer (0 for success).
5640 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
5642 if (argc
< 1 || c
->display_usage
) {
5643 return rpc_file_usage(c
, argc
, argv
);
5646 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
5650 * Formatted print of open file info
5652 * @param r struct FILE_INFO_3 contents
5655 static void display_file_info_3(struct FILE_INFO_3
*r
)
5657 d_printf("%-7.1" PRIu32
" %-20.20s 0x%-4.2x %-6.1u %s\n",
5658 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
5659 r
->fi3_num_locks
, r
->fi3_pathname
);
5663 * List files for a user on a remote RPC server.
5665 * @param argc Standard main() style argc.
5666 * @param argv Standard main() style argv. Initial components are already
5669 * @return A shell status integer (0 for success)..
5672 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
5674 NET_API_STATUS status
;
5675 uint32_t preferred_len
= 0xffffffff, i
;
5676 char *username
=NULL
;
5677 uint32_t total_entries
= 0;
5678 uint32_t entries_read
= 0;
5679 uint32_t resume_handle
= 0;
5680 struct FILE_INFO_3
*i3
= NULL
;
5682 if (c
->display_usage
) {
5683 return rpc_file_usage(c
, argc
, argv
);
5686 /* if argc > 0, must be user command */
5688 username
= smb_xstrdup(argv
[0]);
5691 status
= NetFileEnum(c
->opt_host
,
5695 (uint8_t **)(void *)&i3
,
5705 /* Display results */
5708 "\nEnumerating open files on remote server:\n\n"
5709 "\nFileId Opened by Perms Locks Path"
5710 "\n------ --------- ----- ----- ---- \n"));
5711 for (i
= 0; i
< entries_read
; i
++) {
5712 display_file_info_3(&i3
[i
]);
5715 SAFE_FREE(username
);
5720 * 'net rpc file' entrypoint.
5721 * @param argc Standard main() style argc.
5722 * @param argv Standard main() style argv. Initial components are already
5726 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
5728 NET_API_STATUS status
;
5730 struct functable func
[] = {
5735 N_("Close opened file"),
5736 N_("net rpc file close\n"
5737 " Close opened file")
5743 N_("List files opened by user"),
5744 N_("net rpc file user\n"
5745 " List files opened by user")
5752 N_("Display information about opened file"),
5753 N_("net rpc file info\n"
5754 " Display information about opened file")
5757 {NULL
, NULL
, 0, NULL
, NULL
}
5760 status
= libnetapi_net_init(&c
->netapi_ctx
);
5765 status
= libnetapi_set_creds(c
->netapi_ctx
, c
->creds
);
5771 if (c
->display_usage
) {
5772 d_printf(_("Usage:\n"));
5773 d_printf(_("net rpc file\n"
5774 " List opened files\n"));
5775 net_display_usage_from_functable(func
);
5779 return rpc_file_user(c
, argc
, argv
);
5782 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
5786 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5788 * All parameters are provided by the run_rpc_command function, except for
5789 * argc, argv which are passed through.
5791 * @param c A net_context structure.
5792 * @param domain_sid The domain sid acquired from the remote server.
5793 * @param cli A cli_state connected to the server.
5794 * @param mem_ctx Talloc context, destroyed on completion of the function.
5795 * @param argc Standard main() style argc.
5796 * @param argv Standard main() style argv. Initial components are already
5799 * @return Normal NTSTATUS return.
5802 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
5803 const struct dom_sid
*domain_sid
,
5804 const char *domain_name
,
5805 struct cli_state
*cli
,
5806 struct rpc_pipe_client
*pipe_hnd
,
5807 TALLOC_CTX
*mem_ctx
,
5811 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5813 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5815 status
= dcerpc_initshutdown_Abort(b
, mem_ctx
, NULL
, &result
);
5816 if (!NT_STATUS_IS_OK(status
)) {
5819 if (W_ERROR_IS_OK(result
)) {
5820 d_printf(_("\nShutdown successfully aborted\n"));
5821 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5823 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5825 return werror_to_ntstatus(result
);
5829 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5831 * All parameters are provided by the run_rpc_command function, except for
5832 * argc, argv which are passed through.
5834 * @param c A net_context structure.
5835 * @param domain_sid The domain sid acquired from the remote server.
5836 * @param cli A cli_state connected to the server.
5837 * @param mem_ctx Talloc context, destroyed on completion of the function.
5838 * @param argc Standard main() style argc.
5839 * @param argv Standard main() style argv. Initial components are already
5842 * @return Normal NTSTATUS return.
5845 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5846 const struct dom_sid
*domain_sid
,
5847 const char *domain_name
,
5848 struct cli_state
*cli
,
5849 struct rpc_pipe_client
*pipe_hnd
,
5850 TALLOC_CTX
*mem_ctx
,
5854 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5856 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5858 result
= dcerpc_winreg_AbortSystemShutdown(b
, mem_ctx
, NULL
, &werr
);
5860 if (!NT_STATUS_IS_OK(result
)) {
5861 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5864 if (W_ERROR_IS_OK(werr
)) {
5865 d_printf(_("\nShutdown successfully aborted\n"));
5866 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5868 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5870 return werror_to_ntstatus(werr
);
5874 * ABORT the shutdown of a remote RPC server.
5876 * @param argc Standard main() style argc.
5877 * @param argv Standard main() style argv. Initial components are already
5880 * @return A shell status integer (0 for success).
5883 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5888 if (c
->display_usage
) {
5890 "net rpc abortshutdown\n"
5893 _("Abort a scheduled shutdown"));
5897 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
5898 rpc_shutdown_abort_internals
, argc
, argv
);
5903 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5905 return run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
5906 rpc_reg_shutdown_abort_internals
,
5911 * Shut down a remote RPC Server via initshutdown pipe.
5913 * All parameters are provided by the run_rpc_command function, except for
5914 * argc, argv which are passed through.
5916 * @param c A net_context structure.
5917 * @param domain_sid The domain sid acquired from the remote server.
5918 * @param cli A cli_state connected to the server.
5919 * @param mem_ctx Talloc context, destroyed on completion of the function.
5920 * @param argc Standard main() style argc.
5921 * @param argv Standard main() style argv. Initial components are already
5924 * @return Normal NTSTATUS return.
5927 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5928 const struct dom_sid
*domain_sid
,
5929 const char *domain_name
,
5930 struct cli_state
*cli
,
5931 struct rpc_pipe_client
*pipe_hnd
,
5932 TALLOC_CTX
*mem_ctx
,
5936 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
5938 const char *msg
= N_("This machine will be shutdown shortly");
5939 uint32_t timeout
= 20;
5940 struct lsa_StringLarge msg_string
;
5941 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
5943 if (c
->opt_comment
) {
5944 msg
= c
->opt_comment
;
5946 if (c
->opt_timeout
) {
5947 timeout
= c
->opt_timeout
;
5950 msg_string
.string
= msg
;
5952 /* create an entry */
5953 status
= dcerpc_initshutdown_Init(b
, mem_ctx
, NULL
,
5954 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5956 if (!NT_STATUS_IS_OK(status
)) {
5959 if (W_ERROR_IS_OK(result
)) {
5960 d_printf(_("\nShutdown of remote machine succeeded\n"));
5961 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5963 DEBUG(1,("Shutdown of remote machine failed!\n"));
5965 return werror_to_ntstatus(result
);
5969 * Shut down a remote RPC Server via winreg pipe.
5971 * All parameters are provided by the run_rpc_command function, except for
5972 * argc, argv which are passed through.
5974 * @param c A net_context structure.
5975 * @param domain_sid The domain sid acquired from the remote server.
5976 * @param cli A cli_state connected to the server.
5977 * @param mem_ctx Talloc context, destroyed on completion of the function.
5978 * @param argc Standard main() style argc.
5979 * @param argv Standard main() style argv. Initial components are already
5982 * @return Normal NTSTATUS return.
5985 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5986 const struct dom_sid
*domain_sid
,
5987 const char *domain_name
,
5988 struct cli_state
*cli
,
5989 struct rpc_pipe_client
*pipe_hnd
,
5990 TALLOC_CTX
*mem_ctx
,
5994 const char *msg
= N_("This machine will be shutdown shortly");
5995 uint32_t timeout
= 20;
5996 struct lsa_StringLarge msg_string
;
5999 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6001 if (c
->opt_comment
) {
6002 msg
= c
->opt_comment
;
6004 msg_string
.string
= msg
;
6006 if (c
->opt_timeout
) {
6007 timeout
= c
->opt_timeout
;
6010 /* create an entry */
6011 result
= dcerpc_winreg_InitiateSystemShutdown(b
, mem_ctx
, NULL
,
6012 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
6014 if (!NT_STATUS_IS_OK(result
)) {
6015 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
6019 if (W_ERROR_IS_OK(werr
)) {
6020 d_printf(_("\nShutdown of remote machine succeeded\n"));
6022 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
6023 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
6024 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
6026 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
6029 return werror_to_ntstatus(werr
);
6033 * Shut down a remote RPC server.
6035 * @param argc Standard main() style argc.
6036 * @param argv Standard main() style argv. Initial components are already
6039 * @return A shell status integer (0 for success).
6042 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
6046 if (c
->display_usage
) {
6048 "net rpc shutdown\n"
6051 _("Shut down a remote RPC server"));
6055 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
, 0,
6056 rpc_init_shutdown_internals
, argc
, argv
);
6059 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
6060 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
, 0,
6061 rpc_reg_shutdown_internals
, argc
, argv
);
6067 /***************************************************************************
6068 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
6069 ***************************************************************************/
6072 * Add interdomain trust account to the RPC server.
6073 * All parameters (except for argc and argv) are passed by run_rpc_command
6076 * @param c A net_context structure.
6077 * @param domain_sid The domain sid acquired from the server.
6078 * @param cli A cli_state connected to the server.
6079 * @param mem_ctx Talloc context, destroyed on completion of the function.
6080 * @param argc Standard main() style argc.
6081 * @param argv Standard main() style argv. Initial components are already
6084 * @return normal NTSTATUS return code.
6087 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
6088 const struct dom_sid
*domain_sid
,
6089 const char *domain_name
,
6090 struct cli_state
*cli
,
6091 struct rpc_pipe_client
*pipe_hnd
,
6092 TALLOC_CTX
*mem_ctx
,
6096 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6097 NTSTATUS status
, result
;
6099 struct lsa_String lsa_acct_name
;
6101 uint32_t acct_flags
=0;
6103 uint32_t access_granted
= 0;
6104 union samr_UserInfo info
;
6105 unsigned int orig_timeout
;
6106 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6107 DATA_BLOB session_key
= data_blob_null
;
6108 TALLOC_CTX
*frame
= NULL
;
6113 _(" net rpc trustdom add <domain_name> "
6114 "<trust password>\n"));
6115 return NT_STATUS_INVALID_PARAMETER
;
6118 frame
= talloc_stackframe();
6121 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6124 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
6125 status
= NT_STATUS_NO_MEMORY
;
6128 if (!strupper_m(acct_name
)) {
6129 status
= NT_STATUS_INVALID_PARAMETER
;
6133 init_lsa_String(&lsa_acct_name
, acct_name
);
6135 status
= cli_get_session_key(frame
, pipe_hnd
, &session_key
);
6136 if (!NT_STATUS_IS_OK(status
)) {
6137 DEBUG(0,("Error getting session_key of SAM pipe. Error was %s\n",
6138 nt_errstr(status
)));
6142 /* Get samr policy handle */
6143 status
= dcerpc_samr_Connect2(b
, frame
,
6145 MAXIMUM_ALLOWED_ACCESS
,
6148 if (!NT_STATUS_IS_OK(status
)) {
6151 if (!NT_STATUS_IS_OK(result
)) {
6156 /* Get domain policy handle */
6157 status
= dcerpc_samr_OpenDomain(b
, frame
,
6159 MAXIMUM_ALLOWED_ACCESS
,
6160 discard_const_p(struct dom_sid2
, domain_sid
),
6163 if (!NT_STATUS_IS_OK(status
)) {
6166 if (!NT_STATUS_IS_OK(result
)) {
6171 /* This call can take a long time - allow the server to time out.
6172 * 35 seconds should do it. */
6174 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
6176 /* Create trusting domain's account */
6177 acb_info
= ACB_NORMAL
;
6178 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
6179 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
6180 SAMR_USER_ACCESS_SET_PASSWORD
|
6181 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
6182 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
6184 status
= dcerpc_samr_CreateUser2(b
, frame
,
6193 if (!NT_STATUS_IS_OK(status
)) {
6196 /* And restore our original timeout. */
6197 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
6199 if (!NT_STATUS_IS_OK(result
)) {
6201 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
6202 acct_name
, nt_errstr(result
));
6207 struct samr_CryptPassword crypt_pwd
;
6209 ZERO_STRUCT(info
.info23
);
6211 status
= init_samr_CryptPassword(argv
[1],
6214 if (!NT_STATUS_IS_OK(status
)) {
6218 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
6219 SAMR_FIELD_NT_PASSWORD_PRESENT
;
6220 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
6221 info
.info23
.password
= crypt_pwd
;
6223 status
= dcerpc_samr_SetUserInfo2(b
, frame
,
6228 if (!NT_STATUS_IS_OK(status
)) {
6232 if (!NT_STATUS_IS_OK(result
)) {
6234 DEBUG(0,("Could not set trust account password: %s\n",
6235 nt_errstr(result
)));
6240 status
= NT_STATUS_OK
;
6242 SAFE_FREE(acct_name
);
6243 data_blob_clear_free(&session_key
);
6249 * Create interdomain trust account for a remote domain.
6251 * @param argc Standard argc.
6252 * @param argv Standard argv without initial components.
6254 * @return Integer status (0 means success).
6257 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
6259 if (argc
> 0 && !c
->display_usage
) {
6260 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6261 rpc_trustdom_add_internals
, argc
, argv
);
6265 _("net rpc trustdom add <domain_name> <trust "
6273 * Remove interdomain trust account from the RPC server.
6274 * All parameters (except for argc and argv) are passed by run_rpc_command
6277 * @param c A net_context structure.
6278 * @param domain_sid The domain sid acquired from the server.
6279 * @param cli A cli_state connected to the server.
6280 * @param mem_ctx Talloc context, destroyed on completion of the function.
6281 * @param argc Standard main() style argc.
6282 * @param argv Standard main() style argv. Initial components are already
6285 * @return normal NTSTATUS return code.
6288 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
6289 const struct dom_sid
*domain_sid
,
6290 const char *domain_name
,
6291 struct cli_state
*cli
,
6292 struct rpc_pipe_client
*pipe_hnd
,
6293 TALLOC_CTX
*mem_ctx
,
6297 struct policy_handle connect_pol
, domain_pol
, user_pol
;
6298 NTSTATUS status
, result
;
6300 struct dom_sid trust_acct_sid
;
6301 struct samr_Ids user_rids
, name_types
;
6302 struct lsa_String lsa_acct_name
;
6303 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6308 _(" net rpc trustdom del <domain_name>\n"));
6309 return NT_STATUS_INVALID_PARAMETER
;
6313 * Make valid trusting domain account (ie. uppercased and with '$' appended)
6315 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
6317 if (acct_name
== NULL
)
6318 return NT_STATUS_NO_MEMORY
;
6320 if (!strupper_m(acct_name
)) {
6321 TALLOC_FREE(acct_name
);
6322 return NT_STATUS_INVALID_PARAMETER
;
6325 /* Get samr policy handle */
6326 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
6328 MAXIMUM_ALLOWED_ACCESS
,
6331 if (!NT_STATUS_IS_OK(status
)) {
6334 if (!NT_STATUS_IS_OK(result
)) {
6339 /* Get domain policy handle */
6340 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
6342 MAXIMUM_ALLOWED_ACCESS
,
6343 discard_const_p(struct dom_sid2
, domain_sid
),
6346 if (!NT_STATUS_IS_OK(status
)) {
6349 if (!NT_STATUS_IS_OK(result
)) {
6354 init_lsa_String(&lsa_acct_name
, acct_name
);
6356 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
6363 if (!NT_STATUS_IS_OK(status
)) {
6364 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6366 acct_name
, nt_errstr(status
));
6369 if (!NT_STATUS_IS_OK(result
)) {
6371 d_printf(_("net rpc trustdom del: LookupNames on user %s "
6373 acct_name
, nt_errstr(result
) );
6376 if (user_rids
.count
!= 1) {
6377 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6380 if (name_types
.count
!= 1) {
6381 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
6385 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
6387 MAXIMUM_ALLOWED_ACCESS
,
6391 if (!NT_STATUS_IS_OK(status
)) {
6392 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6394 acct_name
, nt_errstr(status
) );
6398 if (!NT_STATUS_IS_OK(result
)) {
6400 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
6402 acct_name
, nt_errstr(result
) );
6406 /* append the rid to the domain sid */
6407 if (!sid_compose(&trust_acct_sid
, domain_sid
, user_rids
.ids
[0])) {
6411 /* remove the sid */
6413 status
= dcerpc_samr_RemoveMemberFromForeignDomain(b
, mem_ctx
,
6417 if (!NT_STATUS_IS_OK(status
)) {
6418 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6419 " on user %s failed %s\n"),
6420 acct_name
, nt_errstr(status
));
6423 if (!NT_STATUS_IS_OK(result
)) {
6425 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
6426 " on user %s failed %s\n"),
6427 acct_name
, nt_errstr(result
) );
6434 status
= dcerpc_samr_DeleteUser(b
, mem_ctx
,
6437 if (!NT_STATUS_IS_OK(status
)) {
6438 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6440 acct_name
, nt_errstr(status
));
6444 if (!NT_STATUS_IS_OK(result
)) {
6446 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
6448 acct_name
, nt_errstr(result
) );
6452 if (!NT_STATUS_IS_OK(result
)) {
6453 d_printf(_("Could not set trust account password: %s\n"),
6463 * Delete interdomain trust account for a remote domain.
6465 * @param argc Standard argc.
6466 * @param argv Standard argv without initial components.
6468 * @return Integer status (0 means success).
6471 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
6473 if (argc
> 0 && !c
->display_usage
) {
6474 return run_rpc_command(c
, NULL
, &ndr_table_samr
, 0,
6475 rpc_trustdom_del_internals
, argc
, argv
);
6479 _("net rpc trustdom del <domain>\n"));
6484 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
6485 struct cli_state
*cli
,
6486 TALLOC_CTX
*mem_ctx
,
6487 const char *domain_name
)
6489 char *dc_name
= NULL
;
6490 const char *buffer
= NULL
;
6491 struct rpc_pipe_client
*netr
;
6494 struct dcerpc_binding_handle
*b
;
6496 /* Use NetServerEnum2 */
6498 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
6500 return NT_STATUS_OK
;
6503 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
6504 for domain %s\n", domain_name
));
6506 /* Try netr_GetDcName */
6508 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
,
6510 if (!NT_STATUS_IS_OK(status
)) {
6514 b
= netr
->binding_handle
;
6516 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
6523 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(result
)) {
6527 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
6528 for domain %s\n", domain_name
));
6530 if (!NT_STATUS_IS_OK(status
)) {
6534 return werror_to_ntstatus(result
);
6538 * Establish trust relationship to a trusting domain.
6539 * Interdomain account must already be created on remote PDC.
6541 * @param c A net_context structure.
6542 * @param argc Standard argc.
6543 * @param argv Standard argv without initial components.
6545 * @return Integer status (0 means success).
6548 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
6551 struct cli_state
*cli
= NULL
;
6552 struct sockaddr_storage server_ss
;
6553 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6554 struct policy_handle connect_hnd
;
6555 TALLOC_CTX
*mem_ctx
;
6556 NTSTATUS nt_status
, result
;
6557 struct dom_sid
*domain_sid
;
6562 union lsa_PolicyInformation
*info
= NULL
;
6563 struct dcerpc_binding_handle
*b
;
6566 * Connect to \\server\ipc$ as 'our domain' account with password
6569 if (argc
!= 1 || c
->display_usage
) {
6572 _("net rpc trustdom establish <domain_name>\n"));
6576 domain_name
= smb_xstrdup(argv
[0]);
6577 if (!strupper_m(domain_name
)) {
6578 SAFE_FREE(domain_name
);
6582 /* account name used at first is our domain's name with '$' */
6583 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
6586 if (!strupper_m(acct_name
)) {
6587 SAFE_FREE(domain_name
);
6588 SAFE_FREE(acct_name
);
6593 * opt_workgroup will be used by connection functions further,
6594 * hence it should be set to remote domain name instead of ours
6596 if (c
->opt_workgroup
) {
6597 c
->opt_workgroup
= smb_xstrdup(domain_name
);
6600 c
->opt_user_name
= acct_name
;
6601 c
->opt_user_specified
= true;
6603 /* find the domain controller */
6604 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
6605 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
6609 /* connect to ipc$ as username/password */
6610 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
6611 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
6613 /* Is it trusting domain account for sure ? */
6614 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
6615 nt_errstr(nt_status
)));
6619 /* store who we connected to */
6621 saf_store( domain_name
, pdc_name
);
6624 * Connect to \\server\ipc$ again (this time anonymously)
6627 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
6630 if (NT_STATUS_IS_ERR(nt_status
)) {
6631 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
6632 domain_name
, nt_errstr(nt_status
)));
6636 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
6637 "domain %s", domain_name
))) {
6638 DEBUG(0, ("talloc_init() failed\n"));
6643 /* Make sure we're talking to a proper server */
6645 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
6646 if (!NT_STATUS_IS_OK(nt_status
)) {
6648 talloc_destroy(mem_ctx
);
6653 * Call LsaOpenPolicy and LsaQueryInfo
6656 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6658 if (!NT_STATUS_IS_OK(nt_status
)) {
6659 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
6661 talloc_destroy(mem_ctx
);
6665 b
= pipe_hnd
->binding_handle
;
6667 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
6669 if (NT_STATUS_IS_ERR(nt_status
)) {
6670 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6671 nt_errstr(nt_status
)));
6673 talloc_destroy(mem_ctx
);
6677 /* Querying info level 5 */
6679 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6681 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6684 if (NT_STATUS_IS_ERR(nt_status
)) {
6685 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6686 nt_errstr(nt_status
)));
6688 talloc_destroy(mem_ctx
);
6691 if (NT_STATUS_IS_ERR(result
)) {
6692 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6693 nt_errstr(result
)));
6695 talloc_destroy(mem_ctx
);
6699 domain_sid
= info
->account_domain
.sid
;
6701 /* There should be actually query info level 3 (following nt serv behaviour),
6702 but I still don't know if it's _really_ necessary */
6705 * Store the password in secrets db
6708 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
6709 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6711 talloc_destroy(mem_ctx
);
6716 * Close the pipes and clean up
6719 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
6720 if (NT_STATUS_IS_ERR(nt_status
)) {
6721 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6722 nt_errstr(nt_status
)));
6724 talloc_destroy(mem_ctx
);
6730 talloc_destroy(mem_ctx
);
6732 d_printf(_("Trust to domain %s established\n"), domain_name
);
6737 * Revoke trust relationship to the remote domain.
6739 * @param c A net_context structure.
6740 * @param argc Standard argc.
6741 * @param argv Standard argv without initial components.
6743 * @return Integer status (0 means success).
6746 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
6752 if (argc
< 1 || c
->display_usage
) {
6755 _("net rpc trustdom revoke <domain_name>\n"
6756 " Revoke trust relationship\n"
6757 " domain_name\tName of domain to revoke trust\n"));
6761 /* generate upper cased domain name */
6762 domain_name
= smb_xstrdup(argv
[0]);
6763 if (!strupper_m(domain_name
)) {
6764 SAFE_FREE(domain_name
);
6768 /* delete password of the trust */
6769 if (!pdb_del_trusteddom_pw(domain_name
)) {
6770 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6777 SAFE_FREE(domain_name
);
6781 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
6782 const struct dom_sid
*domain_sid
,
6783 const char *domain_name
,
6784 struct cli_state
*cli
,
6785 struct rpc_pipe_client
*pipe_hnd
,
6786 TALLOC_CTX
*mem_ctx
,
6790 struct dom_sid_buf sid_str
;
6791 d_printf("%s\n", dom_sid_str_buf(domain_sid
, &sid_str
));
6792 return NT_STATUS_OK
;
6795 static void print_trusted_domain(struct dom_sid
*dom_sid
, const char *trusted_dom_name
)
6797 struct dom_sid_buf sid_str
;
6799 d_printf("%-20s%s\n",
6801 dom_sid_str_buf(dom_sid
, &sid_str
));
6804 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
6805 TALLOC_CTX
*mem_ctx
,
6806 struct policy_handle
*pol
,
6807 struct dom_sid dom_sid
,
6808 const char *trusted_dom_name
)
6810 NTSTATUS nt_status
, result
;
6811 union lsa_TrustedDomainInfo
*info
= NULL
;
6812 char *cleartextpwd
= NULL
;
6813 DATA_BLOB session_key
;
6814 DATA_BLOB data
= data_blob_null
;
6815 struct dcerpc_binding_handle
*b
= pipe_hnd
->binding_handle
;
6817 nt_status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(b
, mem_ctx
,
6820 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
6823 if (NT_STATUS_IS_ERR(nt_status
)) {
6824 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6825 nt_errstr(nt_status
)));
6828 if (NT_STATUS_IS_ERR(result
)) {
6830 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6831 nt_errstr(result
)));
6835 data
= data_blob(info
->password
.password
->data
,
6836 info
->password
.password
->length
);
6838 nt_status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
6839 if (!NT_STATUS_IS_OK(nt_status
)) {
6840 DEBUG(0, ("Could not retrieve session key: %s\n", nt_errstr(nt_status
)));
6844 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key
);
6845 data_blob_free(&session_key
);
6847 if (cleartextpwd
== NULL
) {
6848 DEBUG(0,("retrieved NULL password\n"));
6849 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6853 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
6854 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6855 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6859 #ifdef DEBUG_PASSWORD
6861 struct dom_sid_buf buf
;
6862 DEBUG(100,("successfully vampired trusted domain [%s], "
6863 "sid: [%s], password: [%s]\n",
6865 dom_sid_str_buf(&dom_sid
, &buf
),
6871 SAFE_FREE(cleartextpwd
);
6872 data_blob_free(&data
);
6877 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
6880 /* common variables */
6881 TALLOC_CTX
* mem_ctx
;
6882 struct cli_state
*cli
= NULL
;
6883 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6884 NTSTATUS nt_status
, result
;
6885 const char *domain_name
= NULL
;
6886 struct policy_handle connect_hnd
;
6887 union lsa_PolicyInformation
*info
= NULL
;
6889 /* trusted domains listing variables */
6890 unsigned int enum_ctx
= 0;
6891 struct lsa_DomainList dom_list
;
6893 struct dcerpc_binding_handle
*b
;
6895 if (c
->display_usage
) {
6897 "net rpc trustdom vampire\n"
6900 _("Vampire trust relationship from remote server"));
6905 * Listing trusted domains (stored in secrets.tdb, if local)
6908 mem_ctx
= talloc_init("trust relationships vampire");
6911 * set domain and pdc name to local samba server (default)
6912 * or to remote one given in command line
6915 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
6916 domain_name
= c
->opt_workgroup
;
6917 c
->opt_target_workgroup
= c
->opt_workgroup
;
6919 fstrcpy(pdc_name
, lp_netbios_name());
6920 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6921 c
->opt_target_workgroup
= domain_name
;
6924 /* open \PIPE\lsarpc and open policy handle */
6925 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6926 if (!NT_STATUS_IS_OK(nt_status
)) {
6927 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6928 nt_errstr(nt_status
)));
6929 talloc_destroy(mem_ctx
);
6933 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
6935 if (!NT_STATUS_IS_OK(nt_status
)) {
6936 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6937 nt_errstr(nt_status
) ));
6939 talloc_destroy(mem_ctx
);
6943 b
= pipe_hnd
->binding_handle
;
6945 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6947 if (NT_STATUS_IS_ERR(nt_status
)) {
6948 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6949 nt_errstr(nt_status
)));
6951 talloc_destroy(mem_ctx
);
6955 /* query info level 5 to obtain sid of a domain being queried */
6956 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
6958 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6962 if (NT_STATUS_IS_ERR(nt_status
)) {
6963 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6964 nt_errstr(nt_status
)));
6966 talloc_destroy(mem_ctx
);
6969 if (NT_STATUS_IS_ERR(result
)) {
6970 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6971 nt_errstr(result
)));
6973 talloc_destroy(mem_ctx
);
6978 * Keep calling LsaEnumTrustdom over opened pipe until
6979 * the end of enumeration is reached
6982 d_printf(_("Vampire trusted domains:\n\n"));
6987 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
6993 if (NT_STATUS_IS_ERR(nt_status
)) {
6994 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6995 nt_errstr(nt_status
)));
6997 talloc_destroy(mem_ctx
);
7000 if (NT_STATUS_IS_ERR(result
)) {
7002 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7003 nt_errstr(result
)));
7005 talloc_destroy(mem_ctx
);
7010 for (i
= 0; i
< dom_list
.count
; i
++) {
7012 print_trusted_domain(dom_list
.domains
[i
].sid
,
7013 dom_list
.domains
[i
].name
.string
);
7015 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
7016 *dom_list
.domains
[i
].sid
,
7017 dom_list
.domains
[i
].name
.string
);
7018 if (!NT_STATUS_IS_OK(nt_status
)) {
7020 talloc_destroy(mem_ctx
);
7026 * in case of no trusted domains say something rather
7027 * than just display blank line
7029 if (!dom_list
.count
) d_printf(_("none\n"));
7031 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
7033 /* close this connection before doing next one */
7034 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7035 if (NT_STATUS_IS_ERR(nt_status
)) {
7036 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
7037 nt_errstr(nt_status
)));
7039 talloc_destroy(mem_ctx
);
7043 /* close lsarpc pipe and connection to IPC$ */
7046 talloc_destroy(mem_ctx
);
7050 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
7052 /* common variables */
7053 TALLOC_CTX
* mem_ctx
;
7054 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
7055 struct rpc_pipe_client
*pipe_hnd
= NULL
;
7056 NTSTATUS nt_status
, result
;
7057 const char *domain_name
= NULL
;
7058 struct dom_sid
*queried_dom_sid
;
7059 int ascii_dom_name_len
;
7060 struct policy_handle connect_hnd
;
7061 union lsa_PolicyInformation
*info
= NULL
;
7062 struct dcerpc_binding_handle
*b
= NULL
;
7064 /* trusted domains listing variables */
7065 unsigned int num_domains
, enum_ctx
= 0;
7067 struct lsa_DomainList dom_list
;
7071 /* trusting domains listing variables */
7072 struct policy_handle domain_hnd
;
7073 struct samr_SamArray
*trusts
= NULL
;
7075 if (c
->display_usage
) {
7077 "net rpc trustdom list\n"
7080 _("List incoming and outgoing trust relationships"));
7085 * Listing trusted domains (stored in secrets.tdb, if local)
7088 mem_ctx
= talloc_init("trust relationships listing");
7091 * set domain and pdc name to local samba server (default)
7092 * or to remote one given in command line
7095 if (strcasecmp_m(c
->opt_workgroup
, lp_workgroup())) {
7096 domain_name
= c
->opt_workgroup
;
7097 c
->opt_target_workgroup
= c
->opt_workgroup
;
7099 fstrcpy(pdc_name
, lp_netbios_name());
7100 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
7101 c
->opt_target_workgroup
= domain_name
;
7104 /* open \PIPE\lsarpc and open policy handle */
7105 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
7106 if (!NT_STATUS_IS_OK(nt_status
)) {
7107 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
7108 nt_errstr(nt_status
)));
7109 talloc_destroy(mem_ctx
);
7113 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
,
7115 if (!NT_STATUS_IS_OK(nt_status
)) {
7116 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
7117 nt_errstr(nt_status
) ));
7119 talloc_destroy(mem_ctx
);
7123 b
= pipe_hnd
->binding_handle
;
7125 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
7127 if (NT_STATUS_IS_ERR(nt_status
)) {
7128 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
7129 nt_errstr(nt_status
)));
7131 talloc_destroy(mem_ctx
);
7135 /* query info level 5 to obtain sid of a domain being queried */
7136 nt_status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
7138 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
7142 if (NT_STATUS_IS_ERR(nt_status
)) {
7143 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7144 nt_errstr(nt_status
)));
7146 talloc_destroy(mem_ctx
);
7149 if (NT_STATUS_IS_ERR(result
)) {
7150 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
7151 nt_errstr(result
)));
7153 talloc_destroy(mem_ctx
);
7157 queried_dom_sid
= info
->account_domain
.sid
;
7160 * Keep calling LsaEnumTrustdom over opened pipe until
7161 * the end of enumeration is reached
7164 d_printf(_("Trusted domains list:\n\n"));
7166 found_domain
= false;
7169 nt_status
= dcerpc_lsa_EnumTrustDom(b
, mem_ctx
,
7175 if (NT_STATUS_IS_ERR(nt_status
)) {
7176 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7177 nt_errstr(nt_status
)));
7179 talloc_destroy(mem_ctx
);
7182 if (NT_STATUS_IS_ERR(result
)) {
7183 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
7184 nt_errstr(result
)));
7186 talloc_destroy(mem_ctx
);
7191 for (i
= 0; i
< dom_list
.count
; i
++) {
7192 print_trusted_domain(dom_list
.domains
[i
].sid
,
7193 dom_list
.domains
[i
].name
.string
);
7194 found_domain
= true;
7198 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
7201 * in case of no trusted domains say something rather
7202 * than just display blank line
7204 if (!found_domain
) {
7205 d_printf(_("none\n"));
7208 /* close this connection before doing next one */
7209 nt_status
= dcerpc_lsa_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7210 if (NT_STATUS_IS_ERR(nt_status
)) {
7211 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
7212 nt_errstr(nt_status
)));
7214 talloc_destroy(mem_ctx
);
7218 TALLOC_FREE(pipe_hnd
);
7221 * Listing trusting domains (stored in passdb backend, if local)
7224 d_printf(_("\nTrusting domains list:\n\n"));
7227 * Open \PIPE\samr and get needed policy handles
7229 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
,
7231 if (!NT_STATUS_IS_OK(nt_status
)) {
7232 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
7234 talloc_destroy(mem_ctx
);
7238 b
= pipe_hnd
->binding_handle
;
7241 nt_status
= dcerpc_samr_Connect2(b
, mem_ctx
,
7243 SAMR_ACCESS_LOOKUP_DOMAIN
,
7246 if (!NT_STATUS_IS_OK(nt_status
)) {
7247 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7248 nt_errstr(nt_status
)));
7250 talloc_destroy(mem_ctx
);
7253 if (!NT_STATUS_IS_OK(result
)) {
7255 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
7256 nt_errstr(result
)));
7258 talloc_destroy(mem_ctx
);
7262 /* SamrOpenDomain - we have to open domain policy handle in order to be
7263 able to enumerate accounts*/
7264 nt_status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
7266 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
7270 if (!NT_STATUS_IS_OK(nt_status
)) {
7271 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7272 nt_errstr(nt_status
)));
7274 talloc_destroy(mem_ctx
);
7277 if (!NT_STATUS_IS_OK(result
)) {
7279 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
7280 nt_errstr(result
)));
7282 talloc_destroy(mem_ctx
);
7287 * perform actual enumeration
7290 found_domain
= false;
7292 enum_ctx
= 0; /* reset enumeration context from last enumeration */
7295 nt_status
= dcerpc_samr_EnumDomainUsers(b
, mem_ctx
,
7303 if (NT_STATUS_IS_ERR(nt_status
)) {
7304 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7305 nt_errstr(nt_status
)));
7307 talloc_destroy(mem_ctx
);
7310 if (NT_STATUS_IS_ERR(result
)) {
7312 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
7313 nt_errstr(result
)));
7315 talloc_destroy(mem_ctx
);
7319 for (i
= 0; i
< num_domains
; i
++) {
7321 char *str
= discard_const_p(char, trusts
->entries
[i
].name
.string
);
7323 found_domain
= true;
7326 * get each single domain's sid (do we _really_ need this ?):
7327 * 1) connect to domain's pdc
7328 * 2) query the pdc for domain's sid
7331 /* get rid of '$' tail */
7332 ascii_dom_name_len
= strlen(str
);
7333 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
7334 str
[ascii_dom_name_len
- 1] = '\0';
7336 /* set opt_* variables to remote domain */
7337 if (!strupper_m(str
)) {
7339 talloc_destroy(mem_ctx
);
7342 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
7343 c
->opt_target_workgroup
= c
->opt_workgroup
;
7345 d_printf("%-20s", str
);
7347 /* connect to remote domain controller */
7348 nt_status
= net_make_ipc_connection(c
,
7349 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
7351 if (NT_STATUS_IS_OK(nt_status
)) {
7352 /* query for domain's sid */
7353 if (run_rpc_command(
7355 &ndr_table_lsarpc
, 0,
7356 rpc_query_domain_sid
, argc
,
7358 d_printf(_("strange - couldn't get domain's sid\n"));
7360 cli_shutdown(remote_cli
);
7363 d_fprintf(stderr
, _("domain controller is not "
7364 "responding: %s\n"),
7365 nt_errstr(nt_status
));
7366 d_printf(_("couldn't get domain's sid\n"));
7370 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
7372 if (!found_domain
) {
7376 /* close opened samr and domain policy handles */
7377 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &domain_hnd
, &result
);
7378 if (!NT_STATUS_IS_OK(nt_status
)) {
7379 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
7382 nt_status
= dcerpc_samr_Close(b
, mem_ctx
, &connect_hnd
, &result
);
7383 if (!NT_STATUS_IS_OK(nt_status
)) {
7384 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
7387 /* close samr pipe and connection to IPC$ */
7390 talloc_destroy(mem_ctx
);
7395 * Entrypoint for 'net rpc trustdom' code.
7397 * @param argc Standard argc.
7398 * @param argv Standard argv without initial components.
7400 * @return Integer status (0 means success).
7403 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
7405 struct functable func
[] = {
7410 N_("Add trusting domain's account"),
7411 N_("net rpc trustdom add\n"
7412 " Add trusting domain's account")
7418 N_("Remove trusting domain's account"),
7419 N_("net rpc trustdom del\n"
7420 " Remove trusting domain's account")
7424 rpc_trustdom_establish
,
7426 N_("Establish outgoing trust relationship"),
7427 N_("net rpc trustdom establish\n"
7428 " Establish outgoing trust relationship")
7432 rpc_trustdom_revoke
,
7434 N_("Revoke outgoing trust relationship"),
7435 N_("net rpc trustdom revoke\n"
7436 " Revoke outgoing trust relationship")
7442 N_("List in- and outgoing domain trusts"),
7443 N_("net rpc trustdom list\n"
7444 " List in- and outgoing domain trusts")
7448 rpc_trustdom_vampire
,
7450 N_("Vampire trusts from remote server"),
7451 N_("net rpc trustdom vampire\n"
7452 " Vampire trusts from remote server")
7454 {NULL
, NULL
, 0, NULL
, NULL
}
7457 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
7461 * Check if a server will take rpc commands
7462 * @param flags Type of server to connect to (PDC, DMB, localhost)
7463 * if the host is not explicitly specified
7464 * @return bool (true means rpc supported)
7466 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
7468 struct cli_state
*cli
;
7470 struct sockaddr_storage server_ss
;
7471 char *server_name
= NULL
;
7474 /* flags (i.e. server type) may depend on command */
7475 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
7478 status
= cli_connect_nb(server_name
, &server_ss
, 0, 0x20,
7479 lp_netbios_name(), SMB_SIGNING_IPC_DEFAULT
,
7481 if (!NT_STATUS_IS_OK(status
)) {
7482 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
7483 DBG_ERR("NetBIOS support disabled, unable to connect\n");
7487 status
= smbXcli_negprot(cli
->conn
, cli
->timeout
,
7488 lp_client_min_protocol(),
7489 lp_client_max_protocol());
7490 if (!NT_STATUS_IS_OK(status
))
7492 if (smbXcli_conn_protocol(cli
->conn
) < PROTOCOL_NT1
)
7501 /* syncronise sam database via samsync rpc calls */
7502 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
7504 struct functable func
[] = {
7509 N_("Dump remote SAM database to Kerberos Keytab"),
7510 N_("net rpc vampire keytab\n"
7511 " Dump remote SAM database to Kerberos keytab "
7518 N_("Dump remote SAM database to passdb"),
7519 N_("net rpc vampire passdb\n"
7520 " Dump remote SAM database to passdb")
7523 {NULL
, NULL
, 0, NULL
, NULL
}
7527 if (c
->display_usage
) {
7532 _("Vampire remote SAM database"));
7536 return rpc_vampire_passdb(c
, argc
, argv
);
7539 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
7543 * Migrate everything from a print server.
7545 * @param c A net_context structure.
7546 * @param argc Standard main() style argc.
7547 * @param argv Standard main() style argv. Initial components are already
7550 * @return A shell status integer (0 for success).
7552 * The order is important !
7553 * To successfully add drivers the print queues have to exist !
7554 * Applying ACLs should be the last step, because you're easily locked out.
7557 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
7562 if (c
->display_usage
) {
7564 "net rpc printer migrate all\n"
7567 _("Migrate everything from a print server"));
7572 d_printf(_("no server to migrate\n"));
7576 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7577 rpc_printer_migrate_printers_internals
, argc
,
7582 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7583 rpc_printer_migrate_drivers_internals
, argc
,
7588 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7589 rpc_printer_migrate_forms_internals
, argc
, argv
);
7593 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7594 rpc_printer_migrate_settings_internals
, argc
,
7599 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7600 rpc_printer_migrate_security_internals
, argc
,
7606 * Migrate print drivers from a print server.
7608 * @param c A net_context structure.
7609 * @param argc Standard main() style argc.
7610 * @param argv Standard main() style argv. Initial components are already
7613 * @return A shell status integer (0 for success).
7615 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
7618 if (c
->display_usage
) {
7620 "net rpc printer migrate drivers\n"
7623 _("Migrate print-drivers from a print-server"));
7628 d_printf(_("no server to migrate\n"));
7632 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7633 rpc_printer_migrate_drivers_internals
,
7638 * Migrate print-forms from a print-server.
7640 * @param c A net_context structure.
7641 * @param argc Standard main() style argc.
7642 * @param argv Standard main() style argv. Initial components are already
7645 * @return A shell status integer (0 for success).
7647 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
7650 if (c
->display_usage
) {
7652 "net rpc printer migrate forms\n"
7655 _("Migrate print-forms from a print-server"));
7660 d_printf(_("no server to migrate\n"));
7664 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7665 rpc_printer_migrate_forms_internals
,
7670 * Migrate printers from a print-server.
7672 * @param c A net_context structure.
7673 * @param argc Standard main() style argc.
7674 * @param argv Standard main() style argv. Initial components are already
7677 * @return A shell status integer (0 for success).
7679 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
7682 if (c
->display_usage
) {
7684 "net rpc printer migrate printers\n"
7687 _("Migrate printers from a print-server"));
7692 d_printf(_("no server to migrate\n"));
7696 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7697 rpc_printer_migrate_printers_internals
,
7702 * Migrate printer-ACLs from a print-server
7704 * @param c A net_context structure.
7705 * @param argc Standard main() style argc.
7706 * @param argv Standard main() style argv. Initial components are already
7709 * @return A shell status integer (0 for success).
7711 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
7714 if (c
->display_usage
) {
7716 "net rpc printer migrate security\n"
7719 _("Migrate printer-ACLs from a print-server"));
7724 d_printf(_("no server to migrate\n"));
7728 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7729 rpc_printer_migrate_security_internals
,
7734 * Migrate printer-settings from a print-server.
7736 * @param c A net_context structure.
7737 * @param argc Standard main() style argc.
7738 * @param argv Standard main() style argv. Initial components are already
7741 * @return A shell status integer (0 for success).
7743 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
7746 if (c
->display_usage
) {
7748 "net rpc printer migrate settings\n"
7751 _("Migrate printer-settings from a "
7757 d_printf(_("no server to migrate\n"));
7761 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7762 rpc_printer_migrate_settings_internals
,
7767 * 'net rpc printer' entrypoint.
7769 * @param c A net_context structure.
7770 * @param argc Standard main() style argc.
7771 * @param argv Standard main() style argv. Initial components are already
7775 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
7778 /* ouch: when addriver and setdriver are called from within
7779 rpc_printer_migrate_drivers_internals, the printer-queue already
7782 struct functable func
[] = {
7785 rpc_printer_migrate_all
,
7787 N_("Migrate all from remote to local print server"),
7788 N_("net rpc printer migrate all\n"
7789 " Migrate all from remote to local print server")
7793 rpc_printer_migrate_drivers
,
7795 N_("Migrate drivers to local server"),
7796 N_("net rpc printer migrate drivers\n"
7797 " Migrate drivers to local server")
7801 rpc_printer_migrate_forms
,
7803 N_("Migrate froms to local server"),
7804 N_("net rpc printer migrate forms\n"
7805 " Migrate froms to local server")
7809 rpc_printer_migrate_printers
,
7811 N_("Migrate printers to local server"),
7812 N_("net rpc printer migrate printers\n"
7813 " Migrate printers to local server")
7817 rpc_printer_migrate_security
,
7819 N_("Migrate printer ACLs to local server"),
7820 N_("net rpc printer migrate security\n"
7821 " Migrate printer ACLs to local server")
7825 rpc_printer_migrate_settings
,
7827 N_("Migrate printer settings to local server"),
7828 N_("net rpc printer migrate settings\n"
7829 " Migrate printer settings to local server")
7831 {NULL
, NULL
, 0, NULL
, NULL
}
7834 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
7839 * List printers on a remote RPC server.
7841 * @param c A net_context structure.
7842 * @param argc Standard main() style argc.
7843 * @param argv Standard main() style argv. Initial components are already
7846 * @return A shell status integer (0 for success).
7848 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
7850 if (c
->display_usage
) {
7852 "net rpc printer list\n"
7855 _("List printers on a remote RPC server"));
7859 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7860 rpc_printer_list_internals
,
7865 * List printer-drivers on a remote RPC server.
7867 * @param c A net_context structure.
7868 * @param argc Standard main() style argc.
7869 * @param argv Standard main() style argv. Initial components are already
7872 * @return A shell status integer (0 for success).
7874 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
7877 if (c
->display_usage
) {
7879 "net rpc printer driver\n"
7882 _("List printer-drivers on a remote RPC server"));
7886 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7887 rpc_printer_driver_list_internals
,
7892 * Publish printer in ADS via MSRPC.
7894 * @param c A net_context structure.
7895 * @param argc Standard main() style argc.
7896 * @param argv Standard main() style argv. Initial components are already
7899 * @return A shell status integer (0 for success).
7901 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
7904 if (c
->display_usage
) {
7906 "net rpc printer publish publish\n"
7909 _("Publish printer in ADS via MSRPC"));
7913 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7914 rpc_printer_publish_publish_internals
,
7919 * Update printer in ADS via MSRPC.
7921 * @param c A net_context structure.
7922 * @param argc Standard main() style argc.
7923 * @param argv Standard main() style argv. Initial components are already
7926 * @return A shell status integer (0 for success).
7928 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
7930 if (c
->display_usage
) {
7932 "net rpc printer publish update\n"
7935 _("Update printer in ADS via MSRPC"));
7939 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7940 rpc_printer_publish_update_internals
,
7945 * UnPublish printer in ADS via MSRPC.
7947 * @param c A net_context structure.
7948 * @param argc Standard main() style argc.
7949 * @param argv Standard main() style argv. Initial components are already
7952 * @return A shell status integer (0 for success).
7954 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
7957 if (c
->display_usage
) {
7959 "net rpc printer publish unpublish\n"
7962 _("UnPublish printer in ADS via MSRPC"));
7966 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7967 rpc_printer_publish_unpublish_internals
,
7972 * List published printers via MSRPC.
7974 * @param c A net_context structure.
7975 * @param argc Standard main() style argc.
7976 * @param argv Standard main() style argv. Initial components are already
7979 * @return A shell status integer (0 for success).
7981 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
7984 if (c
->display_usage
) {
7986 "net rpc printer publish list\n"
7989 _("List published printers via MSRPC"));
7993 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
7994 rpc_printer_publish_list_internals
,
8000 * Publish printer in ADS.
8002 * @param c A net_context structure.
8003 * @param argc Standard main() style argc.
8004 * @param argv Standard main() style argv. Initial components are already
8007 * @return A shell status integer (0 for success).
8009 static int rpc_printer_publish(struct net_context
*c
, int argc
,
8013 struct functable func
[] = {
8016 rpc_printer_publish_publish
,
8018 N_("Publish printer in AD"),
8019 N_("net rpc printer publish publish\n"
8020 " Publish printer in AD")
8024 rpc_printer_publish_update
,
8026 N_("Update printer in AD"),
8027 N_("net rpc printer publish update\n"
8028 " Update printer in AD")
8032 rpc_printer_publish_unpublish
,
8034 N_("Unpublish printer"),
8035 N_("net rpc printer publish unpublish\n"
8036 " Unpublish printer")
8040 rpc_printer_publish_list
,
8042 N_("List published printers"),
8043 N_("net rpc printer publish list\n"
8044 " List published printers")
8046 {NULL
, NULL
, 0, NULL
, NULL
}
8050 if (c
->display_usage
) {
8051 d_printf(_("Usage:\n"));
8052 d_printf(_("net rpc printer publish\n"
8053 " List published printers\n"
8054 " Alias of net rpc printer publish "
8056 net_display_usage_from_functable(func
);
8059 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
8060 rpc_printer_publish_list_internals
,
8064 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
8070 * Display rpc printer help page.
8072 * @param c A net_context structure.
8073 * @param argc Standard main() style argc.
8074 * @param argv Standard main() style argv. Initial components are already
8077 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
8079 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
8080 "\tlists all printers on print-server\n\n"));
8081 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
8082 "\tlists all printer-drivers on print-server\n\n"));
8083 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
8084 "\tpublishes printer settings in Active Directory\n"
8085 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
8086 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
8087 "\n\tmigrates printers from remote to local server\n\n"));
8088 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
8089 "\n\tmigrates printer-settings from remote to local server\n\n"));
8090 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
8091 "\n\tmigrates printer-drivers from remote to local server\n\n"));
8092 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
8093 "\n\tmigrates printer-forms from remote to local server\n\n"));
8094 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
8095 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
8096 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
8097 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
8098 "\tremote to local print-server\n\n"));
8099 net_common_methods_usage(c
, argc
, argv
);
8100 net_common_flags_usage(c
, argc
, argv
);
8102 "\t-v or --verbose\t\t\tgive verbose output\n"
8103 "\t --destination\t\tmigration target server (default: localhost)\n"));
8109 * 'net rpc printer' entrypoint.
8111 * @param c A net_context structure.
8112 * @param argc Standard main() style argc.
8113 * @param argv Standard main() style argv. Initial components are already
8116 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
8118 struct functable func
[] = {
8123 N_("List all printers on print server"),
8124 N_("net rpc printer list\n"
8125 " List all printers on print server")
8129 rpc_printer_migrate
,
8131 N_("Migrate printer to local server"),
8132 N_("net rpc printer migrate\n"
8133 " Migrate printer to local server")
8137 rpc_printer_driver_list
,
8139 N_("List printer drivers"),
8140 N_("net rpc printer driver\n"
8141 " List printer drivers")
8145 rpc_printer_publish
,
8147 N_("Publish printer in AD"),
8148 N_("net rpc printer publish\n"
8149 " Publish printer in AD")
8151 {NULL
, NULL
, 0, NULL
, NULL
}
8155 if (c
->display_usage
) {
8156 d_printf(_("Usage:\n"));
8157 d_printf(_("net rpc printer\n"
8158 " List printers\n"));
8159 net_display_usage_from_functable(func
);
8162 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
, 0,
8163 rpc_printer_list_internals
,
8167 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
8171 * 'net rpc' entrypoint.
8173 * @param c A net_context structure.
8174 * @param argc Standard main() style argc.
8175 * @param argv Standard main() style argv. Initial components are already
8179 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
8181 NET_API_STATUS status
;
8183 struct functable func
[] = {
8188 N_("Modify global audit settings"),
8189 N_("net rpc audit\n"
8190 " Modify global audit settings")
8196 N_("Show basic info about a domain"),
8198 " Show basic info about a domain")
8204 N_("Join a domain"),
8212 N_("Join a domain created in server manager"),
8213 N_("net rpc oldjoin\n"
8214 " Join a domain created in server manager")
8220 N_("Test that a join is valid"),
8221 N_("net rpc testjoin\n"
8222 " Test that a join is valid")
8228 N_("List/modify users"),
8230 " List/modify users")
8236 N_("Change a user password"),
8237 N_("net rpc password\n"
8238 " Change a user password\n"
8239 " Alias for net rpc user password")
8245 N_("List/modify groups"),
8246 N_("net rpc group\n"
8247 " List/modify groups")
8253 N_("List/modify shares"),
8254 N_("net rpc share\n"
8255 " List/modify shares")
8261 N_("List open files"),
8269 N_("List/modify printers"),
8270 N_("net rpc printer\n"
8271 " List/modify printers")
8275 net_rpc_changetrustpw
,
8277 N_("Change trust account password"),
8278 N_("net rpc changetrustpw\n"
8279 " Change trust account password")
8285 N_("Modify domain trusts"),
8286 N_("net rpc trustdom\n"
8287 " Modify domain trusts")
8293 N_("Abort a remote shutdown"),
8294 N_("net rpc abortshutdown\n"
8295 " Abort a remote shutdown")
8301 N_("Shutdown a remote server"),
8302 N_("net rpc shutdown\n"
8303 " Shutdown a remote server")
8309 N_("Sync a remote NT PDC's data into local passdb"),
8310 N_("net rpc vampire\n"
8311 " Sync a remote NT PDC's data into local passdb")
8317 N_("Fetch the domain sid into local secrets.tdb"),
8318 N_("net rpc getsid\n"
8319 " Fetch the domain sid into local secrets.tdb")
8325 N_("Manage privileges assigned to SID"),
8326 N_("net rpc rights\n"
8327 " Manage privileges assigned to SID")
8333 N_("Start/stop/query remote services"),
8334 N_("net rpc service\n"
8335 " Start/stop/query remote services")
8341 N_("Manage registry hives"),
8342 N_("net rpc registry\n"
8343 " Manage registry hives")
8349 N_("Open interactive shell on remote server"),
8350 N_("net rpc shell\n"
8351 " Open interactive shell on remote server")
8357 N_("Manage trusts"),
8358 N_("net rpc trust\n"
8365 N_("Configure a remote samba server"),
8367 " Configure a remote samba server")
8369 {NULL
, NULL
, 0, NULL
, NULL
}
8372 status
= libnetapi_net_init(&c
->netapi_ctx
);
8377 status
= libnetapi_set_creds(c
->netapi_ctx
, c
->creds
);
8382 return net_run_function(c
, argc
, argv
, "net rpc", func
);