2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997,
7 * Copyright (C) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2008,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
14 * Copyright (C) Guenther Deschner 2008.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
31 * This is the implementation of the SAMR code.
37 #define DBGC_CLASS DBGC_RPC_SRV
39 #define SAMR_USR_RIGHTS_WRITE_PW \
40 ( READ_CONTROL_ACCESS | \
41 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
42 SAMR_USER_ACCESS_SET_LOC_COM)
43 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
44 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
46 #define DISP_INFO_CACHE_TIMEOUT 10
48 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
49 #define MAX_SAM_ENTRIES_W95 50
51 typedef struct disp_info {
52 DOM_SID sid; /* identify which domain this is. */
53 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
54 struct pdb_search *users; /* querydispinfo 1 and 4 */
55 struct pdb_search *machines; /* querydispinfo 2 */
56 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
57 struct pdb_search *aliases; /* enumaliases */
60 struct pdb_search *enum_users; /* enumusers with a mask */
62 struct timed_event *cache_timeout_event; /* cache idle timeout
66 /* We keep a static list of these by SID as modern clients close down
67 all resources between each request in a complete enumeration. */
70 /* for use by the \PIPE\samr policy */
72 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
73 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
79 static const struct generic_mapping sam_generic_mapping = {
80 GENERIC_RIGHTS_SAM_READ,
81 GENERIC_RIGHTS_SAM_WRITE,
82 GENERIC_RIGHTS_SAM_EXECUTE,
83 GENERIC_RIGHTS_SAM_ALL_ACCESS};
84 static const struct generic_mapping dom_generic_mapping = {
85 GENERIC_RIGHTS_DOMAIN_READ,
86 GENERIC_RIGHTS_DOMAIN_WRITE,
87 GENERIC_RIGHTS_DOMAIN_EXECUTE,
88 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
89 static const struct generic_mapping usr_generic_mapping = {
90 GENERIC_RIGHTS_USER_READ,
91 GENERIC_RIGHTS_USER_WRITE,
92 GENERIC_RIGHTS_USER_EXECUTE,
93 GENERIC_RIGHTS_USER_ALL_ACCESS};
94 static const struct generic_mapping usr_nopwchange_generic_mapping = {
95 GENERIC_RIGHTS_USER_READ,
96 GENERIC_RIGHTS_USER_WRITE,
97 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
98 GENERIC_RIGHTS_USER_ALL_ACCESS};
99 static const struct generic_mapping grp_generic_mapping = {
100 GENERIC_RIGHTS_GROUP_READ,
101 GENERIC_RIGHTS_GROUP_WRITE,
102 GENERIC_RIGHTS_GROUP_EXECUTE,
103 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
104 static const struct generic_mapping ali_generic_mapping = {
105 GENERIC_RIGHTS_ALIAS_READ,
106 GENERIC_RIGHTS_ALIAS_WRITE,
107 GENERIC_RIGHTS_ALIAS_EXECUTE,
108 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
110 /*******************************************************************
111 *******************************************************************/
113 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
114 const struct generic_mapping *map,
115 DOM_SID *sid, uint32 sid_access )
117 DOM_SID domadmin_sid;
118 SEC_ACE ace[5]; /* at most 5 entries */
123 /* basic access for Everyone */
125 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
126 map->generic_execute | map->generic_read, 0);
128 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
130 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
131 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
132 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
133 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
135 /* Add Full Access for Domain Admins if we are a DC */
138 sid_copy( &domadmin_sid, get_global_sam_sid() );
139 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
140 init_sec_ace(&ace[i++], &domadmin_sid,
141 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
144 /* if we have a sid, give it some special access */
147 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
150 /* create the security descriptor */
152 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
153 return NT_STATUS_NO_MEMORY;
155 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
156 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
157 psa, sd_size)) == NULL)
158 return NT_STATUS_NO_MEMORY;
163 /*******************************************************************
164 Checks if access to an object should be granted, and returns that
165 level of access for further checks.
166 ********************************************************************/
168 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
169 SE_PRIV *rights, uint32 rights_mask,
170 uint32 des_access, uint32 *acc_granted,
173 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
174 uint32 saved_mask = 0;
176 /* check privileges; certain SAM access bits should be overridden
177 by privileges (mostly having to do with creating/modifying/deleting
180 if ( rights && user_has_any_privilege( token, rights ) ) {
182 saved_mask = (des_access & rights_mask);
183 des_access &= ~saved_mask;
185 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
190 /* check the security descriptor first */
192 status = se_access_check(psd, token, des_access, acc_granted);
193 if (NT_STATUS_IS_OK(status)) {
197 /* give root a free pass */
199 if ( geteuid() == sec_initial_uid() ) {
201 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
202 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
204 *acc_granted = des_access;
206 status = NT_STATUS_OK;
212 /* add in any bits saved during the privilege check (only
213 matters is status is ok) */
215 *acc_granted |= rights_mask;
217 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
218 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
219 des_access, *acc_granted));
224 /*******************************************************************
225 Checks if access to a function can be granted
226 ********************************************************************/
228 static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_required, const char *debug)
230 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
231 debug, acc_granted, acc_required));
233 /* check the security descriptor first */
235 if ( (acc_granted&acc_required) == acc_required )
238 /* give root a free pass */
240 if (geteuid() == sec_initial_uid()) {
242 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
243 debug, acc_granted, acc_required));
244 DEBUGADD(4,("but overwritten by euid == 0\n"));
249 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
250 debug, acc_granted, acc_required));
252 return NT_STATUS_ACCESS_DENIED;
255 /*******************************************************************
256 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
257 ********************************************************************/
259 static void map_max_allowed_access(const NT_USER_TOKEN *token,
260 uint32_t *pacc_requested)
262 if (!((*pacc_requested) & MAXIMUM_ALLOWED_ACCESS)) {
265 *pacc_requested &= ~MAXIMUM_ALLOWED_ACCESS;
267 /* At least try for generic read. */
268 *pacc_requested = GENERIC_READ_ACCESS;
270 /* root gets anything. */
271 if (geteuid() == sec_initial_uid()) {
272 *pacc_requested |= GENERIC_ALL_ACCESS;
276 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
278 if (is_sid_in_token(token, &global_sid_Builtin_Administrators) ||
279 is_sid_in_token(token, &global_sid_Builtin_Account_Operators)) {
280 *pacc_requested |= GENERIC_ALL_ACCESS;
284 /* Full access for DOMAIN\Domain Admins. */
286 DOM_SID domadmin_sid;
287 sid_copy( &domadmin_sid, get_global_sam_sid() );
288 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
289 if (is_sid_in_token(token, &domadmin_sid)) {
290 *pacc_requested |= GENERIC_ALL_ACCESS;
294 /* TODO ! Check privileges. */
297 /*******************************************************************
298 Fetch or create a dispinfo struct.
299 ********************************************************************/
301 static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid)
304 * We do a static cache for DISP_INFO's here. Explanation can be found
305 * in Jeremy's checkin message to r11793:
307 * Fix the SAMR cache so it works across completely insane
308 * client behaviour (ie.:
309 * open pipe/open SAMR handle/enumerate 0 - 1024
310 * close SAMR handle, close pipe.
311 * open pipe/open SAMR handle/enumerate 1024 - 2048...
312 * close SAMR handle, close pipe.
313 * And on ad-nausium. Amazing.... probably object-oriented
314 * client side programming in action yet again.
315 * This change should *massively* improve performance when
316 * enumerating users from an LDAP database.
319 * "Our" and the builtin domain are the only ones where we ever
320 * enumerate stuff, so just cache 2 entries.
323 static struct disp_info builtin_dispinfo;
324 static struct disp_info domain_dispinfo;
326 /* There are two cases to consider here:
327 1) The SID is a domain SID and we look for an equality match, or
328 2) This is an account SID and so we return the DISP_INFO* for our
335 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
337 * Necessary only once, but it does not really hurt.
339 sid_copy(&builtin_dispinfo.sid, &global_sid_Builtin);
341 return &builtin_dispinfo;
344 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
346 * Necessary only once, but it does not really hurt.
348 sid_copy(&domain_dispinfo.sid, get_global_sam_sid());
350 return &domain_dispinfo;
356 /*******************************************************************
357 Create a samr_info struct.
358 ********************************************************************/
360 static struct samr_info *get_samr_info_by_sid(DOM_SID *psid)
362 struct samr_info *info;
367 sid_to_fstring(sid_str, psid);
369 fstrcpy(sid_str,"(NULL)");
372 mem_ctx = talloc_init("samr_info for domain sid %s", sid_str);
374 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL)
377 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
379 sid_copy( &info->sid, psid);
380 info->builtin_domain = sid_check_is_builtin(psid);
382 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
383 info->builtin_domain = False;
385 info->mem_ctx = mem_ctx;
387 info->disp_info = get_samr_dispinfo_by_sid(psid);
392 /*******************************************************************
393 Function to free the per SID data.
394 ********************************************************************/
396 static void free_samr_cache(DISP_INFO *disp_info)
398 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
399 sid_string_dbg(&disp_info->sid)));
401 /* We need to become root here because the paged search might have to
402 * tell the LDAP server we're not interested in the rest anymore. */
406 if (disp_info->users) {
407 DEBUG(10,("free_samr_cache: deleting users cache\n"));
408 pdb_search_destroy(disp_info->users);
409 disp_info->users = NULL;
411 if (disp_info->machines) {
412 DEBUG(10,("free_samr_cache: deleting machines cache\n"));
413 pdb_search_destroy(disp_info->machines);
414 disp_info->machines = NULL;
416 if (disp_info->groups) {
417 DEBUG(10,("free_samr_cache: deleting groups cache\n"));
418 pdb_search_destroy(disp_info->groups);
419 disp_info->groups = NULL;
421 if (disp_info->aliases) {
422 DEBUG(10,("free_samr_cache: deleting aliases cache\n"));
423 pdb_search_destroy(disp_info->aliases);
424 disp_info->aliases = NULL;
426 if (disp_info->enum_users) {
427 DEBUG(10,("free_samr_cache: deleting enum_users cache\n"));
428 pdb_search_destroy(disp_info->enum_users);
429 disp_info->enum_users = NULL;
431 disp_info->enum_acb_mask = 0;
436 /*******************************************************************
437 Function to free the per handle data.
438 ********************************************************************/
440 static void free_samr_info(void *ptr)
442 struct samr_info *info=(struct samr_info *) ptr;
444 /* Only free the dispinfo cache if no one bothered to set up
447 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
448 free_samr_cache(info->disp_info);
451 talloc_destroy(info->mem_ctx);
454 /*******************************************************************
455 Idle event handler. Throw away the disp info cache.
456 ********************************************************************/
458 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
459 struct timed_event *te,
463 DISP_INFO *disp_info = (DISP_INFO *)private_data;
465 TALLOC_FREE(disp_info->cache_timeout_event);
467 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
469 free_samr_cache(disp_info);
472 /*******************************************************************
473 Setup cache removal idle event handler.
474 ********************************************************************/
476 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
478 /* Remove any pending timeout and update. */
480 TALLOC_FREE(disp_info->cache_timeout_event);
482 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
483 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
484 (unsigned int)secs_fromnow ));
486 disp_info->cache_timeout_event = event_add_timed(
487 smbd_event_context(), NULL,
488 timeval_current_ofs(secs_fromnow, 0),
489 disp_info_cache_idle_timeout_handler, (void *)disp_info);
492 /*******************************************************************
493 Force flush any cache. We do this on any samr_set_xxx call.
494 We must also remove the timeout handler.
495 ********************************************************************/
497 static void force_flush_samr_cache(DISP_INFO *disp_info)
499 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
503 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
504 TALLOC_FREE(disp_info->cache_timeout_event);
505 free_samr_cache(disp_info);
508 /*******************************************************************
509 Ensure password info is never given out. Paranioa... JRA.
510 ********************************************************************/
512 static void samr_clear_sam_passwd(struct samu *sam_pass)
518 /* These now zero out the old password */
520 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
521 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
524 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
526 struct samr_displayentry *entry;
528 if (info->builtin_domain) {
529 /* No users in builtin. */
533 if (info->users == NULL) {
534 info->users = pdb_search_users(acct_flags);
535 if (info->users == NULL) {
539 /* Fetch the last possible entry, thus trigger an enumeration */
540 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
542 /* Ensure we cache this enumeration. */
543 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
545 return info->users->num_entries;
548 static uint32 count_sam_groups(struct disp_info *info)
550 struct samr_displayentry *entry;
552 if (info->builtin_domain) {
553 /* No groups in builtin. */
557 if (info->groups == NULL) {
558 info->groups = pdb_search_groups();
559 if (info->groups == NULL) {
563 /* Fetch the last possible entry, thus trigger an enumeration */
564 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
566 /* Ensure we cache this enumeration. */
567 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
569 return info->groups->num_entries;
572 static uint32 count_sam_aliases(struct disp_info *info)
574 struct samr_displayentry *entry;
576 if (info->aliases == NULL) {
577 info->aliases = pdb_search_aliases(&info->sid);
578 if (info->aliases == NULL) {
582 /* Fetch the last possible entry, thus trigger an enumeration */
583 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
585 /* Ensure we cache this enumeration. */
586 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
588 return info->aliases->num_entries;
591 /*******************************************************************
593 ********************************************************************/
595 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
597 if (!close_policy_hnd(p, r->in.handle)) {
598 return NT_STATUS_INVALID_HANDLE;
601 ZERO_STRUCTP(r->out.handle);
606 /*******************************************************************
608 ********************************************************************/
610 NTSTATUS _samr_OpenDomain(pipes_struct *p,
611 struct samr_OpenDomain *r)
613 struct samr_info *info;
614 SEC_DESC *psd = NULL;
616 uint32 des_access = r->in.access_mask;
621 /* find the connection policy handle. */
623 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
624 return NT_STATUS_INVALID_HANDLE;
626 status = access_check_samr_function(info->acc_granted,
627 SAMR_ACCESS_OPEN_DOMAIN,
628 "_samr_OpenDomain" );
630 if ( !NT_STATUS_IS_OK(status) )
633 /*check if access can be granted as requested by client. */
634 map_max_allowed_access(p->server_info->ptok, &des_access);
636 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
637 se_map_generic( &des_access, &dom_generic_mapping );
639 se_priv_copy( &se_rights, &se_machine_account );
640 se_priv_add( &se_rights, &se_add_users );
642 status = access_check_samr_object( psd, p->server_info->ptok,
643 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
644 &acc_granted, "_samr_OpenDomain" );
646 if ( !NT_STATUS_IS_OK(status) )
649 if (!sid_check_is_domain(r->in.sid) &&
650 !sid_check_is_builtin(r->in.sid)) {
651 return NT_STATUS_NO_SUCH_DOMAIN;
654 /* associate the domain SID with the (unique) handle. */
655 if ((info = get_samr_info_by_sid(r->in.sid))==NULL)
656 return NT_STATUS_NO_MEMORY;
657 info->acc_granted = acc_granted;
659 /* get a (unique) handle. open a policy on it. */
660 if (!create_policy_hnd(p, r->out.domain_handle, free_samr_info, (void *)info))
661 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
663 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
668 /*******************************************************************
670 ********************************************************************/
672 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
673 struct samr_GetUserPwInfo *r)
675 struct samr_info *info = NULL;
676 enum lsa_SidType sid_type;
677 uint32_t min_password_length = 0;
678 uint32_t password_properties = 0;
682 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
684 /* find the policy handle. open a policy on it. */
685 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info)) {
686 return NT_STATUS_INVALID_HANDLE;
689 status = access_check_samr_function(info->acc_granted,
690 SAMR_USER_ACCESS_GET_ATTRIBUTES,
691 "_samr_GetUserPwInfo" );
692 if (!NT_STATUS_IS_OK(status)) {
696 if (!sid_check_is_in_our_domain(&info->sid)) {
697 return NT_STATUS_OBJECT_TYPE_MISMATCH;
701 ret = lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, &sid_type);
704 return NT_STATUS_NO_SUCH_USER;
710 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
711 &min_password_length);
712 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
713 &password_properties);
716 if (lp_check_password_script() && *lp_check_password_script()) {
717 password_properties |= DOMAIN_PASSWORD_COMPLEX;
725 r->out.info->min_password_length = min_password_length;
726 r->out.info->password_properties = password_properties;
728 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
733 /*******************************************************************
734 ********************************************************************/
736 static bool get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol,
737 DOM_SID *sid, uint32 *acc_granted,
738 DISP_INFO **ppdisp_info)
740 struct samr_info *info = NULL;
742 /* find the policy handle. open a policy on it. */
743 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
750 *acc_granted = info->acc_granted;
752 *ppdisp_info = info->disp_info;
758 /*******************************************************************
760 ********************************************************************/
762 NTSTATUS _samr_SetSecurity(pipes_struct *p,
763 struct samr_SetSecurity *r)
766 uint32 acc_granted, i;
769 struct samu *sampass=NULL;
772 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
773 return NT_STATUS_INVALID_HANDLE;
775 if (!(sampass = samu_new( p->mem_ctx))) {
776 DEBUG(0,("No memory!\n"));
777 return NT_STATUS_NO_MEMORY;
780 /* get the user record */
782 ret = pdb_getsampwsid(sampass, &pol_sid);
786 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
787 TALLOC_FREE(sampass);
788 return NT_STATUS_INVALID_HANDLE;
791 dacl = r->in.sdbuf->sd->dacl;
792 for (i=0; i < dacl->num_aces; i++) {
793 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
794 ret = pdb_set_pass_can_change(sampass,
795 (dacl->aces[i].access_mask &
796 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
803 TALLOC_FREE(sampass);
804 return NT_STATUS_ACCESS_DENIED;
807 status = access_check_samr_function(acc_granted,
808 SAMR_USER_ACCESS_SET_ATTRIBUTES,
809 "_samr_SetSecurity");
810 if (NT_STATUS_IS_OK(status)) {
812 status = pdb_update_sam_account(sampass);
816 TALLOC_FREE(sampass);
821 /*******************************************************************
822 build correct perms based on policies and password times for _samr_query_sec_obj
823 *******************************************************************/
824 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
826 struct samu *sampass=NULL;
829 if ( !(sampass = samu_new( mem_ctx )) ) {
830 DEBUG(0,("No memory!\n"));
835 ret = pdb_getsampwsid(sampass, user_sid);
839 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
840 TALLOC_FREE(sampass);
844 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
846 if (pdb_get_pass_can_change(sampass)) {
847 TALLOC_FREE(sampass);
850 TALLOC_FREE(sampass);
855 /*******************************************************************
857 ********************************************************************/
859 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
860 struct samr_QuerySecurity *r)
864 SEC_DESC * psd = NULL;
869 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
870 return NT_STATUS_INVALID_HANDLE;
872 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
873 sid_string_dbg(&pol_sid)));
875 status = access_check_samr_function(acc_granted,
876 STD_RIGHT_READ_CONTROL_ACCESS,
877 "_samr_QuerySecurity");
878 if (!NT_STATUS_IS_OK(status)) {
882 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
884 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
885 if (pol_sid.sid_rev_num == 0) {
886 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
887 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
888 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
889 /* check if it is our domain SID */
890 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
891 "with SID: %s\n", sid_string_dbg(&pol_sid)));
892 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
893 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
894 /* check if it is the Builtin Domain */
895 /* TODO: Builtin probably needs a different SD with restricted write access*/
896 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
897 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
898 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
899 } else if (sid_check_is_in_our_domain(&pol_sid) ||
900 sid_check_is_in_builtin(&pol_sid)) {
901 /* TODO: different SDs have to be generated for aliases groups and users.
902 Currently all three get a default user SD */
903 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
904 "with SID: %s\n", sid_string_dbg(&pol_sid)));
905 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
906 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
907 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
909 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
910 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
913 return NT_STATUS_OBJECT_TYPE_MISMATCH;
916 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
917 return NT_STATUS_NO_MEMORY;
922 /*******************************************************************
923 makes a SAM_ENTRY / UNISTR2* structure from a user list.
924 ********************************************************************/
926 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
927 struct samr_SamEntry **sam_pp,
928 uint32_t num_entries,
930 struct samr_displayentry *entries)
933 struct samr_SamEntry *sam;
937 if (num_entries == 0) {
941 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
943 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
944 return NT_STATUS_NO_MEMORY;
947 for (i = 0; i < num_entries; i++) {
950 * usrmgr expects a non-NULL terminated string with
951 * trust relationships
953 if (entries[i].acct_flags & ACB_DOMTRUST) {
954 init_unistr2(&uni_temp_name, entries[i].account_name,
957 init_unistr2(&uni_temp_name, entries[i].account_name,
961 init_lsa_String(&sam[i].name, entries[i].account_name);
962 sam[i].idx = entries[i].rid;
970 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
972 /*******************************************************************
973 _samr_EnumDomainUsers
974 ********************************************************************/
976 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
977 struct samr_EnumDomainUsers *r)
980 struct samr_info *info = NULL;
982 uint32 enum_context = *r->in.resume_handle;
983 enum remote_arch_types ra_type = get_remote_arch();
984 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
985 uint32 max_entries = max_sam_entries;
986 struct samr_displayentry *entries = NULL;
987 struct samr_SamArray *samr_array = NULL;
988 struct samr_SamEntry *samr_entries = NULL;
990 /* find the policy handle. open a policy on it. */
991 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
992 return NT_STATUS_INVALID_HANDLE;
994 status = access_check_samr_function(info->acc_granted,
995 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
996 "_samr_EnumDomainUsers");
997 if (!NT_STATUS_IS_OK(status)) {
1001 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1003 if (info->builtin_domain) {
1004 /* No users in builtin. */
1005 *r->out.resume_handle = *r->in.resume_handle;
1006 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
1010 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1012 return NT_STATUS_NO_MEMORY;
1014 *r->out.sam = samr_array;
1020 if ((info->disp_info->enum_users != NULL) &&
1021 (info->disp_info->enum_acb_mask != r->in.acct_flags)) {
1022 pdb_search_destroy(info->disp_info->enum_users);
1023 info->disp_info->enum_users = NULL;
1026 if (info->disp_info->enum_users == NULL) {
1027 info->disp_info->enum_users = pdb_search_users(r->in.acct_flags);
1028 info->disp_info->enum_acb_mask = r->in.acct_flags;
1031 if (info->disp_info->enum_users == NULL) {
1032 /* END AS ROOT !!!! */
1034 return NT_STATUS_ACCESS_DENIED;
1037 num_account = pdb_search_entries(info->disp_info->enum_users,
1038 enum_context, max_entries,
1041 /* END AS ROOT !!!! */
1045 if (num_account == 0) {
1046 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1047 "total entries\n"));
1048 *r->out.resume_handle = *r->in.resume_handle;
1049 return NT_STATUS_OK;
1052 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
1053 num_account, enum_context,
1055 if (!NT_STATUS_IS_OK(status)) {
1059 if (max_entries <= num_account) {
1060 status = STATUS_MORE_ENTRIES;
1062 status = NT_STATUS_OK;
1065 /* Ensure we cache this enumeration. */
1066 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1068 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
1070 samr_array->count = num_account;
1071 samr_array->entries = samr_entries;
1073 *r->out.resume_handle = *r->in.resume_handle + num_account;
1074 *r->out.num_entries = num_account;
1076 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1081 /*******************************************************************
1082 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1083 ********************************************************************/
1085 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1086 struct samr_SamEntry **sam_pp,
1087 uint32_t num_sam_entries,
1088 struct samr_displayentry *entries)
1090 struct samr_SamEntry *sam;
1095 if (num_sam_entries == 0) {
1099 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1104 for (i = 0; i < num_sam_entries; i++) {
1106 * JRA. I think this should include the null. TNG does not.
1108 init_lsa_String(&sam[i].name, entries[i].account_name);
1109 sam[i].idx = entries[i].rid;
1115 /*******************************************************************
1116 _samr_EnumDomainGroups
1117 ********************************************************************/
1119 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1120 struct samr_EnumDomainGroups *r)
1123 struct samr_info *info = NULL;
1124 struct samr_displayentry *groups;
1126 struct samr_SamArray *samr_array = NULL;
1127 struct samr_SamEntry *samr_entries = NULL;
1129 /* find the policy handle. open a policy on it. */
1130 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1131 return NT_STATUS_INVALID_HANDLE;
1133 status = access_check_samr_function(info->acc_granted,
1134 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1135 "_samr_EnumDomainGroups");
1136 if (!NT_STATUS_IS_OK(status)) {
1140 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1142 if (info->builtin_domain) {
1143 /* No groups in builtin. */
1144 *r->out.resume_handle = *r->in.resume_handle;
1145 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1149 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1151 return NT_STATUS_NO_MEMORY;
1154 /* the domain group array is being allocated in the function below */
1158 if (info->disp_info->groups == NULL) {
1159 info->disp_info->groups = pdb_search_groups();
1161 if (info->disp_info->groups == NULL) {
1163 return NT_STATUS_ACCESS_DENIED;
1167 num_groups = pdb_search_entries(info->disp_info->groups,
1168 *r->in.resume_handle,
1169 MAX_SAM_ENTRIES, &groups);
1172 /* Ensure we cache this enumeration. */
1173 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1175 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1176 num_groups, groups);
1178 samr_array->count = num_groups;
1179 samr_array->entries = samr_entries;
1181 *r->out.sam = samr_array;
1182 *r->out.num_entries = num_groups;
1183 /* this was missing, IMHO:
1184 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1187 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1192 /*******************************************************************
1193 _samr_EnumDomainAliases
1194 ********************************************************************/
1196 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1197 struct samr_EnumDomainAliases *r)
1200 struct samr_info *info;
1201 struct samr_displayentry *aliases;
1202 uint32 num_aliases = 0;
1203 struct samr_SamArray *samr_array = NULL;
1204 struct samr_SamEntry *samr_entries = NULL;
1206 /* find the policy handle. open a policy on it. */
1207 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1208 return NT_STATUS_INVALID_HANDLE;
1210 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1211 sid_string_dbg(&info->sid)));
1213 status = access_check_samr_function(info->acc_granted,
1214 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1215 "_samr_EnumDomainAliases");
1216 if (!NT_STATUS_IS_OK(status)) {
1220 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1222 return NT_STATUS_NO_MEMORY;
1227 if (info->disp_info->aliases == NULL) {
1228 info->disp_info->aliases = pdb_search_aliases(&info->sid);
1229 if (info->disp_info->aliases == NULL) {
1231 return NT_STATUS_ACCESS_DENIED;
1235 num_aliases = pdb_search_entries(info->disp_info->aliases,
1236 *r->in.resume_handle,
1237 MAX_SAM_ENTRIES, &aliases);
1240 /* Ensure we cache this enumeration. */
1241 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1243 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1244 num_aliases, aliases);
1246 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1248 samr_array->count = num_aliases;
1249 samr_array->entries = samr_entries;
1251 *r->out.sam = samr_array;
1252 *r->out.num_entries = num_aliases;
1253 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1258 /*******************************************************************
1259 inits a samr_DispInfoGeneral structure.
1260 ********************************************************************/
1262 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1263 struct samr_DispInfoGeneral *r,
1264 uint32_t num_entries,
1266 struct samr_displayentry *entries)
1270 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1272 if (num_entries == 0) {
1273 return NT_STATUS_OK;
1276 r->count = num_entries;
1278 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1280 return NT_STATUS_NO_MEMORY;
1283 for (i = 0; i < num_entries ; i++) {
1285 init_lsa_String(&r->entries[i].account_name,
1286 entries[i].account_name);
1288 init_lsa_String(&r->entries[i].description,
1289 entries[i].description);
1291 init_lsa_String(&r->entries[i].full_name,
1292 entries[i].fullname);
1294 r->entries[i].rid = entries[i].rid;
1295 r->entries[i].acct_flags = entries[i].acct_flags;
1296 r->entries[i].idx = start_idx+i+1;
1299 return NT_STATUS_OK;
1302 /*******************************************************************
1303 inits a samr_DispInfoFull structure.
1304 ********************************************************************/
1306 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1307 struct samr_DispInfoFull *r,
1308 uint32_t num_entries,
1310 struct samr_displayentry *entries)
1314 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1316 if (num_entries == 0) {
1317 return NT_STATUS_OK;
1320 r->count = num_entries;
1322 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1324 return NT_STATUS_NO_MEMORY;
1327 for (i = 0; i < num_entries ; i++) {
1329 init_lsa_String(&r->entries[i].account_name,
1330 entries[i].account_name);
1332 init_lsa_String(&r->entries[i].description,
1333 entries[i].description);
1335 r->entries[i].rid = entries[i].rid;
1336 r->entries[i].acct_flags = entries[i].acct_flags;
1337 r->entries[i].idx = start_idx+i+1;
1340 return NT_STATUS_OK;
1343 /*******************************************************************
1344 inits a samr_DispInfoFullGroups structure.
1345 ********************************************************************/
1347 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1348 struct samr_DispInfoFullGroups *r,
1349 uint32_t num_entries,
1351 struct samr_displayentry *entries)
1355 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1357 if (num_entries == 0) {
1358 return NT_STATUS_OK;
1361 r->count = num_entries;
1363 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1365 return NT_STATUS_NO_MEMORY;
1368 for (i = 0; i < num_entries ; i++) {
1370 init_lsa_String(&r->entries[i].account_name,
1371 entries[i].account_name);
1373 init_lsa_String(&r->entries[i].description,
1374 entries[i].description);
1376 r->entries[i].rid = entries[i].rid;
1377 r->entries[i].acct_flags = entries[i].acct_flags;
1378 r->entries[i].idx = start_idx+i+1;
1381 return NT_STATUS_OK;
1384 /*******************************************************************
1385 inits a samr_DispInfoAscii structure.
1386 ********************************************************************/
1388 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1389 struct samr_DispInfoAscii *r,
1390 uint32_t num_entries,
1392 struct samr_displayentry *entries)
1396 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1398 if (num_entries == 0) {
1399 return NT_STATUS_OK;
1402 r->count = num_entries;
1404 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1406 return NT_STATUS_NO_MEMORY;
1409 for (i = 0; i < num_entries ; i++) {
1411 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1412 entries[i].account_name);
1414 r->entries[i].idx = start_idx+i+1;
1417 return NT_STATUS_OK;
1420 /*******************************************************************
1421 inits a samr_DispInfoAscii structure.
1422 ********************************************************************/
1424 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1425 struct samr_DispInfoAscii *r,
1426 uint32_t num_entries,
1428 struct samr_displayentry *entries)
1432 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1434 if (num_entries == 0) {
1435 return NT_STATUS_OK;
1438 r->count = num_entries;
1440 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1442 return NT_STATUS_NO_MEMORY;
1445 for (i = 0; i < num_entries ; i++) {
1447 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1448 entries[i].account_name);
1450 r->entries[i].idx = start_idx+i+1;
1453 return NT_STATUS_OK;
1456 /*******************************************************************
1457 _samr_QueryDisplayInfo
1458 ********************************************************************/
1460 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1461 struct samr_QueryDisplayInfo *r)
1464 struct samr_info *info = NULL;
1465 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1467 uint32 max_entries = r->in.max_entries;
1468 uint32 enum_context = r->in.start_idx;
1469 uint32 max_size = r->in.buf_size;
1471 union samr_DispInfo *disp_info = r->out.info;
1473 uint32 temp_size=0, total_data_size=0;
1474 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1475 uint32 num_account = 0;
1476 enum remote_arch_types ra_type = get_remote_arch();
1477 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1478 struct samr_displayentry *entries = NULL;
1480 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1482 /* find the policy handle. open a policy on it. */
1483 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1484 return NT_STATUS_INVALID_HANDLE;
1486 if (info->builtin_domain) {
1487 DEBUG(5,("_samr_QueryDisplayInfo: Nothing in BUILTIN\n"));
1488 return NT_STATUS_OK;
1491 status = access_check_samr_function(info->acc_granted,
1492 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1493 "_samr_QueryDisplayInfo");
1494 if (!NT_STATUS_IS_OK(status)) {
1499 * calculate how many entries we will return.
1501 * - the number of entries the client asked
1502 * - our limit on that
1503 * - the starting point (enumeration context)
1504 * - the buffer size the client will accept
1508 * We are a lot more like W2K. Instead of reading the SAM
1509 * each time to find the records we need to send back,
1510 * we read it once and link that copy to the sam handle.
1511 * For large user list (over the MAX_SAM_ENTRIES)
1512 * it's a definitive win.
1513 * second point to notice: between enumerations
1514 * our sam is now the same as it's a snapshoot.
1515 * third point: got rid of the static SAM_USER_21 struct
1516 * no more intermediate.
1517 * con: it uses much more memory, as a full copy is stored
1520 * If you want to change it, think twice and think
1521 * of the second point , that's really important.
1526 if ((r->in.level < 1) || (r->in.level > 5)) {
1527 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1528 (unsigned int)r->in.level ));
1529 return NT_STATUS_INVALID_INFO_CLASS;
1532 /* first limit the number of entries we will return */
1533 if(max_entries > max_sam_entries) {
1534 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1535 "entries, limiting to %d\n", max_entries,
1537 max_entries = max_sam_entries;
1540 /* calculate the size and limit on the number of entries we will
1543 temp_size=max_entries*struct_size;
1545 if (temp_size>max_size) {
1546 max_entries=MIN((max_size/struct_size),max_entries);;
1547 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1548 "only %d entries\n", max_entries));
1553 /* THe following done as ROOT. Don't return without unbecome_root(). */
1555 switch (r->in.level) {
1558 if (info->disp_info->users == NULL) {
1559 info->disp_info->users = pdb_search_users(ACB_NORMAL);
1560 if (info->disp_info->users == NULL) {
1562 return NT_STATUS_ACCESS_DENIED;
1564 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1565 (unsigned int)enum_context ));
1567 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1568 (unsigned int)enum_context ));
1571 num_account = pdb_search_entries(info->disp_info->users,
1572 enum_context, max_entries,
1576 if (info->disp_info->machines == NULL) {
1577 info->disp_info->machines =
1578 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
1579 if (info->disp_info->machines == NULL) {
1581 return NT_STATUS_ACCESS_DENIED;
1583 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1584 (unsigned int)enum_context ));
1586 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1587 (unsigned int)enum_context ));
1590 num_account = pdb_search_entries(info->disp_info->machines,
1591 enum_context, max_entries,
1596 if (info->disp_info->groups == NULL) {
1597 info->disp_info->groups = pdb_search_groups();
1598 if (info->disp_info->groups == NULL) {
1600 return NT_STATUS_ACCESS_DENIED;
1602 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1603 (unsigned int)enum_context ));
1605 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1606 (unsigned int)enum_context ));
1609 num_account = pdb_search_entries(info->disp_info->groups,
1610 enum_context, max_entries,
1615 smb_panic("info class changed");
1621 /* Now create reply structure */
1622 switch (r->in.level) {
1624 disp_ret = init_samr_dispinfo_1(p->mem_ctx, &disp_info->info1,
1625 num_account, enum_context,
1629 disp_ret = init_samr_dispinfo_2(p->mem_ctx, &disp_info->info2,
1630 num_account, enum_context,
1634 disp_ret = init_samr_dispinfo_3(p->mem_ctx, &disp_info->info3,
1635 num_account, enum_context,
1639 disp_ret = init_samr_dispinfo_4(p->mem_ctx, &disp_info->info4,
1640 num_account, enum_context,
1644 disp_ret = init_samr_dispinfo_5(p->mem_ctx, &disp_info->info5,
1645 num_account, enum_context,
1649 smb_panic("info class changed");
1653 if (!NT_STATUS_IS_OK(disp_ret))
1656 /* calculate the total size */
1657 total_data_size=num_account*struct_size;
1659 if (max_entries <= num_account) {
1660 status = STATUS_MORE_ENTRIES;
1662 status = NT_STATUS_OK;
1665 /* Ensure we cache this enumeration. */
1666 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1668 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__));
1670 *r->out.total_size = total_data_size;
1671 *r->out.returned_size = temp_size;
1676 /****************************************************************
1677 _samr_QueryDisplayInfo2
1678 ****************************************************************/
1680 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
1681 struct samr_QueryDisplayInfo2 *r)
1683 struct samr_QueryDisplayInfo q;
1685 q.in.domain_handle = r->in.domain_handle;
1686 q.in.level = r->in.level;
1687 q.in.start_idx = r->in.start_idx;
1688 q.in.max_entries = r->in.max_entries;
1689 q.in.buf_size = r->in.buf_size;
1691 q.out.total_size = r->out.total_size;
1692 q.out.returned_size = r->out.returned_size;
1693 q.out.info = r->out.info;
1695 return _samr_QueryDisplayInfo(p, &q);
1698 /****************************************************************
1699 _samr_QueryDisplayInfo3
1700 ****************************************************************/
1702 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
1703 struct samr_QueryDisplayInfo3 *r)
1705 struct samr_QueryDisplayInfo q;
1707 q.in.domain_handle = r->in.domain_handle;
1708 q.in.level = r->in.level;
1709 q.in.start_idx = r->in.start_idx;
1710 q.in.max_entries = r->in.max_entries;
1711 q.in.buf_size = r->in.buf_size;
1713 q.out.total_size = r->out.total_size;
1714 q.out.returned_size = r->out.returned_size;
1715 q.out.info = r->out.info;
1717 return _samr_QueryDisplayInfo(p, &q);
1720 /*******************************************************************
1721 _samr_QueryAliasInfo
1722 ********************************************************************/
1724 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
1725 struct samr_QueryAliasInfo *r)
1728 struct acct_info info;
1731 union samr_AliasInfo *alias_info = NULL;
1732 const char *alias_name = NULL;
1733 const char *alias_description = NULL;
1735 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1737 alias_info = TALLOC_ZERO_P(p->mem_ctx, union samr_AliasInfo);
1739 return NT_STATUS_NO_MEMORY;
1742 /* find the policy handle. open a policy on it. */
1743 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &sid, &acc_granted, NULL))
1744 return NT_STATUS_INVALID_HANDLE;
1746 status = access_check_samr_function(acc_granted,
1747 SAMR_ALIAS_ACCESS_LOOKUP_INFO,
1748 "_samr_QueryAliasInfo");
1749 if (!NT_STATUS_IS_OK(status)) {
1754 status = pdb_get_aliasinfo(&sid, &info);
1757 if ( !NT_STATUS_IS_OK(status))
1760 /* FIXME: info contains fstrings */
1761 alias_name = talloc_strdup(r, info.acct_name);
1762 alias_description = talloc_strdup(r, info.acct_desc);
1764 switch (r->in.level) {
1766 init_samr_alias_info1(&alias_info->all,
1771 case ALIASINFODESCRIPTION:
1772 init_samr_alias_info3(&alias_info->description,
1776 return NT_STATUS_INVALID_INFO_CLASS;
1779 *r->out.info = alias_info;
1781 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1783 return NT_STATUS_OK;
1786 /*******************************************************************
1788 ********************************************************************/
1790 NTSTATUS _samr_LookupNames(pipes_struct *p,
1791 struct samr_LookupNames *r)
1795 enum lsa_SidType *type;
1797 int num_rids = r->in.num_names;
1800 struct samr_Ids rids, types;
1801 uint32_t num_mapped = 0;
1803 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1805 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL)) {
1806 return NT_STATUS_OBJECT_TYPE_MISMATCH;
1809 status = access_check_samr_function(acc_granted,
1810 0, /* Don't know the acc_bits yet */
1811 "_samr_LookupNames");
1812 if (!NT_STATUS_IS_OK(status)) {
1816 if (num_rids > MAX_SAM_ENTRIES) {
1817 num_rids = MAX_SAM_ENTRIES;
1818 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1821 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1822 NT_STATUS_HAVE_NO_MEMORY(rid);
1824 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1825 NT_STATUS_HAVE_NO_MEMORY(type);
1827 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1828 sid_string_dbg(&pol_sid)));
1830 for (i = 0; i < num_rids; i++) {
1832 status = NT_STATUS_NONE_MAPPED;
1833 type[i] = SID_NAME_UNKNOWN;
1835 rid[i] = 0xffffffff;
1837 if (sid_check_is_builtin(&pol_sid)) {
1838 if (lookup_builtin_name(r->in.names[i].string,
1841 type[i] = SID_NAME_ALIAS;
1844 lookup_global_sam_name(r->in.names[i].string, 0,
1848 if (type[i] != SID_NAME_UNKNOWN) {
1853 if (num_mapped == num_rids) {
1854 status = NT_STATUS_OK;
1855 } else if (num_mapped == 0) {
1856 status = NT_STATUS_NONE_MAPPED;
1858 status = STATUS_SOME_UNMAPPED;
1861 rids.count = num_rids;
1864 types.count = num_rids;
1867 *r->out.rids = rids;
1868 *r->out.types = types;
1870 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1875 /*******************************************************************
1876 _samr_ChangePasswordUser2
1877 ********************************************************************/
1879 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1880 struct samr_ChangePasswordUser2 *r)
1886 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1888 fstrcpy(user_name, r->in.account->string);
1889 fstrcpy(wks, r->in.server->string);
1891 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
1894 * Pass the user through the NT -> unix user mapping
1898 (void)map_username(user_name);
1901 * UNIX username case mangling not required, pass_oem_change
1902 * is case insensitive.
1905 status = pass_oem_change(user_name,
1906 r->in.lm_password->data,
1907 r->in.lm_verifier->hash,
1908 r->in.nt_password->data,
1909 r->in.nt_verifier->hash,
1912 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
1917 /*******************************************************************
1918 _samr_ChangePasswordUser3
1919 ********************************************************************/
1921 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
1922 struct samr_ChangePasswordUser3 *r)
1926 const char *wks = NULL;
1927 uint32 reject_reason;
1928 struct samr_DomInfo1 *dominfo = NULL;
1929 struct samr_ChangeReject *reject = NULL;
1931 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
1933 fstrcpy(user_name, r->in.account->string);
1934 if (r->in.server && r->in.server->string) {
1935 wks = r->in.server->string;
1938 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
1941 * Pass the user through the NT -> unix user mapping
1945 (void)map_username(user_name);
1948 * UNIX username case mangling not required, pass_oem_change
1949 * is case insensitive.
1952 status = pass_oem_change(user_name,
1953 r->in.lm_password->data,
1954 r->in.lm_verifier->hash,
1955 r->in.nt_password->data,
1956 r->in.nt_verifier->hash,
1959 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
1960 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1962 time_t u_expire, u_min_age;
1963 uint32 account_policy_temp;
1965 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
1967 return NT_STATUS_NO_MEMORY;
1970 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
1972 return NT_STATUS_NO_MEMORY;
1979 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
1980 (uint32_t *)&dominfo->min_password_length);
1982 pdb_get_account_policy(AP_PASSWORD_HISTORY,
1983 (uint32_t *)&dominfo->password_history_length);
1985 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
1986 &dominfo->password_properties);
1988 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1989 u_expire = account_policy_temp;
1991 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1992 u_min_age = account_policy_temp;
1998 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
1999 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
2001 if (lp_check_password_script() && *lp_check_password_script()) {
2002 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
2005 reject->reason = reject_reason;
2007 *r->out.dominfo = dominfo;
2008 *r->out.reject = reject;
2011 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2016 /*******************************************************************
2017 makes a SAMR_R_LOOKUP_RIDS structure.
2018 ********************************************************************/
2020 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2022 struct lsa_String **lsa_name_array_p)
2024 struct lsa_String *lsa_name_array = NULL;
2027 *lsa_name_array_p = NULL;
2029 if (num_names != 0) {
2030 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2031 if (!lsa_name_array) {
2036 for (i = 0; i < num_names; i++) {
2037 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2038 init_lsa_String(&lsa_name_array[i], names[i]);
2041 *lsa_name_array_p = lsa_name_array;
2046 /*******************************************************************
2048 ********************************************************************/
2050 NTSTATUS _samr_LookupRids(pipes_struct *p,
2051 struct samr_LookupRids *r)
2055 enum lsa_SidType *attrs = NULL;
2056 uint32 *wire_attrs = NULL;
2058 int num_rids = (int)r->in.num_rids;
2061 struct lsa_Strings names_array;
2062 struct samr_Ids types_array;
2063 struct lsa_String *lsa_names = NULL;
2065 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2067 /* find the policy handle. open a policy on it. */
2068 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2069 return NT_STATUS_INVALID_HANDLE;
2071 status = access_check_samr_function(acc_granted,
2072 0, /* Don't know the acc_bits yet */
2073 "_samr_LookupRids");
2074 if (!NT_STATUS_IS_OK(status)) {
2078 if (num_rids > 1000) {
2079 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2080 "to samba4 idl this is not possible\n", num_rids));
2081 return NT_STATUS_UNSUCCESSFUL;
2085 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2086 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2087 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2089 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2090 return NT_STATUS_NO_MEMORY;
2097 become_root(); /* lookup_sid can require root privs */
2098 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2102 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2103 status = NT_STATUS_OK;
2106 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2108 return NT_STATUS_NO_MEMORY;
2111 /* Convert from enum lsa_SidType to uint32 for wire format. */
2112 for (i = 0; i < num_rids; i++) {
2113 wire_attrs[i] = (uint32)attrs[i];
2116 names_array.count = num_rids;
2117 names_array.names = lsa_names;
2119 types_array.count = num_rids;
2120 types_array.ids = wire_attrs;
2122 *r->out.names = names_array;
2123 *r->out.types = types_array;
2125 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2130 /*******************************************************************
2132 ********************************************************************/
2134 NTSTATUS _samr_OpenUser(pipes_struct *p,
2135 struct samr_OpenUser *r)
2137 struct samu *sampass=NULL;
2139 POLICY_HND domain_pol = *r->in.domain_handle;
2140 POLICY_HND *user_pol = r->out.user_handle;
2141 struct samr_info *info = NULL;
2142 SEC_DESC *psd = NULL;
2144 uint32 des_access = r->in.access_mask;
2150 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2152 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
2153 return NT_STATUS_INVALID_HANDLE;
2155 nt_status = access_check_samr_function(acc_granted,
2156 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2159 if ( !NT_STATUS_IS_OK(nt_status) )
2162 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2163 return NT_STATUS_NO_MEMORY;
2166 /* append the user's RID to it */
2168 if (!sid_append_rid(&sid, r->in.rid))
2169 return NT_STATUS_NO_SUCH_USER;
2171 /* check if access can be granted as requested by client. */
2173 map_max_allowed_access(p->server_info->ptok, &des_access);
2175 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2176 se_map_generic(&des_access, &usr_generic_mapping);
2178 se_priv_copy( &se_rights, &se_machine_account );
2179 se_priv_add( &se_rights, &se_add_users );
2181 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2182 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2183 &acc_granted, "_samr_OpenUser");
2185 if ( !NT_STATUS_IS_OK(nt_status) )
2189 ret=pdb_getsampwsid(sampass, &sid);
2192 /* check that the SID exists in our domain. */
2194 return NT_STATUS_NO_SUCH_USER;
2197 TALLOC_FREE(sampass);
2199 /* associate the user's SID and access bits with the new handle. */
2200 if ((info = get_samr_info_by_sid(&sid)) == NULL)
2201 return NT_STATUS_NO_MEMORY;
2202 info->acc_granted = acc_granted;
2204 /* get a (unique) handle. open a policy on it. */
2205 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
2206 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2208 return NT_STATUS_OK;
2211 /*************************************************************************
2212 *************************************************************************/
2214 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2216 struct lsa_BinaryString **_r)
2218 struct lsa_BinaryString *r;
2221 return NT_STATUS_INVALID_PARAMETER;
2224 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2226 return NT_STATUS_NO_MEMORY;
2229 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2231 return NT_STATUS_NO_MEMORY;
2233 memcpy(r->array, blob->data, blob->length);
2234 r->size = blob->length;
2235 r->length = blob->length;
2238 return NT_STATUS_NO_MEMORY;
2243 return NT_STATUS_OK;
2246 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2247 struct samr_UserInfo5 *r,
2249 DOM_SID *domain_sid)
2251 const DOM_SID *sid_user, *sid_group;
2252 uint32_t rid, primary_gid;
2254 sid_user = pdb_get_user_sid(pw);
2256 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2257 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2258 "the domain sid %s. Failing operation.\n",
2259 pdb_get_username(pw), sid_string_dbg(sid_user),
2260 sid_string_dbg(domain_sid)));
2261 return NT_STATUS_UNSUCCESSFUL;
2265 sid_group = pdb_get_group_sid(pw);
2268 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2269 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2270 "which conflicts with the domain sid %s. Failing operation.\n",
2271 pdb_get_username(pw), sid_string_dbg(sid_group),
2272 sid_string_dbg(domain_sid)));
2273 return NT_STATUS_UNSUCCESSFUL;
2276 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2277 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2278 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2279 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2281 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2282 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2283 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2284 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2285 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2286 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2287 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2288 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2290 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2292 r->primary_gid = primary_gid;
2293 r->acct_flags = pdb_get_acct_ctrl(pw);
2294 r->bad_password_count = pdb_get_bad_password_count(pw);
2295 r->logon_count = pdb_get_logon_count(pw);
2297 return NT_STATUS_OK;
2300 /*************************************************************************
2301 get_user_info_7. Safe. Only gives out account_name.
2302 *************************************************************************/
2304 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2305 struct samr_UserInfo7 *r,
2306 struct samu *smbpass)
2308 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2309 if (!r->account_name.string) {
2310 return NT_STATUS_NO_MEMORY;
2313 return NT_STATUS_OK;
2316 /*************************************************************************
2317 get_user_info_9. Only gives out primary group SID.
2318 *************************************************************************/
2320 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2321 struct samr_UserInfo9 *r,
2322 struct samu *smbpass)
2324 r->primary_gid = pdb_get_group_rid(smbpass);
2326 return NT_STATUS_OK;
2329 /*************************************************************************
2330 get_user_info_16. Safe. Only gives out acb bits.
2331 *************************************************************************/
2333 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2334 struct samr_UserInfo16 *r,
2335 struct samu *smbpass)
2337 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2339 return NT_STATUS_OK;
2342 /*************************************************************************
2343 get_user_info_18. OK - this is the killer as it gives out password info.
2344 Ensure that this is only allowed on an encrypted connection with a root
2346 *************************************************************************/
2348 static NTSTATUS get_user_info_18(pipes_struct *p,
2349 TALLOC_CTX *mem_ctx,
2350 struct samr_UserInfo18 *r,
2353 struct samu *smbpass=NULL;
2358 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2359 return NT_STATUS_ACCESS_DENIED;
2362 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2363 return NT_STATUS_ACCESS_DENIED;
2367 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2370 if ( !(smbpass = samu_new( mem_ctx )) ) {
2371 return NT_STATUS_NO_MEMORY;
2374 ret = pdb_getsampwsid(smbpass, user_sid);
2377 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2378 TALLOC_FREE(smbpass);
2379 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2382 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2384 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2385 TALLOC_FREE(smbpass);
2386 return NT_STATUS_ACCOUNT_DISABLED;
2389 r->lm_pwd_active = true;
2390 r->nt_pwd_active = true;
2391 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2392 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2393 r->password_expired = 0; /* FIXME */
2395 TALLOC_FREE(smbpass);
2397 return NT_STATUS_OK;
2400 /*************************************************************************
2402 *************************************************************************/
2404 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2405 struct samr_UserInfo20 *r,
2406 struct samu *sampass)
2408 const char *munged_dial = NULL;
2411 struct lsa_BinaryString *parameters = NULL;
2415 munged_dial = pdb_get_munged_dial(sampass);
2417 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2418 munged_dial, (int)strlen(munged_dial)));
2421 blob = base64_decode_data_blob(munged_dial);
2423 blob = data_blob_string_const_null("");
2426 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2427 data_blob_free(&blob);
2428 if (!NT_STATUS_IS_OK(status)) {
2432 r->parameters = *parameters;
2434 return NT_STATUS_OK;
2438 /*************************************************************************
2440 *************************************************************************/
2442 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2443 struct samr_UserInfo21 *r,
2445 DOM_SID *domain_sid)
2448 const DOM_SID *sid_user, *sid_group;
2449 uint32_t rid, primary_gid;
2450 NTTIME force_password_change;
2451 time_t must_change_time;
2452 struct lsa_BinaryString *parameters = NULL;
2453 const char *munged_dial = NULL;
2458 sid_user = pdb_get_user_sid(pw);
2460 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2461 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2462 "the domain sid %s. Failing operation.\n",
2463 pdb_get_username(pw), sid_string_dbg(sid_user),
2464 sid_string_dbg(domain_sid)));
2465 return NT_STATUS_UNSUCCESSFUL;
2469 sid_group = pdb_get_group_sid(pw);
2472 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2473 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2474 "which conflicts with the domain sid %s. Failing operation.\n",
2475 pdb_get_username(pw), sid_string_dbg(sid_group),
2476 sid_string_dbg(domain_sid)));
2477 return NT_STATUS_UNSUCCESSFUL;
2480 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2481 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2482 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2483 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2484 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2486 must_change_time = pdb_get_pass_must_change_time(pw);
2487 if (must_change_time == get_time_t_max()) {
2488 unix_to_nt_time_abs(&force_password_change, must_change_time);
2490 unix_to_nt_time(&force_password_change, must_change_time);
2493 munged_dial = pdb_get_munged_dial(pw);
2495 blob = base64_decode_data_blob(munged_dial);
2497 blob = data_blob_string_const_null("");
2500 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2501 data_blob_free(&blob);
2502 if (!NT_STATUS_IS_OK(status)) {
2506 r->force_password_change = force_password_change;
2508 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2509 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2510 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2511 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2512 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2513 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2514 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2515 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2516 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2518 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2519 r->parameters = *parameters;
2521 r->primary_gid = primary_gid;
2522 r->acct_flags = pdb_get_acct_ctrl(pw);
2523 r->bad_password_count = pdb_get_bad_password_count(pw);
2524 r->logon_count = pdb_get_logon_count(pw);
2525 r->fields_present = pdb_build_fields_present(pw);
2526 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2527 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2528 r->country_code = 0;
2530 r->lm_password_set = 0;
2531 r->nt_password_set = 0;
2536 Look at a user on a real NT4 PDC with usrmgr, press
2537 'ok'. Then you will see that fields_present is set to
2538 0x08f827fa. Look at the user immediately after that again,
2539 and you will see that 0x00fffff is returned. This solves
2540 the problem that you get access denied after having looked
2548 return NT_STATUS_OK;
2551 /*******************************************************************
2553 ********************************************************************/
2555 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
2556 struct samr_QueryUserInfo *r)
2559 union samr_UserInfo *user_info = NULL;
2560 struct samr_info *info = NULL;
2564 struct samu *pwd = NULL;
2566 /* search for the handle */
2567 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
2568 return NT_STATUS_INVALID_HANDLE;
2570 status = access_check_samr_function(info->acc_granted,
2571 SAMR_USER_ACCESS_GET_ATTRIBUTES,
2572 "_samr_QueryUserInfo");
2573 if (!NT_STATUS_IS_OK(status)) {
2577 domain_sid = info->sid;
2579 sid_split_rid(&domain_sid, &rid);
2581 if (!sid_check_is_in_our_domain(&info->sid))
2582 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2584 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2585 sid_string_dbg(&info->sid)));
2587 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
2589 return NT_STATUS_NO_MEMORY;
2592 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
2594 if (!(pwd = samu_new(p->mem_ctx))) {
2595 return NT_STATUS_NO_MEMORY;
2599 ret = pdb_getsampwsid(pwd, &info->sid);
2603 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
2605 return NT_STATUS_NO_SUCH_USER;
2608 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
2610 samr_clear_sam_passwd(pwd);
2612 switch (r->in.level) {
2614 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
2617 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
2620 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
2623 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
2626 /* level 18 is special */
2627 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
2630 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
2633 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
2636 status = NT_STATUS_INVALID_INFO_CLASS;
2642 *r->out.info = user_info;
2644 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
2649 /****************************************************************
2650 ****************************************************************/
2652 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
2653 struct samr_QueryUserInfo2 *r)
2655 struct samr_QueryUserInfo u;
2657 u.in.user_handle = r->in.user_handle;
2658 u.in.level = r->in.level;
2659 u.out.info = r->out.info;
2661 return _samr_QueryUserInfo(p, &u);
2664 /*******************************************************************
2665 _samr_GetGroupsForUser
2666 ********************************************************************/
2668 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
2669 struct samr_GetGroupsForUser *r)
2671 struct samu *sam_pass=NULL;
2674 struct samr_RidWithAttribute dom_gid;
2675 struct samr_RidWithAttribute *gids = NULL;
2676 uint32 primary_group_rid;
2677 size_t num_groups = 0;
2683 bool success = False;
2685 struct samr_RidWithAttributeArray *rids = NULL;
2688 * from the SID in the request:
2689 * we should send back the list of DOMAIN GROUPS
2690 * the user is a member of
2692 * and only the DOMAIN GROUPS
2693 * no ALIASES !!! neither aliases of the domain
2694 * nor aliases of the builtin SID
2699 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2701 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
2703 return NT_STATUS_NO_MEMORY;
2706 /* find the policy handle. open a policy on it. */
2707 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
2708 return NT_STATUS_INVALID_HANDLE;
2710 result = access_check_samr_function(acc_granted,
2711 SAMR_USER_ACCESS_GET_GROUPS,
2712 "_samr_GetGroupsForUser");
2713 if (!NT_STATUS_IS_OK(result)) {
2717 if (!sid_check_is_in_our_domain(&sid))
2718 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2720 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2721 return NT_STATUS_NO_MEMORY;
2725 ret = pdb_getsampwsid(sam_pass, &sid);
2729 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2730 sid_string_dbg(&sid)));
2731 return NT_STATUS_NO_SUCH_USER;
2736 /* make both calls inside the root block */
2738 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2739 &sids, &unix_gids, &num_groups);
2740 if ( NT_STATUS_IS_OK(result) ) {
2741 success = sid_peek_check_rid(get_global_sam_sid(),
2742 pdb_get_group_sid(sam_pass),
2743 &primary_group_rid);
2747 if (!NT_STATUS_IS_OK(result)) {
2748 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2749 sid_string_dbg(&sid)));
2754 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2755 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2756 pdb_get_username(sam_pass)));
2757 TALLOC_FREE(sam_pass);
2758 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2764 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2766 dom_gid.rid = primary_group_rid;
2767 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2769 for (i=0; i<num_groups; i++) {
2771 if (!sid_peek_check_rid(get_global_sam_sid(),
2772 &(sids[i]), &dom_gid.rid)) {
2773 DEBUG(10, ("Found sid %s not in our domain\n",
2774 sid_string_dbg(&sids[i])));
2778 if (dom_gid.rid == primary_group_rid) {
2779 /* We added the primary group directly from the
2780 * sam_account. The other SIDs are unique from
2781 * enum_group_memberships */
2785 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
2788 rids->count = num_gids;
2791 *r->out.rids = rids;
2793 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
2798 /*******************************************************************
2799 _samr_QueryDomainInfo
2800 ********************************************************************/
2802 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
2803 struct samr_QueryDomainInfo *r)
2805 NTSTATUS status = NT_STATUS_OK;
2806 struct samr_info *info = NULL;
2807 union samr_DomainInfo *dom_info;
2808 time_t u_expire, u_min_age;
2810 time_t u_lock_duration, u_reset_time;
2813 uint32 account_policy_temp;
2818 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
2820 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
2822 return NT_STATUS_NO_MEMORY;
2825 /* find the policy handle. open a policy on it. */
2826 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
2827 return NT_STATUS_INVALID_HANDLE;
2830 status = access_check_samr_function(info->acc_granted,
2831 SAMR_ACCESS_OPEN_DOMAIN,
2832 "_samr_QueryDomainInfo" );
2834 if ( !NT_STATUS_IS_OK(status) )
2837 switch (r->in.level) {
2844 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
2845 (uint32_t *)&dom_info->info1.min_password_length);
2847 pdb_get_account_policy(AP_PASSWORD_HISTORY,
2848 (uint32_t *)&dom_info->info1.password_history_length);
2850 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2851 &dom_info->info1.password_properties);
2853 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2854 u_expire = account_policy_temp;
2856 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2857 u_min_age = account_policy_temp;
2863 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
2864 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
2866 if (lp_check_password_script() && *lp_check_password_script()) {
2867 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
2877 dom_info->general.num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2878 dom_info->general.num_groups = count_sam_groups(info->disp_info);
2879 dom_info->general.num_aliases = count_sam_aliases(info->disp_info);
2881 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
2883 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
2885 if (!pdb_get_seq_num(&seq_num))
2886 seq_num = time(NULL);
2892 server_role = ROLE_DOMAIN_PDC;
2893 if (lp_server_role() == ROLE_DOMAIN_BDC)
2894 server_role = ROLE_DOMAIN_BDC;
2896 dom_info->general.oem_information.string = lp_serverstring();
2897 dom_info->general.domain_name.string = lp_workgroup();
2898 dom_info->general.primary.string = global_myname();
2899 dom_info->general.sequence_num = seq_num;
2900 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
2901 dom_info->general.role = server_role;
2902 dom_info->general.unknown3 = 1;
2913 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2914 u_logout = (time_t)ul;
2921 unix_to_nt_time_abs(&dom_info->info3.force_logoff_time, u_logout);
2925 dom_info->oem.oem_information.string = lp_serverstring();
2928 dom_info->info5.domain_name.string = get_global_sam_name();
2931 /* NT returns its own name when a PDC. win2k and later
2932 * only the name of the PDC if itself is a BDC (samba4
2934 dom_info->info6.primary.string = global_myname();
2937 server_role = ROLE_DOMAIN_PDC;
2938 if (lp_server_role() == ROLE_DOMAIN_BDC)
2939 server_role = ROLE_DOMAIN_BDC;
2941 dom_info->info7.role = server_role;
2949 if (!pdb_get_seq_num(&seq_num)) {
2950 seq_num = time(NULL);
2957 dom_info->info8.sequence_num = seq_num;
2958 dom_info->info8.domain_create_time = 0;
2967 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
2968 u_lock_duration = account_policy_temp;
2969 if (u_lock_duration != -1) {
2970 u_lock_duration *= 60;
2973 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
2974 u_reset_time = account_policy_temp * 60;
2976 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
2977 (uint32_t *)&dom_info->info12.lockout_threshold);
2983 unix_to_nt_time_abs(&dom_info->info12.lockout_duration,
2985 unix_to_nt_time_abs(&dom_info->info12.lockout_window,
2990 return NT_STATUS_INVALID_INFO_CLASS;
2993 *r->out.info = dom_info;
2995 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
3000 /* W2k3 seems to use the same check for all 3 objects that can be created via
3001 * SAMR, if you try to create for example "Dialup" as an alias it says
3002 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
3005 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
3007 enum lsa_SidType type;
3010 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
3013 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3014 * whether the name already exists */
3015 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3016 NULL, NULL, NULL, &type);
3020 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3021 return NT_STATUS_OK;
3024 DEBUG(5, ("trying to create %s, exists as %s\n",
3025 new_name, sid_type_lookup(type)));
3027 if (type == SID_NAME_DOM_GRP) {
3028 return NT_STATUS_GROUP_EXISTS;
3030 if (type == SID_NAME_ALIAS) {
3031 return NT_STATUS_ALIAS_EXISTS;
3034 /* Yes, the default is NT_STATUS_USER_EXISTS */
3035 return NT_STATUS_USER_EXISTS;
3038 /*******************************************************************
3040 ********************************************************************/
3042 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3043 struct samr_CreateUser2 *r)
3045 const char *account = NULL;
3047 POLICY_HND dom_pol = *r->in.domain_handle;
3048 uint32_t acb_info = r->in.acct_flags;
3049 POLICY_HND *user_pol = r->out.user_handle;
3050 struct samr_info *info = NULL;
3055 /* check this, when giving away 'add computer to domain' privs */
3056 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3057 bool can_add_account = False;
3059 DISP_INFO *disp_info = NULL;
3061 /* Get the domain SID stored in the domain policy */
3062 if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
3064 return NT_STATUS_INVALID_HANDLE;
3066 if (disp_info->builtin_domain) {
3067 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3068 return NT_STATUS_ACCESS_DENIED;
3071 nt_status = access_check_samr_function(acc_granted,
3072 SAMR_DOMAIN_ACCESS_CREATE_USER,
3073 "_samr_CreateUser2");
3074 if (!NT_STATUS_IS_OK(nt_status)) {
3078 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3079 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3080 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3081 this parameter is not an account type */
3082 return NT_STATUS_INVALID_PARAMETER;
3085 account = r->in.account_name->string;
3086 if (account == NULL) {
3087 return NT_STATUS_NO_MEMORY;
3090 nt_status = can_create(p->mem_ctx, account);
3091 if (!NT_STATUS_IS_OK(nt_status)) {
3095 /* determine which user right we need to check based on the acb_info */
3097 if ( acb_info & ACB_WSTRUST )
3099 se_priv_copy( &se_rights, &se_machine_account );
3100 can_add_account = user_has_privileges(
3101 p->server_info->ptok, &se_rights );
3103 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3104 account for domain trusts and changes the ACB flags later */
3105 else if ( acb_info & ACB_NORMAL &&
3106 (account[strlen(account)-1] != '$') )
3108 se_priv_copy( &se_rights, &se_add_users );
3109 can_add_account = user_has_privileges(
3110 p->server_info->ptok, &se_rights );
3112 else /* implicit assumption of a BDC or domain trust account here
3113 * (we already check the flags earlier) */
3115 if ( lp_enable_privileges() ) {
3116 /* only Domain Admins can add a BDC or domain trust */
3117 se_priv_copy( &se_rights, &se_priv_none );
3118 can_add_account = nt_token_check_domain_rid(
3119 p->server_info->ptok,
3120 DOMAIN_GROUP_RID_ADMINS );
3124 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3125 uidtoname(p->server_info->utok.uid),
3126 can_add_account ? "True":"False" ));
3128 /********** BEGIN Admin BLOCK **********/
3130 if ( can_add_account )
3133 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3136 if ( can_add_account )
3139 /********** END Admin BLOCK **********/
3141 /* now check for failure */
3143 if ( !NT_STATUS_IS_OK(nt_status) )
3146 /* Get the user's SID */
3148 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3150 map_max_allowed_access(p->server_info->ptok, &des_access);
3152 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3153 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3154 se_map_generic(&des_access, &usr_generic_mapping);
3156 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3157 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3158 &acc_granted, "_samr_CreateUser2");
3160 if ( !NT_STATUS_IS_OK(nt_status) ) {
3164 /* associate the user's SID with the new handle. */
3165 if ((info = get_samr_info_by_sid(&sid)) == NULL) {
3166 return NT_STATUS_NO_MEMORY;
3171 info->acc_granted = acc_granted;
3173 /* get a (unique) handle. open a policy on it. */
3174 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info)) {
3175 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3178 /* After a "set" ensure we have no cached display info. */
3179 force_flush_samr_cache(info->disp_info);
3181 *r->out.access_granted = acc_granted;
3183 return NT_STATUS_OK;
3186 /****************************************************************
3187 ****************************************************************/
3189 NTSTATUS _samr_CreateUser(pipes_struct *p,
3190 struct samr_CreateUser *r)
3192 struct samr_CreateUser2 c;
3193 uint32_t access_granted;
3195 c.in.domain_handle = r->in.domain_handle;
3196 c.in.account_name = r->in.account_name;
3197 c.in.acct_flags = ACB_NORMAL;
3198 c.in.access_mask = r->in.access_mask;
3199 c.out.user_handle = r->out.user_handle;
3200 c.out.access_granted = &access_granted;
3201 c.out.rid = r->out.rid;
3203 return _samr_CreateUser2(p, &c);
3206 /*******************************************************************
3208 ********************************************************************/
3210 NTSTATUS _samr_Connect(pipes_struct *p,
3211 struct samr_Connect *r)
3213 struct samr_info *info = NULL;
3214 uint32 des_access = r->in.access_mask;
3218 if (!pipe_access_check(p)) {
3219 DEBUG(3, ("access denied to _samr_Connect\n"));
3220 return NT_STATUS_ACCESS_DENIED;
3223 /* set up the SAMR connect_anon response */
3225 /* associate the user's SID with the new handle. */
3226 if ((info = get_samr_info_by_sid(NULL)) == NULL)
3227 return NT_STATUS_NO_MEMORY;
3229 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3230 was observed from a win98 client trying to enumerate users (when configured
3231 user level access control on shares) --jerry */
3233 map_max_allowed_access(p->server_info->ptok, &des_access);
3235 se_map_generic( &des_access, &sam_generic_mapping );
3236 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
3238 /* get a (unique) handle. open a policy on it. */
3239 if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
3240 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3242 return NT_STATUS_OK;
3245 /*******************************************************************
3247 ********************************************************************/
3249 NTSTATUS _samr_Connect2(pipes_struct *p,
3250 struct samr_Connect2 *r)
3252 struct samr_info *info = NULL;
3253 SEC_DESC *psd = NULL;
3255 uint32 des_access = r->in.access_mask;
3258 const char *fn = "_samr_Connect2";
3260 switch (p->hdr_req.opnum) {
3261 case NDR_SAMR_CONNECT2:
3262 fn = "_samr_Connect2";
3264 case NDR_SAMR_CONNECT4:
3265 fn = "_samr_Connect4";
3267 case NDR_SAMR_CONNECT5:
3268 fn = "_samr_Connect5";
3272 DEBUG(5,("%s: %d\n", fn, __LINE__));
3276 if (!pipe_access_check(p)) {
3277 DEBUG(3, ("access denied to %s\n", fn));
3278 return NT_STATUS_ACCESS_DENIED;
3281 map_max_allowed_access(p->server_info->ptok, &des_access);
3283 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3284 se_map_generic(&des_access, &sam_generic_mapping);
3286 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3287 NULL, 0, des_access, &acc_granted, fn);
3289 if ( !NT_STATUS_IS_OK(nt_status) )
3292 /* associate the user's SID and access granted with the new handle. */
3293 if ((info = get_samr_info_by_sid(NULL)) == NULL)
3294 return NT_STATUS_NO_MEMORY;
3296 info->acc_granted = acc_granted;
3297 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3299 /* get a (unique) handle. open a policy on it. */
3300 if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
3301 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3303 DEBUG(5,("%s: %d\n", fn, __LINE__));
3308 /*******************************************************************
3310 ********************************************************************/
3312 NTSTATUS _samr_Connect4(pipes_struct *p,
3313 struct samr_Connect4 *r)
3315 struct samr_Connect2 c;
3317 c.in.system_name = r->in.system_name;
3318 c.in.access_mask = r->in.access_mask;
3319 c.out.connect_handle = r->out.connect_handle;
3321 return _samr_Connect2(p, &c);
3324 /*******************************************************************
3326 ********************************************************************/
3328 NTSTATUS _samr_Connect5(pipes_struct *p,
3329 struct samr_Connect5 *r)
3332 struct samr_Connect2 c;
3333 struct samr_ConnectInfo1 info1;
3335 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3338 c.in.system_name = r->in.system_name;
3339 c.in.access_mask = r->in.access_mask;
3340 c.out.connect_handle = r->out.connect_handle;
3342 status = _samr_Connect2(p, &c);
3343 if (!NT_STATUS_IS_OK(status)) {
3347 *r->out.level_out = 1;
3348 r->out.info_out->info1 = info1;
3350 return NT_STATUS_OK;
3353 /**********************************************************************
3355 **********************************************************************/
3357 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3358 struct samr_LookupDomain *r)
3360 NTSTATUS status = NT_STATUS_OK;
3361 struct samr_info *info;
3362 const char *domain_name;
3363 DOM_SID *sid = NULL;
3365 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3366 return NT_STATUS_INVALID_HANDLE;
3368 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
3369 Reverted that change so we will work with RAS servers again */
3371 status = access_check_samr_function(info->acc_granted,
3372 SAMR_ACCESS_OPEN_DOMAIN,
3373 "_samr_LookupDomain");
3374 if (!NT_STATUS_IS_OK(status)) {
3378 domain_name = r->in.domain_name->string;
3380 return NT_STATUS_INVALID_PARAMETER;
3383 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
3385 return NT_STATUS_NO_MEMORY;
3388 if (strequal(domain_name, builtin_domain_name())) {
3389 sid_copy(sid, &global_sid_Builtin);
3391 if (!secrets_fetch_domain_sid(domain_name, sid)) {
3392 status = NT_STATUS_NO_SUCH_DOMAIN;
3396 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
3397 sid_string_dbg(sid)));
3404 /**********************************************************************
3406 **********************************************************************/
3408 NTSTATUS _samr_EnumDomains(pipes_struct *p,
3409 struct samr_EnumDomains *r)
3412 struct samr_info *info;
3413 uint32_t num_entries = 2;
3414 struct samr_SamEntry *entry_array = NULL;
3415 struct samr_SamArray *sam;
3417 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
3418 return NT_STATUS_INVALID_HANDLE;
3420 status = access_check_samr_function(info->acc_granted,
3421 SAMR_ACCESS_ENUM_DOMAINS,
3422 "_samr_EnumDomains");
3423 if (!NT_STATUS_IS_OK(status)) {
3427 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
3429 return NT_STATUS_NO_MEMORY;
3432 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
3433 struct samr_SamEntry,
3436 return NT_STATUS_NO_MEMORY;
3439 entry_array[0].idx = 0;
3440 init_lsa_String(&entry_array[0].name, get_global_sam_name());
3442 entry_array[1].idx = 1;
3443 init_lsa_String(&entry_array[1].name, "Builtin");
3445 sam->count = num_entries;
3446 sam->entries = entry_array;
3449 *r->out.num_entries = num_entries;
3454 /*******************************************************************
3456 ********************************************************************/
3458 NTSTATUS _samr_OpenAlias(pipes_struct *p,
3459 struct samr_OpenAlias *r)
3462 POLICY_HND domain_pol = *r->in.domain_handle;
3463 uint32 alias_rid = r->in.rid;
3464 POLICY_HND *alias_pol = r->out.alias_handle;
3465 struct samr_info *info = NULL;
3466 SEC_DESC *psd = NULL;
3468 uint32 des_access = r->in.access_mask;
3473 /* find the domain policy and get the SID / access bits stored in the domain policy */
3475 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
3476 return NT_STATUS_INVALID_HANDLE;
3478 status = access_check_samr_function(acc_granted,
3479 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
3482 if ( !NT_STATUS_IS_OK(status) )
3485 /* append the alias' RID to it */
3487 if (!sid_append_rid(&sid, alias_rid))
3488 return NT_STATUS_NO_SUCH_ALIAS;
3490 /*check if access can be granted as requested by client. */
3492 map_max_allowed_access(p->server_info->ptok, &des_access);
3494 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3495 se_map_generic(&des_access,&ali_generic_mapping);
3497 se_priv_copy( &se_rights, &se_add_users );
3500 status = access_check_samr_object(psd, p->server_info->ptok,
3501 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3502 &acc_granted, "_samr_OpenAlias");
3504 if ( !NT_STATUS_IS_OK(status) )
3508 /* Check we actually have the requested alias */
3509 enum lsa_SidType type;
3514 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3517 if (!result || (type != SID_NAME_ALIAS)) {
3518 return NT_STATUS_NO_SUCH_ALIAS;
3521 /* make sure there is a mapping */
3523 if ( !sid_to_gid( &sid, &gid ) ) {
3524 return NT_STATUS_NO_SUCH_ALIAS;
3529 /* associate the alias SID with the new handle. */
3530 if ((info = get_samr_info_by_sid(&sid)) == NULL)
3531 return NT_STATUS_NO_MEMORY;
3533 info->acc_granted = acc_granted;
3535 /* get a (unique) handle. open a policy on it. */
3536 if (!create_policy_hnd(p, alias_pol, free_samr_info, (void *)info))
3537 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3539 return NT_STATUS_OK;
3542 /*******************************************************************
3544 ********************************************************************/
3546 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3547 struct samr_UserInfo7 *id7,
3553 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3554 return NT_STATUS_ACCESS_DENIED;
3557 if (!id7->account_name.string) {
3558 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3559 return NT_STATUS_ACCESS_DENIED;
3562 /* check to see if the new username already exists. Note: we can't
3563 reliably lock all backends, so there is potentially the
3564 possibility that a user can be created in between this check and
3565 the rename. The rename should fail, but may not get the
3566 exact same failure status code. I think this is small enough
3567 of a window for this type of operation and the results are
3568 simply that the rename fails with a slightly different status
3569 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3571 rc = can_create(mem_ctx, id7->account_name.string);
3572 if (!NT_STATUS_IS_OK(rc)) {
3576 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
3581 /*******************************************************************
3583 ********************************************************************/
3585 static bool set_user_info_16(struct samr_UserInfo16 *id16,
3589 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3593 /* FIX ME: check if the value is really changed --metze */
3594 if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
3598 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3605 /*******************************************************************
3607 ********************************************************************/
3609 static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
3610 TALLOC_CTX *mem_ctx,
3611 DATA_BLOB *session_key,
3615 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3616 return NT_STATUS_INVALID_PARAMETER;
3619 if (id18->nt_pwd_active || id18->lm_pwd_active) {
3620 if (!session_key->length) {
3621 return NT_STATUS_NO_USER_SESSION_KEY;
3625 if (id18->nt_pwd_active) {
3629 in = data_blob_const(id18->nt_pwd.hash, 16);
3630 out = data_blob_talloc_zero(mem_ctx, 16);
3632 sess_crypt_blob(&out, &in, session_key, false);
3634 if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
3635 return NT_STATUS_ACCESS_DENIED;
3638 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3641 if (id18->lm_pwd_active) {
3645 in = data_blob_const(id18->lm_pwd.hash, 16);
3646 out = data_blob_talloc_zero(mem_ctx, 16);
3648 sess_crypt_blob(&out, &in, session_key, false);
3650 if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
3651 return NT_STATUS_ACCESS_DENIED;
3654 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3657 if (id18->password_expired) {
3658 pdb_set_pass_last_set_time(pwd, 0, PDB_CHANGED);
3661 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
3664 return pdb_update_sam_account(pwd);
3667 /*******************************************************************
3669 ********************************************************************/
3671 static bool set_user_info_20(struct samr_UserInfo20 *id20,
3675 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3679 copy_id20_to_sam_passwd(pwd, id20);
3681 /* write the change out */
3682 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3689 /*******************************************************************
3691 ********************************************************************/
3693 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
3694 struct samr_UserInfo21 *id21,
3700 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3701 return NT_STATUS_INVALID_PARAMETER;
3704 if (id21->fields_present == 0) {
3705 return NT_STATUS_INVALID_PARAMETER;
3708 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3709 return NT_STATUS_ACCESS_DENIED;
3712 /* we need to separately check for an account rename first */
3714 if (id21->account_name.string &&
3715 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
3718 /* check to see if the new username already exists. Note: we can't
3719 reliably lock all backends, so there is potentially the
3720 possibility that a user can be created in between this check and
3721 the rename. The rename should fail, but may not get the
3722 exact same failure status code. I think this is small enough
3723 of a window for this type of operation and the results are
3724 simply that the rename fails with a slightly different status
3725 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3727 status = can_create(mem_ctx, id21->account_name.string);
3728 if (!NT_STATUS_IS_OK(status)) {
3732 status = pdb_rename_sam_account(pwd, id21->account_name.string);
3734 if (!NT_STATUS_IS_OK(status)) {
3735 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3736 nt_errstr(status)));
3740 /* set the new username so that later
3741 functions can work on the new account */
3742 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
3745 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
3748 * The funny part about the previous two calls is
3749 * that pwd still has the password hashes from the
3750 * passdb entry. These have not been updated from
3751 * id21. I don't know if they need to be set. --jerry
3754 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3755 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3756 if ( !NT_STATUS_IS_OK(status) ) {
3761 /* Don't worry about writing out the user account since the
3762 primary group SID is generated solely from the user's Unix
3765 /* write the change out */
3766 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3770 return NT_STATUS_OK;
3773 /*******************************************************************
3775 ********************************************************************/
3777 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
3778 struct samr_UserInfo23 *id23,
3781 char *plaintext_buf = NULL;
3787 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3788 return NT_STATUS_INVALID_PARAMETER;
3791 if (id23->info.fields_present == 0) {
3792 return NT_STATUS_INVALID_PARAMETER;
3795 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3796 return NT_STATUS_ACCESS_DENIED;
3799 if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
3800 (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
3802 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3803 pdb_get_username(pwd)));
3805 if (!decode_pw_buffer(mem_ctx,
3806 id23->password.data,
3810 return NT_STATUS_WRONG_PASSWORD;
3813 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3814 return NT_STATUS_ACCESS_DENIED;
3818 copy_id23_to_sam_passwd(pwd, id23);
3820 acct_ctrl = pdb_get_acct_ctrl(pwd);
3822 /* if it's a trust account, don't update /etc/passwd */
3823 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3824 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3825 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3826 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3827 } else if (plaintext_buf) {
3828 /* update the UNIX password */
3829 if (lp_unix_password_sync() ) {
3830 struct passwd *passwd;
3831 if (pdb_get_username(pwd) == NULL) {
3832 DEBUG(1, ("chgpasswd: User without name???\n"));
3833 return NT_STATUS_ACCESS_DENIED;
3836 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3837 if (passwd == NULL) {
3838 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3841 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3842 return NT_STATUS_ACCESS_DENIED;
3844 TALLOC_FREE(passwd);
3848 if (plaintext_buf) {
3849 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3852 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3853 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3858 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3862 return NT_STATUS_OK;
3865 /*******************************************************************
3867 ********************************************************************/
3869 static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
3873 char *plaintext_buf = NULL;
3875 time_t last_set_time;
3876 enum pdb_value_state last_set_state;
3878 DEBUG(5, ("Attempting administrator password change for user %s\n",
3879 pdb_get_username(pwd)));
3881 acct_ctrl = pdb_get_acct_ctrl(pwd);
3882 /* we need to know if it's expired, because this is an admin change, not a
3883 user change, so it's still expired when we're done */
3884 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3885 last_set_time = pdb_get_pass_last_set_time(pwd);
3887 if (!decode_pw_buffer(talloc_tos(),
3895 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3899 /* if it's a trust account, don't update /etc/passwd */
3900 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3901 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3902 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3903 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3905 /* update the UNIX password */
3906 if (lp_unix_password_sync()) {
3907 struct passwd *passwd;
3909 if (pdb_get_username(pwd) == NULL) {
3910 DEBUG(1, ("chgpasswd: User without name???\n"));
3914 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3915 if (passwd == NULL) {
3916 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3919 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3922 TALLOC_FREE(passwd);
3926 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3929 * A level 25 change does reset the pwdlastset field, a level 24
3930 * change does not. I know this is probably not the full story, but
3931 * it is needed to make XP join LDAP correctly, without it the later
3932 * auth2 check can fail with PWD_MUST_CHANGE.
3936 * restore last set time as this is an admin change, not a
3939 pdb_set_pass_last_set_time (pwd, last_set_time,
3943 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
3945 /* update the SAMBA password */
3946 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3953 /*******************************************************************
3955 ********************************************************************/
3957 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
3958 struct samr_UserInfo25 *id25,
3964 DEBUG(5, ("set_user_info_25: NULL id25\n"));
3965 return NT_STATUS_INVALID_PARAMETER;
3968 if (id25->info.fields_present == 0) {
3969 return NT_STATUS_INVALID_PARAMETER;
3972 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
3973 return NT_STATUS_ACCESS_DENIED;
3976 copy_id25_to_sam_passwd(pwd, id25);
3978 /* write the change out */
3979 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3984 * We need to "pdb_update_sam_account" before the unix primary group
3985 * is set, because the idealx scripts would also change the
3986 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
3987 * the delete explicit / add explicit, which would then fail to find
3988 * the previous primaryGroupSid value.
3991 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3992 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3993 if ( !NT_STATUS_IS_OK(status) ) {
3998 return NT_STATUS_OK;
4001 /*******************************************************************
4003 ********************************************************************/
4005 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
4006 struct samr_SetUserInfo *r)
4009 struct samu *pwd = NULL;
4011 POLICY_HND *pol = r->in.user_handle;
4012 union samr_UserInfo *info = r->in.info;
4013 uint16_t switch_value = r->in.level;
4014 uint32_t acc_granted;
4015 uint32_t acc_required;
4017 bool has_enough_rights = False;
4019 DISP_INFO *disp_info = NULL;
4021 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4023 /* find the policy handle. open a policy on it. */
4024 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) {
4025 return NT_STATUS_INVALID_HANDLE;
4028 /* This is tricky. A WinXP domain join sets
4029 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4030 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4031 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4032 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4033 we'll use the set from the WinXP join as the basis. */
4035 switch (switch_value) {
4040 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4043 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4044 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4045 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4049 status = access_check_samr_function(acc_granted,
4051 "_samr_SetUserInfo");
4052 if (!NT_STATUS_IS_OK(status)) {
4056 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4057 sid_string_dbg(&sid), switch_value));
4060 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4061 return NT_STATUS_INVALID_INFO_CLASS;
4064 if (!(pwd = samu_new(NULL))) {
4065 return NT_STATUS_NO_MEMORY;
4069 ret = pdb_getsampwsid(pwd, &sid);
4074 return NT_STATUS_NO_SUCH_USER;
4077 /* deal with machine password changes differently from userinfo changes */
4078 /* check to see if we have the sufficient rights */
4080 acb_info = pdb_get_acct_ctrl(pwd);
4081 if (acb_info & ACB_WSTRUST)
4082 has_enough_rights = user_has_privileges(p->server_info->ptok,
4083 &se_machine_account);
4084 else if (acb_info & ACB_NORMAL)
4085 has_enough_rights = user_has_privileges(p->server_info->ptok,
4087 else if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
4088 if (lp_enable_privileges()) {
4089 has_enough_rights = nt_token_check_domain_rid(p->server_info->ptok,
4090 DOMAIN_GROUP_RID_ADMINS);
4094 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4095 uidtoname(p->server_info->utok.uid),
4096 has_enough_rights ? "" : " not"));
4098 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4100 if (has_enough_rights) {
4104 /* ok! user info levels (lots: see MSDEV help), off we go... */
4106 switch (switch_value) {
4109 status = set_user_info_7(p->mem_ctx,
4114 if (!set_user_info_16(&info->info16, pwd)) {
4115 status = NT_STATUS_ACCESS_DENIED;
4120 /* Used by AS/U JRA. */
4121 status = set_user_info_18(&info->info18,
4123 &p->server_info->user_session_key,
4128 if (!set_user_info_20(&info->info20, pwd)) {
4129 status = NT_STATUS_ACCESS_DENIED;
4134 status = set_user_info_21(p->mem_ctx,
4135 &info->info21, pwd);
4139 if (!p->server_info->user_session_key.length) {
4140 status = NT_STATUS_NO_USER_SESSION_KEY;
4142 SamOEMhashBlob(info->info23.password.data, 516,
4143 &p->server_info->user_session_key);
4145 dump_data(100, info->info23.password.data, 516);
4147 status = set_user_info_23(p->mem_ctx,
4148 &info->info23, pwd);
4152 if (!p->server_info->user_session_key.length) {
4153 status = NT_STATUS_NO_USER_SESSION_KEY;
4155 SamOEMhashBlob(info->info24.password.data,
4157 &p->server_info->user_session_key);
4159 dump_data(100, info->info24.password.data, 516);
4161 if (!set_user_info_pw(info->info24.password.data, pwd,
4163 status = NT_STATUS_WRONG_PASSWORD;
4168 if (!p->server_info->user_session_key.length) {
4169 status = NT_STATUS_NO_USER_SESSION_KEY;
4171 encode_or_decode_arc4_passwd_buffer(
4172 info->info25.password.data,
4173 &p->server_info->user_session_key);
4175 dump_data(100, info->info25.password.data, 532);
4177 status = set_user_info_25(p->mem_ctx,
4178 &info->info25, pwd);
4179 if (!NT_STATUS_IS_OK(status)) {
4182 if (!set_user_info_pw(info->info25.password.data, pwd,
4184 status = NT_STATUS_WRONG_PASSWORD;
4189 if (!p->server_info->user_session_key.length) {
4190 status = NT_STATUS_NO_USER_SESSION_KEY;
4192 encode_or_decode_arc4_passwd_buffer(
4193 info->info26.password.data,
4194 &p->server_info->user_session_key);
4196 dump_data(100, info->info26.password.data, 516);
4198 if (!set_user_info_pw(info->info26.password.data, pwd,
4200 status = NT_STATUS_WRONG_PASSWORD;
4205 status = NT_STATUS_INVALID_INFO_CLASS;
4212 if (has_enough_rights) {
4216 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4218 if (NT_STATUS_IS_OK(status)) {
4219 force_flush_samr_cache(disp_info);
4225 /*******************************************************************
4227 ********************************************************************/
4229 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
4230 struct samr_SetUserInfo2 *r)
4232 struct samr_SetUserInfo q;
4234 q.in.user_handle = r->in.user_handle;
4235 q.in.level = r->in.level;
4236 q.in.info = r->in.info;
4238 return _samr_SetUserInfo(p, &q);
4241 /*********************************************************************
4242 _samr_GetAliasMembership
4243 *********************************************************************/
4245 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
4246 struct samr_GetAliasMembership *r)
4248 size_t num_alias_rids;
4250 struct samr_info *info = NULL;
4258 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
4260 /* find the policy handle. open a policy on it. */
4261 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
4262 return NT_STATUS_INVALID_HANDLE;
4264 ntstatus1 = access_check_samr_function(info->acc_granted,
4265 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
4266 "_samr_GetAliasMembership");
4267 ntstatus2 = access_check_samr_function(info->acc_granted,
4268 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4269 "_samr_GetAliasMembership");
4271 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
4272 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
4273 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
4274 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
4278 if (!sid_check_is_domain(&info->sid) &&
4279 !sid_check_is_builtin(&info->sid))
4280 return NT_STATUS_OBJECT_TYPE_MISMATCH;
4282 if (r->in.sids->num_sids) {
4283 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
4285 if (members == NULL)
4286 return NT_STATUS_NO_MEMORY;
4291 for (i=0; i<r->in.sids->num_sids; i++)
4292 sid_copy(&members[i], r->in.sids->sids[i].sid);
4298 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
4299 r->in.sids->num_sids,
4300 &alias_rids, &num_alias_rids);
4303 if (!NT_STATUS_IS_OK(ntstatus1)) {
4307 r->out.rids->count = num_alias_rids;
4308 r->out.rids->ids = alias_rids;
4310 return NT_STATUS_OK;
4313 /*********************************************************************
4314 _samr_GetMembersInAlias
4315 *********************************************************************/
4317 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
4318 struct samr_GetMembersInAlias *r)
4322 size_t num_sids = 0;
4323 struct lsa_SidPtr *sids = NULL;
4324 DOM_SID *pdb_sids = NULL;
4330 /* find the policy handle. open a policy on it. */
4331 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
4332 return NT_STATUS_INVALID_HANDLE;
4334 status = access_check_samr_function(acc_granted,
4335 SAMR_ALIAS_ACCESS_GET_MEMBERS,
4336 "_samr_GetMembersInAlias");
4337 if (!NT_STATUS_IS_OK(status)) {
4341 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4344 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
4347 if (!NT_STATUS_IS_OK(status)) {
4352 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
4354 TALLOC_FREE(pdb_sids);
4355 return NT_STATUS_NO_MEMORY;
4359 for (i = 0; i < num_sids; i++) {
4360 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
4362 TALLOC_FREE(pdb_sids);
4363 return NT_STATUS_NO_MEMORY;
4367 r->out.sids->num_sids = num_sids;
4368 r->out.sids->sids = sids;
4370 TALLOC_FREE(pdb_sids);
4372 return NT_STATUS_OK;
4375 /*********************************************************************
4376 _samr_QueryGroupMember
4377 *********************************************************************/
4379 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
4380 struct samr_QueryGroupMember *r)
4383 size_t i, num_members;
4391 struct samr_RidTypeArray *rids = NULL;
4393 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
4395 return NT_STATUS_NO_MEMORY;
4398 /* find the policy handle. open a policy on it. */
4399 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
4400 return NT_STATUS_INVALID_HANDLE;
4402 status = access_check_samr_function(acc_granted,
4403 SAMR_GROUP_ACCESS_GET_MEMBERS,
4404 "_samr_QueryGroupMember");
4405 if (!NT_STATUS_IS_OK(status)) {
4409 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4411 if (!sid_check_is_in_our_domain(&group_sid)) {
4412 DEBUG(3, ("sid %s is not in our domain\n",
4413 sid_string_dbg(&group_sid)));
4414 return NT_STATUS_NO_SUCH_GROUP;
4417 DEBUG(10, ("lookup on Domain SID\n"));
4420 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
4421 &rid, &num_members);
4424 if (!NT_STATUS_IS_OK(status))
4428 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
4430 return NT_STATUS_NO_MEMORY;
4436 for (i=0; i<num_members; i++)
4437 attr[i] = SID_NAME_USER;
4439 rids->count = num_members;
4443 *r->out.rids = rids;
4445 return NT_STATUS_OK;
4448 /*********************************************************************
4449 _samr_AddAliasMember
4450 *********************************************************************/
4452 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
4453 struct samr_AddAliasMember *r)
4458 bool can_add_accounts;
4460 DISP_INFO *disp_info = NULL;
4462 /* Find the policy handle. Open a policy on it. */
4463 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4464 return NT_STATUS_INVALID_HANDLE;
4466 status = access_check_samr_function(acc_granted,
4467 SAMR_ALIAS_ACCESS_ADD_MEMBER,
4468 "_samr_AddAliasMember");
4469 if (!NT_STATUS_IS_OK(status)) {
4473 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4475 se_priv_copy( &se_rights, &se_add_users );
4476 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4478 /******** BEGIN SeAddUsers BLOCK *********/
4480 if ( can_add_accounts )
4483 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
4485 if ( can_add_accounts )
4488 /******** END SeAddUsers BLOCK *********/
4490 if (NT_STATUS_IS_OK(status)) {
4491 force_flush_samr_cache(disp_info);
4497 /*********************************************************************
4498 _samr_DeleteAliasMember
4499 *********************************************************************/
4501 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
4502 struct samr_DeleteAliasMember *r)
4507 bool can_add_accounts;
4509 DISP_INFO *disp_info = NULL;
4511 /* Find the policy handle. Open a policy on it. */
4512 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4513 return NT_STATUS_INVALID_HANDLE;
4515 status = access_check_samr_function(acc_granted,
4516 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
4517 "_samr_DeleteAliasMember");
4518 if (!NT_STATUS_IS_OK(status)) {
4522 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4523 sid_string_dbg(&alias_sid)));
4525 se_priv_copy( &se_rights, &se_add_users );
4526 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4528 /******** BEGIN SeAddUsers BLOCK *********/
4530 if ( can_add_accounts )
4533 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
4535 if ( can_add_accounts )
4538 /******** END SeAddUsers BLOCK *********/
4540 if (NT_STATUS_IS_OK(status)) {
4541 force_flush_samr_cache(disp_info);
4547 /*********************************************************************
4548 _samr_AddGroupMember
4549 *********************************************************************/
4551 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
4552 struct samr_AddGroupMember *r)
4559 bool can_add_accounts;
4560 DISP_INFO *disp_info = NULL;
4562 /* Find the policy handle. Open a policy on it. */
4563 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4564 return NT_STATUS_INVALID_HANDLE;
4566 status = access_check_samr_function(acc_granted,
4567 SAMR_GROUP_ACCESS_ADD_MEMBER,
4568 "_samr_AddGroupMember");
4569 if (!NT_STATUS_IS_OK(status)) {
4573 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4575 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4577 return NT_STATUS_INVALID_HANDLE;
4580 se_priv_copy( &se_rights, &se_add_users );
4581 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4583 /******** BEGIN SeAddUsers BLOCK *********/
4585 if ( can_add_accounts )
4588 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
4590 if ( can_add_accounts )
4593 /******** END SeAddUsers BLOCK *********/
4595 force_flush_samr_cache(disp_info);
4600 /*********************************************************************
4601 _samr_DeleteGroupMember
4602 *********************************************************************/
4604 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
4605 struct samr_DeleteGroupMember *r)
4613 bool can_add_accounts;
4614 DISP_INFO *disp_info = NULL;
4617 * delete the group member named r->in.rid
4618 * who is a member of the sid associated with the handle
4619 * the rid is a user's rid as the group is a domain group.
4622 /* Find the policy handle. Open a policy on it. */
4623 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4624 return NT_STATUS_INVALID_HANDLE;
4626 status = access_check_samr_function(acc_granted,
4627 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
4628 "_samr_DeleteGroupMember");
4629 if (!NT_STATUS_IS_OK(status)) {
4633 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4635 return NT_STATUS_INVALID_HANDLE;
4638 se_priv_copy( &se_rights, &se_add_users );
4639 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4641 /******** BEGIN SeAddUsers BLOCK *********/
4643 if ( can_add_accounts )
4646 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
4648 if ( can_add_accounts )
4651 /******** END SeAddUsers BLOCK *********/
4653 force_flush_samr_cache(disp_info);
4658 /*********************************************************************
4660 *********************************************************************/
4662 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4663 struct samr_DeleteUser *r)
4667 struct samu *sam_pass=NULL;
4669 bool can_add_accounts;
4671 DISP_INFO *disp_info = NULL;
4674 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4676 /* Find the policy handle. Open a policy on it. */
4677 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4678 return NT_STATUS_INVALID_HANDLE;
4680 status = access_check_samr_function(acc_granted,
4681 STD_RIGHT_DELETE_ACCESS,
4682 "_samr_DeleteUser");
4683 if (!NT_STATUS_IS_OK(status)) {
4687 if (!sid_check_is_in_our_domain(&user_sid))
4688 return NT_STATUS_CANNOT_DELETE;
4690 /* check if the user exists before trying to delete */
4691 if ( !(sam_pass = samu_new( NULL )) ) {
4692 return NT_STATUS_NO_MEMORY;
4696 ret = pdb_getsampwsid(sam_pass, &user_sid);
4700 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4701 sid_string_dbg(&user_sid)));
4702 TALLOC_FREE(sam_pass);
4703 return NT_STATUS_NO_SUCH_USER;
4706 acb_info = pdb_get_acct_ctrl(sam_pass);
4708 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4709 if ( acb_info & ACB_WSTRUST ) {
4710 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_machine_account );
4712 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
4715 /******** BEGIN SeAddUsers BLOCK *********/
4717 if ( can_add_accounts )
4720 status = pdb_delete_user(p->mem_ctx, sam_pass);
4722 if ( can_add_accounts )
4725 /******** END SeAddUsers BLOCK *********/
4727 if ( !NT_STATUS_IS_OK(status) ) {
4728 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4729 "user %s: %s.\n", pdb_get_username(sam_pass),
4730 nt_errstr(status)));
4731 TALLOC_FREE(sam_pass);
4736 TALLOC_FREE(sam_pass);
4738 if (!close_policy_hnd(p, r->in.user_handle))
4739 return NT_STATUS_OBJECT_NAME_INVALID;
4741 ZERO_STRUCTP(r->out.user_handle);
4743 force_flush_samr_cache(disp_info);
4745 return NT_STATUS_OK;
4748 /*********************************************************************
4749 _samr_DeleteDomainGroup
4750 *********************************************************************/
4752 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4753 struct samr_DeleteDomainGroup *r)
4760 bool can_add_accounts;
4761 DISP_INFO *disp_info = NULL;
4763 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4765 /* Find the policy handle. Open a policy on it. */
4766 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4767 return NT_STATUS_INVALID_HANDLE;
4769 status = access_check_samr_function(acc_granted,
4770 STD_RIGHT_DELETE_ACCESS,
4771 "_samr_DeleteDomainGroup");
4772 if (!NT_STATUS_IS_OK(status)) {
4776 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4778 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4780 return NT_STATUS_NO_SUCH_GROUP;
4783 se_priv_copy( &se_rights, &se_add_users );
4784 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4786 /******** BEGIN SeAddUsers BLOCK *********/
4788 if ( can_add_accounts )
4791 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4793 if ( can_add_accounts )
4796 /******** END SeAddUsers BLOCK *********/
4798 if ( !NT_STATUS_IS_OK(status) ) {
4799 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4800 "entry for group %s: %s\n",
4801 sid_string_dbg(&group_sid),
4802 nt_errstr(status)));
4806 if (!close_policy_hnd(p, r->in.group_handle))
4807 return NT_STATUS_OBJECT_NAME_INVALID;
4809 force_flush_samr_cache(disp_info);
4811 return NT_STATUS_OK;
4814 /*********************************************************************
4815 _samr_DeleteDomAlias
4816 *********************************************************************/
4818 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4819 struct samr_DeleteDomAlias *r)
4824 bool can_add_accounts;
4826 DISP_INFO *disp_info = NULL;
4828 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4830 /* Find the policy handle. Open a policy on it. */
4831 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4832 return NT_STATUS_INVALID_HANDLE;
4834 /* copy the handle to the outgoing reply */
4836 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4838 status = access_check_samr_function(acc_granted,
4839 STD_RIGHT_DELETE_ACCESS,
4840 "_samr_DeleteDomAlias");
4841 if (!NT_STATUS_IS_OK(status)) {
4845 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4847 /* Don't let Windows delete builtin groups */
4849 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4850 return NT_STATUS_SPECIAL_ACCOUNT;
4853 if (!sid_check_is_in_our_domain(&alias_sid))
4854 return NT_STATUS_NO_SUCH_ALIAS;
4856 DEBUG(10, ("lookup on Local SID\n"));
4858 se_priv_copy( &se_rights, &se_add_users );
4859 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4861 /******** BEGIN SeAddUsers BLOCK *********/
4863 if ( can_add_accounts )
4866 /* Have passdb delete the alias */
4867 status = pdb_delete_alias(&alias_sid);
4869 if ( can_add_accounts )
4872 /******** END SeAddUsers BLOCK *********/
4874 if ( !NT_STATUS_IS_OK(status))
4877 if (!close_policy_hnd(p, r->in.alias_handle))
4878 return NT_STATUS_OBJECT_NAME_INVALID;
4880 force_flush_samr_cache(disp_info);
4882 return NT_STATUS_OK;
4885 /*********************************************************************
4886 _samr_CreateDomainGroup
4887 *********************************************************************/
4889 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4890 struct samr_CreateDomainGroup *r)
4897 struct samr_info *info;
4900 bool can_add_accounts;
4901 DISP_INFO *disp_info = NULL;
4903 /* Find the policy handle. Open a policy on it. */
4904 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4905 return NT_STATUS_INVALID_HANDLE;
4907 status = access_check_samr_function(acc_granted,
4908 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
4909 "_samr_CreateDomainGroup");
4910 if (!NT_STATUS_IS_OK(status)) {
4914 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4915 return NT_STATUS_ACCESS_DENIED;
4917 name = r->in.name->string;
4919 return NT_STATUS_NO_MEMORY;
4922 status = can_create(p->mem_ctx, name);
4923 if (!NT_STATUS_IS_OK(status)) {
4927 se_priv_copy( &se_rights, &se_add_users );
4928 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
4930 /******** BEGIN SeAddUsers BLOCK *********/
4932 if ( can_add_accounts )
4935 /* check that we successfully create the UNIX group */
4937 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4939 if ( can_add_accounts )
4942 /******** END SeAddUsers BLOCK *********/
4944 /* check if we should bail out here */
4946 if ( !NT_STATUS_IS_OK(status) )
4949 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
4951 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
4952 return NT_STATUS_NO_MEMORY;
4954 /* they created it; let the user do what he wants with it */
4956 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
4958 /* get a (unique) handle. open a policy on it. */
4959 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
4960 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4962 force_flush_samr_cache(disp_info);
4964 return NT_STATUS_OK;
4967 /*********************************************************************
4968 _samr_CreateDomAlias
4969 *********************************************************************/
4971 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
4972 struct samr_CreateDomAlias *r)
4976 const char *name = NULL;
4977 struct samr_info *info;
4982 bool can_add_accounts;
4983 DISP_INFO *disp_info = NULL;
4985 /* Find the policy handle. Open a policy on it. */
4986 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4987 return NT_STATUS_INVALID_HANDLE;
4989 result = access_check_samr_function(acc_granted,
4990 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
4991 "_samr_CreateDomAlias");
4992 if (!NT_STATUS_IS_OK(result)) {
4996 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4997 return NT_STATUS_ACCESS_DENIED;
4999 name = r->in.alias_name->string;
5001 se_priv_copy( &se_rights, &se_add_users );
5002 can_add_accounts = user_has_privileges( p->server_info->ptok, &se_rights );
5004 result = can_create(p->mem_ctx, name);
5005 if (!NT_STATUS_IS_OK(result)) {
5009 /******** BEGIN SeAddUsers BLOCK *********/
5011 if ( can_add_accounts )
5014 /* Have passdb create the alias */
5015 result = pdb_create_alias(name, r->out.rid);
5017 if ( can_add_accounts )
5020 /******** END SeAddUsers BLOCK *********/
5022 if (!NT_STATUS_IS_OK(result)) {
5023 DEBUG(10, ("pdb_create_alias failed: %s\n",
5024 nt_errstr(result)));
5028 sid_copy(&info_sid, get_global_sam_sid());
5029 sid_append_rid(&info_sid, *r->out.rid);
5031 if (!sid_to_gid(&info_sid, &gid)) {
5032 DEBUG(10, ("Could not find alias just created\n"));
5033 return NT_STATUS_ACCESS_DENIED;
5036 /* check if the group has been successfully created */
5037 if ( getgrgid(gid) == NULL ) {
5038 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5040 return NT_STATUS_ACCESS_DENIED;
5043 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
5044 return NT_STATUS_NO_MEMORY;
5046 /* they created it; let the user do what he wants with it */
5048 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5050 /* get a (unique) handle. open a policy on it. */
5051 if (!create_policy_hnd(p, r->out.alias_handle, free_samr_info, (void *)info))
5052 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5054 force_flush_samr_cache(disp_info);
5056 return NT_STATUS_OK;
5059 /*********************************************************************
5060 _samr_QueryGroupInfo
5061 *********************************************************************/
5063 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5064 struct samr_QueryGroupInfo *r)
5069 union samr_GroupInfo *info = NULL;
5072 uint32_t attributes = SE_GROUP_MANDATORY |
5073 SE_GROUP_ENABLED_BY_DEFAULT |
5075 const char *group_name = NULL;
5076 const char *group_description = NULL;
5078 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5079 return NT_STATUS_INVALID_HANDLE;
5081 status = access_check_samr_function(acc_granted,
5082 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5083 "_samr_QueryGroupInfo");
5084 if (!NT_STATUS_IS_OK(status)) {
5089 ret = get_domain_group_from_sid(group_sid, &map);
5092 return NT_STATUS_INVALID_HANDLE;
5094 /* FIXME: map contains fstrings */
5095 group_name = talloc_strdup(r, map.nt_name);
5096 group_description = talloc_strdup(r, map.comment);
5098 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5100 return NT_STATUS_NO_MEMORY;
5103 switch (r->in.level) {
5109 status = pdb_enum_group_members(
5110 p->mem_ctx, &group_sid, &members, &num_members);
5113 if (!NT_STATUS_IS_OK(status)) {
5117 info->all.name.string = group_name;
5118 info->all.attributes = attributes;
5119 info->all.num_members = num_members;
5120 info->all.description.string = group_description;
5124 info->name.string = group_name;
5127 info->attributes.attributes = attributes;
5130 info->description.string = group_description;
5140 status = pdb_enum_group_members(
5141 p->mem_ctx, &group_sid, &members, &num_members);
5144 if (!NT_STATUS_IS_OK(status)) {
5148 info->all2.name.string = group_name;
5149 info->all2.attributes = attributes;
5150 info->all2.num_members = 0; /* num_members - in w2k3 this is always 0 */
5151 info->all2.description.string = group_description;
5156 return NT_STATUS_INVALID_INFO_CLASS;
5159 *r->out.info = info;
5161 return NT_STATUS_OK;
5164 /*********************************************************************
5166 *********************************************************************/
5168 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5169 struct samr_SetGroupInfo *r)
5176 bool can_mod_accounts;
5177 DISP_INFO *disp_info = NULL;
5179 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5180 return NT_STATUS_INVALID_HANDLE;
5182 status = access_check_samr_function(acc_granted,
5183 SAMR_GROUP_ACCESS_SET_INFO,
5184 "_samr_SetGroupInfo");
5185 if (!NT_STATUS_IS_OK(status)) {
5190 ret = get_domain_group_from_sid(group_sid, &map);
5193 return NT_STATUS_NO_SUCH_GROUP;
5195 switch (r->in.level) {
5197 fstrcpy(map.comment, r->in.info->all.description.string);
5200 /* group rename is not supported yet */
5201 return NT_STATUS_NOT_SUPPORTED;
5203 fstrcpy(map.comment, r->in.info->description.string);
5206 return NT_STATUS_INVALID_INFO_CLASS;
5209 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5211 /******** BEGIN SeAddUsers BLOCK *********/
5213 if ( can_mod_accounts )
5216 status = pdb_update_group_mapping_entry(&map);
5218 if ( can_mod_accounts )
5221 /******** End SeAddUsers BLOCK *********/
5223 if (NT_STATUS_IS_OK(status)) {
5224 force_flush_samr_cache(disp_info);
5230 /*********************************************************************
5232 *********************************************************************/
5234 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5235 struct samr_SetAliasInfo *r)
5238 struct acct_info info;
5240 bool can_mod_accounts;
5242 DISP_INFO *disp_info = NULL;
5244 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
5245 return NT_STATUS_INVALID_HANDLE;
5247 status = access_check_samr_function(acc_granted,
5248 SAMR_ALIAS_ACCESS_SET_INFO,
5249 "_samr_SetAliasInfo");
5250 if (!NT_STATUS_IS_OK(status)) {
5254 /* get the current group information */
5257 status = pdb_get_aliasinfo( &group_sid, &info );
5260 if ( !NT_STATUS_IS_OK(status))
5263 switch (r->in.level) {
5268 /* We currently do not support renaming groups in the
5269 the BUILTIN domain. Refer to util_builtin.c to understand
5270 why. The eventually needs to be fixed to be like Windows
5271 where you can rename builtin groups, just not delete them */
5273 if ( sid_check_is_in_builtin( &group_sid ) ) {
5274 return NT_STATUS_SPECIAL_ACCOUNT;
5277 /* There has to be a valid name (and it has to be different) */
5279 if ( !r->in.info->name.string )
5280 return NT_STATUS_INVALID_PARAMETER;
5282 /* If the name is the same just reply "ok". Yes this
5283 doesn't allow you to change the case of a group name. */
5285 if ( strequal( r->in.info->name.string, info.acct_name ) )
5286 return NT_STATUS_OK;
5288 fstrcpy( info.acct_name, r->in.info->name.string);
5290 /* make sure the name doesn't already exist as a user
5293 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
5294 status = can_create( p->mem_ctx, group_name );
5295 if ( !NT_STATUS_IS_OK( status ) )
5299 case ALIASINFODESCRIPTION:
5300 if (r->in.info->description.string) {
5301 fstrcpy(info.acct_desc,
5302 r->in.info->description.string);
5304 fstrcpy( info.acct_desc, "" );
5308 return NT_STATUS_INVALID_INFO_CLASS;
5311 can_mod_accounts = user_has_privileges( p->server_info->ptok, &se_add_users );
5313 /******** BEGIN SeAddUsers BLOCK *********/
5315 if ( can_mod_accounts )
5318 status = pdb_set_aliasinfo( &group_sid, &info );
5320 if ( can_mod_accounts )
5323 /******** End SeAddUsers BLOCK *********/
5325 if (NT_STATUS_IS_OK(status))
5326 force_flush_samr_cache(disp_info);
5331 /****************************************************************
5333 ****************************************************************/
5335 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
5336 struct samr_GetDomPwInfo *r)
5338 uint32_t min_password_length = 0;
5339 uint32_t password_properties = 0;
5341 /* Perform access check. Since this rpc does not require a
5342 policy handle it will not be caught by the access checks on
5343 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5345 if (!pipe_access_check(p)) {
5346 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5347 return NT_STATUS_ACCESS_DENIED;
5351 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
5352 &min_password_length);
5353 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
5354 &password_properties);
5357 if (lp_check_password_script() && *lp_check_password_script()) {
5358 password_properties |= DOMAIN_PASSWORD_COMPLEX;
5361 r->out.info->min_password_length = min_password_length;
5362 r->out.info->password_properties = password_properties;
5364 return NT_STATUS_OK;
5367 /*********************************************************************
5369 *********************************************************************/
5371 NTSTATUS _samr_OpenGroup(pipes_struct *p,
5372 struct samr_OpenGroup *r)
5378 struct samr_info *info;
5379 SEC_DESC *psd = NULL;
5381 uint32 des_access = r->in.access_mask;
5388 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
5389 return NT_STATUS_INVALID_HANDLE;
5391 status = access_check_samr_function(acc_granted,
5392 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5395 if ( !NT_STATUS_IS_OK(status) )
5398 /*check if access can be granted as requested by client. */
5399 map_max_allowed_access(p->server_info->ptok, &des_access);
5401 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
5402 se_map_generic(&des_access,&grp_generic_mapping);
5404 se_priv_copy( &se_rights, &se_add_users );
5406 status = access_check_samr_object(psd, p->server_info->ptok,
5407 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
5408 &acc_granted, "_samr_OpenGroup");
5410 if ( !NT_STATUS_IS_OK(status) )
5413 /* this should not be hard-coded like this */
5415 if (!sid_equal(&sid, get_global_sam_sid()))
5416 return NT_STATUS_ACCESS_DENIED;
5418 sid_copy(&info_sid, get_global_sam_sid());
5419 sid_append_rid(&info_sid, r->in.rid);
5420 sid_to_fstring(sid_string, &info_sid);
5422 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
5423 return NT_STATUS_NO_MEMORY;
5425 info->acc_granted = acc_granted;
5427 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
5429 /* check if that group really exists */
5431 ret = get_domain_group_from_sid(info->sid, &map);
5434 return NT_STATUS_NO_SUCH_GROUP;
5436 /* get a (unique) handle. open a policy on it. */
5437 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
5438 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5440 return NT_STATUS_OK;
5443 /*********************************************************************
5444 _samr_RemoveMemberFromForeignDomain
5445 *********************************************************************/
5447 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5448 struct samr_RemoveMemberFromForeignDomain *r)
5450 DOM_SID delete_sid, domain_sid;
5453 DISP_INFO *disp_info = NULL;
5455 sid_copy( &delete_sid, r->in.sid );
5457 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5458 sid_string_dbg(&delete_sid)));
5460 /* Find the policy handle. Open a policy on it. */
5462 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
5463 &acc_granted, &disp_info))
5464 return NT_STATUS_INVALID_HANDLE;
5466 result = access_check_samr_function(acc_granted,
5467 STD_RIGHT_DELETE_ACCESS,
5468 "_samr_RemoveMemberFromForeignDomain");
5470 if (!NT_STATUS_IS_OK(result))
5473 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5474 sid_string_dbg(&domain_sid)));
5476 /* we can only delete a user from a group since we don't have
5477 nested groups anyways. So in the latter case, just say OK */
5479 /* TODO: The above comment nowadays is bogus. Since we have nested
5480 * groups now, and aliases members are never reported out of the unix
5481 * group membership, the "just say OK" makes this call a no-op. For
5482 * us. This needs fixing however. */
5484 /* I've only ever seen this in the wild when deleting a user from
5485 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5486 * is the user about to be deleted. I very much suspect this is the
5487 * only application of this call. To verify this, let people report
5490 if (!sid_check_is_builtin(&domain_sid)) {
5491 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5492 "global_sam_sid() = %s\n",
5493 sid_string_dbg(&domain_sid),
5494 sid_string_dbg(get_global_sam_sid())));
5495 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5496 return NT_STATUS_OK;
5499 force_flush_samr_cache(disp_info);
5501 result = NT_STATUS_OK;
5506 /*******************************************************************
5507 _samr_QueryDomainInfo2
5508 ********************************************************************/
5510 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5511 struct samr_QueryDomainInfo2 *r)
5513 struct samr_QueryDomainInfo q;
5515 q.in.domain_handle = r->in.domain_handle;
5516 q.in.level = r->in.level;
5518 q.out.info = r->out.info;
5520 return _samr_QueryDomainInfo(p, &q);
5523 /*******************************************************************
5525 ********************************************************************/
5527 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5528 struct samr_SetDomainInfo *r)
5530 struct samr_info *info = NULL;
5531 time_t u_expire, u_min_age;
5533 time_t u_lock_duration, u_reset_time;
5536 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5538 /* find the policy handle. open a policy on it. */
5539 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5540 return NT_STATUS_INVALID_HANDLE;
5542 /* We do have different access bits for info
5543 * levels here, but we're really just looking for
5544 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5545 * this maps to different specific bits. So
5546 * assume if we have SAMR_DOMAIN_ACCESS_SET_INFO_1
5549 result = access_check_samr_function(info->acc_granted,
5550 SAMR_DOMAIN_ACCESS_SET_INFO_1,
5551 "_samr_SetDomainInfo");
5553 if (!NT_STATUS_IS_OK(result))
5556 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
5558 switch (r->in.level) {
5560 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
5561 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
5562 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
5563 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
5564 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
5565 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5566 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5571 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
5572 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5581 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
5582 if (u_lock_duration != -1)
5583 u_lock_duration /= 60;
5585 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
5587 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5588 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5589 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
5592 return NT_STATUS_INVALID_INFO_CLASS;
5595 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
5597 return NT_STATUS_OK;
5600 /****************************************************************
5601 _samr_GetDisplayEnumerationIndex
5602 ****************************************************************/
5604 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5605 struct samr_GetDisplayEnumerationIndex *r)
5607 struct samr_info *info = NULL;
5608 uint32_t max_entries = (uint32_t) -1;
5609 uint32_t enum_context = 0;
5611 uint32_t num_account = 0;
5612 struct samr_displayentry *entries = NULL;
5615 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
5617 /* find the policy handle. open a policy on it. */
5618 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
5619 return NT_STATUS_INVALID_HANDLE;
5622 status = access_check_samr_function(info->acc_granted,
5623 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
5624 "_samr_GetDisplayEnumerationIndex");
5625 if (!NT_STATUS_IS_OK(status)) {
5629 if ((r->in.level < 1) || (r->in.level > 3)) {
5630 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5631 "Unknown info level (%u)\n",
5633 return NT_STATUS_INVALID_INFO_CLASS;
5638 /* The following done as ROOT. Don't return without unbecome_root(). */
5640 switch (r->in.level) {
5642 if (info->disp_info->users == NULL) {
5643 info->disp_info->users = pdb_search_users(ACB_NORMAL);
5644 if (info->disp_info->users == NULL) {
5646 return NT_STATUS_ACCESS_DENIED;
5648 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5649 "starting user enumeration at index %u\n",
5650 (unsigned int)enum_context));
5652 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5653 "using cached user enumeration at index %u\n",
5654 (unsigned int)enum_context));
5656 num_account = pdb_search_entries(info->disp_info->users,
5657 enum_context, max_entries,
5661 if (info->disp_info->machines == NULL) {
5662 info->disp_info->machines =
5663 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
5664 if (info->disp_info->machines == NULL) {
5666 return NT_STATUS_ACCESS_DENIED;
5668 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5669 "starting machine enumeration at index %u\n",
5670 (unsigned int)enum_context));
5672 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5673 "using cached machine enumeration at index %u\n",
5674 (unsigned int)enum_context));
5676 num_account = pdb_search_entries(info->disp_info->machines,
5677 enum_context, max_entries,
5681 if (info->disp_info->groups == NULL) {
5682 info->disp_info->groups = pdb_search_groups();
5683 if (info->disp_info->groups == NULL) {
5685 return NT_STATUS_ACCESS_DENIED;
5687 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5688 "starting group enumeration at index %u\n",
5689 (unsigned int)enum_context));
5691 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5692 "using cached group enumeration at index %u\n",
5693 (unsigned int)enum_context));
5695 num_account = pdb_search_entries(info->disp_info->groups,
5696 enum_context, max_entries,
5701 smb_panic("info class changed");
5707 /* Ensure we cache this enumeration. */
5708 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
5710 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5711 r->in.name->string));
5713 for (i=0; i<num_account; i++) {
5714 if (strequal(entries[i].account_name, r->in.name->string)) {
5715 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5716 "found %s at idx %d\n",
5717 r->in.name->string, i));
5719 return NT_STATUS_OK;
5723 /* assuming account_name lives at the very end */
5724 *r->out.idx = num_account;
5726 return NT_STATUS_NO_MORE_ENTRIES;
5729 /****************************************************************
5730 _samr_GetDisplayEnumerationIndex2
5731 ****************************************************************/
5733 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5734 struct samr_GetDisplayEnumerationIndex2 *r)
5736 struct samr_GetDisplayEnumerationIndex q;
5738 q.in.domain_handle = r->in.domain_handle;
5739 q.in.level = r->in.level;
5740 q.in.name = r->in.name;
5742 q.out.idx = r->out.idx;
5744 return _samr_GetDisplayEnumerationIndex(p, &q);
5747 /****************************************************************
5748 ****************************************************************/
5750 NTSTATUS _samr_Shutdown(pipes_struct *p,
5751 struct samr_Shutdown *r)
5753 p->rng_fault_state = true;
5754 return NT_STATUS_NOT_IMPLEMENTED;
5757 /****************************************************************
5758 ****************************************************************/
5760 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5761 struct samr_SetMemberAttributesOfGroup *r)
5763 p->rng_fault_state = true;
5764 return NT_STATUS_NOT_IMPLEMENTED;
5767 /****************************************************************
5768 ****************************************************************/
5770 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5771 struct samr_ChangePasswordUser *r)
5773 p->rng_fault_state = true;
5774 return NT_STATUS_NOT_IMPLEMENTED;
5777 /****************************************************************
5778 ****************************************************************/
5780 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5781 struct samr_TestPrivateFunctionsDomain *r)
5783 p->rng_fault_state = true;
5784 return NT_STATUS_NOT_IMPLEMENTED;
5787 /****************************************************************
5788 ****************************************************************/
5790 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5791 struct samr_TestPrivateFunctionsUser *r)
5793 p->rng_fault_state = true;
5794 return NT_STATUS_NOT_IMPLEMENTED;
5797 /****************************************************************
5798 ****************************************************************/
5800 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5801 struct samr_AddMultipleMembersToAlias *r)
5803 p->rng_fault_state = true;
5804 return NT_STATUS_NOT_IMPLEMENTED;
5807 /****************************************************************
5808 ****************************************************************/
5810 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5811 struct samr_RemoveMultipleMembersFromAlias *r)
5813 p->rng_fault_state = true;
5814 return NT_STATUS_NOT_IMPLEMENTED;
5817 /****************************************************************
5818 ****************************************************************/
5820 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5821 struct samr_OemChangePasswordUser2 *r)
5823 p->rng_fault_state = true;
5824 return NT_STATUS_NOT_IMPLEMENTED;
5827 /****************************************************************
5828 ****************************************************************/
5830 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5831 struct samr_SetBootKeyInformation *r)
5833 p->rng_fault_state = true;
5834 return NT_STATUS_NOT_IMPLEMENTED;
5837 /****************************************************************
5838 ****************************************************************/
5840 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5841 struct samr_GetBootKeyInformation *r)
5843 p->rng_fault_state = true;
5844 return NT_STATUS_NOT_IMPLEMENTED;
5847 /****************************************************************
5848 ****************************************************************/
5850 NTSTATUS _samr_Connect3(pipes_struct *p,
5851 struct samr_Connect3 *r)
5853 p->rng_fault_state = true;
5854 return NT_STATUS_NOT_IMPLEMENTED;
5857 /****************************************************************
5858 ****************************************************************/
5860 NTSTATUS _samr_RidToSid(pipes_struct *p,
5861 struct samr_RidToSid *r)
5863 p->rng_fault_state = true;
5864 return NT_STATUS_NOT_IMPLEMENTED;
5867 /****************************************************************
5868 ****************************************************************/
5870 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5871 struct samr_SetDsrmPassword *r)
5873 p->rng_fault_state = true;
5874 return NT_STATUS_NOT_IMPLEMENTED;
5877 /****************************************************************
5878 ****************************************************************/
5880 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5881 struct samr_ValidatePassword *r)
5883 p->rng_fault_state = true;
5884 return NT_STATUS_NOT_IMPLEMENTED;