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
= getpass(prompt
);
765 status
= NetUserSetInfo(c
->opt_host
, argv
[0], 1003, (uint8_t *)&u1003
, &parm_err
);
767 /* Display results */
769 d_fprintf(stderr
, "Failed to set password for '%s' with: %s.\n",
770 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
779 * List a user's groups from a remote RPC server.
781 * @param argc Standard main() style argc.
782 * @param argv Standard main() style argv. Initial components are already
785 * @return A shell status integer (0 for success)
788 static int rpc_user_info(struct net_context
*c
, int argc
, const char **argv
)
791 NET_API_STATUS status
;
792 struct GROUP_USERS_INFO_0
*u0
= NULL
;
793 uint32_t entries_read
= 0;
794 uint32_t total_entries
= 0;
798 if (argc
< 1 || c
->display_usage
) {
799 rpc_user_usage(c
, argc
, argv
);
803 status
= NetUserGetGroups(c
->opt_host
,
806 (uint8_t **)(void *)&u0
,
811 d_fprintf(stderr
, "Failed to get groups for '%s' with: %s.\n",
812 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
817 for (i
=0; i
< entries_read
; i
++) {
818 printf("%s\n", u0
->grui0_name
);
826 * List users on a remote RPC server.
828 * All parameters are provided by the run_rpc_command function, except for
829 * argc, argv which are passed through.
831 * @param domain_sid The domain sid acquired from the remote server.
832 * @param cli A cli_state connected to the server.
833 * @param mem_ctx Talloc context, destroyed on completion of the function.
834 * @param argc Standard main() style argc.
835 * @param argv Standard main() style argv. Initial components are already
838 * @return Normal NTSTATUS return.
841 static int rpc_user_list(struct net_context
*c
, int argc
, const char **argv
)
843 NET_API_STATUS status
;
844 uint32_t start_idx
=0, num_entries
, i
, loop_count
= 0;
845 struct NET_DISPLAY_USER
*info
= NULL
;
848 /* Query domain users */
849 if (c
->opt_long_list_entries
)
850 d_printf("\nUser name Comment"
851 "\n-----------------------------\n");
853 uint32_t max_entries
, max_size
;
855 get_query_dispinfo_params(
856 loop_count
, &max_entries
, &max_size
);
858 status
= NetQueryDisplayInformation(c
->opt_host
,
865 if (status
!= 0 && status
!= ERROR_MORE_DATA
) {
869 info
= (struct NET_DISPLAY_USER
*)buffer
;
871 for (i
= 0; i
< num_entries
; i
++) {
873 if (c
->opt_long_list_entries
)
874 printf("%-21.21s %s\n", info
->usri1_name
,
875 info
->usri1_comment
);
877 printf("%s\n", info
->usri1_name
);
881 NetApiBufferFree(buffer
);
884 start_idx
+= num_entries
;
886 } while (status
== ERROR_MORE_DATA
);
892 * 'net rpc user' entrypoint.
893 * @param argc Standard main() style argc.
894 * @param argv Standard main() style argv. Initial components are already
898 int net_rpc_user(struct net_context
*c
, int argc
, const char **argv
)
900 NET_API_STATUS status
;
902 struct functable func
[] = {
907 "Add specified user",
909 " Add specified user"
915 "List domain groups of user",
916 "net rpc user info\n"
917 " Lis domain groups of user"
923 "Remove specified user",
924 "net rpc user delete\n"
925 " Remove specified user"
931 "Change user password",
932 "net rpc user password\n"
933 " Change user password"
939 "Rename specified user",
940 "net rpc user rename\n"
941 " Rename specified user"
943 {NULL
, NULL
, 0, NULL
, NULL
}
946 status
= libnetapi_init(&c
->netapi_ctx
);
950 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
951 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
952 if (c
->opt_kerberos
) {
953 libnetapi_set_use_kerberos(c
->netapi_ctx
);
957 if (c
->display_usage
) {
958 d_printf("Usage:\n");
959 d_printf("net rpc user\n"
960 " List all users\n");
961 net_display_usage_from_functable(func
);
965 return rpc_user_list(c
, argc
, argv
);
968 return net_run_function(c
, argc
, argv
, "net rpc user", func
);
971 static NTSTATUS
rpc_sh_user_list(struct net_context
*c
,
973 struct rpc_sh_ctx
*ctx
,
974 struct rpc_pipe_client
*pipe_hnd
,
975 int argc
, const char **argv
)
977 return werror_to_ntstatus(W_ERROR(rpc_user_list(c
, argc
, argv
)));
980 static NTSTATUS
rpc_sh_user_info(struct net_context
*c
,
982 struct rpc_sh_ctx
*ctx
,
983 struct rpc_pipe_client
*pipe_hnd
,
984 int argc
, const char **argv
)
986 return werror_to_ntstatus(W_ERROR(rpc_user_info(c
, argc
, argv
)));
989 static NTSTATUS
rpc_sh_handle_user(struct net_context
*c
,
991 struct rpc_sh_ctx
*ctx
,
992 struct rpc_pipe_client
*pipe_hnd
,
993 int argc
, const char **argv
,
995 struct net_context
*c
,
997 struct rpc_sh_ctx
*ctx
,
998 struct rpc_pipe_client
*pipe_hnd
,
999 struct policy_handle
*user_hnd
,
1000 int argc
, const char **argv
))
1002 struct policy_handle connect_pol
, domain_pol
, user_pol
;
1003 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1006 enum lsa_SidType type
;
1009 d_fprintf(stderr
, "usage: %s <username>\n", ctx
->whoami
);
1010 return NT_STATUS_INVALID_PARAMETER
;
1013 ZERO_STRUCT(connect_pol
);
1014 ZERO_STRUCT(domain_pol
);
1015 ZERO_STRUCT(user_pol
);
1017 result
= net_rpc_lookup_name(c
, mem_ctx
, rpc_pipe_np_smb_conn(pipe_hnd
),
1018 argv
[0], NULL
, NULL
, &sid
, &type
);
1019 if (!NT_STATUS_IS_OK(result
)) {
1020 d_fprintf(stderr
, "Could not lookup %s: %s\n", argv
[0],
1025 if (type
!= SID_NAME_USER
) {
1026 d_fprintf(stderr
, "%s is a %s, not a user\n", argv
[0],
1027 sid_type_lookup(type
));
1028 result
= NT_STATUS_NO_SUCH_USER
;
1032 if (!sid_peek_check_rid(ctx
->domain_sid
, &sid
, &rid
)) {
1033 d_fprintf(stderr
, "%s is not in our domain\n", argv
[0]);
1034 result
= NT_STATUS_NO_SUCH_USER
;
1038 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1040 MAXIMUM_ALLOWED_ACCESS
,
1042 if (!NT_STATUS_IS_OK(result
)) {
1046 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1048 MAXIMUM_ALLOWED_ACCESS
,
1051 if (!NT_STATUS_IS_OK(result
)) {
1055 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1057 MAXIMUM_ALLOWED_ACCESS
,
1060 if (!NT_STATUS_IS_OK(result
)) {
1064 result
= fn(c
, mem_ctx
, ctx
, pipe_hnd
, &user_pol
, argc
-1, argv
+1);
1067 if (is_valid_policy_hnd(&user_pol
)) {
1068 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1070 if (is_valid_policy_hnd(&domain_pol
)) {
1071 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
1073 if (is_valid_policy_hnd(&connect_pol
)) {
1074 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1079 static NTSTATUS
rpc_sh_user_show_internals(struct net_context
*c
,
1080 TALLOC_CTX
*mem_ctx
,
1081 struct rpc_sh_ctx
*ctx
,
1082 struct rpc_pipe_client
*pipe_hnd
,
1083 struct policy_handle
*user_hnd
,
1084 int argc
, const char **argv
)
1087 union samr_UserInfo
*info
= NULL
;
1090 d_fprintf(stderr
, "usage: %s show <username>\n", ctx
->whoami
);
1091 return NT_STATUS_INVALID_PARAMETER
;
1094 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1098 if (!NT_STATUS_IS_OK(result
)) {
1102 d_printf("user rid: %d, group rid: %d\n",
1104 info
->info21
.primary_gid
);
1109 static NTSTATUS
rpc_sh_user_show(struct net_context
*c
,
1110 TALLOC_CTX
*mem_ctx
,
1111 struct rpc_sh_ctx
*ctx
,
1112 struct rpc_pipe_client
*pipe_hnd
,
1113 int argc
, const char **argv
)
1115 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1116 rpc_sh_user_show_internals
);
1119 #define FETCHSTR(name, rec) \
1120 do { if (strequal(ctx->thiscmd, name)) { \
1121 oldval = talloc_strdup(mem_ctx, info->info21.rec.string); } \
1124 #define SETSTR(name, rec, flag) \
1125 do { if (strequal(ctx->thiscmd, name)) { \
1126 init_lsa_String(&(info->info21.rec), argv[0]); \
1127 info->info21.fields_present |= SAMR_FIELD_##flag; } \
1130 static NTSTATUS
rpc_sh_user_str_edit_internals(struct net_context
*c
,
1131 TALLOC_CTX
*mem_ctx
,
1132 struct rpc_sh_ctx
*ctx
,
1133 struct rpc_pipe_client
*pipe_hnd
,
1134 struct policy_handle
*user_hnd
,
1135 int argc
, const char **argv
)
1138 const char *username
;
1139 const char *oldval
= "";
1140 union samr_UserInfo
*info
= NULL
;
1143 d_fprintf(stderr
, "usage: %s <username> [new value|NULL]\n",
1145 return NT_STATUS_INVALID_PARAMETER
;
1148 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1152 if (!NT_STATUS_IS_OK(result
)) {
1156 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1158 FETCHSTR("fullname", full_name
);
1159 FETCHSTR("homedir", home_directory
);
1160 FETCHSTR("homedrive", home_drive
);
1161 FETCHSTR("logonscript", logon_script
);
1162 FETCHSTR("profilepath", profile_path
);
1163 FETCHSTR("description", description
);
1166 d_printf("%s's %s: [%s]\n", username
, ctx
->thiscmd
, oldval
);
1170 if (strcmp(argv
[0], "NULL") == 0) {
1174 ZERO_STRUCT(info
->info21
);
1176 SETSTR("fullname", full_name
, FULL_NAME
);
1177 SETSTR("homedir", home_directory
, HOME_DIRECTORY
);
1178 SETSTR("homedrive", home_drive
, HOME_DRIVE
);
1179 SETSTR("logonscript", logon_script
, LOGON_SCRIPT
);
1180 SETSTR("profilepath", profile_path
, PROFILE_PATH
);
1181 SETSTR("description", description
, DESCRIPTION
);
1183 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1188 d_printf("Set %s's %s from [%s] to [%s]\n", username
,
1189 ctx
->thiscmd
, oldval
, argv
[0]);
1196 #define HANDLEFLG(name, rec) \
1197 do { if (strequal(ctx->thiscmd, name)) { \
1198 oldval = (oldflags & ACB_##rec) ? "yes" : "no"; \
1200 newflags = oldflags | ACB_##rec; \
1202 newflags = oldflags & ~ACB_##rec; \
1205 static NTSTATUS
rpc_sh_user_str_edit(struct net_context
*c
,
1206 TALLOC_CTX
*mem_ctx
,
1207 struct rpc_sh_ctx
*ctx
,
1208 struct rpc_pipe_client
*pipe_hnd
,
1209 int argc
, const char **argv
)
1211 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1212 rpc_sh_user_str_edit_internals
);
1215 static NTSTATUS
rpc_sh_user_flag_edit_internals(struct net_context
*c
,
1216 TALLOC_CTX
*mem_ctx
,
1217 struct rpc_sh_ctx
*ctx
,
1218 struct rpc_pipe_client
*pipe_hnd
,
1219 struct policy_handle
*user_hnd
,
1220 int argc
, const char **argv
)
1223 const char *username
;
1224 const char *oldval
= "unknown";
1225 uint32 oldflags
, newflags
;
1227 union samr_UserInfo
*info
= NULL
;
1230 ((argc
== 1) && !strequal(argv
[0], "yes") &&
1231 !strequal(argv
[0], "no"))) {
1232 d_fprintf(stderr
, "usage: %s <username> [yes|no]\n",
1234 return NT_STATUS_INVALID_PARAMETER
;
1237 newval
= strequal(argv
[0], "yes");
1239 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1243 if (!NT_STATUS_IS_OK(result
)) {
1247 username
= talloc_strdup(mem_ctx
, info
->info21
.account_name
.string
);
1248 oldflags
= info
->info21
.acct_flags
;
1249 newflags
= info
->info21
.acct_flags
;
1251 HANDLEFLG("disabled", DISABLED
);
1252 HANDLEFLG("pwnotreq", PWNOTREQ
);
1253 HANDLEFLG("autolock", AUTOLOCK
);
1254 HANDLEFLG("pwnoexp", PWNOEXP
);
1257 d_printf("%s's %s flag: %s\n", username
, ctx
->thiscmd
, oldval
);
1261 ZERO_STRUCT(info
->info21
);
1263 info
->info21
.acct_flags
= newflags
;
1264 info
->info21
.fields_present
= SAMR_FIELD_ACCT_FLAGS
;
1266 result
= rpccli_samr_SetUserInfo(pipe_hnd
, mem_ctx
,
1271 if (NT_STATUS_IS_OK(result
)) {
1272 d_printf("Set %s's %s flag from [%s] to [%s]\n", username
,
1273 ctx
->thiscmd
, oldval
, argv
[0]);
1281 static NTSTATUS
rpc_sh_user_flag_edit(struct net_context
*c
,
1282 TALLOC_CTX
*mem_ctx
,
1283 struct rpc_sh_ctx
*ctx
,
1284 struct rpc_pipe_client
*pipe_hnd
,
1285 int argc
, const char **argv
)
1287 return rpc_sh_handle_user(c
, mem_ctx
, ctx
, pipe_hnd
, argc
, argv
,
1288 rpc_sh_user_flag_edit_internals
);
1291 struct rpc_sh_cmd
*net_rpc_user_edit_cmds(struct net_context
*c
,
1292 TALLOC_CTX
*mem_ctx
,
1293 struct rpc_sh_ctx
*ctx
)
1295 static struct rpc_sh_cmd cmds
[] = {
1297 { "fullname", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1298 "Show/Set a user's full name" },
1300 { "homedir", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1301 "Show/Set a user's home directory" },
1303 { "homedrive", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1304 "Show/Set a user's home drive" },
1306 { "logonscript", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1307 "Show/Set a user's logon script" },
1309 { "profilepath", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1310 "Show/Set a user's profile path" },
1312 { "description", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_str_edit
,
1313 "Show/Set a user's description" },
1315 { "disabled", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1316 "Show/Set whether a user is disabled" },
1318 { "autolock", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1319 "Show/Set whether a user locked out" },
1321 { "pwnotreq", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1322 "Show/Set whether a user does not need a password" },
1324 { "pwnoexp", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_flag_edit
,
1325 "Show/Set whether a user's password does not expire" },
1327 { NULL
, NULL
, 0, NULL
, NULL
}
1333 struct rpc_sh_cmd
*net_rpc_user_cmds(struct net_context
*c
,
1334 TALLOC_CTX
*mem_ctx
,
1335 struct rpc_sh_ctx
*ctx
)
1337 static struct rpc_sh_cmd cmds
[] = {
1339 { "list", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_list
,
1340 "List available users" },
1342 { "info", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_info
,
1343 "List the domain groups a user is member of" },
1345 { "show", NULL
, &ndr_table_samr
.syntax_id
, rpc_sh_user_show
,
1346 "Show info about a user" },
1348 { "edit", net_rpc_user_edit_cmds
, 0, NULL
,
1349 "Show/Modify a user's fields" },
1351 { NULL
, NULL
, 0, NULL
, NULL
}
1357 /****************************************************************************/
1360 * Basic usage function for 'net rpc group'.
1361 * @param argc Standard main() style argc.
1362 * @param argv Standard main() style argv. Initial components are already
1366 static int rpc_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1368 return net_group_usage(c
, argc
, argv
);
1372 * Delete group on a remote RPC server.
1374 * All parameters are provided by the run_rpc_command function, except for
1375 * argc, argv which are passed through.
1377 * @param domain_sid The domain sid acquired from the remote server.
1378 * @param cli A cli_state connected to the server.
1379 * @param mem_ctx Talloc context, destroyed on completion of the function.
1380 * @param argc Standard main() style argc.
1381 * @param argv Standard main() style argv. Initial components are already
1384 * @return Normal NTSTATUS return.
1387 static NTSTATUS
rpc_group_delete_internals(struct net_context
*c
,
1388 const DOM_SID
*domain_sid
,
1389 const char *domain_name
,
1390 struct cli_state
*cli
,
1391 struct rpc_pipe_client
*pipe_hnd
,
1392 TALLOC_CTX
*mem_ctx
,
1396 struct policy_handle connect_pol
, domain_pol
, group_pol
, user_pol
;
1397 bool group_is_primary
= false;
1398 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1400 struct samr_RidTypeArray
*rids
= NULL
;
1403 /* struct samr_RidWithAttribute *user_gids; */
1405 struct samr_Ids group_rids
, name_types
;
1406 struct lsa_String lsa_acct_name
;
1407 union samr_UserInfo
*info
= NULL
;
1409 if (argc
< 1 || c
->display_usage
) {
1410 rpc_group_usage(c
, argc
,argv
);
1411 return NT_STATUS_OK
; /* ok? */
1414 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1416 MAXIMUM_ALLOWED_ACCESS
,
1419 if (!NT_STATUS_IS_OK(result
)) {
1420 d_fprintf(stderr
, "Request samr_Connect2 failed\n");
1424 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1426 MAXIMUM_ALLOWED_ACCESS
,
1427 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
1430 if (!NT_STATUS_IS_OK(result
)) {
1431 d_fprintf(stderr
, "Request open_domain failed\n");
1435 init_lsa_String(&lsa_acct_name
, argv
[0]);
1437 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1443 if (!NT_STATUS_IS_OK(result
)) {
1444 d_fprintf(stderr
, "Lookup of '%s' failed\n",argv
[0]);
1448 switch (name_types
.ids
[0])
1450 case SID_NAME_DOM_GRP
:
1451 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1453 MAXIMUM_ALLOWED_ACCESS
,
1456 if (!NT_STATUS_IS_OK(result
)) {
1457 d_fprintf(stderr
, "Request open_group failed");
1461 group_rid
= group_rids
.ids
[0];
1463 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
1467 if (!NT_STATUS_IS_OK(result
)) {
1468 d_fprintf(stderr
, "Unable to query group members of %s",argv
[0]);
1472 if (c
->opt_verbose
) {
1473 d_printf("Domain Group %s (rid: %d) has %d members\n",
1474 argv
[0],group_rid
, rids
->count
);
1477 /* Check if group is anyone's primary group */
1478 for (i
= 0; i
< rids
->count
; i
++)
1480 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
1482 MAXIMUM_ALLOWED_ACCESS
,
1486 if (!NT_STATUS_IS_OK(result
)) {
1487 d_fprintf(stderr
, "Unable to open group member %d\n",
1492 result
= rpccli_samr_QueryUserInfo(pipe_hnd
, mem_ctx
,
1497 if (!NT_STATUS_IS_OK(result
)) {
1498 d_fprintf(stderr
, "Unable to lookup userinfo for group member %d\n",
1503 if (info
->info21
.primary_gid
== group_rid
) {
1504 if (c
->opt_verbose
) {
1505 d_printf("Group is primary group of %s\n",
1506 info
->info21
.account_name
.string
);
1508 group_is_primary
= true;
1511 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &user_pol
);
1514 if (group_is_primary
) {
1515 d_fprintf(stderr
, "Unable to delete group because some "
1516 "of it's members have it as primary group\n");
1517 result
= NT_STATUS_MEMBERS_PRIMARY_GROUP
;
1521 /* remove all group members */
1522 for (i
= 0; i
< rids
->count
; i
++)
1525 d_printf("Remove group member %d...",
1527 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1531 if (NT_STATUS_IS_OK(result
)) {
1536 d_printf("failed\n");
1541 result
= rpccli_samr_DeleteDomainGroup(pipe_hnd
, mem_ctx
,
1545 /* removing a local group is easier... */
1546 case SID_NAME_ALIAS
:
1547 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1549 MAXIMUM_ALLOWED_ACCESS
,
1553 if (!NT_STATUS_IS_OK(result
)) {
1554 d_fprintf(stderr
, "Request open_alias failed\n");
1558 result
= rpccli_samr_DeleteDomAlias(pipe_hnd
, mem_ctx
,
1562 d_fprintf(stderr
, "%s is of type %s. This command is only for deleting local or global groups\n",
1563 argv
[0],sid_type_lookup(name_types
.ids
[0]));
1564 result
= NT_STATUS_UNSUCCESSFUL
;
1568 if (NT_STATUS_IS_OK(result
)) {
1570 d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types
.ids
[0]),argv
[0]);
1572 d_fprintf(stderr
, "Deleting of %s failed: %s\n",argv
[0],
1573 get_friendly_nt_error_msg(result
));
1581 static int rpc_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1583 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1584 rpc_group_delete_internals
, argc
,argv
);
1587 static int rpc_group_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1589 NET_API_STATUS status
;
1590 struct GROUP_INFO_1 info1
;
1591 uint32_t parm_error
= 0;
1593 if (argc
!= 1 || c
->display_usage
) {
1594 rpc_group_usage(c
, argc
, argv
);
1600 info1
.grpi1_name
= argv
[0];
1601 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1602 info1
.grpi1_comment
= c
->opt_comment
;
1605 status
= NetGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1608 d_fprintf(stderr
, "Failed to add group '%s' with: %s.\n",
1609 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1613 d_printf("Added group '%s'.\n", argv
[0]);
1619 static int rpc_alias_add_internals(struct net_context
*c
, int argc
, const char **argv
)
1621 NET_API_STATUS status
;
1622 struct LOCALGROUP_INFO_1 info1
;
1623 uint32_t parm_error
= 0;
1625 if (argc
!= 1 || c
->display_usage
) {
1626 rpc_group_usage(c
, argc
, argv
);
1632 info1
.lgrpi1_name
= argv
[0];
1633 if (c
->opt_comment
&& strlen(c
->opt_comment
) > 0) {
1634 info1
.lgrpi1_comment
= c
->opt_comment
;
1637 status
= NetLocalGroupAdd(c
->opt_host
, 1, (uint8_t *)&info1
, &parm_error
);
1640 d_fprintf(stderr
, "Failed to add alias '%s' with: %s.\n",
1641 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
1645 d_printf("Added alias '%s'.\n", argv
[0]);
1651 static int rpc_group_add(struct net_context
*c
, int argc
, const char **argv
)
1653 if (c
->opt_localgroup
)
1654 return rpc_alias_add_internals(c
, argc
, argv
);
1656 return rpc_group_add_internals(c
, argc
, argv
);
1659 static NTSTATUS
get_sid_from_name(struct cli_state
*cli
,
1660 TALLOC_CTX
*mem_ctx
,
1663 enum lsa_SidType
*type
)
1665 DOM_SID
*sids
= NULL
;
1666 enum lsa_SidType
*types
= NULL
;
1667 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1668 struct policy_handle lsa_pol
;
1669 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1671 result
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
1673 if (!NT_STATUS_IS_OK(result
)) {
1677 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, false,
1678 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
1680 if (!NT_STATUS_IS_OK(result
)) {
1684 result
= rpccli_lsa_lookup_names(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
1685 &name
, NULL
, 1, &sids
, &types
);
1687 if (NT_STATUS_IS_OK(result
)) {
1688 sid_copy(sid
, &sids
[0]);
1692 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
1696 TALLOC_FREE(pipe_hnd
);
1699 if (!NT_STATUS_IS_OK(result
) && (StrnCaseCmp(name
, "S-", 2) == 0)) {
1701 /* Try as S-1-5-whatever */
1705 if (string_to_sid(&tmp_sid
, name
)) {
1706 sid_copy(sid
, &tmp_sid
);
1707 *type
= SID_NAME_UNKNOWN
;
1708 result
= NT_STATUS_OK
;
1715 static NTSTATUS
rpc_add_groupmem(struct rpc_pipe_client
*pipe_hnd
,
1716 TALLOC_CTX
*mem_ctx
,
1717 const DOM_SID
*group_sid
,
1720 struct policy_handle connect_pol
, domain_pol
;
1723 struct policy_handle group_pol
;
1725 struct samr_Ids rids
, rid_types
;
1726 struct lsa_String lsa_acct_name
;
1730 sid_copy(&sid
, group_sid
);
1732 if (!sid_split_rid(&sid
, &group_rid
)) {
1733 return NT_STATUS_UNSUCCESSFUL
;
1736 /* Get sam policy handle */
1737 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1739 MAXIMUM_ALLOWED_ACCESS
,
1741 if (!NT_STATUS_IS_OK(result
)) {
1745 /* Get domain policy handle */
1746 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1748 MAXIMUM_ALLOWED_ACCESS
,
1751 if (!NT_STATUS_IS_OK(result
)) {
1755 init_lsa_String(&lsa_acct_name
, member
);
1757 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1764 if (!NT_STATUS_IS_OK(result
)) {
1765 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1769 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1771 MAXIMUM_ALLOWED_ACCESS
,
1775 if (!NT_STATUS_IS_OK(result
)) {
1779 result
= rpccli_samr_AddGroupMember(pipe_hnd
, mem_ctx
,
1782 0x0005); /* unknown flags */
1785 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1789 static NTSTATUS
rpc_add_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1790 TALLOC_CTX
*mem_ctx
,
1791 const DOM_SID
*alias_sid
,
1794 struct policy_handle connect_pol
, domain_pol
;
1797 struct policy_handle alias_pol
;
1800 enum lsa_SidType member_type
;
1804 sid_copy(&sid
, alias_sid
);
1806 if (!sid_split_rid(&sid
, &alias_rid
)) {
1807 return NT_STATUS_UNSUCCESSFUL
;
1810 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
1811 member
, &member_sid
, &member_type
);
1813 if (!NT_STATUS_IS_OK(result
)) {
1814 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1818 /* Get sam policy handle */
1819 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1821 MAXIMUM_ALLOWED_ACCESS
,
1823 if (!NT_STATUS_IS_OK(result
)) {
1827 /* Get domain policy handle */
1828 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1830 MAXIMUM_ALLOWED_ACCESS
,
1833 if (!NT_STATUS_IS_OK(result
)) {
1837 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
1839 MAXIMUM_ALLOWED_ACCESS
,
1843 if (!NT_STATUS_IS_OK(result
)) {
1847 result
= rpccli_samr_AddAliasMember(pipe_hnd
, mem_ctx
,
1851 if (!NT_STATUS_IS_OK(result
)) {
1856 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1860 static NTSTATUS
rpc_group_addmem_internals(struct net_context
*c
,
1861 const DOM_SID
*domain_sid
,
1862 const char *domain_name
,
1863 struct cli_state
*cli
,
1864 struct rpc_pipe_client
*pipe_hnd
,
1865 TALLOC_CTX
*mem_ctx
,
1870 enum lsa_SidType group_type
;
1872 if (argc
!= 2 || c
->display_usage
) {
1874 "net rpc group addmem <group> <member>\n"
1875 " Add a member to a group\n"
1876 " group\tGroup to add member to\n"
1877 " member\tMember to add to group\n");
1878 return NT_STATUS_UNSUCCESSFUL
;
1881 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
1882 &group_sid
, &group_type
))) {
1883 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
1884 return NT_STATUS_UNSUCCESSFUL
;
1887 if (group_type
== SID_NAME_DOM_GRP
) {
1888 NTSTATUS result
= rpc_add_groupmem(pipe_hnd
, mem_ctx
,
1889 &group_sid
, argv
[1]);
1891 if (!NT_STATUS_IS_OK(result
)) {
1892 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1893 argv
[1], argv
[0], nt_errstr(result
));
1898 if (group_type
== SID_NAME_ALIAS
) {
1899 NTSTATUS result
= rpc_add_aliasmem(pipe_hnd
, mem_ctx
,
1900 &group_sid
, argv
[1]);
1902 if (!NT_STATUS_IS_OK(result
)) {
1903 d_fprintf(stderr
, "Could not add %s to %s: %s\n",
1904 argv
[1], argv
[0], nt_errstr(result
));
1909 d_fprintf(stderr
, "Can only add members to global or local groups "
1910 "which %s is not\n", argv
[0]);
1912 return NT_STATUS_UNSUCCESSFUL
;
1915 static int rpc_group_addmem(struct net_context
*c
, int argc
, const char **argv
)
1917 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
1918 rpc_group_addmem_internals
,
1922 static NTSTATUS
rpc_del_groupmem(struct net_context
*c
,
1923 struct rpc_pipe_client
*pipe_hnd
,
1924 TALLOC_CTX
*mem_ctx
,
1925 const DOM_SID
*group_sid
,
1928 struct policy_handle connect_pol
, domain_pol
;
1931 struct policy_handle group_pol
;
1933 struct samr_Ids rids
, rid_types
;
1934 struct lsa_String lsa_acct_name
;
1938 sid_copy(&sid
, group_sid
);
1940 if (!sid_split_rid(&sid
, &group_rid
))
1941 return NT_STATUS_UNSUCCESSFUL
;
1943 /* Get sam policy handle */
1944 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
1946 MAXIMUM_ALLOWED_ACCESS
,
1948 if (!NT_STATUS_IS_OK(result
))
1951 /* Get domain policy handle */
1952 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
1954 MAXIMUM_ALLOWED_ACCESS
,
1957 if (!NT_STATUS_IS_OK(result
))
1960 init_lsa_String(&lsa_acct_name
, member
);
1962 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
1968 if (!NT_STATUS_IS_OK(result
)) {
1969 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
1973 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
1975 MAXIMUM_ALLOWED_ACCESS
,
1979 if (!NT_STATUS_IS_OK(result
))
1982 result
= rpccli_samr_DeleteGroupMember(pipe_hnd
, mem_ctx
,
1987 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
1991 static NTSTATUS
rpc_del_aliasmem(struct rpc_pipe_client
*pipe_hnd
,
1992 TALLOC_CTX
*mem_ctx
,
1993 const DOM_SID
*alias_sid
,
1996 struct policy_handle connect_pol
, domain_pol
;
1999 struct policy_handle alias_pol
;
2002 enum lsa_SidType member_type
;
2006 sid_copy(&sid
, alias_sid
);
2008 if (!sid_split_rid(&sid
, &alias_rid
))
2009 return NT_STATUS_UNSUCCESSFUL
;
2011 result
= get_sid_from_name(rpc_pipe_np_smb_conn(pipe_hnd
), mem_ctx
,
2012 member
, &member_sid
, &member_type
);
2014 if (!NT_STATUS_IS_OK(result
)) {
2015 d_fprintf(stderr
, "Could not lookup up group member %s\n", member
);
2019 /* Get sam policy handle */
2020 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2022 MAXIMUM_ALLOWED_ACCESS
,
2024 if (!NT_STATUS_IS_OK(result
)) {
2028 /* Get domain policy handle */
2029 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2031 MAXIMUM_ALLOWED_ACCESS
,
2034 if (!NT_STATUS_IS_OK(result
)) {
2038 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2040 MAXIMUM_ALLOWED_ACCESS
,
2044 if (!NT_STATUS_IS_OK(result
))
2047 result
= rpccli_samr_DeleteAliasMember(pipe_hnd
, mem_ctx
,
2051 if (!NT_STATUS_IS_OK(result
))
2055 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
2059 static NTSTATUS
rpc_group_delmem_internals(struct net_context
*c
,
2060 const DOM_SID
*domain_sid
,
2061 const char *domain_name
,
2062 struct cli_state
*cli
,
2063 struct rpc_pipe_client
*pipe_hnd
,
2064 TALLOC_CTX
*mem_ctx
,
2069 enum lsa_SidType group_type
;
2071 if (argc
!= 2 || c
->display_usage
) {
2073 "net rpc group delmem <group> <member>\n"
2074 " Delete a member from a group\n"
2075 " group\tGroup to delete member from\n"
2076 " member\tMember to delete from group\n");
2077 return NT_STATUS_UNSUCCESSFUL
;
2080 if (!NT_STATUS_IS_OK(get_sid_from_name(cli
, mem_ctx
, argv
[0],
2081 &group_sid
, &group_type
))) {
2082 d_fprintf(stderr
, "Could not lookup group name %s\n", argv
[0]);
2083 return NT_STATUS_UNSUCCESSFUL
;
2086 if (group_type
== SID_NAME_DOM_GRP
) {
2087 NTSTATUS result
= rpc_del_groupmem(c
, pipe_hnd
, mem_ctx
,
2088 &group_sid
, argv
[1]);
2090 if (!NT_STATUS_IS_OK(result
)) {
2091 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2092 argv
[1], argv
[0], nt_errstr(result
));
2097 if (group_type
== SID_NAME_ALIAS
) {
2098 NTSTATUS result
= rpc_del_aliasmem(pipe_hnd
, mem_ctx
,
2099 &group_sid
, argv
[1]);
2101 if (!NT_STATUS_IS_OK(result
)) {
2102 d_fprintf(stderr
, "Could not del %s from %s: %s\n",
2103 argv
[1], argv
[0], nt_errstr(result
));
2108 d_fprintf(stderr
, "Can only delete members from global or local groups "
2109 "which %s is not\n", argv
[0]);
2111 return NT_STATUS_UNSUCCESSFUL
;
2114 static int rpc_group_delmem(struct net_context
*c
, int argc
, const char **argv
)
2116 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2117 rpc_group_delmem_internals
,
2122 * List groups on a remote RPC server.
2124 * All parameters are provided by the run_rpc_command function, except for
2125 * argc, argv which are passes through.
2127 * @param domain_sid The domain sid acquired from the remote server.
2128 * @param cli A cli_state connected to the server.
2129 * @param mem_ctx Talloc context, destroyed on completion of the function.
2130 * @param argc Standard main() style argc.
2131 * @param argv Standard main() style argv. Initial components are already
2134 * @return Normal NTSTATUS return.
2137 static NTSTATUS
rpc_group_list_internals(struct net_context
*c
,
2138 const DOM_SID
*domain_sid
,
2139 const char *domain_name
,
2140 struct cli_state
*cli
,
2141 struct rpc_pipe_client
*pipe_hnd
,
2142 TALLOC_CTX
*mem_ctx
,
2146 struct policy_handle connect_pol
, domain_pol
;
2147 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
2148 uint32 start_idx
=0, max_entries
=250, num_entries
, i
, loop_count
= 0;
2149 struct samr_SamArray
*groups
= NULL
;
2150 bool global
= false;
2152 bool builtin
= false;
2154 if (c
->display_usage
) {
2156 "net rpc group list [global] [local] [builtin]\n"
2157 " List groups on RPC server\n"
2158 " global\tList global groups\n"
2159 " local\tList local groups\n"
2160 " builtin\tList builtin groups\n"
2161 " If none of global, local or builtin is "
2162 "specified, all three options are considered set\n");
2163 return NT_STATUS_OK
;
2172 for (i
=0; i
<argc
; i
++) {
2173 if (strequal(argv
[i
], "global"))
2176 if (strequal(argv
[i
], "local"))
2179 if (strequal(argv
[i
], "builtin"))
2183 /* Get sam policy handle */
2185 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2187 MAXIMUM_ALLOWED_ACCESS
,
2189 if (!NT_STATUS_IS_OK(result
)) {
2193 /* Get domain policy handle */
2195 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2197 MAXIMUM_ALLOWED_ACCESS
,
2198 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2200 if (!NT_STATUS_IS_OK(result
)) {
2204 /* Query domain groups */
2205 if (c
->opt_long_list_entries
)
2206 d_printf("\nGroup name Comment"
2207 "\n-----------------------------\n");
2209 uint32_t max_size
, total_size
, returned_size
;
2210 union samr_DispInfo info
;
2214 get_query_dispinfo_params(
2215 loop_count
, &max_entries
, &max_size
);
2217 result
= rpccli_samr_QueryDisplayInfo(pipe_hnd
, mem_ctx
,
2226 num_entries
= info
.info3
.count
;
2227 start_idx
+= info
.info3
.count
;
2229 if (!NT_STATUS_IS_OK(result
) &&
2230 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2233 for (i
= 0; i
< num_entries
; i
++) {
2235 const char *group
= NULL
;
2236 const char *desc
= NULL
;
2238 group
= info
.info3
.entries
[i
].account_name
.string
;
2239 desc
= info
.info3
.entries
[i
].description
.string
;
2241 if (c
->opt_long_list_entries
)
2242 printf("%-21.21s %-50.50s\n",
2245 printf("%s\n", group
);
2247 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2248 /* query domain aliases */
2253 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2259 if (!NT_STATUS_IS_OK(result
) &&
2260 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2263 for (i
= 0; i
< num_entries
; i
++) {
2265 const char *description
= NULL
;
2267 if (c
->opt_long_list_entries
) {
2269 struct policy_handle alias_pol
;
2270 union samr_AliasInfo
*info
= NULL
;
2272 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2275 groups
->entries
[i
].idx
,
2277 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2281 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2283 description
= info
->description
.string
;
2287 if (description
!= NULL
) {
2288 printf("%-21.21s %-50.50s\n",
2289 groups
->entries
[i
].name
.string
,
2292 printf("%s\n", groups
->entries
[i
].name
.string
);
2295 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2296 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2297 /* Get builtin policy handle */
2299 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2301 MAXIMUM_ALLOWED_ACCESS
,
2302 CONST_DISCARD(struct dom_sid2
*, &global_sid_Builtin
),
2304 if (!NT_STATUS_IS_OK(result
)) {
2307 /* query builtin aliases */
2310 if (!builtin
) break;
2312 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
2318 if (!NT_STATUS_IS_OK(result
) &&
2319 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
))
2322 for (i
= 0; i
< num_entries
; i
++) {
2324 const char *description
= NULL
;
2326 if (c
->opt_long_list_entries
) {
2328 struct policy_handle alias_pol
;
2329 union samr_AliasInfo
*info
= NULL
;
2331 if ((NT_STATUS_IS_OK(rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2334 groups
->entries
[i
].idx
,
2336 (NT_STATUS_IS_OK(rpccli_samr_QueryAliasInfo(pipe_hnd
, mem_ctx
,
2340 (NT_STATUS_IS_OK(rpccli_samr_Close(pipe_hnd
, mem_ctx
,
2342 description
= info
->description
.string
;
2346 if (description
!= NULL
) {
2347 printf("%-21.21s %-50.50s\n",
2348 groups
->entries
[i
].name
.string
,
2351 printf("%s\n", groups
->entries
[i
].name
.string
);
2354 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
2360 static int rpc_group_list(struct net_context
*c
, int argc
, const char **argv
)
2362 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2363 rpc_group_list_internals
,
2367 static NTSTATUS
rpc_list_group_members(struct net_context
*c
,
2368 struct rpc_pipe_client
*pipe_hnd
,
2369 TALLOC_CTX
*mem_ctx
,
2370 const char *domain_name
,
2371 const DOM_SID
*domain_sid
,
2372 struct policy_handle
*domain_pol
,
2376 struct policy_handle group_pol
;
2377 uint32 num_members
, *group_rids
;
2379 struct samr_RidTypeArray
*rids
= NULL
;
2380 struct lsa_Strings names
;
2381 struct samr_Ids types
;
2384 sid_to_fstring(sid_str
, domain_sid
);
2386 result
= rpccli_samr_OpenGroup(pipe_hnd
, mem_ctx
,
2388 MAXIMUM_ALLOWED_ACCESS
,
2392 if (!NT_STATUS_IS_OK(result
))
2395 result
= rpccli_samr_QueryGroupMember(pipe_hnd
, mem_ctx
,
2399 if (!NT_STATUS_IS_OK(result
))
2402 num_members
= rids
->count
;
2403 group_rids
= rids
->rids
;
2405 while (num_members
> 0) {
2406 int this_time
= 512;
2408 if (num_members
< this_time
)
2409 this_time
= num_members
;
2411 result
= rpccli_samr_LookupRids(pipe_hnd
, mem_ctx
,
2418 if (!NT_STATUS_IS_OK(result
))
2421 /* We only have users as members, but make the output
2422 the same as the output of alias members */
2424 for (i
= 0; i
< this_time
; i
++) {
2426 if (c
->opt_long_list_entries
) {
2427 printf("%s-%d %s\\%s %d\n", sid_str
,
2428 group_rids
[i
], domain_name
,
2429 names
.names
[i
].string
,
2432 printf("%s\\%s\n", domain_name
,
2433 names
.names
[i
].string
);
2437 num_members
-= this_time
;
2441 return NT_STATUS_OK
;
2444 static NTSTATUS
rpc_list_alias_members(struct net_context
*c
,
2445 struct rpc_pipe_client
*pipe_hnd
,
2446 TALLOC_CTX
*mem_ctx
,
2447 struct policy_handle
*domain_pol
,
2451 struct rpc_pipe_client
*lsa_pipe
;
2452 struct policy_handle alias_pol
, lsa_pol
;
2454 DOM_SID
*alias_sids
;
2457 enum lsa_SidType
*types
;
2459 struct lsa_SidArray sid_array
;
2461 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
2463 MAXIMUM_ALLOWED_ACCESS
,
2467 if (!NT_STATUS_IS_OK(result
))
2470 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
2474 if (!NT_STATUS_IS_OK(result
)) {
2475 d_fprintf(stderr
, "Couldn't list alias members\n");
2479 num_members
= sid_array
.num_sids
;
2481 if (num_members
== 0) {
2482 return NT_STATUS_OK
;
2485 result
= cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd
),
2486 &ndr_table_lsarpc
.syntax_id
,
2488 if (!NT_STATUS_IS_OK(result
)) {
2489 d_fprintf(stderr
, "Couldn't open LSA pipe. Error was %s\n",
2490 nt_errstr(result
) );
2494 result
= rpccli_lsa_open_policy(lsa_pipe
, mem_ctx
, true,
2495 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
2497 if (!NT_STATUS_IS_OK(result
)) {
2498 d_fprintf(stderr
, "Couldn't open LSA policy handle\n");
2499 TALLOC_FREE(lsa_pipe
);
2503 alias_sids
= TALLOC_ZERO_ARRAY(mem_ctx
, DOM_SID
, num_members
);
2505 d_fprintf(stderr
, "Out of memory\n");
2506 TALLOC_FREE(lsa_pipe
);
2507 return NT_STATUS_NO_MEMORY
;
2510 for (i
=0; i
<num_members
; i
++) {
2511 sid_copy(&alias_sids
[i
], sid_array
.sids
[i
].sid
);
2514 result
= rpccli_lsa_lookup_sids(lsa_pipe
, mem_ctx
, &lsa_pol
,
2515 num_members
, alias_sids
,
2516 &domains
, &names
, &types
);
2518 if (!NT_STATUS_IS_OK(result
) &&
2519 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
)) {
2520 d_fprintf(stderr
, "Couldn't lookup SIDs\n");
2521 TALLOC_FREE(lsa_pipe
);
2525 for (i
= 0; i
< num_members
; i
++) {
2527 sid_to_fstring(sid_str
, &alias_sids
[i
]);
2529 if (c
->opt_long_list_entries
) {
2530 printf("%s %s\\%s %d\n", sid_str
,
2531 domains
[i
] ? domains
[i
] : "*unknown*",
2532 names
[i
] ? names
[i
] : "*unknown*", types
[i
]);
2535 printf("%s\\%s\n", domains
[i
], names
[i
]);
2537 printf("%s\n", sid_str
);
2541 TALLOC_FREE(lsa_pipe
);
2542 return NT_STATUS_OK
;
2545 static NTSTATUS
rpc_group_members_internals(struct net_context
*c
,
2546 const DOM_SID
*domain_sid
,
2547 const char *domain_name
,
2548 struct cli_state
*cli
,
2549 struct rpc_pipe_client
*pipe_hnd
,
2550 TALLOC_CTX
*mem_ctx
,
2555 struct policy_handle connect_pol
, domain_pol
;
2556 struct samr_Ids rids
, rid_types
;
2557 struct lsa_String lsa_acct_name
;
2559 /* Get sam policy handle */
2561 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
2563 MAXIMUM_ALLOWED_ACCESS
,
2566 if (!NT_STATUS_IS_OK(result
))
2569 /* Get domain policy handle */
2571 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2573 MAXIMUM_ALLOWED_ACCESS
,
2574 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
2577 if (!NT_STATUS_IS_OK(result
))
2580 init_lsa_String(&lsa_acct_name
, argv
[0]); /* sure? */
2582 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2589 if (!NT_STATUS_IS_OK(result
)) {
2591 /* Ok, did not find it in the global sam, try with builtin */
2593 DOM_SID sid_Builtin
;
2595 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
2597 sid_copy(&sid_Builtin
, &global_sid_Builtin
);
2599 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
2601 MAXIMUM_ALLOWED_ACCESS
,
2605 if (!NT_STATUS_IS_OK(result
)) {
2606 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2610 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
2617 if (!NT_STATUS_IS_OK(result
)) {
2618 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2623 if (rids
.count
!= 1) {
2624 d_fprintf(stderr
, "Couldn't find group %s\n", argv
[0]);
2628 if (rid_types
.ids
[0] == SID_NAME_DOM_GRP
) {
2629 return rpc_list_group_members(c
, pipe_hnd
, mem_ctx
, domain_name
,
2630 domain_sid
, &domain_pol
,
2634 if (rid_types
.ids
[0] == SID_NAME_ALIAS
) {
2635 return rpc_list_alias_members(c
, pipe_hnd
, mem_ctx
, &domain_pol
,
2639 return NT_STATUS_NO_SUCH_GROUP
;
2642 static int rpc_group_members(struct net_context
*c
, int argc
, const char **argv
)
2644 if (argc
!= 1 || c
->display_usage
) {
2645 return rpc_group_usage(c
, argc
, argv
);
2648 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2649 rpc_group_members_internals
,
2653 static int rpc_group_rename_internals(struct net_context
*c
, int argc
, const char **argv
)
2655 NET_API_STATUS status
;
2656 struct GROUP_INFO_0 g0
;
2660 d_printf("Usage: 'net rpc group rename group newname'\n");
2664 g0
.grpi0_name
= argv
[1];
2666 status
= NetGroupSetInfo(c
->opt_host
,
2673 d_fprintf(stderr
, "Renaming group %s failed with: %s\n",
2674 argv
[0], libnetapi_get_error_string(c
->netapi_ctx
,
2682 static int rpc_group_rename(struct net_context
*c
, int argc
, const char **argv
)
2684 if (argc
!= 2 || c
->display_usage
) {
2685 return rpc_group_usage(c
, argc
, argv
);
2688 return rpc_group_rename_internals(c
, argc
, argv
);
2692 * 'net rpc group' entrypoint.
2693 * @param argc Standard main() style argc.
2694 * @param argv Standard main() style argv. Initial components are already
2698 int net_rpc_group(struct net_context
*c
, int argc
, const char **argv
)
2700 NET_API_STATUS status
;
2702 struct functable func
[] = {
2707 "Create specified group",
2708 "net rpc group add\n"
2709 " Create specified group"
2715 "Delete specified group",
2716 "net rpc group delete\n"
2717 " Delete specified group"
2723 "Add member to group",
2724 "net rpc group addmem\n"
2725 " Add member to group"
2731 "Remove member from group",
2732 "net rpc group delmem\n"
2733 " Remove member from group"
2740 "net rpc group list\n"
2747 "List group members",
2748 "net rpc group members\n"
2749 " List group members"
2756 "net rpc group rename\n"
2759 {NULL
, NULL
, 0, NULL
, NULL
}
2762 status
= libnetapi_init(&c
->netapi_ctx
);
2766 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
2767 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
2768 if (c
->opt_kerberos
) {
2769 libnetapi_set_use_kerberos(c
->netapi_ctx
);
2773 if (c
->display_usage
) {
2774 d_printf("Usage:\n");
2775 d_printf("net rpc group\n"
2776 " Alias for net rpc group list global local "
2778 net_display_usage_from_functable(func
);
2782 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
2783 rpc_group_list_internals
,
2787 return net_run_function(c
, argc
, argv
, "net rpc group", func
);
2790 /****************************************************************************/
2792 static int rpc_share_usage(struct net_context
*c
, int argc
, const char **argv
)
2794 return net_share_usage(c
, argc
, argv
);
2798 * Add a share on a remote RPC server.
2800 * @param argc Standard main() style argc.
2801 * @param argv Standard main() style argv. Initial components are already
2804 * @return A shell status integer (0 for success).
2807 static int rpc_share_add(struct net_context
*c
, int argc
, const char **argv
)
2809 NET_API_STATUS status
;
2812 uint32 type
= STYPE_DISKTREE
; /* only allow disk shares to be added */
2813 uint32 num_users
=0, perms
=0;
2814 char *password
=NULL
; /* don't allow a share password */
2815 struct SHARE_INFO_2 i2
;
2816 uint32_t parm_error
= 0;
2818 if ((argc
< 1) || !strchr(argv
[0], '=') || c
->display_usage
) {
2819 return rpc_share_usage(c
, argc
, argv
);
2822 if ((sharename
= talloc_strdup(c
, argv
[0])) == NULL
) {
2826 path
= strchr(sharename
, '=');
2833 i2
.shi2_netname
= sharename
;
2834 i2
.shi2_type
= type
;
2835 i2
.shi2_remark
= c
->opt_comment
;
2836 i2
.shi2_permissions
= perms
;
2837 i2
.shi2_max_uses
= c
->opt_maxusers
;
2838 i2
.shi2_current_uses
= num_users
;
2839 i2
.shi2_path
= path
;
2840 i2
.shi2_passwd
= password
;
2842 status
= NetShareAdd(c
->opt_host
,
2847 printf("NetShareAdd failed with: %s\n",
2848 libnetapi_get_error_string(c
->netapi_ctx
, status
));
2855 * Delete a share on a remote RPC server.
2857 * @param domain_sid The domain sid acquired from the remote server.
2858 * @param argc Standard main() style argc.
2859 * @param argv Standard main() style argv. Initial components are already
2862 * @return A shell status integer (0 for success).
2864 static int rpc_share_delete(struct net_context
*c
, int argc
, const char **argv
)
2866 if (argc
< 1 || c
->display_usage
) {
2867 return rpc_share_usage(c
, argc
, argv
);
2870 return NetShareDel(c
->opt_host
, argv
[0], 0);
2874 * Formatted print of share info
2876 * @param r pointer to SHARE_INFO_1 to format
2879 static void display_share_info_1(struct net_context
*c
,
2880 struct SHARE_INFO_1
*r
)
2882 if (c
->opt_long_list_entries
) {
2883 d_printf("%-12s %-8.8s %-50s\n",
2885 net_share_type_str(r
->shi1_type
& ~(STYPE_TEMPORARY
|STYPE_HIDDEN
)),
2888 d_printf("%s\n", r
->shi1_netname
);
2892 static WERROR
get_share_info(struct net_context
*c
,
2893 struct rpc_pipe_client
*pipe_hnd
,
2894 TALLOC_CTX
*mem_ctx
,
2898 struct srvsvc_NetShareInfoCtr
*info_ctr
)
2902 union srvsvc_NetShareInfo info
;
2904 /* no specific share requested, enumerate all */
2907 uint32_t preferred_len
= 0xffffffff;
2908 uint32_t total_entries
= 0;
2909 uint32_t resume_handle
= 0;
2911 info_ctr
->level
= level
;
2913 status
= rpccli_srvsvc_NetShareEnumAll(pipe_hnd
, mem_ctx
,
2923 /* request just one share */
2924 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
2931 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2936 ZERO_STRUCTP(info_ctr
);
2938 info_ctr
->level
= level
;
2943 struct srvsvc_NetShareCtr1
*ctr1
;
2945 ctr1
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr1
);
2946 W_ERROR_HAVE_NO_MEMORY(ctr1
);
2949 ctr1
->array
= info
.info1
;
2951 info_ctr
->ctr
.ctr1
= ctr1
;
2955 struct srvsvc_NetShareCtr2
*ctr2
;
2957 ctr2
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr2
);
2958 W_ERROR_HAVE_NO_MEMORY(ctr2
);
2961 ctr2
->array
= info
.info2
;
2963 info_ctr
->ctr
.ctr2
= ctr2
;
2967 struct srvsvc_NetShareCtr502
*ctr502
;
2969 ctr502
= TALLOC_ZERO_P(mem_ctx
, struct srvsvc_NetShareCtr502
);
2970 W_ERROR_HAVE_NO_MEMORY(ctr502
);
2973 ctr502
->array
= info
.info502
;
2975 info_ctr
->ctr
.ctr502
= ctr502
;
2983 * 'net rpc share list' entrypoint.
2984 * @param argc Standard main() style argc.
2985 * @param argv Standard main() style argv. Initial components are already
2988 static int rpc_share_list(struct net_context
*c
, int argc
, const char **argv
)
2990 NET_API_STATUS status
;
2991 struct SHARE_INFO_1
*i1
= NULL
;
2992 uint32_t entries_read
= 0;
2993 uint32_t total_entries
= 0;
2994 uint32_t resume_handle
= 0;
2995 uint32_t i
, level
= 1;
2997 if (c
->display_usage
) {
2999 "net rpc share list\n"
3000 " List shares on remote server\n");
3004 status
= NetShareEnum(c
->opt_host
,
3006 (uint8_t **)(void *)&i1
,
3015 /* Display results */
3017 if (c
->opt_long_list_entries
) {
3019 "\nEnumerating shared resources (exports) on remote server:\n\n"
3020 "\nShare name Type Description\n"
3021 "---------- ---- -----------\n");
3023 for (i
= 0; i
< entries_read
; i
++)
3024 display_share_info_1(c
, &i1
[i
]);
3029 static bool check_share_availability(struct cli_state
*cli
, const char *netname
)
3031 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
3032 d_printf("skipping [%s]: not a file share.\n", netname
);
3042 static bool check_share_sanity(struct net_context
*c
, struct cli_state
*cli
,
3043 const char *netname
, uint32 type
)
3045 /* only support disk shares */
3046 if (! ( type
== STYPE_DISKTREE
|| type
== (STYPE_DISKTREE
| STYPE_HIDDEN
)) ) {
3047 printf("share [%s] is not a diskshare (type: %x)\n", netname
, type
);
3051 /* skip builtin shares */
3052 /* FIXME: should print$ be added too ? */
3053 if (strequal(netname
,"IPC$") || strequal(netname
,"ADMIN$") ||
3054 strequal(netname
,"global"))
3057 if (c
->opt_exclude
&& in_list(netname
, c
->opt_exclude
, false)) {
3058 printf("excluding [%s]\n", netname
);
3062 return check_share_availability(cli
, netname
);
3066 * Migrate shares from a remote RPC server to the local RPC server.
3068 * All parameters are provided by the run_rpc_command function, except for
3069 * argc, argv which are passed through.
3071 * @param domain_sid The domain sid acquired from the remote server.
3072 * @param cli A cli_state connected to the server.
3073 * @param mem_ctx Talloc context, destroyed on completion of the function.
3074 * @param argc Standard main() style argc.
3075 * @param argv Standard main() style argv. Initial components are already
3078 * @return Normal NTSTATUS return.
3081 static NTSTATUS
rpc_share_migrate_shares_internals(struct net_context
*c
,
3082 const DOM_SID
*domain_sid
,
3083 const char *domain_name
,
3084 struct cli_state
*cli
,
3085 struct rpc_pipe_client
*pipe_hnd
,
3086 TALLOC_CTX
*mem_ctx
,
3091 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3092 struct srvsvc_NetShareInfoCtr ctr_src
;
3094 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3095 struct cli_state
*cli_dst
= NULL
;
3096 uint32 level
= 502; /* includes secdesc */
3097 uint32_t parm_error
= 0;
3099 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3101 if (!W_ERROR_IS_OK(result
))
3104 /* connect destination PI_SRVSVC */
3105 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3106 &ndr_table_srvsvc
.syntax_id
);
3107 if (!NT_STATUS_IS_OK(nt_status
))
3111 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3113 union srvsvc_NetShareInfo info
;
3114 struct srvsvc_NetShareInfo502 info502
=
3115 ctr_src
.ctr
.ctr502
->array
[i
];
3117 /* reset error-code */
3118 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3120 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3123 /* finally add the share on the dst server */
3125 printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
3126 info502
.name
, info502
.path
, info502
.comment
);
3128 info
.info502
= &info502
;
3130 nt_status
= rpccli_srvsvc_NetShareAdd(srvsvc_pipe
, mem_ctx
,
3131 srvsvc_pipe
->desthost
,
3137 if (W_ERROR_V(result
) == W_ERROR_V(WERR_FILE_EXISTS
)) {
3138 printf(" [%s] does already exist\n",
3143 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3144 printf("cannot add share: %s\n", win_errstr(result
));
3150 nt_status
= NT_STATUS_OK
;
3154 cli_shutdown(cli_dst
);
3162 * Migrate shares from a RPC server to another.
3164 * @param argc Standard main() style argc.
3165 * @param argv Standard main() style argv. Initial components are already
3168 * @return A shell status integer (0 for success).
3170 static int rpc_share_migrate_shares(struct net_context
*c
, int argc
,
3173 if (c
->display_usage
) {
3175 "net rpc share migrate shares\n"
3176 " Migrate shares to local server\n");
3181 printf("no server to migrate\n");
3185 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3186 rpc_share_migrate_shares_internals
,
3193 * @param f file_info
3194 * @param mask current search mask
3195 * @param state arg-pointer
3198 static void copy_fn(const char *mnt
, file_info
*f
,
3199 const char *mask
, void *state
)
3201 static NTSTATUS nt_status
;
3202 static struct copy_clistate
*local_state
;
3203 static fstring filename
, new_mask
;
3206 struct net_context
*c
;
3208 local_state
= (struct copy_clistate
*)state
;
3209 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3213 if (strequal(f
->name
, ".") || strequal(f
->name
, ".."))
3216 DEBUG(3,("got mask: %s, name: %s\n", mask
, f
->name
));
3219 if (f
->mode
& aDIR
) {
3221 DEBUG(3,("got dir: %s\n", f
->name
));
3223 fstrcpy(dir
, local_state
->cwd
);
3225 fstrcat(dir
, f
->name
);
3227 switch (net_mode_share
)
3229 case NET_MODE_SHARE_MIGRATE
:
3230 /* create that directory */
3231 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3232 local_state
->cli_share_src
,
3233 local_state
->cli_share_dst
,
3235 c
->opt_acls
? true : false,
3236 c
->opt_attrs
? true : false,
3237 c
->opt_timestamps
? true:false,
3241 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3245 if (!NT_STATUS_IS_OK(nt_status
))
3246 printf("could not handle dir %s: %s\n",
3247 dir
, nt_errstr(nt_status
));
3249 /* search below that directory */
3250 fstrcpy(new_mask
, dir
);
3251 fstrcat(new_mask
, "\\*");
3253 old_dir
= local_state
->cwd
;
3254 local_state
->cwd
= dir
;
3255 if (!sync_files(local_state
, new_mask
))
3256 printf("could not handle files\n");
3257 local_state
->cwd
= old_dir
;
3264 fstrcpy(filename
, local_state
->cwd
);
3265 fstrcat(filename
, "\\");
3266 fstrcat(filename
, f
->name
);
3268 DEBUG(3,("got file: %s\n", filename
));
3270 switch (net_mode_share
)
3272 case NET_MODE_SHARE_MIGRATE
:
3273 nt_status
= net_copy_file(c
, local_state
->mem_ctx
,
3274 local_state
->cli_share_src
,
3275 local_state
->cli_share_dst
,
3277 c
->opt_acls
? true : false,
3278 c
->opt_attrs
? true : false,
3279 c
->opt_timestamps
? true: false,
3283 d_fprintf(stderr
, "Unsupported file mode %d\n", net_mode_share
);
3287 if (!NT_STATUS_IS_OK(nt_status
))
3288 printf("could not handle file %s: %s\n",
3289 filename
, nt_errstr(nt_status
));
3294 * sync files, can be called recursivly to list files
3295 * and then call copy_fn for each file
3297 * @param cp_clistate pointer to the copy_clistate we work with
3298 * @param mask the current search mask
3300 * @return Boolean result
3302 static bool sync_files(struct copy_clistate
*cp_clistate
, const char *mask
)
3304 struct cli_state
*targetcli
;
3305 char *targetpath
= NULL
;
3307 DEBUG(3,("calling cli_list with mask: %s\n", mask
));
3309 if ( !cli_resolve_path(talloc_tos(), "", NULL
, cp_clistate
->cli_share_src
,
3310 mask
, &targetcli
, &targetpath
) ) {
3311 d_fprintf(stderr
, "cli_resolve_path %s failed with error: %s\n",
3312 mask
, cli_errstr(cp_clistate
->cli_share_src
));
3316 if (cli_list(targetcli
, targetpath
, cp_clistate
->attribute
, copy_fn
, cp_clistate
) == -1) {
3317 d_fprintf(stderr
, "listing %s failed with error: %s\n",
3318 mask
, cli_errstr(targetcli
));
3327 * Set the top level directory permissions before we do any further copies.
3328 * Should set up ACL inheritance.
3331 bool copy_top_level_perms(struct net_context
*c
,
3332 struct copy_clistate
*cp_clistate
,
3333 const char *sharename
)
3335 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3337 switch (net_mode_share
) {
3338 case NET_MODE_SHARE_MIGRATE
:
3339 DEBUG(3,("calling net_copy_fileattr for '.' directory in share %s\n", sharename
));
3340 nt_status
= net_copy_fileattr(c
,
3341 cp_clistate
->mem_ctx
,
3342 cp_clistate
->cli_share_src
,
3343 cp_clistate
->cli_share_dst
,
3345 c
->opt_acls
? true : false,
3346 c
->opt_attrs
? true : false,
3347 c
->opt_timestamps
? true: false,
3351 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3355 if (!NT_STATUS_IS_OK(nt_status
)) {
3356 printf("Could handle directory attributes for top level directory of share %s. Error %s\n",
3357 sharename
, nt_errstr(nt_status
));
3365 * Sync all files inside a remote share to another share (over smb).
3367 * All parameters are provided by the run_rpc_command function, except for
3368 * argc, argv which are passed through.
3370 * @param domain_sid The domain sid acquired from the remote server.
3371 * @param cli A cli_state connected to the server.
3372 * @param mem_ctx Talloc context, destroyed on completion of the function.
3373 * @param argc Standard main() style argc.
3374 * @param argv Standard main() style argv. Initial components are already
3377 * @return Normal NTSTATUS return.
3380 static NTSTATUS
rpc_share_migrate_files_internals(struct net_context
*c
,
3381 const DOM_SID
*domain_sid
,
3382 const char *domain_name
,
3383 struct cli_state
*cli
,
3384 struct rpc_pipe_client
*pipe_hnd
,
3385 TALLOC_CTX
*mem_ctx
,
3390 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3391 struct srvsvc_NetShareInfoCtr ctr_src
;
3394 struct copy_clistate cp_clistate
;
3395 bool got_src_share
= false;
3396 bool got_dst_share
= false;
3397 const char *mask
= "\\*";
3400 dst
= SMB_STRDUP(c
->opt_destination
?c
->opt_destination
:"127.0.0.1");
3402 nt_status
= NT_STATUS_NO_MEMORY
;
3406 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3409 if (!W_ERROR_IS_OK(result
))
3412 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3414 struct srvsvc_NetShareInfo502 info502
=
3415 ctr_src
.ctr
.ctr502
->array
[i
];
3417 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3420 /* one might not want to mirror whole discs :) */
3421 if (strequal(info502
.name
, "print$") || info502
.name
[1] == '$') {
3422 d_printf("skipping [%s]: builtin/hidden share\n", info502
.name
);
3426 switch (net_mode_share
)
3428 case NET_MODE_SHARE_MIGRATE
:
3432 d_fprintf(stderr
, "Unsupported mode %d\n", net_mode_share
);
3435 printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
3437 c
->opt_acls
? "including" : "without",
3438 c
->opt_attrs
? "including" : "without",
3439 c
->opt_timestamps
? "(preserving timestamps)" : "");
3441 cp_clistate
.mem_ctx
= mem_ctx
;
3442 cp_clistate
.cli_share_src
= NULL
;
3443 cp_clistate
.cli_share_dst
= NULL
;
3444 cp_clistate
.cwd
= NULL
;
3445 cp_clistate
.attribute
= aSYSTEM
| aHIDDEN
| aDIR
;
3448 /* open share source */
3449 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_src
,
3450 &cli
->dest_ss
, cli
->desthost
,
3451 info502
.name
, "A:");
3452 if (!NT_STATUS_IS_OK(nt_status
))
3455 got_src_share
= true;
3457 if (net_mode_share
== NET_MODE_SHARE_MIGRATE
) {
3458 /* open share destination */
3459 nt_status
= connect_to_service(c
, &cp_clistate
.cli_share_dst
,
3460 NULL
, dst
, info502
.name
, "A:");
3461 if (!NT_STATUS_IS_OK(nt_status
))
3464 got_dst_share
= true;
3467 if (!copy_top_level_perms(c
, &cp_clistate
, info502
.name
)) {
3468 d_fprintf(stderr
, "Could not handle the top level directory permissions for the share: %s\n", info502
.name
);
3469 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3473 if (!sync_files(&cp_clistate
, mask
)) {
3474 d_fprintf(stderr
, "could not handle files for share: %s\n", info502
.name
);
3475 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3480 nt_status
= NT_STATUS_OK
;
3485 cli_shutdown(cp_clistate
.cli_share_src
);
3488 cli_shutdown(cp_clistate
.cli_share_dst
);
3495 static int rpc_share_migrate_files(struct net_context
*c
, int argc
, const char **argv
)
3497 if (c
->display_usage
) {
3499 "net share migrate files\n"
3500 " Migrate files to local server\n");
3505 d_printf("no server to migrate\n");
3509 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3510 rpc_share_migrate_files_internals
,
3515 * Migrate share-ACLs from a remote RPC server to the local RPC server.
3517 * All parameters are provided by the run_rpc_command function, except for
3518 * argc, argv which are passed through.
3520 * @param domain_sid The domain sid acquired from the remote server.
3521 * @param cli A cli_state connected to the server.
3522 * @param mem_ctx Talloc context, destroyed on completion of the function.
3523 * @param argc Standard main() style argc.
3524 * @param argv Standard main() style argv. Initial components are already
3527 * @return Normal NTSTATUS return.
3530 static NTSTATUS
rpc_share_migrate_security_internals(struct net_context
*c
,
3531 const DOM_SID
*domain_sid
,
3532 const char *domain_name
,
3533 struct cli_state
*cli
,
3534 struct rpc_pipe_client
*pipe_hnd
,
3535 TALLOC_CTX
*mem_ctx
,
3540 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
3541 struct srvsvc_NetShareInfoCtr ctr_src
;
3542 union srvsvc_NetShareInfo info
;
3544 struct rpc_pipe_client
*srvsvc_pipe
= NULL
;
3545 struct cli_state
*cli_dst
= NULL
;
3546 uint32 level
= 502; /* includes secdesc */
3547 uint32_t parm_error
= 0;
3549 result
= get_share_info(c
, pipe_hnd
, mem_ctx
, level
, argc
, argv
,
3552 if (!W_ERROR_IS_OK(result
))
3555 /* connect destination PI_SRVSVC */
3556 nt_status
= connect_dst_pipe(c
, &cli_dst
, &srvsvc_pipe
,
3557 &ndr_table_srvsvc
.syntax_id
);
3558 if (!NT_STATUS_IS_OK(nt_status
))
3562 for (i
= 0; i
< ctr_src
.ctr
.ctr502
->count
; i
++) {
3564 struct srvsvc_NetShareInfo502 info502
=
3565 ctr_src
.ctr
.ctr502
->array
[i
];
3567 /* reset error-code */
3568 nt_status
= NT_STATUS_UNSUCCESSFUL
;
3570 if (!check_share_sanity(c
, cli
, info502
.name
, info502
.type
))
3573 printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
3574 info502
.name
, info502
.path
, info502
.comment
);
3577 display_sec_desc(info502
.sd_buf
.sd
);
3579 /* FIXME: shouldn't we be able to just set the security descriptor ? */
3580 info
.info502
= &info502
;
3582 /* finally modify the share on the dst server */
3583 nt_status
= rpccli_srvsvc_NetShareSetInfo(srvsvc_pipe
, mem_ctx
,
3584 srvsvc_pipe
->desthost
,
3590 if (!NT_STATUS_IS_OK(nt_status
) || !W_ERROR_IS_OK(result
)) {
3591 printf("cannot set share-acl: %s\n", win_errstr(result
));
3597 nt_status
= NT_STATUS_OK
;
3601 cli_shutdown(cli_dst
);
3609 * Migrate share-acls from a RPC server to another.
3611 * @param argc Standard main() style argc.
3612 * @param argv Standard main() style argv. Initial components are already
3615 * @return A shell status integer (0 for success).
3617 static int rpc_share_migrate_security(struct net_context
*c
, int argc
,
3620 if (c
->display_usage
) {
3622 "net rpc share migrate security\n"
3623 " Migrate share-acls to local server\n");
3628 d_printf("no server to migrate\n");
3632 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3633 rpc_share_migrate_security_internals
,
3638 * Migrate shares (including share-definitions, share-acls and files with acls/attrs)
3639 * from one server to another.
3641 * @param argc Standard main() style argc.
3642 * @param argv Standard main() style argv. Initial components are already
3645 * @return A shell status integer (0 for success).
3648 static int rpc_share_migrate_all(struct net_context
*c
, int argc
,
3653 if (c
->display_usage
) {
3655 "net rpc share migrate all\n"
3656 " Migrates shares including all share settings\n");
3661 d_printf("no server to migrate\n");
3665 /* order is important. we don't want to be locked out by the share-acl
3666 * before copying files - gd */
3668 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3669 rpc_share_migrate_shares_internals
, argc
, argv
);
3673 ret
= run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3674 rpc_share_migrate_files_internals
, argc
, argv
);
3678 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
3679 rpc_share_migrate_security_internals
, argc
,
3685 * 'net rpc share migrate' entrypoint.
3686 * @param argc Standard main() style argc.
3687 * @param argv Standard main() style argv. Initial components are already
3690 static int rpc_share_migrate(struct net_context
*c
, int argc
, const char **argv
)
3693 struct functable func
[] = {
3696 rpc_share_migrate_all
,
3698 "Migrate shares from remote to local server",
3699 "net rpc share migrate all\n"
3700 " Migrate shares from remote to local server"
3704 rpc_share_migrate_files
,
3706 "Migrate files from remote to local server",
3707 "net rpc share migrate files\n"
3708 " Migrate files from remote to local server"
3712 rpc_share_migrate_security
,
3714 "Migrate share-ACLs from remote to local server",
3715 "net rpc share migrate security\n"
3716 " Migrate share-ACLs from remote to local server"
3720 rpc_share_migrate_shares
,
3722 "Migrate shares from remote to local server",
3723 "net rpc share migrate shares\n"
3724 " Migrate shares from remote to local server"
3726 {NULL
, NULL
, 0, NULL
, NULL
}
3729 net_mode_share
= NET_MODE_SHARE_MIGRATE
;
3731 return net_run_function(c
, argc
, argv
, "net rpc share migrate", func
);
3740 static int num_server_aliases
;
3741 static struct full_alias
*server_aliases
;
3744 * Add an alias to the static list.
3746 static void push_alias(TALLOC_CTX
*mem_ctx
, struct full_alias
*alias
)
3748 if (server_aliases
== NULL
)
3749 server_aliases
= SMB_MALLOC_ARRAY(struct full_alias
, 100);
3751 server_aliases
[num_server_aliases
] = *alias
;
3752 num_server_aliases
+= 1;
3756 * For a specific domain on the server, fetch all the aliases
3757 * and their members. Add all of them to the server_aliases.
3760 static NTSTATUS
rpc_fetch_domain_aliases(struct rpc_pipe_client
*pipe_hnd
,
3761 TALLOC_CTX
*mem_ctx
,
3762 struct policy_handle
*connect_pol
,
3763 const DOM_SID
*domain_sid
)
3765 uint32 start_idx
, max_entries
, num_entries
, i
;
3766 struct samr_SamArray
*groups
= NULL
;
3768 struct policy_handle domain_pol
;
3770 /* Get domain policy handle */
3772 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
3774 MAXIMUM_ALLOWED_ACCESS
,
3775 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
3777 if (!NT_STATUS_IS_OK(result
))
3784 result
= rpccli_samr_EnumDomainAliases(pipe_hnd
, mem_ctx
,
3790 for (i
= 0; i
< num_entries
; i
++) {
3792 struct policy_handle alias_pol
;
3793 struct full_alias alias
;
3794 struct lsa_SidArray sid_array
;
3797 result
= rpccli_samr_OpenAlias(pipe_hnd
, mem_ctx
,
3799 MAXIMUM_ALLOWED_ACCESS
,
3800 groups
->entries
[i
].idx
,
3802 if (!NT_STATUS_IS_OK(result
))
3805 result
= rpccli_samr_GetMembersInAlias(pipe_hnd
, mem_ctx
,
3808 if (!NT_STATUS_IS_OK(result
))
3811 alias
.num_members
= sid_array
.num_sids
;
3813 result
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &alias_pol
);
3814 if (!NT_STATUS_IS_OK(result
))
3817 alias
.members
= NULL
;
3819 if (alias
.num_members
> 0) {
3820 alias
.members
= SMB_MALLOC_ARRAY(DOM_SID
, alias
.num_members
);
3822 for (j
= 0; j
< alias
.num_members
; j
++)
3823 sid_copy(&alias
.members
[j
],
3824 sid_array
.sids
[j
].sid
);
3827 sid_copy(&alias
.sid
, domain_sid
);
3828 sid_append_rid(&alias
.sid
, groups
->entries
[i
].idx
);
3830 push_alias(mem_ctx
, &alias
);
3832 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
3834 result
= NT_STATUS_OK
;
3837 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_pol
);
3843 * Dump server_aliases as names for debugging purposes.
3846 static NTSTATUS
rpc_aliaslist_dump(struct net_context
*c
,
3847 const DOM_SID
*domain_sid
,
3848 const char *domain_name
,
3849 struct cli_state
*cli
,
3850 struct rpc_pipe_client
*pipe_hnd
,
3851 TALLOC_CTX
*mem_ctx
,
3857 struct policy_handle lsa_pol
;
3859 result
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
3860 SEC_FLAG_MAXIMUM_ALLOWED
,
3862 if (!NT_STATUS_IS_OK(result
))
3865 for (i
=0; i
<num_server_aliases
; i
++) {
3868 enum lsa_SidType
*types
;
3871 struct full_alias
*alias
= &server_aliases
[i
];
3873 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
, 1,
3875 &domains
, &names
, &types
);
3876 if (!NT_STATUS_IS_OK(result
))
3879 DEBUG(1, ("%s\\%s %d: ", domains
[0], names
[0], types
[0]));
3881 if (alias
->num_members
== 0) {
3886 result
= rpccli_lsa_lookup_sids(pipe_hnd
, mem_ctx
, &lsa_pol
,
3889 &domains
, &names
, &types
);
3891 if (!NT_STATUS_IS_OK(result
) &&
3892 !NT_STATUS_EQUAL(result
, STATUS_SOME_UNMAPPED
))
3895 for (j
=0; j
<alias
->num_members
; j
++)
3896 DEBUG(1, ("%s\\%s (%d); ",
3897 domains
[j
] ? domains
[j
] : "*unknown*",
3898 names
[j
] ? names
[j
] : "*unknown*",types
[j
]));
3902 rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &lsa_pol
);
3904 return NT_STATUS_OK
;
3908 * Fetch a list of all server aliases and their members into
3912 static NTSTATUS
rpc_aliaslist_internals(struct net_context
*c
,
3913 const DOM_SID
*domain_sid
,
3914 const char *domain_name
,
3915 struct cli_state
*cli
,
3916 struct rpc_pipe_client
*pipe_hnd
,
3917 TALLOC_CTX
*mem_ctx
,
3922 struct policy_handle connect_pol
;
3924 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
3926 MAXIMUM_ALLOWED_ACCESS
,
3929 if (!NT_STATUS_IS_OK(result
))
3932 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3933 &global_sid_Builtin
);
3935 if (!NT_STATUS_IS_OK(result
))
3938 result
= rpc_fetch_domain_aliases(pipe_hnd
, mem_ctx
, &connect_pol
,
3941 rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_pol
);
3946 static void init_user_token(NT_USER_TOKEN
*token
, DOM_SID
*user_sid
)
3948 token
->num_sids
= 4;
3950 if (!(token
->user_sids
= SMB_MALLOC_ARRAY(DOM_SID
, 4))) {
3951 d_fprintf(stderr
, "malloc failed\n");
3952 token
->num_sids
= 0;
3956 token
->user_sids
[0] = *user_sid
;
3957 sid_copy(&token
->user_sids
[1], &global_sid_World
);
3958 sid_copy(&token
->user_sids
[2], &global_sid_Network
);
3959 sid_copy(&token
->user_sids
[3], &global_sid_Authenticated_Users
);
3962 static void free_user_token(NT_USER_TOKEN
*token
)
3964 SAFE_FREE(token
->user_sids
);
3967 static void add_sid_to_token(NT_USER_TOKEN
*token
, DOM_SID
*sid
)
3969 if (is_sid_in_token(token
, sid
))
3972 token
->user_sids
= SMB_REALLOC_ARRAY(token
->user_sids
, DOM_SID
, token
->num_sids
+1);
3973 if (!token
->user_sids
) {
3977 sid_copy(&token
->user_sids
[token
->num_sids
], sid
);
3979 token
->num_sids
+= 1;
3984 NT_USER_TOKEN token
;
3987 static void dump_user_token(struct user_token
*token
)
3991 d_printf("%s\n", token
->name
);
3993 for (i
=0; i
<token
->token
.num_sids
; i
++) {
3994 d_printf(" %s\n", sid_string_tos(&token
->token
.user_sids
[i
]));
3998 static bool is_alias_member(DOM_SID
*sid
, struct full_alias
*alias
)
4002 for (i
=0; i
<alias
->num_members
; i
++) {
4003 if (sid_compare(sid
, &alias
->members
[i
]) == 0)
4010 static void collect_sid_memberships(NT_USER_TOKEN
*token
, DOM_SID sid
)
4014 for (i
=0; i
<num_server_aliases
; i
++) {
4015 if (is_alias_member(&sid
, &server_aliases
[i
]))
4016 add_sid_to_token(token
, &server_aliases
[i
].sid
);
4021 * We got a user token with all the SIDs we can know about without asking the
4022 * server directly. These are the user and domain group sids. All of these can
4023 * be members of aliases. So scan the list of aliases for each of the SIDs and
4024 * add them to the token.
4027 static void collect_alias_memberships(NT_USER_TOKEN
*token
)
4029 int num_global_sids
= token
->num_sids
;
4032 for (i
=0; i
<num_global_sids
; i
++) {
4033 collect_sid_memberships(token
, token
->user_sids
[i
]);
4037 static bool get_user_sids(const char *domain
, const char *user
, NT_USER_TOKEN
*token
)
4039 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4040 enum wbcSidType type
;
4042 struct wbcDomainSid wsid
;
4043 char *sid_str
= NULL
;
4045 uint32_t num_groups
;
4046 gid_t
*groups
= NULL
;
4049 fstr_sprintf(full_name
, "%s%c%s",
4050 domain
, *lp_winbind_separator(), user
);
4052 /* First let's find out the user sid */
4054 wbc_status
= wbcLookupName(domain
, user
, &wsid
, &type
);
4056 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4057 DEBUG(1, ("winbind could not find %s: %s\n",
4058 full_name
, wbcErrorString(wbc_status
)));
4062 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4063 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4067 if (type
!= SID_NAME_USER
) {
4068 wbcFreeMemory(sid_str
);
4069 DEBUG(1, ("%s is not a user\n", full_name
));
4073 if (!string_to_sid(&user_sid
, sid_str
)) {
4074 DEBUG(1,("Could not convert sid %s from string\n", sid_str
));
4078 wbcFreeMemory(sid_str
);
4081 init_user_token(token
, &user_sid
);
4083 /* And now the groups winbind knows about */
4085 wbc_status
= wbcGetGroups(full_name
, &num_groups
, &groups
);
4086 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4087 DEBUG(1, ("winbind could not get groups of %s: %s\n",
4088 full_name
, wbcErrorString(wbc_status
)));
4092 for (i
= 0; i
< num_groups
; i
++) {
4093 gid_t gid
= groups
[i
];
4096 wbc_status
= wbcGidToSid(gid
, &wsid
);
4097 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4098 DEBUG(1, ("winbind could not find SID of gid %u: %s\n",
4099 (unsigned int)gid
, wbcErrorString(wbc_status
)));
4100 wbcFreeMemory(groups
);
4104 wbc_status
= wbcSidToString(&wsid
, &sid_str
);
4105 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4106 wbcFreeMemory(groups
);
4110 DEBUG(3, (" %s\n", sid_str
));
4112 string_to_sid(&sid
, sid_str
);
4113 wbcFreeMemory(sid_str
);
4116 add_sid_to_token(token
, &sid
);
4118 wbcFreeMemory(groups
);
4124 * Get a list of all user tokens we want to look at
4127 static bool get_user_tokens(struct net_context
*c
, int *num_tokens
,
4128 struct user_token
**user_tokens
)
4130 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
4131 uint32_t i
, num_users
;
4133 struct user_token
*result
;
4134 TALLOC_CTX
*frame
= NULL
;
4136 if (lp_winbind_use_default_domain() &&
4137 (c
->opt_target_workgroup
== NULL
)) {
4138 d_fprintf(stderr
, "winbind use default domain = yes set, "
4139 "please specify a workgroup\n");
4143 /* Send request to winbind daemon */
4145 wbc_status
= wbcListUsers(NULL
, &num_users
, &users
);
4146 if (!WBC_ERROR_IS_OK(wbc_status
)) {
4147 DEBUG(1, ("winbind could not list users: %s\n",
4148 wbcErrorString(wbc_status
)));
4152 result
= SMB_MALLOC_ARRAY(struct user_token
, num_users
);
4154 if (result
== NULL
) {
4155 DEBUG(1, ("Could not malloc sid array\n"));
4156 wbcFreeMemory(users
);
4160 frame
= talloc_stackframe();
4161 for (i
=0; i
< num_users
; i
++) {
4162 fstring domain
, user
;
4165 fstrcpy(result
[i
].name
, users
[i
]);
4167 p
= strchr(users
[i
], *lp_winbind_separator());
4169 DEBUG(3, ("%s\n", users
[i
]));
4172 fstrcpy(domain
, c
->opt_target_workgroup
);
4173 fstrcpy(user
, users
[i
]);
4176 fstrcpy(domain
, users
[i
]);
4181 get_user_sids(domain
, user
, &(result
[i
].token
));
4185 wbcFreeMemory(users
);
4187 *num_tokens
= num_users
;
4188 *user_tokens
= result
;
4193 static bool get_user_tokens_from_file(FILE *f
,
4195 struct user_token
**tokens
)
4197 struct user_token
*token
= NULL
;
4202 if (fgets(line
, sizeof(line
)-1, f
) == NULL
) {
4206 if (line
[strlen(line
)-1] == '\n')
4207 line
[strlen(line
)-1] = '\0';
4209 if (line
[0] == ' ') {
4213 if(!string_to_sid(&sid
, &line
[1])) {
4214 DEBUG(1,("get_user_tokens_from_file: Could "
4215 "not convert sid %s \n",&line
[1]));
4219 if (token
== NULL
) {
4220 DEBUG(0, ("File does not begin with username"));
4224 add_sid_to_token(&token
->token
, &sid
);
4228 /* And a new user... */
4231 *tokens
= SMB_REALLOC_ARRAY(*tokens
, struct user_token
, *num_tokens
);
4232 if (*tokens
== NULL
) {
4233 DEBUG(0, ("Could not realloc tokens\n"));
4237 token
= &((*tokens
)[*num_tokens
-1]);
4239 fstrcpy(token
->name
, line
);
4240 token
->token
.num_sids
= 0;
4241 token
->token
.user_sids
= NULL
;
4250 * Show the list of all users that have access to a share
4253 static void show_userlist(struct rpc_pipe_client
*pipe_hnd
,
4254 TALLOC_CTX
*mem_ctx
,
4255 const char *netname
,
4257 struct user_token
*tokens
)
4260 SEC_DESC
*share_sd
= NULL
;
4261 SEC_DESC
*root_sd
= NULL
;
4262 struct cli_state
*cli
= rpc_pipe_np_smb_conn(pipe_hnd
);
4264 union srvsvc_NetShareInfo info
;
4269 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4276 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4277 DEBUG(1, ("Coult not query secdesc for share %s\n",
4282 share_sd
= info
.info502
->sd_buf
.sd
;
4283 if (share_sd
== NULL
) {
4284 DEBUG(1, ("Got no secdesc for share %s\n",
4290 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, netname
, "A:", "", 0))) {
4294 fnum
= cli_nt_create(cli
, "\\", READ_CONTROL_ACCESS
);
4297 root_sd
= cli_query_secdesc(cli
, fnum
, mem_ctx
);
4300 for (i
=0; i
<num_tokens
; i
++) {
4303 if (share_sd
!= NULL
) {
4304 status
= se_access_check(share_sd
, &tokens
[i
].token
,
4307 if (!NT_STATUS_IS_OK(status
)) {
4308 DEBUG(1, ("Could not check share_sd for "
4315 if (root_sd
== NULL
) {
4316 d_printf(" %s\n", tokens
[i
].name
);
4320 status
= se_access_check(root_sd
, &tokens
[i
].token
,
4322 if (!NT_STATUS_IS_OK(status
)) {
4323 DEBUG(1, ("Could not check root_sd for user %s\n",
4327 d_printf(" %s\n", tokens
[i
].name
);
4331 cli_close(cli
, fnum
);
4343 static void collect_share(const char *name
, uint32 m
,
4344 const char *comment
, void *state
)
4346 struct share_list
*share_list
= (struct share_list
*)state
;
4348 if (m
!= STYPE_DISKTREE
)
4351 share_list
->num_shares
+= 1;
4352 share_list
->shares
= SMB_REALLOC_ARRAY(share_list
->shares
, char *, share_list
->num_shares
);
4353 if (!share_list
->shares
) {
4354 share_list
->num_shares
= 0;
4357 share_list
->shares
[share_list
->num_shares
-1] = SMB_STRDUP(name
);
4361 * List shares on a remote RPC server, including the security descriptors.
4363 * All parameters are provided by the run_rpc_command function, except for
4364 * argc, argv which are passed through.
4366 * @param domain_sid The domain sid acquired from the remote server.
4367 * @param cli A cli_state connected to the server.
4368 * @param mem_ctx Talloc context, destroyed on completion of the function.
4369 * @param argc Standard main() style argc.
4370 * @param argv Standard main() style argv. Initial components are already
4373 * @return Normal NTSTATUS return.
4376 static NTSTATUS
rpc_share_allowedusers_internals(struct net_context
*c
,
4377 const DOM_SID
*domain_sid
,
4378 const char *domain_name
,
4379 struct cli_state
*cli
,
4380 struct rpc_pipe_client
*pipe_hnd
,
4381 TALLOC_CTX
*mem_ctx
,
4390 struct user_token
*tokens
= NULL
;
4393 struct share_list share_list
;
4398 f
= fopen(argv
[0], "r");
4402 DEBUG(0, ("Could not open userlist: %s\n", strerror(errno
)));
4403 return NT_STATUS_UNSUCCESSFUL
;
4406 r
= get_user_tokens_from_file(f
, &num_tokens
, &tokens
);
4412 DEBUG(0, ("Could not read users from file\n"));
4413 return NT_STATUS_UNSUCCESSFUL
;
4416 for (i
=0; i
<num_tokens
; i
++)
4417 collect_alias_memberships(&tokens
[i
].token
);
4419 share_list
.num_shares
= 0;
4420 share_list
.shares
= NULL
;
4422 ret
= cli_RNetShareEnum(cli
, collect_share
, &share_list
);
4425 DEBUG(0, ("Error returning browse list: %s\n",
4430 for (i
= 0; i
< share_list
.num_shares
; i
++) {
4431 char *netname
= share_list
.shares
[i
];
4433 if (netname
[strlen(netname
)-1] == '$')
4436 d_printf("%s\n", netname
);
4438 show_userlist(pipe_hnd
, mem_ctx
, netname
,
4439 num_tokens
, tokens
);
4442 for (i
=0; i
<num_tokens
; i
++) {
4443 free_user_token(&tokens
[i
].token
);
4446 SAFE_FREE(share_list
.shares
);
4448 return NT_STATUS_OK
;
4451 static int rpc_share_allowedusers(struct net_context
*c
, int argc
,
4456 if (c
->display_usage
) {
4458 "net rpc share allowedusers\n"
4459 " List allowed users\n");
4463 result
= run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
4464 rpc_aliaslist_internals
,
4469 result
= run_rpc_command(c
, NULL
, &ndr_table_lsarpc
.syntax_id
, 0,
4475 return run_rpc_command(c
, NULL
, &ndr_table_srvsvc
.syntax_id
, 0,
4476 rpc_share_allowedusers_internals
,
4480 int net_usersidlist(struct net_context
*c
, int argc
, const char **argv
)
4483 struct user_token
*tokens
= NULL
;
4487 net_usersidlist_usage(c
, argc
, argv
);
4491 if (!get_user_tokens(c
, &num_tokens
, &tokens
)) {
4492 DEBUG(0, ("Could not get the user/sid list\n"));
4496 for (i
=0; i
<num_tokens
; i
++) {
4497 dump_user_token(&tokens
[i
]);
4498 free_user_token(&tokens
[i
].token
);
4505 int net_usersidlist_usage(struct net_context
*c
, int argc
, const char **argv
)
4507 d_printf("net usersidlist\n"
4508 "\tprints out a list of all users the running winbind knows\n"
4509 "\tabout, together with all their SIDs. This is used as\n"
4510 "\tinput to the 'net rpc share allowedusers' command.\n\n");
4512 net_common_flags_usage(c
, argc
, argv
);
4517 * 'net rpc share' entrypoint.
4518 * @param argc Standard main() style argc.
4519 * @param argv Standard main() style argv. Initial components are already
4523 int net_rpc_share(struct net_context
*c
, int argc
, const char **argv
)
4525 NET_API_STATUS status
;
4527 struct functable func
[] = {
4533 "net rpc share add\n"
4541 "net rpc share delete\n"
4546 rpc_share_allowedusers
,
4548 "Modify allowed users",
4549 "net rpc share allowedusers\n"
4550 " Modify allowed users"
4556 "Migrate share to local server",
4557 "net rpc share migrate\n"
4558 " Migrate share to local server"
4565 "net rpc share list\n"
4568 {NULL
, NULL
, 0, NULL
, NULL
}
4571 status
= libnetapi_init(&c
->netapi_ctx
);
4575 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4576 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4577 if (c
->opt_kerberos
) {
4578 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4582 if (c
->display_usage
) {
4586 " Alias for net rpc share list\n");
4587 net_display_usage_from_functable(func
);
4591 return rpc_share_list(c
, argc
, argv
);
4594 return net_run_function(c
, argc
, argv
, "net rpc share", func
);
4597 static NTSTATUS
rpc_sh_share_list(struct net_context
*c
,
4598 TALLOC_CTX
*mem_ctx
,
4599 struct rpc_sh_ctx
*ctx
,
4600 struct rpc_pipe_client
*pipe_hnd
,
4601 int argc
, const char **argv
)
4604 return werror_to_ntstatus(W_ERROR(rpc_share_list(c
, argc
, argv
)));
4607 static NTSTATUS
rpc_sh_share_add(struct net_context
*c
,
4608 TALLOC_CTX
*mem_ctx
,
4609 struct rpc_sh_ctx
*ctx
,
4610 struct rpc_pipe_client
*pipe_hnd
,
4611 int argc
, const char **argv
)
4613 NET_API_STATUS status
;
4614 uint32_t parm_err
= 0;
4615 struct SHARE_INFO_2 i2
;
4617 if ((argc
< 2) || (argc
> 3)) {
4618 d_fprintf(stderr
, "usage: %s <share> <path> [comment]\n",
4620 return NT_STATUS_INVALID_PARAMETER
;
4623 i2
.shi2_netname
= argv
[0];
4624 i2
.shi2_type
= STYPE_DISKTREE
;
4625 i2
.shi2_remark
= (argc
== 3) ? argv
[2] : "";
4626 i2
.shi2_permissions
= 0;
4627 i2
.shi2_max_uses
= 0;
4628 i2
.shi2_current_uses
= 0;
4629 i2
.shi2_path
= argv
[1];
4630 i2
.shi2_passwd
= NULL
;
4632 status
= NetShareAdd(pipe_hnd
->desthost
,
4637 return werror_to_ntstatus(W_ERROR(status
));
4640 static NTSTATUS
rpc_sh_share_delete(struct net_context
*c
,
4641 TALLOC_CTX
*mem_ctx
,
4642 struct rpc_sh_ctx
*ctx
,
4643 struct rpc_pipe_client
*pipe_hnd
,
4644 int argc
, const char **argv
)
4647 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4648 return NT_STATUS_INVALID_PARAMETER
;
4651 return werror_to_ntstatus(W_ERROR(NetShareDel(pipe_hnd
->desthost
, argv
[0], 0)));
4654 static NTSTATUS
rpc_sh_share_info(struct net_context
*c
,
4655 TALLOC_CTX
*mem_ctx
,
4656 struct rpc_sh_ctx
*ctx
,
4657 struct rpc_pipe_client
*pipe_hnd
,
4658 int argc
, const char **argv
)
4660 union srvsvc_NetShareInfo info
;
4665 d_fprintf(stderr
, "usage: %s <share>\n", ctx
->whoami
);
4666 return NT_STATUS_INVALID_PARAMETER
;
4669 status
= rpccli_srvsvc_NetShareGetInfo(pipe_hnd
, mem_ctx
,
4675 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
4679 d_printf("Name: %s\n", info
.info2
->name
);
4680 d_printf("Comment: %s\n", info
.info2
->comment
);
4681 d_printf("Path: %s\n", info
.info2
->path
);
4682 d_printf("Password: %s\n", info
.info2
->password
);
4685 return werror_to_ntstatus(result
);
4688 struct rpc_sh_cmd
*net_rpc_share_cmds(struct net_context
*c
, TALLOC_CTX
*mem_ctx
,
4689 struct rpc_sh_ctx
*ctx
)
4691 static struct rpc_sh_cmd cmds
[] = {
4693 { "list", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_list
,
4694 "List available shares" },
4696 { "add", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_add
,
4699 { "delete", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_delete
,
4702 { "info", NULL
, &ndr_table_srvsvc
.syntax_id
, rpc_sh_share_info
,
4703 "Get information about a share" },
4705 { NULL
, NULL
, 0, NULL
, NULL
}
4711 /****************************************************************************/
4713 static int rpc_file_usage(struct net_context
*c
, int argc
, const char **argv
)
4715 return net_file_usage(c
, argc
, argv
);
4719 * Close a file on a remote RPC server.
4721 * @param argc Standard main() style argc.
4722 * @param argv Standard main() style argv. Initial components are already
4725 * @return A shell status integer (0 for success).
4727 static int rpc_file_close(struct net_context
*c
, int argc
, const char **argv
)
4729 if (argc
< 1 || c
->display_usage
) {
4730 return rpc_file_usage(c
, argc
, argv
);
4733 return NetFileClose(c
->opt_host
, atoi(argv
[0]));
4737 * Formatted print of open file info
4739 * @param r struct FILE_INFO_3 contents
4742 static void display_file_info_3(struct FILE_INFO_3
*r
)
4744 d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
4745 r
->fi3_id
, r
->fi3_username
, r
->fi3_permissions
,
4746 r
->fi3_num_locks
, r
->fi3_pathname
);
4750 * List files for a user on a remote RPC server.
4752 * @param argc Standard main() style argc.
4753 * @param argv Standard main() style argv. Initial components are already
4756 * @return A shell status integer (0 for success)..
4759 static int rpc_file_user(struct net_context
*c
, int argc
, const char **argv
)
4761 NET_API_STATUS status
;
4762 uint32 preferred_len
= 0xffffffff, i
;
4763 const char *username
=NULL
;
4764 uint32_t total_entries
= 0;
4765 uint32_t entries_read
= 0;
4766 uint32_t resume_handle
= 0;
4767 struct FILE_INFO_3
*i3
= NULL
;
4769 if (c
->display_usage
) {
4770 return rpc_file_usage(c
, argc
, argv
);
4773 /* if argc > 0, must be user command */
4775 username
= smb_xstrdup(argv
[0]);
4778 status
= NetFileEnum(c
->opt_host
,
4782 (uint8_t **)(void *)&i3
,
4792 /* Display results */
4795 "\nEnumerating open files on remote server:\n\n"
4796 "\nFileId Opened by Perms Locks Path"
4797 "\n------ --------- ----- ----- ---- \n");
4798 for (i
= 0; i
< entries_read
; i
++) {
4799 display_file_info_3(&i3
[i
]);
4806 * 'net rpc file' entrypoint.
4807 * @param argc Standard main() style argc.
4808 * @param argv Standard main() style argv. Initial components are already
4812 int net_rpc_file(struct net_context
*c
, int argc
, const char **argv
)
4814 NET_API_STATUS status
;
4816 struct functable func
[] = {
4821 "Close opened file",
4822 "net rpc file close\n"
4823 " Close opened file"
4829 "List files opened by user",
4830 "net rpc file user\n"
4831 " List files opened by user"
4838 "Display information about opened file",
4839 "net rpc file info\n"
4840 " Display information about opened file"
4843 {NULL
, NULL
, 0, NULL
, NULL
}
4846 status
= libnetapi_init(&c
->netapi_ctx
);
4850 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
4851 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
4852 if (c
->opt_kerberos
) {
4853 libnetapi_set_use_kerberos(c
->netapi_ctx
);
4857 if (c
->display_usage
) {
4858 d_printf("Usage:\n");
4859 d_printf("net rpc file\n"
4860 " List opened files\n");
4861 net_display_usage_from_functable(func
);
4865 return rpc_file_user(c
, argc
, argv
);
4868 return net_run_function(c
, argc
, argv
, "net rpc file", func
);
4872 * ABORT the shutdown of a remote RPC Server, over initshutdown pipe.
4874 * All parameters are provided by the run_rpc_command function, except for
4875 * argc, argv which are passed through.
4877 * @param c A net_context structure.
4878 * @param domain_sid The domain sid acquired from the remote server.
4879 * @param cli A cli_state connected to the server.
4880 * @param mem_ctx Talloc context, destroyed on completion of the function.
4881 * @param argc Standard main() style argc.
4882 * @param argv Standard main() style argv. Initial components are already
4885 * @return Normal NTSTATUS return.
4888 static NTSTATUS
rpc_shutdown_abort_internals(struct net_context
*c
,
4889 const DOM_SID
*domain_sid
,
4890 const char *domain_name
,
4891 struct cli_state
*cli
,
4892 struct rpc_pipe_client
*pipe_hnd
,
4893 TALLOC_CTX
*mem_ctx
,
4897 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4899 result
= rpccli_initshutdown_Abort(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4901 if (NT_STATUS_IS_OK(result
)) {
4902 d_printf("\nShutdown successfully aborted\n");
4903 DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
4905 DEBUG(5,("cmd_shutdown_abort: query failed\n"));
4911 * ABORT the shutdown of a remote RPC Server, over winreg pipe.
4913 * All parameters are provided by the run_rpc_command function, except for
4914 * argc, argv which are passed through.
4916 * @param c A net_context structure.
4917 * @param domain_sid The domain sid acquired from the remote server.
4918 * @param cli A cli_state connected to the server.
4919 * @param mem_ctx Talloc context, destroyed on completion of the function.
4920 * @param argc Standard main() style argc.
4921 * @param argv Standard main() style argv. Initial components are already
4924 * @return Normal NTSTATUS return.
4927 static NTSTATUS
rpc_reg_shutdown_abort_internals(struct net_context
*c
,
4928 const DOM_SID
*domain_sid
,
4929 const char *domain_name
,
4930 struct cli_state
*cli
,
4931 struct rpc_pipe_client
*pipe_hnd
,
4932 TALLOC_CTX
*mem_ctx
,
4936 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
4938 result
= rpccli_winreg_AbortSystemShutdown(pipe_hnd
, mem_ctx
, NULL
, NULL
);
4940 if (NT_STATUS_IS_OK(result
)) {
4941 d_printf("\nShutdown successfully aborted\n");
4942 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
4944 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
4950 * ABORT the shutdown of a remote RPC server.
4952 * @param argc Standard main() style argc.
4953 * @param argv Standard main() style argv. Initial components are already
4956 * @return A shell status integer (0 for success).
4959 static int rpc_shutdown_abort(struct net_context
*c
, int argc
,
4964 if (c
->display_usage
) {
4966 "net rpc abortshutdown\n"
4967 " Abort a scheduled shutdown\n");
4971 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
4972 rpc_shutdown_abort_internals
, argc
, argv
);
4977 DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
4979 return run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
4980 rpc_reg_shutdown_abort_internals
,
4985 * Shut down a remote RPC Server via initshutdown pipe.
4987 * All parameters are provided by the run_rpc_command function, except for
4988 * argc, argv which are passed through.
4990 * @param c A net_context structure.
4991 * @param domain_sid The domain sid acquired from the remote server.
4992 * @param cli A cli_state connected to the server.
4993 * @param mem_ctx Talloc context, destroyed on completion of the function.
4994 * @param argc Standard main() style argc.
4995 * @param argv Standard main() style argv. Initial components are already
4998 * @return Normal NTSTATUS return.
5001 NTSTATUS
rpc_init_shutdown_internals(struct net_context
*c
,
5002 const DOM_SID
*domain_sid
,
5003 const char *domain_name
,
5004 struct cli_state
*cli
,
5005 struct rpc_pipe_client
*pipe_hnd
,
5006 TALLOC_CTX
*mem_ctx
,
5010 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5011 const char *msg
= "This machine will be shutdown shortly";
5012 uint32 timeout
= 20;
5013 struct lsa_StringLarge msg_string
;
5015 if (c
->opt_comment
) {
5016 msg
= c
->opt_comment
;
5018 if (c
->opt_timeout
) {
5019 timeout
= c
->opt_timeout
;
5022 msg_string
.string
= msg
;
5024 /* create an entry */
5025 result
= rpccli_initshutdown_Init(pipe_hnd
, mem_ctx
, NULL
,
5026 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5029 if (NT_STATUS_IS_OK(result
)) {
5030 d_printf("\nShutdown of remote machine succeeded\n");
5031 DEBUG(5,("Shutdown of remote machine succeeded\n"));
5033 DEBUG(1,("Shutdown of remote machine failed!\n"));
5039 * Shut down a remote RPC Server via winreg pipe.
5041 * All parameters are provided by the run_rpc_command function, except for
5042 * argc, argv which are passed through.
5044 * @param c A net_context structure.
5045 * @param domain_sid The domain sid acquired from the remote server.
5046 * @param cli A cli_state connected to the server.
5047 * @param mem_ctx Talloc context, destroyed on completion of the function.
5048 * @param argc Standard main() style argc.
5049 * @param argv Standard main() style argv. Initial components are already
5052 * @return Normal NTSTATUS return.
5055 NTSTATUS
rpc_reg_shutdown_internals(struct net_context
*c
,
5056 const DOM_SID
*domain_sid
,
5057 const char *domain_name
,
5058 struct cli_state
*cli
,
5059 struct rpc_pipe_client
*pipe_hnd
,
5060 TALLOC_CTX
*mem_ctx
,
5064 const char *msg
= "This machine will be shutdown shortly";
5065 uint32 timeout
= 20;
5066 struct lsa_StringLarge msg_string
;
5070 if (c
->opt_comment
) {
5071 msg
= c
->opt_comment
;
5073 msg_string
.string
= msg
;
5075 if (c
->opt_timeout
) {
5076 timeout
= c
->opt_timeout
;
5079 /* create an entry */
5080 result
= rpccli_winreg_InitiateSystemShutdown(pipe_hnd
, mem_ctx
, NULL
,
5081 &msg_string
, timeout
, c
->opt_force
, c
->opt_reboot
,
5084 if (NT_STATUS_IS_OK(result
)) {
5085 d_printf("\nShutdown of remote machine succeeded\n");
5087 d_fprintf(stderr
, "\nShutdown of remote machine failed\n");
5088 if ( W_ERROR_EQUAL(werr
, WERR_MACHINE_LOCKED
) )
5089 d_fprintf(stderr
, "\nMachine locked, use -f switch to force\n");
5091 d_fprintf(stderr
, "\nresult was: %s\n", win_errstr(werr
));
5098 * Shut down a remote RPC server.
5100 * @param argc Standard main() style argc.
5101 * @param argv Standard main() style argv. Initial components are already
5104 * @return A shell status integer (0 for success).
5107 static int rpc_shutdown(struct net_context
*c
, int argc
, const char **argv
)
5111 if (c
->display_usage
) {
5113 "net rpc shutdown\n"
5114 " Shut down a remote RPC server\n");
5118 rc
= run_rpc_command(c
, NULL
, &ndr_table_initshutdown
.syntax_id
, 0,
5119 rpc_init_shutdown_internals
, argc
, argv
);
5122 DEBUG(1, ("initshutdown pipe failed, trying winreg pipe\n"));
5123 rc
= run_rpc_command(c
, NULL
, &ndr_table_winreg
.syntax_id
, 0,
5124 rpc_reg_shutdown_internals
, argc
, argv
);
5130 /***************************************************************************
5131 NT Domain trusts code (i.e. 'net rpc trustdom' functionality)
5132 ***************************************************************************/
5135 * Add interdomain trust account to the RPC server.
5136 * All parameters (except for argc and argv) are passed by run_rpc_command
5139 * @param c A net_context structure.
5140 * @param domain_sid The domain sid acquired from the server.
5141 * @param cli A cli_state connected to the server.
5142 * @param mem_ctx Talloc context, destroyed on completion of the function.
5143 * @param argc Standard main() style argc.
5144 * @param argv Standard main() style argv. Initial components are already
5147 * @return normal NTSTATUS return code.
5150 static NTSTATUS
rpc_trustdom_add_internals(struct net_context
*c
,
5151 const DOM_SID
*domain_sid
,
5152 const char *domain_name
,
5153 struct cli_state
*cli
,
5154 struct rpc_pipe_client
*pipe_hnd
,
5155 TALLOC_CTX
*mem_ctx
,
5159 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5160 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5162 struct lsa_String lsa_acct_name
;
5164 uint32 acct_flags
=0;
5166 uint32_t access_granted
= 0;
5167 union samr_UserInfo info
;
5168 unsigned int orig_timeout
;
5171 d_printf("Usage: net rpc trustdom add <domain_name> "
5172 "<trust password>\n");
5173 return NT_STATUS_INVALID_PARAMETER
;
5177 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5180 if (asprintf(&acct_name
, "%s$", argv
[0]) < 0) {
5181 return NT_STATUS_NO_MEMORY
;
5184 strupper_m(acct_name
);
5186 init_lsa_String(&lsa_acct_name
, acct_name
);
5188 /* Get samr policy handle */
5189 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5191 MAXIMUM_ALLOWED_ACCESS
,
5193 if (!NT_STATUS_IS_OK(result
)) {
5197 /* Get domain policy handle */
5198 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5200 MAXIMUM_ALLOWED_ACCESS
,
5201 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5203 if (!NT_STATUS_IS_OK(result
)) {
5207 /* This call can take a long time - allow the server to time out.
5208 * 35 seconds should do it. */
5210 orig_timeout
= rpccli_set_timeout(pipe_hnd
, 35000);
5212 /* Create trusting domain's account */
5213 acb_info
= ACB_NORMAL
;
5214 acct_flags
= SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
5215 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
5216 SAMR_USER_ACCESS_SET_PASSWORD
|
5217 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
5218 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5220 result
= rpccli_samr_CreateUser2(pipe_hnd
, mem_ctx
,
5229 /* And restore our original timeout. */
5230 rpccli_set_timeout(pipe_hnd
, orig_timeout
);
5232 if (!NT_STATUS_IS_OK(result
)) {
5233 d_printf("net rpc trustdom add: create user %s failed %s\n",
5234 acct_name
, nt_errstr(result
));
5239 struct samr_CryptPassword crypt_pwd
;
5241 ZERO_STRUCT(info
.info23
);
5243 init_samr_CryptPassword(argv
[1],
5244 &cli
->user_session_key
,
5247 info
.info23
.info
.fields_present
= SAMR_FIELD_ACCT_FLAGS
|
5248 SAMR_FIELD_NT_PASSWORD_PRESENT
;
5249 info
.info23
.info
.acct_flags
= ACB_DOMTRUST
;
5250 info
.info23
.password
= crypt_pwd
;
5252 result
= rpccli_samr_SetUserInfo2(pipe_hnd
, mem_ctx
,
5257 if (!NT_STATUS_IS_OK(result
)) {
5258 DEBUG(0,("Could not set trust account password: %s\n",
5259 nt_errstr(result
)));
5265 SAFE_FREE(acct_name
);
5270 * Create interdomain trust account for a remote domain.
5272 * @param argc Standard argc.
5273 * @param argv Standard argv without initial components.
5275 * @return Integer status (0 means success).
5278 static int rpc_trustdom_add(struct net_context
*c
, int argc
, const char **argv
)
5280 if (argc
> 0 && !c
->display_usage
) {
5281 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5282 rpc_trustdom_add_internals
, argc
, argv
);
5285 "net rpc trustdom add <domain_name> <trust password>\n");
5292 * Remove interdomain trust account from the RPC server.
5293 * All parameters (except for argc and argv) are passed by run_rpc_command
5296 * @param c A net_context structure.
5297 * @param domain_sid The domain sid acquired from the server.
5298 * @param cli A cli_state connected to the server.
5299 * @param mem_ctx Talloc context, destroyed on completion of the function.
5300 * @param argc Standard main() style argc.
5301 * @param argv Standard main() style argv. Initial components are already
5304 * @return normal NTSTATUS return code.
5307 static NTSTATUS
rpc_trustdom_del_internals(struct net_context
*c
,
5308 const DOM_SID
*domain_sid
,
5309 const char *domain_name
,
5310 struct cli_state
*cli
,
5311 struct rpc_pipe_client
*pipe_hnd
,
5312 TALLOC_CTX
*mem_ctx
,
5316 struct policy_handle connect_pol
, domain_pol
, user_pol
;
5317 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
5319 DOM_SID trust_acct_sid
;
5320 struct samr_Ids user_rids
, name_types
;
5321 struct lsa_String lsa_acct_name
;
5324 d_printf("Usage: net rpc trustdom del <domain_name>\n");
5325 return NT_STATUS_INVALID_PARAMETER
;
5329 * Make valid trusting domain account (ie. uppercased and with '$' appended)
5331 acct_name
= talloc_asprintf(mem_ctx
, "%s$", argv
[0]);
5333 if (acct_name
== NULL
)
5334 return NT_STATUS_NO_MEMORY
;
5336 strupper_m(acct_name
);
5338 /* Get samr policy handle */
5339 result
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
5341 MAXIMUM_ALLOWED_ACCESS
,
5343 if (!NT_STATUS_IS_OK(result
)) {
5347 /* Get domain policy handle */
5348 result
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
5350 MAXIMUM_ALLOWED_ACCESS
,
5351 CONST_DISCARD(struct dom_sid2
*, domain_sid
),
5353 if (!NT_STATUS_IS_OK(result
)) {
5357 init_lsa_String(&lsa_acct_name
, acct_name
);
5359 result
= rpccli_samr_LookupNames(pipe_hnd
, mem_ctx
,
5366 if (!NT_STATUS_IS_OK(result
)) {
5367 d_printf("net rpc trustdom del: LookupNames on user %s failed %s\n",
5368 acct_name
, nt_errstr(result
) );
5372 result
= rpccli_samr_OpenUser(pipe_hnd
, mem_ctx
,
5374 MAXIMUM_ALLOWED_ACCESS
,
5378 if (!NT_STATUS_IS_OK(result
)) {
5379 d_printf("net rpc trustdom del: OpenUser on user %s failed %s\n",
5380 acct_name
, nt_errstr(result
) );
5384 /* append the rid to the domain sid */
5385 sid_copy(&trust_acct_sid
, domain_sid
);
5386 if (!sid_append_rid(&trust_acct_sid
, user_rids
.ids
[0])) {
5390 /* remove the sid */
5392 result
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_hnd
, mem_ctx
,
5395 if (!NT_STATUS_IS_OK(result
)) {
5396 d_printf("net rpc trustdom del: RemoveMemberFromForeignDomain on user %s failed %s\n",
5397 acct_name
, nt_errstr(result
) );
5403 result
= rpccli_samr_DeleteUser(pipe_hnd
, mem_ctx
,
5406 if (!NT_STATUS_IS_OK(result
)) {
5407 d_printf("net rpc trustdom del: DeleteUser on user %s failed %s\n",
5408 acct_name
, nt_errstr(result
) );
5412 if (!NT_STATUS_IS_OK(result
)) {
5413 d_printf("Could not set trust account password: %s\n",
5423 * Delete interdomain trust account for a remote domain.
5425 * @param argc Standard argc.
5426 * @param argv Standard argv without initial components.
5428 * @return Integer status (0 means success).
5431 static int rpc_trustdom_del(struct net_context
*c
, int argc
, const char **argv
)
5433 if (argc
> 0 && !c
->display_usage
) {
5434 return run_rpc_command(c
, NULL
, &ndr_table_samr
.syntax_id
, 0,
5435 rpc_trustdom_del_internals
, argc
, argv
);
5438 "net rpc trustdom del <domain>\n");
5443 static NTSTATUS
rpc_trustdom_get_pdc(struct net_context
*c
,
5444 struct cli_state
*cli
,
5445 TALLOC_CTX
*mem_ctx
,
5446 const char *domain_name
)
5448 char *dc_name
= NULL
;
5449 const char *buffer
= NULL
;
5450 struct rpc_pipe_client
*netr
;
5453 /* Use NetServerEnum2 */
5455 if (cli_get_pdc_name(cli
, domain_name
, &dc_name
)) {
5457 return NT_STATUS_OK
;
5460 DEBUG(1,("NetServerEnum2 error: Couldn't find primary domain controller\
5461 for domain %s\n", domain_name
));
5463 /* Try netr_GetDcName */
5465 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
.syntax_id
,
5467 if (!NT_STATUS_IS_OK(status
)) {
5471 status
= rpccli_netr_GetDcName(netr
, mem_ctx
,
5478 if (NT_STATUS_IS_OK(status
)) {
5482 DEBUG(1,("netr_GetDcName error: Couldn't find primary domain controller\
5483 for domain %s\n", domain_name
));
5489 * Establish trust relationship to a trusting domain.
5490 * Interdomain account must already be created on remote PDC.
5492 * @param c A net_context structure.
5493 * @param argc Standard argc.
5494 * @param argv Standard argv without initial components.
5496 * @return Integer status (0 means success).
5499 static int rpc_trustdom_establish(struct net_context
*c
, int argc
,
5502 struct cli_state
*cli
= NULL
;
5503 struct sockaddr_storage server_ss
;
5504 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5505 struct policy_handle connect_hnd
;
5506 TALLOC_CTX
*mem_ctx
;
5508 DOM_SID
*domain_sid
;
5513 union lsa_PolicyInformation
*info
= NULL
;
5516 * Connect to \\server\ipc$ as 'our domain' account with password
5519 if (argc
!= 1 || c
->display_usage
) {
5521 "net rpc trustdom establish <domain_name>\n");
5525 domain_name
= smb_xstrdup(argv
[0]);
5526 strupper_m(domain_name
);
5528 /* account name used at first is our domain's name with '$' */
5529 if (asprintf(&acct_name
, "%s$", lp_workgroup()) == -1) {
5532 strupper_m(acct_name
);
5535 * opt_workgroup will be used by connection functions further,
5536 * hence it should be set to remote domain name instead of ours
5538 if (c
->opt_workgroup
) {
5539 c
->opt_workgroup
= smb_xstrdup(domain_name
);
5542 c
->opt_user_name
= acct_name
;
5544 /* find the domain controller */
5545 if (!net_find_pdc(&server_ss
, pdc_name
, domain_name
)) {
5546 DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name
));
5550 /* connect to ipc$ as username/password */
5551 nt_status
= connect_to_ipc(c
, &cli
, &server_ss
, pdc_name
);
5552 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
)) {
5554 /* Is it trusting domain account for sure ? */
5555 DEBUG(0, ("Couldn't verify trusting domain account. Error was %s\n",
5556 nt_errstr(nt_status
)));
5560 /* store who we connected to */
5562 saf_store( domain_name
, pdc_name
);
5565 * Connect to \\server\ipc$ again (this time anonymously)
5568 nt_status
= connect_to_ipc_anonymous(c
, &cli
, &server_ss
,
5571 if (NT_STATUS_IS_ERR(nt_status
)) {
5572 DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n",
5573 domain_name
, nt_errstr(nt_status
)));
5577 if (!(mem_ctx
= talloc_init("establishing trust relationship to "
5578 "domain %s", domain_name
))) {
5579 DEBUG(0, ("talloc_init() failed\n"));
5584 /* Make sure we're talking to a proper server */
5586 nt_status
= rpc_trustdom_get_pdc(c
, cli
, mem_ctx
, domain_name
);
5587 if (!NT_STATUS_IS_OK(nt_status
)) {
5589 talloc_destroy(mem_ctx
);
5594 * Call LsaOpenPolicy and LsaQueryInfo
5597 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5599 if (!NT_STATUS_IS_OK(nt_status
)) {
5600 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n", nt_errstr(nt_status
) ));
5602 talloc_destroy(mem_ctx
);
5606 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, true, KEY_QUERY_VALUE
,
5608 if (NT_STATUS_IS_ERR(nt_status
)) {
5609 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5610 nt_errstr(nt_status
)));
5612 talloc_destroy(mem_ctx
);
5616 /* Querying info level 5 */
5618 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5620 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5622 if (NT_STATUS_IS_ERR(nt_status
)) {
5623 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5624 nt_errstr(nt_status
)));
5626 talloc_destroy(mem_ctx
);
5630 domain_sid
= info
->account_domain
.sid
;
5632 /* There should be actually query info level 3 (following nt serv behaviour),
5633 but I still don't know if it's _really_ necessary */
5636 * Store the password in secrets db
5639 if (!pdb_set_trusteddom_pw(domain_name
, c
->opt_password
, domain_sid
)) {
5640 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5642 talloc_destroy(mem_ctx
);
5647 * Close the pipes and clean up
5650 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5651 if (NT_STATUS_IS_ERR(nt_status
)) {
5652 DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
5653 nt_errstr(nt_status
)));
5655 talloc_destroy(mem_ctx
);
5661 talloc_destroy(mem_ctx
);
5663 d_printf("Trust to domain %s established\n", domain_name
);
5668 * Revoke trust relationship to the remote domain.
5670 * @param c A net_context structure.
5671 * @param argc Standard argc.
5672 * @param argv Standard argv without initial components.
5674 * @return Integer status (0 means success).
5677 static int rpc_trustdom_revoke(struct net_context
*c
, int argc
,
5683 if (argc
< 1 || c
->display_usage
) {
5685 "net rpc trustdom revoke <domain_name>\n"
5686 " Revoke trust relationship\n"
5687 " domain_name\tName of domain to revoke trust\n");
5691 /* generate upper cased domain name */
5692 domain_name
= smb_xstrdup(argv
[0]);
5693 strupper_m(domain_name
);
5695 /* delete password of the trust */
5696 if (!pdb_del_trusteddom_pw(domain_name
)) {
5697 DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
5704 SAFE_FREE(domain_name
);
5708 static NTSTATUS
rpc_query_domain_sid(struct net_context
*c
,
5709 const DOM_SID
*domain_sid
,
5710 const char *domain_name
,
5711 struct cli_state
*cli
,
5712 struct rpc_pipe_client
*pipe_hnd
,
5713 TALLOC_CTX
*mem_ctx
,
5718 sid_to_fstring(str_sid
, domain_sid
);
5719 d_printf("%s\n", str_sid
);
5720 return NT_STATUS_OK
;
5723 static void print_trusted_domain(DOM_SID
*dom_sid
, const char *trusted_dom_name
)
5725 fstring ascii_sid
, padding
;
5726 int pad_len
, col_len
= 20;
5728 /* convert sid into ascii string */
5729 sid_to_fstring(ascii_sid
, dom_sid
);
5731 /* calculate padding space for d_printf to look nicer */
5732 pad_len
= col_len
- strlen(trusted_dom_name
);
5733 padding
[pad_len
] = 0;
5734 do padding
[--pad_len
] = ' '; while (pad_len
);
5736 d_printf("%s%s%s\n", trusted_dom_name
, padding
, ascii_sid
);
5739 static NTSTATUS
vampire_trusted_domain(struct rpc_pipe_client
*pipe_hnd
,
5740 TALLOC_CTX
*mem_ctx
,
5741 struct policy_handle
*pol
,
5743 const char *trusted_dom_name
)
5746 union lsa_TrustedDomainInfo
*info
= NULL
;
5747 char *cleartextpwd
= NULL
;
5748 uint8_t nt_hash
[16];
5749 DATA_BLOB data
= data_blob_null
;
5751 nt_status
= rpccli_lsa_QueryTrustedDomainInfoBySid(pipe_hnd
, mem_ctx
,
5754 LSA_TRUSTED_DOMAIN_INFO_PASSWORD
,
5756 if (NT_STATUS_IS_ERR(nt_status
)) {
5757 DEBUG(0,("Could not query trusted domain info. Error was %s\n",
5758 nt_errstr(nt_status
)));
5762 data
= data_blob(info
->password
.password
->data
,
5763 info
->password
.password
->length
);
5765 if (!rpccli_get_pwd_hash(pipe_hnd
, nt_hash
)) {
5766 DEBUG(0, ("Could not retrieve password hash\n"));
5770 cleartextpwd
= decrypt_trustdom_secret(nt_hash
, &data
);
5772 if (cleartextpwd
== NULL
) {
5773 DEBUG(0,("retrieved NULL password\n"));
5774 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5778 if (!pdb_set_trusteddom_pw(trusted_dom_name
, cleartextpwd
, &dom_sid
)) {
5779 DEBUG(0, ("Storing password for trusted domain failed.\n"));
5780 nt_status
= NT_STATUS_UNSUCCESSFUL
;
5784 #ifdef DEBUG_PASSWORD
5785 DEBUG(100,("successfully vampired trusted domain [%s], sid: [%s], "
5786 "password: [%s]\n", trusted_dom_name
,
5787 sid_string_dbg(&dom_sid
), cleartextpwd
));
5791 SAFE_FREE(cleartextpwd
);
5792 data_blob_free(&data
);
5797 static int rpc_trustdom_vampire(struct net_context
*c
, int argc
,
5800 /* common variables */
5801 TALLOC_CTX
* mem_ctx
;
5802 struct cli_state
*cli
= NULL
;
5803 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5805 const char *domain_name
= NULL
;
5806 DOM_SID
*queried_dom_sid
;
5807 struct policy_handle connect_hnd
;
5808 union lsa_PolicyInformation
*info
= NULL
;
5810 /* trusted domains listing variables */
5811 unsigned int enum_ctx
= 0;
5813 struct lsa_DomainList dom_list
;
5816 if (c
->display_usage
) {
5818 "net rpc trustdom vampire\n"
5819 " Vampire trust relationship from remote server\n");
5824 * Listing trusted domains (stored in secrets.tdb, if local)
5827 mem_ctx
= talloc_init("trust relationships vampire");
5830 * set domain and pdc name to local samba server (default)
5831 * or to remote one given in command line
5834 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5835 domain_name
= c
->opt_workgroup
;
5836 c
->opt_target_workgroup
= c
->opt_workgroup
;
5838 fstrcpy(pdc_name
, global_myname());
5839 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5840 c
->opt_target_workgroup
= domain_name
;
5843 /* open \PIPE\lsarpc and open policy handle */
5844 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
5845 if (!NT_STATUS_IS_OK(nt_status
)) {
5846 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
5847 nt_errstr(nt_status
)));
5848 talloc_destroy(mem_ctx
);
5852 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
5854 if (!NT_STATUS_IS_OK(nt_status
)) {
5855 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
5856 nt_errstr(nt_status
) ));
5858 talloc_destroy(mem_ctx
);
5862 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
5864 if (NT_STATUS_IS_ERR(nt_status
)) {
5865 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
5866 nt_errstr(nt_status
)));
5868 talloc_destroy(mem_ctx
);
5872 /* query info level 5 to obtain sid of a domain being queried */
5873 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
5875 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
5878 if (NT_STATUS_IS_ERR(nt_status
)) {
5879 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
5880 nt_errstr(nt_status
)));
5882 talloc_destroy(mem_ctx
);
5886 queried_dom_sid
= info
->account_domain
.sid
;
5889 * Keep calling LsaEnumTrustdom over opened pipe until
5890 * the end of enumeration is reached
5893 d_printf("Vampire trusted domains:\n\n");
5896 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
5901 if (NT_STATUS_IS_ERR(nt_status
)) {
5902 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
5903 nt_errstr(nt_status
)));
5905 talloc_destroy(mem_ctx
);
5909 for (i
= 0; i
< dom_list
.count
; i
++) {
5911 print_trusted_domain(dom_list
.domains
[i
].sid
,
5912 dom_list
.domains
[i
].name
.string
);
5914 nt_status
= vampire_trusted_domain(pipe_hnd
, mem_ctx
, &connect_hnd
,
5915 *dom_list
.domains
[i
].sid
,
5916 dom_list
.domains
[i
].name
.string
);
5917 if (!NT_STATUS_IS_OK(nt_status
)) {
5919 talloc_destroy(mem_ctx
);
5925 * in case of no trusted domains say something rather
5926 * than just display blank line
5928 if (!dom_list
.count
) d_printf("none\n");
5930 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
5932 /* close this connection before doing next one */
5933 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
5934 if (NT_STATUS_IS_ERR(nt_status
)) {
5935 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
5936 nt_errstr(nt_status
)));
5938 talloc_destroy(mem_ctx
);
5942 /* close lsarpc pipe and connection to IPC$ */
5945 talloc_destroy(mem_ctx
);
5949 static int rpc_trustdom_list(struct net_context
*c
, int argc
, const char **argv
)
5951 /* common variables */
5952 TALLOC_CTX
* mem_ctx
;
5953 struct cli_state
*cli
= NULL
, *remote_cli
= NULL
;
5954 struct rpc_pipe_client
*pipe_hnd
= NULL
;
5956 const char *domain_name
= NULL
;
5957 DOM_SID
*queried_dom_sid
;
5958 int ascii_dom_name_len
;
5959 struct policy_handle connect_hnd
;
5960 union lsa_PolicyInformation
*info
= NULL
;
5962 /* trusted domains listing variables */
5963 unsigned int num_domains
, enum_ctx
= 0;
5965 struct lsa_DomainList dom_list
;
5969 /* trusting domains listing variables */
5970 struct policy_handle domain_hnd
;
5971 struct samr_SamArray
*trusts
= NULL
;
5973 if (c
->display_usage
) {
5975 "net rpc trustdom list\n"
5976 " List trust relationships\n");
5981 * Listing trusted domains (stored in secrets.tdb, if local)
5984 mem_ctx
= talloc_init("trust relationships listing");
5987 * set domain and pdc name to local samba server (default)
5988 * or to remote one given in command line
5991 if (StrCaseCmp(c
->opt_workgroup
, lp_workgroup())) {
5992 domain_name
= c
->opt_workgroup
;
5993 c
->opt_target_workgroup
= c
->opt_workgroup
;
5995 fstrcpy(pdc_name
, global_myname());
5996 domain_name
= talloc_strdup(mem_ctx
, lp_workgroup());
5997 c
->opt_target_workgroup
= domain_name
;
6000 /* open \PIPE\lsarpc and open policy handle */
6001 nt_status
= net_make_ipc_connection(c
, NET_FLAGS_PDC
, &cli
);
6002 if (!NT_STATUS_IS_OK(nt_status
)) {
6003 DEBUG(0, ("Couldn't connect to domain controller: %s\n",
6004 nt_errstr(nt_status
)));
6005 talloc_destroy(mem_ctx
);
6009 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_lsarpc
.syntax_id
,
6011 if (!NT_STATUS_IS_OK(nt_status
)) {
6012 DEBUG(0, ("Could not initialise lsa pipe. Error was %s\n",
6013 nt_errstr(nt_status
) ));
6015 talloc_destroy(mem_ctx
);
6019 nt_status
= rpccli_lsa_open_policy2(pipe_hnd
, mem_ctx
, false, KEY_QUERY_VALUE
,
6021 if (NT_STATUS_IS_ERR(nt_status
)) {
6022 DEBUG(0, ("Couldn't open policy handle. Error was %s\n",
6023 nt_errstr(nt_status
)));
6025 talloc_destroy(mem_ctx
);
6029 /* query info level 5 to obtain sid of a domain being queried */
6030 nt_status
= rpccli_lsa_QueryInfoPolicy(pipe_hnd
, mem_ctx
,
6032 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
6035 if (NT_STATUS_IS_ERR(nt_status
)) {
6036 DEBUG(0, ("LSA Query Info failed. Returned error was %s\n",
6037 nt_errstr(nt_status
)));
6039 talloc_destroy(mem_ctx
);
6043 queried_dom_sid
= info
->account_domain
.sid
;
6046 * Keep calling LsaEnumTrustdom over opened pipe until
6047 * the end of enumeration is reached
6050 d_printf("Trusted domains list:\n\n");
6052 found_domain
= false;
6055 nt_status
= rpccli_lsa_EnumTrustDom(pipe_hnd
, mem_ctx
,
6060 if (NT_STATUS_IS_ERR(nt_status
)) {
6061 DEBUG(0, ("Couldn't enumerate trusted domains. Error was %s\n",
6062 nt_errstr(nt_status
)));
6064 talloc_destroy(mem_ctx
);
6068 for (i
= 0; i
< dom_list
.count
; i
++) {
6069 print_trusted_domain(dom_list
.domains
[i
].sid
,
6070 dom_list
.domains
[i
].name
.string
);
6071 found_domain
= true;
6074 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6077 * in case of no trusted domains say something rather
6078 * than just display blank line
6080 if (!found_domain
) {
6084 /* close this connection before doing next one */
6085 nt_status
= rpccli_lsa_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6086 if (NT_STATUS_IS_ERR(nt_status
)) {
6087 DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
6088 nt_errstr(nt_status
)));
6090 talloc_destroy(mem_ctx
);
6094 TALLOC_FREE(pipe_hnd
);
6097 * Listing trusting domains (stored in passdb backend, if local)
6100 d_printf("\nTrusting domains list:\n\n");
6103 * Open \PIPE\samr and get needed policy handles
6105 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
.syntax_id
,
6107 if (!NT_STATUS_IS_OK(nt_status
)) {
6108 DEBUG(0, ("Could not initialise samr pipe. Error was %s\n", nt_errstr(nt_status
)));
6110 talloc_destroy(mem_ctx
);
6115 nt_status
= rpccli_samr_Connect2(pipe_hnd
, mem_ctx
,
6117 SAMR_ACCESS_LOOKUP_DOMAIN
,
6119 if (!NT_STATUS_IS_OK(nt_status
)) {
6120 DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
6121 nt_errstr(nt_status
)));
6123 talloc_destroy(mem_ctx
);
6127 /* SamrOpenDomain - we have to open domain policy handle in order to be
6128 able to enumerate accounts*/
6129 nt_status
= rpccli_samr_OpenDomain(pipe_hnd
, mem_ctx
,
6131 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
,
6134 if (!NT_STATUS_IS_OK(nt_status
)) {
6135 DEBUG(0, ("Couldn't open domain object. Error was %s\n",
6136 nt_errstr(nt_status
)));
6138 talloc_destroy(mem_ctx
);
6143 * perform actual enumeration
6146 found_domain
= false;
6148 enum_ctx
= 0; /* reset enumeration context from last enumeration */
6151 nt_status
= rpccli_samr_EnumDomainUsers(pipe_hnd
, mem_ctx
,
6158 if (NT_STATUS_IS_ERR(nt_status
)) {
6159 DEBUG(0, ("Couldn't enumerate accounts. Error was: %s\n",
6160 nt_errstr(nt_status
)));
6162 talloc_destroy(mem_ctx
);
6166 for (i
= 0; i
< num_domains
; i
++) {
6168 char *str
= CONST_DISCARD(char *, trusts
->entries
[i
].name
.string
);
6170 found_domain
= true;
6173 * get each single domain's sid (do we _really_ need this ?):
6174 * 1) connect to domain's pdc
6175 * 2) query the pdc for domain's sid
6178 /* get rid of '$' tail */
6179 ascii_dom_name_len
= strlen(str
);
6180 if (ascii_dom_name_len
&& ascii_dom_name_len
< FSTRING_LEN
)
6181 str
[ascii_dom_name_len
- 1] = '\0';
6183 /* set opt_* variables to remote domain */
6185 c
->opt_workgroup
= talloc_strdup(mem_ctx
, str
);
6186 c
->opt_target_workgroup
= c
->opt_workgroup
;
6188 d_printf("%-20s", str
);
6190 /* connect to remote domain controller */
6191 nt_status
= net_make_ipc_connection(c
,
6192 NET_FLAGS_PDC
| NET_FLAGS_ANONYMOUS
,
6194 if (NT_STATUS_IS_OK(nt_status
)) {
6195 /* query for domain's sid */
6196 if (run_rpc_command(
6198 &ndr_table_lsarpc
.syntax_id
, 0,
6199 rpc_query_domain_sid
, argc
,
6201 d_fprintf(stderr
, "couldn't get domain's sid\n");
6203 cli_shutdown(remote_cli
);
6206 d_fprintf(stderr
, "domain controller is not "
6208 nt_errstr(nt_status
));
6212 } while (NT_STATUS_EQUAL(nt_status
, STATUS_MORE_ENTRIES
));
6214 if (!found_domain
) {
6218 /* close opened samr and domain policy handles */
6219 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &domain_hnd
);
6220 if (!NT_STATUS_IS_OK(nt_status
)) {
6221 DEBUG(0, ("Couldn't properly close domain policy handle for domain %s\n", domain_name
));
6224 nt_status
= rpccli_samr_Close(pipe_hnd
, mem_ctx
, &connect_hnd
);
6225 if (!NT_STATUS_IS_OK(nt_status
)) {
6226 DEBUG(0, ("Couldn't properly close samr policy handle for domain %s\n", domain_name
));
6229 /* close samr pipe and connection to IPC$ */
6232 talloc_destroy(mem_ctx
);
6237 * Entrypoint for 'net rpc trustdom' code.
6239 * @param argc Standard argc.
6240 * @param argv Standard argv without initial components.
6242 * @return Integer status (0 means success).
6245 static int rpc_trustdom(struct net_context
*c
, int argc
, const char **argv
)
6247 struct functable func
[] = {
6252 "Add trusted domain's account",
6253 "net rpc trustdom add\n"
6254 " Add trusted domain's account"
6260 "Remove trusted domain's account",
6261 "net rpc trustdom del\n"
6262 " Remove trusted domain's account"
6266 rpc_trustdom_establish
,
6268 "Establish trust relationship",
6269 "net rpc trustdom establish\n"
6270 " Establish trust relationship"
6274 rpc_trustdom_revoke
,
6276 "Revoke trust relationship",
6277 "net rpc trustdom revoke\n"
6278 " Revoke trust relationship"
6284 "List domain trusts",
6285 "net rpc trustdom list\n"
6286 " List domain trusts"
6290 rpc_trustdom_vampire
,
6292 "Vampire trusts from remote server",
6293 "net rpc trustdom vampire\n"
6294 " Vampire trusts from remote server"
6296 {NULL
, NULL
, 0, NULL
, NULL
}
6299 return net_run_function(c
, argc
, argv
, "net rpc trustdom", func
);
6303 * Check if a server will take rpc commands
6304 * @param flags Type of server to connect to (PDC, DMB, localhost)
6305 * if the host is not explicitly specified
6306 * @return bool (true means rpc supported)
6308 bool net_rpc_check(struct net_context
*c
, unsigned flags
)
6310 struct cli_state
*cli
;
6312 struct sockaddr_storage server_ss
;
6313 char *server_name
= NULL
;
6316 /* flags (i.e. server type) may depend on command */
6317 if (!net_find_server(c
, NULL
, flags
, &server_ss
, &server_name
))
6320 if ((cli
= cli_initialise()) == NULL
) {
6324 status
= cli_connect(cli
, server_name
, &server_ss
);
6325 if (!NT_STATUS_IS_OK(status
))
6327 if (!attempt_netbios_session_request(&cli
, global_myname(),
6328 server_name
, &server_ss
))
6330 status
= cli_negprot(cli
);
6331 if (!NT_STATUS_IS_OK(status
))
6333 if (cli
->protocol
< PROTOCOL_NT1
)
6342 /* dump sam database via samsync rpc calls */
6343 static int rpc_samdump(struct net_context
*c
, int argc
, const char **argv
) {
6344 if (c
->display_usage
) {
6347 " Dump remote SAM database\n");
6351 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6352 NET_FLAGS_ANONYMOUS
,
6353 rpc_samdump_internals
, argc
, argv
);
6356 /* syncronise sam database via samsync rpc calls */
6357 static int rpc_vampire(struct net_context
*c
, int argc
, const char **argv
)
6359 struct functable func
[] = {
6364 "Dump remote SAM database to ldif",
6365 "net rpc vampire ldif\n"
6366 " Dump remote SAM database to LDIF file or stdout"
6372 "Dump remote SAM database to Kerberos Keytab",
6373 "net rpc vampire keytab\n"
6374 " Dump remote SAM database to Kerberos keytab file"
6380 "Dump remote SAM database to passdb",
6381 "net rpc vampire passdb\n"
6382 " Dump remote SAM database to passdb"
6385 {NULL
, NULL
, 0, NULL
, NULL
}
6389 if (c
->display_usage
) {
6392 " Vampire remote SAM database\n");
6396 return run_rpc_command(c
, NULL
, &ndr_table_netlogon
.syntax_id
,
6397 NET_FLAGS_ANONYMOUS
,
6398 rpc_vampire_internals
,
6402 return net_run_function(c
, argc
, argv
, "net rpc vampire", func
);
6406 * Migrate everything from a print server.
6408 * @param c A net_context structure.
6409 * @param argc Standard main() style argc.
6410 * @param argv Standard main() style argv. Initial components are already
6413 * @return A shell status integer (0 for success).
6415 * The order is important !
6416 * To successfully add drivers the print queues have to exist !
6417 * Applying ACLs should be the last step, because you're easily locked out.
6420 static int rpc_printer_migrate_all(struct net_context
*c
, int argc
,
6425 if (c
->display_usage
) {
6427 "net rpc printer migrate all\n"
6428 " Migrate everything from a print server\n");
6433 d_printf("no server to migrate\n");
6437 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6438 rpc_printer_migrate_printers_internals
, argc
,
6443 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6444 rpc_printer_migrate_drivers_internals
, argc
,
6449 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6450 rpc_printer_migrate_forms_internals
, argc
, argv
);
6454 ret
= run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6455 rpc_printer_migrate_settings_internals
, argc
,
6460 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6461 rpc_printer_migrate_security_internals
, argc
,
6467 * Migrate print drivers from a print server.
6469 * @param c A net_context structure.
6470 * @param argc Standard main() style argc.
6471 * @param argv Standard main() style argv. Initial components are already
6474 * @return A shell status integer (0 for success).
6476 static int rpc_printer_migrate_drivers(struct net_context
*c
, int argc
,
6479 if (c
->display_usage
) {
6481 "net rpc printer migrate drivers\n"
6482 " Migrate print-drivers from a print-server\n");
6487 d_printf("no server to migrate\n");
6491 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6492 rpc_printer_migrate_drivers_internals
,
6497 * Migrate print-forms from a print-server.
6499 * @param c A net_context structure.
6500 * @param argc Standard main() style argc.
6501 * @param argv Standard main() style argv. Initial components are already
6504 * @return A shell status integer (0 for success).
6506 static int rpc_printer_migrate_forms(struct net_context
*c
, int argc
,
6509 if (c
->display_usage
) {
6511 "net rpc printer migrate forms\n"
6512 " Migrate print-forms from a print-server\n");
6517 d_printf("no server to migrate\n");
6521 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6522 rpc_printer_migrate_forms_internals
,
6527 * Migrate printers from a print-server.
6529 * @param c A net_context structure.
6530 * @param argc Standard main() style argc.
6531 * @param argv Standard main() style argv. Initial components are already
6534 * @return A shell status integer (0 for success).
6536 static int rpc_printer_migrate_printers(struct net_context
*c
, int argc
,
6539 if (c
->display_usage
) {
6541 "net rpc printer migrate printers\n"
6542 " Migrate printers from a print-server\n");
6547 d_printf("no server to migrate\n");
6551 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6552 rpc_printer_migrate_printers_internals
,
6557 * Migrate printer-ACLs from a print-server
6559 * @param c A net_context structure.
6560 * @param argc Standard main() style argc.
6561 * @param argv Standard main() style argv. Initial components are already
6564 * @return A shell status integer (0 for success).
6566 static int rpc_printer_migrate_security(struct net_context
*c
, int argc
,
6569 if (c
->display_usage
) {
6571 "net rpc printer migrate security\n"
6572 " Migrate printer-ACLs from a print-server\n");
6577 d_printf("no server to migrate\n");
6581 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6582 rpc_printer_migrate_security_internals
,
6587 * Migrate printer-settings from a print-server.
6589 * @param c A net_context structure.
6590 * @param argc Standard main() style argc.
6591 * @param argv Standard main() style argv. Initial components are already
6594 * @return A shell status integer (0 for success).
6596 static int rpc_printer_migrate_settings(struct net_context
*c
, int argc
,
6599 if (c
->display_usage
) {
6601 "net rpc printer migrate settings\n"
6602 " Migrate printer-settings from a print-server\n");
6607 d_printf("no server to migrate\n");
6611 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6612 rpc_printer_migrate_settings_internals
,
6617 * 'net rpc printer' entrypoint.
6619 * @param c A net_context structure.
6620 * @param argc Standard main() style argc.
6621 * @param argv Standard main() style argv. Initial components are already
6625 int rpc_printer_migrate(struct net_context
*c
, int argc
, const char **argv
)
6628 /* ouch: when addriver and setdriver are called from within
6629 rpc_printer_migrate_drivers_internals, the printer-queue already
6632 struct functable func
[] = {
6635 rpc_printer_migrate_all
,
6637 "Migrate all from remote to local print server",
6638 "net rpc printer migrate all\n"
6639 " Migrate all from remote to local print server"
6643 rpc_printer_migrate_drivers
,
6645 "Migrate drivers to local server",
6646 "net rpc printer migrate drivers\n"
6647 " Migrate drivers to local server"
6651 rpc_printer_migrate_forms
,
6653 "Migrate froms to local server",
6654 "net rpc printer migrate forms\n"
6655 " Migrate froms to local server"
6659 rpc_printer_migrate_printers
,
6661 "Migrate printers to local server",
6662 "net rpc printer migrate printers\n"
6663 " Migrate printers to local server"
6667 rpc_printer_migrate_security
,
6669 "Mirgate printer ACLs to local server",
6670 "net rpc printer migrate security\n"
6671 " Mirgate printer ACLs to local server"
6675 rpc_printer_migrate_settings
,
6677 "Migrate printer settings to local server",
6678 "net rpc printer migrate settings\n"
6679 " Migrate printer settings to local server"
6681 {NULL
, NULL
, 0, NULL
, NULL
}
6684 return net_run_function(c
, argc
, argv
, "net rpc printer migrate",func
);
6689 * List printers on a remote RPC server.
6691 * @param c A net_context structure.
6692 * @param argc Standard main() style argc.
6693 * @param argv Standard main() style argv. Initial components are already
6696 * @return A shell status integer (0 for success).
6698 static int rpc_printer_list(struct net_context
*c
, int argc
, const char **argv
)
6700 if (c
->display_usage
) {
6702 "net rpc printer list\n"
6703 " List printers on a remote RPC server\n");
6707 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6708 rpc_printer_list_internals
,
6713 * List printer-drivers on a remote RPC server.
6715 * @param c A net_context structure.
6716 * @param argc Standard main() style argc.
6717 * @param argv Standard main() style argv. Initial components are already
6720 * @return A shell status integer (0 for success).
6722 static int rpc_printer_driver_list(struct net_context
*c
, int argc
,
6725 if (c
->display_usage
) {
6727 "net rpc printer driver\n"
6728 " List printer-drivers on a remote RPC server\n");
6732 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6733 rpc_printer_driver_list_internals
,
6738 * Publish printer in ADS via MSRPC.
6740 * @param c A net_context structure.
6741 * @param argc Standard main() style argc.
6742 * @param argv Standard main() style argv. Initial components are already
6745 * @return A shell status integer (0 for success).
6747 static int rpc_printer_publish_publish(struct net_context
*c
, int argc
,
6750 if (c
->display_usage
) {
6752 "net rpc printer publish publish\n"
6753 " Publish printer in ADS via MSRPC\n");
6757 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6758 rpc_printer_publish_publish_internals
,
6763 * Update printer in ADS via MSRPC.
6765 * @param c A net_context structure.
6766 * @param argc Standard main() style argc.
6767 * @param argv Standard main() style argv. Initial components are already
6770 * @return A shell status integer (0 for success).
6772 static int rpc_printer_publish_update(struct net_context
*c
, int argc
, const char **argv
)
6774 if (c
->display_usage
) {
6776 "net rpc printer publish update\n"
6777 " Update printer in ADS via MSRPC\n");
6781 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6782 rpc_printer_publish_update_internals
,
6787 * UnPublish printer in ADS via MSRPC.
6789 * @param c A net_context structure.
6790 * @param argc Standard main() style argc.
6791 * @param argv Standard main() style argv. Initial components are already
6794 * @return A shell status integer (0 for success).
6796 static int rpc_printer_publish_unpublish(struct net_context
*c
, int argc
,
6799 if (c
->display_usage
) {
6801 "net rpc printer publish unpublish\n"
6802 " UnPublish printer in ADS via MSRPC\n");
6806 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6807 rpc_printer_publish_unpublish_internals
,
6812 * List published printers via MSRPC.
6814 * @param c A net_context structure.
6815 * @param argc Standard main() style argc.
6816 * @param argv Standard main() style argv. Initial components are already
6819 * @return A shell status integer (0 for success).
6821 static int rpc_printer_publish_list(struct net_context
*c
, int argc
,
6824 if (c
->display_usage
) {
6826 "net rpc printer publish list\n"
6827 " List published printers via MSRPC\n");
6831 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6832 rpc_printer_publish_list_internals
,
6838 * Publish printer in ADS.
6840 * @param c A net_context structure.
6841 * @param argc Standard main() style argc.
6842 * @param argv Standard main() style argv. Initial components are already
6845 * @return A shell status integer (0 for success).
6847 static int rpc_printer_publish(struct net_context
*c
, int argc
,
6851 struct functable func
[] = {
6854 rpc_printer_publish_publish
,
6856 "Publish printer in AD",
6857 "net rpc printer publish publish\n"
6858 " Publish printer in AD"
6862 rpc_printer_publish_update
,
6864 "Update printer in AD",
6865 "net rpc printer publish update\n"
6866 " Update printer in AD"
6870 rpc_printer_publish_unpublish
,
6872 "Unpublish printer",
6873 "net rpc printer publish unpublish\n"
6874 " Unpublish printer"
6878 rpc_printer_publish_list
,
6880 "List published printers",
6881 "net rpc printer publish list\n"
6882 " List published printers"
6884 {NULL
, NULL
, 0, NULL
, NULL
}
6888 if (c
->display_usage
) {
6889 d_printf("Usage:\n");
6890 d_printf("net rpc printer publish\n"
6891 " List published printers\n"
6892 " Alias of net rpc printer publish list\n");
6893 net_display_usage_from_functable(func
);
6896 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
6897 rpc_printer_publish_list_internals
,
6901 return net_run_function(c
, argc
, argv
, "net rpc printer publish",func
);
6907 * Display rpc printer help page.
6909 * @param c A net_context structure.
6910 * @param argc Standard main() style argc.
6911 * @param argv Standard main() style argv. Initial components are already
6914 int rpc_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
6916 d_printf("net rpc printer LIST [printer] [misc. options] [targets]\n"
6917 "\tlists all printers on print-server\n\n");
6918 d_printf("net rpc printer DRIVER [printer] [misc. options] [targets]\n"
6919 "\tlists all printer-drivers on print-server\n\n");
6920 d_printf("net rpc printer PUBLISH action [printer] [misc. options] [targets]\n"
6921 "\tpublishes printer settings in Active Directory\n"
6922 "\taction can be one of PUBLISH, UPDATE, UNPUBLISH or LIST\n\n");
6923 d_printf("net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets]"
6924 "\n\tmigrates printers from remote to local server\n\n");
6925 d_printf("net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets]"
6926 "\n\tmigrates printer-settings from remote to local server\n\n");
6927 d_printf("net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets]"
6928 "\n\tmigrates printer-drivers from remote to local server\n\n");
6929 d_printf("net rpc printer MIGRATE FORMS [printer] [misc. options] [targets]"
6930 "\n\tmigrates printer-forms from remote to local server\n\n");
6931 d_printf("net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets]"
6932 "\n\tmigrates printer-ACLs from remote to local server\n\n");
6933 d_printf("net rpc printer MIGRATE ALL [printer] [misc. options] [targets]"
6934 "\n\tmigrates drivers, forms, queues, settings and acls from\n"
6935 "\tremote to local print-server\n\n");
6936 net_common_methods_usage(c
, argc
, argv
);
6937 net_common_flags_usage(c
, argc
, argv
);
6939 "\t-v or --verbose\t\t\tgive verbose output\n"
6940 "\t --destination\t\tmigration target server (default: localhost)\n");
6946 * 'net rpc printer' entrypoint.
6948 * @param c A net_context structure.
6949 * @param argc Standard main() style argc.
6950 * @param argv Standard main() style argv. Initial components are already
6953 int net_rpc_printer(struct net_context
*c
, int argc
, const char **argv
)
6955 struct functable func
[] = {
6960 "List all printers on print server",
6961 "net rpc printer list\n"
6962 " List all printers on print server"
6966 rpc_printer_migrate
,
6968 "Migrate printer to local server",
6969 "net rpc printer migrate\n"
6970 " Migrate printer to local server"
6974 rpc_printer_driver_list
,
6976 "List printer drivers",
6977 "net rpc printer driver\n"
6978 " List printer drivers"
6982 rpc_printer_publish
,
6984 "Publish printer in AD",
6985 "net rpc printer publish\n"
6986 " Publish printer in AD"
6988 {NULL
, NULL
, 0, NULL
, NULL
}
6992 if (c
->display_usage
) {
6993 d_printf("Usage:\n");
6994 d_printf("net rpc printer\n"
6995 " List printers\n");
6996 net_display_usage_from_functable(func
);
6999 return run_rpc_command(c
, NULL
, &ndr_table_spoolss
.syntax_id
, 0,
7000 rpc_printer_list_internals
,
7004 return net_run_function(c
, argc
, argv
, "net rpc printer", func
);
7008 * 'net rpc' entrypoint.
7010 * @param c A net_context structure.
7011 * @param argc Standard main() style argc.
7012 * @param argv Standard main() style argv. Initial components are already
7016 int net_rpc(struct net_context
*c
, int argc
, const char **argv
)
7018 NET_API_STATUS status
;
7020 struct functable func
[] = {
7025 "Modify global audit settings",
7027 " Modify global audit settings"
7033 "Show basic info about a domain",
7035 " Show basic info about a domain"
7049 "Join a domain created in server manager",
7051 " Join a domain created in server manager"
7057 "Test that a join is valid",
7058 "net rpc testjoin\n"
7059 " Test that a join is valid"
7065 "List/modify users",
7067 " List/modify users"
7073 "Change a user password",
7074 "net rpc password\n"
7075 " Change a user password\n"
7076 " Alias for net rpc user password"
7082 "List/modify groups",
7084 " List/modify groups"
7090 "List/modify shares",
7092 " List/modify shares"
7106 "List/modify printers",
7108 " List/modify printers"
7112 net_rpc_changetrustpw
,
7114 "Change trust account password",
7115 "net rpc changetrustpw\n"
7116 " Change trust account password"
7122 "Modify domain trusts",
7123 "net rpc trustdom\n"
7124 " Modify domain trusts"
7130 "Abort a remote shutdown",
7131 "net rpc abortshutdown\n"
7132 " Abort a remote shutdown"
7138 "Shutdown a remote server",
7139 "net rpc shutdown\n"
7140 " Shutdown a remote server"
7146 "Dump SAM data of remote NT PDC",
7148 " Dump SAM data of remote NT PDC"
7154 "Sync a remote NT PDC's data into local passdb",
7156 " Sync a remote NT PDC's data into local passdb"
7162 "Fetch the domain sid into local secrets.tdb",
7164 " Fetch the domain sid into local secrets.tdb"
7170 "Manage privileges assigned to SID",
7172 " Manage privileges assigned to SID"
7178 "Start/stop/query remote services",
7180 " Start/stop/query remote services"
7186 "Manage registry hives",
7187 "net rpc registry\n"
7188 " Manage registry hives"
7194 "Open interactive shell on remote server",
7196 " Open interactive shell on remote server"
7198 {NULL
, NULL
, 0, NULL
, NULL
}
7201 status
= libnetapi_init(&c
->netapi_ctx
);
7205 libnetapi_set_username(c
->netapi_ctx
, c
->opt_user_name
);
7206 libnetapi_set_password(c
->netapi_ctx
, c
->opt_password
);
7207 if (c
->opt_kerberos
) {
7208 libnetapi_set_use_kerberos(c
->netapi_ctx
);
7211 return net_run_function(c
, argc
, argv
, "net rpc", func
);