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 (lp_server_role() == ROLE_STANDALONE
) {
393 d_printf("cannot join as standalone machine\n");
397 if (strlen(global_myname()) > 15) {
398 d_printf("Our netbios name can be at most 15 chars long, "
399 "\"%s\" is %d chars long\n",
400 global_myname(), strlen(global_myname()));
404 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
407 return net_rpc_join_newstyle(argc
, argv
);
411 * display info about a rpc domain
413 * All parameters are provided by the run_rpc_command function, except for
414 * argc, argv which are passed through.
416 * @param domain_sid The domain sid acquired from the remote server
417 * @param cli A cli_state connected to the server.
418 * @param mem_ctx Talloc context, destoyed on completion of the function.
419 * @param argc Standard main() style argc
420 * @param argv Standard main() style argv. Initial components are already
423 * @return Normal NTSTATUS return.
426 NTSTATUS
rpc_info_internals(const DOM_SID
*domain_sid
,
427 const char *domain_name
,
428 struct cli_state
*cli
,
429 struct rpc_pipe_client
*pipe_hnd
,
434 POLICY_HND connect_pol
, domain_pol
;
435 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
439 sid_to_string(sid_str
, domain_sid
);
441 /* Get sam policy handle */
442 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
444 if (!NT_STATUS_IS_OK(result
)) {
445 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
449 /* Get domain policy handle */
450 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
451 MAXIMUM_ALLOWED_ACCESS
,
452 domain_sid
, &domain_pol
);
453 if (!NT_STATUS_IS_OK(result
)) {
454 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
459 result
= rpccli_samr_query_dom_info(pipe_hnd
, mem_ctx
, &domain_pol
,
461 if (NT_STATUS_IS_OK(result
)) {
462 TALLOC_CTX
*ctx
= talloc_init("rpc_info_internals");
463 d_printf("Domain Name: %s\n", unistr2_tdup(ctx
, &ctr
.info
.inf2
.uni_domain
));
464 d_printf("Domain SID: %s\n", sid_str
);
465 d_printf("Sequence number: %u\n", ctr
.info
.inf2
.seq_num
.low
);
466 d_printf("Num users: %u\n", ctr
.info
.inf2
.num_domain_usrs
);
467 d_printf("Num domain groups: %u\n", ctr
.info
.inf2
.num_domain_grps
);
468 d_printf("Num local groups: %u\n", ctr
.info
.inf2
.num_local_grps
);
477 * 'net rpc info' entrypoint.
478 * @param argc Standard main() style argc
479 * @param argc Standard main() style argv. Initial components are already
483 int net_rpc_info(int argc
, const char **argv
)
485 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_PDC
,
491 * Fetch domain SID into the local secrets.tdb
493 * All parameters are provided by the run_rpc_command function, except for
494 * argc, argv which are passes through.
496 * @param domain_sid The domain sid acquired from the remote server
497 * @param cli A cli_state connected to the server.
498 * @param mem_ctx Talloc context, destoyed on completion of the function.
499 * @param argc Standard main() style argc
500 * @param argv Standard main() style argv. Initial components are already
503 * @return Normal NTSTATUS return.
506 static NTSTATUS
rpc_getsid_internals(const DOM_SID
*domain_sid
,
507 const char *domain_name
,
508 struct cli_state
*cli
,
509 struct rpc_pipe_client
*pipe_hnd
,
516 sid_to_string(sid_str
, domain_sid
);
517 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
518 sid_str
, domain_name
);
520 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
521 DEBUG(0,("Can't store domain SID\n"));
522 return NT_STATUS_UNSUCCESSFUL
;
529 * 'net rpc getsid' entrypoint.
530 * @param argc Standard main() style argc
531 * @param argc Standard main() style argv. Initial components are already
535 int net_rpc_getsid(int argc
, const char **argv
)
537 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
538 rpc_getsid_internals
,
542 /****************************************************************************/
545 * Basic usage function for 'net rpc user'
546 * @param argc Standard main() style argc.
547 * @param argv Standard main() style argv. Initial components are already
551 static int rpc_user_usage(int argc
, const char **argv
)
553 return net_help_user(argc
, argv
);
557 * Add a new user to a remote RPC server
559 * All parameters are provided by the run_rpc_command function, except for
560 * argc, argv which are passes through.
562 * @param domain_sid The domain sid acquired from the remote server
563 * @param cli A cli_state connected to the server.
564 * @param mem_ctx Talloc context, destoyed on completion of the function.
565 * @param argc Standard main() style argc
566 * @param argv Standard main() style argv. Initial components are already
569 * @return Normal NTSTATUS return.
572 static NTSTATUS
rpc_user_add_internals(const DOM_SID
*domain_sid
,
573 const char *domain_name
,
574 struct cli_state
*cli
,
575 struct rpc_pipe_client
*pipe_hnd
,
577 int argc
, const char **argv
)
580 POLICY_HND connect_pol
, domain_pol
, user_pol
;
581 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
582 const char *acct_name
;
584 uint32 unknown
, user_rid
;
587 d_printf("User must be specified\n");
588 rpc_user_usage(argc
, argv
);
594 /* Get sam policy handle */
596 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
598 if (!NT_STATUS_IS_OK(result
)) {
602 /* Get domain policy handle */
604 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
605 MAXIMUM_ALLOWED_ACCESS
,
606 domain_sid
, &domain_pol
);
607 if (!NT_STATUS_IS_OK(result
)) {
611 /* Create domain user */
613 acb_info
= ACB_NORMAL
;
614 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
616 result
= rpccli_samr_create_dom_user(pipe_hnd
, mem_ctx
, &domain_pol
,
617 acct_name
, acb_info
, unknown
,
618 &user_pol
, &user_rid
);
619 if (!NT_STATUS_IS_OK(result
)) {
624 if (!NT_STATUS_IS_OK(result
)) {
625 d_fprintf(stderr
, "Failed to add user %s - %s\n", acct_name
,
628 d_printf("Added user %s\n", acct_name
);
634 * Add a new user to a remote RPC server
636 * @param argc Standard main() style argc
637 * @param argv Standard main() style argv. Initial components are already
640 * @return A shell status integer (0 for success)
643 static int rpc_user_add(int argc
, const char **argv
)
645 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_add_internals
,
650 * Delete a user from a remote RPC server
652 * All parameters are provided by the run_rpc_command function, except for
653 * argc, argv which are passes through.
655 * @param domain_sid The domain sid acquired from the remote server
656 * @param cli A cli_state connected to the server.
657 * @param mem_ctx Talloc context, destoyed on completion of the function.
658 * @param argc Standard main() style argc
659 * @param argv Standard main() style argv. Initial components are already
662 * @return Normal NTSTATUS return.
665 static NTSTATUS
rpc_user_del_internals(const DOM_SID
*domain_sid
,
666 const char *domain_name
,
667 struct cli_state
*cli
,
668 struct rpc_pipe_client
*pipe_hnd
,
673 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
674 POLICY_HND connect_pol
, domain_pol
, user_pol
;
677 d_printf("User must be specified\n");
678 rpc_user_usage(argc
, argv
);
681 /* Get sam policy and domain handles */
683 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
686 if (!NT_STATUS_IS_OK(result
)) {
690 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
691 MAXIMUM_ALLOWED_ACCESS
,
692 domain_sid
, &domain_pol
);
694 if (!NT_STATUS_IS_OK(result
)) {
698 /* Get handle on user */
701 uint32
*user_rids
, num_rids
, *name_types
;
702 uint32 flags
= 0x000003e8; /* Unknown */
704 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
706 &num_rids
, &user_rids
,
709 if (!NT_STATUS_IS_OK(result
)) {
713 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
714 MAXIMUM_ALLOWED_ACCESS
,
715 user_rids
[0], &user_pol
);
717 if (!NT_STATUS_IS_OK(result
)) {
724 result
= rpccli_samr_delete_dom_user(pipe_hnd
, mem_ctx
, &user_pol
);
726 if (!NT_STATUS_IS_OK(result
)) {
730 /* Display results */
731 if (!NT_STATUS_IS_OK(result
)) {
732 d_fprintf(stderr
, "Failed to delete user account - %s\n", nt_errstr(result
));
734 d_printf("Deleted user account\n");
742 * Rename a user on a remote RPC server
744 * All parameters are provided by the run_rpc_command function, except for
745 * argc, argv which are passes through.
747 * @param domain_sid The domain sid acquired from the remote server
748 * @param cli A cli_state connected to the server.
749 * @param mem_ctx Talloc context, destoyed on completion of the function.
750 * @param argc Standard main() style argc
751 * @param argv Standard main() style argv. Initial components are already
754 * @return Normal NTSTATUS return.
757 static NTSTATUS
rpc_user_rename_internals(const DOM_SID
*domain_sid
,
758 const char *domain_name
,
759 struct cli_state
*cli
,
760 struct rpc_pipe_client
*pipe_hnd
,
765 POLICY_HND connect_pol
, domain_pol
, user_pol
;
766 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
767 uint32 info_level
= 7;
768 const char *old_name
, *new_name
;
770 uint32 flags
= 0x000003e8; /* Unknown */
771 uint32 num_rids
, *name_types
;
772 uint32 num_names
= 1;
774 SAM_USERINFO_CTR
*user_ctr
;
775 SAM_USERINFO_CTR ctr
;
776 SAM_USER_INFO_7 info7
;
779 d_printf("Old and new username must be specified\n");
780 rpc_user_usage(argc
, argv
);
788 ZERO_STRUCT(user_ctr
);
790 /* Get sam policy handle */
792 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
794 if (!NT_STATUS_IS_OK(result
)) {
798 /* Get domain policy handle */
800 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
801 MAXIMUM_ALLOWED_ACCESS
,
802 domain_sid
, &domain_pol
);
803 if (!NT_STATUS_IS_OK(result
)) {
807 names
= TALLOC_ARRAY(mem_ctx
, const char *, num_names
);
809 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
810 flags
, num_names
, names
,
811 &num_rids
, &user_rid
, &name_types
);
812 if (!NT_STATUS_IS_OK(result
)) {
816 /* Open domain user */
817 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
818 MAXIMUM_ALLOWED_ACCESS
, user_rid
[0], &user_pol
);
820 if (!NT_STATUS_IS_OK(result
)) {
824 /* Query user info */
825 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
826 info_level
, &user_ctr
);
828 if (!NT_STATUS_IS_OK(result
)) {
832 ctr
.switch_value
= info_level
;
833 ctr
.info
.id7
= &info7
;
835 init_sam_user_info7(&info7
, new_name
);
838 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
839 info_level
, &cli
->user_session_key
, &ctr
);
841 if (!NT_STATUS_IS_OK(result
)) {
846 if (!NT_STATUS_IS_OK(result
)) {
847 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n", old_name
, new_name
,
850 d_printf("Renamed user from %s to %s\n", old_name
, new_name
);
856 * Rename a user on a remote RPC server
858 * @param argc Standard main() style argc
859 * @param argv Standard main() style argv. Initial components are already
862 * @return A shell status integer (0 for success)
865 static int rpc_user_rename(int argc
, const char **argv
)
867 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_rename_internals
,
872 * Delete a user from a remote RPC server
874 * @param argc Standard main() style argc
875 * @param argv Standard main() style argv. Initial components are already
878 * @return A shell status integer (0 for success)
881 static int rpc_user_delete(int argc
, const char **argv
)
883 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_del_internals
,
888 * Set a password for a user on a remote RPC server
890 * All parameters are provided by the run_rpc_command function, except for
891 * argc, argv which are passes through.
893 * @param domain_sid The domain sid acquired from the remote server
894 * @param cli A cli_state connected to the server.
895 * @param mem_ctx Talloc context, destoyed on completion of the function.
896 * @param argc Standard main() style argc
897 * @param argv Standard main() style argv. Initial components are already
900 * @return Normal NTSTATUS return.
903 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
904 const char *domain_name
,
905 struct cli_state
*cli
,
906 struct rpc_pipe_client
*pipe_hnd
,
911 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
912 POLICY_HND connect_pol
, domain_pol
, user_pol
;
913 SAM_USERINFO_CTR ctr
;
914 SAM_USER_INFO_24 p24
;
917 const char *new_password
;
921 d_printf("User must be specified\n");
922 rpc_user_usage(argc
, argv
);
929 new_password
= argv
[1];
931 asprintf(&prompt
, "Enter new password for %s:", user
);
932 new_password
= getpass(prompt
);
936 /* Get sam policy and domain handles */
938 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
941 if (!NT_STATUS_IS_OK(result
)) {
945 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
946 MAXIMUM_ALLOWED_ACCESS
,
947 domain_sid
, &domain_pol
);
949 if (!NT_STATUS_IS_OK(result
)) {
953 /* Get handle on user */
956 uint32
*user_rids
, num_rids
, *name_types
;
957 uint32 flags
= 0x000003e8; /* Unknown */
959 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
961 &num_rids
, &user_rids
,
964 if (!NT_STATUS_IS_OK(result
)) {
968 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
969 MAXIMUM_ALLOWED_ACCESS
,
970 user_rids
[0], &user_pol
);
972 if (!NT_STATUS_IS_OK(result
)) {
977 /* Set password on account */
982 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
984 init_sam_user_info24(&p24
, (char *)pwbuf
,24);
986 ctr
.switch_value
= 24;
987 ctr
.info
.id24
= &p24
;
989 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
, 24,
990 &cli
->user_session_key
, &ctr
);
992 if (!NT_STATUS_IS_OK(result
)) {
996 /* Display results */
1004 * Set a user's password on a remote RPC server
1006 * @param argc Standard main() style argc
1007 * @param argv Standard main() style argv. Initial components are already
1010 * @return A shell status integer (0 for success)
1013 static int rpc_user_password(int argc
, const char **argv
)
1015 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
1020 * List user's groups on a remote RPC server
1022 * All parameters are provided by the run_rpc_command function, except for
1023 * argc, argv which are passes through.
1025 * @param domain_sid The domain sid acquired from the remote server
1026 * @param cli A cli_state connected to the server.
1027 * @param mem_ctx Talloc context, destoyed on completion of the function.
1028 * @param argc Standard main() style argc
1029 * @param argv Standard main() style argv. Initial components are already
1032 * @return Normal NTSTATUS return.
1035 static NTSTATUS
rpc_user_info_internals(const DOM_SID
*domain_sid
,
1036 const char *domain_name
,
1037 struct cli_state
*cli
,
1038 struct rpc_pipe_client
*pipe_hnd
,
1039 TALLOC_CTX
*mem_ctx
,
1043 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1044 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1045 uint32
*rids
, num_rids
, *name_types
, num_names
;
1046 uint32 flags
= 0x000003e8; /* Unknown */
1052 d_printf("User must be specified\n");
1053 rpc_user_usage(argc
, argv
);
1054 return NT_STATUS_OK
;
1056 /* Get sam policy handle */
1058 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1060 if (!NT_STATUS_IS_OK(result
)) goto done
;
1062 /* Get domain policy handle */
1064 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1065 MAXIMUM_ALLOWED_ACCESS
,
1066 domain_sid
, &domain_pol
);
1067 if (!NT_STATUS_IS_OK(result
)) goto done
;
1069 /* Get handle on user */
1071 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
1073 &num_rids
, &rids
, &name_types
);
1075 if (!NT_STATUS_IS_OK(result
)) goto done
;
1077 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1078 MAXIMUM_ALLOWED_ACCESS
,
1079 rids
[0], &user_pol
);
1080 if (!NT_STATUS_IS_OK(result
)) goto done
;
1082 result
= rpccli_samr_query_usergroups(pipe_hnd
, mem_ctx
, &user_pol
,
1083 &num_rids
, &user_gids
);
1085 if (!NT_STATUS_IS_OK(result
)) goto done
;
1090 rids
= TALLOC_ARRAY(mem_ctx
, uint32
, num_rids
);
1092 for (i
= 0; i
< num_rids
; i
++)
1093 rids
[i
] = user_gids
[i
].g_rid
;
1095 result
= rpccli_samr_lookup_rids(pipe_hnd
, mem_ctx
, &domain_pol
,
1097 &num_names
, &names
, &name_types
);
1099 if (!NT_STATUS_IS_OK(result
)) {
1103 /* Display results */
1105 for (i
= 0; i
< num_names
; i
++)
1106 printf("%s\n", names
[i
]);
1113 * List a user's groups from a remote RPC server
1115 * @param argc Standard main() style argc
1116 * @param argv Standard main() style argv. Initial components are already
1119 * @return A shell status integer (0 for success)
1122 static int rpc_user_info(int argc
, const char **argv
)
1124 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
1129 * List users on a remote RPC server
1131 * All parameters are provided by the run_rpc_command function, except for
1132 * argc, argv which are passes through.
1134 * @param domain_sid The domain sid acquired from the remote server
1135 * @param cli A cli_state connected to the server.
1136 * @param mem_ctx Talloc context, destoyed on completion of the function.
1137 * @param argc Standard main() style argc
1138 * @param argv Standard main() style argv. Initial components are already
1141 * @return Normal NTSTATUS return.
1144 static NTSTATUS
rpc_user_list_internals(const DOM_SID
*domain_sid
,
1145 const char *domain_name
,
1146 struct cli_state
*cli
,
1147 struct rpc_pipe_client
*pipe_hnd
,
1148 TALLOC_CTX
*mem_ctx
,
1152 POLICY_HND connect_pol
, domain_pol
;
1153 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1154 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
1155 SAM_DISPINFO_CTR ctr
;
1156 SAM_DISPINFO_1 info1
;
1158 /* Get sam policy handle */
1160 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1162 if (!NT_STATUS_IS_OK(result
)) {
1166 /* Get domain policy handle */
1168 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1169 MAXIMUM_ALLOWED_ACCESS
,
1170 domain_sid
, &domain_pol
);
1171 if (!NT_STATUS_IS_OK(result
)) {
1175 /* Query domain users */
1178 ctr
.sam
.info1
= &info1
;
1179 if (opt_long_list_entries
)
1180 d_printf("\nUser name Comment"\
1181 "\n-----------------------------\n");
1184 uint32 max_entries
, max_size
;
1186 get_query_dispinfo_params(
1187 loop_count
, &max_entries
, &max_size
);
1189 result
= rpccli_samr_query_dispinfo(pipe_hnd
, mem_ctx
, &domain_pol
,
1190 &start_idx
, 1, &num_entries
,
1191 max_entries
, max_size
, &ctr
);
1194 for (i
= 0; i
< num_entries
; i
++) {
1195 unistr2_to_ascii(user
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_name
, sizeof(user
)-1);
1196 if (opt_long_list_entries
)
1197 unistr2_to_ascii(desc
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_desc
, sizeof(desc
)-1);
1199 if (opt_long_list_entries
)
1200 printf("%-21.21s %s\n", user
, desc
);
1202 printf("%s\n", user
);
1204 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1211 * 'net rpc user' entrypoint.
1212 * @param argc Standard main() style argc
1213 * @param argc Standard main() style argv. Initial components are already
1217 int net_rpc_user(int argc
, const char **argv
)
1219 struct functable func
[] = {
1220 {"add", rpc_user_add
},
1221 {"info", rpc_user_info
},
1222 {"delete", rpc_user_delete
},
1223 {"password", rpc_user_password
},
1224 {"rename", rpc_user_rename
},
1229 return run_rpc_command(NULL
,PI_SAMR
, 0,
1230 rpc_user_list_internals
,
1234 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1237 static NTSTATUS
rpc_sh_user_list(TALLOC_CTX
*mem_ctx
,
1238 struct rpc_sh_ctx
*ctx
,
1239 struct rpc_pipe_client
*pipe_hnd
,
1240 int argc
, const char **argv
)
1242 return rpc_user_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
1243 ctx
->cli
, pipe_hnd
, mem_ctx
,
1247 static NTSTATUS
rpc_sh_user_info(TALLOC_CTX
*mem_ctx
,
1248 struct rpc_sh_ctx
*ctx
,
1249 struct rpc_pipe_client
*pipe_hnd
,
1250 int argc
, const char **argv
)
1252 return rpc_user_info_internals(ctx
->domain_sid
, ctx
->domain_name
,
1253 ctx
->cli
, pipe_hnd
, mem_ctx
,
1257 static NTSTATUS
rpc_sh_handle_user(TALLOC_CTX
*mem_ctx
,
1258 struct rpc_sh_ctx
*ctx
,
1259 struct rpc_pipe_client
*pipe_hnd
,
1260 int argc
, const char **argv
,
1262 TALLOC_CTX
*mem_ctx
,
1263 struct rpc_sh_ctx
*ctx
,
1264 struct rpc_pipe_client
*pipe_hnd
,
1265 const POLICY_HND
*user_hnd
,
1266 int argc
, const char **argv
))
1269 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1270 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1273 enum SID_NAME_USE type
;
1276 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1277 return NT_STATUS_INVALID_PARAMETER
;
1280 ZERO_STRUCT(connect_pol
);
1281 ZERO_STRUCT(domain_pol
);
1282 ZERO_STRUCT(user_pol
);
1284 result
= net_rpc_lookup_name(mem_ctx
, pipe_hnd
->cli
, argv
[0],
1285 NULL
, NULL
, &sid
, &type
);
1286 if (!NT_STATUS_IS_OK(result
)) {
1287 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1292 if (type
!= SID_NAME_USER
) {
1293 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1294 sid_type_lookup(type
));
1295 result
= NT_STATUS_NO_SUCH_USER
;
1299 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1300 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1301 result
= NT_STATUS_NO_SUCH_USER
;
1305 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
,
1306 MAXIMUM_ALLOWED_ACCESS
, &connect_pol
);
1307 if (!NT_STATUS_IS_OK(result
)) {
1311 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1312 MAXIMUM_ALLOWED_ACCESS
,
1313 ctx
->domain_sid
, &domain_pol
);
1314 if (!NT_STATUS_IS_OK(result
)) {
1318 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1319 MAXIMUM_ALLOWED_ACCESS
,
1321 if (!NT_STATUS_IS_OK(result
)) {
1325 result
= fn(mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1328 if (is_valid_policy_hnd(&user_pol
)) {
1329 rpccli_samr_close(pipe_hnd
, mem_ctx
, &user_pol
);
1331 if (is_valid_policy_hnd(&domain_pol
)) {
1332 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
1334 if (is_valid_policy_hnd(&connect_pol
)) {
1335 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
1340 static NTSTATUS
rpc_sh_user_show_internals(TALLOC_CTX
*mem_ctx
,
1341 struct rpc_sh_ctx
*ctx
,
1342 struct rpc_pipe_client
*pipe_hnd
,
1343 const POLICY_HND
*user_hnd
,
1344 int argc
, const char **argv
)
1347 SAM_USERINFO_CTR
*ctr
;
1348 SAM_USER_INFO_21
*info
;
1351 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1352 return NT_STATUS_INVALID_PARAMETER
;
1355 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1357 if (!NT_STATUS_IS_OK(result
)) {
1361 info
= ctr
->info
.id21
;
1363 d_printf("user rid: %d, group rid: %d\n", info
->user_rid
,
1369 static NTSTATUS
rpc_sh_user_show(TALLOC_CTX
*mem_ctx
,
1370 struct rpc_sh_ctx
*ctx
,
1371 struct rpc_pipe_client
*pipe_hnd
,
1372 int argc
, const char **argv
)
1374 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1375 rpc_sh_user_show_internals
);
1378 #define FETCHSTR(name, rec) \
1379 do { if (strequal(ctx->thiscmd, name)) { \
1380 oldval = rpcstr_pull_unistr2_talloc(mem_ctx, &usr->uni_##rec); } \
1383 #define SETSTR(name, rec, flag) \
1384 do { if (strequal(ctx->thiscmd, name)) { \
1385 init_unistr2(&usr->uni_##rec, argv[0], STR_TERMINATE); \
1386 init_uni_hdr(&usr->hdr_##rec, &usr->uni_##rec); \
1387 usr->fields_present |= ACCT_##flag; } \
1390 static NTSTATUS
rpc_sh_user_str_edit_internals(TALLOC_CTX
*mem_ctx
,
1391 struct rpc_sh_ctx
*ctx
,
1392 struct rpc_pipe_client
*pipe_hnd
,
1393 const POLICY_HND
*user_hnd
,
1394 int argc
, const char **argv
)
1397 SAM_USERINFO_CTR
*ctr
;
1398 SAM_USER_INFO_21
*usr
;
1399 const char *username
;
1400 const char *oldval
= "";
1403 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1405 return NT_STATUS_INVALID_PARAMETER
;
1408 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1410 if (!NT_STATUS_IS_OK(result
)) {
1414 usr
= ctr
->info
.id21
;
1416 username
= rpcstr_pull_unistr2_talloc(mem_ctx
, &usr
->uni_user_name
);
1418 FETCHSTR("fullname", full_name
);
1419 FETCHSTR("homedir", home_dir
);
1420 FETCHSTR("homedrive", dir_drive
);
1421 FETCHSTR("logonscript", logon_script
);
1422 FETCHSTR("profilepath", profile_path
);
1423 FETCHSTR("description", acct_desc
);
1426 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1432 if (strcmp(argv
[0], "NULL") == 0) {
1436 SETSTR("fullname", full_name
, FULL_NAME
);
1437 SETSTR("homedir", home_dir
, HOME_DIR
);
1438 SETSTR("homedrive", dir_drive
, HOME_DRIVE
);
1439 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1440 SETSTR("profilepath", profile_path
, PROFILE
);
1441 SETSTR("description", acct_desc
, DESCRIPTION
);
1443 result
= rpccli_samr_set_userinfo2(
1444 pipe_hnd
, mem_ctx
, user_hnd
, 21,
1445 &pipe_hnd
->cli
->user_session_key
, ctr
);
1447 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1448 ctx
->thiscmd
, oldval
, argv
[0]);
1455 #define HANDLEFLG(name, rec) \
1456 do { if (strequal(ctx->thiscmd, name)) { \
1457 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1459 newflags = oldflags | ACB_##rec; \
1461 newflags = oldflags & ~ACB_##rec; \
1464 static NTSTATUS
rpc_sh_user_str_edit(TALLOC_CTX
*mem_ctx
,
1465 struct rpc_sh_ctx
*ctx
,
1466 struct rpc_pipe_client
*pipe_hnd
,
1467 int argc
, const char **argv
)
1469 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1470 rpc_sh_user_str_edit_internals
);
1473 static NTSTATUS
rpc_sh_user_flag_edit_internals(TALLOC_CTX
*mem_ctx
,
1474 struct rpc_sh_ctx
*ctx
,
1475 struct rpc_pipe_client
*pipe_hnd
,
1476 const POLICY_HND
*user_hnd
,
1477 int argc
, const char **argv
)
1480 SAM_USERINFO_CTR
*ctr
;
1481 SAM_USER_INFO_21
*usr
;
1482 const char *username
;
1483 const char *oldval
= "unknown";
1484 uint32 oldflags
, newflags
;
1488 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1489 !strequal(argv
[0], "no"))) {
1490 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1492 return NT_STATUS_INVALID_PARAMETER
;
1495 newval
= strequal(argv
[0], "yes");
1497 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, user_hnd
,
1499 if (!NT_STATUS_IS_OK(result
)) {
1503 usr
= ctr
->info
.id21
;
1505 username
= rpcstr_pull_unistr2_talloc(mem_ctx
, &usr
->uni_user_name
);
1506 oldflags
= usr
->acb_info
;
1507 newflags
= usr
->acb_info
;
1509 HANDLEFLG("disabled", DISABLED
);
1510 HANDLEFLG("pwnotreq", PWNOTREQ
);
1511 HANDLEFLG("autolock", AUTOLOCK
);
1512 HANDLEFLG("pwnoexp", PWNOEXP
);
1515 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1521 usr
->acb_info
= newflags
;
1522 usr
->fields_present
= ACCT_FLAGS
;
1524 result
= rpccli_samr_set_userinfo2(
1525 pipe_hnd
, mem_ctx
, user_hnd
, 21,
1526 &pipe_hnd
->cli
->user_session_key
, ctr
);
1528 if (NT_STATUS_IS_OK(result
)) {
1529 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1530 ctx
->thiscmd
, oldval
, argv
[0]);
1538 static NTSTATUS
rpc_sh_user_flag_edit(TALLOC_CTX
*mem_ctx
,
1539 struct rpc_sh_ctx
*ctx
,
1540 struct rpc_pipe_client
*pipe_hnd
,
1541 int argc
, const char **argv
)
1543 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1544 rpc_sh_user_flag_edit_internals
);
1547 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(TALLOC_CTX
*mem_ctx
,
1548 struct rpc_sh_ctx
*ctx
)
1550 static struct rpc_sh_cmd cmds
[] = {
1552 { "fullname", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1553 "Show/Set a user's full name" },
1555 { "homedir", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1556 "Show/Set a user's home directory" },
1558 { "homedrive", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1559 "Show/Set a user's home drive" },
1561 { "logonscript", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1562 "Show/Set a user's logon script" },
1564 { "profilepath", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1565 "Show/Set a user's profile path" },
1567 { "description", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1568 "Show/Set a user's description" },
1570 { "disabled", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1571 "Show/Set whether a user is disabled" },
1573 { "autolock", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1574 "Show/Set whether a user locked out" },
1576 { "pwnotreq", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1577 "Show/Set whether a user does not need a password" },
1579 { "pwnoexp", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1580 "Show/Set whether a user's password does not expire" },
1582 { NULL
, NULL
, 0, NULL
, NULL
}
1588 struct rpc_sh_cmd
*net_rpc_user_cmds(TALLOC_CTX
*mem_ctx
,
1589 struct rpc_sh_ctx
*ctx
)
1591 static struct rpc_sh_cmd cmds
[] = {
1593 { "list", NULL
, PI_SAMR
, rpc_sh_user_list
,
1594 "List available users" },
1596 { "info", NULL
, PI_SAMR
, rpc_sh_user_info
,
1597 "List the domain groups a user is member of" },
1599 { "show", NULL
, PI_SAMR
, rpc_sh_user_show
,
1600 "Show info about a user" },
1602 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1603 "Show/Modify a user's fields" },
1605 { NULL
, NULL
, 0, NULL
, NULL
}
1611 /****************************************************************************/
1614 * Basic usage function for 'net rpc group'
1615 * @param argc Standard main() style argc.
1616 * @param argv Standard main() style argv. Initial components are already
1620 static int rpc_group_usage(int argc
, const char **argv
)
1622 return net_help_group(argc
, argv
);
1626 * Delete group on a remote RPC server
1628 * All parameters are provided by the run_rpc_command function, except for
1629 * argc, argv which are passes through.
1631 * @param domain_sid The domain sid acquired from the remote server
1632 * @param cli A cli_state connected to the server.
1633 * @param mem_ctx Talloc context, destoyed on completion of the function.
1634 * @param argc Standard main() style argc
1635 * @param argv Standard main() style argv. Initial components are already
1638 * @return Normal NTSTATUS return.
1641 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1642 const char *domain_name
,
1643 struct cli_state
*cli
,
1644 struct rpc_pipe_client
*pipe_hnd
,
1645 TALLOC_CTX
*mem_ctx
,
1649 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1650 BOOL group_is_primary
= False
;
1651 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1653 uint32
*group_rids
, num_rids
, *name_types
, num_members
,
1654 *group_attrs
, group_rid
;
1655 uint32 flags
= 0x000003e8; /* Unknown */
1658 /* DOM_GID *user_gids; */
1659 SAM_USERINFO_CTR
*user_ctr
;
1663 d_printf("specify group\n");
1664 rpc_group_usage(argc
,argv
);
1665 return NT_STATUS_OK
; /* ok? */
1668 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1671 if (!NT_STATUS_IS_OK(result
)) {
1672 d_fprintf(stderr
, "Request samr_connect failed\n");
1676 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1677 MAXIMUM_ALLOWED_ACCESS
,
1678 domain_sid
, &domain_pol
);
1680 if (!NT_STATUS_IS_OK(result
)) {
1681 d_fprintf(stderr
, "Request open_domain failed\n");
1685 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
,
1687 &num_rids
, &group_rids
,
1690 if (!NT_STATUS_IS_OK(result
)) {
1691 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1695 switch (name_types
[0])
1697 case SID_NAME_DOM_GRP
:
1698 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
1699 MAXIMUM_ALLOWED_ACCESS
,
1700 group_rids
[0], &group_pol
);
1701 if (!NT_STATUS_IS_OK(result
)) {
1702 d_fprintf(stderr
, "Request open_group failed");
1706 group_rid
= group_rids
[0];
1708 result
= rpccli_samr_query_groupmem(pipe_hnd
, mem_ctx
, &group_pol
,
1709 &num_members
, &group_rids
,
1712 if (!NT_STATUS_IS_OK(result
)) {
1713 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1718 d_printf("Domain Group %s (rid: %d) has %d members\n",
1719 argv
[0],group_rid
,num_members
);
1722 /* Check if group is anyone's primary group */
1723 for (i
= 0; i
< num_members
; i
++)
1725 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
1726 MAXIMUM_ALLOWED_ACCESS
,
1727 group_rids
[i
], &user_pol
);
1729 if (!NT_STATUS_IS_OK(result
)) {
1730 d_fprintf(stderr
, "Unable to open group member %d\n",group_rids
[i
]);
1734 ZERO_STRUCT(user_ctr
);
1736 result
= rpccli_samr_query_userinfo(pipe_hnd
, mem_ctx
, &user_pol
,
1739 if (!NT_STATUS_IS_OK(result
)) {
1740 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",group_rids
[i
]);
1744 if (user_ctr
->info
.id21
->group_rid
== group_rid
) {
1745 unistr2_to_ascii(temp
, &(user_ctr
->info
.id21
)->uni_user_name
,
1748 d_printf("Group is primary group of %s\n",temp
);
1749 group_is_primary
= True
;
1752 rpccli_samr_close(pipe_hnd
, mem_ctx
, &user_pol
);
1755 if (group_is_primary
) {
1756 d_fprintf(stderr
, "Unable to delete group because some "
1757 "of it's members have it as primary group\n");
1758 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1762 /* remove all group members */
1763 for (i
= 0; i
< num_members
; i
++)
1766 d_printf("Remove group member %d...",group_rids
[i
]);
1767 result
= rpccli_samr_del_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, group_rids
[i
]);
1769 if (NT_STATUS_IS_OK(result
)) {
1774 d_printf("failed\n");
1779 result
= rpccli_samr_delete_dom_group(pipe_hnd
, mem_ctx
, &group_pol
);
1782 /* removing a local group is easier... */
1783 case SID_NAME_ALIAS
:
1784 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
1785 MAXIMUM_ALLOWED_ACCESS
,
1786 group_rids
[0], &group_pol
);
1788 if (!NT_STATUS_IS_OK(result
)) {
1789 d_fprintf(stderr
, "Request open_alias failed\n");
1793 result
= rpccli_samr_delete_dom_alias(pipe_hnd
, mem_ctx
, &group_pol
);
1796 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1797 argv
[0],sid_type_lookup(name_types
[0]));
1798 result
= NT_STATUS_UNSUCCESSFUL
;
1803 if (NT_STATUS_IS_OK(result
)) {
1805 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
[0]),argv
[0]);
1807 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1808 get_friendly_nt_error_msg(result
));
1816 static int rpc_group_delete(int argc
, const char **argv
)
1818 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1822 static NTSTATUS
rpc_group_add_internals(const DOM_SID
*domain_sid
,
1823 const char *domain_name
,
1824 struct cli_state
*cli
,
1825 struct rpc_pipe_client
*pipe_hnd
,
1826 TALLOC_CTX
*mem_ctx
,
1830 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1831 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1832 GROUP_INFO_CTR group_info
;
1835 d_printf("Group name must be specified\n");
1836 rpc_group_usage(argc
, argv
);
1837 return NT_STATUS_OK
;
1840 /* Get sam policy handle */
1842 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1844 if (!NT_STATUS_IS_OK(result
)) goto done
;
1846 /* Get domain policy handle */
1848 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1849 MAXIMUM_ALLOWED_ACCESS
,
1850 domain_sid
, &domain_pol
);
1851 if (!NT_STATUS_IS_OK(result
)) goto done
;
1853 /* Create the group */
1855 result
= rpccli_samr_create_dom_group(pipe_hnd
, mem_ctx
, &domain_pol
,
1856 argv
[0], MAXIMUM_ALLOWED_ACCESS
,
1858 if (!NT_STATUS_IS_OK(result
)) goto done
;
1860 if (strlen(opt_comment
) == 0) goto done
;
1862 /* We've got a comment to set */
1864 group_info
.switch_value1
= 4;
1865 init_samr_group_info4(&group_info
.group
.info4
, opt_comment
);
1867 result
= rpccli_samr_set_groupinfo(pipe_hnd
, mem_ctx
, &group_pol
, &group_info
);
1868 if (!NT_STATUS_IS_OK(result
)) goto done
;
1871 if (NT_STATUS_IS_OK(result
))
1872 DEBUG(5, ("add group succeeded\n"));
1874 d_fprintf(stderr
, "add group failed: %s\n", nt_errstr(result
));
1879 static NTSTATUS
rpc_alias_add_internals(const DOM_SID
*domain_sid
,
1880 const char *domain_name
,
1881 struct cli_state
*cli
,
1882 struct rpc_pipe_client
*pipe_hnd
,
1883 TALLOC_CTX
*mem_ctx
,
1887 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
1888 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1889 ALIAS_INFO_CTR alias_info
;
1892 d_printf("Alias name must be specified\n");
1893 rpc_group_usage(argc
, argv
);
1894 return NT_STATUS_OK
;
1897 /* Get sam policy handle */
1899 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1901 if (!NT_STATUS_IS_OK(result
)) goto done
;
1903 /* Get domain policy handle */
1905 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
1906 MAXIMUM_ALLOWED_ACCESS
,
1907 domain_sid
, &domain_pol
);
1908 if (!NT_STATUS_IS_OK(result
)) goto done
;
1910 /* Create the group */
1912 result
= rpccli_samr_create_dom_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
1913 argv
[0], &alias_pol
);
1914 if (!NT_STATUS_IS_OK(result
)) goto done
;
1916 if (strlen(opt_comment
) == 0) goto done
;
1918 /* We've got a comment to set */
1920 alias_info
.level
= 3;
1921 init_samr_alias_info3(&alias_info
.alias
.info3
, opt_comment
);
1923 result
= rpccli_samr_set_aliasinfo(pipe_hnd
, mem_ctx
, &alias_pol
, &alias_info
);
1924 if (!NT_STATUS_IS_OK(result
)) goto done
;
1927 if (NT_STATUS_IS_OK(result
))
1928 DEBUG(5, ("add alias succeeded\n"));
1930 d_fprintf(stderr
, "add alias failed: %s\n", nt_errstr(result
));
1935 static int rpc_group_add(int argc
, const char **argv
)
1938 return run_rpc_command(NULL
, PI_SAMR
, 0,
1939 rpc_alias_add_internals
,
1942 return run_rpc_command(NULL
, PI_SAMR
, 0,
1943 rpc_group_add_internals
,
1947 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1948 TALLOC_CTX
*mem_ctx
,
1951 enum SID_NAME_USE
*type
)
1953 DOM_SID
*sids
= NULL
;
1954 uint32
*types
= NULL
;
1955 struct rpc_pipe_client
*pipe_hnd
;
1957 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1959 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
1964 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, False
,
1965 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1967 if (!NT_STATUS_IS_OK(result
)) {
1971 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1972 &name
, NULL
, &sids
, &types
);
1974 if (NT_STATUS_IS_OK(result
)) {
1975 sid_copy(sid
, &sids
[0]);
1979 rpccli_lsa_close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1983 cli_rpc_pipe_close(pipe_hnd
);
1986 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1988 /* Try as S-1-5-whatever */
1992 if (string_to_sid(&tmp_sid
, name
)) {
1993 sid_copy(sid
, &tmp_sid
);
1994 *type
= SID_NAME_UNKNOWN
;
1995 result
= NT_STATUS_OK
;
2002 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2003 TALLOC_CTX
*mem_ctx
,
2004 const DOM_SID
*group_sid
,
2007 POLICY_HND connect_pol
, domain_pol
;
2010 POLICY_HND group_pol
;
2013 uint32
*rids
= NULL
;
2014 uint32
*rid_types
= NULL
;
2018 sid_copy(&sid
, group_sid
);
2020 if (!sid_split_rid(&sid
, &group_rid
)) {
2021 return NT_STATUS_UNSUCCESSFUL
;
2024 /* Get sam policy handle */
2025 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2027 if (!NT_STATUS_IS_OK(result
)) {
2031 /* Get domain policy handle */
2032 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2033 MAXIMUM_ALLOWED_ACCESS
,
2035 if (!NT_STATUS_IS_OK(result
)) {
2039 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2041 &num_rids
, &rids
, &rid_types
);
2043 if (!NT_STATUS_IS_OK(result
)) {
2044 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2048 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2049 MAXIMUM_ALLOWED_ACCESS
,
2050 group_rid
, &group_pol
);
2052 if (!NT_STATUS_IS_OK(result
)) {
2056 result
= rpccli_samr_add_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, rids
[0]);
2059 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2063 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2064 TALLOC_CTX
*mem_ctx
,
2065 const DOM_SID
*alias_sid
,
2068 POLICY_HND connect_pol
, domain_pol
;
2071 POLICY_HND alias_pol
;
2074 enum SID_NAME_USE member_type
;
2078 sid_copy(&sid
, alias_sid
);
2080 if (!sid_split_rid(&sid
, &alias_rid
)) {
2081 return NT_STATUS_UNSUCCESSFUL
;
2084 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2085 &member_sid
, &member_type
);
2087 if (!NT_STATUS_IS_OK(result
)) {
2088 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2092 /* Get sam policy handle */
2093 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2095 if (!NT_STATUS_IS_OK(result
)) {
2099 /* Get domain policy handle */
2100 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2101 MAXIMUM_ALLOWED_ACCESS
,
2103 if (!NT_STATUS_IS_OK(result
)) {
2107 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
2108 MAXIMUM_ALLOWED_ACCESS
,
2109 alias_rid
, &alias_pol
);
2111 if (!NT_STATUS_IS_OK(result
)) {
2115 result
= rpccli_samr_add_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
, &member_sid
);
2117 if (!NT_STATUS_IS_OK(result
)) {
2122 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2126 static NTSTATUS
rpc_group_addmem_internals(const DOM_SID
*domain_sid
,
2127 const char *domain_name
,
2128 struct cli_state
*cli
,
2129 struct rpc_pipe_client
*pipe_hnd
,
2130 TALLOC_CTX
*mem_ctx
,
2135 enum SID_NAME_USE group_type
;
2138 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
2139 return NT_STATUS_UNSUCCESSFUL
;
2142 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2143 &group_sid
, &group_type
))) {
2144 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2145 return NT_STATUS_UNSUCCESSFUL
;
2148 if (group_type
== SID_NAME_DOM_GRP
) {
2149 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2150 &group_sid
, argv
[1]);
2152 if (!NT_STATUS_IS_OK(result
)) {
2153 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2154 argv
[1], argv
[0], nt_errstr(result
));
2159 if (group_type
== SID_NAME_ALIAS
) {
2160 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
2161 &group_sid
, argv
[1]);
2163 if (!NT_STATUS_IS_OK(result
)) {
2164 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2165 argv
[1], argv
[0], nt_errstr(result
));
2170 d_fprintf(stderr
, "Can only add members to global or local groups "
2171 "which %s is not\n", argv
[0]);
2173 return NT_STATUS_UNSUCCESSFUL
;
2176 static int rpc_group_addmem(int argc
, const char **argv
)
2178 return run_rpc_command(NULL
, PI_SAMR
, 0,
2179 rpc_group_addmem_internals
,
2183 static NTSTATUS
rpc_del_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2184 TALLOC_CTX
*mem_ctx
,
2185 const DOM_SID
*group_sid
,
2188 POLICY_HND connect_pol
, domain_pol
;
2191 POLICY_HND group_pol
;
2194 uint32
*rids
= NULL
;
2195 uint32
*rid_types
= NULL
;
2199 sid_copy(&sid
, group_sid
);
2201 if (!sid_split_rid(&sid
, &group_rid
))
2202 return NT_STATUS_UNSUCCESSFUL
;
2204 /* Get sam policy handle */
2205 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2207 if (!NT_STATUS_IS_OK(result
))
2210 /* Get domain policy handle */
2211 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2212 MAXIMUM_ALLOWED_ACCESS
,
2214 if (!NT_STATUS_IS_OK(result
))
2217 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2219 &num_rids
, &rids
, &rid_types
);
2221 if (!NT_STATUS_IS_OK(result
)) {
2222 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2226 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2227 MAXIMUM_ALLOWED_ACCESS
,
2228 group_rid
, &group_pol
);
2230 if (!NT_STATUS_IS_OK(result
))
2233 result
= rpccli_samr_del_groupmem(pipe_hnd
, mem_ctx
, &group_pol
, rids
[0]);
2236 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2240 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2241 TALLOC_CTX
*mem_ctx
,
2242 const DOM_SID
*alias_sid
,
2245 POLICY_HND connect_pol
, domain_pol
;
2248 POLICY_HND alias_pol
;
2251 enum SID_NAME_USE member_type
;
2255 sid_copy(&sid
, alias_sid
);
2257 if (!sid_split_rid(&sid
, &alias_rid
))
2258 return NT_STATUS_UNSUCCESSFUL
;
2260 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2261 &member_sid
, &member_type
);
2263 if (!NT_STATUS_IS_OK(result
)) {
2264 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2268 /* Get sam policy handle */
2269 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2271 if (!NT_STATUS_IS_OK(result
)) {
2275 /* Get domain policy handle */
2276 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2277 MAXIMUM_ALLOWED_ACCESS
,
2279 if (!NT_STATUS_IS_OK(result
)) {
2283 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
2284 MAXIMUM_ALLOWED_ACCESS
,
2285 alias_rid
, &alias_pol
);
2287 if (!NT_STATUS_IS_OK(result
))
2290 result
= rpccli_samr_del_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
, &member_sid
);
2292 if (!NT_STATUS_IS_OK(result
))
2296 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
2300 static NTSTATUS
rpc_group_delmem_internals(const DOM_SID
*domain_sid
,
2301 const char *domain_name
,
2302 struct cli_state
*cli
,
2303 struct rpc_pipe_client
*pipe_hnd
,
2304 TALLOC_CTX
*mem_ctx
,
2309 enum SID_NAME_USE group_type
;
2312 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
2313 return NT_STATUS_UNSUCCESSFUL
;
2316 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2317 &group_sid
, &group_type
))) {
2318 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2319 return NT_STATUS_UNSUCCESSFUL
;
2322 if (group_type
== SID_NAME_DOM_GRP
) {
2323 NTSTATUS result
= rpc_del_groupmem(pipe_hnd
, mem_ctx
,
2324 &group_sid
, argv
[1]);
2326 if (!NT_STATUS_IS_OK(result
)) {
2327 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2328 argv
[1], argv
[0], nt_errstr(result
));
2333 if (group_type
== SID_NAME_ALIAS
) {
2334 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2335 &group_sid
, argv
[1]);
2337 if (!NT_STATUS_IS_OK(result
)) {
2338 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2339 argv
[1], argv
[0], nt_errstr(result
));
2344 d_fprintf(stderr
, "Can only delete members from global or local groups "
2345 "which %s is not\n", argv
[0]);
2347 return NT_STATUS_UNSUCCESSFUL
;
2350 static int rpc_group_delmem(int argc
, const char **argv
)
2352 return run_rpc_command(NULL
, PI_SAMR
, 0,
2353 rpc_group_delmem_internals
,
2358 * List groups on a remote RPC server
2360 * All parameters are provided by the run_rpc_command function, except for
2361 * argc, argv which are passes through.
2363 * @param domain_sid The domain sid acquired from the remote server
2364 * @param cli A cli_state connected to the server.
2365 * @param mem_ctx Talloc context, destoyed on completion of the function.
2366 * @param argc Standard main() style argc
2367 * @param argv Standard main() style argv. Initial components are already
2370 * @return Normal NTSTATUS return.
2373 static NTSTATUS
rpc_group_list_internals(const DOM_SID
*domain_sid
,
2374 const char *domain_name
,
2375 struct cli_state
*cli
,
2376 struct rpc_pipe_client
*pipe_hnd
,
2377 TALLOC_CTX
*mem_ctx
,
2381 POLICY_HND connect_pol
, domain_pol
;
2382 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2383 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2384 struct acct_info
*groups
;
2385 BOOL global
= False
;
2387 BOOL builtin
= False
;
2395 for (i
=0; i
<argc
; i
++) {
2396 if (strequal(argv
[i
], "global"))
2399 if (strequal(argv
[i
], "local"))
2402 if (strequal(argv
[i
], "builtin"))
2406 /* Get sam policy handle */
2408 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2410 if (!NT_STATUS_IS_OK(result
)) {
2414 /* Get domain policy handle */
2416 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2417 MAXIMUM_ALLOWED_ACCESS
,
2418 domain_sid
, &domain_pol
);
2419 if (!NT_STATUS_IS_OK(result
)) {
2423 /* Query domain groups */
2424 if (opt_long_list_entries
)
2425 d_printf("\nGroup name Comment"\
2426 "\n-----------------------------\n");
2428 SAM_DISPINFO_CTR ctr
;
2429 SAM_DISPINFO_3 info3
;
2434 ctr
.sam
.info3
= &info3
;
2438 get_query_dispinfo_params(
2439 loop_count
, &max_entries
, &max_size
);
2441 result
= rpccli_samr_query_dispinfo(pipe_hnd
, mem_ctx
, &domain_pol
,
2442 &start_idx
, 3, &num_entries
,
2443 max_entries
, max_size
, &ctr
);
2445 if (!NT_STATUS_IS_OK(result
) &&
2446 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2449 for (i
= 0; i
< num_entries
; i
++) {
2451 fstring group
, desc
;
2453 unistr2_to_ascii(group
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_name
, sizeof(group
)-1);
2454 unistr2_to_ascii(desc
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_desc
, sizeof(desc
)-1);
2456 if (opt_long_list_entries
)
2457 printf("%-21.21s %-50.50s\n",
2460 printf("%s\n", group
);
2462 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2463 /* query domain aliases */
2468 /* The max_size field in cli_samr_enum_als_groups is more like
2469 * an account_control field with indiviual bits what to
2470 * retrieve. Set this to 0xffff as NT4 usrmgr.exe does to get
2471 * everything. I'm too lazy (sorry) to get this through to
2472 * rpc_parse/ etc. Volker */
2474 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
2476 &groups
, &num_entries
);
2478 if (!NT_STATUS_IS_OK(result
) &&
2479 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2482 for (i
= 0; i
< num_entries
; i
++) {
2484 char *description
= NULL
;
2486 if (opt_long_list_entries
) {
2488 POLICY_HND alias_pol
;
2491 if ((NT_STATUS_IS_OK(rpccli_samr_open_alias(pipe_hnd
, mem_ctx
,
2496 (NT_STATUS_IS_OK(rpccli_samr_query_alias_info(pipe_hnd
, mem_ctx
,
2499 (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd
, mem_ctx
,
2501 description
= unistr2_tdup(mem_ctx
,
2502 ctr
.alias
.info3
.description
.string
);
2506 if (description
!= NULL
) {
2507 printf("%-21.21s %-50.50s\n",
2508 groups
[i
].acct_name
,
2511 printf("%s\n", groups
[i
].acct_name
);
2514 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2515 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
2516 /* Get builtin policy handle */
2518 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2519 MAXIMUM_ALLOWED_ACCESS
,
2520 &global_sid_Builtin
, &domain_pol
);
2521 if (!NT_STATUS_IS_OK(result
)) {
2524 /* query builtin aliases */
2527 if (!builtin
) break;
2529 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
2530 &start_idx
, max_entries
,
2531 &groups
, &num_entries
);
2533 if (!NT_STATUS_IS_OK(result
) &&
2534 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2537 for (i
= 0; i
< num_entries
; i
++) {
2539 char *description
= NULL
;
2541 if (opt_long_list_entries
) {
2543 POLICY_HND alias_pol
;
2546 if ((NT_STATUS_IS_OK(rpccli_samr_open_alias(pipe_hnd
, mem_ctx
,
2551 (NT_STATUS_IS_OK(rpccli_samr_query_alias_info(pipe_hnd
, mem_ctx
,
2554 (NT_STATUS_IS_OK(rpccli_samr_close(pipe_hnd
, mem_ctx
,
2556 description
= unistr2_tdup(mem_ctx
,
2557 ctr
.alias
.info3
.description
.string
);
2561 if (description
!= NULL
) {
2562 printf("%-21.21s %-50.50s\n",
2563 groups
[i
].acct_name
,
2566 printf("%s\n", groups
[i
].acct_name
);
2569 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2575 static int rpc_group_list(int argc
, const char **argv
)
2577 return run_rpc_command(NULL
, PI_SAMR
, 0,
2578 rpc_group_list_internals
,
2582 static NTSTATUS
rpc_list_group_members(struct rpc_pipe_client
*pipe_hnd
,
2583 TALLOC_CTX
*mem_ctx
,
2584 const char *domain_name
,
2585 const DOM_SID
*domain_sid
,
2586 POLICY_HND
*domain_pol
,
2590 POLICY_HND group_pol
;
2591 uint32 num_members
, *group_rids
, *group_attrs
;
2598 sid_to_string(sid_str
, domain_sid
);
2600 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, domain_pol
,
2601 MAXIMUM_ALLOWED_ACCESS
,
2604 if (!NT_STATUS_IS_OK(result
))
2607 result
= rpccli_samr_query_groupmem(pipe_hnd
, mem_ctx
, &group_pol
,
2608 &num_members
, &group_rids
,
2611 if (!NT_STATUS_IS_OK(result
))
2614 while (num_members
> 0) {
2615 int this_time
= 512;
2617 if (num_members
< this_time
)
2618 this_time
= num_members
;
2620 result
= rpccli_samr_lookup_rids(pipe_hnd
, mem_ctx
, domain_pol
,
2621 this_time
, group_rids
,
2622 &num_names
, &names
, &name_types
);
2624 if (!NT_STATUS_IS_OK(result
))
2627 /* We only have users as members, but make the output
2628 the same as the output of alias members */
2630 for (i
= 0; i
< this_time
; i
++) {
2632 if (opt_long_list_entries
) {
2633 printf("%s-%d %s\\%s %d\n", sid_str
,
2634 group_rids
[i
], domain_name
, names
[i
],
2637 printf("%s\\%s\n", domain_name
, names
[i
]);
2641 num_members
-= this_time
;
2645 return NT_STATUS_OK
;
2648 static NTSTATUS
rpc_list_alias_members(struct rpc_pipe_client
*pipe_hnd
,
2649 TALLOC_CTX
*mem_ctx
,
2650 POLICY_HND
*domain_pol
,
2654 struct rpc_pipe_client
*lsa_pipe
;
2655 POLICY_HND alias_pol
, lsa_pol
;
2657 DOM_SID
*alias_sids
;
2663 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, domain_pol
,
2664 MAXIMUM_ALLOWED_ACCESS
, rid
, &alias_pol
);
2666 if (!NT_STATUS_IS_OK(result
))
2669 result
= rpccli_samr_query_aliasmem(pipe_hnd
, mem_ctx
, &alias_pol
,
2670 &num_members
, &alias_sids
);
2672 if (!NT_STATUS_IS_OK(result
)) {
2673 d_fprintf(stderr
, "Couldn't list alias members\n");
2677 if (num_members
== 0) {
2678 return NT_STATUS_OK
;
2681 lsa_pipe
= cli_rpc_pipe_open_noauth(pipe_hnd
->cli
, PI_LSARPC
, &result
);
2683 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2684 nt_errstr(result
) );
2688 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, True
,
2689 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2691 if (!NT_STATUS_IS_OK(result
)) {
2692 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2693 cli_rpc_pipe_close(lsa_pipe
);
2697 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
, num_members
,
2699 &domains
, &names
, &types
);
2701 if (!NT_STATUS_IS_OK(result
) &&
2702 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2703 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2704 cli_rpc_pipe_close(lsa_pipe
);
2708 for (i
= 0; i
< num_members
; i
++) {
2710 sid_to_string(sid_str
, &alias_sids
[i
]);
2712 if (opt_long_list_entries
) {
2713 printf("%s %s\\%s %d\n", sid_str
,
2714 domains
[i
] ? domains
[i
] : "*unknown*",
2715 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2718 printf("%s\\%s\n", domains
[i
], names
[i
]);
2720 printf("%s\n", sid_str
);
2724 cli_rpc_pipe_close(lsa_pipe
);
2725 return NT_STATUS_OK
;
2728 static NTSTATUS
rpc_group_members_internals(const DOM_SID
*domain_sid
,
2729 const char *domain_name
,
2730 struct cli_state
*cli
,
2731 struct rpc_pipe_client
*pipe_hnd
,
2732 TALLOC_CTX
*mem_ctx
,
2737 POLICY_HND connect_pol
, domain_pol
;
2738 uint32 num_rids
, *rids
, *rid_types
;
2740 /* Get sam policy handle */
2742 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2745 if (!NT_STATUS_IS_OK(result
))
2748 /* Get domain policy handle */
2750 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2751 MAXIMUM_ALLOWED_ACCESS
,
2752 domain_sid
, &domain_pol
);
2754 if (!NT_STATUS_IS_OK(result
))
2757 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2758 1, argv
, &num_rids
, &rids
, &rid_types
);
2760 if (!NT_STATUS_IS_OK(result
)) {
2762 /* Ok, did not find it in the global sam, try with builtin */
2764 DOM_SID sid_Builtin
;
2766 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
2768 string_to_sid(&sid_Builtin
, "S-1-5-32");
2770 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2771 MAXIMUM_ALLOWED_ACCESS
,
2772 &sid_Builtin
, &domain_pol
);
2774 if (!NT_STATUS_IS_OK(result
)) {
2775 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2779 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2783 if (!NT_STATUS_IS_OK(result
)) {
2784 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2789 if (num_rids
!= 1) {
2790 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2794 if (rid_types
[0] == SID_NAME_DOM_GRP
) {
2795 return rpc_list_group_members(pipe_hnd
, mem_ctx
, domain_name
,
2796 domain_sid
, &domain_pol
,
2800 if (rid_types
[0] == SID_NAME_ALIAS
) {
2801 return rpc_list_alias_members(pipe_hnd
, mem_ctx
, &domain_pol
,
2805 return NT_STATUS_NO_SUCH_GROUP
;
2808 static int rpc_group_members(int argc
, const char **argv
)
2811 return rpc_group_usage(argc
, argv
);
2814 return run_rpc_command(NULL
, PI_SAMR
, 0,
2815 rpc_group_members_internals
,
2819 static NTSTATUS
rpc_group_rename_internals(const DOM_SID
*domain_sid
,
2820 const char *domain_name
,
2821 struct cli_state
*cli
,
2822 struct rpc_pipe_client
*pipe_hnd
,
2823 TALLOC_CTX
*mem_ctx
,
2828 POLICY_HND connect_pol
, domain_pol
, group_pol
;
2829 uint32 num_rids
, *rids
, *rid_types
;
2833 d_printf("Usage: 'net rpc group rename group newname'\n");
2834 return NT_STATUS_UNSUCCESSFUL
;
2837 /* Get sam policy handle */
2839 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2842 if (!NT_STATUS_IS_OK(result
))
2845 /* Get domain policy handle */
2847 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
2848 MAXIMUM_ALLOWED_ACCESS
,
2849 domain_sid
, &domain_pol
);
2851 if (!NT_STATUS_IS_OK(result
))
2854 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, 1000,
2855 1, argv
, &num_rids
, &rids
, &rid_types
);
2857 if (num_rids
!= 1) {
2858 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2862 if (rid_types
[0] != SID_NAME_DOM_GRP
) {
2863 d_fprintf(stderr
, "Can only rename domain groups\n");
2864 return NT_STATUS_UNSUCCESSFUL
;
2867 result
= rpccli_samr_open_group(pipe_hnd
, mem_ctx
, &domain_pol
,
2868 MAXIMUM_ALLOWED_ACCESS
,
2869 rids
[0], &group_pol
);
2871 if (!NT_STATUS_IS_OK(result
))
2876 ctr
.switch_value1
= 2;
2877 init_samr_group_info2(&ctr
.group
.info2
, argv
[1]);
2879 result
= rpccli_samr_set_groupinfo(pipe_hnd
, mem_ctx
, &group_pol
, &ctr
);
2881 if (!NT_STATUS_IS_OK(result
))
2884 return NT_STATUS_NO_SUCH_GROUP
;
2887 static int rpc_group_rename(int argc
, const char **argv
)
2890 return rpc_group_usage(argc
, argv
);
2893 return run_rpc_command(NULL
, PI_SAMR
, 0,
2894 rpc_group_rename_internals
,
2899 * 'net rpc group' entrypoint.
2900 * @param argc Standard main() style argc
2901 * @param argc Standard main() style argv. Initial components are already
2905 int net_rpc_group(int argc
, const char **argv
)
2907 struct functable func
[] = {
2908 {"add", rpc_group_add
},
2909 {"delete", rpc_group_delete
},
2910 {"addmem", rpc_group_addmem
},
2911 {"delmem", rpc_group_delmem
},
2912 {"list", rpc_group_list
},
2913 {"members", rpc_group_members
},
2914 {"rename", rpc_group_rename
},
2919 return run_rpc_command(NULL
, PI_SAMR
, 0,
2920 rpc_group_list_internals
,
2924 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
2927 /****************************************************************************/
2929 static int rpc_share_usage(int argc
, const char **argv
)
2931 return net_help_share(argc
, argv
);
2935 * Add a share on a remote RPC server
2937 * All parameters are provided by the run_rpc_command function, except for
2938 * argc, argv which are passes through.
2940 * @param domain_sid The domain sid acquired from the remote server
2941 * @param cli A cli_state connected to the server.
2942 * @param mem_ctx Talloc context, destoyed on completion of the function.
2943 * @param argc Standard main() style argc
2944 * @param argv Standard main() style argv. Initial components are already
2947 * @return Normal NTSTATUS return.
2949 static NTSTATUS
rpc_share_add_internals(const DOM_SID
*domain_sid
,
2950 const char *domain_name
,
2951 struct cli_state
*cli
,
2952 struct rpc_pipe_client
*pipe_hnd
,
2953 TALLOC_CTX
*mem_ctx
,int argc
,
2957 char *sharename
=talloc_strdup(mem_ctx
, argv
[0]);
2959 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2960 uint32 num_users
=0, perms
=0;
2961 char *password
=NULL
; /* don't allow a share password */
2964 path
= strchr(sharename
, '=');
2966 return NT_STATUS_UNSUCCESSFUL
;
2969 result
= rpccli_srvsvc_net_share_add(pipe_hnd
, mem_ctx
, sharename
, type
,
2970 opt_comment
, perms
, opt_maxusers
,
2971 num_users
, path
, password
,
2973 return werror_to_ntstatus(result
);
2976 static int rpc_share_add(int argc
, const char **argv
)
2978 if ((argc
< 1) || !strchr(argv
[0], '=')) {
2979 DEBUG(1,("Sharename or path not specified on add\n"));
2980 return rpc_share_usage(argc
, argv
);
2982 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2983 rpc_share_add_internals
,
2988 * Delete a share on a remote RPC server
2990 * All parameters are provided by the run_rpc_command function, except for
2991 * argc, argv which are passes through.
2993 * @param domain_sid The domain sid acquired from the remote server
2994 * @param cli A cli_state connected to the server.
2995 * @param mem_ctx Talloc context, destoyed on completion of the function.
2996 * @param argc Standard main() style argc
2997 * @param argv Standard main() style argv. Initial components are already
3000 * @return Normal NTSTATUS return.
3002 static NTSTATUS
rpc_share_del_internals(const DOM_SID
*domain_sid
,
3003 const char *domain_name
,
3004 struct cli_state
*cli
,
3005 struct rpc_pipe_client
*pipe_hnd
,
3006 TALLOC_CTX
*mem_ctx
,
3012 result
= rpccli_srvsvc_net_share_del(pipe_hnd
, mem_ctx
, argv
[0]);
3013 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3017 * Delete a share on a remote RPC server
3019 * @param domain_sid The domain sid acquired from the remote server
3020 * @param argc Standard main() style argc
3021 * @param argv Standard main() style argv. Initial components are already
3024 * @return A shell status integer (0 for success)
3026 static int rpc_share_delete(int argc
, const char **argv
)
3029 DEBUG(1,("Sharename not specified on delete\n"));
3030 return rpc_share_usage(argc
, argv
);
3032 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3033 rpc_share_del_internals
,
3038 * Formatted print of share info
3040 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3043 static void display_share_info_1(SRV_SHARE_INFO_1
*info1
)
3045 fstring netname
= "", remark
= "";
3047 rpcstr_pull_unistr2_fstring(netname
, &info1
->info_1_str
.uni_netname
);
3048 rpcstr_pull_unistr2_fstring(remark
, &info1
->info_1_str
.uni_remark
);
3050 if (opt_long_list_entries
) {
3051 d_printf("%-12s %-8.8s %-50s\n",
3052 netname
, share_type
[info1
->info_1
.type
], remark
);
3054 d_printf("%s\n", netname
);
3059 static WERROR
get_share_info(struct rpc_pipe_client
*pipe_hnd
,
3060 TALLOC_CTX
*mem_ctx
,
3064 SRV_SHARE_INFO_CTR
*ctr
)
3067 SRV_SHARE_INFO info
;
3069 /* no specific share requested, enumerate all */
3073 uint32 preferred_len
= 0xffffffff;
3075 init_enum_hnd(&hnd
, 0);
3077 return rpccli_srvsvc_net_share_enum(pipe_hnd
, mem_ctx
, level
, ctr
,
3078 preferred_len
, &hnd
);
3081 /* request just one share */
3082 result
= rpccli_srvsvc_net_share_get_info(pipe_hnd
, mem_ctx
, argv
[0], level
, &info
);
3084 if (!W_ERROR_IS_OK(result
))
3090 ctr
->info_level
= ctr
->switch_value
= level
;
3091 ctr
->ptr_share_info
= ctr
->ptr_entries
= 1;
3092 ctr
->num_entries
= ctr
->num_entries2
= 1;
3098 SRV_SHARE_INFO_1
*info1
;
3100 ctr
->share
.info1
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_1
, 1);
3101 info1
= ctr
->share
.info1
;
3103 memset(ctr
->share
.info1
, 0, sizeof(SRV_SHARE_INFO_1
));
3105 /* Copy pointer crap */
3107 memcpy(&info1
->info_1
, &info
.share
.info1
.info_1
, sizeof(SH_INFO_1
));
3109 /* Duplicate strings */
3111 s
= unistr2_tdup(mem_ctx
, &info
.share
.info1
.info_1_str
.uni_netname
);
3113 init_unistr2(&info1
->info_1_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3115 s
= unistr2_tdup(mem_ctx
, &info
.share
.info1
.info_1_str
.uni_remark
);
3117 init_unistr2(&info1
->info_1_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3122 SRV_SHARE_INFO_2
*info2
;
3124 ctr
->share
.info2
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_2
, 1);
3125 info2
= ctr
->share
.info2
;
3127 memset(ctr
->share
.info2
, 0, sizeof(SRV_SHARE_INFO_2
));
3129 /* Copy pointer crap */
3131 memcpy(&info2
->info_2
, &info
.share
.info2
.info_2
, sizeof(SH_INFO_2
));
3133 /* Duplicate strings */
3135 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_netname
);
3137 init_unistr2(&info2
->info_2_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3139 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_remark
);
3141 init_unistr2(&info2
->info_2_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3143 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_path
);
3145 init_unistr2(&info2
->info_2_str
.uni_path
, s
, UNI_STR_TERMINATE
);
3147 s
= unistr2_tdup(mem_ctx
, &info
.share
.info2
.info_2_str
.uni_passwd
);
3149 init_unistr2(&info2
->info_2_str
.uni_passwd
, s
, UNI_STR_TERMINATE
);
3154 SRV_SHARE_INFO_502
*info502
;
3156 ctr
->share
.info502
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_502
, 1);
3157 info502
= ctr
->share
.info502
;
3159 memset(ctr
->share
.info502
, 0, sizeof(SRV_SHARE_INFO_502
));
3161 /* Copy pointer crap */
3163 memcpy(&info502
->info_502
, &info
.share
.info502
.info_502
, sizeof(SH_INFO_502
));
3165 /* Duplicate strings */
3167 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_netname
);
3169 init_unistr2(&info502
->info_502_str
.uni_netname
, s
, UNI_STR_TERMINATE
);
3171 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_remark
);
3173 init_unistr2(&info502
->info_502_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
3175 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_path
);
3177 init_unistr2(&info502
->info_502_str
.uni_path
, s
, UNI_STR_TERMINATE
);
3179 s
= unistr2_tdup(mem_ctx
, &info
.share
.info502
.info_502_str
.uni_passwd
);
3181 init_unistr2(&info502
->info_502_str
.uni_passwd
, s
, UNI_STR_TERMINATE
);
3183 info502
->info_502_str
.sd
= dup_sec_desc(mem_ctx
, info
.share
.info502
.info_502_str
.sd
);
3194 * List shares on a remote RPC server
3196 * All parameters are provided by the run_rpc_command function, except for
3197 * argc, argv which are passes through.
3199 * @param domain_sid The domain sid acquired from the remote server
3200 * @param cli A cli_state connected to the server.
3201 * @param mem_ctx Talloc context, destoyed on completion of the function.
3202 * @param argc Standard main() style argc
3203 * @param argv Standard main() style argv. Initial components are already
3206 * @return Normal NTSTATUS return.
3209 static NTSTATUS
rpc_share_list_internals(const DOM_SID
*domain_sid
,
3210 const char *domain_name
,
3211 struct cli_state
*cli
,
3212 struct rpc_pipe_client
*pipe_hnd
,
3213 TALLOC_CTX
*mem_ctx
,
3217 SRV_SHARE_INFO_CTR ctr
;
3219 uint32 i
, level
= 1;
3221 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr
);
3222 if (!W_ERROR_IS_OK(result
))
3225 /* Display results */
3227 if (opt_long_list_entries
) {
3229 "\nEnumerating shared resources (exports) on remote server:\n\n"\
3230 "\nShare name Type Description\n"\
3231 "---------- ---- -----------\n");
3233 for (i
= 0; i
< ctr
.num_entries
; i
++)
3234 display_share_info_1(&ctr
.share
.info1
[i
]);
3236 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3240 * 'net rpc share list' entrypoint.
3241 * @param argc Standard main() style argc
3242 * @param argv Standard main() style argv. Initial components are already
3245 static int rpc_share_list(int argc
, const char **argv
)
3247 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_list_internals
, argc
, argv
);
3250 static BOOL
check_share_availability(struct cli_state
*cli
, const char *netname
)
3252 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3253 d_printf("skipping [%s]: not a file share.\n", netname
);
3263 static BOOL
check_share_sanity(struct cli_state
*cli
, fstring netname
, uint32 type
)
3265 /* only support disk shares */
3266 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3267 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3271 /* skip builtin shares */
3272 /* FIXME: should print$ be added too ? */
3273 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3274 strequal(netname
,"global"))
3277 if (opt_exclude
&& in_list(netname
, opt_exclude
, False
)) {
3278 printf("excluding [%s]\n", netname
);
3282 return check_share_availability(cli
, netname
);
3286 * Migrate shares from a remote RPC server to the local RPC srever
3288 * All parameters are provided by the run_rpc_command function, except for
3289 * argc, argv which are passes through.
3291 * @param domain_sid The domain sid acquired from the remote server
3292 * @param cli A cli_state connected to the server.
3293 * @param mem_ctx Talloc context, destoyed on completion of the function.
3294 * @param argc Standard main() style argc
3295 * @param argv Standard main() style argv. Initial components are already
3298 * @return Normal NTSTATUS return.
3301 static NTSTATUS
rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
,
3302 const char *domain_name
,
3303 struct cli_state
*cli
,
3304 struct rpc_pipe_client
*pipe_hnd
,
3305 TALLOC_CTX
*mem_ctx
,
3310 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3311 SRV_SHARE_INFO_CTR ctr_src
;
3312 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3313 char *password
= NULL
; /* don't allow a share password */
3315 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3316 struct cli_state
*cli_dst
= NULL
;
3317 uint32 level
= 502; /* includes secdesc */
3319 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3320 if (!W_ERROR_IS_OK(result
))
3323 /* connect destination PI_SRVSVC */
3324 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3325 if (!NT_STATUS_IS_OK(nt_status
))
3329 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3331 fstring netname
= "", remark
= "", path
= "";
3332 /* reset error-code */
3333 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3335 rpcstr_pull_unistr2_fstring(
3336 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3337 rpcstr_pull_unistr2_fstring(
3338 remark
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_remark
);
3339 rpcstr_pull_unistr2_fstring(
3340 path
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_path
);
3342 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3345 /* finally add the share on the dst server */
3347 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3348 netname
, path
, remark
);
3350 result
= rpccli_srvsvc_net_share_add(srvsvc_pipe
, mem_ctx
, netname
, type
, remark
,
3351 ctr_src
.share
.info502
[i
].info_502
.perms
,
3352 ctr_src
.share
.info502
[i
].info_502
.max_uses
,
3353 ctr_src
.share
.info502
[i
].info_502
.num_uses
,
3354 path
, password
, level
,
3357 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3358 printf(" [%s] does already exist\n", netname
);
3362 if (!W_ERROR_IS_OK(result
)) {
3363 printf("cannot add share: %s\n", dos_errstr(result
));
3369 nt_status
= NT_STATUS_OK
;
3373 cli_shutdown(cli_dst
);
3381 * Migrate shares from a rpc-server to another
3383 * @param argc Standard main() style argc
3384 * @param argv Standard main() style argv. Initial components are already
3387 * @return A shell status integer (0 for success)
3389 static int rpc_share_migrate_shares(int argc
, const char **argv
)
3393 printf("no server to migrate\n");
3397 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3398 rpc_share_migrate_shares_internals
,
3405 * @param f file_info
3406 * @param mask current search mask
3407 * @param state arg-pointer
3410 static void copy_fn(const char *mnt
, file_info
*f
, const char *mask
, void *state
)
3412 static NTSTATUS nt_status
;
3413 static struct copy_clistate
*local_state
;
3414 static fstring filename
, new_mask
;
3418 local_state
= (struct copy_clistate
*)state
;
3419 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3421 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3424 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3427 if (f
->mode
& aDIR
) {
3429 DEBUG(3,("got dir: %s\n", f
->name
));
3431 fstrcpy(dir
, local_state
->cwd
);
3433 fstrcat(dir
, f
->name
);
3435 switch (net_mode_share
)
3437 case NET_MODE_SHARE_MIGRATE
:
3438 /* create that directory */
3439 nt_status
= net_copy_file(local_state
->mem_ctx
,
3440 local_state
->cli_share_src
,
3441 local_state
->cli_share_dst
,
3443 opt_acls
? True
: False
,
3444 opt_attrs
? True
: False
,
3445 opt_timestamps
? True
: False
,
3449 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3453 if (!NT_STATUS_IS_OK(nt_status
))
3454 printf("could not handle dir %s: %s\n",
3455 dir
, nt_errstr(nt_status
));
3457 /* search below that directory */
3458 fstrcpy(new_mask
, dir
);
3459 fstrcat(new_mask
, "\\*");
3461 old_dir
= local_state
->cwd
;
3462 local_state
->cwd
= dir
;
3463 if (!sync_files(local_state
, new_mask
))
3464 printf("could not handle files\n");
3465 local_state
->cwd
= old_dir
;
3472 fstrcpy(filename
, local_state
->cwd
);
3473 fstrcat(filename
, "\\");
3474 fstrcat(filename
, f
->name
);
3476 DEBUG(3,("got file: %s\n", filename
));
3478 switch (net_mode_share
)
3480 case NET_MODE_SHARE_MIGRATE
:
3481 nt_status
= net_copy_file(local_state
->mem_ctx
,
3482 local_state
->cli_share_src
,
3483 local_state
->cli_share_dst
,
3485 opt_acls
? True
: False
,
3486 opt_attrs
? True
: False
,
3487 opt_timestamps
? True
: False
,
3491 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3495 if (!NT_STATUS_IS_OK(nt_status
))
3496 printf("could not handle file %s: %s\n",
3497 filename
, nt_errstr(nt_status
));
3502 * sync files, can be called recursivly to list files
3503 * and then call copy_fn for each file
3505 * @param cp_clistate pointer to the copy_clistate we work with
3506 * @param mask the current search mask
3508 * @return Boolean result
3510 BOOL
sync_files(struct copy_clistate
*cp_clistate
, pstring mask
)
3513 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3515 if (cli_list(cp_clistate
->cli_share_src
, mask
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3516 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3517 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3526 * Set the top level directory permissions before we do any further copies.
3527 * Should set up ACL inheritance.
3530 BOOL
copy_top_level_perms(struct copy_clistate
*cp_clistate
,
3531 const char *sharename
)
3533 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3535 switch (net_mode_share
) {
3536 case NET_MODE_SHARE_MIGRATE
:
3537 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3538 nt_status
= net_copy_fileattr(cp_clistate
->mem_ctx
,
3539 cp_clistate
->cli_share_src
,
3540 cp_clistate
->cli_share_dst
,
3542 opt_acls
? True
: False
,
3543 opt_attrs
? True
: False
,
3544 opt_timestamps
? True
: False
,
3548 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3552 if (!NT_STATUS_IS_OK(nt_status
)) {
3553 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3554 sharename
, nt_errstr(nt_status
));
3562 * Sync all files inside a remote share to another share (over smb)
3564 * All parameters are provided by the run_rpc_command function, except for
3565 * argc, argv which are passes through.
3567 * @param domain_sid The domain sid acquired from the remote server
3568 * @param cli A cli_state connected to the server.
3569 * @param mem_ctx Talloc context, destoyed on completion of the function.
3570 * @param argc Standard main() style argc
3571 * @param argv Standard main() style argv. Initial components are already
3574 * @return Normal NTSTATUS return.
3577 static NTSTATUS
rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
,
3578 const char *domain_name
,
3579 struct cli_state
*cli
,
3580 struct rpc_pipe_client
*pipe_hnd
,
3581 TALLOC_CTX
*mem_ctx
,
3586 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3587 SRV_SHARE_INFO_CTR ctr_src
;
3590 struct copy_clistate cp_clistate
;
3591 BOOL got_src_share
= False
;
3592 BOOL got_dst_share
= False
;
3593 pstring mask
= "\\*";
3596 dst
= SMB_STRDUP(opt_destination
?opt_destination
:"127.0.0.1");
3598 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3600 if (!W_ERROR_IS_OK(result
))
3603 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3605 fstring netname
= "";
3607 rpcstr_pull_unistr2_fstring(
3608 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3610 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3613 /* one might not want to mirror whole discs :) */
3614 if (strequal(netname
, "print$") || netname
[1] == '$') {
3615 d_printf("skipping [%s]: builtin/hidden share\n", netname
);
3619 switch (net_mode_share
)
3621 case NET_MODE_SHARE_MIGRATE
:
3625 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3628 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3630 opt_acls
? "including" : "without",
3631 opt_attrs
? "including" : "without",
3632 opt_timestamps
? "(preserving timestamps)" : "");
3634 cp_clistate
.mem_ctx
= mem_ctx
;
3635 cp_clistate
.cli_share_src
= NULL
;
3636 cp_clistate
.cli_share_dst
= NULL
;
3637 cp_clistate
.cwd
= NULL
;
3638 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3640 /* open share source */
3641 nt_status
= connect_to_service(&cp_clistate
.cli_share_src
,
3642 &cli
->dest_ip
, cli
->desthost
,
3644 if (!NT_STATUS_IS_OK(nt_status
))
3647 got_src_share
= True
;
3649 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3650 /* open share destination */
3651 nt_status
= connect_to_service(&cp_clistate
.cli_share_dst
,
3652 NULL
, dst
, netname
, "A:");
3653 if (!NT_STATUS_IS_OK(nt_status
))
3656 got_dst_share
= True
;
3659 if (!copy_top_level_perms(&cp_clistate
, netname
)) {
3660 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", netname
);
3661 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3665 if (!sync_files(&cp_clistate
, mask
)) {
3666 d_fprintf(stderr
, "could not handle files for share: %s\n", netname
);
3667 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3672 nt_status
= NT_STATUS_OK
;
3677 cli_shutdown(cp_clistate
.cli_share_src
);
3680 cli_shutdown(cp_clistate
.cli_share_dst
);
3686 static int rpc_share_migrate_files(int argc
, const char **argv
)
3690 printf("no server to migrate\n");
3694 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3695 rpc_share_migrate_files_internals
,
3700 * Migrate share-ACLs from a remote RPC server to the local RPC srever
3702 * All parameters are provided by the run_rpc_command function, except for
3703 * argc, argv which are passes through.
3705 * @param domain_sid The domain sid acquired from the remote server
3706 * @param cli A cli_state connected to the server.
3707 * @param mem_ctx Talloc context, destoyed on completion of the function.
3708 * @param argc Standard main() style argc
3709 * @param argv Standard main() style argv. Initial components are already
3712 * @return Normal NTSTATUS return.
3715 static NTSTATUS
rpc_share_migrate_security_internals(const DOM_SID
*domain_sid
,
3716 const char *domain_name
,
3717 struct cli_state
*cli
,
3718 struct rpc_pipe_client
*pipe_hnd
,
3719 TALLOC_CTX
*mem_ctx
,
3724 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3725 SRV_SHARE_INFO_CTR ctr_src
;
3726 SRV_SHARE_INFO info
;
3728 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3729 struct cli_state
*cli_dst
= NULL
;
3730 uint32 level
= 502; /* includes secdesc */
3732 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3734 if (!W_ERROR_IS_OK(result
))
3737 /* connect destination PI_SRVSVC */
3738 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3739 if (!NT_STATUS_IS_OK(nt_status
))
3743 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
3745 fstring netname
= "", remark
= "", path
= "";
3746 /* reset error-code */
3747 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3749 rpcstr_pull_unistr2_fstring(
3750 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
3751 rpcstr_pull_unistr2_fstring(
3752 remark
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_remark
);
3753 rpcstr_pull_unistr2_fstring(
3754 path
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_path
);
3756 if (!check_share_sanity(cli
, netname
, ctr_src
.share
.info502
[i
].info_502
.type
))
3759 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3760 netname
, path
, remark
);
3763 display_sec_desc(ctr_src
.share
.info502
[i
].info_502_str
.sd
);
3768 info
.switch_value
= level
;
3769 info
.ptr_share_ctr
= 1;
3771 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3772 info
.share
.info502
= ctr_src
.share
.info502
[i
];
3774 /* finally modify the share on the dst server */
3775 result
= rpccli_srvsvc_net_share_set_info(srvsvc_pipe
, mem_ctx
, netname
, level
, &info
);
3777 if (!W_ERROR_IS_OK(result
)) {
3778 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3784 nt_status
= NT_STATUS_OK
;
3788 cli_shutdown(cli_dst
);
3796 * Migrate share-acls from a rpc-server to another
3798 * @param argc Standard main() style argc
3799 * @param argv Standard main() style argv. Initial components are already
3802 * @return A shell status integer (0 for success)
3804 static int rpc_share_migrate_security(int argc
, const char **argv
)
3808 printf("no server to migrate\n");
3812 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3813 rpc_share_migrate_security_internals
,
3818 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3819 * from one server to another
3821 * @param argc Standard main() style argc
3822 * @param argv Standard main() style argv. Initial components are already
3825 * @return A shell status integer (0 for success)
3828 static int rpc_share_migrate_all(int argc
, const char **argv
)
3833 printf("no server to migrate\n");
3837 /* order is important. we don't want to be locked out by the share-acl
3838 * before copying files - gd */
3840 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
3844 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
3848 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_security_internals
, argc
, argv
);
3853 * 'net rpc share migrate' entrypoint.
3854 * @param argc Standard main() style argc
3855 * @param argv Standard main() style argv. Initial components are already
3858 static int rpc_share_migrate(int argc
, const char **argv
)
3861 struct functable func
[] = {
3862 {"all", rpc_share_migrate_all
},
3863 {"files", rpc_share_migrate_files
},
3864 {"help", rpc_share_usage
},
3865 {"security", rpc_share_migrate_security
},
3866 {"shares", rpc_share_migrate_shares
},
3870 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3872 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
3881 static int num_server_aliases
;
3882 static struct full_alias
*server_aliases
;
3885 * Add an alias to the static list.
3887 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3889 if (server_aliases
== NULL
)
3890 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3892 server_aliases
[num_server_aliases
] = *alias
;
3893 num_server_aliases
+= 1;
3897 * For a specific domain on the server, fetch all the aliases
3898 * and their members. Add all of them to the server_aliases.
3901 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3902 TALLOC_CTX
*mem_ctx
,
3903 POLICY_HND
*connect_pol
,
3904 const DOM_SID
*domain_sid
)
3906 uint32 start_idx
, max_entries
, num_entries
, i
;
3907 struct acct_info
*groups
;
3909 POLICY_HND domain_pol
;
3911 /* Get domain policy handle */
3913 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, connect_pol
,
3914 MAXIMUM_ALLOWED_ACCESS
,
3915 domain_sid
, &domain_pol
);
3916 if (!NT_STATUS_IS_OK(result
))
3923 result
= rpccli_samr_enum_als_groups(pipe_hnd
, mem_ctx
, &domain_pol
,
3924 &start_idx
, max_entries
,
3925 &groups
, &num_entries
);
3927 for (i
= 0; i
< num_entries
; i
++) {
3929 POLICY_HND alias_pol
;
3930 struct full_alias alias
;
3934 result
= rpccli_samr_open_alias(pipe_hnd
, mem_ctx
, &domain_pol
,
3935 MAXIMUM_ALLOWED_ACCESS
,
3938 if (!NT_STATUS_IS_OK(result
))
3941 result
= rpccli_samr_query_aliasmem(pipe_hnd
, mem_ctx
,
3945 if (!NT_STATUS_IS_OK(result
))
3948 result
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &alias_pol
);
3949 if (!NT_STATUS_IS_OK(result
))
3952 alias
.members
= NULL
;
3954 if (alias
.num_members
> 0) {
3955 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3957 for (j
= 0; j
< alias
.num_members
; j
++)
3958 sid_copy(&alias
.members
[j
],
3962 sid_copy(&alias
.sid
, domain_sid
);
3963 sid_append_rid(&alias
.sid
, groups
[i
].rid
);
3965 push_alias(mem_ctx
, &alias
);
3967 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3969 result
= NT_STATUS_OK
;
3972 rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_pol
);
3978 * Dump server_aliases as names for debugging purposes.
3981 static NTSTATUS
rpc_aliaslist_dump(const DOM_SID
*domain_sid
,
3982 const char *domain_name
,
3983 struct cli_state
*cli
,
3984 struct rpc_pipe_client
*pipe_hnd
,
3985 TALLOC_CTX
*mem_ctx
,
3993 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, True
,
3994 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3996 if (!NT_STATUS_IS_OK(result
))
3999 for (i
=0; i
<num_server_aliases
; i
++) {
4005 struct full_alias
*alias
= &server_aliases
[i
];
4007 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4009 &domains
, &names
, &types
);
4010 if (!NT_STATUS_IS_OK(result
))
4013 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4015 if (alias
->num_members
== 0) {
4020 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4023 &domains
, &names
, &types
);
4025 if (!NT_STATUS_IS_OK(result
) &&
4026 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4029 for (j
=0; j
<alias
->num_members
; j
++)
4030 DEBUG(1, ("%s\\%s (%d); ",
4031 domains
[j
] ? domains
[j
] : "*unknown*",
4032 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4036 rpccli_lsa_close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4038 return NT_STATUS_OK
;
4042 * Fetch a list of all server aliases and their members into
4046 static NTSTATUS
rpc_aliaslist_internals(const DOM_SID
*domain_sid
,
4047 const char *domain_name
,
4048 struct cli_state
*cli
,
4049 struct rpc_pipe_client
*pipe_hnd
,
4050 TALLOC_CTX
*mem_ctx
,
4055 POLICY_HND connect_pol
;
4057 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
4060 if (!NT_STATUS_IS_OK(result
))
4063 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4064 &global_sid_Builtin
);
4066 if (!NT_STATUS_IS_OK(result
))
4069 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4072 rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_pol
);
4077 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4079 token
->num_sids
= 4;
4081 token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4);
4083 token
->user_sids
[0] = *user_sid
;
4084 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4085 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4086 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4089 static void free_user_token(NT_USER_TOKEN
*token
)
4091 SAFE_FREE(token
->user_sids
);
4094 static BOOL
is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4098 for (i
=0; i
<token
->num_sids
; i
++) {
4099 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
4105 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4107 if (is_sid_in_token(token
, sid
))
4110 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4111 if (!token
->user_sids
) {
4115 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4117 token
->num_sids
+= 1;
4122 NT_USER_TOKEN token
;
4125 static void dump_user_token(struct user_token
*token
)
4129 d_printf("%s\n", token
->name
);
4131 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4132 d_printf(" %s\n", sid_string_static(&token
->token
.user_sids
[i
]));
4136 static BOOL
is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4140 for (i
=0; i
<alias
->num_members
; i
++) {
4141 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4148 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4152 for (i
=0; i
<num_server_aliases
; i
++) {
4153 if (is_alias_member(&sid
, &server_aliases
[i
]))
4154 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4159 * We got a user token with all the SIDs we can know about without asking the
4160 * server directly. These are the user and domain group sids. All of these can
4161 * be members of aliases. So scan the list of aliases for each of the SIDs and
4162 * add them to the token.
4165 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4167 int num_global_sids
= token
->num_sids
;
4170 for (i
=0; i
<num_global_sids
; i
++) {
4171 collect_sid_memberships(token
, token
->user_sids
[i
]);
4175 static BOOL
get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4177 struct winbindd_request request
;
4178 struct winbindd_response response
;
4186 fstr_sprintf(full_name
, "%s%c%s",
4187 domain
, *lp_winbind_separator(), user
);
4189 /* First let's find out the user sid */
4191 ZERO_STRUCT(request
);
4192 ZERO_STRUCT(response
);
4194 fstrcpy(request
.data
.name
.dom_name
, domain
);
4195 fstrcpy(request
.data
.name
.name
, user
);
4197 result
= winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
);
4199 if (result
!= NSS_STATUS_SUCCESS
) {
4200 DEBUG(1, ("winbind could not find %s\n", full_name
));
4204 if (response
.data
.sid
.type
!= SID_NAME_USER
) {
4205 DEBUG(1, ("%s is not a user\n", full_name
));
4209 string_to_sid(&user_sid
, response
.data
.sid
.sid
);
4211 init_user_token(token
, &user_sid
);
4213 /* And now the groups winbind knows about */
4215 ZERO_STRUCT(response
);
4217 fstrcpy(request
.data
.username
, full_name
);
4219 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
4221 if (result
!= NSS_STATUS_SUCCESS
) {
4222 DEBUG(1, ("winbind could not get groups of %s\n", full_name
));
4226 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
4227 gid_t gid
= ((gid_t
*)response
.extra_data
.data
)[i
];
4230 struct winbindd_request sidrequest
;
4231 struct winbindd_response sidresponse
;
4233 ZERO_STRUCT(sidrequest
);
4234 ZERO_STRUCT(sidresponse
);
4236 sidrequest
.data
.gid
= gid
;
4238 result
= winbindd_request_response(WINBINDD_GID_TO_SID
,
4239 &sidrequest
, &sidresponse
);
4241 if (result
!= NSS_STATUS_SUCCESS
) {
4242 DEBUG(1, ("winbind could not find SID of gid %d\n",
4247 DEBUG(3, (" %s\n", sidresponse
.data
.sid
.sid
));
4249 string_to_sid(&sid
, sidresponse
.data
.sid
.sid
);
4250 add_sid_to_token(token
, &sid
);
4253 SAFE_FREE(response
.extra_data
.data
);
4259 * Get a list of all user tokens we want to look at
4262 static BOOL
get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
4264 struct winbindd_request request
;
4265 struct winbindd_response response
;
4266 const char *extra_data
;
4269 struct user_token
*result
;
4271 if (lp_winbind_use_default_domain() &&
4272 (opt_target_workgroup
== NULL
)) {
4273 d_fprintf(stderr
, "winbind use default domain = yes set, "
4274 "please specify a workgroup\n");
4278 /* Send request to winbind daemon */
4280 ZERO_STRUCT(request
);
4281 ZERO_STRUCT(response
);
4283 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
4287 /* Look through extra data */
4289 if (!response
.extra_data
.data
)
4292 extra_data
= (const char *)response
.extra_data
.data
;
4295 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
4299 result
= SMB_MALLOC_ARRAY(struct user_token
, *num_tokens
);
4301 if (result
== NULL
) {
4302 DEBUG(1, ("Could not malloc sid array\n"));
4306 extra_data
= (const char *)response
.extra_data
.data
;
4309 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
4311 fstring domain
, user
;
4314 fstrcpy(result
[i
].name
, name
);
4316 p
= strchr(name
, *lp_winbind_separator());
4318 DEBUG(3, ("%s\n", name
));
4321 fstrcpy(domain
, opt_target_workgroup
);
4322 fstrcpy(user
, name
);
4325 fstrcpy(domain
, name
);
4330 get_user_sids(domain
, user
, &(result
[i
].token
));
4334 SAFE_FREE(response
.extra_data
.data
);
4336 *user_tokens
= result
;
4341 static BOOL
get_user_tokens_from_file(FILE *f
,
4343 struct user_token
**tokens
)
4345 struct user_token
*token
= NULL
;
4350 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4354 if (line
[strlen(line
)-1] == '\n')
4355 line
[strlen(line
)-1] = '\0';
4357 if (line
[0] == ' ') {
4361 string_to_sid(&sid
, &line
[1]);
4363 if (token
== NULL
) {
4364 DEBUG(0, ("File does not begin with username"));
4368 add_sid_to_token(&token
->token
, &sid
);
4372 /* And a new user... */
4375 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4376 if (*tokens
== NULL
) {
4377 DEBUG(0, ("Could not realloc tokens\n"));
4381 token
= &((*tokens
)[*num_tokens
-1]);
4383 fstrcpy(token
->name
, line
);
4384 token
->token
.num_sids
= 0;
4385 token
->token
.user_sids
= NULL
;
4394 * Show the list of all users that have access to a share
4397 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4398 TALLOC_CTX
*mem_ctx
,
4399 const char *netname
,
4401 struct user_token
*tokens
)
4404 SEC_DESC
*share_sd
= NULL
;
4405 SEC_DESC
*root_sd
= NULL
;
4406 struct cli_state
*cli
= pipe_hnd
->cli
;
4408 SRV_SHARE_INFO info
;
4412 result
= rpccli_srvsvc_net_share_get_info(pipe_hnd
, mem_ctx
, netname
,
4415 if (!W_ERROR_IS_OK(result
)) {
4416 DEBUG(1, ("Coult not query secdesc for share %s\n",
4421 share_sd
= info
.share
.info502
.info_502_str
.sd
;
4422 if (share_sd
== NULL
) {
4423 DEBUG(1, ("Got no secdesc for share %s\n",
4429 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4433 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4436 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4439 for (i
=0; i
<num_tokens
; i
++) {
4443 if (share_sd
!= NULL
) {
4444 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4445 1, &acc_granted
, &status
)) {
4446 DEBUG(1, ("Could not check share_sd for "
4452 if (!NT_STATUS_IS_OK(status
))
4456 if (root_sd
== NULL
) {
4457 d_printf(" %s\n", tokens
[i
].name
);
4461 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4462 1, &acc_granted
, &status
)) {
4463 DEBUG(1, ("Could not check root_sd for user %s\n",
4468 if (!NT_STATUS_IS_OK(status
))
4471 d_printf(" %s\n", tokens
[i
].name
);
4475 cli_close(cli
, fnum
);
4487 static void collect_share(const char *name
, uint32 m
,
4488 const char *comment
, void *state
)
4490 struct share_list
*share_list
= (struct share_list
*)state
;
4492 if (m
!= STYPE_DISKTREE
)
4495 share_list
->num_shares
+= 1;
4496 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4497 if (!share_list
->shares
) {
4498 share_list
->num_shares
= 0;
4501 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4504 static void rpc_share_userlist_usage(void)
4510 * List shares on a remote RPC server, including the security descriptors
4512 * All parameters are provided by the run_rpc_command function, except for
4513 * argc, argv which are passes through.
4515 * @param domain_sid The domain sid acquired from the remote server
4516 * @param cli A cli_state connected to the server.
4517 * @param mem_ctx Talloc context, destoyed on completion of the function.
4518 * @param argc Standard main() style argc
4519 * @param argv Standard main() style argv. Initial components are already
4522 * @return Normal NTSTATUS return.
4525 static NTSTATUS
rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
4526 const char *domain_name
,
4527 struct cli_state
*cli
,
4528 struct rpc_pipe_client
*pipe_hnd
,
4529 TALLOC_CTX
*mem_ctx
,
4539 struct user_token
*tokens
= NULL
;
4542 struct share_list share_list
;
4545 rpc_share_userlist_usage();
4546 return NT_STATUS_UNSUCCESSFUL
;
4552 f
= fopen(argv
[0], "r");
4556 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4557 return NT_STATUS_UNSUCCESSFUL
;
4560 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4566 DEBUG(0, ("Could not read users from file\n"));
4567 return NT_STATUS_UNSUCCESSFUL
;
4570 for (i
=0; i
<num_tokens
; i
++)
4571 collect_alias_memberships(&tokens
[i
].token
);
4573 init_enum_hnd(&hnd
, 0);
4575 share_list
.num_shares
= 0;
4576 share_list
.shares
= NULL
;
4578 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4581 DEBUG(0, ("Error returning browse list: %s\n",
4586 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4587 char *netname
= share_list
.shares
[i
];
4589 if (netname
[strlen(netname
)-1] == '$')
4592 d_printf("%s\n", netname
);
4594 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4595 num_tokens
, tokens
);
4598 for (i
=0; i
<num_tokens
; i
++) {
4599 free_user_token(&tokens
[i
].token
);
4602 SAFE_FREE(share_list
.shares
);
4604 return NT_STATUS_OK
;
4607 static int rpc_share_allowedusers(int argc
, const char **argv
)
4611 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
4612 rpc_aliaslist_internals
,
4617 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
4623 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4624 rpc_share_allowedusers_internals
,
4628 int net_usersidlist(int argc
, const char **argv
)
4631 struct user_token
*tokens
= NULL
;
4635 net_usersidlist_usage(argc
, argv
);
4639 if (!get_user_tokens(&num_tokens
, &tokens
)) {
4640 DEBUG(0, ("Could not get the user/sid list\n"));
4644 for (i
=0; i
<num_tokens
; i
++) {
4645 dump_user_token(&tokens
[i
]);
4646 free_user_token(&tokens
[i
].token
);
4653 int net_usersidlist_usage(int argc
, const char **argv
)
4655 d_printf("net usersidlist\n"
4656 "\tprints out a list of all users the running winbind knows\n"
4657 "\tabout, together with all their SIDs. This is used as\n"
4658 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4660 net_common_flags_usage(argc
, argv
);
4665 * 'net rpc share' entrypoint.
4666 * @param argc Standard main() style argc
4667 * @param argv Standard main() style argv. Initial components are already
4671 int net_rpc_share(int argc
, const char **argv
)
4673 struct functable func
[] = {
4674 {"add", rpc_share_add
},
4675 {"delete", rpc_share_delete
},
4676 {"allowedusers", rpc_share_allowedusers
},
4677 {"migrate", rpc_share_migrate
},
4678 {"list", rpc_share_list
},
4683 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4684 rpc_share_list_internals
,
4687 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4690 static NTSTATUS
rpc_sh_share_list(TALLOC_CTX
*mem_ctx
,
4691 struct rpc_sh_ctx
*ctx
,
4692 struct rpc_pipe_client
*pipe_hnd
,
4693 int argc
, const char **argv
)
4695 return rpc_share_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
4696 ctx
->cli
, pipe_hnd
, mem_ctx
,
4700 static NTSTATUS
rpc_sh_share_add(TALLOC_CTX
*mem_ctx
,
4701 struct rpc_sh_ctx
*ctx
,
4702 struct rpc_pipe_client
*pipe_hnd
,
4703 int argc
, const char **argv
)
4707 if ((argc
< 2) || (argc
> 3)) {
4708 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4710 return NT_STATUS_INVALID_PARAMETER
;
4713 result
= rpccli_srvsvc_net_share_add(
4714 pipe_hnd
, mem_ctx
, argv
[0], STYPE_DISKTREE
,
4715 (argc
== 3) ? argv
[2] : "",
4716 0, 0, 0, argv
[1], NULL
, 2, NULL
);
4718 return werror_to_ntstatus(result
);
4721 static NTSTATUS
rpc_sh_share_delete(TALLOC_CTX
*mem_ctx
,
4722 struct rpc_sh_ctx
*ctx
,
4723 struct rpc_pipe_client
*pipe_hnd
,
4724 int argc
, const char **argv
)
4729 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4730 return NT_STATUS_INVALID_PARAMETER
;
4733 result
= rpccli_srvsvc_net_share_del(pipe_hnd
, mem_ctx
, argv
[0]);
4734 return werror_to_ntstatus(result
);
4737 static NTSTATUS
rpc_sh_share_info(TALLOC_CTX
*mem_ctx
,
4738 struct rpc_sh_ctx
*ctx
,
4739 struct rpc_pipe_client
*pipe_hnd
,
4740 int argc
, const char **argv
)
4742 SRV_SHARE_INFO info
;
4743 SRV_SHARE_INFO_2
*info2
= &info
.share
.info2
;
4747 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4748 return NT_STATUS_INVALID_PARAMETER
;
4751 result
= rpccli_srvsvc_net_share_get_info(
4752 pipe_hnd
, mem_ctx
, argv
[0], 2, &info
);
4753 if (!W_ERROR_IS_OK(result
)) {
4757 d_printf("Name: %s\n",
4758 rpcstr_pull_unistr2_talloc(mem_ctx
,
4759 &info2
->info_2_str
.uni_netname
));
4760 d_printf("Comment: %s\n",
4761 rpcstr_pull_unistr2_talloc(mem_ctx
,
4762 &info2
->info_2_str
.uni_remark
));
4764 d_printf("Path: %s\n",
4765 rpcstr_pull_unistr2_talloc(mem_ctx
,
4766 &info2
->info_2_str
.uni_path
));
4767 d_printf("Password: %s\n",
4768 rpcstr_pull_unistr2_talloc(mem_ctx
,
4769 &info2
->info_2_str
.uni_passwd
));
4772 return werror_to_ntstatus(result
);
4775 struct rpc_sh_cmd
*net_rpc_share_cmds(TALLOC_CTX
*mem_ctx
,
4776 struct rpc_sh_ctx
*ctx
)
4778 static struct rpc_sh_cmd cmds
[] = {
4780 { "list", NULL
, PI_SRVSVC
, rpc_sh_share_list
,
4781 "List available shares" },
4783 { "add", NULL
, PI_SRVSVC
, rpc_sh_share_add
,
4786 { "delete", NULL
, PI_SRVSVC
, rpc_sh_share_delete
,
4789 { "info", NULL
, PI_SRVSVC
, rpc_sh_share_info
,
4790 "Get information about a share" },
4792 { NULL
, NULL
, 0, NULL
, NULL
}
4798 /****************************************************************************/
4800 static int rpc_file_usage(int argc
, const char **argv
)
4802 return net_help_file(argc
, argv
);
4806 * Close a file on a remote RPC server
4808 * All parameters are provided by the run_rpc_command function, except for
4809 * argc, argv which are passes through.
4811 * @param domain_sid The domain sid acquired from the remote server
4812 * @param cli A cli_state connected to the server.
4813 * @param mem_ctx Talloc context, destoyed on completion of the function.
4814 * @param argc Standard main() style argc
4815 * @param argv Standard main() style argv. Initial components are already
4818 * @return Normal NTSTATUS return.
4820 static NTSTATUS
rpc_file_close_internals(const DOM_SID
*domain_sid
,
4821 const char *domain_name
,
4822 struct cli_state
*cli
,
4823 struct rpc_pipe_client
*pipe_hnd
,
4824 TALLOC_CTX
*mem_ctx
,
4829 result
= rpccli_srvsvc_net_file_close(pipe_hnd
, mem_ctx
, atoi(argv
[0]));
4830 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
4834 * Close a file on a remote RPC server
4836 * @param argc Standard main() style argc
4837 * @param argv Standard main() style argv. Initial components are already
4840 * @return A shell status integer (0 for success)
4842 static int rpc_file_close(int argc
, const char **argv
)
4845 DEBUG(1, ("No fileid given on close\n"));
4846 return(rpc_file_usage(argc
, argv
));
4849 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4850 rpc_file_close_internals
,
4855 * Formatted print of open file info
4857 * @param info3 FILE_INFO_3 contents
4858 * @param str3 strings for FILE_INFO_3
4861 static void display_file_info_3(FILE_INFO_3
*info3
, FILE_INFO_3_STR
*str3
)
4863 fstring user
= "", path
= "";
4865 rpcstr_pull_unistr2_fstring(user
, &str3
->uni_user_name
);
4866 rpcstr_pull_unistr2_fstring(path
, &str3
->uni_path_name
);
4868 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4869 info3
->id
, user
, info3
->perms
, info3
->num_locks
, path
);
4873 * List open files on a remote RPC server
4875 * All parameters are provided by the run_rpc_command function, except for
4876 * argc, argv which are passes through.
4878 * @param domain_sid The domain sid acquired from the remote server
4879 * @param cli A cli_state connected to the server.
4880 * @param mem_ctx Talloc context, destoyed on completion of the function.
4881 * @param argc Standard main() style argc
4882 * @param argv Standard main() style argv. Initial components are already
4885 * @return Normal NTSTATUS return.
4888 static NTSTATUS
rpc_file_list_internals(const DOM_SID
*domain_sid
,
4889 const char *domain_name
,
4890 struct cli_state
*cli
,
4891 struct rpc_pipe_client
*pipe_hnd
,
4892 TALLOC_CTX
*mem_ctx
,
4896 SRV_FILE_INFO_CTR ctr
;
4899 uint32 preferred_len
= 0xffffffff, i
;
4900 const char *username
=NULL
;
4902 init_enum_hnd(&hnd
, 0);
4904 /* if argc > 0, must be user command */
4906 username
= smb_xstrdup(argv
[0]);
4908 result
= rpccli_srvsvc_net_file_enum(pipe_hnd
,
4909 mem_ctx
, 3, username
, &ctr
, preferred_len
, &hnd
);
4911 if (!W_ERROR_IS_OK(result
))
4914 /* Display results */
4917 "\nEnumerating open files on remote server:\n\n"\
4918 "\nFileId Opened by Perms Locks Path"\
4919 "\n------ --------- ----- ----- ---- \n");
4920 for (i
= 0; i
< ctr
.num_entries
; i
++)
4921 display_file_info_3(&ctr
.file
.info3
[i
].info_3
,
4922 &ctr
.file
.info3
[i
].info_3_str
);
4924 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
4928 * List files for a user on a remote RPC server
4930 * @param argc Standard main() style argc
4931 * @param argv Standard main() style argv. Initial components are already
4934 * @return A shell status integer (0 for success)
4937 static int rpc_file_user(int argc
, const char **argv
)
4940 DEBUG(1, ("No username given\n"));
4941 return(rpc_file_usage(argc
, argv
));
4944 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4945 rpc_file_list_internals
,
4950 * 'net rpc file' entrypoint.
4951 * @param argc Standard main() style argc
4952 * @param argv Standard main() style argv. Initial components are already
4956 int net_rpc_file(int argc
, const char **argv
)
4958 struct functable func
[] = {
4959 {"close", rpc_file_close
},
4960 {"user", rpc_file_user
},
4962 {"info", rpc_file_info
},
4968 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4969 rpc_file_list_internals
,
4972 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
4976 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
4978 * All parameters are provided by the run_rpc_command function, except for
4979 * argc, argv which are passed through.
4981 * @param domain_sid The domain sid aquired from the remote server
4982 * @param cli A cli_state connected to the server.
4983 * @param mem_ctx Talloc context, destoyed on compleation of the function.
4984 * @param argc Standard main() style argc
4985 * @param argv Standard main() style argv. Initial components are already
4988 * @return Normal NTSTATUS return.
4991 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
4992 const char *domain_name
,
4993 struct cli_state
*cli
,
4994 struct rpc_pipe_client
*pipe_hnd
,
4995 TALLOC_CTX
*mem_ctx
,
4999 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5001 result
= rpccli_shutdown_abort(pipe_hnd
, mem_ctx
);
5003 if (NT_STATUS_IS_OK(result
)) {
5004 d_printf("\nShutdown successfully aborted\n");
5005 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5007 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5013 * ABORT the shutdown of a remote RPC Server, over winreg pipe
5015 * All parameters are provided by the run_rpc_command function, except for
5016 * argc, argv which are passed through.
5018 * @param domain_sid The domain sid aquired from the remote server
5019 * @param cli A cli_state connected to the server.
5020 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5021 * @param argc Standard main() style argc
5022 * @param argv Standard main() style argv. Initial components are already
5025 * @return Normal NTSTATUS return.
5028 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5029 const char *domain_name
,
5030 struct cli_state
*cli
,
5031 struct rpc_pipe_client
*pipe_hnd
,
5032 TALLOC_CTX
*mem_ctx
,
5036 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5038 result
= werror_to_ntstatus(rpccli_reg_abort_shutdown(pipe_hnd
, mem_ctx
));
5040 if (NT_STATUS_IS_OK(result
)) {
5041 d_printf("\nShutdown successfully aborted\n");
5042 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5044 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5050 * ABORT the Shut down of a remote RPC server
5052 * @param argc Standard main() style argc
5053 * @param argv Standard main() style argv. Initial components are already
5056 * @return A shell status integer (0 for success)
5059 static int rpc_shutdown_abort(int argc
, const char **argv
)
5061 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
5062 rpc_shutdown_abort_internals
,
5068 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5070 return run_rpc_command(NULL
, PI_WINREG
, 0,
5071 rpc_reg_shutdown_abort_internals
,
5076 * Shut down a remote RPC Server via initshutdown pipe
5078 * All parameters are provided by the run_rpc_command function, except for
5079 * argc, argv which are passes through.
5081 * @param domain_sid The domain sid aquired from the remote server
5082 * @param cli A cli_state connected to the server.
5083 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5084 * @param argc Standard main() style argc
5085 * @param argc Standard main() style argv. Initial components are already
5088 * @return Normal NTSTATUS return.
5091 static NTSTATUS
rpc_init_shutdown_internals(const DOM_SID
*domain_sid
,
5092 const char *domain_name
,
5093 struct cli_state
*cli
,
5094 struct rpc_pipe_client
*pipe_hnd
,
5095 TALLOC_CTX
*mem_ctx
,
5099 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5100 const char *msg
= "This machine will be shutdown shortly";
5101 uint32 timeout
= 20;
5107 timeout
= opt_timeout
;
5110 /* create an entry */
5111 result
= rpccli_shutdown_init(pipe_hnd
, mem_ctx
, msg
, timeout
, opt_reboot
,
5114 if (NT_STATUS_IS_OK(result
)) {
5115 d_printf("\nShutdown of remote machine succeeded\n");
5116 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5118 DEBUG(1,("Shutdown of remote machine failed!\n"));
5124 * Shut down a remote RPC Server via winreg pipe
5126 * All parameters are provided by the run_rpc_command function, except for
5127 * argc, argv which are passes through.
5129 * @param domain_sid The domain sid aquired from the remote server
5130 * @param cli A cli_state connected to the server.
5131 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5132 * @param argc Standard main() style argc
5133 * @param argc Standard main() style argv. Initial components are already
5136 * @return Normal NTSTATUS return.
5139 static NTSTATUS
rpc_reg_shutdown_internals(const DOM_SID
*domain_sid
,
5140 const char *domain_name
,
5141 struct cli_state
*cli
,
5142 struct rpc_pipe_client
*pipe_hnd
,
5143 TALLOC_CTX
*mem_ctx
,
5148 const char *msg
= "This machine will be shutdown shortly";
5149 uint32 timeout
= 20;
5154 struct poptOption long_options
[] = {
5155 {"message", 'm', POPT_ARG_STRING
, &msg
},
5156 {"timeout", 't', POPT_ARG_INT
, &timeout
},
5157 {"reboot", 'r', POPT_ARG_NONE
, &reboot
},
5158 {"force", 'f', POPT_ARG_NONE
, &force
},
5162 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
5163 POPT_CONTEXT_KEEP_FIRST
);
5165 rc
= poptGetNextOpt(pc
);
5168 /* an error occurred during option processing */
5169 DEBUG(0, ("%s: %s\n",
5170 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
5172 return NT_STATUS_INVALID_PARAMETER
;
5179 timeout
= opt_timeout
;
5182 /* create an entry */
5183 result
= rpccli_reg_shutdown(pipe_hnd
, mem_ctx
, msg
, timeout
, opt_reboot
, opt_force
);
5185 if (W_ERROR_IS_OK(result
)) {
5186 d_printf("\nShutdown of remote machine succeeded\n");
5188 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5189 if (W_ERROR_EQUAL(result
,WERR_MACHINE_LOCKED
))
5190 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5192 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(result
));
5195 return werror_to_ntstatus(result
);
5199 * Shut down a remote RPC server
5201 * @param argc Standard main() style argc
5202 * @param argc Standard main() style argv. Initial components are already
5205 * @return A shell status integer (0 for success)
5208 static int rpc_shutdown(int argc
, const char **argv
)
5210 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
5211 rpc_init_shutdown_internals
,
5215 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5216 rc
= run_rpc_command(NULL
, PI_WINREG
, 0,
5217 rpc_reg_shutdown_internals
, argc
, argv
);
5223 /***************************************************************************
5224 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5226 ***************************************************************************/
5229 * Add interdomain trust account to the RPC server.
5230 * All parameters (except for argc and argv) are passed by run_rpc_command
5233 * @param domain_sid The domain sid acquired from the server
5234 * @param cli A cli_state connected to the server.
5235 * @param mem_ctx Talloc context, destoyed on completion of the function.
5236 * @param argc Standard main() style argc
5237 * @param argc Standard main() style argv. Initial components are already
5240 * @return normal NTSTATUS return code
5243 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
5244 const char *domain_name
,
5245 struct cli_state
*cli
,
5246 struct rpc_pipe_client
*pipe_hnd
,
5247 TALLOC_CTX
*mem_ctx
,
5251 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5252 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5255 uint32 unknown
, user_rid
;
5258 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
5259 return NT_STATUS_INVALID_PARAMETER
;
5263 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5266 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5267 return NT_STATUS_NO_MEMORY
;
5270 strupper_m(acct_name
);
5272 /* Get samr policy handle */
5273 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
5275 if (!NT_STATUS_IS_OK(result
)) {
5279 /* Get domain policy handle */
5280 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
5281 MAXIMUM_ALLOWED_ACCESS
,
5282 domain_sid
, &domain_pol
);
5283 if (!NT_STATUS_IS_OK(result
)) {
5287 /* Create trusting domain's account */
5288 acb_info
= ACB_NORMAL
;
5289 unknown
= 0xe00500b0; /* No idea what this is - a permission mask?
5290 mimir: yes, most probably it is */
5292 result
= rpccli_samr_create_dom_user(pipe_hnd
, mem_ctx
, &domain_pol
,
5293 acct_name
, acb_info
, unknown
,
5294 &user_pol
, &user_rid
);
5295 if (!NT_STATUS_IS_OK(result
)) {
5300 SAM_USERINFO_CTR ctr
;
5301 SAM_USER_INFO_23 p23
;
5307 encode_pw_buffer(pwbuf
, argv
[1], STR_UNICODE
);
5311 ZERO_STRUCT(notime
);
5315 memset(hrs
.hours
, 0xFF, sizeof(hrs
.hours
));
5316 acb_info
= ACB_DOMTRUST
;
5318 init_sam_user_info23A(&p23
, ¬ime
, ¬ime
, ¬ime
,
5319 ¬ime
, ¬ime
, ¬ime
,
5320 nostr
, nostr
, nostr
, nostr
, nostr
,
5321 nostr
, nostr
, nostr
, nostr
, nostr
,
5322 0, 0, acb_info
, ACCT_FLAGS
, 168, &hrs
,
5323 0, 0, (char *)pwbuf
);
5324 ctr
.switch_value
= 23;
5325 ctr
.info
.id23
= &p23
;
5326 p23
.passmustchange
= 0;
5328 result
= rpccli_samr_set_userinfo(pipe_hnd
, mem_ctx
, &user_pol
, 23,
5329 &cli
->user_session_key
, &ctr
);
5331 if (!NT_STATUS_IS_OK(result
)) {
5332 DEBUG(0,("Could not set trust account password: %s\n",
5333 nt_errstr(result
)));
5339 SAFE_FREE(acct_name
);
5344 * Create interdomain trust account for a remote domain.
5346 * @param argc standard argc
5347 * @param argv standard argv without initial components
5349 * @return Integer status (0 means success)
5352 static int rpc_trustdom_add(int argc
, const char **argv
)
5355 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
5358 d_printf("Usage: net rpc trustdom add <domain>\n");
5365 * Remove interdomain trust account from the RPC server.
5366 * All parameters (except for argc and argv) are passed by run_rpc_command
5369 * @param domain_sid The domain sid acquired from the server
5370 * @param cli A cli_state connected to the server.
5371 * @param mem_ctx Talloc context, destoyed on completion of the function.
5372 * @param argc Standard main() style argc
5373 * @param argc Standard main() style argv. Initial components are already
5376 * @return normal NTSTATUS return code
5379 static NTSTATUS
rpc_trustdom_del_internals(const DOM_SID
*domain_sid
,
5380 const char *domain_name
,
5381 struct cli_state
*cli
,
5382 struct rpc_pipe_client
*pipe_hnd
,
5383 TALLOC_CTX
*mem_ctx
,
5387 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5388 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5391 DOM_SID trust_acct_sid
;
5392 uint32
*user_rids
, num_rids
, *name_types
;
5393 uint32 flags
= 0x000003e8; /* Unknown */
5396 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5397 return NT_STATUS_INVALID_PARAMETER
;
5401 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5403 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5405 if (acct_name
== NULL
)
5406 return NT_STATUS_NO_MEMORY
;
5408 strupper_m(acct_name
);
5410 names
= TALLOC_ARRAY(mem_ctx
, const char *, 1);
5411 names
[0] = acct_name
;
5414 /* Get samr policy handle */
5415 result
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
5417 if (!NT_STATUS_IS_OK(result
)) {
5421 /* Get domain policy handle */
5422 result
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_pol
,
5423 MAXIMUM_ALLOWED_ACCESS
,
5424 domain_sid
, &domain_pol
);
5425 if (!NT_STATUS_IS_OK(result
)) {
5429 result
= rpccli_samr_lookup_names(pipe_hnd
, mem_ctx
, &domain_pol
, flags
, 1,
5431 &user_rids
, &name_types
);
5433 if (!NT_STATUS_IS_OK(result
)) {
5437 result
= rpccli_samr_open_user(pipe_hnd
, mem_ctx
, &domain_pol
,
5438 MAXIMUM_ALLOWED_ACCESS
,
5439 user_rids
[0], &user_pol
);
5441 if (!NT_STATUS_IS_OK(result
)) {
5445 /* append the rid to the domain sid */
5446 sid_copy(&trust_acct_sid
, domain_sid
);
5447 if (!sid_append_rid(&trust_acct_sid
, user_rids
[0])) {
5451 /* remove the sid */
5453 result
= rpccli_samr_remove_sid_foreign_domain(pipe_hnd
, mem_ctx
, &user_pol
,
5456 if (!NT_STATUS_IS_OK(result
)) {
5462 result
= rpccli_samr_delete_dom_user(pipe_hnd
, mem_ctx
, &user_pol
);
5464 if (!NT_STATUS_IS_OK(result
)) {
5468 if (!NT_STATUS_IS_OK(result
)) {
5469 DEBUG(0,("Could not set trust account password: %s\n",
5470 nt_errstr(result
)));
5479 * Delete interdomain trust account for a remote domain.
5481 * @param argc standard argc
5482 * @param argv standard argv without initial components
5484 * @return Integer status (0 means success)
5487 static int rpc_trustdom_del(int argc
, const char **argv
)
5490 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_del_internals
,
5493 d_printf("Usage: net rpc trustdom del <domain>\n");
5500 * Establish trust relationship to a trusting domain.
5501 * Interdomain account must already be created on remote PDC.
5503 * @param argc standard argc
5504 * @param argv standard argv without initial components
5506 * @return Integer status (0 means success)
5509 static int rpc_trustdom_establish(int argc
, const char **argv
)
5511 struct cli_state
*cli
= NULL
;
5512 struct in_addr server_ip
;
5513 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5514 POLICY_HND connect_hnd
;
5515 TALLOC_CTX
*mem_ctx
;
5517 DOM_SID
*domain_sid
;
5520 char* domain_name_pol
;
5525 * Connect to \\server\ipc$ as 'our domain' account with password
5529 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
5533 domain_name
= smb_xstrdup(argv
[0]);
5534 strupper_m(domain_name
);
5536 /* account name used at first is our domain's name with '$' */
5537 asprintf(&acct_name
, "%s$", lp_workgroup());
5538 strupper_m(acct_name
);
5541 * opt_workgroup will be used by connection functions further,
5542 * hence it should be set to remote domain name instead of ours
5544 if (opt_workgroup
) {
5545 opt_workgroup
= smb_xstrdup(domain_name
);
5548 opt_user_name
= acct_name
;
5550 /* find the domain controller */
5551 if (!net_find_pdc(&server_ip
, pdc_name
, domain_name
)) {
5552 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5556 /* connect to ipc$ as username/password */
5557 nt_status
= connect_to_ipc(&cli
, &server_ip
, pdc_name
);
5558 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5560 /* Is it trusting domain account for sure ? */
5561 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5562 nt_errstr(nt_status
)));
5566 /* store who we connected to */
5568 saf_store( domain_name
, pdc_name
);
5571 * Connect to \\server\ipc$ again (this time anonymously)
5574 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ip
, (char*)pdc_name
);
5576 if (NT_STATUS_IS_ERR(nt_status
)) {
5577 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5578 domain_name
, nt_errstr(nt_status
)));
5582 * Use NetServerEnum2 to make sure we're talking to a proper server
5585 if (!cli_get_pdc_name(cli
, domain_name
, (char*)pdc_name
)) {
5586 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
5587 for domain %s\n", domain_name
));
5590 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5591 "domain %s", domain_name
))) {
5592 DEBUG(0, ("talloc_init() failed\n"));
5598 * Call LsaOpenPolicy and LsaQueryInfo
5601 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5603 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5608 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
5610 if (NT_STATUS_IS_ERR(nt_status
)) {
5611 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5612 nt_errstr(nt_status
)));
5617 /* Querying info level 5 */
5619 nt_status
= rpccli_lsa_query_info_policy(pipe_hnd
, mem_ctx
, &connect_hnd
,
5621 &domain_name_pol
, &domain_sid
);
5622 if (NT_STATUS_IS_ERR(nt_status
)) {
5623 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5624 nt_errstr(nt_status
)));
5629 /* There should be actually query info level 3 (following nt serv behaviour),
5630 but I still don't know if it's _really_ necessary */
5633 * Store the password in secrets db
5636 if (!secrets_store_trusted_domain_password(domain_name
,
5639 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5645 * Close the pipes and clean up
5648 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5649 if (NT_STATUS_IS_ERR(nt_status
)) {
5650 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5651 nt_errstr(nt_status
)));
5658 talloc_destroy(mem_ctx
);
5660 d_printf("Trust to domain %s established\n", domain_name
);
5665 * Revoke trust relationship to the remote domain
5667 * @param argc standard argc
5668 * @param argv standard argv without initial components
5670 * @return Integer status (0 means success)
5673 static int rpc_trustdom_revoke(int argc
, const char **argv
)
5677 if (argc
< 1) return -1;
5679 /* generate upper cased domain name */
5680 domain_name
= smb_xstrdup(argv
[0]);
5681 strupper_m(domain_name
);
5683 /* delete password of the trust */
5684 if (!trusted_domain_password_delete(domain_name
)) {
5685 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5694 * Usage for 'net rpc trustdom' command
5696 * @param argc standard argc
5697 * @param argv standard argv without inital components
5699 * @return Integer status returned to shell
5702 static int rpc_trustdom_usage(int argc
, const char **argv
)
5704 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
5705 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
5706 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
5707 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
5708 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
5709 d_printf(" net rpc trustdom vampire \t vampire interdomain trust relationships from remote server\n");
5714 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
5715 const char *domain_name
,
5716 struct cli_state
*cli
,
5717 struct rpc_pipe_client
*pipe_hnd
,
5718 TALLOC_CTX
*mem_ctx
,
5723 sid_to_string(str_sid
, domain_sid
);
5724 d_printf("%s\n", str_sid
);
5725 return NT_STATUS_OK
;
5728 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5730 fstring ascii_sid
, padding
;
5731 int pad_len
, col_len
= 20;
5733 /* convert sid into ascii string */
5734 sid_to_string(ascii_sid
, dom_sid
);
5736 /* calculate padding space for d_printf to look nicer */
5737 pad_len
= col_len
- strlen(trusted_dom_name
);
5738 padding
[pad_len
] = 0;
5739 do padding
[--pad_len
] = ' '; while (pad_len
);
5741 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5744 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5745 TALLOC_CTX
*mem_ctx
,
5748 const char *trusted_dom_name
)
5751 LSA_TRUSTED_DOMAIN_INFO
*info
;
5752 char *cleartextpwd
= NULL
;
5755 nt_status
= rpccli_lsa_query_trusted_domain_info_by_sid(pipe_hnd
, mem_ctx
, pol
, 4, &dom_sid
, &info
);
5757 if (NT_STATUS_IS_ERR(nt_status
)) {
5758 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5759 nt_errstr(nt_status
)));
5763 data
= data_blob(NULL
, info
->password
.password
.length
);
5765 memcpy(data
.data
, info
->password
.password
.data
, info
->password
.password
.length
);
5766 data
.length
= info
->password
.password
.length
;
5768 cleartextpwd
= decrypt_trustdom_secret(pipe_hnd
->cli
->pwd
.password
, &data
);
5770 if (cleartextpwd
== NULL
) {
5771 DEBUG(0,("retrieved NULL password\n"));
5772 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5776 if (!secrets_store_trusted_domain_password(trusted_dom_name
,
5779 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5780 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5784 #ifdef DEBUG_PASSWORD
5785 DEBUG(100,("sucessfully vampired trusted domain [%s], sid: [%s], password: [%s]\n",
5786 trusted_dom_name
, sid_string_static(&dom_sid
), cleartextpwd
));
5790 SAFE_FREE(cleartextpwd
);
5791 data_blob_free(&data
);
5796 static int rpc_trustdom_vampire(int argc
, const char **argv
)
5798 /* common variables */
5799 TALLOC_CTX
* mem_ctx
;
5800 struct cli_state
*cli
= NULL
;
5801 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5803 const char *domain_name
= NULL
;
5804 DOM_SID
*queried_dom_sid
;
5805 POLICY_HND connect_hnd
;
5807 /* trusted domains listing variables */
5808 unsigned int num_domains
, enum_ctx
= 0;
5810 DOM_SID
*domain_sids
;
5811 char **trusted_dom_names
;
5816 * Listing trusted domains (stored in secrets.tdb, if local)
5819 mem_ctx
= talloc_init("trust relationships vampire");
5822 * set domain and pdc name to local samba server (default)
5823 * or to remote one given in command line
5826 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
5827 domain_name
= opt_workgroup
;
5828 opt_target_workgroup
= opt_workgroup
;
5830 fstrcpy(pdc_name
, global_myname());
5831 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5832 opt_target_workgroup
= domain_name
;
5835 /* open \PIPE\lsarpc and open policy handle */
5836 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
5837 DEBUG(0, ("Couldn't connect to domain controller\n"));
5841 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5843 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5844 nt_errstr(nt_status
) ));
5849 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
5851 if (NT_STATUS_IS_ERR(nt_status
)) {
5852 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5853 nt_errstr(nt_status
)));
5858 /* query info level 5 to obtain sid of a domain being queried */
5859 nt_status
= rpccli_lsa_query_info_policy(
5860 pipe_hnd
, mem_ctx
, &connect_hnd
, 5 /* info level */,
5861 &dummy
, &queried_dom_sid
);
5863 if (NT_STATUS_IS_ERR(nt_status
)) {
5864 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5865 nt_errstr(nt_status
)));
5871 * Keep calling LsaEnumTrustdom over opened pipe until
5872 * the end of enumeration is reached
5875 d_printf("Vampire trusted domains:\n\n");
5878 nt_status
= rpccli_lsa_enum_trust_dom(pipe_hnd
, mem_ctx
, &connect_hnd
, &enum_ctx
,
5880 &trusted_dom_names
, &domain_sids
);
5882 if (NT_STATUS_IS_ERR(nt_status
)) {
5883 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5884 nt_errstr(nt_status
)));
5889 for (i
= 0; i
< num_domains
; i
++) {
5891 print_trusted_domain(&(domain_sids
[i
]), trusted_dom_names
[i
]);
5893 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5894 domain_sids
[i
], trusted_dom_names
[i
]);
5895 if (!NT_STATUS_IS_OK(nt_status
)) {
5902 * in case of no trusted domains say something rather
5903 * than just display blank line
5905 if (!num_domains
) d_printf("none\n");
5907 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5909 /* close this connection before doing next one */
5910 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5911 if (NT_STATUS_IS_ERR(nt_status
)) {
5912 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5913 nt_errstr(nt_status
)));
5918 /* close lsarpc pipe and connection to IPC$ */
5921 talloc_destroy(mem_ctx
);
5925 static int rpc_trustdom_list(int argc
, const char **argv
)
5927 /* common variables */
5928 TALLOC_CTX
* mem_ctx
;
5929 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5930 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5932 const char *domain_name
= NULL
;
5933 DOM_SID
*queried_dom_sid
;
5935 int ascii_dom_name_len
;
5936 POLICY_HND connect_hnd
;
5938 /* trusted domains listing variables */
5939 unsigned int num_domains
, enum_ctx
= 0;
5940 int i
, pad_len
, col_len
= 20;
5941 DOM_SID
*domain_sids
;
5942 char **trusted_dom_names
;
5946 /* trusting domains listing variables */
5947 POLICY_HND domain_hnd
;
5948 char **trusting_dom_names
;
5949 uint32
*trusting_dom_rids
;
5952 * Listing trusted domains (stored in secrets.tdb, if local)
5955 mem_ctx
= talloc_init("trust relationships listing");
5958 * set domain and pdc name to local samba server (default)
5959 * or to remote one given in command line
5962 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
5963 domain_name
= opt_workgroup
;
5964 opt_target_workgroup
= opt_workgroup
;
5966 fstrcpy(pdc_name
, global_myname());
5967 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5968 opt_target_workgroup
= domain_name
;
5971 /* open \PIPE\lsarpc and open policy handle */
5972 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
5973 DEBUG(0, ("Couldn't connect to domain controller\n"));
5977 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5979 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5980 nt_errstr(nt_status
) ));
5984 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
5986 if (NT_STATUS_IS_ERR(nt_status
)) {
5987 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5988 nt_errstr(nt_status
)));
5992 /* query info level 5 to obtain sid of a domain being queried */
5993 nt_status
= rpccli_lsa_query_info_policy(
5994 pipe_hnd
, mem_ctx
, &connect_hnd
, 5 /* info level */,
5995 &dummy
, &queried_dom_sid
);
5997 if (NT_STATUS_IS_ERR(nt_status
)) {
5998 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5999 nt_errstr(nt_status
)));
6004 * Keep calling LsaEnumTrustdom over opened pipe until
6005 * the end of enumeration is reached
6008 d_printf("Trusted domains list:\n\n");
6011 nt_status
= rpccli_lsa_enum_trust_dom(pipe_hnd
, mem_ctx
, &connect_hnd
, &enum_ctx
,
6013 &trusted_dom_names
, &domain_sids
);
6015 if (NT_STATUS_IS_ERR(nt_status
)) {
6016 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6017 nt_errstr(nt_status
)));
6021 for (i
= 0; i
< num_domains
; i
++) {
6022 print_trusted_domain(&(domain_sids
[i
]), trusted_dom_names
[i
]);
6026 * in case of no trusted domains say something rather
6027 * than just display blank line
6029 if (!num_domains
) d_printf("none\n");
6031 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6033 /* close this connection before doing next one */
6034 nt_status
= rpccli_lsa_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6035 if (NT_STATUS_IS_ERR(nt_status
)) {
6036 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6037 nt_errstr(nt_status
)));
6041 cli_rpc_pipe_close(pipe_hnd
);
6044 * Listing trusting domains (stored in passdb backend, if local)
6047 d_printf("\nTrusting domains list:\n\n");
6050 * Open \PIPE\samr and get needed policy handles
6052 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_SAMR
, &nt_status
);
6054 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6059 nt_status
= rpccli_samr_connect(pipe_hnd
, mem_ctx
, SA_RIGHT_SAM_OPEN_DOMAIN
,
6061 if (!NT_STATUS_IS_OK(nt_status
)) {
6062 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6063 nt_errstr(nt_status
)));
6067 /* SamrOpenDomain - we have to open domain policy handle in order to be
6068 able to enumerate accounts*/
6069 nt_status
= rpccli_samr_open_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6070 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6071 queried_dom_sid
, &domain_hnd
);
6072 if (!NT_STATUS_IS_OK(nt_status
)) {
6073 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6074 nt_errstr(nt_status
)));
6079 * perform actual enumeration
6082 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6085 nt_status
= rpccli_samr_enum_dom_users(pipe_hnd
, mem_ctx
, &domain_hnd
,
6086 &enum_ctx
, ACB_DOMTRUST
, 0xffff,
6087 &trusting_dom_names
, &trusting_dom_rids
,
6089 if (NT_STATUS_IS_ERR(nt_status
)) {
6090 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6091 nt_errstr(nt_status
)));
6095 for (i
= 0; i
< num_domains
; i
++) {
6098 * get each single domain's sid (do we _really_ need this ?):
6099 * 1) connect to domain's pdc
6100 * 2) query the pdc for domain's sid
6103 /* get rid of '$' tail */
6104 ascii_dom_name_len
= strlen(trusting_dom_names
[i
]);
6105 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6106 trusting_dom_names
[i
][ascii_dom_name_len
- 1] = '\0';
6108 /* calculate padding space for d_printf to look nicer */
6109 pad_len
= col_len
- strlen(trusting_dom_names
[i
]);
6110 padding
[pad_len
] = 0;
6111 do padding
[--pad_len
] = ' '; while (pad_len
);
6113 /* set opt_* variables to remote domain */
6114 strupper_m(trusting_dom_names
[i
]);
6115 opt_workgroup
= talloc_strdup(mem_ctx
, trusting_dom_names
[i
]);
6116 opt_target_workgroup
= opt_workgroup
;
6118 d_printf("%s%s", trusting_dom_names
[i
], padding
);
6120 /* connect to remote domain controller */
6121 remote_cli
= net_make_ipc_connection(NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
);
6123 /* query for domain's sid */
6124 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
6125 d_fprintf(stderr
, "couldn't get domain's sid\n");
6127 cli_shutdown(remote_cli
);
6130 d_fprintf(stderr
, "domain controller is not responding\n");
6134 if (!num_domains
) d_printf("none\n");
6136 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6138 /* close opened samr and domain policy handles */
6139 nt_status
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6140 if (!NT_STATUS_IS_OK(nt_status
)) {
6141 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6144 nt_status
= rpccli_samr_close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6145 if (!NT_STATUS_IS_OK(nt_status
)) {
6146 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6149 /* close samr pipe and connection to IPC$ */
6152 talloc_destroy(mem_ctx
);
6157 * Entrypoint for 'net rpc trustdom' code
6159 * @param argc standard argc
6160 * @param argv standard argv without initial components
6162 * @return Integer status (0 means success)
6165 static int rpc_trustdom(int argc
, const char **argv
)
6167 struct functable func
[] = {
6168 {"add", rpc_trustdom_add
},
6169 {"del", rpc_trustdom_del
},
6170 {"establish", rpc_trustdom_establish
},
6171 {"revoke", rpc_trustdom_revoke
},
6172 {"help", rpc_trustdom_usage
},
6173 {"list", rpc_trustdom_list
},
6174 {"vampire", rpc_trustdom_vampire
},
6179 rpc_trustdom_usage(argc
, argv
);
6183 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6187 * Check if a server will take rpc commands
6188 * @param flags Type of server to connect to (PDC, DMB, localhost)
6189 * if the host is not explicitly specified
6190 * @return BOOL (true means rpc supported)
6192 BOOL
net_rpc_check(unsigned flags
)
6194 struct cli_state cli
;
6196 struct in_addr server_ip
;
6197 char *server_name
= NULL
;
6199 /* flags (i.e. server type) may depend on command */
6200 if (!net_find_server(NULL
, flags
, &server_ip
, &server_name
))
6204 if (cli_initialise(&cli
) == False
)
6207 if (!cli_connect(&cli
, server_name
, &server_ip
))
6209 if (!attempt_netbios_session_request(&cli
, global_myname(),
6210 server_name
, &server_ip
))
6212 if (!cli_negprot(&cli
))
6214 if (cli
.protocol
< PROTOCOL_NT1
)
6223 /* dump sam database via samsync rpc calls */
6224 static int rpc_samdump(int argc
, const char **argv
) {
6225 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
6229 /* syncronise sam database via samsync rpc calls */
6230 static int rpc_vampire(int argc
, const char **argv
) {
6231 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
6236 * Migrate everything from a print-server
6238 * @param argc Standard main() style argc
6239 * @param argv Standard main() style argv. Initial components are already
6242 * @return A shell status integer (0 for success)
6244 * The order is important !
6245 * To successfully add drivers the print-queues have to exist !
6246 * Applying ACLs should be the last step, because you're easily locked out
6249 static int rpc_printer_migrate_all(int argc
, const char **argv
)
6254 printf("no server to migrate\n");
6258 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
6262 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
6266 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
6270 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
6274 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
6279 * Migrate print-drivers from a print-server
6281 * @param argc Standard main() style argc
6282 * @param argv Standard main() style argv. Initial components are already
6285 * @return A shell status integer (0 for success)
6287 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
6290 printf("no server to migrate\n");
6294 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6295 rpc_printer_migrate_drivers_internals
,
6300 * Migrate print-forms from a print-server
6302 * @param argc Standard main() style argc
6303 * @param argv Standard main() style argv. Initial components are already
6306 * @return A shell status integer (0 for success)
6308 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
6311 printf("no server to migrate\n");
6315 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6316 rpc_printer_migrate_forms_internals
,
6321 * Migrate printers from a print-server
6323 * @param argc Standard main() style argc
6324 * @param argv Standard main() style argv. Initial components are already
6327 * @return A shell status integer (0 for success)
6329 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
6332 printf("no server to migrate\n");
6336 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6337 rpc_printer_migrate_printers_internals
,
6342 * Migrate printer-ACLs from a print-server
6344 * @param argc Standard main() style argc
6345 * @param argv Standard main() style argv. Initial components are already
6348 * @return A shell status integer (0 for success)
6350 static int rpc_printer_migrate_security(int argc
, const char **argv
)
6353 printf("no server to migrate\n");
6357 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6358 rpc_printer_migrate_security_internals
,
6363 * Migrate printer-settings from a print-server
6365 * @param argc Standard main() style argc
6366 * @param argv Standard main() style argv. Initial components are already
6369 * @return A shell status integer (0 for success)
6371 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
6374 printf("no server to migrate\n");
6378 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6379 rpc_printer_migrate_settings_internals
,
6384 * 'net rpc printer' entrypoint.
6385 * @param argc Standard main() style argc
6386 * @param argv Standard main() style argv. Initial components are already
6390 int rpc_printer_migrate(int argc
, const char **argv
)
6393 /* ouch: when addriver and setdriver are called from within
6394 rpc_printer_migrate_drivers_internals, the printer-queue already
6397 struct functable func
[] = {
6398 {"all", rpc_printer_migrate_all
},
6399 {"drivers", rpc_printer_migrate_drivers
},
6400 {"forms", rpc_printer_migrate_forms
},
6401 {"help", rpc_printer_usage
},
6402 {"printers", rpc_printer_migrate_printers
},
6403 {"security", rpc_printer_migrate_security
},
6404 {"settings", rpc_printer_migrate_settings
},
6408 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6413 * List printers on a remote RPC server
6415 * @param argc Standard main() style argc
6416 * @param argv Standard main() style argv. Initial components are already
6419 * @return A shell status integer (0 for success)
6421 static int rpc_printer_list(int argc
, const char **argv
)
6424 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6425 rpc_printer_list_internals
,
6430 * List printer-drivers on a remote RPC server
6432 * @param argc Standard main() style argc
6433 * @param argv Standard main() style argv. Initial components are already
6436 * @return A shell status integer (0 for success)
6438 static int rpc_printer_driver_list(int argc
, const char **argv
)
6441 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6442 rpc_printer_driver_list_internals
,
6447 * Publish printer in ADS via MSRPC
6449 * @param argc Standard main() style argc
6450 * @param argv Standard main() style argv. Initial components are already
6453 * @return A shell status integer (0 for success)
6455 static int rpc_printer_publish_publish(int argc
, const char **argv
)
6458 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6459 rpc_printer_publish_publish_internals
,
6464 * Update printer in ADS via MSRPC
6466 * @param argc Standard main() style argc
6467 * @param argv Standard main() style argv. Initial components are already
6470 * @return A shell status integer (0 for success)
6472 static int rpc_printer_publish_update(int argc
, const char **argv
)
6475 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6476 rpc_printer_publish_update_internals
,
6481 * UnPublish printer in ADS via MSRPC
6483 * @param argc Standard main() style argc
6484 * @param argv Standard main() style argv. Initial components are already
6487 * @return A shell status integer (0 for success)
6489 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
6492 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6493 rpc_printer_publish_unpublish_internals
,
6498 * List published printers via MSRPC
6500 * @param argc Standard main() style argc
6501 * @param argv Standard main() style argv. Initial components are already
6504 * @return A shell status integer (0 for success)
6506 static int rpc_printer_publish_list(int argc
, const char **argv
)
6509 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6510 rpc_printer_publish_list_internals
,
6516 * Publish printer in ADS
6518 * @param argc Standard main() style argc
6519 * @param argv Standard main() style argv. Initial components are already
6522 * @return A shell status integer (0 for success)
6524 static int rpc_printer_publish(int argc
, const char **argv
)
6527 struct functable func
[] = {
6528 {"publish", rpc_printer_publish_publish
},
6529 {"update", rpc_printer_publish_update
},
6530 {"unpublish", rpc_printer_publish_unpublish
},
6531 {"list", rpc_printer_publish_list
},
6532 {"help", rpc_printer_usage
},
6537 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6538 rpc_printer_publish_list_internals
,
6541 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6547 * Display rpc printer help page.
6548 * @param argc Standard main() style argc
6549 * @param argv Standard main() style argv. Initial components are already
6552 int rpc_printer_usage(int argc
, const char **argv
)
6554 return net_help_printer(argc
, argv
);
6558 * 'net rpc printer' entrypoint.
6559 * @param argc Standard main() style argc
6560 * @param argv Standard main() style argv. Initial components are already
6563 int net_rpc_printer(int argc
, const char **argv
)
6565 struct functable func
[] = {
6566 {"list", rpc_printer_list
},
6567 {"migrate", rpc_printer_migrate
},
6568 {"driver", rpc_printer_driver_list
},
6569 {"publish", rpc_printer_publish
},
6574 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6575 rpc_printer_list_internals
,
6578 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6581 /****************************************************************************/
6585 * Basic usage function for 'net rpc'
6586 * @param argc Standard main() style argc
6587 * @param argv Standard main() style argv. Initial components are already
6591 int net_rpc_usage(int argc
, const char **argv
)
6593 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
6594 d_printf(" net rpc join \t\t\tto join a domain \n");
6595 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n");
6596 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
6597 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
6598 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
6599 d_printf(" net rpc group \t\tto list groups\n");
6600 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
6601 d_printf(" net rpc printer \t\tto list and migrate printers\n");
6602 d_printf(" net rpc file \t\t\tto list open files\n");
6603 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
6604 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
6605 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
6606 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
6607 d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n");
6608 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
6609 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
6610 d_printf(" net rpc rights\t\tto manage privileges assigned to SIDs\n");
6611 d_printf(" net rpc registry\t\tto manage registry hives\n");
6612 d_printf(" net rpc service\t\tto start, stop and query services\n");
6613 d_printf(" net rpc audit\t\t\tto modify global auditing settings\n");
6615 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
6616 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
6617 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
6618 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
6619 d_printf("\t-C or --comment=<message>\ttext message to display on impending shutdown\n");
6625 * Help function for 'net rpc'. Calls command specific help if requested
6626 * or displays usage of net rpc
6627 * @param argc Standard main() style argc
6628 * @param argv Standard main() style argv. Initial components are already
6632 int net_rpc_help(int argc
, const char **argv
)
6634 struct functable func
[] = {
6635 {"join", rpc_join_usage
},
6636 {"user", rpc_user_usage
},
6637 {"group", rpc_group_usage
},
6638 {"share", rpc_share_usage
},
6639 /*{"changetrustpw", rpc_changetrustpw_usage}, */
6640 {"trustdom", rpc_trustdom_usage
},
6641 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
6642 /*{"shutdown", rpc_shutdown_usage}, */
6643 {"vampire", rpc_vampire_usage
},
6648 net_rpc_usage(argc
, argv
);
6652 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6656 * 'net rpc' entrypoint.
6657 * @param argc Standard main() style argc
6658 * @param argv Standard main() style argv. Initial components are already
6662 int net_rpc(int argc
, const char **argv
)
6664 struct functable func
[] = {
6665 {"audit", net_rpc_audit
},
6666 {"info", net_rpc_info
},
6667 {"join", net_rpc_join
},
6668 {"oldjoin", net_rpc_oldjoin
},
6669 {"testjoin", net_rpc_testjoin
},
6670 {"user", net_rpc_user
},
6671 {"password", rpc_user_password
},
6672 {"group", net_rpc_group
},
6673 {"share", net_rpc_share
},
6674 {"file", net_rpc_file
},
6675 {"printer", net_rpc_printer
},
6676 {"changetrustpw", net_rpc_changetrustpw
},
6677 {"trustdom", rpc_trustdom
},
6678 {"abortshutdown", rpc_shutdown_abort
},
6679 {"shutdown", rpc_shutdown
},
6680 {"samdump", rpc_samdump
},
6681 {"vampire", rpc_vampire
},
6682 {"getsid", net_rpc_getsid
},
6683 {"rights", net_rpc_rights
},
6684 {"service", net_rpc_service
},
6685 {"registry", net_rpc_registry
},
6686 {"shell", net_rpc_shell
},
6687 {"help", net_rpc_help
},
6690 return net_run_function(argc
, argv
, func
, net_rpc_usage
);