2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
5 Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2004,2008 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2005 Jeremy Allison (jra@samba.org)
8 Copyright (C) 2006 Jelmer Vernooij (jelmer@samba.org)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "utils/net.h"
26 static int net_mode_share
;
27 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
32 * @brief RPC based subcommands for the 'net' utility.
34 * This file should contain much of the functionality that used to
35 * be found in rpcclient, execpt that the commands should change
36 * less often, and the fucntionality should be sane (the user is not
37 * expected to know a rid/sid before they conduct an operation etc.)
39 * @todo Perhaps eventually these should be split out into a number
40 * of files, as this could get quite big.
45 * Many of the RPC functions need the domain sid. This function gets
46 * it at the start of every run
48 * @param cli A cli_state already connected to the remote machine
50 * @return The Domain SID of the remote machine.
53 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
55 const char **domain_name
)
57 struct rpc_pipe_client
*lsa_pipe
;
59 NTSTATUS result
= NT_STATUS_OK
;
60 union lsa_PolicyInformation
*info
= NULL
;
62 lsa_pipe
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
64 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
68 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, False
,
69 SEC_RIGHTS_MAXIMUM_ALLOWED
,
71 if (!NT_STATUS_IS_OK(result
)) {
72 d_fprintf(stderr
, "open_policy failed: %s\n",
77 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
79 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
81 if (!NT_STATUS_IS_OK(result
)) {
82 d_fprintf(stderr
, "lsaquery failed: %s\n",
87 *domain_name
= info
->account_domain
.name
.string
;
88 *domain_sid
= info
->account_domain
.sid
;
90 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
91 cli_rpc_pipe_close(lsa_pipe
);
97 * Run a single RPC command, from start to finish.
99 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
100 * @param conn_flag a NET_FLAG_ combination. Passed to
101 * net_make_ipc_connection.
102 * @param argc Standard main() style argc
103 * @param argc Standard main() style argv. Initial components are already
105 * @return A shell status integer (0 for success)
108 int run_rpc_command(struct cli_state
*cli_arg
,
115 struct cli_state
*cli
= NULL
;
116 struct rpc_pipe_client
*pipe_hnd
= NULL
;
120 const char *domain_name
;
122 /* make use of cli_state handed over as an argument, if possible */
124 nt_status
= net_make_ipc_connection(conn_flags
, &cli
);
125 if (!NT_STATUS_IS_OK(nt_status
)) {
126 DEBUG(1, ("failed to make ipc connection: %s\n",
127 nt_errstr(nt_status
)));
140 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
141 DEBUG(0, ("talloc_init() failed\n"));
146 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
148 if (!NT_STATUS_IS_OK(nt_status
)) {
153 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
154 if (lp_client_schannel() && (pipe_idx
== PI_NETLOGON
)) {
155 /* Always try and create an schannel netlogon pipe. */
156 pipe_hnd
= cli_rpc_pipe_open_schannel(cli
, pipe_idx
,
157 PIPE_AUTH_LEVEL_PRIVACY
,
161 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
162 nt_errstr(nt_status
) ));
167 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, pipe_idx
, &nt_status
);
169 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
170 cli_get_pipe_name(pipe_idx
),
171 nt_errstr(nt_status
) ));
178 nt_status
= fn(domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
180 if (!NT_STATUS_IS_OK(nt_status
)) {
181 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
183 DEBUG(5, ("rpc command function succedded\n"));
186 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
188 cli_rpc_pipe_close(pipe_hnd
);
192 /* close the connection only if it was opened here */
197 talloc_destroy(mem_ctx
);
198 return (!NT_STATUS_IS_OK(nt_status
));
202 * Force a change of the trust acccount password.
204 * All parameters are provided by the run_rpc_command function, except for
205 * argc, argv which are passes through.
207 * @param domain_sid The domain sid aquired from the remote server
208 * @param cli A cli_state connected to the server.
209 * @param mem_ctx Talloc context, destoyed on compleation of the function.
210 * @param argc Standard main() style argc
211 * @param argc Standard main() style argv. Initial components are already
214 * @return Normal NTSTATUS return.
217 static NTSTATUS
rpc_changetrustpw_internals(const DOM_SID
*domain_sid
,
218 const char *domain_name
,
219 struct cli_state
*cli
,
220 struct rpc_pipe_client
*pipe_hnd
,
226 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
);
230 * Force a change of the trust acccount password.
232 * @param argc Standard main() style argc
233 * @param argc Standard main() style argv. Initial components are already
236 * @return A shell status integer (0 for success)
239 int net_rpc_changetrustpw(int argc
, const char **argv
)
241 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
242 rpc_changetrustpw_internals
,
247 * Join a domain, the old way.
249 * This uses 'machinename' as the inital password, and changes it.
251 * The password should be created with 'server manager' or equiv first.
253 * All parameters are provided by the run_rpc_command function, except for
254 * argc, argv which are passes through.
256 * @param domain_sid The domain sid aquired from the remote server
257 * @param cli A cli_state connected to the server.
258 * @param mem_ctx Talloc context, destoyed on compleation of the function.
259 * @param argc Standard main() style argc
260 * @param argc Standard main() style argv. Initial components are already
263 * @return Normal NTSTATUS return.
266 static NTSTATUS
rpc_oldjoin_internals(const DOM_SID
*domain_sid
,
267 const char *domain_name
,
268 struct cli_state
*cli
,
269 struct rpc_pipe_client
*pipe_hnd
,
275 fstring trust_passwd
;
276 unsigned char orig_trust_passwd_hash
[16];
278 uint32 sec_channel_type
;
280 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &result
);
282 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
285 nt_errstr(result
) ));
290 check what type of join - if the user want's to join as
291 a BDC, the server must agree that we are a BDC.
294 sec_channel_type
= get_sec_channel_type(argv
[0]);
296 sec_channel_type
= get_sec_channel_type(NULL
);
299 fstrcpy(trust_passwd
, global_myname());
300 strlower_m(trust_passwd
);
303 * Machine names can be 15 characters, but the max length on
304 * a password is 14. --jerry
307 trust_passwd
[14] = '\0';
309 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
311 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, opt_target_workgroup
,
312 orig_trust_passwd_hash
,
315 if (NT_STATUS_IS_OK(result
))
316 printf("Joined domain %s.\n",opt_target_workgroup
);
319 if (!secrets_store_domain_sid(opt_target_workgroup
, domain_sid
)) {
320 DEBUG(0, ("error storing domain sid for %s\n", opt_target_workgroup
));
321 result
= NT_STATUS_UNSUCCESSFUL
;
328 * Join a domain, the old way.
330 * @param argc Standard main() style argc
331 * @param argc Standard main() style argv. Initial components are already
334 * @return A shell status integer (0 for success)
337 static int net_rpc_perform_oldjoin(int argc
, const char **argv
)
339 return run_rpc_command(NULL
, PI_NETLOGON
,
340 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
341 rpc_oldjoin_internals
,
346 * Join a domain, the old way. This function exists to allow
347 * the message to be displayed when oldjoin was explicitly
348 * requested, but not when it was implied by "net rpc join"
350 * @param argc Standard main() style argc
351 * @param argc Standard main() style argv. Initial components are already
354 * @return A shell status integer (0 for success)
357 static int net_rpc_oldjoin(int argc
, const char **argv
)
359 int rc
= net_rpc_perform_oldjoin(argc
, argv
);
362 d_fprintf(stderr
, "Failed to join domain\n");
369 * Basic usage function for 'net rpc join'
370 * @param argc Standard main() style argc
371 * @param argc Standard main() style argv. Initial components are already
375 static int rpc_join_usage(int argc
, const char **argv
)
377 d_printf("net rpc join -U <username>[%%password] <type>[options]\n"\
378 "\t to join a domain with admin username & password\n"\
379 "\t\t password will be prompted if needed and none is specified\n"\
380 "\t <type> can be (default MEMBER)\n"\
381 "\t\t BDC - Join as a BDC\n"\
382 "\t\t PDC - Join as a PDC\n"\
383 "\t\t MEMBER - Join as a MEMBER server\n");
385 net_common_flags_usage(argc
, argv
);
390 * 'net rpc join' entrypoint.
391 * @param argc Standard main() style argc
392 * @param argc Standard main() style argv. Initial components are already
395 * Main 'net_rpc_join()' (where the admin username/password is used) is
397 * Try to just change the password, but if that doesn't work, use/prompt
398 * for a username/password.
401 int net_rpc_join(int argc
, const char **argv
)
403 if (lp_server_role() == ROLE_STANDALONE
) {
404 d_printf("cannot join as standalone machine\n");
408 if (strlen(global_myname()) > 15) {
409 d_printf("Our netbios name can be at most 15 chars long, "
410 "\"%s\" is %u chars long\n",
411 global_myname(), (unsigned int)strlen(global_myname()));
415 if ((net_rpc_perform_oldjoin(argc
, argv
) == 0))
418 return net_rpc_join_newstyle(argc
, argv
);
422 * display info about a rpc domain
424 * All parameters are provided by the run_rpc_command function, except for
425 * argc, argv which are passed through.
427 * @param domain_sid The domain sid acquired from the remote server
428 * @param cli A cli_state connected to the server.
429 * @param mem_ctx Talloc context, destoyed on completion of the function.
430 * @param argc Standard main() style argc
431 * @param argv Standard main() style argv. Initial components are already
434 * @return Normal NTSTATUS return.
437 NTSTATUS
rpc_info_internals(const DOM_SID
*domain_sid
,
438 const char *domain_name
,
439 struct cli_state
*cli
,
440 struct rpc_pipe_client
*pipe_hnd
,
445 POLICY_HND connect_pol
, domain_pol
;
446 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
447 union samr_DomainInfo
*info
= NULL
;
450 sid_to_fstring(sid_str
, domain_sid
);
452 /* Get sam policy handle */
453 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
454 pipe_hnd
->cli
->desthost
,
455 MAXIMUM_ALLOWED_ACCESS
,
457 if (!NT_STATUS_IS_OK(result
)) {
458 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
462 /* Get domain policy handle */
463 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
465 MAXIMUM_ALLOWED_ACCESS
,
466 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
468 if (!NT_STATUS_IS_OK(result
)) {
469 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
473 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
477 if (NT_STATUS_IS_OK(result
)) {
478 d_printf("Domain Name: %s\n", info
->info2
.domain_name
.string
);
479 d_printf("Domain SID: %s\n", sid_str
);
480 d_printf("Sequence number: %llu\n",
481 (unsigned long long)info
->info2
.sequence_num
);
482 d_printf("Num users: %u\n", info
->info2
.num_users
);
483 d_printf("Num domain groups: %u\n", info
->info2
.num_groups
);
484 d_printf("Num local groups: %u\n", info
->info2
.num_aliases
);
492 * 'net rpc info' entrypoint.
493 * @param argc Standard main() style argc
494 * @param argc Standard main() style argv. Initial components are already
498 int net_rpc_info(int argc
, const char **argv
)
500 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_PDC
,
506 * Fetch domain SID into the local secrets.tdb
508 * All parameters are provided by the run_rpc_command function, except for
509 * argc, argv which are passes through.
511 * @param domain_sid The domain sid acquired from the remote server
512 * @param cli A cli_state connected to the server.
513 * @param mem_ctx Talloc context, destoyed on completion of the function.
514 * @param argc Standard main() style argc
515 * @param argv Standard main() style argv. Initial components are already
518 * @return Normal NTSTATUS return.
521 static NTSTATUS
rpc_getsid_internals(const DOM_SID
*domain_sid
,
522 const char *domain_name
,
523 struct cli_state
*cli
,
524 struct rpc_pipe_client
*pipe_hnd
,
531 sid_to_fstring(sid_str
, domain_sid
);
532 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
533 sid_str
, domain_name
);
535 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
536 DEBUG(0,("Can't store domain SID\n"));
537 return NT_STATUS_UNSUCCESSFUL
;
544 * 'net rpc getsid' entrypoint.
545 * @param argc Standard main() style argc
546 * @param argc Standard main() style argv. Initial components are already
550 int net_rpc_getsid(int argc
, const char **argv
)
552 return run_rpc_command(NULL
, PI_SAMR
, NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
553 rpc_getsid_internals
,
557 /****************************************************************************/
560 * Basic usage function for 'net rpc user'
561 * @param argc Standard main() style argc.
562 * @param argv Standard main() style argv. Initial components are already
566 static int rpc_user_usage(int argc
, const char **argv
)
568 return net_help_user(argc
, argv
);
572 * Add a new user to a remote RPC server
574 * @param argc Standard main() style argc
575 * @param argv Standard main() style argv. Initial components are already
578 * @return A shell status integer (0 for success)
581 static int rpc_user_add(int argc
, const char **argv
)
583 NET_API_STATUS status
;
584 struct USER_INFO_1 info1
;
585 uint32_t parm_error
= 0;
588 d_printf("User must be specified\n");
589 rpc_user_usage(argc
, argv
);
595 info1
.usri1_name
= argv
[0];
597 info1
.usri1_password
= argv
[1];
600 status
= NetUserAdd(opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
603 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
604 argv
[0], libnetapi_get_error_string(netapi_ctx
, status
));
607 d_printf("Added user '%s'.\n", argv
[0]);
614 * Rename a user on a remote RPC server
616 * All parameters are provided by the run_rpc_command function, except for
617 * argc, argv which are passes through.
619 * @param domain_sid The domain sid acquired from the remote server
620 * @param cli A cli_state connected to the server.
621 * @param mem_ctx Talloc context, destoyed on completion of the function.
622 * @param argc Standard main() style argc
623 * @param argv Standard main() style argv. Initial components are already
626 * @return Normal NTSTATUS return.
629 static NTSTATUS
rpc_user_rename_internals(const DOM_SID
*domain_sid
,
630 const char *domain_name
,
631 struct cli_state
*cli
,
632 struct rpc_pipe_client
*pipe_hnd
,
637 POLICY_HND connect_pol
, domain_pol
, user_pol
;
638 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
639 uint32 info_level
= 7;
640 const char *old_name
, *new_name
;
641 struct samr_Ids user_rids
, name_types
;
642 struct lsa_String lsa_acct_name
;
643 union samr_UserInfo
*info
= NULL
;
646 d_printf("Old and new username must be specified\n");
647 rpc_user_usage(argc
, argv
);
654 /* Get sam policy handle */
656 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
657 pipe_hnd
->cli
->desthost
,
658 MAXIMUM_ALLOWED_ACCESS
,
661 if (!NT_STATUS_IS_OK(result
)) {
665 /* Get domain policy handle */
667 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
669 MAXIMUM_ALLOWED_ACCESS
,
670 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
672 if (!NT_STATUS_IS_OK(result
)) {
676 init_lsa_String(&lsa_acct_name
, old_name
);
678 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
684 if (!NT_STATUS_IS_OK(result
)) {
688 /* Open domain user */
689 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
691 MAXIMUM_ALLOWED_ACCESS
,
695 if (!NT_STATUS_IS_OK(result
)) {
699 /* Query user info */
700 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
705 if (!NT_STATUS_IS_OK(result
)) {
709 init_samr_user_info7(&info
->info7
, new_name
);
712 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
717 if (!NT_STATUS_IS_OK(result
)) {
722 if (!NT_STATUS_IS_OK(result
)) {
723 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n", old_name
, new_name
,
726 d_printf("Renamed user from %s to %s\n", old_name
, new_name
);
732 * Rename a user on a remote RPC server
734 * @param argc Standard main() style argc
735 * @param argv Standard main() style argv. Initial components are already
738 * @return A shell status integer (0 for success)
741 static int rpc_user_rename(int argc
, const char **argv
)
743 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_rename_internals
,
748 * Delete a user from a remote RPC server
750 * @param argc Standard main() style argc
751 * @param argv Standard main() style argv. Initial components are already
754 * @return A shell status integer (0 for success)
757 static int rpc_user_delete(int argc
, const char **argv
)
759 NET_API_STATUS status
;
762 d_printf("User must be specified\n");
763 rpc_user_usage(argc
, argv
);
767 status
= NetUserDel(opt_host
, argv
[0]);
770 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
772 libnetapi_get_error_string(netapi_ctx
, status
));
775 d_printf("Deleted user '%s'.\n", argv
[0]);
782 * Set a password for a user on a remote RPC server
784 * All parameters are provided by the run_rpc_command function, except for
785 * argc, argv which are passes through.
787 * @param domain_sid The domain sid acquired from the remote server
788 * @param cli A cli_state connected to the server.
789 * @param mem_ctx Talloc context, destoyed on completion of the function.
790 * @param argc Standard main() style argc
791 * @param argv Standard main() style argv. Initial components are already
794 * @return Normal NTSTATUS return.
797 static NTSTATUS
rpc_user_password_internals(const DOM_SID
*domain_sid
,
798 const char *domain_name
,
799 struct cli_state
*cli
,
800 struct rpc_pipe_client
*pipe_hnd
,
805 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
806 POLICY_HND connect_pol
, domain_pol
, user_pol
;
809 const char *new_password
;
811 union samr_UserInfo info
;
814 d_printf("User must be specified\n");
815 rpc_user_usage(argc
, argv
);
822 new_password
= argv
[1];
824 asprintf(&prompt
, "Enter new password for %s:", user
);
825 new_password
= getpass(prompt
);
829 /* Get sam policy and domain handles */
831 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
832 pipe_hnd
->cli
->desthost
,
833 MAXIMUM_ALLOWED_ACCESS
,
836 if (!NT_STATUS_IS_OK(result
)) {
840 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
842 MAXIMUM_ALLOWED_ACCESS
,
843 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
846 if (!NT_STATUS_IS_OK(result
)) {
850 /* Get handle on user */
853 struct samr_Ids user_rids
, name_types
;
854 struct lsa_String lsa_acct_name
;
856 init_lsa_String(&lsa_acct_name
, user
);
858 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
864 if (!NT_STATUS_IS_OK(result
)) {
868 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
870 MAXIMUM_ALLOWED_ACCESS
,
874 if (!NT_STATUS_IS_OK(result
)) {
879 /* Set password on account */
881 encode_pw_buffer(pwbuf
, new_password
, STR_UNICODE
);
883 init_samr_user_info24(&info
.info24
, pwbuf
, 24);
885 SamOEMhashBlob(info
.info24
.password
.data
, 516,
886 &cli
->user_session_key
);
888 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
893 if (!NT_STATUS_IS_OK(result
)) {
897 /* Display results */
905 * Set a user's password on a remote RPC server
907 * @param argc Standard main() style argc
908 * @param argv Standard main() style argv. Initial components are already
911 * @return A shell status integer (0 for success)
914 static int rpc_user_password(int argc
, const char **argv
)
916 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_password_internals
,
921 * List user's groups on a remote RPC server
923 * All parameters are provided by the run_rpc_command function, except for
924 * argc, argv which are passes through.
926 * @param domain_sid The domain sid acquired from the remote server
927 * @param cli A cli_state connected to the server.
928 * @param mem_ctx Talloc context, destoyed on completion of the function.
929 * @param argc Standard main() style argc
930 * @param argv Standard main() style argv. Initial components are already
933 * @return Normal NTSTATUS return.
936 static NTSTATUS
rpc_user_info_internals(const DOM_SID
*domain_sid
,
937 const char *domain_name
,
938 struct cli_state
*cli
,
939 struct rpc_pipe_client
*pipe_hnd
,
944 POLICY_HND connect_pol
, domain_pol
, user_pol
;
945 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
947 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
948 struct lsa_Strings names
;
949 struct samr_Ids types
;
950 uint32_t *lrids
= NULL
;
951 struct samr_Ids rids
, name_types
;
952 struct lsa_String lsa_acct_name
;
956 d_printf("User must be specified\n");
957 rpc_user_usage(argc
, argv
);
960 /* Get sam policy handle */
962 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
963 pipe_hnd
->cli
->desthost
,
964 MAXIMUM_ALLOWED_ACCESS
,
966 if (!NT_STATUS_IS_OK(result
)) goto done
;
968 /* Get domain policy handle */
970 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
972 MAXIMUM_ALLOWED_ACCESS
,
973 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
975 if (!NT_STATUS_IS_OK(result
)) goto done
;
977 /* Get handle on user */
979 init_lsa_String(&lsa_acct_name
, argv
[0]);
981 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
988 if (!NT_STATUS_IS_OK(result
)) goto done
;
990 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
992 MAXIMUM_ALLOWED_ACCESS
,
995 if (!NT_STATUS_IS_OK(result
)) goto done
;
997 result
= rpccli_samr_GetGroupsForUser(pipe_hnd
, mem_ctx
,
1001 if (!NT_STATUS_IS_OK(result
)) goto done
;
1005 if (rid_array
->count
) {
1006 if ((lrids
= TALLOC_ARRAY(mem_ctx
, uint32
, rid_array
->count
)) == NULL
) {
1007 result
= NT_STATUS_NO_MEMORY
;
1011 for (i
= 0; i
< rid_array
->count
; i
++)
1012 lrids
[i
] = rid_array
->rids
[i
].rid
;
1014 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
1021 if (!NT_STATUS_IS_OK(result
)) {
1025 /* Display results */
1027 for (i
= 0; i
< names
.count
; i
++)
1028 printf("%s\n", names
.names
[i
].string
);
1035 * List a user's groups from a remote RPC server
1037 * @param argc Standard main() style argc
1038 * @param argv Standard main() style argv. Initial components are already
1041 * @return A shell status integer (0 for success)
1044 static int rpc_user_info(int argc
, const char **argv
)
1046 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_user_info_internals
,
1051 * List users on a remote RPC server
1053 * All parameters are provided by the run_rpc_command function, except for
1054 * argc, argv which are passes through.
1056 * @param domain_sid The domain sid acquired from the remote server
1057 * @param cli A cli_state connected to the server.
1058 * @param mem_ctx Talloc context, destoyed on completion of the function.
1059 * @param argc Standard main() style argc
1060 * @param argv Standard main() style argv. Initial components are already
1063 * @return Normal NTSTATUS return.
1066 static NTSTATUS
rpc_user_list_internals(const DOM_SID
*domain_sid
,
1067 const char *domain_name
,
1068 struct cli_state
*cli
,
1069 struct rpc_pipe_client
*pipe_hnd
,
1070 TALLOC_CTX
*mem_ctx
,
1074 POLICY_HND connect_pol
, domain_pol
;
1075 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1076 uint32 start_idx
=0, num_entries
, i
, loop_count
= 0;
1078 /* Get sam policy handle */
1080 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1081 pipe_hnd
->cli
->desthost
,
1082 MAXIMUM_ALLOWED_ACCESS
,
1084 if (!NT_STATUS_IS_OK(result
)) {
1088 /* Get domain policy handle */
1090 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1092 MAXIMUM_ALLOWED_ACCESS
,
1093 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1095 if (!NT_STATUS_IS_OK(result
)) {
1099 /* Query domain users */
1100 if (opt_long_list_entries
)
1101 d_printf("\nUser name Comment"\
1102 "\n-----------------------------\n");
1104 const char *user
= NULL
;
1105 const char *desc
= NULL
;
1106 uint32 max_entries
, max_size
;
1107 uint32_t total_size
, returned_size
;
1108 union samr_DispInfo info
;
1110 get_query_dispinfo_params(
1111 loop_count
, &max_entries
, &max_size
);
1113 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
1123 start_idx
+= info
.info1
.count
;
1124 num_entries
= info
.info1
.count
;
1126 for (i
= 0; i
< num_entries
; i
++) {
1127 user
= info
.info1
.entries
[i
].account_name
.string
;
1128 if (opt_long_list_entries
)
1129 desc
= info
.info1
.entries
[i
].description
.string
;
1130 if (opt_long_list_entries
)
1131 printf("%-21.21s %s\n", user
, desc
);
1133 printf("%s\n", user
);
1135 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
1142 * 'net rpc user' entrypoint.
1143 * @param argc Standard main() style argc
1144 * @param argc Standard main() style argv. Initial components are already
1148 int net_rpc_user(int argc
, const char **argv
)
1150 NET_API_STATUS status
;
1152 struct functable func
[] = {
1153 {"add", rpc_user_add
},
1154 {"info", rpc_user_info
},
1155 {"delete", rpc_user_delete
},
1156 {"password", rpc_user_password
},
1157 {"rename", rpc_user_rename
},
1161 status
= libnetapi_init(&netapi_ctx
);
1165 libnetapi_set_username(netapi_ctx
, opt_user_name
);
1166 libnetapi_set_password(netapi_ctx
, opt_password
);
1169 return run_rpc_command(NULL
,PI_SAMR
, 0,
1170 rpc_user_list_internals
,
1174 return net_run_function(argc
, argv
, func
, rpc_user_usage
);
1177 static NTSTATUS
rpc_sh_user_list(TALLOC_CTX
*mem_ctx
,
1178 struct rpc_sh_ctx
*ctx
,
1179 struct rpc_pipe_client
*pipe_hnd
,
1180 int argc
, const char **argv
)
1182 return rpc_user_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
1183 ctx
->cli
, pipe_hnd
, mem_ctx
,
1187 static NTSTATUS
rpc_sh_user_info(TALLOC_CTX
*mem_ctx
,
1188 struct rpc_sh_ctx
*ctx
,
1189 struct rpc_pipe_client
*pipe_hnd
,
1190 int argc
, const char **argv
)
1192 return rpc_user_info_internals(ctx
->domain_sid
, ctx
->domain_name
,
1193 ctx
->cli
, pipe_hnd
, mem_ctx
,
1197 static NTSTATUS
rpc_sh_handle_user(TALLOC_CTX
*mem_ctx
,
1198 struct rpc_sh_ctx
*ctx
,
1199 struct rpc_pipe_client
*pipe_hnd
,
1200 int argc
, const char **argv
,
1202 TALLOC_CTX
*mem_ctx
,
1203 struct rpc_sh_ctx
*ctx
,
1204 struct rpc_pipe_client
*pipe_hnd
,
1205 POLICY_HND
*user_hnd
,
1206 int argc
, const char **argv
))
1208 POLICY_HND connect_pol
, domain_pol
, user_pol
;
1209 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1212 enum lsa_SidType type
;
1215 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1216 return NT_STATUS_INVALID_PARAMETER
;
1219 ZERO_STRUCT(connect_pol
);
1220 ZERO_STRUCT(domain_pol
);
1221 ZERO_STRUCT(user_pol
);
1223 result
= net_rpc_lookup_name(mem_ctx
, pipe_hnd
->cli
, argv
[0],
1224 NULL
, NULL
, &sid
, &type
);
1225 if (!NT_STATUS_IS_OK(result
)) {
1226 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1231 if (type
!= SID_NAME_USER
) {
1232 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1233 sid_type_lookup(type
));
1234 result
= NT_STATUS_NO_SUCH_USER
;
1238 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1239 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1240 result
= NT_STATUS_NO_SUCH_USER
;
1244 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1245 pipe_hnd
->cli
->desthost
,
1246 MAXIMUM_ALLOWED_ACCESS
,
1248 if (!NT_STATUS_IS_OK(result
)) {
1252 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1254 MAXIMUM_ALLOWED_ACCESS
,
1257 if (!NT_STATUS_IS_OK(result
)) {
1261 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1263 MAXIMUM_ALLOWED_ACCESS
,
1266 if (!NT_STATUS_IS_OK(result
)) {
1270 result
= fn(mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1273 if (is_valid_policy_hnd(&user_pol
)) {
1274 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1276 if (is_valid_policy_hnd(&domain_pol
)) {
1277 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1279 if (is_valid_policy_hnd(&connect_pol
)) {
1280 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1285 static NTSTATUS
rpc_sh_user_show_internals(TALLOC_CTX
*mem_ctx
,
1286 struct rpc_sh_ctx
*ctx
,
1287 struct rpc_pipe_client
*pipe_hnd
,
1288 POLICY_HND
*user_hnd
,
1289 int argc
, const char **argv
)
1292 union samr_UserInfo
*info
= NULL
;
1295 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1296 return NT_STATUS_INVALID_PARAMETER
;
1299 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1303 if (!NT_STATUS_IS_OK(result
)) {
1307 d_printf("user rid: %d, group rid: %d\n",
1309 info
->info21
.primary_gid
);
1314 static NTSTATUS
rpc_sh_user_show(TALLOC_CTX
*mem_ctx
,
1315 struct rpc_sh_ctx
*ctx
,
1316 struct rpc_pipe_client
*pipe_hnd
,
1317 int argc
, const char **argv
)
1319 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1320 rpc_sh_user_show_internals
);
1323 #define FETCHSTR(name, rec) \
1324 do { if (strequal(ctx->thiscmd, name)) { \
1325 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1328 #define SETSTR(name, rec, flag) \
1329 do { if (strequal(ctx->thiscmd, name)) { \
1330 init_lsa_String(&(info->info21.rec), argv[0]); \
1331 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1334 static NTSTATUS
rpc_sh_user_str_edit_internals(TALLOC_CTX
*mem_ctx
,
1335 struct rpc_sh_ctx
*ctx
,
1336 struct rpc_pipe_client
*pipe_hnd
,
1337 POLICY_HND
*user_hnd
,
1338 int argc
, const char **argv
)
1341 const char *username
;
1342 const char *oldval
= "";
1343 union samr_UserInfo
*info
= NULL
;
1346 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1348 return NT_STATUS_INVALID_PARAMETER
;
1351 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1355 if (!NT_STATUS_IS_OK(result
)) {
1359 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1361 FETCHSTR("fullname", full_name
);
1362 FETCHSTR("homedir", home_directory
);
1363 FETCHSTR("homedrive", home_drive
);
1364 FETCHSTR("logonscript", logon_script
);
1365 FETCHSTR("profilepath", profile_path
);
1366 FETCHSTR("description", description
);
1369 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1373 if (strcmp(argv
[0], "NULL") == 0) {
1377 ZERO_STRUCT(info
->info21
);
1379 SETSTR("fullname", full_name
, FULL_NAME
);
1380 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1381 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1382 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1383 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1384 SETSTR("description", description
, DESCRIPTION
);
1386 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1391 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1392 ctx
->thiscmd
, oldval
, argv
[0]);
1399 #define HANDLEFLG(name, rec) \
1400 do { if (strequal(ctx->thiscmd, name)) { \
1401 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1403 newflags = oldflags | ACB_##rec; \
1405 newflags = oldflags & ~ACB_##rec; \
1408 static NTSTATUS
rpc_sh_user_str_edit(TALLOC_CTX
*mem_ctx
,
1409 struct rpc_sh_ctx
*ctx
,
1410 struct rpc_pipe_client
*pipe_hnd
,
1411 int argc
, const char **argv
)
1413 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1414 rpc_sh_user_str_edit_internals
);
1417 static NTSTATUS
rpc_sh_user_flag_edit_internals(TALLOC_CTX
*mem_ctx
,
1418 struct rpc_sh_ctx
*ctx
,
1419 struct rpc_pipe_client
*pipe_hnd
,
1420 POLICY_HND
*user_hnd
,
1421 int argc
, const char **argv
)
1424 const char *username
;
1425 const char *oldval
= "unknown";
1426 uint32 oldflags
, newflags
;
1428 union samr_UserInfo
*info
= NULL
;
1431 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1432 !strequal(argv
[0], "no"))) {
1433 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1435 return NT_STATUS_INVALID_PARAMETER
;
1438 newval
= strequal(argv
[0], "yes");
1440 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1444 if (!NT_STATUS_IS_OK(result
)) {
1448 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1449 oldflags
= info
->info21
.acct_flags
;
1450 newflags
= info
->info21
.acct_flags
;
1452 HANDLEFLG("disabled", DISABLED
);
1453 HANDLEFLG("pwnotreq", PWNOTREQ
);
1454 HANDLEFLG("autolock", AUTOLOCK
);
1455 HANDLEFLG("pwnoexp", PWNOEXP
);
1458 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1462 ZERO_STRUCT(info
->info21
);
1464 info
->info21
.acct_flags
= newflags
;
1465 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1467 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1472 if (NT_STATUS_IS_OK(result
)) {
1473 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1474 ctx
->thiscmd
, oldval
, argv
[0]);
1482 static NTSTATUS
rpc_sh_user_flag_edit(TALLOC_CTX
*mem_ctx
,
1483 struct rpc_sh_ctx
*ctx
,
1484 struct rpc_pipe_client
*pipe_hnd
,
1485 int argc
, const char **argv
)
1487 return rpc_sh_handle_user(mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1488 rpc_sh_user_flag_edit_internals
);
1491 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(TALLOC_CTX
*mem_ctx
,
1492 struct rpc_sh_ctx
*ctx
)
1494 static struct rpc_sh_cmd cmds
[] = {
1496 { "fullname", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1497 "Show/Set a user's full name" },
1499 { "homedir", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1500 "Show/Set a user's home directory" },
1502 { "homedrive", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1503 "Show/Set a user's home drive" },
1505 { "logonscript", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1506 "Show/Set a user's logon script" },
1508 { "profilepath", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1509 "Show/Set a user's profile path" },
1511 { "description", NULL
, PI_SAMR
, rpc_sh_user_str_edit
,
1512 "Show/Set a user's description" },
1514 { "disabled", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1515 "Show/Set whether a user is disabled" },
1517 { "autolock", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1518 "Show/Set whether a user locked out" },
1520 { "pwnotreq", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1521 "Show/Set whether a user does not need a password" },
1523 { "pwnoexp", NULL
, PI_SAMR
, rpc_sh_user_flag_edit
,
1524 "Show/Set whether a user's password does not expire" },
1526 { NULL
, NULL
, 0, NULL
, NULL
}
1532 struct rpc_sh_cmd
*net_rpc_user_cmds(TALLOC_CTX
*mem_ctx
,
1533 struct rpc_sh_ctx
*ctx
)
1535 static struct rpc_sh_cmd cmds
[] = {
1537 { "list", NULL
, PI_SAMR
, rpc_sh_user_list
,
1538 "List available users" },
1540 { "info", NULL
, PI_SAMR
, rpc_sh_user_info
,
1541 "List the domain groups a user is member of" },
1543 { "show", NULL
, PI_SAMR
, rpc_sh_user_show
,
1544 "Show info about a user" },
1546 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1547 "Show/Modify a user's fields" },
1549 { NULL
, NULL
, 0, NULL
, NULL
}
1555 /****************************************************************************/
1558 * Basic usage function for 'net rpc group'
1559 * @param argc Standard main() style argc.
1560 * @param argv Standard main() style argv. Initial components are already
1564 static int rpc_group_usage(int argc
, const char **argv
)
1566 return net_help_group(argc
, argv
);
1570 * Delete group on a remote RPC server
1572 * All parameters are provided by the run_rpc_command function, except for
1573 * argc, argv which are passes through.
1575 * @param domain_sid The domain sid acquired from the remote server
1576 * @param cli A cli_state connected to the server.
1577 * @param mem_ctx Talloc context, destoyed on completion of the function.
1578 * @param argc Standard main() style argc
1579 * @param argv Standard main() style argv. Initial components are already
1582 * @return Normal NTSTATUS return.
1585 static NTSTATUS
rpc_group_delete_internals(const DOM_SID
*domain_sid
,
1586 const char *domain_name
,
1587 struct cli_state
*cli
,
1588 struct rpc_pipe_client
*pipe_hnd
,
1589 TALLOC_CTX
*mem_ctx
,
1593 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1594 bool group_is_primary
= False
;
1595 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1597 struct samr_RidTypeArray
*rids
= NULL
;
1600 /* DOM_GID *user_gids; */
1602 struct samr_Ids group_rids
, name_types
;
1603 struct lsa_String lsa_acct_name
;
1604 union samr_UserInfo
*info
= NULL
;
1607 d_printf("specify group\n");
1608 rpc_group_usage(argc
,argv
);
1609 return NT_STATUS_OK
; /* ok? */
1612 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1613 pipe_hnd
->cli
->desthost
,
1614 MAXIMUM_ALLOWED_ACCESS
,
1617 if (!NT_STATUS_IS_OK(result
)) {
1618 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1622 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1624 MAXIMUM_ALLOWED_ACCESS
,
1625 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1628 if (!NT_STATUS_IS_OK(result
)) {
1629 d_fprintf(stderr
, "Request open_domain failed\n");
1633 init_lsa_String(&lsa_acct_name
, argv
[0]);
1635 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1641 if (!NT_STATUS_IS_OK(result
)) {
1642 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1646 switch (name_types
.ids
[0])
1648 case SID_NAME_DOM_GRP
:
1649 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1651 MAXIMUM_ALLOWED_ACCESS
,
1654 if (!NT_STATUS_IS_OK(result
)) {
1655 d_fprintf(stderr
, "Request open_group failed");
1659 group_rid
= group_rids
.ids
[0];
1661 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1665 if (!NT_STATUS_IS_OK(result
)) {
1666 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1671 d_printf("Domain Group %s (rid: %d) has %d members\n",
1672 argv
[0],group_rid
, rids
->count
);
1675 /* Check if group is anyone's primary group */
1676 for (i
= 0; i
< rids
->count
; i
++)
1678 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1680 MAXIMUM_ALLOWED_ACCESS
,
1684 if (!NT_STATUS_IS_OK(result
)) {
1685 d_fprintf(stderr
, "Unable to open group member %d\n",
1690 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1695 if (!NT_STATUS_IS_OK(result
)) {
1696 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1701 if (info
->info21
.primary_gid
== group_rid
) {
1703 d_printf("Group is primary group of %s\n",
1704 info
->info21
.account_name
.string
);
1706 group_is_primary
= True
;
1709 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1712 if (group_is_primary
) {
1713 d_fprintf(stderr
, "Unable to delete group because some "
1714 "of it's members have it as primary group\n");
1715 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1719 /* remove all group members */
1720 for (i
= 0; i
< rids
->count
; i
++)
1723 d_printf("Remove group member %d...",
1725 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1729 if (NT_STATUS_IS_OK(result
)) {
1734 d_printf("failed\n");
1739 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1743 /* removing a local group is easier... */
1744 case SID_NAME_ALIAS
:
1745 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1747 MAXIMUM_ALLOWED_ACCESS
,
1751 if (!NT_STATUS_IS_OK(result
)) {
1752 d_fprintf(stderr
, "Request open_alias failed\n");
1756 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1760 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1761 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1762 result
= NT_STATUS_UNSUCCESSFUL
;
1767 if (NT_STATUS_IS_OK(result
)) {
1769 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1771 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1772 get_friendly_nt_error_msg(result
));
1780 static int rpc_group_delete(int argc
, const char **argv
)
1782 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_group_delete_internals
,
1786 static NTSTATUS
rpc_group_add_internals(const DOM_SID
*domain_sid
,
1787 const char *domain_name
,
1788 struct cli_state
*cli
,
1789 struct rpc_pipe_client
*pipe_hnd
,
1790 TALLOC_CTX
*mem_ctx
,
1794 POLICY_HND connect_pol
, domain_pol
, group_pol
;
1795 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1796 union samr_GroupInfo group_info
;
1797 struct lsa_String grp_name
;
1801 d_printf("Group name must be specified\n");
1802 rpc_group_usage(argc
, argv
);
1803 return NT_STATUS_OK
;
1806 init_lsa_String(&grp_name
, argv
[0]);
1808 /* Get sam policy handle */
1810 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1811 pipe_hnd
->cli
->desthost
,
1812 MAXIMUM_ALLOWED_ACCESS
,
1814 if (!NT_STATUS_IS_OK(result
)) goto done
;
1816 /* Get domain policy handle */
1818 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1820 MAXIMUM_ALLOWED_ACCESS
,
1821 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1823 if (!NT_STATUS_IS_OK(result
)) goto done
;
1825 /* Create the group */
1827 result
= rpccli_samr_CreateDomainGroup(pipe_hnd
, mem_ctx
,
1830 MAXIMUM_ALLOWED_ACCESS
,
1833 if (!NT_STATUS_IS_OK(result
)) goto done
;
1835 if (strlen(opt_comment
) == 0) goto done
;
1837 /* We've got a comment to set */
1839 init_lsa_String(&group_info
.description
, opt_comment
);
1841 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
1845 if (!NT_STATUS_IS_OK(result
)) goto done
;
1848 if (NT_STATUS_IS_OK(result
))
1849 DEBUG(5, ("add group succeeded\n"));
1851 d_fprintf(stderr
, "add group failed: %s\n", nt_errstr(result
));
1856 static NTSTATUS
rpc_alias_add_internals(const DOM_SID
*domain_sid
,
1857 const char *domain_name
,
1858 struct cli_state
*cli
,
1859 struct rpc_pipe_client
*pipe_hnd
,
1860 TALLOC_CTX
*mem_ctx
,
1864 POLICY_HND connect_pol
, domain_pol
, alias_pol
;
1865 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1866 union samr_AliasInfo alias_info
;
1867 struct lsa_String alias_name
;
1871 d_printf("Alias name must be specified\n");
1872 rpc_group_usage(argc
, argv
);
1873 return NT_STATUS_OK
;
1876 init_lsa_String(&alias_name
, argv
[0]);
1878 /* Get sam policy handle */
1880 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1881 pipe_hnd
->cli
->desthost
,
1882 MAXIMUM_ALLOWED_ACCESS
,
1884 if (!NT_STATUS_IS_OK(result
)) goto done
;
1886 /* Get domain policy handle */
1888 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1890 MAXIMUM_ALLOWED_ACCESS
,
1891 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1893 if (!NT_STATUS_IS_OK(result
)) goto done
;
1895 /* Create the group */
1897 result
= rpccli_samr_CreateDomAlias(pipe_hnd
, mem_ctx
,
1900 MAXIMUM_ALLOWED_ACCESS
,
1903 if (!NT_STATUS_IS_OK(result
)) goto done
;
1905 if (strlen(opt_comment
) == 0) goto done
;
1907 /* We've got a comment to set */
1909 init_lsa_String(&alias_info
.description
, opt_comment
);
1911 result
= rpccli_samr_SetAliasInfo(pipe_hnd
, mem_ctx
,
1916 if (!NT_STATUS_IS_OK(result
)) goto done
;
1919 if (NT_STATUS_IS_OK(result
))
1920 DEBUG(5, ("add alias succeeded\n"));
1922 d_fprintf(stderr
, "add alias failed: %s\n", nt_errstr(result
));
1927 static int rpc_group_add(int argc
, const char **argv
)
1930 return run_rpc_command(NULL
, PI_SAMR
, 0,
1931 rpc_alias_add_internals
,
1934 return run_rpc_command(NULL
, PI_SAMR
, 0,
1935 rpc_group_add_internals
,
1939 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1940 TALLOC_CTX
*mem_ctx
,
1943 enum lsa_SidType
*type
)
1945 DOM_SID
*sids
= NULL
;
1946 enum lsa_SidType
*types
= NULL
;
1947 struct rpc_pipe_client
*pipe_hnd
;
1949 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1951 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &result
);
1956 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, False
,
1957 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1959 if (!NT_STATUS_IS_OK(result
)) {
1963 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1964 &name
, NULL
, 1, &sids
, &types
);
1966 if (NT_STATUS_IS_OK(result
)) {
1967 sid_copy(sid
, &sids
[0]);
1971 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1975 cli_rpc_pipe_close(pipe_hnd
);
1978 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1980 /* Try as S-1-5-whatever */
1984 if (string_to_sid(&tmp_sid
, name
)) {
1985 sid_copy(sid
, &tmp_sid
);
1986 *type
= SID_NAME_UNKNOWN
;
1987 result
= NT_STATUS_OK
;
1994 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1995 TALLOC_CTX
*mem_ctx
,
1996 const DOM_SID
*group_sid
,
1999 POLICY_HND connect_pol
, domain_pol
;
2002 POLICY_HND group_pol
;
2004 struct samr_Ids rids
, rid_types
;
2005 struct lsa_String lsa_acct_name
;
2009 sid_copy(&sid
, group_sid
);
2011 if (!sid_split_rid(&sid
, &group_rid
)) {
2012 return NT_STATUS_UNSUCCESSFUL
;
2015 /* Get sam policy handle */
2016 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2017 pipe_hnd
->cli
->desthost
,
2018 MAXIMUM_ALLOWED_ACCESS
,
2020 if (!NT_STATUS_IS_OK(result
)) {
2024 /* Get domain policy handle */
2025 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2027 MAXIMUM_ALLOWED_ACCESS
,
2030 if (!NT_STATUS_IS_OK(result
)) {
2034 init_lsa_String(&lsa_acct_name
, member
);
2036 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2043 if (!NT_STATUS_IS_OK(result
)) {
2044 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2048 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2050 MAXIMUM_ALLOWED_ACCESS
,
2054 if (!NT_STATUS_IS_OK(result
)) {
2058 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
2061 0x0005); /* unknown flags */
2064 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2068 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2069 TALLOC_CTX
*mem_ctx
,
2070 const DOM_SID
*alias_sid
,
2073 POLICY_HND connect_pol
, domain_pol
;
2076 POLICY_HND alias_pol
;
2079 enum lsa_SidType member_type
;
2083 sid_copy(&sid
, alias_sid
);
2085 if (!sid_split_rid(&sid
, &alias_rid
)) {
2086 return NT_STATUS_UNSUCCESSFUL
;
2089 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2090 &member_sid
, &member_type
);
2092 if (!NT_STATUS_IS_OK(result
)) {
2093 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2097 /* Get sam policy handle */
2098 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2099 pipe_hnd
->cli
->desthost
,
2100 MAXIMUM_ALLOWED_ACCESS
,
2102 if (!NT_STATUS_IS_OK(result
)) {
2106 /* Get domain policy handle */
2107 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2109 MAXIMUM_ALLOWED_ACCESS
,
2112 if (!NT_STATUS_IS_OK(result
)) {
2116 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2118 MAXIMUM_ALLOWED_ACCESS
,
2122 if (!NT_STATUS_IS_OK(result
)) {
2126 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
2130 if (!NT_STATUS_IS_OK(result
)) {
2135 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2139 static NTSTATUS
rpc_group_addmem_internals(const DOM_SID
*domain_sid
,
2140 const char *domain_name
,
2141 struct cli_state
*cli
,
2142 struct rpc_pipe_client
*pipe_hnd
,
2143 TALLOC_CTX
*mem_ctx
,
2148 enum lsa_SidType group_type
;
2151 d_printf("Usage: 'net rpc group addmem <group> <member>\n");
2152 return NT_STATUS_UNSUCCESSFUL
;
2155 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2156 &group_sid
, &group_type
))) {
2157 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2158 return NT_STATUS_UNSUCCESSFUL
;
2161 if (group_type
== SID_NAME_DOM_GRP
) {
2162 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
2163 &group_sid
, argv
[1]);
2165 if (!NT_STATUS_IS_OK(result
)) {
2166 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2167 argv
[1], argv
[0], nt_errstr(result
));
2172 if (group_type
== SID_NAME_ALIAS
) {
2173 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
2174 &group_sid
, argv
[1]);
2176 if (!NT_STATUS_IS_OK(result
)) {
2177 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
2178 argv
[1], argv
[0], nt_errstr(result
));
2183 d_fprintf(stderr
, "Can only add members to global or local groups "
2184 "which %s is not\n", argv
[0]);
2186 return NT_STATUS_UNSUCCESSFUL
;
2189 static int rpc_group_addmem(int argc
, const char **argv
)
2191 return run_rpc_command(NULL
, PI_SAMR
, 0,
2192 rpc_group_addmem_internals
,
2196 static NTSTATUS
rpc_del_groupmem(struct rpc_pipe_client
*pipe_hnd
,
2197 TALLOC_CTX
*mem_ctx
,
2198 const DOM_SID
*group_sid
,
2201 POLICY_HND connect_pol
, domain_pol
;
2204 POLICY_HND group_pol
;
2206 struct samr_Ids rids
, rid_types
;
2207 struct lsa_String lsa_acct_name
;
2211 sid_copy(&sid
, group_sid
);
2213 if (!sid_split_rid(&sid
, &group_rid
))
2214 return NT_STATUS_UNSUCCESSFUL
;
2216 /* Get sam policy handle */
2217 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2218 pipe_hnd
->cli
->desthost
,
2219 MAXIMUM_ALLOWED_ACCESS
,
2221 if (!NT_STATUS_IS_OK(result
))
2224 /* Get domain policy handle */
2225 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2227 MAXIMUM_ALLOWED_ACCESS
,
2230 if (!NT_STATUS_IS_OK(result
))
2233 init_lsa_String(&lsa_acct_name
, member
);
2235 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2241 if (!NT_STATUS_IS_OK(result
)) {
2242 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2246 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2248 MAXIMUM_ALLOWED_ACCESS
,
2252 if (!NT_STATUS_IS_OK(result
))
2255 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
2260 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2264 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
2265 TALLOC_CTX
*mem_ctx
,
2266 const DOM_SID
*alias_sid
,
2269 POLICY_HND connect_pol
, domain_pol
;
2272 POLICY_HND alias_pol
;
2275 enum lsa_SidType member_type
;
2279 sid_copy(&sid
, alias_sid
);
2281 if (!sid_split_rid(&sid
, &alias_rid
))
2282 return NT_STATUS_UNSUCCESSFUL
;
2284 result
= get_sid_from_name(pipe_hnd
->cli
, mem_ctx
, member
,
2285 &member_sid
, &member_type
);
2287 if (!NT_STATUS_IS_OK(result
)) {
2288 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2292 /* Get sam policy handle */
2293 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2294 pipe_hnd
->cli
->desthost
,
2295 MAXIMUM_ALLOWED_ACCESS
,
2297 if (!NT_STATUS_IS_OK(result
)) {
2301 /* Get domain policy handle */
2302 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2304 MAXIMUM_ALLOWED_ACCESS
,
2307 if (!NT_STATUS_IS_OK(result
)) {
2311 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2313 MAXIMUM_ALLOWED_ACCESS
,
2317 if (!NT_STATUS_IS_OK(result
))
2320 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2324 if (!NT_STATUS_IS_OK(result
))
2328 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2332 static NTSTATUS
rpc_group_delmem_internals(const DOM_SID
*domain_sid
,
2333 const char *domain_name
,
2334 struct cli_state
*cli
,
2335 struct rpc_pipe_client
*pipe_hnd
,
2336 TALLOC_CTX
*mem_ctx
,
2341 enum lsa_SidType group_type
;
2344 d_printf("Usage: 'net rpc group delmem <group> <member>\n");
2345 return NT_STATUS_UNSUCCESSFUL
;
2348 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2349 &group_sid
, &group_type
))) {
2350 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2351 return NT_STATUS_UNSUCCESSFUL
;
2354 if (group_type
== SID_NAME_DOM_GRP
) {
2355 NTSTATUS result
= rpc_del_groupmem(pipe_hnd
, mem_ctx
,
2356 &group_sid
, argv
[1]);
2358 if (!NT_STATUS_IS_OK(result
)) {
2359 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2360 argv
[1], argv
[0], nt_errstr(result
));
2365 if (group_type
== SID_NAME_ALIAS
) {
2366 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2367 &group_sid
, argv
[1]);
2369 if (!NT_STATUS_IS_OK(result
)) {
2370 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2371 argv
[1], argv
[0], nt_errstr(result
));
2376 d_fprintf(stderr
, "Can only delete members from global or local groups "
2377 "which %s is not\n", argv
[0]);
2379 return NT_STATUS_UNSUCCESSFUL
;
2382 static int rpc_group_delmem(int argc
, const char **argv
)
2384 return run_rpc_command(NULL
, PI_SAMR
, 0,
2385 rpc_group_delmem_internals
,
2390 * List groups on a remote RPC server
2392 * All parameters are provided by the run_rpc_command function, except for
2393 * argc, argv which are passes through.
2395 * @param domain_sid The domain sid acquired from the remote server
2396 * @param cli A cli_state connected to the server.
2397 * @param mem_ctx Talloc context, destoyed on completion of the function.
2398 * @param argc Standard main() style argc
2399 * @param argv Standard main() style argv. Initial components are already
2402 * @return Normal NTSTATUS return.
2405 static NTSTATUS
rpc_group_list_internals(const DOM_SID
*domain_sid
,
2406 const char *domain_name
,
2407 struct cli_state
*cli
,
2408 struct rpc_pipe_client
*pipe_hnd
,
2409 TALLOC_CTX
*mem_ctx
,
2413 POLICY_HND connect_pol
, domain_pol
;
2414 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2415 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2416 struct samr_SamArray
*groups
= NULL
;
2417 bool global
= False
;
2419 bool builtin
= False
;
2427 for (i
=0; i
<argc
; i
++) {
2428 if (strequal(argv
[i
], "global"))
2431 if (strequal(argv
[i
], "local"))
2434 if (strequal(argv
[i
], "builtin"))
2438 /* Get sam policy handle */
2440 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2441 pipe_hnd
->cli
->desthost
,
2442 MAXIMUM_ALLOWED_ACCESS
,
2444 if (!NT_STATUS_IS_OK(result
)) {
2448 /* Get domain policy handle */
2450 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2452 MAXIMUM_ALLOWED_ACCESS
,
2453 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2455 if (!NT_STATUS_IS_OK(result
)) {
2459 /* Query domain groups */
2460 if (opt_long_list_entries
)
2461 d_printf("\nGroup name Comment"\
2462 "\n-----------------------------\n");
2464 uint32_t max_size
, total_size
, returned_size
;
2465 union samr_DispInfo info
;
2469 get_query_dispinfo_params(
2470 loop_count
, &max_entries
, &max_size
);
2472 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2481 num_entries
= info
.info3
.count
;
2482 start_idx
+= info
.info3
.count
;
2484 if (!NT_STATUS_IS_OK(result
) &&
2485 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2488 for (i
= 0; i
< num_entries
; i
++) {
2490 const char *group
= NULL
;
2491 const char *desc
= NULL
;
2493 group
= info
.info3
.entries
[i
].account_name
.string
;
2494 desc
= info
.info3
.entries
[i
].description
.string
;
2496 if (opt_long_list_entries
)
2497 printf("%-21.21s %-50.50s\n",
2500 printf("%s\n", group
);
2502 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2503 /* query domain aliases */
2508 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2514 if (!NT_STATUS_IS_OK(result
) &&
2515 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2518 for (i
= 0; i
< num_entries
; i
++) {
2520 const char *description
= NULL
;
2522 if (opt_long_list_entries
) {
2524 POLICY_HND alias_pol
;
2525 union samr_AliasInfo
*info
= NULL
;
2527 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2530 groups
->entries
[i
].idx
,
2532 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2536 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2538 description
= info
->description
.string
;
2542 if (description
!= NULL
) {
2543 printf("%-21.21s %-50.50s\n",
2544 groups
->entries
[i
].name
.string
,
2547 printf("%s\n", groups
->entries
[i
].name
.string
);
2550 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2551 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2552 /* Get builtin policy handle */
2554 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2556 MAXIMUM_ALLOWED_ACCESS
,
2557 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2559 if (!NT_STATUS_IS_OK(result
)) {
2562 /* query builtin aliases */
2565 if (!builtin
) break;
2567 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2573 if (!NT_STATUS_IS_OK(result
) &&
2574 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2577 for (i
= 0; i
< num_entries
; i
++) {
2579 const char *description
= NULL
;
2581 if (opt_long_list_entries
) {
2583 POLICY_HND alias_pol
;
2584 union samr_AliasInfo
*info
= NULL
;
2586 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2589 groups
->entries
[i
].idx
,
2591 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2595 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2597 description
= info
->description
.string
;
2601 if (description
!= NULL
) {
2602 printf("%-21.21s %-50.50s\n",
2603 groups
->entries
[i
].name
.string
,
2606 printf("%s\n", groups
->entries
[i
].name
.string
);
2609 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2615 static int rpc_group_list(int argc
, const char **argv
)
2617 return run_rpc_command(NULL
, PI_SAMR
, 0,
2618 rpc_group_list_internals
,
2622 static NTSTATUS
rpc_list_group_members(struct rpc_pipe_client
*pipe_hnd
,
2623 TALLOC_CTX
*mem_ctx
,
2624 const char *domain_name
,
2625 const DOM_SID
*domain_sid
,
2626 POLICY_HND
*domain_pol
,
2630 POLICY_HND group_pol
;
2631 uint32 num_members
, *group_rids
;
2633 struct samr_RidTypeArray
*rids
= NULL
;
2634 struct lsa_Strings names
;
2635 struct samr_Ids types
;
2638 sid_to_fstring(sid_str
, domain_sid
);
2640 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2642 MAXIMUM_ALLOWED_ACCESS
,
2646 if (!NT_STATUS_IS_OK(result
))
2649 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2653 if (!NT_STATUS_IS_OK(result
))
2656 num_members
= rids
->count
;
2657 group_rids
= rids
->rids
;
2659 while (num_members
> 0) {
2660 int this_time
= 512;
2662 if (num_members
< this_time
)
2663 this_time
= num_members
;
2665 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2672 if (!NT_STATUS_IS_OK(result
))
2675 /* We only have users as members, but make the output
2676 the same as the output of alias members */
2678 for (i
= 0; i
< this_time
; i
++) {
2680 if (opt_long_list_entries
) {
2681 printf("%s-%d %s\\%s %d\n", sid_str
,
2682 group_rids
[i
], domain_name
,
2683 names
.names
[i
].string
,
2686 printf("%s\\%s\n", domain_name
,
2687 names
.names
[i
].string
);
2691 num_members
-= this_time
;
2695 return NT_STATUS_OK
;
2698 static NTSTATUS
rpc_list_alias_members(struct rpc_pipe_client
*pipe_hnd
,
2699 TALLOC_CTX
*mem_ctx
,
2700 POLICY_HND
*domain_pol
,
2704 struct rpc_pipe_client
*lsa_pipe
;
2705 POLICY_HND alias_pol
, lsa_pol
;
2707 DOM_SID
*alias_sids
;
2710 enum lsa_SidType
*types
;
2712 struct lsa_SidArray sid_array
;
2714 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2716 MAXIMUM_ALLOWED_ACCESS
,
2720 if (!NT_STATUS_IS_OK(result
))
2723 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2727 if (!NT_STATUS_IS_OK(result
)) {
2728 d_fprintf(stderr
, "Couldn't list alias members\n");
2732 num_members
= sid_array
.num_sids
;
2734 if (num_members
== 0) {
2735 return NT_STATUS_OK
;
2738 lsa_pipe
= cli_rpc_pipe_open_noauth(pipe_hnd
->cli
, PI_LSARPC
, &result
);
2740 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2741 nt_errstr(result
) );
2745 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, True
,
2746 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2748 if (!NT_STATUS_IS_OK(result
)) {
2749 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2750 cli_rpc_pipe_close(lsa_pipe
);
2754 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2756 d_fprintf(stderr
, "Out of memory\n");
2757 cli_rpc_pipe_close(lsa_pipe
);
2758 return NT_STATUS_NO_MEMORY
;
2761 for (i
=0; i
<num_members
; i
++) {
2762 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2765 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
, num_members
,
2767 &domains
, &names
, &types
);
2769 if (!NT_STATUS_IS_OK(result
) &&
2770 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2771 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2772 cli_rpc_pipe_close(lsa_pipe
);
2776 for (i
= 0; i
< num_members
; i
++) {
2778 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2780 if (opt_long_list_entries
) {
2781 printf("%s %s\\%s %d\n", sid_str
,
2782 domains
[i
] ? domains
[i
] : "*unknown*",
2783 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2786 printf("%s\\%s\n", domains
[i
], names
[i
]);
2788 printf("%s\n", sid_str
);
2792 cli_rpc_pipe_close(lsa_pipe
);
2793 return NT_STATUS_OK
;
2796 static NTSTATUS
rpc_group_members_internals(const DOM_SID
*domain_sid
,
2797 const char *domain_name
,
2798 struct cli_state
*cli
,
2799 struct rpc_pipe_client
*pipe_hnd
,
2800 TALLOC_CTX
*mem_ctx
,
2805 POLICY_HND connect_pol
, domain_pol
;
2806 struct samr_Ids rids
, rid_types
;
2807 struct lsa_String lsa_acct_name
;
2809 /* Get sam policy handle */
2811 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2812 pipe_hnd
->cli
->desthost
,
2813 MAXIMUM_ALLOWED_ACCESS
,
2816 if (!NT_STATUS_IS_OK(result
))
2819 /* Get domain policy handle */
2821 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2823 MAXIMUM_ALLOWED_ACCESS
,
2824 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2827 if (!NT_STATUS_IS_OK(result
))
2830 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2832 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2839 if (!NT_STATUS_IS_OK(result
)) {
2841 /* Ok, did not find it in the global sam, try with builtin */
2843 DOM_SID sid_Builtin
;
2845 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2847 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2849 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2851 MAXIMUM_ALLOWED_ACCESS
,
2855 if (!NT_STATUS_IS_OK(result
)) {
2856 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2860 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2867 if (!NT_STATUS_IS_OK(result
)) {
2868 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2873 if (rids
.count
!= 1) {
2874 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2878 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2879 return rpc_list_group_members(pipe_hnd
, mem_ctx
, domain_name
,
2880 domain_sid
, &domain_pol
,
2884 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2885 return rpc_list_alias_members(pipe_hnd
, mem_ctx
, &domain_pol
,
2889 return NT_STATUS_NO_SUCH_GROUP
;
2892 static int rpc_group_members(int argc
, const char **argv
)
2895 return rpc_group_usage(argc
, argv
);
2898 return run_rpc_command(NULL
, PI_SAMR
, 0,
2899 rpc_group_members_internals
,
2903 static NTSTATUS
rpc_group_rename_internals(const DOM_SID
*domain_sid
,
2904 const char *domain_name
,
2905 struct cli_state
*cli
,
2906 struct rpc_pipe_client
*pipe_hnd
,
2907 TALLOC_CTX
*mem_ctx
,
2912 POLICY_HND connect_pol
, domain_pol
, group_pol
;
2913 union samr_GroupInfo group_info
;
2914 struct samr_Ids rids
, rid_types
;
2915 struct lsa_String lsa_acct_name
;
2918 d_printf("Usage: 'net rpc group rename group newname'\n");
2919 return NT_STATUS_UNSUCCESSFUL
;
2922 /* Get sam policy handle */
2924 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2925 pipe_hnd
->cli
->desthost
,
2926 MAXIMUM_ALLOWED_ACCESS
,
2929 if (!NT_STATUS_IS_OK(result
))
2932 /* Get domain policy handle */
2934 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2936 MAXIMUM_ALLOWED_ACCESS
,
2937 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2940 if (!NT_STATUS_IS_OK(result
))
2943 init_lsa_String(&lsa_acct_name
, argv
[0]);
2945 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2952 if (rids
.count
!= 1) {
2953 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2957 if (rid_types
.ids
[0] != SID_NAME_DOM_GRP
) {
2958 d_fprintf(stderr
, "Can only rename domain groups\n");
2959 return NT_STATUS_UNSUCCESSFUL
;
2962 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2964 MAXIMUM_ALLOWED_ACCESS
,
2968 if (!NT_STATUS_IS_OK(result
))
2971 init_lsa_String(&group_info
.name
, argv
[1]);
2973 result
= rpccli_samr_SetGroupInfo(pipe_hnd
, mem_ctx
,
2978 if (!NT_STATUS_IS_OK(result
))
2981 return NT_STATUS_NO_SUCH_GROUP
;
2984 static int rpc_group_rename(int argc
, const char **argv
)
2987 return rpc_group_usage(argc
, argv
);
2990 return run_rpc_command(NULL
, PI_SAMR
, 0,
2991 rpc_group_rename_internals
,
2996 * 'net rpc group' entrypoint.
2997 * @param argc Standard main() style argc
2998 * @param argc Standard main() style argv. Initial components are already
3002 int net_rpc_group(int argc
, const char **argv
)
3004 struct functable func
[] = {
3005 {"add", rpc_group_add
},
3006 {"delete", rpc_group_delete
},
3007 {"addmem", rpc_group_addmem
},
3008 {"delmem", rpc_group_delmem
},
3009 {"list", rpc_group_list
},
3010 {"members", rpc_group_members
},
3011 {"rename", rpc_group_rename
},
3016 return run_rpc_command(NULL
, PI_SAMR
, 0,
3017 rpc_group_list_internals
,
3021 return net_run_function(argc
, argv
, func
, rpc_group_usage
);
3024 /****************************************************************************/
3026 static int rpc_share_usage(int argc
, const char **argv
)
3028 return net_help_share(argc
, argv
);
3032 * Add a share on a remote RPC server
3034 * All parameters are provided by the run_rpc_command function, except for
3035 * argc, argv which are passes through.
3037 * @param domain_sid The domain sid acquired from the remote server
3038 * @param cli A cli_state connected to the server.
3039 * @param mem_ctx Talloc context, destoyed on completion of the function.
3040 * @param argc Standard main() style argc
3041 * @param argv Standard main() style argv. Initial components are already
3044 * @return Normal NTSTATUS return.
3046 static NTSTATUS
rpc_share_add_internals(const DOM_SID
*domain_sid
,
3047 const char *domain_name
,
3048 struct cli_state
*cli
,
3049 struct rpc_pipe_client
*pipe_hnd
,
3050 TALLOC_CTX
*mem_ctx
,int argc
,
3057 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
3058 uint32 num_users
=0, perms
=0;
3059 char *password
=NULL
; /* don't allow a share password */
3061 union srvsvc_NetShareInfo info
;
3062 struct srvsvc_NetShareInfo2 info2
;
3063 uint32_t parm_error
= 0;
3065 if ((sharename
= talloc_strdup(mem_ctx
, argv
[0])) == NULL
) {
3066 return NT_STATUS_NO_MEMORY
;
3069 path
= strchr(sharename
, '=');
3071 return NT_STATUS_UNSUCCESSFUL
;
3074 info2
.name
= sharename
;
3076 info2
.comment
= opt_comment
;
3077 info2
.permissions
= perms
;
3078 info2
.max_users
= opt_maxusers
;
3079 info2
.current_users
= num_users
;
3081 info2
.password
= password
;
3083 info
.info2
= &info2
;
3085 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
3086 pipe_hnd
->cli
->desthost
,
3094 static int rpc_share_add(int argc
, const char **argv
)
3096 if ((argc
< 1) || !strchr(argv
[0], '=')) {
3097 DEBUG(1,("Sharename or path not specified on add\n"));
3098 return rpc_share_usage(argc
, argv
);
3100 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3101 rpc_share_add_internals
,
3106 * Delete a share on a remote RPC server
3108 * All parameters are provided by the run_rpc_command function, except for
3109 * argc, argv which are passes through.
3111 * @param domain_sid The domain sid acquired from the remote server
3112 * @param cli A cli_state connected to the server.
3113 * @param mem_ctx Talloc context, destoyed on completion of the function.
3114 * @param argc Standard main() style argc
3115 * @param argv Standard main() style argv. Initial components are already
3118 * @return Normal NTSTATUS return.
3120 static NTSTATUS
rpc_share_del_internals(const DOM_SID
*domain_sid
,
3121 const char *domain_name
,
3122 struct cli_state
*cli
,
3123 struct rpc_pipe_client
*pipe_hnd
,
3124 TALLOC_CTX
*mem_ctx
,
3130 return rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
3131 pipe_hnd
->cli
->desthost
,
3138 * Delete a share on a remote RPC server
3140 * @param domain_sid The domain sid acquired from the remote server
3141 * @param argc Standard main() style argc
3142 * @param argv Standard main() style argv. Initial components are already
3145 * @return A shell status integer (0 for success)
3147 static int rpc_share_delete(int argc
, const char **argv
)
3150 DEBUG(1,("Sharename not specified on delete\n"));
3151 return rpc_share_usage(argc
, argv
);
3153 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3154 rpc_share_del_internals
,
3159 * Formatted print of share info
3161 * @param info1 pointer to SRV_SHARE_INFO_1 to format
3164 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
3166 if (opt_long_list_entries
) {
3167 d_printf("%-12s %-8.8s %-50s\n",
3169 share_type
[r
->type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)],
3172 d_printf("%s\n", r
->name
);
3176 static WERROR
get_share_info(struct rpc_pipe_client
*pipe_hnd
,
3177 TALLOC_CTX
*mem_ctx
,
3181 struct srvsvc_NetShareInfoCtr
*info_ctr
)
3185 union srvsvc_NetShareInfo info
;
3187 /* no specific share requested, enumerate all */
3190 uint32_t preferred_len
= 0xffffffff;
3191 uint32_t total_entries
= 0;
3192 uint32_t resume_handle
= 0;
3194 info_ctr
->level
= level
;
3196 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
3197 pipe_hnd
->cli
->desthost
,
3206 /* request just one share */
3207 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
3208 pipe_hnd
->cli
->desthost
,
3214 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
3219 ZERO_STRUCTP(info_ctr
);
3221 info_ctr
->level
= level
;
3226 struct srvsvc_NetShareCtr1
*ctr1
;
3228 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
3229 W_ERROR_HAVE_NO_MEMORY(ctr1
);
3232 ctr1
->array
= info
.info1
;
3234 info_ctr
->ctr
.ctr1
= ctr1
;
3238 struct srvsvc_NetShareCtr2
*ctr2
;
3240 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
3241 W_ERROR_HAVE_NO_MEMORY(ctr2
);
3244 ctr2
->array
= info
.info2
;
3246 info_ctr
->ctr
.ctr2
= ctr2
;
3250 struct srvsvc_NetShareCtr502
*ctr502
;
3252 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
3253 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3256 ctr502
->array
= info
.info502
;
3258 info_ctr
->ctr
.ctr502
= ctr502
;
3266 * List shares on a remote RPC server
3268 * All parameters are provided by the run_rpc_command function, except for
3269 * argc, argv which are passes through.
3271 * @param domain_sid The domain sid acquired from the remote server
3272 * @param cli A cli_state connected to the server.
3273 * @param mem_ctx Talloc context, destoyed on completion of the function.
3274 * @param argc Standard main() style argc
3275 * @param argv Standard main() style argv. Initial components are already
3278 * @return Normal NTSTATUS return.
3281 static NTSTATUS
rpc_share_list_internals(const DOM_SID
*domain_sid
,
3282 const char *domain_name
,
3283 struct cli_state
*cli
,
3284 struct rpc_pipe_client
*pipe_hnd
,
3285 TALLOC_CTX
*mem_ctx
,
3289 struct srvsvc_NetShareInfoCtr info_ctr
;
3290 struct srvsvc_NetShareCtr1 ctr1
;
3292 uint32 i
, level
= 1;
3294 ZERO_STRUCT(info_ctr
);
3298 info_ctr
.ctr
.ctr1
= &ctr1
;
3300 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &info_ctr
);
3301 if (!W_ERROR_IS_OK(result
))
3304 /* Display results */
3306 if (opt_long_list_entries
) {
3308 "\nEnumerating shared resources (exports) on remote server:\n\n"\
3309 "\nShare name Type Description\n"\
3310 "---------- ---- -----------\n");
3312 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++)
3313 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
3315 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3319 * 'net rpc share list' entrypoint.
3320 * @param argc Standard main() style argc
3321 * @param argv Standard main() style argv. Initial components are already
3324 static int rpc_share_list(int argc
, const char **argv
)
3326 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_list_internals
, argc
, argv
);
3329 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3331 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3332 d_printf("skipping [%s]: not a file share.\n", netname
);
3342 static bool check_share_sanity(struct cli_state
*cli
, const char *netname
, uint32 type
)
3344 /* only support disk shares */
3345 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3346 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3350 /* skip builtin shares */
3351 /* FIXME: should print$ be added too ? */
3352 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3353 strequal(netname
,"global"))
3356 if (opt_exclude
&& in_list(netname
, opt_exclude
, False
)) {
3357 printf("excluding [%s]\n", netname
);
3361 return check_share_availability(cli
, netname
);
3365 * Migrate shares from a remote RPC server to the local RPC server
3367 * All parameters are provided by the run_rpc_command function, except for
3368 * argc, argv which are passed through.
3370 * @param domain_sid The domain sid acquired from the remote server
3371 * @param cli A cli_state connected to the server.
3372 * @param mem_ctx Talloc context, destroyed on completion of the function.
3373 * @param argc Standard main() style argc
3374 * @param argv Standard main() style argv. Initial components are already
3377 * @return Normal NTSTATUS return.
3380 static NTSTATUS
rpc_share_migrate_shares_internals(const DOM_SID
*domain_sid
,
3381 const char *domain_name
,
3382 struct cli_state
*cli
,
3383 struct rpc_pipe_client
*pipe_hnd
,
3384 TALLOC_CTX
*mem_ctx
,
3389 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3390 struct srvsvc_NetShareInfoCtr ctr_src
;
3392 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3393 struct cli_state
*cli_dst
= NULL
;
3394 uint32 level
= 502; /* includes secdesc */
3395 uint32_t parm_error
= 0;
3397 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3398 if (!W_ERROR_IS_OK(result
))
3401 /* connect destination PI_SRVSVC */
3402 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3403 if (!NT_STATUS_IS_OK(nt_status
))
3407 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3409 union srvsvc_NetShareInfo info
;
3410 struct srvsvc_NetShareInfo502 info502
=
3411 ctr_src
.ctr
.ctr502
->array
[i
];
3413 /* reset error-code */
3414 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3416 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3419 /* finally add the share on the dst server */
3421 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3422 info502
.name
, info502
.path
, info502
.comment
);
3424 info
.info502
= &info502
;
3426 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3427 srvsvc_pipe
->cli
->desthost
,
3433 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3434 printf(" [%s] does already exist\n",
3439 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3440 printf("cannot add share: %s\n", dos_errstr(result
));
3446 nt_status
= NT_STATUS_OK
;
3450 cli_shutdown(cli_dst
);
3458 * Migrate shares from a rpc-server to another
3460 * @param argc Standard main() style argc
3461 * @param argv Standard main() style argv. Initial components are already
3464 * @return A shell status integer (0 for success)
3466 static int rpc_share_migrate_shares(int argc
, const char **argv
)
3470 printf("no server to migrate\n");
3474 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3475 rpc_share_migrate_shares_internals
,
3482 * @param f file_info
3483 * @param mask current search mask
3484 * @param state arg-pointer
3487 static void copy_fn(const char *mnt
, file_info
*f
, const char *mask
, void *state
)
3489 static NTSTATUS nt_status
;
3490 static struct copy_clistate
*local_state
;
3491 static fstring filename
, new_mask
;
3495 local_state
= (struct copy_clistate
*)state
;
3496 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3498 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3501 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3504 if (f
->mode
& aDIR
) {
3506 DEBUG(3,("got dir: %s\n", f
->name
));
3508 fstrcpy(dir
, local_state
->cwd
);
3510 fstrcat(dir
, f
->name
);
3512 switch (net_mode_share
)
3514 case NET_MODE_SHARE_MIGRATE
:
3515 /* create that directory */
3516 nt_status
= net_copy_file(local_state
->mem_ctx
,
3517 local_state
->cli_share_src
,
3518 local_state
->cli_share_dst
,
3520 opt_acls
? True
: False
,
3521 opt_attrs
? True
: False
,
3522 opt_timestamps
? True
: False
,
3526 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3530 if (!NT_STATUS_IS_OK(nt_status
))
3531 printf("could not handle dir %s: %s\n",
3532 dir
, nt_errstr(nt_status
));
3534 /* search below that directory */
3535 fstrcpy(new_mask
, dir
);
3536 fstrcat(new_mask
, "\\*");
3538 old_dir
= local_state
->cwd
;
3539 local_state
->cwd
= dir
;
3540 if (!sync_files(local_state
, new_mask
))
3541 printf("could not handle files\n");
3542 local_state
->cwd
= old_dir
;
3549 fstrcpy(filename
, local_state
->cwd
);
3550 fstrcat(filename
, "\\");
3551 fstrcat(filename
, f
->name
);
3553 DEBUG(3,("got file: %s\n", filename
));
3555 switch (net_mode_share
)
3557 case NET_MODE_SHARE_MIGRATE
:
3558 nt_status
= net_copy_file(local_state
->mem_ctx
,
3559 local_state
->cli_share_src
,
3560 local_state
->cli_share_dst
,
3562 opt_acls
? True
: False
,
3563 opt_attrs
? True
: False
,
3564 opt_timestamps
? True
: False
,
3568 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3572 if (!NT_STATUS_IS_OK(nt_status
))
3573 printf("could not handle file %s: %s\n",
3574 filename
, nt_errstr(nt_status
));
3579 * sync files, can be called recursivly to list files
3580 * and then call copy_fn for each file
3582 * @param cp_clistate pointer to the copy_clistate we work with
3583 * @param mask the current search mask
3585 * @return Boolean result
3587 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3589 struct cli_state
*targetcli
;
3590 char *targetpath
= NULL
;
3592 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3594 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate
->cli_share_src
,
3595 mask
, &targetcli
, &targetpath
) ) {
3596 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3597 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3601 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3602 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3603 mask
, cli_errstr(targetcli
));
3612 * Set the top level directory permissions before we do any further copies.
3613 * Should set up ACL inheritance.
3616 bool copy_top_level_perms(struct copy_clistate
*cp_clistate
,
3617 const char *sharename
)
3619 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3621 switch (net_mode_share
) {
3622 case NET_MODE_SHARE_MIGRATE
:
3623 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3624 nt_status
= net_copy_fileattr(cp_clistate
->mem_ctx
,
3625 cp_clistate
->cli_share_src
,
3626 cp_clistate
->cli_share_dst
,
3628 opt_acls
? True
: False
,
3629 opt_attrs
? True
: False
,
3630 opt_timestamps
? True
: False
,
3634 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3638 if (!NT_STATUS_IS_OK(nt_status
)) {
3639 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3640 sharename
, nt_errstr(nt_status
));
3648 * Sync all files inside a remote share to another share (over smb)
3650 * All parameters are provided by the run_rpc_command function, except for
3651 * argc, argv which are passes through.
3653 * @param domain_sid The domain sid acquired from the remote server
3654 * @param cli A cli_state connected to the server.
3655 * @param mem_ctx Talloc context, destoyed on completion of the function.
3656 * @param argc Standard main() style argc
3657 * @param argv Standard main() style argv. Initial components are already
3660 * @return Normal NTSTATUS return.
3663 static NTSTATUS
rpc_share_migrate_files_internals(const DOM_SID
*domain_sid
,
3664 const char *domain_name
,
3665 struct cli_state
*cli
,
3666 struct rpc_pipe_client
*pipe_hnd
,
3667 TALLOC_CTX
*mem_ctx
,
3672 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3673 struct srvsvc_NetShareInfoCtr ctr_src
;
3676 struct copy_clistate cp_clistate
;
3677 bool got_src_share
= False
;
3678 bool got_dst_share
= False
;
3679 const char *mask
= "\\*";
3682 dst
= SMB_STRDUP(opt_destination
?opt_destination
:"127.0.0.1");
3684 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3686 if (!W_ERROR_IS_OK(result
))
3689 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3691 struct srvsvc_NetShareInfo502 info502
=
3692 ctr_src
.ctr
.ctr502
->array
[i
];
3694 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3697 /* one might not want to mirror whole discs :) */
3698 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3699 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3703 switch (net_mode_share
)
3705 case NET_MODE_SHARE_MIGRATE
:
3709 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3712 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3714 opt_acls
? "including" : "without",
3715 opt_attrs
? "including" : "without",
3716 opt_timestamps
? "(preserving timestamps)" : "");
3718 cp_clistate
.mem_ctx
= mem_ctx
;
3719 cp_clistate
.cli_share_src
= NULL
;
3720 cp_clistate
.cli_share_dst
= NULL
;
3721 cp_clistate
.cwd
= NULL
;
3722 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3724 /* open share source */
3725 nt_status
= connect_to_service(&cp_clistate
.cli_share_src
,
3726 &cli
->dest_ss
, cli
->desthost
,
3727 info502
.name
, "A:");
3728 if (!NT_STATUS_IS_OK(nt_status
))
3731 got_src_share
= True
;
3733 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3734 /* open share destination */
3735 nt_status
= connect_to_service(&cp_clistate
.cli_share_dst
,
3736 NULL
, dst
, info502
.name
, "A:");
3737 if (!NT_STATUS_IS_OK(nt_status
))
3740 got_dst_share
= True
;
3743 if (!copy_top_level_perms(&cp_clistate
, info502
.name
)) {
3744 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3745 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3749 if (!sync_files(&cp_clistate
, mask
)) {
3750 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3751 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3756 nt_status
= NT_STATUS_OK
;
3761 cli_shutdown(cp_clistate
.cli_share_src
);
3764 cli_shutdown(cp_clistate
.cli_share_dst
);
3770 static int rpc_share_migrate_files(int argc
, const char **argv
)
3774 printf("no server to migrate\n");
3778 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3779 rpc_share_migrate_files_internals
,
3784 * Migrate share-ACLs from a remote RPC server to the local RPC srever
3786 * All parameters are provided by the run_rpc_command function, except for
3787 * argc, argv which are passes through.
3789 * @param domain_sid The domain sid acquired from the remote server
3790 * @param cli A cli_state connected to the server.
3791 * @param mem_ctx Talloc context, destoyed on completion of the function.
3792 * @param argc Standard main() style argc
3793 * @param argv Standard main() style argv. Initial components are already
3796 * @return Normal NTSTATUS return.
3799 static NTSTATUS
rpc_share_migrate_security_internals(const DOM_SID
*domain_sid
,
3800 const char *domain_name
,
3801 struct cli_state
*cli
,
3802 struct rpc_pipe_client
*pipe_hnd
,
3803 TALLOC_CTX
*mem_ctx
,
3808 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3809 struct srvsvc_NetShareInfoCtr ctr_src
;
3810 union srvsvc_NetShareInfo info
;
3812 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3813 struct cli_state
*cli_dst
= NULL
;
3814 uint32 level
= 502; /* includes secdesc */
3815 uint32_t parm_error
= 0;
3817 result
= get_share_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &ctr_src
);
3819 if (!W_ERROR_IS_OK(result
))
3822 /* connect destination PI_SRVSVC */
3823 nt_status
= connect_dst_pipe(&cli_dst
, &srvsvc_pipe
, PI_SRVSVC
);
3824 if (!NT_STATUS_IS_OK(nt_status
))
3828 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3830 struct srvsvc_NetShareInfo502 info502
=
3831 ctr_src
.ctr
.ctr502
->array
[i
];
3833 /* reset error-code */
3834 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3836 if (!check_share_sanity(cli
, info502
.name
, info502
.type
))
3839 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3840 info502
.name
, info502
.path
, info502
.comment
);
3843 display_sec_desc(info502
.sd_buf
.sd
);
3845 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3846 info
.info502
= &info502
;
3848 /* finally modify the share on the dst server */
3849 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3850 srvsvc_pipe
->cli
->desthost
,
3856 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3857 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3863 nt_status
= NT_STATUS_OK
;
3867 cli_shutdown(cli_dst
);
3875 * Migrate share-acls from a rpc-server to another
3877 * @param argc Standard main() style argc
3878 * @param argv Standard main() style argv. Initial components are already
3881 * @return A shell status integer (0 for success)
3883 static int rpc_share_migrate_security(int argc
, const char **argv
)
3887 printf("no server to migrate\n");
3891 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
3892 rpc_share_migrate_security_internals
,
3897 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3898 * from one server to another
3900 * @param argc Standard main() style argc
3901 * @param argv Standard main() style argv. Initial components are already
3904 * @return A shell status integer (0 for success)
3907 static int rpc_share_migrate_all(int argc
, const char **argv
)
3912 printf("no server to migrate\n");
3916 /* order is important. we don't want to be locked out by the share-acl
3917 * before copying files - gd */
3919 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_shares_internals
, argc
, argv
);
3923 ret
= run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_files_internals
, argc
, argv
);
3927 return run_rpc_command(NULL
, PI_SRVSVC
, 0, rpc_share_migrate_security_internals
, argc
, argv
);
3932 * 'net rpc share migrate' entrypoint.
3933 * @param argc Standard main() style argc
3934 * @param argv Standard main() style argv. Initial components are already
3937 static int rpc_share_migrate(int argc
, const char **argv
)
3940 struct functable func
[] = {
3941 {"all", rpc_share_migrate_all
},
3942 {"files", rpc_share_migrate_files
},
3943 {"help", rpc_share_usage
},
3944 {"security", rpc_share_migrate_security
},
3945 {"shares", rpc_share_migrate_shares
},
3949 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3951 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
3960 static int num_server_aliases
;
3961 static struct full_alias
*server_aliases
;
3964 * Add an alias to the static list.
3966 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3968 if (server_aliases
== NULL
)
3969 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3971 server_aliases
[num_server_aliases
] = *alias
;
3972 num_server_aliases
+= 1;
3976 * For a specific domain on the server, fetch all the aliases
3977 * and their members. Add all of them to the server_aliases.
3980 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3981 TALLOC_CTX
*mem_ctx
,
3982 POLICY_HND
*connect_pol
,
3983 const DOM_SID
*domain_sid
)
3985 uint32 start_idx
, max_entries
, num_entries
, i
;
3986 struct samr_SamArray
*groups
= NULL
;
3988 POLICY_HND domain_pol
;
3990 /* Get domain policy handle */
3992 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3994 MAXIMUM_ALLOWED_ACCESS
,
3995 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3997 if (!NT_STATUS_IS_OK(result
))
4004 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
4010 for (i
= 0; i
< num_entries
; i
++) {
4012 POLICY_HND alias_pol
;
4013 struct full_alias alias
;
4014 struct lsa_SidArray sid_array
;
4017 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
4019 MAXIMUM_ALLOWED_ACCESS
,
4020 groups
->entries
[i
].idx
,
4022 if (!NT_STATUS_IS_OK(result
))
4025 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
4028 if (!NT_STATUS_IS_OK(result
))
4031 alias
.num_members
= sid_array
.num_sids
;
4033 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
4034 if (!NT_STATUS_IS_OK(result
))
4037 alias
.members
= NULL
;
4039 if (alias
.num_members
> 0) {
4040 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
4042 for (j
= 0; j
< alias
.num_members
; j
++)
4043 sid_copy(&alias
.members
[j
],
4044 sid_array
.sids
[j
].sid
);
4047 sid_copy(&alias
.sid
, domain_sid
);
4048 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
4050 push_alias(mem_ctx
, &alias
);
4052 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
4054 result
= NT_STATUS_OK
;
4057 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
4063 * Dump server_aliases as names for debugging purposes.
4066 static NTSTATUS
rpc_aliaslist_dump(const DOM_SID
*domain_sid
,
4067 const char *domain_name
,
4068 struct cli_state
*cli
,
4069 struct rpc_pipe_client
*pipe_hnd
,
4070 TALLOC_CTX
*mem_ctx
,
4078 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, True
,
4079 SEC_RIGHTS_MAXIMUM_ALLOWED
,
4081 if (!NT_STATUS_IS_OK(result
))
4084 for (i
=0; i
<num_server_aliases
; i
++) {
4087 enum lsa_SidType
*types
;
4090 struct full_alias
*alias
= &server_aliases
[i
];
4092 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
4094 &domains
, &names
, &types
);
4095 if (!NT_STATUS_IS_OK(result
))
4098 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
4100 if (alias
->num_members
== 0) {
4105 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
4108 &domains
, &names
, &types
);
4110 if (!NT_STATUS_IS_OK(result
) &&
4111 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
4114 for (j
=0; j
<alias
->num_members
; j
++)
4115 DEBUG(1, ("%s\\%s (%d); ",
4116 domains
[j
] ? domains
[j
] : "*unknown*",
4117 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
4121 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
4123 return NT_STATUS_OK
;
4127 * Fetch a list of all server aliases and their members into
4131 static NTSTATUS
rpc_aliaslist_internals(const DOM_SID
*domain_sid
,
4132 const char *domain_name
,
4133 struct cli_state
*cli
,
4134 struct rpc_pipe_client
*pipe_hnd
,
4135 TALLOC_CTX
*mem_ctx
,
4140 POLICY_HND connect_pol
;
4142 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
4143 pipe_hnd
->cli
->desthost
,
4144 MAXIMUM_ALLOWED_ACCESS
,
4147 if (!NT_STATUS_IS_OK(result
))
4150 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4151 &global_sid_Builtin
);
4153 if (!NT_STATUS_IS_OK(result
))
4156 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
4159 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4164 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4166 token
->num_sids
= 4;
4168 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4169 d_fprintf(stderr
, "malloc failed\n");
4170 token
->num_sids
= 0;
4174 token
->user_sids
[0] = *user_sid
;
4175 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4176 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4177 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4180 static void free_user_token(NT_USER_TOKEN
*token
)
4182 SAFE_FREE(token
->user_sids
);
4185 static bool is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4189 for (i
=0; i
<token
->num_sids
; i
++) {
4190 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
4196 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4198 if (is_sid_in_token(token
, sid
))
4201 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4202 if (!token
->user_sids
) {
4206 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4208 token
->num_sids
+= 1;
4213 NT_USER_TOKEN token
;
4216 static void dump_user_token(struct user_token
*token
)
4220 d_printf("%s\n", token
->name
);
4222 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4223 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4227 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4231 for (i
=0; i
<alias
->num_members
; i
++) {
4232 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4239 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4243 for (i
=0; i
<num_server_aliases
; i
++) {
4244 if (is_alias_member(&sid
, &server_aliases
[i
]))
4245 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4250 * We got a user token with all the SIDs we can know about without asking the
4251 * server directly. These are the user and domain group sids. All of these can
4252 * be members of aliases. So scan the list of aliases for each of the SIDs and
4253 * add them to the token.
4256 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4258 int num_global_sids
= token
->num_sids
;
4261 for (i
=0; i
<num_global_sids
; i
++) {
4262 collect_sid_memberships(token
, token
->user_sids
[i
]);
4266 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4268 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4269 enum wbcSidType type
;
4271 struct wbcDomainSid wsid
;
4272 char *sid_str
= NULL
;
4274 uint32_t num_groups
;
4275 gid_t
*groups
= NULL
;
4278 fstr_sprintf(full_name
, "%s%c%s",
4279 domain
, *lp_winbind_separator(), user
);
4281 /* First let's find out the user sid */
4283 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4285 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4286 DEBUG(1, ("winbind could not find %s: %s\n",
4287 full_name
, wbcErrorString(wbc_status
)));
4291 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4292 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4296 if (type
!= SID_NAME_USER
) {
4297 wbcFreeMemory(sid_str
);
4298 DEBUG(1, ("%s is not a user\n", full_name
));
4302 string_to_sid(&user_sid
, sid_str
);
4303 wbcFreeMemory(sid_str
);
4306 init_user_token(token
, &user_sid
);
4308 /* And now the groups winbind knows about */
4310 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4311 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4312 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4313 full_name
, wbcErrorString(wbc_status
)));
4317 for (i
= 0; i
< num_groups
; i
++) {
4318 gid_t gid
= groups
[i
];
4321 wbc_status
= wbcGidToSid(gid
, &wsid
);
4322 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4323 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4324 gid
, wbcErrorString(wbc_status
)));
4325 wbcFreeMemory(groups
);
4329 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4330 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4331 wbcFreeMemory(groups
);
4335 DEBUG(3, (" %s\n", sid_str
));
4337 string_to_sid(&sid
, sid_str
);
4338 wbcFreeMemory(sid_str
);
4341 add_sid_to_token(token
, &sid
);
4343 wbcFreeMemory(groups
);
4349 * Get a list of all user tokens we want to look at
4352 static bool get_user_tokens(int *num_tokens
, struct user_token
**user_tokens
)
4354 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4355 uint32_t i
, num_users
;
4357 struct user_token
*result
;
4358 TALLOC_CTX
*frame
= NULL
;
4360 if (lp_winbind_use_default_domain() &&
4361 (opt_target_workgroup
== NULL
)) {
4362 d_fprintf(stderr
, "winbind use default domain = yes set, "
4363 "please specify a workgroup\n");
4367 /* Send request to winbind daemon */
4369 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4370 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4371 DEBUG(1, ("winbind could not list users: %s\n",
4372 wbcErrorString(wbc_status
)));
4376 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4378 if (result
== NULL
) {
4379 DEBUG(1, ("Could not malloc sid array\n"));
4380 wbcFreeMemory(users
);
4384 frame
= talloc_stackframe();
4385 for (i
=0; i
< num_users
; i
++) {
4386 fstring domain
, user
;
4389 fstrcpy(result
[i
].name
, users
[i
]);
4391 p
= strchr(users
[i
], *lp_winbind_separator());
4393 DEBUG(3, ("%s\n", users
[i
]));
4396 fstrcpy(domain
, opt_target_workgroup
);
4397 fstrcpy(user
, users
[i
]);
4400 fstrcpy(domain
, users
[i
]);
4405 get_user_sids(domain
, user
, &(result
[i
].token
));
4409 wbcFreeMemory(users
);
4411 *num_tokens
= num_users
;
4412 *user_tokens
= result
;
4417 static bool get_user_tokens_from_file(FILE *f
,
4419 struct user_token
**tokens
)
4421 struct user_token
*token
= NULL
;
4426 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4430 if (line
[strlen(line
)-1] == '\n')
4431 line
[strlen(line
)-1] = '\0';
4433 if (line
[0] == ' ') {
4437 string_to_sid(&sid
, &line
[1]);
4439 if (token
== NULL
) {
4440 DEBUG(0, ("File does not begin with username"));
4444 add_sid_to_token(&token
->token
, &sid
);
4448 /* And a new user... */
4451 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4452 if (*tokens
== NULL
) {
4453 DEBUG(0, ("Could not realloc tokens\n"));
4457 token
= &((*tokens
)[*num_tokens
-1]);
4459 fstrcpy(token
->name
, line
);
4460 token
->token
.num_sids
= 0;
4461 token
->token
.user_sids
= NULL
;
4470 * Show the list of all users that have access to a share
4473 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4474 TALLOC_CTX
*mem_ctx
,
4475 const char *netname
,
4477 struct user_token
*tokens
)
4480 SEC_DESC
*share_sd
= NULL
;
4481 SEC_DESC
*root_sd
= NULL
;
4482 struct cli_state
*cli
= pipe_hnd
->cli
;
4484 union srvsvc_NetShareInfo info
;
4489 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4490 pipe_hnd
->cli
->desthost
,
4496 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4497 DEBUG(1, ("Coult not query secdesc for share %s\n",
4502 share_sd
= info
.info502
->sd_buf
.sd
;
4503 if (share_sd
== NULL
) {
4504 DEBUG(1, ("Got no secdesc for share %s\n",
4510 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4514 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4517 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4520 for (i
=0; i
<num_tokens
; i
++) {
4523 if (share_sd
!= NULL
) {
4524 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4525 1, &acc_granted
, &status
)) {
4526 DEBUG(1, ("Could not check share_sd for "
4532 if (!NT_STATUS_IS_OK(status
))
4536 if (root_sd
== NULL
) {
4537 d_printf(" %s\n", tokens
[i
].name
);
4541 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4542 1, &acc_granted
, &status
)) {
4543 DEBUG(1, ("Could not check root_sd for user %s\n",
4548 if (!NT_STATUS_IS_OK(status
))
4551 d_printf(" %s\n", tokens
[i
].name
);
4555 cli_close(cli
, fnum
);
4567 static void collect_share(const char *name
, uint32 m
,
4568 const char *comment
, void *state
)
4570 struct share_list
*share_list
= (struct share_list
*)state
;
4572 if (m
!= STYPE_DISKTREE
)
4575 share_list
->num_shares
+= 1;
4576 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4577 if (!share_list
->shares
) {
4578 share_list
->num_shares
= 0;
4581 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4584 static void rpc_share_userlist_usage(void)
4590 * List shares on a remote RPC server, including the security descriptors
4592 * All parameters are provided by the run_rpc_command function, except for
4593 * argc, argv which are passes through.
4595 * @param domain_sid The domain sid acquired from the remote server
4596 * @param cli A cli_state connected to the server.
4597 * @param mem_ctx Talloc context, destoyed on completion of the function.
4598 * @param argc Standard main() style argc
4599 * @param argv Standard main() style argv. Initial components are already
4602 * @return Normal NTSTATUS return.
4605 static NTSTATUS
rpc_share_allowedusers_internals(const DOM_SID
*domain_sid
,
4606 const char *domain_name
,
4607 struct cli_state
*cli
,
4608 struct rpc_pipe_client
*pipe_hnd
,
4609 TALLOC_CTX
*mem_ctx
,
4619 struct user_token
*tokens
= NULL
;
4622 struct share_list share_list
;
4625 rpc_share_userlist_usage();
4626 return NT_STATUS_UNSUCCESSFUL
;
4632 f
= fopen(argv
[0], "r");
4636 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4637 return NT_STATUS_UNSUCCESSFUL
;
4640 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4646 DEBUG(0, ("Could not read users from file\n"));
4647 return NT_STATUS_UNSUCCESSFUL
;
4650 for (i
=0; i
<num_tokens
; i
++)
4651 collect_alias_memberships(&tokens
[i
].token
);
4653 init_enum_hnd(&hnd
, 0);
4655 share_list
.num_shares
= 0;
4656 share_list
.shares
= NULL
;
4658 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4661 DEBUG(0, ("Error returning browse list: %s\n",
4666 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4667 char *netname
= share_list
.shares
[i
];
4669 if (netname
[strlen(netname
)-1] == '$')
4672 d_printf("%s\n", netname
);
4674 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4675 num_tokens
, tokens
);
4678 for (i
=0; i
<num_tokens
; i
++) {
4679 free_user_token(&tokens
[i
].token
);
4682 SAFE_FREE(share_list
.shares
);
4684 return NT_STATUS_OK
;
4687 static int rpc_share_allowedusers(int argc
, const char **argv
)
4691 result
= run_rpc_command(NULL
, PI_SAMR
, 0,
4692 rpc_aliaslist_internals
,
4697 result
= run_rpc_command(NULL
, PI_LSARPC
, 0,
4703 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4704 rpc_share_allowedusers_internals
,
4708 int net_usersidlist(int argc
, const char **argv
)
4711 struct user_token
*tokens
= NULL
;
4715 net_usersidlist_usage(argc
, argv
);
4719 if (!get_user_tokens(&num_tokens
, &tokens
)) {
4720 DEBUG(0, ("Could not get the user/sid list\n"));
4724 for (i
=0; i
<num_tokens
; i
++) {
4725 dump_user_token(&tokens
[i
]);
4726 free_user_token(&tokens
[i
].token
);
4733 int net_usersidlist_usage(int argc
, const char **argv
)
4735 d_printf("net usersidlist\n"
4736 "\tprints out a list of all users the running winbind knows\n"
4737 "\tabout, together with all their SIDs. This is used as\n"
4738 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4740 net_common_flags_usage(argc
, argv
);
4745 * 'net rpc share' entrypoint.
4746 * @param argc Standard main() style argc
4747 * @param argv Standard main() style argv. Initial components are already
4751 int net_rpc_share(int argc
, const char **argv
)
4753 struct functable func
[] = {
4754 {"add", rpc_share_add
},
4755 {"delete", rpc_share_delete
},
4756 {"allowedusers", rpc_share_allowedusers
},
4757 {"migrate", rpc_share_migrate
},
4758 {"list", rpc_share_list
},
4763 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4764 rpc_share_list_internals
,
4767 return net_run_function(argc
, argv
, func
, rpc_share_usage
);
4770 static NTSTATUS
rpc_sh_share_list(TALLOC_CTX
*mem_ctx
,
4771 struct rpc_sh_ctx
*ctx
,
4772 struct rpc_pipe_client
*pipe_hnd
,
4773 int argc
, const char **argv
)
4775 return rpc_share_list_internals(ctx
->domain_sid
, ctx
->domain_name
,
4776 ctx
->cli
, pipe_hnd
, mem_ctx
,
4780 static NTSTATUS
rpc_sh_share_add(TALLOC_CTX
*mem_ctx
,
4781 struct rpc_sh_ctx
*ctx
,
4782 struct rpc_pipe_client
*pipe_hnd
,
4783 int argc
, const char **argv
)
4787 uint32_t parm_err
= 0;
4788 union srvsvc_NetShareInfo info
;
4789 struct srvsvc_NetShareInfo2 info2
;
4791 if ((argc
< 2) || (argc
> 3)) {
4792 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4794 return NT_STATUS_INVALID_PARAMETER
;
4797 info2
.name
= argv
[0];
4798 info2
.type
= STYPE_DISKTREE
;
4799 info2
.comment
= (argc
== 3) ? argv
[2] : "";
4800 info2
.permissions
= 0;
4801 info2
.max_users
= 0;
4802 info2
.current_users
= 0;
4803 info2
.path
= argv
[1];
4804 info2
.password
= NULL
;
4806 info
.info2
= &info2
;
4808 status
= rpccli_srvsvc_NetShareAdd(pipe_hnd
, mem_ctx
,
4809 pipe_hnd
->cli
->desthost
,
4818 static NTSTATUS
rpc_sh_share_delete(TALLOC_CTX
*mem_ctx
,
4819 struct rpc_sh_ctx
*ctx
,
4820 struct rpc_pipe_client
*pipe_hnd
,
4821 int argc
, const char **argv
)
4827 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4828 return NT_STATUS_INVALID_PARAMETER
;
4831 status
= rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
4832 pipe_hnd
->cli
->desthost
,
4840 static NTSTATUS
rpc_sh_share_info(TALLOC_CTX
*mem_ctx
,
4841 struct rpc_sh_ctx
*ctx
,
4842 struct rpc_pipe_client
*pipe_hnd
,
4843 int argc
, const char **argv
)
4845 union srvsvc_NetShareInfo info
;
4850 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4851 return NT_STATUS_INVALID_PARAMETER
;
4854 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4855 pipe_hnd
->cli
->desthost
,
4860 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4864 d_printf("Name: %s\n", info
.info2
->name
);
4865 d_printf("Comment: %s\n", info
.info2
->comment
);
4866 d_printf("Path: %s\n", info
.info2
->path
);
4867 d_printf("Password: %s\n", info
.info2
->password
);
4870 return werror_to_ntstatus(result
);
4873 struct rpc_sh_cmd
*net_rpc_share_cmds(TALLOC_CTX
*mem_ctx
,
4874 struct rpc_sh_ctx
*ctx
)
4876 static struct rpc_sh_cmd cmds
[] = {
4878 { "list", NULL
, PI_SRVSVC
, rpc_sh_share_list
,
4879 "List available shares" },
4881 { "add", NULL
, PI_SRVSVC
, rpc_sh_share_add
,
4884 { "delete", NULL
, PI_SRVSVC
, rpc_sh_share_delete
,
4887 { "info", NULL
, PI_SRVSVC
, rpc_sh_share_info
,
4888 "Get information about a share" },
4890 { NULL
, NULL
, 0, NULL
, NULL
}
4896 /****************************************************************************/
4898 static int rpc_file_usage(int argc
, const char **argv
)
4900 return net_help_file(argc
, argv
);
4904 * Close a file on a remote RPC server
4906 * All parameters are provided by the run_rpc_command function, except for
4907 * argc, argv which are passes through.
4909 * @param domain_sid The domain sid acquired from the remote server
4910 * @param cli A cli_state connected to the server.
4911 * @param mem_ctx Talloc context, destoyed on completion of the function.
4912 * @param argc Standard main() style argc
4913 * @param argv Standard main() style argv. Initial components are already
4916 * @return Normal NTSTATUS return.
4918 static NTSTATUS
rpc_file_close_internals(const DOM_SID
*domain_sid
,
4919 const char *domain_name
,
4920 struct cli_state
*cli
,
4921 struct rpc_pipe_client
*pipe_hnd
,
4922 TALLOC_CTX
*mem_ctx
,
4926 return rpccli_srvsvc_NetFileClose(pipe_hnd
, mem_ctx
,
4927 pipe_hnd
->cli
->desthost
,
4928 atoi(argv
[0]), NULL
);
4932 * Close a file on a remote RPC server
4934 * @param argc Standard main() style argc
4935 * @param argv Standard main() style argv. Initial components are already
4938 * @return A shell status integer (0 for success)
4940 static int rpc_file_close(int argc
, const char **argv
)
4943 DEBUG(1, ("No fileid given on close\n"));
4944 return(rpc_file_usage(argc
, argv
));
4947 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
4948 rpc_file_close_internals
,
4953 * Formatted print of open file info
4955 * @param r struct srvsvc_NetFileInfo3 contents
4958 static void display_file_info_3(struct srvsvc_NetFileInfo3
*r
)
4960 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4961 r
->fid
, r
->user
, r
->permissions
, r
->num_locks
, r
->path
);
4965 * List open files on a remote RPC server
4967 * All parameters are provided by the run_rpc_command function, except for
4968 * argc, argv which are passes through.
4970 * @param domain_sid The domain sid acquired from the remote server
4971 * @param cli A cli_state connected to the server.
4972 * @param mem_ctx Talloc context, destoyed on completion of the function.
4973 * @param argc Standard main() style argc
4974 * @param argv Standard main() style argv. Initial components are already
4977 * @return Normal NTSTATUS return.
4980 static NTSTATUS
rpc_file_list_internals(const DOM_SID
*domain_sid
,
4981 const char *domain_name
,
4982 struct cli_state
*cli
,
4983 struct rpc_pipe_client
*pipe_hnd
,
4984 TALLOC_CTX
*mem_ctx
,
4988 struct srvsvc_NetFileInfoCtr info_ctr
;
4989 struct srvsvc_NetFileCtr3 ctr3
;
4992 uint32 preferred_len
= 0xffffffff, i
;
4993 const char *username
=NULL
;
4994 uint32_t total_entries
= 0;
4995 uint32_t resume_handle
= 0;
4997 /* if argc > 0, must be user command */
4999 username
= smb_xstrdup(argv
[0]);
5001 ZERO_STRUCT(info_ctr
);
5005 info_ctr
.ctr
.ctr3
= &ctr3
;
5007 status
= rpccli_srvsvc_NetFileEnum(pipe_hnd
, mem_ctx
,
5008 pipe_hnd
->cli
->desthost
,
5017 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
5020 /* Display results */
5023 "\nEnumerating open files on remote server:\n\n"\
5024 "\nFileId Opened by Perms Locks Path"\
5025 "\n------ --------- ----- ----- ---- \n");
5026 for (i
= 0; i
< total_entries
; i
++)
5027 display_file_info_3(&info_ctr
.ctr
.ctr3
->array
[i
]);
5029 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
5033 * List files for a user on a remote RPC server
5035 * @param argc Standard main() style argc
5036 * @param argv Standard main() style argv. Initial components are already
5039 * @return A shell status integer (0 for success)
5042 static int rpc_file_user(int argc
, const char **argv
)
5045 DEBUG(1, ("No username given\n"));
5046 return(rpc_file_usage(argc
, argv
));
5049 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5050 rpc_file_list_internals
,
5055 * 'net rpc file' entrypoint.
5056 * @param argc Standard main() style argc
5057 * @param argv Standard main() style argv. Initial components are already
5061 int net_rpc_file(int argc
, const char **argv
)
5063 struct functable func
[] = {
5064 {"close", rpc_file_close
},
5065 {"user", rpc_file_user
},
5067 {"info", rpc_file_info
},
5073 return run_rpc_command(NULL
, PI_SRVSVC
, 0,
5074 rpc_file_list_internals
,
5077 return net_run_function(argc
, argv
, func
, rpc_file_usage
);
5081 * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
5083 * All parameters are provided by the run_rpc_command function, except for
5084 * argc, argv which are passed through.
5086 * @param domain_sid The domain sid aquired from the remote server
5087 * @param cli A cli_state connected to the server.
5088 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5089 * @param argc Standard main() style argc
5090 * @param argv Standard main() style argv. Initial components are already
5093 * @return Normal NTSTATUS return.
5096 static NTSTATUS
rpc_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5097 const char *domain_name
,
5098 struct cli_state
*cli
,
5099 struct rpc_pipe_client
*pipe_hnd
,
5100 TALLOC_CTX
*mem_ctx
,
5104 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5106 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5108 if (NT_STATUS_IS_OK(result
)) {
5109 d_printf("\nShutdown successfully aborted\n");
5110 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5112 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5118 * ABORT the shutdown of a remote RPC Server, over winreg pipe
5120 * All parameters are provided by the run_rpc_command function, except for
5121 * argc, argv which are passed through.
5123 * @param domain_sid The domain sid aquired from the remote server
5124 * @param cli A cli_state connected to the server.
5125 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5126 * @param argc Standard main() style argc
5127 * @param argv Standard main() style argv. Initial components are already
5130 * @return Normal NTSTATUS return.
5133 static NTSTATUS
rpc_reg_shutdown_abort_internals(const DOM_SID
*domain_sid
,
5134 const char *domain_name
,
5135 struct cli_state
*cli
,
5136 struct rpc_pipe_client
*pipe_hnd
,
5137 TALLOC_CTX
*mem_ctx
,
5141 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5143 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5145 if (NT_STATUS_IS_OK(result
)) {
5146 d_printf("\nShutdown successfully aborted\n");
5147 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5149 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5155 * ABORT the Shut down of a remote RPC server
5157 * @param argc Standard main() style argc
5158 * @param argv Standard main() style argv. Initial components are already
5161 * @return A shell status integer (0 for success)
5164 static int rpc_shutdown_abort(int argc
, const char **argv
)
5166 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5167 rpc_shutdown_abort_internals
,
5173 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5175 return run_rpc_command(NULL
, PI_WINREG
, 0,
5176 rpc_reg_shutdown_abort_internals
,
5181 * Shut down a remote RPC Server via initshutdown pipe
5183 * All parameters are provided by the run_rpc_command function, except for
5184 * argc, argv which are passes through.
5186 * @param domain_sid The domain sid aquired from the remote server
5187 * @param cli A cli_state connected to the server.
5188 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5189 * @param argc Standard main() style argc
5190 * @param argc Standard main() style argv. Initial components are already
5193 * @return Normal NTSTATUS return.
5196 NTSTATUS
rpc_init_shutdown_internals(const DOM_SID
*domain_sid
,
5197 const char *domain_name
,
5198 struct cli_state
*cli
,
5199 struct rpc_pipe_client
*pipe_hnd
,
5200 TALLOC_CTX
*mem_ctx
,
5204 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5205 const char *msg
= "This machine will be shutdown shortly";
5206 uint32 timeout
= 20;
5207 struct initshutdown_String msg_string
;
5208 struct initshutdown_String_sub s
;
5214 timeout
= opt_timeout
;
5218 msg_string
.name
= &s
;
5220 /* create an entry */
5221 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5222 &msg_string
, timeout
, opt_force
, opt_reboot
, NULL
);
5224 if (NT_STATUS_IS_OK(result
)) {
5225 d_printf("\nShutdown of remote machine succeeded\n");
5226 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5228 DEBUG(1,("Shutdown of remote machine failed!\n"));
5234 * Shut down a remote RPC Server via winreg pipe
5236 * All parameters are provided by the run_rpc_command function, except for
5237 * argc, argv which are passes through.
5239 * @param domain_sid The domain sid aquired from the remote server
5240 * @param cli A cli_state connected to the server.
5241 * @param mem_ctx Talloc context, destoyed on compleation of the function.
5242 * @param argc Standard main() style argc
5243 * @param argc Standard main() style argv. Initial components are already
5246 * @return Normal NTSTATUS return.
5249 NTSTATUS
rpc_reg_shutdown_internals(const DOM_SID
*domain_sid
,
5250 const char *domain_name
,
5251 struct cli_state
*cli
,
5252 struct rpc_pipe_client
*pipe_hnd
,
5253 TALLOC_CTX
*mem_ctx
,
5257 const char *msg
= "This machine will be shutdown shortly";
5258 uint32 timeout
= 20;
5259 struct initshutdown_String msg_string
;
5260 struct initshutdown_String_sub s
;
5268 msg_string
.name
= &s
;
5271 timeout
= opt_timeout
;
5274 /* create an entry */
5275 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5276 &msg_string
, timeout
, opt_force
, opt_reboot
, &werr
);
5278 if (NT_STATUS_IS_OK(result
)) {
5279 d_printf("\nShutdown of remote machine succeeded\n");
5281 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5282 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5283 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5285 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(werr
));
5292 * Shut down a remote RPC server
5294 * @param argc Standard main() style argc
5295 * @param argc Standard main() style argv. Initial components are already
5298 * @return A shell status integer (0 for success)
5301 static int rpc_shutdown(int argc
, const char **argv
)
5303 int rc
= run_rpc_command(NULL
, PI_INITSHUTDOWN
, 0,
5304 rpc_init_shutdown_internals
,
5308 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5309 rc
= run_rpc_command(NULL
, PI_WINREG
, 0,
5310 rpc_reg_shutdown_internals
, argc
, argv
);
5316 /***************************************************************************
5317 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5319 ***************************************************************************/
5322 * Add interdomain trust account to the RPC server.
5323 * All parameters (except for argc and argv) are passed by run_rpc_command
5326 * @param domain_sid The domain sid acquired from the server
5327 * @param cli A cli_state connected to the server.
5328 * @param mem_ctx Talloc context, destoyed on completion of the function.
5329 * @param argc Standard main() style argc
5330 * @param argc Standard main() style argv. Initial components are already
5333 * @return normal NTSTATUS return code
5336 static NTSTATUS
rpc_trustdom_add_internals(const DOM_SID
*domain_sid
,
5337 const char *domain_name
,
5338 struct cli_state
*cli
,
5339 struct rpc_pipe_client
*pipe_hnd
,
5340 TALLOC_CTX
*mem_ctx
,
5344 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5345 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5347 struct lsa_String lsa_acct_name
;
5349 uint32 acct_flags
=0;
5351 uint32_t access_granted
= 0;
5352 union samr_UserInfo info
;
5355 d_printf("Usage: net rpc trustdom add <domain_name> <pw>\n");
5356 return NT_STATUS_INVALID_PARAMETER
;
5360 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5363 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5364 return NT_STATUS_NO_MEMORY
;
5367 strupper_m(acct_name
);
5369 init_lsa_String(&lsa_acct_name
, acct_name
);
5371 /* Get samr policy handle */
5372 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5373 pipe_hnd
->cli
->desthost
,
5374 MAXIMUM_ALLOWED_ACCESS
,
5376 if (!NT_STATUS_IS_OK(result
)) {
5380 /* Get domain policy handle */
5381 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5383 MAXIMUM_ALLOWED_ACCESS
,
5384 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5386 if (!NT_STATUS_IS_OK(result
)) {
5390 /* Create trusting domain's account */
5391 acb_info
= ACB_NORMAL
;
5392 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5393 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5394 SAMR_USER_ACCESS_SET_PASSWORD
|
5395 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5396 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5398 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5406 if (!NT_STATUS_IS_OK(result
)) {
5412 struct samr_LogonHours hours
;
5413 struct lsa_BinaryString parameters
;
5414 const int units_per_week
= 168;
5417 encode_pw_buffer(pwbuf
, argv
[1], STR_UNICODE
);
5419 ZERO_STRUCT(notime
);
5421 ZERO_STRUCT(parameters
);
5423 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
5425 result
= NT_STATUS_NO_MEMORY
;
5428 hours
.units_per_week
= units_per_week
;
5429 memset(hours
.bits
, 0xFF, units_per_week
);
5431 init_samr_user_info23(&info
.info23
,
5432 notime
, notime
, notime
,
5433 notime
, notime
, notime
,
5434 NULL
, NULL
, NULL
, NULL
, NULL
,
5435 NULL
, NULL
, NULL
, NULL
, ¶meters
,
5436 0, 0, ACB_DOMTRUST
, SAMR_FIELD_ACCT_FLAGS
,
5438 0, 0, 0, 0, 0, 0, 0,
5441 SamOEMhashBlob(info
.info23
.password
.data
, 516,
5442 &cli
->user_session_key
);
5444 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5449 if (!NT_STATUS_IS_OK(result
)) {
5450 DEBUG(0,("Could not set trust account password: %s\n",
5451 nt_errstr(result
)));
5457 SAFE_FREE(acct_name
);
5462 * Create interdomain trust account for a remote domain.
5464 * @param argc standard argc
5465 * @param argv standard argv without initial components
5467 * @return Integer status (0 means success)
5470 static int rpc_trustdom_add(int argc
, const char **argv
)
5473 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_add_internals
,
5476 d_printf("Usage: net rpc trustdom add <domain>\n");
5483 * Remove interdomain trust account from the RPC server.
5484 * All parameters (except for argc and argv) are passed by run_rpc_command
5487 * @param domain_sid The domain sid acquired from the server
5488 * @param cli A cli_state connected to the server.
5489 * @param mem_ctx Talloc context, destoyed on completion of the function.
5490 * @param argc Standard main() style argc
5491 * @param argc Standard main() style argv. Initial components are already
5494 * @return normal NTSTATUS return code
5497 static NTSTATUS
rpc_trustdom_del_internals(const DOM_SID
*domain_sid
,
5498 const char *domain_name
,
5499 struct cli_state
*cli
,
5500 struct rpc_pipe_client
*pipe_hnd
,
5501 TALLOC_CTX
*mem_ctx
,
5505 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5506 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5508 DOM_SID trust_acct_sid
;
5509 struct samr_Ids user_rids
, name_types
;
5510 struct lsa_String lsa_acct_name
;
5513 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5514 return NT_STATUS_INVALID_PARAMETER
;
5518 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5520 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5522 if (acct_name
== NULL
)
5523 return NT_STATUS_NO_MEMORY
;
5525 strupper_m(acct_name
);
5527 /* Get samr policy handle */
5528 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5529 pipe_hnd
->cli
->desthost
,
5530 MAXIMUM_ALLOWED_ACCESS
,
5532 if (!NT_STATUS_IS_OK(result
)) {
5536 /* Get domain policy handle */
5537 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5539 MAXIMUM_ALLOWED_ACCESS
,
5540 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5542 if (!NT_STATUS_IS_OK(result
)) {
5546 init_lsa_String(&lsa_acct_name
, acct_name
);
5548 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5555 if (!NT_STATUS_IS_OK(result
)) {
5559 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5561 MAXIMUM_ALLOWED_ACCESS
,
5565 if (!NT_STATUS_IS_OK(result
)) {
5569 /* append the rid to the domain sid */
5570 sid_copy(&trust_acct_sid
, domain_sid
);
5571 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5575 /* remove the sid */
5577 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5580 if (!NT_STATUS_IS_OK(result
)) {
5586 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5589 if (!NT_STATUS_IS_OK(result
)) {
5593 if (!NT_STATUS_IS_OK(result
)) {
5594 DEBUG(0,("Could not set trust account password: %s\n",
5595 nt_errstr(result
)));
5604 * Delete interdomain trust account for a remote domain.
5606 * @param argc standard argc
5607 * @param argv standard argv without initial components
5609 * @return Integer status (0 means success)
5612 static int rpc_trustdom_del(int argc
, const char **argv
)
5615 return run_rpc_command(NULL
, PI_SAMR
, 0, rpc_trustdom_del_internals
,
5618 d_printf("Usage: net rpc trustdom del <domain>\n");
5623 static NTSTATUS
rpc_trustdom_get_pdc(struct cli_state
*cli
,
5624 TALLOC_CTX
*mem_ctx
,
5625 const char *domain_name
)
5627 char *dc_name
= NULL
;
5628 const char *buffer
= NULL
;
5629 struct rpc_pipe_client
*netr
;
5632 /* Use NetServerEnum2 */
5634 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5636 return NT_STATUS_OK
;
5639 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5640 for domain %s\n", domain_name
));
5642 /* Try netr_GetDcName */
5644 netr
= cli_rpc_pipe_open_noauth(cli
, PI_NETLOGON
, &status
);
5649 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5654 cli_rpc_pipe_close(netr
);
5656 if (NT_STATUS_IS_OK(status
)) {
5660 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5661 for domain %s\n", domain_name
));
5667 * Establish trust relationship to a trusting domain.
5668 * Interdomain account must already be created on remote PDC.
5670 * @param argc standard argc
5671 * @param argv standard argv without initial components
5673 * @return Integer status (0 means success)
5676 static int rpc_trustdom_establish(int argc
, const char **argv
)
5678 struct cli_state
*cli
= NULL
;
5679 struct sockaddr_storage server_ss
;
5680 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5681 POLICY_HND connect_hnd
;
5682 TALLOC_CTX
*mem_ctx
;
5684 DOM_SID
*domain_sid
;
5689 union lsa_PolicyInformation
*info
= NULL
;
5692 * Connect to \\server\ipc$ as 'our domain' account with password
5696 d_printf("Usage: net rpc trustdom establish <domain_name>\n");
5700 domain_name
= smb_xstrdup(argv
[0]);
5701 strupper_m(domain_name
);
5703 /* account name used at first is our domain's name with '$' */
5704 asprintf(&acct_name
, "%s$", lp_workgroup());
5705 strupper_m(acct_name
);
5708 * opt_workgroup will be used by connection functions further,
5709 * hence it should be set to remote domain name instead of ours
5711 if (opt_workgroup
) {
5712 opt_workgroup
= smb_xstrdup(domain_name
);
5715 opt_user_name
= acct_name
;
5717 /* find the domain controller */
5718 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5719 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5723 /* connect to ipc$ as username/password */
5724 nt_status
= connect_to_ipc(&cli
, &server_ss
, pdc_name
);
5725 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5727 /* Is it trusting domain account for sure ? */
5728 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5729 nt_errstr(nt_status
)));
5733 /* store who we connected to */
5735 saf_store( domain_name
, pdc_name
);
5738 * Connect to \\server\ipc$ again (this time anonymously)
5741 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ss
, (char*)pdc_name
);
5743 if (NT_STATUS_IS_ERR(nt_status
)) {
5744 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5745 domain_name
, nt_errstr(nt_status
)));
5749 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5750 "domain %s", domain_name
))) {
5751 DEBUG(0, ("talloc_init() failed\n"));
5756 /* Make sure we're talking to a proper server */
5758 nt_status
= rpc_trustdom_get_pdc(cli
, mem_ctx
, domain_name
);
5759 if (!NT_STATUS_IS_OK(nt_status
)) {
5761 talloc_destroy(mem_ctx
);
5766 * Call LsaOpenPolicy and LsaQueryInfo
5769 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
5771 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5773 talloc_destroy(mem_ctx
);
5777 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, True
, SEC_RIGHTS_QUERY_VALUE
,
5779 if (NT_STATUS_IS_ERR(nt_status
)) {
5780 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5781 nt_errstr(nt_status
)));
5783 talloc_destroy(mem_ctx
);
5787 /* Querying info level 5 */
5789 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5791 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5793 if (NT_STATUS_IS_ERR(nt_status
)) {
5794 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5795 nt_errstr(nt_status
)));
5797 talloc_destroy(mem_ctx
);
5801 domain_sid
= info
->account_domain
.sid
;
5803 /* There should be actually query info level 3 (following nt serv behaviour),
5804 but I still don't know if it's _really_ necessary */
5807 * Store the password in secrets db
5810 if (!pdb_set_trusteddom_pw(domain_name
, opt_password
, domain_sid
)) {
5811 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5813 talloc_destroy(mem_ctx
);
5818 * Close the pipes and clean up
5821 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5822 if (NT_STATUS_IS_ERR(nt_status
)) {
5823 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5824 nt_errstr(nt_status
)));
5826 talloc_destroy(mem_ctx
);
5832 talloc_destroy(mem_ctx
);
5834 d_printf("Trust to domain %s established\n", domain_name
);
5839 * Revoke trust relationship to the remote domain
5841 * @param argc standard argc
5842 * @param argv standard argv without initial components
5844 * @return Integer status (0 means success)
5847 static int rpc_trustdom_revoke(int argc
, const char **argv
)
5852 if (argc
< 1) return -1;
5854 /* generate upper cased domain name */
5855 domain_name
= smb_xstrdup(argv
[0]);
5856 strupper_m(domain_name
);
5858 /* delete password of the trust */
5859 if (!pdb_del_trusteddom_pw(domain_name
)) {
5860 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5867 SAFE_FREE(domain_name
);
5872 * Usage for 'net rpc trustdom' command
5874 * @param argc standard argc
5875 * @param argv standard argv without inital components
5877 * @return Integer status returned to shell
5880 static int rpc_trustdom_usage(int argc
, const char **argv
)
5882 d_printf(" net rpc trustdom add \t\t add trusting domain's account\n");
5883 d_printf(" net rpc trustdom del \t\t delete trusting domain's account\n");
5884 d_printf(" net rpc trustdom establish \t establish relationship to trusted domain\n");
5885 d_printf(" net rpc trustdom revoke \t abandon relationship to trusted domain\n");
5886 d_printf(" net rpc trustdom list \t show current interdomain trust relationships\n");
5887 d_printf(" net rpc trustdom vampire \t vampire interdomain trust relationships from remote server\n");
5892 static NTSTATUS
rpc_query_domain_sid(const DOM_SID
*domain_sid
,
5893 const char *domain_name
,
5894 struct cli_state
*cli
,
5895 struct rpc_pipe_client
*pipe_hnd
,
5896 TALLOC_CTX
*mem_ctx
,
5901 sid_to_fstring(str_sid
, domain_sid
);
5902 d_printf("%s\n", str_sid
);
5903 return NT_STATUS_OK
;
5906 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5908 fstring ascii_sid
, padding
;
5909 int pad_len
, col_len
= 20;
5911 /* convert sid into ascii string */
5912 sid_to_fstring(ascii_sid
, dom_sid
);
5914 /* calculate padding space for d_printf to look nicer */
5915 pad_len
= col_len
- strlen(trusted_dom_name
);
5916 padding
[pad_len
] = 0;
5917 do padding
[--pad_len
] = ' '; while (pad_len
);
5919 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5922 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5923 TALLOC_CTX
*mem_ctx
,
5926 const char *trusted_dom_name
)
5929 union lsa_TrustedDomainInfo
*info
= NULL
;
5930 char *cleartextpwd
= NULL
;
5933 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5936 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5938 if (NT_STATUS_IS_ERR(nt_status
)) {
5939 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5940 nt_errstr(nt_status
)));
5944 data
= data_blob(info
->password
.password
->data
,
5945 info
->password
.password
->length
);
5947 cleartextpwd
= decrypt_trustdom_secret(pipe_hnd
->cli
->pwd
.password
,
5950 if (cleartextpwd
== NULL
) {
5951 DEBUG(0,("retrieved NULL password\n"));
5952 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5956 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5957 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5958 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5962 #ifdef DEBUG_PASSWORD
5963 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5964 "password: [%s]\n", trusted_dom_name
,
5965 sid_string_dbg(&dom_sid
), cleartextpwd
));
5969 SAFE_FREE(cleartextpwd
);
5970 data_blob_free(&data
);
5975 static int rpc_trustdom_vampire(int argc
, const char **argv
)
5977 /* common variables */
5978 TALLOC_CTX
* mem_ctx
;
5979 struct cli_state
*cli
= NULL
;
5980 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5982 const char *domain_name
= NULL
;
5983 DOM_SID
*queried_dom_sid
;
5984 POLICY_HND connect_hnd
;
5985 union lsa_PolicyInformation
*info
= NULL
;
5987 /* trusted domains listing variables */
5988 unsigned int enum_ctx
= 0;
5990 struct lsa_DomainList dom_list
;
5994 * Listing trusted domains (stored in secrets.tdb, if local)
5997 mem_ctx
= talloc_init("trust relationships vampire");
6000 * set domain and pdc name to local samba server (default)
6001 * or to remote one given in command line
6004 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6005 domain_name
= opt_workgroup
;
6006 opt_target_workgroup
= opt_workgroup
;
6008 fstrcpy(pdc_name
, global_myname());
6009 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6010 opt_target_workgroup
= domain_name
;
6013 /* open \PIPE\lsarpc and open policy handle */
6014 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6015 if (!NT_STATUS_IS_OK(nt_status
)) {
6016 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6017 nt_errstr(nt_status
)));
6018 talloc_destroy(mem_ctx
);
6022 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6024 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6025 nt_errstr(nt_status
) ));
6027 talloc_destroy(mem_ctx
);
6031 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6033 if (NT_STATUS_IS_ERR(nt_status
)) {
6034 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6035 nt_errstr(nt_status
)));
6037 talloc_destroy(mem_ctx
);
6041 /* query info level 5 to obtain sid of a domain being queried */
6042 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6044 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6047 if (NT_STATUS_IS_ERR(nt_status
)) {
6048 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6049 nt_errstr(nt_status
)));
6051 talloc_destroy(mem_ctx
);
6055 queried_dom_sid
= info
->account_domain
.sid
;
6058 * Keep calling LsaEnumTrustdom over opened pipe until
6059 * the end of enumeration is reached
6062 d_printf("Vampire trusted domains:\n\n");
6065 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6070 if (NT_STATUS_IS_ERR(nt_status
)) {
6071 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6072 nt_errstr(nt_status
)));
6074 talloc_destroy(mem_ctx
);
6078 for (i
= 0; i
< dom_list
.count
; i
++) {
6080 print_trusted_domain(dom_list
.domains
[i
].sid
,
6081 dom_list
.domains
[i
].name
.string
);
6083 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6084 *dom_list
.domains
[i
].sid
,
6085 dom_list
.domains
[i
].name
.string
);
6086 if (!NT_STATUS_IS_OK(nt_status
)) {
6088 talloc_destroy(mem_ctx
);
6094 * in case of no trusted domains say something rather
6095 * than just display blank line
6097 if (!dom_list
.count
) d_printf("none\n");
6099 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6101 /* close this connection before doing next one */
6102 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6103 if (NT_STATUS_IS_ERR(nt_status
)) {
6104 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6105 nt_errstr(nt_status
)));
6107 talloc_destroy(mem_ctx
);
6111 /* close lsarpc pipe and connection to IPC$ */
6114 talloc_destroy(mem_ctx
);
6118 static int rpc_trustdom_list(int argc
, const char **argv
)
6120 /* common variables */
6121 TALLOC_CTX
* mem_ctx
;
6122 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6123 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6125 const char *domain_name
= NULL
;
6126 DOM_SID
*queried_dom_sid
;
6128 int ascii_dom_name_len
;
6129 POLICY_HND connect_hnd
;
6130 union lsa_PolicyInformation
*info
= NULL
;
6132 /* trusted domains listing variables */
6133 unsigned int num_domains
, enum_ctx
= 0;
6134 int i
, pad_len
, col_len
= 20;
6135 struct lsa_DomainList dom_list
;
6138 /* trusting domains listing variables */
6139 POLICY_HND domain_hnd
;
6140 struct samr_SamArray
*trusts
= NULL
;
6143 * Listing trusted domains (stored in secrets.tdb, if local)
6146 mem_ctx
= talloc_init("trust relationships listing");
6149 * set domain and pdc name to local samba server (default)
6150 * or to remote one given in command line
6153 if (StrCaseCmp(opt_workgroup
, lp_workgroup())) {
6154 domain_name
= opt_workgroup
;
6155 opt_target_workgroup
= opt_workgroup
;
6157 fstrcpy(pdc_name
, global_myname());
6158 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6159 opt_target_workgroup
= domain_name
;
6162 /* open \PIPE\lsarpc and open policy handle */
6163 nt_status
= net_make_ipc_connection(NET_FLAGS_PDC
, &cli
);
6164 if (!NT_STATUS_IS_OK(nt_status
)) {
6165 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6166 nt_errstr(nt_status
)));
6167 talloc_destroy(mem_ctx
);
6171 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_LSARPC
, &nt_status
);
6173 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6174 nt_errstr(nt_status
) ));
6176 talloc_destroy(mem_ctx
);
6180 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, False
, SEC_RIGHTS_QUERY_VALUE
,
6182 if (NT_STATUS_IS_ERR(nt_status
)) {
6183 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6184 nt_errstr(nt_status
)));
6186 talloc_destroy(mem_ctx
);
6190 /* query info level 5 to obtain sid of a domain being queried */
6191 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6193 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6196 if (NT_STATUS_IS_ERR(nt_status
)) {
6197 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6198 nt_errstr(nt_status
)));
6200 talloc_destroy(mem_ctx
);
6204 queried_dom_sid
= info
->account_domain
.sid
;
6207 * Keep calling LsaEnumTrustdom over opened pipe until
6208 * the end of enumeration is reached
6211 d_printf("Trusted domains list:\n\n");
6214 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6219 if (NT_STATUS_IS_ERR(nt_status
)) {
6220 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6221 nt_errstr(nt_status
)));
6223 talloc_destroy(mem_ctx
);
6227 for (i
= 0; i
< dom_list
.count
; i
++) {
6228 print_trusted_domain(dom_list
.domains
[i
].sid
,
6229 dom_list
.domains
[i
].name
.string
);
6233 * in case of no trusted domains say something rather
6234 * than just display blank line
6236 if (!dom_list
.count
) d_printf("none\n");
6238 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6240 /* close this connection before doing next one */
6241 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6242 if (NT_STATUS_IS_ERR(nt_status
)) {
6243 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6244 nt_errstr(nt_status
)));
6246 talloc_destroy(mem_ctx
);
6250 cli_rpc_pipe_close(pipe_hnd
);
6253 * Listing trusting domains (stored in passdb backend, if local)
6256 d_printf("\nTrusting domains list:\n\n");
6259 * Open \PIPE\samr and get needed policy handles
6261 pipe_hnd
= cli_rpc_pipe_open_noauth(cli
, PI_SAMR
, &nt_status
);
6263 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6265 talloc_destroy(mem_ctx
);
6270 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6271 pipe_hnd
->cli
->desthost
,
6272 SA_RIGHT_SAM_OPEN_DOMAIN
,
6274 if (!NT_STATUS_IS_OK(nt_status
)) {
6275 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6276 nt_errstr(nt_status
)));
6278 talloc_destroy(mem_ctx
);
6282 /* SamrOpenDomain - we have to open domain policy handle in order to be
6283 able to enumerate accounts*/
6284 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6286 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6289 if (!NT_STATUS_IS_OK(nt_status
)) {
6290 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6291 nt_errstr(nt_status
)));
6293 talloc_destroy(mem_ctx
);
6298 * perform actual enumeration
6301 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6304 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6311 if (NT_STATUS_IS_ERR(nt_status
)) {
6312 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6313 nt_errstr(nt_status
)));
6315 talloc_destroy(mem_ctx
);
6319 for (i
= 0; i
< num_domains
; i
++) {
6321 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6324 * get each single domain's sid (do we _really_ need this ?):
6325 * 1) connect to domain's pdc
6326 * 2) query the pdc for domain's sid
6329 /* get rid of '$' tail */
6330 ascii_dom_name_len
= strlen(str
);
6331 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6332 str
[ascii_dom_name_len
- 1] = '\0';
6334 /* calculate padding space for d_printf to look nicer */
6335 pad_len
= col_len
- strlen(str
);
6336 padding
[pad_len
] = 0;
6337 do padding
[--pad_len
] = ' '; while (pad_len
);
6339 /* set opt_* variables to remote domain */
6341 opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6342 opt_target_workgroup
= opt_workgroup
;
6344 d_printf("%s%s", str
, padding
);
6346 /* connect to remote domain controller */
6347 nt_status
= net_make_ipc_connection(
6348 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6350 if (NT_STATUS_IS_OK(nt_status
)) {
6351 /* query for domain's sid */
6352 if (run_rpc_command(remote_cli
, PI_LSARPC
, 0, rpc_query_domain_sid
, argc
, argv
))
6353 d_fprintf(stderr
, "couldn't get domain's sid\n");
6355 cli_shutdown(remote_cli
);
6358 d_fprintf(stderr
, "domain controller is not "
6360 nt_errstr(nt_status
));
6364 if (!num_domains
) d_printf("none\n");
6366 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6368 /* close opened samr and domain policy handles */
6369 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6370 if (!NT_STATUS_IS_OK(nt_status
)) {
6371 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6374 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6375 if (!NT_STATUS_IS_OK(nt_status
)) {
6376 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6379 /* close samr pipe and connection to IPC$ */
6382 talloc_destroy(mem_ctx
);
6387 * Entrypoint for 'net rpc trustdom' code
6389 * @param argc standard argc
6390 * @param argv standard argv without initial components
6392 * @return Integer status (0 means success)
6395 static int rpc_trustdom(int argc
, const char **argv
)
6397 struct functable func
[] = {
6398 {"add", rpc_trustdom_add
},
6399 {"del", rpc_trustdom_del
},
6400 {"establish", rpc_trustdom_establish
},
6401 {"revoke", rpc_trustdom_revoke
},
6402 {"help", rpc_trustdom_usage
},
6403 {"list", rpc_trustdom_list
},
6404 {"vampire", rpc_trustdom_vampire
},
6409 rpc_trustdom_usage(argc
, argv
);
6413 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6417 * Check if a server will take rpc commands
6418 * @param flags Type of server to connect to (PDC, DMB, localhost)
6419 * if the host is not explicitly specified
6420 * @return bool (true means rpc supported)
6422 bool net_rpc_check(unsigned flags
)
6424 struct cli_state
*cli
;
6426 struct sockaddr_storage server_ss
;
6427 char *server_name
= NULL
;
6430 /* flags (i.e. server type) may depend on command */
6431 if (!net_find_server(NULL
, flags
, &server_ss
, &server_name
))
6434 if ((cli
= cli_initialise()) == NULL
) {
6438 status
= cli_connect(cli
, server_name
, &server_ss
);
6439 if (!NT_STATUS_IS_OK(status
))
6441 if (!attempt_netbios_session_request(&cli
, global_myname(),
6442 server_name
, &server_ss
))
6444 if (!cli_negprot(cli
))
6446 if (cli
->protocol
< PROTOCOL_NT1
)
6455 /* dump sam database via samsync rpc calls */
6456 static int rpc_samdump(int argc
, const char **argv
) {
6457 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_samdump_internals
,
6461 /* syncronise sam database via samsync rpc calls */
6462 static int rpc_vampire(int argc
, const char **argv
) {
6463 return run_rpc_command(NULL
, PI_NETLOGON
, NET_FLAGS_ANONYMOUS
, rpc_vampire_internals
,
6468 * Migrate everything from a print-server
6470 * @param argc Standard main() style argc
6471 * @param argv Standard main() style argv. Initial components are already
6474 * @return A shell status integer (0 for success)
6476 * The order is important !
6477 * To successfully add drivers the print-queues have to exist !
6478 * Applying ACLs should be the last step, because you're easily locked out
6481 static int rpc_printer_migrate_all(int argc
, const char **argv
)
6486 printf("no server to migrate\n");
6490 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_printers_internals
, argc
, argv
);
6494 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_drivers_internals
, argc
, argv
);
6498 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_forms_internals
, argc
, argv
);
6502 ret
= run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_settings_internals
, argc
, argv
);
6506 return run_rpc_command(NULL
, PI_SPOOLSS
, 0, rpc_printer_migrate_security_internals
, argc
, argv
);
6511 * Migrate print-drivers from a print-server
6513 * @param argc Standard main() style argc
6514 * @param argv Standard main() style argv. Initial components are already
6517 * @return A shell status integer (0 for success)
6519 static int rpc_printer_migrate_drivers(int argc
, const char **argv
)
6522 printf("no server to migrate\n");
6526 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6527 rpc_printer_migrate_drivers_internals
,
6532 * Migrate print-forms from a print-server
6534 * @param argc Standard main() style argc
6535 * @param argv Standard main() style argv. Initial components are already
6538 * @return A shell status integer (0 for success)
6540 static int rpc_printer_migrate_forms(int argc
, const char **argv
)
6543 printf("no server to migrate\n");
6547 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6548 rpc_printer_migrate_forms_internals
,
6553 * Migrate printers from a print-server
6555 * @param argc Standard main() style argc
6556 * @param argv Standard main() style argv. Initial components are already
6559 * @return A shell status integer (0 for success)
6561 static int rpc_printer_migrate_printers(int argc
, const char **argv
)
6564 printf("no server to migrate\n");
6568 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6569 rpc_printer_migrate_printers_internals
,
6574 * Migrate printer-ACLs from a print-server
6576 * @param argc Standard main() style argc
6577 * @param argv Standard main() style argv. Initial components are already
6580 * @return A shell status integer (0 for success)
6582 static int rpc_printer_migrate_security(int argc
, const char **argv
)
6585 printf("no server to migrate\n");
6589 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6590 rpc_printer_migrate_security_internals
,
6595 * Migrate printer-settings from a print-server
6597 * @param argc Standard main() style argc
6598 * @param argv Standard main() style argv. Initial components are already
6601 * @return A shell status integer (0 for success)
6603 static int rpc_printer_migrate_settings(int argc
, const char **argv
)
6606 printf("no server to migrate\n");
6610 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6611 rpc_printer_migrate_settings_internals
,
6616 * 'net rpc printer' entrypoint.
6617 * @param argc Standard main() style argc
6618 * @param argv Standard main() style argv. Initial components are already
6622 int rpc_printer_migrate(int argc
, const char **argv
)
6625 /* ouch: when addriver and setdriver are called from within
6626 rpc_printer_migrate_drivers_internals, the printer-queue already
6629 struct functable func
[] = {
6630 {"all", rpc_printer_migrate_all
},
6631 {"drivers", rpc_printer_migrate_drivers
},
6632 {"forms", rpc_printer_migrate_forms
},
6633 {"help", rpc_printer_usage
},
6634 {"printers", rpc_printer_migrate_printers
},
6635 {"security", rpc_printer_migrate_security
},
6636 {"settings", rpc_printer_migrate_settings
},
6640 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6645 * List printers on a remote RPC server
6647 * @param argc Standard main() style argc
6648 * @param argv Standard main() style argv. Initial components are already
6651 * @return A shell status integer (0 for success)
6653 static int rpc_printer_list(int argc
, const char **argv
)
6656 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6657 rpc_printer_list_internals
,
6662 * List printer-drivers on a remote RPC server
6664 * @param argc Standard main() style argc
6665 * @param argv Standard main() style argv. Initial components are already
6668 * @return A shell status integer (0 for success)
6670 static int rpc_printer_driver_list(int argc
, const char **argv
)
6673 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6674 rpc_printer_driver_list_internals
,
6679 * Publish printer in ADS via MSRPC
6681 * @param argc Standard main() style argc
6682 * @param argv Standard main() style argv. Initial components are already
6685 * @return A shell status integer (0 for success)
6687 static int rpc_printer_publish_publish(int argc
, const char **argv
)
6690 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6691 rpc_printer_publish_publish_internals
,
6696 * Update printer in ADS via MSRPC
6698 * @param argc Standard main() style argc
6699 * @param argv Standard main() style argv. Initial components are already
6702 * @return A shell status integer (0 for success)
6704 static int rpc_printer_publish_update(int argc
, const char **argv
)
6707 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6708 rpc_printer_publish_update_internals
,
6713 * UnPublish printer in ADS via MSRPC
6715 * @param argc Standard main() style argc
6716 * @param argv Standard main() style argv. Initial components are already
6719 * @return A shell status integer (0 for success)
6721 static int rpc_printer_publish_unpublish(int argc
, const char **argv
)
6724 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6725 rpc_printer_publish_unpublish_internals
,
6730 * List published printers via MSRPC
6732 * @param argc Standard main() style argc
6733 * @param argv Standard main() style argv. Initial components are already
6736 * @return A shell status integer (0 for success)
6738 static int rpc_printer_publish_list(int argc
, const char **argv
)
6741 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6742 rpc_printer_publish_list_internals
,
6748 * Publish printer in ADS
6750 * @param argc Standard main() style argc
6751 * @param argv Standard main() style argv. Initial components are already
6754 * @return A shell status integer (0 for success)
6756 static int rpc_printer_publish(int argc
, const char **argv
)
6759 struct functable func
[] = {
6760 {"publish", rpc_printer_publish_publish
},
6761 {"update", rpc_printer_publish_update
},
6762 {"unpublish", rpc_printer_publish_unpublish
},
6763 {"list", rpc_printer_publish_list
},
6764 {"help", rpc_printer_usage
},
6769 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6770 rpc_printer_publish_list_internals
,
6773 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6779 * Display rpc printer help page.
6780 * @param argc Standard main() style argc
6781 * @param argv Standard main() style argv. Initial components are already
6784 int rpc_printer_usage(int argc
, const char **argv
)
6786 return net_help_printer(argc
, argv
);
6790 * 'net rpc printer' entrypoint.
6791 * @param argc Standard main() style argc
6792 * @param argv Standard main() style argv. Initial components are already
6795 int net_rpc_printer(int argc
, const char **argv
)
6797 struct functable func
[] = {
6798 {"list", rpc_printer_list
},
6799 {"migrate", rpc_printer_migrate
},
6800 {"driver", rpc_printer_driver_list
},
6801 {"publish", rpc_printer_publish
},
6806 return run_rpc_command(NULL
, PI_SPOOLSS
, 0,
6807 rpc_printer_list_internals
,
6810 return net_run_function(argc
, argv
, func
, rpc_printer_usage
);
6813 /****************************************************************************/
6817 * Basic usage function for 'net rpc'
6818 * @param argc Standard main() style argc
6819 * @param argv Standard main() style argv. Initial components are already
6823 int net_rpc_usage(int argc
, const char **argv
)
6825 d_printf(" net rpc info \t\t\tshow basic info about a domain \n");
6826 d_printf(" net rpc join \t\t\tto join a domain \n");
6827 d_printf(" net rpc oldjoin \t\tto join a domain created in server manager\n");
6828 d_printf(" net rpc testjoin \t\ttests that a join is valid\n");
6829 d_printf(" net rpc user \t\t\tto add, delete and list users\n");
6830 d_printf(" net rpc password <username> [<password>] -Uadmin_username%%admin_pass\n");
6831 d_printf(" net rpc group \t\tto list groups\n");
6832 d_printf(" net rpc share \t\tto add, delete, list and migrate shares\n");
6833 d_printf(" net rpc printer \t\tto list and migrate printers\n");
6834 d_printf(" net rpc file \t\t\tto list open files\n");
6835 d_printf(" net rpc changetrustpw \tto change the trust account password\n");
6836 d_printf(" net rpc getsid \t\tfetch the domain sid into the local secrets.tdb\n");
6837 d_printf(" net rpc vampire \t\tsyncronise an NT PDC's users and groups into the local passdb\n");
6838 d_printf(" net rpc samdump \t\tdisplay an NT PDC's users, groups and other data\n");
6839 d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n");
6840 d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n");
6841 d_printf(" net rpc shutdown \t\tto shutdown a remote server\n");
6842 d_printf(" net rpc rights\t\tto manage privileges assigned to SIDs\n");
6843 d_printf(" net rpc registry\t\tto manage registry hives\n");
6844 d_printf(" net rpc service\t\tto start, stop and query services\n");
6845 d_printf(" net rpc audit\t\t\tto modify global auditing settings\n");
6846 d_printf(" net rpc shell\t\t\tto open an interactive shell for remote server/account management\n");
6848 d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */
6849 d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n");
6850 d_printf("\t-f or --force\trequest the remote server force its shutdown\n");
6851 d_printf("\t-t or --timeout=<timeout>\tnumber of seconds before shutdown\n");
6852 d_printf("\t-C or --comment=<message>\ttext message to display on impending shutdown\n");
6858 * Help function for 'net rpc'. Calls command specific help if requested
6859 * or displays usage of net rpc
6860 * @param argc Standard main() style argc
6861 * @param argv Standard main() style argv. Initial components are already
6865 int net_rpc_help(int argc
, const char **argv
)
6867 struct functable func
[] = {
6868 {"join", rpc_join_usage
},
6869 {"user", rpc_user_usage
},
6870 {"group", rpc_group_usage
},
6871 {"share", rpc_share_usage
},
6872 /*{"changetrustpw", rpc_changetrustpw_usage}, */
6873 {"trustdom", rpc_trustdom_usage
},
6874 /*{"abortshutdown", rpc_shutdown_abort_usage},*/
6875 /*{"shutdown", rpc_shutdown_usage}, */
6876 {"vampire", rpc_vampire_usage
},
6881 net_rpc_usage(argc
, argv
);
6885 return (net_run_function(argc
, argv
, func
, rpc_user_usage
));
6889 * 'net rpc' entrypoint.
6890 * @param argc Standard main() style argc
6891 * @param argv Standard main() style argv. Initial components are already
6895 int net_rpc(int argc
, const char **argv
)
6897 struct functable func
[] = {
6898 {"audit", net_rpc_audit
},
6899 {"info", net_rpc_info
},
6900 {"join", net_rpc_join
},
6901 {"oldjoin", net_rpc_oldjoin
},
6902 {"testjoin", net_rpc_testjoin
},
6903 {"user", net_rpc_user
},
6904 {"password", rpc_user_password
},
6905 {"group", net_rpc_group
},
6906 {"share", net_rpc_share
},
6907 {"file", net_rpc_file
},
6908 {"printer", net_rpc_printer
},
6909 {"changetrustpw", net_rpc_changetrustpw
},
6910 {"trustdom", rpc_trustdom
},
6911 {"abortshutdown", rpc_shutdown_abort
},
6912 {"shutdown", rpc_shutdown
},
6913 {"samdump", rpc_samdump
},
6914 {"vampire", rpc_vampire
},
6915 {"getsid", net_rpc_getsid
},
6916 {"rights", net_rpc_rights
},
6917 {"service", net_rpc_service
},
6918 {"registry", net_rpc_registry
},
6919 {"shell", net_rpc_shell
},
6920 {"help", net_rpc_help
},
6923 return net_run_function(argc
, argv
, func
, net_rpc_usage
);