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
);
29 extern const char *share_type
[];
34 * @brief RPC based subcommands for the 'net' utility.
36 * This file should contain much of the functionality that used to
37 * be found in rpcclient, execpt that the commands should change
38 * less often, and the fucntionality should be sane (the user is not
39 * expected to know a rid/sid before they conduct an operation etc.)
41 * @todo Perhaps eventually these should be split out into a number
42 * of files, as this could get quite big.
47 * Many of the RPC functions need the domain sid. This function gets
48 * it at the start of every run
50 * @param cli A cli_state already connected to the remote machine
52 * @return The Domain SID of the remote machine.
55 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
57 const char **domain_name
)
59 struct rpc_pipe_client
*lsa_pipe
;
61 NTSTATUS result
= NT_STATUS_OK
;
62 union lsa_PolicyInformation
*info
= NULL
;
64 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
66 if (!NT_STATUS_IS_OK(result
)) {
67 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
71 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
72 SEC_RIGHTS_MAXIMUM_ALLOWED
,
74 if (!NT_STATUS_IS_OK(result
)) {
75 d_fprintf(stderr
, "open_policy failed: %s\n",
80 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
82 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
84 if (!NT_STATUS_IS_OK(result
)) {
85 d_fprintf(stderr
, "lsaquery failed: %s\n",
90 *domain_name
= info
->account_domain
.name
.string
;
91 *domain_sid
= info
->account_domain
.sid
;
93 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
94 TALLOC_FREE(lsa_pipe
);
100 * Run a single RPC command, from start to finish.
102 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
103 * @param conn_flag a NET_FLAG_ combination. Passed to
104 * net_make_ipc_connection.
105 * @param argc Standard main() style argc.
106 * @param argv Standard main() style argv. Initial components are already
108 * @return A shell status integer (0 for success).
111 int run_rpc_command(struct net_context
*c
,
112 struct cli_state
*cli_arg
,
113 const struct ndr_syntax_id
*interface
,
119 struct cli_state
*cli
= NULL
;
120 struct rpc_pipe_client
*pipe_hnd
= NULL
;
124 const char *domain_name
;
126 /* make use of cli_state handed over as an argument, if possible */
128 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
129 if (!NT_STATUS_IS_OK(nt_status
)) {
130 DEBUG(1, ("failed to make ipc connection: %s\n",
131 nt_errstr(nt_status
)));
144 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
145 DEBUG(0, ("talloc_init() failed\n"));
150 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
152 if (!NT_STATUS_IS_OK(nt_status
)) {
157 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
158 if (lp_client_schannel()
159 && (ndr_syntax_id_equal(interface
,
160 &ndr_table_netlogon
.syntax_id
))) {
161 /* Always try and create an schannel netlogon pipe. */
162 nt_status
= cli_rpc_pipe_open_schannel(
164 PIPE_AUTH_LEVEL_PRIVACY
, domain_name
,
166 if (!NT_STATUS_IS_OK(nt_status
)) {
167 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
168 nt_errstr(nt_status
) ));
173 if (conn_flags
& NET_FLAGS_SEAL
) {
174 nt_status
= cli_rpc_pipe_open_ntlmssp(
176 PIPE_AUTH_LEVEL_PRIVACY
,
177 lp_workgroup(), c
->opt_user_name
,
178 c
->opt_password
, &pipe_hnd
);
180 nt_status
= cli_rpc_pipe_open_noauth(
184 if (!NT_STATUS_IS_OK(nt_status
)) {
185 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
186 cli_get_pipe_name_from_iface(
187 debug_ctx(), cli
, interface
),
188 nt_errstr(nt_status
) ));
195 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
197 if (!NT_STATUS_IS_OK(nt_status
)) {
198 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
200 DEBUG(5, ("rpc command function succedded\n"));
203 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
205 TALLOC_FREE(pipe_hnd
);
209 /* close the connection only if it was opened here */
214 talloc_destroy(mem_ctx
);
215 return (!NT_STATUS_IS_OK(nt_status
));
219 * Force a change of the trust acccount password.
221 * All parameters are provided by the run_rpc_command function, except for
222 * argc, argv which are passed through.
224 * @param domain_sid The domain sid acquired from the remote server.
225 * @param cli A cli_state connected to the server.
226 * @param mem_ctx Talloc context, destroyed on completion of the function.
227 * @param argc Standard main() style argc.
228 * @param argv Standard main() style argv. Initial components are already
231 * @return Normal NTSTATUS return.
234 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
235 const DOM_SID
*domain_sid
,
236 const char *domain_name
,
237 struct cli_state
*cli
,
238 struct rpc_pipe_client
*pipe_hnd
,
244 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
248 * Force a change of the trust acccount password.
250 * @param argc Standard main() style argc.
251 * @param argv Standard main() style argv. Initial components are already
254 * @return A shell status integer (0 for success).
257 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
259 if (c
->display_usage
) {
261 "net rpc changetrustpw\n"
262 " Change the machine trust password\n");
266 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
267 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
268 rpc_changetrustpw_internals
,
273 * Join a domain, the old way.
275 * This uses 'machinename' as the inital password, and changes it.
277 * The password should be created with 'server manager' or equiv first.
279 * All parameters are provided by the run_rpc_command function, except for
280 * argc, argv which are passed through.
282 * @param domain_sid The domain sid acquired from the remote server.
283 * @param cli A cli_state connected to the server.
284 * @param mem_ctx Talloc context, destroyed on completion of the function.
285 * @param argc Standard main() style argc.
286 * @param argv Standard main() style argv. Initial components are already
289 * @return Normal NTSTATUS return.
292 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
293 const DOM_SID
*domain_sid
,
294 const char *domain_name
,
295 struct cli_state
*cli
,
296 struct rpc_pipe_client
*pipe_hnd
,
302 fstring trust_passwd
;
303 unsigned char orig_trust_passwd_hash
[16];
305 uint32 sec_channel_type
;
307 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
309 if (!NT_STATUS_IS_OK(result
)) {
310 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
313 nt_errstr(result
) ));
318 check what type of join - if the user want's to join as
319 a BDC, the server must agree that we are a BDC.
322 sec_channel_type
= get_sec_channel_type(argv
[0]);
324 sec_channel_type
= get_sec_channel_type(NULL
);
327 fstrcpy(trust_passwd
, global_myname());
328 strlower_m(trust_passwd
);
331 * Machine names can be 15 characters, but the max length on
332 * a password is 14. --jerry
335 trust_passwd
[14] = '\0';
337 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
339 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
340 orig_trust_passwd_hash
,
343 if (NT_STATUS_IS_OK(result
))
344 printf("Joined domain %s.\n", c
->opt_target_workgroup
);
347 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
348 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
349 result
= NT_STATUS_UNSUCCESSFUL
;
356 * Join a domain, the old way.
358 * @param argc Standard main() style argc.
359 * @param argv Standard main() style argv. Initial components are already
362 * @return A shell status integer (0 for success).
365 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
367 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
368 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
369 rpc_oldjoin_internals
,
374 * Join a domain, the old way. This function exists to allow
375 * the message to be displayed when oldjoin was explicitly
376 * requested, but not when it was implied by "net rpc join".
378 * @param argc Standard main() style argc.
379 * @param argv Standard main() style argv. Initial components are already
382 * @return A shell status integer (0 for success).
385 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
389 if (c
->display_usage
) {
392 " Join a domain the old way\n");
396 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
399 d_fprintf(stderr
, "Failed to join domain\n");
406 * 'net rpc join' entrypoint.
407 * @param argc Standard main() style argc.
408 * @param argv Standard main() style argv. Initial components are already
411 * Main 'net_rpc_join()' (where the admin username/password is used) is
413 * Try to just change the password, but if that doesn't work, use/prompt
414 * for a username/password.
417 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
419 if (c
->display_usage
) {
421 "net rpc join -U <username>[%%password] <type>\n"
423 " username\tName of the admin user"
424 " password\tPassword of the admin user, will "
425 "prompt if not specified\n"
426 " type\tCan be one of the following:\n"
427 "\t\tMEMBER\tJoin as member server (default)\n"
428 "\t\tBDC\tJoin as BDC\n"
429 "\t\tPDC\tJoin as PDC\n");
433 if (lp_server_role() == ROLE_STANDALONE
) {
434 d_printf("cannot join as standalone machine\n");
438 if (strlen(global_myname()) > 15) {
439 d_printf("Our netbios name can be at most 15 chars long, "
440 "\"%s\" is %u chars long\n",
441 global_myname(), (unsigned int)strlen(global_myname()));
445 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
448 return net_rpc_join_newstyle(c
, argc
, argv
);
452 * display info about a rpc domain
454 * All parameters are provided by the run_rpc_command function, except for
455 * argc, argv which are passed through.
457 * @param domain_sid The domain sid acquired from the remote server
458 * @param cli A cli_state connected to the server.
459 * @param mem_ctx Talloc context, destroyed on completion of the function.
460 * @param argc Standard main() style argc.
461 * @param argv Standard main() style argv. Initial components are already
464 * @return Normal NTSTATUS return.
467 NTSTATUS
rpc_info_internals(struct net_context
*c
,
468 const DOM_SID
*domain_sid
,
469 const char *domain_name
,
470 struct cli_state
*cli
,
471 struct rpc_pipe_client
*pipe_hnd
,
476 POLICY_HND connect_pol
, domain_pol
;
477 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
478 union samr_DomainInfo
*info
= NULL
;
481 sid_to_fstring(sid_str
, domain_sid
);
483 /* Get sam policy handle */
484 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
486 MAXIMUM_ALLOWED_ACCESS
,
488 if (!NT_STATUS_IS_OK(result
)) {
489 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
493 /* Get domain policy handle */
494 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
496 MAXIMUM_ALLOWED_ACCESS
,
497 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
499 if (!NT_STATUS_IS_OK(result
)) {
500 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
504 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
508 if (NT_STATUS_IS_OK(result
)) {
509 d_printf("Domain Name: %s\n", info
->info2
.domain_name
.string
);
510 d_printf("Domain SID: %s\n", sid_str
);
511 d_printf("Sequence number: %llu\n",
512 (unsigned long long)info
->info2
.sequence_num
);
513 d_printf("Num users: %u\n", info
->info2
.num_users
);
514 d_printf("Num domain groups: %u\n", info
->info2
.num_groups
);
515 d_printf("Num local groups: %u\n", info
->info2
.num_aliases
);
523 * 'net rpc info' entrypoint.
524 * @param argc Standard main() style argc.
525 * @param argv Standard main() style argv. Initial components are already
529 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
531 if (c
->display_usage
) {
534 " Display information about the domain\n");
538 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
539 NET_FLAGS_PDC
, rpc_info_internals
,
544 * Fetch domain SID into the local secrets.tdb.
546 * All parameters are provided by the run_rpc_command function, except for
547 * argc, argv which are passed through.
549 * @param domain_sid The domain sid acquired from the remote server.
550 * @param cli A cli_state connected to the server.
551 * @param mem_ctx Talloc context, destroyed on completion of the function.
552 * @param argc Standard main() style argc.
553 * @param argv Standard main() style argv. Initial components are already
556 * @return Normal NTSTATUS return.
559 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
560 const DOM_SID
*domain_sid
,
561 const char *domain_name
,
562 struct cli_state
*cli
,
563 struct rpc_pipe_client
*pipe_hnd
,
570 sid_to_fstring(sid_str
, domain_sid
);
571 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
572 sid_str
, domain_name
);
574 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
575 DEBUG(0,("Can't store domain SID\n"));
576 return NT_STATUS_UNSUCCESSFUL
;
583 * 'net rpc getsid' entrypoint.
584 * @param argc Standard main() style argc.
585 * @param argv Standard main() style argv. Initial components are already
589 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
591 if (c
->display_usage
) {
594 " Fetch domain SID into local secrets.tdb\n");
598 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
599 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
600 rpc_getsid_internals
,
604 /****************************************************************************/
607 * Basic usage function for 'net rpc user'.
608 * @param argc Standard main() style argc.
609 * @param argv Standard main() style argv. Initial components are already
613 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
615 return net_user_usage(c
, argc
, argv
);
619 * Add a new user to a remote RPC server.
621 * @param argc Standard main() style argc.
622 * @param argv Standard main() style argv. Initial components are already
625 * @return A shell status integer (0 for success).
628 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
630 NET_API_STATUS status
;
631 struct USER_INFO_1 info1
;
632 uint32_t parm_error
= 0;
634 if (argc
< 1 || c
->display_usage
) {
635 rpc_user_usage(c
, argc
, argv
);
641 info1
.usri1_name
= argv
[0];
643 info1
.usri1_password
= argv
[1];
646 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
649 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
650 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
654 d_printf("Added user '%s'.\n", argv
[0]);
661 * Rename a user on a remote RPC server.
663 * @param argc Standard main() style argc.
664 * @param argv Standard main() style argv. Initial components are already
667 * @return A shell status integer (0 for success).
670 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
672 NET_API_STATUS status
;
673 struct USER_INFO_0 u0
;
674 uint32_t parm_err
= 0;
676 if (argc
!= 2 || c
->display_usage
) {
677 rpc_user_usage(c
, argc
, argv
);
681 u0
.usri0_name
= argv
[1];
683 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
684 0, (uint8_t *)&u0
, &parm_err
);
686 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n",
688 libnetapi_get_error_string(c
->netapi_ctx
, status
));
690 d_printf("Renamed user from %s to %s\n", argv
[0], argv
[1]);
697 * Delete a user from a remote RPC server.
699 * @param argc Standard main() style argc.
700 * @param argv Standard main() style argv. Initial components are already
703 * @return A shell status integer (0 for success).
706 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
708 NET_API_STATUS status
;
710 if (argc
< 1 || c
->display_usage
) {
711 rpc_user_usage(c
, argc
, argv
);
715 status
= NetUserDel(c
->opt_host
, argv
[0]);
718 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
720 libnetapi_get_error_string(c
->netapi_ctx
, status
));
723 d_printf("Deleted user '%s'.\n", argv
[0]);
730 * Set a user's password on a remote RPC server.
732 * @param argc Standard main() style argc.
733 * @param argv Standard main() style argv. Initial components are already
736 * @return A shell status integer (0 for success).
739 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
741 NET_API_STATUS status
;
743 struct USER_INFO_1003 u1003
;
744 uint32_t parm_err
= 0;
746 if (argc
< 1 || c
->display_usage
) {
747 rpc_user_usage(c
, argc
, argv
);
752 u1003
.usri1003_password
= argv
[1];
754 asprintf(&prompt
, "Enter new password for %s:", argv
[0]);
755 u1003
.usri1003_password
= getpass(prompt
);
759 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
761 /* Display results */
763 d_fprintf(stderr
, "Failed to set password for '%s' with: %s.\n",
764 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
773 * List a user's groups from a remote RPC server.
775 * @param argc Standard main() style argc.
776 * @param argv Standard main() style argv. Initial components are already
779 * @return A shell status integer (0 for success)
782 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
785 NET_API_STATUS status
;
786 struct GROUP_USERS_INFO_0
*u0
= NULL
;
787 uint32_t entries_read
= 0;
788 uint32_t total_entries
= 0;
792 if (argc
< 1 || c
->display_usage
) {
793 rpc_user_usage(c
, argc
, argv
);
797 status
= NetUserGetGroups(c
->opt_host
,
805 d_fprintf(stderr
, "Failed to get groups for '%s' with: %s.\n",
806 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
811 for (i
=0; i
< entries_read
; i
++) {
812 printf("%s\n", u0
->grui0_name
);
820 * List users on a remote RPC server.
822 * All parameters are provided by the run_rpc_command function, except for
823 * argc, argv which are passed through.
825 * @param domain_sid The domain sid acquired from the remote server.
826 * @param cli A cli_state connected to the server.
827 * @param mem_ctx Talloc context, destroyed on completion of the function.
828 * @param argc Standard main() style argc.
829 * @param argv Standard main() style argv. Initial components are already
832 * @return Normal NTSTATUS return.
835 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
837 NET_API_STATUS status
;
838 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
839 struct NET_DISPLAY_USER
*info
= NULL
;
842 /* Query domain users */
843 if (c
->opt_long_list_entries
)
844 d_printf("\nUser name Comment"
845 "\n-----------------------------\n");
847 uint32_t max_entries
, max_size
;
849 get_query_dispinfo_params(
850 loop_count
, &max_entries
, &max_size
);
852 status
= NetQueryDisplayInformation(c
->opt_host
,
859 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
863 info
= (struct NET_DISPLAY_USER
*)buffer
;
865 for (i
= 0; i
< num_entries
; i
++) {
867 if (c
->opt_long_list_entries
)
868 printf("%-21.21s %s\n", info
->usri1_name
,
869 info
->usri1_comment
);
871 printf("%s\n", info
->usri1_name
);
875 NetApiBufferFree(buffer
);
878 start_idx
+= num_entries
;
880 } while (status
== ERROR_MORE_DATA
);
886 * 'net rpc user' entrypoint.
887 * @param argc Standard main() style argc.
888 * @param argv Standard main() style argv. Initial components are already
892 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
894 NET_API_STATUS status
;
896 struct functable func
[] = {
901 "Add specified user",
903 " Add specified user"
909 "List domain groups of user",
910 "net rpc user info\n"
911 " Lis domain groups of user"
917 "Remove specified user",
918 "net rpc user delete\n"
919 " Remove specified user"
925 "Change user password",
926 "net rpc user password\n"
927 " Change user password"
933 "Rename specified user",
934 "net rpc user rename\n"
935 " Rename specified user"
937 {NULL
, NULL
, 0, NULL
, NULL
}
940 status
= libnetapi_init(&c
->netapi_ctx
);
944 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
945 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
946 if (c
->opt_kerberos
) {
947 libnetapi_set_use_kerberos(c
->netapi_ctx
);
951 if (c
->display_usage
) {
952 d_printf("Usage:\n");
953 d_printf("net rpc user\n"
954 " List all users\n");
955 net_display_usage_from_functable(func
);
959 return rpc_user_list(c
, argc
, argv
);
962 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
965 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
967 struct rpc_sh_ctx
*ctx
,
968 struct rpc_pipe_client
*pipe_hnd
,
969 int argc
, const char **argv
)
971 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
974 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
976 struct rpc_sh_ctx
*ctx
,
977 struct rpc_pipe_client
*pipe_hnd
,
978 int argc
, const char **argv
)
980 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
983 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
985 struct rpc_sh_ctx
*ctx
,
986 struct rpc_pipe_client
*pipe_hnd
,
987 int argc
, const char **argv
,
989 struct net_context
*c
,
991 struct rpc_sh_ctx
*ctx
,
992 struct rpc_pipe_client
*pipe_hnd
,
993 POLICY_HND
*user_hnd
,
994 int argc
, const char **argv
))
996 POLICY_HND connect_pol
, domain_pol
, user_pol
;
997 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1000 enum lsa_SidType type
;
1003 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1004 return NT_STATUS_INVALID_PARAMETER
;
1007 ZERO_STRUCT(connect_pol
);
1008 ZERO_STRUCT(domain_pol
);
1009 ZERO_STRUCT(user_pol
);
1011 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1012 argv
[0], NULL
, NULL
, &sid
, &type
);
1013 if (!NT_STATUS_IS_OK(result
)) {
1014 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1019 if (type
!= SID_NAME_USER
) {
1020 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1021 sid_type_lookup(type
));
1022 result
= NT_STATUS_NO_SUCH_USER
;
1026 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1027 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1028 result
= NT_STATUS_NO_SUCH_USER
;
1032 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1034 MAXIMUM_ALLOWED_ACCESS
,
1036 if (!NT_STATUS_IS_OK(result
)) {
1040 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1042 MAXIMUM_ALLOWED_ACCESS
,
1045 if (!NT_STATUS_IS_OK(result
)) {
1049 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1051 MAXIMUM_ALLOWED_ACCESS
,
1054 if (!NT_STATUS_IS_OK(result
)) {
1058 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1061 if (is_valid_policy_hnd(&user_pol
)) {
1062 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1064 if (is_valid_policy_hnd(&domain_pol
)) {
1065 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1067 if (is_valid_policy_hnd(&connect_pol
)) {
1068 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1073 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1074 TALLOC_CTX
*mem_ctx
,
1075 struct rpc_sh_ctx
*ctx
,
1076 struct rpc_pipe_client
*pipe_hnd
,
1077 POLICY_HND
*user_hnd
,
1078 int argc
, const char **argv
)
1081 union samr_UserInfo
*info
= NULL
;
1084 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1085 return NT_STATUS_INVALID_PARAMETER
;
1088 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1092 if (!NT_STATUS_IS_OK(result
)) {
1096 d_printf("user rid: %d, group rid: %d\n",
1098 info
->info21
.primary_gid
);
1103 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1104 TALLOC_CTX
*mem_ctx
,
1105 struct rpc_sh_ctx
*ctx
,
1106 struct rpc_pipe_client
*pipe_hnd
,
1107 int argc
, const char **argv
)
1109 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1110 rpc_sh_user_show_internals
);
1113 #define FETCHSTR(name, rec) \
1114 do { if (strequal(ctx->thiscmd, name)) { \
1115 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1118 #define SETSTR(name, rec, flag) \
1119 do { if (strequal(ctx->thiscmd, name)) { \
1120 init_lsa_String(&(info->info21.rec), argv[0]); \
1121 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1124 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1125 TALLOC_CTX
*mem_ctx
,
1126 struct rpc_sh_ctx
*ctx
,
1127 struct rpc_pipe_client
*pipe_hnd
,
1128 POLICY_HND
*user_hnd
,
1129 int argc
, const char **argv
)
1132 const char *username
;
1133 const char *oldval
= "";
1134 union samr_UserInfo
*info
= NULL
;
1137 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1139 return NT_STATUS_INVALID_PARAMETER
;
1142 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1146 if (!NT_STATUS_IS_OK(result
)) {
1150 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1152 FETCHSTR("fullname", full_name
);
1153 FETCHSTR("homedir", home_directory
);
1154 FETCHSTR("homedrive", home_drive
);
1155 FETCHSTR("logonscript", logon_script
);
1156 FETCHSTR("profilepath", profile_path
);
1157 FETCHSTR("description", description
);
1160 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1164 if (strcmp(argv
[0], "NULL") == 0) {
1168 ZERO_STRUCT(info
->info21
);
1170 SETSTR("fullname", full_name
, FULL_NAME
);
1171 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1172 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1173 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1174 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1175 SETSTR("description", description
, DESCRIPTION
);
1177 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1182 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1183 ctx
->thiscmd
, oldval
, argv
[0]);
1190 #define HANDLEFLG(name, rec) \
1191 do { if (strequal(ctx->thiscmd, name)) { \
1192 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1194 newflags = oldflags | ACB_##rec; \
1196 newflags = oldflags & ~ACB_##rec; \
1199 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1200 TALLOC_CTX
*mem_ctx
,
1201 struct rpc_sh_ctx
*ctx
,
1202 struct rpc_pipe_client
*pipe_hnd
,
1203 int argc
, const char **argv
)
1205 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1206 rpc_sh_user_str_edit_internals
);
1209 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1210 TALLOC_CTX
*mem_ctx
,
1211 struct rpc_sh_ctx
*ctx
,
1212 struct rpc_pipe_client
*pipe_hnd
,
1213 POLICY_HND
*user_hnd
,
1214 int argc
, const char **argv
)
1217 const char *username
;
1218 const char *oldval
= "unknown";
1219 uint32 oldflags
, newflags
;
1221 union samr_UserInfo
*info
= NULL
;
1224 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1225 !strequal(argv
[0], "no"))) {
1226 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1228 return NT_STATUS_INVALID_PARAMETER
;
1231 newval
= strequal(argv
[0], "yes");
1233 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1237 if (!NT_STATUS_IS_OK(result
)) {
1241 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1242 oldflags
= info
->info21
.acct_flags
;
1243 newflags
= info
->info21
.acct_flags
;
1245 HANDLEFLG("disabled", DISABLED
);
1246 HANDLEFLG("pwnotreq", PWNOTREQ
);
1247 HANDLEFLG("autolock", AUTOLOCK
);
1248 HANDLEFLG("pwnoexp", PWNOEXP
);
1251 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1255 ZERO_STRUCT(info
->info21
);
1257 info
->info21
.acct_flags
= newflags
;
1258 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1260 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1265 if (NT_STATUS_IS_OK(result
)) {
1266 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1267 ctx
->thiscmd
, oldval
, argv
[0]);
1275 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1276 TALLOC_CTX
*mem_ctx
,
1277 struct rpc_sh_ctx
*ctx
,
1278 struct rpc_pipe_client
*pipe_hnd
,
1279 int argc
, const char **argv
)
1281 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1282 rpc_sh_user_flag_edit_internals
);
1285 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1286 TALLOC_CTX
*mem_ctx
,
1287 struct rpc_sh_ctx
*ctx
)
1289 static struct rpc_sh_cmd cmds
[] = {
1291 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1292 "Show/Set a user's full name" },
1294 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1295 "Show/Set a user's home directory" },
1297 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1298 "Show/Set a user's home drive" },
1300 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1301 "Show/Set a user's logon script" },
1303 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1304 "Show/Set a user's profile path" },
1306 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1307 "Show/Set a user's description" },
1309 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1310 "Show/Set whether a user is disabled" },
1312 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1313 "Show/Set whether a user locked out" },
1315 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1316 "Show/Set whether a user does not need a password" },
1318 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1319 "Show/Set whether a user's password does not expire" },
1321 { NULL
, NULL
, 0, NULL
, NULL
}
1327 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1328 TALLOC_CTX
*mem_ctx
,
1329 struct rpc_sh_ctx
*ctx
)
1331 static struct rpc_sh_cmd cmds
[] = {
1333 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1334 "List available users" },
1336 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1337 "List the domain groups a user is member of" },
1339 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1340 "Show info about a user" },
1342 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1343 "Show/Modify a user's fields" },
1345 { NULL
, NULL
, 0, NULL
, NULL
}
1351 /****************************************************************************/
1354 * Basic usage function for 'net rpc group'.
1355 * @param argc Standard main() style argc.
1356 * @param argv Standard main() style argv. Initial components are already
1360 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1362 return net_group_usage(c
, argc
, argv
);
1366 * Delete group on a remote RPC server.
1368 * All parameters are provided by the run_rpc_command function, except for
1369 * argc, argv which are passed through.
1371 * @param domain_sid The domain sid acquired from the remote server.
1372 * @param cli A cli_state connected to the server.
1373 * @param mem_ctx Talloc context, destroyed on completion of the function.
1374 * @param argc Standard main() style argc.
1375 * @param argv Standard main() style argv. Initial components are already
1378 * @return Normal NTSTATUS return.
1381 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1382 const DOM_SID
*domain_sid
,
1383 const char *domain_name
,
1384 struct cli_state
*cli
,
1385 struct rpc_pipe_client
*pipe_hnd
,
1386 TALLOC_CTX
*mem_ctx
,
1390 POLICY_HND connect_pol
, domain_pol
, group_pol
, user_pol
;
1391 bool group_is_primary
= false;
1392 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1394 struct samr_RidTypeArray
*rids
= NULL
;
1397 /* DOM_GID *user_gids; */
1399 struct samr_Ids group_rids
, name_types
;
1400 struct lsa_String lsa_acct_name
;
1401 union samr_UserInfo
*info
= NULL
;
1403 if (argc
< 1 || c
->display_usage
) {
1404 rpc_group_usage(c
, argc
,argv
);
1405 return NT_STATUS_OK
; /* ok? */
1408 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1410 MAXIMUM_ALLOWED_ACCESS
,
1413 if (!NT_STATUS_IS_OK(result
)) {
1414 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1418 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1420 MAXIMUM_ALLOWED_ACCESS
,
1421 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1424 if (!NT_STATUS_IS_OK(result
)) {
1425 d_fprintf(stderr
, "Request open_domain failed\n");
1429 init_lsa_String(&lsa_acct_name
, argv
[0]);
1431 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1437 if (!NT_STATUS_IS_OK(result
)) {
1438 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1442 switch (name_types
.ids
[0])
1444 case SID_NAME_DOM_GRP
:
1445 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1447 MAXIMUM_ALLOWED_ACCESS
,
1450 if (!NT_STATUS_IS_OK(result
)) {
1451 d_fprintf(stderr
, "Request open_group failed");
1455 group_rid
= group_rids
.ids
[0];
1457 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1461 if (!NT_STATUS_IS_OK(result
)) {
1462 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1466 if (c
->opt_verbose
) {
1467 d_printf("Domain Group %s (rid: %d) has %d members\n",
1468 argv
[0],group_rid
, rids
->count
);
1471 /* Check if group is anyone's primary group */
1472 for (i
= 0; i
< rids
->count
; i
++)
1474 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1476 MAXIMUM_ALLOWED_ACCESS
,
1480 if (!NT_STATUS_IS_OK(result
)) {
1481 d_fprintf(stderr
, "Unable to open group member %d\n",
1486 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1491 if (!NT_STATUS_IS_OK(result
)) {
1492 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1497 if (info
->info21
.primary_gid
== group_rid
) {
1498 if (c
->opt_verbose
) {
1499 d_printf("Group is primary group of %s\n",
1500 info
->info21
.account_name
.string
);
1502 group_is_primary
= true;
1505 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1508 if (group_is_primary
) {
1509 d_fprintf(stderr
, "Unable to delete group because some "
1510 "of it's members have it as primary group\n");
1511 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1515 /* remove all group members */
1516 for (i
= 0; i
< rids
->count
; i
++)
1519 d_printf("Remove group member %d...",
1521 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1525 if (NT_STATUS_IS_OK(result
)) {
1530 d_printf("failed\n");
1535 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1539 /* removing a local group is easier... */
1540 case SID_NAME_ALIAS
:
1541 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1543 MAXIMUM_ALLOWED_ACCESS
,
1547 if (!NT_STATUS_IS_OK(result
)) {
1548 d_fprintf(stderr
, "Request open_alias failed\n");
1552 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1556 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1557 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1558 result
= NT_STATUS_UNSUCCESSFUL
;
1562 if (NT_STATUS_IS_OK(result
)) {
1564 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1566 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1567 get_friendly_nt_error_msg(result
));
1575 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1577 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1578 rpc_group_delete_internals
, argc
,argv
);
1581 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1583 NET_API_STATUS status
;
1584 struct GROUP_INFO_1 info1
;
1585 uint32_t parm_error
= 0;
1587 if (argc
!= 1 || c
->display_usage
) {
1588 rpc_group_usage(c
, argc
, argv
);
1594 info1
.grpi1_name
= argv
[0];
1595 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1596 info1
.grpi1_comment
= c
->opt_comment
;
1599 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1602 d_fprintf(stderr
, "Failed to add group '%s' with: %s.\n",
1603 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1607 d_printf("Added group '%s'.\n", argv
[0]);
1613 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1615 NET_API_STATUS status
;
1616 struct LOCALGROUP_INFO_1 info1
;
1617 uint32_t parm_error
= 0;
1619 if (argc
!= 1 || c
->display_usage
) {
1620 rpc_group_usage(c
, argc
, argv
);
1626 info1
.lgrpi1_name
= argv
[0];
1627 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1628 info1
.lgrpi1_comment
= c
->opt_comment
;
1631 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1634 d_fprintf(stderr
, "Failed to add alias '%s' with: %s.\n",
1635 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1639 d_printf("Added alias '%s'.\n", argv
[0]);
1645 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1647 if (c
->opt_localgroup
)
1648 return rpc_alias_add_internals(c
, argc
, argv
);
1650 return rpc_group_add_internals(c
, argc
, argv
);
1653 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1654 TALLOC_CTX
*mem_ctx
,
1657 enum lsa_SidType
*type
)
1659 DOM_SID
*sids
= NULL
;
1660 enum lsa_SidType
*types
= NULL
;
1661 struct rpc_pipe_client
*pipe_hnd
;
1663 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1665 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1667 if (!NT_STATUS_IS_OK(result
)) {
1671 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1672 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
1674 if (!NT_STATUS_IS_OK(result
)) {
1678 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1679 &name
, NULL
, 1, &sids
, &types
);
1681 if (NT_STATUS_IS_OK(result
)) {
1682 sid_copy(sid
, &sids
[0]);
1686 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1690 TALLOC_FREE(pipe_hnd
);
1693 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1695 /* Try as S-1-5-whatever */
1699 if (string_to_sid(&tmp_sid
, name
)) {
1700 sid_copy(sid
, &tmp_sid
);
1701 *type
= SID_NAME_UNKNOWN
;
1702 result
= NT_STATUS_OK
;
1709 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1710 TALLOC_CTX
*mem_ctx
,
1711 const DOM_SID
*group_sid
,
1714 POLICY_HND connect_pol
, domain_pol
;
1717 POLICY_HND group_pol
;
1719 struct samr_Ids rids
, rid_types
;
1720 struct lsa_String lsa_acct_name
;
1724 sid_copy(&sid
, group_sid
);
1726 if (!sid_split_rid(&sid
, &group_rid
)) {
1727 return NT_STATUS_UNSUCCESSFUL
;
1730 /* Get sam policy handle */
1731 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1733 MAXIMUM_ALLOWED_ACCESS
,
1735 if (!NT_STATUS_IS_OK(result
)) {
1739 /* Get domain policy handle */
1740 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1742 MAXIMUM_ALLOWED_ACCESS
,
1745 if (!NT_STATUS_IS_OK(result
)) {
1749 init_lsa_String(&lsa_acct_name
, member
);
1751 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1758 if (!NT_STATUS_IS_OK(result
)) {
1759 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1763 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1765 MAXIMUM_ALLOWED_ACCESS
,
1769 if (!NT_STATUS_IS_OK(result
)) {
1773 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1776 0x0005); /* unknown flags */
1779 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1783 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1784 TALLOC_CTX
*mem_ctx
,
1785 const DOM_SID
*alias_sid
,
1788 POLICY_HND connect_pol
, domain_pol
;
1791 POLICY_HND alias_pol
;
1794 enum lsa_SidType member_type
;
1798 sid_copy(&sid
, alias_sid
);
1800 if (!sid_split_rid(&sid
, &alias_rid
)) {
1801 return NT_STATUS_UNSUCCESSFUL
;
1804 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1805 member
, &member_sid
, &member_type
);
1807 if (!NT_STATUS_IS_OK(result
)) {
1808 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1812 /* Get sam policy handle */
1813 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1815 MAXIMUM_ALLOWED_ACCESS
,
1817 if (!NT_STATUS_IS_OK(result
)) {
1821 /* Get domain policy handle */
1822 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1824 MAXIMUM_ALLOWED_ACCESS
,
1827 if (!NT_STATUS_IS_OK(result
)) {
1831 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1833 MAXIMUM_ALLOWED_ACCESS
,
1837 if (!NT_STATUS_IS_OK(result
)) {
1841 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1845 if (!NT_STATUS_IS_OK(result
)) {
1850 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1854 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1855 const DOM_SID
*domain_sid
,
1856 const char *domain_name
,
1857 struct cli_state
*cli
,
1858 struct rpc_pipe_client
*pipe_hnd
,
1859 TALLOC_CTX
*mem_ctx
,
1864 enum lsa_SidType group_type
;
1866 if (argc
!= 2 || c
->display_usage
) {
1868 "net rpc group addmem <group> <member>\n"
1869 " Add a member to a group\n"
1870 " group\tGroup to add member to\n"
1871 " member\tMember to add to group\n");
1872 return NT_STATUS_UNSUCCESSFUL
;
1875 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1876 &group_sid
, &group_type
))) {
1877 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
1878 return NT_STATUS_UNSUCCESSFUL
;
1881 if (group_type
== SID_NAME_DOM_GRP
) {
1882 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1883 &group_sid
, argv
[1]);
1885 if (!NT_STATUS_IS_OK(result
)) {
1886 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1887 argv
[1], argv
[0], nt_errstr(result
));
1892 if (group_type
== SID_NAME_ALIAS
) {
1893 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1894 &group_sid
, argv
[1]);
1896 if (!NT_STATUS_IS_OK(result
)) {
1897 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1898 argv
[1], argv
[0], nt_errstr(result
));
1903 d_fprintf(stderr
, "Can only add members to global or local groups "
1904 "which %s is not\n", argv
[0]);
1906 return NT_STATUS_UNSUCCESSFUL
;
1909 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1911 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1912 rpc_group_addmem_internals
,
1916 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1917 struct rpc_pipe_client
*pipe_hnd
,
1918 TALLOC_CTX
*mem_ctx
,
1919 const DOM_SID
*group_sid
,
1922 POLICY_HND connect_pol
, domain_pol
;
1925 POLICY_HND group_pol
;
1927 struct samr_Ids rids
, rid_types
;
1928 struct lsa_String lsa_acct_name
;
1932 sid_copy(&sid
, group_sid
);
1934 if (!sid_split_rid(&sid
, &group_rid
))
1935 return NT_STATUS_UNSUCCESSFUL
;
1937 /* Get sam policy handle */
1938 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1940 MAXIMUM_ALLOWED_ACCESS
,
1942 if (!NT_STATUS_IS_OK(result
))
1945 /* Get domain policy handle */
1946 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1948 MAXIMUM_ALLOWED_ACCESS
,
1951 if (!NT_STATUS_IS_OK(result
))
1954 init_lsa_String(&lsa_acct_name
, member
);
1956 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1962 if (!NT_STATUS_IS_OK(result
)) {
1963 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1967 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1969 MAXIMUM_ALLOWED_ACCESS
,
1973 if (!NT_STATUS_IS_OK(result
))
1976 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1981 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1985 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1986 TALLOC_CTX
*mem_ctx
,
1987 const DOM_SID
*alias_sid
,
1990 POLICY_HND connect_pol
, domain_pol
;
1993 POLICY_HND alias_pol
;
1996 enum lsa_SidType member_type
;
2000 sid_copy(&sid
, alias_sid
);
2002 if (!sid_split_rid(&sid
, &alias_rid
))
2003 return NT_STATUS_UNSUCCESSFUL
;
2005 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2006 member
, &member_sid
, &member_type
);
2008 if (!NT_STATUS_IS_OK(result
)) {
2009 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2013 /* Get sam policy handle */
2014 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2016 MAXIMUM_ALLOWED_ACCESS
,
2018 if (!NT_STATUS_IS_OK(result
)) {
2022 /* Get domain policy handle */
2023 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2025 MAXIMUM_ALLOWED_ACCESS
,
2028 if (!NT_STATUS_IS_OK(result
)) {
2032 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2034 MAXIMUM_ALLOWED_ACCESS
,
2038 if (!NT_STATUS_IS_OK(result
))
2041 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2045 if (!NT_STATUS_IS_OK(result
))
2049 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2053 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2054 const DOM_SID
*domain_sid
,
2055 const char *domain_name
,
2056 struct cli_state
*cli
,
2057 struct rpc_pipe_client
*pipe_hnd
,
2058 TALLOC_CTX
*mem_ctx
,
2063 enum lsa_SidType group_type
;
2065 if (argc
!= 2 || c
->display_usage
) {
2067 "net rpc group delmem <group> <member>\n"
2068 " Delete a member from a group\n"
2069 " group\tGroup to delete member from\n"
2070 " member\tMember to delete from group\n");
2071 return NT_STATUS_UNSUCCESSFUL
;
2074 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2075 &group_sid
, &group_type
))) {
2076 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2077 return NT_STATUS_UNSUCCESSFUL
;
2080 if (group_type
== SID_NAME_DOM_GRP
) {
2081 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2082 &group_sid
, argv
[1]);
2084 if (!NT_STATUS_IS_OK(result
)) {
2085 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2086 argv
[1], argv
[0], nt_errstr(result
));
2091 if (group_type
== SID_NAME_ALIAS
) {
2092 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2093 &group_sid
, argv
[1]);
2095 if (!NT_STATUS_IS_OK(result
)) {
2096 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2097 argv
[1], argv
[0], nt_errstr(result
));
2102 d_fprintf(stderr
, "Can only delete members from global or local groups "
2103 "which %s is not\n", argv
[0]);
2105 return NT_STATUS_UNSUCCESSFUL
;
2108 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2110 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2111 rpc_group_delmem_internals
,
2116 * List groups on a remote RPC server.
2118 * All parameters are provided by the run_rpc_command function, except for
2119 * argc, argv which are passes through.
2121 * @param domain_sid The domain sid acquired from the remote server.
2122 * @param cli A cli_state connected to the server.
2123 * @param mem_ctx Talloc context, destroyed on completion of the function.
2124 * @param argc Standard main() style argc.
2125 * @param argv Standard main() style argv. Initial components are already
2128 * @return Normal NTSTATUS return.
2131 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2132 const DOM_SID
*domain_sid
,
2133 const char *domain_name
,
2134 struct cli_state
*cli
,
2135 struct rpc_pipe_client
*pipe_hnd
,
2136 TALLOC_CTX
*mem_ctx
,
2140 POLICY_HND connect_pol
, domain_pol
;
2141 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2142 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2143 struct samr_SamArray
*groups
= NULL
;
2144 bool global
= false;
2146 bool builtin
= false;
2148 if (c
->display_usage
) {
2150 "net rpc group list [global] [local] [builtin]\n"
2151 " List groups on RPC server\n"
2152 " global\tList global groups\n"
2153 " local\tList local groups\n"
2154 " builtin\tList builtin groups\n"
2155 " If none of global, local or builtin is "
2156 "specified, all three options are considered set\n");
2157 return NT_STATUS_OK
;
2166 for (i
=0; i
<argc
; i
++) {
2167 if (strequal(argv
[i
], "global"))
2170 if (strequal(argv
[i
], "local"))
2173 if (strequal(argv
[i
], "builtin"))
2177 /* Get sam policy handle */
2179 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2181 MAXIMUM_ALLOWED_ACCESS
,
2183 if (!NT_STATUS_IS_OK(result
)) {
2187 /* Get domain policy handle */
2189 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2191 MAXIMUM_ALLOWED_ACCESS
,
2192 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2194 if (!NT_STATUS_IS_OK(result
)) {
2198 /* Query domain groups */
2199 if (c
->opt_long_list_entries
)
2200 d_printf("\nGroup name Comment"
2201 "\n-----------------------------\n");
2203 uint32_t max_size
, total_size
, returned_size
;
2204 union samr_DispInfo info
;
2208 get_query_dispinfo_params(
2209 loop_count
, &max_entries
, &max_size
);
2211 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2220 num_entries
= info
.info3
.count
;
2221 start_idx
+= info
.info3
.count
;
2223 if (!NT_STATUS_IS_OK(result
) &&
2224 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2227 for (i
= 0; i
< num_entries
; i
++) {
2229 const char *group
= NULL
;
2230 const char *desc
= NULL
;
2232 group
= info
.info3
.entries
[i
].account_name
.string
;
2233 desc
= info
.info3
.entries
[i
].description
.string
;
2235 if (c
->opt_long_list_entries
)
2236 printf("%-21.21s %-50.50s\n",
2239 printf("%s\n", group
);
2241 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2242 /* query domain aliases */
2247 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2253 if (!NT_STATUS_IS_OK(result
) &&
2254 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2257 for (i
= 0; i
< num_entries
; i
++) {
2259 const char *description
= NULL
;
2261 if (c
->opt_long_list_entries
) {
2263 POLICY_HND alias_pol
;
2264 union samr_AliasInfo
*info
= NULL
;
2266 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2269 groups
->entries
[i
].idx
,
2271 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2275 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2277 description
= info
->description
.string
;
2281 if (description
!= NULL
) {
2282 printf("%-21.21s %-50.50s\n",
2283 groups
->entries
[i
].name
.string
,
2286 printf("%s\n", groups
->entries
[i
].name
.string
);
2289 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2290 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2291 /* Get builtin policy handle */
2293 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2295 MAXIMUM_ALLOWED_ACCESS
,
2296 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2298 if (!NT_STATUS_IS_OK(result
)) {
2301 /* query builtin aliases */
2304 if (!builtin
) break;
2306 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2312 if (!NT_STATUS_IS_OK(result
) &&
2313 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2316 for (i
= 0; i
< num_entries
; i
++) {
2318 const char *description
= NULL
;
2320 if (c
->opt_long_list_entries
) {
2322 POLICY_HND alias_pol
;
2323 union samr_AliasInfo
*info
= NULL
;
2325 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2328 groups
->entries
[i
].idx
,
2330 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2334 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2336 description
= info
->description
.string
;
2340 if (description
!= NULL
) {
2341 printf("%-21.21s %-50.50s\n",
2342 groups
->entries
[i
].name
.string
,
2345 printf("%s\n", groups
->entries
[i
].name
.string
);
2348 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2354 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2356 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2357 rpc_group_list_internals
,
2361 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2362 struct rpc_pipe_client
*pipe_hnd
,
2363 TALLOC_CTX
*mem_ctx
,
2364 const char *domain_name
,
2365 const DOM_SID
*domain_sid
,
2366 POLICY_HND
*domain_pol
,
2370 POLICY_HND group_pol
;
2371 uint32 num_members
, *group_rids
;
2373 struct samr_RidTypeArray
*rids
= NULL
;
2374 struct lsa_Strings names
;
2375 struct samr_Ids types
;
2378 sid_to_fstring(sid_str
, domain_sid
);
2380 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2382 MAXIMUM_ALLOWED_ACCESS
,
2386 if (!NT_STATUS_IS_OK(result
))
2389 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2393 if (!NT_STATUS_IS_OK(result
))
2396 num_members
= rids
->count
;
2397 group_rids
= rids
->rids
;
2399 while (num_members
> 0) {
2400 int this_time
= 512;
2402 if (num_members
< this_time
)
2403 this_time
= num_members
;
2405 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2412 if (!NT_STATUS_IS_OK(result
))
2415 /* We only have users as members, but make the output
2416 the same as the output of alias members */
2418 for (i
= 0; i
< this_time
; i
++) {
2420 if (c
->opt_long_list_entries
) {
2421 printf("%s-%d %s\\%s %d\n", sid_str
,
2422 group_rids
[i
], domain_name
,
2423 names
.names
[i
].string
,
2426 printf("%s\\%s\n", domain_name
,
2427 names
.names
[i
].string
);
2431 num_members
-= this_time
;
2435 return NT_STATUS_OK
;
2438 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2439 struct rpc_pipe_client
*pipe_hnd
,
2440 TALLOC_CTX
*mem_ctx
,
2441 POLICY_HND
*domain_pol
,
2445 struct rpc_pipe_client
*lsa_pipe
;
2446 POLICY_HND alias_pol
, lsa_pol
;
2448 DOM_SID
*alias_sids
;
2451 enum lsa_SidType
*types
;
2453 struct lsa_SidArray sid_array
;
2455 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2457 MAXIMUM_ALLOWED_ACCESS
,
2461 if (!NT_STATUS_IS_OK(result
))
2464 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2468 if (!NT_STATUS_IS_OK(result
)) {
2469 d_fprintf(stderr
, "Couldn't list alias members\n");
2473 num_members
= sid_array
.num_sids
;
2475 if (num_members
== 0) {
2476 return NT_STATUS_OK
;
2479 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2480 &ndr_table_lsarpc
.syntax_id
,
2482 if (!NT_STATUS_IS_OK(result
)) {
2483 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2484 nt_errstr(result
) );
2488 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2489 SEC_RIGHTS_MAXIMUM_ALLOWED
, &lsa_pol
);
2491 if (!NT_STATUS_IS_OK(result
)) {
2492 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2493 TALLOC_FREE(lsa_pipe
);
2497 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2499 d_fprintf(stderr
, "Out of memory\n");
2500 TALLOC_FREE(lsa_pipe
);
2501 return NT_STATUS_NO_MEMORY
;
2504 for (i
=0; i
<num_members
; i
++) {
2505 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2508 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2509 num_members
, alias_sids
,
2510 &domains
, &names
, &types
);
2512 if (!NT_STATUS_IS_OK(result
) &&
2513 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2514 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2515 TALLOC_FREE(lsa_pipe
);
2519 for (i
= 0; i
< num_members
; i
++) {
2521 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2523 if (c
->opt_long_list_entries
) {
2524 printf("%s %s\\%s %d\n", sid_str
,
2525 domains
[i
] ? domains
[i
] : "*unknown*",
2526 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2529 printf("%s\\%s\n", domains
[i
], names
[i
]);
2531 printf("%s\n", sid_str
);
2535 TALLOC_FREE(lsa_pipe
);
2536 return NT_STATUS_OK
;
2539 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2540 const DOM_SID
*domain_sid
,
2541 const char *domain_name
,
2542 struct cli_state
*cli
,
2543 struct rpc_pipe_client
*pipe_hnd
,
2544 TALLOC_CTX
*mem_ctx
,
2549 POLICY_HND connect_pol
, domain_pol
;
2550 struct samr_Ids rids
, rid_types
;
2551 struct lsa_String lsa_acct_name
;
2553 /* Get sam policy handle */
2555 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2557 MAXIMUM_ALLOWED_ACCESS
,
2560 if (!NT_STATUS_IS_OK(result
))
2563 /* Get domain policy handle */
2565 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2567 MAXIMUM_ALLOWED_ACCESS
,
2568 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2571 if (!NT_STATUS_IS_OK(result
))
2574 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2576 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2583 if (!NT_STATUS_IS_OK(result
)) {
2585 /* Ok, did not find it in the global sam, try with builtin */
2587 DOM_SID sid_Builtin
;
2589 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2591 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2593 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2595 MAXIMUM_ALLOWED_ACCESS
,
2599 if (!NT_STATUS_IS_OK(result
)) {
2600 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2604 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2611 if (!NT_STATUS_IS_OK(result
)) {
2612 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2617 if (rids
.count
!= 1) {
2618 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2622 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2623 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2624 domain_sid
, &domain_pol
,
2628 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2629 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2633 return NT_STATUS_NO_SUCH_GROUP
;
2636 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2638 if (argc
!= 1 || c
->display_usage
) {
2639 return rpc_group_usage(c
, argc
, argv
);
2642 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2643 rpc_group_members_internals
,
2647 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2649 NET_API_STATUS status
;
2650 struct GROUP_INFO_0 g0
;
2654 d_printf("Usage: 'net rpc group rename group newname'\n");
2658 g0
.grpi0_name
= argv
[1];
2660 status
= NetGroupSetInfo(c
->opt_host
,
2667 d_fprintf(stderr
, "Renaming group %s failed with: %s\n",
2668 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2676 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2678 if (argc
!= 2 || c
->display_usage
) {
2679 return rpc_group_usage(c
, argc
, argv
);
2682 return rpc_group_rename_internals(c
, argc
, argv
);
2686 * 'net rpc group' entrypoint.
2687 * @param argc Standard main() style argc.
2688 * @param argv Standard main() style argv. Initial components are already
2692 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2694 NET_API_STATUS status
;
2696 struct functable func
[] = {
2701 "Create specified group",
2702 "net rpc group add\n"
2703 " Create specified group"
2709 "Delete specified group",
2710 "net rpc group delete\n"
2711 " Delete specified group"
2717 "Add member to group",
2718 "net rpc group addmem\n"
2719 " Add member to group"
2725 "Remove member from group",
2726 "net rpc group delmem\n"
2727 " Remove member from group"
2734 "net rpc group list\n"
2741 "List group members",
2742 "net rpc group members\n"
2743 " List group members"
2750 "net rpc group rename\n"
2753 {NULL
, NULL
, 0, NULL
, NULL
}
2756 status
= libnetapi_init(&c
->netapi_ctx
);
2760 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2761 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2762 if (c
->opt_kerberos
) {
2763 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2767 if (c
->display_usage
) {
2768 d_printf("Usage:\n");
2769 d_printf("net rpc group\n"
2770 " Alias for net rpc group list global local "
2772 net_display_usage_from_functable(func
);
2776 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2777 rpc_group_list_internals
,
2781 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2784 /****************************************************************************/
2786 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2788 return net_share_usage(c
, argc
, argv
);
2792 * Add a share on a remote RPC server.
2794 * @param argc Standard main() style argc.
2795 * @param argv Standard main() style argv. Initial components are already
2798 * @return A shell status integer (0 for success).
2801 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2803 NET_API_STATUS status
;
2806 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2807 uint32 num_users
=0, perms
=0;
2808 char *password
=NULL
; /* don't allow a share password */
2809 struct SHARE_INFO_2 i2
;
2810 uint32_t parm_error
= 0;
2812 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2813 return rpc_share_usage(c
, argc
, argv
);
2816 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2820 path
= strchr(sharename
, '=');
2827 i2
.shi2_netname
= sharename
;
2828 i2
.shi2_type
= type
;
2829 i2
.shi2_remark
= c
->opt_comment
;
2830 i2
.shi2_permissions
= perms
;
2831 i2
.shi2_max_uses
= c
->opt_maxusers
;
2832 i2
.shi2_current_uses
= num_users
;
2833 i2
.shi2_path
= path
;
2834 i2
.shi2_passwd
= password
;
2836 status
= NetShareAdd(c
->opt_host
,
2841 printf("NetShareAdd failed with: %s\n",
2842 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2849 * Delete a share on a remote RPC server.
2851 * All parameters are provided by the run_rpc_command function, except for
2852 * argc, argv which are passed through.
2854 * @param domain_sid The domain sid acquired from the remote server.
2855 * @param cli A cli_state connected to the server.
2856 * @param mem_ctx Talloc context, destroyed on completion of the function.
2857 * @param argc Standard main() style argc.
2858 * @param argv Standard main() style argv. Initial components are already
2861 * @return Normal NTSTATUS return.
2863 static NTSTATUS
rpc_share_del_internals(struct net_context
*c
,
2864 const DOM_SID
*domain_sid
,
2865 const char *domain_name
,
2866 struct cli_state
*cli
,
2867 struct rpc_pipe_client
*pipe_hnd
,
2868 TALLOC_CTX
*mem_ctx
,
2874 return rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
2882 * Delete a share on a remote RPC server.
2884 * @param domain_sid The domain sid acquired from the remote server.
2885 * @param argc Standard main() style argc.
2886 * @param argv Standard main() style argv. Initial components are already
2889 * @return A shell status integer (0 for success).
2891 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2893 if (argc
< 1 || c
->display_usage
) {
2894 return rpc_share_usage(c
, argc
, argv
);
2896 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
2897 rpc_share_del_internals
,
2902 * Formatted print of share info
2904 * @param info1 pointer to SRV_SHARE_INFO_1 to format
2907 static void display_share_info_1(struct net_context
*c
,
2908 struct srvsvc_NetShareInfo1
*r
)
2910 if (c
->opt_long_list_entries
) {
2911 d_printf("%-12s %-8.8s %-50s\n",
2913 share_type
[r
->type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)],
2916 d_printf("%s\n", r
->name
);
2920 static WERROR
get_share_info(struct net_context
*c
,
2921 struct rpc_pipe_client
*pipe_hnd
,
2922 TALLOC_CTX
*mem_ctx
,
2926 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2930 union srvsvc_NetShareInfo info
;
2932 /* no specific share requested, enumerate all */
2935 uint32_t preferred_len
= 0xffffffff;
2936 uint32_t total_entries
= 0;
2937 uint32_t resume_handle
= 0;
2939 info_ctr
->level
= level
;
2941 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2951 /* request just one share */
2952 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2959 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2964 ZERO_STRUCTP(info_ctr
);
2966 info_ctr
->level
= level
;
2971 struct srvsvc_NetShareCtr1
*ctr1
;
2973 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2974 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2977 ctr1
->array
= info
.info1
;
2979 info_ctr
->ctr
.ctr1
= ctr1
;
2983 struct srvsvc_NetShareCtr2
*ctr2
;
2985 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2986 W_ERROR_HAVE_NO_MEMORY(ctr2
);
2989 ctr2
->array
= info
.info2
;
2991 info_ctr
->ctr
.ctr2
= ctr2
;
2995 struct srvsvc_NetShareCtr502
*ctr502
;
2997 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
2998 W_ERROR_HAVE_NO_MEMORY(ctr502
);
3001 ctr502
->array
= info
.info502
;
3003 info_ctr
->ctr
.ctr502
= ctr502
;
3011 * List shares on a remote RPC server.
3013 * All parameters are provided by the run_rpc_command function, except for
3014 * argc, argv which are passed through.
3016 * @param domain_sid The domain sid acquired from the remote server.
3017 * @param cli A cli_state connected to the server.
3018 * @param mem_ctx Talloc context, destroyed on completion of the function.
3019 * @param argc Standard main() style argc.
3020 * @param argv Standard main() style argv. Initial components are already
3023 * @return Normal NTSTATUS return.
3026 static NTSTATUS
rpc_share_list_internals(struct net_context
*c
,
3027 const DOM_SID
*domain_sid
,
3028 const char *domain_name
,
3029 struct cli_state
*cli
,
3030 struct rpc_pipe_client
*pipe_hnd
,
3031 TALLOC_CTX
*mem_ctx
,
3035 struct srvsvc_NetShareInfoCtr info_ctr
;
3036 struct srvsvc_NetShareCtr1 ctr1
;
3038 uint32 i
, level
= 1;
3040 ZERO_STRUCT(info_ctr
);
3044 info_ctr
.ctr
.ctr1
= &ctr1
;
3046 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3048 if (!W_ERROR_IS_OK(result
))
3051 /* Display results */
3053 if (c
->opt_long_list_entries
) {
3055 "\nEnumerating shared resources (exports) on remote server:\n\n"
3056 "\nShare name Type Description\n"
3057 "---------- ---- -----------\n");
3059 for (i
= 0; i
< info_ctr
.ctr
.ctr1
->count
; i
++)
3060 display_share_info_1(c
, &info_ctr
.ctr
.ctr1
->array
[i
]);
3062 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
3066 * 'net rpc share list' entrypoint.
3067 * @param argc Standard main() style argc.
3068 * @param argv Standard main() style argv. Initial components are already
3071 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
3073 if (c
->display_usage
) {
3075 "net rpc share list\n"
3076 " List shares on remote server\n");
3080 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3081 rpc_share_list_internals
, argc
, argv
);
3084 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3086 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
3087 d_printf("skipping [%s]: not a file share.\n", netname
);
3097 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3098 const char *netname
, uint32 type
)
3100 /* only support disk shares */
3101 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3102 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3106 /* skip builtin shares */
3107 /* FIXME: should print$ be added too ? */
3108 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3109 strequal(netname
,"global"))
3112 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3113 printf("excluding [%s]\n", netname
);
3117 return check_share_availability(cli
, netname
);
3121 * Migrate shares from a remote RPC server to the local RPC server.
3123 * All parameters are provided by the run_rpc_command function, except for
3124 * argc, argv which are passed through.
3126 * @param domain_sid The domain sid acquired from the remote server.
3127 * @param cli A cli_state connected to the server.
3128 * @param mem_ctx Talloc context, destroyed on completion of the function.
3129 * @param argc Standard main() style argc.
3130 * @param argv Standard main() style argv. Initial components are already
3133 * @return Normal NTSTATUS return.
3136 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3137 const DOM_SID
*domain_sid
,
3138 const char *domain_name
,
3139 struct cli_state
*cli
,
3140 struct rpc_pipe_client
*pipe_hnd
,
3141 TALLOC_CTX
*mem_ctx
,
3146 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3147 struct srvsvc_NetShareInfoCtr ctr_src
;
3149 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3150 struct cli_state
*cli_dst
= NULL
;
3151 uint32 level
= 502; /* includes secdesc */
3152 uint32_t parm_error
= 0;
3154 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3156 if (!W_ERROR_IS_OK(result
))
3159 /* connect destination PI_SRVSVC */
3160 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3161 &ndr_table_srvsvc
.syntax_id
);
3162 if (!NT_STATUS_IS_OK(nt_status
))
3166 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3168 union srvsvc_NetShareInfo info
;
3169 struct srvsvc_NetShareInfo502 info502
=
3170 ctr_src
.ctr
.ctr502
->array
[i
];
3172 /* reset error-code */
3173 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3175 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3178 /* finally add the share on the dst server */
3180 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3181 info502
.name
, info502
.path
, info502
.comment
);
3183 info
.info502
= &info502
;
3185 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3186 srvsvc_pipe
->desthost
,
3192 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ALREADY_EXISTS
)) {
3193 printf(" [%s] does already exist\n",
3198 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3199 printf("cannot add share: %s\n", dos_errstr(result
));
3205 nt_status
= NT_STATUS_OK
;
3209 cli_shutdown(cli_dst
);
3217 * Migrate shares from a RPC server to another.
3219 * @param argc Standard main() style argc.
3220 * @param argv Standard main() style argv. Initial components are already
3223 * @return A shell status integer (0 for success).
3225 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3228 if (c
->display_usage
) {
3230 "net rpc share migrate shares\n"
3231 " Migrate shares to local server\n");
3236 printf("no server to migrate\n");
3240 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3241 rpc_share_migrate_shares_internals
,
3248 * @param f file_info
3249 * @param mask current search mask
3250 * @param state arg-pointer
3253 static void copy_fn(const char *mnt
, file_info
*f
,
3254 const char *mask
, void *state
)
3256 static NTSTATUS nt_status
;
3257 static struct copy_clistate
*local_state
;
3258 static fstring filename
, new_mask
;
3261 struct net_context
*c
;
3263 local_state
= (struct copy_clistate
*)state
;
3264 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3268 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3271 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3274 if (f
->mode
& aDIR
) {
3276 DEBUG(3,("got dir: %s\n", f
->name
));
3278 fstrcpy(dir
, local_state
->cwd
);
3280 fstrcat(dir
, f
->name
);
3282 switch (net_mode_share
)
3284 case NET_MODE_SHARE_MIGRATE
:
3285 /* create that directory */
3286 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3287 local_state
->cli_share_src
,
3288 local_state
->cli_share_dst
,
3290 c
->opt_acls
? true : false,
3291 c
->opt_attrs
? true : false,
3292 c
->opt_timestamps
? true:false,
3296 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3300 if (!NT_STATUS_IS_OK(nt_status
))
3301 printf("could not handle dir %s: %s\n",
3302 dir
, nt_errstr(nt_status
));
3304 /* search below that directory */
3305 fstrcpy(new_mask
, dir
);
3306 fstrcat(new_mask
, "\\*");
3308 old_dir
= local_state
->cwd
;
3309 local_state
->cwd
= dir
;
3310 if (!sync_files(local_state
, new_mask
))
3311 printf("could not handle files\n");
3312 local_state
->cwd
= old_dir
;
3319 fstrcpy(filename
, local_state
->cwd
);
3320 fstrcat(filename
, "\\");
3321 fstrcat(filename
, f
->name
);
3323 DEBUG(3,("got file: %s\n", filename
));
3325 switch (net_mode_share
)
3327 case NET_MODE_SHARE_MIGRATE
:
3328 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3329 local_state
->cli_share_src
,
3330 local_state
->cli_share_dst
,
3332 c
->opt_acls
? true : false,
3333 c
->opt_attrs
? true : false,
3334 c
->opt_timestamps
? true: false,
3338 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3342 if (!NT_STATUS_IS_OK(nt_status
))
3343 printf("could not handle file %s: %s\n",
3344 filename
, nt_errstr(nt_status
));
3349 * sync files, can be called recursivly to list files
3350 * and then call copy_fn for each file
3352 * @param cp_clistate pointer to the copy_clistate we work with
3353 * @param mask the current search mask
3355 * @return Boolean result
3357 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3359 struct cli_state
*targetcli
;
3360 char *targetpath
= NULL
;
3362 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3364 if ( !cli_resolve_path(talloc_tos(), "", cp_clistate
->cli_share_src
,
3365 mask
, &targetcli
, &targetpath
) ) {
3366 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3367 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3371 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3372 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3373 mask
, cli_errstr(targetcli
));
3382 * Set the top level directory permissions before we do any further copies.
3383 * Should set up ACL inheritance.
3386 bool copy_top_level_perms(struct net_context
*c
,
3387 struct copy_clistate
*cp_clistate
,
3388 const char *sharename
)
3390 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3392 switch (net_mode_share
) {
3393 case NET_MODE_SHARE_MIGRATE
:
3394 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3395 nt_status
= net_copy_fileattr(c
,
3396 cp_clistate
->mem_ctx
,
3397 cp_clistate
->cli_share_src
,
3398 cp_clistate
->cli_share_dst
,
3400 c
->opt_acls
? true : false,
3401 c
->opt_attrs
? true : false,
3402 c
->opt_timestamps
? true: false,
3406 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3410 if (!NT_STATUS_IS_OK(nt_status
)) {
3411 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3412 sharename
, nt_errstr(nt_status
));
3420 * Sync all files inside a remote share to another share (over smb).
3422 * All parameters are provided by the run_rpc_command function, except for
3423 * argc, argv which are passed through.
3425 * @param domain_sid The domain sid acquired from the remote server.
3426 * @param cli A cli_state connected to the server.
3427 * @param mem_ctx Talloc context, destroyed on completion of the function.
3428 * @param argc Standard main() style argc.
3429 * @param argv Standard main() style argv. Initial components are already
3432 * @return Normal NTSTATUS return.
3435 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3436 const DOM_SID
*domain_sid
,
3437 const char *domain_name
,
3438 struct cli_state
*cli
,
3439 struct rpc_pipe_client
*pipe_hnd
,
3440 TALLOC_CTX
*mem_ctx
,
3445 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3446 struct srvsvc_NetShareInfoCtr ctr_src
;
3449 struct copy_clistate cp_clistate
;
3450 bool got_src_share
= false;
3451 bool got_dst_share
= false;
3452 const char *mask
= "\\*";
3455 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3457 nt_status
= NT_STATUS_NO_MEMORY
;
3461 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3464 if (!W_ERROR_IS_OK(result
))
3467 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3469 struct srvsvc_NetShareInfo502 info502
=
3470 ctr_src
.ctr
.ctr502
->array
[i
];
3472 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3475 /* one might not want to mirror whole discs :) */
3476 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3477 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3481 switch (net_mode_share
)
3483 case NET_MODE_SHARE_MIGRATE
:
3487 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3490 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3492 c
->opt_acls
? "including" : "without",
3493 c
->opt_attrs
? "including" : "without",
3494 c
->opt_timestamps
? "(preserving timestamps)" : "");
3496 cp_clistate
.mem_ctx
= mem_ctx
;
3497 cp_clistate
.cli_share_src
= NULL
;
3498 cp_clistate
.cli_share_dst
= NULL
;
3499 cp_clistate
.cwd
= NULL
;
3500 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3503 /* open share source */
3504 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3505 &cli
->dest_ss
, cli
->desthost
,
3506 info502
.name
, "A:");
3507 if (!NT_STATUS_IS_OK(nt_status
))
3510 got_src_share
= true;
3512 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3513 /* open share destination */
3514 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3515 NULL
, dst
, info502
.name
, "A:");
3516 if (!NT_STATUS_IS_OK(nt_status
))
3519 got_dst_share
= true;
3522 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3523 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3524 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3528 if (!sync_files(&cp_clistate
, mask
)) {
3529 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3530 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3535 nt_status
= NT_STATUS_OK
;
3540 cli_shutdown(cp_clistate
.cli_share_src
);
3543 cli_shutdown(cp_clistate
.cli_share_dst
);
3550 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3552 if (c
->display_usage
) {
3554 "net share migrate files\n"
3555 " Migrate files to local server\n");
3560 d_printf("no server to migrate\n");
3564 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3565 rpc_share_migrate_files_internals
,
3570 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3572 * All parameters are provided by the run_rpc_command function, except for
3573 * argc, argv which are passed through.
3575 * @param domain_sid The domain sid acquired from the remote server.
3576 * @param cli A cli_state connected to the server.
3577 * @param mem_ctx Talloc context, destroyed on completion of the function.
3578 * @param argc Standard main() style argc.
3579 * @param argv Standard main() style argv. Initial components are already
3582 * @return Normal NTSTATUS return.
3585 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3586 const DOM_SID
*domain_sid
,
3587 const char *domain_name
,
3588 struct cli_state
*cli
,
3589 struct rpc_pipe_client
*pipe_hnd
,
3590 TALLOC_CTX
*mem_ctx
,
3595 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3596 struct srvsvc_NetShareInfoCtr ctr_src
;
3597 union srvsvc_NetShareInfo info
;
3599 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3600 struct cli_state
*cli_dst
= NULL
;
3601 uint32 level
= 502; /* includes secdesc */
3602 uint32_t parm_error
= 0;
3604 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3607 if (!W_ERROR_IS_OK(result
))
3610 /* connect destination PI_SRVSVC */
3611 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3612 &ndr_table_srvsvc
.syntax_id
);
3613 if (!NT_STATUS_IS_OK(nt_status
))
3617 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3619 struct srvsvc_NetShareInfo502 info502
=
3620 ctr_src
.ctr
.ctr502
->array
[i
];
3622 /* reset error-code */
3623 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3625 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3628 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3629 info502
.name
, info502
.path
, info502
.comment
);
3632 display_sec_desc(info502
.sd_buf
.sd
);
3634 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3635 info
.info502
= &info502
;
3637 /* finally modify the share on the dst server */
3638 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3639 srvsvc_pipe
->desthost
,
3645 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3646 printf("cannot set share-acl: %s\n", dos_errstr(result
));
3652 nt_status
= NT_STATUS_OK
;
3656 cli_shutdown(cli_dst
);
3664 * Migrate share-acls from a RPC server to another.
3666 * @param argc Standard main() style argc.
3667 * @param argv Standard main() style argv. Initial components are already
3670 * @return A shell status integer (0 for success).
3672 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3675 if (c
->display_usage
) {
3677 "net rpc share migrate security\n"
3678 " Migrate share-acls to local server\n");
3683 d_printf("no server to migrate\n");
3687 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3688 rpc_share_migrate_security_internals
,
3693 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3694 * from one server to another.
3696 * @param argc Standard main() style argc.
3697 * @param argv Standard main() style argv. Initial components are already
3700 * @return A shell status integer (0 for success).
3703 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3708 if (c
->display_usage
) {
3710 "net rpc share migrate all\n"
3711 " Migrates shares including all share settings\n");
3716 d_printf("no server to migrate\n");
3720 /* order is important. we don't want to be locked out by the share-acl
3721 * before copying files - gd */
3723 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3724 rpc_share_migrate_shares_internals
, argc
, argv
);
3728 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3729 rpc_share_migrate_files_internals
, argc
, argv
);
3733 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3734 rpc_share_migrate_security_internals
, argc
,
3740 * 'net rpc share migrate' entrypoint.
3741 * @param argc Standard main() style argc.
3742 * @param argv Standard main() style argv. Initial components are already
3745 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3748 struct functable func
[] = {
3751 rpc_share_migrate_all
,
3753 "Migrate shares from remote to local server",
3754 "net rpc share migrate all\n"
3755 " Migrate shares from remote to local server"
3759 rpc_share_migrate_files
,
3761 "Migrate files from remote to local server",
3762 "net rpc share migrate files\n"
3763 " Migrate files from remote to local server"
3767 rpc_share_migrate_security
,
3769 "Migrate share-ACLs from remote to local server",
3770 "net rpc share migrate security\n"
3771 " Migrate share-ACLs from remote to local server"
3775 rpc_share_migrate_shares
,
3777 "Migrate shares from remote to local server",
3778 "net rpc share migrate shares\n"
3779 " Migrate shares from remote to local server"
3781 {NULL
, NULL
, 0, NULL
, NULL
}
3784 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3786 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3795 static int num_server_aliases
;
3796 static struct full_alias
*server_aliases
;
3799 * Add an alias to the static list.
3801 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3803 if (server_aliases
== NULL
)
3804 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3806 server_aliases
[num_server_aliases
] = *alias
;
3807 num_server_aliases
+= 1;
3811 * For a specific domain on the server, fetch all the aliases
3812 * and their members. Add all of them to the server_aliases.
3815 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3816 TALLOC_CTX
*mem_ctx
,
3817 POLICY_HND
*connect_pol
,
3818 const DOM_SID
*domain_sid
)
3820 uint32 start_idx
, max_entries
, num_entries
, i
;
3821 struct samr_SamArray
*groups
= NULL
;
3823 POLICY_HND domain_pol
;
3825 /* Get domain policy handle */
3827 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3829 MAXIMUM_ALLOWED_ACCESS
,
3830 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3832 if (!NT_STATUS_IS_OK(result
))
3839 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3845 for (i
= 0; i
< num_entries
; i
++) {
3847 POLICY_HND alias_pol
;
3848 struct full_alias alias
;
3849 struct lsa_SidArray sid_array
;
3852 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3854 MAXIMUM_ALLOWED_ACCESS
,
3855 groups
->entries
[i
].idx
,
3857 if (!NT_STATUS_IS_OK(result
))
3860 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3863 if (!NT_STATUS_IS_OK(result
))
3866 alias
.num_members
= sid_array
.num_sids
;
3868 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3869 if (!NT_STATUS_IS_OK(result
))
3872 alias
.members
= NULL
;
3874 if (alias
.num_members
> 0) {
3875 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3877 for (j
= 0; j
< alias
.num_members
; j
++)
3878 sid_copy(&alias
.members
[j
],
3879 sid_array
.sids
[j
].sid
);
3882 sid_copy(&alias
.sid
, domain_sid
);
3883 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3885 push_alias(mem_ctx
, &alias
);
3887 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3889 result
= NT_STATUS_OK
;
3892 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3898 * Dump server_aliases as names for debugging purposes.
3901 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3902 const DOM_SID
*domain_sid
,
3903 const char *domain_name
,
3904 struct cli_state
*cli
,
3905 struct rpc_pipe_client
*pipe_hnd
,
3906 TALLOC_CTX
*mem_ctx
,
3914 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3915 SEC_RIGHTS_MAXIMUM_ALLOWED
,
3917 if (!NT_STATUS_IS_OK(result
))
3920 for (i
=0; i
<num_server_aliases
; i
++) {
3923 enum lsa_SidType
*types
;
3926 struct full_alias
*alias
= &server_aliases
[i
];
3928 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3930 &domains
, &names
, &types
);
3931 if (!NT_STATUS_IS_OK(result
))
3934 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3936 if (alias
->num_members
== 0) {
3941 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3944 &domains
, &names
, &types
);
3946 if (!NT_STATUS_IS_OK(result
) &&
3947 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3950 for (j
=0; j
<alias
->num_members
; j
++)
3951 DEBUG(1, ("%s\\%s (%d); ",
3952 domains
[j
] ? domains
[j
] : "*unknown*",
3953 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3957 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3959 return NT_STATUS_OK
;
3963 * Fetch a list of all server aliases and their members into
3967 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3968 const DOM_SID
*domain_sid
,
3969 const char *domain_name
,
3970 struct cli_state
*cli
,
3971 struct rpc_pipe_client
*pipe_hnd
,
3972 TALLOC_CTX
*mem_ctx
,
3977 POLICY_HND connect_pol
;
3979 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3981 MAXIMUM_ALLOWED_ACCESS
,
3984 if (!NT_STATUS_IS_OK(result
))
3987 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3988 &global_sid_Builtin
);
3990 if (!NT_STATUS_IS_OK(result
))
3993 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3996 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
4001 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
4003 token
->num_sids
= 4;
4005 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
4006 d_fprintf(stderr
, "malloc failed\n");
4007 token
->num_sids
= 0;
4011 token
->user_sids
[0] = *user_sid
;
4012 sid_copy(&token
->user_sids
[1], &global_sid_World
);
4013 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
4014 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
4017 static void free_user_token(NT_USER_TOKEN
*token
)
4019 SAFE_FREE(token
->user_sids
);
4022 static bool is_sid_in_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4026 for (i
=0; i
<token
->num_sids
; i
++) {
4027 if (sid_compare(sid
, &token
->user_sids
[i
]) == 0)
4033 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
4035 if (is_sid_in_token(token
, sid
))
4038 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
4039 if (!token
->user_sids
) {
4043 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
4045 token
->num_sids
+= 1;
4050 NT_USER_TOKEN token
;
4053 static void dump_user_token(struct user_token
*token
)
4057 d_printf("%s\n", token
->name
);
4059 for (i
=0; i
<token
->token
.num_sids
; i
++) {
4060 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4064 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4068 for (i
=0; i
<alias
->num_members
; i
++) {
4069 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4076 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4080 for (i
=0; i
<num_server_aliases
; i
++) {
4081 if (is_alias_member(&sid
, &server_aliases
[i
]))
4082 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4087 * We got a user token with all the SIDs we can know about without asking the
4088 * server directly. These are the user and domain group sids. All of these can
4089 * be members of aliases. So scan the list of aliases for each of the SIDs and
4090 * add them to the token.
4093 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4095 int num_global_sids
= token
->num_sids
;
4098 for (i
=0; i
<num_global_sids
; i
++) {
4099 collect_sid_memberships(token
, token
->user_sids
[i
]);
4103 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4105 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4106 enum wbcSidType type
;
4108 struct wbcDomainSid wsid
;
4109 char *sid_str
= NULL
;
4111 uint32_t num_groups
;
4112 gid_t
*groups
= NULL
;
4115 fstr_sprintf(full_name
, "%s%c%s",
4116 domain
, *lp_winbind_separator(), user
);
4118 /* First let's find out the user sid */
4120 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4122 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4123 DEBUG(1, ("winbind could not find %s: %s\n",
4124 full_name
, wbcErrorString(wbc_status
)));
4128 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4129 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4133 if (type
!= SID_NAME_USER
) {
4134 wbcFreeMemory(sid_str
);
4135 DEBUG(1, ("%s is not a user\n", full_name
));
4139 string_to_sid(&user_sid
, sid_str
);
4140 wbcFreeMemory(sid_str
);
4143 init_user_token(token
, &user_sid
);
4145 /* And now the groups winbind knows about */
4147 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4148 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4149 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4150 full_name
, wbcErrorString(wbc_status
)));
4154 for (i
= 0; i
< num_groups
; i
++) {
4155 gid_t gid
= groups
[i
];
4158 wbc_status
= wbcGidToSid(gid
, &wsid
);
4159 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4160 DEBUG(1, ("winbind could not find SID of gid %d: %s\n",
4161 gid
, wbcErrorString(wbc_status
)));
4162 wbcFreeMemory(groups
);
4166 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4167 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4168 wbcFreeMemory(groups
);
4172 DEBUG(3, (" %s\n", sid_str
));
4174 string_to_sid(&sid
, sid_str
);
4175 wbcFreeMemory(sid_str
);
4178 add_sid_to_token(token
, &sid
);
4180 wbcFreeMemory(groups
);
4186 * Get a list of all user tokens we want to look at
4189 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4190 struct user_token
**user_tokens
)
4192 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4193 uint32_t i
, num_users
;
4195 struct user_token
*result
;
4196 TALLOC_CTX
*frame
= NULL
;
4198 if (lp_winbind_use_default_domain() &&
4199 (c
->opt_target_workgroup
== NULL
)) {
4200 d_fprintf(stderr
, "winbind use default domain = yes set, "
4201 "please specify a workgroup\n");
4205 /* Send request to winbind daemon */
4207 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4208 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4209 DEBUG(1, ("winbind could not list users: %s\n",
4210 wbcErrorString(wbc_status
)));
4214 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4216 if (result
== NULL
) {
4217 DEBUG(1, ("Could not malloc sid array\n"));
4218 wbcFreeMemory(users
);
4222 frame
= talloc_stackframe();
4223 for (i
=0; i
< num_users
; i
++) {
4224 fstring domain
, user
;
4227 fstrcpy(result
[i
].name
, users
[i
]);
4229 p
= strchr(users
[i
], *lp_winbind_separator());
4231 DEBUG(3, ("%s\n", users
[i
]));
4234 fstrcpy(domain
, c
->opt_target_workgroup
);
4235 fstrcpy(user
, users
[i
]);
4238 fstrcpy(domain
, users
[i
]);
4243 get_user_sids(domain
, user
, &(result
[i
].token
));
4247 wbcFreeMemory(users
);
4249 *num_tokens
= num_users
;
4250 *user_tokens
= result
;
4255 static bool get_user_tokens_from_file(FILE *f
,
4257 struct user_token
**tokens
)
4259 struct user_token
*token
= NULL
;
4264 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4268 if (line
[strlen(line
)-1] == '\n')
4269 line
[strlen(line
)-1] = '\0';
4271 if (line
[0] == ' ') {
4275 string_to_sid(&sid
, &line
[1]);
4277 if (token
== NULL
) {
4278 DEBUG(0, ("File does not begin with username"));
4282 add_sid_to_token(&token
->token
, &sid
);
4286 /* And a new user... */
4289 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4290 if (*tokens
== NULL
) {
4291 DEBUG(0, ("Could not realloc tokens\n"));
4295 token
= &((*tokens
)[*num_tokens
-1]);
4297 fstrcpy(token
->name
, line
);
4298 token
->token
.num_sids
= 0;
4299 token
->token
.user_sids
= NULL
;
4308 * Show the list of all users that have access to a share
4311 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4312 TALLOC_CTX
*mem_ctx
,
4313 const char *netname
,
4315 struct user_token
*tokens
)
4318 SEC_DESC
*share_sd
= NULL
;
4319 SEC_DESC
*root_sd
= NULL
;
4320 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4322 union srvsvc_NetShareInfo info
;
4327 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4334 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4335 DEBUG(1, ("Coult not query secdesc for share %s\n",
4340 share_sd
= info
.info502
->sd_buf
.sd
;
4341 if (share_sd
== NULL
) {
4342 DEBUG(1, ("Got no secdesc for share %s\n",
4348 if (!cli_send_tconX(cli
, netname
, "A:", "", 0)) {
4352 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4355 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4358 for (i
=0; i
<num_tokens
; i
++) {
4361 if (share_sd
!= NULL
) {
4362 if (!se_access_check(share_sd
, &tokens
[i
].token
,
4363 1, &acc_granted
, &status
)) {
4364 DEBUG(1, ("Could not check share_sd for "
4370 if (!NT_STATUS_IS_OK(status
))
4374 if (root_sd
== NULL
) {
4375 d_printf(" %s\n", tokens
[i
].name
);
4379 if (!se_access_check(root_sd
, &tokens
[i
].token
,
4380 1, &acc_granted
, &status
)) {
4381 DEBUG(1, ("Could not check root_sd for user %s\n",
4386 if (!NT_STATUS_IS_OK(status
))
4389 d_printf(" %s\n", tokens
[i
].name
);
4393 cli_close(cli
, fnum
);
4405 static void collect_share(const char *name
, uint32 m
,
4406 const char *comment
, void *state
)
4408 struct share_list
*share_list
= (struct share_list
*)state
;
4410 if (m
!= STYPE_DISKTREE
)
4413 share_list
->num_shares
+= 1;
4414 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4415 if (!share_list
->shares
) {
4416 share_list
->num_shares
= 0;
4419 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4423 * List shares on a remote RPC server, including the security descriptors.
4425 * All parameters are provided by the run_rpc_command function, except for
4426 * argc, argv which are passed through.
4428 * @param domain_sid The domain sid acquired from the remote server.
4429 * @param cli A cli_state connected to the server.
4430 * @param mem_ctx Talloc context, destroyed on completion of the function.
4431 * @param argc Standard main() style argc.
4432 * @param argv Standard main() style argv. Initial components are already
4435 * @return Normal NTSTATUS return.
4438 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4439 const DOM_SID
*domain_sid
,
4440 const char *domain_name
,
4441 struct cli_state
*cli
,
4442 struct rpc_pipe_client
*pipe_hnd
,
4443 TALLOC_CTX
*mem_ctx
,
4453 struct user_token
*tokens
= NULL
;
4456 struct share_list share_list
;
4461 f
= fopen(argv
[0], "r");
4465 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4466 return NT_STATUS_UNSUCCESSFUL
;
4469 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4475 DEBUG(0, ("Could not read users from file\n"));
4476 return NT_STATUS_UNSUCCESSFUL
;
4479 for (i
=0; i
<num_tokens
; i
++)
4480 collect_alias_memberships(&tokens
[i
].token
);
4482 init_enum_hnd(&hnd
, 0);
4484 share_list
.num_shares
= 0;
4485 share_list
.shares
= NULL
;
4487 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4490 DEBUG(0, ("Error returning browse list: %s\n",
4495 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4496 char *netname
= share_list
.shares
[i
];
4498 if (netname
[strlen(netname
)-1] == '$')
4501 d_printf("%s\n", netname
);
4503 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4504 num_tokens
, tokens
);
4507 for (i
=0; i
<num_tokens
; i
++) {
4508 free_user_token(&tokens
[i
].token
);
4511 SAFE_FREE(share_list
.shares
);
4513 return NT_STATUS_OK
;
4516 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4521 if (c
->display_usage
) {
4523 "net rpc share allowedusers\n"
4524 " List allowed users\n");
4528 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4529 rpc_aliaslist_internals
,
4534 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4540 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4541 rpc_share_allowedusers_internals
,
4545 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4548 struct user_token
*tokens
= NULL
;
4552 net_usersidlist_usage(c
, argc
, argv
);
4556 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4557 DEBUG(0, ("Could not get the user/sid list\n"));
4561 for (i
=0; i
<num_tokens
; i
++) {
4562 dump_user_token(&tokens
[i
]);
4563 free_user_token(&tokens
[i
].token
);
4570 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4572 d_printf("net usersidlist\n"
4573 "\tprints out a list of all users the running winbind knows\n"
4574 "\tabout, together with all their SIDs. This is used as\n"
4575 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4577 net_common_flags_usage(c
, argc
, argv
);
4582 * 'net rpc share' entrypoint.
4583 * @param argc Standard main() style argc.
4584 * @param argv Standard main() style argv. Initial components are already
4588 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4590 NET_API_STATUS status
;
4592 struct functable func
[] = {
4598 "net rpc share add\n"
4606 "net rpc share delete\n"
4611 rpc_share_allowedusers
,
4613 "Modify allowed users",
4614 "net rpc share allowedusers\n"
4615 " Modify allowed users"
4621 "Migrate share to local server",
4622 "net rpc share migrate\n"
4623 " Migrate share to local server"
4630 "net rpc share list\n"
4633 {NULL
, NULL
, 0, NULL
, NULL
}
4636 status
= libnetapi_init(&c
->netapi_ctx
);
4640 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4641 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4642 if (c
->opt_kerberos
) {
4643 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4647 if (c
->display_usage
) {
4651 " Alias for net rpc share list\n");
4652 net_display_usage_from_functable(func
);
4656 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4657 rpc_share_list_internals
,
4661 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4664 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4665 TALLOC_CTX
*mem_ctx
,
4666 struct rpc_sh_ctx
*ctx
,
4667 struct rpc_pipe_client
*pipe_hnd
,
4668 int argc
, const char **argv
)
4670 return rpc_share_list_internals(c
, ctx
->domain_sid
, ctx
->domain_name
,
4671 ctx
->cli
, pipe_hnd
, mem_ctx
,
4675 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4676 TALLOC_CTX
*mem_ctx
,
4677 struct rpc_sh_ctx
*ctx
,
4678 struct rpc_pipe_client
*pipe_hnd
,
4679 int argc
, const char **argv
)
4681 NET_API_STATUS status
;
4682 uint32_t parm_err
= 0;
4683 struct SHARE_INFO_2 i2
;
4685 if ((argc
< 2) || (argc
> 3)) {
4686 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4688 return NT_STATUS_INVALID_PARAMETER
;
4691 i2
.shi2_netname
= argv
[0];
4692 i2
.shi2_type
= STYPE_DISKTREE
;
4693 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4694 i2
.shi2_permissions
= 0;
4695 i2
.shi2_max_uses
= 0;
4696 i2
.shi2_current_uses
= 0;
4697 i2
.shi2_path
= argv
[1];
4698 i2
.shi2_passwd
= NULL
;
4700 status
= NetShareAdd(pipe_hnd
->desthost
,
4705 return werror_to_ntstatus(W_ERROR(status
));
4708 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4709 TALLOC_CTX
*mem_ctx
,
4710 struct rpc_sh_ctx
*ctx
,
4711 struct rpc_pipe_client
*pipe_hnd
,
4712 int argc
, const char **argv
)
4718 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4719 return NT_STATUS_INVALID_PARAMETER
;
4722 status
= rpccli_srvsvc_NetShareDel(pipe_hnd
, mem_ctx
,
4731 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4732 TALLOC_CTX
*mem_ctx
,
4733 struct rpc_sh_ctx
*ctx
,
4734 struct rpc_pipe_client
*pipe_hnd
,
4735 int argc
, const char **argv
)
4737 union srvsvc_NetShareInfo info
;
4742 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4743 return NT_STATUS_INVALID_PARAMETER
;
4746 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4752 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4756 d_printf("Name: %s\n", info
.info2
->name
);
4757 d_printf("Comment: %s\n", info
.info2
->comment
);
4758 d_printf("Path: %s\n", info
.info2
->path
);
4759 d_printf("Password: %s\n", info
.info2
->password
);
4762 return werror_to_ntstatus(result
);
4765 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4766 struct rpc_sh_ctx
*ctx
)
4768 static struct rpc_sh_cmd cmds
[] = {
4770 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4771 "List available shares" },
4773 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4776 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4779 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4780 "Get information about a share" },
4782 { NULL
, NULL
, 0, NULL
, NULL
}
4788 /****************************************************************************/
4790 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4792 return net_file_usage(c
, argc
, argv
);
4796 * Close a file on a remote RPC server.
4798 * All parameters are provided by the run_rpc_command function, except for
4799 * argc, argv which are passed through.
4801 * @param c A net_context structure.
4802 * @param domain_sid The domain sid acquired from the remote server.
4803 * @param cli A cli_state connected to the server.
4804 * @param mem_ctx Talloc context, destroyed on completion of the function.
4805 * @param argc Standard main() style argc.
4806 * @param argv Standard main() style argv. Initial components are already
4809 * @return Normal NTSTATUS return.
4811 static NTSTATUS
rpc_file_close_internals(struct net_context
*c
,
4812 const DOM_SID
*domain_sid
,
4813 const char *domain_name
,
4814 struct cli_state
*cli
,
4815 struct rpc_pipe_client
*pipe_hnd
,
4816 TALLOC_CTX
*mem_ctx
,
4820 return rpccli_srvsvc_NetFileClose(pipe_hnd
, mem_ctx
,
4822 atoi(argv
[0]), NULL
);
4826 * Close a file on a remote RPC server.
4828 * @param argc Standard main() style argc.
4829 * @param argv Standard main() style argv. Initial components are already
4832 * @return A shell status integer (0 for success).
4834 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4836 if (argc
< 1 || c
->display_usage
) {
4837 return rpc_file_usage(c
, argc
, argv
);
4840 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4841 rpc_file_close_internals
,
4846 * Formatted print of open file info
4848 * @param r struct srvsvc_NetFileInfo3 contents
4851 static void display_file_info_3(struct srvsvc_NetFileInfo3
*r
)
4853 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4854 r
->fid
, r
->user
, r
->permissions
, r
->num_locks
, r
->path
);
4858 * List open files on a remote RPC server.
4860 * All parameters are provided by the run_rpc_command function, except for
4861 * argc, argv which are passed through.
4863 * @param c A net_context structure.
4864 * @param domain_sid The domain sid acquired from the remote server.
4865 * @param cli A cli_state connected to the server.
4866 * @param mem_ctx Talloc context, destroyed on completion of the function.
4867 * @param argc Standard main() style argc.
4868 * @param argv Standard main() style argv. Initial components are already
4871 * @return Normal NTSTATUS return.
4874 static NTSTATUS
rpc_file_list_internals(struct net_context
*c
,
4875 const DOM_SID
*domain_sid
,
4876 const char *domain_name
,
4877 struct cli_state
*cli
,
4878 struct rpc_pipe_client
*pipe_hnd
,
4879 TALLOC_CTX
*mem_ctx
,
4883 struct srvsvc_NetFileInfoCtr info_ctr
;
4884 struct srvsvc_NetFileCtr3 ctr3
;
4887 uint32 preferred_len
= 0xffffffff, i
;
4888 const char *username
=NULL
;
4889 uint32_t total_entries
= 0;
4890 uint32_t resume_handle
= 0;
4892 /* if argc > 0, must be user command */
4894 username
= smb_xstrdup(argv
[0]);
4896 ZERO_STRUCT(info_ctr
);
4900 info_ctr
.ctr
.ctr3
= &ctr3
;
4902 status
= rpccli_srvsvc_NetFileEnum(pipe_hnd
, mem_ctx
,
4912 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
4915 /* Display results */
4918 "\nEnumerating open files on remote server:\n\n"
4919 "\nFileId Opened by Perms Locks Path"
4920 "\n------ --------- ----- ----- ---- \n");
4921 for (i
= 0; i
< total_entries
; i
++)
4922 display_file_info_3(&info_ctr
.ctr
.ctr3
->array
[i
]);
4924 return W_ERROR_IS_OK(result
) ? NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
4928 * List files for a user on a remote RPC server.
4930 * @param argc Standard main() style argc.
4931 * @param argv Standard main() style argv. Initial components are already
4934 * @return A shell status integer (0 for success)..
4937 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4939 if (argc
< 1 || c
->display_usage
) {
4940 return rpc_file_usage(c
, argc
, argv
);
4943 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4944 rpc_file_list_internals
,
4949 * 'net rpc file' entrypoint.
4950 * @param argc Standard main() style argc.
4951 * @param argv Standard main() style argv. Initial components are already
4955 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4957 struct functable func
[] = {
4962 "Close opened file",
4963 "net rpc file close\n"
4964 " Close opened file"
4970 "List files opened by user",
4971 "net rpc file user\n"
4972 " List files opened by user"
4979 "Display information about opened file",
4980 "net rpc file info\n"
4981 " Display information about opened file"
4984 {NULL
, NULL
, 0, NULL
, NULL
}
4988 if (c
->display_usage
) {
4989 d_printf("Usage:\n");
4990 d_printf("net rpc file\n"
4991 " List opened files\n");
4992 net_display_usage_from_functable(func
);
4996 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4997 rpc_file_list_internals
,
5001 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
5005 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
5007 * All parameters are provided by the run_rpc_command function, except for
5008 * argc, argv which are passed through.
5010 * @param c A net_context structure.
5011 * @param domain_sid The domain sid acquired from the remote server.
5012 * @param cli A cli_state connected to the server.
5013 * @param mem_ctx Talloc context, destroyed on completion of the function.
5014 * @param argc Standard main() style argc.
5015 * @param argv Standard main() style argv. Initial components are already
5018 * @return Normal NTSTATUS return.
5021 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
5022 const DOM_SID
*domain_sid
,
5023 const char *domain_name
,
5024 struct cli_state
*cli
,
5025 struct rpc_pipe_client
*pipe_hnd
,
5026 TALLOC_CTX
*mem_ctx
,
5030 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5032 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5034 if (NT_STATUS_IS_OK(result
)) {
5035 d_printf("\nShutdown successfully aborted\n");
5036 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
5038 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
5044 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
5046 * All parameters are provided by the run_rpc_command function, except for
5047 * argc, argv which are passed through.
5049 * @param c A net_context structure.
5050 * @param domain_sid The domain sid acquired from the remote server.
5051 * @param cli A cli_state connected to the server.
5052 * @param mem_ctx Talloc context, destroyed on completion of the function.
5053 * @param argc Standard main() style argc.
5054 * @param argv Standard main() style argv. Initial components are already
5057 * @return Normal NTSTATUS return.
5060 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
5061 const DOM_SID
*domain_sid
,
5062 const char *domain_name
,
5063 struct cli_state
*cli
,
5064 struct rpc_pipe_client
*pipe_hnd
,
5065 TALLOC_CTX
*mem_ctx
,
5069 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5071 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
5073 if (NT_STATUS_IS_OK(result
)) {
5074 d_printf("\nShutdown successfully aborted\n");
5075 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
5077 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
5083 * ABORT the shutdown of a remote RPC server.
5085 * @param argc Standard main() style argc.
5086 * @param argv Standard main() style argv. Initial components are already
5089 * @return A shell status integer (0 for success).
5092 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
5097 if (c
->display_usage
) {
5099 "net rpc abortshutdown\n"
5100 " Abort a scheduled shutdown\n");
5104 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5105 rpc_shutdown_abort_internals
, argc
, argv
);
5110 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
5112 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5113 rpc_reg_shutdown_abort_internals
,
5118 * Shut down a remote RPC Server via initshutdown pipe.
5120 * All parameters are provided by the run_rpc_command function, except for
5121 * argc, argv which are passed through.
5123 * @param c A net_context structure.
5124 * @param domain_sid The domain sid acquired from the remote server.
5125 * @param cli A cli_state connected to the server.
5126 * @param mem_ctx Talloc context, destroyed on completion of the function.
5127 * @param argc Standard main() style argc.
5128 * @param argv Standard main() style argv. Initial components are already
5131 * @return Normal NTSTATUS return.
5134 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5135 const DOM_SID
*domain_sid
,
5136 const char *domain_name
,
5137 struct cli_state
*cli
,
5138 struct rpc_pipe_client
*pipe_hnd
,
5139 TALLOC_CTX
*mem_ctx
,
5143 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5144 const char *msg
= "This machine will be shutdown shortly";
5145 uint32 timeout
= 20;
5146 struct initshutdown_String msg_string
;
5147 struct initshutdown_String_sub s
;
5149 if (c
->opt_comment
) {
5150 msg
= c
->opt_comment
;
5152 if (c
->opt_timeout
) {
5153 timeout
= c
->opt_timeout
;
5157 msg_string
.name
= &s
;
5159 /* create an entry */
5160 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5161 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5164 if (NT_STATUS_IS_OK(result
)) {
5165 d_printf("\nShutdown of remote machine succeeded\n");
5166 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5168 DEBUG(1,("Shutdown of remote machine failed!\n"));
5174 * Shut down a remote RPC Server via winreg pipe.
5176 * All parameters are provided by the run_rpc_command function, except for
5177 * argc, argv which are passed through.
5179 * @param c A net_context structure.
5180 * @param domain_sid The domain sid acquired from the remote server.
5181 * @param cli A cli_state connected to the server.
5182 * @param mem_ctx Talloc context, destroyed on completion of the function.
5183 * @param argc Standard main() style argc.
5184 * @param argv Standard main() style argv. Initial components are already
5187 * @return Normal NTSTATUS return.
5190 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5191 const DOM_SID
*domain_sid
,
5192 const char *domain_name
,
5193 struct cli_state
*cli
,
5194 struct rpc_pipe_client
*pipe_hnd
,
5195 TALLOC_CTX
*mem_ctx
,
5199 const char *msg
= "This machine will be shutdown shortly";
5200 uint32 timeout
= 20;
5201 struct initshutdown_String msg_string
;
5202 struct initshutdown_String_sub s
;
5206 if (c
->opt_comment
) {
5207 msg
= c
->opt_comment
;
5210 msg_string
.name
= &s
;
5212 if (c
->opt_timeout
) {
5213 timeout
= c
->opt_timeout
;
5216 /* create an entry */
5217 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5218 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5221 if (NT_STATUS_IS_OK(result
)) {
5222 d_printf("\nShutdown of remote machine succeeded\n");
5224 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5225 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5226 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5228 d_fprintf(stderr
, "\nresult was: %s\n", dos_errstr(werr
));
5235 * Shut down a remote RPC server.
5237 * @param argc Standard main() style argc.
5238 * @param argv Standard main() style argv. Initial components are already
5241 * @return A shell status integer (0 for success).
5244 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5248 if (c
->display_usage
) {
5250 "net rpc shutdown\n"
5251 " Shut down a remote RPC server\n");
5255 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5256 rpc_init_shutdown_internals
, argc
, argv
);
5259 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5260 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5261 rpc_reg_shutdown_internals
, argc
, argv
);
5267 /***************************************************************************
5268 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5269 ***************************************************************************/
5272 * Add interdomain trust account to the RPC server.
5273 * All parameters (except for argc and argv) are passed by run_rpc_command
5276 * @param c A net_context structure.
5277 * @param domain_sid The domain sid acquired from the server.
5278 * @param cli A cli_state connected to the server.
5279 * @param mem_ctx Talloc context, destroyed on completion of the function.
5280 * @param argc Standard main() style argc.
5281 * @param argv Standard main() style argv. Initial components are already
5284 * @return normal NTSTATUS return code.
5287 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5288 const DOM_SID
*domain_sid
,
5289 const char *domain_name
,
5290 struct cli_state
*cli
,
5291 struct rpc_pipe_client
*pipe_hnd
,
5292 TALLOC_CTX
*mem_ctx
,
5296 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5297 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5299 struct lsa_String lsa_acct_name
;
5301 uint32 acct_flags
=0;
5303 uint32_t access_granted
= 0;
5304 union samr_UserInfo info
;
5305 unsigned int orig_timeout
;
5308 d_printf("Usage: net rpc trustdom add <domain_name> "
5309 "<trust password>\n");
5310 return NT_STATUS_INVALID_PARAMETER
;
5314 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5317 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5318 return NT_STATUS_NO_MEMORY
;
5321 strupper_m(acct_name
);
5323 init_lsa_String(&lsa_acct_name
, acct_name
);
5325 /* Get samr policy handle */
5326 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5328 MAXIMUM_ALLOWED_ACCESS
,
5330 if (!NT_STATUS_IS_OK(result
)) {
5334 /* Get domain policy handle */
5335 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5337 MAXIMUM_ALLOWED_ACCESS
,
5338 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5340 if (!NT_STATUS_IS_OK(result
)) {
5344 /* This call can take a long time - allow the server to time out.
5345 * 35 seconds should do it. */
5347 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5349 /* Create trusting domain's account */
5350 acb_info
= ACB_NORMAL
;
5351 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5352 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5353 SAMR_USER_ACCESS_SET_PASSWORD
|
5354 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5355 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5357 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5366 /* And restore our original timeout. */
5367 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5369 if (!NT_STATUS_IS_OK(result
)) {
5370 d_printf("net rpc trustdom add: create user %s failed %s\n",
5371 acct_name
, nt_errstr(result
));
5377 struct samr_LogonHours hours
;
5378 struct lsa_BinaryString parameters
;
5379 const int units_per_week
= 168;
5380 struct samr_CryptPassword crypt_pwd
;
5382 ZERO_STRUCT(notime
);
5384 ZERO_STRUCT(parameters
);
5386 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
5388 result
= NT_STATUS_NO_MEMORY
;
5391 hours
.units_per_week
= units_per_week
;
5392 memset(hours
.bits
, 0xFF, units_per_week
);
5394 init_samr_CryptPassword(argv
[1],
5395 &cli
->user_session_key
,
5398 init_samr_user_info23(&info
.info23
,
5399 notime
, notime
, notime
,
5400 notime
, notime
, notime
,
5401 NULL
, NULL
, NULL
, NULL
, NULL
,
5402 NULL
, NULL
, NULL
, NULL
, ¶meters
,
5403 0, 0, ACB_DOMTRUST
, SAMR_FIELD_ACCT_FLAGS
,
5405 0, 0, 0, 0, 0, 0, 0,
5406 crypt_pwd
.data
, 24);
5408 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5413 if (!NT_STATUS_IS_OK(result
)) {
5414 DEBUG(0,("Could not set trust account password: %s\n",
5415 nt_errstr(result
)));
5421 SAFE_FREE(acct_name
);
5426 * Create interdomain trust account for a remote domain.
5428 * @param argc Standard argc.
5429 * @param argv Standard argv without initial components.
5431 * @return Integer status (0 means success).
5434 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5436 if (argc
> 0 && !c
->display_usage
) {
5437 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5438 rpc_trustdom_add_internals
, argc
, argv
);
5441 "net rpc trustdom add <domain_name> <trust password>\n");
5448 * Remove interdomain trust account from the RPC server.
5449 * All parameters (except for argc and argv) are passed by run_rpc_command
5452 * @param c A net_context structure.
5453 * @param domain_sid The domain sid acquired from the server.
5454 * @param cli A cli_state connected to the server.
5455 * @param mem_ctx Talloc context, destroyed on completion of the function.
5456 * @param argc Standard main() style argc.
5457 * @param argv Standard main() style argv. Initial components are already
5460 * @return normal NTSTATUS return code.
5463 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5464 const DOM_SID
*domain_sid
,
5465 const char *domain_name
,
5466 struct cli_state
*cli
,
5467 struct rpc_pipe_client
*pipe_hnd
,
5468 TALLOC_CTX
*mem_ctx
,
5472 POLICY_HND connect_pol
, domain_pol
, user_pol
;
5473 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5475 DOM_SID trust_acct_sid
;
5476 struct samr_Ids user_rids
, name_types
;
5477 struct lsa_String lsa_acct_name
;
5480 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5481 return NT_STATUS_INVALID_PARAMETER
;
5485 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5487 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5489 if (acct_name
== NULL
)
5490 return NT_STATUS_NO_MEMORY
;
5492 strupper_m(acct_name
);
5494 /* Get samr policy handle */
5495 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5497 MAXIMUM_ALLOWED_ACCESS
,
5499 if (!NT_STATUS_IS_OK(result
)) {
5503 /* Get domain policy handle */
5504 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5506 MAXIMUM_ALLOWED_ACCESS
,
5507 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5509 if (!NT_STATUS_IS_OK(result
)) {
5513 init_lsa_String(&lsa_acct_name
, acct_name
);
5515 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5522 if (!NT_STATUS_IS_OK(result
)) {
5523 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5524 acct_name
, nt_errstr(result
) );
5528 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5530 MAXIMUM_ALLOWED_ACCESS
,
5534 if (!NT_STATUS_IS_OK(result
)) {
5535 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5536 acct_name
, nt_errstr(result
) );
5540 /* append the rid to the domain sid */
5541 sid_copy(&trust_acct_sid
, domain_sid
);
5542 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5546 /* remove the sid */
5548 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5551 if (!NT_STATUS_IS_OK(result
)) {
5552 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5553 acct_name
, nt_errstr(result
) );
5559 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5562 if (!NT_STATUS_IS_OK(result
)) {
5563 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5564 acct_name
, nt_errstr(result
) );
5568 if (!NT_STATUS_IS_OK(result
)) {
5569 d_printf("Could not set trust account password: %s\n",
5579 * Delete interdomain trust account for a remote domain.
5581 * @param argc Standard argc.
5582 * @param argv Standard argv without initial components.
5584 * @return Integer status (0 means success).
5587 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5589 if (argc
> 0 && !c
->display_usage
) {
5590 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5591 rpc_trustdom_del_internals
, argc
, argv
);
5594 "net rpc trustdom del <domain>\n");
5599 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5600 struct cli_state
*cli
,
5601 TALLOC_CTX
*mem_ctx
,
5602 const char *domain_name
)
5604 char *dc_name
= NULL
;
5605 const char *buffer
= NULL
;
5606 struct rpc_pipe_client
*netr
;
5609 /* Use NetServerEnum2 */
5611 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5613 return NT_STATUS_OK
;
5616 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5617 for domain %s\n", domain_name
));
5619 /* Try netr_GetDcName */
5621 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5623 if (!NT_STATUS_IS_OK(status
)) {
5627 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5634 if (NT_STATUS_IS_OK(status
)) {
5638 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5639 for domain %s\n", domain_name
));
5645 * Establish trust relationship to a trusting domain.
5646 * Interdomain account must already be created on remote PDC.
5648 * @param c A net_context structure.
5649 * @param argc Standard argc.
5650 * @param argv Standard argv without initial components.
5652 * @return Integer status (0 means success).
5655 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5658 struct cli_state
*cli
= NULL
;
5659 struct sockaddr_storage server_ss
;
5660 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5661 POLICY_HND connect_hnd
;
5662 TALLOC_CTX
*mem_ctx
;
5664 DOM_SID
*domain_sid
;
5669 union lsa_PolicyInformation
*info
= NULL
;
5672 * Connect to \\server\ipc$ as 'our domain' account with password
5675 if (argc
!= 1 || c
->display_usage
) {
5677 "net rpc trustdom establish <domain_name>\n");
5681 domain_name
= smb_xstrdup(argv
[0]);
5682 strupper_m(domain_name
);
5684 /* account name used at first is our domain's name with '$' */
5685 asprintf(&acct_name
, "%s$", lp_workgroup());
5686 strupper_m(acct_name
);
5689 * opt_workgroup will be used by connection functions further,
5690 * hence it should be set to remote domain name instead of ours
5692 if (c
->opt_workgroup
) {
5693 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5696 c
->opt_user_name
= acct_name
;
5698 /* find the domain controller */
5699 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5700 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5704 /* connect to ipc$ as username/password */
5705 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5706 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5708 /* Is it trusting domain account for sure ? */
5709 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5710 nt_errstr(nt_status
)));
5714 /* store who we connected to */
5716 saf_store( domain_name
, pdc_name
);
5719 * Connect to \\server\ipc$ again (this time anonymously)
5722 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5725 if (NT_STATUS_IS_ERR(nt_status
)) {
5726 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5727 domain_name
, nt_errstr(nt_status
)));
5731 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5732 "domain %s", domain_name
))) {
5733 DEBUG(0, ("talloc_init() failed\n"));
5738 /* Make sure we're talking to a proper server */
5740 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5741 if (!NT_STATUS_IS_OK(nt_status
)) {
5743 talloc_destroy(mem_ctx
);
5748 * Call LsaOpenPolicy and LsaQueryInfo
5751 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5753 if (!NT_STATUS_IS_OK(nt_status
)) {
5754 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5756 talloc_destroy(mem_ctx
);
5760 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, SEC_RIGHTS_QUERY_VALUE
,
5762 if (NT_STATUS_IS_ERR(nt_status
)) {
5763 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5764 nt_errstr(nt_status
)));
5766 talloc_destroy(mem_ctx
);
5770 /* Querying info level 5 */
5772 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5774 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5776 if (NT_STATUS_IS_ERR(nt_status
)) {
5777 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5778 nt_errstr(nt_status
)));
5780 talloc_destroy(mem_ctx
);
5784 domain_sid
= info
->account_domain
.sid
;
5786 /* There should be actually query info level 3 (following nt serv behaviour),
5787 but I still don't know if it's _really_ necessary */
5790 * Store the password in secrets db
5793 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5794 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5796 talloc_destroy(mem_ctx
);
5801 * Close the pipes and clean up
5804 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5805 if (NT_STATUS_IS_ERR(nt_status
)) {
5806 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5807 nt_errstr(nt_status
)));
5809 talloc_destroy(mem_ctx
);
5815 talloc_destroy(mem_ctx
);
5817 d_printf("Trust to domain %s established\n", domain_name
);
5822 * Revoke trust relationship to the remote domain.
5824 * @param c A net_context structure.
5825 * @param argc Standard argc.
5826 * @param argv Standard argv without initial components.
5828 * @return Integer status (0 means success).
5831 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5837 if (argc
< 1 || c
->display_usage
) {
5839 "net rpc trustdom revoke <domain_name>\n"
5840 " Revoke trust relationship\n"
5841 " domain_name\tName of domain to revoke trust\n");
5845 /* generate upper cased domain name */
5846 domain_name
= smb_xstrdup(argv
[0]);
5847 strupper_m(domain_name
);
5849 /* delete password of the trust */
5850 if (!pdb_del_trusteddom_pw(domain_name
)) {
5851 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5858 SAFE_FREE(domain_name
);
5862 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5863 const DOM_SID
*domain_sid
,
5864 const char *domain_name
,
5865 struct cli_state
*cli
,
5866 struct rpc_pipe_client
*pipe_hnd
,
5867 TALLOC_CTX
*mem_ctx
,
5872 sid_to_fstring(str_sid
, domain_sid
);
5873 d_printf("%s\n", str_sid
);
5874 return NT_STATUS_OK
;
5877 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5879 fstring ascii_sid
, padding
;
5880 int pad_len
, col_len
= 20;
5882 /* convert sid into ascii string */
5883 sid_to_fstring(ascii_sid
, dom_sid
);
5885 /* calculate padding space for d_printf to look nicer */
5886 pad_len
= col_len
- strlen(trusted_dom_name
);
5887 padding
[pad_len
] = 0;
5888 do padding
[--pad_len
] = ' '; while (pad_len
);
5890 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5893 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5894 TALLOC_CTX
*mem_ctx
,
5897 const char *trusted_dom_name
)
5900 union lsa_TrustedDomainInfo
*info
= NULL
;
5901 char *cleartextpwd
= NULL
;
5902 uint8_t nt_hash
[16];
5905 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5908 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5910 if (NT_STATUS_IS_ERR(nt_status
)) {
5911 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5912 nt_errstr(nt_status
)));
5916 data
= data_blob(info
->password
.password
->data
,
5917 info
->password
.password
->length
);
5919 if (!rpccli_get_pwd_hash(pipe_hnd
, nt_hash
)) {
5920 DEBUG(0, ("Could not retrieve password hash\n"));
5924 cleartextpwd
= decrypt_trustdom_secret(nt_hash
, &data
);
5926 if (cleartextpwd
== NULL
) {
5927 DEBUG(0,("retrieved NULL password\n"));
5928 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5932 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5933 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5934 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5938 #ifdef DEBUG_PASSWORD
5939 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5940 "password: [%s]\n", trusted_dom_name
,
5941 sid_string_dbg(&dom_sid
), cleartextpwd
));
5945 SAFE_FREE(cleartextpwd
);
5946 data_blob_free(&data
);
5951 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5954 /* common variables */
5955 TALLOC_CTX
* mem_ctx
;
5956 struct cli_state
*cli
= NULL
;
5957 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5959 const char *domain_name
= NULL
;
5960 DOM_SID
*queried_dom_sid
;
5961 POLICY_HND connect_hnd
;
5962 union lsa_PolicyInformation
*info
= NULL
;
5964 /* trusted domains listing variables */
5965 unsigned int enum_ctx
= 0;
5967 struct lsa_DomainList dom_list
;
5970 if (c
->display_usage
) {
5972 "net rpc trustdom vampire\n"
5973 " Vampire trust relationship from remote server\n");
5978 * Listing trusted domains (stored in secrets.tdb, if local)
5981 mem_ctx
= talloc_init("trust relationships vampire");
5984 * set domain and pdc name to local samba server (default)
5985 * or to remote one given in command line
5988 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5989 domain_name
= c
->opt_workgroup
;
5990 c
->opt_target_workgroup
= c
->opt_workgroup
;
5992 fstrcpy(pdc_name
, global_myname());
5993 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5994 c
->opt_target_workgroup
= domain_name
;
5997 /* open \PIPE\lsarpc and open policy handle */
5998 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5999 if (!NT_STATUS_IS_OK(nt_status
)) {
6000 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6001 nt_errstr(nt_status
)));
6002 talloc_destroy(mem_ctx
);
6006 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6008 if (!NT_STATUS_IS_OK(nt_status
)) {
6009 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6010 nt_errstr(nt_status
) ));
6012 talloc_destroy(mem_ctx
);
6016 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
6018 if (NT_STATUS_IS_ERR(nt_status
)) {
6019 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6020 nt_errstr(nt_status
)));
6022 talloc_destroy(mem_ctx
);
6026 /* query info level 5 to obtain sid of a domain being queried */
6027 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6029 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6032 if (NT_STATUS_IS_ERR(nt_status
)) {
6033 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6034 nt_errstr(nt_status
)));
6036 talloc_destroy(mem_ctx
);
6040 queried_dom_sid
= info
->account_domain
.sid
;
6043 * Keep calling LsaEnumTrustdom over opened pipe until
6044 * the end of enumeration is reached
6047 d_printf("Vampire trusted domains:\n\n");
6050 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6055 if (NT_STATUS_IS_ERR(nt_status
)) {
6056 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6057 nt_errstr(nt_status
)));
6059 talloc_destroy(mem_ctx
);
6063 for (i
= 0; i
< dom_list
.count
; i
++) {
6065 print_trusted_domain(dom_list
.domains
[i
].sid
,
6066 dom_list
.domains
[i
].name
.string
);
6068 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
6069 *dom_list
.domains
[i
].sid
,
6070 dom_list
.domains
[i
].name
.string
);
6071 if (!NT_STATUS_IS_OK(nt_status
)) {
6073 talloc_destroy(mem_ctx
);
6079 * in case of no trusted domains say something rather
6080 * than just display blank line
6082 if (!dom_list
.count
) d_printf("none\n");
6084 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6086 /* close this connection before doing next one */
6087 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6088 if (NT_STATUS_IS_ERR(nt_status
)) {
6089 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6090 nt_errstr(nt_status
)));
6092 talloc_destroy(mem_ctx
);
6096 /* close lsarpc pipe and connection to IPC$ */
6099 talloc_destroy(mem_ctx
);
6103 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
6105 /* common variables */
6106 TALLOC_CTX
* mem_ctx
;
6107 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
6108 struct rpc_pipe_client
*pipe_hnd
= NULL
;
6110 const char *domain_name
= NULL
;
6111 DOM_SID
*queried_dom_sid
;
6113 int ascii_dom_name_len
;
6114 POLICY_HND connect_hnd
;
6115 union lsa_PolicyInformation
*info
= NULL
;
6117 /* trusted domains listing variables */
6118 unsigned int num_domains
, enum_ctx
= 0;
6119 int i
, pad_len
, col_len
= 20;
6120 struct lsa_DomainList dom_list
;
6123 /* trusting domains listing variables */
6124 POLICY_HND domain_hnd
;
6125 struct samr_SamArray
*trusts
= NULL
;
6127 if (c
->display_usage
) {
6129 "net rpc trustdom list\n"
6130 " List trust relationships\n");
6135 * Listing trusted domains (stored in secrets.tdb, if local)
6138 mem_ctx
= talloc_init("trust relationships listing");
6141 * set domain and pdc name to local samba server (default)
6142 * or to remote one given in command line
6145 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
6146 domain_name
= c
->opt_workgroup
;
6147 c
->opt_target_workgroup
= c
->opt_workgroup
;
6149 fstrcpy(pdc_name
, global_myname());
6150 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6151 c
->opt_target_workgroup
= domain_name
;
6154 /* open \PIPE\lsarpc and open policy handle */
6155 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6156 if (!NT_STATUS_IS_OK(nt_status
)) {
6157 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6158 nt_errstr(nt_status
)));
6159 talloc_destroy(mem_ctx
);
6163 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6165 if (!NT_STATUS_IS_OK(nt_status
)) {
6166 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6167 nt_errstr(nt_status
) ));
6169 talloc_destroy(mem_ctx
);
6173 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, SEC_RIGHTS_QUERY_VALUE
,
6175 if (NT_STATUS_IS_ERR(nt_status
)) {
6176 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6177 nt_errstr(nt_status
)));
6179 talloc_destroy(mem_ctx
);
6183 /* query info level 5 to obtain sid of a domain being queried */
6184 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6186 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6189 if (NT_STATUS_IS_ERR(nt_status
)) {
6190 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6191 nt_errstr(nt_status
)));
6193 talloc_destroy(mem_ctx
);
6197 queried_dom_sid
= info
->account_domain
.sid
;
6200 * Keep calling LsaEnumTrustdom over opened pipe until
6201 * the end of enumeration is reached
6204 d_printf("Trusted domains list:\n\n");
6207 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6212 if (NT_STATUS_IS_ERR(nt_status
)) {
6213 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6214 nt_errstr(nt_status
)));
6216 talloc_destroy(mem_ctx
);
6220 for (i
= 0; i
< dom_list
.count
; i
++) {
6221 print_trusted_domain(dom_list
.domains
[i
].sid
,
6222 dom_list
.domains
[i
].name
.string
);
6226 * in case of no trusted domains say something rather
6227 * than just display blank line
6229 if (!dom_list
.count
) d_printf("none\n");
6231 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6233 /* close this connection before doing next one */
6234 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6235 if (NT_STATUS_IS_ERR(nt_status
)) {
6236 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6237 nt_errstr(nt_status
)));
6239 talloc_destroy(mem_ctx
);
6243 TALLOC_FREE(pipe_hnd
);
6246 * Listing trusting domains (stored in passdb backend, if local)
6249 d_printf("\nTrusting domains list:\n\n");
6252 * Open \PIPE\samr and get needed policy handles
6254 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6256 if (!NT_STATUS_IS_OK(nt_status
)) {
6257 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6259 talloc_destroy(mem_ctx
);
6264 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6266 SA_RIGHT_SAM_OPEN_DOMAIN
,
6268 if (!NT_STATUS_IS_OK(nt_status
)) {
6269 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6270 nt_errstr(nt_status
)));
6272 talloc_destroy(mem_ctx
);
6276 /* SamrOpenDomain - we have to open domain policy handle in order to be
6277 able to enumerate accounts*/
6278 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6280 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
6283 if (!NT_STATUS_IS_OK(nt_status
)) {
6284 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6285 nt_errstr(nt_status
)));
6287 talloc_destroy(mem_ctx
);
6292 * perform actual enumeration
6295 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6298 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6305 if (NT_STATUS_IS_ERR(nt_status
)) {
6306 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6307 nt_errstr(nt_status
)));
6309 talloc_destroy(mem_ctx
);
6313 for (i
= 0; i
< num_domains
; i
++) {
6315 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6318 * get each single domain's sid (do we _really_ need this ?):
6319 * 1) connect to domain's pdc
6320 * 2) query the pdc for domain's sid
6323 /* get rid of '$' tail */
6324 ascii_dom_name_len
= strlen(str
);
6325 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6326 str
[ascii_dom_name_len
- 1] = '\0';
6328 /* calculate padding space for d_printf to look nicer */
6329 pad_len
= col_len
- strlen(str
);
6330 padding
[pad_len
] = 0;
6331 do padding
[--pad_len
] = ' '; while (pad_len
);
6333 /* set opt_* variables to remote domain */
6335 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6336 c
->opt_target_workgroup
= c
->opt_workgroup
;
6338 d_printf("%s%s", str
, padding
);
6340 /* connect to remote domain controller */
6341 nt_status
= net_make_ipc_connection(c
,
6342 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6344 if (NT_STATUS_IS_OK(nt_status
)) {
6345 /* query for domain's sid */
6346 if (run_rpc_command(
6348 &ndr_table_lsarpc
.syntax_id
, 0,
6349 rpc_query_domain_sid
, argc
,
6351 d_fprintf(stderr
, "couldn't get domain's sid\n");
6353 cli_shutdown(remote_cli
);
6356 d_fprintf(stderr
, "domain controller is not "
6358 nt_errstr(nt_status
));
6362 if (!num_domains
) d_printf("none\n");
6364 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6366 /* close opened samr and domain policy handles */
6367 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6368 if (!NT_STATUS_IS_OK(nt_status
)) {
6369 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6372 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6373 if (!NT_STATUS_IS_OK(nt_status
)) {
6374 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6377 /* close samr pipe and connection to IPC$ */
6380 talloc_destroy(mem_ctx
);
6385 * Entrypoint for 'net rpc trustdom' code.
6387 * @param argc Standard argc.
6388 * @param argv Standard argv without initial components.
6390 * @return Integer status (0 means success).
6393 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6395 struct functable func
[] = {
6400 "Add trusted domain's account",
6401 "net rpc trustdom add\n"
6402 " Add trusted domain's account"
6408 "Remove trusted domain's account",
6409 "net rpc trustdom del\n"
6410 " Remove trusted domain's account"
6414 rpc_trustdom_establish
,
6416 "Establish trust relationship",
6417 "net rpc trustdom establish\n"
6418 " Establish trust relationship"
6422 rpc_trustdom_revoke
,
6424 "Revoke trust relationship",
6425 "net rpc trustdom revoke\n"
6426 " Revoke trust relationship"
6432 "List domain trusts",
6433 "net rpc trustdom list\n"
6434 " List domain trusts"
6438 rpc_trustdom_vampire
,
6440 "Vampire trusts from remote server",
6441 "net rpc trustdom vampire\n"
6442 " Vampire trusts from remote server"
6444 {NULL
, NULL
, 0, NULL
, NULL
}
6447 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6451 * Check if a server will take rpc commands
6452 * @param flags Type of server to connect to (PDC, DMB, localhost)
6453 * if the host is not explicitly specified
6454 * @return bool (true means rpc supported)
6456 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6458 struct cli_state
*cli
;
6460 struct sockaddr_storage server_ss
;
6461 char *server_name
= NULL
;
6464 /* flags (i.e. server type) may depend on command */
6465 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6468 if ((cli
= cli_initialise()) == NULL
) {
6472 status
= cli_connect(cli
, server_name
, &server_ss
);
6473 if (!NT_STATUS_IS_OK(status
))
6475 if (!attempt_netbios_session_request(&cli
, global_myname(),
6476 server_name
, &server_ss
))
6478 if (!cli_negprot(cli
))
6480 if (cli
->protocol
< PROTOCOL_NT1
)
6489 /* dump sam database via samsync rpc calls */
6490 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6491 if (c
->display_usage
) {
6494 " Dump remote SAM database\n");
6498 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6499 NET_FLAGS_ANONYMOUS
,
6500 rpc_samdump_internals
, argc
, argv
);
6503 /* syncronise sam database via samsync rpc calls */
6504 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6506 struct functable func
[] = {
6511 "Dump remote SAM database to ldif",
6512 "net rpc vampire ldif\n"
6513 " Dump remote SAM database to LDIF file or stdout"
6519 "Dump remote SAM database to Kerberos Keytab",
6520 "net rpc vampire keytab\n"
6521 " Dump remote SAM database to Kerberos keytab file"
6524 {NULL
, NULL
, 0, NULL
, NULL
}
6528 if (c
->display_usage
) {
6531 " Vampire remote SAM database\n");
6535 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6536 NET_FLAGS_ANONYMOUS
,
6537 rpc_vampire_internals
,
6541 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6545 * Migrate everything from a print server.
6547 * @param c A net_context structure.
6548 * @param argc Standard main() style argc.
6549 * @param argv Standard main() style argv. Initial components are already
6552 * @return A shell status integer (0 for success).
6554 * The order is important !
6555 * To successfully add drivers the print queues have to exist !
6556 * Applying ACLs should be the last step, because you're easily locked out.
6559 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6564 if (c
->display_usage
) {
6566 "net rpc printer migrate all\n"
6567 " Migrate everything from a print server\n");
6572 d_printf("no server to migrate\n");
6576 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6577 rpc_printer_migrate_printers_internals
, argc
,
6582 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6583 rpc_printer_migrate_drivers_internals
, argc
,
6588 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6589 rpc_printer_migrate_forms_internals
, argc
, argv
);
6593 ret
= run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6594 rpc_printer_migrate_settings_internals
, argc
,
6599 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6600 rpc_printer_migrate_security_internals
, argc
,
6606 * Migrate print drivers from a print server.
6608 * @param c A net_context structure.
6609 * @param argc Standard main() style argc.
6610 * @param argv Standard main() style argv. Initial components are already
6613 * @return A shell status integer (0 for success).
6615 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6618 if (c
->display_usage
) {
6620 "net rpc printer migrate drivers\n"
6621 " Migrate print-drivers from a print-server\n");
6626 d_printf("no server to migrate\n");
6630 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6631 rpc_printer_migrate_drivers_internals
,
6636 * Migrate print-forms from a print-server.
6638 * @param c A net_context structure.
6639 * @param argc Standard main() style argc.
6640 * @param argv Standard main() style argv. Initial components are already
6643 * @return A shell status integer (0 for success).
6645 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6648 if (c
->display_usage
) {
6650 "net rpc printer migrate forms\n"
6651 " Migrate print-forms from a print-server\n");
6656 d_printf("no server to migrate\n");
6660 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6661 rpc_printer_migrate_forms_internals
,
6666 * Migrate printers from a print-server.
6668 * @param c A net_context structure.
6669 * @param argc Standard main() style argc.
6670 * @param argv Standard main() style argv. Initial components are already
6673 * @return A shell status integer (0 for success).
6675 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6678 if (c
->display_usage
) {
6680 "net rpc printer migrate printers\n"
6681 " Migrate printers from a print-server\n");
6686 d_printf("no server to migrate\n");
6690 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6691 rpc_printer_migrate_printers_internals
,
6696 * Migrate printer-ACLs from a print-server
6698 * @param c A net_context structure.
6699 * @param argc Standard main() style argc.
6700 * @param argv Standard main() style argv. Initial components are already
6703 * @return A shell status integer (0 for success).
6705 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6708 if (c
->display_usage
) {
6710 "net rpc printer migrate security\n"
6711 " Migrate printer-ACLs from a print-server\n");
6716 d_printf("no server to migrate\n");
6720 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6721 rpc_printer_migrate_security_internals
,
6726 * Migrate printer-settings from a print-server.
6728 * @param c A net_context structure.
6729 * @param argc Standard main() style argc.
6730 * @param argv Standard main() style argv. Initial components are already
6733 * @return A shell status integer (0 for success).
6735 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6738 if (c
->display_usage
) {
6740 "net rpc printer migrate settings\n"
6741 " Migrate printer-settings from a print-server\n");
6746 d_printf("no server to migrate\n");
6750 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6751 rpc_printer_migrate_settings_internals
,
6756 * 'net rpc printer' entrypoint.
6758 * @param c A net_context structure.
6759 * @param argc Standard main() style argc.
6760 * @param argv Standard main() style argv. Initial components are already
6764 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6767 /* ouch: when addriver and setdriver are called from within
6768 rpc_printer_migrate_drivers_internals, the printer-queue already
6771 struct functable func
[] = {
6774 rpc_printer_migrate_all
,
6776 "Migrate all from remote to local print server",
6777 "net rpc printer migrate all\n"
6778 " Migrate all from remote to local print server"
6782 rpc_printer_migrate_drivers
,
6784 "Migrate drivers to local server",
6785 "net rpc printer migrate drivers\n"
6786 " Migrate drivers to local server"
6790 rpc_printer_migrate_forms
,
6792 "Migrate froms to local server",
6793 "net rpc printer migrate forms\n"
6794 " Migrate froms to local server"
6798 rpc_printer_migrate_printers
,
6800 "Migrate printers to local server",
6801 "net rpc printer migrate printers\n"
6802 " Migrate printers to local server"
6806 rpc_printer_migrate_security
,
6808 "Mirgate printer ACLs to local server",
6809 "net rpc printer migrate security\n"
6810 " Mirgate printer ACLs to local server"
6814 rpc_printer_migrate_settings
,
6816 "Migrate printer settings to local server",
6817 "net rpc printer migrate settings\n"
6818 " Migrate printer settings to local server"
6820 {NULL
, NULL
, 0, NULL
, NULL
}
6823 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6828 * List printers on a remote RPC server.
6830 * @param c A net_context structure.
6831 * @param argc Standard main() style argc.
6832 * @param argv Standard main() style argv. Initial components are already
6835 * @return A shell status integer (0 for success).
6837 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6839 if (c
->display_usage
) {
6841 "net rpc printer list\n"
6842 " List printers on a remote RPC server\n");
6846 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6847 rpc_printer_list_internals
,
6852 * List printer-drivers on a remote RPC server.
6854 * @param c A net_context structure.
6855 * @param argc Standard main() style argc.
6856 * @param argv Standard main() style argv. Initial components are already
6859 * @return A shell status integer (0 for success).
6861 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6864 if (c
->display_usage
) {
6866 "net rpc printer driver\n"
6867 " List printer-drivers on a remote RPC server\n");
6871 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6872 rpc_printer_driver_list_internals
,
6877 * Publish printer in ADS via MSRPC.
6879 * @param c A net_context structure.
6880 * @param argc Standard main() style argc.
6881 * @param argv Standard main() style argv. Initial components are already
6884 * @return A shell status integer (0 for success).
6886 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6889 if (c
->display_usage
) {
6891 "net rpc printer publish publish\n"
6892 " Publish printer in ADS via MSRPC\n");
6896 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6897 rpc_printer_publish_publish_internals
,
6902 * Update printer in ADS via MSRPC.
6904 * @param c A net_context structure.
6905 * @param argc Standard main() style argc.
6906 * @param argv Standard main() style argv. Initial components are already
6909 * @return A shell status integer (0 for success).
6911 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6913 if (c
->display_usage
) {
6915 "net rpc printer publish update\n"
6916 " Update printer in ADS via MSRPC\n");
6920 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6921 rpc_printer_publish_update_internals
,
6926 * UnPublish printer in ADS via MSRPC.
6928 * @param c A net_context structure.
6929 * @param argc Standard main() style argc.
6930 * @param argv Standard main() style argv. Initial components are already
6933 * @return A shell status integer (0 for success).
6935 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6938 if (c
->display_usage
) {
6940 "net rpc printer publish unpublish\n"
6941 " UnPublish printer in ADS via MSRPC\n");
6945 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6946 rpc_printer_publish_unpublish_internals
,
6951 * List published printers via MSRPC.
6953 * @param c A net_context structure.
6954 * @param argc Standard main() style argc.
6955 * @param argv Standard main() style argv. Initial components are already
6958 * @return A shell status integer (0 for success).
6960 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6963 if (c
->display_usage
) {
6965 "net rpc printer publish list\n"
6966 " List published printers via MSRPC\n");
6970 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
6971 rpc_printer_publish_list_internals
,
6977 * Publish printer in ADS.
6979 * @param c A net_context structure.
6980 * @param argc Standard main() style argc.
6981 * @param argv Standard main() style argv. Initial components are already
6984 * @return A shell status integer (0 for success).
6986 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6990 struct functable func
[] = {
6993 rpc_printer_publish_publish
,
6995 "Publish printer in AD",
6996 "net rpc printer publish publish\n"
6997 " Publish printer in AD"
7001 rpc_printer_publish_update
,
7003 "Update printer in AD",
7004 "net rpc printer publish update\n"
7005 " Update printer in AD"
7009 rpc_printer_publish_unpublish
,
7011 "Unpublish printer",
7012 "net rpc printer publish unpublish\n"
7013 " Unpublish printer"
7017 rpc_printer_publish_list
,
7019 "List published printers",
7020 "net rpc printer publish list\n"
7021 " List published printers"
7023 {NULL
, NULL
, 0, NULL
, NULL
}
7027 if (c
->display_usage
) {
7028 d_printf("Usage:\n");
7029 d_printf("net rpc printer publish\n"
7030 " List published printers\n"
7031 " Alias of net rpc printer publish list\n");
7032 net_display_usage_from_functable(func
);
7035 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
7036 rpc_printer_publish_list_internals
,
7040 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
7046 * Display rpc printer help page.
7048 * @param c A net_context structure.
7049 * @param argc Standard main() style argc.
7050 * @param argv Standard main() style argv. Initial components are already
7053 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
7055 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
7056 "\tlists all printers on print-server\n\n");
7057 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
7058 "\tlists all printer-drivers on print-server\n\n");
7059 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
7060 "\tpublishes printer settings in Active Directory\n"
7061 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
7062 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
7063 "\n\tmigrates printers from remote to local server\n\n");
7064 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
7065 "\n\tmigrates printer-settings from remote to local server\n\n");
7066 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
7067 "\n\tmigrates printer-drivers from remote to local server\n\n");
7068 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
7069 "\n\tmigrates printer-forms from remote to local server\n\n");
7070 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
7071 "\n\tmigrates printer-ACLs from remote to local server\n\n");
7072 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
7073 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
7074 "\tremote to local print-server\n\n");
7075 net_common_methods_usage(c
, argc
, argv
);
7076 net_common_flags_usage(c
, argc
, argv
);
7078 "\t-v or --verbose\t\t\tgive verbose output\n"
7079 "\t --destination\t\tmigration target server (default: localhost)\n");
7085 * 'net rpc printer' entrypoint.
7087 * @param c A net_context structure.
7088 * @param argc Standard main() style argc.
7089 * @param argv Standard main() style argv. Initial components are already
7092 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
7094 struct functable func
[] = {
7099 "List all printers on print server",
7100 "net rpc printer list\n"
7101 " List all printers on print server"
7105 rpc_printer_migrate
,
7107 "Migrate printer to local server",
7108 "net rpc printer migrate\n"
7109 " Migrate printer to local server"
7113 rpc_printer_driver_list
,
7115 "List printer drivers",
7116 "net rpc printer driver\n"
7117 " List printer drivers"
7121 rpc_printer_publish
,
7123 "Publish printer in AD",
7124 "net rpc printer publish\n"
7125 " Publish printer in AD"
7127 {NULL
, NULL
, 0, NULL
, NULL
}
7131 if (c
->display_usage
) {
7132 d_printf("Usage:\n");
7133 d_printf("net rpc printer\n"
7134 " List printers\n");
7135 net_display_usage_from_functable(func
);
7138 return run_rpc_command(c
, NULL
, &syntax_spoolss
, 0,
7139 rpc_printer_list_internals
,
7143 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7147 * 'net rpc' entrypoint.
7149 * @param c A net_context structure.
7150 * @param argc Standard main() style argc.
7151 * @param argv Standard main() style argv. Initial components are already
7155 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7157 struct functable func
[] = {
7162 "Modify global audit settings",
7164 " Modify global audit settings"
7170 "Show basic info about a domain",
7172 " Show basic info about a domain"
7186 "Join a domain created in server manager",
7188 " Join a domain created in server manager"
7194 "Test that a join is valid",
7195 "net rpc testjoin\n"
7196 " Test that a join is valid"
7202 "List/modify users",
7204 " List/modify users"
7210 "Change a user password",
7211 "net rpc password\n"
7212 " Change a user password\n"
7213 " Alias for net rpc user password"
7219 "List/modify groups",
7221 " List/modify groups"
7227 "List/modify shares",
7229 " List/modify shares"
7243 "List/modify printers",
7245 " List/modify printers"
7249 net_rpc_changetrustpw
,
7251 "Change trust account password",
7252 "net rpc changetrustpw\n"
7253 " Change trust account password"
7259 "Modify domain trusts",
7260 "net rpc trustdom\n"
7261 " Modify domain trusts"
7267 "Abort a remote shutdown",
7268 "net rpc abortshutdown\n"
7269 " Abort a remote shutdown"
7275 "Shutdown a remote server",
7276 "net rpc shutdown\n"
7277 " Shutdown a remote server"
7283 "Dump SAM data of remote NT PDC",
7285 " Dump SAM data of remote NT PDC"
7291 "Sync a remote NT PDC's data into local passdb",
7293 " Sync a remote NT PDC's data into local passdb"
7299 "Fetch the domain sid into local secrets.tdb",
7301 " Fetch the domain sid into local secrets.tdb"
7307 "Manage privileges assigned to SID",
7309 " Manage privileges assigned to SID"
7315 "Start/stop/query remote services",
7317 " Start/stop/query remote services"
7323 "Manage registry hives",
7324 "net rpc registry\n"
7325 " Manage registry hives"
7331 "Open interactive shell on remote server",
7333 " Open interactive shell on remote server"
7335 {NULL
, NULL
, 0, NULL
, NULL
}
7337 return net_run_function(c
, argc
, argv
, "net rpc", func
);