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 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2005 Jeremy Allison (jra@samba.org)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "utils/net.h"
26 static int net_mode_share
;
31 * @brief RPC based subcommands for the 'net' utility.
33 * This file should contain much of the functionality that used to
34 * be found in rpcclient, execpt that the commands should change
35 * less often, and the fucntionality should be sane (the user is not
36 * expected to know a rid/sid before they conduct an operation etc.)
38 * @todo Perhaps eventually these should be split out into a number
39 * of files, as this could get quite big.
44 * Many of the RPC functions need the domain sid. This function gets
45 * it at the start of every run
47 * @param cli A cli_state already connected to the remote machine
49 * @return The Domain SID of the remote machine.
52 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
53 DOM_SID
**domain_sid
, char **domain_name
)
55 struct rpc_pipe_client
*lsa_pipe
;
57 NTSTATUS result
= NT_STATUS_OK
;
58 uint32 info_class
= 5;
60 lsa_pipe
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
62 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
66 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, False
,
67 SEC_RIGHTS_MAXIMUM_ALLOWED
,
69 if (!NT_STATUS_IS_OK(result
)) {
70 d_fprintf(stderr
, "open_policy failed: %s\n",
75 result
= rpccli_lsa_query_info_policy(lsa_pipe
, mem_ctx
, &pol
,
76 info_class
, domain_name
,
78 if (!NT_STATUS_IS_OK(result
)) {
79 d_fprintf(stderr
, "lsaquery failed: %s\n",
84 rpccli_lsa_close(lsa_pipe
, mem_ctx
, &pol
);
85 cli_rpc_pipe_close(lsa_pipe
);
91 * Run a single RPC command, from start to finish.
93 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
94 * @param conn_flag a NET_FLAG_ combination. Passed to
95 * net_make_ipc_connection.
96 * @param argc Standard main() style argc
97 * @param argc Standard main() style argv. Initial components are already
99 * @return A shell status integer (0 for success)
102 int run_rpc_command(struct cli_state
*cli_arg
,
109 struct cli_state
*cli
= NULL
;
110 struct rpc_pipe_client
*pipe_hnd
= NULL
;
116 /* make use of cli_state handed over as an argument, if possible */
118 cli
= net_make_ipc_connection(conn_flags
);
129 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
130 DEBUG(0, ("talloc_init() failed\n"));
135 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
137 if (!NT_STATUS_IS_OK(nt_status
)) {
142 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
143 if (lp_client_schannel() && (pipe_idx
== PI_NETLOGON
)) {
144 /* Always try and create an schannel netlogon pipe. */
145 pipe_hnd
= cli_rpc_pipe_open_schannel(cli
, pipe_idx
,
146 PIPE_AUTH_LEVEL_PRIVACY
,
150 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
151 nt_errstr(nt_status
) ));
156 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, pipe_idx
, &nt_status
);
158 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
159 cli_get_pipe_name(pipe_idx
),
160 nt_errstr(nt_status
) ));
167 nt_status
= fn(domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
169 if (!NT_STATUS_IS_OK(nt_status
)) {
170 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
172 DEBUG(5, ("rpc command function succedded\n"));
175 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
177 cli_rpc_pipe_close(pipe_hnd
);
181 /* close the connection only if it was opened here */
186 talloc_destroy(mem_ctx
);
187 return (!NT_STATUS_IS_OK(nt_status
));
191 * Force a change of the trust acccount password.
193 * All parameters are provided by the run_rpc_command function, except for
194 * argc, argv which are passes through.
196 * @param domain_sid The domain sid aquired from the remote server
197 * @param cli A cli_state connected to the server.
198 * @param mem_ctx Talloc context, destoyed on compleation of the function.
199 * @param argc Standard main() style argc
200 * @param argc Standard main() style argv. Initial components are already
203 * @return Normal NTSTATUS return.
206 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
,
207 const char *domain_name
,
208 struct cli_state
*cli
,
209 struct rpc_pipe_client
*pipe_hnd
,
215 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
);
219 * Force a change of the trust acccount password.
221 * @param argc Standard main() style argc
222 * @param argc Standard main() style argv. Initial components are already
225 * @return A shell status integer (0 for success)
228 int net_rpc_changetrustpw(int argc
, const char **argv
)
230 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
231 rpc_changetrustpw_internals
,
236 * Join a domain, the old way.
238 * This uses 'machinename' as the inital password, and changes it.
240 * The password should be created with 'server manager' or equiv first.
242 * All parameters are provided by the run_rpc_command function, except for
243 * argc, argv which are passes through.
245 * @param domain_sid The domain sid aquired from the remote server
246 * @param cli A cli_state connected to the server.
247 * @param mem_ctx Talloc context, destoyed on compleation of the function.
248 * @param argc Standard main() style argc
249 * @param argc Standard main() style argv. Initial components are already
252 * @return Normal NTSTATUS return.
255 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
,
256 const char *domain_name
,
257 struct cli_state
*cli
,
258 struct rpc_pipe_client
*pipe_hnd
,
264 fstring trust_passwd
;
265 unsigned char orig_trust_passwd_hash
[16];
267 uint32 sec_channel_type
;
269 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &result
);
271 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
274 nt_errstr(result
) ));
279 check what type of join - if the user want's to join as
280 a BDC, the server must agree that we are a BDC.
283 sec_channel_type
= get_sec_channel_type(argv
[0]);
285 sec_channel_type
= get_sec_channel_type(NULL
);
288 fstrcpy(trust_passwd
, global_myname());
289 strlower_m(trust_passwd
);
292 * Machine names can be 15 characters, but the max length on
293 * a password is 14. --jerry
296 trust_passwd
[14] = '\0';
298 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
300 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
,
301 orig_trust_passwd_hash
,
304 if (NT_STATUS_IS_OK(result
))
305 printf("Joined domain %s.\n",opt_target_workgroup
);
308 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
309 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
310 result
= NT_STATUS_UNSUCCESSFUL
;
317 * Join a domain, the old way.
319 * @param argc Standard main() style argc
320 * @param argc Standard main() style argv. Initial components are already
323 * @return A shell status integer (0 for success)
326 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
328 return run_rpc_command(NULL
, PI_NETLOGON
,
329 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
330 rpc_oldjoin_internals
,
335 * Join a domain, the old way. This function exists to allow
336 * the message to be displayed when oldjoin was explicitly
337 * requested, but not when it was implied by "net rpc join"
339 * @param argc Standard main() style argc
340 * @param argc Standard main() style argv. Initial components are already
343 * @return A shell status integer (0 for success)
346 static int net_rpc_oldjoin(int argc
, const char **argv
)
348 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
351 d_fprintf(stderr
, "Failed to join domain\n");
358 * Basic usage function for 'net rpc join'
359 * @param argc Standard main() style argc
360 * @param argc Standard main() style argv. Initial components are already
364 static int rpc_join_usage(int argc
, const char **argv
)
366 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
367 "\t to join a domain with admin username & password\n"\
368 "\t\t password will be prompted if needed and none is specified\n"\
369 "\t <type> can be (default MEMBER)\n"\
370 "\t\t BDC - Join as a BDC\n"\
371 "\t\t PDC - Join as a PDC\n"\
372 "\t\t MEMBER - Join as a MEMBER server\n");
374 net_common_flags_usage(argc
, argv
);
379 * 'net rpc join' entrypoint.
380 * @param argc Standard main() style argc
381 * @param argc Standard main() style argv. Initial components are already
384 * Main 'net_rpc_join()' (where the admain username/password is used) is
386 * Try to just change the password, but if that doesn't work, use/prompt
387 * for a username/password.
390 int net_rpc_join(int argc
, const char **argv
)
392 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
395 return net_rpc_join_newstyle(argc
, argv
);
399 * display info about a rpc domain
401 * All parameters are provided by the run_rpc_command function, except for
402 * argc, argv which are passed through.
404 * @param domain_sid The domain sid acquired from the remote server
405 * @param cli A cli_state connected to the server.
406 * @param mem_ctx Talloc context, destoyed on completion of the function.
407 * @param argc Standard main() style argc
408 * @param argv Standard main() style argv. Initial components are already
411 * @return Normal NTSTATUS return.
414 NTSTATUS
rpc_info_internals(const DOM_SID
*domain_sid
,
415 const char *domain_name
,
416 struct cli_state
*cli
,
417 struct rpc_pipe_client
*pipe_hnd
,
422 POLICY_HND connect_pol
, domain_pol
;
423 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
427 sid_to_string(sid_str
, domain_sid
);
429 /* Get sam policy handle */
430 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
432 if (!NT_STATUS_IS_OK(result
)) {
436 /* Get domain policy handle */
437 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
438 MAXIMUM_ALLOWED_ACCESS
,
439 domain_sid
, &domain_pol
);
440 if (!NT_STATUS_IS_OK(result
)) {
445 result
= rpccli_samr_query_dom_info(pipe_hnd
, mem_ctx
, &domain_pol
,
447 if (NT_STATUS_IS_OK(result
)) {
448 TALLOC_CTX
*ctx
= talloc_init("rpc_info_internals");
449 d_printf("Domain Name: %s\n", unistr2_tdup(ctx
, &ctr
.info
.inf2
.uni_domain
));
450 d_printf("Domain SID: %s\n", sid_str
);
451 d_printf("Sequence number: %u\n", ctr
.info
.inf2
.seq_num
.low
);
452 d_printf("Num users: %u\n", ctr
.info
.inf2
.num_domain_usrs
);
453 d_printf("Num domain groups: %u\n", ctr
.info
.inf2
.num_domain_grps
);
454 d_printf("Num local groups: %u\n", ctr
.info
.inf2
.num_local_grps
);
463 * 'net rpc info' entrypoint.
464 * @param argc Standard main() style argc
465 * @param argc Standard main() style argv. Initial components are already
469 int net_rpc_info(int argc
, const char **argv
)
471 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
477 * Fetch domain SID into the local secrets.tdb
479 * All parameters are provided by the run_rpc_command function, except for
480 * argc, argv which are passes through.
482 * @param domain_sid The domain sid acquired from the remote server
483 * @param cli A cli_state connected to the server.
484 * @param mem_ctx Talloc context, destoyed on completion of the function.
485 * @param argc Standard main() style argc
486 * @param argv Standard main() style argv. Initial components are already
489 * @return Normal NTSTATUS return.
492 static NTSTATUS
rpc_getsid_internals(const DOM_SID
*domain_sid
,
493 const char *domain_name
,
494 struct cli_state
*cli
,
495 struct rpc_pipe_client
*pipe_hnd
,
502 sid_to_string(sid_str
, domain_sid
);
503 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
504 sid_str
, domain_name
);
506 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
507 DEBUG(0,("Can't store domain SID\n"));
508 return NT_STATUS_UNSUCCESSFUL
;
515 * 'net rpc getsid' entrypoint.
516 * @param argc Standard main() style argc
517 * @param argc Standard main() style argv. Initial components are already
521 int net_rpc_getsid(int argc
, const char **argv
)
523 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
524 rpc_getsid_internals
,
528 /****************************************************************************/
531 * Basic usage function for 'net rpc user'
532 * @param argc Standard main() style argc.
533 * @param argv Standard main() style argv. Initial components are already
537 static int rpc_user_usage(int argc
, const char **argv
)
539 return net_help_user(argc
, argv
);
543 * Add a new user to a remote RPC server
545 * All parameters are provided by the run_rpc_command function, except for
546 * argc, argv which are passes through.
548 * @param domain_sid The domain sid acquired from the remote server
549 * @param cli A cli_state connected to the server.
550 * @param mem_ctx Talloc context, destoyed on completion of the function.
551 * @param argc Standard main() style argc
552 * @param argv Standard main() style argv. Initial components are already
555 * @return Normal NTSTATUS return.
558 static NTSTATUS
rpc_user_add_internals(const DOM_SID
*domain_sid
,
559 const char *domain_name
,
560 struct cli_state
*cli
,
561 struct rpc_pipe_client
*pipe_hnd
,
563 int argc
, const char **argv
)
566 POLICY_HND connect_pol
, domain_pol
, user_pol
;
567 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
568 const char *acct_name
;
570 uint32 unknown
, user_rid
;
573 d_printf("User must be specified\n");
574 rpc_user_usage(argc
, argv
);
580 /* Get sam policy handle */
582 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
584 if (!NT_STATUS_IS_OK(result
)) {
588 /* Get domain policy handle */
590 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
591 MAXIMUM_ALLOWED_ACCESS
,
592 domain_sid
, &domain_pol
);
593 if (!NT_STATUS_IS_OK(result
)) {
597 /* Create domain user */
599 acb_info
= ACB_NORMAL
;
600 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
602 result
= rpccli_samr_create_dom_user(pipe_hnd
, mem_ctx
, &domain_pol
,
603 acct_name
, acb_info
, unknown
,
604 &user_pol
, &user_rid
);
605 if (!NT_STATUS_IS_OK(result
)) {
610 if (!NT_STATUS_IS_OK(result
)) {
611 d_fprintf(stderr
, "Failed to add user %s - %s\n", acct_name
,
614 d_printf("Added user %s\n", acct_name
);
620 * Add a new user to a remote RPC server
622 * @param argc Standard main() style argc
623 * @param argv Standard main() style argv. Initial components are already
626 * @return A shell status integer (0 for success)
629 static int rpc_user_add(int argc
, const char **argv
)
631 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_add_internals
,
636 * Delete a user from a remote RPC server
638 * All parameters are provided by the run_rpc_command function, except for
639 * argc, argv which are passes through.
641 * @param domain_sid The domain sid acquired from the remote server
642 * @param cli A cli_state connected to the server.
643 * @param mem_ctx Talloc context, destoyed on completion of the function.
644 * @param argc Standard main() style argc
645 * @param argv Standard main() style argv. Initial components are already
648 * @return Normal NTSTATUS return.
651 static NTSTATUS
rpc_user_del_internals(const DOM_SID
*domain_sid
,
652 const char *domain_name
,
653 struct cli_state
*cli
,
654 struct rpc_pipe_client
*pipe_hnd
,
659 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
660 POLICY_HND connect_pol
, domain_pol
, user_pol
;
663 d_printf("User must be specified\n");
664 rpc_user_usage(argc
, argv
);
667 /* Get sam policy and domain handles */
669 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
672 if (!NT_STATUS_IS_OK(result
)) {
676 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
677 MAXIMUM_ALLOWED_ACCESS
,
678 domain_sid
, &domain_pol
);
680 if (!NT_STATUS_IS_OK(result
)) {
684 /* Get handle on user */
687 uint32
*user_rids
, num_rids
, *name_types
;
688 uint32 flags
= 0x000003e8; /* Unknown */
690 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
692 &num_rids
, &user_rids
,
695 if (!NT_STATUS_IS_OK(result
)) {
699 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
700 MAXIMUM_ALLOWED_ACCESS
,
701 user_rids
[0], &user_pol
);
703 if (!NT_STATUS_IS_OK(result
)) {
710 result
= rpccli_samr_delete_dom_user(pipe_hnd
, mem_ctx
, &user_pol
);
712 if (!NT_STATUS_IS_OK(result
)) {
716 /* Display results */
717 if (!NT_STATUS_IS_OK(result
)) {
718 d_fprintf(stderr
, "Failed to delete user account - %s\n", nt_errstr(result
));
720 d_printf("Deleted user account\n");
728 * Rename a user on a remote RPC server
730 * All parameters are provided by the run_rpc_command function, except for
731 * argc, argv which are passes through.
733 * @param domain_sid The domain sid acquired from the remote server
734 * @param cli A cli_state connected to the server.
735 * @param mem_ctx Talloc context, destoyed on completion of the function.
736 * @param argc Standard main() style argc
737 * @param argv Standard main() style argv. Initial components are already
740 * @return Normal NTSTATUS return.
743 static NTSTATUS
rpc_user_rename_internals(const DOM_SID
*domain_sid
,
744 const char *domain_name
,
745 struct cli_state
*cli
,
746 struct rpc_pipe_client
*pipe_hnd
,
751 POLICY_HND connect_pol
, domain_pol
, user_pol
;
752 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
753 uint32 info_level
= 7;
754 const char *old_name
, *new_name
;
756 uint32 flags
= 0x000003e8; /* Unknown */
757 uint32 num_rids
, *name_types
;
758 uint32 num_names
= 1;
760 SAM_USERINFO_CTR
*user_ctr
;
761 SAM_USERINFO_CTR ctr
;
762 SAM_USER_INFO_7 info7
;
765 d_printf("Old and new username must be specified\n");
766 rpc_user_usage(argc
, argv
);
774 ZERO_STRUCT(user_ctr
);
776 /* Get sam policy handle */
778 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
780 if (!NT_STATUS_IS_OK(result
)) {
784 /* Get domain policy handle */
786 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
787 MAXIMUM_ALLOWED_ACCESS
,
788 domain_sid
, &domain_pol
);
789 if (!NT_STATUS_IS_OK(result
)) {
793 names
= TALLOC_ARRAY(mem_ctx
, const char *, num_names
);
795 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
796 flags
, num_names
, names
,
797 &num_rids
, &user_rid
, &name_types
);
798 if (!NT_STATUS_IS_OK(result
)) {
802 /* Open domain user */
803 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
804 MAXIMUM_ALLOWED_ACCESS
, user_rid
[0], &user_pol
);
806 if (!NT_STATUS_IS_OK(result
)) {
810 /* Query user info */
811 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
812 info_level
, &user_ctr
);
814 if (!NT_STATUS_IS_OK(result
)) {
818 ctr
.switch_value
= info_level
;
819 ctr
.info
.id7
= &info7
;
821 init_sam_user_info7(&info7
, new_name
);
824 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
825 info_level
, &cli
->user_session_key
, &ctr
);
827 if (!NT_STATUS_IS_OK(result
)) {
832 if (!NT_STATUS_IS_OK(result
)) {
833 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n", old_name
, new_name
,
836 d_printf("Renamed user from %s to %s\n", old_name
, new_name
);
842 * Rename a user on a remote RPC server
844 * @param argc Standard main() style argc
845 * @param argv Standard main() style argv. Initial components are already
848 * @return A shell status integer (0 for success)
851 static int rpc_user_rename(int argc
, const char **argv
)
853 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_rename_internals
,
858 * Delete a user from a remote RPC server
860 * @param argc Standard main() style argc
861 * @param argv Standard main() style argv. Initial components are already
864 * @return A shell status integer (0 for success)
867 static int rpc_user_delete(int argc
, const char **argv
)
869 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_del_internals
,
874 * Set a password for a user on a remote RPC server
876 * All parameters are provided by the run_rpc_command function, except for
877 * argc, argv which are passes through.
879 * @param domain_sid The domain sid acquired from the remote server
880 * @param cli A cli_state connected to the server.
881 * @param mem_ctx Talloc context, destoyed on completion of the function.
882 * @param argc Standard main() style argc
883 * @param argv Standard main() style argv. Initial components are already
886 * @return Normal NTSTATUS return.
889 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
890 const char *domain_name
,
891 struct cli_state
*cli
,
892 struct rpc_pipe_client
*pipe_hnd
,
897 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
898 POLICY_HND connect_pol
, domain_pol
, user_pol
;
899 SAM_USERINFO_CTR ctr
;
900 SAM_USER_INFO_24 p24
;
903 const char *new_password
;
907 d_printf("User must be specified\n");
908 rpc_user_usage(argc
, argv
);
915 new_password
= argv
[1];
917 asprintf(&prompt
, "Enter new password for %s:", user
);
918 new_password
= getpass(prompt
);
922 /* Get sam policy and domain handles */
924 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
927 if (!NT_STATUS_IS_OK(result
)) {
931 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
932 MAXIMUM_ALLOWED_ACCESS
,
933 domain_sid
, &domain_pol
);
935 if (!NT_STATUS_IS_OK(result
)) {
939 /* Get handle on user */
942 uint32
*user_rids
, num_rids
, *name_types
;
943 uint32 flags
= 0x000003e8; /* Unknown */
945 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
947 &num_rids
, &user_rids
,
950 if (!NT_STATUS_IS_OK(result
)) {
954 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
955 MAXIMUM_ALLOWED_ACCESS
,
956 user_rids
[0], &user_pol
);
958 if (!NT_STATUS_IS_OK(result
)) {
963 /* Set password on account */
968 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
970 init_sam_user_info24(&p24
, (char *)pwbuf
,24);
972 ctr
.switch_value
= 24;
973 ctr
.info
.id24
= &p24
;
975 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
, 24,
976 &cli
->user_session_key
, &ctr
);
978 if (!NT_STATUS_IS_OK(result
)) {
982 /* Display results */
990 * Set a user's password on a remote RPC server
992 * @param argc Standard main() style argc
993 * @param argv Standard main() style argv. Initial components are already
996 * @return A shell status integer (0 for success)
999 static int rpc_user_password(int argc
, const char **argv
)
1001 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
1006 * List user's groups on a remote RPC server
1008 * All parameters are provided by the run_rpc_command function, except for
1009 * argc, argv which are passes through.
1011 * @param domain_sid The domain sid acquired from the remote server
1012 * @param cli A cli_state connected to the server.
1013 * @param mem_ctx Talloc context, destoyed on completion of the function.
1014 * @param argc Standard main() style argc
1015 * @param argv Standard main() style argv. Initial components are already
1018 * @return Normal NTSTATUS return.
1021 static NTSTATUS
rpc_user_info_internals(const DOM_SID
*domain_sid
,
1022 const char *domain_name
,
1023 struct cli_state
*cli
,
1024 struct rpc_pipe_client
*pipe_hnd
,
1025 TALLOC_CTX
*mem_ctx
,
1029 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1030 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1031 uint32
*rids
, num_rids
, *name_types
, num_names
;
1032 uint32 flags
= 0x000003e8; /* Unknown */
1038 d_printf("User must be specified\n");
1039 rpc_user_usage(argc
, argv
);
1040 return NT_STATUS_OK
;
1042 /* Get sam policy handle */
1044 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1046 if (!NT_STATUS_IS_OK(result
)) goto done
;
1048 /* Get domain policy handle */
1050 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1051 MAXIMUM_ALLOWED_ACCESS
,
1052 domain_sid
, &domain_pol
);
1053 if (!NT_STATUS_IS_OK(result
)) goto done
;
1055 /* Get handle on user */
1057 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
1059 &num_rids
, &rids
, &name_types
);
1061 if (!NT_STATUS_IS_OK(result
)) goto done
;
1063 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1064 MAXIMUM_ALLOWED_ACCESS
,
1065 rids
[0], &user_pol
);
1066 if (!NT_STATUS_IS_OK(result
)) goto done
;
1068 result
= rpccli_samr_query_usergroups(pipe_hnd
, mem_ctx
, &user_pol
,
1069 &num_rids
, &user_gids
);
1071 if (!NT_STATUS_IS_OK(result
)) goto done
;
1076 rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
);
1078 for (i
= 0; i
< num_rids
; i
++)
1079 rids
[i
] = user_gids
[i
].g_rid
;
1081 result
= rpccli_samr_lookup_rids(pipe_hnd
, mem_ctx
, &domain_pol
,
1083 &num_names
, &names
, &name_types
);
1085 if (!NT_STATUS_IS_OK(result
)) {
1089 /* Display results */
1091 for (i
= 0; i
< num_names
; i
++)
1092 printf("%s\n", names
[i
]);
1099 * List a user's groups from a remote RPC server
1101 * @param argc Standard main() style argc
1102 * @param argv Standard main() style argv. Initial components are already
1105 * @return A shell status integer (0 for success)
1108 static int rpc_user_info(int argc
, const char **argv
)
1110 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
1115 * List users on a remote RPC server
1117 * All parameters are provided by the run_rpc_command function, except for
1118 * argc, argv which are passes through.
1120 * @param domain_sid The domain sid acquired from the remote server
1121 * @param cli A cli_state connected to the server.
1122 * @param mem_ctx Talloc context, destoyed on completion of the function.
1123 * @param argc Standard main() style argc
1124 * @param argv Standard main() style argv. Initial components are already
1127 * @return Normal NTSTATUS return.
1130 static NTSTATUS
rpc_user_list_internals(const DOM_SID
*domain_sid
,
1131 const char *domain_name
,
1132 struct cli_state
*cli
,
1133 struct rpc_pipe_client
*pipe_hnd
,
1134 TALLOC_CTX
*mem_ctx
,
1138 POLICY_HND connect_pol
, domain_pol
;
1139 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1140 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
1141 SAM_DISPINFO_CTR ctr
;
1142 SAM_DISPINFO_1 info1
;
1144 /* Get sam policy handle */
1146 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1148 if (!NT_STATUS_IS_OK(result
)) {
1152 /* Get domain policy handle */
1154 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1155 MAXIMUM_ALLOWED_ACCESS
,
1156 domain_sid
, &domain_pol
);
1157 if (!NT_STATUS_IS_OK(result
)) {
1161 /* Query domain users */
1164 ctr
.sam
.info1
= &info1
;
1165 if (opt_long_list_entries
)
1166 d_printf("\nUser name Comment"\
1167 "\n-----------------------------\n");
1170 uint32 max_entries
, max_size
;
1172 get_query_dispinfo_params(
1173 loop_count
, &max_entries
, &max_size
);
1175 result
= rpccli_samr_query_dispinfo(pipe_hnd
, mem_ctx
, &domain_pol
,
1176 &start_idx
, 1, &num_entries
,
1177 max_entries
, max_size
, &ctr
);
1180 for (i
= 0; i
< num_entries
; i
++) {
1181 unistr2_to_ascii(user
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_name
, sizeof(user
)-1);
1182 if (opt_long_list_entries
)
1183 unistr2_to_ascii(desc
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_desc
, sizeof(desc
)-1);
1185 if (opt_long_list_entries
)
1186 printf("%-21.21s %s\n", user
, desc
);
1188 printf("%s\n", user
);
1190 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1197 * 'net rpc user' entrypoint.
1198 * @param argc Standard main() style argc
1199 * @param argc Standard main() style argv. Initial components are already
1203 int net_rpc_user(int argc
, const char **argv
)
1205 struct functable func
[] = {
1206 {"add", rpc_user_add
},
1207 {"info", rpc_user_info
},
1208 {"delete", rpc_user_delete
},
1209 {"password", rpc_user_password
},
1210 {"rename", rpc_user_rename
},
1215 return run_rpc_command(NULL
,PI_SAMR
, 0,
1216 rpc_user_list_internals
,
1220 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1223 static NTSTATUS
rpc_sh_user_list(TALLOC_CTX
*mem_ctx
,
1224 struct rpc_sh_ctx
*ctx
,
1225 struct rpc_pipe_client
*pipe_hnd
,
1226 int argc
, const char **argv
)
1228 return rpc_user_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
1229 ctx
->cli
, pipe_hnd
, mem_ctx
,
1233 static NTSTATUS
rpc_sh_user_info(TALLOC_CTX
*mem_ctx
,
1234 struct rpc_sh_ctx
*ctx
,
1235 struct rpc_pipe_client
*pipe_hnd
,
1236 int argc
, const char **argv
)
1238 return rpc_user_info_internals(ctx
->domain_sid
, ctx
->domain_name
,
1239 ctx
->cli
, pipe_hnd
, mem_ctx
,
1243 static NTSTATUS
rpc_sh_handle_user(TALLOC_CTX
*mem_ctx
,
1244 struct rpc_sh_ctx
*ctx
,
1245 struct rpc_pipe_client
*pipe_hnd
,
1246 int argc
, const char **argv
,
1248 TALLOC_CTX
*mem_ctx
,
1249 struct rpc_sh_ctx
*ctx
,
1250 struct rpc_pipe_client
*pipe_hnd
,
1251 const POLICY_HND
*user_hnd
,
1252 int argc
, const char **argv
))
1255 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1256 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1259 enum SID_NAME_USE type
;
1262 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1263 return NT_STATUS_INVALID_PARAMETER
;
1266 ZERO_STRUCT(connect_pol
);
1267 ZERO_STRUCT(domain_pol
);
1268 ZERO_STRUCT(user_pol
);
1270 result
= net_rpc_lookup_name(mem_ctx
, pipe_hnd
->cli
, argv
[0],
1271 NULL
, NULL
, &sid
, &type
);
1272 if (!NT_STATUS_IS_OK(result
)) {
1273 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1278 if (type
!= SID_NAME_USER
) {
1279 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1280 sid_type_lookup(type
));
1281 result
= NT_STATUS_NO_SUCH_USER
;
1285 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1286 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1287 result
= NT_STATUS_NO_SUCH_USER
;
1291 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
,
1292 MAXIMUM_ALLOWED_ACCESS
, &connect_pol
);
1293 if (!NT_STATUS_IS_OK(result
)) {
1297 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1298 MAXIMUM_ALLOWED_ACCESS
,
1299 ctx
->domain_sid
, &domain_pol
);
1300 if (!NT_STATUS_IS_OK(result
)) {
1304 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1305 MAXIMUM_ALLOWED_ACCESS
,
1307 if (!NT_STATUS_IS_OK(result
)) {
1311 result
= fn(mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1314 if (is_valid_policy_hnd(&user_pol
)) {
1315 rpccli_samr_close(pipe_hnd
, mem_ctx
, &user_pol
);
1317 if (is_valid_policy_hnd(&domain_pol
)) {
1318 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
1320 if (is_valid_policy_hnd(&connect_pol
)) {
1321 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
1326 static NTSTATUS
rpc_sh_user_show_internals(TALLOC_CTX
*mem_ctx
,
1327 struct rpc_sh_ctx
*ctx
,
1328 struct rpc_pipe_client
*pipe_hnd
,
1329 const POLICY_HND
*user_hnd
,
1330 int argc
, const char **argv
)
1333 SAM_USERINFO_CTR
*ctr
;
1334 SAM_USER_INFO_21
*info
;
1337 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1338 return NT_STATUS_INVALID_PARAMETER
;
1341 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1343 if (!NT_STATUS_IS_OK(result
)) {
1347 info
= ctr
->info
.id21
;
1349 d_printf("user rid: %d, group rid: %d\n", info
->user_rid
,
1355 static NTSTATUS
rpc_sh_user_show(TALLOC_CTX
*mem_ctx
,
1356 struct rpc_sh_ctx
*ctx
,
1357 struct rpc_pipe_client
*pipe_hnd
,
1358 int argc
, const char **argv
)
1360 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1361 rpc_sh_user_show_internals
);
1364 #define FETCHSTR(name, rec) \
1365 do { if (strequal(ctx->thiscmd, name)) { \
1366 oldval = rpcstr_pull_unistr2_talloc(mem_ctx, &usr->uni_##rec); } \
1369 #define SETSTR(name, rec, flag) \
1370 do { if (strequal(ctx->thiscmd, name)) { \
1371 init_unistr2(&usr->uni_##rec, argv[0], STR_TERMINATE); \
1372 init_uni_hdr(&usr->hdr_##rec, &usr->uni_##rec); \
1373 usr->fields_present |= ACCT_##flag; } \
1376 static NTSTATUS
rpc_sh_user_str_edit_internals(TALLOC_CTX
*mem_ctx
,
1377 struct rpc_sh_ctx
*ctx
,
1378 struct rpc_pipe_client
*pipe_hnd
,
1379 const POLICY_HND
*user_hnd
,
1380 int argc
, const char **argv
)
1383 SAM_USERINFO_CTR
*ctr
;
1384 SAM_USER_INFO_21
*usr
;
1385 const char *username
;
1386 const char *oldval
= "";
1389 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1391 return NT_STATUS_INVALID_PARAMETER
;
1394 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1396 if (!NT_STATUS_IS_OK(result
)) {
1400 usr
= ctr
->info
.id21
;
1402 username
= rpcstr_pull_unistr2_talloc(mem_ctx
, &usr
->uni_user_name
);
1404 FETCHSTR("fullname", full_name
);
1405 FETCHSTR("homedir", home_dir
);
1406 FETCHSTR("homedrive", dir_drive
);
1407 FETCHSTR("logonscript", logon_script
);
1408 FETCHSTR("profilepath", profile_path
);
1409 FETCHSTR("description", acct_desc
);
1412 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1418 if (strcmp(argv
[0], "NULL") == 0) {
1422 SETSTR("fullname", full_name
, FULL_NAME
);
1423 SETSTR("homedir", home_dir
, HOME_DIR
);
1424 SETSTR("homedrive", dir_drive
, HOME_DRIVE
);
1425 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1426 SETSTR("profilepath", profile_path
, PROFILE
);
1427 SETSTR("description", acct_desc
, DESCRIPTION
);
1429 result
= rpccli_samr_set_userinfo2(
1430 pipe_hnd
, mem_ctx
, user_hnd
, 21,
1431 &pipe_hnd
->cli
->user_session_key
, ctr
);
1433 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1434 ctx
->thiscmd
, oldval
, argv
[0]);
1441 #define HANDLEFLG(name, rec) \
1442 do { if (strequal(ctx->thiscmd, name)) { \
1443 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1445 newflags = oldflags | ACB_##rec; \
1447 newflags = oldflags & ~ACB_##rec; \
1450 static NTSTATUS
rpc_sh_user_str_edit(TALLOC_CTX
*mem_ctx
,
1451 struct rpc_sh_ctx
*ctx
,
1452 struct rpc_pipe_client
*pipe_hnd
,
1453 int argc
, const char **argv
)
1455 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1456 rpc_sh_user_str_edit_internals
);
1459 static NTSTATUS
rpc_sh_user_flag_edit_internals(TALLOC_CTX
*mem_ctx
,
1460 struct rpc_sh_ctx
*ctx
,
1461 struct rpc_pipe_client
*pipe_hnd
,
1462 const POLICY_HND
*user_hnd
,
1463 int argc
, const char **argv
)
1466 SAM_USERINFO_CTR
*ctr
;
1467 SAM_USER_INFO_21
*usr
;
1468 const char *username
;
1469 const char *oldval
= "unknown";
1470 uint32 oldflags
, newflags
;
1474 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1475 !strequal(argv
[0], "no"))) {
1476 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1478 return NT_STATUS_INVALID_PARAMETER
;
1481 newval
= strequal(argv
[0], "yes");
1483 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1485 if (!NT_STATUS_IS_OK(result
)) {
1489 usr
= ctr
->info
.id21
;
1491 username
= rpcstr_pull_unistr2_talloc(mem_ctx
, &usr
->uni_user_name
);
1492 oldflags
= usr
->acb_info
;
1493 newflags
= usr
->acb_info
;
1495 HANDLEFLG("disabled", DISABLED
);
1496 HANDLEFLG("pwnotreq", PWNOTREQ
);
1497 HANDLEFLG("autolock", AUTOLOCK
);
1498 HANDLEFLG("pwnoexp", PWNOEXP
);
1501 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1507 usr
->acb_info
= newflags
;
1508 usr
->fields_present
= ACCT_FLAGS
;
1510 result
= rpccli_samr_set_userinfo2(
1511 pipe_hnd
, mem_ctx
, user_hnd
, 21,
1512 &pipe_hnd
->cli
->user_session_key
, ctr
);
1514 if (NT_STATUS_IS_OK(result
)) {
1515 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1516 ctx
->thiscmd
, oldval
, argv
[0]);
1524 static NTSTATUS
rpc_sh_user_flag_edit(TALLOC_CTX
*mem_ctx
,
1525 struct rpc_sh_ctx
*ctx
,
1526 struct rpc_pipe_client
*pipe_hnd
,
1527 int argc
, const char **argv
)
1529 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1530 rpc_sh_user_flag_edit_internals
);
1533 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(TALLOC_CTX
*mem_ctx
,
1534 struct rpc_sh_ctx
*ctx
)
1536 static struct rpc_sh_cmd cmds
[] = {
1538 { "fullname", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1539 "Show/Set a user's full name" },
1541 { "homedir", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1542 "Show/Set a user's home directory" },
1544 { "homedrive", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1545 "Show/Set a user's home drive" },
1547 { "logonscript", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1548 "Show/Set a user's logon script" },
1550 { "profilepath", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1551 "Show/Set a user's profile path" },
1553 { "description", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1554 "Show/Set a user's description" },
1556 { "disabled", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1557 "Show/Set whether a user is disabled" },
1559 { "autolock", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1560 "Show/Set whether a user locked out" },
1562 { "pwnotreq", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1563 "Show/Set whether a user does not need a password" },
1565 { "pwnoexp", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1566 "Show/Set whether a user's password does not expire" },
1568 { NULL
, NULL
, 0, NULL
, NULL
}
1574 struct rpc_sh_cmd
*net_rpc_user_cmds(TALLOC_CTX
*mem_ctx
,
1575 struct rpc_sh_ctx
*ctx
)
1577 static struct rpc_sh_cmd cmds
[] = {
1579 { "list", NULL
, PI_SAMR
, rpc_sh_user_list
,
1580 "List available users" },
1582 { "info", NULL
, PI_SAMR
, rpc_sh_user_info
,
1583 "List the domain groups a user is member of" },
1585 { "show", NULL
, PI_SAMR
, rpc_sh_user_show
,
1586 "Show info about a user" },
1588 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1589 "Show/Modify a user's fields" },
1591 { NULL
, NULL
, 0, NULL
, NULL
}
1597 /****************************************************************************/
1600 * Basic usage function for 'net rpc group'
1601 * @param argc Standard main() style argc.
1602 * @param argv Standard main() style argv. Initial components are already
1606 static int rpc_group_usage(int argc
, const char **argv
)
1608 return net_help_group(argc
, argv
);
1612 * Delete group on a remote RPC server
1614 * All parameters are provided by the run_rpc_command function, except for
1615 * argc, argv which are passes through.
1617 * @param domain_sid The domain sid acquired from the remote server
1618 * @param cli A cli_state connected to the server.
1619 * @param mem_ctx Talloc context, destoyed on completion of the function.
1620 * @param argc Standard main() style argc
1621 * @param argv Standard main() style argv. Initial components are already
1624 * @return Normal NTSTATUS return.
1627 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1628 const char *domain_name
,
1629 struct cli_state
*cli
,
1630 struct rpc_pipe_client
*pipe_hnd
,
1631 TALLOC_CTX
*mem_ctx
,
1635 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1636 BOOL group_is_primary
= False
;
1637 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1639 uint32
*group_rids
, num_rids
, *name_types
, num_members
,
1640 *group_attrs
, group_rid
;
1641 uint32 flags
= 0x000003e8; /* Unknown */
1644 /* DOM_GID *user_gids; */
1645 SAM_USERINFO_CTR
*user_ctr
;
1649 d_printf("specify group\n");
1650 rpc_group_usage(argc
,argv
);
1651 return NT_STATUS_OK
; /* ok? */
1654 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1657 if (!NT_STATUS_IS_OK(result
)) {
1658 d_fprintf(stderr
, "Request samr_connect failed\n");
1662 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1663 MAXIMUM_ALLOWED_ACCESS
,
1664 domain_sid
, &domain_pol
);
1666 if (!NT_STATUS_IS_OK(result
)) {
1667 d_fprintf(stderr
, "Request open_domain failed\n");
1671 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
1673 &num_rids
, &group_rids
,
1676 if (!NT_STATUS_IS_OK(result
)) {
1677 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1681 switch (name_types
[0])
1683 case SID_NAME_DOM_GRP
:
1684 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
1685 MAXIMUM_ALLOWED_ACCESS
,
1686 group_rids
[0], &group_pol
);
1687 if (!NT_STATUS_IS_OK(result
)) {
1688 d_fprintf(stderr
, "Request open_group failed");
1692 group_rid
= group_rids
[0];
1694 result
= rpccli_samr_query_groupmem(pipe_hnd
, mem_ctx
, &group_pol
,
1695 &num_members
, &group_rids
,
1698 if (!NT_STATUS_IS_OK(result
)) {
1699 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1704 d_printf("Domain Group %s (rid: %d) has %d members\n",
1705 argv
[0],group_rid
,num_members
);
1708 /* Check if group is anyone's primary group */
1709 for (i
= 0; i
< num_members
; i
++)
1711 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1712 MAXIMUM_ALLOWED_ACCESS
,
1713 group_rids
[i
], &user_pol
);
1715 if (!NT_STATUS_IS_OK(result
)) {
1716 d_fprintf(stderr
, "Unable to open group member %d\n",group_rids
[i
]);
1720 ZERO_STRUCT(user_ctr
);
1722 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
1725 if (!NT_STATUS_IS_OK(result
)) {
1726 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",group_rids
[i
]);
1730 if (user_ctr
->info
.id21
->group_rid
== group_rid
) {
1731 unistr2_to_ascii(temp
, &(user_ctr
->info
.id21
)->uni_user_name
,
1734 d_printf("Group is primary group of %s\n",temp
);
1735 group_is_primary
= True
;
1738 rpccli_samr_close(pipe_hnd
, mem_ctx
, &user_pol
);
1741 if (group_is_primary
) {
1742 d_fprintf(stderr
, "Unable to delete group because some "
1743 "of it's members have it as primary group\n");
1744 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1748 /* remove all group members */
1749 for (i
= 0; i
< num_members
; i
++)
1752 d_printf("Remove group member %d...",group_rids
[i
]);
1753 result
= rpccli_samr_del_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, group_rids
[i
]);
1755 if (NT_STATUS_IS_OK(result
)) {
1760 d_printf("failed\n");
1765 result
= rpccli_samr_delete_dom_group(pipe_hnd
, mem_ctx
, &group_pol
);
1768 /* removing a local group is easier... */
1769 case SID_NAME_ALIAS
:
1770 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
1771 MAXIMUM_ALLOWED_ACCESS
,
1772 group_rids
[0], &group_pol
);
1774 if (!NT_STATUS_IS_OK(result
)) {
1775 d_fprintf(stderr
, "Request open_alias failed\n");
1779 result
= rpccli_samr_delete_dom_alias(pipe_hnd
, mem_ctx
, &group_pol
);
1782 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1783 argv
[0],sid_type_lookup(name_types
[0]));
1784 result
= NT_STATUS_UNSUCCESSFUL
;
1789 if (NT_STATUS_IS_OK(result
)) {
1791 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
[0]),argv
[0]);
1793 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1794 get_friendly_nt_error_msg(result
));
1802 static int rpc_group_delete(int argc
, const char **argv
)
1804 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1808 static NTSTATUS
rpc_group_add_internals(const DOM_SID
*domain_sid
,
1809 const char *domain_name
,
1810 struct cli_state
*cli
,
1811 struct rpc_pipe_client
*pipe_hnd
,
1812 TALLOC_CTX
*mem_ctx
,
1816 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1817 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1818 GROUP_INFO_CTR group_info
;
1821 d_printf("Group name must be specified\n");
1822 rpc_group_usage(argc
, argv
);
1823 return NT_STATUS_OK
;
1826 /* Get sam policy handle */
1828 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1830 if (!NT_STATUS_IS_OK(result
)) goto done
;
1832 /* Get domain policy handle */
1834 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1835 MAXIMUM_ALLOWED_ACCESS
,
1836 domain_sid
, &domain_pol
);
1837 if (!NT_STATUS_IS_OK(result
)) goto done
;
1839 /* Create the group */
1841 result
= rpccli_samr_create_dom_group(pipe_hnd
, mem_ctx
, &domain_pol
,
1842 argv
[0], MAXIMUM_ALLOWED_ACCESS
,
1844 if (!NT_STATUS_IS_OK(result
)) goto done
;
1846 if (strlen(opt_comment
) == 0) goto done
;
1848 /* We've got a comment to set */
1850 group_info
.switch_value1
= 4;
1851 init_samr_group_info4(&group_info
.group
.info4
, opt_comment
);
1853 result
= rpccli_samr_set_groupinfo(pipe_hnd
, mem_ctx
, &group_pol
, &group_info
);
1854 if (!NT_STATUS_IS_OK(result
)) goto done
;
1857 if (NT_STATUS_IS_OK(result
))
1858 DEBUG(5, ("add group succeeded\n"));
1860 d_fprintf(stderr
, "add group failed: %s\n", nt_errstr(result
));
1865 static NTSTATUS
rpc_alias_add_internals(const DOM_SID
*domain_sid
,
1866 const char *domain_name
,
1867 struct cli_state
*cli
,
1868 struct rpc_pipe_client
*pipe_hnd
,
1869 TALLOC_CTX
*mem_ctx
,
1873 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
1874 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1875 ALIAS_INFO_CTR alias_info
;
1878 d_printf("Alias name must be specified\n");
1879 rpc_group_usage(argc
, argv
);
1880 return NT_STATUS_OK
;
1883 /* Get sam policy handle */
1885 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1887 if (!NT_STATUS_IS_OK(result
)) goto done
;
1889 /* Get domain policy handle */
1891 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1892 MAXIMUM_ALLOWED_ACCESS
,
1893 domain_sid
, &domain_pol
);
1894 if (!NT_STATUS_IS_OK(result
)) goto done
;
1896 /* Create the group */
1898 result
= rpccli_samr_create_dom_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
1899 argv
[0], &alias_pol
);
1900 if (!NT_STATUS_IS_OK(result
)) goto done
;
1902 if (strlen(opt_comment
) == 0) goto done
;
1904 /* We've got a comment to set */
1906 alias_info
.level
= 3;
1907 init_samr_alias_info3(&alias_info
.alias
.info3
, opt_comment
);
1909 result
= rpccli_samr_set_aliasinfo(pipe_hnd
, mem_ctx
, &alias_pol
, &alias_info
);
1910 if (!NT_STATUS_IS_OK(result
)) goto done
;
1913 if (NT_STATUS_IS_OK(result
))
1914 DEBUG(5, ("add alias succeeded\n"));
1916 d_fprintf(stderr
, "add alias failed: %s\n", nt_errstr(result
));
1921 static int rpc_group_add(int argc
, const char **argv
)
1924 return run_rpc_command(NULL
, PI_SAMR
, 0,
1925 rpc_alias_add_internals
,
1928 return run_rpc_command(NULL
, PI_SAMR
, 0,
1929 rpc_group_add_internals
,
1933 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1934 TALLOC_CTX
*mem_ctx
,
1937 enum SID_NAME_USE
*type
)
1939 DOM_SID
*sids
= NULL
;
1940 uint32
*types
= NULL
;
1941 struct rpc_pipe_client
*pipe_hnd
;
1943 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1945 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
1950 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, False
,
1951 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1953 if (!NT_STATUS_IS_OK(result
)) {
1957 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1958 &name
, NULL
, &sids
, &types
);
1960 if (NT_STATUS_IS_OK(result
)) {
1961 sid_copy(sid
, &sids
[0]);
1965 rpccli_lsa_close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1969 cli_rpc_pipe_close(pipe_hnd
);
1972 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1974 /* Try as S-1-5-whatever */
1978 if (string_to_sid(&tmp_sid
, name
)) {
1979 sid_copy(sid
, &tmp_sid
);
1980 *type
= SID_NAME_UNKNOWN
;
1981 result
= NT_STATUS_OK
;
1988 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1989 TALLOC_CTX
*mem_ctx
,
1990 const DOM_SID
*group_sid
,
1993 POLICY_HND connect_pol
, domain_pol
;
1996 POLICY_HND group_pol
;
1999 uint32
*rids
= NULL
;
2000 uint32
*rid_types
= NULL
;
2004 sid_copy(&sid
, group_sid
);
2006 if (!sid_split_rid(&sid
, &group_rid
)) {
2007 return NT_STATUS_UNSUCCESSFUL
;
2010 /* Get sam policy handle */
2011 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2013 if (!NT_STATUS_IS_OK(result
)) {
2017 /* Get domain policy handle */
2018 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2019 MAXIMUM_ALLOWED_ACCESS
,
2021 if (!NT_STATUS_IS_OK(result
)) {
2025 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2027 &num_rids
, &rids
, &rid_types
);
2029 if (!NT_STATUS_IS_OK(result
)) {
2030 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2034 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2035 MAXIMUM_ALLOWED_ACCESS
,
2036 group_rid
, &group_pol
);
2038 if (!NT_STATUS_IS_OK(result
)) {
2042 result
= rpccli_samr_add_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, rids
[0]);
2045 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2049 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2050 TALLOC_CTX
*mem_ctx
,
2051 const DOM_SID
*alias_sid
,
2054 POLICY_HND connect_pol
, domain_pol
;
2057 POLICY_HND alias_pol
;
2060 enum SID_NAME_USE member_type
;
2064 sid_copy(&sid
, alias_sid
);
2066 if (!sid_split_rid(&sid
, &alias_rid
)) {
2067 return NT_STATUS_UNSUCCESSFUL
;
2070 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2071 &member_sid
, &member_type
);
2073 if (!NT_STATUS_IS_OK(result
)) {
2074 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2078 /* Get sam policy handle */
2079 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2081 if (!NT_STATUS_IS_OK(result
)) {
2085 /* Get domain policy handle */
2086 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2087 MAXIMUM_ALLOWED_ACCESS
,
2089 if (!NT_STATUS_IS_OK(result
)) {
2093 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
2094 MAXIMUM_ALLOWED_ACCESS
,
2095 alias_rid
, &alias_pol
);
2097 if (!NT_STATUS_IS_OK(result
)) {
2101 result
= rpccli_samr_add_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
, &member_sid
);
2103 if (!NT_STATUS_IS_OK(result
)) {
2108 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2112 static NTSTATUS
rpc_group_addmem_internals(const DOM_SID
*domain_sid
,
2113 const char *domain_name
,
2114 struct cli_state
*cli
,
2115 struct rpc_pipe_client
*pipe_hnd
,
2116 TALLOC_CTX
*mem_ctx
,
2121 enum SID_NAME_USE group_type
;
2124 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
2125 return NT_STATUS_UNSUCCESSFUL
;
2128 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2129 &group_sid
, &group_type
))) {
2130 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2131 return NT_STATUS_UNSUCCESSFUL
;
2134 if (group_type
== SID_NAME_DOM_GRP
) {
2135 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2136 &group_sid
, argv
[1]);
2138 if (!NT_STATUS_IS_OK(result
)) {
2139 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2140 argv
[1], argv
[0], nt_errstr(result
));
2145 if (group_type
== SID_NAME_ALIAS
) {
2146 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
2147 &group_sid
, argv
[1]);
2149 if (!NT_STATUS_IS_OK(result
)) {
2150 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2151 argv
[1], argv
[0], nt_errstr(result
));
2156 d_fprintf(stderr
, "Can only add members to global or local groups "
2157 "which %s is not\n", argv
[0]);
2159 return NT_STATUS_UNSUCCESSFUL
;
2162 static int rpc_group_addmem(int argc
, const char **argv
)
2164 return run_rpc_command(NULL
, PI_SAMR
, 0,
2165 rpc_group_addmem_internals
,
2169 static NTSTATUS
rpc_del_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2170 TALLOC_CTX
*mem_ctx
,
2171 const DOM_SID
*group_sid
,
2174 POLICY_HND connect_pol
, domain_pol
;
2177 POLICY_HND group_pol
;
2180 uint32
*rids
= NULL
;
2181 uint32
*rid_types
= NULL
;
2185 sid_copy(&sid
, group_sid
);
2187 if (!sid_split_rid(&sid
, &group_rid
))
2188 return NT_STATUS_UNSUCCESSFUL
;
2190 /* Get sam policy handle */
2191 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2193 if (!NT_STATUS_IS_OK(result
))
2196 /* Get domain policy handle */
2197 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2198 MAXIMUM_ALLOWED_ACCESS
,
2200 if (!NT_STATUS_IS_OK(result
))
2203 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2205 &num_rids
, &rids
, &rid_types
);
2207 if (!NT_STATUS_IS_OK(result
)) {
2208 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2212 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2213 MAXIMUM_ALLOWED_ACCESS
,
2214 group_rid
, &group_pol
);
2216 if (!NT_STATUS_IS_OK(result
))
2219 result
= rpccli_samr_del_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, rids
[0]);
2222 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2226 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2227 TALLOC_CTX
*mem_ctx
,
2228 const DOM_SID
*alias_sid
,
2231 POLICY_HND connect_pol
, domain_pol
;
2234 POLICY_HND alias_pol
;
2237 enum SID_NAME_USE member_type
;
2241 sid_copy(&sid
, alias_sid
);
2243 if (!sid_split_rid(&sid
, &alias_rid
))
2244 return NT_STATUS_UNSUCCESSFUL
;
2246 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2247 &member_sid
, &member_type
);
2249 if (!NT_STATUS_IS_OK(result
)) {
2250 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2254 /* Get sam policy handle */
2255 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2257 if (!NT_STATUS_IS_OK(result
)) {
2261 /* Get domain policy handle */
2262 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2263 MAXIMUM_ALLOWED_ACCESS
,
2265 if (!NT_STATUS_IS_OK(result
)) {
2269 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
2270 MAXIMUM_ALLOWED_ACCESS
,
2271 alias_rid
, &alias_pol
);
2273 if (!NT_STATUS_IS_OK(result
))
2276 result
= rpccli_samr_del_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
, &member_sid
);
2278 if (!NT_STATUS_IS_OK(result
))
2282 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2286 static NTSTATUS
rpc_group_delmem_internals(const DOM_SID
*domain_sid
,
2287 const char *domain_name
,
2288 struct cli_state
*cli
,
2289 struct rpc_pipe_client
*pipe_hnd
,
2290 TALLOC_CTX
*mem_ctx
,
2295 enum SID_NAME_USE group_type
;
2298 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
2299 return NT_STATUS_UNSUCCESSFUL
;
2302 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2303 &group_sid
, &group_type
))) {
2304 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2305 return NT_STATUS_UNSUCCESSFUL
;
2308 if (group_type
== SID_NAME_DOM_GRP
) {
2309 NTSTATUS result
= rpc_del_groupmem(pipe_hnd
, mem_ctx
,
2310 &group_sid
, argv
[1]);
2312 if (!NT_STATUS_IS_OK(result
)) {
2313 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2314 argv
[1], argv
[0], nt_errstr(result
));
2319 if (group_type
== SID_NAME_ALIAS
) {
2320 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2321 &group_sid
, argv
[1]);
2323 if (!NT_STATUS_IS_OK(result
)) {
2324 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2325 argv
[1], argv
[0], nt_errstr(result
));
2330 d_fprintf(stderr
, "Can only delete members from global or local groups "
2331 "which %s is not\n", argv
[0]);
2333 return NT_STATUS_UNSUCCESSFUL
;
2336 static int rpc_group_delmem(int argc
, const char **argv
)
2338 return run_rpc_command(NULL
, PI_SAMR
, 0,
2339 rpc_group_delmem_internals
,
2344 * List groups on a remote RPC server
2346 * All parameters are provided by the run_rpc_command function, except for
2347 * argc, argv which are passes through.
2349 * @param domain_sid The domain sid acquired from the remote server
2350 * @param cli A cli_state connected to the server.
2351 * @param mem_ctx Talloc context, destoyed on completion of the function.
2352 * @param argc Standard main() style argc
2353 * @param argv Standard main() style argv. Initial components are already
2356 * @return Normal NTSTATUS return.
2359 static NTSTATUS
rpc_group_list_internals(const DOM_SID
*domain_sid
,
2360 const char *domain_name
,
2361 struct cli_state
*cli
,
2362 struct rpc_pipe_client
*pipe_hnd
,
2363 TALLOC_CTX
*mem_ctx
,
2367 POLICY_HND connect_pol
, domain_pol
;
2368 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2369 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2370 struct acct_info
*groups
;
2371 BOOL global
= False
;
2373 BOOL builtin
= False
;
2381 for (i
=0; i
<argc
; i
++) {
2382 if (strequal(argv
[i
], "global"))
2385 if (strequal(argv
[i
], "local"))
2388 if (strequal(argv
[i
], "builtin"))
2392 /* Get sam policy handle */
2394 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2396 if (!NT_STATUS_IS_OK(result
)) {
2400 /* Get domain policy handle */
2402 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2403 MAXIMUM_ALLOWED_ACCESS
,
2404 domain_sid
, &domain_pol
);
2405 if (!NT_STATUS_IS_OK(result
)) {
2409 /* Query domain groups */
2410 if (opt_long_list_entries
)
2411 d_printf("\nGroup name Comment"\
2412 "\n-----------------------------\n");
2414 SAM_DISPINFO_CTR ctr
;
2415 SAM_DISPINFO_3 info3
;
2420 ctr
.sam
.info3
= &info3
;
2424 get_query_dispinfo_params(
2425 loop_count
, &max_entries
, &max_size
);
2427 result
= rpccli_samr_query_dispinfo(pipe_hnd
, mem_ctx
, &domain_pol
,
2428 &start_idx
, 3, &num_entries
,
2429 max_entries
, max_size
, &ctr
);
2431 if (!NT_STATUS_IS_OK(result
) &&
2432 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2435 for (i
= 0; i
< num_entries
; i
++) {
2437 fstring group
, desc
;
2439 unistr2_to_ascii(group
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_name
, sizeof(group
)-1);
2440 unistr2_to_ascii(desc
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_desc
, sizeof(desc
)-1);
2442 if (opt_long_list_entries
)
2443 printf("%-21.21s %-50.50s\n",
2446 printf("%s\n", group
);
2448 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2449 /* query domain aliases */
2454 /* The max_size field in cli_samr_enum_als_groups is more like
2455 * an account_control field with indiviual bits what to
2456 * retrieve. Set this to 0xffff as NT4 usrmgr.exe does to get
2457 * everything. I'm too lazy (sorry) to get this through to
2458 * rpc_parse/ etc. Volker */
2460 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
2462 &groups
, &num_entries
);
2464 if (!NT_STATUS_IS_OK(result
) &&
2465 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2468 for (i
= 0; i
< num_entries
; i
++) {
2470 char *description
= NULL
;
2472 if (opt_long_list_entries
) {
2474 POLICY_HND alias_pol
;
2477 if ((NT_STATUS_IS_OK(rpccli_samr_open_alias(pipe_hnd
, mem_ctx
,
2482 (NT_STATUS_IS_OK(rpccli_samr_query_alias_info(pipe_hnd
, mem_ctx
,
2485 (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd
, mem_ctx
,
2487 description
= unistr2_tdup(mem_ctx
,
2488 ctr
.alias
.info3
.description
.string
);
2492 if (description
!= NULL
) {
2493 printf("%-21.21s %-50.50s\n",
2494 groups
[i
].acct_name
,
2497 printf("%s\n", groups
[i
].acct_name
);
2500 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2501 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
2502 /* Get builtin policy handle */
2504 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2505 MAXIMUM_ALLOWED_ACCESS
,
2506 &global_sid_Builtin
, &domain_pol
);
2507 if (!NT_STATUS_IS_OK(result
)) {
2510 /* query builtin aliases */
2513 if (!builtin
) break;
2515 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
2516 &start_idx
, max_entries
,
2517 &groups
, &num_entries
);
2519 if (!NT_STATUS_IS_OK(result
) &&
2520 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2523 for (i
= 0; i
< num_entries
; i
++) {
2525 char *description
= NULL
;
2527 if (opt_long_list_entries
) {
2529 POLICY_HND alias_pol
;
2532 if ((NT_STATUS_IS_OK(rpccli_samr_open_alias(pipe_hnd
, mem_ctx
,
2537 (NT_STATUS_IS_OK(rpccli_samr_query_alias_info(pipe_hnd
, mem_ctx
,
2540 (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd
, mem_ctx
,
2542 description
= unistr2_tdup(mem_ctx
,
2543 ctr
.alias
.info3
.description
.string
);
2547 if (description
!= NULL
) {
2548 printf("%-21.21s %-50.50s\n",
2549 groups
[i
].acct_name
,
2552 printf("%s\n", groups
[i
].acct_name
);
2555 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2561 static int rpc_group_list(int argc
, const char **argv
)
2563 return run_rpc_command(NULL
, PI_SAMR
, 0,
2564 rpc_group_list_internals
,
2568 static NTSTATUS
rpc_list_group_members(struct rpc_pipe_client
*pipe_hnd
,
2569 TALLOC_CTX
*mem_ctx
,
2570 const char *domain_name
,
2571 const DOM_SID
*domain_sid
,
2572 POLICY_HND
*domain_pol
,
2576 POLICY_HND group_pol
;
2577 uint32 num_members
, *group_rids
, *group_attrs
;
2584 sid_to_string(sid_str
, domain_sid
);
2586 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, domain_pol
,
2587 MAXIMUM_ALLOWED_ACCESS
,
2590 if (!NT_STATUS_IS_OK(result
))
2593 result
= rpccli_samr_query_groupmem(pipe_hnd
, mem_ctx
, &group_pol
,
2594 &num_members
, &group_rids
,
2597 if (!NT_STATUS_IS_OK(result
))
2600 while (num_members
> 0) {
2601 int this_time
= 512;
2603 if (num_members
< this_time
)
2604 this_time
= num_members
;
2606 result
= rpccli_samr_lookup_rids(pipe_hnd
, mem_ctx
, domain_pol
,
2607 this_time
, group_rids
,
2608 &num_names
, &names
, &name_types
);
2610 if (!NT_STATUS_IS_OK(result
))
2613 /* We only have users as members, but make the output
2614 the same as the output of alias members */
2616 for (i
= 0; i
< this_time
; i
++) {
2618 if (opt_long_list_entries
) {
2619 printf("%s-%d %s\\%s %d\n", sid_str
,
2620 group_rids
[i
], domain_name
, names
[i
],
2623 printf("%s\\%s\n", domain_name
, names
[i
]);
2627 num_members
-= this_time
;
2631 return NT_STATUS_OK
;
2634 static NTSTATUS
rpc_list_alias_members(struct rpc_pipe_client
*pipe_hnd
,
2635 TALLOC_CTX
*mem_ctx
,
2636 POLICY_HND
*domain_pol
,
2640 struct rpc_pipe_client
*lsa_pipe
;
2641 POLICY_HND alias_pol
, lsa_pol
;
2643 DOM_SID
*alias_sids
;
2649 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, domain_pol
,
2650 MAXIMUM_ALLOWED_ACCESS
, rid
, &alias_pol
);
2652 if (!NT_STATUS_IS_OK(result
))
2655 result
= rpccli_samr_query_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
,
2656 &num_members
, &alias_sids
);
2658 if (!NT_STATUS_IS_OK(result
)) {
2659 d_fprintf(stderr
, "Couldn't list alias members\n");
2663 if (num_members
== 0) {
2664 return NT_STATUS_OK
;
2667 lsa_pipe
= cli_rpc_pipe_open_noauth(pipe_hnd
->cli
, PI_LSARPC
, &result
);
2669 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2670 nt_errstr(result
) );
2674 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, True
,
2675 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2677 if (!NT_STATUS_IS_OK(result
)) {
2678 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2679 cli_rpc_pipe_close(lsa_pipe
);
2683 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
, num_members
,
2685 &domains
, &names
, &types
);
2687 if (!NT_STATUS_IS_OK(result
) &&
2688 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2689 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2690 cli_rpc_pipe_close(lsa_pipe
);
2694 for (i
= 0; i
< num_members
; i
++) {
2696 sid_to_string(sid_str
, &alias_sids
[i
]);
2698 if (opt_long_list_entries
) {
2699 printf("%s %s\\%s %d\n", sid_str
,
2700 domains
[i
] ? domains
[i
] : "*unknown*",
2701 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2704 printf("%s\\%s\n", domains
[i
], names
[i
]);
2706 printf("%s\n", sid_str
);
2710 cli_rpc_pipe_close(lsa_pipe
);
2711 return NT_STATUS_OK
;
2714 static NTSTATUS
rpc_group_members_internals(const DOM_SID
*domain_sid
,
2715 const char *domain_name
,
2716 struct cli_state
*cli
,
2717 struct rpc_pipe_client
*pipe_hnd
,
2718 TALLOC_CTX
*mem_ctx
,
2723 POLICY_HND connect_pol
, domain_pol
;
2724 uint32 num_rids
, *rids
, *rid_types
;
2726 /* Get sam policy handle */
2728 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2731 if (!NT_STATUS_IS_OK(result
))
2734 /* Get domain policy handle */
2736 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2737 MAXIMUM_ALLOWED_ACCESS
,
2738 domain_sid
, &domain_pol
);
2740 if (!NT_STATUS_IS_OK(result
))
2743 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2744 1, argv
, &num_rids
, &rids
, &rid_types
);
2746 if (!NT_STATUS_IS_OK(result
)) {
2748 /* Ok, did not find it in the global sam, try with builtin */
2750 DOM_SID sid_Builtin
;
2752 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
2754 string_to_sid(&sid_Builtin
, "S-1-5-32");
2756 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2757 MAXIMUM_ALLOWED_ACCESS
,
2758 &sid_Builtin
, &domain_pol
);
2760 if (!NT_STATUS_IS_OK(result
)) {
2761 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2765 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2769 if (!NT_STATUS_IS_OK(result
)) {
2770 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2775 if (num_rids
!= 1) {
2776 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2780 if (rid_types
[0] == SID_NAME_DOM_GRP
) {
2781 return rpc_list_group_members(pipe_hnd
, mem_ctx
, domain_name
,
2782 domain_sid
, &domain_pol
,
2786 if (rid_types
[0] == SID_NAME_ALIAS
) {
2787 return rpc_list_alias_members(pipe_hnd
, mem_ctx
, &domain_pol
,
2791 return NT_STATUS_NO_SUCH_GROUP
;
2794 static int rpc_group_members(int argc
, const char **argv
)
2797 return rpc_group_usage(argc
, argv
);
2800 return run_rpc_command(NULL
, PI_SAMR
, 0,
2801 rpc_group_members_internals
,
2805 static NTSTATUS
rpc_group_rename_internals(const DOM_SID
*domain_sid
,
2806 const char *domain_name
,
2807 struct cli_state
*cli
,
2808 struct rpc_pipe_client
*pipe_hnd
,
2809 TALLOC_CTX
*mem_ctx
,
2814 POLICY_HND connect_pol
, domain_pol
, group_pol
;
2815 uint32 num_rids
, *rids
, *rid_types
;
2819 d_printf("Usage: 'net rpc group rename group newname'\n");
2820 return NT_STATUS_UNSUCCESSFUL
;
2823 /* Get sam policy handle */
2825 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2828 if (!NT_STATUS_IS_OK(result
))
2831 /* Get domain policy handle */
2833 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2834 MAXIMUM_ALLOWED_ACCESS
,
2835 domain_sid
, &domain_pol
);
2837 if (!NT_STATUS_IS_OK(result
))
2840 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2841 1, argv
, &num_rids
, &rids
, &rid_types
);
2843 if (num_rids
!= 1) {
2844 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2848 if (rid_types
[0] != SID_NAME_DOM_GRP
) {
2849 d_fprintf(stderr
, "Can only rename domain groups\n");
2850 return NT_STATUS_UNSUCCESSFUL
;
2853 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2854 MAXIMUM_ALLOWED_ACCESS
,
2855 rids
[0], &group_pol
);
2857 if (!NT_STATUS_IS_OK(result
))
2862 ctr
.switch_value1
= 2;
2863 init_samr_group_info2(&ctr
.group
.info2
, argv
[1]);
2865 result
= rpccli_samr_set_groupinfo(pipe_hnd
, mem_ctx
, &group_pol
, &ctr
);
2867 if (!NT_STATUS_IS_OK(result
))
2870 return NT_STATUS_NO_SUCH_GROUP
;
2873 static int rpc_group_rename(int argc
, const char **argv
)
2876 return rpc_group_usage(argc
, argv
);
2879 return run_rpc_command(NULL
, PI_SAMR
, 0,
2880 rpc_group_rename_internals
,
2885 * 'net rpc group' entrypoint.
2886 * @param argc Standard main() style argc
2887 * @param argc Standard main() style argv. Initial components are already
2891 int net_rpc_group(int argc
, const char **argv
)
2893 struct functable func
[] = {
2894 {"add", rpc_group_add
},
2895 {"delete", rpc_group_delete
},
2896 {"addmem", rpc_group_addmem
},
2897 {"delmem", rpc_group_delmem
},
2898 {"list", rpc_group_list
},
2899 {"members", rpc_group_members
},
2900 {"rename", rpc_group_rename
},
2905 return run_rpc_command(NULL
, PI_SAMR
, 0,
2906 rpc_group_list_internals
,
2910 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
2913 /****************************************************************************/
2915 static int rpc_share_usage(int argc
, const char **argv
)
2917 return net_help_share(argc
, argv
);
2921 * Add a share on a remote RPC server
2923 * All parameters are provided by the run_rpc_command function, except for
2924 * argc, argv which are passes through.
2926 * @param domain_sid The domain sid acquired from the remote server
2927 * @param cli A cli_state connected to the server.
2928 * @param mem_ctx Talloc context, destoyed on completion of the function.
2929 * @param argc Standard main() style argc
2930 * @param argv Standard main() style argv. Initial components are already
2933 * @return Normal NTSTATUS return.
2935 static NTSTATUS
rpc_share_add_internals(const DOM_SID
*domain_sid
,
2936 const char *domain_name
,
2937 struct cli_state
*cli
,
2938 struct rpc_pipe_client
*pipe_hnd
,
2939 TALLOC_CTX
*mem_ctx
,int argc
,
2943 char *sharename
=talloc_strdup(mem_ctx
, argv
[0]);
2945 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2946 uint32 num_users
=0, perms
=0;
2947 char *password
=NULL
; /* don't allow a share password */
2950 path
= strchr(sharename
, '=');
2952 return NT_STATUS_UNSUCCESSFUL
;
2955 result
= rpccli_srvsvc_net_share_add(pipe_hnd
, mem_ctx
, sharename
, type
,
2956 opt_comment
, perms
, opt_maxusers
,
2957 num_users
, path
, password
,
2959 return werror_to_ntstatus(result
);
2962 static int rpc_share_add(int argc
, const char **argv
)
2964 if ((argc
< 1) || !strchr(argv
[0], '=')) {
2965 DEBUG(1,("Sharename or path not specified on add\n"));
2966 return rpc_share_usage(argc
, argv
);
2968 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2969 rpc_share_add_internals
,
2974 * Delete a share on a remote RPC server
2976 * All parameters are provided by the run_rpc_command function, except for
2977 * argc, argv which are passes through.
2979 * @param domain_sid The domain sid acquired from the remote server
2980 * @param cli A cli_state connected to the server.
2981 * @param mem_ctx Talloc context, destoyed on completion of the function.
2982 * @param argc Standard main() style argc
2983 * @param argv Standard main() style argv. Initial components are already
2986 * @return Normal NTSTATUS return.
2988 static NTSTATUS
rpc_share_del_internals(const DOM_SID
*domain_sid
,
2989 const char *domain_name
,
2990 struct cli_state
*cli
,
2991 struct rpc_pipe_client
*pipe_hnd
,
2992 TALLOC_CTX
*mem_ctx
,
2998 result
= rpccli_srvsvc_net_share_del(pipe_hnd
, mem_ctx
, argv
[0]);
2999 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3003 * Delete a share on a remote RPC server
3005 * @param domain_sid The domain sid acquired from the remote server
3006 * @param argc Standard main() style argc
3007 * @param argv Standard main() style argv. Initial components are already
3010 * @return A shell status integer (0 for success)
3012 static int rpc_share_delete(int argc
, const char **argv
)
3015 DEBUG(1,("Sharename not specified on delete\n"));
3016 return rpc_share_usage(argc
, argv
);
3018 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3019 rpc_share_del_internals
,
3024 * Formatted print of share info
3026 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3029 static void display_share_info_1(SRV_SHARE_INFO_1
*info1
)
3031 fstring netname
= "", remark
= "";
3033 rpcstr_pull_unistr2_fstring(netname
, &info1
->info_1_str
.uni_netname
);
3034 rpcstr_pull_unistr2_fstring(remark
, &info1
->info_1_str
.uni_remark
);
3036 if (opt_long_list_entries
) {
3037 d_printf("%-12s %-8.8s %-50s\n",
3038 netname
, share_type
[info1
->info_1
.type
], remark
);
3040 d_printf("%s\n", netname
);
3045 static WERROR
get_share_info(struct rpc_pipe_client
*pipe_hnd
,
3046 TALLOC_CTX
*mem_ctx
,
3050 SRV_SHARE_INFO_CTR
*ctr
)
3053 SRV_SHARE_INFO info
;
3055 /* no specific share requested, enumerate all */
3059 uint32 preferred_len
= 0xffffffff;
3061 init_enum_hnd(&hnd
, 0);
3063 return rpccli_srvsvc_net_share_enum(pipe_hnd
, mem_ctx
, level
, ctr
,
3064 preferred_len
, &hnd
);
3067 /* request just one share */
3068 result
= rpccli_srvsvc_net_share_get_info(pipe_hnd
, mem_ctx
, argv
[0], level
, &info
);
3070 if (!W_ERROR_IS_OK(result
))
3076 ctr
->info_level
= ctr
->switch_value
= level
;
3077 ctr
->ptr_share_info
= ctr
->ptr_entries
= 1;
3078 ctr
->num_entries
= ctr
->num_entries2
= 1;
3084 SRV_SHARE_INFO_1
*info1
;
3086 ctr
->share
.info1
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_1
, 1);
3087 info1
= ctr
->share
.info1
;
3089 memset(ctr
->share
.info1
, 0, sizeof(SRV_SHARE_INFO_1
));
3091 /* Copy pointer crap */
3093 memcpy(&info1
->info_1
, &info
.share
.info1
.info_1
, sizeof(SH_INFO_1
));
3095 /* Duplicate strings */
3097 s
= unistr2_tdup(mem_ctx
, &info
.share
.info1
.info_1_str
.uni_netname
);
3099 init_unistr2(&info1
->info_1_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3101 s
= unistr2_tdup(mem_ctx
, &info
.share
.info1
.info_1_str
.uni_remark
);
3103 init_unistr2(&info1
->info_1_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3108 SRV_SHARE_INFO_2
*info2
;
3110 ctr
->share
.info2
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_2
, 1);
3111 info2
= ctr
->share
.info2
;
3113 memset(ctr
->share
.info2
, 0, sizeof(SRV_SHARE_INFO_2
));
3115 /* Copy pointer crap */
3117 memcpy(&info2
->info_2
, &info
.share
.info2
.info_2
, sizeof(SH_INFO_2
));
3119 /* Duplicate strings */
3121 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_netname
);
3123 init_unistr2(&info2
->info_2_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3125 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_remark
);
3127 init_unistr2(&info2
->info_2_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3129 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_path
);
3131 init_unistr2(&info2
->info_2_str
.uni_path
, s
, UNI_STR_TERMINATE
);
3133 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_passwd
);
3135 init_unistr2(&info2
->info_2_str
.uni_passwd
, s
, UNI_STR_TERMINATE
);
3140 SRV_SHARE_INFO_502
*info502
;
3142 ctr
->share
.info502
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_502
, 1);
3143 info502
= ctr
->share
.info502
;
3145 memset(ctr
->share
.info502
, 0, sizeof(SRV_SHARE_INFO_502
));
3147 /* Copy pointer crap */
3149 memcpy(&info502
->info_502
, &info
.share
.info502
.info_502
, sizeof(SH_INFO_502
));
3151 /* Duplicate strings */
3153 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_netname
);
3155 init_unistr2(&info502
->info_502_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3157 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_remark
);
3159 init_unistr2(&info502
->info_502_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3161 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_path
);
3163 init_unistr2(&info502
->info_502_str
.uni_path
, s
, UNI_STR_TERMINATE
);
3165 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_passwd
);
3167 init_unistr2(&info502
->info_502_str
.uni_passwd
, s
, UNI_STR_TERMINATE
);
3169 info502
->info_502_str
.sd
= dup_sec_desc(mem_ctx
, info
.share
.info502
.info_502_str
.sd
);
3180 * List shares on a remote RPC server
3182 * All parameters are provided by the run_rpc_command function, except for
3183 * argc, argv which are passes through.
3185 * @param domain_sid The domain sid acquired from the remote server
3186 * @param cli A cli_state connected to the server.
3187 * @param mem_ctx Talloc context, destoyed on completion of the function.
3188 * @param argc Standard main() style argc
3189 * @param argv Standard main() style argv. Initial components are already
3192 * @return Normal NTSTATUS return.
3195 static NTSTATUS
rpc_share_list_internals(const DOM_SID
*domain_sid
,
3196 const char *domain_name
,
3197 struct cli_state
*cli
,
3198 struct rpc_pipe_client
*pipe_hnd
,
3199 TALLOC_CTX
*mem_ctx
,
3203 SRV_SHARE_INFO_CTR ctr
;
3205 uint32 i
, level
= 1;
3207 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr
);
3208 if (!W_ERROR_IS_OK(result
))
3211 /* Display results */
3213 if (opt_long_list_entries
) {
3215 "\nEnumerating shared resources (exports) on remote server:\n\n"\
3216 "\nShare name Type Description\n"\
3217 "---------- ---- -----------\n");
3219 for (i
= 0; i
< ctr
.num_entries
; i
++)
3220 display_share_info_1(&ctr
.share
.info1
[i
]);
3222 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3226 * 'net rpc share list' entrypoint.
3227 * @param argc Standard main() style argc
3228 * @param argv Standard main() style argv. Initial components are already
3231 static int rpc_share_list(int argc
, const char **argv
)
3233 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_list_internals
, argc
, argv
);
3236 static BOOL
check_share_availability(struct cli_state
*cli
, const char *netname
)
3238 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3239 d_printf("skipping [%s]: not a file share.\n", netname
);
3249 static BOOL
check_share_sanity(struct cli_state
*cli
, fstring netname
, uint32 type
)
3251 /* only support disk shares */
3252 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3253 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3257 /* skip builtin shares */
3258 /* FIXME: should print$ be added too ? */
3259 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3260 strequal(netname
,"global"))
3263 if (opt_exclude
&& in_list(netname
, opt_exclude
, False
)) {
3264 printf("excluding [%s]\n", netname
);
3268 return check_share_availability(cli
, netname
);
3272 * Migrate shares from a remote RPC server to the local RPC srever
3274 * All parameters are provided by the run_rpc_command function, except for
3275 * argc, argv which are passes through.
3277 * @param domain_sid The domain sid acquired from the remote server
3278 * @param cli A cli_state connected to the server.
3279 * @param mem_ctx Talloc context, destoyed on completion of the function.
3280 * @param argc Standard main() style argc
3281 * @param argv Standard main() style argv. Initial components are already
3284 * @return Normal NTSTATUS return.
3287 static NTSTATUS
rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
,
3288 const char *domain_name
,
3289 struct cli_state
*cli
,
3290 struct rpc_pipe_client
*pipe_hnd
,
3291 TALLOC_CTX
*mem_ctx
,
3296 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3297 SRV_SHARE_INFO_CTR ctr_src
;
3298 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3299 char *password
= NULL
; /* don't allow a share password */
3301 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3302 struct cli_state
*cli_dst
= NULL
;
3303 uint32 level
= 502; /* includes secdesc */
3305 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3306 if (!W_ERROR_IS_OK(result
))
3309 /* connect destination PI_SRVSVC */
3310 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3311 if (!NT_STATUS_IS_OK(nt_status
))
3315 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3317 fstring netname
= "", remark
= "", path
= "";
3318 /* reset error-code */
3319 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3321 rpcstr_pull_unistr2_fstring(
3322 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3323 rpcstr_pull_unistr2_fstring(
3324 remark
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_remark
);
3325 rpcstr_pull_unistr2_fstring(
3326 path
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_path
);
3328 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3331 /* finally add the share on the dst server */
3333 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3334 netname
, path
, remark
);
3336 result
= rpccli_srvsvc_net_share_add(srvsvc_pipe
, mem_ctx
, netname
, type
, remark
,
3337 ctr_src
.share
.info502
[i
].info_502
.perms
,
3338 ctr_src
.share
.info502
[i
].info_502
.max_uses
,
3339 ctr_src
.share
.info502
[i
].info_502
.num_uses
,
3340 path
, password
, level
,
3343 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3344 printf(" [%s] does already exist\n", netname
);
3348 if (!W_ERROR_IS_OK(result
)) {
3349 printf("cannot add share: %s\n", dos_errstr(result
));
3355 nt_status
= NT_STATUS_OK
;
3359 cli_shutdown(cli_dst
);
3367 * Migrate shares from a rpc-server to another
3369 * @param argc Standard main() style argc
3370 * @param argv Standard main() style argv. Initial components are already
3373 * @return A shell status integer (0 for success)
3375 static int rpc_share_migrate_shares(int argc
, const char **argv
)
3379 printf("no server to migrate\n");
3383 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3384 rpc_share_migrate_shares_internals
,
3391 * @param f file_info
3392 * @param mask current search mask
3393 * @param state arg-pointer
3396 static void copy_fn(const char *mnt
, file_info
*f
, const char *mask
, void *state
)
3398 static NTSTATUS nt_status
;
3399 static struct copy_clistate
*local_state
;
3400 static fstring filename
, new_mask
;
3404 local_state
= (struct copy_clistate
*)state
;
3405 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3407 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3410 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3413 if (f
->mode
& aDIR
) {
3415 DEBUG(3,("got dir: %s\n", f
->name
));
3417 fstrcpy(dir
, local_state
->cwd
);
3419 fstrcat(dir
, f
->name
);
3421 switch (net_mode_share
)
3423 case NET_MODE_SHARE_MIGRATE
:
3424 /* create that directory */
3425 nt_status
= net_copy_file(local_state
->mem_ctx
,
3426 local_state
->cli_share_src
,
3427 local_state
->cli_share_dst
,
3429 opt_acls
? True
: False
,
3430 opt_attrs
? True
: False
,
3431 opt_timestamps
? True
: False
,
3435 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3439 if (!NT_STATUS_IS_OK(nt_status
))
3440 printf("could not handle dir %s: %s\n",
3441 dir
, nt_errstr(nt_status
));
3443 /* search below that directory */
3444 fstrcpy(new_mask
, dir
);
3445 fstrcat(new_mask
, "\\*");
3447 old_dir
= local_state
->cwd
;
3448 local_state
->cwd
= dir
;
3449 if (!sync_files(local_state
, new_mask
))
3450 printf("could not handle files\n");
3451 local_state
->cwd
= old_dir
;
3458 fstrcpy(filename
, local_state
->cwd
);
3459 fstrcat(filename
, "\\");
3460 fstrcat(filename
, f
->name
);
3462 DEBUG(3,("got file: %s\n", filename
));
3464 switch (net_mode_share
)
3466 case NET_MODE_SHARE_MIGRATE
:
3467 nt_status
= net_copy_file(local_state
->mem_ctx
,
3468 local_state
->cli_share_src
,
3469 local_state
->cli_share_dst
,
3471 opt_acls
? True
: False
,
3472 opt_attrs
? True
: False
,
3473 opt_timestamps
? True
: False
,
3477 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3481 if (!NT_STATUS_IS_OK(nt_status
))
3482 printf("could not handle file %s: %s\n",
3483 filename
, nt_errstr(nt_status
));
3488 * sync files, can be called recursivly to list files
3489 * and then call copy_fn for each file
3491 * @param cp_clistate pointer to the copy_clistate we work with
3492 * @param mask the current search mask
3494 * @return Boolean result
3496 BOOL
sync_files(struct copy_clistate
*cp_clistate
, pstring mask
)
3499 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3501 if (cli_list(cp_clistate
->cli_share_src
, mask
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3502 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3503 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3512 * Set the top level directory permissions before we do any further copies.
3513 * Should set up ACL inheritance.
3516 BOOL
copy_top_level_perms(struct copy_clistate
*cp_clistate
,
3517 const char *sharename
)
3519 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3521 switch (net_mode_share
) {
3522 case NET_MODE_SHARE_MIGRATE
:
3523 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3524 nt_status
= net_copy_fileattr(cp_clistate
->mem_ctx
,
3525 cp_clistate
->cli_share_src
,
3526 cp_clistate
->cli_share_dst
,
3528 opt_acls
? True
: False
,
3529 opt_attrs
? True
: False
,
3530 opt_timestamps
? True
: False
,
3534 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3538 if (!NT_STATUS_IS_OK(nt_status
)) {
3539 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3540 sharename
, nt_errstr(nt_status
));
3548 * Sync all files inside a remote share to another share (over smb)
3550 * All parameters are provided by the run_rpc_command function, except for
3551 * argc, argv which are passes through.
3553 * @param domain_sid The domain sid acquired from the remote server
3554 * @param cli A cli_state connected to the server.
3555 * @param mem_ctx Talloc context, destoyed on completion of the function.
3556 * @param argc Standard main() style argc
3557 * @param argv Standard main() style argv. Initial components are already
3560 * @return Normal NTSTATUS return.
3563 static NTSTATUS
rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
,
3564 const char *domain_name
,
3565 struct cli_state
*cli
,
3566 struct rpc_pipe_client
*pipe_hnd
,
3567 TALLOC_CTX
*mem_ctx
,
3572 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3573 SRV_SHARE_INFO_CTR ctr_src
;
3576 struct copy_clistate cp_clistate
;
3577 BOOL got_src_share
= False
;
3578 BOOL got_dst_share
= False
;
3579 pstring mask
= "\\*";
3582 dst
= SMB_STRDUP(opt_destination
?opt_destination
:"127.0.0.1");
3584 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3586 if (!W_ERROR_IS_OK(result
))
3589 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3591 fstring netname
= "";
3593 rpcstr_pull_unistr2_fstring(
3594 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3596 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3599 /* one might not want to mirror whole discs :) */
3600 if (strequal(netname
, "print$") || netname
[1] == '$') {
3601 d_printf("skipping [%s]: builtin/hidden share\n", netname
);
3605 switch (net_mode_share
)
3607 case NET_MODE_SHARE_MIGRATE
:
3611 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3614 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3616 opt_acls
? "including" : "without",
3617 opt_attrs
? "including" : "without",
3618 opt_timestamps
? "(preserving timestamps)" : "");
3620 cp_clistate
.mem_ctx
= mem_ctx
;
3621 cp_clistate
.cli_share_src
= NULL
;
3622 cp_clistate
.cli_share_dst
= NULL
;
3623 cp_clistate
.cwd
= NULL
;
3624 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3626 /* open share source */
3627 nt_status
= connect_to_service(&cp_clistate
.cli_share_src
,
3628 &cli
->dest_ip
, cli
->desthost
,
3630 if (!NT_STATUS_IS_OK(nt_status
))
3633 got_src_share
= True
;
3635 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3636 /* open share destination */
3637 nt_status
= connect_to_service(&cp_clistate
.cli_share_dst
,
3638 NULL
, dst
, netname
, "A:");
3639 if (!NT_STATUS_IS_OK(nt_status
))
3642 got_dst_share
= True
;
3645 if (!copy_top_level_perms(&cp_clistate
, netname
)) {
3646 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", netname
);
3647 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3651 if (!sync_files(&cp_clistate
, mask
)) {
3652 d_fprintf(stderr
, "could not handle files for share: %s\n", netname
);
3653 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3658 nt_status
= NT_STATUS_OK
;
3663 cli_shutdown(cp_clistate
.cli_share_src
);
3666 cli_shutdown(cp_clistate
.cli_share_dst
);
3672 static int rpc_share_migrate_files(int argc
, const char **argv
)
3676 printf("no server to migrate\n");
3680 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3681 rpc_share_migrate_files_internals
,
3686 * Migrate share-ACLs from a remote RPC server to the local RPC srever
3688 * All parameters are provided by the run_rpc_command function, except for
3689 * argc, argv which are passes through.
3691 * @param domain_sid The domain sid acquired from the remote server
3692 * @param cli A cli_state connected to the server.
3693 * @param mem_ctx Talloc context, destoyed on completion of the function.
3694 * @param argc Standard main() style argc
3695 * @param argv Standard main() style argv. Initial components are already
3698 * @return Normal NTSTATUS return.
3701 static NTSTATUS
rpc_share_migrate_security_internals(const DOM_SID
*domain_sid
,
3702 const char *domain_name
,
3703 struct cli_state
*cli
,
3704 struct rpc_pipe_client
*pipe_hnd
,
3705 TALLOC_CTX
*mem_ctx
,
3710 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3711 SRV_SHARE_INFO_CTR ctr_src
;
3712 SRV_SHARE_INFO info
;
3714 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3715 struct cli_state
*cli_dst
= NULL
;
3716 uint32 level
= 502; /* includes secdesc */
3718 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3720 if (!W_ERROR_IS_OK(result
))
3723 /* connect destination PI_SRVSVC */
3724 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3725 if (!NT_STATUS_IS_OK(nt_status
))
3729 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3731 fstring netname
= "", remark
= "", path
= "";
3732 /* reset error-code */
3733 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3735 rpcstr_pull_unistr2_fstring(
3736 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3737 rpcstr_pull_unistr2_fstring(
3738 remark
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_remark
);
3739 rpcstr_pull_unistr2_fstring(
3740 path
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_path
);
3742 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3745 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3746 netname
, path
, remark
);
3749 display_sec_desc(ctr_src
.share
.info502
[i
].info_502_str
.sd
);
3754 info
.switch_value
= level
;
3755 info
.ptr_share_ctr
= 1;
3757 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3758 info
.share
.info502
= ctr_src
.share
.info502
[i
];
3760 /* finally modify the share on the dst server */
3761 result
= rpccli_srvsvc_net_share_set_info(srvsvc_pipe
, mem_ctx
, netname
, level
, &info
);
3763 if (!W_ERROR_IS_OK(result
)) {
3764 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3770 nt_status
= NT_STATUS_OK
;
3774 cli_shutdown(cli_dst
);
3782 * Migrate share-acls from a rpc-server to another
3784 * @param argc Standard main() style argc
3785 * @param argv Standard main() style argv. Initial components are already
3788 * @return A shell status integer (0 for success)
3790 static int rpc_share_migrate_security(int argc
, const char **argv
)
3794 printf("no server to migrate\n");
3798 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3799 rpc_share_migrate_security_internals
,
3804 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3805 * from one server to another
3807 * @param argc Standard main() style argc
3808 * @param argv Standard main() style argv. Initial components are already
3811 * @return A shell status integer (0 for success)
3814 static int rpc_share_migrate_all(int argc
, const char **argv
)
3819 printf("no server to migrate\n");
3823 /* order is important. we don't want to be locked out by the share-acl
3824 * before copying files - gd */
3826 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
3830 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
3834 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_security_internals
, argc
, argv
);
3839 * 'net rpc share migrate' entrypoint.
3840 * @param argc Standard main() style argc
3841 * @param argv Standard main() style argv. Initial components are already
3844 static int rpc_share_migrate(int argc
, const char **argv
)
3847 struct functable func
[] = {
3848 {"all", rpc_share_migrate_all
},
3849 {"files", rpc_share_migrate_files
},
3850 {"help", rpc_share_usage
},
3851 {"security", rpc_share_migrate_security
},
3852 {"shares", rpc_share_migrate_shares
},
3856 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3858 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
3867 static int num_server_aliases
;
3868 static struct full_alias
*server_aliases
;
3871 * Add an alias to the static list.
3873 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3875 if (server_aliases
== NULL
)
3876 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3878 server_aliases
[num_server_aliases
] = *alias
;
3879 num_server_aliases
+= 1;
3883 * For a specific domain on the server, fetch all the aliases
3884 * and their members. Add all of them to the server_aliases.
3887 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3888 TALLOC_CTX
*mem_ctx
,
3889 POLICY_HND
*connect_pol
,
3890 const DOM_SID
*domain_sid
)
3892 uint32 start_idx
, max_entries
, num_entries
, i
;
3893 struct acct_info
*groups
;
3895 POLICY_HND domain_pol
;
3897 /* Get domain policy handle */
3899 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, connect_pol
,
3900 MAXIMUM_ALLOWED_ACCESS
,
3901 domain_sid
, &domain_pol
);
3902 if (!NT_STATUS_IS_OK(result
))
3909 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
3910 &start_idx
, max_entries
,
3911 &groups
, &num_entries
);
3913 for (i
= 0; i
< num_entries
; i
++) {
3915 POLICY_HND alias_pol
;
3916 struct full_alias alias
;
3920 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
3921 MAXIMUM_ALLOWED_ACCESS
,
3924 if (!NT_STATUS_IS_OK(result
))
3927 result
= rpccli_samr_query_aliasmem(pipe_hnd
, mem_ctx
,
3931 if (!NT_STATUS_IS_OK(result
))
3934 result
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &alias_pol
);
3935 if (!NT_STATUS_IS_OK(result
))
3938 alias
.members
= NULL
;
3940 if (alias
.num_members
> 0) {
3941 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3943 for (j
= 0; j
< alias
.num_members
; j
++)
3944 sid_copy(&alias
.members
[j
],
3948 sid_copy(&alias
.sid
, domain_sid
);
3949 sid_append_rid(&alias
.sid
, groups
[i
].rid
);
3951 push_alias(mem_ctx
, &alias
);
3953 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3955 result
= NT_STATUS_OK
;
3958 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
3964 * Dump server_aliases as names for debugging purposes.
3967 static NTSTATUS
rpc_aliaslist_dump(const DOM_SID
*domain_sid
,
3968 const char *domain_name
,
3969 struct cli_state
*cli
,
3970 struct rpc_pipe_client
*pipe_hnd
,
3971 TALLOC_CTX
*mem_ctx
,
3979 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, True
,
3980 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3982 if (!NT_STATUS_IS_OK(result
))
3985 for (i
=0; i
<num_server_aliases
; i
++) {
3991 struct full_alias
*alias
= &server_aliases
[i
];
3993 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3995 &domains
, &names
, &types
);
3996 if (!NT_STATUS_IS_OK(result
))
3999 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4001 if (alias
->num_members
== 0) {
4006 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4009 &domains
, &names
, &types
);
4011 if (!NT_STATUS_IS_OK(result
) &&
4012 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4015 for (j
=0; j
<alias
->num_members
; j
++)
4016 DEBUG(1, ("%s\\%s (%d); ",
4017 domains
[j
] ? domains
[j
] : "*unknown*",
4018 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4022 rpccli_lsa_close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4024 return NT_STATUS_OK
;
4028 * Fetch a list of all server aliases and their members into
4032 static NTSTATUS
rpc_aliaslist_internals(const DOM_SID
*domain_sid
,
4033 const char *domain_name
,
4034 struct cli_state
*cli
,
4035 struct rpc_pipe_client
*pipe_hnd
,
4036 TALLOC_CTX
*mem_ctx
,
4041 POLICY_HND connect_pol
;
4043 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
4046 if (!NT_STATUS_IS_OK(result
))
4049 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4050 &global_sid_Builtin
);
4052 if (!NT_STATUS_IS_OK(result
))
4055 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4058 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
4063 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4065 token
->num_sids
= 4;
4067 token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4);
4069 token
->user_sids
[0] = *user_sid
;
4070 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4071 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4072 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4075 static void free_user_token(NT_USER_TOKEN
*token
)
4077 SAFE_FREE(token
->user_sids
);
4080 static BOOL
is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4084 for (i
=0; i
<token
->num_sids
; i
++) {
4085 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
4091 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4093 if (is_sid_in_token(token
, sid
))
4096 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4097 if (!token
->user_sids
) {
4101 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4103 token
->num_sids
+= 1;
4108 NT_USER_TOKEN token
;
4111 static void dump_user_token(struct user_token
*token
)
4115 d_printf("%s\n", token
->name
);
4117 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4118 d_printf(" %s\n", sid_string_static(&token
->token
.user_sids
[i
]));
4122 static BOOL
is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4126 for (i
=0; i
<alias
->num_members
; i
++) {
4127 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4134 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4138 for (i
=0; i
<num_server_aliases
; i
++) {
4139 if (is_alias_member(&sid
, &server_aliases
[i
]))
4140 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4145 * We got a user token with all the SIDs we can know about without asking the
4146 * server directly. These are the user and domain group sids. All of these can
4147 * be members of aliases. So scan the list of aliases for each of the SIDs and
4148 * add them to the token.
4151 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4153 int num_global_sids
= token
->num_sids
;
4156 for (i
=0; i
<num_global_sids
; i
++) {
4157 collect_sid_memberships(token
, token
->user_sids
[i
]);
4161 static BOOL
get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4163 struct winbindd_request request
;
4164 struct winbindd_response response
;
4172 fstr_sprintf(full_name
, "%s%c%s",
4173 domain
, *lp_winbind_separator(), user
);
4175 /* First let's find out the user sid */
4177 ZERO_STRUCT(request
);
4178 ZERO_STRUCT(response
);
4180 fstrcpy(request
.data
.name
.dom_name
, domain
);
4181 fstrcpy(request
.data
.name
.name
, user
);
4183 result
= winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
);
4185 if (result
!= NSS_STATUS_SUCCESS
) {
4186 DEBUG(1, ("winbind could not find %s\n", full_name
));
4190 if (response
.data
.sid
.type
!= SID_NAME_USER
) {
4191 DEBUG(1, ("%s is not a user\n", full_name
));
4195 string_to_sid(&user_sid
, response
.data
.sid
.sid
);
4197 init_user_token(token
, &user_sid
);
4199 /* And now the groups winbind knows about */
4201 ZERO_STRUCT(response
);
4203 fstrcpy(request
.data
.username
, full_name
);
4205 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
4207 if (result
!= NSS_STATUS_SUCCESS
) {
4208 DEBUG(1, ("winbind could not get groups of %s\n", full_name
));
4212 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
4213 gid_t gid
= ((gid_t
*)response
.extra_data
)[i
];
4216 struct winbindd_request sidrequest
;
4217 struct winbindd_response sidresponse
;
4219 ZERO_STRUCT(sidrequest
);
4220 ZERO_STRUCT(sidresponse
);
4222 sidrequest
.data
.gid
= gid
;
4224 result
= winbindd_request_response(WINBINDD_GID_TO_SID
,
4225 &sidrequest
, &sidresponse
);
4227 if (result
!= NSS_STATUS_SUCCESS
) {
4228 DEBUG(1, ("winbind could not find SID of gid %d\n",
4233 DEBUG(3, (" %s\n", sidresponse
.data
.sid
.sid
));
4235 string_to_sid(&sid
, sidresponse
.data
.sid
.sid
);
4236 add_sid_to_token(token
, &sid
);
4239 SAFE_FREE(response
.extra_data
);
4245 * Get a list of all user tokens we want to look at
4248 static BOOL
get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
4250 struct winbindd_request request
;
4251 struct winbindd_response response
;
4252 const char *extra_data
;
4255 struct user_token
*result
;
4257 if (lp_winbind_use_default_domain() &&
4258 (opt_target_workgroup
== NULL
)) {
4259 d_fprintf(stderr
, "winbind use default domain = yes set, "
4260 "please specify a workgroup\n");
4264 /* Send request to winbind daemon */
4266 ZERO_STRUCT(request
);
4267 ZERO_STRUCT(response
);
4269 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
4273 /* Look through extra data */
4275 if (!response
.extra_data
)
4278 extra_data
= (const char *)response
.extra_data
;
4281 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
4285 result
= SMB_MALLOC_ARRAY(struct user_token
, *num_tokens
);
4287 if (result
== NULL
) {
4288 DEBUG(1, ("Could not malloc sid array\n"));
4292 extra_data
= (const char *)response
.extra_data
;
4295 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
4297 fstring domain
, user
;
4300 fstrcpy(result
[i
].name
, name
);
4302 p
= strchr(name
, *lp_winbind_separator());
4304 DEBUG(3, ("%s\n", name
));
4307 fstrcpy(domain
, opt_target_workgroup
);
4308 fstrcpy(user
, name
);
4311 fstrcpy(domain
, name
);
4316 get_user_sids(domain
, user
, &(result
[i
].token
));
4320 SAFE_FREE(response
.extra_data
);
4322 *user_tokens
= result
;
4327 static BOOL
get_user_tokens_from_file(FILE *f
,
4329 struct user_token
**tokens
)
4331 struct user_token
*token
= NULL
;
4336 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4340 if (line
[strlen(line
)-1] == '\n')
4341 line
[strlen(line
)-1] = '\0';
4343 if (line
[0] == ' ') {
4347 string_to_sid(&sid
, &line
[1]);
4349 if (token
== NULL
) {
4350 DEBUG(0, ("File does not begin with username"));
4354 add_sid_to_token(&token
->token
, &sid
);
4358 /* And a new user... */
4361 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4362 if (*tokens
== NULL
) {
4363 DEBUG(0, ("Could not realloc tokens\n"));
4367 token
= &((*tokens
)[*num_tokens
-1]);
4369 fstrcpy(token
->name
, line
);
4370 token
->token
.num_sids
= 0;
4371 token
->token
.user_sids
= NULL
;
4380 * Show the list of all users that have access to a share
4383 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4384 TALLOC_CTX
*mem_ctx
,
4385 const char *netname
,
4387 struct user_token
*tokens
)
4390 SEC_DESC
*share_sd
= NULL
;
4391 SEC_DESC
*root_sd
= NULL
;
4392 struct cli_state
*cli
= pipe_hnd
->cli
;
4394 SRV_SHARE_INFO info
;
4398 result
= rpccli_srvsvc_net_share_get_info(pipe_hnd
, mem_ctx
, netname
,
4401 if (!W_ERROR_IS_OK(result
)) {
4402 DEBUG(1, ("Coult not query secdesc for share %s\n",
4407 share_sd
= info
.share
.info502
.info_502_str
.sd
;
4408 if (share_sd
== NULL
) {
4409 DEBUG(1, ("Got no secdesc for share %s\n",
4415 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4419 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4422 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4425 for (i
=0; i
<num_tokens
; i
++) {
4429 if (share_sd
!= NULL
) {
4430 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4431 1, &acc_granted
, &status
)) {
4432 DEBUG(1, ("Could not check share_sd for "
4438 if (!NT_STATUS_IS_OK(status
))
4442 if (root_sd
== NULL
) {
4443 d_printf(" %s\n", tokens
[i
].name
);
4447 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4448 1, &acc_granted
, &status
)) {
4449 DEBUG(1, ("Could not check root_sd for user %s\n",
4454 if (!NT_STATUS_IS_OK(status
))
4457 d_printf(" %s\n", tokens
[i
].name
);
4461 cli_close(cli
, fnum
);
4473 static void collect_share(const char *name
, uint32 m
,
4474 const char *comment
, void *state
)
4476 struct share_list
*share_list
= (struct share_list
*)state
;
4478 if (m
!= STYPE_DISKTREE
)
4481 share_list
->num_shares
+= 1;
4482 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4483 if (!share_list
->shares
) {
4484 share_list
->num_shares
= 0;
4487 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4490 static void rpc_share_userlist_usage(void)
4496 * List shares on a remote RPC server, including the security descriptors
4498 * All parameters are provided by the run_rpc_command function, except for
4499 * argc, argv which are passes through.
4501 * @param domain_sid The domain sid acquired from the remote server
4502 * @param cli A cli_state connected to the server.
4503 * @param mem_ctx Talloc context, destoyed on completion of the function.
4504 * @param argc Standard main() style argc
4505 * @param argv Standard main() style argv. Initial components are already
4508 * @return Normal NTSTATUS return.
4511 static NTSTATUS
rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
4512 const char *domain_name
,
4513 struct cli_state
*cli
,
4514 struct rpc_pipe_client
*pipe_hnd
,
4515 TALLOC_CTX
*mem_ctx
,
4525 struct user_token
*tokens
= NULL
;
4528 struct share_list share_list
;
4531 rpc_share_userlist_usage();
4532 return NT_STATUS_UNSUCCESSFUL
;
4538 f
= fopen(argv
[0], "r");
4542 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4543 return NT_STATUS_UNSUCCESSFUL
;
4546 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4552 DEBUG(0, ("Could not read users from file\n"));
4553 return NT_STATUS_UNSUCCESSFUL
;
4556 for (i
=0; i
<num_tokens
; i
++)
4557 collect_alias_memberships(&tokens
[i
].token
);
4559 init_enum_hnd(&hnd
, 0);
4561 share_list
.num_shares
= 0;
4562 share_list
.shares
= NULL
;
4564 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4567 DEBUG(0, ("Error returning browse list: %s\n",
4572 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4573 char *netname
= share_list
.shares
[i
];
4575 if (netname
[strlen(netname
)-1] == '$')
4578 d_printf("%s\n", netname
);
4580 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4581 num_tokens
, tokens
);
4584 for (i
=0; i
<num_tokens
; i
++) {
4585 free_user_token(&tokens
[i
].token
);
4588 SAFE_FREE(share_list
.shares
);
4590 return NT_STATUS_OK
;
4593 static int rpc_share_allowedusers(int argc
, const char **argv
)
4597 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
4598 rpc_aliaslist_internals
,
4603 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
4609 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4610 rpc_share_allowedusers_internals
,
4614 int net_usersidlist(int argc
, const char **argv
)
4617 struct user_token
*tokens
= NULL
;
4621 net_usersidlist_usage(argc
, argv
);
4625 if (!get_user_tokens(&num_tokens
, &tokens
)) {
4626 DEBUG(0, ("Could not get the user/sid list\n"));
4630 for (i
=0; i
<num_tokens
; i
++) {
4631 dump_user_token(&tokens
[i
]);
4632 free_user_token(&tokens
[i
].token
);
4639 int net_usersidlist_usage(int argc
, const char **argv
)
4641 d_printf("net usersidlist\n"
4642 "\tprints out a list of all users the running winbind knows\n"
4643 "\tabout, together with all their SIDs. This is used as\n"
4644 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4646 net_common_flags_usage(argc
, argv
);
4651 * 'net rpc share' entrypoint.
4652 * @param argc Standard main() style argc
4653 * @param argv Standard main() style argv. Initial components are already
4657 int net_rpc_share(int argc
, const char **argv
)
4659 struct functable func
[] = {
4660 {"add", rpc_share_add
},
4661 {"delete", rpc_share_delete
},
4662 {"allowedusers", rpc_share_allowedusers
},
4663 {"migrate", rpc_share_migrate
},
4664 {"list", rpc_share_list
},
4669 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4670 rpc_share_list_internals
,
4673 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4676 static NTSTATUS
rpc_sh_share_list(TALLOC_CTX
*mem_ctx
,
4677 struct rpc_sh_ctx
*ctx
,
4678 struct rpc_pipe_client
*pipe_hnd
,
4679 int argc
, const char **argv
)
4681 return rpc_share_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
4682 ctx
->cli
, pipe_hnd
, mem_ctx
,
4686 static NTSTATUS
rpc_sh_share_add(TALLOC_CTX
*mem_ctx
,
4687 struct rpc_sh_ctx
*ctx
,
4688 struct rpc_pipe_client
*pipe_hnd
,
4689 int argc
, const char **argv
)
4693 if ((argc
< 2) || (argc
> 3)) {
4694 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4696 return NT_STATUS_INVALID_PARAMETER
;
4699 result
= rpccli_srvsvc_net_share_add(
4700 pipe_hnd
, mem_ctx
, argv
[0], STYPE_DISKTREE
,
4701 (argc
== 3) ? argv
[2] : "",
4702 0, 0, 0, argv
[1], NULL
, 2, NULL
);
4704 return werror_to_ntstatus(result
);
4707 static NTSTATUS
rpc_sh_share_delete(TALLOC_CTX
*mem_ctx
,
4708 struct rpc_sh_ctx
*ctx
,
4709 struct rpc_pipe_client
*pipe_hnd
,
4710 int argc
, const char **argv
)
4715 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4716 return NT_STATUS_INVALID_PARAMETER
;
4719 result
= rpccli_srvsvc_net_share_del(pipe_hnd
, mem_ctx
, argv
[0]);
4720 return werror_to_ntstatus(result
);
4723 static NTSTATUS
rpc_sh_share_info(TALLOC_CTX
*mem_ctx
,
4724 struct rpc_sh_ctx
*ctx
,
4725 struct rpc_pipe_client
*pipe_hnd
,
4726 int argc
, const char **argv
)
4728 SRV_SHARE_INFO info
;
4729 SRV_SHARE_INFO_2
*info2
= &info
.share
.info2
;
4733 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4734 return NT_STATUS_INVALID_PARAMETER
;
4737 result
= rpccli_srvsvc_net_share_get_info(
4738 pipe_hnd
, mem_ctx
, argv
[0], 2, &info
);
4739 if (!W_ERROR_IS_OK(result
)) {
4743 d_printf("Name: %s\n",
4744 rpcstr_pull_unistr2_talloc(mem_ctx
,
4745 &info2
->info_2_str
.uni_netname
));
4746 d_printf("Comment: %s\n",
4747 rpcstr_pull_unistr2_talloc(mem_ctx
,
4748 &info2
->info_2_str
.uni_remark
));
4750 d_printf("Path: %s\n",
4751 rpcstr_pull_unistr2_talloc(mem_ctx
,
4752 &info2
->info_2_str
.uni_path
));
4753 d_printf("Password: %s\n",
4754 rpcstr_pull_unistr2_talloc(mem_ctx
,
4755 &info2
->info_2_str
.uni_passwd
));
4758 return werror_to_ntstatus(result
);
4761 struct rpc_sh_cmd
*net_rpc_share_cmds(TALLOC_CTX
*mem_ctx
,
4762 struct rpc_sh_ctx
*ctx
)
4764 static struct rpc_sh_cmd cmds
[] = {
4766 { "list", NULL
, PI_SRVSVC
, rpc_sh_share_list
,
4767 "List available shares" },
4769 { "add", NULL
, PI_SRVSVC
, rpc_sh_share_add
,
4772 { "delete", NULL
, PI_SRVSVC
, rpc_sh_share_delete
,
4775 { "info", NULL
, PI_SRVSVC
, rpc_sh_share_info
,
4776 "Get information about a share" },
4778 { NULL
, NULL
, 0, NULL
, NULL
}
4784 /****************************************************************************/
4786 static int rpc_file_usage(int argc
, const char **argv
)
4788 return net_help_file(argc
, argv
);
4792 * Close a file on a remote RPC server
4794 * All parameters are provided by the run_rpc_command function, except for
4795 * argc, argv which are passes through.
4797 * @param domain_sid The domain sid acquired from the remote server
4798 * @param cli A cli_state connected to the server.
4799 * @param mem_ctx Talloc context, destoyed on completion of the function.
4800 * @param argc Standard main() style argc
4801 * @param argv Standard main() style argv. Initial components are already
4804 * @return Normal NTSTATUS return.
4806 static NTSTATUS
rpc_file_close_internals(const DOM_SID
*domain_sid
,
4807 const char *domain_name
,
4808 struct cli_state
*cli
,
4809 struct rpc_pipe_client
*pipe_hnd
,
4810 TALLOC_CTX
*mem_ctx
,
4815 result
= rpccli_srvsvc_net_file_close(pipe_hnd
, mem_ctx
, atoi(argv
[0]));
4816 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
4820 * Close a file on a remote RPC server
4822 * @param argc Standard main() style argc
4823 * @param argv Standard main() style argv. Initial components are already
4826 * @return A shell status integer (0 for success)
4828 static int rpc_file_close(int argc
, const char **argv
)
4831 DEBUG(1, ("No fileid given on close\n"));
4832 return(rpc_file_usage(argc
, argv
));
4835 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4836 rpc_file_close_internals
,
4841 * Formatted print of open file info
4843 * @param info3 FILE_INFO_3 contents
4844 * @param str3 strings for FILE_INFO_3
4847 static void display_file_info_3(FILE_INFO_3
*info3
, FILE_INFO_3_STR
*str3
)
4849 fstring user
= "", path
= "";
4851 rpcstr_pull_unistr2_fstring(user
, &str3
->uni_user_name
);
4852 rpcstr_pull_unistr2_fstring(path
, &str3
->uni_path_name
);
4854 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4855 info3
->id
, user
, info3
->perms
, info3
->num_locks
, path
);
4859 * List open files on a remote RPC server
4861 * All parameters are provided by the run_rpc_command function, except for
4862 * argc, argv which are passes through.
4864 * @param domain_sid The domain sid acquired from the remote server
4865 * @param cli A cli_state connected to the server.
4866 * @param mem_ctx Talloc context, destoyed on completion of the function.
4867 * @param argc Standard main() style argc
4868 * @param argv Standard main() style argv. Initial components are already
4871 * @return Normal NTSTATUS return.
4874 static NTSTATUS
rpc_file_list_internals(const DOM_SID
*domain_sid
,
4875 const char *domain_name
,
4876 struct cli_state
*cli
,
4877 struct rpc_pipe_client
*pipe_hnd
,
4878 TALLOC_CTX
*mem_ctx
,
4882 SRV_FILE_INFO_CTR ctr
;
4885 uint32 preferred_len
= 0xffffffff, i
;
4886 const char *username
=NULL
;
4888 init_enum_hnd(&hnd
, 0);
4890 /* if argc > 0, must be user command */
4892 username
= smb_xstrdup(argv
[0]);
4894 result
= rpccli_srvsvc_net_file_enum(pipe_hnd
,
4895 mem_ctx
, 3, username
, &ctr
, preferred_len
, &hnd
);
4897 if (!W_ERROR_IS_OK(result
))
4900 /* Display results */
4903 "\nEnumerating open files on remote server:\n\n"\
4904 "\nFileId Opened by Perms Locks Path"\
4905 "\n------ --------- ----- ----- ---- \n");
4906 for (i
= 0; i
< ctr
.num_entries
; i
++)
4907 display_file_info_3(&ctr
.file
.info3
[i
].info_3
,
4908 &ctr
.file
.info3
[i
].info_3_str
);
4910 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
4914 * List files for a user on a remote RPC server
4916 * @param argc Standard main() style argc
4917 * @param argv Standard main() style argv. Initial components are already
4920 * @return A shell status integer (0 for success)
4923 static int rpc_file_user(int argc
, const char **argv
)
4926 DEBUG(1, ("No username given\n"));
4927 return(rpc_file_usage(argc
, argv
));
4930 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4931 rpc_file_list_internals
,
4936 * 'net rpc file' entrypoint.
4937 * @param argc Standard main() style argc
4938 * @param argv Standard main() style argv. Initial components are already
4942 int net_rpc_file(int argc
, const char **argv
)
4944 struct functable func
[] = {
4945 {"close", rpc_file_close
},
4946 {"user", rpc_file_user
},
4948 {"info", rpc_file_info
},
4954 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4955 rpc_file_list_internals
,
4958 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
4962 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
4964 * All parameters are provided by the run_rpc_command function, except for
4965 * argc, argv which are passed through.
4967 * @param domain_sid The domain sid aquired from the remote server
4968 * @param cli A cli_state connected to the server.
4969 * @param mem_ctx Talloc context, destoyed on compleation of the function.
4970 * @param argc Standard main() style argc
4971 * @param argv Standard main() style argv. Initial components are already
4974 * @return Normal NTSTATUS return.
4977 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
4978 const char *domain_name
,
4979 struct cli_state
*cli
,
4980 struct rpc_pipe_client
*pipe_hnd
,
4981 TALLOC_CTX
*mem_ctx
,
4985 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4987 result
= rpccli_shutdown_abort(pipe_hnd
, mem_ctx
);
4989 if (NT_STATUS_IS_OK(result
)) {
4990 d_printf("\nShutdown successfully aborted\n");
4991 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4993 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4999 * ABORT the shutdown of a remote RPC Server, over winreg pipe
5001 * All parameters are provided by the run_rpc_command function, except for
5002 * argc, argv which are passed through.
5004 * @param domain_sid The domain sid aquired from the remote server
5005 * @param cli A cli_state connected to the server.
5006 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5007 * @param argc Standard main() style argc
5008 * @param argv Standard main() style argv. Initial components are already
5011 * @return Normal NTSTATUS return.
5014 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5015 const char *domain_name
,
5016 struct cli_state
*cli
,
5017 struct rpc_pipe_client
*pipe_hnd
,
5018 TALLOC_CTX
*mem_ctx
,
5022 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5024 result
= werror_to_ntstatus(rpccli_reg_abort_shutdown(pipe_hnd
, mem_ctx
));
5026 if (NT_STATUS_IS_OK(result
)) {
5027 d_printf("\nShutdown successfully aborted\n");
5028 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5030 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5036 * ABORT the Shut down of a remote RPC server
5038 * @param argc Standard main() style argc
5039 * @param argv Standard main() style argv. Initial components are already
5042 * @return A shell status integer (0 for success)
5045 static int rpc_shutdown_abort(int argc
, const char **argv
)
5047 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
5048 rpc_shutdown_abort_internals
,
5054 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5056 return run_rpc_command(NULL
, PI_WINREG
, 0,
5057 rpc_reg_shutdown_abort_internals
,
5062 * Shut down a remote RPC Server via initshutdown pipe
5064 * All parameters are provided by the run_rpc_command function, except for
5065 * argc, argv which are passes through.
5067 * @param domain_sid The domain sid aquired from the remote server
5068 * @param cli A cli_state connected to the server.
5069 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5070 * @param argc Standard main() style argc
5071 * @param argc Standard main() style argv. Initial components are already
5074 * @return Normal NTSTATUS return.
5077 static NTSTATUS
rpc_init_shutdown_internals(const DOM_SID
*domain_sid
,
5078 const char *domain_name
,
5079 struct cli_state
*cli
,
5080 struct rpc_pipe_client
*pipe_hnd
,
5081 TALLOC_CTX
*mem_ctx
,
5085 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5086 const char *msg
= "This machine will be shutdown shortly";
5087 uint32 timeout
= 20;
5093 timeout
= opt_timeout
;
5096 /* create an entry */
5097 result
= rpccli_shutdown_init(pipe_hnd
, mem_ctx
, msg
, timeout
, opt_reboot
,
5100 if (NT_STATUS_IS_OK(result
)) {
5101 d_printf("\nShutdown of remote machine succeeded\n");
5102 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5104 DEBUG(1,("Shutdown of remote machine failed!\n"));
5110 * Shut down a remote RPC Server via winreg pipe
5112 * All parameters are provided by the run_rpc_command function, except for
5113 * argc, argv which are passes through.
5115 * @param domain_sid The domain sid aquired from the remote server
5116 * @param cli A cli_state connected to the server.
5117 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5118 * @param argc Standard main() style argc
5119 * @param argc Standard main() style argv. Initial components are already
5122 * @return Normal NTSTATUS return.
5125 static NTSTATUS
rpc_reg_shutdown_internals(const DOM_SID
*domain_sid
,
5126 const char *domain_name
,
5127 struct cli_state
*cli
,
5128 struct rpc_pipe_client
*pipe_hnd
,
5129 TALLOC_CTX
*mem_ctx
,
5134 const char *msg
= "This machine will be shutdown shortly";
5135 uint32 timeout
= 20;
5140 struct poptOption long_options
[] = {
5141 {"message", 'm', POPT_ARG_STRING
, &msg
},
5142 {"timeout", 't', POPT_ARG_INT
, &timeout
},
5143 {"reboot", 'r', POPT_ARG_NONE
, &reboot
},
5144 {"force", 'f', POPT_ARG_NONE
, &force
},
5148 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
5149 POPT_CONTEXT_KEEP_FIRST
);
5151 rc
= poptGetNextOpt(pc
);
5154 /* an error occurred during option processing */
5155 DEBUG(0, ("%s: %s\n",
5156 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
5158 return NT_STATUS_INVALID_PARAMETER
;
5165 timeout
= opt_timeout
;
5168 /* create an entry */
5169 result
= rpccli_reg_shutdown(pipe_hnd
, mem_ctx
, msg
, timeout
, opt_reboot
, opt_force
);
5171 if (W_ERROR_IS_OK(result
)) {
5172 d_printf("\nShutdown of remote machine succeeded\n");
5174 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5175 if (W_ERROR_EQUAL(result
,WERR_MACHINE_LOCKED
))
5176 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5178 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(result
));
5181 return werror_to_ntstatus(result
);
5185 * Shut down a remote RPC server
5187 * @param argc Standard main() style argc
5188 * @param argc Standard main() style argv. Initial components are already
5191 * @return A shell status integer (0 for success)
5194 static int rpc_shutdown(int argc
, const char **argv
)
5196 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
5197 rpc_init_shutdown_internals
,
5201 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5202 rc
= run_rpc_command(NULL
, PI_WINREG
, 0,
5203 rpc_reg_shutdown_internals
, argc
, argv
);
5209 /***************************************************************************
5210 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5212 ***************************************************************************/
5215 * Add interdomain trust account to the RPC server.
5216 * All parameters (except for argc and argv) are passed by run_rpc_command
5219 * @param domain_sid The domain sid acquired from the server
5220 * @param cli A cli_state connected to the server.
5221 * @param mem_ctx Talloc context, destoyed on completion of the function.
5222 * @param argc Standard main() style argc
5223 * @param argc Standard main() style argv. Initial components are already
5226 * @return normal NTSTATUS return code
5229 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
5230 const char *domain_name
,
5231 struct cli_state
*cli
,
5232 struct rpc_pipe_client
*pipe_hnd
,
5233 TALLOC_CTX
*mem_ctx
,
5237 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5238 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5241 uint32 unknown
, user_rid
;
5244 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
5245 return NT_STATUS_INVALID_PARAMETER
;
5249 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5252 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5253 return NT_STATUS_NO_MEMORY
;
5256 strupper_m(acct_name
);
5258 /* Get samr policy handle */
5259 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
5261 if (!NT_STATUS_IS_OK(result
)) {
5265 /* Get domain policy handle */
5266 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
5267 MAXIMUM_ALLOWED_ACCESS
,
5268 domain_sid
, &domain_pol
);
5269 if (!NT_STATUS_IS_OK(result
)) {
5273 /* Create trusting domain's account */
5274 acb_info
= ACB_NORMAL
;
5275 unknown
= 0xe00500b0; /* No idea what this is - a permission mask?
5276 mimir: yes, most probably it is */
5278 result
= rpccli_samr_create_dom_user(pipe_hnd
, mem_ctx
, &domain_pol
,
5279 acct_name
, acb_info
, unknown
,
5280 &user_pol
, &user_rid
);
5281 if (!NT_STATUS_IS_OK(result
)) {
5286 SAM_USERINFO_CTR ctr
;
5287 SAM_USER_INFO_23 p23
;
5293 encode_pw_buffer(pwbuf
, argv
[1], STR_UNICODE
);
5297 ZERO_STRUCT(notime
);
5301 memset(hrs
.hours
, 0xFF, sizeof(hrs
.hours
));
5302 acb_info
= ACB_DOMTRUST
;
5304 init_sam_user_info23A(&p23
, ¬ime
, ¬ime
, ¬ime
,
5305 ¬ime
, ¬ime
, ¬ime
,
5306 nostr
, nostr
, nostr
, nostr
, nostr
,
5307 nostr
, nostr
, nostr
, nostr
, nostr
,
5308 0, 0, acb_info
, ACCT_FLAGS
, 168, &hrs
,
5309 0, 0, (char *)pwbuf
);
5310 ctr
.switch_value
= 23;
5311 ctr
.info
.id23
= &p23
;
5312 p23
.passmustchange
= 0;
5314 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
, 23,
5315 &cli
->user_session_key
, &ctr
);
5317 if (!NT_STATUS_IS_OK(result
)) {
5318 DEBUG(0,("Could not set trust account password: %s\n",
5319 nt_errstr(result
)));
5325 SAFE_FREE(acct_name
);
5330 * Create interdomain trust account for a remote domain.
5332 * @param argc standard argc
5333 * @param argv standard argv without initial components
5335 * @return Integer status (0 means success)
5338 static int rpc_trustdom_add(int argc
, const char **argv
)
5341 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
5344 d_printf("Usage: net rpc trustdom add <domain>\n");
5351 * Remove interdomain trust account from the RPC server.
5352 * All parameters (except for argc and argv) are passed by run_rpc_command
5355 * @param domain_sid The domain sid acquired from the server
5356 * @param cli A cli_state connected to the server.
5357 * @param mem_ctx Talloc context, destoyed on completion of the function.
5358 * @param argc Standard main() style argc
5359 * @param argc Standard main() style argv. Initial components are already
5362 * @return normal NTSTATUS return code
5365 static NTSTATUS
rpc_trustdom_del_internals(const DOM_SID
*domain_sid
,
5366 const char *domain_name
,
5367 struct cli_state
*cli
,
5368 struct rpc_pipe_client
*pipe_hnd
,
5369 TALLOC_CTX
*mem_ctx
,
5373 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5374 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5377 DOM_SID trust_acct_sid
;
5378 uint32
*user_rids
, num_rids
, *name_types
;
5379 uint32 flags
= 0x000003e8; /* Unknown */
5382 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5383 return NT_STATUS_INVALID_PARAMETER
;
5387 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5389 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5391 if (acct_name
== NULL
)
5392 return NT_STATUS_NO_MEMORY
;
5394 strupper_m(acct_name
);
5396 names
= TALLOC_ARRAY(mem_ctx
, const char *, 1);
5397 names
[0] = acct_name
;
5400 /* Get samr policy handle */
5401 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
5403 if (!NT_STATUS_IS_OK(result
)) {
5407 /* Get domain policy handle */
5408 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
5409 MAXIMUM_ALLOWED_ACCESS
,
5410 domain_sid
, &domain_pol
);
5411 if (!NT_STATUS_IS_OK(result
)) {
5415 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, flags
, 1,
5417 &user_rids
, &name_types
);
5419 if (!NT_STATUS_IS_OK(result
)) {
5423 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
5424 MAXIMUM_ALLOWED_ACCESS
,
5425 user_rids
[0], &user_pol
);
5427 if (!NT_STATUS_IS_OK(result
)) {
5431 /* append the rid to the domain sid */
5432 sid_copy(&trust_acct_sid
, domain_sid
);
5433 if (!sid_append_rid(&trust_acct_sid
, user_rids
[0])) {
5437 /* remove the sid */
5439 result
= rpccli_samr_remove_sid_foreign_domain(pipe_hnd
, mem_ctx
, &user_pol
,
5442 if (!NT_STATUS_IS_OK(result
)) {
5448 result
= rpccli_samr_delete_dom_user(pipe_hnd
, mem_ctx
, &user_pol
);
5450 if (!NT_STATUS_IS_OK(result
)) {
5454 if (!NT_STATUS_IS_OK(result
)) {
5455 DEBUG(0,("Could not set trust account password: %s\n",
5456 nt_errstr(result
)));
5465 * Delete interdomain trust account for a remote domain.
5467 * @param argc standard argc
5468 * @param argv standard argv without initial components
5470 * @return Integer status (0 means success)
5473 static int rpc_trustdom_del(int argc
, const char **argv
)
5476 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_del_internals
,
5479 d_printf("Usage: net rpc trustdom del <domain>\n");
5486 * Establish trust relationship to a trusting domain.
5487 * Interdomain account must already be created on remote PDC.
5489 * @param argc standard argc
5490 * @param argv standard argv without initial components
5492 * @return Integer status (0 means success)
5495 static int rpc_trustdom_establish(int argc
, const char **argv
)
5497 struct cli_state
*cli
= NULL
;
5498 struct in_addr server_ip
;
5499 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5500 POLICY_HND connect_hnd
;
5501 TALLOC_CTX
*mem_ctx
;
5503 DOM_SID
*domain_sid
;
5506 char* domain_name_pol
;
5511 * Connect to \\server\ipc$ as 'our domain' account with password
5515 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
5519 domain_name
= smb_xstrdup(argv
[0]);
5520 strupper_m(domain_name
);
5522 /* account name used at first is our domain's name with '$' */
5523 asprintf(&acct_name
, "%s$", lp_workgroup());
5524 strupper_m(acct_name
);
5527 * opt_workgroup will be used by connection functions further,
5528 * hence it should be set to remote domain name instead of ours
5530 if (opt_workgroup
) {
5531 opt_workgroup
= smb_xstrdup(domain_name
);
5534 opt_user_name
= acct_name
;
5536 /* find the domain controller */
5537 if (!net_find_pdc(&server_ip
, pdc_name
, domain_name
)) {
5538 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5542 /* connect to ipc$ as username/password */
5543 nt_status
= connect_to_ipc(&cli
, &server_ip
, pdc_name
);
5544 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5546 /* Is it trusting domain account for sure ? */
5547 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5548 nt_errstr(nt_status
)));
5552 /* store who we connected to */
5554 saf_store( domain_name
, pdc_name
);
5557 * Connect to \\server\ipc$ again (this time anonymously)
5560 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ip
, (char*)pdc_name
);
5562 if (NT_STATUS_IS_ERR(nt_status
)) {
5563 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5564 domain_name
, nt_errstr(nt_status
)));
5568 * Use NetServerEnum2 to make sure we're talking to a proper server
5571 if (!cli_get_pdc_name(cli
, domain_name
, (char*)pdc_name
)) {
5572 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
5573 for domain %s\n", domain_name
));
5576 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5577 "domain %s", domain_name
))) {
5578 DEBUG(0, ("talloc_init() failed\n"));
5584 * Call LsaOpenPolicy and LsaQueryInfo
5587 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5589 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5594 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
5596 if (NT_STATUS_IS_ERR(nt_status
)) {
5597 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5598 nt_errstr(nt_status
)));
5603 /* Querying info level 5 */
5605 nt_status
= rpccli_lsa_query_info_policy(pipe_hnd
, mem_ctx
, &connect_hnd
,
5607 &domain_name_pol
, &domain_sid
);
5608 if (NT_STATUS_IS_ERR(nt_status
)) {
5609 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5610 nt_errstr(nt_status
)));
5615 /* There should be actually query info level 3 (following nt serv behaviour),
5616 but I still don't know if it's _really_ necessary */
5619 * Store the password in secrets db
5622 if (!secrets_store_trusted_domain_password(domain_name
,
5625 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5631 * Close the pipes and clean up
5634 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5635 if (NT_STATUS_IS_ERR(nt_status
)) {
5636 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5637 nt_errstr(nt_status
)));
5644 talloc_destroy(mem_ctx
);
5646 d_printf("Trust to domain %s established\n", domain_name
);
5651 * Revoke trust relationship to the remote domain
5653 * @param argc standard argc
5654 * @param argv standard argv without initial components
5656 * @return Integer status (0 means success)
5659 static int rpc_trustdom_revoke(int argc
, const char **argv
)
5663 if (argc
< 1) return -1;
5665 /* generate upper cased domain name */
5666 domain_name
= smb_xstrdup(argv
[0]);
5667 strupper_m(domain_name
);
5669 /* delete password of the trust */
5670 if (!trusted_domain_password_delete(domain_name
)) {
5671 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5680 * Usage for 'net rpc trustdom' command
5682 * @param argc standard argc
5683 * @param argv standard argv without inital components
5685 * @return Integer status returned to shell
5688 static int rpc_trustdom_usage(int argc
, const char **argv
)
5690 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
5691 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
5692 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
5693 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
5694 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
5695 d_printf(" net rpc trustdom vampire \t vampire interdomain trust relationships from remote server\n");
5700 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
5701 const char *domain_name
,
5702 struct cli_state
*cli
,
5703 struct rpc_pipe_client
*pipe_hnd
,
5704 TALLOC_CTX
*mem_ctx
,
5709 sid_to_string(str_sid
, domain_sid
);
5710 d_printf("%s\n", str_sid
);
5711 return NT_STATUS_OK
;
5714 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5716 fstring ascii_sid
, padding
;
5717 int pad_len
, col_len
= 20;
5719 /* convert sid into ascii string */
5720 sid_to_string(ascii_sid
, dom_sid
);
5722 /* calculate padding space for d_printf to look nicer */
5723 pad_len
= col_len
- strlen(trusted_dom_name
);
5724 padding
[pad_len
] = 0;
5725 do padding
[--pad_len
] = ' '; while (pad_len
);
5727 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5730 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5731 TALLOC_CTX
*mem_ctx
,
5734 const char *trusted_dom_name
)
5737 LSA_TRUSTED_DOMAIN_INFO
*info
;
5738 char *cleartextpwd
= NULL
;
5741 nt_status
= rpccli_lsa_query_trusted_domain_info_by_sid(pipe_hnd
, mem_ctx
, pol
, 4, &dom_sid
, &info
);
5743 if (NT_STATUS_IS_ERR(nt_status
)) {
5744 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5745 nt_errstr(nt_status
)));
5749 data
= data_blob(NULL
, info
->password
.password
.length
);
5751 memcpy(data
.data
, info
->password
.password
.data
, info
->password
.password
.length
);
5752 data
.length
= info
->password
.password
.length
;
5754 cleartextpwd
= decrypt_trustdom_secret(pipe_hnd
->cli
->pwd
.password
, &data
);
5756 if (cleartextpwd
== NULL
) {
5757 DEBUG(0,("retrieved NULL password\n"));
5758 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5762 if (!secrets_store_trusted_domain_password(trusted_dom_name
,
5765 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5766 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5770 #ifdef DEBUG_PASSWORD
5771 DEBUG(100,("sucessfully vampired trusted domain [%s], sid: [%s], password: [%s]\n",
5772 trusted_dom_name
, sid_string_static(&dom_sid
), cleartextpwd
));
5776 SAFE_FREE(cleartextpwd
);
5777 data_blob_free(&data
);
5782 static int rpc_trustdom_vampire(int argc
, const char **argv
)
5784 /* common variables */
5785 TALLOC_CTX
* mem_ctx
;
5786 struct cli_state
*cli
= NULL
;
5787 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5789 const char *domain_name
= NULL
;
5790 DOM_SID
*queried_dom_sid
;
5791 POLICY_HND connect_hnd
;
5793 /* trusted domains listing variables */
5794 unsigned int num_domains
, enum_ctx
= 0;
5796 DOM_SID
*domain_sids
;
5797 char **trusted_dom_names
;
5802 * Listing trusted domains (stored in secrets.tdb, if local)
5805 mem_ctx
= talloc_init("trust relationships vampire");
5808 * set domain and pdc name to local samba server (default)
5809 * or to remote one given in command line
5812 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
5813 domain_name
= opt_workgroup
;
5814 opt_target_workgroup
= opt_workgroup
;
5816 fstrcpy(pdc_name
, global_myname());
5817 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5818 opt_target_workgroup
= domain_name
;
5821 /* open \PIPE\lsarpc and open policy handle */
5822 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
5823 DEBUG(0, ("Couldn't connect to domain controller\n"));
5827 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5829 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5830 nt_errstr(nt_status
) ));
5835 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
5837 if (NT_STATUS_IS_ERR(nt_status
)) {
5838 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5839 nt_errstr(nt_status
)));
5844 /* query info level 5 to obtain sid of a domain being queried */
5845 nt_status
= rpccli_lsa_query_info_policy(
5846 pipe_hnd
, mem_ctx
, &connect_hnd
, 5 /* info level */,
5847 &dummy
, &queried_dom_sid
);
5849 if (NT_STATUS_IS_ERR(nt_status
)) {
5850 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5851 nt_errstr(nt_status
)));
5857 * Keep calling LsaEnumTrustdom over opened pipe until
5858 * the end of enumeration is reached
5861 d_printf("Vampire trusted domains:\n\n");
5864 nt_status
= rpccli_lsa_enum_trust_dom(pipe_hnd
, mem_ctx
, &connect_hnd
, &enum_ctx
,
5866 &trusted_dom_names
, &domain_sids
);
5868 if (NT_STATUS_IS_ERR(nt_status
)) {
5869 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5870 nt_errstr(nt_status
)));
5875 for (i
= 0; i
< num_domains
; i
++) {
5877 print_trusted_domain(&(domain_sids
[i
]), trusted_dom_names
[i
]);
5879 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5880 domain_sids
[i
], trusted_dom_names
[i
]);
5881 if (!NT_STATUS_IS_OK(nt_status
)) {
5888 * in case of no trusted domains say something rather
5889 * than just display blank line
5891 if (!num_domains
) d_printf("none\n");
5893 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5895 /* close this connection before doing next one */
5896 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5897 if (NT_STATUS_IS_ERR(nt_status
)) {
5898 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5899 nt_errstr(nt_status
)));
5904 /* close lsarpc pipe and connection to IPC$ */
5907 talloc_destroy(mem_ctx
);
5911 static int rpc_trustdom_list(int argc
, const char **argv
)
5913 /* common variables */
5914 TALLOC_CTX
* mem_ctx
;
5915 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5916 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5918 const char *domain_name
= NULL
;
5919 DOM_SID
*queried_dom_sid
;
5921 int ascii_dom_name_len
;
5922 POLICY_HND connect_hnd
;
5924 /* trusted domains listing variables */
5925 unsigned int num_domains
, enum_ctx
= 0;
5926 int i
, pad_len
, col_len
= 20;
5927 DOM_SID
*domain_sids
;
5928 char **trusted_dom_names
;
5932 /* trusting domains listing variables */
5933 POLICY_HND domain_hnd
;
5934 char **trusting_dom_names
;
5935 uint32
*trusting_dom_rids
;
5938 * Listing trusted domains (stored in secrets.tdb, if local)
5941 mem_ctx
= talloc_init("trust relationships listing");
5944 * set domain and pdc name to local samba server (default)
5945 * or to remote one given in command line
5948 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
5949 domain_name
= opt_workgroup
;
5950 opt_target_workgroup
= opt_workgroup
;
5952 fstrcpy(pdc_name
, global_myname());
5953 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5954 opt_target_workgroup
= domain_name
;
5957 /* open \PIPE\lsarpc and open policy handle */
5958 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
5959 DEBUG(0, ("Couldn't connect to domain controller\n"));
5963 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5965 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5966 nt_errstr(nt_status
) ));
5970 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
5972 if (NT_STATUS_IS_ERR(nt_status
)) {
5973 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5974 nt_errstr(nt_status
)));
5978 /* query info level 5 to obtain sid of a domain being queried */
5979 nt_status
= rpccli_lsa_query_info_policy(
5980 pipe_hnd
, mem_ctx
, &connect_hnd
, 5 /* info level */,
5981 &dummy
, &queried_dom_sid
);
5983 if (NT_STATUS_IS_ERR(nt_status
)) {
5984 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5985 nt_errstr(nt_status
)));
5990 * Keep calling LsaEnumTrustdom over opened pipe until
5991 * the end of enumeration is reached
5994 d_printf("Trusted domains list:\n\n");
5997 nt_status
= rpccli_lsa_enum_trust_dom(pipe_hnd
, mem_ctx
, &connect_hnd
, &enum_ctx
,
5999 &trusted_dom_names
, &domain_sids
);
6001 if (NT_STATUS_IS_ERR(nt_status
)) {
6002 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6003 nt_errstr(nt_status
)));
6007 for (i
= 0; i
< num_domains
; i
++) {
6008 print_trusted_domain(&(domain_sids
[i
]), trusted_dom_names
[i
]);
6012 * in case of no trusted domains say something rather
6013 * than just display blank line
6015 if (!num_domains
) d_printf("none\n");
6017 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6019 /* close this connection before doing next one */
6020 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6021 if (NT_STATUS_IS_ERR(nt_status
)) {
6022 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6023 nt_errstr(nt_status
)));
6027 cli_rpc_pipe_close(pipe_hnd
);
6030 * Listing trusting domains (stored in passdb backend, if local)
6033 d_printf("\nTrusting domains list:\n\n");
6036 * Open \PIPE\samr and get needed policy handles
6038 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_SAMR
, &nt_status
);
6040 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6045 nt_status
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, SA_RIGHT_SAM_OPEN_DOMAIN
,
6047 if (!NT_STATUS_IS_OK(nt_status
)) {
6048 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6049 nt_errstr(nt_status
)));
6053 /* SamrOpenDomain - we have to open domain policy handle in order to be
6054 able to enumerate accounts*/
6055 nt_status
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6056 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6057 queried_dom_sid
, &domain_hnd
);
6058 if (!NT_STATUS_IS_OK(nt_status
)) {
6059 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6060 nt_errstr(nt_status
)));
6065 * perform actual enumeration
6068 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6071 nt_status
= rpccli_samr_enum_dom_users(pipe_hnd
, mem_ctx
, &domain_hnd
,
6072 &enum_ctx
, ACB_DOMTRUST
, 0xffff,
6073 &trusting_dom_names
, &trusting_dom_rids
,
6075 if (NT_STATUS_IS_ERR(nt_status
)) {
6076 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6077 nt_errstr(nt_status
)));
6081 for (i
= 0; i
< num_domains
; i
++) {
6084 * get each single domain's sid (do we _really_ need this ?):
6085 * 1) connect to domain's pdc
6086 * 2) query the pdc for domain's sid
6089 /* get rid of '$' tail */
6090 ascii_dom_name_len
= strlen(trusting_dom_names
[i
]);
6091 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6092 trusting_dom_names
[i
][ascii_dom_name_len
- 1] = '\0';
6094 /* calculate padding space for d_printf to look nicer */
6095 pad_len
= col_len
- strlen(trusting_dom_names
[i
]);
6096 padding
[pad_len
] = 0;
6097 do padding
[--pad_len
] = ' '; while (pad_len
);
6099 /* set opt_* variables to remote domain */
6100 strupper_m(trusting_dom_names
[i
]);
6101 opt_workgroup
= talloc_strdup(mem_ctx
, trusting_dom_names
[i
]);
6102 opt_target_workgroup
= opt_workgroup
;
6104 d_printf("%s%s", trusting_dom_names
[i
], padding
);
6106 /* connect to remote domain controller */
6107 remote_cli
= net_make_ipc_connection(NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
);
6109 /* query for domain's sid */
6110 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
6111 d_fprintf(stderr
, "couldn't get domain's sid\n");
6113 cli_shutdown(remote_cli
);
6116 d_fprintf(stderr
, "domain controller is not responding\n");
6120 if (!num_domains
) d_printf("none\n");
6122 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6124 /* close opened samr and domain policy handles */
6125 nt_status
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6126 if (!NT_STATUS_IS_OK(nt_status
)) {
6127 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6130 nt_status
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6131 if (!NT_STATUS_IS_OK(nt_status
)) {
6132 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6135 /* close samr pipe and connection to IPC$ */
6138 talloc_destroy(mem_ctx
);
6143 * Entrypoint for 'net rpc trustdom' code
6145 * @param argc standard argc
6146 * @param argv standard argv without initial components
6148 * @return Integer status (0 means success)
6151 static int rpc_trustdom(int argc
, const char **argv
)
6153 struct functable func
[] = {
6154 {"add", rpc_trustdom_add
},
6155 {"del", rpc_trustdom_del
},
6156 {"establish", rpc_trustdom_establish
},
6157 {"revoke", rpc_trustdom_revoke
},
6158 {"help", rpc_trustdom_usage
},
6159 {"list", rpc_trustdom_list
},
6160 {"vampire", rpc_trustdom_vampire
},
6165 rpc_trustdom_usage(argc
, argv
);
6169 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6173 * Check if a server will take rpc commands
6174 * @param flags Type of server to connect to (PDC, DMB, localhost)
6175 * if the host is not explicitly specified
6176 * @return BOOL (true means rpc supported)
6178 BOOL
net_rpc_check(unsigned flags
)
6180 struct cli_state cli
;
6182 struct in_addr server_ip
;
6183 char *server_name
= NULL
;
6185 /* flags (i.e. server type) may depend on command */
6186 if (!net_find_server(flags
, &server_ip
, &server_name
))
6190 if (cli_initialise(&cli
) == False
)
6193 if (!cli_connect(&cli
, server_name
, &server_ip
))
6195 if (!attempt_netbios_session_request(&cli
, global_myname(),
6196 server_name
, &server_ip
))
6198 if (!cli_negprot(&cli
))
6200 if (cli
.protocol
< PROTOCOL_NT1
)
6209 /* dump sam database via samsync rpc calls */
6210 static int rpc_samdump(int argc
, const char **argv
) {
6211 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
6215 /* syncronise sam database via samsync rpc calls */
6216 static int rpc_vampire(int argc
, const char **argv
) {
6217 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
6222 * Migrate everything from a print-server
6224 * @param argc Standard main() style argc
6225 * @param argv Standard main() style argv. Initial components are already
6228 * @return A shell status integer (0 for success)
6230 * The order is important !
6231 * To successfully add drivers the print-queues have to exist !
6232 * Applying ACLs should be the last step, because you're easily locked out
6235 static int rpc_printer_migrate_all(int argc
, const char **argv
)
6240 printf("no server to migrate\n");
6244 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
6248 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
6252 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
6256 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
6260 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
6265 * Migrate print-drivers from a print-server
6267 * @param argc Standard main() style argc
6268 * @param argv Standard main() style argv. Initial components are already
6271 * @return A shell status integer (0 for success)
6273 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
6276 printf("no server to migrate\n");
6280 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6281 rpc_printer_migrate_drivers_internals
,
6286 * Migrate print-forms from a print-server
6288 * @param argc Standard main() style argc
6289 * @param argv Standard main() style argv. Initial components are already
6292 * @return A shell status integer (0 for success)
6294 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
6297 printf("no server to migrate\n");
6301 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6302 rpc_printer_migrate_forms_internals
,
6307 * Migrate printers from a print-server
6309 * @param argc Standard main() style argc
6310 * @param argv Standard main() style argv. Initial components are already
6313 * @return A shell status integer (0 for success)
6315 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
6318 printf("no server to migrate\n");
6322 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6323 rpc_printer_migrate_printers_internals
,
6328 * Migrate printer-ACLs from a print-server
6330 * @param argc Standard main() style argc
6331 * @param argv Standard main() style argv. Initial components are already
6334 * @return A shell status integer (0 for success)
6336 static int rpc_printer_migrate_security(int argc
, const char **argv
)
6339 printf("no server to migrate\n");
6343 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6344 rpc_printer_migrate_security_internals
,
6349 * Migrate printer-settings from a print-server
6351 * @param argc Standard main() style argc
6352 * @param argv Standard main() style argv. Initial components are already
6355 * @return A shell status integer (0 for success)
6357 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
6360 printf("no server to migrate\n");
6364 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6365 rpc_printer_migrate_settings_internals
,
6370 * 'net rpc printer' entrypoint.
6371 * @param argc Standard main() style argc
6372 * @param argv Standard main() style argv. Initial components are already
6376 int rpc_printer_migrate(int argc
, const char **argv
)
6379 /* ouch: when addriver and setdriver are called from within
6380 rpc_printer_migrate_drivers_internals, the printer-queue already
6383 struct functable func
[] = {
6384 {"all", rpc_printer_migrate_all
},
6385 {"drivers", rpc_printer_migrate_drivers
},
6386 {"forms", rpc_printer_migrate_forms
},
6387 {"help", rpc_printer_usage
},
6388 {"printers", rpc_printer_migrate_printers
},
6389 {"security", rpc_printer_migrate_security
},
6390 {"settings", rpc_printer_migrate_settings
},
6394 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6399 * List printers on a remote RPC server
6401 * @param argc Standard main() style argc
6402 * @param argv Standard main() style argv. Initial components are already
6405 * @return A shell status integer (0 for success)
6407 static int rpc_printer_list(int argc
, const char **argv
)
6410 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6411 rpc_printer_list_internals
,
6416 * List printer-drivers on a remote RPC server
6418 * @param argc Standard main() style argc
6419 * @param argv Standard main() style argv. Initial components are already
6422 * @return A shell status integer (0 for success)
6424 static int rpc_printer_driver_list(int argc
, const char **argv
)
6427 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6428 rpc_printer_driver_list_internals
,
6433 * Publish printer in ADS via MSRPC
6435 * @param argc Standard main() style argc
6436 * @param argv Standard main() style argv. Initial components are already
6439 * @return A shell status integer (0 for success)
6441 static int rpc_printer_publish_publish(int argc
, const char **argv
)
6444 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6445 rpc_printer_publish_publish_internals
,
6450 * Update printer in ADS via MSRPC
6452 * @param argc Standard main() style argc
6453 * @param argv Standard main() style argv. Initial components are already
6456 * @return A shell status integer (0 for success)
6458 static int rpc_printer_publish_update(int argc
, const char **argv
)
6461 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6462 rpc_printer_publish_update_internals
,
6467 * UnPublish printer in ADS via MSRPC
6469 * @param argc Standard main() style argc
6470 * @param argv Standard main() style argv. Initial components are already
6473 * @return A shell status integer (0 for success)
6475 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
6478 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6479 rpc_printer_publish_unpublish_internals
,
6484 * List published printers via MSRPC
6486 * @param argc Standard main() style argc
6487 * @param argv Standard main() style argv. Initial components are already
6490 * @return A shell status integer (0 for success)
6492 static int rpc_printer_publish_list(int argc
, const char **argv
)
6495 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6496 rpc_printer_publish_list_internals
,
6502 * Publish printer in ADS
6504 * @param argc Standard main() style argc
6505 * @param argv Standard main() style argv. Initial components are already
6508 * @return A shell status integer (0 for success)
6510 static int rpc_printer_publish(int argc
, const char **argv
)
6513 struct functable func
[] = {
6514 {"publish", rpc_printer_publish_publish
},
6515 {"update", rpc_printer_publish_update
},
6516 {"unpublish", rpc_printer_publish_unpublish
},
6517 {"list", rpc_printer_publish_list
},
6518 {"help", rpc_printer_usage
},
6523 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6524 rpc_printer_publish_list_internals
,
6527 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6533 * Display rpc printer help page.
6534 * @param argc Standard main() style argc
6535 * @param argv Standard main() style argv. Initial components are already
6538 int rpc_printer_usage(int argc
, const char **argv
)
6540 return net_help_printer(argc
, argv
);
6544 * 'net rpc printer' entrypoint.
6545 * @param argc Standard main() style argc
6546 * @param argv Standard main() style argv. Initial components are already
6549 int net_rpc_printer(int argc
, const char **argv
)
6551 struct functable func
[] = {
6552 {"list", rpc_printer_list
},
6553 {"migrate", rpc_printer_migrate
},
6554 {"driver", rpc_printer_driver_list
},
6555 {"publish", rpc_printer_publish
},
6560 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6561 rpc_printer_list_internals
,
6564 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6567 /****************************************************************************/
6571 * Basic usage function for 'net rpc'
6572 * @param argc Standard main() style argc
6573 * @param argv Standard main() style argv. Initial components are already
6577 int net_rpc_usage(int argc
, const char **argv
)
6579 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
6580 d_printf(" net rpc join \t\t\tto join a domain \n");
6581 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n");
6582 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
6583 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
6584 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
6585 d_printf(" net rpc group \t\tto list groups\n");
6586 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
6587 d_printf(" net rpc printer \t\tto list and migrate printers\n");
6588 d_printf(" net rpc file \t\t\tto list open files\n");
6589 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
6590 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
6591 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
6592 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
6593 d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n");
6594 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
6595 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
6596 d_printf(" net rpc rights\t\tto manage privileges assigned to SIDs\n");
6597 d_printf(" net rpc registry\t\tto manage registry hives\n");
6598 d_printf(" net rpc service\t\tto start, stop and query services\n");
6600 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
6601 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
6602 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
6603 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
6604 d_printf("\t-C or --comment=<message>\ttext message to display on impending shutdown\n");
6610 * Help function for 'net rpc'. Calls command specific help if requested
6611 * or displays usage of net rpc
6612 * @param argc Standard main() style argc
6613 * @param argv Standard main() style argv. Initial components are already
6617 int net_rpc_help(int argc
, const char **argv
)
6619 struct functable func
[] = {
6620 {"join", rpc_join_usage
},
6621 {"user", rpc_user_usage
},
6622 {"group", rpc_group_usage
},
6623 {"share", rpc_share_usage
},
6624 /*{"changetrustpw", rpc_changetrustpw_usage}, */
6625 {"trustdom", rpc_trustdom_usage
},
6626 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
6627 /*{"shutdown", rpc_shutdown_usage}, */
6628 {"vampire", rpc_vampire_usage
},
6633 net_rpc_usage(argc
, argv
);
6637 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6641 * 'net rpc' entrypoint.
6642 * @param argc Standard main() style argc
6643 * @param argv Standard main() style argv. Initial components are already
6647 int net_rpc(int argc
, const char **argv
)
6649 struct functable func
[] = {
6650 {"info", net_rpc_info
},
6651 {"join", net_rpc_join
},
6652 {"oldjoin", net_rpc_oldjoin
},
6653 {"testjoin", net_rpc_testjoin
},
6654 {"user", net_rpc_user
},
6655 {"password", rpc_user_password
},
6656 {"group", net_rpc_group
},
6657 {"share", net_rpc_share
},
6658 {"file", net_rpc_file
},
6659 {"printer", net_rpc_printer
},
6660 {"changetrustpw", net_rpc_changetrustpw
},
6661 {"trustdom", rpc_trustdom
},
6662 {"abortshutdown", rpc_shutdown_abort
},
6663 {"shutdown", rpc_shutdown
},
6664 {"samdump", rpc_samdump
},
6665 {"vampire", rpc_vampire
},
6666 {"getsid", net_rpc_getsid
},
6667 {"rights", net_rpc_rights
},
6668 {"service", net_rpc_service
},
6669 {"registry", net_rpc_registry
},
6670 {"shell", net_rpc_shell
},
6671 {"help", net_rpc_help
},
6674 return net_run_function(argc
, argv
, func
, net_rpc_usage
);