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.
37 #define DBGC_CLASS DBGC_RPC_SRV
39 #define SAMR_USR_RIGHTS_WRITE_PW \
40 ( READ_CONTROL_ACCESS | \
41 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
42 SAMR_USER_ACCESS_SET_LOC_COM)
43 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
44 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
46 #define DISP_INFO_CACHE_TIMEOUT 10
48 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
49 #define MAX_SAM_ENTRIES_W95 50
51 typedef struct disp_info {
52 DOM_SID sid; /* identify which domain this is. */
53 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
54 struct pdb_search *users; /* querydispinfo 1 and 4 */
55 struct pdb_search *machines; /* querydispinfo 2 */
56 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
57 struct pdb_search *aliases; /* enumaliases */
60 struct pdb_search *enum_users; /* enumusers with a mask */
62 struct timed_event *cache_timeout_event; /* cache idle timeout
66 /* We keep a static list of these by SID as modern clients close down
67 all resources between each request in a complete enumeration. */
70 /* for use by the \PIPE\samr policy */
72 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
73 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
78 static const struct generic_mapping sam_generic_mapping = {
79 GENERIC_RIGHTS_SAM_READ,
80 GENERIC_RIGHTS_SAM_WRITE,
81 GENERIC_RIGHTS_SAM_EXECUTE,
82 GENERIC_RIGHTS_SAM_ALL_ACCESS};
83 static const struct generic_mapping dom_generic_mapping = {
84 GENERIC_RIGHTS_DOMAIN_READ,
85 GENERIC_RIGHTS_DOMAIN_WRITE,
86 GENERIC_RIGHTS_DOMAIN_EXECUTE,
87 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
88 static const struct generic_mapping usr_generic_mapping = {
89 GENERIC_RIGHTS_USER_READ,
90 GENERIC_RIGHTS_USER_WRITE,
91 GENERIC_RIGHTS_USER_EXECUTE,
92 GENERIC_RIGHTS_USER_ALL_ACCESS};
93 static const struct generic_mapping usr_nopwchange_generic_mapping = {
94 GENERIC_RIGHTS_USER_READ,
95 GENERIC_RIGHTS_USER_WRITE,
96 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
97 GENERIC_RIGHTS_USER_ALL_ACCESS};
98 static const struct generic_mapping grp_generic_mapping = {
99 GENERIC_RIGHTS_GROUP_READ,
100 GENERIC_RIGHTS_GROUP_WRITE,
101 GENERIC_RIGHTS_GROUP_EXECUTE,
102 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
103 static const struct generic_mapping ali_generic_mapping = {
104 GENERIC_RIGHTS_ALIAS_READ,
105 GENERIC_RIGHTS_ALIAS_WRITE,
106 GENERIC_RIGHTS_ALIAS_EXECUTE,
107 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
109 /*******************************************************************
110 *******************************************************************/
112 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
113 const struct generic_mapping *map,
114 DOM_SID *sid, uint32 sid_access )
116 DOM_SID domadmin_sid;
117 SEC_ACE ace[5]; /* at most 5 entries */
122 /* basic access for Everyone */
124 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
125 map->generic_execute | map->generic_read, 0);
127 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
129 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
130 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
131 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
132 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
134 /* Add Full Access for Domain Admins if we are a DC */
137 sid_copy( &domadmin_sid, get_global_sam_sid() );
138 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
139 init_sec_ace(&ace[i++], &domadmin_sid,
140 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
143 /* if we have a sid, give it some special access */
146 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
149 /* create the security descriptor */
151 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
152 return NT_STATUS_NO_MEMORY;
154 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
155 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
156 psa, sd_size)) == NULL)
157 return NT_STATUS_NO_MEMORY;
162 /*******************************************************************
163 Checks if access to an object should be granted, and returns that
164 level of access for further checks.
165 ********************************************************************/
167 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
168 SE_PRIV *rights, uint32 rights_mask,
169 uint32 des_access, uint32 *acc_granted,
172 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
173 uint32 saved_mask = 0;
175 /* check privileges; certain SAM access bits should be overridden
176 by privileges (mostly having to do with creating/modifying/deleting
179 if ( rights && user_has_any_privilege( token, rights ) ) {
181 saved_mask = (des_access & rights_mask);
182 des_access &= ~saved_mask;
184 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
189 /* check the security descriptor first */
191 status = se_access_check(psd, token, des_access, acc_granted);
192 if (NT_STATUS_IS_OK(status)) {
196 /* give root a free pass */
198 if ( geteuid() == sec_initial_uid() ) {
200 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
201 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
203 *acc_granted = des_access;
205 status = NT_STATUS_OK;
211 /* add in any bits saved during the privilege check (only
212 matters is status is ok) */
214 *acc_granted |= rights_mask;
216 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
217 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
218 des_access, *acc_granted));
223 /*******************************************************************
224 Checks if access to a function can be granted
225 ********************************************************************/
227 static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_required, const char *debug)
229 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
230 debug, acc_granted, acc_required));
232 /* check the security descriptor first */
234 if ( (acc_granted&acc_required) == acc_required )
237 /* give root a free pass */
239 if (geteuid() == sec_initial_uid()) {
241 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
242 debug, acc_granted, acc_required));
243 DEBUGADD(4,("but overwritten by euid == 0\n"));
248 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
249 debug, acc_granted, acc_required));
251 return NT_STATUS_ACCESS_DENIED;
254 /*******************************************************************
255 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
256 ********************************************************************/
258 static void map_max_allowed_access(const NT_USER_TOKEN *token,
259 uint32_t *pacc_requested)
261 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
264 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
266 /* At least try for generic read. */
267 *pacc_requested = GENERIC_READ_ACCESS;
269 /* root gets anything. */
270 if (geteuid() == sec_initial_uid()) {
271 *pacc_requested |= GENERIC_ALL_ACCESS;
275 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
277 if (is_sid_in_token(token, &global_sid_Builtin_Administrators) ||
278 is_sid_in_token(token, &global_sid_Builtin_Account_Operators)) {
279 *pacc_requested |= GENERIC_ALL_ACCESS;
283 /* Full access for DOMAIN\Domain Admins. */
285 DOM_SID domadmin_sid;
286 sid_copy( &domadmin_sid, get_global_sam_sid() );
287 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
288 if (is_sid_in_token(token, &domadmin_sid)) {
289 *pacc_requested |= GENERIC_ALL_ACCESS;
293 /* TODO ! Check privileges. */
296 /*******************************************************************
297 Fetch or create a dispinfo struct.
298 ********************************************************************/
300 static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid)
303 * We do a static cache for DISP_INFO's here. Explanation can be found
304 * in Jeremy's checkin message to r11793:
306 * Fix the SAMR cache so it works across completely insane
307 * client behaviour (ie.:
308 * open pipe/open SAMR handle/enumerate 0 - 1024
309 * close SAMR handle, close pipe.
310 * open pipe/open SAMR handle/enumerate 1024 - 2048...
311 * close SAMR handle, close pipe.
312 * And on ad-nausium. Amazing.... probably object-oriented
313 * client side programming in action yet again.
314 * This change should *massively* improve performance when
315 * enumerating users from an LDAP database.
318 * "Our" and the builtin domain are the only ones where we ever
319 * enumerate stuff, so just cache 2 entries.
322 static struct disp_info *builtin_dispinfo;
323 static struct disp_info *domain_dispinfo;
325 /* There are two cases to consider here:
326 1) The SID is a domain SID and we look for an equality match, or
327 2) This is an account SID and so we return the DISP_INFO* for our
334 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
336 * Necessary only once, but it does not really hurt.
338 if (builtin_dispinfo == NULL) {
339 builtin_dispinfo = talloc_zero(
340 talloc_autofree_context(), struct disp_info);
341 if (builtin_dispinfo == NULL) {
345 sid_copy(&builtin_dispinfo->sid, &global_sid_Builtin);
347 return builtin_dispinfo;
350 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
352 * Necessary only once, but it does not really hurt.
354 if (domain_dispinfo == NULL) {
355 domain_dispinfo = talloc_zero(
356 talloc_autofree_context(), struct disp_info);
357 if (domain_dispinfo == NULL) {
361 sid_copy(&domain_dispinfo->sid, get_global_sam_sid());
363 return domain_dispinfo;
369 /*******************************************************************
370 Create a samr_info struct.
371 ********************************************************************/
373 static int samr_info_destructor(struct samr_info *info);
375 static struct samr_info *get_samr_info_by_sid(TALLOC_CTX *mem_ctx,
378 struct samr_info *info;
382 sid_to_fstring(sid_str, psid);
384 fstrcpy(sid_str,"(NULL)");
387 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL) {
390 talloc_set_destructor(info, samr_info_destructor);
392 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
394 sid_copy( &info->sid, psid);
395 info->builtin_domain = sid_check_is_builtin(psid);
397 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
398 info->builtin_domain = False;
401 info->disp_info = get_samr_dispinfo_by_sid(psid);
406 /*******************************************************************
407 Function to free the per SID data.
408 ********************************************************************/
410 static void free_samr_cache(DISP_INFO *disp_info)
412 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
413 sid_string_dbg(&disp_info->sid)));
415 /* We need to become root here because the paged search might have to
416 * tell the LDAP server we're not interested in the rest anymore. */
420 TALLOC_FREE(disp_info->users);
421 TALLOC_FREE(disp_info->machines);
422 TALLOC_FREE(disp_info->groups);
423 TALLOC_FREE(disp_info->aliases);
424 TALLOC_FREE(disp_info->enum_users);
429 static int samr_info_destructor(struct samr_info *info)
431 /* Only free the dispinfo cache if no one bothered to set up
434 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
435 free_samr_cache(info->disp_info);
440 /*******************************************************************
441 Idle event handler. Throw away the disp info cache.
442 ********************************************************************/
444 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
445 struct timed_event *te,
449 DISP_INFO *disp_info = (DISP_INFO *)private_data;
451 TALLOC_FREE(disp_info->cache_timeout_event);
453 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
455 free_samr_cache(disp_info);
458 /*******************************************************************
459 Setup cache removal idle event handler.
460 ********************************************************************/
462 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
464 /* Remove any pending timeout and update. */
466 TALLOC_FREE(disp_info->cache_timeout_event);
468 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
469 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
470 (unsigned int)secs_fromnow ));
472 disp_info->cache_timeout_event = event_add_timed(
473 smbd_event_context(), NULL,
474 timeval_current_ofs(secs_fromnow, 0),
475 disp_info_cache_idle_timeout_handler, (void *)disp_info);
478 /*******************************************************************
479 Force flush any cache. We do this on any samr_set_xxx call.
480 We must also remove the timeout handler.
481 ********************************************************************/
483 static void force_flush_samr_cache(DISP_INFO *disp_info)
485 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
489 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
490 TALLOC_FREE(disp_info->cache_timeout_event);
491 free_samr_cache(disp_info);
494 /*******************************************************************
495 Ensure password info is never given out. Paranioa... JRA.
496 ********************************************************************/
498 static void samr_clear_sam_passwd(struct samu *sam_pass)
504 /* These now zero out the old password */
506 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
507 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
510 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
512 struct samr_displayentry *entry;
514 if (info->builtin_domain) {
515 /* No users in builtin. */
519 if (info->users == NULL) {
520 info->users = pdb_search_users(info, acct_flags);
521 if (info->users == NULL) {
525 /* Fetch the last possible entry, thus trigger an enumeration */
526 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
528 /* Ensure we cache this enumeration. */
529 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
531 return info->users->num_entries;
534 static uint32 count_sam_groups(struct disp_info *info)
536 struct samr_displayentry *entry;
538 if (info->builtin_domain) {
539 /* No groups in builtin. */
543 if (info->groups == NULL) {
544 info->groups = pdb_search_groups(info);
545 if (info->groups == NULL) {
549 /* Fetch the last possible entry, thus trigger an enumeration */
550 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
552 /* Ensure we cache this enumeration. */
553 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
555 return info->groups->num_entries;
558 static uint32 count_sam_aliases(struct disp_info *info)
560 struct samr_displayentry *entry;
562 if (info->aliases == NULL) {
563 info->aliases = pdb_search_aliases(info, &info->sid);
564 if (info->aliases == NULL) {
568 /* Fetch the last possible entry, thus trigger an enumeration */
569 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
571 /* Ensure we cache this enumeration. */
572 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
574 return info->aliases->num_entries;
577 /*******************************************************************
579 ********************************************************************/
581 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
583 if (!close_policy_hnd(p, r->in.handle)) {
584 return NT_STATUS_INVALID_HANDLE;
587 ZERO_STRUCTP(r->out.handle);
592 /*******************************************************************
594 ********************************************************************/
596 NTSTATUS _samr_OpenDomain(pipes_struct *p,
597 struct samr_OpenDomain *r)
599 struct samr_info *info;
600 SEC_DESC *psd = NULL;
602 uint32 des_access = r->in.access_mask;
607 /* find the connection policy handle. */
609 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
610 return NT_STATUS_INVALID_HANDLE;
612 status = access_check_samr_function(info->acc_granted,
613 SAMR_ACCESS_OPEN_DOMAIN,
614 "_samr_OpenDomain" );
616 if ( !NT_STATUS_IS_OK(status) )
619 /*check if access can be granted as requested by client. */
620 map_max_allowed_access(p->server_info->ptok, &des_access);
622 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
623 se_map_generic( &des_access, &dom_generic_mapping );
625 se_priv_copy( &se_rights, &se_machine_account );
626 se_priv_add( &se_rights, &se_add_users );
628 status = access_check_samr_object( psd, p->server_info->ptok,
629 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
630 &acc_granted, "_samr_OpenDomain" );
632 if ( !NT_STATUS_IS_OK(status) )
635 if (!sid_check_is_domain(r->in.sid) &&
636 !sid_check_is_builtin(r->in.sid)) {
637 return NT_STATUS_NO_SUCH_DOMAIN;
640 /* associate the domain SID with the (unique) handle. */
641 if ((info = get_samr_info_by_sid(p->mem_ctx, r->in.sid))==NULL)
642 return NT_STATUS_NO_MEMORY;
643 info->acc_granted = acc_granted;
645 /* get a (unique) handle. open a policy on it. */
646 if (!create_policy_hnd(p, r->out.domain_handle, info))
647 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
649 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
654 /*******************************************************************
656 ********************************************************************/
658 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
659 struct samr_GetUserPwInfo *r)
661 struct samr_info *info = NULL;
662 enum lsa_SidType sid_type;
663 uint32_t min_password_length = 0;
664 uint32_t password_properties = 0;
668 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
670 /* find the policy handle. open a policy on it. */
671 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info)) {
672 return NT_STATUS_INVALID_HANDLE;
675 status = access_check_samr_function(info->acc_granted,
676 SAMR_USER_ACCESS_GET_ATTRIBUTES,
677 "_samr_GetUserPwInfo" );
678 if (!NT_STATUS_IS_OK(status)) {
682 if (!sid_check_is_in_our_domain(&info->sid)) {
683 return NT_STATUS_OBJECT_TYPE_MISMATCH;
687 ret = lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, &sid_type);
690 return NT_STATUS_NO_SUCH_USER;
696 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
697 &min_password_length);
698 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
699 &password_properties);
702 if (lp_check_password_script() && *lp_check_password_script()) {
703 password_properties |= DOMAIN_PASSWORD_COMPLEX;
711 r->out.info->min_password_length = min_password_length;
712 r->out.info->password_properties = password_properties;
714 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
719 /*******************************************************************
720 ********************************************************************/
722 static bool get_lsa_policy_samr_sid( pipes_struct *p, struct policy_handle *pol,
723 DOM_SID *sid, uint32 *acc_granted,
724 DISP_INFO **ppdisp_info)
726 struct samr_info *info = NULL;
728 /* find the policy handle. open a policy on it. */
729 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
736 *acc_granted = info->acc_granted;
738 *ppdisp_info = info->disp_info;
744 /*******************************************************************
746 ********************************************************************/
748 NTSTATUS _samr_SetSecurity(pipes_struct *p,
749 struct samr_SetSecurity *r)
752 uint32 acc_granted, i;
755 struct samu *sampass=NULL;
758 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
759 return NT_STATUS_INVALID_HANDLE;
761 if (!(sampass = samu_new( p->mem_ctx))) {
762 DEBUG(0,("No memory!\n"));
763 return NT_STATUS_NO_MEMORY;
766 /* get the user record */
768 ret = pdb_getsampwsid(sampass, &pol_sid);
772 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
773 TALLOC_FREE(sampass);
774 return NT_STATUS_INVALID_HANDLE;
777 dacl = r->in.sdbuf->sd->dacl;
778 for (i=0; i < dacl->num_aces; i++) {
779 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
780 ret = pdb_set_pass_can_change(sampass,
781 (dacl->aces[i].access_mask &
782 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
789 TALLOC_FREE(sampass);
790 return NT_STATUS_ACCESS_DENIED;
793 status = access_check_samr_function(acc_granted,
794 SAMR_USER_ACCESS_SET_ATTRIBUTES,
795 "_samr_SetSecurity");
796 if (NT_STATUS_IS_OK(status)) {
798 status = pdb_update_sam_account(sampass);
802 TALLOC_FREE(sampass);
807 /*******************************************************************
808 build correct perms based on policies and password times for _samr_query_sec_obj
809 *******************************************************************/
810 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
812 struct samu *sampass=NULL;
815 if ( !(sampass = samu_new( mem_ctx )) ) {
816 DEBUG(0,("No memory!\n"));
821 ret = pdb_getsampwsid(sampass, user_sid);
825 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
826 TALLOC_FREE(sampass);
830 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
832 if (pdb_get_pass_can_change(sampass)) {
833 TALLOC_FREE(sampass);
836 TALLOC_FREE(sampass);
841 /*******************************************************************
843 ********************************************************************/
845 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
846 struct samr_QuerySecurity *r)
850 SEC_DESC * psd = NULL;
855 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
856 return NT_STATUS_INVALID_HANDLE;
858 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
859 sid_string_dbg(&pol_sid)));
861 status = access_check_samr_function(acc_granted,
862 STD_RIGHT_READ_CONTROL_ACCESS,
863 "_samr_QuerySecurity");
864 if (!NT_STATUS_IS_OK(status)) {
868 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
870 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
871 if (pol_sid.sid_rev_num == 0) {
872 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
873 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
874 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
875 /* check if it is our domain SID */
876 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
877 "with SID: %s\n", sid_string_dbg(&pol_sid)));
878 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
879 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
880 /* check if it is the Builtin Domain */
881 /* TODO: Builtin probably needs a different SD with restricted write access*/
882 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
883 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
884 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
885 } else if (sid_check_is_in_our_domain(&pol_sid) ||
886 sid_check_is_in_builtin(&pol_sid)) {
887 /* TODO: different SDs have to be generated for aliases groups and users.
888 Currently all three get a default user SD */
889 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
890 "with SID: %s\n", sid_string_dbg(&pol_sid)));
891 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
892 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
893 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
895 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
896 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
899 return NT_STATUS_OBJECT_TYPE_MISMATCH;
902 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
903 return NT_STATUS_NO_MEMORY;
908 /*******************************************************************
909 makes a SAM_ENTRY / UNISTR2* structure from a user list.
910 ********************************************************************/
912 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
913 struct samr_SamEntry **sam_pp,
914 uint32_t num_entries,
916 struct samr_displayentry *entries)
919 struct samr_SamEntry *sam;
923 if (num_entries == 0) {
927 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
929 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
930 return NT_STATUS_NO_MEMORY;
933 for (i = 0; i < num_entries; i++) {
936 * usrmgr expects a non-NULL terminated string with
937 * trust relationships
939 if (entries[i].acct_flags & ACB_DOMTRUST) {
940 init_unistr2(&uni_temp_name, entries[i].account_name,
943 init_unistr2(&uni_temp_name, entries[i].account_name,
947 init_lsa_String(&sam[i].name, entries[i].account_name);
948 sam[i].idx = entries[i].rid;
956 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
958 /*******************************************************************
959 _samr_EnumDomainUsers
960 ********************************************************************/
962 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
963 struct samr_EnumDomainUsers *r)
966 struct samr_info *info = NULL;
968 uint32 enum_context = *r->in.resume_handle;
969 enum remote_arch_types ra_type = get_remote_arch();
970 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
971 uint32 max_entries = max_sam_entries;
972 struct samr_displayentry *entries = NULL;
973 struct samr_SamArray *samr_array = NULL;
974 struct samr_SamEntry *samr_entries = NULL;
976 /* find the policy handle. open a policy on it. */
977 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
978 return NT_STATUS_INVALID_HANDLE;
980 status = access_check_samr_function(info->acc_granted,
981 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
982 "_samr_EnumDomainUsers");
983 if (!NT_STATUS_IS_OK(status)) {
987 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
989 if (info->builtin_domain) {
990 /* No users in builtin. */
991 *r->out.resume_handle = *r->in.resume_handle;
992 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
996 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
998 return NT_STATUS_NO_MEMORY;
1000 *r->out.sam = samr_array;
1006 if ((info->disp_info->enum_users != NULL) &&
1007 (info->disp_info->enum_acb_mask != r->in.acct_flags)) {
1008 TALLOC_FREE(info->disp_info->enum_users);
1011 if (info->disp_info->enum_users == NULL) {
1012 info->disp_info->enum_users = pdb_search_users(
1013 info->disp_info, r->in.acct_flags);
1014 info->disp_info->enum_acb_mask = r->in.acct_flags;
1017 if (info->disp_info->enum_users == NULL) {
1018 /* END AS ROOT !!!! */
1020 return NT_STATUS_ACCESS_DENIED;
1023 num_account = pdb_search_entries(info->disp_info->enum_users,
1024 enum_context, max_entries,
1027 /* END AS ROOT !!!! */
1031 if (num_account == 0) {
1032 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1033 "total entries\n"));
1034 *r->out.resume_handle = *r->in.resume_handle;
1035 return NT_STATUS_OK;
1038 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
1039 num_account, enum_context,
1041 if (!NT_STATUS_IS_OK(status)) {
1045 if (max_entries <= num_account) {
1046 status = STATUS_MORE_ENTRIES;
1048 status = NT_STATUS_OK;
1051 /* Ensure we cache this enumeration. */
1052 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1054 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
1056 samr_array->count = num_account;
1057 samr_array->entries = samr_entries;
1059 *r->out.resume_handle = *r->in.resume_handle + num_account;
1060 *r->out.num_entries = num_account;
1062 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1067 /*******************************************************************
1068 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1069 ********************************************************************/
1071 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1072 struct samr_SamEntry **sam_pp,
1073 uint32_t num_sam_entries,
1074 struct samr_displayentry *entries)
1076 struct samr_SamEntry *sam;
1081 if (num_sam_entries == 0) {
1085 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1090 for (i = 0; i < num_sam_entries; i++) {
1092 * JRA. I think this should include the null. TNG does not.
1094 init_lsa_String(&sam[i].name, entries[i].account_name);
1095 sam[i].idx = entries[i].rid;
1101 /*******************************************************************
1102 _samr_EnumDomainGroups
1103 ********************************************************************/
1105 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1106 struct samr_EnumDomainGroups *r)
1109 struct samr_info *info = NULL;
1110 struct samr_displayentry *groups;
1112 struct samr_SamArray *samr_array = NULL;
1113 struct samr_SamEntry *samr_entries = NULL;
1115 /* find the policy handle. open a policy on it. */
1116 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1117 return NT_STATUS_INVALID_HANDLE;
1119 status = access_check_samr_function(info->acc_granted,
1120 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1121 "_samr_EnumDomainGroups");
1122 if (!NT_STATUS_IS_OK(status)) {
1126 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1128 if (info->builtin_domain) {
1129 /* No groups in builtin. */
1130 *r->out.resume_handle = *r->in.resume_handle;
1131 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1135 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1137 return NT_STATUS_NO_MEMORY;
1140 /* the domain group array is being allocated in the function below */
1144 if (info->disp_info->groups == NULL) {
1145 info->disp_info->groups = pdb_search_groups(info->disp_info);
1147 if (info->disp_info->groups == NULL) {
1149 return NT_STATUS_ACCESS_DENIED;
1153 num_groups = pdb_search_entries(info->disp_info->groups,
1154 *r->in.resume_handle,
1155 MAX_SAM_ENTRIES, &groups);
1158 /* Ensure we cache this enumeration. */
1159 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1161 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1162 num_groups, groups);
1164 samr_array->count = num_groups;
1165 samr_array->entries = samr_entries;
1167 *r->out.sam = samr_array;
1168 *r->out.num_entries = num_groups;
1169 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1171 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1176 /*******************************************************************
1177 _samr_EnumDomainAliases
1178 ********************************************************************/
1180 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1181 struct samr_EnumDomainAliases *r)
1184 struct samr_info *info;
1185 struct samr_displayentry *aliases;
1186 uint32 num_aliases = 0;
1187 struct samr_SamArray *samr_array = NULL;
1188 struct samr_SamEntry *samr_entries = NULL;
1190 /* find the policy handle. open a policy on it. */
1191 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1192 return NT_STATUS_INVALID_HANDLE;
1194 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1195 sid_string_dbg(&info->sid)));
1197 status = access_check_samr_function(info->acc_granted,
1198 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1199 "_samr_EnumDomainAliases");
1200 if (!NT_STATUS_IS_OK(status)) {
1204 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1206 return NT_STATUS_NO_MEMORY;
1211 if (info->disp_info->aliases == NULL) {
1212 info->disp_info->aliases = pdb_search_aliases(
1213 info->disp_info, &info->sid);
1214 if (info->disp_info->aliases == NULL) {
1216 return NT_STATUS_ACCESS_DENIED;
1220 num_aliases = pdb_search_entries(info->disp_info->aliases,
1221 *r->in.resume_handle,
1222 MAX_SAM_ENTRIES, &aliases);
1225 /* Ensure we cache this enumeration. */
1226 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1228 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1229 num_aliases, aliases);
1231 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1233 samr_array->count = num_aliases;
1234 samr_array->entries = samr_entries;
1236 *r->out.sam = samr_array;
1237 *r->out.num_entries = num_aliases;
1238 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1243 /*******************************************************************
1244 inits a samr_DispInfoGeneral structure.
1245 ********************************************************************/
1247 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1248 struct samr_DispInfoGeneral *r,
1249 uint32_t num_entries,
1251 struct samr_displayentry *entries)
1255 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1257 if (num_entries == 0) {
1258 return NT_STATUS_OK;
1261 r->count = num_entries;
1263 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1265 return NT_STATUS_NO_MEMORY;
1268 for (i = 0; i < num_entries ; i++) {
1270 init_lsa_String(&r->entries[i].account_name,
1271 entries[i].account_name);
1273 init_lsa_String(&r->entries[i].description,
1274 entries[i].description);
1276 init_lsa_String(&r->entries[i].full_name,
1277 entries[i].fullname);
1279 r->entries[i].rid = entries[i].rid;
1280 r->entries[i].acct_flags = entries[i].acct_flags;
1281 r->entries[i].idx = start_idx+i+1;
1284 return NT_STATUS_OK;
1287 /*******************************************************************
1288 inits a samr_DispInfoFull structure.
1289 ********************************************************************/
1291 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1292 struct samr_DispInfoFull *r,
1293 uint32_t num_entries,
1295 struct samr_displayentry *entries)
1299 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1301 if (num_entries == 0) {
1302 return NT_STATUS_OK;
1305 r->count = num_entries;
1307 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1309 return NT_STATUS_NO_MEMORY;
1312 for (i = 0; i < num_entries ; i++) {
1314 init_lsa_String(&r->entries[i].account_name,
1315 entries[i].account_name);
1317 init_lsa_String(&r->entries[i].description,
1318 entries[i].description);
1320 r->entries[i].rid = entries[i].rid;
1321 r->entries[i].acct_flags = entries[i].acct_flags;
1322 r->entries[i].idx = start_idx+i+1;
1325 return NT_STATUS_OK;
1328 /*******************************************************************
1329 inits a samr_DispInfoFullGroups structure.
1330 ********************************************************************/
1332 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1333 struct samr_DispInfoFullGroups *r,
1334 uint32_t num_entries,
1336 struct samr_displayentry *entries)
1340 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1342 if (num_entries == 0) {
1343 return NT_STATUS_OK;
1346 r->count = num_entries;
1348 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1350 return NT_STATUS_NO_MEMORY;
1353 for (i = 0; i < num_entries ; i++) {
1355 init_lsa_String(&r->entries[i].account_name,
1356 entries[i].account_name);
1358 init_lsa_String(&r->entries[i].description,
1359 entries[i].description);
1361 r->entries[i].rid = entries[i].rid;
1362 r->entries[i].acct_flags = entries[i].acct_flags;
1363 r->entries[i].idx = start_idx+i+1;
1366 return NT_STATUS_OK;
1369 /*******************************************************************
1370 inits a samr_DispInfoAscii structure.
1371 ********************************************************************/
1373 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1374 struct samr_DispInfoAscii *r,
1375 uint32_t num_entries,
1377 struct samr_displayentry *entries)
1381 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1383 if (num_entries == 0) {
1384 return NT_STATUS_OK;
1387 r->count = num_entries;
1389 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1391 return NT_STATUS_NO_MEMORY;
1394 for (i = 0; i < num_entries ; i++) {
1396 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1397 entries[i].account_name);
1399 r->entries[i].idx = start_idx+i+1;
1402 return NT_STATUS_OK;
1405 /*******************************************************************
1406 inits a samr_DispInfoAscii structure.
1407 ********************************************************************/
1409 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1410 struct samr_DispInfoAscii *r,
1411 uint32_t num_entries,
1413 struct samr_displayentry *entries)
1417 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1419 if (num_entries == 0) {
1420 return NT_STATUS_OK;
1423 r->count = num_entries;
1425 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1427 return NT_STATUS_NO_MEMORY;
1430 for (i = 0; i < num_entries ; i++) {
1432 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1433 entries[i].account_name);
1435 r->entries[i].idx = start_idx+i+1;
1438 return NT_STATUS_OK;
1441 /*******************************************************************
1442 _samr_QueryDisplayInfo
1443 ********************************************************************/
1445 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1446 struct samr_QueryDisplayInfo *r)
1449 struct samr_info *info = NULL;
1450 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1452 uint32 max_entries = r->in.max_entries;
1453 uint32 enum_context = r->in.start_idx;
1454 uint32 max_size = r->in.buf_size;
1456 union samr_DispInfo *disp_info = r->out.info;
1458 uint32 temp_size=0, total_data_size=0;
1459 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1460 uint32 num_account = 0;
1461 enum remote_arch_types ra_type = get_remote_arch();
1462 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1463 struct samr_displayentry *entries = NULL;
1465 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1467 /* find the policy handle. open a policy on it. */
1468 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1469 return NT_STATUS_INVALID_HANDLE;
1471 if (info->builtin_domain) {
1472 DEBUG(5,("_samr_QueryDisplayInfo: Nothing in BUILTIN\n"));
1473 return NT_STATUS_OK;
1476 status = access_check_samr_function(info->acc_granted,
1477 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1478 "_samr_QueryDisplayInfo");
1479 if (!NT_STATUS_IS_OK(status)) {
1484 * calculate how many entries we will return.
1486 * - the number of entries the client asked
1487 * - our limit on that
1488 * - the starting point (enumeration context)
1489 * - the buffer size the client will accept
1493 * We are a lot more like W2K. Instead of reading the SAM
1494 * each time to find the records we need to send back,
1495 * we read it once and link that copy to the sam handle.
1496 * For large user list (over the MAX_SAM_ENTRIES)
1497 * it's a definitive win.
1498 * second point to notice: between enumerations
1499 * our sam is now the same as it's a snapshoot.
1500 * third point: got rid of the static SAM_USER_21 struct
1501 * no more intermediate.
1502 * con: it uses much more memory, as a full copy is stored
1505 * If you want to change it, think twice and think
1506 * of the second point , that's really important.
1511 if ((r->in.level < 1) || (r->in.level > 5)) {
1512 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1513 (unsigned int)r->in.level ));
1514 return NT_STATUS_INVALID_INFO_CLASS;
1517 /* first limit the number of entries we will return */
1518 if(max_entries > max_sam_entries) {
1519 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1520 "entries, limiting to %d\n", max_entries,
1522 max_entries = max_sam_entries;
1525 /* calculate the size and limit on the number of entries we will
1528 temp_size=max_entries*struct_size;
1530 if (temp_size>max_size) {
1531 max_entries=MIN((max_size/struct_size),max_entries);;
1532 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1533 "only %d entries\n", max_entries));
1538 /* THe following done as ROOT. Don't return without unbecome_root(). */
1540 switch (r->in.level) {
1543 if (info->disp_info->users == NULL) {
1544 info->disp_info->users = pdb_search_users(
1545 info->disp_info, ACB_NORMAL);
1546 if (info->disp_info->users == NULL) {
1548 return NT_STATUS_ACCESS_DENIED;
1550 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1551 (unsigned int)enum_context ));
1553 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1554 (unsigned int)enum_context ));
1557 num_account = pdb_search_entries(info->disp_info->users,
1558 enum_context, max_entries,
1562 if (info->disp_info->machines == NULL) {
1563 info->disp_info->machines = pdb_search_users(
1564 info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
1565 if (info->disp_info->machines == NULL) {
1567 return NT_STATUS_ACCESS_DENIED;
1569 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1570 (unsigned int)enum_context ));
1572 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1573 (unsigned int)enum_context ));
1576 num_account = pdb_search_entries(info->disp_info->machines,
1577 enum_context, max_entries,
1582 if (info->disp_info->groups == NULL) {
1583 info->disp_info->groups = pdb_search_groups(
1585 if (info->disp_info->groups == NULL) {
1587 return NT_STATUS_ACCESS_DENIED;
1589 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1590 (unsigned int)enum_context ));
1592 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1593 (unsigned int)enum_context ));
1596 num_account = pdb_search_entries(info->disp_info->groups,
1597 enum_context, max_entries,
1602 smb_panic("info class changed");
1608 /* Now create reply structure */
1609 switch (r->in.level) {
1611 disp_ret = init_samr_dispinfo_1(p->mem_ctx, &disp_info->info1,
1612 num_account, enum_context,
1616 disp_ret = init_samr_dispinfo_2(p->mem_ctx, &disp_info->info2,
1617 num_account, enum_context,
1621 disp_ret = init_samr_dispinfo_3(p->mem_ctx, &disp_info->info3,
1622 num_account, enum_context,
1626 disp_ret = init_samr_dispinfo_4(p->mem_ctx, &disp_info->info4,
1627 num_account, enum_context,
1631 disp_ret = init_samr_dispinfo_5(p->mem_ctx, &disp_info->info5,
1632 num_account, enum_context,
1636 smb_panic("info class changed");
1640 if (!NT_STATUS_IS_OK(disp_ret))
1643 /* calculate the total size */
1644 total_data_size=num_account*struct_size;
1646 if (max_entries <= num_account) {
1647 status = STATUS_MORE_ENTRIES;
1649 status = NT_STATUS_OK;
1652 /* Ensure we cache this enumeration. */
1653 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1655 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__));
1657 *r->out.total_size = total_data_size;
1658 *r->out.returned_size = temp_size;
1663 /****************************************************************
1664 _samr_QueryDisplayInfo2
1665 ****************************************************************/
1667 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
1668 struct samr_QueryDisplayInfo2 *r)
1670 struct samr_QueryDisplayInfo q;
1672 q.in.domain_handle = r->in.domain_handle;
1673 q.in.level = r->in.level;
1674 q.in.start_idx = r->in.start_idx;
1675 q.in.max_entries = r->in.max_entries;
1676 q.in.buf_size = r->in.buf_size;
1678 q.out.total_size = r->out.total_size;
1679 q.out.returned_size = r->out.returned_size;
1680 q.out.info = r->out.info;
1682 return _samr_QueryDisplayInfo(p, &q);
1685 /****************************************************************
1686 _samr_QueryDisplayInfo3
1687 ****************************************************************/
1689 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
1690 struct samr_QueryDisplayInfo3 *r)
1692 struct samr_QueryDisplayInfo q;
1694 q.in.domain_handle = r->in.domain_handle;
1695 q.in.level = r->in.level;
1696 q.in.start_idx = r->in.start_idx;
1697 q.in.max_entries = r->in.max_entries;
1698 q.in.buf_size = r->in.buf_size;
1700 q.out.total_size = r->out.total_size;
1701 q.out.returned_size = r->out.returned_size;
1702 q.out.info = r->out.info;
1704 return _samr_QueryDisplayInfo(p, &q);
1707 /*******************************************************************
1708 _samr_QueryAliasInfo
1709 ********************************************************************/
1711 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
1712 struct samr_QueryAliasInfo *r)
1715 struct acct_info info;
1718 union samr_AliasInfo *alias_info = NULL;
1719 const char *alias_name = NULL;
1720 const char *alias_description = NULL;
1722 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1724 alias_info = TALLOC_ZERO_P(p->mem_ctx, union samr_AliasInfo);
1726 return NT_STATUS_NO_MEMORY;
1729 /* find the policy handle. open a policy on it. */
1730 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &sid, &acc_granted, NULL))
1731 return NT_STATUS_INVALID_HANDLE;
1733 status = access_check_samr_function(acc_granted,
1734 SAMR_ALIAS_ACCESS_LOOKUP_INFO,
1735 "_samr_QueryAliasInfo");
1736 if (!NT_STATUS_IS_OK(status)) {
1741 status = pdb_get_aliasinfo(&sid, &info);
1744 if ( !NT_STATUS_IS_OK(status))
1747 /* FIXME: info contains fstrings */
1748 alias_name = talloc_strdup(r, info.acct_name);
1749 alias_description = talloc_strdup(r, info.acct_desc);
1751 switch (r->in.level) {
1753 alias_info->all.name.string = alias_name;
1754 alias_info->all.num_members = 1; /* ??? */
1755 alias_info->all.description.string = alias_description;
1757 case ALIASINFODESCRIPTION:
1758 alias_info->description.string = alias_description;
1761 return NT_STATUS_INVALID_INFO_CLASS;
1764 *r->out.info = alias_info;
1766 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1768 return NT_STATUS_OK;
1771 /*******************************************************************
1773 ********************************************************************/
1775 NTSTATUS _samr_LookupNames(pipes_struct *p,
1776 struct samr_LookupNames *r)
1780 enum lsa_SidType *type;
1782 int num_rids = r->in.num_names;
1785 struct samr_Ids rids, types;
1786 uint32_t num_mapped = 0;
1788 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1790 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL)) {
1791 return NT_STATUS_OBJECT_TYPE_MISMATCH;
1794 status = access_check_samr_function(acc_granted,
1795 0, /* Don't know the acc_bits yet */
1796 "_samr_LookupNames");
1797 if (!NT_STATUS_IS_OK(status)) {
1801 if (num_rids > MAX_SAM_ENTRIES) {
1802 num_rids = MAX_SAM_ENTRIES;
1803 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1806 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1807 NT_STATUS_HAVE_NO_MEMORY(rid);
1809 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1810 NT_STATUS_HAVE_NO_MEMORY(type);
1812 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1813 sid_string_dbg(&pol_sid)));
1815 for (i = 0; i < num_rids; i++) {
1817 status = NT_STATUS_NONE_MAPPED;
1818 type[i] = SID_NAME_UNKNOWN;
1820 rid[i] = 0xffffffff;
1822 if (sid_check_is_builtin(&pol_sid)) {
1823 if (lookup_builtin_name(r->in.names[i].string,
1826 type[i] = SID_NAME_ALIAS;
1829 lookup_global_sam_name(r->in.names[i].string, 0,
1833 if (type[i] != SID_NAME_UNKNOWN) {
1838 if (num_mapped == num_rids) {
1839 status = NT_STATUS_OK;
1840 } else if (num_mapped == 0) {
1841 status = NT_STATUS_NONE_MAPPED;
1843 status = STATUS_SOME_UNMAPPED;
1846 rids.count = num_rids;
1849 types.count = num_rids;
1852 *r->out.rids = rids;
1853 *r->out.types = types;
1855 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1860 /*******************************************************************
1861 _samr_ChangePasswordUser2
1862 ********************************************************************/
1864 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1865 struct samr_ChangePasswordUser2 *r)
1871 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1873 fstrcpy(user_name, r->in.account->string);
1874 fstrcpy(wks, r->in.server->string);
1876 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1879 * Pass the user through the NT -> unix user mapping
1883 (void)map_username(user_name);
1886 * UNIX username case mangling not required, pass_oem_change
1887 * is case insensitive.
1890 status = pass_oem_change(user_name,
1891 r->in.lm_password->data,
1892 r->in.lm_verifier->hash,
1893 r->in.nt_password->data,
1894 r->in.nt_verifier->hash,
1897 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1902 /*******************************************************************
1903 _samr_ChangePasswordUser3
1904 ********************************************************************/
1906 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
1907 struct samr_ChangePasswordUser3 *r)
1911 const char *wks = NULL;
1912 uint32 reject_reason;
1913 struct samr_DomInfo1 *dominfo = NULL;
1914 struct samr_ChangeReject *reject = NULL;
1917 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1919 fstrcpy(user_name, r->in.account->string);
1920 if (r->in.server && r->in.server->string) {
1921 wks = r->in.server->string;
1924 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
1927 * Pass the user through the NT -> unix user mapping
1931 (void)map_username(user_name);
1934 * UNIX username case mangling not required, pass_oem_change
1935 * is case insensitive.
1938 status = pass_oem_change(user_name,
1939 r->in.lm_password->data,
1940 r->in.lm_verifier->hash,
1941 r->in.nt_password->data,
1942 r->in.nt_verifier->hash,
1945 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
1946 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1948 time_t u_expire, u_min_age;
1949 uint32 account_policy_temp;
1951 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
1953 return NT_STATUS_NO_MEMORY;
1956 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
1958 return NT_STATUS_NO_MEMORY;
1965 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &tmp);
1966 dominfo->min_password_length = tmp;
1968 pdb_get_account_policy(AP_PASSWORD_HISTORY, &tmp);
1969 dominfo->password_history_length = tmp;
1971 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
1972 &dominfo->password_properties);
1974 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1975 u_expire = account_policy_temp;
1977 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1978 u_min_age = account_policy_temp;
1984 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
1985 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
1987 if (lp_check_password_script() && *lp_check_password_script()) {
1988 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
1991 reject->reason = reject_reason;
1993 *r->out.dominfo = dominfo;
1994 *r->out.reject = reject;
1997 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2002 /*******************************************************************
2003 makes a SAMR_R_LOOKUP_RIDS structure.
2004 ********************************************************************/
2006 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2008 struct lsa_String **lsa_name_array_p)
2010 struct lsa_String *lsa_name_array = NULL;
2013 *lsa_name_array_p = NULL;
2015 if (num_names != 0) {
2016 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2017 if (!lsa_name_array) {
2022 for (i = 0; i < num_names; i++) {
2023 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2024 init_lsa_String(&lsa_name_array[i], names[i]);
2027 *lsa_name_array_p = lsa_name_array;
2032 /*******************************************************************
2034 ********************************************************************/
2036 NTSTATUS _samr_LookupRids(pipes_struct *p,
2037 struct samr_LookupRids *r)
2041 enum lsa_SidType *attrs = NULL;
2042 uint32 *wire_attrs = NULL;
2044 int num_rids = (int)r->in.num_rids;
2047 struct lsa_Strings names_array;
2048 struct samr_Ids types_array;
2049 struct lsa_String *lsa_names = NULL;
2051 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2053 /* find the policy handle. open a policy on it. */
2054 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2055 return NT_STATUS_INVALID_HANDLE;
2057 status = access_check_samr_function(acc_granted,
2058 0, /* Don't know the acc_bits yet */
2059 "_samr_LookupRids");
2060 if (!NT_STATUS_IS_OK(status)) {
2064 if (num_rids > 1000) {
2065 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2066 "to samba4 idl this is not possible\n", num_rids));
2067 return NT_STATUS_UNSUCCESSFUL;
2071 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2072 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2073 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2075 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2076 return NT_STATUS_NO_MEMORY;
2083 become_root(); /* lookup_sid can require root privs */
2084 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2088 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2089 status = NT_STATUS_OK;
2092 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2094 return NT_STATUS_NO_MEMORY;
2097 /* Convert from enum lsa_SidType to uint32 for wire format. */
2098 for (i = 0; i < num_rids; i++) {
2099 wire_attrs[i] = (uint32)attrs[i];
2102 names_array.count = num_rids;
2103 names_array.names = lsa_names;
2105 types_array.count = num_rids;
2106 types_array.ids = wire_attrs;
2108 *r->out.names = names_array;
2109 *r->out.types = types_array;
2111 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2116 /*******************************************************************
2118 ********************************************************************/
2120 NTSTATUS _samr_OpenUser(pipes_struct *p,
2121 struct samr_OpenUser *r)
2123 struct samu *sampass=NULL;
2125 struct samr_info *info = NULL;
2126 SEC_DESC *psd = NULL;
2128 uint32 des_access = r->in.access_mask;
2134 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2136 if ( !get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL) )
2137 return NT_STATUS_INVALID_HANDLE;
2139 nt_status = access_check_samr_function(acc_granted,
2140 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2143 if ( !NT_STATUS_IS_OK(nt_status) )
2146 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2147 return NT_STATUS_NO_MEMORY;
2150 /* append the user's RID to it */
2152 if (!sid_append_rid(&sid, r->in.rid))
2153 return NT_STATUS_NO_SUCH_USER;
2155 /* check if access can be granted as requested by client. */
2157 map_max_allowed_access(p->server_info->ptok, &des_access);
2159 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2160 se_map_generic(&des_access, &usr_generic_mapping);
2162 se_priv_copy( &se_rights, &se_machine_account );
2163 se_priv_add( &se_rights, &se_add_users );
2165 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2166 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2167 &acc_granted, "_samr_OpenUser");
2169 if ( !NT_STATUS_IS_OK(nt_status) )
2173 ret=pdb_getsampwsid(sampass, &sid);
2176 /* check that the SID exists in our domain. */
2178 return NT_STATUS_NO_SUCH_USER;
2181 TALLOC_FREE(sampass);
2183 /* associate the user's SID and access bits with the new handle. */
2184 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
2185 return NT_STATUS_NO_MEMORY;
2186 info->acc_granted = acc_granted;
2188 /* get a (unique) handle. open a policy on it. */
2189 if (!create_policy_hnd(p, r->out.user_handle, info))
2190 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2192 return NT_STATUS_OK;
2195 /*************************************************************************
2196 *************************************************************************/
2198 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2200 struct lsa_BinaryString **_r)
2202 struct lsa_BinaryString *r;
2205 return NT_STATUS_INVALID_PARAMETER;
2208 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2210 return NT_STATUS_NO_MEMORY;
2213 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2215 return NT_STATUS_NO_MEMORY;
2217 memcpy(r->array, blob->data, blob->length);
2218 r->size = blob->length;
2219 r->length = blob->length;
2222 return NT_STATUS_NO_MEMORY;
2227 return NT_STATUS_OK;
2230 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2231 struct samr_UserInfo5 *r,
2233 DOM_SID *domain_sid)
2235 const DOM_SID *sid_user, *sid_group;
2236 uint32_t rid, primary_gid;
2238 sid_user = pdb_get_user_sid(pw);
2240 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2241 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2242 "the domain sid %s. Failing operation.\n",
2243 pdb_get_username(pw), sid_string_dbg(sid_user),
2244 sid_string_dbg(domain_sid)));
2245 return NT_STATUS_UNSUCCESSFUL;
2249 sid_group = pdb_get_group_sid(pw);
2252 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2253 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2254 "which conflicts with the domain sid %s. Failing operation.\n",
2255 pdb_get_username(pw), sid_string_dbg(sid_group),
2256 sid_string_dbg(domain_sid)));
2257 return NT_STATUS_UNSUCCESSFUL;
2260 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2261 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2262 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2263 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2265 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2266 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2267 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2268 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2269 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2270 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2271 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2272 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2274 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2276 r->primary_gid = primary_gid;
2277 r->acct_flags = pdb_get_acct_ctrl(pw);
2278 r->bad_password_count = pdb_get_bad_password_count(pw);
2279 r->logon_count = pdb_get_logon_count(pw);
2281 return NT_STATUS_OK;
2284 /*************************************************************************
2285 get_user_info_7. Safe. Only gives out account_name.
2286 *************************************************************************/
2288 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2289 struct samr_UserInfo7 *r,
2290 struct samu *smbpass)
2292 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2293 if (!r->account_name.string) {
2294 return NT_STATUS_NO_MEMORY;
2297 return NT_STATUS_OK;
2300 /*************************************************************************
2301 get_user_info_9. Only gives out primary group SID.
2302 *************************************************************************/
2304 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2305 struct samr_UserInfo9 *r,
2306 struct samu *smbpass)
2308 r->primary_gid = pdb_get_group_rid(smbpass);
2310 return NT_STATUS_OK;
2313 /*************************************************************************
2314 get_user_info_16. Safe. Only gives out acb bits.
2315 *************************************************************************/
2317 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2318 struct samr_UserInfo16 *r,
2319 struct samu *smbpass)
2321 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2323 return NT_STATUS_OK;
2326 /*************************************************************************
2327 get_user_info_18. OK - this is the killer as it gives out password info.
2328 Ensure that this is only allowed on an encrypted connection with a root
2330 *************************************************************************/
2332 static NTSTATUS get_user_info_18(pipes_struct *p,
2333 TALLOC_CTX *mem_ctx,
2334 struct samr_UserInfo18 *r,
2337 struct samu *smbpass=NULL;
2342 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2343 return NT_STATUS_ACCESS_DENIED;
2346 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2347 return NT_STATUS_ACCESS_DENIED;
2351 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2354 if ( !(smbpass = samu_new( mem_ctx )) ) {
2355 return NT_STATUS_NO_MEMORY;
2358 ret = pdb_getsampwsid(smbpass, user_sid);
2361 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2362 TALLOC_FREE(smbpass);
2363 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2366 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2368 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2369 TALLOC_FREE(smbpass);
2370 return NT_STATUS_ACCOUNT_DISABLED;
2373 r->lm_pwd_active = true;
2374 r->nt_pwd_active = true;
2375 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2376 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2377 r->password_expired = 0; /* FIXME */
2379 TALLOC_FREE(smbpass);
2381 return NT_STATUS_OK;
2384 /*************************************************************************
2386 *************************************************************************/
2388 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2389 struct samr_UserInfo20 *r,
2390 struct samu *sampass)
2392 const char *munged_dial = NULL;
2395 struct lsa_BinaryString *parameters = NULL;
2399 munged_dial = pdb_get_munged_dial(sampass);
2401 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2402 munged_dial, (int)strlen(munged_dial)));
2405 blob = base64_decode_data_blob(munged_dial);
2407 blob = data_blob_string_const_null("");
2410 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2411 data_blob_free(&blob);
2412 if (!NT_STATUS_IS_OK(status)) {
2416 r->parameters = *parameters;
2418 return NT_STATUS_OK;
2422 /*************************************************************************
2424 *************************************************************************/
2426 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2427 struct samr_UserInfo21 *r,
2429 DOM_SID *domain_sid)
2432 const DOM_SID *sid_user, *sid_group;
2433 uint32_t rid, primary_gid;
2434 NTTIME force_password_change;
2435 time_t must_change_time;
2436 struct lsa_BinaryString *parameters = NULL;
2437 const char *munged_dial = NULL;
2442 sid_user = pdb_get_user_sid(pw);
2444 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2445 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2446 "the domain sid %s. Failing operation.\n",
2447 pdb_get_username(pw), sid_string_dbg(sid_user),
2448 sid_string_dbg(domain_sid)));
2449 return NT_STATUS_UNSUCCESSFUL;
2453 sid_group = pdb_get_group_sid(pw);
2456 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2457 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2458 "which conflicts with the domain sid %s. Failing operation.\n",
2459 pdb_get_username(pw), sid_string_dbg(sid_group),
2460 sid_string_dbg(domain_sid)));
2461 return NT_STATUS_UNSUCCESSFUL;
2464 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2465 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2466 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2467 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2468 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2470 must_change_time = pdb_get_pass_must_change_time(pw);
2471 if (must_change_time == get_time_t_max()) {
2472 unix_to_nt_time_abs(&force_password_change, must_change_time);
2474 unix_to_nt_time(&force_password_change, must_change_time);
2477 munged_dial = pdb_get_munged_dial(pw);
2479 blob = base64_decode_data_blob(munged_dial);
2481 blob = data_blob_string_const_null("");
2484 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2485 data_blob_free(&blob);
2486 if (!NT_STATUS_IS_OK(status)) {
2490 r->force_password_change = force_password_change;
2492 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2493 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2494 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2495 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2496 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2497 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2498 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2499 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2500 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2502 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2503 r->parameters = *parameters;
2505 r->primary_gid = primary_gid;
2506 r->acct_flags = pdb_get_acct_ctrl(pw);
2507 r->bad_password_count = pdb_get_bad_password_count(pw);
2508 r->logon_count = pdb_get_logon_count(pw);
2509 r->fields_present = pdb_build_fields_present(pw);
2510 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2511 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2512 r->country_code = 0;
2514 r->lm_password_set = 0;
2515 r->nt_password_set = 0;
2520 Look at a user on a real NT4 PDC with usrmgr, press
2521 'ok'. Then you will see that fields_present is set to
2522 0x08f827fa. Look at the user immediately after that again,
2523 and you will see that 0x00fffff is returned. This solves
2524 the problem that you get access denied after having looked
2532 return NT_STATUS_OK;
2535 /*******************************************************************
2537 ********************************************************************/
2539 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2540 struct samr_QueryUserInfo *r)
2543 union samr_UserInfo *user_info = NULL;
2544 struct samr_info *info = NULL;
2548 struct samu *pwd = NULL;
2550 /* search for the handle */
2551 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
2552 return NT_STATUS_INVALID_HANDLE;
2554 status = access_check_samr_function(info->acc_granted,
2555 SAMR_USER_ACCESS_GET_ATTRIBUTES,
2556 "_samr_QueryUserInfo");
2557 if (!NT_STATUS_IS_OK(status)) {
2561 domain_sid = info->sid;
2563 sid_split_rid(&domain_sid, &rid);
2565 if (!sid_check_is_in_our_domain(&info->sid))
2566 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2568 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2569 sid_string_dbg(&info->sid)));
2571 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2573 return NT_STATUS_NO_MEMORY;
2576 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2578 if (!(pwd = samu_new(p->mem_ctx))) {
2579 return NT_STATUS_NO_MEMORY;
2583 ret = pdb_getsampwsid(pwd, &info->sid);
2587 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
2589 return NT_STATUS_NO_SUCH_USER;
2592 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2594 samr_clear_sam_passwd(pwd);
2596 switch (r->in.level) {
2598 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2601 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2604 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2607 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2610 /* level 18 is special */
2611 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
2614 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2617 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2620 status = NT_STATUS_INVALID_INFO_CLASS;
2626 *r->out.info = user_info;
2628 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2633 /****************************************************************
2634 ****************************************************************/
2636 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2637 struct samr_QueryUserInfo2 *r)
2639 struct samr_QueryUserInfo u;
2641 u.in.user_handle = r->in.user_handle;
2642 u.in.level = r->in.level;
2643 u.out.info = r->out.info;
2645 return _samr_QueryUserInfo(p, &u);
2648 /*******************************************************************
2649 _samr_GetGroupsForUser
2650 ********************************************************************/
2652 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2653 struct samr_GetGroupsForUser *r)
2655 struct samu *sam_pass=NULL;
2658 struct samr_RidWithAttribute dom_gid;
2659 struct samr_RidWithAttribute *gids = NULL;
2660 uint32 primary_group_rid;
2661 size_t num_groups = 0;
2667 bool success = False;
2669 struct samr_RidWithAttributeArray *rids = NULL;
2672 * from the SID in the request:
2673 * we should send back the list of DOMAIN GROUPS
2674 * the user is a member of
2676 * and only the DOMAIN GROUPS
2677 * no ALIASES !!! neither aliases of the domain
2678 * nor aliases of the builtin SID
2683 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2685 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
2687 return NT_STATUS_NO_MEMORY;
2690 /* find the policy handle. open a policy on it. */
2691 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
2692 return NT_STATUS_INVALID_HANDLE;
2694 result = access_check_samr_function(acc_granted,
2695 SAMR_USER_ACCESS_GET_GROUPS,
2696 "_samr_GetGroupsForUser");
2697 if (!NT_STATUS_IS_OK(result)) {
2701 if (!sid_check_is_in_our_domain(&sid))
2702 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2704 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2705 return NT_STATUS_NO_MEMORY;
2709 ret = pdb_getsampwsid(sam_pass, &sid);
2713 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2714 sid_string_dbg(&sid)));
2715 return NT_STATUS_NO_SUCH_USER;
2720 /* make both calls inside the root block */
2722 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2723 &sids, &unix_gids, &num_groups);
2724 if ( NT_STATUS_IS_OK(result) ) {
2725 success = sid_peek_check_rid(get_global_sam_sid(),
2726 pdb_get_group_sid(sam_pass),
2727 &primary_group_rid);
2731 if (!NT_STATUS_IS_OK(result)) {
2732 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2733 sid_string_dbg(&sid)));
2738 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2739 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2740 pdb_get_username(sam_pass)));
2741 TALLOC_FREE(sam_pass);
2742 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2748 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2750 dom_gid.rid = primary_group_rid;
2751 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2753 for (i=0; i<num_groups; i++) {
2755 if (!sid_peek_check_rid(get_global_sam_sid(),
2756 &(sids[i]), &dom_gid.rid)) {
2757 DEBUG(10, ("Found sid %s not in our domain\n",
2758 sid_string_dbg(&sids[i])));
2762 if (dom_gid.rid == primary_group_rid) {
2763 /* We added the primary group directly from the
2764 * sam_account. The other SIDs are unique from
2765 * enum_group_memberships */
2769 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2772 rids->count = num_gids;
2775 *r->out.rids = rids;
2777 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2782 /*******************************************************************
2783 _samr_QueryDomainInfo
2784 ********************************************************************/
2786 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
2787 struct samr_QueryDomainInfo *r)
2789 NTSTATUS status = NT_STATUS_OK;
2790 struct samr_info *info = NULL;
2791 union samr_DomainInfo *dom_info;
2792 time_t u_expire, u_min_age;
2794 time_t u_lock_duration, u_reset_time;
2797 uint32 account_policy_temp;
2802 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2804 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
2806 return NT_STATUS_NO_MEMORY;
2809 /* find the policy handle. open a policy on it. */
2810 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
2811 return NT_STATUS_INVALID_HANDLE;
2814 status = access_check_samr_function(info->acc_granted,
2815 SAMR_ACCESS_OPEN_DOMAIN,
2816 "_samr_QueryDomainInfo" );
2818 if ( !NT_STATUS_IS_OK(status) )
2821 switch (r->in.level) {
2828 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
2829 &account_policy_temp);
2830 dom_info->info1.min_password_length = account_policy_temp;
2832 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
2833 dom_info->info1.password_history_length = account_policy_temp;
2835 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2836 &dom_info->info1.password_properties);
2838 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2839 u_expire = account_policy_temp;
2841 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2842 u_min_age = account_policy_temp;
2848 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
2849 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
2851 if (lp_check_password_script() && *lp_check_password_script()) {
2852 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
2862 dom_info->general.num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2863 dom_info->general.num_groups = count_sam_groups(info->disp_info);
2864 dom_info->general.num_aliases = count_sam_aliases(info->disp_info);
2866 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
2868 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
2870 if (!pdb_get_seq_num(&seq_num))
2871 seq_num = time(NULL);
2877 server_role = ROLE_DOMAIN_PDC;
2878 if (lp_server_role() == ROLE_DOMAIN_BDC)
2879 server_role = ROLE_DOMAIN_BDC;
2881 dom_info->general.oem_information.string = lp_serverstring();
2882 dom_info->general.domain_name.string = lp_workgroup();
2883 dom_info->general.primary.string = global_myname();
2884 dom_info->general.sequence_num = seq_num;
2885 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
2886 dom_info->general.role = server_role;
2887 dom_info->general.unknown3 = 1;
2898 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2899 u_logout = (time_t)ul;
2906 unix_to_nt_time_abs(&dom_info->info3.force_logoff_time, u_logout);
2910 dom_info->oem.oem_information.string = lp_serverstring();
2913 dom_info->info5.domain_name.string = get_global_sam_name();
2916 /* NT returns its own name when a PDC. win2k and later
2917 * only the name of the PDC if itself is a BDC (samba4
2919 dom_info->info6.primary.string = global_myname();
2922 server_role = ROLE_DOMAIN_PDC;
2923 if (lp_server_role() == ROLE_DOMAIN_BDC)
2924 server_role = ROLE_DOMAIN_BDC;
2926 dom_info->info7.role = server_role;
2934 if (!pdb_get_seq_num(&seq_num)) {
2935 seq_num = time(NULL);
2942 dom_info->info8.sequence_num = seq_num;
2943 dom_info->info8.domain_create_time = 0;
2952 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
2953 u_lock_duration = account_policy_temp;
2954 if (u_lock_duration != -1) {
2955 u_lock_duration *= 60;
2958 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
2959 u_reset_time = account_policy_temp * 60;
2961 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
2962 &account_policy_temp);
2963 dom_info->info12.lockout_threshold = account_policy_temp;
2969 unix_to_nt_time_abs(&dom_info->info12.lockout_duration,
2971 unix_to_nt_time_abs(&dom_info->info12.lockout_window,
2976 return NT_STATUS_INVALID_INFO_CLASS;
2979 *r->out.info = dom_info;
2981 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2986 /* W2k3 seems to use the same check for all 3 objects that can be created via
2987 * SAMR, if you try to create for example "Dialup" as an alias it says
2988 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
2991 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
2993 enum lsa_SidType type;
2996 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
2999 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3000 * whether the name already exists */
3001 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3002 NULL, NULL, NULL, &type);
3006 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3007 return NT_STATUS_OK;
3010 DEBUG(5, ("trying to create %s, exists as %s\n",
3011 new_name, sid_type_lookup(type)));
3013 if (type == SID_NAME_DOM_GRP) {
3014 return NT_STATUS_GROUP_EXISTS;
3016 if (type == SID_NAME_ALIAS) {
3017 return NT_STATUS_ALIAS_EXISTS;
3020 /* Yes, the default is NT_STATUS_USER_EXISTS */
3021 return NT_STATUS_USER_EXISTS;
3024 /*******************************************************************
3026 ********************************************************************/
3028 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3029 struct samr_CreateUser2 *r)
3031 const char *account = NULL;
3033 uint32_t acb_info = r->in.acct_flags;
3034 struct samr_info *info = NULL;
3039 /* check this, when giving away 'add computer to domain' privs */
3040 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3041 bool can_add_account = False;
3043 DISP_INFO *disp_info = NULL;
3045 /* Get the domain SID stored in the domain policy */
3046 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted,
3048 return NT_STATUS_INVALID_HANDLE;
3050 if (disp_info->builtin_domain) {
3051 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3052 return NT_STATUS_ACCESS_DENIED;
3055 nt_status = access_check_samr_function(acc_granted,
3056 SAMR_DOMAIN_ACCESS_CREATE_USER,
3057 "_samr_CreateUser2");
3058 if (!NT_STATUS_IS_OK(nt_status)) {
3062 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3063 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3064 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3065 this parameter is not an account type */
3066 return NT_STATUS_INVALID_PARAMETER;
3069 account = r->in.account_name->string;
3070 if (account == NULL) {
3071 return NT_STATUS_NO_MEMORY;
3074 nt_status = can_create(p->mem_ctx, account);
3075 if (!NT_STATUS_IS_OK(nt_status)) {
3079 /* determine which user right we need to check based on the acb_info */
3081 if ( acb_info & ACB_WSTRUST )
3083 se_priv_copy( &se_rights, &se_machine_account );
3084 can_add_account = user_has_privileges(
3085 p->server_info->ptok, &se_rights );
3087 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3088 account for domain trusts and changes the ACB flags later */
3089 else if ( acb_info & ACB_NORMAL &&
3090 (account[strlen(account)-1] != '$') )
3092 se_priv_copy( &se_rights, &se_add_users );
3093 can_add_account = user_has_privileges(
3094 p->server_info->ptok, &se_rights );
3096 else /* implicit assumption of a BDC or domain trust account here
3097 * (we already check the flags earlier) */
3099 if ( lp_enable_privileges() ) {
3100 /* only Domain Admins can add a BDC or domain trust */
3101 se_priv_copy( &se_rights, &se_priv_none );
3102 can_add_account = nt_token_check_domain_rid(
3103 p->server_info->ptok,
3104 DOMAIN_GROUP_RID_ADMINS );
3108 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3109 uidtoname(p->server_info->utok.uid),
3110 can_add_account ? "True":"False" ));
3112 /********** BEGIN Admin BLOCK **********/
3114 if ( can_add_account )
3117 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3120 if ( can_add_account )
3123 /********** END Admin BLOCK **********/
3125 /* now check for failure */
3127 if ( !NT_STATUS_IS_OK(nt_status) )
3130 /* Get the user's SID */
3132 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3134 map_max_allowed_access(p->server_info->ptok, &des_access);
3136 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3137 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3138 se_map_generic(&des_access, &usr_generic_mapping);
3140 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3141 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3142 &acc_granted, "_samr_CreateUser2");
3144 if ( !NT_STATUS_IS_OK(nt_status) ) {
3148 /* associate the user's SID with the new handle. */
3149 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL) {
3150 return NT_STATUS_NO_MEMORY;
3155 info->acc_granted = acc_granted;
3157 /* get a (unique) handle. open a policy on it. */
3158 if (!create_policy_hnd(p, r->out.user_handle, info)) {
3159 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3162 /* After a "set" ensure we have no cached display info. */
3163 force_flush_samr_cache(info->disp_info);
3165 *r->out.access_granted = acc_granted;
3167 return NT_STATUS_OK;
3170 /****************************************************************
3171 ****************************************************************/
3173 NTSTATUS _samr_CreateUser(pipes_struct *p,
3174 struct samr_CreateUser *r)
3176 struct samr_CreateUser2 c;
3177 uint32_t access_granted;
3179 c.in.domain_handle = r->in.domain_handle;
3180 c.in.account_name = r->in.account_name;
3181 c.in.acct_flags = ACB_NORMAL;
3182 c.in.access_mask = r->in.access_mask;
3183 c.out.user_handle = r->out.user_handle;
3184 c.out.access_granted = &access_granted;
3185 c.out.rid = r->out.rid;
3187 return _samr_CreateUser2(p, &c);
3190 /*******************************************************************
3192 ********************************************************************/
3194 NTSTATUS _samr_Connect(pipes_struct *p,
3195 struct samr_Connect *r)
3197 struct samr_info *info = NULL;
3198 uint32 des_access = r->in.access_mask;
3202 if (!pipe_access_check(p)) {
3203 DEBUG(3, ("access denied to _samr_Connect\n"));
3204 return NT_STATUS_ACCESS_DENIED;
3207 /* set up the SAMR connect_anon response */
3209 /* associate the user's SID with the new handle. */
3210 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3211 return NT_STATUS_NO_MEMORY;
3213 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3214 was observed from a win98 client trying to enumerate users (when configured
3215 user level access control on shares) --jerry */
3217 map_max_allowed_access(p->server_info->ptok, &des_access);
3219 se_map_generic( &des_access, &sam_generic_mapping );
3220 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
3222 /* get a (unique) handle. open a policy on it. */
3223 if (!create_policy_hnd(p, r->out.connect_handle, info))
3224 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3226 return NT_STATUS_OK;
3229 /*******************************************************************
3231 ********************************************************************/
3233 NTSTATUS _samr_Connect2(pipes_struct *p,
3234 struct samr_Connect2 *r)
3236 struct samr_info *info = NULL;
3237 SEC_DESC *psd = NULL;
3239 uint32 des_access = r->in.access_mask;
3242 const char *fn = "_samr_Connect2";
3244 switch (p->hdr_req.opnum) {
3245 case NDR_SAMR_CONNECT2:
3246 fn = "_samr_Connect2";
3248 case NDR_SAMR_CONNECT4:
3249 fn = "_samr_Connect4";
3251 case NDR_SAMR_CONNECT5:
3252 fn = "_samr_Connect5";
3256 DEBUG(5,("%s: %d\n", fn, __LINE__));
3260 if (!pipe_access_check(p)) {
3261 DEBUG(3, ("access denied to %s\n", fn));
3262 return NT_STATUS_ACCESS_DENIED;
3265 map_max_allowed_access(p->server_info->ptok, &des_access);
3267 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3268 se_map_generic(&des_access, &sam_generic_mapping);
3270 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3271 NULL, 0, des_access, &acc_granted, fn);
3273 if ( !NT_STATUS_IS_OK(nt_status) )
3276 /* associate the user's SID and access granted with the new handle. */
3277 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3278 return NT_STATUS_NO_MEMORY;
3280 info->acc_granted = acc_granted;
3281 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3283 /* get a (unique) handle. open a policy on it. */
3284 if (!create_policy_hnd(p, r->out.connect_handle, info))
3285 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3287 DEBUG(5,("%s: %d\n", fn, __LINE__));
3292 /*******************************************************************
3294 ********************************************************************/
3296 NTSTATUS _samr_Connect4(pipes_struct *p,
3297 struct samr_Connect4 *r)
3299 struct samr_Connect2 c;
3301 c.in.system_name = r->in.system_name;
3302 c.in.access_mask = r->in.access_mask;
3303 c.out.connect_handle = r->out.connect_handle;
3305 return _samr_Connect2(p, &c);
3308 /*******************************************************************
3310 ********************************************************************/
3312 NTSTATUS _samr_Connect5(pipes_struct *p,
3313 struct samr_Connect5 *r)
3316 struct samr_Connect2 c;
3317 struct samr_ConnectInfo1 info1;
3319 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3322 c.in.system_name = r->in.system_name;
3323 c.in.access_mask = r->in.access_mask;
3324 c.out.connect_handle = r->out.connect_handle;
3326 status = _samr_Connect2(p, &c);
3327 if (!NT_STATUS_IS_OK(status)) {
3331 *r->out.level_out = 1;
3332 r->out.info_out->info1 = info1;
3334 return NT_STATUS_OK;
3337 /**********************************************************************
3339 **********************************************************************/
3341 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3342 struct samr_LookupDomain *r)
3344 NTSTATUS status = NT_STATUS_OK;
3345 struct samr_info *info;
3346 const char *domain_name;
3347 DOM_SID *sid = NULL;
3349 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3350 return NT_STATUS_INVALID_HANDLE;
3352 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
3353 Reverted that change so we will work with RAS servers again */
3355 status = access_check_samr_function(info->acc_granted,
3356 SAMR_ACCESS_OPEN_DOMAIN,
3357 "_samr_LookupDomain");
3358 if (!NT_STATUS_IS_OK(status)) {
3362 domain_name = r->in.domain_name->string;
3364 return NT_STATUS_INVALID_PARAMETER;
3367 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
3369 return NT_STATUS_NO_MEMORY;
3372 if (strequal(domain_name, builtin_domain_name())) {
3373 sid_copy(sid, &global_sid_Builtin);
3375 if (!secrets_fetch_domain_sid(domain_name, sid)) {
3376 status = NT_STATUS_NO_SUCH_DOMAIN;
3380 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
3381 sid_string_dbg(sid)));
3388 /**********************************************************************
3390 **********************************************************************/
3392 NTSTATUS _samr_EnumDomains(pipes_struct *p,
3393 struct samr_EnumDomains *r)
3396 struct samr_info *info;
3397 uint32_t num_entries = 2;
3398 struct samr_SamEntry *entry_array = NULL;
3399 struct samr_SamArray *sam;
3401 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3402 return NT_STATUS_INVALID_HANDLE;
3404 status = access_check_samr_function(info->acc_granted,
3405 SAMR_ACCESS_ENUM_DOMAINS,
3406 "_samr_EnumDomains");
3407 if (!NT_STATUS_IS_OK(status)) {
3411 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
3413 return NT_STATUS_NO_MEMORY;
3416 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
3417 struct samr_SamEntry,
3420 return NT_STATUS_NO_MEMORY;
3423 entry_array[0].idx = 0;
3424 init_lsa_String(&entry_array[0].name, get_global_sam_name());
3426 entry_array[1].idx = 1;
3427 init_lsa_String(&entry_array[1].name, "Builtin");
3429 sam->count = num_entries;
3430 sam->entries = entry_array;
3433 *r->out.num_entries = num_entries;
3438 /*******************************************************************
3440 ********************************************************************/
3442 NTSTATUS _samr_OpenAlias(pipes_struct *p,
3443 struct samr_OpenAlias *r)
3446 uint32 alias_rid = r->in.rid;
3447 struct samr_info *info = NULL;
3448 SEC_DESC *psd = NULL;
3450 uint32 des_access = r->in.access_mask;
3455 /* find the domain policy and get the SID / access bits stored in the domain policy */
3457 if ( !get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL) )
3458 return NT_STATUS_INVALID_HANDLE;
3460 status = access_check_samr_function(acc_granted,
3461 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
3464 if ( !NT_STATUS_IS_OK(status) )
3467 /* append the alias' RID to it */
3469 if (!sid_append_rid(&sid, alias_rid))
3470 return NT_STATUS_NO_SUCH_ALIAS;
3472 /*check if access can be granted as requested by client. */
3474 map_max_allowed_access(p->server_info->ptok, &des_access);
3476 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3477 se_map_generic(&des_access,&ali_generic_mapping);
3479 se_priv_copy( &se_rights, &se_add_users );
3482 status = access_check_samr_object(psd, p->server_info->ptok,
3483 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3484 &acc_granted, "_samr_OpenAlias");
3486 if ( !NT_STATUS_IS_OK(status) )
3490 /* Check we actually have the requested alias */
3491 enum lsa_SidType type;
3496 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3499 if (!result || (type != SID_NAME_ALIAS)) {
3500 return NT_STATUS_NO_SUCH_ALIAS;
3503 /* make sure there is a mapping */
3505 if ( !sid_to_gid( &sid, &gid ) ) {
3506 return NT_STATUS_NO_SUCH_ALIAS;
3511 /* associate the alias SID with the new handle. */
3512 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
3513 return NT_STATUS_NO_MEMORY;
3515 info->acc_granted = acc_granted;
3517 /* get a (unique) handle. open a policy on it. */
3518 if (!create_policy_hnd(p, r->out.alias_handle, info))
3519 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3521 return NT_STATUS_OK;
3524 /*******************************************************************
3526 ********************************************************************/
3528 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3529 struct samr_UserInfo7 *id7,
3535 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3536 return NT_STATUS_ACCESS_DENIED;
3539 if (!id7->account_name.string) {
3540 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3541 return NT_STATUS_ACCESS_DENIED;
3544 /* check to see if the new username already exists. Note: we can't
3545 reliably lock all backends, so there is potentially the
3546 possibility that a user can be created in between this check and
3547 the rename. The rename should fail, but may not get the
3548 exact same failure status code. I think this is small enough
3549 of a window for this type of operation and the results are
3550 simply that the rename fails with a slightly different status
3551 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3553 rc = can_create(mem_ctx, id7->account_name.string);
3554 if (!NT_STATUS_IS_OK(rc)) {
3558 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
3563 /*******************************************************************
3565 ********************************************************************/
3567 static bool set_user_info_16(struct samr_UserInfo16 *id16,
3571 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3575 /* FIX ME: check if the value is really changed --metze */
3576 if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
3580 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3587 /*******************************************************************
3589 ********************************************************************/
3591 static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
3592 TALLOC_CTX *mem_ctx,
3593 DATA_BLOB *session_key,
3597 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3598 return NT_STATUS_INVALID_PARAMETER;
3601 if (id18->nt_pwd_active || id18->lm_pwd_active) {
3602 if (!session_key->length) {
3603 return NT_STATUS_NO_USER_SESSION_KEY;
3607 if (id18->nt_pwd_active) {
3611 in = data_blob_const(id18->nt_pwd.hash, 16);
3612 out = data_blob_talloc_zero(mem_ctx, 16);
3614 sess_crypt_blob(&out, &in, session_key, false);
3616 if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
3617 return NT_STATUS_ACCESS_DENIED;
3620 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3623 if (id18->lm_pwd_active) {
3627 in = data_blob_const(id18->lm_pwd.hash, 16);
3628 out = data_blob_talloc_zero(mem_ctx, 16);
3630 sess_crypt_blob(&out, &in, session_key, false);
3632 if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
3633 return NT_STATUS_ACCESS_DENIED;
3636 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3639 if (id18->password_expired) {
3640 pdb_set_pass_last_set_time(pwd, 0, PDB_CHANGED);
3643 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3646 return pdb_update_sam_account(pwd);
3649 /*******************************************************************
3651 ********************************************************************/
3653 static bool set_user_info_20(struct samr_UserInfo20 *id20,
3657 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3661 copy_id20_to_sam_passwd(pwd, id20);
3663 /* write the change out */
3664 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3671 /*******************************************************************
3673 ********************************************************************/
3675 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
3676 struct samr_UserInfo21 *id21,
3682 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3683 return NT_STATUS_INVALID_PARAMETER;
3686 if (id21->fields_present == 0) {
3687 return NT_STATUS_INVALID_PARAMETER;
3690 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3691 return NT_STATUS_ACCESS_DENIED;
3694 /* we need to separately check for an account rename first */
3696 if (id21->account_name.string &&
3697 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
3700 /* check to see if the new username already exists. Note: we can't
3701 reliably lock all backends, so there is potentially the
3702 possibility that a user can be created in between this check and
3703 the rename. The rename should fail, but may not get the
3704 exact same failure status code. I think this is small enough
3705 of a window for this type of operation and the results are
3706 simply that the rename fails with a slightly different status
3707 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3709 status = can_create(mem_ctx, id21->account_name.string);
3710 if (!NT_STATUS_IS_OK(status)) {
3714 status = pdb_rename_sam_account(pwd, id21->account_name.string);
3716 if (!NT_STATUS_IS_OK(status)) {
3717 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3718 nt_errstr(status)));
3722 /* set the new username so that later
3723 functions can work on the new account */
3724 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
3727 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
3730 * The funny part about the previous two calls is
3731 * that pwd still has the password hashes from the
3732 * passdb entry. These have not been updated from
3733 * id21. I don't know if they need to be set. --jerry
3736 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3737 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3738 if ( !NT_STATUS_IS_OK(status) ) {
3743 /* Don't worry about writing out the user account since the
3744 primary group SID is generated solely from the user's Unix
3747 /* write the change out */
3748 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3752 return NT_STATUS_OK;
3755 /*******************************************************************
3757 ********************************************************************/
3759 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
3760 struct samr_UserInfo23 *id23,
3763 char *plaintext_buf = NULL;
3769 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3770 return NT_STATUS_INVALID_PARAMETER;
3773 if (id23->info.fields_present == 0) {
3774 return NT_STATUS_INVALID_PARAMETER;
3777 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3778 return NT_STATUS_ACCESS_DENIED;
3781 if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
3782 (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
3784 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3785 pdb_get_username(pwd)));
3787 if (!decode_pw_buffer(mem_ctx,
3788 id23->password.data,
3792 return NT_STATUS_WRONG_PASSWORD;
3795 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3796 return NT_STATUS_ACCESS_DENIED;
3800 copy_id23_to_sam_passwd(pwd, id23);
3802 acct_ctrl = pdb_get_acct_ctrl(pwd);
3804 /* if it's a trust account, don't update /etc/passwd */
3805 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3806 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3807 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3808 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3809 } else if (plaintext_buf) {
3810 /* update the UNIX password */
3811 if (lp_unix_password_sync() ) {
3812 struct passwd *passwd;
3813 if (pdb_get_username(pwd) == NULL) {
3814 DEBUG(1, ("chgpasswd: User without name???\n"));
3815 return NT_STATUS_ACCESS_DENIED;
3818 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3819 if (passwd == NULL) {
3820 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3823 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3824 return NT_STATUS_ACCESS_DENIED;
3826 TALLOC_FREE(passwd);
3830 if (plaintext_buf) {
3831 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3834 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3835 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3840 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3844 return NT_STATUS_OK;
3847 /*******************************************************************
3849 ********************************************************************/
3851 static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
3855 char *plaintext_buf = NULL;
3857 time_t last_set_time;
3858 enum pdb_value_state last_set_state;
3860 DEBUG(5, ("Attempting administrator password change for user %s\n",
3861 pdb_get_username(pwd)));
3863 acct_ctrl = pdb_get_acct_ctrl(pwd);
3864 /* we need to know if it's expired, because this is an admin change, not a
3865 user change, so it's still expired when we're done */
3866 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3867 last_set_time = pdb_get_pass_last_set_time(pwd);
3869 if (!decode_pw_buffer(talloc_tos(),
3877 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3881 /* if it's a trust account, don't update /etc/passwd */
3882 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3883 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3884 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3885 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3887 /* update the UNIX password */
3888 if (lp_unix_password_sync()) {
3889 struct passwd *passwd;
3891 if (pdb_get_username(pwd) == NULL) {
3892 DEBUG(1, ("chgpasswd: User without name???\n"));
3896 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3897 if (passwd == NULL) {
3898 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3901 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3904 TALLOC_FREE(passwd);
3908 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3911 * A level 25 change does reset the pwdlastset field, a level 24
3912 * change does not. I know this is probably not the full story, but
3913 * it is needed to make XP join LDAP correctly, without it the later
3914 * auth2 check can fail with PWD_MUST_CHANGE.
3918 * restore last set time as this is an admin change, not a
3921 pdb_set_pass_last_set_time (pwd, last_set_time,
3925 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
3927 /* update the SAMBA password */
3928 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3935 /*******************************************************************
3937 ********************************************************************/
3939 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
3940 struct samr_UserInfo25 *id25,
3946 DEBUG(5, ("set_user_info_25: NULL id25\n"));
3947 return NT_STATUS_INVALID_PARAMETER;
3950 if (id25->info.fields_present == 0) {
3951 return NT_STATUS_INVALID_PARAMETER;
3954 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3955 return NT_STATUS_ACCESS_DENIED;
3958 copy_id25_to_sam_passwd(pwd, id25);
3960 /* write the change out */
3961 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3966 * We need to "pdb_update_sam_account" before the unix primary group
3967 * is set, because the idealx scripts would also change the
3968 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
3969 * the delete explicit / add explicit, which would then fail to find
3970 * the previous primaryGroupSid value.
3973 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3974 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3975 if ( !NT_STATUS_IS_OK(status) ) {
3980 return NT_STATUS_OK;
3983 /*******************************************************************
3985 ********************************************************************/
3987 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
3988 struct samr_SetUserInfo *r)
3991 struct samu *pwd = NULL;
3993 union samr_UserInfo *info = r->in.info;
3994 uint16_t switch_value = r->in.level;
3995 uint32_t acc_granted;
3996 uint32_t acc_required;
3998 bool has_enough_rights = False;
4000 DISP_INFO *disp_info = NULL;
4002 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4004 /* find the policy handle. open a policy on it. */
4005 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, &disp_info)) {
4006 return NT_STATUS_INVALID_HANDLE;
4009 /* This is tricky. A WinXP domain join sets
4010 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4011 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4012 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4013 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4014 we'll use the set from the WinXP join as the basis. */
4016 switch (switch_value) {
4021 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4024 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4025 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4026 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4030 status = access_check_samr_function(acc_granted,
4032 "_samr_SetUserInfo");
4033 if (!NT_STATUS_IS_OK(status)) {
4037 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4038 sid_string_dbg(&sid), switch_value));
4041 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4042 return NT_STATUS_INVALID_INFO_CLASS;
4045 if (!(pwd = samu_new(NULL))) {
4046 return NT_STATUS_NO_MEMORY;
4050 ret = pdb_getsampwsid(pwd, &sid);
4055 return NT_STATUS_NO_SUCH_USER;
4058 /* deal with machine password changes differently from userinfo changes */
4059 /* check to see if we have the sufficient rights */
4061 acb_info = pdb_get_acct_ctrl(pwd);
4062 if (acb_info & ACB_WSTRUST)
4063 has_enough_rights = user_has_privileges(p->server_info->ptok,
4064 &se_machine_account);
4065 else if (acb_info & ACB_NORMAL)
4066 has_enough_rights = user_has_privileges(p->server_info->ptok,
4068 else if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
4069 if (lp_enable_privileges()) {
4070 has_enough_rights = nt_token_check_domain_rid(p->server_info->ptok,
4071 DOMAIN_GROUP_RID_ADMINS);
4075 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4076 uidtoname(p->server_info->utok.uid),
4077 has_enough_rights ? "" : " not"));
4079 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4081 if (has_enough_rights) {
4085 /* ok! user info levels (lots: see MSDEV help), off we go... */
4087 switch (switch_value) {
4090 status = set_user_info_7(p->mem_ctx,
4095 if (!set_user_info_16(&info->info16, pwd)) {
4096 status = NT_STATUS_ACCESS_DENIED;
4101 /* Used by AS/U JRA. */
4102 status = set_user_info_18(&info->info18,
4104 &p->server_info->user_session_key,
4109 if (!set_user_info_20(&info->info20, pwd)) {
4110 status = NT_STATUS_ACCESS_DENIED;
4115 status = set_user_info_21(p->mem_ctx,
4116 &info->info21, pwd);
4120 if (!p->server_info->user_session_key.length) {
4121 status = NT_STATUS_NO_USER_SESSION_KEY;
4123 SamOEMhashBlob(info->info23.password.data, 516,
4124 &p->server_info->user_session_key);
4126 dump_data(100, info->info23.password.data, 516);
4128 status = set_user_info_23(p->mem_ctx,
4129 &info->info23, pwd);
4133 if (!p->server_info->user_session_key.length) {
4134 status = NT_STATUS_NO_USER_SESSION_KEY;
4136 SamOEMhashBlob(info->info24.password.data,
4138 &p->server_info->user_session_key);
4140 dump_data(100, info->info24.password.data, 516);
4142 if (!set_user_info_pw(info->info24.password.data, pwd,
4144 status = NT_STATUS_WRONG_PASSWORD;
4149 if (!p->server_info->user_session_key.length) {
4150 status = NT_STATUS_NO_USER_SESSION_KEY;
4152 encode_or_decode_arc4_passwd_buffer(
4153 info->info25.password.data,
4154 &p->server_info->user_session_key);
4156 dump_data(100, info->info25.password.data, 532);
4158 status = set_user_info_25(p->mem_ctx,
4159 &info->info25, pwd);
4160 if (!NT_STATUS_IS_OK(status)) {
4163 if (!set_user_info_pw(info->info25.password.data, pwd,
4165 status = NT_STATUS_WRONG_PASSWORD;
4170 if (!p->server_info->user_session_key.length) {
4171 status = NT_STATUS_NO_USER_SESSION_KEY;
4173 encode_or_decode_arc4_passwd_buffer(
4174 info->info26.password.data,
4175 &p->server_info->user_session_key);
4177 dump_data(100, info->info26.password.data, 516);
4179 if (!set_user_info_pw(info->info26.password.data, pwd,
4181 status = NT_STATUS_WRONG_PASSWORD;
4186 status = NT_STATUS_INVALID_INFO_CLASS;
4193 if (has_enough_rights) {
4197 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4199 if (NT_STATUS_IS_OK(status)) {
4200 force_flush_samr_cache(disp_info);
4206 /*******************************************************************
4208 ********************************************************************/
4210 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
4211 struct samr_SetUserInfo2 *r)
4213 struct samr_SetUserInfo q;
4215 q.in.user_handle = r->in.user_handle;
4216 q.in.level = r->in.level;
4217 q.in.info = r->in.info;
4219 return _samr_SetUserInfo(p, &q);
4222 /*********************************************************************
4223 _samr_GetAliasMembership
4224 *********************************************************************/
4226 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
4227 struct samr_GetAliasMembership *r)
4229 size_t num_alias_rids;
4231 struct samr_info *info = NULL;
4239 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
4241 /* find the policy handle. open a policy on it. */
4242 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
4243 return NT_STATUS_INVALID_HANDLE;
4245 ntstatus1 = access_check_samr_function(info->acc_granted,
4246 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
4247 "_samr_GetAliasMembership");
4248 ntstatus2 = access_check_samr_function(info->acc_granted,
4249 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4250 "_samr_GetAliasMembership");
4252 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
4253 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
4254 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
4255 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
4259 if (!sid_check_is_domain(&info->sid) &&
4260 !sid_check_is_builtin(&info->sid))
4261 return NT_STATUS_OBJECT_TYPE_MISMATCH;
4263 if (r->in.sids->num_sids) {
4264 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
4266 if (members == NULL)
4267 return NT_STATUS_NO_MEMORY;
4272 for (i=0; i<r->in.sids->num_sids; i++)
4273 sid_copy(&members[i], r->in.sids->sids[i].sid);
4279 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
4280 r->in.sids->num_sids,
4281 &alias_rids, &num_alias_rids);
4284 if (!NT_STATUS_IS_OK(ntstatus1)) {
4288 r->out.rids->count = num_alias_rids;
4289 r->out.rids->ids = alias_rids;
4291 return NT_STATUS_OK;
4294 /*********************************************************************
4295 _samr_GetMembersInAlias
4296 *********************************************************************/
4298 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
4299 struct samr_GetMembersInAlias *r)
4303 size_t num_sids = 0;
4304 struct lsa_SidPtr *sids = NULL;
4305 DOM_SID *pdb_sids = NULL;
4311 /* find the policy handle. open a policy on it. */
4312 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
4313 return NT_STATUS_INVALID_HANDLE;
4315 status = access_check_samr_function(acc_granted,
4316 SAMR_ALIAS_ACCESS_GET_MEMBERS,
4317 "_samr_GetMembersInAlias");
4318 if (!NT_STATUS_IS_OK(status)) {
4322 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4325 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
4328 if (!NT_STATUS_IS_OK(status)) {
4333 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
4335 TALLOC_FREE(pdb_sids);
4336 return NT_STATUS_NO_MEMORY;
4340 for (i = 0; i < num_sids; i++) {
4341 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
4343 TALLOC_FREE(pdb_sids);
4344 return NT_STATUS_NO_MEMORY;
4348 r->out.sids->num_sids = num_sids;
4349 r->out.sids->sids = sids;
4351 TALLOC_FREE(pdb_sids);
4353 return NT_STATUS_OK;
4356 /*********************************************************************
4357 _samr_QueryGroupMember
4358 *********************************************************************/
4360 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
4361 struct samr_QueryGroupMember *r)
4364 size_t i, num_members;
4372 struct samr_RidTypeArray *rids = NULL;
4374 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
4376 return NT_STATUS_NO_MEMORY;
4379 /* find the policy handle. open a policy on it. */
4380 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
4381 return NT_STATUS_INVALID_HANDLE;
4383 status = access_check_samr_function(acc_granted,
4384 SAMR_GROUP_ACCESS_GET_MEMBERS,
4385 "_samr_QueryGroupMember");
4386 if (!NT_STATUS_IS_OK(status)) {
4390 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4392 if (!sid_check_is_in_our_domain(&group_sid)) {
4393 DEBUG(3, ("sid %s is not in our domain\n",
4394 sid_string_dbg(&group_sid)));
4395 return NT_STATUS_NO_SUCH_GROUP;
4398 DEBUG(10, ("lookup on Domain SID\n"));
4401 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
4402 &rid, &num_members);
4405 if (!NT_STATUS_IS_OK(status))
4409 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
4411 return NT_STATUS_NO_MEMORY;
4417 for (i=0; i<num_members; i++)
4418 attr[i] = SID_NAME_USER;
4420 rids->count = num_members;
4424 *r->out.rids = rids;
4426 return NT_STATUS_OK;
4429 /*********************************************************************
4430 _samr_AddAliasMember
4431 *********************************************************************/
4433 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
4434 struct samr_AddAliasMember *r)
4439 bool can_add_accounts;
4441 DISP_INFO *disp_info = NULL;
4443 /* Find the policy handle. Open a policy on it. */
4444 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4445 return NT_STATUS_INVALID_HANDLE;
4447 status = access_check_samr_function(acc_granted,
4448 SAMR_ALIAS_ACCESS_ADD_MEMBER,
4449 "_samr_AddAliasMember");
4450 if (!NT_STATUS_IS_OK(status)) {
4454 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4456 se_priv_copy( &se_rights, &se_add_users );
4457 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4459 /******** BEGIN SeAddUsers BLOCK *********/
4461 if ( can_add_accounts )
4464 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
4466 if ( can_add_accounts )
4469 /******** END SeAddUsers BLOCK *********/
4471 if (NT_STATUS_IS_OK(status)) {
4472 force_flush_samr_cache(disp_info);
4478 /*********************************************************************
4479 _samr_DeleteAliasMember
4480 *********************************************************************/
4482 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
4483 struct samr_DeleteAliasMember *r)
4488 bool can_add_accounts;
4490 DISP_INFO *disp_info = NULL;
4492 /* Find the policy handle. Open a policy on it. */
4493 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4494 return NT_STATUS_INVALID_HANDLE;
4496 status = access_check_samr_function(acc_granted,
4497 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
4498 "_samr_DeleteAliasMember");
4499 if (!NT_STATUS_IS_OK(status)) {
4503 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4504 sid_string_dbg(&alias_sid)));
4506 se_priv_copy( &se_rights, &se_add_users );
4507 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4509 /******** BEGIN SeAddUsers BLOCK *********/
4511 if ( can_add_accounts )
4514 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
4516 if ( can_add_accounts )
4519 /******** END SeAddUsers BLOCK *********/
4521 if (NT_STATUS_IS_OK(status)) {
4522 force_flush_samr_cache(disp_info);
4528 /*********************************************************************
4529 _samr_AddGroupMember
4530 *********************************************************************/
4532 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
4533 struct samr_AddGroupMember *r)
4540 bool can_add_accounts;
4541 DISP_INFO *disp_info = NULL;
4543 /* Find the policy handle. Open a policy on it. */
4544 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4545 return NT_STATUS_INVALID_HANDLE;
4547 status = access_check_samr_function(acc_granted,
4548 SAMR_GROUP_ACCESS_ADD_MEMBER,
4549 "_samr_AddGroupMember");
4550 if (!NT_STATUS_IS_OK(status)) {
4554 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4556 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4558 return NT_STATUS_INVALID_HANDLE;
4561 se_priv_copy( &se_rights, &se_add_users );
4562 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4564 /******** BEGIN SeAddUsers BLOCK *********/
4566 if ( can_add_accounts )
4569 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
4571 if ( can_add_accounts )
4574 /******** END SeAddUsers BLOCK *********/
4576 force_flush_samr_cache(disp_info);
4581 /*********************************************************************
4582 _samr_DeleteGroupMember
4583 *********************************************************************/
4585 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
4586 struct samr_DeleteGroupMember *r)
4594 bool can_add_accounts;
4595 DISP_INFO *disp_info = NULL;
4598 * delete the group member named r->in.rid
4599 * who is a member of the sid associated with the handle
4600 * the rid is a user's rid as the group is a domain group.
4603 /* Find the policy handle. Open a policy on it. */
4604 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4605 return NT_STATUS_INVALID_HANDLE;
4607 status = access_check_samr_function(acc_granted,
4608 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
4609 "_samr_DeleteGroupMember");
4610 if (!NT_STATUS_IS_OK(status)) {
4614 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4616 return NT_STATUS_INVALID_HANDLE;
4619 se_priv_copy( &se_rights, &se_add_users );
4620 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4622 /******** BEGIN SeAddUsers BLOCK *********/
4624 if ( can_add_accounts )
4627 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
4629 if ( can_add_accounts )
4632 /******** END SeAddUsers BLOCK *********/
4634 force_flush_samr_cache(disp_info);
4639 /*********************************************************************
4641 *********************************************************************/
4643 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4644 struct samr_DeleteUser *r)
4648 struct samu *sam_pass=NULL;
4650 bool can_add_accounts;
4652 DISP_INFO *disp_info = NULL;
4655 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4657 /* Find the policy handle. Open a policy on it. */
4658 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4659 return NT_STATUS_INVALID_HANDLE;
4661 status = access_check_samr_function(acc_granted,
4662 STD_RIGHT_DELETE_ACCESS,
4663 "_samr_DeleteUser");
4664 if (!NT_STATUS_IS_OK(status)) {
4668 if (!sid_check_is_in_our_domain(&user_sid))
4669 return NT_STATUS_CANNOT_DELETE;
4671 /* check if the user exists before trying to delete */
4672 if ( !(sam_pass = samu_new( NULL )) ) {
4673 return NT_STATUS_NO_MEMORY;
4677 ret = pdb_getsampwsid(sam_pass, &user_sid);
4681 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4682 sid_string_dbg(&user_sid)));
4683 TALLOC_FREE(sam_pass);
4684 return NT_STATUS_NO_SUCH_USER;
4687 acb_info = pdb_get_acct_ctrl(sam_pass);
4689 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4690 if ( acb_info & ACB_WSTRUST ) {
4691 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_machine_account );
4693 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
4696 /******** BEGIN SeAddUsers BLOCK *********/
4698 if ( can_add_accounts )
4701 status = pdb_delete_user(p->mem_ctx, sam_pass);
4703 if ( can_add_accounts )
4706 /******** END SeAddUsers BLOCK *********/
4708 if ( !NT_STATUS_IS_OK(status) ) {
4709 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4710 "user %s: %s.\n", pdb_get_username(sam_pass),
4711 nt_errstr(status)));
4712 TALLOC_FREE(sam_pass);
4717 TALLOC_FREE(sam_pass);
4719 if (!close_policy_hnd(p, r->in.user_handle))
4720 return NT_STATUS_OBJECT_NAME_INVALID;
4722 ZERO_STRUCTP(r->out.user_handle);
4724 force_flush_samr_cache(disp_info);
4726 return NT_STATUS_OK;
4729 /*********************************************************************
4730 _samr_DeleteDomainGroup
4731 *********************************************************************/
4733 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4734 struct samr_DeleteDomainGroup *r)
4741 bool can_add_accounts;
4742 DISP_INFO *disp_info = NULL;
4744 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4746 /* Find the policy handle. Open a policy on it. */
4747 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4748 return NT_STATUS_INVALID_HANDLE;
4750 status = access_check_samr_function(acc_granted,
4751 STD_RIGHT_DELETE_ACCESS,
4752 "_samr_DeleteDomainGroup");
4753 if (!NT_STATUS_IS_OK(status)) {
4757 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4759 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4761 return NT_STATUS_NO_SUCH_GROUP;
4764 se_priv_copy( &se_rights, &se_add_users );
4765 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4767 /******** BEGIN SeAddUsers BLOCK *********/
4769 if ( can_add_accounts )
4772 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4774 if ( can_add_accounts )
4777 /******** END SeAddUsers BLOCK *********/
4779 if ( !NT_STATUS_IS_OK(status) ) {
4780 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4781 "entry for group %s: %s\n",
4782 sid_string_dbg(&group_sid),
4783 nt_errstr(status)));
4787 if (!close_policy_hnd(p, r->in.group_handle))
4788 return NT_STATUS_OBJECT_NAME_INVALID;
4790 force_flush_samr_cache(disp_info);
4792 return NT_STATUS_OK;
4795 /*********************************************************************
4796 _samr_DeleteDomAlias
4797 *********************************************************************/
4799 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4800 struct samr_DeleteDomAlias *r)
4805 bool can_add_accounts;
4807 DISP_INFO *disp_info = NULL;
4809 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4811 /* Find the policy handle. Open a policy on it. */
4812 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4813 return NT_STATUS_INVALID_HANDLE;
4815 /* copy the handle to the outgoing reply */
4817 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4819 status = access_check_samr_function(acc_granted,
4820 STD_RIGHT_DELETE_ACCESS,
4821 "_samr_DeleteDomAlias");
4822 if (!NT_STATUS_IS_OK(status)) {
4826 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4828 /* Don't let Windows delete builtin groups */
4830 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4831 return NT_STATUS_SPECIAL_ACCOUNT;
4834 if (!sid_check_is_in_our_domain(&alias_sid))
4835 return NT_STATUS_NO_SUCH_ALIAS;
4837 DEBUG(10, ("lookup on Local SID\n"));
4839 se_priv_copy( &se_rights, &se_add_users );
4840 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4842 /******** BEGIN SeAddUsers BLOCK *********/
4844 if ( can_add_accounts )
4847 /* Have passdb delete the alias */
4848 status = pdb_delete_alias(&alias_sid);
4850 if ( can_add_accounts )
4853 /******** END SeAddUsers BLOCK *********/
4855 if ( !NT_STATUS_IS_OK(status))
4858 if (!close_policy_hnd(p, r->in.alias_handle))
4859 return NT_STATUS_OBJECT_NAME_INVALID;
4861 force_flush_samr_cache(disp_info);
4863 return NT_STATUS_OK;
4866 /*********************************************************************
4867 _samr_CreateDomainGroup
4868 *********************************************************************/
4870 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4871 struct samr_CreateDomainGroup *r)
4878 struct samr_info *info;
4881 bool can_add_accounts;
4882 DISP_INFO *disp_info = NULL;
4884 /* Find the policy handle. Open a policy on it. */
4885 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4886 return NT_STATUS_INVALID_HANDLE;
4888 status = access_check_samr_function(acc_granted,
4889 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
4890 "_samr_CreateDomainGroup");
4891 if (!NT_STATUS_IS_OK(status)) {
4895 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4896 return NT_STATUS_ACCESS_DENIED;
4898 name = r->in.name->string;
4900 return NT_STATUS_NO_MEMORY;
4903 status = can_create(p->mem_ctx, name);
4904 if (!NT_STATUS_IS_OK(status)) {
4908 se_priv_copy( &se_rights, &se_add_users );
4909 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4911 /******** BEGIN SeAddUsers BLOCK *********/
4913 if ( can_add_accounts )
4916 /* check that we successfully create the UNIX group */
4918 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4920 if ( can_add_accounts )
4923 /******** END SeAddUsers BLOCK *********/
4925 /* check if we should bail out here */
4927 if ( !NT_STATUS_IS_OK(status) )
4930 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
4932 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
4933 return NT_STATUS_NO_MEMORY;
4935 /* they created it; let the user do what he wants with it */
4937 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
4939 /* get a (unique) handle. open a policy on it. */
4940 if (!create_policy_hnd(p, r->out.group_handle, info))
4941 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4943 force_flush_samr_cache(disp_info);
4945 return NT_STATUS_OK;
4948 /*********************************************************************
4949 _samr_CreateDomAlias
4950 *********************************************************************/
4952 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
4953 struct samr_CreateDomAlias *r)
4957 const char *name = NULL;
4958 struct samr_info *info;
4963 bool can_add_accounts;
4964 DISP_INFO *disp_info = NULL;
4966 /* Find the policy handle. Open a policy on it. */
4967 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4968 return NT_STATUS_INVALID_HANDLE;
4970 result = access_check_samr_function(acc_granted,
4971 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
4972 "_samr_CreateDomAlias");
4973 if (!NT_STATUS_IS_OK(result)) {
4977 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4978 return NT_STATUS_ACCESS_DENIED;
4980 name = r->in.alias_name->string;
4982 se_priv_copy( &se_rights, &se_add_users );
4983 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4985 result = can_create(p->mem_ctx, name);
4986 if (!NT_STATUS_IS_OK(result)) {
4990 /******** BEGIN SeAddUsers BLOCK *********/
4992 if ( can_add_accounts )
4995 /* Have passdb create the alias */
4996 result = pdb_create_alias(name, r->out.rid);
4998 if ( can_add_accounts )
5001 /******** END SeAddUsers BLOCK *********/
5003 if (!NT_STATUS_IS_OK(result)) {
5004 DEBUG(10, ("pdb_create_alias failed: %s\n",
5005 nt_errstr(result)));
5009 sid_copy(&info_sid, get_global_sam_sid());
5010 sid_append_rid(&info_sid, *r->out.rid);
5012 if (!sid_to_gid(&info_sid, &gid)) {
5013 DEBUG(10, ("Could not find alias just created\n"));
5014 return NT_STATUS_ACCESS_DENIED;
5017 /* check if the group has been successfully created */
5018 if ( getgrgid(gid) == NULL ) {
5019 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5021 return NT_STATUS_ACCESS_DENIED;
5024 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5025 return NT_STATUS_NO_MEMORY;
5027 /* they created it; let the user do what he wants with it */
5029 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5031 /* get a (unique) handle. open a policy on it. */
5032 if (!create_policy_hnd(p, r->out.alias_handle, info))
5033 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5035 force_flush_samr_cache(disp_info);
5037 return NT_STATUS_OK;
5040 /*********************************************************************
5041 _samr_QueryGroupInfo
5042 *********************************************************************/
5044 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5045 struct samr_QueryGroupInfo *r)
5050 union samr_GroupInfo *info = NULL;
5053 uint32_t attributes = SE_GROUP_MANDATORY |
5054 SE_GROUP_ENABLED_BY_DEFAULT |
5056 const char *group_name = NULL;
5057 const char *group_description = NULL;
5059 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5060 return NT_STATUS_INVALID_HANDLE;
5062 status = access_check_samr_function(acc_granted,
5063 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5064 "_samr_QueryGroupInfo");
5065 if (!NT_STATUS_IS_OK(status)) {
5070 ret = get_domain_group_from_sid(group_sid, &map);
5073 return NT_STATUS_INVALID_HANDLE;
5075 /* FIXME: map contains fstrings */
5076 group_name = talloc_strdup(r, map.nt_name);
5077 group_description = talloc_strdup(r, map.comment);
5079 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5081 return NT_STATUS_NO_MEMORY;
5084 switch (r->in.level) {
5090 status = pdb_enum_group_members(
5091 p->mem_ctx, &group_sid, &members, &num_members);
5094 if (!NT_STATUS_IS_OK(status)) {
5098 info->all.name.string = group_name;
5099 info->all.attributes = attributes;
5100 info->all.num_members = num_members;
5101 info->all.description.string = group_description;
5105 info->name.string = group_name;
5108 info->attributes.attributes = attributes;
5111 info->description.string = group_description;
5121 status = pdb_enum_group_members(
5122 p->mem_ctx, &group_sid, &members, &num_members);
5125 if (!NT_STATUS_IS_OK(status)) {
5129 info->all2.name.string = group_name;
5130 info->all2.attributes = attributes;
5131 info->all2.num_members = 0; /* num_members - in w2k3 this is always 0 */
5132 info->all2.description.string = group_description;
5137 return NT_STATUS_INVALID_INFO_CLASS;
5140 *r->out.info = info;
5142 return NT_STATUS_OK;
5145 /*********************************************************************
5147 *********************************************************************/
5149 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5150 struct samr_SetGroupInfo *r)
5157 bool can_mod_accounts;
5158 DISP_INFO *disp_info = NULL;
5160 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5161 return NT_STATUS_INVALID_HANDLE;
5163 status = access_check_samr_function(acc_granted,
5164 SAMR_GROUP_ACCESS_SET_INFO,
5165 "_samr_SetGroupInfo");
5166 if (!NT_STATUS_IS_OK(status)) {
5171 ret = get_domain_group_from_sid(group_sid, &map);
5174 return NT_STATUS_NO_SUCH_GROUP;
5176 switch (r->in.level) {
5178 fstrcpy(map.comment, r->in.info->all.description.string);
5181 /* group rename is not supported yet */
5182 return NT_STATUS_NOT_SUPPORTED;
5184 fstrcpy(map.comment, r->in.info->description.string);
5187 return NT_STATUS_INVALID_INFO_CLASS;
5190 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5192 /******** BEGIN SeAddUsers BLOCK *********/
5194 if ( can_mod_accounts )
5197 status = pdb_update_group_mapping_entry(&map);
5199 if ( can_mod_accounts )
5202 /******** End SeAddUsers BLOCK *********/
5204 if (NT_STATUS_IS_OK(status)) {
5205 force_flush_samr_cache(disp_info);
5211 /*********************************************************************
5213 *********************************************************************/
5215 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5216 struct samr_SetAliasInfo *r)
5219 struct acct_info info;
5221 bool can_mod_accounts;
5223 DISP_INFO *disp_info = NULL;
5225 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
5226 return NT_STATUS_INVALID_HANDLE;
5228 status = access_check_samr_function(acc_granted,
5229 SAMR_ALIAS_ACCESS_SET_INFO,
5230 "_samr_SetAliasInfo");
5231 if (!NT_STATUS_IS_OK(status)) {
5235 /* get the current group information */
5238 status = pdb_get_aliasinfo( &group_sid, &info );
5241 if ( !NT_STATUS_IS_OK(status))
5244 switch (r->in.level) {
5249 /* We currently do not support renaming groups in the
5250 the BUILTIN domain. Refer to util_builtin.c to understand
5251 why. The eventually needs to be fixed to be like Windows
5252 where you can rename builtin groups, just not delete them */
5254 if ( sid_check_is_in_builtin( &group_sid ) ) {
5255 return NT_STATUS_SPECIAL_ACCOUNT;
5258 /* There has to be a valid name (and it has to be different) */
5260 if ( !r->in.info->name.string )
5261 return NT_STATUS_INVALID_PARAMETER;
5263 /* If the name is the same just reply "ok". Yes this
5264 doesn't allow you to change the case of a group name. */
5266 if ( strequal( r->in.info->name.string, info.acct_name ) )
5267 return NT_STATUS_OK;
5269 fstrcpy( info.acct_name, r->in.info->name.string);
5271 /* make sure the name doesn't already exist as a user
5274 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
5275 status = can_create( p->mem_ctx, group_name );
5276 if ( !NT_STATUS_IS_OK( status ) )
5280 case ALIASINFODESCRIPTION:
5281 if (r->in.info->description.string) {
5282 fstrcpy(info.acct_desc,
5283 r->in.info->description.string);
5285 fstrcpy( info.acct_desc, "" );
5289 return NT_STATUS_INVALID_INFO_CLASS;
5292 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5294 /******** BEGIN SeAddUsers BLOCK *********/
5296 if ( can_mod_accounts )
5299 status = pdb_set_aliasinfo( &group_sid, &info );
5301 if ( can_mod_accounts )
5304 /******** End SeAddUsers BLOCK *********/
5306 if (NT_STATUS_IS_OK(status))
5307 force_flush_samr_cache(disp_info);
5312 /****************************************************************
5314 ****************************************************************/
5316 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
5317 struct samr_GetDomPwInfo *r)
5319 uint32_t min_password_length = 0;
5320 uint32_t password_properties = 0;
5322 /* Perform access check. Since this rpc does not require a
5323 policy handle it will not be caught by the access checks on
5324 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5326 if (!pipe_access_check(p)) {
5327 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5328 return NT_STATUS_ACCESS_DENIED;
5332 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
5333 &min_password_length);
5334 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
5335 &password_properties);
5338 if (lp_check_password_script() && *lp_check_password_script()) {
5339 password_properties |= DOMAIN_PASSWORD_COMPLEX;
5342 r->out.info->min_password_length = min_password_length;
5343 r->out.info->password_properties = password_properties;
5345 return NT_STATUS_OK;
5348 /*********************************************************************
5350 *********************************************************************/
5352 NTSTATUS _samr_OpenGroup(pipes_struct *p,
5353 struct samr_OpenGroup *r)
5359 struct samr_info *info;
5360 SEC_DESC *psd = NULL;
5362 uint32 des_access = r->in.access_mask;
5369 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
5370 return NT_STATUS_INVALID_HANDLE;
5372 status = access_check_samr_function(acc_granted,
5373 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5376 if ( !NT_STATUS_IS_OK(status) )
5379 /*check if access can be granted as requested by client. */
5380 map_max_allowed_access(p->server_info->ptok, &des_access);
5382 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
5383 se_map_generic(&des_access,&grp_generic_mapping);
5385 se_priv_copy( &se_rights, &se_add_users );
5387 status = access_check_samr_object(psd, p->server_info->ptok,
5388 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
5389 &acc_granted, "_samr_OpenGroup");
5391 if ( !NT_STATUS_IS_OK(status) )
5394 /* this should not be hard-coded like this */
5396 if (!sid_equal(&sid, get_global_sam_sid()))
5397 return NT_STATUS_ACCESS_DENIED;
5399 sid_copy(&info_sid, get_global_sam_sid());
5400 sid_append_rid(&info_sid, r->in.rid);
5401 sid_to_fstring(sid_string, &info_sid);
5403 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5404 return NT_STATUS_NO_MEMORY;
5406 info->acc_granted = acc_granted;
5408 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
5410 /* check if that group really exists */
5412 ret = get_domain_group_from_sid(info->sid, &map);
5415 return NT_STATUS_NO_SUCH_GROUP;
5417 /* get a (unique) handle. open a policy on it. */
5418 if (!create_policy_hnd(p, r->out.group_handle, info))
5419 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5421 return NT_STATUS_OK;
5424 /*********************************************************************
5425 _samr_RemoveMemberFromForeignDomain
5426 *********************************************************************/
5428 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5429 struct samr_RemoveMemberFromForeignDomain *r)
5431 DOM_SID delete_sid, domain_sid;
5434 DISP_INFO *disp_info = NULL;
5436 sid_copy( &delete_sid, r->in.sid );
5438 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5439 sid_string_dbg(&delete_sid)));
5441 /* Find the policy handle. Open a policy on it. */
5443 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
5444 &acc_granted, &disp_info))
5445 return NT_STATUS_INVALID_HANDLE;
5447 result = access_check_samr_function(acc_granted,
5448 STD_RIGHT_DELETE_ACCESS,
5449 "_samr_RemoveMemberFromForeignDomain");
5451 if (!NT_STATUS_IS_OK(result))
5454 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5455 sid_string_dbg(&domain_sid)));
5457 /* we can only delete a user from a group since we don't have
5458 nested groups anyways. So in the latter case, just say OK */
5460 /* TODO: The above comment nowadays is bogus. Since we have nested
5461 * groups now, and aliases members are never reported out of the unix
5462 * group membership, the "just say OK" makes this call a no-op. For
5463 * us. This needs fixing however. */
5465 /* I've only ever seen this in the wild when deleting a user from
5466 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5467 * is the user about to be deleted. I very much suspect this is the
5468 * only application of this call. To verify this, let people report
5471 if (!sid_check_is_builtin(&domain_sid)) {
5472 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5473 "global_sam_sid() = %s\n",
5474 sid_string_dbg(&domain_sid),
5475 sid_string_dbg(get_global_sam_sid())));
5476 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5477 return NT_STATUS_OK;
5480 force_flush_samr_cache(disp_info);
5482 result = NT_STATUS_OK;
5487 /*******************************************************************
5488 _samr_QueryDomainInfo2
5489 ********************************************************************/
5491 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5492 struct samr_QueryDomainInfo2 *r)
5494 struct samr_QueryDomainInfo q;
5496 q.in.domain_handle = r->in.domain_handle;
5497 q.in.level = r->in.level;
5499 q.out.info = r->out.info;
5501 return _samr_QueryDomainInfo(p, &q);
5504 /*******************************************************************
5506 ********************************************************************/
5508 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5509 struct samr_SetDomainInfo *r)
5511 struct samr_info *info = NULL;
5512 time_t u_expire, u_min_age;
5514 time_t u_lock_duration, u_reset_time;
5517 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5519 /* find the policy handle. open a policy on it. */
5520 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5521 return NT_STATUS_INVALID_HANDLE;
5523 /* We do have different access bits for info
5524 * levels here, but we're really just looking for
5525 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5526 * this maps to different specific bits. So
5527 * assume if we have SAMR_DOMAIN_ACCESS_SET_INFO_1
5530 result = access_check_samr_function(info->acc_granted,
5531 SAMR_DOMAIN_ACCESS_SET_INFO_1,
5532 "_samr_SetDomainInfo");
5534 if (!NT_STATUS_IS_OK(result))
5537 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
5539 switch (r->in.level) {
5541 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
5542 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
5543 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
5544 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
5545 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
5546 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5547 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5552 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
5553 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5562 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
5563 if (u_lock_duration != -1)
5564 u_lock_duration /= 60;
5566 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
5568 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5569 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5570 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
5573 return NT_STATUS_INVALID_INFO_CLASS;
5576 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5578 return NT_STATUS_OK;
5581 /****************************************************************
5582 _samr_GetDisplayEnumerationIndex
5583 ****************************************************************/
5585 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5586 struct samr_GetDisplayEnumerationIndex *r)
5588 struct samr_info *info = NULL;
5589 uint32_t max_entries = (uint32_t) -1;
5590 uint32_t enum_context = 0;
5592 uint32_t num_account = 0;
5593 struct samr_displayentry *entries = NULL;
5596 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
5598 /* find the policy handle. open a policy on it. */
5599 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
5600 return NT_STATUS_INVALID_HANDLE;
5603 status = access_check_samr_function(info->acc_granted,
5604 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
5605 "_samr_GetDisplayEnumerationIndex");
5606 if (!NT_STATUS_IS_OK(status)) {
5610 if ((r->in.level < 1) || (r->in.level > 3)) {
5611 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5612 "Unknown info level (%u)\n",
5614 return NT_STATUS_INVALID_INFO_CLASS;
5619 /* The following done as ROOT. Don't return without unbecome_root(). */
5621 switch (r->in.level) {
5623 if (info->disp_info->users == NULL) {
5624 info->disp_info->users = pdb_search_users(
5625 info->disp_info, ACB_NORMAL);
5626 if (info->disp_info->users == NULL) {
5628 return NT_STATUS_ACCESS_DENIED;
5630 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5631 "starting user enumeration at index %u\n",
5632 (unsigned int)enum_context));
5634 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5635 "using cached user enumeration at index %u\n",
5636 (unsigned int)enum_context));
5638 num_account = pdb_search_entries(info->disp_info->users,
5639 enum_context, max_entries,
5643 if (info->disp_info->machines == NULL) {
5644 info->disp_info->machines = pdb_search_users(
5645 info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
5646 if (info->disp_info->machines == NULL) {
5648 return NT_STATUS_ACCESS_DENIED;
5650 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5651 "starting machine enumeration at index %u\n",
5652 (unsigned int)enum_context));
5654 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5655 "using cached machine enumeration at index %u\n",
5656 (unsigned int)enum_context));
5658 num_account = pdb_search_entries(info->disp_info->machines,
5659 enum_context, max_entries,
5663 if (info->disp_info->groups == NULL) {
5664 info->disp_info->groups = pdb_search_groups(
5666 if (info->disp_info->groups == NULL) {
5668 return NT_STATUS_ACCESS_DENIED;
5670 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5671 "starting group enumeration at index %u\n",
5672 (unsigned int)enum_context));
5674 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5675 "using cached group enumeration at index %u\n",
5676 (unsigned int)enum_context));
5678 num_account = pdb_search_entries(info->disp_info->groups,
5679 enum_context, max_entries,
5684 smb_panic("info class changed");
5690 /* Ensure we cache this enumeration. */
5691 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
5693 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5694 r->in.name->string));
5696 for (i=0; i<num_account; i++) {
5697 if (strequal(entries[i].account_name, r->in.name->string)) {
5698 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5699 "found %s at idx %d\n",
5700 r->in.name->string, i));
5702 return NT_STATUS_OK;
5706 /* assuming account_name lives at the very end */
5707 *r->out.idx = num_account;
5709 return NT_STATUS_NO_MORE_ENTRIES;
5712 /****************************************************************
5713 _samr_GetDisplayEnumerationIndex2
5714 ****************************************************************/
5716 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5717 struct samr_GetDisplayEnumerationIndex2 *r)
5719 struct samr_GetDisplayEnumerationIndex q;
5721 q.in.domain_handle = r->in.domain_handle;
5722 q.in.level = r->in.level;
5723 q.in.name = r->in.name;
5725 q.out.idx = r->out.idx;
5727 return _samr_GetDisplayEnumerationIndex(p, &q);
5730 /****************************************************************
5731 ****************************************************************/
5733 NTSTATUS _samr_Shutdown(pipes_struct *p,
5734 struct samr_Shutdown *r)
5736 p->rng_fault_state = true;
5737 return NT_STATUS_NOT_IMPLEMENTED;
5740 /****************************************************************
5741 ****************************************************************/
5743 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5744 struct samr_SetMemberAttributesOfGroup *r)
5746 p->rng_fault_state = true;
5747 return NT_STATUS_NOT_IMPLEMENTED;
5750 /****************************************************************
5751 ****************************************************************/
5753 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5754 struct samr_ChangePasswordUser *r)
5756 p->rng_fault_state = true;
5757 return NT_STATUS_NOT_IMPLEMENTED;
5760 /****************************************************************
5761 ****************************************************************/
5763 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5764 struct samr_TestPrivateFunctionsDomain *r)
5766 p->rng_fault_state = true;
5767 return NT_STATUS_NOT_IMPLEMENTED;
5770 /****************************************************************
5771 ****************************************************************/
5773 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5774 struct samr_TestPrivateFunctionsUser *r)
5776 p->rng_fault_state = true;
5777 return NT_STATUS_NOT_IMPLEMENTED;
5780 /****************************************************************
5781 ****************************************************************/
5783 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5784 struct samr_AddMultipleMembersToAlias *r)
5786 p->rng_fault_state = true;
5787 return NT_STATUS_NOT_IMPLEMENTED;
5790 /****************************************************************
5791 ****************************************************************/
5793 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5794 struct samr_RemoveMultipleMembersFromAlias *r)
5796 p->rng_fault_state = true;
5797 return NT_STATUS_NOT_IMPLEMENTED;
5800 /****************************************************************
5801 ****************************************************************/
5803 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5804 struct samr_OemChangePasswordUser2 *r)
5806 p->rng_fault_state = true;
5807 return NT_STATUS_NOT_IMPLEMENTED;
5810 /****************************************************************
5811 ****************************************************************/
5813 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5814 struct samr_SetBootKeyInformation *r)
5816 p->rng_fault_state = true;
5817 return NT_STATUS_NOT_IMPLEMENTED;
5820 /****************************************************************
5821 ****************************************************************/
5823 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5824 struct samr_GetBootKeyInformation *r)
5826 p->rng_fault_state = true;
5827 return NT_STATUS_NOT_IMPLEMENTED;
5830 /****************************************************************
5831 ****************************************************************/
5833 NTSTATUS _samr_Connect3(pipes_struct *p,
5834 struct samr_Connect3 *r)
5836 p->rng_fault_state = true;
5837 return NT_STATUS_NOT_IMPLEMENTED;
5840 /****************************************************************
5841 ****************************************************************/
5843 NTSTATUS _samr_RidToSid(pipes_struct *p,
5844 struct samr_RidToSid *r)
5846 p->rng_fault_state = true;
5847 return NT_STATUS_NOT_IMPLEMENTED;
5850 /****************************************************************
5851 ****************************************************************/
5853 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5854 struct samr_SetDsrmPassword *r)
5856 p->rng_fault_state = true;
5857 return NT_STATUS_NOT_IMPLEMENTED;
5860 /****************************************************************
5861 ****************************************************************/
5863 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5864 struct samr_ValidatePassword *r)
5866 p->rng_fault_state = true;
5867 return NT_STATUS_NOT_IMPLEMENTED;