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
= NULL
;
58 struct policy_handle pol
;
59 NTSTATUS result
= NT_STATUS_OK
;
60 union lsa_PolicyInformation
*info
= NULL
;
62 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
64 if (!NT_STATUS_IS_OK(result
)) {
65 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
69 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
70 SEC_RIGHTS_MAXIMUM_ALLOWED
,
72 if (!NT_STATUS_IS_OK(result
)) {
73 d_fprintf(stderr
, "open_policy failed: %s\n",
78 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
80 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
82 if (!NT_STATUS_IS_OK(result
)) {
83 d_fprintf(stderr
, "lsaquery failed: %s\n",
88 *domain_name
= info
->account_domain
.name
.string
;
89 *domain_sid
= info
->account_domain
.sid
;
91 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
92 TALLOC_FREE(lsa_pipe
);
98 * Run a single RPC command, from start to finish.
100 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
101 * @param conn_flag a NET_FLAG_ combination. Passed to
102 * net_make_ipc_connection.
103 * @param argc Standard main() style argc.
104 * @param argv Standard main() style argv. Initial components are already
106 * @return A shell status integer (0 for success).
109 int run_rpc_command(struct net_context
*c
,
110 struct cli_state
*cli_arg
,
111 const struct ndr_syntax_id
*interface
,
117 struct cli_state
*cli
= NULL
;
118 struct rpc_pipe_client
*pipe_hnd
= NULL
;
122 const char *domain_name
;
124 /* make use of cli_state handed over as an argument, if possible */
126 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
127 if (!NT_STATUS_IS_OK(nt_status
)) {
128 DEBUG(1, ("failed to make ipc connection: %s\n",
129 nt_errstr(nt_status
)));
142 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
143 DEBUG(0, ("talloc_init() failed\n"));
148 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
150 if (!NT_STATUS_IS_OK(nt_status
)) {
155 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
156 if (lp_client_schannel()
157 && (ndr_syntax_id_equal(interface
,
158 &ndr_table_netlogon
.syntax_id
))) {
159 /* Always try and create an schannel netlogon pipe. */
160 nt_status
= cli_rpc_pipe_open_schannel(
162 PIPE_AUTH_LEVEL_PRIVACY
, domain_name
,
164 if (!NT_STATUS_IS_OK(nt_status
)) {
165 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
166 nt_errstr(nt_status
) ));
171 if (conn_flags
& NET_FLAGS_SEAL
) {
172 nt_status
= cli_rpc_pipe_open_ntlmssp(
174 PIPE_AUTH_LEVEL_PRIVACY
,
175 lp_workgroup(), c
->opt_user_name
,
176 c
->opt_password
, &pipe_hnd
);
178 nt_status
= cli_rpc_pipe_open_noauth(
182 if (!NT_STATUS_IS_OK(nt_status
)) {
183 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
184 get_pipe_name_from_iface(interface
),
185 nt_errstr(nt_status
) ));
192 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
194 if (!NT_STATUS_IS_OK(nt_status
)) {
195 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
197 DEBUG(5, ("rpc command function succedded\n"));
200 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
202 TALLOC_FREE(pipe_hnd
);
206 /* close the connection only if it was opened here */
211 talloc_destroy(mem_ctx
);
212 return (!NT_STATUS_IS_OK(nt_status
));
216 * Force a change of the trust acccount password.
218 * All parameters are provided by the run_rpc_command function, except for
219 * argc, argv which are passed through.
221 * @param domain_sid The domain sid acquired from the remote server.
222 * @param cli A cli_state connected to the server.
223 * @param mem_ctx Talloc context, destroyed on completion of the function.
224 * @param argc Standard main() style argc.
225 * @param argv Standard main() style argv. Initial components are already
228 * @return Normal NTSTATUS return.
231 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
232 const DOM_SID
*domain_sid
,
233 const char *domain_name
,
234 struct cli_state
*cli
,
235 struct rpc_pipe_client
*pipe_hnd
,
241 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
245 * Force a change of the trust acccount password.
247 * @param argc Standard main() style argc.
248 * @param argv Standard main() style argv. Initial components are already
251 * @return A shell status integer (0 for success).
254 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
256 if (c
->display_usage
) {
258 "net rpc changetrustpw\n"
259 " Change the machine trust password\n");
263 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
264 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
265 rpc_changetrustpw_internals
,
270 * Join a domain, the old way.
272 * This uses 'machinename' as the inital password, and changes it.
274 * The password should be created with 'server manager' or equiv first.
276 * All parameters are provided by the run_rpc_command function, except for
277 * argc, argv which are passed through.
279 * @param domain_sid The domain sid acquired from the remote server.
280 * @param cli A cli_state connected to the server.
281 * @param mem_ctx Talloc context, destroyed on completion of the function.
282 * @param argc Standard main() style argc.
283 * @param argv Standard main() style argv. Initial components are already
286 * @return Normal NTSTATUS return.
289 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
290 const DOM_SID
*domain_sid
,
291 const char *domain_name
,
292 struct cli_state
*cli
,
293 struct rpc_pipe_client
*pipe_hnd
,
299 fstring trust_passwd
;
300 unsigned char orig_trust_passwd_hash
[16];
302 uint32 sec_channel_type
;
304 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
306 if (!NT_STATUS_IS_OK(result
)) {
307 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
310 nt_errstr(result
) ));
315 check what type of join - if the user want's to join as
316 a BDC, the server must agree that we are a BDC.
319 sec_channel_type
= get_sec_channel_type(argv
[0]);
321 sec_channel_type
= get_sec_channel_type(NULL
);
324 fstrcpy(trust_passwd
, global_myname());
325 strlower_m(trust_passwd
);
328 * Machine names can be 15 characters, but the max length on
329 * a password is 14. --jerry
332 trust_passwd
[14] = '\0';
334 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
336 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
337 orig_trust_passwd_hash
,
340 if (NT_STATUS_IS_OK(result
))
341 printf("Joined domain %s.\n", c
->opt_target_workgroup
);
344 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
345 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
346 result
= NT_STATUS_UNSUCCESSFUL
;
353 * Join a domain, the old way.
355 * @param argc Standard main() style argc.
356 * @param argv Standard main() style argv. Initial components are already
359 * @return A shell status integer (0 for success).
362 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
364 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
365 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
366 rpc_oldjoin_internals
,
371 * Join a domain, the old way. This function exists to allow
372 * the message to be displayed when oldjoin was explicitly
373 * requested, but not when it was implied by "net rpc join".
375 * @param argc Standard main() style argc.
376 * @param argv Standard main() style argv. Initial components are already
379 * @return A shell status integer (0 for success).
382 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
386 if (c
->display_usage
) {
389 " Join a domain the old way\n");
393 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
396 d_fprintf(stderr
, "Failed to join domain\n");
403 * 'net rpc join' entrypoint.
404 * @param argc Standard main() style argc.
405 * @param argv Standard main() style argv. Initial components are already
408 * Main 'net_rpc_join()' (where the admin username/password is used) is
410 * Try to just change the password, but if that doesn't work, use/prompt
411 * for a username/password.
414 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
416 if (c
->display_usage
) {
418 "net rpc join -U <username>[%%password] <type>\n"
420 " username\tName of the admin user"
421 " password\tPassword of the admin user, will "
422 "prompt if not specified\n"
423 " type\tCan be one of the following:\n"
424 "\t\tMEMBER\tJoin as member server (default)\n"
425 "\t\tBDC\tJoin as BDC\n"
426 "\t\tPDC\tJoin as PDC\n");
430 if (lp_server_role() == ROLE_STANDALONE
) {
431 d_printf("cannot join as standalone machine\n");
435 if (strlen(global_myname()) > 15) {
436 d_printf("Our netbios name can be at most 15 chars long, "
437 "\"%s\" is %u chars long\n",
438 global_myname(), (unsigned int)strlen(global_myname()));
442 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
445 return net_rpc_join_newstyle(c
, argc
, argv
);
449 * display info about a rpc domain
451 * All parameters are provided by the run_rpc_command function, except for
452 * argc, argv which are passed through.
454 * @param domain_sid The domain sid acquired from the remote server
455 * @param cli A cli_state connected to the server.
456 * @param mem_ctx Talloc context, destroyed on completion of the function.
457 * @param argc Standard main() style argc.
458 * @param argv Standard main() style argv. Initial components are already
461 * @return Normal NTSTATUS return.
464 NTSTATUS
rpc_info_internals(struct net_context
*c
,
465 const DOM_SID
*domain_sid
,
466 const char *domain_name
,
467 struct cli_state
*cli
,
468 struct rpc_pipe_client
*pipe_hnd
,
473 struct policy_handle connect_pol
, domain_pol
;
474 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
475 union samr_DomainInfo
*info
= NULL
;
478 sid_to_fstring(sid_str
, domain_sid
);
480 /* Get sam policy handle */
481 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
483 MAXIMUM_ALLOWED_ACCESS
,
485 if (!NT_STATUS_IS_OK(result
)) {
486 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
490 /* Get domain policy handle */
491 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
493 MAXIMUM_ALLOWED_ACCESS
,
494 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
496 if (!NT_STATUS_IS_OK(result
)) {
497 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
501 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
505 if (NT_STATUS_IS_OK(result
)) {
506 d_printf("Domain Name: %s\n", info
->general
.domain_name
.string
);
507 d_printf("Domain SID: %s\n", sid_str
);
508 d_printf("Sequence number: %llu\n",
509 (unsigned long long)info
->general
.sequence_num
);
510 d_printf("Num users: %u\n", info
->general
.num_users
);
511 d_printf("Num domain groups: %u\n", info
->general
.num_groups
);
512 d_printf("Num local groups: %u\n", info
->general
.num_aliases
);
520 * 'net rpc info' entrypoint.
521 * @param argc Standard main() style argc.
522 * @param argv Standard main() style argv. Initial components are already
526 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
528 if (c
->display_usage
) {
531 " Display information about the domain\n");
535 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
536 NET_FLAGS_PDC
, rpc_info_internals
,
541 * Fetch domain SID into the local secrets.tdb.
543 * All parameters are provided by the run_rpc_command function, except for
544 * argc, argv which are passed through.
546 * @param domain_sid The domain sid acquired from the remote server.
547 * @param cli A cli_state connected to the server.
548 * @param mem_ctx Talloc context, destroyed on completion of the function.
549 * @param argc Standard main() style argc.
550 * @param argv Standard main() style argv. Initial components are already
553 * @return Normal NTSTATUS return.
556 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
557 const DOM_SID
*domain_sid
,
558 const char *domain_name
,
559 struct cli_state
*cli
,
560 struct rpc_pipe_client
*pipe_hnd
,
567 sid_to_fstring(sid_str
, domain_sid
);
568 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
569 sid_str
, domain_name
);
571 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
572 DEBUG(0,("Can't store domain SID\n"));
573 return NT_STATUS_UNSUCCESSFUL
;
580 * 'net rpc getsid' entrypoint.
581 * @param argc Standard main() style argc.
582 * @param argv Standard main() style argv. Initial components are already
586 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
588 if (c
->display_usage
) {
591 " Fetch domain SID into local secrets.tdb\n");
595 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
596 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
597 rpc_getsid_internals
,
601 /****************************************************************************/
604 * Basic usage function for 'net rpc user'.
605 * @param argc Standard main() style argc.
606 * @param argv Standard main() style argv. Initial components are already
610 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
612 return net_user_usage(c
, argc
, argv
);
616 * Add a new user to a remote RPC server.
618 * @param argc Standard main() style argc.
619 * @param argv Standard main() style argv. Initial components are already
622 * @return A shell status integer (0 for success).
625 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
627 NET_API_STATUS status
;
628 struct USER_INFO_1 info1
;
629 uint32_t parm_error
= 0;
631 if (argc
< 1 || c
->display_usage
) {
632 rpc_user_usage(c
, argc
, argv
);
638 info1
.usri1_name
= argv
[0];
640 info1
.usri1_password
= argv
[1];
643 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
646 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
647 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
651 d_printf("Added user '%s'.\n", argv
[0]);
658 * Rename a user on a remote RPC server.
660 * @param argc Standard main() style argc.
661 * @param argv Standard main() style argv. Initial components are already
664 * @return A shell status integer (0 for success).
667 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
669 NET_API_STATUS status
;
670 struct USER_INFO_0 u0
;
671 uint32_t parm_err
= 0;
673 if (argc
!= 2 || c
->display_usage
) {
674 rpc_user_usage(c
, argc
, argv
);
678 u0
.usri0_name
= argv
[1];
680 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
681 0, (uint8_t *)&u0
, &parm_err
);
683 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n",
685 libnetapi_get_error_string(c
->netapi_ctx
, status
));
687 d_printf("Renamed user from %s to %s\n", argv
[0], argv
[1]);
694 * Delete a user from a remote RPC server.
696 * @param argc Standard main() style argc.
697 * @param argv Standard main() style argv. Initial components are already
700 * @return A shell status integer (0 for success).
703 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
705 NET_API_STATUS status
;
707 if (argc
< 1 || c
->display_usage
) {
708 rpc_user_usage(c
, argc
, argv
);
712 status
= NetUserDel(c
->opt_host
, argv
[0]);
715 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
717 libnetapi_get_error_string(c
->netapi_ctx
, status
));
720 d_printf("Deleted user '%s'.\n", argv
[0]);
727 * Set a user's password on a remote RPC server.
729 * @param argc Standard main() style argc.
730 * @param argv Standard main() style argv. Initial components are already
733 * @return A shell status integer (0 for success).
736 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
738 NET_API_STATUS status
;
740 struct USER_INFO_1003 u1003
;
741 uint32_t parm_err
= 0;
743 if (argc
< 1 || c
->display_usage
) {
744 rpc_user_usage(c
, argc
, argv
);
749 u1003
.usri1003_password
= argv
[1];
751 if (asprintf(&prompt
, "Enter new password for %s:", argv
[0]) == -1) {
754 u1003
.usri1003_password
= getpass(prompt
);
758 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
760 /* Display results */
762 d_fprintf(stderr
, "Failed to set password for '%s' with: %s.\n",
763 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
772 * List a user's groups from a remote RPC server.
774 * @param argc Standard main() style argc.
775 * @param argv Standard main() style argv. Initial components are already
778 * @return A shell status integer (0 for success)
781 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
784 NET_API_STATUS status
;
785 struct GROUP_USERS_INFO_0
*u0
= NULL
;
786 uint32_t entries_read
= 0;
787 uint32_t total_entries
= 0;
791 if (argc
< 1 || c
->display_usage
) {
792 rpc_user_usage(c
, argc
, argv
);
796 status
= NetUserGetGroups(c
->opt_host
,
799 (uint8_t **)(void *)&u0
,
804 d_fprintf(stderr
, "Failed to get groups for '%s' with: %s.\n",
805 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
810 for (i
=0; i
< entries_read
; i
++) {
811 printf("%s\n", u0
->grui0_name
);
819 * List users on a remote RPC server.
821 * All parameters are provided by the run_rpc_command function, except for
822 * argc, argv which are passed through.
824 * @param domain_sid The domain sid acquired from the remote server.
825 * @param cli A cli_state connected to the server.
826 * @param mem_ctx Talloc context, destroyed on completion of the function.
827 * @param argc Standard main() style argc.
828 * @param argv Standard main() style argv. Initial components are already
831 * @return Normal NTSTATUS return.
834 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
836 NET_API_STATUS status
;
837 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
838 struct NET_DISPLAY_USER
*info
= NULL
;
841 /* Query domain users */
842 if (c
->opt_long_list_entries
)
843 d_printf("\nUser name Comment"
844 "\n-----------------------------\n");
846 uint32_t max_entries
, max_size
;
848 get_query_dispinfo_params(
849 loop_count
, &max_entries
, &max_size
);
851 status
= NetQueryDisplayInformation(c
->opt_host
,
858 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
862 info
= (struct NET_DISPLAY_USER
*)buffer
;
864 for (i
= 0; i
< num_entries
; i
++) {
866 if (c
->opt_long_list_entries
)
867 printf("%-21.21s %s\n", info
->usri1_name
,
868 info
->usri1_comment
);
870 printf("%s\n", info
->usri1_name
);
874 NetApiBufferFree(buffer
);
877 start_idx
+= num_entries
;
879 } while (status
== ERROR_MORE_DATA
);
885 * 'net rpc user' entrypoint.
886 * @param argc Standard main() style argc.
887 * @param argv Standard main() style argv. Initial components are already
891 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
893 NET_API_STATUS status
;
895 struct functable func
[] = {
900 "Add specified user",
902 " Add specified user"
908 "List domain groups of user",
909 "net rpc user info\n"
910 " Lis domain groups of user"
916 "Remove specified user",
917 "net rpc user delete\n"
918 " Remove specified user"
924 "Change user password",
925 "net rpc user password\n"
926 " Change user password"
932 "Rename specified user",
933 "net rpc user rename\n"
934 " Rename specified user"
936 {NULL
, NULL
, 0, NULL
, NULL
}
939 status
= libnetapi_init(&c
->netapi_ctx
);
943 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
944 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
945 if (c
->opt_kerberos
) {
946 libnetapi_set_use_kerberos(c
->netapi_ctx
);
950 if (c
->display_usage
) {
951 d_printf("Usage:\n");
952 d_printf("net rpc user\n"
953 " List all users\n");
954 net_display_usage_from_functable(func
);
958 return rpc_user_list(c
, argc
, argv
);
961 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
964 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
966 struct rpc_sh_ctx
*ctx
,
967 struct rpc_pipe_client
*pipe_hnd
,
968 int argc
, const char **argv
)
970 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
973 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
975 struct rpc_sh_ctx
*ctx
,
976 struct rpc_pipe_client
*pipe_hnd
,
977 int argc
, const char **argv
)
979 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
982 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
984 struct rpc_sh_ctx
*ctx
,
985 struct rpc_pipe_client
*pipe_hnd
,
986 int argc
, const char **argv
,
988 struct net_context
*c
,
990 struct rpc_sh_ctx
*ctx
,
991 struct rpc_pipe_client
*pipe_hnd
,
992 struct policy_handle
*user_hnd
,
993 int argc
, const char **argv
))
995 struct policy_handle connect_pol
, domain_pol
, user_pol
;
996 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
999 enum lsa_SidType type
;
1002 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1003 return NT_STATUS_INVALID_PARAMETER
;
1006 ZERO_STRUCT(connect_pol
);
1007 ZERO_STRUCT(domain_pol
);
1008 ZERO_STRUCT(user_pol
);
1010 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1011 argv
[0], NULL
, NULL
, &sid
, &type
);
1012 if (!NT_STATUS_IS_OK(result
)) {
1013 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1018 if (type
!= SID_NAME_USER
) {
1019 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1020 sid_type_lookup(type
));
1021 result
= NT_STATUS_NO_SUCH_USER
;
1025 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1026 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1027 result
= NT_STATUS_NO_SUCH_USER
;
1031 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1033 MAXIMUM_ALLOWED_ACCESS
,
1035 if (!NT_STATUS_IS_OK(result
)) {
1039 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1041 MAXIMUM_ALLOWED_ACCESS
,
1044 if (!NT_STATUS_IS_OK(result
)) {
1048 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1050 MAXIMUM_ALLOWED_ACCESS
,
1053 if (!NT_STATUS_IS_OK(result
)) {
1057 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1060 if (is_valid_policy_hnd(&user_pol
)) {
1061 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1063 if (is_valid_policy_hnd(&domain_pol
)) {
1064 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1066 if (is_valid_policy_hnd(&connect_pol
)) {
1067 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1072 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1073 TALLOC_CTX
*mem_ctx
,
1074 struct rpc_sh_ctx
*ctx
,
1075 struct rpc_pipe_client
*pipe_hnd
,
1076 struct policy_handle
*user_hnd
,
1077 int argc
, const char **argv
)
1080 union samr_UserInfo
*info
= NULL
;
1083 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1084 return NT_STATUS_INVALID_PARAMETER
;
1087 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1091 if (!NT_STATUS_IS_OK(result
)) {
1095 d_printf("user rid: %d, group rid: %d\n",
1097 info
->info21
.primary_gid
);
1102 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1103 TALLOC_CTX
*mem_ctx
,
1104 struct rpc_sh_ctx
*ctx
,
1105 struct rpc_pipe_client
*pipe_hnd
,
1106 int argc
, const char **argv
)
1108 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1109 rpc_sh_user_show_internals
);
1112 #define FETCHSTR(name, rec) \
1113 do { if (strequal(ctx->thiscmd, name)) { \
1114 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1117 #define SETSTR(name, rec, flag) \
1118 do { if (strequal(ctx->thiscmd, name)) { \
1119 init_lsa_String(&(info->info21.rec), argv[0]); \
1120 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1123 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1124 TALLOC_CTX
*mem_ctx
,
1125 struct rpc_sh_ctx
*ctx
,
1126 struct rpc_pipe_client
*pipe_hnd
,
1127 struct policy_handle
*user_hnd
,
1128 int argc
, const char **argv
)
1131 const char *username
;
1132 const char *oldval
= "";
1133 union samr_UserInfo
*info
= NULL
;
1136 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1138 return NT_STATUS_INVALID_PARAMETER
;
1141 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1145 if (!NT_STATUS_IS_OK(result
)) {
1149 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1151 FETCHSTR("fullname", full_name
);
1152 FETCHSTR("homedir", home_directory
);
1153 FETCHSTR("homedrive", home_drive
);
1154 FETCHSTR("logonscript", logon_script
);
1155 FETCHSTR("profilepath", profile_path
);
1156 FETCHSTR("description", description
);
1159 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1163 if (strcmp(argv
[0], "NULL") == 0) {
1167 ZERO_STRUCT(info
->info21
);
1169 SETSTR("fullname", full_name
, FULL_NAME
);
1170 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1171 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1172 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1173 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1174 SETSTR("description", description
, DESCRIPTION
);
1176 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1181 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1182 ctx
->thiscmd
, oldval
, argv
[0]);
1189 #define HANDLEFLG(name, rec) \
1190 do { if (strequal(ctx->thiscmd, name)) { \
1191 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1193 newflags = oldflags | ACB_##rec; \
1195 newflags = oldflags & ~ACB_##rec; \
1198 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1199 TALLOC_CTX
*mem_ctx
,
1200 struct rpc_sh_ctx
*ctx
,
1201 struct rpc_pipe_client
*pipe_hnd
,
1202 int argc
, const char **argv
)
1204 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1205 rpc_sh_user_str_edit_internals
);
1208 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1209 TALLOC_CTX
*mem_ctx
,
1210 struct rpc_sh_ctx
*ctx
,
1211 struct rpc_pipe_client
*pipe_hnd
,
1212 struct policy_handle
*user_hnd
,
1213 int argc
, const char **argv
)
1216 const char *username
;
1217 const char *oldval
= "unknown";
1218 uint32 oldflags
, newflags
;
1220 union samr_UserInfo
*info
= NULL
;
1223 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1224 !strequal(argv
[0], "no"))) {
1225 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1227 return NT_STATUS_INVALID_PARAMETER
;
1230 newval
= strequal(argv
[0], "yes");
1232 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1236 if (!NT_STATUS_IS_OK(result
)) {
1240 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1241 oldflags
= info
->info21
.acct_flags
;
1242 newflags
= info
->info21
.acct_flags
;
1244 HANDLEFLG("disabled", DISABLED
);
1245 HANDLEFLG("pwnotreq", PWNOTREQ
);
1246 HANDLEFLG("autolock", AUTOLOCK
);
1247 HANDLEFLG("pwnoexp", PWNOEXP
);
1250 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1254 ZERO_STRUCT(info
->info21
);
1256 info
->info21
.acct_flags
= newflags
;
1257 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1259 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1264 if (NT_STATUS_IS_OK(result
)) {
1265 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1266 ctx
->thiscmd
, oldval
, argv
[0]);
1274 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1275 TALLOC_CTX
*mem_ctx
,
1276 struct rpc_sh_ctx
*ctx
,
1277 struct rpc_pipe_client
*pipe_hnd
,
1278 int argc
, const char **argv
)
1280 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1281 rpc_sh_user_flag_edit_internals
);
1284 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1285 TALLOC_CTX
*mem_ctx
,
1286 struct rpc_sh_ctx
*ctx
)
1288 static struct rpc_sh_cmd cmds
[] = {
1290 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1291 "Show/Set a user's full name" },
1293 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1294 "Show/Set a user's home directory" },
1296 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1297 "Show/Set a user's home drive" },
1299 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1300 "Show/Set a user's logon script" },
1302 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1303 "Show/Set a user's profile path" },
1305 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1306 "Show/Set a user's description" },
1308 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1309 "Show/Set whether a user is disabled" },
1311 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1312 "Show/Set whether a user locked out" },
1314 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1315 "Show/Set whether a user does not need a password" },
1317 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1318 "Show/Set whether a user's password does not expire" },
1320 { NULL
, NULL
, 0, NULL
, NULL
}
1326 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1327 TALLOC_CTX
*mem_ctx
,
1328 struct rpc_sh_ctx
*ctx
)
1330 static struct rpc_sh_cmd cmds
[] = {
1332 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1333 "List available users" },
1335 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1336 "List the domain groups a user is member of" },
1338 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1339 "Show info about a user" },
1341 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1342 "Show/Modify a user's fields" },
1344 { NULL
, NULL
, 0, NULL
, NULL
}
1350 /****************************************************************************/
1353 * Basic usage function for 'net rpc group'.
1354 * @param argc Standard main() style argc.
1355 * @param argv Standard main() style argv. Initial components are already
1359 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1361 return net_group_usage(c
, argc
, argv
);
1365 * Delete group on a remote RPC server.
1367 * All parameters are provided by the run_rpc_command function, except for
1368 * argc, argv which are passed through.
1370 * @param domain_sid The domain sid acquired from the remote server.
1371 * @param cli A cli_state connected to the server.
1372 * @param mem_ctx Talloc context, destroyed on completion of the function.
1373 * @param argc Standard main() style argc.
1374 * @param argv Standard main() style argv. Initial components are already
1377 * @return Normal NTSTATUS return.
1380 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1381 const DOM_SID
*domain_sid
,
1382 const char *domain_name
,
1383 struct cli_state
*cli
,
1384 struct rpc_pipe_client
*pipe_hnd
,
1385 TALLOC_CTX
*mem_ctx
,
1389 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1390 bool group_is_primary
= false;
1391 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1393 struct samr_RidTypeArray
*rids
= NULL
;
1396 /* struct samr_RidWithAttribute *user_gids; */
1398 struct samr_Ids group_rids
, name_types
;
1399 struct lsa_String lsa_acct_name
;
1400 union samr_UserInfo
*info
= NULL
;
1402 if (argc
< 1 || c
->display_usage
) {
1403 rpc_group_usage(c
, argc
,argv
);
1404 return NT_STATUS_OK
; /* ok? */
1407 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1409 MAXIMUM_ALLOWED_ACCESS
,
1412 if (!NT_STATUS_IS_OK(result
)) {
1413 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1417 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1419 MAXIMUM_ALLOWED_ACCESS
,
1420 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1423 if (!NT_STATUS_IS_OK(result
)) {
1424 d_fprintf(stderr
, "Request open_domain failed\n");
1428 init_lsa_String(&lsa_acct_name
, argv
[0]);
1430 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1436 if (!NT_STATUS_IS_OK(result
)) {
1437 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1441 switch (name_types
.ids
[0])
1443 case SID_NAME_DOM_GRP
:
1444 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1446 MAXIMUM_ALLOWED_ACCESS
,
1449 if (!NT_STATUS_IS_OK(result
)) {
1450 d_fprintf(stderr
, "Request open_group failed");
1454 group_rid
= group_rids
.ids
[0];
1456 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1460 if (!NT_STATUS_IS_OK(result
)) {
1461 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1465 if (c
->opt_verbose
) {
1466 d_printf("Domain Group %s (rid: %d) has %d members\n",
1467 argv
[0],group_rid
, rids
->count
);
1470 /* Check if group is anyone's primary group */
1471 for (i
= 0; i
< rids
->count
; i
++)
1473 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1475 MAXIMUM_ALLOWED_ACCESS
,
1479 if (!NT_STATUS_IS_OK(result
)) {
1480 d_fprintf(stderr
, "Unable to open group member %d\n",
1485 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1490 if (!NT_STATUS_IS_OK(result
)) {
1491 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1496 if (info
->info21
.primary_gid
== group_rid
) {
1497 if (c
->opt_verbose
) {
1498 d_printf("Group is primary group of %s\n",
1499 info
->info21
.account_name
.string
);
1501 group_is_primary
= true;
1504 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1507 if (group_is_primary
) {
1508 d_fprintf(stderr
, "Unable to delete group because some "
1509 "of it's members have it as primary group\n");
1510 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1514 /* remove all group members */
1515 for (i
= 0; i
< rids
->count
; i
++)
1518 d_printf("Remove group member %d...",
1520 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1524 if (NT_STATUS_IS_OK(result
)) {
1529 d_printf("failed\n");
1534 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1538 /* removing a local group is easier... */
1539 case SID_NAME_ALIAS
:
1540 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1542 MAXIMUM_ALLOWED_ACCESS
,
1546 if (!NT_STATUS_IS_OK(result
)) {
1547 d_fprintf(stderr
, "Request open_alias failed\n");
1551 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1555 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1556 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1557 result
= NT_STATUS_UNSUCCESSFUL
;
1561 if (NT_STATUS_IS_OK(result
)) {
1563 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1565 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1566 get_friendly_nt_error_msg(result
));
1574 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1576 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1577 rpc_group_delete_internals
, argc
,argv
);
1580 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1582 NET_API_STATUS status
;
1583 struct GROUP_INFO_1 info1
;
1584 uint32_t parm_error
= 0;
1586 if (argc
!= 1 || c
->display_usage
) {
1587 rpc_group_usage(c
, argc
, argv
);
1593 info1
.grpi1_name
= argv
[0];
1594 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1595 info1
.grpi1_comment
= c
->opt_comment
;
1598 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1601 d_fprintf(stderr
, "Failed to add group '%s' with: %s.\n",
1602 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1606 d_printf("Added group '%s'.\n", argv
[0]);
1612 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1614 NET_API_STATUS status
;
1615 struct LOCALGROUP_INFO_1 info1
;
1616 uint32_t parm_error
= 0;
1618 if (argc
!= 1 || c
->display_usage
) {
1619 rpc_group_usage(c
, argc
, argv
);
1625 info1
.lgrpi1_name
= argv
[0];
1626 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1627 info1
.lgrpi1_comment
= c
->opt_comment
;
1630 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1633 d_fprintf(stderr
, "Failed to add alias '%s' with: %s.\n",
1634 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1638 d_printf("Added alias '%s'.\n", argv
[0]);
1644 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1646 if (c
->opt_localgroup
)
1647 return rpc_alias_add_internals(c
, argc
, argv
);
1649 return rpc_group_add_internals(c
, argc
, argv
);
1652 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1653 TALLOC_CTX
*mem_ctx
,
1656 enum lsa_SidType
*type
)
1658 DOM_SID
*sids
= NULL
;
1659 enum lsa_SidType
*types
= NULL
;
1660 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1661 struct policy_handle lsa_pol
;
1662 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1664 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1666 if (!NT_STATUS_IS_OK(result
)) {
1670 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1671 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1673 if (!NT_STATUS_IS_OK(result
)) {
1677 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1678 &name
, NULL
, 1, &sids
, &types
);
1680 if (NT_STATUS_IS_OK(result
)) {
1681 sid_copy(sid
, &sids
[0]);
1685 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1689 TALLOC_FREE(pipe_hnd
);
1692 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1694 /* Try as S-1-5-whatever */
1698 if (string_to_sid(&tmp_sid
, name
)) {
1699 sid_copy(sid
, &tmp_sid
);
1700 *type
= SID_NAME_UNKNOWN
;
1701 result
= NT_STATUS_OK
;
1708 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1709 TALLOC_CTX
*mem_ctx
,
1710 const DOM_SID
*group_sid
,
1713 struct policy_handle connect_pol
, domain_pol
;
1716 struct policy_handle group_pol
;
1718 struct samr_Ids rids
, rid_types
;
1719 struct lsa_String lsa_acct_name
;
1723 sid_copy(&sid
, group_sid
);
1725 if (!sid_split_rid(&sid
, &group_rid
)) {
1726 return NT_STATUS_UNSUCCESSFUL
;
1729 /* Get sam policy handle */
1730 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1732 MAXIMUM_ALLOWED_ACCESS
,
1734 if (!NT_STATUS_IS_OK(result
)) {
1738 /* Get domain policy handle */
1739 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1741 MAXIMUM_ALLOWED_ACCESS
,
1744 if (!NT_STATUS_IS_OK(result
)) {
1748 init_lsa_String(&lsa_acct_name
, member
);
1750 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1757 if (!NT_STATUS_IS_OK(result
)) {
1758 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1762 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1764 MAXIMUM_ALLOWED_ACCESS
,
1768 if (!NT_STATUS_IS_OK(result
)) {
1772 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1775 0x0005); /* unknown flags */
1778 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1782 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1783 TALLOC_CTX
*mem_ctx
,
1784 const DOM_SID
*alias_sid
,
1787 struct policy_handle connect_pol
, domain_pol
;
1790 struct policy_handle alias_pol
;
1793 enum lsa_SidType member_type
;
1797 sid_copy(&sid
, alias_sid
);
1799 if (!sid_split_rid(&sid
, &alias_rid
)) {
1800 return NT_STATUS_UNSUCCESSFUL
;
1803 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1804 member
, &member_sid
, &member_type
);
1806 if (!NT_STATUS_IS_OK(result
)) {
1807 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1811 /* Get sam policy handle */
1812 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1814 MAXIMUM_ALLOWED_ACCESS
,
1816 if (!NT_STATUS_IS_OK(result
)) {
1820 /* Get domain policy handle */
1821 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1823 MAXIMUM_ALLOWED_ACCESS
,
1826 if (!NT_STATUS_IS_OK(result
)) {
1830 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1832 MAXIMUM_ALLOWED_ACCESS
,
1836 if (!NT_STATUS_IS_OK(result
)) {
1840 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1844 if (!NT_STATUS_IS_OK(result
)) {
1849 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1853 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1854 const DOM_SID
*domain_sid
,
1855 const char *domain_name
,
1856 struct cli_state
*cli
,
1857 struct rpc_pipe_client
*pipe_hnd
,
1858 TALLOC_CTX
*mem_ctx
,
1863 enum lsa_SidType group_type
;
1865 if (argc
!= 2 || c
->display_usage
) {
1867 "net rpc group addmem <group> <member>\n"
1868 " Add a member to a group\n"
1869 " group\tGroup to add member to\n"
1870 " member\tMember to add to group\n");
1871 return NT_STATUS_UNSUCCESSFUL
;
1874 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1875 &group_sid
, &group_type
))) {
1876 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
1877 return NT_STATUS_UNSUCCESSFUL
;
1880 if (group_type
== SID_NAME_DOM_GRP
) {
1881 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1882 &group_sid
, argv
[1]);
1884 if (!NT_STATUS_IS_OK(result
)) {
1885 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1886 argv
[1], argv
[0], nt_errstr(result
));
1891 if (group_type
== SID_NAME_ALIAS
) {
1892 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1893 &group_sid
, argv
[1]);
1895 if (!NT_STATUS_IS_OK(result
)) {
1896 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1897 argv
[1], argv
[0], nt_errstr(result
));
1902 d_fprintf(stderr
, "Can only add members to global or local groups "
1903 "which %s is not\n", argv
[0]);
1905 return NT_STATUS_UNSUCCESSFUL
;
1908 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1910 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1911 rpc_group_addmem_internals
,
1915 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1916 struct rpc_pipe_client
*pipe_hnd
,
1917 TALLOC_CTX
*mem_ctx
,
1918 const DOM_SID
*group_sid
,
1921 struct policy_handle connect_pol
, domain_pol
;
1924 struct policy_handle group_pol
;
1926 struct samr_Ids rids
, rid_types
;
1927 struct lsa_String lsa_acct_name
;
1931 sid_copy(&sid
, group_sid
);
1933 if (!sid_split_rid(&sid
, &group_rid
))
1934 return NT_STATUS_UNSUCCESSFUL
;
1936 /* Get sam policy handle */
1937 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1939 MAXIMUM_ALLOWED_ACCESS
,
1941 if (!NT_STATUS_IS_OK(result
))
1944 /* Get domain policy handle */
1945 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1947 MAXIMUM_ALLOWED_ACCESS
,
1950 if (!NT_STATUS_IS_OK(result
))
1953 init_lsa_String(&lsa_acct_name
, member
);
1955 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1961 if (!NT_STATUS_IS_OK(result
)) {
1962 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1966 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1968 MAXIMUM_ALLOWED_ACCESS
,
1972 if (!NT_STATUS_IS_OK(result
))
1975 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1980 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1984 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1985 TALLOC_CTX
*mem_ctx
,
1986 const DOM_SID
*alias_sid
,
1989 struct policy_handle connect_pol
, domain_pol
;
1992 struct policy_handle alias_pol
;
1995 enum lsa_SidType member_type
;
1999 sid_copy(&sid
, alias_sid
);
2001 if (!sid_split_rid(&sid
, &alias_rid
))
2002 return NT_STATUS_UNSUCCESSFUL
;
2004 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2005 member
, &member_sid
, &member_type
);
2007 if (!NT_STATUS_IS_OK(result
)) {
2008 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2012 /* Get sam policy handle */
2013 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2015 MAXIMUM_ALLOWED_ACCESS
,
2017 if (!NT_STATUS_IS_OK(result
)) {
2021 /* Get domain policy handle */
2022 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2024 MAXIMUM_ALLOWED_ACCESS
,
2027 if (!NT_STATUS_IS_OK(result
)) {
2031 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2033 MAXIMUM_ALLOWED_ACCESS
,
2037 if (!NT_STATUS_IS_OK(result
))
2040 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2044 if (!NT_STATUS_IS_OK(result
))
2048 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2052 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2053 const DOM_SID
*domain_sid
,
2054 const char *domain_name
,
2055 struct cli_state
*cli
,
2056 struct rpc_pipe_client
*pipe_hnd
,
2057 TALLOC_CTX
*mem_ctx
,
2062 enum lsa_SidType group_type
;
2064 if (argc
!= 2 || c
->display_usage
) {
2066 "net rpc group delmem <group> <member>\n"
2067 " Delete a member from a group\n"
2068 " group\tGroup to delete member from\n"
2069 " member\tMember to delete from group\n");
2070 return NT_STATUS_UNSUCCESSFUL
;
2073 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2074 &group_sid
, &group_type
))) {
2075 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2076 return NT_STATUS_UNSUCCESSFUL
;
2079 if (group_type
== SID_NAME_DOM_GRP
) {
2080 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2081 &group_sid
, argv
[1]);
2083 if (!NT_STATUS_IS_OK(result
)) {
2084 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2085 argv
[1], argv
[0], nt_errstr(result
));
2090 if (group_type
== SID_NAME_ALIAS
) {
2091 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2092 &group_sid
, argv
[1]);
2094 if (!NT_STATUS_IS_OK(result
)) {
2095 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2096 argv
[1], argv
[0], nt_errstr(result
));
2101 d_fprintf(stderr
, "Can only delete members from global or local groups "
2102 "which %s is not\n", argv
[0]);
2104 return NT_STATUS_UNSUCCESSFUL
;
2107 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2109 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2110 rpc_group_delmem_internals
,
2115 * List groups on a remote RPC server.
2117 * All parameters are provided by the run_rpc_command function, except for
2118 * argc, argv which are passes through.
2120 * @param domain_sid The domain sid acquired from the remote server.
2121 * @param cli A cli_state connected to the server.
2122 * @param mem_ctx Talloc context, destroyed on completion of the function.
2123 * @param argc Standard main() style argc.
2124 * @param argv Standard main() style argv. Initial components are already
2127 * @return Normal NTSTATUS return.
2130 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2131 const DOM_SID
*domain_sid
,
2132 const char *domain_name
,
2133 struct cli_state
*cli
,
2134 struct rpc_pipe_client
*pipe_hnd
,
2135 TALLOC_CTX
*mem_ctx
,
2139 struct policy_handle connect_pol
, domain_pol
;
2140 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2141 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2142 struct samr_SamArray
*groups
= NULL
;
2143 bool global
= false;
2145 bool builtin
= false;
2147 if (c
->display_usage
) {
2149 "net rpc group list [global] [local] [builtin]\n"
2150 " List groups on RPC server\n"
2151 " global\tList global groups\n"
2152 " local\tList local groups\n"
2153 " builtin\tList builtin groups\n"
2154 " If none of global, local or builtin is "
2155 "specified, all three options are considered set\n");
2156 return NT_STATUS_OK
;
2165 for (i
=0; i
<argc
; i
++) {
2166 if (strequal(argv
[i
], "global"))
2169 if (strequal(argv
[i
], "local"))
2172 if (strequal(argv
[i
], "builtin"))
2176 /* Get sam policy handle */
2178 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2180 MAXIMUM_ALLOWED_ACCESS
,
2182 if (!NT_STATUS_IS_OK(result
)) {
2186 /* Get domain policy handle */
2188 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2190 MAXIMUM_ALLOWED_ACCESS
,
2191 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2193 if (!NT_STATUS_IS_OK(result
)) {
2197 /* Query domain groups */
2198 if (c
->opt_long_list_entries
)
2199 d_printf("\nGroup name Comment"
2200 "\n-----------------------------\n");
2202 uint32_t max_size
, total_size
, returned_size
;
2203 union samr_DispInfo info
;
2207 get_query_dispinfo_params(
2208 loop_count
, &max_entries
, &max_size
);
2210 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2219 num_entries
= info
.info3
.count
;
2220 start_idx
+= info
.info3
.count
;
2222 if (!NT_STATUS_IS_OK(result
) &&
2223 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2226 for (i
= 0; i
< num_entries
; i
++) {
2228 const char *group
= NULL
;
2229 const char *desc
= NULL
;
2231 group
= info
.info3
.entries
[i
].account_name
.string
;
2232 desc
= info
.info3
.entries
[i
].description
.string
;
2234 if (c
->opt_long_list_entries
)
2235 printf("%-21.21s %-50.50s\n",
2238 printf("%s\n", group
);
2240 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2241 /* query domain aliases */
2246 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2252 if (!NT_STATUS_IS_OK(result
) &&
2253 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2256 for (i
= 0; i
< num_entries
; i
++) {
2258 const char *description
= NULL
;
2260 if (c
->opt_long_list_entries
) {
2262 struct policy_handle alias_pol
;
2263 union samr_AliasInfo
*info
= NULL
;
2265 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2268 groups
->entries
[i
].idx
,
2270 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2274 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2276 description
= info
->description
.string
;
2280 if (description
!= NULL
) {
2281 printf("%-21.21s %-50.50s\n",
2282 groups
->entries
[i
].name
.string
,
2285 printf("%s\n", groups
->entries
[i
].name
.string
);
2288 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2289 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2290 /* Get builtin policy handle */
2292 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2294 MAXIMUM_ALLOWED_ACCESS
,
2295 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2297 if (!NT_STATUS_IS_OK(result
)) {
2300 /* query builtin aliases */
2303 if (!builtin
) break;
2305 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2311 if (!NT_STATUS_IS_OK(result
) &&
2312 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2315 for (i
= 0; i
< num_entries
; i
++) {
2317 const char *description
= NULL
;
2319 if (c
->opt_long_list_entries
) {
2321 struct policy_handle alias_pol
;
2322 union samr_AliasInfo
*info
= NULL
;
2324 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2327 groups
->entries
[i
].idx
,
2329 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2333 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2335 description
= info
->description
.string
;
2339 if (description
!= NULL
) {
2340 printf("%-21.21s %-50.50s\n",
2341 groups
->entries
[i
].name
.string
,
2344 printf("%s\n", groups
->entries
[i
].name
.string
);
2347 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2353 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2355 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2356 rpc_group_list_internals
,
2360 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2361 struct rpc_pipe_client
*pipe_hnd
,
2362 TALLOC_CTX
*mem_ctx
,
2363 const char *domain_name
,
2364 const DOM_SID
*domain_sid
,
2365 struct policy_handle
*domain_pol
,
2369 struct policy_handle group_pol
;
2370 uint32 num_members
, *group_rids
;
2372 struct samr_RidTypeArray
*rids
= NULL
;
2373 struct lsa_Strings names
;
2374 struct samr_Ids types
;
2377 sid_to_fstring(sid_str
, domain_sid
);
2379 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2381 MAXIMUM_ALLOWED_ACCESS
,
2385 if (!NT_STATUS_IS_OK(result
))
2388 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2392 if (!NT_STATUS_IS_OK(result
))
2395 num_members
= rids
->count
;
2396 group_rids
= rids
->rids
;
2398 while (num_members
> 0) {
2399 int this_time
= 512;
2401 if (num_members
< this_time
)
2402 this_time
= num_members
;
2404 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2411 if (!NT_STATUS_IS_OK(result
))
2414 /* We only have users as members, but make the output
2415 the same as the output of alias members */
2417 for (i
= 0; i
< this_time
; i
++) {
2419 if (c
->opt_long_list_entries
) {
2420 printf("%s-%d %s\\%s %d\n", sid_str
,
2421 group_rids
[i
], domain_name
,
2422 names
.names
[i
].string
,
2425 printf("%s\\%s\n", domain_name
,
2426 names
.names
[i
].string
);
2430 num_members
-= this_time
;
2434 return NT_STATUS_OK
;
2437 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2438 struct rpc_pipe_client
*pipe_hnd
,
2439 TALLOC_CTX
*mem_ctx
,
2440 struct policy_handle
*domain_pol
,
2444 struct rpc_pipe_client
*lsa_pipe
;
2445 struct policy_handle alias_pol
, lsa_pol
;
2447 DOM_SID
*alias_sids
;
2450 enum lsa_SidType
*types
;
2452 struct lsa_SidArray sid_array
;
2454 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2456 MAXIMUM_ALLOWED_ACCESS
,
2460 if (!NT_STATUS_IS_OK(result
))
2463 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2467 if (!NT_STATUS_IS_OK(result
)) {
2468 d_fprintf(stderr
, "Couldn't list alias members\n");
2472 num_members
= sid_array
.num_sids
;
2474 if (num_members
== 0) {
2475 return NT_STATUS_OK
;
2478 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2479 &ndr_table_lsarpc
.syntax_id
,
2481 if (!NT_STATUS_IS_OK(result
)) {
2482 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2483 nt_errstr(result
) );
2487 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2488 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2490 if (!NT_STATUS_IS_OK(result
)) {
2491 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2492 TALLOC_FREE(lsa_pipe
);
2496 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2498 d_fprintf(stderr
, "Out of memory\n");
2499 TALLOC_FREE(lsa_pipe
);
2500 return NT_STATUS_NO_MEMORY
;
2503 for (i
=0; i
<num_members
; i
++) {
2504 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2507 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2508 num_members
, alias_sids
,
2509 &domains
, &names
, &types
);
2511 if (!NT_STATUS_IS_OK(result
) &&
2512 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2513 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2514 TALLOC_FREE(lsa_pipe
);
2518 for (i
= 0; i
< num_members
; i
++) {
2520 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2522 if (c
->opt_long_list_entries
) {
2523 printf("%s %s\\%s %d\n", sid_str
,
2524 domains
[i
] ? domains
[i
] : "*unknown*",
2525 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2528 printf("%s\\%s\n", domains
[i
], names
[i
]);
2530 printf("%s\n", sid_str
);
2534 TALLOC_FREE(lsa_pipe
);
2535 return NT_STATUS_OK
;
2538 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2539 const DOM_SID
*domain_sid
,
2540 const char *domain_name
,
2541 struct cli_state
*cli
,
2542 struct rpc_pipe_client
*pipe_hnd
,
2543 TALLOC_CTX
*mem_ctx
,
2548 struct policy_handle connect_pol
, domain_pol
;
2549 struct samr_Ids rids
, rid_types
;
2550 struct lsa_String lsa_acct_name
;
2552 /* Get sam policy handle */
2554 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2556 MAXIMUM_ALLOWED_ACCESS
,
2559 if (!NT_STATUS_IS_OK(result
))
2562 /* Get domain policy handle */
2564 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2566 MAXIMUM_ALLOWED_ACCESS
,
2567 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2570 if (!NT_STATUS_IS_OK(result
))
2573 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2575 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2582 if (!NT_STATUS_IS_OK(result
)) {
2584 /* Ok, did not find it in the global sam, try with builtin */
2586 DOM_SID sid_Builtin
;
2588 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2590 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2592 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2594 MAXIMUM_ALLOWED_ACCESS
,
2598 if (!NT_STATUS_IS_OK(result
)) {
2599 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2603 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2610 if (!NT_STATUS_IS_OK(result
)) {
2611 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2616 if (rids
.count
!= 1) {
2617 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2621 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2622 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2623 domain_sid
, &domain_pol
,
2627 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2628 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2632 return NT_STATUS_NO_SUCH_GROUP
;
2635 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2637 if (argc
!= 1 || c
->display_usage
) {
2638 return rpc_group_usage(c
, argc
, argv
);
2641 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2642 rpc_group_members_internals
,
2646 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2648 NET_API_STATUS status
;
2649 struct GROUP_INFO_0 g0
;
2653 d_printf("Usage: 'net rpc group rename group newname'\n");
2657 g0
.grpi0_name
= argv
[1];
2659 status
= NetGroupSetInfo(c
->opt_host
,
2666 d_fprintf(stderr
, "Renaming group %s failed with: %s\n",
2667 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2675 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2677 if (argc
!= 2 || c
->display_usage
) {
2678 return rpc_group_usage(c
, argc
, argv
);
2681 return rpc_group_rename_internals(c
, argc
, argv
);
2685 * 'net rpc group' entrypoint.
2686 * @param argc Standard main() style argc.
2687 * @param argv Standard main() style argv. Initial components are already
2691 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2693 NET_API_STATUS status
;
2695 struct functable func
[] = {
2700 "Create specified group",
2701 "net rpc group add\n"
2702 " Create specified group"
2708 "Delete specified group",
2709 "net rpc group delete\n"
2710 " Delete specified group"
2716 "Add member to group",
2717 "net rpc group addmem\n"
2718 " Add member to group"
2724 "Remove member from group",
2725 "net rpc group delmem\n"
2726 " Remove member from group"
2733 "net rpc group list\n"
2740 "List group members",
2741 "net rpc group members\n"
2742 " List group members"
2749 "net rpc group rename\n"
2752 {NULL
, NULL
, 0, NULL
, NULL
}
2755 status
= libnetapi_init(&c
->netapi_ctx
);
2759 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2760 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2761 if (c
->opt_kerberos
) {
2762 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2766 if (c
->display_usage
) {
2767 d_printf("Usage:\n");
2768 d_printf("net rpc group\n"
2769 " Alias for net rpc group list global local "
2771 net_display_usage_from_functable(func
);
2775 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2776 rpc_group_list_internals
,
2780 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2783 /****************************************************************************/
2785 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2787 return net_share_usage(c
, argc
, argv
);
2791 * Add a share on a remote RPC server.
2793 * @param argc Standard main() style argc.
2794 * @param argv Standard main() style argv. Initial components are already
2797 * @return A shell status integer (0 for success).
2800 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2802 NET_API_STATUS status
;
2805 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2806 uint32 num_users
=0, perms
=0;
2807 char *password
=NULL
; /* don't allow a share password */
2808 struct SHARE_INFO_2 i2
;
2809 uint32_t parm_error
= 0;
2811 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2812 return rpc_share_usage(c
, argc
, argv
);
2815 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2819 path
= strchr(sharename
, '=');
2826 i2
.shi2_netname
= sharename
;
2827 i2
.shi2_type
= type
;
2828 i2
.shi2_remark
= c
->opt_comment
;
2829 i2
.shi2_permissions
= perms
;
2830 i2
.shi2_max_uses
= c
->opt_maxusers
;
2831 i2
.shi2_current_uses
= num_users
;
2832 i2
.shi2_path
= path
;
2833 i2
.shi2_passwd
= password
;
2835 status
= NetShareAdd(c
->opt_host
,
2840 printf("NetShareAdd failed with: %s\n",
2841 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2848 * Delete a share on a remote RPC server.
2850 * @param domain_sid The domain sid acquired from the remote server.
2851 * @param argc Standard main() style argc.
2852 * @param argv Standard main() style argv. Initial components are already
2855 * @return A shell status integer (0 for success).
2857 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2859 if (argc
< 1 || c
->display_usage
) {
2860 return rpc_share_usage(c
, argc
, argv
);
2863 return NetShareDel(c
->opt_host
, argv
[0], 0);
2867 * Formatted print of share info
2869 * @param r pointer to SHARE_INFO_1 to format
2872 static void display_share_info_1(struct net_context
*c
,
2873 struct SHARE_INFO_1
*r
)
2875 if (c
->opt_long_list_entries
) {
2876 d_printf("%-12s %-8.8s %-50s\n",
2878 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2881 d_printf("%s\n", r
->shi1_netname
);
2885 static WERROR
get_share_info(struct net_context
*c
,
2886 struct rpc_pipe_client
*pipe_hnd
,
2887 TALLOC_CTX
*mem_ctx
,
2891 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2895 union srvsvc_NetShareInfo info
;
2897 /* no specific share requested, enumerate all */
2900 uint32_t preferred_len
= 0xffffffff;
2901 uint32_t total_entries
= 0;
2902 uint32_t resume_handle
= 0;
2904 info_ctr
->level
= level
;
2906 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2916 /* request just one share */
2917 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2924 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2929 ZERO_STRUCTP(info_ctr
);
2931 info_ctr
->level
= level
;
2936 struct srvsvc_NetShareCtr1
*ctr1
;
2938 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2939 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2942 ctr1
->array
= info
.info1
;
2944 info_ctr
->ctr
.ctr1
= ctr1
;
2948 struct srvsvc_NetShareCtr2
*ctr2
;
2950 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2951 W_ERROR_HAVE_NO_MEMORY(ctr2
);
2954 ctr2
->array
= info
.info2
;
2956 info_ctr
->ctr
.ctr2
= ctr2
;
2960 struct srvsvc_NetShareCtr502
*ctr502
;
2962 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
2963 W_ERROR_HAVE_NO_MEMORY(ctr502
);
2966 ctr502
->array
= info
.info502
;
2968 info_ctr
->ctr
.ctr502
= ctr502
;
2976 * 'net rpc share list' entrypoint.
2977 * @param argc Standard main() style argc.
2978 * @param argv Standard main() style argv. Initial components are already
2981 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
2983 NET_API_STATUS status
;
2984 struct SHARE_INFO_1
*i1
= NULL
;
2985 uint32_t entries_read
= 0;
2986 uint32_t total_entries
= 0;
2987 uint32_t resume_handle
= 0;
2988 uint32_t i
, level
= 1;
2990 if (c
->display_usage
) {
2992 "net rpc share list\n"
2993 " List shares on remote server\n");
2997 status
= NetShareEnum(c
->opt_host
,
2999 (uint8_t **)(void *)&i1
,
3008 /* Display results */
3010 if (c
->opt_long_list_entries
) {
3012 "\nEnumerating shared resources (exports) on remote server:\n\n"
3013 "\nShare name Type Description\n"
3014 "---------- ---- -----------\n");
3016 for (i
= 0; i
< entries_read
; i
++)
3017 display_share_info_1(c
, &i1
[i
]);
3022 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3024 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3025 d_printf("skipping [%s]: not a file share.\n", netname
);
3035 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3036 const char *netname
, uint32 type
)
3038 /* only support disk shares */
3039 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3040 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3044 /* skip builtin shares */
3045 /* FIXME: should print$ be added too ? */
3046 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3047 strequal(netname
,"global"))
3050 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3051 printf("excluding [%s]\n", netname
);
3055 return check_share_availability(cli
, netname
);
3059 * Migrate shares from a remote RPC server to the local RPC server.
3061 * All parameters are provided by the run_rpc_command function, except for
3062 * argc, argv which are passed through.
3064 * @param domain_sid The domain sid acquired from the remote server.
3065 * @param cli A cli_state connected to the server.
3066 * @param mem_ctx Talloc context, destroyed on completion of the function.
3067 * @param argc Standard main() style argc.
3068 * @param argv Standard main() style argv. Initial components are already
3071 * @return Normal NTSTATUS return.
3074 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3075 const DOM_SID
*domain_sid
,
3076 const char *domain_name
,
3077 struct cli_state
*cli
,
3078 struct rpc_pipe_client
*pipe_hnd
,
3079 TALLOC_CTX
*mem_ctx
,
3084 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3085 struct srvsvc_NetShareInfoCtr ctr_src
;
3087 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3088 struct cli_state
*cli_dst
= NULL
;
3089 uint32 level
= 502; /* includes secdesc */
3090 uint32_t parm_error
= 0;
3092 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3094 if (!W_ERROR_IS_OK(result
))
3097 /* connect destination PI_SRVSVC */
3098 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3099 &ndr_table_srvsvc
.syntax_id
);
3100 if (!NT_STATUS_IS_OK(nt_status
))
3104 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3106 union srvsvc_NetShareInfo info
;
3107 struct srvsvc_NetShareInfo502 info502
=
3108 ctr_src
.ctr
.ctr502
->array
[i
];
3110 /* reset error-code */
3111 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3113 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3116 /* finally add the share on the dst server */
3118 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3119 info502
.name
, info502
.path
, info502
.comment
);
3121 info
.info502
= &info502
;
3123 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3124 srvsvc_pipe
->desthost
,
3130 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3131 printf(" [%s] does already exist\n",
3136 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3137 printf("cannot add share: %s\n", win_errstr(result
));
3143 nt_status
= NT_STATUS_OK
;
3147 cli_shutdown(cli_dst
);
3155 * Migrate shares from a RPC server to another.
3157 * @param argc Standard main() style argc.
3158 * @param argv Standard main() style argv. Initial components are already
3161 * @return A shell status integer (0 for success).
3163 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3166 if (c
->display_usage
) {
3168 "net rpc share migrate shares\n"
3169 " Migrate shares to local server\n");
3174 printf("no server to migrate\n");
3178 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3179 rpc_share_migrate_shares_internals
,
3186 * @param f file_info
3187 * @param mask current search mask
3188 * @param state arg-pointer
3191 static void copy_fn(const char *mnt
, file_info
*f
,
3192 const char *mask
, void *state
)
3194 static NTSTATUS nt_status
;
3195 static struct copy_clistate
*local_state
;
3196 static fstring filename
, new_mask
;
3199 struct net_context
*c
;
3201 local_state
= (struct copy_clistate
*)state
;
3202 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3206 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3209 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3212 if (f
->mode
& aDIR
) {
3214 DEBUG(3,("got dir: %s\n", f
->name
));
3216 fstrcpy(dir
, local_state
->cwd
);
3218 fstrcat(dir
, f
->name
);
3220 switch (net_mode_share
)
3222 case NET_MODE_SHARE_MIGRATE
:
3223 /* create that directory */
3224 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3225 local_state
->cli_share_src
,
3226 local_state
->cli_share_dst
,
3228 c
->opt_acls
? true : false,
3229 c
->opt_attrs
? true : false,
3230 c
->opt_timestamps
? true:false,
3234 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3238 if (!NT_STATUS_IS_OK(nt_status
))
3239 printf("could not handle dir %s: %s\n",
3240 dir
, nt_errstr(nt_status
));
3242 /* search below that directory */
3243 fstrcpy(new_mask
, dir
);
3244 fstrcat(new_mask
, "\\*");
3246 old_dir
= local_state
->cwd
;
3247 local_state
->cwd
= dir
;
3248 if (!sync_files(local_state
, new_mask
))
3249 printf("could not handle files\n");
3250 local_state
->cwd
= old_dir
;
3257 fstrcpy(filename
, local_state
->cwd
);
3258 fstrcat(filename
, "\\");
3259 fstrcat(filename
, f
->name
);
3261 DEBUG(3,("got file: %s\n", filename
));
3263 switch (net_mode_share
)
3265 case NET_MODE_SHARE_MIGRATE
:
3266 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3267 local_state
->cli_share_src
,
3268 local_state
->cli_share_dst
,
3270 c
->opt_acls
? true : false,
3271 c
->opt_attrs
? true : false,
3272 c
->opt_timestamps
? true: false,
3276 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3280 if (!NT_STATUS_IS_OK(nt_status
))
3281 printf("could not handle file %s: %s\n",
3282 filename
, nt_errstr(nt_status
));
3287 * sync files, can be called recursivly to list files
3288 * and then call copy_fn for each file
3290 * @param cp_clistate pointer to the copy_clistate we work with
3291 * @param mask the current search mask
3293 * @return Boolean result
3295 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3297 struct cli_state
*targetcli
;
3298 char *targetpath
= NULL
;
3300 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3302 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3303 mask
, &targetcli
, &targetpath
) ) {
3304 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3305 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3309 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3310 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3311 mask
, cli_errstr(targetcli
));
3320 * Set the top level directory permissions before we do any further copies.
3321 * Should set up ACL inheritance.
3324 bool copy_top_level_perms(struct net_context
*c
,
3325 struct copy_clistate
*cp_clistate
,
3326 const char *sharename
)
3328 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3330 switch (net_mode_share
) {
3331 case NET_MODE_SHARE_MIGRATE
:
3332 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3333 nt_status
= net_copy_fileattr(c
,
3334 cp_clistate
->mem_ctx
,
3335 cp_clistate
->cli_share_src
,
3336 cp_clistate
->cli_share_dst
,
3338 c
->opt_acls
? true : false,
3339 c
->opt_attrs
? true : false,
3340 c
->opt_timestamps
? true: false,
3344 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3348 if (!NT_STATUS_IS_OK(nt_status
)) {
3349 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3350 sharename
, nt_errstr(nt_status
));
3358 * Sync all files inside a remote share to another share (over smb).
3360 * All parameters are provided by the run_rpc_command function, except for
3361 * argc, argv which are passed through.
3363 * @param domain_sid The domain sid acquired from the remote server.
3364 * @param cli A cli_state connected to the server.
3365 * @param mem_ctx Talloc context, destroyed on completion of the function.
3366 * @param argc Standard main() style argc.
3367 * @param argv Standard main() style argv. Initial components are already
3370 * @return Normal NTSTATUS return.
3373 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3374 const DOM_SID
*domain_sid
,
3375 const char *domain_name
,
3376 struct cli_state
*cli
,
3377 struct rpc_pipe_client
*pipe_hnd
,
3378 TALLOC_CTX
*mem_ctx
,
3383 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3384 struct srvsvc_NetShareInfoCtr ctr_src
;
3387 struct copy_clistate cp_clistate
;
3388 bool got_src_share
= false;
3389 bool got_dst_share
= false;
3390 const char *mask
= "\\*";
3393 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3395 nt_status
= NT_STATUS_NO_MEMORY
;
3399 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3402 if (!W_ERROR_IS_OK(result
))
3405 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3407 struct srvsvc_NetShareInfo502 info502
=
3408 ctr_src
.ctr
.ctr502
->array
[i
];
3410 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3413 /* one might not want to mirror whole discs :) */
3414 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3415 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3419 switch (net_mode_share
)
3421 case NET_MODE_SHARE_MIGRATE
:
3425 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3428 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3430 c
->opt_acls
? "including" : "without",
3431 c
->opt_attrs
? "including" : "without",
3432 c
->opt_timestamps
? "(preserving timestamps)" : "");
3434 cp_clistate
.mem_ctx
= mem_ctx
;
3435 cp_clistate
.cli_share_src
= NULL
;
3436 cp_clistate
.cli_share_dst
= NULL
;
3437 cp_clistate
.cwd
= NULL
;
3438 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3441 /* open share source */
3442 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3443 &cli
->dest_ss
, cli
->desthost
,
3444 info502
.name
, "A:");
3445 if (!NT_STATUS_IS_OK(nt_status
))
3448 got_src_share
= true;
3450 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3451 /* open share destination */
3452 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3453 NULL
, dst
, info502
.name
, "A:");
3454 if (!NT_STATUS_IS_OK(nt_status
))
3457 got_dst_share
= true;
3460 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3461 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3462 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3466 if (!sync_files(&cp_clistate
, mask
)) {
3467 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3468 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3473 nt_status
= NT_STATUS_OK
;
3478 cli_shutdown(cp_clistate
.cli_share_src
);
3481 cli_shutdown(cp_clistate
.cli_share_dst
);
3488 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3490 if (c
->display_usage
) {
3492 "net share migrate files\n"
3493 " Migrate files to local server\n");
3498 d_printf("no server to migrate\n");
3502 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3503 rpc_share_migrate_files_internals
,
3508 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3510 * All parameters are provided by the run_rpc_command function, except for
3511 * argc, argv which are passed through.
3513 * @param domain_sid The domain sid acquired from the remote server.
3514 * @param cli A cli_state connected to the server.
3515 * @param mem_ctx Talloc context, destroyed on completion of the function.
3516 * @param argc Standard main() style argc.
3517 * @param argv Standard main() style argv. Initial components are already
3520 * @return Normal NTSTATUS return.
3523 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3524 const DOM_SID
*domain_sid
,
3525 const char *domain_name
,
3526 struct cli_state
*cli
,
3527 struct rpc_pipe_client
*pipe_hnd
,
3528 TALLOC_CTX
*mem_ctx
,
3533 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3534 struct srvsvc_NetShareInfoCtr ctr_src
;
3535 union srvsvc_NetShareInfo info
;
3537 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3538 struct cli_state
*cli_dst
= NULL
;
3539 uint32 level
= 502; /* includes secdesc */
3540 uint32_t parm_error
= 0;
3542 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3545 if (!W_ERROR_IS_OK(result
))
3548 /* connect destination PI_SRVSVC */
3549 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3550 &ndr_table_srvsvc
.syntax_id
);
3551 if (!NT_STATUS_IS_OK(nt_status
))
3555 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3557 struct srvsvc_NetShareInfo502 info502
=
3558 ctr_src
.ctr
.ctr502
->array
[i
];
3560 /* reset error-code */
3561 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3563 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3566 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3567 info502
.name
, info502
.path
, info502
.comment
);
3570 display_sec_desc(info502
.sd_buf
.sd
);
3572 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3573 info
.info502
= &info502
;
3575 /* finally modify the share on the dst server */
3576 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3577 srvsvc_pipe
->desthost
,
3583 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3584 printf("cannot set share-acl: %s\n", win_errstr(result
));
3590 nt_status
= NT_STATUS_OK
;
3594 cli_shutdown(cli_dst
);
3602 * Migrate share-acls from a RPC server to another.
3604 * @param argc Standard main() style argc.
3605 * @param argv Standard main() style argv. Initial components are already
3608 * @return A shell status integer (0 for success).
3610 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3613 if (c
->display_usage
) {
3615 "net rpc share migrate security\n"
3616 " Migrate share-acls to local server\n");
3621 d_printf("no server to migrate\n");
3625 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3626 rpc_share_migrate_security_internals
,
3631 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3632 * from one server to another.
3634 * @param argc Standard main() style argc.
3635 * @param argv Standard main() style argv. Initial components are already
3638 * @return A shell status integer (0 for success).
3641 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3646 if (c
->display_usage
) {
3648 "net rpc share migrate all\n"
3649 " Migrates shares including all share settings\n");
3654 d_printf("no server to migrate\n");
3658 /* order is important. we don't want to be locked out by the share-acl
3659 * before copying files - gd */
3661 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3662 rpc_share_migrate_shares_internals
, argc
, argv
);
3666 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3667 rpc_share_migrate_files_internals
, argc
, argv
);
3671 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3672 rpc_share_migrate_security_internals
, argc
,
3678 * 'net rpc share migrate' entrypoint.
3679 * @param argc Standard main() style argc.
3680 * @param argv Standard main() style argv. Initial components are already
3683 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3686 struct functable func
[] = {
3689 rpc_share_migrate_all
,
3691 "Migrate shares from remote to local server",
3692 "net rpc share migrate all\n"
3693 " Migrate shares from remote to local server"
3697 rpc_share_migrate_files
,
3699 "Migrate files from remote to local server",
3700 "net rpc share migrate files\n"
3701 " Migrate files from remote to local server"
3705 rpc_share_migrate_security
,
3707 "Migrate share-ACLs from remote to local server",
3708 "net rpc share migrate security\n"
3709 " Migrate share-ACLs from remote to local server"
3713 rpc_share_migrate_shares
,
3715 "Migrate shares from remote to local server",
3716 "net rpc share migrate shares\n"
3717 " Migrate shares from remote to local server"
3719 {NULL
, NULL
, 0, NULL
, NULL
}
3722 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3724 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3733 static int num_server_aliases
;
3734 static struct full_alias
*server_aliases
;
3737 * Add an alias to the static list.
3739 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3741 if (server_aliases
== NULL
)
3742 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3744 server_aliases
[num_server_aliases
] = *alias
;
3745 num_server_aliases
+= 1;
3749 * For a specific domain on the server, fetch all the aliases
3750 * and their members. Add all of them to the server_aliases.
3753 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3754 TALLOC_CTX
*mem_ctx
,
3755 struct policy_handle
*connect_pol
,
3756 const DOM_SID
*domain_sid
)
3758 uint32 start_idx
, max_entries
, num_entries
, i
;
3759 struct samr_SamArray
*groups
= NULL
;
3761 struct policy_handle domain_pol
;
3763 /* Get domain policy handle */
3765 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3767 MAXIMUM_ALLOWED_ACCESS
,
3768 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3770 if (!NT_STATUS_IS_OK(result
))
3777 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3783 for (i
= 0; i
< num_entries
; i
++) {
3785 struct policy_handle alias_pol
;
3786 struct full_alias alias
;
3787 struct lsa_SidArray sid_array
;
3790 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3792 MAXIMUM_ALLOWED_ACCESS
,
3793 groups
->entries
[i
].idx
,
3795 if (!NT_STATUS_IS_OK(result
))
3798 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3801 if (!NT_STATUS_IS_OK(result
))
3804 alias
.num_members
= sid_array
.num_sids
;
3806 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3807 if (!NT_STATUS_IS_OK(result
))
3810 alias
.members
= NULL
;
3812 if (alias
.num_members
> 0) {
3813 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3815 for (j
= 0; j
< alias
.num_members
; j
++)
3816 sid_copy(&alias
.members
[j
],
3817 sid_array
.sids
[j
].sid
);
3820 sid_copy(&alias
.sid
, domain_sid
);
3821 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3823 push_alias(mem_ctx
, &alias
);
3825 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3827 result
= NT_STATUS_OK
;
3830 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3836 * Dump server_aliases as names for debugging purposes.
3839 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3840 const DOM_SID
*domain_sid
,
3841 const char *domain_name
,
3842 struct cli_state
*cli
,
3843 struct rpc_pipe_client
*pipe_hnd
,
3844 TALLOC_CTX
*mem_ctx
,
3850 struct policy_handle lsa_pol
;
3852 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3853 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3855 if (!NT_STATUS_IS_OK(result
))
3858 for (i
=0; i
<num_server_aliases
; i
++) {
3861 enum lsa_SidType
*types
;
3864 struct full_alias
*alias
= &server_aliases
[i
];
3866 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3868 &domains
, &names
, &types
);
3869 if (!NT_STATUS_IS_OK(result
))
3872 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3874 if (alias
->num_members
== 0) {
3879 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3882 &domains
, &names
, &types
);
3884 if (!NT_STATUS_IS_OK(result
) &&
3885 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3888 for (j
=0; j
<alias
->num_members
; j
++)
3889 DEBUG(1, ("%s\\%s (%d); ",
3890 domains
[j
] ? domains
[j
] : "*unknown*",
3891 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3895 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3897 return NT_STATUS_OK
;
3901 * Fetch a list of all server aliases and their members into
3905 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3906 const DOM_SID
*domain_sid
,
3907 const char *domain_name
,
3908 struct cli_state
*cli
,
3909 struct rpc_pipe_client
*pipe_hnd
,
3910 TALLOC_CTX
*mem_ctx
,
3915 struct policy_handle connect_pol
;
3917 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3919 MAXIMUM_ALLOWED_ACCESS
,
3922 if (!NT_STATUS_IS_OK(result
))
3925 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3926 &global_sid_Builtin
);
3928 if (!NT_STATUS_IS_OK(result
))
3931 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3934 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
3939 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
3941 token
->num_sids
= 4;
3943 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
3944 d_fprintf(stderr
, "malloc failed\n");
3945 token
->num_sids
= 0;
3949 token
->user_sids
[0] = *user_sid
;
3950 sid_copy(&token
->user_sids
[1], &global_sid_World
);
3951 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
3952 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
3955 static void free_user_token(NT_USER_TOKEN
*token
)
3957 SAFE_FREE(token
->user_sids
);
3960 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3962 if (is_sid_in_token(token
, sid
))
3965 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
3966 if (!token
->user_sids
) {
3970 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
3972 token
->num_sids
+= 1;
3977 NT_USER_TOKEN token
;
3980 static void dump_user_token(struct user_token
*token
)
3984 d_printf("%s\n", token
->name
);
3986 for (i
=0; i
<token
->token
.num_sids
; i
++) {
3987 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
3991 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
3995 for (i
=0; i
<alias
->num_members
; i
++) {
3996 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4003 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4007 for (i
=0; i
<num_server_aliases
; i
++) {
4008 if (is_alias_member(&sid
, &server_aliases
[i
]))
4009 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4014 * We got a user token with all the SIDs we can know about without asking the
4015 * server directly. These are the user and domain group sids. All of these can
4016 * be members of aliases. So scan the list of aliases for each of the SIDs and
4017 * add them to the token.
4020 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4022 int num_global_sids
= token
->num_sids
;
4025 for (i
=0; i
<num_global_sids
; i
++) {
4026 collect_sid_memberships(token
, token
->user_sids
[i
]);
4030 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4032 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4033 enum wbcSidType type
;
4035 struct wbcDomainSid wsid
;
4036 char *sid_str
= NULL
;
4038 uint32_t num_groups
;
4039 gid_t
*groups
= NULL
;
4042 fstr_sprintf(full_name
, "%s%c%s",
4043 domain
, *lp_winbind_separator(), user
);
4045 /* First let's find out the user sid */
4047 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4049 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4050 DEBUG(1, ("winbind could not find %s: %s\n",
4051 full_name
, wbcErrorString(wbc_status
)));
4055 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4056 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4060 if (type
!= SID_NAME_USER
) {
4061 wbcFreeMemory(sid_str
);
4062 DEBUG(1, ("%s is not a user\n", full_name
));
4066 if (!string_to_sid(&user_sid
, sid_str
)) {
4067 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4071 wbcFreeMemory(sid_str
);
4074 init_user_token(token
, &user_sid
);
4076 /* And now the groups winbind knows about */
4078 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4079 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4080 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4081 full_name
, wbcErrorString(wbc_status
)));
4085 for (i
= 0; i
< num_groups
; i
++) {
4086 gid_t gid
= groups
[i
];
4089 wbc_status
= wbcGidToSid(gid
, &wsid
);
4090 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4091 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4092 gid
, wbcErrorString(wbc_status
)));
4093 wbcFreeMemory(groups
);
4097 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4098 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4099 wbcFreeMemory(groups
);
4103 DEBUG(3, (" %s\n", sid_str
));
4105 string_to_sid(&sid
, sid_str
);
4106 wbcFreeMemory(sid_str
);
4109 add_sid_to_token(token
, &sid
);
4111 wbcFreeMemory(groups
);
4117 * Get a list of all user tokens we want to look at
4120 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4121 struct user_token
**user_tokens
)
4123 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4124 uint32_t i
, num_users
;
4126 struct user_token
*result
;
4127 TALLOC_CTX
*frame
= NULL
;
4129 if (lp_winbind_use_default_domain() &&
4130 (c
->opt_target_workgroup
== NULL
)) {
4131 d_fprintf(stderr
, "winbind use default domain = yes set, "
4132 "please specify a workgroup\n");
4136 /* Send request to winbind daemon */
4138 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4139 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4140 DEBUG(1, ("winbind could not list users: %s\n",
4141 wbcErrorString(wbc_status
)));
4145 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4147 if (result
== NULL
) {
4148 DEBUG(1, ("Could not malloc sid array\n"));
4149 wbcFreeMemory(users
);
4153 frame
= talloc_stackframe();
4154 for (i
=0; i
< num_users
; i
++) {
4155 fstring domain
, user
;
4158 fstrcpy(result
[i
].name
, users
[i
]);
4160 p
= strchr(users
[i
], *lp_winbind_separator());
4162 DEBUG(3, ("%s\n", users
[i
]));
4165 fstrcpy(domain
, c
->opt_target_workgroup
);
4166 fstrcpy(user
, users
[i
]);
4169 fstrcpy(domain
, users
[i
]);
4174 get_user_sids(domain
, user
, &(result
[i
].token
));
4178 wbcFreeMemory(users
);
4180 *num_tokens
= num_users
;
4181 *user_tokens
= result
;
4186 static bool get_user_tokens_from_file(FILE *f
,
4188 struct user_token
**tokens
)
4190 struct user_token
*token
= NULL
;
4195 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4199 if (line
[strlen(line
)-1] == '\n')
4200 line
[strlen(line
)-1] = '\0';
4202 if (line
[0] == ' ') {
4206 if(!string_to_sid(&sid
, &line
[1])) {
4207 DEBUG(1,("get_user_tokens_from_file: Could "
4208 "not convert sid %s \n",&line
[1]));
4212 if (token
== NULL
) {
4213 DEBUG(0, ("File does not begin with username"));
4217 add_sid_to_token(&token
->token
, &sid
);
4221 /* And a new user... */
4224 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4225 if (*tokens
== NULL
) {
4226 DEBUG(0, ("Could not realloc tokens\n"));
4230 token
= &((*tokens
)[*num_tokens
-1]);
4232 fstrcpy(token
->name
, line
);
4233 token
->token
.num_sids
= 0;
4234 token
->token
.user_sids
= NULL
;
4243 * Show the list of all users that have access to a share
4246 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4247 TALLOC_CTX
*mem_ctx
,
4248 const char *netname
,
4250 struct user_token
*tokens
)
4253 SEC_DESC
*share_sd
= NULL
;
4254 SEC_DESC
*root_sd
= NULL
;
4255 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4257 union srvsvc_NetShareInfo info
;
4262 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4269 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4270 DEBUG(1, ("Coult not query secdesc for share %s\n",
4275 share_sd
= info
.info502
->sd_buf
.sd
;
4276 if (share_sd
== NULL
) {
4277 DEBUG(1, ("Got no secdesc for share %s\n",
4283 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4287 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4290 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4293 for (i
=0; i
<num_tokens
; i
++) {
4296 if (share_sd
!= NULL
) {
4297 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4300 if (!NT_STATUS_IS_OK(status
)) {
4301 DEBUG(1, ("Could not check share_sd for "
4308 if (root_sd
== NULL
) {
4309 d_printf(" %s\n", tokens
[i
].name
);
4313 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4315 if (!NT_STATUS_IS_OK(status
)) {
4316 DEBUG(1, ("Could not check root_sd for user %s\n",
4320 d_printf(" %s\n", tokens
[i
].name
);
4324 cli_close(cli
, fnum
);
4336 static void collect_share(const char *name
, uint32 m
,
4337 const char *comment
, void *state
)
4339 struct share_list
*share_list
= (struct share_list
*)state
;
4341 if (m
!= STYPE_DISKTREE
)
4344 share_list
->num_shares
+= 1;
4345 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4346 if (!share_list
->shares
) {
4347 share_list
->num_shares
= 0;
4350 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4354 * List shares on a remote RPC server, including the security descriptors.
4356 * All parameters are provided by the run_rpc_command function, except for
4357 * argc, argv which are passed through.
4359 * @param domain_sid The domain sid acquired from the remote server.
4360 * @param cli A cli_state connected to the server.
4361 * @param mem_ctx Talloc context, destroyed on completion of the function.
4362 * @param argc Standard main() style argc.
4363 * @param argv Standard main() style argv. Initial components are already
4366 * @return Normal NTSTATUS return.
4369 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4370 const DOM_SID
*domain_sid
,
4371 const char *domain_name
,
4372 struct cli_state
*cli
,
4373 struct rpc_pipe_client
*pipe_hnd
,
4374 TALLOC_CTX
*mem_ctx
,
4383 struct user_token
*tokens
= NULL
;
4386 struct share_list share_list
;
4391 f
= fopen(argv
[0], "r");
4395 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4396 return NT_STATUS_UNSUCCESSFUL
;
4399 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4405 DEBUG(0, ("Could not read users from file\n"));
4406 return NT_STATUS_UNSUCCESSFUL
;
4409 for (i
=0; i
<num_tokens
; i
++)
4410 collect_alias_memberships(&tokens
[i
].token
);
4412 share_list
.num_shares
= 0;
4413 share_list
.shares
= NULL
;
4415 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4418 DEBUG(0, ("Error returning browse list: %s\n",
4423 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4424 char *netname
= share_list
.shares
[i
];
4426 if (netname
[strlen(netname
)-1] == '$')
4429 d_printf("%s\n", netname
);
4431 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4432 num_tokens
, tokens
);
4435 for (i
=0; i
<num_tokens
; i
++) {
4436 free_user_token(&tokens
[i
].token
);
4439 SAFE_FREE(share_list
.shares
);
4441 return NT_STATUS_OK
;
4444 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4449 if (c
->display_usage
) {
4451 "net rpc share allowedusers\n"
4452 " List allowed users\n");
4456 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4457 rpc_aliaslist_internals
,
4462 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4468 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4469 rpc_share_allowedusers_internals
,
4473 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4476 struct user_token
*tokens
= NULL
;
4480 net_usersidlist_usage(c
, argc
, argv
);
4484 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4485 DEBUG(0, ("Could not get the user/sid list\n"));
4489 for (i
=0; i
<num_tokens
; i
++) {
4490 dump_user_token(&tokens
[i
]);
4491 free_user_token(&tokens
[i
].token
);
4498 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4500 d_printf("net usersidlist\n"
4501 "\tprints out a list of all users the running winbind knows\n"
4502 "\tabout, together with all their SIDs. This is used as\n"
4503 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4505 net_common_flags_usage(c
, argc
, argv
);
4510 * 'net rpc share' entrypoint.
4511 * @param argc Standard main() style argc.
4512 * @param argv Standard main() style argv. Initial components are already
4516 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4518 NET_API_STATUS status
;
4520 struct functable func
[] = {
4526 "net rpc share add\n"
4534 "net rpc share delete\n"
4539 rpc_share_allowedusers
,
4541 "Modify allowed users",
4542 "net rpc share allowedusers\n"
4543 " Modify allowed users"
4549 "Migrate share to local server",
4550 "net rpc share migrate\n"
4551 " Migrate share to local server"
4558 "net rpc share list\n"
4561 {NULL
, NULL
, 0, NULL
, NULL
}
4564 status
= libnetapi_init(&c
->netapi_ctx
);
4568 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4569 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4570 if (c
->opt_kerberos
) {
4571 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4575 if (c
->display_usage
) {
4579 " Alias for net rpc share list\n");
4580 net_display_usage_from_functable(func
);
4584 return rpc_share_list(c
, argc
, argv
);
4587 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4590 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4591 TALLOC_CTX
*mem_ctx
,
4592 struct rpc_sh_ctx
*ctx
,
4593 struct rpc_pipe_client
*pipe_hnd
,
4594 int argc
, const char **argv
)
4597 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4600 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4601 TALLOC_CTX
*mem_ctx
,
4602 struct rpc_sh_ctx
*ctx
,
4603 struct rpc_pipe_client
*pipe_hnd
,
4604 int argc
, const char **argv
)
4606 NET_API_STATUS status
;
4607 uint32_t parm_err
= 0;
4608 struct SHARE_INFO_2 i2
;
4610 if ((argc
< 2) || (argc
> 3)) {
4611 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4613 return NT_STATUS_INVALID_PARAMETER
;
4616 i2
.shi2_netname
= argv
[0];
4617 i2
.shi2_type
= STYPE_DISKTREE
;
4618 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4619 i2
.shi2_permissions
= 0;
4620 i2
.shi2_max_uses
= 0;
4621 i2
.shi2_current_uses
= 0;
4622 i2
.shi2_path
= argv
[1];
4623 i2
.shi2_passwd
= NULL
;
4625 status
= NetShareAdd(pipe_hnd
->desthost
,
4630 return werror_to_ntstatus(W_ERROR(status
));
4633 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4634 TALLOC_CTX
*mem_ctx
,
4635 struct rpc_sh_ctx
*ctx
,
4636 struct rpc_pipe_client
*pipe_hnd
,
4637 int argc
, const char **argv
)
4640 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4641 return NT_STATUS_INVALID_PARAMETER
;
4644 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4647 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4648 TALLOC_CTX
*mem_ctx
,
4649 struct rpc_sh_ctx
*ctx
,
4650 struct rpc_pipe_client
*pipe_hnd
,
4651 int argc
, const char **argv
)
4653 union srvsvc_NetShareInfo info
;
4658 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4659 return NT_STATUS_INVALID_PARAMETER
;
4662 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4668 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4672 d_printf("Name: %s\n", info
.info2
->name
);
4673 d_printf("Comment: %s\n", info
.info2
->comment
);
4674 d_printf("Path: %s\n", info
.info2
->path
);
4675 d_printf("Password: %s\n", info
.info2
->password
);
4678 return werror_to_ntstatus(result
);
4681 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4682 struct rpc_sh_ctx
*ctx
)
4684 static struct rpc_sh_cmd cmds
[] = {
4686 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4687 "List available shares" },
4689 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4692 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4695 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4696 "Get information about a share" },
4698 { NULL
, NULL
, 0, NULL
, NULL
}
4704 /****************************************************************************/
4706 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4708 return net_file_usage(c
, argc
, argv
);
4712 * Close a file on a remote RPC server.
4714 * @param argc Standard main() style argc.
4715 * @param argv Standard main() style argv. Initial components are already
4718 * @return A shell status integer (0 for success).
4720 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4722 if (argc
< 1 || c
->display_usage
) {
4723 return rpc_file_usage(c
, argc
, argv
);
4726 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4730 * Formatted print of open file info
4732 * @param r struct FILE_INFO_3 contents
4735 static void display_file_info_3(struct FILE_INFO_3
*r
)
4737 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4738 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4739 r
->fi3_num_locks
, r
->fi3_pathname
);
4743 * List files for a user on a remote RPC server.
4745 * @param argc Standard main() style argc.
4746 * @param argv Standard main() style argv. Initial components are already
4749 * @return A shell status integer (0 for success)..
4752 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4754 NET_API_STATUS status
;
4755 uint32 preferred_len
= 0xffffffff, i
;
4756 const char *username
=NULL
;
4757 uint32_t total_entries
= 0;
4758 uint32_t entries_read
= 0;
4759 uint32_t resume_handle
= 0;
4760 struct FILE_INFO_3
*i3
= NULL
;
4762 if (c
->display_usage
) {
4763 return rpc_file_usage(c
, argc
, argv
);
4766 /* if argc > 0, must be user command */
4768 username
= smb_xstrdup(argv
[0]);
4771 status
= NetFileEnum(c
->opt_host
,
4775 (uint8_t **)(void *)&i3
,
4785 /* Display results */
4788 "\nEnumerating open files on remote server:\n\n"
4789 "\nFileId Opened by Perms Locks Path"
4790 "\n------ --------- ----- ----- ---- \n");
4791 for (i
= 0; i
< entries_read
; i
++) {
4792 display_file_info_3(&i3
[i
]);
4799 * 'net rpc file' entrypoint.
4800 * @param argc Standard main() style argc.
4801 * @param argv Standard main() style argv. Initial components are already
4805 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4807 NET_API_STATUS status
;
4809 struct functable func
[] = {
4814 "Close opened file",
4815 "net rpc file close\n"
4816 " Close opened file"
4822 "List files opened by user",
4823 "net rpc file user\n"
4824 " List files opened by user"
4831 "Display information about opened file",
4832 "net rpc file info\n"
4833 " Display information about opened file"
4836 {NULL
, NULL
, 0, NULL
, NULL
}
4839 status
= libnetapi_init(&c
->netapi_ctx
);
4843 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4844 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4845 if (c
->opt_kerberos
) {
4846 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4850 if (c
->display_usage
) {
4851 d_printf("Usage:\n");
4852 d_printf("net rpc file\n"
4853 " List opened files\n");
4854 net_display_usage_from_functable(func
);
4858 return rpc_file_user(c
, argc
, argv
);
4861 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4865 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4867 * All parameters are provided by the run_rpc_command function, except for
4868 * argc, argv which are passed through.
4870 * @param c A net_context structure.
4871 * @param domain_sid The domain sid acquired from the remote server.
4872 * @param cli A cli_state connected to the server.
4873 * @param mem_ctx Talloc context, destroyed on completion of the function.
4874 * @param argc Standard main() style argc.
4875 * @param argv Standard main() style argv. Initial components are already
4878 * @return Normal NTSTATUS return.
4881 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4882 const DOM_SID
*domain_sid
,
4883 const char *domain_name
,
4884 struct cli_state
*cli
,
4885 struct rpc_pipe_client
*pipe_hnd
,
4886 TALLOC_CTX
*mem_ctx
,
4890 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4892 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4894 if (NT_STATUS_IS_OK(result
)) {
4895 d_printf("\nShutdown successfully aborted\n");
4896 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4898 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4904 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
4906 * All parameters are provided by the run_rpc_command function, except for
4907 * argc, argv which are passed through.
4909 * @param c A net_context structure.
4910 * @param domain_sid The domain sid acquired from the remote server.
4911 * @param cli A cli_state connected to the server.
4912 * @param mem_ctx Talloc context, destroyed on completion of the function.
4913 * @param argc Standard main() style argc.
4914 * @param argv Standard main() style argv. Initial components are already
4917 * @return Normal NTSTATUS return.
4920 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
4921 const DOM_SID
*domain_sid
,
4922 const char *domain_name
,
4923 struct cli_state
*cli
,
4924 struct rpc_pipe_client
*pipe_hnd
,
4925 TALLOC_CTX
*mem_ctx
,
4929 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4931 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4933 if (NT_STATUS_IS_OK(result
)) {
4934 d_printf("\nShutdown successfully aborted\n");
4935 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4937 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
4943 * ABORT the shutdown of a remote RPC server.
4945 * @param argc Standard main() style argc.
4946 * @param argv Standard main() style argv. Initial components are already
4949 * @return A shell status integer (0 for success).
4952 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
4957 if (c
->display_usage
) {
4959 "net rpc abortshutdown\n"
4960 " Abort a scheduled shutdown\n");
4964 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
4965 rpc_shutdown_abort_internals
, argc
, argv
);
4970 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
4972 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
4973 rpc_reg_shutdown_abort_internals
,
4978 * Shut down a remote RPC Server via initshutdown pipe.
4980 * All parameters are provided by the run_rpc_command function, except for
4981 * argc, argv which are passed through.
4983 * @param c A net_context structure.
4984 * @param domain_sid The domain sid acquired from the remote server.
4985 * @param cli A cli_state connected to the server.
4986 * @param mem_ctx Talloc context, destroyed on completion of the function.
4987 * @param argc Standard main() style argc.
4988 * @param argv Standard main() style argv. Initial components are already
4991 * @return Normal NTSTATUS return.
4994 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
4995 const DOM_SID
*domain_sid
,
4996 const char *domain_name
,
4997 struct cli_state
*cli
,
4998 struct rpc_pipe_client
*pipe_hnd
,
4999 TALLOC_CTX
*mem_ctx
,
5003 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5004 const char *msg
= "This machine will be shutdown shortly";
5005 uint32 timeout
= 20;
5006 struct lsa_StringLarge msg_string
;
5008 if (c
->opt_comment
) {
5009 msg
= c
->opt_comment
;
5011 if (c
->opt_timeout
) {
5012 timeout
= c
->opt_timeout
;
5015 msg_string
.string
= msg
;
5017 /* create an entry */
5018 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5019 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5022 if (NT_STATUS_IS_OK(result
)) {
5023 d_printf("\nShutdown of remote machine succeeded\n");
5024 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5026 DEBUG(1,("Shutdown of remote machine failed!\n"));
5032 * Shut down a remote RPC Server via winreg pipe.
5034 * All parameters are provided by the run_rpc_command function, except for
5035 * argc, argv which are passed through.
5037 * @param c A net_context structure.
5038 * @param domain_sid The domain sid acquired from the remote server.
5039 * @param cli A cli_state connected to the server.
5040 * @param mem_ctx Talloc context, destroyed on completion of the function.
5041 * @param argc Standard main() style argc.
5042 * @param argv Standard main() style argv. Initial components are already
5045 * @return Normal NTSTATUS return.
5048 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5049 const DOM_SID
*domain_sid
,
5050 const char *domain_name
,
5051 struct cli_state
*cli
,
5052 struct rpc_pipe_client
*pipe_hnd
,
5053 TALLOC_CTX
*mem_ctx
,
5057 const char *msg
= "This machine will be shutdown shortly";
5058 uint32 timeout
= 20;
5059 struct lsa_StringLarge msg_string
;
5063 if (c
->opt_comment
) {
5064 msg
= c
->opt_comment
;
5066 msg_string
.string
= msg
;
5068 if (c
->opt_timeout
) {
5069 timeout
= c
->opt_timeout
;
5072 /* create an entry */
5073 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5074 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5077 if (NT_STATUS_IS_OK(result
)) {
5078 d_printf("\nShutdown of remote machine succeeded\n");
5080 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5081 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5082 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5084 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5091 * Shut down a remote RPC server.
5093 * @param argc Standard main() style argc.
5094 * @param argv Standard main() style argv. Initial components are already
5097 * @return A shell status integer (0 for success).
5100 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5104 if (c
->display_usage
) {
5106 "net rpc shutdown\n"
5107 " Shut down a remote RPC server\n");
5111 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5112 rpc_init_shutdown_internals
, argc
, argv
);
5115 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5116 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5117 rpc_reg_shutdown_internals
, argc
, argv
);
5123 /***************************************************************************
5124 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5125 ***************************************************************************/
5128 * Add interdomain trust account to the RPC server.
5129 * All parameters (except for argc and argv) are passed by run_rpc_command
5132 * @param c A net_context structure.
5133 * @param domain_sid The domain sid acquired from the server.
5134 * @param cli A cli_state connected to the server.
5135 * @param mem_ctx Talloc context, destroyed on completion of the function.
5136 * @param argc Standard main() style argc.
5137 * @param argv Standard main() style argv. Initial components are already
5140 * @return normal NTSTATUS return code.
5143 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5144 const DOM_SID
*domain_sid
,
5145 const char *domain_name
,
5146 struct cli_state
*cli
,
5147 struct rpc_pipe_client
*pipe_hnd
,
5148 TALLOC_CTX
*mem_ctx
,
5152 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5153 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5155 struct lsa_String lsa_acct_name
;
5157 uint32 acct_flags
=0;
5159 uint32_t access_granted
= 0;
5160 union samr_UserInfo info
;
5161 unsigned int orig_timeout
;
5164 d_printf("Usage: net rpc trustdom add <domain_name> "
5165 "<trust password>\n");
5166 return NT_STATUS_INVALID_PARAMETER
;
5170 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5173 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5174 return NT_STATUS_NO_MEMORY
;
5177 strupper_m(acct_name
);
5179 init_lsa_String(&lsa_acct_name
, acct_name
);
5181 /* Get samr policy handle */
5182 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5184 MAXIMUM_ALLOWED_ACCESS
,
5186 if (!NT_STATUS_IS_OK(result
)) {
5190 /* Get domain policy handle */
5191 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5193 MAXIMUM_ALLOWED_ACCESS
,
5194 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5196 if (!NT_STATUS_IS_OK(result
)) {
5200 /* This call can take a long time - allow the server to time out.
5201 * 35 seconds should do it. */
5203 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5205 /* Create trusting domain's account */
5206 acb_info
= ACB_NORMAL
;
5207 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5208 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5209 SAMR_USER_ACCESS_SET_PASSWORD
|
5210 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5211 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5213 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5222 /* And restore our original timeout. */
5223 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5225 if (!NT_STATUS_IS_OK(result
)) {
5226 d_printf("net rpc trustdom add: create user %s failed %s\n",
5227 acct_name
, nt_errstr(result
));
5232 struct samr_CryptPassword crypt_pwd
;
5234 ZERO_STRUCT(info
.info23
);
5236 init_samr_CryptPassword(argv
[1],
5237 &cli
->user_session_key
,
5240 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5241 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5242 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5243 info
.info23
.password
= crypt_pwd
;
5245 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5250 if (!NT_STATUS_IS_OK(result
)) {
5251 DEBUG(0,("Could not set trust account password: %s\n",
5252 nt_errstr(result
)));
5258 SAFE_FREE(acct_name
);
5263 * Create interdomain trust account for a remote domain.
5265 * @param argc Standard argc.
5266 * @param argv Standard argv without initial components.
5268 * @return Integer status (0 means success).
5271 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5273 if (argc
> 0 && !c
->display_usage
) {
5274 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5275 rpc_trustdom_add_internals
, argc
, argv
);
5278 "net rpc trustdom add <domain_name> <trust password>\n");
5285 * Remove interdomain trust account from the RPC server.
5286 * All parameters (except for argc and argv) are passed by run_rpc_command
5289 * @param c A net_context structure.
5290 * @param domain_sid The domain sid acquired from the server.
5291 * @param cli A cli_state connected to the server.
5292 * @param mem_ctx Talloc context, destroyed on completion of the function.
5293 * @param argc Standard main() style argc.
5294 * @param argv Standard main() style argv. Initial components are already
5297 * @return normal NTSTATUS return code.
5300 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5301 const DOM_SID
*domain_sid
,
5302 const char *domain_name
,
5303 struct cli_state
*cli
,
5304 struct rpc_pipe_client
*pipe_hnd
,
5305 TALLOC_CTX
*mem_ctx
,
5309 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5310 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5312 DOM_SID trust_acct_sid
;
5313 struct samr_Ids user_rids
, name_types
;
5314 struct lsa_String lsa_acct_name
;
5317 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5318 return NT_STATUS_INVALID_PARAMETER
;
5322 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5324 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5326 if (acct_name
== NULL
)
5327 return NT_STATUS_NO_MEMORY
;
5329 strupper_m(acct_name
);
5331 /* Get samr policy handle */
5332 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5334 MAXIMUM_ALLOWED_ACCESS
,
5336 if (!NT_STATUS_IS_OK(result
)) {
5340 /* Get domain policy handle */
5341 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5343 MAXIMUM_ALLOWED_ACCESS
,
5344 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5346 if (!NT_STATUS_IS_OK(result
)) {
5350 init_lsa_String(&lsa_acct_name
, acct_name
);
5352 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5359 if (!NT_STATUS_IS_OK(result
)) {
5360 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5361 acct_name
, nt_errstr(result
) );
5365 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5367 MAXIMUM_ALLOWED_ACCESS
,
5371 if (!NT_STATUS_IS_OK(result
)) {
5372 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5373 acct_name
, nt_errstr(result
) );
5377 /* append the rid to the domain sid */
5378 sid_copy(&trust_acct_sid
, domain_sid
);
5379 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5383 /* remove the sid */
5385 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5388 if (!NT_STATUS_IS_OK(result
)) {
5389 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5390 acct_name
, nt_errstr(result
) );
5396 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5399 if (!NT_STATUS_IS_OK(result
)) {
5400 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5401 acct_name
, nt_errstr(result
) );
5405 if (!NT_STATUS_IS_OK(result
)) {
5406 d_printf("Could not set trust account password: %s\n",
5416 * Delete interdomain trust account for a remote domain.
5418 * @param argc Standard argc.
5419 * @param argv Standard argv without initial components.
5421 * @return Integer status (0 means success).
5424 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5426 if (argc
> 0 && !c
->display_usage
) {
5427 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5428 rpc_trustdom_del_internals
, argc
, argv
);
5431 "net rpc trustdom del <domain>\n");
5436 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5437 struct cli_state
*cli
,
5438 TALLOC_CTX
*mem_ctx
,
5439 const char *domain_name
)
5441 char *dc_name
= NULL
;
5442 const char *buffer
= NULL
;
5443 struct rpc_pipe_client
*netr
;
5446 /* Use NetServerEnum2 */
5448 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5450 return NT_STATUS_OK
;
5453 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5454 for domain %s\n", domain_name
));
5456 /* Try netr_GetDcName */
5458 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5460 if (!NT_STATUS_IS_OK(status
)) {
5464 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5471 if (NT_STATUS_IS_OK(status
)) {
5475 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5476 for domain %s\n", domain_name
));
5482 * Establish trust relationship to a trusting domain.
5483 * Interdomain account must already be created on remote PDC.
5485 * @param c A net_context structure.
5486 * @param argc Standard argc.
5487 * @param argv Standard argv without initial components.
5489 * @return Integer status (0 means success).
5492 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5495 struct cli_state
*cli
= NULL
;
5496 struct sockaddr_storage server_ss
;
5497 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5498 struct policy_handle connect_hnd
;
5499 TALLOC_CTX
*mem_ctx
;
5501 DOM_SID
*domain_sid
;
5506 union lsa_PolicyInformation
*info
= NULL
;
5509 * Connect to \\server\ipc$ as 'our domain' account with password
5512 if (argc
!= 1 || c
->display_usage
) {
5514 "net rpc trustdom establish <domain_name>\n");
5518 domain_name
= smb_xstrdup(argv
[0]);
5519 strupper_m(domain_name
);
5521 /* account name used at first is our domain's name with '$' */
5522 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5525 strupper_m(acct_name
);
5528 * opt_workgroup will be used by connection functions further,
5529 * hence it should be set to remote domain name instead of ours
5531 if (c
->opt_workgroup
) {
5532 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5535 c
->opt_user_name
= acct_name
;
5537 /* find the domain controller */
5538 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5539 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5543 /* connect to ipc$ as username/password */
5544 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5545 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5547 /* Is it trusting domain account for sure ? */
5548 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5549 nt_errstr(nt_status
)));
5553 /* store who we connected to */
5555 saf_store( domain_name
, pdc_name
);
5558 * Connect to \\server\ipc$ again (this time anonymously)
5561 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5564 if (NT_STATUS_IS_ERR(nt_status
)) {
5565 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5566 domain_name
, nt_errstr(nt_status
)));
5570 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5571 "domain %s", domain_name
))) {
5572 DEBUG(0, ("talloc_init() failed\n"));
5577 /* Make sure we're talking to a proper server */
5579 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5580 if (!NT_STATUS_IS_OK(nt_status
)) {
5582 talloc_destroy(mem_ctx
);
5587 * Call LsaOpenPolicy and LsaQueryInfo
5590 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5592 if (!NT_STATUS_IS_OK(nt_status
)) {
5593 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5595 talloc_destroy(mem_ctx
);
5599 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, SEC_RIGHTS_QUERY_VALUE
,
5601 if (NT_STATUS_IS_ERR(nt_status
)) {
5602 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5603 nt_errstr(nt_status
)));
5605 talloc_destroy(mem_ctx
);
5609 /* Querying info level 5 */
5611 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5613 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5615 if (NT_STATUS_IS_ERR(nt_status
)) {
5616 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5617 nt_errstr(nt_status
)));
5619 talloc_destroy(mem_ctx
);
5623 domain_sid
= info
->account_domain
.sid
;
5625 /* There should be actually query info level 3 (following nt serv behaviour),
5626 but I still don't know if it's _really_ necessary */
5629 * Store the password in secrets db
5632 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5633 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5635 talloc_destroy(mem_ctx
);
5640 * Close the pipes and clean up
5643 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5644 if (NT_STATUS_IS_ERR(nt_status
)) {
5645 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5646 nt_errstr(nt_status
)));
5648 talloc_destroy(mem_ctx
);
5654 talloc_destroy(mem_ctx
);
5656 d_printf("Trust to domain %s established\n", domain_name
);
5661 * Revoke trust relationship to the remote domain.
5663 * @param c A net_context structure.
5664 * @param argc Standard argc.
5665 * @param argv Standard argv without initial components.
5667 * @return Integer status (0 means success).
5670 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5676 if (argc
< 1 || c
->display_usage
) {
5678 "net rpc trustdom revoke <domain_name>\n"
5679 " Revoke trust relationship\n"
5680 " domain_name\tName of domain to revoke trust\n");
5684 /* generate upper cased domain name */
5685 domain_name
= smb_xstrdup(argv
[0]);
5686 strupper_m(domain_name
);
5688 /* delete password of the trust */
5689 if (!pdb_del_trusteddom_pw(domain_name
)) {
5690 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5697 SAFE_FREE(domain_name
);
5701 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5702 const DOM_SID
*domain_sid
,
5703 const char *domain_name
,
5704 struct cli_state
*cli
,
5705 struct rpc_pipe_client
*pipe_hnd
,
5706 TALLOC_CTX
*mem_ctx
,
5711 sid_to_fstring(str_sid
, domain_sid
);
5712 d_printf("%s\n", str_sid
);
5713 return NT_STATUS_OK
;
5716 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5718 fstring ascii_sid
, padding
;
5719 int pad_len
, col_len
= 20;
5721 /* convert sid into ascii string */
5722 sid_to_fstring(ascii_sid
, dom_sid
);
5724 /* calculate padding space for d_printf to look nicer */
5725 pad_len
= col_len
- strlen(trusted_dom_name
);
5726 padding
[pad_len
] = 0;
5727 do padding
[--pad_len
] = ' '; while (pad_len
);
5729 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5732 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5733 TALLOC_CTX
*mem_ctx
,
5734 struct policy_handle
*pol
,
5736 const char *trusted_dom_name
)
5739 union lsa_TrustedDomainInfo
*info
= NULL
;
5740 char *cleartextpwd
= NULL
;
5741 uint8_t nt_hash
[16];
5744 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5747 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5749 if (NT_STATUS_IS_ERR(nt_status
)) {
5750 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5751 nt_errstr(nt_status
)));
5755 data
= data_blob(info
->password
.password
->data
,
5756 info
->password
.password
->length
);
5758 if (!rpccli_get_pwd_hash(pipe_hnd
, nt_hash
)) {
5759 DEBUG(0, ("Could not retrieve password hash\n"));
5763 cleartextpwd
= decrypt_trustdom_secret(nt_hash
, &data
);
5765 if (cleartextpwd
== NULL
) {
5766 DEBUG(0,("retrieved NULL password\n"));
5767 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5771 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5772 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5773 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5777 #ifdef DEBUG_PASSWORD
5778 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5779 "password: [%s]\n", trusted_dom_name
,
5780 sid_string_dbg(&dom_sid
), cleartextpwd
));
5784 SAFE_FREE(cleartextpwd
);
5785 data_blob_free(&data
);
5790 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5793 /* common variables */
5794 TALLOC_CTX
* mem_ctx
;
5795 struct cli_state
*cli
= NULL
;
5796 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5798 const char *domain_name
= NULL
;
5799 DOM_SID
*queried_dom_sid
;
5800 struct policy_handle connect_hnd
;
5801 union lsa_PolicyInformation
*info
= NULL
;
5803 /* trusted domains listing variables */
5804 unsigned int enum_ctx
= 0;
5806 struct lsa_DomainList dom_list
;
5809 if (c
->display_usage
) {
5811 "net rpc trustdom vampire\n"
5812 " Vampire trust relationship from remote server\n");
5817 * Listing trusted domains (stored in secrets.tdb, if local)
5820 mem_ctx
= talloc_init("trust relationships vampire");
5823 * set domain and pdc name to local samba server (default)
5824 * or to remote one given in command line
5827 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5828 domain_name
= c
->opt_workgroup
;
5829 c
->opt_target_workgroup
= c
->opt_workgroup
;
5831 fstrcpy(pdc_name
, global_myname());
5832 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5833 c
->opt_target_workgroup
= domain_name
;
5836 /* open \PIPE\lsarpc and open policy handle */
5837 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5838 if (!NT_STATUS_IS_OK(nt_status
)) {
5839 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5840 nt_errstr(nt_status
)));
5841 talloc_destroy(mem_ctx
);
5845 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5847 if (!NT_STATUS_IS_OK(nt_status
)) {
5848 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5849 nt_errstr(nt_status
) ));
5851 talloc_destroy(mem_ctx
);
5855 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
5857 if (NT_STATUS_IS_ERR(nt_status
)) {
5858 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5859 nt_errstr(nt_status
)));
5861 talloc_destroy(mem_ctx
);
5865 /* query info level 5 to obtain sid of a domain being queried */
5866 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5868 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5871 if (NT_STATUS_IS_ERR(nt_status
)) {
5872 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5873 nt_errstr(nt_status
)));
5875 talloc_destroy(mem_ctx
);
5879 queried_dom_sid
= info
->account_domain
.sid
;
5882 * Keep calling LsaEnumTrustdom over opened pipe until
5883 * the end of enumeration is reached
5886 d_printf("Vampire trusted domains:\n\n");
5889 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
5894 if (NT_STATUS_IS_ERR(nt_status
)) {
5895 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5896 nt_errstr(nt_status
)));
5898 talloc_destroy(mem_ctx
);
5902 for (i
= 0; i
< dom_list
.count
; i
++) {
5904 print_trusted_domain(dom_list
.domains
[i
].sid
,
5905 dom_list
.domains
[i
].name
.string
);
5907 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5908 *dom_list
.domains
[i
].sid
,
5909 dom_list
.domains
[i
].name
.string
);
5910 if (!NT_STATUS_IS_OK(nt_status
)) {
5912 talloc_destroy(mem_ctx
);
5918 * in case of no trusted domains say something rather
5919 * than just display blank line
5921 if (!dom_list
.count
) d_printf("none\n");
5923 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5925 /* close this connection before doing next one */
5926 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5927 if (NT_STATUS_IS_ERR(nt_status
)) {
5928 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5929 nt_errstr(nt_status
)));
5931 talloc_destroy(mem_ctx
);
5935 /* close lsarpc pipe and connection to IPC$ */
5938 talloc_destroy(mem_ctx
);
5942 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
5944 /* common variables */
5945 TALLOC_CTX
* mem_ctx
;
5946 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5947 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5949 const char *domain_name
= NULL
;
5950 DOM_SID
*queried_dom_sid
;
5952 int ascii_dom_name_len
;
5953 struct policy_handle connect_hnd
;
5954 union lsa_PolicyInformation
*info
= NULL
;
5956 /* trusted domains listing variables */
5957 unsigned int num_domains
, enum_ctx
= 0;
5958 int i
, pad_len
, col_len
= 20;
5959 struct lsa_DomainList dom_list
;
5962 /* trusting domains listing variables */
5963 struct policy_handle domain_hnd
;
5964 struct samr_SamArray
*trusts
= NULL
;
5966 if (c
->display_usage
) {
5968 "net rpc trustdom list\n"
5969 " List trust relationships\n");
5974 * Listing trusted domains (stored in secrets.tdb, if local)
5977 mem_ctx
= talloc_init("trust relationships listing");
5980 * set domain and pdc name to local samba server (default)
5981 * or to remote one given in command line
5984 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5985 domain_name
= c
->opt_workgroup
;
5986 c
->opt_target_workgroup
= c
->opt_workgroup
;
5988 fstrcpy(pdc_name
, global_myname());
5989 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5990 c
->opt_target_workgroup
= domain_name
;
5993 /* open \PIPE\lsarpc and open policy handle */
5994 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5995 if (!NT_STATUS_IS_OK(nt_status
)) {
5996 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5997 nt_errstr(nt_status
)));
5998 talloc_destroy(mem_ctx
);
6002 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6004 if (!NT_STATUS_IS_OK(nt_status
)) {
6005 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6006 nt_errstr(nt_status
) ));
6008 talloc_destroy(mem_ctx
);
6012 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
6014 if (NT_STATUS_IS_ERR(nt_status
)) {
6015 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6016 nt_errstr(nt_status
)));
6018 talloc_destroy(mem_ctx
);
6022 /* query info level 5 to obtain sid of a domain being queried */
6023 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6025 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6028 if (NT_STATUS_IS_ERR(nt_status
)) {
6029 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6030 nt_errstr(nt_status
)));
6032 talloc_destroy(mem_ctx
);
6036 queried_dom_sid
= info
->account_domain
.sid
;
6039 * Keep calling LsaEnumTrustdom over opened pipe until
6040 * the end of enumeration is reached
6043 d_printf("Trusted domains list:\n\n");
6046 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6051 if (NT_STATUS_IS_ERR(nt_status
)) {
6052 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6053 nt_errstr(nt_status
)));
6055 talloc_destroy(mem_ctx
);
6059 for (i
= 0; i
< dom_list
.count
; i
++) {
6060 print_trusted_domain(dom_list
.domains
[i
].sid
,
6061 dom_list
.domains
[i
].name
.string
);
6065 * in case of no trusted domains say something rather
6066 * than just display blank line
6068 if (!dom_list
.count
) d_printf("none\n");
6070 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6072 /* close this connection before doing next one */
6073 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6074 if (NT_STATUS_IS_ERR(nt_status
)) {
6075 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6076 nt_errstr(nt_status
)));
6078 talloc_destroy(mem_ctx
);
6082 TALLOC_FREE(pipe_hnd
);
6085 * Listing trusting domains (stored in passdb backend, if local)
6088 d_printf("\nTrusting domains list:\n\n");
6091 * Open \PIPE\samr and get needed policy handles
6093 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6095 if (!NT_STATUS_IS_OK(nt_status
)) {
6096 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6098 talloc_destroy(mem_ctx
);
6103 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6105 SAMR_ACCESS_OPEN_DOMAIN
,
6107 if (!NT_STATUS_IS_OK(nt_status
)) {
6108 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6109 nt_errstr(nt_status
)));
6111 talloc_destroy(mem_ctx
);
6115 /* SamrOpenDomain - we have to open domain policy handle in order to be
6116 able to enumerate accounts*/
6117 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6119 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6122 if (!NT_STATUS_IS_OK(nt_status
)) {
6123 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6124 nt_errstr(nt_status
)));
6126 talloc_destroy(mem_ctx
);
6131 * perform actual enumeration
6134 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6137 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6144 if (NT_STATUS_IS_ERR(nt_status
)) {
6145 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6146 nt_errstr(nt_status
)));
6148 talloc_destroy(mem_ctx
);
6152 for (i
= 0; i
< num_domains
; i
++) {
6154 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6157 * get each single domain's sid (do we _really_ need this ?):
6158 * 1) connect to domain's pdc
6159 * 2) query the pdc for domain's sid
6162 /* get rid of '$' tail */
6163 ascii_dom_name_len
= strlen(str
);
6164 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6165 str
[ascii_dom_name_len
- 1] = '\0';
6167 /* calculate padding space for d_printf to look nicer */
6168 pad_len
= col_len
- strlen(str
);
6169 padding
[pad_len
] = 0;
6170 do padding
[--pad_len
] = ' '; while (pad_len
);
6172 /* set opt_* variables to remote domain */
6174 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6175 c
->opt_target_workgroup
= c
->opt_workgroup
;
6177 d_printf("%s%s", str
, padding
);
6179 /* connect to remote domain controller */
6180 nt_status
= net_make_ipc_connection(c
,
6181 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6183 if (NT_STATUS_IS_OK(nt_status
)) {
6184 /* query for domain's sid */
6185 if (run_rpc_command(
6187 &ndr_table_lsarpc
.syntax_id
, 0,
6188 rpc_query_domain_sid
, argc
,
6190 d_fprintf(stderr
, "couldn't get domain's sid\n");
6192 cli_shutdown(remote_cli
);
6195 d_fprintf(stderr
, "domain controller is not "
6197 nt_errstr(nt_status
));
6201 if (!num_domains
) d_printf("none\n");
6203 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6205 /* close opened samr and domain policy handles */
6206 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6207 if (!NT_STATUS_IS_OK(nt_status
)) {
6208 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6211 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6212 if (!NT_STATUS_IS_OK(nt_status
)) {
6213 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6216 /* close samr pipe and connection to IPC$ */
6219 talloc_destroy(mem_ctx
);
6224 * Entrypoint for 'net rpc trustdom' code.
6226 * @param argc Standard argc.
6227 * @param argv Standard argv without initial components.
6229 * @return Integer status (0 means success).
6232 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6234 struct functable func
[] = {
6239 "Add trusted domain's account",
6240 "net rpc trustdom add\n"
6241 " Add trusted domain's account"
6247 "Remove trusted domain's account",
6248 "net rpc trustdom del\n"
6249 " Remove trusted domain's account"
6253 rpc_trustdom_establish
,
6255 "Establish trust relationship",
6256 "net rpc trustdom establish\n"
6257 " Establish trust relationship"
6261 rpc_trustdom_revoke
,
6263 "Revoke trust relationship",
6264 "net rpc trustdom revoke\n"
6265 " Revoke trust relationship"
6271 "List domain trusts",
6272 "net rpc trustdom list\n"
6273 " List domain trusts"
6277 rpc_trustdom_vampire
,
6279 "Vampire trusts from remote server",
6280 "net rpc trustdom vampire\n"
6281 " Vampire trusts from remote server"
6283 {NULL
, NULL
, 0, NULL
, NULL
}
6286 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6290 * Check if a server will take rpc commands
6291 * @param flags Type of server to connect to (PDC, DMB, localhost)
6292 * if the host is not explicitly specified
6293 * @return bool (true means rpc supported)
6295 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6297 struct cli_state
*cli
;
6299 struct sockaddr_storage server_ss
;
6300 char *server_name
= NULL
;
6303 /* flags (i.e. server type) may depend on command */
6304 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6307 if ((cli
= cli_initialise()) == NULL
) {
6311 status
= cli_connect(cli
, server_name
, &server_ss
);
6312 if (!NT_STATUS_IS_OK(status
))
6314 if (!attempt_netbios_session_request(&cli
, global_myname(),
6315 server_name
, &server_ss
))
6317 status
= cli_negprot(cli
);
6318 if (!NT_STATUS_IS_OK(status
))
6320 if (cli
->protocol
< PROTOCOL_NT1
)
6329 /* dump sam database via samsync rpc calls */
6330 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6331 if (c
->display_usage
) {
6334 " Dump remote SAM database\n");
6338 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6339 NET_FLAGS_ANONYMOUS
,
6340 rpc_samdump_internals
, argc
, argv
);
6343 /* syncronise sam database via samsync rpc calls */
6344 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6346 struct functable func
[] = {
6351 "Dump remote SAM database to ldif",
6352 "net rpc vampire ldif\n"
6353 " Dump remote SAM database to LDIF file or stdout"
6359 "Dump remote SAM database to Kerberos Keytab",
6360 "net rpc vampire keytab\n"
6361 " Dump remote SAM database to Kerberos keytab file"
6367 "Dump remote SAM database to passdb",
6368 "net rpc vampire passdb\n"
6369 " Dump remote SAM database to passdb"
6372 {NULL
, NULL
, 0, NULL
, NULL
}
6376 if (c
->display_usage
) {
6379 " Vampire remote SAM database\n");
6383 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6384 NET_FLAGS_ANONYMOUS
,
6385 rpc_vampire_internals
,
6389 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6393 * Migrate everything from a print server.
6395 * @param c A net_context structure.
6396 * @param argc Standard main() style argc.
6397 * @param argv Standard main() style argv. Initial components are already
6400 * @return A shell status integer (0 for success).
6402 * The order is important !
6403 * To successfully add drivers the print queues have to exist !
6404 * Applying ACLs should be the last step, because you're easily locked out.
6407 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6412 if (c
->display_usage
) {
6414 "net rpc printer migrate all\n"
6415 " Migrate everything from a print server\n");
6420 d_printf("no server to migrate\n");
6424 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6425 rpc_printer_migrate_printers_internals
, argc
,
6430 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6431 rpc_printer_migrate_drivers_internals
, argc
,
6436 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6437 rpc_printer_migrate_forms_internals
, argc
, argv
);
6441 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6442 rpc_printer_migrate_settings_internals
, argc
,
6447 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6448 rpc_printer_migrate_security_internals
, argc
,
6454 * Migrate print drivers from a print server.
6456 * @param c A net_context structure.
6457 * @param argc Standard main() style argc.
6458 * @param argv Standard main() style argv. Initial components are already
6461 * @return A shell status integer (0 for success).
6463 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6466 if (c
->display_usage
) {
6468 "net rpc printer migrate drivers\n"
6469 " Migrate print-drivers from a print-server\n");
6474 d_printf("no server to migrate\n");
6478 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6479 rpc_printer_migrate_drivers_internals
,
6484 * Migrate print-forms from a print-server.
6486 * @param c A net_context structure.
6487 * @param argc Standard main() style argc.
6488 * @param argv Standard main() style argv. Initial components are already
6491 * @return A shell status integer (0 for success).
6493 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6496 if (c
->display_usage
) {
6498 "net rpc printer migrate forms\n"
6499 " Migrate print-forms from a print-server\n");
6504 d_printf("no server to migrate\n");
6508 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6509 rpc_printer_migrate_forms_internals
,
6514 * Migrate printers from a print-server.
6516 * @param c A net_context structure.
6517 * @param argc Standard main() style argc.
6518 * @param argv Standard main() style argv. Initial components are already
6521 * @return A shell status integer (0 for success).
6523 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6526 if (c
->display_usage
) {
6528 "net rpc printer migrate printers\n"
6529 " Migrate printers from a print-server\n");
6534 d_printf("no server to migrate\n");
6538 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6539 rpc_printer_migrate_printers_internals
,
6544 * Migrate printer-ACLs from a print-server
6546 * @param c A net_context structure.
6547 * @param argc Standard main() style argc.
6548 * @param argv Standard main() style argv. Initial components are already
6551 * @return A shell status integer (0 for success).
6553 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6556 if (c
->display_usage
) {
6558 "net rpc printer migrate security\n"
6559 " Migrate printer-ACLs from a print-server\n");
6564 d_printf("no server to migrate\n");
6568 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6569 rpc_printer_migrate_security_internals
,
6574 * Migrate printer-settings from a print-server.
6576 * @param c A net_context structure.
6577 * @param argc Standard main() style argc.
6578 * @param argv Standard main() style argv. Initial components are already
6581 * @return A shell status integer (0 for success).
6583 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6586 if (c
->display_usage
) {
6588 "net rpc printer migrate settings\n"
6589 " Migrate printer-settings from a print-server\n");
6594 d_printf("no server to migrate\n");
6598 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6599 rpc_printer_migrate_settings_internals
,
6604 * 'net rpc printer' entrypoint.
6606 * @param c A net_context structure.
6607 * @param argc Standard main() style argc.
6608 * @param argv Standard main() style argv. Initial components are already
6612 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6615 /* ouch: when addriver and setdriver are called from within
6616 rpc_printer_migrate_drivers_internals, the printer-queue already
6619 struct functable func
[] = {
6622 rpc_printer_migrate_all
,
6624 "Migrate all from remote to local print server",
6625 "net rpc printer migrate all\n"
6626 " Migrate all from remote to local print server"
6630 rpc_printer_migrate_drivers
,
6632 "Migrate drivers to local server",
6633 "net rpc printer migrate drivers\n"
6634 " Migrate drivers to local server"
6638 rpc_printer_migrate_forms
,
6640 "Migrate froms to local server",
6641 "net rpc printer migrate forms\n"
6642 " Migrate froms to local server"
6646 rpc_printer_migrate_printers
,
6648 "Migrate printers to local server",
6649 "net rpc printer migrate printers\n"
6650 " Migrate printers to local server"
6654 rpc_printer_migrate_security
,
6656 "Mirgate printer ACLs to local server",
6657 "net rpc printer migrate security\n"
6658 " Mirgate printer ACLs to local server"
6662 rpc_printer_migrate_settings
,
6664 "Migrate printer settings to local server",
6665 "net rpc printer migrate settings\n"
6666 " Migrate printer settings to local server"
6668 {NULL
, NULL
, 0, NULL
, NULL
}
6671 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6676 * List printers on a remote RPC server.
6678 * @param c A net_context structure.
6679 * @param argc Standard main() style argc.
6680 * @param argv Standard main() style argv. Initial components are already
6683 * @return A shell status integer (0 for success).
6685 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6687 if (c
->display_usage
) {
6689 "net rpc printer list\n"
6690 " List printers on a remote RPC server\n");
6694 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6695 rpc_printer_list_internals
,
6700 * List printer-drivers on a remote RPC server.
6702 * @param c A net_context structure.
6703 * @param argc Standard main() style argc.
6704 * @param argv Standard main() style argv. Initial components are already
6707 * @return A shell status integer (0 for success).
6709 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6712 if (c
->display_usage
) {
6714 "net rpc printer driver\n"
6715 " List printer-drivers on a remote RPC server\n");
6719 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6720 rpc_printer_driver_list_internals
,
6725 * Publish printer in ADS via MSRPC.
6727 * @param c A net_context structure.
6728 * @param argc Standard main() style argc.
6729 * @param argv Standard main() style argv. Initial components are already
6732 * @return A shell status integer (0 for success).
6734 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6737 if (c
->display_usage
) {
6739 "net rpc printer publish publish\n"
6740 " Publish printer in ADS via MSRPC\n");
6744 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6745 rpc_printer_publish_publish_internals
,
6750 * Update printer in ADS via MSRPC.
6752 * @param c A net_context structure.
6753 * @param argc Standard main() style argc.
6754 * @param argv Standard main() style argv. Initial components are already
6757 * @return A shell status integer (0 for success).
6759 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6761 if (c
->display_usage
) {
6763 "net rpc printer publish update\n"
6764 " Update printer in ADS via MSRPC\n");
6768 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6769 rpc_printer_publish_update_internals
,
6774 * UnPublish printer in ADS via MSRPC.
6776 * @param c A net_context structure.
6777 * @param argc Standard main() style argc.
6778 * @param argv Standard main() style argv. Initial components are already
6781 * @return A shell status integer (0 for success).
6783 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6786 if (c
->display_usage
) {
6788 "net rpc printer publish unpublish\n"
6789 " UnPublish printer in ADS via MSRPC\n");
6793 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6794 rpc_printer_publish_unpublish_internals
,
6799 * List published printers via MSRPC.
6801 * @param c A net_context structure.
6802 * @param argc Standard main() style argc.
6803 * @param argv Standard main() style argv. Initial components are already
6806 * @return A shell status integer (0 for success).
6808 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6811 if (c
->display_usage
) {
6813 "net rpc printer publish list\n"
6814 " List published printers via MSRPC\n");
6818 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6819 rpc_printer_publish_list_internals
,
6825 * Publish printer in ADS.
6827 * @param c A net_context structure.
6828 * @param argc Standard main() style argc.
6829 * @param argv Standard main() style argv. Initial components are already
6832 * @return A shell status integer (0 for success).
6834 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6838 struct functable func
[] = {
6841 rpc_printer_publish_publish
,
6843 "Publish printer in AD",
6844 "net rpc printer publish publish\n"
6845 " Publish printer in AD"
6849 rpc_printer_publish_update
,
6851 "Update printer in AD",
6852 "net rpc printer publish update\n"
6853 " Update printer in AD"
6857 rpc_printer_publish_unpublish
,
6859 "Unpublish printer",
6860 "net rpc printer publish unpublish\n"
6861 " Unpublish printer"
6865 rpc_printer_publish_list
,
6867 "List published printers",
6868 "net rpc printer publish list\n"
6869 " List published printers"
6871 {NULL
, NULL
, 0, NULL
, NULL
}
6875 if (c
->display_usage
) {
6876 d_printf("Usage:\n");
6877 d_printf("net rpc printer publish\n"
6878 " List published printers\n"
6879 " Alias of net rpc printer publish list\n");
6880 net_display_usage_from_functable(func
);
6883 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6884 rpc_printer_publish_list_internals
,
6888 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
6894 * Display rpc printer help page.
6896 * @param c A net_context structure.
6897 * @param argc Standard main() style argc.
6898 * @param argv Standard main() style argv. Initial components are already
6901 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
6903 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
6904 "\tlists all printers on print-server\n\n");
6905 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
6906 "\tlists all printer-drivers on print-server\n\n");
6907 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
6908 "\tpublishes printer settings in Active Directory\n"
6909 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
6910 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
6911 "\n\tmigrates printers from remote to local server\n\n");
6912 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
6913 "\n\tmigrates printer-settings from remote to local server\n\n");
6914 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
6915 "\n\tmigrates printer-drivers from remote to local server\n\n");
6916 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
6917 "\n\tmigrates printer-forms from remote to local server\n\n");
6918 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
6919 "\n\tmigrates printer-ACLs from remote to local server\n\n");
6920 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
6921 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
6922 "\tremote to local print-server\n\n");
6923 net_common_methods_usage(c
, argc
, argv
);
6924 net_common_flags_usage(c
, argc
, argv
);
6926 "\t-v or --verbose\t\t\tgive verbose output\n"
6927 "\t --destination\t\tmigration target server (default: localhost)\n");
6933 * 'net rpc printer' entrypoint.
6935 * @param c A net_context structure.
6936 * @param argc Standard main() style argc.
6937 * @param argv Standard main() style argv. Initial components are already
6940 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
6942 struct functable func
[] = {
6947 "List all printers on print server",
6948 "net rpc printer list\n"
6949 " List all printers on print server"
6953 rpc_printer_migrate
,
6955 "Migrate printer to local server",
6956 "net rpc printer migrate\n"
6957 " Migrate printer to local server"
6961 rpc_printer_driver_list
,
6963 "List printer drivers",
6964 "net rpc printer driver\n"
6965 " List printer drivers"
6969 rpc_printer_publish
,
6971 "Publish printer in AD",
6972 "net rpc printer publish\n"
6973 " Publish printer in AD"
6975 {NULL
, NULL
, 0, NULL
, NULL
}
6979 if (c
->display_usage
) {
6980 d_printf("Usage:\n");
6981 d_printf("net rpc printer\n"
6982 " List printers\n");
6983 net_display_usage_from_functable(func
);
6986 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6987 rpc_printer_list_internals
,
6991 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
6995 * 'net rpc' entrypoint.
6997 * @param c A net_context structure.
6998 * @param argc Standard main() style argc.
6999 * @param argv Standard main() style argv. Initial components are already
7003 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7005 struct functable func
[] = {
7010 "Modify global audit settings",
7012 " Modify global audit settings"
7018 "Show basic info about a domain",
7020 " Show basic info about a domain"
7034 "Join a domain created in server manager",
7036 " Join a domain created in server manager"
7042 "Test that a join is valid",
7043 "net rpc testjoin\n"
7044 " Test that a join is valid"
7050 "List/modify users",
7052 " List/modify users"
7058 "Change a user password",
7059 "net rpc password\n"
7060 " Change a user password\n"
7061 " Alias for net rpc user password"
7067 "List/modify groups",
7069 " List/modify groups"
7075 "List/modify shares",
7077 " List/modify shares"
7091 "List/modify printers",
7093 " List/modify printers"
7097 net_rpc_changetrustpw
,
7099 "Change trust account password",
7100 "net rpc changetrustpw\n"
7101 " Change trust account password"
7107 "Modify domain trusts",
7108 "net rpc trustdom\n"
7109 " Modify domain trusts"
7115 "Abort a remote shutdown",
7116 "net rpc abortshutdown\n"
7117 " Abort a remote shutdown"
7123 "Shutdown a remote server",
7124 "net rpc shutdown\n"
7125 " Shutdown a remote server"
7131 "Dump SAM data of remote NT PDC",
7133 " Dump SAM data of remote NT PDC"
7139 "Sync a remote NT PDC's data into local passdb",
7141 " Sync a remote NT PDC's data into local passdb"
7147 "Fetch the domain sid into local secrets.tdb",
7149 " Fetch the domain sid into local secrets.tdb"
7155 "Manage privileges assigned to SID",
7157 " Manage privileges assigned to SID"
7163 "Start/stop/query remote services",
7165 " Start/stop/query remote services"
7171 "Manage registry hives",
7172 "net rpc registry\n"
7173 " Manage registry hives"
7179 "Open interactive shell on remote server",
7181 " Open interactive shell on remote server"
7183 {NULL
, NULL
, 0, NULL
, NULL
}
7185 return net_run_function(c
, argc
, argv
, "net rpc", func
);