2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997,
7 * Copyright (C) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2008,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
14 * Copyright (C) Guenther Deschner 2008.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
31 * This is the implementation of the SAMR code.
37 #define DBGC_CLASS DBGC_RPC_SRV
39 #define SAMR_USR_RIGHTS_WRITE_PW \
40 ( READ_CONTROL_ACCESS | \
41 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
42 SAMR_USER_ACCESS_SET_LOC_COM)
43 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
44 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
46 #define DISP_INFO_CACHE_TIMEOUT 10
48 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
49 #define MAX_SAM_ENTRIES_W95 50
51 typedef struct disp_info {
52 DOM_SID sid; /* identify which domain this is. */
53 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
54 struct pdb_search *users; /* querydispinfo 1 and 4 */
55 struct pdb_search *machines; /* querydispinfo 2 */
56 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
57 struct pdb_search *aliases; /* enumaliases */
60 struct pdb_search *enum_users; /* enumusers with a mask */
62 struct timed_event *cache_timeout_event; /* cache idle timeout
66 /* We keep a static list of these by SID as modern clients close down
67 all resources between each request in a complete enumeration. */
70 /* for use by the \PIPE\samr policy */
72 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
73 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
78 static const struct generic_mapping sam_generic_mapping = {
79 GENERIC_RIGHTS_SAM_READ,
80 GENERIC_RIGHTS_SAM_WRITE,
81 GENERIC_RIGHTS_SAM_EXECUTE,
82 GENERIC_RIGHTS_SAM_ALL_ACCESS};
83 static const struct generic_mapping dom_generic_mapping = {
84 GENERIC_RIGHTS_DOMAIN_READ,
85 GENERIC_RIGHTS_DOMAIN_WRITE,
86 GENERIC_RIGHTS_DOMAIN_EXECUTE,
87 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
88 static const struct generic_mapping usr_generic_mapping = {
89 GENERIC_RIGHTS_USER_READ,
90 GENERIC_RIGHTS_USER_WRITE,
91 GENERIC_RIGHTS_USER_EXECUTE,
92 GENERIC_RIGHTS_USER_ALL_ACCESS};
93 static const struct generic_mapping usr_nopwchange_generic_mapping = {
94 GENERIC_RIGHTS_USER_READ,
95 GENERIC_RIGHTS_USER_WRITE,
96 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
97 GENERIC_RIGHTS_USER_ALL_ACCESS};
98 static const struct generic_mapping grp_generic_mapping = {
99 GENERIC_RIGHTS_GROUP_READ,
100 GENERIC_RIGHTS_GROUP_WRITE,
101 GENERIC_RIGHTS_GROUP_EXECUTE,
102 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
103 static const struct generic_mapping ali_generic_mapping = {
104 GENERIC_RIGHTS_ALIAS_READ,
105 GENERIC_RIGHTS_ALIAS_WRITE,
106 GENERIC_RIGHTS_ALIAS_EXECUTE,
107 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
109 /*******************************************************************
110 *******************************************************************/
112 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
113 const struct generic_mapping *map,
114 DOM_SID *sid, uint32 sid_access )
116 DOM_SID domadmin_sid;
117 SEC_ACE ace[5]; /* at most 5 entries */
122 /* basic access for Everyone */
124 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
125 map->generic_execute | map->generic_read, 0);
127 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
129 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
130 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
131 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
132 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
134 /* Add Full Access for Domain Admins if we are a DC */
137 sid_copy( &domadmin_sid, get_global_sam_sid() );
138 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
139 init_sec_ace(&ace[i++], &domadmin_sid,
140 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
143 /* if we have a sid, give it some special access */
146 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
149 /* create the security descriptor */
151 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
152 return NT_STATUS_NO_MEMORY;
154 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
155 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
156 psa, sd_size)) == NULL)
157 return NT_STATUS_NO_MEMORY;
162 /*******************************************************************
163 Checks if access to an object should be granted, and returns that
164 level of access for further checks.
165 ********************************************************************/
167 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
168 SE_PRIV *rights, uint32 rights_mask,
169 uint32 des_access, uint32 *acc_granted,
172 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
173 uint32 saved_mask = 0;
175 /* check privileges; certain SAM access bits should be overridden
176 by privileges (mostly having to do with creating/modifying/deleting
179 if ( rights && user_has_any_privilege( token, rights ) ) {
181 saved_mask = (des_access & rights_mask);
182 des_access &= ~saved_mask;
184 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
189 /* check the security descriptor first */
191 status = se_access_check(psd, token, des_access, acc_granted);
192 if (NT_STATUS_IS_OK(status)) {
196 /* give root a free pass */
198 if ( geteuid() == sec_initial_uid() ) {
200 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
201 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
203 *acc_granted = des_access;
205 status = NT_STATUS_OK;
211 /* add in any bits saved during the privilege check (only
212 matters is status is ok) */
214 *acc_granted |= rights_mask;
216 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
217 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
218 des_access, *acc_granted));
223 /*******************************************************************
224 Checks if access to a function can be granted
225 ********************************************************************/
227 static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_required, const char *debug)
229 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
230 debug, acc_granted, acc_required));
232 /* check the security descriptor first */
234 if ( (acc_granted&acc_required) == acc_required )
237 /* give root a free pass */
239 if (geteuid() == sec_initial_uid()) {
241 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
242 debug, acc_granted, acc_required));
243 DEBUGADD(4,("but overwritten by euid == 0\n"));
248 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
249 debug, acc_granted, acc_required));
251 return NT_STATUS_ACCESS_DENIED;
254 /*******************************************************************
255 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
256 ********************************************************************/
258 static void map_max_allowed_access(const NT_USER_TOKEN *token,
259 uint32_t *pacc_requested)
261 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
264 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
266 /* At least try for generic read. */
267 *pacc_requested = GENERIC_READ_ACCESS;
269 /* root gets anything. */
270 if (geteuid() == sec_initial_uid()) {
271 *pacc_requested |= GENERIC_ALL_ACCESS;
275 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
277 if (is_sid_in_token(token, &global_sid_Builtin_Administrators) ||
278 is_sid_in_token(token, &global_sid_Builtin_Account_Operators)) {
279 *pacc_requested |= GENERIC_ALL_ACCESS;
283 /* Full access for DOMAIN\Domain Admins. */
285 DOM_SID domadmin_sid;
286 sid_copy( &domadmin_sid, get_global_sam_sid() );
287 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
288 if (is_sid_in_token(token, &domadmin_sid)) {
289 *pacc_requested |= GENERIC_ALL_ACCESS;
293 /* TODO ! Check privileges. */
296 /*******************************************************************
297 Fetch or create a dispinfo struct.
298 ********************************************************************/
300 static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid)
303 * We do a static cache for DISP_INFO's here. Explanation can be found
304 * in Jeremy's checkin message to r11793:
306 * Fix the SAMR cache so it works across completely insane
307 * client behaviour (ie.:
308 * open pipe/open SAMR handle/enumerate 0 - 1024
309 * close SAMR handle, close pipe.
310 * open pipe/open SAMR handle/enumerate 1024 - 2048...
311 * close SAMR handle, close pipe.
312 * And on ad-nausium. Amazing.... probably object-oriented
313 * client side programming in action yet again.
314 * This change should *massively* improve performance when
315 * enumerating users from an LDAP database.
318 * "Our" and the builtin domain are the only ones where we ever
319 * enumerate stuff, so just cache 2 entries.
322 static struct disp_info builtin_dispinfo;
323 static struct disp_info domain_dispinfo;
325 /* There are two cases to consider here:
326 1) The SID is a domain SID and we look for an equality match, or
327 2) This is an account SID and so we return the DISP_INFO* for our
334 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
336 * Necessary only once, but it does not really hurt.
338 sid_copy(&builtin_dispinfo.sid, &global_sid_Builtin);
340 return &builtin_dispinfo;
343 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
345 * Necessary only once, but it does not really hurt.
347 sid_copy(&domain_dispinfo.sid, get_global_sam_sid());
349 return &domain_dispinfo;
355 /*******************************************************************
356 Create a samr_info struct.
357 ********************************************************************/
359 static int samr_info_destructor(struct samr_info *info);
361 static struct samr_info *get_samr_info_by_sid(TALLOC_CTX *mem_ctx,
364 struct samr_info *info;
368 sid_to_fstring(sid_str, psid);
370 fstrcpy(sid_str,"(NULL)");
373 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL) {
376 talloc_set_destructor(info, samr_info_destructor);
378 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
380 sid_copy( &info->sid, psid);
381 info->builtin_domain = sid_check_is_builtin(psid);
383 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
384 info->builtin_domain = False;
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 static int samr_info_destructor(struct samr_info *info)
438 /* Only free the dispinfo cache if no one bothered to set up
441 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
442 free_samr_cache(info->disp_info);
447 /*******************************************************************
448 Idle event handler. Throw away the disp info cache.
449 ********************************************************************/
451 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
452 struct timed_event *te,
456 DISP_INFO *disp_info = (DISP_INFO *)private_data;
458 TALLOC_FREE(disp_info->cache_timeout_event);
460 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
462 free_samr_cache(disp_info);
465 /*******************************************************************
466 Setup cache removal idle event handler.
467 ********************************************************************/
469 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
471 /* Remove any pending timeout and update. */
473 TALLOC_FREE(disp_info->cache_timeout_event);
475 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
476 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
477 (unsigned int)secs_fromnow ));
479 disp_info->cache_timeout_event = event_add_timed(
480 smbd_event_context(), NULL,
481 timeval_current_ofs(secs_fromnow, 0),
482 disp_info_cache_idle_timeout_handler, (void *)disp_info);
485 /*******************************************************************
486 Force flush any cache. We do this on any samr_set_xxx call.
487 We must also remove the timeout handler.
488 ********************************************************************/
490 static void force_flush_samr_cache(DISP_INFO *disp_info)
492 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
496 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
497 TALLOC_FREE(disp_info->cache_timeout_event);
498 free_samr_cache(disp_info);
501 /*******************************************************************
502 Ensure password info is never given out. Paranioa... JRA.
503 ********************************************************************/
505 static void samr_clear_sam_passwd(struct samu *sam_pass)
511 /* These now zero out the old password */
513 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
514 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
517 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
519 struct samr_displayentry *entry;
521 if (info->builtin_domain) {
522 /* No users in builtin. */
526 if (info->users == NULL) {
527 info->users = pdb_search_users(acct_flags);
528 if (info->users == NULL) {
532 /* Fetch the last possible entry, thus trigger an enumeration */
533 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
535 /* Ensure we cache this enumeration. */
536 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
538 return info->users->num_entries;
541 static uint32 count_sam_groups(struct disp_info *info)
543 struct samr_displayentry *entry;
545 if (info->builtin_domain) {
546 /* No groups in builtin. */
550 if (info->groups == NULL) {
551 info->groups = pdb_search_groups();
552 if (info->groups == NULL) {
556 /* Fetch the last possible entry, thus trigger an enumeration */
557 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
559 /* Ensure we cache this enumeration. */
560 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
562 return info->groups->num_entries;
565 static uint32 count_sam_aliases(struct disp_info *info)
567 struct samr_displayentry *entry;
569 if (info->aliases == NULL) {
570 info->aliases = pdb_search_aliases(&info->sid);
571 if (info->aliases == NULL) {
575 /* Fetch the last possible entry, thus trigger an enumeration */
576 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
578 /* Ensure we cache this enumeration. */
579 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
581 return info->aliases->num_entries;
584 /*******************************************************************
586 ********************************************************************/
588 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
590 if (!close_policy_hnd(p, r->in.handle)) {
591 return NT_STATUS_INVALID_HANDLE;
594 ZERO_STRUCTP(r->out.handle);
599 /*******************************************************************
601 ********************************************************************/
603 NTSTATUS _samr_OpenDomain(pipes_struct *p,
604 struct samr_OpenDomain *r)
606 struct samr_info *info;
607 SEC_DESC *psd = NULL;
609 uint32 des_access = r->in.access_mask;
614 /* find the connection policy handle. */
616 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
617 return NT_STATUS_INVALID_HANDLE;
619 status = access_check_samr_function(info->acc_granted,
620 SAMR_ACCESS_OPEN_DOMAIN,
621 "_samr_OpenDomain" );
623 if ( !NT_STATUS_IS_OK(status) )
626 /*check if access can be granted as requested by client. */
627 map_max_allowed_access(p->server_info->ptok, &des_access);
629 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
630 se_map_generic( &des_access, &dom_generic_mapping );
632 se_priv_copy( &se_rights, &se_machine_account );
633 se_priv_add( &se_rights, &se_add_users );
635 status = access_check_samr_object( psd, p->server_info->ptok,
636 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
637 &acc_granted, "_samr_OpenDomain" );
639 if ( !NT_STATUS_IS_OK(status) )
642 if (!sid_check_is_domain(r->in.sid) &&
643 !sid_check_is_builtin(r->in.sid)) {
644 return NT_STATUS_NO_SUCH_DOMAIN;
647 /* associate the domain SID with the (unique) handle. */
648 if ((info = get_samr_info_by_sid(p->mem_ctx, r->in.sid))==NULL)
649 return NT_STATUS_NO_MEMORY;
650 info->acc_granted = acc_granted;
652 /* get a (unique) handle. open a policy on it. */
653 if (!create_policy_hnd(p, r->out.domain_handle, info))
654 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
656 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
661 /*******************************************************************
663 ********************************************************************/
665 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
666 struct samr_GetUserPwInfo *r)
668 struct samr_info *info = NULL;
669 enum lsa_SidType sid_type;
670 uint32_t min_password_length = 0;
671 uint32_t password_properties = 0;
675 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
677 /* find the policy handle. open a policy on it. */
678 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info)) {
679 return NT_STATUS_INVALID_HANDLE;
682 status = access_check_samr_function(info->acc_granted,
683 SAMR_USER_ACCESS_GET_ATTRIBUTES,
684 "_samr_GetUserPwInfo" );
685 if (!NT_STATUS_IS_OK(status)) {
689 if (!sid_check_is_in_our_domain(&info->sid)) {
690 return NT_STATUS_OBJECT_TYPE_MISMATCH;
694 ret = lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, &sid_type);
697 return NT_STATUS_NO_SUCH_USER;
703 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
704 &min_password_length);
705 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
706 &password_properties);
709 if (lp_check_password_script() && *lp_check_password_script()) {
710 password_properties |= DOMAIN_PASSWORD_COMPLEX;
718 r->out.info->min_password_length = min_password_length;
719 r->out.info->password_properties = password_properties;
721 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
726 /*******************************************************************
727 ********************************************************************/
729 static bool get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol,
730 DOM_SID *sid, uint32 *acc_granted,
731 DISP_INFO **ppdisp_info)
733 struct samr_info *info = NULL;
735 /* find the policy handle. open a policy on it. */
736 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
743 *acc_granted = info->acc_granted;
745 *ppdisp_info = info->disp_info;
751 /*******************************************************************
753 ********************************************************************/
755 NTSTATUS _samr_SetSecurity(pipes_struct *p,
756 struct samr_SetSecurity *r)
759 uint32 acc_granted, i;
762 struct samu *sampass=NULL;
765 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
766 return NT_STATUS_INVALID_HANDLE;
768 if (!(sampass = samu_new( p->mem_ctx))) {
769 DEBUG(0,("No memory!\n"));
770 return NT_STATUS_NO_MEMORY;
773 /* get the user record */
775 ret = pdb_getsampwsid(sampass, &pol_sid);
779 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
780 TALLOC_FREE(sampass);
781 return NT_STATUS_INVALID_HANDLE;
784 dacl = r->in.sdbuf->sd->dacl;
785 for (i=0; i < dacl->num_aces; i++) {
786 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
787 ret = pdb_set_pass_can_change(sampass,
788 (dacl->aces[i].access_mask &
789 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
796 TALLOC_FREE(sampass);
797 return NT_STATUS_ACCESS_DENIED;
800 status = access_check_samr_function(acc_granted,
801 SAMR_USER_ACCESS_SET_ATTRIBUTES,
802 "_samr_SetSecurity");
803 if (NT_STATUS_IS_OK(status)) {
805 status = pdb_update_sam_account(sampass);
809 TALLOC_FREE(sampass);
814 /*******************************************************************
815 build correct perms based on policies and password times for _samr_query_sec_obj
816 *******************************************************************/
817 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
819 struct samu *sampass=NULL;
822 if ( !(sampass = samu_new( mem_ctx )) ) {
823 DEBUG(0,("No memory!\n"));
828 ret = pdb_getsampwsid(sampass, user_sid);
832 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
833 TALLOC_FREE(sampass);
837 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
839 if (pdb_get_pass_can_change(sampass)) {
840 TALLOC_FREE(sampass);
843 TALLOC_FREE(sampass);
848 /*******************************************************************
850 ********************************************************************/
852 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
853 struct samr_QuerySecurity *r)
857 SEC_DESC * psd = NULL;
862 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
863 return NT_STATUS_INVALID_HANDLE;
865 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
866 sid_string_dbg(&pol_sid)));
868 status = access_check_samr_function(acc_granted,
869 STD_RIGHT_READ_CONTROL_ACCESS,
870 "_samr_QuerySecurity");
871 if (!NT_STATUS_IS_OK(status)) {
875 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
877 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
878 if (pol_sid.sid_rev_num == 0) {
879 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
880 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
881 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
882 /* check if it is our domain SID */
883 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
884 "with SID: %s\n", sid_string_dbg(&pol_sid)));
885 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
886 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
887 /* check if it is the Builtin Domain */
888 /* TODO: Builtin probably needs a different SD with restricted write access*/
889 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
890 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
891 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
892 } else if (sid_check_is_in_our_domain(&pol_sid) ||
893 sid_check_is_in_builtin(&pol_sid)) {
894 /* TODO: different SDs have to be generated for aliases groups and users.
895 Currently all three get a default user SD */
896 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
897 "with SID: %s\n", sid_string_dbg(&pol_sid)));
898 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
899 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
900 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
902 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
903 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
906 return NT_STATUS_OBJECT_TYPE_MISMATCH;
909 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
910 return NT_STATUS_NO_MEMORY;
915 /*******************************************************************
916 makes a SAM_ENTRY / UNISTR2* structure from a user list.
917 ********************************************************************/
919 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
920 struct samr_SamEntry **sam_pp,
921 uint32_t num_entries,
923 struct samr_displayentry *entries)
926 struct samr_SamEntry *sam;
930 if (num_entries == 0) {
934 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
936 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
937 return NT_STATUS_NO_MEMORY;
940 for (i = 0; i < num_entries; i++) {
943 * usrmgr expects a non-NULL terminated string with
944 * trust relationships
946 if (entries[i].acct_flags & ACB_DOMTRUST) {
947 init_unistr2(&uni_temp_name, entries[i].account_name,
950 init_unistr2(&uni_temp_name, entries[i].account_name,
954 init_lsa_String(&sam[i].name, entries[i].account_name);
955 sam[i].idx = entries[i].rid;
963 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
965 /*******************************************************************
966 _samr_EnumDomainUsers
967 ********************************************************************/
969 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
970 struct samr_EnumDomainUsers *r)
973 struct samr_info *info = NULL;
975 uint32 enum_context = *r->in.resume_handle;
976 enum remote_arch_types ra_type = get_remote_arch();
977 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
978 uint32 max_entries = max_sam_entries;
979 struct samr_displayentry *entries = NULL;
980 struct samr_SamArray *samr_array = NULL;
981 struct samr_SamEntry *samr_entries = NULL;
983 /* find the policy handle. open a policy on it. */
984 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
985 return NT_STATUS_INVALID_HANDLE;
987 status = access_check_samr_function(info->acc_granted,
988 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
989 "_samr_EnumDomainUsers");
990 if (!NT_STATUS_IS_OK(status)) {
994 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
996 if (info->builtin_domain) {
997 /* No users in builtin. */
998 *r->out.resume_handle = *r->in.resume_handle;
999 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
1003 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1005 return NT_STATUS_NO_MEMORY;
1007 *r->out.sam = samr_array;
1013 if ((info->disp_info->enum_users != NULL) &&
1014 (info->disp_info->enum_acb_mask != r->in.acct_flags)) {
1015 pdb_search_destroy(info->disp_info->enum_users);
1016 info->disp_info->enum_users = NULL;
1019 if (info->disp_info->enum_users == NULL) {
1020 info->disp_info->enum_users = pdb_search_users(r->in.acct_flags);
1021 info->disp_info->enum_acb_mask = r->in.acct_flags;
1024 if (info->disp_info->enum_users == NULL) {
1025 /* END AS ROOT !!!! */
1027 return NT_STATUS_ACCESS_DENIED;
1030 num_account = pdb_search_entries(info->disp_info->enum_users,
1031 enum_context, max_entries,
1034 /* END AS ROOT !!!! */
1038 if (num_account == 0) {
1039 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1040 "total entries\n"));
1041 *r->out.resume_handle = *r->in.resume_handle;
1042 return NT_STATUS_OK;
1045 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
1046 num_account, enum_context,
1048 if (!NT_STATUS_IS_OK(status)) {
1052 if (max_entries <= num_account) {
1053 status = STATUS_MORE_ENTRIES;
1055 status = NT_STATUS_OK;
1058 /* Ensure we cache this enumeration. */
1059 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1061 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
1063 samr_array->count = num_account;
1064 samr_array->entries = samr_entries;
1066 *r->out.resume_handle = *r->in.resume_handle + num_account;
1067 *r->out.num_entries = num_account;
1069 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1074 /*******************************************************************
1075 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1076 ********************************************************************/
1078 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1079 struct samr_SamEntry **sam_pp,
1080 uint32_t num_sam_entries,
1081 struct samr_displayentry *entries)
1083 struct samr_SamEntry *sam;
1088 if (num_sam_entries == 0) {
1092 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1097 for (i = 0; i < num_sam_entries; i++) {
1099 * JRA. I think this should include the null. TNG does not.
1101 init_lsa_String(&sam[i].name, entries[i].account_name);
1102 sam[i].idx = entries[i].rid;
1108 /*******************************************************************
1109 _samr_EnumDomainGroups
1110 ********************************************************************/
1112 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1113 struct samr_EnumDomainGroups *r)
1116 struct samr_info *info = NULL;
1117 struct samr_displayentry *groups;
1119 struct samr_SamArray *samr_array = NULL;
1120 struct samr_SamEntry *samr_entries = NULL;
1122 /* find the policy handle. open a policy on it. */
1123 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1124 return NT_STATUS_INVALID_HANDLE;
1126 status = access_check_samr_function(info->acc_granted,
1127 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1128 "_samr_EnumDomainGroups");
1129 if (!NT_STATUS_IS_OK(status)) {
1133 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1135 if (info->builtin_domain) {
1136 /* No groups in builtin. */
1137 *r->out.resume_handle = *r->in.resume_handle;
1138 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1142 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1144 return NT_STATUS_NO_MEMORY;
1147 /* the domain group array is being allocated in the function below */
1151 if (info->disp_info->groups == NULL) {
1152 info->disp_info->groups = pdb_search_groups();
1154 if (info->disp_info->groups == NULL) {
1156 return NT_STATUS_ACCESS_DENIED;
1160 num_groups = pdb_search_entries(info->disp_info->groups,
1161 *r->in.resume_handle,
1162 MAX_SAM_ENTRIES, &groups);
1165 /* Ensure we cache this enumeration. */
1166 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1168 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1169 num_groups, groups);
1171 samr_array->count = num_groups;
1172 samr_array->entries = samr_entries;
1174 *r->out.sam = samr_array;
1175 *r->out.num_entries = num_groups;
1176 /* this was missing, IMHO:
1177 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1180 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1185 /*******************************************************************
1186 _samr_EnumDomainAliases
1187 ********************************************************************/
1189 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1190 struct samr_EnumDomainAliases *r)
1193 struct samr_info *info;
1194 struct samr_displayentry *aliases;
1195 uint32 num_aliases = 0;
1196 struct samr_SamArray *samr_array = NULL;
1197 struct samr_SamEntry *samr_entries = NULL;
1199 /* find the policy handle. open a policy on it. */
1200 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1201 return NT_STATUS_INVALID_HANDLE;
1203 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1204 sid_string_dbg(&info->sid)));
1206 status = access_check_samr_function(info->acc_granted,
1207 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1208 "_samr_EnumDomainAliases");
1209 if (!NT_STATUS_IS_OK(status)) {
1213 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1215 return NT_STATUS_NO_MEMORY;
1220 if (info->disp_info->aliases == NULL) {
1221 info->disp_info->aliases = pdb_search_aliases(&info->sid);
1222 if (info->disp_info->aliases == NULL) {
1224 return NT_STATUS_ACCESS_DENIED;
1228 num_aliases = pdb_search_entries(info->disp_info->aliases,
1229 *r->in.resume_handle,
1230 MAX_SAM_ENTRIES, &aliases);
1233 /* Ensure we cache this enumeration. */
1234 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1236 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1237 num_aliases, aliases);
1239 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1241 samr_array->count = num_aliases;
1242 samr_array->entries = samr_entries;
1244 *r->out.sam = samr_array;
1245 *r->out.num_entries = num_aliases;
1246 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1251 /*******************************************************************
1252 inits a samr_DispInfoGeneral structure.
1253 ********************************************************************/
1255 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1256 struct samr_DispInfoGeneral *r,
1257 uint32_t num_entries,
1259 struct samr_displayentry *entries)
1263 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1265 if (num_entries == 0) {
1266 return NT_STATUS_OK;
1269 r->count = num_entries;
1271 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1273 return NT_STATUS_NO_MEMORY;
1276 for (i = 0; i < num_entries ; i++) {
1278 init_lsa_String(&r->entries[i].account_name,
1279 entries[i].account_name);
1281 init_lsa_String(&r->entries[i].description,
1282 entries[i].description);
1284 init_lsa_String(&r->entries[i].full_name,
1285 entries[i].fullname);
1287 r->entries[i].rid = entries[i].rid;
1288 r->entries[i].acct_flags = entries[i].acct_flags;
1289 r->entries[i].idx = start_idx+i+1;
1292 return NT_STATUS_OK;
1295 /*******************************************************************
1296 inits a samr_DispInfoFull structure.
1297 ********************************************************************/
1299 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1300 struct samr_DispInfoFull *r,
1301 uint32_t num_entries,
1303 struct samr_displayentry *entries)
1307 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1309 if (num_entries == 0) {
1310 return NT_STATUS_OK;
1313 r->count = num_entries;
1315 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1317 return NT_STATUS_NO_MEMORY;
1320 for (i = 0; i < num_entries ; i++) {
1322 init_lsa_String(&r->entries[i].account_name,
1323 entries[i].account_name);
1325 init_lsa_String(&r->entries[i].description,
1326 entries[i].description);
1328 r->entries[i].rid = entries[i].rid;
1329 r->entries[i].acct_flags = entries[i].acct_flags;
1330 r->entries[i].idx = start_idx+i+1;
1333 return NT_STATUS_OK;
1336 /*******************************************************************
1337 inits a samr_DispInfoFullGroups structure.
1338 ********************************************************************/
1340 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1341 struct samr_DispInfoFullGroups *r,
1342 uint32_t num_entries,
1344 struct samr_displayentry *entries)
1348 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1350 if (num_entries == 0) {
1351 return NT_STATUS_OK;
1354 r->count = num_entries;
1356 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1358 return NT_STATUS_NO_MEMORY;
1361 for (i = 0; i < num_entries ; i++) {
1363 init_lsa_String(&r->entries[i].account_name,
1364 entries[i].account_name);
1366 init_lsa_String(&r->entries[i].description,
1367 entries[i].description);
1369 r->entries[i].rid = entries[i].rid;
1370 r->entries[i].acct_flags = entries[i].acct_flags;
1371 r->entries[i].idx = start_idx+i+1;
1374 return NT_STATUS_OK;
1377 /*******************************************************************
1378 inits a samr_DispInfoAscii structure.
1379 ********************************************************************/
1381 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1382 struct samr_DispInfoAscii *r,
1383 uint32_t num_entries,
1385 struct samr_displayentry *entries)
1389 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1391 if (num_entries == 0) {
1392 return NT_STATUS_OK;
1395 r->count = num_entries;
1397 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1399 return NT_STATUS_NO_MEMORY;
1402 for (i = 0; i < num_entries ; i++) {
1404 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1405 entries[i].account_name);
1407 r->entries[i].idx = start_idx+i+1;
1410 return NT_STATUS_OK;
1413 /*******************************************************************
1414 inits a samr_DispInfoAscii structure.
1415 ********************************************************************/
1417 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1418 struct samr_DispInfoAscii *r,
1419 uint32_t num_entries,
1421 struct samr_displayentry *entries)
1425 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1427 if (num_entries == 0) {
1428 return NT_STATUS_OK;
1431 r->count = num_entries;
1433 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1435 return NT_STATUS_NO_MEMORY;
1438 for (i = 0; i < num_entries ; i++) {
1440 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1441 entries[i].account_name);
1443 r->entries[i].idx = start_idx+i+1;
1446 return NT_STATUS_OK;
1449 /*******************************************************************
1450 _samr_QueryDisplayInfo
1451 ********************************************************************/
1453 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1454 struct samr_QueryDisplayInfo *r)
1457 struct samr_info *info = NULL;
1458 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1460 uint32 max_entries = r->in.max_entries;
1461 uint32 enum_context = r->in.start_idx;
1462 uint32 max_size = r->in.buf_size;
1464 union samr_DispInfo *disp_info = r->out.info;
1466 uint32 temp_size=0, total_data_size=0;
1467 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1468 uint32 num_account = 0;
1469 enum remote_arch_types ra_type = get_remote_arch();
1470 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1471 struct samr_displayentry *entries = NULL;
1473 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1475 /* find the policy handle. open a policy on it. */
1476 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1477 return NT_STATUS_INVALID_HANDLE;
1479 if (info->builtin_domain) {
1480 DEBUG(5,("_samr_QueryDisplayInfo: Nothing in BUILTIN\n"));
1481 return NT_STATUS_OK;
1484 status = access_check_samr_function(info->acc_granted,
1485 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1486 "_samr_QueryDisplayInfo");
1487 if (!NT_STATUS_IS_OK(status)) {
1492 * calculate how many entries we will return.
1494 * - the number of entries the client asked
1495 * - our limit on that
1496 * - the starting point (enumeration context)
1497 * - the buffer size the client will accept
1501 * We are a lot more like W2K. Instead of reading the SAM
1502 * each time to find the records we need to send back,
1503 * we read it once and link that copy to the sam handle.
1504 * For large user list (over the MAX_SAM_ENTRIES)
1505 * it's a definitive win.
1506 * second point to notice: between enumerations
1507 * our sam is now the same as it's a snapshoot.
1508 * third point: got rid of the static SAM_USER_21 struct
1509 * no more intermediate.
1510 * con: it uses much more memory, as a full copy is stored
1513 * If you want to change it, think twice and think
1514 * of the second point , that's really important.
1519 if ((r->in.level < 1) || (r->in.level > 5)) {
1520 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1521 (unsigned int)r->in.level ));
1522 return NT_STATUS_INVALID_INFO_CLASS;
1525 /* first limit the number of entries we will return */
1526 if(max_entries > max_sam_entries) {
1527 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1528 "entries, limiting to %d\n", max_entries,
1530 max_entries = max_sam_entries;
1533 /* calculate the size and limit on the number of entries we will
1536 temp_size=max_entries*struct_size;
1538 if (temp_size>max_size) {
1539 max_entries=MIN((max_size/struct_size),max_entries);;
1540 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1541 "only %d entries\n", max_entries));
1546 /* THe following done as ROOT. Don't return without unbecome_root(). */
1548 switch (r->in.level) {
1551 if (info->disp_info->users == NULL) {
1552 info->disp_info->users = pdb_search_users(ACB_NORMAL);
1553 if (info->disp_info->users == NULL) {
1555 return NT_STATUS_ACCESS_DENIED;
1557 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1558 (unsigned int)enum_context ));
1560 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1561 (unsigned int)enum_context ));
1564 num_account = pdb_search_entries(info->disp_info->users,
1565 enum_context, max_entries,
1569 if (info->disp_info->machines == NULL) {
1570 info->disp_info->machines =
1571 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
1572 if (info->disp_info->machines == NULL) {
1574 return NT_STATUS_ACCESS_DENIED;
1576 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1577 (unsigned int)enum_context ));
1579 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1580 (unsigned int)enum_context ));
1583 num_account = pdb_search_entries(info->disp_info->machines,
1584 enum_context, max_entries,
1589 if (info->disp_info->groups == NULL) {
1590 info->disp_info->groups = pdb_search_groups();
1591 if (info->disp_info->groups == NULL) {
1593 return NT_STATUS_ACCESS_DENIED;
1595 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1596 (unsigned int)enum_context ));
1598 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1599 (unsigned int)enum_context ));
1602 num_account = pdb_search_entries(info->disp_info->groups,
1603 enum_context, max_entries,
1608 smb_panic("info class changed");
1614 /* Now create reply structure */
1615 switch (r->in.level) {
1617 disp_ret = init_samr_dispinfo_1(p->mem_ctx, &disp_info->info1,
1618 num_account, enum_context,
1622 disp_ret = init_samr_dispinfo_2(p->mem_ctx, &disp_info->info2,
1623 num_account, enum_context,
1627 disp_ret = init_samr_dispinfo_3(p->mem_ctx, &disp_info->info3,
1628 num_account, enum_context,
1632 disp_ret = init_samr_dispinfo_4(p->mem_ctx, &disp_info->info4,
1633 num_account, enum_context,
1637 disp_ret = init_samr_dispinfo_5(p->mem_ctx, &disp_info->info5,
1638 num_account, enum_context,
1642 smb_panic("info class changed");
1646 if (!NT_STATUS_IS_OK(disp_ret))
1649 /* calculate the total size */
1650 total_data_size=num_account*struct_size;
1652 if (max_entries <= num_account) {
1653 status = STATUS_MORE_ENTRIES;
1655 status = NT_STATUS_OK;
1658 /* Ensure we cache this enumeration. */
1659 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1661 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__));
1663 *r->out.total_size = total_data_size;
1664 *r->out.returned_size = temp_size;
1669 /****************************************************************
1670 _samr_QueryDisplayInfo2
1671 ****************************************************************/
1673 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
1674 struct samr_QueryDisplayInfo2 *r)
1676 struct samr_QueryDisplayInfo q;
1678 q.in.domain_handle = r->in.domain_handle;
1679 q.in.level = r->in.level;
1680 q.in.start_idx = r->in.start_idx;
1681 q.in.max_entries = r->in.max_entries;
1682 q.in.buf_size = r->in.buf_size;
1684 q.out.total_size = r->out.total_size;
1685 q.out.returned_size = r->out.returned_size;
1686 q.out.info = r->out.info;
1688 return _samr_QueryDisplayInfo(p, &q);
1691 /****************************************************************
1692 _samr_QueryDisplayInfo3
1693 ****************************************************************/
1695 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
1696 struct samr_QueryDisplayInfo3 *r)
1698 struct samr_QueryDisplayInfo q;
1700 q.in.domain_handle = r->in.domain_handle;
1701 q.in.level = r->in.level;
1702 q.in.start_idx = r->in.start_idx;
1703 q.in.max_entries = r->in.max_entries;
1704 q.in.buf_size = r->in.buf_size;
1706 q.out.total_size = r->out.total_size;
1707 q.out.returned_size = r->out.returned_size;
1708 q.out.info = r->out.info;
1710 return _samr_QueryDisplayInfo(p, &q);
1713 /*******************************************************************
1714 _samr_QueryAliasInfo
1715 ********************************************************************/
1717 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
1718 struct samr_QueryAliasInfo *r)
1721 struct acct_info info;
1724 union samr_AliasInfo *alias_info = NULL;
1725 const char *alias_name = NULL;
1726 const char *alias_description = NULL;
1728 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1730 alias_info = TALLOC_ZERO_P(p->mem_ctx, union samr_AliasInfo);
1732 return NT_STATUS_NO_MEMORY;
1735 /* find the policy handle. open a policy on it. */
1736 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &sid, &acc_granted, NULL))
1737 return NT_STATUS_INVALID_HANDLE;
1739 status = access_check_samr_function(acc_granted,
1740 SAMR_ALIAS_ACCESS_LOOKUP_INFO,
1741 "_samr_QueryAliasInfo");
1742 if (!NT_STATUS_IS_OK(status)) {
1747 status = pdb_get_aliasinfo(&sid, &info);
1750 if ( !NT_STATUS_IS_OK(status))
1753 /* FIXME: info contains fstrings */
1754 alias_name = talloc_strdup(r, info.acct_name);
1755 alias_description = talloc_strdup(r, info.acct_desc);
1757 switch (r->in.level) {
1759 alias_info->all.name.string = alias_name;
1760 alias_info->all.num_members = 1; /* ??? */
1761 alias_info->all.description.string = alias_description;
1763 case ALIASINFODESCRIPTION:
1764 alias_info->description.string = alias_description;
1767 return NT_STATUS_INVALID_INFO_CLASS;
1770 *r->out.info = alias_info;
1772 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1774 return NT_STATUS_OK;
1777 /*******************************************************************
1779 ********************************************************************/
1781 NTSTATUS _samr_LookupNames(pipes_struct *p,
1782 struct samr_LookupNames *r)
1786 enum lsa_SidType *type;
1788 int num_rids = r->in.num_names;
1791 struct samr_Ids rids, types;
1792 uint32_t num_mapped = 0;
1794 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1796 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL)) {
1797 return NT_STATUS_OBJECT_TYPE_MISMATCH;
1800 status = access_check_samr_function(acc_granted,
1801 0, /* Don't know the acc_bits yet */
1802 "_samr_LookupNames");
1803 if (!NT_STATUS_IS_OK(status)) {
1807 if (num_rids > MAX_SAM_ENTRIES) {
1808 num_rids = MAX_SAM_ENTRIES;
1809 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1812 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1813 NT_STATUS_HAVE_NO_MEMORY(rid);
1815 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1816 NT_STATUS_HAVE_NO_MEMORY(type);
1818 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1819 sid_string_dbg(&pol_sid)));
1821 for (i = 0; i < num_rids; i++) {
1823 status = NT_STATUS_NONE_MAPPED;
1824 type[i] = SID_NAME_UNKNOWN;
1826 rid[i] = 0xffffffff;
1828 if (sid_check_is_builtin(&pol_sid)) {
1829 if (lookup_builtin_name(r->in.names[i].string,
1832 type[i] = SID_NAME_ALIAS;
1835 lookup_global_sam_name(r->in.names[i].string, 0,
1839 if (type[i] != SID_NAME_UNKNOWN) {
1844 if (num_mapped == num_rids) {
1845 status = NT_STATUS_OK;
1846 } else if (num_mapped == 0) {
1847 status = NT_STATUS_NONE_MAPPED;
1849 status = STATUS_SOME_UNMAPPED;
1852 rids.count = num_rids;
1855 types.count = num_rids;
1858 *r->out.rids = rids;
1859 *r->out.types = types;
1861 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1866 /*******************************************************************
1867 _samr_ChangePasswordUser2
1868 ********************************************************************/
1870 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1871 struct samr_ChangePasswordUser2 *r)
1877 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1879 fstrcpy(user_name, r->in.account->string);
1880 fstrcpy(wks, r->in.server->string);
1882 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1885 * Pass the user through the NT -> unix user mapping
1889 (void)map_username(user_name);
1892 * UNIX username case mangling not required, pass_oem_change
1893 * is case insensitive.
1896 status = pass_oem_change(user_name,
1897 r->in.lm_password->data,
1898 r->in.lm_verifier->hash,
1899 r->in.nt_password->data,
1900 r->in.nt_verifier->hash,
1903 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1908 /*******************************************************************
1909 _samr_ChangePasswordUser3
1910 ********************************************************************/
1912 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
1913 struct samr_ChangePasswordUser3 *r)
1917 const char *wks = NULL;
1918 uint32 reject_reason;
1919 struct samr_DomInfo1 *dominfo = NULL;
1920 struct samr_ChangeReject *reject = NULL;
1922 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1924 fstrcpy(user_name, r->in.account->string);
1925 if (r->in.server && r->in.server->string) {
1926 wks = r->in.server->string;
1929 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
1932 * Pass the user through the NT -> unix user mapping
1936 (void)map_username(user_name);
1939 * UNIX username case mangling not required, pass_oem_change
1940 * is case insensitive.
1943 status = pass_oem_change(user_name,
1944 r->in.lm_password->data,
1945 r->in.lm_verifier->hash,
1946 r->in.nt_password->data,
1947 r->in.nt_verifier->hash,
1950 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
1951 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1953 time_t u_expire, u_min_age;
1954 uint32 account_policy_temp;
1956 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
1958 return NT_STATUS_NO_MEMORY;
1961 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
1963 return NT_STATUS_NO_MEMORY;
1970 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
1971 (uint32_t *)&dominfo->min_password_length);
1973 pdb_get_account_policy(AP_PASSWORD_HISTORY,
1974 (uint32_t *)&dominfo->password_history_length);
1976 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
1977 &dominfo->password_properties);
1979 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1980 u_expire = account_policy_temp;
1982 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1983 u_min_age = account_policy_temp;
1989 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
1990 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
1992 if (lp_check_password_script() && *lp_check_password_script()) {
1993 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
1996 reject->reason = reject_reason;
1998 *r->out.dominfo = dominfo;
1999 *r->out.reject = reject;
2002 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2007 /*******************************************************************
2008 makes a SAMR_R_LOOKUP_RIDS structure.
2009 ********************************************************************/
2011 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2013 struct lsa_String **lsa_name_array_p)
2015 struct lsa_String *lsa_name_array = NULL;
2018 *lsa_name_array_p = NULL;
2020 if (num_names != 0) {
2021 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2022 if (!lsa_name_array) {
2027 for (i = 0; i < num_names; i++) {
2028 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2029 init_lsa_String(&lsa_name_array[i], names[i]);
2032 *lsa_name_array_p = lsa_name_array;
2037 /*******************************************************************
2039 ********************************************************************/
2041 NTSTATUS _samr_LookupRids(pipes_struct *p,
2042 struct samr_LookupRids *r)
2046 enum lsa_SidType *attrs = NULL;
2047 uint32 *wire_attrs = NULL;
2049 int num_rids = (int)r->in.num_rids;
2052 struct lsa_Strings names_array;
2053 struct samr_Ids types_array;
2054 struct lsa_String *lsa_names = NULL;
2056 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2058 /* find the policy handle. open a policy on it. */
2059 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2060 return NT_STATUS_INVALID_HANDLE;
2062 status = access_check_samr_function(acc_granted,
2063 0, /* Don't know the acc_bits yet */
2064 "_samr_LookupRids");
2065 if (!NT_STATUS_IS_OK(status)) {
2069 if (num_rids > 1000) {
2070 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2071 "to samba4 idl this is not possible\n", num_rids));
2072 return NT_STATUS_UNSUCCESSFUL;
2076 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2077 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2078 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2080 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2081 return NT_STATUS_NO_MEMORY;
2088 become_root(); /* lookup_sid can require root privs */
2089 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2093 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2094 status = NT_STATUS_OK;
2097 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2099 return NT_STATUS_NO_MEMORY;
2102 /* Convert from enum lsa_SidType to uint32 for wire format. */
2103 for (i = 0; i < num_rids; i++) {
2104 wire_attrs[i] = (uint32)attrs[i];
2107 names_array.count = num_rids;
2108 names_array.names = lsa_names;
2110 types_array.count = num_rids;
2111 types_array.ids = wire_attrs;
2113 *r->out.names = names_array;
2114 *r->out.types = types_array;
2116 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2121 /*******************************************************************
2123 ********************************************************************/
2125 NTSTATUS _samr_OpenUser(pipes_struct *p,
2126 struct samr_OpenUser *r)
2128 struct samu *sampass=NULL;
2130 POLICY_HND domain_pol = *r->in.domain_handle;
2131 POLICY_HND *user_pol = r->out.user_handle;
2132 struct samr_info *info = NULL;
2133 SEC_DESC *psd = NULL;
2135 uint32 des_access = r->in.access_mask;
2141 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2143 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
2144 return NT_STATUS_INVALID_HANDLE;
2146 nt_status = access_check_samr_function(acc_granted,
2147 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2150 if ( !NT_STATUS_IS_OK(nt_status) )
2153 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2154 return NT_STATUS_NO_MEMORY;
2157 /* append the user's RID to it */
2159 if (!sid_append_rid(&sid, r->in.rid))
2160 return NT_STATUS_NO_SUCH_USER;
2162 /* check if access can be granted as requested by client. */
2164 map_max_allowed_access(p->server_info->ptok, &des_access);
2166 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2167 se_map_generic(&des_access, &usr_generic_mapping);
2169 se_priv_copy( &se_rights, &se_machine_account );
2170 se_priv_add( &se_rights, &se_add_users );
2172 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2173 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2174 &acc_granted, "_samr_OpenUser");
2176 if ( !NT_STATUS_IS_OK(nt_status) )
2180 ret=pdb_getsampwsid(sampass, &sid);
2183 /* check that the SID exists in our domain. */
2185 return NT_STATUS_NO_SUCH_USER;
2188 TALLOC_FREE(sampass);
2190 /* associate the user's SID and access bits with the new handle. */
2191 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
2192 return NT_STATUS_NO_MEMORY;
2193 info->acc_granted = acc_granted;
2195 /* get a (unique) handle. open a policy on it. */
2196 if (!create_policy_hnd(p, user_pol, info))
2197 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2199 return NT_STATUS_OK;
2202 /*************************************************************************
2203 *************************************************************************/
2205 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2207 struct lsa_BinaryString **_r)
2209 struct lsa_BinaryString *r;
2212 return NT_STATUS_INVALID_PARAMETER;
2215 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2217 return NT_STATUS_NO_MEMORY;
2220 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2222 return NT_STATUS_NO_MEMORY;
2224 memcpy(r->array, blob->data, blob->length);
2225 r->size = blob->length;
2226 r->length = blob->length;
2229 return NT_STATUS_NO_MEMORY;
2234 return NT_STATUS_OK;
2237 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2238 struct samr_UserInfo5 *r,
2240 DOM_SID *domain_sid)
2242 const DOM_SID *sid_user, *sid_group;
2243 uint32_t rid, primary_gid;
2245 sid_user = pdb_get_user_sid(pw);
2247 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2248 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2249 "the domain sid %s. Failing operation.\n",
2250 pdb_get_username(pw), sid_string_dbg(sid_user),
2251 sid_string_dbg(domain_sid)));
2252 return NT_STATUS_UNSUCCESSFUL;
2256 sid_group = pdb_get_group_sid(pw);
2259 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2260 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2261 "which conflicts with the domain sid %s. Failing operation.\n",
2262 pdb_get_username(pw), sid_string_dbg(sid_group),
2263 sid_string_dbg(domain_sid)));
2264 return NT_STATUS_UNSUCCESSFUL;
2267 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2268 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2269 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2270 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2272 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2273 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2274 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2275 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2276 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2277 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2278 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2279 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2281 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2283 r->primary_gid = primary_gid;
2284 r->acct_flags = pdb_get_acct_ctrl(pw);
2285 r->bad_password_count = pdb_get_bad_password_count(pw);
2286 r->logon_count = pdb_get_logon_count(pw);
2288 return NT_STATUS_OK;
2291 /*************************************************************************
2292 get_user_info_7. Safe. Only gives out account_name.
2293 *************************************************************************/
2295 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2296 struct samr_UserInfo7 *r,
2297 struct samu *smbpass)
2299 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2300 if (!r->account_name.string) {
2301 return NT_STATUS_NO_MEMORY;
2304 return NT_STATUS_OK;
2307 /*************************************************************************
2308 get_user_info_9. Only gives out primary group SID.
2309 *************************************************************************/
2311 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2312 struct samr_UserInfo9 *r,
2313 struct samu *smbpass)
2315 r->primary_gid = pdb_get_group_rid(smbpass);
2317 return NT_STATUS_OK;
2320 /*************************************************************************
2321 get_user_info_16. Safe. Only gives out acb bits.
2322 *************************************************************************/
2324 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2325 struct samr_UserInfo16 *r,
2326 struct samu *smbpass)
2328 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2330 return NT_STATUS_OK;
2333 /*************************************************************************
2334 get_user_info_18. OK - this is the killer as it gives out password info.
2335 Ensure that this is only allowed on an encrypted connection with a root
2337 *************************************************************************/
2339 static NTSTATUS get_user_info_18(pipes_struct *p,
2340 TALLOC_CTX *mem_ctx,
2341 struct samr_UserInfo18 *r,
2344 struct samu *smbpass=NULL;
2349 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2350 return NT_STATUS_ACCESS_DENIED;
2353 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2354 return NT_STATUS_ACCESS_DENIED;
2358 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2361 if ( !(smbpass = samu_new( mem_ctx )) ) {
2362 return NT_STATUS_NO_MEMORY;
2365 ret = pdb_getsampwsid(smbpass, user_sid);
2368 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2369 TALLOC_FREE(smbpass);
2370 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2373 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2375 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2376 TALLOC_FREE(smbpass);
2377 return NT_STATUS_ACCOUNT_DISABLED;
2380 r->lm_pwd_active = true;
2381 r->nt_pwd_active = true;
2382 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2383 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2384 r->password_expired = 0; /* FIXME */
2386 TALLOC_FREE(smbpass);
2388 return NT_STATUS_OK;
2391 /*************************************************************************
2393 *************************************************************************/
2395 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2396 struct samr_UserInfo20 *r,
2397 struct samu *sampass)
2399 const char *munged_dial = NULL;
2402 struct lsa_BinaryString *parameters = NULL;
2406 munged_dial = pdb_get_munged_dial(sampass);
2408 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2409 munged_dial, (int)strlen(munged_dial)));
2412 blob = base64_decode_data_blob(munged_dial);
2414 blob = data_blob_string_const_null("");
2417 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2418 data_blob_free(&blob);
2419 if (!NT_STATUS_IS_OK(status)) {
2423 r->parameters = *parameters;
2425 return NT_STATUS_OK;
2429 /*************************************************************************
2431 *************************************************************************/
2433 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2434 struct samr_UserInfo21 *r,
2436 DOM_SID *domain_sid)
2439 const DOM_SID *sid_user, *sid_group;
2440 uint32_t rid, primary_gid;
2441 NTTIME force_password_change;
2442 time_t must_change_time;
2443 struct lsa_BinaryString *parameters = NULL;
2444 const char *munged_dial = NULL;
2449 sid_user = pdb_get_user_sid(pw);
2451 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2452 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2453 "the domain sid %s. Failing operation.\n",
2454 pdb_get_username(pw), sid_string_dbg(sid_user),
2455 sid_string_dbg(domain_sid)));
2456 return NT_STATUS_UNSUCCESSFUL;
2460 sid_group = pdb_get_group_sid(pw);
2463 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2464 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2465 "which conflicts with the domain sid %s. Failing operation.\n",
2466 pdb_get_username(pw), sid_string_dbg(sid_group),
2467 sid_string_dbg(domain_sid)));
2468 return NT_STATUS_UNSUCCESSFUL;
2471 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2472 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2473 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2474 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2475 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2477 must_change_time = pdb_get_pass_must_change_time(pw);
2478 if (must_change_time == get_time_t_max()) {
2479 unix_to_nt_time_abs(&force_password_change, must_change_time);
2481 unix_to_nt_time(&force_password_change, must_change_time);
2484 munged_dial = pdb_get_munged_dial(pw);
2486 blob = base64_decode_data_blob(munged_dial);
2488 blob = data_blob_string_const_null("");
2491 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2492 data_blob_free(&blob);
2493 if (!NT_STATUS_IS_OK(status)) {
2497 r->force_password_change = force_password_change;
2499 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2500 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2501 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2502 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2503 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2504 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2505 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2506 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2507 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2509 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2510 r->parameters = *parameters;
2512 r->primary_gid = primary_gid;
2513 r->acct_flags = pdb_get_acct_ctrl(pw);
2514 r->bad_password_count = pdb_get_bad_password_count(pw);
2515 r->logon_count = pdb_get_logon_count(pw);
2516 r->fields_present = pdb_build_fields_present(pw);
2517 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2518 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2519 r->country_code = 0;
2521 r->lm_password_set = 0;
2522 r->nt_password_set = 0;
2527 Look at a user on a real NT4 PDC with usrmgr, press
2528 'ok'. Then you will see that fields_present is set to
2529 0x08f827fa. Look at the user immediately after that again,
2530 and you will see that 0x00fffff is returned. This solves
2531 the problem that you get access denied after having looked
2539 return NT_STATUS_OK;
2542 /*******************************************************************
2544 ********************************************************************/
2546 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2547 struct samr_QueryUserInfo *r)
2550 union samr_UserInfo *user_info = NULL;
2551 struct samr_info *info = NULL;
2555 struct samu *pwd = NULL;
2557 /* search for the handle */
2558 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
2559 return NT_STATUS_INVALID_HANDLE;
2561 status = access_check_samr_function(info->acc_granted,
2562 SAMR_USER_ACCESS_GET_ATTRIBUTES,
2563 "_samr_QueryUserInfo");
2564 if (!NT_STATUS_IS_OK(status)) {
2568 domain_sid = info->sid;
2570 sid_split_rid(&domain_sid, &rid);
2572 if (!sid_check_is_in_our_domain(&info->sid))
2573 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2575 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2576 sid_string_dbg(&info->sid)));
2578 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2580 return NT_STATUS_NO_MEMORY;
2583 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2585 if (!(pwd = samu_new(p->mem_ctx))) {
2586 return NT_STATUS_NO_MEMORY;
2590 ret = pdb_getsampwsid(pwd, &info->sid);
2594 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
2596 return NT_STATUS_NO_SUCH_USER;
2599 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2601 samr_clear_sam_passwd(pwd);
2603 switch (r->in.level) {
2605 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2608 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2611 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2614 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2617 /* level 18 is special */
2618 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
2621 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2624 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2627 status = NT_STATUS_INVALID_INFO_CLASS;
2633 *r->out.info = user_info;
2635 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2640 /****************************************************************
2641 ****************************************************************/
2643 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2644 struct samr_QueryUserInfo2 *r)
2646 struct samr_QueryUserInfo u;
2648 u.in.user_handle = r->in.user_handle;
2649 u.in.level = r->in.level;
2650 u.out.info = r->out.info;
2652 return _samr_QueryUserInfo(p, &u);
2655 /*******************************************************************
2656 _samr_GetGroupsForUser
2657 ********************************************************************/
2659 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2660 struct samr_GetGroupsForUser *r)
2662 struct samu *sam_pass=NULL;
2665 struct samr_RidWithAttribute dom_gid;
2666 struct samr_RidWithAttribute *gids = NULL;
2667 uint32 primary_group_rid;
2668 size_t num_groups = 0;
2674 bool success = False;
2676 struct samr_RidWithAttributeArray *rids = NULL;
2679 * from the SID in the request:
2680 * we should send back the list of DOMAIN GROUPS
2681 * the user is a member of
2683 * and only the DOMAIN GROUPS
2684 * no ALIASES !!! neither aliases of the domain
2685 * nor aliases of the builtin SID
2690 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2692 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
2694 return NT_STATUS_NO_MEMORY;
2697 /* find the policy handle. open a policy on it. */
2698 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
2699 return NT_STATUS_INVALID_HANDLE;
2701 result = access_check_samr_function(acc_granted,
2702 SAMR_USER_ACCESS_GET_GROUPS,
2703 "_samr_GetGroupsForUser");
2704 if (!NT_STATUS_IS_OK(result)) {
2708 if (!sid_check_is_in_our_domain(&sid))
2709 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2711 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2712 return NT_STATUS_NO_MEMORY;
2716 ret = pdb_getsampwsid(sam_pass, &sid);
2720 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2721 sid_string_dbg(&sid)));
2722 return NT_STATUS_NO_SUCH_USER;
2727 /* make both calls inside the root block */
2729 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2730 &sids, &unix_gids, &num_groups);
2731 if ( NT_STATUS_IS_OK(result) ) {
2732 success = sid_peek_check_rid(get_global_sam_sid(),
2733 pdb_get_group_sid(sam_pass),
2734 &primary_group_rid);
2738 if (!NT_STATUS_IS_OK(result)) {
2739 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2740 sid_string_dbg(&sid)));
2745 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2746 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2747 pdb_get_username(sam_pass)));
2748 TALLOC_FREE(sam_pass);
2749 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2755 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2757 dom_gid.rid = primary_group_rid;
2758 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2760 for (i=0; i<num_groups; i++) {
2762 if (!sid_peek_check_rid(get_global_sam_sid(),
2763 &(sids[i]), &dom_gid.rid)) {
2764 DEBUG(10, ("Found sid %s not in our domain\n",
2765 sid_string_dbg(&sids[i])));
2769 if (dom_gid.rid == primary_group_rid) {
2770 /* We added the primary group directly from the
2771 * sam_account. The other SIDs are unique from
2772 * enum_group_memberships */
2776 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2779 rids->count = num_gids;
2782 *r->out.rids = rids;
2784 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2789 /*******************************************************************
2790 _samr_QueryDomainInfo
2791 ********************************************************************/
2793 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
2794 struct samr_QueryDomainInfo *r)
2796 NTSTATUS status = NT_STATUS_OK;
2797 struct samr_info *info = NULL;
2798 union samr_DomainInfo *dom_info;
2799 time_t u_expire, u_min_age;
2801 time_t u_lock_duration, u_reset_time;
2804 uint32 account_policy_temp;
2809 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2811 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
2813 return NT_STATUS_NO_MEMORY;
2816 /* find the policy handle. open a policy on it. */
2817 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
2818 return NT_STATUS_INVALID_HANDLE;
2821 status = access_check_samr_function(info->acc_granted,
2822 SAMR_ACCESS_OPEN_DOMAIN,
2823 "_samr_QueryDomainInfo" );
2825 if ( !NT_STATUS_IS_OK(status) )
2828 switch (r->in.level) {
2835 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
2836 (uint32_t *)&dom_info->info1.min_password_length);
2838 pdb_get_account_policy(AP_PASSWORD_HISTORY,
2839 (uint32_t *)&dom_info->info1.password_history_length);
2841 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2842 &dom_info->info1.password_properties);
2844 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2845 u_expire = account_policy_temp;
2847 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2848 u_min_age = account_policy_temp;
2854 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
2855 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
2857 if (lp_check_password_script() && *lp_check_password_script()) {
2858 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
2868 dom_info->general.num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2869 dom_info->general.num_groups = count_sam_groups(info->disp_info);
2870 dom_info->general.num_aliases = count_sam_aliases(info->disp_info);
2872 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
2874 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
2876 if (!pdb_get_seq_num(&seq_num))
2877 seq_num = time(NULL);
2883 server_role = ROLE_DOMAIN_PDC;
2884 if (lp_server_role() == ROLE_DOMAIN_BDC)
2885 server_role = ROLE_DOMAIN_BDC;
2887 dom_info->general.oem_information.string = lp_serverstring();
2888 dom_info->general.domain_name.string = lp_workgroup();
2889 dom_info->general.primary.string = global_myname();
2890 dom_info->general.sequence_num = seq_num;
2891 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
2892 dom_info->general.role = server_role;
2893 dom_info->general.unknown3 = 1;
2904 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2905 u_logout = (time_t)ul;
2912 unix_to_nt_time_abs(&dom_info->info3.force_logoff_time, u_logout);
2916 dom_info->oem.oem_information.string = lp_serverstring();
2919 dom_info->info5.domain_name.string = get_global_sam_name();
2922 /* NT returns its own name when a PDC. win2k and later
2923 * only the name of the PDC if itself is a BDC (samba4
2925 dom_info->info6.primary.string = global_myname();
2928 server_role = ROLE_DOMAIN_PDC;
2929 if (lp_server_role() == ROLE_DOMAIN_BDC)
2930 server_role = ROLE_DOMAIN_BDC;
2932 dom_info->info7.role = server_role;
2940 if (!pdb_get_seq_num(&seq_num)) {
2941 seq_num = time(NULL);
2948 dom_info->info8.sequence_num = seq_num;
2949 dom_info->info8.domain_create_time = 0;
2958 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
2959 u_lock_duration = account_policy_temp;
2960 if (u_lock_duration != -1) {
2961 u_lock_duration *= 60;
2964 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
2965 u_reset_time = account_policy_temp * 60;
2967 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
2968 (uint32_t *)&dom_info->info12.lockout_threshold);
2974 unix_to_nt_time_abs(&dom_info->info12.lockout_duration,
2976 unix_to_nt_time_abs(&dom_info->info12.lockout_window,
2981 return NT_STATUS_INVALID_INFO_CLASS;
2984 *r->out.info = dom_info;
2986 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2991 /* W2k3 seems to use the same check for all 3 objects that can be created via
2992 * SAMR, if you try to create for example "Dialup" as an alias it says
2993 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
2996 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
2998 enum lsa_SidType type;
3001 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
3004 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3005 * whether the name already exists */
3006 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3007 NULL, NULL, NULL, &type);
3011 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3012 return NT_STATUS_OK;
3015 DEBUG(5, ("trying to create %s, exists as %s\n",
3016 new_name, sid_type_lookup(type)));
3018 if (type == SID_NAME_DOM_GRP) {
3019 return NT_STATUS_GROUP_EXISTS;
3021 if (type == SID_NAME_ALIAS) {
3022 return NT_STATUS_ALIAS_EXISTS;
3025 /* Yes, the default is NT_STATUS_USER_EXISTS */
3026 return NT_STATUS_USER_EXISTS;
3029 /*******************************************************************
3031 ********************************************************************/
3033 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3034 struct samr_CreateUser2 *r)
3036 const char *account = NULL;
3038 POLICY_HND dom_pol = *r->in.domain_handle;
3039 uint32_t acb_info = r->in.acct_flags;
3040 POLICY_HND *user_pol = r->out.user_handle;
3041 struct samr_info *info = NULL;
3046 /* check this, when giving away 'add computer to domain' privs */
3047 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3048 bool can_add_account = False;
3050 DISP_INFO *disp_info = NULL;
3052 /* Get the domain SID stored in the domain policy */
3053 if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
3055 return NT_STATUS_INVALID_HANDLE;
3057 if (disp_info->builtin_domain) {
3058 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3059 return NT_STATUS_ACCESS_DENIED;
3062 nt_status = access_check_samr_function(acc_granted,
3063 SAMR_DOMAIN_ACCESS_CREATE_USER,
3064 "_samr_CreateUser2");
3065 if (!NT_STATUS_IS_OK(nt_status)) {
3069 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3070 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3071 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3072 this parameter is not an account type */
3073 return NT_STATUS_INVALID_PARAMETER;
3076 account = r->in.account_name->string;
3077 if (account == NULL) {
3078 return NT_STATUS_NO_MEMORY;
3081 nt_status = can_create(p->mem_ctx, account);
3082 if (!NT_STATUS_IS_OK(nt_status)) {
3086 /* determine which user right we need to check based on the acb_info */
3088 if ( acb_info & ACB_WSTRUST )
3090 se_priv_copy( &se_rights, &se_machine_account );
3091 can_add_account = user_has_privileges(
3092 p->server_info->ptok, &se_rights );
3094 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3095 account for domain trusts and changes the ACB flags later */
3096 else if ( acb_info & ACB_NORMAL &&
3097 (account[strlen(account)-1] != '$') )
3099 se_priv_copy( &se_rights, &se_add_users );
3100 can_add_account = user_has_privileges(
3101 p->server_info->ptok, &se_rights );
3103 else /* implicit assumption of a BDC or domain trust account here
3104 * (we already check the flags earlier) */
3106 if ( lp_enable_privileges() ) {
3107 /* only Domain Admins can add a BDC or domain trust */
3108 se_priv_copy( &se_rights, &se_priv_none );
3109 can_add_account = nt_token_check_domain_rid(
3110 p->server_info->ptok,
3111 DOMAIN_GROUP_RID_ADMINS );
3115 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3116 uidtoname(p->server_info->utok.uid),
3117 can_add_account ? "True":"False" ));
3119 /********** BEGIN Admin BLOCK **********/
3121 if ( can_add_account )
3124 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3127 if ( can_add_account )
3130 /********** END Admin BLOCK **********/
3132 /* now check for failure */
3134 if ( !NT_STATUS_IS_OK(nt_status) )
3137 /* Get the user's SID */
3139 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3141 map_max_allowed_access(p->server_info->ptok, &des_access);
3143 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3144 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3145 se_map_generic(&des_access, &usr_generic_mapping);
3147 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3148 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3149 &acc_granted, "_samr_CreateUser2");
3151 if ( !NT_STATUS_IS_OK(nt_status) ) {
3155 /* associate the user's SID with the new handle. */
3156 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL) {
3157 return NT_STATUS_NO_MEMORY;
3162 info->acc_granted = acc_granted;
3164 /* get a (unique) handle. open a policy on it. */
3165 if (!create_policy_hnd(p, user_pol, info)) {
3166 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3169 /* After a "set" ensure we have no cached display info. */
3170 force_flush_samr_cache(info->disp_info);
3172 *r->out.access_granted = acc_granted;
3174 return NT_STATUS_OK;
3177 /****************************************************************
3178 ****************************************************************/
3180 NTSTATUS _samr_CreateUser(pipes_struct *p,
3181 struct samr_CreateUser *r)
3183 struct samr_CreateUser2 c;
3184 uint32_t access_granted;
3186 c.in.domain_handle = r->in.domain_handle;
3187 c.in.account_name = r->in.account_name;
3188 c.in.acct_flags = ACB_NORMAL;
3189 c.in.access_mask = r->in.access_mask;
3190 c.out.user_handle = r->out.user_handle;
3191 c.out.access_granted = &access_granted;
3192 c.out.rid = r->out.rid;
3194 return _samr_CreateUser2(p, &c);
3197 /*******************************************************************
3199 ********************************************************************/
3201 NTSTATUS _samr_Connect(pipes_struct *p,
3202 struct samr_Connect *r)
3204 struct samr_info *info = NULL;
3205 uint32 des_access = r->in.access_mask;
3209 if (!pipe_access_check(p)) {
3210 DEBUG(3, ("access denied to _samr_Connect\n"));
3211 return NT_STATUS_ACCESS_DENIED;
3214 /* set up the SAMR connect_anon response */
3216 /* associate the user's SID with the new handle. */
3217 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3218 return NT_STATUS_NO_MEMORY;
3220 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3221 was observed from a win98 client trying to enumerate users (when configured
3222 user level access control on shares) --jerry */
3224 map_max_allowed_access(p->server_info->ptok, &des_access);
3226 se_map_generic( &des_access, &sam_generic_mapping );
3227 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
3229 /* get a (unique) handle. open a policy on it. */
3230 if (!create_policy_hnd(p, r->out.connect_handle, info))
3231 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3233 return NT_STATUS_OK;
3236 /*******************************************************************
3238 ********************************************************************/
3240 NTSTATUS _samr_Connect2(pipes_struct *p,
3241 struct samr_Connect2 *r)
3243 struct samr_info *info = NULL;
3244 SEC_DESC *psd = NULL;
3246 uint32 des_access = r->in.access_mask;
3249 const char *fn = "_samr_Connect2";
3251 switch (p->hdr_req.opnum) {
3252 case NDR_SAMR_CONNECT2:
3253 fn = "_samr_Connect2";
3255 case NDR_SAMR_CONNECT4:
3256 fn = "_samr_Connect4";
3258 case NDR_SAMR_CONNECT5:
3259 fn = "_samr_Connect5";
3263 DEBUG(5,("%s: %d\n", fn, __LINE__));
3267 if (!pipe_access_check(p)) {
3268 DEBUG(3, ("access denied to %s\n", fn));
3269 return NT_STATUS_ACCESS_DENIED;
3272 map_max_allowed_access(p->server_info->ptok, &des_access);
3274 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3275 se_map_generic(&des_access, &sam_generic_mapping);
3277 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3278 NULL, 0, des_access, &acc_granted, fn);
3280 if ( !NT_STATUS_IS_OK(nt_status) )
3283 /* associate the user's SID and access granted with the new handle. */
3284 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3285 return NT_STATUS_NO_MEMORY;
3287 info->acc_granted = acc_granted;
3288 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3290 /* get a (unique) handle. open a policy on it. */
3291 if (!create_policy_hnd(p, r->out.connect_handle, info))
3292 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3294 DEBUG(5,("%s: %d\n", fn, __LINE__));
3299 /*******************************************************************
3301 ********************************************************************/
3303 NTSTATUS _samr_Connect4(pipes_struct *p,
3304 struct samr_Connect4 *r)
3306 struct samr_Connect2 c;
3308 c.in.system_name = r->in.system_name;
3309 c.in.access_mask = r->in.access_mask;
3310 c.out.connect_handle = r->out.connect_handle;
3312 return _samr_Connect2(p, &c);
3315 /*******************************************************************
3317 ********************************************************************/
3319 NTSTATUS _samr_Connect5(pipes_struct *p,
3320 struct samr_Connect5 *r)
3323 struct samr_Connect2 c;
3324 struct samr_ConnectInfo1 info1;
3326 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3329 c.in.system_name = r->in.system_name;
3330 c.in.access_mask = r->in.access_mask;
3331 c.out.connect_handle = r->out.connect_handle;
3333 status = _samr_Connect2(p, &c);
3334 if (!NT_STATUS_IS_OK(status)) {
3338 *r->out.level_out = 1;
3339 r->out.info_out->info1 = info1;
3341 return NT_STATUS_OK;
3344 /**********************************************************************
3346 **********************************************************************/
3348 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3349 struct samr_LookupDomain *r)
3351 NTSTATUS status = NT_STATUS_OK;
3352 struct samr_info *info;
3353 const char *domain_name;
3354 DOM_SID *sid = NULL;
3356 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3357 return NT_STATUS_INVALID_HANDLE;
3359 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
3360 Reverted that change so we will work with RAS servers again */
3362 status = access_check_samr_function(info->acc_granted,
3363 SAMR_ACCESS_OPEN_DOMAIN,
3364 "_samr_LookupDomain");
3365 if (!NT_STATUS_IS_OK(status)) {
3369 domain_name = r->in.domain_name->string;
3371 return NT_STATUS_INVALID_PARAMETER;
3374 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
3376 return NT_STATUS_NO_MEMORY;
3379 if (strequal(domain_name, builtin_domain_name())) {
3380 sid_copy(sid, &global_sid_Builtin);
3382 if (!secrets_fetch_domain_sid(domain_name, sid)) {
3383 status = NT_STATUS_NO_SUCH_DOMAIN;
3387 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
3388 sid_string_dbg(sid)));
3395 /**********************************************************************
3397 **********************************************************************/
3399 NTSTATUS _samr_EnumDomains(pipes_struct *p,
3400 struct samr_EnumDomains *r)
3403 struct samr_info *info;
3404 uint32_t num_entries = 2;
3405 struct samr_SamEntry *entry_array = NULL;
3406 struct samr_SamArray *sam;
3408 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3409 return NT_STATUS_INVALID_HANDLE;
3411 status = access_check_samr_function(info->acc_granted,
3412 SAMR_ACCESS_ENUM_DOMAINS,
3413 "_samr_EnumDomains");
3414 if (!NT_STATUS_IS_OK(status)) {
3418 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
3420 return NT_STATUS_NO_MEMORY;
3423 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
3424 struct samr_SamEntry,
3427 return NT_STATUS_NO_MEMORY;
3430 entry_array[0].idx = 0;
3431 init_lsa_String(&entry_array[0].name, get_global_sam_name());
3433 entry_array[1].idx = 1;
3434 init_lsa_String(&entry_array[1].name, "Builtin");
3436 sam->count = num_entries;
3437 sam->entries = entry_array;
3440 *r->out.num_entries = num_entries;
3445 /*******************************************************************
3447 ********************************************************************/
3449 NTSTATUS _samr_OpenAlias(pipes_struct *p,
3450 struct samr_OpenAlias *r)
3453 POLICY_HND domain_pol = *r->in.domain_handle;
3454 uint32 alias_rid = r->in.rid;
3455 POLICY_HND *alias_pol = r->out.alias_handle;
3456 struct samr_info *info = NULL;
3457 SEC_DESC *psd = NULL;
3459 uint32 des_access = r->in.access_mask;
3464 /* find the domain policy and get the SID / access bits stored in the domain policy */
3466 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
3467 return NT_STATUS_INVALID_HANDLE;
3469 status = access_check_samr_function(acc_granted,
3470 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
3473 if ( !NT_STATUS_IS_OK(status) )
3476 /* append the alias' RID to it */
3478 if (!sid_append_rid(&sid, alias_rid))
3479 return NT_STATUS_NO_SUCH_ALIAS;
3481 /*check if access can be granted as requested by client. */
3483 map_max_allowed_access(p->server_info->ptok, &des_access);
3485 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3486 se_map_generic(&des_access,&ali_generic_mapping);
3488 se_priv_copy( &se_rights, &se_add_users );
3491 status = access_check_samr_object(psd, p->server_info->ptok,
3492 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3493 &acc_granted, "_samr_OpenAlias");
3495 if ( !NT_STATUS_IS_OK(status) )
3499 /* Check we actually have the requested alias */
3500 enum lsa_SidType type;
3505 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3508 if (!result || (type != SID_NAME_ALIAS)) {
3509 return NT_STATUS_NO_SUCH_ALIAS;
3512 /* make sure there is a mapping */
3514 if ( !sid_to_gid( &sid, &gid ) ) {
3515 return NT_STATUS_NO_SUCH_ALIAS;
3520 /* associate the alias SID with the new handle. */
3521 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
3522 return NT_STATUS_NO_MEMORY;
3524 info->acc_granted = acc_granted;
3526 /* get a (unique) handle. open a policy on it. */
3527 if (!create_policy_hnd(p, alias_pol, info))
3528 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3530 return NT_STATUS_OK;
3533 /*******************************************************************
3535 ********************************************************************/
3537 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3538 struct samr_UserInfo7 *id7,
3544 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3545 return NT_STATUS_ACCESS_DENIED;
3548 if (!id7->account_name.string) {
3549 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3550 return NT_STATUS_ACCESS_DENIED;
3553 /* check to see if the new username already exists. Note: we can't
3554 reliably lock all backends, so there is potentially the
3555 possibility that a user can be created in between this check and
3556 the rename. The rename should fail, but may not get the
3557 exact same failure status code. I think this is small enough
3558 of a window for this type of operation and the results are
3559 simply that the rename fails with a slightly different status
3560 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3562 rc = can_create(mem_ctx, id7->account_name.string);
3563 if (!NT_STATUS_IS_OK(rc)) {
3567 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
3572 /*******************************************************************
3574 ********************************************************************/
3576 static bool set_user_info_16(struct samr_UserInfo16 *id16,
3580 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3584 /* FIX ME: check if the value is really changed --metze */
3585 if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
3589 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3596 /*******************************************************************
3598 ********************************************************************/
3600 static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
3601 TALLOC_CTX *mem_ctx,
3602 DATA_BLOB *session_key,
3606 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3607 return NT_STATUS_INVALID_PARAMETER;
3610 if (id18->nt_pwd_active || id18->lm_pwd_active) {
3611 if (!session_key->length) {
3612 return NT_STATUS_NO_USER_SESSION_KEY;
3616 if (id18->nt_pwd_active) {
3620 in = data_blob_const(id18->nt_pwd.hash, 16);
3621 out = data_blob_talloc_zero(mem_ctx, 16);
3623 sess_crypt_blob(&out, &in, session_key, false);
3625 if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
3626 return NT_STATUS_ACCESS_DENIED;
3629 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3632 if (id18->lm_pwd_active) {
3636 in = data_blob_const(id18->lm_pwd.hash, 16);
3637 out = data_blob_talloc_zero(mem_ctx, 16);
3639 sess_crypt_blob(&out, &in, session_key, false);
3641 if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
3642 return NT_STATUS_ACCESS_DENIED;
3645 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3648 if (id18->password_expired) {
3649 pdb_set_pass_last_set_time(pwd, 0, PDB_CHANGED);
3652 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3655 return pdb_update_sam_account(pwd);
3658 /*******************************************************************
3660 ********************************************************************/
3662 static bool set_user_info_20(struct samr_UserInfo20 *id20,
3666 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3670 copy_id20_to_sam_passwd(pwd, id20);
3672 /* write the change out */
3673 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3680 /*******************************************************************
3682 ********************************************************************/
3684 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
3685 struct samr_UserInfo21 *id21,
3691 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3692 return NT_STATUS_INVALID_PARAMETER;
3695 if (id21->fields_present == 0) {
3696 return NT_STATUS_INVALID_PARAMETER;
3699 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3700 return NT_STATUS_ACCESS_DENIED;
3703 /* we need to separately check for an account rename first */
3705 if (id21->account_name.string &&
3706 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
3709 /* check to see if the new username already exists. Note: we can't
3710 reliably lock all backends, so there is potentially the
3711 possibility that a user can be created in between this check and
3712 the rename. The rename should fail, but may not get the
3713 exact same failure status code. I think this is small enough
3714 of a window for this type of operation and the results are
3715 simply that the rename fails with a slightly different status
3716 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3718 status = can_create(mem_ctx, id21->account_name.string);
3719 if (!NT_STATUS_IS_OK(status)) {
3723 status = pdb_rename_sam_account(pwd, id21->account_name.string);
3725 if (!NT_STATUS_IS_OK(status)) {
3726 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3727 nt_errstr(status)));
3731 /* set the new username so that later
3732 functions can work on the new account */
3733 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
3736 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
3739 * The funny part about the previous two calls is
3740 * that pwd still has the password hashes from the
3741 * passdb entry. These have not been updated from
3742 * id21. I don't know if they need to be set. --jerry
3745 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3746 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3747 if ( !NT_STATUS_IS_OK(status) ) {
3752 /* Don't worry about writing out the user account since the
3753 primary group SID is generated solely from the user's Unix
3756 /* write the change out */
3757 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3761 return NT_STATUS_OK;
3764 /*******************************************************************
3766 ********************************************************************/
3768 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
3769 struct samr_UserInfo23 *id23,
3772 char *plaintext_buf = NULL;
3778 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3779 return NT_STATUS_INVALID_PARAMETER;
3782 if (id23->info.fields_present == 0) {
3783 return NT_STATUS_INVALID_PARAMETER;
3786 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3787 return NT_STATUS_ACCESS_DENIED;
3790 if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
3791 (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
3793 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3794 pdb_get_username(pwd)));
3796 if (!decode_pw_buffer(mem_ctx,
3797 id23->password.data,
3801 return NT_STATUS_WRONG_PASSWORD;
3804 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3805 return NT_STATUS_ACCESS_DENIED;
3809 copy_id23_to_sam_passwd(pwd, id23);
3811 acct_ctrl = pdb_get_acct_ctrl(pwd);
3813 /* if it's a trust account, don't update /etc/passwd */
3814 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3815 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3816 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3817 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3818 } else if (plaintext_buf) {
3819 /* update the UNIX password */
3820 if (lp_unix_password_sync() ) {
3821 struct passwd *passwd;
3822 if (pdb_get_username(pwd) == NULL) {
3823 DEBUG(1, ("chgpasswd: User without name???\n"));
3824 return NT_STATUS_ACCESS_DENIED;
3827 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3828 if (passwd == NULL) {
3829 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3832 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3833 return NT_STATUS_ACCESS_DENIED;
3835 TALLOC_FREE(passwd);
3839 if (plaintext_buf) {
3840 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3843 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3844 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3849 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3853 return NT_STATUS_OK;
3856 /*******************************************************************
3858 ********************************************************************/
3860 static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
3864 char *plaintext_buf = NULL;
3866 time_t last_set_time;
3867 enum pdb_value_state last_set_state;
3869 DEBUG(5, ("Attempting administrator password change for user %s\n",
3870 pdb_get_username(pwd)));
3872 acct_ctrl = pdb_get_acct_ctrl(pwd);
3873 /* we need to know if it's expired, because this is an admin change, not a
3874 user change, so it's still expired when we're done */
3875 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3876 last_set_time = pdb_get_pass_last_set_time(pwd);
3878 if (!decode_pw_buffer(talloc_tos(),
3886 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3890 /* if it's a trust account, don't update /etc/passwd */
3891 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3892 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3893 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3894 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3896 /* update the UNIX password */
3897 if (lp_unix_password_sync()) {
3898 struct passwd *passwd;
3900 if (pdb_get_username(pwd) == NULL) {
3901 DEBUG(1, ("chgpasswd: User without name???\n"));
3905 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3906 if (passwd == NULL) {
3907 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3910 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3913 TALLOC_FREE(passwd);
3917 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3920 * A level 25 change does reset the pwdlastset field, a level 24
3921 * change does not. I know this is probably not the full story, but
3922 * it is needed to make XP join LDAP correctly, without it the later
3923 * auth2 check can fail with PWD_MUST_CHANGE.
3927 * restore last set time as this is an admin change, not a
3930 pdb_set_pass_last_set_time (pwd, last_set_time,
3934 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
3936 /* update the SAMBA password */
3937 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3944 /*******************************************************************
3946 ********************************************************************/
3948 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
3949 struct samr_UserInfo25 *id25,
3955 DEBUG(5, ("set_user_info_25: NULL id25\n"));
3956 return NT_STATUS_INVALID_PARAMETER;
3959 if (id25->info.fields_present == 0) {
3960 return NT_STATUS_INVALID_PARAMETER;
3963 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3964 return NT_STATUS_ACCESS_DENIED;
3967 copy_id25_to_sam_passwd(pwd, id25);
3969 /* write the change out */
3970 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3975 * We need to "pdb_update_sam_account" before the unix primary group
3976 * is set, because the idealx scripts would also change the
3977 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
3978 * the delete explicit / add explicit, which would then fail to find
3979 * the previous primaryGroupSid value.
3982 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3983 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3984 if ( !NT_STATUS_IS_OK(status) ) {
3989 return NT_STATUS_OK;
3992 /*******************************************************************
3994 ********************************************************************/
3996 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
3997 struct samr_SetUserInfo *r)
4000 struct samu *pwd = NULL;
4002 POLICY_HND *pol = r->in.user_handle;
4003 union samr_UserInfo *info = r->in.info;
4004 uint16_t switch_value = r->in.level;
4005 uint32_t acc_granted;
4006 uint32_t acc_required;
4008 bool has_enough_rights = False;
4010 DISP_INFO *disp_info = NULL;
4012 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4014 /* find the policy handle. open a policy on it. */
4015 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) {
4016 return NT_STATUS_INVALID_HANDLE;
4019 /* This is tricky. A WinXP domain join sets
4020 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4021 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4022 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4023 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4024 we'll use the set from the WinXP join as the basis. */
4026 switch (switch_value) {
4031 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4034 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4035 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4036 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4040 status = access_check_samr_function(acc_granted,
4042 "_samr_SetUserInfo");
4043 if (!NT_STATUS_IS_OK(status)) {
4047 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4048 sid_string_dbg(&sid), switch_value));
4051 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4052 return NT_STATUS_INVALID_INFO_CLASS;
4055 if (!(pwd = samu_new(NULL))) {
4056 return NT_STATUS_NO_MEMORY;
4060 ret = pdb_getsampwsid(pwd, &sid);
4065 return NT_STATUS_NO_SUCH_USER;
4068 /* deal with machine password changes differently from userinfo changes */
4069 /* check to see if we have the sufficient rights */
4071 acb_info = pdb_get_acct_ctrl(pwd);
4072 if (acb_info & ACB_WSTRUST)
4073 has_enough_rights = user_has_privileges(p->server_info->ptok,
4074 &se_machine_account);
4075 else if (acb_info & ACB_NORMAL)
4076 has_enough_rights = user_has_privileges(p->server_info->ptok,
4078 else if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
4079 if (lp_enable_privileges()) {
4080 has_enough_rights = nt_token_check_domain_rid(p->server_info->ptok,
4081 DOMAIN_GROUP_RID_ADMINS);
4085 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4086 uidtoname(p->server_info->utok.uid),
4087 has_enough_rights ? "" : " not"));
4089 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4091 if (has_enough_rights) {
4095 /* ok! user info levels (lots: see MSDEV help), off we go... */
4097 switch (switch_value) {
4100 status = set_user_info_7(p->mem_ctx,
4105 if (!set_user_info_16(&info->info16, pwd)) {
4106 status = NT_STATUS_ACCESS_DENIED;
4111 /* Used by AS/U JRA. */
4112 status = set_user_info_18(&info->info18,
4114 &p->server_info->user_session_key,
4119 if (!set_user_info_20(&info->info20, pwd)) {
4120 status = NT_STATUS_ACCESS_DENIED;
4125 status = set_user_info_21(p->mem_ctx,
4126 &info->info21, pwd);
4130 if (!p->server_info->user_session_key.length) {
4131 status = NT_STATUS_NO_USER_SESSION_KEY;
4133 SamOEMhashBlob(info->info23.password.data, 516,
4134 &p->server_info->user_session_key);
4136 dump_data(100, info->info23.password.data, 516);
4138 status = set_user_info_23(p->mem_ctx,
4139 &info->info23, pwd);
4143 if (!p->server_info->user_session_key.length) {
4144 status = NT_STATUS_NO_USER_SESSION_KEY;
4146 SamOEMhashBlob(info->info24.password.data,
4148 &p->server_info->user_session_key);
4150 dump_data(100, info->info24.password.data, 516);
4152 if (!set_user_info_pw(info->info24.password.data, pwd,
4154 status = NT_STATUS_WRONG_PASSWORD;
4159 if (!p->server_info->user_session_key.length) {
4160 status = NT_STATUS_NO_USER_SESSION_KEY;
4162 encode_or_decode_arc4_passwd_buffer(
4163 info->info25.password.data,
4164 &p->server_info->user_session_key);
4166 dump_data(100, info->info25.password.data, 532);
4168 status = set_user_info_25(p->mem_ctx,
4169 &info->info25, pwd);
4170 if (!NT_STATUS_IS_OK(status)) {
4173 if (!set_user_info_pw(info->info25.password.data, pwd,
4175 status = NT_STATUS_WRONG_PASSWORD;
4180 if (!p->server_info->user_session_key.length) {
4181 status = NT_STATUS_NO_USER_SESSION_KEY;
4183 encode_or_decode_arc4_passwd_buffer(
4184 info->info26.password.data,
4185 &p->server_info->user_session_key);
4187 dump_data(100, info->info26.password.data, 516);
4189 if (!set_user_info_pw(info->info26.password.data, pwd,
4191 status = NT_STATUS_WRONG_PASSWORD;
4196 status = NT_STATUS_INVALID_INFO_CLASS;
4203 if (has_enough_rights) {
4207 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4209 if (NT_STATUS_IS_OK(status)) {
4210 force_flush_samr_cache(disp_info);
4216 /*******************************************************************
4218 ********************************************************************/
4220 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
4221 struct samr_SetUserInfo2 *r)
4223 struct samr_SetUserInfo q;
4225 q.in.user_handle = r->in.user_handle;
4226 q.in.level = r->in.level;
4227 q.in.info = r->in.info;
4229 return _samr_SetUserInfo(p, &q);
4232 /*********************************************************************
4233 _samr_GetAliasMembership
4234 *********************************************************************/
4236 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
4237 struct samr_GetAliasMembership *r)
4239 size_t num_alias_rids;
4241 struct samr_info *info = NULL;
4249 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
4251 /* find the policy handle. open a policy on it. */
4252 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
4253 return NT_STATUS_INVALID_HANDLE;
4255 ntstatus1 = access_check_samr_function(info->acc_granted,
4256 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
4257 "_samr_GetAliasMembership");
4258 ntstatus2 = access_check_samr_function(info->acc_granted,
4259 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4260 "_samr_GetAliasMembership");
4262 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
4263 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
4264 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
4265 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
4269 if (!sid_check_is_domain(&info->sid) &&
4270 !sid_check_is_builtin(&info->sid))
4271 return NT_STATUS_OBJECT_TYPE_MISMATCH;
4273 if (r->in.sids->num_sids) {
4274 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
4276 if (members == NULL)
4277 return NT_STATUS_NO_MEMORY;
4282 for (i=0; i<r->in.sids->num_sids; i++)
4283 sid_copy(&members[i], r->in.sids->sids[i].sid);
4289 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
4290 r->in.sids->num_sids,
4291 &alias_rids, &num_alias_rids);
4294 if (!NT_STATUS_IS_OK(ntstatus1)) {
4298 r->out.rids->count = num_alias_rids;
4299 r->out.rids->ids = alias_rids;
4301 return NT_STATUS_OK;
4304 /*********************************************************************
4305 _samr_GetMembersInAlias
4306 *********************************************************************/
4308 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
4309 struct samr_GetMembersInAlias *r)
4313 size_t num_sids = 0;
4314 struct lsa_SidPtr *sids = NULL;
4315 DOM_SID *pdb_sids = NULL;
4321 /* find the policy handle. open a policy on it. */
4322 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
4323 return NT_STATUS_INVALID_HANDLE;
4325 status = access_check_samr_function(acc_granted,
4326 SAMR_ALIAS_ACCESS_GET_MEMBERS,
4327 "_samr_GetMembersInAlias");
4328 if (!NT_STATUS_IS_OK(status)) {
4332 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4335 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
4338 if (!NT_STATUS_IS_OK(status)) {
4343 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
4345 TALLOC_FREE(pdb_sids);
4346 return NT_STATUS_NO_MEMORY;
4350 for (i = 0; i < num_sids; i++) {
4351 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
4353 TALLOC_FREE(pdb_sids);
4354 return NT_STATUS_NO_MEMORY;
4358 r->out.sids->num_sids = num_sids;
4359 r->out.sids->sids = sids;
4361 TALLOC_FREE(pdb_sids);
4363 return NT_STATUS_OK;
4366 /*********************************************************************
4367 _samr_QueryGroupMember
4368 *********************************************************************/
4370 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
4371 struct samr_QueryGroupMember *r)
4374 size_t i, num_members;
4382 struct samr_RidTypeArray *rids = NULL;
4384 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
4386 return NT_STATUS_NO_MEMORY;
4389 /* find the policy handle. open a policy on it. */
4390 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
4391 return NT_STATUS_INVALID_HANDLE;
4393 status = access_check_samr_function(acc_granted,
4394 SAMR_GROUP_ACCESS_GET_MEMBERS,
4395 "_samr_QueryGroupMember");
4396 if (!NT_STATUS_IS_OK(status)) {
4400 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4402 if (!sid_check_is_in_our_domain(&group_sid)) {
4403 DEBUG(3, ("sid %s is not in our domain\n",
4404 sid_string_dbg(&group_sid)));
4405 return NT_STATUS_NO_SUCH_GROUP;
4408 DEBUG(10, ("lookup on Domain SID\n"));
4411 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
4412 &rid, &num_members);
4415 if (!NT_STATUS_IS_OK(status))
4419 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
4421 return NT_STATUS_NO_MEMORY;
4427 for (i=0; i<num_members; i++)
4428 attr[i] = SID_NAME_USER;
4430 rids->count = num_members;
4434 *r->out.rids = rids;
4436 return NT_STATUS_OK;
4439 /*********************************************************************
4440 _samr_AddAliasMember
4441 *********************************************************************/
4443 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
4444 struct samr_AddAliasMember *r)
4449 bool can_add_accounts;
4451 DISP_INFO *disp_info = NULL;
4453 /* Find the policy handle. Open a policy on it. */
4454 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4455 return NT_STATUS_INVALID_HANDLE;
4457 status = access_check_samr_function(acc_granted,
4458 SAMR_ALIAS_ACCESS_ADD_MEMBER,
4459 "_samr_AddAliasMember");
4460 if (!NT_STATUS_IS_OK(status)) {
4464 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4466 se_priv_copy( &se_rights, &se_add_users );
4467 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4469 /******** BEGIN SeAddUsers BLOCK *********/
4471 if ( can_add_accounts )
4474 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
4476 if ( can_add_accounts )
4479 /******** END SeAddUsers BLOCK *********/
4481 if (NT_STATUS_IS_OK(status)) {
4482 force_flush_samr_cache(disp_info);
4488 /*********************************************************************
4489 _samr_DeleteAliasMember
4490 *********************************************************************/
4492 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
4493 struct samr_DeleteAliasMember *r)
4498 bool can_add_accounts;
4500 DISP_INFO *disp_info = NULL;
4502 /* Find the policy handle. Open a policy on it. */
4503 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4504 return NT_STATUS_INVALID_HANDLE;
4506 status = access_check_samr_function(acc_granted,
4507 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
4508 "_samr_DeleteAliasMember");
4509 if (!NT_STATUS_IS_OK(status)) {
4513 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4514 sid_string_dbg(&alias_sid)));
4516 se_priv_copy( &se_rights, &se_add_users );
4517 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4519 /******** BEGIN SeAddUsers BLOCK *********/
4521 if ( can_add_accounts )
4524 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
4526 if ( can_add_accounts )
4529 /******** END SeAddUsers BLOCK *********/
4531 if (NT_STATUS_IS_OK(status)) {
4532 force_flush_samr_cache(disp_info);
4538 /*********************************************************************
4539 _samr_AddGroupMember
4540 *********************************************************************/
4542 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
4543 struct samr_AddGroupMember *r)
4550 bool can_add_accounts;
4551 DISP_INFO *disp_info = NULL;
4553 /* Find the policy handle. Open a policy on it. */
4554 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4555 return NT_STATUS_INVALID_HANDLE;
4557 status = access_check_samr_function(acc_granted,
4558 SAMR_GROUP_ACCESS_ADD_MEMBER,
4559 "_samr_AddGroupMember");
4560 if (!NT_STATUS_IS_OK(status)) {
4564 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4566 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4568 return NT_STATUS_INVALID_HANDLE;
4571 se_priv_copy( &se_rights, &se_add_users );
4572 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4574 /******** BEGIN SeAddUsers BLOCK *********/
4576 if ( can_add_accounts )
4579 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
4581 if ( can_add_accounts )
4584 /******** END SeAddUsers BLOCK *********/
4586 force_flush_samr_cache(disp_info);
4591 /*********************************************************************
4592 _samr_DeleteGroupMember
4593 *********************************************************************/
4595 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
4596 struct samr_DeleteGroupMember *r)
4604 bool can_add_accounts;
4605 DISP_INFO *disp_info = NULL;
4608 * delete the group member named r->in.rid
4609 * who is a member of the sid associated with the handle
4610 * the rid is a user's rid as the group is a domain group.
4613 /* Find the policy handle. Open a policy on it. */
4614 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4615 return NT_STATUS_INVALID_HANDLE;
4617 status = access_check_samr_function(acc_granted,
4618 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
4619 "_samr_DeleteGroupMember");
4620 if (!NT_STATUS_IS_OK(status)) {
4624 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4626 return NT_STATUS_INVALID_HANDLE;
4629 se_priv_copy( &se_rights, &se_add_users );
4630 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4632 /******** BEGIN SeAddUsers BLOCK *********/
4634 if ( can_add_accounts )
4637 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
4639 if ( can_add_accounts )
4642 /******** END SeAddUsers BLOCK *********/
4644 force_flush_samr_cache(disp_info);
4649 /*********************************************************************
4651 *********************************************************************/
4653 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4654 struct samr_DeleteUser *r)
4658 struct samu *sam_pass=NULL;
4660 bool can_add_accounts;
4662 DISP_INFO *disp_info = NULL;
4665 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4667 /* Find the policy handle. Open a policy on it. */
4668 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4669 return NT_STATUS_INVALID_HANDLE;
4671 status = access_check_samr_function(acc_granted,
4672 STD_RIGHT_DELETE_ACCESS,
4673 "_samr_DeleteUser");
4674 if (!NT_STATUS_IS_OK(status)) {
4678 if (!sid_check_is_in_our_domain(&user_sid))
4679 return NT_STATUS_CANNOT_DELETE;
4681 /* check if the user exists before trying to delete */
4682 if ( !(sam_pass = samu_new( NULL )) ) {
4683 return NT_STATUS_NO_MEMORY;
4687 ret = pdb_getsampwsid(sam_pass, &user_sid);
4691 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4692 sid_string_dbg(&user_sid)));
4693 TALLOC_FREE(sam_pass);
4694 return NT_STATUS_NO_SUCH_USER;
4697 acb_info = pdb_get_acct_ctrl(sam_pass);
4699 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4700 if ( acb_info & ACB_WSTRUST ) {
4701 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_machine_account );
4703 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
4706 /******** BEGIN SeAddUsers BLOCK *********/
4708 if ( can_add_accounts )
4711 status = pdb_delete_user(p->mem_ctx, sam_pass);
4713 if ( can_add_accounts )
4716 /******** END SeAddUsers BLOCK *********/
4718 if ( !NT_STATUS_IS_OK(status) ) {
4719 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4720 "user %s: %s.\n", pdb_get_username(sam_pass),
4721 nt_errstr(status)));
4722 TALLOC_FREE(sam_pass);
4727 TALLOC_FREE(sam_pass);
4729 if (!close_policy_hnd(p, r->in.user_handle))
4730 return NT_STATUS_OBJECT_NAME_INVALID;
4732 ZERO_STRUCTP(r->out.user_handle);
4734 force_flush_samr_cache(disp_info);
4736 return NT_STATUS_OK;
4739 /*********************************************************************
4740 _samr_DeleteDomainGroup
4741 *********************************************************************/
4743 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4744 struct samr_DeleteDomainGroup *r)
4751 bool can_add_accounts;
4752 DISP_INFO *disp_info = NULL;
4754 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4756 /* Find the policy handle. Open a policy on it. */
4757 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4758 return NT_STATUS_INVALID_HANDLE;
4760 status = access_check_samr_function(acc_granted,
4761 STD_RIGHT_DELETE_ACCESS,
4762 "_samr_DeleteDomainGroup");
4763 if (!NT_STATUS_IS_OK(status)) {
4767 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4769 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4771 return NT_STATUS_NO_SUCH_GROUP;
4774 se_priv_copy( &se_rights, &se_add_users );
4775 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4777 /******** BEGIN SeAddUsers BLOCK *********/
4779 if ( can_add_accounts )
4782 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4784 if ( can_add_accounts )
4787 /******** END SeAddUsers BLOCK *********/
4789 if ( !NT_STATUS_IS_OK(status) ) {
4790 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4791 "entry for group %s: %s\n",
4792 sid_string_dbg(&group_sid),
4793 nt_errstr(status)));
4797 if (!close_policy_hnd(p, r->in.group_handle))
4798 return NT_STATUS_OBJECT_NAME_INVALID;
4800 force_flush_samr_cache(disp_info);
4802 return NT_STATUS_OK;
4805 /*********************************************************************
4806 _samr_DeleteDomAlias
4807 *********************************************************************/
4809 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4810 struct samr_DeleteDomAlias *r)
4815 bool can_add_accounts;
4817 DISP_INFO *disp_info = NULL;
4819 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4821 /* Find the policy handle. Open a policy on it. */
4822 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4823 return NT_STATUS_INVALID_HANDLE;
4825 /* copy the handle to the outgoing reply */
4827 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4829 status = access_check_samr_function(acc_granted,
4830 STD_RIGHT_DELETE_ACCESS,
4831 "_samr_DeleteDomAlias");
4832 if (!NT_STATUS_IS_OK(status)) {
4836 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4838 /* Don't let Windows delete builtin groups */
4840 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4841 return NT_STATUS_SPECIAL_ACCOUNT;
4844 if (!sid_check_is_in_our_domain(&alias_sid))
4845 return NT_STATUS_NO_SUCH_ALIAS;
4847 DEBUG(10, ("lookup on Local SID\n"));
4849 se_priv_copy( &se_rights, &se_add_users );
4850 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4852 /******** BEGIN SeAddUsers BLOCK *********/
4854 if ( can_add_accounts )
4857 /* Have passdb delete the alias */
4858 status = pdb_delete_alias(&alias_sid);
4860 if ( can_add_accounts )
4863 /******** END SeAddUsers BLOCK *********/
4865 if ( !NT_STATUS_IS_OK(status))
4868 if (!close_policy_hnd(p, r->in.alias_handle))
4869 return NT_STATUS_OBJECT_NAME_INVALID;
4871 force_flush_samr_cache(disp_info);
4873 return NT_STATUS_OK;
4876 /*********************************************************************
4877 _samr_CreateDomainGroup
4878 *********************************************************************/
4880 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4881 struct samr_CreateDomainGroup *r)
4888 struct samr_info *info;
4891 bool can_add_accounts;
4892 DISP_INFO *disp_info = NULL;
4894 /* Find the policy handle. Open a policy on it. */
4895 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4896 return NT_STATUS_INVALID_HANDLE;
4898 status = access_check_samr_function(acc_granted,
4899 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
4900 "_samr_CreateDomainGroup");
4901 if (!NT_STATUS_IS_OK(status)) {
4905 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4906 return NT_STATUS_ACCESS_DENIED;
4908 name = r->in.name->string;
4910 return NT_STATUS_NO_MEMORY;
4913 status = can_create(p->mem_ctx, name);
4914 if (!NT_STATUS_IS_OK(status)) {
4918 se_priv_copy( &se_rights, &se_add_users );
4919 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4921 /******** BEGIN SeAddUsers BLOCK *********/
4923 if ( can_add_accounts )
4926 /* check that we successfully create the UNIX group */
4928 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4930 if ( can_add_accounts )
4933 /******** END SeAddUsers BLOCK *********/
4935 /* check if we should bail out here */
4937 if ( !NT_STATUS_IS_OK(status) )
4940 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
4942 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
4943 return NT_STATUS_NO_MEMORY;
4945 /* they created it; let the user do what he wants with it */
4947 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
4949 /* get a (unique) handle. open a policy on it. */
4950 if (!create_policy_hnd(p, r->out.group_handle, info))
4951 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4953 force_flush_samr_cache(disp_info);
4955 return NT_STATUS_OK;
4958 /*********************************************************************
4959 _samr_CreateDomAlias
4960 *********************************************************************/
4962 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
4963 struct samr_CreateDomAlias *r)
4967 const char *name = NULL;
4968 struct samr_info *info;
4973 bool can_add_accounts;
4974 DISP_INFO *disp_info = NULL;
4976 /* Find the policy handle. Open a policy on it. */
4977 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4978 return NT_STATUS_INVALID_HANDLE;
4980 result = access_check_samr_function(acc_granted,
4981 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
4982 "_samr_CreateDomAlias");
4983 if (!NT_STATUS_IS_OK(result)) {
4987 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4988 return NT_STATUS_ACCESS_DENIED;
4990 name = r->in.alias_name->string;
4992 se_priv_copy( &se_rights, &se_add_users );
4993 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4995 result = can_create(p->mem_ctx, name);
4996 if (!NT_STATUS_IS_OK(result)) {
5000 /******** BEGIN SeAddUsers BLOCK *********/
5002 if ( can_add_accounts )
5005 /* Have passdb create the alias */
5006 result = pdb_create_alias(name, r->out.rid);
5008 if ( can_add_accounts )
5011 /******** END SeAddUsers BLOCK *********/
5013 if (!NT_STATUS_IS_OK(result)) {
5014 DEBUG(10, ("pdb_create_alias failed: %s\n",
5015 nt_errstr(result)));
5019 sid_copy(&info_sid, get_global_sam_sid());
5020 sid_append_rid(&info_sid, *r->out.rid);
5022 if (!sid_to_gid(&info_sid, &gid)) {
5023 DEBUG(10, ("Could not find alias just created\n"));
5024 return NT_STATUS_ACCESS_DENIED;
5027 /* check if the group has been successfully created */
5028 if ( getgrgid(gid) == NULL ) {
5029 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5031 return NT_STATUS_ACCESS_DENIED;
5034 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5035 return NT_STATUS_NO_MEMORY;
5037 /* they created it; let the user do what he wants with it */
5039 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5041 /* get a (unique) handle. open a policy on it. */
5042 if (!create_policy_hnd(p, r->out.alias_handle, info))
5043 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5045 force_flush_samr_cache(disp_info);
5047 return NT_STATUS_OK;
5050 /*********************************************************************
5051 _samr_QueryGroupInfo
5052 *********************************************************************/
5054 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5055 struct samr_QueryGroupInfo *r)
5060 union samr_GroupInfo *info = NULL;
5063 uint32_t attributes = SE_GROUP_MANDATORY |
5064 SE_GROUP_ENABLED_BY_DEFAULT |
5066 const char *group_name = NULL;
5067 const char *group_description = NULL;
5069 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5070 return NT_STATUS_INVALID_HANDLE;
5072 status = access_check_samr_function(acc_granted,
5073 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5074 "_samr_QueryGroupInfo");
5075 if (!NT_STATUS_IS_OK(status)) {
5080 ret = get_domain_group_from_sid(group_sid, &map);
5083 return NT_STATUS_INVALID_HANDLE;
5085 /* FIXME: map contains fstrings */
5086 group_name = talloc_strdup(r, map.nt_name);
5087 group_description = talloc_strdup(r, map.comment);
5089 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5091 return NT_STATUS_NO_MEMORY;
5094 switch (r->in.level) {
5100 status = pdb_enum_group_members(
5101 p->mem_ctx, &group_sid, &members, &num_members);
5104 if (!NT_STATUS_IS_OK(status)) {
5108 info->all.name.string = group_name;
5109 info->all.attributes = attributes;
5110 info->all.num_members = num_members;
5111 info->all.description.string = group_description;
5115 info->name.string = group_name;
5118 info->attributes.attributes = attributes;
5121 info->description.string = group_description;
5131 status = pdb_enum_group_members(
5132 p->mem_ctx, &group_sid, &members, &num_members);
5135 if (!NT_STATUS_IS_OK(status)) {
5139 info->all2.name.string = group_name;
5140 info->all2.attributes = attributes;
5141 info->all2.num_members = 0; /* num_members - in w2k3 this is always 0 */
5142 info->all2.description.string = group_description;
5147 return NT_STATUS_INVALID_INFO_CLASS;
5150 *r->out.info = info;
5152 return NT_STATUS_OK;
5155 /*********************************************************************
5157 *********************************************************************/
5159 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5160 struct samr_SetGroupInfo *r)
5167 bool can_mod_accounts;
5168 DISP_INFO *disp_info = NULL;
5170 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5171 return NT_STATUS_INVALID_HANDLE;
5173 status = access_check_samr_function(acc_granted,
5174 SAMR_GROUP_ACCESS_SET_INFO,
5175 "_samr_SetGroupInfo");
5176 if (!NT_STATUS_IS_OK(status)) {
5181 ret = get_domain_group_from_sid(group_sid, &map);
5184 return NT_STATUS_NO_SUCH_GROUP;
5186 switch (r->in.level) {
5188 fstrcpy(map.comment, r->in.info->all.description.string);
5191 /* group rename is not supported yet */
5192 return NT_STATUS_NOT_SUPPORTED;
5194 fstrcpy(map.comment, r->in.info->description.string);
5197 return NT_STATUS_INVALID_INFO_CLASS;
5200 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5202 /******** BEGIN SeAddUsers BLOCK *********/
5204 if ( can_mod_accounts )
5207 status = pdb_update_group_mapping_entry(&map);
5209 if ( can_mod_accounts )
5212 /******** End SeAddUsers BLOCK *********/
5214 if (NT_STATUS_IS_OK(status)) {
5215 force_flush_samr_cache(disp_info);
5221 /*********************************************************************
5223 *********************************************************************/
5225 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5226 struct samr_SetAliasInfo *r)
5229 struct acct_info info;
5231 bool can_mod_accounts;
5233 DISP_INFO *disp_info = NULL;
5235 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
5236 return NT_STATUS_INVALID_HANDLE;
5238 status = access_check_samr_function(acc_granted,
5239 SAMR_ALIAS_ACCESS_SET_INFO,
5240 "_samr_SetAliasInfo");
5241 if (!NT_STATUS_IS_OK(status)) {
5245 /* get the current group information */
5248 status = pdb_get_aliasinfo( &group_sid, &info );
5251 if ( !NT_STATUS_IS_OK(status))
5254 switch (r->in.level) {
5259 /* We currently do not support renaming groups in the
5260 the BUILTIN domain. Refer to util_builtin.c to understand
5261 why. The eventually needs to be fixed to be like Windows
5262 where you can rename builtin groups, just not delete them */
5264 if ( sid_check_is_in_builtin( &group_sid ) ) {
5265 return NT_STATUS_SPECIAL_ACCOUNT;
5268 /* There has to be a valid name (and it has to be different) */
5270 if ( !r->in.info->name.string )
5271 return NT_STATUS_INVALID_PARAMETER;
5273 /* If the name is the same just reply "ok". Yes this
5274 doesn't allow you to change the case of a group name. */
5276 if ( strequal( r->in.info->name.string, info.acct_name ) )
5277 return NT_STATUS_OK;
5279 fstrcpy( info.acct_name, r->in.info->name.string);
5281 /* make sure the name doesn't already exist as a user
5284 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
5285 status = can_create( p->mem_ctx, group_name );
5286 if ( !NT_STATUS_IS_OK( status ) )
5290 case ALIASINFODESCRIPTION:
5291 if (r->in.info->description.string) {
5292 fstrcpy(info.acct_desc,
5293 r->in.info->description.string);
5295 fstrcpy( info.acct_desc, "" );
5299 return NT_STATUS_INVALID_INFO_CLASS;
5302 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5304 /******** BEGIN SeAddUsers BLOCK *********/
5306 if ( can_mod_accounts )
5309 status = pdb_set_aliasinfo( &group_sid, &info );
5311 if ( can_mod_accounts )
5314 /******** End SeAddUsers BLOCK *********/
5316 if (NT_STATUS_IS_OK(status))
5317 force_flush_samr_cache(disp_info);
5322 /****************************************************************
5324 ****************************************************************/
5326 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
5327 struct samr_GetDomPwInfo *r)
5329 uint32_t min_password_length = 0;
5330 uint32_t password_properties = 0;
5332 /* Perform access check. Since this rpc does not require a
5333 policy handle it will not be caught by the access checks on
5334 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5336 if (!pipe_access_check(p)) {
5337 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5338 return NT_STATUS_ACCESS_DENIED;
5342 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
5343 &min_password_length);
5344 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
5345 &password_properties);
5348 if (lp_check_password_script() && *lp_check_password_script()) {
5349 password_properties |= DOMAIN_PASSWORD_COMPLEX;
5352 r->out.info->min_password_length = min_password_length;
5353 r->out.info->password_properties = password_properties;
5355 return NT_STATUS_OK;
5358 /*********************************************************************
5360 *********************************************************************/
5362 NTSTATUS _samr_OpenGroup(pipes_struct *p,
5363 struct samr_OpenGroup *r)
5369 struct samr_info *info;
5370 SEC_DESC *psd = NULL;
5372 uint32 des_access = r->in.access_mask;
5379 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
5380 return NT_STATUS_INVALID_HANDLE;
5382 status = access_check_samr_function(acc_granted,
5383 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5386 if ( !NT_STATUS_IS_OK(status) )
5389 /*check if access can be granted as requested by client. */
5390 map_max_allowed_access(p->server_info->ptok, &des_access);
5392 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
5393 se_map_generic(&des_access,&grp_generic_mapping);
5395 se_priv_copy( &se_rights, &se_add_users );
5397 status = access_check_samr_object(psd, p->server_info->ptok,
5398 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
5399 &acc_granted, "_samr_OpenGroup");
5401 if ( !NT_STATUS_IS_OK(status) )
5404 /* this should not be hard-coded like this */
5406 if (!sid_equal(&sid, get_global_sam_sid()))
5407 return NT_STATUS_ACCESS_DENIED;
5409 sid_copy(&info_sid, get_global_sam_sid());
5410 sid_append_rid(&info_sid, r->in.rid);
5411 sid_to_fstring(sid_string, &info_sid);
5413 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5414 return NT_STATUS_NO_MEMORY;
5416 info->acc_granted = acc_granted;
5418 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
5420 /* check if that group really exists */
5422 ret = get_domain_group_from_sid(info->sid, &map);
5425 return NT_STATUS_NO_SUCH_GROUP;
5427 /* get a (unique) handle. open a policy on it. */
5428 if (!create_policy_hnd(p, r->out.group_handle, info))
5429 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5431 return NT_STATUS_OK;
5434 /*********************************************************************
5435 _samr_RemoveMemberFromForeignDomain
5436 *********************************************************************/
5438 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5439 struct samr_RemoveMemberFromForeignDomain *r)
5441 DOM_SID delete_sid, domain_sid;
5444 DISP_INFO *disp_info = NULL;
5446 sid_copy( &delete_sid, r->in.sid );
5448 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5449 sid_string_dbg(&delete_sid)));
5451 /* Find the policy handle. Open a policy on it. */
5453 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
5454 &acc_granted, &disp_info))
5455 return NT_STATUS_INVALID_HANDLE;
5457 result = access_check_samr_function(acc_granted,
5458 STD_RIGHT_DELETE_ACCESS,
5459 "_samr_RemoveMemberFromForeignDomain");
5461 if (!NT_STATUS_IS_OK(result))
5464 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5465 sid_string_dbg(&domain_sid)));
5467 /* we can only delete a user from a group since we don't have
5468 nested groups anyways. So in the latter case, just say OK */
5470 /* TODO: The above comment nowadays is bogus. Since we have nested
5471 * groups now, and aliases members are never reported out of the unix
5472 * group membership, the "just say OK" makes this call a no-op. For
5473 * us. This needs fixing however. */
5475 /* I've only ever seen this in the wild when deleting a user from
5476 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5477 * is the user about to be deleted. I very much suspect this is the
5478 * only application of this call. To verify this, let people report
5481 if (!sid_check_is_builtin(&domain_sid)) {
5482 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5483 "global_sam_sid() = %s\n",
5484 sid_string_dbg(&domain_sid),
5485 sid_string_dbg(get_global_sam_sid())));
5486 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5487 return NT_STATUS_OK;
5490 force_flush_samr_cache(disp_info);
5492 result = NT_STATUS_OK;
5497 /*******************************************************************
5498 _samr_QueryDomainInfo2
5499 ********************************************************************/
5501 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5502 struct samr_QueryDomainInfo2 *r)
5504 struct samr_QueryDomainInfo q;
5506 q.in.domain_handle = r->in.domain_handle;
5507 q.in.level = r->in.level;
5509 q.out.info = r->out.info;
5511 return _samr_QueryDomainInfo(p, &q);
5514 /*******************************************************************
5516 ********************************************************************/
5518 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5519 struct samr_SetDomainInfo *r)
5521 struct samr_info *info = NULL;
5522 time_t u_expire, u_min_age;
5524 time_t u_lock_duration, u_reset_time;
5527 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5529 /* find the policy handle. open a policy on it. */
5530 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5531 return NT_STATUS_INVALID_HANDLE;
5533 /* We do have different access bits for info
5534 * levels here, but we're really just looking for
5535 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5536 * this maps to different specific bits. So
5537 * assume if we have SAMR_DOMAIN_ACCESS_SET_INFO_1
5540 result = access_check_samr_function(info->acc_granted,
5541 SAMR_DOMAIN_ACCESS_SET_INFO_1,
5542 "_samr_SetDomainInfo");
5544 if (!NT_STATUS_IS_OK(result))
5547 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
5549 switch (r->in.level) {
5551 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
5552 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
5553 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
5554 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
5555 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
5556 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5557 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5562 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
5563 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5572 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
5573 if (u_lock_duration != -1)
5574 u_lock_duration /= 60;
5576 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
5578 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5579 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5580 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
5583 return NT_STATUS_INVALID_INFO_CLASS;
5586 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5588 return NT_STATUS_OK;
5591 /****************************************************************
5592 _samr_GetDisplayEnumerationIndex
5593 ****************************************************************/
5595 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5596 struct samr_GetDisplayEnumerationIndex *r)
5598 struct samr_info *info = NULL;
5599 uint32_t max_entries = (uint32_t) -1;
5600 uint32_t enum_context = 0;
5602 uint32_t num_account = 0;
5603 struct samr_displayentry *entries = NULL;
5606 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
5608 /* find the policy handle. open a policy on it. */
5609 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
5610 return NT_STATUS_INVALID_HANDLE;
5613 status = access_check_samr_function(info->acc_granted,
5614 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
5615 "_samr_GetDisplayEnumerationIndex");
5616 if (!NT_STATUS_IS_OK(status)) {
5620 if ((r->in.level < 1) || (r->in.level > 3)) {
5621 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5622 "Unknown info level (%u)\n",
5624 return NT_STATUS_INVALID_INFO_CLASS;
5629 /* The following done as ROOT. Don't return without unbecome_root(). */
5631 switch (r->in.level) {
5633 if (info->disp_info->users == NULL) {
5634 info->disp_info->users = pdb_search_users(ACB_NORMAL);
5635 if (info->disp_info->users == NULL) {
5637 return NT_STATUS_ACCESS_DENIED;
5639 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5640 "starting user enumeration at index %u\n",
5641 (unsigned int)enum_context));
5643 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5644 "using cached user enumeration at index %u\n",
5645 (unsigned int)enum_context));
5647 num_account = pdb_search_entries(info->disp_info->users,
5648 enum_context, max_entries,
5652 if (info->disp_info->machines == NULL) {
5653 info->disp_info->machines =
5654 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
5655 if (info->disp_info->machines == NULL) {
5657 return NT_STATUS_ACCESS_DENIED;
5659 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5660 "starting machine enumeration at index %u\n",
5661 (unsigned int)enum_context));
5663 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5664 "using cached machine enumeration at index %u\n",
5665 (unsigned int)enum_context));
5667 num_account = pdb_search_entries(info->disp_info->machines,
5668 enum_context, max_entries,
5672 if (info->disp_info->groups == NULL) {
5673 info->disp_info->groups = pdb_search_groups();
5674 if (info->disp_info->groups == NULL) {
5676 return NT_STATUS_ACCESS_DENIED;
5678 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5679 "starting group enumeration at index %u\n",
5680 (unsigned int)enum_context));
5682 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5683 "using cached group enumeration at index %u\n",
5684 (unsigned int)enum_context));
5686 num_account = pdb_search_entries(info->disp_info->groups,
5687 enum_context, max_entries,
5692 smb_panic("info class changed");
5698 /* Ensure we cache this enumeration. */
5699 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
5701 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5702 r->in.name->string));
5704 for (i=0; i<num_account; i++) {
5705 if (strequal(entries[i].account_name, r->in.name->string)) {
5706 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5707 "found %s at idx %d\n",
5708 r->in.name->string, i));
5710 return NT_STATUS_OK;
5714 /* assuming account_name lives at the very end */
5715 *r->out.idx = num_account;
5717 return NT_STATUS_NO_MORE_ENTRIES;
5720 /****************************************************************
5721 _samr_GetDisplayEnumerationIndex2
5722 ****************************************************************/
5724 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5725 struct samr_GetDisplayEnumerationIndex2 *r)
5727 struct samr_GetDisplayEnumerationIndex q;
5729 q.in.domain_handle = r->in.domain_handle;
5730 q.in.level = r->in.level;
5731 q.in.name = r->in.name;
5733 q.out.idx = r->out.idx;
5735 return _samr_GetDisplayEnumerationIndex(p, &q);
5738 /****************************************************************
5739 ****************************************************************/
5741 NTSTATUS _samr_Shutdown(pipes_struct *p,
5742 struct samr_Shutdown *r)
5744 p->rng_fault_state = true;
5745 return NT_STATUS_NOT_IMPLEMENTED;
5748 /****************************************************************
5749 ****************************************************************/
5751 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5752 struct samr_SetMemberAttributesOfGroup *r)
5754 p->rng_fault_state = true;
5755 return NT_STATUS_NOT_IMPLEMENTED;
5758 /****************************************************************
5759 ****************************************************************/
5761 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5762 struct samr_ChangePasswordUser *r)
5764 p->rng_fault_state = true;
5765 return NT_STATUS_NOT_IMPLEMENTED;
5768 /****************************************************************
5769 ****************************************************************/
5771 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5772 struct samr_TestPrivateFunctionsDomain *r)
5774 p->rng_fault_state = true;
5775 return NT_STATUS_NOT_IMPLEMENTED;
5778 /****************************************************************
5779 ****************************************************************/
5781 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5782 struct samr_TestPrivateFunctionsUser *r)
5784 p->rng_fault_state = true;
5785 return NT_STATUS_NOT_IMPLEMENTED;
5788 /****************************************************************
5789 ****************************************************************/
5791 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5792 struct samr_AddMultipleMembersToAlias *r)
5794 p->rng_fault_state = true;
5795 return NT_STATUS_NOT_IMPLEMENTED;
5798 /****************************************************************
5799 ****************************************************************/
5801 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5802 struct samr_RemoveMultipleMembersFromAlias *r)
5804 p->rng_fault_state = true;
5805 return NT_STATUS_NOT_IMPLEMENTED;
5808 /****************************************************************
5809 ****************************************************************/
5811 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5812 struct samr_OemChangePasswordUser2 *r)
5814 p->rng_fault_state = true;
5815 return NT_STATUS_NOT_IMPLEMENTED;
5818 /****************************************************************
5819 ****************************************************************/
5821 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5822 struct samr_SetBootKeyInformation *r)
5824 p->rng_fault_state = true;
5825 return NT_STATUS_NOT_IMPLEMENTED;
5828 /****************************************************************
5829 ****************************************************************/
5831 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5832 struct samr_GetBootKeyInformation *r)
5834 p->rng_fault_state = true;
5835 return NT_STATUS_NOT_IMPLEMENTED;
5838 /****************************************************************
5839 ****************************************************************/
5841 NTSTATUS _samr_Connect3(pipes_struct *p,
5842 struct samr_Connect3 *r)
5844 p->rng_fault_state = true;
5845 return NT_STATUS_NOT_IMPLEMENTED;
5848 /****************************************************************
5849 ****************************************************************/
5851 NTSTATUS _samr_RidToSid(pipes_struct *p,
5852 struct samr_RidToSid *r)
5854 p->rng_fault_state = true;
5855 return NT_STATUS_NOT_IMPLEMENTED;
5858 /****************************************************************
5859 ****************************************************************/
5861 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5862 struct samr_SetDsrmPassword *r)
5864 p->rng_fault_state = true;
5865 return NT_STATUS_NOT_IMPLEMENTED;
5868 /****************************************************************
5869 ****************************************************************/
5871 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5872 struct samr_ValidatePassword *r)
5874 p->rng_fault_state = true;
5875 return NT_STATUS_NOT_IMPLEMENTED;