2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997,
7 * Copyright (C) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2008,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
14 * Copyright (C) Guenther Deschner 2008.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
31 * This is the implementation of the SAMR code.
37 #define DBGC_CLASS DBGC_RPC_SRV
39 #define SAMR_USR_RIGHTS_WRITE_PW \
40 ( READ_CONTROL_ACCESS | \
41 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
42 SAMR_USER_ACCESS_SET_LOC_COM)
43 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
44 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
46 #define DISP_INFO_CACHE_TIMEOUT 10
48 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
49 #define MAX_SAM_ENTRIES_W95 50
51 typedef struct disp_info {
52 DOM_SID sid; /* identify which domain this is. */
53 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
54 struct pdb_search *users; /* querydispinfo 1 and 4 */
55 struct pdb_search *machines; /* querydispinfo 2 */
56 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
57 struct pdb_search *aliases; /* enumaliases */
60 struct pdb_search *enum_users; /* enumusers with a mask */
62 struct timed_event *cache_timeout_event; /* cache idle timeout
66 /* We keep a static list of these by SID as modern clients close down
67 all resources between each request in a complete enumeration. */
70 /* for use by the \PIPE\samr policy */
72 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
73 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
78 static const struct generic_mapping sam_generic_mapping = {
79 GENERIC_RIGHTS_SAM_READ,
80 GENERIC_RIGHTS_SAM_WRITE,
81 GENERIC_RIGHTS_SAM_EXECUTE,
82 GENERIC_RIGHTS_SAM_ALL_ACCESS};
83 static const struct generic_mapping dom_generic_mapping = {
84 GENERIC_RIGHTS_DOMAIN_READ,
85 GENERIC_RIGHTS_DOMAIN_WRITE,
86 GENERIC_RIGHTS_DOMAIN_EXECUTE,
87 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
88 static const struct generic_mapping usr_generic_mapping = {
89 GENERIC_RIGHTS_USER_READ,
90 GENERIC_RIGHTS_USER_WRITE,
91 GENERIC_RIGHTS_USER_EXECUTE,
92 GENERIC_RIGHTS_USER_ALL_ACCESS};
93 static const struct generic_mapping usr_nopwchange_generic_mapping = {
94 GENERIC_RIGHTS_USER_READ,
95 GENERIC_RIGHTS_USER_WRITE,
96 GENERIC_RIGHTS_USER_EXECUTE & ~SAMR_USER_ACCESS_CHANGE_PASSWORD,
97 GENERIC_RIGHTS_USER_ALL_ACCESS};
98 static const struct generic_mapping grp_generic_mapping = {
99 GENERIC_RIGHTS_GROUP_READ,
100 GENERIC_RIGHTS_GROUP_WRITE,
101 GENERIC_RIGHTS_GROUP_EXECUTE,
102 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
103 static const struct generic_mapping ali_generic_mapping = {
104 GENERIC_RIGHTS_ALIAS_READ,
105 GENERIC_RIGHTS_ALIAS_WRITE,
106 GENERIC_RIGHTS_ALIAS_EXECUTE,
107 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
109 /*******************************************************************
110 *******************************************************************/
112 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
113 const struct generic_mapping *map,
114 DOM_SID *sid, uint32 sid_access )
116 DOM_SID domadmin_sid;
117 SEC_ACE ace[5]; /* at most 5 entries */
122 /* basic access for Everyone */
124 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
125 map->generic_execute | map->generic_read, 0);
127 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
129 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
130 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
131 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
132 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
134 /* Add Full Access for Domain Admins if we are a DC */
137 sid_copy( &domadmin_sid, get_global_sam_sid() );
138 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
139 init_sec_ace(&ace[i++], &domadmin_sid,
140 SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
143 /* if we have a sid, give it some special access */
146 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, sid_access, 0);
149 /* create the security descriptor */
151 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
152 return NT_STATUS_NO_MEMORY;
154 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
155 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
156 psa, sd_size)) == NULL)
157 return NT_STATUS_NO_MEMORY;
162 /*******************************************************************
163 Checks if access to an object should be granted, and returns that
164 level of access for further checks.
165 ********************************************************************/
167 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
168 SE_PRIV *rights, uint32 rights_mask,
169 uint32 des_access, uint32 *acc_granted,
172 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
173 uint32 saved_mask = 0;
175 /* check privileges; certain SAM access bits should be overridden
176 by privileges (mostly having to do with creating/modifying/deleting
179 if (rights && !se_priv_equal(rights, &se_priv_none) &&
180 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 if (builtin_dispinfo == NULL) {
340 builtin_dispinfo = talloc_zero(
341 talloc_autofree_context(), struct disp_info);
342 if (builtin_dispinfo == NULL) {
346 sid_copy(&builtin_dispinfo->sid, &global_sid_Builtin);
347 builtin_dispinfo->builtin_domain = true;
349 return builtin_dispinfo;
352 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
354 * Necessary only once, but it does not really hurt.
356 if (domain_dispinfo == NULL) {
357 domain_dispinfo = talloc_zero(
358 talloc_autofree_context(), struct disp_info);
359 if (domain_dispinfo == NULL) {
363 sid_copy(&domain_dispinfo->sid, get_global_sam_sid());
364 domain_dispinfo->builtin_domain = false;
366 return domain_dispinfo;
372 /*******************************************************************
373 Create a samr_info struct.
374 ********************************************************************/
376 static int samr_info_destructor(struct samr_info *info);
378 static struct samr_info *get_samr_info_by_sid(TALLOC_CTX *mem_ctx,
381 struct samr_info *info;
385 sid_to_fstring(sid_str, psid);
387 fstrcpy(sid_str,"(NULL)");
390 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL) {
393 talloc_set_destructor(info, samr_info_destructor);
395 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
397 sid_copy( &info->sid, psid);
398 info->builtin_domain = sid_check_is_builtin(psid);
400 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
401 info->builtin_domain = False;
404 info->disp_info = get_samr_dispinfo_by_sid(psid);
409 /*******************************************************************
410 Function to free the per SID data.
411 ********************************************************************/
413 static void free_samr_cache(DISP_INFO *disp_info)
415 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
416 sid_string_dbg(&disp_info->sid)));
418 /* We need to become root here because the paged search might have to
419 * tell the LDAP server we're not interested in the rest anymore. */
423 TALLOC_FREE(disp_info->users);
424 TALLOC_FREE(disp_info->machines);
425 TALLOC_FREE(disp_info->groups);
426 TALLOC_FREE(disp_info->aliases);
427 TALLOC_FREE(disp_info->enum_users);
432 static int samr_info_destructor(struct samr_info *info)
434 /* Only free the dispinfo cache if no one bothered to set up
437 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
438 free_samr_cache(info->disp_info);
443 /*******************************************************************
444 Idle event handler. Throw away the disp info cache.
445 ********************************************************************/
447 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
448 struct timed_event *te,
452 DISP_INFO *disp_info = (DISP_INFO *)private_data;
454 TALLOC_FREE(disp_info->cache_timeout_event);
456 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
458 free_samr_cache(disp_info);
461 /*******************************************************************
462 Setup cache removal idle event handler.
463 ********************************************************************/
465 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
467 /* Remove any pending timeout and update. */
469 TALLOC_FREE(disp_info->cache_timeout_event);
471 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
472 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
473 (unsigned int)secs_fromnow ));
475 disp_info->cache_timeout_event = event_add_timed(
476 smbd_event_context(), NULL,
477 timeval_current_ofs(secs_fromnow, 0),
478 disp_info_cache_idle_timeout_handler, (void *)disp_info);
481 /*******************************************************************
482 Force flush any cache. We do this on any samr_set_xxx call.
483 We must also remove the timeout handler.
484 ********************************************************************/
486 static void force_flush_samr_cache(DISP_INFO *disp_info)
488 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
492 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
493 TALLOC_FREE(disp_info->cache_timeout_event);
494 free_samr_cache(disp_info);
497 /*******************************************************************
498 Ensure password info is never given out. Paranioa... JRA.
499 ********************************************************************/
501 static void samr_clear_sam_passwd(struct samu *sam_pass)
507 /* These now zero out the old password */
509 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
510 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
513 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
515 struct samr_displayentry *entry;
517 if (info->builtin_domain) {
518 /* No users in builtin. */
522 if (info->users == NULL) {
523 info->users = pdb_search_users(info, acct_flags);
524 if (info->users == NULL) {
528 /* Fetch the last possible entry, thus trigger an enumeration */
529 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
531 /* Ensure we cache this enumeration. */
532 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
534 return info->users->num_entries;
537 static uint32 count_sam_groups(struct disp_info *info)
539 struct samr_displayentry *entry;
541 if (info->builtin_domain) {
542 /* No groups in builtin. */
546 if (info->groups == NULL) {
547 info->groups = pdb_search_groups(info);
548 if (info->groups == NULL) {
552 /* Fetch the last possible entry, thus trigger an enumeration */
553 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
555 /* Ensure we cache this enumeration. */
556 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
558 return info->groups->num_entries;
561 static uint32 count_sam_aliases(struct disp_info *info)
563 struct samr_displayentry *entry;
565 if (info->aliases == NULL) {
566 info->aliases = pdb_search_aliases(info, &info->sid);
567 if (info->aliases == NULL) {
571 /* Fetch the last possible entry, thus trigger an enumeration */
572 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
574 /* Ensure we cache this enumeration. */
575 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
577 return info->aliases->num_entries;
580 /*******************************************************************
582 ********************************************************************/
584 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
586 if (!close_policy_hnd(p, r->in.handle)) {
587 return NT_STATUS_INVALID_HANDLE;
590 ZERO_STRUCTP(r->out.handle);
595 /*******************************************************************
597 ********************************************************************/
599 NTSTATUS _samr_OpenDomain(pipes_struct *p,
600 struct samr_OpenDomain *r)
602 struct samr_info *info;
603 SEC_DESC *psd = NULL;
605 uint32 des_access = r->in.access_mask;
608 uint32_t extra_access = SAMR_DOMAIN_ACCESS_CREATE_USER;
611 /* find the connection policy handle. */
613 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
614 return NT_STATUS_INVALID_HANDLE;
616 /*check if access can be granted as requested by client. */
617 map_max_allowed_access(p->server_info->ptok, &des_access);
619 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
620 se_map_generic( &des_access, &dom_generic_mapping );
623 * Users with SeMachineAccount or SeAddUser get additional
624 * SAMR_DOMAIN_ACCESS_CREATE_USER access.
626 se_priv_copy( &se_rights, &se_machine_account );
627 se_priv_add( &se_rights, &se_add_users );
630 * Users with SeAddUser get the ability to manipulate groups
633 if (user_has_any_privilege(p->server_info->ptok, &se_add_users)) {
634 extra_access |= (SAMR_DOMAIN_ACCESS_CREATE_GROUP |
635 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
636 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
637 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS |
638 SAMR_DOMAIN_ACCESS_CREATE_ALIAS);
641 status = access_check_samr_object( psd, p->server_info->ptok,
642 &se_rights, extra_access, des_access,
643 &acc_granted, "_samr_OpenDomain" );
645 if ( !NT_STATUS_IS_OK(status) )
648 if (!sid_check_is_domain(r->in.sid) &&
649 !sid_check_is_builtin(r->in.sid)) {
650 return NT_STATUS_NO_SUCH_DOMAIN;
653 /* associate the domain SID with the (unique) handle. */
654 if ((info = get_samr_info_by_sid(p->mem_ctx, r->in.sid))==NULL)
655 return NT_STATUS_NO_MEMORY;
656 info->acc_granted = acc_granted;
658 /* get a (unique) handle. open a policy on it. */
659 if (!create_policy_hnd(p, r->out.domain_handle, info))
660 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
662 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
667 /*******************************************************************
669 ********************************************************************/
671 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
672 struct samr_GetUserPwInfo *r)
674 struct samr_info *info = NULL;
675 enum lsa_SidType sid_type;
676 uint32_t min_password_length = 0;
677 uint32_t password_properties = 0;
681 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
683 /* find the policy handle. open a policy on it. */
684 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info)) {
685 return NT_STATUS_INVALID_HANDLE;
688 status = access_check_samr_function(info->acc_granted,
689 SAMR_USER_ACCESS_GET_ATTRIBUTES,
690 "_samr_GetUserPwInfo" );
691 if (!NT_STATUS_IS_OK(status)) {
695 if (!sid_check_is_in_our_domain(&info->sid)) {
696 return NT_STATUS_OBJECT_TYPE_MISMATCH;
700 ret = lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, &sid_type);
703 return NT_STATUS_NO_SUCH_USER;
709 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
710 &min_password_length);
711 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
712 &password_properties);
715 if (lp_check_password_script() && *lp_check_password_script()) {
716 password_properties |= DOMAIN_PASSWORD_COMPLEX;
724 r->out.info->min_password_length = min_password_length;
725 r->out.info->password_properties = password_properties;
727 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__));
732 /*******************************************************************
733 ********************************************************************/
735 static bool get_lsa_policy_samr_sid( pipes_struct *p, struct policy_handle *pol,
736 DOM_SID *sid, uint32 *acc_granted,
737 DISP_INFO **ppdisp_info)
739 struct samr_info *info = NULL;
741 /* find the policy handle. open a policy on it. */
742 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
749 *acc_granted = info->acc_granted;
751 *ppdisp_info = info->disp_info;
757 /*******************************************************************
759 ********************************************************************/
761 NTSTATUS _samr_SetSecurity(pipes_struct *p,
762 struct samr_SetSecurity *r)
765 uint32 acc_granted, i;
768 struct samu *sampass=NULL;
771 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
772 return NT_STATUS_INVALID_HANDLE;
774 if (!(sampass = samu_new( p->mem_ctx))) {
775 DEBUG(0,("No memory!\n"));
776 return NT_STATUS_NO_MEMORY;
779 /* get the user record */
781 ret = pdb_getsampwsid(sampass, &pol_sid);
785 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
786 TALLOC_FREE(sampass);
787 return NT_STATUS_INVALID_HANDLE;
790 dacl = r->in.sdbuf->sd->dacl;
791 for (i=0; i < dacl->num_aces; i++) {
792 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
793 ret = pdb_set_pass_can_change(sampass,
794 (dacl->aces[i].access_mask &
795 SAMR_USER_ACCESS_CHANGE_PASSWORD) ?
802 TALLOC_FREE(sampass);
803 return NT_STATUS_ACCESS_DENIED;
806 status = access_check_samr_function(acc_granted,
807 SAMR_USER_ACCESS_SET_ATTRIBUTES,
808 "_samr_SetSecurity");
809 if (NT_STATUS_IS_OK(status)) {
811 status = pdb_update_sam_account(sampass);
815 TALLOC_FREE(sampass);
820 /*******************************************************************
821 build correct perms based on policies and password times for _samr_query_sec_obj
822 *******************************************************************/
823 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
825 struct samu *sampass=NULL;
828 if ( !(sampass = samu_new( mem_ctx )) ) {
829 DEBUG(0,("No memory!\n"));
834 ret = pdb_getsampwsid(sampass, user_sid);
838 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
839 TALLOC_FREE(sampass);
843 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
845 if (pdb_get_pass_can_change(sampass)) {
846 TALLOC_FREE(sampass);
849 TALLOC_FREE(sampass);
854 /*******************************************************************
856 ********************************************************************/
858 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
859 struct samr_QuerySecurity *r)
863 SEC_DESC * psd = NULL;
868 if (!get_lsa_policy_samr_sid(p, r->in.handle, &pol_sid, &acc_granted, NULL))
869 return NT_STATUS_INVALID_HANDLE;
871 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
872 sid_string_dbg(&pol_sid)));
874 status = access_check_samr_function(acc_granted,
875 STD_RIGHT_READ_CONTROL_ACCESS,
876 "_samr_QuerySecurity");
877 if (!NT_STATUS_IS_OK(status)) {
881 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
883 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
884 if (pol_sid.sid_rev_num == 0) {
885 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
886 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
887 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
888 /* check if it is our domain SID */
889 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
890 "with SID: %s\n", sid_string_dbg(&pol_sid)));
891 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
892 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
893 /* check if it is the Builtin Domain */
894 /* TODO: Builtin probably needs a different SD with restricted write access*/
895 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
896 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
897 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
898 } else if (sid_check_is_in_our_domain(&pol_sid) ||
899 sid_check_is_in_builtin(&pol_sid)) {
900 /* TODO: different SDs have to be generated for aliases groups and users.
901 Currently all three get a default user SD */
902 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
903 "with SID: %s\n", sid_string_dbg(&pol_sid)));
904 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
905 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
906 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
908 status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
909 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
912 return NT_STATUS_OBJECT_TYPE_MISMATCH;
915 if ((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
916 return NT_STATUS_NO_MEMORY;
921 /*******************************************************************
922 makes a SAM_ENTRY / UNISTR2* structure from a user list.
923 ********************************************************************/
925 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx,
926 struct samr_SamEntry **sam_pp,
927 uint32_t num_entries,
929 struct samr_displayentry *entries)
932 struct samr_SamEntry *sam;
936 if (num_entries == 0) {
940 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_entries);
942 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
943 return NT_STATUS_NO_MEMORY;
946 for (i = 0; i < num_entries; i++) {
949 * usrmgr expects a non-NULL terminated string with
950 * trust relationships
952 if (entries[i].acct_flags & ACB_DOMTRUST) {
953 init_unistr2(&uni_temp_name, entries[i].account_name,
956 init_unistr2(&uni_temp_name, entries[i].account_name,
960 init_lsa_String(&sam[i].name, entries[i].account_name);
961 sam[i].idx = entries[i].rid;
969 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
971 /*******************************************************************
972 _samr_EnumDomainUsers
973 ********************************************************************/
975 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
976 struct samr_EnumDomainUsers *r)
979 struct samr_info *info = NULL;
981 uint32 enum_context = *r->in.resume_handle;
982 enum remote_arch_types ra_type = get_remote_arch();
983 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
984 uint32 max_entries = max_sam_entries;
985 struct samr_displayentry *entries = NULL;
986 struct samr_SamArray *samr_array = NULL;
987 struct samr_SamEntry *samr_entries = NULL;
989 /* find the policy handle. open a policy on it. */
990 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
991 return NT_STATUS_INVALID_HANDLE;
993 status = access_check_samr_function(info->acc_granted,
994 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
995 "_samr_EnumDomainUsers");
996 if (!NT_STATUS_IS_OK(status)) {
1000 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1002 if (info->builtin_domain) {
1003 /* No users in builtin. */
1004 *r->out.resume_handle = *r->in.resume_handle;
1005 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
1009 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1011 return NT_STATUS_NO_MEMORY;
1013 *r->out.sam = samr_array;
1019 if ((info->disp_info->enum_users != NULL) &&
1020 (info->disp_info->enum_acb_mask != r->in.acct_flags)) {
1021 TALLOC_FREE(info->disp_info->enum_users);
1024 if (info->disp_info->enum_users == NULL) {
1025 info->disp_info->enum_users = pdb_search_users(
1026 info->disp_info, r->in.acct_flags);
1027 info->disp_info->enum_acb_mask = r->in.acct_flags;
1030 if (info->disp_info->enum_users == NULL) {
1031 /* END AS ROOT !!!! */
1033 return NT_STATUS_ACCESS_DENIED;
1036 num_account = pdb_search_entries(info->disp_info->enum_users,
1037 enum_context, max_entries,
1040 /* END AS ROOT !!!! */
1044 if (num_account == 0) {
1045 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1046 "total entries\n"));
1047 *r->out.resume_handle = *r->in.resume_handle;
1048 return NT_STATUS_OK;
1051 status = make_user_sam_entry_list(p->mem_ctx, &samr_entries,
1052 num_account, enum_context,
1054 if (!NT_STATUS_IS_OK(status)) {
1058 if (max_entries <= num_account) {
1059 status = STATUS_MORE_ENTRIES;
1061 status = NT_STATUS_OK;
1064 /* Ensure we cache this enumeration. */
1065 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1067 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__));
1069 samr_array->count = num_account;
1070 samr_array->entries = samr_entries;
1072 *r->out.resume_handle = *r->in.resume_handle + num_account;
1073 *r->out.num_entries = num_account;
1075 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__));
1080 /*******************************************************************
1081 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1082 ********************************************************************/
1084 static void make_group_sam_entry_list(TALLOC_CTX *ctx,
1085 struct samr_SamEntry **sam_pp,
1086 uint32_t num_sam_entries,
1087 struct samr_displayentry *entries)
1089 struct samr_SamEntry *sam;
1094 if (num_sam_entries == 0) {
1098 sam = TALLOC_ZERO_ARRAY(ctx, struct samr_SamEntry, num_sam_entries);
1103 for (i = 0; i < num_sam_entries; i++) {
1105 * JRA. I think this should include the null. TNG does not.
1107 init_lsa_String(&sam[i].name, entries[i].account_name);
1108 sam[i].idx = entries[i].rid;
1114 /*******************************************************************
1115 _samr_EnumDomainGroups
1116 ********************************************************************/
1118 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
1119 struct samr_EnumDomainGroups *r)
1122 struct samr_info *info = NULL;
1123 struct samr_displayentry *groups;
1125 struct samr_SamArray *samr_array = NULL;
1126 struct samr_SamEntry *samr_entries = NULL;
1128 /* find the policy handle. open a policy on it. */
1129 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1130 return NT_STATUS_INVALID_HANDLE;
1132 status = access_check_samr_function(info->acc_granted,
1133 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1134 "_samr_EnumDomainGroups");
1135 if (!NT_STATUS_IS_OK(status)) {
1139 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1141 if (info->builtin_domain) {
1142 /* No groups in builtin. */
1143 *r->out.resume_handle = *r->in.resume_handle;
1144 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1148 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1150 return NT_STATUS_NO_MEMORY;
1153 /* the domain group array is being allocated in the function below */
1157 if (info->disp_info->groups == NULL) {
1158 info->disp_info->groups = pdb_search_groups(info->disp_info);
1160 if (info->disp_info->groups == NULL) {
1162 return NT_STATUS_ACCESS_DENIED;
1166 num_groups = pdb_search_entries(info->disp_info->groups,
1167 *r->in.resume_handle,
1168 MAX_SAM_ENTRIES, &groups);
1171 /* Ensure we cache this enumeration. */
1172 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1174 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1175 num_groups, groups);
1177 samr_array->count = num_groups;
1178 samr_array->entries = samr_entries;
1180 *r->out.sam = samr_array;
1181 *r->out.num_entries = num_groups;
1182 *r->out.resume_handle = num_groups + *r->in.resume_handle;
1184 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__));
1189 /*******************************************************************
1190 _samr_EnumDomainAliases
1191 ********************************************************************/
1193 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
1194 struct samr_EnumDomainAliases *r)
1197 struct samr_info *info;
1198 struct samr_displayentry *aliases;
1199 uint32 num_aliases = 0;
1200 struct samr_SamArray *samr_array = NULL;
1201 struct samr_SamEntry *samr_entries = NULL;
1203 /* find the policy handle. open a policy on it. */
1204 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1205 return NT_STATUS_INVALID_HANDLE;
1207 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1208 sid_string_dbg(&info->sid)));
1210 status = access_check_samr_function(info->acc_granted,
1211 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1212 "_samr_EnumDomainAliases");
1213 if (!NT_STATUS_IS_OK(status)) {
1217 samr_array = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
1219 return NT_STATUS_NO_MEMORY;
1224 if (info->disp_info->aliases == NULL) {
1225 info->disp_info->aliases = pdb_search_aliases(
1226 info->disp_info, &info->sid);
1227 if (info->disp_info->aliases == NULL) {
1229 return NT_STATUS_ACCESS_DENIED;
1233 num_aliases = pdb_search_entries(info->disp_info->aliases,
1234 *r->in.resume_handle,
1235 MAX_SAM_ENTRIES, &aliases);
1238 /* Ensure we cache this enumeration. */
1239 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1241 make_group_sam_entry_list(p->mem_ctx, &samr_entries,
1242 num_aliases, aliases);
1244 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__));
1246 samr_array->count = num_aliases;
1247 samr_array->entries = samr_entries;
1249 *r->out.sam = samr_array;
1250 *r->out.num_entries = num_aliases;
1251 *r->out.resume_handle = num_aliases + *r->in.resume_handle;
1256 /*******************************************************************
1257 inits a samr_DispInfoGeneral structure.
1258 ********************************************************************/
1260 static NTSTATUS init_samr_dispinfo_1(TALLOC_CTX *ctx,
1261 struct samr_DispInfoGeneral *r,
1262 uint32_t num_entries,
1264 struct samr_displayentry *entries)
1268 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries));
1270 if (num_entries == 0) {
1271 return NT_STATUS_OK;
1274 r->count = num_entries;
1276 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryGeneral, num_entries);
1278 return NT_STATUS_NO_MEMORY;
1281 for (i = 0; i < num_entries ; i++) {
1283 init_lsa_String(&r->entries[i].account_name,
1284 entries[i].account_name);
1286 init_lsa_String(&r->entries[i].description,
1287 entries[i].description);
1289 init_lsa_String(&r->entries[i].full_name,
1290 entries[i].fullname);
1292 r->entries[i].rid = entries[i].rid;
1293 r->entries[i].acct_flags = entries[i].acct_flags;
1294 r->entries[i].idx = start_idx+i+1;
1297 return NT_STATUS_OK;
1300 /*******************************************************************
1301 inits a samr_DispInfoFull structure.
1302 ********************************************************************/
1304 static NTSTATUS init_samr_dispinfo_2(TALLOC_CTX *ctx,
1305 struct samr_DispInfoFull *r,
1306 uint32_t num_entries,
1308 struct samr_displayentry *entries)
1312 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries));
1314 if (num_entries == 0) {
1315 return NT_STATUS_OK;
1318 r->count = num_entries;
1320 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFull, num_entries);
1322 return NT_STATUS_NO_MEMORY;
1325 for (i = 0; i < num_entries ; i++) {
1327 init_lsa_String(&r->entries[i].account_name,
1328 entries[i].account_name);
1330 init_lsa_String(&r->entries[i].description,
1331 entries[i].description);
1333 r->entries[i].rid = entries[i].rid;
1334 r->entries[i].acct_flags = entries[i].acct_flags;
1335 r->entries[i].idx = start_idx+i+1;
1338 return NT_STATUS_OK;
1341 /*******************************************************************
1342 inits a samr_DispInfoFullGroups structure.
1343 ********************************************************************/
1345 static NTSTATUS init_samr_dispinfo_3(TALLOC_CTX *ctx,
1346 struct samr_DispInfoFullGroups *r,
1347 uint32_t num_entries,
1349 struct samr_displayentry *entries)
1353 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries));
1355 if (num_entries == 0) {
1356 return NT_STATUS_OK;
1359 r->count = num_entries;
1361 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryFullGroup, num_entries);
1363 return NT_STATUS_NO_MEMORY;
1366 for (i = 0; i < num_entries ; i++) {
1368 init_lsa_String(&r->entries[i].account_name,
1369 entries[i].account_name);
1371 init_lsa_String(&r->entries[i].description,
1372 entries[i].description);
1374 r->entries[i].rid = entries[i].rid;
1375 r->entries[i].acct_flags = entries[i].acct_flags;
1376 r->entries[i].idx = start_idx+i+1;
1379 return NT_STATUS_OK;
1382 /*******************************************************************
1383 inits a samr_DispInfoAscii structure.
1384 ********************************************************************/
1386 static NTSTATUS init_samr_dispinfo_4(TALLOC_CTX *ctx,
1387 struct samr_DispInfoAscii *r,
1388 uint32_t num_entries,
1390 struct samr_displayentry *entries)
1394 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries));
1396 if (num_entries == 0) {
1397 return NT_STATUS_OK;
1400 r->count = num_entries;
1402 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1404 return NT_STATUS_NO_MEMORY;
1407 for (i = 0; i < num_entries ; i++) {
1409 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1410 entries[i].account_name);
1412 r->entries[i].idx = start_idx+i+1;
1415 return NT_STATUS_OK;
1418 /*******************************************************************
1419 inits a samr_DispInfoAscii structure.
1420 ********************************************************************/
1422 static NTSTATUS init_samr_dispinfo_5(TALLOC_CTX *ctx,
1423 struct samr_DispInfoAscii *r,
1424 uint32_t num_entries,
1426 struct samr_displayentry *entries)
1430 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries));
1432 if (num_entries == 0) {
1433 return NT_STATUS_OK;
1436 r->count = num_entries;
1438 r->entries = TALLOC_ZERO_ARRAY(ctx, struct samr_DispEntryAscii, num_entries);
1440 return NT_STATUS_NO_MEMORY;
1443 for (i = 0; i < num_entries ; i++) {
1445 init_lsa_AsciiStringLarge(&r->entries[i].account_name,
1446 entries[i].account_name);
1448 r->entries[i].idx = start_idx+i+1;
1451 return NT_STATUS_OK;
1454 /*******************************************************************
1455 _samr_QueryDisplayInfo
1456 ********************************************************************/
1458 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
1459 struct samr_QueryDisplayInfo *r)
1462 struct samr_info *info = NULL;
1463 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1465 uint32 max_entries = r->in.max_entries;
1466 uint32 enum_context = r->in.start_idx;
1467 uint32 max_size = r->in.buf_size;
1469 union samr_DispInfo *disp_info = r->out.info;
1471 uint32 temp_size=0, total_data_size=0;
1472 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1473 uint32 num_account = 0;
1474 enum remote_arch_types ra_type = get_remote_arch();
1475 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1476 struct samr_displayentry *entries = NULL;
1478 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__));
1480 /* find the policy handle. open a policy on it. */
1481 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
1482 return NT_STATUS_INVALID_HANDLE;
1484 if (info->builtin_domain) {
1485 DEBUG(5,("_samr_QueryDisplayInfo: Nothing in BUILTIN\n"));
1486 return NT_STATUS_OK;
1489 status = access_check_samr_function(info->acc_granted,
1490 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
1491 "_samr_QueryDisplayInfo");
1492 if (!NT_STATUS_IS_OK(status)) {
1497 * calculate how many entries we will return.
1499 * - the number of entries the client asked
1500 * - our limit on that
1501 * - the starting point (enumeration context)
1502 * - the buffer size the client will accept
1506 * We are a lot more like W2K. Instead of reading the SAM
1507 * each time to find the records we need to send back,
1508 * we read it once and link that copy to the sam handle.
1509 * For large user list (over the MAX_SAM_ENTRIES)
1510 * it's a definitive win.
1511 * second point to notice: between enumerations
1512 * our sam is now the same as it's a snapshoot.
1513 * third point: got rid of the static SAM_USER_21 struct
1514 * no more intermediate.
1515 * con: it uses much more memory, as a full copy is stored
1518 * If you want to change it, think twice and think
1519 * of the second point , that's really important.
1524 if ((r->in.level < 1) || (r->in.level > 5)) {
1525 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1526 (unsigned int)r->in.level ));
1527 return NT_STATUS_INVALID_INFO_CLASS;
1530 /* first limit the number of entries we will return */
1531 if(max_entries > max_sam_entries) {
1532 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1533 "entries, limiting to %d\n", max_entries,
1535 max_entries = max_sam_entries;
1538 /* calculate the size and limit on the number of entries we will
1541 temp_size=max_entries*struct_size;
1543 if (temp_size>max_size) {
1544 max_entries=MIN((max_size/struct_size),max_entries);;
1545 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1546 "only %d entries\n", max_entries));
1551 /* THe following done as ROOT. Don't return without unbecome_root(). */
1553 switch (r->in.level) {
1556 if (info->disp_info->users == NULL) {
1557 info->disp_info->users = pdb_search_users(
1558 info->disp_info, ACB_NORMAL);
1559 if (info->disp_info->users == NULL) {
1561 return NT_STATUS_ACCESS_DENIED;
1563 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1564 (unsigned int)enum_context ));
1566 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1567 (unsigned int)enum_context ));
1570 num_account = pdb_search_entries(info->disp_info->users,
1571 enum_context, max_entries,
1575 if (info->disp_info->machines == NULL) {
1576 info->disp_info->machines = pdb_search_users(
1577 info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
1578 if (info->disp_info->machines == NULL) {
1580 return NT_STATUS_ACCESS_DENIED;
1582 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1583 (unsigned int)enum_context ));
1585 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1586 (unsigned int)enum_context ));
1589 num_account = pdb_search_entries(info->disp_info->machines,
1590 enum_context, max_entries,
1595 if (info->disp_info->groups == NULL) {
1596 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 alias_info->all.name.string = alias_name;
1767 alias_info->all.num_members = 1; /* ??? */
1768 alias_info->all.description.string = alias_description;
1771 alias_info->name.string = alias_name;
1773 case ALIASINFODESCRIPTION:
1774 alias_info->description.string = alias_description;
1777 return NT_STATUS_INVALID_INFO_CLASS;
1780 *r->out.info = alias_info;
1782 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__));
1784 return NT_STATUS_OK;
1787 /*******************************************************************
1789 ********************************************************************/
1791 NTSTATUS _samr_LookupNames(pipes_struct *p,
1792 struct samr_LookupNames *r)
1796 enum lsa_SidType *type;
1798 int num_rids = r->in.num_names;
1801 struct samr_Ids rids, types;
1802 uint32_t num_mapped = 0;
1804 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1806 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL)) {
1807 return NT_STATUS_OBJECT_TYPE_MISMATCH;
1810 status = access_check_samr_function(acc_granted,
1811 0, /* Don't know the acc_bits yet */
1812 "_samr_LookupNames");
1813 if (!NT_STATUS_IS_OK(status)) {
1817 if (num_rids > MAX_SAM_ENTRIES) {
1818 num_rids = MAX_SAM_ENTRIES;
1819 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids));
1822 rid = talloc_array(p->mem_ctx, uint32, num_rids);
1823 NT_STATUS_HAVE_NO_MEMORY(rid);
1825 type = talloc_array(p->mem_ctx, enum lsa_SidType, num_rids);
1826 NT_STATUS_HAVE_NO_MEMORY(type);
1828 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1829 sid_string_dbg(&pol_sid)));
1831 for (i = 0; i < num_rids; i++) {
1833 status = NT_STATUS_NONE_MAPPED;
1834 type[i] = SID_NAME_UNKNOWN;
1836 rid[i] = 0xffffffff;
1838 if (sid_check_is_builtin(&pol_sid)) {
1839 if (lookup_builtin_name(r->in.names[i].string,
1842 type[i] = SID_NAME_ALIAS;
1845 lookup_global_sam_name(r->in.names[i].string, 0,
1849 if (type[i] != SID_NAME_UNKNOWN) {
1854 if (num_mapped == num_rids) {
1855 status = NT_STATUS_OK;
1856 } else if (num_mapped == 0) {
1857 status = NT_STATUS_NONE_MAPPED;
1859 status = STATUS_SOME_UNMAPPED;
1862 rids.count = num_rids;
1865 types.count = num_rids;
1868 *r->out.rids = rids;
1869 *r->out.types = types;
1871 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__));
1876 /****************************************************************
1877 _samr_ChangePasswordUser
1878 ****************************************************************/
1880 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
1881 struct samr_ChangePasswordUser *r)
1886 struct samr_Password new_lmPwdHash, new_ntPwdHash, checkHash;
1887 struct samr_Password lm_pwd, nt_pwd;
1888 uint32_t acc_granted;
1891 DISP_INFO *disp_info = NULL;
1893 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, &disp_info)) {
1894 return NT_STATUS_INVALID_HANDLE;
1897 status = access_check_samr_function(acc_granted,
1898 SAMR_USER_ACCESS_SET_PASSWORD,
1899 "_samr_ChangePasswordUser");
1900 if (!NT_STATUS_IS_OK(status)) {
1904 DEBUG(5,("_samr_ChangePasswordUser: sid:%s\n",
1905 sid_string_dbg(&sid)));
1907 if (!(pwd = samu_new(NULL))) {
1908 return NT_STATUS_NO_MEMORY;
1912 ret = pdb_getsampwsid(pwd, &sid);
1917 return NT_STATUS_WRONG_PASSWORD;
1921 const uint8_t *lm_pass, *nt_pass;
1923 lm_pass = pdb_get_lanman_passwd(pwd);
1924 nt_pass = pdb_get_nt_passwd(pwd);
1926 if (!lm_pass || !nt_pass) {
1927 status = NT_STATUS_WRONG_PASSWORD;
1931 memcpy(&lm_pwd.hash, lm_pass, sizeof(lm_pwd.hash));
1932 memcpy(&nt_pwd.hash, nt_pass, sizeof(nt_pwd.hash));
1935 /* basic sanity checking on parameters. Do this before any database ops */
1936 if (!r->in.lm_present || !r->in.nt_present ||
1937 !r->in.old_lm_crypted || !r->in.new_lm_crypted ||
1938 !r->in.old_nt_crypted || !r->in.new_nt_crypted) {
1939 /* we should really handle a change with lm not
1941 status = NT_STATUS_INVALID_PARAMETER_MIX;
1945 /* decrypt and check the new lm hash */
1946 D_P16(lm_pwd.hash, r->in.new_lm_crypted->hash, new_lmPwdHash.hash);
1947 D_P16(new_lmPwdHash.hash, r->in.old_lm_crypted->hash, checkHash.hash);
1948 if (memcmp(checkHash.hash, lm_pwd.hash, 16) != 0) {
1949 status = NT_STATUS_WRONG_PASSWORD;
1953 /* decrypt and check the new nt hash */
1954 D_P16(nt_pwd.hash, r->in.new_nt_crypted->hash, new_ntPwdHash.hash);
1955 D_P16(new_ntPwdHash.hash, r->in.old_nt_crypted->hash, checkHash.hash);
1956 if (memcmp(checkHash.hash, nt_pwd.hash, 16) != 0) {
1957 status = NT_STATUS_WRONG_PASSWORD;
1961 /* The NT Cross is not required by Win2k3 R2, but if present
1962 check the nt cross hash */
1963 if (r->in.cross1_present && r->in.nt_cross) {
1964 D_P16(lm_pwd.hash, r->in.nt_cross->hash, checkHash.hash);
1965 if (memcmp(checkHash.hash, new_ntPwdHash.hash, 16) != 0) {
1966 status = NT_STATUS_WRONG_PASSWORD;
1971 /* The LM Cross is not required by Win2k3 R2, but if present
1972 check the lm cross hash */
1973 if (r->in.cross2_present && r->in.lm_cross) {
1974 D_P16(nt_pwd.hash, r->in.lm_cross->hash, checkHash.hash);
1975 if (memcmp(checkHash.hash, new_lmPwdHash.hash, 16) != 0) {
1976 status = NT_STATUS_WRONG_PASSWORD;
1981 if (!pdb_set_nt_passwd(pwd, new_ntPwdHash.hash, PDB_CHANGED) ||
1982 !pdb_set_lanman_passwd(pwd, new_lmPwdHash.hash, PDB_CHANGED)) {
1983 status = NT_STATUS_ACCESS_DENIED;
1987 status = pdb_update_sam_account(pwd);
1994 /*******************************************************************
1995 _samr_ChangePasswordUser2
1996 ********************************************************************/
1998 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
1999 struct samr_ChangePasswordUser2 *r)
2005 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
2007 fstrcpy(user_name, r->in.account->string);
2008 fstrcpy(wks, r->in.server->string);
2010 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
2013 * Pass the user through the NT -> unix user mapping
2017 (void)map_username(user_name);
2020 * UNIX username case mangling not required, pass_oem_change
2021 * is case insensitive.
2024 status = pass_oem_change(user_name,
2025 r->in.lm_password->data,
2026 r->in.lm_verifier->hash,
2027 r->in.nt_password->data,
2028 r->in.nt_verifier->hash,
2031 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__));
2033 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
2034 return NT_STATUS_WRONG_PASSWORD;
2040 /****************************************************************
2041 _samr_OemChangePasswordUser2
2042 ****************************************************************/
2044 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
2045 struct samr_OemChangePasswordUser2 *r)
2049 const char *wks = NULL;
2051 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__));
2053 fstrcpy(user_name, r->in.account->string);
2054 if (r->in.server && r->in.server->string) {
2055 wks = r->in.server->string;
2058 DEBUG(5,("_samr_OemChangePasswordUser2: user: %s wks: %s\n", user_name, wks));
2061 * Pass the user through the NT -> unix user mapping
2065 (void)map_username(user_name);
2068 * UNIX username case mangling not required, pass_oem_change
2069 * is case insensitive.
2072 if (!r->in.hash || !r->in.password) {
2073 return NT_STATUS_INVALID_PARAMETER;
2076 status = pass_oem_change(user_name,
2077 r->in.password->data,
2083 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
2084 return NT_STATUS_WRONG_PASSWORD;
2087 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__));
2092 /*******************************************************************
2093 _samr_ChangePasswordUser3
2094 ********************************************************************/
2096 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
2097 struct samr_ChangePasswordUser3 *r)
2101 const char *wks = NULL;
2102 uint32 reject_reason;
2103 struct samr_DomInfo1 *dominfo = NULL;
2104 struct samr_ChangeReject *reject = NULL;
2107 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2109 fstrcpy(user_name, r->in.account->string);
2110 if (r->in.server && r->in.server->string) {
2111 wks = r->in.server->string;
2114 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name, wks));
2117 * Pass the user through the NT -> unix user mapping
2121 (void)map_username(user_name);
2124 * UNIX username case mangling not required, pass_oem_change
2125 * is case insensitive.
2128 status = pass_oem_change(user_name,
2129 r->in.lm_password->data,
2130 r->in.lm_verifier->hash,
2131 r->in.nt_password->data,
2132 r->in.nt_verifier->hash,
2134 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
2135 return NT_STATUS_WRONG_PASSWORD;
2138 if (NT_STATUS_EQUAL(status, NT_STATUS_PASSWORD_RESTRICTION) ||
2139 NT_STATUS_EQUAL(status, NT_STATUS_ACCOUNT_RESTRICTION)) {
2141 time_t u_expire, u_min_age;
2142 uint32 account_policy_temp;
2144 dominfo = TALLOC_ZERO_P(p->mem_ctx, struct samr_DomInfo1);
2146 return NT_STATUS_NO_MEMORY;
2149 reject = TALLOC_ZERO_P(p->mem_ctx, struct samr_ChangeReject);
2151 return NT_STATUS_NO_MEMORY;
2158 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &tmp);
2159 dominfo->min_password_length = tmp;
2161 pdb_get_account_policy(AP_PASSWORD_HISTORY, &tmp);
2162 dominfo->password_history_length = tmp;
2164 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
2165 &dominfo->password_properties);
2167 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2168 u_expire = account_policy_temp;
2170 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2171 u_min_age = account_policy_temp;
2177 unix_to_nt_time_abs((NTTIME *)&dominfo->max_password_age, u_expire);
2178 unix_to_nt_time_abs((NTTIME *)&dominfo->min_password_age, u_min_age);
2180 if (lp_check_password_script() && *lp_check_password_script()) {
2181 dominfo->password_properties |= DOMAIN_PASSWORD_COMPLEX;
2184 reject->reason = reject_reason;
2186 *r->out.dominfo = dominfo;
2187 *r->out.reject = reject;
2190 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__));
2195 /*******************************************************************
2196 makes a SAMR_R_LOOKUP_RIDS structure.
2197 ********************************************************************/
2199 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
2201 struct lsa_String **lsa_name_array_p)
2203 struct lsa_String *lsa_name_array = NULL;
2206 *lsa_name_array_p = NULL;
2208 if (num_names != 0) {
2209 lsa_name_array = TALLOC_ZERO_ARRAY(ctx, struct lsa_String, num_names);
2210 if (!lsa_name_array) {
2215 for (i = 0; i < num_names; i++) {
2216 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
2217 init_lsa_String(&lsa_name_array[i], names[i]);
2220 *lsa_name_array_p = lsa_name_array;
2225 /*******************************************************************
2227 ********************************************************************/
2229 NTSTATUS _samr_LookupRids(pipes_struct *p,
2230 struct samr_LookupRids *r)
2234 enum lsa_SidType *attrs = NULL;
2235 uint32 *wire_attrs = NULL;
2237 int num_rids = (int)r->in.num_rids;
2240 struct lsa_Strings names_array;
2241 struct samr_Ids types_array;
2242 struct lsa_String *lsa_names = NULL;
2244 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2246 /* find the policy handle. open a policy on it. */
2247 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &pol_sid, &acc_granted, NULL))
2248 return NT_STATUS_INVALID_HANDLE;
2250 status = access_check_samr_function(acc_granted,
2251 0, /* Don't know the acc_bits yet */
2252 "_samr_LookupRids");
2253 if (!NT_STATUS_IS_OK(status)) {
2257 if (num_rids > 1000) {
2258 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2259 "to samba4 idl this is not possible\n", num_rids));
2260 return NT_STATUS_UNSUCCESSFUL;
2264 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
2265 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
2266 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
2268 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
2269 return NT_STATUS_NO_MEMORY;
2276 become_root(); /* lookup_sid can require root privs */
2277 status = pdb_lookup_rids(&pol_sid, num_rids, r->in.rids,
2281 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED) && (num_rids == 0)) {
2282 status = NT_STATUS_OK;
2285 if (!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
2287 return NT_STATUS_NO_MEMORY;
2290 /* Convert from enum lsa_SidType to uint32 for wire format. */
2291 for (i = 0; i < num_rids; i++) {
2292 wire_attrs[i] = (uint32)attrs[i];
2295 names_array.count = num_rids;
2296 names_array.names = lsa_names;
2298 types_array.count = num_rids;
2299 types_array.ids = wire_attrs;
2301 *r->out.names = names_array;
2302 *r->out.types = types_array;
2304 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__));
2309 /*******************************************************************
2311 ********************************************************************/
2313 NTSTATUS _samr_OpenUser(pipes_struct *p,
2314 struct samr_OpenUser *r)
2316 struct samu *sampass=NULL;
2318 struct samr_info *info = NULL;
2319 SEC_DESC *psd = NULL;
2321 uint32 des_access = r->in.access_mask;
2322 uint32_t extra_access = 0;
2328 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2330 if ( !get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL) )
2331 return NT_STATUS_INVALID_HANDLE;
2333 nt_status = access_check_samr_function(acc_granted,
2334 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
2337 if ( !NT_STATUS_IS_OK(nt_status) )
2340 if ( !(sampass = samu_new( p->mem_ctx )) ) {
2341 return NT_STATUS_NO_MEMORY;
2344 /* append the user's RID to it */
2346 if (!sid_append_rid(&sid, r->in.rid))
2347 return NT_STATUS_NO_SUCH_USER;
2349 /* check if access can be granted as requested by client. */
2351 map_max_allowed_access(p->server_info->ptok, &des_access);
2353 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
2354 se_map_generic(&des_access, &usr_generic_mapping);
2357 * Get the sampass first as we need to check privilages
2358 * based on what kind of user object this is.
2359 * But don't reveal info too early if it didn't exist.
2363 ret=pdb_getsampwsid(sampass, &sid);
2366 se_priv_copy(&se_rights, &se_priv_none);
2369 * We do the override access checks on *open*, not at
2373 uint32_t acb_info = pdb_get_acct_ctrl(sampass);
2375 if ((acb_info & ACB_WSTRUST) &&
2376 user_has_any_privilege(p->server_info->ptok,
2377 &se_machine_account)) {
2379 * SeMachineAccount is needed to add
2380 * GENERIC_RIGHTS_USER_WRITE to a machine
2383 se_priv_add(&se_rights, &se_machine_account);
2384 DEBUG(10,("_samr_OpenUser: adding machine account "
2385 "rights to handle for user %s\n",
2386 pdb_get_username(sampass) ));
2388 if ((acb_info & ACB_NORMAL) &&
2389 user_has_any_privilege(p->server_info->ptok,
2392 * SeAddUsers is needed to add
2393 * GENERIC_RIGHTS_USER_WRITE to a normal
2396 se_priv_add(&se_rights, &se_add_users);
2397 DEBUG(10,("_samr_OpenUser: adding add user "
2398 "rights to handle for user %s\n",
2399 pdb_get_username(sampass) ));
2402 * Cheat - allow GENERIC_RIGHTS_USER_WRITE if pipe user is
2403 * in DOMAIN_GROUP_RID_ADMINS. This is almost certainly not
2404 * what Windows does but is a hack for people who haven't
2405 * set up privilages on groups in Samba.
2407 if (acb_info & (ACB_SVRTRUST|ACB_DOMTRUST)) {
2408 if (lp_enable_privileges() && nt_token_check_domain_rid(p->server_info->ptok,
2409 DOMAIN_GROUP_RID_ADMINS)) {
2410 des_access &= ~GENERIC_RIGHTS_USER_WRITE;
2411 extra_access = GENERIC_RIGHTS_USER_WRITE;
2412 DEBUG(4,("_samr_OpenUser: Allowing "
2413 "GENERIC_RIGHTS_USER_WRITE for "
2419 TALLOC_FREE(sampass);
2421 nt_status = access_check_samr_object(psd, p->server_info->ptok,
2422 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2423 &acc_granted, "_samr_OpenUser");
2425 if ( !NT_STATUS_IS_OK(nt_status) )
2428 /* check that the SID exists in our domain. */
2430 return NT_STATUS_NO_SUCH_USER;
2433 /* If we did the rid admins hack above, allow access. */
2434 acc_granted |= extra_access;
2436 /* associate the user's SID and access bits with the new handle. */
2437 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
2438 return NT_STATUS_NO_MEMORY;
2439 info->acc_granted = acc_granted;
2441 /* get a (unique) handle. open a policy on it. */
2442 if (!create_policy_hnd(p, r->out.user_handle, info))
2443 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2445 return NT_STATUS_OK;
2448 /*************************************************************************
2449 *************************************************************************/
2451 static NTSTATUS init_samr_parameters_string(TALLOC_CTX *mem_ctx,
2453 struct lsa_BinaryString **_r)
2455 struct lsa_BinaryString *r;
2458 return NT_STATUS_INVALID_PARAMETER;
2461 r = TALLOC_ZERO_P(mem_ctx, struct lsa_BinaryString);
2463 return NT_STATUS_NO_MEMORY;
2466 r->array = TALLOC_ZERO_ARRAY(mem_ctx, uint16_t, blob->length/2);
2468 return NT_STATUS_NO_MEMORY;
2470 memcpy(r->array, blob->data, blob->length);
2471 r->size = blob->length;
2472 r->length = blob->length;
2475 return NT_STATUS_NO_MEMORY;
2480 return NT_STATUS_OK;
2483 /*************************************************************************
2485 *************************************************************************/
2487 static NTSTATUS get_user_info_1(TALLOC_CTX *mem_ctx,
2488 struct samr_UserInfo1 *r,
2490 DOM_SID *domain_sid)
2492 const DOM_SID *sid_group;
2493 uint32_t primary_gid;
2496 sid_group = pdb_get_group_sid(pw);
2499 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2500 DEBUG(0, ("get_user_info_1: User %s has Primary Group SID %s, \n"
2501 "which conflicts with the domain sid %s. Failing operation.\n",
2502 pdb_get_username(pw), sid_string_dbg(sid_group),
2503 sid_string_dbg(domain_sid)));
2504 return NT_STATUS_UNSUCCESSFUL;
2507 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2508 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2509 r->primary_gid = primary_gid;
2510 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2511 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2513 return NT_STATUS_OK;
2516 /*************************************************************************
2518 *************************************************************************/
2520 static NTSTATUS get_user_info_2(TALLOC_CTX *mem_ctx,
2521 struct samr_UserInfo2 *r,
2524 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2525 r->unknown.string = NULL;
2526 r->country_code = 0;
2529 return NT_STATUS_OK;
2532 /*************************************************************************
2534 *************************************************************************/
2536 static NTSTATUS get_user_info_3(TALLOC_CTX *mem_ctx,
2537 struct samr_UserInfo3 *r,
2539 DOM_SID *domain_sid)
2541 const DOM_SID *sid_user, *sid_group;
2542 uint32_t rid, primary_gid;
2544 sid_user = pdb_get_user_sid(pw);
2546 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2547 DEBUG(0, ("get_user_info_3: User %s has SID %s, \nwhich conflicts with "
2548 "the domain sid %s. Failing operation.\n",
2549 pdb_get_username(pw), sid_string_dbg(sid_user),
2550 sid_string_dbg(domain_sid)));
2551 return NT_STATUS_UNSUCCESSFUL;
2555 sid_group = pdb_get_group_sid(pw);
2558 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2559 DEBUG(0, ("get_user_info_3: User %s has Primary Group SID %s, \n"
2560 "which conflicts with the domain sid %s. Failing operation.\n",
2561 pdb_get_username(pw), sid_string_dbg(sid_group),
2562 sid_string_dbg(domain_sid)));
2563 return NT_STATUS_UNSUCCESSFUL;
2566 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2567 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2568 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2569 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2570 unix_to_nt_time(&r->force_password_change, pdb_get_pass_must_change_time(pw));
2572 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2573 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2574 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2575 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2576 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2577 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2578 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2580 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2582 r->primary_gid = primary_gid;
2583 r->acct_flags = pdb_get_acct_ctrl(pw);
2584 r->bad_password_count = pdb_get_bad_password_count(pw);
2585 r->logon_count = pdb_get_logon_count(pw);
2587 return NT_STATUS_OK;
2590 /*************************************************************************
2592 *************************************************************************/
2594 static NTSTATUS get_user_info_4(TALLOC_CTX *mem_ctx,
2595 struct samr_UserInfo4 *r,
2598 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2600 return NT_STATUS_OK;
2603 /*************************************************************************
2605 *************************************************************************/
2607 static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
2608 struct samr_UserInfo5 *r,
2610 DOM_SID *domain_sid)
2612 const DOM_SID *sid_user, *sid_group;
2613 uint32_t rid, primary_gid;
2615 sid_user = pdb_get_user_sid(pw);
2617 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2618 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2619 "the domain sid %s. Failing operation.\n",
2620 pdb_get_username(pw), sid_string_dbg(sid_user),
2621 sid_string_dbg(domain_sid)));
2622 return NT_STATUS_UNSUCCESSFUL;
2626 sid_group = pdb_get_group_sid(pw);
2629 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2630 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2631 "which conflicts with the domain sid %s. Failing operation.\n",
2632 pdb_get_username(pw), sid_string_dbg(sid_group),
2633 sid_string_dbg(domain_sid)));
2634 return NT_STATUS_UNSUCCESSFUL;
2637 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2638 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2639 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2640 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2642 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2643 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2644 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2645 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2646 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2647 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2648 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2649 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2651 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2653 r->primary_gid = primary_gid;
2654 r->acct_flags = pdb_get_acct_ctrl(pw);
2655 r->bad_password_count = pdb_get_bad_password_count(pw);
2656 r->logon_count = pdb_get_logon_count(pw);
2658 return NT_STATUS_OK;
2661 /*************************************************************************
2663 *************************************************************************/
2665 static NTSTATUS get_user_info_6(TALLOC_CTX *mem_ctx,
2666 struct samr_UserInfo6 *r,
2669 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2670 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2672 return NT_STATUS_OK;
2675 /*************************************************************************
2676 get_user_info_7. Safe. Only gives out account_name.
2677 *************************************************************************/
2679 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
2680 struct samr_UserInfo7 *r,
2681 struct samu *smbpass)
2683 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
2684 if (!r->account_name.string) {
2685 return NT_STATUS_NO_MEMORY;
2688 return NT_STATUS_OK;
2691 /*************************************************************************
2693 *************************************************************************/
2695 static NTSTATUS get_user_info_8(TALLOC_CTX *mem_ctx,
2696 struct samr_UserInfo8 *r,
2699 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2701 return NT_STATUS_OK;
2704 /*************************************************************************
2705 get_user_info_9. Only gives out primary group SID.
2706 *************************************************************************/
2708 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
2709 struct samr_UserInfo9 *r,
2710 struct samu *smbpass)
2712 r->primary_gid = pdb_get_group_rid(smbpass);
2714 return NT_STATUS_OK;
2717 /*************************************************************************
2719 *************************************************************************/
2721 static NTSTATUS get_user_info_10(TALLOC_CTX *mem_ctx,
2722 struct samr_UserInfo10 *r,
2725 r->home_directory.string= talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2726 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2728 return NT_STATUS_OK;
2731 /*************************************************************************
2733 *************************************************************************/
2735 static NTSTATUS get_user_info_11(TALLOC_CTX *mem_ctx,
2736 struct samr_UserInfo11 *r,
2739 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2741 return NT_STATUS_OK;
2744 /*************************************************************************
2746 *************************************************************************/
2748 static NTSTATUS get_user_info_12(TALLOC_CTX *mem_ctx,
2749 struct samr_UserInfo12 *r,
2752 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2754 return NT_STATUS_OK;
2757 /*************************************************************************
2759 *************************************************************************/
2761 static NTSTATUS get_user_info_13(TALLOC_CTX *mem_ctx,
2762 struct samr_UserInfo13 *r,
2765 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2767 return NT_STATUS_OK;
2770 /*************************************************************************
2772 *************************************************************************/
2774 static NTSTATUS get_user_info_14(TALLOC_CTX *mem_ctx,
2775 struct samr_UserInfo14 *r,
2778 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2780 return NT_STATUS_OK;
2783 /*************************************************************************
2784 get_user_info_16. Safe. Only gives out acb bits.
2785 *************************************************************************/
2787 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
2788 struct samr_UserInfo16 *r,
2789 struct samu *smbpass)
2791 r->acct_flags = pdb_get_acct_ctrl(smbpass);
2793 return NT_STATUS_OK;
2796 /*************************************************************************
2798 *************************************************************************/
2800 static NTSTATUS get_user_info_17(TALLOC_CTX *mem_ctx,
2801 struct samr_UserInfo17 *r,
2804 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2806 return NT_STATUS_OK;
2809 /*************************************************************************
2810 get_user_info_18. OK - this is the killer as it gives out password info.
2811 Ensure that this is only allowed on an encrypted connection with a root
2813 *************************************************************************/
2815 static NTSTATUS get_user_info_18(pipes_struct *p,
2816 TALLOC_CTX *mem_ctx,
2817 struct samr_UserInfo18 *r,
2820 struct samu *smbpass=NULL;
2825 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
2826 return NT_STATUS_ACCESS_DENIED;
2829 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
2830 return NT_STATUS_ACCESS_DENIED;
2834 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2837 if ( !(smbpass = samu_new( mem_ctx )) ) {
2838 return NT_STATUS_NO_MEMORY;
2841 ret = pdb_getsampwsid(smbpass, user_sid);
2844 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
2845 TALLOC_FREE(smbpass);
2846 return (geteuid() == sec_initial_uid()) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
2849 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
2851 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
2852 TALLOC_FREE(smbpass);
2853 return NT_STATUS_ACCOUNT_DISABLED;
2856 r->lm_pwd_active = true;
2857 r->nt_pwd_active = true;
2858 memcpy(r->lm_pwd.hash, pdb_get_lanman_passwd(smbpass), 16);
2859 memcpy(r->nt_pwd.hash, pdb_get_nt_passwd(smbpass), 16);
2860 r->password_expired = 0; /* FIXME */
2862 TALLOC_FREE(smbpass);
2864 return NT_STATUS_OK;
2867 /*************************************************************************
2869 *************************************************************************/
2871 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
2872 struct samr_UserInfo20 *r,
2873 struct samu *sampass)
2875 const char *munged_dial = NULL;
2878 struct lsa_BinaryString *parameters = NULL;
2882 munged_dial = pdb_get_munged_dial(sampass);
2884 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
2885 munged_dial, (int)strlen(munged_dial)));
2888 blob = base64_decode_data_blob(munged_dial);
2890 blob = data_blob_string_const_null("");
2893 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2894 data_blob_free(&blob);
2895 if (!NT_STATUS_IS_OK(status)) {
2899 r->parameters = *parameters;
2901 return NT_STATUS_OK;
2905 /*************************************************************************
2907 *************************************************************************/
2909 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
2910 struct samr_UserInfo21 *r,
2912 DOM_SID *domain_sid)
2915 const DOM_SID *sid_user, *sid_group;
2916 uint32_t rid, primary_gid;
2917 NTTIME force_password_change;
2918 time_t must_change_time;
2919 struct lsa_BinaryString *parameters = NULL;
2920 const char *munged_dial = NULL;
2925 sid_user = pdb_get_user_sid(pw);
2927 if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
2928 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2929 "the domain sid %s. Failing operation.\n",
2930 pdb_get_username(pw), sid_string_dbg(sid_user),
2931 sid_string_dbg(domain_sid)));
2932 return NT_STATUS_UNSUCCESSFUL;
2936 sid_group = pdb_get_group_sid(pw);
2939 if (!sid_peek_check_rid(domain_sid, sid_group, &primary_gid)) {
2940 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2941 "which conflicts with the domain sid %s. Failing operation.\n",
2942 pdb_get_username(pw), sid_string_dbg(sid_group),
2943 sid_string_dbg(domain_sid)));
2944 return NT_STATUS_UNSUCCESSFUL;
2947 unix_to_nt_time(&r->last_logon, pdb_get_logon_time(pw));
2948 unix_to_nt_time(&r->last_logoff, pdb_get_logoff_time(pw));
2949 unix_to_nt_time(&r->acct_expiry, pdb_get_kickoff_time(pw));
2950 unix_to_nt_time(&r->last_password_change, pdb_get_pass_last_set_time(pw));
2951 unix_to_nt_time(&r->allow_password_change, pdb_get_pass_can_change_time(pw));
2953 must_change_time = pdb_get_pass_must_change_time(pw);
2954 if (must_change_time == get_time_t_max()) {
2955 unix_to_nt_time_abs(&force_password_change, must_change_time);
2957 unix_to_nt_time(&force_password_change, must_change_time);
2960 munged_dial = pdb_get_munged_dial(pw);
2962 blob = base64_decode_data_blob(munged_dial);
2964 blob = data_blob_string_const_null("");
2967 status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
2968 data_blob_free(&blob);
2969 if (!NT_STATUS_IS_OK(status)) {
2973 r->force_password_change = force_password_change;
2975 r->account_name.string = talloc_strdup(mem_ctx, pdb_get_username(pw));
2976 r->full_name.string = talloc_strdup(mem_ctx, pdb_get_fullname(pw));
2977 r->home_directory.string = talloc_strdup(mem_ctx, pdb_get_homedir(pw));
2978 r->home_drive.string = talloc_strdup(mem_ctx, pdb_get_dir_drive(pw));
2979 r->logon_script.string = talloc_strdup(mem_ctx, pdb_get_logon_script(pw));
2980 r->profile_path.string = talloc_strdup(mem_ctx, pdb_get_profile_path(pw));
2981 r->description.string = talloc_strdup(mem_ctx, pdb_get_acct_desc(pw));
2982 r->workstations.string = talloc_strdup(mem_ctx, pdb_get_workstations(pw));
2983 r->comment.string = talloc_strdup(mem_ctx, pdb_get_comment(pw));
2985 r->logon_hours = get_logon_hours_from_pdb(mem_ctx, pw);
2986 r->parameters = *parameters;
2988 r->primary_gid = primary_gid;
2989 r->acct_flags = pdb_get_acct_ctrl(pw);
2990 r->bad_password_count = pdb_get_bad_password_count(pw);
2991 r->logon_count = pdb_get_logon_count(pw);
2992 r->fields_present = pdb_build_fields_present(pw);
2993 r->password_expired = (pdb_get_pass_must_change_time(pw) == 0) ?
2994 PASS_MUST_CHANGE_AT_NEXT_LOGON : 0;
2995 r->country_code = 0;
2997 r->lm_password_set = 0;
2998 r->nt_password_set = 0;
3003 Look at a user on a real NT4 PDC with usrmgr, press
3004 'ok'. Then you will see that fields_present is set to
3005 0x08f827fa. Look at the user immediately after that again,
3006 and you will see that 0x00fffff is returned. This solves
3007 the problem that you get access denied after having looked
3015 return NT_STATUS_OK;
3018 /*******************************************************************
3020 ********************************************************************/
3022 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
3023 struct samr_QueryUserInfo *r)
3026 union samr_UserInfo *user_info = NULL;
3027 struct samr_info *info = NULL;
3031 struct samu *pwd = NULL;
3033 /* search for the handle */
3034 if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
3035 return NT_STATUS_INVALID_HANDLE;
3037 status = access_check_samr_function(info->acc_granted,
3038 SAMR_USER_ACCESS_GET_ATTRIBUTES,
3039 "_samr_QueryUserInfo");
3040 if (!NT_STATUS_IS_OK(status)) {
3044 domain_sid = info->sid;
3046 sid_split_rid(&domain_sid, &rid);
3048 if (!sid_check_is_in_our_domain(&info->sid))
3049 return NT_STATUS_OBJECT_TYPE_MISMATCH;
3051 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
3052 sid_string_dbg(&info->sid)));
3054 user_info = TALLOC_ZERO_P(p->mem_ctx, union samr_UserInfo);
3056 return NT_STATUS_NO_MEMORY;
3059 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
3061 if (!(pwd = samu_new(p->mem_ctx))) {
3062 return NT_STATUS_NO_MEMORY;
3066 ret = pdb_getsampwsid(pwd, &info->sid);
3070 DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
3072 return NT_STATUS_NO_SUCH_USER;
3075 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
3077 samr_clear_sam_passwd(pwd);
3079 switch (r->in.level) {
3081 status = get_user_info_1(p->mem_ctx, &user_info->info1, pwd, &domain_sid);
3084 status = get_user_info_2(p->mem_ctx, &user_info->info2, pwd);
3087 status = get_user_info_3(p->mem_ctx, &user_info->info3, pwd, &domain_sid);
3090 status = get_user_info_4(p->mem_ctx, &user_info->info4, pwd);
3093 status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
3096 status = get_user_info_6(p->mem_ctx, &user_info->info6, pwd);
3099 status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
3102 status = get_user_info_8(p->mem_ctx, &user_info->info8, pwd);
3105 status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
3108 status = get_user_info_10(p->mem_ctx, &user_info->info10, pwd);
3111 status = get_user_info_11(p->mem_ctx, &user_info->info11, pwd);
3114 status = get_user_info_12(p->mem_ctx, &user_info->info12, pwd);
3117 status = get_user_info_13(p->mem_ctx, &user_info->info13, pwd);
3120 status = get_user_info_14(p->mem_ctx, &user_info->info14, pwd);
3123 status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
3126 status = get_user_info_17(p->mem_ctx, &user_info->info17, pwd);
3129 /* level 18 is special */
3130 status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
3133 status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
3136 status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
3139 status = NT_STATUS_INVALID_INFO_CLASS;
3143 if (!NT_STATUS_IS_OK(status)) {
3147 *r->out.info = user_info;
3152 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
3157 /****************************************************************
3158 ****************************************************************/
3160 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
3161 struct samr_QueryUserInfo2 *r)
3163 struct samr_QueryUserInfo u;
3165 u.in.user_handle = r->in.user_handle;
3166 u.in.level = r->in.level;
3167 u.out.info = r->out.info;
3169 return _samr_QueryUserInfo(p, &u);
3172 /*******************************************************************
3173 _samr_GetGroupsForUser
3174 ********************************************************************/
3176 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
3177 struct samr_GetGroupsForUser *r)
3179 struct samu *sam_pass=NULL;
3182 struct samr_RidWithAttribute dom_gid;
3183 struct samr_RidWithAttribute *gids = NULL;
3184 uint32 primary_group_rid;
3185 size_t num_groups = 0;
3191 bool success = False;
3193 struct samr_RidWithAttributeArray *rids = NULL;
3196 * from the SID in the request:
3197 * we should send back the list of DOMAIN GROUPS
3198 * the user is a member of
3200 * and only the DOMAIN GROUPS
3201 * no ALIASES !!! neither aliases of the domain
3202 * nor aliases of the builtin SID
3207 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
3209 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidWithAttributeArray);
3211 return NT_STATUS_NO_MEMORY;
3214 /* find the policy handle. open a policy on it. */
3215 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, NULL))
3216 return NT_STATUS_INVALID_HANDLE;
3218 result = access_check_samr_function(acc_granted,
3219 SAMR_USER_ACCESS_GET_GROUPS,
3220 "_samr_GetGroupsForUser");
3221 if (!NT_STATUS_IS_OK(result)) {
3225 if (!sid_check_is_in_our_domain(&sid))
3226 return NT_STATUS_OBJECT_TYPE_MISMATCH;
3228 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
3229 return NT_STATUS_NO_MEMORY;
3233 ret = pdb_getsampwsid(sam_pass, &sid);
3237 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
3238 sid_string_dbg(&sid)));
3239 return NT_STATUS_NO_SUCH_USER;
3244 /* make both calls inside the root block */
3246 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
3247 &sids, &unix_gids, &num_groups);
3248 if ( NT_STATUS_IS_OK(result) ) {
3249 success = sid_peek_check_rid(get_global_sam_sid(),
3250 pdb_get_group_sid(sam_pass),
3251 &primary_group_rid);
3255 if (!NT_STATUS_IS_OK(result)) {
3256 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
3257 sid_string_dbg(&sid)));
3262 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
3263 sid_string_dbg(pdb_get_group_sid(sam_pass)),
3264 pdb_get_username(sam_pass)));
3265 TALLOC_FREE(sam_pass);
3266 return NT_STATUS_INTERNAL_DB_CORRUPTION;
3272 dom_gid.attributes = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
3274 dom_gid.rid = primary_group_rid;
3275 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
3277 for (i=0; i<num_groups; i++) {
3279 if (!sid_peek_check_rid(get_global_sam_sid(),
3280 &(sids[i]), &dom_gid.rid)) {
3281 DEBUG(10, ("Found sid %s not in our domain\n",
3282 sid_string_dbg(&sids[i])));
3286 if (dom_gid.rid == primary_group_rid) {
3287 /* We added the primary group directly from the
3288 * sam_account. The other SIDs are unique from
3289 * enum_group_memberships */
3293 ADD_TO_ARRAY(p->mem_ctx, struct samr_RidWithAttribute, dom_gid, &gids, &num_gids);
3296 rids->count = num_gids;
3299 *r->out.rids = rids;
3301 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__));
3306 /*******************************************************************
3307 _samr_QueryDomainInfo
3308 ********************************************************************/
3310 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
3311 struct samr_QueryDomainInfo *r)
3313 NTSTATUS status = NT_STATUS_OK;
3314 struct samr_info *info = NULL;
3315 union samr_DomainInfo *dom_info;
3316 time_t u_expire, u_min_age;
3318 time_t u_lock_duration, u_reset_time;
3321 uint32 account_policy_temp;
3325 uint32_t acc_required;
3327 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
3329 switch (r->in.level) {
3330 case 1: /* DomainPasswordInformation */
3331 case 12: /* DomainLockoutInformation */
3332 /* DOMAIN_READ_PASSWORD_PARAMETERS */
3333 acc_required = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1;
3335 case 11: /* DomainGeneralInformation2 */
3336 /* DOMAIN_READ_PASSWORD_PARAMETERS |
3337 * DOMAIN_READ_OTHER_PARAMETERS */
3338 acc_required = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
3339 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2;
3341 case 2: /* DomainGeneralInformation */
3342 case 3: /* DomainLogoffInformation */
3343 case 4: /* DomainOemInformation */
3344 case 5: /* DomainReplicationInformation */
3345 case 6: /* DomainReplicationInformation */
3346 case 7: /* DomainServerRoleInformation */
3347 case 8: /* DomainModifiedInformation */
3348 case 9: /* DomainStateInformation */
3349 case 10: /* DomainUasInformation */
3350 case 13: /* DomainModifiedInformation2 */
3351 /* DOMAIN_READ_OTHER_PARAMETERS */
3352 acc_required = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2;
3355 return NT_STATUS_INVALID_INFO_CLASS;
3358 dom_info = TALLOC_ZERO_P(p->mem_ctx, union samr_DomainInfo);
3360 return NT_STATUS_NO_MEMORY;
3363 /* find the policy handle. open a policy on it. */
3364 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
3365 return NT_STATUS_INVALID_HANDLE;
3368 status = access_check_samr_function(info->acc_granted,
3370 "_samr_QueryDomainInfo" );
3372 if ( !NT_STATUS_IS_OK(status) )
3375 switch (r->in.level) {
3382 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
3383 &account_policy_temp);
3384 dom_info->info1.min_password_length = account_policy_temp;
3386 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
3387 dom_info->info1.password_history_length = account_policy_temp;
3389 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
3390 &dom_info->info1.password_properties);
3392 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
3393 u_expire = account_policy_temp;
3395 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
3396 u_min_age = account_policy_temp;
3402 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.max_password_age, u_expire);
3403 unix_to_nt_time_abs((NTTIME *)&dom_info->info1.min_password_age, u_min_age);
3405 if (lp_check_password_script() && *lp_check_password_script()) {
3406 dom_info->info1.password_properties |= DOMAIN_PASSWORD_COMPLEX;
3416 dom_info->general.num_users = count_sam_users(info->disp_info, ACB_NORMAL);
3417 dom_info->general.num_groups = count_sam_groups(info->disp_info);
3418 dom_info->general.num_aliases = count_sam_aliases(info->disp_info);
3420 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
3422 unix_to_nt_time_abs(&dom_info->general.force_logoff_time, u_logout);
3424 if (!pdb_get_seq_num(&seq_num))
3425 seq_num = time(NULL);
3431 server_role = ROLE_DOMAIN_PDC;
3432 if (lp_server_role() == ROLE_DOMAIN_BDC)
3433 server_role = ROLE_DOMAIN_BDC;
3435 dom_info->general.oem_information.string = lp_serverstring();
3436 dom_info->general.domain_name.string = lp_workgroup();
3437 dom_info->general.primary.string = global_myname();
3438 dom_info->general.sequence_num = seq_num;
3439 dom_info->general.domain_server_state = DOMAIN_SERVER_ENABLED;
3440 dom_info->general.role = server_role;
3441 dom_info->general.unknown3 = 1;
3452 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
3453 u_logout = (time_t)ul;
3460 unix_to_nt_time_abs(&dom_info->info3.force_logoff_time, u_logout);
3464 dom_info->oem.oem_information.string = lp_serverstring();
3467 dom_info->info5.domain_name.string = get_global_sam_name();
3470 /* NT returns its own name when a PDC. win2k and later
3471 * only the name of the PDC if itself is a BDC (samba4
3473 dom_info->info6.primary.string = global_myname();
3476 server_role = ROLE_DOMAIN_PDC;
3477 if (lp_server_role() == ROLE_DOMAIN_BDC)
3478 server_role = ROLE_DOMAIN_BDC;
3480 dom_info->info7.role = server_role;
3488 if (!pdb_get_seq_num(&seq_num)) {
3489 seq_num = time(NULL);
3496 dom_info->info8.sequence_num = seq_num;
3497 dom_info->info8.domain_create_time = 0;
3502 dom_info->info9.domain_server_state = DOMAIN_SERVER_ENABLED;
3511 dom_info->general2.general.num_users = count_sam_users(
3512 info->disp_info, ACB_NORMAL);
3513 dom_info->general2.general.num_groups = count_sam_groups(
3515 dom_info->general2.general.num_aliases = count_sam_aliases(
3518 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &u_logout);
3520 unix_to_nt_time_abs(&dom_info->general2.general.force_logoff_time, u_logout);
3522 if (!pdb_get_seq_num(&seq_num))
3523 seq_num = time(NULL);
3525 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
3526 u_lock_duration = account_policy_temp;
3527 if (u_lock_duration != -1) {
3528 u_lock_duration *= 60;
3531 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
3532 u_reset_time = account_policy_temp * 60;
3534 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
3535 &account_policy_temp);
3536 dom_info->general2.lockout_threshold = account_policy_temp;
3542 server_role = ROLE_DOMAIN_PDC;
3543 if (lp_server_role() == ROLE_DOMAIN_BDC)
3544 server_role = ROLE_DOMAIN_BDC;
3546 dom_info->general2.general.oem_information.string = lp_serverstring();
3547 dom_info->general2.general.domain_name.string = lp_workgroup();
3548 dom_info->general2.general.primary.string = global_myname();
3549 dom_info->general2.general.sequence_num = seq_num;
3550 dom_info->general2.general.domain_server_state = DOMAIN_SERVER_ENABLED;
3551 dom_info->general2.general.role = server_role;
3552 dom_info->general2.general.unknown3 = 1;
3554 unix_to_nt_time_abs(&dom_info->general2.lockout_duration,
3556 unix_to_nt_time_abs(&dom_info->general2.lockout_window,
3566 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
3567 u_lock_duration = account_policy_temp;
3568 if (u_lock_duration != -1) {
3569 u_lock_duration *= 60;
3572 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
3573 u_reset_time = account_policy_temp * 60;
3575 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT,
3576 &account_policy_temp);
3577 dom_info->info12.lockout_threshold = account_policy_temp;
3583 unix_to_nt_time_abs(&dom_info->info12.lockout_duration,
3585 unix_to_nt_time_abs(&dom_info->info12.lockout_window,
3595 if (!pdb_get_seq_num(&seq_num)) {
3596 seq_num = time(NULL);
3603 dom_info->info13.sequence_num = seq_num;
3604 dom_info->info13.domain_create_time = 0;
3605 dom_info->info13.modified_count_at_last_promotion = 0;
3609 return NT_STATUS_INVALID_INFO_CLASS;
3612 *r->out.info = dom_info;
3614 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__));
3619 /* W2k3 seems to use the same check for all 3 objects that can be created via
3620 * SAMR, if you try to create for example "Dialup" as an alias it says
3621 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
3624 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
3626 enum lsa_SidType type;
3629 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
3632 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3633 * whether the name already exists */
3634 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
3635 NULL, NULL, NULL, &type);
3639 DEBUG(10, ("%s does not exist, can create it\n", new_name));
3640 return NT_STATUS_OK;
3643 DEBUG(5, ("trying to create %s, exists as %s\n",
3644 new_name, sid_type_lookup(type)));
3646 if (type == SID_NAME_DOM_GRP) {
3647 return NT_STATUS_GROUP_EXISTS;
3649 if (type == SID_NAME_ALIAS) {
3650 return NT_STATUS_ALIAS_EXISTS;
3653 /* Yes, the default is NT_STATUS_USER_EXISTS */
3654 return NT_STATUS_USER_EXISTS;
3657 /*******************************************************************
3659 ********************************************************************/
3661 NTSTATUS _samr_CreateUser2(pipes_struct *p,
3662 struct samr_CreateUser2 *r)
3664 const char *account = NULL;
3666 uint32_t acb_info = r->in.acct_flags;
3667 struct samr_info *info = NULL;
3672 /* check this, when giving away 'add computer to domain' privs */
3673 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
3674 bool can_add_account = False;
3676 DISP_INFO *disp_info = NULL;
3678 /* Get the domain SID stored in the domain policy */
3679 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted,
3681 return NT_STATUS_INVALID_HANDLE;
3683 if (disp_info->builtin_domain) {
3684 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3685 return NT_STATUS_ACCESS_DENIED;
3688 nt_status = access_check_samr_function(acc_granted,
3689 SAMR_DOMAIN_ACCESS_CREATE_USER,
3690 "_samr_CreateUser2");
3691 if (!NT_STATUS_IS_OK(nt_status)) {
3695 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
3696 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
3697 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3698 this parameter is not an account type */
3699 return NT_STATUS_INVALID_PARAMETER;
3702 account = r->in.account_name->string;
3703 if (account == NULL) {
3704 return NT_STATUS_NO_MEMORY;
3707 nt_status = can_create(p->mem_ctx, account);
3708 if (!NT_STATUS_IS_OK(nt_status)) {
3712 /* determine which user right we need to check based on the acb_info */
3714 if (geteuid() == sec_initial_uid()) {
3715 se_priv_copy(&se_rights, &se_priv_none);
3716 can_add_account = true;
3717 } else if (acb_info & ACB_WSTRUST) {
3718 se_priv_copy(&se_rights, &se_machine_account);
3719 can_add_account = user_has_privileges(
3720 p->server_info->ptok, &se_rights );
3721 } else if (acb_info & ACB_NORMAL &&
3722 (account[strlen(account)-1] != '$')) {
3723 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3724 account for domain trusts and changes the ACB flags later */
3725 se_priv_copy(&se_rights, &se_add_users);
3726 can_add_account = user_has_privileges(
3727 p->server_info->ptok, &se_rights );
3728 } else if (lp_enable_privileges()) {
3729 /* implicit assumption of a BDC or domain trust account here
3730 * (we already check the flags earlier) */
3731 /* only Domain Admins can add a BDC or domain trust */
3732 se_priv_copy(&se_rights, &se_priv_none);
3733 can_add_account = nt_token_check_domain_rid(
3734 p->server_info->ptok,
3735 DOMAIN_GROUP_RID_ADMINS );
3738 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3739 uidtoname(p->server_info->utok.uid),
3740 can_add_account ? "True":"False" ));
3742 if (!can_add_account) {
3743 return NT_STATUS_ACCESS_DENIED;
3746 /********** BEGIN Admin BLOCK **********/
3749 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
3753 /********** END Admin BLOCK **********/
3755 /* now check for failure */
3757 if ( !NT_STATUS_IS_OK(nt_status) )
3760 /* Get the user's SID */
3762 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
3764 map_max_allowed_access(p->server_info->ptok, &des_access);
3766 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
3767 &sid, SAMR_USR_RIGHTS_WRITE_PW);
3768 se_map_generic(&des_access, &usr_generic_mapping);
3771 * JRA - TESTME. We just created this user so we
3772 * had rights to create them. Do we need to check
3773 * any further access on this object ? Can't we
3774 * just assume we have all the rights we need ?
3777 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3778 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
3779 &acc_granted, "_samr_CreateUser2");
3781 if ( !NT_STATUS_IS_OK(nt_status) ) {
3785 /* associate the user's SID with the new handle. */
3786 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL) {
3787 return NT_STATUS_NO_MEMORY;
3792 info->acc_granted = acc_granted;
3794 /* get a (unique) handle. open a policy on it. */
3795 if (!create_policy_hnd(p, r->out.user_handle, info)) {
3796 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3799 /* After a "set" ensure we have no cached display info. */
3800 force_flush_samr_cache(info->disp_info);
3802 *r->out.access_granted = acc_granted;
3804 return NT_STATUS_OK;
3807 /****************************************************************
3808 ****************************************************************/
3810 NTSTATUS _samr_CreateUser(pipes_struct *p,
3811 struct samr_CreateUser *r)
3813 struct samr_CreateUser2 c;
3814 uint32_t access_granted;
3816 c.in.domain_handle = r->in.domain_handle;
3817 c.in.account_name = r->in.account_name;
3818 c.in.acct_flags = ACB_NORMAL;
3819 c.in.access_mask = r->in.access_mask;
3820 c.out.user_handle = r->out.user_handle;
3821 c.out.access_granted = &access_granted;
3822 c.out.rid = r->out.rid;
3824 return _samr_CreateUser2(p, &c);
3827 /*******************************************************************
3829 ********************************************************************/
3831 NTSTATUS _samr_Connect(pipes_struct *p,
3832 struct samr_Connect *r)
3834 struct samr_info *info = NULL;
3835 uint32 des_access = r->in.access_mask;
3839 if (!pipe_access_check(p)) {
3840 DEBUG(3, ("access denied to _samr_Connect\n"));
3841 return NT_STATUS_ACCESS_DENIED;
3844 /* set up the SAMR connect_anon response */
3846 /* associate the user's SID with the new handle. */
3847 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3848 return NT_STATUS_NO_MEMORY;
3850 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3851 was observed from a win98 client trying to enumerate users (when configured
3852 user level access control on shares) --jerry */
3854 map_max_allowed_access(p->server_info->ptok, &des_access);
3856 se_map_generic( &des_access, &sam_generic_mapping );
3857 info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_LOOKUP_DOMAIN);
3859 /* get a (unique) handle. open a policy on it. */
3860 if (!create_policy_hnd(p, r->out.connect_handle, info))
3861 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3863 return NT_STATUS_OK;
3866 /*******************************************************************
3868 ********************************************************************/
3870 NTSTATUS _samr_Connect2(pipes_struct *p,
3871 struct samr_Connect2 *r)
3873 struct samr_info *info = NULL;
3874 SEC_DESC *psd = NULL;
3876 uint32 des_access = r->in.access_mask;
3879 const char *fn = "_samr_Connect2";
3881 switch (p->hdr_req.opnum) {
3882 case NDR_SAMR_CONNECT2:
3883 fn = "_samr_Connect2";
3885 case NDR_SAMR_CONNECT3:
3886 fn = "_samr_Connect3";
3888 case NDR_SAMR_CONNECT4:
3889 fn = "_samr_Connect4";
3891 case NDR_SAMR_CONNECT5:
3892 fn = "_samr_Connect5";
3896 DEBUG(5,("%s: %d\n", fn, __LINE__));
3900 if (!pipe_access_check(p)) {
3901 DEBUG(3, ("access denied to %s\n", fn));
3902 return NT_STATUS_ACCESS_DENIED;
3905 map_max_allowed_access(p->server_info->ptok, &des_access);
3907 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
3908 se_map_generic(&des_access, &sam_generic_mapping);
3910 nt_status = access_check_samr_object(psd, p->server_info->ptok,
3911 NULL, 0, des_access, &acc_granted, fn);
3913 if ( !NT_STATUS_IS_OK(nt_status) )
3916 /* associate the user's SID and access granted with the new handle. */
3917 if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
3918 return NT_STATUS_NO_MEMORY;
3920 info->acc_granted = acc_granted;
3921 info->status = r->in.access_mask; /* this looks so wrong... - gd */
3923 /* get a (unique) handle. open a policy on it. */
3924 if (!create_policy_hnd(p, r->out.connect_handle, info))
3925 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3927 DEBUG(5,("%s: %d\n", fn, __LINE__));
3932 /****************************************************************
3934 ****************************************************************/
3936 NTSTATUS _samr_Connect3(pipes_struct *p,
3937 struct samr_Connect3 *r)
3939 struct samr_Connect2 c;
3941 c.in.system_name = r->in.system_name;
3942 c.in.access_mask = r->in.access_mask;
3943 c.out.connect_handle = r->out.connect_handle;
3945 return _samr_Connect2(p, &c);
3948 /*******************************************************************
3950 ********************************************************************/
3952 NTSTATUS _samr_Connect4(pipes_struct *p,
3953 struct samr_Connect4 *r)
3955 struct samr_Connect2 c;
3957 c.in.system_name = r->in.system_name;
3958 c.in.access_mask = r->in.access_mask;
3959 c.out.connect_handle = r->out.connect_handle;
3961 return _samr_Connect2(p, &c);
3964 /*******************************************************************
3966 ********************************************************************/
3968 NTSTATUS _samr_Connect5(pipes_struct *p,
3969 struct samr_Connect5 *r)
3972 struct samr_Connect2 c;
3973 struct samr_ConnectInfo1 info1;
3975 info1.client_version = SAMR_CONNECT_AFTER_W2K;
3978 c.in.system_name = r->in.system_name;
3979 c.in.access_mask = r->in.access_mask;
3980 c.out.connect_handle = r->out.connect_handle;
3982 *r->out.level_out = 1;
3984 status = _samr_Connect2(p, &c);
3985 if (!NT_STATUS_IS_OK(status)) {
3989 r->out.info_out->info1 = info1;
3991 return NT_STATUS_OK;
3994 /**********************************************************************
3996 **********************************************************************/
3998 NTSTATUS _samr_LookupDomain(pipes_struct *p,
3999 struct samr_LookupDomain *r)
4001 NTSTATUS status = NT_STATUS_OK;
4002 struct samr_info *info;
4003 const char *domain_name;
4004 DOM_SID *sid = NULL;
4006 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
4007 return NT_STATUS_INVALID_HANDLE;
4009 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
4010 Reverted that change so we will work with RAS servers again */
4012 status = access_check_samr_function(info->acc_granted,
4013 SAMR_ACCESS_LOOKUP_DOMAIN,
4014 "_samr_LookupDomain");
4015 if (!NT_STATUS_IS_OK(status)) {
4019 domain_name = r->in.domain_name->string;
4021 return NT_STATUS_INVALID_PARAMETER;
4024 sid = TALLOC_ZERO_P(p->mem_ctx, struct dom_sid2);
4026 return NT_STATUS_NO_MEMORY;
4029 if (strequal(domain_name, builtin_domain_name())) {
4030 sid_copy(sid, &global_sid_Builtin);
4032 if (!secrets_fetch_domain_sid(domain_name, sid)) {
4033 status = NT_STATUS_NO_SUCH_DOMAIN;
4037 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
4038 sid_string_dbg(sid)));
4045 /**********************************************************************
4047 **********************************************************************/
4049 NTSTATUS _samr_EnumDomains(pipes_struct *p,
4050 struct samr_EnumDomains *r)
4053 struct samr_info *info;
4054 uint32_t num_entries = 2;
4055 struct samr_SamEntry *entry_array = NULL;
4056 struct samr_SamArray *sam;
4058 if (!find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info))
4059 return NT_STATUS_INVALID_HANDLE;
4061 status = access_check_samr_function(info->acc_granted,
4062 SAMR_ACCESS_ENUM_DOMAINS,
4063 "_samr_EnumDomains");
4064 if (!NT_STATUS_IS_OK(status)) {
4068 sam = TALLOC_ZERO_P(p->mem_ctx, struct samr_SamArray);
4070 return NT_STATUS_NO_MEMORY;
4073 entry_array = TALLOC_ZERO_ARRAY(p->mem_ctx,
4074 struct samr_SamEntry,
4077 return NT_STATUS_NO_MEMORY;
4080 entry_array[0].idx = 0;
4081 init_lsa_String(&entry_array[0].name, get_global_sam_name());
4083 entry_array[1].idx = 1;
4084 init_lsa_String(&entry_array[1].name, "Builtin");
4086 sam->count = num_entries;
4087 sam->entries = entry_array;
4090 *r->out.num_entries = num_entries;
4095 /*******************************************************************
4097 ********************************************************************/
4099 NTSTATUS _samr_OpenAlias(pipes_struct *p,
4100 struct samr_OpenAlias *r)
4103 uint32 alias_rid = r->in.rid;
4104 struct samr_info *info = NULL;
4105 SEC_DESC *psd = NULL;
4107 uint32 des_access = r->in.access_mask;
4112 /* find the domain policy and get the SID / access bits stored in the domain policy */
4114 if ( !get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL) )
4115 return NT_STATUS_INVALID_HANDLE;
4117 status = access_check_samr_function(acc_granted,
4118 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
4121 if ( !NT_STATUS_IS_OK(status) )
4124 /* append the alias' RID to it */
4126 if (!sid_append_rid(&sid, alias_rid))
4127 return NT_STATUS_NO_SUCH_ALIAS;
4129 /*check if access can be granted as requested by client. */
4131 map_max_allowed_access(p->server_info->ptok, &des_access);
4133 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
4134 se_map_generic(&des_access,&ali_generic_mapping);
4136 se_priv_copy( &se_rights, &se_add_users );
4138 status = access_check_samr_object(psd, p->server_info->ptok,
4139 &se_rights, SAMR_ALIAS_ACCESS_ADD_MEMBER,
4140 des_access, &acc_granted, "_samr_OpenAlias");
4142 if ( !NT_STATUS_IS_OK(status) )
4146 /* Check we actually have the requested alias */
4147 enum lsa_SidType type;
4152 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
4155 if (!result || (type != SID_NAME_ALIAS)) {
4156 return NT_STATUS_NO_SUCH_ALIAS;
4159 /* make sure there is a mapping */
4161 if ( !sid_to_gid( &sid, &gid ) ) {
4162 return NT_STATUS_NO_SUCH_ALIAS;
4167 /* associate the alias SID with the new handle. */
4168 if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
4169 return NT_STATUS_NO_MEMORY;
4171 info->acc_granted = acc_granted;
4173 /* get a (unique) handle. open a policy on it. */
4174 if (!create_policy_hnd(p, r->out.alias_handle, info))
4175 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4177 return NT_STATUS_OK;
4180 /*******************************************************************
4182 ********************************************************************/
4184 static NTSTATUS set_user_info_2(TALLOC_CTX *mem_ctx,
4185 struct samr_UserInfo2 *id2,
4189 DEBUG(5,("set_user_info_2: NULL id2\n"));
4190 return NT_STATUS_ACCESS_DENIED;
4193 copy_id2_to_sam_passwd(pwd, id2);
4195 return pdb_update_sam_account(pwd);
4198 /*******************************************************************
4200 ********************************************************************/
4202 static NTSTATUS set_user_info_4(TALLOC_CTX *mem_ctx,
4203 struct samr_UserInfo4 *id4,
4207 DEBUG(5,("set_user_info_2: NULL id4\n"));
4208 return NT_STATUS_ACCESS_DENIED;
4211 copy_id4_to_sam_passwd(pwd, id4);
4213 return pdb_update_sam_account(pwd);
4216 /*******************************************************************
4218 ********************************************************************/
4220 static NTSTATUS set_user_info_6(TALLOC_CTX *mem_ctx,
4221 struct samr_UserInfo6 *id6,
4225 DEBUG(5,("set_user_info_6: NULL id6\n"));
4226 return NT_STATUS_ACCESS_DENIED;
4229 copy_id6_to_sam_passwd(pwd, id6);
4231 return pdb_update_sam_account(pwd);
4234 /*******************************************************************
4236 ********************************************************************/
4238 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
4239 struct samr_UserInfo7 *id7,
4245 DEBUG(5, ("set_user_info_7: NULL id7\n"));
4246 return NT_STATUS_ACCESS_DENIED;
4249 if (!id7->account_name.string) {
4250 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
4251 return NT_STATUS_ACCESS_DENIED;
4254 /* check to see if the new username already exists. Note: we can't
4255 reliably lock all backends, so there is potentially the
4256 possibility that a user can be created in between this check and
4257 the rename. The rename should fail, but may not get the
4258 exact same failure status code. I think this is small enough
4259 of a window for this type of operation and the results are
4260 simply that the rename fails with a slightly different status
4261 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
4263 rc = can_create(mem_ctx, id7->account_name.string);
4265 /* when there is nothing to change, we're done here */
4266 if (NT_STATUS_EQUAL(rc, NT_STATUS_USER_EXISTS) &&
4267 strequal(id7->account_name.string, pdb_get_username(pwd))) {
4268 return NT_STATUS_OK;
4270 if (!NT_STATUS_IS_OK(rc)) {
4274 rc = pdb_rename_sam_account(pwd, id7->account_name.string);
4279 /*******************************************************************
4281 ********************************************************************/
4283 static NTSTATUS set_user_info_8(TALLOC_CTX *mem_ctx,
4284 struct samr_UserInfo8 *id8,
4288 DEBUG(5,("set_user_info_8: NULL id8\n"));
4289 return NT_STATUS_ACCESS_DENIED;
4292 copy_id8_to_sam_passwd(pwd, id8);
4294 return pdb_update_sam_account(pwd);
4297 /*******************************************************************
4299 ********************************************************************/
4301 static NTSTATUS set_user_info_10(TALLOC_CTX *mem_ctx,
4302 struct samr_UserInfo10 *id10,
4306 DEBUG(5,("set_user_info_8: NULL id10\n"));
4307 return NT_STATUS_ACCESS_DENIED;
4310 copy_id10_to_sam_passwd(pwd, id10);
4312 return pdb_update_sam_account(pwd);
4315 /*******************************************************************
4317 ********************************************************************/
4319 static NTSTATUS set_user_info_11(TALLOC_CTX *mem_ctx,
4320 struct samr_UserInfo11 *id11,
4324 DEBUG(5,("set_user_info_11: NULL id11\n"));
4325 return NT_STATUS_ACCESS_DENIED;
4328 copy_id11_to_sam_passwd(pwd, id11);
4330 return pdb_update_sam_account(pwd);
4333 /*******************************************************************
4335 ********************************************************************/
4337 static NTSTATUS set_user_info_12(TALLOC_CTX *mem_ctx,
4338 struct samr_UserInfo12 *id12,
4342 DEBUG(5,("set_user_info_12: NULL id12\n"));
4343 return NT_STATUS_ACCESS_DENIED;
4346 copy_id12_to_sam_passwd(pwd, id12);
4348 return pdb_update_sam_account(pwd);
4351 /*******************************************************************
4353 ********************************************************************/
4355 static NTSTATUS set_user_info_13(TALLOC_CTX *mem_ctx,
4356 struct samr_UserInfo13 *id13,
4360 DEBUG(5,("set_user_info_13: NULL id13\n"));
4361 return NT_STATUS_ACCESS_DENIED;
4364 copy_id13_to_sam_passwd(pwd, id13);
4366 return pdb_update_sam_account(pwd);
4369 /*******************************************************************
4371 ********************************************************************/
4373 static NTSTATUS set_user_info_14(TALLOC_CTX *mem_ctx,
4374 struct samr_UserInfo14 *id14,
4378 DEBUG(5,("set_user_info_14: NULL id14\n"));
4379 return NT_STATUS_ACCESS_DENIED;
4382 copy_id14_to_sam_passwd(pwd, id14);
4384 return pdb_update_sam_account(pwd);
4387 /*******************************************************************
4389 ********************************************************************/
4391 static NTSTATUS set_user_info_16(TALLOC_CTX *mem_ctx,
4392 struct samr_UserInfo16 *id16,
4396 DEBUG(5,("set_user_info_16: NULL id16\n"));
4397 return NT_STATUS_ACCESS_DENIED;
4400 copy_id16_to_sam_passwd(pwd, id16);
4402 return pdb_update_sam_account(pwd);
4405 /*******************************************************************
4407 ********************************************************************/
4409 static NTSTATUS set_user_info_17(TALLOC_CTX *mem_ctx,
4410 struct samr_UserInfo17 *id17,
4414 DEBUG(5,("set_user_info_17: NULL id17\n"));
4415 return NT_STATUS_ACCESS_DENIED;
4418 copy_id17_to_sam_passwd(pwd, id17);
4420 return pdb_update_sam_account(pwd);
4423 /*******************************************************************
4425 ********************************************************************/
4427 static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
4428 TALLOC_CTX *mem_ctx,
4429 DATA_BLOB *session_key,
4433 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
4434 return NT_STATUS_INVALID_PARAMETER;
4437 if (id18->nt_pwd_active || id18->lm_pwd_active) {
4438 if (!session_key->length) {
4439 return NT_STATUS_NO_USER_SESSION_KEY;
4443 if (id18->nt_pwd_active) {
4447 in = data_blob_const(id18->nt_pwd.hash, 16);
4448 out = data_blob_talloc_zero(mem_ctx, 16);
4450 sess_crypt_blob(&out, &in, session_key, false);
4452 if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
4453 return NT_STATUS_ACCESS_DENIED;
4456 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
4459 if (id18->lm_pwd_active) {
4463 in = data_blob_const(id18->lm_pwd.hash, 16);
4464 out = data_blob_talloc_zero(mem_ctx, 16);
4466 sess_crypt_blob(&out, &in, session_key, false);
4468 if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
4469 return NT_STATUS_ACCESS_DENIED;
4472 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
4475 copy_id18_to_sam_passwd(pwd, id18);
4477 return pdb_update_sam_account(pwd);
4480 /*******************************************************************
4482 ********************************************************************/
4484 static NTSTATUS set_user_info_20(TALLOC_CTX *mem_ctx,
4485 struct samr_UserInfo20 *id20,
4489 DEBUG(5,("set_user_info_20: NULL id20\n"));
4490 return NT_STATUS_ACCESS_DENIED;
4493 copy_id20_to_sam_passwd(pwd, id20);
4495 return pdb_update_sam_account(pwd);
4498 /*******************************************************************
4500 ********************************************************************/
4502 static NTSTATUS set_user_info_21(struct samr_UserInfo21 *id21,
4503 TALLOC_CTX *mem_ctx,
4504 DATA_BLOB *session_key,
4510 DEBUG(5, ("set_user_info_21: NULL id21\n"));
4511 return NT_STATUS_INVALID_PARAMETER;
4514 if (id21->fields_present == 0) {
4515 return NT_STATUS_INVALID_PARAMETER;
4518 if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
4519 return NT_STATUS_ACCESS_DENIED;
4522 if (id21->fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) {
4523 if (id21->nt_password_set) {
4526 if ((id21->nt_owf_password.length != 16) ||
4527 (id21->nt_owf_password.size != 16)) {
4528 return NT_STATUS_INVALID_PARAMETER;
4531 if (!session_key->length) {
4532 return NT_STATUS_NO_USER_SESSION_KEY;
4535 in = data_blob_const(id21->nt_owf_password.array, 16);
4536 out = data_blob_talloc_zero(mem_ctx, 16);
4538 sess_crypt_blob(&out, &in, session_key, false);
4540 pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED);
4541 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
4545 if (id21->fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT) {
4546 if (id21->lm_password_set) {
4549 if ((id21->lm_owf_password.length != 16) ||
4550 (id21->lm_owf_password.size != 16)) {
4551 return NT_STATUS_INVALID_PARAMETER;
4554 if (!session_key->length) {
4555 return NT_STATUS_NO_USER_SESSION_KEY;
4558 in = data_blob_const(id21->lm_owf_password.array, 16);
4559 out = data_blob_talloc_zero(mem_ctx, 16);
4561 sess_crypt_blob(&out, &in, session_key, false);
4563 pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED);
4564 pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
4568 /* we need to separately check for an account rename first */
4570 if (id21->account_name.string &&
4571 (!strequal(id21->account_name.string, pdb_get_username(pwd))))
4574 /* check to see if the new username already exists. Note: we can't
4575 reliably lock all backends, so there is potentially the
4576 possibility that a user can be created in between this check and
4577 the rename. The rename should fail, but may not get the
4578 exact same failure status code. I think this is small enough
4579 of a window for this type of operation and the results are
4580 simply that the rename fails with a slightly different status
4581 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
4583 status = can_create(mem_ctx, id21->account_name.string);
4584 if (!NT_STATUS_IS_OK(status)) {
4588 status = pdb_rename_sam_account(pwd, id21->account_name.string);
4590 if (!NT_STATUS_IS_OK(status)) {
4591 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
4592 nt_errstr(status)));
4596 /* set the new username so that later
4597 functions can work on the new account */
4598 pdb_set_username(pwd, id21->account_name.string, PDB_SET);
4601 copy_id21_to_sam_passwd("INFO_21", pwd, id21);
4604 * The funny part about the previous two calls is
4605 * that pwd still has the password hashes from the
4606 * passdb entry. These have not been updated from
4607 * id21. I don't know if they need to be set. --jerry
4610 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
4611 status = pdb_set_unix_primary_group(mem_ctx, pwd);
4612 if ( !NT_STATUS_IS_OK(status) ) {
4617 /* Don't worry about writing out the user account since the
4618 primary group SID is generated solely from the user's Unix
4621 /* write the change out */
4622 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
4626 return NT_STATUS_OK;
4629 /*******************************************************************
4631 ********************************************************************/
4633 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
4634 struct samr_UserInfo23 *id23,
4637 char *plaintext_buf = NULL;
4643 DEBUG(5, ("set_user_info_23: NULL id23\n"));
4644 return NT_STATUS_INVALID_PARAMETER;
4647 if (id23->info.fields_present == 0) {
4648 return NT_STATUS_INVALID_PARAMETER;
4651 if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
4652 return NT_STATUS_ACCESS_DENIED;
4655 if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
4656 (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
4658 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
4659 pdb_get_username(pwd)));
4661 if (!decode_pw_buffer(mem_ctx,
4662 id23->password.data,
4666 return NT_STATUS_WRONG_PASSWORD;
4669 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
4670 return NT_STATUS_ACCESS_DENIED;
4674 copy_id23_to_sam_passwd(pwd, id23);
4676 acct_ctrl = pdb_get_acct_ctrl(pwd);
4678 /* if it's a trust account, don't update /etc/passwd */
4679 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
4680 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
4681 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
4682 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
4683 } else if (plaintext_buf) {
4684 /* update the UNIX password */
4685 if (lp_unix_password_sync() ) {
4686 struct passwd *passwd;
4687 if (pdb_get_username(pwd) == NULL) {
4688 DEBUG(1, ("chgpasswd: User without name???\n"));
4689 return NT_STATUS_ACCESS_DENIED;
4692 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
4693 if (passwd == NULL) {
4694 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
4697 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
4698 return NT_STATUS_ACCESS_DENIED;
4700 TALLOC_FREE(passwd);
4704 if (plaintext_buf) {
4705 memset(plaintext_buf, '\0', strlen(plaintext_buf));
4708 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
4709 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
4714 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
4718 return NT_STATUS_OK;
4721 /*******************************************************************
4723 ********************************************************************/
4725 static bool set_user_info_pw(uint8 *pass, struct samu *pwd)
4728 char *plaintext_buf = NULL;
4731 DEBUG(5, ("Attempting administrator password change for user %s\n",
4732 pdb_get_username(pwd)));
4734 acct_ctrl = pdb_get_acct_ctrl(pwd);
4736 if (!decode_pw_buffer(talloc_tos(),
4744 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
4748 /* if it's a trust account, don't update /etc/passwd */
4749 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
4750 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
4751 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
4752 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
4754 /* update the UNIX password */
4755 if (lp_unix_password_sync()) {
4756 struct passwd *passwd;
4758 if (pdb_get_username(pwd) == NULL) {
4759 DEBUG(1, ("chgpasswd: User without name???\n"));
4763 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
4764 if (passwd == NULL) {
4765 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
4768 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
4771 TALLOC_FREE(passwd);
4775 memset(plaintext_buf, '\0', strlen(plaintext_buf));
4777 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
4782 /*******************************************************************
4784 ********************************************************************/
4786 static NTSTATUS set_user_info_24(TALLOC_CTX *mem_ctx,
4787 struct samr_UserInfo24 *id24,
4793 DEBUG(5, ("set_user_info_24: NULL id24\n"));
4794 return NT_STATUS_INVALID_PARAMETER;
4797 if (!set_user_info_pw(id24->password.data, pwd)) {
4798 return NT_STATUS_WRONG_PASSWORD;
4801 copy_id24_to_sam_passwd(pwd, id24);
4803 status = pdb_update_sam_account(pwd);
4804 if (!NT_STATUS_IS_OK(status)) {
4808 return NT_STATUS_OK;
4811 /*******************************************************************
4813 ********************************************************************/
4815 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
4816 struct samr_UserInfo25 *id25,
4822 DEBUG(5, ("set_user_info_25: NULL id25\n"));
4823 return NT_STATUS_INVALID_PARAMETER;
4826 if (id25->info.fields_present == 0) {
4827 return NT_STATUS_INVALID_PARAMETER;
4830 if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
4831 return NT_STATUS_ACCESS_DENIED;
4834 if ((id25->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
4835 (id25->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
4837 if (!set_user_info_pw(id25->password.data, pwd)) {
4838 return NT_STATUS_WRONG_PASSWORD;
4842 copy_id25_to_sam_passwd(pwd, id25);
4844 /* write the change out */
4845 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
4850 * We need to "pdb_update_sam_account" before the unix primary group
4851 * is set, because the idealx scripts would also change the
4852 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
4853 * the delete explicit / add explicit, which would then fail to find
4854 * the previous primaryGroupSid value.
4857 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
4858 status = pdb_set_unix_primary_group(mem_ctx, pwd);
4859 if ( !NT_STATUS_IS_OK(status) ) {
4864 return NT_STATUS_OK;
4867 /*******************************************************************
4869 ********************************************************************/
4871 static NTSTATUS set_user_info_26(TALLOC_CTX *mem_ctx,
4872 struct samr_UserInfo26 *id26,
4878 DEBUG(5, ("set_user_info_26: NULL id26\n"));
4879 return NT_STATUS_INVALID_PARAMETER;
4882 if (!set_user_info_pw(id26->password.data, pwd)) {
4883 return NT_STATUS_WRONG_PASSWORD;
4886 copy_id26_to_sam_passwd(pwd, id26);
4888 status = pdb_update_sam_account(pwd);
4889 if (!NT_STATUS_IS_OK(status)) {
4893 return NT_STATUS_OK;
4897 /*******************************************************************
4899 ********************************************************************/
4901 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
4902 struct samr_SetUserInfo *r)
4905 struct samu *pwd = NULL;
4907 union samr_UserInfo *info = r->in.info;
4908 uint16_t switch_value = r->in.level;
4909 uint32_t acc_granted;
4910 uint32_t acc_required;
4912 DISP_INFO *disp_info = NULL;
4914 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__));
4916 /* find the policy handle. open a policy on it. */
4917 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &sid, &acc_granted, &disp_info)) {
4918 return NT_STATUS_INVALID_HANDLE;
4921 /* This is tricky. A WinXP domain join sets
4922 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
4923 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4924 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
4925 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4926 we'll use the set from the WinXP join as the basis. */
4928 switch (switch_value) {
4930 acc_required = SAMR_USER_ACCESS_SET_ATTRIBUTES;
4936 acc_required = SAMR_USER_ACCESS_SET_PASSWORD;
4939 acc_required = SAMR_USER_ACCESS_SET_PASSWORD |
4940 SAMR_USER_ACCESS_SET_ATTRIBUTES |
4941 SAMR_USER_ACCESS_GET_ATTRIBUTES;
4945 status = access_check_samr_function(acc_granted,
4947 "_samr_SetUserInfo");
4948 if (!NT_STATUS_IS_OK(status)) {
4952 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4953 sid_string_dbg(&sid), switch_value));
4956 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4957 return NT_STATUS_INVALID_INFO_CLASS;
4960 if (!(pwd = samu_new(NULL))) {
4961 return NT_STATUS_NO_MEMORY;
4965 ret = pdb_getsampwsid(pwd, &sid);
4970 return NT_STATUS_NO_SUCH_USER;
4973 /* ================ BEGIN Privilege BLOCK ================ */
4977 /* ok! user info levels (lots: see MSDEV help), off we go... */
4979 switch (switch_value) {
4982 status = set_user_info_2(p->mem_ctx,
4987 status = set_user_info_4(p->mem_ctx,
4992 status = set_user_info_6(p->mem_ctx,
4997 status = set_user_info_7(p->mem_ctx,
5002 status = set_user_info_8(p->mem_ctx,
5007 status = set_user_info_10(p->mem_ctx,
5008 &info->info10, pwd);
5012 status = set_user_info_11(p->mem_ctx,
5013 &info->info11, pwd);
5017 status = set_user_info_12(p->mem_ctx,
5018 &info->info12, pwd);
5022 status = set_user_info_13(p->mem_ctx,
5023 &info->info13, pwd);
5027 status = set_user_info_14(p->mem_ctx,
5028 &info->info14, pwd);
5032 status = set_user_info_16(p->mem_ctx,
5033 &info->info16, pwd);
5037 status = set_user_info_17(p->mem_ctx,
5038 &info->info17, pwd);
5042 /* Used by AS/U JRA. */
5043 status = set_user_info_18(&info->info18,
5045 &p->server_info->user_session_key,
5050 status = set_user_info_20(p->mem_ctx,
5051 &info->info20, pwd);
5055 status = set_user_info_21(&info->info21,
5057 &p->server_info->user_session_key,
5062 if (!p->server_info->user_session_key.length) {
5063 status = NT_STATUS_NO_USER_SESSION_KEY;
5065 SamOEMhashBlob(info->info23.password.data, 516,
5066 &p->server_info->user_session_key);
5068 dump_data(100, info->info23.password.data, 516);
5070 status = set_user_info_23(p->mem_ctx,
5071 &info->info23, pwd);
5075 if (!p->server_info->user_session_key.length) {
5076 status = NT_STATUS_NO_USER_SESSION_KEY;
5078 SamOEMhashBlob(info->info24.password.data,
5080 &p->server_info->user_session_key);
5082 dump_data(100, info->info24.password.data, 516);
5084 status = set_user_info_24(p->mem_ctx,
5085 &info->info24, pwd);
5089 if (!p->server_info->user_session_key.length) {
5090 status = NT_STATUS_NO_USER_SESSION_KEY;
5092 encode_or_decode_arc4_passwd_buffer(
5093 info->info25.password.data,
5094 &p->server_info->user_session_key);
5096 dump_data(100, info->info25.password.data, 532);
5098 status = set_user_info_25(p->mem_ctx,
5099 &info->info25, pwd);
5103 if (!p->server_info->user_session_key.length) {
5104 status = NT_STATUS_NO_USER_SESSION_KEY;
5106 encode_or_decode_arc4_passwd_buffer(
5107 info->info26.password.data,
5108 &p->server_info->user_session_key);
5110 dump_data(100, info->info26.password.data, 516);
5112 status = set_user_info_26(p->mem_ctx,
5113 &info->info26, pwd);
5117 status = NT_STATUS_INVALID_INFO_CLASS;
5124 /* ================ END Privilege BLOCK ================ */
5126 if (NT_STATUS_IS_OK(status)) {
5127 force_flush_samr_cache(disp_info);
5133 /*******************************************************************
5135 ********************************************************************/
5137 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
5138 struct samr_SetUserInfo2 *r)
5140 struct samr_SetUserInfo q;
5142 q.in.user_handle = r->in.user_handle;
5143 q.in.level = r->in.level;
5144 q.in.info = r->in.info;
5146 return _samr_SetUserInfo(p, &q);
5149 /*********************************************************************
5150 _samr_GetAliasMembership
5151 *********************************************************************/
5153 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
5154 struct samr_GetAliasMembership *r)
5156 size_t num_alias_rids;
5158 struct samr_info *info = NULL;
5166 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__));
5168 /* find the policy handle. open a policy on it. */
5169 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
5170 return NT_STATUS_INVALID_HANDLE;
5172 ntstatus1 = access_check_samr_function(info->acc_granted,
5173 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS,
5174 "_samr_GetAliasMembership");
5175 ntstatus2 = access_check_samr_function(info->acc_granted,
5176 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
5177 "_samr_GetAliasMembership");
5179 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
5180 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
5181 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
5182 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
5186 if (!sid_check_is_domain(&info->sid) &&
5187 !sid_check_is_builtin(&info->sid))
5188 return NT_STATUS_OBJECT_TYPE_MISMATCH;
5190 if (r->in.sids->num_sids) {
5191 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, r->in.sids->num_sids);
5193 if (members == NULL)
5194 return NT_STATUS_NO_MEMORY;
5199 for (i=0; i<r->in.sids->num_sids; i++)
5200 sid_copy(&members[i], r->in.sids->sids[i].sid);
5206 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
5207 r->in.sids->num_sids,
5208 &alias_rids, &num_alias_rids);
5211 if (!NT_STATUS_IS_OK(ntstatus1)) {
5215 r->out.rids->count = num_alias_rids;
5216 r->out.rids->ids = alias_rids;
5218 return NT_STATUS_OK;
5221 /*********************************************************************
5222 _samr_GetMembersInAlias
5223 *********************************************************************/
5225 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
5226 struct samr_GetMembersInAlias *r)
5230 size_t num_sids = 0;
5231 struct lsa_SidPtr *sids = NULL;
5232 DOM_SID *pdb_sids = NULL;
5238 /* find the policy handle. open a policy on it. */
5239 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, NULL))
5240 return NT_STATUS_INVALID_HANDLE;
5242 status = access_check_samr_function(acc_granted,
5243 SAMR_ALIAS_ACCESS_GET_MEMBERS,
5244 "_samr_GetMembersInAlias");
5245 if (!NT_STATUS_IS_OK(status)) {
5249 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
5252 status = pdb_enum_aliasmem(&alias_sid, &pdb_sids, &num_sids);
5255 if (!NT_STATUS_IS_OK(status)) {
5260 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr, num_sids);
5262 TALLOC_FREE(pdb_sids);
5263 return NT_STATUS_NO_MEMORY;
5267 for (i = 0; i < num_sids; i++) {
5268 sids[i].sid = sid_dup_talloc(p->mem_ctx, &pdb_sids[i]);
5270 TALLOC_FREE(pdb_sids);
5271 return NT_STATUS_NO_MEMORY;
5275 r->out.sids->num_sids = num_sids;
5276 r->out.sids->sids = sids;
5278 TALLOC_FREE(pdb_sids);
5280 return NT_STATUS_OK;
5283 /*********************************************************************
5284 _samr_QueryGroupMember
5285 *********************************************************************/
5287 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
5288 struct samr_QueryGroupMember *r)
5291 size_t i, num_members;
5299 struct samr_RidTypeArray *rids = NULL;
5301 rids = TALLOC_ZERO_P(p->mem_ctx, struct samr_RidTypeArray);
5303 return NT_STATUS_NO_MEMORY;
5306 /* find the policy handle. open a policy on it. */
5307 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5308 return NT_STATUS_INVALID_HANDLE;
5310 status = access_check_samr_function(acc_granted,
5311 SAMR_GROUP_ACCESS_GET_MEMBERS,
5312 "_samr_QueryGroupMember");
5313 if (!NT_STATUS_IS_OK(status)) {
5317 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
5319 if (!sid_check_is_in_our_domain(&group_sid)) {
5320 DEBUG(3, ("sid %s is not in our domain\n",
5321 sid_string_dbg(&group_sid)));
5322 return NT_STATUS_NO_SUCH_GROUP;
5325 DEBUG(10, ("lookup on Domain SID\n"));
5328 status = pdb_enum_group_members(p->mem_ctx, &group_sid,
5329 &rid, &num_members);
5332 if (!NT_STATUS_IS_OK(status))
5336 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
5338 return NT_STATUS_NO_MEMORY;
5344 for (i=0; i<num_members; i++)
5345 attr[i] = SID_NAME_USER;
5347 rids->count = num_members;
5351 *r->out.rids = rids;
5353 return NT_STATUS_OK;
5356 /*********************************************************************
5357 _samr_AddAliasMember
5358 *********************************************************************/
5360 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
5361 struct samr_AddAliasMember *r)
5366 DISP_INFO *disp_info = NULL;
5368 /* Find the policy handle. Open a policy on it. */
5369 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
5370 return NT_STATUS_INVALID_HANDLE;
5372 status = access_check_samr_function(acc_granted,
5373 SAMR_ALIAS_ACCESS_ADD_MEMBER,
5374 "_samr_AddAliasMember");
5375 if (!NT_STATUS_IS_OK(status)) {
5379 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
5381 /******** BEGIN SeAddUsers BLOCK *********/
5384 status = pdb_add_aliasmem(&alias_sid, r->in.sid);
5387 /******** END SeAddUsers BLOCK *********/
5389 if (NT_STATUS_IS_OK(status)) {
5390 force_flush_samr_cache(disp_info);
5396 /*********************************************************************
5397 _samr_DeleteAliasMember
5398 *********************************************************************/
5400 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
5401 struct samr_DeleteAliasMember *r)
5406 DISP_INFO *disp_info = NULL;
5408 /* Find the policy handle. Open a policy on it. */
5409 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
5410 return NT_STATUS_INVALID_HANDLE;
5412 status = access_check_samr_function(acc_granted,
5413 SAMR_ALIAS_ACCESS_REMOVE_MEMBER,
5414 "_samr_DeleteAliasMember");
5415 if (!NT_STATUS_IS_OK(status)) {
5419 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
5420 sid_string_dbg(&alias_sid)));
5422 /******** BEGIN SeAddUsers BLOCK *********/
5425 status = pdb_del_aliasmem(&alias_sid, r->in.sid);
5428 /******** END SeAddUsers BLOCK *********/
5430 if (NT_STATUS_IS_OK(status)) {
5431 force_flush_samr_cache(disp_info);
5437 /*********************************************************************
5438 _samr_AddGroupMember
5439 *********************************************************************/
5441 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
5442 struct samr_AddGroupMember *r)
5448 DISP_INFO *disp_info = NULL;
5450 /* Find the policy handle. Open a policy on it. */
5451 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5452 return NT_STATUS_INVALID_HANDLE;
5454 status = access_check_samr_function(acc_granted,
5455 SAMR_GROUP_ACCESS_ADD_MEMBER,
5456 "_samr_AddGroupMember");
5457 if (!NT_STATUS_IS_OK(status)) {
5461 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
5463 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
5465 return NT_STATUS_INVALID_HANDLE;
5468 /******** BEGIN SeAddUsers BLOCK *********/
5471 status = pdb_add_groupmem(p->mem_ctx, group_rid, r->in.rid);
5474 /******** END SeAddUsers BLOCK *********/
5476 force_flush_samr_cache(disp_info);
5481 /*********************************************************************
5482 _samr_DeleteGroupMember
5483 *********************************************************************/
5485 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
5486 struct samr_DeleteGroupMember *r)
5493 DISP_INFO *disp_info = NULL;
5496 * delete the group member named r->in.rid
5497 * who is a member of the sid associated with the handle
5498 * the rid is a user's rid as the group is a domain group.
5501 /* Find the policy handle. Open a policy on it. */
5502 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5503 return NT_STATUS_INVALID_HANDLE;
5505 status = access_check_samr_function(acc_granted,
5506 SAMR_GROUP_ACCESS_REMOVE_MEMBER,
5507 "_samr_DeleteGroupMember");
5508 if (!NT_STATUS_IS_OK(status)) {
5512 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
5514 return NT_STATUS_INVALID_HANDLE;
5517 /******** BEGIN SeAddUsers BLOCK *********/
5520 status = pdb_del_groupmem(p->mem_ctx, group_rid, r->in.rid);
5523 /******** END SeAddUsers BLOCK *********/
5525 force_flush_samr_cache(disp_info);
5530 /*********************************************************************
5532 *********************************************************************/
5534 NTSTATUS _samr_DeleteUser(pipes_struct *p,
5535 struct samr_DeleteUser *r)
5539 struct samu *sam_pass=NULL;
5541 DISP_INFO *disp_info = NULL;
5544 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
5546 /* Find the policy handle. Open a policy on it. */
5547 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
5548 return NT_STATUS_INVALID_HANDLE;
5550 status = access_check_samr_function(acc_granted,
5551 STD_RIGHT_DELETE_ACCESS,
5552 "_samr_DeleteUser");
5553 if (!NT_STATUS_IS_OK(status)) {
5557 if (!sid_check_is_in_our_domain(&user_sid))
5558 return NT_STATUS_CANNOT_DELETE;
5560 /* check if the user exists before trying to delete */
5561 if ( !(sam_pass = samu_new( NULL )) ) {
5562 return NT_STATUS_NO_MEMORY;
5566 ret = pdb_getsampwsid(sam_pass, &user_sid);
5570 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
5571 sid_string_dbg(&user_sid)));
5572 TALLOC_FREE(sam_pass);
5573 return NT_STATUS_NO_SUCH_USER;
5576 /******** BEGIN SeAddUsers BLOCK *********/
5579 status = pdb_delete_user(p->mem_ctx, sam_pass);
5582 /******** END SeAddUsers BLOCK *********/
5584 if ( !NT_STATUS_IS_OK(status) ) {
5585 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
5586 "user %s: %s.\n", pdb_get_username(sam_pass),
5587 nt_errstr(status)));
5588 TALLOC_FREE(sam_pass);
5593 TALLOC_FREE(sam_pass);
5595 if (!close_policy_hnd(p, r->in.user_handle))
5596 return NT_STATUS_OBJECT_NAME_INVALID;
5598 ZERO_STRUCTP(r->out.user_handle);
5600 force_flush_samr_cache(disp_info);
5602 return NT_STATUS_OK;
5605 /*********************************************************************
5606 _samr_DeleteDomainGroup
5607 *********************************************************************/
5609 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
5610 struct samr_DeleteDomainGroup *r)
5616 DISP_INFO *disp_info = NULL;
5618 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
5620 /* Find the policy handle. Open a policy on it. */
5621 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5622 return NT_STATUS_INVALID_HANDLE;
5624 status = access_check_samr_function(acc_granted,
5625 STD_RIGHT_DELETE_ACCESS,
5626 "_samr_DeleteDomainGroup");
5627 if (!NT_STATUS_IS_OK(status)) {
5631 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
5633 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
5635 return NT_STATUS_NO_SUCH_GROUP;
5638 /******** BEGIN SeAddUsers BLOCK *********/
5641 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
5644 /******** END SeAddUsers BLOCK *********/
5646 if ( !NT_STATUS_IS_OK(status) ) {
5647 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
5648 "entry for group %s: %s\n",
5649 sid_string_dbg(&group_sid),
5650 nt_errstr(status)));
5654 if (!close_policy_hnd(p, r->in.group_handle))
5655 return NT_STATUS_OBJECT_NAME_INVALID;
5657 force_flush_samr_cache(disp_info);
5659 return NT_STATUS_OK;
5662 /*********************************************************************
5663 _samr_DeleteDomAlias
5664 *********************************************************************/
5666 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
5667 struct samr_DeleteDomAlias *r)
5672 DISP_INFO *disp_info = NULL;
5674 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
5676 /* Find the policy handle. Open a policy on it. */
5677 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
5678 return NT_STATUS_INVALID_HANDLE;
5680 /* copy the handle to the outgoing reply */
5682 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
5684 status = access_check_samr_function(acc_granted,
5685 STD_RIGHT_DELETE_ACCESS,
5686 "_samr_DeleteDomAlias");
5687 if (!NT_STATUS_IS_OK(status)) {
5691 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
5693 /* Don't let Windows delete builtin groups */
5695 if ( sid_check_is_in_builtin( &alias_sid ) ) {
5696 return NT_STATUS_SPECIAL_ACCOUNT;
5699 if (!sid_check_is_in_our_domain(&alias_sid))
5700 return NT_STATUS_NO_SUCH_ALIAS;
5702 DEBUG(10, ("lookup on Local SID\n"));
5704 /******** BEGIN SeAddUsers BLOCK *********/
5707 /* Have passdb delete the alias */
5708 status = pdb_delete_alias(&alias_sid);
5711 /******** END SeAddUsers BLOCK *********/
5713 if ( !NT_STATUS_IS_OK(status))
5716 if (!close_policy_hnd(p, r->in.alias_handle))
5717 return NT_STATUS_OBJECT_NAME_INVALID;
5719 force_flush_samr_cache(disp_info);
5721 return NT_STATUS_OK;
5724 /*********************************************************************
5725 _samr_CreateDomainGroup
5726 *********************************************************************/
5728 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
5729 struct samr_CreateDomainGroup *r)
5736 struct samr_info *info;
5738 DISP_INFO *disp_info = NULL;
5740 /* Find the policy handle. Open a policy on it. */
5741 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
5742 return NT_STATUS_INVALID_HANDLE;
5744 status = access_check_samr_function(acc_granted,
5745 SAMR_DOMAIN_ACCESS_CREATE_GROUP,
5746 "_samr_CreateDomainGroup");
5747 if (!NT_STATUS_IS_OK(status)) {
5751 if (!sid_equal(&dom_sid, get_global_sam_sid()))
5752 return NT_STATUS_ACCESS_DENIED;
5754 name = r->in.name->string;
5756 return NT_STATUS_NO_MEMORY;
5759 status = can_create(p->mem_ctx, name);
5760 if (!NT_STATUS_IS_OK(status)) {
5764 /******** BEGIN SeAddUsers BLOCK *********/
5767 /* check that we successfully create the UNIX group */
5768 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
5771 /******** END SeAddUsers BLOCK *********/
5773 /* check if we should bail out here */
5775 if ( !NT_STATUS_IS_OK(status) )
5778 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
5780 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5781 return NT_STATUS_NO_MEMORY;
5783 /* they created it; let the user do what he wants with it */
5785 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
5787 /* get a (unique) handle. open a policy on it. */
5788 if (!create_policy_hnd(p, r->out.group_handle, info))
5789 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5791 force_flush_samr_cache(disp_info);
5793 return NT_STATUS_OK;
5796 /*********************************************************************
5797 _samr_CreateDomAlias
5798 *********************************************************************/
5800 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
5801 struct samr_CreateDomAlias *r)
5805 const char *name = NULL;
5806 struct samr_info *info;
5810 DISP_INFO *disp_info = NULL;
5812 /* Find the policy handle. Open a policy on it. */
5813 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
5814 return NT_STATUS_INVALID_HANDLE;
5816 result = access_check_samr_function(acc_granted,
5817 SAMR_DOMAIN_ACCESS_CREATE_ALIAS,
5818 "_samr_CreateDomAlias");
5819 if (!NT_STATUS_IS_OK(result)) {
5823 if (!sid_equal(&dom_sid, get_global_sam_sid()))
5824 return NT_STATUS_ACCESS_DENIED;
5826 name = r->in.alias_name->string;
5828 result = can_create(p->mem_ctx, name);
5829 if (!NT_STATUS_IS_OK(result)) {
5833 /******** BEGIN SeAddUsers BLOCK *********/
5836 /* Have passdb create the alias */
5837 result = pdb_create_alias(name, r->out.rid);
5840 /******** END SeAddUsers BLOCK *********/
5842 if (!NT_STATUS_IS_OK(result)) {
5843 DEBUG(10, ("pdb_create_alias failed: %s\n",
5844 nt_errstr(result)));
5848 sid_copy(&info_sid, get_global_sam_sid());
5849 sid_append_rid(&info_sid, *r->out.rid);
5851 if (!sid_to_gid(&info_sid, &gid)) {
5852 DEBUG(10, ("Could not find alias just created\n"));
5853 return NT_STATUS_ACCESS_DENIED;
5856 /* check if the group has been successfully created */
5857 if ( getgrgid(gid) == NULL ) {
5858 DEBUG(10, ("getgrgid(%u) of just created alias failed\n",
5859 (unsigned int)gid));
5860 return NT_STATUS_ACCESS_DENIED;
5863 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
5864 return NT_STATUS_NO_MEMORY;
5866 /* they created it; let the user do what he wants with it */
5868 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
5870 /* get a (unique) handle. open a policy on it. */
5871 if (!create_policy_hnd(p, r->out.alias_handle, info))
5872 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5874 force_flush_samr_cache(disp_info);
5876 return NT_STATUS_OK;
5879 /*********************************************************************
5880 _samr_QueryGroupInfo
5881 *********************************************************************/
5883 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5884 struct samr_QueryGroupInfo *r)
5889 union samr_GroupInfo *info = NULL;
5892 uint32_t attributes = SE_GROUP_MANDATORY |
5893 SE_GROUP_ENABLED_BY_DEFAULT |
5895 const char *group_name = NULL;
5896 const char *group_description = NULL;
5898 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, NULL))
5899 return NT_STATUS_INVALID_HANDLE;
5901 status = access_check_samr_function(acc_granted,
5902 SAMR_GROUP_ACCESS_LOOKUP_INFO,
5903 "_samr_QueryGroupInfo");
5904 if (!NT_STATUS_IS_OK(status)) {
5909 ret = get_domain_group_from_sid(group_sid, &map);
5912 return NT_STATUS_INVALID_HANDLE;
5914 /* FIXME: map contains fstrings */
5915 group_name = talloc_strdup(r, map.nt_name);
5916 group_description = talloc_strdup(r, map.comment);
5918 info = TALLOC_ZERO_P(p->mem_ctx, union samr_GroupInfo);
5920 return NT_STATUS_NO_MEMORY;
5923 switch (r->in.level) {
5929 status = pdb_enum_group_members(
5930 p->mem_ctx, &group_sid, &members, &num_members);
5933 if (!NT_STATUS_IS_OK(status)) {
5937 info->all.name.string = group_name;
5938 info->all.attributes = attributes;
5939 info->all.num_members = num_members;
5940 info->all.description.string = group_description;
5944 info->name.string = group_name;
5947 info->attributes.attributes = attributes;
5950 info->description.string = group_description;
5960 status = pdb_enum_group_members(
5961 p->mem_ctx, &group_sid, &members, &num_members);
5964 if (!NT_STATUS_IS_OK(status)) {
5968 info->all2.name.string = group_name;
5969 info->all2.attributes = attributes;
5970 info->all2.num_members = 0; /* num_members - in w2k3 this is always 0 */
5971 info->all2.description.string = group_description;
5976 return NT_STATUS_INVALID_INFO_CLASS;
5979 *r->out.info = info;
5981 return NT_STATUS_OK;
5984 /*********************************************************************
5986 *********************************************************************/
5988 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5989 struct samr_SetGroupInfo *r)
5996 DISP_INFO *disp_info = NULL;
5998 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
5999 return NT_STATUS_INVALID_HANDLE;
6001 status = access_check_samr_function(acc_granted,
6002 SAMR_GROUP_ACCESS_SET_INFO,
6003 "_samr_SetGroupInfo");
6004 if (!NT_STATUS_IS_OK(status)) {
6009 ret = get_domain_group_from_sid(group_sid, &map);
6012 return NT_STATUS_NO_SUCH_GROUP;
6014 switch (r->in.level) {
6016 fstrcpy(map.comment, r->in.info->all.description.string);
6019 /* group rename is not supported yet */
6020 return NT_STATUS_NOT_SUPPORTED;
6022 fstrcpy(map.comment, r->in.info->description.string);
6025 return NT_STATUS_INVALID_INFO_CLASS;
6028 /******** BEGIN SeAddUsers BLOCK *********/
6031 status = pdb_update_group_mapping_entry(&map);
6034 /******** End SeAddUsers BLOCK *********/
6036 if (NT_STATUS_IS_OK(status)) {
6037 force_flush_samr_cache(disp_info);
6043 /*********************************************************************
6045 *********************************************************************/
6047 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
6048 struct samr_SetAliasInfo *r)
6051 struct acct_info info;
6054 DISP_INFO *disp_info = NULL;
6056 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &group_sid, &acc_granted, &disp_info))
6057 return NT_STATUS_INVALID_HANDLE;
6059 status = access_check_samr_function(acc_granted,
6060 SAMR_ALIAS_ACCESS_SET_INFO,
6061 "_samr_SetAliasInfo");
6062 if (!NT_STATUS_IS_OK(status)) {
6066 /* get the current group information */
6069 status = pdb_get_aliasinfo( &group_sid, &info );
6072 if ( !NT_STATUS_IS_OK(status))
6075 switch (r->in.level) {
6080 /* We currently do not support renaming groups in the
6081 the BUILTIN domain. Refer to util_builtin.c to understand
6082 why. The eventually needs to be fixed to be like Windows
6083 where you can rename builtin groups, just not delete them */
6085 if ( sid_check_is_in_builtin( &group_sid ) ) {
6086 return NT_STATUS_SPECIAL_ACCOUNT;
6089 /* There has to be a valid name (and it has to be different) */
6091 if ( !r->in.info->name.string )
6092 return NT_STATUS_INVALID_PARAMETER;
6094 /* If the name is the same just reply "ok". Yes this
6095 doesn't allow you to change the case of a group name. */
6097 if ( strequal( r->in.info->name.string, info.acct_name ) )
6098 return NT_STATUS_OK;
6100 fstrcpy( info.acct_name, r->in.info->name.string);
6102 /* make sure the name doesn't already exist as a user
6105 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
6106 status = can_create( p->mem_ctx, group_name );
6107 if ( !NT_STATUS_IS_OK( status ) )
6111 case ALIASINFODESCRIPTION:
6112 if (r->in.info->description.string) {
6113 fstrcpy(info.acct_desc,
6114 r->in.info->description.string);
6116 fstrcpy( info.acct_desc, "" );
6120 return NT_STATUS_INVALID_INFO_CLASS;
6123 /******** BEGIN SeAddUsers BLOCK *********/
6126 status = pdb_set_aliasinfo( &group_sid, &info );
6129 /******** End SeAddUsers BLOCK *********/
6131 if (NT_STATUS_IS_OK(status))
6132 force_flush_samr_cache(disp_info);
6137 /****************************************************************
6139 ****************************************************************/
6141 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
6142 struct samr_GetDomPwInfo *r)
6144 uint32_t min_password_length = 0;
6145 uint32_t password_properties = 0;
6147 /* Perform access check. Since this rpc does not require a
6148 policy handle it will not be caught by the access checks on
6149 SAMR_CONNECT or SAMR_CONNECT_ANON. */
6151 if (!pipe_access_check(p)) {
6152 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
6153 return NT_STATUS_ACCESS_DENIED;
6157 pdb_get_account_policy(AP_MIN_PASSWORD_LEN,
6158 &min_password_length);
6159 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS,
6160 &password_properties);
6163 if (lp_check_password_script() && *lp_check_password_script()) {
6164 password_properties |= DOMAIN_PASSWORD_COMPLEX;
6167 r->out.info->min_password_length = min_password_length;
6168 r->out.info->password_properties = password_properties;
6170 return NT_STATUS_OK;
6173 /*********************************************************************
6175 *********************************************************************/
6177 NTSTATUS _samr_OpenGroup(pipes_struct *p,
6178 struct samr_OpenGroup *r)
6184 struct samr_info *info;
6185 SEC_DESC *psd = NULL;
6187 uint32 des_access = r->in.access_mask;
6194 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
6195 return NT_STATUS_INVALID_HANDLE;
6197 status = access_check_samr_function(acc_granted,
6198 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
6201 if ( !NT_STATUS_IS_OK(status) )
6204 /*check if access can be granted as requested by client. */
6205 map_max_allowed_access(p->server_info->ptok, &des_access);
6207 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
6208 se_map_generic(&des_access,&grp_generic_mapping);
6210 se_priv_copy( &se_rights, &se_add_users );
6212 status = access_check_samr_object(psd, p->server_info->ptok,
6213 &se_rights, SAMR_GROUP_ACCESS_ADD_MEMBER,
6214 des_access, &acc_granted, "_samr_OpenGroup");
6216 if ( !NT_STATUS_IS_OK(status) )
6219 /* this should not be hard-coded like this */
6221 if (!sid_equal(&sid, get_global_sam_sid()))
6222 return NT_STATUS_ACCESS_DENIED;
6224 sid_copy(&info_sid, get_global_sam_sid());
6225 sid_append_rid(&info_sid, r->in.rid);
6226 sid_to_fstring(sid_string, &info_sid);
6228 if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
6229 return NT_STATUS_NO_MEMORY;
6231 info->acc_granted = acc_granted;
6233 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
6235 /* check if that group really exists */
6237 ret = get_domain_group_from_sid(info->sid, &map);
6240 return NT_STATUS_NO_SUCH_GROUP;
6242 /* get a (unique) handle. open a policy on it. */
6243 if (!create_policy_hnd(p, r->out.group_handle, info))
6244 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
6246 return NT_STATUS_OK;
6249 /*********************************************************************
6250 _samr_RemoveMemberFromForeignDomain
6251 *********************************************************************/
6253 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
6254 struct samr_RemoveMemberFromForeignDomain *r)
6256 DOM_SID delete_sid, domain_sid;
6259 DISP_INFO *disp_info = NULL;
6261 sid_copy( &delete_sid, r->in.sid );
6263 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
6264 sid_string_dbg(&delete_sid)));
6266 /* Find the policy handle. Open a policy on it. */
6268 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &domain_sid,
6269 &acc_granted, &disp_info))
6270 return NT_STATUS_INVALID_HANDLE;
6272 result = access_check_samr_function(acc_granted,
6273 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
6274 "_samr_RemoveMemberFromForeignDomain");
6276 if (!NT_STATUS_IS_OK(result))
6279 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
6280 sid_string_dbg(&domain_sid)));
6282 /* we can only delete a user from a group since we don't have
6283 nested groups anyways. So in the latter case, just say OK */
6285 /* TODO: The above comment nowadays is bogus. Since we have nested
6286 * groups now, and aliases members are never reported out of the unix
6287 * group membership, the "just say OK" makes this call a no-op. For
6288 * us. This needs fixing however. */
6290 /* I've only ever seen this in the wild when deleting a user from
6291 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
6292 * is the user about to be deleted. I very much suspect this is the
6293 * only application of this call. To verify this, let people report
6296 if (!sid_check_is_builtin(&domain_sid)) {
6297 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
6298 "global_sam_sid() = %s\n",
6299 sid_string_dbg(&domain_sid),
6300 sid_string_dbg(get_global_sam_sid())));
6301 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
6302 return NT_STATUS_OK;
6305 force_flush_samr_cache(disp_info);
6307 result = NT_STATUS_OK;
6312 /*******************************************************************
6313 _samr_QueryDomainInfo2
6314 ********************************************************************/
6316 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
6317 struct samr_QueryDomainInfo2 *r)
6319 struct samr_QueryDomainInfo q;
6321 q.in.domain_handle = r->in.domain_handle;
6322 q.in.level = r->in.level;
6324 q.out.info = r->out.info;
6326 return _samr_QueryDomainInfo(p, &q);
6329 /*******************************************************************
6331 ********************************************************************/
6333 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
6334 struct samr_SetDomainInfo *r)
6336 struct samr_info *info = NULL;
6337 time_t u_expire, u_min_age;
6339 time_t u_lock_duration, u_reset_time;
6341 uint32_t acc_required = 0;
6343 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
6345 /* find the policy handle. open a policy on it. */
6346 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info))
6347 return NT_STATUS_INVALID_HANDLE;
6349 switch (r->in.level) {
6350 case 1: /* DomainPasswordInformation */
6351 case 12: /* DomainLockoutInformation */
6352 /* DOMAIN_WRITE_PASSWORD_PARAMETERS */
6353 acc_required = SAMR_DOMAIN_ACCESS_SET_INFO_1;
6355 case 3: /* DomainLogoffInformation */
6356 case 4: /* DomainOemInformation */
6357 /* DOMAIN_WRITE_OTHER_PARAMETERS */
6358 acc_required = SAMR_DOMAIN_ACCESS_SET_INFO_2;
6360 case 6: /* DomainReplicationInformation */
6361 case 9: /* DomainStateInformation */
6362 case 7: /* DomainServerRoleInformation */
6363 /* DOMAIN_ADMINISTER_SERVER */
6364 acc_required = SAMR_DOMAIN_ACCESS_SET_INFO_3;
6367 return NT_STATUS_INVALID_INFO_CLASS;
6370 result = access_check_samr_function(info->acc_granted,
6372 "_samr_SetDomainInfo");
6374 if (!NT_STATUS_IS_OK(result))
6377 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r->in.level));
6379 switch (r->in.level) {
6381 u_expire=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.max_password_age);
6382 u_min_age=nt_time_to_unix_abs((NTTIME *)&r->in.info->info1.min_password_age);
6383 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)r->in.info->info1.min_password_length);
6384 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)r->in.info->info1.password_history_length);
6385 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)r->in.info->info1.password_properties);
6386 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
6387 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
6390 u_logout=nt_time_to_unix_abs((NTTIME *)&r->in.info->info3.force_logoff_time);
6391 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
6402 u_lock_duration=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_duration);
6403 if (u_lock_duration != -1)
6404 u_lock_duration /= 60;
6406 u_reset_time=nt_time_to_unix_abs((NTTIME *)&r->in.info->info12.lockout_window)/60;
6408 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
6409 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
6410 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)r->in.info->info12.lockout_threshold);
6413 return NT_STATUS_INVALID_INFO_CLASS;
6416 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__));
6418 return NT_STATUS_OK;
6421 /****************************************************************
6422 _samr_GetDisplayEnumerationIndex
6423 ****************************************************************/
6425 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
6426 struct samr_GetDisplayEnumerationIndex *r)
6428 struct samr_info *info = NULL;
6429 uint32_t max_entries = (uint32_t) -1;
6430 uint32_t enum_context = 0;
6432 uint32_t num_account = 0;
6433 struct samr_displayentry *entries = NULL;
6436 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__));
6438 /* find the policy handle. open a policy on it. */
6439 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
6440 return NT_STATUS_INVALID_HANDLE;
6443 status = access_check_samr_function(info->acc_granted,
6444 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
6445 "_samr_GetDisplayEnumerationIndex");
6446 if (!NT_STATUS_IS_OK(status)) {
6450 if ((r->in.level < 1) || (r->in.level > 3)) {
6451 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
6452 "Unknown info level (%u)\n",
6454 return NT_STATUS_INVALID_INFO_CLASS;
6459 /* The following done as ROOT. Don't return without unbecome_root(). */
6461 switch (r->in.level) {
6463 if (info->disp_info->users == NULL) {
6464 info->disp_info->users = pdb_search_users(
6465 info->disp_info, ACB_NORMAL);
6466 if (info->disp_info->users == NULL) {
6468 return NT_STATUS_ACCESS_DENIED;
6470 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6471 "starting user enumeration at index %u\n",
6472 (unsigned int)enum_context));
6474 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6475 "using cached user enumeration at index %u\n",
6476 (unsigned int)enum_context));
6478 num_account = pdb_search_entries(info->disp_info->users,
6479 enum_context, max_entries,
6483 if (info->disp_info->machines == NULL) {
6484 info->disp_info->machines = pdb_search_users(
6485 info->disp_info, ACB_WSTRUST|ACB_SVRTRUST);
6486 if (info->disp_info->machines == NULL) {
6488 return NT_STATUS_ACCESS_DENIED;
6490 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6491 "starting machine enumeration at index %u\n",
6492 (unsigned int)enum_context));
6494 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6495 "using cached machine enumeration at index %u\n",
6496 (unsigned int)enum_context));
6498 num_account = pdb_search_entries(info->disp_info->machines,
6499 enum_context, max_entries,
6503 if (info->disp_info->groups == NULL) {
6504 info->disp_info->groups = pdb_search_groups(
6506 if (info->disp_info->groups == NULL) {
6508 return NT_STATUS_ACCESS_DENIED;
6510 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6511 "starting group enumeration at index %u\n",
6512 (unsigned int)enum_context));
6514 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6515 "using cached group enumeration at index %u\n",
6516 (unsigned int)enum_context));
6518 num_account = pdb_search_entries(info->disp_info->groups,
6519 enum_context, max_entries,
6524 smb_panic("info class changed");
6530 /* Ensure we cache this enumeration. */
6531 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
6533 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
6534 r->in.name->string));
6536 for (i=0; i<num_account; i++) {
6537 if (strequal(entries[i].account_name, r->in.name->string)) {
6538 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6539 "found %s at idx %d\n",
6540 r->in.name->string, i));
6542 return NT_STATUS_OK;
6546 /* assuming account_name lives at the very end */
6547 *r->out.idx = num_account;
6549 return NT_STATUS_NO_MORE_ENTRIES;
6552 /****************************************************************
6553 _samr_GetDisplayEnumerationIndex2
6554 ****************************************************************/
6556 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
6557 struct samr_GetDisplayEnumerationIndex2 *r)
6559 struct samr_GetDisplayEnumerationIndex q;
6561 q.in.domain_handle = r->in.domain_handle;
6562 q.in.level = r->in.level;
6563 q.in.name = r->in.name;
6565 q.out.idx = r->out.idx;
6567 return _samr_GetDisplayEnumerationIndex(p, &q);
6570 /****************************************************************
6572 ****************************************************************/
6574 NTSTATUS _samr_RidToSid(pipes_struct *p,
6575 struct samr_RidToSid *r)
6577 struct samr_info *info = NULL;
6580 if (!find_policy_by_hnd(p, r->in.domain_handle, (void **)(void *)&info)) {
6581 return NT_STATUS_INVALID_HANDLE;
6584 if (!sid_compose(&sid, &info->sid, r->in.rid)) {
6585 return NT_STATUS_NO_MEMORY;
6588 *r->out.sid = sid_dup_talloc(p->mem_ctx, &sid);
6590 return NT_STATUS_NO_MEMORY;
6593 return NT_STATUS_OK;
6596 /****************************************************************
6597 ****************************************************************/
6599 NTSTATUS _samr_Shutdown(pipes_struct *p,
6600 struct samr_Shutdown *r)
6602 p->rng_fault_state = true;
6603 return NT_STATUS_NOT_IMPLEMENTED;
6606 /****************************************************************
6607 ****************************************************************/
6609 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
6610 struct samr_SetMemberAttributesOfGroup *r)
6612 p->rng_fault_state = true;
6613 return NT_STATUS_NOT_IMPLEMENTED;
6616 /****************************************************************
6617 ****************************************************************/
6619 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
6620 struct samr_TestPrivateFunctionsDomain *r)
6622 return NT_STATUS_NOT_IMPLEMENTED;
6625 /****************************************************************
6626 ****************************************************************/
6628 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
6629 struct samr_TestPrivateFunctionsUser *r)
6631 return NT_STATUS_NOT_IMPLEMENTED;
6634 /****************************************************************
6635 ****************************************************************/
6637 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
6638 struct samr_AddMultipleMembersToAlias *r)
6640 p->rng_fault_state = true;
6641 return NT_STATUS_NOT_IMPLEMENTED;
6644 /****************************************************************
6645 ****************************************************************/
6647 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
6648 struct samr_RemoveMultipleMembersFromAlias *r)
6650 p->rng_fault_state = true;
6651 return NT_STATUS_NOT_IMPLEMENTED;
6654 /****************************************************************
6655 ****************************************************************/
6657 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
6658 struct samr_SetBootKeyInformation *r)
6660 p->rng_fault_state = true;
6661 return NT_STATUS_NOT_IMPLEMENTED;
6664 /****************************************************************
6665 ****************************************************************/
6667 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
6668 struct samr_GetBootKeyInformation *r)
6670 p->rng_fault_state = true;
6671 return NT_STATUS_NOT_IMPLEMENTED;
6674 /****************************************************************
6675 ****************************************************************/
6677 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
6678 struct samr_SetDsrmPassword *r)
6680 p->rng_fault_state = true;
6681 return NT_STATUS_NOT_IMPLEMENTED;
6684 /****************************************************************
6685 ****************************************************************/
6687 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
6688 struct samr_ValidatePassword *r)
6690 p->rng_fault_state = true;
6691 return NT_STATUS_NOT_IMPLEMENTED;