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 lsa_pipe
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
64 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
68 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, False
,
69 SEC_RIGHTS_MAXIMUM_ALLOWED
,
71 if (!NT_STATUS_IS_OK(result
)) {
72 d_fprintf(stderr
, "open_policy failed: %s\n",
77 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
79 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
81 if (!NT_STATUS_IS_OK(result
)) {
82 d_fprintf(stderr
, "lsaquery failed: %s\n",
87 *domain_name
= info
->account_domain
.name
.string
;
88 *domain_sid
= info
->account_domain
.sid
;
90 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
91 cli_rpc_pipe_close(lsa_pipe
);
97 * Run a single RPC command, from start to finish.
99 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
100 * @param conn_flag a NET_FLAG_ combination. Passed to
101 * net_make_ipc_connection.
102 * @param argc Standard main() style argc.
103 * @param argv Standard main() style argv. Initial components are already
105 * @return A shell status integer (0 for success).
108 int run_rpc_command(struct cli_state
*cli_arg
,
115 struct cli_state
*cli
= NULL
;
116 struct rpc_pipe_client
*pipe_hnd
= NULL
;
120 const char *domain_name
;
123 /* make use of cli_state handed over as an argument, if possible */
125 nt_status
= net_make_ipc_connection(conn_flags
, &cli
);
126 if (!NT_STATUS_IS_OK(nt_status
)) {
127 DEBUG(1, ("failed to make ipc connection: %s\n",
128 nt_errstr(nt_status
)));
141 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
142 DEBUG(0, ("talloc_init() failed\n"));
146 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
148 if (!NT_STATUS_IS_OK(nt_status
)) {
152 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
153 if (lp_client_schannel() && (pipe_idx
== PI_NETLOGON
)) {
154 /* Always try and create an schannel netlogon pipe. */
155 pipe_hnd
= cli_rpc_pipe_open_schannel(cli
, pipe_idx
,
156 PIPE_AUTH_LEVEL_PRIVACY
,
160 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
161 nt_errstr(nt_status
) ));
165 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, pipe_idx
, &nt_status
);
167 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
168 cli_get_pipe_name(pipe_idx
),
169 nt_errstr(nt_status
) ));
175 nt_status
= fn(domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
177 if (!NT_STATUS_IS_OK(nt_status
)) {
178 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
181 DEBUG(5, ("rpc command function succedded\n"));
184 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
186 cli_rpc_pipe_close(pipe_hnd
);
191 /* close the connection only if it was opened here */
196 talloc_destroy(mem_ctx
);
201 * Force a change of the trust acccount password.
203 * All parameters are provided by the run_rpc_command function, except for
204 * argc, argv which are passed through.
206 * @param domain_sid The domain sid acquired from the remote server
207 * @param cli A cli_state connected to the server.
208 * @param mem_ctx Talloc context, destroyed on completion of the function.
209 * @param argc Standard main() style argc.
210 * @param argv Standard main() style argv. Initial components are already
213 * @return Normal NTSTATUS return.
216 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
,
217 const char *domain_name
,
218 struct cli_state
*cli
,
219 struct rpc_pipe_client
*pipe_hnd
,
225 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
);
229 * Force a change of the trust acccount password.
231 * @param argc Standard main() style argc.
232 * @param argv Standard main() style argv. Initial components are already
235 * @return A shell status integer (0 for success).
238 int net_rpc_changetrustpw(int argc
, const char **argv
)
240 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
241 rpc_changetrustpw_internals
,
246 * Join a domain, the old way.
248 * This uses 'machinename' as the inital password, and changes it.
250 * The password should be created with 'server manager' or equiv first.
252 * All parameters are provided by the run_rpc_command function, except for
253 * argc, argv which are passed through.
255 * @param domain_sid The domain sid acquired from the remote server.
256 * @param cli A cli_state connected to the server.
257 * @param mem_ctx Talloc context, destroyed on completion of the function.
258 * @param argc Standard main() style argc.
259 * @param argv Standard main() style argv. Initial components are already
262 * @return Normal NTSTATUS return.
265 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
,
266 const char *domain_name
,
267 struct cli_state
*cli
,
268 struct rpc_pipe_client
*pipe_hnd
,
274 fstring trust_passwd
;
275 unsigned char orig_trust_passwd_hash
[16];
277 uint32 sec_channel_type
;
279 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &result
);
281 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
284 nt_errstr(result
) ));
289 check what type of join - if the user want's to join as
290 a BDC, the server must agree that we are a BDC.
293 sec_channel_type
= get_sec_channel_type(argv
[0]);
295 sec_channel_type
= get_sec_channel_type(NULL
);
298 fstrcpy(trust_passwd
, global_myname());
299 strlower_m(trust_passwd
);
302 * Machine names can be 15 characters, but the max length on
303 * a password is 14. --jerry
306 trust_passwd
[14] = '\0';
308 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
310 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
,
311 orig_trust_passwd_hash
,
314 if (NT_STATUS_IS_OK(result
))
315 printf("Joined domain %s.\n",opt_target_workgroup
);
318 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
319 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
320 result
= NT_STATUS_UNSUCCESSFUL
;
327 * Join a domain, the old way.
329 * @param argc Standard main() style argc.
330 * @param argv Standard main() style argv. Initial components are already
333 * @return A shell status integer (0 for success)
336 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
338 return run_rpc_command(NULL
, PI_NETLOGON
,
339 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
340 rpc_oldjoin_internals
,
345 * Join a domain, the old way. This function exists to allow
346 * the message to be displayed when oldjoin was explicitly
347 * requested, but not when it was implied by "net rpc join".
349 * @param argc Standard main() style argc.
350 * @param argv Standard main() style argv. Initial components are already
353 * @return A shell status integer (0 for success)
356 static int net_rpc_oldjoin(int argc
, const char **argv
)
358 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
361 d_fprintf(stderr
, "Failed to join domain\n");
368 * Basic usage function for 'net rpc join'.
369 * @param argc Standard main() style argc.
370 * @param argv Standard main() style argv. Initial components are already
374 static int rpc_join_usage(int argc
, const char **argv
)
376 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
377 "\t to join a domain with admin username & password\n"\
378 "\t\t password will be prompted if needed and none is specified\n"\
379 "\t <type> can be (default MEMBER)\n"\
380 "\t\t BDC - Join as a BDC\n"\
381 "\t\t PDC - Join as a PDC\n"\
382 "\t\t MEMBER - Join as a MEMBER server\n");
384 net_common_flags_usage(argc
, argv
);
389 * 'net rpc join' entrypoint.
390 * @param argc Standard main() style argc.
391 * @param argv Standard main() style argv. Initial components are already
394 * Main 'net_rpc_join()' (where the admin username/password is used) is
396 * Try to just change the password, but if that doesn't work, use/prompt
397 * for a username/password.
400 int net_rpc_join(int argc
, const char **argv
)
402 if (lp_server_role() == ROLE_STANDALONE
) {
403 d_printf("cannot join as standalone machine\n");
407 if (strlen(global_myname()) > 15) {
408 d_printf("Our netbios name can be at most 15 chars long, "
409 "\"%s\" is %u chars long\n",
410 global_myname(), (unsigned int)strlen(global_myname()));
414 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
417 return net_rpc_join_newstyle(argc
, argv
);
421 * display info about a rpc domain
423 * All parameters are provided by the run_rpc_command function, except for
424 * argc, argv which are passed through.
426 * @param domain_sid The domain sid acquired from the remote server.
427 * @param cli A cli_state connected to the server.
428 * @param mem_ctx Talloc context, destroyed on completion of the function.
429 * @param argc Standard main() style argc.
430 * @param argv Standard main() style argv. Initial components are already
433 * @return Normal NTSTATUS return.
436 NTSTATUS
rpc_info_internals(const DOM_SID
*domain_sid
,
437 const char *domain_name
,
438 struct cli_state
*cli
,
439 struct rpc_pipe_client
*pipe_hnd
,
444 POLICY_HND connect_pol
, domain_pol
;
445 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
446 union samr_DomainInfo
*info
= NULL
;
449 sid_to_fstring(sid_str
, domain_sid
);
451 /* Get sam policy handle */
452 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
453 pipe_hnd
->cli
->desthost
,
454 MAXIMUM_ALLOWED_ACCESS
,
456 if (!NT_STATUS_IS_OK(result
)) {
457 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
461 /* Get domain policy handle */
462 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
464 MAXIMUM_ALLOWED_ACCESS
,
465 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
467 if (!NT_STATUS_IS_OK(result
)) {
468 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
472 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
476 if (NT_STATUS_IS_OK(result
)) {
477 d_printf("Domain Name: %s\n", info
->info2
.domain_name
.string
);
478 d_printf("Domain SID: %s\n", sid_str
);
479 d_printf("Sequence number: %llu\n",
480 (unsigned long long)info
->info2
.sequence_num
);
481 d_printf("Num users: %u\n", info
->info2
.num_users
);
482 d_printf("Num domain groups: %u\n", info
->info2
.num_groups
);
483 d_printf("Num local groups: %u\n", info
->info2
.num_aliases
);
491 * 'net rpc info' entrypoint.
492 * @param argc Standard main() style argc
493 * @param argv Standard main() style argv. Initial components are already
497 int net_rpc_info(int argc
, const char **argv
)
499 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_PDC
,
505 * Fetch domain SID into the local secrets.tdb
507 * All parameters are provided by the run_rpc_command function, except for
508 * argc, argv which are passed through.
510 * @param domain_sid The domain sid acquired from the remote server.
511 * @param cli A cli_state connected to the server.
512 * @param mem_ctx Talloc context, destroyed on completion of the function.
513 * @param argc Standard main() style argc.
514 * @param argv Standard main() style argv. Initial components are already
517 * @return Normal NTSTATUS return.
520 static NTSTATUS
rpc_getsid_internals(const DOM_SID
*domain_sid
,
521 const char *domain_name
,
522 struct cli_state
*cli
,
523 struct rpc_pipe_client
*pipe_hnd
,
530 sid_to_fstring(sid_str
, domain_sid
);
531 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
532 sid_str
, domain_name
);
534 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
535 DEBUG(0,("Can't store domain SID\n"));
536 return NT_STATUS_UNSUCCESSFUL
;
543 * 'net rpc getsid' entrypoint.
544 * @param argc Standard main() style argc.
545 * @param argv Standard main() style argv. Initial components are already
549 int net_rpc_getsid(int argc
, const char **argv
)
551 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
552 rpc_getsid_internals
,
556 /****************************************************************************/
559 * Basic usage function for 'net rpc user'.
560 * @param argc Standard main() style argc.
561 * @param argv Standard main() style argv. Initial components are already
565 static int rpc_user_usage(int argc
, const char **argv
)
567 return net_help_user(argc
, argv
);
571 * Add a new user to a remote RPC server.
573 * @param argc Standard main() style argc.
574 * @param argv Standard main() style argv. Initial components are already
577 * @return A shell status integer (0 for success)
580 static int rpc_user_add(int argc
, const char **argv
)
582 NET_API_STATUS status
;
583 struct USER_INFO_1 info1
;
584 uint32_t parm_error
= 0;
587 d_printf("User must be specified\n");
588 rpc_user_usage(argc
, argv
);
594 info1
.usri1_name
= argv
[0];
596 info1
.usri1_password
= argv
[1];
599 status
= NetUserAdd(opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
602 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
603 argv
[0], libnetapi_get_error_string(netapi_ctx
, status
));
606 d_printf("Added user '%s'.\n", argv
[0]);
613 * Rename a user on a remote RPC server.
615 * All parameters are provided by the run_rpc_command function, except for
616 * argc, argv which are passed through.
618 * @param domain_sid The domain sid acquired from the remote server.
619 * @param cli A cli_state connected to the server.
620 * @param mem_ctx Talloc context, destroyed on completion of the function.
621 * @param argc Standard main() style argc.
622 * @param argv Standard main() style argv. Initial components are already
625 * @return Normal NTSTATUS return.
628 static NTSTATUS
rpc_user_rename_internals(const DOM_SID
*domain_sid
,
629 const char *domain_name
,
630 struct cli_state
*cli
,
631 struct rpc_pipe_client
*pipe_hnd
,
636 POLICY_HND connect_pol
, domain_pol
, user_pol
;
637 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
638 uint32 info_level
= 7;
639 const char *old_name
, *new_name
;
640 struct samr_Ids user_rids
, name_types
;
641 struct lsa_String lsa_acct_name
;
642 union samr_UserInfo
*info
= NULL
;
645 d_printf("Old and new username must be specified\n");
646 rpc_user_usage(argc
, argv
);
653 /* Get sam policy handle */
655 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
656 pipe_hnd
->cli
->desthost
,
657 MAXIMUM_ALLOWED_ACCESS
,
660 if (!NT_STATUS_IS_OK(result
)) {
664 /* Get domain policy handle */
666 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
668 MAXIMUM_ALLOWED_ACCESS
,
669 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
671 if (!NT_STATUS_IS_OK(result
)) {
675 init_lsa_String(&lsa_acct_name
, old_name
);
677 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
683 if (!NT_STATUS_IS_OK(result
)) {
687 /* Open domain user */
688 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
690 MAXIMUM_ALLOWED_ACCESS
,
694 if (!NT_STATUS_IS_OK(result
)) {
698 /* Query user info */
699 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
704 if (!NT_STATUS_IS_OK(result
)) {
708 init_samr_user_info7(&info
->info7
, new_name
);
711 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
716 if (!NT_STATUS_IS_OK(result
)) {
721 if (!NT_STATUS_IS_OK(result
)) {
722 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n", old_name
, new_name
,
725 d_printf("Renamed user from %s to %s\n", old_name
, new_name
);
731 * Rename a user on a remote RPC server.
733 * @param argc Standard main() style argc.
734 * @param argv Standard main() style argv. Initial components are already
737 * @return A shell status integer (0 for success).
740 static int rpc_user_rename(int argc
, const char **argv
)
742 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_rename_internals
,
747 * Delete a user from a remote RPC server.
749 * @param argc Standard main() style argc.
750 * @param argv Standard main() style argv. Initial components are already
753 * @return A shell status integer (0 for success).
756 static int rpc_user_delete(int argc
, const char **argv
)
758 NET_API_STATUS status
;
761 d_printf("User must be specified\n");
762 rpc_user_usage(argc
, argv
);
766 status
= NetUserDel(opt_host
, argv
[0]);
769 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
771 libnetapi_get_error_string(netapi_ctx
, status
));
774 d_printf("Deleted user '%s'.\n", argv
[0]);
781 * Set a password for a user on a remote RPC server.
783 * All parameters are provided by the run_rpc_command function, except for
784 * argc, argv which are passed through.
786 * @param domain_sid The domain sid acquired from the remote server.
787 * @param cli A cli_state connected to the server.
788 * @param mem_ctx Talloc context, destroyed on completion of the function.
789 * @param argc Standard main() style argc.
790 * @param argv Standard main() style argv. Initial components are already
793 * @return Normal NTSTATUS return.
796 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
797 const char *domain_name
,
798 struct cli_state
*cli
,
799 struct rpc_pipe_client
*pipe_hnd
,
804 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
805 POLICY_HND connect_pol
, domain_pol
, user_pol
;
807 const char *new_password
;
809 union samr_UserInfo info
;
810 struct samr_CryptPassword crypt_pwd
;
813 d_printf("User must be specified\n");
814 rpc_user_usage(argc
, argv
);
821 new_password
= argv
[1];
823 asprintf(&prompt
, "Enter new password for %s:", user
);
824 new_password
= getpass(prompt
);
828 /* Get sam policy and domain handles */
830 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
831 pipe_hnd
->cli
->desthost
,
832 MAXIMUM_ALLOWED_ACCESS
,
835 if (!NT_STATUS_IS_OK(result
)) {
839 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
841 MAXIMUM_ALLOWED_ACCESS
,
842 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
845 if (!NT_STATUS_IS_OK(result
)) {
849 /* Get handle on user */
852 struct samr_Ids user_rids
, name_types
;
853 struct lsa_String lsa_acct_name
;
855 init_lsa_String(&lsa_acct_name
, user
);
857 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
863 if (!NT_STATUS_IS_OK(result
)) {
867 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
869 MAXIMUM_ALLOWED_ACCESS
,
873 if (!NT_STATUS_IS_OK(result
)) {
878 /* Set password on account */
880 init_samr_CryptPassword(new_password
,
881 &cli
->user_session_key
,
884 init_samr_user_info24(&info
.info24
, &crypt_pwd
,
885 PASS_DONT_CHANGE_AT_NEXT_LOGON
);
887 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
892 if (!NT_STATUS_IS_OK(result
)) {
896 /* Display results */
904 * Set a user's password on a remote RPC server.
906 * @param argc Standard main() style argc.
907 * @param argv Standard main() style argv. Initial components are already
910 * @return A shell status integer (0 for success).
913 static int rpc_user_password(int argc
, const char **argv
)
915 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
920 * List user's groups on a remote RPC server.
922 * All parameters are provided by the run_rpc_command function, except for
923 * argc, argv which are passed through.
925 * @param domain_sid The domain sid acquired from the remote server.
926 * @param cli A cli_state connected to the server.
927 * @param mem_ctx Talloc context, destroyed on completion of the function.
928 * @param argc Standard main() style argc.
929 * @param argv Standard main() style argv. Initial components are already
932 * @return Normal NTSTATUS return.
935 static NTSTATUS
rpc_user_info_internals(const DOM_SID
*domain_sid
,
936 const char *domain_name
,
937 struct cli_state
*cli
,
938 struct rpc_pipe_client
*pipe_hnd
,
943 POLICY_HND connect_pol
, domain_pol
, user_pol
;
944 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
946 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
947 struct lsa_Strings names
;
948 struct samr_Ids types
;
949 uint32_t *lrids
= NULL
;
950 struct samr_Ids rids
, name_types
;
951 struct lsa_String lsa_acct_name
;
955 d_printf("User must be specified\n");
956 rpc_user_usage(argc
, argv
);
959 /* Get sam policy handle */
961 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
962 pipe_hnd
->cli
->desthost
,
963 MAXIMUM_ALLOWED_ACCESS
,
965 if (!NT_STATUS_IS_OK(result
)) goto done
;
967 /* Get domain policy handle */
969 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
971 MAXIMUM_ALLOWED_ACCESS
,
972 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
974 if (!NT_STATUS_IS_OK(result
)) goto done
;
976 /* Get handle on user */
978 init_lsa_String(&lsa_acct_name
, argv
[0]);
980 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
987 if (!NT_STATUS_IS_OK(result
)) goto done
;
989 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
991 MAXIMUM_ALLOWED_ACCESS
,
994 if (!NT_STATUS_IS_OK(result
)) goto done
;
996 result
= rpccli_samr_GetGroupsForUser(pipe_hnd
, mem_ctx
,
1000 if (!NT_STATUS_IS_OK(result
)) goto done
;
1004 if (rid_array
->count
) {
1005 if ((lrids
= TALLOC_ARRAY(mem_ctx
, uint32
, rid_array
->count
)) == NULL
) {
1006 result
= NT_STATUS_NO_MEMORY
;
1010 for (i
= 0; i
< rid_array
->count
; i
++)
1011 lrids
[i
] = rid_array
->rids
[i
].rid
;
1013 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
1020 if (!NT_STATUS_IS_OK(result
)) {
1024 /* Display results */
1026 for (i
= 0; i
< names
.count
; i
++)
1027 printf("%s\n", names
.names
[i
].string
);
1034 * List a user's groups from a remote RPC server.
1036 * @param argc Standard main() style argc.
1037 * @param argv Standard main() style argv. Initial components are already
1040 * @return A shell status integer (0 for success).
1043 static int rpc_user_info(int argc
, const char **argv
)
1045 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
1050 * List users on a remote RPC server.
1052 * All parameters are provided by the run_rpc_command function, except for
1053 * argc, argv which are passed through.
1055 * @param domain_sid The domain sid acquired from the remote server.
1056 * @param cli A cli_state connected to the server.
1057 * @param mem_ctx Talloc context, destroyed on completion of the function.
1058 * @param argc Standard main() style argc.
1059 * @param argv Standard main() style argv. Initial components are already
1062 * @return Normal NTSTATUS return.
1065 static NTSTATUS
rpc_user_list_internals(const DOM_SID
*domain_sid
,
1066 const char *domain_name
,
1067 struct cli_state
*cli
,
1068 struct rpc_pipe_client
*pipe_hnd
,
1069 TALLOC_CTX
*mem_ctx
,
1073 POLICY_HND connect_pol
, domain_pol
;
1074 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1075 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
1077 /* Get sam policy handle */
1079 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1080 pipe_hnd
->cli
->desthost
,
1081 MAXIMUM_ALLOWED_ACCESS
,
1083 if (!NT_STATUS_IS_OK(result
)) {
1087 /* Get domain policy handle */
1089 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1091 MAXIMUM_ALLOWED_ACCESS
,
1092 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1094 if (!NT_STATUS_IS_OK(result
)) {
1098 /* Query domain users */
1099 if (opt_long_list_entries
)
1100 d_printf("\nUser name Comment"\
1101 "\n-----------------------------\n");
1103 const char *user
= NULL
;
1104 const char *desc
= NULL
;
1105 uint32 max_entries
, max_size
;
1106 uint32_t total_size
, returned_size
;
1107 union samr_DispInfo info
;
1109 get_query_dispinfo_params(
1110 loop_count
, &max_entries
, &max_size
);
1112 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
1122 start_idx
+= info
.info1
.count
;
1123 num_entries
= info
.info1
.count
;
1125 for (i
= 0; i
< num_entries
; i
++) {
1126 user
= info
.info1
.entries
[i
].account_name
.string
;
1127 if (opt_long_list_entries
)
1128 desc
= info
.info1
.entries
[i
].description
.string
;
1129 if (opt_long_list_entries
)
1130 printf("%-21.21s %s\n", user
, desc
);
1132 printf("%s\n", user
);
1134 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1141 * 'net rpc user' entrypoint.
1142 * @param argc Standard main() style argc.
1143 * @param argv Standard main() style argv. Initial components are already
1147 int net_rpc_user(int argc
, const char **argv
)
1149 NET_API_STATUS status
;
1151 struct functable func
[] = {
1152 {"add", rpc_user_add
},
1153 {"info", rpc_user_info
},
1154 {"delete", rpc_user_delete
},
1155 {"password", rpc_user_password
},
1156 {"rename", rpc_user_rename
},
1160 status
= libnetapi_init(&netapi_ctx
);
1164 libnetapi_set_username(netapi_ctx
, opt_user_name
);
1165 libnetapi_set_password(netapi_ctx
, opt_password
);
1168 return run_rpc_command(NULL
,PI_SAMR
, 0,
1169 rpc_user_list_internals
,
1173 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1176 static NTSTATUS
rpc_sh_user_list(TALLOC_CTX
*mem_ctx
,
1177 struct rpc_sh_ctx
*ctx
,
1178 struct rpc_pipe_client
*pipe_hnd
,
1179 int argc
, const char **argv
)
1181 return rpc_user_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
1182 ctx
->cli
, pipe_hnd
, mem_ctx
,
1186 static NTSTATUS
rpc_sh_user_info(TALLOC_CTX
*mem_ctx
,
1187 struct rpc_sh_ctx
*ctx
,
1188 struct rpc_pipe_client
*pipe_hnd
,
1189 int argc
, const char **argv
)
1191 return rpc_user_info_internals(ctx
->domain_sid
, ctx
->domain_name
,
1192 ctx
->cli
, pipe_hnd
, mem_ctx
,
1196 static NTSTATUS
rpc_sh_handle_user(TALLOC_CTX
*mem_ctx
,
1197 struct rpc_sh_ctx
*ctx
,
1198 struct rpc_pipe_client
*pipe_hnd
,
1199 int argc
, const char **argv
,
1201 TALLOC_CTX
*mem_ctx
,
1202 struct rpc_sh_ctx
*ctx
,
1203 struct rpc_pipe_client
*pipe_hnd
,
1204 POLICY_HND
*user_hnd
,
1205 int argc
, const char **argv
))
1207 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1208 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1211 enum lsa_SidType type
;
1214 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1215 return NT_STATUS_INVALID_PARAMETER
;
1218 ZERO_STRUCT(connect_pol
);
1219 ZERO_STRUCT(domain_pol
);
1220 ZERO_STRUCT(user_pol
);
1222 result
= net_rpc_lookup_name(mem_ctx
, pipe_hnd
->cli
, argv
[0],
1223 NULL
, NULL
, &sid
, &type
);
1224 if (!NT_STATUS_IS_OK(result
)) {
1225 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1230 if (type
!= SID_NAME_USER
) {
1231 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1232 sid_type_lookup(type
));
1233 result
= NT_STATUS_NO_SUCH_USER
;
1237 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1238 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1239 result
= NT_STATUS_NO_SUCH_USER
;
1243 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1244 pipe_hnd
->cli
->desthost
,
1245 MAXIMUM_ALLOWED_ACCESS
,
1247 if (!NT_STATUS_IS_OK(result
)) {
1251 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1253 MAXIMUM_ALLOWED_ACCESS
,
1256 if (!NT_STATUS_IS_OK(result
)) {
1260 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1262 MAXIMUM_ALLOWED_ACCESS
,
1265 if (!NT_STATUS_IS_OK(result
)) {
1269 result
= fn(mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1272 if (is_valid_policy_hnd(&user_pol
)) {
1273 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1275 if (is_valid_policy_hnd(&domain_pol
)) {
1276 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1278 if (is_valid_policy_hnd(&connect_pol
)) {
1279 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1284 static NTSTATUS
rpc_sh_user_show_internals(TALLOC_CTX
*mem_ctx
,
1285 struct rpc_sh_ctx
*ctx
,
1286 struct rpc_pipe_client
*pipe_hnd
,
1287 POLICY_HND
*user_hnd
,
1288 int argc
, const char **argv
)
1291 union samr_UserInfo
*info
= NULL
;
1294 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1295 return NT_STATUS_INVALID_PARAMETER
;
1298 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1302 if (!NT_STATUS_IS_OK(result
)) {
1306 d_printf("user rid: %d, group rid: %d\n",
1308 info
->info21
.primary_gid
);
1313 static NTSTATUS
rpc_sh_user_show(TALLOC_CTX
*mem_ctx
,
1314 struct rpc_sh_ctx
*ctx
,
1315 struct rpc_pipe_client
*pipe_hnd
,
1316 int argc
, const char **argv
)
1318 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1319 rpc_sh_user_show_internals
);
1322 #define FETCHSTR(name, rec) \
1323 do { if (strequal(ctx->thiscmd, name)) { \
1324 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1327 #define SETSTR(name, rec, flag) \
1328 do { if (strequal(ctx->thiscmd, name)) { \
1329 init_lsa_String(&(info->info21.rec), argv[0]); \
1330 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1333 static NTSTATUS
rpc_sh_user_str_edit_internals(TALLOC_CTX
*mem_ctx
,
1334 struct rpc_sh_ctx
*ctx
,
1335 struct rpc_pipe_client
*pipe_hnd
,
1336 POLICY_HND
*user_hnd
,
1337 int argc
, const char **argv
)
1340 const char *username
;
1341 const char *oldval
= "";
1342 union samr_UserInfo
*info
= NULL
;
1345 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1347 return NT_STATUS_INVALID_PARAMETER
;
1350 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1354 if (!NT_STATUS_IS_OK(result
)) {
1358 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1360 FETCHSTR("fullname", full_name
);
1361 FETCHSTR("homedir", home_directory
);
1362 FETCHSTR("homedrive", home_drive
);
1363 FETCHSTR("logonscript", logon_script
);
1364 FETCHSTR("profilepath", profile_path
);
1365 FETCHSTR("description", description
);
1368 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1372 if (strcmp(argv
[0], "NULL") == 0) {
1376 ZERO_STRUCT(info
->info21
);
1378 SETSTR("fullname", full_name
, FULL_NAME
);
1379 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1380 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1381 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1382 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1383 SETSTR("description", description
, DESCRIPTION
);
1385 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1390 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1391 ctx
->thiscmd
, oldval
, argv
[0]);
1398 #define HANDLEFLG(name, rec) \
1399 do { if (strequal(ctx->thiscmd, name)) { \
1400 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1402 newflags = oldflags | ACB_##rec; \
1404 newflags = oldflags & ~ACB_##rec; \
1407 static NTSTATUS
rpc_sh_user_str_edit(TALLOC_CTX
*mem_ctx
,
1408 struct rpc_sh_ctx
*ctx
,
1409 struct rpc_pipe_client
*pipe_hnd
,
1410 int argc
, const char **argv
)
1412 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1413 rpc_sh_user_str_edit_internals
);
1416 static NTSTATUS
rpc_sh_user_flag_edit_internals(TALLOC_CTX
*mem_ctx
,
1417 struct rpc_sh_ctx
*ctx
,
1418 struct rpc_pipe_client
*pipe_hnd
,
1419 POLICY_HND
*user_hnd
,
1420 int argc
, const char **argv
)
1423 const char *username
;
1424 const char *oldval
= "unknown";
1425 uint32 oldflags
, newflags
;
1427 union samr_UserInfo
*info
= NULL
;
1430 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1431 !strequal(argv
[0], "no"))) {
1432 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1434 return NT_STATUS_INVALID_PARAMETER
;
1437 newval
= strequal(argv
[0], "yes");
1439 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1443 if (!NT_STATUS_IS_OK(result
)) {
1447 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1448 oldflags
= info
->info21
.acct_flags
;
1449 newflags
= info
->info21
.acct_flags
;
1451 HANDLEFLG("disabled", DISABLED
);
1452 HANDLEFLG("pwnotreq", PWNOTREQ
);
1453 HANDLEFLG("autolock", AUTOLOCK
);
1454 HANDLEFLG("pwnoexp", PWNOEXP
);
1457 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1461 ZERO_STRUCT(info
->info21
);
1463 info
->info21
.acct_flags
= newflags
;
1464 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1466 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1471 if (NT_STATUS_IS_OK(result
)) {
1472 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1473 ctx
->thiscmd
, oldval
, argv
[0]);
1481 static NTSTATUS
rpc_sh_user_flag_edit(TALLOC_CTX
*mem_ctx
,
1482 struct rpc_sh_ctx
*ctx
,
1483 struct rpc_pipe_client
*pipe_hnd
,
1484 int argc
, const char **argv
)
1486 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1487 rpc_sh_user_flag_edit_internals
);
1490 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(TALLOC_CTX
*mem_ctx
,
1491 struct rpc_sh_ctx
*ctx
)
1493 static struct rpc_sh_cmd cmds
[] = {
1495 { "fullname", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1496 "Show/Set a user's full name" },
1498 { "homedir", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1499 "Show/Set a user's home directory" },
1501 { "homedrive", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1502 "Show/Set a user's home drive" },
1504 { "logonscript", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1505 "Show/Set a user's logon script" },
1507 { "profilepath", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1508 "Show/Set a user's profile path" },
1510 { "description", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1511 "Show/Set a user's description" },
1513 { "disabled", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1514 "Show/Set whether a user is disabled" },
1516 { "autolock", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1517 "Show/Set whether a user locked out" },
1519 { "pwnotreq", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1520 "Show/Set whether a user does not need a password" },
1522 { "pwnoexp", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1523 "Show/Set whether a user's password does not expire" },
1525 { NULL
, NULL
, 0, NULL
, NULL
}
1531 struct rpc_sh_cmd
*net_rpc_user_cmds(TALLOC_CTX
*mem_ctx
,
1532 struct rpc_sh_ctx
*ctx
)
1534 static struct rpc_sh_cmd cmds
[] = {
1536 { "list", NULL
, PI_SAMR
, rpc_sh_user_list
,
1537 "List available users" },
1539 { "info", NULL
, PI_SAMR
, rpc_sh_user_info
,
1540 "List the domain groups a user is member of" },
1542 { "show", NULL
, PI_SAMR
, rpc_sh_user_show
,
1543 "Show info about a user" },
1545 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1546 "Show/Modify a user's fields" },
1548 { NULL
, NULL
, 0, NULL
, NULL
}
1554 /****************************************************************************/
1557 * Basic usage function for 'net rpc group'.
1558 * @param argc Standard main() style argc.
1559 * @param argv Standard main() style argv. Initial components are already
1563 static int rpc_group_usage(int argc
, const char **argv
)
1565 return net_help_group(argc
, argv
);
1569 * Delete group on a remote RPC server.
1571 * All parameters are provided by the run_rpc_command function, except for
1572 * argc, argv which are passed through.
1574 * @param domain_sid The domain sid acquired from the remote server.
1575 * @param cli A cli_state connected to the server.
1576 * @param mem_ctx Talloc context, destroyed on completion of the function.
1577 * @param argc Standard main() style argc.
1578 * @param argv Standard main() style argv. Initial components are already
1581 * @return Normal NTSTATUS return.
1584 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1585 const char *domain_name
,
1586 struct cli_state
*cli
,
1587 struct rpc_pipe_client
*pipe_hnd
,
1588 TALLOC_CTX
*mem_ctx
,
1592 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1593 bool group_is_primary
= False
;
1594 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1596 struct samr_RidTypeArray
*rids
= NULL
;
1599 /* DOM_GID *user_gids; */
1601 struct samr_Ids group_rids
, name_types
;
1602 struct lsa_String lsa_acct_name
;
1603 union samr_UserInfo
*info
= NULL
;
1606 d_printf("specify group\n");
1607 rpc_group_usage(argc
,argv
);
1608 return NT_STATUS_OK
; /* ok? */
1611 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1612 pipe_hnd
->cli
->desthost
,
1613 MAXIMUM_ALLOWED_ACCESS
,
1616 if (!NT_STATUS_IS_OK(result
)) {
1617 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1621 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1623 MAXIMUM_ALLOWED_ACCESS
,
1624 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1627 if (!NT_STATUS_IS_OK(result
)) {
1628 d_fprintf(stderr
, "Request open_domain failed\n");
1632 init_lsa_String(&lsa_acct_name
, argv
[0]);
1634 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1640 if (!NT_STATUS_IS_OK(result
)) {
1641 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1645 switch (name_types
.ids
[0])
1647 case SID_NAME_DOM_GRP
:
1648 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1650 MAXIMUM_ALLOWED_ACCESS
,
1653 if (!NT_STATUS_IS_OK(result
)) {
1654 d_fprintf(stderr
, "Request open_group failed");
1658 group_rid
= group_rids
.ids
[0];
1660 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1664 if (!NT_STATUS_IS_OK(result
)) {
1665 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1670 d_printf("Domain Group %s (rid: %d) has %d members\n",
1671 argv
[0],group_rid
, rids
->count
);
1674 /* Check if group is anyone's primary group */
1675 for (i
= 0; i
< rids
->count
; i
++)
1677 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1679 MAXIMUM_ALLOWED_ACCESS
,
1683 if (!NT_STATUS_IS_OK(result
)) {
1684 d_fprintf(stderr
, "Unable to open group member %d\n",
1689 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1694 if (!NT_STATUS_IS_OK(result
)) {
1695 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1700 if (info
->info21
.primary_gid
== group_rid
) {
1702 d_printf("Group is primary group of %s\n",
1703 info
->info21
.account_name
.string
);
1705 group_is_primary
= True
;
1708 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1711 if (group_is_primary
) {
1712 d_fprintf(stderr
, "Unable to delete group because some "
1713 "of it's members have it as primary group\n");
1714 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1718 /* remove all group members */
1719 for (i
= 0; i
< rids
->count
; i
++)
1722 d_printf("Remove group member %d...",
1724 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1728 if (NT_STATUS_IS_OK(result
)) {
1733 d_printf("failed\n");
1738 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1742 /* removing a local group is easier... */
1743 case SID_NAME_ALIAS
:
1744 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1746 MAXIMUM_ALLOWED_ACCESS
,
1750 if (!NT_STATUS_IS_OK(result
)) {
1751 d_fprintf(stderr
, "Request open_alias failed\n");
1755 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1759 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1760 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1761 result
= NT_STATUS_UNSUCCESSFUL
;
1766 if (NT_STATUS_IS_OK(result
)) {
1768 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1770 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1771 get_friendly_nt_error_msg(result
));
1779 static int rpc_group_delete(int argc
, const char **argv
)
1781 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1785 static NTSTATUS
rpc_group_add_internals(const DOM_SID
*domain_sid
,
1786 const char *domain_name
,
1787 struct cli_state
*cli
,
1788 struct rpc_pipe_client
*pipe_hnd
,
1789 TALLOC_CTX
*mem_ctx
,
1793 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1794 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1795 union samr_GroupInfo group_info
;
1796 struct lsa_String grp_name
;
1800 d_printf("Group name must be specified\n");
1801 rpc_group_usage(argc
, argv
);
1802 return NT_STATUS_OK
;
1805 init_lsa_String(&grp_name
, argv
[0]);
1807 /* Get sam policy handle */
1809 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1810 pipe_hnd
->cli
->desthost
,
1811 MAXIMUM_ALLOWED_ACCESS
,
1813 if (!NT_STATUS_IS_OK(result
)) goto done
;
1815 /* Get domain policy handle */
1817 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1819 MAXIMUM_ALLOWED_ACCESS
,
1820 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1822 if (!NT_STATUS_IS_OK(result
)) goto done
;
1824 /* Create the group */
1826 result
= rpccli_samr_CreateDomainGroup(pipe_hnd
, mem_ctx
,
1829 MAXIMUM_ALLOWED_ACCESS
,
1832 if (!NT_STATUS_IS_OK(result
)) goto done
;
1834 if (strlen(opt_comment
) == 0) goto done
;
1836 /* We've got a comment to set */
1838 init_lsa_String(&group_info
.description
, opt_comment
);
1840 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
1844 if (!NT_STATUS_IS_OK(result
)) goto done
;
1847 if (NT_STATUS_IS_OK(result
))
1848 DEBUG(5, ("add group succeeded\n"));
1850 d_fprintf(stderr
, "add group failed: %s\n", nt_errstr(result
));
1855 static NTSTATUS
rpc_alias_add_internals(const DOM_SID
*domain_sid
,
1856 const char *domain_name
,
1857 struct cli_state
*cli
,
1858 struct rpc_pipe_client
*pipe_hnd
,
1859 TALLOC_CTX
*mem_ctx
,
1863 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
1864 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1865 union samr_AliasInfo alias_info
;
1866 struct lsa_String alias_name
;
1870 d_printf("Alias name must be specified\n");
1871 rpc_group_usage(argc
, argv
);
1872 return NT_STATUS_OK
;
1875 init_lsa_String(&alias_name
, argv
[0]);
1877 /* Get sam policy handle */
1879 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1880 pipe_hnd
->cli
->desthost
,
1881 MAXIMUM_ALLOWED_ACCESS
,
1883 if (!NT_STATUS_IS_OK(result
)) goto done
;
1885 /* Get domain policy handle */
1887 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1889 MAXIMUM_ALLOWED_ACCESS
,
1890 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1892 if (!NT_STATUS_IS_OK(result
)) goto done
;
1894 /* Create the group */
1896 result
= rpccli_samr_CreateDomAlias(pipe_hnd
, mem_ctx
,
1899 MAXIMUM_ALLOWED_ACCESS
,
1902 if (!NT_STATUS_IS_OK(result
)) goto done
;
1904 if (strlen(opt_comment
) == 0) goto done
;
1906 /* We've got a comment to set */
1908 init_lsa_String(&alias_info
.description
, opt_comment
);
1910 result
= rpccli_samr_SetAliasInfo(pipe_hnd
, mem_ctx
,
1915 if (!NT_STATUS_IS_OK(result
)) goto done
;
1918 if (NT_STATUS_IS_OK(result
))
1919 DEBUG(5, ("add alias succeeded\n"));
1921 d_fprintf(stderr
, "add alias failed: %s\n", nt_errstr(result
));
1926 static int rpc_group_add(int argc
, const char **argv
)
1929 return run_rpc_command(NULL
, PI_SAMR
, 0,
1930 rpc_alias_add_internals
,
1933 return run_rpc_command(NULL
, PI_SAMR
, 0,
1934 rpc_group_add_internals
,
1938 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1939 TALLOC_CTX
*mem_ctx
,
1942 enum lsa_SidType
*type
)
1944 DOM_SID
*sids
= NULL
;
1945 enum lsa_SidType
*types
= NULL
;
1946 struct rpc_pipe_client
*pipe_hnd
;
1948 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1950 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
1955 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, False
,
1956 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1958 if (!NT_STATUS_IS_OK(result
)) {
1962 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1963 &name
, NULL
, 1, &sids
, &types
);
1965 if (NT_STATUS_IS_OK(result
)) {
1966 sid_copy(sid
, &sids
[0]);
1970 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1974 cli_rpc_pipe_close(pipe_hnd
);
1977 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1979 /* Try as S-1-5-whatever */
1983 if (string_to_sid(&tmp_sid
, name
)) {
1984 sid_copy(sid
, &tmp_sid
);
1985 *type
= SID_NAME_UNKNOWN
;
1986 result
= NT_STATUS_OK
;
1993 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1994 TALLOC_CTX
*mem_ctx
,
1995 const DOM_SID
*group_sid
,
1998 POLICY_HND connect_pol
, domain_pol
;
2001 POLICY_HND group_pol
;
2003 struct samr_Ids rids
, rid_types
;
2004 struct lsa_String lsa_acct_name
;
2008 sid_copy(&sid
, group_sid
);
2010 if (!sid_split_rid(&sid
, &group_rid
)) {
2011 return NT_STATUS_UNSUCCESSFUL
;
2014 /* Get sam policy handle */
2015 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2016 pipe_hnd
->cli
->desthost
,
2017 MAXIMUM_ALLOWED_ACCESS
,
2019 if (!NT_STATUS_IS_OK(result
)) {
2023 /* Get domain policy handle */
2024 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2026 MAXIMUM_ALLOWED_ACCESS
,
2029 if (!NT_STATUS_IS_OK(result
)) {
2033 init_lsa_String(&lsa_acct_name
, member
);
2035 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2042 if (!NT_STATUS_IS_OK(result
)) {
2043 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2047 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2049 MAXIMUM_ALLOWED_ACCESS
,
2053 if (!NT_STATUS_IS_OK(result
)) {
2057 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
2060 0x0005); /* unknown flags */
2063 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2067 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2068 TALLOC_CTX
*mem_ctx
,
2069 const DOM_SID
*alias_sid
,
2072 POLICY_HND connect_pol
, domain_pol
;
2075 POLICY_HND alias_pol
;
2078 enum lsa_SidType member_type
;
2082 sid_copy(&sid
, alias_sid
);
2084 if (!sid_split_rid(&sid
, &alias_rid
)) {
2085 return NT_STATUS_UNSUCCESSFUL
;
2088 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2089 &member_sid
, &member_type
);
2091 if (!NT_STATUS_IS_OK(result
)) {
2092 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2096 /* Get sam policy handle */
2097 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2098 pipe_hnd
->cli
->desthost
,
2099 MAXIMUM_ALLOWED_ACCESS
,
2101 if (!NT_STATUS_IS_OK(result
)) {
2105 /* Get domain policy handle */
2106 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2108 MAXIMUM_ALLOWED_ACCESS
,
2111 if (!NT_STATUS_IS_OK(result
)) {
2115 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2117 MAXIMUM_ALLOWED_ACCESS
,
2121 if (!NT_STATUS_IS_OK(result
)) {
2125 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
2129 if (!NT_STATUS_IS_OK(result
)) {
2134 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2138 static NTSTATUS
rpc_group_addmem_internals(const DOM_SID
*domain_sid
,
2139 const char *domain_name
,
2140 struct cli_state
*cli
,
2141 struct rpc_pipe_client
*pipe_hnd
,
2142 TALLOC_CTX
*mem_ctx
,
2147 enum lsa_SidType group_type
;
2150 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
2151 return NT_STATUS_UNSUCCESSFUL
;
2154 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2155 &group_sid
, &group_type
))) {
2156 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2157 return NT_STATUS_UNSUCCESSFUL
;
2160 if (group_type
== SID_NAME_DOM_GRP
) {
2161 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2162 &group_sid
, argv
[1]);
2164 if (!NT_STATUS_IS_OK(result
)) {
2165 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2166 argv
[1], argv
[0], nt_errstr(result
));
2171 if (group_type
== SID_NAME_ALIAS
) {
2172 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
2173 &group_sid
, argv
[1]);
2175 if (!NT_STATUS_IS_OK(result
)) {
2176 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2177 argv
[1], argv
[0], nt_errstr(result
));
2182 d_fprintf(stderr
, "Can only add members to global or local groups "
2183 "which %s is not\n", argv
[0]);
2185 return NT_STATUS_UNSUCCESSFUL
;
2188 static int rpc_group_addmem(int argc
, const char **argv
)
2190 return run_rpc_command(NULL
, PI_SAMR
, 0,
2191 rpc_group_addmem_internals
,
2195 static NTSTATUS
rpc_del_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2196 TALLOC_CTX
*mem_ctx
,
2197 const DOM_SID
*group_sid
,
2200 POLICY_HND connect_pol
, domain_pol
;
2203 POLICY_HND group_pol
;
2205 struct samr_Ids rids
, rid_types
;
2206 struct lsa_String lsa_acct_name
;
2210 sid_copy(&sid
, group_sid
);
2212 if (!sid_split_rid(&sid
, &group_rid
))
2213 return NT_STATUS_UNSUCCESSFUL
;
2215 /* Get sam policy handle */
2216 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2217 pipe_hnd
->cli
->desthost
,
2218 MAXIMUM_ALLOWED_ACCESS
,
2220 if (!NT_STATUS_IS_OK(result
))
2223 /* Get domain policy handle */
2224 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2226 MAXIMUM_ALLOWED_ACCESS
,
2229 if (!NT_STATUS_IS_OK(result
))
2232 init_lsa_String(&lsa_acct_name
, member
);
2234 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2240 if (!NT_STATUS_IS_OK(result
)) {
2241 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2245 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2247 MAXIMUM_ALLOWED_ACCESS
,
2251 if (!NT_STATUS_IS_OK(result
))
2254 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2259 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2263 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2264 TALLOC_CTX
*mem_ctx
,
2265 const DOM_SID
*alias_sid
,
2268 POLICY_HND connect_pol
, domain_pol
;
2271 POLICY_HND alias_pol
;
2274 enum lsa_SidType member_type
;
2278 sid_copy(&sid
, alias_sid
);
2280 if (!sid_split_rid(&sid
, &alias_rid
))
2281 return NT_STATUS_UNSUCCESSFUL
;
2283 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2284 &member_sid
, &member_type
);
2286 if (!NT_STATUS_IS_OK(result
)) {
2287 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2291 /* Get sam policy handle */
2292 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2293 pipe_hnd
->cli
->desthost
,
2294 MAXIMUM_ALLOWED_ACCESS
,
2296 if (!NT_STATUS_IS_OK(result
)) {
2300 /* Get domain policy handle */
2301 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2303 MAXIMUM_ALLOWED_ACCESS
,
2306 if (!NT_STATUS_IS_OK(result
)) {
2310 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2312 MAXIMUM_ALLOWED_ACCESS
,
2316 if (!NT_STATUS_IS_OK(result
))
2319 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2323 if (!NT_STATUS_IS_OK(result
))
2327 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2331 static NTSTATUS
rpc_group_delmem_internals(const DOM_SID
*domain_sid
,
2332 const char *domain_name
,
2333 struct cli_state
*cli
,
2334 struct rpc_pipe_client
*pipe_hnd
,
2335 TALLOC_CTX
*mem_ctx
,
2340 enum lsa_SidType group_type
;
2343 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
2344 return NT_STATUS_UNSUCCESSFUL
;
2347 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2348 &group_sid
, &group_type
))) {
2349 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2350 return NT_STATUS_UNSUCCESSFUL
;
2353 if (group_type
== SID_NAME_DOM_GRP
) {
2354 NTSTATUS result
= rpc_del_groupmem(pipe_hnd
, mem_ctx
,
2355 &group_sid
, argv
[1]);
2357 if (!NT_STATUS_IS_OK(result
)) {
2358 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2359 argv
[1], argv
[0], nt_errstr(result
));
2364 if (group_type
== SID_NAME_ALIAS
) {
2365 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2366 &group_sid
, argv
[1]);
2368 if (!NT_STATUS_IS_OK(result
)) {
2369 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2370 argv
[1], argv
[0], nt_errstr(result
));
2375 d_fprintf(stderr
, "Can only delete members from global or local groups "
2376 "which %s is not\n", argv
[0]);
2378 return NT_STATUS_UNSUCCESSFUL
;
2381 static int rpc_group_delmem(int argc
, const char **argv
)
2383 return run_rpc_command(NULL
, PI_SAMR
, 0,
2384 rpc_group_delmem_internals
,
2389 * List groups on a remote RPC server.
2391 * All parameters are provided by the run_rpc_command function, except for
2392 * argc, argv which are passed through.
2394 * @param domain_sid The domain sid acquired from the remote server.
2395 * @param cli A cli_state connected to the server.
2396 * @param mem_ctx Talloc context, destroyed on completion of the function.
2397 * @param argc Standard main() style argc.
2398 * @param argv Standard main() style argv. Initial components are already
2401 * @return Normal NTSTATUS return.
2404 static NTSTATUS
rpc_group_list_internals(const DOM_SID
*domain_sid
,
2405 const char *domain_name
,
2406 struct cli_state
*cli
,
2407 struct rpc_pipe_client
*pipe_hnd
,
2408 TALLOC_CTX
*mem_ctx
,
2412 POLICY_HND connect_pol
, domain_pol
;
2413 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2414 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2415 struct samr_SamArray
*groups
= NULL
;
2416 bool global
= False
;
2418 bool builtin
= False
;
2426 for (i
=0; i
<argc
; i
++) {
2427 if (strequal(argv
[i
], "global"))
2430 if (strequal(argv
[i
], "local"))
2433 if (strequal(argv
[i
], "builtin"))
2437 /* Get sam policy handle */
2439 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2440 pipe_hnd
->cli
->desthost
,
2441 MAXIMUM_ALLOWED_ACCESS
,
2443 if (!NT_STATUS_IS_OK(result
)) {
2447 /* Get domain policy handle */
2449 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2451 MAXIMUM_ALLOWED_ACCESS
,
2452 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2454 if (!NT_STATUS_IS_OK(result
)) {
2458 /* Query domain groups */
2459 if (opt_long_list_entries
)
2460 d_printf("\nGroup name Comment"\
2461 "\n-----------------------------\n");
2463 uint32_t max_size
, total_size
, returned_size
;
2464 union samr_DispInfo info
;
2468 get_query_dispinfo_params(
2469 loop_count
, &max_entries
, &max_size
);
2471 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2480 num_entries
= info
.info3
.count
;
2481 start_idx
+= info
.info3
.count
;
2483 if (!NT_STATUS_IS_OK(result
) &&
2484 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2487 for (i
= 0; i
< num_entries
; i
++) {
2489 const char *group
= NULL
;
2490 const char *desc
= NULL
;
2492 group
= info
.info3
.entries
[i
].account_name
.string
;
2493 desc
= info
.info3
.entries
[i
].description
.string
;
2495 if (opt_long_list_entries
)
2496 printf("%-21.21s %-50.50s\n",
2499 printf("%s\n", group
);
2501 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2502 /* query domain aliases */
2507 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2513 if (!NT_STATUS_IS_OK(result
) &&
2514 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2517 for (i
= 0; i
< num_entries
; i
++) {
2519 const char *description
= NULL
;
2521 if (opt_long_list_entries
) {
2523 POLICY_HND alias_pol
;
2524 union samr_AliasInfo
*info
= NULL
;
2526 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2529 groups
->entries
[i
].idx
,
2531 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2535 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2537 description
= info
->description
.string
;
2541 if (description
!= NULL
) {
2542 printf("%-21.21s %-50.50s\n",
2543 groups
->entries
[i
].name
.string
,
2546 printf("%s\n", groups
->entries
[i
].name
.string
);
2549 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2550 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2551 /* Get builtin policy handle */
2553 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2555 MAXIMUM_ALLOWED_ACCESS
,
2556 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2558 if (!NT_STATUS_IS_OK(result
)) {
2561 /* query builtin aliases */
2564 if (!builtin
) break;
2566 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2572 if (!NT_STATUS_IS_OK(result
) &&
2573 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2576 for (i
= 0; i
< num_entries
; i
++) {
2578 const char *description
= NULL
;
2580 if (opt_long_list_entries
) {
2582 POLICY_HND alias_pol
;
2583 union samr_AliasInfo
*info
= NULL
;
2585 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2588 groups
->entries
[i
].idx
,
2590 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2594 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2596 description
= info
->description
.string
;
2600 if (description
!= NULL
) {
2601 printf("%-21.21s %-50.50s\n",
2602 groups
->entries
[i
].name
.string
,
2605 printf("%s\n", groups
->entries
[i
].name
.string
);
2608 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2614 static int rpc_group_list(int argc
, const char **argv
)
2616 return run_rpc_command(NULL
, PI_SAMR
, 0,
2617 rpc_group_list_internals
,
2621 static NTSTATUS
rpc_list_group_members(struct rpc_pipe_client
*pipe_hnd
,
2622 TALLOC_CTX
*mem_ctx
,
2623 const char *domain_name
,
2624 const DOM_SID
*domain_sid
,
2625 POLICY_HND
*domain_pol
,
2629 POLICY_HND group_pol
;
2630 uint32 num_members
, *group_rids
;
2632 struct samr_RidTypeArray
*rids
= NULL
;
2633 struct lsa_Strings names
;
2634 struct samr_Ids types
;
2637 sid_to_fstring(sid_str
, domain_sid
);
2639 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2641 MAXIMUM_ALLOWED_ACCESS
,
2645 if (!NT_STATUS_IS_OK(result
))
2648 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2652 if (!NT_STATUS_IS_OK(result
))
2655 num_members
= rids
->count
;
2656 group_rids
= rids
->rids
;
2658 while (num_members
> 0) {
2659 int this_time
= 512;
2661 if (num_members
< this_time
)
2662 this_time
= num_members
;
2664 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2671 if (!NT_STATUS_IS_OK(result
))
2674 /* We only have users as members, but make the output
2675 the same as the output of alias members */
2677 for (i
= 0; i
< this_time
; i
++) {
2679 if (opt_long_list_entries
) {
2680 printf("%s-%d %s\\%s %d\n", sid_str
,
2681 group_rids
[i
], domain_name
,
2682 names
.names
[i
].string
,
2685 printf("%s\\%s\n", domain_name
,
2686 names
.names
[i
].string
);
2690 num_members
-= this_time
;
2694 return NT_STATUS_OK
;
2697 static NTSTATUS
rpc_list_alias_members(struct rpc_pipe_client
*pipe_hnd
,
2698 TALLOC_CTX
*mem_ctx
,
2699 POLICY_HND
*domain_pol
,
2703 struct rpc_pipe_client
*lsa_pipe
;
2704 POLICY_HND alias_pol
, lsa_pol
;
2706 DOM_SID
*alias_sids
;
2709 enum lsa_SidType
*types
;
2711 struct lsa_SidArray sid_array
;
2713 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2715 MAXIMUM_ALLOWED_ACCESS
,
2719 if (!NT_STATUS_IS_OK(result
))
2722 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2726 if (!NT_STATUS_IS_OK(result
)) {
2727 d_fprintf(stderr
, "Couldn't list alias members\n");
2731 num_members
= sid_array
.num_sids
;
2733 if (num_members
== 0) {
2734 return NT_STATUS_OK
;
2737 lsa_pipe
= cli_rpc_pipe_open_noauth(pipe_hnd
->cli
, PI_LSARPC
, &result
);
2739 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2740 nt_errstr(result
) );
2744 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, True
,
2745 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2747 if (!NT_STATUS_IS_OK(result
)) {
2748 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2749 cli_rpc_pipe_close(lsa_pipe
);
2753 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2755 d_fprintf(stderr
, "Out of memory\n");
2756 cli_rpc_pipe_close(lsa_pipe
);
2757 return NT_STATUS_NO_MEMORY
;
2760 for (i
=0; i
<num_members
; i
++) {
2761 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2764 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
, num_members
,
2766 &domains
, &names
, &types
);
2768 if (!NT_STATUS_IS_OK(result
) &&
2769 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2770 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2771 cli_rpc_pipe_close(lsa_pipe
);
2775 for (i
= 0; i
< num_members
; i
++) {
2777 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2779 if (opt_long_list_entries
) {
2780 printf("%s %s\\%s %d\n", sid_str
,
2781 domains
[i
] ? domains
[i
] : "*unknown*",
2782 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2785 printf("%s\\%s\n", domains
[i
], names
[i
]);
2787 printf("%s\n", sid_str
);
2791 cli_rpc_pipe_close(lsa_pipe
);
2792 return NT_STATUS_OK
;
2795 static NTSTATUS
rpc_group_members_internals(const DOM_SID
*domain_sid
,
2796 const char *domain_name
,
2797 struct cli_state
*cli
,
2798 struct rpc_pipe_client
*pipe_hnd
,
2799 TALLOC_CTX
*mem_ctx
,
2804 POLICY_HND connect_pol
, domain_pol
;
2805 struct samr_Ids rids
, rid_types
;
2806 struct lsa_String lsa_acct_name
;
2808 /* Get sam policy handle */
2810 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2811 pipe_hnd
->cli
->desthost
,
2812 MAXIMUM_ALLOWED_ACCESS
,
2815 if (!NT_STATUS_IS_OK(result
))
2818 /* Get domain policy handle */
2820 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2822 MAXIMUM_ALLOWED_ACCESS
,
2823 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2826 if (!NT_STATUS_IS_OK(result
))
2829 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2831 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2838 if (!NT_STATUS_IS_OK(result
)) {
2840 /* Ok, did not find it in the global sam, try with builtin */
2842 DOM_SID sid_Builtin
;
2844 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2846 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2848 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2850 MAXIMUM_ALLOWED_ACCESS
,
2854 if (!NT_STATUS_IS_OK(result
)) {
2855 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2859 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2866 if (!NT_STATUS_IS_OK(result
)) {
2867 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2872 if (rids
.count
!= 1) {
2873 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2877 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2878 return rpc_list_group_members(pipe_hnd
, mem_ctx
, domain_name
,
2879 domain_sid
, &domain_pol
,
2883 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2884 return rpc_list_alias_members(pipe_hnd
, mem_ctx
, &domain_pol
,
2888 return NT_STATUS_NO_SUCH_GROUP
;
2891 static int rpc_group_members(int argc
, const char **argv
)
2894 return rpc_group_usage(argc
, argv
);
2897 return run_rpc_command(NULL
, PI_SAMR
, 0,
2898 rpc_group_members_internals
,
2902 static NTSTATUS
rpc_group_rename_internals(const DOM_SID
*domain_sid
,
2903 const char *domain_name
,
2904 struct cli_state
*cli
,
2905 struct rpc_pipe_client
*pipe_hnd
,
2906 TALLOC_CTX
*mem_ctx
,
2911 POLICY_HND connect_pol
, domain_pol
, group_pol
;
2912 union samr_GroupInfo group_info
;
2913 struct samr_Ids rids
, rid_types
;
2914 struct lsa_String lsa_acct_name
;
2917 d_printf("Usage: 'net rpc group rename group newname'\n");
2918 return NT_STATUS_UNSUCCESSFUL
;
2921 /* Get sam policy handle */
2923 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2924 pipe_hnd
->cli
->desthost
,
2925 MAXIMUM_ALLOWED_ACCESS
,
2928 if (!NT_STATUS_IS_OK(result
))
2931 /* Get domain policy handle */
2933 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2935 MAXIMUM_ALLOWED_ACCESS
,
2936 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2939 if (!NT_STATUS_IS_OK(result
))
2942 init_lsa_String(&lsa_acct_name
, argv
[0]);
2944 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2951 if (rids
.count
!= 1) {
2952 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2956 if (rid_types
.ids
[0] != SID_NAME_DOM_GRP
) {
2957 d_fprintf(stderr
, "Can only rename domain groups\n");
2958 return NT_STATUS_UNSUCCESSFUL
;
2961 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2963 MAXIMUM_ALLOWED_ACCESS
,
2967 if (!NT_STATUS_IS_OK(result
))
2970 init_lsa_String(&group_info
.name
, argv
[1]);
2972 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
2977 if (!NT_STATUS_IS_OK(result
))
2980 return NT_STATUS_NO_SUCH_GROUP
;
2983 static int rpc_group_rename(int argc
, const char **argv
)
2986 return rpc_group_usage(argc
, argv
);
2989 return run_rpc_command(NULL
, PI_SAMR
, 0,
2990 rpc_group_rename_internals
,
2995 * 'net rpc group' entrypoint.
2996 * @param argc Standard main() style argc.
2997 * @param argv Standard main() style argv. Initial components are already
3001 int net_rpc_group(int argc
, const char **argv
)
3003 struct functable func
[] = {
3004 {"add", rpc_group_add
},
3005 {"delete", rpc_group_delete
},
3006 {"addmem", rpc_group_addmem
},
3007 {"delmem", rpc_group_delmem
},
3008 {"list", rpc_group_list
},
3009 {"members", rpc_group_members
},
3010 {"rename", rpc_group_rename
},
3015 return run_rpc_command(NULL
, PI_SAMR
, 0,
3016 rpc_group_list_internals
,
3020 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
3023 /****************************************************************************/
3025 static int rpc_share_usage(int argc
, const char **argv
)
3027 return net_help_share(argc
, argv
);
3031 * Add a share on a remote RPC server.
3033 * All parameters are provided by the run_rpc_command function, except for
3034 * argc, argv which are passed through.
3036 * @param domain_sid The domain sid acquired from the remote server.
3037 * @param cli A cli_state connected to the server.
3038 * @param mem_ctx Talloc context, destroyed on completion of the function.
3039 * @param argc Standard main() style argc.
3040 * @param argv Standard main() style argv. Initial components are already
3043 * @return Normal NTSTATUS return.
3045 static NTSTATUS
rpc_share_add_internals(const DOM_SID
*domain_sid
,
3046 const char *domain_name
,
3047 struct cli_state
*cli
,
3048 struct rpc_pipe_client
*pipe_hnd
,
3049 TALLOC_CTX
*mem_ctx
,int argc
,
3056 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3057 uint32 num_users
=0, perms
=0;
3058 char *password
=NULL
; /* don't allow a share password */
3060 union srvsvc_NetShareInfo info
;
3061 struct srvsvc_NetShareInfo2 info2
;
3062 uint32_t parm_error
= 0;
3064 if ((sharename
= talloc_strdup(mem_ctx
, argv
[0])) == NULL
) {
3065 return NT_STATUS_NO_MEMORY
;
3068 path
= strchr(sharename
, '=');
3070 return NT_STATUS_UNSUCCESSFUL
;
3073 info2
.name
= sharename
;
3075 info2
.comment
= opt_comment
;
3076 info2
.permissions
= perms
;
3077 info2
.max_users
= opt_maxusers
;
3078 info2
.current_users
= num_users
;
3080 info2
.password
= password
;
3082 info
.info2
= &info2
;
3084 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
3085 pipe_hnd
->cli
->desthost
,
3093 static int rpc_share_add(int argc
, const char **argv
)
3095 if ((argc
< 1) || !strchr(argv
[0], '=')) {
3096 DEBUG(1,("Sharename or path not specified on add\n"));
3097 return rpc_share_usage(argc
, argv
);
3099 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3100 rpc_share_add_internals
,
3105 * Delete a share on a remote RPC server.
3107 * All parameters are provided by the run_rpc_command function, except for
3108 * argc, argv which are passed through.
3110 * @param domain_sid The domain sid acquired from the remote server.
3111 * @param cli A cli_state connected to the server.
3112 * @param mem_ctx Talloc context, destroyed on completion of the function.
3113 * @param argc Standard main() style argc.
3114 * @param argv Standard main() style argv. Initial components are already
3117 * @return Normal NTSTATUS return.
3119 static NTSTATUS
rpc_share_del_internals(const DOM_SID
*domain_sid
,
3120 const char *domain_name
,
3121 struct cli_state
*cli
,
3122 struct rpc_pipe_client
*pipe_hnd
,
3123 TALLOC_CTX
*mem_ctx
,
3129 return rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
3130 pipe_hnd
->cli
->desthost
,
3137 * Delete a share on a remote RPC server.
3139 * @param domain_sid The domain sid acquired from the remote server.
3140 * @param argc Standard main() style argc.
3141 * @param argv Standard main() style argv. Initial components are already
3144 * @return A shell status integer (0 for success).
3146 static int rpc_share_delete(int argc
, const char **argv
)
3149 DEBUG(1,("Sharename not specified on delete\n"));
3150 return rpc_share_usage(argc
, argv
);
3152 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3153 rpc_share_del_internals
,
3158 * Formatted print of share info
3160 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3163 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
3165 if (opt_long_list_entries
) {
3166 d_printf("%-12s %-8.8s %-50s\n",
3168 share_type
[r
->type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)],
3171 d_printf("%s\n", r
->name
);
3175 static WERROR
get_share_info(struct rpc_pipe_client
*pipe_hnd
,
3176 TALLOC_CTX
*mem_ctx
,
3180 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3184 union srvsvc_NetShareInfo info
;
3186 /* no specific share requested, enumerate all */
3189 uint32_t preferred_len
= 0xffffffff;
3190 uint32_t total_entries
= 0;
3191 uint32_t resume_handle
= 0;
3193 info_ctr
->level
= level
;
3195 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
3196 pipe_hnd
->cli
->desthost
,
3205 /* request just one share */
3206 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
3207 pipe_hnd
->cli
->desthost
,
3213 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
3218 ZERO_STRUCTP(info_ctr
);
3220 info_ctr
->level
= level
;
3225 struct srvsvc_NetShareCtr1
*ctr1
;
3227 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
3228 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3231 ctr1
->array
= info
.info1
;
3233 info_ctr
->ctr
.ctr1
= ctr1
;
3237 struct srvsvc_NetShareCtr2
*ctr2
;
3239 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
3240 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3243 ctr2
->array
= info
.info2
;
3245 info_ctr
->ctr
.ctr2
= ctr2
;
3249 struct srvsvc_NetShareCtr502
*ctr502
;
3251 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3252 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3255 ctr502
->array
= info
.info502
;
3257 info_ctr
->ctr
.ctr502
= ctr502
;
3265 * List shares on a remote RPC server.
3267 * All parameters are provided by the run_rpc_command function, except for
3268 * argc, argv which are passed through.
3270 * @param domain_sid The domain sid acquired from the remote server.
3271 * @param cli A cli_state connected to the server.
3272 * @param mem_ctx Talloc context, destroyed on completion of the function.
3273 * @param argc Standard main() style argc.
3274 * @param argv Standard main() style argv. Initial components are already
3277 * @return Normal NTSTATUS return.
3280 static NTSTATUS
rpc_share_list_internals(const DOM_SID
*domain_sid
,
3281 const char *domain_name
,
3282 struct cli_state
*cli
,
3283 struct rpc_pipe_client
*pipe_hnd
,
3284 TALLOC_CTX
*mem_ctx
,
3288 struct srvsvc_NetShareInfoCtr info_ctr
;
3289 struct srvsvc_NetShareCtr1 ctr1
;
3291 uint32 i
, level
= 1;
3293 ZERO_STRUCT(info_ctr
);
3297 info_ctr
.ctr
.ctr1
= &ctr1
;
3299 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &info_ctr
);
3300 if (!W_ERROR_IS_OK(result
))
3303 /* Display results */
3305 if (opt_long_list_entries
) {
3307 "\nEnumerating shared resources (exports) on remote server:\n\n"\
3308 "\nShare name Type Description\n"\
3309 "---------- ---- -----------\n");
3311 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++)
3312 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
3314 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3318 * 'net rpc share list' entrypoint.
3319 * @param argc Standard main() style argc
3320 * @param argv Standard main() style argv. Initial components are already
3323 static int rpc_share_list(int argc
, const char **argv
)
3325 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_list_internals
, argc
, argv
);
3328 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3330 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3331 d_printf("skipping [%s]: not a file share.\n", netname
);
3341 static bool check_share_sanity(struct cli_state
*cli
, const char *netname
, uint32 type
)
3343 /* only support disk shares */
3344 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3345 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3349 /* skip builtin shares */
3350 /* FIXME: should print$ be added too ? */
3351 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3352 strequal(netname
,"global"))
3355 if (opt_exclude
&& in_list(netname
, opt_exclude
, False
)) {
3356 printf("excluding [%s]\n", netname
);
3360 return check_share_availability(cli
, netname
);
3364 * Migrate shares from a remote RPC server to the local RPC server.
3366 * All parameters are provided by the run_rpc_command function, except for
3367 * argc, argv which are passed through.
3369 * @param domain_sid The domain sid acquired from the remote server.
3370 * @param cli A cli_state connected to the server.
3371 * @param mem_ctx Talloc context, destroyed on completion of the function.
3372 * @param argc Standard main() style argc.
3373 * @param argv Standard main() style argv. Initial components are already
3376 * @return Normal NTSTATUS return.
3379 static NTSTATUS
rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
,
3380 const char *domain_name
,
3381 struct cli_state
*cli
,
3382 struct rpc_pipe_client
*pipe_hnd
,
3383 TALLOC_CTX
*mem_ctx
,
3388 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3389 struct srvsvc_NetShareInfoCtr ctr_src
;
3391 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3392 struct cli_state
*cli_dst
= NULL
;
3393 uint32 level
= 502; /* includes secdesc */
3394 uint32_t parm_error
= 0;
3396 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3397 if (!W_ERROR_IS_OK(result
))
3400 /* connect destination PI_SRVSVC */
3401 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3402 if (!NT_STATUS_IS_OK(nt_status
))
3406 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3408 union srvsvc_NetShareInfo info
;
3409 struct srvsvc_NetShareInfo502 info502
=
3410 ctr_src
.ctr
.ctr502
->array
[i
];
3412 /* reset error-code */
3413 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3415 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3418 /* finally add the share on the dst server */
3420 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3421 info502
.name
, info502
.path
, info502
.comment
);
3423 info
.info502
= &info502
;
3425 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3426 srvsvc_pipe
->cli
->desthost
,
3432 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3433 printf(" [%s] does already exist\n",
3438 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3439 printf("cannot add share: %s\n", dos_errstr(result
));
3445 nt_status
= NT_STATUS_OK
;
3449 cli_shutdown(cli_dst
);
3457 * Migrate shares from a rpc-server to another.
3459 * @param argc Standard main() style argc.
3460 * @param argv Standard main() style argv. Initial components are already
3463 * @return A shell status integer (0 for success).
3465 static int rpc_share_migrate_shares(int argc
, const char **argv
)
3469 printf("no server to migrate\n");
3473 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3474 rpc_share_migrate_shares_internals
,
3481 * @param f file_info
3482 * @param mask current search mask
3483 * @param state arg-pointer
3486 static void copy_fn(const char *mnt
, file_info
*f
, const char *mask
, void *state
)
3488 static NTSTATUS nt_status
;
3489 static struct copy_clistate
*local_state
;
3490 static fstring filename
, new_mask
;
3494 local_state
= (struct copy_clistate
*)state
;
3495 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3497 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3500 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3503 if (f
->mode
& aDIR
) {
3505 DEBUG(3,("got dir: %s\n", f
->name
));
3507 fstrcpy(dir
, local_state
->cwd
);
3509 fstrcat(dir
, f
->name
);
3511 switch (net_mode_share
)
3513 case NET_MODE_SHARE_MIGRATE
:
3514 /* create that directory */
3515 nt_status
= net_copy_file(local_state
->mem_ctx
,
3516 local_state
->cli_share_src
,
3517 local_state
->cli_share_dst
,
3519 opt_acls
? True
: False
,
3520 opt_attrs
? True
: False
,
3521 opt_timestamps
? True
: False
,
3525 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3529 if (!NT_STATUS_IS_OK(nt_status
))
3530 printf("could not handle dir %s: %s\n",
3531 dir
, nt_errstr(nt_status
));
3533 /* search below that directory */
3534 fstrcpy(new_mask
, dir
);
3535 fstrcat(new_mask
, "\\*");
3537 old_dir
= local_state
->cwd
;
3538 local_state
->cwd
= dir
;
3539 if (!sync_files(local_state
, new_mask
))
3540 printf("could not handle files\n");
3541 local_state
->cwd
= old_dir
;
3548 fstrcpy(filename
, local_state
->cwd
);
3549 fstrcat(filename
, "\\");
3550 fstrcat(filename
, f
->name
);
3552 DEBUG(3,("got file: %s\n", filename
));
3554 switch (net_mode_share
)
3556 case NET_MODE_SHARE_MIGRATE
:
3557 nt_status
= net_copy_file(local_state
->mem_ctx
,
3558 local_state
->cli_share_src
,
3559 local_state
->cli_share_dst
,
3561 opt_acls
? True
: False
,
3562 opt_attrs
? True
: False
,
3563 opt_timestamps
? True
: False
,
3567 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3571 if (!NT_STATUS_IS_OK(nt_status
))
3572 printf("could not handle file %s: %s\n",
3573 filename
, nt_errstr(nt_status
));
3578 * sync files, can be called recursivly to list files
3579 * and then call copy_fn for each file
3581 * @param cp_clistate pointer to the copy_clistate we work with
3582 * @param mask the current search mask
3584 * @return Boolean result
3586 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3588 struct cli_state
*targetcli
;
3589 char *targetpath
= NULL
;
3591 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3593 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate
->cli_share_src
,
3594 mask
, &targetcli
, &targetpath
) ) {
3595 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3596 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3600 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3601 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3602 mask
, cli_errstr(targetcli
));
3611 * Set the top level directory permissions before we do any further copies.
3612 * Should set up ACL inheritance.
3615 bool copy_top_level_perms(struct copy_clistate
*cp_clistate
,
3616 const char *sharename
)
3618 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3620 switch (net_mode_share
) {
3621 case NET_MODE_SHARE_MIGRATE
:
3622 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3623 nt_status
= net_copy_fileattr(cp_clistate
->mem_ctx
,
3624 cp_clistate
->cli_share_src
,
3625 cp_clistate
->cli_share_dst
,
3627 opt_acls
? True
: False
,
3628 opt_attrs
? True
: False
,
3629 opt_timestamps
? True
: False
,
3633 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3637 if (!NT_STATUS_IS_OK(nt_status
)) {
3638 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3639 sharename
, nt_errstr(nt_status
));
3647 * Sync all files inside a remote share to another share (over smb).
3649 * All parameters are provided by the run_rpc_command function, except for
3650 * argc, argv which are passed through.
3652 * @param domain_sid The domain sid acquired from the remote server.
3653 * @param cli A cli_state connected to the server.
3654 * @param mem_ctx Talloc context, destroyed on completion of the function.
3655 * @param argc Standard main() style argc.
3656 * @param argv Standard main() style argv. Initial components are already
3659 * @return Normal NTSTATUS return.
3662 static NTSTATUS
rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
,
3663 const char *domain_name
,
3664 struct cli_state
*cli
,
3665 struct rpc_pipe_client
*pipe_hnd
,
3666 TALLOC_CTX
*mem_ctx
,
3671 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3672 struct srvsvc_NetShareInfoCtr ctr_src
;
3675 struct copy_clistate cp_clistate
;
3676 bool got_src_share
= False
;
3677 bool got_dst_share
= False
;
3678 const char *mask
= "\\*";
3681 dst
= SMB_STRDUP(opt_destination
?opt_destination
:"127.0.0.1");
3683 nt_status
= NT_STATUS_NO_MEMORY
;
3687 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3689 if (!W_ERROR_IS_OK(result
))
3692 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3694 struct srvsvc_NetShareInfo502 info502
=
3695 ctr_src
.ctr
.ctr502
->array
[i
];
3697 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3700 /* one might not want to mirror whole discs :) */
3701 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3702 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3706 switch (net_mode_share
)
3708 case NET_MODE_SHARE_MIGRATE
:
3712 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3715 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3717 opt_acls
? "including" : "without",
3718 opt_attrs
? "including" : "without",
3719 opt_timestamps
? "(preserving timestamps)" : "");
3721 cp_clistate
.mem_ctx
= mem_ctx
;
3722 cp_clistate
.cli_share_src
= NULL
;
3723 cp_clistate
.cli_share_dst
= NULL
;
3724 cp_clistate
.cwd
= NULL
;
3725 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3727 /* open share source */
3728 nt_status
= connect_to_service(&cp_clistate
.cli_share_src
,
3729 &cli
->dest_ss
, cli
->desthost
,
3730 info502
.name
, "A:");
3731 if (!NT_STATUS_IS_OK(nt_status
))
3734 got_src_share
= True
;
3736 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3737 /* open share destination */
3738 nt_status
= connect_to_service(&cp_clistate
.cli_share_dst
,
3739 NULL
, dst
, info502
.name
, "A:");
3740 if (!NT_STATUS_IS_OK(nt_status
))
3743 got_dst_share
= True
;
3746 if (!copy_top_level_perms(&cp_clistate
, info502
.name
)) {
3747 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3748 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3752 if (!sync_files(&cp_clistate
, mask
)) {
3753 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3754 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3759 nt_status
= NT_STATUS_OK
;
3764 cli_shutdown(cp_clistate
.cli_share_src
);
3767 cli_shutdown(cp_clistate
.cli_share_dst
);
3774 static int rpc_share_migrate_files(int argc
, const char **argv
)
3778 printf("no server to migrate\n");
3782 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3783 rpc_share_migrate_files_internals
,
3788 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3790 * All parameters are provided by the run_rpc_command function, except for
3791 * argc, argv which are passed through.
3793 * @param domain_sid The domain sid acquired from the remote server.
3794 * @param cli A cli_state connected to the server.
3795 * @param mem_ctx Talloc context, destroyed on completion of the function.
3796 * @param argc Standard main() style argc.
3797 * @param argv Standard main() style argv. Initial components are already
3800 * @return Normal NTSTATUS return.
3803 static NTSTATUS
rpc_share_migrate_security_internals(const DOM_SID
*domain_sid
,
3804 const char *domain_name
,
3805 struct cli_state
*cli
,
3806 struct rpc_pipe_client
*pipe_hnd
,
3807 TALLOC_CTX
*mem_ctx
,
3812 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3813 struct srvsvc_NetShareInfoCtr ctr_src
;
3814 union srvsvc_NetShareInfo info
;
3816 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3817 struct cli_state
*cli_dst
= NULL
;
3818 uint32 level
= 502; /* includes secdesc */
3819 uint32_t parm_error
= 0;
3821 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3823 if (!W_ERROR_IS_OK(result
))
3826 /* connect destination PI_SRVSVC */
3827 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3828 if (!NT_STATUS_IS_OK(nt_status
))
3832 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3834 struct srvsvc_NetShareInfo502 info502
=
3835 ctr_src
.ctr
.ctr502
->array
[i
];
3837 /* reset error-code */
3838 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3840 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3843 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3844 info502
.name
, info502
.path
, info502
.comment
);
3847 display_sec_desc(info502
.sd_buf
.sd
);
3849 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3850 info
.info502
= &info502
;
3852 /* finally modify the share on the dst server */
3853 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3854 srvsvc_pipe
->cli
->desthost
,
3860 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3861 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3867 nt_status
= NT_STATUS_OK
;
3871 cli_shutdown(cli_dst
);
3879 * Migrate share-acls from a rpc-server to another.
3881 * @param argc Standard main() style argc.
3882 * @param argv Standard main() style argv. Initial components are already
3885 * @return A shell status integer (0 for success)
3887 static int rpc_share_migrate_security(int argc
, const char **argv
)
3891 printf("no server to migrate\n");
3895 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3896 rpc_share_migrate_security_internals
,
3901 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3902 * from one server to another
3904 * @param argc Standard main() style argc.
3905 * @param argv Standard main() style argv. Initial components are already
3908 * @return A shell status integer (0 for success)
3911 static int rpc_share_migrate_all(int argc
, const char **argv
)
3916 printf("no server to migrate\n");
3920 /* order is important. we don't want to be locked out by the share-acl
3921 * before copying files - gd */
3923 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
3927 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
3931 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_security_internals
, argc
, argv
);
3936 * 'net rpc share migrate' entrypoint.
3937 * @param argc Standard main() style argc.
3938 * @param argv Standard main() style argv. Initial components are already
3941 static int rpc_share_migrate(int argc
, const char **argv
)
3944 struct functable func
[] = {
3945 {"all", rpc_share_migrate_all
},
3946 {"files", rpc_share_migrate_files
},
3947 {"help", rpc_share_usage
},
3948 {"security", rpc_share_migrate_security
},
3949 {"shares", rpc_share_migrate_shares
},
3953 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3955 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
3964 static int num_server_aliases
;
3965 static struct full_alias
*server_aliases
;
3968 * Add an alias to the static list.
3970 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3972 if (server_aliases
== NULL
)
3973 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3975 server_aliases
[num_server_aliases
] = *alias
;
3976 num_server_aliases
+= 1;
3980 * For a specific domain on the server, fetch all the aliases
3981 * and their members. Add all of them to the server_aliases.
3984 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3985 TALLOC_CTX
*mem_ctx
,
3986 POLICY_HND
*connect_pol
,
3987 const DOM_SID
*domain_sid
)
3989 uint32 start_idx
, max_entries
, num_entries
, i
;
3990 struct samr_SamArray
*groups
= NULL
;
3992 POLICY_HND domain_pol
;
3994 /* Get domain policy handle */
3996 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3998 MAXIMUM_ALLOWED_ACCESS
,
3999 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
4001 if (!NT_STATUS_IS_OK(result
))
4008 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
4014 for (i
= 0; i
< num_entries
; i
++) {
4016 POLICY_HND alias_pol
;
4017 struct full_alias alias
;
4018 struct lsa_SidArray sid_array
;
4021 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
4023 MAXIMUM_ALLOWED_ACCESS
,
4024 groups
->entries
[i
].idx
,
4026 if (!NT_STATUS_IS_OK(result
))
4029 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
4032 if (!NT_STATUS_IS_OK(result
))
4035 alias
.num_members
= sid_array
.num_sids
;
4037 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
4038 if (!NT_STATUS_IS_OK(result
))
4041 alias
.members
= NULL
;
4043 if (alias
.num_members
> 0) {
4044 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
4046 for (j
= 0; j
< alias
.num_members
; j
++)
4047 sid_copy(&alias
.members
[j
],
4048 sid_array
.sids
[j
].sid
);
4051 sid_copy(&alias
.sid
, domain_sid
);
4052 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
4054 push_alias(mem_ctx
, &alias
);
4056 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4058 result
= NT_STATUS_OK
;
4061 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
4067 * Dump server_aliases as names for debugging purposes.
4070 static NTSTATUS
rpc_aliaslist_dump(const DOM_SID
*domain_sid
,
4071 const char *domain_name
,
4072 struct cli_state
*cli
,
4073 struct rpc_pipe_client
*pipe_hnd
,
4074 TALLOC_CTX
*mem_ctx
,
4082 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, True
,
4083 SEC_RIGHTS_MAXIMUM_ALLOWED
,
4085 if (!NT_STATUS_IS_OK(result
))
4088 for (i
=0; i
<num_server_aliases
; i
++) {
4091 enum lsa_SidType
*types
;
4094 struct full_alias
*alias
= &server_aliases
[i
];
4096 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4098 &domains
, &names
, &types
);
4099 if (!NT_STATUS_IS_OK(result
))
4102 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4104 if (alias
->num_members
== 0) {
4109 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4112 &domains
, &names
, &types
);
4114 if (!NT_STATUS_IS_OK(result
) &&
4115 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4118 for (j
=0; j
<alias
->num_members
; j
++)
4119 DEBUG(1, ("%s\\%s (%d); ",
4120 domains
[j
] ? domains
[j
] : "*unknown*",
4121 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4125 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4127 return NT_STATUS_OK
;
4131 * Fetch a list of all server aliases and their members into
4135 static NTSTATUS
rpc_aliaslist_internals(const DOM_SID
*domain_sid
,
4136 const char *domain_name
,
4137 struct cli_state
*cli
,
4138 struct rpc_pipe_client
*pipe_hnd
,
4139 TALLOC_CTX
*mem_ctx
,
4144 POLICY_HND connect_pol
;
4146 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4147 pipe_hnd
->cli
->desthost
,
4148 MAXIMUM_ALLOWED_ACCESS
,
4151 if (!NT_STATUS_IS_OK(result
))
4154 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4155 &global_sid_Builtin
);
4157 if (!NT_STATUS_IS_OK(result
))
4160 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4163 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4168 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4170 token
->num_sids
= 4;
4172 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4173 d_fprintf(stderr
, "malloc failed\n");
4174 token
->num_sids
= 0;
4178 token
->user_sids
[0] = *user_sid
;
4179 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4180 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4181 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4184 static void free_user_token(NT_USER_TOKEN
*token
)
4186 SAFE_FREE(token
->user_sids
);
4189 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4191 if (is_sid_in_token(token
, sid
))
4194 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4195 if (!token
->user_sids
) {
4199 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4201 token
->num_sids
+= 1;
4206 NT_USER_TOKEN token
;
4209 static void dump_user_token(struct user_token
*token
)
4213 d_printf("%s\n", token
->name
);
4215 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4216 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4220 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4224 for (i
=0; i
<alias
->num_members
; i
++) {
4225 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4232 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4236 for (i
=0; i
<num_server_aliases
; i
++) {
4237 if (is_alias_member(&sid
, &server_aliases
[i
]))
4238 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4243 * We got a user token with all the SIDs we can know about without asking the
4244 * server directly. These are the user and domain group sids. All of these can
4245 * be members of aliases. So scan the list of aliases for each of the SIDs and
4246 * add them to the token.
4249 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4251 int num_global_sids
= token
->num_sids
;
4254 for (i
=0; i
<num_global_sids
; i
++) {
4255 collect_sid_memberships(token
, token
->user_sids
[i
]);
4259 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4261 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4262 enum wbcSidType type
;
4264 struct wbcDomainSid wsid
;
4265 char *sid_str
= NULL
;
4267 uint32_t num_groups
;
4268 gid_t
*groups
= NULL
;
4271 fstr_sprintf(full_name
, "%s%c%s",
4272 domain
, *lp_winbind_separator(), user
);
4274 /* First let's find out the user sid */
4276 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4278 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4279 DEBUG(1, ("winbind could not find %s: %s\n",
4280 full_name
, wbcErrorString(wbc_status
)));
4284 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4285 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4289 if (type
!= SID_NAME_USER
) {
4290 wbcFreeMemory(sid_str
);
4291 DEBUG(1, ("%s is not a user\n", full_name
));
4295 string_to_sid(&user_sid
, sid_str
);
4296 wbcFreeMemory(sid_str
);
4299 init_user_token(token
, &user_sid
);
4301 /* And now the groups winbind knows about */
4303 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4304 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4305 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4306 full_name
, wbcErrorString(wbc_status
)));
4310 for (i
= 0; i
< num_groups
; i
++) {
4311 gid_t gid
= groups
[i
];
4314 wbc_status
= wbcGidToSid(gid
, &wsid
);
4315 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4316 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4317 gid
, wbcErrorString(wbc_status
)));
4318 wbcFreeMemory(groups
);
4322 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4323 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4324 wbcFreeMemory(groups
);
4328 DEBUG(3, (" %s\n", sid_str
));
4330 string_to_sid(&sid
, sid_str
);
4331 wbcFreeMemory(sid_str
);
4334 add_sid_to_token(token
, &sid
);
4336 wbcFreeMemory(groups
);
4342 * Get a list of all user tokens we want to look at
4345 static bool get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
4347 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4348 uint32_t i
, num_users
;
4350 struct user_token
*result
;
4351 TALLOC_CTX
*frame
= NULL
;
4353 if (lp_winbind_use_default_domain() &&
4354 (opt_target_workgroup
== NULL
)) {
4355 d_fprintf(stderr
, "winbind use default domain = yes set, "
4356 "please specify a workgroup\n");
4360 /* Send request to winbind daemon */
4362 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4363 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4364 DEBUG(1, ("winbind could not list users: %s\n",
4365 wbcErrorString(wbc_status
)));
4369 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4371 if (result
== NULL
) {
4372 DEBUG(1, ("Could not malloc sid array\n"));
4373 wbcFreeMemory(users
);
4377 frame
= talloc_stackframe();
4378 for (i
=0; i
< num_users
; i
++) {
4379 fstring domain
, user
;
4382 fstrcpy(result
[i
].name
, users
[i
]);
4384 p
= strchr(users
[i
], *lp_winbind_separator());
4386 DEBUG(3, ("%s\n", users
[i
]));
4389 fstrcpy(domain
, opt_target_workgroup
);
4390 fstrcpy(user
, users
[i
]);
4393 fstrcpy(domain
, users
[i
]);
4398 get_user_sids(domain
, user
, &(result
[i
].token
));
4402 wbcFreeMemory(users
);
4404 *num_tokens
= num_users
;
4405 *user_tokens
= result
;
4410 static bool get_user_tokens_from_file(FILE *f
,
4412 struct user_token
**tokens
)
4414 struct user_token
*token
= NULL
;
4419 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4423 if (line
[strlen(line
)-1] == '\n')
4424 line
[strlen(line
)-1] = '\0';
4426 if (line
[0] == ' ') {
4430 string_to_sid(&sid
, &line
[1]);
4432 if (token
== NULL
) {
4433 DEBUG(0, ("File does not begin with username"));
4437 add_sid_to_token(&token
->token
, &sid
);
4441 /* And a new user... */
4444 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4445 if (*tokens
== NULL
) {
4446 DEBUG(0, ("Could not realloc tokens\n"));
4450 token
= &((*tokens
)[*num_tokens
-1]);
4452 fstrcpy(token
->name
, line
);
4453 token
->token
.num_sids
= 0;
4454 token
->token
.user_sids
= NULL
;
4463 * Show the list of all users that have access to a share
4466 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4467 TALLOC_CTX
*mem_ctx
,
4468 const char *netname
,
4470 struct user_token
*tokens
)
4473 SEC_DESC
*share_sd
= NULL
;
4474 SEC_DESC
*root_sd
= NULL
;
4475 struct cli_state
*cli
= pipe_hnd
->cli
;
4477 union srvsvc_NetShareInfo info
;
4482 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4483 pipe_hnd
->cli
->desthost
,
4489 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4490 DEBUG(1, ("Coult not query secdesc for share %s\n",
4495 share_sd
= info
.info502
->sd_buf
.sd
;
4496 if (share_sd
== NULL
) {
4497 DEBUG(1, ("Got no secdesc for share %s\n",
4503 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4507 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4510 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4513 for (i
=0; i
<num_tokens
; i
++) {
4516 if (share_sd
!= NULL
) {
4517 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4518 1, &acc_granted
, &status
)) {
4519 DEBUG(1, ("Could not check share_sd for "
4525 if (!NT_STATUS_IS_OK(status
))
4529 if (root_sd
== NULL
) {
4530 d_printf(" %s\n", tokens
[i
].name
);
4534 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4535 1, &acc_granted
, &status
)) {
4536 DEBUG(1, ("Could not check root_sd for user %s\n",
4541 if (!NT_STATUS_IS_OK(status
))
4544 d_printf(" %s\n", tokens
[i
].name
);
4548 cli_close(cli
, fnum
);
4560 static void collect_share(const char *name
, uint32 m
,
4561 const char *comment
, void *state
)
4563 struct share_list
*share_list
= (struct share_list
*)state
;
4565 if (m
!= STYPE_DISKTREE
)
4568 share_list
->num_shares
+= 1;
4569 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4570 if (!share_list
->shares
) {
4571 share_list
->num_shares
= 0;
4574 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4577 static void rpc_share_userlist_usage(void)
4583 * List shares on a remote RPC server, including the security descriptors.
4585 * All parameters are provided by the run_rpc_command function, except for
4586 * argc, argv which are passed through.
4588 * @param domain_sid The domain sid acquired from the remote server.
4589 * @param cli A cli_state connected to the server.
4590 * @param mem_ctx Talloc context, destroyed on completion of the function.
4591 * @param argc Standard main() style argc.
4592 * @param argv Standard main() style argv. Initial components are already
4595 * @return Normal NTSTATUS return.
4598 static NTSTATUS
rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
4599 const char *domain_name
,
4600 struct cli_state
*cli
,
4601 struct rpc_pipe_client
*pipe_hnd
,
4602 TALLOC_CTX
*mem_ctx
,
4611 struct user_token
*tokens
= NULL
;
4614 struct share_list share_list
;
4617 rpc_share_userlist_usage();
4618 return NT_STATUS_UNSUCCESSFUL
;
4624 f
= fopen(argv
[0], "r");
4628 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4629 return NT_STATUS_UNSUCCESSFUL
;
4632 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4638 DEBUG(0, ("Could not read users from file\n"));
4639 return NT_STATUS_UNSUCCESSFUL
;
4642 for (i
=0; i
<num_tokens
; i
++)
4643 collect_alias_memberships(&tokens
[i
].token
);
4645 share_list
.num_shares
= 0;
4646 share_list
.shares
= NULL
;
4648 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4651 DEBUG(0, ("Error returning browse list: %s\n",
4656 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4657 char *netname
= share_list
.shares
[i
];
4659 if (netname
[strlen(netname
)-1] == '$')
4662 d_printf("%s\n", netname
);
4664 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4665 num_tokens
, tokens
);
4668 for (i
=0; i
<num_tokens
; i
++) {
4669 free_user_token(&tokens
[i
].token
);
4672 SAFE_FREE(share_list
.shares
);
4674 return NT_STATUS_OK
;
4677 static int rpc_share_allowedusers(int argc
, const char **argv
)
4681 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
4682 rpc_aliaslist_internals
,
4687 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
4693 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4694 rpc_share_allowedusers_internals
,
4698 int net_usersidlist(int argc
, const char **argv
)
4701 struct user_token
*tokens
= NULL
;
4705 net_usersidlist_usage(argc
, argv
);
4709 if (!get_user_tokens(&num_tokens
, &tokens
)) {
4710 DEBUG(0, ("Could not get the user/sid list\n"));
4714 for (i
=0; i
<num_tokens
; i
++) {
4715 dump_user_token(&tokens
[i
]);
4716 free_user_token(&tokens
[i
].token
);
4723 int net_usersidlist_usage(int argc
, const char **argv
)
4725 d_printf("net usersidlist\n"
4726 "\tprints out a list of all users the running winbind knows\n"
4727 "\tabout, together with all their SIDs. This is used as\n"
4728 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4730 net_common_flags_usage(argc
, argv
);
4735 * 'net rpc share' entrypoint.
4736 * @param argc Standard main() style argc.
4737 * @param argv Standard main() style argv. Initial components are already
4741 int net_rpc_share(int argc
, const char **argv
)
4743 struct functable func
[] = {
4744 {"add", rpc_share_add
},
4745 {"delete", rpc_share_delete
},
4746 {"allowedusers", rpc_share_allowedusers
},
4747 {"migrate", rpc_share_migrate
},
4748 {"list", rpc_share_list
},
4753 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4754 rpc_share_list_internals
,
4757 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4760 static NTSTATUS
rpc_sh_share_list(TALLOC_CTX
*mem_ctx
,
4761 struct rpc_sh_ctx
*ctx
,
4762 struct rpc_pipe_client
*pipe_hnd
,
4763 int argc
, const char **argv
)
4765 return rpc_share_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
4766 ctx
->cli
, pipe_hnd
, mem_ctx
,
4770 static NTSTATUS
rpc_sh_share_add(TALLOC_CTX
*mem_ctx
,
4771 struct rpc_sh_ctx
*ctx
,
4772 struct rpc_pipe_client
*pipe_hnd
,
4773 int argc
, const char **argv
)
4777 uint32_t parm_err
= 0;
4778 union srvsvc_NetShareInfo info
;
4779 struct srvsvc_NetShareInfo2 info2
;
4781 if ((argc
< 2) || (argc
> 3)) {
4782 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4784 return NT_STATUS_INVALID_PARAMETER
;
4787 info2
.name
= argv
[0];
4788 info2
.type
= STYPE_DISKTREE
;
4789 info2
.comment
= (argc
== 3) ? argv
[2] : "";
4790 info2
.permissions
= 0;
4791 info2
.max_users
= 0;
4792 info2
.current_users
= 0;
4793 info2
.path
= argv
[1];
4794 info2
.password
= NULL
;
4796 info
.info2
= &info2
;
4798 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
4799 pipe_hnd
->cli
->desthost
,
4808 static NTSTATUS
rpc_sh_share_delete(TALLOC_CTX
*mem_ctx
,
4809 struct rpc_sh_ctx
*ctx
,
4810 struct rpc_pipe_client
*pipe_hnd
,
4811 int argc
, const char **argv
)
4817 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4818 return NT_STATUS_INVALID_PARAMETER
;
4821 status
= rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
4822 pipe_hnd
->cli
->desthost
,
4830 static NTSTATUS
rpc_sh_share_info(TALLOC_CTX
*mem_ctx
,
4831 struct rpc_sh_ctx
*ctx
,
4832 struct rpc_pipe_client
*pipe_hnd
,
4833 int argc
, const char **argv
)
4835 union srvsvc_NetShareInfo info
;
4840 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4841 return NT_STATUS_INVALID_PARAMETER
;
4844 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4845 pipe_hnd
->cli
->desthost
,
4850 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4854 d_printf("Name: %s\n", info
.info2
->name
);
4855 d_printf("Comment: %s\n", info
.info2
->comment
);
4856 d_printf("Path: %s\n", info
.info2
->path
);
4857 d_printf("Password: %s\n", info
.info2
->password
);
4860 return werror_to_ntstatus(result
);
4863 struct rpc_sh_cmd
*net_rpc_share_cmds(TALLOC_CTX
*mem_ctx
,
4864 struct rpc_sh_ctx
*ctx
)
4866 static struct rpc_sh_cmd cmds
[] = {
4868 { "list", NULL
, PI_SRVSVC
, rpc_sh_share_list
,
4869 "List available shares" },
4871 { "add", NULL
, PI_SRVSVC
, rpc_sh_share_add
,
4874 { "delete", NULL
, PI_SRVSVC
, rpc_sh_share_delete
,
4877 { "info", NULL
, PI_SRVSVC
, rpc_sh_share_info
,
4878 "Get information about a share" },
4880 { NULL
, NULL
, 0, NULL
, NULL
}
4886 /****************************************************************************/
4888 static int rpc_file_usage(int argc
, const char **argv
)
4890 return net_help_file(argc
, argv
);
4894 * Close a file on a remote RPC server.
4896 * All parameters are provided by the run_rpc_command function, except for
4897 * argc, argv which are passed through.
4899 * @param domain_sid The domain sid acquired from the remote server.
4900 * @param cli A cli_state connected to the server.
4901 * @param mem_ctx Talloc context, destroyed on completion of the function.
4902 * @param argc Standard main() style argc.
4903 * @param argv Standard main() style argv. Initial components are already
4906 * @return Normal NTSTATUS return.
4908 static NTSTATUS
rpc_file_close_internals(const DOM_SID
*domain_sid
,
4909 const char *domain_name
,
4910 struct cli_state
*cli
,
4911 struct rpc_pipe_client
*pipe_hnd
,
4912 TALLOC_CTX
*mem_ctx
,
4916 return rpccli_srvsvc_NetFileClose(pipe_hnd
, mem_ctx
,
4917 pipe_hnd
->cli
->desthost
,
4918 atoi(argv
[0]), NULL
);
4922 * Close a file on a remote RPC server.
4924 * @param argc Standard main() style argc.
4925 * @param argv Standard main() style argv. Initial components are already
4928 * @return A shell status integer (0 for success).
4930 static int rpc_file_close(int argc
, const char **argv
)
4933 DEBUG(1, ("No fileid given on close\n"));
4934 return(rpc_file_usage(argc
, argv
));
4937 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4938 rpc_file_close_internals
,
4943 * Formatted print of open file info
4945 * @param r struct srvsvc_NetFileInfo3 contents
4948 static void display_file_info_3(struct srvsvc_NetFileInfo3
*r
)
4950 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4951 r
->fid
, r
->user
, r
->permissions
, r
->num_locks
, r
->path
);
4955 * List open files on a remote RPC server.
4957 * All parameters are provided by the run_rpc_command function, except for
4958 * argc, argv which are passed through.
4960 * @param domain_sid The domain sid acquired from the remote server.
4961 * @param cli A cli_state connected to the server.
4962 * @param mem_ctx Talloc context, destroyed on completion of the function.
4963 * @param argc Standard main() style argc.
4964 * @param argv Standard main() style argv. Initial components are already
4967 * @return Normal NTSTATUS return.
4970 static NTSTATUS
rpc_file_list_internals(const DOM_SID
*domain_sid
,
4971 const char *domain_name
,
4972 struct cli_state
*cli
,
4973 struct rpc_pipe_client
*pipe_hnd
,
4974 TALLOC_CTX
*mem_ctx
,
4978 struct srvsvc_NetFileInfoCtr info_ctr
;
4979 struct srvsvc_NetFileCtr3 ctr3
;
4982 uint32 preferred_len
= 0xffffffff, i
;
4983 const char *username
=NULL
;
4984 uint32_t total_entries
= 0;
4985 uint32_t resume_handle
= 0;
4987 /* if argc > 0, must be user command */
4989 username
= smb_xstrdup(argv
[0]);
4991 ZERO_STRUCT(info_ctr
);
4995 info_ctr
.ctr
.ctr3
= &ctr3
;
4997 status
= rpccli_srvsvc_NetFileEnum(pipe_hnd
, mem_ctx
,
4998 pipe_hnd
->cli
->desthost
,
5007 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
5010 /* Display results */
5013 "\nEnumerating open files on remote server:\n\n"\
5014 "\nFileId Opened by Perms Locks Path"\
5015 "\n------ --------- ----- ----- ---- \n");
5016 for (i
= 0; i
< total_entries
; i
++)
5017 display_file_info_3(&info_ctr
.ctr
.ctr3
->array
[i
]);
5019 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
5023 * List files for a user on a remote RPC server.
5025 * @param argc Standard main() style argc.
5026 * @param argv Standard main() style argv. Initial components are already
5029 * @return A shell status integer (0 for success).
5032 static int rpc_file_user(int argc
, const char **argv
)
5035 DEBUG(1, ("No username given\n"));
5036 return(rpc_file_usage(argc
, argv
));
5039 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5040 rpc_file_list_internals
,
5045 * 'net rpc file' entrypoint.
5046 * @param argc Standard main() style argc.
5047 * @param argv Standard main() style argv. Initial components are already
5051 int net_rpc_file(int argc
, const char **argv
)
5053 struct functable func
[] = {
5054 {"close", rpc_file_close
},
5055 {"user", rpc_file_user
},
5057 {"info", rpc_file_info
},
5063 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5064 rpc_file_list_internals
,
5067 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
5071 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5073 * All parameters are provided by the run_rpc_command function, except for
5074 * argc, argv which are passed through.
5076 * @param domain_sid The domain sid acquired from the remote server.
5077 * @param cli A cli_state connected to the server.
5078 * @param mem_ctx Talloc context, destroyed on completion of the function.
5079 * @param argc Standard main() style argc.
5080 * @param argv Standard main() style argv. Initial components are already
5083 * @return Normal NTSTATUS return.
5086 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5087 const char *domain_name
,
5088 struct cli_state
*cli
,
5089 struct rpc_pipe_client
*pipe_hnd
,
5090 TALLOC_CTX
*mem_ctx
,
5094 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5096 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5098 if (NT_STATUS_IS_OK(result
)) {
5099 d_printf("\nShutdown successfully aborted\n");
5100 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5102 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5108 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5110 * All parameters are provided by the run_rpc_command function, except for
5111 * argc, argv which are passed through.
5113 * @param domain_sid The domain sid acquired from the remote server.
5114 * @param cli A cli_state connected to the server.
5115 * @param mem_ctx Talloc context, destroyed on completion of the function.
5116 * @param argc Standard main() style argc.
5117 * @param argv Standard main() style argv. Initial components are already
5120 * @return Normal NTSTATUS return.
5123 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5124 const char *domain_name
,
5125 struct cli_state
*cli
,
5126 struct rpc_pipe_client
*pipe_hnd
,
5127 TALLOC_CTX
*mem_ctx
,
5131 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5133 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5135 if (NT_STATUS_IS_OK(result
)) {
5136 d_printf("\nShutdown successfully aborted\n");
5137 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5139 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5145 * ABORT the Shut down of a remote RPC server.
5147 * @param argc Standard main() style argc.
5148 * @param argv Standard main() style argv. Initial components are already
5151 * @return A shell status integer (0 for success).
5154 static int rpc_shutdown_abort(int argc
, const char **argv
)
5156 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5157 rpc_shutdown_abort_internals
,
5163 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5165 return run_rpc_command(NULL
, PI_WINREG
, 0,
5166 rpc_reg_shutdown_abort_internals
,
5171 * Shut down a remote RPC Server via initshutdown pipe.
5173 * All parameters are provided by the run_rpc_command function, except for
5174 * argc, argv which are passed through.
5176 * @param domain_sid The domain sid acquired from the remote server.
5177 * @param cli A cli_state connected to the server.
5178 * @param mem_ctx Talloc context, destroyed on completion of the function.
5179 * @param argc Standard main() style argc.
5180 * @param argv Standard main() style argv. Initial components are already
5183 * @return Normal NTSTATUS return.
5186 NTSTATUS
rpc_init_shutdown_internals(const DOM_SID
*domain_sid
,
5187 const char *domain_name
,
5188 struct cli_state
*cli
,
5189 struct rpc_pipe_client
*pipe_hnd
,
5190 TALLOC_CTX
*mem_ctx
,
5194 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5195 const char *msg
= "This machine will be shutdown shortly";
5196 uint32 timeout
= 20;
5197 struct initshutdown_String msg_string
;
5198 struct initshutdown_String_sub s
;
5200 if (opt_comment
&& strlen(opt_comment
)) {
5204 timeout
= opt_timeout
;
5208 msg_string
.name
= &s
;
5210 /* create an entry */
5211 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5212 &msg_string
, timeout
, opt_force
, opt_reboot
, NULL
);
5214 if (NT_STATUS_IS_OK(result
)) {
5215 d_printf("\nShutdown of remote machine succeeded\n");
5216 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5218 DEBUG(1,("Shutdown of remote machine failed!\n"));
5224 * Shut down a remote RPC Server via winreg pipe.
5226 * All parameters are provided by the run_rpc_command function, except for
5227 * argc, argv which are passed through.
5229 * @param domain_sid The domain sid acquired from the remote server.
5230 * @param cli A cli_state connected to the server.
5231 * @param mem_ctx Talloc context, destroyed on completion of the function.
5232 * @param argc Standard main() style argc.
5233 * @param argv Standard main() style argv. Initial components are already
5236 * @return Normal NTSTATUS return.
5239 NTSTATUS
rpc_reg_shutdown_internals(const DOM_SID
*domain_sid
,
5240 const char *domain_name
,
5241 struct cli_state
*cli
,
5242 struct rpc_pipe_client
*pipe_hnd
,
5243 TALLOC_CTX
*mem_ctx
,
5247 const char *msg
= "This machine will be shutdown shortly";
5248 uint32 timeout
= 20;
5249 struct initshutdown_String msg_string
;
5250 struct initshutdown_String_sub s
;
5254 if (opt_comment
&& strlen(opt_comment
)) {
5258 msg_string
.name
= &s
;
5261 timeout
= opt_timeout
;
5264 /* create an entry */
5265 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5266 &msg_string
, timeout
, opt_force
, opt_reboot
, &werr
);
5268 if (NT_STATUS_IS_OK(result
)) {
5269 d_printf("\nShutdown of remote machine succeeded\n");
5271 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5272 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5273 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5275 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(werr
));
5282 * Shut down a remote RPC server.
5284 * @param argc Standard main() style argc.
5285 * @param argv Standard main() style argv. Initial components are already
5288 * @return A shell status integer (0 for success).
5291 static int rpc_shutdown(int argc
, const char **argv
)
5293 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5294 rpc_init_shutdown_internals
,
5298 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5299 rc
= run_rpc_command(NULL
, PI_WINREG
, 0,
5300 rpc_reg_shutdown_internals
, argc
, argv
);
5306 /***************************************************************************
5307 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5309 ***************************************************************************/
5312 * Add interdomain trust account to the RPC server.
5313 * All parameters (except for argc and argv) are passed by run_rpc_command
5316 * @param domain_sid The domain sid acquired from the server.
5317 * @param cli A cli_state connected to the server.
5318 * @param mem_ctx Talloc context, destroyed on completion of the function.
5319 * @param argc Standard main() style argc.
5320 * @param argv Standard main() style argv. Initial components are already
5323 * @return normal NTSTATUS return code.
5326 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
5327 const char *domain_name
,
5328 struct cli_state
*cli
,
5329 struct rpc_pipe_client
*pipe_hnd
,
5330 TALLOC_CTX
*mem_ctx
,
5334 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5335 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5337 struct lsa_String lsa_acct_name
;
5339 uint32 acct_flags
=0;
5341 uint32_t access_granted
= 0;
5342 union samr_UserInfo info
;
5343 unsigned int orig_timeout
;
5346 d_printf("Usage: net rpc trustdom add <domain_name> <trust password>\n");
5347 return NT_STATUS_INVALID_PARAMETER
;
5351 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5354 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5355 return NT_STATUS_NO_MEMORY
;
5358 strupper_m(acct_name
);
5360 init_lsa_String(&lsa_acct_name
, acct_name
);
5362 /* Get samr policy handle */
5363 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5364 pipe_hnd
->cli
->desthost
,
5365 MAXIMUM_ALLOWED_ACCESS
,
5367 if (!NT_STATUS_IS_OK(result
)) {
5371 /* Get domain policy handle */
5372 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5374 MAXIMUM_ALLOWED_ACCESS
,
5375 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5377 if (!NT_STATUS_IS_OK(result
)) {
5381 /* This call can take a long time - allow the server to time out.
5382 * 35 seconds should do it. */
5384 orig_timeout
= cli_set_timeout(pipe_hnd
->cli
, 35000);
5386 /* Create trusting domain's account */
5387 acb_info
= ACB_NORMAL
;
5388 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5389 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5390 SAMR_USER_ACCESS_SET_PASSWORD
|
5391 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5392 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5394 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5403 /* And restore our original timeout. */
5404 cli_set_timeout(pipe_hnd
->cli
, orig_timeout
);
5406 if (!NT_STATUS_IS_OK(result
)) {
5407 d_printf("net rpc trustdom add: create user %s failed %s\n",
5408 acct_name
, nt_errstr(result
));
5414 struct samr_LogonHours hours
;
5415 struct lsa_BinaryString parameters
;
5416 const int units_per_week
= 168;
5417 struct samr_CryptPassword crypt_pwd
;
5419 ZERO_STRUCT(notime
);
5421 ZERO_STRUCT(parameters
);
5423 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
5425 result
= NT_STATUS_NO_MEMORY
;
5428 hours
.units_per_week
= units_per_week
;
5429 memset(hours
.bits
, 0xFF, units_per_week
);
5431 init_samr_CryptPassword(argv
[1],
5432 &cli
->user_session_key
,
5435 init_samr_user_info23(&info
.info23
,
5436 notime
, notime
, notime
,
5437 notime
, notime
, notime
,
5438 NULL
, NULL
, NULL
, NULL
, NULL
,
5439 NULL
, NULL
, NULL
, NULL
, ¶meters
,
5441 SAMR_FIELD_ACCT_FLAGS
| SAMR_FIELD_PASSWORD
,
5443 0, 0, 0, 0, 0, 0, 0,
5446 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5451 if (!NT_STATUS_IS_OK(result
)) {
5452 DEBUG(0,("Could not set trust account password: %s\n",
5453 nt_errstr(result
)));
5459 SAFE_FREE(acct_name
);
5464 * Create interdomain trust account for a remote domain.
5466 * @param argc Standard argc.
5467 * @param argv Standard argv without initial components.
5469 * @return Integer status (0 means success)
5472 static int rpc_trustdom_add(int argc
, const char **argv
)
5475 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
5478 d_printf("Usage: net rpc trustdom add <domain_name> <trust password>\n");
5485 * Remove interdomain trust account from the RPC server.
5486 * All parameters (except for argc and argv) are passed by run_rpc_command
5489 * @param domain_sid The domain sid acquired from the server.
5490 * @param cli A cli_state connected to the server.
5491 * @param mem_ctx Talloc context, destroyed on completion of the function.
5492 * @param argc Standard main() style argc.
5493 * @param argv Standard main() style argv. Initial components are already
5496 * @return normal NTSTATUS return code.
5499 static NTSTATUS
rpc_trustdom_del_internals(const DOM_SID
*domain_sid
,
5500 const char *domain_name
,
5501 struct cli_state
*cli
,
5502 struct rpc_pipe_client
*pipe_hnd
,
5503 TALLOC_CTX
*mem_ctx
,
5507 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5508 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5510 DOM_SID trust_acct_sid
;
5511 struct samr_Ids user_rids
, name_types
;
5512 struct lsa_String lsa_acct_name
;
5515 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5516 return NT_STATUS_INVALID_PARAMETER
;
5520 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5522 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5524 if (acct_name
== NULL
)
5525 return NT_STATUS_NO_MEMORY
;
5527 strupper_m(acct_name
);
5529 /* Get samr policy handle */
5530 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5531 pipe_hnd
->cli
->desthost
,
5532 MAXIMUM_ALLOWED_ACCESS
,
5534 if (!NT_STATUS_IS_OK(result
)) {
5538 /* Get domain policy handle */
5539 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5541 MAXIMUM_ALLOWED_ACCESS
,
5542 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5544 if (!NT_STATUS_IS_OK(result
)) {
5548 init_lsa_String(&lsa_acct_name
, acct_name
);
5550 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5557 if (!NT_STATUS_IS_OK(result
)) {
5558 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5559 acct_name
, nt_errstr(result
) );
5563 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5565 MAXIMUM_ALLOWED_ACCESS
,
5569 if (!NT_STATUS_IS_OK(result
)) {
5570 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5571 acct_name
, nt_errstr(result
) );
5575 /* append the rid to the domain sid */
5576 sid_copy(&trust_acct_sid
, domain_sid
);
5577 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5581 /* remove the sid */
5583 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5586 if (!NT_STATUS_IS_OK(result
)) {
5587 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5588 acct_name
, nt_errstr(result
) );
5594 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5597 if (!NT_STATUS_IS_OK(result
)) {
5598 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5599 acct_name
, nt_errstr(result
) );
5603 if (!NT_STATUS_IS_OK(result
)) {
5604 d_printf("Could not set trust account password: %s\n",
5614 * Delete interdomain trust account for a remote domain.
5616 * @param argc Standard argc.
5617 * @param argv Standard argv without initial components.
5619 * @return Integer status (0 means success).
5622 static int rpc_trustdom_del(int argc
, const char **argv
)
5625 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_del_internals
,
5628 d_printf("Usage: net rpc trustdom del <domain>\n");
5633 static NTSTATUS
rpc_trustdom_get_pdc(struct cli_state
*cli
,
5634 TALLOC_CTX
*mem_ctx
,
5635 const char *domain_name
)
5637 char *dc_name
= NULL
;
5638 const char *buffer
= NULL
;
5639 struct rpc_pipe_client
*netr
;
5642 /* Use NetServerEnum2 */
5644 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5646 return NT_STATUS_OK
;
5649 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5650 for domain %s\n", domain_name
));
5652 /* Try netr_GetDcName */
5654 netr
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &status
);
5659 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5664 cli_rpc_pipe_close(netr
);
5666 if (NT_STATUS_IS_OK(status
)) {
5670 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5671 for domain %s\n", domain_name
));
5677 * Establish trust relationship to a trusting domain.
5678 * Interdomain account must already be created on remote PDC.
5680 * @param argc Standard argc.
5681 * @param argv Standard argv without initial components.
5683 * @return Integer status (0 means success).
5686 static int rpc_trustdom_establish(int argc
, const char **argv
)
5688 struct cli_state
*cli
= NULL
;
5689 struct sockaddr_storage server_ss
;
5690 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5691 POLICY_HND connect_hnd
;
5692 TALLOC_CTX
*mem_ctx
;
5694 DOM_SID
*domain_sid
;
5699 union lsa_PolicyInformation
*info
= NULL
;
5702 * Connect to \\server\ipc$ as 'our domain' account with password
5706 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
5710 domain_name
= smb_xstrdup(argv
[0]);
5711 strupper_m(domain_name
);
5713 /* account name used at first is our domain's name with '$' */
5714 asprintf(&acct_name
, "%s$", lp_workgroup());
5715 strupper_m(acct_name
);
5718 * opt_workgroup will be used by connection functions further,
5719 * hence it should be set to remote domain name instead of ours
5721 if (opt_workgroup
) {
5722 opt_workgroup
= smb_xstrdup(domain_name
);
5725 opt_user_name
= acct_name
;
5727 /* find the domain controller */
5728 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5729 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5733 /* connect to ipc$ as username/password */
5734 nt_status
= connect_to_ipc(&cli
, &server_ss
, pdc_name
);
5735 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5737 /* Is it trusting domain account for sure ? */
5738 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5739 nt_errstr(nt_status
)));
5743 /* store who we connected to */
5745 saf_store( domain_name
, pdc_name
);
5748 * Connect to \\server\ipc$ again (this time anonymously)
5751 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ss
, (char*)pdc_name
);
5753 if (NT_STATUS_IS_ERR(nt_status
)) {
5754 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5755 domain_name
, nt_errstr(nt_status
)));
5759 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5760 "domain %s", domain_name
))) {
5761 DEBUG(0, ("talloc_init() failed\n"));
5766 /* Make sure we're talking to a proper server */
5768 nt_status
= rpc_trustdom_get_pdc(cli
, mem_ctx
, domain_name
);
5769 if (!NT_STATUS_IS_OK(nt_status
)) {
5771 talloc_destroy(mem_ctx
);
5776 * Call LsaOpenPolicy and LsaQueryInfo
5779 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5781 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5783 talloc_destroy(mem_ctx
);
5787 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
5789 if (NT_STATUS_IS_ERR(nt_status
)) {
5790 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5791 nt_errstr(nt_status
)));
5793 talloc_destroy(mem_ctx
);
5797 /* Querying info level 5 */
5799 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5801 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5803 if (NT_STATUS_IS_ERR(nt_status
)) {
5804 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5805 nt_errstr(nt_status
)));
5807 talloc_destroy(mem_ctx
);
5811 domain_sid
= info
->account_domain
.sid
;
5813 /* There should be actually query info level 3 (following nt serv behaviour),
5814 but I still don't know if it's _really_ necessary */
5817 * Store the password in secrets db
5820 if (!pdb_set_trusteddom_pw(domain_name
, opt_password
, domain_sid
)) {
5821 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5823 talloc_destroy(mem_ctx
);
5828 * Close the pipes and clean up
5831 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5832 if (NT_STATUS_IS_ERR(nt_status
)) {
5833 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5834 nt_errstr(nt_status
)));
5836 talloc_destroy(mem_ctx
);
5842 talloc_destroy(mem_ctx
);
5844 d_printf("Trust to domain %s established\n", domain_name
);
5849 * Revoke trust relationship to the remote domain.
5851 * @param argc Standard argc.
5852 * @param argv Standard argv without initial components.
5854 * @return Integer status (0 means success).
5857 static int rpc_trustdom_revoke(int argc
, const char **argv
)
5862 if (argc
< 1) return -1;
5864 /* generate upper cased domain name */
5865 domain_name
= smb_xstrdup(argv
[0]);
5866 strupper_m(domain_name
);
5868 /* delete password of the trust */
5869 if (!pdb_del_trusteddom_pw(domain_name
)) {
5870 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5877 SAFE_FREE(domain_name
);
5882 * Usage for 'net rpc trustdom' command
5884 * @param argc standard argc
5885 * @param argv standard argv without inital components
5887 * @return Integer status returned to shell
5890 static int rpc_trustdom_usage(int argc
, const char **argv
)
5892 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
5893 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
5894 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
5895 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
5896 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
5897 d_printf(" net rpc trustdom vampire \t vampire interdomain trust relationships from remote server\n");
5902 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
5903 const char *domain_name
,
5904 struct cli_state
*cli
,
5905 struct rpc_pipe_client
*pipe_hnd
,
5906 TALLOC_CTX
*mem_ctx
,
5911 sid_to_fstring(str_sid
, domain_sid
);
5912 d_printf("%s\n", str_sid
);
5913 return NT_STATUS_OK
;
5916 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5918 fstring ascii_sid
, padding
;
5919 int pad_len
, col_len
= 20;
5921 /* convert sid into ascii string */
5922 sid_to_fstring(ascii_sid
, dom_sid
);
5924 /* calculate padding space for d_printf to look nicer */
5925 pad_len
= col_len
- strlen(trusted_dom_name
);
5926 padding
[pad_len
] = 0;
5927 do padding
[--pad_len
] = ' '; while (pad_len
);
5929 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5932 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5933 TALLOC_CTX
*mem_ctx
,
5936 const char *trusted_dom_name
)
5939 union lsa_TrustedDomainInfo
*info
= NULL
;
5940 char *cleartextpwd
= NULL
;
5943 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5946 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5948 if (NT_STATUS_IS_ERR(nt_status
)) {
5949 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5950 nt_errstr(nt_status
)));
5954 data
= data_blob(info
->password
.password
->data
,
5955 info
->password
.password
->length
);
5957 cleartextpwd
= decrypt_trustdom_secret(pipe_hnd
->cli
->pwd
.password
,
5960 if (cleartextpwd
== NULL
) {
5961 DEBUG(0,("retrieved NULL password\n"));
5962 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5966 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5967 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5968 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5972 #ifdef DEBUG_PASSWORD
5973 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5974 "password: [%s]\n", trusted_dom_name
,
5975 sid_string_dbg(&dom_sid
), cleartextpwd
));
5979 SAFE_FREE(cleartextpwd
);
5980 data_blob_free(&data
);
5985 static int rpc_trustdom_vampire(int argc
, const char **argv
)
5987 /* common variables */
5988 TALLOC_CTX
* mem_ctx
;
5989 struct cli_state
*cli
= NULL
;
5990 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5992 const char *domain_name
= NULL
;
5993 DOM_SID
*queried_dom_sid
;
5994 POLICY_HND connect_hnd
;
5995 union lsa_PolicyInformation
*info
= NULL
;
5997 /* trusted domains listing variables */
5998 unsigned int enum_ctx
= 0;
6000 struct lsa_DomainList dom_list
;
6004 * Listing trusted domains (stored in secrets.tdb, if local)
6007 mem_ctx
= talloc_init("trust relationships vampire");
6010 * set domain and pdc name to local samba server (default)
6011 * or to remote one given in command line
6014 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6015 domain_name
= opt_workgroup
;
6016 opt_target_workgroup
= opt_workgroup
;
6018 fstrcpy(pdc_name
, global_myname());
6019 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6020 opt_target_workgroup
= domain_name
;
6023 /* open \PIPE\lsarpc and open policy handle */
6024 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6025 if (!NT_STATUS_IS_OK(nt_status
)) {
6026 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6027 nt_errstr(nt_status
)));
6028 talloc_destroy(mem_ctx
);
6032 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6034 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6035 nt_errstr(nt_status
) ));
6037 talloc_destroy(mem_ctx
);
6041 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6043 if (NT_STATUS_IS_ERR(nt_status
)) {
6044 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6045 nt_errstr(nt_status
)));
6047 talloc_destroy(mem_ctx
);
6051 /* query info level 5 to obtain sid of a domain being queried */
6052 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6054 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6057 if (NT_STATUS_IS_ERR(nt_status
)) {
6058 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6059 nt_errstr(nt_status
)));
6061 talloc_destroy(mem_ctx
);
6065 queried_dom_sid
= info
->account_domain
.sid
;
6068 * Keep calling LsaEnumTrustdom over opened pipe until
6069 * the end of enumeration is reached
6072 d_printf("Vampire trusted domains:\n\n");
6075 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6080 if (NT_STATUS_IS_ERR(nt_status
)) {
6081 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6082 nt_errstr(nt_status
)));
6084 talloc_destroy(mem_ctx
);
6088 for (i
= 0; i
< dom_list
.count
; i
++) {
6090 print_trusted_domain(dom_list
.domains
[i
].sid
,
6091 dom_list
.domains
[i
].name
.string
);
6093 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6094 *dom_list
.domains
[i
].sid
,
6095 dom_list
.domains
[i
].name
.string
);
6096 if (!NT_STATUS_IS_OK(nt_status
)) {
6098 talloc_destroy(mem_ctx
);
6104 * in case of no trusted domains say something rather
6105 * than just display blank line
6107 if (!dom_list
.count
) d_printf("none\n");
6109 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6111 /* close this connection before doing next one */
6112 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6113 if (NT_STATUS_IS_ERR(nt_status
)) {
6114 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6115 nt_errstr(nt_status
)));
6117 talloc_destroy(mem_ctx
);
6121 /* close lsarpc pipe and connection to IPC$ */
6124 talloc_destroy(mem_ctx
);
6128 static int rpc_trustdom_list(int argc
, const char **argv
)
6130 /* common variables */
6131 TALLOC_CTX
* mem_ctx
;
6132 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6133 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6135 const char *domain_name
= NULL
;
6136 DOM_SID
*queried_dom_sid
;
6138 int ascii_dom_name_len
;
6139 POLICY_HND connect_hnd
;
6140 union lsa_PolicyInformation
*info
= NULL
;
6142 /* trusted domains listing variables */
6143 unsigned int num_domains
, enum_ctx
= 0;
6144 int i
, pad_len
, col_len
= 20;
6145 struct lsa_DomainList dom_list
;
6148 /* trusting domains listing variables */
6149 POLICY_HND domain_hnd
;
6150 struct samr_SamArray
*trusts
= NULL
;
6153 * Listing trusted domains (stored in secrets.tdb, if local)
6156 mem_ctx
= talloc_init("trust relationships listing");
6159 * set domain and pdc name to local samba server (default)
6160 * or to remote one given in command line
6163 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6164 domain_name
= opt_workgroup
;
6165 opt_target_workgroup
= opt_workgroup
;
6167 fstrcpy(pdc_name
, global_myname());
6168 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6169 opt_target_workgroup
= domain_name
;
6172 /* open \PIPE\lsarpc and open policy handle */
6173 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6174 if (!NT_STATUS_IS_OK(nt_status
)) {
6175 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6176 nt_errstr(nt_status
)));
6177 talloc_destroy(mem_ctx
);
6181 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6183 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6184 nt_errstr(nt_status
) ));
6186 talloc_destroy(mem_ctx
);
6190 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6192 if (NT_STATUS_IS_ERR(nt_status
)) {
6193 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6194 nt_errstr(nt_status
)));
6196 talloc_destroy(mem_ctx
);
6200 /* query info level 5 to obtain sid of a domain being queried */
6201 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6203 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6206 if (NT_STATUS_IS_ERR(nt_status
)) {
6207 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6208 nt_errstr(nt_status
)));
6210 talloc_destroy(mem_ctx
);
6214 queried_dom_sid
= info
->account_domain
.sid
;
6217 * Keep calling LsaEnumTrustdom over opened pipe until
6218 * the end of enumeration is reached
6221 d_printf("Trusted domains list:\n\n");
6224 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6229 if (NT_STATUS_IS_ERR(nt_status
)) {
6230 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6231 nt_errstr(nt_status
)));
6233 talloc_destroy(mem_ctx
);
6237 for (i
= 0; i
< dom_list
.count
; i
++) {
6238 print_trusted_domain(dom_list
.domains
[i
].sid
,
6239 dom_list
.domains
[i
].name
.string
);
6243 * in case of no trusted domains say something rather
6244 * than just display blank line
6246 if (!dom_list
.count
) d_printf("none\n");
6248 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6250 /* close this connection before doing next one */
6251 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6252 if (NT_STATUS_IS_ERR(nt_status
)) {
6253 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6254 nt_errstr(nt_status
)));
6256 talloc_destroy(mem_ctx
);
6260 cli_rpc_pipe_close(pipe_hnd
);
6263 * Listing trusting domains (stored in passdb backend, if local)
6266 d_printf("\nTrusting domains list:\n\n");
6269 * Open \PIPE\samr and get needed policy handles
6271 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_SAMR
, &nt_status
);
6273 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6275 talloc_destroy(mem_ctx
);
6280 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6281 pipe_hnd
->cli
->desthost
,
6282 SA_RIGHT_SAM_LOOKUP_DOMAIN
,
6284 if (!NT_STATUS_IS_OK(nt_status
)) {
6285 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6286 nt_errstr(nt_status
)));
6288 talloc_destroy(mem_ctx
);
6292 /* SamrOpenDomain - we have to open domain policy handle in order to be
6293 able to enumerate accounts*/
6294 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6296 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6299 if (!NT_STATUS_IS_OK(nt_status
)) {
6300 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6301 nt_errstr(nt_status
)));
6303 talloc_destroy(mem_ctx
);
6308 * perform actual enumeration
6311 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6314 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6321 if (NT_STATUS_IS_ERR(nt_status
)) {
6322 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6323 nt_errstr(nt_status
)));
6325 talloc_destroy(mem_ctx
);
6329 for (i
= 0; i
< num_domains
; i
++) {
6331 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6334 * get each single domain's sid (do we _really_ need this ?):
6335 * 1) connect to domain's pdc
6336 * 2) query the pdc for domain's sid
6339 /* get rid of '$' tail */
6340 ascii_dom_name_len
= strlen(str
);
6341 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6342 str
[ascii_dom_name_len
- 1] = '\0';
6344 /* calculate padding space for d_printf to look nicer */
6345 pad_len
= col_len
- strlen(str
);
6346 padding
[pad_len
] = 0;
6347 do padding
[--pad_len
] = ' '; while (pad_len
);
6349 /* set opt_* variables to remote domain */
6351 opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6352 opt_target_workgroup
= opt_workgroup
;
6354 d_printf("%s%s", str
, padding
);
6356 /* connect to remote domain controller */
6357 nt_status
= net_make_ipc_connection(
6358 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6360 if (NT_STATUS_IS_OK(nt_status
)) {
6361 /* query for domain's sid */
6362 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
6363 d_fprintf(stderr
, "couldn't get domain's sid\n");
6365 cli_shutdown(remote_cli
);
6368 d_fprintf(stderr
, "domain controller is not "
6370 nt_errstr(nt_status
));
6374 if (!num_domains
) d_printf("none\n");
6376 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6378 /* close opened samr and domain policy handles */
6379 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6380 if (!NT_STATUS_IS_OK(nt_status
)) {
6381 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6384 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6385 if (!NT_STATUS_IS_OK(nt_status
)) {
6386 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6389 /* close samr pipe and connection to IPC$ */
6392 talloc_destroy(mem_ctx
);
6397 * Entrypoint for 'net rpc trustdom' code.
6399 * @param argc Standard argc.
6400 * @param argv Standard argv without initial components.
6402 * @return Integer status (0 means success).
6405 static int rpc_trustdom(int argc
, const char **argv
)
6407 struct functable func
[] = {
6408 {"add", rpc_trustdom_add
},
6409 {"del", rpc_trustdom_del
},
6410 {"establish", rpc_trustdom_establish
},
6411 {"revoke", rpc_trustdom_revoke
},
6412 {"help", rpc_trustdom_usage
},
6413 {"list", rpc_trustdom_list
},
6414 {"vampire", rpc_trustdom_vampire
},
6419 rpc_trustdom_usage(argc
, argv
);
6423 return (net_run_function(argc
, argv
, func
, rpc_trustdom_usage
));
6427 * Check if a server will take rpc commands
6428 * @param flags Type of server to connect to (PDC, DMB, localhost)
6429 * if the host is not explicitly specified
6430 * @return bool (true means rpc supported)
6432 bool net_rpc_check(unsigned flags
)
6434 struct cli_state
*cli
;
6436 struct sockaddr_storage server_ss
;
6437 char *server_name
= NULL
;
6440 /* flags (i.e. server type) may depend on command */
6441 if (!net_find_server(NULL
, flags
, &server_ss
, &server_name
))
6444 if ((cli
= cli_initialise()) == NULL
) {
6448 status
= cli_connect(cli
, server_name
, &server_ss
);
6449 if (!NT_STATUS_IS_OK(status
))
6451 if (!attempt_netbios_session_request(&cli
, global_myname(),
6452 server_name
, &server_ss
))
6454 if (!cli_negprot(cli
))
6456 if (cli
->protocol
< PROTOCOL_NT1
)
6465 /* dump sam database via samsync rpc calls */
6466 static int rpc_samdump(int argc
, const char **argv
) {
6467 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
6471 /* syncronise sam database via samsync rpc calls */
6472 static int rpc_vampire(int argc
, const char **argv
) {
6473 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
6478 * Migrate everything from a print-server.
6480 * @param argc Standard main() style argc.
6481 * @param argv Standard main() style argv. Initial components are already
6484 * @return A shell status integer (0 for success).
6486 * The order is important !
6487 * To successfully add drivers the print-queues have to exist !
6488 * Applying ACLs should be the last step, because you're easily locked out.
6491 static int rpc_printer_migrate_all(int argc
, const char **argv
)
6496 printf("no server to migrate\n");
6500 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
6504 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
6508 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
6512 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
6516 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
6521 * Migrate print-drivers from a print-server.
6523 * @param argc Standard main() style argc.
6524 * @param argv Standard main() style argv. Initial components are already
6527 * @return A shell status integer (0 for success).
6529 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
6532 printf("no server to migrate\n");
6536 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6537 rpc_printer_migrate_drivers_internals
,
6542 * Migrate print-forms from a print-server.
6544 * @param argc Standard main() style argc.
6545 * @param argv Standard main() style argv. Initial components are already
6548 * @return A shell status integer (0 for success).
6550 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
6553 printf("no server to migrate\n");
6557 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6558 rpc_printer_migrate_forms_internals
,
6563 * Migrate printers from a print-server.
6565 * @param argc Standard main() style argc.
6566 * @param argv Standard main() style argv. Initial components are already
6569 * @return A shell status integer (0 for success).
6571 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
6574 printf("no server to migrate\n");
6578 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6579 rpc_printer_migrate_printers_internals
,
6584 * Migrate printer-ACLs from a print-server.
6586 * @param argc Standard main() style argc.
6587 * @param argv Standard main() style argv. Initial components are already
6590 * @return A shell status integer (0 for success).
6592 static int rpc_printer_migrate_security(int argc
, const char **argv
)
6595 printf("no server to migrate\n");
6599 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6600 rpc_printer_migrate_security_internals
,
6605 * Migrate printer-settings from a print-server.
6607 * @param argc Standard main() style argc.
6608 * @param argv Standard main() style argv. Initial components are already
6611 * @return A shell status integer (0 for success).
6613 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
6616 printf("no server to migrate\n");
6620 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6621 rpc_printer_migrate_settings_internals
,
6626 * 'net rpc printer' entrypoint.
6627 * @param argc Standard main() style argc.
6628 * @param argv Standard main() style argv. Initial components are already
6632 int rpc_printer_migrate(int argc
, const char **argv
)
6635 /* ouch: when addriver and setdriver are called from within
6636 rpc_printer_migrate_drivers_internals, the printer-queue already
6639 struct functable func
[] = {
6640 {"all", rpc_printer_migrate_all
},
6641 {"drivers", rpc_printer_migrate_drivers
},
6642 {"forms", rpc_printer_migrate_forms
},
6643 {"help", rpc_printer_usage
},
6644 {"printers", rpc_printer_migrate_printers
},
6645 {"security", rpc_printer_migrate_security
},
6646 {"settings", rpc_printer_migrate_settings
},
6650 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6655 * List printers on a remote RPC server.
6657 * @param argc Standard main() style argc.
6658 * @param argv Standard main() style argv. Initial components are already
6661 * @return A shell status integer (0 for success).
6663 static int rpc_printer_list(int argc
, const char **argv
)
6666 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6667 rpc_printer_list_internals
,
6672 * List printer-drivers on a remote RPC server.
6674 * @param argc Standard main() style argc.
6675 * @param argv Standard main() style argv. Initial components are already
6678 * @return A shell status integer (0 for success).
6680 static int rpc_printer_driver_list(int argc
, const char **argv
)
6683 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6684 rpc_printer_driver_list_internals
,
6689 * Publish printer in ADS via MSRPC.
6691 * @param argc Standard main() style argc.
6692 * @param argv Standard main() style argv. Initial components are already
6695 * @return A shell status integer (0 for success).
6697 static int rpc_printer_publish_publish(int argc
, const char **argv
)
6700 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6701 rpc_printer_publish_publish_internals
,
6706 * Update printer in ADS via MSRPC.
6708 * @param argc Standard main() style argc.
6709 * @param argv Standard main() style argv. Initial components are already
6712 * @return A shell status integer (0 for success).
6714 static int rpc_printer_publish_update(int argc
, const char **argv
)
6717 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6718 rpc_printer_publish_update_internals
,
6723 * UnPublish printer in ADS via MSRPC
6725 * @param argc Standard main() style argc.
6726 * @param argv Standard main() style argv. Initial components are already
6729 * @return A shell status integer (0 for success).
6731 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
6734 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6735 rpc_printer_publish_unpublish_internals
,
6740 * List published printers via MSRPC.
6742 * @param argc Standard main() style argc.
6743 * @param argv Standard main() style argv. Initial components are already
6746 * @return A shell status integer (0 for success).
6748 static int rpc_printer_publish_list(int argc
, const char **argv
)
6751 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6752 rpc_printer_publish_list_internals
,
6758 * Publish printer in ADS.
6760 * @param argc Standard main() style argc.
6761 * @param argv Standard main() style argv. Initial components are already
6764 * @return A shell status integer (0 for success).
6766 static int rpc_printer_publish(int argc
, const char **argv
)
6769 struct functable func
[] = {
6770 {"publish", rpc_printer_publish_publish
},
6771 {"update", rpc_printer_publish_update
},
6772 {"unpublish", rpc_printer_publish_unpublish
},
6773 {"list", rpc_printer_publish_list
},
6774 {"help", rpc_printer_usage
},
6779 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6780 rpc_printer_publish_list_internals
,
6783 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6789 * Display rpc printer help page.
6790 * @param argc Standard main() style argc.
6791 * @param argv Standard main() style argv. Initial components are already
6794 int rpc_printer_usage(int argc
, const char **argv
)
6796 return net_help_printer(argc
, argv
);
6800 * 'net rpc printer' entrypoint.
6801 * @param argc Standard main() style argc.
6802 * @param argv Standard main() style argv. Initial components are already
6805 int net_rpc_printer(int argc
, const char **argv
)
6807 struct functable func
[] = {
6808 {"list", rpc_printer_list
},
6809 {"migrate", rpc_printer_migrate
},
6810 {"driver", rpc_printer_driver_list
},
6811 {"publish", rpc_printer_publish
},
6816 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6817 rpc_printer_list_internals
,
6820 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6823 /****************************************************************************/
6827 * Basic usage function for 'net rpc'.
6828 * @param argc Standard main() style argc.
6829 * @param argv Standard main() style argv. Initial components are already
6833 int net_rpc_usage(int argc
, const char **argv
)
6835 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
6836 d_printf(" net rpc join \t\t\tto join a domain \n");
6837 d_printf(" net rpc oldjoin \t\tto join a domain created in server manager\n");
6838 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
6839 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
6840 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
6841 d_printf(" net rpc group \t\tto list groups\n");
6842 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
6843 d_printf(" net rpc printer \t\tto list and migrate printers\n");
6844 d_printf(" net rpc file \t\t\tto list open files\n");
6845 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
6846 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
6847 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
6848 d_printf(" net rpc samdump \t\tdisplay an NT PDC's users, groups and other data\n");
6849 d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n");
6850 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
6851 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
6852 d_printf(" net rpc rights\t\tto manage privileges assigned to SIDs\n");
6853 d_printf(" net rpc registry\t\tto manage registry hives\n");
6854 d_printf(" net rpc service\t\tto start, stop and query services\n");
6855 d_printf(" net rpc audit\t\t\tto modify global auditing settings\n");
6856 d_printf(" net rpc shell\t\t\tto open an interactive shell for remote server/account management\n");
6858 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
6859 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
6860 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
6861 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
6862 d_printf("\t-C or --comment=<message>\ttext message to display on impending shutdown\n");
6868 * Help function for 'net rpc'. Calls command specific help if requested
6869 * or displays usage of net rpc.
6870 * @param argc Standard main() style argc.
6871 * @param argv Standard main() style argv. Initial components are already
6875 int net_rpc_help(int argc
, const char **argv
)
6877 struct functable func
[] = {
6878 {"join", rpc_join_usage
},
6879 {"user", rpc_user_usage
},
6880 {"group", rpc_group_usage
},
6881 {"share", rpc_share_usage
},
6882 /*{"changetrustpw", rpc_changetrustpw_usage}, */
6883 {"trustdom", rpc_trustdom_usage
},
6884 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
6885 /*{"shutdown", rpc_shutdown_usage}, */
6886 {"vampire", rpc_vampire_usage
},
6891 net_rpc_usage(argc
, argv
);
6895 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6899 * 'net rpc' entrypoint.
6900 * @param argc Standard main() style argc.
6901 * @param argv Standard main() style argv. Initial components are already
6905 int net_rpc(int argc
, const char **argv
)
6907 struct functable func
[] = {
6908 {"audit", net_rpc_audit
},
6909 {"info", net_rpc_info
},
6910 {"join", net_rpc_join
},
6911 {"oldjoin", net_rpc_oldjoin
},
6912 {"testjoin", net_rpc_testjoin
},
6913 {"user", net_rpc_user
},
6914 {"password", rpc_user_password
},
6915 {"group", net_rpc_group
},
6916 {"share", net_rpc_share
},
6917 {"file", net_rpc_file
},
6918 {"printer", net_rpc_printer
},
6919 {"changetrustpw", net_rpc_changetrustpw
},
6920 {"trustdom", rpc_trustdom
},
6921 {"abortshutdown", rpc_shutdown_abort
},
6922 {"shutdown", rpc_shutdown
},
6923 {"samdump", rpc_samdump
},
6924 {"vampire", rpc_vampire
},
6925 {"getsid", net_rpc_getsid
},
6926 {"rights", net_rpc_rights
},
6927 {"service", net_rpc_service
},
6928 {"registry", net_rpc_registry
},
6929 {"shell", net_rpc_shell
},
6930 {"help", net_rpc_help
},
6933 return net_run_function(argc
, argv
, func
, net_rpc_usage
);