2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997,
7 * Copyright (C) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2008,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
14 * Copyright (C) Guenther Deschner 2008.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
31 * This is the implementation of the SAMR code.
35 #include "../libcli/auth/libcli_auth.h"
38 #define DBGC_CLASS DBGC_RPC_SRV
40 #define SAMR_USR_RIGHTS_WRITE_PW \
41 ( READ_CONTROL_ACCESS | \
42 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
43 SAMR_USER_ACCESS_SET_LOC_COM)
44 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
45 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
47 #define DISP_INFO_CACHE_TIMEOUT 10
49 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
50 #define MAX_SAM_ENTRIES_W95 50
52 struct samr_connect_info {
56 struct samr_domain_info {
58 struct disp_info *disp_info;
61 struct samr_user_info {
65 struct samr_group_info {
69 struct samr_alias_info {
73 typedef struct disp_info {
74 DOM_SID sid; /* identify which domain this is. */
75 struct pdb_search *users; /* querydispinfo 1 and 4 */
76 struct pdb_search *machines; /* querydispinfo 2 */
77 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
78 struct pdb_search *aliases; /* enumaliases */
81 struct pdb_search *enum_users; /* enumusers with a mask */
83 struct timed_event *cache_timeout_event; /* cache idle timeout
87 static const struct generic_mapping sam_generic_mapping = {
88 GENERIC_RIGHTS_SAM_READ,
89 GENERIC_RIGHTS_SAM_WRITE,
90 GENERIC_RIGHTS_SAM_EXECUTE,
91 GENERIC_RIGHTS_SAM_ALL_ACCESS};
92 static const struct generic_mapping dom_generic_mapping = {
93 GENERIC_RIGHTS_DOMAIN_READ,
94 GENERIC_RIGHTS_DOMAIN_WRITE,
95 GENERIC_RIGHTS_DOMAIN_EXECUTE,
96 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
97 static const struct generic_mapping usr_generic_mapping = {
98 GENERIC_RIGHTS_USER_READ,
99 GENERIC_RIGHTS_USER_WRITE,
100 GENERIC_RIGHTS_USER_EXECUTE,
101 GENERIC_RIGHTS_USER_ALL_ACCESS};
102 static const struct generic_mapping usr_nopwchange_generic_mapping = {
103 GENERIC_RIGHTS_USER_READ,
104 GENERIC_RIGHTS_USER_WRITE,
105 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
106 GENERIC_RIGHTS_USER_ALL_ACCESS};
107 static const struct generic_mapping grp_generic_mapping = {
108 GENERIC_RIGHTS_GROUP_READ,
109 GENERIC_RIGHTS_GROUP_WRITE,
110 GENERIC_RIGHTS_GROUP_EXECUTE,
111 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
112 static const struct generic_mapping ali_generic_mapping = {
113 GENERIC_RIGHTS_ALIAS_READ,
114 GENERIC_RIGHTS_ALIAS_WRITE,
115 GENERIC_RIGHTS_ALIAS_EXECUTE,
116 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
118 /*******************************************************************
119 *******************************************************************/
121 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
122 const struct generic_mapping *map,
123 DOM_SID *sid, uint32 sid_access )
125 DOM_SID domadmin_sid;
126 SEC_ACE ace[5]; /* at most 5 entries */
131 /* basic access for Everyone */
133 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
134 map->generic_execute | map->generic_read, 0);
136 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
138 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
139 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
140 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
141 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
143 /* Add Full Access for Domain Admins if we are a DC */
146 sid_copy( &domadmin_sid, get_global_sam_sid() );
147 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
148 init_sec_ace(&ace[i++], &domadmin_sid,
149 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
152 /* if we have a sid, give it some special access */
155 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
158 /* create the security descriptor */
160 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
161 return NT_STATUS_NO_MEMORY;
163 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
164 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
165 psa, sd_size)) == NULL)
166 return NT_STATUS_NO_MEMORY;
171 /*******************************************************************
172 Checks if access to an object should be granted, and returns that
173 level of access for further checks.
174 ********************************************************************/
176 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
177 SE_PRIV *rights, uint32 rights_mask,
178 uint32 des_access, uint32 *acc_granted,
181 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
182 uint32 saved_mask = 0;
184 /* check privileges; certain SAM access bits should be overridden
185 by privileges (mostly having to do with creating/modifying/deleting
188 if ( rights && user_has_any_privilege( token, rights ) ) {
190 saved_mask = (des_access & rights_mask);
191 des_access &= ~saved_mask;
193 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
198 /* check the security descriptor first */
200 status = se_access_check(psd, token, des_access, acc_granted);
201 if (NT_STATUS_IS_OK(status)) {
205 /* give root a free pass */
207 if ( geteuid() == sec_initial_uid() ) {
209 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
210 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
212 *acc_granted = des_access;
214 status = NT_STATUS_OK;
220 /* add in any bits saved during the privilege check (only
221 matters is status is ok) */
223 *acc_granted |= rights_mask;
225 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
226 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
227 des_access, *acc_granted));
233 /*******************************************************************
234 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
235 ********************************************************************/
237 static void map_max_allowed_access(const NT_USER_TOKEN *token,
238 uint32_t *pacc_requested)
240 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
243 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
245 /* At least try for generic read. */
246 *pacc_requested = GENERIC_READ_ACCESS;
248 /* root gets anything. */
249 if (geteuid() == sec_initial_uid()) {
250 *pacc_requested |= GENERIC_ALL_ACCESS;
254 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
256 if (is_sid_in_token(token, &global_sid_Builtin_Administrators) ||
257 is_sid_in_token(token, &global_sid_Builtin_Account_Operators)) {
258 *pacc_requested |= GENERIC_ALL_ACCESS;
262 /* Full access for DOMAIN\Domain Admins. */
264 DOM_SID domadmin_sid;
265 sid_copy( &domadmin_sid, get_global_sam_sid() );
266 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
267 if (is_sid_in_token(token, &domadmin_sid)) {
268 *pacc_requested |= GENERIC_ALL_ACCESS;
272 /* TODO ! Check privileges. */
275 /*******************************************************************
276 Fetch or create a dispinfo struct.
277 ********************************************************************/
279 static DISP_INFO *get_samr_dispinfo_by_sid(const struct dom_sid *psid)
282 * We do a static cache for DISP_INFO's here. Explanation can be found
283 * in Jeremy's checkin message to r11793:
285 * Fix the SAMR cache so it works across completely insane
286 * client behaviour (ie.:
287 * open pipe/open SAMR handle/enumerate 0 - 1024
288 * close SAMR handle, close pipe.
289 * open pipe/open SAMR handle/enumerate 1024 - 2048...
290 * close SAMR handle, close pipe.
291 * And on ad-nausium. Amazing.... probably object-oriented
292 * client side programming in action yet again.
293 * This change should *massively* improve performance when
294 * enumerating users from an LDAP database.
297 * "Our" and the builtin domain are the only ones where we ever
298 * enumerate stuff, so just cache 2 entries.
301 static struct disp_info *builtin_dispinfo;
302 static struct disp_info *domain_dispinfo;
304 /* There are two cases to consider here:
305 1) The SID is a domain SID and we look for an equality match, or
306 2) This is an account SID and so we return the DISP_INFO* for our
313 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
315 * Necessary only once, but it does not really hurt.
317 if (builtin_dispinfo == NULL) {
318 builtin_dispinfo = talloc_zero(
319 talloc_autofree_context(), struct disp_info);
320 if (builtin_dispinfo == NULL) {
324 sid_copy(&builtin_dispinfo->sid, &global_sid_Builtin);
326 return builtin_dispinfo;
329 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
331 * Necessary only once, but it does not really hurt.
333 if (domain_dispinfo == NULL) {
334 domain_dispinfo = talloc_zero(
335 talloc_autofree_context(), struct disp_info);
336 if (domain_dispinfo == NULL) {
340 sid_copy(&domain_dispinfo->sid, get_global_sam_sid());
342 return domain_dispinfo;
348 /*******************************************************************
349 Function to free the per SID data.
350 ********************************************************************/
352 static void free_samr_cache(DISP_INFO *disp_info)
354 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
355 sid_string_dbg(&disp_info->sid)));
357 /* We need to become root here because the paged search might have to
358 * tell the LDAP server we're not interested in the rest anymore. */
362 TALLOC_FREE(disp_info->users);
363 TALLOC_FREE(disp_info->machines);
364 TALLOC_FREE(disp_info->groups);
365 TALLOC_FREE(disp_info->aliases);
366 TALLOC_FREE(disp_info->enum_users);
371 /*******************************************************************
372 Idle event handler. Throw away the disp info cache.
373 ********************************************************************/
375 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
376 struct timed_event *te,
380 DISP_INFO *disp_info = (DISP_INFO *)private_data;
382 TALLOC_FREE(disp_info->cache_timeout_event);
384 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
386 free_samr_cache(disp_info);
389 /*******************************************************************
390 Setup cache removal idle event handler.
391 ********************************************************************/
393 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
395 /* Remove any pending timeout and update. */
397 TALLOC_FREE(disp_info->cache_timeout_event);
399 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
400 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
401 (unsigned int)secs_fromnow ));
403 disp_info->cache_timeout_event = event_add_timed(
404 smbd_event_context(), NULL,
405 timeval_current_ofs(secs_fromnow, 0),
406 disp_info_cache_idle_timeout_handler, (void *)disp_info);
409 /*******************************************************************
410 Force flush any cache. We do this on any samr_set_xxx call.
411 We must also remove the timeout handler.
412 ********************************************************************/
414 static void force_flush_samr_cache(const struct dom_sid *sid)
416 struct disp_info *disp_info = get_samr_dispinfo_by_sid(sid);
418 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
422 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
423 TALLOC_FREE(disp_info->cache_timeout_event);
424 free_samr_cache(disp_info);
427 /*******************************************************************
428 Ensure password info is never given out. Paranioa... JRA.
429 ********************************************************************/
431 static void samr_clear_sam_passwd(struct samu *sam_pass)
437 /* These now zero out the old password */
439 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
440 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
443 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
445 struct samr_displayentry *entry;
447 if (sid_check_is_builtin(&info->sid)) {
448 /* No users in builtin. */
452 if (info->users == NULL) {
453 info->users = pdb_search_users(info, acct_flags);
454 if (info->users == NULL) {
458 /* Fetch the last possible entry, thus trigger an enumeration */
459 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
461 /* Ensure we cache this enumeration. */
462 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
464 return info->users->num_entries;
467 static uint32 count_sam_groups(struct disp_info *info)
469 struct samr_displayentry *entry;
471 if (sid_check_is_builtin(&info->sid)) {
472 /* No groups in builtin. */
476 if (info->groups == NULL) {
477 info->groups = pdb_search_groups(info);
478 if (info->groups == NULL) {
482 /* Fetch the last possible entry, thus trigger an enumeration */
483 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
485 /* Ensure we cache this enumeration. */
486 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
488 return info->groups->num_entries;
491 static uint32 count_sam_aliases(struct disp_info *info)
493 struct samr_displayentry *entry;
495 if (info->aliases == NULL) {
496 info->aliases = pdb_search_aliases(info, &info->sid);
497 if (info->aliases == NULL) {
501 /* Fetch the last possible entry, thus trigger an enumeration */
502 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
504 /* Ensure we cache this enumeration. */
505 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
507 return info->aliases->num_entries;
510 /*******************************************************************
512 ********************************************************************/
514 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
516 if (!close_policy_hnd(p, r->in.handle)) {
517 return NT_STATUS_INVALID_HANDLE;
520 ZERO_STRUCTP(r->out.handle);
525 /*******************************************************************
527 ********************************************************************/
529 NTSTATUS _samr_OpenDomain(pipes_struct *p,
530 struct samr_OpenDomain *r)
532 struct samr_connect_info *cinfo;
533 struct samr_domain_info *dinfo;
534 SEC_DESC *psd = NULL;
536 uint32 des_access = r->in.access_mask;
541 /* find the connection policy handle. */
543 cinfo = policy_handle_find(p, r->in.connect_handle, 0, NULL,
544 struct samr_connect_info, &status);
545 if (!NT_STATUS_IS_OK(status)) {
549 /*check if access can be granted as requested by client. */
550 map_max_allowed_access(p->server_info->ptok, &des_access);
552 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
553 se_map_generic( &des_access, &dom_generic_mapping );
555 se_priv_copy( &se_rights, &se_machine_account );
556 se_priv_add( &se_rights, &se_add_users );
558 status = access_check_samr_object( psd, p->server_info->ptok,
559 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
560 &acc_granted, "_samr_OpenDomain" );
562 if ( !NT_STATUS_IS_OK(status) )
565 if (!sid_check_is_domain(r->in.sid) &&
566 !sid_check_is_builtin(r->in.sid)) {
567 return NT_STATUS_NO_SUCH_DOMAIN;
570 dinfo = policy_handle_create(p, r->out.domain_handle, acc_granted,
571 struct samr_domain_info, &status);
572 if (!NT_STATUS_IS_OK(status)) {
575 dinfo->sid = *r->in.sid;
576 dinfo->disp_info = get_samr_dispinfo_by_sid(r->in.sid);
578 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
583 /*******************************************************************
585 ********************************************************************/
587 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
588 struct samr_GetUserPwInfo *r)
590 struct samr_user_info *uinfo;
591 enum lsa_SidType sid_type;
592 uint32_t min_password_length = 0;
593 uint32_t password_properties = 0;
597 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
599 uinfo = policy_handle_find(p, r->in.user_handle,
600 SAMR_USER_ACCESS_GET_ATTRIBUTES, NULL,
601 struct samr_user_info, &status);
602 if (!NT_STATUS_IS_OK(status)) {
606 if (!sid_check_is_in_our_domain(&uinfo->sid)) {
607 return NT_STATUS_OBJECT_TYPE_MISMATCH;
611 ret = lookup_sid(p->mem_ctx, &uinfo->sid, NULL, NULL, &sid_type);
614 return NT_STATUS_NO_SUCH_USER;
620 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
621 &min_password_length);
622 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
623 &password_properties);
626 if (lp_check_password_script() && *lp_check_password_script()) {
627 password_properties |= DOMAIN_PASSWORD_COMPLEX;
635 r->out.info->min_password_length = min_password_length;
636 r->out.info->password_properties = password_properties;
638 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
643 /*******************************************************************
645 ********************************************************************/
647 NTSTATUS _samr_SetSecurity(pipes_struct *p,
648 struct samr_SetSecurity *r)
650 struct samr_user_info *uinfo;
654 struct samu *sampass=NULL;
657 uinfo = policy_handle_find(p, r->in.handle,
658 SAMR_USER_ACCESS_SET_ATTRIBUTES, NULL,
659 struct samr_user_info, &status);
660 if (!NT_STATUS_IS_OK(status)) {
664 if (!(sampass = samu_new( p->mem_ctx))) {
665 DEBUG(0,("No memory!\n"));
666 return NT_STATUS_NO_MEMORY;
669 /* get the user record */
671 ret = pdb_getsampwsid(sampass, &uinfo->sid);
675 DEBUG(4, ("User %s not found\n",
676 sid_string_dbg(&uinfo->sid)));
677 TALLOC_FREE(sampass);
678 return NT_STATUS_INVALID_HANDLE;
681 dacl = r->in.sdbuf->sd->dacl;
682 for (i=0; i < dacl->num_aces; i++) {
683 if (sid_equal(&uinfo->sid, &dacl->aces[i].trustee)) {
684 ret = pdb_set_pass_can_change(sampass,
685 (dacl->aces[i].access_mask &
686 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
693 TALLOC_FREE(sampass);
694 return NT_STATUS_ACCESS_DENIED;
698 status = pdb_update_sam_account(sampass);
701 TALLOC_FREE(sampass);
706 /*******************************************************************
707 build correct perms based on policies and password times for _samr_query_sec_obj
708 *******************************************************************/
709 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
711 struct samu *sampass=NULL;
714 if ( !(sampass = samu_new( mem_ctx )) ) {
715 DEBUG(0,("No memory!\n"));
720 ret = pdb_getsampwsid(sampass, user_sid);
724 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
725 TALLOC_FREE(sampass);
729 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
731 if (pdb_get_pass_can_change(sampass)) {
732 TALLOC_FREE(sampass);
735 TALLOC_FREE(sampass);
740 /*******************************************************************
742 ********************************************************************/
744 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
745 struct samr_QuerySecurity *r)
747 struct samr_connect_info *cinfo;
748 struct samr_domain_info *dinfo;
749 struct samr_user_info *uinfo;
750 struct samr_group_info *ginfo;
751 struct samr_alias_info *ainfo;
753 SEC_DESC * psd = NULL;
756 cinfo = policy_handle_find(p, r->in.handle,
757 STD_RIGHT_READ_CONTROL_ACCESS, NULL,
758 struct samr_connect_info, &status);
759 if (NT_STATUS_IS_OK(status)) {
760 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
761 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size,
762 &sam_generic_mapping, NULL, 0);
766 dinfo = policy_handle_find(p, r->in.handle,
767 STD_RIGHT_READ_CONTROL_ACCESS, NULL,
768 struct samr_domain_info, &status);
769 if (NT_STATUS_IS_OK(status)) {
770 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
771 "with SID: %s\n", sid_string_dbg(&dinfo->sid)));
773 * TODO: Builtin probably needs a different SD with restricted
776 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size,
777 &dom_generic_mapping, NULL, 0);
781 uinfo = policy_handle_find(p, r->in.handle,
782 STD_RIGHT_READ_CONTROL_ACCESS, NULL,
783 struct samr_user_info, &status);
784 if (NT_STATUS_IS_OK(status)) {
785 DEBUG(10,("_samr_QuerySecurity: querying security on user "
786 "Object with SID: %s\n",
787 sid_string_dbg(&uinfo->sid)));
788 if (check_change_pw_access(p->mem_ctx, &uinfo->sid)) {
789 status = make_samr_object_sd(
790 p->mem_ctx, &psd, &sd_size,
791 &usr_generic_mapping,
792 &uinfo->sid, SAMR_USR_RIGHTS_WRITE_PW);
794 status = make_samr_object_sd(
795 p->mem_ctx, &psd, &sd_size,
796 &usr_nopwchange_generic_mapping,
797 &uinfo->sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
802 ginfo = policy_handle_find(p, r->in.handle,
803 STD_RIGHT_READ_CONTROL_ACCESS, NULL,
804 struct samr_group_info, &status);
805 if (NT_STATUS_IS_OK(status)) {
807 * TODO: different SDs have to be generated for aliases groups
808 * and users. Currently all three get a default user SD
810 DEBUG(10,("_samr_QuerySecurity: querying security on group "
811 "Object with SID: %s\n",
812 sid_string_dbg(&ginfo->sid)));
813 status = make_samr_object_sd(
814 p->mem_ctx, &psd, &sd_size,
815 &usr_nopwchange_generic_mapping,
816 &ginfo->sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
820 ainfo = policy_handle_find(p, r->in.handle,
821 STD_RIGHT_READ_CONTROL_ACCESS, NULL,
822 struct samr_alias_info, &status);
823 if (NT_STATUS_IS_OK(status)) {
825 * TODO: different SDs have to be generated for aliases groups
826 * and users. Currently all three get a default user SD
828 DEBUG(10,("_samr_QuerySecurity: querying security on alias "
829 "Object with SID: %s\n",
830 sid_string_dbg(&ainfo->sid)));
831 status = make_samr_object_sd(
832 p->mem_ctx, &psd, &sd_size,
833 &usr_nopwchange_generic_mapping,
834 &ainfo->sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
838 return NT_STATUS_OBJECT_TYPE_MISMATCH;
840 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
841 return NT_STATUS_NO_MEMORY;
846 /*******************************************************************
847 makes a SAM_ENTRY / UNISTR2* structure from a user list.
848 ********************************************************************/
850 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
851 struct samr_SamEntry **sam_pp,
852 uint32_t num_entries,
854 struct samr_displayentry *entries)
857 struct samr_SamEntry *sam;
861 if (num_entries == 0) {
865 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
867 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
868 return NT_STATUS_NO_MEMORY;
871 for (i = 0; i < num_entries; i++) {
874 * usrmgr expects a non-NULL terminated string with
875 * trust relationships
877 if (entries[i].acct_flags & ACB_DOMTRUST) {
878 init_unistr2(&uni_temp_name, entries[i].account_name,
881 init_unistr2(&uni_temp_name, entries[i].account_name,
885 init_lsa_String(&sam[i].name, entries[i].account_name);
886 sam[i].idx = entries[i].rid;
894 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
896 /*******************************************************************
897 _samr_EnumDomainUsers
898 ********************************************************************/
900 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
901 struct samr_EnumDomainUsers *r)
904 struct samr_domain_info *dinfo;
906 uint32 enum_context = *r->in.resume_handle;
907 enum remote_arch_types ra_type = get_remote_arch();
908 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
909 uint32 max_entries = max_sam_entries;
910 struct samr_displayentry *entries = NULL;
911 struct samr_SamArray *samr_array = NULL;
912 struct samr_SamEntry *samr_entries = NULL;
914 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
916 dinfo = policy_handle_find(p, r->in.domain_handle,
917 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS, NULL,
918 struct samr_domain_info, &status);
919 if (!NT_STATUS_IS_OK(status)) {
923 if (sid_check_is_builtin(&dinfo->sid)) {
924 /* No users in builtin. */
925 *r->out.resume_handle = *r->in.resume_handle;
926 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
930 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
932 return NT_STATUS_NO_MEMORY;
934 *r->out.sam = samr_array;
940 if ((dinfo->disp_info->enum_users != NULL) &&
941 (dinfo->disp_info->enum_acb_mask != r->in.acct_flags)) {
942 TALLOC_FREE(dinfo->disp_info->enum_users);
945 if (dinfo->disp_info->enum_users == NULL) {
946 dinfo->disp_info->enum_users = pdb_search_users(
947 dinfo->disp_info, r->in.acct_flags);
948 dinfo->disp_info->enum_acb_mask = r->in.acct_flags;
951 if (dinfo->disp_info->enum_users == NULL) {
952 /* END AS ROOT !!!! */
954 return NT_STATUS_ACCESS_DENIED;
957 num_account = pdb_search_entries(dinfo->disp_info->enum_users,
958 enum_context, max_entries,
961 /* END AS ROOT !!!! */
965 if (num_account == 0) {
966 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
968 *r->out.resume_handle = *r->in.resume_handle;
972 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
973 num_account, enum_context,
975 if (!NT_STATUS_IS_OK(status)) {
979 if (max_entries <= num_account) {
980 status = STATUS_MORE_ENTRIES;
982 status = NT_STATUS_OK;
985 /* Ensure we cache this enumeration. */
986 set_disp_info_cache_timeout(dinfo->disp_info, DISP_INFO_CACHE_TIMEOUT);
988 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
990 samr_array->count = num_account;
991 samr_array->entries = samr_entries;
993 *r->out.resume_handle = *r->in.resume_handle + num_account;
994 *r->out.num_entries = num_account;
996 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1001 /*******************************************************************
1002 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1003 ********************************************************************/
1005 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1006 struct samr_SamEntry **sam_pp,
1007 uint32_t num_sam_entries,
1008 struct samr_displayentry *entries)
1010 struct samr_SamEntry *sam;
1015 if (num_sam_entries == 0) {
1019 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1024 for (i = 0; i < num_sam_entries; i++) {
1026 * JRA. I think this should include the null. TNG does not.
1028 init_lsa_String(&sam[i].name, entries[i].account_name);
1029 sam[i].idx = entries[i].rid;
1035 /*******************************************************************
1036 _samr_EnumDomainGroups
1037 ********************************************************************/
1039 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1040 struct samr_EnumDomainGroups *r)
1043 struct samr_domain_info *dinfo;
1044 struct samr_displayentry *groups;
1046 struct samr_SamArray *samr_array = NULL;
1047 struct samr_SamEntry *samr_entries = NULL;
1049 dinfo = policy_handle_find(p, r->in.domain_handle,
1050 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS, NULL,
1051 struct samr_domain_info, &status);
1052 if (!NT_STATUS_IS_OK(status)) {
1056 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1058 if (sid_check_is_builtin(&dinfo->sid)) {
1059 /* No groups in builtin. */
1060 *r->out.resume_handle = *r->in.resume_handle;
1061 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1065 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1067 return NT_STATUS_NO_MEMORY;
1070 /* the domain group array is being allocated in the function below */
1074 if (dinfo->disp_info->groups == NULL) {
1075 dinfo->disp_info->groups = pdb_search_groups(dinfo->disp_info);
1077 if (dinfo->disp_info->groups == NULL) {
1079 return NT_STATUS_ACCESS_DENIED;
1083 num_groups = pdb_search_entries(dinfo->disp_info->groups,
1084 *r->in.resume_handle,
1085 MAX_SAM_ENTRIES, &groups);
1088 /* Ensure we cache this enumeration. */
1089 set_disp_info_cache_timeout(dinfo->disp_info, DISP_INFO_CACHE_TIMEOUT);
1091 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1092 num_groups, groups);
1094 samr_array->count = num_groups;
1095 samr_array->entries = samr_entries;
1097 *r->out.sam = samr_array;
1098 *r->out.num_entries = num_groups;
1099 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1101 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1106 /*******************************************************************
1107 _samr_EnumDomainAliases
1108 ********************************************************************/
1110 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1111 struct samr_EnumDomainAliases *r)
1114 struct samr_domain_info *dinfo;
1115 struct samr_displayentry *aliases;
1116 uint32 num_aliases = 0;
1117 struct samr_SamArray *samr_array = NULL;
1118 struct samr_SamEntry *samr_entries = NULL;
1120 dinfo = policy_handle_find(p, r->in.domain_handle,
1121 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS, NULL,
1122 struct samr_domain_info, &status);
1123 if (!NT_STATUS_IS_OK(status)) {
1127 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1128 sid_string_dbg(&dinfo->sid)));
1130 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1132 return NT_STATUS_NO_MEMORY;
1137 if (dinfo->disp_info->aliases == NULL) {
1138 dinfo->disp_info->aliases = pdb_search_aliases(
1139 dinfo->disp_info, &dinfo->sid);
1140 if (dinfo->disp_info->aliases == NULL) {
1142 return NT_STATUS_ACCESS_DENIED;
1146 num_aliases = pdb_search_entries(dinfo->disp_info->aliases,
1147 *r->in.resume_handle,
1148 MAX_SAM_ENTRIES, &aliases);
1151 /* Ensure we cache this enumeration. */
1152 set_disp_info_cache_timeout(dinfo->disp_info, DISP_INFO_CACHE_TIMEOUT);
1154 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1155 num_aliases, aliases);
1157 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1159 samr_array->count = num_aliases;
1160 samr_array->entries = samr_entries;
1162 *r->out.sam = samr_array;
1163 *r->out.num_entries = num_aliases;
1164 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1169 /*******************************************************************
1170 inits a samr_DispInfoGeneral structure.
1171 ********************************************************************/
1173 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1174 struct samr_DispInfoGeneral *r,
1175 uint32_t num_entries,
1177 struct samr_displayentry *entries)
1181 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1183 if (num_entries == 0) {
1184 return NT_STATUS_OK;
1187 r->count = num_entries;
1189 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1191 return NT_STATUS_NO_MEMORY;
1194 for (i = 0; i < num_entries ; i++) {
1196 init_lsa_String(&r->entries[i].account_name,
1197 entries[i].account_name);
1199 init_lsa_String(&r->entries[i].description,
1200 entries[i].description);
1202 init_lsa_String(&r->entries[i].full_name,
1203 entries[i].fullname);
1205 r->entries[i].rid = entries[i].rid;
1206 r->entries[i].acct_flags = entries[i].acct_flags;
1207 r->entries[i].idx = start_idx+i+1;
1210 return NT_STATUS_OK;
1213 /*******************************************************************
1214 inits a samr_DispInfoFull structure.
1215 ********************************************************************/
1217 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1218 struct samr_DispInfoFull *r,
1219 uint32_t num_entries,
1221 struct samr_displayentry *entries)
1225 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1227 if (num_entries == 0) {
1228 return NT_STATUS_OK;
1231 r->count = num_entries;
1233 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1235 return NT_STATUS_NO_MEMORY;
1238 for (i = 0; i < num_entries ; i++) {
1240 init_lsa_String(&r->entries[i].account_name,
1241 entries[i].account_name);
1243 init_lsa_String(&r->entries[i].description,
1244 entries[i].description);
1246 r->entries[i].rid = entries[i].rid;
1247 r->entries[i].acct_flags = entries[i].acct_flags;
1248 r->entries[i].idx = start_idx+i+1;
1251 return NT_STATUS_OK;
1254 /*******************************************************************
1255 inits a samr_DispInfoFullGroups structure.
1256 ********************************************************************/
1258 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1259 struct samr_DispInfoFullGroups *r,
1260 uint32_t num_entries,
1262 struct samr_displayentry *entries)
1266 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1268 if (num_entries == 0) {
1269 return NT_STATUS_OK;
1272 r->count = num_entries;
1274 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1276 return NT_STATUS_NO_MEMORY;
1279 for (i = 0; i < num_entries ; i++) {
1281 init_lsa_String(&r->entries[i].account_name,
1282 entries[i].account_name);
1284 init_lsa_String(&r->entries[i].description,
1285 entries[i].description);
1287 r->entries[i].rid = entries[i].rid;
1288 r->entries[i].acct_flags = entries[i].acct_flags;
1289 r->entries[i].idx = start_idx+i+1;
1292 return NT_STATUS_OK;
1295 /*******************************************************************
1296 inits a samr_DispInfoAscii structure.
1297 ********************************************************************/
1299 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1300 struct samr_DispInfoAscii *r,
1301 uint32_t num_entries,
1303 struct samr_displayentry *entries)
1307 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1309 if (num_entries == 0) {
1310 return NT_STATUS_OK;
1313 r->count = num_entries;
1315 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1317 return NT_STATUS_NO_MEMORY;
1320 for (i = 0; i < num_entries ; i++) {
1322 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1323 entries[i].account_name);
1325 r->entries[i].idx = start_idx+i+1;
1328 return NT_STATUS_OK;
1331 /*******************************************************************
1332 inits a samr_DispInfoAscii structure.
1333 ********************************************************************/
1335 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1336 struct samr_DispInfoAscii *r,
1337 uint32_t num_entries,
1339 struct samr_displayentry *entries)
1343 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1345 if (num_entries == 0) {
1346 return NT_STATUS_OK;
1349 r->count = num_entries;
1351 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1353 return NT_STATUS_NO_MEMORY;
1356 for (i = 0; i < num_entries ; i++) {
1358 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1359 entries[i].account_name);
1361 r->entries[i].idx = start_idx+i+1;
1364 return NT_STATUS_OK;
1367 /*******************************************************************
1368 _samr_QueryDisplayInfo
1369 ********************************************************************/
1371 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1372 struct samr_QueryDisplayInfo *r)
1375 struct samr_domain_info *dinfo;
1376 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1378 uint32 max_entries = r->in.max_entries;
1379 uint32 enum_context = r->in.start_idx;
1380 uint32 max_size = r->in.buf_size;
1382 union samr_DispInfo *disp_info = r->out.info;
1384 uint32 temp_size=0, total_data_size=0;
1385 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1386 uint32 num_account = 0;
1387 enum remote_arch_types ra_type = get_remote_arch();
1388 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1389 struct samr_displayentry *entries = NULL;
1391 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1393 dinfo = policy_handle_find(p, r->in.domain_handle,
1394 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS, NULL,
1395 struct samr_domain_info, &status);
1396 if (!NT_STATUS_IS_OK(status)) {
1400 if (sid_check_is_builtin(&dinfo->sid)) {
1401 DEBUG(5,("_samr_QueryDisplayInfo: no users in BUILTIN\n"));
1402 return NT_STATUS_OK;
1406 * calculate how many entries we will return.
1408 * - the number of entries the client asked
1409 * - our limit on that
1410 * - the starting point (enumeration context)
1411 * - the buffer size the client will accept
1415 * We are a lot more like W2K. Instead of reading the SAM
1416 * each time to find the records we need to send back,
1417 * we read it once and link that copy to the sam handle.
1418 * For large user list (over the MAX_SAM_ENTRIES)
1419 * it's a definitive win.
1420 * second point to notice: between enumerations
1421 * our sam is now the same as it's a snapshoot.
1422 * third point: got rid of the static SAM_USER_21 struct
1423 * no more intermediate.
1424 * con: it uses much more memory, as a full copy is stored
1427 * If you want to change it, think twice and think
1428 * of the second point , that's really important.
1433 if ((r->in.level < 1) || (r->in.level > 5)) {
1434 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1435 (unsigned int)r->in.level ));
1436 return NT_STATUS_INVALID_INFO_CLASS;
1439 /* first limit the number of entries we will return */
1440 if(max_entries > max_sam_entries) {
1441 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1442 "entries, limiting to %d\n", max_entries,
1444 max_entries = max_sam_entries;
1447 /* calculate the size and limit on the number of entries we will
1450 temp_size=max_entries*struct_size;
1452 if (temp_size>max_size) {
1453 max_entries=MIN((max_size/struct_size),max_entries);;
1454 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1455 "only %d entries\n", max_entries));
1460 /* THe following done as ROOT. Don't return without unbecome_root(). */
1462 switch (r->in.level) {
1465 if (dinfo->disp_info->users == NULL) {
1466 dinfo->disp_info->users = pdb_search_users(
1467 dinfo->disp_info, ACB_NORMAL);
1468 if (dinfo->disp_info->users == NULL) {
1470 return NT_STATUS_ACCESS_DENIED;
1472 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1473 (unsigned int)enum_context ));
1475 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1476 (unsigned int)enum_context ));
1479 num_account = pdb_search_entries(dinfo->disp_info->users,
1480 enum_context, max_entries,
1484 if (dinfo->disp_info->machines == NULL) {
1485 dinfo->disp_info->machines = pdb_search_users(
1486 dinfo->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
1487 if (dinfo->disp_info->machines == NULL) {
1489 return NT_STATUS_ACCESS_DENIED;
1491 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1492 (unsigned int)enum_context ));
1494 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1495 (unsigned int)enum_context ));
1498 num_account = pdb_search_entries(dinfo->disp_info->machines,
1499 enum_context, max_entries,
1504 if (dinfo->disp_info->groups == NULL) {
1505 dinfo->disp_info->groups = pdb_search_groups(
1507 if (dinfo->disp_info->groups == NULL) {
1509 return NT_STATUS_ACCESS_DENIED;
1511 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1512 (unsigned int)enum_context ));
1514 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1515 (unsigned int)enum_context ));
1518 num_account = pdb_search_entries(dinfo->disp_info->groups,
1519 enum_context, max_entries,
1524 smb_panic("info class changed");
1530 /* Now create reply structure */
1531 switch (r->in.level) {
1533 disp_ret = init_samr_dispinfo_1(p->mem_ctx, &disp_info->info1,
1534 num_account, enum_context,
1538 disp_ret = init_samr_dispinfo_2(p->mem_ctx, &disp_info->info2,
1539 num_account, enum_context,
1543 disp_ret = init_samr_dispinfo_3(p->mem_ctx, &disp_info->info3,
1544 num_account, enum_context,
1548 disp_ret = init_samr_dispinfo_4(p->mem_ctx, &disp_info->info4,
1549 num_account, enum_context,
1553 disp_ret = init_samr_dispinfo_5(p->mem_ctx, &disp_info->info5,
1554 num_account, enum_context,
1558 smb_panic("info class changed");
1562 if (!NT_STATUS_IS_OK(disp_ret))
1565 /* calculate the total size */
1566 total_data_size=num_account*struct_size;
1568 if (max_entries <= num_account) {
1569 status = STATUS_MORE_ENTRIES;
1571 status = NT_STATUS_OK;
1574 /* Ensure we cache this enumeration. */
1575 set_disp_info_cache_timeout(dinfo->disp_info, DISP_INFO_CACHE_TIMEOUT);
1577 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__));
1579 *r->out.total_size = total_data_size;
1580 *r->out.returned_size = temp_size;
1585 /****************************************************************
1586 _samr_QueryDisplayInfo2
1587 ****************************************************************/
1589 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
1590 struct samr_QueryDisplayInfo2 *r)
1592 struct samr_QueryDisplayInfo q;
1594 q.in.domain_handle = r->in.domain_handle;
1595 q.in.level = r->in.level;
1596 q.in.start_idx = r->in.start_idx;
1597 q.in.max_entries = r->in.max_entries;
1598 q.in.buf_size = r->in.buf_size;
1600 q.out.total_size = r->out.total_size;
1601 q.out.returned_size = r->out.returned_size;
1602 q.out.info = r->out.info;
1604 return _samr_QueryDisplayInfo(p, &q);
1607 /****************************************************************
1608 _samr_QueryDisplayInfo3
1609 ****************************************************************/
1611 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
1612 struct samr_QueryDisplayInfo3 *r)
1614 struct samr_QueryDisplayInfo q;
1616 q.in.domain_handle = r->in.domain_handle;
1617 q.in.level = r->in.level;
1618 q.in.start_idx = r->in.start_idx;
1619 q.in.max_entries = r->in.max_entries;
1620 q.in.buf_size = r->in.buf_size;
1622 q.out.total_size = r->out.total_size;
1623 q.out.returned_size = r->out.returned_size;
1624 q.out.info = r->out.info;
1626 return _samr_QueryDisplayInfo(p, &q);
1629 /*******************************************************************
1630 _samr_QueryAliasInfo
1631 ********************************************************************/
1633 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
1634 struct samr_QueryAliasInfo *r)
1636 struct samr_alias_info *ainfo;
1637 struct acct_info info;
1639 union samr_AliasInfo *alias_info = NULL;
1640 const char *alias_name = NULL;
1641 const char *alias_description = NULL;
1643 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1645 ainfo = policy_handle_find(p, r->in.alias_handle,
1646 SAMR_ALIAS_ACCESS_LOOKUP_INFO, NULL,
1647 struct samr_alias_info, &status);
1648 if (!NT_STATUS_IS_OK(status)) {
1652 alias_info = TALLOC_ZERO_P(p->mem_ctx, union samr_AliasInfo);
1654 return NT_STATUS_NO_MEMORY;
1658 status = pdb_get_aliasinfo(&ainfo->sid, &info);
1661 if ( !NT_STATUS_IS_OK(status))
1664 /* FIXME: info contains fstrings */
1665 alias_name = talloc_strdup(r, info.acct_name);
1666 alias_description = talloc_strdup(r, info.acct_desc);
1668 switch (r->in.level) {
1670 alias_info->all.name.string = alias_name;
1671 alias_info->all.num_members = 1; /* ??? */
1672 alias_info->all.description.string = alias_description;
1674 case ALIASINFODESCRIPTION:
1675 alias_info->description.string = alias_description;
1678 return NT_STATUS_INVALID_INFO_CLASS;
1681 *r->out.info = alias_info;
1683 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1685 return NT_STATUS_OK;
1688 /*******************************************************************
1690 ********************************************************************/
1692 NTSTATUS _samr_LookupNames(pipes_struct *p,
1693 struct samr_LookupNames *r)
1695 struct samr_domain_info *dinfo;
1698 enum lsa_SidType *type;
1700 int num_rids = r->in.num_names;
1701 struct samr_Ids rids, types;
1702 uint32_t num_mapped = 0;
1704 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1706 dinfo = policy_handle_find(p, r->in.domain_handle,
1707 0 /* Don't know the acc_bits yet */, NULL,
1708 struct samr_domain_info, &status);
1709 if (!NT_STATUS_IS_OK(status)) {
1713 if (num_rids > MAX_SAM_ENTRIES) {
1714 num_rids = MAX_SAM_ENTRIES;
1715 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1718 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1719 NT_STATUS_HAVE_NO_MEMORY(rid);
1721 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1722 NT_STATUS_HAVE_NO_MEMORY(type);
1724 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1725 sid_string_dbg(&dinfo->sid)));
1727 for (i = 0; i < num_rids; i++) {
1729 status = NT_STATUS_NONE_MAPPED;
1730 type[i] = SID_NAME_UNKNOWN;
1732 rid[i] = 0xffffffff;
1734 if (sid_check_is_builtin(&dinfo->sid)) {
1735 if (lookup_builtin_name(r->in.names[i].string,
1738 type[i] = SID_NAME_ALIAS;
1741 lookup_global_sam_name(r->in.names[i].string, 0,
1745 if (type[i] != SID_NAME_UNKNOWN) {
1750 if (num_mapped == num_rids) {
1751 status = NT_STATUS_OK;
1752 } else if (num_mapped == 0) {
1753 status = NT_STATUS_NONE_MAPPED;
1755 status = STATUS_SOME_UNMAPPED;
1758 rids.count = num_rids;
1761 types.count = num_rids;
1764 *r->out.rids = rids;
1765 *r->out.types = types;
1767 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1772 /****************************************************************
1773 _samr_ChangePasswordUser
1774 ****************************************************************/
1776 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
1777 struct samr_ChangePasswordUser *r)
1781 struct samr_user_info *uinfo;
1783 struct samr_Password new_lmPwdHash, new_ntPwdHash, checkHash;
1784 struct samr_Password lm_pwd, nt_pwd;
1786 uinfo = policy_handle_find(p, r->in.user_handle,
1787 SAMR_USER_ACCESS_SET_PASSWORD, NULL,
1788 struct samr_user_info, &status);
1789 if (!NT_STATUS_IS_OK(status)) {
1793 DEBUG(5,("_samr_ChangePasswordUser: sid:%s\n",
1794 sid_string_dbg(&uinfo->sid)));
1796 if (!(pwd = samu_new(NULL))) {
1797 return NT_STATUS_NO_MEMORY;
1801 ret = pdb_getsampwsid(pwd, &uinfo->sid);
1806 return NT_STATUS_WRONG_PASSWORD;
1810 const uint8_t *lm_pass, *nt_pass;
1812 lm_pass = pdb_get_lanman_passwd(pwd);
1813 nt_pass = pdb_get_nt_passwd(pwd);
1815 if (!lm_pass || !nt_pass) {
1816 status = NT_STATUS_WRONG_PASSWORD;
1820 memcpy(&lm_pwd.hash, lm_pass, sizeof(lm_pwd.hash));
1821 memcpy(&nt_pwd.hash, nt_pass, sizeof(nt_pwd.hash));
1824 /* basic sanity checking on parameters. Do this before any database ops */
1825 if (!r->in.lm_present || !r->in.nt_present ||
1826 !r->in.old_lm_crypted || !r->in.new_lm_crypted ||
1827 !r->in.old_nt_crypted || !r->in.new_nt_crypted) {
1828 /* we should really handle a change with lm not
1830 status = NT_STATUS_INVALID_PARAMETER_MIX;
1834 /* decrypt and check the new lm hash */
1835 D_P16(lm_pwd.hash, r->in.new_lm_crypted->hash, new_lmPwdHash.hash);
1836 D_P16(new_lmPwdHash.hash, r->in.old_lm_crypted->hash, checkHash.hash);
1837 if (memcmp(checkHash.hash, lm_pwd.hash, 16) != 0) {
1838 status = NT_STATUS_WRONG_PASSWORD;
1842 /* decrypt and check the new nt hash */
1843 D_P16(nt_pwd.hash, r->in.new_nt_crypted->hash, new_ntPwdHash.hash);
1844 D_P16(new_ntPwdHash.hash, r->in.old_nt_crypted->hash, checkHash.hash);
1845 if (memcmp(checkHash.hash, nt_pwd.hash, 16) != 0) {
1846 status = NT_STATUS_WRONG_PASSWORD;
1850 /* The NT Cross is not required by Win2k3 R2, but if present
1851 check the nt cross hash */
1852 if (r->in.cross1_present && r->in.nt_cross) {
1853 D_P16(lm_pwd.hash, r->in.nt_cross->hash, checkHash.hash);
1854 if (memcmp(checkHash.hash, new_ntPwdHash.hash, 16) != 0) {
1855 status = NT_STATUS_WRONG_PASSWORD;
1860 /* The LM Cross is not required by Win2k3 R2, but if present
1861 check the lm cross hash */
1862 if (r->in.cross2_present && r->in.lm_cross) {
1863 D_P16(nt_pwd.hash, r->in.lm_cross->hash, checkHash.hash);
1864 if (memcmp(checkHash.hash, new_lmPwdHash.hash, 16) != 0) {
1865 status = NT_STATUS_WRONG_PASSWORD;
1870 if (!pdb_set_nt_passwd(pwd, new_ntPwdHash.hash, PDB_CHANGED) ||
1871 !pdb_set_lanman_passwd(pwd, new_lmPwdHash.hash, PDB_CHANGED)) {
1872 status = NT_STATUS_ACCESS_DENIED;
1876 status = pdb_update_sam_account(pwd);
1883 /*******************************************************************
1884 _samr_ChangePasswordUser2
1885 ********************************************************************/
1887 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1888 struct samr_ChangePasswordUser2 *r)
1894 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1896 fstrcpy(user_name, r->in.account->string);
1897 fstrcpy(wks, r->in.server->string);
1899 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1902 * Pass the user through the NT -> unix user mapping
1906 (void)map_username(user_name);
1909 * UNIX username case mangling not required, pass_oem_change
1910 * is case insensitive.
1913 status = pass_oem_change(user_name,
1914 r->in.lm_password->data,
1915 r->in.lm_verifier->hash,
1916 r->in.nt_password->data,
1917 r->in.nt_verifier->hash,
1920 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1922 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
1923 return NT_STATUS_WRONG_PASSWORD;
1929 /****************************************************************
1930 _samr_OemChangePasswordUser2
1931 ****************************************************************/
1933 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
1934 struct samr_OemChangePasswordUser2 *r)
1938 const char *wks = NULL;
1940 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__));
1942 fstrcpy(user_name, r->in.account->string);
1943 if (r->in.server && r->in.server->string) {
1944 wks = r->in.server->string;
1947 DEBUG(5,("_samr_OemChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1950 * Pass the user through the NT -> unix user mapping
1954 (void)map_username(user_name);
1957 * UNIX username case mangling not required, pass_oem_change
1958 * is case insensitive.
1961 if (!r->in.hash || !r->in.password) {
1962 return NT_STATUS_INVALID_PARAMETER;
1965 status = pass_oem_change(user_name,
1966 r->in.password->data,
1972 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
1973 return NT_STATUS_WRONG_PASSWORD;
1976 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__));
1981 /*******************************************************************
1982 _samr_ChangePasswordUser3
1983 ********************************************************************/
1985 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
1986 struct samr_ChangePasswordUser3 *r)
1990 const char *wks = NULL;
1991 uint32 reject_reason;
1992 struct samr_DomInfo1 *dominfo = NULL;
1993 struct samr_ChangeReject *reject = NULL;
1996 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1998 fstrcpy(user_name, r->in.account->string);
1999 if (r->in.server && r->in.server->string) {
2000 wks = r->in.server->string;
2003 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
2006 * Pass the user through the NT -> unix user mapping
2010 (void)map_username(user_name);
2013 * UNIX username case mangling not required, pass_oem_change
2014 * is case insensitive.
2017 status = pass_oem_change(user_name,
2018 r->in.lm_password->data,
2019 r->in.lm_verifier->hash,
2020 r->in.nt_password->data,
2021 r->in.nt_verifier->hash,
2023 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
2024 return NT_STATUS_WRONG_PASSWORD;
2027 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
2028 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
2030 time_t u_expire, u_min_age;
2031 uint32 account_policy_temp;
2033 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
2035 return NT_STATUS_NO_MEMORY;
2038 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
2040 return NT_STATUS_NO_MEMORY;
2047 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &tmp);
2048 dominfo->min_password_length = tmp;
2050 pdb_get_account_policy(AP_PASSWORD_HISTORY, &tmp);
2051 dominfo->password_history_length = tmp;
2053 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2054 &dominfo->password_properties);
2056 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2057 u_expire = account_policy_temp;
2059 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2060 u_min_age = account_policy_temp;
2066 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
2067 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
2069 if (lp_check_password_script() && *lp_check_password_script()) {
2070 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
2073 reject->reason = reject_reason;
2075 *r->out.dominfo = dominfo;
2076 *r->out.reject = reject;
2079 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2084 /*******************************************************************
2085 makes a SAMR_R_LOOKUP_RIDS structure.
2086 ********************************************************************/
2088 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2090 struct lsa_String **lsa_name_array_p)
2092 struct lsa_String *lsa_name_array = NULL;
2095 *lsa_name_array_p = NULL;
2097 if (num_names != 0) {
2098 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2099 if (!lsa_name_array) {
2104 for (i = 0; i < num_names; i++) {
2105 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2106 init_lsa_String(&lsa_name_array[i], names[i]);
2109 *lsa_name_array_p = lsa_name_array;
2114 /*******************************************************************
2116 ********************************************************************/
2118 NTSTATUS _samr_LookupRids(pipes_struct *p,
2119 struct samr_LookupRids *r)
2121 struct samr_domain_info *dinfo;
2124 enum lsa_SidType *attrs = NULL;
2125 uint32 *wire_attrs = NULL;
2126 int num_rids = (int)r->in.num_rids;
2128 struct lsa_Strings names_array;
2129 struct samr_Ids types_array;
2130 struct lsa_String *lsa_names = NULL;
2132 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2134 dinfo = policy_handle_find(p, r->in.domain_handle,
2135 0 /* Don't know the acc_bits yet */, NULL,
2136 struct samr_domain_info, &status);
2137 if (!NT_STATUS_IS_OK(status)) {
2141 if (num_rids > 1000) {
2142 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2143 "to samba4 idl this is not possible\n", num_rids));
2144 return NT_STATUS_UNSUCCESSFUL;
2148 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2149 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2150 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2152 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2153 return NT_STATUS_NO_MEMORY;
2160 become_root(); /* lookup_sid can require root privs */
2161 status = pdb_lookup_rids(&dinfo->sid, num_rids, r->in.rids,
2165 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2166 status = NT_STATUS_OK;
2169 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2171 return NT_STATUS_NO_MEMORY;
2174 /* Convert from enum lsa_SidType to uint32 for wire format. */
2175 for (i = 0; i < num_rids; i++) {
2176 wire_attrs[i] = (uint32)attrs[i];
2179 names_array.count = num_rids;
2180 names_array.names = lsa_names;
2182 types_array.count = num_rids;
2183 types_array.ids = wire_attrs;
2185 *r->out.names = names_array;
2186 *r->out.types = types_array;
2188 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2193 /*******************************************************************
2195 ********************************************************************/
2197 NTSTATUS _samr_OpenUser(pipes_struct *p,
2198 struct samr_OpenUser *r)
2200 struct samu *sampass=NULL;
2202 struct samr_domain_info *dinfo;
2203 struct samr_user_info *uinfo;
2204 SEC_DESC *psd = NULL;
2206 uint32 des_access = r->in.access_mask;
2213 dinfo = policy_handle_find(p, r->in.domain_handle,
2214 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, NULL,
2215 struct samr_domain_info, &status);
2216 if (!NT_STATUS_IS_OK(status)) {
2220 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2221 return NT_STATUS_NO_MEMORY;
2224 /* append the user's RID to it */
2226 if (!sid_compose(&sid, &dinfo->sid, r->in.rid))
2227 return NT_STATUS_NO_SUCH_USER;
2229 /* check if access can be granted as requested by client. */
2231 map_max_allowed_access(p->server_info->ptok, &des_access);
2233 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2234 se_map_generic(&des_access, &usr_generic_mapping);
2236 se_priv_copy( &se_rights, &se_machine_account );
2237 se_priv_add( &se_rights, &se_add_users );
2239 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2240 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2241 &acc_granted, "_samr_OpenUser");
2243 if ( !NT_STATUS_IS_OK(nt_status) )
2247 ret=pdb_getsampwsid(sampass, &sid);
2250 /* check that the SID exists in our domain. */
2252 return NT_STATUS_NO_SUCH_USER;
2255 TALLOC_FREE(sampass);
2257 uinfo = policy_handle_create(p, r->out.user_handle, acc_granted,
2258 struct samr_user_info, &nt_status);
2259 if (!NT_STATUS_IS_OK(nt_status)) {
2264 return NT_STATUS_OK;
2267 /*************************************************************************
2268 *************************************************************************/
2270 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2272 struct lsa_BinaryString **_r)
2274 struct lsa_BinaryString *r;
2277 return NT_STATUS_INVALID_PARAMETER;
2280 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2282 return NT_STATUS_NO_MEMORY;
2285 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2287 return NT_STATUS_NO_MEMORY;
2289 memcpy(r->array, blob->data, blob->length);
2290 r->size = blob->length;
2291 r->length = blob->length;
2294 return NT_STATUS_NO_MEMORY;
2299 return NT_STATUS_OK;
2302 /*************************************************************************
2304 *************************************************************************/
2306 static NTSTATUS get_user_info_1(TALLOC_CTX *mem_ctx,
2307 struct samr_UserInfo1 *r,
2309 DOM_SID *domain_sid)
2311 const DOM_SID *sid_group;
2312 uint32_t primary_gid;
2315 sid_group = pdb_get_group_sid(pw);
2318 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2319 DEBUG(0, ("get_user_info_1: User %s has Primary Group SID %s, \n"
2320 "which conflicts with the domain sid %s. Failing operation.\n",
2321 pdb_get_username(pw), sid_string_dbg(sid_group),
2322 sid_string_dbg(domain_sid)));
2323 return NT_STATUS_UNSUCCESSFUL;
2326 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2327 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2328 r->primary_gid = primary_gid;
2329 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2330 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2332 return NT_STATUS_OK;
2335 /*************************************************************************
2337 *************************************************************************/
2339 static NTSTATUS get_user_info_2(TALLOC_CTX *mem_ctx,
2340 struct samr_UserInfo2 *r,
2343 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2344 r->unknown.string = NULL;
2345 r->country_code = 0;
2348 return NT_STATUS_OK;
2351 /*************************************************************************
2353 *************************************************************************/
2355 static NTSTATUS get_user_info_3(TALLOC_CTX *mem_ctx,
2356 struct samr_UserInfo3 *r,
2358 DOM_SID *domain_sid)
2360 const DOM_SID *sid_user, *sid_group;
2361 uint32_t rid, primary_gid;
2363 sid_user = pdb_get_user_sid(pw);
2365 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2366 DEBUG(0, ("get_user_info_3: User %s has SID %s, \nwhich conflicts with "
2367 "the domain sid %s. Failing operation.\n",
2368 pdb_get_username(pw), sid_string_dbg(sid_user),
2369 sid_string_dbg(domain_sid)));
2370 return NT_STATUS_UNSUCCESSFUL;
2374 sid_group = pdb_get_group_sid(pw);
2377 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2378 DEBUG(0, ("get_user_info_3: User %s has Primary Group SID %s, \n"
2379 "which conflicts with the domain sid %s. Failing operation.\n",
2380 pdb_get_username(pw), sid_string_dbg(sid_group),
2381 sid_string_dbg(domain_sid)));
2382 return NT_STATUS_UNSUCCESSFUL;
2385 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2386 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2387 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2388 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2389 unix_to_nt_time(&r->force_password_change, pdb_get_pass_must_change_time(pw));
2391 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2392 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2393 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2394 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2395 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2396 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2397 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2399 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2401 r->primary_gid = primary_gid;
2402 r->acct_flags = pdb_get_acct_ctrl(pw);
2403 r->bad_password_count = pdb_get_bad_password_count(pw);
2404 r->logon_count = pdb_get_logon_count(pw);
2406 return NT_STATUS_OK;
2409 /*************************************************************************
2411 *************************************************************************/
2413 static NTSTATUS get_user_info_4(TALLOC_CTX *mem_ctx,
2414 struct samr_UserInfo4 *r,
2417 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2419 return NT_STATUS_OK;
2422 /*************************************************************************
2424 *************************************************************************/
2426 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2427 struct samr_UserInfo5 *r,
2429 DOM_SID *domain_sid)
2431 const DOM_SID *sid_user, *sid_group;
2432 uint32_t rid, primary_gid;
2434 sid_user = pdb_get_user_sid(pw);
2436 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2437 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2438 "the domain sid %s. Failing operation.\n",
2439 pdb_get_username(pw), sid_string_dbg(sid_user),
2440 sid_string_dbg(domain_sid)));
2441 return NT_STATUS_UNSUCCESSFUL;
2445 sid_group = pdb_get_group_sid(pw);
2448 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2449 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2450 "which conflicts with the domain sid %s. Failing operation.\n",
2451 pdb_get_username(pw), sid_string_dbg(sid_group),
2452 sid_string_dbg(domain_sid)));
2453 return NT_STATUS_UNSUCCESSFUL;
2456 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2457 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2458 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2459 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2461 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2462 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2463 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2464 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2465 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2466 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2467 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2468 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2470 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2472 r->primary_gid = primary_gid;
2473 r->acct_flags = pdb_get_acct_ctrl(pw);
2474 r->bad_password_count = pdb_get_bad_password_count(pw);
2475 r->logon_count = pdb_get_logon_count(pw);
2477 return NT_STATUS_OK;
2480 /*************************************************************************
2482 *************************************************************************/
2484 static NTSTATUS get_user_info_6(TALLOC_CTX *mem_ctx,
2485 struct samr_UserInfo6 *r,
2488 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2489 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2491 return NT_STATUS_OK;
2494 /*************************************************************************
2495 get_user_info_7. Safe. Only gives out account_name.
2496 *************************************************************************/
2498 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2499 struct samr_UserInfo7 *r,
2500 struct samu *smbpass)
2502 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2503 if (!r->account_name.string) {
2504 return NT_STATUS_NO_MEMORY;
2507 return NT_STATUS_OK;
2510 /*************************************************************************
2512 *************************************************************************/
2514 static NTSTATUS get_user_info_8(TALLOC_CTX *mem_ctx,
2515 struct samr_UserInfo8 *r,
2518 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2520 return NT_STATUS_OK;
2523 /*************************************************************************
2524 get_user_info_9. Only gives out primary group SID.
2525 *************************************************************************/
2527 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2528 struct samr_UserInfo9 *r,
2529 struct samu *smbpass)
2531 r->primary_gid = pdb_get_group_rid(smbpass);
2533 return NT_STATUS_OK;
2536 /*************************************************************************
2538 *************************************************************************/
2540 static NTSTATUS get_user_info_10(TALLOC_CTX *mem_ctx,
2541 struct samr_UserInfo10 *r,
2544 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2545 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2547 return NT_STATUS_OK;
2550 /*************************************************************************
2552 *************************************************************************/
2554 static NTSTATUS get_user_info_11(TALLOC_CTX *mem_ctx,
2555 struct samr_UserInfo11 *r,
2558 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2560 return NT_STATUS_OK;
2563 /*************************************************************************
2565 *************************************************************************/
2567 static NTSTATUS get_user_info_12(TALLOC_CTX *mem_ctx,
2568 struct samr_UserInfo12 *r,
2571 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2573 return NT_STATUS_OK;
2576 /*************************************************************************
2578 *************************************************************************/
2580 static NTSTATUS get_user_info_13(TALLOC_CTX *mem_ctx,
2581 struct samr_UserInfo13 *r,
2584 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2586 return NT_STATUS_OK;
2589 /*************************************************************************
2591 *************************************************************************/
2593 static NTSTATUS get_user_info_14(TALLOC_CTX *mem_ctx,
2594 struct samr_UserInfo14 *r,
2597 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2599 return NT_STATUS_OK;
2602 /*************************************************************************
2603 get_user_info_16. Safe. Only gives out acb bits.
2604 *************************************************************************/
2606 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2607 struct samr_UserInfo16 *r,
2608 struct samu *smbpass)
2610 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2612 return NT_STATUS_OK;
2615 /*************************************************************************
2617 *************************************************************************/
2619 static NTSTATUS get_user_info_17(TALLOC_CTX *mem_ctx,
2620 struct samr_UserInfo17 *r,
2623 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2625 return NT_STATUS_OK;
2628 /*************************************************************************
2629 get_user_info_18. OK - this is the killer as it gives out password info.
2630 Ensure that this is only allowed on an encrypted connection with a root
2632 *************************************************************************/
2634 static NTSTATUS get_user_info_18(pipes_struct *p,
2635 TALLOC_CTX *mem_ctx,
2636 struct samr_UserInfo18 *r,
2639 struct samu *smbpass=NULL;
2644 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2645 return NT_STATUS_ACCESS_DENIED;
2648 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2649 return NT_STATUS_ACCESS_DENIED;
2653 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2656 if ( !(smbpass = samu_new( mem_ctx )) ) {
2657 return NT_STATUS_NO_MEMORY;
2660 ret = pdb_getsampwsid(smbpass, user_sid);
2663 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2664 TALLOC_FREE(smbpass);
2665 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2668 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2670 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2671 TALLOC_FREE(smbpass);
2672 return NT_STATUS_ACCOUNT_DISABLED;
2675 r->lm_pwd_active = true;
2676 r->nt_pwd_active = true;
2677 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2678 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2679 r->password_expired = 0; /* FIXME */
2681 TALLOC_FREE(smbpass);
2683 return NT_STATUS_OK;
2686 /*************************************************************************
2688 *************************************************************************/
2690 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2691 struct samr_UserInfo20 *r,
2692 struct samu *sampass)
2694 const char *munged_dial = NULL;
2697 struct lsa_BinaryString *parameters = NULL;
2701 munged_dial = pdb_get_munged_dial(sampass);
2703 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2704 munged_dial, (int)strlen(munged_dial)));
2707 blob = base64_decode_data_blob(munged_dial);
2709 blob = data_blob_string_const_null("");
2712 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2713 data_blob_free(&blob);
2714 if (!NT_STATUS_IS_OK(status)) {
2718 r->parameters = *parameters;
2720 return NT_STATUS_OK;
2724 /*************************************************************************
2726 *************************************************************************/
2728 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2729 struct samr_UserInfo21 *r,
2731 DOM_SID *domain_sid)
2734 const DOM_SID *sid_user, *sid_group;
2735 uint32_t rid, primary_gid;
2736 NTTIME force_password_change;
2737 time_t must_change_time;
2738 struct lsa_BinaryString *parameters = NULL;
2739 const char *munged_dial = NULL;
2744 sid_user = pdb_get_user_sid(pw);
2746 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2747 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2748 "the domain sid %s. Failing operation.\n",
2749 pdb_get_username(pw), sid_string_dbg(sid_user),
2750 sid_string_dbg(domain_sid)));
2751 return NT_STATUS_UNSUCCESSFUL;
2755 sid_group = pdb_get_group_sid(pw);
2758 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2759 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2760 "which conflicts with the domain sid %s. Failing operation.\n",
2761 pdb_get_username(pw), sid_string_dbg(sid_group),
2762 sid_string_dbg(domain_sid)));
2763 return NT_STATUS_UNSUCCESSFUL;
2766 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2767 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2768 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2769 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2770 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2772 must_change_time = pdb_get_pass_must_change_time(pw);
2773 if (must_change_time == get_time_t_max()) {
2774 unix_to_nt_time_abs(&force_password_change, must_change_time);
2776 unix_to_nt_time(&force_password_change, must_change_time);
2779 munged_dial = pdb_get_munged_dial(pw);
2781 blob = base64_decode_data_blob(munged_dial);
2783 blob = data_blob_string_const_null("");
2786 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2787 data_blob_free(&blob);
2788 if (!NT_STATUS_IS_OK(status)) {
2792 r->force_password_change = force_password_change;
2794 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2795 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2796 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2797 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2798 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2799 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2800 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2801 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2802 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2804 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2805 r->parameters = *parameters;
2807 r->primary_gid = primary_gid;
2808 r->acct_flags = pdb_get_acct_ctrl(pw);
2809 r->bad_password_count = pdb_get_bad_password_count(pw);
2810 r->logon_count = pdb_get_logon_count(pw);
2811 r->fields_present = pdb_build_fields_present(pw);
2812 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2813 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2814 r->country_code = 0;
2816 r->lm_password_set = 0;
2817 r->nt_password_set = 0;
2822 Look at a user on a real NT4 PDC with usrmgr, press
2823 'ok'. Then you will see that fields_present is set to
2824 0x08f827fa. Look at the user immediately after that again,
2825 and you will see that 0x00fffff is returned. This solves
2826 the problem that you get access denied after having looked
2834 return NT_STATUS_OK;
2837 /*******************************************************************
2839 ********************************************************************/
2841 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2842 struct samr_QueryUserInfo *r)
2845 union samr_UserInfo *user_info = NULL;
2846 struct samr_user_info *uinfo;
2850 struct samu *pwd = NULL;
2852 uinfo = policy_handle_find(p, r->in.user_handle,
2853 SAMR_USER_ACCESS_GET_ATTRIBUTES, NULL,
2854 struct samr_user_info, &status);
2855 if (!NT_STATUS_IS_OK(status)) {
2859 domain_sid = uinfo->sid;
2861 sid_split_rid(&domain_sid, &rid);
2863 if (!sid_check_is_in_our_domain(&uinfo->sid))
2864 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2866 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2867 sid_string_dbg(&uinfo->sid)));
2869 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2871 return NT_STATUS_NO_MEMORY;
2874 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2876 if (!(pwd = samu_new(p->mem_ctx))) {
2877 return NT_STATUS_NO_MEMORY;
2881 ret = pdb_getsampwsid(pwd, &uinfo->sid);
2885 DEBUG(4,("User %s not found\n", sid_string_dbg(&uinfo->sid)));
2887 return NT_STATUS_NO_SUCH_USER;
2890 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2892 samr_clear_sam_passwd(pwd);
2894 switch (r->in.level) {
2896 status = get_user_info_1(p->mem_ctx, &user_info->info1, pwd, &domain_sid);
2899 status = get_user_info_2(p->mem_ctx, &user_info->info2, pwd);
2902 status = get_user_info_3(p->mem_ctx, &user_info->info3, pwd, &domain_sid);
2905 status = get_user_info_4(p->mem_ctx, &user_info->info4, pwd);
2908 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2911 status = get_user_info_6(p->mem_ctx, &user_info->info6, pwd);
2914 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2917 status = get_user_info_8(p->mem_ctx, &user_info->info8, pwd);
2920 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2923 status = get_user_info_10(p->mem_ctx, &user_info->info10, pwd);
2926 status = get_user_info_11(p->mem_ctx, &user_info->info11, pwd);
2929 status = get_user_info_12(p->mem_ctx, &user_info->info12, pwd);
2932 status = get_user_info_13(p->mem_ctx, &user_info->info13, pwd);
2935 status = get_user_info_14(p->mem_ctx, &user_info->info14, pwd);
2938 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2941 status = get_user_info_17(p->mem_ctx, &user_info->info17, pwd);
2944 /* level 18 is special */
2945 status = get_user_info_18(p, p->mem_ctx, &user_info->info18,
2949 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2952 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2955 status = NT_STATUS_INVALID_INFO_CLASS;
2961 *r->out.info = user_info;
2963 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2968 /****************************************************************
2969 ****************************************************************/
2971 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2972 struct samr_QueryUserInfo2 *r)
2974 struct samr_QueryUserInfo u;
2976 u.in.user_handle = r->in.user_handle;
2977 u.in.level = r->in.level;
2978 u.out.info = r->out.info;
2980 return _samr_QueryUserInfo(p, &u);
2983 /*******************************************************************
2984 _samr_GetGroupsForUser
2985 ********************************************************************/
2987 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2988 struct samr_GetGroupsForUser *r)
2990 struct samr_user_info *uinfo;
2991 struct samu *sam_pass=NULL;
2993 struct samr_RidWithAttribute dom_gid;
2994 struct samr_RidWithAttribute *gids = NULL;
2995 uint32 primary_group_rid;
2996 size_t num_groups = 0;
3001 bool success = False;
3003 struct samr_RidWithAttributeArray *rids = NULL;
3006 * from the SID in the request:
3007 * we should send back the list of DOMAIN GROUPS
3008 * the user is a member of
3010 * and only the DOMAIN GROUPS
3011 * no ALIASES !!! neither aliases of the domain
3012 * nor aliases of the builtin SID
3017 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
3019 uinfo = policy_handle_find(p, r->in.user_handle,
3020 SAMR_USER_ACCESS_GET_GROUPS, NULL,
3021 struct samr_user_info, &result);
3022 if (!NT_STATUS_IS_OK(result)) {
3026 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
3028 return NT_STATUS_NO_MEMORY;
3031 if (!sid_check_is_in_our_domain(&uinfo->sid))
3032 return NT_STATUS_OBJECT_TYPE_MISMATCH;
3034 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
3035 return NT_STATUS_NO_MEMORY;
3039 ret = pdb_getsampwsid(sam_pass, &uinfo->sid);
3043 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
3044 sid_string_dbg(&uinfo->sid)));
3045 return NT_STATUS_NO_SUCH_USER;
3050 /* make both calls inside the root block */
3052 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
3053 &sids, &unix_gids, &num_groups);
3054 if ( NT_STATUS_IS_OK(result) ) {
3055 success = sid_peek_check_rid(get_global_sam_sid(),
3056 pdb_get_group_sid(sam_pass),
3057 &primary_group_rid);
3061 if (!NT_STATUS_IS_OK(result)) {
3062 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
3063 sid_string_dbg(&uinfo->sid)));
3068 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
3069 sid_string_dbg(pdb_get_group_sid(sam_pass)),
3070 pdb_get_username(sam_pass)));
3071 TALLOC_FREE(sam_pass);
3072 return NT_STATUS_INTERNAL_DB_CORRUPTION;
3078 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
3080 dom_gid.rid = primary_group_rid;
3081 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
3083 for (i=0; i<num_groups; i++) {
3085 if (!sid_peek_check_rid(get_global_sam_sid(),
3086 &(sids[i]), &dom_gid.rid)) {
3087 DEBUG(10, ("Found sid %s not in our domain\n",
3088 sid_string_dbg(&sids[i])));
3092 if (dom_gid.rid == primary_group_rid) {
3093 /* We added the primary group directly from the
3094 * sam_account. The other SIDs are unique from
3095 * enum_group_memberships */
3099 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
3102 rids->count = num_gids;
3105 *r->out.rids = rids;
3107 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
3112 /*******************************************************************
3113 _samr_QueryDomainInfo
3114 ********************************************************************/
3116 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
3117 struct samr_QueryDomainInfo *r)
3119 NTSTATUS status = NT_STATUS_OK;
3120 struct samr_domain_info *dinfo;
3121 union samr_DomainInfo *dom_info;
3122 time_t u_expire, u_min_age;
3124 time_t u_lock_duration, u_reset_time;
3127 uint32 account_policy_temp;
3132 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
3134 dinfo = policy_handle_find(p, r->in.domain_handle,
3135 SAMR_ACCESS_LOOKUP_DOMAIN, NULL,
3136 struct samr_domain_info, &status);
3137 if (!NT_STATUS_IS_OK(status)) {
3141 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
3143 return NT_STATUS_NO_MEMORY;
3146 switch (r->in.level) {
3153 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
3154 &account_policy_temp);
3155 dom_info->info1.min_password_length = account_policy_temp;
3157 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
3158 dom_info->info1.password_history_length = account_policy_temp;
3160 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
3161 &dom_info->info1.password_properties);
3163 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
3164 u_expire = account_policy_temp;
3166 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
3167 u_min_age = account_policy_temp;
3173 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
3174 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
3176 if (lp_check_password_script() && *lp_check_password_script()) {
3177 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
3187 dom_info->general.num_users = count_sam_users(
3188 dinfo->disp_info, ACB_NORMAL);
3189 dom_info->general.num_groups = count_sam_groups(
3191 dom_info->general.num_aliases = count_sam_aliases(
3194 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
3196 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
3198 if (!pdb_get_seq_num(&seq_num))
3199 seq_num = time(NULL);
3205 server_role = ROLE_DOMAIN_PDC;
3206 if (lp_server_role() == ROLE_DOMAIN_BDC)
3207 server_role = ROLE_DOMAIN_BDC;
3209 dom_info->general.oem_information.string = lp_serverstring();
3210 dom_info->general.domain_name.string = lp_workgroup();
3211 dom_info->general.primary.string = global_myname();
3212 dom_info->general.sequence_num = seq_num;
3213 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
3214 dom_info->general.role = server_role;
3215 dom_info->general.unknown3 = 1;
3226 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
3227 u_logout = (time_t)ul;