2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "librpc/gen_ndr/libnetapi.h"
23 #include "lib/netapi/netapi.h"
24 #include "lib/netapi/netapi_private.h"
25 #include "lib/netapi/libnetapi.h"
27 /****************************************************************
28 ****************************************************************/
30 static void convert_USER_INFO_X_to_samr_user_info21(struct USER_INFO_X
*infoX
,
31 struct samr_UserInfo21
*info21
)
33 uint32_t fields_present
= 0;
34 struct samr_LogonHours zero_logon_hours
;
35 struct lsa_BinaryString zero_parameters
;
39 ZERO_STRUCT(zero_logon_hours
);
40 ZERO_STRUCT(zero_parameters
);
42 if (infoX
->usriX_flags
) {
43 fields_present
|= SAMR_FIELD_ACCT_FLAGS
;
45 if (infoX
->usriX_name
) {
46 fields_present
|= SAMR_FIELD_ACCOUNT_NAME
;
48 if (infoX
->usriX_password
) {
49 fields_present
|= SAMR_FIELD_NT_PASSWORD_PRESENT
;
51 if (infoX
->usriX_flags
) {
52 fields_present
|= SAMR_FIELD_ACCT_FLAGS
;
54 if (infoX
->usriX_name
) {
55 fields_present
|= SAMR_FIELD_FULL_NAME
;
57 if (infoX
->usriX_home_dir
) {
58 fields_present
|= SAMR_FIELD_HOME_DIRECTORY
;
60 if (infoX
->usriX_script_path
) {
61 fields_present
|= SAMR_FIELD_LOGON_SCRIPT
;
63 if (infoX
->usriX_comment
) {
64 fields_present
|= SAMR_FIELD_DESCRIPTION
;
66 if (infoX
->usriX_password_age
) {
67 fields_present
|= SAMR_FIELD_FORCE_PWD_CHANGE
;
69 if (infoX
->usriX_full_name
) {
70 fields_present
|= SAMR_FIELD_FULL_NAME
;
72 if (infoX
->usriX_usr_comment
) {
73 fields_present
|= SAMR_FIELD_COMMENT
;
75 if (infoX
->usriX_profile
) {
76 fields_present
|= SAMR_FIELD_PROFILE_PATH
;
78 if (infoX
->usriX_home_dir_drive
) {
79 fields_present
|= SAMR_FIELD_HOME_DRIVE
;
81 if (infoX
->usriX_primary_group_id
) {
82 fields_present
|= SAMR_FIELD_PRIMARY_GID
;
84 if (infoX
->usriX_country_code
) {
85 fields_present
|= SAMR_FIELD_COUNTRY_CODE
;
87 if (infoX
->usriX_workstations
) {
88 fields_present
|= SAMR_FIELD_WORKSTATIONS
;
91 unix_to_nt_time_abs(&password_age
, infoX
->usriX_password_age
);
93 /* TODO: infoX->usriX_priv */
95 info21
->last_logon
= 0;
96 info21
->last_logoff
= 0;
97 info21
->last_password_change
= 0;
98 info21
->acct_expiry
= 0;
99 info21
->allow_password_change
= 0;
100 info21
->force_password_change
= 0;
101 info21
->account_name
.string
= infoX
->usriX_name
;
102 info21
->full_name
.string
= infoX
->usriX_full_name
;
103 info21
->home_directory
.string
= infoX
->usriX_home_dir
;
104 info21
->home_drive
.string
= infoX
->usriX_home_dir_drive
;
105 info21
->logon_script
.string
= infoX
->usriX_script_path
;
106 info21
->profile_path
.string
= infoX
->usriX_profile
;
107 info21
->description
.string
= infoX
->usriX_comment
;
108 info21
->workstations
.string
= infoX
->usriX_workstations
;
109 info21
->comment
.string
= infoX
->usriX_usr_comment
;
110 info21
->parameters
= zero_parameters
;
111 info21
->lm_owf_password
= zero_parameters
;
112 info21
->nt_owf_password
= zero_parameters
;
113 info21
->unknown3
.string
= NULL
;
114 info21
->buf_count
= 0;
115 info21
->buffer
= NULL
;
116 info21
->rid
= infoX
->usriX_user_id
;
117 info21
->primary_gid
= infoX
->usriX_primary_group_id
;
118 info21
->acct_flags
= infoX
->usriX_flags
;
119 info21
->fields_present
= fields_present
;
120 info21
->logon_hours
= zero_logon_hours
;
121 info21
->bad_password_count
= infoX
->usriX_bad_pw_count
;
122 info21
->logon_count
= infoX
->usriX_num_logons
;
123 info21
->country_code
= infoX
->usriX_country_code
;
124 info21
->code_page
= infoX
->usriX_code_page
;
125 info21
->lm_password_set
= 0;
126 info21
->nt_password_set
= 0;
127 info21
->password_expired
= infoX
->usriX_password_expired
;
128 info21
->unknown4
= 0;
131 /****************************************************************
132 ****************************************************************/
134 static NTSTATUS
construct_USER_INFO_X(uint32_t level
,
136 struct USER_INFO_X
*uX
)
138 struct USER_INFO_0
*u0
= NULL
;
139 struct USER_INFO_1
*u1
= NULL
;
140 struct USER_INFO_2
*u2
= NULL
;
141 struct USER_INFO_3
*u3
= NULL
;
142 struct USER_INFO_1003
*u1003
= NULL
;
143 struct USER_INFO_1006
*u1006
= NULL
;
144 struct USER_INFO_1007
*u1007
= NULL
;
145 struct USER_INFO_1009
*u1009
= NULL
;
146 struct USER_INFO_1011
*u1011
= NULL
;
147 struct USER_INFO_1012
*u1012
= NULL
;
148 struct USER_INFO_1014
*u1014
= NULL
;
149 struct USER_INFO_1024
*u1024
= NULL
;
150 struct USER_INFO_1051
*u1051
= NULL
;
151 struct USER_INFO_1052
*u1052
= NULL
;
152 struct USER_INFO_1053
*u1053
= NULL
;
154 if (!buffer
|| !uX
) {
155 return NT_STATUS_INVALID_PARAMETER
;
162 u0
= (struct USER_INFO_0
*)buffer
;
163 uX
->usriX_name
= u0
->usri0_name
;
166 u1
= (struct USER_INFO_1
*)buffer
;
167 uX
->usriX_name
= u1
->usri1_name
;
168 uX
->usriX_password
= u1
->usri1_password
;
169 uX
->usriX_password_age
= u1
->usri1_password_age
;
170 uX
->usriX_priv
= u1
->usri1_priv
;
171 uX
->usriX_home_dir
= u1
->usri1_home_dir
;
172 uX
->usriX_comment
= u1
->usri1_comment
;
173 uX
->usriX_flags
= u1
->usri1_flags
;
174 uX
->usriX_script_path
= u1
->usri1_script_path
;
177 u2
= (struct USER_INFO_2
*)buffer
;
178 uX
->usriX_name
= u2
->usri2_name
;
179 uX
->usriX_password
= u2
->usri2_password
;
180 uX
->usriX_password_age
= u2
->usri2_password_age
;
181 uX
->usriX_priv
= u2
->usri2_priv
;
182 uX
->usriX_home_dir
= u2
->usri2_home_dir
;
183 uX
->usriX_comment
= u2
->usri2_comment
;
184 uX
->usriX_flags
= u2
->usri2_flags
;
185 uX
->usriX_script_path
= u2
->usri2_script_path
;
186 uX
->usriX_auth_flags
= u2
->usri2_auth_flags
;
187 uX
->usriX_full_name
= u2
->usri2_full_name
;
188 uX
->usriX_usr_comment
= u2
->usri2_usr_comment
;
189 uX
->usriX_parms
= u2
->usri2_parms
;
190 uX
->usriX_workstations
= u2
->usri2_workstations
;
191 uX
->usriX_last_logon
= u2
->usri2_last_logon
;
192 uX
->usriX_last_logoff
= u2
->usri2_last_logoff
;
193 uX
->usriX_acct_expires
= u2
->usri2_acct_expires
;
194 uX
->usriX_max_storage
= u2
->usri2_max_storage
;
195 uX
->usriX_units_per_week
= u2
->usri2_units_per_week
;
196 uX
->usriX_logon_hours
= u2
->usri2_logon_hours
;
197 uX
->usriX_bad_pw_count
= u2
->usri2_bad_pw_count
;
198 uX
->usriX_num_logons
= u2
->usri2_num_logons
;
199 uX
->usriX_logon_server
= u2
->usri2_logon_server
;
200 uX
->usriX_country_code
= u2
->usri2_country_code
;
201 uX
->usriX_code_page
= u2
->usri2_code_page
;
204 u3
= (struct USER_INFO_3
*)buffer
;
205 uX
->usriX_name
= u3
->usri3_name
;
206 uX
->usriX_password_age
= u3
->usri3_password_age
;
207 uX
->usriX_priv
= u3
->usri3_priv
;
208 uX
->usriX_home_dir
= u3
->usri3_home_dir
;
209 uX
->usriX_comment
= u3
->usri3_comment
;
210 uX
->usriX_flags
= u3
->usri3_flags
;
211 uX
->usriX_script_path
= u3
->usri3_script_path
;
212 uX
->usriX_auth_flags
= u3
->usri3_auth_flags
;
213 uX
->usriX_full_name
= u3
->usri3_full_name
;
214 uX
->usriX_usr_comment
= u3
->usri3_usr_comment
;
215 uX
->usriX_parms
= u3
->usri3_parms
;
216 uX
->usriX_workstations
= u3
->usri3_workstations
;
217 uX
->usriX_last_logon
= u3
->usri3_last_logon
;
218 uX
->usriX_last_logoff
= u3
->usri3_last_logoff
;
219 uX
->usriX_acct_expires
= u3
->usri3_acct_expires
;
220 uX
->usriX_max_storage
= u3
->usri3_max_storage
;
221 uX
->usriX_units_per_week
= u3
->usri3_units_per_week
;
222 uX
->usriX_logon_hours
= u3
->usri3_logon_hours
;
223 uX
->usriX_bad_pw_count
= u3
->usri3_bad_pw_count
;
224 uX
->usriX_num_logons
= u3
->usri3_num_logons
;
225 uX
->usriX_logon_server
= u3
->usri3_logon_server
;
226 uX
->usriX_country_code
= u3
->usri3_country_code
;
227 uX
->usriX_code_page
= u3
->usri3_code_page
;
228 uX
->usriX_user_id
= u3
->usri3_user_id
;
229 uX
->usriX_primary_group_id
= u3
->usri3_primary_group_id
;
230 uX
->usriX_profile
= u3
->usri3_profile
;
231 uX
->usriX_home_dir_drive
= u3
->usri3_home_dir_drive
;
232 uX
->usriX_password_expired
= u3
->usri3_password_expired
;
235 u1003
= (struct USER_INFO_1003
*)buffer
;
236 uX
->usriX_password
= u1003
->usri1003_password
;
239 u1006
= (struct USER_INFO_1006
*)buffer
;
240 uX
->usriX_home_dir
= u1006
->usri1006_home_dir
;
243 u1007
= (struct USER_INFO_1007
*)buffer
;
244 uX
->usriX_comment
= u1007
->usri1007_comment
;
247 u1009
= (struct USER_INFO_1009
*)buffer
;
248 uX
->usriX_script_path
= u1009
->usri1009_script_path
;
251 u1011
= (struct USER_INFO_1011
*)buffer
;
252 uX
->usriX_full_name
= u1011
->usri1011_full_name
;
255 u1012
= (struct USER_INFO_1012
*)buffer
;
256 uX
->usriX_usr_comment
= u1012
->usri1012_usr_comment
;
259 u1014
= (struct USER_INFO_1014
*)buffer
;
260 uX
->usriX_workstations
= u1014
->usri1014_workstations
;
263 u1024
= (struct USER_INFO_1024
*)buffer
;
264 uX
->usriX_country_code
= u1024
->usri1024_country_code
;
267 u1051
= (struct USER_INFO_1051
*)buffer
;
268 uX
->usriX_primary_group_id
= u1051
->usri1051_primary_group_id
;
271 u1052
= (struct USER_INFO_1052
*)buffer
;
272 uX
->usriX_profile
= u1052
->usri1052_profile
;
275 u1053
= (struct USER_INFO_1053
*)buffer
;
276 uX
->usriX_home_dir_drive
= u1053
->usri1053_home_dir_drive
;
280 return NT_STATUS_INVALID_INFO_CLASS
;
286 /****************************************************************
287 ****************************************************************/
289 static NTSTATUS
set_user_info_USER_INFO_X(TALLOC_CTX
*ctx
,
290 struct rpc_pipe_client
*pipe_cli
,
291 DATA_BLOB
*session_key
,
292 struct policy_handle
*user_handle
,
293 struct USER_INFO_X
*uX
)
295 union samr_UserInfo user_info
;
296 struct samr_UserInfo21 info21
;
300 return NT_STATUS_INVALID_PARAMETER
;
303 convert_USER_INFO_X_to_samr_user_info21(uX
, &info21
);
305 ZERO_STRUCT(user_info
);
307 if (uX
->usriX_password
) {
309 user_info
.info25
.info
= info21
;
311 init_samr_CryptPasswordEx(uX
->usriX_password
,
313 &user_info
.info25
.password
);
315 status
= rpccli_samr_SetUserInfo2(pipe_cli
, ctx
,
320 if (NT_STATUS_EQUAL(status
, NT_STATUS(DCERPC_FAULT_INVALID_TAG
))) {
322 user_info
.info23
.info
= info21
;
324 init_samr_CryptPassword(uX
->usriX_password
,
326 &user_info
.info23
.password
);
328 status
= rpccli_samr_SetUserInfo2(pipe_cli
, ctx
,
335 user_info
.info21
= info21
;
337 status
= rpccli_samr_SetUserInfo(pipe_cli
, ctx
,
346 /****************************************************************
347 ****************************************************************/
349 WERROR
NetUserAdd_r(struct libnetapi_ctx
*ctx
,
350 struct NetUserAdd
*r
)
352 struct rpc_pipe_client
*pipe_cli
= NULL
;
355 POLICY_HND connect_handle
, domain_handle
, user_handle
;
356 struct lsa_String lsa_account_name
;
357 struct dom_sid2
*domain_sid
= NULL
;
358 union samr_UserInfo
*user_info
= NULL
;
359 struct samr_PwInfo pw_info
;
360 uint32_t access_granted
= 0;
362 struct USER_INFO_X uX
;
364 ZERO_STRUCT(connect_handle
);
365 ZERO_STRUCT(domain_handle
);
366 ZERO_STRUCT(user_handle
);
369 return WERR_INVALID_PARAM
;
372 switch (r
->in
.level
) {
379 werr
= WERR_NOT_SUPPORTED
;
383 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
384 &ndr_table_samr
.syntax_id
,
386 if (!W_ERROR_IS_OK(werr
)) {
390 status
= construct_USER_INFO_X(r
->in
.level
, r
->in
.buffer
, &uX
);
391 if (!NT_STATUS_IS_OK(status
)) {
392 werr
= ntstatus_to_werror(status
);
396 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
397 SAMR_ACCESS_ENUM_DOMAINS
|
398 SAMR_ACCESS_OPEN_DOMAIN
,
399 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
400 SAMR_DOMAIN_ACCESS_CREATE_USER
|
401 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
405 if (!W_ERROR_IS_OK(werr
)) {
409 init_lsa_String(&lsa_account_name
, uX
.usriX_name
);
411 status
= rpccli_samr_CreateUser2(pipe_cli
, ctx
,
417 SAMR_USER_ACCESS_SET_PASSWORD
|
418 SAMR_USER_ACCESS_SET_ATTRIBUTES
|
419 SAMR_USER_ACCESS_GET_ATTRIBUTES
,
423 if (!NT_STATUS_IS_OK(status
)) {
424 werr
= ntstatus_to_werror(status
);
428 status
= rpccli_samr_QueryUserInfo(pipe_cli
, ctx
,
432 if (!NT_STATUS_IS_OK(status
)) {
433 werr
= ntstatus_to_werror(status
);
437 if (!(user_info
->info16
.acct_flags
& ACB_NORMAL
)) {
438 werr
= WERR_INVALID_PARAM
;
442 status
= rpccli_samr_GetUserPwInfo(pipe_cli
, ctx
,
445 if (!NT_STATUS_IS_OK(status
)) {
446 werr
= ntstatus_to_werror(status
);
450 uX
.usriX_flags
|= ACB_NORMAL
;
452 status
= set_user_info_USER_INFO_X(ctx
, pipe_cli
,
453 &pipe_cli
->auth
->user_session_key
,
456 if (!NT_STATUS_IS_OK(status
)) {
457 werr
= ntstatus_to_werror(status
);
465 rpccli_samr_DeleteUser(pipe_cli
, ctx
,
469 if (is_valid_policy_hnd(&user_handle
)) {
470 rpccli_samr_Close(pipe_cli
, ctx
, &user_handle
);
473 if (ctx
->disable_policy_handle_cache
) {
474 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
475 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
481 /****************************************************************
482 ****************************************************************/
484 WERROR
NetUserAdd_l(struct libnetapi_ctx
*ctx
,
485 struct NetUserAdd
*r
)
487 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserAdd
);
490 /****************************************************************
491 ****************************************************************/
493 WERROR
NetUserDel_r(struct libnetapi_ctx
*ctx
,
494 struct NetUserDel
*r
)
496 struct rpc_pipe_client
*pipe_cli
= NULL
;
499 POLICY_HND connect_handle
, builtin_handle
, domain_handle
, user_handle
;
500 struct lsa_String lsa_account_name
;
501 struct samr_Ids user_rids
, name_types
;
502 struct dom_sid2
*domain_sid
= NULL
;
503 struct dom_sid2 user_sid
;
505 ZERO_STRUCT(connect_handle
);
506 ZERO_STRUCT(builtin_handle
);
507 ZERO_STRUCT(domain_handle
);
508 ZERO_STRUCT(user_handle
);
510 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
511 &ndr_table_samr
.syntax_id
,
514 if (!W_ERROR_IS_OK(werr
)) {
518 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
519 SAMR_ACCESS_ENUM_DOMAINS
|
520 SAMR_ACCESS_OPEN_DOMAIN
,
521 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
525 if (!W_ERROR_IS_OK(werr
)) {
529 status
= rpccli_samr_OpenDomain(pipe_cli
, ctx
,
531 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
532 CONST_DISCARD(DOM_SID
*, &global_sid_Builtin
),
534 if (!NT_STATUS_IS_OK(status
)) {
535 werr
= ntstatus_to_werror(status
);
539 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
541 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
547 if (!NT_STATUS_IS_OK(status
)) {
548 werr
= ntstatus_to_werror(status
);
552 status
= rpccli_samr_OpenUser(pipe_cli
, ctx
,
557 if (!NT_STATUS_IS_OK(status
)) {
558 werr
= ntstatus_to_werror(status
);
562 sid_compose(&user_sid
, domain_sid
, user_rids
.ids
[0]);
564 status
= rpccli_samr_RemoveMemberFromForeignDomain(pipe_cli
, ctx
,
567 if (!NT_STATUS_IS_OK(status
)) {
568 werr
= ntstatus_to_werror(status
);
572 status
= rpccli_samr_DeleteUser(pipe_cli
, ctx
,
574 if (!NT_STATUS_IS_OK(status
)) {
575 werr
= ntstatus_to_werror(status
);
582 if (is_valid_policy_hnd(&user_handle
)) {
583 rpccli_samr_Close(pipe_cli
, ctx
, &user_handle
);
586 if (ctx
->disable_policy_handle_cache
) {
587 libnetapi_samr_close_builtin_handle(ctx
, &builtin_handle
);
588 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
589 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
595 /****************************************************************
596 ****************************************************************/
598 WERROR
NetUserDel_l(struct libnetapi_ctx
*ctx
,
599 struct NetUserDel
*r
)
601 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserDel
);
604 /****************************************************************
605 ****************************************************************/
607 static NTSTATUS
libnetapi_samr_lookup_user(TALLOC_CTX
*mem_ctx
,
608 struct rpc_pipe_client
*pipe_cli
,
609 struct policy_handle
*domain_handle
,
610 struct policy_handle
*builtin_handle
,
611 const char *user_name
,
612 const struct dom_sid
*domain_sid
,
615 struct samr_UserInfo21
**info21
,
616 struct sec_desc_buf
**sec_desc
,
617 uint32_t *auth_flag_p
)
621 struct policy_handle user_handle
;
622 union samr_UserInfo
*user_info
= NULL
;
623 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
624 uint32_t access_mask
= SEC_STD_READ_CONTROL
|
625 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
626 SAMR_USER_ACCESS_GET_NAME_ETC
;
628 ZERO_STRUCT(user_handle
);
634 access_mask
|= SAMR_USER_ACCESS_GET_LOGONINFO
|
635 SAMR_USER_ACCESS_GET_GROUPS
;
641 access_mask
|= SAMR_USER_ACCESS_GET_LOGONINFO
|
642 SAMR_USER_ACCESS_GET_GROUPS
|
643 SAMR_USER_ACCESS_GET_LOCALE
;
650 return NT_STATUS_INVALID_LEVEL
;
657 status
= rpccli_samr_OpenUser(pipe_cli
, mem_ctx
,
662 if (!NT_STATUS_IS_OK(status
)) {
666 status
= rpccli_samr_QueryUserInfo(pipe_cli
, mem_ctx
,
670 if (!NT_STATUS_IS_OK(status
)) {
674 status
= rpccli_samr_QuerySecurity(pipe_cli
, mem_ctx
,
678 if (!NT_STATUS_IS_OK(status
)) {
682 if (access_mask
& SAMR_USER_ACCESS_GET_GROUPS
) {
684 struct lsa_SidArray sid_array
;
685 struct samr_Ids alias_rids
;
687 uint32_t auth_flag
= 0;
690 status
= rpccli_samr_GetGroupsForUser(pipe_cli
, mem_ctx
,
693 if (!NT_STATUS_IS_OK(status
)) {
697 sid_array
.num_sids
= rid_array
->count
+ 1;
698 sid_array
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
,
700 NT_STATUS_HAVE_NO_MEMORY(sid_array
.sids
);
702 for (i
=0; i
<rid_array
->count
; i
++) {
703 sid_compose(&sid
, domain_sid
, rid_array
->rids
[i
].rid
);
704 sid_array
.sids
[i
].sid
= sid_dup_talloc(mem_ctx
, &sid
);
705 NT_STATUS_HAVE_NO_MEMORY(sid_array
.sids
[i
].sid
);
708 sid_compose(&sid
, domain_sid
, rid
);
709 sid_array
.sids
[i
].sid
= sid_dup_talloc(mem_ctx
, &sid
);
710 NT_STATUS_HAVE_NO_MEMORY(sid_array
.sids
[i
].sid
);
712 status
= rpccli_samr_GetAliasMembership(pipe_cli
, mem_ctx
,
716 if (!NT_STATUS_IS_OK(status
)) {
720 for (i
=0; i
<alias_rids
.count
; i
++) {
721 switch (alias_rids
.ids
[i
]) {
722 case 550: /* Print Operators */
723 auth_flag
|= AF_OP_PRINT
;
725 case 549: /* Server Operators */
726 auth_flag
|= AF_OP_SERVER
;
728 case 548: /* Account Operators */
729 auth_flag
|= AF_OP_ACCOUNTS
;
737 *auth_flag_p
= auth_flag
;
741 *info21
= &user_info
->info21
;
744 if (is_valid_policy_hnd(&user_handle
)) {
745 rpccli_samr_Close(pipe_cli
, mem_ctx
, &user_handle
);
751 /****************************************************************
752 ****************************************************************/
754 static uint32_t samr_rid_to_priv_level(uint32_t rid
)
757 case DOMAIN_RID_ADMINISTRATOR
:
758 return USER_PRIV_ADMIN
;
759 case DOMAIN_RID_GUEST
:
760 return USER_PRIV_GUEST
;
762 return USER_PRIV_USER
;
766 /****************************************************************
767 ****************************************************************/
769 static uint32_t samr_acb_flags_to_netapi_flags(uint32_t acb
)
771 uint32_t fl
= UF_SCRIPT
; /* god knows why */
773 fl
|= ads_acb2uf(acb
);
778 /****************************************************************
779 ****************************************************************/
781 static NTSTATUS
info21_to_USER_INFO_1(TALLOC_CTX
*mem_ctx
,
782 const struct samr_UserInfo21
*i21
,
783 struct USER_INFO_1
*i
)
786 i
->usri1_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
787 NT_STATUS_HAVE_NO_MEMORY(i
->usri1_name
);
788 i
->usri1_password
= NULL
;
789 i
->usri1_password_age
= time(NULL
) - nt_time_to_unix(i21
->last_password_change
);
790 i
->usri1_priv
= samr_rid_to_priv_level(i21
->rid
);
791 i
->usri1_home_dir
= talloc_strdup(mem_ctx
, i21
->home_directory
.string
);
792 i
->usri1_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
793 i
->usri1_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
794 i
->usri1_script_path
= talloc_strdup(mem_ctx
, i21
->logon_script
.string
);
799 /****************************************************************
800 ****************************************************************/
802 static NTSTATUS
info21_to_USER_INFO_2(TALLOC_CTX
*mem_ctx
,
803 const struct samr_UserInfo21
*i21
,
805 struct USER_INFO_2
*i
)
809 i
->usri2_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
810 NT_STATUS_HAVE_NO_MEMORY(i
->usri2_name
);
811 i
->usri2_password
= NULL
;
812 i
->usri2_password_age
= time(NULL
) - nt_time_to_unix(i21
->last_password_change
);
813 i
->usri2_priv
= samr_rid_to_priv_level(i21
->rid
);
814 i
->usri2_home_dir
= talloc_strdup(mem_ctx
, i21
->home_directory
.string
);
815 i
->usri2_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
816 i
->usri2_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
817 i
->usri2_script_path
= talloc_strdup(mem_ctx
, i21
->logon_script
.string
);
818 i
->usri2_auth_flags
= auth_flag
;
819 i
->usri2_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
820 i
->usri2_usr_comment
= talloc_strdup(mem_ctx
, i21
->comment
.string
);
821 i
->usri2_parms
= talloc_strndup(mem_ctx
, (const char *)i21
->parameters
.array
, i21
->parameters
.size
/2);
822 i
->usri2_workstations
= talloc_strdup(mem_ctx
, i21
->workstations
.string
);
823 i
->usri2_last_logon
= nt_time_to_unix(i21
->last_logon
);
824 i
->usri2_last_logoff
= nt_time_to_unix(i21
->last_logoff
);
825 i
->usri2_acct_expires
= nt_time_to_unix(i21
->acct_expiry
);
826 i
->usri2_max_storage
= USER_MAXSTORAGE_UNLIMITED
; /* FIXME */
827 i
->usri2_units_per_week
= i21
->logon_hours
.units_per_week
;
828 i
->usri2_logon_hours
= (uint8_t *)talloc_memdup(mem_ctx
, i21
->logon_hours
.bits
, 21);
829 i
->usri2_bad_pw_count
= i21
->bad_password_count
;
830 i
->usri2_num_logons
= i21
->logon_count
;
831 i
->usri2_logon_server
= talloc_strdup(mem_ctx
, "\\\\*");
832 i
->usri2_country_code
= i21
->country_code
;
833 i
->usri2_code_page
= i21
->code_page
;
838 /****************************************************************
839 ****************************************************************/
841 static NTSTATUS
info21_to_USER_INFO_3(TALLOC_CTX
*mem_ctx
,
842 const struct samr_UserInfo21
*i21
,
844 struct USER_INFO_3
*i
)
848 i
->usri3_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
849 NT_STATUS_HAVE_NO_MEMORY(i
->usri3_name
);
850 i
->usri3_password_age
= time(NULL
) - nt_time_to_unix(i21
->last_password_change
);
851 i
->usri3_priv
= samr_rid_to_priv_level(i21
->rid
);
852 i
->usri3_home_dir
= talloc_strdup(mem_ctx
, i21
->home_directory
.string
);
853 i
->usri3_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
854 i
->usri3_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
855 i
->usri3_script_path
= talloc_strdup(mem_ctx
, i21
->logon_script
.string
);
856 i
->usri3_auth_flags
= auth_flag
;
857 i
->usri3_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
858 i
->usri3_usr_comment
= talloc_strdup(mem_ctx
, i21
->comment
.string
);
859 i
->usri3_parms
= talloc_strndup(mem_ctx
, (const char *)i21
->parameters
.array
, i21
->parameters
.size
/2);
860 i
->usri3_workstations
= talloc_strdup(mem_ctx
, i21
->workstations
.string
);
861 i
->usri3_last_logon
= nt_time_to_unix(i21
->last_logon
);
862 i
->usri3_last_logoff
= nt_time_to_unix(i21
->last_logoff
);
863 i
->usri3_acct_expires
= nt_time_to_unix(i21
->acct_expiry
);
864 i
->usri3_max_storage
= USER_MAXSTORAGE_UNLIMITED
; /* FIXME */
865 i
->usri3_units_per_week
= i21
->logon_hours
.units_per_week
;
866 i
->usri3_logon_hours
= (uint8_t *)talloc_memdup(mem_ctx
, i21
->logon_hours
.bits
, 21);
867 i
->usri3_bad_pw_count
= i21
->bad_password_count
;
868 i
->usri3_num_logons
= i21
->logon_count
;
869 i
->usri3_logon_server
= talloc_strdup(mem_ctx
, "\\\\*");
870 i
->usri3_country_code
= i21
->country_code
;
871 i
->usri3_code_page
= i21
->code_page
;
872 i
->usri3_user_id
= i21
->rid
;
873 i
->usri3_primary_group_id
= i21
->primary_gid
;
874 i
->usri3_profile
= talloc_strdup(mem_ctx
, i21
->profile_path
.string
);
875 i
->usri3_home_dir_drive
= talloc_strdup(mem_ctx
, i21
->home_drive
.string
);
876 i
->usri3_password_expired
= i21
->password_expired
;
881 /****************************************************************
882 ****************************************************************/
884 static NTSTATUS
info21_to_USER_INFO_4(TALLOC_CTX
*mem_ctx
,
885 const struct samr_UserInfo21
*i21
,
887 struct dom_sid
*domain_sid
,
888 struct USER_INFO_4
*i
)
894 i
->usri4_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
895 NT_STATUS_HAVE_NO_MEMORY(i
->usri4_name
);
896 i
->usri4_password_age
= time(NULL
) - nt_time_to_unix(i21
->last_password_change
);
897 i
->usri4_password
= NULL
;
898 i
->usri4_priv
= samr_rid_to_priv_level(i21
->rid
);
899 i
->usri4_home_dir
= talloc_strdup(mem_ctx
, i21
->home_directory
.string
);
900 i
->usri4_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
901 i
->usri4_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
902 i
->usri4_script_path
= talloc_strdup(mem_ctx
, i21
->logon_script
.string
);
903 i
->usri4_auth_flags
= auth_flag
;
904 i
->usri4_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
905 i
->usri4_usr_comment
= talloc_strdup(mem_ctx
, i21
->comment
.string
);
906 i
->usri4_parms
= talloc_strndup(mem_ctx
, (const char *)i21
->parameters
.array
, i21
->parameters
.size
/2);
907 i
->usri4_workstations
= talloc_strdup(mem_ctx
, i21
->workstations
.string
);
908 i
->usri4_last_logon
= nt_time_to_unix(i21
->last_logon
);
909 i
->usri4_last_logoff
= nt_time_to_unix(i21
->last_logoff
);
910 i
->usri4_acct_expires
= nt_time_to_unix(i21
->acct_expiry
);
911 i
->usri4_max_storage
= USER_MAXSTORAGE_UNLIMITED
; /* FIXME */
912 i
->usri4_units_per_week
= i21
->logon_hours
.units_per_week
;
913 i
->usri4_logon_hours
= (uint8_t *)talloc_memdup(mem_ctx
, i21
->logon_hours
.bits
, 21);
914 i
->usri4_bad_pw_count
= i21
->bad_password_count
;
915 i
->usri4_num_logons
= i21
->logon_count
;
916 i
->usri4_logon_server
= talloc_strdup(mem_ctx
, "\\\\*");
917 i
->usri4_country_code
= i21
->country_code
;
918 i
->usri4_code_page
= i21
->code_page
;
919 if (!sid_compose(&sid
, domain_sid
, i21
->rid
)) {
920 return NT_STATUS_NO_MEMORY
;
922 i
->usri4_user_sid
= (struct domsid
*)sid_dup_talloc(mem_ctx
, &sid
);
923 i
->usri4_primary_group_id
= i21
->primary_gid
;
924 i
->usri4_profile
= talloc_strdup(mem_ctx
, i21
->profile_path
.string
);
925 i
->usri4_home_dir_drive
= talloc_strdup(mem_ctx
, i21
->home_drive
.string
);
926 i
->usri4_password_expired
= i21
->password_expired
;
931 /****************************************************************
932 ****************************************************************/
934 static NTSTATUS
info21_to_USER_INFO_10(TALLOC_CTX
*mem_ctx
,
935 const struct samr_UserInfo21
*i21
,
936 struct USER_INFO_10
*i
)
940 i
->usri10_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
941 NT_STATUS_HAVE_NO_MEMORY(i
->usri10_name
);
942 i
->usri10_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
943 i
->usri10_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
944 i
->usri10_usr_comment
= talloc_strdup(mem_ctx
, i21
->comment
.string
);
949 /****************************************************************
950 ****************************************************************/
952 static NTSTATUS
info21_to_USER_INFO_11(TALLOC_CTX
*mem_ctx
,
953 const struct samr_UserInfo21
*i21
,
955 struct USER_INFO_11
*i
)
959 i
->usri11_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
960 NT_STATUS_HAVE_NO_MEMORY(i
->usri11_name
);
961 i
->usri11_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
962 i
->usri11_usr_comment
= talloc_strdup(mem_ctx
, i21
->comment
.string
);
963 i
->usri11_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
964 i
->usri11_priv
= samr_rid_to_priv_level(i21
->rid
);
965 i
->usri11_auth_flags
= auth_flag
;
966 i
->usri11_password_age
= time(NULL
) - nt_time_to_unix(i21
->last_password_change
);
967 i
->usri11_home_dir
= talloc_strdup(mem_ctx
, i21
->home_directory
.string
);
968 i
->usri11_parms
= talloc_strndup(mem_ctx
, (const char *)i21
->parameters
.array
, i21
->parameters
.size
/2);
969 i
->usri11_last_logon
= nt_time_to_unix(i21
->last_logon
);
970 i
->usri11_last_logoff
= nt_time_to_unix(i21
->last_logoff
);
971 i
->usri11_bad_pw_count
= i21
->bad_password_count
;
972 i
->usri11_num_logons
= i21
->logon_count
;
973 i
->usri11_logon_server
= talloc_strdup(mem_ctx
, "\\\\*");
974 i
->usri11_country_code
= i21
->country_code
;
975 i
->usri11_workstations
= talloc_strdup(mem_ctx
, i21
->workstations
.string
);
976 i
->usri11_max_storage
= USER_MAXSTORAGE_UNLIMITED
; /* FIXME */
977 i
->usri11_units_per_week
= i21
->logon_hours
.units_per_week
;
978 i
->usri11_logon_hours
= (uint8_t *)talloc_memdup(mem_ctx
, i21
->logon_hours
.bits
, 21);
979 i
->usri11_code_page
= i21
->code_page
;
984 /****************************************************************
985 ****************************************************************/
987 static NTSTATUS
info21_to_USER_INFO_20(TALLOC_CTX
*mem_ctx
,
988 const struct samr_UserInfo21
*i21
,
989 struct USER_INFO_20
*i
)
993 i
->usri20_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
994 NT_STATUS_HAVE_NO_MEMORY(i
->usri20_name
);
995 i
->usri20_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
996 i
->usri20_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
997 i
->usri20_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
998 i
->usri20_user_id
= i21
->rid
;
1000 return NT_STATUS_OK
;
1003 /****************************************************************
1004 ****************************************************************/
1006 static NTSTATUS
info21_to_USER_INFO_23(TALLOC_CTX
*mem_ctx
,
1007 const struct samr_UserInfo21
*i21
,
1008 struct dom_sid
*domain_sid
,
1009 struct USER_INFO_23
*i
)
1015 i
->usri23_name
= talloc_strdup(mem_ctx
, i21
->account_name
.string
);
1016 NT_STATUS_HAVE_NO_MEMORY(i
->usri23_name
);
1017 i
->usri23_comment
= talloc_strdup(mem_ctx
, i21
->description
.string
);
1018 i
->usri23_full_name
= talloc_strdup(mem_ctx
, i21
->full_name
.string
);
1019 i
->usri23_flags
= samr_acb_flags_to_netapi_flags(i21
->acct_flags
);
1020 if (!sid_compose(&sid
, domain_sid
, i21
->rid
)) {
1021 return NT_STATUS_NO_MEMORY
;
1023 i
->usri23_user_sid
= (struct domsid
*)sid_dup_talloc(mem_ctx
, &sid
);
1025 return NT_STATUS_OK
;
1028 /****************************************************************
1029 ****************************************************************/
1031 static NTSTATUS
libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX
*mem_ctx
,
1032 struct rpc_pipe_client
*pipe_cli
,
1033 struct dom_sid
*domain_sid
,
1034 struct policy_handle
*domain_handle
,
1035 struct policy_handle
*builtin_handle
,
1036 const char *user_name
,
1040 uint32_t *num_entries
)
1044 struct samr_UserInfo21
*info21
= NULL
;
1045 struct sec_desc_buf
*sec_desc
= NULL
;
1046 uint32_t auth_flag
= 0;
1048 struct USER_INFO_0 info0
;
1049 struct USER_INFO_1 info1
;
1050 struct USER_INFO_2 info2
;
1051 struct USER_INFO_3 info3
;
1052 struct USER_INFO_4 info4
;
1053 struct USER_INFO_10 info10
;
1054 struct USER_INFO_11 info11
;
1055 struct USER_INFO_20 info20
;
1056 struct USER_INFO_23 info23
;
1070 return NT_STATUS_INVALID_LEVEL
;
1074 info0
.usri0_name
= talloc_strdup(mem_ctx
, user_name
);
1075 NT_STATUS_HAVE_NO_MEMORY(info0
.usri0_name
);
1077 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_0
, info0
,
1078 (struct USER_INFO_0
**)buffer
, num_entries
);
1080 return NT_STATUS_OK
;
1083 status
= libnetapi_samr_lookup_user(mem_ctx
, pipe_cli
,
1094 if (!NT_STATUS_IS_OK(status
)) {
1100 /* already returned above */
1103 status
= info21_to_USER_INFO_1(mem_ctx
, info21
, &info1
);
1104 NT_STATUS_NOT_OK_RETURN(status
);
1106 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_1
, info1
,
1107 (struct USER_INFO_1
**)buffer
, num_entries
);
1111 status
= info21_to_USER_INFO_2(mem_ctx
, info21
, auth_flag
, &info2
);
1112 NT_STATUS_NOT_OK_RETURN(status
);
1114 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_2
, info2
,
1115 (struct USER_INFO_2
**)buffer
, num_entries
);
1119 status
= info21_to_USER_INFO_3(mem_ctx
, info21
, auth_flag
, &info3
);
1120 NT_STATUS_NOT_OK_RETURN(status
);
1122 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_3
, info3
,
1123 (struct USER_INFO_3
**)buffer
, num_entries
);
1127 status
= info21_to_USER_INFO_4(mem_ctx
, info21
, auth_flag
, domain_sid
, &info4
);
1128 NT_STATUS_NOT_OK_RETURN(status
);
1130 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_4
, info4
,
1131 (struct USER_INFO_4
**)buffer
, num_entries
);
1135 status
= info21_to_USER_INFO_10(mem_ctx
, info21
, &info10
);
1136 NT_STATUS_NOT_OK_RETURN(status
);
1138 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_10
, info10
,
1139 (struct USER_INFO_10
**)buffer
, num_entries
);
1143 status
= info21_to_USER_INFO_11(mem_ctx
, info21
, auth_flag
, &info11
);
1144 NT_STATUS_NOT_OK_RETURN(status
);
1146 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_11
, info11
,
1147 (struct USER_INFO_11
**)buffer
, num_entries
);
1151 status
= info21_to_USER_INFO_20(mem_ctx
, info21
, &info20
);
1152 NT_STATUS_NOT_OK_RETURN(status
);
1154 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_20
, info20
,
1155 (struct USER_INFO_20
**)buffer
, num_entries
);
1159 status
= info21_to_USER_INFO_23(mem_ctx
, info21
, domain_sid
, &info23
);
1160 NT_STATUS_NOT_OK_RETURN(status
);
1162 ADD_TO_ARRAY(mem_ctx
, struct USER_INFO_23
, info23
,
1163 (struct USER_INFO_23
**)buffer
, num_entries
);
1166 return NT_STATUS_INVALID_LEVEL
;
1173 /****************************************************************
1174 ****************************************************************/
1176 WERROR
NetUserEnum_r(struct libnetapi_ctx
*ctx
,
1177 struct NetUserEnum
*r
)
1179 struct rpc_pipe_client
*pipe_cli
= NULL
;
1180 struct policy_handle connect_handle
;
1181 struct dom_sid2
*domain_sid
= NULL
;
1182 struct policy_handle domain_handle
, builtin_handle
;
1183 struct samr_SamArray
*sam
= NULL
;
1184 uint32_t filter
= ACB_NORMAL
;
1186 uint32_t entries_read
= 0;
1188 NTSTATUS status
= NT_STATUS_OK
;
1191 ZERO_STRUCT(connect_handle
);
1192 ZERO_STRUCT(domain_handle
);
1193 ZERO_STRUCT(builtin_handle
);
1195 if (!r
->out
.buffer
) {
1196 return WERR_INVALID_PARAM
;
1199 *r
->out
.buffer
= NULL
;
1200 *r
->out
.entries_read
= 0;
1202 switch (r
->in
.level
) {
1214 return WERR_UNKNOWN_LEVEL
;
1217 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
1218 &ndr_table_samr
.syntax_id
,
1220 if (!W_ERROR_IS_OK(werr
)) {
1224 werr
= libnetapi_samr_open_builtin_domain(ctx
, pipe_cli
,
1225 SAMR_ACCESS_ENUM_DOMAINS
|
1226 SAMR_ACCESS_OPEN_DOMAIN
,
1227 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
1228 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
,
1231 if (!W_ERROR_IS_OK(werr
)) {
1235 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
1236 SAMR_ACCESS_ENUM_DOMAINS
|
1237 SAMR_ACCESS_OPEN_DOMAIN
,
1238 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
|
1239 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
|
1240 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1244 if (!W_ERROR_IS_OK(werr
)) {
1248 switch (r
->in
.filter
) {
1249 case FILTER_NORMAL_ACCOUNT
:
1250 filter
= ACB_NORMAL
;
1252 case FILTER_TEMP_DUPLICATE_ACCOUNT
:
1253 filter
= ACB_TEMPDUP
;
1255 case FILTER_INTERDOMAIN_TRUST_ACCOUNT
:
1256 filter
= ACB_DOMTRUST
;
1258 case FILTER_WORKSTATION_TRUST_ACCOUNT
:
1259 filter
= ACB_WSTRUST
;
1261 case FILTER_SERVER_TRUST_ACCOUNT
:
1262 filter
= ACB_SVRTRUST
;
1268 status
= rpccli_samr_EnumDomainUsers(pipe_cli
,
1271 r
->in
.resume_handle
,
1276 werr
= ntstatus_to_werror(status
);
1277 if (NT_STATUS_IS_ERR(status
)) {
1281 for (i
=0; i
< sam
->count
; i
++) {
1283 status
= libnetapi_samr_lookup_user_map_USER_INFO(ctx
, pipe_cli
,
1287 sam
->entries
[i
].name
.string
,
1288 sam
->entries
[i
].idx
,
1291 r
->out
.entries_read
);
1292 if (!NT_STATUS_IS_OK(status
)) {
1293 werr
= ntstatus_to_werror(status
);
1300 if (NT_STATUS_IS_OK(status
) ||
1301 NT_STATUS_IS_ERR(status
)) {
1303 if (ctx
->disable_policy_handle_cache
) {
1304 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
1305 libnetapi_samr_close_builtin_handle(ctx
, &builtin_handle
);
1306 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
1313 /****************************************************************
1314 ****************************************************************/
1316 WERROR
NetUserEnum_l(struct libnetapi_ctx
*ctx
,
1317 struct NetUserEnum
*r
)
1319 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserEnum
);
1322 /****************************************************************
1323 ****************************************************************/
1325 static WERROR
convert_samr_dispinfo_to_NET_DISPLAY_USER(TALLOC_CTX
*mem_ctx
,
1326 struct samr_DispInfoGeneral
*info
,
1327 uint32_t *entries_read
,
1330 struct NET_DISPLAY_USER
*user
= NULL
;
1333 user
= TALLOC_ZERO_ARRAY(mem_ctx
,
1334 struct NET_DISPLAY_USER
,
1336 W_ERROR_HAVE_NO_MEMORY(user
);
1338 for (i
= 0; i
< info
->count
; i
++) {
1339 user
[i
].usri1_name
= talloc_strdup(mem_ctx
,
1340 info
->entries
[i
].account_name
.string
);
1341 user
[i
].usri1_comment
= talloc_strdup(mem_ctx
,
1342 info
->entries
[i
].description
.string
);
1343 user
[i
].usri1_flags
=
1344 info
->entries
[i
].acct_flags
;
1345 user
[i
].usri1_full_name
= talloc_strdup(mem_ctx
,
1346 info
->entries
[i
].full_name
.string
);
1347 user
[i
].usri1_user_id
=
1348 info
->entries
[i
].rid
;
1349 user
[i
].usri1_next_index
=
1350 info
->entries
[i
].idx
;
1352 if (!user
[i
].usri1_name
) {
1357 *buffer
= talloc_memdup(mem_ctx
, user
,
1358 sizeof(struct NET_DISPLAY_USER
) * info
->count
);
1359 W_ERROR_HAVE_NO_MEMORY(*buffer
);
1361 *entries_read
= info
->count
;
1366 /****************************************************************
1367 ****************************************************************/
1369 static WERROR
convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(TALLOC_CTX
*mem_ctx
,
1370 struct samr_DispInfoFull
*info
,
1371 uint32_t *entries_read
,
1374 struct NET_DISPLAY_MACHINE
*machine
= NULL
;
1377 machine
= TALLOC_ZERO_ARRAY(mem_ctx
,
1378 struct NET_DISPLAY_MACHINE
,
1380 W_ERROR_HAVE_NO_MEMORY(machine
);
1382 for (i
= 0; i
< info
->count
; i
++) {
1383 machine
[i
].usri2_name
= talloc_strdup(mem_ctx
,
1384 info
->entries
[i
].account_name
.string
);
1385 machine
[i
].usri2_comment
= talloc_strdup(mem_ctx
,
1386 info
->entries
[i
].description
.string
);
1387 machine
[i
].usri2_flags
=
1388 info
->entries
[i
].acct_flags
;
1389 machine
[i
].usri2_user_id
=
1390 info
->entries
[i
].rid
;
1391 machine
[i
].usri2_next_index
=
1392 info
->entries
[i
].idx
;
1394 if (!machine
[i
].usri2_name
) {
1399 *buffer
= talloc_memdup(mem_ctx
, machine
,
1400 sizeof(struct NET_DISPLAY_MACHINE
) * info
->count
);
1401 W_ERROR_HAVE_NO_MEMORY(*buffer
);
1403 *entries_read
= info
->count
;
1408 /****************************************************************
1409 ****************************************************************/
1411 static WERROR
convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX
*mem_ctx
,
1412 struct samr_DispInfoFullGroups
*info
,
1413 uint32_t *entries_read
,
1416 struct NET_DISPLAY_GROUP
*group
= NULL
;
1419 group
= TALLOC_ZERO_ARRAY(mem_ctx
,
1420 struct NET_DISPLAY_GROUP
,
1422 W_ERROR_HAVE_NO_MEMORY(group
);
1424 for (i
= 0; i
< info
->count
; i
++) {
1425 group
[i
].grpi3_name
= talloc_strdup(mem_ctx
,
1426 info
->entries
[i
].account_name
.string
);
1427 group
[i
].grpi3_comment
= talloc_strdup(mem_ctx
,
1428 info
->entries
[i
].description
.string
);
1429 group
[i
].grpi3_group_id
=
1430 info
->entries
[i
].rid
;
1431 group
[i
].grpi3_attributes
=
1432 info
->entries
[i
].acct_flags
;
1433 group
[i
].grpi3_next_index
=
1434 info
->entries
[i
].idx
;
1436 if (!group
[i
].grpi3_name
) {
1441 *buffer
= talloc_memdup(mem_ctx
, group
,
1442 sizeof(struct NET_DISPLAY_GROUP
) * info
->count
);
1443 W_ERROR_HAVE_NO_MEMORY(*buffer
);
1445 *entries_read
= info
->count
;
1451 /****************************************************************
1452 ****************************************************************/
1454 static WERROR
convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX
*mem_ctx
,
1455 union samr_DispInfo
*info
,
1457 uint32_t *entries_read
,
1462 return convert_samr_dispinfo_to_NET_DISPLAY_USER(mem_ctx
,
1467 return convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(mem_ctx
,
1472 return convert_samr_dispinfo_to_NET_DISPLAY_GROUP(mem_ctx
,
1477 return WERR_UNKNOWN_LEVEL
;
1483 /****************************************************************
1484 ****************************************************************/
1486 WERROR
NetQueryDisplayInformation_r(struct libnetapi_ctx
*ctx
,
1487 struct NetQueryDisplayInformation
*r
)
1489 struct rpc_pipe_client
*pipe_cli
= NULL
;
1490 struct policy_handle connect_handle
;
1491 struct dom_sid2
*domain_sid
= NULL
;
1492 struct policy_handle domain_handle
;
1493 union samr_DispInfo info
;
1495 uint32_t total_size
= 0;
1496 uint32_t returned_size
= 0;
1498 NTSTATUS status
= NT_STATUS_OK
;
1501 ZERO_STRUCT(connect_handle
);
1502 ZERO_STRUCT(domain_handle
);
1504 switch (r
->in
.level
) {
1510 return WERR_UNKNOWN_LEVEL
;
1513 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
1514 &ndr_table_samr
.syntax_id
,
1516 if (!W_ERROR_IS_OK(werr
)) {
1520 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
1521 SAMR_ACCESS_ENUM_DOMAINS
|
1522 SAMR_ACCESS_OPEN_DOMAIN
,
1523 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
|
1524 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
|
1525 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1529 if (!W_ERROR_IS_OK(werr
)) {
1533 status
= rpccli_samr_QueryDisplayInfo2(pipe_cli
,
1538 r
->in
.entries_requested
,
1543 if (!NT_STATUS_IS_OK(status
)) {
1544 werr
= ntstatus_to_werror(status
);
1548 werr
= convert_samr_dispinfo_to_NET_DISPLAY(ctx
, &info
,
1550 r
->out
.entries_read
,
1554 if (NT_STATUS_IS_OK(status
) ||
1555 NT_STATUS_IS_ERR(status
)) {
1557 if (ctx
->disable_policy_handle_cache
) {
1558 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
1559 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
1567 /****************************************************************
1568 ****************************************************************/
1571 WERROR
NetQueryDisplayInformation_l(struct libnetapi_ctx
*ctx
,
1572 struct NetQueryDisplayInformation
*r
)
1574 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetQueryDisplayInformation
);
1577 /****************************************************************
1578 ****************************************************************/
1580 WERROR
NetUserChangePassword_r(struct libnetapi_ctx
*ctx
,
1581 struct NetUserChangePassword
*r
)
1583 return WERR_NOT_SUPPORTED
;
1586 /****************************************************************
1587 ****************************************************************/
1589 WERROR
NetUserChangePassword_l(struct libnetapi_ctx
*ctx
,
1590 struct NetUserChangePassword
*r
)
1592 return WERR_NOT_SUPPORTED
;
1595 /****************************************************************
1596 ****************************************************************/
1598 WERROR
NetUserGetInfo_r(struct libnetapi_ctx
*ctx
,
1599 struct NetUserGetInfo
*r
)
1601 struct rpc_pipe_client
*pipe_cli
= NULL
;
1605 struct policy_handle connect_handle
, domain_handle
, builtin_handle
, user_handle
;
1606 struct lsa_String lsa_account_name
;
1607 struct dom_sid2
*domain_sid
= NULL
;
1608 struct samr_Ids user_rids
, name_types
;
1609 uint32_t num_entries
= 0;
1611 ZERO_STRUCT(connect_handle
);
1612 ZERO_STRUCT(domain_handle
);
1613 ZERO_STRUCT(builtin_handle
);
1614 ZERO_STRUCT(user_handle
);
1616 if (!r
->out
.buffer
) {
1617 return WERR_INVALID_PARAM
;
1620 switch (r
->in
.level
) {
1632 werr
= WERR_UNKNOWN_LEVEL
;
1636 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
1637 &ndr_table_samr
.syntax_id
,
1639 if (!W_ERROR_IS_OK(werr
)) {
1643 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
1644 SAMR_ACCESS_ENUM_DOMAINS
|
1645 SAMR_ACCESS_OPEN_DOMAIN
,
1646 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1650 if (!W_ERROR_IS_OK(werr
)) {
1654 werr
= libnetapi_samr_open_builtin_domain(ctx
, pipe_cli
,
1655 SAMR_ACCESS_ENUM_DOMAINS
|
1656 SAMR_ACCESS_OPEN_DOMAIN
,
1657 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
1658 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
,
1661 if (!W_ERROR_IS_OK(werr
)) {
1665 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
1667 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
1673 if (!NT_STATUS_IS_OK(status
)) {
1674 werr
= ntstatus_to_werror(status
);
1678 status
= libnetapi_samr_lookup_user_map_USER_INFO(ctx
, pipe_cli
,
1687 if (!NT_STATUS_IS_OK(status
)) {
1688 werr
= ntstatus_to_werror(status
);
1693 if (is_valid_policy_hnd(&user_handle
)) {
1694 rpccli_samr_Close(pipe_cli
, ctx
, &user_handle
);
1697 if (ctx
->disable_policy_handle_cache
) {
1698 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
1699 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
1705 /****************************************************************
1706 ****************************************************************/
1708 WERROR
NetUserGetInfo_l(struct libnetapi_ctx
*ctx
,
1709 struct NetUserGetInfo
*r
)
1711 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserGetInfo
);
1714 /****************************************************************
1715 ****************************************************************/
1717 WERROR
NetUserSetInfo_r(struct libnetapi_ctx
*ctx
,
1718 struct NetUserSetInfo
*r
)
1720 struct rpc_pipe_client
*pipe_cli
= NULL
;
1724 struct policy_handle connect_handle
, domain_handle
, builtin_handle
, user_handle
;
1725 struct lsa_String lsa_account_name
;
1726 struct dom_sid2
*domain_sid
= NULL
;
1727 struct samr_Ids user_rids
, name_types
;
1728 uint32_t user_mask
= 0;
1730 struct USER_INFO_X uX
;
1732 ZERO_STRUCT(connect_handle
);
1733 ZERO_STRUCT(domain_handle
);
1734 ZERO_STRUCT(builtin_handle
);
1735 ZERO_STRUCT(user_handle
);
1737 if (!r
->in
.buffer
) {
1738 return WERR_INVALID_PARAM
;
1741 switch (r
->in
.level
) {
1744 user_mask
= SAMR_USER_ACCESS_SET_PASSWORD
;
1753 user_mask
= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1757 user_mask
= SAMR_USER_ACCESS_SET_LOC_COM
;
1759 user_mask
= SAMR_USER_ACCESS_SET_ATTRIBUTES
|
1760 SAMR_USER_ACCESS_GET_GROUPS
;
1763 user_mask
= STD_RIGHT_READ_CONTROL_ACCESS
|
1764 STD_RIGHT_WRITE_DAC_ACCESS
|
1765 SAMR_USER_ACCESS_GET_GROUPS
|
1766 SAMR_USER_ACCESS_SET_PASSWORD
|
1767 SAMR_USER_ACCESS_SET_ATTRIBUTES
|
1768 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1769 SAMR_USER_ACCESS_SET_LOC_COM
;
1781 werr
= WERR_NOT_SUPPORTED
;
1784 werr
= WERR_UNKNOWN_LEVEL
;
1788 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
1789 &ndr_table_samr
.syntax_id
,
1791 if (!W_ERROR_IS_OK(werr
)) {
1795 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
1796 SAMR_ACCESS_ENUM_DOMAINS
|
1797 SAMR_ACCESS_OPEN_DOMAIN
,
1798 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
1799 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1803 if (!W_ERROR_IS_OK(werr
)) {
1807 werr
= libnetapi_samr_open_builtin_domain(ctx
, pipe_cli
,
1808 SAMR_ACCESS_ENUM_DOMAINS
|
1809 SAMR_ACCESS_OPEN_DOMAIN
,
1810 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
1811 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
,
1814 if (!W_ERROR_IS_OK(werr
)) {
1818 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
1820 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
1826 if (!NT_STATUS_IS_OK(status
)) {
1827 werr
= ntstatus_to_werror(status
);
1831 status
= rpccli_samr_OpenUser(pipe_cli
, ctx
,
1836 if (!NT_STATUS_IS_OK(status
)) {
1837 werr
= ntstatus_to_werror(status
);
1841 status
= construct_USER_INFO_X(r
->in
.level
, r
->in
.buffer
, &uX
);
1842 if (!NT_STATUS_IS_OK(status
)) {
1843 werr
= ntstatus_to_werror(status
);
1847 status
= set_user_info_USER_INFO_X(ctx
, pipe_cli
,
1848 &pipe_cli
->auth
->user_session_key
,
1851 if (!NT_STATUS_IS_OK(status
)) {
1852 werr
= ntstatus_to_werror(status
);
1859 if (is_valid_policy_hnd(&user_handle
)) {
1860 rpccli_samr_Close(pipe_cli
, ctx
, &user_handle
);
1863 if (ctx
->disable_policy_handle_cache
) {
1864 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
1865 libnetapi_samr_close_builtin_handle(ctx
, &builtin_handle
);
1866 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
1872 /****************************************************************
1873 ****************************************************************/
1875 WERROR
NetUserSetInfo_l(struct libnetapi_ctx
*ctx
,
1876 struct NetUserSetInfo
*r
)
1878 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserSetInfo
);
1881 /****************************************************************
1882 ****************************************************************/
1884 static NTSTATUS
query_USER_MODALS_INFO_rpc(TALLOC_CTX
*mem_ctx
,
1885 struct rpc_pipe_client
*pipe_cli
,
1886 struct policy_handle
*domain_handle
,
1887 struct samr_DomInfo1
*info1
,
1888 struct samr_DomInfo3
*info3
,
1889 struct samr_DomInfo5
*info5
,
1890 struct samr_DomInfo6
*info6
,
1891 struct samr_DomInfo7
*info7
,
1892 struct samr_DomInfo12
*info12
)
1895 union samr_DomainInfo
*dom_info
= NULL
;
1898 status
= rpccli_samr_QueryDomainInfo(pipe_cli
, mem_ctx
,
1902 NT_STATUS_NOT_OK_RETURN(status
);
1904 *info1
= dom_info
->info1
;
1908 status
= rpccli_samr_QueryDomainInfo(pipe_cli
, mem_ctx
,
1912 NT_STATUS_NOT_OK_RETURN(status
);
1914 *info3
= dom_info
->info3
;
1918 status
= rpccli_samr_QueryDomainInfo(pipe_cli
, mem_ctx
,
1922 NT_STATUS_NOT_OK_RETURN(status
);
1924 *info5
= dom_info
->info5
;
1928 status
= rpccli_samr_QueryDomainInfo(pipe_cli
, mem_ctx
,
1932 NT_STATUS_NOT_OK_RETURN(status
);
1934 *info6
= dom_info
->info6
;
1938 status
= rpccli_samr_QueryDomainInfo(pipe_cli
, mem_ctx
,
1942 NT_STATUS_NOT_OK_RETURN(status
);
1944 *info7
= dom_info
->info7
;
1948 status
= rpccli_samr_QueryDomainInfo2(pipe_cli
, mem_ctx
,
1952 NT_STATUS_NOT_OK_RETURN(status
);
1954 *info12
= dom_info
->info12
;
1957 return NT_STATUS_OK
;
1960 /****************************************************************
1961 ****************************************************************/
1963 static NTSTATUS
query_USER_MODALS_INFO_0(TALLOC_CTX
*mem_ctx
,
1964 struct rpc_pipe_client
*pipe_cli
,
1965 struct policy_handle
*domain_handle
,
1966 struct USER_MODALS_INFO_0
*info0
)
1969 struct samr_DomInfo1 dom_info1
;
1970 struct samr_DomInfo3 dom_info3
;
1972 ZERO_STRUCTP(info0
);
1974 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
1983 NT_STATUS_NOT_OK_RETURN(status
);
1985 info0
->usrmod0_min_passwd_len
=
1986 dom_info1
.min_password_length
;
1987 info0
->usrmod0_max_passwd_age
=
1988 nt_time_to_unix_abs((NTTIME
*)&dom_info1
.max_password_age
);
1989 info0
->usrmod0_min_passwd_age
=
1990 nt_time_to_unix_abs((NTTIME
*)&dom_info1
.min_password_age
);
1991 info0
->usrmod0_password_hist_len
=
1992 dom_info1
.password_history_length
;
1994 info0
->usrmod0_force_logoff
=
1995 nt_time_to_unix_abs(&dom_info3
.force_logoff_time
);
1997 return NT_STATUS_OK
;
2000 /****************************************************************
2001 ****************************************************************/
2003 static NTSTATUS
query_USER_MODALS_INFO_1(TALLOC_CTX
*mem_ctx
,
2004 struct rpc_pipe_client
*pipe_cli
,
2005 struct policy_handle
*domain_handle
,
2006 struct USER_MODALS_INFO_1
*info1
)
2009 struct samr_DomInfo6 dom_info6
;
2010 struct samr_DomInfo7 dom_info7
;
2012 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2021 NT_STATUS_NOT_OK_RETURN(status
);
2023 info1
->usrmod1_primary
=
2024 talloc_strdup(mem_ctx
, dom_info6
.primary
.string
);
2026 info1
->usrmod1_role
= dom_info7
.role
;
2028 return NT_STATUS_OK
;
2031 /****************************************************************
2032 ****************************************************************/
2034 static NTSTATUS
query_USER_MODALS_INFO_2(TALLOC_CTX
*mem_ctx
,
2035 struct rpc_pipe_client
*pipe_cli
,
2036 struct policy_handle
*domain_handle
,
2037 struct dom_sid
*domain_sid
,
2038 struct USER_MODALS_INFO_2
*info2
)
2041 struct samr_DomInfo5 dom_info5
;
2043 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2052 NT_STATUS_NOT_OK_RETURN(status
);
2054 info2
->usrmod2_domain_name
=
2055 talloc_strdup(mem_ctx
, dom_info5
.domain_name
.string
);
2056 info2
->usrmod2_domain_id
=
2057 (struct domsid
*)sid_dup_talloc(mem_ctx
, domain_sid
);
2059 NT_STATUS_HAVE_NO_MEMORY(info2
->usrmod2_domain_name
);
2060 NT_STATUS_HAVE_NO_MEMORY(info2
->usrmod2_domain_id
);
2062 return NT_STATUS_OK
;
2065 /****************************************************************
2066 ****************************************************************/
2068 static NTSTATUS
query_USER_MODALS_INFO_3(TALLOC_CTX
*mem_ctx
,
2069 struct rpc_pipe_client
*pipe_cli
,
2070 struct policy_handle
*domain_handle
,
2071 struct USER_MODALS_INFO_3
*info3
)
2074 struct samr_DomInfo12 dom_info12
;
2076 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2085 NT_STATUS_NOT_OK_RETURN(status
);
2087 info3
->usrmod3_lockout_duration
=
2088 nt_time_to_unix_abs(&dom_info12
.lockout_duration
);
2089 info3
->usrmod3_lockout_observation_window
=
2090 nt_time_to_unix_abs(&dom_info12
.lockout_window
);
2091 info3
->usrmod3_lockout_threshold
=
2092 dom_info12
.lockout_threshold
;
2094 return NT_STATUS_OK
;
2097 /****************************************************************
2098 ****************************************************************/
2100 static NTSTATUS
query_USER_MODALS_INFO_to_buffer(TALLOC_CTX
*mem_ctx
,
2101 struct rpc_pipe_client
*pipe_cli
,
2103 struct policy_handle
*domain_handle
,
2104 struct dom_sid
*domain_sid
,
2109 struct USER_MODALS_INFO_0 info0
;
2110 struct USER_MODALS_INFO_1 info1
;
2111 struct USER_MODALS_INFO_2 info2
;
2112 struct USER_MODALS_INFO_3 info3
;
2115 return ERROR_INSUFFICIENT_BUFFER
;
2120 status
= query_USER_MODALS_INFO_0(mem_ctx
,
2124 NT_STATUS_NOT_OK_RETURN(status
);
2126 *buffer
= (uint8_t *)talloc_memdup(mem_ctx
, &info0
,
2131 status
= query_USER_MODALS_INFO_1(mem_ctx
,
2135 NT_STATUS_NOT_OK_RETURN(status
);
2137 *buffer
= (uint8_t *)talloc_memdup(mem_ctx
, &info1
,
2141 status
= query_USER_MODALS_INFO_2(mem_ctx
,
2146 NT_STATUS_NOT_OK_RETURN(status
);
2148 *buffer
= (uint8_t *)talloc_memdup(mem_ctx
, &info2
,
2152 status
= query_USER_MODALS_INFO_3(mem_ctx
,
2156 NT_STATUS_NOT_OK_RETURN(status
);
2158 *buffer
= (uint8_t *)talloc_memdup(mem_ctx
, &info3
,
2165 NT_STATUS_HAVE_NO_MEMORY(*buffer
);
2167 return NT_STATUS_OK
;
2170 /****************************************************************
2171 ****************************************************************/
2173 WERROR
NetUserModalsGet_r(struct libnetapi_ctx
*ctx
,
2174 struct NetUserModalsGet
*r
)
2176 struct rpc_pipe_client
*pipe_cli
= NULL
;
2180 struct policy_handle connect_handle
, domain_handle
;
2181 struct dom_sid2
*domain_sid
= NULL
;
2182 uint32_t access_mask
= SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
;
2184 ZERO_STRUCT(connect_handle
);
2185 ZERO_STRUCT(domain_handle
);
2187 if (!r
->out
.buffer
) {
2188 return WERR_INVALID_PARAM
;
2191 switch (r
->in
.level
) {
2193 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
2194 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
;
2198 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
;
2201 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
;
2204 werr
= WERR_UNKNOWN_LEVEL
;
2208 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
2209 &ndr_table_samr
.syntax_id
,
2211 if (!W_ERROR_IS_OK(werr
)) {
2215 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
2216 SAMR_ACCESS_ENUM_DOMAINS
|
2217 SAMR_ACCESS_OPEN_DOMAIN
,
2222 if (!W_ERROR_IS_OK(werr
)) {
2229 /* 3: 12 (DomainInfo2) */
2231 status
= query_USER_MODALS_INFO_to_buffer(ctx
,
2237 if (!NT_STATUS_IS_OK(status
)) {
2238 werr
= ntstatus_to_werror(status
);
2243 if (ctx
->disable_policy_handle_cache
) {
2244 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
2245 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
2251 /****************************************************************
2252 ****************************************************************/
2254 WERROR
NetUserModalsGet_l(struct libnetapi_ctx
*ctx
,
2255 struct NetUserModalsGet
*r
)
2257 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserModalsGet
);
2260 /****************************************************************
2261 ****************************************************************/
2263 static NTSTATUS
set_USER_MODALS_INFO_rpc(TALLOC_CTX
*mem_ctx
,
2264 struct rpc_pipe_client
*pipe_cli
,
2265 struct policy_handle
*domain_handle
,
2266 struct samr_DomInfo1
*info1
,
2267 struct samr_DomInfo3
*info3
,
2268 struct samr_DomInfo12
*info12
)
2271 union samr_DomainInfo dom_info
;
2275 ZERO_STRUCT(dom_info
);
2277 dom_info
.info1
= *info1
;
2279 status
= rpccli_samr_SetDomainInfo(pipe_cli
, mem_ctx
,
2283 NT_STATUS_NOT_OK_RETURN(status
);
2288 ZERO_STRUCT(dom_info
);
2290 dom_info
.info3
= *info3
;
2292 status
= rpccli_samr_SetDomainInfo(pipe_cli
, mem_ctx
,
2297 NT_STATUS_NOT_OK_RETURN(status
);
2302 ZERO_STRUCT(dom_info
);
2304 dom_info
.info12
= *info12
;
2306 status
= rpccli_samr_SetDomainInfo(pipe_cli
, mem_ctx
,
2311 NT_STATUS_NOT_OK_RETURN(status
);
2314 return NT_STATUS_OK
;
2317 /****************************************************************
2318 ****************************************************************/
2320 static NTSTATUS
set_USER_MODALS_INFO_0_buffer(TALLOC_CTX
*mem_ctx
,
2321 struct rpc_pipe_client
*pipe_cli
,
2322 struct policy_handle
*domain_handle
,
2323 struct USER_MODALS_INFO_0
*info0
)
2326 struct samr_DomInfo1 dom_info_1
;
2327 struct samr_DomInfo3 dom_info_3
;
2329 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2338 NT_STATUS_NOT_OK_RETURN(status
);
2340 dom_info_1
.min_password_length
=
2341 info0
->usrmod0_min_passwd_len
;
2342 dom_info_1
.password_history_length
=
2343 info0
->usrmod0_password_hist_len
;
2345 unix_to_nt_time_abs((NTTIME
*)&dom_info_1
.max_password_age
,
2346 info0
->usrmod0_max_passwd_age
);
2347 unix_to_nt_time_abs((NTTIME
*)&dom_info_1
.min_password_age
,
2348 info0
->usrmod0_min_passwd_age
);
2350 unix_to_nt_time_abs(&dom_info_3
.force_logoff_time
,
2351 info0
->usrmod0_force_logoff
);
2353 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2361 /****************************************************************
2362 ****************************************************************/
2364 static NTSTATUS
set_USER_MODALS_INFO_3_buffer(TALLOC_CTX
*mem_ctx
,
2365 struct rpc_pipe_client
*pipe_cli
,
2366 struct policy_handle
*domain_handle
,
2367 struct USER_MODALS_INFO_3
*info3
)
2370 struct samr_DomInfo12 dom_info_12
;
2372 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2381 NT_STATUS_NOT_OK_RETURN(status
);
2383 unix_to_nt_time_abs((NTTIME
*)&dom_info_12
.lockout_duration
,
2384 info3
->usrmod3_lockout_duration
);
2385 unix_to_nt_time_abs((NTTIME
*)&dom_info_12
.lockout_window
,
2386 info3
->usrmod3_lockout_observation_window
);
2387 dom_info_12
.lockout_threshold
= info3
->usrmod3_lockout_threshold
;
2389 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2397 /****************************************************************
2398 ****************************************************************/
2400 static NTSTATUS
set_USER_MODALS_INFO_1001_buffer(TALLOC_CTX
*mem_ctx
,
2401 struct rpc_pipe_client
*pipe_cli
,
2402 struct policy_handle
*domain_handle
,
2403 struct USER_MODALS_INFO_1001
*info1001
)
2406 struct samr_DomInfo1 dom_info_1
;
2408 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2417 NT_STATUS_NOT_OK_RETURN(status
);
2419 dom_info_1
.min_password_length
=
2420 info1001
->usrmod1001_min_passwd_len
;
2422 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2430 /****************************************************************
2431 ****************************************************************/
2433 static NTSTATUS
set_USER_MODALS_INFO_1002_buffer(TALLOC_CTX
*mem_ctx
,
2434 struct rpc_pipe_client
*pipe_cli
,
2435 struct policy_handle
*domain_handle
,
2436 struct USER_MODALS_INFO_1002
*info1002
)
2439 struct samr_DomInfo1 dom_info_1
;
2441 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2450 NT_STATUS_NOT_OK_RETURN(status
);
2452 unix_to_nt_time_abs((NTTIME
*)&dom_info_1
.max_password_age
,
2453 info1002
->usrmod1002_max_passwd_age
);
2455 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2463 /****************************************************************
2464 ****************************************************************/
2466 static NTSTATUS
set_USER_MODALS_INFO_1003_buffer(TALLOC_CTX
*mem_ctx
,
2467 struct rpc_pipe_client
*pipe_cli
,
2468 struct policy_handle
*domain_handle
,
2469 struct USER_MODALS_INFO_1003
*info1003
)
2472 struct samr_DomInfo1 dom_info_1
;
2474 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2483 NT_STATUS_NOT_OK_RETURN(status
);
2485 unix_to_nt_time_abs((NTTIME
*)&dom_info_1
.min_password_age
,
2486 info1003
->usrmod1003_min_passwd_age
);
2488 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2496 /****************************************************************
2497 ****************************************************************/
2499 static NTSTATUS
set_USER_MODALS_INFO_1004_buffer(TALLOC_CTX
*mem_ctx
,
2500 struct rpc_pipe_client
*pipe_cli
,
2501 struct policy_handle
*domain_handle
,
2502 struct USER_MODALS_INFO_1004
*info1004
)
2505 struct samr_DomInfo3 dom_info_3
;
2507 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2516 NT_STATUS_NOT_OK_RETURN(status
);
2518 unix_to_nt_time_abs(&dom_info_3
.force_logoff_time
,
2519 info1004
->usrmod1004_force_logoff
);
2521 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2529 /****************************************************************
2530 ****************************************************************/
2532 static NTSTATUS
set_USER_MODALS_INFO_1005_buffer(TALLOC_CTX
*mem_ctx
,
2533 struct rpc_pipe_client
*pipe_cli
,
2534 struct policy_handle
*domain_handle
,
2535 struct USER_MODALS_INFO_1005
*info1005
)
2538 struct samr_DomInfo1 dom_info_1
;
2540 status
= query_USER_MODALS_INFO_rpc(mem_ctx
,
2549 NT_STATUS_NOT_OK_RETURN(status
);
2551 dom_info_1
.password_history_length
=
2552 info1005
->usrmod1005_password_hist_len
;
2554 return set_USER_MODALS_INFO_rpc(mem_ctx
,
2562 /****************************************************************
2563 ****************************************************************/
2565 static NTSTATUS
set_USER_MODALS_INFO_buffer(TALLOC_CTX
*mem_ctx
,
2566 struct rpc_pipe_client
*pipe_cli
,
2568 struct policy_handle
*domain_handle
,
2569 struct dom_sid
*domain_sid
,
2572 struct USER_MODALS_INFO_0
*info0
;
2573 struct USER_MODALS_INFO_3
*info3
;
2574 struct USER_MODALS_INFO_1001
*info1001
;
2575 struct USER_MODALS_INFO_1002
*info1002
;
2576 struct USER_MODALS_INFO_1003
*info1003
;
2577 struct USER_MODALS_INFO_1004
*info1004
;
2578 struct USER_MODALS_INFO_1005
*info1005
;
2581 return ERROR_INSUFFICIENT_BUFFER
;
2586 info0
= (struct USER_MODALS_INFO_0
*)buffer
;
2587 return set_USER_MODALS_INFO_0_buffer(mem_ctx
,
2592 info3
= (struct USER_MODALS_INFO_3
*)buffer
;
2593 return set_USER_MODALS_INFO_3_buffer(mem_ctx
,
2598 info1001
= (struct USER_MODALS_INFO_1001
*)buffer
;
2599 return set_USER_MODALS_INFO_1001_buffer(mem_ctx
,
2604 info1002
= (struct USER_MODALS_INFO_1002
*)buffer
;
2605 return set_USER_MODALS_INFO_1002_buffer(mem_ctx
,
2610 info1003
= (struct USER_MODALS_INFO_1003
*)buffer
;
2611 return set_USER_MODALS_INFO_1003_buffer(mem_ctx
,
2616 info1004
= (struct USER_MODALS_INFO_1004
*)buffer
;
2617 return set_USER_MODALS_INFO_1004_buffer(mem_ctx
,
2622 info1005
= (struct USER_MODALS_INFO_1005
*)buffer
;
2623 return set_USER_MODALS_INFO_1005_buffer(mem_ctx
,
2632 return NT_STATUS_OK
;
2635 /****************************************************************
2636 ****************************************************************/
2638 WERROR
NetUserModalsSet_r(struct libnetapi_ctx
*ctx
,
2639 struct NetUserModalsSet
*r
)
2641 struct rpc_pipe_client
*pipe_cli
= NULL
;
2645 struct policy_handle connect_handle
, domain_handle
;
2646 struct dom_sid2
*domain_sid
= NULL
;
2647 uint32_t access_mask
= SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
;
2649 ZERO_STRUCT(connect_handle
);
2650 ZERO_STRUCT(domain_handle
);
2652 if (!r
->in
.buffer
) {
2653 return WERR_INVALID_PARAM
;
2656 switch (r
->in
.level
) {
2658 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
2659 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
|
2660 SAMR_DOMAIN_ACCESS_SET_INFO_1
|
2661 SAMR_DOMAIN_ACCESS_SET_INFO_2
;
2668 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
2669 SAMR_DOMAIN_ACCESS_SET_INFO_1
;
2672 access_mask
|= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
|
2673 SAMR_DOMAIN_ACCESS_SET_INFO_2
;
2679 werr
= WERR_NOT_SUPPORTED
;
2682 werr
= WERR_UNKNOWN_LEVEL
;
2686 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
2687 &ndr_table_samr
.syntax_id
,
2689 if (!W_ERROR_IS_OK(werr
)) {
2693 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
2694 SAMR_ACCESS_ENUM_DOMAINS
|
2695 SAMR_ACCESS_OPEN_DOMAIN
,
2700 if (!W_ERROR_IS_OK(werr
)) {
2704 status
= set_USER_MODALS_INFO_buffer(ctx
,
2710 if (!NT_STATUS_IS_OK(status
)) {
2711 werr
= ntstatus_to_werror(status
);
2716 if (ctx
->disable_policy_handle_cache
) {
2717 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
2718 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
2724 /****************************************************************
2725 ****************************************************************/
2727 WERROR
NetUserModalsSet_l(struct libnetapi_ctx
*ctx
,
2728 struct NetUserModalsSet
*r
)
2730 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserModalsSet
);
2733 /****************************************************************
2734 ****************************************************************/
2736 NTSTATUS
add_GROUP_USERS_INFO_X_buffer(TALLOC_CTX
*mem_ctx
,
2738 const char *group_name
,
2739 uint32_t attributes
,
2741 uint32_t *num_entries
)
2743 struct GROUP_USERS_INFO_0 u0
;
2744 struct GROUP_USERS_INFO_1 u1
;
2749 u0
.grui0_name
= talloc_strdup(mem_ctx
, group_name
);
2750 NT_STATUS_HAVE_NO_MEMORY(u0
.grui0_name
);
2752 u0
.grui0_name
= NULL
;
2755 ADD_TO_ARRAY(mem_ctx
, struct GROUP_USERS_INFO_0
, u0
,
2756 (struct GROUP_USERS_INFO_0
**)buffer
, num_entries
);
2760 u1
.grui1_name
= talloc_strdup(mem_ctx
, group_name
);
2761 NT_STATUS_HAVE_NO_MEMORY(u1
.grui1_name
);
2763 u1
.grui1_name
= NULL
;
2766 u1
.grui1_attributes
= attributes
;
2768 ADD_TO_ARRAY(mem_ctx
, struct GROUP_USERS_INFO_1
, u1
,
2769 (struct GROUP_USERS_INFO_1
**)buffer
, num_entries
);
2772 return NT_STATUS_INVALID_INFO_CLASS
;
2775 return NT_STATUS_OK
;
2778 /****************************************************************
2779 ****************************************************************/
2781 WERROR
NetUserGetGroups_r(struct libnetapi_ctx
*ctx
,
2782 struct NetUserGetGroups
*r
)
2784 struct rpc_pipe_client
*pipe_cli
= NULL
;
2785 struct policy_handle connect_handle
, domain_handle
, user_handle
;
2786 struct lsa_String lsa_account_name
;
2787 struct dom_sid2
*domain_sid
= NULL
;
2788 struct samr_Ids user_rids
, name_types
;
2789 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
2790 struct lsa_Strings names
;
2791 struct samr_Ids types
;
2792 uint32_t *rids
= NULL
;
2795 uint32_t entries_read
= 0;
2797 NTSTATUS status
= NT_STATUS_OK
;
2800 ZERO_STRUCT(connect_handle
);
2801 ZERO_STRUCT(domain_handle
);
2803 if (!r
->out
.buffer
) {
2804 return WERR_INVALID_PARAM
;
2807 *r
->out
.buffer
= NULL
;
2808 *r
->out
.entries_read
= 0;
2810 switch (r
->in
.level
) {
2815 return WERR_UNKNOWN_LEVEL
;
2818 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
2819 &ndr_table_samr
.syntax_id
,
2821 if (!W_ERROR_IS_OK(werr
)) {
2825 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
2826 SAMR_ACCESS_ENUM_DOMAINS
|
2827 SAMR_ACCESS_OPEN_DOMAIN
,
2828 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
2832 if (!W_ERROR_IS_OK(werr
)) {
2836 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
2838 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
2844 if (!NT_STATUS_IS_OK(status
)) {
2845 werr
= ntstatus_to_werror(status
);
2849 status
= rpccli_samr_OpenUser(pipe_cli
, ctx
,
2851 SAMR_USER_ACCESS_GET_GROUPS
,
2854 if (!NT_STATUS_IS_OK(status
)) {
2855 werr
= ntstatus_to_werror(status
);
2859 status
= rpccli_samr_GetGroupsForUser(pipe_cli
, ctx
,
2862 if (!NT_STATUS_IS_OK(status
)) {
2863 werr
= ntstatus_to_werror(status
);
2867 rids
= talloc_array(ctx
, uint32_t, rid_array
->count
);
2873 for (i
=0; i
< rid_array
->count
; i
++) {
2874 rids
[i
] = rid_array
->rids
[i
].rid
;
2877 status
= rpccli_samr_LookupRids(pipe_cli
, ctx
,
2883 if (!NT_STATUS_IS_OK(status
) &&
2884 !NT_STATUS_EQUAL(status
, STATUS_SOME_UNMAPPED
)) {
2885 werr
= ntstatus_to_werror(status
);
2889 for (i
=0; i
< names
.count
; i
++) {
2890 status
= add_GROUP_USERS_INFO_X_buffer(ctx
,
2892 names
.names
[i
].string
,
2893 rid_array
->rids
[i
].attributes
,
2896 if (!NT_STATUS_IS_OK(status
)) {
2897 werr
= ntstatus_to_werror(status
);
2902 if (r
->out
.entries_read
) {
2903 *r
->out
.entries_read
= entries_read
;
2905 if (r
->out
.total_entries
) {
2906 *r
->out
.total_entries
= entries_read
;
2910 if (ctx
->disable_policy_handle_cache
) {
2911 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
2912 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
2918 /****************************************************************
2919 ****************************************************************/
2921 WERROR
NetUserGetGroups_l(struct libnetapi_ctx
*ctx
,
2922 struct NetUserGetGroups
*r
)
2924 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserGetGroups
);
2927 /****************************************************************
2928 ****************************************************************/
2930 WERROR
NetUserSetGroups_r(struct libnetapi_ctx
*ctx
,
2931 struct NetUserSetGroups
*r
)
2933 struct rpc_pipe_client
*pipe_cli
= NULL
;
2934 struct policy_handle connect_handle
, domain_handle
, user_handle
, group_handle
;
2935 struct lsa_String lsa_account_name
;
2936 struct dom_sid2
*domain_sid
= NULL
;
2937 struct samr_Ids user_rids
, name_types
;
2938 struct samr_Ids group_rids
;
2939 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
2940 struct lsa_String
*lsa_names
= NULL
;
2942 uint32_t *add_rids
= NULL
;
2943 uint32_t *del_rids
= NULL
;
2944 size_t num_add_rids
= 0;
2945 size_t num_del_rids
= 0;
2947 uint32_t *member_rids
= NULL
;
2948 size_t num_member_rids
= 0;
2950 struct GROUP_USERS_INFO_0
*i0
= NULL
;
2951 struct GROUP_USERS_INFO_1
*i1
= NULL
;
2955 NTSTATUS status
= NT_STATUS_OK
;
2958 ZERO_STRUCT(connect_handle
);
2959 ZERO_STRUCT(domain_handle
);
2961 if (!r
->in
.buffer
) {
2962 return WERR_INVALID_PARAM
;
2965 switch (r
->in
.level
) {
2970 return WERR_UNKNOWN_LEVEL
;
2973 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
2974 &ndr_table_samr
.syntax_id
,
2976 if (!W_ERROR_IS_OK(werr
)) {
2980 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
2981 SAMR_ACCESS_ENUM_DOMAINS
|
2982 SAMR_ACCESS_OPEN_DOMAIN
,
2983 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
2987 if (!W_ERROR_IS_OK(werr
)) {
2991 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
2993 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
2999 if (!NT_STATUS_IS_OK(status
)) {
3000 werr
= ntstatus_to_werror(status
);
3004 status
= rpccli_samr_OpenUser(pipe_cli
, ctx
,
3006 SAMR_USER_ACCESS_GET_GROUPS
,
3009 if (!NT_STATUS_IS_OK(status
)) {
3010 werr
= ntstatus_to_werror(status
);
3014 switch (r
->in
.level
) {
3016 i0
= (struct GROUP_USERS_INFO_0
*)r
->in
.buffer
;
3019 i1
= (struct GROUP_USERS_INFO_1
*)r
->in
.buffer
;
3023 lsa_names
= talloc_array(ctx
, struct lsa_String
, r
->in
.num_entries
);
3029 for (i
=0; i
< r
->in
.num_entries
; i
++) {
3031 switch (r
->in
.level
) {
3033 init_lsa_String(&lsa_names
[i
], i0
->grui0_name
);
3037 init_lsa_String(&lsa_names
[i
], i1
->grui1_name
);
3043 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
3049 if (!NT_STATUS_IS_OK(status
)) {
3050 werr
= ntstatus_to_werror(status
);
3054 member_rids
= group_rids
.ids
;
3055 num_member_rids
= group_rids
.count
;
3057 status
= rpccli_samr_GetGroupsForUser(pipe_cli
, ctx
,
3060 if (!NT_STATUS_IS_OK(status
)) {
3061 werr
= ntstatus_to_werror(status
);
3067 for (i
=0; i
< r
->in
.num_entries
; i
++) {
3068 bool already_member
= false;
3069 for (k
=0; k
< rid_array
->count
; k
++) {
3070 if (member_rids
[i
] == rid_array
->rids
[k
].rid
) {
3071 already_member
= true;
3075 if (!already_member
) {
3076 if (!add_rid_to_array_unique(ctx
,
3078 &add_rids
, &num_add_rids
)) {
3079 werr
= WERR_GENERAL_FAILURE
;
3087 for (k
=0; k
< rid_array
->count
; k
++) {
3088 bool keep_member
= false;
3089 for (i
=0; i
< r
->in
.num_entries
; i
++) {
3090 if (member_rids
[i
] == rid_array
->rids
[k
].rid
) {
3096 if (!add_rid_to_array_unique(ctx
,
3097 rid_array
->rids
[k
].rid
,
3098 &del_rids
, &num_del_rids
)) {
3099 werr
= WERR_GENERAL_FAILURE
;
3107 for (i
=0; i
< num_add_rids
; i
++) {
3108 status
= rpccli_samr_OpenGroup(pipe_cli
, ctx
,
3110 SAMR_GROUP_ACCESS_ADD_MEMBER
,
3113 if (!NT_STATUS_IS_OK(status
)) {
3114 werr
= ntstatus_to_werror(status
);
3118 status
= rpccli_samr_AddGroupMember(pipe_cli
, ctx
,
3122 if (!NT_STATUS_IS_OK(status
)) {
3123 werr
= ntstatus_to_werror(status
);
3127 if (is_valid_policy_hnd(&group_handle
)) {
3128 rpccli_samr_Close(pipe_cli
, ctx
, &group_handle
);
3134 for (i
=0; i
< num_del_rids
; i
++) {
3135 status
= rpccli_samr_OpenGroup(pipe_cli
, ctx
,
3137 SAMR_GROUP_ACCESS_REMOVE_MEMBER
,
3140 if (!NT_STATUS_IS_OK(status
)) {
3141 werr
= ntstatus_to_werror(status
);
3145 status
= rpccli_samr_DeleteGroupMember(pipe_cli
, ctx
,
3148 if (!NT_STATUS_IS_OK(status
)) {
3149 werr
= ntstatus_to_werror(status
);
3153 if (is_valid_policy_hnd(&group_handle
)) {
3154 rpccli_samr_Close(pipe_cli
, ctx
, &group_handle
);
3161 if (is_valid_policy_hnd(&group_handle
)) {
3162 rpccli_samr_Close(pipe_cli
, ctx
, &group_handle
);
3165 if (ctx
->disable_policy_handle_cache
) {
3166 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
3167 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
3173 /****************************************************************
3174 ****************************************************************/
3176 WERROR
NetUserSetGroups_l(struct libnetapi_ctx
*ctx
,
3177 struct NetUserSetGroups
*r
)
3179 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserSetGroups
);
3182 /****************************************************************
3183 ****************************************************************/
3185 static NTSTATUS
add_LOCALGROUP_USERS_INFO_X_buffer(TALLOC_CTX
*mem_ctx
,
3187 const char *group_name
,
3189 uint32_t *num_entries
)
3191 struct LOCALGROUP_USERS_INFO_0 u0
;
3195 u0
.lgrui0_name
= talloc_strdup(mem_ctx
, group_name
);
3196 NT_STATUS_HAVE_NO_MEMORY(u0
.lgrui0_name
);
3198 ADD_TO_ARRAY(mem_ctx
, struct LOCALGROUP_USERS_INFO_0
, u0
,
3199 (struct LOCALGROUP_USERS_INFO_0
**)buffer
, num_entries
);
3202 return NT_STATUS_INVALID_INFO_CLASS
;
3205 return NT_STATUS_OK
;
3208 /****************************************************************
3209 ****************************************************************/
3211 WERROR
NetUserGetLocalGroups_r(struct libnetapi_ctx
*ctx
,
3212 struct NetUserGetLocalGroups
*r
)
3214 struct rpc_pipe_client
*pipe_cli
= NULL
;
3215 struct policy_handle connect_handle
, domain_handle
, user_handle
,
3217 struct lsa_String lsa_account_name
;
3218 struct dom_sid2
*domain_sid
= NULL
;
3219 struct samr_Ids user_rids
, name_types
;
3220 struct samr_RidWithAttributeArray
*rid_array
= NULL
;
3221 struct lsa_Strings names
;
3222 struct samr_Ids types
;
3223 uint32_t *rids
= NULL
;
3224 size_t num_rids
= 0;
3225 struct dom_sid user_sid
;
3226 struct lsa_SidArray sid_array
;
3227 struct samr_Ids domain_rids
;
3228 struct samr_Ids builtin_rids
;
3231 uint32_t entries_read
= 0;
3233 NTSTATUS status
= NT_STATUS_OK
;
3236 ZERO_STRUCT(connect_handle
);
3237 ZERO_STRUCT(domain_handle
);
3239 if (!r
->out
.buffer
) {
3240 return WERR_INVALID_PARAM
;
3243 *r
->out
.buffer
= NULL
;
3244 *r
->out
.entries_read
= 0;
3246 switch (r
->in
.level
) {
3251 return WERR_UNKNOWN_LEVEL
;
3254 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
3255 &ndr_table_samr
.syntax_id
,
3257 if (!W_ERROR_IS_OK(werr
)) {
3261 werr
= libnetapi_samr_open_domain(ctx
, pipe_cli
,
3262 SAMR_ACCESS_ENUM_DOMAINS
|
3263 SAMR_ACCESS_OPEN_DOMAIN
,
3264 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
3265 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
,
3269 if (!W_ERROR_IS_OK(werr
)) {
3273 werr
= libnetapi_samr_open_builtin_domain(ctx
, pipe_cli
,
3274 SAMR_ACCESS_ENUM_DOMAINS
|
3275 SAMR_ACCESS_OPEN_DOMAIN
,
3276 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
3277 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
,
3280 if (!W_ERROR_IS_OK(werr
)) {
3284 init_lsa_String(&lsa_account_name
, r
->in
.user_name
);
3286 status
= rpccli_samr_LookupNames(pipe_cli
, ctx
,
3292 if (!NT_STATUS_IS_OK(status
)) {
3293 werr
= ntstatus_to_werror(status
);
3297 status
= rpccli_samr_OpenUser(pipe_cli
, ctx
,
3299 SAMR_USER_ACCESS_GET_GROUPS
,
3302 if (!NT_STATUS_IS_OK(status
)) {
3303 werr
= ntstatus_to_werror(status
);
3307 status
= rpccli_samr_GetGroupsForUser(pipe_cli
, ctx
,
3310 if (!NT_STATUS_IS_OK(status
)) {
3311 werr
= ntstatus_to_werror(status
);
3315 if (!sid_compose(&user_sid
, domain_sid
, user_rids
.ids
[0])) {
3320 sid_array
.num_sids
= rid_array
->count
+ 1;
3321 sid_array
.sids
= TALLOC_ARRAY(ctx
, struct lsa_SidPtr
, sid_array
.num_sids
);
3322 if (!sid_array
.sids
) {
3327 sid_array
.sids
[0].sid
= sid_dup_talloc(ctx
, &user_sid
);
3328 if (!sid_array
.sids
[0].sid
) {
3333 for (i
=0; i
< rid_array
->count
; i
++) {
3336 if (!sid_compose(&sid
, domain_sid
, rid_array
->rids
[i
].rid
)) {
3341 sid_array
.sids
[i
+1].sid
= sid_dup_talloc(ctx
, &sid
);
3342 if (!sid_array
.sids
[i
+1].sid
) {
3348 status
= rpccli_samr_GetAliasMembership(pipe_cli
, ctx
,
3352 if (!NT_STATUS_IS_OK(status
)) {
3353 werr
= ntstatus_to_werror(status
);
3357 for (i
=0; i
< domain_rids
.count
; i
++) {
3358 if (!add_rid_to_array_unique(ctx
, domain_rids
.ids
[i
],
3359 &rids
, &num_rids
)) {
3365 status
= rpccli_samr_GetAliasMembership(pipe_cli
, ctx
,
3369 if (!NT_STATUS_IS_OK(status
)) {
3370 werr
= ntstatus_to_werror(status
);
3374 for (i
=0; i
< builtin_rids
.count
; i
++) {
3375 if (!add_rid_to_array_unique(ctx
, builtin_rids
.ids
[i
],
3376 &rids
, &num_rids
)) {
3382 status
= rpccli_samr_LookupRids(pipe_cli
, ctx
,
3388 if (!NT_STATUS_IS_OK(status
)) {
3389 werr
= ntstatus_to_werror(status
);
3393 for (i
=0; i
< names
.count
; i
++) {
3394 status
= add_LOCALGROUP_USERS_INFO_X_buffer(ctx
,
3396 names
.names
[i
].string
,
3399 if (!NT_STATUS_IS_OK(status
)) {
3400 werr
= ntstatus_to_werror(status
);
3405 if (r
->out
.entries_read
) {
3406 *r
->out
.entries_read
= entries_read
;
3408 if (r
->out
.total_entries
) {
3409 *r
->out
.total_entries
= entries_read
;
3413 if (ctx
->disable_policy_handle_cache
) {
3414 libnetapi_samr_close_domain_handle(ctx
, &domain_handle
);
3415 libnetapi_samr_close_connect_handle(ctx
, &connect_handle
);
3421 /****************************************************************
3422 ****************************************************************/
3424 WERROR
NetUserGetLocalGroups_l(struct libnetapi_ctx
*ctx
,
3425 struct NetUserGetLocalGroups
*r
)
3427 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetUserGetLocalGroups
);