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;
1923 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1925 fstrcpy(user_name, r->in.account->string);
1926 if (r->in.server && r->in.server->string) {
1927 wks = r->in.server->string;
1930 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
1933 * Pass the user through the NT -> unix user mapping
1937 (void)map_username(user_name);
1940 * UNIX username case mangling not required, pass_oem_change
1941 * is case insensitive.
1944 status = pass_oem_change(user_name,
1945 r->in.lm_password->data,
1946 r->in.lm_verifier->hash,
1947 r->in.nt_password->data,
1948 r->in.nt_verifier->hash,
1951 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
1952 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1954 time_t u_expire, u_min_age;
1955 uint32 account_policy_temp;
1957 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
1959 return NT_STATUS_NO_MEMORY;
1962 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
1964 return NT_STATUS_NO_MEMORY;
1971 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &tmp);
1972 dominfo->min_password_length = tmp;
1974 pdb_get_account_policy(AP_PASSWORD_HISTORY, &tmp);
1975 dominfo->password_history_length = tmp;
1977 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
1978 &dominfo->password_properties);
1980 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1981 u_expire = account_policy_temp;
1983 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1984 u_min_age = account_policy_temp;
1990 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
1991 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
1993 if (lp_check_password_script() && *lp_check_password_script()) {
1994 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
1997 reject->reason = reject_reason;
1999 *r->out.dominfo = dominfo;
2000 *r->out.reject = reject;
2003 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2008 /*******************************************************************
2009 makes a SAMR_R_LOOKUP_RIDS structure.
2010 ********************************************************************/
2012 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2014 struct lsa_String **lsa_name_array_p)
2016 struct lsa_String *lsa_name_array = NULL;
2019 *lsa_name_array_p = NULL;
2021 if (num_names != 0) {
2022 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2023 if (!lsa_name_array) {
2028 for (i = 0; i < num_names; i++) {
2029 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2030 init_lsa_String(&lsa_name_array[i], names[i]);
2033 *lsa_name_array_p = lsa_name_array;
2038 /*******************************************************************
2040 ********************************************************************/
2042 NTSTATUS _samr_LookupRids(pipes_struct *p,
2043 struct samr_LookupRids *r)
2047 enum lsa_SidType *attrs = NULL;
2048 uint32 *wire_attrs = NULL;
2050 int num_rids = (int)r->in.num_rids;
2053 struct lsa_Strings names_array;
2054 struct samr_Ids types_array;
2055 struct lsa_String *lsa_names = NULL;
2057 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2059 /* find the policy handle. open a policy on it. */
2060 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2061 return NT_STATUS_INVALID_HANDLE;
2063 status = access_check_samr_function(acc_granted,
2064 0, /* Don't know the acc_bits yet */
2065 "_samr_LookupRids");
2066 if (!NT_STATUS_IS_OK(status)) {
2070 if (num_rids > 1000) {
2071 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2072 "to samba4 idl this is not possible\n", num_rids));
2073 return NT_STATUS_UNSUCCESSFUL;
2077 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2078 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2079 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2081 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2082 return NT_STATUS_NO_MEMORY;
2089 become_root(); /* lookup_sid can require root privs */
2090 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2094 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2095 status = NT_STATUS_OK;
2098 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2100 return NT_STATUS_NO_MEMORY;
2103 /* Convert from enum lsa_SidType to uint32 for wire format. */
2104 for (i = 0; i < num_rids; i++) {
2105 wire_attrs[i] = (uint32)attrs[i];
2108 names_array.count = num_rids;
2109 names_array.names = lsa_names;
2111 types_array.count = num_rids;
2112 types_array.ids = wire_attrs;
2114 *r->out.names = names_array;
2115 *r->out.types = types_array;
2117 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2122 /*******************************************************************
2124 ********************************************************************/
2126 NTSTATUS _samr_OpenUser(pipes_struct *p,
2127 struct samr_OpenUser *r)
2129 struct samu *sampass=NULL;
2131 POLICY_HND domain_pol = *r->in.domain_handle;
2132 POLICY_HND *user_pol = r->out.user_handle;
2133 struct samr_info *info = NULL;
2134 SEC_DESC *psd = NULL;
2136 uint32 des_access = r->in.access_mask;
2142 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2144 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
2145 return NT_STATUS_INVALID_HANDLE;
2147 nt_status = access_check_samr_function(acc_granted,
2148 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2151 if ( !NT_STATUS_IS_OK(nt_status) )
2154 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2155 return NT_STATUS_NO_MEMORY;
2158 /* append the user's RID to it */
2160 if (!sid_append_rid(&sid, r->in.rid))
2161 return NT_STATUS_NO_SUCH_USER;
2163 /* check if access can be granted as requested by client. */
2165 map_max_allowed_access(p->server_info->ptok, &des_access);
2167 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2168 se_map_generic(&des_access, &usr_generic_mapping);
2170 se_priv_copy( &se_rights, &se_machine_account );
2171 se_priv_add( &se_rights, &se_add_users );
2173 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2174 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2175 &acc_granted, "_samr_OpenUser");
2177 if ( !NT_STATUS_IS_OK(nt_status) )
2181 ret=pdb_getsampwsid(sampass, &sid);
2184 /* check that the SID exists in our domain. */
2186 return NT_STATUS_NO_SUCH_USER;
2189 TALLOC_FREE(sampass);
2191 /* associate the user's SID and access bits with the new handle. */
2192 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
2193 return NT_STATUS_NO_MEMORY;
2194 info->acc_granted = acc_granted;
2196 /* get a (unique) handle. open a policy on it. */
2197 if (!create_policy_hnd(p, user_pol, info))
2198 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2200 return NT_STATUS_OK;
2203 /*************************************************************************
2204 *************************************************************************/
2206 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2208 struct lsa_BinaryString **_r)
2210 struct lsa_BinaryString *r;
2213 return NT_STATUS_INVALID_PARAMETER;
2216 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2218 return NT_STATUS_NO_MEMORY;
2221 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2223 return NT_STATUS_NO_MEMORY;
2225 memcpy(r->array, blob->data, blob->length);
2226 r->size = blob->length;
2227 r->length = blob->length;
2230 return NT_STATUS_NO_MEMORY;
2235 return NT_STATUS_OK;
2238 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2239 struct samr_UserInfo5 *r,
2241 DOM_SID *domain_sid)
2243 const DOM_SID *sid_user, *sid_group;
2244 uint32_t rid, primary_gid;
2246 sid_user = pdb_get_user_sid(pw);
2248 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2249 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2250 "the domain sid %s. Failing operation.\n",
2251 pdb_get_username(pw), sid_string_dbg(sid_user),
2252 sid_string_dbg(domain_sid)));
2253 return NT_STATUS_UNSUCCESSFUL;
2257 sid_group = pdb_get_group_sid(pw);
2260 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2261 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2262 "which conflicts with the domain sid %s. Failing operation.\n",
2263 pdb_get_username(pw), sid_string_dbg(sid_group),
2264 sid_string_dbg(domain_sid)));
2265 return NT_STATUS_UNSUCCESSFUL;
2268 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2269 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2270 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2271 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2273 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2274 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2275 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2276 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2277 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2278 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2279 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2280 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2282 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2284 r->primary_gid = primary_gid;
2285 r->acct_flags = pdb_get_acct_ctrl(pw);
2286 r->bad_password_count = pdb_get_bad_password_count(pw);
2287 r->logon_count = pdb_get_logon_count(pw);
2289 return NT_STATUS_OK;
2292 /*************************************************************************
2293 get_user_info_7. Safe. Only gives out account_name.
2294 *************************************************************************/
2296 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2297 struct samr_UserInfo7 *r,
2298 struct samu *smbpass)
2300 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2301 if (!r->account_name.string) {
2302 return NT_STATUS_NO_MEMORY;
2305 return NT_STATUS_OK;
2308 /*************************************************************************
2309 get_user_info_9. Only gives out primary group SID.
2310 *************************************************************************/
2312 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2313 struct samr_UserInfo9 *r,
2314 struct samu *smbpass)
2316 r->primary_gid = pdb_get_group_rid(smbpass);
2318 return NT_STATUS_OK;
2321 /*************************************************************************
2322 get_user_info_16. Safe. Only gives out acb bits.
2323 *************************************************************************/
2325 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2326 struct samr_UserInfo16 *r,
2327 struct samu *smbpass)
2329 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2331 return NT_STATUS_OK;
2334 /*************************************************************************
2335 get_user_info_18. OK - this is the killer as it gives out password info.
2336 Ensure that this is only allowed on an encrypted connection with a root
2338 *************************************************************************/
2340 static NTSTATUS get_user_info_18(pipes_struct *p,
2341 TALLOC_CTX *mem_ctx,
2342 struct samr_UserInfo18 *r,
2345 struct samu *smbpass=NULL;
2350 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2351 return NT_STATUS_ACCESS_DENIED;
2354 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2355 return NT_STATUS_ACCESS_DENIED;
2359 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2362 if ( !(smbpass = samu_new( mem_ctx )) ) {
2363 return NT_STATUS_NO_MEMORY;
2366 ret = pdb_getsampwsid(smbpass, user_sid);
2369 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2370 TALLOC_FREE(smbpass);
2371 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2374 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2376 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2377 TALLOC_FREE(smbpass);
2378 return NT_STATUS_ACCOUNT_DISABLED;
2381 r->lm_pwd_active = true;
2382 r->nt_pwd_active = true;
2383 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2384 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2385 r->password_expired = 0; /* FIXME */
2387 TALLOC_FREE(smbpass);
2389 return NT_STATUS_OK;
2392 /*************************************************************************
2394 *************************************************************************/
2396 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2397 struct samr_UserInfo20 *r,
2398 struct samu *sampass)
2400 const char *munged_dial = NULL;
2403 struct lsa_BinaryString *parameters = NULL;
2407 munged_dial = pdb_get_munged_dial(sampass);
2409 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2410 munged_dial, (int)strlen(munged_dial)));
2413 blob = base64_decode_data_blob(munged_dial);
2415 blob = data_blob_string_const_null("");
2418 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2419 data_blob_free(&blob);
2420 if (!NT_STATUS_IS_OK(status)) {
2424 r->parameters = *parameters;
2426 return NT_STATUS_OK;
2430 /*************************************************************************
2432 *************************************************************************/
2434 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2435 struct samr_UserInfo21 *r,
2437 DOM_SID *domain_sid)
2440 const DOM_SID *sid_user, *sid_group;
2441 uint32_t rid, primary_gid;
2442 NTTIME force_password_change;
2443 time_t must_change_time;
2444 struct lsa_BinaryString *parameters = NULL;
2445 const char *munged_dial = NULL;
2450 sid_user = pdb_get_user_sid(pw);
2452 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2453 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2454 "the domain sid %s. Failing operation.\n",
2455 pdb_get_username(pw), sid_string_dbg(sid_user),
2456 sid_string_dbg(domain_sid)));
2457 return NT_STATUS_UNSUCCESSFUL;
2461 sid_group = pdb_get_group_sid(pw);
2464 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2465 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2466 "which conflicts with the domain sid %s. Failing operation.\n",
2467 pdb_get_username(pw), sid_string_dbg(sid_group),
2468 sid_string_dbg(domain_sid)));
2469 return NT_STATUS_UNSUCCESSFUL;
2472 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2473 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2474 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2475 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2476 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2478 must_change_time = pdb_get_pass_must_change_time(pw);
2479 if (must_change_time == get_time_t_max()) {
2480 unix_to_nt_time_abs(&force_password_change, must_change_time);
2482 unix_to_nt_time(&force_password_change, must_change_time);
2485 munged_dial = pdb_get_munged_dial(pw);
2487 blob = base64_decode_data_blob(munged_dial);
2489 blob = data_blob_string_const_null("");
2492 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2493 data_blob_free(&blob);
2494 if (!NT_STATUS_IS_OK(status)) {
2498 r->force_password_change = force_password_change;
2500 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2501 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2502 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2503 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2504 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2505 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2506 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2507 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2508 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2510 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2511 r->parameters = *parameters;
2513 r->primary_gid = primary_gid;
2514 r->acct_flags = pdb_get_acct_ctrl(pw);
2515 r->bad_password_count = pdb_get_bad_password_count(pw);
2516 r->logon_count = pdb_get_logon_count(pw);
2517 r->fields_present = pdb_build_fields_present(pw);
2518 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2519 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2520 r->country_code = 0;
2522 r->lm_password_set = 0;
2523 r->nt_password_set = 0;
2528 Look at a user on a real NT4 PDC with usrmgr, press
2529 'ok'. Then you will see that fields_present is set to
2530 0x08f827fa. Look at the user immediately after that again,
2531 and you will see that 0x00fffff is returned. This solves
2532 the problem that you get access denied after having looked
2540 return NT_STATUS_OK;
2543 /*******************************************************************
2545 ********************************************************************/
2547 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2548 struct samr_QueryUserInfo *r)
2551 union samr_UserInfo *user_info = NULL;
2552 struct samr_info *info = NULL;
2556 struct samu *pwd = NULL;
2558 /* search for the handle */
2559 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
2560 return NT_STATUS_INVALID_HANDLE;
2562 status = access_check_samr_function(info->acc_granted,
2563 SAMR_USER_ACCESS_GET_ATTRIBUTES,
2564 "_samr_QueryUserInfo");
2565 if (!NT_STATUS_IS_OK(status)) {
2569 domain_sid = info->sid;
2571 sid_split_rid(&domain_sid, &rid);
2573 if (!sid_check_is_in_our_domain(&info->sid))
2574 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2576 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2577 sid_string_dbg(&info->sid)));
2579 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2581 return NT_STATUS_NO_MEMORY;
2584 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2586 if (!(pwd = samu_new(p->mem_ctx))) {
2587 return NT_STATUS_NO_MEMORY;
2591 ret = pdb_getsampwsid(pwd, &info->sid);
2595 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
2597 return NT_STATUS_NO_SUCH_USER;
2600 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2602 samr_clear_sam_passwd(pwd);
2604 switch (r->in.level) {
2606 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2609 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2612 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2615 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2618 /* level 18 is special */
2619 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
2622 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2625 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2628 status = NT_STATUS_INVALID_INFO_CLASS;
2634 *r->out.info = user_info;
2636 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2641 /****************************************************************
2642 ****************************************************************/
2644 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2645 struct samr_QueryUserInfo2 *r)
2647 struct samr_QueryUserInfo u;
2649 u.in.user_handle = r->in.user_handle;
2650 u.in.level = r->in.level;
2651 u.out.info = r->out.info;
2653 return _samr_QueryUserInfo(p, &u);
2656 /*******************************************************************
2657 _samr_GetGroupsForUser
2658 ********************************************************************/
2660 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2661 struct samr_GetGroupsForUser *r)
2663 struct samu *sam_pass=NULL;
2666 struct samr_RidWithAttribute dom_gid;
2667 struct samr_RidWithAttribute *gids = NULL;
2668 uint32 primary_group_rid;
2669 size_t num_groups = 0;
2675 bool success = False;
2677 struct samr_RidWithAttributeArray *rids = NULL;
2680 * from the SID in the request:
2681 * we should send back the list of DOMAIN GROUPS
2682 * the user is a member of
2684 * and only the DOMAIN GROUPS
2685 * no ALIASES !!! neither aliases of the domain
2686 * nor aliases of the builtin SID
2691 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2693 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
2695 return NT_STATUS_NO_MEMORY;
2698 /* find the policy handle. open a policy on it. */
2699 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
2700 return NT_STATUS_INVALID_HANDLE;
2702 result = access_check_samr_function(acc_granted,
2703 SAMR_USER_ACCESS_GET_GROUPS,
2704 "_samr_GetGroupsForUser");
2705 if (!NT_STATUS_IS_OK(result)) {
2709 if (!sid_check_is_in_our_domain(&sid))
2710 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2712 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2713 return NT_STATUS_NO_MEMORY;
2717 ret = pdb_getsampwsid(sam_pass, &sid);
2721 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2722 sid_string_dbg(&sid)));
2723 return NT_STATUS_NO_SUCH_USER;
2728 /* make both calls inside the root block */
2730 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2731 &sids, &unix_gids, &num_groups);
2732 if ( NT_STATUS_IS_OK(result) ) {
2733 success = sid_peek_check_rid(get_global_sam_sid(),
2734 pdb_get_group_sid(sam_pass),
2735 &primary_group_rid);
2739 if (!NT_STATUS_IS_OK(result)) {
2740 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2741 sid_string_dbg(&sid)));
2746 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2747 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2748 pdb_get_username(sam_pass)));
2749 TALLOC_FREE(sam_pass);
2750 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2756 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2758 dom_gid.rid = primary_group_rid;
2759 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2761 for (i=0; i<num_groups; i++) {
2763 if (!sid_peek_check_rid(get_global_sam_sid(),
2764 &(sids[i]), &dom_gid.rid)) {
2765 DEBUG(10, ("Found sid %s not in our domain\n",
2766 sid_string_dbg(&sids[i])));
2770 if (dom_gid.rid == primary_group_rid) {
2771 /* We added the primary group directly from the
2772 * sam_account. The other SIDs are unique from
2773 * enum_group_memberships */
2777 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2780 rids->count = num_gids;
2783 *r->out.rids = rids;
2785 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2790 /*******************************************************************
2791 _samr_QueryDomainInfo
2792 ********************************************************************/
2794 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
2795 struct samr_QueryDomainInfo *r)
2797 NTSTATUS status = NT_STATUS_OK;
2798 struct samr_info *info = NULL;
2799 union samr_DomainInfo *dom_info;
2800 time_t u_expire, u_min_age;
2802 time_t u_lock_duration, u_reset_time;
2805 uint32 account_policy_temp;
2810 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2812 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
2814 return NT_STATUS_NO_MEMORY;
2817 /* find the policy handle. open a policy on it. */
2818 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
2819 return NT_STATUS_INVALID_HANDLE;
2822 status = access_check_samr_function(info->acc_granted,
2823 SAMR_ACCESS_OPEN_DOMAIN,
2824 "_samr_QueryDomainInfo" );
2826 if ( !NT_STATUS_IS_OK(status) )
2829 switch (r->in.level) {
2836 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
2837 &account_policy_temp);
2838 dom_info->info1.min_password_length = account_policy_temp;
2840 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
2841 dom_info->info1.password_history_length = account_policy_temp;
2843 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2844 &dom_info->info1.password_properties);
2846 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2847 u_expire = account_policy_temp;
2849 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2850 u_min_age = account_policy_temp;
2856 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
2857 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
2859 if (lp_check_password_script() && *lp_check_password_script()) {
2860 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
2870 dom_info->general.num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2871 dom_info->general.num_groups = count_sam_groups(info->disp_info);
2872 dom_info->general.num_aliases = count_sam_aliases(info->disp_info);
2874 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
2876 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
2878 if (!pdb_get_seq_num(&seq_num))
2879 seq_num = time(NULL);
2885 server_role = ROLE_DOMAIN_PDC;
2886 if (lp_server_role() == ROLE_DOMAIN_BDC)
2887 server_role = ROLE_DOMAIN_BDC;
2889 dom_info->general.oem_information.string = lp_serverstring();
2890 dom_info->general.domain_name.string = lp_workgroup();
2891 dom_info->general.primary.string = global_myname();
2892 dom_info->general.sequence_num = seq_num;
2893 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
2894 dom_info->general.role = server_role;
2895 dom_info->general.unknown3 = 1;
2906 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2907 u_logout = (time_t)ul;
2914 unix_to_nt_time_abs(&dom_info->info3.force_logoff_time, u_logout);
2918 dom_info->oem.oem_information.string = lp_serverstring();
2921 dom_info->info5.domain_name.string = get_global_sam_name();
2924 /* NT returns its own name when a PDC. win2k and later
2925 * only the name of the PDC if itself is a BDC (samba4
2927 dom_info->info6.primary.string = global_myname();
2930 server_role = ROLE_DOMAIN_PDC;
2931 if (lp_server_role() == ROLE_DOMAIN_BDC)
2932 server_role = ROLE_DOMAIN_BDC;
2934 dom_info->info7.role = server_role;
2942 if (!pdb_get_seq_num(&seq_num)) {
2943 seq_num = time(NULL);
2950 dom_info->info8.sequence_num = seq_num;
2951 dom_info->info8.domain_create_time = 0;
2960 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
2961 u_lock_duration = account_policy_temp;
2962 if (u_lock_duration != -1) {
2963 u_lock_duration *= 60;
2966 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
2967 u_reset_time = account_policy_temp * 60;
2969 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
2970 &account_policy_temp);
2971 dom_info->info12.lockout_threshold = account_policy_temp;
2977 unix_to_nt_time_abs(&dom_info->info12.lockout_duration,
2979 unix_to_nt_time_abs(&dom_info->info12.lockout_window,
2984 return NT_STATUS_INVALID_INFO_CLASS;
2987 *r->out.info = dom_info;
2989 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2994 /* W2k3 seems to use the same check for all 3 objects that can be created via
2995 * SAMR, if you try to create for example "Dialup" as an alias it says
2996 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
2999 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
3001 enum lsa_SidType type;
3004 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
3007 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3008 * whether the name already exists */
3009 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3010 NULL, NULL, NULL, &type);
3014 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3015 return NT_STATUS_OK;
3018 DEBUG(5, ("trying to create %s, exists as %s\n",
3019 new_name, sid_type_lookup(type)));
3021 if (type == SID_NAME_DOM_GRP) {
3022 return NT_STATUS_GROUP_EXISTS;
3024 if (type == SID_NAME_ALIAS) {
3025 return NT_STATUS_ALIAS_EXISTS;
3028 /* Yes, the default is NT_STATUS_USER_EXISTS */
3029 return NT_STATUS_USER_EXISTS;
3032 /*******************************************************************
3034 ********************************************************************/
3036 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3037 struct samr_CreateUser2 *r)
3039 const char *account = NULL;
3041 POLICY_HND dom_pol = *r->in.domain_handle;
3042 uint32_t acb_info = r->in.acct_flags;
3043 POLICY_HND *user_pol = r->out.user_handle;
3044 struct samr_info *info = NULL;
3049 /* check this, when giving away 'add computer to domain' privs */
3050 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3051 bool can_add_account = False;
3053 DISP_INFO *disp_info = NULL;
3055 /* Get the domain SID stored in the domain policy */
3056 if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
3058 return NT_STATUS_INVALID_HANDLE;
3060 if (disp_info->builtin_domain) {
3061 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3062 return NT_STATUS_ACCESS_DENIED;
3065 nt_status = access_check_samr_function(acc_granted,
3066 SAMR_DOMAIN_ACCESS_CREATE_USER,
3067 "_samr_CreateUser2");
3068 if (!NT_STATUS_IS_OK(nt_status)) {
3072 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3073 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3074 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3075 this parameter is not an account type */
3076 return NT_STATUS_INVALID_PARAMETER;
3079 account = r->in.account_name->string;
3080 if (account == NULL) {
3081 return NT_STATUS_NO_MEMORY;
3084 nt_status = can_create(p->mem_ctx, account);
3085 if (!NT_STATUS_IS_OK(nt_status)) {
3089 /* determine which user right we need to check based on the acb_info */
3091 if ( acb_info & ACB_WSTRUST )
3093 se_priv_copy( &se_rights, &se_machine_account );
3094 can_add_account = user_has_privileges(
3095 p->server_info->ptok, &se_rights );
3097 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3098 account for domain trusts and changes the ACB flags later */
3099 else if ( acb_info & ACB_NORMAL &&
3100 (account[strlen(account)-1] != '$') )
3102 se_priv_copy( &se_rights, &se_add_users );
3103 can_add_account = user_has_privileges(
3104 p->server_info->ptok, &se_rights );
3106 else /* implicit assumption of a BDC or domain trust account here
3107 * (we already check the flags earlier) */
3109 if ( lp_enable_privileges() ) {
3110 /* only Domain Admins can add a BDC or domain trust */
3111 se_priv_copy( &se_rights, &se_priv_none );
3112 can_add_account = nt_token_check_domain_rid(
3113 p->server_info->ptok,
3114 DOMAIN_GROUP_RID_ADMINS );
3118 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3119 uidtoname(p->server_info->utok.uid),
3120 can_add_account ? "True":"False" ));
3122 /********** BEGIN Admin BLOCK **********/
3124 if ( can_add_account )
3127 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3130 if ( can_add_account )
3133 /********** END Admin BLOCK **********/
3135 /* now check for failure */
3137 if ( !NT_STATUS_IS_OK(nt_status) )
3140 /* Get the user's SID */
3142 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3144 map_max_allowed_access(p->server_info->ptok, &des_access);
3146 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3147 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3148 se_map_generic(&des_access, &usr_generic_mapping);
3150 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3151 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3152 &acc_granted, "_samr_CreateUser2");
3154 if ( !NT_STATUS_IS_OK(nt_status) ) {
3158 /* associate the user's SID with the new handle. */
3159 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL) {
3160 return NT_STATUS_NO_MEMORY;
3165 info->acc_granted = acc_granted;
3167 /* get a (unique) handle. open a policy on it. */
3168 if (!create_policy_hnd(p, user_pol, info)) {
3169 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3172 /* After a "set" ensure we have no cached display info. */
3173 force_flush_samr_cache(info->disp_info);
3175 *r->out.access_granted = acc_granted;
3177 return NT_STATUS_OK;
3180 /****************************************************************
3181 ****************************************************************/
3183 NTSTATUS _samr_CreateUser(pipes_struct *p,
3184 struct samr_CreateUser *r)
3186 struct samr_CreateUser2 c;
3187 uint32_t access_granted;
3189 c.in.domain_handle = r->in.domain_handle;
3190 c.in.account_name = r->in.account_name;
3191 c.in.acct_flags = ACB_NORMAL;
3192 c.in.access_mask = r->in.access_mask;
3193 c.out.user_handle = r->out.user_handle;
3194 c.out.access_granted = &access_granted;
3195 c.out.rid = r->out.rid;
3197 return _samr_CreateUser2(p, &c);
3200 /*******************************************************************
3202 ********************************************************************/
3204 NTSTATUS _samr_Connect(pipes_struct *p,
3205 struct samr_Connect *r)
3207 struct samr_info *info = NULL;
3208 uint32 des_access = r->in.access_mask;
3212 if (!pipe_access_check(p)) {
3213 DEBUG(3, ("access denied to _samr_Connect\n"));
3214 return NT_STATUS_ACCESS_DENIED;
3217 /* set up the SAMR connect_anon response */
3219 /* associate the user's SID with the new handle. */
3220 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3221 return NT_STATUS_NO_MEMORY;
3223 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3224 was observed from a win98 client trying to enumerate users (when configured
3225 user level access control on shares) --jerry */
3227 map_max_allowed_access(p->server_info->ptok, &des_access);
3229 se_map_generic( &des_access, &sam_generic_mapping );
3230 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
3232 /* get a (unique) handle. open a policy on it. */
3233 if (!create_policy_hnd(p, r->out.connect_handle, info))
3234 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3236 return NT_STATUS_OK;
3239 /*******************************************************************
3241 ********************************************************************/
3243 NTSTATUS _samr_Connect2(pipes_struct *p,
3244 struct samr_Connect2 *r)
3246 struct samr_info *info = NULL;
3247 SEC_DESC *psd = NULL;
3249 uint32 des_access = r->in.access_mask;
3252 const char *fn = "_samr_Connect2";
3254 switch (p->hdr_req.opnum) {
3255 case NDR_SAMR_CONNECT2:
3256 fn = "_samr_Connect2";
3258 case NDR_SAMR_CONNECT4:
3259 fn = "_samr_Connect4";
3261 case NDR_SAMR_CONNECT5:
3262 fn = "_samr_Connect5";
3266 DEBUG(5,("%s: %d\n", fn, __LINE__));
3270 if (!pipe_access_check(p)) {
3271 DEBUG(3, ("access denied to %s\n", fn));
3272 return NT_STATUS_ACCESS_DENIED;
3275 map_max_allowed_access(p->server_info->ptok, &des_access);
3277 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3278 se_map_generic(&des_access, &sam_generic_mapping);
3280 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3281 NULL, 0, des_access, &acc_granted, fn);
3283 if ( !NT_STATUS_IS_OK(nt_status) )
3286 /* associate the user's SID and access granted with the new handle. */
3287 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3288 return NT_STATUS_NO_MEMORY;
3290 info->acc_granted = acc_granted;
3291 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3293 /* get a (unique) handle. open a policy on it. */
3294 if (!create_policy_hnd(p, r->out.connect_handle, info))
3295 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3297 DEBUG(5,("%s: %d\n", fn, __LINE__));
3302 /*******************************************************************
3304 ********************************************************************/
3306 NTSTATUS _samr_Connect4(pipes_struct *p,
3307 struct samr_Connect4 *r)
3309 struct samr_Connect2 c;
3311 c.in.system_name = r->in.system_name;
3312 c.in.access_mask = r->in.access_mask;
3313 c.out.connect_handle = r->out.connect_handle;
3315 return _samr_Connect2(p, &c);
3318 /*******************************************************************
3320 ********************************************************************/
3322 NTSTATUS _samr_Connect5(pipes_struct *p,
3323 struct samr_Connect5 *r)
3326 struct samr_Connect2 c;
3327 struct samr_ConnectInfo1 info1;
3329 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3332 c.in.system_name = r->in.system_name;
3333 c.in.access_mask = r->in.access_mask;
3334 c.out.connect_handle = r->out.connect_handle;
3336 status = _samr_Connect2(p, &c);
3337 if (!NT_STATUS_IS_OK(status)) {
3341 *r->out.level_out = 1;
3342 r->out.info_out->info1 = info1;
3344 return NT_STATUS_OK;
3347 /**********************************************************************
3349 **********************************************************************/
3351 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3352 struct samr_LookupDomain *r)
3354 NTSTATUS status = NT_STATUS_OK;
3355 struct samr_info *info;
3356 const char *domain_name;
3357 DOM_SID *sid = NULL;
3359 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3360 return NT_STATUS_INVALID_HANDLE;
3362 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
3363 Reverted that change so we will work with RAS servers again */
3365 status = access_check_samr_function(info->acc_granted,
3366 SAMR_ACCESS_OPEN_DOMAIN,
3367 "_samr_LookupDomain");
3368 if (!NT_STATUS_IS_OK(status)) {
3372 domain_name = r->in.domain_name->string;
3374 return NT_STATUS_INVALID_PARAMETER;
3377 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
3379 return NT_STATUS_NO_MEMORY;
3382 if (strequal(domain_name, builtin_domain_name())) {
3383 sid_copy(sid, &global_sid_Builtin);
3385 if (!secrets_fetch_domain_sid(domain_name, sid)) {
3386 status = NT_STATUS_NO_SUCH_DOMAIN;
3390 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
3391 sid_string_dbg(sid)));
3398 /**********************************************************************
3400 **********************************************************************/
3402 NTSTATUS _samr_EnumDomains(pipes_struct *p,
3403 struct samr_EnumDomains *r)
3406 struct samr_info *info;
3407 uint32_t num_entries = 2;
3408 struct samr_SamEntry *entry_array = NULL;
3409 struct samr_SamArray *sam;
3411 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3412 return NT_STATUS_INVALID_HANDLE;
3414 status = access_check_samr_function(info->acc_granted,
3415 SAMR_ACCESS_ENUM_DOMAINS,
3416 "_samr_EnumDomains");
3417 if (!NT_STATUS_IS_OK(status)) {
3421 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
3423 return NT_STATUS_NO_MEMORY;
3426 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
3427 struct samr_SamEntry,
3430 return NT_STATUS_NO_MEMORY;
3433 entry_array[0].idx = 0;
3434 init_lsa_String(&entry_array[0].name, get_global_sam_name());
3436 entry_array[1].idx = 1;
3437 init_lsa_String(&entry_array[1].name, "Builtin");
3439 sam->count = num_entries;
3440 sam->entries = entry_array;
3443 *r->out.num_entries = num_entries;
3448 /*******************************************************************
3450 ********************************************************************/
3452 NTSTATUS _samr_OpenAlias(pipes_struct *p,
3453 struct samr_OpenAlias *r)
3456 POLICY_HND domain_pol = *r->in.domain_handle;
3457 uint32 alias_rid = r->in.rid;
3458 POLICY_HND *alias_pol = r->out.alias_handle;
3459 struct samr_info *info = NULL;
3460 SEC_DESC *psd = NULL;
3462 uint32 des_access = r->in.access_mask;
3467 /* find the domain policy and get the SID / access bits stored in the domain policy */
3469 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
3470 return NT_STATUS_INVALID_HANDLE;
3472 status = access_check_samr_function(acc_granted,
3473 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
3476 if ( !NT_STATUS_IS_OK(status) )
3479 /* append the alias' RID to it */
3481 if (!sid_append_rid(&sid, alias_rid))
3482 return NT_STATUS_NO_SUCH_ALIAS;
3484 /*check if access can be granted as requested by client. */
3486 map_max_allowed_access(p->server_info->ptok, &des_access);
3488 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3489 se_map_generic(&des_access,&ali_generic_mapping);
3491 se_priv_copy( &se_rights, &se_add_users );
3494 status = access_check_samr_object(psd, p->server_info->ptok,
3495 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3496 &acc_granted, "_samr_OpenAlias");
3498 if ( !NT_STATUS_IS_OK(status) )
3502 /* Check we actually have the requested alias */
3503 enum lsa_SidType type;
3508 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3511 if (!result || (type != SID_NAME_ALIAS)) {
3512 return NT_STATUS_NO_SUCH_ALIAS;
3515 /* make sure there is a mapping */
3517 if ( !sid_to_gid( &sid, &gid ) ) {
3518 return NT_STATUS_NO_SUCH_ALIAS;
3523 /* associate the alias SID with the new handle. */
3524 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
3525 return NT_STATUS_NO_MEMORY;
3527 info->acc_granted = acc_granted;
3529 /* get a (unique) handle. open a policy on it. */
3530 if (!create_policy_hnd(p, alias_pol, info))
3531 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3533 return NT_STATUS_OK;
3536 /*******************************************************************
3538 ********************************************************************/
3540 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3541 struct samr_UserInfo7 *id7,
3547 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3548 return NT_STATUS_ACCESS_DENIED;
3551 if (!id7->account_name.string) {
3552 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3553 return NT_STATUS_ACCESS_DENIED;
3556 /* check to see if the new username already exists. Note: we can't
3557 reliably lock all backends, so there is potentially the
3558 possibility that a user can be created in between this check and
3559 the rename. The rename should fail, but may not get the
3560 exact same failure status code. I think this is small enough
3561 of a window for this type of operation and the results are
3562 simply that the rename fails with a slightly different status
3563 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3565 rc = can_create(mem_ctx, id7->account_name.string);
3566 if (!NT_STATUS_IS_OK(rc)) {
3570 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
3575 /*******************************************************************
3577 ********************************************************************/
3579 static bool set_user_info_16(struct samr_UserInfo16 *id16,
3583 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3587 /* FIX ME: check if the value is really changed --metze */
3588 if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
3592 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3599 /*******************************************************************
3601 ********************************************************************/
3603 static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
3604 TALLOC_CTX *mem_ctx,
3605 DATA_BLOB *session_key,
3609 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3610 return NT_STATUS_INVALID_PARAMETER;
3613 if (id18->nt_pwd_active || id18->lm_pwd_active) {
3614 if (!session_key->length) {
3615 return NT_STATUS_NO_USER_SESSION_KEY;
3619 if (id18->nt_pwd_active) {
3623 in = data_blob_const(id18->nt_pwd.hash, 16);
3624 out = data_blob_talloc_zero(mem_ctx, 16);
3626 sess_crypt_blob(&out, &in, session_key, false);
3628 if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
3629 return NT_STATUS_ACCESS_DENIED;
3632 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3635 if (id18->lm_pwd_active) {
3639 in = data_blob_const(id18->lm_pwd.hash, 16);
3640 out = data_blob_talloc_zero(mem_ctx, 16);
3642 sess_crypt_blob(&out, &in, session_key, false);
3644 if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
3645 return NT_STATUS_ACCESS_DENIED;
3648 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3651 if (id18->password_expired) {
3652 pdb_set_pass_last_set_time(pwd, 0, PDB_CHANGED);
3655 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3658 return pdb_update_sam_account(pwd);
3661 /*******************************************************************
3663 ********************************************************************/
3665 static bool set_user_info_20(struct samr_UserInfo20 *id20,
3669 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3673 copy_id20_to_sam_passwd(pwd, id20);
3675 /* write the change out */
3676 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3683 /*******************************************************************
3685 ********************************************************************/
3687 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
3688 struct samr_UserInfo21 *id21,
3694 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3695 return NT_STATUS_INVALID_PARAMETER;
3698 if (id21->fields_present == 0) {
3699 return NT_STATUS_INVALID_PARAMETER;
3702 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3703 return NT_STATUS_ACCESS_DENIED;
3706 /* we need to separately check for an account rename first */
3708 if (id21->account_name.string &&
3709 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
3712 /* check to see if the new username already exists. Note: we can't
3713 reliably lock all backends, so there is potentially the
3714 possibility that a user can be created in between this check and
3715 the rename. The rename should fail, but may not get the
3716 exact same failure status code. I think this is small enough
3717 of a window for this type of operation and the results are
3718 simply that the rename fails with a slightly different status
3719 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3721 status = can_create(mem_ctx, id21->account_name.string);
3722 if (!NT_STATUS_IS_OK(status)) {
3726 status = pdb_rename_sam_account(pwd, id21->account_name.string);
3728 if (!NT_STATUS_IS_OK(status)) {
3729 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3730 nt_errstr(status)));
3734 /* set the new username so that later
3735 functions can work on the new account */
3736 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
3739 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
3742 * The funny part about the previous two calls is
3743 * that pwd still has the password hashes from the
3744 * passdb entry. These have not been updated from
3745 * id21. I don't know if they need to be set. --jerry
3748 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3749 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3750 if ( !NT_STATUS_IS_OK(status) ) {
3755 /* Don't worry about writing out the user account since the
3756 primary group SID is generated solely from the user's Unix
3759 /* write the change out */
3760 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3764 return NT_STATUS_OK;
3767 /*******************************************************************
3769 ********************************************************************/
3771 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
3772 struct samr_UserInfo23 *id23,
3775 char *plaintext_buf = NULL;
3781 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3782 return NT_STATUS_INVALID_PARAMETER;
3785 if (id23->info.fields_present == 0) {
3786 return NT_STATUS_INVALID_PARAMETER;
3789 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3790 return NT_STATUS_ACCESS_DENIED;
3793 if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
3794 (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
3796 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3797 pdb_get_username(pwd)));
3799 if (!decode_pw_buffer(mem_ctx,
3800 id23->password.data,
3804 return NT_STATUS_WRONG_PASSWORD;
3807 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3808 return NT_STATUS_ACCESS_DENIED;
3812 copy_id23_to_sam_passwd(pwd, id23);
3814 acct_ctrl = pdb_get_acct_ctrl(pwd);
3816 /* if it's a trust account, don't update /etc/passwd */
3817 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3818 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3819 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3820 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3821 } else if (plaintext_buf) {
3822 /* update the UNIX password */
3823 if (lp_unix_password_sync() ) {
3824 struct passwd *passwd;
3825 if (pdb_get_username(pwd) == NULL) {
3826 DEBUG(1, ("chgpasswd: User without name???\n"));
3827 return NT_STATUS_ACCESS_DENIED;
3830 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3831 if (passwd == NULL) {
3832 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3835 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3836 return NT_STATUS_ACCESS_DENIED;
3838 TALLOC_FREE(passwd);
3842 if (plaintext_buf) {
3843 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3846 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3847 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3852 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3856 return NT_STATUS_OK;
3859 /*******************************************************************
3861 ********************************************************************/
3863 static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
3867 char *plaintext_buf = NULL;
3869 time_t last_set_time;
3870 enum pdb_value_state last_set_state;
3872 DEBUG(5, ("Attempting administrator password change for user %s\n",
3873 pdb_get_username(pwd)));
3875 acct_ctrl = pdb_get_acct_ctrl(pwd);
3876 /* we need to know if it's expired, because this is an admin change, not a
3877 user change, so it's still expired when we're done */
3878 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3879 last_set_time = pdb_get_pass_last_set_time(pwd);
3881 if (!decode_pw_buffer(talloc_tos(),
3889 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3893 /* if it's a trust account, don't update /etc/passwd */
3894 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3895 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3896 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3897 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3899 /* update the UNIX password */
3900 if (lp_unix_password_sync()) {
3901 struct passwd *passwd;
3903 if (pdb_get_username(pwd) == NULL) {
3904 DEBUG(1, ("chgpasswd: User without name???\n"));
3908 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3909 if (passwd == NULL) {
3910 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3913 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3916 TALLOC_FREE(passwd);
3920 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3923 * A level 25 change does reset the pwdlastset field, a level 24
3924 * change does not. I know this is probably not the full story, but
3925 * it is needed to make XP join LDAP correctly, without it the later
3926 * auth2 check can fail with PWD_MUST_CHANGE.
3930 * restore last set time as this is an admin change, not a
3933 pdb_set_pass_last_set_time (pwd, last_set_time,
3937 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
3939 /* update the SAMBA password */
3940 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3947 /*******************************************************************
3949 ********************************************************************/
3951 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
3952 struct samr_UserInfo25 *id25,
3958 DEBUG(5, ("set_user_info_25: NULL id25\n"));
3959 return NT_STATUS_INVALID_PARAMETER;
3962 if (id25->info.fields_present == 0) {
3963 return NT_STATUS_INVALID_PARAMETER;
3966 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3967 return NT_STATUS_ACCESS_DENIED;
3970 copy_id25_to_sam_passwd(pwd, id25);
3972 /* write the change out */
3973 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3978 * We need to "pdb_update_sam_account" before the unix primary group
3979 * is set, because the idealx scripts would also change the
3980 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
3981 * the delete explicit / add explicit, which would then fail to find
3982 * the previous primaryGroupSid value.
3985 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3986 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3987 if ( !NT_STATUS_IS_OK(status) ) {
3992 return NT_STATUS_OK;
3995 /*******************************************************************
3997 ********************************************************************/
3999 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
4000 struct samr_SetUserInfo *r)
4003 struct samu *pwd = NULL;
4005 POLICY_HND *pol = r->in.user_handle;
4006 union samr_UserInfo *info = r->in.info;
4007 uint16_t switch_value = r->in.level;
4008 uint32_t acc_granted;
4009 uint32_t acc_required;
4011 bool has_enough_rights = False;
4013 DISP_INFO *disp_info = NULL;
4015 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4017 /* find the policy handle. open a policy on it. */
4018 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) {
4019 return NT_STATUS_INVALID_HANDLE;
4022 /* This is tricky. A WinXP domain join sets
4023 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4024 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4025 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4026 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4027 we'll use the set from the WinXP join as the basis. */
4029 switch (switch_value) {
4034 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4037 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4038 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4039 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4043 status = access_check_samr_function(acc_granted,
4045 "_samr_SetUserInfo");
4046 if (!NT_STATUS_IS_OK(status)) {
4050 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4051 sid_string_dbg(&sid), switch_value));
4054 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4055 return NT_STATUS_INVALID_INFO_CLASS;
4058 if (!(pwd = samu_new(NULL))) {
4059 return NT_STATUS_NO_MEMORY;
4063 ret = pdb_getsampwsid(pwd, &sid);
4068 return NT_STATUS_NO_SUCH_USER;
4071 /* deal with machine password changes differently from userinfo changes */
4072 /* check to see if we have the sufficient rights */
4074 acb_info = pdb_get_acct_ctrl(pwd);
4075 if (acb_info & ACB_WSTRUST)
4076 has_enough_rights = user_has_privileges(p->server_info->ptok,
4077 &se_machine_account);
4078 else if (acb_info & ACB_NORMAL)
4079 has_enough_rights = user_has_privileges(p->server_info->ptok,
4081 else if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
4082 if (lp_enable_privileges()) {
4083 has_enough_rights = nt_token_check_domain_rid(p->server_info->ptok,
4084 DOMAIN_GROUP_RID_ADMINS);
4088 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4089 uidtoname(p->server_info->utok.uid),
4090 has_enough_rights ? "" : " not"));
4092 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4094 if (has_enough_rights) {
4098 /* ok! user info levels (lots: see MSDEV help), off we go... */
4100 switch (switch_value) {
4103 status = set_user_info_7(p->mem_ctx,
4108 if (!set_user_info_16(&info->info16, pwd)) {
4109 status = NT_STATUS_ACCESS_DENIED;
4114 /* Used by AS/U JRA. */
4115 status = set_user_info_18(&info->info18,
4117 &p->server_info->user_session_key,
4122 if (!set_user_info_20(&info->info20, pwd)) {
4123 status = NT_STATUS_ACCESS_DENIED;
4128 status = set_user_info_21(p->mem_ctx,
4129 &info->info21, pwd);
4133 if (!p->server_info->user_session_key.length) {
4134 status = NT_STATUS_NO_USER_SESSION_KEY;
4136 SamOEMhashBlob(info->info23.password.data, 516,
4137 &p->server_info->user_session_key);
4139 dump_data(100, info->info23.password.data, 516);
4141 status = set_user_info_23(p->mem_ctx,
4142 &info->info23, pwd);
4146 if (!p->server_info->user_session_key.length) {
4147 status = NT_STATUS_NO_USER_SESSION_KEY;
4149 SamOEMhashBlob(info->info24.password.data,
4151 &p->server_info->user_session_key);
4153 dump_data(100, info->info24.password.data, 516);
4155 if (!set_user_info_pw(info->info24.password.data, pwd,
4157 status = NT_STATUS_WRONG_PASSWORD;
4162 if (!p->server_info->user_session_key.length) {
4163 status = NT_STATUS_NO_USER_SESSION_KEY;
4165 encode_or_decode_arc4_passwd_buffer(
4166 info->info25.password.data,
4167 &p->server_info->user_session_key);
4169 dump_data(100, info->info25.password.data, 532);
4171 status = set_user_info_25(p->mem_ctx,
4172 &info->info25, pwd);
4173 if (!NT_STATUS_IS_OK(status)) {
4176 if (!set_user_info_pw(info->info25.password.data, pwd,
4178 status = NT_STATUS_WRONG_PASSWORD;
4183 if (!p->server_info->user_session_key.length) {
4184 status = NT_STATUS_NO_USER_SESSION_KEY;
4186 encode_or_decode_arc4_passwd_buffer(
4187 info->info26.password.data,
4188 &p->server_info->user_session_key);
4190 dump_data(100, info->info26.password.data, 516);
4192 if (!set_user_info_pw(info->info26.password.data, pwd,
4194 status = NT_STATUS_WRONG_PASSWORD;
4199 status = NT_STATUS_INVALID_INFO_CLASS;
4206 if (has_enough_rights) {
4210 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4212 if (NT_STATUS_IS_OK(status)) {
4213 force_flush_samr_cache(disp_info);
4219 /*******************************************************************
4221 ********************************************************************/
4223 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
4224 struct samr_SetUserInfo2 *r)
4226 struct samr_SetUserInfo q;
4228 q.in.user_handle = r->in.user_handle;
4229 q.in.level = r->in.level;
4230 q.in.info = r->in.info;
4232 return _samr_SetUserInfo(p, &q);
4235 /*********************************************************************
4236 _samr_GetAliasMembership
4237 *********************************************************************/
4239 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
4240 struct samr_GetAliasMembership *r)
4242 size_t num_alias_rids;
4244 struct samr_info *info = NULL;
4252 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
4254 /* find the policy handle. open a policy on it. */
4255 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
4256 return NT_STATUS_INVALID_HANDLE;
4258 ntstatus1 = access_check_samr_function(info->acc_granted,
4259 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
4260 "_samr_GetAliasMembership");
4261 ntstatus2 = access_check_samr_function(info->acc_granted,
4262 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4263 "_samr_GetAliasMembership");
4265 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
4266 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
4267 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
4268 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
4272 if (!sid_check_is_domain(&info->sid) &&
4273 !sid_check_is_builtin(&info->sid))
4274 return NT_STATUS_OBJECT_TYPE_MISMATCH;
4276 if (r->in.sids->num_sids) {
4277 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
4279 if (members == NULL)
4280 return NT_STATUS_NO_MEMORY;
4285 for (i=0; i<r->in.sids->num_sids; i++)
4286 sid_copy(&members[i], r->in.sids->sids[i].sid);
4292 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
4293 r->in.sids->num_sids,
4294 &alias_rids, &num_alias_rids);
4297 if (!NT_STATUS_IS_OK(ntstatus1)) {
4301 r->out.rids->count = num_alias_rids;
4302 r->out.rids->ids = alias_rids;
4304 return NT_STATUS_OK;
4307 /*********************************************************************
4308 _samr_GetMembersInAlias
4309 *********************************************************************/
4311 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
4312 struct samr_GetMembersInAlias *r)
4316 size_t num_sids = 0;
4317 struct lsa_SidPtr *sids = NULL;
4318 DOM_SID *pdb_sids = NULL;
4324 /* find the policy handle. open a policy on it. */
4325 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
4326 return NT_STATUS_INVALID_HANDLE;
4328 status = access_check_samr_function(acc_granted,
4329 SAMR_ALIAS_ACCESS_GET_MEMBERS,
4330 "_samr_GetMembersInAlias");
4331 if (!NT_STATUS_IS_OK(status)) {
4335 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4338 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
4341 if (!NT_STATUS_IS_OK(status)) {
4346 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
4348 TALLOC_FREE(pdb_sids);
4349 return NT_STATUS_NO_MEMORY;
4353 for (i = 0; i < num_sids; i++) {
4354 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
4356 TALLOC_FREE(pdb_sids);
4357 return NT_STATUS_NO_MEMORY;
4361 r->out.sids->num_sids = num_sids;
4362 r->out.sids->sids = sids;
4364 TALLOC_FREE(pdb_sids);
4366 return NT_STATUS_OK;
4369 /*********************************************************************
4370 _samr_QueryGroupMember
4371 *********************************************************************/
4373 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
4374 struct samr_QueryGroupMember *r)
4377 size_t i, num_members;
4385 struct samr_RidTypeArray *rids = NULL;
4387 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
4389 return NT_STATUS_NO_MEMORY;
4392 /* find the policy handle. open a policy on it. */
4393 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
4394 return NT_STATUS_INVALID_HANDLE;
4396 status = access_check_samr_function(acc_granted,
4397 SAMR_GROUP_ACCESS_GET_MEMBERS,
4398 "_samr_QueryGroupMember");
4399 if (!NT_STATUS_IS_OK(status)) {
4403 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4405 if (!sid_check_is_in_our_domain(&group_sid)) {
4406 DEBUG(3, ("sid %s is not in our domain\n",
4407 sid_string_dbg(&group_sid)));
4408 return NT_STATUS_NO_SUCH_GROUP;
4411 DEBUG(10, ("lookup on Domain SID\n"));
4414 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
4415 &rid, &num_members);
4418 if (!NT_STATUS_IS_OK(status))
4422 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
4424 return NT_STATUS_NO_MEMORY;
4430 for (i=0; i<num_members; i++)
4431 attr[i] = SID_NAME_USER;
4433 rids->count = num_members;
4437 *r->out.rids = rids;
4439 return NT_STATUS_OK;
4442 /*********************************************************************
4443 _samr_AddAliasMember
4444 *********************************************************************/
4446 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
4447 struct samr_AddAliasMember *r)
4452 bool can_add_accounts;
4454 DISP_INFO *disp_info = NULL;
4456 /* Find the policy handle. Open a policy on it. */
4457 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4458 return NT_STATUS_INVALID_HANDLE;
4460 status = access_check_samr_function(acc_granted,
4461 SAMR_ALIAS_ACCESS_ADD_MEMBER,
4462 "_samr_AddAliasMember");
4463 if (!NT_STATUS_IS_OK(status)) {
4467 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4469 se_priv_copy( &se_rights, &se_add_users );
4470 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4472 /******** BEGIN SeAddUsers BLOCK *********/
4474 if ( can_add_accounts )
4477 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
4479 if ( can_add_accounts )
4482 /******** END SeAddUsers BLOCK *********/
4484 if (NT_STATUS_IS_OK(status)) {
4485 force_flush_samr_cache(disp_info);
4491 /*********************************************************************
4492 _samr_DeleteAliasMember
4493 *********************************************************************/
4495 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
4496 struct samr_DeleteAliasMember *r)
4501 bool can_add_accounts;
4503 DISP_INFO *disp_info = NULL;
4505 /* Find the policy handle. Open a policy on it. */
4506 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4507 return NT_STATUS_INVALID_HANDLE;
4509 status = access_check_samr_function(acc_granted,
4510 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
4511 "_samr_DeleteAliasMember");
4512 if (!NT_STATUS_IS_OK(status)) {
4516 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4517 sid_string_dbg(&alias_sid)));
4519 se_priv_copy( &se_rights, &se_add_users );
4520 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4522 /******** BEGIN SeAddUsers BLOCK *********/
4524 if ( can_add_accounts )
4527 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
4529 if ( can_add_accounts )
4532 /******** END SeAddUsers BLOCK *********/
4534 if (NT_STATUS_IS_OK(status)) {
4535 force_flush_samr_cache(disp_info);
4541 /*********************************************************************
4542 _samr_AddGroupMember
4543 *********************************************************************/
4545 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
4546 struct samr_AddGroupMember *r)
4553 bool can_add_accounts;
4554 DISP_INFO *disp_info = NULL;
4556 /* Find the policy handle. Open a policy on it. */
4557 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4558 return NT_STATUS_INVALID_HANDLE;
4560 status = access_check_samr_function(acc_granted,
4561 SAMR_GROUP_ACCESS_ADD_MEMBER,
4562 "_samr_AddGroupMember");
4563 if (!NT_STATUS_IS_OK(status)) {
4567 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4569 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4571 return NT_STATUS_INVALID_HANDLE;
4574 se_priv_copy( &se_rights, &se_add_users );
4575 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4577 /******** BEGIN SeAddUsers BLOCK *********/
4579 if ( can_add_accounts )
4582 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
4584 if ( can_add_accounts )
4587 /******** END SeAddUsers BLOCK *********/
4589 force_flush_samr_cache(disp_info);
4594 /*********************************************************************
4595 _samr_DeleteGroupMember
4596 *********************************************************************/
4598 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
4599 struct samr_DeleteGroupMember *r)
4607 bool can_add_accounts;
4608 DISP_INFO *disp_info = NULL;
4611 * delete the group member named r->in.rid
4612 * who is a member of the sid associated with the handle
4613 * the rid is a user's rid as the group is a domain group.
4616 /* Find the policy handle. Open a policy on it. */
4617 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4618 return NT_STATUS_INVALID_HANDLE;
4620 status = access_check_samr_function(acc_granted,
4621 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
4622 "_samr_DeleteGroupMember");
4623 if (!NT_STATUS_IS_OK(status)) {
4627 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4629 return NT_STATUS_INVALID_HANDLE;
4632 se_priv_copy( &se_rights, &se_add_users );
4633 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4635 /******** BEGIN SeAddUsers BLOCK *********/
4637 if ( can_add_accounts )
4640 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
4642 if ( can_add_accounts )
4645 /******** END SeAddUsers BLOCK *********/
4647 force_flush_samr_cache(disp_info);
4652 /*********************************************************************
4654 *********************************************************************/
4656 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4657 struct samr_DeleteUser *r)
4661 struct samu *sam_pass=NULL;
4663 bool can_add_accounts;
4665 DISP_INFO *disp_info = NULL;
4668 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4670 /* Find the policy handle. Open a policy on it. */
4671 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4672 return NT_STATUS_INVALID_HANDLE;
4674 status = access_check_samr_function(acc_granted,
4675 STD_RIGHT_DELETE_ACCESS,
4676 "_samr_DeleteUser");
4677 if (!NT_STATUS_IS_OK(status)) {
4681 if (!sid_check_is_in_our_domain(&user_sid))
4682 return NT_STATUS_CANNOT_DELETE;
4684 /* check if the user exists before trying to delete */
4685 if ( !(sam_pass = samu_new( NULL )) ) {
4686 return NT_STATUS_NO_MEMORY;
4690 ret = pdb_getsampwsid(sam_pass, &user_sid);
4694 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4695 sid_string_dbg(&user_sid)));
4696 TALLOC_FREE(sam_pass);
4697 return NT_STATUS_NO_SUCH_USER;
4700 acb_info = pdb_get_acct_ctrl(sam_pass);
4702 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4703 if ( acb_info & ACB_WSTRUST ) {
4704 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_machine_account );
4706 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
4709 /******** BEGIN SeAddUsers BLOCK *********/
4711 if ( can_add_accounts )
4714 status = pdb_delete_user(p->mem_ctx, sam_pass);
4716 if ( can_add_accounts )
4719 /******** END SeAddUsers BLOCK *********/
4721 if ( !NT_STATUS_IS_OK(status) ) {
4722 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4723 "user %s: %s.\n", pdb_get_username(sam_pass),
4724 nt_errstr(status)));
4725 TALLOC_FREE(sam_pass);
4730 TALLOC_FREE(sam_pass);
4732 if (!close_policy_hnd(p, r->in.user_handle))
4733 return NT_STATUS_OBJECT_NAME_INVALID;
4735 ZERO_STRUCTP(r->out.user_handle);
4737 force_flush_samr_cache(disp_info);
4739 return NT_STATUS_OK;
4742 /*********************************************************************
4743 _samr_DeleteDomainGroup
4744 *********************************************************************/
4746 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4747 struct samr_DeleteDomainGroup *r)
4754 bool can_add_accounts;
4755 DISP_INFO *disp_info = NULL;
4757 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4759 /* Find the policy handle. Open a policy on it. */
4760 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4761 return NT_STATUS_INVALID_HANDLE;
4763 status = access_check_samr_function(acc_granted,
4764 STD_RIGHT_DELETE_ACCESS,
4765 "_samr_DeleteDomainGroup");
4766 if (!NT_STATUS_IS_OK(status)) {
4770 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4772 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4774 return NT_STATUS_NO_SUCH_GROUP;
4777 se_priv_copy( &se_rights, &se_add_users );
4778 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4780 /******** BEGIN SeAddUsers BLOCK *********/
4782 if ( can_add_accounts )
4785 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4787 if ( can_add_accounts )
4790 /******** END SeAddUsers BLOCK *********/
4792 if ( !NT_STATUS_IS_OK(status) ) {
4793 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4794 "entry for group %s: %s\n",
4795 sid_string_dbg(&group_sid),
4796 nt_errstr(status)));
4800 if (!close_policy_hnd(p, r->in.group_handle))
4801 return NT_STATUS_OBJECT_NAME_INVALID;
4803 force_flush_samr_cache(disp_info);
4805 return NT_STATUS_OK;
4808 /*********************************************************************
4809 _samr_DeleteDomAlias
4810 *********************************************************************/
4812 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4813 struct samr_DeleteDomAlias *r)
4818 bool can_add_accounts;
4820 DISP_INFO *disp_info = NULL;
4822 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4824 /* Find the policy handle. Open a policy on it. */
4825 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4826 return NT_STATUS_INVALID_HANDLE;
4828 /* copy the handle to the outgoing reply */
4830 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4832 status = access_check_samr_function(acc_granted,
4833 STD_RIGHT_DELETE_ACCESS,
4834 "_samr_DeleteDomAlias");
4835 if (!NT_STATUS_IS_OK(status)) {
4839 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4841 /* Don't let Windows delete builtin groups */
4843 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4844 return NT_STATUS_SPECIAL_ACCOUNT;
4847 if (!sid_check_is_in_our_domain(&alias_sid))
4848 return NT_STATUS_NO_SUCH_ALIAS;
4850 DEBUG(10, ("lookup on Local SID\n"));
4852 se_priv_copy( &se_rights, &se_add_users );
4853 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4855 /******** BEGIN SeAddUsers BLOCK *********/
4857 if ( can_add_accounts )
4860 /* Have passdb delete the alias */
4861 status = pdb_delete_alias(&alias_sid);
4863 if ( can_add_accounts )
4866 /******** END SeAddUsers BLOCK *********/
4868 if ( !NT_STATUS_IS_OK(status))
4871 if (!close_policy_hnd(p, r->in.alias_handle))
4872 return NT_STATUS_OBJECT_NAME_INVALID;
4874 force_flush_samr_cache(disp_info);
4876 return NT_STATUS_OK;
4879 /*********************************************************************
4880 _samr_CreateDomainGroup
4881 *********************************************************************/
4883 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4884 struct samr_CreateDomainGroup *r)
4891 struct samr_info *info;
4894 bool can_add_accounts;
4895 DISP_INFO *disp_info = NULL;
4897 /* Find the policy handle. Open a policy on it. */
4898 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4899 return NT_STATUS_INVALID_HANDLE;
4901 status = access_check_samr_function(acc_granted,
4902 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
4903 "_samr_CreateDomainGroup");
4904 if (!NT_STATUS_IS_OK(status)) {
4908 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4909 return NT_STATUS_ACCESS_DENIED;
4911 name = r->in.name->string;
4913 return NT_STATUS_NO_MEMORY;
4916 status = can_create(p->mem_ctx, name);
4917 if (!NT_STATUS_IS_OK(status)) {
4921 se_priv_copy( &se_rights, &se_add_users );
4922 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4924 /******** BEGIN SeAddUsers BLOCK *********/
4926 if ( can_add_accounts )
4929 /* check that we successfully create the UNIX group */
4931 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4933 if ( can_add_accounts )
4936 /******** END SeAddUsers BLOCK *********/
4938 /* check if we should bail out here */
4940 if ( !NT_STATUS_IS_OK(status) )
4943 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
4945 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
4946 return NT_STATUS_NO_MEMORY;
4948 /* they created it; let the user do what he wants with it */
4950 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
4952 /* get a (unique) handle. open a policy on it. */
4953 if (!create_policy_hnd(p, r->out.group_handle, info))
4954 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4956 force_flush_samr_cache(disp_info);
4958 return NT_STATUS_OK;
4961 /*********************************************************************
4962 _samr_CreateDomAlias
4963 *********************************************************************/
4965 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
4966 struct samr_CreateDomAlias *r)
4970 const char *name = NULL;
4971 struct samr_info *info;
4976 bool can_add_accounts;
4977 DISP_INFO *disp_info = NULL;
4979 /* Find the policy handle. Open a policy on it. */
4980 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4981 return NT_STATUS_INVALID_HANDLE;
4983 result = access_check_samr_function(acc_granted,
4984 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
4985 "_samr_CreateDomAlias");
4986 if (!NT_STATUS_IS_OK(result)) {
4990 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4991 return NT_STATUS_ACCESS_DENIED;
4993 name = r->in.alias_name->string;
4995 se_priv_copy( &se_rights, &se_add_users );
4996 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4998 result = can_create(p->mem_ctx, name);
4999 if (!NT_STATUS_IS_OK(result)) {
5003 /******** BEGIN SeAddUsers BLOCK *********/
5005 if ( can_add_accounts )
5008 /* Have passdb create the alias */
5009 result = pdb_create_alias(name, r->out.rid);
5011 if ( can_add_accounts )
5014 /******** END SeAddUsers BLOCK *********/
5016 if (!NT_STATUS_IS_OK(result)) {
5017 DEBUG(10, ("pdb_create_alias failed: %s\n",
5018 nt_errstr(result)));
5022 sid_copy(&info_sid, get_global_sam_sid());
5023 sid_append_rid(&info_sid, *r->out.rid);
5025 if (!sid_to_gid(&info_sid, &gid)) {
5026 DEBUG(10, ("Could not find alias just created\n"));
5027 return NT_STATUS_ACCESS_DENIED;
5030 /* check if the group has been successfully created */
5031 if ( getgrgid(gid) == NULL ) {
5032 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5034 return NT_STATUS_ACCESS_DENIED;
5037 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5038 return NT_STATUS_NO_MEMORY;
5040 /* they created it; let the user do what he wants with it */
5042 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5044 /* get a (unique) handle. open a policy on it. */
5045 if (!create_policy_hnd(p, r->out.alias_handle, info))
5046 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5048 force_flush_samr_cache(disp_info);
5050 return NT_STATUS_OK;
5053 /*********************************************************************
5054 _samr_QueryGroupInfo
5055 *********************************************************************/
5057 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5058 struct samr_QueryGroupInfo *r)
5063 union samr_GroupInfo *info = NULL;
5066 uint32_t attributes = SE_GROUP_MANDATORY |
5067 SE_GROUP_ENABLED_BY_DEFAULT |
5069 const char *group_name = NULL;
5070 const char *group_description = NULL;
5072 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5073 return NT_STATUS_INVALID_HANDLE;
5075 status = access_check_samr_function(acc_granted,
5076 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5077 "_samr_QueryGroupInfo");
5078 if (!NT_STATUS_IS_OK(status)) {
5083 ret = get_domain_group_from_sid(group_sid, &map);
5086 return NT_STATUS_INVALID_HANDLE;
5088 /* FIXME: map contains fstrings */
5089 group_name = talloc_strdup(r, map.nt_name);
5090 group_description = talloc_strdup(r, map.comment);
5092 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5094 return NT_STATUS_NO_MEMORY;
5097 switch (r->in.level) {
5103 status = pdb_enum_group_members(
5104 p->mem_ctx, &group_sid, &members, &num_members);
5107 if (!NT_STATUS_IS_OK(status)) {
5111 info->all.name.string = group_name;
5112 info->all.attributes = attributes;
5113 info->all.num_members = num_members;
5114 info->all.description.string = group_description;
5118 info->name.string = group_name;
5121 info->attributes.attributes = attributes;
5124 info->description.string = group_description;
5134 status = pdb_enum_group_members(
5135 p->mem_ctx, &group_sid, &members, &num_members);
5138 if (!NT_STATUS_IS_OK(status)) {
5142 info->all2.name.string = group_name;
5143 info->all2.attributes = attributes;
5144 info->all2.num_members = 0; /* num_members - in w2k3 this is always 0 */
5145 info->all2.description.string = group_description;
5150 return NT_STATUS_INVALID_INFO_CLASS;
5153 *r->out.info = info;
5155 return NT_STATUS_OK;
5158 /*********************************************************************
5160 *********************************************************************/
5162 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5163 struct samr_SetGroupInfo *r)
5170 bool can_mod_accounts;
5171 DISP_INFO *disp_info = NULL;
5173 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5174 return NT_STATUS_INVALID_HANDLE;
5176 status = access_check_samr_function(acc_granted,
5177 SAMR_GROUP_ACCESS_SET_INFO,
5178 "_samr_SetGroupInfo");
5179 if (!NT_STATUS_IS_OK(status)) {
5184 ret = get_domain_group_from_sid(group_sid, &map);
5187 return NT_STATUS_NO_SUCH_GROUP;
5189 switch (r->in.level) {
5191 fstrcpy(map.comment, r->in.info->all.description.string);
5194 /* group rename is not supported yet */
5195 return NT_STATUS_NOT_SUPPORTED;
5197 fstrcpy(map.comment, r->in.info->description.string);
5200 return NT_STATUS_INVALID_INFO_CLASS;
5203 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5205 /******** BEGIN SeAddUsers BLOCK *********/
5207 if ( can_mod_accounts )
5210 status = pdb_update_group_mapping_entry(&map);
5212 if ( can_mod_accounts )
5215 /******** End SeAddUsers BLOCK *********/
5217 if (NT_STATUS_IS_OK(status)) {
5218 force_flush_samr_cache(disp_info);
5224 /*********************************************************************
5226 *********************************************************************/
5228 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5229 struct samr_SetAliasInfo *r)
5232 struct acct_info info;
5234 bool can_mod_accounts;
5236 DISP_INFO *disp_info = NULL;
5238 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
5239 return NT_STATUS_INVALID_HANDLE;
5241 status = access_check_samr_function(acc_granted,
5242 SAMR_ALIAS_ACCESS_SET_INFO,
5243 "_samr_SetAliasInfo");
5244 if (!NT_STATUS_IS_OK(status)) {
5248 /* get the current group information */
5251 status = pdb_get_aliasinfo( &group_sid, &info );
5254 if ( !NT_STATUS_IS_OK(status))
5257 switch (r->in.level) {
5262 /* We currently do not support renaming groups in the
5263 the BUILTIN domain. Refer to util_builtin.c to understand
5264 why. The eventually needs to be fixed to be like Windows
5265 where you can rename builtin groups, just not delete them */
5267 if ( sid_check_is_in_builtin( &group_sid ) ) {
5268 return NT_STATUS_SPECIAL_ACCOUNT;
5271 /* There has to be a valid name (and it has to be different) */
5273 if ( !r->in.info->name.string )
5274 return NT_STATUS_INVALID_PARAMETER;
5276 /* If the name is the same just reply "ok". Yes this
5277 doesn't allow you to change the case of a group name. */
5279 if ( strequal( r->in.info->name.string, info.acct_name ) )
5280 return NT_STATUS_OK;
5282 fstrcpy( info.acct_name, r->in.info->name.string);
5284 /* make sure the name doesn't already exist as a user
5287 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
5288 status = can_create( p->mem_ctx, group_name );
5289 if ( !NT_STATUS_IS_OK( status ) )
5293 case ALIASINFODESCRIPTION:
5294 if (r->in.info->description.string) {
5295 fstrcpy(info.acct_desc,
5296 r->in.info->description.string);
5298 fstrcpy( info.acct_desc, "" );
5302 return NT_STATUS_INVALID_INFO_CLASS;
5305 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5307 /******** BEGIN SeAddUsers BLOCK *********/
5309 if ( can_mod_accounts )
5312 status = pdb_set_aliasinfo( &group_sid, &info );
5314 if ( can_mod_accounts )
5317 /******** End SeAddUsers BLOCK *********/
5319 if (NT_STATUS_IS_OK(status))
5320 force_flush_samr_cache(disp_info);
5325 /****************************************************************
5327 ****************************************************************/
5329 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
5330 struct samr_GetDomPwInfo *r)
5332 uint32_t min_password_length = 0;
5333 uint32_t password_properties = 0;
5335 /* Perform access check. Since this rpc does not require a
5336 policy handle it will not be caught by the access checks on
5337 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5339 if (!pipe_access_check(p)) {
5340 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5341 return NT_STATUS_ACCESS_DENIED;
5345 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
5346 &min_password_length);
5347 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
5348 &password_properties);
5351 if (lp_check_password_script() && *lp_check_password_script()) {
5352 password_properties |= DOMAIN_PASSWORD_COMPLEX;
5355 r->out.info->min_password_length = min_password_length;
5356 r->out.info->password_properties = password_properties;
5358 return NT_STATUS_OK;
5361 /*********************************************************************
5363 *********************************************************************/
5365 NTSTATUS _samr_OpenGroup(pipes_struct *p,
5366 struct samr_OpenGroup *r)
5372 struct samr_info *info;
5373 SEC_DESC *psd = NULL;
5375 uint32 des_access = r->in.access_mask;
5382 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
5383 return NT_STATUS_INVALID_HANDLE;
5385 status = access_check_samr_function(acc_granted,
5386 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5389 if ( !NT_STATUS_IS_OK(status) )
5392 /*check if access can be granted as requested by client. */
5393 map_max_allowed_access(p->server_info->ptok, &des_access);
5395 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
5396 se_map_generic(&des_access,&grp_generic_mapping);
5398 se_priv_copy( &se_rights, &se_add_users );
5400 status = access_check_samr_object(psd, p->server_info->ptok,
5401 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
5402 &acc_granted, "_samr_OpenGroup");
5404 if ( !NT_STATUS_IS_OK(status) )
5407 /* this should not be hard-coded like this */
5409 if (!sid_equal(&sid, get_global_sam_sid()))
5410 return NT_STATUS_ACCESS_DENIED;
5412 sid_copy(&info_sid, get_global_sam_sid());
5413 sid_append_rid(&info_sid, r->in.rid);
5414 sid_to_fstring(sid_string, &info_sid);
5416 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5417 return NT_STATUS_NO_MEMORY;
5419 info->acc_granted = acc_granted;
5421 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
5423 /* check if that group really exists */
5425 ret = get_domain_group_from_sid(info->sid, &map);
5428 return NT_STATUS_NO_SUCH_GROUP;
5430 /* get a (unique) handle. open a policy on it. */
5431 if (!create_policy_hnd(p, r->out.group_handle, info))
5432 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5434 return NT_STATUS_OK;
5437 /*********************************************************************
5438 _samr_RemoveMemberFromForeignDomain
5439 *********************************************************************/
5441 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5442 struct samr_RemoveMemberFromForeignDomain *r)
5444 DOM_SID delete_sid, domain_sid;
5447 DISP_INFO *disp_info = NULL;
5449 sid_copy( &delete_sid, r->in.sid );
5451 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5452 sid_string_dbg(&delete_sid)));
5454 /* Find the policy handle. Open a policy on it. */
5456 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
5457 &acc_granted, &disp_info))
5458 return NT_STATUS_INVALID_HANDLE;
5460 result = access_check_samr_function(acc_granted,
5461 STD_RIGHT_DELETE_ACCESS,
5462 "_samr_RemoveMemberFromForeignDomain");
5464 if (!NT_STATUS_IS_OK(result))
5467 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5468 sid_string_dbg(&domain_sid)));
5470 /* we can only delete a user from a group since we don't have
5471 nested groups anyways. So in the latter case, just say OK */
5473 /* TODO: The above comment nowadays is bogus. Since we have nested
5474 * groups now, and aliases members are never reported out of the unix
5475 * group membership, the "just say OK" makes this call a no-op. For
5476 * us. This needs fixing however. */
5478 /* I've only ever seen this in the wild when deleting a user from
5479 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5480 * is the user about to be deleted. I very much suspect this is the
5481 * only application of this call. To verify this, let people report
5484 if (!sid_check_is_builtin(&domain_sid)) {
5485 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5486 "global_sam_sid() = %s\n",
5487 sid_string_dbg(&domain_sid),
5488 sid_string_dbg(get_global_sam_sid())));
5489 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5490 return NT_STATUS_OK;
5493 force_flush_samr_cache(disp_info);
5495 result = NT_STATUS_OK;
5500 /*******************************************************************
5501 _samr_QueryDomainInfo2
5502 ********************************************************************/
5504 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5505 struct samr_QueryDomainInfo2 *r)
5507 struct samr_QueryDomainInfo q;
5509 q.in.domain_handle = r->in.domain_handle;
5510 q.in.level = r->in.level;
5512 q.out.info = r->out.info;
5514 return _samr_QueryDomainInfo(p, &q);
5517 /*******************************************************************
5519 ********************************************************************/
5521 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5522 struct samr_SetDomainInfo *r)
5524 struct samr_info *info = NULL;
5525 time_t u_expire, u_min_age;
5527 time_t u_lock_duration, u_reset_time;
5530 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5532 /* find the policy handle. open a policy on it. */
5533 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5534 return NT_STATUS_INVALID_HANDLE;
5536 /* We do have different access bits for info
5537 * levels here, but we're really just looking for
5538 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5539 * this maps to different specific bits. So
5540 * assume if we have SAMR_DOMAIN_ACCESS_SET_INFO_1
5543 result = access_check_samr_function(info->acc_granted,
5544 SAMR_DOMAIN_ACCESS_SET_INFO_1,
5545 "_samr_SetDomainInfo");
5547 if (!NT_STATUS_IS_OK(result))
5550 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
5552 switch (r->in.level) {
5554 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
5555 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
5556 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
5557 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
5558 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
5559 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5560 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5565 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
5566 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5575 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
5576 if (u_lock_duration != -1)
5577 u_lock_duration /= 60;
5579 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
5581 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5582 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5583 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
5586 return NT_STATUS_INVALID_INFO_CLASS;
5589 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5591 return NT_STATUS_OK;
5594 /****************************************************************
5595 _samr_GetDisplayEnumerationIndex
5596 ****************************************************************/
5598 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5599 struct samr_GetDisplayEnumerationIndex *r)
5601 struct samr_info *info = NULL;
5602 uint32_t max_entries = (uint32_t) -1;
5603 uint32_t enum_context = 0;
5605 uint32_t num_account = 0;
5606 struct samr_displayentry *entries = NULL;
5609 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
5611 /* find the policy handle. open a policy on it. */
5612 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
5613 return NT_STATUS_INVALID_HANDLE;
5616 status = access_check_samr_function(info->acc_granted,
5617 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
5618 "_samr_GetDisplayEnumerationIndex");
5619 if (!NT_STATUS_IS_OK(status)) {
5623 if ((r->in.level < 1) || (r->in.level > 3)) {
5624 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5625 "Unknown info level (%u)\n",
5627 return NT_STATUS_INVALID_INFO_CLASS;
5632 /* The following done as ROOT. Don't return without unbecome_root(). */
5634 switch (r->in.level) {
5636 if (info->disp_info->users == NULL) {
5637 info->disp_info->users = pdb_search_users(ACB_NORMAL);
5638 if (info->disp_info->users == NULL) {
5640 return NT_STATUS_ACCESS_DENIED;
5642 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5643 "starting user enumeration at index %u\n",
5644 (unsigned int)enum_context));
5646 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5647 "using cached user enumeration at index %u\n",
5648 (unsigned int)enum_context));
5650 num_account = pdb_search_entries(info->disp_info->users,
5651 enum_context, max_entries,
5655 if (info->disp_info->machines == NULL) {
5656 info->disp_info->machines =
5657 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
5658 if (info->disp_info->machines == NULL) {
5660 return NT_STATUS_ACCESS_DENIED;
5662 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5663 "starting machine enumeration at index %u\n",
5664 (unsigned int)enum_context));
5666 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5667 "using cached machine enumeration at index %u\n",
5668 (unsigned int)enum_context));
5670 num_account = pdb_search_entries(info->disp_info->machines,
5671 enum_context, max_entries,
5675 if (info->disp_info->groups == NULL) {
5676 info->disp_info->groups = pdb_search_groups();
5677 if (info->disp_info->groups == NULL) {
5679 return NT_STATUS_ACCESS_DENIED;
5681 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5682 "starting group enumeration at index %u\n",
5683 (unsigned int)enum_context));
5685 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5686 "using cached group enumeration at index %u\n",
5687 (unsigned int)enum_context));
5689 num_account = pdb_search_entries(info->disp_info->groups,
5690 enum_context, max_entries,
5695 smb_panic("info class changed");
5701 /* Ensure we cache this enumeration. */
5702 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
5704 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5705 r->in.name->string));
5707 for (i=0; i<num_account; i++) {
5708 if (strequal(entries[i].account_name, r->in.name->string)) {
5709 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5710 "found %s at idx %d\n",
5711 r->in.name->string, i));
5713 return NT_STATUS_OK;
5717 /* assuming account_name lives at the very end */
5718 *r->out.idx = num_account;
5720 return NT_STATUS_NO_MORE_ENTRIES;
5723 /****************************************************************
5724 _samr_GetDisplayEnumerationIndex2
5725 ****************************************************************/
5727 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5728 struct samr_GetDisplayEnumerationIndex2 *r)
5730 struct samr_GetDisplayEnumerationIndex q;
5732 q.in.domain_handle = r->in.domain_handle;
5733 q.in.level = r->in.level;
5734 q.in.name = r->in.name;
5736 q.out.idx = r->out.idx;
5738 return _samr_GetDisplayEnumerationIndex(p, &q);
5741 /****************************************************************
5742 ****************************************************************/
5744 NTSTATUS _samr_Shutdown(pipes_struct *p,
5745 struct samr_Shutdown *r)
5747 p->rng_fault_state = true;
5748 return NT_STATUS_NOT_IMPLEMENTED;
5751 /****************************************************************
5752 ****************************************************************/
5754 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5755 struct samr_SetMemberAttributesOfGroup *r)
5757 p->rng_fault_state = true;
5758 return NT_STATUS_NOT_IMPLEMENTED;
5761 /****************************************************************
5762 ****************************************************************/
5764 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5765 struct samr_ChangePasswordUser *r)
5767 p->rng_fault_state = true;
5768 return NT_STATUS_NOT_IMPLEMENTED;
5771 /****************************************************************
5772 ****************************************************************/
5774 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5775 struct samr_TestPrivateFunctionsDomain *r)
5777 p->rng_fault_state = true;
5778 return NT_STATUS_NOT_IMPLEMENTED;
5781 /****************************************************************
5782 ****************************************************************/
5784 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5785 struct samr_TestPrivateFunctionsUser *r)
5787 p->rng_fault_state = true;
5788 return NT_STATUS_NOT_IMPLEMENTED;
5791 /****************************************************************
5792 ****************************************************************/
5794 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5795 struct samr_AddMultipleMembersToAlias *r)
5797 p->rng_fault_state = true;
5798 return NT_STATUS_NOT_IMPLEMENTED;
5801 /****************************************************************
5802 ****************************************************************/
5804 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5805 struct samr_RemoveMultipleMembersFromAlias *r)
5807 p->rng_fault_state = true;
5808 return NT_STATUS_NOT_IMPLEMENTED;
5811 /****************************************************************
5812 ****************************************************************/
5814 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5815 struct samr_OemChangePasswordUser2 *r)
5817 p->rng_fault_state = true;
5818 return NT_STATUS_NOT_IMPLEMENTED;
5821 /****************************************************************
5822 ****************************************************************/
5824 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5825 struct samr_SetBootKeyInformation *r)
5827 p->rng_fault_state = true;
5828 return NT_STATUS_NOT_IMPLEMENTED;
5831 /****************************************************************
5832 ****************************************************************/
5834 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5835 struct samr_GetBootKeyInformation *r)
5837 p->rng_fault_state = true;
5838 return NT_STATUS_NOT_IMPLEMENTED;
5841 /****************************************************************
5842 ****************************************************************/
5844 NTSTATUS _samr_Connect3(pipes_struct *p,
5845 struct samr_Connect3 *r)
5847 p->rng_fault_state = true;
5848 return NT_STATUS_NOT_IMPLEMENTED;
5851 /****************************************************************
5852 ****************************************************************/
5854 NTSTATUS _samr_RidToSid(pipes_struct *p,
5855 struct samr_RidToSid *r)
5857 p->rng_fault_state = true;
5858 return NT_STATUS_NOT_IMPLEMENTED;
5861 /****************************************************************
5862 ****************************************************************/
5864 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5865 struct samr_SetDsrmPassword *r)
5867 p->rng_fault_state = true;
5868 return NT_STATUS_NOT_IMPLEMENTED;
5871 /****************************************************************
5872 ****************************************************************/
5874 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5875 struct samr_ValidatePassword *r)
5877 p->rng_fault_state = true;
5878 return NT_STATUS_NOT_IMPLEMENTED;