2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
5 Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2004,2008 Guenther Deschner (gd@samba.org)
7 Copyright (C) 2005 Jeremy Allison (jra@samba.org)
8 Copyright (C) 2006 Jelmer Vernooij (jelmer@samba.org)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "utils/net.h"
26 static int net_mode_share
;
27 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
);
32 * @brief RPC based subcommands for the 'net' utility.
34 * This file should contain much of the functionality that used to
35 * be found in rpcclient, execpt that the commands should change
36 * less often, and the fucntionality should be sane (the user is not
37 * expected to know a rid/sid before they conduct an operation etc.)
39 * @todo Perhaps eventually these should be split out into a number
40 * of files, as this could get quite big.
45 * Many of the RPC functions need the domain sid. This function gets
46 * it at the start of every run
48 * @param cli A cli_state already connected to the remote machine
50 * @return The Domain SID of the remote machine.
53 NTSTATUS
net_get_remote_domain_sid(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
55 const char **domain_name
)
57 struct rpc_pipe_client
*lsa_pipe
= NULL
;
58 struct policy_handle pol
;
59 NTSTATUS result
= NT_STATUS_OK
;
60 union lsa_PolicyInformation
*info
= NULL
;
62 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
64 if (!NT_STATUS_IS_OK(result
)) {
65 d_fprintf(stderr
, "Could not initialise lsa pipe\n");
69 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, false,
70 SEC_FLAG_MAXIMUM_ALLOWED
,
72 if (!NT_STATUS_IS_OK(result
)) {
73 d_fprintf(stderr
, "open_policy failed: %s\n",
78 result
= rpccli_lsa_QueryInfoPolicy(lsa_pipe
, mem_ctx
,
80 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
82 if (!NT_STATUS_IS_OK(result
)) {
83 d_fprintf(stderr
, "lsaquery failed: %s\n",
88 *domain_name
= info
->account_domain
.name
.string
;
89 *domain_sid
= info
->account_domain
.sid
;
91 rpccli_lsa_Close(lsa_pipe
, mem_ctx
, &pol
);
92 TALLOC_FREE(lsa_pipe
);
98 * Run a single RPC command, from start to finish.
100 * @param pipe_name the pipe to connect to (usually a PIPE_ constant)
101 * @param conn_flag a NET_FLAG_ combination. Passed to
102 * net_make_ipc_connection.
103 * @param argc Standard main() style argc.
104 * @param argv Standard main() style argv. Initial components are already
106 * @return A shell status integer (0 for success).
109 int run_rpc_command(struct net_context
*c
,
110 struct cli_state
*cli_arg
,
111 const struct ndr_syntax_id
*interface
,
117 struct cli_state
*cli
= NULL
;
118 struct rpc_pipe_client
*pipe_hnd
= NULL
;
122 const char *domain_name
;
125 /* make use of cli_state handed over as an argument, if possible */
127 nt_status
= net_make_ipc_connection(c
, conn_flags
, &cli
);
128 if (!NT_STATUS_IS_OK(nt_status
)) {
129 DEBUG(1, ("failed to make ipc connection: %s\n",
130 nt_errstr(nt_status
)));
143 if (!(mem_ctx
= talloc_init("run_rpc_command"))) {
144 DEBUG(0, ("talloc_init() failed\n"));
148 nt_status
= net_get_remote_domain_sid(cli
, mem_ctx
, &domain_sid
,
150 if (!NT_STATUS_IS_OK(nt_status
)) {
154 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
155 if (lp_client_schannel()
156 && (ndr_syntax_id_equal(interface
,
157 &ndr_table_netlogon
.syntax_id
))) {
158 /* Always try and create an schannel netlogon pipe. */
159 nt_status
= cli_rpc_pipe_open_schannel(
160 cli
, interface
, NCACN_NP
,
161 PIPE_AUTH_LEVEL_PRIVACY
, domain_name
,
163 if (!NT_STATUS_IS_OK(nt_status
)) {
164 DEBUG(0, ("Could not initialise schannel netlogon pipe. Error was %s\n",
165 nt_errstr(nt_status
) ));
169 if (conn_flags
& NET_FLAGS_SEAL
) {
170 nt_status
= cli_rpc_pipe_open_ntlmssp(
172 (conn_flags
& NET_FLAGS_TCP
) ?
173 NCACN_IP_TCP
: NCACN_NP
,
174 PIPE_AUTH_LEVEL_PRIVACY
,
175 lp_workgroup(), c
->opt_user_name
,
176 c
->opt_password
, &pipe_hnd
);
178 nt_status
= cli_rpc_pipe_open_noauth(
182 if (!NT_STATUS_IS_OK(nt_status
)) {
183 DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
184 get_pipe_name_from_iface(interface
),
185 nt_errstr(nt_status
) ));
191 nt_status
= fn(c
, domain_sid
, domain_name
, cli
, pipe_hnd
, mem_ctx
, argc
, argv
);
193 if (!NT_STATUS_IS_OK(nt_status
)) {
194 DEBUG(1, ("rpc command function failed! (%s)\n", nt_errstr(nt_status
)));
197 DEBUG(5, ("rpc command function succedded\n"));
200 if (!(conn_flags
& NET_FLAGS_NO_PIPE
)) {
202 TALLOC_FREE(pipe_hnd
);
207 /* close the connection only if it was opened here */
212 talloc_destroy(mem_ctx
);
217 * Force a change of the trust acccount password.
219 * All parameters are provided by the run_rpc_command function, except for
220 * argc, argv which are passed through.
222 * @param domain_sid The domain sid acquired from the remote server.
223 * @param cli A cli_state connected to the server.
224 * @param mem_ctx Talloc context, destroyed on completion of the function.
225 * @param argc Standard main() style argc.
226 * @param argv Standard main() style argv. Initial components are already
229 * @return Normal NTSTATUS return.
232 static NTSTATUS
rpc_changetrustpw_internals(struct net_context
*c
,
233 const DOM_SID
*domain_sid
,
234 const char *domain_name
,
235 struct cli_state
*cli
,
236 struct rpc_pipe_client
*pipe_hnd
,
242 return trust_pw_find_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
);
246 * Force a change of the trust acccount password.
248 * @param argc Standard main() style argc.
249 * @param argv Standard main() style argv. Initial components are already
252 * @return A shell status integer (0 for success).
255 int net_rpc_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
257 if (c
->display_usage
) {
259 "net rpc changetrustpw\n"
260 " Change the machine trust password\n");
264 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
265 NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
266 rpc_changetrustpw_internals
,
271 * Join a domain, the old way.
273 * This uses 'machinename' as the inital password, and changes it.
275 * The password should be created with 'server manager' or equiv first.
277 * All parameters are provided by the run_rpc_command function, except for
278 * argc, argv which are passed through.
280 * @param domain_sid The domain sid acquired from the remote server.
281 * @param cli A cli_state connected to the server.
282 * @param mem_ctx Talloc context, destroyed on completion of the function.
283 * @param argc Standard main() style argc.
284 * @param argv Standard main() style argv. Initial components are already
287 * @return Normal NTSTATUS return.
290 static NTSTATUS
rpc_oldjoin_internals(struct net_context
*c
,
291 const DOM_SID
*domain_sid
,
292 const char *domain_name
,
293 struct cli_state
*cli
,
294 struct rpc_pipe_client
*pipe_hnd
,
300 fstring trust_passwd
;
301 unsigned char orig_trust_passwd_hash
[16];
303 uint32 sec_channel_type
;
305 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
307 if (!NT_STATUS_IS_OK(result
)) {
308 DEBUG(0,("rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
311 nt_errstr(result
) ));
316 check what type of join - if the user want's to join as
317 a BDC, the server must agree that we are a BDC.
320 sec_channel_type
= get_sec_channel_type(argv
[0]);
322 sec_channel_type
= get_sec_channel_type(NULL
);
325 fstrcpy(trust_passwd
, global_myname());
326 strlower_m(trust_passwd
);
329 * Machine names can be 15 characters, but the max length on
330 * a password is 14. --jerry
333 trust_passwd
[14] = '\0';
335 E_md4hash(trust_passwd
, orig_trust_passwd_hash
);
337 result
= trust_pw_change_and_store_it(pipe_hnd
, mem_ctx
, c
->opt_target_workgroup
,
338 orig_trust_passwd_hash
,
341 if (NT_STATUS_IS_OK(result
))
342 printf("Joined domain %s.\n", c
->opt_target_workgroup
);
345 if (!secrets_store_domain_sid(c
->opt_target_workgroup
, domain_sid
)) {
346 DEBUG(0, ("error storing domain sid for %s\n", c
->opt_target_workgroup
));
347 result
= NT_STATUS_UNSUCCESSFUL
;
354 * Join a domain, the old way.
356 * @param argc Standard main() style argc.
357 * @param argv Standard main() style argv. Initial components are already
360 * @return A shell status integer (0 for success).
363 static int net_rpc_perform_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
365 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
366 NET_FLAGS_NO_PIPE
| NET_FLAGS_ANONYMOUS
| NET_FLAGS_PDC
,
367 rpc_oldjoin_internals
,
372 * Join a domain, the old way. This function exists to allow
373 * the message to be displayed when oldjoin was explicitly
374 * requested, but not when it was implied by "net rpc join".
376 * @param argc Standard main() style argc.
377 * @param argv Standard main() style argv. Initial components are already
380 * @return A shell status integer (0 for success).
383 static int net_rpc_oldjoin(struct net_context
*c
, int argc
, const char **argv
)
387 if (c
->display_usage
) {
390 " Join a domain the old way\n");
394 rc
= net_rpc_perform_oldjoin(c
, argc
, argv
);
397 d_fprintf(stderr
, "Failed to join domain\n");
404 * 'net rpc join' entrypoint.
405 * @param argc Standard main() style argc.
406 * @param argv Standard main() style argv. Initial components are already
409 * Main 'net_rpc_join()' (where the admin username/password is used) is
411 * Try to just change the password, but if that doesn't work, use/prompt
412 * for a username/password.
415 int net_rpc_join(struct net_context
*c
, int argc
, const char **argv
)
417 if (c
->display_usage
) {
419 "net rpc join -U <username>[%%password] <type>\n"
421 " username\tName of the admin user"
422 " password\tPassword of the admin user, will "
423 "prompt if not specified\n"
424 " type\tCan be one of the following:\n"
425 "\t\tMEMBER\tJoin as member server (default)\n"
426 "\t\tBDC\tJoin as BDC\n"
427 "\t\tPDC\tJoin as PDC\n");
431 if (lp_server_role() == ROLE_STANDALONE
) {
432 d_printf("cannot join as standalone machine\n");
436 if (strlen(global_myname()) > 15) {
437 d_printf("Our netbios name can be at most 15 chars long, "
438 "\"%s\" is %u chars long\n",
439 global_myname(), (unsigned int)strlen(global_myname()));
443 if ((net_rpc_perform_oldjoin(c
, argc
, argv
) == 0))
446 return net_rpc_join_newstyle(c
, argc
, argv
);
450 * display info about a rpc domain
452 * All parameters are provided by the run_rpc_command function, except for
453 * argc, argv which are passed through.
455 * @param domain_sid The domain sid acquired from the remote server
456 * @param cli A cli_state connected to the server.
457 * @param mem_ctx Talloc context, destroyed on completion of the function.
458 * @param argc Standard main() style argc.
459 * @param argv Standard main() style argv. Initial components are already
462 * @return Normal NTSTATUS return.
465 NTSTATUS
rpc_info_internals(struct net_context
*c
,
466 const DOM_SID
*domain_sid
,
467 const char *domain_name
,
468 struct cli_state
*cli
,
469 struct rpc_pipe_client
*pipe_hnd
,
474 struct policy_handle connect_pol
, domain_pol
;
475 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
476 union samr_DomainInfo
*info
= NULL
;
479 sid_to_fstring(sid_str
, domain_sid
);
481 /* Get sam policy handle */
482 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
484 MAXIMUM_ALLOWED_ACCESS
,
486 if (!NT_STATUS_IS_OK(result
)) {
487 d_fprintf(stderr
, "Could not connect to SAM: %s\n", nt_errstr(result
));
491 /* Get domain policy handle */
492 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
494 MAXIMUM_ALLOWED_ACCESS
,
495 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
497 if (!NT_STATUS_IS_OK(result
)) {
498 d_fprintf(stderr
, "Could not open domain: %s\n", nt_errstr(result
));
502 result
= rpccli_samr_QueryDomainInfo(pipe_hnd
, mem_ctx
,
506 if (NT_STATUS_IS_OK(result
)) {
507 d_printf("Domain Name: %s\n", info
->general
.domain_name
.string
);
508 d_printf("Domain SID: %s\n", sid_str
);
509 d_printf("Sequence number: %llu\n",
510 (unsigned long long)info
->general
.sequence_num
);
511 d_printf("Num users: %u\n", info
->general
.num_users
);
512 d_printf("Num domain groups: %u\n", info
->general
.num_groups
);
513 d_printf("Num local groups: %u\n", info
->general
.num_aliases
);
521 * 'net rpc info' entrypoint.
522 * @param argc Standard main() style argc.
523 * @param argv Standard main() style argv. Initial components are already
527 int net_rpc_info(struct net_context
*c
, int argc
, const char **argv
)
529 if (c
->display_usage
) {
532 " Display information about the domain\n");
536 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
537 NET_FLAGS_PDC
, rpc_info_internals
,
542 * Fetch domain SID into the local secrets.tdb.
544 * All parameters are provided by the run_rpc_command function, except for
545 * argc, argv which are passed through.
547 * @param domain_sid The domain sid acquired from the remote server.
548 * @param cli A cli_state connected to the server.
549 * @param mem_ctx Talloc context, destroyed on completion of the function.
550 * @param argc Standard main() style argc.
551 * @param argv Standard main() style argv. Initial components are already
554 * @return Normal NTSTATUS return.
557 static NTSTATUS
rpc_getsid_internals(struct net_context
*c
,
558 const DOM_SID
*domain_sid
,
559 const char *domain_name
,
560 struct cli_state
*cli
,
561 struct rpc_pipe_client
*pipe_hnd
,
568 sid_to_fstring(sid_str
, domain_sid
);
569 d_printf("Storing SID %s for Domain %s in secrets.tdb\n",
570 sid_str
, domain_name
);
572 if (!secrets_store_domain_sid(domain_name
, domain_sid
)) {
573 DEBUG(0,("Can't store domain SID\n"));
574 return NT_STATUS_UNSUCCESSFUL
;
581 * 'net rpc getsid' entrypoint.
582 * @param argc Standard main() style argc.
583 * @param argv Standard main() style argv. Initial components are already
587 int net_rpc_getsid(struct net_context
*c
, int argc
, const char **argv
)
589 int conn_flags
= NET_FLAGS_PDC
;
591 if (!c
->opt_user_specified
) {
592 conn_flags
|= NET_FLAGS_ANONYMOUS
;
595 if (c
->display_usage
) {
598 " Fetch domain SID into local secrets.tdb\n");
602 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
,
604 rpc_getsid_internals
,
608 /****************************************************************************/
611 * Basic usage function for 'net rpc user'.
612 * @param argc Standard main() style argc.
613 * @param argv Standard main() style argv. Initial components are already
617 static int rpc_user_usage(struct net_context
*c
, int argc
, const char **argv
)
619 return net_user_usage(c
, argc
, argv
);
623 * Add a new user to a remote RPC server.
625 * @param argc Standard main() style argc.
626 * @param argv Standard main() style argv. Initial components are already
629 * @return A shell status integer (0 for success).
632 static int rpc_user_add(struct net_context
*c
, int argc
, const char **argv
)
634 NET_API_STATUS status
;
635 struct USER_INFO_1 info1
;
636 uint32_t parm_error
= 0;
638 if (argc
< 1 || c
->display_usage
) {
639 rpc_user_usage(c
, argc
, argv
);
645 info1
.usri1_name
= argv
[0];
647 info1
.usri1_password
= argv
[1];
650 status
= NetUserAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
653 d_fprintf(stderr
, "Failed to add user '%s' with: %s.\n",
654 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
658 d_printf("Added user '%s'.\n", argv
[0]);
665 * Rename a user on a remote RPC server.
667 * @param argc Standard main() style argc.
668 * @param argv Standard main() style argv. Initial components are already
671 * @return A shell status integer (0 for success).
674 static int rpc_user_rename(struct net_context
*c
, int argc
, const char **argv
)
676 NET_API_STATUS status
;
677 struct USER_INFO_0 u0
;
678 uint32_t parm_err
= 0;
680 if (argc
!= 2 || c
->display_usage
) {
681 rpc_user_usage(c
, argc
, argv
);
685 u0
.usri0_name
= argv
[1];
687 status
= NetUserSetInfo(c
->opt_host
, argv
[0],
688 0, (uint8_t *)&u0
, &parm_err
);
690 d_fprintf(stderr
, "Failed to rename user from %s to %s - %s\n",
692 libnetapi_get_error_string(c
->netapi_ctx
, status
));
694 d_printf("Renamed user from %s to %s\n", argv
[0], argv
[1]);
701 * Delete a user from a remote RPC server.
703 * @param argc Standard main() style argc.
704 * @param argv Standard main() style argv. Initial components are already
707 * @return A shell status integer (0 for success).
710 static int rpc_user_delete(struct net_context
*c
, int argc
, const char **argv
)
712 NET_API_STATUS status
;
714 if (argc
< 1 || c
->display_usage
) {
715 rpc_user_usage(c
, argc
, argv
);
719 status
= NetUserDel(c
->opt_host
, argv
[0]);
722 d_fprintf(stderr
, "Failed to delete user '%s' with: %s.\n",
724 libnetapi_get_error_string(c
->netapi_ctx
, status
));
727 d_printf("Deleted user '%s'.\n", argv
[0]);
734 * Set a user's password on a remote RPC server.
736 * @param argc Standard main() style argc.
737 * @param argv Standard main() style argv. Initial components are already
740 * @return A shell status integer (0 for success).
743 static int rpc_user_password(struct net_context
*c
, int argc
, const char **argv
)
745 NET_API_STATUS status
;
747 struct USER_INFO_1003 u1003
;
748 uint32_t parm_err
= 0;
750 if (argc
< 1 || c
->display_usage
) {
751 rpc_user_usage(c
, argc
, argv
);
756 u1003
.usri1003_password
= argv
[1];
758 if (asprintf(&prompt
, "Enter new password for %s:", argv
[0]) == -1) {
761 u1003
.usri1003_password
= talloc_strdup(c
, getpass(prompt
));
763 if (u1003
.usri1003_password
== NULL
) {
768 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
770 /* Display results */
772 d_fprintf(stderr
, "Failed to set password for '%s' with: %s.\n",
773 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
782 * List a user's groups from a remote RPC server.
784 * @param argc Standard main() style argc.
785 * @param argv Standard main() style argv. Initial components are already
788 * @return A shell status integer (0 for success)
791 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
794 NET_API_STATUS status
;
795 struct GROUP_USERS_INFO_0
*u0
= NULL
;
796 uint32_t entries_read
= 0;
797 uint32_t total_entries
= 0;
801 if (argc
< 1 || c
->display_usage
) {
802 rpc_user_usage(c
, argc
, argv
);
806 status
= NetUserGetGroups(c
->opt_host
,
809 (uint8_t **)(void *)&u0
,
814 d_fprintf(stderr
, "Failed to get groups for '%s' with: %s.\n",
815 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
820 for (i
=0; i
< entries_read
; i
++) {
821 printf("%s\n", u0
->grui0_name
);
829 * List users on a remote RPC server.
831 * All parameters are provided by the run_rpc_command function, except for
832 * argc, argv which are passed through.
834 * @param domain_sid The domain sid acquired from the remote server.
835 * @param cli A cli_state connected to the server.
836 * @param mem_ctx Talloc context, destroyed on completion of the function.
837 * @param argc Standard main() style argc.
838 * @param argv Standard main() style argv. Initial components are already
841 * @return Normal NTSTATUS return.
844 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
846 NET_API_STATUS status
;
847 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
848 struct NET_DISPLAY_USER
*info
= NULL
;
851 /* Query domain users */
852 if (c
->opt_long_list_entries
)
853 d_printf("\nUser name Comment"
854 "\n-----------------------------\n");
856 uint32_t max_entries
, max_size
;
858 get_query_dispinfo_params(
859 loop_count
, &max_entries
, &max_size
);
861 status
= NetQueryDisplayInformation(c
->opt_host
,
868 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
872 info
= (struct NET_DISPLAY_USER
*)buffer
;
874 for (i
= 0; i
< num_entries
; i
++) {
876 if (c
->opt_long_list_entries
)
877 printf("%-21.21s %s\n", info
->usri1_name
,
878 info
->usri1_comment
);
880 printf("%s\n", info
->usri1_name
);
884 NetApiBufferFree(buffer
);
887 start_idx
+= num_entries
;
889 } while (status
== ERROR_MORE_DATA
);
895 * 'net rpc user' entrypoint.
896 * @param argc Standard main() style argc.
897 * @param argv Standard main() style argv. Initial components are already
901 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
903 NET_API_STATUS status
;
905 struct functable func
[] = {
910 "Add specified user",
912 " Add specified user"
918 "List domain groups of user",
919 "net rpc user info\n"
920 " Lis domain groups of user"
926 "Remove specified user",
927 "net rpc user delete\n"
928 " Remove specified user"
934 "Change user password",
935 "net rpc user password\n"
936 " Change user password"
942 "Rename specified user",
943 "net rpc user rename\n"
944 " Rename specified user"
946 {NULL
, NULL
, 0, NULL
, NULL
}
949 status
= libnetapi_init(&c
->netapi_ctx
);
953 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
954 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
955 if (c
->opt_kerberos
) {
956 libnetapi_set_use_kerberos(c
->netapi_ctx
);
960 if (c
->display_usage
) {
961 d_printf("Usage:\n");
962 d_printf("net rpc user\n"
963 " List all users\n");
964 net_display_usage_from_functable(func
);
968 return rpc_user_list(c
, argc
, argv
);
971 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
974 static NTSTATUS
rpc_sh_user_list(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_list(c
, argc
, argv
)));
983 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
985 struct rpc_sh_ctx
*ctx
,
986 struct rpc_pipe_client
*pipe_hnd
,
987 int argc
, const char **argv
)
989 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
992 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
994 struct rpc_sh_ctx
*ctx
,
995 struct rpc_pipe_client
*pipe_hnd
,
996 int argc
, const char **argv
,
998 struct net_context
*c
,
1000 struct rpc_sh_ctx
*ctx
,
1001 struct rpc_pipe_client
*pipe_hnd
,
1002 struct policy_handle
*user_hnd
,
1003 int argc
, const char **argv
))
1005 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1006 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1009 enum lsa_SidType type
;
1012 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1013 return NT_STATUS_INVALID_PARAMETER
;
1016 ZERO_STRUCT(connect_pol
);
1017 ZERO_STRUCT(domain_pol
);
1018 ZERO_STRUCT(user_pol
);
1020 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1021 argv
[0], NULL
, NULL
, &sid
, &type
);
1022 if (!NT_STATUS_IS_OK(result
)) {
1023 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1028 if (type
!= SID_NAME_USER
) {
1029 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1030 sid_type_lookup(type
));
1031 result
= NT_STATUS_NO_SUCH_USER
;
1035 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1036 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1037 result
= NT_STATUS_NO_SUCH_USER
;
1041 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1043 MAXIMUM_ALLOWED_ACCESS
,
1045 if (!NT_STATUS_IS_OK(result
)) {
1049 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1051 MAXIMUM_ALLOWED_ACCESS
,
1054 if (!NT_STATUS_IS_OK(result
)) {
1058 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1060 MAXIMUM_ALLOWED_ACCESS
,
1063 if (!NT_STATUS_IS_OK(result
)) {
1067 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1070 if (is_valid_policy_hnd(&user_pol
)) {
1071 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1073 if (is_valid_policy_hnd(&domain_pol
)) {
1074 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1076 if (is_valid_policy_hnd(&connect_pol
)) {
1077 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1082 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1083 TALLOC_CTX
*mem_ctx
,
1084 struct rpc_sh_ctx
*ctx
,
1085 struct rpc_pipe_client
*pipe_hnd
,
1086 struct policy_handle
*user_hnd
,
1087 int argc
, const char **argv
)
1090 union samr_UserInfo
*info
= NULL
;
1093 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1094 return NT_STATUS_INVALID_PARAMETER
;
1097 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1101 if (!NT_STATUS_IS_OK(result
)) {
1105 d_printf("user rid: %d, group rid: %d\n",
1107 info
->info21
.primary_gid
);
1112 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1113 TALLOC_CTX
*mem_ctx
,
1114 struct rpc_sh_ctx
*ctx
,
1115 struct rpc_pipe_client
*pipe_hnd
,
1116 int argc
, const char **argv
)
1118 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1119 rpc_sh_user_show_internals
);
1122 #define FETCHSTR(name, rec) \
1123 do { if (strequal(ctx->thiscmd, name)) { \
1124 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1127 #define SETSTR(name, rec, flag) \
1128 do { if (strequal(ctx->thiscmd, name)) { \
1129 init_lsa_String(&(info->info21.rec), argv[0]); \
1130 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1133 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1134 TALLOC_CTX
*mem_ctx
,
1135 struct rpc_sh_ctx
*ctx
,
1136 struct rpc_pipe_client
*pipe_hnd
,
1137 struct policy_handle
*user_hnd
,
1138 int argc
, const char **argv
)
1141 const char *username
;
1142 const char *oldval
= "";
1143 union samr_UserInfo
*info
= NULL
;
1146 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1148 return NT_STATUS_INVALID_PARAMETER
;
1151 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1155 if (!NT_STATUS_IS_OK(result
)) {
1159 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1161 FETCHSTR("fullname", full_name
);
1162 FETCHSTR("homedir", home_directory
);
1163 FETCHSTR("homedrive", home_drive
);
1164 FETCHSTR("logonscript", logon_script
);
1165 FETCHSTR("profilepath", profile_path
);
1166 FETCHSTR("description", description
);
1169 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1173 if (strcmp(argv
[0], "NULL") == 0) {
1177 ZERO_STRUCT(info
->info21
);
1179 SETSTR("fullname", full_name
, FULL_NAME
);
1180 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1181 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1182 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1183 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1184 SETSTR("description", description
, DESCRIPTION
);
1186 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1191 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1192 ctx
->thiscmd
, oldval
, argv
[0]);
1199 #define HANDLEFLG(name, rec) \
1200 do { if (strequal(ctx->thiscmd, name)) { \
1201 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1203 newflags = oldflags | ACB_##rec; \
1205 newflags = oldflags & ~ACB_##rec; \
1208 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1209 TALLOC_CTX
*mem_ctx
,
1210 struct rpc_sh_ctx
*ctx
,
1211 struct rpc_pipe_client
*pipe_hnd
,
1212 int argc
, const char **argv
)
1214 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1215 rpc_sh_user_str_edit_internals
);
1218 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1219 TALLOC_CTX
*mem_ctx
,
1220 struct rpc_sh_ctx
*ctx
,
1221 struct rpc_pipe_client
*pipe_hnd
,
1222 struct policy_handle
*user_hnd
,
1223 int argc
, const char **argv
)
1226 const char *username
;
1227 const char *oldval
= "unknown";
1228 uint32 oldflags
, newflags
;
1230 union samr_UserInfo
*info
= NULL
;
1233 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1234 !strequal(argv
[0], "no"))) {
1235 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1237 return NT_STATUS_INVALID_PARAMETER
;
1240 newval
= strequal(argv
[0], "yes");
1242 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1246 if (!NT_STATUS_IS_OK(result
)) {
1250 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1251 oldflags
= info
->info21
.acct_flags
;
1252 newflags
= info
->info21
.acct_flags
;
1254 HANDLEFLG("disabled", DISABLED
);
1255 HANDLEFLG("pwnotreq", PWNOTREQ
);
1256 HANDLEFLG("autolock", AUTOLOCK
);
1257 HANDLEFLG("pwnoexp", PWNOEXP
);
1260 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1264 ZERO_STRUCT(info
->info21
);
1266 info
->info21
.acct_flags
= newflags
;
1267 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1269 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1274 if (NT_STATUS_IS_OK(result
)) {
1275 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1276 ctx
->thiscmd
, oldval
, argv
[0]);
1284 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1285 TALLOC_CTX
*mem_ctx
,
1286 struct rpc_sh_ctx
*ctx
,
1287 struct rpc_pipe_client
*pipe_hnd
,
1288 int argc
, const char **argv
)
1290 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1291 rpc_sh_user_flag_edit_internals
);
1294 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1295 TALLOC_CTX
*mem_ctx
,
1296 struct rpc_sh_ctx
*ctx
)
1298 static struct rpc_sh_cmd cmds
[] = {
1300 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1301 "Show/Set a user's full name" },
1303 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1304 "Show/Set a user's home directory" },
1306 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1307 "Show/Set a user's home drive" },
1309 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1310 "Show/Set a user's logon script" },
1312 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1313 "Show/Set a user's profile path" },
1315 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1316 "Show/Set a user's description" },
1318 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1319 "Show/Set whether a user is disabled" },
1321 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1322 "Show/Set whether a user locked out" },
1324 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1325 "Show/Set whether a user does not need a password" },
1327 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1328 "Show/Set whether a user's password does not expire" },
1330 { NULL
, NULL
, 0, NULL
, NULL
}
1336 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1337 TALLOC_CTX
*mem_ctx
,
1338 struct rpc_sh_ctx
*ctx
)
1340 static struct rpc_sh_cmd cmds
[] = {
1342 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1343 "List available users" },
1345 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1346 "List the domain groups a user is member of" },
1348 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1349 "Show info about a user" },
1351 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1352 "Show/Modify a user's fields" },
1354 { NULL
, NULL
, 0, NULL
, NULL
}
1360 /****************************************************************************/
1363 * Basic usage function for 'net rpc group'.
1364 * @param argc Standard main() style argc.
1365 * @param argv Standard main() style argv. Initial components are already
1369 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1371 return net_group_usage(c
, argc
, argv
);
1375 * Delete group on a remote RPC server.
1377 * All parameters are provided by the run_rpc_command function, except for
1378 * argc, argv which are passed through.
1380 * @param domain_sid The domain sid acquired from the remote server.
1381 * @param cli A cli_state connected to the server.
1382 * @param mem_ctx Talloc context, destroyed on completion of the function.
1383 * @param argc Standard main() style argc.
1384 * @param argv Standard main() style argv. Initial components are already
1387 * @return Normal NTSTATUS return.
1390 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1391 const DOM_SID
*domain_sid
,
1392 const char *domain_name
,
1393 struct cli_state
*cli
,
1394 struct rpc_pipe_client
*pipe_hnd
,
1395 TALLOC_CTX
*mem_ctx
,
1399 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1400 bool group_is_primary
= false;
1401 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1403 struct samr_RidTypeArray
*rids
= NULL
;
1406 /* struct samr_RidWithAttribute *user_gids; */
1408 struct samr_Ids group_rids
, name_types
;
1409 struct lsa_String lsa_acct_name
;
1410 union samr_UserInfo
*info
= NULL
;
1412 if (argc
< 1 || c
->display_usage
) {
1413 rpc_group_usage(c
, argc
,argv
);
1414 return NT_STATUS_OK
; /* ok? */
1417 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1419 MAXIMUM_ALLOWED_ACCESS
,
1422 if (!NT_STATUS_IS_OK(result
)) {
1423 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1427 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1429 MAXIMUM_ALLOWED_ACCESS
,
1430 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1433 if (!NT_STATUS_IS_OK(result
)) {
1434 d_fprintf(stderr
, "Request open_domain failed\n");
1438 init_lsa_String(&lsa_acct_name
, argv
[0]);
1440 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1446 if (!NT_STATUS_IS_OK(result
)) {
1447 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1451 switch (name_types
.ids
[0])
1453 case SID_NAME_DOM_GRP
:
1454 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1456 MAXIMUM_ALLOWED_ACCESS
,
1459 if (!NT_STATUS_IS_OK(result
)) {
1460 d_fprintf(stderr
, "Request open_group failed");
1464 group_rid
= group_rids
.ids
[0];
1466 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1470 if (!NT_STATUS_IS_OK(result
)) {
1471 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1475 if (c
->opt_verbose
) {
1476 d_printf("Domain Group %s (rid: %d) has %d members\n",
1477 argv
[0],group_rid
, rids
->count
);
1480 /* Check if group is anyone's primary group */
1481 for (i
= 0; i
< rids
->count
; i
++)
1483 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1485 MAXIMUM_ALLOWED_ACCESS
,
1489 if (!NT_STATUS_IS_OK(result
)) {
1490 d_fprintf(stderr
, "Unable to open group member %d\n",
1495 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1500 if (!NT_STATUS_IS_OK(result
)) {
1501 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1506 if (info
->info21
.primary_gid
== group_rid
) {
1507 if (c
->opt_verbose
) {
1508 d_printf("Group is primary group of %s\n",
1509 info
->info21
.account_name
.string
);
1511 group_is_primary
= true;
1514 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1517 if (group_is_primary
) {
1518 d_fprintf(stderr
, "Unable to delete group because some "
1519 "of it's members have it as primary group\n");
1520 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1524 /* remove all group members */
1525 for (i
= 0; i
< rids
->count
; i
++)
1528 d_printf("Remove group member %d...",
1530 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1534 if (NT_STATUS_IS_OK(result
)) {
1539 d_printf("failed\n");
1544 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1548 /* removing a local group is easier... */
1549 case SID_NAME_ALIAS
:
1550 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1552 MAXIMUM_ALLOWED_ACCESS
,
1556 if (!NT_STATUS_IS_OK(result
)) {
1557 d_fprintf(stderr
, "Request open_alias failed\n");
1561 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1565 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1566 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1567 result
= NT_STATUS_UNSUCCESSFUL
;
1571 if (NT_STATUS_IS_OK(result
)) {
1573 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1575 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1576 get_friendly_nt_error_msg(result
));
1584 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1586 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1587 rpc_group_delete_internals
, argc
,argv
);
1590 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1592 NET_API_STATUS status
;
1593 struct GROUP_INFO_1 info1
;
1594 uint32_t parm_error
= 0;
1596 if (argc
!= 1 || c
->display_usage
) {
1597 rpc_group_usage(c
, argc
, argv
);
1603 info1
.grpi1_name
= argv
[0];
1604 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1605 info1
.grpi1_comment
= c
->opt_comment
;
1608 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1611 d_fprintf(stderr
, "Failed to add group '%s' with: %s.\n",
1612 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1616 d_printf("Added group '%s'.\n", argv
[0]);
1622 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1624 NET_API_STATUS status
;
1625 struct LOCALGROUP_INFO_1 info1
;
1626 uint32_t parm_error
= 0;
1628 if (argc
!= 1 || c
->display_usage
) {
1629 rpc_group_usage(c
, argc
, argv
);
1635 info1
.lgrpi1_name
= argv
[0];
1636 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1637 info1
.lgrpi1_comment
= c
->opt_comment
;
1640 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1643 d_fprintf(stderr
, "Failed to add alias '%s' with: %s.\n",
1644 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1648 d_printf("Added alias '%s'.\n", argv
[0]);
1654 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1656 if (c
->opt_localgroup
)
1657 return rpc_alias_add_internals(c
, argc
, argv
);
1659 return rpc_group_add_internals(c
, argc
, argv
);
1662 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1663 TALLOC_CTX
*mem_ctx
,
1666 enum lsa_SidType
*type
)
1668 DOM_SID
*sids
= NULL
;
1669 enum lsa_SidType
*types
= NULL
;
1670 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1671 struct policy_handle lsa_pol
;
1672 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1674 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1676 if (!NT_STATUS_IS_OK(result
)) {
1680 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1681 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
1683 if (!NT_STATUS_IS_OK(result
)) {
1687 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1688 &name
, NULL
, 1, &sids
, &types
);
1690 if (NT_STATUS_IS_OK(result
)) {
1691 sid_copy(sid
, &sids
[0]);
1695 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1699 TALLOC_FREE(pipe_hnd
);
1702 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1704 /* Try as S-1-5-whatever */
1708 if (string_to_sid(&tmp_sid
, name
)) {
1709 sid_copy(sid
, &tmp_sid
);
1710 *type
= SID_NAME_UNKNOWN
;
1711 result
= NT_STATUS_OK
;
1718 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1719 TALLOC_CTX
*mem_ctx
,
1720 const DOM_SID
*group_sid
,
1723 struct policy_handle connect_pol
, domain_pol
;
1726 struct policy_handle group_pol
;
1728 struct samr_Ids rids
, rid_types
;
1729 struct lsa_String lsa_acct_name
;
1733 sid_copy(&sid
, group_sid
);
1735 if (!sid_split_rid(&sid
, &group_rid
)) {
1736 return NT_STATUS_UNSUCCESSFUL
;
1739 /* Get sam policy handle */
1740 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1742 MAXIMUM_ALLOWED_ACCESS
,
1744 if (!NT_STATUS_IS_OK(result
)) {
1748 /* Get domain policy handle */
1749 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1751 MAXIMUM_ALLOWED_ACCESS
,
1754 if (!NT_STATUS_IS_OK(result
)) {
1758 init_lsa_String(&lsa_acct_name
, member
);
1760 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1767 if (!NT_STATUS_IS_OK(result
)) {
1768 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1772 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1774 MAXIMUM_ALLOWED_ACCESS
,
1778 if (!NT_STATUS_IS_OK(result
)) {
1782 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1785 0x0005); /* unknown flags */
1788 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1792 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1793 TALLOC_CTX
*mem_ctx
,
1794 const DOM_SID
*alias_sid
,
1797 struct policy_handle connect_pol
, domain_pol
;
1800 struct policy_handle alias_pol
;
1803 enum lsa_SidType member_type
;
1807 sid_copy(&sid
, alias_sid
);
1809 if (!sid_split_rid(&sid
, &alias_rid
)) {
1810 return NT_STATUS_UNSUCCESSFUL
;
1813 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1814 member
, &member_sid
, &member_type
);
1816 if (!NT_STATUS_IS_OK(result
)) {
1817 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1821 /* Get sam policy handle */
1822 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1824 MAXIMUM_ALLOWED_ACCESS
,
1826 if (!NT_STATUS_IS_OK(result
)) {
1830 /* Get domain policy handle */
1831 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1833 MAXIMUM_ALLOWED_ACCESS
,
1836 if (!NT_STATUS_IS_OK(result
)) {
1840 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1842 MAXIMUM_ALLOWED_ACCESS
,
1846 if (!NT_STATUS_IS_OK(result
)) {
1850 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1854 if (!NT_STATUS_IS_OK(result
)) {
1859 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1863 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1864 const DOM_SID
*domain_sid
,
1865 const char *domain_name
,
1866 struct cli_state
*cli
,
1867 struct rpc_pipe_client
*pipe_hnd
,
1868 TALLOC_CTX
*mem_ctx
,
1873 enum lsa_SidType group_type
;
1875 if (argc
!= 2 || c
->display_usage
) {
1877 "net rpc group addmem <group> <member>\n"
1878 " Add a member to a group\n"
1879 " group\tGroup to add member to\n"
1880 " member\tMember to add to group\n");
1881 return NT_STATUS_UNSUCCESSFUL
;
1884 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1885 &group_sid
, &group_type
))) {
1886 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
1887 return NT_STATUS_UNSUCCESSFUL
;
1890 if (group_type
== SID_NAME_DOM_GRP
) {
1891 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1892 &group_sid
, argv
[1]);
1894 if (!NT_STATUS_IS_OK(result
)) {
1895 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1896 argv
[1], argv
[0], nt_errstr(result
));
1901 if (group_type
== SID_NAME_ALIAS
) {
1902 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1903 &group_sid
, argv
[1]);
1905 if (!NT_STATUS_IS_OK(result
)) {
1906 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1907 argv
[1], argv
[0], nt_errstr(result
));
1912 d_fprintf(stderr
, "Can only add members to global or local groups "
1913 "which %s is not\n", argv
[0]);
1915 return NT_STATUS_UNSUCCESSFUL
;
1918 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1920 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1921 rpc_group_addmem_internals
,
1925 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1926 struct rpc_pipe_client
*pipe_hnd
,
1927 TALLOC_CTX
*mem_ctx
,
1928 const DOM_SID
*group_sid
,
1931 struct policy_handle connect_pol
, domain_pol
;
1934 struct policy_handle group_pol
;
1936 struct samr_Ids rids
, rid_types
;
1937 struct lsa_String lsa_acct_name
;
1941 sid_copy(&sid
, group_sid
);
1943 if (!sid_split_rid(&sid
, &group_rid
))
1944 return NT_STATUS_UNSUCCESSFUL
;
1946 /* Get sam policy handle */
1947 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1949 MAXIMUM_ALLOWED_ACCESS
,
1951 if (!NT_STATUS_IS_OK(result
))
1954 /* Get domain policy handle */
1955 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1957 MAXIMUM_ALLOWED_ACCESS
,
1960 if (!NT_STATUS_IS_OK(result
))
1963 init_lsa_String(&lsa_acct_name
, member
);
1965 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1971 if (!NT_STATUS_IS_OK(result
)) {
1972 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1976 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1978 MAXIMUM_ALLOWED_ACCESS
,
1982 if (!NT_STATUS_IS_OK(result
))
1985 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1990 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1994 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1995 TALLOC_CTX
*mem_ctx
,
1996 const DOM_SID
*alias_sid
,
1999 struct policy_handle connect_pol
, domain_pol
;
2002 struct policy_handle alias_pol
;
2005 enum lsa_SidType member_type
;
2009 sid_copy(&sid
, alias_sid
);
2011 if (!sid_split_rid(&sid
, &alias_rid
))
2012 return NT_STATUS_UNSUCCESSFUL
;
2014 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2015 member
, &member_sid
, &member_type
);
2017 if (!NT_STATUS_IS_OK(result
)) {
2018 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2022 /* Get sam policy handle */
2023 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2025 MAXIMUM_ALLOWED_ACCESS
,
2027 if (!NT_STATUS_IS_OK(result
)) {
2031 /* Get domain policy handle */
2032 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2034 MAXIMUM_ALLOWED_ACCESS
,
2037 if (!NT_STATUS_IS_OK(result
)) {
2041 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2043 MAXIMUM_ALLOWED_ACCESS
,
2047 if (!NT_STATUS_IS_OK(result
))
2050 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2054 if (!NT_STATUS_IS_OK(result
))
2058 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2062 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2063 const DOM_SID
*domain_sid
,
2064 const char *domain_name
,
2065 struct cli_state
*cli
,
2066 struct rpc_pipe_client
*pipe_hnd
,
2067 TALLOC_CTX
*mem_ctx
,
2072 enum lsa_SidType group_type
;
2074 if (argc
!= 2 || c
->display_usage
) {
2076 "net rpc group delmem <group> <member>\n"
2077 " Delete a member from a group\n"
2078 " group\tGroup to delete member from\n"
2079 " member\tMember to delete from group\n");
2080 return NT_STATUS_UNSUCCESSFUL
;
2083 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2084 &group_sid
, &group_type
))) {
2085 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2086 return NT_STATUS_UNSUCCESSFUL
;
2089 if (group_type
== SID_NAME_DOM_GRP
) {
2090 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2091 &group_sid
, argv
[1]);
2093 if (!NT_STATUS_IS_OK(result
)) {
2094 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2095 argv
[1], argv
[0], nt_errstr(result
));
2100 if (group_type
== SID_NAME_ALIAS
) {
2101 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2102 &group_sid
, argv
[1]);
2104 if (!NT_STATUS_IS_OK(result
)) {
2105 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2106 argv
[1], argv
[0], nt_errstr(result
));
2111 d_fprintf(stderr
, "Can only delete members from global or local groups "
2112 "which %s is not\n", argv
[0]);
2114 return NT_STATUS_UNSUCCESSFUL
;
2117 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2119 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2120 rpc_group_delmem_internals
,
2125 * List groups on a remote RPC server.
2127 * All parameters are provided by the run_rpc_command function, except for
2128 * argc, argv which are passes through.
2130 * @param domain_sid The domain sid acquired from the remote server.
2131 * @param cli A cli_state connected to the server.
2132 * @param mem_ctx Talloc context, destroyed on completion of the function.
2133 * @param argc Standard main() style argc.
2134 * @param argv Standard main() style argv. Initial components are already
2137 * @return Normal NTSTATUS return.
2140 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2141 const DOM_SID
*domain_sid
,
2142 const char *domain_name
,
2143 struct cli_state
*cli
,
2144 struct rpc_pipe_client
*pipe_hnd
,
2145 TALLOC_CTX
*mem_ctx
,
2149 struct policy_handle connect_pol
, domain_pol
;
2150 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2151 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2152 struct samr_SamArray
*groups
= NULL
;
2153 bool global
= false;
2155 bool builtin
= false;
2157 if (c
->display_usage
) {
2159 "net rpc group list [global] [local] [builtin]\n"
2160 " List groups on RPC server\n"
2161 " global\tList global groups\n"
2162 " local\tList local groups\n"
2163 " builtin\tList builtin groups\n"
2164 " If none of global, local or builtin is "
2165 "specified, all three options are considered set\n");
2166 return NT_STATUS_OK
;
2175 for (i
=0; i
<argc
; i
++) {
2176 if (strequal(argv
[i
], "global"))
2179 if (strequal(argv
[i
], "local"))
2182 if (strequal(argv
[i
], "builtin"))
2186 /* Get sam policy handle */
2188 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2190 MAXIMUM_ALLOWED_ACCESS
,
2192 if (!NT_STATUS_IS_OK(result
)) {
2196 /* Get domain policy handle */
2198 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2200 MAXIMUM_ALLOWED_ACCESS
,
2201 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2203 if (!NT_STATUS_IS_OK(result
)) {
2207 /* Query domain groups */
2208 if (c
->opt_long_list_entries
)
2209 d_printf("\nGroup name Comment"
2210 "\n-----------------------------\n");
2212 uint32_t max_size
, total_size
, returned_size
;
2213 union samr_DispInfo info
;
2217 get_query_dispinfo_params(
2218 loop_count
, &max_entries
, &max_size
);
2220 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2229 num_entries
= info
.info3
.count
;
2230 start_idx
+= info
.info3
.count
;
2232 if (!NT_STATUS_IS_OK(result
) &&
2233 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2236 for (i
= 0; i
< num_entries
; i
++) {
2238 const char *group
= NULL
;
2239 const char *desc
= NULL
;
2241 group
= info
.info3
.entries
[i
].account_name
.string
;
2242 desc
= info
.info3
.entries
[i
].description
.string
;
2244 if (c
->opt_long_list_entries
)
2245 printf("%-21.21s %-50.50s\n",
2248 printf("%s\n", group
);
2250 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2251 /* query domain aliases */
2256 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2262 if (!NT_STATUS_IS_OK(result
) &&
2263 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2266 for (i
= 0; i
< num_entries
; i
++) {
2268 const char *description
= NULL
;
2270 if (c
->opt_long_list_entries
) {
2272 struct policy_handle alias_pol
;
2273 union samr_AliasInfo
*info
= NULL
;
2275 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2278 groups
->entries
[i
].idx
,
2280 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2284 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2286 description
= info
->description
.string
;
2290 if (description
!= NULL
) {
2291 printf("%-21.21s %-50.50s\n",
2292 groups
->entries
[i
].name
.string
,
2295 printf("%s\n", groups
->entries
[i
].name
.string
);
2298 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2299 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2300 /* Get builtin policy handle */
2302 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2304 MAXIMUM_ALLOWED_ACCESS
,
2305 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2307 if (!NT_STATUS_IS_OK(result
)) {
2310 /* query builtin aliases */
2313 if (!builtin
) break;
2315 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2321 if (!NT_STATUS_IS_OK(result
) &&
2322 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2325 for (i
= 0; i
< num_entries
; i
++) {
2327 const char *description
= NULL
;
2329 if (c
->opt_long_list_entries
) {
2331 struct policy_handle alias_pol
;
2332 union samr_AliasInfo
*info
= NULL
;
2334 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2337 groups
->entries
[i
].idx
,
2339 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2343 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2345 description
= info
->description
.string
;
2349 if (description
!= NULL
) {
2350 printf("%-21.21s %-50.50s\n",
2351 groups
->entries
[i
].name
.string
,
2354 printf("%s\n", groups
->entries
[i
].name
.string
);
2357 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2363 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2365 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2366 rpc_group_list_internals
,
2370 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2371 struct rpc_pipe_client
*pipe_hnd
,
2372 TALLOC_CTX
*mem_ctx
,
2373 const char *domain_name
,
2374 const DOM_SID
*domain_sid
,
2375 struct policy_handle
*domain_pol
,
2379 struct policy_handle group_pol
;
2380 uint32 num_members
, *group_rids
;
2382 struct samr_RidTypeArray
*rids
= NULL
;
2383 struct lsa_Strings names
;
2384 struct samr_Ids types
;
2387 sid_to_fstring(sid_str
, domain_sid
);
2389 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2391 MAXIMUM_ALLOWED_ACCESS
,
2395 if (!NT_STATUS_IS_OK(result
))
2398 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2402 if (!NT_STATUS_IS_OK(result
))
2405 num_members
= rids
->count
;
2406 group_rids
= rids
->rids
;
2408 while (num_members
> 0) {
2409 int this_time
= 512;
2411 if (num_members
< this_time
)
2412 this_time
= num_members
;
2414 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2421 if (!NT_STATUS_IS_OK(result
))
2424 /* We only have users as members, but make the output
2425 the same as the output of alias members */
2427 for (i
= 0; i
< this_time
; i
++) {
2429 if (c
->opt_long_list_entries
) {
2430 printf("%s-%d %s\\%s %d\n", sid_str
,
2431 group_rids
[i
], domain_name
,
2432 names
.names
[i
].string
,
2435 printf("%s\\%s\n", domain_name
,
2436 names
.names
[i
].string
);
2440 num_members
-= this_time
;
2444 return NT_STATUS_OK
;
2447 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2448 struct rpc_pipe_client
*pipe_hnd
,
2449 TALLOC_CTX
*mem_ctx
,
2450 struct policy_handle
*domain_pol
,
2454 struct rpc_pipe_client
*lsa_pipe
;
2455 struct policy_handle alias_pol
, lsa_pol
;
2457 DOM_SID
*alias_sids
;
2460 enum lsa_SidType
*types
;
2462 struct lsa_SidArray sid_array
;
2464 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2466 MAXIMUM_ALLOWED_ACCESS
,
2470 if (!NT_STATUS_IS_OK(result
))
2473 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2477 if (!NT_STATUS_IS_OK(result
)) {
2478 d_fprintf(stderr
, "Couldn't list alias members\n");
2482 num_members
= sid_array
.num_sids
;
2484 if (num_members
== 0) {
2485 return NT_STATUS_OK
;
2488 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2489 &ndr_table_lsarpc
.syntax_id
,
2491 if (!NT_STATUS_IS_OK(result
)) {
2492 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2493 nt_errstr(result
) );
2497 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2498 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2500 if (!NT_STATUS_IS_OK(result
)) {
2501 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2502 TALLOC_FREE(lsa_pipe
);
2506 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2508 d_fprintf(stderr
, "Out of memory\n");
2509 TALLOC_FREE(lsa_pipe
);
2510 return NT_STATUS_NO_MEMORY
;
2513 for (i
=0; i
<num_members
; i
++) {
2514 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2517 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2518 num_members
, alias_sids
,
2519 &domains
, &names
, &types
);
2521 if (!NT_STATUS_IS_OK(result
) &&
2522 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2523 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2524 TALLOC_FREE(lsa_pipe
);
2528 for (i
= 0; i
< num_members
; i
++) {
2530 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2532 if (c
->opt_long_list_entries
) {
2533 printf("%s %s\\%s %d\n", sid_str
,
2534 domains
[i
] ? domains
[i
] : "*unknown*",
2535 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2538 printf("%s\\%s\n", domains
[i
], names
[i
]);
2540 printf("%s\n", sid_str
);
2544 TALLOC_FREE(lsa_pipe
);
2545 return NT_STATUS_OK
;
2548 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2549 const DOM_SID
*domain_sid
,
2550 const char *domain_name
,
2551 struct cli_state
*cli
,
2552 struct rpc_pipe_client
*pipe_hnd
,
2553 TALLOC_CTX
*mem_ctx
,
2558 struct policy_handle connect_pol
, domain_pol
;
2559 struct samr_Ids rids
, rid_types
;
2560 struct lsa_String lsa_acct_name
;
2562 /* Get sam policy handle */
2564 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2566 MAXIMUM_ALLOWED_ACCESS
,
2569 if (!NT_STATUS_IS_OK(result
))
2572 /* Get domain policy handle */
2574 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2576 MAXIMUM_ALLOWED_ACCESS
,
2577 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2580 if (!NT_STATUS_IS_OK(result
))
2583 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2585 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2592 if (!NT_STATUS_IS_OK(result
)) {
2594 /* Ok, did not find it in the global sam, try with builtin */
2596 DOM_SID sid_Builtin
;
2598 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2600 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2602 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2604 MAXIMUM_ALLOWED_ACCESS
,
2608 if (!NT_STATUS_IS_OK(result
)) {
2609 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2613 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2620 if (!NT_STATUS_IS_OK(result
)) {
2621 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2626 if (rids
.count
!= 1) {
2627 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2631 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2632 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2633 domain_sid
, &domain_pol
,
2637 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2638 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2642 return NT_STATUS_NO_SUCH_GROUP
;
2645 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2647 if (argc
!= 1 || c
->display_usage
) {
2648 return rpc_group_usage(c
, argc
, argv
);
2651 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2652 rpc_group_members_internals
,
2656 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2658 NET_API_STATUS status
;
2659 struct GROUP_INFO_0 g0
;
2663 d_printf("Usage: 'net rpc group rename group newname'\n");
2667 g0
.grpi0_name
= argv
[1];
2669 status
= NetGroupSetInfo(c
->opt_host
,
2676 d_fprintf(stderr
, "Renaming group %s failed with: %s\n",
2677 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2685 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2687 if (argc
!= 2 || c
->display_usage
) {
2688 return rpc_group_usage(c
, argc
, argv
);
2691 return rpc_group_rename_internals(c
, argc
, argv
);
2695 * 'net rpc group' entrypoint.
2696 * @param argc Standard main() style argc.
2697 * @param argv Standard main() style argv. Initial components are already
2701 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2703 NET_API_STATUS status
;
2705 struct functable func
[] = {
2710 "Create specified group",
2711 "net rpc group add\n"
2712 " Create specified group"
2718 "Delete specified group",
2719 "net rpc group delete\n"
2720 " Delete specified group"
2726 "Add member to group",
2727 "net rpc group addmem\n"
2728 " Add member to group"
2734 "Remove member from group",
2735 "net rpc group delmem\n"
2736 " Remove member from group"
2743 "net rpc group list\n"
2750 "List group members",
2751 "net rpc group members\n"
2752 " List group members"
2759 "net rpc group rename\n"
2762 {NULL
, NULL
, 0, NULL
, NULL
}
2765 status
= libnetapi_init(&c
->netapi_ctx
);
2769 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2770 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2771 if (c
->opt_kerberos
) {
2772 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2776 if (c
->display_usage
) {
2777 d_printf("Usage:\n");
2778 d_printf("net rpc group\n"
2779 " Alias for net rpc group list global local "
2781 net_display_usage_from_functable(func
);
2785 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2786 rpc_group_list_internals
,
2790 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2793 /****************************************************************************/
2795 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2797 return net_share_usage(c
, argc
, argv
);
2801 * Add a share on a remote RPC server.
2803 * @param argc Standard main() style argc.
2804 * @param argv Standard main() style argv. Initial components are already
2807 * @return A shell status integer (0 for success).
2810 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2812 NET_API_STATUS status
;
2815 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2816 uint32 num_users
=0, perms
=0;
2817 char *password
=NULL
; /* don't allow a share password */
2818 struct SHARE_INFO_2 i2
;
2819 uint32_t parm_error
= 0;
2821 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2822 return rpc_share_usage(c
, argc
, argv
);
2825 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2829 path
= strchr(sharename
, '=');
2836 i2
.shi2_netname
= sharename
;
2837 i2
.shi2_type
= type
;
2838 i2
.shi2_remark
= c
->opt_comment
;
2839 i2
.shi2_permissions
= perms
;
2840 i2
.shi2_max_uses
= c
->opt_maxusers
;
2841 i2
.shi2_current_uses
= num_users
;
2842 i2
.shi2_path
= path
;
2843 i2
.shi2_passwd
= password
;
2845 status
= NetShareAdd(c
->opt_host
,
2850 printf("NetShareAdd failed with: %s\n",
2851 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2858 * Delete a share on a remote RPC server.
2860 * @param domain_sid The domain sid acquired from the remote server.
2861 * @param argc Standard main() style argc.
2862 * @param argv Standard main() style argv. Initial components are already
2865 * @return A shell status integer (0 for success).
2867 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2869 if (argc
< 1 || c
->display_usage
) {
2870 return rpc_share_usage(c
, argc
, argv
);
2873 return NetShareDel(c
->opt_host
, argv
[0], 0);
2877 * Formatted print of share info
2879 * @param r pointer to SHARE_INFO_1 to format
2882 static void display_share_info_1(struct net_context
*c
,
2883 struct SHARE_INFO_1
*r
)
2885 if (c
->opt_long_list_entries
) {
2886 d_printf("%-12s %-8.8s %-50s\n",
2888 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2891 d_printf("%s\n", r
->shi1_netname
);
2895 static WERROR
get_share_info(struct net_context
*c
,
2896 struct rpc_pipe_client
*pipe_hnd
,
2897 TALLOC_CTX
*mem_ctx
,
2901 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2905 union srvsvc_NetShareInfo info
;
2907 /* no specific share requested, enumerate all */
2910 uint32_t preferred_len
= 0xffffffff;
2911 uint32_t total_entries
= 0;
2912 uint32_t resume_handle
= 0;
2914 info_ctr
->level
= level
;
2916 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2926 /* request just one share */
2927 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2934 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2939 ZERO_STRUCTP(info_ctr
);
2941 info_ctr
->level
= level
;
2946 struct srvsvc_NetShareCtr1
*ctr1
;
2948 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2949 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2952 ctr1
->array
= info
.info1
;
2954 info_ctr
->ctr
.ctr1
= ctr1
;
2958 struct srvsvc_NetShareCtr2
*ctr2
;
2960 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2961 W_ERROR_HAVE_NO_MEMORY(ctr2
);
2964 ctr2
->array
= info
.info2
;
2966 info_ctr
->ctr
.ctr2
= ctr2
;
2970 struct srvsvc_NetShareCtr502
*ctr502
;
2972 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
2973 W_ERROR_HAVE_NO_MEMORY(ctr502
);
2976 ctr502
->array
= info
.info502
;
2978 info_ctr
->ctr
.ctr502
= ctr502
;
2986 * 'net rpc share list' entrypoint.
2987 * @param argc Standard main() style argc.
2988 * @param argv Standard main() style argv. Initial components are already
2991 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
2993 NET_API_STATUS status
;
2994 struct SHARE_INFO_1
*i1
= NULL
;
2995 uint32_t entries_read
= 0;
2996 uint32_t total_entries
= 0;
2997 uint32_t resume_handle
= 0;
2998 uint32_t i
, level
= 1;
3000 if (c
->display_usage
) {
3002 "net rpc share list\n"
3003 " List shares on remote server\n");
3007 status
= NetShareEnum(c
->opt_host
,
3009 (uint8_t **)(void *)&i1
,
3018 /* Display results */
3020 if (c
->opt_long_list_entries
) {
3022 "\nEnumerating shared resources (exports) on remote server:\n\n"
3023 "\nShare name Type Description\n"
3024 "---------- ---- -----------\n");
3026 for (i
= 0; i
< entries_read
; i
++)
3027 display_share_info_1(c
, &i1
[i
]);
3032 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3034 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3035 d_printf("skipping [%s]: not a file share.\n", netname
);
3045 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3046 const char *netname
, uint32 type
)
3048 /* only support disk shares */
3049 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3050 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3054 /* skip builtin shares */
3055 /* FIXME: should print$ be added too ? */
3056 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3057 strequal(netname
,"global"))
3060 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3061 printf("excluding [%s]\n", netname
);
3065 return check_share_availability(cli
, netname
);
3069 * Migrate shares from a remote RPC server to the local RPC server.
3071 * All parameters are provided by the run_rpc_command function, except for
3072 * argc, argv which are passed through.
3074 * @param domain_sid The domain sid acquired from the remote server.
3075 * @param cli A cli_state connected to the server.
3076 * @param mem_ctx Talloc context, destroyed on completion of the function.
3077 * @param argc Standard main() style argc.
3078 * @param argv Standard main() style argv. Initial components are already
3081 * @return Normal NTSTATUS return.
3084 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3085 const DOM_SID
*domain_sid
,
3086 const char *domain_name
,
3087 struct cli_state
*cli
,
3088 struct rpc_pipe_client
*pipe_hnd
,
3089 TALLOC_CTX
*mem_ctx
,
3094 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3095 struct srvsvc_NetShareInfoCtr ctr_src
;
3097 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3098 struct cli_state
*cli_dst
= NULL
;
3099 uint32 level
= 502; /* includes secdesc */
3100 uint32_t parm_error
= 0;
3102 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3104 if (!W_ERROR_IS_OK(result
))
3107 /* connect destination PI_SRVSVC */
3108 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3109 &ndr_table_srvsvc
.syntax_id
);
3110 if (!NT_STATUS_IS_OK(nt_status
))
3114 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3116 union srvsvc_NetShareInfo info
;
3117 struct srvsvc_NetShareInfo502 info502
=
3118 ctr_src
.ctr
.ctr502
->array
[i
];
3120 /* reset error-code */
3121 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3123 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3126 /* finally add the share on the dst server */
3128 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3129 info502
.name
, info502
.path
, info502
.comment
);
3131 info
.info502
= &info502
;
3133 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3134 srvsvc_pipe
->desthost
,
3140 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3141 printf(" [%s] does already exist\n",
3146 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3147 printf("cannot add share: %s\n", win_errstr(result
));
3153 nt_status
= NT_STATUS_OK
;
3157 cli_shutdown(cli_dst
);
3165 * Migrate shares from a RPC server to another.
3167 * @param argc Standard main() style argc.
3168 * @param argv Standard main() style argv. Initial components are already
3171 * @return A shell status integer (0 for success).
3173 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3176 if (c
->display_usage
) {
3178 "net rpc share migrate shares\n"
3179 " Migrate shares to local server\n");
3184 printf("no server to migrate\n");
3188 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3189 rpc_share_migrate_shares_internals
,
3196 * @param f file_info
3197 * @param mask current search mask
3198 * @param state arg-pointer
3201 static void copy_fn(const char *mnt
, file_info
*f
,
3202 const char *mask
, void *state
)
3204 static NTSTATUS nt_status
;
3205 static struct copy_clistate
*local_state
;
3206 static fstring filename
, new_mask
;
3209 struct net_context
*c
;
3211 local_state
= (struct copy_clistate
*)state
;
3212 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3216 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3219 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3222 if (f
->mode
& aDIR
) {
3224 DEBUG(3,("got dir: %s\n", f
->name
));
3226 fstrcpy(dir
, local_state
->cwd
);
3228 fstrcat(dir
, f
->name
);
3230 switch (net_mode_share
)
3232 case NET_MODE_SHARE_MIGRATE
:
3233 /* create that directory */
3234 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3235 local_state
->cli_share_src
,
3236 local_state
->cli_share_dst
,
3238 c
->opt_acls
? true : false,
3239 c
->opt_attrs
? true : false,
3240 c
->opt_timestamps
? true:false,
3244 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3248 if (!NT_STATUS_IS_OK(nt_status
))
3249 printf("could not handle dir %s: %s\n",
3250 dir
, nt_errstr(nt_status
));
3252 /* search below that directory */
3253 fstrcpy(new_mask
, dir
);
3254 fstrcat(new_mask
, "\\*");
3256 old_dir
= local_state
->cwd
;
3257 local_state
->cwd
= dir
;
3258 if (!sync_files(local_state
, new_mask
))
3259 printf("could not handle files\n");
3260 local_state
->cwd
= old_dir
;
3267 fstrcpy(filename
, local_state
->cwd
);
3268 fstrcat(filename
, "\\");
3269 fstrcat(filename
, f
->name
);
3271 DEBUG(3,("got file: %s\n", filename
));
3273 switch (net_mode_share
)
3275 case NET_MODE_SHARE_MIGRATE
:
3276 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3277 local_state
->cli_share_src
,
3278 local_state
->cli_share_dst
,
3280 c
->opt_acls
? true : false,
3281 c
->opt_attrs
? true : false,
3282 c
->opt_timestamps
? true: false,
3286 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3290 if (!NT_STATUS_IS_OK(nt_status
))
3291 printf("could not handle file %s: %s\n",
3292 filename
, nt_errstr(nt_status
));
3297 * sync files, can be called recursivly to list files
3298 * and then call copy_fn for each file
3300 * @param cp_clistate pointer to the copy_clistate we work with
3301 * @param mask the current search mask
3303 * @return Boolean result
3305 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3307 struct cli_state
*targetcli
;
3308 char *targetpath
= NULL
;
3310 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3312 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3313 mask
, &targetcli
, &targetpath
) ) {
3314 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3315 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3319 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3320 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3321 mask
, cli_errstr(targetcli
));
3330 * Set the top level directory permissions before we do any further copies.
3331 * Should set up ACL inheritance.
3334 bool copy_top_level_perms(struct net_context
*c
,
3335 struct copy_clistate
*cp_clistate
,
3336 const char *sharename
)
3338 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3340 switch (net_mode_share
) {
3341 case NET_MODE_SHARE_MIGRATE
:
3342 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3343 nt_status
= net_copy_fileattr(c
,
3344 cp_clistate
->mem_ctx
,
3345 cp_clistate
->cli_share_src
,
3346 cp_clistate
->cli_share_dst
,
3348 c
->opt_acls
? true : false,
3349 c
->opt_attrs
? true : false,
3350 c
->opt_timestamps
? true: false,
3354 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3358 if (!NT_STATUS_IS_OK(nt_status
)) {
3359 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3360 sharename
, nt_errstr(nt_status
));
3368 * Sync all files inside a remote share to another share (over smb).
3370 * All parameters are provided by the run_rpc_command function, except for
3371 * argc, argv which are passed through.
3373 * @param domain_sid The domain sid acquired from the remote server.
3374 * @param cli A cli_state connected to the server.
3375 * @param mem_ctx Talloc context, destroyed on completion of the function.
3376 * @param argc Standard main() style argc.
3377 * @param argv Standard main() style argv. Initial components are already
3380 * @return Normal NTSTATUS return.
3383 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3384 const DOM_SID
*domain_sid
,
3385 const char *domain_name
,
3386 struct cli_state
*cli
,
3387 struct rpc_pipe_client
*pipe_hnd
,
3388 TALLOC_CTX
*mem_ctx
,
3393 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3394 struct srvsvc_NetShareInfoCtr ctr_src
;
3397 struct copy_clistate cp_clistate
;
3398 bool got_src_share
= false;
3399 bool got_dst_share
= false;
3400 const char *mask
= "\\*";
3403 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3405 nt_status
= NT_STATUS_NO_MEMORY
;
3409 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3412 if (!W_ERROR_IS_OK(result
))
3415 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3417 struct srvsvc_NetShareInfo502 info502
=
3418 ctr_src
.ctr
.ctr502
->array
[i
];
3420 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3423 /* one might not want to mirror whole discs :) */
3424 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3425 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3429 switch (net_mode_share
)
3431 case NET_MODE_SHARE_MIGRATE
:
3435 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3438 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3440 c
->opt_acls
? "including" : "without",
3441 c
->opt_attrs
? "including" : "without",
3442 c
->opt_timestamps
? "(preserving timestamps)" : "");
3444 cp_clistate
.mem_ctx
= mem_ctx
;
3445 cp_clistate
.cli_share_src
= NULL
;
3446 cp_clistate
.cli_share_dst
= NULL
;
3447 cp_clistate
.cwd
= NULL
;
3448 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3451 /* open share source */
3452 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3453 &cli
->dest_ss
, cli
->desthost
,
3454 info502
.name
, "A:");
3455 if (!NT_STATUS_IS_OK(nt_status
))
3458 got_src_share
= true;
3460 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3461 /* open share destination */
3462 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3463 NULL
, dst
, info502
.name
, "A:");
3464 if (!NT_STATUS_IS_OK(nt_status
))
3467 got_dst_share
= true;
3470 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3471 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3472 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3476 if (!sync_files(&cp_clistate
, mask
)) {
3477 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3478 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3483 nt_status
= NT_STATUS_OK
;
3488 cli_shutdown(cp_clistate
.cli_share_src
);
3491 cli_shutdown(cp_clistate
.cli_share_dst
);
3498 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3500 if (c
->display_usage
) {
3502 "net share migrate files\n"
3503 " Migrate files to local server\n");
3508 d_printf("no server to migrate\n");
3512 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3513 rpc_share_migrate_files_internals
,
3518 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3520 * All parameters are provided by the run_rpc_command function, except for
3521 * argc, argv which are passed through.
3523 * @param domain_sid The domain sid acquired from the remote server.
3524 * @param cli A cli_state connected to the server.
3525 * @param mem_ctx Talloc context, destroyed on completion of the function.
3526 * @param argc Standard main() style argc.
3527 * @param argv Standard main() style argv. Initial components are already
3530 * @return Normal NTSTATUS return.
3533 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3534 const DOM_SID
*domain_sid
,
3535 const char *domain_name
,
3536 struct cli_state
*cli
,
3537 struct rpc_pipe_client
*pipe_hnd
,
3538 TALLOC_CTX
*mem_ctx
,
3543 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3544 struct srvsvc_NetShareInfoCtr ctr_src
;
3545 union srvsvc_NetShareInfo info
;
3547 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3548 struct cli_state
*cli_dst
= NULL
;
3549 uint32 level
= 502; /* includes secdesc */
3550 uint32_t parm_error
= 0;
3552 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3555 if (!W_ERROR_IS_OK(result
))
3558 /* connect destination PI_SRVSVC */
3559 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3560 &ndr_table_srvsvc
.syntax_id
);
3561 if (!NT_STATUS_IS_OK(nt_status
))
3565 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3567 struct srvsvc_NetShareInfo502 info502
=
3568 ctr_src
.ctr
.ctr502
->array
[i
];
3570 /* reset error-code */
3571 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3573 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3576 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3577 info502
.name
, info502
.path
, info502
.comment
);
3580 display_sec_desc(info502
.sd_buf
.sd
);
3582 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3583 info
.info502
= &info502
;
3585 /* finally modify the share on the dst server */
3586 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3587 srvsvc_pipe
->desthost
,
3593 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3594 printf("cannot set share-acl: %s\n", win_errstr(result
));
3600 nt_status
= NT_STATUS_OK
;
3604 cli_shutdown(cli_dst
);
3612 * Migrate share-acls from a RPC server to another.
3614 * @param argc Standard main() style argc.
3615 * @param argv Standard main() style argv. Initial components are already
3618 * @return A shell status integer (0 for success).
3620 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3623 if (c
->display_usage
) {
3625 "net rpc share migrate security\n"
3626 " Migrate share-acls to local server\n");
3631 d_printf("no server to migrate\n");
3635 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3636 rpc_share_migrate_security_internals
,
3641 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3642 * from one server to another.
3644 * @param argc Standard main() style argc.
3645 * @param argv Standard main() style argv. Initial components are already
3648 * @return A shell status integer (0 for success).
3651 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3656 if (c
->display_usage
) {
3658 "net rpc share migrate all\n"
3659 " Migrates shares including all share settings\n");
3664 d_printf("no server to migrate\n");
3668 /* order is important. we don't want to be locked out by the share-acl
3669 * before copying files - gd */
3671 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3672 rpc_share_migrate_shares_internals
, argc
, argv
);
3676 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3677 rpc_share_migrate_files_internals
, argc
, argv
);
3681 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3682 rpc_share_migrate_security_internals
, argc
,
3688 * 'net rpc share migrate' entrypoint.
3689 * @param argc Standard main() style argc.
3690 * @param argv Standard main() style argv. Initial components are already
3693 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3696 struct functable func
[] = {
3699 rpc_share_migrate_all
,
3701 "Migrate shares from remote to local server",
3702 "net rpc share migrate all\n"
3703 " Migrate shares from remote to local server"
3707 rpc_share_migrate_files
,
3709 "Migrate files from remote to local server",
3710 "net rpc share migrate files\n"
3711 " Migrate files from remote to local server"
3715 rpc_share_migrate_security
,
3717 "Migrate share-ACLs from remote to local server",
3718 "net rpc share migrate security\n"
3719 " Migrate share-ACLs from remote to local server"
3723 rpc_share_migrate_shares
,
3725 "Migrate shares from remote to local server",
3726 "net rpc share migrate shares\n"
3727 " Migrate shares from remote to local server"
3729 {NULL
, NULL
, 0, NULL
, NULL
}
3732 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3734 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3743 static int num_server_aliases
;
3744 static struct full_alias
*server_aliases
;
3747 * Add an alias to the static list.
3749 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3751 if (server_aliases
== NULL
)
3752 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3754 server_aliases
[num_server_aliases
] = *alias
;
3755 num_server_aliases
+= 1;
3759 * For a specific domain on the server, fetch all the aliases
3760 * and their members. Add all of them to the server_aliases.
3763 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3764 TALLOC_CTX
*mem_ctx
,
3765 struct policy_handle
*connect_pol
,
3766 const DOM_SID
*domain_sid
)
3768 uint32 start_idx
, max_entries
, num_entries
, i
;
3769 struct samr_SamArray
*groups
= NULL
;
3771 struct policy_handle domain_pol
;
3773 /* Get domain policy handle */
3775 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3777 MAXIMUM_ALLOWED_ACCESS
,
3778 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3780 if (!NT_STATUS_IS_OK(result
))
3787 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3793 for (i
= 0; i
< num_entries
; i
++) {
3795 struct policy_handle alias_pol
;
3796 struct full_alias alias
;
3797 struct lsa_SidArray sid_array
;
3800 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3802 MAXIMUM_ALLOWED_ACCESS
,
3803 groups
->entries
[i
].idx
,
3805 if (!NT_STATUS_IS_OK(result
))
3808 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3811 if (!NT_STATUS_IS_OK(result
))
3814 alias
.num_members
= sid_array
.num_sids
;
3816 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3817 if (!NT_STATUS_IS_OK(result
))
3820 alias
.members
= NULL
;
3822 if (alias
.num_members
> 0) {
3823 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3825 for (j
= 0; j
< alias
.num_members
; j
++)
3826 sid_copy(&alias
.members
[j
],
3827 sid_array
.sids
[j
].sid
);
3830 sid_copy(&alias
.sid
, domain_sid
);
3831 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3833 push_alias(mem_ctx
, &alias
);
3835 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3837 result
= NT_STATUS_OK
;
3840 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3846 * Dump server_aliases as names for debugging purposes.
3849 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3850 const DOM_SID
*domain_sid
,
3851 const char *domain_name
,
3852 struct cli_state
*cli
,
3853 struct rpc_pipe_client
*pipe_hnd
,
3854 TALLOC_CTX
*mem_ctx
,
3860 struct policy_handle lsa_pol
;
3862 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3863 SEC_FLAG_MAXIMUM_ALLOWED
,
3865 if (!NT_STATUS_IS_OK(result
))
3868 for (i
=0; i
<num_server_aliases
; i
++) {
3871 enum lsa_SidType
*types
;
3874 struct full_alias
*alias
= &server_aliases
[i
];
3876 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3878 &domains
, &names
, &types
);
3879 if (!NT_STATUS_IS_OK(result
))
3882 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3884 if (alias
->num_members
== 0) {
3889 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3892 &domains
, &names
, &types
);
3894 if (!NT_STATUS_IS_OK(result
) &&
3895 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3898 for (j
=0; j
<alias
->num_members
; j
++)
3899 DEBUG(1, ("%s\\%s (%d); ",
3900 domains
[j
] ? domains
[j
] : "*unknown*",
3901 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3905 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3907 return NT_STATUS_OK
;
3911 * Fetch a list of all server aliases and their members into
3915 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3916 const DOM_SID
*domain_sid
,
3917 const char *domain_name
,
3918 struct cli_state
*cli
,
3919 struct rpc_pipe_client
*pipe_hnd
,
3920 TALLOC_CTX
*mem_ctx
,
3925 struct policy_handle connect_pol
;
3927 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3929 MAXIMUM_ALLOWED_ACCESS
,
3932 if (!NT_STATUS_IS_OK(result
))
3935 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3936 &global_sid_Builtin
);
3938 if (!NT_STATUS_IS_OK(result
))
3941 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3944 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
3949 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
3951 token
->num_sids
= 4;
3953 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
3954 d_fprintf(stderr
, "malloc failed\n");
3955 token
->num_sids
= 0;
3959 token
->user_sids
[0] = *user_sid
;
3960 sid_copy(&token
->user_sids
[1], &global_sid_World
);
3961 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
3962 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
3965 static void free_user_token(NT_USER_TOKEN
*token
)
3967 SAFE_FREE(token
->user_sids
);
3970 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3972 if (is_sid_in_token(token
, sid
))
3975 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
3976 if (!token
->user_sids
) {
3980 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
3982 token
->num_sids
+= 1;
3987 NT_USER_TOKEN token
;
3990 static void dump_user_token(struct user_token
*token
)
3994 d_printf("%s\n", token
->name
);
3996 for (i
=0; i
<token
->token
.num_sids
; i
++) {
3997 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
4001 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4005 for (i
=0; i
<alias
->num_members
; i
++) {
4006 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4013 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4017 for (i
=0; i
<num_server_aliases
; i
++) {
4018 if (is_alias_member(&sid
, &server_aliases
[i
]))
4019 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4024 * We got a user token with all the SIDs we can know about without asking the
4025 * server directly. These are the user and domain group sids. All of these can
4026 * be members of aliases. So scan the list of aliases for each of the SIDs and
4027 * add them to the token.
4030 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4032 int num_global_sids
= token
->num_sids
;
4035 for (i
=0; i
<num_global_sids
; i
++) {
4036 collect_sid_memberships(token
, token
->user_sids
[i
]);
4040 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4042 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4043 enum wbcSidType type
;
4045 struct wbcDomainSid wsid
;
4046 char *sid_str
= NULL
;
4048 uint32_t num_groups
;
4049 gid_t
*groups
= NULL
;
4052 fstr_sprintf(full_name
, "%s%c%s",
4053 domain
, *lp_winbind_separator(), user
);
4055 /* First let's find out the user sid */
4057 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4059 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4060 DEBUG(1, ("winbind could not find %s: %s\n",
4061 full_name
, wbcErrorString(wbc_status
)));
4065 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4066 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4070 if (type
!= SID_NAME_USER
) {
4071 wbcFreeMemory(sid_str
);
4072 DEBUG(1, ("%s is not a user\n", full_name
));
4076 if (!string_to_sid(&user_sid
, sid_str
)) {
4077 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4081 wbcFreeMemory(sid_str
);
4084 init_user_token(token
, &user_sid
);
4086 /* And now the groups winbind knows about */
4088 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4089 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4090 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4091 full_name
, wbcErrorString(wbc_status
)));
4095 for (i
= 0; i
< num_groups
; i
++) {
4096 gid_t gid
= groups
[i
];
4099 wbc_status
= wbcGidToSid(gid
, &wsid
);
4100 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4101 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4102 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4103 wbcFreeMemory(groups
);
4107 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4108 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4109 wbcFreeMemory(groups
);
4113 DEBUG(3, (" %s\n", sid_str
));
4115 string_to_sid(&sid
, sid_str
);
4116 wbcFreeMemory(sid_str
);
4119 add_sid_to_token(token
, &sid
);
4121 wbcFreeMemory(groups
);
4127 * Get a list of all user tokens we want to look at
4130 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4131 struct user_token
**user_tokens
)
4133 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4134 uint32_t i
, num_users
;
4136 struct user_token
*result
;
4137 TALLOC_CTX
*frame
= NULL
;
4139 if (lp_winbind_use_default_domain() &&
4140 (c
->opt_target_workgroup
== NULL
)) {
4141 d_fprintf(stderr
, "winbind use default domain = yes set, "
4142 "please specify a workgroup\n");
4146 /* Send request to winbind daemon */
4148 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4149 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4150 DEBUG(1, ("winbind could not list users: %s\n",
4151 wbcErrorString(wbc_status
)));
4155 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4157 if (result
== NULL
) {
4158 DEBUG(1, ("Could not malloc sid array\n"));
4159 wbcFreeMemory(users
);
4163 frame
= talloc_stackframe();
4164 for (i
=0; i
< num_users
; i
++) {
4165 fstring domain
, user
;
4168 fstrcpy(result
[i
].name
, users
[i
]);
4170 p
= strchr(users
[i
], *lp_winbind_separator());
4172 DEBUG(3, ("%s\n", users
[i
]));
4175 fstrcpy(domain
, c
->opt_target_workgroup
);
4176 fstrcpy(user
, users
[i
]);
4179 fstrcpy(domain
, users
[i
]);
4184 get_user_sids(domain
, user
, &(result
[i
].token
));
4188 wbcFreeMemory(users
);
4190 *num_tokens
= num_users
;
4191 *user_tokens
= result
;
4196 static bool get_user_tokens_from_file(FILE *f
,
4198 struct user_token
**tokens
)
4200 struct user_token
*token
= NULL
;
4205 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4209 if (line
[strlen(line
)-1] == '\n')
4210 line
[strlen(line
)-1] = '\0';
4212 if (line
[0] == ' ') {
4216 if(!string_to_sid(&sid
, &line
[1])) {
4217 DEBUG(1,("get_user_tokens_from_file: Could "
4218 "not convert sid %s \n",&line
[1]));
4222 if (token
== NULL
) {
4223 DEBUG(0, ("File does not begin with username"));
4227 add_sid_to_token(&token
->token
, &sid
);
4231 /* And a new user... */
4234 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4235 if (*tokens
== NULL
) {
4236 DEBUG(0, ("Could not realloc tokens\n"));
4240 token
= &((*tokens
)[*num_tokens
-1]);
4242 fstrcpy(token
->name
, line
);
4243 token
->token
.num_sids
= 0;
4244 token
->token
.user_sids
= NULL
;
4253 * Show the list of all users that have access to a share
4256 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4257 TALLOC_CTX
*mem_ctx
,
4258 const char *netname
,
4260 struct user_token
*tokens
)
4263 SEC_DESC
*share_sd
= NULL
;
4264 SEC_DESC
*root_sd
= NULL
;
4265 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4267 union srvsvc_NetShareInfo info
;
4272 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4279 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4280 DEBUG(1, ("Coult not query secdesc for share %s\n",
4285 share_sd
= info
.info502
->sd_buf
.sd
;
4286 if (share_sd
== NULL
) {
4287 DEBUG(1, ("Got no secdesc for share %s\n",
4293 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4297 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4300 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4303 for (i
=0; i
<num_tokens
; i
++) {
4306 if (share_sd
!= NULL
) {
4307 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4310 if (!NT_STATUS_IS_OK(status
)) {
4311 DEBUG(1, ("Could not check share_sd for "
4318 if (root_sd
== NULL
) {
4319 d_printf(" %s\n", tokens
[i
].name
);
4323 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4325 if (!NT_STATUS_IS_OK(status
)) {
4326 DEBUG(1, ("Could not check root_sd for user %s\n",
4330 d_printf(" %s\n", tokens
[i
].name
);
4334 cli_close(cli
, fnum
);
4346 static void collect_share(const char *name
, uint32 m
,
4347 const char *comment
, void *state
)
4349 struct share_list
*share_list
= (struct share_list
*)state
;
4351 if (m
!= STYPE_DISKTREE
)
4354 share_list
->num_shares
+= 1;
4355 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4356 if (!share_list
->shares
) {
4357 share_list
->num_shares
= 0;
4360 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4364 * List shares on a remote RPC server, including the security descriptors.
4366 * All parameters are provided by the run_rpc_command function, except for
4367 * argc, argv which are passed through.
4369 * @param domain_sid The domain sid acquired from the remote server.
4370 * @param cli A cli_state connected to the server.
4371 * @param mem_ctx Talloc context, destroyed on completion of the function.
4372 * @param argc Standard main() style argc.
4373 * @param argv Standard main() style argv. Initial components are already
4376 * @return Normal NTSTATUS return.
4379 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4380 const DOM_SID
*domain_sid
,
4381 const char *domain_name
,
4382 struct cli_state
*cli
,
4383 struct rpc_pipe_client
*pipe_hnd
,
4384 TALLOC_CTX
*mem_ctx
,
4393 struct user_token
*tokens
= NULL
;
4396 struct share_list share_list
;
4401 f
= fopen(argv
[0], "r");
4405 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4406 return NT_STATUS_UNSUCCESSFUL
;
4409 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4415 DEBUG(0, ("Could not read users from file\n"));
4416 return NT_STATUS_UNSUCCESSFUL
;
4419 for (i
=0; i
<num_tokens
; i
++)
4420 collect_alias_memberships(&tokens
[i
].token
);
4422 share_list
.num_shares
= 0;
4423 share_list
.shares
= NULL
;
4425 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4428 DEBUG(0, ("Error returning browse list: %s\n",
4433 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4434 char *netname
= share_list
.shares
[i
];
4436 if (netname
[strlen(netname
)-1] == '$')
4439 d_printf("%s\n", netname
);
4441 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4442 num_tokens
, tokens
);
4445 for (i
=0; i
<num_tokens
; i
++) {
4446 free_user_token(&tokens
[i
].token
);
4449 SAFE_FREE(share_list
.shares
);
4451 return NT_STATUS_OK
;
4454 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4459 if (c
->display_usage
) {
4461 "net rpc share allowedusers\n"
4462 " List allowed users\n");
4466 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4467 rpc_aliaslist_internals
,
4472 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4478 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4479 rpc_share_allowedusers_internals
,
4483 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4486 struct user_token
*tokens
= NULL
;
4490 net_usersidlist_usage(c
, argc
, argv
);
4494 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4495 DEBUG(0, ("Could not get the user/sid list\n"));
4499 for (i
=0; i
<num_tokens
; i
++) {
4500 dump_user_token(&tokens
[i
]);
4501 free_user_token(&tokens
[i
].token
);
4508 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4510 d_printf("net usersidlist\n"
4511 "\tprints out a list of all users the running winbind knows\n"
4512 "\tabout, together with all their SIDs. This is used as\n"
4513 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4515 net_common_flags_usage(c
, argc
, argv
);
4520 * 'net rpc share' entrypoint.
4521 * @param argc Standard main() style argc.
4522 * @param argv Standard main() style argv. Initial components are already
4526 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4528 NET_API_STATUS status
;
4530 struct functable func
[] = {
4536 "net rpc share add\n"
4544 "net rpc share delete\n"
4549 rpc_share_allowedusers
,
4551 "Modify allowed users",
4552 "net rpc share allowedusers\n"
4553 " Modify allowed users"
4559 "Migrate share to local server",
4560 "net rpc share migrate\n"
4561 " Migrate share to local server"
4568 "net rpc share list\n"
4571 {NULL
, NULL
, 0, NULL
, NULL
}
4574 status
= libnetapi_init(&c
->netapi_ctx
);
4578 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4579 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4580 if (c
->opt_kerberos
) {
4581 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4585 if (c
->display_usage
) {
4589 " Alias for net rpc share list\n");
4590 net_display_usage_from_functable(func
);
4594 return rpc_share_list(c
, argc
, argv
);
4597 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4600 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4601 TALLOC_CTX
*mem_ctx
,
4602 struct rpc_sh_ctx
*ctx
,
4603 struct rpc_pipe_client
*pipe_hnd
,
4604 int argc
, const char **argv
)
4607 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4610 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4611 TALLOC_CTX
*mem_ctx
,
4612 struct rpc_sh_ctx
*ctx
,
4613 struct rpc_pipe_client
*pipe_hnd
,
4614 int argc
, const char **argv
)
4616 NET_API_STATUS status
;
4617 uint32_t parm_err
= 0;
4618 struct SHARE_INFO_2 i2
;
4620 if ((argc
< 2) || (argc
> 3)) {
4621 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4623 return NT_STATUS_INVALID_PARAMETER
;
4626 i2
.shi2_netname
= argv
[0];
4627 i2
.shi2_type
= STYPE_DISKTREE
;
4628 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4629 i2
.shi2_permissions
= 0;
4630 i2
.shi2_max_uses
= 0;
4631 i2
.shi2_current_uses
= 0;
4632 i2
.shi2_path
= argv
[1];
4633 i2
.shi2_passwd
= NULL
;
4635 status
= NetShareAdd(pipe_hnd
->desthost
,
4640 return werror_to_ntstatus(W_ERROR(status
));
4643 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4644 TALLOC_CTX
*mem_ctx
,
4645 struct rpc_sh_ctx
*ctx
,
4646 struct rpc_pipe_client
*pipe_hnd
,
4647 int argc
, const char **argv
)
4650 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4651 return NT_STATUS_INVALID_PARAMETER
;
4654 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4657 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4658 TALLOC_CTX
*mem_ctx
,
4659 struct rpc_sh_ctx
*ctx
,
4660 struct rpc_pipe_client
*pipe_hnd
,
4661 int argc
, const char **argv
)
4663 union srvsvc_NetShareInfo info
;
4668 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4669 return NT_STATUS_INVALID_PARAMETER
;
4672 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4678 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4682 d_printf("Name: %s\n", info
.info2
->name
);
4683 d_printf("Comment: %s\n", info
.info2
->comment
);
4684 d_printf("Path: %s\n", info
.info2
->path
);
4685 d_printf("Password: %s\n", info
.info2
->password
);
4688 return werror_to_ntstatus(result
);
4691 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4692 struct rpc_sh_ctx
*ctx
)
4694 static struct rpc_sh_cmd cmds
[] = {
4696 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4697 "List available shares" },
4699 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4702 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4705 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4706 "Get information about a share" },
4708 { NULL
, NULL
, 0, NULL
, NULL
}
4714 /****************************************************************************/
4716 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4718 return net_file_usage(c
, argc
, argv
);
4722 * Close a file on a remote RPC server.
4724 * @param argc Standard main() style argc.
4725 * @param argv Standard main() style argv. Initial components are already
4728 * @return A shell status integer (0 for success).
4730 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4732 if (argc
< 1 || c
->display_usage
) {
4733 return rpc_file_usage(c
, argc
, argv
);
4736 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4740 * Formatted print of open file info
4742 * @param r struct FILE_INFO_3 contents
4745 static void display_file_info_3(struct FILE_INFO_3
*r
)
4747 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4748 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4749 r
->fi3_num_locks
, r
->fi3_pathname
);
4753 * List files for a user on a remote RPC server.
4755 * @param argc Standard main() style argc.
4756 * @param argv Standard main() style argv. Initial components are already
4759 * @return A shell status integer (0 for success)..
4762 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4764 NET_API_STATUS status
;
4765 uint32 preferred_len
= 0xffffffff, i
;
4766 const char *username
=NULL
;
4767 uint32_t total_entries
= 0;
4768 uint32_t entries_read
= 0;
4769 uint32_t resume_handle
= 0;
4770 struct FILE_INFO_3
*i3
= NULL
;
4772 if (c
->display_usage
) {
4773 return rpc_file_usage(c
, argc
, argv
);
4776 /* if argc > 0, must be user command */
4778 username
= smb_xstrdup(argv
[0]);
4781 status
= NetFileEnum(c
->opt_host
,
4785 (uint8_t **)(void *)&i3
,
4795 /* Display results */
4798 "\nEnumerating open files on remote server:\n\n"
4799 "\nFileId Opened by Perms Locks Path"
4800 "\n------ --------- ----- ----- ---- \n");
4801 for (i
= 0; i
< entries_read
; i
++) {
4802 display_file_info_3(&i3
[i
]);
4809 * 'net rpc file' entrypoint.
4810 * @param argc Standard main() style argc.
4811 * @param argv Standard main() style argv. Initial components are already
4815 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4817 NET_API_STATUS status
;
4819 struct functable func
[] = {
4824 "Close opened file",
4825 "net rpc file close\n"
4826 " Close opened file"
4832 "List files opened by user",
4833 "net rpc file user\n"
4834 " List files opened by user"
4841 "Display information about opened file",
4842 "net rpc file info\n"
4843 " Display information about opened file"
4846 {NULL
, NULL
, 0, NULL
, NULL
}
4849 status
= libnetapi_init(&c
->netapi_ctx
);
4853 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4854 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4855 if (c
->opt_kerberos
) {
4856 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4860 if (c
->display_usage
) {
4861 d_printf("Usage:\n");
4862 d_printf("net rpc file\n"
4863 " List opened files\n");
4864 net_display_usage_from_functable(func
);
4868 return rpc_file_user(c
, argc
, argv
);
4871 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4875 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4877 * All parameters are provided by the run_rpc_command function, except for
4878 * argc, argv which are passed through.
4880 * @param c A net_context structure.
4881 * @param domain_sid The domain sid acquired from the remote server.
4882 * @param cli A cli_state connected to the server.
4883 * @param mem_ctx Talloc context, destroyed on completion of the function.
4884 * @param argc Standard main() style argc.
4885 * @param argv Standard main() style argv. Initial components are already
4888 * @return Normal NTSTATUS return.
4891 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4892 const DOM_SID
*domain_sid
,
4893 const char *domain_name
,
4894 struct cli_state
*cli
,
4895 struct rpc_pipe_client
*pipe_hnd
,
4896 TALLOC_CTX
*mem_ctx
,
4900 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4902 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4904 if (NT_STATUS_IS_OK(result
)) {
4905 d_printf("\nShutdown successfully aborted\n");
4906 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4908 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4914 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
4916 * All parameters are provided by the run_rpc_command function, except for
4917 * argc, argv which are passed through.
4919 * @param c A net_context structure.
4920 * @param domain_sid The domain sid acquired from the remote server.
4921 * @param cli A cli_state connected to the server.
4922 * @param mem_ctx Talloc context, destroyed on completion of the function.
4923 * @param argc Standard main() style argc.
4924 * @param argv Standard main() style argv. Initial components are already
4927 * @return Normal NTSTATUS return.
4930 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
4931 const DOM_SID
*domain_sid
,
4932 const char *domain_name
,
4933 struct cli_state
*cli
,
4934 struct rpc_pipe_client
*pipe_hnd
,
4935 TALLOC_CTX
*mem_ctx
,
4939 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4941 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4943 if (NT_STATUS_IS_OK(result
)) {
4944 d_printf("\nShutdown successfully aborted\n");
4945 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4947 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
4953 * ABORT the shutdown of a remote RPC server.
4955 * @param argc Standard main() style argc.
4956 * @param argv Standard main() style argv. Initial components are already
4959 * @return A shell status integer (0 for success).
4962 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
4967 if (c
->display_usage
) {
4969 "net rpc abortshutdown\n"
4970 " Abort a scheduled shutdown\n");
4974 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
4975 rpc_shutdown_abort_internals
, argc
, argv
);
4980 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
4982 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
4983 rpc_reg_shutdown_abort_internals
,
4988 * Shut down a remote RPC Server via initshutdown pipe.
4990 * All parameters are provided by the run_rpc_command function, except for
4991 * argc, argv which are passed through.
4993 * @param c A net_context structure.
4994 * @param domain_sid The domain sid acquired from the remote server.
4995 * @param cli A cli_state connected to the server.
4996 * @param mem_ctx Talloc context, destroyed on completion of the function.
4997 * @param argc Standard main() style argc.
4998 * @param argv Standard main() style argv. Initial components are already
5001 * @return Normal NTSTATUS return.
5004 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5005 const DOM_SID
*domain_sid
,
5006 const char *domain_name
,
5007 struct cli_state
*cli
,
5008 struct rpc_pipe_client
*pipe_hnd
,
5009 TALLOC_CTX
*mem_ctx
,
5013 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5014 const char *msg
= "This machine will be shutdown shortly";
5015 uint32 timeout
= 20;
5016 struct lsa_StringLarge msg_string
;
5018 if (c
->opt_comment
) {
5019 msg
= c
->opt_comment
;
5021 if (c
->opt_timeout
) {
5022 timeout
= c
->opt_timeout
;
5025 msg_string
.string
= msg
;
5027 /* create an entry */
5028 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5029 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5032 if (NT_STATUS_IS_OK(result
)) {
5033 d_printf("\nShutdown of remote machine succeeded\n");
5034 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5036 DEBUG(1,("Shutdown of remote machine failed!\n"));
5042 * Shut down a remote RPC Server via winreg pipe.
5044 * All parameters are provided by the run_rpc_command function, except for
5045 * argc, argv which are passed through.
5047 * @param c A net_context structure.
5048 * @param domain_sid The domain sid acquired from the remote server.
5049 * @param cli A cli_state connected to the server.
5050 * @param mem_ctx Talloc context, destroyed on completion of the function.
5051 * @param argc Standard main() style argc.
5052 * @param argv Standard main() style argv. Initial components are already
5055 * @return Normal NTSTATUS return.
5058 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5059 const DOM_SID
*domain_sid
,
5060 const char *domain_name
,
5061 struct cli_state
*cli
,
5062 struct rpc_pipe_client
*pipe_hnd
,
5063 TALLOC_CTX
*mem_ctx
,
5067 const char *msg
= "This machine will be shutdown shortly";
5068 uint32 timeout
= 20;
5069 struct lsa_StringLarge msg_string
;
5073 if (c
->opt_comment
) {
5074 msg
= c
->opt_comment
;
5076 msg_string
.string
= msg
;
5078 if (c
->opt_timeout
) {
5079 timeout
= c
->opt_timeout
;
5082 /* create an entry */
5083 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5084 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5087 if (NT_STATUS_IS_OK(result
)) {
5088 d_printf("\nShutdown of remote machine succeeded\n");
5090 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5091 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5092 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5094 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5101 * Shut down a remote RPC server.
5103 * @param argc Standard main() style argc.
5104 * @param argv Standard main() style argv. Initial components are already
5107 * @return A shell status integer (0 for success).
5110 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5114 if (c
->display_usage
) {
5116 "net rpc shutdown\n"
5117 " Shut down a remote RPC server\n");
5121 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5122 rpc_init_shutdown_internals
, argc
, argv
);
5125 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5126 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5127 rpc_reg_shutdown_internals
, argc
, argv
);
5133 /***************************************************************************
5134 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5135 ***************************************************************************/
5138 * Add interdomain trust account to the RPC server.
5139 * All parameters (except for argc and argv) are passed by run_rpc_command
5142 * @param c A net_context structure.
5143 * @param domain_sid The domain sid acquired from the server.
5144 * @param cli A cli_state connected to the server.
5145 * @param mem_ctx Talloc context, destroyed on completion of the function.
5146 * @param argc Standard main() style argc.
5147 * @param argv Standard main() style argv. Initial components are already
5150 * @return normal NTSTATUS return code.
5153 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5154 const DOM_SID
*domain_sid
,
5155 const char *domain_name
,
5156 struct cli_state
*cli
,
5157 struct rpc_pipe_client
*pipe_hnd
,
5158 TALLOC_CTX
*mem_ctx
,
5162 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5163 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5165 struct lsa_String lsa_acct_name
;
5167 uint32 acct_flags
=0;
5169 uint32_t access_granted
= 0;
5170 union samr_UserInfo info
;
5171 unsigned int orig_timeout
;
5174 d_printf("Usage: net rpc trustdom add <domain_name> "
5175 "<trust password>\n");
5176 return NT_STATUS_INVALID_PARAMETER
;
5180 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5183 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5184 return NT_STATUS_NO_MEMORY
;
5187 strupper_m(acct_name
);
5189 init_lsa_String(&lsa_acct_name
, acct_name
);
5191 /* Get samr policy handle */
5192 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5194 MAXIMUM_ALLOWED_ACCESS
,
5196 if (!NT_STATUS_IS_OK(result
)) {
5200 /* Get domain policy handle */
5201 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5203 MAXIMUM_ALLOWED_ACCESS
,
5204 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5206 if (!NT_STATUS_IS_OK(result
)) {
5210 /* This call can take a long time - allow the server to time out.
5211 * 35 seconds should do it. */
5213 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5215 /* Create trusting domain's account */
5216 acb_info
= ACB_NORMAL
;
5217 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5218 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5219 SAMR_USER_ACCESS_SET_PASSWORD
|
5220 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5221 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5223 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5232 /* And restore our original timeout. */
5233 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5235 if (!NT_STATUS_IS_OK(result
)) {
5236 d_printf("net rpc trustdom add: create user %s failed %s\n",
5237 acct_name
, nt_errstr(result
));
5242 struct samr_CryptPassword crypt_pwd
;
5244 ZERO_STRUCT(info
.info23
);
5246 init_samr_CryptPassword(argv
[1],
5247 &cli
->user_session_key
,
5250 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5251 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5252 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5253 info
.info23
.password
= crypt_pwd
;
5255 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5260 if (!NT_STATUS_IS_OK(result
)) {
5261 DEBUG(0,("Could not set trust account password: %s\n",
5262 nt_errstr(result
)));
5268 SAFE_FREE(acct_name
);
5273 * Create interdomain trust account for a remote domain.
5275 * @param argc Standard argc.
5276 * @param argv Standard argv without initial components.
5278 * @return Integer status (0 means success).
5281 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5283 if (argc
> 0 && !c
->display_usage
) {
5284 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5285 rpc_trustdom_add_internals
, argc
, argv
);
5288 "net rpc trustdom add <domain_name> <trust password>\n");
5295 * Remove interdomain trust account from the RPC server.
5296 * All parameters (except for argc and argv) are passed by run_rpc_command
5299 * @param c A net_context structure.
5300 * @param domain_sid The domain sid acquired from the server.
5301 * @param cli A cli_state connected to the server.
5302 * @param mem_ctx Talloc context, destroyed on completion of the function.
5303 * @param argc Standard main() style argc.
5304 * @param argv Standard main() style argv. Initial components are already
5307 * @return normal NTSTATUS return code.
5310 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5311 const DOM_SID
*domain_sid
,
5312 const char *domain_name
,
5313 struct cli_state
*cli
,
5314 struct rpc_pipe_client
*pipe_hnd
,
5315 TALLOC_CTX
*mem_ctx
,
5319 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5320 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5322 DOM_SID trust_acct_sid
;
5323 struct samr_Ids user_rids
, name_types
;
5324 struct lsa_String lsa_acct_name
;
5327 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5328 return NT_STATUS_INVALID_PARAMETER
;
5332 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5334 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5336 if (acct_name
== NULL
)
5337 return NT_STATUS_NO_MEMORY
;
5339 strupper_m(acct_name
);
5341 /* Get samr policy handle */
5342 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5344 MAXIMUM_ALLOWED_ACCESS
,
5346 if (!NT_STATUS_IS_OK(result
)) {
5350 /* Get domain policy handle */
5351 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5353 MAXIMUM_ALLOWED_ACCESS
,
5354 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5356 if (!NT_STATUS_IS_OK(result
)) {
5360 init_lsa_String(&lsa_acct_name
, acct_name
);
5362 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5369 if (!NT_STATUS_IS_OK(result
)) {
5370 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5371 acct_name
, nt_errstr(result
) );
5375 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5377 MAXIMUM_ALLOWED_ACCESS
,
5381 if (!NT_STATUS_IS_OK(result
)) {
5382 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5383 acct_name
, nt_errstr(result
) );
5387 /* append the rid to the domain sid */
5388 sid_copy(&trust_acct_sid
, domain_sid
);
5389 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5393 /* remove the sid */
5395 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5398 if (!NT_STATUS_IS_OK(result
)) {
5399 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5400 acct_name
, nt_errstr(result
) );
5406 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5409 if (!NT_STATUS_IS_OK(result
)) {
5410 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5411 acct_name
, nt_errstr(result
) );
5415 if (!NT_STATUS_IS_OK(result
)) {
5416 d_printf("Could not set trust account password: %s\n",
5426 * Delete 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_del(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_del_internals
, argc
, argv
);
5441 "net rpc trustdom del <domain>\n");
5446 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5447 struct cli_state
*cli
,
5448 TALLOC_CTX
*mem_ctx
,
5449 const char *domain_name
)
5451 char *dc_name
= NULL
;
5452 const char *buffer
= NULL
;
5453 struct rpc_pipe_client
*netr
;
5456 /* Use NetServerEnum2 */
5458 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5460 return NT_STATUS_OK
;
5463 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5464 for domain %s\n", domain_name
));
5466 /* Try netr_GetDcName */
5468 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5470 if (!NT_STATUS_IS_OK(status
)) {
5474 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5481 if (NT_STATUS_IS_OK(status
)) {
5485 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5486 for domain %s\n", domain_name
));
5492 * Establish trust relationship to a trusting domain.
5493 * Interdomain account must already be created on remote PDC.
5495 * @param c A net_context structure.
5496 * @param argc Standard argc.
5497 * @param argv Standard argv without initial components.
5499 * @return Integer status (0 means success).
5502 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5505 struct cli_state
*cli
= NULL
;
5506 struct sockaddr_storage server_ss
;
5507 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5508 struct policy_handle connect_hnd
;
5509 TALLOC_CTX
*mem_ctx
;
5511 DOM_SID
*domain_sid
;
5516 union lsa_PolicyInformation
*info
= NULL
;
5519 * Connect to \\server\ipc$ as 'our domain' account with password
5522 if (argc
!= 1 || c
->display_usage
) {
5524 "net rpc trustdom establish <domain_name>\n");
5528 domain_name
= smb_xstrdup(argv
[0]);
5529 strupper_m(domain_name
);
5531 /* account name used at first is our domain's name with '$' */
5532 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5535 strupper_m(acct_name
);
5538 * opt_workgroup will be used by connection functions further,
5539 * hence it should be set to remote domain name instead of ours
5541 if (c
->opt_workgroup
) {
5542 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5545 c
->opt_user_name
= acct_name
;
5547 /* find the domain controller */
5548 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5549 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5553 /* connect to ipc$ as username/password */
5554 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5555 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5557 /* Is it trusting domain account for sure ? */
5558 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5559 nt_errstr(nt_status
)));
5563 /* store who we connected to */
5565 saf_store( domain_name
, pdc_name
);
5568 * Connect to \\server\ipc$ again (this time anonymously)
5571 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5574 if (NT_STATUS_IS_ERR(nt_status
)) {
5575 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5576 domain_name
, nt_errstr(nt_status
)));
5580 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5581 "domain %s", domain_name
))) {
5582 DEBUG(0, ("talloc_init() failed\n"));
5587 /* Make sure we're talking to a proper server */
5589 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5590 if (!NT_STATUS_IS_OK(nt_status
)) {
5592 talloc_destroy(mem_ctx
);
5597 * Call LsaOpenPolicy and LsaQueryInfo
5600 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5602 if (!NT_STATUS_IS_OK(nt_status
)) {
5603 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5605 talloc_destroy(mem_ctx
);
5609 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5611 if (NT_STATUS_IS_ERR(nt_status
)) {
5612 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5613 nt_errstr(nt_status
)));
5615 talloc_destroy(mem_ctx
);
5619 /* Querying info level 5 */
5621 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5623 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5625 if (NT_STATUS_IS_ERR(nt_status
)) {
5626 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5627 nt_errstr(nt_status
)));
5629 talloc_destroy(mem_ctx
);
5633 domain_sid
= info
->account_domain
.sid
;
5635 /* There should be actually query info level 3 (following nt serv behaviour),
5636 but I still don't know if it's _really_ necessary */
5639 * Store the password in secrets db
5642 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5643 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5645 talloc_destroy(mem_ctx
);
5650 * Close the pipes and clean up
5653 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5654 if (NT_STATUS_IS_ERR(nt_status
)) {
5655 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5656 nt_errstr(nt_status
)));
5658 talloc_destroy(mem_ctx
);
5664 talloc_destroy(mem_ctx
);
5666 d_printf("Trust to domain %s established\n", domain_name
);
5671 * Revoke trust relationship to the remote domain.
5673 * @param c A net_context structure.
5674 * @param argc Standard argc.
5675 * @param argv Standard argv without initial components.
5677 * @return Integer status (0 means success).
5680 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5686 if (argc
< 1 || c
->display_usage
) {
5688 "net rpc trustdom revoke <domain_name>\n"
5689 " Revoke trust relationship\n"
5690 " domain_name\tName of domain to revoke trust\n");
5694 /* generate upper cased domain name */
5695 domain_name
= smb_xstrdup(argv
[0]);
5696 strupper_m(domain_name
);
5698 /* delete password of the trust */
5699 if (!pdb_del_trusteddom_pw(domain_name
)) {
5700 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5707 SAFE_FREE(domain_name
);
5711 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5712 const DOM_SID
*domain_sid
,
5713 const char *domain_name
,
5714 struct cli_state
*cli
,
5715 struct rpc_pipe_client
*pipe_hnd
,
5716 TALLOC_CTX
*mem_ctx
,
5721 sid_to_fstring(str_sid
, domain_sid
);
5722 d_printf("%s\n", str_sid
);
5723 return NT_STATUS_OK
;
5726 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5728 fstring ascii_sid
, padding
;
5729 int pad_len
, col_len
= 20;
5731 /* convert sid into ascii string */
5732 sid_to_fstring(ascii_sid
, dom_sid
);
5734 /* calculate padding space for d_printf to look nicer */
5735 pad_len
= col_len
- strlen(trusted_dom_name
);
5736 padding
[pad_len
] = 0;
5737 do padding
[--pad_len
] = ' '; while (pad_len
);
5739 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5742 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5743 TALLOC_CTX
*mem_ctx
,
5744 struct policy_handle
*pol
,
5746 const char *trusted_dom_name
)
5749 union lsa_TrustedDomainInfo
*info
= NULL
;
5750 char *cleartextpwd
= NULL
;
5751 uint8_t nt_hash
[16];
5752 DATA_BLOB data
= data_blob_null
;
5754 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5757 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5759 if (NT_STATUS_IS_ERR(nt_status
)) {
5760 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5761 nt_errstr(nt_status
)));
5765 data
= data_blob(info
->password
.password
->data
,
5766 info
->password
.password
->length
);
5768 if (!rpccli_get_pwd_hash(pipe_hnd
, nt_hash
)) {
5769 DEBUG(0, ("Could not retrieve password hash\n"));
5773 cleartextpwd
= decrypt_trustdom_secret(nt_hash
, &data
);
5775 if (cleartextpwd
== NULL
) {
5776 DEBUG(0,("retrieved NULL password\n"));
5777 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5781 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5782 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5783 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5787 #ifdef DEBUG_PASSWORD
5788 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5789 "password: [%s]\n", trusted_dom_name
,
5790 sid_string_dbg(&dom_sid
), cleartextpwd
));
5794 SAFE_FREE(cleartextpwd
);
5795 data_blob_free(&data
);
5800 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5803 /* common variables */
5804 TALLOC_CTX
* mem_ctx
;
5805 struct cli_state
*cli
= NULL
;
5806 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5808 const char *domain_name
= NULL
;
5809 DOM_SID
*queried_dom_sid
;
5810 struct policy_handle connect_hnd
;
5811 union lsa_PolicyInformation
*info
= NULL
;
5813 /* trusted domains listing variables */
5814 unsigned int enum_ctx
= 0;
5816 struct lsa_DomainList dom_list
;
5819 if (c
->display_usage
) {
5821 "net rpc trustdom vampire\n"
5822 " Vampire trust relationship from remote server\n");
5827 * Listing trusted domains (stored in secrets.tdb, if local)
5830 mem_ctx
= talloc_init("trust relationships vampire");
5833 * set domain and pdc name to local samba server (default)
5834 * or to remote one given in command line
5837 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5838 domain_name
= c
->opt_workgroup
;
5839 c
->opt_target_workgroup
= c
->opt_workgroup
;
5841 fstrcpy(pdc_name
, global_myname());
5842 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5843 c
->opt_target_workgroup
= domain_name
;
5846 /* open \PIPE\lsarpc and open policy handle */
5847 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5848 if (!NT_STATUS_IS_OK(nt_status
)) {
5849 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5850 nt_errstr(nt_status
)));
5851 talloc_destroy(mem_ctx
);
5855 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5857 if (!NT_STATUS_IS_OK(nt_status
)) {
5858 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5859 nt_errstr(nt_status
) ));
5861 talloc_destroy(mem_ctx
);
5865 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5867 if (NT_STATUS_IS_ERR(nt_status
)) {
5868 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5869 nt_errstr(nt_status
)));
5871 talloc_destroy(mem_ctx
);
5875 /* query info level 5 to obtain sid of a domain being queried */
5876 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5878 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5881 if (NT_STATUS_IS_ERR(nt_status
)) {
5882 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5883 nt_errstr(nt_status
)));
5885 talloc_destroy(mem_ctx
);
5889 queried_dom_sid
= info
->account_domain
.sid
;
5892 * Keep calling LsaEnumTrustdom over opened pipe until
5893 * the end of enumeration is reached
5896 d_printf("Vampire trusted domains:\n\n");
5899 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
5904 if (NT_STATUS_IS_ERR(nt_status
)) {
5905 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5906 nt_errstr(nt_status
)));
5908 talloc_destroy(mem_ctx
);
5912 for (i
= 0; i
< dom_list
.count
; i
++) {
5914 print_trusted_domain(dom_list
.domains
[i
].sid
,
5915 dom_list
.domains
[i
].name
.string
);
5917 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5918 *dom_list
.domains
[i
].sid
,
5919 dom_list
.domains
[i
].name
.string
);
5920 if (!NT_STATUS_IS_OK(nt_status
)) {
5922 talloc_destroy(mem_ctx
);
5928 * in case of no trusted domains say something rather
5929 * than just display blank line
5931 if (!dom_list
.count
) d_printf("none\n");
5933 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5935 /* close this connection before doing next one */
5936 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5937 if (NT_STATUS_IS_ERR(nt_status
)) {
5938 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5939 nt_errstr(nt_status
)));
5941 talloc_destroy(mem_ctx
);
5945 /* close lsarpc pipe and connection to IPC$ */
5948 talloc_destroy(mem_ctx
);
5952 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
5954 /* common variables */
5955 TALLOC_CTX
* mem_ctx
;
5956 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5957 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5959 const char *domain_name
= NULL
;
5960 DOM_SID
*queried_dom_sid
;
5961 int ascii_dom_name_len
;
5962 struct policy_handle connect_hnd
;
5963 union lsa_PolicyInformation
*info
= NULL
;
5965 /* trusted domains listing variables */
5966 unsigned int num_domains
, enum_ctx
= 0;
5968 struct lsa_DomainList dom_list
;
5972 /* trusting domains listing variables */
5973 struct policy_handle domain_hnd
;
5974 struct samr_SamArray
*trusts
= NULL
;
5976 if (c
->display_usage
) {
5978 "net rpc trustdom list\n"
5979 " List trust relationships\n");
5984 * Listing trusted domains (stored in secrets.tdb, if local)
5987 mem_ctx
= talloc_init("trust relationships listing");
5990 * set domain and pdc name to local samba server (default)
5991 * or to remote one given in command line
5994 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5995 domain_name
= c
->opt_workgroup
;
5996 c
->opt_target_workgroup
= c
->opt_workgroup
;
5998 fstrcpy(pdc_name
, global_myname());
5999 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
6000 c
->opt_target_workgroup
= domain_name
;
6003 /* open \PIPE\lsarpc and open policy handle */
6004 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6005 if (!NT_STATUS_IS_OK(nt_status
)) {
6006 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6007 nt_errstr(nt_status
)));
6008 talloc_destroy(mem_ctx
);
6012 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6014 if (!NT_STATUS_IS_OK(nt_status
)) {
6015 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6016 nt_errstr(nt_status
) ));
6018 talloc_destroy(mem_ctx
);
6022 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6024 if (NT_STATUS_IS_ERR(nt_status
)) {
6025 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6026 nt_errstr(nt_status
)));
6028 talloc_destroy(mem_ctx
);
6032 /* query info level 5 to obtain sid of a domain being queried */
6033 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6035 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6038 if (NT_STATUS_IS_ERR(nt_status
)) {
6039 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6040 nt_errstr(nt_status
)));
6042 talloc_destroy(mem_ctx
);
6046 queried_dom_sid
= info
->account_domain
.sid
;
6049 * Keep calling LsaEnumTrustdom over opened pipe until
6050 * the end of enumeration is reached
6053 d_printf("Trusted domains list:\n\n");
6055 found_domain
= false;
6058 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6063 if (NT_STATUS_IS_ERR(nt_status
)) {
6064 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6065 nt_errstr(nt_status
)));
6067 talloc_destroy(mem_ctx
);
6071 for (i
= 0; i
< dom_list
.count
; i
++) {
6072 print_trusted_domain(dom_list
.domains
[i
].sid
,
6073 dom_list
.domains
[i
].name
.string
);
6074 found_domain
= true;
6077 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6080 * in case of no trusted domains say something rather
6081 * than just display blank line
6083 if (!found_domain
) {
6087 /* close this connection before doing next one */
6088 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6089 if (NT_STATUS_IS_ERR(nt_status
)) {
6090 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6091 nt_errstr(nt_status
)));
6093 talloc_destroy(mem_ctx
);
6097 TALLOC_FREE(pipe_hnd
);
6100 * Listing trusting domains (stored in passdb backend, if local)
6103 d_printf("\nTrusting domains list:\n\n");
6106 * Open \PIPE\samr and get needed policy handles
6108 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6110 if (!NT_STATUS_IS_OK(nt_status
)) {
6111 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6113 talloc_destroy(mem_ctx
);
6118 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6120 SAMR_ACCESS_LOOKUP_DOMAIN
,
6122 if (!NT_STATUS_IS_OK(nt_status
)) {
6123 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6124 nt_errstr(nt_status
)));
6126 talloc_destroy(mem_ctx
);
6130 /* SamrOpenDomain - we have to open domain policy handle in order to be
6131 able to enumerate accounts*/
6132 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6134 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6137 if (!NT_STATUS_IS_OK(nt_status
)) {
6138 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6139 nt_errstr(nt_status
)));
6141 talloc_destroy(mem_ctx
);
6146 * perform actual enumeration
6149 found_domain
= false;
6151 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6154 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6161 if (NT_STATUS_IS_ERR(nt_status
)) {
6162 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6163 nt_errstr(nt_status
)));
6165 talloc_destroy(mem_ctx
);
6169 for (i
= 0; i
< num_domains
; i
++) {
6171 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6173 found_domain
= true;
6176 * get each single domain's sid (do we _really_ need this ?):
6177 * 1) connect to domain's pdc
6178 * 2) query the pdc for domain's sid
6181 /* get rid of '$' tail */
6182 ascii_dom_name_len
= strlen(str
);
6183 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6184 str
[ascii_dom_name_len
- 1] = '\0';
6186 /* set opt_* variables to remote domain */
6188 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6189 c
->opt_target_workgroup
= c
->opt_workgroup
;
6191 d_printf("%-20s", str
);
6193 /* connect to remote domain controller */
6194 nt_status
= net_make_ipc_connection(c
,
6195 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6197 if (NT_STATUS_IS_OK(nt_status
)) {
6198 /* query for domain's sid */
6199 if (run_rpc_command(
6201 &ndr_table_lsarpc
.syntax_id
, 0,
6202 rpc_query_domain_sid
, argc
,
6204 d_fprintf(stderr
, "couldn't get domain's sid\n");
6206 cli_shutdown(remote_cli
);
6209 d_fprintf(stderr
, "domain controller is not "
6211 nt_errstr(nt_status
));
6215 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6217 if (!found_domain
) {
6221 /* close opened samr and domain policy handles */
6222 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6223 if (!NT_STATUS_IS_OK(nt_status
)) {
6224 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6227 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6228 if (!NT_STATUS_IS_OK(nt_status
)) {
6229 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6232 /* close samr pipe and connection to IPC$ */
6235 talloc_destroy(mem_ctx
);
6240 * Entrypoint for 'net rpc trustdom' code.
6242 * @param argc Standard argc.
6243 * @param argv Standard argv without initial components.
6245 * @return Integer status (0 means success).
6248 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6250 struct functable func
[] = {
6255 "Add trusted domain's account",
6256 "net rpc trustdom add\n"
6257 " Add trusted domain's account"
6263 "Remove trusted domain's account",
6264 "net rpc trustdom del\n"
6265 " Remove trusted domain's account"
6269 rpc_trustdom_establish
,
6271 "Establish trust relationship",
6272 "net rpc trustdom establish\n"
6273 " Establish trust relationship"
6277 rpc_trustdom_revoke
,
6279 "Revoke trust relationship",
6280 "net rpc trustdom revoke\n"
6281 " Revoke trust relationship"
6287 "List domain trusts",
6288 "net rpc trustdom list\n"
6289 " List domain trusts"
6293 rpc_trustdom_vampire
,
6295 "Vampire trusts from remote server",
6296 "net rpc trustdom vampire\n"
6297 " Vampire trusts from remote server"
6299 {NULL
, NULL
, 0, NULL
, NULL
}
6302 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6306 * Check if a server will take rpc commands
6307 * @param flags Type of server to connect to (PDC, DMB, localhost)
6308 * if the host is not explicitly specified
6309 * @return bool (true means rpc supported)
6311 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6313 struct cli_state
*cli
;
6315 struct sockaddr_storage server_ss
;
6316 char *server_name
= NULL
;
6319 /* flags (i.e. server type) may depend on command */
6320 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6323 if ((cli
= cli_initialise()) == NULL
) {
6327 status
= cli_connect(cli
, server_name
, &server_ss
);
6328 if (!NT_STATUS_IS_OK(status
))
6330 if (!attempt_netbios_session_request(&cli
, global_myname(),
6331 server_name
, &server_ss
))
6333 status
= cli_negprot(cli
);
6334 if (!NT_STATUS_IS_OK(status
))
6336 if (cli
->protocol
< PROTOCOL_NT1
)
6345 /* dump sam database via samsync rpc calls */
6346 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6347 if (c
->display_usage
) {
6350 " Dump remote SAM database\n");
6354 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6355 NET_FLAGS_ANONYMOUS
,
6356 rpc_samdump_internals
, argc
, argv
);
6359 /* syncronise sam database via samsync rpc calls */
6360 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6362 struct functable func
[] = {
6367 "Dump remote SAM database to ldif",
6368 "net rpc vampire ldif\n"
6369 " Dump remote SAM database to LDIF file or stdout"
6375 "Dump remote SAM database to Kerberos Keytab",
6376 "net rpc vampire keytab\n"
6377 " Dump remote SAM database to Kerberos keytab file"
6383 "Dump remote SAM database to passdb",
6384 "net rpc vampire passdb\n"
6385 " Dump remote SAM database to passdb"
6388 {NULL
, NULL
, 0, NULL
, NULL
}
6392 if (c
->display_usage
) {
6395 " Vampire remote SAM database\n");
6399 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6400 NET_FLAGS_ANONYMOUS
,
6401 rpc_vampire_internals
,
6405 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6409 * Migrate everything from a print server.
6411 * @param c A net_context structure.
6412 * @param argc Standard main() style argc.
6413 * @param argv Standard main() style argv. Initial components are already
6416 * @return A shell status integer (0 for success).
6418 * The order is important !
6419 * To successfully add drivers the print queues have to exist !
6420 * Applying ACLs should be the last step, because you're easily locked out.
6423 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6428 if (c
->display_usage
) {
6430 "net rpc printer migrate all\n"
6431 " Migrate everything from a print server\n");
6436 d_printf("no server to migrate\n");
6440 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6441 rpc_printer_migrate_printers_internals
, argc
,
6446 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6447 rpc_printer_migrate_drivers_internals
, argc
,
6452 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6453 rpc_printer_migrate_forms_internals
, argc
, argv
);
6457 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6458 rpc_printer_migrate_settings_internals
, argc
,
6463 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6464 rpc_printer_migrate_security_internals
, argc
,
6470 * Migrate print drivers from a print server.
6472 * @param c A net_context structure.
6473 * @param argc Standard main() style argc.
6474 * @param argv Standard main() style argv. Initial components are already
6477 * @return A shell status integer (0 for success).
6479 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6482 if (c
->display_usage
) {
6484 "net rpc printer migrate drivers\n"
6485 " Migrate print-drivers from a print-server\n");
6490 d_printf("no server to migrate\n");
6494 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6495 rpc_printer_migrate_drivers_internals
,
6500 * Migrate print-forms from a print-server.
6502 * @param c A net_context structure.
6503 * @param argc Standard main() style argc.
6504 * @param argv Standard main() style argv. Initial components are already
6507 * @return A shell status integer (0 for success).
6509 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6512 if (c
->display_usage
) {
6514 "net rpc printer migrate forms\n"
6515 " Migrate print-forms from a print-server\n");
6520 d_printf("no server to migrate\n");
6524 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6525 rpc_printer_migrate_forms_internals
,
6530 * Migrate printers from a print-server.
6532 * @param c A net_context structure.
6533 * @param argc Standard main() style argc.
6534 * @param argv Standard main() style argv. Initial components are already
6537 * @return A shell status integer (0 for success).
6539 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6542 if (c
->display_usage
) {
6544 "net rpc printer migrate printers\n"
6545 " Migrate printers from a print-server\n");
6550 d_printf("no server to migrate\n");
6554 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6555 rpc_printer_migrate_printers_internals
,
6560 * Migrate printer-ACLs from a print-server
6562 * @param c A net_context structure.
6563 * @param argc Standard main() style argc.
6564 * @param argv Standard main() style argv. Initial components are already
6567 * @return A shell status integer (0 for success).
6569 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6572 if (c
->display_usage
) {
6574 "net rpc printer migrate security\n"
6575 " Migrate printer-ACLs from a print-server\n");
6580 d_printf("no server to migrate\n");
6584 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6585 rpc_printer_migrate_security_internals
,
6590 * Migrate printer-settings from a print-server.
6592 * @param c A net_context structure.
6593 * @param argc Standard main() style argc.
6594 * @param argv Standard main() style argv. Initial components are already
6597 * @return A shell status integer (0 for success).
6599 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6602 if (c
->display_usage
) {
6604 "net rpc printer migrate settings\n"
6605 " Migrate printer-settings from a print-server\n");
6610 d_printf("no server to migrate\n");
6614 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6615 rpc_printer_migrate_settings_internals
,
6620 * 'net rpc printer' entrypoint.
6622 * @param c A net_context structure.
6623 * @param argc Standard main() style argc.
6624 * @param argv Standard main() style argv. Initial components are already
6628 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6631 /* ouch: when addriver and setdriver are called from within
6632 rpc_printer_migrate_drivers_internals, the printer-queue already
6635 struct functable func
[] = {
6638 rpc_printer_migrate_all
,
6640 "Migrate all from remote to local print server",
6641 "net rpc printer migrate all\n"
6642 " Migrate all from remote to local print server"
6646 rpc_printer_migrate_drivers
,
6648 "Migrate drivers to local server",
6649 "net rpc printer migrate drivers\n"
6650 " Migrate drivers to local server"
6654 rpc_printer_migrate_forms
,
6656 "Migrate froms to local server",
6657 "net rpc printer migrate forms\n"
6658 " Migrate froms to local server"
6662 rpc_printer_migrate_printers
,
6664 "Migrate printers to local server",
6665 "net rpc printer migrate printers\n"
6666 " Migrate printers to local server"
6670 rpc_printer_migrate_security
,
6672 "Mirgate printer ACLs to local server",
6673 "net rpc printer migrate security\n"
6674 " Mirgate printer ACLs to local server"
6678 rpc_printer_migrate_settings
,
6680 "Migrate printer settings to local server",
6681 "net rpc printer migrate settings\n"
6682 " Migrate printer settings to local server"
6684 {NULL
, NULL
, 0, NULL
, NULL
}
6687 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6692 * List printers on a remote RPC server.
6694 * @param c A net_context structure.
6695 * @param argc Standard main() style argc.
6696 * @param argv Standard main() style argv. Initial components are already
6699 * @return A shell status integer (0 for success).
6701 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6703 if (c
->display_usage
) {
6705 "net rpc printer list\n"
6706 " List printers on a remote RPC server\n");
6710 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6711 rpc_printer_list_internals
,
6716 * List printer-drivers on a remote RPC server.
6718 * @param c A net_context structure.
6719 * @param argc Standard main() style argc.
6720 * @param argv Standard main() style argv. Initial components are already
6723 * @return A shell status integer (0 for success).
6725 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6728 if (c
->display_usage
) {
6730 "net rpc printer driver\n"
6731 " List printer-drivers on a remote RPC server\n");
6735 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6736 rpc_printer_driver_list_internals
,
6741 * Publish printer in ADS via MSRPC.
6743 * @param c A net_context structure.
6744 * @param argc Standard main() style argc.
6745 * @param argv Standard main() style argv. Initial components are already
6748 * @return A shell status integer (0 for success).
6750 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6753 if (c
->display_usage
) {
6755 "net rpc printer publish publish\n"
6756 " Publish printer in ADS via MSRPC\n");
6760 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6761 rpc_printer_publish_publish_internals
,
6766 * Update printer in ADS via MSRPC.
6768 * @param c A net_context structure.
6769 * @param argc Standard main() style argc.
6770 * @param argv Standard main() style argv. Initial components are already
6773 * @return A shell status integer (0 for success).
6775 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6777 if (c
->display_usage
) {
6779 "net rpc printer publish update\n"
6780 " Update printer in ADS via MSRPC\n");
6784 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6785 rpc_printer_publish_update_internals
,
6790 * UnPublish printer in ADS via MSRPC.
6792 * @param c A net_context structure.
6793 * @param argc Standard main() style argc.
6794 * @param argv Standard main() style argv. Initial components are already
6797 * @return A shell status integer (0 for success).
6799 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6802 if (c
->display_usage
) {
6804 "net rpc printer publish unpublish\n"
6805 " UnPublish printer in ADS via MSRPC\n");
6809 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6810 rpc_printer_publish_unpublish_internals
,
6815 * List published printers via MSRPC.
6817 * @param c A net_context structure.
6818 * @param argc Standard main() style argc.
6819 * @param argv Standard main() style argv. Initial components are already
6822 * @return A shell status integer (0 for success).
6824 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6827 if (c
->display_usage
) {
6829 "net rpc printer publish list\n"
6830 " List published printers via MSRPC\n");
6834 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6835 rpc_printer_publish_list_internals
,
6841 * Publish printer in ADS.
6843 * @param c A net_context structure.
6844 * @param argc Standard main() style argc.
6845 * @param argv Standard main() style argv. Initial components are already
6848 * @return A shell status integer (0 for success).
6850 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6854 struct functable func
[] = {
6857 rpc_printer_publish_publish
,
6859 "Publish printer in AD",
6860 "net rpc printer publish publish\n"
6861 " Publish printer in AD"
6865 rpc_printer_publish_update
,
6867 "Update printer in AD",
6868 "net rpc printer publish update\n"
6869 " Update printer in AD"
6873 rpc_printer_publish_unpublish
,
6875 "Unpublish printer",
6876 "net rpc printer publish unpublish\n"
6877 " Unpublish printer"
6881 rpc_printer_publish_list
,
6883 "List published printers",
6884 "net rpc printer publish list\n"
6885 " List published printers"
6887 {NULL
, NULL
, 0, NULL
, NULL
}
6891 if (c
->display_usage
) {
6892 d_printf("Usage:\n");
6893 d_printf("net rpc printer publish\n"
6894 " List published printers\n"
6895 " Alias of net rpc printer publish list\n");
6896 net_display_usage_from_functable(func
);
6899 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6900 rpc_printer_publish_list_internals
,
6904 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
6910 * Display rpc printer help page.
6912 * @param c A net_context structure.
6913 * @param argc Standard main() style argc.
6914 * @param argv Standard main() style argv. Initial components are already
6917 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
6919 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
6920 "\tlists all printers on print-server\n\n");
6921 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
6922 "\tlists all printer-drivers on print-server\n\n");
6923 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
6924 "\tpublishes printer settings in Active Directory\n"
6925 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
6926 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
6927 "\n\tmigrates printers from remote to local server\n\n");
6928 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
6929 "\n\tmigrates printer-settings from remote to local server\n\n");
6930 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
6931 "\n\tmigrates printer-drivers from remote to local server\n\n");
6932 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
6933 "\n\tmigrates printer-forms from remote to local server\n\n");
6934 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
6935 "\n\tmigrates printer-ACLs from remote to local server\n\n");
6936 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
6937 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
6938 "\tremote to local print-server\n\n");
6939 net_common_methods_usage(c
, argc
, argv
);
6940 net_common_flags_usage(c
, argc
, argv
);
6942 "\t-v or --verbose\t\t\tgive verbose output\n"
6943 "\t --destination\t\tmigration target server (default: localhost)\n");
6949 * 'net rpc printer' entrypoint.
6951 * @param c A net_context structure.
6952 * @param argc Standard main() style argc.
6953 * @param argv Standard main() style argv. Initial components are already
6956 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
6958 struct functable func
[] = {
6963 "List all printers on print server",
6964 "net rpc printer list\n"
6965 " List all printers on print server"
6969 rpc_printer_migrate
,
6971 "Migrate printer to local server",
6972 "net rpc printer migrate\n"
6973 " Migrate printer to local server"
6977 rpc_printer_driver_list
,
6979 "List printer drivers",
6980 "net rpc printer driver\n"
6981 " List printer drivers"
6985 rpc_printer_publish
,
6987 "Publish printer in AD",
6988 "net rpc printer publish\n"
6989 " Publish printer in AD"
6991 {NULL
, NULL
, 0, NULL
, NULL
}
6995 if (c
->display_usage
) {
6996 d_printf("Usage:\n");
6997 d_printf("net rpc printer\n"
6998 " List printers\n");
6999 net_display_usage_from_functable(func
);
7002 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7003 rpc_printer_list_internals
,
7007 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7011 * 'net rpc' entrypoint.
7013 * @param c A net_context structure.
7014 * @param argc Standard main() style argc.
7015 * @param argv Standard main() style argv. Initial components are already
7019 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7021 NET_API_STATUS status
;
7023 struct functable func
[] = {
7028 "Modify global audit settings",
7030 " Modify global audit settings"
7036 "Show basic info about a domain",
7038 " Show basic info about a domain"
7052 "Join a domain created in server manager",
7054 " Join a domain created in server manager"
7060 "Test that a join is valid",
7061 "net rpc testjoin\n"
7062 " Test that a join is valid"
7068 "List/modify users",
7070 " List/modify users"
7076 "Change a user password",
7077 "net rpc password\n"
7078 " Change a user password\n"
7079 " Alias for net rpc user password"
7085 "List/modify groups",
7087 " List/modify groups"
7093 "List/modify shares",
7095 " List/modify shares"
7109 "List/modify printers",
7111 " List/modify printers"
7115 net_rpc_changetrustpw
,
7117 "Change trust account password",
7118 "net rpc changetrustpw\n"
7119 " Change trust account password"
7125 "Modify domain trusts",
7126 "net rpc trustdom\n"
7127 " Modify domain trusts"
7133 "Abort a remote shutdown",
7134 "net rpc abortshutdown\n"
7135 " Abort a remote shutdown"
7141 "Shutdown a remote server",
7142 "net rpc shutdown\n"
7143 " Shutdown a remote server"
7149 "Dump SAM data of remote NT PDC",
7151 " Dump SAM data of remote NT PDC"
7157 "Sync a remote NT PDC's data into local passdb",
7159 " Sync a remote NT PDC's data into local passdb"
7165 "Fetch the domain sid into local secrets.tdb",
7167 " Fetch the domain sid into local secrets.tdb"
7173 "Manage privileges assigned to SID",
7175 " Manage privileges assigned to SID"
7181 "Start/stop/query remote services",
7183 " Start/stop/query remote services"
7189 "Manage registry hives",
7190 "net rpc registry\n"
7191 " Manage registry hives"
7197 "Open interactive shell on remote server",
7199 " Open interactive shell on remote server"
7201 {NULL
, NULL
, 0, NULL
, NULL
}
7204 status
= libnetapi_init(&c
->netapi_ctx
);
7208 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7209 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7210 if (c
->opt_kerberos
) {
7211 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7214 return net_run_function(c
, argc
, argv
, "net rpc", func
);