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 = SAMR_FIELD_ACCT_FLAGS;
34 struct samr_LogonHours zero_logon_hours;
35 struct lsa_BinaryString zero_parameters;
36 uint32_t acct_flags = 0;
40 ZERO_STRUCT(zero_logon_hours);
41 ZERO_STRUCT(zero_parameters);
43 if (infoX->usriX_name) {
44 fields_present |= SAMR_FIELD_FULL_NAME;
46 if (infoX->usriX_password) {
47 fields_present |= SAMR_FIELD_PASSWORD;
49 if (infoX->usriX_flags) {
50 fields_present |= SAMR_FIELD_ACCT_FLAGS;
52 if (infoX->usriX_name) {
53 fields_present |= SAMR_FIELD_FULL_NAME;
55 if (infoX->usriX_home_dir) {
56 fields_present |= SAMR_FIELD_HOME_DIRECTORY;
58 if (infoX->usriX_script_path) {
59 fields_present |= SAMR_FIELD_LOGON_SCRIPT;
61 if (infoX->usriX_comment) {
62 fields_present |= SAMR_FIELD_DESCRIPTION;
64 if (infoX->usriX_password_age) {
65 fields_present |= SAMR_FIELD_FORCE_PWD_CHANGE;
68 acct_flags |= infoX->usriX_flags | ACB_NORMAL;
70 unix_to_nt_time_abs(&password_age, infoX->usriX_password_age);
72 /* TODO: infoX->usriX_priv */
73 init_samr_user_info21(info21,
82 infoX->usriX_home_dir,
84 infoX->usriX_script_path,
104 /****************************************************************
105 ****************************************************************/
107 static NTSTATUS construct_USER_INFO_X(uint32_t level,
109 struct USER_INFO_X *uX)
111 struct USER_INFO_0 *u0 = NULL;
112 struct USER_INFO_1 *u1 = NULL;
113 struct USER_INFO_2 *u2 = NULL;
114 struct USER_INFO_1007 *u1007 = NULL;
116 if (!buffer || !uX) {
117 return NT_STATUS_INVALID_PARAMETER;
124 u0 = (struct USER_INFO_0 *)buffer;
125 uX->usriX_name = u0->usri0_name;
128 u1 = (struct USER_INFO_1 *)buffer;
129 uX->usriX_name = u1->usri1_name;
130 uX->usriX_password = u1->usri1_password;
131 uX->usriX_password_age = u1->usri1_password_age;
132 uX->usriX_priv = u1->usri1_priv;
133 uX->usriX_home_dir = u1->usri1_home_dir;
134 uX->usriX_comment = u1->usri1_comment;
135 uX->usriX_flags = u1->usri1_flags;
136 uX->usriX_script_path = u1->usri1_script_path;
139 u2 = (struct USER_INFO_2 *)buffer;
140 uX->usriX_name = u2->usri2_name;
141 uX->usriX_password = u2->usri2_password;
142 uX->usriX_password_age = u2->usri2_password_age;
143 uX->usriX_priv = u2->usri2_priv;
144 uX->usriX_home_dir = u2->usri2_home_dir;
145 uX->usriX_comment = u2->usri2_comment;
146 uX->usriX_flags = u2->usri2_flags;
147 uX->usriX_script_path = u2->usri2_script_path;
148 uX->usriX_auth_flags = u2->usri2_auth_flags;
149 uX->usriX_full_name = u2->usri2_full_name;
150 uX->usriX_usr_comment = u2->usri2_usr_comment;
151 uX->usriX_parms = u2->usri2_parms;
152 uX->usriX_workstations = u2->usri2_workstations;
153 uX->usriX_last_logon = u2->usri2_last_logon;
154 uX->usriX_last_logoff = u2->usri2_last_logoff;
155 uX->usriX_acct_expires = u2->usri2_acct_expires;
156 uX->usriX_max_storage = u2->usri2_max_storage;
157 uX->usriX_units_per_week= u2->usri2_units_per_week;
158 uX->usriX_logon_hours = u2->usri2_logon_hours;
159 uX->usriX_bad_pw_count = u2->usri2_bad_pw_count;
160 uX->usriX_num_logons = u2->usri2_num_logons;
161 uX->usriX_logon_server = u2->usri2_logon_server;
162 uX->usriX_country_code = u2->usri2_country_code;
163 uX->usriX_code_page = u2->usri2_code_page;
166 u1007 = (struct USER_INFO_1007 *)buffer;
167 uX->usriX_comment = u1007->usri1007_comment;
172 return NT_STATUS_INVALID_INFO_CLASS;
178 /****************************************************************
179 ****************************************************************/
181 static NTSTATUS set_user_info_USER_INFO_X(TALLOC_CTX *ctx,
182 struct rpc_pipe_client *pipe_cli,
183 DATA_BLOB *session_key,
184 struct policy_handle *user_handle,
185 struct USER_INFO_X *uX)
187 union samr_UserInfo user_info;
188 struct samr_UserInfo21 info21;
192 return NT_STATUS_INVALID_PARAMETER;
195 convert_USER_INFO_X_to_samr_user_info21(uX, &info21);
197 ZERO_STRUCT(user_info);
199 if (uX->usriX_password) {
201 user_info.info25.info = info21;
203 init_samr_CryptPasswordEx(uX->usriX_password,
205 &user_info.info25.password);
207 status = rpccli_samr_SetUserInfo2(pipe_cli, ctx,
212 if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) {
214 user_info.info23.info = info21;
216 init_samr_CryptPassword(uX->usriX_password,
218 &user_info.info23.password);
220 status = rpccli_samr_SetUserInfo2(pipe_cli, ctx,
227 user_info.info21 = info21;
229 status = rpccli_samr_SetUserInfo(pipe_cli, ctx,
238 /****************************************************************
239 ****************************************************************/
241 WERROR NetUserAdd_r(struct libnetapi_ctx *ctx,
242 struct NetUserAdd *r)
244 struct cli_state *cli = NULL;
245 struct rpc_pipe_client *pipe_cli = NULL;
248 POLICY_HND connect_handle, domain_handle, user_handle;
249 struct lsa_String lsa_account_name;
250 struct dom_sid2 *domain_sid = NULL;
251 union samr_UserInfo *user_info = NULL;
252 struct samr_PwInfo pw_info;
253 uint32_t access_granted = 0;
255 struct USER_INFO_X uX;
257 ZERO_STRUCT(connect_handle);
258 ZERO_STRUCT(domain_handle);
259 ZERO_STRUCT(user_handle);
262 return WERR_INVALID_PARAM;
265 switch (r->in.level) {
272 werr = WERR_NOT_SUPPORTED;
276 werr = libnetapi_open_pipe(ctx, r->in.server_name,
277 &ndr_table_samr.syntax_id,
280 if (!W_ERROR_IS_OK(werr)) {
284 status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX);
285 if (!NT_STATUS_IS_OK(status)) {
286 werr = ntstatus_to_werror(status);
290 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
291 SAMR_ACCESS_ENUM_DOMAINS |
292 SAMR_ACCESS_OPEN_DOMAIN,
293 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
294 SAMR_DOMAIN_ACCESS_CREATE_USER |
295 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
299 if (!W_ERROR_IS_OK(werr)) {
303 init_lsa_String(&lsa_account_name, uX.usriX_name);
305 status = rpccli_samr_CreateUser2(pipe_cli, ctx,
311 SAMR_USER_ACCESS_SET_PASSWORD |
312 SAMR_USER_ACCESS_SET_ATTRIBUTES |
313 SAMR_USER_ACCESS_GET_ATTRIBUTES,
317 if (!NT_STATUS_IS_OK(status)) {
318 werr = ntstatus_to_werror(status);
322 status = rpccli_samr_QueryUserInfo(pipe_cli, ctx,
326 if (!NT_STATUS_IS_OK(status)) {
327 werr = ntstatus_to_werror(status);
331 if (!(user_info->info16.acct_flags & ACB_NORMAL)) {
332 werr = WERR_INVALID_PARAM;
336 status = rpccli_samr_GetUserPwInfo(pipe_cli, ctx,
339 if (!NT_STATUS_IS_OK(status)) {
340 werr = ntstatus_to_werror(status);
344 status = set_user_info_USER_INFO_X(ctx, pipe_cli,
345 &cli->user_session_key,
348 if (!NT_STATUS_IS_OK(status)) {
349 werr = ntstatus_to_werror(status);
357 rpccli_samr_DeleteUser(pipe_cli, ctx,
365 if (is_valid_policy_hnd(&user_handle)) {
366 rpccli_samr_Close(pipe_cli, ctx, &user_handle);
369 if (ctx->disable_policy_handle_cache) {
370 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
371 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
377 /****************************************************************
378 ****************************************************************/
380 WERROR NetUserAdd_l(struct libnetapi_ctx *ctx,
381 struct NetUserAdd *r)
383 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserAdd);
386 /****************************************************************
387 ****************************************************************/
389 WERROR NetUserDel_r(struct libnetapi_ctx *ctx,
390 struct NetUserDel *r)
392 struct cli_state *cli = NULL;
393 struct rpc_pipe_client *pipe_cli = NULL;
396 POLICY_HND connect_handle, builtin_handle, domain_handle, user_handle;
397 struct lsa_String lsa_account_name;
398 struct samr_Ids user_rids, name_types;
399 struct dom_sid2 *domain_sid = NULL;
400 struct dom_sid2 user_sid;
402 ZERO_STRUCT(connect_handle);
403 ZERO_STRUCT(builtin_handle);
404 ZERO_STRUCT(domain_handle);
405 ZERO_STRUCT(user_handle);
407 werr = libnetapi_open_pipe(ctx, r->in.server_name,
408 &ndr_table_samr.syntax_id,
412 if (!W_ERROR_IS_OK(werr)) {
416 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
417 SAMR_ACCESS_ENUM_DOMAINS |
418 SAMR_ACCESS_OPEN_DOMAIN,
419 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
423 if (!W_ERROR_IS_OK(werr)) {
427 status = rpccli_samr_OpenDomain(pipe_cli, ctx,
429 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
430 CONST_DISCARD(DOM_SID *, &global_sid_Builtin),
432 if (!NT_STATUS_IS_OK(status)) {
433 werr = ntstatus_to_werror(status);
437 init_lsa_String(&lsa_account_name, r->in.user_name);
439 status = rpccli_samr_LookupNames(pipe_cli, ctx,
445 if (!NT_STATUS_IS_OK(status)) {
446 werr = ntstatus_to_werror(status);
450 status = rpccli_samr_OpenUser(pipe_cli, ctx,
452 STD_RIGHT_DELETE_ACCESS,
455 if (!NT_STATUS_IS_OK(status)) {
456 werr = ntstatus_to_werror(status);
460 sid_compose(&user_sid, domain_sid, user_rids.ids[0]);
462 status = rpccli_samr_RemoveMemberFromForeignDomain(pipe_cli, ctx,
465 if (!NT_STATUS_IS_OK(status)) {
466 werr = ntstatus_to_werror(status);
470 status = rpccli_samr_DeleteUser(pipe_cli, ctx,
472 if (!NT_STATUS_IS_OK(status)) {
473 werr = ntstatus_to_werror(status);
484 if (is_valid_policy_hnd(&user_handle)) {
485 rpccli_samr_Close(pipe_cli, ctx, &user_handle);
488 if (ctx->disable_policy_handle_cache) {
489 libnetapi_samr_close_builtin_handle(ctx, &builtin_handle);
490 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
491 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
497 /****************************************************************
498 ****************************************************************/
500 WERROR NetUserDel_l(struct libnetapi_ctx *ctx,
501 struct NetUserDel *r)
503 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserDel);
506 /****************************************************************
507 ****************************************************************/
509 static NTSTATUS libnetapi_samr_lookup_user(TALLOC_CTX *mem_ctx,
510 struct rpc_pipe_client *pipe_cli,
511 struct policy_handle *domain_handle,
512 struct policy_handle *builtin_handle,
513 const char *user_name,
516 struct samr_UserInfo21 **info21,
517 struct sec_desc_buf **sec_desc)
521 struct policy_handle user_handle;
522 union samr_UserInfo *user_info = NULL;
523 struct samr_RidWithAttributeArray *rid_array = NULL;
524 uint32_t access_mask = SEC_STD_READ_CONTROL |
525 SAMR_USER_ACCESS_GET_ATTRIBUTES |
526 SAMR_USER_ACCESS_GET_NAME_ETC;
528 ZERO_STRUCT(user_handle);
541 return NT_STATUS_INVALID_LEVEL;
548 status = rpccli_samr_OpenUser(pipe_cli, mem_ctx,
553 if (!NT_STATUS_IS_OK(status)) {
557 status = rpccli_samr_QueryUserInfo(pipe_cli, mem_ctx,
561 if (!NT_STATUS_IS_OK(status)) {
565 status = rpccli_samr_QuerySecurity(pipe_cli, mem_ctx,
569 if (!NT_STATUS_IS_OK(status)) {
574 status = rpccli_samr_GetGroupsForUser(pipe_cli, mem_ctx,
577 if (!NT_STATUS_IS_OK(status)) {
582 status = rpccli_samr_GetAliasMembership(pipe_cli, ctx,
586 if (!NT_STATUS_IS_OK(status)) {
592 *info21 = &user_info->info21;
595 if (is_valid_policy_hnd(&user_handle)) {
596 rpccli_samr_Close(pipe_cli, mem_ctx, &user_handle);
602 /****************************************************************
603 ****************************************************************/
605 static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO(TALLOC_CTX *mem_ctx,
606 struct rpc_pipe_client *pipe_cli,
607 struct dom_sid *domain_sid,
608 struct policy_handle *domain_handle,
609 struct policy_handle *builtin_handle,
610 const char *user_name,
614 uint32_t *num_entries)
618 struct samr_UserInfo21 *info21 = NULL;
619 struct sec_desc_buf *sec_desc = NULL;
622 struct USER_INFO_0 info0;
623 struct USER_INFO_10 info10;
624 struct USER_INFO_20 info20;
625 struct USER_INFO_23 info23;
638 return NT_STATUS_INVALID_LEVEL;
642 info0.usri0_name = talloc_strdup(mem_ctx, user_name);
643 NT_STATUS_HAVE_NO_MEMORY(info0.usri0_name);
645 ADD_TO_ARRAY(mem_ctx, struct USER_INFO_0, info0,
646 (struct USER_INFO_0 **)buffer, num_entries);
651 status = libnetapi_samr_lookup_user(mem_ctx, pipe_cli,
660 if (!NT_STATUS_IS_OK(status)) {
666 info10.usri10_name = talloc_strdup(mem_ctx, user_name);
667 NT_STATUS_HAVE_NO_MEMORY(info10.usri10_name);
669 info10.usri10_comment = talloc_strdup(mem_ctx,
670 info21->description.string);
672 info10.usri10_full_name = talloc_strdup(mem_ctx,
673 info21->full_name.string);
675 info10.usri10_usr_comment = talloc_strdup(mem_ctx,
676 info21->comment.string);
678 ADD_TO_ARRAY(mem_ctx, struct USER_INFO_10, info10,
679 (struct USER_INFO_10 **)buffer, num_entries);
684 info20.usri20_name = talloc_strdup(mem_ctx, user_name);
685 NT_STATUS_HAVE_NO_MEMORY(info20.usri20_name);
687 info20.usri20_comment = talloc_strdup(mem_ctx,
688 info21->description.string);
690 info20.usri20_full_name = talloc_strdup(mem_ctx,
691 info21->full_name.string);
693 info20.usri20_flags = info21->acct_flags;
694 info20.usri20_user_id = rid;
696 ADD_TO_ARRAY(mem_ctx, struct USER_INFO_20, info20,
697 (struct USER_INFO_20 **)buffer, num_entries);
701 info23.usri23_name = talloc_strdup(mem_ctx, user_name);
702 NT_STATUS_HAVE_NO_MEMORY(info23.usri23_name);
704 info23.usri23_comment = talloc_strdup(mem_ctx,
705 info21->description.string);
707 info23.usri23_full_name = talloc_strdup(mem_ctx,
708 info21->full_name.string);
710 info23.usri23_flags = info21->acct_flags;
712 if (!sid_compose(&sid, domain_sid, rid)) {
713 return NT_STATUS_NO_MEMORY;
716 info23.usri23_user_sid =
717 (struct domsid *)sid_dup_talloc(mem_ctx, &sid);
719 ADD_TO_ARRAY(mem_ctx, struct USER_INFO_23, info23,
720 (struct USER_INFO_23 **)buffer, num_entries);
728 /****************************************************************
729 ****************************************************************/
731 WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
732 struct NetUserEnum *r)
734 struct cli_state *cli = NULL;
735 struct rpc_pipe_client *pipe_cli = NULL;
736 struct policy_handle connect_handle;
737 struct dom_sid2 *domain_sid = NULL;
738 struct policy_handle domain_handle;
739 struct samr_SamArray *sam = NULL;
740 uint32_t filter = ACB_NORMAL;
742 uint32_t entries_read = 0;
744 NTSTATUS status = NT_STATUS_OK;
747 ZERO_STRUCT(connect_handle);
748 ZERO_STRUCT(domain_handle);
750 if (!r->out.buffer) {
751 return WERR_INVALID_PARAM;
754 *r->out.buffer = NULL;
755 *r->out.entries_read = 0;
757 switch (r->in.level) {
768 return WERR_NOT_SUPPORTED;
771 werr = libnetapi_open_pipe(ctx, r->in.server_name,
772 &ndr_table_samr.syntax_id,
775 if (!W_ERROR_IS_OK(werr)) {
779 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
780 SAMR_ACCESS_ENUM_DOMAINS |
781 SAMR_ACCESS_OPEN_DOMAIN,
782 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
783 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
784 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
788 if (!W_ERROR_IS_OK(werr)) {
792 switch (r->in.filter) {
793 case FILTER_NORMAL_ACCOUNT:
796 case FILTER_TEMP_DUPLICATE_ACCOUNT:
797 filter = ACB_TEMPDUP;
799 case FILTER_INTERDOMAIN_TRUST_ACCOUNT:
800 filter = ACB_DOMTRUST;
802 case FILTER_WORKSTATION_TRUST_ACCOUNT:
803 filter = ACB_WSTRUST;
805 case FILTER_SERVER_TRUST_ACCOUNT:
806 filter = ACB_SVRTRUST;
812 status = rpccli_samr_EnumDomainUsers(pipe_cli,
820 werr = ntstatus_to_werror(status);
821 if (NT_STATUS_IS_ERR(status)) {
825 for (i=0; i < sam->count; i++) {
827 status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli,
830 NULL, /*&builtin_handle, */
831 sam->entries[i].name.string,
835 r->out.entries_read);
836 if (!NT_STATUS_IS_OK(status)) {
837 werr = ntstatus_to_werror(status);
848 if (NT_STATUS_IS_OK(status) ||
849 NT_STATUS_IS_ERR(status)) {
851 if (ctx->disable_policy_handle_cache) {
852 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
853 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
860 /****************************************************************
861 ****************************************************************/
863 WERROR NetUserEnum_l(struct libnetapi_ctx *ctx,
864 struct NetUserEnum *r)
866 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserEnum);
869 /****************************************************************
870 ****************************************************************/
872 static WERROR convert_samr_dispinfo_to_NET_DISPLAY_USER(TALLOC_CTX *mem_ctx,
873 struct samr_DispInfoGeneral *info,
874 uint32_t *entries_read,
877 struct NET_DISPLAY_USER *user = NULL;
880 user = TALLOC_ZERO_ARRAY(mem_ctx,
881 struct NET_DISPLAY_USER,
883 W_ERROR_HAVE_NO_MEMORY(user);
885 for (i = 0; i < info->count; i++) {
886 user[i].usri1_name = talloc_strdup(mem_ctx,
887 info->entries[i].account_name.string);
888 user[i].usri1_comment = talloc_strdup(mem_ctx,
889 info->entries[i].description.string);
890 user[i].usri1_flags =
891 info->entries[i].acct_flags;
892 user[i].usri1_full_name = talloc_strdup(mem_ctx,
893 info->entries[i].full_name.string);
894 user[i].usri1_user_id =
895 info->entries[i].rid;
896 user[i].usri1_next_index =
897 info->entries[i].idx;
899 if (!user[i].usri1_name) {
904 *buffer = talloc_memdup(mem_ctx, user,
905 sizeof(struct NET_DISPLAY_USER) * info->count);
906 W_ERROR_HAVE_NO_MEMORY(*buffer);
908 *entries_read = info->count;
913 /****************************************************************
914 ****************************************************************/
916 static WERROR convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(TALLOC_CTX *mem_ctx,
917 struct samr_DispInfoFull *info,
918 uint32_t *entries_read,
921 struct NET_DISPLAY_MACHINE *machine = NULL;
924 machine = TALLOC_ZERO_ARRAY(mem_ctx,
925 struct NET_DISPLAY_MACHINE,
927 W_ERROR_HAVE_NO_MEMORY(machine);
929 for (i = 0; i < info->count; i++) {
930 machine[i].usri2_name = talloc_strdup(mem_ctx,
931 info->entries[i].account_name.string);
932 machine[i].usri2_comment = talloc_strdup(mem_ctx,
933 info->entries[i].description.string);
934 machine[i].usri2_flags =
935 info->entries[i].acct_flags;
936 machine[i].usri2_user_id =
937 info->entries[i].rid;
938 machine[i].usri2_next_index =
939 info->entries[i].idx;
941 if (!machine[i].usri2_name) {
946 *buffer = talloc_memdup(mem_ctx, machine,
947 sizeof(struct NET_DISPLAY_MACHINE) * info->count);
948 W_ERROR_HAVE_NO_MEMORY(*buffer);
950 *entries_read = info->count;
955 /****************************************************************
956 ****************************************************************/
958 static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX *mem_ctx,
959 struct samr_DispInfoFullGroups *info,
960 uint32_t *entries_read,
963 struct NET_DISPLAY_GROUP *group = NULL;
966 group = TALLOC_ZERO_ARRAY(mem_ctx,
967 struct NET_DISPLAY_GROUP,
969 W_ERROR_HAVE_NO_MEMORY(group);
971 for (i = 0; i < info->count; i++) {
972 group[i].grpi3_name = talloc_strdup(mem_ctx,
973 info->entries[i].account_name.string);
974 group[i].grpi3_comment = talloc_strdup(mem_ctx,
975 info->entries[i].description.string);
976 group[i].grpi3_group_id =
977 info->entries[i].rid;
978 group[i].grpi3_attributes =
979 info->entries[i].acct_flags;
980 group[i].grpi3_next_index =
981 info->entries[i].idx;
983 if (!group[i].grpi3_name) {
988 *buffer = talloc_memdup(mem_ctx, group,
989 sizeof(struct NET_DISPLAY_GROUP) * info->count);
990 W_ERROR_HAVE_NO_MEMORY(*buffer);
992 *entries_read = info->count;
998 /****************************************************************
999 ****************************************************************/
1001 static WERROR convert_samr_dispinfo_to_NET_DISPLAY(TALLOC_CTX *mem_ctx,
1002 union samr_DispInfo *info,
1004 uint32_t *entries_read,
1009 return convert_samr_dispinfo_to_NET_DISPLAY_USER(mem_ctx,
1014 return convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(mem_ctx,
1019 return convert_samr_dispinfo_to_NET_DISPLAY_GROUP(mem_ctx,
1024 return WERR_UNKNOWN_LEVEL;
1030 /****************************************************************
1031 ****************************************************************/
1033 WERROR NetQueryDisplayInformation_r(struct libnetapi_ctx *ctx,
1034 struct NetQueryDisplayInformation *r)
1036 struct cli_state *cli = NULL;
1037 struct rpc_pipe_client *pipe_cli = NULL;
1038 struct policy_handle connect_handle;
1039 struct dom_sid2 *domain_sid = NULL;
1040 struct policy_handle domain_handle;
1041 union samr_DispInfo info;
1043 uint32_t total_size = 0;
1044 uint32_t returned_size = 0;
1046 NTSTATUS status = NT_STATUS_OK;
1049 ZERO_STRUCT(connect_handle);
1050 ZERO_STRUCT(domain_handle);
1052 switch (r->in.level) {
1058 return WERR_UNKNOWN_LEVEL;
1061 werr = libnetapi_open_pipe(ctx, r->in.server_name,
1062 &ndr_table_samr.syntax_id,
1065 if (!W_ERROR_IS_OK(werr)) {
1069 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
1070 SAMR_ACCESS_ENUM_DOMAINS |
1071 SAMR_ACCESS_OPEN_DOMAIN,
1072 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
1073 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
1074 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
1078 if (!W_ERROR_IS_OK(werr)) {
1082 status = rpccli_samr_QueryDisplayInfo2(pipe_cli,
1087 r->in.entries_requested,
1092 if (!NT_STATUS_IS_OK(status)) {
1093 werr = ntstatus_to_werror(status);
1097 werr = convert_samr_dispinfo_to_NET_DISPLAY(ctx, &info,
1099 r->out.entries_read,
1107 if (NT_STATUS_IS_OK(status) ||
1108 NT_STATUS_IS_ERR(status)) {
1110 if (ctx->disable_policy_handle_cache) {
1111 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
1112 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
1120 /****************************************************************
1121 ****************************************************************/
1124 WERROR NetQueryDisplayInformation_l(struct libnetapi_ctx *ctx,
1125 struct NetQueryDisplayInformation *r)
1127 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetQueryDisplayInformation);
1130 /****************************************************************
1131 ****************************************************************/
1133 WERROR NetUserChangePassword_r(struct libnetapi_ctx *ctx,
1134 struct NetUserChangePassword *r)
1136 return WERR_NOT_SUPPORTED;
1139 /****************************************************************
1140 ****************************************************************/
1142 WERROR NetUserChangePassword_l(struct libnetapi_ctx *ctx,
1143 struct NetUserChangePassword *r)
1145 return WERR_NOT_SUPPORTED;
1148 /****************************************************************
1149 ****************************************************************/
1151 WERROR NetUserGetInfo_r(struct libnetapi_ctx *ctx,
1152 struct NetUserGetInfo *r)
1154 struct cli_state *cli = NULL;
1155 struct rpc_pipe_client *pipe_cli = NULL;
1159 struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle;
1160 struct lsa_String lsa_account_name;
1161 struct dom_sid2 *domain_sid = NULL;
1162 struct samr_Ids user_rids, name_types;
1163 uint32_t num_entries = 0;
1165 ZERO_STRUCT(connect_handle);
1166 ZERO_STRUCT(domain_handle);
1167 ZERO_STRUCT(builtin_handle);
1168 ZERO_STRUCT(user_handle);
1170 if (!r->out.buffer) {
1171 return WERR_INVALID_PARAM;
1174 switch (r->in.level) {
1182 werr = WERR_NOT_SUPPORTED;
1186 werr = libnetapi_open_pipe(ctx, r->in.server_name,
1187 &ndr_table_samr.syntax_id,
1190 if (!W_ERROR_IS_OK(werr)) {
1194 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
1195 SAMR_ACCESS_ENUM_DOMAINS |
1196 SAMR_ACCESS_OPEN_DOMAIN,
1197 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
1201 if (!W_ERROR_IS_OK(werr)) {
1205 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
1206 SAMR_ACCESS_ENUM_DOMAINS |
1207 SAMR_ACCESS_OPEN_DOMAIN,
1208 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
1209 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
1212 if (!W_ERROR_IS_OK(werr)) {
1216 init_lsa_String(&lsa_account_name, r->in.user_name);
1218 status = rpccli_samr_LookupNames(pipe_cli, ctx,
1224 if (!NT_STATUS_IS_OK(status)) {
1225 werr = ntstatus_to_werror(status);
1229 status = libnetapi_samr_lookup_user_map_USER_INFO(ctx, pipe_cli,
1238 if (!NT_STATUS_IS_OK(status)) {
1239 werr = ntstatus_to_werror(status);
1248 if (is_valid_policy_hnd(&user_handle)) {
1249 rpccli_samr_Close(pipe_cli, ctx, &user_handle);
1252 if (ctx->disable_policy_handle_cache) {
1253 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
1254 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
1260 /****************************************************************
1261 ****************************************************************/
1263 WERROR NetUserGetInfo_l(struct libnetapi_ctx *ctx,
1264 struct NetUserGetInfo *r)
1266 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserGetInfo);
1269 /****************************************************************
1270 ****************************************************************/
1272 WERROR NetUserSetInfo_r(struct libnetapi_ctx *ctx,
1273 struct NetUserSetInfo *r)
1275 struct cli_state *cli = NULL;
1276 struct rpc_pipe_client *pipe_cli = NULL;
1280 struct policy_handle connect_handle, domain_handle, builtin_handle, user_handle;
1281 struct lsa_String lsa_account_name;
1282 struct dom_sid2 *domain_sid = NULL;
1283 struct samr_Ids user_rids, name_types;
1284 union samr_UserInfo user_info;
1286 struct USER_INFO_X uX;
1288 ZERO_STRUCT(connect_handle);
1289 ZERO_STRUCT(domain_handle);
1290 ZERO_STRUCT(builtin_handle);
1291 ZERO_STRUCT(user_handle);
1293 if (!r->in.buffer) {
1294 return WERR_INVALID_PARAM;
1297 switch (r->in.level) {
1302 werr = WERR_NOT_SUPPORTED;
1306 werr = libnetapi_open_pipe(ctx, r->in.server_name,
1307 &ndr_table_samr.syntax_id,
1310 if (!W_ERROR_IS_OK(werr)) {
1314 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
1315 SAMR_ACCESS_ENUM_DOMAINS |
1316 SAMR_ACCESS_OPEN_DOMAIN,
1317 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
1318 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
1322 if (!W_ERROR_IS_OK(werr)) {
1326 werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
1327 SAMR_ACCESS_ENUM_DOMAINS |
1328 SAMR_ACCESS_OPEN_DOMAIN,
1329 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
1330 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
1333 if (!W_ERROR_IS_OK(werr)) {
1337 init_lsa_String(&lsa_account_name, r->in.user_name);
1339 status = rpccli_samr_LookupNames(pipe_cli, ctx,
1345 if (!NT_STATUS_IS_OK(status)) {
1346 werr = ntstatus_to_werror(status);
1350 status = rpccli_samr_OpenUser(pipe_cli, ctx,
1352 SAMR_USER_ACCESS_SET_ATTRIBUTES,
1355 if (!NT_STATUS_IS_OK(status)) {
1356 werr = ntstatus_to_werror(status);
1360 status = construct_USER_INFO_X(r->in.level, r->in.buffer, &uX);
1361 if (!NT_STATUS_IS_OK(status)) {
1362 werr = ntstatus_to_werror(status);
1366 convert_USER_INFO_X_to_samr_user_info21(&uX, &user_info.info21);
1368 status = rpccli_samr_SetUserInfo(pipe_cli, ctx,
1372 if (!NT_STATUS_IS_OK(status)) {
1373 werr = ntstatus_to_werror(status);
1384 if (is_valid_policy_hnd(&user_handle)) {
1385 rpccli_samr_Close(pipe_cli, ctx, &user_handle);
1388 if (ctx->disable_policy_handle_cache) {
1389 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
1390 libnetapi_samr_close_builtin_handle(ctx, &builtin_handle);
1391 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
1397 /****************************************************************
1398 ****************************************************************/
1400 WERROR NetUserSetInfo_l(struct libnetapi_ctx *ctx,
1401 struct NetUserSetInfo *r)
1403 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserSetInfo);
1406 /****************************************************************
1407 ****************************************************************/
1409 static NTSTATUS query_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx,
1410 struct rpc_pipe_client *pipe_cli,
1411 struct policy_handle *domain_handle,
1412 struct samr_DomInfo1 *info1,
1413 struct samr_DomInfo3 *info3,
1414 struct samr_DomInfo5 *info5,
1415 struct samr_DomInfo6 *info6,
1416 struct samr_DomInfo7 *info7,
1417 struct samr_DomInfo12 *info12)
1420 union samr_DomainInfo *dom_info = NULL;
1423 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
1427 NT_STATUS_NOT_OK_RETURN(status);
1429 *info1 = dom_info->info1;
1433 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
1437 NT_STATUS_NOT_OK_RETURN(status);
1439 *info3 = dom_info->info3;
1443 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
1447 NT_STATUS_NOT_OK_RETURN(status);
1449 *info5 = dom_info->info5;
1453 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
1457 NT_STATUS_NOT_OK_RETURN(status);
1459 *info6 = dom_info->info6;
1463 status = rpccli_samr_QueryDomainInfo(pipe_cli, mem_ctx,
1467 NT_STATUS_NOT_OK_RETURN(status);
1469 *info7 = dom_info->info7;
1473 status = rpccli_samr_QueryDomainInfo2(pipe_cli, mem_ctx,
1477 NT_STATUS_NOT_OK_RETURN(status);
1479 *info12 = dom_info->info12;
1482 return NT_STATUS_OK;
1485 /****************************************************************
1486 ****************************************************************/
1488 static NTSTATUS query_USER_MODALS_INFO_0(TALLOC_CTX *mem_ctx,
1489 struct rpc_pipe_client *pipe_cli,
1490 struct policy_handle *domain_handle,
1491 struct USER_MODALS_INFO_0 *info0)
1494 struct samr_DomInfo1 dom_info1;
1495 struct samr_DomInfo3 dom_info3;
1497 ZERO_STRUCTP(info0);
1499 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1508 NT_STATUS_NOT_OK_RETURN(status);
1510 info0->usrmod0_min_passwd_len =
1511 dom_info1.min_password_length;
1512 info0->usrmod0_max_passwd_age =
1513 nt_time_to_unix_abs((NTTIME *)&dom_info1.max_password_age);
1514 info0->usrmod0_min_passwd_age =
1515 nt_time_to_unix_abs((NTTIME *)&dom_info1.min_password_age);
1516 info0->usrmod0_password_hist_len =
1517 dom_info1.password_history_length;
1519 info0->usrmod0_force_logoff =
1520 nt_time_to_unix_abs(&dom_info3.force_logoff_time);
1522 return NT_STATUS_OK;
1525 /****************************************************************
1526 ****************************************************************/
1528 static NTSTATUS query_USER_MODALS_INFO_1(TALLOC_CTX *mem_ctx,
1529 struct rpc_pipe_client *pipe_cli,
1530 struct policy_handle *domain_handle,
1531 struct USER_MODALS_INFO_1 *info1)
1534 struct samr_DomInfo6 dom_info6;
1535 struct samr_DomInfo7 dom_info7;
1537 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1546 NT_STATUS_NOT_OK_RETURN(status);
1548 info1->usrmod1_primary =
1549 talloc_strdup(mem_ctx, dom_info6.primary.string);
1551 info1->usrmod1_role = dom_info7.role;
1553 return NT_STATUS_OK;
1556 /****************************************************************
1557 ****************************************************************/
1559 static NTSTATUS query_USER_MODALS_INFO_2(TALLOC_CTX *mem_ctx,
1560 struct rpc_pipe_client *pipe_cli,
1561 struct policy_handle *domain_handle,
1562 struct dom_sid *domain_sid,
1563 struct USER_MODALS_INFO_2 *info2)
1566 struct samr_DomInfo5 dom_info5;
1568 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1577 NT_STATUS_NOT_OK_RETURN(status);
1579 info2->usrmod2_domain_name =
1580 talloc_strdup(mem_ctx, dom_info5.domain_name.string);
1581 info2->usrmod2_domain_id =
1582 (struct domsid *)sid_dup_talloc(mem_ctx, domain_sid);
1584 NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_name);
1585 NT_STATUS_HAVE_NO_MEMORY(info2->usrmod2_domain_id);
1587 return NT_STATUS_OK;
1590 /****************************************************************
1591 ****************************************************************/
1593 static NTSTATUS query_USER_MODALS_INFO_3(TALLOC_CTX *mem_ctx,
1594 struct rpc_pipe_client *pipe_cli,
1595 struct policy_handle *domain_handle,
1596 struct USER_MODALS_INFO_3 *info3)
1599 struct samr_DomInfo12 dom_info12;
1601 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1610 NT_STATUS_NOT_OK_RETURN(status);
1612 info3->usrmod3_lockout_duration =
1613 nt_time_to_unix_abs(&dom_info12.lockout_duration);
1614 info3->usrmod3_lockout_observation_window =
1615 nt_time_to_unix_abs(&dom_info12.lockout_window);
1616 info3->usrmod3_lockout_threshold =
1617 dom_info12.lockout_threshold;
1619 return NT_STATUS_OK;
1622 /****************************************************************
1623 ****************************************************************/
1625 static NTSTATUS query_USER_MODALS_INFO_to_buffer(TALLOC_CTX *mem_ctx,
1626 struct rpc_pipe_client *pipe_cli,
1628 struct policy_handle *domain_handle,
1629 struct dom_sid *domain_sid,
1634 struct USER_MODALS_INFO_0 info0;
1635 struct USER_MODALS_INFO_1 info1;
1636 struct USER_MODALS_INFO_2 info2;
1637 struct USER_MODALS_INFO_3 info3;
1640 return ERROR_INSUFFICIENT_BUFFER;
1645 status = query_USER_MODALS_INFO_0(mem_ctx,
1649 NT_STATUS_NOT_OK_RETURN(status);
1651 *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info0,
1656 status = query_USER_MODALS_INFO_1(mem_ctx,
1660 NT_STATUS_NOT_OK_RETURN(status);
1662 *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info1,
1666 status = query_USER_MODALS_INFO_2(mem_ctx,
1671 NT_STATUS_NOT_OK_RETURN(status);
1673 *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info2,
1677 status = query_USER_MODALS_INFO_3(mem_ctx,
1681 NT_STATUS_NOT_OK_RETURN(status);
1683 *buffer = (uint8_t *)talloc_memdup(mem_ctx, &info3,
1690 NT_STATUS_HAVE_NO_MEMORY(*buffer);
1692 return NT_STATUS_OK;
1695 /****************************************************************
1696 ****************************************************************/
1698 WERROR NetUserModalsGet_r(struct libnetapi_ctx *ctx,
1699 struct NetUserModalsGet *r)
1701 struct cli_state *cli = NULL;
1702 struct rpc_pipe_client *pipe_cli = NULL;
1706 struct policy_handle connect_handle, domain_handle;
1707 struct dom_sid2 *domain_sid = NULL;
1708 uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT;
1710 ZERO_STRUCT(connect_handle);
1711 ZERO_STRUCT(domain_handle);
1713 if (!r->out.buffer) {
1714 return WERR_INVALID_PARAM;
1717 switch (r->in.level) {
1719 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
1720 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2;
1724 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2;
1727 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1;
1730 werr = WERR_UNKNOWN_LEVEL;
1734 werr = libnetapi_open_pipe(ctx, r->in.server_name,
1735 &ndr_table_samr.syntax_id,
1738 if (!W_ERROR_IS_OK(werr)) {
1742 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
1743 SAMR_ACCESS_ENUM_DOMAINS |
1744 SAMR_ACCESS_OPEN_DOMAIN,
1749 if (!W_ERROR_IS_OK(werr)) {
1756 /* 3: 12 (DomainInfo2) */
1758 status = query_USER_MODALS_INFO_to_buffer(ctx,
1764 if (!NT_STATUS_IS_OK(status)) {
1765 werr = ntstatus_to_werror(status);
1774 if (ctx->disable_policy_handle_cache) {
1775 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
1776 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
1782 /****************************************************************
1783 ****************************************************************/
1785 WERROR NetUserModalsGet_l(struct libnetapi_ctx *ctx,
1786 struct NetUserModalsGet *r)
1788 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsGet);
1791 /****************************************************************
1792 ****************************************************************/
1794 static NTSTATUS set_USER_MODALS_INFO_rpc(TALLOC_CTX *mem_ctx,
1795 struct rpc_pipe_client *pipe_cli,
1796 struct policy_handle *domain_handle,
1797 struct samr_DomInfo1 *info1,
1798 struct samr_DomInfo3 *info3,
1799 struct samr_DomInfo12 *info12)
1802 union samr_DomainInfo dom_info;
1806 ZERO_STRUCT(dom_info);
1808 dom_info.info1 = *info1;
1810 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
1814 NT_STATUS_NOT_OK_RETURN(status);
1819 ZERO_STRUCT(dom_info);
1821 dom_info.info3 = *info3;
1823 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
1828 NT_STATUS_NOT_OK_RETURN(status);
1833 ZERO_STRUCT(dom_info);
1835 dom_info.info12 = *info12;
1837 status = rpccli_samr_SetDomainInfo(pipe_cli, mem_ctx,
1842 NT_STATUS_NOT_OK_RETURN(status);
1845 return NT_STATUS_OK;
1848 /****************************************************************
1849 ****************************************************************/
1851 static NTSTATUS set_USER_MODALS_INFO_0_buffer(TALLOC_CTX *mem_ctx,
1852 struct rpc_pipe_client *pipe_cli,
1853 struct policy_handle *domain_handle,
1854 struct USER_MODALS_INFO_0 *info0)
1857 struct samr_DomInfo1 dom_info_1;
1858 struct samr_DomInfo3 dom_info_3;
1860 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1869 NT_STATUS_NOT_OK_RETURN(status);
1871 dom_info_1.min_password_length =
1872 info0->usrmod0_min_passwd_len;
1873 dom_info_1.password_history_length =
1874 info0->usrmod0_password_hist_len;
1876 unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age,
1877 info0->usrmod0_max_passwd_age);
1878 unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age,
1879 info0->usrmod0_min_passwd_age);
1881 unix_to_nt_time_abs(&dom_info_3.force_logoff_time,
1882 info0->usrmod0_force_logoff);
1884 return set_USER_MODALS_INFO_rpc(mem_ctx,
1892 /****************************************************************
1893 ****************************************************************/
1895 static NTSTATUS set_USER_MODALS_INFO_3_buffer(TALLOC_CTX *mem_ctx,
1896 struct rpc_pipe_client *pipe_cli,
1897 struct policy_handle *domain_handle,
1898 struct USER_MODALS_INFO_3 *info3)
1901 struct samr_DomInfo12 dom_info_12;
1903 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1912 NT_STATUS_NOT_OK_RETURN(status);
1914 unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_duration,
1915 info3->usrmod3_lockout_duration);
1916 unix_to_nt_time_abs((NTTIME *)&dom_info_12.lockout_window,
1917 info3->usrmod3_lockout_observation_window);
1918 dom_info_12.lockout_threshold = info3->usrmod3_lockout_threshold;
1920 return set_USER_MODALS_INFO_rpc(mem_ctx,
1928 /****************************************************************
1929 ****************************************************************/
1931 static NTSTATUS set_USER_MODALS_INFO_1001_buffer(TALLOC_CTX *mem_ctx,
1932 struct rpc_pipe_client *pipe_cli,
1933 struct policy_handle *domain_handle,
1934 struct USER_MODALS_INFO_1001 *info1001)
1937 struct samr_DomInfo1 dom_info_1;
1939 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1948 NT_STATUS_NOT_OK_RETURN(status);
1950 dom_info_1.min_password_length =
1951 info1001->usrmod1001_min_passwd_len;
1953 return set_USER_MODALS_INFO_rpc(mem_ctx,
1961 /****************************************************************
1962 ****************************************************************/
1964 static NTSTATUS set_USER_MODALS_INFO_1002_buffer(TALLOC_CTX *mem_ctx,
1965 struct rpc_pipe_client *pipe_cli,
1966 struct policy_handle *domain_handle,
1967 struct USER_MODALS_INFO_1002 *info1002)
1970 struct samr_DomInfo1 dom_info_1;
1972 status = query_USER_MODALS_INFO_rpc(mem_ctx,
1981 NT_STATUS_NOT_OK_RETURN(status);
1983 unix_to_nt_time_abs((NTTIME *)&dom_info_1.max_password_age,
1984 info1002->usrmod1002_max_passwd_age);
1986 return set_USER_MODALS_INFO_rpc(mem_ctx,
1994 /****************************************************************
1995 ****************************************************************/
1997 static NTSTATUS set_USER_MODALS_INFO_1003_buffer(TALLOC_CTX *mem_ctx,
1998 struct rpc_pipe_client *pipe_cli,
1999 struct policy_handle *domain_handle,
2000 struct USER_MODALS_INFO_1003 *info1003)
2003 struct samr_DomInfo1 dom_info_1;
2005 status = query_USER_MODALS_INFO_rpc(mem_ctx,
2014 NT_STATUS_NOT_OK_RETURN(status);
2016 unix_to_nt_time_abs((NTTIME *)&dom_info_1.min_password_age,
2017 info1003->usrmod1003_min_passwd_age);
2019 return set_USER_MODALS_INFO_rpc(mem_ctx,
2027 /****************************************************************
2028 ****************************************************************/
2030 static NTSTATUS set_USER_MODALS_INFO_1004_buffer(TALLOC_CTX *mem_ctx,
2031 struct rpc_pipe_client *pipe_cli,
2032 struct policy_handle *domain_handle,
2033 struct USER_MODALS_INFO_1004 *info1004)
2036 struct samr_DomInfo3 dom_info_3;
2038 status = query_USER_MODALS_INFO_rpc(mem_ctx,
2047 NT_STATUS_NOT_OK_RETURN(status);
2049 unix_to_nt_time_abs(&dom_info_3.force_logoff_time,
2050 info1004->usrmod1004_force_logoff);
2052 return set_USER_MODALS_INFO_rpc(mem_ctx,
2060 /****************************************************************
2061 ****************************************************************/
2063 static NTSTATUS set_USER_MODALS_INFO_1005_buffer(TALLOC_CTX *mem_ctx,
2064 struct rpc_pipe_client *pipe_cli,
2065 struct policy_handle *domain_handle,
2066 struct USER_MODALS_INFO_1005 *info1005)
2069 struct samr_DomInfo1 dom_info_1;
2071 status = query_USER_MODALS_INFO_rpc(mem_ctx,
2080 NT_STATUS_NOT_OK_RETURN(status);
2082 dom_info_1.password_history_length =
2083 info1005->usrmod1005_password_hist_len;
2085 return set_USER_MODALS_INFO_rpc(mem_ctx,
2093 /****************************************************************
2094 ****************************************************************/
2096 static NTSTATUS set_USER_MODALS_INFO_buffer(TALLOC_CTX *mem_ctx,
2097 struct rpc_pipe_client *pipe_cli,
2099 struct policy_handle *domain_handle,
2100 struct dom_sid *domain_sid,
2103 struct USER_MODALS_INFO_0 *info0;
2104 struct USER_MODALS_INFO_3 *info3;
2105 struct USER_MODALS_INFO_1001 *info1001;
2106 struct USER_MODALS_INFO_1002 *info1002;
2107 struct USER_MODALS_INFO_1003 *info1003;
2108 struct USER_MODALS_INFO_1004 *info1004;
2109 struct USER_MODALS_INFO_1005 *info1005;
2112 return ERROR_INSUFFICIENT_BUFFER;
2117 info0 = (struct USER_MODALS_INFO_0 *)buffer;
2118 return set_USER_MODALS_INFO_0_buffer(mem_ctx,
2123 info3 = (struct USER_MODALS_INFO_3 *)buffer;
2124 return set_USER_MODALS_INFO_3_buffer(mem_ctx,
2129 info1001 = (struct USER_MODALS_INFO_1001 *)buffer;
2130 return set_USER_MODALS_INFO_1001_buffer(mem_ctx,
2135 info1002 = (struct USER_MODALS_INFO_1002 *)buffer;
2136 return set_USER_MODALS_INFO_1002_buffer(mem_ctx,
2141 info1003 = (struct USER_MODALS_INFO_1003 *)buffer;
2142 return set_USER_MODALS_INFO_1003_buffer(mem_ctx,
2147 info1004 = (struct USER_MODALS_INFO_1004 *)buffer;
2148 return set_USER_MODALS_INFO_1004_buffer(mem_ctx,
2153 info1005 = (struct USER_MODALS_INFO_1005 *)buffer;
2154 return set_USER_MODALS_INFO_1005_buffer(mem_ctx,
2163 return NT_STATUS_OK;
2166 /****************************************************************
2167 ****************************************************************/
2169 WERROR NetUserModalsSet_r(struct libnetapi_ctx *ctx,
2170 struct NetUserModalsSet *r)
2172 struct cli_state *cli = NULL;
2173 struct rpc_pipe_client *pipe_cli = NULL;
2177 struct policy_handle connect_handle, domain_handle;
2178 struct dom_sid2 *domain_sid = NULL;
2179 uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT;
2181 ZERO_STRUCT(connect_handle);
2182 ZERO_STRUCT(domain_handle);
2184 if (!r->in.buffer) {
2185 return WERR_INVALID_PARAM;
2188 switch (r->in.level) {
2190 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
2191 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
2192 SAMR_DOMAIN_ACCESS_SET_INFO_1 |
2193 SAMR_DOMAIN_ACCESS_SET_INFO_2;
2200 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
2201 SAMR_DOMAIN_ACCESS_SET_INFO_1;
2204 access_mask |= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
2205 SAMR_DOMAIN_ACCESS_SET_INFO_2;
2211 werr = WERR_NOT_SUPPORTED;
2214 werr = WERR_UNKNOWN_LEVEL;
2218 werr = libnetapi_open_pipe(ctx, r->in.server_name,
2219 &ndr_table_samr.syntax_id,
2222 if (!W_ERROR_IS_OK(werr)) {
2226 werr = libnetapi_samr_open_domain(ctx, pipe_cli,
2227 SAMR_ACCESS_ENUM_DOMAINS |
2228 SAMR_ACCESS_OPEN_DOMAIN,
2233 if (!W_ERROR_IS_OK(werr)) {
2237 status = set_USER_MODALS_INFO_buffer(ctx,
2243 if (!NT_STATUS_IS_OK(status)) {
2244 werr = ntstatus_to_werror(status);
2253 if (ctx->disable_policy_handle_cache) {
2254 libnetapi_samr_close_domain_handle(ctx, &domain_handle);
2255 libnetapi_samr_close_connect_handle(ctx, &connect_handle);
2261 /****************************************************************
2262 ****************************************************************/
2264 WERROR NetUserModalsSet_l(struct libnetapi_ctx *ctx,
2265 struct NetUserModalsSet *r)
2267 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetUserModalsSet);