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 SA_RIGHT_USER_CHANGE_PASSWORD | \
42 SA_RIGHT_USER_SET_LOC_COM )
43 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
44 ( READ_CONTROL_ACCESS | SA_RIGHT_USER_SET_LOC_COM )
46 #define DISP_INFO_CACHE_TIMEOUT 10
48 typedef struct disp_info
{
49 DOM_SID sid
; /* identify which domain this is. */
50 bool builtin_domain
; /* Quick flag to check if this is the builtin domain. */
51 struct pdb_search
*users
; /* querydispinfo 1 and 4 */
52 struct pdb_search
*machines
; /* querydispinfo 2 */
53 struct pdb_search
*groups
; /* querydispinfo 3 and 5, enumgroups */
54 struct pdb_search
*aliases
; /* enumaliases */
57 struct pdb_search
*enum_users
; /* enumusers with a mask */
59 struct timed_event
*cache_timeout_event
; /* cache idle timeout
63 /* We keep a static list of these by SID as modern clients close down
64 all resources between each request in a complete enumeration. */
67 /* for use by the \PIPE\samr policy */
69 bool builtin_domain
; /* Quick flag to check if this is the builtin domain. */
70 uint32 status
; /* some sort of flag. best to record it. comes from opnum 0x39 */
76 static const struct generic_mapping sam_generic_mapping
= {
77 GENERIC_RIGHTS_SAM_READ
,
78 GENERIC_RIGHTS_SAM_WRITE
,
79 GENERIC_RIGHTS_SAM_EXECUTE
,
80 GENERIC_RIGHTS_SAM_ALL_ACCESS
};
81 static const struct generic_mapping dom_generic_mapping
= {
82 GENERIC_RIGHTS_DOMAIN_READ
,
83 GENERIC_RIGHTS_DOMAIN_WRITE
,
84 GENERIC_RIGHTS_DOMAIN_EXECUTE
,
85 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS
};
86 static const struct generic_mapping usr_generic_mapping
= {
87 GENERIC_RIGHTS_USER_READ
,
88 GENERIC_RIGHTS_USER_WRITE
,
89 GENERIC_RIGHTS_USER_EXECUTE
,
90 GENERIC_RIGHTS_USER_ALL_ACCESS
};
91 static const struct generic_mapping usr_nopwchange_generic_mapping
= {
92 GENERIC_RIGHTS_USER_READ
,
93 GENERIC_RIGHTS_USER_WRITE
,
94 GENERIC_RIGHTS_USER_EXECUTE
& ~SA_RIGHT_USER_CHANGE_PASSWORD
,
95 GENERIC_RIGHTS_USER_ALL_ACCESS
};
96 static const struct generic_mapping grp_generic_mapping
= {
97 GENERIC_RIGHTS_GROUP_READ
,
98 GENERIC_RIGHTS_GROUP_WRITE
,
99 GENERIC_RIGHTS_GROUP_EXECUTE
,
100 GENERIC_RIGHTS_GROUP_ALL_ACCESS
};
101 static const struct generic_mapping ali_generic_mapping
= {
102 GENERIC_RIGHTS_ALIAS_READ
,
103 GENERIC_RIGHTS_ALIAS_WRITE
,
104 GENERIC_RIGHTS_ALIAS_EXECUTE
,
105 GENERIC_RIGHTS_ALIAS_ALL_ACCESS
};
107 /*******************************************************************
108 *******************************************************************/
110 static NTSTATUS
make_samr_object_sd( TALLOC_CTX
*ctx
, SEC_DESC
**psd
, size_t *sd_size
,
111 const struct generic_mapping
*map
,
112 DOM_SID
*sid
, uint32 sid_access
)
114 DOM_SID domadmin_sid
;
115 SEC_ACE ace
[5]; /* at most 5 entries */
121 /* basic access for Everyone */
123 init_sec_access(&mask
, map
->generic_execute
| map
->generic_read
);
124 init_sec_ace(&ace
[i
++], &global_sid_World
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
126 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
128 init_sec_access(&mask
, map
->generic_all
);
130 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
131 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Account_Operators
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
133 /* Add Full Access for Domain Admins if we are a DC */
136 sid_copy( &domadmin_sid
, get_global_sam_sid() );
137 sid_append_rid( &domadmin_sid
, DOMAIN_GROUP_RID_ADMINS
);
138 init_sec_ace(&ace
[i
++], &domadmin_sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
141 /* if we have a sid, give it some special access */
144 init_sec_access( &mask
, sid_access
);
145 init_sec_ace(&ace
[i
++], sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
148 /* create the security descriptor */
150 if ((psa
= make_sec_acl(ctx
, NT4_ACL_REVISION
, i
, ace
)) == NULL
)
151 return NT_STATUS_NO_MEMORY
;
153 if ((*psd
= make_sec_desc(ctx
, SECURITY_DESCRIPTOR_REVISION_1
,
154 SEC_DESC_SELF_RELATIVE
, NULL
, NULL
, NULL
,
155 psa
, sd_size
)) == NULL
)
156 return NT_STATUS_NO_MEMORY
;
161 /*******************************************************************
162 Checks if access to an object should be granted, and returns that
163 level of access for further checks.
164 ********************************************************************/
166 static NTSTATUS
access_check_samr_object( SEC_DESC
*psd
, NT_USER_TOKEN
*token
,
167 SE_PRIV
*rights
, uint32 rights_mask
,
168 uint32 des_access
, uint32
*acc_granted
,
171 NTSTATUS status
= NT_STATUS_ACCESS_DENIED
;
172 uint32 saved_mask
= 0;
174 /* check privileges; certain SAM access bits should be overridden
175 by privileges (mostly having to do with creating/modifying/deleting
178 if ( rights
&& user_has_any_privilege( token
, rights
) ) {
180 saved_mask
= (des_access
& rights_mask
);
181 des_access
&= ~saved_mask
;
183 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
188 /* check the security descriptor first */
190 if ( se_access_check(psd
, token
, des_access
, acc_granted
, &status
) )
193 /* give root a free pass */
195 if ( geteuid() == sec_initial_uid() ) {
197 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug
, des_access
));
198 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
200 *acc_granted
= des_access
;
202 status
= NT_STATUS_OK
;
208 /* add in any bits saved during the privilege check (only
209 matters is status is ok) */
211 *acc_granted
|= rights_mask
;
213 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
214 debug
, NT_STATUS_IS_OK(status
) ? "GRANTED" : "DENIED",
215 des_access
, *acc_granted
));
220 /*******************************************************************
221 Checks if access to a function can be granted
222 ********************************************************************/
224 static NTSTATUS
access_check_samr_function(uint32 acc_granted
, uint32 acc_required
, const char *debug
)
226 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
227 debug
, acc_granted
, acc_required
));
229 /* check the security descriptor first */
231 if ( (acc_granted
&acc_required
) == acc_required
)
234 /* give root a free pass */
236 if (geteuid() == sec_initial_uid()) {
238 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
239 debug
, acc_granted
, acc_required
));
240 DEBUGADD(4,("but overwritten by euid == 0\n"));
245 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
246 debug
, acc_granted
, acc_required
));
248 return NT_STATUS_ACCESS_DENIED
;
251 /*******************************************************************
252 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
253 ********************************************************************/
255 static void map_max_allowed_access(const NT_USER_TOKEN
*token
,
256 uint32_t *pacc_requested
)
258 if (!((*pacc_requested
) & MAXIMUM_ALLOWED_ACCESS
)) {
261 *pacc_requested
&= ~MAXIMUM_ALLOWED_ACCESS
;
263 /* At least try for generic read. */
264 *pacc_requested
= GENERIC_READ_ACCESS
;
266 /* root gets anything. */
267 if (geteuid() == sec_initial_uid()) {
268 *pacc_requested
|= GENERIC_ALL_ACCESS
;
272 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
274 if (is_sid_in_token(token
, &global_sid_Builtin_Administrators
) ||
275 is_sid_in_token(token
, &global_sid_Builtin_Account_Operators
)) {
276 *pacc_requested
|= GENERIC_ALL_ACCESS
;
280 /* Full access for DOMAIN\Domain Admins. */
282 DOM_SID domadmin_sid
;
283 sid_copy( &domadmin_sid
, get_global_sam_sid() );
284 sid_append_rid( &domadmin_sid
, DOMAIN_GROUP_RID_ADMINS
);
285 if (is_sid_in_token(token
, &domadmin_sid
)) {
286 *pacc_requested
|= GENERIC_ALL_ACCESS
;
290 /* TODO ! Check privileges. */
293 /*******************************************************************
294 Fetch or create a dispinfo struct.
295 ********************************************************************/
297 static DISP_INFO
*get_samr_dispinfo_by_sid(DOM_SID
*psid
)
300 * We do a static cache for DISP_INFO's here. Explanation can be found
301 * in Jeremy's checkin message to r11793:
303 * Fix the SAMR cache so it works across completely insane
304 * client behaviour (ie.:
305 * open pipe/open SAMR handle/enumerate 0 - 1024
306 * close SAMR handle, close pipe.
307 * open pipe/open SAMR handle/enumerate 1024 - 2048...
308 * close SAMR handle, close pipe.
309 * And on ad-nausium. Amazing.... probably object-oriented
310 * client side programming in action yet again.
311 * This change should *massively* improve performance when
312 * enumerating users from an LDAP database.
315 * "Our" and the builtin domain are the only ones where we ever
316 * enumerate stuff, so just cache 2 entries.
319 static struct disp_info builtin_dispinfo
;
320 static struct disp_info domain_dispinfo
;
322 /* There are two cases to consider here:
323 1) The SID is a domain SID and we look for an equality match, or
324 2) This is an account SID and so we return the DISP_INFO* for our
331 if (sid_check_is_builtin(psid
) || sid_check_is_in_builtin(psid
)) {
333 * Necessary only once, but it does not really hurt.
335 sid_copy(&builtin_dispinfo
.sid
, &global_sid_Builtin
);
337 return &builtin_dispinfo
;
340 if (sid_check_is_domain(psid
) || sid_check_is_in_our_domain(psid
)) {
342 * Necessary only once, but it does not really hurt.
344 sid_copy(&domain_dispinfo
.sid
, get_global_sam_sid());
346 return &domain_dispinfo
;
352 /*******************************************************************
353 Create a samr_info struct.
354 ********************************************************************/
356 static struct samr_info
*get_samr_info_by_sid(DOM_SID
*psid
)
358 struct samr_info
*info
;
363 sid_to_fstring(sid_str
, psid
);
365 fstrcpy(sid_str
,"(NULL)");
368 mem_ctx
= talloc_init("samr_info for domain sid %s", sid_str
);
370 if ((info
= TALLOC_ZERO_P(mem_ctx
, struct samr_info
)) == NULL
)
373 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str
));
375 sid_copy( &info
->sid
, psid
);
376 info
->builtin_domain
= sid_check_is_builtin(psid
);
378 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
379 info
->builtin_domain
= False
;
381 info
->mem_ctx
= mem_ctx
;
383 info
->disp_info
= get_samr_dispinfo_by_sid(psid
);
388 /*******************************************************************
389 Function to free the per SID data.
390 ********************************************************************/
392 static void free_samr_cache(DISP_INFO
*disp_info
)
394 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
395 sid_string_dbg(&disp_info
->sid
)));
397 /* We need to become root here because the paged search might have to
398 * tell the LDAP server we're not interested in the rest anymore. */
402 if (disp_info
->users
) {
403 DEBUG(10,("free_samr_cache: deleting users cache\n"));
404 pdb_search_destroy(disp_info
->users
);
405 disp_info
->users
= NULL
;
407 if (disp_info
->machines
) {
408 DEBUG(10,("free_samr_cache: deleting machines cache\n"));
409 pdb_search_destroy(disp_info
->machines
);
410 disp_info
->machines
= NULL
;
412 if (disp_info
->groups
) {
413 DEBUG(10,("free_samr_cache: deleting groups cache\n"));
414 pdb_search_destroy(disp_info
->groups
);
415 disp_info
->groups
= NULL
;
417 if (disp_info
->aliases
) {
418 DEBUG(10,("free_samr_cache: deleting aliases cache\n"));
419 pdb_search_destroy(disp_info
->aliases
);
420 disp_info
->aliases
= NULL
;
422 if (disp_info
->enum_users
) {
423 DEBUG(10,("free_samr_cache: deleting enum_users cache\n"));
424 pdb_search_destroy(disp_info
->enum_users
);
425 disp_info
->enum_users
= NULL
;
427 disp_info
->enum_acb_mask
= 0;
432 /*******************************************************************
433 Function to free the per handle data.
434 ********************************************************************/
436 static void free_samr_info(void *ptr
)
438 struct samr_info
*info
=(struct samr_info
*) ptr
;
440 /* Only free the dispinfo cache if no one bothered to set up
443 if (info
->disp_info
&& info
->disp_info
->cache_timeout_event
== NULL
) {
444 free_samr_cache(info
->disp_info
);
447 talloc_destroy(info
->mem_ctx
);
450 /*******************************************************************
451 Idle event handler. Throw away the disp info cache.
452 ********************************************************************/
454 static void disp_info_cache_idle_timeout_handler(struct event_context
*ev_ctx
,
455 struct timed_event
*te
,
456 const struct timeval
*now
,
459 DISP_INFO
*disp_info
= (DISP_INFO
*)private_data
;
461 TALLOC_FREE(disp_info
->cache_timeout_event
);
463 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
465 free_samr_cache(disp_info
);
468 /*******************************************************************
469 Setup cache removal idle event handler.
470 ********************************************************************/
472 static void set_disp_info_cache_timeout(DISP_INFO
*disp_info
, time_t secs_fromnow
)
474 /* Remove any pending timeout and update. */
476 TALLOC_FREE(disp_info
->cache_timeout_event
);
478 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
479 "SID %s for %u seconds\n", sid_string_dbg(&disp_info
->sid
),
480 (unsigned int)secs_fromnow
));
482 disp_info
->cache_timeout_event
= event_add_timed(
483 smbd_event_context(), NULL
,
484 timeval_current_ofs(secs_fromnow
, 0),
485 "disp_info_cache_idle_timeout_handler",
486 disp_info_cache_idle_timeout_handler
, (void *)disp_info
);
489 /*******************************************************************
490 Force flush any cache. We do this on any samr_set_xxx call.
491 We must also remove the timeout handler.
492 ********************************************************************/
494 static void force_flush_samr_cache(DISP_INFO
*disp_info
)
496 if ((disp_info
== NULL
) || (disp_info
->cache_timeout_event
== NULL
)) {
500 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
501 TALLOC_FREE(disp_info
->cache_timeout_event
);
502 free_samr_cache(disp_info
);
505 /*******************************************************************
506 Ensure password info is never given out. Paranioa... JRA.
507 ********************************************************************/
509 static void samr_clear_sam_passwd(struct samu
*sam_pass
)
515 /* These now zero out the old password */
517 pdb_set_lanman_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
518 pdb_set_nt_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
521 static uint32
count_sam_users(struct disp_info
*info
, uint32 acct_flags
)
523 struct samr_displayentry
*entry
;
525 if (info
->builtin_domain
) {
526 /* No users in builtin. */
530 if (info
->users
== NULL
) {
531 info
->users
= pdb_search_users(acct_flags
);
532 if (info
->users
== NULL
) {
536 /* Fetch the last possible entry, thus trigger an enumeration */
537 pdb_search_entries(info
->users
, 0xffffffff, 1, &entry
);
539 /* Ensure we cache this enumeration. */
540 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
542 return info
->users
->num_entries
;
545 static uint32
count_sam_groups(struct disp_info
*info
)
547 struct samr_displayentry
*entry
;
549 if (info
->builtin_domain
) {
550 /* No groups in builtin. */
554 if (info
->groups
== NULL
) {
555 info
->groups
= pdb_search_groups();
556 if (info
->groups
== NULL
) {
560 /* Fetch the last possible entry, thus trigger an enumeration */
561 pdb_search_entries(info
->groups
, 0xffffffff, 1, &entry
);
563 /* Ensure we cache this enumeration. */
564 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
566 return info
->groups
->num_entries
;
569 static uint32
count_sam_aliases(struct disp_info
*info
)
571 struct samr_displayentry
*entry
;
573 if (info
->aliases
== NULL
) {
574 info
->aliases
= pdb_search_aliases(&info
->sid
);
575 if (info
->aliases
== NULL
) {
579 /* Fetch the last possible entry, thus trigger an enumeration */
580 pdb_search_entries(info
->aliases
, 0xffffffff, 1, &entry
);
582 /* Ensure we cache this enumeration. */
583 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
585 return info
->aliases
->num_entries
;
588 /*******************************************************************
590 ********************************************************************/
592 NTSTATUS
_samr_Close(pipes_struct
*p
, struct samr_Close
*r
)
594 if (!close_policy_hnd(p
, r
->in
.handle
)) {
595 return NT_STATUS_INVALID_HANDLE
;
598 ZERO_STRUCTP(r
->out
.handle
);
603 /*******************************************************************
605 ********************************************************************/
607 NTSTATUS
_samr_OpenDomain(pipes_struct
*p
,
608 struct samr_OpenDomain
*r
)
610 struct samr_info
*info
;
611 SEC_DESC
*psd
= NULL
;
613 uint32 des_access
= r
->in
.access_mask
;
618 /* find the connection policy handle. */
620 if ( !find_policy_by_hnd(p
, r
->in
.connect_handle
, (void**)(void *)&info
) )
621 return NT_STATUS_INVALID_HANDLE
;
623 status
= access_check_samr_function(info
->acc_granted
,
624 SA_RIGHT_SAM_OPEN_DOMAIN
,
625 "_samr_OpenDomain" );
627 if ( !NT_STATUS_IS_OK(status
) )
630 /*check if access can be granted as requested by client. */
631 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
633 make_samr_object_sd( p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0 );
634 se_map_generic( &des_access
, &dom_generic_mapping
);
636 se_priv_copy( &se_rights
, &se_machine_account
);
637 se_priv_add( &se_rights
, &se_add_users
);
639 status
= access_check_samr_object( psd
, p
->pipe_user
.nt_user_token
,
640 &se_rights
, GENERIC_RIGHTS_DOMAIN_WRITE
, des_access
,
641 &acc_granted
, "_samr_OpenDomain" );
643 if ( !NT_STATUS_IS_OK(status
) )
646 if (!sid_check_is_domain(r
->in
.sid
) &&
647 !sid_check_is_builtin(r
->in
.sid
)) {
648 return NT_STATUS_NO_SUCH_DOMAIN
;
651 /* associate the domain SID with the (unique) handle. */
652 if ((info
= get_samr_info_by_sid(r
->in
.sid
))==NULL
)
653 return NT_STATUS_NO_MEMORY
;
654 info
->acc_granted
= acc_granted
;
656 /* get a (unique) handle. open a policy on it. */
657 if (!create_policy_hnd(p
, r
->out
.domain_handle
, free_samr_info
, (void *)info
))
658 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
660 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__
));
665 /*******************************************************************
667 ********************************************************************/
669 NTSTATUS
_samr_GetUserPwInfo(pipes_struct
*p
,
670 struct samr_GetUserPwInfo
*r
)
672 struct samr_info
*info
= NULL
;
673 enum lsa_SidType sid_type
;
674 uint32_t min_password_length
= 0;
675 uint32_t password_properties
= 0;
679 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__
));
681 /* find the policy handle. open a policy on it. */
682 if (!find_policy_by_hnd(p
, r
->in
.user_handle
, (void **)(void *)&info
)) {
683 return NT_STATUS_INVALID_HANDLE
;
686 status
= access_check_samr_function(info
->acc_granted
,
687 SAMR_USER_ACCESS_GET_ATTRIBUTES
,
688 "_samr_GetUserPwInfo" );
689 if (!NT_STATUS_IS_OK(status
)) {
693 if (!sid_check_is_in_our_domain(&info
->sid
)) {
694 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
698 ret
= lookup_sid(p
->mem_ctx
, &info
->sid
, NULL
, NULL
, &sid_type
);
701 return NT_STATUS_NO_SUCH_USER
;
707 pdb_get_account_policy(AP_MIN_PASSWORD_LEN
,
708 &min_password_length
);
709 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS
,
710 &password_properties
);
713 if (lp_check_password_script() && *lp_check_password_script()) {
714 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
722 r
->out
.info
->min_password_length
= min_password_length
;
723 r
->out
.info
->password_properties
= password_properties
;
725 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__
));
730 /*******************************************************************
731 ********************************************************************/
733 static bool get_lsa_policy_samr_sid( pipes_struct
*p
, POLICY_HND
*pol
,
734 DOM_SID
*sid
, uint32
*acc_granted
,
735 DISP_INFO
**ppdisp_info
)
737 struct samr_info
*info
= NULL
;
739 /* find the policy handle. open a policy on it. */
740 if (!find_policy_by_hnd(p
, pol
, (void **)(void *)&info
))
747 *acc_granted
= info
->acc_granted
;
749 *ppdisp_info
= info
->disp_info
;
755 /*******************************************************************
757 ********************************************************************/
759 NTSTATUS
_samr_SetSecurity(pipes_struct
*p
,
760 struct samr_SetSecurity
*r
)
763 uint32 acc_granted
, i
;
766 struct samu
*sampass
=NULL
;
769 if (!get_lsa_policy_samr_sid(p
, r
->in
.handle
, &pol_sid
, &acc_granted
, NULL
))
770 return NT_STATUS_INVALID_HANDLE
;
772 if (!(sampass
= samu_new( p
->mem_ctx
))) {
773 DEBUG(0,("No memory!\n"));
774 return NT_STATUS_NO_MEMORY
;
777 /* get the user record */
779 ret
= pdb_getsampwsid(sampass
, &pol_sid
);
783 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid
)));
784 TALLOC_FREE(sampass
);
785 return NT_STATUS_INVALID_HANDLE
;
788 dacl
= r
->in
.sdbuf
->sd
->dacl
;
789 for (i
=0; i
< dacl
->num_aces
; i
++) {
790 if (sid_equal(&pol_sid
, &dacl
->aces
[i
].trustee
)) {
791 ret
= pdb_set_pass_can_change(sampass
,
792 (dacl
->aces
[i
].access_mask
&
793 SA_RIGHT_USER_CHANGE_PASSWORD
) ?
800 TALLOC_FREE(sampass
);
801 return NT_STATUS_ACCESS_DENIED
;
804 status
= access_check_samr_function(acc_granted
,
805 SA_RIGHT_USER_SET_ATTRIBUTES
,
806 "_samr_SetSecurity");
807 if (NT_STATUS_IS_OK(status
)) {
809 status
= pdb_update_sam_account(sampass
);
813 TALLOC_FREE(sampass
);
818 /*******************************************************************
819 build correct perms based on policies and password times for _samr_query_sec_obj
820 *******************************************************************/
821 static bool check_change_pw_access(TALLOC_CTX
*mem_ctx
, DOM_SID
*user_sid
)
823 struct samu
*sampass
=NULL
;
826 if ( !(sampass
= samu_new( mem_ctx
)) ) {
827 DEBUG(0,("No memory!\n"));
832 ret
= pdb_getsampwsid(sampass
, user_sid
);
836 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
837 TALLOC_FREE(sampass
);
841 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass
) ));
843 if (pdb_get_pass_can_change(sampass
)) {
844 TALLOC_FREE(sampass
);
847 TALLOC_FREE(sampass
);
852 /*******************************************************************
854 ********************************************************************/
856 NTSTATUS
_samr_QuerySecurity(pipes_struct
*p
,
857 struct samr_QuerySecurity
*r
)
861 SEC_DESC
* psd
= NULL
;
866 if (!get_lsa_policy_samr_sid(p
, r
->in
.handle
, &pol_sid
, &acc_granted
, NULL
))
867 return NT_STATUS_INVALID_HANDLE
;
869 DEBUG(10,("_samr_QuerySecurity: querying security on SID: %s\n",
870 sid_string_dbg(&pol_sid
)));
872 status
= access_check_samr_function(acc_granted
,
873 STD_RIGHT_READ_CONTROL_ACCESS
,
874 "_samr_QuerySecurity");
875 if (!NT_STATUS_IS_OK(status
)) {
879 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
881 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
882 if (pol_sid
.sid_rev_num
== 0) {
883 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
884 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
885 } else if (sid_equal(&pol_sid
,get_global_sam_sid())) {
886 /* check if it is our domain SID */
887 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
888 "with SID: %s\n", sid_string_dbg(&pol_sid
)));
889 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0);
890 } else if (sid_equal(&pol_sid
,&global_sid_Builtin
)) {
891 /* check if it is the Builtin Domain */
892 /* TODO: Builtin probably needs a different SD with restricted write access*/
893 DEBUG(5,("_samr_QuerySecurity: querying security on Builtin "
894 "Domain with SID: %s\n", sid_string_dbg(&pol_sid
)));
895 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0);
896 } else if (sid_check_is_in_our_domain(&pol_sid
) ||
897 sid_check_is_in_builtin(&pol_sid
)) {
898 /* TODO: different SDs have to be generated for aliases groups and users.
899 Currently all three get a default user SD */
900 DEBUG(10,("_samr_QuerySecurity: querying security on Object "
901 "with SID: %s\n", sid_string_dbg(&pol_sid
)));
902 if (check_change_pw_access(p
->mem_ctx
, &pol_sid
)) {
903 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
,
904 &pol_sid
, SAMR_USR_RIGHTS_WRITE_PW
);
906 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_nopwchange_generic_mapping
,
907 &pol_sid
, SAMR_USR_RIGHTS_CANT_WRITE_PW
);
910 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
913 if ((*r
->out
.sdbuf
= make_sec_desc_buf(p
->mem_ctx
, sd_size
, psd
)) == NULL
)
914 return NT_STATUS_NO_MEMORY
;
919 /*******************************************************************
920 makes a SAM_ENTRY / UNISTR2* structure from a user list.
921 ********************************************************************/
923 static NTSTATUS
make_user_sam_entry_list(TALLOC_CTX
*ctx
,
924 struct samr_SamEntry
**sam_pp
,
925 uint32_t num_entries
,
927 struct samr_displayentry
*entries
)
930 struct samr_SamEntry
*sam
;
934 if (num_entries
== 0) {
938 sam
= TALLOC_ZERO_ARRAY(ctx
, struct samr_SamEntry
, num_entries
);
940 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
941 return NT_STATUS_NO_MEMORY
;
944 for (i
= 0; i
< num_entries
; i
++) {
947 * usrmgr expects a non-NULL terminated string with
948 * trust relationships
950 if (entries
[i
].acct_flags
& ACB_DOMTRUST
) {
951 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
954 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
958 init_lsa_String(&sam
[i
].name
, entries
[i
].account_name
);
959 sam
[i
].idx
= entries
[i
].rid
;
967 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
969 /*******************************************************************
970 _samr_EnumDomainUsers
971 ********************************************************************/
973 NTSTATUS
_samr_EnumDomainUsers(pipes_struct
*p
,
974 struct samr_EnumDomainUsers
*r
)
977 struct samr_info
*info
= NULL
;
979 uint32 enum_context
= *r
->in
.resume_handle
;
980 enum remote_arch_types ra_type
= get_remote_arch();
981 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
982 uint32 max_entries
= max_sam_entries
;
983 struct samr_displayentry
*entries
= NULL
;
984 struct samr_SamArray
*samr_array
= NULL
;
985 struct samr_SamEntry
*samr_entries
= NULL
;
987 /* find the policy handle. open a policy on it. */
988 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
))
989 return NT_STATUS_INVALID_HANDLE
;
991 status
= access_check_samr_function(info
->acc_granted
,
992 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
993 "_samr_EnumDomainUsers");
994 if (!NT_STATUS_IS_OK(status
)) {
998 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__
));
1000 if (info
->builtin_domain
) {
1001 /* No users in builtin. */
1002 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
1003 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
1007 samr_array
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
1009 return NT_STATUS_NO_MEMORY
;
1016 if ((info
->disp_info
->enum_users
!= NULL
) &&
1017 (info
->disp_info
->enum_acb_mask
!= r
->in
.acct_flags
)) {
1018 pdb_search_destroy(info
->disp_info
->enum_users
);
1019 info
->disp_info
->enum_users
= NULL
;
1022 if (info
->disp_info
->enum_users
== NULL
) {
1023 info
->disp_info
->enum_users
= pdb_search_users(r
->in
.acct_flags
);
1024 info
->disp_info
->enum_acb_mask
= r
->in
.acct_flags
;
1027 if (info
->disp_info
->enum_users
== NULL
) {
1028 /* END AS ROOT !!!! */
1030 return NT_STATUS_ACCESS_DENIED
;
1033 num_account
= pdb_search_entries(info
->disp_info
->enum_users
,
1034 enum_context
, max_entries
,
1037 /* END AS ROOT !!!! */
1041 if (num_account
== 0) {
1042 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
1043 "total entries\n"));
1044 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
1045 return NT_STATUS_OK
;
1048 status
= make_user_sam_entry_list(p
->mem_ctx
, &samr_entries
,
1049 num_account
, enum_context
,
1051 if (!NT_STATUS_IS_OK(status
)) {
1055 if (max_entries
<= num_account
) {
1056 status
= STATUS_MORE_ENTRIES
;
1058 status
= NT_STATUS_OK
;
1061 /* Ensure we cache this enumeration. */
1062 set_disp_info_cache_timeout(info
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1064 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__
));
1066 samr_array
->count
= num_account
;
1067 samr_array
->entries
= samr_entries
;
1069 *r
->out
.resume_handle
= *r
->in
.resume_handle
+ num_account
;
1070 *r
->out
.sam
= samr_array
;
1071 *r
->out
.num_entries
= num_account
;
1073 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__
));
1078 /*******************************************************************
1079 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1080 ********************************************************************/
1082 static void make_group_sam_entry_list(TALLOC_CTX
*ctx
,
1083 struct samr_SamEntry
**sam_pp
,
1084 uint32_t num_sam_entries
,
1085 struct samr_displayentry
*entries
)
1087 struct samr_SamEntry
*sam
;
1092 if (num_sam_entries
== 0) {
1096 sam
= TALLOC_ZERO_ARRAY(ctx
, struct samr_SamEntry
, num_sam_entries
);
1101 for (i
= 0; i
< num_sam_entries
; i
++) {
1103 * JRA. I think this should include the null. TNG does not.
1105 init_lsa_String(&sam
[i
].name
, entries
[i
].account_name
);
1106 sam
[i
].idx
= entries
[i
].rid
;
1112 /*******************************************************************
1113 _samr_EnumDomainGroups
1114 ********************************************************************/
1116 NTSTATUS
_samr_EnumDomainGroups(pipes_struct
*p
,
1117 struct samr_EnumDomainGroups
*r
)
1120 struct samr_info
*info
= NULL
;
1121 struct samr_displayentry
*groups
;
1123 struct samr_SamArray
*samr_array
= NULL
;
1124 struct samr_SamEntry
*samr_entries
= NULL
;
1126 /* find the policy handle. open a policy on it. */
1127 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
))
1128 return NT_STATUS_INVALID_HANDLE
;
1130 status
= access_check_samr_function(info
->acc_granted
,
1131 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
1132 "_samr_EnumDomainGroups");
1133 if (!NT_STATUS_IS_OK(status
)) {
1137 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__
));
1139 if (info
->builtin_domain
) {
1140 /* No groups in builtin. */
1141 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
1142 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1146 samr_array
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
1148 return NT_STATUS_NO_MEMORY
;
1151 /* the domain group array is being allocated in the function below */
1155 if (info
->disp_info
->groups
== NULL
) {
1156 info
->disp_info
->groups
= pdb_search_groups();
1158 if (info
->disp_info
->groups
== NULL
) {
1160 return NT_STATUS_ACCESS_DENIED
;
1164 num_groups
= pdb_search_entries(info
->disp_info
->groups
,
1165 *r
->in
.resume_handle
,
1166 MAX_SAM_ENTRIES
, &groups
);
1169 /* Ensure we cache this enumeration. */
1170 set_disp_info_cache_timeout(info
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1172 make_group_sam_entry_list(p
->mem_ctx
, &samr_entries
,
1173 num_groups
, groups
);
1175 samr_array
->count
= num_groups
;
1176 samr_array
->entries
= samr_entries
;
1178 *r
->out
.sam
= samr_array
;
1179 *r
->out
.num_entries
= num_groups
;
1180 /* this was missing, IMHO:
1181 *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 SA_RIGHT_DOMAIN_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(&info
->sid
);
1226 if (info
->disp_info
->aliases
== NULL
) {
1228 return NT_STATUS_ACCESS_DENIED
;
1232 num_aliases
= pdb_search_entries(info
->disp_info
->aliases
,
1233 *r
->in
.resume_handle
,
1234 MAX_SAM_ENTRIES
, &aliases
);
1237 /* Ensure we cache this enumeration. */
1238 set_disp_info_cache_timeout(info
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1240 make_group_sam_entry_list(p
->mem_ctx
, &samr_entries
,
1241 num_aliases
, aliases
);
1243 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__
));
1245 samr_array
->count
= num_aliases
;
1246 samr_array
->entries
= samr_entries
;
1248 *r
->out
.sam
= samr_array
;
1249 *r
->out
.num_entries
= num_aliases
;
1250 *r
->out
.resume_handle
= num_aliases
+ *r
->in
.resume_handle
;
1255 /*******************************************************************
1256 inits a samr_DispInfoGeneral structure.
1257 ********************************************************************/
1259 static NTSTATUS
init_samr_dispinfo_1(TALLOC_CTX
*ctx
,
1260 struct samr_DispInfoGeneral
*r
,
1261 uint32_t num_entries
,
1263 struct samr_displayentry
*entries
)
1267 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries
));
1269 if (num_entries
== 0) {
1270 return NT_STATUS_OK
;
1273 r
->count
= num_entries
;
1275 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryGeneral
, num_entries
);
1277 return NT_STATUS_NO_MEMORY
;
1280 for (i
= 0; i
< num_entries
; i
++) {
1282 init_lsa_String(&r
->entries
[i
].account_name
,
1283 entries
[i
].account_name
);
1285 init_lsa_String(&r
->entries
[i
].description
,
1286 entries
[i
].description
);
1288 init_lsa_String(&r
->entries
[i
].full_name
,
1289 entries
[i
].fullname
);
1291 r
->entries
[i
].rid
= entries
[i
].rid
;
1292 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1293 r
->entries
[i
].idx
= start_idx
+i
+1;
1296 return NT_STATUS_OK
;
1299 /*******************************************************************
1300 inits a samr_DispInfoFull structure.
1301 ********************************************************************/
1303 static NTSTATUS
init_samr_dispinfo_2(TALLOC_CTX
*ctx
,
1304 struct samr_DispInfoFull
*r
,
1305 uint32_t num_entries
,
1307 struct samr_displayentry
*entries
)
1311 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries
));
1313 if (num_entries
== 0) {
1314 return NT_STATUS_OK
;
1317 r
->count
= num_entries
;
1319 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryFull
, num_entries
);
1321 return NT_STATUS_NO_MEMORY
;
1324 for (i
= 0; i
< num_entries
; i
++) {
1326 init_lsa_String(&r
->entries
[i
].account_name
,
1327 entries
[i
].account_name
);
1329 init_lsa_String(&r
->entries
[i
].description
,
1330 entries
[i
].description
);
1332 r
->entries
[i
].rid
= entries
[i
].rid
;
1333 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1334 r
->entries
[i
].idx
= start_idx
+i
+1;
1337 return NT_STATUS_OK
;
1340 /*******************************************************************
1341 inits a samr_DispInfoFullGroups structure.
1342 ********************************************************************/
1344 static NTSTATUS
init_samr_dispinfo_3(TALLOC_CTX
*ctx
,
1345 struct samr_DispInfoFullGroups
*r
,
1346 uint32_t num_entries
,
1348 struct samr_displayentry
*entries
)
1352 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries
));
1354 if (num_entries
== 0) {
1355 return NT_STATUS_OK
;
1358 r
->count
= num_entries
;
1360 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryFullGroup
, num_entries
);
1362 return NT_STATUS_NO_MEMORY
;
1365 for (i
= 0; i
< num_entries
; i
++) {
1367 init_lsa_String(&r
->entries
[i
].account_name
,
1368 entries
[i
].account_name
);
1370 init_lsa_String(&r
->entries
[i
].description
,
1371 entries
[i
].description
);
1373 r
->entries
[i
].rid
= entries
[i
].rid
;
1374 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1375 r
->entries
[i
].idx
= start_idx
+i
+1;
1378 return NT_STATUS_OK
;
1381 /*******************************************************************
1382 inits a samr_DispInfoAscii structure.
1383 ********************************************************************/
1385 static NTSTATUS
init_samr_dispinfo_4(TALLOC_CTX
*ctx
,
1386 struct samr_DispInfoAscii
*r
,
1387 uint32_t num_entries
,
1389 struct samr_displayentry
*entries
)
1393 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries
));
1395 if (num_entries
== 0) {
1396 return NT_STATUS_OK
;
1399 r
->count
= num_entries
;
1401 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryAscii
, num_entries
);
1403 return NT_STATUS_NO_MEMORY
;
1406 for (i
= 0; i
< num_entries
; i
++) {
1408 init_lsa_AsciiStringLarge(&r
->entries
[i
].account_name
,
1409 entries
[i
].account_name
);
1411 r
->entries
[i
].idx
= start_idx
+i
+1;
1414 return NT_STATUS_OK
;
1417 /*******************************************************************
1418 inits a samr_DispInfoAscii structure.
1419 ********************************************************************/
1421 static NTSTATUS
init_samr_dispinfo_5(TALLOC_CTX
*ctx
,
1422 struct samr_DispInfoAscii
*r
,
1423 uint32_t num_entries
,
1425 struct samr_displayentry
*entries
)
1429 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries
));
1431 if (num_entries
== 0) {
1432 return NT_STATUS_OK
;
1435 r
->count
= num_entries
;
1437 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryAscii
, num_entries
);
1439 return NT_STATUS_NO_MEMORY
;
1442 for (i
= 0; i
< num_entries
; i
++) {
1444 init_lsa_AsciiStringLarge(&r
->entries
[i
].account_name
,
1445 entries
[i
].account_name
);
1447 r
->entries
[i
].idx
= start_idx
+i
+1;
1450 return NT_STATUS_OK
;
1453 /*******************************************************************
1454 _samr_QueryDisplayInfo
1455 ********************************************************************/
1457 NTSTATUS
_samr_QueryDisplayInfo(pipes_struct
*p
,
1458 struct samr_QueryDisplayInfo
*r
)
1461 struct samr_info
*info
= NULL
;
1462 uint32 struct_size
=0x20; /* W2K always reply that, client doesn't care */
1464 uint32 max_entries
= r
->in
.max_entries
;
1465 uint32 enum_context
= r
->in
.start_idx
;
1466 uint32 max_size
= r
->in
.buf_size
;
1468 union samr_DispInfo
*disp_info
= r
->out
.info
;
1470 uint32 temp_size
=0, total_data_size
=0;
1471 NTSTATUS disp_ret
= NT_STATUS_UNSUCCESSFUL
;
1472 uint32 num_account
= 0;
1473 enum remote_arch_types ra_type
= get_remote_arch();
1474 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
1475 struct samr_displayentry
*entries
= NULL
;
1477 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__
));
1479 /* find the policy handle. open a policy on it. */
1480 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
))
1481 return NT_STATUS_INVALID_HANDLE
;
1483 status
= access_check_samr_function(info
->acc_granted
,
1484 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
1485 "_samr_QueryDisplayInfo");
1486 if (!NT_STATUS_IS_OK(status
)) {
1491 * calculate how many entries we will return.
1493 * - the number of entries the client asked
1494 * - our limit on that
1495 * - the starting point (enumeration context)
1496 * - the buffer size the client will accept
1500 * We are a lot more like W2K. Instead of reading the SAM
1501 * each time to find the records we need to send back,
1502 * we read it once and link that copy to the sam handle.
1503 * For large user list (over the MAX_SAM_ENTRIES)
1504 * it's a definitive win.
1505 * second point to notice: between enumerations
1506 * our sam is now the same as it's a snapshoot.
1507 * third point: got rid of the static SAM_USER_21 struct
1508 * no more intermediate.
1509 * con: it uses much more memory, as a full copy is stored
1512 * If you want to change it, think twice and think
1513 * of the second point , that's really important.
1518 if ((r
->in
.level
< 1) || (r
->in
.level
> 5)) {
1519 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1520 (unsigned int)r
->in
.level
));
1521 return NT_STATUS_INVALID_INFO_CLASS
;
1524 /* first limit the number of entries we will return */
1525 if(max_entries
> max_sam_entries
) {
1526 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1527 "entries, limiting to %d\n", max_entries
,
1529 max_entries
= max_sam_entries
;
1532 /* calculate the size and limit on the number of entries we will
1535 temp_size
=max_entries
*struct_size
;
1537 if (temp_size
>max_size
) {
1538 max_entries
=MIN((max_size
/struct_size
),max_entries
);;
1539 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1540 "only %d entries\n", max_entries
));
1545 /* THe following done as ROOT. Don't return without unbecome_root(). */
1547 switch (r
->in
.level
) {
1550 if (info
->disp_info
->users
== NULL
) {
1551 info
->disp_info
->users
= pdb_search_users(ACB_NORMAL
);
1552 if (info
->disp_info
->users
== NULL
) {
1554 return NT_STATUS_ACCESS_DENIED
;
1556 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1557 (unsigned int)enum_context
));
1559 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1560 (unsigned int)enum_context
));
1563 num_account
= pdb_search_entries(info
->disp_info
->users
,
1564 enum_context
, max_entries
,
1568 if (info
->disp_info
->machines
== NULL
) {
1569 info
->disp_info
->machines
=
1570 pdb_search_users(ACB_WSTRUST
|ACB_SVRTRUST
);
1571 if (info
->disp_info
->machines
== NULL
) {
1573 return NT_STATUS_ACCESS_DENIED
;
1575 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1576 (unsigned int)enum_context
));
1578 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1579 (unsigned int)enum_context
));
1582 num_account
= pdb_search_entries(info
->disp_info
->machines
,
1583 enum_context
, max_entries
,
1588 if (info
->disp_info
->groups
== NULL
) {
1589 info
->disp_info
->groups
= pdb_search_groups();
1590 if (info
->disp_info
->groups
== NULL
) {
1592 return NT_STATUS_ACCESS_DENIED
;
1594 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1595 (unsigned int)enum_context
));
1597 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1598 (unsigned int)enum_context
));
1601 num_account
= pdb_search_entries(info
->disp_info
->groups
,
1602 enum_context
, max_entries
,
1607 smb_panic("info class changed");
1613 /* Now create reply structure */
1614 switch (r
->in
.level
) {
1616 disp_ret
= init_samr_dispinfo_1(p
->mem_ctx
, &disp_info
->info1
,
1617 num_account
, enum_context
,
1621 disp_ret
= init_samr_dispinfo_2(p
->mem_ctx
, &disp_info
->info2
,
1622 num_account
, enum_context
,
1626 disp_ret
= init_samr_dispinfo_3(p
->mem_ctx
, &disp_info
->info3
,
1627 num_account
, enum_context
,
1631 disp_ret
= init_samr_dispinfo_4(p
->mem_ctx
, &disp_info
->info4
,
1632 num_account
, enum_context
,
1636 disp_ret
= init_samr_dispinfo_5(p
->mem_ctx
, &disp_info
->info5
,
1637 num_account
, enum_context
,
1641 smb_panic("info class changed");
1645 if (!NT_STATUS_IS_OK(disp_ret
))
1648 /* calculate the total size */
1649 total_data_size
=num_account
*struct_size
;
1651 if (max_entries
<= num_account
) {
1652 status
= STATUS_MORE_ENTRIES
;
1654 status
= NT_STATUS_OK
;
1657 /* Ensure we cache this enumeration. */
1658 set_disp_info_cache_timeout(info
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1660 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__
));
1662 *r
->out
.total_size
= total_data_size
;
1663 *r
->out
.returned_size
= temp_size
;
1668 /****************************************************************
1669 _samr_QueryDisplayInfo2
1670 ****************************************************************/
1672 NTSTATUS
_samr_QueryDisplayInfo2(pipes_struct
*p
,
1673 struct samr_QueryDisplayInfo2
*r
)
1675 struct samr_QueryDisplayInfo q
;
1677 q
.in
.domain_handle
= r
->in
.domain_handle
;
1678 q
.in
.level
= r
->in
.level
;
1679 q
.in
.start_idx
= r
->in
.start_idx
;
1680 q
.in
.max_entries
= r
->in
.max_entries
;
1681 q
.in
.buf_size
= r
->in
.buf_size
;
1683 q
.out
.total_size
= r
->out
.total_size
;
1684 q
.out
.returned_size
= r
->out
.returned_size
;
1685 q
.out
.info
= r
->out
.info
;
1687 return _samr_QueryDisplayInfo(p
, &q
);
1690 /****************************************************************
1691 _samr_QueryDisplayInfo3
1692 ****************************************************************/
1694 NTSTATUS
_samr_QueryDisplayInfo3(pipes_struct
*p
,
1695 struct samr_QueryDisplayInfo3
*r
)
1697 struct samr_QueryDisplayInfo q
;
1699 q
.in
.domain_handle
= r
->in
.domain_handle
;
1700 q
.in
.level
= r
->in
.level
;
1701 q
.in
.start_idx
= r
->in
.start_idx
;
1702 q
.in
.max_entries
= r
->in
.max_entries
;
1703 q
.in
.buf_size
= r
->in
.buf_size
;
1705 q
.out
.total_size
= r
->out
.total_size
;
1706 q
.out
.returned_size
= r
->out
.returned_size
;
1707 q
.out
.info
= r
->out
.info
;
1709 return _samr_QueryDisplayInfo(p
, &q
);
1712 /*******************************************************************
1713 _samr_QueryAliasInfo
1714 ********************************************************************/
1716 NTSTATUS
_samr_QueryAliasInfo(pipes_struct
*p
,
1717 struct samr_QueryAliasInfo
*r
)
1720 struct acct_info info
;
1723 union samr_AliasInfo
*alias_info
= NULL
;
1724 const char *alias_name
= NULL
;
1725 const char *alias_description
= NULL
;
1727 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__
));
1729 alias_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_AliasInfo
);
1731 return NT_STATUS_NO_MEMORY
;
1734 /* find the policy handle. open a policy on it. */
1735 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &sid
, &acc_granted
, NULL
))
1736 return NT_STATUS_INVALID_HANDLE
;
1738 status
= access_check_samr_function(acc_granted
,
1739 SA_RIGHT_ALIAS_LOOKUP_INFO
,
1740 "_samr_QueryAliasInfo");
1741 if (!NT_STATUS_IS_OK(status
)) {
1746 status
= pdb_get_aliasinfo(&sid
, &info
);
1749 if ( !NT_STATUS_IS_OK(status
))
1752 /* FIXME: info contains fstrings */
1753 alias_name
= talloc_strdup(r
, info
.acct_name
);
1754 alias_description
= talloc_strdup(r
, info
.acct_desc
);
1756 switch (r
->in
.level
) {
1758 init_samr_alias_info1(&alias_info
->all
,
1763 case ALIASINFODESCRIPTION
:
1764 init_samr_alias_info3(&alias_info
->description
,
1768 return NT_STATUS_INVALID_INFO_CLASS
;
1771 *r
->out
.info
= alias_info
;
1773 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__
));
1775 return NT_STATUS_OK
;
1779 /*******************************************************************
1780 samr_reply_lookup_ids
1781 ********************************************************************/
1783 uint32
_samr_lookup_ids(pipes_struct
*p
, SAMR_Q_LOOKUP_IDS
*q_u
, SAMR_R_LOOKUP_IDS
*r_u
)
1785 uint32 rid
[MAX_SAM_ENTRIES
];
1786 int num_rids
= q_u
->num_sids1
;
1788 r_u
->status
= NT_STATUS_OK
;
1790 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__
));
1792 if (num_rids
> MAX_SAM_ENTRIES
) {
1793 num_rids
= MAX_SAM_ENTRIES
;
1794 DEBUG(5,("_samr_lookup_ids: truncating entries to %d\n", num_rids
));
1799 SMB_ASSERT_ARRAY(q_u
->uni_user_name
, num_rids
);
1801 for (i
= 0; i
< num_rids
&& status
== 0; i
++)
1803 struct sam_passwd
*sam_pass
;
1807 fstrcpy(user_name
, unistrn2(q_u
->uni_user_name
[i
].buffer
,
1808 q_u
->uni_user_name
[i
].uni_str_len
));
1810 /* find the user account */
1812 sam_pass
= get_smb21pwd_entry(user_name
, 0);
1815 if (sam_pass
== NULL
)
1817 status
= 0xC0000000 | NT_STATUS_NO_SUCH_USER
;
1822 rid
[i
] = sam_pass
->user_rid
;
1828 rid
[0] = BUILTIN_ALIAS_RID_USERS
;
1830 init_samr_r_lookup_ids(&r_u
, num_rids
, rid
, NT_STATUS_OK
);
1832 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__
));
1838 /*******************************************************************
1840 ********************************************************************/
1842 NTSTATUS
_samr_LookupNames(pipes_struct
*p
,
1843 struct samr_LookupNames
*r
)
1847 enum lsa_SidType
*type
;
1849 int num_rids
= r
->in
.num_names
;
1852 struct samr_Ids rids
, types
;
1853 uint32_t num_mapped
= 0;
1855 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__
));
1857 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &pol_sid
, &acc_granted
, NULL
)) {
1858 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
1861 status
= access_check_samr_function(acc_granted
,
1862 0, /* Don't know the acc_bits yet */
1863 "_samr_LookupNames");
1864 if (!NT_STATUS_IS_OK(status
)) {
1868 if (num_rids
> MAX_SAM_ENTRIES
) {
1869 num_rids
= MAX_SAM_ENTRIES
;
1870 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids
));
1873 rid
= talloc_array(p
->mem_ctx
, uint32
, num_rids
);
1874 NT_STATUS_HAVE_NO_MEMORY(rid
);
1876 type
= talloc_array(p
->mem_ctx
, enum lsa_SidType
, num_rids
);
1877 NT_STATUS_HAVE_NO_MEMORY(type
);
1879 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1880 sid_string_dbg(&pol_sid
)));
1882 for (i
= 0; i
< num_rids
; i
++) {
1884 status
= NT_STATUS_NONE_MAPPED
;
1885 type
[i
] = SID_NAME_UNKNOWN
;
1887 rid
[i
] = 0xffffffff;
1889 if (sid_check_is_builtin(&pol_sid
)) {
1890 if (lookup_builtin_name(r
->in
.names
[i
].string
,
1893 type
[i
] = SID_NAME_ALIAS
;
1896 lookup_global_sam_name(r
->in
.names
[i
].string
, 0,
1900 if (type
[i
] != SID_NAME_UNKNOWN
) {
1905 if (num_mapped
== num_rids
) {
1906 status
= NT_STATUS_OK
;
1907 } else if (num_mapped
== 0) {
1908 status
= NT_STATUS_NONE_MAPPED
;
1910 status
= STATUS_SOME_UNMAPPED
;
1913 rids
.count
= num_rids
;
1916 types
.count
= num_rids
;
1919 *r
->out
.rids
= rids
;
1920 *r
->out
.types
= types
;
1922 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__
));
1927 /*******************************************************************
1928 _samr_ChangePasswordUser2
1929 ********************************************************************/
1931 NTSTATUS
_samr_ChangePasswordUser2(pipes_struct
*p
,
1932 struct samr_ChangePasswordUser2
*r
)
1938 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__
));
1940 fstrcpy(user_name
, r
->in
.account
->string
);
1941 fstrcpy(wks
, r
->in
.server
->string
);
1943 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name
, wks
));
1946 * Pass the user through the NT -> unix user mapping
1950 (void)map_username(user_name
);
1953 * UNIX username case mangling not required, pass_oem_change
1954 * is case insensitive.
1957 status
= pass_oem_change(user_name
,
1958 r
->in
.lm_password
->data
,
1959 r
->in
.lm_verifier
->hash
,
1960 r
->in
.nt_password
->data
,
1961 r
->in
.nt_verifier
->hash
,
1964 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__
));
1969 /*******************************************************************
1970 _samr_ChangePasswordUser3
1971 ********************************************************************/
1973 NTSTATUS
_samr_ChangePasswordUser3(pipes_struct
*p
,
1974 struct samr_ChangePasswordUser3
*r
)
1978 const char *wks
= NULL
;
1979 uint32 reject_reason
;
1980 struct samr_DomInfo1
*dominfo
= NULL
;
1981 struct samr_ChangeReject
*reject
= NULL
;
1983 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__
));
1985 fstrcpy(user_name
, r
->in
.account
->string
);
1986 if (r
->in
.server
&& r
->in
.server
->string
) {
1987 wks
= r
->in
.server
->string
;
1990 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name
, wks
));
1993 * Pass the user through the NT -> unix user mapping
1997 (void)map_username(user_name
);
2000 * UNIX username case mangling not required, pass_oem_change
2001 * is case insensitive.
2004 status
= pass_oem_change(user_name
,
2005 r
->in
.lm_password
->data
,
2006 r
->in
.lm_verifier
->hash
,
2007 r
->in
.nt_password
->data
,
2008 r
->in
.nt_verifier
->hash
,
2011 if (NT_STATUS_EQUAL(status
, NT_STATUS_PASSWORD_RESTRICTION
) ||
2012 NT_STATUS_EQUAL(status
, NT_STATUS_ACCOUNT_RESTRICTION
)) {
2014 uint32 min_pass_len
,pass_hist
,password_properties
;
2015 time_t u_expire
, u_min_age
;
2016 NTTIME nt_expire
, nt_min_age
;
2017 uint32 account_policy_temp
;
2019 dominfo
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_DomInfo1
);
2021 return NT_STATUS_NO_MEMORY
;
2024 reject
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_ChangeReject
);
2026 return NT_STATUS_NO_MEMORY
;
2033 pdb_get_account_policy(AP_MIN_PASSWORD_LEN
, &account_policy_temp
);
2034 min_pass_len
= account_policy_temp
;
2036 pdb_get_account_policy(AP_PASSWORD_HISTORY
, &account_policy_temp
);
2037 pass_hist
= account_policy_temp
;
2039 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS
, &account_policy_temp
);
2040 password_properties
= account_policy_temp
;
2042 pdb_get_account_policy(AP_MAX_PASSWORD_AGE
, &account_policy_temp
);
2043 u_expire
= account_policy_temp
;
2045 pdb_get_account_policy(AP_MIN_PASSWORD_AGE
, &account_policy_temp
);
2046 u_min_age
= account_policy_temp
;
2052 unix_to_nt_time_abs(&nt_expire
, u_expire
);
2053 unix_to_nt_time_abs(&nt_min_age
, u_min_age
);
2055 if (lp_check_password_script() && *lp_check_password_script()) {
2056 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
2059 init_samr_DomInfo1(dominfo
,
2062 password_properties
,
2066 reject
->reason
= reject_reason
;
2068 *r
->out
.dominfo
= dominfo
;
2069 *r
->out
.reject
= reject
;
2072 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__
));
2077 /*******************************************************************
2078 makes a SAMR_R_LOOKUP_RIDS structure.
2079 ********************************************************************/
2081 static bool make_samr_lookup_rids(TALLOC_CTX
*ctx
, uint32 num_names
,
2083 struct lsa_String
**lsa_name_array_p
)
2085 struct lsa_String
*lsa_name_array
= NULL
;
2088 *lsa_name_array_p
= NULL
;
2090 if (num_names
!= 0) {
2091 lsa_name_array
= TALLOC_ZERO_ARRAY(ctx
, struct lsa_String
, num_names
);
2092 if (!lsa_name_array
) {
2097 for (i
= 0; i
< num_names
; i
++) {
2098 DEBUG(10, ("names[%d]:%s\n", i
, names
[i
] && *names
[i
] ? names
[i
] : ""));
2099 init_lsa_String(&lsa_name_array
[i
], names
[i
]);
2102 *lsa_name_array_p
= lsa_name_array
;
2107 /*******************************************************************
2109 ********************************************************************/
2111 NTSTATUS
_samr_LookupRids(pipes_struct
*p
,
2112 struct samr_LookupRids
*r
)
2116 enum lsa_SidType
*attrs
= NULL
;
2117 uint32
*wire_attrs
= NULL
;
2119 int num_rids
= (int)r
->in
.num_rids
;
2122 struct lsa_Strings names_array
;
2123 struct samr_Ids types_array
;
2124 struct lsa_String
*lsa_names
= NULL
;
2126 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__
));
2128 /* find the policy handle. open a policy on it. */
2129 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &pol_sid
, &acc_granted
, NULL
))
2130 return NT_STATUS_INVALID_HANDLE
;
2132 status
= access_check_samr_function(acc_granted
,
2133 0, /* Don't know the acc_bits yet */
2134 "_samr__LookupRids");
2135 if (!NT_STATUS_IS_OK(status
)) {
2139 if (num_rids
> 1000) {
2140 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2141 "to samba4 idl this is not possible\n", num_rids
));
2142 return NT_STATUS_UNSUCCESSFUL
;
2146 names
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, const char *, num_rids
);
2147 attrs
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, enum lsa_SidType
, num_rids
);
2148 wire_attrs
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_rids
);
2150 if ((names
== NULL
) || (attrs
== NULL
) || (wire_attrs
==NULL
))
2151 return NT_STATUS_NO_MEMORY
;
2158 become_root(); /* lookup_sid can require root privs */
2159 status
= pdb_lookup_rids(&pol_sid
, num_rids
, r
->in
.rids
,
2163 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
) && (num_rids
== 0)) {
2164 status
= NT_STATUS_OK
;
2167 if (!make_samr_lookup_rids(p
->mem_ctx
, num_rids
, names
,
2169 return NT_STATUS_NO_MEMORY
;
2172 /* Convert from enum lsa_SidType to uint32 for wire format. */
2173 for (i
= 0; i
< num_rids
; i
++) {
2174 wire_attrs
[i
] = (uint32
)attrs
[i
];
2177 names_array
.count
= num_rids
;
2178 names_array
.names
= lsa_names
;
2180 types_array
.count
= num_rids
;
2181 types_array
.ids
= wire_attrs
;
2183 *r
->out
.names
= names_array
;
2184 *r
->out
.types
= types_array
;
2186 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__
));
2191 /*******************************************************************
2193 ********************************************************************/
2195 NTSTATUS
_samr_OpenUser(pipes_struct
*p
,
2196 struct samr_OpenUser
*r
)
2198 struct samu
*sampass
=NULL
;
2200 POLICY_HND domain_pol
= *r
->in
.domain_handle
;
2201 POLICY_HND
*user_pol
= r
->out
.user_handle
;
2202 struct samr_info
*info
= NULL
;
2203 SEC_DESC
*psd
= NULL
;
2205 uint32 des_access
= r
->in
.access_mask
;
2211 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
2213 if ( !get_lsa_policy_samr_sid(p
, &domain_pol
, &sid
, &acc_granted
, NULL
) )
2214 return NT_STATUS_INVALID_HANDLE
;
2216 nt_status
= access_check_samr_function(acc_granted
,
2217 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
,
2220 if ( !NT_STATUS_IS_OK(nt_status
) )
2223 if ( !(sampass
= samu_new( p
->mem_ctx
)) ) {
2224 return NT_STATUS_NO_MEMORY
;
2227 /* append the user's RID to it */
2229 if (!sid_append_rid(&sid
, r
->in
.rid
))
2230 return NT_STATUS_NO_SUCH_USER
;
2232 /* check if access can be granted as requested by client. */
2234 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
2236 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
, &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
2237 se_map_generic(&des_access
, &usr_generic_mapping
);
2239 se_priv_copy( &se_rights
, &se_machine_account
);
2240 se_priv_add( &se_rights
, &se_add_users
);
2242 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
2243 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
2244 &acc_granted
, "_samr_OpenUser");
2246 if ( !NT_STATUS_IS_OK(nt_status
) )
2250 ret
=pdb_getsampwsid(sampass
, &sid
);
2253 /* check that the SID exists in our domain. */
2255 return NT_STATUS_NO_SUCH_USER
;
2258 TALLOC_FREE(sampass
);
2260 /* associate the user's SID and access bits with the new handle. */
2261 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
)
2262 return NT_STATUS_NO_MEMORY
;
2263 info
->acc_granted
= acc_granted
;
2265 /* get a (unique) handle. open a policy on it. */
2266 if (!create_policy_hnd(p
, user_pol
, free_samr_info
, (void *)info
))
2267 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2269 return NT_STATUS_OK
;
2272 /*************************************************************************
2273 *************************************************************************/
2275 static NTSTATUS
init_samr_parameters_string(TALLOC_CTX
*mem_ctx
,
2277 struct lsa_BinaryString
**_r
)
2279 struct lsa_BinaryString
*r
;
2282 return NT_STATUS_INVALID_PARAMETER
;
2285 r
= TALLOC_ZERO_P(mem_ctx
, struct lsa_BinaryString
);
2287 return NT_STATUS_NO_MEMORY
;
2290 r
->array
= TALLOC_ZERO_ARRAY(mem_ctx
, uint16_t, blob
->length
/2);
2292 return NT_STATUS_NO_MEMORY
;
2294 memcpy(r
->array
, blob
->data
, blob
->length
);
2295 r
->size
= blob
->length
;
2296 r
->length
= blob
->length
;
2299 return NT_STATUS_NO_MEMORY
;
2304 return NT_STATUS_OK
;
2307 /*************************************************************************
2308 get_user_info_7. Safe. Only gives out account_name.
2309 *************************************************************************/
2311 static NTSTATUS
get_user_info_7(TALLOC_CTX
*mem_ctx
,
2312 struct samr_UserInfo7
*r
,
2315 struct samu
*smbpass
=NULL
;
2317 const char *account_name
= NULL
;
2321 if ( !(smbpass
= samu_new( mem_ctx
)) ) {
2322 return NT_STATUS_NO_MEMORY
;
2326 ret
= pdb_getsampwsid(smbpass
, user_sid
);
2330 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
2331 return NT_STATUS_NO_SUCH_USER
;
2334 account_name
= talloc_strdup(mem_ctx
, pdb_get_username(smbpass
));
2335 if (!account_name
) {
2336 TALLOC_FREE(smbpass
);
2337 return NT_STATUS_NO_MEMORY
;
2339 TALLOC_FREE(smbpass
);
2341 DEBUG(3,("User:[%s]\n", account_name
));
2343 init_samr_user_info7(r
, account_name
);
2345 return NT_STATUS_OK
;
2348 /*************************************************************************
2349 get_user_info_9. Only gives out primary group SID.
2350 *************************************************************************/
2352 static NTSTATUS
get_user_info_9(TALLOC_CTX
*mem_ctx
,
2353 struct samr_UserInfo9
*r
,
2356 struct samu
*smbpass
=NULL
;
2361 if ( !(smbpass
= samu_new( mem_ctx
)) ) {
2362 return NT_STATUS_NO_MEMORY
;
2366 ret
= pdb_getsampwsid(smbpass
, user_sid
);
2370 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
2371 TALLOC_FREE(smbpass
);
2372 return NT_STATUS_NO_SUCH_USER
;
2375 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass
) ));
2377 init_samr_user_info9(r
, pdb_get_group_rid(smbpass
));
2379 TALLOC_FREE(smbpass
);
2381 return NT_STATUS_OK
;
2384 /*************************************************************************
2385 get_user_info_16. Safe. Only gives out acb bits.
2386 *************************************************************************/
2388 static NTSTATUS
get_user_info_16(TALLOC_CTX
*mem_ctx
,
2389 struct samr_UserInfo16
*r
,
2392 struct samu
*smbpass
=NULL
;
2397 if ( !(smbpass
= samu_new( mem_ctx
)) ) {
2398 return NT_STATUS_NO_MEMORY
;
2402 ret
= pdb_getsampwsid(smbpass
, user_sid
);
2406 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
2407 TALLOC_FREE(smbpass
);
2408 return NT_STATUS_NO_SUCH_USER
;
2411 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass
) ));
2413 init_samr_user_info16(r
, pdb_get_acct_ctrl(smbpass
));
2415 TALLOC_FREE(smbpass
);
2417 return NT_STATUS_OK
;
2420 /*************************************************************************
2421 get_user_info_18. OK - this is the killer as it gives out password info.
2422 Ensure that this is only allowed on an encrypted connection with a root
2424 *************************************************************************/
2426 static NTSTATUS
get_user_info_18(pipes_struct
*p
,
2427 TALLOC_CTX
*mem_ctx
,
2428 struct samr_UserInfo18
*r
,
2431 struct samu
*smbpass
=NULL
;
2436 if (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_NTLMSSP
|| p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SPNEGO_NTLMSSP
) {
2437 return NT_STATUS_ACCESS_DENIED
;
2440 if (p
->auth
.auth_level
!= PIPE_AUTH_LEVEL_PRIVACY
) {
2441 return NT_STATUS_ACCESS_DENIED
;
2445 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2448 if ( !(smbpass
= samu_new( mem_ctx
)) ) {
2449 return NT_STATUS_NO_MEMORY
;
2452 ret
= pdb_getsampwsid(smbpass
, user_sid
);
2455 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid
)));
2456 TALLOC_FREE(smbpass
);
2457 return (geteuid() == (uid_t
)0) ? NT_STATUS_NO_SUCH_USER
: NT_STATUS_ACCESS_DENIED
;
2460 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass
), pdb_get_acct_ctrl(smbpass
) ));
2462 if ( pdb_get_acct_ctrl(smbpass
) & ACB_DISABLED
) {
2463 TALLOC_FREE(smbpass
);
2464 return NT_STATUS_ACCOUNT_DISABLED
;
2467 init_samr_user_info18(r
, pdb_get_lanman_passwd(smbpass
),
2468 pdb_get_nt_passwd(smbpass
));
2470 TALLOC_FREE(smbpass
);
2472 return NT_STATUS_OK
;
2475 /*************************************************************************
2477 *************************************************************************/
2479 static NTSTATUS
get_user_info_20(TALLOC_CTX
*mem_ctx
,
2480 struct samr_UserInfo20
*r
,
2483 struct samu
*sampass
=NULL
;
2485 const char *munged_dial
= NULL
;
2488 struct lsa_BinaryString
*parameters
= NULL
;
2492 if ( !(sampass
= samu_new( mem_ctx
)) ) {
2493 return NT_STATUS_NO_MEMORY
;
2497 ret
= pdb_getsampwsid(sampass
, user_sid
);
2501 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
2502 TALLOC_FREE(sampass
);
2503 return NT_STATUS_NO_SUCH_USER
;
2506 munged_dial
= pdb_get_munged_dial(sampass
);
2508 samr_clear_sam_passwd(sampass
);
2510 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass
),
2511 munged_dial
, (int)strlen(munged_dial
)));
2514 blob
= base64_decode_data_blob(munged_dial
);
2516 blob
= data_blob_string_const("");
2519 status
= init_samr_parameters_string(mem_ctx
, &blob
, ¶meters
);
2520 data_blob_free(&blob
);
2521 TALLOC_FREE(sampass
);
2522 if (!NT_STATUS_IS_OK(status
)) {
2526 init_samr_user_info20(r
, parameters
);
2528 return NT_STATUS_OK
;
2532 /*************************************************************************
2534 *************************************************************************/
2536 static NTSTATUS
get_user_info_21(TALLOC_CTX
*mem_ctx
,
2537 struct samr_UserInfo21
*r
,
2539 DOM_SID
*domain_sid
)
2542 struct samu
*pw
= NULL
;
2544 const DOM_SID
*sid_user
, *sid_group
;
2545 uint32_t rid
, primary_gid
;
2546 NTTIME last_logon
, last_logoff
, last_password_change
,
2547 acct_expiry
, allow_password_change
, force_password_change
;
2548 time_t must_change_time
;
2549 uint8_t password_expired
;
2550 const char *account_name
, *full_name
, *home_directory
, *home_drive
,
2551 *logon_script
, *profile_path
, *description
,
2552 *workstations
, *comment
;
2553 struct samr_LogonHours logon_hours
;
2554 struct lsa_BinaryString
*parameters
= NULL
;
2555 const char *munged_dial
= NULL
;
2560 if (!(pw
= samu_new(mem_ctx
))) {
2561 return NT_STATUS_NO_MEMORY
;
2565 ret
= pdb_getsampwsid(pw
, user_sid
);
2569 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
2571 return NT_STATUS_NO_SUCH_USER
;
2574 samr_clear_sam_passwd(pw
);
2576 DEBUG(3,("User:[%s]\n", pdb_get_username(pw
)));
2578 sid_user
= pdb_get_user_sid(pw
);
2580 if (!sid_peek_check_rid(domain_sid
, sid_user
, &rid
)) {
2581 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2582 "the domain sid %s. Failing operation.\n",
2583 pdb_get_username(pw
), sid_string_dbg(sid_user
),
2584 sid_string_dbg(domain_sid
)));
2586 return NT_STATUS_UNSUCCESSFUL
;
2590 sid_group
= pdb_get_group_sid(pw
);
2593 if (!sid_peek_check_rid(domain_sid
, sid_group
, &primary_gid
)) {
2594 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2595 "which conflicts with the domain sid %s. Failing operation.\n",
2596 pdb_get_username(pw
), sid_string_dbg(sid_group
),
2597 sid_string_dbg(domain_sid
)));
2599 return NT_STATUS_UNSUCCESSFUL
;
2602 unix_to_nt_time(&last_logon
, pdb_get_logon_time(pw
));
2603 unix_to_nt_time(&last_logoff
, pdb_get_logoff_time(pw
));
2604 unix_to_nt_time(&acct_expiry
, pdb_get_kickoff_time(pw
));
2605 unix_to_nt_time(&last_password_change
, pdb_get_pass_last_set_time(pw
));
2606 unix_to_nt_time(&allow_password_change
, pdb_get_pass_can_change_time(pw
));
2608 must_change_time
= pdb_get_pass_must_change_time(pw
);
2609 if (must_change_time
== get_time_t_max()) {
2610 unix_to_nt_time_abs(&force_password_change
, must_change_time
);
2612 unix_to_nt_time(&force_password_change
, must_change_time
);
2615 if (pdb_get_pass_must_change_time(pw
) == 0) {
2616 password_expired
= PASS_MUST_CHANGE_AT_NEXT_LOGON
;
2618 password_expired
= 0;
2621 munged_dial
= pdb_get_munged_dial(pw
);
2623 blob
= base64_decode_data_blob(munged_dial
);
2625 blob
= data_blob_string_const("");
2628 status
= init_samr_parameters_string(mem_ctx
, &blob
, ¶meters
);
2629 data_blob_free(&blob
);
2630 if (!NT_STATUS_IS_OK(status
)) {
2635 account_name
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2636 full_name
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2637 home_directory
= talloc_strdup(mem_ctx
, pdb_get_homedir(pw
));
2638 home_drive
= talloc_strdup(mem_ctx
, pdb_get_dir_drive(pw
));
2639 logon_script
= talloc_strdup(mem_ctx
, pdb_get_logon_script(pw
));
2640 profile_path
= talloc_strdup(mem_ctx
, pdb_get_profile_path(pw
));
2641 description
= talloc_strdup(mem_ctx
, pdb_get_acct_desc(pw
));
2642 workstations
= talloc_strdup(mem_ctx
, pdb_get_workstations(pw
));
2643 comment
= talloc_strdup(mem_ctx
, pdb_get_comment(pw
));
2645 logon_hours
= get_logon_hours_from_pdb(mem_ctx
, pw
);
2649 Look at a user on a real NT4 PDC with usrmgr, press
2650 'ok'. Then you will see that fields_present is set to
2651 0x08f827fa. Look at the user immediately after that again,
2652 and you will see that 0x00fffff is returned. This solves
2653 the problem that you get access denied after having looked
2660 init_samr_user_info21(r
,
2663 last_password_change
,
2665 allow_password_change
,
2666 force_password_change
,
2679 pdb_get_acct_ctrl(pw
),
2680 pdb_build_fields_present(pw
),
2682 pdb_get_bad_password_count(pw
),
2683 pdb_get_logon_count(pw
),
2684 0, /* country_code */
2686 0, /* nt_password_set */
2687 0, /* lm_password_set */
2691 return NT_STATUS_OK
;
2694 /*******************************************************************
2696 ********************************************************************/
2698 NTSTATUS
_samr_QueryUserInfo(pipes_struct
*p
,
2699 struct samr_QueryUserInfo
*r
)
2702 union samr_UserInfo
*user_info
= NULL
;
2703 struct samr_info
*info
= NULL
;
2707 /* search for the handle */
2708 if (!find_policy_by_hnd(p
, r
->in
.user_handle
, (void **)(void *)&info
))
2709 return NT_STATUS_INVALID_HANDLE
;
2711 status
= access_check_samr_function(info
->acc_granted
,
2712 SAMR_USER_ACCESS_GET_ATTRIBUTES
,
2713 "_samr_QueryUserInfo");
2714 if (!NT_STATUS_IS_OK(status
)) {
2718 domain_sid
= info
->sid
;
2720 sid_split_rid(&domain_sid
, &rid
);
2722 if (!sid_check_is_in_our_domain(&info
->sid
))
2723 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
2725 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
2726 sid_string_dbg(&info
->sid
)));
2728 user_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_UserInfo
);
2730 return NT_STATUS_NO_MEMORY
;
2733 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r
->in
.level
));
2735 switch (r
->in
.level
) {
2737 status
= get_user_info_7(p
->mem_ctx
, &user_info
->info7
, &info
->sid
);
2738 if (!NT_STATUS_IS_OK(status
)) {
2743 status
= get_user_info_9(p
->mem_ctx
, &user_info
->info9
, &info
->sid
);
2744 if (!NT_STATUS_IS_OK(status
)) {
2749 status
= get_user_info_16(p
->mem_ctx
, &user_info
->info16
, &info
->sid
);
2750 if (!NT_STATUS_IS_OK(status
)) {
2756 status
= get_user_info_18(p
, p
->mem_ctx
, &user_info
->info18
, &info
->sid
);
2757 if (!NT_STATUS_IS_OK(status
)) {
2763 status
= get_user_info_20(p
->mem_ctx
, &user_info
->info20
, &info
->sid
);
2764 if (!NT_STATUS_IS_OK(status
)) {
2770 status
= get_user_info_21(p
->mem_ctx
, &user_info
->info21
,
2771 &info
->sid
, &domain_sid
);
2772 if (!NT_STATUS_IS_OK(status
)) {
2778 return NT_STATUS_INVALID_INFO_CLASS
;
2781 *r
->out
.info
= user_info
;
2783 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__
));
2788 /*******************************************************************
2789 _samr_GetGroupsForUser
2790 ********************************************************************/
2792 NTSTATUS
_samr_GetGroupsForUser(pipes_struct
*p
,
2793 struct samr_GetGroupsForUser
*r
)
2795 struct samu
*sam_pass
=NULL
;
2798 struct samr_RidWithAttribute dom_gid
;
2799 struct samr_RidWithAttribute
*gids
= NULL
;
2800 uint32 primary_group_rid
;
2801 size_t num_groups
= 0;
2807 bool success
= False
;
2809 struct samr_RidWithAttributeArray
*rids
= NULL
;
2812 * from the SID in the request:
2813 * we should send back the list of DOMAIN GROUPS
2814 * the user is a member of
2816 * and only the DOMAIN GROUPS
2817 * no ALIASES !!! neither aliases of the domain
2818 * nor aliases of the builtin SID
2823 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__
));
2825 rids
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_RidWithAttributeArray
);
2827 return NT_STATUS_NO_MEMORY
;
2830 /* find the policy handle. open a policy on it. */
2831 if (!get_lsa_policy_samr_sid(p
, r
->in
.user_handle
, &sid
, &acc_granted
, NULL
))
2832 return NT_STATUS_INVALID_HANDLE
;
2834 result
= access_check_samr_function(acc_granted
,
2835 SA_RIGHT_USER_GET_GROUPS
,
2836 "_samr_GetGroupsForUser");
2837 if (!NT_STATUS_IS_OK(result
)) {
2841 if (!sid_check_is_in_our_domain(&sid
))
2842 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
2844 if ( !(sam_pass
= samu_new( p
->mem_ctx
)) ) {
2845 return NT_STATUS_NO_MEMORY
;
2849 ret
= pdb_getsampwsid(sam_pass
, &sid
);
2853 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2854 sid_string_dbg(&sid
)));
2855 return NT_STATUS_NO_SUCH_USER
;
2860 /* make both calls inside the root block */
2862 result
= pdb_enum_group_memberships(p
->mem_ctx
, sam_pass
,
2863 &sids
, &unix_gids
, &num_groups
);
2864 if ( NT_STATUS_IS_OK(result
) ) {
2865 success
= sid_peek_check_rid(get_global_sam_sid(),
2866 pdb_get_group_sid(sam_pass
),
2867 &primary_group_rid
);
2871 if (!NT_STATUS_IS_OK(result
)) {
2872 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2873 sid_string_dbg(&sid
)));
2878 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2879 sid_string_dbg(pdb_get_group_sid(sam_pass
)),
2880 pdb_get_username(sam_pass
)));
2881 TALLOC_FREE(sam_pass
);
2882 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
2888 dom_gid
.attributes
= (SE_GROUP_MANDATORY
|SE_GROUP_ENABLED_BY_DEFAULT
|
2890 dom_gid
.rid
= primary_group_rid
;
2891 ADD_TO_ARRAY(p
->mem_ctx
, struct samr_RidWithAttribute
, dom_gid
, &gids
, &num_gids
);
2893 for (i
=0; i
<num_groups
; i
++) {
2895 if (!sid_peek_check_rid(get_global_sam_sid(),
2896 &(sids
[i
]), &dom_gid
.rid
)) {
2897 DEBUG(10, ("Found sid %s not in our domain\n",
2898 sid_string_dbg(&sids
[i
])));
2902 if (dom_gid
.rid
== primary_group_rid
) {
2903 /* We added the primary group directly from the
2904 * sam_account. The other SIDs are unique from
2905 * enum_group_memberships */
2909 ADD_TO_ARRAY(p
->mem_ctx
, struct samr_RidWithAttribute
, dom_gid
, &gids
, &num_gids
);
2912 rids
->count
= num_gids
;
2915 *r
->out
.rids
= rids
;
2917 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__
));
2922 /*******************************************************************
2923 _samr_QueryDomainInfo
2924 ********************************************************************/
2926 NTSTATUS
_samr_QueryDomainInfo(pipes_struct
*p
,
2927 struct samr_QueryDomainInfo
*r
)
2929 NTSTATUS status
= NT_STATUS_OK
;
2930 struct samr_info
*info
= NULL
;
2931 union samr_DomainInfo
*dom_info
;
2932 uint32 min_pass_len
,pass_hist
,password_properties
;
2933 time_t u_expire
, u_min_age
;
2934 NTTIME nt_expire
, nt_min_age
;
2936 time_t u_lock_duration
, u_reset_time
;
2937 NTTIME nt_lock_duration
, nt_reset_time
;
2942 uint32 account_policy_temp
;
2947 uint32 num_users
=0, num_groups
=0, num_aliases
=0;
2949 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__
));
2951 dom_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_DomainInfo
);
2953 return NT_STATUS_NO_MEMORY
;
2956 /* find the policy handle. open a policy on it. */
2957 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
)) {
2958 return NT_STATUS_INVALID_HANDLE
;
2961 status
= access_check_samr_function(info
->acc_granted
,
2962 SA_RIGHT_SAM_OPEN_DOMAIN
,
2963 "_samr_QueryDomainInfo" );
2965 if ( !NT_STATUS_IS_OK(status
) )
2968 switch (r
->in
.level
) {
2975 pdb_get_account_policy(AP_MIN_PASSWORD_LEN
, &account_policy_temp
);
2976 min_pass_len
= account_policy_temp
;
2978 pdb_get_account_policy(AP_PASSWORD_HISTORY
, &account_policy_temp
);
2979 pass_hist
= account_policy_temp
;
2981 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS
, &account_policy_temp
);
2982 password_properties
= account_policy_temp
;
2984 pdb_get_account_policy(AP_MAX_PASSWORD_AGE
, &account_policy_temp
);
2985 u_expire
= account_policy_temp
;
2987 pdb_get_account_policy(AP_MIN_PASSWORD_AGE
, &account_policy_temp
);
2988 u_min_age
= account_policy_temp
;
2994 unix_to_nt_time_abs(&nt_expire
, u_expire
);
2995 unix_to_nt_time_abs(&nt_min_age
, u_min_age
);
2997 if (lp_check_password_script() && *lp_check_password_script()) {
2998 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
3001 init_samr_DomInfo1(&dom_info
->info1
,
3002 (uint16
)min_pass_len
,
3004 password_properties
,
3014 num_users
= count_sam_users(info
->disp_info
, ACB_NORMAL
);
3015 num_groups
= count_sam_groups(info
->disp_info
);
3016 num_aliases
= count_sam_aliases(info
->disp_info
);
3018 pdb_get_account_policy(AP_TIME_TO_LOGOUT
, &account_policy_temp
);
3019 u_logout
= account_policy_temp
;
3021 unix_to_nt_time_abs(&nt_logout
, u_logout
);
3023 if (!pdb_get_seq_num(&seq_num
))
3024 seq_num
= time(NULL
);
3030 server_role
= ROLE_DOMAIN_PDC
;
3031 if (lp_server_role() == ROLE_DOMAIN_BDC
)
3032 server_role
= ROLE_DOMAIN_BDC
;
3034 init_samr_DomInfo2(&dom_info
->info2
,
3055 pdb_get_account_policy(AP_TIME_TO_LOGOUT
, &ul
);
3056 u_logout
= (time_t)ul
;
3063 unix_to_nt_time_abs(&nt_logout
, u_logout
);
3065 init_samr_DomInfo3(&dom_info
->info3
,
3070 init_samr_DomInfo4(&dom_info
->info4
,
3074 init_samr_DomInfo5(&dom_info
->info5
,
3075 get_global_sam_name());
3078 /* NT returns its own name when a PDC. win2k and later
3079 * only the name of the PDC if itself is a BDC (samba4
3081 init_samr_DomInfo6(&dom_info
->info6
,
3085 server_role
= ROLE_DOMAIN_PDC
;
3086 if (lp_server_role() == ROLE_DOMAIN_BDC
)
3087 server_role
= ROLE_DOMAIN_BDC
;
3089 init_samr_DomInfo7(&dom_info
->info7
,
3098 if (!pdb_get_seq_num(&seq_num
)) {
3099 seq_num
= time(NULL
);
3106 init_samr_DomInfo8(&dom_info
->info8
,
3116 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION
, &account_policy_temp
);
3117 u_lock_duration
= account_policy_temp
;
3118 if (u_lock_duration
!= -1) {
3119 u_lock_duration
*= 60;
3122 pdb_get_account_policy(AP_RESET_COUNT_TIME
, &account_policy_temp
);
3123 u_reset_time
= account_policy_temp
* 60;
3125 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT
, &account_policy_temp
);
3126 lockout
= account_policy_temp
;
3132 unix_to_nt_time_abs(&nt_lock_duration
, u_lock_duration
);
3133 unix_to_nt_time_abs(&nt_reset_time
, u_reset_time
);
3135 init_samr_DomInfo12(&dom_info
->info12
,
3141 return NT_STATUS_INVALID_INFO_CLASS
;
3144 *r
->out
.info
= dom_info
;
3146 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__
));
3151 /* W2k3 seems to use the same check for all 3 objects that can be created via
3152 * SAMR, if you try to create for example "Dialup" as an alias it says
3153 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
3156 static NTSTATUS
can_create(TALLOC_CTX
*mem_ctx
, const char *new_name
)
3158 enum lsa_SidType type
;
3161 DEBUG(10, ("Checking whether [%s] can be created\n", new_name
));
3164 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3165 * whether the name already exists */
3166 result
= lookup_name(mem_ctx
, new_name
, LOOKUP_NAME_LOCAL
,
3167 NULL
, NULL
, NULL
, &type
);
3171 DEBUG(10, ("%s does not exist, can create it\n", new_name
));
3172 return NT_STATUS_OK
;
3175 DEBUG(5, ("trying to create %s, exists as %s\n",
3176 new_name
, sid_type_lookup(type
)));
3178 if (type
== SID_NAME_DOM_GRP
) {
3179 return NT_STATUS_GROUP_EXISTS
;
3181 if (type
== SID_NAME_ALIAS
) {
3182 return NT_STATUS_ALIAS_EXISTS
;
3185 /* Yes, the default is NT_STATUS_USER_EXISTS */
3186 return NT_STATUS_USER_EXISTS
;
3189 /*******************************************************************
3191 ********************************************************************/
3193 NTSTATUS
_samr_CreateUser2(pipes_struct
*p
,
3194 struct samr_CreateUser2
*r
)
3196 const char *account
= NULL
;
3198 POLICY_HND dom_pol
= *r
->in
.domain_handle
;
3199 uint32_t acb_info
= r
->in
.acct_flags
;
3200 POLICY_HND
*user_pol
= r
->out
.user_handle
;
3201 struct samr_info
*info
= NULL
;
3206 /* check this, when giving away 'add computer to domain' privs */
3207 uint32 des_access
= GENERIC_RIGHTS_USER_ALL_ACCESS
;
3208 bool can_add_account
= False
;
3210 DISP_INFO
*disp_info
= NULL
;
3212 /* Get the domain SID stored in the domain policy */
3213 if (!get_lsa_policy_samr_sid(p
, &dom_pol
, &sid
, &acc_granted
,
3215 return NT_STATUS_INVALID_HANDLE
;
3217 nt_status
= access_check_samr_function(acc_granted
,
3218 SA_RIGHT_DOMAIN_CREATE_USER
,
3219 "_samr_CreateUser2");
3220 if (!NT_STATUS_IS_OK(nt_status
)) {
3224 if (!(acb_info
== ACB_NORMAL
|| acb_info
== ACB_DOMTRUST
||
3225 acb_info
== ACB_WSTRUST
|| acb_info
== ACB_SVRTRUST
)) {
3226 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3227 this parameter is not an account type */
3228 return NT_STATUS_INVALID_PARAMETER
;
3231 account
= r
->in
.account_name
->string
;
3232 if (account
== NULL
) {
3233 return NT_STATUS_NO_MEMORY
;
3236 nt_status
= can_create(p
->mem_ctx
, account
);
3237 if (!NT_STATUS_IS_OK(nt_status
)) {
3241 /* determine which user right we need to check based on the acb_info */
3243 if ( acb_info
& ACB_WSTRUST
)
3245 se_priv_copy( &se_rights
, &se_machine_account
);
3246 can_add_account
= user_has_privileges(
3247 p
->pipe_user
.nt_user_token
, &se_rights
);
3249 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3250 account for domain trusts and changes the ACB flags later */
3251 else if ( acb_info
& ACB_NORMAL
&&
3252 (account
[strlen(account
)-1] != '$') )
3254 se_priv_copy( &se_rights
, &se_add_users
);
3255 can_add_account
= user_has_privileges(
3256 p
->pipe_user
.nt_user_token
, &se_rights
);
3258 else /* implicit assumption of a BDC or domain trust account here
3259 * (we already check the flags earlier) */
3261 if ( lp_enable_privileges() ) {
3262 /* only Domain Admins can add a BDC or domain trust */
3263 se_priv_copy( &se_rights
, &se_priv_none
);
3264 can_add_account
= nt_token_check_domain_rid(
3265 p
->pipe_user
.nt_user_token
,
3266 DOMAIN_GROUP_RID_ADMINS
);
3270 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3271 uidtoname(p
->pipe_user
.ut
.uid
),
3272 can_add_account
? "True":"False" ));
3274 /********** BEGIN Admin BLOCK **********/
3276 if ( can_add_account
)
3279 nt_status
= pdb_create_user(p
->mem_ctx
, account
, acb_info
,
3282 if ( can_add_account
)
3285 /********** END Admin BLOCK **********/
3287 /* now check for failure */
3289 if ( !NT_STATUS_IS_OK(nt_status
) )
3292 /* Get the user's SID */
3294 sid_compose(&sid
, get_global_sam_sid(), *r
->out
.rid
);
3296 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3298 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
,
3299 &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
3300 se_map_generic(&des_access
, &usr_generic_mapping
);
3302 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
3303 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
3304 &acc_granted
, "_samr_CreateUser2");
3306 if ( !NT_STATUS_IS_OK(nt_status
) ) {
3310 /* associate the user's SID with the new handle. */
3311 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
) {
3312 return NT_STATUS_NO_MEMORY
;
3317 info
->acc_granted
= acc_granted
;
3319 /* get a (unique) handle. open a policy on it. */
3320 if (!create_policy_hnd(p
, user_pol
, free_samr_info
, (void *)info
)) {
3321 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3324 /* After a "set" ensure we have no cached display info. */
3325 force_flush_samr_cache(info
->disp_info
);
3327 *r
->out
.access_granted
= acc_granted
;
3329 return NT_STATUS_OK
;
3332 /*******************************************************************
3334 ********************************************************************/
3336 NTSTATUS
_samr_Connect(pipes_struct
*p
,
3337 struct samr_Connect
*r
)
3339 struct samr_info
*info
= NULL
;
3340 uint32 des_access
= r
->in
.access_mask
;
3344 if (!pipe_access_check(p
)) {
3345 DEBUG(3, ("access denied to _samr_Connect\n"));
3346 return NT_STATUS_ACCESS_DENIED
;
3349 /* set up the SAMR connect_anon response */
3351 /* associate the user's SID with the new handle. */
3352 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
3353 return NT_STATUS_NO_MEMORY
;
3355 /* don't give away the farm but this is probably ok. The SA_RIGHT_SAM_ENUM_DOMAINS
3356 was observed from a win98 client trying to enumerate users (when configured
3357 user level access control on shares) --jerry */
3359 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3361 se_map_generic( &des_access
, &sam_generic_mapping
);
3362 info
->acc_granted
= des_access
& (SA_RIGHT_SAM_ENUM_DOMAINS
|SA_RIGHT_SAM_OPEN_DOMAIN
);
3364 /* get a (unique) handle. open a policy on it. */
3365 if (!create_policy_hnd(p
, r
->out
.connect_handle
, free_samr_info
, (void *)info
))
3366 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3368 return NT_STATUS_OK
;
3371 /*******************************************************************
3373 ********************************************************************/
3375 NTSTATUS
_samr_Connect2(pipes_struct
*p
,
3376 struct samr_Connect2
*r
)
3378 struct samr_info
*info
= NULL
;
3379 SEC_DESC
*psd
= NULL
;
3381 uint32 des_access
= r
->in
.access_mask
;
3386 DEBUG(5,("_samr_Connect2: %d\n", __LINE__
));
3390 if (!pipe_access_check(p
)) {
3391 DEBUG(3, ("access denied to _samr_Connect2\n"));
3392 return NT_STATUS_ACCESS_DENIED
;
3395 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3397 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
3398 se_map_generic(&des_access
, &sam_generic_mapping
);
3400 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
3401 NULL
, 0, des_access
, &acc_granted
, "_samr_Connect2");
3403 if ( !NT_STATUS_IS_OK(nt_status
) )
3406 /* associate the user's SID and access granted with the new handle. */
3407 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
3408 return NT_STATUS_NO_MEMORY
;
3410 info
->acc_granted
= acc_granted
;
3411 info
->status
= r
->in
.access_mask
; /* this looks so wrong... - gd */
3413 /* get a (unique) handle. open a policy on it. */
3414 if (!create_policy_hnd(p
, r
->out
.connect_handle
, free_samr_info
, (void *)info
))
3415 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3417 DEBUG(5,("_samr_Connect2: %d\n", __LINE__
));
3422 /*******************************************************************
3424 ********************************************************************/
3426 NTSTATUS
_samr_Connect4(pipes_struct
*p
,
3427 struct samr_Connect4
*r
)
3429 struct samr_info
*info
= NULL
;
3430 SEC_DESC
*psd
= NULL
;
3432 uint32 des_access
= r
->in
.access_mask
;
3437 DEBUG(5,("_samr_Connect4: %d\n", __LINE__
));
3441 if (!pipe_access_check(p
)) {
3442 DEBUG(3, ("access denied to samr_Connect4\n"));
3443 return NT_STATUS_ACCESS_DENIED
;
3446 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3448 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
3449 se_map_generic(&des_access
, &sam_generic_mapping
);
3451 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
3452 NULL
, 0, des_access
, &acc_granted
, "_samr_Connect4");
3454 if ( !NT_STATUS_IS_OK(nt_status
) )
3457 /* associate the user's SID and access granted with the new handle. */
3458 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
3459 return NT_STATUS_NO_MEMORY
;
3461 info
->acc_granted
= acc_granted
;
3462 info
->status
= r
->in
.access_mask
; /* ??? */
3464 /* get a (unique) handle. open a policy on it. */
3465 if (!create_policy_hnd(p
, r
->out
.connect_handle
, free_samr_info
, (void *)info
))
3466 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3468 DEBUG(5,("_samr_Connect4: %d\n", __LINE__
));
3470 return NT_STATUS_OK
;
3473 /*******************************************************************
3475 ********************************************************************/
3477 NTSTATUS
_samr_Connect5(pipes_struct
*p
,
3478 struct samr_Connect5
*r
)
3480 struct samr_info
*info
= NULL
;
3481 SEC_DESC
*psd
= NULL
;
3483 uint32 des_access
= r
->in
.access_mask
;
3486 struct samr_ConnectInfo1 info1
;
3488 DEBUG(5,("_samr_Connect5: %d\n", __LINE__
));
3492 if (!pipe_access_check(p
)) {
3493 DEBUG(3, ("access denied to samr_Connect5\n"));
3494 return NT_STATUS_ACCESS_DENIED
;
3497 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3499 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
3500 se_map_generic(&des_access
, &sam_generic_mapping
);
3502 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
3503 NULL
, 0, des_access
, &acc_granted
, "_samr_Connect5");
3505 if ( !NT_STATUS_IS_OK(nt_status
) )
3508 /* associate the user's SID and access granted with the new handle. */
3509 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
3510 return NT_STATUS_NO_MEMORY
;
3512 info
->acc_granted
= acc_granted
;
3513 info
->status
= r
->in
.access_mask
; /* ??? */
3515 /* get a (unique) handle. open a policy on it. */
3516 if (!create_policy_hnd(p
, r
->out
.connect_handle
, free_samr_info
, (void *)info
))
3517 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3519 DEBUG(5,("_samr_Connect5: %d\n", __LINE__
));
3521 info1
.client_version
= SAMR_CONNECT_AFTER_W2K
;
3524 *r
->out
.level_out
= 1;
3525 r
->out
.info_out
->info1
= info1
;
3527 return NT_STATUS_OK
;
3530 /**********************************************************************
3532 **********************************************************************/
3534 NTSTATUS
_samr_LookupDomain(pipes_struct
*p
,
3535 struct samr_LookupDomain
*r
)
3537 NTSTATUS status
= NT_STATUS_OK
;
3538 struct samr_info
*info
;
3539 const char *domain_name
;
3540 DOM_SID
*sid
= NULL
;
3542 if (!find_policy_by_hnd(p
, r
->in
.connect_handle
, (void**)(void *)&info
))
3543 return NT_STATUS_INVALID_HANDLE
;
3545 /* win9x user manager likes to use SA_RIGHT_SAM_ENUM_DOMAINS here.
3546 Reverted that change so we will work with RAS servers again */
3548 status
= access_check_samr_function(info
->acc_granted
,
3549 SA_RIGHT_SAM_OPEN_DOMAIN
,
3550 "_samr_LookupDomain");
3551 if (!NT_STATUS_IS_OK(status
)) {
3555 domain_name
= r
->in
.domain_name
->string
;
3557 sid
= TALLOC_ZERO_P(p
->mem_ctx
, struct dom_sid2
);
3559 return NT_STATUS_NO_MEMORY
;
3562 if (strequal(domain_name
, builtin_domain_name())) {
3563 sid_copy(sid
, &global_sid_Builtin
);
3565 if (!secrets_fetch_domain_sid(domain_name
, sid
)) {
3566 status
= NT_STATUS_NO_SUCH_DOMAIN
;
3570 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name
,
3571 sid_string_dbg(sid
)));
3578 /**********************************************************************
3580 **********************************************************************/
3582 NTSTATUS
_samr_EnumDomains(pipes_struct
*p
,
3583 struct samr_EnumDomains
*r
)
3586 struct samr_info
*info
;
3587 uint32_t num_entries
= 2;
3588 struct samr_SamEntry
*entry_array
= NULL
;
3589 struct samr_SamArray
*sam
;
3591 if (!find_policy_by_hnd(p
, r
->in
.connect_handle
, (void**)(void *)&info
))
3592 return NT_STATUS_INVALID_HANDLE
;
3594 status
= access_check_samr_function(info
->acc_granted
,
3595 SA_RIGHT_SAM_ENUM_DOMAINS
,
3596 "_samr_EnumDomains");
3597 if (!NT_STATUS_IS_OK(status
)) {
3601 sam
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
3603 return NT_STATUS_NO_MEMORY
;
3606 entry_array
= TALLOC_ZERO_ARRAY(p
->mem_ctx
,
3607 struct samr_SamEntry
,
3610 return NT_STATUS_NO_MEMORY
;
3613 entry_array
[0].idx
= 0;
3614 init_lsa_String(&entry_array
[0].name
, get_global_sam_name());
3616 entry_array
[1].idx
= 1;
3617 init_lsa_String(&entry_array
[1].name
, "Builtin");
3619 sam
->count
= num_entries
;
3620 sam
->entries
= entry_array
;
3623 *r
->out
.num_entries
= num_entries
;
3628 /*******************************************************************
3630 ********************************************************************/
3632 NTSTATUS
_samr_OpenAlias(pipes_struct
*p
,
3633 struct samr_OpenAlias
*r
)
3636 POLICY_HND domain_pol
= *r
->in
.domain_handle
;
3637 uint32 alias_rid
= r
->in
.rid
;
3638 POLICY_HND
*alias_pol
= r
->out
.alias_handle
;
3639 struct samr_info
*info
= NULL
;
3640 SEC_DESC
*psd
= NULL
;
3642 uint32 des_access
= r
->in
.access_mask
;
3647 /* find the domain policy and get the SID / access bits stored in the domain policy */
3649 if ( !get_lsa_policy_samr_sid(p
, &domain_pol
, &sid
, &acc_granted
, NULL
) )
3650 return NT_STATUS_INVALID_HANDLE
;
3652 status
= access_check_samr_function(acc_granted
,
3653 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
,
3656 if ( !NT_STATUS_IS_OK(status
) )
3659 /* append the alias' RID to it */
3661 if (!sid_append_rid(&sid
, alias_rid
))
3662 return NT_STATUS_NO_SUCH_ALIAS
;
3664 /*check if access can be granted as requested by client. */
3666 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
3668 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &ali_generic_mapping
, NULL
, 0);
3669 se_map_generic(&des_access
,&ali_generic_mapping
);
3671 se_priv_copy( &se_rights
, &se_add_users
);
3674 status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
3675 &se_rights
, GENERIC_RIGHTS_ALIAS_WRITE
, des_access
,
3676 &acc_granted
, "_samr_OpenAlias");
3678 if ( !NT_STATUS_IS_OK(status
) )
3682 /* Check we actually have the requested alias */
3683 enum lsa_SidType type
;
3688 result
= lookup_sid(NULL
, &sid
, NULL
, NULL
, &type
);
3691 if (!result
|| (type
!= SID_NAME_ALIAS
)) {
3692 return NT_STATUS_NO_SUCH_ALIAS
;
3695 /* make sure there is a mapping */
3697 if ( !sid_to_gid( &sid
, &gid
) ) {
3698 return NT_STATUS_NO_SUCH_ALIAS
;
3703 /* associate the alias SID with the new handle. */
3704 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
)
3705 return NT_STATUS_NO_MEMORY
;
3707 info
->acc_granted
= acc_granted
;
3709 /* get a (unique) handle. open a policy on it. */
3710 if (!create_policy_hnd(p
, alias_pol
, free_samr_info
, (void *)info
))
3711 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3713 return NT_STATUS_OK
;
3716 /*******************************************************************
3718 ********************************************************************/
3720 static NTSTATUS
set_user_info_7(TALLOC_CTX
*mem_ctx
,
3721 struct samr_UserInfo7
*id7
,
3727 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3729 return NT_STATUS_ACCESS_DENIED
;
3732 if (!id7
->account_name
.string
) {
3733 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3735 return NT_STATUS_ACCESS_DENIED
;
3738 /* check to see if the new username already exists. Note: we can't
3739 reliably lock all backends, so there is potentially the
3740 possibility that a user can be created in between this check and
3741 the rename. The rename should fail, but may not get the
3742 exact same failure status code. I think this is small enough
3743 of a window for this type of operation and the results are
3744 simply that the rename fails with a slightly different status
3745 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3747 rc
= can_create(mem_ctx
, id7
->account_name
.string
);
3748 if (!NT_STATUS_IS_OK(rc
)) {
3752 rc
= pdb_rename_sam_account(pwd
, id7
->account_name
.string
);
3758 /*******************************************************************
3760 ********************************************************************/
3762 static bool set_user_info_16(struct samr_UserInfo16
*id16
,
3766 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3771 /* FIX ME: check if the value is really changed --metze */
3772 if (!pdb_set_acct_ctrl(pwd
, id16
->acct_flags
, PDB_CHANGED
)) {
3777 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd
))) {
3787 /*******************************************************************
3789 ********************************************************************/
3791 static bool set_user_info_18(struct samr_UserInfo18
*id18
,
3795 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3800 if (!pdb_set_lanman_passwd (pwd
, id18
->lm_pwd
.hash
, PDB_CHANGED
)) {
3804 if (!pdb_set_nt_passwd (pwd
, id18
->nt_pwd
.hash
, PDB_CHANGED
)) {
3808 if (!pdb_set_pass_last_set_time (pwd
, time(NULL
), PDB_CHANGED
)) {
3813 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd
))) {
3822 /*******************************************************************
3824 ********************************************************************/
3826 static bool set_user_info_20(struct samr_UserInfo20
*id20
,
3830 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3834 copy_id20_to_sam_passwd(pwd
, id20
);
3836 /* write the change out */
3837 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd
))) {
3847 /*******************************************************************
3849 ********************************************************************/
3851 static NTSTATUS
set_user_info_21(TALLOC_CTX
*mem_ctx
,
3852 struct samr_UserInfo21
*id21
,
3858 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3859 return NT_STATUS_INVALID_PARAMETER
;
3862 /* we need to separately check for an account rename first */
3864 if (id21
->account_name
.string
&&
3865 (!strequal(id21
->account_name
.string
, pdb_get_username(pwd
))))
3868 /* check to see if the new username already exists. Note: we can't
3869 reliably lock all backends, so there is potentially the
3870 possibility that a user can be created in between this check and
3871 the rename. The rename should fail, but may not get the
3872 exact same failure status code. I think this is small enough
3873 of a window for this type of operation and the results are
3874 simply that the rename fails with a slightly different status
3875 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3877 status
= can_create(mem_ctx
, id21
->account_name
.string
);
3878 if (!NT_STATUS_IS_OK(status
)) {
3882 status
= pdb_rename_sam_account(pwd
, id21
->account_name
.string
);
3884 if (!NT_STATUS_IS_OK(status
)) {
3885 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3886 nt_errstr(status
)));
3891 /* set the new username so that later
3892 functions can work on the new account */
3893 pdb_set_username(pwd
, id21
->account_name
.string
, PDB_SET
);
3896 copy_id21_to_sam_passwd("INFO_21", pwd
, id21
);
3899 * The funny part about the previous two calls is
3900 * that pwd still has the password hashes from the
3901 * passdb entry. These have not been updated from
3902 * id21. I don't know if they need to be set. --jerry
3905 if ( IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) ) {
3906 status
= pdb_set_unix_primary_group(mem_ctx
, pwd
);
3907 if ( !NT_STATUS_IS_OK(status
) ) {
3912 /* Don't worry about writing out the user account since the
3913 primary group SID is generated solely from the user's Unix
3916 /* write the change out */
3917 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
3924 return NT_STATUS_OK
;
3927 /*******************************************************************
3929 ********************************************************************/
3931 static NTSTATUS
set_user_info_23(TALLOC_CTX
*mem_ctx
,
3932 struct samr_UserInfo23
*id23
,
3935 char *plaintext_buf
= NULL
;
3941 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3942 return NT_STATUS_INVALID_PARAMETER
;
3945 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3946 pdb_get_username(pwd
)));
3948 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
3950 if (!decode_pw_buffer(mem_ctx
,
3951 id23
->password
.data
,
3956 return NT_STATUS_INVALID_PARAMETER
;
3959 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
3961 return NT_STATUS_ACCESS_DENIED
;
3964 copy_id23_to_sam_passwd(pwd
, id23
);
3966 /* if it's a trust account, don't update /etc/passwd */
3967 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
3968 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
3969 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
3970 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3972 /* update the UNIX password */
3973 if (lp_unix_password_sync() ) {
3974 struct passwd
*passwd
;
3975 if (pdb_get_username(pwd
) == NULL
) {
3976 DEBUG(1, ("chgpasswd: User without name???\n"));
3978 return NT_STATUS_ACCESS_DENIED
;
3981 passwd
= Get_Pwnam_alloc(pwd
, pdb_get_username(pwd
));
3982 if (passwd
== NULL
) {
3983 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3986 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
3988 return NT_STATUS_ACCESS_DENIED
;
3990 TALLOC_FREE(passwd
);
3994 memset(plaintext_buf
, '\0', strlen(plaintext_buf
));
3996 if (IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) &&
3997 (!NT_STATUS_IS_OK(status
= pdb_set_unix_primary_group(mem_ctx
,
4003 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
4010 return NT_STATUS_OK
;
4013 /*******************************************************************
4015 ********************************************************************/
4017 static bool set_user_info_pw(uint8
*pass
, struct samu
*pwd
,
4021 char *plaintext_buf
= NULL
;
4023 time_t last_set_time
;
4024 enum pdb_value_state last_set_state
;
4026 DEBUG(5, ("Attempting administrator password change for user %s\n",
4027 pdb_get_username(pwd
)));
4029 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
4030 /* we need to know if it's expired, because this is an admin change, not a
4031 user change, so it's still expired when we're done */
4032 last_set_state
= pdb_get_init_flags(pwd
, PDB_PASSLASTSET
);
4033 last_set_time
= pdb_get_pass_last_set_time(pwd
);
4035 if (!decode_pw_buffer(talloc_tos(),
4044 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
4049 /* if it's a trust account, don't update /etc/passwd */
4050 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
4051 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
4052 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
4053 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
4055 /* update the UNIX password */
4056 if (lp_unix_password_sync()) {
4057 struct passwd
*passwd
;
4059 if (pdb_get_username(pwd
) == NULL
) {
4060 DEBUG(1, ("chgpasswd: User without name???\n"));
4065 passwd
= Get_Pwnam_alloc(pwd
, pdb_get_username(pwd
));
4066 if (passwd
== NULL
) {
4067 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
4070 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
4074 TALLOC_FREE(passwd
);
4078 memset(plaintext_buf
, '\0', strlen(plaintext_buf
));
4081 * A level 25 change does reset the pwdlastset field, a level 24
4082 * change does not. I know this is probably not the full story, but
4083 * it is needed to make XP join LDAP correctly, without it the later
4084 * auth2 check can fail with PWD_MUST_CHANGE.
4088 * restore last set time as this is an admin change, not a
4091 pdb_set_pass_last_set_time (pwd
, last_set_time
,
4095 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
4097 /* update the SAMBA password */
4098 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd
))) {
4108 /*******************************************************************
4110 ********************************************************************/
4112 static NTSTATUS
set_user_info_25(TALLOC_CTX
*mem_ctx
,
4113 struct samr_UserInfo25
*id25
,
4119 DEBUG(5, ("set_user_info_25: NULL id25\n"));
4120 return NT_STATUS_INVALID_PARAMETER
;
4123 copy_id25_to_sam_passwd(pwd
, id25
);
4125 /* write the change out */
4126 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
4132 * We need to "pdb_update_sam_account" before the unix primary group
4133 * is set, because the idealx scripts would also change the
4134 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
4135 * the delete explicit / add explicit, which would then fail to find
4136 * the previous primaryGroupSid value.
4139 if ( IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) ) {
4140 status
= pdb_set_unix_primary_group(mem_ctx
, pwd
);
4141 if ( !NT_STATUS_IS_OK(status
) ) {
4146 /* WARNING: No TALLOC_FREE(pwd), we are about to set the password
4149 return NT_STATUS_OK
;
4152 /*******************************************************************
4154 ********************************************************************/
4156 NTSTATUS
_samr_SetUserInfo(pipes_struct
*p
,
4157 struct samr_SetUserInfo
*r
)
4160 struct samu
*pwd
= NULL
;
4162 POLICY_HND
*pol
= r
->in
.user_handle
;
4163 union samr_UserInfo
*info
= r
->in
.info
;
4164 uint16_t switch_value
= r
->in
.level
;
4165 uint32_t acc_granted
;
4166 uint32_t acc_required
;
4168 bool has_enough_rights
= False
;
4170 DISP_INFO
*disp_info
= NULL
;
4172 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__
));
4174 /* find the policy handle. open a policy on it. */
4175 if (!get_lsa_policy_samr_sid(p
, pol
, &sid
, &acc_granted
, &disp_info
)) {
4176 return NT_STATUS_INVALID_HANDLE
;
4179 /* This is tricky. A WinXP domain join sets
4180 (SA_RIGHT_USER_SET_PASSWORD|SA_RIGHT_USER_SET_ATTRIBUTES|SA_RIGHT_USER_ACCT_FLAGS_EXPIRY)
4181 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
4182 standard Win32 API calls just ask for SA_RIGHT_USER_SET_PASSWORD in the SamrOpenUser().
4183 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
4184 we'll use the set from the WinXP join as the basis. */
4186 switch (switch_value
) {
4191 acc_required
= SA_RIGHT_USER_SET_PASSWORD
;
4194 acc_required
= SA_RIGHT_USER_SET_PASSWORD
|
4195 SA_RIGHT_USER_SET_ATTRIBUTES
|
4196 SA_RIGHT_USER_ACCT_FLAGS_EXPIRY
;
4200 status
= access_check_samr_function(acc_granted
,
4202 "_samr_SetUserInfo");
4203 if (!NT_STATUS_IS_OK(status
)) {
4207 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
4208 sid_string_dbg(&sid
), switch_value
));
4211 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
4212 return NT_STATUS_INVALID_INFO_CLASS
;
4215 if (!(pwd
= samu_new(NULL
))) {
4216 return NT_STATUS_NO_MEMORY
;
4220 ret
= pdb_getsampwsid(pwd
, &sid
);
4225 return NT_STATUS_NO_SUCH_USER
;
4228 /* deal with machine password changes differently from userinfo changes */
4229 /* check to see if we have the sufficient rights */
4231 acb_info
= pdb_get_acct_ctrl(pwd
);
4232 if (acb_info
& ACB_WSTRUST
)
4233 has_enough_rights
= user_has_privileges(p
->pipe_user
.nt_user_token
,
4234 &se_machine_account
);
4235 else if (acb_info
& ACB_NORMAL
)
4236 has_enough_rights
= user_has_privileges(p
->pipe_user
.nt_user_token
,
4238 else if (acb_info
& (ACB_SVRTRUST
|ACB_DOMTRUST
)) {
4239 if (lp_enable_privileges()) {
4240 has_enough_rights
= nt_token_check_domain_rid(p
->pipe_user
.nt_user_token
,
4241 DOMAIN_GROUP_RID_ADMINS
);
4245 DEBUG(5, ("_samr_SetUserInfo: %s does%s possess sufficient rights\n",
4246 uidtoname(p
->pipe_user
.ut
.uid
),
4247 has_enough_rights
? "" : " not"));
4249 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
4251 if (has_enough_rights
) {
4255 /* ok! user info levels (lots: see MSDEV help), off we go... */
4257 switch (switch_value
) {
4260 status
= set_user_info_7(p
->mem_ctx
,
4265 if (!set_user_info_16(&info
->info16
, pwd
)) {
4266 status
= NT_STATUS_ACCESS_DENIED
;
4271 /* Used by AS/U JRA. */
4272 if (!set_user_info_18(&info
->info18
, pwd
)) {
4273 status
= NT_STATUS_ACCESS_DENIED
;
4278 if (!set_user_info_20(&info
->info20
, pwd
)) {
4279 status
= NT_STATUS_ACCESS_DENIED
;
4284 status
= set_user_info_21(p
->mem_ctx
,
4285 &info
->info21
, pwd
);
4289 if (!p
->session_key
.length
) {
4290 status
= NT_STATUS_NO_USER_SESSION_KEY
;
4292 SamOEMhashBlob(info
->info23
.password
.data
, 516,
4295 dump_data(100, info
->info23
.password
.data
, 516);
4297 status
= set_user_info_23(p
->mem_ctx
,
4298 &info
->info23
, pwd
);
4302 if (!p
->session_key
.length
) {
4303 status
= NT_STATUS_NO_USER_SESSION_KEY
;
4305 SamOEMhashBlob(info
->info24
.password
.data
,
4309 dump_data(100, info
->info24
.password
.data
, 516);
4311 if (!set_user_info_pw(info
->info24
.password
.data
, pwd
,
4313 status
= NT_STATUS_ACCESS_DENIED
;
4318 if (!p
->session_key
.length
) {
4319 status
= NT_STATUS_NO_USER_SESSION_KEY
;
4321 encode_or_decode_arc4_passwd_buffer(info
->info25
.password
.data
,
4324 dump_data(100, info
->info25
.password
.data
, 532);
4326 status
= set_user_info_25(p
->mem_ctx
,
4327 &info
->info25
, pwd
);
4328 if (!NT_STATUS_IS_OK(status
)) {
4331 if (!set_user_info_pw(info
->info25
.password
.data
, pwd
,
4333 status
= NT_STATUS_ACCESS_DENIED
;
4338 if (!p
->session_key
.length
) {
4339 status
= NT_STATUS_NO_USER_SESSION_KEY
;
4341 encode_or_decode_arc4_passwd_buffer(info
->info26
.password
.data
,
4344 dump_data(100, info
->info26
.password
.data
, 516);
4346 if (!set_user_info_pw(info
->info26
.password
.data
, pwd
,
4348 status
= NT_STATUS_ACCESS_DENIED
;
4353 status
= NT_STATUS_INVALID_INFO_CLASS
;
4358 if (has_enough_rights
) {
4362 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
4364 if (NT_STATUS_IS_OK(status
)) {
4365 force_flush_samr_cache(disp_info
);
4371 /*******************************************************************
4373 ********************************************************************/
4375 NTSTATUS
_samr_SetUserInfo2(pipes_struct
*p
,
4376 struct samr_SetUserInfo2
*r
)
4378 struct samr_SetUserInfo q
;
4380 q
.in
.user_handle
= r
->in
.user_handle
;
4381 q
.in
.level
= r
->in
.level
;
4382 q
.in
.info
= r
->in
.info
;
4384 return _samr_SetUserInfo(p
, &q
);
4387 /*********************************************************************
4388 _samr_GetAliasMembership
4389 *********************************************************************/
4391 NTSTATUS
_samr_GetAliasMembership(pipes_struct
*p
,
4392 struct samr_GetAliasMembership
*r
)
4394 size_t num_alias_rids
;
4396 struct samr_info
*info
= NULL
;
4404 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__
));
4406 /* find the policy handle. open a policy on it. */
4407 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
))
4408 return NT_STATUS_INVALID_HANDLE
;
4410 ntstatus1
= access_check_samr_function(info
->acc_granted
,
4411 SA_RIGHT_DOMAIN_LOOKUP_ALIAS_BY_MEM
,
4412 "_samr_GetAliasMembership");
4413 ntstatus2
= access_check_samr_function(info
->acc_granted
,
4414 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
,
4415 "_samr_GetAliasMembership");
4417 if (!NT_STATUS_IS_OK(ntstatus1
) || !NT_STATUS_IS_OK(ntstatus2
)) {
4418 if (!(NT_STATUS_EQUAL(ntstatus1
,NT_STATUS_ACCESS_DENIED
) && NT_STATUS_IS_OK(ntstatus2
)) &&
4419 !(NT_STATUS_EQUAL(ntstatus1
,NT_STATUS_ACCESS_DENIED
) && NT_STATUS_IS_OK(ntstatus1
))) {
4420 return (NT_STATUS_IS_OK(ntstatus1
)) ? ntstatus2
: ntstatus1
;
4424 if (!sid_check_is_domain(&info
->sid
) &&
4425 !sid_check_is_builtin(&info
->sid
))
4426 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
4428 if (r
->in
.sids
->num_sids
) {
4429 members
= TALLOC_ARRAY(p
->mem_ctx
, DOM_SID
, r
->in
.sids
->num_sids
);
4431 if (members
== NULL
)
4432 return NT_STATUS_NO_MEMORY
;
4437 for (i
=0; i
<r
->in
.sids
->num_sids
; i
++)
4438 sid_copy(&members
[i
], r
->in
.sids
->sids
[i
].sid
);
4444 ntstatus1
= pdb_enum_alias_memberships(p
->mem_ctx
, &info
->sid
, members
,
4445 r
->in
.sids
->num_sids
,
4446 &alias_rids
, &num_alias_rids
);
4449 if (!NT_STATUS_IS_OK(ntstatus1
)) {
4453 r
->out
.rids
->count
= num_alias_rids
;
4454 r
->out
.rids
->ids
= alias_rids
;
4456 return NT_STATUS_OK
;
4459 /*********************************************************************
4460 _samr_GetMembersInAlias
4461 *********************************************************************/
4463 NTSTATUS
_samr_GetMembersInAlias(pipes_struct
*p
,
4464 struct samr_GetMembersInAlias
*r
)
4468 size_t num_sids
= 0;
4469 struct lsa_SidPtr
*sids
= NULL
;
4470 DOM_SID
*pdb_sids
= NULL
;
4476 /* find the policy handle. open a policy on it. */
4477 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &alias_sid
, &acc_granted
, NULL
))
4478 return NT_STATUS_INVALID_HANDLE
;
4480 status
= access_check_samr_function(acc_granted
,
4481 SA_RIGHT_ALIAS_GET_MEMBERS
,
4482 "_samr_GetMembersInAlias");
4483 if (!NT_STATUS_IS_OK(status
)) {
4487 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid
)));
4490 status
= pdb_enum_aliasmem(&alias_sid
, &pdb_sids
, &num_sids
);
4493 if (!NT_STATUS_IS_OK(status
)) {
4498 sids
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, struct lsa_SidPtr
, num_sids
);
4500 TALLOC_FREE(pdb_sids
);
4501 return NT_STATUS_NO_MEMORY
;
4505 for (i
= 0; i
< num_sids
; i
++) {
4506 sids
[i
].sid
= sid_dup_talloc(p
->mem_ctx
, &pdb_sids
[i
]);
4508 TALLOC_FREE(pdb_sids
);
4509 return NT_STATUS_NO_MEMORY
;
4513 r
->out
.sids
->num_sids
= num_sids
;
4514 r
->out
.sids
->sids
= sids
;
4516 TALLOC_FREE(pdb_sids
);
4518 return NT_STATUS_OK
;
4521 /*********************************************************************
4522 _samr_QueryGroupMember
4523 *********************************************************************/
4525 NTSTATUS
_samr_QueryGroupMember(pipes_struct
*p
,
4526 struct samr_QueryGroupMember
*r
)
4529 size_t i
, num_members
;
4537 struct samr_RidTypeArray
*rids
= NULL
;
4539 rids
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_RidTypeArray
);
4541 return NT_STATUS_NO_MEMORY
;
4544 /* find the policy handle. open a policy on it. */
4545 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, NULL
))
4546 return NT_STATUS_INVALID_HANDLE
;
4548 status
= access_check_samr_function(acc_granted
,
4549 SA_RIGHT_GROUP_GET_MEMBERS
,
4550 "_samr_QueryGroupMember");
4551 if (!NT_STATUS_IS_OK(status
)) {
4555 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid
)));
4557 if (!sid_check_is_in_our_domain(&group_sid
)) {
4558 DEBUG(3, ("sid %s is not in our domain\n",
4559 sid_string_dbg(&group_sid
)));
4560 return NT_STATUS_NO_SUCH_GROUP
;
4563 DEBUG(10, ("lookup on Domain SID\n"));
4566 status
= pdb_enum_group_members(p
->mem_ctx
, &group_sid
,
4567 &rid
, &num_members
);
4570 if (!NT_STATUS_IS_OK(status
))
4574 attr
=TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_members
);
4576 return NT_STATUS_NO_MEMORY
;
4582 for (i
=0; i
<num_members
; i
++)
4583 attr
[i
] = SID_NAME_USER
;
4585 rids
->count
= num_members
;
4589 *r
->out
.rids
= rids
;
4591 return NT_STATUS_OK
;
4594 /*********************************************************************
4595 _samr_AddAliasMember
4596 *********************************************************************/
4598 NTSTATUS
_samr_AddAliasMember(pipes_struct
*p
,
4599 struct samr_AddAliasMember
*r
)
4604 bool can_add_accounts
;
4606 DISP_INFO
*disp_info
= NULL
;
4608 /* Find the policy handle. Open a policy on it. */
4609 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &alias_sid
, &acc_granted
, &disp_info
))
4610 return NT_STATUS_INVALID_HANDLE
;
4612 status
= access_check_samr_function(acc_granted
,
4613 SA_RIGHT_ALIAS_ADD_MEMBER
,
4614 "_samr_AddAliasMember");
4615 if (!NT_STATUS_IS_OK(status
)) {
4619 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid
)));
4621 se_priv_copy( &se_rights
, &se_add_users
);
4622 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
4624 /******** BEGIN SeAddUsers BLOCK *********/
4626 if ( can_add_accounts
)
4629 status
= pdb_add_aliasmem(&alias_sid
, r
->in
.sid
);
4631 if ( can_add_accounts
)
4634 /******** END SeAddUsers BLOCK *********/
4636 if (NT_STATUS_IS_OK(status
)) {
4637 force_flush_samr_cache(disp_info
);
4643 /*********************************************************************
4644 _samr_DeleteAliasMember
4645 *********************************************************************/
4647 NTSTATUS
_samr_DeleteAliasMember(pipes_struct
*p
,
4648 struct samr_DeleteAliasMember
*r
)
4653 bool can_add_accounts
;
4655 DISP_INFO
*disp_info
= NULL
;
4657 /* Find the policy handle. Open a policy on it. */
4658 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &alias_sid
, &acc_granted
, &disp_info
))
4659 return NT_STATUS_INVALID_HANDLE
;
4661 status
= access_check_samr_function(acc_granted
,
4662 SA_RIGHT_ALIAS_REMOVE_MEMBER
,
4663 "_samr_DeleteAliasMember");
4664 if (!NT_STATUS_IS_OK(status
)) {
4668 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4669 sid_string_dbg(&alias_sid
)));
4671 se_priv_copy( &se_rights
, &se_add_users
);
4672 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
4674 /******** BEGIN SeAddUsers BLOCK *********/
4676 if ( can_add_accounts
)
4679 status
= pdb_del_aliasmem(&alias_sid
, r
->in
.sid
);
4681 if ( can_add_accounts
)
4684 /******** END SeAddUsers BLOCK *********/
4686 if (NT_STATUS_IS_OK(status
)) {
4687 force_flush_samr_cache(disp_info
);
4693 /*********************************************************************
4694 _samr_AddGroupMember
4695 *********************************************************************/
4697 NTSTATUS
_samr_AddGroupMember(pipes_struct
*p
,
4698 struct samr_AddGroupMember
*r
)
4705 bool can_add_accounts
;
4706 DISP_INFO
*disp_info
= NULL
;
4708 /* Find the policy handle. Open a policy on it. */
4709 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, &disp_info
))
4710 return NT_STATUS_INVALID_HANDLE
;
4712 status
= access_check_samr_function(acc_granted
,
4713 SA_RIGHT_GROUP_ADD_MEMBER
,
4714 "_samr_AddGroupMember");
4715 if (!NT_STATUS_IS_OK(status
)) {
4719 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid
)));
4721 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid
,
4723 return NT_STATUS_INVALID_HANDLE
;
4726 se_priv_copy( &se_rights
, &se_add_users
);
4727 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
4729 /******** BEGIN SeAddUsers BLOCK *********/
4731 if ( can_add_accounts
)
4734 status
= pdb_add_groupmem(p
->mem_ctx
, group_rid
, r
->in
.rid
);
4736 if ( can_add_accounts
)
4739 /******** END SeAddUsers BLOCK *********/
4741 force_flush_samr_cache(disp_info
);
4746 /*********************************************************************
4747 _samr_DeleteGroupMember
4748 *********************************************************************/
4750 NTSTATUS
_samr_DeleteGroupMember(pipes_struct
*p
,
4751 struct samr_DeleteGroupMember
*r
)
4759 bool can_add_accounts
;
4760 DISP_INFO
*disp_info
= NULL
;
4763 * delete the group member named r->in.rid
4764 * who is a member of the sid associated with the handle
4765 * the rid is a user's rid as the group is a domain group.
4768 /* Find the policy handle. Open a policy on it. */
4769 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, &disp_info
))
4770 return NT_STATUS_INVALID_HANDLE
;
4772 status
= access_check_samr_function(acc_granted
,
4773 SA_RIGHT_GROUP_REMOVE_MEMBER
,
4774 "_samr_DeleteGroupMember");
4775 if (!NT_STATUS_IS_OK(status
)) {
4779 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid
,
4781 return NT_STATUS_INVALID_HANDLE
;
4784 se_priv_copy( &se_rights
, &se_add_users
);
4785 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
4787 /******** BEGIN SeAddUsers BLOCK *********/
4789 if ( can_add_accounts
)
4792 status
= pdb_del_groupmem(p
->mem_ctx
, group_rid
, r
->in
.rid
);
4794 if ( can_add_accounts
)
4797 /******** END SeAddUsers BLOCK *********/
4799 force_flush_samr_cache(disp_info
);
4804 /*********************************************************************
4806 *********************************************************************/
4808 NTSTATUS
_samr_DeleteUser(pipes_struct
*p
,
4809 struct samr_DeleteUser
*r
)
4813 struct samu
*sam_pass
=NULL
;
4815 bool can_add_accounts
;
4817 DISP_INFO
*disp_info
= NULL
;
4820 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__
));
4822 /* Find the policy handle. Open a policy on it. */
4823 if (!get_lsa_policy_samr_sid(p
, r
->in
.user_handle
, &user_sid
, &acc_granted
, &disp_info
))
4824 return NT_STATUS_INVALID_HANDLE
;
4826 status
= access_check_samr_function(acc_granted
,
4827 STD_RIGHT_DELETE_ACCESS
,
4828 "_samr_DeleteUser");
4829 if (!NT_STATUS_IS_OK(status
)) {
4833 if (!sid_check_is_in_our_domain(&user_sid
))
4834 return NT_STATUS_CANNOT_DELETE
;
4836 /* check if the user exists before trying to delete */
4837 if ( !(sam_pass
= samu_new( NULL
)) ) {
4838 return NT_STATUS_NO_MEMORY
;
4842 ret
= pdb_getsampwsid(sam_pass
, &user_sid
);
4846 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4847 sid_string_dbg(&user_sid
)));
4848 TALLOC_FREE(sam_pass
);
4849 return NT_STATUS_NO_SUCH_USER
;
4852 acb_info
= pdb_get_acct_ctrl(sam_pass
);
4854 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4855 if ( acb_info
& ACB_WSTRUST
) {
4856 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_machine_account
);
4858 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
4861 /******** BEGIN SeAddUsers BLOCK *********/
4863 if ( can_add_accounts
)
4866 status
= pdb_delete_user(p
->mem_ctx
, sam_pass
);
4868 if ( can_add_accounts
)
4871 /******** END SeAddUsers BLOCK *********/
4873 if ( !NT_STATUS_IS_OK(status
) ) {
4874 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4875 "user %s: %s.\n", pdb_get_username(sam_pass
),
4876 nt_errstr(status
)));
4877 TALLOC_FREE(sam_pass
);
4882 TALLOC_FREE(sam_pass
);
4884 if (!close_policy_hnd(p
, r
->in
.user_handle
))
4885 return NT_STATUS_OBJECT_NAME_INVALID
;
4887 ZERO_STRUCTP(r
->out
.user_handle
);
4889 force_flush_samr_cache(disp_info
);
4891 return NT_STATUS_OK
;
4894 /*********************************************************************
4895 _samr_DeleteDomainGroup
4896 *********************************************************************/
4898 NTSTATUS
_samr_DeleteDomainGroup(pipes_struct
*p
,
4899 struct samr_DeleteDomainGroup
*r
)
4906 bool can_add_accounts
;
4907 DISP_INFO
*disp_info
= NULL
;
4909 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__
));
4911 /* Find the policy handle. Open a policy on it. */
4912 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, &disp_info
))
4913 return NT_STATUS_INVALID_HANDLE
;
4915 status
= access_check_samr_function(acc_granted
,
4916 STD_RIGHT_DELETE_ACCESS
,
4917 "_samr_DeleteDomainGroup");
4918 if (!NT_STATUS_IS_OK(status
)) {
4922 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid
)));
4924 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid
,
4926 return NT_STATUS_NO_SUCH_GROUP
;
4929 se_priv_copy( &se_rights
, &se_add_users
);
4930 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
4932 /******** BEGIN SeAddUsers BLOCK *********/
4934 if ( can_add_accounts
)
4937 status
= pdb_delete_dom_group(p
->mem_ctx
, group_rid
);
4939 if ( can_add_accounts
)
4942 /******** END SeAddUsers BLOCK *********/
4944 if ( !NT_STATUS_IS_OK(status
) ) {
4945 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4946 "entry for group %s: %s\n",
4947 sid_string_dbg(&group_sid
),
4948 nt_errstr(status
)));
4952 if (!close_policy_hnd(p
, r
->in
.group_handle
))
4953 return NT_STATUS_OBJECT_NAME_INVALID
;
4955 force_flush_samr_cache(disp_info
);
4957 return NT_STATUS_OK
;
4960 /*********************************************************************
4961 _samr_DeleteDomAlias
4962 *********************************************************************/
4964 NTSTATUS
_samr_DeleteDomAlias(pipes_struct
*p
,
4965 struct samr_DeleteDomAlias
*r
)
4970 bool can_add_accounts
;
4972 DISP_INFO
*disp_info
= NULL
;
4974 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__
));
4976 /* Find the policy handle. Open a policy on it. */
4977 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &alias_sid
, &acc_granted
, &disp_info
))
4978 return NT_STATUS_INVALID_HANDLE
;
4980 /* copy the handle to the outgoing reply */
4982 memcpy(r
->out
.alias_handle
, r
->in
.alias_handle
, sizeof(r
->out
.alias_handle
));
4984 status
= access_check_samr_function(acc_granted
,
4985 STD_RIGHT_DELETE_ACCESS
,
4986 "_samr_DeleteDomAlias");
4987 if (!NT_STATUS_IS_OK(status
)) {
4991 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid
)));
4993 /* Don't let Windows delete builtin groups */
4995 if ( sid_check_is_in_builtin( &alias_sid
) ) {
4996 return NT_STATUS_SPECIAL_ACCOUNT
;
4999 if (!sid_check_is_in_our_domain(&alias_sid
))
5000 return NT_STATUS_NO_SUCH_ALIAS
;
5002 DEBUG(10, ("lookup on Local SID\n"));
5004 se_priv_copy( &se_rights
, &se_add_users
);
5005 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
5007 /******** BEGIN SeAddUsers BLOCK *********/
5009 if ( can_add_accounts
)
5012 /* Have passdb delete the alias */
5013 status
= pdb_delete_alias(&alias_sid
);
5015 if ( can_add_accounts
)
5018 /******** END SeAddUsers BLOCK *********/
5020 if ( !NT_STATUS_IS_OK(status
))
5023 if (!close_policy_hnd(p
, r
->in
.alias_handle
))
5024 return NT_STATUS_OBJECT_NAME_INVALID
;
5026 force_flush_samr_cache(disp_info
);
5028 return NT_STATUS_OK
;
5031 /*********************************************************************
5032 _samr_CreateDomainGroup
5033 *********************************************************************/
5035 NTSTATUS
_samr_CreateDomainGroup(pipes_struct
*p
,
5036 struct samr_CreateDomainGroup
*r
)
5043 struct samr_info
*info
;
5046 bool can_add_accounts
;
5047 DISP_INFO
*disp_info
= NULL
;
5049 /* Find the policy handle. Open a policy on it. */
5050 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &dom_sid
, &acc_granted
, &disp_info
))
5051 return NT_STATUS_INVALID_HANDLE
;
5053 status
= access_check_samr_function(acc_granted
,
5054 SA_RIGHT_DOMAIN_CREATE_GROUP
,
5055 "_samr_CreateDomainGroup");
5056 if (!NT_STATUS_IS_OK(status
)) {
5060 if (!sid_equal(&dom_sid
, get_global_sam_sid()))
5061 return NT_STATUS_ACCESS_DENIED
;
5063 name
= r
->in
.name
->string
;
5065 return NT_STATUS_NO_MEMORY
;
5068 status
= can_create(p
->mem_ctx
, name
);
5069 if (!NT_STATUS_IS_OK(status
)) {
5073 se_priv_copy( &se_rights
, &se_add_users
);
5074 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
5076 /******** BEGIN SeAddUsers BLOCK *********/
5078 if ( can_add_accounts
)
5081 /* check that we successfully create the UNIX group */
5083 status
= pdb_create_dom_group(p
->mem_ctx
, name
, r
->out
.rid
);
5085 if ( can_add_accounts
)
5088 /******** END SeAddUsers BLOCK *********/
5090 /* check if we should bail out here */
5092 if ( !NT_STATUS_IS_OK(status
) )
5095 sid_compose(&info_sid
, get_global_sam_sid(), *r
->out
.rid
);
5097 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
5098 return NT_STATUS_NO_MEMORY
;
5100 /* they created it; let the user do what he wants with it */
5102 info
->acc_granted
= GENERIC_RIGHTS_GROUP_ALL_ACCESS
;
5104 /* get a (unique) handle. open a policy on it. */
5105 if (!create_policy_hnd(p
, r
->out
.group_handle
, free_samr_info
, (void *)info
))
5106 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5108 force_flush_samr_cache(disp_info
);
5110 return NT_STATUS_OK
;
5113 /*********************************************************************
5114 _samr_CreateDomAlias
5115 *********************************************************************/
5117 NTSTATUS
_samr_CreateDomAlias(pipes_struct
*p
,
5118 struct samr_CreateDomAlias
*r
)
5122 const char *name
= NULL
;
5123 struct samr_info
*info
;
5128 bool can_add_accounts
;
5129 DISP_INFO
*disp_info
= NULL
;
5131 /* Find the policy handle. Open a policy on it. */
5132 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &dom_sid
, &acc_granted
, &disp_info
))
5133 return NT_STATUS_INVALID_HANDLE
;
5135 result
= access_check_samr_function(acc_granted
,
5136 SA_RIGHT_DOMAIN_CREATE_ALIAS
,
5137 "_samr_CreateDomAlias");
5138 if (!NT_STATUS_IS_OK(result
)) {
5142 if (!sid_equal(&dom_sid
, get_global_sam_sid()))
5143 return NT_STATUS_ACCESS_DENIED
;
5145 name
= r
->in
.alias_name
->string
;
5147 se_priv_copy( &se_rights
, &se_add_users
);
5148 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
5150 result
= can_create(p
->mem_ctx
, name
);
5151 if (!NT_STATUS_IS_OK(result
)) {
5155 /******** BEGIN SeAddUsers BLOCK *********/
5157 if ( can_add_accounts
)
5160 /* Have passdb create the alias */
5161 result
= pdb_create_alias(name
, r
->out
.rid
);
5163 if ( can_add_accounts
)
5166 /******** END SeAddUsers BLOCK *********/
5168 if (!NT_STATUS_IS_OK(result
)) {
5169 DEBUG(10, ("pdb_create_alias failed: %s\n",
5170 nt_errstr(result
)));
5174 sid_copy(&info_sid
, get_global_sam_sid());
5175 sid_append_rid(&info_sid
, *r
->out
.rid
);
5177 if (!sid_to_gid(&info_sid
, &gid
)) {
5178 DEBUG(10, ("Could not find alias just created\n"));
5179 return NT_STATUS_ACCESS_DENIED
;
5182 /* check if the group has been successfully created */
5183 if ( getgrgid(gid
) == NULL
) {
5184 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
5186 return NT_STATUS_ACCESS_DENIED
;
5189 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
5190 return NT_STATUS_NO_MEMORY
;
5192 /* they created it; let the user do what he wants with it */
5194 info
->acc_granted
= GENERIC_RIGHTS_ALIAS_ALL_ACCESS
;
5196 /* get a (unique) handle. open a policy on it. */
5197 if (!create_policy_hnd(p
, r
->out
.alias_handle
, free_samr_info
, (void *)info
))
5198 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5200 force_flush_samr_cache(disp_info
);
5202 return NT_STATUS_OK
;
5205 /*********************************************************************
5206 _samr_QueryGroupInfo
5207 *********************************************************************/
5209 NTSTATUS
_samr_QueryGroupInfo(pipes_struct
*p
,
5210 struct samr_QueryGroupInfo
*r
)
5215 union samr_GroupInfo
*info
= NULL
;
5218 uint32_t attributes
= SE_GROUP_MANDATORY
|
5219 SE_GROUP_ENABLED_BY_DEFAULT
|
5221 const char *group_name
= NULL
;
5222 const char *group_description
= NULL
;
5224 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, NULL
))
5225 return NT_STATUS_INVALID_HANDLE
;
5227 status
= access_check_samr_function(acc_granted
,
5228 SA_RIGHT_GROUP_LOOKUP_INFO
,
5229 "_samr_QueryGroupInfo");
5230 if (!NT_STATUS_IS_OK(status
)) {
5235 ret
= get_domain_group_from_sid(group_sid
, &map
);
5238 return NT_STATUS_INVALID_HANDLE
;
5240 /* FIXME: map contains fstrings */
5241 group_name
= talloc_strdup(r
, map
.nt_name
);
5242 group_description
= talloc_strdup(r
, map
.comment
);
5244 info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_GroupInfo
);
5246 return NT_STATUS_NO_MEMORY
;
5249 switch (r
->in
.level
) {
5255 status
= pdb_enum_group_members(
5256 p
->mem_ctx
, &group_sid
, &members
, &num_members
);
5259 if (!NT_STATUS_IS_OK(status
)) {
5263 init_samr_group_info1(&info
->all
,
5271 init_samr_group_info2(&info
->name
,
5275 init_samr_group_info3(&info
->attributes
,
5279 init_samr_group_info4(&info
->description
,
5290 status = pdb_enum_group_members(
5291 p->mem_ctx, &group_sid, &members, &num_members);
5294 if (!NT_STATUS_IS_OK(status)) {
5298 init_samr_group_info5(&info
->all2
,
5301 0, /* num_members - in w2k3 this is always 0 */
5307 return NT_STATUS_INVALID_INFO_CLASS
;
5310 *r
->out
.info
= info
;
5312 return NT_STATUS_OK
;
5315 /*********************************************************************
5317 *********************************************************************/
5319 NTSTATUS
_samr_SetGroupInfo(pipes_struct
*p
,
5320 struct samr_SetGroupInfo
*r
)
5327 bool can_mod_accounts
;
5328 DISP_INFO
*disp_info
= NULL
;
5330 if (!get_lsa_policy_samr_sid(p
, r
->in
.group_handle
, &group_sid
, &acc_granted
, &disp_info
))
5331 return NT_STATUS_INVALID_HANDLE
;
5333 status
= access_check_samr_function(acc_granted
,
5334 SA_RIGHT_GROUP_SET_INFO
,
5335 "_samr_SetGroupInfo");
5336 if (!NT_STATUS_IS_OK(status
)) {
5341 ret
= get_domain_group_from_sid(group_sid
, &map
);
5344 return NT_STATUS_NO_SUCH_GROUP
;
5346 switch (r
->in
.level
) {
5348 fstrcpy(map
.comment
, r
->in
.info
->all
.description
.string
);
5351 fstrcpy(map
.comment
, r
->in
.info
->description
.string
);
5354 return NT_STATUS_INVALID_INFO_CLASS
;
5357 can_mod_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
5359 /******** BEGIN SeAddUsers BLOCK *********/
5361 if ( can_mod_accounts
)
5364 status
= pdb_update_group_mapping_entry(&map
);
5366 if ( can_mod_accounts
)
5369 /******** End SeAddUsers BLOCK *********/
5371 if (NT_STATUS_IS_OK(status
)) {
5372 force_flush_samr_cache(disp_info
);
5378 /*********************************************************************
5380 *********************************************************************/
5382 NTSTATUS
_samr_SetAliasInfo(pipes_struct
*p
,
5383 struct samr_SetAliasInfo
*r
)
5386 struct acct_info info
;
5388 bool can_mod_accounts
;
5390 DISP_INFO
*disp_info
= NULL
;
5392 if (!get_lsa_policy_samr_sid(p
, r
->in
.alias_handle
, &group_sid
, &acc_granted
, &disp_info
))
5393 return NT_STATUS_INVALID_HANDLE
;
5395 status
= access_check_samr_function(acc_granted
,
5396 SA_RIGHT_ALIAS_SET_INFO
,
5397 "_samr_SetAliasInfo");
5398 if (!NT_STATUS_IS_OK(status
)) {
5402 /* get the current group information */
5405 status
= pdb_get_aliasinfo( &group_sid
, &info
);
5408 if ( !NT_STATUS_IS_OK(status
))
5411 switch (r
->in
.level
) {
5416 /* We currently do not support renaming groups in the
5417 the BUILTIN domain. Refer to util_builtin.c to understand
5418 why. The eventually needs to be fixed to be like Windows
5419 where you can rename builtin groups, just not delete them */
5421 if ( sid_check_is_in_builtin( &group_sid
) ) {
5422 return NT_STATUS_SPECIAL_ACCOUNT
;
5425 /* There has to be a valid name (and it has to be different) */
5427 if ( !r
->in
.info
->name
.string
)
5428 return NT_STATUS_INVALID_PARAMETER
;
5430 /* If the name is the same just reply "ok". Yes this
5431 doesn't allow you to change the case of a group name. */
5433 if ( strequal( r
->in
.info
->name
.string
, info
.acct_name
) )
5434 return NT_STATUS_OK
;
5436 fstrcpy( info
.acct_name
, r
->in
.info
->name
.string
);
5438 /* make sure the name doesn't already exist as a user
5441 fstr_sprintf( group_name
, "%s\\%s", global_myname(), info
.acct_name
);
5442 status
= can_create( p
->mem_ctx
, group_name
);
5443 if ( !NT_STATUS_IS_OK( status
) )
5447 case ALIASINFODESCRIPTION
:
5448 if (r
->in
.info
->description
.string
) {
5449 fstrcpy(info
.acct_desc
,
5450 r
->in
.info
->description
.string
);
5452 fstrcpy( info
.acct_desc
, "" );
5456 return NT_STATUS_INVALID_INFO_CLASS
;
5459 can_mod_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
5461 /******** BEGIN SeAddUsers BLOCK *********/
5463 if ( can_mod_accounts
)
5466 status
= pdb_set_aliasinfo( &group_sid
, &info
);
5468 if ( can_mod_accounts
)
5471 /******** End SeAddUsers BLOCK *********/
5473 if (NT_STATUS_IS_OK(status
))
5474 force_flush_samr_cache(disp_info
);
5479 /****************************************************************
5481 ****************************************************************/
5483 NTSTATUS
_samr_GetDomPwInfo(pipes_struct
*p
,
5484 struct samr_GetDomPwInfo
*r
)
5486 uint32_t min_password_length
= 0;
5487 uint32_t password_properties
= 0;
5489 /* Perform access check. Since this rpc does not require a
5490 policy handle it will not be caught by the access checks on
5491 SAMR_CONNECT or SAMR_CONNECT_ANON. */
5493 if (!pipe_access_check(p
)) {
5494 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
5495 return NT_STATUS_ACCESS_DENIED
;
5499 pdb_get_account_policy(AP_MIN_PASSWORD_LEN
,
5500 &min_password_length
);
5501 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS
,
5502 &password_properties
);
5505 if (lp_check_password_script() && *lp_check_password_script()) {
5506 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
5509 r
->out
.info
->min_password_length
= min_password_length
;
5510 r
->out
.info
->password_properties
= password_properties
;
5512 return NT_STATUS_OK
;
5515 /*********************************************************************
5517 *********************************************************************/
5519 NTSTATUS
_samr_OpenGroup(pipes_struct
*p
,
5520 struct samr_OpenGroup
*r
)
5526 struct samr_info
*info
;
5527 SEC_DESC
*psd
= NULL
;
5529 uint32 des_access
= r
->in
.access_mask
;
5536 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &sid
, &acc_granted
, NULL
))
5537 return NT_STATUS_INVALID_HANDLE
;
5539 status
= access_check_samr_function(acc_granted
,
5540 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
,
5543 if ( !NT_STATUS_IS_OK(status
) )
5546 /*check if access can be granted as requested by client. */
5547 map_max_allowed_access(p
->pipe_user
.nt_user_token
, &des_access
);
5549 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &grp_generic_mapping
, NULL
, 0);
5550 se_map_generic(&des_access
,&grp_generic_mapping
);
5552 se_priv_copy( &se_rights
, &se_add_users
);
5554 status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
5555 &se_rights
, GENERIC_RIGHTS_GROUP_WRITE
, des_access
,
5556 &acc_granted
, "_samr_OpenGroup");
5558 if ( !NT_STATUS_IS_OK(status
) )
5561 /* this should not be hard-coded like this */
5563 if (!sid_equal(&sid
, get_global_sam_sid()))
5564 return NT_STATUS_ACCESS_DENIED
;
5566 sid_copy(&info_sid
, get_global_sam_sid());
5567 sid_append_rid(&info_sid
, r
->in
.rid
);
5568 sid_to_fstring(sid_string
, &info_sid
);
5570 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
5571 return NT_STATUS_NO_MEMORY
;
5573 info
->acc_granted
= acc_granted
;
5575 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string
));
5577 /* check if that group really exists */
5579 ret
= get_domain_group_from_sid(info
->sid
, &map
);
5582 return NT_STATUS_NO_SUCH_GROUP
;
5584 /* get a (unique) handle. open a policy on it. */
5585 if (!create_policy_hnd(p
, r
->out
.group_handle
, free_samr_info
, (void *)info
))
5586 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5588 return NT_STATUS_OK
;
5591 /*********************************************************************
5592 _samr_RemoveMemberFromForeignDomain
5593 *********************************************************************/
5595 NTSTATUS
_samr_RemoveMemberFromForeignDomain(pipes_struct
*p
,
5596 struct samr_RemoveMemberFromForeignDomain
*r
)
5598 DOM_SID delete_sid
, domain_sid
;
5601 DISP_INFO
*disp_info
= NULL
;
5603 sid_copy( &delete_sid
, r
->in
.sid
);
5605 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
5606 sid_string_dbg(&delete_sid
)));
5608 /* Find the policy handle. Open a policy on it. */
5610 if (!get_lsa_policy_samr_sid(p
, r
->in
.domain_handle
, &domain_sid
,
5611 &acc_granted
, &disp_info
))
5612 return NT_STATUS_INVALID_HANDLE
;
5614 result
= access_check_samr_function(acc_granted
,
5615 STD_RIGHT_DELETE_ACCESS
,
5616 "_samr_RemoveMemberFromForeignDomain");
5618 if (!NT_STATUS_IS_OK(result
))
5621 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
5622 sid_string_dbg(&domain_sid
)));
5624 /* we can only delete a user from a group since we don't have
5625 nested groups anyways. So in the latter case, just say OK */
5627 /* TODO: The above comment nowadays is bogus. Since we have nested
5628 * groups now, and aliases members are never reported out of the unix
5629 * group membership, the "just say OK" makes this call a no-op. For
5630 * us. This needs fixing however. */
5632 /* I've only ever seen this in the wild when deleting a user from
5633 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
5634 * is the user about to be deleted. I very much suspect this is the
5635 * only application of this call. To verify this, let people report
5638 if (!sid_check_is_builtin(&domain_sid
)) {
5639 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
5640 "global_sam_sid() = %s\n",
5641 sid_string_dbg(&domain_sid
),
5642 sid_string_dbg(get_global_sam_sid())));
5643 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
5644 return NT_STATUS_OK
;
5647 force_flush_samr_cache(disp_info
);
5649 result
= NT_STATUS_OK
;
5654 /*******************************************************************
5655 _samr_QueryDomainInfo2
5656 ********************************************************************/
5658 NTSTATUS
_samr_QueryDomainInfo2(pipes_struct
*p
,
5659 struct samr_QueryDomainInfo2
*r
)
5661 struct samr_QueryDomainInfo q
;
5663 q
.in
.domain_handle
= r
->in
.domain_handle
;
5664 q
.in
.level
= r
->in
.level
;
5666 q
.out
.info
= r
->out
.info
;
5668 return _samr_QueryDomainInfo(p
, &q
);
5671 /*******************************************************************
5673 ********************************************************************/
5675 NTSTATUS
_samr_SetDomainInfo(pipes_struct
*p
,
5676 struct samr_SetDomainInfo
*r
)
5678 struct samr_info
*info
= NULL
;
5679 time_t u_expire
, u_min_age
;
5681 time_t u_lock_duration
, u_reset_time
;
5684 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__
));
5686 /* find the policy handle. open a policy on it. */
5687 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
))
5688 return NT_STATUS_INVALID_HANDLE
;
5690 /* We do have different access bits for info
5691 * levels here, but we're really just looking for
5692 * GENERIC_RIGHTS_DOMAIN_WRITE access. Unfortunately
5693 * this maps to different specific bits. So
5694 * assume if we have SA_RIGHT_DOMAIN_SET_INFO_1
5697 result
= access_check_samr_function(info
->acc_granted
,
5698 SA_RIGHT_DOMAIN_SET_INFO_1
,
5699 "_samr_SetDomainInfo");
5701 if (!NT_STATUS_IS_OK(result
))
5704 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r
->in
.level
));
5706 switch (r
->in
.level
) {
5708 u_expire
=nt_time_to_unix_abs((NTTIME
*)&r
->in
.info
->info1
.max_password_age
);
5709 u_min_age
=nt_time_to_unix_abs((NTTIME
*)&r
->in
.info
->info1
.min_password_age
);
5710 pdb_set_account_policy(AP_MIN_PASSWORD_LEN
, (uint32
)r
->in
.info
->info1
.min_password_length
);
5711 pdb_set_account_policy(AP_PASSWORD_HISTORY
, (uint32
)r
->in
.info
->info1
.password_history_length
);
5712 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS
, (uint32
)r
->in
.info
->info1
.password_properties
);
5713 pdb_set_account_policy(AP_MAX_PASSWORD_AGE
, (int)u_expire
);
5714 pdb_set_account_policy(AP_MIN_PASSWORD_AGE
, (int)u_min_age
);
5719 u_logout
=nt_time_to_unix_abs((NTTIME
*)&r
->in
.info
->info3
.force_logoff_time
);
5720 pdb_set_account_policy(AP_TIME_TO_LOGOUT
, (int)u_logout
);
5729 u_lock_duration
=nt_time_to_unix_abs((NTTIME
*)&r
->in
.info
->info12
.lockout_duration
);
5730 if (u_lock_duration
!= -1)
5731 u_lock_duration
/= 60;
5733 u_reset_time
=nt_time_to_unix_abs((NTTIME
*)&r
->in
.info
->info12
.lockout_window
)/60;
5735 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION
, (int)u_lock_duration
);
5736 pdb_set_account_policy(AP_RESET_COUNT_TIME
, (int)u_reset_time
);
5737 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT
, (uint32
)r
->in
.info
->info12
.lockout_threshold
);
5740 return NT_STATUS_INVALID_INFO_CLASS
;
5743 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__
));
5745 return NT_STATUS_OK
;
5748 /****************************************************************
5749 _samr_GetDisplayEnumerationIndex
5750 ****************************************************************/
5752 NTSTATUS
_samr_GetDisplayEnumerationIndex(pipes_struct
*p
,
5753 struct samr_GetDisplayEnumerationIndex
*r
)
5755 struct samr_info
*info
= NULL
;
5756 uint32_t max_entries
= (uint32_t) -1;
5757 uint32_t enum_context
= 0;
5759 uint32_t num_account
= 0;
5760 struct samr_displayentry
*entries
= NULL
;
5763 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__
));
5765 /* find the policy handle. open a policy on it. */
5766 if (!find_policy_by_hnd(p
, r
->in
.domain_handle
, (void **)(void *)&info
)) {
5767 return NT_STATUS_INVALID_HANDLE
;
5770 status
= access_check_samr_function(info
->acc_granted
,
5771 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
5772 "_samr_GetDisplayEnumerationIndex");
5773 if (!NT_STATUS_IS_OK(status
)) {
5777 if ((r
->in
.level
< 1) || (r
->in
.level
> 3)) {
5778 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
5779 "Unknown info level (%u)\n",
5781 return NT_STATUS_INVALID_INFO_CLASS
;
5786 /* The following done as ROOT. Don't return without unbecome_root(). */
5788 switch (r
->in
.level
) {
5790 if (info
->disp_info
->users
== NULL
) {
5791 info
->disp_info
->users
= pdb_search_users(ACB_NORMAL
);
5792 if (info
->disp_info
->users
== NULL
) {
5794 return NT_STATUS_ACCESS_DENIED
;
5796 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5797 "starting user enumeration at index %u\n",
5798 (unsigned int)enum_context
));
5800 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5801 "using cached user enumeration at index %u\n",
5802 (unsigned int)enum_context
));
5804 num_account
= pdb_search_entries(info
->disp_info
->users
,
5805 enum_context
, max_entries
,
5809 if (info
->disp_info
->machines
== NULL
) {
5810 info
->disp_info
->machines
=
5811 pdb_search_users(ACB_WSTRUST
|ACB_SVRTRUST
);
5812 if (info
->disp_info
->machines
== NULL
) {
5814 return NT_STATUS_ACCESS_DENIED
;
5816 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5817 "starting machine enumeration at index %u\n",
5818 (unsigned int)enum_context
));
5820 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5821 "using cached machine enumeration at index %u\n",
5822 (unsigned int)enum_context
));
5824 num_account
= pdb_search_entries(info
->disp_info
->machines
,
5825 enum_context
, max_entries
,
5829 if (info
->disp_info
->groups
== NULL
) {
5830 info
->disp_info
->groups
= pdb_search_groups();
5831 if (info
->disp_info
->groups
== NULL
) {
5833 return NT_STATUS_ACCESS_DENIED
;
5835 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5836 "starting group enumeration at index %u\n",
5837 (unsigned int)enum_context
));
5839 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5840 "using cached group enumeration at index %u\n",
5841 (unsigned int)enum_context
));
5843 num_account
= pdb_search_entries(info
->disp_info
->groups
,
5844 enum_context
, max_entries
,
5849 smb_panic("info class changed");
5855 /* Ensure we cache this enumeration. */
5856 set_disp_info_cache_timeout(info
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
5858 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
5859 r
->in
.name
->string
));
5861 for (i
=0; i
<num_account
; i
++) {
5862 if (strequal(entries
[i
].account_name
, r
->in
.name
->string
)) {
5863 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
5864 "found %s at idx %d\n",
5865 r
->in
.name
->string
, i
));
5867 return NT_STATUS_OK
;
5871 /* assuming account_name lives at the very end */
5872 *r
->out
.idx
= num_account
;
5874 return NT_STATUS_NO_MORE_ENTRIES
;
5877 /****************************************************************
5878 _samr_GetDisplayEnumerationIndex2
5879 ****************************************************************/
5881 NTSTATUS
_samr_GetDisplayEnumerationIndex2(pipes_struct
*p
,
5882 struct samr_GetDisplayEnumerationIndex2
*r
)
5884 struct samr_GetDisplayEnumerationIndex q
;
5886 q
.in
.domain_handle
= r
->in
.domain_handle
;
5887 q
.in
.level
= r
->in
.level
;
5888 q
.in
.name
= r
->in
.name
;
5890 q
.out
.idx
= r
->out
.idx
;
5892 return _samr_GetDisplayEnumerationIndex(p
, &q
);
5895 /****************************************************************
5896 ****************************************************************/
5898 NTSTATUS
_samr_Shutdown(pipes_struct
*p
,
5899 struct samr_Shutdown
*r
)
5901 p
->rng_fault_state
= true;
5902 return NT_STATUS_NOT_IMPLEMENTED
;
5905 /****************************************************************
5906 ****************************************************************/
5908 NTSTATUS
_samr_CreateUser(pipes_struct
*p
,
5909 struct samr_CreateUser
*r
)
5911 p
->rng_fault_state
= true;
5912 return NT_STATUS_NOT_IMPLEMENTED
;
5915 /****************************************************************
5916 ****************************************************************/
5918 NTSTATUS
_samr_SetMemberAttributesOfGroup(pipes_struct
*p
,
5919 struct samr_SetMemberAttributesOfGroup
*r
)
5921 p
->rng_fault_state
= true;
5922 return NT_STATUS_NOT_IMPLEMENTED
;
5925 /****************************************************************
5926 ****************************************************************/
5928 NTSTATUS
_samr_ChangePasswordUser(pipes_struct
*p
,
5929 struct samr_ChangePasswordUser
*r
)
5931 p
->rng_fault_state
= true;
5932 return NT_STATUS_NOT_IMPLEMENTED
;
5935 /****************************************************************
5936 ****************************************************************/
5938 NTSTATUS
_samr_TestPrivateFunctionsDomain(pipes_struct
*p
,
5939 struct samr_TestPrivateFunctionsDomain
*r
)
5941 p
->rng_fault_state
= true;
5942 return NT_STATUS_NOT_IMPLEMENTED
;
5945 /****************************************************************
5946 ****************************************************************/
5948 NTSTATUS
_samr_TestPrivateFunctionsUser(pipes_struct
*p
,
5949 struct samr_TestPrivateFunctionsUser
*r
)
5951 p
->rng_fault_state
= true;
5952 return NT_STATUS_NOT_IMPLEMENTED
;
5955 /****************************************************************
5956 ****************************************************************/
5958 NTSTATUS
_samr_QueryUserInfo2(pipes_struct
*p
,
5959 struct samr_QueryUserInfo2
*r
)
5961 p
->rng_fault_state
= true;
5962 return NT_STATUS_NOT_IMPLEMENTED
;
5965 /****************************************************************
5966 ****************************************************************/
5968 NTSTATUS
_samr_AddMultipleMembersToAlias(pipes_struct
*p
,
5969 struct samr_AddMultipleMembersToAlias
*r
)
5971 p
->rng_fault_state
= true;
5972 return NT_STATUS_NOT_IMPLEMENTED
;
5975 /****************************************************************
5976 ****************************************************************/
5978 NTSTATUS
_samr_RemoveMultipleMembersFromAlias(pipes_struct
*p
,
5979 struct samr_RemoveMultipleMembersFromAlias
*r
)
5981 p
->rng_fault_state
= true;
5982 return NT_STATUS_NOT_IMPLEMENTED
;
5985 /****************************************************************
5986 ****************************************************************/
5988 NTSTATUS
_samr_OemChangePasswordUser2(pipes_struct
*p
,
5989 struct samr_OemChangePasswordUser2
*r
)
5991 p
->rng_fault_state
= true;
5992 return NT_STATUS_NOT_IMPLEMENTED
;
5995 /****************************************************************
5996 ****************************************************************/
5998 NTSTATUS
_samr_SetBootKeyInformation(pipes_struct
*p
,
5999 struct samr_SetBootKeyInformation
*r
)
6001 p
->rng_fault_state
= true;
6002 return NT_STATUS_NOT_IMPLEMENTED
;
6005 /****************************************************************
6006 ****************************************************************/
6008 NTSTATUS
_samr_GetBootKeyInformation(pipes_struct
*p
,
6009 struct samr_GetBootKeyInformation
*r
)
6011 p
->rng_fault_state
= true;
6012 return NT_STATUS_NOT_IMPLEMENTED
;
6015 /****************************************************************
6016 ****************************************************************/
6018 NTSTATUS
_samr_Connect3(pipes_struct
*p
,
6019 struct samr_Connect3
*r
)
6021 p
->rng_fault_state
= true;
6022 return NT_STATUS_NOT_IMPLEMENTED
;
6025 /****************************************************************
6026 ****************************************************************/
6028 NTSTATUS
_samr_RidToSid(pipes_struct
*p
,
6029 struct samr_RidToSid
*r
)
6031 p
->rng_fault_state
= true;
6032 return NT_STATUS_NOT_IMPLEMENTED
;
6035 /****************************************************************
6036 ****************************************************************/
6038 NTSTATUS
_samr_SetDsrmPassword(pipes_struct
*p
,
6039 struct samr_SetDsrmPassword
*r
)
6041 p
->rng_fault_state
= true;
6042 return NT_STATUS_NOT_IMPLEMENTED
;
6045 /****************************************************************
6046 ****************************************************************/
6048 NTSTATUS
_samr_ValidatePassword(pipes_struct
*p
,
6049 struct samr_ValidatePassword
*r
)
6051 p
->rng_fault_state
= true;
6052 return NT_STATUS_NOT_IMPLEMENTED
;