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"
26 static int net_mode_share
;
27 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
32 * @brief RPC based subcommands for the 'net' utility.
34 * This file should contain much of the functionality that used to
35 * be found in rpcclient, execpt that the commands should change
36 * less often, and the fucntionality should be sane (the user is not
37 * expected to know a rid/sid before they conduct an operation etc.)
39 * @todo Perhaps eventually these should be split out into a number
40 * of files, as this could get quite big.
45 * Many of the RPC functions need the domain sid. This function gets
46 * it at the start of every run
48 * @param cli A cli_state already connected to the remote machine
50 * @return The Domain SID of the remote machine.
53 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
55 const char **domain_name
)
57 struct rpc_pipe_client
*lsa_pipe
;
59 NTSTATUS result
= NT_STATUS_OK
;
60 union lsa_PolicyInformation
*info
= NULL
;
62 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
64 if (!NT_STATUS_IS_OK(result
)) {
65 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
69 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
70 SEC_RIGHTS_MAXIMUM_ALLOWED
,
72 if (!NT_STATUS_IS_OK(result
)) {
73 d_fprintf(stderr
, "open_policy failed: %s\n",
78 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
80 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
82 if (!NT_STATUS_IS_OK(result
)) {
83 d_fprintf(stderr
, "lsaquery failed: %s\n",
88 *domain_name
= info
->account_domain
.name
.string
;
89 *domain_sid
= info
->account_domain
.sid
;
91 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
92 TALLOC_FREE(lsa_pipe
);
98 * Run a single RPC command, from start to finish.
100 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
101 * @param conn_flag a NET_FLAG_ combination. Passed to
102 * net_make_ipc_connection.
103 * @param argc Standard main() style argc.
104 * @param argv Standard main() style argv. Initial components are already
106 * @return A shell status integer (0 for success).
109 int run_rpc_command(struct net_context
*c
,
110 struct cli_state
*cli_arg
,
111 const struct ndr_syntax_id
*interface
,
117 struct cli_state
*cli
= NULL
;
118 struct rpc_pipe_client
*pipe_hnd
= NULL
;
122 const char *domain_name
;
125 /* make use of cli_state handed over as an argument, if possible */
127 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
128 if (!NT_STATUS_IS_OK(nt_status
)) {
129 DEBUG(1, ("failed to make ipc connection: %s\n",
130 nt_errstr(nt_status
)));
143 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
144 DEBUG(0, ("talloc_init() failed\n"));
148 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
150 if (!NT_STATUS_IS_OK(nt_status
)) {
154 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
155 if (lp_client_schannel()
156 && (ndr_syntax_id_equal(interface
,
157 &ndr_table_netlogon
.syntax_id
))) {
158 /* Always try and create an schannel netlogon pipe. */
159 nt_status
= cli_rpc_pipe_open_schannel(
160 cli
, interface
, NCACN_NP
,
161 PIPE_AUTH_LEVEL_PRIVACY
, domain_name
,
163 if (!NT_STATUS_IS_OK(nt_status
)) {
164 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
165 nt_errstr(nt_status
) ));
169 if (conn_flags
& NET_FLAGS_SEAL
) {
170 nt_status
= cli_rpc_pipe_open_ntlmssp(
172 (conn_flags
& NET_FLAGS_TCP
) ?
173 NCACN_IP_TCP
: NCACN_NP
,
174 PIPE_AUTH_LEVEL_PRIVACY
,
175 lp_workgroup(), c
->opt_user_name
,
176 c
->opt_password
, &pipe_hnd
);
178 nt_status
= cli_rpc_pipe_open_noauth(
182 if (!NT_STATUS_IS_OK(nt_status
)) {
183 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
184 cli_get_pipe_name_from_iface(
185 debug_ctx(), cli
, interface
),
186 nt_errstr(nt_status
) ));
192 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
194 if (!NT_STATUS_IS_OK(nt_status
)) {
195 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
198 DEBUG(5, ("rpc command function succedded\n"));
201 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
203 TALLOC_FREE(pipe_hnd
);
208 /* close the connection only if it was opened here */
213 talloc_destroy(mem_ctx
);
218 * Force a change of the trust acccount password.
220 * All parameters are provided by the run_rpc_command function, except for
221 * argc, argv which are passed through.
223 * @param domain_sid The domain sid acquired from the remote server.
224 * @param cli A cli_state connected to the server.
225 * @param mem_ctx Talloc context, destroyed on completion of the function.
226 * @param argc Standard main() style argc.
227 * @param argv Standard main() style argv. Initial components are already
230 * @return Normal NTSTATUS return.
233 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
234 const DOM_SID
*domain_sid
,
235 const char *domain_name
,
236 struct cli_state
*cli
,
237 struct rpc_pipe_client
*pipe_hnd
,
243 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
247 * Force a change of the trust acccount password.
249 * @param argc Standard main() style argc.
250 * @param argv Standard main() style argv. Initial components are already
253 * @return A shell status integer (0 for success).
256 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
258 if (c
->display_usage
) {
260 "net rpc changetrustpw\n"
261 " Change the machine trust password\n");
265 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
266 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
267 rpc_changetrustpw_internals
,
272 * Join a domain, the old way.
274 * This uses 'machinename' as the inital password, and changes it.
276 * The password should be created with 'server manager' or equiv first.
278 * All parameters are provided by the run_rpc_command function, except for
279 * argc, argv which are passed through.
281 * @param domain_sid The domain sid acquired from the remote server.
282 * @param cli A cli_state connected to the server.
283 * @param mem_ctx Talloc context, destroyed on completion of the function.
284 * @param argc Standard main() style argc.
285 * @param argv Standard main() style argv. Initial components are already
288 * @return Normal NTSTATUS return.
291 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
292 const DOM_SID
*domain_sid
,
293 const char *domain_name
,
294 struct cli_state
*cli
,
295 struct rpc_pipe_client
*pipe_hnd
,
301 fstring trust_passwd
;
302 unsigned char orig_trust_passwd_hash
[16];
304 uint32 sec_channel_type
;
306 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
308 if (!NT_STATUS_IS_OK(result
)) {
309 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
312 nt_errstr(result
) ));
317 check what type of join - if the user want's to join as
318 a BDC, the server must agree that we are a BDC.
321 sec_channel_type
= get_sec_channel_type(argv
[0]);
323 sec_channel_type
= get_sec_channel_type(NULL
);
326 fstrcpy(trust_passwd
, global_myname());
327 strlower_m(trust_passwd
);
330 * Machine names can be 15 characters, but the max length on
331 * a password is 14. --jerry
334 trust_passwd
[14] = '\0';
336 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
338 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
339 orig_trust_passwd_hash
,
342 if (NT_STATUS_IS_OK(result
))
343 printf("Joined domain %s.\n", c
->opt_target_workgroup
);
346 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
347 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
348 result
= NT_STATUS_UNSUCCESSFUL
;
355 * Join a domain, the old way.
357 * @param argc Standard main() style argc.
358 * @param argv Standard main() style argv. Initial components are already
361 * @return A shell status integer (0 for success).
364 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
366 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
367 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
368 rpc_oldjoin_internals
,
373 * Join a domain, the old way. This function exists to allow
374 * the message to be displayed when oldjoin was explicitly
375 * requested, but not when it was implied by "net rpc join".
377 * @param argc Standard main() style argc.
378 * @param argv Standard main() style argv. Initial components are already
381 * @return A shell status integer (0 for success).
384 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
388 if (c
->display_usage
) {
391 " Join a domain the old way\n");
395 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
398 d_fprintf(stderr
, "Failed to join domain\n");
405 * 'net rpc join' entrypoint.
406 * @param argc Standard main() style argc.
407 * @param argv Standard main() style argv. Initial components are already
410 * Main 'net_rpc_join()' (where the admin username/password is used) is
412 * Try to just change the password, but if that doesn't work, use/prompt
413 * for a username/password.
416 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
418 if (c
->display_usage
) {
420 "net rpc join -U <username>[%%password] <type>\n"
422 " username\tName of the admin user"
423 " password\tPassword of the admin user, will "
424 "prompt if not specified\n"
425 " type\tCan be one of the following:\n"
426 "\t\tMEMBER\tJoin as member server (default)\n"
427 "\t\tBDC\tJoin as BDC\n"
428 "\t\tPDC\tJoin as PDC\n");
432 if (lp_server_role() == ROLE_STANDALONE
) {
433 d_printf("cannot join as standalone machine\n");
437 if (strlen(global_myname()) > 15) {
438 d_printf("Our netbios name can be at most 15 chars long, "
439 "\"%s\" is %u chars long\n",
440 global_myname(), (unsigned int)strlen(global_myname()));
444 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
447 return net_rpc_join_newstyle(c
, argc
, argv
);
451 * display info about a rpc domain
453 * All parameters are provided by the run_rpc_command function, except for
454 * argc, argv which are passed through.
456 * @param domain_sid The domain sid acquired from the remote server
457 * @param cli A cli_state connected to the server.
458 * @param mem_ctx Talloc context, destroyed on completion of the function.
459 * @param argc Standard main() style argc.
460 * @param argv Standard main() style argv. Initial components are already
463 * @return Normal NTSTATUS return.
466 NTSTATUS
rpc_info_internals(struct net_context
*c
,
467 const DOM_SID
*domain_sid
,
468 const char *domain_name
,
469 struct cli_state
*cli
,
470 struct rpc_pipe_client
*pipe_hnd
,
475 POLICY_HND connect_pol
, domain_pol
;
476 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
477 union samr_DomainInfo
*info
= NULL
;
480 sid_to_fstring(sid_str
, domain_sid
);
482 /* Get sam policy handle */
483 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
485 MAXIMUM_ALLOWED_ACCESS
,
487 if (!NT_STATUS_IS_OK(result
)) {
488 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
492 /* Get domain policy handle */
493 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
495 MAXIMUM_ALLOWED_ACCESS
,
496 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
498 if (!NT_STATUS_IS_OK(result
)) {
499 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
503 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
507 if (NT_STATUS_IS_OK(result
)) {
508 d_printf("Domain Name: %s\n", info
->info2
.domain_name
.string
);
509 d_printf("Domain SID: %s\n", sid_str
);
510 d_printf("Sequence number: %llu\n",
511 (unsigned long long)info
->info2
.sequence_num
);
512 d_printf("Num users: %u\n", info
->info2
.num_users
);
513 d_printf("Num domain groups: %u\n", info
->info2
.num_groups
);
514 d_printf("Num local groups: %u\n", info
->info2
.num_aliases
);
522 * 'net rpc info' entrypoint.
523 * @param argc Standard main() style argc.
524 * @param argv Standard main() style argv. Initial components are already
528 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
530 if (c
->display_usage
) {
533 " Display information about the domain\n");
537 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
538 NET_FLAGS_PDC
, rpc_info_internals
,
543 * Fetch domain SID into the local secrets.tdb.
545 * All parameters are provided by the run_rpc_command function, except for
546 * argc, argv which are passed through.
548 * @param domain_sid The domain sid acquired from the remote server.
549 * @param cli A cli_state connected to the server.
550 * @param mem_ctx Talloc context, destroyed on completion of the function.
551 * @param argc Standard main() style argc.
552 * @param argv Standard main() style argv. Initial components are already
555 * @return Normal NTSTATUS return.
558 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
559 const DOM_SID
*domain_sid
,
560 const char *domain_name
,
561 struct cli_state
*cli
,
562 struct rpc_pipe_client
*pipe_hnd
,
569 sid_to_fstring(sid_str
, domain_sid
);
570 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
571 sid_str
, domain_name
);
573 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
574 DEBUG(0,("Can't store domain SID\n"));
575 return NT_STATUS_UNSUCCESSFUL
;
582 * 'net rpc getsid' entrypoint.
583 * @param argc Standard main() style argc.
584 * @param argv Standard main() style argv. Initial components are already
588 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
590 int conn_flags
= NET_FLAGS_PDC
;
592 if (!c
->opt_user_specified
) {
593 conn_flags
|= NET_FLAGS_ANONYMOUS
;
596 if (c
->display_usage
) {
599 " Fetch domain SID into local secrets.tdb\n");
603 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
605 rpc_getsid_internals
,
609 /****************************************************************************/
612 * Basic usage function for 'net rpc user'.
613 * @param argc Standard main() style argc.
614 * @param argv Standard main() style argv. Initial components are already
618 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
620 return net_user_usage(c
, argc
, argv
);
624 * Add a new user to a remote RPC server.
626 * @param argc Standard main() style argc.
627 * @param argv Standard main() style argv. Initial components are already
630 * @return A shell status integer (0 for success).
633 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
635 NET_API_STATUS status
;
636 struct USER_INFO_1 info1
;
637 uint32_t parm_error
= 0;
639 if (argc
< 1 || c
->display_usage
) {
640 rpc_user_usage(c
, argc
, argv
);
646 info1
.usri1_name
= argv
[0];
648 info1
.usri1_password
= argv
[1];
651 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
654 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
655 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
659 d_printf("Added user '%s'.\n", argv
[0]);
666 * Rename a user on a remote RPC server.
668 * @param argc Standard main() style argc.
669 * @param argv Standard main() style argv. Initial components are already
672 * @return A shell status integer (0 for success).
675 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
677 NET_API_STATUS status
;
678 struct USER_INFO_0 u0
;
679 uint32_t parm_err
= 0;
681 if (argc
!= 2 || c
->display_usage
) {
682 rpc_user_usage(c
, argc
, argv
);
686 u0
.usri0_name
= argv
[1];
688 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
689 0, (uint8_t *)&u0
, &parm_err
);
691 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n",
693 libnetapi_get_error_string(c
->netapi_ctx
, status
));
695 d_printf("Renamed user from %s to %s\n", argv
[0], argv
[1]);
702 * Delete a user from a remote RPC server.
704 * @param argc Standard main() style argc.
705 * @param argv Standard main() style argv. Initial components are already
708 * @return A shell status integer (0 for success).
711 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
713 NET_API_STATUS status
;
715 if (argc
< 1 || c
->display_usage
) {
716 rpc_user_usage(c
, argc
, argv
);
720 status
= NetUserDel(c
->opt_host
, argv
[0]);
723 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
725 libnetapi_get_error_string(c
->netapi_ctx
, status
));
728 d_printf("Deleted user '%s'.\n", argv
[0]);
735 * Set a user's password on a remote RPC server.
737 * @param argc Standard main() style argc.
738 * @param argv Standard main() style argv. Initial components are already
741 * @return A shell status integer (0 for success).
744 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
746 NET_API_STATUS status
;
748 struct USER_INFO_1003 u1003
;
749 uint32_t parm_err
= 0;
751 if (argc
< 1 || c
->display_usage
) {
752 rpc_user_usage(c
, argc
, argv
);
757 u1003
.usri1003_password
= argv
[1];
759 if (asprintf(&prompt
, "Enter new password for %s:", argv
[0]) == -1) {
762 u1003
.usri1003_password
= getpass(prompt
);
766 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
768 /* Display results */
770 d_fprintf(stderr
, "Failed to set password for '%s' with: %s.\n",
771 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
780 * List a user's groups from a remote RPC server.
782 * @param argc Standard main() style argc.
783 * @param argv Standard main() style argv. Initial components are already
786 * @return A shell status integer (0 for success)
789 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
792 NET_API_STATUS status
;
793 struct GROUP_USERS_INFO_0
*u0
= NULL
;
794 uint32_t entries_read
= 0;
795 uint32_t total_entries
= 0;
799 if (argc
< 1 || c
->display_usage
) {
800 rpc_user_usage(c
, argc
, argv
);
804 status
= NetUserGetGroups(c
->opt_host
,
807 (uint8_t **)(void *)&u0
,
812 d_fprintf(stderr
, "Failed to get groups for '%s' with: %s.\n",
813 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
818 for (i
=0; i
< entries_read
; i
++) {
819 printf("%s\n", u0
->grui0_name
);
827 * List users on a remote RPC server.
829 * All parameters are provided by the run_rpc_command function, except for
830 * argc, argv which are passed through.
832 * @param domain_sid The domain sid acquired from the remote server.
833 * @param cli A cli_state connected to the server.
834 * @param mem_ctx Talloc context, destroyed on completion of the function.
835 * @param argc Standard main() style argc.
836 * @param argv Standard main() style argv. Initial components are already
839 * @return Normal NTSTATUS return.
842 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
844 NET_API_STATUS status
;
845 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
846 struct NET_DISPLAY_USER
*info
= NULL
;
849 /* Query domain users */
850 if (c
->opt_long_list_entries
)
851 d_printf("\nUser name Comment"
852 "\n-----------------------------\n");
854 uint32_t max_entries
, max_size
;
856 get_query_dispinfo_params(
857 loop_count
, &max_entries
, &max_size
);
859 status
= NetQueryDisplayInformation(c
->opt_host
,
866 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
870 info
= (struct NET_DISPLAY_USER
*)buffer
;
872 for (i
= 0; i
< num_entries
; i
++) {
874 if (c
->opt_long_list_entries
)
875 printf("%-21.21s %s\n", info
->usri1_name
,
876 info
->usri1_comment
);
878 printf("%s\n", info
->usri1_name
);
882 NetApiBufferFree(buffer
);
885 start_idx
+= num_entries
;
887 } while (status
== ERROR_MORE_DATA
);
893 * 'net rpc user' entrypoint.
894 * @param argc Standard main() style argc.
895 * @param argv Standard main() style argv. Initial components are already
899 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
901 NET_API_STATUS status
;
903 struct functable func
[] = {
908 "Add specified user",
910 " Add specified user"
916 "List domain groups of user",
917 "net rpc user info\n"
918 " Lis domain groups of user"
924 "Remove specified user",
925 "net rpc user delete\n"
926 " Remove specified user"
932 "Change user password",
933 "net rpc user password\n"
934 " Change user password"
940 "Rename specified user",
941 "net rpc user rename\n"
942 " Rename specified user"
944 {NULL
, NULL
, 0, NULL
, NULL
}
947 status
= libnetapi_init(&c
->netapi_ctx
);
951 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
952 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
953 if (c
->opt_kerberos
) {
954 libnetapi_set_use_kerberos(c
->netapi_ctx
);
958 if (c
->display_usage
) {
959 d_printf("Usage:\n");
960 d_printf("net rpc user\n"
961 " List all users\n");
962 net_display_usage_from_functable(func
);
966 return rpc_user_list(c
, argc
, argv
);
969 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
972 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
974 struct rpc_sh_ctx
*ctx
,
975 struct rpc_pipe_client
*pipe_hnd
,
976 int argc
, const char **argv
)
978 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
981 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
983 struct rpc_sh_ctx
*ctx
,
984 struct rpc_pipe_client
*pipe_hnd
,
985 int argc
, const char **argv
)
987 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
990 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
992 struct rpc_sh_ctx
*ctx
,
993 struct rpc_pipe_client
*pipe_hnd
,
994 int argc
, const char **argv
,
996 struct net_context
*c
,
998 struct rpc_sh_ctx
*ctx
,
999 struct rpc_pipe_client
*pipe_hnd
,
1000 POLICY_HND
*user_hnd
,
1001 int argc
, const char **argv
))
1003 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1004 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1007 enum lsa_SidType type
;
1010 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1011 return NT_STATUS_INVALID_PARAMETER
;
1014 ZERO_STRUCT(connect_pol
);
1015 ZERO_STRUCT(domain_pol
);
1016 ZERO_STRUCT(user_pol
);
1018 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1019 argv
[0], NULL
, NULL
, &sid
, &type
);
1020 if (!NT_STATUS_IS_OK(result
)) {
1021 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1026 if (type
!= SID_NAME_USER
) {
1027 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1028 sid_type_lookup(type
));
1029 result
= NT_STATUS_NO_SUCH_USER
;
1033 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1034 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1035 result
= NT_STATUS_NO_SUCH_USER
;
1039 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1041 MAXIMUM_ALLOWED_ACCESS
,
1043 if (!NT_STATUS_IS_OK(result
)) {
1047 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1049 MAXIMUM_ALLOWED_ACCESS
,
1052 if (!NT_STATUS_IS_OK(result
)) {
1056 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1058 MAXIMUM_ALLOWED_ACCESS
,
1061 if (!NT_STATUS_IS_OK(result
)) {
1065 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1068 if (is_valid_policy_hnd(&user_pol
)) {
1069 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1071 if (is_valid_policy_hnd(&domain_pol
)) {
1072 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1074 if (is_valid_policy_hnd(&connect_pol
)) {
1075 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1080 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1081 TALLOC_CTX
*mem_ctx
,
1082 struct rpc_sh_ctx
*ctx
,
1083 struct rpc_pipe_client
*pipe_hnd
,
1084 POLICY_HND
*user_hnd
,
1085 int argc
, const char **argv
)
1088 union samr_UserInfo
*info
= NULL
;
1091 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1092 return NT_STATUS_INVALID_PARAMETER
;
1095 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1099 if (!NT_STATUS_IS_OK(result
)) {
1103 d_printf("user rid: %d, group rid: %d\n",
1105 info
->info21
.primary_gid
);
1110 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1111 TALLOC_CTX
*mem_ctx
,
1112 struct rpc_sh_ctx
*ctx
,
1113 struct rpc_pipe_client
*pipe_hnd
,
1114 int argc
, const char **argv
)
1116 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1117 rpc_sh_user_show_internals
);
1120 #define FETCHSTR(name, rec) \
1121 do { if (strequal(ctx->thiscmd, name)) { \
1122 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1125 #define SETSTR(name, rec, flag) \
1126 do { if (strequal(ctx->thiscmd, name)) { \
1127 init_lsa_String(&(info->info21.rec), argv[0]); \
1128 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1131 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1132 TALLOC_CTX
*mem_ctx
,
1133 struct rpc_sh_ctx
*ctx
,
1134 struct rpc_pipe_client
*pipe_hnd
,
1135 POLICY_HND
*user_hnd
,
1136 int argc
, const char **argv
)
1139 const char *username
;
1140 const char *oldval
= "";
1141 union samr_UserInfo
*info
= NULL
;
1144 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1146 return NT_STATUS_INVALID_PARAMETER
;
1149 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1153 if (!NT_STATUS_IS_OK(result
)) {
1157 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1159 FETCHSTR("fullname", full_name
);
1160 FETCHSTR("homedir", home_directory
);
1161 FETCHSTR("homedrive", home_drive
);
1162 FETCHSTR("logonscript", logon_script
);
1163 FETCHSTR("profilepath", profile_path
);
1164 FETCHSTR("description", description
);
1167 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1171 if (strcmp(argv
[0], "NULL") == 0) {
1175 ZERO_STRUCT(info
->info21
);
1177 SETSTR("fullname", full_name
, FULL_NAME
);
1178 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1179 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1180 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1181 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1182 SETSTR("description", description
, DESCRIPTION
);
1184 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1189 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1190 ctx
->thiscmd
, oldval
, argv
[0]);
1197 #define HANDLEFLG(name, rec) \
1198 do { if (strequal(ctx->thiscmd, name)) { \
1199 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1201 newflags = oldflags | ACB_##rec; \
1203 newflags = oldflags & ~ACB_##rec; \
1206 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1207 TALLOC_CTX
*mem_ctx
,
1208 struct rpc_sh_ctx
*ctx
,
1209 struct rpc_pipe_client
*pipe_hnd
,
1210 int argc
, const char **argv
)
1212 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1213 rpc_sh_user_str_edit_internals
);
1216 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1217 TALLOC_CTX
*mem_ctx
,
1218 struct rpc_sh_ctx
*ctx
,
1219 struct rpc_pipe_client
*pipe_hnd
,
1220 POLICY_HND
*user_hnd
,
1221 int argc
, const char **argv
)
1224 const char *username
;
1225 const char *oldval
= "unknown";
1226 uint32 oldflags
, newflags
;
1228 union samr_UserInfo
*info
= NULL
;
1231 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1232 !strequal(argv
[0], "no"))) {
1233 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1235 return NT_STATUS_INVALID_PARAMETER
;
1238 newval
= strequal(argv
[0], "yes");
1240 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1244 if (!NT_STATUS_IS_OK(result
)) {
1248 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1249 oldflags
= info
->info21
.acct_flags
;
1250 newflags
= info
->info21
.acct_flags
;
1252 HANDLEFLG("disabled", DISABLED
);
1253 HANDLEFLG("pwnotreq", PWNOTREQ
);
1254 HANDLEFLG("autolock", AUTOLOCK
);
1255 HANDLEFLG("pwnoexp", PWNOEXP
);
1258 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1262 ZERO_STRUCT(info
->info21
);
1264 info
->info21
.acct_flags
= newflags
;
1265 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1267 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1272 if (NT_STATUS_IS_OK(result
)) {
1273 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1274 ctx
->thiscmd
, oldval
, argv
[0]);
1282 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1283 TALLOC_CTX
*mem_ctx
,
1284 struct rpc_sh_ctx
*ctx
,
1285 struct rpc_pipe_client
*pipe_hnd
,
1286 int argc
, const char **argv
)
1288 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1289 rpc_sh_user_flag_edit_internals
);
1292 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1293 TALLOC_CTX
*mem_ctx
,
1294 struct rpc_sh_ctx
*ctx
)
1296 static struct rpc_sh_cmd cmds
[] = {
1298 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1299 "Show/Set a user's full name" },
1301 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1302 "Show/Set a user's home directory" },
1304 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1305 "Show/Set a user's home drive" },
1307 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1308 "Show/Set a user's logon script" },
1310 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1311 "Show/Set a user's profile path" },
1313 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1314 "Show/Set a user's description" },
1316 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1317 "Show/Set whether a user is disabled" },
1319 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1320 "Show/Set whether a user locked out" },
1322 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1323 "Show/Set whether a user does not need a password" },
1325 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1326 "Show/Set whether a user's password does not expire" },
1328 { NULL
, NULL
, 0, NULL
, NULL
}
1334 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1335 TALLOC_CTX
*mem_ctx
,
1336 struct rpc_sh_ctx
*ctx
)
1338 static struct rpc_sh_cmd cmds
[] = {
1340 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1341 "List available users" },
1343 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1344 "List the domain groups a user is member of" },
1346 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1347 "Show info about a user" },
1349 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1350 "Show/Modify a user's fields" },
1352 { NULL
, NULL
, 0, NULL
, NULL
}
1358 /****************************************************************************/
1361 * Basic usage function for 'net rpc group'.
1362 * @param argc Standard main() style argc.
1363 * @param argv Standard main() style argv. Initial components are already
1367 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1369 return net_group_usage(c
, argc
, argv
);
1373 * Delete group on a remote RPC server.
1375 * All parameters are provided by the run_rpc_command function, except for
1376 * argc, argv which are passed through.
1378 * @param domain_sid The domain sid acquired from the remote server.
1379 * @param cli A cli_state connected to the server.
1380 * @param mem_ctx Talloc context, destroyed on completion of the function.
1381 * @param argc Standard main() style argc.
1382 * @param argv Standard main() style argv. Initial components are already
1385 * @return Normal NTSTATUS return.
1388 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1389 const DOM_SID
*domain_sid
,
1390 const char *domain_name
,
1391 struct cli_state
*cli
,
1392 struct rpc_pipe_client
*pipe_hnd
,
1393 TALLOC_CTX
*mem_ctx
,
1397 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1398 bool group_is_primary
= false;
1399 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1401 struct samr_RidTypeArray
*rids
= NULL
;
1404 /* DOM_GID *user_gids; */
1406 struct samr_Ids group_rids
, name_types
;
1407 struct lsa_String lsa_acct_name
;
1408 union samr_UserInfo
*info
= NULL
;
1410 if (argc
< 1 || c
->display_usage
) {
1411 rpc_group_usage(c
, argc
,argv
);
1412 return NT_STATUS_OK
; /* ok? */
1415 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1417 MAXIMUM_ALLOWED_ACCESS
,
1420 if (!NT_STATUS_IS_OK(result
)) {
1421 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1425 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1427 MAXIMUM_ALLOWED_ACCESS
,
1428 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1431 if (!NT_STATUS_IS_OK(result
)) {
1432 d_fprintf(stderr
, "Request open_domain failed\n");
1436 init_lsa_String(&lsa_acct_name
, argv
[0]);
1438 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1444 if (!NT_STATUS_IS_OK(result
)) {
1445 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1449 switch (name_types
.ids
[0])
1451 case SID_NAME_DOM_GRP
:
1452 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1454 MAXIMUM_ALLOWED_ACCESS
,
1457 if (!NT_STATUS_IS_OK(result
)) {
1458 d_fprintf(stderr
, "Request open_group failed");
1462 group_rid
= group_rids
.ids
[0];
1464 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1468 if (!NT_STATUS_IS_OK(result
)) {
1469 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1473 if (c
->opt_verbose
) {
1474 d_printf("Domain Group %s (rid: %d) has %d members\n",
1475 argv
[0],group_rid
, rids
->count
);
1478 /* Check if group is anyone's primary group */
1479 for (i
= 0; i
< rids
->count
; i
++)
1481 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1483 MAXIMUM_ALLOWED_ACCESS
,
1487 if (!NT_STATUS_IS_OK(result
)) {
1488 d_fprintf(stderr
, "Unable to open group member %d\n",
1493 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1498 if (!NT_STATUS_IS_OK(result
)) {
1499 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1504 if (info
->info21
.primary_gid
== group_rid
) {
1505 if (c
->opt_verbose
) {
1506 d_printf("Group is primary group of %s\n",
1507 info
->info21
.account_name
.string
);
1509 group_is_primary
= true;
1512 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1515 if (group_is_primary
) {
1516 d_fprintf(stderr
, "Unable to delete group because some "
1517 "of it's members have it as primary group\n");
1518 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1522 /* remove all group members */
1523 for (i
= 0; i
< rids
->count
; i
++)
1526 d_printf("Remove group member %d...",
1528 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1532 if (NT_STATUS_IS_OK(result
)) {
1537 d_printf("failed\n");
1542 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1546 /* removing a local group is easier... */
1547 case SID_NAME_ALIAS
:
1548 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1550 MAXIMUM_ALLOWED_ACCESS
,
1554 if (!NT_STATUS_IS_OK(result
)) {
1555 d_fprintf(stderr
, "Request open_alias failed\n");
1559 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1563 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1564 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1565 result
= NT_STATUS_UNSUCCESSFUL
;
1569 if (NT_STATUS_IS_OK(result
)) {
1571 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1573 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1574 get_friendly_nt_error_msg(result
));
1582 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1584 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1585 rpc_group_delete_internals
, argc
,argv
);
1588 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1590 NET_API_STATUS status
;
1591 struct GROUP_INFO_1 info1
;
1592 uint32_t parm_error
= 0;
1594 if (argc
!= 1 || c
->display_usage
) {
1595 rpc_group_usage(c
, argc
, argv
);
1601 info1
.grpi1_name
= argv
[0];
1602 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1603 info1
.grpi1_comment
= c
->opt_comment
;
1606 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1609 d_fprintf(stderr
, "Failed to add group '%s' with: %s.\n",
1610 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1614 d_printf("Added group '%s'.\n", argv
[0]);
1620 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1622 NET_API_STATUS status
;
1623 struct LOCALGROUP_INFO_1 info1
;
1624 uint32_t parm_error
= 0;
1626 if (argc
!= 1 || c
->display_usage
) {
1627 rpc_group_usage(c
, argc
, argv
);
1633 info1
.lgrpi1_name
= argv
[0];
1634 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1635 info1
.lgrpi1_comment
= c
->opt_comment
;
1638 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1641 d_fprintf(stderr
, "Failed to add alias '%s' with: %s.\n",
1642 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1646 d_printf("Added alias '%s'.\n", argv
[0]);
1652 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1654 if (c
->opt_localgroup
)
1655 return rpc_alias_add_internals(c
, argc
, argv
);
1657 return rpc_group_add_internals(c
, argc
, argv
);
1660 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1661 TALLOC_CTX
*mem_ctx
,
1664 enum lsa_SidType
*type
)
1666 DOM_SID
*sids
= NULL
;
1667 enum lsa_SidType
*types
= NULL
;
1668 struct rpc_pipe_client
*pipe_hnd
;
1670 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1672 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1674 if (!NT_STATUS_IS_OK(result
)) {
1678 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1679 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1681 if (!NT_STATUS_IS_OK(result
)) {
1685 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1686 &name
, NULL
, 1, &sids
, &types
);
1688 if (NT_STATUS_IS_OK(result
)) {
1689 sid_copy(sid
, &sids
[0]);
1693 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1697 TALLOC_FREE(pipe_hnd
);
1700 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1702 /* Try as S-1-5-whatever */
1706 if (string_to_sid(&tmp_sid
, name
)) {
1707 sid_copy(sid
, &tmp_sid
);
1708 *type
= SID_NAME_UNKNOWN
;
1709 result
= NT_STATUS_OK
;
1716 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1717 TALLOC_CTX
*mem_ctx
,
1718 const DOM_SID
*group_sid
,
1721 POLICY_HND connect_pol
, domain_pol
;
1724 POLICY_HND group_pol
;
1726 struct samr_Ids rids
, rid_types
;
1727 struct lsa_String lsa_acct_name
;
1731 sid_copy(&sid
, group_sid
);
1733 if (!sid_split_rid(&sid
, &group_rid
)) {
1734 return NT_STATUS_UNSUCCESSFUL
;
1737 /* Get sam policy handle */
1738 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1740 MAXIMUM_ALLOWED_ACCESS
,
1742 if (!NT_STATUS_IS_OK(result
)) {
1746 /* Get domain policy handle */
1747 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1749 MAXIMUM_ALLOWED_ACCESS
,
1752 if (!NT_STATUS_IS_OK(result
)) {
1756 init_lsa_String(&lsa_acct_name
, member
);
1758 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1765 if (!NT_STATUS_IS_OK(result
)) {
1766 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1770 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1772 MAXIMUM_ALLOWED_ACCESS
,
1776 if (!NT_STATUS_IS_OK(result
)) {
1780 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1783 0x0005); /* unknown flags */
1786 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1790 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1791 TALLOC_CTX
*mem_ctx
,
1792 const DOM_SID
*alias_sid
,
1795 POLICY_HND connect_pol
, domain_pol
;
1798 POLICY_HND alias_pol
;
1801 enum lsa_SidType member_type
;
1805 sid_copy(&sid
, alias_sid
);
1807 if (!sid_split_rid(&sid
, &alias_rid
)) {
1808 return NT_STATUS_UNSUCCESSFUL
;
1811 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1812 member
, &member_sid
, &member_type
);
1814 if (!NT_STATUS_IS_OK(result
)) {
1815 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1819 /* Get sam policy handle */
1820 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1822 MAXIMUM_ALLOWED_ACCESS
,
1824 if (!NT_STATUS_IS_OK(result
)) {
1828 /* Get domain policy handle */
1829 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1831 MAXIMUM_ALLOWED_ACCESS
,
1834 if (!NT_STATUS_IS_OK(result
)) {
1838 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1840 MAXIMUM_ALLOWED_ACCESS
,
1844 if (!NT_STATUS_IS_OK(result
)) {
1848 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1852 if (!NT_STATUS_IS_OK(result
)) {
1857 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1861 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1862 const DOM_SID
*domain_sid
,
1863 const char *domain_name
,
1864 struct cli_state
*cli
,
1865 struct rpc_pipe_client
*pipe_hnd
,
1866 TALLOC_CTX
*mem_ctx
,
1871 enum lsa_SidType group_type
;
1873 if (argc
!= 2 || c
->display_usage
) {
1875 "net rpc group addmem <group> <member>\n"
1876 " Add a member to a group\n"
1877 " group\tGroup to add member to\n"
1878 " member\tMember to add to group\n");
1879 return NT_STATUS_UNSUCCESSFUL
;
1882 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1883 &group_sid
, &group_type
))) {
1884 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
1885 return NT_STATUS_UNSUCCESSFUL
;
1888 if (group_type
== SID_NAME_DOM_GRP
) {
1889 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1890 &group_sid
, argv
[1]);
1892 if (!NT_STATUS_IS_OK(result
)) {
1893 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1894 argv
[1], argv
[0], nt_errstr(result
));
1899 if (group_type
== SID_NAME_ALIAS
) {
1900 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1901 &group_sid
, argv
[1]);
1903 if (!NT_STATUS_IS_OK(result
)) {
1904 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1905 argv
[1], argv
[0], nt_errstr(result
));
1910 d_fprintf(stderr
, "Can only add members to global or local groups "
1911 "which %s is not\n", argv
[0]);
1913 return NT_STATUS_UNSUCCESSFUL
;
1916 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1918 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1919 rpc_group_addmem_internals
,
1923 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1924 struct rpc_pipe_client
*pipe_hnd
,
1925 TALLOC_CTX
*mem_ctx
,
1926 const DOM_SID
*group_sid
,
1929 POLICY_HND connect_pol
, domain_pol
;
1932 POLICY_HND group_pol
;
1934 struct samr_Ids rids
, rid_types
;
1935 struct lsa_String lsa_acct_name
;
1939 sid_copy(&sid
, group_sid
);
1941 if (!sid_split_rid(&sid
, &group_rid
))
1942 return NT_STATUS_UNSUCCESSFUL
;
1944 /* Get sam policy handle */
1945 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1947 MAXIMUM_ALLOWED_ACCESS
,
1949 if (!NT_STATUS_IS_OK(result
))
1952 /* Get domain policy handle */
1953 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1955 MAXIMUM_ALLOWED_ACCESS
,
1958 if (!NT_STATUS_IS_OK(result
))
1961 init_lsa_String(&lsa_acct_name
, member
);
1963 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1969 if (!NT_STATUS_IS_OK(result
)) {
1970 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1974 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1976 MAXIMUM_ALLOWED_ACCESS
,
1980 if (!NT_STATUS_IS_OK(result
))
1983 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1988 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1992 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1993 TALLOC_CTX
*mem_ctx
,
1994 const DOM_SID
*alias_sid
,
1997 POLICY_HND connect_pol
, domain_pol
;
2000 POLICY_HND alias_pol
;
2003 enum lsa_SidType member_type
;
2007 sid_copy(&sid
, alias_sid
);
2009 if (!sid_split_rid(&sid
, &alias_rid
))
2010 return NT_STATUS_UNSUCCESSFUL
;
2012 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2013 member
, &member_sid
, &member_type
);
2015 if (!NT_STATUS_IS_OK(result
)) {
2016 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2020 /* Get sam policy handle */
2021 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2023 MAXIMUM_ALLOWED_ACCESS
,
2025 if (!NT_STATUS_IS_OK(result
)) {
2029 /* Get domain policy handle */
2030 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2032 MAXIMUM_ALLOWED_ACCESS
,
2035 if (!NT_STATUS_IS_OK(result
)) {
2039 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2041 MAXIMUM_ALLOWED_ACCESS
,
2045 if (!NT_STATUS_IS_OK(result
))
2048 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2052 if (!NT_STATUS_IS_OK(result
))
2056 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2060 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2061 const DOM_SID
*domain_sid
,
2062 const char *domain_name
,
2063 struct cli_state
*cli
,
2064 struct rpc_pipe_client
*pipe_hnd
,
2065 TALLOC_CTX
*mem_ctx
,
2070 enum lsa_SidType group_type
;
2072 if (argc
!= 2 || c
->display_usage
) {
2074 "net rpc group delmem <group> <member>\n"
2075 " Delete a member from a group\n"
2076 " group\tGroup to delete member from\n"
2077 " member\tMember to delete from group\n");
2078 return NT_STATUS_UNSUCCESSFUL
;
2081 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2082 &group_sid
, &group_type
))) {
2083 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2084 return NT_STATUS_UNSUCCESSFUL
;
2087 if (group_type
== SID_NAME_DOM_GRP
) {
2088 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2089 &group_sid
, argv
[1]);
2091 if (!NT_STATUS_IS_OK(result
)) {
2092 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2093 argv
[1], argv
[0], nt_errstr(result
));
2098 if (group_type
== SID_NAME_ALIAS
) {
2099 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2100 &group_sid
, argv
[1]);
2102 if (!NT_STATUS_IS_OK(result
)) {
2103 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2104 argv
[1], argv
[0], nt_errstr(result
));
2109 d_fprintf(stderr
, "Can only delete members from global or local groups "
2110 "which %s is not\n", argv
[0]);
2112 return NT_STATUS_UNSUCCESSFUL
;
2115 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2117 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2118 rpc_group_delmem_internals
,
2123 * List groups on a remote RPC server.
2125 * All parameters are provided by the run_rpc_command function, except for
2126 * argc, argv which are passes through.
2128 * @param domain_sid The domain sid acquired from the remote server.
2129 * @param cli A cli_state connected to the server.
2130 * @param mem_ctx Talloc context, destroyed on completion of the function.
2131 * @param argc Standard main() style argc.
2132 * @param argv Standard main() style argv. Initial components are already
2135 * @return Normal NTSTATUS return.
2138 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2139 const DOM_SID
*domain_sid
,
2140 const char *domain_name
,
2141 struct cli_state
*cli
,
2142 struct rpc_pipe_client
*pipe_hnd
,
2143 TALLOC_CTX
*mem_ctx
,
2147 POLICY_HND connect_pol
, domain_pol
;
2148 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2149 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2150 struct samr_SamArray
*groups
= NULL
;
2151 bool global
= false;
2153 bool builtin
= false;
2155 if (c
->display_usage
) {
2157 "net rpc group list [global] [local] [builtin]\n"
2158 " List groups on RPC server\n"
2159 " global\tList global groups\n"
2160 " local\tList local groups\n"
2161 " builtin\tList builtin groups\n"
2162 " If none of global, local or builtin is "
2163 "specified, all three options are considered set\n");
2164 return NT_STATUS_OK
;
2173 for (i
=0; i
<argc
; i
++) {
2174 if (strequal(argv
[i
], "global"))
2177 if (strequal(argv
[i
], "local"))
2180 if (strequal(argv
[i
], "builtin"))
2184 /* Get sam policy handle */
2186 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2188 MAXIMUM_ALLOWED_ACCESS
,
2190 if (!NT_STATUS_IS_OK(result
)) {
2194 /* Get domain policy handle */
2196 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2198 MAXIMUM_ALLOWED_ACCESS
,
2199 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2201 if (!NT_STATUS_IS_OK(result
)) {
2205 /* Query domain groups */
2206 if (c
->opt_long_list_entries
)
2207 d_printf("\nGroup name Comment"
2208 "\n-----------------------------\n");
2210 uint32_t max_size
, total_size
, returned_size
;
2211 union samr_DispInfo info
;
2215 get_query_dispinfo_params(
2216 loop_count
, &max_entries
, &max_size
);
2218 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2227 num_entries
= info
.info3
.count
;
2228 start_idx
+= info
.info3
.count
;
2230 if (!NT_STATUS_IS_OK(result
) &&
2231 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2234 for (i
= 0; i
< num_entries
; i
++) {
2236 const char *group
= NULL
;
2237 const char *desc
= NULL
;
2239 group
= info
.info3
.entries
[i
].account_name
.string
;
2240 desc
= info
.info3
.entries
[i
].description
.string
;
2242 if (c
->opt_long_list_entries
)
2243 printf("%-21.21s %-50.50s\n",
2246 printf("%s\n", group
);
2248 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2249 /* query domain aliases */
2254 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2260 if (!NT_STATUS_IS_OK(result
) &&
2261 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2264 for (i
= 0; i
< num_entries
; i
++) {
2266 const char *description
= NULL
;
2268 if (c
->opt_long_list_entries
) {
2270 POLICY_HND alias_pol
;
2271 union samr_AliasInfo
*info
= NULL
;
2273 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2276 groups
->entries
[i
].idx
,
2278 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2282 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2284 description
= info
->description
.string
;
2288 if (description
!= NULL
) {
2289 printf("%-21.21s %-50.50s\n",
2290 groups
->entries
[i
].name
.string
,
2293 printf("%s\n", groups
->entries
[i
].name
.string
);
2296 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2297 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2298 /* Get builtin policy handle */
2300 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2302 MAXIMUM_ALLOWED_ACCESS
,
2303 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2305 if (!NT_STATUS_IS_OK(result
)) {
2308 /* query builtin aliases */
2311 if (!builtin
) break;
2313 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2319 if (!NT_STATUS_IS_OK(result
) &&
2320 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2323 for (i
= 0; i
< num_entries
; i
++) {
2325 const char *description
= NULL
;
2327 if (c
->opt_long_list_entries
) {
2329 POLICY_HND alias_pol
;
2330 union samr_AliasInfo
*info
= NULL
;
2332 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2335 groups
->entries
[i
].idx
,
2337 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2341 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2343 description
= info
->description
.string
;
2347 if (description
!= NULL
) {
2348 printf("%-21.21s %-50.50s\n",
2349 groups
->entries
[i
].name
.string
,
2352 printf("%s\n", groups
->entries
[i
].name
.string
);
2355 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2361 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2363 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2364 rpc_group_list_internals
,
2368 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2369 struct rpc_pipe_client
*pipe_hnd
,
2370 TALLOC_CTX
*mem_ctx
,
2371 const char *domain_name
,
2372 const DOM_SID
*domain_sid
,
2373 POLICY_HND
*domain_pol
,
2377 POLICY_HND group_pol
;
2378 uint32 num_members
, *group_rids
;
2380 struct samr_RidTypeArray
*rids
= NULL
;
2381 struct lsa_Strings names
;
2382 struct samr_Ids types
;
2385 sid_to_fstring(sid_str
, domain_sid
);
2387 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2389 MAXIMUM_ALLOWED_ACCESS
,
2393 if (!NT_STATUS_IS_OK(result
))
2396 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2400 if (!NT_STATUS_IS_OK(result
))
2403 num_members
= rids
->count
;
2404 group_rids
= rids
->rids
;
2406 while (num_members
> 0) {
2407 int this_time
= 512;
2409 if (num_members
< this_time
)
2410 this_time
= num_members
;
2412 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2419 if (!NT_STATUS_IS_OK(result
))
2422 /* We only have users as members, but make the output
2423 the same as the output of alias members */
2425 for (i
= 0; i
< this_time
; i
++) {
2427 if (c
->opt_long_list_entries
) {
2428 printf("%s-%d %s\\%s %d\n", sid_str
,
2429 group_rids
[i
], domain_name
,
2430 names
.names
[i
].string
,
2433 printf("%s\\%s\n", domain_name
,
2434 names
.names
[i
].string
);
2438 num_members
-= this_time
;
2442 return NT_STATUS_OK
;
2445 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2446 struct rpc_pipe_client
*pipe_hnd
,
2447 TALLOC_CTX
*mem_ctx
,
2448 POLICY_HND
*domain_pol
,
2452 struct rpc_pipe_client
*lsa_pipe
;
2453 POLICY_HND alias_pol
, lsa_pol
;
2455 DOM_SID
*alias_sids
;
2458 enum lsa_SidType
*types
;
2460 struct lsa_SidArray sid_array
;
2462 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2464 MAXIMUM_ALLOWED_ACCESS
,
2468 if (!NT_STATUS_IS_OK(result
))
2471 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2475 if (!NT_STATUS_IS_OK(result
)) {
2476 d_fprintf(stderr
, "Couldn't list alias members\n");
2480 num_members
= sid_array
.num_sids
;
2482 if (num_members
== 0) {
2483 return NT_STATUS_OK
;
2486 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2487 &ndr_table_lsarpc
.syntax_id
,
2489 if (!NT_STATUS_IS_OK(result
)) {
2490 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2491 nt_errstr(result
) );
2495 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2496 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2498 if (!NT_STATUS_IS_OK(result
)) {
2499 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2500 TALLOC_FREE(lsa_pipe
);
2504 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2506 d_fprintf(stderr
, "Out of memory\n");
2507 TALLOC_FREE(lsa_pipe
);
2508 return NT_STATUS_NO_MEMORY
;
2511 for (i
=0; i
<num_members
; i
++) {
2512 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2515 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2516 num_members
, alias_sids
,
2517 &domains
, &names
, &types
);
2519 if (!NT_STATUS_IS_OK(result
) &&
2520 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2521 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2522 TALLOC_FREE(lsa_pipe
);
2526 for (i
= 0; i
< num_members
; i
++) {
2528 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2530 if (c
->opt_long_list_entries
) {
2531 printf("%s %s\\%s %d\n", sid_str
,
2532 domains
[i
] ? domains
[i
] : "*unknown*",
2533 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2536 printf("%s\\%s\n", domains
[i
], names
[i
]);
2538 printf("%s\n", sid_str
);
2542 TALLOC_FREE(lsa_pipe
);
2543 return NT_STATUS_OK
;
2546 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2547 const DOM_SID
*domain_sid
,
2548 const char *domain_name
,
2549 struct cli_state
*cli
,
2550 struct rpc_pipe_client
*pipe_hnd
,
2551 TALLOC_CTX
*mem_ctx
,
2556 POLICY_HND connect_pol
, domain_pol
;
2557 struct samr_Ids rids
, rid_types
;
2558 struct lsa_String lsa_acct_name
;
2560 /* Get sam policy handle */
2562 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2564 MAXIMUM_ALLOWED_ACCESS
,
2567 if (!NT_STATUS_IS_OK(result
))
2570 /* Get domain policy handle */
2572 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2574 MAXIMUM_ALLOWED_ACCESS
,
2575 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2578 if (!NT_STATUS_IS_OK(result
))
2581 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2583 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2590 if (!NT_STATUS_IS_OK(result
)) {
2592 /* Ok, did not find it in the global sam, try with builtin */
2594 DOM_SID sid_Builtin
;
2596 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2598 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2600 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2602 MAXIMUM_ALLOWED_ACCESS
,
2606 if (!NT_STATUS_IS_OK(result
)) {
2607 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2611 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2618 if (!NT_STATUS_IS_OK(result
)) {
2619 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2624 if (rids
.count
!= 1) {
2625 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2629 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2630 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2631 domain_sid
, &domain_pol
,
2635 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2636 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2640 return NT_STATUS_NO_SUCH_GROUP
;
2643 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2645 if (argc
!= 1 || c
->display_usage
) {
2646 return rpc_group_usage(c
, argc
, argv
);
2649 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2650 rpc_group_members_internals
,
2654 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2656 NET_API_STATUS status
;
2657 struct GROUP_INFO_0 g0
;
2661 d_printf("Usage: 'net rpc group rename group newname'\n");
2665 g0
.grpi0_name
= argv
[1];
2667 status
= NetGroupSetInfo(c
->opt_host
,
2674 d_fprintf(stderr
, "Renaming group %s failed with: %s\n",
2675 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2683 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2685 if (argc
!= 2 || c
->display_usage
) {
2686 return rpc_group_usage(c
, argc
, argv
);
2689 return rpc_group_rename_internals(c
, argc
, argv
);
2693 * 'net rpc group' entrypoint.
2694 * @param argc Standard main() style argc.
2695 * @param argv Standard main() style argv. Initial components are already
2699 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2701 NET_API_STATUS status
;
2703 struct functable func
[] = {
2708 "Create specified group",
2709 "net rpc group add\n"
2710 " Create specified group"
2716 "Delete specified group",
2717 "net rpc group delete\n"
2718 " Delete specified group"
2724 "Add member to group",
2725 "net rpc group addmem\n"
2726 " Add member to group"
2732 "Remove member from group",
2733 "net rpc group delmem\n"
2734 " Remove member from group"
2741 "net rpc group list\n"
2748 "List group members",
2749 "net rpc group members\n"
2750 " List group members"
2757 "net rpc group rename\n"
2760 {NULL
, NULL
, 0, NULL
, NULL
}
2763 status
= libnetapi_init(&c
->netapi_ctx
);
2767 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2768 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2769 if (c
->opt_kerberos
) {
2770 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2774 if (c
->display_usage
) {
2775 d_printf("Usage:\n");
2776 d_printf("net rpc group\n"
2777 " Alias for net rpc group list global local "
2779 net_display_usage_from_functable(func
);
2783 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2784 rpc_group_list_internals
,
2788 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2791 /****************************************************************************/
2793 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2795 return net_share_usage(c
, argc
, argv
);
2799 * Add a share on a remote RPC server.
2801 * @param argc Standard main() style argc.
2802 * @param argv Standard main() style argv. Initial components are already
2805 * @return A shell status integer (0 for success).
2808 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2810 NET_API_STATUS status
;
2813 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2814 uint32 num_users
=0, perms
=0;
2815 char *password
=NULL
; /* don't allow a share password */
2816 struct SHARE_INFO_2 i2
;
2817 uint32_t parm_error
= 0;
2819 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2820 return rpc_share_usage(c
, argc
, argv
);
2823 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2827 path
= strchr(sharename
, '=');
2834 i2
.shi2_netname
= sharename
;
2835 i2
.shi2_type
= type
;
2836 i2
.shi2_remark
= c
->opt_comment
;
2837 i2
.shi2_permissions
= perms
;
2838 i2
.shi2_max_uses
= c
->opt_maxusers
;
2839 i2
.shi2_current_uses
= num_users
;
2840 i2
.shi2_path
= path
;
2841 i2
.shi2_passwd
= password
;
2843 status
= NetShareAdd(c
->opt_host
,
2848 printf("NetShareAdd failed with: %s\n",
2849 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2856 * Delete a share on a remote RPC server.
2858 * @param domain_sid The domain sid acquired from the remote server.
2859 * @param argc Standard main() style argc.
2860 * @param argv Standard main() style argv. Initial components are already
2863 * @return A shell status integer (0 for success).
2865 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2867 if (argc
< 1 || c
->display_usage
) {
2868 return rpc_share_usage(c
, argc
, argv
);
2871 return NetShareDel(c
->opt_host
, argv
[0], 0);
2875 * Formatted print of share info
2877 * @param r pointer to SHARE_INFO_1 to format
2880 static void display_share_info_1(struct net_context
*c
,
2881 struct SHARE_INFO_1
*r
)
2883 if (c
->opt_long_list_entries
) {
2884 d_printf("%-12s %-8.8s %-50s\n",
2886 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2889 d_printf("%s\n", r
->shi1_netname
);
2893 static WERROR
get_share_info(struct net_context
*c
,
2894 struct rpc_pipe_client
*pipe_hnd
,
2895 TALLOC_CTX
*mem_ctx
,
2899 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2903 union srvsvc_NetShareInfo info
;
2905 /* no specific share requested, enumerate all */
2908 uint32_t preferred_len
= 0xffffffff;
2909 uint32_t total_entries
= 0;
2910 uint32_t resume_handle
= 0;
2912 info_ctr
->level
= level
;
2914 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2924 /* request just one share */
2925 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2932 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2937 ZERO_STRUCTP(info_ctr
);
2939 info_ctr
->level
= level
;
2944 struct srvsvc_NetShareCtr1
*ctr1
;
2946 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2947 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2950 ctr1
->array
= info
.info1
;
2952 info_ctr
->ctr
.ctr1
= ctr1
;
2956 struct srvsvc_NetShareCtr2
*ctr2
;
2958 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2959 W_ERROR_HAVE_NO_MEMORY(ctr2
);
2962 ctr2
->array
= info
.info2
;
2964 info_ctr
->ctr
.ctr2
= ctr2
;
2968 struct srvsvc_NetShareCtr502
*ctr502
;
2970 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
2971 W_ERROR_HAVE_NO_MEMORY(ctr502
);
2974 ctr502
->array
= info
.info502
;
2976 info_ctr
->ctr
.ctr502
= ctr502
;
2984 * 'net rpc share list' entrypoint.
2985 * @param argc Standard main() style argc.
2986 * @param argv Standard main() style argv. Initial components are already
2989 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
2991 NET_API_STATUS status
;
2992 struct SHARE_INFO_1
*i1
= NULL
;
2993 uint32_t entries_read
= 0;
2994 uint32_t total_entries
= 0;
2995 uint32_t resume_handle
= 0;
2996 uint32_t i
, level
= 1;
2998 if (c
->display_usage
) {
3000 "net rpc share list\n"
3001 " List shares on remote server\n");
3005 status
= NetShareEnum(c
->opt_host
,
3007 (uint8_t **)(void *)&i1
,
3016 /* Display results */
3018 if (c
->opt_long_list_entries
) {
3020 "\nEnumerating shared resources (exports) on remote server:\n\n"
3021 "\nShare name Type Description\n"
3022 "---------- ---- -----------\n");
3024 for (i
= 0; i
< entries_read
; i
++)
3025 display_share_info_1(c
, &i1
[i
]);
3030 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3032 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3033 d_printf("skipping [%s]: not a file share.\n", netname
);
3043 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3044 const char *netname
, uint32 type
)
3046 /* only support disk shares */
3047 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3048 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3052 /* skip builtin shares */
3053 /* FIXME: should print$ be added too ? */
3054 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3055 strequal(netname
,"global"))
3058 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3059 printf("excluding [%s]\n", netname
);
3063 return check_share_availability(cli
, netname
);
3067 * Migrate shares from a remote RPC server to the local RPC server.
3069 * All parameters are provided by the run_rpc_command function, except for
3070 * argc, argv which are passed through.
3072 * @param domain_sid The domain sid acquired from the remote server.
3073 * @param cli A cli_state connected to the server.
3074 * @param mem_ctx Talloc context, destroyed on completion of the function.
3075 * @param argc Standard main() style argc.
3076 * @param argv Standard main() style argv. Initial components are already
3079 * @return Normal NTSTATUS return.
3082 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3083 const DOM_SID
*domain_sid
,
3084 const char *domain_name
,
3085 struct cli_state
*cli
,
3086 struct rpc_pipe_client
*pipe_hnd
,
3087 TALLOC_CTX
*mem_ctx
,
3092 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3093 struct srvsvc_NetShareInfoCtr ctr_src
;
3095 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3096 struct cli_state
*cli_dst
= NULL
;
3097 uint32 level
= 502; /* includes secdesc */
3098 uint32_t parm_error
= 0;
3100 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3102 if (!W_ERROR_IS_OK(result
))
3105 /* connect destination PI_SRVSVC */
3106 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3107 &ndr_table_srvsvc
.syntax_id
);
3108 if (!NT_STATUS_IS_OK(nt_status
))
3112 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3114 union srvsvc_NetShareInfo info
;
3115 struct srvsvc_NetShareInfo502 info502
=
3116 ctr_src
.ctr
.ctr502
->array
[i
];
3118 /* reset error-code */
3119 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3121 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3124 /* finally add the share on the dst server */
3126 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3127 info502
.name
, info502
.path
, info502
.comment
);
3129 info
.info502
= &info502
;
3131 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3132 srvsvc_pipe
->desthost
,
3138 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3139 printf(" [%s] does already exist\n",
3144 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3145 printf("cannot add share: %s\n", dos_errstr(result
));
3151 nt_status
= NT_STATUS_OK
;
3155 cli_shutdown(cli_dst
);
3163 * Migrate shares from a RPC server to another.
3165 * @param argc Standard main() style argc.
3166 * @param argv Standard main() style argv. Initial components are already
3169 * @return A shell status integer (0 for success).
3171 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3174 if (c
->display_usage
) {
3176 "net rpc share migrate shares\n"
3177 " Migrate shares to local server\n");
3182 printf("no server to migrate\n");
3186 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3187 rpc_share_migrate_shares_internals
,
3194 * @param f file_info
3195 * @param mask current search mask
3196 * @param state arg-pointer
3199 static void copy_fn(const char *mnt
, file_info
*f
,
3200 const char *mask
, void *state
)
3202 static NTSTATUS nt_status
;
3203 static struct copy_clistate
*local_state
;
3204 static fstring filename
, new_mask
;
3207 struct net_context
*c
;
3209 local_state
= (struct copy_clistate
*)state
;
3210 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3214 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3217 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3220 if (f
->mode
& aDIR
) {
3222 DEBUG(3,("got dir: %s\n", f
->name
));
3224 fstrcpy(dir
, local_state
->cwd
);
3226 fstrcat(dir
, f
->name
);
3228 switch (net_mode_share
)
3230 case NET_MODE_SHARE_MIGRATE
:
3231 /* create that directory */
3232 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3233 local_state
->cli_share_src
,
3234 local_state
->cli_share_dst
,
3236 c
->opt_acls
? true : false,
3237 c
->opt_attrs
? true : false,
3238 c
->opt_timestamps
? true:false,
3242 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3246 if (!NT_STATUS_IS_OK(nt_status
))
3247 printf("could not handle dir %s: %s\n",
3248 dir
, nt_errstr(nt_status
));
3250 /* search below that directory */
3251 fstrcpy(new_mask
, dir
);
3252 fstrcat(new_mask
, "\\*");
3254 old_dir
= local_state
->cwd
;
3255 local_state
->cwd
= dir
;
3256 if (!sync_files(local_state
, new_mask
))
3257 printf("could not handle files\n");
3258 local_state
->cwd
= old_dir
;
3265 fstrcpy(filename
, local_state
->cwd
);
3266 fstrcat(filename
, "\\");
3267 fstrcat(filename
, f
->name
);
3269 DEBUG(3,("got file: %s\n", filename
));
3271 switch (net_mode_share
)
3273 case NET_MODE_SHARE_MIGRATE
:
3274 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3275 local_state
->cli_share_src
,
3276 local_state
->cli_share_dst
,
3278 c
->opt_acls
? true : false,
3279 c
->opt_attrs
? true : false,
3280 c
->opt_timestamps
? true: false,
3284 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3288 if (!NT_STATUS_IS_OK(nt_status
))
3289 printf("could not handle file %s: %s\n",
3290 filename
, nt_errstr(nt_status
));
3295 * sync files, can be called recursivly to list files
3296 * and then call copy_fn for each file
3298 * @param cp_clistate pointer to the copy_clistate we work with
3299 * @param mask the current search mask
3301 * @return Boolean result
3303 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3305 struct cli_state
*targetcli
;
3306 char *targetpath
= NULL
;
3308 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3310 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate
->cli_share_src
,
3311 mask
, &targetcli
, &targetpath
) ) {
3312 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3313 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3317 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3318 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3319 mask
, cli_errstr(targetcli
));
3328 * Set the top level directory permissions before we do any further copies.
3329 * Should set up ACL inheritance.
3332 bool copy_top_level_perms(struct net_context
*c
,
3333 struct copy_clistate
*cp_clistate
,
3334 const char *sharename
)
3336 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3338 switch (net_mode_share
) {
3339 case NET_MODE_SHARE_MIGRATE
:
3340 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3341 nt_status
= net_copy_fileattr(c
,
3342 cp_clistate
->mem_ctx
,
3343 cp_clistate
->cli_share_src
,
3344 cp_clistate
->cli_share_dst
,
3346 c
->opt_acls
? true : false,
3347 c
->opt_attrs
? true : false,
3348 c
->opt_timestamps
? true: false,
3352 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3356 if (!NT_STATUS_IS_OK(nt_status
)) {
3357 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3358 sharename
, nt_errstr(nt_status
));
3366 * Sync all files inside a remote share to another share (over smb).
3368 * All parameters are provided by the run_rpc_command function, except for
3369 * argc, argv which are passed through.
3371 * @param domain_sid The domain sid acquired from the remote server.
3372 * @param cli A cli_state connected to the server.
3373 * @param mem_ctx Talloc context, destroyed on completion of the function.
3374 * @param argc Standard main() style argc.
3375 * @param argv Standard main() style argv. Initial components are already
3378 * @return Normal NTSTATUS return.
3381 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3382 const DOM_SID
*domain_sid
,
3383 const char *domain_name
,
3384 struct cli_state
*cli
,
3385 struct rpc_pipe_client
*pipe_hnd
,
3386 TALLOC_CTX
*mem_ctx
,
3391 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3392 struct srvsvc_NetShareInfoCtr ctr_src
;
3395 struct copy_clistate cp_clistate
;
3396 bool got_src_share
= false;
3397 bool got_dst_share
= false;
3398 const char *mask
= "\\*";
3401 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3403 nt_status
= NT_STATUS_NO_MEMORY
;
3407 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3410 if (!W_ERROR_IS_OK(result
))
3413 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3415 struct srvsvc_NetShareInfo502 info502
=
3416 ctr_src
.ctr
.ctr502
->array
[i
];
3418 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3421 /* one might not want to mirror whole discs :) */
3422 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3423 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3427 switch (net_mode_share
)
3429 case NET_MODE_SHARE_MIGRATE
:
3433 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3436 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3438 c
->opt_acls
? "including" : "without",
3439 c
->opt_attrs
? "including" : "without",
3440 c
->opt_timestamps
? "(preserving timestamps)" : "");
3442 cp_clistate
.mem_ctx
= mem_ctx
;
3443 cp_clistate
.cli_share_src
= NULL
;
3444 cp_clistate
.cli_share_dst
= NULL
;
3445 cp_clistate
.cwd
= NULL
;
3446 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3449 /* open share source */
3450 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3451 &cli
->dest_ss
, cli
->desthost
,
3452 info502
.name
, "A:");
3453 if (!NT_STATUS_IS_OK(nt_status
))
3456 got_src_share
= true;
3458 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3459 /* open share destination */
3460 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3461 NULL
, dst
, info502
.name
, "A:");
3462 if (!NT_STATUS_IS_OK(nt_status
))
3465 got_dst_share
= true;
3468 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3469 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3470 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3474 if (!sync_files(&cp_clistate
, mask
)) {
3475 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3476 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3481 nt_status
= NT_STATUS_OK
;
3486 cli_shutdown(cp_clistate
.cli_share_src
);
3489 cli_shutdown(cp_clistate
.cli_share_dst
);
3496 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3498 if (c
->display_usage
) {
3500 "net share migrate files\n"
3501 " Migrate files to local server\n");
3506 d_printf("no server to migrate\n");
3510 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3511 rpc_share_migrate_files_internals
,
3516 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3518 * All parameters are provided by the run_rpc_command function, except for
3519 * argc, argv which are passed through.
3521 * @param domain_sid The domain sid acquired from the remote server.
3522 * @param cli A cli_state connected to the server.
3523 * @param mem_ctx Talloc context, destroyed on completion of the function.
3524 * @param argc Standard main() style argc.
3525 * @param argv Standard main() style argv. Initial components are already
3528 * @return Normal NTSTATUS return.
3531 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3532 const DOM_SID
*domain_sid
,
3533 const char *domain_name
,
3534 struct cli_state
*cli
,
3535 struct rpc_pipe_client
*pipe_hnd
,
3536 TALLOC_CTX
*mem_ctx
,
3541 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3542 struct srvsvc_NetShareInfoCtr ctr_src
;
3543 union srvsvc_NetShareInfo info
;
3545 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3546 struct cli_state
*cli_dst
= NULL
;
3547 uint32 level
= 502; /* includes secdesc */
3548 uint32_t parm_error
= 0;
3550 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3553 if (!W_ERROR_IS_OK(result
))
3556 /* connect destination PI_SRVSVC */
3557 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3558 &ndr_table_srvsvc
.syntax_id
);
3559 if (!NT_STATUS_IS_OK(nt_status
))
3563 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3565 struct srvsvc_NetShareInfo502 info502
=
3566 ctr_src
.ctr
.ctr502
->array
[i
];
3568 /* reset error-code */
3569 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3571 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3574 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3575 info502
.name
, info502
.path
, info502
.comment
);
3578 display_sec_desc(info502
.sd_buf
.sd
);
3580 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3581 info
.info502
= &info502
;
3583 /* finally modify the share on the dst server */
3584 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3585 srvsvc_pipe
->desthost
,
3591 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3592 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3598 nt_status
= NT_STATUS_OK
;
3602 cli_shutdown(cli_dst
);
3610 * Migrate share-acls from a RPC server to another.
3612 * @param argc Standard main() style argc.
3613 * @param argv Standard main() style argv. Initial components are already
3616 * @return A shell status integer (0 for success).
3618 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3621 if (c
->display_usage
) {
3623 "net rpc share migrate security\n"
3624 " Migrate share-acls to local server\n");
3629 d_printf("no server to migrate\n");
3633 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3634 rpc_share_migrate_security_internals
,
3639 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3640 * from one server to another.
3642 * @param argc Standard main() style argc.
3643 * @param argv Standard main() style argv. Initial components are already
3646 * @return A shell status integer (0 for success).
3649 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3654 if (c
->display_usage
) {
3656 "net rpc share migrate all\n"
3657 " Migrates shares including all share settings\n");
3662 d_printf("no server to migrate\n");
3666 /* order is important. we don't want to be locked out by the share-acl
3667 * before copying files - gd */
3669 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3670 rpc_share_migrate_shares_internals
, argc
, argv
);
3674 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3675 rpc_share_migrate_files_internals
, argc
, argv
);
3679 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3680 rpc_share_migrate_security_internals
, argc
,
3686 * 'net rpc share migrate' entrypoint.
3687 * @param argc Standard main() style argc.
3688 * @param argv Standard main() style argv. Initial components are already
3691 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3694 struct functable func
[] = {
3697 rpc_share_migrate_all
,
3699 "Migrate shares from remote to local server",
3700 "net rpc share migrate all\n"
3701 " Migrate shares from remote to local server"
3705 rpc_share_migrate_files
,
3707 "Migrate files from remote to local server",
3708 "net rpc share migrate files\n"
3709 " Migrate files from remote to local server"
3713 rpc_share_migrate_security
,
3715 "Migrate share-ACLs from remote to local server",
3716 "net rpc share migrate security\n"
3717 " Migrate share-ACLs from remote to local server"
3721 rpc_share_migrate_shares
,
3723 "Migrate shares from remote to local server",
3724 "net rpc share migrate shares\n"
3725 " Migrate shares from remote to local server"
3727 {NULL
, NULL
, 0, NULL
, NULL
}
3730 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3732 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3741 static int num_server_aliases
;
3742 static struct full_alias
*server_aliases
;
3745 * Add an alias to the static list.
3747 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3749 if (server_aliases
== NULL
)
3750 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3752 server_aliases
[num_server_aliases
] = *alias
;
3753 num_server_aliases
+= 1;
3757 * For a specific domain on the server, fetch all the aliases
3758 * and their members. Add all of them to the server_aliases.
3761 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3762 TALLOC_CTX
*mem_ctx
,
3763 POLICY_HND
*connect_pol
,
3764 const DOM_SID
*domain_sid
)
3766 uint32 start_idx
, max_entries
, num_entries
, i
;
3767 struct samr_SamArray
*groups
= NULL
;
3769 POLICY_HND domain_pol
;
3771 /* Get domain policy handle */
3773 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3775 MAXIMUM_ALLOWED_ACCESS
,
3776 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3778 if (!NT_STATUS_IS_OK(result
))
3785 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3791 for (i
= 0; i
< num_entries
; i
++) {
3793 POLICY_HND alias_pol
;
3794 struct full_alias alias
;
3795 struct lsa_SidArray sid_array
;
3798 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3800 MAXIMUM_ALLOWED_ACCESS
,
3801 groups
->entries
[i
].idx
,
3803 if (!NT_STATUS_IS_OK(result
))
3806 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3809 if (!NT_STATUS_IS_OK(result
))
3812 alias
.num_members
= sid_array
.num_sids
;
3814 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3815 if (!NT_STATUS_IS_OK(result
))
3818 alias
.members
= NULL
;
3820 if (alias
.num_members
> 0) {
3821 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3823 for (j
= 0; j
< alias
.num_members
; j
++)
3824 sid_copy(&alias
.members
[j
],
3825 sid_array
.sids
[j
].sid
);
3828 sid_copy(&alias
.sid
, domain_sid
);
3829 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3831 push_alias(mem_ctx
, &alias
);
3833 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3835 result
= NT_STATUS_OK
;
3838 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3844 * Dump server_aliases as names for debugging purposes.
3847 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3848 const DOM_SID
*domain_sid
,
3849 const char *domain_name
,
3850 struct cli_state
*cli
,
3851 struct rpc_pipe_client
*pipe_hnd
,
3852 TALLOC_CTX
*mem_ctx
,
3860 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3861 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3863 if (!NT_STATUS_IS_OK(result
))
3866 for (i
=0; i
<num_server_aliases
; i
++) {
3869 enum lsa_SidType
*types
;
3872 struct full_alias
*alias
= &server_aliases
[i
];
3874 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3876 &domains
, &names
, &types
);
3877 if (!NT_STATUS_IS_OK(result
))
3880 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3882 if (alias
->num_members
== 0) {
3887 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3890 &domains
, &names
, &types
);
3892 if (!NT_STATUS_IS_OK(result
) &&
3893 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3896 for (j
=0; j
<alias
->num_members
; j
++)
3897 DEBUG(1, ("%s\\%s (%d); ",
3898 domains
[j
] ? domains
[j
] : "*unknown*",
3899 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3903 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3905 return NT_STATUS_OK
;
3909 * Fetch a list of all server aliases and their members into
3913 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3914 const DOM_SID
*domain_sid
,
3915 const char *domain_name
,
3916 struct cli_state
*cli
,
3917 struct rpc_pipe_client
*pipe_hnd
,
3918 TALLOC_CTX
*mem_ctx
,
3923 POLICY_HND connect_pol
;
3925 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3927 MAXIMUM_ALLOWED_ACCESS
,
3930 if (!NT_STATUS_IS_OK(result
))
3933 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3934 &global_sid_Builtin
);
3936 if (!NT_STATUS_IS_OK(result
))
3939 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3942 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
3947 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
3949 token
->num_sids
= 4;
3951 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
3952 d_fprintf(stderr
, "malloc failed\n");
3953 token
->num_sids
= 0;
3957 token
->user_sids
[0] = *user_sid
;
3958 sid_copy(&token
->user_sids
[1], &global_sid_World
);
3959 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
3960 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
3963 static void free_user_token(NT_USER_TOKEN
*token
)
3965 SAFE_FREE(token
->user_sids
);
3968 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3970 if (is_sid_in_token(token
, sid
))
3973 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
3974 if (!token
->user_sids
) {
3978 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
3980 token
->num_sids
+= 1;
3985 NT_USER_TOKEN token
;
3988 static void dump_user_token(struct user_token
*token
)
3992 d_printf("%s\n", token
->name
);
3994 for (i
=0; i
<token
->token
.num_sids
; i
++) {
3995 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
3999 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4003 for (i
=0; i
<alias
->num_members
; i
++) {
4004 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4011 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4015 for (i
=0; i
<num_server_aliases
; i
++) {
4016 if (is_alias_member(&sid
, &server_aliases
[i
]))
4017 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4022 * We got a user token with all the SIDs we can know about without asking the
4023 * server directly. These are the user and domain group sids. All of these can
4024 * be members of aliases. So scan the list of aliases for each of the SIDs and
4025 * add them to the token.
4028 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4030 int num_global_sids
= token
->num_sids
;
4033 for (i
=0; i
<num_global_sids
; i
++) {
4034 collect_sid_memberships(token
, token
->user_sids
[i
]);
4038 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4040 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4041 enum wbcSidType type
;
4043 struct wbcDomainSid wsid
;
4044 char *sid_str
= NULL
;
4046 uint32_t num_groups
;
4047 gid_t
*groups
= NULL
;
4050 fstr_sprintf(full_name
, "%s%c%s",
4051 domain
, *lp_winbind_separator(), user
);
4053 /* First let's find out the user sid */
4055 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4057 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4058 DEBUG(1, ("winbind could not find %s: %s\n",
4059 full_name
, wbcErrorString(wbc_status
)));
4063 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4064 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4068 if (type
!= SID_NAME_USER
) {
4069 wbcFreeMemory(sid_str
);
4070 DEBUG(1, ("%s is not a user\n", full_name
));
4074 if (!string_to_sid(&user_sid
, sid_str
)) {
4075 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4079 wbcFreeMemory(sid_str
);
4082 init_user_token(token
, &user_sid
);
4084 /* And now the groups winbind knows about */
4086 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4087 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4088 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4089 full_name
, wbcErrorString(wbc_status
)));
4093 for (i
= 0; i
< num_groups
; i
++) {
4094 gid_t gid
= groups
[i
];
4097 wbc_status
= wbcGidToSid(gid
, &wsid
);
4098 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4099 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4100 gid
, wbcErrorString(wbc_status
)));
4101 wbcFreeMemory(groups
);
4105 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4106 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4107 wbcFreeMemory(groups
);
4111 DEBUG(3, (" %s\n", sid_str
));
4113 string_to_sid(&sid
, sid_str
);
4114 wbcFreeMemory(sid_str
);
4117 add_sid_to_token(token
, &sid
);
4119 wbcFreeMemory(groups
);
4125 * Get a list of all user tokens we want to look at
4128 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4129 struct user_token
**user_tokens
)
4131 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4132 uint32_t i
, num_users
;
4134 struct user_token
*result
;
4135 TALLOC_CTX
*frame
= NULL
;
4137 if (lp_winbind_use_default_domain() &&
4138 (c
->opt_target_workgroup
== NULL
)) {
4139 d_fprintf(stderr
, "winbind use default domain = yes set, "
4140 "please specify a workgroup\n");
4144 /* Send request to winbind daemon */
4146 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4147 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4148 DEBUG(1, ("winbind could not list users: %s\n",
4149 wbcErrorString(wbc_status
)));
4153 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4155 if (result
== NULL
) {
4156 DEBUG(1, ("Could not malloc sid array\n"));
4157 wbcFreeMemory(users
);
4161 frame
= talloc_stackframe();
4162 for (i
=0; i
< num_users
; i
++) {
4163 fstring domain
, user
;
4166 fstrcpy(result
[i
].name
, users
[i
]);
4168 p
= strchr(users
[i
], *lp_winbind_separator());
4170 DEBUG(3, ("%s\n", users
[i
]));
4173 fstrcpy(domain
, c
->opt_target_workgroup
);
4174 fstrcpy(user
, users
[i
]);
4177 fstrcpy(domain
, users
[i
]);
4182 get_user_sids(domain
, user
, &(result
[i
].token
));
4186 wbcFreeMemory(users
);
4188 *num_tokens
= num_users
;
4189 *user_tokens
= result
;
4194 static bool get_user_tokens_from_file(FILE *f
,
4196 struct user_token
**tokens
)
4198 struct user_token
*token
= NULL
;
4203 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4207 if (line
[strlen(line
)-1] == '\n')
4208 line
[strlen(line
)-1] = '\0';
4210 if (line
[0] == ' ') {
4214 if(!string_to_sid(&sid
, &line
[1])) {
4215 DEBUG(1,("get_user_tokens_from_file: Could "
4216 "not convert sid %s \n",&line
[1]));
4220 if (token
== NULL
) {
4221 DEBUG(0, ("File does not begin with username"));
4225 add_sid_to_token(&token
->token
, &sid
);
4229 /* And a new user... */
4232 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4233 if (*tokens
== NULL
) {
4234 DEBUG(0, ("Could not realloc tokens\n"));
4238 token
= &((*tokens
)[*num_tokens
-1]);
4240 fstrcpy(token
->name
, line
);
4241 token
->token
.num_sids
= 0;
4242 token
->token
.user_sids
= NULL
;
4251 * Show the list of all users that have access to a share
4254 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4255 TALLOC_CTX
*mem_ctx
,
4256 const char *netname
,
4258 struct user_token
*tokens
)
4261 SEC_DESC
*share_sd
= NULL
;
4262 SEC_DESC
*root_sd
= NULL
;
4263 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4265 union srvsvc_NetShareInfo info
;
4270 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4277 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4278 DEBUG(1, ("Coult not query secdesc for share %s\n",
4283 share_sd
= info
.info502
->sd_buf
.sd
;
4284 if (share_sd
== NULL
) {
4285 DEBUG(1, ("Got no secdesc for share %s\n",
4291 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4295 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4298 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4301 for (i
=0; i
<num_tokens
; i
++) {
4304 if (share_sd
!= NULL
) {
4305 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4308 if (!NT_STATUS_IS_OK(status
)) {
4309 DEBUG(1, ("Could not check share_sd for "
4316 if (root_sd
== NULL
) {
4317 d_printf(" %s\n", tokens
[i
].name
);
4321 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4323 if (!NT_STATUS_IS_OK(status
)) {
4324 DEBUG(1, ("Could not check root_sd for user %s\n",
4328 d_printf(" %s\n", tokens
[i
].name
);
4332 cli_close(cli
, fnum
);
4344 static void collect_share(const char *name
, uint32 m
,
4345 const char *comment
, void *state
)
4347 struct share_list
*share_list
= (struct share_list
*)state
;
4349 if (m
!= STYPE_DISKTREE
)
4352 share_list
->num_shares
+= 1;
4353 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4354 if (!share_list
->shares
) {
4355 share_list
->num_shares
= 0;
4358 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4362 * List shares on a remote RPC server, including the security descriptors.
4364 * All parameters are provided by the run_rpc_command function, except for
4365 * argc, argv which are passed through.
4367 * @param domain_sid The domain sid acquired from the remote server.
4368 * @param cli A cli_state connected to the server.
4369 * @param mem_ctx Talloc context, destroyed on completion of the function.
4370 * @param argc Standard main() style argc.
4371 * @param argv Standard main() style argv. Initial components are already
4374 * @return Normal NTSTATUS return.
4377 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4378 const DOM_SID
*domain_sid
,
4379 const char *domain_name
,
4380 struct cli_state
*cli
,
4381 struct rpc_pipe_client
*pipe_hnd
,
4382 TALLOC_CTX
*mem_ctx
,
4391 struct user_token
*tokens
= NULL
;
4394 struct share_list share_list
;
4399 f
= fopen(argv
[0], "r");
4403 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4404 return NT_STATUS_UNSUCCESSFUL
;
4407 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4413 DEBUG(0, ("Could not read users from file\n"));
4414 return NT_STATUS_UNSUCCESSFUL
;
4417 for (i
=0; i
<num_tokens
; i
++)
4418 collect_alias_memberships(&tokens
[i
].token
);
4420 share_list
.num_shares
= 0;
4421 share_list
.shares
= NULL
;
4423 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4426 DEBUG(0, ("Error returning browse list: %s\n",
4431 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4432 char *netname
= share_list
.shares
[i
];
4434 if (netname
[strlen(netname
)-1] == '$')
4437 d_printf("%s\n", netname
);
4439 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4440 num_tokens
, tokens
);
4443 for (i
=0; i
<num_tokens
; i
++) {
4444 free_user_token(&tokens
[i
].token
);
4447 SAFE_FREE(share_list
.shares
);
4449 return NT_STATUS_OK
;
4452 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4457 if (c
->display_usage
) {
4459 "net rpc share allowedusers\n"
4460 " List allowed users\n");
4464 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4465 rpc_aliaslist_internals
,
4470 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4476 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4477 rpc_share_allowedusers_internals
,
4481 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4484 struct user_token
*tokens
= NULL
;
4488 net_usersidlist_usage(c
, argc
, argv
);
4492 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4493 DEBUG(0, ("Could not get the user/sid list\n"));
4497 for (i
=0; i
<num_tokens
; i
++) {
4498 dump_user_token(&tokens
[i
]);
4499 free_user_token(&tokens
[i
].token
);
4506 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4508 d_printf("net usersidlist\n"
4509 "\tprints out a list of all users the running winbind knows\n"
4510 "\tabout, together with all their SIDs. This is used as\n"
4511 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4513 net_common_flags_usage(c
, argc
, argv
);
4518 * 'net rpc share' entrypoint.
4519 * @param argc Standard main() style argc.
4520 * @param argv Standard main() style argv. Initial components are already
4524 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4526 NET_API_STATUS status
;
4528 struct functable func
[] = {
4534 "net rpc share add\n"
4542 "net rpc share delete\n"
4547 rpc_share_allowedusers
,
4549 "Modify allowed users",
4550 "net rpc share allowedusers\n"
4551 " Modify allowed users"
4557 "Migrate share to local server",
4558 "net rpc share migrate\n"
4559 " Migrate share to local server"
4566 "net rpc share list\n"
4569 {NULL
, NULL
, 0, NULL
, NULL
}
4572 status
= libnetapi_init(&c
->netapi_ctx
);
4576 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4577 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4578 if (c
->opt_kerberos
) {
4579 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4583 if (c
->display_usage
) {
4587 " Alias for net rpc share list\n");
4588 net_display_usage_from_functable(func
);
4592 return rpc_share_list(c
, argc
, argv
);
4595 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4598 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4599 TALLOC_CTX
*mem_ctx
,
4600 struct rpc_sh_ctx
*ctx
,
4601 struct rpc_pipe_client
*pipe_hnd
,
4602 int argc
, const char **argv
)
4605 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4608 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4609 TALLOC_CTX
*mem_ctx
,
4610 struct rpc_sh_ctx
*ctx
,
4611 struct rpc_pipe_client
*pipe_hnd
,
4612 int argc
, const char **argv
)
4614 NET_API_STATUS status
;
4615 uint32_t parm_err
= 0;
4616 struct SHARE_INFO_2 i2
;
4618 if ((argc
< 2) || (argc
> 3)) {
4619 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4621 return NT_STATUS_INVALID_PARAMETER
;
4624 i2
.shi2_netname
= argv
[0];
4625 i2
.shi2_type
= STYPE_DISKTREE
;
4626 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4627 i2
.shi2_permissions
= 0;
4628 i2
.shi2_max_uses
= 0;
4629 i2
.shi2_current_uses
= 0;
4630 i2
.shi2_path
= argv
[1];
4631 i2
.shi2_passwd
= NULL
;
4633 status
= NetShareAdd(pipe_hnd
->desthost
,
4638 return werror_to_ntstatus(W_ERROR(status
));
4641 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4642 TALLOC_CTX
*mem_ctx
,
4643 struct rpc_sh_ctx
*ctx
,
4644 struct rpc_pipe_client
*pipe_hnd
,
4645 int argc
, const char **argv
)
4648 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4649 return NT_STATUS_INVALID_PARAMETER
;
4652 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4655 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4656 TALLOC_CTX
*mem_ctx
,
4657 struct rpc_sh_ctx
*ctx
,
4658 struct rpc_pipe_client
*pipe_hnd
,
4659 int argc
, const char **argv
)
4661 union srvsvc_NetShareInfo info
;
4666 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4667 return NT_STATUS_INVALID_PARAMETER
;
4670 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4676 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4680 d_printf("Name: %s\n", info
.info2
->name
);
4681 d_printf("Comment: %s\n", info
.info2
->comment
);
4682 d_printf("Path: %s\n", info
.info2
->path
);
4683 d_printf("Password: %s\n", info
.info2
->password
);
4686 return werror_to_ntstatus(result
);
4689 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4690 struct rpc_sh_ctx
*ctx
)
4692 static struct rpc_sh_cmd cmds
[] = {
4694 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4695 "List available shares" },
4697 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4700 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4703 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4704 "Get information about a share" },
4706 { NULL
, NULL
, 0, NULL
, NULL
}
4712 /****************************************************************************/
4714 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4716 return net_file_usage(c
, argc
, argv
);
4720 * Close a file on a remote RPC server.
4722 * @param argc Standard main() style argc.
4723 * @param argv Standard main() style argv. Initial components are already
4726 * @return A shell status integer (0 for success).
4728 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4730 if (argc
< 1 || c
->display_usage
) {
4731 return rpc_file_usage(c
, argc
, argv
);
4734 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4738 * Formatted print of open file info
4740 * @param r struct FILE_INFO_3 contents
4743 static void display_file_info_3(struct FILE_INFO_3
*r
)
4745 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4746 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4747 r
->fi3_num_locks
, r
->fi3_pathname
);
4751 * List files for a user on a remote RPC server.
4753 * @param argc Standard main() style argc.
4754 * @param argv Standard main() style argv. Initial components are already
4757 * @return A shell status integer (0 for success)..
4760 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4762 NET_API_STATUS status
;
4763 uint32 preferred_len
= 0xffffffff, i
;
4764 const char *username
=NULL
;
4765 uint32_t total_entries
= 0;
4766 uint32_t entries_read
= 0;
4767 uint32_t resume_handle
= 0;
4768 struct FILE_INFO_3
*i3
= NULL
;
4770 if (c
->display_usage
) {
4771 return rpc_file_usage(c
, argc
, argv
);
4774 /* if argc > 0, must be user command */
4776 username
= smb_xstrdup(argv
[0]);
4779 status
= NetFileEnum(c
->opt_host
,
4783 (uint8_t **)(void *)&i3
,
4793 /* Display results */
4796 "\nEnumerating open files on remote server:\n\n"
4797 "\nFileId Opened by Perms Locks Path"
4798 "\n------ --------- ----- ----- ---- \n");
4799 for (i
= 0; i
< entries_read
; i
++) {
4800 display_file_info_3(&i3
[i
]);
4807 * 'net rpc file' entrypoint.
4808 * @param argc Standard main() style argc.
4809 * @param argv Standard main() style argv. Initial components are already
4813 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4815 NET_API_STATUS status
;
4817 struct functable func
[] = {
4822 "Close opened file",
4823 "net rpc file close\n"
4824 " Close opened file"
4830 "List files opened by user",
4831 "net rpc file user\n"
4832 " List files opened by user"
4839 "Display information about opened file",
4840 "net rpc file info\n"
4841 " Display information about opened file"
4844 {NULL
, NULL
, 0, NULL
, NULL
}
4847 status
= libnetapi_init(&c
->netapi_ctx
);
4851 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4852 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4853 if (c
->opt_kerberos
) {
4854 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4858 if (c
->display_usage
) {
4859 d_printf("Usage:\n");
4860 d_printf("net rpc file\n"
4861 " List opened files\n");
4862 net_display_usage_from_functable(func
);
4866 return rpc_file_user(c
, argc
, argv
);
4869 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4873 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4875 * All parameters are provided by the run_rpc_command function, except for
4876 * argc, argv which are passed through.
4878 * @param c A net_context structure.
4879 * @param domain_sid The domain sid acquired from the remote server.
4880 * @param cli A cli_state connected to the server.
4881 * @param mem_ctx Talloc context, destroyed on completion of the function.
4882 * @param argc Standard main() style argc.
4883 * @param argv Standard main() style argv. Initial components are already
4886 * @return Normal NTSTATUS return.
4889 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4890 const DOM_SID
*domain_sid
,
4891 const char *domain_name
,
4892 struct cli_state
*cli
,
4893 struct rpc_pipe_client
*pipe_hnd
,
4894 TALLOC_CTX
*mem_ctx
,
4898 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4900 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4902 if (NT_STATUS_IS_OK(result
)) {
4903 d_printf("\nShutdown successfully aborted\n");
4904 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4906 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4912 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
4914 * All parameters are provided by the run_rpc_command function, except for
4915 * argc, argv which are passed through.
4917 * @param c A net_context structure.
4918 * @param domain_sid The domain sid acquired from the remote server.
4919 * @param cli A cli_state connected to the server.
4920 * @param mem_ctx Talloc context, destroyed on completion of the function.
4921 * @param argc Standard main() style argc.
4922 * @param argv Standard main() style argv. Initial components are already
4925 * @return Normal NTSTATUS return.
4928 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
4929 const DOM_SID
*domain_sid
,
4930 const char *domain_name
,
4931 struct cli_state
*cli
,
4932 struct rpc_pipe_client
*pipe_hnd
,
4933 TALLOC_CTX
*mem_ctx
,
4937 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4939 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4941 if (NT_STATUS_IS_OK(result
)) {
4942 d_printf("\nShutdown successfully aborted\n");
4943 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4945 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
4951 * ABORT the shutdown of a remote RPC server.
4953 * @param argc Standard main() style argc.
4954 * @param argv Standard main() style argv. Initial components are already
4957 * @return A shell status integer (0 for success).
4960 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
4965 if (c
->display_usage
) {
4967 "net rpc abortshutdown\n"
4968 " Abort a scheduled shutdown\n");
4972 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
4973 rpc_shutdown_abort_internals
, argc
, argv
);
4978 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
4980 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
4981 rpc_reg_shutdown_abort_internals
,
4986 * Shut down a remote RPC Server via initshutdown pipe.
4988 * All parameters are provided by the run_rpc_command function, except for
4989 * argc, argv which are passed through.
4991 * @param c A net_context structure.
4992 * @param domain_sid The domain sid acquired from the remote server.
4993 * @param cli A cli_state connected to the server.
4994 * @param mem_ctx Talloc context, destroyed on completion of the function.
4995 * @param argc Standard main() style argc.
4996 * @param argv Standard main() style argv. Initial components are already
4999 * @return Normal NTSTATUS return.
5002 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5003 const DOM_SID
*domain_sid
,
5004 const char *domain_name
,
5005 struct cli_state
*cli
,
5006 struct rpc_pipe_client
*pipe_hnd
,
5007 TALLOC_CTX
*mem_ctx
,
5011 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5012 const char *msg
= "This machine will be shutdown shortly";
5013 uint32 timeout
= 20;
5014 struct initshutdown_String msg_string
;
5015 struct initshutdown_String_sub s
;
5017 if (c
->opt_comment
) {
5018 msg
= c
->opt_comment
;
5020 if (c
->opt_timeout
) {
5021 timeout
= c
->opt_timeout
;
5025 msg_string
.name
= &s
;
5027 /* create an entry */
5028 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5029 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5032 if (NT_STATUS_IS_OK(result
)) {
5033 d_printf("\nShutdown of remote machine succeeded\n");
5034 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5036 DEBUG(1,("Shutdown of remote machine failed!\n"));
5042 * Shut down a remote RPC Server via winreg pipe.
5044 * All parameters are provided by the run_rpc_command function, except for
5045 * argc, argv which are passed through.
5047 * @param c A net_context structure.
5048 * @param domain_sid The domain sid acquired from the remote server.
5049 * @param cli A cli_state connected to the server.
5050 * @param mem_ctx Talloc context, destroyed on completion of the function.
5051 * @param argc Standard main() style argc.
5052 * @param argv Standard main() style argv. Initial components are already
5055 * @return Normal NTSTATUS return.
5058 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5059 const DOM_SID
*domain_sid
,
5060 const char *domain_name
,
5061 struct cli_state
*cli
,
5062 struct rpc_pipe_client
*pipe_hnd
,
5063 TALLOC_CTX
*mem_ctx
,
5067 const char *msg
= "This machine will be shutdown shortly";
5068 uint32 timeout
= 20;
5069 struct initshutdown_String msg_string
;
5070 struct initshutdown_String_sub s
;
5074 if (c
->opt_comment
) {
5075 msg
= c
->opt_comment
;
5078 msg_string
.name
= &s
;
5080 if (c
->opt_timeout
) {
5081 timeout
= c
->opt_timeout
;
5084 /* create an entry */
5085 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5086 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5089 if (NT_STATUS_IS_OK(result
)) {
5090 d_printf("\nShutdown of remote machine succeeded\n");
5092 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5093 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5094 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5096 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(werr
));
5103 * Shut down a remote RPC server.
5105 * @param argc Standard main() style argc.
5106 * @param argv Standard main() style argv. Initial components are already
5109 * @return A shell status integer (0 for success).
5112 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5116 if (c
->display_usage
) {
5118 "net rpc shutdown\n"
5119 " Shut down a remote RPC server\n");
5123 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5124 rpc_init_shutdown_internals
, argc
, argv
);
5127 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5128 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5129 rpc_reg_shutdown_internals
, argc
, argv
);
5135 /***************************************************************************
5136 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5137 ***************************************************************************/
5140 * Add interdomain trust account to the RPC server.
5141 * All parameters (except for argc and argv) are passed by run_rpc_command
5144 * @param c A net_context structure.
5145 * @param domain_sid The domain sid acquired from the server.
5146 * @param cli A cli_state connected to the server.
5147 * @param mem_ctx Talloc context, destroyed on completion of the function.
5148 * @param argc Standard main() style argc.
5149 * @param argv Standard main() style argv. Initial components are already
5152 * @return normal NTSTATUS return code.
5155 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5156 const DOM_SID
*domain_sid
,
5157 const char *domain_name
,
5158 struct cli_state
*cli
,
5159 struct rpc_pipe_client
*pipe_hnd
,
5160 TALLOC_CTX
*mem_ctx
,
5164 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5165 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5167 struct lsa_String lsa_acct_name
;
5169 uint32 acct_flags
=0;
5171 uint32_t access_granted
= 0;
5172 union samr_UserInfo info
;
5173 unsigned int orig_timeout
;
5176 d_printf("Usage: net rpc trustdom add <domain_name> "
5177 "<trust password>\n");
5178 return NT_STATUS_INVALID_PARAMETER
;
5182 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5185 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5186 return NT_STATUS_NO_MEMORY
;
5189 strupper_m(acct_name
);
5191 init_lsa_String(&lsa_acct_name
, acct_name
);
5193 /* Get samr policy handle */
5194 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5196 MAXIMUM_ALLOWED_ACCESS
,
5198 if (!NT_STATUS_IS_OK(result
)) {
5202 /* Get domain policy handle */
5203 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5205 MAXIMUM_ALLOWED_ACCESS
,
5206 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5208 if (!NT_STATUS_IS_OK(result
)) {
5212 /* This call can take a long time - allow the server to time out.
5213 * 35 seconds should do it. */
5215 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5217 /* Create trusting domain's account */
5218 acb_info
= ACB_NORMAL
;
5219 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5220 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5221 SAMR_USER_ACCESS_SET_PASSWORD
|
5222 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5223 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5225 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5234 /* And restore our original timeout. */
5235 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5237 if (!NT_STATUS_IS_OK(result
)) {
5238 d_printf("net rpc trustdom add: create user %s failed %s\n",
5239 acct_name
, nt_errstr(result
));
5245 struct samr_LogonHours hours
;
5246 struct lsa_BinaryString parameters
;
5247 const int units_per_week
= 168;
5248 struct samr_CryptPassword crypt_pwd
;
5250 ZERO_STRUCT(notime
);
5252 ZERO_STRUCT(parameters
);
5254 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
5256 result
= NT_STATUS_NO_MEMORY
;
5259 hours
.units_per_week
= units_per_week
;
5260 memset(hours
.bits
, 0xFF, units_per_week
);
5262 init_samr_CryptPassword(argv
[1],
5263 &cli
->user_session_key
,
5266 init_samr_user_info23(&info
.info23
,
5267 notime
, notime
, notime
,
5268 notime
, notime
, notime
,
5269 NULL
, NULL
, NULL
, NULL
, NULL
,
5270 NULL
, NULL
, NULL
, NULL
, ¶meters
,
5272 SAMR_FIELD_ACCT_FLAGS
| SAMR_FIELD_NT_PASSWORD_PRESENT
,
5274 0, 0, 0, 0, 0, 0, 0,
5277 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5282 if (!NT_STATUS_IS_OK(result
)) {
5283 DEBUG(0,("Could not set trust account password: %s\n",
5284 nt_errstr(result
)));
5290 SAFE_FREE(acct_name
);
5295 * Create interdomain trust account for a remote domain.
5297 * @param argc Standard argc.
5298 * @param argv Standard argv without initial components.
5300 * @return Integer status (0 means success).
5303 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5305 if (argc
> 0 && !c
->display_usage
) {
5306 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5307 rpc_trustdom_add_internals
, argc
, argv
);
5310 "net rpc trustdom add <domain_name> <trust password>\n");
5317 * Remove interdomain trust account from the RPC server.
5318 * All parameters (except for argc and argv) are passed by run_rpc_command
5321 * @param c A net_context structure.
5322 * @param domain_sid The domain sid acquired from the server.
5323 * @param cli A cli_state connected to the server.
5324 * @param mem_ctx Talloc context, destroyed on completion of the function.
5325 * @param argc Standard main() style argc.
5326 * @param argv Standard main() style argv. Initial components are already
5329 * @return normal NTSTATUS return code.
5332 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5333 const DOM_SID
*domain_sid
,
5334 const char *domain_name
,
5335 struct cli_state
*cli
,
5336 struct rpc_pipe_client
*pipe_hnd
,
5337 TALLOC_CTX
*mem_ctx
,
5341 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5342 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5344 DOM_SID trust_acct_sid
;
5345 struct samr_Ids user_rids
, name_types
;
5346 struct lsa_String lsa_acct_name
;
5349 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5350 return NT_STATUS_INVALID_PARAMETER
;
5354 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5356 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5358 if (acct_name
== NULL
)
5359 return NT_STATUS_NO_MEMORY
;
5361 strupper_m(acct_name
);
5363 /* Get samr policy handle */
5364 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5366 MAXIMUM_ALLOWED_ACCESS
,
5368 if (!NT_STATUS_IS_OK(result
)) {
5372 /* Get domain policy handle */
5373 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5375 MAXIMUM_ALLOWED_ACCESS
,
5376 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5378 if (!NT_STATUS_IS_OK(result
)) {
5382 init_lsa_String(&lsa_acct_name
, acct_name
);
5384 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5391 if (!NT_STATUS_IS_OK(result
)) {
5392 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5393 acct_name
, nt_errstr(result
) );
5397 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5399 MAXIMUM_ALLOWED_ACCESS
,
5403 if (!NT_STATUS_IS_OK(result
)) {
5404 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5405 acct_name
, nt_errstr(result
) );
5409 /* append the rid to the domain sid */
5410 sid_copy(&trust_acct_sid
, domain_sid
);
5411 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5415 /* remove the sid */
5417 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5420 if (!NT_STATUS_IS_OK(result
)) {
5421 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5422 acct_name
, nt_errstr(result
) );
5428 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5431 if (!NT_STATUS_IS_OK(result
)) {
5432 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5433 acct_name
, nt_errstr(result
) );
5437 if (!NT_STATUS_IS_OK(result
)) {
5438 d_printf("Could not set trust account password: %s\n",
5448 * Delete interdomain trust account for a remote domain.
5450 * @param argc Standard argc.
5451 * @param argv Standard argv without initial components.
5453 * @return Integer status (0 means success).
5456 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5458 if (argc
> 0 && !c
->display_usage
) {
5459 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5460 rpc_trustdom_del_internals
, argc
, argv
);
5463 "net rpc trustdom del <domain>\n");
5468 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5469 struct cli_state
*cli
,
5470 TALLOC_CTX
*mem_ctx
,
5471 const char *domain_name
)
5473 char *dc_name
= NULL
;
5474 const char *buffer
= NULL
;
5475 struct rpc_pipe_client
*netr
;
5478 /* Use NetServerEnum2 */
5480 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5482 return NT_STATUS_OK
;
5485 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5486 for domain %s\n", domain_name
));
5488 /* Try netr_GetDcName */
5490 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5492 if (!NT_STATUS_IS_OK(status
)) {
5496 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5503 if (NT_STATUS_IS_OK(status
)) {
5507 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5508 for domain %s\n", domain_name
));
5514 * Establish trust relationship to a trusting domain.
5515 * Interdomain account must already be created on remote PDC.
5517 * @param c A net_context structure.
5518 * @param argc Standard argc.
5519 * @param argv Standard argv without initial components.
5521 * @return Integer status (0 means success).
5524 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5527 struct cli_state
*cli
= NULL
;
5528 struct sockaddr_storage server_ss
;
5529 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5530 POLICY_HND connect_hnd
;
5531 TALLOC_CTX
*mem_ctx
;
5533 DOM_SID
*domain_sid
;
5538 union lsa_PolicyInformation
*info
= NULL
;
5541 * Connect to \\server\ipc$ as 'our domain' account with password
5544 if (argc
!= 1 || c
->display_usage
) {
5546 "net rpc trustdom establish <domain_name>\n");
5550 domain_name
= smb_xstrdup(argv
[0]);
5551 strupper_m(domain_name
);
5553 /* account name used at first is our domain's name with '$' */
5554 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5557 strupper_m(acct_name
);
5560 * opt_workgroup will be used by connection functions further,
5561 * hence it should be set to remote domain name instead of ours
5563 if (c
->opt_workgroup
) {
5564 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5567 c
->opt_user_name
= acct_name
;
5569 /* find the domain controller */
5570 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5571 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5575 /* connect to ipc$ as username/password */
5576 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5577 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5579 /* Is it trusting domain account for sure ? */
5580 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5581 nt_errstr(nt_status
)));
5585 /* store who we connected to */
5587 saf_store( domain_name
, pdc_name
);
5590 * Connect to \\server\ipc$ again (this time anonymously)
5593 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5596 if (NT_STATUS_IS_ERR(nt_status
)) {
5597 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5598 domain_name
, nt_errstr(nt_status
)));
5602 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5603 "domain %s", domain_name
))) {
5604 DEBUG(0, ("talloc_init() failed\n"));
5609 /* Make sure we're talking to a proper server */
5611 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5612 if (!NT_STATUS_IS_OK(nt_status
)) {
5614 talloc_destroy(mem_ctx
);
5619 * Call LsaOpenPolicy and LsaQueryInfo
5622 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5624 if (!NT_STATUS_IS_OK(nt_status
)) {
5625 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5627 talloc_destroy(mem_ctx
);
5631 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, SEC_RIGHTS_QUERY_VALUE
,
5633 if (NT_STATUS_IS_ERR(nt_status
)) {
5634 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5635 nt_errstr(nt_status
)));
5637 talloc_destroy(mem_ctx
);
5641 /* Querying info level 5 */
5643 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5645 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5647 if (NT_STATUS_IS_ERR(nt_status
)) {
5648 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5649 nt_errstr(nt_status
)));
5651 talloc_destroy(mem_ctx
);
5655 domain_sid
= info
->account_domain
.sid
;
5657 /* There should be actually query info level 3 (following nt serv behaviour),
5658 but I still don't know if it's _really_ necessary */
5661 * Store the password in secrets db
5664 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5665 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5667 talloc_destroy(mem_ctx
);
5672 * Close the pipes and clean up
5675 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5676 if (NT_STATUS_IS_ERR(nt_status
)) {
5677 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5678 nt_errstr(nt_status
)));
5680 talloc_destroy(mem_ctx
);
5686 talloc_destroy(mem_ctx
);
5688 d_printf("Trust to domain %s established\n", domain_name
);
5693 * Revoke trust relationship to the remote domain.
5695 * @param c A net_context structure.
5696 * @param argc Standard argc.
5697 * @param argv Standard argv without initial components.
5699 * @return Integer status (0 means success).
5702 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5708 if (argc
< 1 || c
->display_usage
) {
5710 "net rpc trustdom revoke <domain_name>\n"
5711 " Revoke trust relationship\n"
5712 " domain_name\tName of domain to revoke trust\n");
5716 /* generate upper cased domain name */
5717 domain_name
= smb_xstrdup(argv
[0]);
5718 strupper_m(domain_name
);
5720 /* delete password of the trust */
5721 if (!pdb_del_trusteddom_pw(domain_name
)) {
5722 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5729 SAFE_FREE(domain_name
);
5733 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5734 const DOM_SID
*domain_sid
,
5735 const char *domain_name
,
5736 struct cli_state
*cli
,
5737 struct rpc_pipe_client
*pipe_hnd
,
5738 TALLOC_CTX
*mem_ctx
,
5743 sid_to_fstring(str_sid
, domain_sid
);
5744 d_printf("%s\n", str_sid
);
5745 return NT_STATUS_OK
;
5748 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5750 fstring ascii_sid
, padding
;
5751 int pad_len
, col_len
= 20;
5753 /* convert sid into ascii string */
5754 sid_to_fstring(ascii_sid
, dom_sid
);
5756 /* calculate padding space for d_printf to look nicer */
5757 pad_len
= col_len
- strlen(trusted_dom_name
);
5758 padding
[pad_len
] = 0;
5759 do padding
[--pad_len
] = ' '; while (pad_len
);
5761 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5764 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5765 TALLOC_CTX
*mem_ctx
,
5768 const char *trusted_dom_name
)
5771 union lsa_TrustedDomainInfo
*info
= NULL
;
5772 char *cleartextpwd
= NULL
;
5773 uint8_t nt_hash
[16];
5774 DATA_BLOB data
= data_blob_null
;
5776 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5779 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5781 if (NT_STATUS_IS_ERR(nt_status
)) {
5782 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5783 nt_errstr(nt_status
)));
5787 data
= data_blob(info
->password
.password
->data
,
5788 info
->password
.password
->length
);
5790 if (!rpccli_get_pwd_hash(pipe_hnd
, nt_hash
)) {
5791 DEBUG(0, ("Could not retrieve password hash\n"));
5795 cleartextpwd
= decrypt_trustdom_secret(nt_hash
, &data
);
5797 if (cleartextpwd
== NULL
) {
5798 DEBUG(0,("retrieved NULL password\n"));
5799 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5803 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5804 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5805 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5809 #ifdef DEBUG_PASSWORD
5810 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5811 "password: [%s]\n", trusted_dom_name
,
5812 sid_string_dbg(&dom_sid
), cleartextpwd
));
5816 SAFE_FREE(cleartextpwd
);
5817 data_blob_free(&data
);
5822 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5825 /* common variables */
5826 TALLOC_CTX
* mem_ctx
;
5827 struct cli_state
*cli
= NULL
;
5828 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5830 const char *domain_name
= NULL
;
5831 DOM_SID
*queried_dom_sid
;
5832 POLICY_HND connect_hnd
;
5833 union lsa_PolicyInformation
*info
= NULL
;
5835 /* trusted domains listing variables */
5836 unsigned int enum_ctx
= 0;
5838 struct lsa_DomainList dom_list
;
5841 if (c
->display_usage
) {
5843 "net rpc trustdom vampire\n"
5844 " Vampire trust relationship from remote server\n");
5849 * Listing trusted domains (stored in secrets.tdb, if local)
5852 mem_ctx
= talloc_init("trust relationships vampire");
5855 * set domain and pdc name to local samba server (default)
5856 * or to remote one given in command line
5859 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5860 domain_name
= c
->opt_workgroup
;
5861 c
->opt_target_workgroup
= c
->opt_workgroup
;
5863 fstrcpy(pdc_name
, global_myname());
5864 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5865 c
->opt_target_workgroup
= domain_name
;
5868 /* open \PIPE\lsarpc and open policy handle */
5869 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5870 if (!NT_STATUS_IS_OK(nt_status
)) {
5871 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5872 nt_errstr(nt_status
)));
5873 talloc_destroy(mem_ctx
);
5877 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5879 if (!NT_STATUS_IS_OK(nt_status
)) {
5880 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5881 nt_errstr(nt_status
) ));
5883 talloc_destroy(mem_ctx
);
5887 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
5889 if (NT_STATUS_IS_ERR(nt_status
)) {
5890 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5891 nt_errstr(nt_status
)));
5893 talloc_destroy(mem_ctx
);
5897 /* query info level 5 to obtain sid of a domain being queried */
5898 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5900 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5903 if (NT_STATUS_IS_ERR(nt_status
)) {
5904 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5905 nt_errstr(nt_status
)));
5907 talloc_destroy(mem_ctx
);
5911 queried_dom_sid
= info
->account_domain
.sid
;
5914 * Keep calling LsaEnumTrustdom over opened pipe until
5915 * the end of enumeration is reached
5918 d_printf("Vampire trusted domains:\n\n");
5921 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
5926 if (NT_STATUS_IS_ERR(nt_status
)) {
5927 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5928 nt_errstr(nt_status
)));
5930 talloc_destroy(mem_ctx
);
5934 for (i
= 0; i
< dom_list
.count
; i
++) {
5936 print_trusted_domain(dom_list
.domains
[i
].sid
,
5937 dom_list
.domains
[i
].name
.string
);
5939 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5940 *dom_list
.domains
[i
].sid
,
5941 dom_list
.domains
[i
].name
.string
);
5942 if (!NT_STATUS_IS_OK(nt_status
)) {
5944 talloc_destroy(mem_ctx
);
5950 * in case of no trusted domains say something rather
5951 * than just display blank line
5953 if (!dom_list
.count
) d_printf("none\n");
5955 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5957 /* close this connection before doing next one */
5958 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5959 if (NT_STATUS_IS_ERR(nt_status
)) {
5960 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5961 nt_errstr(nt_status
)));
5963 talloc_destroy(mem_ctx
);
5967 /* close lsarpc pipe and connection to IPC$ */
5970 talloc_destroy(mem_ctx
);
5974 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
5976 /* common variables */
5977 TALLOC_CTX
* mem_ctx
;
5978 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5979 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5981 const char *domain_name
= NULL
;
5982 DOM_SID
*queried_dom_sid
;
5984 int ascii_dom_name_len
;
5985 POLICY_HND connect_hnd
;
5986 union lsa_PolicyInformation
*info
= NULL
;
5988 /* trusted domains listing variables */
5989 unsigned int num_domains
, enum_ctx
= 0;
5990 int i
, pad_len
, col_len
= 20;
5991 struct lsa_DomainList dom_list
;
5995 /* trusting domains listing variables */
5996 POLICY_HND domain_hnd
;
5997 struct samr_SamArray
*trusts
= NULL
;
5999 if (c
->display_usage
) {
6001 "net rpc trustdom list\n"
6002 " List trust relationships\n");
6007 * Listing trusted domains (stored in secrets.tdb, if local)
6010 mem_ctx
= talloc_init("trust relationships listing");
6013 * set domain and pdc name to local samba server (default)
6014 * or to remote one given in command line
6017 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6018 domain_name
= c
->opt_workgroup
;
6019 c
->opt_target_workgroup
= c
->opt_workgroup
;
6021 fstrcpy(pdc_name
, global_myname());
6022 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6023 c
->opt_target_workgroup
= domain_name
;
6026 /* open \PIPE\lsarpc and open policy handle */
6027 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6028 if (!NT_STATUS_IS_OK(nt_status
)) {
6029 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6030 nt_errstr(nt_status
)));
6031 talloc_destroy(mem_ctx
);
6035 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6037 if (!NT_STATUS_IS_OK(nt_status
)) {
6038 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6039 nt_errstr(nt_status
) ));
6041 talloc_destroy(mem_ctx
);
6045 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
6047 if (NT_STATUS_IS_ERR(nt_status
)) {
6048 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6049 nt_errstr(nt_status
)));
6051 talloc_destroy(mem_ctx
);
6055 /* query info level 5 to obtain sid of a domain being queried */
6056 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6058 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6061 if (NT_STATUS_IS_ERR(nt_status
)) {
6062 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6063 nt_errstr(nt_status
)));
6065 talloc_destroy(mem_ctx
);
6069 queried_dom_sid
= info
->account_domain
.sid
;
6072 * Keep calling LsaEnumTrustdom over opened pipe until
6073 * the end of enumeration is reached
6076 d_printf("Trusted domains list:\n\n");
6078 found_domain
= false;
6081 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6086 if (NT_STATUS_IS_ERR(nt_status
)) {
6087 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6088 nt_errstr(nt_status
)));
6090 talloc_destroy(mem_ctx
);
6094 for (i
= 0; i
< dom_list
.count
; i
++) {
6095 print_trusted_domain(dom_list
.domains
[i
].sid
,
6096 dom_list
.domains
[i
].name
.string
);
6097 found_domain
= true;
6100 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6103 * in case of no trusted domains say something rather
6104 * than just display blank line
6106 if (!found_domain
) {
6110 /* close this connection before doing next one */
6111 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6112 if (NT_STATUS_IS_ERR(nt_status
)) {
6113 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6114 nt_errstr(nt_status
)));
6116 talloc_destroy(mem_ctx
);
6120 TALLOC_FREE(pipe_hnd
);
6123 * Listing trusting domains (stored in passdb backend, if local)
6126 d_printf("\nTrusting domains list:\n\n");
6129 * Open \PIPE\samr and get needed policy handles
6131 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6133 if (!NT_STATUS_IS_OK(nt_status
)) {
6134 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6136 talloc_destroy(mem_ctx
);
6141 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6143 SAMR_ACCESS_LOOKUP_DOMAIN
,
6145 if (!NT_STATUS_IS_OK(nt_status
)) {
6146 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6147 nt_errstr(nt_status
)));
6149 talloc_destroy(mem_ctx
);
6153 /* SamrOpenDomain - we have to open domain policy handle in order to be
6154 able to enumerate accounts*/
6155 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6157 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6160 if (!NT_STATUS_IS_OK(nt_status
)) {
6161 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6162 nt_errstr(nt_status
)));
6164 talloc_destroy(mem_ctx
);
6169 * perform actual enumeration
6172 found_domain
= false;
6174 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6177 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6184 if (NT_STATUS_IS_ERR(nt_status
)) {
6185 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6186 nt_errstr(nt_status
)));
6188 talloc_destroy(mem_ctx
);
6192 for (i
= 0; i
< num_domains
; i
++) {
6194 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6196 found_domain
= true;
6199 * get each single domain's sid (do we _really_ need this ?):
6200 * 1) connect to domain's pdc
6201 * 2) query the pdc for domain's sid
6204 /* get rid of '$' tail */
6205 ascii_dom_name_len
= strlen(str
);
6206 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6207 str
[ascii_dom_name_len
- 1] = '\0';
6209 /* calculate padding space for d_printf to look nicer */
6210 pad_len
= col_len
- strlen(str
);
6211 padding
[pad_len
] = 0;
6212 do padding
[--pad_len
] = ' '; while (pad_len
);
6214 /* set opt_* variables to remote domain */
6216 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6217 c
->opt_target_workgroup
= c
->opt_workgroup
;
6219 d_printf("%s%s", str
, padding
);
6221 /* connect to remote domain controller */
6222 nt_status
= net_make_ipc_connection(c
,
6223 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6225 if (NT_STATUS_IS_OK(nt_status
)) {
6226 /* query for domain's sid */
6227 if (run_rpc_command(
6229 &ndr_table_lsarpc
.syntax_id
, 0,
6230 rpc_query_domain_sid
, argc
,
6232 d_fprintf(stderr
, "couldn't get domain's sid\n");
6234 cli_shutdown(remote_cli
);
6237 d_fprintf(stderr
, "domain controller is not "
6239 nt_errstr(nt_status
));
6243 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6245 if (!found_domain
) {
6249 /* close opened samr and domain policy handles */
6250 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6251 if (!NT_STATUS_IS_OK(nt_status
)) {
6252 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6255 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6256 if (!NT_STATUS_IS_OK(nt_status
)) {
6257 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6260 /* close samr pipe and connection to IPC$ */
6263 talloc_destroy(mem_ctx
);
6268 * Entrypoint for 'net rpc trustdom' code.
6270 * @param argc Standard argc.
6271 * @param argv Standard argv without initial components.
6273 * @return Integer status (0 means success).
6276 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6278 struct functable func
[] = {
6283 "Add trusted domain's account",
6284 "net rpc trustdom add\n"
6285 " Add trusted domain's account"
6291 "Remove trusted domain's account",
6292 "net rpc trustdom del\n"
6293 " Remove trusted domain's account"
6297 rpc_trustdom_establish
,
6299 "Establish trust relationship",
6300 "net rpc trustdom establish\n"
6301 " Establish trust relationship"
6305 rpc_trustdom_revoke
,
6307 "Revoke trust relationship",
6308 "net rpc trustdom revoke\n"
6309 " Revoke trust relationship"
6315 "List domain trusts",
6316 "net rpc trustdom list\n"
6317 " List domain trusts"
6321 rpc_trustdom_vampire
,
6323 "Vampire trusts from remote server",
6324 "net rpc trustdom vampire\n"
6325 " Vampire trusts from remote server"
6327 {NULL
, NULL
, 0, NULL
, NULL
}
6330 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6334 * Check if a server will take rpc commands
6335 * @param flags Type of server to connect to (PDC, DMB, localhost)
6336 * if the host is not explicitly specified
6337 * @return bool (true means rpc supported)
6339 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6341 struct cli_state
*cli
;
6343 struct sockaddr_storage server_ss
;
6344 char *server_name
= NULL
;
6347 /* flags (i.e. server type) may depend on command */
6348 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6351 if ((cli
= cli_initialise()) == NULL
) {
6355 status
= cli_connect(cli
, server_name
, &server_ss
);
6356 if (!NT_STATUS_IS_OK(status
))
6358 if (!attempt_netbios_session_request(&cli
, global_myname(),
6359 server_name
, &server_ss
))
6361 if (!cli_negprot(cli
))
6363 if (cli
->protocol
< PROTOCOL_NT1
)
6372 /* dump sam database via samsync rpc calls */
6373 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6374 if (c
->display_usage
) {
6377 " Dump remote SAM database\n");
6381 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6382 NET_FLAGS_ANONYMOUS
,
6383 rpc_samdump_internals
, argc
, argv
);
6386 /* syncronise sam database via samsync rpc calls */
6387 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6389 struct functable func
[] = {
6394 "Dump remote SAM database to ldif",
6395 "net rpc vampire ldif\n"
6396 " Dump remote SAM database to LDIF file or stdout"
6402 "Dump remote SAM database to Kerberos Keytab",
6403 "net rpc vampire keytab\n"
6404 " Dump remote SAM database to Kerberos keytab file"
6410 "Dump remote SAM database to passdb",
6411 "net rpc vampire passdb\n"
6412 " Dump remote SAM database to passdb"
6415 {NULL
, NULL
, 0, NULL
, NULL
}
6419 if (c
->display_usage
) {
6422 " Vampire remote SAM database\n");
6426 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6427 NET_FLAGS_ANONYMOUS
,
6428 rpc_vampire_internals
,
6432 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6436 * Migrate everything from a print server.
6438 * @param c A net_context structure.
6439 * @param argc Standard main() style argc.
6440 * @param argv Standard main() style argv. Initial components are already
6443 * @return A shell status integer (0 for success).
6445 * The order is important !
6446 * To successfully add drivers the print queues have to exist !
6447 * Applying ACLs should be the last step, because you're easily locked out.
6450 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6455 if (c
->display_usage
) {
6457 "net rpc printer migrate all\n"
6458 " Migrate everything from a print server\n");
6463 d_printf("no server to migrate\n");
6467 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6468 rpc_printer_migrate_printers_internals
, argc
,
6473 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6474 rpc_printer_migrate_drivers_internals
, argc
,
6479 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6480 rpc_printer_migrate_forms_internals
, argc
, argv
);
6484 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6485 rpc_printer_migrate_settings_internals
, argc
,
6490 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6491 rpc_printer_migrate_security_internals
, argc
,
6497 * Migrate print drivers from a print server.
6499 * @param c A net_context structure.
6500 * @param argc Standard main() style argc.
6501 * @param argv Standard main() style argv. Initial components are already
6504 * @return A shell status integer (0 for success).
6506 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6509 if (c
->display_usage
) {
6511 "net rpc printer migrate drivers\n"
6512 " Migrate print-drivers from a print-server\n");
6517 d_printf("no server to migrate\n");
6521 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6522 rpc_printer_migrate_drivers_internals
,
6527 * Migrate print-forms from a print-server.
6529 * @param c A net_context structure.
6530 * @param argc Standard main() style argc.
6531 * @param argv Standard main() style argv. Initial components are already
6534 * @return A shell status integer (0 for success).
6536 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6539 if (c
->display_usage
) {
6541 "net rpc printer migrate forms\n"
6542 " Migrate print-forms from a print-server\n");
6547 d_printf("no server to migrate\n");
6551 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6552 rpc_printer_migrate_forms_internals
,
6557 * Migrate printers from a print-server.
6559 * @param c A net_context structure.
6560 * @param argc Standard main() style argc.
6561 * @param argv Standard main() style argv. Initial components are already
6564 * @return A shell status integer (0 for success).
6566 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6569 if (c
->display_usage
) {
6571 "net rpc printer migrate printers\n"
6572 " Migrate printers from a print-server\n");
6577 d_printf("no server to migrate\n");
6581 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6582 rpc_printer_migrate_printers_internals
,
6587 * Migrate printer-ACLs from a print-server
6589 * @param c A net_context structure.
6590 * @param argc Standard main() style argc.
6591 * @param argv Standard main() style argv. Initial components are already
6594 * @return A shell status integer (0 for success).
6596 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6599 if (c
->display_usage
) {
6601 "net rpc printer migrate security\n"
6602 " Migrate printer-ACLs from a print-server\n");
6607 d_printf("no server to migrate\n");
6611 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6612 rpc_printer_migrate_security_internals
,
6617 * Migrate printer-settings from a print-server.
6619 * @param c A net_context structure.
6620 * @param argc Standard main() style argc.
6621 * @param argv Standard main() style argv. Initial components are already
6624 * @return A shell status integer (0 for success).
6626 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6629 if (c
->display_usage
) {
6631 "net rpc printer migrate settings\n"
6632 " Migrate printer-settings from a print-server\n");
6637 d_printf("no server to migrate\n");
6641 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6642 rpc_printer_migrate_settings_internals
,
6647 * 'net rpc printer' entrypoint.
6649 * @param c A net_context structure.
6650 * @param argc Standard main() style argc.
6651 * @param argv Standard main() style argv. Initial components are already
6655 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6658 /* ouch: when addriver and setdriver are called from within
6659 rpc_printer_migrate_drivers_internals, the printer-queue already
6662 struct functable func
[] = {
6665 rpc_printer_migrate_all
,
6667 "Migrate all from remote to local print server",
6668 "net rpc printer migrate all\n"
6669 " Migrate all from remote to local print server"
6673 rpc_printer_migrate_drivers
,
6675 "Migrate drivers to local server",
6676 "net rpc printer migrate drivers\n"
6677 " Migrate drivers to local server"
6681 rpc_printer_migrate_forms
,
6683 "Migrate froms to local server",
6684 "net rpc printer migrate forms\n"
6685 " Migrate froms to local server"
6689 rpc_printer_migrate_printers
,
6691 "Migrate printers to local server",
6692 "net rpc printer migrate printers\n"
6693 " Migrate printers to local server"
6697 rpc_printer_migrate_security
,
6699 "Mirgate printer ACLs to local server",
6700 "net rpc printer migrate security\n"
6701 " Mirgate printer ACLs to local server"
6705 rpc_printer_migrate_settings
,
6707 "Migrate printer settings to local server",
6708 "net rpc printer migrate settings\n"
6709 " Migrate printer settings to local server"
6711 {NULL
, NULL
, 0, NULL
, NULL
}
6714 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6719 * List printers on a remote RPC server.
6721 * @param c A net_context structure.
6722 * @param argc Standard main() style argc.
6723 * @param argv Standard main() style argv. Initial components are already
6726 * @return A shell status integer (0 for success).
6728 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6730 if (c
->display_usage
) {
6732 "net rpc printer list\n"
6733 " List printers on a remote RPC server\n");
6737 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6738 rpc_printer_list_internals
,
6743 * List printer-drivers on a remote RPC server.
6745 * @param c A net_context structure.
6746 * @param argc Standard main() style argc.
6747 * @param argv Standard main() style argv. Initial components are already
6750 * @return A shell status integer (0 for success).
6752 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6755 if (c
->display_usage
) {
6757 "net rpc printer driver\n"
6758 " List printer-drivers on a remote RPC server\n");
6762 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6763 rpc_printer_driver_list_internals
,
6768 * Publish printer in ADS via MSRPC.
6770 * @param c A net_context structure.
6771 * @param argc Standard main() style argc.
6772 * @param argv Standard main() style argv. Initial components are already
6775 * @return A shell status integer (0 for success).
6777 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6780 if (c
->display_usage
) {
6782 "net rpc printer publish publish\n"
6783 " Publish printer in ADS via MSRPC\n");
6787 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6788 rpc_printer_publish_publish_internals
,
6793 * Update printer in ADS via MSRPC.
6795 * @param c A net_context structure.
6796 * @param argc Standard main() style argc.
6797 * @param argv Standard main() style argv. Initial components are already
6800 * @return A shell status integer (0 for success).
6802 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6804 if (c
->display_usage
) {
6806 "net rpc printer publish update\n"
6807 " Update printer in ADS via MSRPC\n");
6811 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6812 rpc_printer_publish_update_internals
,
6817 * UnPublish printer in ADS via MSRPC.
6819 * @param c A net_context structure.
6820 * @param argc Standard main() style argc.
6821 * @param argv Standard main() style argv. Initial components are already
6824 * @return A shell status integer (0 for success).
6826 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6829 if (c
->display_usage
) {
6831 "net rpc printer publish unpublish\n"
6832 " UnPublish printer in ADS via MSRPC\n");
6836 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6837 rpc_printer_publish_unpublish_internals
,
6842 * List published printers via MSRPC.
6844 * @param c A net_context structure.
6845 * @param argc Standard main() style argc.
6846 * @param argv Standard main() style argv. Initial components are already
6849 * @return A shell status integer (0 for success).
6851 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6854 if (c
->display_usage
) {
6856 "net rpc printer publish list\n"
6857 " List published printers via MSRPC\n");
6861 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6862 rpc_printer_publish_list_internals
,
6868 * Publish printer in ADS.
6870 * @param c A net_context structure.
6871 * @param argc Standard main() style argc.
6872 * @param argv Standard main() style argv. Initial components are already
6875 * @return A shell status integer (0 for success).
6877 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6881 struct functable func
[] = {
6884 rpc_printer_publish_publish
,
6886 "Publish printer in AD",
6887 "net rpc printer publish publish\n"
6888 " Publish printer in AD"
6892 rpc_printer_publish_update
,
6894 "Update printer in AD",
6895 "net rpc printer publish update\n"
6896 " Update printer in AD"
6900 rpc_printer_publish_unpublish
,
6902 "Unpublish printer",
6903 "net rpc printer publish unpublish\n"
6904 " Unpublish printer"
6908 rpc_printer_publish_list
,
6910 "List published printers",
6911 "net rpc printer publish list\n"
6912 " List published printers"
6914 {NULL
, NULL
, 0, NULL
, NULL
}
6918 if (c
->display_usage
) {
6919 d_printf("Usage:\n");
6920 d_printf("net rpc printer publish\n"
6921 " List published printers\n"
6922 " Alias of net rpc printer publish list\n");
6923 net_display_usage_from_functable(func
);
6926 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6927 rpc_printer_publish_list_internals
,
6931 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
6937 * Display rpc printer help page.
6939 * @param c A net_context structure.
6940 * @param argc Standard main() style argc.
6941 * @param argv Standard main() style argv. Initial components are already
6944 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
6946 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
6947 "\tlists all printers on print-server\n\n");
6948 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
6949 "\tlists all printer-drivers on print-server\n\n");
6950 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
6951 "\tpublishes printer settings in Active Directory\n"
6952 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
6953 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
6954 "\n\tmigrates printers from remote to local server\n\n");
6955 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
6956 "\n\tmigrates printer-settings from remote to local server\n\n");
6957 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
6958 "\n\tmigrates printer-drivers from remote to local server\n\n");
6959 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
6960 "\n\tmigrates printer-forms from remote to local server\n\n");
6961 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
6962 "\n\tmigrates printer-ACLs from remote to local server\n\n");
6963 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
6964 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
6965 "\tremote to local print-server\n\n");
6966 net_common_methods_usage(c
, argc
, argv
);
6967 net_common_flags_usage(c
, argc
, argv
);
6969 "\t-v or --verbose\t\t\tgive verbose output\n"
6970 "\t --destination\t\tmigration target server (default: localhost)\n");
6976 * 'net rpc printer' entrypoint.
6978 * @param c A net_context structure.
6979 * @param argc Standard main() style argc.
6980 * @param argv Standard main() style argv. Initial components are already
6983 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
6985 struct functable func
[] = {
6990 "List all printers on print server",
6991 "net rpc printer list\n"
6992 " List all printers on print server"
6996 rpc_printer_migrate
,
6998 "Migrate printer to local server",
6999 "net rpc printer migrate\n"
7000 " Migrate printer to local server"
7004 rpc_printer_driver_list
,
7006 "List printer drivers",
7007 "net rpc printer driver\n"
7008 " List printer drivers"
7012 rpc_printer_publish
,
7014 "Publish printer in AD",
7015 "net rpc printer publish\n"
7016 " Publish printer in AD"
7018 {NULL
, NULL
, 0, NULL
, NULL
}
7022 if (c
->display_usage
) {
7023 d_printf("Usage:\n");
7024 d_printf("net rpc printer\n"
7025 " List printers\n");
7026 net_display_usage_from_functable(func
);
7029 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
7030 rpc_printer_list_internals
,
7034 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7038 * 'net rpc' entrypoint.
7040 * @param c A net_context structure.
7041 * @param argc Standard main() style argc.
7042 * @param argv Standard main() style argv. Initial components are already
7046 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7048 struct functable func
[] = {
7053 "Modify global audit settings",
7055 " Modify global audit settings"
7061 "Show basic info about a domain",
7063 " Show basic info about a domain"
7077 "Join a domain created in server manager",
7079 " Join a domain created in server manager"
7085 "Test that a join is valid",
7086 "net rpc testjoin\n"
7087 " Test that a join is valid"
7093 "List/modify users",
7095 " List/modify users"
7101 "Change a user password",
7102 "net rpc password\n"
7103 " Change a user password\n"
7104 " Alias for net rpc user password"
7110 "List/modify groups",
7112 " List/modify groups"
7118 "List/modify shares",
7120 " List/modify shares"
7134 "List/modify printers",
7136 " List/modify printers"
7140 net_rpc_changetrustpw
,
7142 "Change trust account password",
7143 "net rpc changetrustpw\n"
7144 " Change trust account password"
7150 "Modify domain trusts",
7151 "net rpc trustdom\n"
7152 " Modify domain trusts"
7158 "Abort a remote shutdown",
7159 "net rpc abortshutdown\n"
7160 " Abort a remote shutdown"
7166 "Shutdown a remote server",
7167 "net rpc shutdown\n"
7168 " Shutdown a remote server"
7174 "Dump SAM data of remote NT PDC",
7176 " Dump SAM data of remote NT PDC"
7182 "Sync a remote NT PDC's data into local passdb",
7184 " Sync a remote NT PDC's data into local passdb"
7190 "Fetch the domain sid into local secrets.tdb",
7192 " Fetch the domain sid into local secrets.tdb"
7198 "Manage privileges assigned to SID",
7200 " Manage privileges assigned to SID"
7206 "Start/stop/query remote services",
7208 " Start/stop/query remote services"
7214 "Manage registry hives",
7215 "net rpc registry\n"
7216 " Manage registry hives"
7222 "Open interactive shell on remote server",
7224 " Open interactive shell on remote server"
7226 {NULL
, NULL
, 0, NULL
, NULL
}
7228 return net_run_function(c
, argc
, argv
, "net rpc", func
);