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 */
79 static const struct generic_mapping sam_generic_mapping = {
80 GENERIC_RIGHTS_SAM_READ,
81 GENERIC_RIGHTS_SAM_WRITE,
82 GENERIC_RIGHTS_SAM_EXECUTE,
83 GENERIC_RIGHTS_SAM_ALL_ACCESS};
84 static const struct generic_mapping dom_generic_mapping = {
85 GENERIC_RIGHTS_DOMAIN_READ,
86 GENERIC_RIGHTS_DOMAIN_WRITE,
87 GENERIC_RIGHTS_DOMAIN_EXECUTE,
88 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
89 static const struct generic_mapping usr_generic_mapping = {
90 GENERIC_RIGHTS_USER_READ,
91 GENERIC_RIGHTS_USER_WRITE,
92 GENERIC_RIGHTS_USER_EXECUTE,
93 GENERIC_RIGHTS_USER_ALL_ACCESS};
94 static const struct generic_mapping usr_nopwchange_generic_mapping = {
95 GENERIC_RIGHTS_USER_READ,
96 GENERIC_RIGHTS_USER_WRITE,
97 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
98 GENERIC_RIGHTS_USER_ALL_ACCESS};
99 static const struct generic_mapping grp_generic_mapping = {
100 GENERIC_RIGHTS_GROUP_READ,
101 GENERIC_RIGHTS_GROUP_WRITE,
102 GENERIC_RIGHTS_GROUP_EXECUTE,
103 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
104 static const struct generic_mapping ali_generic_mapping = {
105 GENERIC_RIGHTS_ALIAS_READ,
106 GENERIC_RIGHTS_ALIAS_WRITE,
107 GENERIC_RIGHTS_ALIAS_EXECUTE,
108 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
110 /*******************************************************************
111 *******************************************************************/
113 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
114 const struct generic_mapping *map,
115 DOM_SID *sid, uint32 sid_access )
117 DOM_SID domadmin_sid;
118 SEC_ACE ace[5]; /* at most 5 entries */
123 /* basic access for Everyone */
125 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
126 map->generic_execute | map->generic_read, 0);
128 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
130 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
131 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
132 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
133 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
135 /* Add Full Access for Domain Admins if we are a DC */
138 sid_copy( &domadmin_sid, get_global_sam_sid() );
139 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
140 init_sec_ace(&ace[i++], &domadmin_sid,
141 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
144 /* if we have a sid, give it some special access */
147 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
150 /* create the security descriptor */
152 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
153 return NT_STATUS_NO_MEMORY;
155 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
156 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
157 psa, sd_size)) == NULL)
158 return NT_STATUS_NO_MEMORY;
163 /*******************************************************************
164 Checks if access to an object should be granted, and returns that
165 level of access for further checks.
166 ********************************************************************/
168 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
169 SE_PRIV *rights, uint32 rights_mask,
170 uint32 des_access, uint32 *acc_granted,
173 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
174 uint32 saved_mask = 0;
176 /* check privileges; certain SAM access bits should be overridden
177 by privileges (mostly having to do with creating/modifying/deleting
180 if ( rights && user_has_any_privilege( token, rights ) ) {
182 saved_mask = (des_access & rights_mask);
183 des_access &= ~saved_mask;
185 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
190 /* check the security descriptor first */
192 status = se_access_check(psd, token, des_access, acc_granted);
193 if (NT_STATUS_IS_OK(status)) {
197 /* give root a free pass */
199 if ( geteuid() == sec_initial_uid() ) {
201 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
202 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
204 *acc_granted = des_access;
206 status = NT_STATUS_OK;
212 /* add in any bits saved during the privilege check (only
213 matters is status is ok) */
215 *acc_granted |= rights_mask;
217 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
218 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
219 des_access, *acc_granted));
224 /*******************************************************************
225 Checks if access to a function can be granted
226 ********************************************************************/
228 static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_required, const char *debug)
230 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
231 debug, acc_granted, acc_required));
233 /* check the security descriptor first */
235 if ( (acc_granted&acc_required) == acc_required )
238 /* give root a free pass */
240 if (geteuid() == sec_initial_uid()) {
242 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
243 debug, acc_granted, acc_required));
244 DEBUGADD(4,("but overwritten by euid == 0\n"));
249 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
250 debug, acc_granted, acc_required));
252 return NT_STATUS_ACCESS_DENIED;
255 /*******************************************************************
256 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
257 ********************************************************************/
259 static void map_max_allowed_access(const NT_USER_TOKEN *token,
260 uint32_t *pacc_requested)
262 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
265 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
267 /* At least try for generic read. */
268 *pacc_requested = GENERIC_READ_ACCESS;
270 /* root gets anything. */
271 if (geteuid() == sec_initial_uid()) {
272 *pacc_requested |= GENERIC_ALL_ACCESS;
276 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
278 if (is_sid_in_token(token, &global_sid_Builtin_Administrators) ||
279 is_sid_in_token(token, &global_sid_Builtin_Account_Operators)) {
280 *pacc_requested |= GENERIC_ALL_ACCESS;
284 /* Full access for DOMAIN\Domain Admins. */
286 DOM_SID domadmin_sid;
287 sid_copy( &domadmin_sid, get_global_sam_sid() );
288 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
289 if (is_sid_in_token(token, &domadmin_sid)) {
290 *pacc_requested |= GENERIC_ALL_ACCESS;
294 /* TODO ! Check privileges. */
297 /*******************************************************************
298 Fetch or create a dispinfo struct.
299 ********************************************************************/
301 static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid)
304 * We do a static cache for DISP_INFO's here. Explanation can be found
305 * in Jeremy's checkin message to r11793:
307 * Fix the SAMR cache so it works across completely insane
308 * client behaviour (ie.:
309 * open pipe/open SAMR handle/enumerate 0 - 1024
310 * close SAMR handle, close pipe.
311 * open pipe/open SAMR handle/enumerate 1024 - 2048...
312 * close SAMR handle, close pipe.
313 * And on ad-nausium. Amazing.... probably object-oriented
314 * client side programming in action yet again.
315 * This change should *massively* improve performance when
316 * enumerating users from an LDAP database.
319 * "Our" and the builtin domain are the only ones where we ever
320 * enumerate stuff, so just cache 2 entries.
323 static struct disp_info builtin_dispinfo;
324 static struct disp_info domain_dispinfo;
326 /* There are two cases to consider here:
327 1) The SID is a domain SID and we look for an equality match, or
328 2) This is an account SID and so we return the DISP_INFO* for our
335 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
337 * Necessary only once, but it does not really hurt.
339 sid_copy(&builtin_dispinfo.sid, &global_sid_Builtin);
341 return &builtin_dispinfo;
344 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
346 * Necessary only once, but it does not really hurt.
348 sid_copy(&domain_dispinfo.sid, get_global_sam_sid());
350 return &domain_dispinfo;
356 /*******************************************************************
357 Create a samr_info struct.
358 ********************************************************************/
360 static struct samr_info *get_samr_info_by_sid(DOM_SID *psid)
362 struct samr_info *info;
367 sid_to_fstring(sid_str, psid);
369 fstrcpy(sid_str,"(NULL)");
372 mem_ctx = talloc_init("samr_info for domain sid %s", sid_str);
374 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL)
377 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
379 sid_copy( &info->sid, psid);
380 info->builtin_domain = sid_check_is_builtin(psid);
382 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
383 info->builtin_domain = False;
385 info->mem_ctx = mem_ctx;
387 info->disp_info = get_samr_dispinfo_by_sid(psid);
392 /*******************************************************************
393 Function to free the per SID data.
394 ********************************************************************/
396 static void free_samr_cache(DISP_INFO *disp_info)
398 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
399 sid_string_dbg(&disp_info->sid)));
401 /* We need to become root here because the paged search might have to
402 * tell the LDAP server we're not interested in the rest anymore. */
406 if (disp_info->users) {
407 DEBUG(10,("free_samr_cache: deleting users cache\n"));
408 pdb_search_destroy(disp_info->users);
409 disp_info->users = NULL;
411 if (disp_info->machines) {
412 DEBUG(10,("free_samr_cache: deleting machines cache\n"));
413 pdb_search_destroy(disp_info->machines);
414 disp_info->machines = NULL;
416 if (disp_info->groups) {
417 DEBUG(10,("free_samr_cache: deleting groups cache\n"));
418 pdb_search_destroy(disp_info->groups);
419 disp_info->groups = NULL;
421 if (disp_info->aliases) {
422 DEBUG(10,("free_samr_cache: deleting aliases cache\n"));
423 pdb_search_destroy(disp_info->aliases);
424 disp_info->aliases = NULL;
426 if (disp_info->enum_users) {
427 DEBUG(10,("free_samr_cache: deleting enum_users cache\n"));
428 pdb_search_destroy(disp_info->enum_users);
429 disp_info->enum_users = NULL;
431 disp_info->enum_acb_mask = 0;
436 /*******************************************************************
437 Function to free the per handle data.
438 ********************************************************************/
440 static void free_samr_info(void *ptr)
442 struct samr_info *info=(struct samr_info *) ptr;
444 /* Only free the dispinfo cache if no one bothered to set up
447 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
448 free_samr_cache(info->disp_info);
451 talloc_destroy(info->mem_ctx);
454 /*******************************************************************
455 Idle event handler. Throw away the disp info cache.
456 ********************************************************************/
458 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
459 struct timed_event *te,
460 const struct timeval *now,
463 DISP_INFO *disp_info = (DISP_INFO *)private_data;
465 TALLOC_FREE(disp_info->cache_timeout_event);
467 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
469 free_samr_cache(disp_info);
472 /*******************************************************************
473 Setup cache removal idle event handler.
474 ********************************************************************/
476 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
478 /* Remove any pending timeout and update. */
480 TALLOC_FREE(disp_info->cache_timeout_event);
482 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
483 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
484 (unsigned int)secs_fromnow ));
486 disp_info->cache_timeout_event = event_add_timed(
487 smbd_event_context(), NULL,
488 timeval_current_ofs(secs_fromnow, 0),
489 "disp_info_cache_idle_timeout_handler",
490 disp_info_cache_idle_timeout_handler, (void *)disp_info);
493 /*******************************************************************
494 Force flush any cache. We do this on any samr_set_xxx call.
495 We must also remove the timeout handler.
496 ********************************************************************/
498 static void force_flush_samr_cache(DISP_INFO *disp_info)
500 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
504 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
505 TALLOC_FREE(disp_info->cache_timeout_event);
506 free_samr_cache(disp_info);
509 /*******************************************************************
510 Ensure password info is never given out. Paranioa... JRA.
511 ********************************************************************/
513 static void samr_clear_sam_passwd(struct samu *sam_pass)
519 /* These now zero out the old password */
521 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
522 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
525 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
527 struct samr_displayentry *entry;
529 if (info->builtin_domain) {
530 /* No users in builtin. */
534 if (info->users == NULL) {
535 info->users = pdb_search_users(acct_flags);
536 if (info->users == NULL) {
540 /* Fetch the last possible entry, thus trigger an enumeration */
541 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
543 /* Ensure we cache this enumeration. */
544 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
546 return info->users->num_entries;
549 static uint32 count_sam_groups(struct disp_info *info)
551 struct samr_displayentry *entry;
553 if (info->builtin_domain) {
554 /* No groups in builtin. */
558 if (info->groups == NULL) {
559 info->groups = pdb_search_groups();
560 if (info->groups == NULL) {
564 /* Fetch the last possible entry, thus trigger an enumeration */
565 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
567 /* Ensure we cache this enumeration. */
568 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
570 return info->groups->num_entries;
573 static uint32 count_sam_aliases(struct disp_info *info)
575 struct samr_displayentry *entry;
577 if (info->aliases == NULL) {
578 info->aliases = pdb_search_aliases(&info->sid);
579 if (info->aliases == NULL) {
583 /* Fetch the last possible entry, thus trigger an enumeration */
584 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
586 /* Ensure we cache this enumeration. */
587 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
589 return info->aliases->num_entries;
592 /*******************************************************************
594 ********************************************************************/
596 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
598 if (!close_policy_hnd(p, r->in.handle)) {
599 return NT_STATUS_INVALID_HANDLE;
602 ZERO_STRUCTP(r->out.handle);
607 /*******************************************************************
609 ********************************************************************/
611 NTSTATUS _samr_OpenDomain(pipes_struct *p,
612 struct samr_OpenDomain *r)
614 struct samr_info *info;
615 SEC_DESC *psd = NULL;
617 uint32 des_access = r->in.access_mask;
622 /* find the connection policy handle. */
624 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
625 return NT_STATUS_INVALID_HANDLE;
627 status = access_check_samr_function(info->acc_granted,
628 SAMR_ACCESS_OPEN_DOMAIN,
629 "_samr_OpenDomain" );
631 if ( !NT_STATUS_IS_OK(status) )
634 /*check if access can be granted as requested by client. */
635 map_max_allowed_access(p->server_info->ptok, &des_access);
637 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
638 se_map_generic( &des_access, &dom_generic_mapping );
640 se_priv_copy( &se_rights, &se_machine_account );
641 se_priv_add( &se_rights, &se_add_users );
643 status = access_check_samr_object( psd, p->server_info->ptok,
644 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
645 &acc_granted, "_samr_OpenDomain" );
647 if ( !NT_STATUS_IS_OK(status) )
650 if (!sid_check_is_domain(r->in.sid) &&
651 !sid_check_is_builtin(r->in.sid)) {
652 return NT_STATUS_NO_SUCH_DOMAIN;
655 /* associate the domain SID with the (unique) handle. */
656 if ((info = get_samr_info_by_sid(r->in.sid))==NULL)
657 return NT_STATUS_NO_MEMORY;
658 info->acc_granted = acc_granted;
660 /* get a (unique) handle. open a policy on it. */
661 if (!create_policy_hnd(p, r->out.domain_handle, free_samr_info, (void *)info))
662 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
664 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
669 /*******************************************************************
671 ********************************************************************/
673 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
674 struct samr_GetUserPwInfo *r)
676 struct samr_info *info = NULL;
677 enum lsa_SidType sid_type;
678 uint32_t min_password_length = 0;
679 uint32_t password_properties = 0;
683 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
685 /* find the policy handle. open a policy on it. */
686 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info)) {
687 return NT_STATUS_INVALID_HANDLE;
690 status = access_check_samr_function(info->acc_granted,
691 SAMR_USER_ACCESS_GET_ATTRIBUTES,
692 "_samr_GetUserPwInfo" );
693 if (!NT_STATUS_IS_OK(status)) {
697 if (!sid_check_is_in_our_domain(&info->sid)) {
698 return NT_STATUS_OBJECT_TYPE_MISMATCH;
702 ret = lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, &sid_type);
705 return NT_STATUS_NO_SUCH_USER;
711 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
712 &min_password_length);
713 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
714 &password_properties);
717 if (lp_check_password_script() && *lp_check_password_script()) {
718 password_properties |= DOMAIN_PASSWORD_COMPLEX;
726 r->out.info->min_password_length = min_password_length;
727 r->out.info->password_properties = password_properties;
729 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
734 /*******************************************************************
735 ********************************************************************/
737 static bool get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol,
738 DOM_SID *sid, uint32 *acc_granted,
739 DISP_INFO **ppdisp_info)
741 struct samr_info *info = NULL;
743 /* find the policy handle. open a policy on it. */
744 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
751 *acc_granted = info->acc_granted;
753 *ppdisp_info = info->disp_info;
759 /*******************************************************************
761 ********************************************************************/
763 NTSTATUS _samr_SetSecurity(pipes_struct *p,
764 struct samr_SetSecurity *r)
767 uint32 acc_granted, i;
770 struct samu *sampass=NULL;
773 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
774 return NT_STATUS_INVALID_HANDLE;
776 if (!(sampass = samu_new( p->mem_ctx))) {
777 DEBUG(0,("No memory!\n"));
778 return NT_STATUS_NO_MEMORY;
781 /* get the user record */
783 ret = pdb_getsampwsid(sampass, &pol_sid);
787 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
788 TALLOC_FREE(sampass);
789 return NT_STATUS_INVALID_HANDLE;
792 dacl = r->in.sdbuf->sd->dacl;
793 for (i=0; i < dacl->num_aces; i++) {
794 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
795 ret = pdb_set_pass_can_change(sampass,
796 (dacl->aces[i].access_mask &
797 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
804 TALLOC_FREE(sampass);
805 return NT_STATUS_ACCESS_DENIED;
808 status = access_check_samr_function(acc_granted,
809 SAMR_USER_ACCESS_SET_ATTRIBUTES,
810 "_samr_SetSecurity");
811 if (NT_STATUS_IS_OK(status)) {
813 status = pdb_update_sam_account(sampass);
817 TALLOC_FREE(sampass);
822 /*******************************************************************
823 build correct perms based on policies and password times for _samr_query_sec_obj
824 *******************************************************************/
825 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
827 struct samu *sampass=NULL;
830 if ( !(sampass = samu_new( mem_ctx )) ) {
831 DEBUG(0,("No memory!\n"));
836 ret = pdb_getsampwsid(sampass, user_sid);
840 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
841 TALLOC_FREE(sampass);
845 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
847 if (pdb_get_pass_can_change(sampass)) {
848 TALLOC_FREE(sampass);
851 TALLOC_FREE(sampass);
856 /*******************************************************************
858 ********************************************************************/
860 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
861 struct samr_QuerySecurity *r)
865 SEC_DESC * psd = NULL;
870 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
871 return NT_STATUS_INVALID_HANDLE;
873 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
874 sid_string_dbg(&pol_sid)));
876 status = access_check_samr_function(acc_granted,
877 STD_RIGHT_READ_CONTROL_ACCESS,
878 "_samr_QuerySecurity");
879 if (!NT_STATUS_IS_OK(status)) {
883 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
885 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
886 if (pol_sid.sid_rev_num == 0) {
887 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
888 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
889 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
890 /* check if it is our domain SID */
891 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
892 "with SID: %s\n", sid_string_dbg(&pol_sid)));
893 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
894 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
895 /* check if it is the Builtin Domain */
896 /* TODO: Builtin probably needs a different SD with restricted write access*/
897 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
898 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
899 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
900 } else if (sid_check_is_in_our_domain(&pol_sid) ||
901 sid_check_is_in_builtin(&pol_sid)) {
902 /* TODO: different SDs have to be generated for aliases groups and users.
903 Currently all three get a default user SD */
904 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
905 "with SID: %s\n", sid_string_dbg(&pol_sid)));
906 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
907 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
908 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
910 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
911 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
914 return NT_STATUS_OBJECT_TYPE_MISMATCH;
917 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
918 return NT_STATUS_NO_MEMORY;
923 /*******************************************************************
924 makes a SAM_ENTRY / UNISTR2* structure from a user list.
925 ********************************************************************/
927 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
928 struct samr_SamEntry **sam_pp,
929 uint32_t num_entries,
931 struct samr_displayentry *entries)
934 struct samr_SamEntry *sam;
938 if (num_entries == 0) {
942 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
944 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
945 return NT_STATUS_NO_MEMORY;
948 for (i = 0; i < num_entries; i++) {
951 * usrmgr expects a non-NULL terminated string with
952 * trust relationships
954 if (entries[i].acct_flags & ACB_DOMTRUST) {
955 init_unistr2(&uni_temp_name, entries[i].account_name,
958 init_unistr2(&uni_temp_name, entries[i].account_name,
962 init_lsa_String(&sam[i].name, entries[i].account_name);
963 sam[i].idx = entries[i].rid;
971 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
973 /*******************************************************************
974 _samr_EnumDomainUsers
975 ********************************************************************/
977 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
978 struct samr_EnumDomainUsers *r)
981 struct samr_info *info = NULL;
983 uint32 enum_context = *r->in.resume_handle;
984 enum remote_arch_types ra_type = get_remote_arch();
985 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
986 uint32 max_entries = max_sam_entries;
987 struct samr_displayentry *entries = NULL;
988 struct samr_SamArray *samr_array = NULL;
989 struct samr_SamEntry *samr_entries = NULL;
991 /* find the policy handle. open a policy on it. */
992 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
993 return NT_STATUS_INVALID_HANDLE;
995 status = access_check_samr_function(info->acc_granted,
996 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
997 "_samr_EnumDomainUsers");
998 if (!NT_STATUS_IS_OK(status)) {
1002 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1004 if (info->builtin_domain) {
1005 /* No users in builtin. */
1006 *r->out.resume_handle = *r->in.resume_handle;
1007 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
1011 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1013 return NT_STATUS_NO_MEMORY;
1015 *r->out.sam = samr_array;
1021 if ((info->disp_info->enum_users != NULL) &&
1022 (info->disp_info->enum_acb_mask != r->in.acct_flags)) {
1023 pdb_search_destroy(info->disp_info->enum_users);
1024 info->disp_info->enum_users = NULL;
1027 if (info->disp_info->enum_users == NULL) {
1028 info->disp_info->enum_users = pdb_search_users(r->in.acct_flags);
1029 info->disp_info->enum_acb_mask = r->in.acct_flags;
1032 if (info->disp_info->enum_users == NULL) {
1033 /* END AS ROOT !!!! */
1035 return NT_STATUS_ACCESS_DENIED;
1038 num_account = pdb_search_entries(info->disp_info->enum_users,
1039 enum_context, max_entries,
1042 /* END AS ROOT !!!! */
1046 if (num_account == 0) {
1047 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1048 "total entries\n"));
1049 *r->out.resume_handle = *r->in.resume_handle;
1050 return NT_STATUS_OK;
1053 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
1054 num_account, enum_context,
1056 if (!NT_STATUS_IS_OK(status)) {
1060 if (max_entries <= num_account) {
1061 status = STATUS_MORE_ENTRIES;
1063 status = NT_STATUS_OK;
1066 /* Ensure we cache this enumeration. */
1067 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1069 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
1071 samr_array->count = num_account;
1072 samr_array->entries = samr_entries;
1074 *r->out.resume_handle = *r->in.resume_handle + num_account;
1075 *r->out.num_entries = num_account;
1077 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1082 /*******************************************************************
1083 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1084 ********************************************************************/
1086 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1087 struct samr_SamEntry **sam_pp,
1088 uint32_t num_sam_entries,
1089 struct samr_displayentry *entries)
1091 struct samr_SamEntry *sam;
1096 if (num_sam_entries == 0) {
1100 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1105 for (i = 0; i < num_sam_entries; i++) {
1107 * JRA. I think this should include the null. TNG does not.
1109 init_lsa_String(&sam[i].name, entries[i].account_name);
1110 sam[i].idx = entries[i].rid;
1116 /*******************************************************************
1117 _samr_EnumDomainGroups
1118 ********************************************************************/
1120 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1121 struct samr_EnumDomainGroups *r)
1124 struct samr_info *info = NULL;
1125 struct samr_displayentry *groups;
1127 struct samr_SamArray *samr_array = NULL;
1128 struct samr_SamEntry *samr_entries = NULL;
1130 /* find the policy handle. open a policy on it. */
1131 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1132 return NT_STATUS_INVALID_HANDLE;
1134 status = access_check_samr_function(info->acc_granted,
1135 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1136 "_samr_EnumDomainGroups");
1137 if (!NT_STATUS_IS_OK(status)) {
1141 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1143 if (info->builtin_domain) {
1144 /* No groups in builtin. */
1145 *r->out.resume_handle = *r->in.resume_handle;
1146 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1150 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1152 return NT_STATUS_NO_MEMORY;
1155 /* the domain group array is being allocated in the function below */
1159 if (info->disp_info->groups == NULL) {
1160 info->disp_info->groups = pdb_search_groups();
1162 if (info->disp_info->groups == NULL) {
1164 return NT_STATUS_ACCESS_DENIED;
1168 num_groups = pdb_search_entries(info->disp_info->groups,
1169 *r->in.resume_handle,
1170 MAX_SAM_ENTRIES, &groups);
1173 /* Ensure we cache this enumeration. */
1174 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1176 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1177 num_groups, groups);
1179 samr_array->count = num_groups;
1180 samr_array->entries = samr_entries;
1182 *r->out.sam = samr_array;
1183 *r->out.num_entries = num_groups;
1184 /* this was missing, IMHO:
1185 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1188 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1193 /*******************************************************************
1194 _samr_EnumDomainAliases
1195 ********************************************************************/
1197 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1198 struct samr_EnumDomainAliases *r)
1201 struct samr_info *info;
1202 struct samr_displayentry *aliases;
1203 uint32 num_aliases = 0;
1204 struct samr_SamArray *samr_array = NULL;
1205 struct samr_SamEntry *samr_entries = NULL;
1207 /* find the policy handle. open a policy on it. */
1208 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1209 return NT_STATUS_INVALID_HANDLE;
1211 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1212 sid_string_dbg(&info->sid)));
1214 status = access_check_samr_function(info->acc_granted,
1215 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1216 "_samr_EnumDomainAliases");
1217 if (!NT_STATUS_IS_OK(status)) {
1221 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1223 return NT_STATUS_NO_MEMORY;
1228 if (info->disp_info->aliases == NULL) {
1229 info->disp_info->aliases = pdb_search_aliases(&info->sid);
1230 if (info->disp_info->aliases == NULL) {
1232 return NT_STATUS_ACCESS_DENIED;
1236 num_aliases = pdb_search_entries(info->disp_info->aliases,
1237 *r->in.resume_handle,
1238 MAX_SAM_ENTRIES, &aliases);
1241 /* Ensure we cache this enumeration. */
1242 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1244 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1245 num_aliases, aliases);
1247 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1249 samr_array->count = num_aliases;
1250 samr_array->entries = samr_entries;
1252 *r->out.sam = samr_array;
1253 *r->out.num_entries = num_aliases;
1254 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1259 /*******************************************************************
1260 inits a samr_DispInfoGeneral structure.
1261 ********************************************************************/
1263 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1264 struct samr_DispInfoGeneral *r,
1265 uint32_t num_entries,
1267 struct samr_displayentry *entries)
1271 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1273 if (num_entries == 0) {
1274 return NT_STATUS_OK;
1277 r->count = num_entries;
1279 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1281 return NT_STATUS_NO_MEMORY;
1284 for (i = 0; i < num_entries ; i++) {
1286 init_lsa_String(&r->entries[i].account_name,
1287 entries[i].account_name);
1289 init_lsa_String(&r->entries[i].description,
1290 entries[i].description);
1292 init_lsa_String(&r->entries[i].full_name,
1293 entries[i].fullname);
1295 r->entries[i].rid = entries[i].rid;
1296 r->entries[i].acct_flags = entries[i].acct_flags;
1297 r->entries[i].idx = start_idx+i+1;
1300 return NT_STATUS_OK;
1303 /*******************************************************************
1304 inits a samr_DispInfoFull structure.
1305 ********************************************************************/
1307 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1308 struct samr_DispInfoFull *r,
1309 uint32_t num_entries,
1311 struct samr_displayentry *entries)
1315 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1317 if (num_entries == 0) {
1318 return NT_STATUS_OK;
1321 r->count = num_entries;
1323 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1325 return NT_STATUS_NO_MEMORY;
1328 for (i = 0; i < num_entries ; i++) {
1330 init_lsa_String(&r->entries[i].account_name,
1331 entries[i].account_name);
1333 init_lsa_String(&r->entries[i].description,
1334 entries[i].description);
1336 r->entries[i].rid = entries[i].rid;
1337 r->entries[i].acct_flags = entries[i].acct_flags;
1338 r->entries[i].idx = start_idx+i+1;
1341 return NT_STATUS_OK;
1344 /*******************************************************************
1345 inits a samr_DispInfoFullGroups structure.
1346 ********************************************************************/
1348 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1349 struct samr_DispInfoFullGroups *r,
1350 uint32_t num_entries,
1352 struct samr_displayentry *entries)
1356 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1358 if (num_entries == 0) {
1359 return NT_STATUS_OK;
1362 r->count = num_entries;
1364 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1366 return NT_STATUS_NO_MEMORY;
1369 for (i = 0; i < num_entries ; i++) {
1371 init_lsa_String(&r->entries[i].account_name,
1372 entries[i].account_name);
1374 init_lsa_String(&r->entries[i].description,
1375 entries[i].description);
1377 r->entries[i].rid = entries[i].rid;
1378 r->entries[i].acct_flags = entries[i].acct_flags;
1379 r->entries[i].idx = start_idx+i+1;
1382 return NT_STATUS_OK;
1385 /*******************************************************************
1386 inits a samr_DispInfoAscii structure.
1387 ********************************************************************/
1389 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1390 struct samr_DispInfoAscii *r,
1391 uint32_t num_entries,
1393 struct samr_displayentry *entries)
1397 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1399 if (num_entries == 0) {
1400 return NT_STATUS_OK;
1403 r->count = num_entries;
1405 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1407 return NT_STATUS_NO_MEMORY;
1410 for (i = 0; i < num_entries ; i++) {
1412 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1413 entries[i].account_name);
1415 r->entries[i].idx = start_idx+i+1;
1418 return NT_STATUS_OK;
1421 /*******************************************************************
1422 inits a samr_DispInfoAscii structure.
1423 ********************************************************************/
1425 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1426 struct samr_DispInfoAscii *r,
1427 uint32_t num_entries,
1429 struct samr_displayentry *entries)
1433 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1435 if (num_entries == 0) {
1436 return NT_STATUS_OK;
1439 r->count = num_entries;
1441 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1443 return NT_STATUS_NO_MEMORY;
1446 for (i = 0; i < num_entries ; i++) {
1448 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1449 entries[i].account_name);
1451 r->entries[i].idx = start_idx+i+1;
1454 return NT_STATUS_OK;
1457 /*******************************************************************
1458 _samr_QueryDisplayInfo
1459 ********************************************************************/
1461 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1462 struct samr_QueryDisplayInfo *r)
1465 struct samr_info *info = NULL;
1466 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1468 uint32 max_entries = r->in.max_entries;
1469 uint32 enum_context = r->in.start_idx;
1470 uint32 max_size = r->in.buf_size;
1472 union samr_DispInfo *disp_info = r->out.info;
1474 uint32 temp_size=0, total_data_size=0;
1475 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1476 uint32 num_account = 0;
1477 enum remote_arch_types ra_type = get_remote_arch();
1478 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1479 struct samr_displayentry *entries = NULL;
1481 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1483 /* find the policy handle. open a policy on it. */
1484 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1485 return NT_STATUS_INVALID_HANDLE;
1487 if (info->builtin_domain) {
1488 DEBUG(5,("_samr_QueryDisplayInfo: Nothing in BUILTIN\n"));
1489 return NT_STATUS_OK;
1492 status = access_check_samr_function(info->acc_granted,
1493 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1494 "_samr_QueryDisplayInfo");
1495 if (!NT_STATUS_IS_OK(status)) {
1500 * calculate how many entries we will return.
1502 * - the number of entries the client asked
1503 * - our limit on that
1504 * - the starting point (enumeration context)
1505 * - the buffer size the client will accept
1509 * We are a lot more like W2K. Instead of reading the SAM
1510 * each time to find the records we need to send back,
1511 * we read it once and link that copy to the sam handle.
1512 * For large user list (over the MAX_SAM_ENTRIES)
1513 * it's a definitive win.
1514 * second point to notice: between enumerations
1515 * our sam is now the same as it's a snapshoot.
1516 * third point: got rid of the static SAM_USER_21 struct
1517 * no more intermediate.
1518 * con: it uses much more memory, as a full copy is stored
1521 * If you want to change it, think twice and think
1522 * of the second point , that's really important.
1527 if ((r->in.level < 1) || (r->in.level > 5)) {
1528 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1529 (unsigned int)r->in.level ));
1530 return NT_STATUS_INVALID_INFO_CLASS;
1533 /* first limit the number of entries we will return */
1534 if(max_entries > max_sam_entries) {
1535 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1536 "entries, limiting to %d\n", max_entries,
1538 max_entries = max_sam_entries;
1541 /* calculate the size and limit on the number of entries we will
1544 temp_size=max_entries*struct_size;
1546 if (temp_size>max_size) {
1547 max_entries=MIN((max_size/struct_size),max_entries);;
1548 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1549 "only %d entries\n", max_entries));
1554 /* THe following done as ROOT. Don't return without unbecome_root(). */
1556 switch (r->in.level) {
1559 if (info->disp_info->users == NULL) {
1560 info->disp_info->users = pdb_search_users(ACB_NORMAL);
1561 if (info->disp_info->users == NULL) {
1563 return NT_STATUS_ACCESS_DENIED;
1565 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1566 (unsigned int)enum_context ));
1568 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1569 (unsigned int)enum_context ));
1572 num_account = pdb_search_entries(info->disp_info->users,
1573 enum_context, max_entries,
1577 if (info->disp_info->machines == NULL) {
1578 info->disp_info->machines =
1579 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
1580 if (info->disp_info->machines == NULL) {
1582 return NT_STATUS_ACCESS_DENIED;
1584 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1585 (unsigned int)enum_context ));
1587 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1588 (unsigned int)enum_context ));
1591 num_account = pdb_search_entries(info->disp_info->machines,
1592 enum_context, max_entries,
1597 if (info->disp_info->groups == NULL) {
1598 info->disp_info->groups = pdb_search_groups();
1599 if (info->disp_info->groups == NULL) {
1601 return NT_STATUS_ACCESS_DENIED;
1603 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1604 (unsigned int)enum_context ));
1606 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1607 (unsigned int)enum_context ));
1610 num_account = pdb_search_entries(info->disp_info->groups,
1611 enum_context, max_entries,
1616 smb_panic("info class changed");
1622 /* Now create reply structure */
1623 switch (r->in.level) {
1625 disp_ret = init_samr_dispinfo_1(p->mem_ctx, &disp_info->info1,
1626 num_account, enum_context,
1630 disp_ret = init_samr_dispinfo_2(p->mem_ctx, &disp_info->info2,
1631 num_account, enum_context,
1635 disp_ret = init_samr_dispinfo_3(p->mem_ctx, &disp_info->info3,
1636 num_account, enum_context,
1640 disp_ret = init_samr_dispinfo_4(p->mem_ctx, &disp_info->info4,
1641 num_account, enum_context,
1645 disp_ret = init_samr_dispinfo_5(p->mem_ctx, &disp_info->info5,
1646 num_account, enum_context,
1650 smb_panic("info class changed");
1654 if (!NT_STATUS_IS_OK(disp_ret))
1657 /* calculate the total size */
1658 total_data_size=num_account*struct_size;
1660 if (max_entries <= num_account) {
1661 status = STATUS_MORE_ENTRIES;
1663 status = NT_STATUS_OK;
1666 /* Ensure we cache this enumeration. */
1667 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1669 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__));
1671 *r->out.total_size = total_data_size;
1672 *r->out.returned_size = temp_size;
1677 /****************************************************************
1678 _samr_QueryDisplayInfo2
1679 ****************************************************************/
1681 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
1682 struct samr_QueryDisplayInfo2 *r)
1684 struct samr_QueryDisplayInfo q;
1686 q.in.domain_handle = r->in.domain_handle;
1687 q.in.level = r->in.level;
1688 q.in.start_idx = r->in.start_idx;
1689 q.in.max_entries = r->in.max_entries;
1690 q.in.buf_size = r->in.buf_size;
1692 q.out.total_size = r->out.total_size;
1693 q.out.returned_size = r->out.returned_size;
1694 q.out.info = r->out.info;
1696 return _samr_QueryDisplayInfo(p, &q);
1699 /****************************************************************
1700 _samr_QueryDisplayInfo3
1701 ****************************************************************/
1703 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
1704 struct samr_QueryDisplayInfo3 *r)
1706 struct samr_QueryDisplayInfo q;
1708 q.in.domain_handle = r->in.domain_handle;
1709 q.in.level = r->in.level;
1710 q.in.start_idx = r->in.start_idx;
1711 q.in.max_entries = r->in.max_entries;
1712 q.in.buf_size = r->in.buf_size;
1714 q.out.total_size = r->out.total_size;
1715 q.out.returned_size = r->out.returned_size;
1716 q.out.info = r->out.info;
1718 return _samr_QueryDisplayInfo(p, &q);
1721 /*******************************************************************
1722 _samr_QueryAliasInfo
1723 ********************************************************************/
1725 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
1726 struct samr_QueryAliasInfo *r)
1729 struct acct_info info;
1732 union samr_AliasInfo *alias_info = NULL;
1733 const char *alias_name = NULL;
1734 const char *alias_description = NULL;
1736 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1738 alias_info = TALLOC_ZERO_P(p->mem_ctx, union samr_AliasInfo);
1740 return NT_STATUS_NO_MEMORY;
1743 /* find the policy handle. open a policy on it. */
1744 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &sid, &acc_granted, NULL))
1745 return NT_STATUS_INVALID_HANDLE;
1747 status = access_check_samr_function(acc_granted,
1748 SAMR_ALIAS_ACCESS_LOOKUP_INFO,
1749 "_samr_QueryAliasInfo");
1750 if (!NT_STATUS_IS_OK(status)) {
1755 status = pdb_get_aliasinfo(&sid, &info);
1758 if ( !NT_STATUS_IS_OK(status))
1761 /* FIXME: info contains fstrings */
1762 alias_name = talloc_strdup(r, info.acct_name);
1763 alias_description = talloc_strdup(r, info.acct_desc);
1765 switch (r->in.level) {
1767 init_samr_alias_info1(&alias_info->all,
1772 case ALIASINFODESCRIPTION:
1773 init_samr_alias_info3(&alias_info->description,
1777 return NT_STATUS_INVALID_INFO_CLASS;
1780 *r->out.info = alias_info;
1782 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1784 return NT_STATUS_OK;
1787 /*******************************************************************
1789 ********************************************************************/
1791 NTSTATUS _samr_LookupNames(pipes_struct *p,
1792 struct samr_LookupNames *r)
1796 enum lsa_SidType *type;
1798 int num_rids = r->in.num_names;
1801 struct samr_Ids rids, types;
1802 uint32_t num_mapped = 0;
1804 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1806 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL)) {
1807 return NT_STATUS_OBJECT_TYPE_MISMATCH;
1810 status = access_check_samr_function(acc_granted,
1811 0, /* Don't know the acc_bits yet */
1812 "_samr_LookupNames");
1813 if (!NT_STATUS_IS_OK(status)) {
1817 if (num_rids > MAX_SAM_ENTRIES) {
1818 num_rids = MAX_SAM_ENTRIES;
1819 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1822 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1823 NT_STATUS_HAVE_NO_MEMORY(rid);
1825 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1826 NT_STATUS_HAVE_NO_MEMORY(type);
1828 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1829 sid_string_dbg(&pol_sid)));
1831 for (i = 0; i < num_rids; i++) {
1833 status = NT_STATUS_NONE_MAPPED;
1834 type[i] = SID_NAME_UNKNOWN;
1836 rid[i] = 0xffffffff;
1838 if (sid_check_is_builtin(&pol_sid)) {
1839 if (lookup_builtin_name(r->in.names[i].string,
1842 type[i] = SID_NAME_ALIAS;
1845 lookup_global_sam_name(r->in.names[i].string, 0,
1849 if (type[i] != SID_NAME_UNKNOWN) {
1854 if (num_mapped == num_rids) {
1855 status = NT_STATUS_OK;
1856 } else if (num_mapped == 0) {
1857 status = NT_STATUS_NONE_MAPPED;
1859 status = STATUS_SOME_UNMAPPED;
1862 rids.count = num_rids;
1865 types.count = num_rids;
1868 *r->out.rids = rids;
1869 *r->out.types = types;
1871 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1876 /*******************************************************************
1877 _samr_ChangePasswordUser2
1878 ********************************************************************/
1880 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1881 struct samr_ChangePasswordUser2 *r)
1887 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1889 fstrcpy(user_name, r->in.account->string);
1890 fstrcpy(wks, r->in.server->string);
1892 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1895 * Pass the user through the NT -> unix user mapping
1899 (void)map_username(user_name);
1902 * UNIX username case mangling not required, pass_oem_change
1903 * is case insensitive.
1906 status = pass_oem_change(user_name,
1907 r->in.lm_password->data,
1908 r->in.lm_verifier->hash,
1909 r->in.nt_password->data,
1910 r->in.nt_verifier->hash,
1913 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1918 /*******************************************************************
1919 _samr_ChangePasswordUser3
1920 ********************************************************************/
1922 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
1923 struct samr_ChangePasswordUser3 *r)
1927 const char *wks = NULL;
1928 uint32 reject_reason;
1929 struct samr_DomInfo1 *dominfo = NULL;
1930 struct samr_ChangeReject *reject = NULL;
1932 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1934 fstrcpy(user_name, r->in.account->string);
1935 if (r->in.server && r->in.server->string) {
1936 wks = r->in.server->string;
1939 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
1942 * Pass the user through the NT -> unix user mapping
1946 (void)map_username(user_name);
1949 * UNIX username case mangling not required, pass_oem_change
1950 * is case insensitive.
1953 status = pass_oem_change(user_name,
1954 r->in.lm_password->data,
1955 r->in.lm_verifier->hash,
1956 r->in.nt_password->data,
1957 r->in.nt_verifier->hash,
1960 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
1961 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1963 uint32 min_pass_len,pass_hist,password_properties;
1964 time_t u_expire, u_min_age;
1965 NTTIME nt_expire, nt_min_age;
1966 uint32 account_policy_temp;
1968 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
1970 return NT_STATUS_NO_MEMORY;
1973 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
1975 return NT_STATUS_NO_MEMORY;
1982 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp);
1983 min_pass_len = account_policy_temp;
1985 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
1986 pass_hist = account_policy_temp;
1988 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
1989 password_properties = account_policy_temp;
1991 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1992 u_expire = account_policy_temp;
1994 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1995 u_min_age = account_policy_temp;
2001 unix_to_nt_time_abs(&nt_expire, u_expire);
2002 unix_to_nt_time_abs(&nt_min_age, u_min_age);
2004 if (lp_check_password_script() && *lp_check_password_script()) {
2005 password_properties |= DOMAIN_PASSWORD_COMPLEX;
2008 init_samr_DomInfo1(dominfo,
2011 password_properties,
2015 reject->reason = reject_reason;
2017 *r->out.dominfo = dominfo;
2018 *r->out.reject = reject;
2021 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2026 /*******************************************************************
2027 makes a SAMR_R_LOOKUP_RIDS structure.
2028 ********************************************************************/
2030 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2032 struct lsa_String **lsa_name_array_p)
2034 struct lsa_String *lsa_name_array = NULL;
2037 *lsa_name_array_p = NULL;
2039 if (num_names != 0) {
2040 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2041 if (!lsa_name_array) {
2046 for (i = 0; i < num_names; i++) {
2047 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2048 init_lsa_String(&lsa_name_array[i], names[i]);
2051 *lsa_name_array_p = lsa_name_array;
2056 /*******************************************************************
2058 ********************************************************************/
2060 NTSTATUS _samr_LookupRids(pipes_struct *p,
2061 struct samr_LookupRids *r)
2065 enum lsa_SidType *attrs = NULL;
2066 uint32 *wire_attrs = NULL;
2068 int num_rids = (int)r->in.num_rids;
2071 struct lsa_Strings names_array;
2072 struct samr_Ids types_array;
2073 struct lsa_String *lsa_names = NULL;
2075 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2077 /* find the policy handle. open a policy on it. */
2078 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2079 return NT_STATUS_INVALID_HANDLE;
2081 status = access_check_samr_function(acc_granted,
2082 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
2083 "_samr_LookupRids");
2084 if (!NT_STATUS_IS_OK(status)) {
2088 if (num_rids > 1000) {
2089 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2090 "to samba4 idl this is not possible\n", num_rids));
2091 return NT_STATUS_UNSUCCESSFUL;
2095 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2096 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2097 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2099 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2100 return NT_STATUS_NO_MEMORY;
2107 become_root(); /* lookup_sid can require root privs */
2108 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2112 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2113 status = NT_STATUS_OK;
2116 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2118 return NT_STATUS_NO_MEMORY;
2121 /* Convert from enum lsa_SidType to uint32 for wire format. */
2122 for (i = 0; i < num_rids; i++) {
2123 wire_attrs[i] = (uint32)attrs[i];
2126 names_array.count = num_rids;
2127 names_array.names = lsa_names;
2129 types_array.count = num_rids;
2130 types_array.ids = wire_attrs;
2132 *r->out.names = names_array;
2133 *r->out.types = types_array;
2135 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2140 /*******************************************************************
2142 ********************************************************************/
2144 NTSTATUS _samr_OpenUser(pipes_struct *p,
2145 struct samr_OpenUser *r)
2147 struct samu *sampass=NULL;
2149 POLICY_HND domain_pol = *r->in.domain_handle;
2150 POLICY_HND *user_pol = r->out.user_handle;
2151 struct samr_info *info = NULL;
2152 SEC_DESC *psd = NULL;
2154 uint32 des_access = r->in.access_mask;
2160 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2162 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
2163 return NT_STATUS_INVALID_HANDLE;
2165 nt_status = access_check_samr_function(acc_granted,
2166 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2169 if ( !NT_STATUS_IS_OK(nt_status) )
2172 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2173 return NT_STATUS_NO_MEMORY;
2176 /* append the user's RID to it */
2178 if (!sid_append_rid(&sid, r->in.rid))
2179 return NT_STATUS_NO_SUCH_USER;
2181 /* check if access can be granted as requested by client. */
2183 map_max_allowed_access(p->server_info->ptok, &des_access);
2185 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2186 se_map_generic(&des_access, &usr_generic_mapping);
2188 se_priv_copy( &se_rights, &se_machine_account );
2189 se_priv_add( &se_rights, &se_add_users );
2191 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2192 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2193 &acc_granted, "_samr_OpenUser");
2195 if ( !NT_STATUS_IS_OK(nt_status) )
2199 ret=pdb_getsampwsid(sampass, &sid);
2202 /* check that the SID exists in our domain. */
2204 return NT_STATUS_NO_SUCH_USER;
2207 TALLOC_FREE(sampass);
2209 /* associate the user's SID and access bits with the new handle. */
2210 if ((info = get_samr_info_by_sid(&sid)) == NULL)
2211 return NT_STATUS_NO_MEMORY;
2212 info->acc_granted = acc_granted;
2214 /* get a (unique) handle. open a policy on it. */
2215 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
2216 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2218 return NT_STATUS_OK;
2221 /*************************************************************************
2222 *************************************************************************/
2224 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2226 struct lsa_BinaryString **_r)
2228 struct lsa_BinaryString *r;
2231 return NT_STATUS_INVALID_PARAMETER;
2234 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2236 return NT_STATUS_NO_MEMORY;
2239 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2241 return NT_STATUS_NO_MEMORY;
2243 memcpy(r->array, blob->data, blob->length);
2244 r->size = blob->length;
2245 r->length = blob->length;
2248 return NT_STATUS_NO_MEMORY;
2253 return NT_STATUS_OK;
2256 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2257 struct samr_UserInfo5 *r,
2259 DOM_SID *domain_sid)
2261 const DOM_SID *sid_user, *sid_group;
2262 uint32_t rid, primary_gid;
2263 NTTIME last_logon, last_logoff, last_password_change,
2265 const char *account_name, *full_name, *home_directory, *home_drive,
2266 *logon_script, *profile_path, *description,
2267 *workstations, *comment;
2268 struct samr_LogonHours logon_hours;
2272 sid_user = pdb_get_user_sid(pw);
2274 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2275 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2276 "the domain sid %s. Failing operation.\n",
2277 pdb_get_username(pw), sid_string_dbg(sid_user),
2278 sid_string_dbg(domain_sid)));
2279 return NT_STATUS_UNSUCCESSFUL;
2283 sid_group = pdb_get_group_sid(pw);
2286 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2287 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2288 "which conflicts with the domain sid %s. Failing operation.\n",
2289 pdb_get_username(pw), sid_string_dbg(sid_group),
2290 sid_string_dbg(domain_sid)));
2291 return NT_STATUS_UNSUCCESSFUL;
2294 unix_to_nt_time(&last_logon, pdb_get_logon_time(pw));
2295 unix_to_nt_time(&last_logoff, pdb_get_logoff_time(pw));
2296 unix_to_nt_time(&acct_expiry, pdb_get_kickoff_time(pw));
2297 unix_to_nt_time(&last_password_change, pdb_get_pass_last_set_time(pw));
2299 account_name = talloc_strdup(mem_ctx, pdb_get_username(pw));
2300 full_name = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2301 home_directory = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2302 home_drive = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2303 logon_script = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2304 profile_path = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2305 description = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2306 workstations = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2307 comment = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2309 logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2311 init_samr_user_info5(r,
2325 pdb_get_bad_password_count(pw),
2326 pdb_get_logon_count(pw),
2327 last_password_change,
2329 pdb_get_acct_ctrl(pw));
2331 return NT_STATUS_OK;
2334 /*************************************************************************
2335 get_user_info_7. Safe. Only gives out account_name.
2336 *************************************************************************/
2338 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2339 struct samr_UserInfo7 *r,
2340 struct samu *smbpass)
2342 const char *account_name = NULL;
2346 account_name = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2347 if (!account_name) {
2348 return NT_STATUS_NO_MEMORY;
2351 init_samr_user_info7(r, account_name);
2353 return NT_STATUS_OK;
2356 /*************************************************************************
2357 get_user_info_9. Only gives out primary group SID.
2358 *************************************************************************/
2360 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2361 struct samr_UserInfo9 *r,
2362 struct samu *smbpass)
2366 init_samr_user_info9(r, pdb_get_group_rid(smbpass));
2368 return NT_STATUS_OK;
2371 /*************************************************************************
2372 get_user_info_16. Safe. Only gives out acb bits.
2373 *************************************************************************/
2375 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2376 struct samr_UserInfo16 *r,
2377 struct samu *smbpass)
2381 init_samr_user_info16(r, pdb_get_acct_ctrl(smbpass));
2383 return NT_STATUS_OK;
2386 /*************************************************************************
2387 get_user_info_18. OK - this is the killer as it gives out password info.
2388 Ensure that this is only allowed on an encrypted connection with a root
2390 *************************************************************************/
2392 static NTSTATUS get_user_info_18(pipes_struct *p,
2393 TALLOC_CTX *mem_ctx,
2394 struct samr_UserInfo18 *r,
2397 struct samu *smbpass=NULL;
2402 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2403 return NT_STATUS_ACCESS_DENIED;
2406 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2407 return NT_STATUS_ACCESS_DENIED;
2411 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2414 if ( !(smbpass = samu_new( mem_ctx )) ) {
2415 return NT_STATUS_NO_MEMORY;
2418 ret = pdb_getsampwsid(smbpass, user_sid);
2421 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2422 TALLOC_FREE(smbpass);
2423 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2426 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2428 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2429 TALLOC_FREE(smbpass);
2430 return NT_STATUS_ACCOUNT_DISABLED;
2433 init_samr_user_info18(r, pdb_get_lanman_passwd(smbpass),
2434 pdb_get_nt_passwd(smbpass));
2436 TALLOC_FREE(smbpass);
2438 return NT_STATUS_OK;
2441 /*************************************************************************
2443 *************************************************************************/
2445 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2446 struct samr_UserInfo20 *r,
2447 struct samu *sampass)
2449 const char *munged_dial = NULL;
2452 struct lsa_BinaryString *parameters = NULL;
2456 munged_dial = pdb_get_munged_dial(sampass);
2458 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2459 munged_dial, (int)strlen(munged_dial)));
2462 blob = base64_decode_data_blob(munged_dial);
2464 blob = data_blob_string_const_null("");
2467 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2468 data_blob_free(&blob);
2469 if (!NT_STATUS_IS_OK(status)) {
2473 init_samr_user_info20(r, parameters);
2475 return NT_STATUS_OK;
2479 /*************************************************************************
2481 *************************************************************************/
2483 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2484 struct samr_UserInfo21 *r,
2486 DOM_SID *domain_sid)
2489 const DOM_SID *sid_user, *sid_group;
2490 uint32_t rid, primary_gid;
2491 NTTIME last_logon, last_logoff, last_password_change,
2492 acct_expiry, allow_password_change, force_password_change;
2493 time_t must_change_time;
2494 uint8_t password_expired;
2495 const char *account_name, *full_name, *home_directory, *home_drive,
2496 *logon_script, *profile_path, *description,
2497 *workstations, *comment;
2498 struct samr_LogonHours logon_hours;
2499 struct lsa_BinaryString *parameters = NULL;
2500 const char *munged_dial = NULL;
2505 sid_user = pdb_get_user_sid(pw);
2507 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2508 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2509 "the domain sid %s. Failing operation.\n",
2510 pdb_get_username(pw), sid_string_dbg(sid_user),
2511 sid_string_dbg(domain_sid)));
2512 return NT_STATUS_UNSUCCESSFUL;
2516 sid_group = pdb_get_group_sid(pw);
2519 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2520 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2521 "which conflicts with the domain sid %s. Failing operation.\n",
2522 pdb_get_username(pw), sid_string_dbg(sid_group),
2523 sid_string_dbg(domain_sid)));
2524 return NT_STATUS_UNSUCCESSFUL;
2527 unix_to_nt_time(&last_logon, pdb_get_logon_time(pw));
2528 unix_to_nt_time(&last_logoff, pdb_get_logoff_time(pw));
2529 unix_to_nt_time(&acct_expiry, pdb_get_kickoff_time(pw));
2530 unix_to_nt_time(&last_password_change, pdb_get_pass_last_set_time(pw));
2531 unix_to_nt_time(&allow_password_change, pdb_get_pass_can_change_time(pw));
2533 must_change_time = pdb_get_pass_must_change_time(pw);
2534 if (must_change_time == get_time_t_max()) {
2535 unix_to_nt_time_abs(&force_password_change, must_change_time);
2537 unix_to_nt_time(&force_password_change, must_change_time);
2540 if (pdb_get_pass_must_change_time(pw) == 0) {
2541 password_expired = PASS_MUST_CHANGE_AT_NEXT_LOGON;
2543 password_expired = 0;
2546 munged_dial = pdb_get_munged_dial(pw);
2548 blob = base64_decode_data_blob(munged_dial);
2550 blob = data_blob_string_const_null("");
2553 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2554 data_blob_free(&blob);
2555 if (!NT_STATUS_IS_OK(status)) {
2559 account_name = talloc_strdup(mem_ctx, pdb_get_username(pw));
2560 full_name = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2561 home_directory = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2562 home_drive = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2563 logon_script = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2564 profile_path = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2565 description = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2566 workstations = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2567 comment = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2569 logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2573 Look at a user on a real NT4 PDC with usrmgr, press
2574 'ok'. Then you will see that fields_present is set to
2575 0x08f827fa. Look at the user immediately after that again,
2576 and you will see that 0x00fffff is returned. This solves
2577 the problem that you get access denied after having looked
2584 init_samr_user_info21(r,
2587 last_password_change,
2589 allow_password_change,
2590 force_password_change,
2603 pdb_get_acct_ctrl(pw),
2604 pdb_build_fields_present(pw),
2606 pdb_get_bad_password_count(pw),
2607 pdb_get_logon_count(pw),
2608 0, /* country_code */
2610 0, /* nt_password_set */
2611 0, /* lm_password_set */
2614 return NT_STATUS_OK;
2617 /*******************************************************************
2619 ********************************************************************/
2621 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2622 struct samr_QueryUserInfo *r)
2625 union samr_UserInfo *user_info = NULL;
2626 struct samr_info *info = NULL;
2630 struct samu *pwd = NULL;
2632 /* search for the handle */
2633 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
2634 return NT_STATUS_INVALID_HANDLE;
2636 status = access_check_samr_function(info->acc_granted,
2637 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2638 "_samr_QueryUserInfo");
2639 if (!NT_STATUS_IS_OK(status)) {
2643 domain_sid = info->sid;
2645 sid_split_rid(&domain_sid, &rid);
2647 if (!sid_check_is_in_our_domain(&info->sid))
2648 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2650 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2651 sid_string_dbg(&info->sid)));
2653 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2655 return NT_STATUS_NO_MEMORY;
2658 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2660 if (!(pwd = samu_new(p->mem_ctx))) {
2661 return NT_STATUS_NO_MEMORY;
2665 ret = pdb_getsampwsid(pwd, &info->sid);
2669 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
2671 return NT_STATUS_NO_SUCH_USER;
2674 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2676 samr_clear_sam_passwd(pwd);
2678 switch (r->in.level) {
2680 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2683 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2686 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2689 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2692 /* level 18 is special */
2693 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
2696 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2699 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2702 status = NT_STATUS_INVALID_INFO_CLASS;
2708 *r->out.info = user_info;
2710 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2715 /****************************************************************
2716 ****************************************************************/
2718 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2719 struct samr_QueryUserInfo2 *r)
2721 struct samr_QueryUserInfo u;
2723 u.in.user_handle = r->in.user_handle;
2724 u.in.level = r->in.level;
2725 u.out.info = r->out.info;
2727 return _samr_QueryUserInfo(p, &u);
2730 /*******************************************************************
2731 _samr_GetGroupsForUser
2732 ********************************************************************/
2734 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2735 struct samr_GetGroupsForUser *r)
2737 struct samu *sam_pass=NULL;
2740 struct samr_RidWithAttribute dom_gid;
2741 struct samr_RidWithAttribute *gids = NULL;
2742 uint32 primary_group_rid;
2743 size_t num_groups = 0;
2749 bool success = False;
2751 struct samr_RidWithAttributeArray *rids = NULL;
2754 * from the SID in the request:
2755 * we should send back the list of DOMAIN GROUPS
2756 * the user is a member of
2758 * and only the DOMAIN GROUPS
2759 * no ALIASES !!! neither aliases of the domain
2760 * nor aliases of the builtin SID
2765 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2767 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
2769 return NT_STATUS_NO_MEMORY;
2772 /* find the policy handle. open a policy on it. */
2773 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
2774 return NT_STATUS_INVALID_HANDLE;
2776 result = access_check_samr_function(acc_granted,
2777 SAMR_USER_ACCESS_GET_GROUPS,
2778 "_samr_GetGroupsForUser");
2779 if (!NT_STATUS_IS_OK(result)) {
2783 if (!sid_check_is_in_our_domain(&sid))
2784 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2786 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2787 return NT_STATUS_NO_MEMORY;
2791 ret = pdb_getsampwsid(sam_pass, &sid);
2795 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2796 sid_string_dbg(&sid)));
2797 return NT_STATUS_NO_SUCH_USER;
2802 /* make both calls inside the root block */
2804 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2805 &sids, &unix_gids, &num_groups);
2806 if ( NT_STATUS_IS_OK(result) ) {
2807 success = sid_peek_check_rid(get_global_sam_sid(),
2808 pdb_get_group_sid(sam_pass),
2809 &primary_group_rid);
2813 if (!NT_STATUS_IS_OK(result)) {
2814 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2815 sid_string_dbg(&sid)));
2820 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2821 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2822 pdb_get_username(sam_pass)));
2823 TALLOC_FREE(sam_pass);
2824 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2830 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2832 dom_gid.rid = primary_group_rid;
2833 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2835 for (i=0; i<num_groups; i++) {
2837 if (!sid_peek_check_rid(get_global_sam_sid(),
2838 &(sids[i]), &dom_gid.rid)) {
2839 DEBUG(10, ("Found sid %s not in our domain\n",
2840 sid_string_dbg(&sids[i])));
2844 if (dom_gid.rid == primary_group_rid) {
2845 /* We added the primary group directly from the
2846 * sam_account. The other SIDs are unique from
2847 * enum_group_memberships */
2851 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2854 rids->count = num_gids;
2857 *r->out.rids = rids;
2859 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2864 /*******************************************************************
2865 _samr_QueryDomainInfo
2866 ********************************************************************/
2868 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
2869 struct samr_QueryDomainInfo *r)
2871 NTSTATUS status = NT_STATUS_OK;
2872 struct samr_info *info = NULL;
2873 union samr_DomainInfo *dom_info;
2874 uint32 min_pass_len,pass_hist,password_properties;
2875 time_t u_expire, u_min_age;
2876 NTTIME nt_expire, nt_min_age;
2878 time_t u_lock_duration, u_reset_time;
2879 NTTIME nt_lock_duration, nt_reset_time;
2884 uint32 account_policy_temp;
2889 uint32 num_users=0, num_groups=0, num_aliases=0;
2891 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2893 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
2895 return NT_STATUS_NO_MEMORY;
2898 /* find the policy handle. open a policy on it. */
2899 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
2900 return NT_STATUS_INVALID_HANDLE;
2903 status = access_check_samr_function(info->acc_granted,
2904 SAMR_ACCESS_OPEN_DOMAIN,
2905 "_samr_QueryDomainInfo" );
2907 if ( !NT_STATUS_IS_OK(status) )
2910 switch (r->in.level) {
2917 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp);
2918 min_pass_len = account_policy_temp;
2920 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
2921 pass_hist = account_policy_temp;
2923 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
2924 password_properties = account_policy_temp;
2926 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2927 u_expire = account_policy_temp;
2929 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2930 u_min_age = account_policy_temp;
2936 unix_to_nt_time_abs(&nt_expire, u_expire);
2937 unix_to_nt_time_abs(&nt_min_age, u_min_age);
2939 if (lp_check_password_script() && *lp_check_password_script()) {
2940 password_properties |= DOMAIN_PASSWORD_COMPLEX;
2943 init_samr_DomInfo1(&dom_info->info1,
2944 (uint16)min_pass_len,
2946 password_properties,
2956 num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2957 num_groups = count_sam_groups(info->disp_info);
2958 num_aliases = count_sam_aliases(info->disp_info);
2960 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp);
2961 u_logout = account_policy_temp;
2963 unix_to_nt_time_abs(&nt_logout, u_logout);
2965 if (!pdb_get_seq_num(&seq_num))
2966 seq_num = time(NULL);
2972 server_role = ROLE_DOMAIN_PDC;
2973 if (lp_server_role() == ROLE_DOMAIN_BDC)
2974 server_role = ROLE_DOMAIN_BDC;
2976 init_samr_DomGeneralInformation(&dom_info->general,
2982 DOMAIN_SERVER_ENABLED,
2997 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2998 u_logout = (time_t)ul;
3005 unix_to_nt_time_abs(&nt_logout, u_logout);
3007 init_samr_DomInfo3(&dom_info->info3,
3012 init_samr_DomOEMInformation(&dom_info->oem,
3016 init_samr_DomInfo5(&dom_info->info5,
3017 get_global_sam_name());
3020 /* NT returns its own name when a PDC. win2k and later
3021 * only the name of the PDC if itself is a BDC (samba4
3023 init_samr_DomInfo6(&dom_info->info6,
3027 server_role = ROLE_DOMAIN_PDC;
3028 if (lp_server_role() == ROLE_DOMAIN_BDC)
3029 server_role = ROLE_DOMAIN_BDC;
3031 init_samr_DomInfo7(&dom_info->info7,
3040 if (!pdb_get_seq_num(&seq_num)) {
3041 seq_num = time(NULL);
3048 init_samr_DomInfo8(&dom_info->info8,
3058 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
3059 u_lock_duration = account_policy_temp;
3060 if (u_lock_duration != -1) {
3061 u_lock_duration *= 60;
3064 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
3065 u_reset_time = account_policy_temp * 60;
3067 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT, &account_policy_temp);
3068 lockout = account_policy_temp;
3074 unix_to_nt_time_abs(&nt_lock_duration, u_lock_duration);
3075 unix_to_nt_time_abs(&nt_reset_time, u_reset_time);
3077 init_samr_DomInfo12(&dom_info->info12,
3083 return NT_STATUS_INVALID_INFO_CLASS;
3086 *r->out.info = dom_info;
3088 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
3093 /* W2k3 seems to use the same check for all 3 objects that can be created via
3094 * SAMR, if you try to create for example "Dialup" as an alias it says
3095 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
3098 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
3100 enum lsa_SidType type;
3103 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
3106 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3107 * whether the name already exists */
3108 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3109 NULL, NULL, NULL, &type);
3113 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3114 return NT_STATUS_OK;
3117 DEBUG(5, ("trying to create %s, exists as %s\n",
3118 new_name, sid_type_lookup(type)));
3120 if (type == SID_NAME_DOM_GRP) {
3121 return NT_STATUS_GROUP_EXISTS;
3123 if (type == SID_NAME_ALIAS) {
3124 return NT_STATUS_ALIAS_EXISTS;
3127 /* Yes, the default is NT_STATUS_USER_EXISTS */
3128 return NT_STATUS_USER_EXISTS;
3131 /*******************************************************************
3133 ********************************************************************/
3135 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3136 struct samr_CreateUser2 *r)
3138 const char *account = NULL;
3140 POLICY_HND dom_pol = *r->in.domain_handle;
3141 uint32_t acb_info = r->in.acct_flags;
3142 POLICY_HND *user_pol = r->out.user_handle;
3143 struct samr_info *info = NULL;
3148 /* check this, when giving away 'add computer to domain' privs */
3149 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3150 bool can_add_account = False;
3152 DISP_INFO *disp_info = NULL;
3154 /* Get the domain SID stored in the domain policy */
3155 if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
3157 return NT_STATUS_INVALID_HANDLE;
3159 if (disp_info->builtin_domain) {
3160 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3161 return NT_STATUS_ACCESS_DENIED;
3164 nt_status = access_check_samr_function(acc_granted,
3165 SAMR_DOMAIN_ACCESS_CREATE_USER,
3166 "_samr_CreateUser2");
3167 if (!NT_STATUS_IS_OK(nt_status)) {
3171 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3172 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3173 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3174 this parameter is not an account type */
3175 return NT_STATUS_INVALID_PARAMETER;
3178 account = r->in.account_name->string;
3179 if (account == NULL) {
3180 return NT_STATUS_NO_MEMORY;
3183 nt_status = can_create(p->mem_ctx, account);
3184 if (!NT_STATUS_IS_OK(nt_status)) {
3188 /* determine which user right we need to check based on the acb_info */
3190 if ( acb_info & ACB_WSTRUST )
3192 se_priv_copy( &se_rights, &se_machine_account );
3193 can_add_account = user_has_privileges(
3194 p->server_info->ptok, &se_rights );
3196 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3197 account for domain trusts and changes the ACB flags later */
3198 else if ( acb_info & ACB_NORMAL &&
3199 (account[strlen(account)-1] != '$') )
3201 se_priv_copy( &se_rights, &se_add_users );
3202 can_add_account = user_has_privileges(
3203 p->server_info->ptok, &se_rights );
3205 else /* implicit assumption of a BDC or domain trust account here
3206 * (we already check the flags earlier) */
3208 if ( lp_enable_privileges() ) {
3209 /* only Domain Admins can add a BDC or domain trust */
3210 se_priv_copy( &se_rights, &se_priv_none );
3211 can_add_account = nt_token_check_domain_rid(
3212 p->server_info->ptok,
3213 DOMAIN_GROUP_RID_ADMINS );
3217 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3218 uidtoname(p->server_info->utok.uid),
3219 can_add_account ? "True":"False" ));
3221 /********** BEGIN Admin BLOCK **********/
3223 if ( can_add_account )
3226 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3229 if ( can_add_account )
3232 /********** END Admin BLOCK **********/
3234 /* now check for failure */
3236 if ( !NT_STATUS_IS_OK(nt_status) )
3239 /* Get the user's SID */
3241 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3243 map_max_allowed_access(p->server_info->ptok, &des_access);
3245 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3246 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3247 se_map_generic(&des_access, &usr_generic_mapping);
3249 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3250 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3251 &acc_granted, "_samr_CreateUser2");
3253 if ( !NT_STATUS_IS_OK(nt_status) ) {
3257 /* associate the user's SID with the new handle. */
3258 if ((info = get_samr_info_by_sid(&sid)) == NULL) {
3259 return NT_STATUS_NO_MEMORY;
3264 info->acc_granted = acc_granted;
3266 /* get a (unique) handle. open a policy on it. */
3267 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info)) {
3268 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3271 /* After a "set" ensure we have no cached display info. */
3272 force_flush_samr_cache(info->disp_info);
3274 *r->out.access_granted = acc_granted;
3276 return NT_STATUS_OK;
3279 /****************************************************************
3280 ****************************************************************/
3282 NTSTATUS _samr_CreateUser(pipes_struct *p,
3283 struct samr_CreateUser *r)
3285 struct samr_CreateUser2 c;
3286 uint32_t access_granted;
3288 c.in.domain_handle = r->in.domain_handle;
3289 c.in.account_name = r->in.account_name;
3290 c.in.acct_flags = ACB_NORMAL;
3291 c.in.access_mask = r->in.access_mask;
3292 c.out.user_handle = r->out.user_handle;
3293 c.out.access_granted = &access_granted;
3294 c.out.rid = r->out.rid;
3296 return _samr_CreateUser2(p, &c);
3299 /*******************************************************************
3301 ********************************************************************/
3303 NTSTATUS _samr_Connect(pipes_struct *p,
3304 struct samr_Connect *r)
3306 struct samr_info *info = NULL;
3307 uint32 des_access = r->in.access_mask;
3311 if (!pipe_access_check(p)) {
3312 DEBUG(3, ("access denied to _samr_Connect\n"));
3313 return NT_STATUS_ACCESS_DENIED;
3316 /* set up the SAMR connect_anon response */
3318 /* associate the user's SID with the new handle. */
3319 if ((info = get_samr_info_by_sid(NULL)) == NULL)
3320 return NT_STATUS_NO_MEMORY;
3322 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3323 was observed from a win98 client trying to enumerate users (when configured
3324 user level access control on shares) --jerry */
3326 map_max_allowed_access(p->server_info->ptok, &des_access);
3328 se_map_generic( &des_access, &sam_generic_mapping );
3329 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
3331 /* get a (unique) handle. open a policy on it. */
3332 if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
3333 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3335 return NT_STATUS_OK;
3338 /*******************************************************************
3340 ********************************************************************/
3342 NTSTATUS _samr_Connect2(pipes_struct *p,
3343 struct samr_Connect2 *r)
3345 struct samr_info *info = NULL;
3346 SEC_DESC *psd = NULL;
3348 uint32 des_access = r->in.access_mask;
3351 const char *fn = "_samr_Connect2";
3353 switch (p->hdr_req.opnum) {
3354 case NDR_SAMR_CONNECT2:
3355 fn = "_samr_Connect2";
3357 case NDR_SAMR_CONNECT4:
3358 fn = "_samr_Connect4";
3360 case NDR_SAMR_CONNECT5:
3361 fn = "_samr_Connect5";
3365 DEBUG(5,("%s: %d\n", fn, __LINE__));
3369 if (!pipe_access_check(p)) {
3370 DEBUG(3, ("access denied to %s\n", fn));
3371 return NT_STATUS_ACCESS_DENIED;
3374 map_max_allowed_access(p->server_info->ptok, &des_access);
3376 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3377 se_map_generic(&des_access, &sam_generic_mapping);
3379 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3380 NULL, 0, des_access, &acc_granted, fn);
3382 if ( !NT_STATUS_IS_OK(nt_status) )
3385 /* associate the user's SID and access granted with the new handle. */
3386 if ((info = get_samr_info_by_sid(NULL)) == NULL)
3387 return NT_STATUS_NO_MEMORY;
3389 info->acc_granted = acc_granted;
3390 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3392 /* get a (unique) handle. open a policy on it. */
3393 if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
3394 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3396 DEBUG(5,("%s: %d\n", fn, __LINE__));
3401 /*******************************************************************
3403 ********************************************************************/
3405 NTSTATUS _samr_Connect4(pipes_struct *p,
3406 struct samr_Connect4 *r)
3408 struct samr_Connect2 c;
3410 c.in.system_name = r->in.system_name;
3411 c.in.access_mask = r->in.access_mask;
3412 c.out.connect_handle = r->out.connect_handle;
3414 return _samr_Connect2(p, &c);
3417 /*******************************************************************
3419 ********************************************************************/
3421 NTSTATUS _samr_Connect5(pipes_struct *p,
3422 struct samr_Connect5 *r)
3425 struct samr_Connect2 c;
3426 struct samr_ConnectInfo1 info1;
3428 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3431 c.in.system_name = r->in.system_name;
3432 c.in.access_mask = r->in.access_mask;
3433 c.out.connect_handle = r->out.connect_handle;
3435 status = _samr_Connect2(p, &c);
3436 if (!NT_STATUS_IS_OK(status)) {
3440 *r->out.level_out = 1;
3441 r->out.info_out->info1 = info1;
3443 return NT_STATUS_OK;
3446 /**********************************************************************
3448 **********************************************************************/
3450 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3451 struct samr_LookupDomain *r)
3453 NTSTATUS status = NT_STATUS_OK;
3454 struct samr_info *info;
3455 const char *domain_name;
3456 DOM_SID *sid = NULL;
3458 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3459 return NT_STATUS_INVALID_HANDLE;
3461 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
3462 Reverted that change so we will work with RAS servers again */
3464 status = access_check_samr_function(info->acc_granted,
3465 SAMR_ACCESS_OPEN_DOMAIN,
3466 "_samr_LookupDomain");
3467 if (!NT_STATUS_IS_OK(status)) {
3471 domain_name = r->in.domain_name->string;
3473 return NT_STATUS_INVALID_PARAMETER;
3476 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
3478 return NT_STATUS_NO_MEMORY;
3481 if (strequal(domain_name, builtin_domain_name())) {
3482 sid_copy(sid, &global_sid_Builtin);
3484 if (!secrets_fetch_domain_sid(domain_name, sid)) {
3485 status = NT_STATUS_NO_SUCH_DOMAIN;
3489 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
3490 sid_string_dbg(sid)));
3497 /**********************************************************************
3499 **********************************************************************/
3501 NTSTATUS _samr_EnumDomains(pipes_struct *p,
3502 struct samr_EnumDomains *r)
3505 struct samr_info *info;
3506 uint32_t num_entries = 2;
3507 struct samr_SamEntry *entry_array = NULL;
3508 struct samr_SamArray *sam;
3510 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3511 return NT_STATUS_INVALID_HANDLE;
3513 status = access_check_samr_function(info->acc_granted,
3514 SAMR_ACCESS_ENUM_DOMAINS,
3515 "_samr_EnumDomains");
3516 if (!NT_STATUS_IS_OK(status)) {
3520 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
3522 return NT_STATUS_NO_MEMORY;
3525 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
3526 struct samr_SamEntry,
3529 return NT_STATUS_NO_MEMORY;
3532 entry_array[0].idx = 0;
3533 init_lsa_String(&entry_array[0].name, get_global_sam_name());
3535 entry_array[1].idx = 1;
3536 init_lsa_String(&entry_array[1].name, "Builtin");
3538 sam->count = num_entries;
3539 sam->entries = entry_array;
3542 *r->out.num_entries = num_entries;
3547 /*******************************************************************
3549 ********************************************************************/
3551 NTSTATUS _samr_OpenAlias(pipes_struct *p,
3552 struct samr_OpenAlias *r)
3555 POLICY_HND domain_pol = *r->in.domain_handle;
3556 uint32 alias_rid = r->in.rid;
3557 POLICY_HND *alias_pol = r->out.alias_handle;
3558 struct samr_info *info = NULL;
3559 SEC_DESC *psd = NULL;
3561 uint32 des_access = r->in.access_mask;
3566 /* find the domain policy and get the SID / access bits stored in the domain policy */
3568 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
3569 return NT_STATUS_INVALID_HANDLE;
3571 status = access_check_samr_function(acc_granted,
3572 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
3575 if ( !NT_STATUS_IS_OK(status) )
3578 /* append the alias' RID to it */
3580 if (!sid_append_rid(&sid, alias_rid))
3581 return NT_STATUS_NO_SUCH_ALIAS;
3583 /*check if access can be granted as requested by client. */
3585 map_max_allowed_access(p->server_info->ptok, &des_access);
3587 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3588 se_map_generic(&des_access,&ali_generic_mapping);
3590 se_priv_copy( &se_rights, &se_add_users );
3593 status = access_check_samr_object(psd, p->server_info->ptok,
3594 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3595 &acc_granted, "_samr_OpenAlias");
3597 if ( !NT_STATUS_IS_OK(status) )
3601 /* Check we actually have the requested alias */
3602 enum lsa_SidType type;
3607 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3610 if (!result || (type != SID_NAME_ALIAS)) {
3611 return NT_STATUS_NO_SUCH_ALIAS;
3614 /* make sure there is a mapping */
3616 if ( !sid_to_gid( &sid, &gid ) ) {
3617 return NT_STATUS_NO_SUCH_ALIAS;
3622 /* associate the alias SID with the new handle. */
3623 if ((info = get_samr_info_by_sid(&sid)) == NULL)
3624 return NT_STATUS_NO_MEMORY;
3626 info->acc_granted = acc_granted;
3628 /* get a (unique) handle. open a policy on it. */
3629 if (!create_policy_hnd(p, alias_pol, free_samr_info, (void *)info))
3630 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3632 return NT_STATUS_OK;
3635 /*******************************************************************
3637 ********************************************************************/
3639 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3640 struct samr_UserInfo7 *id7,
3646 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3647 return NT_STATUS_ACCESS_DENIED;
3650 if (!id7->account_name.string) {
3651 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3652 return NT_STATUS_ACCESS_DENIED;
3655 /* check to see if the new username already exists. Note: we can't
3656 reliably lock all backends, so there is potentially the
3657 possibility that a user can be created in between this check and
3658 the rename. The rename should fail, but may not get the
3659 exact same failure status code. I think this is small enough
3660 of a window for this type of operation and the results are
3661 simply that the rename fails with a slightly different status
3662 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3664 rc = can_create(mem_ctx, id7->account_name.string);
3665 if (!NT_STATUS_IS_OK(rc)) {
3669 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
3674 /*******************************************************************
3676 ********************************************************************/
3678 static bool set_user_info_16(struct samr_UserInfo16 *id16,
3682 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3686 /* FIX ME: check if the value is really changed --metze */
3687 if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
3691 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3698 /*******************************************************************
3700 ********************************************************************/
3702 static bool set_user_info_18(struct samr_UserInfo18 *id18,
3706 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3710 if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd.hash, PDB_CHANGED)) {
3713 if (!pdb_set_nt_passwd (pwd, id18->nt_pwd.hash, PDB_CHANGED)) {
3716 if (!pdb_set_pass_last_set_time (pwd, time(NULL), PDB_CHANGED)) {
3720 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3727 /*******************************************************************
3729 ********************************************************************/
3731 static bool set_user_info_20(struct samr_UserInfo20 *id20,
3735 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3739 copy_id20_to_sam_passwd(pwd, id20);
3741 /* write the change out */
3742 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3749 /*******************************************************************
3751 ********************************************************************/
3753 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
3754 struct samr_UserInfo21 *id21,
3760 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3761 return NT_STATUS_INVALID_PARAMETER;
3764 if (id21->fields_present == 0) {
3765 return NT_STATUS_INVALID_PARAMETER;
3768 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3769 return NT_STATUS_ACCESS_DENIED;
3772 /* we need to separately check for an account rename first */
3774 if (id21->account_name.string &&
3775 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
3778 /* check to see if the new username already exists. Note: we can't
3779 reliably lock all backends, so there is potentially the
3780 possibility that a user can be created in between this check and
3781 the rename. The rename should fail, but may not get the
3782 exact same failure status code. I think this is small enough
3783 of a window for this type of operation and the results are
3784 simply that the rename fails with a slightly different status
3785 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3787 status = can_create(mem_ctx, id21->account_name.string);
3788 if (!NT_STATUS_IS_OK(status)) {
3792 status = pdb_rename_sam_account(pwd, id21->account_name.string);
3794 if (!NT_STATUS_IS_OK(status)) {
3795 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3796 nt_errstr(status)));
3800 /* set the new username so that later
3801 functions can work on the new account */
3802 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
3805 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
3808 * The funny part about the previous two calls is
3809 * that pwd still has the password hashes from the
3810 * passdb entry. These have not been updated from
3811 * id21. I don't know if they need to be set. --jerry
3814 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3815 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3816 if ( !NT_STATUS_IS_OK(status) ) {
3821 /* Don't worry about writing out the user account since the
3822 primary group SID is generated solely from the user's Unix
3825 /* write the change out */
3826 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3830 return NT_STATUS_OK;
3833 /*******************************************************************
3835 ********************************************************************/
3837 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
3838 struct samr_UserInfo23 *id23,
3841 char *plaintext_buf = NULL;
3847 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3848 return NT_STATUS_INVALID_PARAMETER;
3851 if (id23->info.fields_present == 0) {
3852 return NT_STATUS_INVALID_PARAMETER;
3855 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3856 return NT_STATUS_ACCESS_DENIED;
3859 if ((id23->info.fields_present & SAMR_FIELD_PASSWORD) ||
3860 (id23->info.fields_present & SAMR_FIELD_PASSWORD2)) {
3862 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3863 pdb_get_username(pwd)));
3865 if (!decode_pw_buffer(mem_ctx,
3866 id23->password.data,
3870 return NT_STATUS_WRONG_PASSWORD;
3873 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3874 return NT_STATUS_ACCESS_DENIED;
3878 copy_id23_to_sam_passwd(pwd, id23);
3880 acct_ctrl = pdb_get_acct_ctrl(pwd);
3882 /* if it's a trust account, don't update /etc/passwd */
3883 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3884 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3885 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3886 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3887 } else if (plaintext_buf) {
3888 /* update the UNIX password */
3889 if (lp_unix_password_sync() ) {
3890 struct passwd *passwd;
3891 if (pdb_get_username(pwd) == NULL) {
3892 DEBUG(1, ("chgpasswd: User without name???\n"));
3893 return NT_STATUS_ACCESS_DENIED;
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)) {
3902 return NT_STATUS_ACCESS_DENIED;
3904 TALLOC_FREE(passwd);
3908 if (plaintext_buf) {
3909 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3912 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3913 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3918 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3922 return NT_STATUS_OK;
3925 /*******************************************************************
3927 ********************************************************************/
3929 static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
3933 char *plaintext_buf = NULL;
3935 time_t last_set_time;
3936 enum pdb_value_state last_set_state;
3938 DEBUG(5, ("Attempting administrator password change for user %s\n",
3939 pdb_get_username(pwd)));
3941 acct_ctrl = pdb_get_acct_ctrl(pwd);
3942 /* we need to know if it's expired, because this is an admin change, not a
3943 user change, so it's still expired when we're done */
3944 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3945 last_set_time = pdb_get_pass_last_set_time(pwd);
3947 if (!decode_pw_buffer(talloc_tos(),
3955 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3959 /* if it's a trust account, don't update /etc/passwd */
3960 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3961 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3962 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3963 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3965 /* update the UNIX password */
3966 if (lp_unix_password_sync()) {
3967 struct passwd *passwd;
3969 if (pdb_get_username(pwd) == NULL) {
3970 DEBUG(1, ("chgpasswd: User without name???\n"));
3974 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3975 if (passwd == NULL) {
3976 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3979 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3982 TALLOC_FREE(passwd);
3986 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3989 * A level 25 change does reset the pwdlastset field, a level 24
3990 * change does not. I know this is probably not the full story, but
3991 * it is needed to make XP join LDAP correctly, without it the later
3992 * auth2 check can fail with PWD_MUST_CHANGE.
3996 * restore last set time as this is an admin change, not a
3999 pdb_set_pass_last_set_time (pwd, last_set_time,
4003 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
4005 /* update the SAMBA password */
4006 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
4013 /*******************************************************************
4015 ********************************************************************/
4017 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
4018 struct samr_UserInfo25 *id25,
4024 DEBUG(5, ("set_user_info_25: NULL id25\n"));
4025 return NT_STATUS_INVALID_PARAMETER;
4028 if (id25->info.fields_present == 0) {
4029 return NT_STATUS_INVALID_PARAMETER;
4032 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
4033 return NT_STATUS_ACCESS_DENIED;
4036 copy_id25_to_sam_passwd(pwd, id25);
4038 /* write the change out */
4039 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
4044 * We need to "pdb_update_sam_account" before the unix primary group
4045 * is set, because the idealx scripts would also change the
4046 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
4047 * the delete explicit / add explicit, which would then fail to find
4048 * the previous primaryGroupSid value.
4051 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
4052 status = pdb_set_unix_primary_group(mem_ctx, pwd);
4053 if ( !NT_STATUS_IS_OK(status) ) {
4058 return NT_STATUS_OK;
4061 /*******************************************************************
4063 ********************************************************************/
4065 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
4066 struct samr_SetUserInfo *r)
4069 struct samu *pwd = NULL;
4071 POLICY_HND *pol = r->in.user_handle;
4072 union samr_UserInfo *info = r->in.info;
4073 uint16_t switch_value = r->in.level;
4074 uint32_t acc_granted;
4075 uint32_t acc_required;
4077 bool has_enough_rights = False;
4079 DISP_INFO *disp_info = NULL;
4081 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4083 /* find the policy handle. open a policy on it. */
4084 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) {
4085 return NT_STATUS_INVALID_HANDLE;
4088 /* This is tricky. A WinXP domain join sets
4089 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4090 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4091 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4092 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4093 we'll use the set from the WinXP join as the basis. */
4095 switch (switch_value) {
4100 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4103 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4104 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4105 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4109 status = access_check_samr_function(acc_granted,
4111 "_samr_SetUserInfo");
4112 if (!NT_STATUS_IS_OK(status)) {
4116 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4117 sid_string_dbg(&sid), switch_value));
4120 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4121 return NT_STATUS_INVALID_INFO_CLASS;
4124 if (!(pwd = samu_new(NULL))) {
4125 return NT_STATUS_NO_MEMORY;
4129 ret = pdb_getsampwsid(pwd, &sid);
4134 return NT_STATUS_NO_SUCH_USER;
4137 /* deal with machine password changes differently from userinfo changes */
4138 /* check to see if we have the sufficient rights */
4140 acb_info = pdb_get_acct_ctrl(pwd);
4141 if (acb_info & ACB_WSTRUST)
4142 has_enough_rights = user_has_privileges(p->server_info->ptok,
4143 &se_machine_account);
4144 else if (acb_info & ACB_NORMAL)
4145 has_enough_rights = user_has_privileges(p->server_info->ptok,
4147 else if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
4148 if (lp_enable_privileges()) {
4149 has_enough_rights = nt_token_check_domain_rid(p->server_info->ptok,
4150 DOMAIN_GROUP_RID_ADMINS);
4154 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4155 uidtoname(p->server_info->utok.uid),
4156 has_enough_rights ? "" : " not"));
4158 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4160 if (has_enough_rights) {
4164 /* ok! user info levels (lots: see MSDEV help), off we go... */
4166 switch (switch_value) {
4169 status = set_user_info_7(p->mem_ctx,
4174 if (!set_user_info_16(&info->info16, pwd)) {
4175 status = NT_STATUS_ACCESS_DENIED;
4180 /* Used by AS/U JRA. */
4181 if (!set_user_info_18(&info->info18, pwd)) {
4182 status = NT_STATUS_ACCESS_DENIED;
4187 if (!set_user_info_20(&info->info20, pwd)) {
4188 status = NT_STATUS_ACCESS_DENIED;
4193 status = set_user_info_21(p->mem_ctx,
4194 &info->info21, pwd);
4198 if (!p->server_info->user_session_key.length) {
4199 status = NT_STATUS_NO_USER_SESSION_KEY;
4201 SamOEMhashBlob(info->info23.password.data, 516,
4202 &p->server_info->user_session_key);
4204 dump_data(100, info->info23.password.data, 516);
4206 status = set_user_info_23(p->mem_ctx,
4207 &info->info23, pwd);
4211 if (!p->server_info->user_session_key.length) {
4212 status = NT_STATUS_NO_USER_SESSION_KEY;
4214 SamOEMhashBlob(info->info24.password.data,
4216 &p->server_info->user_session_key);
4218 dump_data(100, info->info24.password.data, 516);
4220 if (!set_user_info_pw(info->info24.password.data, pwd,
4222 status = NT_STATUS_WRONG_PASSWORD;
4227 if (!p->server_info->user_session_key.length) {
4228 status = NT_STATUS_NO_USER_SESSION_KEY;
4230 encode_or_decode_arc4_passwd_buffer(
4231 info->info25.password.data,
4232 &p->server_info->user_session_key);
4234 dump_data(100, info->info25.password.data, 532);
4236 status = set_user_info_25(p->mem_ctx,
4237 &info->info25, pwd);
4238 if (!NT_STATUS_IS_OK(status)) {
4241 if (!set_user_info_pw(info->info25.password.data, pwd,
4243 status = NT_STATUS_WRONG_PASSWORD;
4248 if (!p->server_info->user_session_key.length) {
4249 status = NT_STATUS_NO_USER_SESSION_KEY;
4251 encode_or_decode_arc4_passwd_buffer(
4252 info->info26.password.data,
4253 &p->server_info->user_session_key);
4255 dump_data(100, info->info26.password.data, 516);
4257 if (!set_user_info_pw(info->info26.password.data, pwd,
4259 status = NT_STATUS_WRONG_PASSWORD;
4264 status = NT_STATUS_INVALID_INFO_CLASS;
4271 if (has_enough_rights) {
4275 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4277 if (NT_STATUS_IS_OK(status)) {
4278 force_flush_samr_cache(disp_info);
4284 /*******************************************************************
4286 ********************************************************************/
4288 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
4289 struct samr_SetUserInfo2 *r)
4291 struct samr_SetUserInfo q;
4293 q.in.user_handle = r->in.user_handle;
4294 q.in.level = r->in.level;
4295 q.in.info = r->in.info;
4297 return _samr_SetUserInfo(p, &q);
4300 /*********************************************************************
4301 _samr_GetAliasMembership
4302 *********************************************************************/
4304 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
4305 struct samr_GetAliasMembership *r)
4307 size_t num_alias_rids;
4309 struct samr_info *info = NULL;
4317 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
4319 /* find the policy handle. open a policy on it. */
4320 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
4321 return NT_STATUS_INVALID_HANDLE;
4323 ntstatus1 = access_check_samr_function(info->acc_granted,
4324 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
4325 "_samr_GetAliasMembership");
4326 ntstatus2 = access_check_samr_function(info->acc_granted,
4327 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4328 "_samr_GetAliasMembership");
4330 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
4331 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
4332 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
4333 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
4337 if (!sid_check_is_domain(&info->sid) &&
4338 !sid_check_is_builtin(&info->sid))
4339 return NT_STATUS_OBJECT_TYPE_MISMATCH;
4341 if (r->in.sids->num_sids) {
4342 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
4344 if (members == NULL)
4345 return NT_STATUS_NO_MEMORY;
4350 for (i=0; i<r->in.sids->num_sids; i++)
4351 sid_copy(&members[i], r->in.sids->sids[i].sid);
4357 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
4358 r->in.sids->num_sids,
4359 &alias_rids, &num_alias_rids);
4362 if (!NT_STATUS_IS_OK(ntstatus1)) {
4366 r->out.rids->count = num_alias_rids;
4367 r->out.rids->ids = alias_rids;
4369 return NT_STATUS_OK;
4372 /*********************************************************************
4373 _samr_GetMembersInAlias
4374 *********************************************************************/
4376 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
4377 struct samr_GetMembersInAlias *r)
4381 size_t num_sids = 0;
4382 struct lsa_SidPtr *sids = NULL;
4383 DOM_SID *pdb_sids = NULL;
4389 /* find the policy handle. open a policy on it. */
4390 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
4391 return NT_STATUS_INVALID_HANDLE;
4393 status = access_check_samr_function(acc_granted,
4394 SAMR_ALIAS_ACCESS_GET_MEMBERS,
4395 "_samr_GetMembersInAlias");
4396 if (!NT_STATUS_IS_OK(status)) {
4400 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4403 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
4406 if (!NT_STATUS_IS_OK(status)) {
4411 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
4413 TALLOC_FREE(pdb_sids);
4414 return NT_STATUS_NO_MEMORY;
4418 for (i = 0; i < num_sids; i++) {
4419 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
4421 TALLOC_FREE(pdb_sids);
4422 return NT_STATUS_NO_MEMORY;
4426 r->out.sids->num_sids = num_sids;
4427 r->out.sids->sids = sids;
4429 TALLOC_FREE(pdb_sids);
4431 return NT_STATUS_OK;
4434 /*********************************************************************
4435 _samr_QueryGroupMember
4436 *********************************************************************/
4438 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
4439 struct samr_QueryGroupMember *r)
4442 size_t i, num_members;
4450 struct samr_RidTypeArray *rids = NULL;
4452 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
4454 return NT_STATUS_NO_MEMORY;
4457 /* find the policy handle. open a policy on it. */
4458 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
4459 return NT_STATUS_INVALID_HANDLE;
4461 status = access_check_samr_function(acc_granted,
4462 SAMR_GROUP_ACCESS_GET_MEMBERS,
4463 "_samr_QueryGroupMember");
4464 if (!NT_STATUS_IS_OK(status)) {
4468 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4470 if (!sid_check_is_in_our_domain(&group_sid)) {
4471 DEBUG(3, ("sid %s is not in our domain\n",
4472 sid_string_dbg(&group_sid)));
4473 return NT_STATUS_NO_SUCH_GROUP;
4476 DEBUG(10, ("lookup on Domain SID\n"));
4479 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
4480 &rid, &num_members);
4483 if (!NT_STATUS_IS_OK(status))
4487 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
4489 return NT_STATUS_NO_MEMORY;
4495 for (i=0; i<num_members; i++)
4496 attr[i] = SID_NAME_USER;
4498 rids->count = num_members;
4502 *r->out.rids = rids;
4504 return NT_STATUS_OK;
4507 /*********************************************************************
4508 _samr_AddAliasMember
4509 *********************************************************************/
4511 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
4512 struct samr_AddAliasMember *r)
4517 bool can_add_accounts;
4519 DISP_INFO *disp_info = NULL;
4521 /* Find the policy handle. Open a policy on it. */
4522 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4523 return NT_STATUS_INVALID_HANDLE;
4525 status = access_check_samr_function(acc_granted,
4526 SAMR_ALIAS_ACCESS_ADD_MEMBER,
4527 "_samr_AddAliasMember");
4528 if (!NT_STATUS_IS_OK(status)) {
4532 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4534 se_priv_copy( &se_rights, &se_add_users );
4535 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4537 /******** BEGIN SeAddUsers BLOCK *********/
4539 if ( can_add_accounts )
4542 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
4544 if ( can_add_accounts )
4547 /******** END SeAddUsers BLOCK *********/
4549 if (NT_STATUS_IS_OK(status)) {
4550 force_flush_samr_cache(disp_info);
4556 /*********************************************************************
4557 _samr_DeleteAliasMember
4558 *********************************************************************/
4560 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
4561 struct samr_DeleteAliasMember *r)
4566 bool can_add_accounts;
4568 DISP_INFO *disp_info = NULL;
4570 /* Find the policy handle. Open a policy on it. */
4571 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4572 return NT_STATUS_INVALID_HANDLE;
4574 status = access_check_samr_function(acc_granted,
4575 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
4576 "_samr_DeleteAliasMember");
4577 if (!NT_STATUS_IS_OK(status)) {
4581 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4582 sid_string_dbg(&alias_sid)));
4584 se_priv_copy( &se_rights, &se_add_users );
4585 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4587 /******** BEGIN SeAddUsers BLOCK *********/
4589 if ( can_add_accounts )
4592 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
4594 if ( can_add_accounts )
4597 /******** END SeAddUsers BLOCK *********/
4599 if (NT_STATUS_IS_OK(status)) {
4600 force_flush_samr_cache(disp_info);
4606 /*********************************************************************
4607 _samr_AddGroupMember
4608 *********************************************************************/
4610 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
4611 struct samr_AddGroupMember *r)
4618 bool can_add_accounts;
4619 DISP_INFO *disp_info = NULL;
4621 /* Find the policy handle. Open a policy on it. */
4622 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4623 return NT_STATUS_INVALID_HANDLE;
4625 status = access_check_samr_function(acc_granted,
4626 SAMR_GROUP_ACCESS_ADD_MEMBER,
4627 "_samr_AddGroupMember");
4628 if (!NT_STATUS_IS_OK(status)) {
4632 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4634 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4636 return NT_STATUS_INVALID_HANDLE;
4639 se_priv_copy( &se_rights, &se_add_users );
4640 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4642 /******** BEGIN SeAddUsers BLOCK *********/
4644 if ( can_add_accounts )
4647 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
4649 if ( can_add_accounts )
4652 /******** END SeAddUsers BLOCK *********/
4654 force_flush_samr_cache(disp_info);
4659 /*********************************************************************
4660 _samr_DeleteGroupMember
4661 *********************************************************************/
4663 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
4664 struct samr_DeleteGroupMember *r)
4672 bool can_add_accounts;
4673 DISP_INFO *disp_info = NULL;
4676 * delete the group member named r->in.rid
4677 * who is a member of the sid associated with the handle
4678 * the rid is a user's rid as the group is a domain group.
4681 /* Find the policy handle. Open a policy on it. */
4682 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4683 return NT_STATUS_INVALID_HANDLE;
4685 status = access_check_samr_function(acc_granted,
4686 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
4687 "_samr_DeleteGroupMember");
4688 if (!NT_STATUS_IS_OK(status)) {
4692 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4694 return NT_STATUS_INVALID_HANDLE;
4697 se_priv_copy( &se_rights, &se_add_users );
4698 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4700 /******** BEGIN SeAddUsers BLOCK *********/
4702 if ( can_add_accounts )
4705 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
4707 if ( can_add_accounts )
4710 /******** END SeAddUsers BLOCK *********/
4712 force_flush_samr_cache(disp_info);
4717 /*********************************************************************
4719 *********************************************************************/
4721 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4722 struct samr_DeleteUser *r)
4726 struct samu *sam_pass=NULL;
4728 bool can_add_accounts;
4730 DISP_INFO *disp_info = NULL;
4733 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4735 /* Find the policy handle. Open a policy on it. */
4736 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4737 return NT_STATUS_INVALID_HANDLE;
4739 status = access_check_samr_function(acc_granted,
4740 STD_RIGHT_DELETE_ACCESS,
4741 "_samr_DeleteUser");
4742 if (!NT_STATUS_IS_OK(status)) {
4746 if (!sid_check_is_in_our_domain(&user_sid))
4747 return NT_STATUS_CANNOT_DELETE;
4749 /* check if the user exists before trying to delete */
4750 if ( !(sam_pass = samu_new( NULL )) ) {
4751 return NT_STATUS_NO_MEMORY;
4755 ret = pdb_getsampwsid(sam_pass, &user_sid);
4759 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4760 sid_string_dbg(&user_sid)));
4761 TALLOC_FREE(sam_pass);
4762 return NT_STATUS_NO_SUCH_USER;
4765 acb_info = pdb_get_acct_ctrl(sam_pass);
4767 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4768 if ( acb_info & ACB_WSTRUST ) {
4769 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_machine_account );
4771 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
4774 /******** BEGIN SeAddUsers BLOCK *********/
4776 if ( can_add_accounts )
4779 status = pdb_delete_user(p->mem_ctx, sam_pass);
4781 if ( can_add_accounts )
4784 /******** END SeAddUsers BLOCK *********/
4786 if ( !NT_STATUS_IS_OK(status) ) {
4787 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4788 "user %s: %s.\n", pdb_get_username(sam_pass),
4789 nt_errstr(status)));
4790 TALLOC_FREE(sam_pass);
4795 TALLOC_FREE(sam_pass);
4797 if (!close_policy_hnd(p, r->in.user_handle))
4798 return NT_STATUS_OBJECT_NAME_INVALID;
4800 ZERO_STRUCTP(r->out.user_handle);
4802 force_flush_samr_cache(disp_info);
4804 return NT_STATUS_OK;
4807 /*********************************************************************
4808 _samr_DeleteDomainGroup
4809 *********************************************************************/
4811 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4812 struct samr_DeleteDomainGroup *r)
4819 bool can_add_accounts;
4820 DISP_INFO *disp_info = NULL;
4822 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4824 /* Find the policy handle. Open a policy on it. */
4825 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4826 return NT_STATUS_INVALID_HANDLE;
4828 status = access_check_samr_function(acc_granted,
4829 STD_RIGHT_DELETE_ACCESS,
4830 "_samr_DeleteDomainGroup");
4831 if (!NT_STATUS_IS_OK(status)) {
4835 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4837 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4839 return NT_STATUS_NO_SUCH_GROUP;
4842 se_priv_copy( &se_rights, &se_add_users );
4843 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4845 /******** BEGIN SeAddUsers BLOCK *********/
4847 if ( can_add_accounts )
4850 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4852 if ( can_add_accounts )
4855 /******** END SeAddUsers BLOCK *********/
4857 if ( !NT_STATUS_IS_OK(status) ) {
4858 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4859 "entry for group %s: %s\n",
4860 sid_string_dbg(&group_sid),
4861 nt_errstr(status)));
4865 if (!close_policy_hnd(p, r->in.group_handle))
4866 return NT_STATUS_OBJECT_NAME_INVALID;
4868 force_flush_samr_cache(disp_info);
4870 return NT_STATUS_OK;
4873 /*********************************************************************
4874 _samr_DeleteDomAlias
4875 *********************************************************************/
4877 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4878 struct samr_DeleteDomAlias *r)
4883 bool can_add_accounts;
4885 DISP_INFO *disp_info = NULL;
4887 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4889 /* Find the policy handle. Open a policy on it. */
4890 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4891 return NT_STATUS_INVALID_HANDLE;
4893 /* copy the handle to the outgoing reply */
4895 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4897 status = access_check_samr_function(acc_granted,
4898 STD_RIGHT_DELETE_ACCESS,
4899 "_samr_DeleteDomAlias");
4900 if (!NT_STATUS_IS_OK(status)) {
4904 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4906 /* Don't let Windows delete builtin groups */
4908 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4909 return NT_STATUS_SPECIAL_ACCOUNT;
4912 if (!sid_check_is_in_our_domain(&alias_sid))
4913 return NT_STATUS_NO_SUCH_ALIAS;
4915 DEBUG(10, ("lookup on Local SID\n"));
4917 se_priv_copy( &se_rights, &se_add_users );
4918 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4920 /******** BEGIN SeAddUsers BLOCK *********/
4922 if ( can_add_accounts )
4925 /* Have passdb delete the alias */
4926 status = pdb_delete_alias(&alias_sid);
4928 if ( can_add_accounts )
4931 /******** END SeAddUsers BLOCK *********/
4933 if ( !NT_STATUS_IS_OK(status))
4936 if (!close_policy_hnd(p, r->in.alias_handle))
4937 return NT_STATUS_OBJECT_NAME_INVALID;
4939 force_flush_samr_cache(disp_info);
4941 return NT_STATUS_OK;
4944 /*********************************************************************
4945 _samr_CreateDomainGroup
4946 *********************************************************************/
4948 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4949 struct samr_CreateDomainGroup *r)
4956 struct samr_info *info;
4959 bool can_add_accounts;
4960 DISP_INFO *disp_info = NULL;
4962 /* Find the policy handle. Open a policy on it. */
4963 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4964 return NT_STATUS_INVALID_HANDLE;
4966 status = access_check_samr_function(acc_granted,
4967 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
4968 "_samr_CreateDomainGroup");
4969 if (!NT_STATUS_IS_OK(status)) {
4973 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4974 return NT_STATUS_ACCESS_DENIED;
4976 name = r->in.name->string;
4978 return NT_STATUS_NO_MEMORY;
4981 status = can_create(p->mem_ctx, name);
4982 if (!NT_STATUS_IS_OK(status)) {
4986 se_priv_copy( &se_rights, &se_add_users );
4987 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4989 /******** BEGIN SeAddUsers BLOCK *********/
4991 if ( can_add_accounts )
4994 /* check that we successfully create the UNIX group */
4996 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4998 if ( can_add_accounts )
5001 /******** END SeAddUsers BLOCK *********/
5003 /* check if we should bail out here */
5005 if ( !NT_STATUS_IS_OK(status) )
5008 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
5010 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
5011 return NT_STATUS_NO_MEMORY;
5013 /* they created it; let the user do what he wants with it */
5015 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
5017 /* get a (unique) handle. open a policy on it. */
5018 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
5019 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5021 force_flush_samr_cache(disp_info);
5023 return NT_STATUS_OK;
5026 /*********************************************************************
5027 _samr_CreateDomAlias
5028 *********************************************************************/
5030 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
5031 struct samr_CreateDomAlias *r)
5035 const char *name = NULL;
5036 struct samr_info *info;
5041 bool can_add_accounts;
5042 DISP_INFO *disp_info = NULL;
5044 /* Find the policy handle. Open a policy on it. */
5045 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
5046 return NT_STATUS_INVALID_HANDLE;
5048 result = access_check_samr_function(acc_granted,
5049 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
5050 "_samr_CreateDomAlias");
5051 if (!NT_STATUS_IS_OK(result)) {
5055 if (!sid_equal(&dom_sid, get_global_sam_sid()))
5056 return NT_STATUS_ACCESS_DENIED;
5058 name = r->in.alias_name->string;
5060 se_priv_copy( &se_rights, &se_add_users );
5061 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
5063 result = can_create(p->mem_ctx, name);
5064 if (!NT_STATUS_IS_OK(result)) {
5068 /******** BEGIN SeAddUsers BLOCK *********/
5070 if ( can_add_accounts )
5073 /* Have passdb create the alias */
5074 result = pdb_create_alias(name, r->out.rid);
5076 if ( can_add_accounts )
5079 /******** END SeAddUsers BLOCK *********/
5081 if (!NT_STATUS_IS_OK(result)) {
5082 DEBUG(10, ("pdb_create_alias failed: %s\n",
5083 nt_errstr(result)));
5087 sid_copy(&info_sid, get_global_sam_sid());
5088 sid_append_rid(&info_sid, *r->out.rid);
5090 if (!sid_to_gid(&info_sid, &gid)) {
5091 DEBUG(10, ("Could not find alias just created\n"));
5092 return NT_STATUS_ACCESS_DENIED;
5095 /* check if the group has been successfully created */
5096 if ( getgrgid(gid) == NULL ) {
5097 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5099 return NT_STATUS_ACCESS_DENIED;
5102 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
5103 return NT_STATUS_NO_MEMORY;
5105 /* they created it; let the user do what he wants with it */
5107 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5109 /* get a (unique) handle. open a policy on it. */
5110 if (!create_policy_hnd(p, r->out.alias_handle, free_samr_info, (void *)info))
5111 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5113 force_flush_samr_cache(disp_info);
5115 return NT_STATUS_OK;
5118 /*********************************************************************
5119 _samr_QueryGroupInfo
5120 *********************************************************************/
5122 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5123 struct samr_QueryGroupInfo *r)
5128 union samr_GroupInfo *info = NULL;
5131 uint32_t attributes = SE_GROUP_MANDATORY |
5132 SE_GROUP_ENABLED_BY_DEFAULT |
5134 const char *group_name = NULL;
5135 const char *group_description = NULL;
5137 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5138 return NT_STATUS_INVALID_HANDLE;
5140 status = access_check_samr_function(acc_granted,
5141 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5142 "_samr_QueryGroupInfo");
5143 if (!NT_STATUS_IS_OK(status)) {
5148 ret = get_domain_group_from_sid(group_sid, &map);
5151 return NT_STATUS_INVALID_HANDLE;
5153 /* FIXME: map contains fstrings */
5154 group_name = talloc_strdup(r, map.nt_name);
5155 group_description = talloc_strdup(r, map.comment);
5157 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5159 return NT_STATUS_NO_MEMORY;
5162 switch (r->in.level) {
5168 status = pdb_enum_group_members(
5169 p->mem_ctx, &group_sid, &members, &num_members);
5172 if (!NT_STATUS_IS_OK(status)) {
5176 init_samr_group_info1(&info->all,
5184 init_samr_group_info2(&info->name,
5188 init_samr_group_info3(&info->attributes,
5192 init_samr_group_info4(&info->description,
5203 status = pdb_enum_group_members(
5204 p->mem_ctx, &group_sid, &members, &num_members);
5207 if (!NT_STATUS_IS_OK(status)) {
5211 init_samr_group_info5(&info->all2,
5214 0, /* num_members - in w2k3 this is always 0 */
5220 return NT_STATUS_INVALID_INFO_CLASS;
5223 *r->out.info = info;
5225 return NT_STATUS_OK;
5228 /*********************************************************************
5230 *********************************************************************/
5232 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5233 struct samr_SetGroupInfo *r)
5240 bool can_mod_accounts;
5241 DISP_INFO *disp_info = NULL;
5243 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5244 return NT_STATUS_INVALID_HANDLE;
5246 status = access_check_samr_function(acc_granted,
5247 SAMR_GROUP_ACCESS_SET_INFO,
5248 "_samr_SetGroupInfo");
5249 if (!NT_STATUS_IS_OK(status)) {
5254 ret = get_domain_group_from_sid(group_sid, &map);
5257 return NT_STATUS_NO_SUCH_GROUP;
5259 switch (r->in.level) {
5261 fstrcpy(map.comment, r->in.info->all.description.string);
5264 /* group rename is not supported yet */
5265 return NT_STATUS_NOT_SUPPORTED;
5267 fstrcpy(map.comment, r->in.info->description.string);
5270 return NT_STATUS_INVALID_INFO_CLASS;
5273 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5275 /******** BEGIN SeAddUsers BLOCK *********/
5277 if ( can_mod_accounts )
5280 status = pdb_update_group_mapping_entry(&map);
5282 if ( can_mod_accounts )
5285 /******** End SeAddUsers BLOCK *********/
5287 if (NT_STATUS_IS_OK(status)) {
5288 force_flush_samr_cache(disp_info);
5294 /*********************************************************************
5296 *********************************************************************/
5298 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5299 struct samr_SetAliasInfo *r)
5302 struct acct_info info;
5304 bool can_mod_accounts;
5306 DISP_INFO *disp_info = NULL;
5308 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
5309 return NT_STATUS_INVALID_HANDLE;
5311 status = access_check_samr_function(acc_granted,
5312 SAMR_ALIAS_ACCESS_SET_INFO,
5313 "_samr_SetAliasInfo");
5314 if (!NT_STATUS_IS_OK(status)) {
5318 /* get the current group information */
5321 status = pdb_get_aliasinfo( &group_sid, &info );
5324 if ( !NT_STATUS_IS_OK(status))
5327 switch (r->in.level) {
5332 /* We currently do not support renaming groups in the
5333 the BUILTIN domain. Refer to util_builtin.c to understand
5334 why. The eventually needs to be fixed to be like Windows
5335 where you can rename builtin groups, just not delete them */
5337 if ( sid_check_is_in_builtin( &group_sid ) ) {
5338 return NT_STATUS_SPECIAL_ACCOUNT;
5341 /* There has to be a valid name (and it has to be different) */
5343 if ( !r->in.info->name.string )
5344 return NT_STATUS_INVALID_PARAMETER;
5346 /* If the name is the same just reply "ok". Yes this
5347 doesn't allow you to change the case of a group name. */
5349 if ( strequal( r->in.info->name.string, info.acct_name ) )
5350 return NT_STATUS_OK;
5352 fstrcpy( info.acct_name, r->in.info->name.string);
5354 /* make sure the name doesn't already exist as a user
5357 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
5358 status = can_create( p->mem_ctx, group_name );
5359 if ( !NT_STATUS_IS_OK( status ) )
5363 case ALIASINFODESCRIPTION:
5364 if (r->in.info->description.string) {
5365 fstrcpy(info.acct_desc,
5366 r->in.info->description.string);
5368 fstrcpy( info.acct_desc, "" );
5372 return NT_STATUS_INVALID_INFO_CLASS;
5375 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5377 /******** BEGIN SeAddUsers BLOCK *********/
5379 if ( can_mod_accounts )
5382 status = pdb_set_aliasinfo( &group_sid, &info );
5384 if ( can_mod_accounts )
5387 /******** End SeAddUsers BLOCK *********/
5389 if (NT_STATUS_IS_OK(status))
5390 force_flush_samr_cache(disp_info);
5395 /****************************************************************
5397 ****************************************************************/
5399 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
5400 struct samr_GetDomPwInfo *r)
5402 uint32_t min_password_length = 0;
5403 uint32_t password_properties = 0;
5405 /* Perform access check. Since this rpc does not require a
5406 policy handle it will not be caught by the access checks on
5407 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5409 if (!pipe_access_check(p)) {
5410 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5411 return NT_STATUS_ACCESS_DENIED;
5415 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
5416 &min_password_length);
5417 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
5418 &password_properties);
5421 if (lp_check_password_script() && *lp_check_password_script()) {
5422 password_properties |= DOMAIN_PASSWORD_COMPLEX;
5425 r->out.info->min_password_length = min_password_length;
5426 r->out.info->password_properties = password_properties;
5428 return NT_STATUS_OK;
5431 /*********************************************************************
5433 *********************************************************************/
5435 NTSTATUS _samr_OpenGroup(pipes_struct *p,
5436 struct samr_OpenGroup *r)
5442 struct samr_info *info;
5443 SEC_DESC *psd = NULL;
5445 uint32 des_access = r->in.access_mask;
5452 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
5453 return NT_STATUS_INVALID_HANDLE;
5455 status = access_check_samr_function(acc_granted,
5456 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5459 if ( !NT_STATUS_IS_OK(status) )
5462 /*check if access can be granted as requested by client. */
5463 map_max_allowed_access(p->server_info->ptok, &des_access);
5465 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
5466 se_map_generic(&des_access,&grp_generic_mapping);
5468 se_priv_copy( &se_rights, &se_add_users );
5470 status = access_check_samr_object(psd, p->server_info->ptok,
5471 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
5472 &acc_granted, "_samr_OpenGroup");
5474 if ( !NT_STATUS_IS_OK(status) )
5477 /* this should not be hard-coded like this */
5479 if (!sid_equal(&sid, get_global_sam_sid()))
5480 return NT_STATUS_ACCESS_DENIED;
5482 sid_copy(&info_sid, get_global_sam_sid());
5483 sid_append_rid(&info_sid, r->in.rid);
5484 sid_to_fstring(sid_string, &info_sid);
5486 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
5487 return NT_STATUS_NO_MEMORY;
5489 info->acc_granted = acc_granted;
5491 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
5493 /* check if that group really exists */
5495 ret = get_domain_group_from_sid(info->sid, &map);
5498 return NT_STATUS_NO_SUCH_GROUP;
5500 /* get a (unique) handle. open a policy on it. */
5501 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
5502 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5504 return NT_STATUS_OK;
5507 /*********************************************************************
5508 _samr_RemoveMemberFromForeignDomain
5509 *********************************************************************/
5511 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5512 struct samr_RemoveMemberFromForeignDomain *r)
5514 DOM_SID delete_sid, domain_sid;
5517 DISP_INFO *disp_info = NULL;
5519 sid_copy( &delete_sid, r->in.sid );
5521 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5522 sid_string_dbg(&delete_sid)));
5524 /* Find the policy handle. Open a policy on it. */
5526 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
5527 &acc_granted, &disp_info))
5528 return NT_STATUS_INVALID_HANDLE;
5530 result = access_check_samr_function(acc_granted,
5531 STD_RIGHT_DELETE_ACCESS,
5532 "_samr_RemoveMemberFromForeignDomain");
5534 if (!NT_STATUS_IS_OK(result))
5537 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5538 sid_string_dbg(&domain_sid)));
5540 /* we can only delete a user from a group since we don't have
5541 nested groups anyways. So in the latter case, just say OK */
5543 /* TODO: The above comment nowadays is bogus. Since we have nested
5544 * groups now, and aliases members are never reported out of the unix
5545 * group membership, the "just say OK" makes this call a no-op. For
5546 * us. This needs fixing however. */
5548 /* I've only ever seen this in the wild when deleting a user from
5549 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5550 * is the user about to be deleted. I very much suspect this is the
5551 * only application of this call. To verify this, let people report
5554 if (!sid_check_is_builtin(&domain_sid)) {
5555 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5556 "global_sam_sid() = %s\n",
5557 sid_string_dbg(&domain_sid),
5558 sid_string_dbg(get_global_sam_sid())));
5559 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5560 return NT_STATUS_OK;
5563 force_flush_samr_cache(disp_info);
5565 result = NT_STATUS_OK;
5570 /*******************************************************************
5571 _samr_QueryDomainInfo2
5572 ********************************************************************/
5574 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5575 struct samr_QueryDomainInfo2 *r)
5577 struct samr_QueryDomainInfo q;
5579 q.in.domain_handle = r->in.domain_handle;
5580 q.in.level = r->in.level;
5582 q.out.info = r->out.info;
5584 return _samr_QueryDomainInfo(p, &q);
5587 /*******************************************************************
5589 ********************************************************************/
5591 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5592 struct samr_SetDomainInfo *r)
5594 struct samr_info *info = NULL;
5595 time_t u_expire, u_min_age;
5597 time_t u_lock_duration, u_reset_time;
5600 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5602 /* find the policy handle. open a policy on it. */
5603 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5604 return NT_STATUS_INVALID_HANDLE;
5606 /* We do have different access bits for info
5607 * levels here, but we're really just looking for
5608 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5609 * this maps to different specific bits. So
5610 * assume if we have SAMR_DOMAIN_ACCESS_SET_INFO_1
5613 result = access_check_samr_function(info->acc_granted,
5614 SAMR_DOMAIN_ACCESS_SET_INFO_1,
5615 "_samr_SetDomainInfo");
5617 if (!NT_STATUS_IS_OK(result))
5620 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
5622 switch (r->in.level) {
5624 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
5625 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
5626 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
5627 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
5628 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
5629 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5630 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5635 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
5636 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5645 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
5646 if (u_lock_duration != -1)
5647 u_lock_duration /= 60;
5649 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
5651 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5652 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5653 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
5656 return NT_STATUS_INVALID_INFO_CLASS;
5659 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5661 return NT_STATUS_OK;
5664 /****************************************************************
5665 _samr_GetDisplayEnumerationIndex
5666 ****************************************************************/
5668 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5669 struct samr_GetDisplayEnumerationIndex *r)
5671 struct samr_info *info = NULL;
5672 uint32_t max_entries = (uint32_t) -1;
5673 uint32_t enum_context = 0;
5675 uint32_t num_account = 0;
5676 struct samr_displayentry *entries = NULL;
5679 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
5681 /* find the policy handle. open a policy on it. */
5682 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
5683 return NT_STATUS_INVALID_HANDLE;
5686 status = access_check_samr_function(info->acc_granted,
5687 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
5688 "_samr_GetDisplayEnumerationIndex");
5689 if (!NT_STATUS_IS_OK(status)) {
5693 if ((r->in.level < 1) || (r->in.level > 3)) {
5694 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5695 "Unknown info level (%u)\n",
5697 return NT_STATUS_INVALID_INFO_CLASS;
5702 /* The following done as ROOT. Don't return without unbecome_root(). */
5704 switch (r->in.level) {
5706 if (info->disp_info->users == NULL) {
5707 info->disp_info->users = pdb_search_users(ACB_NORMAL);
5708 if (info->disp_info->users == NULL) {
5710 return NT_STATUS_ACCESS_DENIED;
5712 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5713 "starting user enumeration at index %u\n",
5714 (unsigned int)enum_context));
5716 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5717 "using cached user enumeration at index %u\n",
5718 (unsigned int)enum_context));
5720 num_account = pdb_search_entries(info->disp_info->users,
5721 enum_context, max_entries,
5725 if (info->disp_info->machines == NULL) {
5726 info->disp_info->machines =
5727 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
5728 if (info->disp_info->machines == NULL) {
5730 return NT_STATUS_ACCESS_DENIED;
5732 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5733 "starting machine enumeration at index %u\n",
5734 (unsigned int)enum_context));
5736 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5737 "using cached machine enumeration at index %u\n",
5738 (unsigned int)enum_context));
5740 num_account = pdb_search_entries(info->disp_info->machines,
5741 enum_context, max_entries,
5745 if (info->disp_info->groups == NULL) {
5746 info->disp_info->groups = pdb_search_groups();
5747 if (info->disp_info->groups == NULL) {
5749 return NT_STATUS_ACCESS_DENIED;
5751 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5752 "starting group enumeration at index %u\n",
5753 (unsigned int)enum_context));
5755 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5756 "using cached group enumeration at index %u\n",
5757 (unsigned int)enum_context));
5759 num_account = pdb_search_entries(info->disp_info->groups,
5760 enum_context, max_entries,
5765 smb_panic("info class changed");
5771 /* Ensure we cache this enumeration. */
5772 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
5774 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5775 r->in.name->string));
5777 for (i=0; i<num_account; i++) {
5778 if (strequal(entries[i].account_name, r->in.name->string)) {
5779 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5780 "found %s at idx %d\n",
5781 r->in.name->string, i));
5783 return NT_STATUS_OK;
5787 /* assuming account_name lives at the very end */
5788 *r->out.idx = num_account;
5790 return NT_STATUS_NO_MORE_ENTRIES;
5793 /****************************************************************
5794 _samr_GetDisplayEnumerationIndex2
5795 ****************************************************************/
5797 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5798 struct samr_GetDisplayEnumerationIndex2 *r)
5800 struct samr_GetDisplayEnumerationIndex q;
5802 q.in.domain_handle = r->in.domain_handle;
5803 q.in.level = r->in.level;
5804 q.in.name = r->in.name;
5806 q.out.idx = r->out.idx;
5808 return _samr_GetDisplayEnumerationIndex(p, &q);
5811 /****************************************************************
5812 ****************************************************************/
5814 NTSTATUS _samr_Shutdown(pipes_struct *p,
5815 struct samr_Shutdown *r)
5817 p->rng_fault_state = true;
5818 return NT_STATUS_NOT_IMPLEMENTED;
5821 /****************************************************************
5822 ****************************************************************/
5824 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5825 struct samr_SetMemberAttributesOfGroup *r)
5827 p->rng_fault_state = true;
5828 return NT_STATUS_NOT_IMPLEMENTED;
5831 /****************************************************************
5832 ****************************************************************/
5834 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5835 struct samr_ChangePasswordUser *r)
5837 p->rng_fault_state = true;
5838 return NT_STATUS_NOT_IMPLEMENTED;
5841 /****************************************************************
5842 ****************************************************************/
5844 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5845 struct samr_TestPrivateFunctionsDomain *r)
5847 p->rng_fault_state = true;
5848 return NT_STATUS_NOT_IMPLEMENTED;
5851 /****************************************************************
5852 ****************************************************************/
5854 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5855 struct samr_TestPrivateFunctionsUser *r)
5857 p->rng_fault_state = true;
5858 return NT_STATUS_NOT_IMPLEMENTED;
5861 /****************************************************************
5862 ****************************************************************/
5864 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5865 struct samr_AddMultipleMembersToAlias *r)
5867 p->rng_fault_state = true;
5868 return NT_STATUS_NOT_IMPLEMENTED;
5871 /****************************************************************
5872 ****************************************************************/
5874 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5875 struct samr_RemoveMultipleMembersFromAlias *r)
5877 p->rng_fault_state = true;
5878 return NT_STATUS_NOT_IMPLEMENTED;
5881 /****************************************************************
5882 ****************************************************************/
5884 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5885 struct samr_OemChangePasswordUser2 *r)
5887 p->rng_fault_state = true;
5888 return NT_STATUS_NOT_IMPLEMENTED;
5891 /****************************************************************
5892 ****************************************************************/
5894 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5895 struct samr_SetBootKeyInformation *r)
5897 p->rng_fault_state = true;
5898 return NT_STATUS_NOT_IMPLEMENTED;
5901 /****************************************************************
5902 ****************************************************************/
5904 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5905 struct samr_GetBootKeyInformation *r)
5907 p->rng_fault_state = true;
5908 return NT_STATUS_NOT_IMPLEMENTED;
5911 /****************************************************************
5912 ****************************************************************/
5914 NTSTATUS _samr_Connect3(pipes_struct *p,
5915 struct samr_Connect3 *r)
5917 p->rng_fault_state = true;
5918 return NT_STATUS_NOT_IMPLEMENTED;
5921 /****************************************************************
5922 ****************************************************************/
5924 NTSTATUS _samr_RidToSid(pipes_struct *p,
5925 struct samr_RidToSid *r)
5927 p->rng_fault_state = true;
5928 return NT_STATUS_NOT_IMPLEMENTED;
5931 /****************************************************************
5932 ****************************************************************/
5934 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5935 struct samr_SetDsrmPassword *r)
5937 p->rng_fault_state = true;
5938 return NT_STATUS_NOT_IMPLEMENTED;
5941 /****************************************************************
5942 ****************************************************************/
5944 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5945 struct samr_ValidatePassword *r)
5947 p->rng_fault_state = true;
5948 return NT_STATUS_NOT_IMPLEMENTED;