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 argc 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
;
122 /* make use of cli_state handed over as an argument, if possible */
124 nt_status
= net_make_ipc_connection(conn_flags
, &cli
);
125 if (!NT_STATUS_IS_OK(nt_status
)) {
126 DEBUG(1, ("failed to make ipc connection: %s\n",
127 nt_errstr(nt_status
)));
140 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
141 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
)) {
153 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
154 if (lp_client_schannel() && (pipe_idx
== PI_NETLOGON
)) {
155 /* Always try and create an schannel netlogon pipe. */
156 pipe_hnd
= cli_rpc_pipe_open_schannel(cli
, pipe_idx
,
157 PIPE_AUTH_LEVEL_PRIVACY
,
161 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
162 nt_errstr(nt_status
) ));
167 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, pipe_idx
, &nt_status
);
169 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
170 cli_get_pipe_name(pipe_idx
),
171 nt_errstr(nt_status
) ));
178 nt_status
= fn(domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
180 if (!NT_STATUS_IS_OK(nt_status
)) {
181 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
183 DEBUG(5, ("rpc command function succedded\n"));
186 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
188 cli_rpc_pipe_close(pipe_hnd
);
192 /* close the connection only if it was opened here */
197 talloc_destroy(mem_ctx
);
198 return (!NT_STATUS_IS_OK(nt_status
));
202 * Force a change of the trust acccount password.
204 * All parameters are provided by the run_rpc_command function, except for
205 * argc, argv which are passes through.
207 * @param domain_sid The domain sid aquired from the remote server
208 * @param cli A cli_state connected to the server.
209 * @param mem_ctx Talloc context, destoyed on compleation of the function.
210 * @param argc Standard main() style argc
211 * @param argc Standard main() style argv. Initial components are already
214 * @return Normal NTSTATUS return.
217 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
,
218 const char *domain_name
,
219 struct cli_state
*cli
,
220 struct rpc_pipe_client
*pipe_hnd
,
226 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
);
230 * Force a change of the trust acccount password.
232 * @param argc Standard main() style argc
233 * @param argc Standard main() style argv. Initial components are already
236 * @return A shell status integer (0 for success)
239 int net_rpc_changetrustpw(int argc
, const char **argv
)
241 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
242 rpc_changetrustpw_internals
,
247 * Join a domain, the old way.
249 * This uses 'machinename' as the inital password, and changes it.
251 * The password should be created with 'server manager' or equiv first.
253 * All parameters are provided by the run_rpc_command function, except for
254 * argc, argv which are passes through.
256 * @param domain_sid The domain sid aquired from the remote server
257 * @param cli A cli_state connected to the server.
258 * @param mem_ctx Talloc context, destoyed on compleation of the function.
259 * @param argc Standard main() style argc
260 * @param argc Standard main() style argv. Initial components are already
263 * @return Normal NTSTATUS return.
266 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
,
267 const char *domain_name
,
268 struct cli_state
*cli
,
269 struct rpc_pipe_client
*pipe_hnd
,
275 fstring trust_passwd
;
276 unsigned char orig_trust_passwd_hash
[16];
278 uint32 sec_channel_type
;
280 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &result
);
282 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
285 nt_errstr(result
) ));
290 check what type of join - if the user want's to join as
291 a BDC, the server must agree that we are a BDC.
294 sec_channel_type
= get_sec_channel_type(argv
[0]);
296 sec_channel_type
= get_sec_channel_type(NULL
);
299 fstrcpy(trust_passwd
, global_myname());
300 strlower_m(trust_passwd
);
303 * Machine names can be 15 characters, but the max length on
304 * a password is 14. --jerry
307 trust_passwd
[14] = '\0';
309 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
311 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
,
312 orig_trust_passwd_hash
,
315 if (NT_STATUS_IS_OK(result
))
316 printf("Joined domain %s.\n",opt_target_workgroup
);
319 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
320 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
321 result
= NT_STATUS_UNSUCCESSFUL
;
328 * Join a domain, the old way.
330 * @param argc Standard main() style argc
331 * @param argc Standard main() style argv. Initial components are already
334 * @return A shell status integer (0 for success)
337 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
339 return run_rpc_command(NULL
, PI_NETLOGON
,
340 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
341 rpc_oldjoin_internals
,
346 * Join a domain, the old way. This function exists to allow
347 * the message to be displayed when oldjoin was explicitly
348 * requested, but not when it was implied by "net rpc join"
350 * @param argc Standard main() style argc
351 * @param argc Standard main() style argv. Initial components are already
354 * @return A shell status integer (0 for success)
357 static int net_rpc_oldjoin(int argc
, const char **argv
)
359 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
362 d_fprintf(stderr
, "Failed to join domain\n");
369 * Basic usage function for 'net rpc join'
370 * @param argc Standard main() style argc
371 * @param argc Standard main() style argv. Initial components are already
375 static int rpc_join_usage(int argc
, const char **argv
)
377 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
378 "\t to join a domain with admin username & password\n"\
379 "\t\t password will be prompted if needed and none is specified\n"\
380 "\t <type> can be (default MEMBER)\n"\
381 "\t\t BDC - Join as a BDC\n"\
382 "\t\t PDC - Join as a PDC\n"\
383 "\t\t MEMBER - Join as a MEMBER server\n");
385 net_common_flags_usage(argc
, argv
);
390 * 'net rpc join' entrypoint.
391 * @param argc Standard main() style argc
392 * @param argc Standard main() style argv. Initial components are already
395 * Main 'net_rpc_join()' (where the admin username/password is used) is
397 * Try to just change the password, but if that doesn't work, use/prompt
398 * for a username/password.
401 int net_rpc_join(int argc
, const char **argv
)
403 if (lp_server_role() == ROLE_STANDALONE
) {
404 d_printf("cannot join as standalone machine\n");
408 if (strlen(global_myname()) > 15) {
409 d_printf("Our netbios name can be at most 15 chars long, "
410 "\"%s\" is %u chars long\n",
411 global_myname(), (unsigned int)strlen(global_myname()));
415 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
418 return net_rpc_join_newstyle(argc
, argv
);
422 * display info about a rpc domain
424 * All parameters are provided by the run_rpc_command function, except for
425 * argc, argv which are passed through.
427 * @param domain_sid The domain sid acquired from the remote server
428 * @param cli A cli_state connected to the server.
429 * @param mem_ctx Talloc context, destoyed on completion of the function.
430 * @param argc Standard main() style argc
431 * @param argv Standard main() style argv. Initial components are already
434 * @return Normal NTSTATUS return.
437 NTSTATUS
rpc_info_internals(const DOM_SID
*domain_sid
,
438 const char *domain_name
,
439 struct cli_state
*cli
,
440 struct rpc_pipe_client
*pipe_hnd
,
445 POLICY_HND connect_pol
, domain_pol
;
446 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
447 union samr_DomainInfo
*info
= NULL
;
450 sid_to_fstring(sid_str
, domain_sid
);
452 /* Get sam policy handle */
453 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
454 pipe_hnd
->cli
->desthost
,
455 MAXIMUM_ALLOWED_ACCESS
,
457 if (!NT_STATUS_IS_OK(result
)) {
458 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
462 /* Get domain policy handle */
463 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
465 MAXIMUM_ALLOWED_ACCESS
,
466 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
468 if (!NT_STATUS_IS_OK(result
)) {
469 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
473 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
477 if (NT_STATUS_IS_OK(result
)) {
478 d_printf("Domain Name: %s\n", info
->info2
.domain_name
.string
);
479 d_printf("Domain SID: %s\n", sid_str
);
480 d_printf("Sequence number: %llu\n",
481 (unsigned long long)info
->info2
.sequence_num
);
482 d_printf("Num users: %u\n", info
->info2
.num_users
);
483 d_printf("Num domain groups: %u\n", info
->info2
.num_groups
);
484 d_printf("Num local groups: %u\n", info
->info2
.num_aliases
);
492 * 'net rpc info' entrypoint.
493 * @param argc Standard main() style argc
494 * @param argc Standard main() style argv. Initial components are already
498 int net_rpc_info(int argc
, const char **argv
)
500 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_PDC
,
506 * Fetch domain SID into the local secrets.tdb
508 * All parameters are provided by the run_rpc_command function, except for
509 * argc, argv which are passes through.
511 * @param domain_sid The domain sid acquired from the remote server
512 * @param cli A cli_state connected to the server.
513 * @param mem_ctx Talloc context, destoyed on completion of the function.
514 * @param argc Standard main() style argc
515 * @param argv Standard main() style argv. Initial components are already
518 * @return Normal NTSTATUS return.
521 static NTSTATUS
rpc_getsid_internals(const DOM_SID
*domain_sid
,
522 const char *domain_name
,
523 struct cli_state
*cli
,
524 struct rpc_pipe_client
*pipe_hnd
,
531 sid_to_fstring(sid_str
, domain_sid
);
532 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
533 sid_str
, domain_name
);
535 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
536 DEBUG(0,("Can't store domain SID\n"));
537 return NT_STATUS_UNSUCCESSFUL
;
544 * 'net rpc getsid' entrypoint.
545 * @param argc Standard main() style argc
546 * @param argc Standard main() style argv. Initial components are already
550 int net_rpc_getsid(int argc
, const char **argv
)
552 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
553 rpc_getsid_internals
,
557 /****************************************************************************/
560 * Basic usage function for 'net rpc user'
561 * @param argc Standard main() style argc.
562 * @param argv Standard main() style argv. Initial components are already
566 static int rpc_user_usage(int argc
, const char **argv
)
568 return net_help_user(argc
, argv
);
572 * Add a new user to a remote RPC server
574 * All parameters are provided by the run_rpc_command function, except for
575 * argc, argv which are passes through.
577 * @param domain_sid The domain sid acquired from the remote server
578 * @param cli A cli_state connected to the server.
579 * @param mem_ctx Talloc context, destoyed on completion of the function.
580 * @param argc Standard main() style argc
581 * @param argv Standard main() style argv. Initial components are already
584 * @return Normal NTSTATUS return.
587 static NTSTATUS
rpc_user_add_internals(const DOM_SID
*domain_sid
,
588 const char *domain_name
,
589 struct cli_state
*cli
,
590 struct rpc_pipe_client
*pipe_hnd
,
592 int argc
, const char **argv
)
595 POLICY_HND connect_pol
, domain_pol
, user_pol
;
596 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
597 const char *acct_name
;
598 struct lsa_String lsa_acct_name
;
600 uint32 acct_flags
, user_rid
;
601 uint32_t access_granted
= 0;
602 struct samr_Ids user_rids
, name_types
;
605 d_printf("User must be specified\n");
606 rpc_user_usage(argc
, argv
);
611 init_lsa_String(&lsa_acct_name
, acct_name
);
613 /* Get sam policy handle */
615 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
616 pipe_hnd
->cli
->desthost
,
617 MAXIMUM_ALLOWED_ACCESS
,
619 if (!NT_STATUS_IS_OK(result
)) {
623 /* Get domain policy handle */
625 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
627 MAXIMUM_ALLOWED_ACCESS
,
628 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
630 if (!NT_STATUS_IS_OK(result
)) {
634 /* Create domain user */
636 acb_info
= ACB_NORMAL
;
637 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
638 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
639 SAMR_USER_ACCESS_SET_PASSWORD
|
640 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
641 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
643 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
652 if (!NT_STATUS_IS_OK(result
)) {
658 union samr_UserInfo info
;
661 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
668 if (!NT_STATUS_IS_OK(result
)) {
672 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
674 MAXIMUM_ALLOWED_ACCESS
,
678 if (!NT_STATUS_IS_OK(result
)) {
682 /* Set password on account */
684 encode_pw_buffer(pwbuf
, argv
[1], STR_UNICODE
);
686 init_samr_user_info24(&info
.info24
, pwbuf
, 24);
688 SamOEMhashBlob(info
.info24
.password
.data
, 516,
689 &cli
->user_session_key
);
691 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
696 if (!NT_STATUS_IS_OK(result
)) {
697 d_fprintf(stderr
, "Failed to set password for user %s - %s\n",
698 acct_name
, nt_errstr(result
));
700 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
703 if (!NT_STATUS_IS_OK(result
)) {
704 d_fprintf(stderr
, "Failed to delete user %s - %s\n",
705 acct_name
, nt_errstr(result
));
712 if (!NT_STATUS_IS_OK(result
)) {
713 d_fprintf(stderr
, "Failed to add user '%s' with %s.\n",
714 acct_name
, nt_errstr(result
));
716 d_printf("Added user '%s'.\n", acct_name
);
722 * Add a new user to a remote RPC server
724 * @param argc Standard main() style argc
725 * @param argv Standard main() style argv. Initial components are already
728 * @return A shell status integer (0 for success)
731 static int rpc_user_add(int argc
, const char **argv
)
733 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_add_internals
,
738 * Delete a user from a remote RPC server
740 * All parameters are provided by the run_rpc_command function, except for
741 * argc, argv which are passes through.
743 * @param domain_sid The domain sid acquired from the remote server
744 * @param cli A cli_state connected to the server.
745 * @param mem_ctx Talloc context, destoyed on completion of the function.
746 * @param argc Standard main() style argc
747 * @param argv Standard main() style argv. Initial components are already
750 * @return Normal NTSTATUS return.
753 static NTSTATUS
rpc_user_del_internals(const DOM_SID
*domain_sid
,
754 const char *domain_name
,
755 struct cli_state
*cli
,
756 struct rpc_pipe_client
*pipe_hnd
,
761 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
762 POLICY_HND connect_pol
, domain_pol
, user_pol
;
763 const char *acct_name
;
766 d_printf("User must be specified\n");
767 rpc_user_usage(argc
, argv
);
773 /* Get sam policy and domain handles */
775 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
776 pipe_hnd
->cli
->desthost
,
777 MAXIMUM_ALLOWED_ACCESS
,
780 if (!NT_STATUS_IS_OK(result
)) {
784 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
786 MAXIMUM_ALLOWED_ACCESS
,
787 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
790 if (!NT_STATUS_IS_OK(result
)) {
794 /* Get handle on user */
797 struct samr_Ids user_rids
, name_types
;
798 struct lsa_String lsa_acct_name
;
800 init_lsa_String(&lsa_acct_name
, acct_name
);
802 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
809 if (!NT_STATUS_IS_OK(result
)) {
813 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
815 MAXIMUM_ALLOWED_ACCESS
,
819 if (!NT_STATUS_IS_OK(result
)) {
826 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
829 if (!NT_STATUS_IS_OK(result
)) {
834 if (!NT_STATUS_IS_OK(result
)) {
835 d_fprintf(stderr
, "Failed to delete user '%s' with %s.\n",
836 acct_name
, nt_errstr(result
));
838 d_printf("Deleted user '%s'.\n", acct_name
);
845 * Rename a user on a remote RPC server
847 * All parameters are provided by the run_rpc_command function, except for
848 * argc, argv which are passes through.
850 * @param domain_sid The domain sid acquired from the remote server
851 * @param cli A cli_state connected to the server.
852 * @param mem_ctx Talloc context, destoyed on completion of the function.
853 * @param argc Standard main() style argc
854 * @param argv Standard main() style argv. Initial components are already
857 * @return Normal NTSTATUS return.
860 static NTSTATUS
rpc_user_rename_internals(const DOM_SID
*domain_sid
,
861 const char *domain_name
,
862 struct cli_state
*cli
,
863 struct rpc_pipe_client
*pipe_hnd
,
868 POLICY_HND connect_pol
, domain_pol
, user_pol
;
869 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
870 uint32 info_level
= 7;
871 const char *old_name
, *new_name
;
872 struct samr_Ids user_rids
, name_types
;
873 struct lsa_String lsa_acct_name
;
874 union samr_UserInfo
*info
= NULL
;
877 d_printf("Old and new username must be specified\n");
878 rpc_user_usage(argc
, argv
);
885 /* Get sam policy handle */
887 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
888 pipe_hnd
->cli
->desthost
,
889 MAXIMUM_ALLOWED_ACCESS
,
892 if (!NT_STATUS_IS_OK(result
)) {
896 /* Get domain policy handle */
898 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
900 MAXIMUM_ALLOWED_ACCESS
,
901 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
903 if (!NT_STATUS_IS_OK(result
)) {
907 init_lsa_String(&lsa_acct_name
, old_name
);
909 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
915 if (!NT_STATUS_IS_OK(result
)) {
919 /* Open domain user */
920 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
922 MAXIMUM_ALLOWED_ACCESS
,
926 if (!NT_STATUS_IS_OK(result
)) {
930 /* Query user info */
931 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
936 if (!NT_STATUS_IS_OK(result
)) {
940 init_samr_user_info7(&info
->info7
, new_name
);
943 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
948 if (!NT_STATUS_IS_OK(result
)) {
953 if (!NT_STATUS_IS_OK(result
)) {
954 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n", old_name
, new_name
,
957 d_printf("Renamed user from %s to %s\n", old_name
, new_name
);
963 * Rename a user on a remote RPC server
965 * @param argc Standard main() style argc
966 * @param argv Standard main() style argv. Initial components are already
969 * @return A shell status integer (0 for success)
972 static int rpc_user_rename(int argc
, const char **argv
)
974 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_rename_internals
,
979 * Delete a user from a remote RPC server
981 * @param argc Standard main() style argc
982 * @param argv Standard main() style argv. Initial components are already
985 * @return A shell status integer (0 for success)
988 static int rpc_user_delete(int argc
, const char **argv
)
990 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_del_internals
,
995 * Set a password for a user on a remote RPC server
997 * All parameters are provided by the run_rpc_command function, except for
998 * argc, argv which are passes through.
1000 * @param domain_sid The domain sid acquired from the remote server
1001 * @param cli A cli_state connected to the server.
1002 * @param mem_ctx Talloc context, destoyed on completion of the function.
1003 * @param argc Standard main() style argc
1004 * @param argv Standard main() style argv. Initial components are already
1007 * @return Normal NTSTATUS return.
1010 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
1011 const char *domain_name
,
1012 struct cli_state
*cli
,
1013 struct rpc_pipe_client
*pipe_hnd
,
1014 TALLOC_CTX
*mem_ctx
,
1018 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1019 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1022 const char *new_password
;
1023 char *prompt
= NULL
;
1024 union samr_UserInfo info
;
1027 d_printf("User must be specified\n");
1028 rpc_user_usage(argc
, argv
);
1029 return NT_STATUS_OK
;
1035 new_password
= argv
[1];
1037 asprintf(&prompt
, "Enter new password for %s:", user
);
1038 new_password
= getpass(prompt
);
1042 /* Get sam policy and domain handles */
1044 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1045 pipe_hnd
->cli
->desthost
,
1046 MAXIMUM_ALLOWED_ACCESS
,
1049 if (!NT_STATUS_IS_OK(result
)) {
1053 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1055 MAXIMUM_ALLOWED_ACCESS
,
1056 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1059 if (!NT_STATUS_IS_OK(result
)) {
1063 /* Get handle on user */
1066 struct samr_Ids user_rids
, name_types
;
1067 struct lsa_String lsa_acct_name
;
1069 init_lsa_String(&lsa_acct_name
, user
);
1071 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1077 if (!NT_STATUS_IS_OK(result
)) {
1081 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1083 MAXIMUM_ALLOWED_ACCESS
,
1087 if (!NT_STATUS_IS_OK(result
)) {
1092 /* Set password on account */
1094 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
1096 init_samr_user_info24(&info
.info24
, pwbuf
, 24);
1098 SamOEMhashBlob(info
.info24
.password
.data
, 516,
1099 &cli
->user_session_key
);
1101 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
1106 if (!NT_STATUS_IS_OK(result
)) {
1110 /* Display results */
1118 * Set a user's password on a remote RPC server
1120 * @param argc Standard main() style argc
1121 * @param argv Standard main() style argv. Initial components are already
1124 * @return A shell status integer (0 for success)
1127 static int rpc_user_password(int argc
, const char **argv
)
1129 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
1134 * List user's groups on a remote RPC server
1136 * All parameters are provided by the run_rpc_command function, except for
1137 * argc, argv which are passes through.
1139 * @param domain_sid The domain sid acquired from the remote server
1140 * @param cli A cli_state connected to the server.
1141 * @param mem_ctx Talloc context, destoyed on completion of the function.
1142 * @param argc Standard main() style argc
1143 * @param argv Standard main() style argv. Initial components are already
1146 * @return Normal NTSTATUS return.
1149 static NTSTATUS
rpc_user_info_internals(const DOM_SID
*domain_sid
,
1150 const char *domain_name
,
1151 struct cli_state
*cli
,
1152 struct rpc_pipe_client
*pipe_hnd
,
1153 TALLOC_CTX
*mem_ctx
,
1157 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1158 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1160 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
1161 struct lsa_Strings names
;
1162 struct samr_Ids types
;
1163 uint32_t *lrids
= NULL
;
1164 struct samr_Ids rids
, name_types
;
1165 struct lsa_String lsa_acct_name
;
1169 d_printf("User must be specified\n");
1170 rpc_user_usage(argc
, argv
);
1171 return NT_STATUS_OK
;
1173 /* Get sam policy handle */
1175 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1176 pipe_hnd
->cli
->desthost
,
1177 MAXIMUM_ALLOWED_ACCESS
,
1179 if (!NT_STATUS_IS_OK(result
)) goto done
;
1181 /* Get domain policy handle */
1183 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1185 MAXIMUM_ALLOWED_ACCESS
,
1186 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1188 if (!NT_STATUS_IS_OK(result
)) goto done
;
1190 /* Get handle on user */
1192 init_lsa_String(&lsa_acct_name
, argv
[0]);
1194 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1201 if (!NT_STATUS_IS_OK(result
)) goto done
;
1203 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1205 MAXIMUM_ALLOWED_ACCESS
,
1208 if (!NT_STATUS_IS_OK(result
)) goto done
;
1210 result
= rpccli_samr_GetGroupsForUser(pipe_hnd
, mem_ctx
,
1214 if (!NT_STATUS_IS_OK(result
)) goto done
;
1218 if (rid_array
->count
) {
1219 if ((lrids
= TALLOC_ARRAY(mem_ctx
, uint32
, rid_array
->count
)) == NULL
) {
1220 result
= NT_STATUS_NO_MEMORY
;
1224 for (i
= 0; i
< rid_array
->count
; i
++)
1225 lrids
[i
] = rid_array
->rids
[i
].rid
;
1227 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
1234 if (!NT_STATUS_IS_OK(result
)) {
1238 /* Display results */
1240 for (i
= 0; i
< names
.count
; i
++)
1241 printf("%s\n", names
.names
[i
].string
);
1248 * List a user's groups from a remote RPC server
1250 * @param argc Standard main() style argc
1251 * @param argv Standard main() style argv. Initial components are already
1254 * @return A shell status integer (0 for success)
1257 static int rpc_user_info(int argc
, const char **argv
)
1259 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
1264 * List users on a remote RPC server
1266 * All parameters are provided by the run_rpc_command function, except for
1267 * argc, argv which are passes through.
1269 * @param domain_sid The domain sid acquired from the remote server
1270 * @param cli A cli_state connected to the server.
1271 * @param mem_ctx Talloc context, destoyed on completion of the function.
1272 * @param argc Standard main() style argc
1273 * @param argv Standard main() style argv. Initial components are already
1276 * @return Normal NTSTATUS return.
1279 static NTSTATUS
rpc_user_list_internals(const DOM_SID
*domain_sid
,
1280 const char *domain_name
,
1281 struct cli_state
*cli
,
1282 struct rpc_pipe_client
*pipe_hnd
,
1283 TALLOC_CTX
*mem_ctx
,
1287 POLICY_HND connect_pol
, domain_pol
;
1288 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1289 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
1291 /* Get sam policy handle */
1293 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1294 pipe_hnd
->cli
->desthost
,
1295 MAXIMUM_ALLOWED_ACCESS
,
1297 if (!NT_STATUS_IS_OK(result
)) {
1301 /* Get domain policy handle */
1303 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1305 MAXIMUM_ALLOWED_ACCESS
,
1306 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1308 if (!NT_STATUS_IS_OK(result
)) {
1312 /* Query domain users */
1313 if (opt_long_list_entries
)
1314 d_printf("\nUser name Comment"\
1315 "\n-----------------------------\n");
1317 const char *user
= NULL
;
1318 const char *desc
= NULL
;
1319 uint32 max_entries
, max_size
;
1320 uint32_t total_size
, returned_size
;
1321 union samr_DispInfo info
;
1323 get_query_dispinfo_params(
1324 loop_count
, &max_entries
, &max_size
);
1326 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
1336 start_idx
+= info
.info1
.count
;
1337 num_entries
= info
.info1
.count
;
1339 for (i
= 0; i
< num_entries
; i
++) {
1340 user
= info
.info1
.entries
[i
].account_name
.string
;
1341 if (opt_long_list_entries
)
1342 desc
= info
.info1
.entries
[i
].description
.string
;
1343 if (opt_long_list_entries
)
1344 printf("%-21.21s %s\n", user
, desc
);
1346 printf("%s\n", user
);
1348 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1355 * 'net rpc user' entrypoint.
1356 * @param argc Standard main() style argc
1357 * @param argc Standard main() style argv. Initial components are already
1361 int net_rpc_user(int argc
, const char **argv
)
1363 struct functable func
[] = {
1364 {"add", rpc_user_add
},
1365 {"info", rpc_user_info
},
1366 {"delete", rpc_user_delete
},
1367 {"password", rpc_user_password
},
1368 {"rename", rpc_user_rename
},
1373 return run_rpc_command(NULL
,PI_SAMR
, 0,
1374 rpc_user_list_internals
,
1378 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1381 static NTSTATUS
rpc_sh_user_list(TALLOC_CTX
*mem_ctx
,
1382 struct rpc_sh_ctx
*ctx
,
1383 struct rpc_pipe_client
*pipe_hnd
,
1384 int argc
, const char **argv
)
1386 return rpc_user_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
1387 ctx
->cli
, pipe_hnd
, mem_ctx
,
1391 static NTSTATUS
rpc_sh_user_info(TALLOC_CTX
*mem_ctx
,
1392 struct rpc_sh_ctx
*ctx
,
1393 struct rpc_pipe_client
*pipe_hnd
,
1394 int argc
, const char **argv
)
1396 return rpc_user_info_internals(ctx
->domain_sid
, ctx
->domain_name
,
1397 ctx
->cli
, pipe_hnd
, mem_ctx
,
1401 static NTSTATUS
rpc_sh_handle_user(TALLOC_CTX
*mem_ctx
,
1402 struct rpc_sh_ctx
*ctx
,
1403 struct rpc_pipe_client
*pipe_hnd
,
1404 int argc
, const char **argv
,
1406 TALLOC_CTX
*mem_ctx
,
1407 struct rpc_sh_ctx
*ctx
,
1408 struct rpc_pipe_client
*pipe_hnd
,
1409 POLICY_HND
*user_hnd
,
1410 int argc
, const char **argv
))
1412 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1413 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1416 enum lsa_SidType type
;
1419 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1420 return NT_STATUS_INVALID_PARAMETER
;
1423 ZERO_STRUCT(connect_pol
);
1424 ZERO_STRUCT(domain_pol
);
1425 ZERO_STRUCT(user_pol
);
1427 result
= net_rpc_lookup_name(mem_ctx
, pipe_hnd
->cli
, argv
[0],
1428 NULL
, NULL
, &sid
, &type
);
1429 if (!NT_STATUS_IS_OK(result
)) {
1430 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1435 if (type
!= SID_NAME_USER
) {
1436 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1437 sid_type_lookup(type
));
1438 result
= NT_STATUS_NO_SUCH_USER
;
1442 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1443 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1444 result
= NT_STATUS_NO_SUCH_USER
;
1448 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1449 pipe_hnd
->cli
->desthost
,
1450 MAXIMUM_ALLOWED_ACCESS
,
1452 if (!NT_STATUS_IS_OK(result
)) {
1456 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1458 MAXIMUM_ALLOWED_ACCESS
,
1461 if (!NT_STATUS_IS_OK(result
)) {
1465 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1467 MAXIMUM_ALLOWED_ACCESS
,
1470 if (!NT_STATUS_IS_OK(result
)) {
1474 result
= fn(mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1477 if (is_valid_policy_hnd(&user_pol
)) {
1478 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1480 if (is_valid_policy_hnd(&domain_pol
)) {
1481 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1483 if (is_valid_policy_hnd(&connect_pol
)) {
1484 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1489 static NTSTATUS
rpc_sh_user_show_internals(TALLOC_CTX
*mem_ctx
,
1490 struct rpc_sh_ctx
*ctx
,
1491 struct rpc_pipe_client
*pipe_hnd
,
1492 POLICY_HND
*user_hnd
,
1493 int argc
, const char **argv
)
1496 union samr_UserInfo
*info
= NULL
;
1499 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1500 return NT_STATUS_INVALID_PARAMETER
;
1503 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1507 if (!NT_STATUS_IS_OK(result
)) {
1511 d_printf("user rid: %d, group rid: %d\n",
1513 info
->info21
.primary_gid
);
1518 static NTSTATUS
rpc_sh_user_show(TALLOC_CTX
*mem_ctx
,
1519 struct rpc_sh_ctx
*ctx
,
1520 struct rpc_pipe_client
*pipe_hnd
,
1521 int argc
, const char **argv
)
1523 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1524 rpc_sh_user_show_internals
);
1527 #define FETCHSTR(name, rec) \
1528 do { if (strequal(ctx->thiscmd, name)) { \
1529 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1532 #define SETSTR(name, rec, flag) \
1533 do { if (strequal(ctx->thiscmd, name)) { \
1534 init_lsa_String(&(info->info21.rec), argv[0]); \
1535 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1538 static NTSTATUS
rpc_sh_user_str_edit_internals(TALLOC_CTX
*mem_ctx
,
1539 struct rpc_sh_ctx
*ctx
,
1540 struct rpc_pipe_client
*pipe_hnd
,
1541 POLICY_HND
*user_hnd
,
1542 int argc
, const char **argv
)
1545 const char *username
;
1546 const char *oldval
= "";
1547 union samr_UserInfo
*info
= NULL
;
1550 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1552 return NT_STATUS_INVALID_PARAMETER
;
1555 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1559 if (!NT_STATUS_IS_OK(result
)) {
1563 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1565 FETCHSTR("fullname", full_name
);
1566 FETCHSTR("homedir", home_directory
);
1567 FETCHSTR("homedrive", home_drive
);
1568 FETCHSTR("logonscript", logon_script
);
1569 FETCHSTR("profilepath", profile_path
);
1570 FETCHSTR("description", description
);
1573 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1577 if (strcmp(argv
[0], "NULL") == 0) {
1581 ZERO_STRUCT(info
->info21
);
1583 SETSTR("fullname", full_name
, FULL_NAME
);
1584 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1585 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1586 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1587 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1588 SETSTR("description", description
, DESCRIPTION
);
1590 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1595 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1596 ctx
->thiscmd
, oldval
, argv
[0]);
1603 #define HANDLEFLG(name, rec) \
1604 do { if (strequal(ctx->thiscmd, name)) { \
1605 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1607 newflags = oldflags | ACB_##rec; \
1609 newflags = oldflags & ~ACB_##rec; \
1612 static NTSTATUS
rpc_sh_user_str_edit(TALLOC_CTX
*mem_ctx
,
1613 struct rpc_sh_ctx
*ctx
,
1614 struct rpc_pipe_client
*pipe_hnd
,
1615 int argc
, const char **argv
)
1617 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1618 rpc_sh_user_str_edit_internals
);
1621 static NTSTATUS
rpc_sh_user_flag_edit_internals(TALLOC_CTX
*mem_ctx
,
1622 struct rpc_sh_ctx
*ctx
,
1623 struct rpc_pipe_client
*pipe_hnd
,
1624 POLICY_HND
*user_hnd
,
1625 int argc
, const char **argv
)
1628 const char *username
;
1629 const char *oldval
= "unknown";
1630 uint32 oldflags
, newflags
;
1632 union samr_UserInfo
*info
= NULL
;
1635 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1636 !strequal(argv
[0], "no"))) {
1637 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1639 return NT_STATUS_INVALID_PARAMETER
;
1642 newval
= strequal(argv
[0], "yes");
1644 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1648 if (!NT_STATUS_IS_OK(result
)) {
1652 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1653 oldflags
= info
->info21
.acct_flags
;
1654 newflags
= info
->info21
.acct_flags
;
1656 HANDLEFLG("disabled", DISABLED
);
1657 HANDLEFLG("pwnotreq", PWNOTREQ
);
1658 HANDLEFLG("autolock", AUTOLOCK
);
1659 HANDLEFLG("pwnoexp", PWNOEXP
);
1662 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1666 ZERO_STRUCT(info
->info21
);
1668 info
->info21
.acct_flags
= newflags
;
1669 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1671 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1676 if (NT_STATUS_IS_OK(result
)) {
1677 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1678 ctx
->thiscmd
, oldval
, argv
[0]);
1686 static NTSTATUS
rpc_sh_user_flag_edit(TALLOC_CTX
*mem_ctx
,
1687 struct rpc_sh_ctx
*ctx
,
1688 struct rpc_pipe_client
*pipe_hnd
,
1689 int argc
, const char **argv
)
1691 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1692 rpc_sh_user_flag_edit_internals
);
1695 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(TALLOC_CTX
*mem_ctx
,
1696 struct rpc_sh_ctx
*ctx
)
1698 static struct rpc_sh_cmd cmds
[] = {
1700 { "fullname", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1701 "Show/Set a user's full name" },
1703 { "homedir", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1704 "Show/Set a user's home directory" },
1706 { "homedrive", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1707 "Show/Set a user's home drive" },
1709 { "logonscript", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1710 "Show/Set a user's logon script" },
1712 { "profilepath", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1713 "Show/Set a user's profile path" },
1715 { "description", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1716 "Show/Set a user's description" },
1718 { "disabled", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1719 "Show/Set whether a user is disabled" },
1721 { "autolock", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1722 "Show/Set whether a user locked out" },
1724 { "pwnotreq", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1725 "Show/Set whether a user does not need a password" },
1727 { "pwnoexp", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1728 "Show/Set whether a user's password does not expire" },
1730 { NULL
, NULL
, 0, NULL
, NULL
}
1736 struct rpc_sh_cmd
*net_rpc_user_cmds(TALLOC_CTX
*mem_ctx
,
1737 struct rpc_sh_ctx
*ctx
)
1739 static struct rpc_sh_cmd cmds
[] = {
1741 { "list", NULL
, PI_SAMR
, rpc_sh_user_list
,
1742 "List available users" },
1744 { "info", NULL
, PI_SAMR
, rpc_sh_user_info
,
1745 "List the domain groups a user is member of" },
1747 { "show", NULL
, PI_SAMR
, rpc_sh_user_show
,
1748 "Show info about a user" },
1750 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1751 "Show/Modify a user's fields" },
1753 { NULL
, NULL
, 0, NULL
, NULL
}
1759 /****************************************************************************/
1762 * Basic usage function for 'net rpc group'
1763 * @param argc Standard main() style argc.
1764 * @param argv Standard main() style argv. Initial components are already
1768 static int rpc_group_usage(int argc
, const char **argv
)
1770 return net_help_group(argc
, argv
);
1774 * Delete group on a remote RPC server
1776 * All parameters are provided by the run_rpc_command function, except for
1777 * argc, argv which are passes through.
1779 * @param domain_sid The domain sid acquired from the remote server
1780 * @param cli A cli_state connected to the server.
1781 * @param mem_ctx Talloc context, destoyed on completion of the function.
1782 * @param argc Standard main() style argc
1783 * @param argv Standard main() style argv. Initial components are already
1786 * @return Normal NTSTATUS return.
1789 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1790 const char *domain_name
,
1791 struct cli_state
*cli
,
1792 struct rpc_pipe_client
*pipe_hnd
,
1793 TALLOC_CTX
*mem_ctx
,
1797 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1798 bool group_is_primary
= False
;
1799 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1801 struct samr_RidTypeArray
*rids
= NULL
;
1804 /* DOM_GID *user_gids; */
1806 struct samr_Ids group_rids
, name_types
;
1807 struct lsa_String lsa_acct_name
;
1808 union samr_UserInfo
*info
= NULL
;
1811 d_printf("specify group\n");
1812 rpc_group_usage(argc
,argv
);
1813 return NT_STATUS_OK
; /* ok? */
1816 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1817 pipe_hnd
->cli
->desthost
,
1818 MAXIMUM_ALLOWED_ACCESS
,
1821 if (!NT_STATUS_IS_OK(result
)) {
1822 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1826 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1828 MAXIMUM_ALLOWED_ACCESS
,
1829 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1832 if (!NT_STATUS_IS_OK(result
)) {
1833 d_fprintf(stderr
, "Request open_domain failed\n");
1837 init_lsa_String(&lsa_acct_name
, argv
[0]);
1839 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1845 if (!NT_STATUS_IS_OK(result
)) {
1846 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1850 switch (name_types
.ids
[0])
1852 case SID_NAME_DOM_GRP
:
1853 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1855 MAXIMUM_ALLOWED_ACCESS
,
1858 if (!NT_STATUS_IS_OK(result
)) {
1859 d_fprintf(stderr
, "Request open_group failed");
1863 group_rid
= group_rids
.ids
[0];
1865 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1869 if (!NT_STATUS_IS_OK(result
)) {
1870 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1875 d_printf("Domain Group %s (rid: %d) has %d members\n",
1876 argv
[0],group_rid
, rids
->count
);
1879 /* Check if group is anyone's primary group */
1880 for (i
= 0; i
< rids
->count
; i
++)
1882 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1884 MAXIMUM_ALLOWED_ACCESS
,
1888 if (!NT_STATUS_IS_OK(result
)) {
1889 d_fprintf(stderr
, "Unable to open group member %d\n",
1894 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1899 if (!NT_STATUS_IS_OK(result
)) {
1900 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1905 if (info
->info21
.primary_gid
== group_rid
) {
1907 d_printf("Group is primary group of %s\n",
1908 info
->info21
.account_name
.string
);
1910 group_is_primary
= True
;
1913 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1916 if (group_is_primary
) {
1917 d_fprintf(stderr
, "Unable to delete group because some "
1918 "of it's members have it as primary group\n");
1919 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1923 /* remove all group members */
1924 for (i
= 0; i
< rids
->count
; i
++)
1927 d_printf("Remove group member %d...",
1929 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1933 if (NT_STATUS_IS_OK(result
)) {
1938 d_printf("failed\n");
1943 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1947 /* removing a local group is easier... */
1948 case SID_NAME_ALIAS
:
1949 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1951 MAXIMUM_ALLOWED_ACCESS
,
1955 if (!NT_STATUS_IS_OK(result
)) {
1956 d_fprintf(stderr
, "Request open_alias failed\n");
1960 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1964 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1965 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1966 result
= NT_STATUS_UNSUCCESSFUL
;
1971 if (NT_STATUS_IS_OK(result
)) {
1973 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1975 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1976 get_friendly_nt_error_msg(result
));
1984 static int rpc_group_delete(int argc
, const char **argv
)
1986 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1990 static NTSTATUS
rpc_group_add_internals(const DOM_SID
*domain_sid
,
1991 const char *domain_name
,
1992 struct cli_state
*cli
,
1993 struct rpc_pipe_client
*pipe_hnd
,
1994 TALLOC_CTX
*mem_ctx
,
1998 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1999 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2000 union samr_GroupInfo group_info
;
2001 struct lsa_String grp_name
;
2005 d_printf("Group name must be specified\n");
2006 rpc_group_usage(argc
, argv
);
2007 return NT_STATUS_OK
;
2010 init_lsa_String(&grp_name
, argv
[0]);
2012 /* Get sam policy handle */
2014 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2015 pipe_hnd
->cli
->desthost
,
2016 MAXIMUM_ALLOWED_ACCESS
,
2018 if (!NT_STATUS_IS_OK(result
)) goto done
;
2020 /* Get domain policy handle */
2022 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2024 MAXIMUM_ALLOWED_ACCESS
,
2025 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2027 if (!NT_STATUS_IS_OK(result
)) goto done
;
2029 /* Create the group */
2031 result
= rpccli_samr_CreateDomainGroup(pipe_hnd
, mem_ctx
,
2034 MAXIMUM_ALLOWED_ACCESS
,
2037 if (!NT_STATUS_IS_OK(result
)) goto done
;
2039 if (strlen(opt_comment
) == 0) goto done
;
2041 /* We've got a comment to set */
2043 init_lsa_String(&group_info
.description
, opt_comment
);
2045 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
2049 if (!NT_STATUS_IS_OK(result
)) goto done
;
2052 if (NT_STATUS_IS_OK(result
))
2053 DEBUG(5, ("add group succeeded\n"));
2055 d_fprintf(stderr
, "add group failed: %s\n", nt_errstr(result
));
2060 static NTSTATUS
rpc_alias_add_internals(const DOM_SID
*domain_sid
,
2061 const char *domain_name
,
2062 struct cli_state
*cli
,
2063 struct rpc_pipe_client
*pipe_hnd
,
2064 TALLOC_CTX
*mem_ctx
,
2068 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
2069 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2070 union samr_AliasInfo alias_info
;
2071 struct lsa_String alias_name
;
2075 d_printf("Alias name must be specified\n");
2076 rpc_group_usage(argc
, argv
);
2077 return NT_STATUS_OK
;
2080 init_lsa_String(&alias_name
, argv
[0]);
2082 /* Get sam policy handle */
2084 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2085 pipe_hnd
->cli
->desthost
,
2086 MAXIMUM_ALLOWED_ACCESS
,
2088 if (!NT_STATUS_IS_OK(result
)) goto done
;
2090 /* Get domain policy handle */
2092 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2094 MAXIMUM_ALLOWED_ACCESS
,
2095 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2097 if (!NT_STATUS_IS_OK(result
)) goto done
;
2099 /* Create the group */
2101 result
= rpccli_samr_CreateDomAlias(pipe_hnd
, mem_ctx
,
2104 MAXIMUM_ALLOWED_ACCESS
,
2107 if (!NT_STATUS_IS_OK(result
)) goto done
;
2109 if (strlen(opt_comment
) == 0) goto done
;
2111 /* We've got a comment to set */
2113 init_lsa_String(&alias_info
.description
, opt_comment
);
2115 result
= rpccli_samr_SetAliasInfo(pipe_hnd
, mem_ctx
,
2120 if (!NT_STATUS_IS_OK(result
)) goto done
;
2123 if (NT_STATUS_IS_OK(result
))
2124 DEBUG(5, ("add alias succeeded\n"));
2126 d_fprintf(stderr
, "add alias failed: %s\n", nt_errstr(result
));
2131 static int rpc_group_add(int argc
, const char **argv
)
2134 return run_rpc_command(NULL
, PI_SAMR
, 0,
2135 rpc_alias_add_internals
,
2138 return run_rpc_command(NULL
, PI_SAMR
, 0,
2139 rpc_group_add_internals
,
2143 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
2144 TALLOC_CTX
*mem_ctx
,
2147 enum lsa_SidType
*type
)
2149 DOM_SID
*sids
= NULL
;
2150 enum lsa_SidType
*types
= NULL
;
2151 struct rpc_pipe_client
*pipe_hnd
;
2153 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2155 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
2160 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, False
,
2161 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2163 if (!NT_STATUS_IS_OK(result
)) {
2167 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
2168 &name
, NULL
, 1, &sids
, &types
);
2170 if (NT_STATUS_IS_OK(result
)) {
2171 sid_copy(sid
, &sids
[0]);
2175 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
2179 cli_rpc_pipe_close(pipe_hnd
);
2182 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
2184 /* Try as S-1-5-whatever */
2188 if (string_to_sid(&tmp_sid
, name
)) {
2189 sid_copy(sid
, &tmp_sid
);
2190 *type
= SID_NAME_UNKNOWN
;
2191 result
= NT_STATUS_OK
;
2198 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2199 TALLOC_CTX
*mem_ctx
,
2200 const DOM_SID
*group_sid
,
2203 POLICY_HND connect_pol
, domain_pol
;
2206 POLICY_HND group_pol
;
2208 struct samr_Ids rids
, rid_types
;
2209 struct lsa_String lsa_acct_name
;
2213 sid_copy(&sid
, group_sid
);
2215 if (!sid_split_rid(&sid
, &group_rid
)) {
2216 return NT_STATUS_UNSUCCESSFUL
;
2219 /* Get sam policy handle */
2220 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2221 pipe_hnd
->cli
->desthost
,
2222 MAXIMUM_ALLOWED_ACCESS
,
2224 if (!NT_STATUS_IS_OK(result
)) {
2228 /* Get domain policy handle */
2229 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2231 MAXIMUM_ALLOWED_ACCESS
,
2234 if (!NT_STATUS_IS_OK(result
)) {
2238 init_lsa_String(&lsa_acct_name
, member
);
2240 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2247 if (!NT_STATUS_IS_OK(result
)) {
2248 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2252 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2254 MAXIMUM_ALLOWED_ACCESS
,
2258 if (!NT_STATUS_IS_OK(result
)) {
2262 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
2265 0x0005); /* unknown flags */
2268 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2272 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2273 TALLOC_CTX
*mem_ctx
,
2274 const DOM_SID
*alias_sid
,
2277 POLICY_HND connect_pol
, domain_pol
;
2280 POLICY_HND alias_pol
;
2283 enum lsa_SidType member_type
;
2287 sid_copy(&sid
, alias_sid
);
2289 if (!sid_split_rid(&sid
, &alias_rid
)) {
2290 return NT_STATUS_UNSUCCESSFUL
;
2293 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2294 &member_sid
, &member_type
);
2296 if (!NT_STATUS_IS_OK(result
)) {
2297 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2301 /* Get sam policy handle */
2302 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2303 pipe_hnd
->cli
->desthost
,
2304 MAXIMUM_ALLOWED_ACCESS
,
2306 if (!NT_STATUS_IS_OK(result
)) {
2310 /* Get domain policy handle */
2311 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2313 MAXIMUM_ALLOWED_ACCESS
,
2316 if (!NT_STATUS_IS_OK(result
)) {
2320 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2322 MAXIMUM_ALLOWED_ACCESS
,
2326 if (!NT_STATUS_IS_OK(result
)) {
2330 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
2334 if (!NT_STATUS_IS_OK(result
)) {
2339 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2343 static NTSTATUS
rpc_group_addmem_internals(const DOM_SID
*domain_sid
,
2344 const char *domain_name
,
2345 struct cli_state
*cli
,
2346 struct rpc_pipe_client
*pipe_hnd
,
2347 TALLOC_CTX
*mem_ctx
,
2352 enum lsa_SidType group_type
;
2355 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
2356 return NT_STATUS_UNSUCCESSFUL
;
2359 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2360 &group_sid
, &group_type
))) {
2361 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2362 return NT_STATUS_UNSUCCESSFUL
;
2365 if (group_type
== SID_NAME_DOM_GRP
) {
2366 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2367 &group_sid
, argv
[1]);
2369 if (!NT_STATUS_IS_OK(result
)) {
2370 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2371 argv
[1], argv
[0], nt_errstr(result
));
2376 if (group_type
== SID_NAME_ALIAS
) {
2377 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
2378 &group_sid
, argv
[1]);
2380 if (!NT_STATUS_IS_OK(result
)) {
2381 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2382 argv
[1], argv
[0], nt_errstr(result
));
2387 d_fprintf(stderr
, "Can only add members to global or local groups "
2388 "which %s is not\n", argv
[0]);
2390 return NT_STATUS_UNSUCCESSFUL
;
2393 static int rpc_group_addmem(int argc
, const char **argv
)
2395 return run_rpc_command(NULL
, PI_SAMR
, 0,
2396 rpc_group_addmem_internals
,
2400 static NTSTATUS
rpc_del_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2401 TALLOC_CTX
*mem_ctx
,
2402 const DOM_SID
*group_sid
,
2405 POLICY_HND connect_pol
, domain_pol
;
2408 POLICY_HND group_pol
;
2410 struct samr_Ids rids
, rid_types
;
2411 struct lsa_String lsa_acct_name
;
2415 sid_copy(&sid
, group_sid
);
2417 if (!sid_split_rid(&sid
, &group_rid
))
2418 return NT_STATUS_UNSUCCESSFUL
;
2420 /* Get sam policy handle */
2421 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2422 pipe_hnd
->cli
->desthost
,
2423 MAXIMUM_ALLOWED_ACCESS
,
2425 if (!NT_STATUS_IS_OK(result
))
2428 /* Get domain policy handle */
2429 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2431 MAXIMUM_ALLOWED_ACCESS
,
2434 if (!NT_STATUS_IS_OK(result
))
2437 init_lsa_String(&lsa_acct_name
, member
);
2439 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2445 if (!NT_STATUS_IS_OK(result
)) {
2446 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2450 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2452 MAXIMUM_ALLOWED_ACCESS
,
2456 if (!NT_STATUS_IS_OK(result
))
2459 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2464 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2468 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2469 TALLOC_CTX
*mem_ctx
,
2470 const DOM_SID
*alias_sid
,
2473 POLICY_HND connect_pol
, domain_pol
;
2476 POLICY_HND alias_pol
;
2479 enum lsa_SidType member_type
;
2483 sid_copy(&sid
, alias_sid
);
2485 if (!sid_split_rid(&sid
, &alias_rid
))
2486 return NT_STATUS_UNSUCCESSFUL
;
2488 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2489 &member_sid
, &member_type
);
2491 if (!NT_STATUS_IS_OK(result
)) {
2492 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2496 /* Get sam policy handle */
2497 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2498 pipe_hnd
->cli
->desthost
,
2499 MAXIMUM_ALLOWED_ACCESS
,
2501 if (!NT_STATUS_IS_OK(result
)) {
2505 /* Get domain policy handle */
2506 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2508 MAXIMUM_ALLOWED_ACCESS
,
2511 if (!NT_STATUS_IS_OK(result
)) {
2515 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2517 MAXIMUM_ALLOWED_ACCESS
,
2521 if (!NT_STATUS_IS_OK(result
))
2524 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2528 if (!NT_STATUS_IS_OK(result
))
2532 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2536 static NTSTATUS
rpc_group_delmem_internals(const DOM_SID
*domain_sid
,
2537 const char *domain_name
,
2538 struct cli_state
*cli
,
2539 struct rpc_pipe_client
*pipe_hnd
,
2540 TALLOC_CTX
*mem_ctx
,
2545 enum lsa_SidType group_type
;
2548 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
2549 return NT_STATUS_UNSUCCESSFUL
;
2552 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2553 &group_sid
, &group_type
))) {
2554 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2555 return NT_STATUS_UNSUCCESSFUL
;
2558 if (group_type
== SID_NAME_DOM_GRP
) {
2559 NTSTATUS result
= rpc_del_groupmem(pipe_hnd
, mem_ctx
,
2560 &group_sid
, argv
[1]);
2562 if (!NT_STATUS_IS_OK(result
)) {
2563 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2564 argv
[1], argv
[0], nt_errstr(result
));
2569 if (group_type
== SID_NAME_ALIAS
) {
2570 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2571 &group_sid
, argv
[1]);
2573 if (!NT_STATUS_IS_OK(result
)) {
2574 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2575 argv
[1], argv
[0], nt_errstr(result
));
2580 d_fprintf(stderr
, "Can only delete members from global or local groups "
2581 "which %s is not\n", argv
[0]);
2583 return NT_STATUS_UNSUCCESSFUL
;
2586 static int rpc_group_delmem(int argc
, const char **argv
)
2588 return run_rpc_command(NULL
, PI_SAMR
, 0,
2589 rpc_group_delmem_internals
,
2594 * List groups on a remote RPC server
2596 * All parameters are provided by the run_rpc_command function, except for
2597 * argc, argv which are passes through.
2599 * @param domain_sid The domain sid acquired from the remote server
2600 * @param cli A cli_state connected to the server.
2601 * @param mem_ctx Talloc context, destoyed on completion of the function.
2602 * @param argc Standard main() style argc
2603 * @param argv Standard main() style argv. Initial components are already
2606 * @return Normal NTSTATUS return.
2609 static NTSTATUS
rpc_group_list_internals(const DOM_SID
*domain_sid
,
2610 const char *domain_name
,
2611 struct cli_state
*cli
,
2612 struct rpc_pipe_client
*pipe_hnd
,
2613 TALLOC_CTX
*mem_ctx
,
2617 POLICY_HND connect_pol
, domain_pol
;
2618 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2619 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2620 struct samr_SamArray
*groups
= NULL
;
2621 bool global
= False
;
2623 bool builtin
= False
;
2631 for (i
=0; i
<argc
; i
++) {
2632 if (strequal(argv
[i
], "global"))
2635 if (strequal(argv
[i
], "local"))
2638 if (strequal(argv
[i
], "builtin"))
2642 /* Get sam policy handle */
2644 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2645 pipe_hnd
->cli
->desthost
,
2646 MAXIMUM_ALLOWED_ACCESS
,
2648 if (!NT_STATUS_IS_OK(result
)) {
2652 /* Get domain policy handle */
2654 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2656 MAXIMUM_ALLOWED_ACCESS
,
2657 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2659 if (!NT_STATUS_IS_OK(result
)) {
2663 /* Query domain groups */
2664 if (opt_long_list_entries
)
2665 d_printf("\nGroup name Comment"\
2666 "\n-----------------------------\n");
2668 uint32_t max_size
, total_size
, returned_size
;
2669 union samr_DispInfo info
;
2673 get_query_dispinfo_params(
2674 loop_count
, &max_entries
, &max_size
);
2676 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2685 num_entries
= info
.info3
.count
;
2686 start_idx
+= info
.info3
.count
;
2688 if (!NT_STATUS_IS_OK(result
) &&
2689 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2692 for (i
= 0; i
< num_entries
; i
++) {
2694 const char *group
= NULL
;
2695 const char *desc
= NULL
;
2697 group
= info
.info3
.entries
[i
].account_name
.string
;
2698 desc
= info
.info3
.entries
[i
].description
.string
;
2700 if (opt_long_list_entries
)
2701 printf("%-21.21s %-50.50s\n",
2704 printf("%s\n", group
);
2706 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2707 /* query domain aliases */
2712 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2718 if (!NT_STATUS_IS_OK(result
) &&
2719 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2722 for (i
= 0; i
< num_entries
; i
++) {
2724 const char *description
= NULL
;
2726 if (opt_long_list_entries
) {
2728 POLICY_HND alias_pol
;
2729 union samr_AliasInfo
*info
= NULL
;
2731 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2734 groups
->entries
[i
].idx
,
2736 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2740 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2742 description
= info
->description
.string
;
2746 if (description
!= NULL
) {
2747 printf("%-21.21s %-50.50s\n",
2748 groups
->entries
[i
].name
.string
,
2751 printf("%s\n", groups
->entries
[i
].name
.string
);
2754 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2755 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2756 /* Get builtin policy handle */
2758 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2760 MAXIMUM_ALLOWED_ACCESS
,
2761 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2763 if (!NT_STATUS_IS_OK(result
)) {
2766 /* query builtin aliases */
2769 if (!builtin
) break;
2771 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2777 if (!NT_STATUS_IS_OK(result
) &&
2778 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2781 for (i
= 0; i
< num_entries
; i
++) {
2783 const char *description
= NULL
;
2785 if (opt_long_list_entries
) {
2787 POLICY_HND alias_pol
;
2788 union samr_AliasInfo
*info
= NULL
;
2790 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2793 groups
->entries
[i
].idx
,
2795 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2799 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2801 description
= info
->description
.string
;
2805 if (description
!= NULL
) {
2806 printf("%-21.21s %-50.50s\n",
2807 groups
->entries
[i
].name
.string
,
2810 printf("%s\n", groups
->entries
[i
].name
.string
);
2813 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2819 static int rpc_group_list(int argc
, const char **argv
)
2821 return run_rpc_command(NULL
, PI_SAMR
, 0,
2822 rpc_group_list_internals
,
2826 static NTSTATUS
rpc_list_group_members(struct rpc_pipe_client
*pipe_hnd
,
2827 TALLOC_CTX
*mem_ctx
,
2828 const char *domain_name
,
2829 const DOM_SID
*domain_sid
,
2830 POLICY_HND
*domain_pol
,
2834 POLICY_HND group_pol
;
2835 uint32 num_members
, *group_rids
;
2837 struct samr_RidTypeArray
*rids
= NULL
;
2838 struct lsa_Strings names
;
2839 struct samr_Ids types
;
2842 sid_to_fstring(sid_str
, domain_sid
);
2844 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2846 MAXIMUM_ALLOWED_ACCESS
,
2850 if (!NT_STATUS_IS_OK(result
))
2853 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2857 if (!NT_STATUS_IS_OK(result
))
2860 num_members
= rids
->count
;
2861 group_rids
= rids
->rids
;
2863 while (num_members
> 0) {
2864 int this_time
= 512;
2866 if (num_members
< this_time
)
2867 this_time
= num_members
;
2869 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2876 if (!NT_STATUS_IS_OK(result
))
2879 /* We only have users as members, but make the output
2880 the same as the output of alias members */
2882 for (i
= 0; i
< this_time
; i
++) {
2884 if (opt_long_list_entries
) {
2885 printf("%s-%d %s\\%s %d\n", sid_str
,
2886 group_rids
[i
], domain_name
,
2887 names
.names
[i
].string
,
2890 printf("%s\\%s\n", domain_name
,
2891 names
.names
[i
].string
);
2895 num_members
-= this_time
;
2899 return NT_STATUS_OK
;
2902 static NTSTATUS
rpc_list_alias_members(struct rpc_pipe_client
*pipe_hnd
,
2903 TALLOC_CTX
*mem_ctx
,
2904 POLICY_HND
*domain_pol
,
2908 struct rpc_pipe_client
*lsa_pipe
;
2909 POLICY_HND alias_pol
, lsa_pol
;
2911 DOM_SID
*alias_sids
;
2914 enum lsa_SidType
*types
;
2916 struct lsa_SidArray sid_array
;
2918 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2920 MAXIMUM_ALLOWED_ACCESS
,
2924 if (!NT_STATUS_IS_OK(result
))
2927 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2931 if (!NT_STATUS_IS_OK(result
)) {
2932 d_fprintf(stderr
, "Couldn't list alias members\n");
2936 num_members
= sid_array
.num_sids
;
2938 if (num_members
== 0) {
2939 return NT_STATUS_OK
;
2942 lsa_pipe
= cli_rpc_pipe_open_noauth(pipe_hnd
->cli
, PI_LSARPC
, &result
);
2944 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2945 nt_errstr(result
) );
2949 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, True
,
2950 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2952 if (!NT_STATUS_IS_OK(result
)) {
2953 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2954 cli_rpc_pipe_close(lsa_pipe
);
2958 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2960 d_fprintf(stderr
, "Out of memory\n");
2961 cli_rpc_pipe_close(lsa_pipe
);
2962 return NT_STATUS_NO_MEMORY
;
2965 for (i
=0; i
<num_members
; i
++) {
2966 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2969 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
, num_members
,
2971 &domains
, &names
, &types
);
2973 if (!NT_STATUS_IS_OK(result
) &&
2974 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2975 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2976 cli_rpc_pipe_close(lsa_pipe
);
2980 for (i
= 0; i
< num_members
; i
++) {
2982 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2984 if (opt_long_list_entries
) {
2985 printf("%s %s\\%s %d\n", sid_str
,
2986 domains
[i
] ? domains
[i
] : "*unknown*",
2987 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2990 printf("%s\\%s\n", domains
[i
], names
[i
]);
2992 printf("%s\n", sid_str
);
2996 cli_rpc_pipe_close(lsa_pipe
);
2997 return NT_STATUS_OK
;
3000 static NTSTATUS
rpc_group_members_internals(const DOM_SID
*domain_sid
,
3001 const char *domain_name
,
3002 struct cli_state
*cli
,
3003 struct rpc_pipe_client
*pipe_hnd
,
3004 TALLOC_CTX
*mem_ctx
,
3009 POLICY_HND connect_pol
, domain_pol
;
3010 struct samr_Ids rids
, rid_types
;
3011 struct lsa_String lsa_acct_name
;
3013 /* Get sam policy handle */
3015 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3016 pipe_hnd
->cli
->desthost
,
3017 MAXIMUM_ALLOWED_ACCESS
,
3020 if (!NT_STATUS_IS_OK(result
))
3023 /* Get domain policy handle */
3025 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3027 MAXIMUM_ALLOWED_ACCESS
,
3028 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3031 if (!NT_STATUS_IS_OK(result
))
3034 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
3036 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
3043 if (!NT_STATUS_IS_OK(result
)) {
3045 /* Ok, did not find it in the global sam, try with builtin */
3047 DOM_SID sid_Builtin
;
3049 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3051 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
3053 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3055 MAXIMUM_ALLOWED_ACCESS
,
3059 if (!NT_STATUS_IS_OK(result
)) {
3060 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
3064 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
3071 if (!NT_STATUS_IS_OK(result
)) {
3072 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
3077 if (rids
.count
!= 1) {
3078 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
3082 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
3083 return rpc_list_group_members(pipe_hnd
, mem_ctx
, domain_name
,
3084 domain_sid
, &domain_pol
,
3088 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
3089 return rpc_list_alias_members(pipe_hnd
, mem_ctx
, &domain_pol
,
3093 return NT_STATUS_NO_SUCH_GROUP
;
3096 static int rpc_group_members(int argc
, const char **argv
)
3099 return rpc_group_usage(argc
, argv
);
3102 return run_rpc_command(NULL
, PI_SAMR
, 0,
3103 rpc_group_members_internals
,
3107 static NTSTATUS
rpc_group_rename_internals(const DOM_SID
*domain_sid
,
3108 const char *domain_name
,
3109 struct cli_state
*cli
,
3110 struct rpc_pipe_client
*pipe_hnd
,
3111 TALLOC_CTX
*mem_ctx
,
3116 POLICY_HND connect_pol
, domain_pol
, group_pol
;
3117 union samr_GroupInfo group_info
;
3118 struct samr_Ids rids
, rid_types
;
3119 struct lsa_String lsa_acct_name
;
3122 d_printf("Usage: 'net rpc group rename group newname'\n");
3123 return NT_STATUS_UNSUCCESSFUL
;
3126 /* Get sam policy handle */
3128 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3129 pipe_hnd
->cli
->desthost
,
3130 MAXIMUM_ALLOWED_ACCESS
,
3133 if (!NT_STATUS_IS_OK(result
))
3136 /* Get domain policy handle */
3138 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3140 MAXIMUM_ALLOWED_ACCESS
,
3141 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3144 if (!NT_STATUS_IS_OK(result
))
3147 init_lsa_String(&lsa_acct_name
, argv
[0]);
3149 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
3156 if (rids
.count
!= 1) {
3157 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
3161 if (rid_types
.ids
[0] != SID_NAME_DOM_GRP
) {
3162 d_fprintf(stderr
, "Can only rename domain groups\n");
3163 return NT_STATUS_UNSUCCESSFUL
;
3166 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
3168 MAXIMUM_ALLOWED_ACCESS
,
3172 if (!NT_STATUS_IS_OK(result
))
3175 init_lsa_String(&group_info
.name
, argv
[1]);
3177 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
3182 if (!NT_STATUS_IS_OK(result
))
3185 return NT_STATUS_NO_SUCH_GROUP
;
3188 static int rpc_group_rename(int argc
, const char **argv
)
3191 return rpc_group_usage(argc
, argv
);
3194 return run_rpc_command(NULL
, PI_SAMR
, 0,
3195 rpc_group_rename_internals
,
3200 * 'net rpc group' entrypoint.
3201 * @param argc Standard main() style argc
3202 * @param argc Standard main() style argv. Initial components are already
3206 int net_rpc_group(int argc
, const char **argv
)
3208 struct functable func
[] = {
3209 {"add", rpc_group_add
},
3210 {"delete", rpc_group_delete
},
3211 {"addmem", rpc_group_addmem
},
3212 {"delmem", rpc_group_delmem
},
3213 {"list", rpc_group_list
},
3214 {"members", rpc_group_members
},
3215 {"rename", rpc_group_rename
},
3220 return run_rpc_command(NULL
, PI_SAMR
, 0,
3221 rpc_group_list_internals
,
3225 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
3228 /****************************************************************************/
3230 static int rpc_share_usage(int argc
, const char **argv
)
3232 return net_help_share(argc
, argv
);
3236 * Add a share on a remote RPC server
3238 * All parameters are provided by the run_rpc_command function, except for
3239 * argc, argv which are passes through.
3241 * @param domain_sid The domain sid acquired from the remote server
3242 * @param cli A cli_state connected to the server.
3243 * @param mem_ctx Talloc context, destoyed on completion of the function.
3244 * @param argc Standard main() style argc
3245 * @param argv Standard main() style argv. Initial components are already
3248 * @return Normal NTSTATUS return.
3250 static NTSTATUS
rpc_share_add_internals(const DOM_SID
*domain_sid
,
3251 const char *domain_name
,
3252 struct cli_state
*cli
,
3253 struct rpc_pipe_client
*pipe_hnd
,
3254 TALLOC_CTX
*mem_ctx
,int argc
,
3261 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3262 uint32 num_users
=0, perms
=0;
3263 char *password
=NULL
; /* don't allow a share password */
3265 union srvsvc_NetShareInfo info
;
3266 struct srvsvc_NetShareInfo2 info2
;
3267 uint32_t parm_error
= 0;
3269 if ((sharename
= talloc_strdup(mem_ctx
, argv
[0])) == NULL
) {
3270 return NT_STATUS_NO_MEMORY
;
3273 path
= strchr(sharename
, '=');
3275 return NT_STATUS_UNSUCCESSFUL
;
3278 info2
.name
= sharename
;
3280 info2
.comment
= opt_comment
;
3281 info2
.permissions
= perms
;
3282 info2
.max_users
= opt_maxusers
;
3283 info2
.current_users
= num_users
;
3285 info2
.password
= password
;
3287 info
.info2
= &info2
;
3289 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
3290 pipe_hnd
->cli
->desthost
,
3298 static int rpc_share_add(int argc
, const char **argv
)
3300 if ((argc
< 1) || !strchr(argv
[0], '=')) {
3301 DEBUG(1,("Sharename or path not specified on add\n"));
3302 return rpc_share_usage(argc
, argv
);
3304 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3305 rpc_share_add_internals
,
3310 * Delete a share on a remote RPC server
3312 * All parameters are provided by the run_rpc_command function, except for
3313 * argc, argv which are passes through.
3315 * @param domain_sid The domain sid acquired from the remote server
3316 * @param cli A cli_state connected to the server.
3317 * @param mem_ctx Talloc context, destoyed on completion of the function.
3318 * @param argc Standard main() style argc
3319 * @param argv Standard main() style argv. Initial components are already
3322 * @return Normal NTSTATUS return.
3324 static NTSTATUS
rpc_share_del_internals(const DOM_SID
*domain_sid
,
3325 const char *domain_name
,
3326 struct cli_state
*cli
,
3327 struct rpc_pipe_client
*pipe_hnd
,
3328 TALLOC_CTX
*mem_ctx
,
3334 return rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
3335 pipe_hnd
->cli
->desthost
,
3342 * Delete a share on a remote RPC server
3344 * @param domain_sid The domain sid acquired from the remote server
3345 * @param argc Standard main() style argc
3346 * @param argv Standard main() style argv. Initial components are already
3349 * @return A shell status integer (0 for success)
3351 static int rpc_share_delete(int argc
, const char **argv
)
3354 DEBUG(1,("Sharename not specified on delete\n"));
3355 return rpc_share_usage(argc
, argv
);
3357 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3358 rpc_share_del_internals
,
3363 * Formatted print of share info
3365 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3368 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
3370 if (opt_long_list_entries
) {
3371 d_printf("%-12s %-8.8s %-50s\n",
3373 share_type
[r
->type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)],
3376 d_printf("%s\n", r
->name
);
3380 static WERROR
get_share_info(struct rpc_pipe_client
*pipe_hnd
,
3381 TALLOC_CTX
*mem_ctx
,
3385 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3389 union srvsvc_NetShareInfo info
;
3391 /* no specific share requested, enumerate all */
3394 uint32_t preferred_len
= 0xffffffff;
3395 uint32_t total_entries
= 0;
3396 uint32_t resume_handle
= 0;
3398 info_ctr
->level
= level
;
3400 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
3401 pipe_hnd
->cli
->desthost
,
3410 /* request just one share */
3411 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
3412 pipe_hnd
->cli
->desthost
,
3418 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
3423 ZERO_STRUCTP(info_ctr
);
3425 info_ctr
->level
= level
;
3430 struct srvsvc_NetShareCtr1
*ctr1
;
3432 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
3433 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3436 ctr1
->array
= info
.info1
;
3438 info_ctr
->ctr
.ctr1
= ctr1
;
3442 struct srvsvc_NetShareCtr2
*ctr2
;
3444 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
3445 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3448 ctr2
->array
= info
.info2
;
3450 info_ctr
->ctr
.ctr2
= ctr2
;
3454 struct srvsvc_NetShareCtr502
*ctr502
;
3456 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3457 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3460 ctr502
->array
= info
.info502
;
3462 info_ctr
->ctr
.ctr502
= ctr502
;
3470 * List shares on a remote RPC server
3472 * All parameters are provided by the run_rpc_command function, except for
3473 * argc, argv which are passes through.
3475 * @param domain_sid The domain sid acquired from the remote server
3476 * @param cli A cli_state connected to the server.
3477 * @param mem_ctx Talloc context, destoyed on completion of the function.
3478 * @param argc Standard main() style argc
3479 * @param argv Standard main() style argv. Initial components are already
3482 * @return Normal NTSTATUS return.
3485 static NTSTATUS
rpc_share_list_internals(const DOM_SID
*domain_sid
,
3486 const char *domain_name
,
3487 struct cli_state
*cli
,
3488 struct rpc_pipe_client
*pipe_hnd
,
3489 TALLOC_CTX
*mem_ctx
,
3493 struct srvsvc_NetShareInfoCtr info_ctr
;
3494 struct srvsvc_NetShareCtr1 ctr1
;
3496 uint32 i
, level
= 1;
3498 ZERO_STRUCT(info_ctr
);
3502 info_ctr
.ctr
.ctr1
= &ctr1
;
3504 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &info_ctr
);
3505 if (!W_ERROR_IS_OK(result
))
3508 /* Display results */
3510 if (opt_long_list_entries
) {
3512 "\nEnumerating shared resources (exports) on remote server:\n\n"\
3513 "\nShare name Type Description\n"\
3514 "---------- ---- -----------\n");
3516 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++)
3517 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
3519 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3523 * 'net rpc share list' entrypoint.
3524 * @param argc Standard main() style argc
3525 * @param argv Standard main() style argv. Initial components are already
3528 static int rpc_share_list(int argc
, const char **argv
)
3530 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_list_internals
, argc
, argv
);
3533 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3535 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3536 d_printf("skipping [%s]: not a file share.\n", netname
);
3546 static bool check_share_sanity(struct cli_state
*cli
, const char *netname
, uint32 type
)
3548 /* only support disk shares */
3549 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3550 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3554 /* skip builtin shares */
3555 /* FIXME: should print$ be added too ? */
3556 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3557 strequal(netname
,"global"))
3560 if (opt_exclude
&& in_list(netname
, opt_exclude
, False
)) {
3561 printf("excluding [%s]\n", netname
);
3565 return check_share_availability(cli
, netname
);
3569 * Migrate shares from a remote RPC server to the local RPC server
3571 * All parameters are provided by the run_rpc_command function, except for
3572 * argc, argv which are passed through.
3574 * @param domain_sid The domain sid acquired from the remote server
3575 * @param cli A cli_state connected to the server.
3576 * @param mem_ctx Talloc context, destroyed on completion of the function.
3577 * @param argc Standard main() style argc
3578 * @param argv Standard main() style argv. Initial components are already
3581 * @return Normal NTSTATUS return.
3584 static NTSTATUS
rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
,
3585 const char *domain_name
,
3586 struct cli_state
*cli
,
3587 struct rpc_pipe_client
*pipe_hnd
,
3588 TALLOC_CTX
*mem_ctx
,
3593 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3594 struct srvsvc_NetShareInfoCtr ctr_src
;
3596 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3597 struct cli_state
*cli_dst
= NULL
;
3598 uint32 level
= 502; /* includes secdesc */
3599 uint32_t parm_error
= 0;
3601 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3602 if (!W_ERROR_IS_OK(result
))
3605 /* connect destination PI_SRVSVC */
3606 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3607 if (!NT_STATUS_IS_OK(nt_status
))
3611 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3613 union srvsvc_NetShareInfo info
;
3614 struct srvsvc_NetShareInfo502 info502
=
3615 ctr_src
.ctr
.ctr502
->array
[i
];
3617 /* reset error-code */
3618 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3620 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3623 /* finally add the share on the dst server */
3625 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3626 info502
.name
, info502
.path
, info502
.comment
);
3628 info
.info502
= &info502
;
3630 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3631 srvsvc_pipe
->cli
->desthost
,
3637 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3638 printf(" [%s] does already exist\n",
3643 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3644 printf("cannot add share: %s\n", dos_errstr(result
));
3650 nt_status
= NT_STATUS_OK
;
3654 cli_shutdown(cli_dst
);
3662 * Migrate shares from a rpc-server to another
3664 * @param argc Standard main() style argc
3665 * @param argv Standard main() style argv. Initial components are already
3668 * @return A shell status integer (0 for success)
3670 static int rpc_share_migrate_shares(int argc
, const char **argv
)
3674 printf("no server to migrate\n");
3678 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3679 rpc_share_migrate_shares_internals
,
3686 * @param f file_info
3687 * @param mask current search mask
3688 * @param state arg-pointer
3691 static void copy_fn(const char *mnt
, file_info
*f
, const char *mask
, void *state
)
3693 static NTSTATUS nt_status
;
3694 static struct copy_clistate
*local_state
;
3695 static fstring filename
, new_mask
;
3699 local_state
= (struct copy_clistate
*)state
;
3700 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3702 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3705 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3708 if (f
->mode
& aDIR
) {
3710 DEBUG(3,("got dir: %s\n", f
->name
));
3712 fstrcpy(dir
, local_state
->cwd
);
3714 fstrcat(dir
, f
->name
);
3716 switch (net_mode_share
)
3718 case NET_MODE_SHARE_MIGRATE
:
3719 /* create that directory */
3720 nt_status
= net_copy_file(local_state
->mem_ctx
,
3721 local_state
->cli_share_src
,
3722 local_state
->cli_share_dst
,
3724 opt_acls
? True
: False
,
3725 opt_attrs
? True
: False
,
3726 opt_timestamps
? True
: False
,
3730 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3734 if (!NT_STATUS_IS_OK(nt_status
))
3735 printf("could not handle dir %s: %s\n",
3736 dir
, nt_errstr(nt_status
));
3738 /* search below that directory */
3739 fstrcpy(new_mask
, dir
);
3740 fstrcat(new_mask
, "\\*");
3742 old_dir
= local_state
->cwd
;
3743 local_state
->cwd
= dir
;
3744 if (!sync_files(local_state
, new_mask
))
3745 printf("could not handle files\n");
3746 local_state
->cwd
= old_dir
;
3753 fstrcpy(filename
, local_state
->cwd
);
3754 fstrcat(filename
, "\\");
3755 fstrcat(filename
, f
->name
);
3757 DEBUG(3,("got file: %s\n", filename
));
3759 switch (net_mode_share
)
3761 case NET_MODE_SHARE_MIGRATE
:
3762 nt_status
= net_copy_file(local_state
->mem_ctx
,
3763 local_state
->cli_share_src
,
3764 local_state
->cli_share_dst
,
3766 opt_acls
? True
: False
,
3767 opt_attrs
? True
: False
,
3768 opt_timestamps
? True
: False
,
3772 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3776 if (!NT_STATUS_IS_OK(nt_status
))
3777 printf("could not handle file %s: %s\n",
3778 filename
, nt_errstr(nt_status
));
3783 * sync files, can be called recursivly to list files
3784 * and then call copy_fn for each file
3786 * @param cp_clistate pointer to the copy_clistate we work with
3787 * @param mask the current search mask
3789 * @return Boolean result
3791 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3793 struct cli_state
*targetcli
;
3794 char *targetpath
= NULL
;
3796 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3798 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate
->cli_share_src
,
3799 mask
, &targetcli
, &targetpath
) ) {
3800 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3801 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3805 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3806 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3807 mask
, cli_errstr(targetcli
));
3816 * Set the top level directory permissions before we do any further copies.
3817 * Should set up ACL inheritance.
3820 bool copy_top_level_perms(struct copy_clistate
*cp_clistate
,
3821 const char *sharename
)
3823 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3825 switch (net_mode_share
) {
3826 case NET_MODE_SHARE_MIGRATE
:
3827 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3828 nt_status
= net_copy_fileattr(cp_clistate
->mem_ctx
,
3829 cp_clistate
->cli_share_src
,
3830 cp_clistate
->cli_share_dst
,
3832 opt_acls
? True
: False
,
3833 opt_attrs
? True
: False
,
3834 opt_timestamps
? True
: False
,
3838 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3842 if (!NT_STATUS_IS_OK(nt_status
)) {
3843 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3844 sharename
, nt_errstr(nt_status
));
3852 * Sync all files inside a remote share to another share (over smb)
3854 * All parameters are provided by the run_rpc_command function, except for
3855 * argc, argv which are passes through.
3857 * @param domain_sid The domain sid acquired from the remote server
3858 * @param cli A cli_state connected to the server.
3859 * @param mem_ctx Talloc context, destoyed on completion of the function.
3860 * @param argc Standard main() style argc
3861 * @param argv Standard main() style argv. Initial components are already
3864 * @return Normal NTSTATUS return.
3867 static NTSTATUS
rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
,
3868 const char *domain_name
,
3869 struct cli_state
*cli
,
3870 struct rpc_pipe_client
*pipe_hnd
,
3871 TALLOC_CTX
*mem_ctx
,
3876 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3877 struct srvsvc_NetShareInfoCtr ctr_src
;
3880 struct copy_clistate cp_clistate
;
3881 bool got_src_share
= False
;
3882 bool got_dst_share
= False
;
3883 const char *mask
= "\\*";
3886 dst
= SMB_STRDUP(opt_destination
?opt_destination
:"127.0.0.1");
3888 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3890 if (!W_ERROR_IS_OK(result
))
3893 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3895 struct srvsvc_NetShareInfo502 info502
=
3896 ctr_src
.ctr
.ctr502
->array
[i
];
3898 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3901 /* one might not want to mirror whole discs :) */
3902 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3903 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3907 switch (net_mode_share
)
3909 case NET_MODE_SHARE_MIGRATE
:
3913 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3916 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3918 opt_acls
? "including" : "without",
3919 opt_attrs
? "including" : "without",
3920 opt_timestamps
? "(preserving timestamps)" : "");
3922 cp_clistate
.mem_ctx
= mem_ctx
;
3923 cp_clistate
.cli_share_src
= NULL
;
3924 cp_clistate
.cli_share_dst
= NULL
;
3925 cp_clistate
.cwd
= NULL
;
3926 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3928 /* open share source */
3929 nt_status
= connect_to_service(&cp_clistate
.cli_share_src
,
3930 &cli
->dest_ss
, cli
->desthost
,
3931 info502
.name
, "A:");
3932 if (!NT_STATUS_IS_OK(nt_status
))
3935 got_src_share
= True
;
3937 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3938 /* open share destination */
3939 nt_status
= connect_to_service(&cp_clistate
.cli_share_dst
,
3940 NULL
, dst
, info502
.name
, "A:");
3941 if (!NT_STATUS_IS_OK(nt_status
))
3944 got_dst_share
= True
;
3947 if (!copy_top_level_perms(&cp_clistate
, info502
.name
)) {
3948 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3949 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3953 if (!sync_files(&cp_clistate
, mask
)) {
3954 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3955 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3960 nt_status
= NT_STATUS_OK
;
3965 cli_shutdown(cp_clistate
.cli_share_src
);
3968 cli_shutdown(cp_clistate
.cli_share_dst
);
3974 static int rpc_share_migrate_files(int argc
, const char **argv
)
3978 printf("no server to migrate\n");
3982 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3983 rpc_share_migrate_files_internals
,
3988 * Migrate share-ACLs from a remote RPC server to the local RPC srever
3990 * All parameters are provided by the run_rpc_command function, except for
3991 * argc, argv which are passes through.
3993 * @param domain_sid The domain sid acquired from the remote server
3994 * @param cli A cli_state connected to the server.
3995 * @param mem_ctx Talloc context, destoyed on completion of the function.
3996 * @param argc Standard main() style argc
3997 * @param argv Standard main() style argv. Initial components are already
4000 * @return Normal NTSTATUS return.
4003 static NTSTATUS
rpc_share_migrate_security_internals(const DOM_SID
*domain_sid
,
4004 const char *domain_name
,
4005 struct cli_state
*cli
,
4006 struct rpc_pipe_client
*pipe_hnd
,
4007 TALLOC_CTX
*mem_ctx
,
4012 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
4013 struct srvsvc_NetShareInfoCtr ctr_src
;
4014 union srvsvc_NetShareInfo info
;
4016 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
4017 struct cli_state
*cli_dst
= NULL
;
4018 uint32 level
= 502; /* includes secdesc */
4019 uint32_t parm_error
= 0;
4021 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
4023 if (!W_ERROR_IS_OK(result
))
4026 /* connect destination PI_SRVSVC */
4027 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
4028 if (!NT_STATUS_IS_OK(nt_status
))
4032 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
4034 struct srvsvc_NetShareInfo502 info502
=
4035 ctr_src
.ctr
.ctr502
->array
[i
];
4037 /* reset error-code */
4038 nt_status
= NT_STATUS_UNSUCCESSFUL
;
4040 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
4043 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
4044 info502
.name
, info502
.path
, info502
.comment
);
4047 display_sec_desc(info502
.sd_buf
.sd
);
4049 /* FIXME: shouldn't we be able to just set the security descriptor ? */
4050 info
.info502
= &info502
;
4052 /* finally modify the share on the dst server */
4053 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
4054 srvsvc_pipe
->cli
->desthost
,
4060 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
4061 printf("cannot set share-acl: %s\n", dos_errstr(result
));
4067 nt_status
= NT_STATUS_OK
;
4071 cli_shutdown(cli_dst
);
4079 * Migrate share-acls from a rpc-server to another
4081 * @param argc Standard main() style argc
4082 * @param argv Standard main() style argv. Initial components are already
4085 * @return A shell status integer (0 for success)
4087 static int rpc_share_migrate_security(int argc
, const char **argv
)
4091 printf("no server to migrate\n");
4095 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4096 rpc_share_migrate_security_internals
,
4101 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
4102 * from one server to another
4104 * @param argc Standard main() style argc
4105 * @param argv Standard main() style argv. Initial components are already
4108 * @return A shell status integer (0 for success)
4111 static int rpc_share_migrate_all(int argc
, const char **argv
)
4116 printf("no server to migrate\n");
4120 /* order is important. we don't want to be locked out by the share-acl
4121 * before copying files - gd */
4123 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
4127 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
4131 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_security_internals
, argc
, argv
);
4136 * 'net rpc share migrate' entrypoint.
4137 * @param argc Standard main() style argc
4138 * @param argv Standard main() style argv. Initial components are already
4141 static int rpc_share_migrate(int argc
, const char **argv
)
4144 struct functable func
[] = {
4145 {"all", rpc_share_migrate_all
},
4146 {"files", rpc_share_migrate_files
},
4147 {"help", rpc_share_usage
},
4148 {"security", rpc_share_migrate_security
},
4149 {"shares", rpc_share_migrate_shares
},
4153 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
4155 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4164 static int num_server_aliases
;
4165 static struct full_alias
*server_aliases
;
4168 * Add an alias to the static list.
4170 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
4172 if (server_aliases
== NULL
)
4173 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
4175 server_aliases
[num_server_aliases
] = *alias
;
4176 num_server_aliases
+= 1;
4180 * For a specific domain on the server, fetch all the aliases
4181 * and their members. Add all of them to the server_aliases.
4184 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
4185 TALLOC_CTX
*mem_ctx
,
4186 POLICY_HND
*connect_pol
,
4187 const DOM_SID
*domain_sid
)
4189 uint32 start_idx
, max_entries
, num_entries
, i
;
4190 struct samr_SamArray
*groups
= NULL
;
4192 POLICY_HND domain_pol
;
4194 /* Get domain policy handle */
4196 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
4198 MAXIMUM_ALLOWED_ACCESS
,
4199 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
4201 if (!NT_STATUS_IS_OK(result
))
4208 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
4214 for (i
= 0; i
< num_entries
; i
++) {
4216 POLICY_HND alias_pol
;
4217 struct full_alias alias
;
4218 struct lsa_SidArray sid_array
;
4221 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
4223 MAXIMUM_ALLOWED_ACCESS
,
4224 groups
->entries
[i
].idx
,
4226 if (!NT_STATUS_IS_OK(result
))
4229 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
4232 if (!NT_STATUS_IS_OK(result
))
4235 alias
.num_members
= sid_array
.num_sids
;
4237 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
4238 if (!NT_STATUS_IS_OK(result
))
4241 alias
.members
= NULL
;
4243 if (alias
.num_members
> 0) {
4244 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
4246 for (j
= 0; j
< alias
.num_members
; j
++)
4247 sid_copy(&alias
.members
[j
],
4248 sid_array
.sids
[j
].sid
);
4251 sid_copy(&alias
.sid
, domain_sid
);
4252 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
4254 push_alias(mem_ctx
, &alias
);
4256 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4258 result
= NT_STATUS_OK
;
4261 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
4267 * Dump server_aliases as names for debugging purposes.
4270 static NTSTATUS
rpc_aliaslist_dump(const DOM_SID
*domain_sid
,
4271 const char *domain_name
,
4272 struct cli_state
*cli
,
4273 struct rpc_pipe_client
*pipe_hnd
,
4274 TALLOC_CTX
*mem_ctx
,
4282 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, True
,
4283 SEC_RIGHTS_MAXIMUM_ALLOWED
,
4285 if (!NT_STATUS_IS_OK(result
))
4288 for (i
=0; i
<num_server_aliases
; i
++) {
4291 enum lsa_SidType
*types
;
4294 struct full_alias
*alias
= &server_aliases
[i
];
4296 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4298 &domains
, &names
, &types
);
4299 if (!NT_STATUS_IS_OK(result
))
4302 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4304 if (alias
->num_members
== 0) {
4309 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4312 &domains
, &names
, &types
);
4314 if (!NT_STATUS_IS_OK(result
) &&
4315 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4318 for (j
=0; j
<alias
->num_members
; j
++)
4319 DEBUG(1, ("%s\\%s (%d); ",
4320 domains
[j
] ? domains
[j
] : "*unknown*",
4321 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4325 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4327 return NT_STATUS_OK
;
4331 * Fetch a list of all server aliases and their members into
4335 static NTSTATUS
rpc_aliaslist_internals(const DOM_SID
*domain_sid
,
4336 const char *domain_name
,
4337 struct cli_state
*cli
,
4338 struct rpc_pipe_client
*pipe_hnd
,
4339 TALLOC_CTX
*mem_ctx
,
4344 POLICY_HND connect_pol
;
4346 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4347 pipe_hnd
->cli
->desthost
,
4348 MAXIMUM_ALLOWED_ACCESS
,
4351 if (!NT_STATUS_IS_OK(result
))
4354 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4355 &global_sid_Builtin
);
4357 if (!NT_STATUS_IS_OK(result
))
4360 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4363 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4368 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4370 token
->num_sids
= 4;
4372 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4373 d_fprintf(stderr
, "malloc failed\n");
4374 token
->num_sids
= 0;
4378 token
->user_sids
[0] = *user_sid
;
4379 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4380 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4381 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4384 static void free_user_token(NT_USER_TOKEN
*token
)
4386 SAFE_FREE(token
->user_sids
);
4389 static bool is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4393 for (i
=0; i
<token
->num_sids
; i
++) {
4394 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
4400 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4402 if (is_sid_in_token(token
, sid
))
4405 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4406 if (!token
->user_sids
) {
4410 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4412 token
->num_sids
+= 1;
4417 NT_USER_TOKEN token
;
4420 static void dump_user_token(struct user_token
*token
)
4424 d_printf("%s\n", token
->name
);
4426 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4427 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4431 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4435 for (i
=0; i
<alias
->num_members
; i
++) {
4436 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4443 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4447 for (i
=0; i
<num_server_aliases
; i
++) {
4448 if (is_alias_member(&sid
, &server_aliases
[i
]))
4449 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4454 * We got a user token with all the SIDs we can know about without asking the
4455 * server directly. These are the user and domain group sids. All of these can
4456 * be members of aliases. So scan the list of aliases for each of the SIDs and
4457 * add them to the token.
4460 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4462 int num_global_sids
= token
->num_sids
;
4465 for (i
=0; i
<num_global_sids
; i
++) {
4466 collect_sid_memberships(token
, token
->user_sids
[i
]);
4470 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4472 struct winbindd_request request
;
4473 struct winbindd_response response
;
4481 fstr_sprintf(full_name
, "%s%c%s",
4482 domain
, *lp_winbind_separator(), user
);
4484 /* First let's find out the user sid */
4486 ZERO_STRUCT(request
);
4487 ZERO_STRUCT(response
);
4489 fstrcpy(request
.data
.name
.dom_name
, domain
);
4490 fstrcpy(request
.data
.name
.name
, user
);
4492 result
= winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
);
4494 if (result
!= NSS_STATUS_SUCCESS
) {
4495 DEBUG(1, ("winbind could not find %s\n", full_name
));
4499 if (response
.data
.sid
.type
!= SID_NAME_USER
) {
4500 DEBUG(1, ("%s is not a user\n", full_name
));
4504 if (!string_to_sid(&user_sid
, response
.data
.sid
.sid
)) {
4505 DEBUG(1, ("Could not convert string '%s' to SID\n", response
.data
.sid
.sid
));
4509 init_user_token(token
, &user_sid
);
4511 /* And now the groups winbind knows about */
4513 ZERO_STRUCT(response
);
4515 fstrcpy(request
.data
.username
, full_name
);
4517 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
4519 if (result
!= NSS_STATUS_SUCCESS
) {
4520 DEBUG(1, ("winbind could not get groups of %s\n", full_name
));
4524 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
4525 gid_t gid
= ((gid_t
*)response
.extra_data
.data
)[i
];
4528 struct winbindd_request sidrequest
;
4529 struct winbindd_response sidresponse
;
4531 ZERO_STRUCT(sidrequest
);
4532 ZERO_STRUCT(sidresponse
);
4534 sidrequest
.data
.gid
= gid
;
4536 result
= winbindd_request_response(WINBINDD_GID_TO_SID
,
4537 &sidrequest
, &sidresponse
);
4539 if (result
!= NSS_STATUS_SUCCESS
) {
4540 DEBUG(1, ("winbind could not find SID of gid %d\n",
4545 DEBUG(3, (" %s\n", sidresponse
.data
.sid
.sid
));
4547 string_to_sid(&sid
, sidresponse
.data
.sid
.sid
);
4548 add_sid_to_token(token
, &sid
);
4551 SAFE_FREE(response
.extra_data
.data
);
4557 * Get a list of all user tokens we want to look at
4560 static bool get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
4562 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4563 uint32_t i
, num_users
;
4565 struct user_token
*result
;
4566 TALLOC_CTX
*frame
= NULL
;
4568 if (lp_winbind_use_default_domain() &&
4569 (opt_target_workgroup
== NULL
)) {
4570 d_fprintf(stderr
, "winbind use default domain = yes set, "
4571 "please specify a workgroup\n");
4575 /* Send request to winbind daemon */
4577 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4578 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4579 DEBUG(1, ("winbind could not list users: %s\n",
4580 wbcErrorString(wbc_status
)));
4584 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4586 if (result
== NULL
) {
4587 DEBUG(1, ("Could not malloc sid array\n"));
4588 wbcFreeMemory(users
);
4592 frame
= talloc_stackframe();
4593 for (i
=0; i
< num_users
; i
++) {
4594 fstring domain
, user
;
4597 fstrcpy(result
[i
].name
, users
[i
]);
4599 p
= strchr(users
[i
], *lp_winbind_separator());
4601 DEBUG(3, ("%s\n", users
[i
]));
4604 fstrcpy(domain
, opt_target_workgroup
);
4605 fstrcpy(user
, users
[i
]);
4608 fstrcpy(domain
, users
[i
]);
4613 get_user_sids(domain
, user
, &(result
[i
].token
));
4617 wbcFreeMemory(users
);
4619 *num_tokens
= num_users
;
4620 *user_tokens
= result
;
4625 static bool get_user_tokens_from_file(FILE *f
,
4627 struct user_token
**tokens
)
4629 struct user_token
*token
= NULL
;
4634 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4638 if (line
[strlen(line
)-1] == '\n')
4639 line
[strlen(line
)-1] = '\0';
4641 if (line
[0] == ' ') {
4645 string_to_sid(&sid
, &line
[1]);
4647 if (token
== NULL
) {
4648 DEBUG(0, ("File does not begin with username"));
4652 add_sid_to_token(&token
->token
, &sid
);
4656 /* And a new user... */
4659 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4660 if (*tokens
== NULL
) {
4661 DEBUG(0, ("Could not realloc tokens\n"));
4665 token
= &((*tokens
)[*num_tokens
-1]);
4667 fstrcpy(token
->name
, line
);
4668 token
->token
.num_sids
= 0;
4669 token
->token
.user_sids
= NULL
;
4678 * Show the list of all users that have access to a share
4681 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4682 TALLOC_CTX
*mem_ctx
,
4683 const char *netname
,
4685 struct user_token
*tokens
)
4688 SEC_DESC
*share_sd
= NULL
;
4689 SEC_DESC
*root_sd
= NULL
;
4690 struct cli_state
*cli
= pipe_hnd
->cli
;
4692 union srvsvc_NetShareInfo info
;
4697 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4698 pipe_hnd
->cli
->desthost
,
4704 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4705 DEBUG(1, ("Coult not query secdesc for share %s\n",
4710 share_sd
= info
.info502
->sd_buf
.sd
;
4711 if (share_sd
== NULL
) {
4712 DEBUG(1, ("Got no secdesc for share %s\n",
4718 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4722 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4725 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4728 for (i
=0; i
<num_tokens
; i
++) {
4731 if (share_sd
!= NULL
) {
4732 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4733 1, &acc_granted
, &status
)) {
4734 DEBUG(1, ("Could not check share_sd for "
4740 if (!NT_STATUS_IS_OK(status
))
4744 if (root_sd
== NULL
) {
4745 d_printf(" %s\n", tokens
[i
].name
);
4749 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4750 1, &acc_granted
, &status
)) {
4751 DEBUG(1, ("Could not check root_sd for user %s\n",
4756 if (!NT_STATUS_IS_OK(status
))
4759 d_printf(" %s\n", tokens
[i
].name
);
4763 cli_close(cli
, fnum
);
4775 static void collect_share(const char *name
, uint32 m
,
4776 const char *comment
, void *state
)
4778 struct share_list
*share_list
= (struct share_list
*)state
;
4780 if (m
!= STYPE_DISKTREE
)
4783 share_list
->num_shares
+= 1;
4784 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4785 if (!share_list
->shares
) {
4786 share_list
->num_shares
= 0;
4789 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4792 static void rpc_share_userlist_usage(void)
4798 * List shares on a remote RPC server, including the security descriptors
4800 * All parameters are provided by the run_rpc_command function, except for
4801 * argc, argv which are passes through.
4803 * @param domain_sid The domain sid acquired from the remote server
4804 * @param cli A cli_state connected to the server.
4805 * @param mem_ctx Talloc context, destoyed on completion of the function.
4806 * @param argc Standard main() style argc
4807 * @param argv Standard main() style argv. Initial components are already
4810 * @return Normal NTSTATUS return.
4813 static NTSTATUS
rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
4814 const char *domain_name
,
4815 struct cli_state
*cli
,
4816 struct rpc_pipe_client
*pipe_hnd
,
4817 TALLOC_CTX
*mem_ctx
,
4827 struct user_token
*tokens
= NULL
;
4830 struct share_list share_list
;
4833 rpc_share_userlist_usage();
4834 return NT_STATUS_UNSUCCESSFUL
;
4840 f
= fopen(argv
[0], "r");
4844 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4845 return NT_STATUS_UNSUCCESSFUL
;
4848 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4854 DEBUG(0, ("Could not read users from file\n"));
4855 return NT_STATUS_UNSUCCESSFUL
;
4858 for (i
=0; i
<num_tokens
; i
++)
4859 collect_alias_memberships(&tokens
[i
].token
);
4861 init_enum_hnd(&hnd
, 0);
4863 share_list
.num_shares
= 0;
4864 share_list
.shares
= NULL
;
4866 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4869 DEBUG(0, ("Error returning browse list: %s\n",
4874 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4875 char *netname
= share_list
.shares
[i
];
4877 if (netname
[strlen(netname
)-1] == '$')
4880 d_printf("%s\n", netname
);
4882 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4883 num_tokens
, tokens
);
4886 for (i
=0; i
<num_tokens
; i
++) {
4887 free_user_token(&tokens
[i
].token
);
4890 SAFE_FREE(share_list
.shares
);
4892 return NT_STATUS_OK
;
4895 static int rpc_share_allowedusers(int argc
, const char **argv
)
4899 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
4900 rpc_aliaslist_internals
,
4905 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
4911 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4912 rpc_share_allowedusers_internals
,
4916 int net_usersidlist(int argc
, const char **argv
)
4919 struct user_token
*tokens
= NULL
;
4923 net_usersidlist_usage(argc
, argv
);
4927 if (!get_user_tokens(&num_tokens
, &tokens
)) {
4928 DEBUG(0, ("Could not get the user/sid list\n"));
4932 for (i
=0; i
<num_tokens
; i
++) {
4933 dump_user_token(&tokens
[i
]);
4934 free_user_token(&tokens
[i
].token
);
4941 int net_usersidlist_usage(int argc
, const char **argv
)
4943 d_printf("net usersidlist\n"
4944 "\tprints out a list of all users the running winbind knows\n"
4945 "\tabout, together with all their SIDs. This is used as\n"
4946 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4948 net_common_flags_usage(argc
, argv
);
4953 * 'net rpc share' entrypoint.
4954 * @param argc Standard main() style argc
4955 * @param argv Standard main() style argv. Initial components are already
4959 int net_rpc_share(int argc
, const char **argv
)
4961 struct functable func
[] = {
4962 {"add", rpc_share_add
},
4963 {"delete", rpc_share_delete
},
4964 {"allowedusers", rpc_share_allowedusers
},
4965 {"migrate", rpc_share_migrate
},
4966 {"list", rpc_share_list
},
4971 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4972 rpc_share_list_internals
,
4975 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4978 static NTSTATUS
rpc_sh_share_list(TALLOC_CTX
*mem_ctx
,
4979 struct rpc_sh_ctx
*ctx
,
4980 struct rpc_pipe_client
*pipe_hnd
,
4981 int argc
, const char **argv
)
4983 return rpc_share_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
4984 ctx
->cli
, pipe_hnd
, mem_ctx
,
4988 static NTSTATUS
rpc_sh_share_add(TALLOC_CTX
*mem_ctx
,
4989 struct rpc_sh_ctx
*ctx
,
4990 struct rpc_pipe_client
*pipe_hnd
,
4991 int argc
, const char **argv
)
4995 uint32_t parm_err
= 0;
4996 union srvsvc_NetShareInfo info
;
4997 struct srvsvc_NetShareInfo2 info2
;
4999 if ((argc
< 2) || (argc
> 3)) {
5000 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
5002 return NT_STATUS_INVALID_PARAMETER
;
5005 info2
.name
= argv
[0];
5006 info2
.type
= STYPE_DISKTREE
;
5007 info2
.comment
= (argc
== 3) ? argv
[2] : "";
5008 info2
.permissions
= 0;
5009 info2
.max_users
= 0;
5010 info2
.current_users
= 0;
5011 info2
.path
= argv
[1];
5012 info2
.password
= NULL
;
5014 info
.info2
= &info2
;
5016 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
5017 pipe_hnd
->cli
->desthost
,
5026 static NTSTATUS
rpc_sh_share_delete(TALLOC_CTX
*mem_ctx
,
5027 struct rpc_sh_ctx
*ctx
,
5028 struct rpc_pipe_client
*pipe_hnd
,
5029 int argc
, const char **argv
)
5035 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
5036 return NT_STATUS_INVALID_PARAMETER
;
5039 status
= rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
5040 pipe_hnd
->cli
->desthost
,
5048 static NTSTATUS
rpc_sh_share_info(TALLOC_CTX
*mem_ctx
,
5049 struct rpc_sh_ctx
*ctx
,
5050 struct rpc_pipe_client
*pipe_hnd
,
5051 int argc
, const char **argv
)
5053 union srvsvc_NetShareInfo info
;
5058 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
5059 return NT_STATUS_INVALID_PARAMETER
;
5062 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
5063 pipe_hnd
->cli
->desthost
,
5068 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
5072 d_printf("Name: %s\n", info
.info2
->name
);
5073 d_printf("Comment: %s\n", info
.info2
->comment
);
5074 d_printf("Path: %s\n", info
.info2
->path
);
5075 d_printf("Password: %s\n", info
.info2
->password
);
5078 return werror_to_ntstatus(result
);
5081 struct rpc_sh_cmd
*net_rpc_share_cmds(TALLOC_CTX
*mem_ctx
,
5082 struct rpc_sh_ctx
*ctx
)
5084 static struct rpc_sh_cmd cmds
[] = {
5086 { "list", NULL
, PI_SRVSVC
, rpc_sh_share_list
,
5087 "List available shares" },
5089 { "add", NULL
, PI_SRVSVC
, rpc_sh_share_add
,
5092 { "delete", NULL
, PI_SRVSVC
, rpc_sh_share_delete
,
5095 { "info", NULL
, PI_SRVSVC
, rpc_sh_share_info
,
5096 "Get information about a share" },
5098 { NULL
, NULL
, 0, NULL
, NULL
}
5104 /****************************************************************************/
5106 static int rpc_file_usage(int argc
, const char **argv
)
5108 return net_help_file(argc
, argv
);
5112 * Close a file on a remote RPC server
5114 * All parameters are provided by the run_rpc_command function, except for
5115 * argc, argv which are passes through.
5117 * @param domain_sid The domain sid acquired from the remote server
5118 * @param cli A cli_state connected to the server.
5119 * @param mem_ctx Talloc context, destoyed on completion of the function.
5120 * @param argc Standard main() style argc
5121 * @param argv Standard main() style argv. Initial components are already
5124 * @return Normal NTSTATUS return.
5126 static NTSTATUS
rpc_file_close_internals(const DOM_SID
*domain_sid
,
5127 const char *domain_name
,
5128 struct cli_state
*cli
,
5129 struct rpc_pipe_client
*pipe_hnd
,
5130 TALLOC_CTX
*mem_ctx
,
5134 return rpccli_srvsvc_NetFileClose(pipe_hnd
, mem_ctx
,
5135 pipe_hnd
->cli
->desthost
,
5136 atoi(argv
[0]), NULL
);
5140 * Close a file on a remote RPC server
5142 * @param argc Standard main() style argc
5143 * @param argv Standard main() style argv. Initial components are already
5146 * @return A shell status integer (0 for success)
5148 static int rpc_file_close(int argc
, const char **argv
)
5151 DEBUG(1, ("No fileid given on close\n"));
5152 return(rpc_file_usage(argc
, argv
));
5155 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5156 rpc_file_close_internals
,
5161 * Formatted print of open file info
5163 * @param r struct srvsvc_NetFileInfo3 contents
5166 static void display_file_info_3(struct srvsvc_NetFileInfo3
*r
)
5168 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
5169 r
->fid
, r
->user
, r
->permissions
, r
->num_locks
, r
->path
);
5173 * List open files on a remote RPC server
5175 * All parameters are provided by the run_rpc_command function, except for
5176 * argc, argv which are passes through.
5178 * @param domain_sid The domain sid acquired from the remote server
5179 * @param cli A cli_state connected to the server.
5180 * @param mem_ctx Talloc context, destoyed on completion of the function.
5181 * @param argc Standard main() style argc
5182 * @param argv Standard main() style argv. Initial components are already
5185 * @return Normal NTSTATUS return.
5188 static NTSTATUS
rpc_file_list_internals(const DOM_SID
*domain_sid
,
5189 const char *domain_name
,
5190 struct cli_state
*cli
,
5191 struct rpc_pipe_client
*pipe_hnd
,
5192 TALLOC_CTX
*mem_ctx
,
5196 struct srvsvc_NetFileInfoCtr info_ctr
;
5197 struct srvsvc_NetFileCtr3 ctr3
;
5200 uint32 preferred_len
= 0xffffffff, i
;
5201 const char *username
=NULL
;
5202 uint32_t total_entries
= 0;
5203 uint32_t resume_handle
= 0;
5205 /* if argc > 0, must be user command */
5207 username
= smb_xstrdup(argv
[0]);
5209 ZERO_STRUCT(info_ctr
);
5213 info_ctr
.ctr
.ctr3
= &ctr3
;
5215 status
= rpccli_srvsvc_NetFileEnum(pipe_hnd
, mem_ctx
,
5216 pipe_hnd
->cli
->desthost
,
5225 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
5228 /* Display results */
5231 "\nEnumerating open files on remote server:\n\n"\
5232 "\nFileId Opened by Perms Locks Path"\
5233 "\n------ --------- ----- ----- ---- \n");
5234 for (i
= 0; i
< total_entries
; i
++)
5235 display_file_info_3(&info_ctr
.ctr
.ctr3
->array
[i
]);
5237 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
5241 * List files for a user on a remote RPC server
5243 * @param argc Standard main() style argc
5244 * @param argv Standard main() style argv. Initial components are already
5247 * @return A shell status integer (0 for success)
5250 static int rpc_file_user(int argc
, const char **argv
)
5253 DEBUG(1, ("No username given\n"));
5254 return(rpc_file_usage(argc
, argv
));
5257 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5258 rpc_file_list_internals
,
5263 * 'net rpc file' entrypoint.
5264 * @param argc Standard main() style argc
5265 * @param argv Standard main() style argv. Initial components are already
5269 int net_rpc_file(int argc
, const char **argv
)
5271 struct functable func
[] = {
5272 {"close", rpc_file_close
},
5273 {"user", rpc_file_user
},
5275 {"info", rpc_file_info
},
5281 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5282 rpc_file_list_internals
,
5285 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
5289 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
5291 * All parameters are provided by the run_rpc_command function, except for
5292 * argc, argv which are passed through.
5294 * @param domain_sid The domain sid aquired from the remote server
5295 * @param cli A cli_state connected to the server.
5296 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5297 * @param argc Standard main() style argc
5298 * @param argv Standard main() style argv. Initial components are already
5301 * @return Normal NTSTATUS return.
5304 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5305 const char *domain_name
,
5306 struct cli_state
*cli
,
5307 struct rpc_pipe_client
*pipe_hnd
,
5308 TALLOC_CTX
*mem_ctx
,
5312 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5314 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5316 if (NT_STATUS_IS_OK(result
)) {
5317 d_printf("\nShutdown successfully aborted\n");
5318 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5320 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5326 * ABORT the shutdown of a remote RPC Server, over winreg pipe
5328 * All parameters are provided by the run_rpc_command function, except for
5329 * argc, argv which are passed through.
5331 * @param domain_sid The domain sid aquired from the remote server
5332 * @param cli A cli_state connected to the server.
5333 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5334 * @param argc Standard main() style argc
5335 * @param argv Standard main() style argv. Initial components are already
5338 * @return Normal NTSTATUS return.
5341 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5342 const char *domain_name
,
5343 struct cli_state
*cli
,
5344 struct rpc_pipe_client
*pipe_hnd
,
5345 TALLOC_CTX
*mem_ctx
,
5349 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5351 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5353 if (NT_STATUS_IS_OK(result
)) {
5354 d_printf("\nShutdown successfully aborted\n");
5355 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5357 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5363 * ABORT the Shut down of a remote RPC server
5365 * @param argc Standard main() style argc
5366 * @param argv Standard main() style argv. Initial components are already
5369 * @return A shell status integer (0 for success)
5372 static int rpc_shutdown_abort(int argc
, const char **argv
)
5374 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5375 rpc_shutdown_abort_internals
,
5381 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5383 return run_rpc_command(NULL
, PI_WINREG
, 0,
5384 rpc_reg_shutdown_abort_internals
,
5389 * Shut down a remote RPC Server via initshutdown pipe
5391 * All parameters are provided by the run_rpc_command function, except for
5392 * argc, argv which are passes through.
5394 * @param domain_sid The domain sid aquired from the remote server
5395 * @param cli A cli_state connected to the server.
5396 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5397 * @param argc Standard main() style argc
5398 * @param argc Standard main() style argv. Initial components are already
5401 * @return Normal NTSTATUS return.
5404 NTSTATUS
rpc_init_shutdown_internals(const DOM_SID
*domain_sid
,
5405 const char *domain_name
,
5406 struct cli_state
*cli
,
5407 struct rpc_pipe_client
*pipe_hnd
,
5408 TALLOC_CTX
*mem_ctx
,
5412 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5413 const char *msg
= "This machine will be shutdown shortly";
5414 uint32 timeout
= 20;
5415 struct initshutdown_String msg_string
;
5416 struct initshutdown_String_sub s
;
5422 timeout
= opt_timeout
;
5426 msg_string
.name
= &s
;
5428 /* create an entry */
5429 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5430 &msg_string
, timeout
, opt_force
, opt_reboot
, NULL
);
5432 if (NT_STATUS_IS_OK(result
)) {
5433 d_printf("\nShutdown of remote machine succeeded\n");
5434 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5436 DEBUG(1,("Shutdown of remote machine failed!\n"));
5442 * Shut down a remote RPC Server via winreg pipe
5444 * All parameters are provided by the run_rpc_command function, except for
5445 * argc, argv which are passes through.
5447 * @param domain_sid The domain sid aquired from the remote server
5448 * @param cli A cli_state connected to the server.
5449 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5450 * @param argc Standard main() style argc
5451 * @param argc Standard main() style argv. Initial components are already
5454 * @return Normal NTSTATUS return.
5457 NTSTATUS
rpc_reg_shutdown_internals(const DOM_SID
*domain_sid
,
5458 const char *domain_name
,
5459 struct cli_state
*cli
,
5460 struct rpc_pipe_client
*pipe_hnd
,
5461 TALLOC_CTX
*mem_ctx
,
5465 const char *msg
= "This machine will be shutdown shortly";
5466 uint32 timeout
= 20;
5467 struct initshutdown_String msg_string
;
5468 struct initshutdown_String_sub s
;
5476 msg_string
.name
= &s
;
5479 timeout
= opt_timeout
;
5482 /* create an entry */
5483 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5484 &msg_string
, timeout
, opt_force
, opt_reboot
, &werr
);
5486 if (NT_STATUS_IS_OK(result
)) {
5487 d_printf("\nShutdown of remote machine succeeded\n");
5489 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5490 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5491 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5493 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(werr
));
5500 * Shut down a remote RPC server
5502 * @param argc Standard main() style argc
5503 * @param argc Standard main() style argv. Initial components are already
5506 * @return A shell status integer (0 for success)
5509 static int rpc_shutdown(int argc
, const char **argv
)
5511 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5512 rpc_init_shutdown_internals
,
5516 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5517 rc
= run_rpc_command(NULL
, PI_WINREG
, 0,
5518 rpc_reg_shutdown_internals
, argc
, argv
);
5524 /***************************************************************************
5525 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5527 ***************************************************************************/
5530 * Add interdomain trust account to the RPC server.
5531 * All parameters (except for argc and argv) are passed by run_rpc_command
5534 * @param domain_sid The domain sid acquired from the server
5535 * @param cli A cli_state connected to the server.
5536 * @param mem_ctx Talloc context, destoyed on completion of the function.
5537 * @param argc Standard main() style argc
5538 * @param argc Standard main() style argv. Initial components are already
5541 * @return normal NTSTATUS return code
5544 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
5545 const char *domain_name
,
5546 struct cli_state
*cli
,
5547 struct rpc_pipe_client
*pipe_hnd
,
5548 TALLOC_CTX
*mem_ctx
,
5552 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5553 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5555 struct lsa_String lsa_acct_name
;
5557 uint32 acct_flags
=0;
5559 uint32_t access_granted
= 0;
5560 union samr_UserInfo info
;
5563 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
5564 return NT_STATUS_INVALID_PARAMETER
;
5568 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5571 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5572 return NT_STATUS_NO_MEMORY
;
5575 strupper_m(acct_name
);
5577 init_lsa_String(&lsa_acct_name
, acct_name
);
5579 /* Get samr policy handle */
5580 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5581 pipe_hnd
->cli
->desthost
,
5582 MAXIMUM_ALLOWED_ACCESS
,
5584 if (!NT_STATUS_IS_OK(result
)) {
5588 /* Get domain policy handle */
5589 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5591 MAXIMUM_ALLOWED_ACCESS
,
5592 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5594 if (!NT_STATUS_IS_OK(result
)) {
5598 /* Create trusting domain's account */
5599 acb_info
= ACB_NORMAL
;
5600 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5601 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5602 SAMR_USER_ACCESS_SET_PASSWORD
|
5603 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5604 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5606 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5614 if (!NT_STATUS_IS_OK(result
)) {
5620 struct samr_LogonHours hours
;
5621 const int units_per_week
= 168;
5624 encode_pw_buffer(pwbuf
, argv
[1], STR_UNICODE
);
5626 ZERO_STRUCT(notime
);
5629 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
5631 result
= NT_STATUS_NO_MEMORY
;
5634 hours
.units_per_week
= units_per_week
;
5635 memset(hours
.bits
, 0xFF, units_per_week
);
5637 init_samr_user_info23(&info
.info23
,
5638 notime
, notime
, notime
,
5639 notime
, notime
, notime
,
5640 NULL
, NULL
, NULL
, NULL
, NULL
,
5641 NULL
, NULL
, NULL
, NULL
, NULL
,
5642 0, 0, ACB_DOMTRUST
, SAMR_FIELD_ACCT_FLAGS
,
5644 0, 0, 0, 0, 0, 0, 0,
5647 SamOEMhashBlob(info
.info23
.password
.data
, 516,
5648 &cli
->user_session_key
);
5650 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5655 if (!NT_STATUS_IS_OK(result
)) {
5656 DEBUG(0,("Could not set trust account password: %s\n",
5657 nt_errstr(result
)));
5663 SAFE_FREE(acct_name
);
5668 * Create interdomain trust account for a remote domain.
5670 * @param argc standard argc
5671 * @param argv standard argv without initial components
5673 * @return Integer status (0 means success)
5676 static int rpc_trustdom_add(int argc
, const char **argv
)
5679 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
5682 d_printf("Usage: net rpc trustdom add <domain>\n");
5689 * Remove interdomain trust account from the RPC server.
5690 * All parameters (except for argc and argv) are passed by run_rpc_command
5693 * @param domain_sid The domain sid acquired from the server
5694 * @param cli A cli_state connected to the server.
5695 * @param mem_ctx Talloc context, destoyed on completion of the function.
5696 * @param argc Standard main() style argc
5697 * @param argc Standard main() style argv. Initial components are already
5700 * @return normal NTSTATUS return code
5703 static NTSTATUS
rpc_trustdom_del_internals(const DOM_SID
*domain_sid
,
5704 const char *domain_name
,
5705 struct cli_state
*cli
,
5706 struct rpc_pipe_client
*pipe_hnd
,
5707 TALLOC_CTX
*mem_ctx
,
5711 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5712 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5714 DOM_SID trust_acct_sid
;
5715 struct samr_Ids user_rids
, name_types
;
5716 struct lsa_String lsa_acct_name
;
5719 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5720 return NT_STATUS_INVALID_PARAMETER
;
5724 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5726 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5728 if (acct_name
== NULL
)
5729 return NT_STATUS_NO_MEMORY
;
5731 strupper_m(acct_name
);
5733 /* Get samr policy handle */
5734 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5735 pipe_hnd
->cli
->desthost
,
5736 MAXIMUM_ALLOWED_ACCESS
,
5738 if (!NT_STATUS_IS_OK(result
)) {
5742 /* Get domain policy handle */
5743 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5745 MAXIMUM_ALLOWED_ACCESS
,
5746 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5748 if (!NT_STATUS_IS_OK(result
)) {
5752 init_lsa_String(&lsa_acct_name
, acct_name
);
5754 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5761 if (!NT_STATUS_IS_OK(result
)) {
5765 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5767 MAXIMUM_ALLOWED_ACCESS
,
5771 if (!NT_STATUS_IS_OK(result
)) {
5775 /* append the rid to the domain sid */
5776 sid_copy(&trust_acct_sid
, domain_sid
);
5777 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5781 /* remove the sid */
5783 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5786 if (!NT_STATUS_IS_OK(result
)) {
5792 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5795 if (!NT_STATUS_IS_OK(result
)) {
5799 if (!NT_STATUS_IS_OK(result
)) {
5800 DEBUG(0,("Could not set trust account password: %s\n",
5801 nt_errstr(result
)));
5810 * Delete interdomain trust account for a remote domain.
5812 * @param argc standard argc
5813 * @param argv standard argv without initial components
5815 * @return Integer status (0 means success)
5818 static int rpc_trustdom_del(int argc
, const char **argv
)
5821 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_del_internals
,
5824 d_printf("Usage: net rpc trustdom del <domain>\n");
5829 static NTSTATUS
rpc_trustdom_get_pdc(struct cli_state
*cli
,
5830 TALLOC_CTX
*mem_ctx
,
5831 const char *domain_name
)
5833 char *dc_name
= NULL
;
5834 const char *buffer
= NULL
;
5835 struct rpc_pipe_client
*netr
;
5838 /* Use NetServerEnum2 */
5840 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5842 return NT_STATUS_OK
;
5845 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5846 for domain %s\n", domain_name
));
5848 /* Try netr_GetDcName */
5850 netr
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &status
);
5855 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5860 cli_rpc_pipe_close(netr
);
5862 if (NT_STATUS_IS_OK(status
)) {
5866 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5867 for domain %s\n", domain_name
));
5873 * Establish trust relationship to a trusting domain.
5874 * Interdomain account must already be created on remote PDC.
5876 * @param argc standard argc
5877 * @param argv standard argv without initial components
5879 * @return Integer status (0 means success)
5882 static int rpc_trustdom_establish(int argc
, const char **argv
)
5884 struct cli_state
*cli
= NULL
;
5885 struct sockaddr_storage server_ss
;
5886 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5887 POLICY_HND connect_hnd
;
5888 TALLOC_CTX
*mem_ctx
;
5890 DOM_SID
*domain_sid
;
5895 union lsa_PolicyInformation
*info
= NULL
;
5898 * Connect to \\server\ipc$ as 'our domain' account with password
5902 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
5906 domain_name
= smb_xstrdup(argv
[0]);
5907 strupper_m(domain_name
);
5909 /* account name used at first is our domain's name with '$' */
5910 asprintf(&acct_name
, "%s$", lp_workgroup());
5911 strupper_m(acct_name
);
5914 * opt_workgroup will be used by connection functions further,
5915 * hence it should be set to remote domain name instead of ours
5917 if (opt_workgroup
) {
5918 opt_workgroup
= smb_xstrdup(domain_name
);
5921 opt_user_name
= acct_name
;
5923 /* find the domain controller */
5924 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5925 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5929 /* connect to ipc$ as username/password */
5930 nt_status
= connect_to_ipc(&cli
, &server_ss
, pdc_name
);
5931 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5933 /* Is it trusting domain account for sure ? */
5934 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5935 nt_errstr(nt_status
)));
5939 /* store who we connected to */
5941 saf_store( domain_name
, pdc_name
);
5944 * Connect to \\server\ipc$ again (this time anonymously)
5947 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ss
, (char*)pdc_name
);
5949 if (NT_STATUS_IS_ERR(nt_status
)) {
5950 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5951 domain_name
, nt_errstr(nt_status
)));
5955 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5956 "domain %s", domain_name
))) {
5957 DEBUG(0, ("talloc_init() failed\n"));
5962 /* Make sure we're talking to a proper server */
5964 nt_status
= rpc_trustdom_get_pdc(cli
, mem_ctx
, domain_name
);
5965 if (!NT_STATUS_IS_OK(nt_status
)) {
5967 talloc_destroy(mem_ctx
);
5972 * Call LsaOpenPolicy and LsaQueryInfo
5975 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5977 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5979 talloc_destroy(mem_ctx
);
5983 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
5985 if (NT_STATUS_IS_ERR(nt_status
)) {
5986 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5987 nt_errstr(nt_status
)));
5989 talloc_destroy(mem_ctx
);
5993 /* Querying info level 5 */
5995 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5997 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5999 if (NT_STATUS_IS_ERR(nt_status
)) {
6000 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6001 nt_errstr(nt_status
)));
6003 talloc_destroy(mem_ctx
);
6007 domain_sid
= info
->account_domain
.sid
;
6009 /* There should be actually query info level 3 (following nt serv behaviour),
6010 but I still don't know if it's _really_ necessary */
6013 * Store the password in secrets db
6016 if (!pdb_set_trusteddom_pw(domain_name
, opt_password
, domain_sid
)) {
6017 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6019 talloc_destroy(mem_ctx
);
6024 * Close the pipes and clean up
6027 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6028 if (NT_STATUS_IS_ERR(nt_status
)) {
6029 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
6030 nt_errstr(nt_status
)));
6032 talloc_destroy(mem_ctx
);
6038 talloc_destroy(mem_ctx
);
6040 d_printf("Trust to domain %s established\n", domain_name
);
6045 * Revoke trust relationship to the remote domain
6047 * @param argc standard argc
6048 * @param argv standard argv without initial components
6050 * @return Integer status (0 means success)
6053 static int rpc_trustdom_revoke(int argc
, const char **argv
)
6058 if (argc
< 1) return -1;
6060 /* generate upper cased domain name */
6061 domain_name
= smb_xstrdup(argv
[0]);
6062 strupper_m(domain_name
);
6064 /* delete password of the trust */
6065 if (!pdb_del_trusteddom_pw(domain_name
)) {
6066 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
6073 SAFE_FREE(domain_name
);
6078 * Usage for 'net rpc trustdom' command
6080 * @param argc standard argc
6081 * @param argv standard argv without inital components
6083 * @return Integer status returned to shell
6086 static int rpc_trustdom_usage(int argc
, const char **argv
)
6088 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
6089 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
6090 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
6091 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
6092 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
6093 d_printf(" net rpc trustdom vampire \t vampire interdomain trust relationships from remote server\n");
6098 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
6099 const char *domain_name
,
6100 struct cli_state
*cli
,
6101 struct rpc_pipe_client
*pipe_hnd
,
6102 TALLOC_CTX
*mem_ctx
,
6107 sid_to_fstring(str_sid
, domain_sid
);
6108 d_printf("%s\n", str_sid
);
6109 return NT_STATUS_OK
;
6112 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
6114 fstring ascii_sid
, padding
;
6115 int pad_len
, col_len
= 20;
6117 /* convert sid into ascii string */
6118 sid_to_fstring(ascii_sid
, dom_sid
);
6120 /* calculate padding space for d_printf to look nicer */
6121 pad_len
= col_len
- strlen(trusted_dom_name
);
6122 padding
[pad_len
] = 0;
6123 do padding
[--pad_len
] = ' '; while (pad_len
);
6125 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
6128 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
6129 TALLOC_CTX
*mem_ctx
,
6132 const char *trusted_dom_name
)
6135 union lsa_TrustedDomainInfo info
;
6136 char *cleartextpwd
= NULL
;
6139 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
6142 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
6144 if (NT_STATUS_IS_ERR(nt_status
)) {
6145 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
6146 nt_errstr(nt_status
)));
6150 data
= data_blob(NULL
, info
.password
.password
->length
);
6153 info
.password
.password
->data
,
6154 info
.password
.password
->length
);
6155 data
.length
= info
.password
.password
->length
;
6157 cleartextpwd
= decrypt_trustdom_secret(pipe_hnd
->cli
->pwd
.password
,
6160 if (cleartextpwd
== NULL
) {
6161 DEBUG(0,("retrieved NULL password\n"));
6162 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6166 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
6167 DEBUG(0, ("Storing password for trusted domain failed.\n"));
6168 nt_status
= NT_STATUS_UNSUCCESSFUL
;
6172 #ifdef DEBUG_PASSWORD
6173 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
6174 "password: [%s]\n", trusted_dom_name
,
6175 sid_string_dbg(&dom_sid
), cleartextpwd
));
6179 SAFE_FREE(cleartextpwd
);
6180 data_blob_free(&data
);
6185 static int rpc_trustdom_vampire(int argc
, const char **argv
)
6187 /* common variables */
6188 TALLOC_CTX
* mem_ctx
;
6189 struct cli_state
*cli
= NULL
;
6190 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6192 const char *domain_name
= NULL
;
6193 DOM_SID
*queried_dom_sid
;
6194 POLICY_HND connect_hnd
;
6195 union lsa_PolicyInformation
*info
= NULL
;
6197 /* trusted domains listing variables */
6198 unsigned int enum_ctx
= 0;
6200 struct lsa_DomainList dom_list
;
6204 * Listing trusted domains (stored in secrets.tdb, if local)
6207 mem_ctx
= talloc_init("trust relationships vampire");
6210 * set domain and pdc name to local samba server (default)
6211 * or to remote one given in command line
6214 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6215 domain_name
= opt_workgroup
;
6216 opt_target_workgroup
= opt_workgroup
;
6218 fstrcpy(pdc_name
, global_myname());
6219 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6220 opt_target_workgroup
= domain_name
;
6223 /* open \PIPE\lsarpc and open policy handle */
6224 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6225 if (!NT_STATUS_IS_OK(nt_status
)) {
6226 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6227 nt_errstr(nt_status
)));
6228 talloc_destroy(mem_ctx
);
6232 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6234 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6235 nt_errstr(nt_status
) ));
6237 talloc_destroy(mem_ctx
);
6241 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6243 if (NT_STATUS_IS_ERR(nt_status
)) {
6244 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6245 nt_errstr(nt_status
)));
6247 talloc_destroy(mem_ctx
);
6251 /* query info level 5 to obtain sid of a domain being queried */
6252 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6254 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6257 if (NT_STATUS_IS_ERR(nt_status
)) {
6258 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6259 nt_errstr(nt_status
)));
6261 talloc_destroy(mem_ctx
);
6265 queried_dom_sid
= info
->account_domain
.sid
;
6268 * Keep calling LsaEnumTrustdom over opened pipe until
6269 * the end of enumeration is reached
6272 d_printf("Vampire trusted domains:\n\n");
6275 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6280 if (NT_STATUS_IS_ERR(nt_status
)) {
6281 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6282 nt_errstr(nt_status
)));
6284 talloc_destroy(mem_ctx
);
6288 for (i
= 0; i
< dom_list
.count
; i
++) {
6290 print_trusted_domain(dom_list
.domains
[i
].sid
,
6291 dom_list
.domains
[i
].name
.string
);
6293 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6294 *dom_list
.domains
[i
].sid
,
6295 dom_list
.domains
[i
].name
.string
);
6296 if (!NT_STATUS_IS_OK(nt_status
)) {
6298 talloc_destroy(mem_ctx
);
6304 * in case of no trusted domains say something rather
6305 * than just display blank line
6307 if (!dom_list
.count
) d_printf("none\n");
6309 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6311 /* close this connection before doing next one */
6312 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6313 if (NT_STATUS_IS_ERR(nt_status
)) {
6314 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6315 nt_errstr(nt_status
)));
6317 talloc_destroy(mem_ctx
);
6321 /* close lsarpc pipe and connection to IPC$ */
6324 talloc_destroy(mem_ctx
);
6328 static int rpc_trustdom_list(int argc
, const char **argv
)
6330 /* common variables */
6331 TALLOC_CTX
* mem_ctx
;
6332 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6333 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6335 const char *domain_name
= NULL
;
6336 DOM_SID
*queried_dom_sid
;
6338 int ascii_dom_name_len
;
6339 POLICY_HND connect_hnd
;
6340 union lsa_PolicyInformation
*info
= NULL
;
6342 /* trusted domains listing variables */
6343 unsigned int num_domains
, enum_ctx
= 0;
6344 int i
, pad_len
, col_len
= 20;
6345 struct lsa_DomainList dom_list
;
6348 /* trusting domains listing variables */
6349 POLICY_HND domain_hnd
;
6350 struct samr_SamArray
*trusts
= NULL
;
6353 * Listing trusted domains (stored in secrets.tdb, if local)
6356 mem_ctx
= talloc_init("trust relationships listing");
6359 * set domain and pdc name to local samba server (default)
6360 * or to remote one given in command line
6363 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6364 domain_name
= opt_workgroup
;
6365 opt_target_workgroup
= opt_workgroup
;
6367 fstrcpy(pdc_name
, global_myname());
6368 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6369 opt_target_workgroup
= domain_name
;
6372 /* open \PIPE\lsarpc and open policy handle */
6373 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6374 if (!NT_STATUS_IS_OK(nt_status
)) {
6375 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6376 nt_errstr(nt_status
)));
6377 talloc_destroy(mem_ctx
);
6381 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6383 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6384 nt_errstr(nt_status
) ));
6386 talloc_destroy(mem_ctx
);
6390 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6392 if (NT_STATUS_IS_ERR(nt_status
)) {
6393 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6394 nt_errstr(nt_status
)));
6396 talloc_destroy(mem_ctx
);
6400 /* query info level 5 to obtain sid of a domain being queried */
6401 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6403 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6406 if (NT_STATUS_IS_ERR(nt_status
)) {
6407 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6408 nt_errstr(nt_status
)));
6410 talloc_destroy(mem_ctx
);
6414 queried_dom_sid
= info
->account_domain
.sid
;
6417 * Keep calling LsaEnumTrustdom over opened pipe until
6418 * the end of enumeration is reached
6421 d_printf("Trusted domains list:\n\n");
6424 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6429 if (NT_STATUS_IS_ERR(nt_status
)) {
6430 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6431 nt_errstr(nt_status
)));
6433 talloc_destroy(mem_ctx
);
6437 for (i
= 0; i
< dom_list
.count
; i
++) {
6438 print_trusted_domain(dom_list
.domains
[i
].sid
,
6439 dom_list
.domains
[i
].name
.string
);
6443 * in case of no trusted domains say something rather
6444 * than just display blank line
6446 if (!dom_list
.count
) d_printf("none\n");
6448 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6450 /* close this connection before doing next one */
6451 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6452 if (NT_STATUS_IS_ERR(nt_status
)) {
6453 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6454 nt_errstr(nt_status
)));
6456 talloc_destroy(mem_ctx
);
6460 cli_rpc_pipe_close(pipe_hnd
);
6463 * Listing trusting domains (stored in passdb backend, if local)
6466 d_printf("\nTrusting domains list:\n\n");
6469 * Open \PIPE\samr and get needed policy handles
6471 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_SAMR
, &nt_status
);
6473 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6475 talloc_destroy(mem_ctx
);
6480 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6481 pipe_hnd
->cli
->desthost
,
6482 SA_RIGHT_SAM_OPEN_DOMAIN
,
6484 if (!NT_STATUS_IS_OK(nt_status
)) {
6485 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6486 nt_errstr(nt_status
)));
6488 talloc_destroy(mem_ctx
);
6492 /* SamrOpenDomain - we have to open domain policy handle in order to be
6493 able to enumerate accounts*/
6494 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6496 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6499 if (!NT_STATUS_IS_OK(nt_status
)) {
6500 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6501 nt_errstr(nt_status
)));
6503 talloc_destroy(mem_ctx
);
6508 * perform actual enumeration
6511 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6514 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6521 if (NT_STATUS_IS_ERR(nt_status
)) {
6522 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6523 nt_errstr(nt_status
)));
6525 talloc_destroy(mem_ctx
);
6529 for (i
= 0; i
< num_domains
; i
++) {
6531 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6534 * get each single domain's sid (do we _really_ need this ?):
6535 * 1) connect to domain's pdc
6536 * 2) query the pdc for domain's sid
6539 /* get rid of '$' tail */
6540 ascii_dom_name_len
= strlen(str
);
6541 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6542 str
[ascii_dom_name_len
- 1] = '\0';
6544 /* calculate padding space for d_printf to look nicer */
6545 pad_len
= col_len
- strlen(str
);
6546 padding
[pad_len
] = 0;
6547 do padding
[--pad_len
] = ' '; while (pad_len
);
6549 /* set opt_* variables to remote domain */
6551 opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6552 opt_target_workgroup
= opt_workgroup
;
6554 d_printf("%s%s", str
, padding
);
6556 /* connect to remote domain controller */
6557 nt_status
= net_make_ipc_connection(
6558 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6560 if (NT_STATUS_IS_OK(nt_status
)) {
6561 /* query for domain's sid */
6562 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
6563 d_fprintf(stderr
, "couldn't get domain's sid\n");
6565 cli_shutdown(remote_cli
);
6568 d_fprintf(stderr
, "domain controller is not "
6570 nt_errstr(nt_status
));
6574 if (!num_domains
) d_printf("none\n");
6576 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6578 /* close opened samr and domain policy handles */
6579 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6580 if (!NT_STATUS_IS_OK(nt_status
)) {
6581 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6584 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6585 if (!NT_STATUS_IS_OK(nt_status
)) {
6586 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6589 /* close samr pipe and connection to IPC$ */
6592 talloc_destroy(mem_ctx
);
6597 * Entrypoint for 'net rpc trustdom' code
6599 * @param argc standard argc
6600 * @param argv standard argv without initial components
6602 * @return Integer status (0 means success)
6605 static int rpc_trustdom(int argc
, const char **argv
)
6607 struct functable func
[] = {
6608 {"add", rpc_trustdom_add
},
6609 {"del", rpc_trustdom_del
},
6610 {"establish", rpc_trustdom_establish
},
6611 {"revoke", rpc_trustdom_revoke
},
6612 {"help", rpc_trustdom_usage
},
6613 {"list", rpc_trustdom_list
},
6614 {"vampire", rpc_trustdom_vampire
},
6619 rpc_trustdom_usage(argc
, argv
);
6623 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6627 * Check if a server will take rpc commands
6628 * @param flags Type of server to connect to (PDC, DMB, localhost)
6629 * if the host is not explicitly specified
6630 * @return bool (true means rpc supported)
6632 bool net_rpc_check(unsigned flags
)
6634 struct cli_state
*cli
;
6636 struct sockaddr_storage server_ss
;
6637 char *server_name
= NULL
;
6640 /* flags (i.e. server type) may depend on command */
6641 if (!net_find_server(NULL
, flags
, &server_ss
, &server_name
))
6644 if ((cli
= cli_initialise()) == NULL
) {
6648 status
= cli_connect(cli
, server_name
, &server_ss
);
6649 if (!NT_STATUS_IS_OK(status
))
6651 if (!attempt_netbios_session_request(&cli
, global_myname(),
6652 server_name
, &server_ss
))
6654 if (!cli_negprot(cli
))
6656 if (cli
->protocol
< PROTOCOL_NT1
)
6665 /* dump sam database via samsync rpc calls */
6666 static int rpc_samdump(int argc
, const char **argv
) {
6667 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
6671 /* syncronise sam database via samsync rpc calls */
6672 static int rpc_vampire(int argc
, const char **argv
) {
6673 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
6678 * Migrate everything from a print-server
6680 * @param argc Standard main() style argc
6681 * @param argv Standard main() style argv. Initial components are already
6684 * @return A shell status integer (0 for success)
6686 * The order is important !
6687 * To successfully add drivers the print-queues have to exist !
6688 * Applying ACLs should be the last step, because you're easily locked out
6691 static int rpc_printer_migrate_all(int argc
, const char **argv
)
6696 printf("no server to migrate\n");
6700 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
6704 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
6708 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
6712 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
6716 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
6721 * Migrate print-drivers from a print-server
6723 * @param argc Standard main() style argc
6724 * @param argv Standard main() style argv. Initial components are already
6727 * @return A shell status integer (0 for success)
6729 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
6732 printf("no server to migrate\n");
6736 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6737 rpc_printer_migrate_drivers_internals
,
6742 * Migrate print-forms from a print-server
6744 * @param argc Standard main() style argc
6745 * @param argv Standard main() style argv. Initial components are already
6748 * @return A shell status integer (0 for success)
6750 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
6753 printf("no server to migrate\n");
6757 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6758 rpc_printer_migrate_forms_internals
,
6763 * Migrate printers from a print-server
6765 * @param argc Standard main() style argc
6766 * @param argv Standard main() style argv. Initial components are already
6769 * @return A shell status integer (0 for success)
6771 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
6774 printf("no server to migrate\n");
6778 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6779 rpc_printer_migrate_printers_internals
,
6784 * Migrate printer-ACLs from a print-server
6786 * @param argc Standard main() style argc
6787 * @param argv Standard main() style argv. Initial components are already
6790 * @return A shell status integer (0 for success)
6792 static int rpc_printer_migrate_security(int argc
, const char **argv
)
6795 printf("no server to migrate\n");
6799 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6800 rpc_printer_migrate_security_internals
,
6805 * Migrate printer-settings from a print-server
6807 * @param argc Standard main() style argc
6808 * @param argv Standard main() style argv. Initial components are already
6811 * @return A shell status integer (0 for success)
6813 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
6816 printf("no server to migrate\n");
6820 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6821 rpc_printer_migrate_settings_internals
,
6826 * 'net rpc printer' entrypoint.
6827 * @param argc Standard main() style argc
6828 * @param argv Standard main() style argv. Initial components are already
6832 int rpc_printer_migrate(int argc
, const char **argv
)
6835 /* ouch: when addriver and setdriver are called from within
6836 rpc_printer_migrate_drivers_internals, the printer-queue already
6839 struct functable func
[] = {
6840 {"all", rpc_printer_migrate_all
},
6841 {"drivers", rpc_printer_migrate_drivers
},
6842 {"forms", rpc_printer_migrate_forms
},
6843 {"help", rpc_printer_usage
},
6844 {"printers", rpc_printer_migrate_printers
},
6845 {"security", rpc_printer_migrate_security
},
6846 {"settings", rpc_printer_migrate_settings
},
6850 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6855 * List printers on a remote RPC server
6857 * @param argc Standard main() style argc
6858 * @param argv Standard main() style argv. Initial components are already
6861 * @return A shell status integer (0 for success)
6863 static int rpc_printer_list(int argc
, const char **argv
)
6866 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6867 rpc_printer_list_internals
,
6872 * List printer-drivers on a remote RPC server
6874 * @param argc Standard main() style argc
6875 * @param argv Standard main() style argv. Initial components are already
6878 * @return A shell status integer (0 for success)
6880 static int rpc_printer_driver_list(int argc
, const char **argv
)
6883 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6884 rpc_printer_driver_list_internals
,
6889 * Publish printer in ADS via MSRPC
6891 * @param argc Standard main() style argc
6892 * @param argv Standard main() style argv. Initial components are already
6895 * @return A shell status integer (0 for success)
6897 static int rpc_printer_publish_publish(int argc
, const char **argv
)
6900 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6901 rpc_printer_publish_publish_internals
,
6906 * Update printer in ADS via MSRPC
6908 * @param argc Standard main() style argc
6909 * @param argv Standard main() style argv. Initial components are already
6912 * @return A shell status integer (0 for success)
6914 static int rpc_printer_publish_update(int argc
, const char **argv
)
6917 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6918 rpc_printer_publish_update_internals
,
6923 * UnPublish printer in ADS via MSRPC
6925 * @param argc Standard main() style argc
6926 * @param argv Standard main() style argv. Initial components are already
6929 * @return A shell status integer (0 for success)
6931 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
6934 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6935 rpc_printer_publish_unpublish_internals
,
6940 * List published printers via MSRPC
6942 * @param argc Standard main() style argc
6943 * @param argv Standard main() style argv. Initial components are already
6946 * @return A shell status integer (0 for success)
6948 static int rpc_printer_publish_list(int argc
, const char **argv
)
6951 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6952 rpc_printer_publish_list_internals
,
6958 * Publish printer in ADS
6960 * @param argc Standard main() style argc
6961 * @param argv Standard main() style argv. Initial components are already
6964 * @return A shell status integer (0 for success)
6966 static int rpc_printer_publish(int argc
, const char **argv
)
6969 struct functable func
[] = {
6970 {"publish", rpc_printer_publish_publish
},
6971 {"update", rpc_printer_publish_update
},
6972 {"unpublish", rpc_printer_publish_unpublish
},
6973 {"list", rpc_printer_publish_list
},
6974 {"help", rpc_printer_usage
},
6979 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6980 rpc_printer_publish_list_internals
,
6983 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6989 * Display rpc printer help page.
6990 * @param argc Standard main() style argc
6991 * @param argv Standard main() style argv. Initial components are already
6994 int rpc_printer_usage(int argc
, const char **argv
)
6996 return net_help_printer(argc
, argv
);
7000 * 'net rpc printer' entrypoint.
7001 * @param argc Standard main() style argc
7002 * @param argv Standard main() style argv. Initial components are already
7005 int net_rpc_printer(int argc
, const char **argv
)
7007 struct functable func
[] = {
7008 {"list", rpc_printer_list
},
7009 {"migrate", rpc_printer_migrate
},
7010 {"driver", rpc_printer_driver_list
},
7011 {"publish", rpc_printer_publish
},
7016 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
7017 rpc_printer_list_internals
,
7020 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
7023 /****************************************************************************/
7027 * Basic usage function for 'net rpc'
7028 * @param argc Standard main() style argc
7029 * @param argv Standard main() style argv. Initial components are already
7033 int net_rpc_usage(int argc
, const char **argv
)
7035 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
7036 d_printf(" net rpc join \t\t\tto join a domain \n");
7037 d_printf(" net rpc oldjoin \t\tto join a domain created in server manager\n");
7038 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
7039 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
7040 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
7041 d_printf(" net rpc group \t\tto list groups\n");
7042 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
7043 d_printf(" net rpc printer \t\tto list and migrate printers\n");
7044 d_printf(" net rpc file \t\t\tto list open files\n");
7045 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
7046 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
7047 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
7048 d_printf(" net rpc samdump \t\tdisplay an NT PDC's users, groups and other data\n");
7049 d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n");
7050 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
7051 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
7052 d_printf(" net rpc rights\t\tto manage privileges assigned to SIDs\n");
7053 d_printf(" net rpc registry\t\tto manage registry hives\n");
7054 d_printf(" net rpc service\t\tto start, stop and query services\n");
7055 d_printf(" net rpc audit\t\t\tto modify global auditing settings\n");
7056 d_printf(" net rpc shell\t\t\tto open an interactive shell for remote server/account management\n");
7058 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
7059 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
7060 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
7061 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
7062 d_printf("\t-C or --comment=<message>\ttext message to display on impending shutdown\n");
7068 * Help function for 'net rpc'. Calls command specific help if requested
7069 * or displays usage of net rpc
7070 * @param argc Standard main() style argc
7071 * @param argv Standard main() style argv. Initial components are already
7075 int net_rpc_help(int argc
, const char **argv
)
7077 struct functable func
[] = {
7078 {"join", rpc_join_usage
},
7079 {"user", rpc_user_usage
},
7080 {"group", rpc_group_usage
},
7081 {"share", rpc_share_usage
},
7082 /*{"changetrustpw", rpc_changetrustpw_usage}, */
7083 {"trustdom", rpc_trustdom_usage
},
7084 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
7085 /*{"shutdown", rpc_shutdown_usage}, */
7086 {"vampire", rpc_vampire_usage
},
7091 net_rpc_usage(argc
, argv
);
7095 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
7099 * 'net rpc' entrypoint.
7100 * @param argc Standard main() style argc
7101 * @param argv Standard main() style argv. Initial components are already
7105 int net_rpc(int argc
, const char **argv
)
7107 struct functable func
[] = {
7108 {"audit", net_rpc_audit
},
7109 {"info", net_rpc_info
},
7110 {"join", net_rpc_join
},
7111 {"oldjoin", net_rpc_oldjoin
},
7112 {"testjoin", net_rpc_testjoin
},
7113 {"user", net_rpc_user
},
7114 {"password", rpc_user_password
},
7115 {"group", net_rpc_group
},
7116 {"share", net_rpc_share
},
7117 {"file", net_rpc_file
},
7118 {"printer", net_rpc_printer
},
7119 {"changetrustpw", net_rpc_changetrustpw
},
7120 {"trustdom", rpc_trustdom
},
7121 {"abortshutdown", rpc_shutdown_abort
},
7122 {"shutdown", rpc_shutdown
},
7123 {"samdump", rpc_samdump
},
7124 {"vampire", rpc_vampire
},
7125 {"getsid", net_rpc_getsid
},
7126 {"rights", net_rpc_rights
},
7127 {"service", net_rpc_service
},
7128 {"registry", net_rpc_registry
},
7129 {"shell", net_rpc_shell
},
7130 {"help", net_rpc_help
},
7133 return net_run_function(argc
, argv
, func
, net_rpc_usage
);