2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
5 Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2004,2008 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2005 Jeremy Allison (jra@samba.org)
8 Copyright (C) 2006 Jelmer Vernooij (jelmer@samba.org)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "utils/net.h"
25 #include "../libcli/auth/libcli_auth.h"
27 static int net_mode_share
;
28 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
33 * @brief RPC based subcommands for the 'net' utility.
35 * This file should contain much of the functionality that used to
36 * be found in rpcclient, execpt that the commands should change
37 * less often, and the fucntionality should be sane (the user is not
38 * expected to know a rid/sid before they conduct an operation etc.)
40 * @todo Perhaps eventually these should be split out into a number
41 * of files, as this could get quite big.
46 * Many of the RPC functions need the domain sid. This function gets
47 * it at the start of every run
49 * @param cli A cli_state already connected to the remote machine
51 * @return The Domain SID of the remote machine.
54 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
56 const char **domain_name
)
58 struct rpc_pipe_client
*lsa_pipe
= NULL
;
59 struct policy_handle pol
;
60 NTSTATUS result
= NT_STATUS_OK
;
61 union lsa_PolicyInformation
*info
= NULL
;
63 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
65 if (!NT_STATUS_IS_OK(result
)) {
66 d_fprintf(stderr
, _("Could not initialise lsa pipe\n"));
70 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
71 SEC_FLAG_MAXIMUM_ALLOWED
,
73 if (!NT_STATUS_IS_OK(result
)) {
74 d_fprintf(stderr
, _("open_policy failed: %s\n"),
79 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
81 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
83 if (!NT_STATUS_IS_OK(result
)) {
84 d_fprintf(stderr
, _("lsaquery failed: %s\n"),
89 *domain_name
= info
->account_domain
.name
.string
;
90 *domain_sid
= info
->account_domain
.sid
;
92 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
93 TALLOC_FREE(lsa_pipe
);
99 * Run a single RPC command, from start to finish.
101 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
102 * @param conn_flag a NET_FLAG_ combination. Passed to
103 * net_make_ipc_connection.
104 * @param argc Standard main() style argc.
105 * @param argv Standard main() style argv. Initial components are already
107 * @return A shell status integer (0 for success).
110 int run_rpc_command(struct net_context
*c
,
111 struct cli_state
*cli_arg
,
112 const struct ndr_syntax_id
*interface
,
118 struct cli_state
*cli
= NULL
;
119 struct rpc_pipe_client
*pipe_hnd
= NULL
;
123 const char *domain_name
;
126 /* make use of cli_state handed over as an argument, if possible */
128 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
129 if (!NT_STATUS_IS_OK(nt_status
)) {
130 DEBUG(1, ("failed to make ipc connection: %s\n",
131 nt_errstr(nt_status
)));
144 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
145 DEBUG(0, ("talloc_init() failed\n"));
149 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
151 if (!NT_STATUS_IS_OK(nt_status
)) {
155 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
156 if (lp_client_schannel()
157 && (ndr_syntax_id_equal(interface
,
158 &ndr_table_netlogon
.syntax_id
))) {
159 /* Always try and create an schannel netlogon pipe. */
160 nt_status
= cli_rpc_pipe_open_schannel(
161 cli
, interface
, NCACN_NP
,
162 DCERPC_AUTH_LEVEL_PRIVACY
, domain_name
,
164 if (!NT_STATUS_IS_OK(nt_status
)) {
165 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
166 nt_errstr(nt_status
) ));
170 if (conn_flags
& NET_FLAGS_SEAL
) {
171 nt_status
= cli_rpc_pipe_open_ntlmssp(
173 (conn_flags
& NET_FLAGS_TCP
) ?
174 NCACN_IP_TCP
: NCACN_NP
,
175 DCERPC_AUTH_LEVEL_PRIVACY
,
176 lp_workgroup(), c
->opt_user_name
,
177 c
->opt_password
, &pipe_hnd
);
179 nt_status
= cli_rpc_pipe_open_noauth(
183 if (!NT_STATUS_IS_OK(nt_status
)) {
184 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
185 get_pipe_name_from_syntax(
186 talloc_tos(), interface
),
187 nt_errstr(nt_status
) ));
193 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
195 if (!NT_STATUS_IS_OK(nt_status
)) {
196 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
199 DEBUG(5, ("rpc command function succedded\n"));
202 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
204 TALLOC_FREE(pipe_hnd
);
209 /* close the connection only if it was opened here */
214 talloc_destroy(mem_ctx
);
219 * Force a change of the trust acccount password.
221 * All parameters are provided by the run_rpc_command function, except for
222 * argc, argv which are passed through.
224 * @param domain_sid The domain sid acquired from the remote server.
225 * @param cli A cli_state connected to the server.
226 * @param mem_ctx Talloc context, destroyed on completion of the function.
227 * @param argc Standard main() style argc.
228 * @param argv Standard main() style argv. Initial components are already
231 * @return Normal NTSTATUS return.
234 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
235 const DOM_SID
*domain_sid
,
236 const char *domain_name
,
237 struct cli_state
*cli
,
238 struct rpc_pipe_client
*pipe_hnd
,
245 status
= trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
246 if (!NT_STATUS_IS_OK(status
)) {
247 d_fprintf(stderr
, _("Failed to change machine account password: %s\n"),
256 * Force a change of the trust acccount password.
258 * @param argc Standard main() style argc.
259 * @param argv Standard main() style argv. Initial components are already
262 * @return A shell status integer (0 for success).
265 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
267 if (c
->display_usage
) {
268 d_printf(_("Usage:\n"
269 "net rpc changetrustpw\n"
270 " Change the machine trust password\n"));
274 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
275 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
276 rpc_changetrustpw_internals
,
281 * Join a domain, the old way.
283 * This uses 'machinename' as the inital password, and changes it.
285 * The password should be created with 'server manager' or equiv first.
287 * All parameters are provided by the run_rpc_command function, except for
288 * argc, argv which are passed through.
290 * @param domain_sid The domain sid acquired from the remote server.
291 * @param cli A cli_state connected to the server.
292 * @param mem_ctx Talloc context, destroyed on completion of the function.
293 * @param argc Standard main() style argc.
294 * @param argv Standard main() style argv. Initial components are already
297 * @return Normal NTSTATUS return.
300 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
301 const DOM_SID
*domain_sid
,
302 const char *domain_name
,
303 struct cli_state
*cli
,
304 struct rpc_pipe_client
*pipe_hnd
,
310 fstring trust_passwd
;
311 unsigned char orig_trust_passwd_hash
[16];
313 enum netr_SchannelType sec_channel_type
;
315 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
317 if (!NT_STATUS_IS_OK(result
)) {
318 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
321 nt_errstr(result
) ));
326 check what type of join - if the user want's to join as
327 a BDC, the server must agree that we are a BDC.
330 sec_channel_type
= get_sec_channel_type(argv
[0]);
332 sec_channel_type
= get_sec_channel_type(NULL
);
335 fstrcpy(trust_passwd
, global_myname());
336 strlower_m(trust_passwd
);
339 * Machine names can be 15 characters, but the max length on
340 * a password is 14. --jerry
343 trust_passwd
[14] = '\0';
345 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
347 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
349 orig_trust_passwd_hash
,
352 if (NT_STATUS_IS_OK(result
))
353 printf(_("Joined domain %s.\n"), c
->opt_target_workgroup
);
356 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
357 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
358 result
= NT_STATUS_UNSUCCESSFUL
;
365 * Join a domain, the old way.
367 * @param argc Standard main() style argc.
368 * @param argv Standard main() style argv. Initial components are already
371 * @return A shell status integer (0 for success).
374 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
376 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
377 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
378 rpc_oldjoin_internals
,
383 * Join a domain, the old way. This function exists to allow
384 * the message to be displayed when oldjoin was explicitly
385 * requested, but not when it was implied by "net rpc join".
387 * @param argc Standard main() style argc.
388 * @param argv Standard main() style argv. Initial components are already
391 * @return A shell status integer (0 for success).
394 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
398 if (c
->display_usage
) {
399 d_printf(_("Usage:\n"
401 " Join a domain the old way\n"));
405 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
408 d_fprintf(stderr
, _("Failed to join domain\n"));
415 * 'net rpc join' entrypoint.
416 * @param argc Standard main() style argc.
417 * @param argv Standard main() style argv. Initial components are already
420 * Main 'net_rpc_join()' (where the admin username/password is used) is
422 * Try to just change the password, but if that doesn't work, use/prompt
423 * for a username/password.
426 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
428 if (c
->display_usage
) {
429 d_printf(_("Usage:\n"
430 "net rpc join -U <username>[%%password] <type>\n"
432 " username\tName of the admin user"
433 " password\tPassword of the admin user, will "
434 "prompt if not specified\n"
435 " type\tCan be one of the following:\n"
436 "\t\tMEMBER\tJoin as member server (default)\n"
437 "\t\tBDC\tJoin as BDC\n"
438 "\t\tPDC\tJoin as PDC\n"));
442 if (lp_server_role() == ROLE_STANDALONE
) {
443 d_printf(_("cannot join as standalone machine\n"));
447 if (strlen(global_myname()) > 15) {
448 d_printf(_("Our netbios name can be at most 15 chars long, "
449 "\"%s\" is %u chars long\n"),
450 global_myname(), (unsigned int)strlen(global_myname()));
454 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
457 return net_rpc_join_newstyle(c
, argc
, argv
);
461 * display info about a rpc domain
463 * All parameters are provided by the run_rpc_command function, except for
464 * argc, argv which are passed through.
466 * @param domain_sid The domain sid acquired from the remote server
467 * @param cli A cli_state connected to the server.
468 * @param mem_ctx Talloc context, destroyed on completion of the function.
469 * @param argc Standard main() style argc.
470 * @param argv Standard main() style argv. Initial components are already
473 * @return Normal NTSTATUS return.
476 NTSTATUS
rpc_info_internals(struct net_context
*c
,
477 const DOM_SID
*domain_sid
,
478 const char *domain_name
,
479 struct cli_state
*cli
,
480 struct rpc_pipe_client
*pipe_hnd
,
485 struct policy_handle connect_pol
, domain_pol
;
486 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
487 union samr_DomainInfo
*info
= NULL
;
490 sid_to_fstring(sid_str
, domain_sid
);
492 /* Get sam policy handle */
493 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
495 MAXIMUM_ALLOWED_ACCESS
,
497 if (!NT_STATUS_IS_OK(result
)) {
498 d_fprintf(stderr
, _("Could not connect to SAM: %s\n"),
503 /* Get domain policy handle */
504 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
506 MAXIMUM_ALLOWED_ACCESS
,
507 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
509 if (!NT_STATUS_IS_OK(result
)) {
510 d_fprintf(stderr
, _("Could not open domain: %s\n"),
515 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
519 if (NT_STATUS_IS_OK(result
)) {
520 d_printf(_("Domain Name: %s\n"),
521 info
->general
.domain_name
.string
);
522 d_printf(_("Domain SID: %s\n"), sid_str
);
523 d_printf(_("Sequence number: %llu\n"),
524 (unsigned long long)info
->general
.sequence_num
);
525 d_printf(_("Num users: %u\n"), info
->general
.num_users
);
526 d_printf(_("Num domain groups: %u\n"),info
->general
.num_groups
);
527 d_printf(_("Num local groups: %u\n"),info
->general
.num_aliases
);
535 * 'net rpc info' entrypoint.
536 * @param argc Standard main() style argc.
537 * @param argv Standard main() style argv. Initial components are already
541 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
543 if (c
->display_usage
) {
544 d_printf(_("Usage:\n"
546 " Display information about the domain\n"));
550 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
551 NET_FLAGS_PDC
, rpc_info_internals
,
556 * Fetch domain SID into the local secrets.tdb.
558 * All parameters are provided by the run_rpc_command function, except for
559 * argc, argv which are passed through.
561 * @param domain_sid The domain sid acquired from the remote server.
562 * @param cli A cli_state connected to the server.
563 * @param mem_ctx Talloc context, destroyed on completion of the function.
564 * @param argc Standard main() style argc.
565 * @param argv Standard main() style argv. Initial components are already
568 * @return Normal NTSTATUS return.
571 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
572 const DOM_SID
*domain_sid
,
573 const char *domain_name
,
574 struct cli_state
*cli
,
575 struct rpc_pipe_client
*pipe_hnd
,
582 sid_to_fstring(sid_str
, domain_sid
);
583 d_printf(_("Storing SID %s for Domain %s in secrets.tdb\n"),
584 sid_str
, domain_name
);
586 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
587 DEBUG(0,("Can't store domain SID\n"));
588 return NT_STATUS_UNSUCCESSFUL
;
595 * 'net rpc getsid' entrypoint.
596 * @param argc Standard main() style argc.
597 * @param argv Standard main() style argv. Initial components are already
601 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
603 if (c
->display_usage
) {
604 d_printf(_("Usage:\n"
606 " Fetch domain SID into local secrets.tdb\n"));
610 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
611 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
612 rpc_getsid_internals
,
616 /****************************************************************************/
619 * Basic usage function for 'net rpc user'.
620 * @param argc Standard main() style argc.
621 * @param argv Standard main() style argv. Initial components are already
625 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
627 return net_user_usage(c
, argc
, argv
);
631 * Add a new user to a remote RPC server.
633 * @param argc Standard main() style argc.
634 * @param argv Standard main() style argv. Initial components are already
637 * @return A shell status integer (0 for success).
640 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
642 NET_API_STATUS status
;
643 struct USER_INFO_1 info1
;
644 uint32_t parm_error
= 0;
646 if (argc
< 1 || c
->display_usage
) {
647 rpc_user_usage(c
, argc
, argv
);
653 info1
.usri1_name
= argv
[0];
655 info1
.usri1_password
= argv
[1];
658 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
661 d_fprintf(stderr
,_("Failed to add user '%s' with error: %s.\n"),
662 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
666 d_printf(_("Added user '%s'.\n"), argv
[0]);
673 * Rename a user on a remote RPC server.
675 * @param argc Standard main() style argc.
676 * @param argv Standard main() style argv. Initial components are already
679 * @return A shell status integer (0 for success).
682 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
684 NET_API_STATUS status
;
685 struct USER_INFO_0 u0
;
686 uint32_t parm_err
= 0;
688 if (argc
!= 2 || c
->display_usage
) {
689 rpc_user_usage(c
, argc
, argv
);
693 u0
.usri0_name
= argv
[1];
695 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
696 0, (uint8_t *)&u0
, &parm_err
);
699 _("Failed to rename user from %s to %s - %s\n"),
701 libnetapi_get_error_string(c
->netapi_ctx
, status
));
703 d_printf(_("Renamed user from %s to %s\n"), argv
[0], argv
[1]);
710 * Delete a user from a remote RPC server.
712 * @param argc Standard main() style argc.
713 * @param argv Standard main() style argv. Initial components are already
716 * @return A shell status integer (0 for success).
719 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
721 NET_API_STATUS status
;
723 if (argc
< 1 || c
->display_usage
) {
724 rpc_user_usage(c
, argc
, argv
);
728 status
= NetUserDel(c
->opt_host
, argv
[0]);
731 d_fprintf(stderr
, _("Failed to delete user '%s' with: %s.\n"),
733 libnetapi_get_error_string(c
->netapi_ctx
, status
));
736 d_printf(_("Deleted user '%s'.\n"), argv
[0]);
743 * Set a user's password on a remote RPC server.
745 * @param argc Standard main() style argc.
746 * @param argv Standard main() style argv. Initial components are already
749 * @return A shell status integer (0 for success).
752 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
754 NET_API_STATUS status
;
756 struct USER_INFO_1003 u1003
;
757 uint32_t parm_err
= 0;
760 if (argc
< 1 || c
->display_usage
) {
761 rpc_user_usage(c
, argc
, argv
);
766 u1003
.usri1003_password
= argv
[1];
768 ret
= asprintf(&prompt
, _("Enter new password for %s:"),
773 u1003
.usri1003_password
= getpass(prompt
);
777 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
779 /* Display results */
782 _("Failed to set password for '%s' with error: %s.\n"),
783 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
792 * List a user's groups from a remote RPC server.
794 * @param argc Standard main() style argc.
795 * @param argv Standard main() style argv. Initial components are already
798 * @return A shell status integer (0 for success)
801 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
804 NET_API_STATUS status
;
805 struct GROUP_USERS_INFO_0
*u0
= NULL
;
806 uint32_t entries_read
= 0;
807 uint32_t total_entries
= 0;
811 if (argc
< 1 || c
->display_usage
) {
812 rpc_user_usage(c
, argc
, argv
);
816 status
= NetUserGetGroups(c
->opt_host
,
819 (uint8_t **)(void *)&u0
,
825 _("Failed to get groups for '%s' with error: %s.\n"),
826 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
831 for (i
=0; i
< entries_read
; i
++) {
832 printf("%s\n", u0
->grui0_name
);
840 * List users on a remote RPC server.
842 * All parameters are provided by the run_rpc_command function, except for
843 * argc, argv which are passed through.
845 * @param domain_sid The domain sid acquired from the remote server.
846 * @param cli A cli_state connected to the server.
847 * @param mem_ctx Talloc context, destroyed on completion of the function.
848 * @param argc Standard main() style argc.
849 * @param argv Standard main() style argv. Initial components are already
852 * @return Normal NTSTATUS return.
855 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
857 NET_API_STATUS status
;
858 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
859 struct NET_DISPLAY_USER
*info
= NULL
;
862 /* Query domain users */
863 if (c
->opt_long_list_entries
)
864 d_printf(_("\nUser name Comment"
865 "\n-----------------------------\n"));
867 uint32_t max_entries
, max_size
;
869 get_query_dispinfo_params(
870 loop_count
, &max_entries
, &max_size
);
872 status
= NetQueryDisplayInformation(c
->opt_host
,
879 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
883 info
= (struct NET_DISPLAY_USER
*)buffer
;
885 for (i
= 0; i
< num_entries
; i
++) {
887 if (c
->opt_long_list_entries
)
888 printf("%-21.21s %s\n", info
->usri1_name
,
889 info
->usri1_comment
);
891 printf("%s\n", info
->usri1_name
);
895 NetApiBufferFree(buffer
);
898 start_idx
+= num_entries
;
900 } while (status
== ERROR_MORE_DATA
);
906 * 'net rpc user' entrypoint.
907 * @param argc Standard main() style argc.
908 * @param argv Standard main() style argv. Initial components are already
912 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
914 NET_API_STATUS status
;
916 struct functable func
[] = {
921 N_("Add specified user"),
922 N_("net rpc user add\n"
923 " Add specified user")
929 N_("List domain groups of user"),
930 N_("net rpc user info\n"
931 " Lis domain groups of user")
937 N_("Remove specified user"),
938 N_("net rpc user delete\n"
939 " Remove specified user")
945 N_("Change user password"),
946 N_("net rpc user password\n"
947 " Change user password")
953 N_("Rename specified user"),
954 N_("net rpc user rename\n"
955 " Rename specified user")
957 {NULL
, NULL
, 0, NULL
, NULL
}
960 status
= libnetapi_init(&c
->netapi_ctx
);
964 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
965 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
966 if (c
->opt_kerberos
) {
967 libnetapi_set_use_kerberos(c
->netapi_ctx
);
971 if (c
->display_usage
) {
972 d_printf(_("Usage:\n"));
973 d_printf(_("net rpc user\n"
974 " List all users\n"));
975 net_display_usage_from_functable(func
);
979 return rpc_user_list(c
, argc
, argv
);
982 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
985 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
987 struct rpc_sh_ctx
*ctx
,
988 struct rpc_pipe_client
*pipe_hnd
,
989 int argc
, const char **argv
)
991 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
994 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
996 struct rpc_sh_ctx
*ctx
,
997 struct rpc_pipe_client
*pipe_hnd
,
998 int argc
, const char **argv
)
1000 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
1003 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
1004 TALLOC_CTX
*mem_ctx
,
1005 struct rpc_sh_ctx
*ctx
,
1006 struct rpc_pipe_client
*pipe_hnd
,
1007 int argc
, const char **argv
,
1009 struct net_context
*c
,
1010 TALLOC_CTX
*mem_ctx
,
1011 struct rpc_sh_ctx
*ctx
,
1012 struct rpc_pipe_client
*pipe_hnd
,
1013 struct policy_handle
*user_hnd
,
1014 int argc
, const char **argv
))
1016 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1017 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1020 enum lsa_SidType type
;
1023 d_fprintf(stderr
, _("usage: %s <username>\n"), ctx
->whoami
);
1024 return NT_STATUS_INVALID_PARAMETER
;
1027 ZERO_STRUCT(connect_pol
);
1028 ZERO_STRUCT(domain_pol
);
1029 ZERO_STRUCT(user_pol
);
1031 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1032 argv
[0], NULL
, NULL
, &sid
, &type
);
1033 if (!NT_STATUS_IS_OK(result
)) {
1034 d_fprintf(stderr
, _("Could not lookup %s: %s\n"), argv
[0],
1039 if (type
!= SID_NAME_USER
) {
1040 d_fprintf(stderr
, _("%s is a %s, not a user\n"), argv
[0],
1041 sid_type_lookup(type
));
1042 result
= NT_STATUS_NO_SUCH_USER
;
1046 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1047 d_fprintf(stderr
, _("%s is not in our domain\n"), argv
[0]);
1048 result
= NT_STATUS_NO_SUCH_USER
;
1052 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1054 MAXIMUM_ALLOWED_ACCESS
,
1056 if (!NT_STATUS_IS_OK(result
)) {
1060 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1062 MAXIMUM_ALLOWED_ACCESS
,
1065 if (!NT_STATUS_IS_OK(result
)) {
1069 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1071 MAXIMUM_ALLOWED_ACCESS
,
1074 if (!NT_STATUS_IS_OK(result
)) {
1078 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1081 if (is_valid_policy_hnd(&user_pol
)) {
1082 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1084 if (is_valid_policy_hnd(&domain_pol
)) {
1085 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1087 if (is_valid_policy_hnd(&connect_pol
)) {
1088 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1093 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1094 TALLOC_CTX
*mem_ctx
,
1095 struct rpc_sh_ctx
*ctx
,
1096 struct rpc_pipe_client
*pipe_hnd
,
1097 struct policy_handle
*user_hnd
,
1098 int argc
, const char **argv
)
1101 union samr_UserInfo
*info
= NULL
;
1104 d_fprintf(stderr
, _("usage: %s show <username>\n"),ctx
->whoami
);
1105 return NT_STATUS_INVALID_PARAMETER
;
1108 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1112 if (!NT_STATUS_IS_OK(result
)) {
1116 d_printf(_("user rid: %d, group rid: %d\n"),
1118 info
->info21
.primary_gid
);
1123 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1124 TALLOC_CTX
*mem_ctx
,
1125 struct rpc_sh_ctx
*ctx
,
1126 struct rpc_pipe_client
*pipe_hnd
,
1127 int argc
, const char **argv
)
1129 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1130 rpc_sh_user_show_internals
);
1133 #define FETCHSTR(name, rec) \
1134 do { if (strequal(ctx->thiscmd, name)) { \
1135 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1138 #define SETSTR(name, rec, flag) \
1139 do { if (strequal(ctx->thiscmd, name)) { \
1140 init_lsa_String(&(info->info21.rec), argv[0]); \
1141 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1144 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1145 TALLOC_CTX
*mem_ctx
,
1146 struct rpc_sh_ctx
*ctx
,
1147 struct rpc_pipe_client
*pipe_hnd
,
1148 struct policy_handle
*user_hnd
,
1149 int argc
, const char **argv
)
1152 const char *username
;
1153 const char *oldval
= "";
1154 union samr_UserInfo
*info
= NULL
;
1157 d_fprintf(stderr
, _("usage: %s <username> [new value|NULL]\n"),
1159 return NT_STATUS_INVALID_PARAMETER
;
1162 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1166 if (!NT_STATUS_IS_OK(result
)) {
1170 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1172 FETCHSTR("fullname", full_name
);
1173 FETCHSTR("homedir", home_directory
);
1174 FETCHSTR("homedrive", home_drive
);
1175 FETCHSTR("logonscript", logon_script
);
1176 FETCHSTR("profilepath", profile_path
);
1177 FETCHSTR("description", description
);
1180 d_printf(_("%s's %s: [%s]\n"), username
, ctx
->thiscmd
, oldval
);
1184 if (strcmp(argv
[0], "NULL") == 0) {
1188 ZERO_STRUCT(info
->info21
);
1190 SETSTR("fullname", full_name
, FULL_NAME
);
1191 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1192 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1193 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1194 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1195 SETSTR("description", description
, DESCRIPTION
);
1197 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1202 d_printf(_("Set %s's %s from [%s] to [%s]\n"), username
,
1203 ctx
->thiscmd
, oldval
, argv
[0]);
1210 #define HANDLEFLG(name, rec) \
1211 do { if (strequal(ctx->thiscmd, name)) { \
1212 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1214 newflags = oldflags | ACB_##rec; \
1216 newflags = oldflags & ~ACB_##rec; \
1219 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1220 TALLOC_CTX
*mem_ctx
,
1221 struct rpc_sh_ctx
*ctx
,
1222 struct rpc_pipe_client
*pipe_hnd
,
1223 int argc
, const char **argv
)
1225 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1226 rpc_sh_user_str_edit_internals
);
1229 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1230 TALLOC_CTX
*mem_ctx
,
1231 struct rpc_sh_ctx
*ctx
,
1232 struct rpc_pipe_client
*pipe_hnd
,
1233 struct policy_handle
*user_hnd
,
1234 int argc
, const char **argv
)
1237 const char *username
;
1238 const char *oldval
= "unknown";
1239 uint32 oldflags
, newflags
;
1241 union samr_UserInfo
*info
= NULL
;
1244 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1245 !strequal(argv
[0], "no"))) {
1246 /* TRANSATORS: The yes|no here are program keywords. Please do
1248 d_fprintf(stderr
, _("usage: %s <username> [yes|no]\n"),
1250 return NT_STATUS_INVALID_PARAMETER
;
1253 newval
= strequal(argv
[0], "yes");
1255 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1259 if (!NT_STATUS_IS_OK(result
)) {
1263 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1264 oldflags
= info
->info21
.acct_flags
;
1265 newflags
= info
->info21
.acct_flags
;
1267 HANDLEFLG("disabled", DISABLED
);
1268 HANDLEFLG("pwnotreq", PWNOTREQ
);
1269 HANDLEFLG("autolock", AUTOLOCK
);
1270 HANDLEFLG("pwnoexp", PWNOEXP
);
1273 d_printf(_("%s's %s flag: %s\n"), username
, ctx
->thiscmd
,
1278 ZERO_STRUCT(info
->info21
);
1280 info
->info21
.acct_flags
= newflags
;
1281 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1283 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1288 if (NT_STATUS_IS_OK(result
)) {
1289 d_printf(_("Set %s's %s flag from [%s] to [%s]\n"), username
,
1290 ctx
->thiscmd
, oldval
, argv
[0]);
1298 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1299 TALLOC_CTX
*mem_ctx
,
1300 struct rpc_sh_ctx
*ctx
,
1301 struct rpc_pipe_client
*pipe_hnd
,
1302 int argc
, const char **argv
)
1304 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1305 rpc_sh_user_flag_edit_internals
);
1308 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1309 TALLOC_CTX
*mem_ctx
,
1310 struct rpc_sh_ctx
*ctx
)
1312 static struct rpc_sh_cmd cmds
[] = {
1314 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1315 N_("Show/Set a user's full name") },
1317 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1318 N_("Show/Set a user's home directory") },
1320 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1321 N_("Show/Set a user's home drive") },
1323 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1324 N_("Show/Set a user's logon script") },
1326 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1327 N_("Show/Set a user's profile path") },
1329 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1330 N_("Show/Set a user's description") },
1332 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1333 N_("Show/Set whether a user is disabled") },
1335 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1336 N_("Show/Set whether a user locked out") },
1338 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1339 N_("Show/Set whether a user does not need a password") },
1341 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1342 N_("Show/Set whether a user's password does not expire") },
1344 { NULL
, NULL
, 0, NULL
, NULL
}
1350 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1351 TALLOC_CTX
*mem_ctx
,
1352 struct rpc_sh_ctx
*ctx
)
1354 static struct rpc_sh_cmd cmds
[] = {
1356 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1357 N_("List available users") },
1359 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1360 N_("List the domain groups a user is member of") },
1362 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1363 N_("Show info about a user") },
1365 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1366 N_("Show/Modify a user's fields") },
1368 { NULL
, NULL
, 0, NULL
, NULL
}
1374 /****************************************************************************/
1377 * Basic usage function for 'net rpc group'.
1378 * @param argc Standard main() style argc.
1379 * @param argv Standard main() style argv. Initial components are already
1383 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1385 return net_group_usage(c
, argc
, argv
);
1389 * Delete group on a remote RPC server.
1391 * All parameters are provided by the run_rpc_command function, except for
1392 * argc, argv which are passed through.
1394 * @param domain_sid The domain sid acquired from the remote server.
1395 * @param cli A cli_state connected to the server.
1396 * @param mem_ctx Talloc context, destroyed on completion of the function.
1397 * @param argc Standard main() style argc.
1398 * @param argv Standard main() style argv. Initial components are already
1401 * @return Normal NTSTATUS return.
1404 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1405 const DOM_SID
*domain_sid
,
1406 const char *domain_name
,
1407 struct cli_state
*cli
,
1408 struct rpc_pipe_client
*pipe_hnd
,
1409 TALLOC_CTX
*mem_ctx
,
1413 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1414 bool group_is_primary
= false;
1415 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1417 struct samr_RidTypeArray
*rids
= NULL
;
1420 /* struct samr_RidWithAttribute *user_gids; */
1422 struct samr_Ids group_rids
, name_types
;
1423 struct lsa_String lsa_acct_name
;
1424 union samr_UserInfo
*info
= NULL
;
1426 if (argc
< 1 || c
->display_usage
) {
1427 rpc_group_usage(c
, argc
,argv
);
1428 return NT_STATUS_OK
; /* ok? */
1431 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1433 MAXIMUM_ALLOWED_ACCESS
,
1436 if (!NT_STATUS_IS_OK(result
)) {
1437 d_fprintf(stderr
, _("Request samr_Connect2 failed\n"));
1441 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1443 MAXIMUM_ALLOWED_ACCESS
,
1444 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1447 if (!NT_STATUS_IS_OK(result
)) {
1448 d_fprintf(stderr
, _("Request open_domain failed\n"));
1452 init_lsa_String(&lsa_acct_name
, argv
[0]);
1454 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1460 if (!NT_STATUS_IS_OK(result
)) {
1461 d_fprintf(stderr
, _("Lookup of '%s' failed\n"),argv
[0]);
1465 switch (name_types
.ids
[0])
1467 case SID_NAME_DOM_GRP
:
1468 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1470 MAXIMUM_ALLOWED_ACCESS
,
1473 if (!NT_STATUS_IS_OK(result
)) {
1474 d_fprintf(stderr
, _("Request open_group failed"));
1478 group_rid
= group_rids
.ids
[0];
1480 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1484 if (!NT_STATUS_IS_OK(result
)) {
1486 _("Unable to query group members of %s"),
1491 if (c
->opt_verbose
) {
1493 _("Domain Group %s (rid: %d) has %d members\n"),
1494 argv
[0],group_rid
, rids
->count
);
1497 /* Check if group is anyone's primary group */
1498 for (i
= 0; i
< rids
->count
; i
++)
1500 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1502 MAXIMUM_ALLOWED_ACCESS
,
1506 if (!NT_STATUS_IS_OK(result
)) {
1508 _("Unable to open group member %d\n"),
1513 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1518 if (!NT_STATUS_IS_OK(result
)) {
1520 _("Unable to lookup userinfo for group "
1526 if (info
->info21
.primary_gid
== group_rid
) {
1527 if (c
->opt_verbose
) {
1528 d_printf(_("Group is primary group "
1530 info
->info21
.account_name
.string
);
1532 group_is_primary
= true;
1535 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1538 if (group_is_primary
) {
1539 d_fprintf(stderr
, _("Unable to delete group because "
1540 "some of it's members have it as primary "
1542 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1546 /* remove all group members */
1547 for (i
= 0; i
< rids
->count
; i
++)
1550 d_printf(_("Remove group member %d..."),
1552 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1556 if (NT_STATUS_IS_OK(result
)) {
1558 d_printf(_("ok\n"));
1561 d_printf(_("failed\n"));
1566 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1570 /* removing a local group is easier... */
1571 case SID_NAME_ALIAS
:
1572 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1574 MAXIMUM_ALLOWED_ACCESS
,
1578 if (!NT_STATUS_IS_OK(result
)) {
1579 d_fprintf(stderr
, _("Request open_alias failed\n"));
1583 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1587 d_fprintf(stderr
, _("%s is of type %s. This command is only "
1588 "for deleting local or global groups\n"),
1589 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1590 result
= NT_STATUS_UNSUCCESSFUL
;
1594 if (NT_STATUS_IS_OK(result
)) {
1596 d_printf(_("Deleted %s '%s'\n"),
1597 sid_type_lookup(name_types
.ids
[0]), argv
[0]);
1599 d_fprintf(stderr
, _("Deleting of %s failed: %s\n"), argv
[0],
1600 get_friendly_nt_error_msg(result
));
1608 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1610 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1611 rpc_group_delete_internals
, argc
,argv
);
1614 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1616 NET_API_STATUS status
;
1617 struct GROUP_INFO_1 info1
;
1618 uint32_t parm_error
= 0;
1620 if (argc
!= 1 || c
->display_usage
) {
1621 rpc_group_usage(c
, argc
, argv
);
1627 info1
.grpi1_name
= argv
[0];
1628 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1629 info1
.grpi1_comment
= c
->opt_comment
;
1632 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1636 _("Failed to add group '%s' with error: %s.\n"),
1637 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1641 d_printf(_("Added group '%s'.\n"), argv
[0]);
1647 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1649 NET_API_STATUS status
;
1650 struct LOCALGROUP_INFO_1 info1
;
1651 uint32_t parm_error
= 0;
1653 if (argc
!= 1 || c
->display_usage
) {
1654 rpc_group_usage(c
, argc
, argv
);
1660 info1
.lgrpi1_name
= argv
[0];
1661 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1662 info1
.lgrpi1_comment
= c
->opt_comment
;
1665 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1669 _("Failed to add alias '%s' with error: %s.\n"),
1670 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1674 d_printf(_("Added alias '%s'.\n"), argv
[0]);
1680 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1682 if (c
->opt_localgroup
)
1683 return rpc_alias_add_internals(c
, argc
, argv
);
1685 return rpc_group_add_internals(c
, argc
, argv
);
1688 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1689 TALLOC_CTX
*mem_ctx
,
1692 enum lsa_SidType
*type
)
1694 DOM_SID
*sids
= NULL
;
1695 enum lsa_SidType
*types
= NULL
;
1696 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1697 struct policy_handle lsa_pol
;
1698 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1700 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1702 if (!NT_STATUS_IS_OK(result
)) {
1706 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1707 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
1709 if (!NT_STATUS_IS_OK(result
)) {
1713 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1714 &name
, NULL
, 1, &sids
, &types
);
1716 if (NT_STATUS_IS_OK(result
)) {
1717 sid_copy(sid
, &sids
[0]);
1721 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1725 TALLOC_FREE(pipe_hnd
);
1728 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1730 /* Try as S-1-5-whatever */
1734 if (string_to_sid(&tmp_sid
, name
)) {
1735 sid_copy(sid
, &tmp_sid
);
1736 *type
= SID_NAME_UNKNOWN
;
1737 result
= NT_STATUS_OK
;
1744 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1745 TALLOC_CTX
*mem_ctx
,
1746 const DOM_SID
*group_sid
,
1749 struct policy_handle connect_pol
, domain_pol
;
1752 struct policy_handle group_pol
;
1754 struct samr_Ids rids
, rid_types
;
1755 struct lsa_String lsa_acct_name
;
1759 sid_copy(&sid
, group_sid
);
1761 if (!sid_split_rid(&sid
, &group_rid
)) {
1762 return NT_STATUS_UNSUCCESSFUL
;
1765 /* Get sam policy handle */
1766 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1768 MAXIMUM_ALLOWED_ACCESS
,
1770 if (!NT_STATUS_IS_OK(result
)) {
1774 /* Get domain policy handle */
1775 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1777 MAXIMUM_ALLOWED_ACCESS
,
1780 if (!NT_STATUS_IS_OK(result
)) {
1784 init_lsa_String(&lsa_acct_name
, member
);
1786 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1793 if (!NT_STATUS_IS_OK(result
)) {
1794 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1799 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1801 MAXIMUM_ALLOWED_ACCESS
,
1805 if (!NT_STATUS_IS_OK(result
)) {
1809 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1812 0x0005); /* unknown flags */
1815 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1819 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1820 TALLOC_CTX
*mem_ctx
,
1821 const DOM_SID
*alias_sid
,
1824 struct policy_handle connect_pol
, domain_pol
;
1827 struct policy_handle alias_pol
;
1830 enum lsa_SidType member_type
;
1834 sid_copy(&sid
, alias_sid
);
1836 if (!sid_split_rid(&sid
, &alias_rid
)) {
1837 return NT_STATUS_UNSUCCESSFUL
;
1840 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1841 member
, &member_sid
, &member_type
);
1843 if (!NT_STATUS_IS_OK(result
)) {
1844 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
1849 /* Get sam policy handle */
1850 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1852 MAXIMUM_ALLOWED_ACCESS
,
1854 if (!NT_STATUS_IS_OK(result
)) {
1858 /* Get domain policy handle */
1859 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1861 MAXIMUM_ALLOWED_ACCESS
,
1864 if (!NT_STATUS_IS_OK(result
)) {
1868 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1870 MAXIMUM_ALLOWED_ACCESS
,
1874 if (!NT_STATUS_IS_OK(result
)) {
1878 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1882 if (!NT_STATUS_IS_OK(result
)) {
1887 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1891 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1892 const DOM_SID
*domain_sid
,
1893 const char *domain_name
,
1894 struct cli_state
*cli
,
1895 struct rpc_pipe_client
*pipe_hnd
,
1896 TALLOC_CTX
*mem_ctx
,
1901 enum lsa_SidType group_type
;
1903 if (argc
!= 2 || c
->display_usage
) {
1904 d_printf(_("Usage:\n"
1905 "net rpc group addmem <group> <member>\n"
1906 " Add a member to a group\n"
1907 " group\tGroup to add member to\n"
1908 " member\tMember to add to group\n"));
1909 return NT_STATUS_UNSUCCESSFUL
;
1912 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1913 &group_sid
, &group_type
))) {
1914 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
1916 return NT_STATUS_UNSUCCESSFUL
;
1919 if (group_type
== SID_NAME_DOM_GRP
) {
1920 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1921 &group_sid
, argv
[1]);
1923 if (!NT_STATUS_IS_OK(result
)) {
1924 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1925 argv
[1], argv
[0], nt_errstr(result
));
1930 if (group_type
== SID_NAME_ALIAS
) {
1931 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1932 &group_sid
, argv
[1]);
1934 if (!NT_STATUS_IS_OK(result
)) {
1935 d_fprintf(stderr
, _("Could not add %s to %s: %s\n"),
1936 argv
[1], argv
[0], nt_errstr(result
));
1941 d_fprintf(stderr
, _("Can only add members to global or local groups "
1942 "which %s is not\n"), argv
[0]);
1944 return NT_STATUS_UNSUCCESSFUL
;
1947 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1949 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1950 rpc_group_addmem_internals
,
1954 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1955 struct rpc_pipe_client
*pipe_hnd
,
1956 TALLOC_CTX
*mem_ctx
,
1957 const DOM_SID
*group_sid
,
1960 struct policy_handle connect_pol
, domain_pol
;
1963 struct policy_handle group_pol
;
1965 struct samr_Ids rids
, rid_types
;
1966 struct lsa_String lsa_acct_name
;
1970 sid_copy(&sid
, group_sid
);
1972 if (!sid_split_rid(&sid
, &group_rid
))
1973 return NT_STATUS_UNSUCCESSFUL
;
1975 /* Get sam policy handle */
1976 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1978 MAXIMUM_ALLOWED_ACCESS
,
1980 if (!NT_STATUS_IS_OK(result
))
1983 /* Get domain policy handle */
1984 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1986 MAXIMUM_ALLOWED_ACCESS
,
1989 if (!NT_STATUS_IS_OK(result
))
1992 init_lsa_String(&lsa_acct_name
, member
);
1994 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2000 if (!NT_STATUS_IS_OK(result
)) {
2001 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2006 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2008 MAXIMUM_ALLOWED_ACCESS
,
2012 if (!NT_STATUS_IS_OK(result
))
2015 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2020 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2024 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2025 TALLOC_CTX
*mem_ctx
,
2026 const DOM_SID
*alias_sid
,
2029 struct policy_handle connect_pol
, domain_pol
;
2032 struct policy_handle alias_pol
;
2035 enum lsa_SidType member_type
;
2039 sid_copy(&sid
, alias_sid
);
2041 if (!sid_split_rid(&sid
, &alias_rid
))
2042 return NT_STATUS_UNSUCCESSFUL
;
2044 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2045 member
, &member_sid
, &member_type
);
2047 if (!NT_STATUS_IS_OK(result
)) {
2048 d_fprintf(stderr
, _("Could not lookup up group member %s\n"),
2053 /* Get sam policy handle */
2054 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2056 MAXIMUM_ALLOWED_ACCESS
,
2058 if (!NT_STATUS_IS_OK(result
)) {
2062 /* Get domain policy handle */
2063 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2065 MAXIMUM_ALLOWED_ACCESS
,
2068 if (!NT_STATUS_IS_OK(result
)) {
2072 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2074 MAXIMUM_ALLOWED_ACCESS
,
2078 if (!NT_STATUS_IS_OK(result
))
2081 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2085 if (!NT_STATUS_IS_OK(result
))
2089 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2093 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2094 const DOM_SID
*domain_sid
,
2095 const char *domain_name
,
2096 struct cli_state
*cli
,
2097 struct rpc_pipe_client
*pipe_hnd
,
2098 TALLOC_CTX
*mem_ctx
,
2103 enum lsa_SidType group_type
;
2105 if (argc
!= 2 || c
->display_usage
) {
2106 d_printf(_("Usage:\n"
2107 "net rpc group delmem <group> <member>\n"
2108 " Delete a member from a group\n"
2109 " group\tGroup to delete member from\n"
2110 " member\tMember to delete from group\n"));
2111 return NT_STATUS_UNSUCCESSFUL
;
2114 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2115 &group_sid
, &group_type
))) {
2116 d_fprintf(stderr
, _("Could not lookup group name %s\n"),
2118 return NT_STATUS_UNSUCCESSFUL
;
2121 if (group_type
== SID_NAME_DOM_GRP
) {
2122 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2123 &group_sid
, argv
[1]);
2125 if (!NT_STATUS_IS_OK(result
)) {
2126 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2127 argv
[1], argv
[0], nt_errstr(result
));
2132 if (group_type
== SID_NAME_ALIAS
) {
2133 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2134 &group_sid
, argv
[1]);
2136 if (!NT_STATUS_IS_OK(result
)) {
2137 d_fprintf(stderr
, _("Could not del %s from %s: %s\n"),
2138 argv
[1], argv
[0], nt_errstr(result
));
2143 d_fprintf(stderr
, _("Can only delete members from global or local "
2144 "groups which %s is not\n"), argv
[0]);
2146 return NT_STATUS_UNSUCCESSFUL
;
2149 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2151 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2152 rpc_group_delmem_internals
,
2157 * List groups on a remote RPC server.
2159 * All parameters are provided by the run_rpc_command function, except for
2160 * argc, argv which are passes through.
2162 * @param domain_sid The domain sid acquired from the remote server.
2163 * @param cli A cli_state connected to the server.
2164 * @param mem_ctx Talloc context, destroyed on completion of the function.
2165 * @param argc Standard main() style argc.
2166 * @param argv Standard main() style argv. Initial components are already
2169 * @return Normal NTSTATUS return.
2172 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2173 const DOM_SID
*domain_sid
,
2174 const char *domain_name
,
2175 struct cli_state
*cli
,
2176 struct rpc_pipe_client
*pipe_hnd
,
2177 TALLOC_CTX
*mem_ctx
,
2181 struct policy_handle connect_pol
, domain_pol
;
2182 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2183 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2184 struct samr_SamArray
*groups
= NULL
;
2185 bool global
= false;
2187 bool builtin
= false;
2189 if (c
->display_usage
) {
2190 d_printf(_("Usage:\n"
2191 "net rpc group list [global] [local] [builtin]\n"
2192 " List groups on RPC server\n"
2193 " global\tList global groups\n"
2194 " local\tList local groups\n"
2195 " builtin\tList builtin groups\n"
2196 " If none of global, local or builtin is "
2197 "specified, all three options are considered "
2199 return NT_STATUS_OK
;
2208 for (i
=0; i
<argc
; i
++) {
2209 if (strequal(argv
[i
], "global"))
2212 if (strequal(argv
[i
], "local"))
2215 if (strequal(argv
[i
], "builtin"))
2219 /* Get sam policy handle */
2221 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2223 MAXIMUM_ALLOWED_ACCESS
,
2225 if (!NT_STATUS_IS_OK(result
)) {
2229 /* Get domain policy handle */
2231 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2233 MAXIMUM_ALLOWED_ACCESS
,
2234 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2236 if (!NT_STATUS_IS_OK(result
)) {
2240 /* Query domain groups */
2241 if (c
->opt_long_list_entries
)
2242 d_printf(_("\nGroup name Comment"
2243 "\n-----------------------------\n"));
2245 uint32_t max_size
, total_size
, returned_size
;
2246 union samr_DispInfo info
;
2250 get_query_dispinfo_params(
2251 loop_count
, &max_entries
, &max_size
);
2253 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2262 num_entries
= info
.info3
.count
;
2263 start_idx
+= info
.info3
.count
;
2265 if (!NT_STATUS_IS_OK(result
) &&
2266 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2269 for (i
= 0; i
< num_entries
; i
++) {
2271 const char *group
= NULL
;
2272 const char *desc
= NULL
;
2274 group
= info
.info3
.entries
[i
].account_name
.string
;
2275 desc
= info
.info3
.entries
[i
].description
.string
;
2277 if (c
->opt_long_list_entries
)
2278 printf("%-21.21s %-50.50s\n",
2281 printf("%s\n", group
);
2283 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2284 /* query domain aliases */
2289 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2295 if (!NT_STATUS_IS_OK(result
) &&
2296 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2299 for (i
= 0; i
< num_entries
; i
++) {
2301 const char *description
= NULL
;
2303 if (c
->opt_long_list_entries
) {
2305 struct policy_handle alias_pol
;
2306 union samr_AliasInfo
*info
= NULL
;
2308 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2311 groups
->entries
[i
].idx
,
2313 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2317 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2319 description
= info
->description
.string
;
2323 if (description
!= NULL
) {
2324 printf("%-21.21s %-50.50s\n",
2325 groups
->entries
[i
].name
.string
,
2328 printf("%s\n", groups
->entries
[i
].name
.string
);
2331 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2332 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2333 /* Get builtin policy handle */
2335 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2337 MAXIMUM_ALLOWED_ACCESS
,
2338 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2340 if (!NT_STATUS_IS_OK(result
)) {
2343 /* query builtin aliases */
2346 if (!builtin
) break;
2348 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2354 if (!NT_STATUS_IS_OK(result
) &&
2355 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2358 for (i
= 0; i
< num_entries
; i
++) {
2360 const char *description
= NULL
;
2362 if (c
->opt_long_list_entries
) {
2364 struct policy_handle alias_pol
;
2365 union samr_AliasInfo
*info
= NULL
;
2367 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2370 groups
->entries
[i
].idx
,
2372 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2376 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2378 description
= info
->description
.string
;
2382 if (description
!= NULL
) {
2383 printf("%-21.21s %-50.50s\n",
2384 groups
->entries
[i
].name
.string
,
2387 printf("%s\n", groups
->entries
[i
].name
.string
);
2390 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2396 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2398 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2399 rpc_group_list_internals
,
2403 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2404 struct rpc_pipe_client
*pipe_hnd
,
2405 TALLOC_CTX
*mem_ctx
,
2406 const char *domain_name
,
2407 const DOM_SID
*domain_sid
,
2408 struct policy_handle
*domain_pol
,
2412 struct policy_handle group_pol
;
2413 uint32 num_members
, *group_rids
;
2415 struct samr_RidTypeArray
*rids
= NULL
;
2416 struct lsa_Strings names
;
2417 struct samr_Ids types
;
2420 sid_to_fstring(sid_str
, domain_sid
);
2422 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2424 MAXIMUM_ALLOWED_ACCESS
,
2428 if (!NT_STATUS_IS_OK(result
))
2431 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2435 if (!NT_STATUS_IS_OK(result
))
2438 num_members
= rids
->count
;
2439 group_rids
= rids
->rids
;
2441 while (num_members
> 0) {
2442 int this_time
= 512;
2444 if (num_members
< this_time
)
2445 this_time
= num_members
;
2447 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2454 if (!NT_STATUS_IS_OK(result
))
2457 /* We only have users as members, but make the output
2458 the same as the output of alias members */
2460 for (i
= 0; i
< this_time
; i
++) {
2462 if (c
->opt_long_list_entries
) {
2463 printf("%s-%d %s\\%s %d\n", sid_str
,
2464 group_rids
[i
], domain_name
,
2465 names
.names
[i
].string
,
2468 printf("%s\\%s\n", domain_name
,
2469 names
.names
[i
].string
);
2473 num_members
-= this_time
;
2477 return NT_STATUS_OK
;
2480 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2481 struct rpc_pipe_client
*pipe_hnd
,
2482 TALLOC_CTX
*mem_ctx
,
2483 struct policy_handle
*domain_pol
,
2487 struct rpc_pipe_client
*lsa_pipe
;
2488 struct policy_handle alias_pol
, lsa_pol
;
2490 DOM_SID
*alias_sids
;
2493 enum lsa_SidType
*types
;
2495 struct lsa_SidArray sid_array
;
2497 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2499 MAXIMUM_ALLOWED_ACCESS
,
2503 if (!NT_STATUS_IS_OK(result
))
2506 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2510 if (!NT_STATUS_IS_OK(result
)) {
2511 d_fprintf(stderr
, _("Couldn't list alias members\n"));
2515 num_members
= sid_array
.num_sids
;
2517 if (num_members
== 0) {
2518 return NT_STATUS_OK
;
2521 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2522 &ndr_table_lsarpc
.syntax_id
,
2524 if (!NT_STATUS_IS_OK(result
)) {
2525 d_fprintf(stderr
, _("Couldn't open LSA pipe. Error was %s\n"),
2526 nt_errstr(result
) );
2530 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2531 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2533 if (!NT_STATUS_IS_OK(result
)) {
2534 d_fprintf(stderr
, _("Couldn't open LSA policy handle\n"));
2535 TALLOC_FREE(lsa_pipe
);
2539 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2541 d_fprintf(stderr
, _("Out of memory\n"));
2542 TALLOC_FREE(lsa_pipe
);
2543 return NT_STATUS_NO_MEMORY
;
2546 for (i
=0; i
<num_members
; i
++) {
2547 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2550 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2551 num_members
, alias_sids
,
2552 &domains
, &names
, &types
);
2554 if (!NT_STATUS_IS_OK(result
) &&
2555 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2556 d_fprintf(stderr
, _("Couldn't lookup SIDs\n"));
2557 TALLOC_FREE(lsa_pipe
);
2561 for (i
= 0; i
< num_members
; i
++) {
2563 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2565 if (c
->opt_long_list_entries
) {
2566 printf("%s %s\\%s %d\n", sid_str
,
2567 domains
[i
] ? domains
[i
] : _("*unknown*"),
2568 names
[i
] ? names
[i
] : _("*unknown*"), types
[i
]);
2571 printf("%s\\%s\n", domains
[i
], names
[i
]);
2573 printf("%s\n", sid_str
);
2577 TALLOC_FREE(lsa_pipe
);
2578 return NT_STATUS_OK
;
2581 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2582 const DOM_SID
*domain_sid
,
2583 const char *domain_name
,
2584 struct cli_state
*cli
,
2585 struct rpc_pipe_client
*pipe_hnd
,
2586 TALLOC_CTX
*mem_ctx
,
2591 struct policy_handle connect_pol
, domain_pol
;
2592 struct samr_Ids rids
, rid_types
;
2593 struct lsa_String lsa_acct_name
;
2595 /* Get sam policy handle */
2597 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2599 MAXIMUM_ALLOWED_ACCESS
,
2602 if (!NT_STATUS_IS_OK(result
))
2605 /* Get domain policy handle */
2607 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2609 MAXIMUM_ALLOWED_ACCESS
,
2610 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2613 if (!NT_STATUS_IS_OK(result
))
2616 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2618 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2625 if (!NT_STATUS_IS_OK(result
)) {
2627 /* Ok, did not find it in the global sam, try with builtin */
2629 DOM_SID sid_Builtin
;
2631 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2633 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2635 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2637 MAXIMUM_ALLOWED_ACCESS
,
2641 if (!NT_STATUS_IS_OK(result
)) {
2642 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2647 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2654 if (!NT_STATUS_IS_OK(result
)) {
2655 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2661 if (rids
.count
!= 1) {
2662 d_fprintf(stderr
, _("Couldn't find group %s\n"),
2667 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2668 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2669 domain_sid
, &domain_pol
,
2673 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2674 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2678 return NT_STATUS_NO_SUCH_GROUP
;
2681 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2683 if (argc
!= 1 || c
->display_usage
) {
2684 return rpc_group_usage(c
, argc
, argv
);
2687 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2688 rpc_group_members_internals
,
2692 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2694 NET_API_STATUS status
;
2695 struct GROUP_INFO_0 g0
;
2699 d_printf(_("Usage: 'net rpc group rename group newname'\n"));
2703 g0
.grpi0_name
= argv
[1];
2705 status
= NetGroupSetInfo(c
->opt_host
,
2712 d_fprintf(stderr
, _("Renaming group %s failed with: %s\n"),
2713 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2721 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2723 if (argc
!= 2 || c
->display_usage
) {
2724 return rpc_group_usage(c
, argc
, argv
);
2727 return rpc_group_rename_internals(c
, argc
, argv
);
2731 * 'net rpc group' entrypoint.
2732 * @param argc Standard main() style argc.
2733 * @param argv Standard main() style argv. Initial components are already
2737 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2739 NET_API_STATUS status
;
2741 struct functable func
[] = {
2746 N_("Create specified group"),
2747 N_("net rpc group add\n"
2748 " Create specified group")
2754 N_("Delete specified group"),
2755 N_("net rpc group delete\n"
2756 " Delete specified group")
2762 N_("Add member to group"),
2763 N_("net rpc group addmem\n"
2764 " Add member to group")
2770 N_("Remove member from group"),
2771 N_("net rpc group delmem\n"
2772 " Remove member from group")
2779 N_("net rpc group list\n"
2786 N_("List group members"),
2787 N_("net rpc group members\n"
2788 " List group members")
2795 N_("net rpc group rename\n"
2798 {NULL
, NULL
, 0, NULL
, NULL
}
2801 status
= libnetapi_init(&c
->netapi_ctx
);
2805 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2806 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2807 if (c
->opt_kerberos
) {
2808 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2812 if (c
->display_usage
) {
2813 d_printf(_("Usage:\n"));
2814 d_printf(_("net rpc group\n"
2815 " Alias for net rpc group list global "
2816 "local builtin\n"));
2817 net_display_usage_from_functable(func
);
2821 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2822 rpc_group_list_internals
,
2826 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2829 /****************************************************************************/
2831 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2833 return net_share_usage(c
, argc
, argv
);
2837 * Add a share on a remote RPC server.
2839 * @param argc Standard main() style argc.
2840 * @param argv Standard main() style argv. Initial components are already
2843 * @return A shell status integer (0 for success).
2846 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2848 NET_API_STATUS status
;
2851 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2852 uint32 num_users
=0, perms
=0;
2853 char *password
=NULL
; /* don't allow a share password */
2854 struct SHARE_INFO_2 i2
;
2855 uint32_t parm_error
= 0;
2857 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2858 return rpc_share_usage(c
, argc
, argv
);
2861 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2865 path
= strchr(sharename
, '=');
2872 i2
.shi2_netname
= sharename
;
2873 i2
.shi2_type
= type
;
2874 i2
.shi2_remark
= c
->opt_comment
;
2875 i2
.shi2_permissions
= perms
;
2876 i2
.shi2_max_uses
= c
->opt_maxusers
;
2877 i2
.shi2_current_uses
= num_users
;
2878 i2
.shi2_path
= path
;
2879 i2
.shi2_passwd
= password
;
2881 status
= NetShareAdd(c
->opt_host
,
2886 printf(_("NetShareAdd failed with: %s\n"),
2887 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2894 * Delete a share on a remote RPC server.
2896 * @param domain_sid The domain sid acquired from the remote server.
2897 * @param argc Standard main() style argc.
2898 * @param argv Standard main() style argv. Initial components are already
2901 * @return A shell status integer (0 for success).
2903 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2905 if (argc
< 1 || c
->display_usage
) {
2906 return rpc_share_usage(c
, argc
, argv
);
2909 return NetShareDel(c
->opt_host
, argv
[0], 0);
2913 * Formatted print of share info
2915 * @param r pointer to SHARE_INFO_1 to format
2918 static void display_share_info_1(struct net_context
*c
,
2919 struct SHARE_INFO_1
*r
)
2921 if (c
->opt_long_list_entries
) {
2922 d_printf("%-12s %-8.8s %-50s\n",
2924 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2927 d_printf("%s\n", r
->shi1_netname
);
2931 static WERROR
get_share_info(struct net_context
*c
,
2932 struct rpc_pipe_client
*pipe_hnd
,
2933 TALLOC_CTX
*mem_ctx
,
2937 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2941 union srvsvc_NetShareInfo info
;
2943 /* no specific share requested, enumerate all */
2946 uint32_t preferred_len
= 0xffffffff;
2947 uint32_t total_entries
= 0;
2948 uint32_t resume_handle
= 0;
2950 info_ctr
->level
= level
;
2952 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2962 /* request just one share */
2963 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2970 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2975 ZERO_STRUCTP(info_ctr
);
2977 info_ctr
->level
= level
;
2982 struct srvsvc_NetShareCtr1
*ctr1
;
2984 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2985 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2988 ctr1
->array
= info
.info1
;
2990 info_ctr
->ctr
.ctr1
= ctr1
;
2994 struct srvsvc_NetShareCtr2
*ctr2
;
2996 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2997 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3000 ctr2
->array
= info
.info2
;
3002 info_ctr
->ctr
.ctr2
= ctr2
;
3006 struct srvsvc_NetShareCtr502
*ctr502
;
3008 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3009 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3012 ctr502
->array
= info
.info502
;
3014 info_ctr
->ctr
.ctr502
= ctr502
;
3022 * 'net rpc share list' entrypoint.
3023 * @param argc Standard main() style argc.
3024 * @param argv Standard main() style argv. Initial components are already
3027 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3029 NET_API_STATUS status
;
3030 struct SHARE_INFO_1
*i1
= NULL
;
3031 uint32_t entries_read
= 0;
3032 uint32_t total_entries
= 0;
3033 uint32_t resume_handle
= 0;
3034 uint32_t i
, level
= 1;
3036 if (c
->display_usage
) {
3037 d_printf(_("Usage\n"
3038 "net rpc share list\n"
3039 " List shares on remote server\n"));
3043 status
= NetShareEnum(c
->opt_host
,
3045 (uint8_t **)(void *)&i1
,
3054 /* Display results */
3056 if (c
->opt_long_list_entries
) {
3058 "\nEnumerating shared resources (exports) on remote server:\n\n"
3059 "\nShare name Type Description\n"
3060 "---------- ---- -----------\n"));
3062 for (i
= 0; i
< entries_read
; i
++)
3063 display_share_info_1(c
, &i1
[i
]);
3068 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3070 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3071 d_printf(_("skipping [%s]: not a file share.\n"), netname
);
3081 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3082 const char *netname
, uint32 type
)
3084 /* only support disk shares */
3085 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3086 printf(_("share [%s] is not a diskshare (type: %x)\n"), netname
,
3091 /* skip builtin shares */
3092 /* FIXME: should print$ be added too ? */
3093 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3094 strequal(netname
,"global"))
3097 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3098 printf(_("excluding [%s]\n"), netname
);
3102 return check_share_availability(cli
, netname
);
3106 * Migrate shares from a remote RPC server to the local RPC server.
3108 * All parameters are provided by the run_rpc_command function, except for
3109 * argc, argv which are passed through.
3111 * @param domain_sid The domain sid acquired from the remote server.
3112 * @param cli A cli_state connected to the server.
3113 * @param mem_ctx Talloc context, destroyed on completion of the function.
3114 * @param argc Standard main() style argc.
3115 * @param argv Standard main() style argv. Initial components are already
3118 * @return Normal NTSTATUS return.
3121 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3122 const DOM_SID
*domain_sid
,
3123 const char *domain_name
,
3124 struct cli_state
*cli
,
3125 struct rpc_pipe_client
*pipe_hnd
,
3126 TALLOC_CTX
*mem_ctx
,
3131 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3132 struct srvsvc_NetShareInfoCtr ctr_src
;
3134 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3135 struct cli_state
*cli_dst
= NULL
;
3136 uint32 level
= 502; /* includes secdesc */
3137 uint32_t parm_error
= 0;
3139 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3141 if (!W_ERROR_IS_OK(result
))
3144 /* connect destination PI_SRVSVC */
3145 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3146 &ndr_table_srvsvc
.syntax_id
);
3147 if (!NT_STATUS_IS_OK(nt_status
))
3151 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3153 union srvsvc_NetShareInfo info
;
3154 struct srvsvc_NetShareInfo502 info502
=
3155 ctr_src
.ctr
.ctr502
->array
[i
];
3157 /* reset error-code */
3158 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3160 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3163 /* finally add the share on the dst server */
3165 printf(_("migrating: [%s], path: %s, comment: %s, without "
3167 info502
.name
, info502
.path
, info502
.comment
);
3169 info
.info502
= &info502
;
3171 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3172 srvsvc_pipe
->desthost
,
3178 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3179 printf(_(" [%s] does already exist\n"),
3184 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3185 printf(_("cannot add share: %s\n"), win_errstr(result
));
3191 nt_status
= NT_STATUS_OK
;
3195 cli_shutdown(cli_dst
);
3203 * Migrate shares from a RPC server to another.
3205 * @param argc Standard main() style argc.
3206 * @param argv Standard main() style argv. Initial components are already
3209 * @return A shell status integer (0 for success).
3211 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3214 if (c
->display_usage
) {
3215 d_printf(_("Usage:\n"
3216 "net rpc share migrate shares\n"
3217 " Migrate shares to local server\n"));
3222 printf(_("no server to migrate\n"));
3226 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3227 rpc_share_migrate_shares_internals
,
3234 * @param f file_info
3235 * @param mask current search mask
3236 * @param state arg-pointer
3239 static void copy_fn(const char *mnt
, file_info
*f
,
3240 const char *mask
, void *state
)
3242 static NTSTATUS nt_status
;
3243 static struct copy_clistate
*local_state
;
3244 static fstring filename
, new_mask
;
3247 struct net_context
*c
;
3249 local_state
= (struct copy_clistate
*)state
;
3250 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3254 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3257 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3260 if (f
->mode
& aDIR
) {
3262 DEBUG(3,("got dir: %s\n", f
->name
));
3264 fstrcpy(dir
, local_state
->cwd
);
3266 fstrcat(dir
, f
->name
);
3268 switch (net_mode_share
)
3270 case NET_MODE_SHARE_MIGRATE
:
3271 /* create that directory */
3272 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3273 local_state
->cli_share_src
,
3274 local_state
->cli_share_dst
,
3276 c
->opt_acls
? true : false,
3277 c
->opt_attrs
? true : false,
3278 c
->opt_timestamps
? true:false,
3282 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3286 if (!NT_STATUS_IS_OK(nt_status
))
3287 printf(_("could not handle dir %s: %s\n"),
3288 dir
, nt_errstr(nt_status
));
3290 /* search below that directory */
3291 fstrcpy(new_mask
, dir
);
3292 fstrcat(new_mask
, "\\*");
3294 old_dir
= local_state
->cwd
;
3295 local_state
->cwd
= dir
;
3296 if (!sync_files(local_state
, new_mask
))
3297 printf(_("could not handle files\n"));
3298 local_state
->cwd
= old_dir
;
3305 fstrcpy(filename
, local_state
->cwd
);
3306 fstrcat(filename
, "\\");
3307 fstrcat(filename
, f
->name
);
3309 DEBUG(3,("got file: %s\n", filename
));
3311 switch (net_mode_share
)
3313 case NET_MODE_SHARE_MIGRATE
:
3314 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3315 local_state
->cli_share_src
,
3316 local_state
->cli_share_dst
,
3318 c
->opt_acls
? true : false,
3319 c
->opt_attrs
? true : false,
3320 c
->opt_timestamps
? true: false,
3324 d_fprintf(stderr
, _("Unsupported file mode %d\n"),
3329 if (!NT_STATUS_IS_OK(nt_status
))
3330 printf(_("could not handle file %s: %s\n"),
3331 filename
, nt_errstr(nt_status
));
3336 * sync files, can be called recursivly to list files
3337 * and then call copy_fn for each file
3339 * @param cp_clistate pointer to the copy_clistate we work with
3340 * @param mask the current search mask
3342 * @return Boolean result
3344 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3346 struct cli_state
*targetcli
;
3347 char *targetpath
= NULL
;
3349 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3351 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3352 mask
, &targetcli
, &targetpath
) ) {
3353 d_fprintf(stderr
, _("cli_resolve_path %s failed with error: "
3355 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3359 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3360 d_fprintf(stderr
, _("listing %s failed with error: %s\n"),
3361 mask
, cli_errstr(targetcli
));
3370 * Set the top level directory permissions before we do any further copies.
3371 * Should set up ACL inheritance.
3374 bool copy_top_level_perms(struct net_context
*c
,
3375 struct copy_clistate
*cp_clistate
,
3376 const char *sharename
)
3378 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3380 switch (net_mode_share
) {
3381 case NET_MODE_SHARE_MIGRATE
:
3382 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3383 nt_status
= net_copy_fileattr(c
,
3384 cp_clistate
->mem_ctx
,
3385 cp_clistate
->cli_share_src
,
3386 cp_clistate
->cli_share_dst
,
3388 c
->opt_acls
? true : false,
3389 c
->opt_attrs
? true : false,
3390 c
->opt_timestamps
? true: false,
3394 d_fprintf(stderr
, _("Unsupported mode %d\n"), net_mode_share
);
3398 if (!NT_STATUS_IS_OK(nt_status
)) {
3399 printf(_("Could handle directory attributes for top level "
3400 "directory of share %s. Error %s\n"),
3401 sharename
, nt_errstr(nt_status
));
3409 * Sync all files inside a remote share to another share (over smb).
3411 * All parameters are provided by the run_rpc_command function, except for
3412 * argc, argv which are passed through.
3414 * @param domain_sid The domain sid acquired from the remote server.
3415 * @param cli A cli_state connected to the server.
3416 * @param mem_ctx Talloc context, destroyed on completion of the function.
3417 * @param argc Standard main() style argc.
3418 * @param argv Standard main() style argv. Initial components are already
3421 * @return Normal NTSTATUS return.
3424 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3425 const DOM_SID
*domain_sid
,
3426 const char *domain_name
,
3427 struct cli_state
*cli
,
3428 struct rpc_pipe_client
*pipe_hnd
,
3429 TALLOC_CTX
*mem_ctx
,
3434 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3435 struct srvsvc_NetShareInfoCtr ctr_src
;
3438 struct copy_clistate cp_clistate
;
3439 bool got_src_share
= false;
3440 bool got_dst_share
= false;
3441 const char *mask
= "\\*";
3444 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3446 nt_status
= NT_STATUS_NO_MEMORY
;
3450 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3453 if (!W_ERROR_IS_OK(result
))
3456 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3458 struct srvsvc_NetShareInfo502 info502
=
3459 ctr_src
.ctr
.ctr502
->array
[i
];
3461 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3464 /* one might not want to mirror whole discs :) */
3465 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3466 d_printf(_("skipping [%s]: builtin/hidden share\n"),
3471 switch (net_mode_share
)
3473 case NET_MODE_SHARE_MIGRATE
:
3477 d_fprintf(stderr
, _("Unsupported mode %d\n"),
3481 printf(_(" [%s] files and directories %s ACLs, %s DOS "
3484 c
->opt_acls
? _("including") : _("without"),
3485 c
->opt_attrs
? _("including") : _("without"),
3486 c
->opt_timestamps
? _("(preserving timestamps)") : "");
3488 cp_clistate
.mem_ctx
= mem_ctx
;
3489 cp_clistate
.cli_share_src
= NULL
;
3490 cp_clistate
.cli_share_dst
= NULL
;
3491 cp_clistate
.cwd
= NULL
;
3492 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3495 /* open share source */
3496 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3497 &cli
->dest_ss
, cli
->desthost
,
3498 info502
.name
, "A:");
3499 if (!NT_STATUS_IS_OK(nt_status
))
3502 got_src_share
= true;
3504 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3505 /* open share destination */
3506 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3507 NULL
, dst
, info502
.name
, "A:");
3508 if (!NT_STATUS_IS_OK(nt_status
))
3511 got_dst_share
= true;
3514 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3515 d_fprintf(stderr
, _("Could not handle the top level "
3516 "directory permissions for the "
3517 "share: %s\n"), info502
.name
);
3518 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3522 if (!sync_files(&cp_clistate
, mask
)) {
3523 d_fprintf(stderr
, _("could not handle files for share: "
3524 "%s\n"), info502
.name
);
3525 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3530 nt_status
= NT_STATUS_OK
;
3535 cli_shutdown(cp_clistate
.cli_share_src
);
3538 cli_shutdown(cp_clistate
.cli_share_dst
);
3545 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3547 if (c
->display_usage
) {
3548 d_printf(_("Usage:\n"
3549 "net share migrate files\n"
3550 " Migrate files to local server\n"));
3555 d_printf(_("no server to migrate\n"));
3559 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3560 rpc_share_migrate_files_internals
,
3565 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3567 * All parameters are provided by the run_rpc_command function, except for
3568 * argc, argv which are passed through.
3570 * @param domain_sid The domain sid acquired from the remote server.
3571 * @param cli A cli_state connected to the server.
3572 * @param mem_ctx Talloc context, destroyed on completion of the function.
3573 * @param argc Standard main() style argc.
3574 * @param argv Standard main() style argv. Initial components are already
3577 * @return Normal NTSTATUS return.
3580 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3581 const DOM_SID
*domain_sid
,
3582 const char *domain_name
,
3583 struct cli_state
*cli
,
3584 struct rpc_pipe_client
*pipe_hnd
,
3585 TALLOC_CTX
*mem_ctx
,
3590 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3591 struct srvsvc_NetShareInfoCtr ctr_src
;
3592 union srvsvc_NetShareInfo info
;
3594 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3595 struct cli_state
*cli_dst
= NULL
;
3596 uint32 level
= 502; /* includes secdesc */
3597 uint32_t parm_error
= 0;
3599 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3602 if (!W_ERROR_IS_OK(result
))
3605 /* connect destination PI_SRVSVC */
3606 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3607 &ndr_table_srvsvc
.syntax_id
);
3608 if (!NT_STATUS_IS_OK(nt_status
))
3612 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3614 struct srvsvc_NetShareInfo502 info502
=
3615 ctr_src
.ctr
.ctr502
->array
[i
];
3617 /* reset error-code */
3618 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3620 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3623 printf(_("migrating: [%s], path: %s, comment: %s, including "
3625 info502
.name
, info502
.path
, info502
.comment
);
3628 display_sec_desc(info502
.sd_buf
.sd
);
3630 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3631 info
.info502
= &info502
;
3633 /* finally modify the share on the dst server */
3634 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3635 srvsvc_pipe
->desthost
,
3641 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3642 printf(_("cannot set share-acl: %s\n"),
3643 win_errstr(result
));
3649 nt_status
= NT_STATUS_OK
;
3653 cli_shutdown(cli_dst
);
3661 * Migrate share-acls from a RPC server to another.
3663 * @param argc Standard main() style argc.
3664 * @param argv Standard main() style argv. Initial components are already
3667 * @return A shell status integer (0 for success).
3669 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3672 if (c
->display_usage
) {
3673 d_printf(_("Usage:\n"
3674 "net rpc share migrate security\n"
3675 " Migrate share-acls to local server\n"));
3680 d_printf(_("no server to migrate\n"));
3684 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3685 rpc_share_migrate_security_internals
,
3690 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3691 * from one server to another.
3693 * @param argc Standard main() style argc.
3694 * @param argv Standard main() style argv. Initial components are already
3697 * @return A shell status integer (0 for success).
3700 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3705 if (c
->display_usage
) {
3706 d_printf(_("Usage:\n"
3707 "net rpc share migrate all\n"
3708 " Migrates shares including all share settings\n"));
3713 d_printf(_("no server to migrate\n"));
3717 /* order is important. we don't want to be locked out by the share-acl
3718 * before copying files - gd */
3720 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3721 rpc_share_migrate_shares_internals
, argc
, argv
);
3725 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3726 rpc_share_migrate_files_internals
, argc
, argv
);
3730 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3731 rpc_share_migrate_security_internals
, argc
,
3737 * 'net rpc share migrate' entrypoint.
3738 * @param argc Standard main() style argc.
3739 * @param argv Standard main() style argv. Initial components are already
3742 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3745 struct functable func
[] = {
3748 rpc_share_migrate_all
,
3750 N_("Migrate shares from remote to local server"),
3751 N_("net rpc share migrate all\n"
3752 " Migrate shares from remote to local server")
3756 rpc_share_migrate_files
,
3758 N_("Migrate files from remote to local server"),
3759 N_("net rpc share migrate files\n"
3760 " Migrate files from remote to local server")
3764 rpc_share_migrate_security
,
3766 N_("Migrate share-ACLs from remote to local server"),
3767 N_("net rpc share migrate security\n"
3768 " Migrate share-ACLs from remote to local server")
3772 rpc_share_migrate_shares
,
3774 N_("Migrate shares from remote to local server"),
3775 N_("net rpc share migrate shares\n"
3776 " Migrate shares from remote to local server")
3778 {NULL
, NULL
, 0, NULL
, NULL
}
3781 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3783 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3792 static int num_server_aliases
;
3793 static struct full_alias
*server_aliases
;
3796 * Add an alias to the static list.
3798 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3800 if (server_aliases
== NULL
)
3801 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3803 server_aliases
[num_server_aliases
] = *alias
;
3804 num_server_aliases
+= 1;
3808 * For a specific domain on the server, fetch all the aliases
3809 * and their members. Add all of them to the server_aliases.
3812 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3813 TALLOC_CTX
*mem_ctx
,
3814 struct policy_handle
*connect_pol
,
3815 const DOM_SID
*domain_sid
)
3817 uint32 start_idx
, max_entries
, num_entries
, i
;
3818 struct samr_SamArray
*groups
= NULL
;
3820 struct policy_handle domain_pol
;
3822 /* Get domain policy handle */
3824 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3826 MAXIMUM_ALLOWED_ACCESS
,
3827 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3829 if (!NT_STATUS_IS_OK(result
))
3836 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3842 for (i
= 0; i
< num_entries
; i
++) {
3844 struct policy_handle alias_pol
;
3845 struct full_alias alias
;
3846 struct lsa_SidArray sid_array
;
3849 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3851 MAXIMUM_ALLOWED_ACCESS
,
3852 groups
->entries
[i
].idx
,
3854 if (!NT_STATUS_IS_OK(result
))
3857 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3860 if (!NT_STATUS_IS_OK(result
))
3863 alias
.num_members
= sid_array
.num_sids
;
3865 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3866 if (!NT_STATUS_IS_OK(result
))
3869 alias
.members
= NULL
;
3871 if (alias
.num_members
> 0) {
3872 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3874 for (j
= 0; j
< alias
.num_members
; j
++)
3875 sid_copy(&alias
.members
[j
],
3876 sid_array
.sids
[j
].sid
);
3879 sid_copy(&alias
.sid
, domain_sid
);
3880 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3882 push_alias(mem_ctx
, &alias
);
3884 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3886 result
= NT_STATUS_OK
;
3889 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3895 * Dump server_aliases as names for debugging purposes.
3898 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3899 const DOM_SID
*domain_sid
,
3900 const char *domain_name
,
3901 struct cli_state
*cli
,
3902 struct rpc_pipe_client
*pipe_hnd
,
3903 TALLOC_CTX
*mem_ctx
,
3909 struct policy_handle lsa_pol
;
3911 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3912 SEC_FLAG_MAXIMUM_ALLOWED
,
3914 if (!NT_STATUS_IS_OK(result
))
3917 for (i
=0; i
<num_server_aliases
; i
++) {
3920 enum lsa_SidType
*types
;
3923 struct full_alias
*alias
= &server_aliases
[i
];
3925 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3927 &domains
, &names
, &types
);
3928 if (!NT_STATUS_IS_OK(result
))
3931 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3933 if (alias
->num_members
== 0) {
3938 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3941 &domains
, &names
, &types
);
3943 if (!NT_STATUS_IS_OK(result
) &&
3944 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3947 for (j
=0; j
<alias
->num_members
; j
++)
3948 DEBUG(1, ("%s\\%s (%d); ",
3949 domains
[j
] ? domains
[j
] : "*unknown*",
3950 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3954 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3956 return NT_STATUS_OK
;
3960 * Fetch a list of all server aliases and their members into
3964 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3965 const DOM_SID
*domain_sid
,
3966 const char *domain_name
,
3967 struct cli_state
*cli
,
3968 struct rpc_pipe_client
*pipe_hnd
,
3969 TALLOC_CTX
*mem_ctx
,
3974 struct policy_handle connect_pol
;
3976 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3978 MAXIMUM_ALLOWED_ACCESS
,
3981 if (!NT_STATUS_IS_OK(result
))
3984 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3985 &global_sid_Builtin
);
3987 if (!NT_STATUS_IS_OK(result
))
3990 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3993 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
3998 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4000 token
->num_sids
= 4;
4002 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4003 d_fprintf(stderr
, _("malloc failed\n"));
4004 token
->num_sids
= 0;
4008 token
->user_sids
[0] = *user_sid
;
4009 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4010 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4011 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4014 static void free_user_token(NT_USER_TOKEN
*token
)
4016 SAFE_FREE(token
->user_sids
);
4019 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4021 if (is_sid_in_token(token
, sid
))
4024 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4025 if (!token
->user_sids
) {
4029 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4031 token
->num_sids
+= 1;
4036 NT_USER_TOKEN token
;
4039 static void dump_user_token(struct user_token
*token
)
4043 d_printf("%s\n", token
->name
);
4045 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4046 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4050 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4054 for (i
=0; i
<alias
->num_members
; i
++) {
4055 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4062 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4066 for (i
=0; i
<num_server_aliases
; i
++) {
4067 if (is_alias_member(&sid
, &server_aliases
[i
]))
4068 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4073 * We got a user token with all the SIDs we can know about without asking the
4074 * server directly. These are the user and domain group sids. All of these can
4075 * be members of aliases. So scan the list of aliases for each of the SIDs and
4076 * add them to the token.
4079 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4081 int num_global_sids
= token
->num_sids
;
4084 for (i
=0; i
<num_global_sids
; i
++) {
4085 collect_sid_memberships(token
, token
->user_sids
[i
]);
4089 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4091 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4092 enum wbcSidType type
;
4094 struct wbcDomainSid wsid
;
4095 char *sid_str
= NULL
;
4097 uint32_t num_groups
;
4098 gid_t
*groups
= NULL
;
4101 fstr_sprintf(full_name
, "%s%c%s",
4102 domain
, *lp_winbind_separator(), user
);
4104 /* First let's find out the user sid */
4106 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4108 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4109 DEBUG(1, ("winbind could not find %s: %s\n",
4110 full_name
, wbcErrorString(wbc_status
)));
4114 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4115 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4119 if (type
!= SID_NAME_USER
) {
4120 wbcFreeMemory(sid_str
);
4121 DEBUG(1, ("%s is not a user\n", full_name
));
4125 if (!string_to_sid(&user_sid
, sid_str
)) {
4126 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4130 wbcFreeMemory(sid_str
);
4133 init_user_token(token
, &user_sid
);
4135 /* And now the groups winbind knows about */
4137 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4138 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4139 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4140 full_name
, wbcErrorString(wbc_status
)));
4144 for (i
= 0; i
< num_groups
; i
++) {
4145 gid_t gid
= groups
[i
];
4148 wbc_status
= wbcGidToSid(gid
, &wsid
);
4149 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4150 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4151 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4152 wbcFreeMemory(groups
);
4156 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4157 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4158 wbcFreeMemory(groups
);
4162 DEBUG(3, (" %s\n", sid_str
));
4164 string_to_sid(&sid
, sid_str
);
4165 wbcFreeMemory(sid_str
);
4168 add_sid_to_token(token
, &sid
);
4170 wbcFreeMemory(groups
);
4176 * Get a list of all user tokens we want to look at
4179 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4180 struct user_token
**user_tokens
)
4182 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4183 uint32_t i
, num_users
;
4185 struct user_token
*result
;
4186 TALLOC_CTX
*frame
= NULL
;
4188 if (lp_winbind_use_default_domain() &&
4189 (c
->opt_target_workgroup
== NULL
)) {
4190 d_fprintf(stderr
, _("winbind use default domain = yes set, "
4191 "please specify a workgroup\n"));
4195 /* Send request to winbind daemon */
4197 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4198 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4199 DEBUG(1, (_("winbind could not list users: %s\n"),
4200 wbcErrorString(wbc_status
)));
4204 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4206 if (result
== NULL
) {
4207 DEBUG(1, ("Could not malloc sid array\n"));
4208 wbcFreeMemory(users
);
4212 frame
= talloc_stackframe();
4213 for (i
=0; i
< num_users
; i
++) {
4214 fstring domain
, user
;
4217 fstrcpy(result
[i
].name
, users
[i
]);
4219 p
= strchr(users
[i
], *lp_winbind_separator());
4221 DEBUG(3, ("%s\n", users
[i
]));
4224 fstrcpy(domain
, c
->opt_target_workgroup
);
4225 fstrcpy(user
, users
[i
]);
4228 fstrcpy(domain
, users
[i
]);
4233 get_user_sids(domain
, user
, &(result
[i
].token
));
4237 wbcFreeMemory(users
);
4239 *num_tokens
= num_users
;
4240 *user_tokens
= result
;
4245 static bool get_user_tokens_from_file(FILE *f
,
4247 struct user_token
**tokens
)
4249 struct user_token
*token
= NULL
;
4254 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4258 if (line
[strlen(line
)-1] == '\n')
4259 line
[strlen(line
)-1] = '\0';
4261 if (line
[0] == ' ') {
4265 if(!string_to_sid(&sid
, &line
[1])) {
4266 DEBUG(1,("get_user_tokens_from_file: Could "
4267 "not convert sid %s \n",&line
[1]));
4271 if (token
== NULL
) {
4272 DEBUG(0, ("File does not begin with username"));
4276 add_sid_to_token(&token
->token
, &sid
);
4280 /* And a new user... */
4283 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4284 if (*tokens
== NULL
) {
4285 DEBUG(0, ("Could not realloc tokens\n"));
4289 token
= &((*tokens
)[*num_tokens
-1]);
4291 fstrcpy(token
->name
, line
);
4292 token
->token
.num_sids
= 0;
4293 token
->token
.user_sids
= NULL
;
4302 * Show the list of all users that have access to a share
4305 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4306 TALLOC_CTX
*mem_ctx
,
4307 const char *netname
,
4309 struct user_token
*tokens
)
4312 SEC_DESC
*share_sd
= NULL
;
4313 SEC_DESC
*root_sd
= NULL
;
4314 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4316 union srvsvc_NetShareInfo info
;
4321 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4328 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4329 DEBUG(1, ("Coult not query secdesc for share %s\n",
4334 share_sd
= info
.info502
->sd_buf
.sd
;
4335 if (share_sd
== NULL
) {
4336 DEBUG(1, ("Got no secdesc for share %s\n",
4342 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4346 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, "\\", 0, READ_CONTROL_ACCESS
, 0,
4347 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum
))) {
4348 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4351 for (i
=0; i
<num_tokens
; i
++) {
4354 if (share_sd
!= NULL
) {
4355 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4358 if (!NT_STATUS_IS_OK(status
)) {
4359 DEBUG(1, ("Could not check share_sd for "
4366 if (root_sd
== NULL
) {
4367 d_printf(" %s\n", tokens
[i
].name
);
4371 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4373 if (!NT_STATUS_IS_OK(status
)) {
4374 DEBUG(1, ("Could not check root_sd for user %s\n",
4378 d_printf(" %s\n", tokens
[i
].name
);
4381 if (fnum
!= (uint16_t)-1)
4382 cli_close(cli
, fnum
);
4394 static void collect_share(const char *name
, uint32 m
,
4395 const char *comment
, void *state
)
4397 struct share_list
*share_list
= (struct share_list
*)state
;
4399 if (m
!= STYPE_DISKTREE
)
4402 share_list
->num_shares
+= 1;
4403 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4404 if (!share_list
->shares
) {
4405 share_list
->num_shares
= 0;
4408 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4412 * List shares on a remote RPC server, including the security descriptors.
4414 * All parameters are provided by the run_rpc_command function, except for
4415 * argc, argv which are passed through.
4417 * @param domain_sid The domain sid acquired from the remote server.
4418 * @param cli A cli_state connected to the server.
4419 * @param mem_ctx Talloc context, destroyed on completion of the function.
4420 * @param argc Standard main() style argc.
4421 * @param argv Standard main() style argv. Initial components are already
4424 * @return Normal NTSTATUS return.
4427 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4428 const DOM_SID
*domain_sid
,
4429 const char *domain_name
,
4430 struct cli_state
*cli
,
4431 struct rpc_pipe_client
*pipe_hnd
,
4432 TALLOC_CTX
*mem_ctx
,
4441 struct user_token
*tokens
= NULL
;
4444 struct share_list share_list
;
4449 f
= fopen(argv
[0], "r");
4453 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4454 return NT_STATUS_UNSUCCESSFUL
;
4457 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4463 DEBUG(0, ("Could not read users from file\n"));
4464 return NT_STATUS_UNSUCCESSFUL
;
4467 for (i
=0; i
<num_tokens
; i
++)
4468 collect_alias_memberships(&tokens
[i
].token
);
4470 share_list
.num_shares
= 0;
4471 share_list
.shares
= NULL
;
4473 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4476 DEBUG(0, ("Error returning browse list: %s\n",
4481 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4482 char *netname
= share_list
.shares
[i
];
4484 if (netname
[strlen(netname
)-1] == '$')
4487 d_printf("%s\n", netname
);
4489 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4490 num_tokens
, tokens
);
4493 for (i
=0; i
<num_tokens
; i
++) {
4494 free_user_token(&tokens
[i
].token
);
4497 SAFE_FREE(share_list
.shares
);
4499 return NT_STATUS_OK
;
4502 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4507 if (c
->display_usage
) {
4508 d_printf(_("Usage:\n"
4509 "net rpc share allowedusers\n"
4510 " List allowed users\n"));
4514 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4515 rpc_aliaslist_internals
,
4520 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4526 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4527 rpc_share_allowedusers_internals
,
4531 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4534 struct user_token
*tokens
= NULL
;
4538 net_usersidlist_usage(c
, argc
, argv
);
4542 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4543 DEBUG(0, ("Could not get the user/sid list\n"));
4547 for (i
=0; i
<num_tokens
; i
++) {
4548 dump_user_token(&tokens
[i
]);
4549 free_user_token(&tokens
[i
].token
);
4556 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4558 d_printf(_("net usersidlist\n"
4559 "\tprints out a list of all users the running winbind knows\n"
4560 "\tabout, together with all their SIDs. This is used as\n"
4561 "\tinput to the 'net rpc share allowedusers' command.\n\n"));
4563 net_common_flags_usage(c
, argc
, argv
);
4568 * 'net rpc share' entrypoint.
4569 * @param argc Standard main() style argc.
4570 * @param argv Standard main() style argv. Initial components are already
4574 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4576 NET_API_STATUS status
;
4578 struct functable func
[] = {
4584 N_("net rpc share add\n"
4592 N_("net rpc share delete\n"
4597 rpc_share_allowedusers
,
4599 N_("Modify allowed users"),
4600 N_("net rpc share allowedusers\n"
4601 " Modify allowed users")
4607 N_("Migrate share to local server"),
4608 N_("net rpc share migrate\n"
4609 " Migrate share to local server")
4616 N_("net rpc share list\n"
4619 {NULL
, NULL
, 0, NULL
, NULL
}
4622 status
= libnetapi_init(&c
->netapi_ctx
);
4626 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4627 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4628 if (c
->opt_kerberos
) {
4629 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4633 if (c
->display_usage
) {
4634 d_printf(_("Usage:\n"
4637 " Alias for net rpc share list\n"));
4638 net_display_usage_from_functable(func
);
4642 return rpc_share_list(c
, argc
, argv
);
4645 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4648 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4649 TALLOC_CTX
*mem_ctx
,
4650 struct rpc_sh_ctx
*ctx
,
4651 struct rpc_pipe_client
*pipe_hnd
,
4652 int argc
, const char **argv
)
4655 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4658 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4659 TALLOC_CTX
*mem_ctx
,
4660 struct rpc_sh_ctx
*ctx
,
4661 struct rpc_pipe_client
*pipe_hnd
,
4662 int argc
, const char **argv
)
4664 NET_API_STATUS status
;
4665 uint32_t parm_err
= 0;
4666 struct SHARE_INFO_2 i2
;
4668 if ((argc
< 2) || (argc
> 3)) {
4669 d_fprintf(stderr
, _("usage: %s <share> <path> [comment]\n"),
4671 return NT_STATUS_INVALID_PARAMETER
;
4674 i2
.shi2_netname
= argv
[0];
4675 i2
.shi2_type
= STYPE_DISKTREE
;
4676 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4677 i2
.shi2_permissions
= 0;
4678 i2
.shi2_max_uses
= 0;
4679 i2
.shi2_current_uses
= 0;
4680 i2
.shi2_path
= argv
[1];
4681 i2
.shi2_passwd
= NULL
;
4683 status
= NetShareAdd(pipe_hnd
->desthost
,
4688 return werror_to_ntstatus(W_ERROR(status
));
4691 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4692 TALLOC_CTX
*mem_ctx
,
4693 struct rpc_sh_ctx
*ctx
,
4694 struct rpc_pipe_client
*pipe_hnd
,
4695 int argc
, const char **argv
)
4698 d_fprintf(stderr
, _("usage: %s <share>\n"), ctx
->whoami
);
4699 return NT_STATUS_INVALID_PARAMETER
;
4702 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4705 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4706 TALLOC_CTX
*mem_ctx
,
4707 struct rpc_sh_ctx
*ctx
,
4708 struct rpc_pipe_client
*pipe_hnd
,
4709 int argc
, const char **argv
)
4711 union srvsvc_NetShareInfo info
;
4716 d_fprintf(stderr
, _("usage: %s <share>\n"), ctx
->whoami
);
4717 return NT_STATUS_INVALID_PARAMETER
;
4720 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4726 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4730 d_printf(_("Name: %s\n"), info
.info2
->name
);
4731 d_printf(_("Comment: %s\n"), info
.info2
->comment
);
4732 d_printf(_("Path: %s\n"), info
.info2
->path
);
4733 d_printf(_("Password: %s\n"), info
.info2
->password
);
4736 return werror_to_ntstatus(result
);
4739 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4740 struct rpc_sh_ctx
*ctx
)
4742 static struct rpc_sh_cmd cmds
[] = {
4744 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4745 N_("List available shares") },
4747 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4748 N_("Add a share") },
4750 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4751 N_("Delete a share") },
4753 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4754 N_("Get information about a share") },
4756 { NULL
, NULL
, 0, NULL
, NULL
}
4762 /****************************************************************************/
4764 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4766 return net_file_usage(c
, argc
, argv
);
4770 * Close a file on a remote RPC server.
4772 * @param argc Standard main() style argc.
4773 * @param argv Standard main() style argv. Initial components are already
4776 * @return A shell status integer (0 for success).
4778 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4780 if (argc
< 1 || c
->display_usage
) {
4781 return rpc_file_usage(c
, argc
, argv
);
4784 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4788 * Formatted print of open file info
4790 * @param r struct FILE_INFO_3 contents
4793 static void display_file_info_3(struct FILE_INFO_3
*r
)
4795 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4796 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4797 r
->fi3_num_locks
, r
->fi3_pathname
);
4801 * List files for a user on a remote RPC server.
4803 * @param argc Standard main() style argc.
4804 * @param argv Standard main() style argv. Initial components are already
4807 * @return A shell status integer (0 for success)..
4810 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4812 NET_API_STATUS status
;
4813 uint32 preferred_len
= 0xffffffff, i
;
4814 const char *username
=NULL
;
4815 uint32_t total_entries
= 0;
4816 uint32_t entries_read
= 0;
4817 uint32_t resume_handle
= 0;
4818 struct FILE_INFO_3
*i3
= NULL
;
4820 if (c
->display_usage
) {
4821 return rpc_file_usage(c
, argc
, argv
);
4824 /* if argc > 0, must be user command */
4826 username
= smb_xstrdup(argv
[0]);
4829 status
= NetFileEnum(c
->opt_host
,
4833 (uint8_t **)(void *)&i3
,
4843 /* Display results */
4846 "\nEnumerating open files on remote server:\n\n"
4847 "\nFileId Opened by Perms Locks Path"
4848 "\n------ --------- ----- ----- ---- \n"));
4849 for (i
= 0; i
< entries_read
; i
++) {
4850 display_file_info_3(&i3
[i
]);
4857 * 'net rpc file' entrypoint.
4858 * @param argc Standard main() style argc.
4859 * @param argv Standard main() style argv. Initial components are already
4863 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4865 NET_API_STATUS status
;
4867 struct functable func
[] = {
4872 N_("Close opened file"),
4873 N_("net rpc file close\n"
4874 " Close opened file")
4880 N_("List files opened by user"),
4881 N_("net rpc file user\n"
4882 " List files opened by user")
4889 N_("Display information about opened file"),
4890 N_("net rpc file info\n"
4891 " Display information about opened file")
4894 {NULL
, NULL
, 0, NULL
, NULL
}
4897 status
= libnetapi_init(&c
->netapi_ctx
);
4901 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4902 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4903 if (c
->opt_kerberos
) {
4904 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4908 if (c
->display_usage
) {
4909 d_printf(_("Usage:\n"));
4910 d_printf(_("net rpc file\n"
4911 " List opened files\n"));
4912 net_display_usage_from_functable(func
);
4916 return rpc_file_user(c
, argc
, argv
);
4919 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4923 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4925 * All parameters are provided by the run_rpc_command function, except for
4926 * argc, argv which are passed through.
4928 * @param c A net_context structure.
4929 * @param domain_sid The domain sid acquired from the remote server.
4930 * @param cli A cli_state connected to the server.
4931 * @param mem_ctx Talloc context, destroyed on completion of the function.
4932 * @param argc Standard main() style argc.
4933 * @param argv Standard main() style argv. Initial components are already
4936 * @return Normal NTSTATUS return.
4939 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4940 const DOM_SID
*domain_sid
,
4941 const char *domain_name
,
4942 struct cli_state
*cli
,
4943 struct rpc_pipe_client
*pipe_hnd
,
4944 TALLOC_CTX
*mem_ctx
,
4948 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4950 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4952 if (NT_STATUS_IS_OK(result
)) {
4953 d_printf(_("\nShutdown successfully aborted\n"));
4954 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4956 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4962 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
4964 * All parameters are provided by the run_rpc_command function, except for
4965 * argc, argv which are passed through.
4967 * @param c A net_context structure.
4968 * @param domain_sid The domain sid acquired from the remote server.
4969 * @param cli A cli_state connected to the server.
4970 * @param mem_ctx Talloc context, destroyed on completion of the function.
4971 * @param argc Standard main() style argc.
4972 * @param argv Standard main() style argv. Initial components are already
4975 * @return Normal NTSTATUS return.
4978 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
4979 const DOM_SID
*domain_sid
,
4980 const char *domain_name
,
4981 struct cli_state
*cli
,
4982 struct rpc_pipe_client
*pipe_hnd
,
4983 TALLOC_CTX
*mem_ctx
,
4987 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4989 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4991 if (NT_STATUS_IS_OK(result
)) {
4992 d_printf(_("\nShutdown successfully aborted\n"));
4993 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4995 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5001 * ABORT the shutdown of a remote RPC server.
5003 * @param argc Standard main() style argc.
5004 * @param argv Standard main() style argv. Initial components are already
5007 * @return A shell status integer (0 for success).
5010 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5015 if (c
->display_usage
) {
5016 d_printf(_("Usage:\n"
5017 "net rpc abortshutdown\n"
5018 " Abort a scheduled shutdown\n"));
5022 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5023 rpc_shutdown_abort_internals
, argc
, argv
);
5028 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5030 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5031 rpc_reg_shutdown_abort_internals
,
5036 * Shut down a remote RPC Server via initshutdown pipe.
5038 * All parameters are provided by the run_rpc_command function, except for
5039 * argc, argv which are passed through.
5041 * @param c A net_context structure.
5042 * @param domain_sid The domain sid acquired from the remote server.
5043 * @param cli A cli_state connected to the server.
5044 * @param mem_ctx Talloc context, destroyed on completion of the function.
5045 * @param argc Standard main() style argc.
5046 * @param argv Standard main() style argv. Initial components are already
5049 * @return Normal NTSTATUS return.
5052 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5053 const DOM_SID
*domain_sid
,
5054 const char *domain_name
,
5055 struct cli_state
*cli
,
5056 struct rpc_pipe_client
*pipe_hnd
,
5057 TALLOC_CTX
*mem_ctx
,
5061 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5062 const char *msg
= N_("This machine will be shutdown shortly");
5063 uint32 timeout
= 20;
5064 struct lsa_StringLarge msg_string
;
5066 if (c
->opt_comment
) {
5067 msg
= c
->opt_comment
;
5069 if (c
->opt_timeout
) {
5070 timeout
= c
->opt_timeout
;
5073 msg_string
.string
= msg
;
5075 /* create an entry */
5076 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5077 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5080 if (NT_STATUS_IS_OK(result
)) {
5081 d_printf(_("\nShutdown of remote machine succeeded\n"));
5082 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5084 DEBUG(1,("Shutdown of remote machine failed!\n"));
5090 * Shut down a remote RPC Server via winreg pipe.
5092 * All parameters are provided by the run_rpc_command function, except for
5093 * argc, argv which are passed through.
5095 * @param c A net_context structure.
5096 * @param domain_sid The domain sid acquired from the remote server.
5097 * @param cli A cli_state connected to the server.
5098 * @param mem_ctx Talloc context, destroyed on completion of the function.
5099 * @param argc Standard main() style argc.
5100 * @param argv Standard main() style argv. Initial components are already
5103 * @return Normal NTSTATUS return.
5106 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5107 const DOM_SID
*domain_sid
,
5108 const char *domain_name
,
5109 struct cli_state
*cli
,
5110 struct rpc_pipe_client
*pipe_hnd
,
5111 TALLOC_CTX
*mem_ctx
,
5115 const char *msg
= N_("This machine will be shutdown shortly");
5116 uint32 timeout
= 20;
5117 struct lsa_StringLarge msg_string
;
5121 if (c
->opt_comment
) {
5122 msg
= c
->opt_comment
;
5124 msg_string
.string
= msg
;
5126 if (c
->opt_timeout
) {
5127 timeout
= c
->opt_timeout
;
5130 /* create an entry */
5131 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5132 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5135 if (NT_STATUS_IS_OK(result
)) {
5136 d_printf(_("\nShutdown of remote machine succeeded\n"));
5138 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5139 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5140 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5142 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5149 * Shut down a remote RPC server.
5151 * @param argc Standard main() style argc.
5152 * @param argv Standard main() style argv. Initial components are already
5155 * @return A shell status integer (0 for success).
5158 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5162 if (c
->display_usage
) {
5163 d_printf(_("Usage:\n"
5164 "net rpc shutdown\n"
5165 " Shut down a remote RPC server\n"));
5169 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5170 rpc_init_shutdown_internals
, argc
, argv
);
5173 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5174 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5175 rpc_reg_shutdown_internals
, argc
, argv
);
5181 /***************************************************************************
5182 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5183 ***************************************************************************/
5186 * Add interdomain trust account to the RPC server.
5187 * All parameters (except for argc and argv) are passed by run_rpc_command
5190 * @param c A net_context structure.
5191 * @param domain_sid The domain sid acquired from the server.
5192 * @param cli A cli_state connected to the server.
5193 * @param mem_ctx Talloc context, destroyed on completion of the function.
5194 * @param argc Standard main() style argc.
5195 * @param argv Standard main() style argv. Initial components are already
5198 * @return normal NTSTATUS return code.
5201 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5202 const DOM_SID
*domain_sid
,
5203 const char *domain_name
,
5204 struct cli_state
*cli
,
5205 struct rpc_pipe_client
*pipe_hnd
,
5206 TALLOC_CTX
*mem_ctx
,
5210 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5211 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5213 struct lsa_String lsa_acct_name
;
5215 uint32 acct_flags
=0;
5217 uint32_t access_granted
= 0;
5218 union samr_UserInfo info
;
5219 unsigned int orig_timeout
;
5222 d_printf(_("Usage: net rpc trustdom add <domain_name> "
5223 "<trust password>\n"));
5224 return NT_STATUS_INVALID_PARAMETER
;
5228 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5231 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5232 return NT_STATUS_NO_MEMORY
;
5235 strupper_m(acct_name
);
5237 init_lsa_String(&lsa_acct_name
, acct_name
);
5239 /* Get samr policy handle */
5240 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5242 MAXIMUM_ALLOWED_ACCESS
,
5244 if (!NT_STATUS_IS_OK(result
)) {
5248 /* Get domain policy handle */
5249 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5251 MAXIMUM_ALLOWED_ACCESS
,
5252 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5254 if (!NT_STATUS_IS_OK(result
)) {
5258 /* This call can take a long time - allow the server to time out.
5259 * 35 seconds should do it. */
5261 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5263 /* Create trusting domain's account */
5264 acb_info
= ACB_NORMAL
;
5265 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5266 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5267 SAMR_USER_ACCESS_SET_PASSWORD
|
5268 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5269 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5271 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5280 /* And restore our original timeout. */
5281 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5283 if (!NT_STATUS_IS_OK(result
)) {
5284 d_printf(_("net rpc trustdom add: create user %s failed %s\n"),
5285 acct_name
, nt_errstr(result
));
5290 struct samr_CryptPassword crypt_pwd
;
5292 ZERO_STRUCT(info
.info23
);
5294 init_samr_CryptPassword(argv
[1],
5295 &cli
->user_session_key
,
5298 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5299 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5300 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5301 info
.info23
.password
= crypt_pwd
;
5303 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5308 if (!NT_STATUS_IS_OK(result
)) {
5309 DEBUG(0,("Could not set trust account password: %s\n",
5310 nt_errstr(result
)));
5316 SAFE_FREE(acct_name
);
5321 * Create interdomain trust account for a remote domain.
5323 * @param argc Standard argc.
5324 * @param argv Standard argv without initial components.
5326 * @return Integer status (0 means success).
5329 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5331 if (argc
> 0 && !c
->display_usage
) {
5332 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5333 rpc_trustdom_add_internals
, argc
, argv
);
5335 d_printf(_("Usage:\n"
5336 "net rpc trustdom add <domain_name> <trust "
5344 * Remove interdomain trust account from the RPC server.
5345 * All parameters (except for argc and argv) are passed by run_rpc_command
5348 * @param c A net_context structure.
5349 * @param domain_sid The domain sid acquired from the server.
5350 * @param cli A cli_state connected to the server.
5351 * @param mem_ctx Talloc context, destroyed on completion of the function.
5352 * @param argc Standard main() style argc.
5353 * @param argv Standard main() style argv. Initial components are already
5356 * @return normal NTSTATUS return code.
5359 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5360 const DOM_SID
*domain_sid
,
5361 const char *domain_name
,
5362 struct cli_state
*cli
,
5363 struct rpc_pipe_client
*pipe_hnd
,
5364 TALLOC_CTX
*mem_ctx
,
5368 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5369 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5371 DOM_SID trust_acct_sid
;
5372 struct samr_Ids user_rids
, name_types
;
5373 struct lsa_String lsa_acct_name
;
5376 d_printf(_("Usage: net rpc trustdom del <domain_name>\n"));
5377 return NT_STATUS_INVALID_PARAMETER
;
5381 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5383 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5385 if (acct_name
== NULL
)
5386 return NT_STATUS_NO_MEMORY
;
5388 strupper_m(acct_name
);
5390 /* Get samr policy handle */
5391 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5393 MAXIMUM_ALLOWED_ACCESS
,
5395 if (!NT_STATUS_IS_OK(result
)) {
5399 /* Get domain policy handle */
5400 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5402 MAXIMUM_ALLOWED_ACCESS
,
5403 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5405 if (!NT_STATUS_IS_OK(result
)) {
5409 init_lsa_String(&lsa_acct_name
, acct_name
);
5411 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5418 if (!NT_STATUS_IS_OK(result
)) {
5419 d_printf(_("net rpc trustdom del: LookupNames on user %s "
5421 acct_name
, nt_errstr(result
) );
5425 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5427 MAXIMUM_ALLOWED_ACCESS
,
5431 if (!NT_STATUS_IS_OK(result
)) {
5432 d_printf(_("net rpc trustdom del: OpenUser on user %s failed "
5434 acct_name
, nt_errstr(result
) );
5438 /* append the rid to the domain sid */
5439 sid_copy(&trust_acct_sid
, domain_sid
);
5440 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5444 /* remove the sid */
5446 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5449 if (!NT_STATUS_IS_OK(result
)) {
5450 d_printf(_("net rpc trustdom del: RemoveMemberFromForeignDomain"
5451 " on user %s failed %s\n"),
5452 acct_name
, nt_errstr(result
) );
5458 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5461 if (!NT_STATUS_IS_OK(result
)) {
5462 d_printf(_("net rpc trustdom del: DeleteUser on user %s failed "
5464 acct_name
, nt_errstr(result
) );
5468 if (!NT_STATUS_IS_OK(result
)) {
5469 d_printf(_("Could not set trust account password: %s\n"),
5479 * Delete interdomain trust account for a remote domain.
5481 * @param argc Standard argc.
5482 * @param argv Standard argv without initial components.
5484 * @return Integer status (0 means success).
5487 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5489 if (argc
> 0 && !c
->display_usage
) {
5490 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5491 rpc_trustdom_del_internals
, argc
, argv
);
5493 d_printf(_("Usage:\n"
5494 "net rpc trustdom del <domain>\n"));
5499 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5500 struct cli_state
*cli
,
5501 TALLOC_CTX
*mem_ctx
,
5502 const char *domain_name
)
5504 char *dc_name
= NULL
;
5505 const char *buffer
= NULL
;
5506 struct rpc_pipe_client
*netr
;
5509 /* Use NetServerEnum2 */
5511 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5513 return NT_STATUS_OK
;
5516 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5517 for domain %s\n", domain_name
));
5519 /* Try netr_GetDcName */
5521 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5523 if (!NT_STATUS_IS_OK(status
)) {
5527 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5534 if (NT_STATUS_IS_OK(status
)) {
5538 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5539 for domain %s\n", domain_name
));
5545 * Establish trust relationship to a trusting domain.
5546 * Interdomain account must already be created on remote PDC.
5548 * @param c A net_context structure.
5549 * @param argc Standard argc.
5550 * @param argv Standard argv without initial components.
5552 * @return Integer status (0 means success).
5555 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5558 struct cli_state
*cli
= NULL
;
5559 struct sockaddr_storage server_ss
;
5560 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5561 struct policy_handle connect_hnd
;
5562 TALLOC_CTX
*mem_ctx
;
5564 DOM_SID
*domain_sid
;
5569 union lsa_PolicyInformation
*info
= NULL
;
5572 * Connect to \\server\ipc$ as 'our domain' account with password
5575 if (argc
!= 1 || c
->display_usage
) {
5576 d_printf(_("Usage:\n"
5577 "net rpc trustdom establish <domain_name>\n"));
5581 domain_name
= smb_xstrdup(argv
[0]);
5582 strupper_m(domain_name
);
5584 /* account name used at first is our domain's name with '$' */
5585 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5588 strupper_m(acct_name
);
5591 * opt_workgroup will be used by connection functions further,
5592 * hence it should be set to remote domain name instead of ours
5594 if (c
->opt_workgroup
) {
5595 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5598 c
->opt_user_name
= acct_name
;
5600 /* find the domain controller */
5601 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5602 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5606 /* connect to ipc$ as username/password */
5607 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5608 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5610 /* Is it trusting domain account for sure ? */
5611 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5612 nt_errstr(nt_status
)));
5616 /* store who we connected to */
5618 saf_store( domain_name
, pdc_name
);
5621 * Connect to \\server\ipc$ again (this time anonymously)
5624 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5627 if (NT_STATUS_IS_ERR(nt_status
)) {
5628 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5629 domain_name
, nt_errstr(nt_status
)));
5633 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5634 "domain %s", domain_name
))) {
5635 DEBUG(0, ("talloc_init() failed\n"));
5640 /* Make sure we're talking to a proper server */
5642 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5643 if (!NT_STATUS_IS_OK(nt_status
)) {
5645 talloc_destroy(mem_ctx
);
5650 * Call LsaOpenPolicy and LsaQueryInfo
5653 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5655 if (!NT_STATUS_IS_OK(nt_status
)) {
5656 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5658 talloc_destroy(mem_ctx
);
5662 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5664 if (NT_STATUS_IS_ERR(nt_status
)) {
5665 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5666 nt_errstr(nt_status
)));
5668 talloc_destroy(mem_ctx
);
5672 /* Querying info level 5 */
5674 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5676 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5678 if (NT_STATUS_IS_ERR(nt_status
)) {
5679 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5680 nt_errstr(nt_status
)));
5682 talloc_destroy(mem_ctx
);
5686 domain_sid
= info
->account_domain
.sid
;
5688 /* There should be actually query info level 3 (following nt serv behaviour),
5689 but I still don't know if it's _really_ necessary */
5692 * Store the password in secrets db
5695 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5696 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5698 talloc_destroy(mem_ctx
);
5703 * Close the pipes and clean up
5706 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5707 if (NT_STATUS_IS_ERR(nt_status
)) {
5708 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5709 nt_errstr(nt_status
)));
5711 talloc_destroy(mem_ctx
);
5717 talloc_destroy(mem_ctx
);
5719 d_printf(_("Trust to domain %s established\n"), domain_name
);
5724 * Revoke trust relationship to the remote domain.
5726 * @param c A net_context structure.
5727 * @param argc Standard argc.
5728 * @param argv Standard argv without initial components.
5730 * @return Integer status (0 means success).
5733 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5739 if (argc
< 1 || c
->display_usage
) {
5740 d_printf(_("Usage:\n"
5741 "net rpc trustdom revoke <domain_name>\n"
5742 " Revoke trust relationship\n"
5743 " domain_name\tName of domain to revoke trust\n"));
5747 /* generate upper cased domain name */
5748 domain_name
= smb_xstrdup(argv
[0]);
5749 strupper_m(domain_name
);
5751 /* delete password of the trust */
5752 if (!pdb_del_trusteddom_pw(domain_name
)) {
5753 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5760 SAFE_FREE(domain_name
);
5764 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5765 const DOM_SID
*domain_sid
,
5766 const char *domain_name
,
5767 struct cli_state
*cli
,
5768 struct rpc_pipe_client
*pipe_hnd
,
5769 TALLOC_CTX
*mem_ctx
,
5774 if (!sid_to_fstring(str_sid
, domain_sid
)) {
5775 return NT_STATUS_UNSUCCESSFUL
;
5777 d_printf("%s\n", str_sid
);
5778 return NT_STATUS_OK
;
5781 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5785 /* convert sid into ascii string */
5786 sid_to_fstring(ascii_sid
, dom_sid
);
5788 d_printf("%-20s%s\n", trusted_dom_name
, ascii_sid
);
5791 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5792 TALLOC_CTX
*mem_ctx
,
5793 struct policy_handle
*pol
,
5795 const char *trusted_dom_name
)
5798 union lsa_TrustedDomainInfo
*info
= NULL
;
5799 char *cleartextpwd
= NULL
;
5800 uint8_t session_key
[16];
5801 DATA_BLOB session_key_blob
;
5802 DATA_BLOB data
= data_blob_null
;
5804 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5807 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5809 if (NT_STATUS_IS_ERR(nt_status
)) {
5810 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5811 nt_errstr(nt_status
)));
5815 data
= data_blob(info
->password
.password
->data
,
5816 info
->password
.password
->length
);
5818 if (!rpccli_get_pwd_hash(pipe_hnd
, session_key
)) {
5819 DEBUG(0, ("Could not retrieve password hash\n"));
5823 session_key_blob
= data_blob_const(session_key
, sizeof(session_key
));
5824 cleartextpwd
= sess_decrypt_string(mem_ctx
, &data
, &session_key_blob
);
5826 if (cleartextpwd
== NULL
) {
5827 DEBUG(0,("retrieved NULL password\n"));
5828 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5832 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5833 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5834 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5838 #ifdef DEBUG_PASSWORD
5839 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5840 "password: [%s]\n", trusted_dom_name
,
5841 sid_string_dbg(&dom_sid
), cleartextpwd
));
5845 SAFE_FREE(cleartextpwd
);
5846 data_blob_free(&data
);
5851 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5854 /* common variables */
5855 TALLOC_CTX
* mem_ctx
;
5856 struct cli_state
*cli
= NULL
;
5857 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5859 const char *domain_name
= NULL
;
5860 DOM_SID
*queried_dom_sid
;
5861 struct policy_handle connect_hnd
;
5862 union lsa_PolicyInformation
*info
= NULL
;
5864 /* trusted domains listing variables */
5865 unsigned int enum_ctx
= 0;
5867 struct lsa_DomainList dom_list
;
5870 if (c
->display_usage
) {
5871 d_printf(_("Usage:\n"
5872 "net rpc trustdom vampire\n"
5873 " Vampire trust relationship from remote server\n"));
5878 * Listing trusted domains (stored in secrets.tdb, if local)
5881 mem_ctx
= talloc_init("trust relationships vampire");
5884 * set domain and pdc name to local samba server (default)
5885 * or to remote one given in command line
5888 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5889 domain_name
= c
->opt_workgroup
;
5890 c
->opt_target_workgroup
= c
->opt_workgroup
;
5892 fstrcpy(pdc_name
, global_myname());
5893 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5894 c
->opt_target_workgroup
= domain_name
;
5897 /* open \PIPE\lsarpc and open policy handle */
5898 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5899 if (!NT_STATUS_IS_OK(nt_status
)) {
5900 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5901 nt_errstr(nt_status
)));
5902 talloc_destroy(mem_ctx
);
5906 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5908 if (!NT_STATUS_IS_OK(nt_status
)) {
5909 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5910 nt_errstr(nt_status
) ));
5912 talloc_destroy(mem_ctx
);
5916 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5918 if (NT_STATUS_IS_ERR(nt_status
)) {
5919 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5920 nt_errstr(nt_status
)));
5922 talloc_destroy(mem_ctx
);
5926 /* query info level 5 to obtain sid of a domain being queried */
5927 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5929 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5932 if (NT_STATUS_IS_ERR(nt_status
)) {
5933 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5934 nt_errstr(nt_status
)));
5936 talloc_destroy(mem_ctx
);
5940 queried_dom_sid
= info
->account_domain
.sid
;
5943 * Keep calling LsaEnumTrustdom over opened pipe until
5944 * the end of enumeration is reached
5947 d_printf(_("Vampire trusted domains:\n\n"));
5950 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
5955 if (NT_STATUS_IS_ERR(nt_status
)) {
5956 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5957 nt_errstr(nt_status
)));
5959 talloc_destroy(mem_ctx
);
5963 for (i
= 0; i
< dom_list
.count
; i
++) {
5965 print_trusted_domain(dom_list
.domains
[i
].sid
,
5966 dom_list
.domains
[i
].name
.string
);
5968 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5969 *dom_list
.domains
[i
].sid
,
5970 dom_list
.domains
[i
].name
.string
);
5971 if (!NT_STATUS_IS_OK(nt_status
)) {
5973 talloc_destroy(mem_ctx
);
5979 * in case of no trusted domains say something rather
5980 * than just display blank line
5982 if (!dom_list
.count
) d_printf(_("none\n"));
5984 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5986 /* close this connection before doing next one */
5987 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5988 if (NT_STATUS_IS_ERR(nt_status
)) {
5989 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5990 nt_errstr(nt_status
)));
5992 talloc_destroy(mem_ctx
);
5996 /* close lsarpc pipe and connection to IPC$ */
5999 talloc_destroy(mem_ctx
);
6003 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6005 /* common variables */
6006 TALLOC_CTX
* mem_ctx
;
6007 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6008 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6010 const char *domain_name
= NULL
;
6011 DOM_SID
*queried_dom_sid
;
6012 int ascii_dom_name_len
;
6013 struct policy_handle connect_hnd
;
6014 union lsa_PolicyInformation
*info
= NULL
;
6016 /* trusted domains listing variables */
6017 unsigned int num_domains
, enum_ctx
= 0;
6019 struct lsa_DomainList dom_list
;
6022 /* trusting domains listing variables */
6023 struct policy_handle domain_hnd
;
6024 struct samr_SamArray
*trusts
= NULL
;
6026 if (c
->display_usage
) {
6027 d_printf(_("Usage:\n"
6028 "net rpc trustdom list\n"
6029 " List in- and outgoing trust relationships\n"));
6034 * Listing trusted domains (stored in secrets.tdb, if local)
6037 mem_ctx
= talloc_init("trust relationships listing");
6040 * set domain and pdc name to local samba server (default)
6041 * or to remote one given in command line
6044 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6045 domain_name
= c
->opt_workgroup
;
6046 c
->opt_target_workgroup
= c
->opt_workgroup
;
6048 fstrcpy(pdc_name
, global_myname());
6049 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6050 c
->opt_target_workgroup
= domain_name
;
6053 /* open \PIPE\lsarpc and open policy handle */
6054 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6055 if (!NT_STATUS_IS_OK(nt_status
)) {
6056 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6057 nt_errstr(nt_status
)));
6058 talloc_destroy(mem_ctx
);
6062 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6064 if (!NT_STATUS_IS_OK(nt_status
)) {
6065 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6066 nt_errstr(nt_status
) ));
6068 talloc_destroy(mem_ctx
);
6072 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6074 if (NT_STATUS_IS_ERR(nt_status
)) {
6075 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6076 nt_errstr(nt_status
)));
6078 talloc_destroy(mem_ctx
);
6082 /* query info level 5 to obtain sid of a domain being queried */
6083 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6085 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6088 if (NT_STATUS_IS_ERR(nt_status
)) {
6089 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6090 nt_errstr(nt_status
)));
6092 talloc_destroy(mem_ctx
);
6096 queried_dom_sid
= info
->account_domain
.sid
;
6099 * Keep calling LsaEnumTrustdom over opened pipe until
6100 * the end of enumeration is reached
6103 d_printf(_("Trusted domains list:\n\n"));
6106 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6111 if (NT_STATUS_IS_ERR(nt_status
)) {
6112 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6113 nt_errstr(nt_status
)));
6115 talloc_destroy(mem_ctx
);
6119 for (i
= 0; i
< dom_list
.count
; i
++) {
6120 print_trusted_domain(dom_list
.domains
[i
].sid
,
6121 dom_list
.domains
[i
].name
.string
);
6125 * in case of no trusted domains say something rather
6126 * than just display blank line
6128 if (!dom_list
.count
) d_printf(_("none\n"));
6130 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6132 /* close this connection before doing next one */
6133 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6134 if (NT_STATUS_IS_ERR(nt_status
)) {
6135 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6136 nt_errstr(nt_status
)));
6138 talloc_destroy(mem_ctx
);
6142 TALLOC_FREE(pipe_hnd
);
6145 * Listing trusting domains (stored in passdb backend, if local)
6148 d_printf(_("\nTrusting domains list:\n\n"));
6151 * Open \PIPE\samr and get needed policy handles
6153 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6155 if (!NT_STATUS_IS_OK(nt_status
)) {
6156 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6158 talloc_destroy(mem_ctx
);
6163 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6165 SAMR_ACCESS_LOOKUP_DOMAIN
,
6167 if (!NT_STATUS_IS_OK(nt_status
)) {
6168 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6169 nt_errstr(nt_status
)));
6171 talloc_destroy(mem_ctx
);
6175 /* SamrOpenDomain - we have to open domain policy handle in order to be
6176 able to enumerate accounts*/
6177 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6179 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6182 if (!NT_STATUS_IS_OK(nt_status
)) {
6183 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6184 nt_errstr(nt_status
)));
6186 talloc_destroy(mem_ctx
);
6191 * perform actual enumeration
6194 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6197 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6204 if (NT_STATUS_IS_ERR(nt_status
)) {
6205 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6206 nt_errstr(nt_status
)));
6208 talloc_destroy(mem_ctx
);
6212 for (i
= 0; i
< num_domains
; i
++) {
6214 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6217 * get each single domain's sid (do we _really_ need this ?):
6218 * 1) connect to domain's pdc
6219 * 2) query the pdc for domain's sid
6222 /* get rid of '$' tail */
6223 ascii_dom_name_len
= strlen(str
);
6224 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6225 str
[ascii_dom_name_len
- 1] = '\0';
6227 /* set opt_* variables to remote domain */
6229 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6230 c
->opt_target_workgroup
= c
->opt_workgroup
;
6232 d_printf("%-20s", str
);
6234 /* connect to remote domain controller */
6235 nt_status
= net_make_ipc_connection(c
,
6236 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6238 if (NT_STATUS_IS_OK(nt_status
)) {
6239 /* query for domain's sid */
6240 if (run_rpc_command(
6242 &ndr_table_lsarpc
.syntax_id
, 0,
6243 rpc_query_domain_sid
, argc
,
6245 d_printf(_("strange - couldn't get domain's sid\n"));
6247 cli_shutdown(remote_cli
);
6250 d_fprintf(stderr
, _("domain controller is not "
6251 "responding: %s\n"),
6252 nt_errstr(nt_status
));
6253 d_printf(_("couldn't get domain's sid\n"));
6257 if (!num_domains
) d_printf("none\n");
6259 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6261 /* close opened samr and domain policy handles */
6262 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6263 if (!NT_STATUS_IS_OK(nt_status
)) {
6264 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6267 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6268 if (!NT_STATUS_IS_OK(nt_status
)) {
6269 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6272 /* close samr pipe and connection to IPC$ */
6275 talloc_destroy(mem_ctx
);
6280 * Entrypoint for 'net rpc trustdom' code.
6282 * @param argc Standard argc.
6283 * @param argv Standard argv without initial components.
6285 * @return Integer status (0 means success).
6288 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6290 struct functable func
[] = {
6295 N_("Add trusting domain's account"),
6296 N_("net rpc trustdom add\n"
6297 " Add trusting domain's account")
6303 N_("Remove trusting domain's account"),
6304 N_("net rpc trustdom del\n"
6305 " Remove trusting domain's account")
6309 rpc_trustdom_establish
,
6311 N_("Establish outgoing trust relationship"),
6312 N_("net rpc trustdom establish\n"
6313 " Establish outgoing trust relationship")
6317 rpc_trustdom_revoke
,
6319 N_("Revoke outgoing trust relationship"),
6320 N_("net rpc trustdom revoke\n"
6321 " Revoke outgoing trust relationship")
6327 N_("List in- and outgoing domain trusts"),
6328 N_("net rpc trustdom list\n"
6329 " List in- and outgoing domain trusts")
6333 rpc_trustdom_vampire
,
6335 N_("Vampire trusts from remote server"),
6336 N_("net rpc trustdom vampire\n"
6337 " Vampire trusts from remote server")
6339 {NULL
, NULL
, 0, NULL
, NULL
}
6342 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6346 * Check if a server will take rpc commands
6347 * @param flags Type of server to connect to (PDC, DMB, localhost)
6348 * if the host is not explicitly specified
6349 * @return bool (true means rpc supported)
6351 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6353 struct cli_state
*cli
;
6355 struct sockaddr_storage server_ss
;
6356 char *server_name
= NULL
;
6359 /* flags (i.e. server type) may depend on command */
6360 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6363 if ((cli
= cli_initialise()) == NULL
) {
6367 status
= cli_connect(cli
, server_name
, &server_ss
);
6368 if (!NT_STATUS_IS_OK(status
))
6370 if (!attempt_netbios_session_request(&cli
, global_myname(),
6371 server_name
, &server_ss
))
6373 status
= cli_negprot(cli
);
6374 if (!NT_STATUS_IS_OK(status
))
6376 if (cli
->protocol
< PROTOCOL_NT1
)
6385 /* dump sam database via samsync rpc calls */
6386 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6387 if (c
->display_usage
) {
6388 d_printf(_("Usage:\n"
6390 " Dump remote SAM database\n"));
6394 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6395 NET_FLAGS_ANONYMOUS
,
6396 rpc_samdump_internals
, argc
, argv
);
6399 /* syncronise sam database via samsync rpc calls */
6400 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6402 struct functable func
[] = {
6407 N_("Dump remote SAM database to ldif"),
6408 N_("net rpc vampire ldif\n"
6409 " Dump remote SAM database to LDIF file or "
6416 N_("Dump remote SAM database to Kerberos Keytab"),
6417 N_("net rpc vampire keytab\n"
6418 " Dump remote SAM database to Kerberos keytab "
6425 N_("Dump remote SAM database to passdb"),
6426 N_("net rpc vampire passdb\n"
6427 " Dump remote SAM database to passdb")
6430 {NULL
, NULL
, 0, NULL
, NULL
}
6434 if (c
->display_usage
) {
6435 d_printf(_("Usage:\n"
6437 " Vampire remote SAM database\n"));
6441 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6442 NET_FLAGS_ANONYMOUS
,
6443 rpc_vampire_internals
,
6447 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6451 * Migrate everything from a print server.
6453 * @param c A net_context structure.
6454 * @param argc Standard main() style argc.
6455 * @param argv Standard main() style argv. Initial components are already
6458 * @return A shell status integer (0 for success).
6460 * The order is important !
6461 * To successfully add drivers the print queues have to exist !
6462 * Applying ACLs should be the last step, because you're easily locked out.
6465 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6470 if (c
->display_usage
) {
6471 d_printf(_("Usage:\n"
6472 "net rpc printer migrate all\n"
6473 " Migrate everything from a print server\n"));
6478 d_printf(_("no server to migrate\n"));
6482 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6483 rpc_printer_migrate_printers_internals
, argc
,
6488 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6489 rpc_printer_migrate_drivers_internals
, argc
,
6494 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6495 rpc_printer_migrate_forms_internals
, argc
, argv
);
6499 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6500 rpc_printer_migrate_settings_internals
, argc
,
6505 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6506 rpc_printer_migrate_security_internals
, argc
,
6512 * Migrate print drivers from a print server.
6514 * @param c A net_context structure.
6515 * @param argc Standard main() style argc.
6516 * @param argv Standard main() style argv. Initial components are already
6519 * @return A shell status integer (0 for success).
6521 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6524 if (c
->display_usage
) {
6525 d_printf(_("Usage:\n"
6526 "net rpc printer migrate drivers\n"
6527 " Migrate print-drivers from a print-server\n"));
6532 d_printf(_("no server to migrate\n"));
6536 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6537 rpc_printer_migrate_drivers_internals
,
6542 * Migrate print-forms from a print-server.
6544 * @param c A net_context structure.
6545 * @param argc Standard main() style argc.
6546 * @param argv Standard main() style argv. Initial components are already
6549 * @return A shell status integer (0 for success).
6551 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6554 if (c
->display_usage
) {
6555 d_printf(_("Usage:\n"
6556 "net rpc printer migrate forms\n"
6557 " Migrate print-forms from a print-server\n"));
6562 d_printf(_("no server to migrate\n"));
6566 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6567 rpc_printer_migrate_forms_internals
,
6572 * Migrate printers from a print-server.
6574 * @param c A net_context structure.
6575 * @param argc Standard main() style argc.
6576 * @param argv Standard main() style argv. Initial components are already
6579 * @return A shell status integer (0 for success).
6581 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6584 if (c
->display_usage
) {
6585 d_printf(_("Usage:\n"
6586 "net rpc printer migrate printers\n"
6587 " Migrate printers from a print-server\n"));
6592 d_printf(_("no server to migrate\n"));
6596 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6597 rpc_printer_migrate_printers_internals
,
6602 * Migrate printer-ACLs from a print-server
6604 * @param c A net_context structure.
6605 * @param argc Standard main() style argc.
6606 * @param argv Standard main() style argv. Initial components are already
6609 * @return A shell status integer (0 for success).
6611 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6614 if (c
->display_usage
) {
6615 d_printf(_("Usage:\n"
6616 "net rpc printer migrate security\n"
6617 " Migrate printer-ACLs from a print-server\n"));
6622 d_printf(_("no server to migrate\n"));
6626 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6627 rpc_printer_migrate_security_internals
,
6632 * Migrate printer-settings from a print-server.
6634 * @param c A net_context structure.
6635 * @param argc Standard main() style argc.
6636 * @param argv Standard main() style argv. Initial components are already
6639 * @return A shell status integer (0 for success).
6641 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6644 if (c
->display_usage
) {
6645 d_printf(_("Usage:\n"
6646 "net rpc printer migrate settings\n"
6647 " Migrate printer-settings from a "
6653 d_printf(_("no server to migrate\n"));
6657 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6658 rpc_printer_migrate_settings_internals
,
6663 * 'net rpc printer' entrypoint.
6665 * @param c A net_context structure.
6666 * @param argc Standard main() style argc.
6667 * @param argv Standard main() style argv. Initial components are already
6671 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6674 /* ouch: when addriver and setdriver are called from within
6675 rpc_printer_migrate_drivers_internals, the printer-queue already
6678 struct functable func
[] = {
6681 rpc_printer_migrate_all
,
6683 N_("Migrate all from remote to local print server"),
6684 N_("net rpc printer migrate all\n"
6685 " Migrate all from remote to local print server")
6689 rpc_printer_migrate_drivers
,
6691 N_("Migrate drivers to local server"),
6692 N_("net rpc printer migrate drivers\n"
6693 " Migrate drivers to local server")
6697 rpc_printer_migrate_forms
,
6699 N_("Migrate froms to local server"),
6700 N_("net rpc printer migrate forms\n"
6701 " Migrate froms to local server")
6705 rpc_printer_migrate_printers
,
6707 N_("Migrate printers to local server"),
6708 N_("net rpc printer migrate printers\n"
6709 " Migrate printers to local server")
6713 rpc_printer_migrate_security
,
6715 N_("Mirgate printer ACLs to local server"),
6716 N_("net rpc printer migrate security\n"
6717 " Mirgate printer ACLs to local server")
6721 rpc_printer_migrate_settings
,
6723 N_("Migrate printer settings to local server"),
6724 N_("net rpc printer migrate settings\n"
6725 " Migrate printer settings to local server")
6727 {NULL
, NULL
, 0, NULL
, NULL
}
6730 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6735 * List printers on a remote RPC server.
6737 * @param c A net_context structure.
6738 * @param argc Standard main() style argc.
6739 * @param argv Standard main() style argv. Initial components are already
6742 * @return A shell status integer (0 for success).
6744 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6746 if (c
->display_usage
) {
6747 d_printf(_("Usage:\n"
6748 "net rpc printer list\n"
6749 " List printers on a remote RPC server\n"));
6753 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6754 rpc_printer_list_internals
,
6759 * List printer-drivers on a remote RPC server.
6761 * @param c A net_context structure.
6762 * @param argc Standard main() style argc.
6763 * @param argv Standard main() style argv. Initial components are already
6766 * @return A shell status integer (0 for success).
6768 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6771 if (c
->display_usage
) {
6772 d_printf(_("Usage:\n"
6773 "net rpc printer driver\n"
6774 " List printer-drivers on a remote RPC server\n"));
6778 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6779 rpc_printer_driver_list_internals
,
6784 * Publish printer in ADS via MSRPC.
6786 * @param c A net_context structure.
6787 * @param argc Standard main() style argc.
6788 * @param argv Standard main() style argv. Initial components are already
6791 * @return A shell status integer (0 for success).
6793 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6796 if (c
->display_usage
) {
6797 d_printf(_("Usage:\n"
6798 "net rpc printer publish publish\n"
6799 " Publish printer in ADS via MSRPC\n"));
6803 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6804 rpc_printer_publish_publish_internals
,
6809 * Update printer in ADS via MSRPC.
6811 * @param c A net_context structure.
6812 * @param argc Standard main() style argc.
6813 * @param argv Standard main() style argv. Initial components are already
6816 * @return A shell status integer (0 for success).
6818 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6820 if (c
->display_usage
) {
6821 d_printf(_("Usage:\n"
6822 "net rpc printer publish update\n"
6823 " Update printer in ADS via MSRPC\n"));
6827 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6828 rpc_printer_publish_update_internals
,
6833 * UnPublish printer in ADS via MSRPC.
6835 * @param c A net_context structure.
6836 * @param argc Standard main() style argc.
6837 * @param argv Standard main() style argv. Initial components are already
6840 * @return A shell status integer (0 for success).
6842 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6845 if (c
->display_usage
) {
6846 d_printf(_("Usage:\n"
6847 "net rpc printer publish unpublish\n"
6848 " UnPublish printer in ADS via MSRPC\n"));
6852 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6853 rpc_printer_publish_unpublish_internals
,
6858 * List published printers via MSRPC.
6860 * @param c A net_context structure.
6861 * @param argc Standard main() style argc.
6862 * @param argv Standard main() style argv. Initial components are already
6865 * @return A shell status integer (0 for success).
6867 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6870 if (c
->display_usage
) {
6871 d_printf(_("Usage:\n"
6872 "net rpc printer publish list\n"
6873 " List published printers via MSRPC\n"));
6877 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6878 rpc_printer_publish_list_internals
,
6884 * Publish printer in ADS.
6886 * @param c A net_context structure.
6887 * @param argc Standard main() style argc.
6888 * @param argv Standard main() style argv. Initial components are already
6891 * @return A shell status integer (0 for success).
6893 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6897 struct functable func
[] = {
6900 rpc_printer_publish_publish
,
6902 N_("Publish printer in AD"),
6903 N_("net rpc printer publish publish\n"
6904 " Publish printer in AD")
6908 rpc_printer_publish_update
,
6910 N_("Update printer in AD"),
6911 N_("net rpc printer publish update\n"
6912 " Update printer in AD")
6916 rpc_printer_publish_unpublish
,
6918 N_("Unpublish printer"),
6919 N_("net rpc printer publish unpublish\n"
6920 " Unpublish printer")
6924 rpc_printer_publish_list
,
6926 N_("List published printers"),
6927 N_("net rpc printer publish list\n"
6928 " List published printers")
6930 {NULL
, NULL
, 0, NULL
, NULL
}
6934 if (c
->display_usage
) {
6935 d_printf(_("Usage:\n"));
6936 d_printf(_("net rpc printer publish\n"
6937 " List published printers\n"
6938 " Alias of net rpc printer publish "
6940 net_display_usage_from_functable(func
);
6943 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6944 rpc_printer_publish_list_internals
,
6948 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
6954 * Display rpc printer help page.
6956 * @param c A net_context structure.
6957 * @param argc Standard main() style argc.
6958 * @param argv Standard main() style argv. Initial components are already
6961 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
6963 d_printf(_("net rpc printer LIST [printer] [misc. options] [targets]\n"
6964 "\tlists all printers on print-server\n\n"));
6965 d_printf(_("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
6966 "\tlists all printer-drivers on print-server\n\n"));
6967 d_printf(_("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
6968 "\tpublishes printer settings in Active Directory\n"
6969 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n"));
6970 d_printf(_("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
6971 "\n\tmigrates printers from remote to local server\n\n"));
6972 d_printf(_("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
6973 "\n\tmigrates printer-settings from remote to local server\n\n"));
6974 d_printf(_("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
6975 "\n\tmigrates printer-drivers from remote to local server\n\n"));
6976 d_printf(_("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
6977 "\n\tmigrates printer-forms from remote to local server\n\n"));
6978 d_printf(_("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
6979 "\n\tmigrates printer-ACLs from remote to local server\n\n"));
6980 d_printf(_("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
6981 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
6982 "\tremote to local print-server\n\n"));
6983 net_common_methods_usage(c
, argc
, argv
);
6984 net_common_flags_usage(c
, argc
, argv
);
6986 "\t-v or --verbose\t\t\tgive verbose output\n"
6987 "\t --destination\t\tmigration target server (default: localhost)\n"));
6993 * 'net rpc printer' entrypoint.
6995 * @param c A net_context structure.
6996 * @param argc Standard main() style argc.
6997 * @param argv Standard main() style argv. Initial components are already
7000 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
7002 struct functable func
[] = {
7007 N_("List all printers on print server"),
7008 N_("net rpc printer list\n"
7009 " List all printers on print server")
7013 rpc_printer_migrate
,
7015 N_("Migrate printer to local server"),
7016 N_("net rpc printer migrate\n"
7017 " Migrate printer to local server")
7021 rpc_printer_driver_list
,
7023 N_("List printer drivers"),
7024 N_("net rpc printer driver\n"
7025 " List printer drivers")
7029 rpc_printer_publish
,
7031 N_("Publish printer in AD"),
7032 N_("net rpc printer publish\n"
7033 " Publish printer in AD")
7035 {NULL
, NULL
, 0, NULL
, NULL
}
7039 if (c
->display_usage
) {
7040 d_printf(_("Usage:\n"));
7041 d_printf(_("net rpc printer\n"
7042 " List printers\n"));
7043 net_display_usage_from_functable(func
);
7046 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7047 rpc_printer_list_internals
,
7051 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7055 * 'net rpc' entrypoint.
7057 * @param c A net_context structure.
7058 * @param argc Standard main() style argc.
7059 * @param argv Standard main() style argv. Initial components are already
7063 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7065 NET_API_STATUS status
;
7067 struct functable func
[] = {
7072 N_("Modify global audit settings"),
7073 N_("net rpc audit\n"
7074 " Modify global audit settings")
7080 N_("Show basic info about a domain"),
7082 " Show basic info about a domain")
7088 N_("Join a domain"),
7096 N_("Join a domain created in server manager"),
7097 N_("net rpc oldjoin\n"
7098 " Join a domain created in server manager")
7104 N_("Test that a join is valid"),
7105 N_("net rpc testjoin\n"
7106 " Test that a join is valid")
7112 N_("List/modify users"),
7114 " List/modify users")
7120 N_("Change a user password"),
7121 N_("net rpc password\n"
7122 " Change a user password\n"
7123 " Alias for net rpc user password")
7129 N_("List/modify groups"),
7130 N_("net rpc group\n"
7131 " List/modify groups")
7137 N_("List/modify shares"),
7138 N_("net rpc share\n"
7139 " List/modify shares")
7145 N_("List open files"),
7153 N_("List/modify printers"),
7154 N_("net rpc printer\n"
7155 " List/modify printers")
7159 net_rpc_changetrustpw
,
7161 N_("Change trust account password"),
7162 N_("net rpc changetrustpw\n"
7163 " Change trust account password")
7169 N_("Modify domain trusts"),
7170 N_("net rpc trustdom\n"
7171 " Modify domain trusts")
7177 N_("Abort a remote shutdown"),
7178 N_("net rpc abortshutdown\n"
7179 " Abort a remote shutdown")
7185 N_("Shutdown a remote server"),
7186 N_("net rpc shutdown\n"
7187 " Shutdown a remote server")
7193 N_("Dump SAM data of remote NT PDC"),
7194 N_("net rpc samdump\n"
7195 " Dump SAM data of remote NT PDC")
7201 N_("Sync a remote NT PDC's data into local passdb"),
7202 N_("net rpc vampire\n"
7203 " Sync a remote NT PDC's data into local passdb")
7209 N_("Fetch the domain sid into local secrets.tdb"),
7210 N_("net rpc getsid\n"
7211 " Fetch the domain sid into local secrets.tdb")
7217 N_("Manage privileges assigned to SID"),
7218 N_("net rpc rights\n"
7219 " Manage privileges assigned to SID")
7225 N_("Start/stop/query remote services"),
7226 N_("net rpc service\n"
7227 " Start/stop/query remote services")
7233 N_("Manage registry hives"),
7234 N_("net rpc registry\n"
7235 " Manage registry hives")
7241 N_("Open interactive shell on remote server"),
7242 N_("net rpc shell\n"
7243 " Open interactive shell on remote server")
7245 {NULL
, NULL
, 0, NULL
, NULL
}
7248 status
= libnetapi_init(&c
->netapi_ctx
);
7252 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7253 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7254 if (c
->opt_kerberos
) {
7255 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7258 return net_run_function(c
, argc
, argv
, "net rpc", func
);