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)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "utils/net.h"
28 * @brief RPC based subcommands for the 'net' utility.
30 * This file should contain much of the functionality that used to
31 * be found in rpcclient, execpt that the commands should change
32 * less often, and the fucntionality should be sane (the user is not
33 * expected to know a rid/sid before they conduct an operation etc.)
35 * @todo Perhaps eventually these should be split out into a number
36 * of files, as this could get quite big.
40 /* A function of this type is passed to the 'run_rpc_command' wrapper */
41 typedef NTSTATUS (*rpc_command_fn
)(const DOM_SID
*, const char *,
42 struct cli_state
*, TALLOC_CTX
*, int, const char **);
45 * Many of the RPC functions need the domain sid. This function gets
46 * it at the start of every run
48 * @param cli A cli_state already connected to the remote machine
50 * @return The Domain SID of the remote machine.
53 static DOM_SID
*net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
, char **domain_name
)
57 NTSTATUS result
= NT_STATUS_OK
;
58 uint32 info_class
= 5;
60 if (!cli_nt_session_open (cli
, PI_LSARPC
)) {
61 fprintf(stderr
, "could not initialise lsa pipe\n");
65 result
= cli_lsa_open_policy(cli
, mem_ctx
, False
,
66 SEC_RIGHTS_MAXIMUM_ALLOWED
,
68 if (!NT_STATUS_IS_OK(result
)) {
72 result
= cli_lsa_query_info_policy(cli
, mem_ctx
, &pol
, info_class
,
73 domain_name
, &domain_sid
);
74 if (!NT_STATUS_IS_OK(result
)) {
76 fprintf(stderr
, "could not obtain sid for domain %s\n", cli
->domain
);
78 if (!NT_STATUS_IS_OK(result
)) {
79 fprintf(stderr
, "error: %s\n", nt_errstr(result
));
85 cli_lsa_close(cli
, mem_ctx
, &pol
);
86 cli_nt_session_close(cli
);
92 * Run a single RPC command, from start to finish.
94 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
95 * @param conn_flag a NET_FLAG_ combination. Passed to
96 * net_make_ipc_connection.
97 * @param argc Standard main() style argc
98 * @param argc Standard main() style argv. Initial components are already
100 * @return A shell status integer (0 for success)
103 static int run_rpc_command(struct cli_state
*cli_arg
, const int pipe_idx
, int conn_flags
,
105 int argc
, const char **argv
)
107 struct cli_state
*cli
= NULL
;
113 /* make use of cli_state handed over as an argument, if possible */
115 cli
= net_make_ipc_connection(conn_flags
);
125 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
126 DEBUG(0, ("talloc_init() failed\n"));
131 domain_sid
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_name
);
133 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
134 if (!cli_nt_session_open(cli
, pipe_idx
)) {
135 DEBUG(0, ("Could not initialise pipe\n"));
139 nt_status
= fn(domain_sid
, domain_name
, cli
, mem_ctx
, argc
, argv
);
141 if (!NT_STATUS_IS_OK(nt_status
)) {
142 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
144 DEBUG(5, ("rpc command function succedded\n"));
147 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
148 if (cli
->nt_pipe_fnum
)
149 cli_nt_session_close(cli
);
152 /* close the connection only if it was opened here */
156 talloc_destroy(mem_ctx
);
158 return (!NT_STATUS_IS_OK(nt_status
));
162 /****************************************************************************/
166 * Force a change of the trust acccount password.
168 * All parameters are provided by the run_rpc_command function, except for
169 * argc, argv which are passes through.
171 * @param domain_sid The domain sid aquired from the remote server
172 * @param cli A cli_state connected to the server.
173 * @param mem_ctx Talloc context, destoyed on compleation of the function.
174 * @param argc Standard main() style argc
175 * @param argc Standard main() style argv. Initial components are already
178 * @return Normal NTSTATUS return.
181 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
182 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
183 int argc
, const char **argv
) {
185 return trust_pw_find_change_and_store_it(cli
, mem_ctx
, opt_target_workgroup
);
189 * Force a change of the trust acccount password.
191 * @param argc Standard main() style argc
192 * @param argc Standard main() style argv. Initial components are already
195 * @return A shell status integer (0 for success)
198 int net_rpc_changetrustpw(int argc
, const char **argv
)
200 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
201 rpc_changetrustpw_internals
,
206 /****************************************************************************/
210 * Join a domain, the old way.
212 * This uses 'machinename' as the inital password, and changes it.
214 * The password should be created with 'server manager' or equiv first.
216 * All parameters are provided by the run_rpc_command function, except for
217 * argc, argv which are passes through.
219 * @param domain_sid The domain sid aquired from the remote server
220 * @param cli A cli_state connected to the server.
221 * @param mem_ctx Talloc context, destoyed on compleation of the function.
222 * @param argc Standard main() style argc
223 * @param argc Standard main() style argv. Initial components are already
226 * @return Normal NTSTATUS return.
229 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
230 struct cli_state
*cli
,
232 int argc
, const char **argv
) {
234 fstring trust_passwd
;
235 unsigned char orig_trust_passwd_hash
[16];
237 uint32 sec_channel_type
;
240 check what type of join - if the user want's to join as
241 a BDC, the server must agree that we are a BDC.
244 sec_channel_type
= get_sec_channel_type(argv
[0]);
246 sec_channel_type
= get_sec_channel_type(NULL
);
249 fstrcpy(trust_passwd
, global_myname());
250 strlower_m(trust_passwd
);
253 * Machine names can be 15 characters, but the max length on
254 * a password is 14. --jerry
257 trust_passwd
[14] = '\0';
259 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
261 result
= trust_pw_change_and_store_it(cli
, mem_ctx
, opt_target_workgroup
,
262 orig_trust_passwd_hash
,
265 if (NT_STATUS_IS_OK(result
))
266 printf("Joined domain %s.\n",opt_target_workgroup
);
269 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
270 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
271 result
= NT_STATUS_UNSUCCESSFUL
;
278 * Join a domain, the old way.
280 * @param argc Standard main() style argc
281 * @param argc Standard main() style argv. Initial components are already
284 * @return A shell status integer (0 for success)
287 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
289 return run_rpc_command(NULL
, PI_NETLOGON
,
290 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
291 rpc_oldjoin_internals
,
296 * Join a domain, the old way. This function exists to allow
297 * the message to be displayed when oldjoin was explicitly
298 * requested, but not when it was implied by "net rpc join"
300 * @param argc Standard main() style argc
301 * @param argc Standard main() style argv. Initial components are already
304 * @return A shell status integer (0 for success)
307 static int net_rpc_oldjoin(int argc
, const char **argv
)
309 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
312 d_printf("Failed to join domain\n");
319 * Basic usage function for 'net rpc join'
320 * @param argc Standard main() style argc
321 * @param argc Standard main() style argv. Initial components are already
325 static int rpc_join_usage(int argc
, const char **argv
)
327 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
328 "\t to join a domain with admin username & password\n"\
329 "\t\t password will be prompted if needed and none is specified\n"\
330 "\t <type> can be (default MEMBER)\n"\
331 "\t\t BDC - Join as a BDC\n"\
332 "\t\t PDC - Join as a PDC\n"\
333 "\t\t MEMBER - Join as a MEMBER server\n");
335 net_common_flags_usage(argc
, argv
);
340 * 'net rpc join' entrypoint.
341 * @param argc Standard main() style argc
342 * @param argc Standard main() style argv. Initial components are already
345 * Main 'net_rpc_join()' (where the admain username/password is used) is
347 * Try to just change the password, but if that doesn't work, use/prompt
348 * for a username/password.
351 int net_rpc_join(int argc
, const char **argv
)
353 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
356 return net_rpc_join_newstyle(argc
, argv
);
362 * display info about a rpc domain
364 * All parameters are provided by the run_rpc_command function, except for
365 * argc, argv which are passed through.
367 * @param domain_sid The domain sid acquired from the remote server
368 * @param cli A cli_state connected to the server.
369 * @param mem_ctx Talloc context, destoyed on completion of the function.
370 * @param argc Standard main() style argc
371 * @param argv Standard main() style argv. Initial components are already
374 * @return Normal NTSTATUS return.
378 rpc_info_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
379 struct cli_state
*cli
,
380 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
382 POLICY_HND connect_pol
, domain_pol
;
383 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
387 sid_to_string(sid_str
, domain_sid
);
389 /* Get sam policy handle */
390 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
392 if (!NT_STATUS_IS_OK(result
)) {
396 /* Get domain policy handle */
397 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
398 MAXIMUM_ALLOWED_ACCESS
,
399 domain_sid
, &domain_pol
);
400 if (!NT_STATUS_IS_OK(result
)) {
405 result
= cli_samr_query_dom_info(cli
, mem_ctx
, &domain_pol
,
407 if (NT_STATUS_IS_OK(result
)) {
408 TALLOC_CTX
*ctx
= talloc_init("rpc_info_internals");
409 d_printf("Domain Name: %s\n", unistr2_tdup(ctx
, &ctr
.info
.inf2
.uni_domain
));
410 d_printf("Domain SID: %s\n", sid_str
);
411 d_printf("Sequence number: %u\n", ctr
.info
.inf2
.seq_num
);
412 d_printf("Num users: %u\n", ctr
.info
.inf2
.num_domain_usrs
);
413 d_printf("Num domain groups: %u\n", ctr
.info
.inf2
.num_domain_grps
);
414 d_printf("Num local groups: %u\n", ctr
.info
.inf2
.num_local_grps
);
424 * 'net rpc info' entrypoint.
425 * @param argc Standard main() style argc
426 * @param argc Standard main() style argv. Initial components are already
429 int net_rpc_info(int argc
, const char **argv
)
431 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
438 * Fetch domain SID into the local secrets.tdb
440 * All parameters are provided by the run_rpc_command function, except for
441 * argc, argv which are passes through.
443 * @param domain_sid The domain sid acquired from the remote server
444 * @param cli A cli_state connected to the server.
445 * @param mem_ctx Talloc context, destoyed on completion of the function.
446 * @param argc Standard main() style argc
447 * @param argv Standard main() style argv. Initial components are already
450 * @return Normal NTSTATUS return.
454 rpc_getsid_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
455 struct cli_state
*cli
,
456 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
460 sid_to_string(sid_str
, domain_sid
);
461 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
462 sid_str
, domain_name
);
464 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
465 DEBUG(0,("Can't store domain SID\n"));
466 return NT_STATUS_UNSUCCESSFUL
;
474 * 'net rpc getsid' entrypoint.
475 * @param argc Standard main() style argc
476 * @param argc Standard main() style argv. Initial components are already
479 int net_rpc_getsid(int argc
, const char **argv
)
481 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
482 rpc_getsid_internals
,
487 /****************************************************************************/
490 * Basic usage function for 'net rpc user'
491 * @param argc Standard main() style argc.
492 * @param argv Standard main() style argv. Initial components are already
496 static int rpc_user_usage(int argc
, const char **argv
)
498 return net_help_user(argc
, argv
);
502 * Add a new user to a remote RPC server
504 * All parameters are provided by the run_rpc_command function, except for
505 * argc, argv which are passes through.
507 * @param domain_sid The domain sid acquired from the remote server
508 * @param cli A cli_state connected to the server.
509 * @param mem_ctx Talloc context, destoyed on completion of the function.
510 * @param argc Standard main() style argc
511 * @param argv Standard main() style argv. Initial components are already
514 * @return Normal NTSTATUS return.
517 static NTSTATUS
rpc_user_add_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
518 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
519 int argc
, const char **argv
) {
521 POLICY_HND connect_pol
, domain_pol
, user_pol
;
522 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
523 const char *acct_name
;
525 uint32 unknown
, user_rid
;
528 d_printf("User must be specified\n");
529 rpc_user_usage(argc
, argv
);
535 /* Get sam policy handle */
537 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
539 if (!NT_STATUS_IS_OK(result
)) {
543 /* Get domain policy handle */
545 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
546 MAXIMUM_ALLOWED_ACCESS
,
547 domain_sid
, &domain_pol
);
548 if (!NT_STATUS_IS_OK(result
)) {
552 /* Create domain user */
554 acb_info
= ACB_NORMAL
;
555 unknown
= 0xe005000b; /* No idea what this is - a permission mask? */
557 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
558 acct_name
, acb_info
, unknown
,
559 &user_pol
, &user_rid
);
560 if (!NT_STATUS_IS_OK(result
)) {
565 if (!NT_STATUS_IS_OK(result
)) {
566 d_printf("Failed to add user %s - %s\n", acct_name
,
569 d_printf("Added user %s\n", acct_name
);
575 * Add a new user to a remote RPC server
577 * @param argc Standard main() style argc
578 * @param argv Standard main() style argv. Initial components are already
581 * @return A shell status integer (0 for success)
584 static int rpc_user_add(int argc
, const char **argv
)
586 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_add_internals
,
591 * Delete a user from a remote RPC server
593 * All parameters are provided by the run_rpc_command function, except for
594 * argc, argv which are passes through.
596 * @param domain_sid The domain sid acquired from the remote server
597 * @param cli A cli_state connected to the server.
598 * @param mem_ctx Talloc context, destoyed on completion of the function.
599 * @param argc Standard main() style argc
600 * @param argv Standard main() style argv. Initial components are already
603 * @return Normal NTSTATUS return.
606 static NTSTATUS
rpc_user_del_internals(const DOM_SID
*domain_sid
,
607 const char *domain_name
,
608 struct cli_state
*cli
,
610 int argc
, const char **argv
)
612 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
613 POLICY_HND connect_pol
, domain_pol
, user_pol
;
616 d_printf("User must be specified\n");
617 rpc_user_usage(argc
, argv
);
620 /* Get sam policy and domain handles */
622 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
625 if (!NT_STATUS_IS_OK(result
)) {
629 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
630 MAXIMUM_ALLOWED_ACCESS
,
631 domain_sid
, &domain_pol
);
633 if (!NT_STATUS_IS_OK(result
)) {
637 /* Get handle on user */
640 uint32
*user_rids
, num_rids
, *name_types
;
641 uint32 flags
= 0x000003e8; /* Unknown */
643 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
645 &num_rids
, &user_rids
,
648 if (!NT_STATUS_IS_OK(result
)) {
652 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
653 MAXIMUM_ALLOWED_ACCESS
,
654 user_rids
[0], &user_pol
);
656 if (!NT_STATUS_IS_OK(result
)) {
663 result
= cli_samr_delete_dom_user(cli
, mem_ctx
, &user_pol
);
665 if (!NT_STATUS_IS_OK(result
)) {
669 /* Display results */
677 * Delete a user from a remote RPC server
679 * @param argc Standard main() style argc
680 * @param argv Standard main() style argv. Initial components are already
683 * @return A shell status integer (0 for success)
686 static int rpc_user_delete(int argc
, const char **argv
)
688 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_del_internals
,
693 * Set a password for a user on a remote RPC server
695 * All parameters are provided by the run_rpc_command function, except for
696 * argc, argv which are passes through.
698 * @param domain_sid The domain sid acquired from the remote server
699 * @param cli A cli_state connected to the server.
700 * @param mem_ctx Talloc context, destoyed on completion of the function.
701 * @param argc Standard main() style argc
702 * @param argv Standard main() style argv. Initial components are already
705 * @return Normal NTSTATUS return.
708 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
709 const char *domain_name
,
710 struct cli_state
*cli
,
712 int argc
, const char **argv
)
714 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
715 POLICY_HND connect_pol
, domain_pol
, user_pol
;
716 SAM_USERINFO_CTR ctr
;
717 SAM_USER_INFO_24 p24
;
720 const char *new_password
;
724 d_printf("User must be specified\n");
725 rpc_user_usage(argc
, argv
);
732 new_password
= argv
[1];
734 asprintf(&prompt
, "Enter new password for %s:", user
);
735 new_password
= getpass(prompt
);
739 /* Get sam policy and domain handles */
741 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
744 if (!NT_STATUS_IS_OK(result
)) {
748 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
749 MAXIMUM_ALLOWED_ACCESS
,
750 domain_sid
, &domain_pol
);
752 if (!NT_STATUS_IS_OK(result
)) {
756 /* Get handle on user */
759 uint32
*user_rids
, num_rids
, *name_types
;
760 uint32 flags
= 0x000003e8; /* Unknown */
762 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
764 &num_rids
, &user_rids
,
767 if (!NT_STATUS_IS_OK(result
)) {
771 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
772 MAXIMUM_ALLOWED_ACCESS
,
773 user_rids
[0], &user_pol
);
775 if (!NT_STATUS_IS_OK(result
)) {
780 /* Set password on account */
785 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
787 init_sam_user_info24(&p24
, (char *)pwbuf
,24);
789 ctr
.switch_value
= 24;
790 ctr
.info
.id24
= &p24
;
792 result
= cli_samr_set_userinfo(cli
, mem_ctx
, &user_pol
, 24,
793 &cli
->user_session_key
, &ctr
);
795 if (!NT_STATUS_IS_OK(result
)) {
799 /* Display results */
807 * Set a user's password on a remote RPC server
809 * @param argc Standard main() style argc
810 * @param argv Standard main() style argv. Initial components are already
813 * @return A shell status integer (0 for success)
816 static int rpc_user_password(int argc
, const char **argv
)
818 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
823 * List user's groups on a remote RPC server
825 * All parameters are provided by the run_rpc_command function, except for
826 * argc, argv which are passes through.
828 * @param domain_sid The domain sid acquired from the remote server
829 * @param cli A cli_state connected to the server.
830 * @param mem_ctx Talloc context, destoyed on completion of the function.
831 * @param argc Standard main() style argc
832 * @param argv Standard main() style argv. Initial components are already
835 * @return Normal NTSTATUS return.
839 rpc_user_info_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
840 struct cli_state
*cli
,
841 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
843 POLICY_HND connect_pol
, domain_pol
, user_pol
;
844 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
845 uint32
*rids
, num_rids
, *name_types
, num_names
;
846 uint32 flags
= 0x000003e8; /* Unknown */
852 d_printf("User must be specified\n");
853 rpc_user_usage(argc
, argv
);
856 /* Get sam policy handle */
858 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
860 if (!NT_STATUS_IS_OK(result
)) goto done
;
862 /* Get domain policy handle */
864 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
865 MAXIMUM_ALLOWED_ACCESS
,
866 domain_sid
, &domain_pol
);
867 if (!NT_STATUS_IS_OK(result
)) goto done
;
869 /* Get handle on user */
871 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
873 &num_rids
, &rids
, &name_types
);
875 if (!NT_STATUS_IS_OK(result
)) goto done
;
877 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
878 MAXIMUM_ALLOWED_ACCESS
,
880 if (!NT_STATUS_IS_OK(result
)) goto done
;
882 result
= cli_samr_query_usergroups(cli
, mem_ctx
, &user_pol
,
883 &num_rids
, &user_gids
);
887 rids
= (uint32
*)talloc(mem_ctx
, sizeof(uint32
) * num_rids
);
889 for (i
= 0; i
< num_rids
; i
++)
890 rids
[i
] = user_gids
[i
].g_rid
;
892 result
= cli_samr_lookup_rids(cli
, mem_ctx
, &domain_pol
,
893 flags
, num_rids
, rids
,
894 &num_names
, &names
, &name_types
);
896 if (!NT_STATUS_IS_OK(result
)) {
900 /* Display results */
902 for (i
= 0; i
< num_names
; i
++)
903 printf("%s\n", names
[i
]);
910 * List a user's groups from a remote RPC server
912 * @param argc Standard main() style argc
913 * @param argv Standard main() style argv. Initial components are already
916 * @return A shell status integer (0 for success)
919 static int rpc_user_info(int argc
, const char **argv
)
921 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
926 * List users on a remote RPC server
928 * All parameters are provided by the run_rpc_command function, except for
929 * argc, argv which are passes through.
931 * @param domain_sid The domain sid acquired from the remote server
932 * @param cli A cli_state connected to the server.
933 * @param mem_ctx Talloc context, destoyed on completion of the function.
934 * @param argc Standard main() style argc
935 * @param argv Standard main() style argv. Initial components are already
938 * @return Normal NTSTATUS return.
942 rpc_user_list_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
943 struct cli_state
*cli
,
944 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
946 POLICY_HND connect_pol
, domain_pol
;
947 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
948 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
949 SAM_DISPINFO_CTR ctr
;
950 SAM_DISPINFO_1 info1
;
952 /* Get sam policy handle */
954 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
956 if (!NT_STATUS_IS_OK(result
)) {
960 /* Get domain policy handle */
962 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
963 MAXIMUM_ALLOWED_ACCESS
,
964 domain_sid
, &domain_pol
);
965 if (!NT_STATUS_IS_OK(result
)) {
969 /* Query domain users */
972 ctr
.sam
.info1
= &info1
;
973 if (opt_long_list_entries
)
974 d_printf("\nUser name Comment"\
975 "\n-----------------------------\n");
978 uint32 max_entries
, max_size
;
980 get_query_dispinfo_params(
981 loop_count
, &max_entries
, &max_size
);
983 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
984 &start_idx
, 1, &num_entries
,
985 max_entries
, max_size
, &ctr
);
988 for (i
= 0; i
< num_entries
; i
++) {
989 unistr2_to_ascii(user
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_name
, sizeof(user
)-1);
990 if (opt_long_list_entries
)
991 unistr2_to_ascii(desc
, &(&ctr
.sam
.info1
->str
[i
])->uni_acct_desc
, sizeof(desc
)-1);
993 if (opt_long_list_entries
)
994 printf("%-21.21s %s\n", user
, desc
);
996 printf("%s\n", user
);
998 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1005 * 'net rpc user' entrypoint.
1006 * @param argc Standard main() style argc
1007 * @param argc Standard main() style argv. Initial components are already
1011 int net_rpc_user(int argc
, const char **argv
)
1013 struct functable func
[] = {
1014 {"add", rpc_user_add
},
1015 {"info", rpc_user_info
},
1016 {"delete", rpc_user_delete
},
1017 {"password", rpc_user_password
},
1022 if (opt_long_list_entries
) {
1025 return run_rpc_command(NULL
,PI_SAMR
, 0,
1026 rpc_user_list_internals
,
1030 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1034 /****************************************************************************/
1037 * Basic usage function for 'net rpc group'
1038 * @param argc Standard main() style argc.
1039 * @param argv Standard main() style argv. Initial components are already
1043 static int rpc_group_usage(int argc
, const char **argv
)
1045 return net_help_group(argc
, argv
);
1049 * Delete group on a remote RPC server
1051 * All parameters are provided by the run_rpc_command function, except for
1052 * argc, argv which are passes through.
1054 * @param domain_sid The domain sid acquired from the remote server
1055 * @param cli A cli_state connected to the server.
1056 * @param mem_ctx Talloc context, destoyed on completion of the function.
1057 * @param argc Standard main() style argc
1058 * @param argv Standard main() style argv. Initial components are already
1061 * @return Normal NTSTATUS return.
1064 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1065 const char *domain_name
,
1066 struct cli_state
*cli
,
1067 TALLOC_CTX
*mem_ctx
,
1068 int argc
, const char **argv
)
1070 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1071 BOOL group_is_primary
= False
;
1072 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1074 uint32
*group_rids
, num_rids
, *name_types
, num_members
,
1075 *group_attrs
, group_rid
;
1076 uint32 flags
= 0x000003e8; /* Unknown */
1079 /* DOM_GID *user_gids; */
1080 SAM_USERINFO_CTR
*user_ctr
;
1084 d_printf("specify group\n");
1085 rpc_group_usage(argc
,argv
);
1086 return NT_STATUS_OK
; /* ok? */
1089 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1092 if (!NT_STATUS_IS_OK(result
)) {
1093 d_printf("Request samr_connect failed\n");
1097 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1098 MAXIMUM_ALLOWED_ACCESS
,
1099 domain_sid
, &domain_pol
);
1101 if (!NT_STATUS_IS_OK(result
)) {
1102 d_printf("Request open_domain failed\n");
1106 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
,
1108 &num_rids
, &group_rids
,
1111 if (!NT_STATUS_IS_OK(result
)) {
1112 d_printf("Lookup of '%s' failed\n",argv
[0]);
1116 switch (name_types
[0])
1118 case SID_NAME_DOM_GRP
:
1119 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
1120 MAXIMUM_ALLOWED_ACCESS
,
1121 group_rids
[0], &group_pol
);
1122 if (!NT_STATUS_IS_OK(result
)) {
1123 d_printf("Request open_group failed");
1127 group_rid
= group_rids
[0];
1129 result
= cli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
1130 &num_members
, &group_rids
,
1133 if (!NT_STATUS_IS_OK(result
)) {
1134 d_printf("Unable to query group members of %s",argv
[0]);
1139 d_printf("Domain Group %s (rid: %d) has %d members\n",
1140 argv
[0],group_rid
,num_members
);
1143 /* Check if group is anyone's primary group */
1144 for (i
= 0; i
< num_members
; i
++)
1146 result
= cli_samr_open_user(cli
, mem_ctx
, &domain_pol
,
1147 MAXIMUM_ALLOWED_ACCESS
,
1148 group_rids
[i
], &user_pol
);
1150 if (!NT_STATUS_IS_OK(result
)) {
1151 d_printf("Unable to open group member %d\n",group_rids
[i
]);
1155 ZERO_STRUCT(user_ctr
);
1157 result
= cli_samr_query_userinfo(cli
, mem_ctx
, &user_pol
,
1160 if (!NT_STATUS_IS_OK(result
)) {
1161 d_printf("Unable to lookup userinfo for group member %d\n",group_rids
[i
]);
1165 if (user_ctr
->info
.id21
->group_rid
== group_rid
) {
1166 unistr2_to_ascii(temp
, &(user_ctr
->info
.id21
)->uni_user_name
,
1169 d_printf("Group is primary group of %s\n",temp
);
1170 group_is_primary
= True
;
1173 cli_samr_close(cli
, mem_ctx
, &user_pol
);
1176 if (group_is_primary
) {
1177 d_printf("Unable to delete group because some of it's "
1178 "members have it as primary group\n");
1179 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1183 /* remove all group members */
1184 for (i
= 0; i
< num_members
; i
++)
1187 d_printf("Remove group member %d...",group_rids
[i
]);
1188 result
= cli_samr_del_groupmem(cli
, mem_ctx
, &group_pol
, group_rids
[i
]);
1190 if (NT_STATUS_IS_OK(result
)) {
1195 d_printf("failed\n");
1200 result
= cli_samr_delete_dom_group(cli
, mem_ctx
, &group_pol
);
1203 /* removing a local group is easier... */
1204 case SID_NAME_ALIAS
:
1205 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
1206 MAXIMUM_ALLOWED_ACCESS
,
1207 group_rids
[0], &group_pol
);
1209 if (!NT_STATUS_IS_OK(result
)) {
1210 d_printf("Request open_alias failed\n");
1214 result
= cli_samr_delete_dom_alias(cli
, mem_ctx
, &group_pol
);
1217 d_printf("%s is of type %s. This command is only for deleting local or global groups\n",
1218 argv
[0],sid_type_lookup(name_types
[0]));
1219 result
= NT_STATUS_UNSUCCESSFUL
;
1224 if (NT_STATUS_IS_OK(result
)) {
1226 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
[0]),argv
[0]);
1228 d_printf("Deleting of %s failed: %s\n",argv
[0],
1229 get_friendly_nt_error_msg(result
));
1237 static int rpc_group_delete(int argc
, const char **argv
)
1239 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1244 rpc_group_add_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
1245 struct cli_state
*cli
,
1246 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1248 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1249 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1250 GROUP_INFO_CTR group_info
;
1253 d_printf("Group name must be specified\n");
1254 rpc_group_usage(argc
, argv
);
1255 return NT_STATUS_OK
;
1258 /* Get sam policy handle */
1260 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1262 if (!NT_STATUS_IS_OK(result
)) goto done
;
1264 /* Get domain policy handle */
1266 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1267 MAXIMUM_ALLOWED_ACCESS
,
1268 domain_sid
, &domain_pol
);
1269 if (!NT_STATUS_IS_OK(result
)) goto done
;
1271 /* Create the group */
1273 result
= cli_samr_create_dom_group(cli
, mem_ctx
, &domain_pol
,
1274 argv
[0], MAXIMUM_ALLOWED_ACCESS
,
1276 if (!NT_STATUS_IS_OK(result
)) goto done
;
1278 if (strlen(opt_comment
) == 0) goto done
;
1280 /* We've got a comment to set */
1282 group_info
.switch_value1
= 4;
1283 init_samr_group_info4(&group_info
.group
.info4
, opt_comment
);
1285 result
= cli_samr_set_groupinfo(cli
, mem_ctx
, &group_pol
, &group_info
);
1286 if (!NT_STATUS_IS_OK(result
)) goto done
;
1289 if (NT_STATUS_IS_OK(result
))
1290 DEBUG(5, ("add group succeeded\n"));
1292 d_printf("add group failed: %s\n", nt_errstr(result
));
1298 rpc_alias_add_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
1299 struct cli_state
*cli
,
1300 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1302 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
1303 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1304 ALIAS_INFO_CTR alias_info
;
1307 d_printf("Group name must be specified\n");
1308 rpc_group_usage(argc
, argv
);
1309 return NT_STATUS_OK
;
1312 /* Get sam policy handle */
1314 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1316 if (!NT_STATUS_IS_OK(result
)) goto done
;
1318 /* Get domain policy handle */
1320 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1321 MAXIMUM_ALLOWED_ACCESS
,
1322 domain_sid
, &domain_pol
);
1323 if (!NT_STATUS_IS_OK(result
)) goto done
;
1325 /* Create the group */
1327 result
= cli_samr_create_dom_alias(cli
, mem_ctx
, &domain_pol
,
1328 argv
[0], &alias_pol
);
1329 if (!NT_STATUS_IS_OK(result
)) goto done
;
1331 if (strlen(opt_comment
) == 0) goto done
;
1333 /* We've got a comment to set */
1335 alias_info
.switch_value1
= 3;
1336 alias_info
.switch_value2
= 3;
1337 init_samr_alias_info3(&alias_info
.alias
.info3
, opt_comment
);
1339 result
= cli_samr_set_aliasinfo(cli
, mem_ctx
, &alias_pol
, &alias_info
);
1340 if (!NT_STATUS_IS_OK(result
)) goto done
;
1343 if (NT_STATUS_IS_OK(result
))
1344 DEBUG(5, ("add group succeeded\n"));
1346 d_printf("add group failed: %s\n", nt_errstr(result
));
1351 static int rpc_group_add(int argc
, const char **argv
)
1354 return run_rpc_command(NULL
, PI_SAMR
, 0,
1355 rpc_alias_add_internals
,
1358 return run_rpc_command(NULL
, PI_SAMR
, 0,
1359 rpc_group_add_internals
,
1364 get_sid_from_name(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
, const char *name
,
1365 DOM_SID
*sid
, enum SID_NAME_USE
*type
)
1367 int current_pipe
= cli
->pipe_idx
;
1369 DOM_SID
*sids
= NULL
;
1370 uint32
*types
= NULL
;
1372 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1374 if (current_pipe
!= PI_LSARPC
) {
1376 if (current_pipe
!= -1)
1377 cli_nt_session_close(cli
);
1379 if (!cli_nt_session_open(cli
, PI_LSARPC
))
1383 result
= cli_lsa_open_policy(cli
, mem_ctx
, False
,
1384 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1386 if (!NT_STATUS_IS_OK(result
))
1389 result
= cli_lsa_lookup_names(cli
, mem_ctx
, &lsa_pol
, 1,
1390 &name
, &sids
, &types
);
1392 if (NT_STATUS_IS_OK(result
)) {
1393 sid_copy(sid
, &sids
[0]);
1397 cli_lsa_close(cli
, mem_ctx
, &lsa_pol
);
1400 if (current_pipe
!= PI_LSARPC
) {
1401 cli_nt_session_close(cli
);
1402 if (current_pipe
!= -1)
1403 cli_nt_session_open(cli
, current_pipe
);
1406 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1408 /* Try as S-1-5-whatever */
1412 if (string_to_sid(&tmp_sid
, name
)) {
1413 sid_copy(sid
, &tmp_sid
);
1414 *type
= SID_NAME_UNKNOWN
;
1415 result
= NT_STATUS_OK
;
1423 rpc_add_groupmem(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1424 const DOM_SID
*group_sid
, const char *member
)
1426 POLICY_HND connect_pol
, domain_pol
;
1429 POLICY_HND group_pol
;
1432 uint32
*rids
= NULL
;
1433 uint32
*rid_types
= NULL
;
1437 sid_copy(&sid
, group_sid
);
1439 if (!sid_split_rid(&sid
, &group_rid
))
1440 return NT_STATUS_UNSUCCESSFUL
;
1442 /* Get sam policy handle */
1443 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1445 if (!NT_STATUS_IS_OK(result
))
1448 /* Get domain policy handle */
1449 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1450 MAXIMUM_ALLOWED_ACCESS
,
1452 if (!NT_STATUS_IS_OK(result
))
1455 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
1457 &num_rids
, &rids
, &rid_types
);
1459 if (!NT_STATUS_IS_OK(result
)) {
1460 d_printf("Could not lookup up group member %s\n", member
);
1464 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
1465 MAXIMUM_ALLOWED_ACCESS
,
1466 group_rid
, &group_pol
);
1468 if (!NT_STATUS_IS_OK(result
))
1471 result
= cli_samr_add_groupmem(cli
, mem_ctx
, &group_pol
, rids
[0]);
1474 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1479 rpc_add_aliasmem(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1480 const DOM_SID
*alias_sid
, const char *member
)
1482 POLICY_HND connect_pol
, domain_pol
;
1485 POLICY_HND alias_pol
;
1488 enum SID_NAME_USE member_type
;
1492 sid_copy(&sid
, alias_sid
);
1494 if (!sid_split_rid(&sid
, &alias_rid
))
1495 return NT_STATUS_UNSUCCESSFUL
;
1497 result
= get_sid_from_name(cli
, mem_ctx
, member
,
1498 &member_sid
, &member_type
);
1500 if (!NT_STATUS_IS_OK(result
)) {
1501 d_printf("Could not lookup up group member %s\n", member
);
1505 /* Get sam policy handle */
1506 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1508 if (!NT_STATUS_IS_OK(result
)) {
1512 /* Get domain policy handle */
1513 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1514 MAXIMUM_ALLOWED_ACCESS
,
1516 if (!NT_STATUS_IS_OK(result
)) {
1520 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
1521 MAXIMUM_ALLOWED_ACCESS
,
1522 alias_rid
, &alias_pol
);
1524 if (!NT_STATUS_IS_OK(result
))
1527 result
= cli_samr_add_aliasmem(cli
, mem_ctx
, &alias_pol
, &member_sid
);
1529 if (!NT_STATUS_IS_OK(result
))
1533 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1538 rpc_group_addmem_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
1539 struct cli_state
*cli
,
1540 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1543 enum SID_NAME_USE group_type
;
1546 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
1547 return NT_STATUS_UNSUCCESSFUL
;
1550 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1551 &group_sid
, &group_type
))) {
1552 d_printf("Could not lookup group name %s\n", argv
[0]);
1553 return NT_STATUS_UNSUCCESSFUL
;
1556 if (group_type
== SID_NAME_DOM_GRP
) {
1557 NTSTATUS result
= rpc_add_groupmem(cli
, mem_ctx
,
1558 &group_sid
, argv
[1]);
1560 if (!NT_STATUS_IS_OK(result
)) {
1561 d_printf("Could not add %s to %s: %s\n",
1562 argv
[1], argv
[0], nt_errstr(result
));
1567 if (group_type
== SID_NAME_ALIAS
) {
1568 NTSTATUS result
= rpc_add_aliasmem(cli
, mem_ctx
,
1569 &group_sid
, argv
[1]);
1571 if (!NT_STATUS_IS_OK(result
)) {
1572 d_printf("Could not add %s to %s: %s\n",
1573 argv
[1], argv
[0], nt_errstr(result
));
1578 d_printf("Can only add members to global or local groups which "
1579 "%s is not\n", argv
[0]);
1581 return NT_STATUS_UNSUCCESSFUL
;
1584 static int rpc_group_addmem(int argc
, const char **argv
)
1586 return run_rpc_command(NULL
, PI_SAMR
, 0,
1587 rpc_group_addmem_internals
,
1592 rpc_del_groupmem(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1593 const DOM_SID
*group_sid
, const char *member
)
1595 POLICY_HND connect_pol
, domain_pol
;
1598 POLICY_HND group_pol
;
1601 uint32
*rids
= NULL
;
1602 uint32
*rid_types
= NULL
;
1606 sid_copy(&sid
, group_sid
);
1608 if (!sid_split_rid(&sid
, &group_rid
))
1609 return NT_STATUS_UNSUCCESSFUL
;
1611 /* Get sam policy handle */
1612 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1614 if (!NT_STATUS_IS_OK(result
))
1617 /* Get domain policy handle */
1618 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1619 MAXIMUM_ALLOWED_ACCESS
,
1621 if (!NT_STATUS_IS_OK(result
))
1624 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
1626 &num_rids
, &rids
, &rid_types
);
1628 if (!NT_STATUS_IS_OK(result
)) {
1629 d_printf("Could not lookup up group member %s\n", member
);
1633 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
1634 MAXIMUM_ALLOWED_ACCESS
,
1635 group_rid
, &group_pol
);
1637 if (!NT_STATUS_IS_OK(result
))
1640 result
= cli_samr_del_groupmem(cli
, mem_ctx
, &group_pol
, rids
[0]);
1643 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1648 rpc_del_aliasmem(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1649 const DOM_SID
*alias_sid
, const char *member
)
1651 POLICY_HND connect_pol
, domain_pol
;
1654 POLICY_HND alias_pol
;
1657 enum SID_NAME_USE member_type
;
1661 sid_copy(&sid
, alias_sid
);
1663 if (!sid_split_rid(&sid
, &alias_rid
))
1664 return NT_STATUS_UNSUCCESSFUL
;
1666 result
= get_sid_from_name(cli
, mem_ctx
, member
,
1667 &member_sid
, &member_type
);
1669 if (!NT_STATUS_IS_OK(result
)) {
1670 d_printf("Could not lookup up group member %s\n", member
);
1674 /* Get sam policy handle */
1675 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1677 if (!NT_STATUS_IS_OK(result
)) {
1681 /* Get domain policy handle */
1682 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1683 MAXIMUM_ALLOWED_ACCESS
,
1685 if (!NT_STATUS_IS_OK(result
)) {
1689 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
1690 MAXIMUM_ALLOWED_ACCESS
,
1691 alias_rid
, &alias_pol
);
1693 if (!NT_STATUS_IS_OK(result
))
1696 result
= cli_samr_del_aliasmem(cli
, mem_ctx
, &alias_pol
, &member_sid
);
1698 if (!NT_STATUS_IS_OK(result
))
1702 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
1707 rpc_group_delmem_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
1708 struct cli_state
*cli
,
1709 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1712 enum SID_NAME_USE group_type
;
1715 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
1716 return NT_STATUS_UNSUCCESSFUL
;
1719 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1720 &group_sid
, &group_type
))) {
1721 d_printf("Could not lookup group name %s\n", argv
[0]);
1722 return NT_STATUS_UNSUCCESSFUL
;
1725 if (group_type
== SID_NAME_DOM_GRP
) {
1726 NTSTATUS result
= rpc_del_groupmem(cli
, mem_ctx
,
1727 &group_sid
, argv
[1]);
1729 if (!NT_STATUS_IS_OK(result
)) {
1730 d_printf("Could not del %s from %s: %s\n",
1731 argv
[1], argv
[0], nt_errstr(result
));
1736 if (group_type
== SID_NAME_ALIAS
) {
1737 NTSTATUS result
= rpc_del_aliasmem(cli
, mem_ctx
,
1738 &group_sid
, argv
[1]);
1740 if (!NT_STATUS_IS_OK(result
)) {
1741 d_printf("Could not del %s from %s: %s\n",
1742 argv
[1], argv
[0], nt_errstr(result
));
1747 d_printf("Can only delete members from global or local groups which "
1748 "%s is not\n", argv
[0]);
1750 return NT_STATUS_UNSUCCESSFUL
;
1753 static int rpc_group_delmem(int argc
, const char **argv
)
1755 return run_rpc_command(NULL
, PI_SAMR
, 0,
1756 rpc_group_delmem_internals
,
1761 * List groups on a remote RPC server
1763 * All parameters are provided by the run_rpc_command function, except for
1764 * argc, argv which are passes through.
1766 * @param domain_sid The domain sid acquired from the remote server
1767 * @param cli A cli_state connected to the server.
1768 * @param mem_ctx Talloc context, destoyed on completion of the function.
1769 * @param argc Standard main() style argc
1770 * @param argv Standard main() style argv. Initial components are already
1773 * @return Normal NTSTATUS return.
1777 rpc_group_list_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
1778 struct cli_state
*cli
,
1779 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1781 POLICY_HND connect_pol
, domain_pol
;
1782 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1783 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
1784 struct acct_info
*groups
;
1785 DOM_SID global_sid_Builtin
;
1786 BOOL global
= False
;
1788 BOOL builtin
= False
;
1796 for (i
=0; i
<argc
; i
++) {
1797 if (strequal(argv
[i
], "global"))
1800 if (strequal(argv
[i
], "local"))
1803 if (strequal(argv
[i
], "builtin"))
1807 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
1809 /* Get sam policy handle */
1811 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
1813 if (!NT_STATUS_IS_OK(result
)) {
1817 /* Get domain policy handle */
1819 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1820 MAXIMUM_ALLOWED_ACCESS
,
1821 domain_sid
, &domain_pol
);
1822 if (!NT_STATUS_IS_OK(result
)) {
1826 /* Query domain groups */
1827 if (opt_long_list_entries
)
1828 d_printf("\nGroup name Comment"\
1829 "\n-----------------------------\n");
1831 SAM_DISPINFO_CTR ctr
;
1832 SAM_DISPINFO_3 info3
;
1837 ctr
.sam
.info3
= &info3
;
1841 get_query_dispinfo_params(
1842 loop_count
, &max_entries
, &max_size
);
1844 result
= cli_samr_query_dispinfo(cli
, mem_ctx
, &domain_pol
,
1845 &start_idx
, 3, &num_entries
,
1846 max_entries
, max_size
, &ctr
);
1848 if (!NT_STATUS_IS_OK(result
) &&
1849 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
1852 for (i
= 0; i
< num_entries
; i
++) {
1854 fstring group
, desc
;
1856 unistr2_to_ascii(group
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_name
, sizeof(group
)-1);
1857 unistr2_to_ascii(desc
, &(&ctr
.sam
.info3
->str
[i
])->uni_grp_desc
, sizeof(desc
)-1);
1859 if (opt_long_list_entries
)
1860 printf("%-21.21s %-50.50s\n",
1863 printf("%s\n", group
);
1865 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1866 /* query domain aliases */
1871 /* The max_size field in cli_samr_enum_als_groups is more like
1872 * an account_control field with indiviual bits what to
1873 * retrieve. Set this to 0xffff as NT4 usrmgr.exe does to get
1874 * everything. I'm too lazy (sorry) to get this through to
1875 * rpc_parse/ etc. Volker */
1877 result
= cli_samr_enum_als_groups(cli
, mem_ctx
, &domain_pol
,
1879 &groups
, &num_entries
);
1881 if (!NT_STATUS_IS_OK(result
) &&
1882 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
1885 for (i
= 0; i
< num_entries
; i
++) {
1887 char *description
= NULL
;
1889 if (opt_long_list_entries
) {
1891 POLICY_HND alias_pol
;
1894 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli
, mem_ctx
,
1899 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli
, mem_ctx
,
1902 (NT_STATUS_IS_OK(cli_samr_close(cli
, mem_ctx
,
1904 description
= unistr2_tdup(mem_ctx
,
1905 &ctr
.alias
.info3
.uni_acct_desc
);
1909 if (description
!= NULL
) {
1910 printf("%-21.21s %-50.50s\n",
1911 groups
[i
].acct_name
,
1914 printf("%s\n", groups
[i
].acct_name
);
1917 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1918 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
1919 /* Get builtin policy handle */
1921 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
1922 MAXIMUM_ALLOWED_ACCESS
,
1923 &global_sid_Builtin
, &domain_pol
);
1924 if (!NT_STATUS_IS_OK(result
)) {
1927 /* query builtin aliases */
1930 if (!builtin
) break;
1932 result
= cli_samr_enum_als_groups(cli
, mem_ctx
, &domain_pol
,
1933 &start_idx
, max_entries
,
1934 &groups
, &num_entries
);
1936 if (!NT_STATUS_IS_OK(result
) &&
1937 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
1940 for (i
= 0; i
< num_entries
; i
++) {
1942 char *description
= NULL
;
1944 if (opt_long_list_entries
) {
1946 POLICY_HND alias_pol
;
1949 if ((NT_STATUS_IS_OK(cli_samr_open_alias(cli
, mem_ctx
,
1954 (NT_STATUS_IS_OK(cli_samr_query_alias_info(cli
, mem_ctx
,
1957 (NT_STATUS_IS_OK(cli_samr_close(cli
, mem_ctx
,
1959 description
= unistr2_tdup(mem_ctx
,
1960 &ctr
.alias
.info3
.uni_acct_desc
);
1964 if (description
!= NULL
) {
1965 printf("%-21.21s %-50.50s\n",
1966 groups
[i
].acct_name
,
1969 printf("%s\n", groups
[i
].acct_name
);
1972 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1978 static int rpc_group_list(int argc
, const char **argv
)
1980 return run_rpc_command(NULL
, PI_SAMR
, 0,
1981 rpc_group_list_internals
,
1986 rpc_list_group_members(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
1987 const char *domain_name
, const DOM_SID
*domain_sid
,
1988 POLICY_HND
*domain_pol
, uint32 rid
)
1991 POLICY_HND group_pol
;
1992 uint32 num_members
, *group_rids
, *group_attrs
;
1999 sid_to_string(sid_str
, domain_sid
);
2001 result
= cli_samr_open_group(cli
, mem_ctx
, domain_pol
,
2002 MAXIMUM_ALLOWED_ACCESS
,
2005 if (!NT_STATUS_IS_OK(result
))
2008 result
= cli_samr_query_groupmem(cli
, mem_ctx
, &group_pol
,
2009 &num_members
, &group_rids
,
2012 if (!NT_STATUS_IS_OK(result
))
2015 while (num_members
> 0) {
2016 int this_time
= 512;
2018 if (num_members
< this_time
)
2019 this_time
= num_members
;
2021 result
= cli_samr_lookup_rids(cli
, mem_ctx
, domain_pol
, 1000,
2022 this_time
, group_rids
,
2023 &num_names
, &names
, &name_types
);
2025 if (!NT_STATUS_IS_OK(result
))
2028 /* We only have users as members, but make the output
2029 the same as the output of alias members */
2031 for (i
= 0; i
< this_time
; i
++) {
2033 if (opt_long_list_entries
) {
2034 printf("%s-%d %s\\%s %d\n", sid_str
,
2035 group_rids
[i
], domain_name
, names
[i
],
2038 printf("%s\\%s\n", domain_name
, names
[i
]);
2042 num_members
-= this_time
;
2046 return NT_STATUS_OK
;
2050 rpc_list_alias_members(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2051 POLICY_HND
*domain_pol
, uint32 rid
)
2054 POLICY_HND alias_pol
, lsa_pol
;
2056 DOM_SID
*alias_sids
;
2062 result
= cli_samr_open_alias(cli
, mem_ctx
, domain_pol
,
2063 MAXIMUM_ALLOWED_ACCESS
, rid
, &alias_pol
);
2065 if (!NT_STATUS_IS_OK(result
))
2068 result
= cli_samr_query_aliasmem(cli
, mem_ctx
, &alias_pol
,
2069 &num_members
, &alias_sids
);
2071 if (!NT_STATUS_IS_OK(result
)) {
2072 d_printf("Couldn't list alias members\n");
2076 if (num_members
== 0) {
2077 return NT_STATUS_OK
;
2080 cli_nt_session_close(cli
);
2082 if (!cli_nt_session_open(cli
, PI_LSARPC
)) {
2083 d_printf("Couldn't open LSA pipe\n");
2087 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
2088 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2090 if (!NT_STATUS_IS_OK(result
)) {
2091 d_printf("Couldn't open LSA policy handle\n");
2095 result
= cli_lsa_lookup_sids(cli
, mem_ctx
, &lsa_pol
, num_members
,
2097 &domains
, &names
, &types
);
2099 if (!NT_STATUS_IS_OK(result
) &&
2100 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2101 d_printf("Couldn't lookup SIDs\n");
2105 for (i
= 0; i
< num_members
; i
++) {
2107 sid_to_string(sid_str
, &alias_sids
[i
]);
2109 if (opt_long_list_entries
) {
2110 printf("%s %s\\%s %d\n", sid_str
,
2111 domains
[i
] ? domains
[i
] : "*unknown*",
2112 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2115 printf("%s\\%s\n", domains
[i
], names
[i
]);
2117 printf("%s\n", sid_str
);
2121 return NT_STATUS_OK
;
2125 rpc_group_members_internals(const DOM_SID
*domain_sid
,
2126 const char *domain_name
,
2127 struct cli_state
*cli
,
2128 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
2131 POLICY_HND connect_pol
, domain_pol
;
2132 uint32 num_rids
, *rids
, *rid_types
;
2134 /* Get sam policy handle */
2136 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2139 if (!NT_STATUS_IS_OK(result
))
2142 /* Get domain policy handle */
2144 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
2145 MAXIMUM_ALLOWED_ACCESS
,
2146 domain_sid
, &domain_pol
);
2148 if (!NT_STATUS_IS_OK(result
))
2151 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
2152 1, argv
, &num_rids
, &rids
, &rid_types
);
2154 if (!NT_STATUS_IS_OK(result
)) {
2156 /* Ok, did not find it in the global sam, try with builtin */
2158 DOM_SID sid_Builtin
;
2160 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
2162 string_to_sid(&sid_Builtin
, "S-1-5-32");
2164 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
2165 MAXIMUM_ALLOWED_ACCESS
,
2166 &sid_Builtin
, &domain_pol
);
2168 if (!NT_STATUS_IS_OK(result
)) {
2169 d_printf("Couldn't find group %s\n", argv
[0]);
2173 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
2177 if (!NT_STATUS_IS_OK(result
)) {
2178 d_printf("Couldn't find group %s\n", argv
[0]);
2183 if (num_rids
!= 1) {
2184 d_printf("Couldn't find group %s\n", argv
[0]);
2188 if (rid_types
[0] == SID_NAME_DOM_GRP
) {
2189 return rpc_list_group_members(cli
, mem_ctx
, domain_name
,
2190 domain_sid
, &domain_pol
,
2194 if (rid_types
[0] == SID_NAME_ALIAS
) {
2195 return rpc_list_alias_members(cli
, mem_ctx
, &domain_pol
,
2199 return NT_STATUS_NO_SUCH_GROUP
;
2202 static int rpc_group_members(int argc
, const char **argv
)
2205 return rpc_group_usage(argc
, argv
);
2208 return run_rpc_command(NULL
, PI_SAMR
, 0,
2209 rpc_group_members_internals
,
2214 rpc_group_rename_internals(const DOM_SID
*domain_sid
,
2215 const char *domain_name
,
2216 struct cli_state
*cli
,
2217 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
2220 POLICY_HND connect_pol
, domain_pol
, group_pol
;
2221 uint32 num_rids
, *rids
, *rid_types
;
2225 d_printf("Usage: 'net rpc group rename group newname'\n");
2226 return NT_STATUS_UNSUCCESSFUL
;
2229 /* Get sam policy handle */
2231 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
2234 if (!NT_STATUS_IS_OK(result
))
2237 /* Get domain policy handle */
2239 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
2240 MAXIMUM_ALLOWED_ACCESS
,
2241 domain_sid
, &domain_pol
);
2243 if (!NT_STATUS_IS_OK(result
))
2246 result
= cli_samr_lookup_names(cli
, mem_ctx
, &domain_pol
, 1000,
2247 1, argv
, &num_rids
, &rids
, &rid_types
);
2249 if (num_rids
!= 1) {
2250 d_printf("Couldn't find group %s\n", argv
[0]);
2254 if (rid_types
[0] != SID_NAME_DOM_GRP
) {
2255 d_printf("Can only rename domain groups\n");
2256 return NT_STATUS_UNSUCCESSFUL
;
2259 result
= cli_samr_open_group(cli
, mem_ctx
, &domain_pol
,
2260 MAXIMUM_ALLOWED_ACCESS
,
2261 rids
[0], &group_pol
);
2263 if (!NT_STATUS_IS_OK(result
))
2268 ctr
.switch_value1
= 2;
2269 init_samr_group_info2(&ctr
.group
.info2
, argv
[1]);
2271 result
= cli_samr_set_groupinfo(cli
, mem_ctx
, &group_pol
, &ctr
);
2273 if (!NT_STATUS_IS_OK(result
))
2276 return NT_STATUS_NO_SUCH_GROUP
;
2279 static int rpc_group_rename(int argc
, const char **argv
)
2282 return rpc_group_usage(argc
, argv
);
2285 return run_rpc_command(NULL
, PI_SAMR
, 0,
2286 rpc_group_rename_internals
,
2291 * 'net rpc group' entrypoint.
2292 * @param argc Standard main() style argc
2293 * @param argc Standard main() style argv. Initial components are already
2297 int net_rpc_group(int argc
, const char **argv
)
2299 struct functable func
[] = {
2300 {"add", rpc_group_add
},
2301 {"delete", rpc_group_delete
},
2302 {"addmem", rpc_group_addmem
},
2303 {"delmem", rpc_group_delmem
},
2304 {"list", rpc_group_list
},
2305 {"members", rpc_group_members
},
2306 {"rename", rpc_group_rename
},
2311 if (opt_long_list_entries
) {
2314 return run_rpc_command(NULL
, PI_SAMR
, 0,
2315 rpc_group_list_internals
,
2319 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
2322 /****************************************************************************/
2324 static int rpc_share_usage(int argc
, const char **argv
)
2326 return net_help_share(argc
, argv
);
2330 * Add a share on a remote RPC server
2332 * All parameters are provided by the run_rpc_command function, except for
2333 * argc, argv which are passes through.
2335 * @param domain_sid The domain sid acquired from the remote server
2336 * @param cli A cli_state connected to the server.
2337 * @param mem_ctx Talloc context, destoyed on completion of the function.
2338 * @param argc Standard main() style argc
2339 * @param argv Standard main() style argv. Initial components are already
2342 * @return Normal NTSTATUS return.
2345 rpc_share_add_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
2346 struct cli_state
*cli
,
2347 TALLOC_CTX
*mem_ctx
,int argc
, const char **argv
)
2350 char *sharename
=talloc_strdup(mem_ctx
, argv
[0]);
2352 uint32 type
=0; /* only allow disk shares to be added */
2353 uint32 num_users
=0, perms
=0;
2354 char *password
=NULL
; /* don't allow a share password */
2357 path
= strchr(sharename
, '=');
2359 return NT_STATUS_UNSUCCESSFUL
;
2362 result
= cli_srvsvc_net_share_add(cli
, mem_ctx
, sharename
, type
,
2363 opt_comment
, perms
, opt_maxusers
,
2364 num_users
, path
, password
,
2366 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
2369 static int rpc_share_add(int argc
, const char **argv
)
2371 if ((argc
< 1) || !strchr(argv
[0], '=')) {
2372 DEBUG(1,("Sharename or path not specified on add\n"));
2373 return rpc_share_usage(argc
, argv
);
2375 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2376 rpc_share_add_internals
,
2381 * Delete a share on a remote RPC server
2383 * All parameters are provided by the run_rpc_command function, except for
2384 * argc, argv which are passes through.
2386 * @param domain_sid The domain sid acquired from the remote server
2387 * @param cli A cli_state connected to the server.
2388 * @param mem_ctx Talloc context, destoyed on completion of the function.
2389 * @param argc Standard main() style argc
2390 * @param argv Standard main() style argv. Initial components are already
2393 * @return Normal NTSTATUS return.
2396 rpc_share_del_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
2397 struct cli_state
*cli
,
2398 TALLOC_CTX
*mem_ctx
,int argc
, const char **argv
)
2402 result
= cli_srvsvc_net_share_del(cli
, mem_ctx
, argv
[0]);
2403 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
2407 * Delete a share on a remote RPC server
2409 * @param domain_sid The domain sid acquired from the remote server
2410 * @param argc Standard main() style argc
2411 * @param argv Standard main() style argv. Initial components are already
2414 * @return A shell status integer (0 for success)
2416 static int rpc_share_delete(int argc
, const char **argv
)
2419 DEBUG(1,("Sharename not specified on delete\n"));
2420 return rpc_share_usage(argc
, argv
);
2422 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2423 rpc_share_del_internals
,
2428 * Formatted print of share info
2430 * @param info1 pointer to SRV_SHARE_INFO_1 to format
2433 static void display_share_info_1(SRV_SHARE_INFO_1
*info1
)
2435 fstring netname
= "", remark
= "";
2437 rpcstr_pull_unistr2_fstring(netname
, &info1
->info_1_str
.uni_netname
);
2438 rpcstr_pull_unistr2_fstring(remark
, &info1
->info_1_str
.uni_remark
);
2440 if (opt_long_list_entries
) {
2441 d_printf("%-12s %-8.8s %-50s\n",
2442 netname
, share_type
[info1
->info_1
.type
], remark
);
2444 d_printf("%s\n", netname
);
2450 * List shares on a remote RPC server
2452 * All parameters are provided by the run_rpc_command function, except for
2453 * argc, argv which are passes through.
2455 * @param domain_sid The domain sid acquired from the remote server
2456 * @param cli A cli_state connected to the server.
2457 * @param mem_ctx Talloc context, destoyed on completion of the function.
2458 * @param argc Standard main() style argc
2459 * @param argv Standard main() style argv. Initial components are already
2462 * @return Normal NTSTATUS return.
2466 rpc_share_list_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
2467 struct cli_state
*cli
,
2468 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
2470 SRV_SHARE_INFO_CTR ctr
;
2473 uint32 preferred_len
= 0xffffffff, i
;
2475 init_enum_hnd(&hnd
, 0);
2477 result
= cli_srvsvc_net_share_enum(
2478 cli
, mem_ctx
, 1, &ctr
, preferred_len
, &hnd
);
2480 if (!W_ERROR_IS_OK(result
))
2483 /* Display results */
2485 if (opt_long_list_entries
) {
2487 "\nEnumerating shared resources (exports) on remote server:\n\n"\
2488 "\nShare name Type Description\n"\
2489 "---------- ---- -----------\n");
2491 for (i
= 0; i
< ctr
.num_entries
; i
++)
2492 display_share_info_1(&ctr
.share
.info1
[i
]);
2494 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
2498 * Migrate shares from a remote RPC server to the local RPC srever
2500 * All parameters are provided by the run_rpc_command function, except for
2501 * argc, argv which are passes through.
2503 * @param domain_sid The domain sid acquired from the remote server
2504 * @param cli A cli_state connected to the server.
2505 * @param mem_ctx Talloc context, destoyed on completion of the function.
2506 * @param argc Standard main() style argc
2507 * @param argv Standard main() style argv. Initial components are already
2510 * @return Normal NTSTATUS return.
2513 rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
2514 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2515 int argc
, const char **argv
)
2518 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2519 SRV_SHARE_INFO_CTR ctr_src
;
2521 uint32 type
= 0; /* only allow disk shares to be added */
2522 uint32 num_uses
= 0, perms
= 0, max_uses
= 0;
2523 char *password
= NULL
; /* don't allow a share password */
2524 uint32 preferred_len
= 0xffffffff, i
;
2525 BOOL got_dst_srvsvc_pipe
= False
;
2526 struct cli_state
*cli_dst
= NULL
;
2527 uint32 level
= 502; /* includes secdesc */
2528 SEC_DESC
*share_sd
= NULL
;
2530 init_enum_hnd(&hnd
, 0);
2532 result
= cli_srvsvc_net_share_enum(
2533 cli
, mem_ctx
, level
, &ctr_src
, preferred_len
, &hnd
);
2534 if (!W_ERROR_IS_OK(result
))
2537 /* connect local PI_SRVSVC */
2538 nt_status
= connect_pipe(&cli_dst
, PI_SRVSVC
, &got_dst_srvsvc_pipe
);
2539 if (!NT_STATUS_IS_OK(nt_status
))
2543 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
2545 fstring netname
= "", remark
= "", path
= "";
2546 /* reset error-code */
2547 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2549 rpcstr_pull_unistr2_fstring(
2550 netname
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_netname
);
2551 rpcstr_pull_unistr2_fstring(
2552 remark
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_remark
);
2553 rpcstr_pull_unistr2_fstring(
2554 path
, &ctr_src
.share
.info502
[i
].info_502_str
.uni_path
);
2555 num_uses
= ctr_src
.share
.info502
[i
].info_502
.num_uses
;
2556 max_uses
= ctr_src
.share
.info502
[i
].info_502
.max_uses
;
2557 perms
= ctr_src
.share
.info502
[i
].info_502
.perms
;
2561 share_sd
= dup_sec_desc(
2562 mem_ctx
, ctr_src
.share
.info502
[i
].info_502_str
.sd
);
2564 /* since we do not have NetShareGetInfo implemented in samba3 we
2565 only can skip inside the enum-ctr_src */
2567 char *one_share
= talloc_strdup(mem_ctx
, argv
[0]);
2568 if (!strequal(netname
, one_share
))
2572 /* skip builtin shares */
2573 /* FIXME: should print$ be added too ? */
2574 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
2575 strequal(netname
,"global"))
2578 /* only work with file-shares */
2579 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
2580 d_printf("skipping [%s]: not a file share.\n", netname
);
2588 /* finallly add the share on the dst server
2589 please note that samba currently does not allow to
2590 add a share without existing directory */
2592 printf("migrating: [%s], path: %s, comment: %s, %s share-ACLs\n",
2593 netname
, path
, remark
, opt_acls
? "including" : "without" );
2595 if (opt_verbose
&& opt_acls
)
2596 display_sec_desc(share_sd
);
2598 result
= cli_srvsvc_net_share_add(cli_dst
, mem_ctx
, netname
, type
,
2599 remark
, perms
, max_uses
,
2600 num_uses
, path
, password
,
2603 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
2604 printf(" [%s] does already exist\n", netname
);
2608 if (!W_ERROR_IS_OK(result
)) {
2609 printf("cannot add share: %s\n", dos_errstr(result
));
2615 nt_status
= NT_STATUS_OK
;
2618 if (got_dst_srvsvc_pipe
) {
2619 cli_nt_session_close(cli_dst
);
2620 cli_shutdown(cli_dst
);
2628 * Migrate shares from a rpc-server to another
2630 * @param argc Standard main() style argc
2631 * @param argv Standard main() style argv. Initial components are already
2634 * @return A shell status integer (0 for success)
2636 static int rpc_share_migrate_shares(int argc
, const char **argv
)
2640 printf("no server to migrate\n");
2644 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2645 rpc_share_migrate_shares_internals
,
2649 typedef struct copy_clistate
{
2650 TALLOC_CTX
*mem_ctx
;
2651 struct cli_state
*cli_share_src
;
2652 struct cli_state
*cli_share_dst
;
2660 * @param f file_info
2661 * @param mask current search mask
2662 * @param state arg-pointer
2665 static void copy_fn(file_info
*f
, const char *mask
, void *state
)
2667 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2668 struct copy_clistate
*local_state
= (struct copy_clistate
*)state
;
2669 fstring filename
, new_mask
, dir
;
2671 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
2674 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
2677 if (f
->mode
& aDIR
) {
2679 DEBUG(3,("got dir: %s\n", f
->name
));
2681 fstrcpy(dir
, local_state
->cwd
);
2683 fstrcat(dir
, f
->name
);
2685 /* create that directory */
2686 nt_status
= net_copy_file(local_state
->mem_ctx
,
2687 local_state
->cli_share_src
,
2688 local_state
->cli_share_dst
,
2690 opt_acls
? True
: False
,
2691 opt_attrs
? True
: False
,
2692 opt_timestamps
? True
: False
,
2695 if (!NT_STATUS_IS_OK(nt_status
))
2696 printf("could not copy dir %s: %s\n",
2697 dir
, nt_errstr(nt_status
));
2699 /* search below that directory */
2700 fstrcpy(new_mask
, dir
);
2701 fstrcat(new_mask
, "\\*");
2703 if (!sync_files(local_state
->mem_ctx
,
2704 local_state
->cli_share_src
,
2705 local_state
->cli_share_dst
,
2708 printf("could not sync files\n");
2715 fstrcpy(filename
, local_state
->cwd
);
2716 fstrcat(filename
, "\\");
2717 fstrcat(filename
, f
->name
);
2719 DEBUG(3,("got file: %s\n", filename
));
2721 nt_status
= net_copy_file(local_state
->mem_ctx
,
2722 local_state
->cli_share_src
,
2723 local_state
->cli_share_dst
,
2725 opt_acls
? True
: False
,
2726 opt_attrs
? True
: False
,
2727 opt_timestamps
? True
: False
,
2730 if (!NT_STATUS_IS_OK(nt_status
))
2731 printf("could not copy file %s: %s\n",
2732 filename
, nt_errstr(nt_status
));
2737 * sync files, can be called recursivly to list files
2738 * and then call copy_fn for each file
2740 * @param mem_ctx TALLOC_CTX
2741 * @param cli_share_src a connected share on the originating server
2742 * @param cli_share_dst a connected share on the destination server
2743 * @param mask the current search mask
2744 * @param cwd the current path
2746 * @return Boolean result
2748 BOOL
sync_files(TALLOC_CTX
*mem_ctx
,
2749 struct cli_state
*cli_share_src
,
2750 struct cli_state
*cli_share_dst
,
2751 pstring mask
, fstring cwd
)
2755 uint16 attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
2756 struct copy_clistate clistate
;
2758 clistate
.mem_ctx
= mem_ctx
;
2759 clistate
.cli_share_src
= cli_share_src
;
2760 clistate
.cli_share_dst
= cli_share_dst
;
2763 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
2765 if (cli_list(cli_share_src
, mask
, attribute
, copy_fn
, &clistate
) == -1) {
2766 d_printf("listing %s failed with error: %s\n",
2767 mask
, cli_errstr(cli_share_src
));
2776 * Sync all files inside a remote share to another share (over smb)
2778 * All parameters are provided by the run_rpc_command function, except for
2779 * argc, argv which are passes through.
2781 * @param domain_sid The domain sid acquired from the remote server
2782 * @param cli A cli_state connected to the server.
2783 * @param mem_ctx Talloc context, destoyed on completion of the function.
2784 * @param argc Standard main() style argc
2785 * @param argv Standard main() style argv. Initial components are already
2788 * @return Normal NTSTATUS return.
2791 rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
2792 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
2793 int argc
, const char **argv
)
2796 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2797 SRV_SHARE_INFO_CTR ctr_src
;
2799 uint32 preferred_len
= 0xffffffff, i
;
2801 struct cli_state
*cli_share_src
= NULL
;
2802 struct cli_state
*cli_share_dst
= NULL
;
2803 BOOL got_src_share
= False
;
2804 BOOL got_dst_share
= False
;
2808 dst
= strdup(opt_destination
?opt_destination
:"127.0.0.1");
2810 init_enum_hnd(&hnd
, 0);
2812 result
= cli_srvsvc_net_share_enum(
2813 cli
, mem_ctx
, level
, &ctr_src
, preferred_len
, &hnd
);
2815 if (!W_ERROR_IS_OK(result
))
2818 for (i
= 0; i
< ctr_src
.num_entries
; i
++) {
2820 fstring netname
= "", remark
= "", path
= "";
2822 rpcstr_pull_unistr2_fstring(
2823 netname
, &ctr_src
.share
.info2
[i
].info_2_str
.uni_netname
);
2824 rpcstr_pull_unistr2_fstring(
2825 remark
, &ctr_src
.share
.info2
[i
].info_2_str
.uni_remark
);
2826 rpcstr_pull_unistr2_fstring(
2827 path
, &ctr_src
.share
.info2
[i
].info_2_str
.uni_path
);
2829 /* since we do not have NetShareGetInfo implemented in samba3 we
2830 only can skip inside the enum-ctr_src */
2832 char *one_share
= talloc_strdup(mem_ctx
, argv
[0]);
2833 if (!strequal(netname
, one_share
))
2837 /* skip builtin and hidden shares
2838 In particular, one might not want to mirror whole discs :) */
2839 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$"))
2842 if (strequal(netname
, "print$") || netname
[1] == '$') {
2843 d_printf("skipping [%s]: builtin/hidden share\n", netname
);
2847 if (opt_exclude
&& in_list(netname
, (char *)opt_exclude
, False
)) {
2848 printf("excluding [%s]\n", netname
);
2852 /* only work with file-shares */
2853 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
2854 d_printf("skipping [%s]: not a file share.\n", netname
);
2859 return NT_STATUS_UNSUCCESSFUL
;
2861 printf("syncing [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
2863 opt_acls
? "including" : "without",
2864 opt_attrs
? "including" : "without",
2865 opt_timestamps
? "(preserving timestamps)" : "");
2868 /* open share source */
2869 nt_status
= connect_to_service(&cli_share_src
, &cli
->dest_ip
,
2870 cli
->desthost
, netname
, "A:");
2871 if (!NT_STATUS_IS_OK(nt_status
))
2874 got_src_share
= True
;
2877 /* open share destination */
2878 nt_status
= connect_to_service(&cli_share_dst
, NULL
,
2879 dst
, netname
, "A:");
2880 if (!NT_STATUS_IS_OK(nt_status
))
2883 got_dst_share
= True
;
2886 /* now call the filesync */
2887 pstrcpy(mask
, "\\*");
2889 if (!sync_files(mem_ctx
, cli_share_src
, cli_share_dst
, mask
, NULL
)) {
2890 d_printf("could not sync files for share: %s\n", netname
);
2891 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2897 nt_status
= NT_STATUS_OK
;
2902 cli_shutdown(cli_share_src
);
2905 cli_shutdown(cli_share_dst
);
2911 static int rpc_share_migrate_files(int argc
, const char **argv
)
2915 printf("no server to migrate\n");
2919 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
2920 rpc_share_migrate_files_internals
,
2925 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
2926 * from one server to another
2928 * @param argc Standard main() style argc
2929 * @param argv Standard main() style argv. Initial components are already
2932 * @return A shell status integer (0 for success)
2935 static int rpc_share_migrate_all(int argc
, const char **argv
)
2940 printf("no server to migrate\n");
2944 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
2948 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_security_internals
, argc
, argv
);
2952 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
2957 * 'net rpc share migrate' entrypoint.
2958 * @param argc Standard main() style argc
2959 * @param argv Standard main() style argv. Initial components are already
2962 static int rpc_share_migrate(int argc
, const char **argv
)
2965 struct functable func
[] = {
2966 {"all", rpc_share_migrate_all
},
2967 {"files", rpc_share_migrate_files
},
2968 {"help", rpc_share_usage
},
2969 /* {"security", rpc_share_migrate_security},*/
2970 {"shares", rpc_share_migrate_shares
},
2974 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
2983 static int num_server_aliases
;
2984 static struct full_alias
*server_aliases
;
2987 * Add an alias to the static list.
2989 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
2991 if (server_aliases
== NULL
)
2992 server_aliases
= malloc(100 * sizeof(struct full_alias
));
2994 server_aliases
[num_server_aliases
] = *alias
;
2995 num_server_aliases
+= 1;
2999 * For a specific domain on the server, fetch all the aliases
3000 * and their members. Add all of them to the server_aliases.
3003 rpc_fetch_domain_aliases(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
3004 POLICY_HND
*connect_pol
,
3005 const DOM_SID
*domain_sid
)
3007 uint32 start_idx
, max_entries
, num_entries
, i
;
3008 struct acct_info
*groups
;
3010 POLICY_HND domain_pol
;
3012 /* Get domain policy handle */
3014 result
= cli_samr_open_domain(cli
, mem_ctx
, connect_pol
,
3015 MAXIMUM_ALLOWED_ACCESS
,
3016 domain_sid
, &domain_pol
);
3017 if (!NT_STATUS_IS_OK(result
))
3024 result
= cli_samr_enum_als_groups(cli
, mem_ctx
, &domain_pol
,
3025 &start_idx
, max_entries
,
3026 &groups
, &num_entries
);
3028 for (i
= 0; i
< num_entries
; i
++) {
3030 POLICY_HND alias_pol
;
3031 struct full_alias alias
;
3035 result
= cli_samr_open_alias(cli
, mem_ctx
, &domain_pol
,
3036 MAXIMUM_ALLOWED_ACCESS
,
3039 if (!NT_STATUS_IS_OK(result
))
3042 result
= cli_samr_query_aliasmem(cli
, mem_ctx
,
3046 if (!NT_STATUS_IS_OK(result
))
3049 result
= cli_samr_close(cli
, mem_ctx
, &alias_pol
);
3050 if (!NT_STATUS_IS_OK(result
))
3053 alias
.members
= NULL
;
3055 if (alias
.num_members
> 0) {
3056 alias
.members
= malloc(alias
.num_members
*
3059 for (j
= 0; j
< alias
.num_members
; j
++)
3060 sid_copy(&alias
.members
[j
],
3064 sid_copy(&alias
.sid
, domain_sid
);
3065 sid_append_rid(&alias
.sid
, groups
[i
].rid
);
3067 push_alias(mem_ctx
, &alias
);
3069 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3071 result
= NT_STATUS_OK
;
3074 cli_samr_close(cli
, mem_ctx
, &domain_pol
);
3080 * Dump server_aliases as names for debugging purposes.
3083 rpc_aliaslist_dump(const DOM_SID
*domain_sid
, const char *domain_name
,
3084 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
3085 int argc
, const char **argv
)
3091 result
= cli_lsa_open_policy(cli
, mem_ctx
, True
,
3092 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3094 if (!NT_STATUS_IS_OK(result
))
3097 for (i
=0; i
<num_server_aliases
; i
++) {
3103 struct full_alias
*alias
= &server_aliases
[i
];
3105 result
= cli_lsa_lookup_sids(cli
, mem_ctx
, &lsa_pol
, 1,
3107 &domains
, &names
, &types
);
3108 if (!NT_STATUS_IS_OK(result
))
3111 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3113 if (alias
->num_members
== 0) {
3118 result
= cli_lsa_lookup_sids(cli
, mem_ctx
, &lsa_pol
,
3121 &domains
, &names
, &types
);
3123 if (!NT_STATUS_IS_OK(result
) &&
3124 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3127 for (j
=0; j
<alias
->num_members
; j
++)
3128 DEBUG(1, ("%s\\%s (%d); ",
3129 domains
[j
] ? domains
[j
] : "*unknown*",
3130 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3134 cli_lsa_close(cli
, mem_ctx
, &lsa_pol
);
3136 return NT_STATUS_OK
;
3140 * Fetch a list of all server aliases and their members into
3144 rpc_aliaslist_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
3145 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
3146 int argc
, const char **argv
)
3149 POLICY_HND connect_pol
;
3150 DOM_SID global_sid_Builtin
;
3152 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
3155 if (!NT_STATUS_IS_OK(result
))
3158 string_to_sid(&global_sid_Builtin
, "S-1-5-32");
3160 result
= rpc_fetch_domain_aliases(cli
, mem_ctx
, &connect_pol
,
3161 &global_sid_Builtin
);
3163 if (!NT_STATUS_IS_OK(result
))
3166 result
= rpc_fetch_domain_aliases(cli
, mem_ctx
, &connect_pol
,
3169 cli_samr_close(cli
, mem_ctx
, &connect_pol
);
3174 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
3176 DOM_SID global_sid_World
;
3177 DOM_SID global_sid_Network
;
3178 DOM_SID global_sid_Authenticated_Users
;
3180 string_to_sid(&global_sid_World
, "S-1-1-0");
3181 string_to_sid(&global_sid_Network
, "S-1-5-2");
3182 string_to_sid(&global_sid_Authenticated_Users
, "S-1-5-11");
3184 token
->num_sids
= 4;
3186 token
->user_sids
= malloc(4 * sizeof(DOM_SID
));
3188 token
->user_sids
[0] = *user_sid
;
3189 sid_copy(&token
->user_sids
[1], &global_sid_World
);
3190 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
3191 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
3194 static void free_user_token(NT_USER_TOKEN
*token
)
3196 SAFE_FREE(token
->user_sids
);
3199 static BOOL
is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3203 for (i
=0; i
<token
->num_sids
; i
++) {
3204 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
3210 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3212 if (is_sid_in_token(token
, sid
))
3215 token
->user_sids
= Realloc(token
->user_sids
,
3216 (token
->num_sids
+1) * sizeof(DOM_SID
));
3218 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
3220 token
->num_sids
+= 1;
3225 NT_USER_TOKEN token
;
3228 static void dump_user_token(struct user_token
*token
)
3232 d_printf("%s\n", token
->name
);
3234 for (i
=0; i
<token
->token
.num_sids
; i
++) {
3235 d_printf(" %s\n", sid_string_static(&token
->token
.user_sids
[i
]));
3239 static BOOL
is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
3243 for (i
=0; i
<alias
->num_members
; i
++) {
3244 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
3251 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
3255 for (i
=0; i
<num_server_aliases
; i
++) {
3256 if (is_alias_member(&sid
, &server_aliases
[i
]))
3257 add_sid_to_token(token
, &server_aliases
[i
].sid
);
3262 * We got a user token with all the SIDs we can know about without asking the
3263 * server directly. These are the user and domain group sids. All of these can
3264 * be members of aliases. So scan the list of aliases for each of the SIDs and
3265 * add them to the token.
3268 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
3270 int num_global_sids
= token
->num_sids
;
3273 for (i
=0; i
<num_global_sids
; i
++) {
3274 collect_sid_memberships(token
, token
->user_sids
[i
]);
3278 static BOOL
get_user_sids(const char *domain
, const char *user
,
3279 NT_USER_TOKEN
*token
)
3281 struct winbindd_request request
;
3282 struct winbindd_response response
;
3290 fstr_sprintf(full_name
, "%s%c%s",
3291 domain
, *lp_winbind_separator(), user
);
3293 /* First let's find out the user sid */
3295 ZERO_STRUCT(request
);
3296 ZERO_STRUCT(response
);
3298 fstrcpy(request
.data
.name
.dom_name
, domain
);
3299 fstrcpy(request
.data
.name
.name
, user
);
3301 result
= winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
);
3303 if (result
!= NSS_STATUS_SUCCESS
) {
3304 DEBUG(1, ("winbind could not find %s\n", full_name
));
3308 if (response
.data
.sid
.type
!= SID_NAME_USER
) {
3309 DEBUG(1, ("%s is not a user\n", full_name
));
3313 string_to_sid(&user_sid
, response
.data
.sid
.sid
);
3315 init_user_token(token
, &user_sid
);
3317 /* And now the groups winbind knows about */
3319 ZERO_STRUCT(response
);
3321 fstrcpy(request
.data
.username
, full_name
);
3323 result
= winbindd_request(WINBINDD_GETGROUPS
, &request
, &response
);
3325 if (result
!= NSS_STATUS_SUCCESS
) {
3326 DEBUG(1, ("winbind could not get groups of %s\n", full_name
));
3330 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
3331 gid_t gid
= ((gid_t
*)response
.extra_data
)[i
];
3334 struct winbindd_request sidrequest
;
3335 struct winbindd_response sidresponse
;
3337 ZERO_STRUCT(sidrequest
);
3338 ZERO_STRUCT(sidresponse
);
3340 sidrequest
.data
.gid
= gid
;
3342 result
= winbindd_request(WINBINDD_GID_TO_SID
,
3343 &sidrequest
, &sidresponse
);
3345 if (result
!= NSS_STATUS_SUCCESS
) {
3346 DEBUG(1, ("winbind could not find SID of gid %d\n",
3351 DEBUG(3, (" %s\n", sidresponse
.data
.sid
.sid
));
3353 string_to_sid(&sid
, sidresponse
.data
.sid
.sid
);
3354 add_sid_to_token(token
, &sid
);
3357 SAFE_FREE(response
.extra_data
);
3363 * Get a list of all user tokens we want to look at
3365 static BOOL
get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
3367 struct winbindd_request request
;
3368 struct winbindd_response response
;
3369 const char *extra_data
;
3372 struct user_token
*result
;
3374 /* Send request to winbind daemon */
3376 ZERO_STRUCT(request
);
3377 ZERO_STRUCT(response
);
3379 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
3383 /* Look through extra data */
3385 if (!response
.extra_data
)
3388 extra_data
= (const char *)response
.extra_data
;
3391 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
3395 result
= malloc(*num_tokens
* sizeof(struct user_token
));
3397 if (result
== NULL
) {
3398 DEBUG(1, ("Could not malloc sid array\n"));
3402 extra_data
= (const char *)response
.extra_data
;
3405 while(next_token(&extra_data
, name
, ",", sizeof(fstring
))) {
3407 fstring domain
, user
;
3410 fstrcpy(result
[i
].name
, name
);
3412 p
= strchr(name
, *lp_winbind_separator());
3414 DEBUG(3, ("%s\n", name
));
3421 fstrcpy(domain
, name
);
3425 get_user_sids(domain
, user
, &(result
[i
].token
));
3429 SAFE_FREE(response
.extra_data
);
3431 *user_tokens
= result
;
3436 static BOOL
get_user_tokens_from_file(FILE *f
,
3438 struct user_token
**tokens
)
3440 struct user_token
*token
= NULL
;
3445 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
3449 if (line
[strlen(line
)-1] == '\n')
3450 line
[strlen(line
)-1] = '\0';
3452 if (line
[0] == ' ') {
3456 string_to_sid(&sid
, &line
[1]);
3458 if (token
== NULL
) {
3459 DEBUG(0, ("File does not begin with username"));
3463 add_sid_to_token(&token
->token
, &sid
);
3467 /* And a new user... */
3470 *tokens
= Realloc(*tokens
,
3472 sizeof(struct user_token
));
3473 if (*tokens
== NULL
) {
3474 DEBUG(0, ("Could not realloc tokens\n"));
3478 token
= &((*tokens
)[*num_tokens
-1]);
3480 fstrcpy(token
->name
, line
);
3481 token
->token
.num_sids
= 0;
3482 token
->token
.user_sids
= NULL
;
3491 * Show the list of all users that have access to a share
3494 static void show_userlist(struct cli_state
*cli
,
3495 TALLOC_CTX
*mem_ctx
, const char *netname
,
3496 int num_tokens
, struct user_token
*tokens
)
3499 SEC_DESC
*share_sd
= NULL
;
3500 SEC_DESC
*root_sd
= NULL
;
3502 SRV_SHARE_INFO info
;
3506 result
= cli_srvsvc_net_share_get_info(cli
, mem_ctx
, netname
,
3509 if (!W_ERROR_IS_OK(result
)) {
3510 DEBUG(1, ("Coult not query secdesc for share %s\n",
3515 share_sd
= info
.share
.info502
.info_502_str
.sd
;
3516 if (share_sd
== NULL
) {
3517 DEBUG(1, ("Got no secdesc for share %s\n",
3523 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3527 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
3530 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
3533 for (i
=0; i
<num_tokens
; i
++) {
3537 if (share_sd
!= NULL
) {
3538 if (!se_access_check(share_sd
, &tokens
[i
].token
,
3539 1, &acc_granted
, &status
)) {
3540 DEBUG(1, ("Could not check share_sd for "
3546 if (!NT_STATUS_IS_OK(status
))
3550 if (root_sd
== NULL
) {
3551 d_printf(" %s\n", tokens
[i
].name
);
3555 if (!se_access_check(root_sd
, &tokens
[i
].token
,
3556 1, &acc_granted
, &status
)) {
3557 DEBUG(1, ("Could not check root_sd for user %s\n",
3562 if (!NT_STATUS_IS_OK(status
))
3565 d_printf(" %s\n", tokens
[i
].name
);
3569 cli_close(cli
, fnum
);
3581 static void collect_share(const char *name
, uint32 m
,
3582 const char *comment
, void *state
)
3584 struct share_list
*share_list
= (struct share_list
*)state
;
3586 if (m
!= STYPE_DISKTREE
)
3589 share_list
->num_shares
+= 1;
3590 share_list
->shares
= Realloc(share_list
->shares
,
3591 share_list
->num_shares
* sizeof(char *));
3592 share_list
->shares
[share_list
->num_shares
-1] = strdup(name
);
3595 static void rpc_share_userlist_usage(void)
3601 * List shares on a remote RPC server, including the security descriptors
3603 * All parameters are provided by the run_rpc_command function, except for
3604 * argc, argv which are passes through.
3606 * @param domain_sid The domain sid acquired from the remote server
3607 * @param cli A cli_state connected to the server.
3608 * @param mem_ctx Talloc context, destoyed on completion of the function.
3609 * @param argc Standard main() style argc
3610 * @param argv Standard main() style argv. Initial components are already
3613 * @return Normal NTSTATUS return.
3617 rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
3618 const char *domain_name
,
3619 struct cli_state
*cli
,
3620 TALLOC_CTX
*mem_ctx
,
3621 int argc
, const char **argv
)
3629 struct user_token
*tokens
= NULL
;
3632 struct share_list share_list
;
3635 rpc_share_userlist_usage();
3636 return NT_STATUS_UNSUCCESSFUL
;
3642 f
= fopen(argv
[0], "r");
3646 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
3647 return NT_STATUS_UNSUCCESSFUL
;
3650 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
3656 DEBUG(0, ("Could not read users from file\n"));
3657 return NT_STATUS_UNSUCCESSFUL
;
3660 for (i
=0; i
<num_tokens
; i
++)
3661 collect_alias_memberships(&tokens
[i
].token
);
3663 init_enum_hnd(&hnd
, 0);
3665 share_list
.num_shares
= 0;
3666 share_list
.shares
= NULL
;
3668 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
3671 DEBUG(0, ("Error returning browse list: %s\n",
3676 for (i
= 0; i
< share_list
.num_shares
; i
++) {
3677 char *netname
= share_list
.shares
[i
];
3679 if (netname
[strlen(netname
)-1] == '$')
3682 d_printf("%s\n", netname
);
3684 show_userlist(cli
, mem_ctx
, netname
,
3685 num_tokens
, tokens
);
3688 for (i
=0; i
<num_tokens
; i
++) {
3689 free_user_token(&tokens
[i
].token
);
3692 SAFE_FREE(share_list
.shares
);
3694 return NT_STATUS_OK
;
3698 rpc_share_allowedusers(int argc
, const char **argv
)
3702 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
3703 rpc_aliaslist_internals
,
3708 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
3714 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3715 rpc_share_allowedusers_internals
,
3719 int net_usersidlist(int argc
, const char **argv
)
3722 struct user_token
*tokens
= NULL
;
3726 net_usersidlist_usage(argc
, argv
);
3730 if (!get_user_tokens(&num_tokens
, &tokens
)) {
3731 DEBUG(0, ("Could not get the user/sid list\n"));
3735 for (i
=0; i
<num_tokens
; i
++) {
3736 dump_user_token(&tokens
[i
]);
3737 free_user_token(&tokens
[i
].token
);
3744 int net_usersidlist_usage(int argc
, const char **argv
)
3746 d_printf("net usersidlist\n"
3747 "\tprints out a list of all users the running winbind knows\n"
3748 "\tabout, together with all their SIDs. This is used as\n"
3749 "\tinput to the 'net rpc share allowedusers' command.\n\n");
3751 net_common_flags_usage(argc
, argv
);
3756 * 'net rpc share' entrypoint.
3757 * @param argc Standard main() style argc
3758 * @param argv Standard main() style argv. Initial components are already
3762 int net_rpc_share(int argc
, const char **argv
)
3764 struct functable func
[] = {
3765 {"add", rpc_share_add
},
3766 {"delete", rpc_share_delete
},
3767 {"allowedusers", rpc_share_allowedusers
},
3768 {"migrate", rpc_share_migrate
},
3773 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3774 rpc_share_list_internals
,
3777 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
3780 /****************************************************************************/
3782 static int rpc_file_usage(int argc
, const char **argv
)
3784 return net_help_file(argc
, argv
);
3788 * Close a file on a remote RPC server
3790 * All parameters are provided by the run_rpc_command function, except for
3791 * argc, argv which are passes through.
3793 * @param domain_sid The domain sid acquired from the remote server
3794 * @param cli A cli_state connected to the server.
3795 * @param mem_ctx Talloc context, destoyed on completion of the function.
3796 * @param argc Standard main() style argc
3797 * @param argv Standard main() style argv. Initial components are already
3800 * @return Normal NTSTATUS return.
3803 rpc_file_close_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
3804 struct cli_state
*cli
,
3805 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
3808 result
= cli_srvsvc_net_file_close(cli
, mem_ctx
, atoi(argv
[0]));
3809 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3813 * Close a file on a remote RPC server
3815 * @param argc Standard main() style argc
3816 * @param argv Standard main() style argv. Initial components are already
3819 * @return A shell status integer (0 for success)
3821 static int rpc_file_close(int argc
, const char **argv
)
3824 DEBUG(1, ("No fileid given on close\n"));
3825 return(rpc_file_usage(argc
, argv
));
3828 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3829 rpc_file_close_internals
,
3834 * Formatted print of open file info
3836 * @param info3 FILE_INFO_3 contents
3837 * @param str3 strings for FILE_INFO_3
3840 static void display_file_info_3(FILE_INFO_3
*info3
, FILE_INFO_3_STR
*str3
)
3842 fstring user
= "", path
= "";
3844 rpcstr_pull_unistr2_fstring(user
, &str3
->uni_user_name
);
3845 rpcstr_pull_unistr2_fstring(path
, &str3
->uni_path_name
);
3847 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
3848 info3
->id
, user
, info3
->perms
, info3
->num_locks
, path
);
3852 * List open files on a remote RPC server
3854 * All parameters are provided by the run_rpc_command function, except for
3855 * argc, argv which are passes through.
3857 * @param domain_sid The domain sid acquired from the remote server
3858 * @param cli A cli_state connected to the server.
3859 * @param mem_ctx Talloc context, destoyed on completion of the function.
3860 * @param argc Standard main() style argc
3861 * @param argv Standard main() style argv. Initial components are already
3864 * @return Normal NTSTATUS return.
3868 rpc_file_list_internals(const DOM_SID
*domain_sid
, const char *domain_name
,
3869 struct cli_state
*cli
,
3870 TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
3872 SRV_FILE_INFO_CTR ctr
;
3875 uint32 preferred_len
= 0xffffffff, i
;
3876 const char *username
=NULL
;
3878 init_enum_hnd(&hnd
, 0);
3880 /* if argc > 0, must be user command */
3882 username
= smb_xstrdup(argv
[0]);
3884 result
= cli_srvsvc_net_file_enum(
3885 cli
, mem_ctx
, 3, username
, &ctr
, preferred_len
, &hnd
);
3887 if (!W_ERROR_IS_OK(result
))
3890 /* Display results */
3893 "\nEnumerating open files on remote server:\n\n"\
3894 "\nFileId Opened by Perms Locks Path"\
3895 "\n------ --------- ----- ----- ---- \n");
3896 for (i
= 0; i
< ctr
.num_entries
; i
++)
3897 display_file_info_3(&ctr
.file
.info3
[i
].info_3
,
3898 &ctr
.file
.info3
[i
].info_3_str
);
3900 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3905 * List files for a user on a remote RPC server
3907 * @param argc Standard main() style argc
3908 * @param argv Standard main() style argv. Initial components are already
3911 * @return A shell status integer (0 for success)
3913 static int rpc_file_user(int argc
, const char **argv
)
3916 DEBUG(1, ("No username given\n"));
3917 return(rpc_file_usage(argc
, argv
));
3920 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3921 rpc_file_list_internals
,
3927 * 'net rpc file' entrypoint.
3928 * @param argc Standard main() style argc
3929 * @param argv Standard main() style argv. Initial components are already
3933 int net_rpc_file(int argc
, const char **argv
)
3935 struct functable func
[] = {
3936 {"close", rpc_file_close
},
3937 {"user", rpc_file_user
},
3939 {"info", rpc_file_info
},
3945 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3946 rpc_file_list_internals
,
3949 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
3952 /****************************************************************************/
3957 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
3959 * All parameters are provided by the run_rpc_command function, except for
3960 * argc, argv which are passed through.
3962 * @param domain_sid The domain sid aquired from the remote server
3963 * @param cli A cli_state connected to the server.
3964 * @param mem_ctx Talloc context, destoyed on compleation of the function.
3965 * @param argc Standard main() style argc
3966 * @param argv Standard main() style argv. Initial components are already
3969 * @return Normal NTSTATUS return.
3972 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
3973 const char *domain_name
,
3974 struct cli_state
*cli
,
3975 TALLOC_CTX
*mem_ctx
,
3976 int argc
, const char **argv
)
3978 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
3980 result
= cli_shutdown_abort(cli
, mem_ctx
);
3982 if (NT_STATUS_IS_OK(result
))
3983 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
3985 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
3992 * ABORT the shutdown of a remote RPC Server, over winreg pipe
3994 * All parameters are provided by the run_rpc_command function, except for
3995 * argc, argv which are passed through.
3997 * @param domain_sid The domain sid aquired from the remote server
3998 * @param cli A cli_state connected to the server.
3999 * @param mem_ctx Talloc context, destoyed on compleation of the function.
4000 * @param argc Standard main() style argc
4001 * @param argv Standard main() style argv. Initial components are already
4004 * @return Normal NTSTATUS return.
4007 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
4008 const char *domain_name
,
4009 struct cli_state
*cli
,
4010 TALLOC_CTX
*mem_ctx
,
4011 int argc
, const char **argv
)
4013 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4015 result
= cli_reg_abort_shutdown(cli
, mem_ctx
);
4017 if (NT_STATUS_IS_OK(result
))
4018 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4020 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
4026 * ABORT the Shut down of a remote RPC server
4028 * @param argc Standard main() style argc
4029 * @param argv Standard main() style argv. Initial components are already
4032 * @return A shell status integer (0 for success)
4035 static int rpc_shutdown_abort(int argc
, const char **argv
)
4037 int rc
= run_rpc_command(NULL
, PI_SHUTDOWN
, 0,
4038 rpc_shutdown_abort_internals
,
4044 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
4046 return run_rpc_command(NULL
, PI_WINREG
, 0,
4047 rpc_reg_shutdown_abort_internals
,
4052 * Shut down a remote RPC Server
4054 * All parameters are provided by the run_rpc_command function, except for
4055 * argc, argv which are passes through.
4057 * @param domain_sid The domain sid aquired from the remote server
4058 * @param cli A cli_state connected to the server.
4059 * @param mem_ctx Talloc context, destoyed on compleation of the function.
4060 * @param argc Standard main() style argc
4061 * @param argc Standard main() style argv. Initial components are already
4064 * @return Normal NTSTATUS return.
4067 static NTSTATUS
rpc_shutdown_internals(const DOM_SID
*domain_sid
,
4068 const char *domain_name
,
4069 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
4070 int argc
, const char **argv
)
4072 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4073 const char *msg
= "This machine will be shutdown shortly";
4074 uint32 timeout
= 20;
4079 struct poptOption long_options
[] = {
4080 {"message", 'm', POPT_ARG_STRING
, &msg
},
4081 {"timeout", 't', POPT_ARG_INT
, &timeout
},
4082 {"reboot", 'r', POPT_ARG_NONE
, &reboot
},
4083 {"force", 'f', POPT_ARG_NONE
, &force
},
4087 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
4088 POPT_CONTEXT_KEEP_FIRST
);
4090 rc
= poptGetNextOpt(pc
);
4093 /* an error occurred during option processing */
4094 DEBUG(0, ("%s: %s\n",
4095 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
4097 return NT_STATUS_INVALID_PARAMETER
;
4104 timeout
= opt_timeout
;
4107 /* create an entry */
4108 result
= cli_reg_shutdown(cli
, mem_ctx
, msg
, timeout
, opt_reboot
, opt_force
);
4110 if (NT_STATUS_IS_OK(result
))
4111 DEBUG(5,("Shutdown of remote machine succeeded\n"));
4113 DEBUG(0,("Shutdown of remote machine failed!\n"));
4119 * Shut down a remote RPC server
4121 * @param argc Standard main() style argc
4122 * @param argc Standard main() style argv. Initial components are already
4125 * @return A shell status integer (0 for success)
4128 static int rpc_shutdown(int argc
, const char **argv
)
4130 return run_rpc_command(NULL
, PI_WINREG
, 0, rpc_shutdown_internals
,
4134 /***************************************************************************
4135 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
4137 ***************************************************************************/
4140 * Add interdomain trust account to the RPC server.
4141 * All parameters (except for argc and argv) are passed by run_rpc_command
4144 * @param domain_sid The domain sid acquired from the server
4145 * @param cli A cli_state connected to the server.
4146 * @param mem_ctx Talloc context, destoyed on completion of the function.
4147 * @param argc Standard main() style argc
4148 * @param argc Standard main() style argv. Initial components are already
4151 * @return normal NTSTATUS return code
4154 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
4155 const char *domain_name
,
4156 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
4157 int argc
, const char **argv
) {
4159 POLICY_HND connect_pol
, domain_pol
, user_pol
;
4160 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4163 uint32 unknown
, user_rid
;
4166 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
4167 return NT_STATUS_INVALID_PARAMETER
;
4171 * Make valid trusting domain account (ie. uppercased and with '$' appended)
4174 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
4175 return NT_STATUS_NO_MEMORY
;
4178 strupper_m(acct_name
);
4180 /* Get samr policy handle */
4181 result
= cli_samr_connect(cli
, mem_ctx
, MAXIMUM_ALLOWED_ACCESS
,
4183 if (!NT_STATUS_IS_OK(result
)) {
4187 /* Get domain policy handle */
4188 result
= cli_samr_open_domain(cli
, mem_ctx
, &connect_pol
,
4189 MAXIMUM_ALLOWED_ACCESS
,
4190 domain_sid
, &domain_pol
);
4191 if (!NT_STATUS_IS_OK(result
)) {
4195 /* Create trusting domain's account */
4196 acb_info
= ACB_DOMTRUST
;
4197 unknown
= 0xe00500b0; /* No idea what this is - a permission mask?
4198 mimir: yes, most probably it is */
4200 result
= cli_samr_create_dom_user(cli
, mem_ctx
, &domain_pol
,
4201 acct_name
, acb_info
, unknown
,
4202 &user_pol
, &user_rid
);
4203 if (!NT_STATUS_IS_OK(result
)) {
4208 SAM_USERINFO_CTR ctr
;
4209 SAM_USER_INFO_24 p24
;
4212 encode_pw_buffer((char *)pwbuf
, argv
[1], STR_UNICODE
);
4217 init_sam_user_info24(&p24
, (char *)pwbuf
, 24);
4219 ctr
.switch_value
= 24;
4220 ctr
.info
.id24
= &p24
;
4222 result
= cli_samr_set_userinfo(cli
, mem_ctx
, &user_pol
, 24,
4223 &cli
->user_session_key
, &ctr
);
4225 if (!NT_STATUS_IS_OK(result
)) {
4226 DEBUG(0,("Could not set trust account password: %s\n",
4227 nt_errstr(result
)));
4233 SAFE_FREE(acct_name
);
4238 * Create interdomain trust account for a remote domain.
4240 * @param argc standard argc
4241 * @param argv standard argv without initial components
4243 * @return Integer status (0 means success)
4246 static int rpc_trustdom_add(int argc
, const char **argv
)
4249 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
4252 d_printf("Usage: net rpc trustdom add <domain>\n");
4259 * Delete interdomain trust account for a remote domain.
4261 * @param argc standard argc
4262 * @param argv standard argv without initial components
4264 * @return Integer status (0 means success)
4267 static int rpc_trustdom_del(int argc
, const char **argv
)
4269 d_printf("Sorry, not yet implemented.\n");
4270 d_printf("Use 'smbpasswd -x -i' instead.\n");
4276 * Establish trust relationship to a trusting domain.
4277 * Interdomain account must already be created on remote PDC.
4279 * @param argc standard argc
4280 * @param argv standard argv without initial components
4282 * @return Integer status (0 means success)
4285 static int rpc_trustdom_establish(int argc
, const char **argv
)
4287 struct cli_state
*cli
;
4288 struct in_addr server_ip
;
4289 POLICY_HND connect_hnd
;
4290 TALLOC_CTX
*mem_ctx
;
4292 DOM_SID
*domain_sid
;
4293 WKS_INFO_100 wks_info
;
4296 char* domain_name_pol
;
4301 * Connect to \\server\ipc$ as 'our domain' account with password
4305 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
4309 domain_name
= smb_xstrdup(argv
[0]);
4310 strupper_m(domain_name
);
4312 /* account name used at first is our domain's name with '$' */
4313 asprintf(&acct_name
, "%s$", lp_workgroup());
4314 strupper_m(acct_name
);
4317 * opt_workgroup will be used by connection functions further,
4318 * hence it should be set to remote domain name instead of ours
4320 if (opt_workgroup
) {
4321 opt_workgroup
= smb_xstrdup(domain_name
);
4324 opt_user_name
= acct_name
;
4326 /* find the domain controller */
4327 if (!net_find_pdc(&server_ip
, pdc_name
, domain_name
)) {
4328 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
4332 /* connect to ipc$ as username/password */
4333 nt_status
= connect_to_ipc(&cli
, &server_ip
, pdc_name
);
4334 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
4336 /* Is it trusting domain account for sure ? */
4337 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
4338 nt_errstr(nt_status
)));
4343 * Connect to \\server\ipc$ again (this time anonymously)
4346 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ip
, (char*)pdc_name
);
4348 if (NT_STATUS_IS_ERR(nt_status
)) {
4349 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
4350 domain_name
, nt_errstr(nt_status
)));
4354 * Use NetServerEnum2 to make sure we're talking to a proper server
4357 if (!cli_get_pdc_name(cli
, domain_name
, (char*)pdc_name
)) {
4358 DEBUG(0, ("NetServerEnum2 error: Couldn't find primary domain controller\
4359 for domain %s\n", domain_name
));
4363 * Call WksQueryInfo to check remote server's capabilities
4364 * note: It is now used only to get unicode domain name
4367 if (!cli_nt_session_open(cli
, PI_WKSSVC
)) {
4368 DEBUG(0, ("Couldn't not initialise wkssvc pipe\n"));
4372 if (!(mem_ctx
= talloc_init("establishing trust relationship to domain %s",
4374 DEBUG(0, ("talloc_init() failed\n"));
4379 nt_status
= cli_wks_query_info(cli
, mem_ctx
, &wks_info
);
4381 if (NT_STATUS_IS_ERR(nt_status
)) {
4382 DEBUG(0, ("WksQueryInfo call failed.\n"));
4386 if (cli
->nt_pipe_fnum
)
4387 cli_nt_session_close(cli
);
4391 * Call LsaOpenPolicy and LsaQueryInfo
4394 if (!(mem_ctx
= talloc_init("rpc_trustdom_establish"))) {
4395 DEBUG(0, ("talloc_init() failed\n"));
4400 if (!cli_nt_session_open(cli
, PI_LSARPC
)) {
4401 DEBUG(0, ("Could not initialise lsa pipe\n"));
4406 nt_status
= cli_lsa_open_policy2(cli
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
4408 if (NT_STATUS_IS_ERR(nt_status
)) {
4409 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
4410 nt_errstr(nt_status
)));
4414 /* Querying info level 5 */
4416 nt_status
= cli_lsa_query_info_policy(cli
, mem_ctx
, &connect_hnd
,
4417 5 /* info level */, &domain_name_pol
,
4419 if (NT_STATUS_IS_ERR(nt_status
)) {
4420 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
4421 nt_errstr(nt_status
)));
4428 /* There should be actually query info level 3 (following nt serv behaviour),
4429 but I still don't know if it's _really_ necessary */
4432 * Store the password in secrets db
4435 if (!secrets_store_trusted_domain_password(domain_name
, wks_info
.uni_lan_grp
.buffer
,
4436 wks_info
.uni_lan_grp
.uni_str_len
, opt_password
,
4438 DEBUG(0, ("Storing password for trusted domain failed.\n"));
4443 * Close the pipes and clean up
4446 nt_status
= cli_lsa_close(cli
, mem_ctx
, &connect_hnd
);
4447 if (NT_STATUS_IS_ERR(nt_status
)) {
4448 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
4449 nt_errstr(nt_status
)));
4453 if (cli
->nt_pipe_fnum
)
4454 cli_nt_session_close(cli
);
4456 talloc_destroy(mem_ctx
);
4458 d_printf("Trust to domain %s established\n", domain_name
);
4463 * Revoke trust relationship to the remote domain
4465 * @param argc standard argc
4466 * @param argv standard argv without initial components
4468 * @return Integer status (0 means success)
4471 static int rpc_trustdom_revoke(int argc
, const char **argv
)
4475 if (argc
< 1) return -1;
4477 /* generate upper cased domain name */
4478 domain_name
= smb_xstrdup(argv
[0]);
4479 strupper_m(domain_name
);
4481 /* delete password of the trust */
4482 if (!trusted_domain_password_delete(domain_name
)) {
4483 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
4492 * Usage for 'net rpc trustdom' command
4494 * @param argc standard argc
4495 * @param argv standard argv without inital components
4497 * @return Integer status returned to shell
4500 static int rpc_trustdom_usage(int argc
, const char **argv
)
4502 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
4503 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
4504 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
4505 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
4506 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
4511 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
4512 const char *domain_name
,
4513 struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
4514 int argc
, const char **argv
)
4517 sid_to_string(str_sid
, domain_sid
);
4518 d_printf("%s\n", str_sid
);
4519 return NT_STATUS_OK
;
4523 static int rpc_trustdom_list(int argc
, const char **argv
)
4525 /* common variables */
4526 TALLOC_CTX
* mem_ctx
;
4527 struct cli_state
*cli
, *remote_cli
;
4529 const char *domain_name
= NULL
;
4530 DOM_SID
*queried_dom_sid
;
4531 fstring ascii_sid
, padding
;
4532 int ascii_dom_name_len
;
4533 POLICY_HND connect_hnd
;
4535 /* trusted domains listing variables */
4536 unsigned int num_domains
, enum_ctx
= 0;
4537 int i
, pad_len
, col_len
= 20;
4538 DOM_SID
*domain_sids
;
4539 char **trusted_dom_names
;
4543 /* trusting domains listing variables */
4544 POLICY_HND domain_hnd
;
4545 char **trusting_dom_names
;
4546 uint32
*trusting_dom_rids
;
4549 * Listing trusted domains (stored in secrets.tdb, if local)
4552 mem_ctx
= talloc_init("trust relationships listing");
4555 * set domain and pdc name to local samba server (default)
4556 * or to remote one given in command line
4559 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
4560 domain_name
= opt_workgroup
;
4561 opt_target_workgroup
= opt_workgroup
;
4563 fstrcpy(pdc_name
, global_myname());
4564 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
4565 opt_target_workgroup
= domain_name
;
4568 /* open \PIPE\lsarpc and open policy handle */
4569 if (!(cli
= net_make_ipc_connection(NET_FLAGS_PDC
))) {
4570 DEBUG(0, ("Couldn't connect to domain controller\n"));
4574 if (!cli_nt_session_open(cli
, PI_LSARPC
)) {
4575 DEBUG(0, ("Could not initialise lsa pipe\n"));
4579 nt_status
= cli_lsa_open_policy2(cli
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
4581 if (NT_STATUS_IS_ERR(nt_status
)) {
4582 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
4583 nt_errstr(nt_status
)));
4587 /* query info level 5 to obtain sid of a domain being queried */
4588 nt_status
= cli_lsa_query_info_policy(
4589 cli
, mem_ctx
, &connect_hnd
, 5 /* info level */,
4590 &dummy
, &queried_dom_sid
);
4592 if (NT_STATUS_IS_ERR(nt_status
)) {
4593 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
4594 nt_errstr(nt_status
)));
4599 * Keep calling LsaEnumTrustdom over opened pipe until
4600 * the end of enumeration is reached
4603 d_printf("Trusted domains list:\n\n");
4606 nt_status
= cli_lsa_enum_trust_dom(cli
, mem_ctx
, &connect_hnd
, &enum_ctx
,
4608 &trusted_dom_names
, &domain_sids
);
4610 if (NT_STATUS_IS_ERR(nt_status
)) {
4611 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
4612 nt_errstr(nt_status
)));
4616 for (i
= 0; i
< num_domains
; i
++) {
4617 /* convert sid into ascii string */
4618 sid_to_string(ascii_sid
, &(domain_sids
[i
]));
4620 /* calculate padding space for d_printf to look nicer */
4621 pad_len
= col_len
- strlen(trusted_dom_names
[i
]);
4622 padding
[pad_len
] = 0;
4623 do padding
[--pad_len
] = ' '; while (pad_len
);
4625 d_printf("%s%s%s\n", trusted_dom_names
[i
], padding
, ascii_sid
);
4629 * in case of no trusted domains say something rather
4630 * than just display blank line
4632 if (!num_domains
) d_printf("none\n");
4634 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
4636 /* close this connection before doing next one */
4637 nt_status
= cli_lsa_close(cli
, mem_ctx
, &connect_hnd
);
4638 if (NT_STATUS_IS_ERR(nt_status
)) {
4639 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
4640 nt_errstr(nt_status
)));
4644 cli_nt_session_close(cli
);
4647 * Listing trusting domains (stored in passdb backend, if local)
4650 d_printf("\nTrusting domains list:\n\n");
4653 * Open \PIPE\samr and get needed policy handles
4655 if (!cli_nt_session_open(cli
, PI_SAMR
)) {
4656 DEBUG(0, ("Could not initialise samr pipe\n"));
4661 nt_status
= cli_samr_connect(cli
, mem_ctx
, SA_RIGHT_SAM_OPEN_DOMAIN
,
4663 if (!NT_STATUS_IS_OK(nt_status
)) {
4664 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
4665 nt_errstr(nt_status
)));
4669 /* SamrOpenDomain - we have to open domain policy handle in order to be
4670 able to enumerate accounts*/
4671 nt_status
= cli_samr_open_domain(cli
, mem_ctx
, &connect_hnd
,
4672 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
4673 queried_dom_sid
, &domain_hnd
);
4674 if (!NT_STATUS_IS_OK(nt_status
)) {
4675 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
4676 nt_errstr(nt_status
)));
4681 * perform actual enumeration
4684 enum_ctx
= 0; /* reset enumeration context from last enumeration */
4687 nt_status
= cli_samr_enum_dom_users(cli
, mem_ctx
, &domain_hnd
,
4688 &enum_ctx
, ACB_DOMTRUST
, 0xffff,
4689 &trusting_dom_names
, &trusting_dom_rids
,
4691 if (NT_STATUS_IS_ERR(nt_status
)) {
4692 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
4693 nt_errstr(nt_status
)));
4697 for (i
= 0; i
< num_domains
; i
++) {
4700 * get each single domain's sid (do we _really_ need this ?):
4701 * 1) connect to domain's pdc
4702 * 2) query the pdc for domain's sid
4705 /* get rid of '$' tail */
4706 ascii_dom_name_len
= strlen(trusting_dom_names
[i
]);
4707 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
4708 trusting_dom_names
[i
][ascii_dom_name_len
- 1] = '\0';
4710 /* calculate padding space for d_printf to look nicer */
4711 pad_len
= col_len
- strlen(trusting_dom_names
[i
]);
4712 padding
[pad_len
] = 0;
4713 do padding
[--pad_len
] = ' '; while (pad_len
);
4715 /* set opt_* variables to remote domain */
4716 strupper_m(trusting_dom_names
[i
]);
4717 opt_workgroup
= talloc_strdup(mem_ctx
, trusting_dom_names
[i
]);
4718 opt_target_workgroup
= opt_workgroup
;
4720 d_printf("%s%s", trusting_dom_names
[i
], padding
);
4722 /* connect to remote domain controller */
4723 remote_cli
= net_make_ipc_connection(NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
);
4725 /* query for domain's sid */
4726 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
4727 d_printf("couldn't get domain's sid\n");
4729 cli_shutdown(remote_cli
);
4732 d_printf("domain controller is not responding\n");
4736 if (!num_domains
) d_printf("none\n");
4738 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
4740 /* close opened samr and domain policy handles */
4741 nt_status
= cli_samr_close(cli
, mem_ctx
, &domain_hnd
);
4742 if (!NT_STATUS_IS_OK(nt_status
)) {
4743 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
4746 nt_status
= cli_samr_close(cli
, mem_ctx
, &connect_hnd
);
4747 if (!NT_STATUS_IS_OK(nt_status
)) {
4748 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
4751 /* close samr pipe and connection to IPC$ */
4752 cli_nt_session_close(cli
);
4755 talloc_destroy(mem_ctx
);
4760 * Entrypoint for 'net rpc trustdom' code
4762 * @param argc standard argc
4763 * @param argv standard argv without initial components
4765 * @return Integer status (0 means success)
4768 static int rpc_trustdom(int argc
, const char **argv
)
4770 struct functable func
[] = {
4771 {"add", rpc_trustdom_add
},
4772 {"del", rpc_trustdom_del
},
4773 {"establish", rpc_trustdom_establish
},
4774 {"revoke", rpc_trustdom_revoke
},
4775 {"help", rpc_trustdom_usage
},
4776 {"list", rpc_trustdom_list
},
4781 rpc_trustdom_usage(argc
, argv
);
4785 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
4789 * Check if a server will take rpc commands
4790 * @param flags Type of server to connect to (PDC, DMB, localhost)
4791 * if the host is not explicitly specified
4792 * @return BOOL (true means rpc supported)
4794 BOOL
net_rpc_check(unsigned flags
)
4796 struct cli_state cli
;
4798 struct in_addr server_ip
;
4799 char *server_name
= NULL
;
4801 /* flags (i.e. server type) may depend on command */
4802 if (!net_find_server(flags
, &server_ip
, &server_name
))
4806 if (cli_initialise(&cli
) == False
)
4809 if (!cli_connect(&cli
, server_name
, &server_ip
))
4811 if (!attempt_netbios_session_request(&cli
, global_myname(),
4812 server_name
, &server_ip
))
4814 if (!cli_negprot(&cli
))
4816 if (cli
.protocol
< PROTOCOL_NT1
)
4825 /* dump sam database via samsync rpc calls */
4826 static int rpc_samdump(int argc
, const char **argv
) {
4827 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
4831 /* syncronise sam database via samsync rpc calls */
4832 static int rpc_vampire(int argc
, const char **argv
) {
4833 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
4838 * Migrate everything from a print-server
4840 * @param argc Standard main() style argc
4841 * @param argv Standard main() style argv. Initial components are already
4844 * @return A shell status integer (0 for success)
4846 * The order is important !
4847 * To successfully add drivers the print-queues have to exist !
4848 * Applying ACLs should be the last step, because you're easily locked out
4851 static int rpc_printer_migrate_all(int argc
, const char **argv
)
4856 printf("no server to migrate\n");
4860 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
4864 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
4868 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
4872 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
4876 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
4881 * Migrate print-drivers from a print-server
4883 * @param argc Standard main() style argc
4884 * @param argv Standard main() style argv. Initial components are already
4887 * @return A shell status integer (0 for success)
4889 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
4892 printf("no server to migrate\n");
4896 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
4897 rpc_printer_migrate_drivers_internals
,
4902 * Migrate print-forms from a print-server
4904 * @param argc Standard main() style argc
4905 * @param argv Standard main() style argv. Initial components are already
4908 * @return A shell status integer (0 for success)
4910 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
4913 printf("no server to migrate\n");
4917 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
4918 rpc_printer_migrate_forms_internals
,
4923 * Migrate printers from a print-server
4925 * @param argc Standard main() style argc
4926 * @param argv Standard main() style argv. Initial components are already
4929 * @return A shell status integer (0 for success)
4931 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
4934 printf("no server to migrate\n");
4938 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
4939 rpc_printer_migrate_printers_internals
,
4944 * Migrate printer-ACLs from a print-server
4946 * @param argc Standard main() style argc
4947 * @param argv Standard main() style argv. Initial components are already
4950 * @return A shell status integer (0 for success)
4952 static int rpc_printer_migrate_security(int argc
, const char **argv
)
4955 printf("no server to migrate\n");
4959 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
4960 rpc_printer_migrate_security_internals
,
4965 * Migrate printer-settings from a print-server
4967 * @param argc Standard main() style argc
4968 * @param argv Standard main() style argv. Initial components are already
4971 * @return A shell status integer (0 for success)
4973 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
4976 printf("no server to migrate\n");
4980 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
4981 rpc_printer_migrate_settings_internals
,
4986 * 'net rpc printer' entrypoint.
4987 * @param argc Standard main() style argc
4988 * @param argv Standard main() style argv. Initial components are already
4992 int rpc_printer_migrate(int argc
, const char **argv
)
4995 /* ouch: when addriver and setdriver are called from within
4996 rpc_printer_migrate_drivers_internals, the printer-queue already
4999 struct functable func
[] = {
5000 {"all", rpc_printer_migrate_all
},
5001 {"drivers", rpc_printer_migrate_drivers
},
5002 {"forms", rpc_printer_migrate_forms
},
5003 {"help", rpc_printer_usage
},
5004 {"printers", rpc_printer_migrate_printers
},
5005 {"security", rpc_printer_migrate_security
},
5006 {"settings", rpc_printer_migrate_settings
},
5010 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
5015 * List printers on a remote RPC server
5017 * @param argc Standard main() style argc
5018 * @param argv Standard main() style argv. Initial components are already
5021 * @return A shell status integer (0 for success)
5023 static int rpc_printer_list(int argc
, const char **argv
)
5026 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5027 rpc_printer_list_internals
,
5032 * List printer-drivers on a remote RPC server
5034 * @param argc Standard main() style argc
5035 * @param argv Standard main() style argv. Initial components are already
5038 * @return A shell status integer (0 for success)
5040 static int rpc_printer_driver_list(int argc
, const char **argv
)
5043 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5044 rpc_printer_driver_list_internals
,
5049 * Publish printer in ADS via MSRPC
5051 * @param argc Standard main() style argc
5052 * @param argv Standard main() style argv. Initial components are already
5055 * @return A shell status integer (0 for success)
5057 static int rpc_printer_publish_publish(int argc
, const char **argv
)
5060 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5061 rpc_printer_publish_publish_internals
,
5066 * Update printer in ADS via MSRPC
5068 * @param argc Standard main() style argc
5069 * @param argv Standard main() style argv. Initial components are already
5072 * @return A shell status integer (0 for success)
5074 static int rpc_printer_publish_update(int argc
, const char **argv
)
5077 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5078 rpc_printer_publish_update_internals
,
5083 * UnPublish printer in ADS via MSRPC
5085 * @param argc Standard main() style argc
5086 * @param argv Standard main() style argv. Initial components are already
5089 * @return A shell status integer (0 for success)
5091 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
5094 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5095 rpc_printer_publish_unpublish_internals
,
5100 * List published printers via MSRPC
5102 * @param argc Standard main() style argc
5103 * @param argv Standard main() style argv. Initial components are already
5106 * @return A shell status integer (0 for success)
5108 static int rpc_printer_publish_list(int argc
, const char **argv
)
5111 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5112 rpc_printer_publish_list_internals
,
5118 * Publish printer in ADS
5120 * @param argc Standard main() style argc
5121 * @param argv Standard main() style argv. Initial components are already
5124 * @return A shell status integer (0 for success)
5126 static int rpc_printer_publish(int argc
, const char **argv
)
5129 struct functable func
[] = {
5130 {"publish", rpc_printer_publish_publish
},
5131 {"update", rpc_printer_publish_update
},
5132 {"unpublish", rpc_printer_publish_unpublish
},
5133 {"list", rpc_printer_publish_list
},
5134 {"help", rpc_printer_usage
},
5139 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5140 rpc_printer_publish_list_internals
,
5143 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
5149 * Display rpc printer help page.
5150 * @param argc Standard main() style argc
5151 * @param argv Standard main() style argv. Initial components are already
5154 int rpc_printer_usage(int argc
, const char **argv
)
5156 return net_help_printer(argc
, argv
);
5160 * 'net rpc printer' entrypoint.
5161 * @param argc Standard main() style argc
5162 * @param argv Standard main() style argv. Initial components are already
5165 int net_rpc_printer(int argc
, const char **argv
)
5167 struct functable func
[] = {
5168 {"list", rpc_printer_list
},
5169 {"migrate", rpc_printer_migrate
},
5170 {"driver", rpc_printer_driver_list
},
5171 {"publish", rpc_printer_publish
},
5176 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
5177 rpc_printer_list_internals
,
5180 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
5183 /****************************************************************************/
5187 * Basic usage function for 'net rpc'
5188 * @param argc Standard main() style argc
5189 * @param argv Standard main() style argv. Initial components are already
5193 int net_rpc_usage(int argc
, const char **argv
)
5195 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
5196 d_printf(" net rpc join \t\t\tto join a domain \n");
5197 d_printf(" net rpc oldjoin \t\t\tto join a domain created in server manager\n\n\n");
5198 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
5199 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
5200 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
5201 d_printf(" net rpc group \t\tto list groups\n");
5202 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
5203 d_printf(" net rpc printer \t\tto list and migrate printers\n");
5204 d_printf(" net rpc file \t\t\tto list open files\n");
5205 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
5206 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
5207 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
5208 d_printf(" net rpc samdump \t\tdiplay an NT PDC's users, groups and other data\n");
5209 d_printf(" net rpc trustdom \t\tto create trusting domain's account\n"
5210 "\t\t\t\t\tor establish trust\n");
5211 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
5212 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
5214 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
5215 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
5216 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
5217 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
5218 d_printf("\t-c or --comment=<message>\ttext message to display on impending shutdown\n");
5224 * Help function for 'net rpc'. Calls command specific help if requested
5225 * or displays usage of net rpc
5226 * @param argc Standard main() style argc
5227 * @param argv Standard main() style argv. Initial components are already
5231 int net_rpc_help(int argc
, const char **argv
)
5233 struct functable func
[] = {
5234 {"join", rpc_join_usage
},
5235 {"user", rpc_user_usage
},
5236 {"group", rpc_group_usage
},
5237 {"share", rpc_share_usage
},
5238 /*{"changetrustpw", rpc_changetrustpw_usage}, */
5239 {"trustdom", rpc_trustdom_usage
},
5240 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
5241 /*{"shutdown", rpc_shutdown_usage}, */
5246 net_rpc_usage(argc
, argv
);
5250 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
5255 * 'net rpc' entrypoint.
5256 * @param argc Standard main() style argc
5257 * @param argv Standard main() style argv. Initial components are already
5261 int net_rpc(int argc
, const char **argv
)
5263 struct functable func
[] = {
5264 {"info", net_rpc_info
},
5265 {"join", net_rpc_join
},
5266 {"oldjoin", net_rpc_oldjoin
},
5267 {"testjoin", net_rpc_testjoin
},
5268 {"user", net_rpc_user
},
5269 {"password", rpc_user_password
},
5270 {"group", net_rpc_group
},
5271 {"share", net_rpc_share
},
5272 {"file", net_rpc_file
},
5273 {"printer", net_rpc_printer
},
5274 {"changetrustpw", net_rpc_changetrustpw
},
5275 {"trustdom", rpc_trustdom
},
5276 {"abortshutdown", rpc_shutdown_abort
},
5277 {"shutdown", rpc_shutdown
},
5278 {"samdump", rpc_samdump
},
5279 {"vampire", rpc_vampire
},
5280 {"getsid", net_rpc_getsid
},
5281 {"help", net_rpc_help
},
5284 return net_run_function(argc
, argv
, func
, net_rpc_usage
);