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.
35 #include "smbd/globals.h"
36 #include "../libcli/auth/libcli_auth.h"
37 #include "../librpc/gen_ndr/srv_samr.h"
38 #include "rpc_server/srv_samr_util.h"
39 #include "../lib/crypto/arcfour.h"
43 #define DBGC_CLASS DBGC_RPC_SRV
45 #define SAMR_USR_RIGHTS_WRITE_PW \
46 ( READ_CONTROL_ACCESS | \
47 SAMR_USER_ACCESS_CHANGE_PASSWORD | \
48 SAMR_USER_ACCESS_SET_LOC_COM)
49 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
50 ( READ_CONTROL_ACCESS | SAMR_USER_ACCESS_SET_LOC_COM )
52 #define DISP_INFO_CACHE_TIMEOUT 10
54 #define MAX_SAM_ENTRIES_W2K 0x400 /* 1024 */
55 #define MAX_SAM_ENTRIES_W95 50
57 struct samr_connect_info
{
61 struct samr_domain_info
{
63 struct disp_info
*disp_info
;
66 struct samr_user_info
{
70 struct samr_group_info
{
74 struct samr_alias_info
{
78 typedef struct disp_info
{
79 struct dom_sid sid
; /* identify which domain this is. */
80 struct pdb_search
*users
; /* querydispinfo 1 and 4 */
81 struct pdb_search
*machines
; /* querydispinfo 2 */
82 struct pdb_search
*groups
; /* querydispinfo 3 and 5, enumgroups */
83 struct pdb_search
*aliases
; /* enumaliases */
85 uint32_t enum_acb_mask
;
86 struct pdb_search
*enum_users
; /* enumusers with a mask */
88 struct timed_event
*cache_timeout_event
; /* cache idle timeout
92 static const struct generic_mapping sam_generic_mapping
= {
93 GENERIC_RIGHTS_SAM_READ
,
94 GENERIC_RIGHTS_SAM_WRITE
,
95 GENERIC_RIGHTS_SAM_EXECUTE
,
96 GENERIC_RIGHTS_SAM_ALL_ACCESS
};
97 static const struct generic_mapping dom_generic_mapping
= {
98 GENERIC_RIGHTS_DOMAIN_READ
,
99 GENERIC_RIGHTS_DOMAIN_WRITE
,
100 GENERIC_RIGHTS_DOMAIN_EXECUTE
,
101 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS
};
102 static const struct generic_mapping usr_generic_mapping
= {
103 GENERIC_RIGHTS_USER_READ
,
104 GENERIC_RIGHTS_USER_WRITE
,
105 GENERIC_RIGHTS_USER_EXECUTE
,
106 GENERIC_RIGHTS_USER_ALL_ACCESS
};
107 static const struct generic_mapping usr_nopwchange_generic_mapping
= {
108 GENERIC_RIGHTS_USER_READ
,
109 GENERIC_RIGHTS_USER_WRITE
,
110 GENERIC_RIGHTS_USER_EXECUTE
& ~SAMR_USER_ACCESS_CHANGE_PASSWORD
,
111 GENERIC_RIGHTS_USER_ALL_ACCESS
};
112 static const struct generic_mapping grp_generic_mapping
= {
113 GENERIC_RIGHTS_GROUP_READ
,
114 GENERIC_RIGHTS_GROUP_WRITE
,
115 GENERIC_RIGHTS_GROUP_EXECUTE
,
116 GENERIC_RIGHTS_GROUP_ALL_ACCESS
};
117 static const struct generic_mapping ali_generic_mapping
= {
118 GENERIC_RIGHTS_ALIAS_READ
,
119 GENERIC_RIGHTS_ALIAS_WRITE
,
120 GENERIC_RIGHTS_ALIAS_EXECUTE
,
121 GENERIC_RIGHTS_ALIAS_ALL_ACCESS
};
123 /*******************************************************************
124 *******************************************************************/
126 static NTSTATUS
make_samr_object_sd( TALLOC_CTX
*ctx
, struct security_descriptor
**psd
, size_t *sd_size
,
127 const struct generic_mapping
*map
,
128 struct dom_sid
*sid
, uint32 sid_access
)
130 struct dom_sid domadmin_sid
;
131 struct security_ace ace
[5]; /* at most 5 entries */
134 struct security_acl
*psa
= NULL
;
136 /* basic access for Everyone */
138 init_sec_ace(&ace
[i
++], &global_sid_World
, SEC_ACE_TYPE_ACCESS_ALLOWED
,
139 map
->generic_execute
| map
->generic_read
, 0);
141 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
143 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
,
144 SEC_ACE_TYPE_ACCESS_ALLOWED
, map
->generic_all
, 0);
145 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Account_Operators
,
146 SEC_ACE_TYPE_ACCESS_ALLOWED
, map
->generic_all
, 0);
148 /* Add Full Access for Domain Admins if we are a DC */
151 sid_compose(&domadmin_sid
, get_global_sam_sid(),
153 init_sec_ace(&ace
[i
++], &domadmin_sid
,
154 SEC_ACE_TYPE_ACCESS_ALLOWED
, map
->generic_all
, 0);
157 /* if we have a sid, give it some special access */
160 init_sec_ace(&ace
[i
++], sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
, sid_access
, 0);
163 /* create the security descriptor */
165 if ((psa
= make_sec_acl(ctx
, NT4_ACL_REVISION
, i
, ace
)) == NULL
)
166 return NT_STATUS_NO_MEMORY
;
168 if ((*psd
= make_sec_desc(ctx
, SECURITY_DESCRIPTOR_REVISION_1
,
169 SEC_DESC_SELF_RELATIVE
, NULL
, NULL
, NULL
,
170 psa
, sd_size
)) == NULL
)
171 return NT_STATUS_NO_MEMORY
;
176 /*******************************************************************
177 Checks if access to an object should be granted, and returns that
178 level of access for further checks.
179 ********************************************************************/
181 NTSTATUS
access_check_object( struct security_descriptor
*psd
, NT_USER_TOKEN
*token
,
182 SE_PRIV
*rights
, uint32 rights_mask
,
183 uint32 des_access
, uint32
*acc_granted
,
186 NTSTATUS status
= NT_STATUS_ACCESS_DENIED
;
187 uint32 saved_mask
= 0;
189 /* check privileges; certain SAM access bits should be overridden
190 by privileges (mostly having to do with creating/modifying/deleting
193 if (rights
&& !se_priv_equal(rights
, &se_priv_none
) &&
194 user_has_any_privilege(token
, rights
)) {
196 saved_mask
= (des_access
& rights_mask
);
197 des_access
&= ~saved_mask
;
199 DEBUG(4,("access_check_object: user rights access mask [0x%x]\n",
204 /* check the security descriptor first */
206 status
= se_access_check(psd
, token
, des_access
, acc_granted
);
207 if (NT_STATUS_IS_OK(status
)) {
211 /* give root a free pass */
213 if ( geteuid() == sec_initial_uid() ) {
215 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug
, des_access
));
216 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
218 *acc_granted
= des_access
;
220 status
= NT_STATUS_OK
;
226 /* add in any bits saved during the privilege check (only
227 matters is status is ok) */
229 *acc_granted
|= rights_mask
;
231 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
232 debug
, NT_STATUS_IS_OK(status
) ? "GRANTED" : "DENIED",
233 des_access
, *acc_granted
));
239 /*******************************************************************
240 Map any MAXIMUM_ALLOWED_ACCESS request to a valid access set.
241 ********************************************************************/
243 void map_max_allowed_access(const NT_USER_TOKEN
*nt_token
,
244 const struct unix_user_token
*unix_token
,
245 uint32_t *pacc_requested
)
247 if (!((*pacc_requested
) & MAXIMUM_ALLOWED_ACCESS
)) {
250 *pacc_requested
&= ~MAXIMUM_ALLOWED_ACCESS
;
252 /* At least try for generic read|execute - Everyone gets that. */
253 *pacc_requested
= GENERIC_READ_ACCESS
|GENERIC_EXECUTE_ACCESS
;
255 /* root gets anything. */
256 if (unix_token
->uid
== sec_initial_uid()) {
257 *pacc_requested
|= GENERIC_ALL_ACCESS
;
261 /* Full Access for 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
263 if (is_sid_in_token(nt_token
, &global_sid_Builtin_Administrators
) ||
264 is_sid_in_token(nt_token
, &global_sid_Builtin_Account_Operators
)) {
265 *pacc_requested
|= GENERIC_ALL_ACCESS
;
269 /* Full access for DOMAIN\Domain Admins. */
271 struct dom_sid domadmin_sid
;
272 sid_compose(&domadmin_sid
, get_global_sam_sid(),
274 if (is_sid_in_token(nt_token
, &domadmin_sid
)) {
275 *pacc_requested
|= GENERIC_ALL_ACCESS
;
279 /* TODO ! Check privileges. */
282 /*******************************************************************
283 Fetch or create a dispinfo struct.
284 ********************************************************************/
286 static DISP_INFO
*get_samr_dispinfo_by_sid(const struct dom_sid
*psid
)
289 * We do a static cache for DISP_INFO's here. Explanation can be found
290 * in Jeremy's checkin message to r11793:
292 * Fix the SAMR cache so it works across completely insane
293 * client behaviour (ie.:
294 * open pipe/open SAMR handle/enumerate 0 - 1024
295 * close SAMR handle, close pipe.
296 * open pipe/open SAMR handle/enumerate 1024 - 2048...
297 * close SAMR handle, close pipe.
298 * And on ad-nausium. Amazing.... probably object-oriented
299 * client side programming in action yet again.
300 * This change should *massively* improve performance when
301 * enumerating users from an LDAP database.
304 * "Our" and the builtin domain are the only ones where we ever
305 * enumerate stuff, so just cache 2 entries.
308 static struct disp_info
*builtin_dispinfo
;
309 static struct disp_info
*domain_dispinfo
;
311 /* There are two cases to consider here:
312 1) The SID is a domain SID and we look for an equality match, or
313 2) This is an account SID and so we return the DISP_INFO* for our
320 if (sid_check_is_builtin(psid
) || sid_check_is_in_builtin(psid
)) {
322 * Necessary only once, but it does not really hurt.
324 if (builtin_dispinfo
== NULL
) {
325 builtin_dispinfo
= talloc_zero(
326 talloc_autofree_context(), struct disp_info
);
327 if (builtin_dispinfo
== NULL
) {
331 sid_copy(&builtin_dispinfo
->sid
, &global_sid_Builtin
);
333 return builtin_dispinfo
;
336 if (sid_check_is_domain(psid
) || sid_check_is_in_our_domain(psid
)) {
338 * Necessary only once, but it does not really hurt.
340 if (domain_dispinfo
== NULL
) {
341 domain_dispinfo
= talloc_zero(
342 talloc_autofree_context(), struct disp_info
);
343 if (domain_dispinfo
== NULL
) {
347 sid_copy(&domain_dispinfo
->sid
, get_global_sam_sid());
349 return domain_dispinfo
;
355 /*******************************************************************
356 Function to free the per SID data.
357 ********************************************************************/
359 static void free_samr_cache(DISP_INFO
*disp_info
)
361 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
362 sid_string_dbg(&disp_info
->sid
)));
364 /* We need to become root here because the paged search might have to
365 * tell the LDAP server we're not interested in the rest anymore. */
369 TALLOC_FREE(disp_info
->users
);
370 TALLOC_FREE(disp_info
->machines
);
371 TALLOC_FREE(disp_info
->groups
);
372 TALLOC_FREE(disp_info
->aliases
);
373 TALLOC_FREE(disp_info
->enum_users
);
378 /*******************************************************************
379 Idle event handler. Throw away the disp info cache.
380 ********************************************************************/
382 static void disp_info_cache_idle_timeout_handler(struct event_context
*ev_ctx
,
383 struct timed_event
*te
,
387 DISP_INFO
*disp_info
= (DISP_INFO
*)private_data
;
389 TALLOC_FREE(disp_info
->cache_timeout_event
);
391 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
393 free_samr_cache(disp_info
);
396 /*******************************************************************
397 Setup cache removal idle event handler.
398 ********************************************************************/
400 static void set_disp_info_cache_timeout(DISP_INFO
*disp_info
, time_t secs_fromnow
)
402 /* Remove any pending timeout and update. */
404 TALLOC_FREE(disp_info
->cache_timeout_event
);
406 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
407 "SID %s for %u seconds\n", sid_string_dbg(&disp_info
->sid
),
408 (unsigned int)secs_fromnow
));
410 disp_info
->cache_timeout_event
= event_add_timed(
411 server_event_context(), NULL
,
412 timeval_current_ofs(secs_fromnow
, 0),
413 disp_info_cache_idle_timeout_handler
, (void *)disp_info
);
416 /*******************************************************************
417 Force flush any cache. We do this on any samr_set_xxx call.
418 We must also remove the timeout handler.
419 ********************************************************************/
421 static void force_flush_samr_cache(const struct dom_sid
*sid
)
423 struct disp_info
*disp_info
= get_samr_dispinfo_by_sid(sid
);
425 if ((disp_info
== NULL
) || (disp_info
->cache_timeout_event
== NULL
)) {
429 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
430 TALLOC_FREE(disp_info
->cache_timeout_event
);
431 free_samr_cache(disp_info
);
434 /*******************************************************************
435 Ensure password info is never given out. Paranioa... JRA.
436 ********************************************************************/
438 static void samr_clear_sam_passwd(struct samu
*sam_pass
)
444 /* These now zero out the old password */
446 pdb_set_lanman_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
447 pdb_set_nt_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
450 static uint32
count_sam_users(struct disp_info
*info
, uint32 acct_flags
)
452 struct samr_displayentry
*entry
;
454 if (sid_check_is_builtin(&info
->sid
)) {
455 /* No users in builtin. */
459 if (info
->users
== NULL
) {
460 info
->users
= pdb_search_users(info
, acct_flags
);
461 if (info
->users
== NULL
) {
465 /* Fetch the last possible entry, thus trigger an enumeration */
466 pdb_search_entries(info
->users
, 0xffffffff, 1, &entry
);
468 /* Ensure we cache this enumeration. */
469 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
471 return info
->users
->num_entries
;
474 static uint32
count_sam_groups(struct disp_info
*info
)
476 struct samr_displayentry
*entry
;
478 if (sid_check_is_builtin(&info
->sid
)) {
479 /* No groups in builtin. */
483 if (info
->groups
== NULL
) {
484 info
->groups
= pdb_search_groups(info
);
485 if (info
->groups
== NULL
) {
489 /* Fetch the last possible entry, thus trigger an enumeration */
490 pdb_search_entries(info
->groups
, 0xffffffff, 1, &entry
);
492 /* Ensure we cache this enumeration. */
493 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
495 return info
->groups
->num_entries
;
498 static uint32
count_sam_aliases(struct disp_info
*info
)
500 struct samr_displayentry
*entry
;
502 if (info
->aliases
== NULL
) {
503 info
->aliases
= pdb_search_aliases(info
, &info
->sid
);
504 if (info
->aliases
== NULL
) {
508 /* Fetch the last possible entry, thus trigger an enumeration */
509 pdb_search_entries(info
->aliases
, 0xffffffff, 1, &entry
);
511 /* Ensure we cache this enumeration. */
512 set_disp_info_cache_timeout(info
, DISP_INFO_CACHE_TIMEOUT
);
514 return info
->aliases
->num_entries
;
517 /*******************************************************************
519 ********************************************************************/
521 NTSTATUS
_samr_Close(struct pipes_struct
*p
, struct samr_Close
*r
)
523 if (!close_policy_hnd(p
, r
->in
.handle
)) {
524 return NT_STATUS_INVALID_HANDLE
;
527 ZERO_STRUCTP(r
->out
.handle
);
532 /*******************************************************************
534 ********************************************************************/
536 NTSTATUS
_samr_OpenDomain(struct pipes_struct
*p
,
537 struct samr_OpenDomain
*r
)
539 struct samr_connect_info
*cinfo
;
540 struct samr_domain_info
*dinfo
;
541 struct security_descriptor
*psd
= NULL
;
543 uint32 des_access
= r
->in
.access_mask
;
546 uint32_t extra_access
= SAMR_DOMAIN_ACCESS_CREATE_USER
;
549 /* find the connection policy handle. */
551 cinfo
= policy_handle_find(p
, r
->in
.connect_handle
, 0, NULL
,
552 struct samr_connect_info
, &status
);
553 if (!NT_STATUS_IS_OK(status
)) {
557 /*check if access can be granted as requested by client. */
558 map_max_allowed_access(p
->server_info
->ptok
,
559 &p
->server_info
->utok
,
562 make_samr_object_sd( p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0 );
563 se_map_generic( &des_access
, &dom_generic_mapping
);
566 * Users with SeMachineAccount or SeAddUser get additional
567 * SAMR_DOMAIN_ACCESS_CREATE_USER access.
569 se_priv_copy( &se_rights
, &se_machine_account
);
570 se_priv_add( &se_rights
, &se_add_users
);
573 * Users with SeAddUser get the ability to manipulate groups
576 if (user_has_any_privilege(p
->server_info
->ptok
, &se_add_users
)) {
577 extra_access
|= (SAMR_DOMAIN_ACCESS_CREATE_GROUP
|
578 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
|
579 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
|
580 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
|
581 SAMR_DOMAIN_ACCESS_CREATE_ALIAS
);
584 status
= access_check_object( psd
, p
->server_info
->ptok
,
585 &se_rights
, extra_access
, des_access
,
586 &acc_granted
, "_samr_OpenDomain" );
588 if ( !NT_STATUS_IS_OK(status
) )
591 if (!sid_check_is_domain(r
->in
.sid
) &&
592 !sid_check_is_builtin(r
->in
.sid
)) {
593 return NT_STATUS_NO_SUCH_DOMAIN
;
596 dinfo
= policy_handle_create(p
, r
->out
.domain_handle
, acc_granted
,
597 struct samr_domain_info
, &status
);
598 if (!NT_STATUS_IS_OK(status
)) {
601 dinfo
->sid
= *r
->in
.sid
;
602 dinfo
->disp_info
= get_samr_dispinfo_by_sid(r
->in
.sid
);
604 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__
));
609 /*******************************************************************
611 ********************************************************************/
613 NTSTATUS
_samr_GetUserPwInfo(struct pipes_struct
*p
,
614 struct samr_GetUserPwInfo
*r
)
616 struct samr_user_info
*uinfo
;
617 enum lsa_SidType sid_type
;
618 uint32_t min_password_length
= 0;
619 uint32_t password_properties
= 0;
623 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__
));
625 uinfo
= policy_handle_find(p
, r
->in
.user_handle
,
626 SAMR_USER_ACCESS_GET_ATTRIBUTES
, NULL
,
627 struct samr_user_info
, &status
);
628 if (!NT_STATUS_IS_OK(status
)) {
632 if (!sid_check_is_in_our_domain(&uinfo
->sid
)) {
633 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
637 ret
= lookup_sid(p
->mem_ctx
, &uinfo
->sid
, NULL
, NULL
, &sid_type
);
640 return NT_STATUS_NO_SUCH_USER
;
646 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_LEN
,
647 &min_password_length
);
648 pdb_get_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS
,
649 &password_properties
);
652 if (lp_check_password_script() && *lp_check_password_script()) {
653 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
661 r
->out
.info
->min_password_length
= min_password_length
;
662 r
->out
.info
->password_properties
= password_properties
;
664 DEBUG(5,("_samr_GetUserPwInfo: %d\n", __LINE__
));
669 /*******************************************************************
671 ********************************************************************/
673 NTSTATUS
_samr_SetSecurity(struct pipes_struct
*p
,
674 struct samr_SetSecurity
*r
)
676 struct samr_user_info
*uinfo
;
678 struct security_acl
*dacl
;
680 struct samu
*sampass
=NULL
;
683 uinfo
= policy_handle_find(p
, r
->in
.handle
,
684 SAMR_USER_ACCESS_SET_ATTRIBUTES
, NULL
,
685 struct samr_user_info
, &status
);
686 if (!NT_STATUS_IS_OK(status
)) {
690 if (!(sampass
= samu_new( p
->mem_ctx
))) {
691 DEBUG(0,("No memory!\n"));
692 return NT_STATUS_NO_MEMORY
;
695 /* get the user record */
697 ret
= pdb_getsampwsid(sampass
, &uinfo
->sid
);
701 DEBUG(4, ("User %s not found\n",
702 sid_string_dbg(&uinfo
->sid
)));
703 TALLOC_FREE(sampass
);
704 return NT_STATUS_INVALID_HANDLE
;
707 dacl
= r
->in
.sdbuf
->sd
->dacl
;
708 for (i
=0; i
< dacl
->num_aces
; i
++) {
709 if (sid_equal(&uinfo
->sid
, &dacl
->aces
[i
].trustee
)) {
710 ret
= pdb_set_pass_can_change(sampass
,
711 (dacl
->aces
[i
].access_mask
&
712 SAMR_USER_ACCESS_CHANGE_PASSWORD
) ?
719 TALLOC_FREE(sampass
);
720 return NT_STATUS_ACCESS_DENIED
;
724 status
= pdb_update_sam_account(sampass
);
727 TALLOC_FREE(sampass
);
732 /*******************************************************************
733 build correct perms based on policies and password times for _samr_query_sec_obj
734 *******************************************************************/
735 static bool check_change_pw_access(TALLOC_CTX
*mem_ctx
, struct dom_sid
*user_sid
)
737 struct samu
*sampass
=NULL
;
740 if ( !(sampass
= samu_new( mem_ctx
)) ) {
741 DEBUG(0,("No memory!\n"));
746 ret
= pdb_getsampwsid(sampass
, user_sid
);
750 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid
)));
751 TALLOC_FREE(sampass
);
755 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass
) ));
757 if (pdb_get_pass_can_change(sampass
)) {
758 TALLOC_FREE(sampass
);
761 TALLOC_FREE(sampass
);
766 /*******************************************************************
768 ********************************************************************/
770 NTSTATUS
_samr_QuerySecurity(struct pipes_struct
*p
,
771 struct samr_QuerySecurity
*r
)
773 struct samr_connect_info
*cinfo
;
774 struct samr_domain_info
*dinfo
;
775 struct samr_user_info
*uinfo
;
776 struct samr_group_info
*ginfo
;
777 struct samr_alias_info
*ainfo
;
779 struct security_descriptor
* psd
= NULL
;
782 cinfo
= policy_handle_find(p
, r
->in
.handle
,
783 SEC_STD_READ_CONTROL
, NULL
,
784 struct samr_connect_info
, &status
);
785 if (NT_STATUS_IS_OK(status
)) {
786 DEBUG(5,("_samr_QuerySecurity: querying security on SAM\n"));
787 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
,
788 &sam_generic_mapping
, NULL
, 0);
792 dinfo
= policy_handle_find(p
, r
->in
.handle
,
793 SEC_STD_READ_CONTROL
, NULL
,
794 struct samr_domain_info
, &status
);
795 if (NT_STATUS_IS_OK(status
)) {
796 DEBUG(5,("_samr_QuerySecurity: querying security on Domain "
797 "with SID: %s\n", sid_string_dbg(&dinfo
->sid
)));
799 * TODO: Builtin probably needs a different SD with restricted
802 status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
,
803 &dom_generic_mapping
, NULL
, 0);
807 uinfo
= policy_handle_find(p
, r
->in
.handle
,
808 SEC_STD_READ_CONTROL
, NULL
,
809 struct samr_user_info
, &status
);
810 if (NT_STATUS_IS_OK(status
)) {
811 DEBUG(10,("_samr_QuerySecurity: querying security on user "
812 "Object with SID: %s\n",
813 sid_string_dbg(&uinfo
->sid
)));
814 if (check_change_pw_access(p
->mem_ctx
, &uinfo
->sid
)) {
815 status
= make_samr_object_sd(
816 p
->mem_ctx
, &psd
, &sd_size
,
817 &usr_generic_mapping
,
818 &uinfo
->sid
, SAMR_USR_RIGHTS_WRITE_PW
);
820 status
= make_samr_object_sd(
821 p
->mem_ctx
, &psd
, &sd_size
,
822 &usr_nopwchange_generic_mapping
,
823 &uinfo
->sid
, SAMR_USR_RIGHTS_CANT_WRITE_PW
);
828 ginfo
= policy_handle_find(p
, r
->in
.handle
,
829 SEC_STD_READ_CONTROL
, NULL
,
830 struct samr_group_info
, &status
);
831 if (NT_STATUS_IS_OK(status
)) {
833 * TODO: different SDs have to be generated for aliases groups
834 * and users. Currently all three get a default user SD
836 DEBUG(10,("_samr_QuerySecurity: querying security on group "
837 "Object with SID: %s\n",
838 sid_string_dbg(&ginfo
->sid
)));
839 status
= make_samr_object_sd(
840 p
->mem_ctx
, &psd
, &sd_size
,
841 &usr_nopwchange_generic_mapping
,
842 &ginfo
->sid
, SAMR_USR_RIGHTS_CANT_WRITE_PW
);
846 ainfo
= policy_handle_find(p
, r
->in
.handle
,
847 SEC_STD_READ_CONTROL
, NULL
,
848 struct samr_alias_info
, &status
);
849 if (NT_STATUS_IS_OK(status
)) {
851 * TODO: different SDs have to be generated for aliases groups
852 * and users. Currently all three get a default user SD
854 DEBUG(10,("_samr_QuerySecurity: querying security on alias "
855 "Object with SID: %s\n",
856 sid_string_dbg(&ainfo
->sid
)));
857 status
= make_samr_object_sd(
858 p
->mem_ctx
, &psd
, &sd_size
,
859 &usr_nopwchange_generic_mapping
,
860 &ainfo
->sid
, SAMR_USR_RIGHTS_CANT_WRITE_PW
);
864 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
866 if ((*r
->out
.sdbuf
= make_sec_desc_buf(p
->mem_ctx
, sd_size
, psd
)) == NULL
)
867 return NT_STATUS_NO_MEMORY
;
872 /*******************************************************************
873 makes a SAM_ENTRY / UNISTR2* structure from a user list.
874 ********************************************************************/
876 static NTSTATUS
make_user_sam_entry_list(TALLOC_CTX
*ctx
,
877 struct samr_SamEntry
**sam_pp
,
878 uint32_t num_entries
,
880 struct samr_displayentry
*entries
)
883 struct samr_SamEntry
*sam
;
887 if (num_entries
== 0) {
891 sam
= TALLOC_ZERO_ARRAY(ctx
, struct samr_SamEntry
, num_entries
);
893 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
894 return NT_STATUS_NO_MEMORY
;
897 for (i
= 0; i
< num_entries
; i
++) {
900 * usrmgr expects a non-NULL terminated string with
901 * trust relationships
903 if (entries
[i
].acct_flags
& ACB_DOMTRUST
) {
904 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
907 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
911 init_lsa_String(&sam
[i
].name
, entries
[i
].account_name
);
912 sam
[i
].idx
= entries
[i
].rid
;
920 #define MAX_SAM_ENTRIES MAX_SAM_ENTRIES_W2K
922 /*******************************************************************
923 _samr_EnumDomainUsers
924 ********************************************************************/
926 NTSTATUS
_samr_EnumDomainUsers(struct pipes_struct
*p
,
927 struct samr_EnumDomainUsers
*r
)
930 struct samr_domain_info
*dinfo
;
932 uint32 enum_context
= *r
->in
.resume_handle
;
933 enum remote_arch_types ra_type
= get_remote_arch();
934 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
935 uint32 max_entries
= max_sam_entries
;
936 struct samr_displayentry
*entries
= NULL
;
937 struct samr_SamArray
*samr_array
= NULL
;
938 struct samr_SamEntry
*samr_entries
= NULL
;
940 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__
));
942 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
943 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
, NULL
,
944 struct samr_domain_info
, &status
);
945 if (!NT_STATUS_IS_OK(status
)) {
949 samr_array
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
951 return NT_STATUS_NO_MEMORY
;
953 *r
->out
.sam
= samr_array
;
955 if (sid_check_is_builtin(&dinfo
->sid
)) {
956 /* No users in builtin. */
957 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
958 DEBUG(5,("_samr_EnumDomainUsers: No users in BUILTIN\n"));
966 if ((dinfo
->disp_info
->enum_users
!= NULL
) &&
967 (dinfo
->disp_info
->enum_acb_mask
!= r
->in
.acct_flags
)) {
968 TALLOC_FREE(dinfo
->disp_info
->enum_users
);
971 if (dinfo
->disp_info
->enum_users
== NULL
) {
972 dinfo
->disp_info
->enum_users
= pdb_search_users(
973 dinfo
->disp_info
, r
->in
.acct_flags
);
974 dinfo
->disp_info
->enum_acb_mask
= r
->in
.acct_flags
;
977 if (dinfo
->disp_info
->enum_users
== NULL
) {
978 /* END AS ROOT !!!! */
980 return NT_STATUS_ACCESS_DENIED
;
983 num_account
= pdb_search_entries(dinfo
->disp_info
->enum_users
,
984 enum_context
, max_entries
,
987 /* END AS ROOT !!!! */
991 if (num_account
== 0) {
992 DEBUG(5, ("_samr_EnumDomainUsers: enumeration handle over "
994 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
998 status
= make_user_sam_entry_list(p
->mem_ctx
, &samr_entries
,
999 num_account
, enum_context
,
1001 if (!NT_STATUS_IS_OK(status
)) {
1005 if (max_entries
<= num_account
) {
1006 status
= STATUS_MORE_ENTRIES
;
1008 status
= NT_STATUS_OK
;
1011 /* Ensure we cache this enumeration. */
1012 set_disp_info_cache_timeout(dinfo
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1014 DEBUG(5, ("_samr_EnumDomainUsers: %d\n", __LINE__
));
1016 samr_array
->count
= num_account
;
1017 samr_array
->entries
= samr_entries
;
1019 *r
->out
.resume_handle
= *r
->in
.resume_handle
+ num_account
;
1020 *r
->out
.num_entries
= num_account
;
1022 DEBUG(5,("_samr_EnumDomainUsers: %d\n", __LINE__
));
1027 /*******************************************************************
1028 makes a SAM_ENTRY / UNISTR2* structure from a group list.
1029 ********************************************************************/
1031 static void make_group_sam_entry_list(TALLOC_CTX
*ctx
,
1032 struct samr_SamEntry
**sam_pp
,
1033 uint32_t num_sam_entries
,
1034 struct samr_displayentry
*entries
)
1036 struct samr_SamEntry
*sam
;
1041 if (num_sam_entries
== 0) {
1045 sam
= TALLOC_ZERO_ARRAY(ctx
, struct samr_SamEntry
, num_sam_entries
);
1050 for (i
= 0; i
< num_sam_entries
; i
++) {
1052 * JRA. I think this should include the null. TNG does not.
1054 init_lsa_String(&sam
[i
].name
, entries
[i
].account_name
);
1055 sam
[i
].idx
= entries
[i
].rid
;
1061 /*******************************************************************
1062 _samr_EnumDomainGroups
1063 ********************************************************************/
1065 NTSTATUS
_samr_EnumDomainGroups(struct pipes_struct
*p
,
1066 struct samr_EnumDomainGroups
*r
)
1069 struct samr_domain_info
*dinfo
;
1070 struct samr_displayentry
*groups
;
1072 struct samr_SamArray
*samr_array
= NULL
;
1073 struct samr_SamEntry
*samr_entries
= NULL
;
1075 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
1076 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
, NULL
,
1077 struct samr_domain_info
, &status
);
1078 if (!NT_STATUS_IS_OK(status
)) {
1082 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__
));
1084 samr_array
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
1086 return NT_STATUS_NO_MEMORY
;
1088 *r
->out
.sam
= samr_array
;
1090 if (sid_check_is_builtin(&dinfo
->sid
)) {
1091 /* No groups in builtin. */
1092 *r
->out
.resume_handle
= *r
->in
.resume_handle
;
1093 DEBUG(5,("_samr_EnumDomainGroups: No groups in BUILTIN\n"));
1097 /* the domain group array is being allocated in the function below */
1101 if (dinfo
->disp_info
->groups
== NULL
) {
1102 dinfo
->disp_info
->groups
= pdb_search_groups(dinfo
->disp_info
);
1104 if (dinfo
->disp_info
->groups
== NULL
) {
1106 return NT_STATUS_ACCESS_DENIED
;
1110 num_groups
= pdb_search_entries(dinfo
->disp_info
->groups
,
1111 *r
->in
.resume_handle
,
1112 MAX_SAM_ENTRIES
, &groups
);
1115 /* Ensure we cache this enumeration. */
1116 set_disp_info_cache_timeout(dinfo
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1118 make_group_sam_entry_list(p
->mem_ctx
, &samr_entries
,
1119 num_groups
, groups
);
1121 if (MAX_SAM_ENTRIES
<= num_groups
) {
1122 status
= STATUS_MORE_ENTRIES
;
1124 status
= NT_STATUS_OK
;
1127 samr_array
->count
= num_groups
;
1128 samr_array
->entries
= samr_entries
;
1130 *r
->out
.num_entries
= num_groups
;
1131 *r
->out
.resume_handle
= num_groups
+ *r
->in
.resume_handle
;
1133 DEBUG(5,("_samr_EnumDomainGroups: %d\n", __LINE__
));
1138 /*******************************************************************
1139 _samr_EnumDomainAliases
1140 ********************************************************************/
1142 NTSTATUS
_samr_EnumDomainAliases(struct pipes_struct
*p
,
1143 struct samr_EnumDomainAliases
*r
)
1146 struct samr_domain_info
*dinfo
;
1147 struct samr_displayentry
*aliases
;
1148 uint32 num_aliases
= 0;
1149 struct samr_SamArray
*samr_array
= NULL
;
1150 struct samr_SamEntry
*samr_entries
= NULL
;
1152 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
1153 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
, NULL
,
1154 struct samr_domain_info
, &status
);
1155 if (!NT_STATUS_IS_OK(status
)) {
1159 DEBUG(5,("_samr_EnumDomainAliases: sid %s\n",
1160 sid_string_dbg(&dinfo
->sid
)));
1162 samr_array
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
1164 return NT_STATUS_NO_MEMORY
;
1169 if (dinfo
->disp_info
->aliases
== NULL
) {
1170 dinfo
->disp_info
->aliases
= pdb_search_aliases(
1171 dinfo
->disp_info
, &dinfo
->sid
);
1172 if (dinfo
->disp_info
->aliases
== NULL
) {
1174 return NT_STATUS_ACCESS_DENIED
;
1178 num_aliases
= pdb_search_entries(dinfo
->disp_info
->aliases
,
1179 *r
->in
.resume_handle
,
1180 MAX_SAM_ENTRIES
, &aliases
);
1183 /* Ensure we cache this enumeration. */
1184 set_disp_info_cache_timeout(dinfo
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1186 make_group_sam_entry_list(p
->mem_ctx
, &samr_entries
,
1187 num_aliases
, aliases
);
1189 DEBUG(5,("_samr_EnumDomainAliases: %d\n", __LINE__
));
1191 if (MAX_SAM_ENTRIES
<= num_aliases
) {
1192 status
= STATUS_MORE_ENTRIES
;
1194 status
= NT_STATUS_OK
;
1197 samr_array
->count
= num_aliases
;
1198 samr_array
->entries
= samr_entries
;
1200 *r
->out
.sam
= samr_array
;
1201 *r
->out
.num_entries
= num_aliases
;
1202 *r
->out
.resume_handle
= num_aliases
+ *r
->in
.resume_handle
;
1207 /*******************************************************************
1208 inits a samr_DispInfoGeneral structure.
1209 ********************************************************************/
1211 static NTSTATUS
init_samr_dispinfo_1(TALLOC_CTX
*ctx
,
1212 struct samr_DispInfoGeneral
*r
,
1213 uint32_t num_entries
,
1215 struct samr_displayentry
*entries
)
1219 DEBUG(10, ("init_samr_dispinfo_1: num_entries: %d\n", num_entries
));
1221 if (num_entries
== 0) {
1222 return NT_STATUS_OK
;
1225 r
->count
= num_entries
;
1227 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryGeneral
, num_entries
);
1229 return NT_STATUS_NO_MEMORY
;
1232 for (i
= 0; i
< num_entries
; i
++) {
1234 init_lsa_String(&r
->entries
[i
].account_name
,
1235 entries
[i
].account_name
);
1237 init_lsa_String(&r
->entries
[i
].description
,
1238 entries
[i
].description
);
1240 init_lsa_String(&r
->entries
[i
].full_name
,
1241 entries
[i
].fullname
);
1243 r
->entries
[i
].rid
= entries
[i
].rid
;
1244 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1245 r
->entries
[i
].idx
= start_idx
+i
+1;
1248 return NT_STATUS_OK
;
1251 /*******************************************************************
1252 inits a samr_DispInfoFull structure.
1253 ********************************************************************/
1255 static NTSTATUS
init_samr_dispinfo_2(TALLOC_CTX
*ctx
,
1256 struct samr_DispInfoFull
*r
,
1257 uint32_t num_entries
,
1259 struct samr_displayentry
*entries
)
1263 DEBUG(10, ("init_samr_dispinfo_2: num_entries: %d\n", num_entries
));
1265 if (num_entries
== 0) {
1266 return NT_STATUS_OK
;
1269 r
->count
= num_entries
;
1271 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryFull
, num_entries
);
1273 return NT_STATUS_NO_MEMORY
;
1276 for (i
= 0; i
< num_entries
; i
++) {
1278 init_lsa_String(&r
->entries
[i
].account_name
,
1279 entries
[i
].account_name
);
1281 init_lsa_String(&r
->entries
[i
].description
,
1282 entries
[i
].description
);
1284 r
->entries
[i
].rid
= entries
[i
].rid
;
1285 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1286 r
->entries
[i
].idx
= start_idx
+i
+1;
1289 return NT_STATUS_OK
;
1292 /*******************************************************************
1293 inits a samr_DispInfoFullGroups structure.
1294 ********************************************************************/
1296 static NTSTATUS
init_samr_dispinfo_3(TALLOC_CTX
*ctx
,
1297 struct samr_DispInfoFullGroups
*r
,
1298 uint32_t num_entries
,
1300 struct samr_displayentry
*entries
)
1304 DEBUG(5, ("init_samr_dispinfo_3: num_entries: %d\n", num_entries
));
1306 if (num_entries
== 0) {
1307 return NT_STATUS_OK
;
1310 r
->count
= num_entries
;
1312 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryFullGroup
, num_entries
);
1314 return NT_STATUS_NO_MEMORY
;
1317 for (i
= 0; i
< num_entries
; i
++) {
1319 init_lsa_String(&r
->entries
[i
].account_name
,
1320 entries
[i
].account_name
);
1322 init_lsa_String(&r
->entries
[i
].description
,
1323 entries
[i
].description
);
1325 r
->entries
[i
].rid
= entries
[i
].rid
;
1326 r
->entries
[i
].acct_flags
= entries
[i
].acct_flags
;
1327 r
->entries
[i
].idx
= start_idx
+i
+1;
1330 return NT_STATUS_OK
;
1333 /*******************************************************************
1334 inits a samr_DispInfoAscii structure.
1335 ********************************************************************/
1337 static NTSTATUS
init_samr_dispinfo_4(TALLOC_CTX
*ctx
,
1338 struct samr_DispInfoAscii
*r
,
1339 uint32_t num_entries
,
1341 struct samr_displayentry
*entries
)
1345 DEBUG(5, ("init_samr_dispinfo_4: num_entries: %d\n", num_entries
));
1347 if (num_entries
== 0) {
1348 return NT_STATUS_OK
;
1351 r
->count
= num_entries
;
1353 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryAscii
, num_entries
);
1355 return NT_STATUS_NO_MEMORY
;
1358 for (i
= 0; i
< num_entries
; i
++) {
1360 init_lsa_AsciiStringLarge(&r
->entries
[i
].account_name
,
1361 entries
[i
].account_name
);
1363 r
->entries
[i
].idx
= start_idx
+i
+1;
1366 return NT_STATUS_OK
;
1369 /*******************************************************************
1370 inits a samr_DispInfoAscii structure.
1371 ********************************************************************/
1373 static NTSTATUS
init_samr_dispinfo_5(TALLOC_CTX
*ctx
,
1374 struct samr_DispInfoAscii
*r
,
1375 uint32_t num_entries
,
1377 struct samr_displayentry
*entries
)
1381 DEBUG(5, ("init_samr_dispinfo_5: num_entries: %d\n", num_entries
));
1383 if (num_entries
== 0) {
1384 return NT_STATUS_OK
;
1387 r
->count
= num_entries
;
1389 r
->entries
= TALLOC_ZERO_ARRAY(ctx
, struct samr_DispEntryAscii
, num_entries
);
1391 return NT_STATUS_NO_MEMORY
;
1394 for (i
= 0; i
< num_entries
; i
++) {
1396 init_lsa_AsciiStringLarge(&r
->entries
[i
].account_name
,
1397 entries
[i
].account_name
);
1399 r
->entries
[i
].idx
= start_idx
+i
+1;
1402 return NT_STATUS_OK
;
1405 /*******************************************************************
1406 _samr_QueryDisplayInfo
1407 ********************************************************************/
1409 NTSTATUS
_samr_QueryDisplayInfo(struct pipes_struct
*p
,
1410 struct samr_QueryDisplayInfo
*r
)
1413 struct samr_domain_info
*dinfo
;
1414 uint32 struct_size
=0x20; /* W2K always reply that, client doesn't care */
1416 uint32 max_entries
= r
->in
.max_entries
;
1418 union samr_DispInfo
*disp_info
= r
->out
.info
;
1421 NTSTATUS disp_ret
= NT_STATUS_UNSUCCESSFUL
;
1422 uint32 num_account
= 0;
1423 enum remote_arch_types ra_type
= get_remote_arch();
1424 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
1425 struct samr_displayentry
*entries
= NULL
;
1427 DEBUG(5,("_samr_QueryDisplayInfo: %d\n", __LINE__
));
1429 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
1430 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
, NULL
,
1431 struct samr_domain_info
, &status
);
1432 if (!NT_STATUS_IS_OK(status
)) {
1436 if (sid_check_is_builtin(&dinfo
->sid
)) {
1437 DEBUG(5,("_samr_QueryDisplayInfo: no users in BUILTIN\n"));
1438 return NT_STATUS_OK
;
1442 * calculate how many entries we will return.
1444 * - the number of entries the client asked
1445 * - our limit on that
1446 * - the starting point (enumeration context)
1447 * - the buffer size the client will accept
1451 * We are a lot more like W2K. Instead of reading the SAM
1452 * each time to find the records we need to send back,
1453 * we read it once and link that copy to the sam handle.
1454 * For large user list (over the MAX_SAM_ENTRIES)
1455 * it's a definitive win.
1456 * second point to notice: between enumerations
1457 * our sam is now the same as it's a snapshoot.
1458 * third point: got rid of the static SAM_USER_21 struct
1459 * no more intermediate.
1460 * con: it uses much more memory, as a full copy is stored
1463 * If you want to change it, think twice and think
1464 * of the second point , that's really important.
1469 if ((r
->in
.level
< 1) || (r
->in
.level
> 5)) {
1470 DEBUG(0,("_samr_QueryDisplayInfo: Unknown info level (%u)\n",
1471 (unsigned int)r
->in
.level
));
1472 return NT_STATUS_INVALID_INFO_CLASS
;
1475 /* first limit the number of entries we will return */
1476 if (r
->in
.max_entries
> max_sam_entries
) {
1477 DEBUG(5, ("_samr_QueryDisplayInfo: client requested %d "
1478 "entries, limiting to %d\n", r
->in
.max_entries
,
1480 max_entries
= max_sam_entries
;
1483 /* calculate the size and limit on the number of entries we will
1486 temp_size
=max_entries
*struct_size
;
1488 if (temp_size
> r
->in
.buf_size
) {
1489 max_entries
= MIN((r
->in
.buf_size
/ struct_size
),max_entries
);;
1490 DEBUG(5, ("_samr_QueryDisplayInfo: buffer size limits to "
1491 "only %d entries\n", max_entries
));
1496 /* THe following done as ROOT. Don't return without unbecome_root(). */
1498 switch (r
->in
.level
) {
1501 if (dinfo
->disp_info
->users
== NULL
) {
1502 dinfo
->disp_info
->users
= pdb_search_users(
1503 dinfo
->disp_info
, ACB_NORMAL
);
1504 if (dinfo
->disp_info
->users
== NULL
) {
1506 return NT_STATUS_ACCESS_DENIED
;
1508 DEBUG(10,("_samr_QueryDisplayInfo: starting user enumeration at index %u\n",
1509 (unsigned int)r
->in
.start_idx
));
1511 DEBUG(10,("_samr_QueryDisplayInfo: using cached user enumeration at index %u\n",
1512 (unsigned int)r
->in
.start_idx
));
1515 num_account
= pdb_search_entries(dinfo
->disp_info
->users
,
1516 r
->in
.start_idx
, max_entries
,
1520 if (dinfo
->disp_info
->machines
== NULL
) {
1521 dinfo
->disp_info
->machines
= pdb_search_users(
1522 dinfo
->disp_info
, ACB_WSTRUST
|ACB_SVRTRUST
);
1523 if (dinfo
->disp_info
->machines
== NULL
) {
1525 return NT_STATUS_ACCESS_DENIED
;
1527 DEBUG(10,("_samr_QueryDisplayInfo: starting machine enumeration at index %u\n",
1528 (unsigned int)r
->in
.start_idx
));
1530 DEBUG(10,("_samr_QueryDisplayInfo: using cached machine enumeration at index %u\n",
1531 (unsigned int)r
->in
.start_idx
));
1534 num_account
= pdb_search_entries(dinfo
->disp_info
->machines
,
1535 r
->in
.start_idx
, max_entries
,
1540 if (dinfo
->disp_info
->groups
== NULL
) {
1541 dinfo
->disp_info
->groups
= pdb_search_groups(
1543 if (dinfo
->disp_info
->groups
== NULL
) {
1545 return NT_STATUS_ACCESS_DENIED
;
1547 DEBUG(10,("_samr_QueryDisplayInfo: starting group enumeration at index %u\n",
1548 (unsigned int)r
->in
.start_idx
));
1550 DEBUG(10,("_samr_QueryDisplayInfo: using cached group enumeration at index %u\n",
1551 (unsigned int)r
->in
.start_idx
));
1554 num_account
= pdb_search_entries(dinfo
->disp_info
->groups
,
1555 r
->in
.start_idx
, max_entries
,
1560 smb_panic("info class changed");
1566 /* Now create reply structure */
1567 switch (r
->in
.level
) {
1569 disp_ret
= init_samr_dispinfo_1(p
->mem_ctx
, &disp_info
->info1
,
1570 num_account
, r
->in
.start_idx
,
1574 disp_ret
= init_samr_dispinfo_2(p
->mem_ctx
, &disp_info
->info2
,
1575 num_account
, r
->in
.start_idx
,
1579 disp_ret
= init_samr_dispinfo_3(p
->mem_ctx
, &disp_info
->info3
,
1580 num_account
, r
->in
.start_idx
,
1584 disp_ret
= init_samr_dispinfo_4(p
->mem_ctx
, &disp_info
->info4
,
1585 num_account
, r
->in
.start_idx
,
1589 disp_ret
= init_samr_dispinfo_5(p
->mem_ctx
, &disp_info
->info5
,
1590 num_account
, r
->in
.start_idx
,
1594 smb_panic("info class changed");
1598 if (!NT_STATUS_IS_OK(disp_ret
))
1601 if (max_entries
<= num_account
) {
1602 status
= STATUS_MORE_ENTRIES
;
1604 status
= NT_STATUS_OK
;
1607 /* Ensure we cache this enumeration. */
1608 set_disp_info_cache_timeout(dinfo
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
1610 DEBUG(5, ("_samr_QueryDisplayInfo: %d\n", __LINE__
));
1612 *r
->out
.total_size
= num_account
* struct_size
;
1613 *r
->out
.returned_size
= num_account
? temp_size
: 0;
1618 /****************************************************************
1619 _samr_QueryDisplayInfo2
1620 ****************************************************************/
1622 NTSTATUS
_samr_QueryDisplayInfo2(struct pipes_struct
*p
,
1623 struct samr_QueryDisplayInfo2
*r
)
1625 struct samr_QueryDisplayInfo q
;
1627 q
.in
.domain_handle
= r
->in
.domain_handle
;
1628 q
.in
.level
= r
->in
.level
;
1629 q
.in
.start_idx
= r
->in
.start_idx
;
1630 q
.in
.max_entries
= r
->in
.max_entries
;
1631 q
.in
.buf_size
= r
->in
.buf_size
;
1633 q
.out
.total_size
= r
->out
.total_size
;
1634 q
.out
.returned_size
= r
->out
.returned_size
;
1635 q
.out
.info
= r
->out
.info
;
1637 return _samr_QueryDisplayInfo(p
, &q
);
1640 /****************************************************************
1641 _samr_QueryDisplayInfo3
1642 ****************************************************************/
1644 NTSTATUS
_samr_QueryDisplayInfo3(struct pipes_struct
*p
,
1645 struct samr_QueryDisplayInfo3
*r
)
1647 struct samr_QueryDisplayInfo q
;
1649 q
.in
.domain_handle
= r
->in
.domain_handle
;
1650 q
.in
.level
= r
->in
.level
;
1651 q
.in
.start_idx
= r
->in
.start_idx
;
1652 q
.in
.max_entries
= r
->in
.max_entries
;
1653 q
.in
.buf_size
= r
->in
.buf_size
;
1655 q
.out
.total_size
= r
->out
.total_size
;
1656 q
.out
.returned_size
= r
->out
.returned_size
;
1657 q
.out
.info
= r
->out
.info
;
1659 return _samr_QueryDisplayInfo(p
, &q
);
1662 /*******************************************************************
1663 _samr_QueryAliasInfo
1664 ********************************************************************/
1666 NTSTATUS
_samr_QueryAliasInfo(struct pipes_struct
*p
,
1667 struct samr_QueryAliasInfo
*r
)
1669 struct samr_alias_info
*ainfo
;
1670 struct acct_info info
;
1672 union samr_AliasInfo
*alias_info
= NULL
;
1673 const char *alias_name
= NULL
;
1674 const char *alias_description
= NULL
;
1676 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__
));
1678 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
1679 SAMR_ALIAS_ACCESS_LOOKUP_INFO
, NULL
,
1680 struct samr_alias_info
, &status
);
1681 if (!NT_STATUS_IS_OK(status
)) {
1685 alias_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_AliasInfo
);
1687 return NT_STATUS_NO_MEMORY
;
1691 status
= pdb_get_aliasinfo(&ainfo
->sid
, &info
);
1694 if ( !NT_STATUS_IS_OK(status
))
1697 /* FIXME: info contains fstrings */
1698 alias_name
= talloc_strdup(r
, info
.acct_name
);
1699 alias_description
= talloc_strdup(r
, info
.acct_desc
);
1701 switch (r
->in
.level
) {
1703 alias_info
->all
.name
.string
= alias_name
;
1704 alias_info
->all
.num_members
= 1; /* ??? */
1705 alias_info
->all
.description
.string
= alias_description
;
1708 alias_info
->name
.string
= alias_name
;
1710 case ALIASINFODESCRIPTION
:
1711 alias_info
->description
.string
= alias_description
;
1714 return NT_STATUS_INVALID_INFO_CLASS
;
1717 *r
->out
.info
= alias_info
;
1719 DEBUG(5,("_samr_QueryAliasInfo: %d\n", __LINE__
));
1721 return NT_STATUS_OK
;
1724 /*******************************************************************
1726 ********************************************************************/
1728 NTSTATUS
_samr_LookupNames(struct pipes_struct
*p
,
1729 struct samr_LookupNames
*r
)
1731 struct samr_domain_info
*dinfo
;
1734 enum lsa_SidType
*type
;
1736 int num_rids
= r
->in
.num_names
;
1737 struct samr_Ids rids
, types
;
1738 uint32_t num_mapped
= 0;
1740 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__
));
1742 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
1743 0 /* Don't know the acc_bits yet */, NULL
,
1744 struct samr_domain_info
, &status
);
1745 if (!NT_STATUS_IS_OK(status
)) {
1749 if (num_rids
> MAX_SAM_ENTRIES
) {
1750 num_rids
= MAX_SAM_ENTRIES
;
1751 DEBUG(5,("_samr_LookupNames: truncating entries to %d\n", num_rids
));
1754 rid
= talloc_array(p
->mem_ctx
, uint32
, num_rids
);
1755 NT_STATUS_HAVE_NO_MEMORY(rid
);
1757 type
= talloc_array(p
->mem_ctx
, enum lsa_SidType
, num_rids
);
1758 NT_STATUS_HAVE_NO_MEMORY(type
);
1760 DEBUG(5,("_samr_LookupNames: looking name on SID %s\n",
1761 sid_string_dbg(&dinfo
->sid
)));
1763 for (i
= 0; i
< num_rids
; i
++) {
1765 status
= NT_STATUS_NONE_MAPPED
;
1766 type
[i
] = SID_NAME_UNKNOWN
;
1768 rid
[i
] = 0xffffffff;
1770 if (sid_check_is_builtin(&dinfo
->sid
)) {
1771 if (lookup_builtin_name(r
->in
.names
[i
].string
,
1774 type
[i
] = SID_NAME_ALIAS
;
1777 lookup_global_sam_name(r
->in
.names
[i
].string
, 0,
1781 if (type
[i
] != SID_NAME_UNKNOWN
) {
1786 if (num_mapped
== num_rids
) {
1787 status
= NT_STATUS_OK
;
1788 } else if (num_mapped
== 0) {
1789 status
= NT_STATUS_NONE_MAPPED
;
1791 status
= STATUS_SOME_UNMAPPED
;
1794 rids
.count
= num_rids
;
1797 types
.count
= num_rids
;
1800 *r
->out
.rids
= rids
;
1801 *r
->out
.types
= types
;
1803 DEBUG(5,("_samr_LookupNames: %d\n", __LINE__
));
1808 /****************************************************************
1809 _samr_ChangePasswordUser
1810 ****************************************************************/
1812 NTSTATUS
_samr_ChangePasswordUser(struct pipes_struct
*p
,
1813 struct samr_ChangePasswordUser
*r
)
1817 struct samr_user_info
*uinfo
;
1819 struct samr_Password new_lmPwdHash
, new_ntPwdHash
, checkHash
;
1820 struct samr_Password lm_pwd
, nt_pwd
;
1822 uinfo
= policy_handle_find(p
, r
->in
.user_handle
,
1823 SAMR_USER_ACCESS_SET_PASSWORD
, NULL
,
1824 struct samr_user_info
, &status
);
1825 if (!NT_STATUS_IS_OK(status
)) {
1829 DEBUG(5,("_samr_ChangePasswordUser: sid:%s\n",
1830 sid_string_dbg(&uinfo
->sid
)));
1832 if (!(pwd
= samu_new(NULL
))) {
1833 return NT_STATUS_NO_MEMORY
;
1837 ret
= pdb_getsampwsid(pwd
, &uinfo
->sid
);
1842 return NT_STATUS_WRONG_PASSWORD
;
1846 const uint8_t *lm_pass
, *nt_pass
;
1848 lm_pass
= pdb_get_lanman_passwd(pwd
);
1849 nt_pass
= pdb_get_nt_passwd(pwd
);
1851 if (!lm_pass
|| !nt_pass
) {
1852 status
= NT_STATUS_WRONG_PASSWORD
;
1856 memcpy(&lm_pwd
.hash
, lm_pass
, sizeof(lm_pwd
.hash
));
1857 memcpy(&nt_pwd
.hash
, nt_pass
, sizeof(nt_pwd
.hash
));
1860 /* basic sanity checking on parameters. Do this before any database ops */
1861 if (!r
->in
.lm_present
|| !r
->in
.nt_present
||
1862 !r
->in
.old_lm_crypted
|| !r
->in
.new_lm_crypted
||
1863 !r
->in
.old_nt_crypted
|| !r
->in
.new_nt_crypted
) {
1864 /* we should really handle a change with lm not
1866 status
= NT_STATUS_INVALID_PARAMETER_MIX
;
1870 /* decrypt and check the new lm hash */
1871 D_P16(lm_pwd
.hash
, r
->in
.new_lm_crypted
->hash
, new_lmPwdHash
.hash
);
1872 D_P16(new_lmPwdHash
.hash
, r
->in
.old_lm_crypted
->hash
, checkHash
.hash
);
1873 if (memcmp(checkHash
.hash
, lm_pwd
.hash
, 16) != 0) {
1874 status
= NT_STATUS_WRONG_PASSWORD
;
1878 /* decrypt and check the new nt hash */
1879 D_P16(nt_pwd
.hash
, r
->in
.new_nt_crypted
->hash
, new_ntPwdHash
.hash
);
1880 D_P16(new_ntPwdHash
.hash
, r
->in
.old_nt_crypted
->hash
, checkHash
.hash
);
1881 if (memcmp(checkHash
.hash
, nt_pwd
.hash
, 16) != 0) {
1882 status
= NT_STATUS_WRONG_PASSWORD
;
1886 /* The NT Cross is not required by Win2k3 R2, but if present
1887 check the nt cross hash */
1888 if (r
->in
.cross1_present
&& r
->in
.nt_cross
) {
1889 D_P16(lm_pwd
.hash
, r
->in
.nt_cross
->hash
, checkHash
.hash
);
1890 if (memcmp(checkHash
.hash
, new_ntPwdHash
.hash
, 16) != 0) {
1891 status
= NT_STATUS_WRONG_PASSWORD
;
1896 /* The LM Cross is not required by Win2k3 R2, but if present
1897 check the lm cross hash */
1898 if (r
->in
.cross2_present
&& r
->in
.lm_cross
) {
1899 D_P16(nt_pwd
.hash
, r
->in
.lm_cross
->hash
, checkHash
.hash
);
1900 if (memcmp(checkHash
.hash
, new_lmPwdHash
.hash
, 16) != 0) {
1901 status
= NT_STATUS_WRONG_PASSWORD
;
1906 if (!pdb_set_nt_passwd(pwd
, new_ntPwdHash
.hash
, PDB_CHANGED
) ||
1907 !pdb_set_lanman_passwd(pwd
, new_lmPwdHash
.hash
, PDB_CHANGED
)) {
1908 status
= NT_STATUS_ACCESS_DENIED
;
1912 status
= pdb_update_sam_account(pwd
);
1919 /*******************************************************************
1920 _samr_ChangePasswordUser2
1921 ********************************************************************/
1923 NTSTATUS
_samr_ChangePasswordUser2(struct pipes_struct
*p
,
1924 struct samr_ChangePasswordUser2
*r
)
1930 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__
));
1932 fstrcpy(user_name
, r
->in
.account
->string
);
1933 fstrcpy(wks
, r
->in
.server
->string
);
1935 DEBUG(5,("_samr_ChangePasswordUser2: user: %s wks: %s\n", user_name
, wks
));
1938 * Pass the user through the NT -> unix user mapping
1942 (void)map_username(user_name
);
1945 * UNIX username case mangling not required, pass_oem_change
1946 * is case insensitive.
1949 status
= pass_oem_change(user_name
,
1950 r
->in
.lm_password
->data
,
1951 r
->in
.lm_verifier
->hash
,
1952 r
->in
.nt_password
->data
,
1953 r
->in
.nt_verifier
->hash
,
1956 DEBUG(5,("_samr_ChangePasswordUser2: %d\n", __LINE__
));
1958 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
1959 return NT_STATUS_WRONG_PASSWORD
;
1965 /****************************************************************
1966 _samr_OemChangePasswordUser2
1967 ****************************************************************/
1969 NTSTATUS
_samr_OemChangePasswordUser2(struct pipes_struct
*p
,
1970 struct samr_OemChangePasswordUser2
*r
)
1974 const char *wks
= NULL
;
1976 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__
));
1978 fstrcpy(user_name
, r
->in
.account
->string
);
1979 if (r
->in
.server
&& r
->in
.server
->string
) {
1980 wks
= r
->in
.server
->string
;
1983 DEBUG(5,("_samr_OemChangePasswordUser2: user: %s wks: %s\n", user_name
, wks
));
1986 * Pass the user through the NT -> unix user mapping
1990 (void)map_username(user_name
);
1993 * UNIX username case mangling not required, pass_oem_change
1994 * is case insensitive.
1997 if (!r
->in
.hash
|| !r
->in
.password
) {
1998 return NT_STATUS_INVALID_PARAMETER
;
2001 status
= pass_oem_change(user_name
,
2002 r
->in
.password
->data
,
2008 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
2009 return NT_STATUS_WRONG_PASSWORD
;
2012 DEBUG(5,("_samr_OemChangePasswordUser2: %d\n", __LINE__
));
2017 /*******************************************************************
2018 _samr_ChangePasswordUser3
2019 ********************************************************************/
2021 NTSTATUS
_samr_ChangePasswordUser3(struct pipes_struct
*p
,
2022 struct samr_ChangePasswordUser3
*r
)
2026 const char *wks
= NULL
;
2027 enum samPwdChangeReason reject_reason
;
2028 struct samr_DomInfo1
*dominfo
= NULL
;
2029 struct userPwdChangeFailureInformation
*reject
= NULL
;
2032 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__
));
2034 fstrcpy(user_name
, r
->in
.account
->string
);
2035 if (r
->in
.server
&& r
->in
.server
->string
) {
2036 wks
= r
->in
.server
->string
;
2039 DEBUG(5,("_samr_ChangePasswordUser3: user: %s wks: %s\n", user_name
, wks
));
2042 * Pass the user through the NT -> unix user mapping
2046 (void)map_username(user_name
);
2049 * UNIX username case mangling not required, pass_oem_change
2050 * is case insensitive.
2053 status
= pass_oem_change(user_name
,
2054 r
->in
.lm_password
->data
,
2055 r
->in
.lm_verifier
->hash
,
2056 r
->in
.nt_password
->data
,
2057 r
->in
.nt_verifier
->hash
,
2059 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
2060 return NT_STATUS_WRONG_PASSWORD
;
2063 if (NT_STATUS_EQUAL(status
, NT_STATUS_PASSWORD_RESTRICTION
) ||
2064 NT_STATUS_EQUAL(status
, NT_STATUS_ACCOUNT_RESTRICTION
)) {
2066 time_t u_expire
, u_min_age
;
2067 uint32 account_policy_temp
;
2069 dominfo
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_DomInfo1
);
2071 return NT_STATUS_NO_MEMORY
;
2074 reject
= TALLOC_ZERO_P(p
->mem_ctx
,
2075 struct userPwdChangeFailureInformation
);
2077 return NT_STATUS_NO_MEMORY
;
2084 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_LEN
, &tmp
);
2085 dominfo
->min_password_length
= tmp
;
2087 pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY
, &tmp
);
2088 dominfo
->password_history_length
= tmp
;
2090 pdb_get_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS
,
2091 &dominfo
->password_properties
);
2093 pdb_get_account_policy(PDB_POLICY_MAX_PASSWORD_AGE
, &account_policy_temp
);
2094 u_expire
= account_policy_temp
;
2096 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_AGE
, &account_policy_temp
);
2097 u_min_age
= account_policy_temp
;
2103 unix_to_nt_time_abs((NTTIME
*)&dominfo
->max_password_age
, u_expire
);
2104 unix_to_nt_time_abs((NTTIME
*)&dominfo
->min_password_age
, u_min_age
);
2106 if (lp_check_password_script() && *lp_check_password_script()) {
2107 dominfo
->password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
2110 reject
->extendedFailureReason
= reject_reason
;
2112 *r
->out
.dominfo
= dominfo
;
2113 *r
->out
.reject
= reject
;
2116 DEBUG(5,("_samr_ChangePasswordUser3: %d\n", __LINE__
));
2121 /*******************************************************************
2122 makes a SAMR_R_LOOKUP_RIDS structure.
2123 ********************************************************************/
2125 static bool make_samr_lookup_rids(TALLOC_CTX
*ctx
, uint32 num_names
,
2127 struct lsa_String
**lsa_name_array_p
)
2129 struct lsa_String
*lsa_name_array
= NULL
;
2132 *lsa_name_array_p
= NULL
;
2134 if (num_names
!= 0) {
2135 lsa_name_array
= TALLOC_ZERO_ARRAY(ctx
, struct lsa_String
, num_names
);
2136 if (!lsa_name_array
) {
2141 for (i
= 0; i
< num_names
; i
++) {
2142 DEBUG(10, ("names[%d]:%s\n", i
, names
[i
] && *names
[i
] ? names
[i
] : ""));
2143 init_lsa_String(&lsa_name_array
[i
], names
[i
]);
2146 *lsa_name_array_p
= lsa_name_array
;
2151 /*******************************************************************
2153 ********************************************************************/
2155 NTSTATUS
_samr_LookupRids(struct pipes_struct
*p
,
2156 struct samr_LookupRids
*r
)
2158 struct samr_domain_info
*dinfo
;
2161 enum lsa_SidType
*attrs
= NULL
;
2162 uint32
*wire_attrs
= NULL
;
2163 int num_rids
= (int)r
->in
.num_rids
;
2165 struct lsa_Strings names_array
;
2166 struct samr_Ids types_array
;
2167 struct lsa_String
*lsa_names
= NULL
;
2169 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__
));
2171 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
2172 0 /* Don't know the acc_bits yet */, NULL
,
2173 struct samr_domain_info
, &status
);
2174 if (!NT_STATUS_IS_OK(status
)) {
2178 if (num_rids
> 1000) {
2179 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
2180 "to samba4 idl this is not possible\n", num_rids
));
2181 return NT_STATUS_UNSUCCESSFUL
;
2185 names
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, const char *, num_rids
);
2186 attrs
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, enum lsa_SidType
, num_rids
);
2187 wire_attrs
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_rids
);
2189 if ((names
== NULL
) || (attrs
== NULL
) || (wire_attrs
==NULL
))
2190 return NT_STATUS_NO_MEMORY
;
2197 become_root(); /* lookup_sid can require root privs */
2198 status
= pdb_lookup_rids(&dinfo
->sid
, num_rids
, r
->in
.rids
,
2202 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
) && (num_rids
== 0)) {
2203 status
= NT_STATUS_OK
;
2206 if (!make_samr_lookup_rids(p
->mem_ctx
, num_rids
, names
,
2208 return NT_STATUS_NO_MEMORY
;
2211 /* Convert from enum lsa_SidType to uint32 for wire format. */
2212 for (i
= 0; i
< num_rids
; i
++) {
2213 wire_attrs
[i
] = (uint32
)attrs
[i
];
2216 names_array
.count
= num_rids
;
2217 names_array
.names
= lsa_names
;
2219 types_array
.count
= num_rids
;
2220 types_array
.ids
= wire_attrs
;
2222 *r
->out
.names
= names_array
;
2223 *r
->out
.types
= types_array
;
2225 DEBUG(5,("_samr_LookupRids: %d\n", __LINE__
));
2230 /*******************************************************************
2232 ********************************************************************/
2234 NTSTATUS
_samr_OpenUser(struct pipes_struct
*p
,
2235 struct samr_OpenUser
*r
)
2237 struct samu
*sampass
=NULL
;
2239 struct samr_domain_info
*dinfo
;
2240 struct samr_user_info
*uinfo
;
2241 struct security_descriptor
*psd
= NULL
;
2243 uint32 des_access
= r
->in
.access_mask
;
2244 uint32_t extra_access
= 0;
2251 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
2252 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
, NULL
,
2253 struct samr_domain_info
, &status
);
2254 if (!NT_STATUS_IS_OK(status
)) {
2258 if ( !(sampass
= samu_new( p
->mem_ctx
)) ) {
2259 return NT_STATUS_NO_MEMORY
;
2262 /* append the user's RID to it */
2264 if (!sid_compose(&sid
, &dinfo
->sid
, r
->in
.rid
))
2265 return NT_STATUS_NO_SUCH_USER
;
2267 /* check if access can be granted as requested by client. */
2268 map_max_allowed_access(p
->server_info
->ptok
,
2269 &p
->server_info
->utok
,
2272 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
, &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
2273 se_map_generic(&des_access
, &usr_generic_mapping
);
2276 * Get the sampass first as we need to check privileges
2277 * based on what kind of user object this is.
2278 * But don't reveal info too early if it didn't exist.
2282 ret
=pdb_getsampwsid(sampass
, &sid
);
2285 se_priv_copy(&se_rights
, &se_priv_none
);
2288 * We do the override access checks on *open*, not at
2292 uint32_t acb_info
= pdb_get_acct_ctrl(sampass
);
2294 if ((acb_info
& ACB_WSTRUST
) &&
2295 user_has_any_privilege(p
->server_info
->ptok
,
2296 &se_machine_account
)) {
2298 * SeMachineAccount is needed to add
2299 * GENERIC_RIGHTS_USER_WRITE to a machine
2302 se_priv_add(&se_rights
, &se_machine_account
);
2303 DEBUG(10,("_samr_OpenUser: adding machine account "
2304 "rights to handle for user %s\n",
2305 pdb_get_username(sampass
) ));
2307 if ((acb_info
& ACB_NORMAL
) &&
2308 user_has_any_privilege(p
->server_info
->ptok
,
2311 * SeAddUsers is needed to add
2312 * GENERIC_RIGHTS_USER_WRITE to a normal
2315 se_priv_add(&se_rights
, &se_add_users
);
2316 DEBUG(10,("_samr_OpenUser: adding add user "
2317 "rights to handle for user %s\n",
2318 pdb_get_username(sampass
) ));
2321 * Cheat - allow GENERIC_RIGHTS_USER_WRITE if pipe user is
2322 * in DOMAIN_RID_ADMINS. This is almost certainly not
2323 * what Windows does but is a hack for people who haven't
2324 * set up privileges on groups in Samba.
2326 if (acb_info
& (ACB_SVRTRUST
|ACB_DOMTRUST
)) {
2327 if (lp_enable_privileges() && nt_token_check_domain_rid(p
->server_info
->ptok
,
2328 DOMAIN_RID_ADMINS
)) {
2329 des_access
&= ~GENERIC_RIGHTS_USER_WRITE
;
2330 extra_access
= GENERIC_RIGHTS_USER_WRITE
;
2331 DEBUG(4,("_samr_OpenUser: Allowing "
2332 "GENERIC_RIGHTS_USER_WRITE for "
2338 TALLOC_FREE(sampass
);
2340 nt_status
= access_check_object(psd
, p
->server_info
->ptok
,
2341 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
2342 &acc_granted
, "_samr_OpenUser");
2344 if ( !NT_STATUS_IS_OK(nt_status
) )
2347 /* check that the SID exists in our domain. */
2349 return NT_STATUS_NO_SUCH_USER
;
2352 /* If we did the rid admins hack above, allow access. */
2353 acc_granted
|= extra_access
;
2355 uinfo
= policy_handle_create(p
, r
->out
.user_handle
, acc_granted
,
2356 struct samr_user_info
, &nt_status
);
2357 if (!NT_STATUS_IS_OK(nt_status
)) {
2362 return NT_STATUS_OK
;
2365 /*************************************************************************
2366 *************************************************************************/
2368 static NTSTATUS
init_samr_parameters_string(TALLOC_CTX
*mem_ctx
,
2370 struct lsa_BinaryString
**_r
)
2372 struct lsa_BinaryString
*r
;
2375 return NT_STATUS_INVALID_PARAMETER
;
2378 r
= TALLOC_ZERO_P(mem_ctx
, struct lsa_BinaryString
);
2380 return NT_STATUS_NO_MEMORY
;
2383 r
->array
= TALLOC_ZERO_ARRAY(mem_ctx
, uint16_t, blob
->length
/2);
2385 return NT_STATUS_NO_MEMORY
;
2387 memcpy(r
->array
, blob
->data
, blob
->length
);
2388 r
->size
= blob
->length
;
2389 r
->length
= blob
->length
;
2392 return NT_STATUS_NO_MEMORY
;
2397 return NT_STATUS_OK
;
2400 /*************************************************************************
2401 *************************************************************************/
2403 static struct samr_LogonHours
get_logon_hours_from_pdb(TALLOC_CTX
*mem_ctx
,
2406 struct samr_LogonHours hours
;
2407 const int units_per_week
= 168;
2410 hours
.bits
= talloc_array(mem_ctx
, uint8_t, units_per_week
);
2415 hours
.units_per_week
= units_per_week
;
2416 memset(hours
.bits
, 0xFF, units_per_week
);
2418 if (pdb_get_hours(pw
)) {
2419 memcpy(hours
.bits
, pdb_get_hours(pw
),
2420 MIN(pdb_get_hours_len(pw
), units_per_week
));
2426 /*************************************************************************
2428 *************************************************************************/
2430 static NTSTATUS
get_user_info_1(TALLOC_CTX
*mem_ctx
,
2431 struct samr_UserInfo1
*r
,
2433 struct dom_sid
*domain_sid
)
2435 const struct dom_sid
*sid_group
;
2436 uint32_t primary_gid
;
2439 sid_group
= pdb_get_group_sid(pw
);
2442 if (!sid_peek_check_rid(domain_sid
, sid_group
, &primary_gid
)) {
2443 DEBUG(0, ("get_user_info_1: User %s has Primary Group SID %s, \n"
2444 "which conflicts with the domain sid %s. Failing operation.\n",
2445 pdb_get_username(pw
), sid_string_dbg(sid_group
),
2446 sid_string_dbg(domain_sid
)));
2447 return NT_STATUS_UNSUCCESSFUL
;
2450 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2451 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2452 r
->primary_gid
= primary_gid
;
2453 r
->description
.string
= talloc_strdup(mem_ctx
, pdb_get_acct_desc(pw
));
2454 r
->comment
.string
= talloc_strdup(mem_ctx
, pdb_get_comment(pw
));
2456 return NT_STATUS_OK
;
2459 /*************************************************************************
2461 *************************************************************************/
2463 static NTSTATUS
get_user_info_2(TALLOC_CTX
*mem_ctx
,
2464 struct samr_UserInfo2
*r
,
2467 r
->comment
.string
= talloc_strdup(mem_ctx
, pdb_get_comment(pw
));
2468 r
->reserved
.string
= NULL
;
2469 r
->country_code
= 0;
2472 return NT_STATUS_OK
;
2475 /*************************************************************************
2477 *************************************************************************/
2479 static NTSTATUS
get_user_info_3(TALLOC_CTX
*mem_ctx
,
2480 struct samr_UserInfo3
*r
,
2482 struct dom_sid
*domain_sid
)
2484 const struct dom_sid
*sid_user
, *sid_group
;
2485 uint32_t rid
, primary_gid
;
2487 sid_user
= pdb_get_user_sid(pw
);
2489 if (!sid_peek_check_rid(domain_sid
, sid_user
, &rid
)) {
2490 DEBUG(0, ("get_user_info_3: User %s has SID %s, \nwhich conflicts with "
2491 "the domain sid %s. Failing operation.\n",
2492 pdb_get_username(pw
), sid_string_dbg(sid_user
),
2493 sid_string_dbg(domain_sid
)));
2494 return NT_STATUS_UNSUCCESSFUL
;
2498 sid_group
= pdb_get_group_sid(pw
);
2501 if (!sid_peek_check_rid(domain_sid
, sid_group
, &primary_gid
)) {
2502 DEBUG(0, ("get_user_info_3: User %s has Primary Group SID %s, \n"
2503 "which conflicts with the domain sid %s. Failing operation.\n",
2504 pdb_get_username(pw
), sid_string_dbg(sid_group
),
2505 sid_string_dbg(domain_sid
)));
2506 return NT_STATUS_UNSUCCESSFUL
;
2509 unix_to_nt_time(&r
->last_logon
, pdb_get_logon_time(pw
));
2510 unix_to_nt_time(&r
->last_logoff
, pdb_get_logoff_time(pw
));
2511 unix_to_nt_time(&r
->last_password_change
, pdb_get_pass_last_set_time(pw
));
2512 unix_to_nt_time(&r
->allow_password_change
, pdb_get_pass_can_change_time(pw
));
2513 unix_to_nt_time(&r
->force_password_change
, pdb_get_pass_must_change_time(pw
));
2515 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2516 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2517 r
->home_directory
.string
= talloc_strdup(mem_ctx
, pdb_get_homedir(pw
));
2518 r
->home_drive
.string
= talloc_strdup(mem_ctx
, pdb_get_dir_drive(pw
));
2519 r
->logon_script
.string
= talloc_strdup(mem_ctx
, pdb_get_logon_script(pw
));
2520 r
->profile_path
.string
= talloc_strdup(mem_ctx
, pdb_get_profile_path(pw
));
2521 r
->workstations
.string
= talloc_strdup(mem_ctx
, pdb_get_workstations(pw
));
2523 r
->logon_hours
= get_logon_hours_from_pdb(mem_ctx
, pw
);
2525 r
->primary_gid
= primary_gid
;
2526 r
->acct_flags
= pdb_get_acct_ctrl(pw
);
2527 r
->bad_password_count
= pdb_get_bad_password_count(pw
);
2528 r
->logon_count
= pdb_get_logon_count(pw
);
2530 return NT_STATUS_OK
;
2533 /*************************************************************************
2535 *************************************************************************/
2537 static NTSTATUS
get_user_info_4(TALLOC_CTX
*mem_ctx
,
2538 struct samr_UserInfo4
*r
,
2541 r
->logon_hours
= get_logon_hours_from_pdb(mem_ctx
, pw
);
2543 return NT_STATUS_OK
;
2546 /*************************************************************************
2548 *************************************************************************/
2550 static NTSTATUS
get_user_info_5(TALLOC_CTX
*mem_ctx
,
2551 struct samr_UserInfo5
*r
,
2553 struct dom_sid
*domain_sid
)
2555 const struct dom_sid
*sid_user
, *sid_group
;
2556 uint32_t rid
, primary_gid
;
2558 sid_user
= pdb_get_user_sid(pw
);
2560 if (!sid_peek_check_rid(domain_sid
, sid_user
, &rid
)) {
2561 DEBUG(0, ("get_user_info_5: User %s has SID %s, \nwhich conflicts with "
2562 "the domain sid %s. Failing operation.\n",
2563 pdb_get_username(pw
), sid_string_dbg(sid_user
),
2564 sid_string_dbg(domain_sid
)));
2565 return NT_STATUS_UNSUCCESSFUL
;
2569 sid_group
= pdb_get_group_sid(pw
);
2572 if (!sid_peek_check_rid(domain_sid
, sid_group
, &primary_gid
)) {
2573 DEBUG(0, ("get_user_info_5: User %s has Primary Group SID %s, \n"
2574 "which conflicts with the domain sid %s. Failing operation.\n",
2575 pdb_get_username(pw
), sid_string_dbg(sid_group
),
2576 sid_string_dbg(domain_sid
)));
2577 return NT_STATUS_UNSUCCESSFUL
;
2580 unix_to_nt_time(&r
->last_logon
, pdb_get_logon_time(pw
));
2581 unix_to_nt_time(&r
->last_logoff
, pdb_get_logoff_time(pw
));
2582 unix_to_nt_time(&r
->acct_expiry
, pdb_get_kickoff_time(pw
));
2583 unix_to_nt_time(&r
->last_password_change
, pdb_get_pass_last_set_time(pw
));
2585 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2586 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2587 r
->home_directory
.string
= talloc_strdup(mem_ctx
, pdb_get_homedir(pw
));
2588 r
->home_drive
.string
= talloc_strdup(mem_ctx
, pdb_get_dir_drive(pw
));
2589 r
->logon_script
.string
= talloc_strdup(mem_ctx
, pdb_get_logon_script(pw
));
2590 r
->profile_path
.string
= talloc_strdup(mem_ctx
, pdb_get_profile_path(pw
));
2591 r
->description
.string
= talloc_strdup(mem_ctx
, pdb_get_acct_desc(pw
));
2592 r
->workstations
.string
= talloc_strdup(mem_ctx
, pdb_get_workstations(pw
));
2594 r
->logon_hours
= get_logon_hours_from_pdb(mem_ctx
, pw
);
2596 r
->primary_gid
= primary_gid
;
2597 r
->acct_flags
= pdb_get_acct_ctrl(pw
);
2598 r
->bad_password_count
= pdb_get_bad_password_count(pw
);
2599 r
->logon_count
= pdb_get_logon_count(pw
);
2601 return NT_STATUS_OK
;
2604 /*************************************************************************
2606 *************************************************************************/
2608 static NTSTATUS
get_user_info_6(TALLOC_CTX
*mem_ctx
,
2609 struct samr_UserInfo6
*r
,
2612 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2613 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2615 return NT_STATUS_OK
;
2618 /*************************************************************************
2619 get_user_info_7. Safe. Only gives out account_name.
2620 *************************************************************************/
2622 static NTSTATUS
get_user_info_7(TALLOC_CTX
*mem_ctx
,
2623 struct samr_UserInfo7
*r
,
2624 struct samu
*smbpass
)
2626 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(smbpass
));
2627 if (!r
->account_name
.string
) {
2628 return NT_STATUS_NO_MEMORY
;
2631 return NT_STATUS_OK
;
2634 /*************************************************************************
2636 *************************************************************************/
2638 static NTSTATUS
get_user_info_8(TALLOC_CTX
*mem_ctx
,
2639 struct samr_UserInfo8
*r
,
2642 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2644 return NT_STATUS_OK
;
2647 /*************************************************************************
2648 get_user_info_9. Only gives out primary group SID.
2649 *************************************************************************/
2651 static NTSTATUS
get_user_info_9(TALLOC_CTX
*mem_ctx
,
2652 struct samr_UserInfo9
*r
,
2653 struct samu
*smbpass
)
2655 r
->primary_gid
= pdb_get_group_rid(smbpass
);
2657 return NT_STATUS_OK
;
2660 /*************************************************************************
2662 *************************************************************************/
2664 static NTSTATUS
get_user_info_10(TALLOC_CTX
*mem_ctx
,
2665 struct samr_UserInfo10
*r
,
2668 r
->home_directory
.string
= talloc_strdup(mem_ctx
, pdb_get_homedir(pw
));
2669 r
->home_drive
.string
= talloc_strdup(mem_ctx
, pdb_get_dir_drive(pw
));
2671 return NT_STATUS_OK
;
2674 /*************************************************************************
2676 *************************************************************************/
2678 static NTSTATUS
get_user_info_11(TALLOC_CTX
*mem_ctx
,
2679 struct samr_UserInfo11
*r
,
2682 r
->logon_script
.string
= talloc_strdup(mem_ctx
, pdb_get_logon_script(pw
));
2684 return NT_STATUS_OK
;
2687 /*************************************************************************
2689 *************************************************************************/
2691 static NTSTATUS
get_user_info_12(TALLOC_CTX
*mem_ctx
,
2692 struct samr_UserInfo12
*r
,
2695 r
->profile_path
.string
= talloc_strdup(mem_ctx
, pdb_get_profile_path(pw
));
2697 return NT_STATUS_OK
;
2700 /*************************************************************************
2702 *************************************************************************/
2704 static NTSTATUS
get_user_info_13(TALLOC_CTX
*mem_ctx
,
2705 struct samr_UserInfo13
*r
,
2708 r
->description
.string
= talloc_strdup(mem_ctx
, pdb_get_acct_desc(pw
));
2710 return NT_STATUS_OK
;
2713 /*************************************************************************
2715 *************************************************************************/
2717 static NTSTATUS
get_user_info_14(TALLOC_CTX
*mem_ctx
,
2718 struct samr_UserInfo14
*r
,
2721 r
->workstations
.string
= talloc_strdup(mem_ctx
, pdb_get_workstations(pw
));
2723 return NT_STATUS_OK
;
2726 /*************************************************************************
2727 get_user_info_16. Safe. Only gives out acb bits.
2728 *************************************************************************/
2730 static NTSTATUS
get_user_info_16(TALLOC_CTX
*mem_ctx
,
2731 struct samr_UserInfo16
*r
,
2732 struct samu
*smbpass
)
2734 r
->acct_flags
= pdb_get_acct_ctrl(smbpass
);
2736 return NT_STATUS_OK
;
2739 /*************************************************************************
2741 *************************************************************************/
2743 static NTSTATUS
get_user_info_17(TALLOC_CTX
*mem_ctx
,
2744 struct samr_UserInfo17
*r
,
2747 unix_to_nt_time(&r
->acct_expiry
, pdb_get_kickoff_time(pw
));
2749 return NT_STATUS_OK
;
2752 /*************************************************************************
2753 get_user_info_18. OK - this is the killer as it gives out password info.
2754 Ensure that this is only allowed on an encrypted connection with a root
2756 *************************************************************************/
2758 static NTSTATUS
get_user_info_18(struct pipes_struct
*p
,
2759 TALLOC_CTX
*mem_ctx
,
2760 struct samr_UserInfo18
*r
,
2761 struct dom_sid
*user_sid
)
2763 struct samu
*smbpass
=NULL
;
2765 const uint8_t *nt_pass
= NULL
;
2766 const uint8_t *lm_pass
= NULL
;
2770 if (p
->server_info
->system
) {
2774 if ((p
->auth
.auth_type
!= DCERPC_AUTH_TYPE_NTLMSSP
) ||
2775 ((p
->auth
.auth_type
== DCERPC_AUTH_TYPE_SPNEGO
) &&
2776 (p
->auth
.spnego_type
!= PIPE_AUTH_TYPE_SPNEGO_NTLMSSP
))) {
2777 return NT_STATUS_ACCESS_DENIED
;
2780 if (p
->auth
.auth_level
!= DCERPC_AUTH_LEVEL_PRIVACY
) {
2781 return NT_STATUS_ACCESS_DENIED
;
2786 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
2789 if ( !(smbpass
= samu_new( mem_ctx
)) ) {
2790 return NT_STATUS_NO_MEMORY
;
2793 ret
= pdb_getsampwsid(smbpass
, user_sid
);
2796 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid
)));
2797 TALLOC_FREE(smbpass
);
2798 return (geteuid() == sec_initial_uid()) ? NT_STATUS_NO_SUCH_USER
: NT_STATUS_ACCESS_DENIED
;
2801 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass
), pdb_get_acct_ctrl(smbpass
) ));
2803 if ( pdb_get_acct_ctrl(smbpass
) & ACB_DISABLED
) {
2804 TALLOC_FREE(smbpass
);
2805 return NT_STATUS_ACCOUNT_DISABLED
;
2808 lm_pass
= pdb_get_lanman_passwd(smbpass
);
2809 if (lm_pass
!= NULL
) {
2810 memcpy(r
->lm_pwd
.hash
, lm_pass
, 16);
2811 r
->lm_pwd_active
= true;
2814 nt_pass
= pdb_get_nt_passwd(smbpass
);
2815 if (nt_pass
!= NULL
) {
2816 memcpy(r
->nt_pwd
.hash
, nt_pass
, 16);
2817 r
->nt_pwd_active
= true;
2819 r
->password_expired
= 0; /* FIXME */
2821 TALLOC_FREE(smbpass
);
2823 return NT_STATUS_OK
;
2826 /*************************************************************************
2828 *************************************************************************/
2830 static NTSTATUS
get_user_info_20(TALLOC_CTX
*mem_ctx
,
2831 struct samr_UserInfo20
*r
,
2832 struct samu
*sampass
)
2834 const char *munged_dial
= NULL
;
2837 struct lsa_BinaryString
*parameters
= NULL
;
2841 munged_dial
= pdb_get_munged_dial(sampass
);
2843 DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass
),
2844 munged_dial
, (int)strlen(munged_dial
)));
2847 blob
= base64_decode_data_blob(munged_dial
);
2849 blob
= data_blob_string_const_null("");
2852 status
= init_samr_parameters_string(mem_ctx
, &blob
, ¶meters
);
2853 data_blob_free(&blob
);
2854 if (!NT_STATUS_IS_OK(status
)) {
2858 r
->parameters
= *parameters
;
2860 return NT_STATUS_OK
;
2864 /*************************************************************************
2866 *************************************************************************/
2868 static NTSTATUS
get_user_info_21(TALLOC_CTX
*mem_ctx
,
2869 struct samr_UserInfo21
*r
,
2871 struct dom_sid
*domain_sid
,
2872 uint32_t acc_granted
)
2875 const struct dom_sid
*sid_user
, *sid_group
;
2876 uint32_t rid
, primary_gid
;
2877 NTTIME force_password_change
;
2878 time_t must_change_time
;
2879 struct lsa_BinaryString
*parameters
= NULL
;
2880 const char *munged_dial
= NULL
;
2885 sid_user
= pdb_get_user_sid(pw
);
2887 if (!sid_peek_check_rid(domain_sid
, sid_user
, &rid
)) {
2888 DEBUG(0, ("get_user_info_21: User %s has SID %s, \nwhich conflicts with "
2889 "the domain sid %s. Failing operation.\n",
2890 pdb_get_username(pw
), sid_string_dbg(sid_user
),
2891 sid_string_dbg(domain_sid
)));
2892 return NT_STATUS_UNSUCCESSFUL
;
2896 sid_group
= pdb_get_group_sid(pw
);
2899 if (!sid_peek_check_rid(domain_sid
, sid_group
, &primary_gid
)) {
2900 DEBUG(0, ("get_user_info_21: User %s has Primary Group SID %s, \n"
2901 "which conflicts with the domain sid %s. Failing operation.\n",
2902 pdb_get_username(pw
), sid_string_dbg(sid_group
),
2903 sid_string_dbg(domain_sid
)));
2904 return NT_STATUS_UNSUCCESSFUL
;
2907 unix_to_nt_time(&r
->last_logon
, pdb_get_logon_time(pw
));
2908 unix_to_nt_time(&r
->last_logoff
, pdb_get_logoff_time(pw
));
2909 unix_to_nt_time(&r
->acct_expiry
, pdb_get_kickoff_time(pw
));
2910 unix_to_nt_time(&r
->last_password_change
, pdb_get_pass_last_set_time(pw
));
2911 unix_to_nt_time(&r
->allow_password_change
, pdb_get_pass_can_change_time(pw
));
2913 must_change_time
= pdb_get_pass_must_change_time(pw
);
2914 if (must_change_time
== get_time_t_max()) {
2915 unix_to_nt_time_abs(&force_password_change
, must_change_time
);
2917 unix_to_nt_time(&force_password_change
, must_change_time
);
2920 munged_dial
= pdb_get_munged_dial(pw
);
2922 blob
= base64_decode_data_blob(munged_dial
);
2924 blob
= data_blob_string_const_null("");
2927 status
= init_samr_parameters_string(mem_ctx
, &blob
, ¶meters
);
2928 data_blob_free(&blob
);
2929 if (!NT_STATUS_IS_OK(status
)) {
2933 r
->force_password_change
= force_password_change
;
2935 r
->account_name
.string
= talloc_strdup(mem_ctx
, pdb_get_username(pw
));
2936 r
->full_name
.string
= talloc_strdup(mem_ctx
, pdb_get_fullname(pw
));
2937 r
->home_directory
.string
= talloc_strdup(mem_ctx
, pdb_get_homedir(pw
));
2938 r
->home_drive
.string
= talloc_strdup(mem_ctx
, pdb_get_dir_drive(pw
));
2939 r
->logon_script
.string
= talloc_strdup(mem_ctx
, pdb_get_logon_script(pw
));
2940 r
->profile_path
.string
= talloc_strdup(mem_ctx
, pdb_get_profile_path(pw
));
2941 r
->description
.string
= talloc_strdup(mem_ctx
, pdb_get_acct_desc(pw
));
2942 r
->workstations
.string
= talloc_strdup(mem_ctx
, pdb_get_workstations(pw
));
2943 r
->comment
.string
= talloc_strdup(mem_ctx
, pdb_get_comment(pw
));
2945 r
->logon_hours
= get_logon_hours_from_pdb(mem_ctx
, pw
);
2946 r
->parameters
= *parameters
;
2948 r
->primary_gid
= primary_gid
;
2949 r
->acct_flags
= pdb_get_acct_ctrl(pw
);
2950 r
->bad_password_count
= pdb_get_bad_password_count(pw
);
2951 r
->logon_count
= pdb_get_logon_count(pw
);
2952 r
->fields_present
= pdb_build_fields_present(pw
);
2953 r
->password_expired
= (pdb_get_pass_must_change_time(pw
) == 0) ?
2954 PASS_MUST_CHANGE_AT_NEXT_LOGON
: 0;
2955 r
->country_code
= 0;
2957 r
->lm_password_set
= 0;
2958 r
->nt_password_set
= 0;
2963 Look at a user on a real NT4 PDC with usrmgr, press
2964 'ok'. Then you will see that fields_present is set to
2965 0x08f827fa. Look at the user immediately after that again,
2966 and you will see that 0x00fffff is returned. This solves
2967 the problem that you get access denied after having looked
2975 return NT_STATUS_OK
;
2978 /*******************************************************************
2980 ********************************************************************/
2982 NTSTATUS
_samr_QueryUserInfo(struct pipes_struct
*p
,
2983 struct samr_QueryUserInfo
*r
)
2986 union samr_UserInfo
*user_info
= NULL
;
2987 struct samr_user_info
*uinfo
;
2988 struct dom_sid domain_sid
;
2991 struct samu
*pwd
= NULL
;
2992 uint32_t acc_required
, acc_granted
;
2994 switch (r
->in
.level
) {
2995 case 1: /* UserGeneralInformation */
2996 /* USER_READ_GENERAL */
2997 acc_required
= SAMR_USER_ACCESS_GET_NAME_ETC
;
2999 case 2: /* UserPreferencesInformation */
3000 /* USER_READ_PREFERENCES | USER_READ_GENERAL */
3001 acc_required
= SAMR_USER_ACCESS_GET_LOCALE
|
3002 SAMR_USER_ACCESS_GET_NAME_ETC
;
3004 case 3: /* UserLogonInformation */
3005 /* USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT */
3006 acc_required
= SAMR_USER_ACCESS_GET_NAME_ETC
|
3007 SAMR_USER_ACCESS_GET_LOCALE
|
3008 SAMR_USER_ACCESS_GET_LOGONINFO
|
3009 SAMR_USER_ACCESS_GET_ATTRIBUTES
;
3011 case 4: /* UserLogonHoursInformation */
3012 /* USER_READ_LOGON */
3013 acc_required
= SAMR_USER_ACCESS_GET_LOGONINFO
;
3015 case 5: /* UserAccountInformation */
3016 /* USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT */
3017 acc_required
= SAMR_USER_ACCESS_GET_NAME_ETC
|
3018 SAMR_USER_ACCESS_GET_LOCALE
|
3019 SAMR_USER_ACCESS_GET_LOGONINFO
|
3020 SAMR_USER_ACCESS_GET_ATTRIBUTES
;
3022 case 6: /* UserNameInformation */
3023 case 7: /* UserAccountNameInformation */
3024 case 8: /* UserFullNameInformation */
3025 case 9: /* UserPrimaryGroupInformation */
3026 case 13: /* UserAdminCommentInformation */
3027 /* USER_READ_GENERAL */
3028 acc_required
= SAMR_USER_ACCESS_GET_NAME_ETC
;
3030 case 10: /* UserHomeInformation */
3031 case 11: /* UserScriptInformation */
3032 case 12: /* UserProfileInformation */
3033 case 14: /* UserWorkStationsInformation */
3034 /* USER_READ_LOGON */
3035 acc_required
= SAMR_USER_ACCESS_GET_LOGONINFO
;
3037 case 16: /* UserControlInformation */
3038 case 17: /* UserExpiresInformation */
3039 case 20: /* UserParametersInformation */
3040 /* USER_READ_ACCOUNT */
3041 acc_required
= SAMR_USER_ACCESS_GET_ATTRIBUTES
;
3043 case 21: /* UserAllInformation */
3045 acc_required
= SAMR_USER_ACCESS_GET_ATTRIBUTES
;
3047 case 18: /* UserInternal1Information */
3049 acc_required
= SAMR_USER_ACCESS_GET_ATTRIBUTES
;
3051 case 23: /* UserInternal4Information */
3052 case 24: /* UserInternal4InformationNew */
3053 case 25: /* UserInternal4InformationNew */
3054 case 26: /* UserInternal5InformationNew */
3056 return NT_STATUS_INVALID_INFO_CLASS
;
3060 uinfo
= policy_handle_find(p
, r
->in
.user_handle
,
3061 acc_required
, &acc_granted
,
3062 struct samr_user_info
, &status
);
3063 if (!NT_STATUS_IS_OK(status
)) {
3067 domain_sid
= uinfo
->sid
;
3069 sid_split_rid(&domain_sid
, &rid
);
3071 if (!sid_check_is_in_our_domain(&uinfo
->sid
))
3072 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
3074 DEBUG(5,("_samr_QueryUserInfo: sid:%s\n",
3075 sid_string_dbg(&uinfo
->sid
)));
3077 user_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_UserInfo
);
3079 return NT_STATUS_NO_MEMORY
;
3082 DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r
->in
.level
));
3084 if (!(pwd
= samu_new(p
->mem_ctx
))) {
3085 return NT_STATUS_NO_MEMORY
;
3089 ret
= pdb_getsampwsid(pwd
, &uinfo
->sid
);
3093 DEBUG(4,("User %s not found\n", sid_string_dbg(&uinfo
->sid
)));
3095 return NT_STATUS_NO_SUCH_USER
;
3098 DEBUG(3,("User:[%s]\n", pdb_get_username(pwd
)));
3100 samr_clear_sam_passwd(pwd
);
3102 switch (r
->in
.level
) {
3104 status
= get_user_info_1(p
->mem_ctx
, &user_info
->info1
, pwd
, &domain_sid
);
3107 status
= get_user_info_2(p
->mem_ctx
, &user_info
->info2
, pwd
);
3110 status
= get_user_info_3(p
->mem_ctx
, &user_info
->info3
, pwd
, &domain_sid
);
3113 status
= get_user_info_4(p
->mem_ctx
, &user_info
->info4
, pwd
);
3116 status
= get_user_info_5(p
->mem_ctx
, &user_info
->info5
, pwd
, &domain_sid
);
3119 status
= get_user_info_6(p
->mem_ctx
, &user_info
->info6
, pwd
);
3122 status
= get_user_info_7(p
->mem_ctx
, &user_info
->info7
, pwd
);
3125 status
= get_user_info_8(p
->mem_ctx
, &user_info
->info8
, pwd
);
3128 status
= get_user_info_9(p
->mem_ctx
, &user_info
->info9
, pwd
);
3131 status
= get_user_info_10(p
->mem_ctx
, &user_info
->info10
, pwd
);
3134 status
= get_user_info_11(p
->mem_ctx
, &user_info
->info11
, pwd
);
3137 status
= get_user_info_12(p
->mem_ctx
, &user_info
->info12
, pwd
);
3140 status
= get_user_info_13(p
->mem_ctx
, &user_info
->info13
, pwd
);
3143 status
= get_user_info_14(p
->mem_ctx
, &user_info
->info14
, pwd
);
3146 status
= get_user_info_16(p
->mem_ctx
, &user_info
->info16
, pwd
);
3149 status
= get_user_info_17(p
->mem_ctx
, &user_info
->info17
, pwd
);
3152 /* level 18 is special */
3153 status
= get_user_info_18(p
, p
->mem_ctx
, &user_info
->info18
,
3157 status
= get_user_info_20(p
->mem_ctx
, &user_info
->info20
, pwd
);
3160 status
= get_user_info_21(p
->mem_ctx
, &user_info
->info21
, pwd
, &domain_sid
, acc_granted
);
3163 status
= NT_STATUS_INVALID_INFO_CLASS
;
3167 if (!NT_STATUS_IS_OK(status
)) {
3171 *r
->out
.info
= user_info
;
3176 DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__
));
3181 /****************************************************************
3182 ****************************************************************/
3184 NTSTATUS
_samr_QueryUserInfo2(struct pipes_struct
*p
,
3185 struct samr_QueryUserInfo2
*r
)
3187 struct samr_QueryUserInfo u
;
3189 u
.in
.user_handle
= r
->in
.user_handle
;
3190 u
.in
.level
= r
->in
.level
;
3191 u
.out
.info
= r
->out
.info
;
3193 return _samr_QueryUserInfo(p
, &u
);
3196 /*******************************************************************
3197 _samr_GetGroupsForUser
3198 ********************************************************************/
3200 NTSTATUS
_samr_GetGroupsForUser(struct pipes_struct
*p
,
3201 struct samr_GetGroupsForUser
*r
)
3203 struct samr_user_info
*uinfo
;
3204 struct samu
*sam_pass
=NULL
;
3205 struct dom_sid
*sids
;
3206 struct samr_RidWithAttribute dom_gid
;
3207 struct samr_RidWithAttribute
*gids
= NULL
;
3208 uint32 primary_group_rid
;
3209 size_t num_groups
= 0;
3214 bool success
= False
;
3216 struct samr_RidWithAttributeArray
*rids
= NULL
;
3219 * from the SID in the request:
3220 * we should send back the list of DOMAIN GROUPS
3221 * the user is a member of
3223 * and only the DOMAIN GROUPS
3224 * no ALIASES !!! neither aliases of the domain
3225 * nor aliases of the builtin SID
3230 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__
));
3232 uinfo
= policy_handle_find(p
, r
->in
.user_handle
,
3233 SAMR_USER_ACCESS_GET_GROUPS
, NULL
,
3234 struct samr_user_info
, &result
);
3235 if (!NT_STATUS_IS_OK(result
)) {
3239 rids
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_RidWithAttributeArray
);
3241 return NT_STATUS_NO_MEMORY
;
3244 if (!sid_check_is_in_our_domain(&uinfo
->sid
))
3245 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
3247 if ( !(sam_pass
= samu_new( p
->mem_ctx
)) ) {
3248 return NT_STATUS_NO_MEMORY
;
3252 ret
= pdb_getsampwsid(sam_pass
, &uinfo
->sid
);
3256 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
3257 sid_string_dbg(&uinfo
->sid
)));
3258 return NT_STATUS_NO_SUCH_USER
;
3263 /* make both calls inside the root block */
3265 result
= pdb_enum_group_memberships(p
->mem_ctx
, sam_pass
,
3266 &sids
, &unix_gids
, &num_groups
);
3267 if ( NT_STATUS_IS_OK(result
) ) {
3268 success
= sid_peek_check_rid(get_global_sam_sid(),
3269 pdb_get_group_sid(sam_pass
),
3270 &primary_group_rid
);
3274 if (!NT_STATUS_IS_OK(result
)) {
3275 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
3276 sid_string_dbg(&uinfo
->sid
)));
3281 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
3282 sid_string_dbg(pdb_get_group_sid(sam_pass
)),
3283 pdb_get_username(sam_pass
)));
3284 TALLOC_FREE(sam_pass
);
3285 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
3291 dom_gid
.attributes
= (SE_GROUP_MANDATORY
|SE_GROUP_ENABLED_BY_DEFAULT
|
3293 dom_gid
.rid
= primary_group_rid
;
3294 ADD_TO_ARRAY(p
->mem_ctx
, struct samr_RidWithAttribute
, dom_gid
, &gids
, &num_gids
);
3296 for (i
=0; i
<num_groups
; i
++) {
3298 if (!sid_peek_check_rid(get_global_sam_sid(),
3299 &(sids
[i
]), &dom_gid
.rid
)) {
3300 DEBUG(10, ("Found sid %s not in our domain\n",
3301 sid_string_dbg(&sids
[i
])));
3305 if (dom_gid
.rid
== primary_group_rid
) {
3306 /* We added the primary group directly from the
3307 * sam_account. The other SIDs are unique from
3308 * enum_group_memberships */
3312 ADD_TO_ARRAY(p
->mem_ctx
, struct samr_RidWithAttribute
, dom_gid
, &gids
, &num_gids
);
3315 rids
->count
= num_gids
;
3318 *r
->out
.rids
= rids
;
3320 DEBUG(5,("_samr_GetGroupsForUser: %d\n", __LINE__
));
3325 /*******************************************************************
3326 ********************************************************************/
3328 static uint32_t samr_get_server_role(void)
3330 uint32_t role
= ROLE_DOMAIN_PDC
;
3332 if (lp_server_role() == ROLE_DOMAIN_BDC
) {
3333 role
= ROLE_DOMAIN_BDC
;
3339 /*******************************************************************
3340 ********************************************************************/
3342 static NTSTATUS
query_dom_info_1(TALLOC_CTX
*mem_ctx
,
3343 struct samr_DomInfo1
*r
)
3345 uint32_t account_policy_temp
;
3346 time_t u_expire
, u_min_age
;
3352 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_LEN
, &account_policy_temp
);
3353 r
->min_password_length
= account_policy_temp
;
3355 pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY
, &account_policy_temp
);
3356 r
->password_history_length
= account_policy_temp
;
3358 pdb_get_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS
,
3359 &r
->password_properties
);
3361 pdb_get_account_policy(PDB_POLICY_MAX_PASSWORD_AGE
, &account_policy_temp
);
3362 u_expire
= account_policy_temp
;
3364 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_AGE
, &account_policy_temp
);
3365 u_min_age
= account_policy_temp
;
3371 unix_to_nt_time_abs((NTTIME
*)&r
->max_password_age
, u_expire
);
3372 unix_to_nt_time_abs((NTTIME
*)&r
->min_password_age
, u_min_age
);
3374 if (lp_check_password_script() && *lp_check_password_script()) {
3375 r
->password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
3378 return NT_STATUS_OK
;
3381 /*******************************************************************
3382 ********************************************************************/
3384 static NTSTATUS
query_dom_info_2(TALLOC_CTX
*mem_ctx
,
3385 struct samr_DomGeneralInformation
*r
,
3386 struct samr_domain_info
*dinfo
)
3395 r
->num_users
= count_sam_users(dinfo
->disp_info
, ACB_NORMAL
);
3396 r
->num_groups
= count_sam_groups(dinfo
->disp_info
);
3397 r
->num_aliases
= count_sam_aliases(dinfo
->disp_info
);
3399 pdb_get_account_policy(PDB_POLICY_TIME_TO_LOGOUT
, &u_logout
);
3401 unix_to_nt_time_abs(&r
->force_logoff_time
, u_logout
);
3403 if (!pdb_get_seq_num(&seq_num
)) {
3404 seq_num
= time(NULL
);
3411 r
->oem_information
.string
= lp_serverstring();
3412 r
->domain_name
.string
= lp_workgroup();
3413 r
->primary
.string
= global_myname();
3414 r
->sequence_num
= seq_num
;
3415 r
->domain_server_state
= DOMAIN_SERVER_ENABLED
;
3416 r
->role
= samr_get_server_role();
3419 return NT_STATUS_OK
;
3422 /*******************************************************************
3423 ********************************************************************/
3425 static NTSTATUS
query_dom_info_3(TALLOC_CTX
*mem_ctx
,
3426 struct samr_DomInfo3
*r
)
3436 pdb_get_account_policy(PDB_POLICY_TIME_TO_LOGOUT
, &ul
);
3437 u_logout
= (time_t)ul
;
3444 unix_to_nt_time_abs(&r
->force_logoff_time
, u_logout
);
3446 return NT_STATUS_OK
;
3449 /*******************************************************************
3450 ********************************************************************/
3452 static NTSTATUS
query_dom_info_4(TALLOC_CTX
*mem_ctx
,
3453 struct samr_DomOEMInformation
*r
)
3455 r
->oem_information
.string
= lp_serverstring();
3457 return NT_STATUS_OK
;
3460 /*******************************************************************
3461 ********************************************************************/
3463 static NTSTATUS
query_dom_info_5(TALLOC_CTX
*mem_ctx
,
3464 struct samr_DomInfo5
*r
)
3466 r
->domain_name
.string
= get_global_sam_name();
3468 return NT_STATUS_OK
;
3471 /*******************************************************************
3472 ********************************************************************/
3474 static NTSTATUS
query_dom_info_6(TALLOC_CTX
*mem_ctx
,
3475 struct samr_DomInfo6
*r
)
3477 /* NT returns its own name when a PDC. win2k and later
3478 * only the name of the PDC if itself is a BDC (samba4
3480 r
->primary
.string
= global_myname();
3482 return NT_STATUS_OK
;
3485 /*******************************************************************
3486 ********************************************************************/
3488 static NTSTATUS
query_dom_info_7(TALLOC_CTX
*mem_ctx
,
3489 struct samr_DomInfo7
*r
)
3491 r
->role
= samr_get_server_role();
3493 return NT_STATUS_OK
;
3496 /*******************************************************************
3497 ********************************************************************/
3499 static NTSTATUS
query_dom_info_8(TALLOC_CTX
*mem_ctx
,
3500 struct samr_DomInfo8
*r
)
3508 if (!pdb_get_seq_num(&seq_num
)) {
3509 seq_num
= time(NULL
);
3516 r
->sequence_num
= seq_num
;
3517 r
->domain_create_time
= 0;
3519 return NT_STATUS_OK
;
3522 /*******************************************************************
3523 ********************************************************************/
3525 static NTSTATUS
query_dom_info_9(TALLOC_CTX
*mem_ctx
,
3526 struct samr_DomInfo9
*r
)
3528 r
->domain_server_state
= DOMAIN_SERVER_ENABLED
;
3530 return NT_STATUS_OK
;
3533 /*******************************************************************
3534 ********************************************************************/
3536 static NTSTATUS
query_dom_info_11(TALLOC_CTX
*mem_ctx
,
3537 struct samr_DomGeneralInformation2
*r
,
3538 struct samr_domain_info
*dinfo
)
3541 uint32_t account_policy_temp
;
3542 time_t u_lock_duration
, u_reset_time
;
3544 status
= query_dom_info_2(mem_ctx
, &r
->general
, dinfo
);
3545 if (!NT_STATUS_IS_OK(status
)) {
3553 pdb_get_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION
, &account_policy_temp
);
3554 u_lock_duration
= account_policy_temp
;
3555 if (u_lock_duration
!= -1) {
3556 u_lock_duration
*= 60;
3559 pdb_get_account_policy(PDB_POLICY_RESET_COUNT_TIME
, &account_policy_temp
);
3560 u_reset_time
= account_policy_temp
* 60;
3562 pdb_get_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT
, &account_policy_temp
);
3563 r
->lockout_threshold
= account_policy_temp
;
3569 unix_to_nt_time_abs(&r
->lockout_duration
, u_lock_duration
);
3570 unix_to_nt_time_abs(&r
->lockout_window
, u_reset_time
);
3572 return NT_STATUS_OK
;
3575 /*******************************************************************
3576 ********************************************************************/
3578 static NTSTATUS
query_dom_info_12(TALLOC_CTX
*mem_ctx
,
3579 struct samr_DomInfo12
*r
)
3581 uint32_t account_policy_temp
;
3582 time_t u_lock_duration
, u_reset_time
;
3588 pdb_get_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION
, &account_policy_temp
);
3589 u_lock_duration
= account_policy_temp
;
3590 if (u_lock_duration
!= -1) {
3591 u_lock_duration
*= 60;
3594 pdb_get_account_policy(PDB_POLICY_RESET_COUNT_TIME
, &account_policy_temp
);
3595 u_reset_time
= account_policy_temp
* 60;
3597 pdb_get_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT
, &account_policy_temp
);
3598 r
->lockout_threshold
= account_policy_temp
;
3604 unix_to_nt_time_abs(&r
->lockout_duration
, u_lock_duration
);
3605 unix_to_nt_time_abs(&r
->lockout_window
, u_reset_time
);
3607 return NT_STATUS_OK
;
3610 /*******************************************************************
3611 ********************************************************************/
3613 static NTSTATUS
query_dom_info_13(TALLOC_CTX
*mem_ctx
,
3614 struct samr_DomInfo13
*r
)
3622 if (!pdb_get_seq_num(&seq_num
)) {
3623 seq_num
= time(NULL
);
3630 r
->sequence_num
= seq_num
;
3631 r
->domain_create_time
= 0;
3632 r
->modified_count_at_last_promotion
= 0;
3634 return NT_STATUS_OK
;
3637 /*******************************************************************
3638 _samr_QueryDomainInfo
3639 ********************************************************************/
3641 NTSTATUS
_samr_QueryDomainInfo(struct pipes_struct
*p
,
3642 struct samr_QueryDomainInfo
*r
)
3644 NTSTATUS status
= NT_STATUS_OK
;
3645 struct samr_domain_info
*dinfo
;
3646 union samr_DomainInfo
*dom_info
;
3648 uint32_t acc_required
;
3650 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__
));
3652 switch (r
->in
.level
) {
3653 case 1: /* DomainPasswordInformation */
3654 case 12: /* DomainLockoutInformation */
3655 /* DOMAIN_READ_PASSWORD_PARAMETERS */
3656 acc_required
= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
;
3658 case 11: /* DomainGeneralInformation2 */
3659 /* DOMAIN_READ_PASSWORD_PARAMETERS |
3660 * DOMAIN_READ_OTHER_PARAMETERS */
3661 acc_required
= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
|
3662 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
;
3664 case 2: /* DomainGeneralInformation */
3665 case 3: /* DomainLogoffInformation */
3666 case 4: /* DomainOemInformation */
3667 case 5: /* DomainReplicationInformation */
3668 case 6: /* DomainReplicationInformation */
3669 case 7: /* DomainServerRoleInformation */
3670 case 8: /* DomainModifiedInformation */
3671 case 9: /* DomainStateInformation */
3672 case 10: /* DomainUasInformation */
3673 case 13: /* DomainModifiedInformation2 */
3674 /* DOMAIN_READ_OTHER_PARAMETERS */
3675 acc_required
= SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2
;
3678 return NT_STATUS_INVALID_INFO_CLASS
;
3681 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
3683 struct samr_domain_info
, &status
);
3684 if (!NT_STATUS_IS_OK(status
)) {
3688 dom_info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_DomainInfo
);
3690 return NT_STATUS_NO_MEMORY
;
3693 switch (r
->in
.level
) {
3695 status
= query_dom_info_1(p
->mem_ctx
, &dom_info
->info1
);
3698 status
= query_dom_info_2(p
->mem_ctx
, &dom_info
->general
, dinfo
);
3701 status
= query_dom_info_3(p
->mem_ctx
, &dom_info
->info3
);
3704 status
= query_dom_info_4(p
->mem_ctx
, &dom_info
->oem
);
3707 status
= query_dom_info_5(p
->mem_ctx
, &dom_info
->info5
);
3710 status
= query_dom_info_6(p
->mem_ctx
, &dom_info
->info6
);
3713 status
= query_dom_info_7(p
->mem_ctx
, &dom_info
->info7
);
3716 status
= query_dom_info_8(p
->mem_ctx
, &dom_info
->info8
);
3719 status
= query_dom_info_9(p
->mem_ctx
, &dom_info
->info9
);
3722 status
= query_dom_info_11(p
->mem_ctx
, &dom_info
->general2
, dinfo
);
3725 status
= query_dom_info_12(p
->mem_ctx
, &dom_info
->info12
);
3728 status
= query_dom_info_13(p
->mem_ctx
, &dom_info
->info13
);
3731 return NT_STATUS_INVALID_INFO_CLASS
;
3734 if (!NT_STATUS_IS_OK(status
)) {
3738 *r
->out
.info
= dom_info
;
3740 DEBUG(5,("_samr_QueryDomainInfo: %d\n", __LINE__
));
3745 /* W2k3 seems to use the same check for all 3 objects that can be created via
3746 * SAMR, if you try to create for example "Dialup" as an alias it says
3747 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
3750 static NTSTATUS
can_create(TALLOC_CTX
*mem_ctx
, const char *new_name
)
3752 enum lsa_SidType type
;
3755 DEBUG(10, ("Checking whether [%s] can be created\n", new_name
));
3758 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
3759 * whether the name already exists */
3760 result
= lookup_name(mem_ctx
, new_name
, LOOKUP_NAME_LOCAL
,
3761 NULL
, NULL
, NULL
, &type
);
3765 DEBUG(10, ("%s does not exist, can create it\n", new_name
));
3766 return NT_STATUS_OK
;
3769 DEBUG(5, ("trying to create %s, exists as %s\n",
3770 new_name
, sid_type_lookup(type
)));
3772 if (type
== SID_NAME_DOM_GRP
) {
3773 return NT_STATUS_GROUP_EXISTS
;
3775 if (type
== SID_NAME_ALIAS
) {
3776 return NT_STATUS_ALIAS_EXISTS
;
3779 /* Yes, the default is NT_STATUS_USER_EXISTS */
3780 return NT_STATUS_USER_EXISTS
;
3783 /*******************************************************************
3785 ********************************************************************/
3787 NTSTATUS
_samr_CreateUser2(struct pipes_struct
*p
,
3788 struct samr_CreateUser2
*r
)
3790 const char *account
= NULL
;
3792 uint32_t acb_info
= r
->in
.acct_flags
;
3793 struct samr_domain_info
*dinfo
;
3794 struct samr_user_info
*uinfo
;
3797 struct security_descriptor
*psd
;
3799 /* check this, when giving away 'add computer to domain' privs */
3800 uint32 des_access
= GENERIC_RIGHTS_USER_ALL_ACCESS
;
3801 bool can_add_account
= False
;
3804 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
3805 SAMR_DOMAIN_ACCESS_CREATE_USER
, NULL
,
3806 struct samr_domain_info
, &nt_status
);
3807 if (!NT_STATUS_IS_OK(nt_status
)) {
3811 if (sid_check_is_builtin(&dinfo
->sid
)) {
3812 DEBUG(5,("_samr_CreateUser2: Refusing user create in BUILTIN\n"));
3813 return NT_STATUS_ACCESS_DENIED
;
3816 if (!(acb_info
== ACB_NORMAL
|| acb_info
== ACB_DOMTRUST
||
3817 acb_info
== ACB_WSTRUST
|| acb_info
== ACB_SVRTRUST
)) {
3818 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
3819 this parameter is not an account type */
3820 return NT_STATUS_INVALID_PARAMETER
;
3823 account
= r
->in
.account_name
->string
;
3824 if (account
== NULL
) {
3825 return NT_STATUS_NO_MEMORY
;
3828 nt_status
= can_create(p
->mem_ctx
, account
);
3829 if (!NT_STATUS_IS_OK(nt_status
)) {
3833 /* determine which user right we need to check based on the acb_info */
3835 if (geteuid() == sec_initial_uid()) {
3836 se_priv_copy(&se_rights
, &se_priv_none
);
3837 can_add_account
= true;
3838 } else if (acb_info
& ACB_WSTRUST
) {
3839 se_priv_copy(&se_rights
, &se_machine_account
);
3840 can_add_account
= user_has_privileges(
3841 p
->server_info
->ptok
, &se_rights
);
3842 } else if (acb_info
& ACB_NORMAL
&&
3843 (account
[strlen(account
)-1] != '$')) {
3844 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
3845 account for domain trusts and changes the ACB flags later */
3846 se_priv_copy(&se_rights
, &se_add_users
);
3847 can_add_account
= user_has_privileges(
3848 p
->server_info
->ptok
, &se_rights
);
3849 } else if (lp_enable_privileges()) {
3850 /* implicit assumption of a BDC or domain trust account here
3851 * (we already check the flags earlier) */
3852 /* only Domain Admins can add a BDC or domain trust */
3853 se_priv_copy(&se_rights
, &se_priv_none
);
3854 can_add_account
= nt_token_check_domain_rid(
3855 p
->server_info
->ptok
,
3856 DOMAIN_RID_ADMINS
);
3859 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
3860 uidtoname(p
->server_info
->utok
.uid
),
3861 can_add_account
? "True":"False" ));
3863 if (!can_add_account
) {
3864 return NT_STATUS_ACCESS_DENIED
;
3867 /********** BEGIN Admin BLOCK **********/
3870 nt_status
= pdb_create_user(p
->mem_ctx
, account
, acb_info
,
3874 /********** END Admin BLOCK **********/
3876 /* now check for failure */
3878 if ( !NT_STATUS_IS_OK(nt_status
) )
3881 /* Get the user's SID */
3883 sid_compose(&sid
, get_global_sam_sid(), *r
->out
.rid
);
3885 map_max_allowed_access(p
->server_info
->ptok
,
3886 &p
->server_info
->utok
,
3889 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
,
3890 &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
3891 se_map_generic(&des_access
, &usr_generic_mapping
);
3894 * JRA - TESTME. We just created this user so we
3895 * had rights to create them. Do we need to check
3896 * any further access on this object ? Can't we
3897 * just assume we have all the rights we need ?
3900 nt_status
= access_check_object(psd
, p
->server_info
->ptok
,
3901 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
3902 &acc_granted
, "_samr_CreateUser2");
3904 if ( !NT_STATUS_IS_OK(nt_status
) ) {
3908 uinfo
= policy_handle_create(p
, r
->out
.user_handle
, acc_granted
,
3909 struct samr_user_info
, &nt_status
);
3910 if (!NT_STATUS_IS_OK(nt_status
)) {
3915 /* After a "set" ensure we have no cached display info. */
3916 force_flush_samr_cache(&sid
);
3918 *r
->out
.access_granted
= acc_granted
;
3920 return NT_STATUS_OK
;
3923 /****************************************************************
3924 ****************************************************************/
3926 NTSTATUS
_samr_CreateUser(struct pipes_struct
*p
,
3927 struct samr_CreateUser
*r
)
3929 struct samr_CreateUser2 c
;
3930 uint32_t access_granted
;
3932 c
.in
.domain_handle
= r
->in
.domain_handle
;
3933 c
.in
.account_name
= r
->in
.account_name
;
3934 c
.in
.acct_flags
= ACB_NORMAL
;
3935 c
.in
.access_mask
= r
->in
.access_mask
;
3936 c
.out
.user_handle
= r
->out
.user_handle
;
3937 c
.out
.access_granted
= &access_granted
;
3938 c
.out
.rid
= r
->out
.rid
;
3940 return _samr_CreateUser2(p
, &c
);
3943 /*******************************************************************
3945 ********************************************************************/
3947 NTSTATUS
_samr_Connect(struct pipes_struct
*p
,
3948 struct samr_Connect
*r
)
3950 struct samr_connect_info
*info
;
3951 uint32_t acc_granted
;
3952 struct policy_handle hnd
;
3953 uint32 des_access
= r
->in
.access_mask
;
3958 if (!pipe_access_check(p
)) {
3959 DEBUG(3, ("access denied to _samr_Connect\n"));
3960 return NT_STATUS_ACCESS_DENIED
;
3963 /* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
3964 was observed from a win98 client trying to enumerate users (when configured
3965 user level access control on shares) --jerry */
3967 map_max_allowed_access(p
->server_info
->ptok
,
3968 &p
->server_info
->utok
,
3971 se_map_generic( &des_access
, &sam_generic_mapping
);
3973 acc_granted
= des_access
& (SAMR_ACCESS_ENUM_DOMAINS
3974 |SAMR_ACCESS_LOOKUP_DOMAIN
);
3976 /* set up the SAMR connect_anon response */
3978 info
= policy_handle_create(p
, &hnd
, acc_granted
,
3979 struct samr_connect_info
,
3981 if (!NT_STATUS_IS_OK(status
)) {
3985 *r
->out
.connect_handle
= hnd
;
3986 return NT_STATUS_OK
;
3989 /*******************************************************************
3991 ********************************************************************/
3993 NTSTATUS
_samr_Connect2(struct pipes_struct
*p
,
3994 struct samr_Connect2
*r
)
3996 struct samr_connect_info
*info
= NULL
;
3997 struct policy_handle hnd
;
3998 struct security_descriptor
*psd
= NULL
;
4000 uint32 des_access
= r
->in
.access_mask
;
4003 const char *fn
= "_samr_Connect2";
4006 case NDR_SAMR_CONNECT2
:
4007 fn
= "_samr_Connect2";
4009 case NDR_SAMR_CONNECT3
:
4010 fn
= "_samr_Connect3";
4012 case NDR_SAMR_CONNECT4
:
4013 fn
= "_samr_Connect4";
4015 case NDR_SAMR_CONNECT5
:
4016 fn
= "_samr_Connect5";
4020 DEBUG(5,("%s: %d\n", fn
, __LINE__
));
4024 if (!pipe_access_check(p
)) {
4025 DEBUG(3, ("access denied to %s\n", fn
));
4026 return NT_STATUS_ACCESS_DENIED
;
4029 map_max_allowed_access(p
->server_info
->ptok
,
4030 &p
->server_info
->utok
,
4033 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
4034 se_map_generic(&des_access
, &sam_generic_mapping
);
4036 nt_status
= access_check_object(psd
, p
->server_info
->ptok
,
4037 NULL
, 0, des_access
, &acc_granted
, fn
);
4039 if ( !NT_STATUS_IS_OK(nt_status
) )
4042 info
= policy_handle_create(p
, &hnd
, acc_granted
,
4043 struct samr_connect_info
, &nt_status
);
4044 if (!NT_STATUS_IS_OK(nt_status
)) {
4048 DEBUG(5,("%s: %d\n", fn
, __LINE__
));
4050 *r
->out
.connect_handle
= hnd
;
4051 return NT_STATUS_OK
;
4054 /****************************************************************
4056 ****************************************************************/
4058 NTSTATUS
_samr_Connect3(struct pipes_struct
*p
,
4059 struct samr_Connect3
*r
)
4061 struct samr_Connect2 c
;
4063 c
.in
.system_name
= r
->in
.system_name
;
4064 c
.in
.access_mask
= r
->in
.access_mask
;
4065 c
.out
.connect_handle
= r
->out
.connect_handle
;
4067 return _samr_Connect2(p
, &c
);
4070 /*******************************************************************
4072 ********************************************************************/
4074 NTSTATUS
_samr_Connect4(struct pipes_struct
*p
,
4075 struct samr_Connect4
*r
)
4077 struct samr_Connect2 c
;
4079 c
.in
.system_name
= r
->in
.system_name
;
4080 c
.in
.access_mask
= r
->in
.access_mask
;
4081 c
.out
.connect_handle
= r
->out
.connect_handle
;
4083 return _samr_Connect2(p
, &c
);
4086 /*******************************************************************
4088 ********************************************************************/
4090 NTSTATUS
_samr_Connect5(struct pipes_struct
*p
,
4091 struct samr_Connect5
*r
)
4094 struct samr_Connect2 c
;
4095 struct samr_ConnectInfo1 info1
;
4097 info1
.client_version
= SAMR_CONNECT_AFTER_W2K
;
4100 c
.in
.system_name
= r
->in
.system_name
;
4101 c
.in
.access_mask
= r
->in
.access_mask
;
4102 c
.out
.connect_handle
= r
->out
.connect_handle
;
4104 *r
->out
.level_out
= 1;
4106 status
= _samr_Connect2(p
, &c
);
4107 if (!NT_STATUS_IS_OK(status
)) {
4111 r
->out
.info_out
->info1
= info1
;
4113 return NT_STATUS_OK
;
4116 /**********************************************************************
4118 **********************************************************************/
4120 NTSTATUS
_samr_LookupDomain(struct pipes_struct
*p
,
4121 struct samr_LookupDomain
*r
)
4124 struct samr_connect_info
*info
;
4125 const char *domain_name
;
4126 struct dom_sid
*sid
= NULL
;
4128 /* win9x user manager likes to use SAMR_ACCESS_ENUM_DOMAINS here.
4129 Reverted that change so we will work with RAS servers again */
4131 info
= policy_handle_find(p
, r
->in
.connect_handle
,
4132 SAMR_ACCESS_LOOKUP_DOMAIN
, NULL
,
4133 struct samr_connect_info
,
4135 if (!NT_STATUS_IS_OK(status
)) {
4139 domain_name
= r
->in
.domain_name
->string
;
4141 return NT_STATUS_INVALID_PARAMETER
;
4144 sid
= TALLOC_ZERO_P(p
->mem_ctx
, struct dom_sid2
);
4146 return NT_STATUS_NO_MEMORY
;
4149 if (strequal(domain_name
, builtin_domain_name())) {
4150 sid_copy(sid
, &global_sid_Builtin
);
4152 if (!secrets_fetch_domain_sid(domain_name
, sid
)) {
4153 status
= NT_STATUS_NO_SUCH_DOMAIN
;
4157 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name
,
4158 sid_string_dbg(sid
)));
4165 /**********************************************************************
4167 **********************************************************************/
4169 NTSTATUS
_samr_EnumDomains(struct pipes_struct
*p
,
4170 struct samr_EnumDomains
*r
)
4173 struct samr_connect_info
*info
;
4174 uint32_t num_entries
= 2;
4175 struct samr_SamEntry
*entry_array
= NULL
;
4176 struct samr_SamArray
*sam
;
4178 info
= policy_handle_find(p
, r
->in
.connect_handle
,
4179 SAMR_ACCESS_ENUM_DOMAINS
, NULL
,
4180 struct samr_connect_info
, &status
);
4181 if (!NT_STATUS_IS_OK(status
)) {
4185 sam
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_SamArray
);
4187 return NT_STATUS_NO_MEMORY
;
4190 entry_array
= TALLOC_ZERO_ARRAY(p
->mem_ctx
,
4191 struct samr_SamEntry
,
4194 return NT_STATUS_NO_MEMORY
;
4197 entry_array
[0].idx
= 0;
4198 init_lsa_String(&entry_array
[0].name
, get_global_sam_name());
4200 entry_array
[1].idx
= 1;
4201 init_lsa_String(&entry_array
[1].name
, "Builtin");
4203 sam
->count
= num_entries
;
4204 sam
->entries
= entry_array
;
4207 *r
->out
.num_entries
= num_entries
;
4212 /*******************************************************************
4214 ********************************************************************/
4216 NTSTATUS
_samr_OpenAlias(struct pipes_struct
*p
,
4217 struct samr_OpenAlias
*r
)
4220 uint32 alias_rid
= r
->in
.rid
;
4221 struct samr_alias_info
*ainfo
;
4222 struct samr_domain_info
*dinfo
;
4223 struct security_descriptor
*psd
= NULL
;
4225 uint32 des_access
= r
->in
.access_mask
;
4230 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
4231 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
, NULL
,
4232 struct samr_domain_info
, &status
);
4233 if (!NT_STATUS_IS_OK(status
)) {
4237 /* append the alias' RID to it */
4239 if (!sid_compose(&sid
, &dinfo
->sid
, alias_rid
))
4240 return NT_STATUS_NO_SUCH_ALIAS
;
4242 /*check if access can be granted as requested by client. */
4244 map_max_allowed_access(p
->server_info
->ptok
,
4245 &p
->server_info
->utok
,
4248 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &ali_generic_mapping
, NULL
, 0);
4249 se_map_generic(&des_access
,&ali_generic_mapping
);
4251 se_priv_copy( &se_rights
, &se_add_users
);
4253 status
= access_check_object(psd
, p
->server_info
->ptok
,
4254 &se_rights
, GENERIC_RIGHTS_ALIAS_ALL_ACCESS
,
4255 des_access
, &acc_granted
, "_samr_OpenAlias");
4257 if ( !NT_STATUS_IS_OK(status
) )
4261 /* Check we actually have the requested alias */
4262 enum lsa_SidType type
;
4267 result
= lookup_sid(NULL
, &sid
, NULL
, NULL
, &type
);
4270 if (!result
|| (type
!= SID_NAME_ALIAS
)) {
4271 return NT_STATUS_NO_SUCH_ALIAS
;
4274 /* make sure there is a mapping */
4276 if ( !sid_to_gid( &sid
, &gid
) ) {
4277 return NT_STATUS_NO_SUCH_ALIAS
;
4282 ainfo
= policy_handle_create(p
, r
->out
.alias_handle
, acc_granted
,
4283 struct samr_alias_info
, &status
);
4284 if (!NT_STATUS_IS_OK(status
)) {
4289 return NT_STATUS_OK
;
4292 /*******************************************************************
4294 ********************************************************************/
4296 static NTSTATUS
set_user_info_2(TALLOC_CTX
*mem_ctx
,
4297 struct samr_UserInfo2
*id2
,
4301 DEBUG(5,("set_user_info_2: NULL id2\n"));
4302 return NT_STATUS_ACCESS_DENIED
;
4305 copy_id2_to_sam_passwd(pwd
, id2
);
4307 return pdb_update_sam_account(pwd
);
4310 /*******************************************************************
4312 ********************************************************************/
4314 static NTSTATUS
set_user_info_4(TALLOC_CTX
*mem_ctx
,
4315 struct samr_UserInfo4
*id4
,
4319 DEBUG(5,("set_user_info_2: NULL id4\n"));
4320 return NT_STATUS_ACCESS_DENIED
;
4323 copy_id4_to_sam_passwd(pwd
, id4
);
4325 return pdb_update_sam_account(pwd
);
4328 /*******************************************************************
4330 ********************************************************************/
4332 static NTSTATUS
set_user_info_6(TALLOC_CTX
*mem_ctx
,
4333 struct samr_UserInfo6
*id6
,
4337 DEBUG(5,("set_user_info_6: NULL id6\n"));
4338 return NT_STATUS_ACCESS_DENIED
;
4341 copy_id6_to_sam_passwd(pwd
, id6
);
4343 return pdb_update_sam_account(pwd
);
4346 /*******************************************************************
4348 ********************************************************************/
4350 static NTSTATUS
set_user_info_7(TALLOC_CTX
*mem_ctx
,
4351 struct samr_UserInfo7
*id7
,
4357 DEBUG(5, ("set_user_info_7: NULL id7\n"));
4358 return NT_STATUS_ACCESS_DENIED
;
4361 if (!id7
->account_name
.string
) {
4362 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
4363 return NT_STATUS_ACCESS_DENIED
;
4366 /* check to see if the new username already exists. Note: we can't
4367 reliably lock all backends, so there is potentially the
4368 possibility that a user can be created in between this check and
4369 the rename. The rename should fail, but may not get the
4370 exact same failure status code. I think this is small enough
4371 of a window for this type of operation and the results are
4372 simply that the rename fails with a slightly different status
4373 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
4375 rc
= can_create(mem_ctx
, id7
->account_name
.string
);
4377 /* when there is nothing to change, we're done here */
4378 if (NT_STATUS_EQUAL(rc
, NT_STATUS_USER_EXISTS
) &&
4379 strequal(id7
->account_name
.string
, pdb_get_username(pwd
))) {
4380 return NT_STATUS_OK
;
4382 if (!NT_STATUS_IS_OK(rc
)) {
4386 rc
= pdb_rename_sam_account(pwd
, id7
->account_name
.string
);
4391 /*******************************************************************
4393 ********************************************************************/
4395 static NTSTATUS
set_user_info_8(TALLOC_CTX
*mem_ctx
,
4396 struct samr_UserInfo8
*id8
,
4400 DEBUG(5,("set_user_info_8: NULL id8\n"));
4401 return NT_STATUS_ACCESS_DENIED
;
4404 copy_id8_to_sam_passwd(pwd
, id8
);
4406 return pdb_update_sam_account(pwd
);
4409 /*******************************************************************
4411 ********************************************************************/
4413 static NTSTATUS
set_user_info_10(TALLOC_CTX
*mem_ctx
,
4414 struct samr_UserInfo10
*id10
,
4418 DEBUG(5,("set_user_info_8: NULL id10\n"));
4419 return NT_STATUS_ACCESS_DENIED
;
4422 copy_id10_to_sam_passwd(pwd
, id10
);
4424 return pdb_update_sam_account(pwd
);
4427 /*******************************************************************
4429 ********************************************************************/
4431 static NTSTATUS
set_user_info_11(TALLOC_CTX
*mem_ctx
,
4432 struct samr_UserInfo11
*id11
,
4436 DEBUG(5,("set_user_info_11: NULL id11\n"));
4437 return NT_STATUS_ACCESS_DENIED
;
4440 copy_id11_to_sam_passwd(pwd
, id11
);
4442 return pdb_update_sam_account(pwd
);
4445 /*******************************************************************
4447 ********************************************************************/
4449 static NTSTATUS
set_user_info_12(TALLOC_CTX
*mem_ctx
,
4450 struct samr_UserInfo12
*id12
,
4454 DEBUG(5,("set_user_info_12: NULL id12\n"));
4455 return NT_STATUS_ACCESS_DENIED
;
4458 copy_id12_to_sam_passwd(pwd
, id12
);
4460 return pdb_update_sam_account(pwd
);
4463 /*******************************************************************
4465 ********************************************************************/
4467 static NTSTATUS
set_user_info_13(TALLOC_CTX
*mem_ctx
,
4468 struct samr_UserInfo13
*id13
,
4472 DEBUG(5,("set_user_info_13: NULL id13\n"));
4473 return NT_STATUS_ACCESS_DENIED
;
4476 copy_id13_to_sam_passwd(pwd
, id13
);
4478 return pdb_update_sam_account(pwd
);
4481 /*******************************************************************
4483 ********************************************************************/
4485 static NTSTATUS
set_user_info_14(TALLOC_CTX
*mem_ctx
,
4486 struct samr_UserInfo14
*id14
,
4490 DEBUG(5,("set_user_info_14: NULL id14\n"));
4491 return NT_STATUS_ACCESS_DENIED
;
4494 copy_id14_to_sam_passwd(pwd
, id14
);
4496 return pdb_update_sam_account(pwd
);
4499 /*******************************************************************
4501 ********************************************************************/
4503 static NTSTATUS
set_user_info_16(TALLOC_CTX
*mem_ctx
,
4504 struct samr_UserInfo16
*id16
,
4508 DEBUG(5,("set_user_info_16: NULL id16\n"));
4509 return NT_STATUS_ACCESS_DENIED
;
4512 copy_id16_to_sam_passwd(pwd
, id16
);
4514 return pdb_update_sam_account(pwd
);
4517 /*******************************************************************
4519 ********************************************************************/
4521 static NTSTATUS
set_user_info_17(TALLOC_CTX
*mem_ctx
,
4522 struct samr_UserInfo17
*id17
,
4526 DEBUG(5,("set_user_info_17: NULL id17\n"));
4527 return NT_STATUS_ACCESS_DENIED
;
4530 copy_id17_to_sam_passwd(pwd
, id17
);
4532 return pdb_update_sam_account(pwd
);
4535 /*******************************************************************
4537 ********************************************************************/
4539 static NTSTATUS
set_user_info_18(struct samr_UserInfo18
*id18
,
4540 TALLOC_CTX
*mem_ctx
,
4541 DATA_BLOB
*session_key
,
4545 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
4546 return NT_STATUS_INVALID_PARAMETER
;
4549 if (id18
->nt_pwd_active
|| id18
->lm_pwd_active
) {
4550 if (!session_key
->length
) {
4551 return NT_STATUS_NO_USER_SESSION_KEY
;
4555 if (id18
->nt_pwd_active
) {
4559 in
= data_blob_const(id18
->nt_pwd
.hash
, 16);
4560 out
= data_blob_talloc_zero(mem_ctx
, 16);
4562 sess_crypt_blob(&out
, &in
, session_key
, false);
4564 if (!pdb_set_nt_passwd(pwd
, out
.data
, PDB_CHANGED
)) {
4565 return NT_STATUS_ACCESS_DENIED
;
4568 pdb_set_pass_last_set_time(pwd
, time(NULL
), PDB_CHANGED
);
4571 if (id18
->lm_pwd_active
) {
4575 in
= data_blob_const(id18
->lm_pwd
.hash
, 16);
4576 out
= data_blob_talloc_zero(mem_ctx
, 16);
4578 sess_crypt_blob(&out
, &in
, session_key
, false);
4580 if (!pdb_set_lanman_passwd(pwd
, out
.data
, PDB_CHANGED
)) {
4581 return NT_STATUS_ACCESS_DENIED
;
4584 pdb_set_pass_last_set_time(pwd
, time(NULL
), PDB_CHANGED
);
4587 copy_id18_to_sam_passwd(pwd
, id18
);
4589 return pdb_update_sam_account(pwd
);
4592 /*******************************************************************
4594 ********************************************************************/
4596 static NTSTATUS
set_user_info_20(TALLOC_CTX
*mem_ctx
,
4597 struct samr_UserInfo20
*id20
,
4601 DEBUG(5,("set_user_info_20: NULL id20\n"));
4602 return NT_STATUS_ACCESS_DENIED
;
4605 copy_id20_to_sam_passwd(pwd
, id20
);
4607 return pdb_update_sam_account(pwd
);
4610 /*******************************************************************
4612 ********************************************************************/
4614 static NTSTATUS
set_user_info_21(struct samr_UserInfo21
*id21
,
4615 TALLOC_CTX
*mem_ctx
,
4616 DATA_BLOB
*session_key
,
4622 DEBUG(5, ("set_user_info_21: NULL id21\n"));
4623 return NT_STATUS_INVALID_PARAMETER
;
4626 if (id21
->fields_present
== 0) {
4627 return NT_STATUS_INVALID_PARAMETER
;
4630 if (id21
->fields_present
& SAMR_FIELD_LAST_PWD_CHANGE
) {
4631 return NT_STATUS_ACCESS_DENIED
;
4634 if (id21
->fields_present
& SAMR_FIELD_NT_PASSWORD_PRESENT
) {
4635 if (id21
->nt_password_set
) {
4638 if ((id21
->nt_owf_password
.length
!= 16) ||
4639 (id21
->nt_owf_password
.size
!= 16)) {
4640 return NT_STATUS_INVALID_PARAMETER
;
4643 if (!session_key
->length
) {
4644 return NT_STATUS_NO_USER_SESSION_KEY
;
4647 in
= data_blob_const(id21
->nt_owf_password
.array
, 16);
4648 out
= data_blob_talloc_zero(mem_ctx
, 16);
4650 sess_crypt_blob(&out
, &in
, session_key
, false);
4652 pdb_set_nt_passwd(pwd
, out
.data
, PDB_CHANGED
);
4653 pdb_set_pass_last_set_time(pwd
, time(NULL
), PDB_CHANGED
);
4657 if (id21
->fields_present
& SAMR_FIELD_LM_PASSWORD_PRESENT
) {
4658 if (id21
->lm_password_set
) {
4661 if ((id21
->lm_owf_password
.length
!= 16) ||
4662 (id21
->lm_owf_password
.size
!= 16)) {
4663 return NT_STATUS_INVALID_PARAMETER
;
4666 if (!session_key
->length
) {
4667 return NT_STATUS_NO_USER_SESSION_KEY
;
4670 in
= data_blob_const(id21
->lm_owf_password
.array
, 16);
4671 out
= data_blob_talloc_zero(mem_ctx
, 16);
4673 sess_crypt_blob(&out
, &in
, session_key
, false);
4675 pdb_set_lanman_passwd(pwd
, out
.data
, PDB_CHANGED
);
4676 pdb_set_pass_last_set_time(pwd
, time(NULL
), PDB_CHANGED
);
4680 /* we need to separately check for an account rename first */
4682 if (id21
->account_name
.string
&&
4683 (!strequal(id21
->account_name
.string
, pdb_get_username(pwd
))))
4686 /* check to see if the new username already exists. Note: we can't
4687 reliably lock all backends, so there is potentially the
4688 possibility that a user can be created in between this check and
4689 the rename. The rename should fail, but may not get the
4690 exact same failure status code. I think this is small enough
4691 of a window for this type of operation and the results are
4692 simply that the rename fails with a slightly different status
4693 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
4695 status
= can_create(mem_ctx
, id21
->account_name
.string
);
4696 if (!NT_STATUS_IS_OK(status
)) {
4700 status
= pdb_rename_sam_account(pwd
, id21
->account_name
.string
);
4702 if (!NT_STATUS_IS_OK(status
)) {
4703 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
4704 nt_errstr(status
)));
4708 /* set the new username so that later
4709 functions can work on the new account */
4710 pdb_set_username(pwd
, id21
->account_name
.string
, PDB_SET
);
4713 copy_id21_to_sam_passwd("INFO_21", pwd
, id21
);
4716 * The funny part about the previous two calls is
4717 * that pwd still has the password hashes from the
4718 * passdb entry. These have not been updated from
4719 * id21. I don't know if they need to be set. --jerry
4722 if ( IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) ) {
4723 status
= pdb_set_unix_primary_group(mem_ctx
, pwd
);
4724 if ( !NT_STATUS_IS_OK(status
) ) {
4729 /* Don't worry about writing out the user account since the
4730 primary group SID is generated solely from the user's Unix
4733 /* write the change out */
4734 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
4738 return NT_STATUS_OK
;
4741 /*******************************************************************
4743 ********************************************************************/
4745 static NTSTATUS
set_user_info_23(TALLOC_CTX
*mem_ctx
,
4746 struct samr_UserInfo23
*id23
,
4749 char *plaintext_buf
= NULL
;
4755 DEBUG(5, ("set_user_info_23: NULL id23\n"));
4756 return NT_STATUS_INVALID_PARAMETER
;
4759 if (id23
->info
.fields_present
== 0) {
4760 return NT_STATUS_INVALID_PARAMETER
;
4763 if (id23
->info
.fields_present
& SAMR_FIELD_LAST_PWD_CHANGE
) {
4764 return NT_STATUS_ACCESS_DENIED
;
4767 if ((id23
->info
.fields_present
& SAMR_FIELD_NT_PASSWORD_PRESENT
) ||
4768 (id23
->info
.fields_present
& SAMR_FIELD_LM_PASSWORD_PRESENT
)) {
4770 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
4771 pdb_get_username(pwd
)));
4773 if (!decode_pw_buffer(mem_ctx
,
4774 id23
->password
.data
,
4778 return NT_STATUS_WRONG_PASSWORD
;
4781 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
4782 return NT_STATUS_ACCESS_DENIED
;
4786 copy_id23_to_sam_passwd(pwd
, id23
);
4788 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
4790 /* if it's a trust account, don't update /etc/passwd */
4791 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
4792 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
4793 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
4794 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
4795 } else if (plaintext_buf
) {
4796 /* update the UNIX password */
4797 if (lp_unix_password_sync() ) {
4798 struct passwd
*passwd
;
4799 if (pdb_get_username(pwd
) == NULL
) {
4800 DEBUG(1, ("chgpasswd: User without name???\n"));
4801 return NT_STATUS_ACCESS_DENIED
;
4804 passwd
= Get_Pwnam_alloc(pwd
, pdb_get_username(pwd
));
4805 if (passwd
== NULL
) {
4806 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
4809 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
4810 return NT_STATUS_ACCESS_DENIED
;
4812 TALLOC_FREE(passwd
);
4816 if (plaintext_buf
) {
4817 memset(plaintext_buf
, '\0', strlen(plaintext_buf
));
4820 if (IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) &&
4821 (!NT_STATUS_IS_OK(status
= pdb_set_unix_primary_group(mem_ctx
,
4826 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
4830 return NT_STATUS_OK
;
4833 /*******************************************************************
4835 ********************************************************************/
4837 static bool set_user_info_pw(uint8
*pass
, struct samu
*pwd
)
4840 char *plaintext_buf
= NULL
;
4843 DEBUG(5, ("Attempting administrator password change for user %s\n",
4844 pdb_get_username(pwd
)));
4846 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
4848 if (!decode_pw_buffer(talloc_tos(),
4856 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
4860 /* if it's a trust account, don't update /etc/passwd */
4861 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
4862 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
4863 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
4864 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
4866 /* update the UNIX password */
4867 if (lp_unix_password_sync()) {
4868 struct passwd
*passwd
;
4870 if (pdb_get_username(pwd
) == NULL
) {
4871 DEBUG(1, ("chgpasswd: User without name???\n"));
4875 passwd
= Get_Pwnam_alloc(pwd
, pdb_get_username(pwd
));
4876 if (passwd
== NULL
) {
4877 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
4880 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
4883 TALLOC_FREE(passwd
);
4887 memset(plaintext_buf
, '\0', strlen(plaintext_buf
));
4889 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
4894 /*******************************************************************
4896 ********************************************************************/
4898 static NTSTATUS
set_user_info_24(TALLOC_CTX
*mem_ctx
,
4899 struct samr_UserInfo24
*id24
,
4905 DEBUG(5, ("set_user_info_24: NULL id24\n"));
4906 return NT_STATUS_INVALID_PARAMETER
;
4909 if (!set_user_info_pw(id24
->password
.data
, pwd
)) {
4910 return NT_STATUS_WRONG_PASSWORD
;
4913 copy_id24_to_sam_passwd(pwd
, id24
);
4915 status
= pdb_update_sam_account(pwd
);
4916 if (!NT_STATUS_IS_OK(status
)) {
4920 return NT_STATUS_OK
;
4923 /*******************************************************************
4925 ********************************************************************/
4927 static NTSTATUS
set_user_info_25(TALLOC_CTX
*mem_ctx
,
4928 struct samr_UserInfo25
*id25
,
4934 DEBUG(5, ("set_user_info_25: NULL id25\n"));
4935 return NT_STATUS_INVALID_PARAMETER
;
4938 if (id25
->info
.fields_present
== 0) {
4939 return NT_STATUS_INVALID_PARAMETER
;
4942 if (id25
->info
.fields_present
& SAMR_FIELD_LAST_PWD_CHANGE
) {
4943 return NT_STATUS_ACCESS_DENIED
;
4946 if ((id25
->info
.fields_present
& SAMR_FIELD_NT_PASSWORD_PRESENT
) ||
4947 (id25
->info
.fields_present
& SAMR_FIELD_LM_PASSWORD_PRESENT
)) {
4949 if (!set_user_info_pw(id25
->password
.data
, pwd
)) {
4950 return NT_STATUS_WRONG_PASSWORD
;
4954 copy_id25_to_sam_passwd(pwd
, id25
);
4956 /* write the change out */
4957 if(!NT_STATUS_IS_OK(status
= pdb_update_sam_account(pwd
))) {
4962 * We need to "pdb_update_sam_account" before the unix primary group
4963 * is set, because the idealx scripts would also change the
4964 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
4965 * the delete explicit / add explicit, which would then fail to find
4966 * the previous primaryGroupSid value.
4969 if ( IS_SAM_CHANGED(pwd
, PDB_GROUPSID
) ) {
4970 status
= pdb_set_unix_primary_group(mem_ctx
, pwd
);
4971 if ( !NT_STATUS_IS_OK(status
) ) {
4976 return NT_STATUS_OK
;
4979 /*******************************************************************
4981 ********************************************************************/
4983 static NTSTATUS
set_user_info_26(TALLOC_CTX
*mem_ctx
,
4984 struct samr_UserInfo26
*id26
,
4990 DEBUG(5, ("set_user_info_26: NULL id26\n"));
4991 return NT_STATUS_INVALID_PARAMETER
;
4994 if (!set_user_info_pw(id26
->password
.data
, pwd
)) {
4995 return NT_STATUS_WRONG_PASSWORD
;
4998 copy_id26_to_sam_passwd(pwd
, id26
);
5000 status
= pdb_update_sam_account(pwd
);
5001 if (!NT_STATUS_IS_OK(status
)) {
5005 return NT_STATUS_OK
;
5008 /*************************************************************
5009 **************************************************************/
5011 static uint32_t samr_set_user_info_map_fields_to_access_mask(uint32_t fields
)
5013 uint32_t acc_required
= 0;
5015 /* USER_ALL_USERNAME */
5016 if (fields
& SAMR_FIELD_ACCOUNT_NAME
)
5017 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5018 /* USER_ALL_FULLNAME */
5019 if (fields
& SAMR_FIELD_FULL_NAME
)
5020 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5021 /* USER_ALL_PRIMARYGROUPID */
5022 if (fields
& SAMR_FIELD_PRIMARY_GID
)
5023 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5024 /* USER_ALL_HOMEDIRECTORY */
5025 if (fields
& SAMR_FIELD_HOME_DIRECTORY
)
5026 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5027 /* USER_ALL_HOMEDIRECTORYDRIVE */
5028 if (fields
& SAMR_FIELD_HOME_DRIVE
)
5029 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5030 /* USER_ALL_SCRIPTPATH */
5031 if (fields
& SAMR_FIELD_LOGON_SCRIPT
)
5032 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5033 /* USER_ALL_PROFILEPATH */
5034 if (fields
& SAMR_FIELD_PROFILE_PATH
)
5035 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5036 /* USER_ALL_ADMINCOMMENT */
5037 if (fields
& SAMR_FIELD_COMMENT
)
5038 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5039 /* USER_ALL_WORKSTATIONS */
5040 if (fields
& SAMR_FIELD_WORKSTATIONS
)
5041 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5042 /* USER_ALL_LOGONHOURS */
5043 if (fields
& SAMR_FIELD_LOGON_HOURS
)
5044 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5045 /* USER_ALL_ACCOUNTEXPIRES */
5046 if (fields
& SAMR_FIELD_ACCT_EXPIRY
)
5047 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5048 /* USER_ALL_USERACCOUNTCONTROL */
5049 if (fields
& SAMR_FIELD_ACCT_FLAGS
)
5050 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5051 /* USER_ALL_PARAMETERS */
5052 if (fields
& SAMR_FIELD_PARAMETERS
)
5053 acc_required
|= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5054 /* USER_ALL_USERCOMMENT */
5055 if (fields
& SAMR_FIELD_COMMENT
)
5056 acc_required
|= SAMR_USER_ACCESS_SET_LOC_COM
;
5057 /* USER_ALL_COUNTRYCODE */
5058 if (fields
& SAMR_FIELD_COUNTRY_CODE
)
5059 acc_required
|= SAMR_USER_ACCESS_SET_LOC_COM
;
5060 /* USER_ALL_CODEPAGE */
5061 if (fields
& SAMR_FIELD_CODE_PAGE
)
5062 acc_required
|= SAMR_USER_ACCESS_SET_LOC_COM
;
5063 /* USER_ALL_NTPASSWORDPRESENT */
5064 if (fields
& SAMR_FIELD_NT_PASSWORD_PRESENT
)
5065 acc_required
|= SAMR_USER_ACCESS_SET_PASSWORD
;
5066 /* USER_ALL_LMPASSWORDPRESENT */
5067 if (fields
& SAMR_FIELD_LM_PASSWORD_PRESENT
)
5068 acc_required
|= SAMR_USER_ACCESS_SET_PASSWORD
;
5069 /* USER_ALL_PASSWORDEXPIRED */
5070 if (fields
& SAMR_FIELD_EXPIRED_FLAG
)
5071 acc_required
|= SAMR_USER_ACCESS_SET_PASSWORD
;
5073 return acc_required
;
5076 /*******************************************************************
5078 ********************************************************************/
5080 NTSTATUS
_samr_SetUserInfo(struct pipes_struct
*p
,
5081 struct samr_SetUserInfo
*r
)
5083 struct samr_user_info
*uinfo
;
5085 struct samu
*pwd
= NULL
;
5086 union samr_UserInfo
*info
= r
->in
.info
;
5087 uint32_t acc_required
= 0;
5088 uint32_t fields
= 0;
5091 DEBUG(5,("_samr_SetUserInfo: %d\n", __LINE__
));
5093 /* This is tricky. A WinXP domain join sets
5094 (SAMR_USER_ACCESS_SET_PASSWORD|SAMR_USER_ACCESS_SET_ATTRIBUTES|SAMR_USER_ACCESS_GET_ATTRIBUTES)
5095 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
5096 standard Win32 API calls just ask for SAMR_USER_ACCESS_SET_PASSWORD in the SamrOpenUser().
5097 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
5098 we'll use the set from the WinXP join as the basis. */
5100 switch (r
->in
.level
) {
5101 case 2: /* UserPreferencesInformation */
5102 /* USER_WRITE_ACCOUNT | USER_WRITE_PREFERENCES */
5103 acc_required
= SAMR_USER_ACCESS_SET_ATTRIBUTES
| SAMR_USER_ACCESS_SET_LOC_COM
;
5105 case 4: /* UserLogonHoursInformation */
5106 case 6: /* UserNameInformation */
5107 case 7: /* UserAccountNameInformation */
5108 case 8: /* UserFullNameInformation */
5109 case 9: /* UserPrimaryGroupInformation */
5110 case 10: /* UserHomeInformation */
5111 case 11: /* UserScriptInformation */
5112 case 12: /* UserProfileInformation */
5113 case 13: /* UserAdminCommentInformation */
5114 case 14: /* UserWorkStationsInformation */
5115 case 16: /* UserControlInformation */
5116 case 17: /* UserExpiresInformation */
5117 case 20: /* UserParametersInformation */
5118 /* USER_WRITE_ACCOUNT */
5119 acc_required
= SAMR_USER_ACCESS_SET_ATTRIBUTES
;
5121 case 18: /* UserInternal1Information */
5122 /* FIXME: gd, this is a guess */
5123 acc_required
= SAMR_USER_ACCESS_SET_PASSWORD
;
5125 case 21: /* UserAllInformation */
5126 fields
= info
->info21
.fields_present
;
5127 acc_required
= samr_set_user_info_map_fields_to_access_mask(fields
);
5129 case 23: /* UserInternal4Information */
5130 fields
= info
->info23
.info
.fields_present
;
5131 acc_required
= samr_set_user_info_map_fields_to_access_mask(fields
);
5133 case 25: /* UserInternal4InformationNew */
5134 fields
= info
->info25
.info
.fields_present
;
5135 acc_required
= samr_set_user_info_map_fields_to_access_mask(fields
);
5137 case 24: /* UserInternal5Information */
5138 case 26: /* UserInternal5InformationNew */
5139 acc_required
= SAMR_USER_ACCESS_SET_PASSWORD
;
5142 return NT_STATUS_INVALID_INFO_CLASS
;
5145 uinfo
= policy_handle_find(p
, r
->in
.user_handle
, acc_required
, NULL
,
5146 struct samr_user_info
, &status
);
5147 if (!NT_STATUS_IS_OK(status
)) {
5151 DEBUG(5, ("_samr_SetUserInfo: sid:%s, level:%d\n",
5152 sid_string_dbg(&uinfo
->sid
), r
->in
.level
));
5155 DEBUG(5, ("_samr_SetUserInfo: NULL info level\n"));
5156 return NT_STATUS_INVALID_INFO_CLASS
;
5159 if (!(pwd
= samu_new(NULL
))) {
5160 return NT_STATUS_NO_MEMORY
;
5164 ret
= pdb_getsampwsid(pwd
, &uinfo
->sid
);
5169 return NT_STATUS_NO_SUCH_USER
;
5172 /* ================ BEGIN Privilege BLOCK ================ */
5176 /* ok! user info levels (lots: see MSDEV help), off we go... */
5178 switch (r
->in
.level
) {
5181 status
= set_user_info_2(p
->mem_ctx
,
5186 status
= set_user_info_4(p
->mem_ctx
,
5191 status
= set_user_info_6(p
->mem_ctx
,
5196 status
= set_user_info_7(p
->mem_ctx
,
5201 status
= set_user_info_8(p
->mem_ctx
,
5206 status
= set_user_info_10(p
->mem_ctx
,
5207 &info
->info10
, pwd
);
5211 status
= set_user_info_11(p
->mem_ctx
,
5212 &info
->info11
, pwd
);
5216 status
= set_user_info_12(p
->mem_ctx
,
5217 &info
->info12
, pwd
);
5221 status
= set_user_info_13(p
->mem_ctx
,
5222 &info
->info13
, pwd
);
5226 status
= set_user_info_14(p
->mem_ctx
,
5227 &info
->info14
, pwd
);
5231 status
= set_user_info_16(p
->mem_ctx
,
5232 &info
->info16
, pwd
);
5236 status
= set_user_info_17(p
->mem_ctx
,
5237 &info
->info17
, pwd
);
5241 /* Used by AS/U JRA. */
5242 status
= set_user_info_18(&info
->info18
,
5244 &p
->server_info
->user_session_key
,
5249 status
= set_user_info_20(p
->mem_ctx
,
5250 &info
->info20
, pwd
);
5254 status
= set_user_info_21(&info
->info21
,
5256 &p
->server_info
->user_session_key
,
5261 if (!p
->server_info
->user_session_key
.length
) {
5262 status
= NT_STATUS_NO_USER_SESSION_KEY
;
5264 arcfour_crypt_blob(info
->info23
.password
.data
, 516,
5265 &p
->server_info
->user_session_key
);
5267 dump_data(100, info
->info23
.password
.data
, 516);
5269 status
= set_user_info_23(p
->mem_ctx
,
5270 &info
->info23
, pwd
);
5274 if (!p
->server_info
->user_session_key
.length
) {
5275 status
= NT_STATUS_NO_USER_SESSION_KEY
;
5277 arcfour_crypt_blob(info
->info24
.password
.data
,
5279 &p
->server_info
->user_session_key
);
5281 dump_data(100, info
->info24
.password
.data
, 516);
5283 status
= set_user_info_24(p
->mem_ctx
,
5284 &info
->info24
, pwd
);
5288 if (!p
->server_info
->user_session_key
.length
) {
5289 status
= NT_STATUS_NO_USER_SESSION_KEY
;
5291 encode_or_decode_arc4_passwd_buffer(
5292 info
->info25
.password
.data
,
5293 &p
->server_info
->user_session_key
);
5295 dump_data(100, info
->info25
.password
.data
, 532);
5297 status
= set_user_info_25(p
->mem_ctx
,
5298 &info
->info25
, pwd
);
5302 if (!p
->server_info
->user_session_key
.length
) {
5303 status
= NT_STATUS_NO_USER_SESSION_KEY
;
5305 encode_or_decode_arc4_passwd_buffer(
5306 info
->info26
.password
.data
,
5307 &p
->server_info
->user_session_key
);
5309 dump_data(100, info
->info26
.password
.data
, 516);
5311 status
= set_user_info_26(p
->mem_ctx
,
5312 &info
->info26
, pwd
);
5316 status
= NT_STATUS_INVALID_INFO_CLASS
;
5323 /* ================ END Privilege BLOCK ================ */
5325 if (NT_STATUS_IS_OK(status
)) {
5326 force_flush_samr_cache(&uinfo
->sid
);
5332 /*******************************************************************
5334 ********************************************************************/
5336 NTSTATUS
_samr_SetUserInfo2(struct pipes_struct
*p
,
5337 struct samr_SetUserInfo2
*r
)
5339 struct samr_SetUserInfo q
;
5341 q
.in
.user_handle
= r
->in
.user_handle
;
5342 q
.in
.level
= r
->in
.level
;
5343 q
.in
.info
= r
->in
.info
;
5345 return _samr_SetUserInfo(p
, &q
);
5348 /*********************************************************************
5349 _samr_GetAliasMembership
5350 *********************************************************************/
5352 NTSTATUS
_samr_GetAliasMembership(struct pipes_struct
*p
,
5353 struct samr_GetAliasMembership
*r
)
5355 size_t num_alias_rids
;
5357 struct samr_domain_info
*dinfo
;
5362 struct dom_sid
*members
;
5364 DEBUG(5,("_samr_GetAliasMembership: %d\n", __LINE__
));
5366 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
5367 SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
5368 | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
, NULL
,
5369 struct samr_domain_info
, &status
);
5370 if (!NT_STATUS_IS_OK(status
)) {
5374 if (!sid_check_is_domain(&dinfo
->sid
) &&
5375 !sid_check_is_builtin(&dinfo
->sid
))
5376 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
5378 if (r
->in
.sids
->num_sids
) {
5379 members
= TALLOC_ARRAY(p
->mem_ctx
, struct dom_sid
, r
->in
.sids
->num_sids
);
5381 if (members
== NULL
)
5382 return NT_STATUS_NO_MEMORY
;
5387 for (i
=0; i
<r
->in
.sids
->num_sids
; i
++)
5388 sid_copy(&members
[i
], r
->in
.sids
->sids
[i
].sid
);
5394 status
= pdb_enum_alias_memberships(p
->mem_ctx
, &dinfo
->sid
, members
,
5395 r
->in
.sids
->num_sids
,
5396 &alias_rids
, &num_alias_rids
);
5399 if (!NT_STATUS_IS_OK(status
)) {
5403 r
->out
.rids
->count
= num_alias_rids
;
5404 r
->out
.rids
->ids
= alias_rids
;
5406 if (r
->out
.rids
->ids
== NULL
) {
5407 /* Windows domain clients don't accept a NULL ptr here */
5408 r
->out
.rids
->ids
= talloc_zero(p
->mem_ctx
, uint32_t);
5410 if (r
->out
.rids
->ids
== NULL
) {
5411 return NT_STATUS_NO_MEMORY
;
5414 return NT_STATUS_OK
;
5417 /*********************************************************************
5418 _samr_GetMembersInAlias
5419 *********************************************************************/
5421 NTSTATUS
_samr_GetMembersInAlias(struct pipes_struct
*p
,
5422 struct samr_GetMembersInAlias
*r
)
5424 struct samr_alias_info
*ainfo
;
5427 size_t num_sids
= 0;
5428 struct lsa_SidPtr
*sids
= NULL
;
5429 struct dom_sid
*pdb_sids
= NULL
;
5431 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
5432 SAMR_ALIAS_ACCESS_GET_MEMBERS
, NULL
,
5433 struct samr_alias_info
, &status
);
5434 if (!NT_STATUS_IS_OK(status
)) {
5438 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ainfo
->sid
)));
5441 status
= pdb_enum_aliasmem(&ainfo
->sid
, talloc_tos(), &pdb_sids
,
5445 if (!NT_STATUS_IS_OK(status
)) {
5450 sids
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, struct lsa_SidPtr
, num_sids
);
5452 TALLOC_FREE(pdb_sids
);
5453 return NT_STATUS_NO_MEMORY
;
5457 for (i
= 0; i
< num_sids
; i
++) {
5458 sids
[i
].sid
= sid_dup_talloc(p
->mem_ctx
, &pdb_sids
[i
]);
5460 TALLOC_FREE(pdb_sids
);
5461 return NT_STATUS_NO_MEMORY
;
5465 r
->out
.sids
->num_sids
= num_sids
;
5466 r
->out
.sids
->sids
= sids
;
5468 TALLOC_FREE(pdb_sids
);
5470 return NT_STATUS_OK
;
5473 /*********************************************************************
5474 _samr_QueryGroupMember
5475 *********************************************************************/
5477 NTSTATUS
_samr_QueryGroupMember(struct pipes_struct
*p
,
5478 struct samr_QueryGroupMember
*r
)
5480 struct samr_group_info
*ginfo
;
5481 size_t i
, num_members
;
5487 struct samr_RidTypeArray
*rids
= NULL
;
5489 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
5490 SAMR_GROUP_ACCESS_GET_MEMBERS
, NULL
,
5491 struct samr_group_info
, &status
);
5492 if (!NT_STATUS_IS_OK(status
)) {
5496 rids
= TALLOC_ZERO_P(p
->mem_ctx
, struct samr_RidTypeArray
);
5498 return NT_STATUS_NO_MEMORY
;
5501 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ginfo
->sid
)));
5503 if (!sid_check_is_in_our_domain(&ginfo
->sid
)) {
5504 DEBUG(3, ("sid %s is not in our domain\n",
5505 sid_string_dbg(&ginfo
->sid
)));
5506 return NT_STATUS_NO_SUCH_GROUP
;
5509 DEBUG(10, ("lookup on Domain SID\n"));
5512 status
= pdb_enum_group_members(p
->mem_ctx
, &ginfo
->sid
,
5513 &rid
, &num_members
);
5516 if (!NT_STATUS_IS_OK(status
))
5520 attr
=TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_members
);
5522 return NT_STATUS_NO_MEMORY
;
5528 for (i
=0; i
<num_members
; i
++)
5529 attr
[i
] = SID_NAME_USER
;
5531 rids
->count
= num_members
;
5535 *r
->out
.rids
= rids
;
5537 return NT_STATUS_OK
;
5540 /*********************************************************************
5541 _samr_AddAliasMember
5542 *********************************************************************/
5544 NTSTATUS
_samr_AddAliasMember(struct pipes_struct
*p
,
5545 struct samr_AddAliasMember
*r
)
5547 struct samr_alias_info
*ainfo
;
5550 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
5551 SAMR_ALIAS_ACCESS_ADD_MEMBER
, NULL
,
5552 struct samr_alias_info
, &status
);
5553 if (!NT_STATUS_IS_OK(status
)) {
5557 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ainfo
->sid
)));
5559 /******** BEGIN SeAddUsers BLOCK *********/
5562 status
= pdb_add_aliasmem(&ainfo
->sid
, r
->in
.sid
);
5565 /******** END SeAddUsers BLOCK *********/
5567 if (NT_STATUS_IS_OK(status
)) {
5568 force_flush_samr_cache(&ainfo
->sid
);
5574 /*********************************************************************
5575 _samr_DeleteAliasMember
5576 *********************************************************************/
5578 NTSTATUS
_samr_DeleteAliasMember(struct pipes_struct
*p
,
5579 struct samr_DeleteAliasMember
*r
)
5581 struct samr_alias_info
*ainfo
;
5584 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
5585 SAMR_ALIAS_ACCESS_REMOVE_MEMBER
, NULL
,
5586 struct samr_alias_info
, &status
);
5587 if (!NT_STATUS_IS_OK(status
)) {
5591 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
5592 sid_string_dbg(&ainfo
->sid
)));
5594 /******** BEGIN SeAddUsers BLOCK *********/
5597 status
= pdb_del_aliasmem(&ainfo
->sid
, r
->in
.sid
);
5600 /******** END SeAddUsers BLOCK *********/
5602 if (NT_STATUS_IS_OK(status
)) {
5603 force_flush_samr_cache(&ainfo
->sid
);
5609 /*********************************************************************
5610 _samr_AddGroupMember
5611 *********************************************************************/
5613 NTSTATUS
_samr_AddGroupMember(struct pipes_struct
*p
,
5614 struct samr_AddGroupMember
*r
)
5616 struct samr_group_info
*ginfo
;
5620 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
5621 SAMR_GROUP_ACCESS_ADD_MEMBER
, NULL
,
5622 struct samr_group_info
, &status
);
5623 if (!NT_STATUS_IS_OK(status
)) {
5627 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ginfo
->sid
)));
5629 if (!sid_peek_check_rid(get_global_sam_sid(), &ginfo
->sid
,
5631 return NT_STATUS_INVALID_HANDLE
;
5634 /******** BEGIN SeAddUsers BLOCK *********/
5637 status
= pdb_add_groupmem(p
->mem_ctx
, group_rid
, r
->in
.rid
);
5640 /******** END SeAddUsers BLOCK *********/
5642 force_flush_samr_cache(&ginfo
->sid
);
5647 /*********************************************************************
5648 _samr_DeleteGroupMember
5649 *********************************************************************/
5651 NTSTATUS
_samr_DeleteGroupMember(struct pipes_struct
*p
,
5652 struct samr_DeleteGroupMember
*r
)
5655 struct samr_group_info
*ginfo
;
5660 * delete the group member named r->in.rid
5661 * who is a member of the sid associated with the handle
5662 * the rid is a user's rid as the group is a domain group.
5665 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
5666 SAMR_GROUP_ACCESS_REMOVE_MEMBER
, NULL
,
5667 struct samr_group_info
, &status
);
5668 if (!NT_STATUS_IS_OK(status
)) {
5672 if (!sid_peek_check_rid(get_global_sam_sid(), &ginfo
->sid
,
5674 return NT_STATUS_INVALID_HANDLE
;
5677 /******** BEGIN SeAddUsers BLOCK *********/
5680 status
= pdb_del_groupmem(p
->mem_ctx
, group_rid
, r
->in
.rid
);
5683 /******** END SeAddUsers BLOCK *********/
5685 force_flush_samr_cache(&ginfo
->sid
);
5690 /*********************************************************************
5692 *********************************************************************/
5694 NTSTATUS
_samr_DeleteUser(struct pipes_struct
*p
,
5695 struct samr_DeleteUser
*r
)
5697 struct samr_user_info
*uinfo
;
5699 struct samu
*sam_pass
=NULL
;
5702 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__
));
5704 uinfo
= policy_handle_find(p
, r
->in
.user_handle
,
5705 SEC_STD_DELETE
, NULL
,
5706 struct samr_user_info
, &status
);
5707 if (!NT_STATUS_IS_OK(status
)) {
5711 if (!sid_check_is_in_our_domain(&uinfo
->sid
))
5712 return NT_STATUS_CANNOT_DELETE
;
5714 /* check if the user exists before trying to delete */
5715 if ( !(sam_pass
= samu_new( NULL
)) ) {
5716 return NT_STATUS_NO_MEMORY
;
5720 ret
= pdb_getsampwsid(sam_pass
, &uinfo
->sid
);
5724 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
5725 sid_string_dbg(&uinfo
->sid
)));
5726 TALLOC_FREE(sam_pass
);
5727 return NT_STATUS_NO_SUCH_USER
;
5730 /******** BEGIN SeAddUsers BLOCK *********/
5733 status
= pdb_delete_user(p
->mem_ctx
, sam_pass
);
5736 /******** END SeAddUsers BLOCK *********/
5738 if ( !NT_STATUS_IS_OK(status
) ) {
5739 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
5740 "user %s: %s.\n", pdb_get_username(sam_pass
),
5741 nt_errstr(status
)));
5742 TALLOC_FREE(sam_pass
);
5747 TALLOC_FREE(sam_pass
);
5749 force_flush_samr_cache(&uinfo
->sid
);
5751 if (!close_policy_hnd(p
, r
->in
.user_handle
))
5752 return NT_STATUS_OBJECT_NAME_INVALID
;
5754 ZERO_STRUCTP(r
->out
.user_handle
);
5756 return NT_STATUS_OK
;
5759 /*********************************************************************
5760 _samr_DeleteDomainGroup
5761 *********************************************************************/
5763 NTSTATUS
_samr_DeleteDomainGroup(struct pipes_struct
*p
,
5764 struct samr_DeleteDomainGroup
*r
)
5766 struct samr_group_info
*ginfo
;
5770 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__
));
5772 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
5773 SEC_STD_DELETE
, NULL
,
5774 struct samr_group_info
, &status
);
5775 if (!NT_STATUS_IS_OK(status
)) {
5779 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ginfo
->sid
)));
5781 if (!sid_peek_check_rid(get_global_sam_sid(), &ginfo
->sid
,
5783 return NT_STATUS_NO_SUCH_GROUP
;
5786 /******** BEGIN SeAddUsers BLOCK *********/
5789 status
= pdb_delete_dom_group(p
->mem_ctx
, group_rid
);
5792 /******** END SeAddUsers BLOCK *********/
5794 if ( !NT_STATUS_IS_OK(status
) ) {
5795 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
5796 "entry for group %s: %s\n",
5797 sid_string_dbg(&ginfo
->sid
),
5798 nt_errstr(status
)));
5802 force_flush_samr_cache(&ginfo
->sid
);
5804 if (!close_policy_hnd(p
, r
->in
.group_handle
))
5805 return NT_STATUS_OBJECT_NAME_INVALID
;
5807 return NT_STATUS_OK
;
5810 /*********************************************************************
5811 _samr_DeleteDomAlias
5812 *********************************************************************/
5814 NTSTATUS
_samr_DeleteDomAlias(struct pipes_struct
*p
,
5815 struct samr_DeleteDomAlias
*r
)
5817 struct samr_alias_info
*ainfo
;
5820 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__
));
5822 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
5823 SEC_STD_DELETE
, NULL
,
5824 struct samr_alias_info
, &status
);
5825 if (!NT_STATUS_IS_OK(status
)) {
5829 DEBUG(10, ("sid is %s\n", sid_string_dbg(&ainfo
->sid
)));
5831 /* Don't let Windows delete builtin groups */
5833 if ( sid_check_is_in_builtin( &ainfo
->sid
) ) {
5834 return NT_STATUS_SPECIAL_ACCOUNT
;
5837 if (!sid_check_is_in_our_domain(&ainfo
->sid
))
5838 return NT_STATUS_NO_SUCH_ALIAS
;
5840 DEBUG(10, ("lookup on Local SID\n"));
5842 /******** BEGIN SeAddUsers BLOCK *********/
5845 /* Have passdb delete the alias */
5846 status
= pdb_delete_alias(&ainfo
->sid
);
5849 /******** END SeAddUsers BLOCK *********/
5851 if ( !NT_STATUS_IS_OK(status
))
5854 force_flush_samr_cache(&ainfo
->sid
);
5856 if (!close_policy_hnd(p
, r
->in
.alias_handle
))
5857 return NT_STATUS_OBJECT_NAME_INVALID
;
5859 return NT_STATUS_OK
;
5862 /*********************************************************************
5863 _samr_CreateDomainGroup
5864 *********************************************************************/
5866 NTSTATUS
_samr_CreateDomainGroup(struct pipes_struct
*p
,
5867 struct samr_CreateDomainGroup
*r
)
5872 struct samr_domain_info
*dinfo
;
5873 struct samr_group_info
*ginfo
;
5875 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
5876 SAMR_DOMAIN_ACCESS_CREATE_GROUP
, NULL
,
5877 struct samr_domain_info
, &status
);
5878 if (!NT_STATUS_IS_OK(status
)) {
5882 if (!sid_check_is_domain(&dinfo
->sid
)) {
5883 return NT_STATUS_ACCESS_DENIED
;
5886 name
= r
->in
.name
->string
;
5888 return NT_STATUS_NO_MEMORY
;
5891 status
= can_create(p
->mem_ctx
, name
);
5892 if (!NT_STATUS_IS_OK(status
)) {
5896 /******** BEGIN SeAddUsers BLOCK *********/
5899 /* check that we successfully create the UNIX group */
5900 status
= pdb_create_dom_group(p
->mem_ctx
, name
, r
->out
.rid
);
5903 /******** END SeAddUsers BLOCK *********/
5905 /* check if we should bail out here */
5907 if ( !NT_STATUS_IS_OK(status
) )
5910 ginfo
= policy_handle_create(p
, r
->out
.group_handle
,
5911 GENERIC_RIGHTS_GROUP_ALL_ACCESS
,
5912 struct samr_group_info
, &status
);
5913 if (!NT_STATUS_IS_OK(status
)) {
5916 sid_compose(&ginfo
->sid
, &dinfo
->sid
, *r
->out
.rid
);
5918 force_flush_samr_cache(&dinfo
->sid
);
5920 return NT_STATUS_OK
;
5923 /*********************************************************************
5924 _samr_CreateDomAlias
5925 *********************************************************************/
5927 NTSTATUS
_samr_CreateDomAlias(struct pipes_struct
*p
,
5928 struct samr_CreateDomAlias
*r
)
5930 struct dom_sid info_sid
;
5931 const char *name
= NULL
;
5932 struct samr_domain_info
*dinfo
;
5933 struct samr_alias_info
*ainfo
;
5937 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
5938 SAMR_DOMAIN_ACCESS_CREATE_ALIAS
, NULL
,
5939 struct samr_domain_info
, &result
);
5940 if (!NT_STATUS_IS_OK(result
)) {
5944 if (!sid_check_is_domain(&dinfo
->sid
)) {
5945 return NT_STATUS_ACCESS_DENIED
;
5948 name
= r
->in
.alias_name
->string
;
5950 result
= can_create(p
->mem_ctx
, name
);
5951 if (!NT_STATUS_IS_OK(result
)) {
5955 /******** BEGIN SeAddUsers BLOCK *********/
5958 /* Have passdb create the alias */
5959 result
= pdb_create_alias(name
, r
->out
.rid
);
5962 /******** END SeAddUsers BLOCK *********/
5964 if (!NT_STATUS_IS_OK(result
)) {
5965 DEBUG(10, ("pdb_create_alias failed: %s\n",
5966 nt_errstr(result
)));
5970 sid_compose(&info_sid
, &dinfo
->sid
, *r
->out
.rid
);
5972 if (!sid_to_gid(&info_sid
, &gid
)) {
5973 DEBUG(10, ("Could not find alias just created\n"));
5974 return NT_STATUS_ACCESS_DENIED
;
5977 /* check if the group has been successfully created */
5978 if ( getgrgid(gid
) == NULL
) {
5979 DEBUG(10, ("getgrgid(%u) of just created alias failed\n",
5980 (unsigned int)gid
));
5981 return NT_STATUS_ACCESS_DENIED
;
5984 ainfo
= policy_handle_create(p
, r
->out
.alias_handle
,
5985 GENERIC_RIGHTS_ALIAS_ALL_ACCESS
,
5986 struct samr_alias_info
, &result
);
5987 if (!NT_STATUS_IS_OK(result
)) {
5990 ainfo
->sid
= info_sid
;
5992 force_flush_samr_cache(&info_sid
);
5994 return NT_STATUS_OK
;
5997 /*********************************************************************
5998 _samr_QueryGroupInfo
5999 *********************************************************************/
6001 NTSTATUS
_samr_QueryGroupInfo(struct pipes_struct
*p
,
6002 struct samr_QueryGroupInfo
*r
)
6004 struct samr_group_info
*ginfo
;
6007 union samr_GroupInfo
*info
= NULL
;
6009 uint32_t attributes
= SE_GROUP_MANDATORY
|
6010 SE_GROUP_ENABLED_BY_DEFAULT
|
6012 const char *group_name
= NULL
;
6013 const char *group_description
= NULL
;
6015 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
6016 SAMR_GROUP_ACCESS_LOOKUP_INFO
, NULL
,
6017 struct samr_group_info
, &status
);
6018 if (!NT_STATUS_IS_OK(status
)) {
6023 ret
= get_domain_group_from_sid(ginfo
->sid
, &map
);
6026 return NT_STATUS_INVALID_HANDLE
;
6028 /* FIXME: map contains fstrings */
6029 group_name
= talloc_strdup(r
, map
.nt_name
);
6030 group_description
= talloc_strdup(r
, map
.comment
);
6032 info
= TALLOC_ZERO_P(p
->mem_ctx
, union samr_GroupInfo
);
6034 return NT_STATUS_NO_MEMORY
;
6037 switch (r
->in
.level
) {
6043 status
= pdb_enum_group_members(
6044 p
->mem_ctx
, &ginfo
->sid
, &members
,
6048 if (!NT_STATUS_IS_OK(status
)) {
6052 info
->all
.name
.string
= group_name
;
6053 info
->all
.attributes
= attributes
;
6054 info
->all
.num_members
= num_members
;
6055 info
->all
.description
.string
= group_description
;
6059 info
->name
.string
= group_name
;
6062 info
->attributes
.attributes
= attributes
;
6065 info
->description
.string
= group_description
;
6075 status = pdb_enum_group_members(
6076 p->mem_ctx, &ginfo->sid, &members,
6080 if (!NT_STATUS_IS_OK(status)) {
6084 info
->all2
.name
.string
= group_name
;
6085 info
->all2
.attributes
= attributes
;
6086 info
->all2
.num_members
= 0; /* num_members - in w2k3 this is always 0 */
6087 info
->all2
.description
.string
= group_description
;
6092 return NT_STATUS_INVALID_INFO_CLASS
;
6095 *r
->out
.info
= info
;
6097 return NT_STATUS_OK
;
6100 /*********************************************************************
6102 *********************************************************************/
6104 NTSTATUS
_samr_SetGroupInfo(struct pipes_struct
*p
,
6105 struct samr_SetGroupInfo
*r
)
6107 struct samr_group_info
*ginfo
;
6112 ginfo
= policy_handle_find(p
, r
->in
.group_handle
,
6113 SAMR_GROUP_ACCESS_SET_INFO
, NULL
,
6114 struct samr_group_info
, &status
);
6115 if (!NT_STATUS_IS_OK(status
)) {
6120 ret
= get_domain_group_from_sid(ginfo
->sid
, &map
);
6123 return NT_STATUS_NO_SUCH_GROUP
;
6125 switch (r
->in
.level
) {
6127 fstrcpy(map
.nt_name
, r
->in
.info
->name
.string
);
6132 fstrcpy(map
.comment
, r
->in
.info
->description
.string
);
6135 return NT_STATUS_INVALID_INFO_CLASS
;
6138 /******** BEGIN SeAddUsers BLOCK *********/
6141 status
= pdb_update_group_mapping_entry(&map
);
6144 /******** End SeAddUsers BLOCK *********/
6146 if (NT_STATUS_IS_OK(status
)) {
6147 force_flush_samr_cache(&ginfo
->sid
);
6153 /*********************************************************************
6155 *********************************************************************/
6157 NTSTATUS
_samr_SetAliasInfo(struct pipes_struct
*p
,
6158 struct samr_SetAliasInfo
*r
)
6160 struct samr_alias_info
*ainfo
;
6161 struct acct_info info
;
6164 ainfo
= policy_handle_find(p
, r
->in
.alias_handle
,
6165 SAMR_ALIAS_ACCESS_SET_INFO
, NULL
,
6166 struct samr_alias_info
, &status
);
6167 if (!NT_STATUS_IS_OK(status
)) {
6171 /* get the current group information */
6174 status
= pdb_get_aliasinfo( &ainfo
->sid
, &info
);
6177 if ( !NT_STATUS_IS_OK(status
))
6180 switch (r
->in
.level
) {
6185 /* We currently do not support renaming groups in the
6186 the BUILTIN domain. Refer to util_builtin.c to understand
6187 why. The eventually needs to be fixed to be like Windows
6188 where you can rename builtin groups, just not delete them */
6190 if ( sid_check_is_in_builtin( &ainfo
->sid
) ) {
6191 return NT_STATUS_SPECIAL_ACCOUNT
;
6194 /* There has to be a valid name (and it has to be different) */
6196 if ( !r
->in
.info
->name
.string
)
6197 return NT_STATUS_INVALID_PARAMETER
;
6199 /* If the name is the same just reply "ok". Yes this
6200 doesn't allow you to change the case of a group name. */
6202 if ( strequal( r
->in
.info
->name
.string
, info
.acct_name
) )
6203 return NT_STATUS_OK
;
6205 fstrcpy( info
.acct_name
, r
->in
.info
->name
.string
);
6207 /* make sure the name doesn't already exist as a user
6210 fstr_sprintf( group_name
, "%s\\%s", global_myname(), info
.acct_name
);
6211 status
= can_create( p
->mem_ctx
, group_name
);
6212 if ( !NT_STATUS_IS_OK( status
) )
6216 case ALIASINFODESCRIPTION
:
6217 if (r
->in
.info
->description
.string
) {
6218 fstrcpy(info
.acct_desc
,
6219 r
->in
.info
->description
.string
);
6221 fstrcpy( info
.acct_desc
, "" );
6225 return NT_STATUS_INVALID_INFO_CLASS
;
6228 /******** BEGIN SeAddUsers BLOCK *********/
6231 status
= pdb_set_aliasinfo( &ainfo
->sid
, &info
);
6234 /******** End SeAddUsers BLOCK *********/
6236 if (NT_STATUS_IS_OK(status
))
6237 force_flush_samr_cache(&ainfo
->sid
);
6242 /****************************************************************
6244 ****************************************************************/
6246 NTSTATUS
_samr_GetDomPwInfo(struct pipes_struct
*p
,
6247 struct samr_GetDomPwInfo
*r
)
6249 uint32_t min_password_length
= 0;
6250 uint32_t password_properties
= 0;
6252 /* Perform access check. Since this rpc does not require a
6253 policy handle it will not be caught by the access checks on
6254 SAMR_CONNECT or SAMR_CONNECT_ANON. */
6256 if (!pipe_access_check(p
)) {
6257 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
6258 return NT_STATUS_ACCESS_DENIED
;
6262 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_LEN
,
6263 &min_password_length
);
6264 pdb_get_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS
,
6265 &password_properties
);
6268 if (lp_check_password_script() && *lp_check_password_script()) {
6269 password_properties
|= DOMAIN_PASSWORD_COMPLEX
;
6272 r
->out
.info
->min_password_length
= min_password_length
;
6273 r
->out
.info
->password_properties
= password_properties
;
6275 return NT_STATUS_OK
;
6278 /*********************************************************************
6280 *********************************************************************/
6282 NTSTATUS
_samr_OpenGroup(struct pipes_struct
*p
,
6283 struct samr_OpenGroup
*r
)
6286 struct dom_sid info_sid
;
6288 struct samr_domain_info
*dinfo
;
6289 struct samr_group_info
*ginfo
;
6290 struct security_descriptor
*psd
= NULL
;
6292 uint32 des_access
= r
->in
.access_mask
;
6298 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
6299 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
, NULL
,
6300 struct samr_domain_info
, &status
);
6301 if (!NT_STATUS_IS_OK(status
)) {
6305 /*check if access can be granted as requested by client. */
6306 map_max_allowed_access(p
->server_info
->ptok
,
6307 &p
->server_info
->utok
,
6310 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &grp_generic_mapping
, NULL
, 0);
6311 se_map_generic(&des_access
,&grp_generic_mapping
);
6313 se_priv_copy( &se_rights
, &se_add_users
);
6315 status
= access_check_object(psd
, p
->server_info
->ptok
,
6316 &se_rights
, GENERIC_RIGHTS_GROUP_ALL_ACCESS
,
6317 des_access
, &acc_granted
, "_samr_OpenGroup");
6319 if ( !NT_STATUS_IS_OK(status
) )
6322 /* this should not be hard-coded like this */
6324 if (!sid_check_is_domain(&dinfo
->sid
)) {
6325 return NT_STATUS_ACCESS_DENIED
;
6328 sid_compose(&info_sid
, &dinfo
->sid
, r
->in
.rid
);
6330 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n",
6331 sid_string_dbg(&info_sid
)));
6333 /* check if that group really exists */
6335 ret
= get_domain_group_from_sid(info_sid
, &map
);
6338 return NT_STATUS_NO_SUCH_GROUP
;
6340 ginfo
= policy_handle_create(p
, r
->out
.group_handle
,
6342 struct samr_group_info
, &status
);
6343 if (!NT_STATUS_IS_OK(status
)) {
6346 ginfo
->sid
= info_sid
;
6348 return NT_STATUS_OK
;
6351 /*********************************************************************
6352 _samr_RemoveMemberFromForeignDomain
6353 *********************************************************************/
6355 NTSTATUS
_samr_RemoveMemberFromForeignDomain(struct pipes_struct
*p
,
6356 struct samr_RemoveMemberFromForeignDomain
*r
)
6358 struct samr_domain_info
*dinfo
;
6361 DEBUG(5,("_samr_RemoveMemberFromForeignDomain: removing SID [%s]\n",
6362 sid_string_dbg(r
->in
.sid
)));
6364 /* Find the policy handle. Open a policy on it. */
6366 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
6367 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
, NULL
,
6368 struct samr_domain_info
, &result
);
6369 if (!NT_STATUS_IS_OK(result
)) {
6373 DEBUG(8, ("_samr_RemoveMemberFromForeignDomain: sid is %s\n",
6374 sid_string_dbg(&dinfo
->sid
)));
6376 /* we can only delete a user from a group since we don't have
6377 nested groups anyways. So in the latter case, just say OK */
6379 /* TODO: The above comment nowadays is bogus. Since we have nested
6380 * groups now, and aliases members are never reported out of the unix
6381 * group membership, the "just say OK" makes this call a no-op. For
6382 * us. This needs fixing however. */
6384 /* I've only ever seen this in the wild when deleting a user from
6385 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
6386 * is the user about to be deleted. I very much suspect this is the
6387 * only application of this call. To verify this, let people report
6390 if (!sid_check_is_builtin(&dinfo
->sid
)) {
6391 DEBUG(1,("_samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
6392 "global_sam_sid() = %s\n",
6393 sid_string_dbg(&dinfo
->sid
),
6394 sid_string_dbg(get_global_sam_sid())));
6395 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
6396 return NT_STATUS_OK
;
6399 force_flush_samr_cache(&dinfo
->sid
);
6401 result
= NT_STATUS_OK
;
6406 /*******************************************************************
6407 _samr_QueryDomainInfo2
6408 ********************************************************************/
6410 NTSTATUS
_samr_QueryDomainInfo2(struct pipes_struct
*p
,
6411 struct samr_QueryDomainInfo2
*r
)
6413 struct samr_QueryDomainInfo q
;
6415 q
.in
.domain_handle
= r
->in
.domain_handle
;
6416 q
.in
.level
= r
->in
.level
;
6418 q
.out
.info
= r
->out
.info
;
6420 return _samr_QueryDomainInfo(p
, &q
);
6423 /*******************************************************************
6424 ********************************************************************/
6426 static NTSTATUS
set_dom_info_1(TALLOC_CTX
*mem_ctx
,
6427 struct samr_DomInfo1
*r
)
6429 time_t u_expire
, u_min_age
;
6431 u_expire
= nt_time_to_unix_abs((NTTIME
*)&r
->max_password_age
);
6432 u_min_age
= nt_time_to_unix_abs((NTTIME
*)&r
->min_password_age
);
6434 pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_LEN
,
6435 (uint32_t)r
->min_password_length
);
6436 pdb_set_account_policy(PDB_POLICY_PASSWORD_HISTORY
,
6437 (uint32_t)r
->password_history_length
);
6438 pdb_set_account_policy(PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS
,
6439 (uint32_t)r
->password_properties
);
6440 pdb_set_account_policy(PDB_POLICY_MAX_PASSWORD_AGE
, (int)u_expire
);
6441 pdb_set_account_policy(PDB_POLICY_MIN_PASSWORD_AGE
, (int)u_min_age
);
6443 return NT_STATUS_OK
;
6446 /*******************************************************************
6447 ********************************************************************/
6449 static NTSTATUS
set_dom_info_3(TALLOC_CTX
*mem_ctx
,
6450 struct samr_DomInfo3
*r
)
6454 u_logout
= nt_time_to_unix_abs((NTTIME
*)&r
->force_logoff_time
);
6456 pdb_set_account_policy(PDB_POLICY_TIME_TO_LOGOUT
, (int)u_logout
);
6458 return NT_STATUS_OK
;
6461 /*******************************************************************
6462 ********************************************************************/
6464 static NTSTATUS
set_dom_info_12(TALLOC_CTX
*mem_ctx
,
6465 struct samr_DomInfo12
*r
)
6467 time_t u_lock_duration
, u_reset_time
;
6469 u_lock_duration
= nt_time_to_unix_abs((NTTIME
*)&r
->lockout_duration
);
6470 if (u_lock_duration
!= -1) {
6471 u_lock_duration
/= 60;
6474 u_reset_time
= nt_time_to_unix_abs((NTTIME
*)&r
->lockout_window
)/60;
6476 pdb_set_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION
, (int)u_lock_duration
);
6477 pdb_set_account_policy(PDB_POLICY_RESET_COUNT_TIME
, (int)u_reset_time
);
6478 pdb_set_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT
,
6479 (uint32_t)r
->lockout_threshold
);
6481 return NT_STATUS_OK
;
6484 /*******************************************************************
6486 ********************************************************************/
6488 NTSTATUS
_samr_SetDomainInfo(struct pipes_struct
*p
,
6489 struct samr_SetDomainInfo
*r
)
6491 struct samr_domain_info
*dinfo
;
6493 uint32_t acc_required
= 0;
6495 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__
));
6497 switch (r
->in
.level
) {
6498 case 1: /* DomainPasswordInformation */
6499 case 12: /* DomainLockoutInformation */
6500 /* DOMAIN_WRITE_PASSWORD_PARAMETERS */
6501 acc_required
= SAMR_DOMAIN_ACCESS_SET_INFO_1
;
6503 case 3: /* DomainLogoffInformation */
6504 case 4: /* DomainOemInformation */
6505 /* DOMAIN_WRITE_OTHER_PARAMETERS */
6506 acc_required
= SAMR_DOMAIN_ACCESS_SET_INFO_2
;
6508 case 6: /* DomainReplicationInformation */
6509 case 9: /* DomainStateInformation */
6510 case 7: /* DomainServerRoleInformation */
6511 /* DOMAIN_ADMINISTER_SERVER */
6512 acc_required
= SAMR_DOMAIN_ACCESS_SET_INFO_3
;
6515 return NT_STATUS_INVALID_INFO_CLASS
;
6518 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
6520 struct samr_domain_info
, &status
);
6521 if (!NT_STATUS_IS_OK(status
)) {
6525 DEBUG(5,("_samr_SetDomainInfo: level: %d\n", r
->in
.level
));
6527 switch (r
->in
.level
) {
6529 status
= set_dom_info_1(p
->mem_ctx
, &r
->in
.info
->info1
);
6532 status
= set_dom_info_3(p
->mem_ctx
, &r
->in
.info
->info3
);
6543 status
= set_dom_info_12(p
->mem_ctx
, &r
->in
.info
->info12
);
6546 return NT_STATUS_INVALID_INFO_CLASS
;
6549 if (!NT_STATUS_IS_OK(status
)) {
6553 DEBUG(5,("_samr_SetDomainInfo: %d\n", __LINE__
));
6555 return NT_STATUS_OK
;
6558 /****************************************************************
6559 _samr_GetDisplayEnumerationIndex
6560 ****************************************************************/
6562 NTSTATUS
_samr_GetDisplayEnumerationIndex(struct pipes_struct
*p
,
6563 struct samr_GetDisplayEnumerationIndex
*r
)
6565 struct samr_domain_info
*dinfo
;
6566 uint32_t max_entries
= (uint32_t) -1;
6567 uint32_t enum_context
= 0;
6569 uint32_t num_account
= 0;
6570 struct samr_displayentry
*entries
= NULL
;
6573 DEBUG(5,("_samr_GetDisplayEnumerationIndex: %d\n", __LINE__
));
6575 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
6576 SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS
, NULL
,
6577 struct samr_domain_info
, &status
);
6578 if (!NT_STATUS_IS_OK(status
)) {
6582 if ((r
->in
.level
< 1) || (r
->in
.level
> 3)) {
6583 DEBUG(0,("_samr_GetDisplayEnumerationIndex: "
6584 "Unknown info level (%u)\n",
6586 return NT_STATUS_INVALID_INFO_CLASS
;
6591 /* The following done as ROOT. Don't return without unbecome_root(). */
6593 switch (r
->in
.level
) {
6595 if (dinfo
->disp_info
->users
== NULL
) {
6596 dinfo
->disp_info
->users
= pdb_search_users(
6597 dinfo
->disp_info
, ACB_NORMAL
);
6598 if (dinfo
->disp_info
->users
== NULL
) {
6600 return NT_STATUS_ACCESS_DENIED
;
6602 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6603 "starting user enumeration at index %u\n",
6604 (unsigned int)enum_context
));
6606 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6607 "using cached user enumeration at index %u\n",
6608 (unsigned int)enum_context
));
6610 num_account
= pdb_search_entries(dinfo
->disp_info
->users
,
6611 enum_context
, max_entries
,
6615 if (dinfo
->disp_info
->machines
== NULL
) {
6616 dinfo
->disp_info
->machines
= pdb_search_users(
6617 dinfo
->disp_info
, ACB_WSTRUST
|ACB_SVRTRUST
);
6618 if (dinfo
->disp_info
->machines
== NULL
) {
6620 return NT_STATUS_ACCESS_DENIED
;
6622 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6623 "starting machine enumeration at index %u\n",
6624 (unsigned int)enum_context
));
6626 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6627 "using cached machine enumeration at index %u\n",
6628 (unsigned int)enum_context
));
6630 num_account
= pdb_search_entries(dinfo
->disp_info
->machines
,
6631 enum_context
, max_entries
,
6635 if (dinfo
->disp_info
->groups
== NULL
) {
6636 dinfo
->disp_info
->groups
= pdb_search_groups(
6638 if (dinfo
->disp_info
->groups
== NULL
) {
6640 return NT_STATUS_ACCESS_DENIED
;
6642 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6643 "starting group enumeration at index %u\n",
6644 (unsigned int)enum_context
));
6646 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6647 "using cached group enumeration at index %u\n",
6648 (unsigned int)enum_context
));
6650 num_account
= pdb_search_entries(dinfo
->disp_info
->groups
,
6651 enum_context
, max_entries
,
6656 smb_panic("info class changed");
6662 /* Ensure we cache this enumeration. */
6663 set_disp_info_cache_timeout(dinfo
->disp_info
, DISP_INFO_CACHE_TIMEOUT
);
6665 DEBUG(10,("_samr_GetDisplayEnumerationIndex: looking for :%s\n",
6666 r
->in
.name
->string
));
6668 for (i
=0; i
<num_account
; i
++) {
6669 if (strequal(entries
[i
].account_name
, r
->in
.name
->string
)) {
6670 DEBUG(10,("_samr_GetDisplayEnumerationIndex: "
6671 "found %s at idx %d\n",
6672 r
->in
.name
->string
, i
));
6674 return NT_STATUS_OK
;
6678 /* assuming account_name lives at the very end */
6679 *r
->out
.idx
= num_account
;
6681 return NT_STATUS_NO_MORE_ENTRIES
;
6684 /****************************************************************
6685 _samr_GetDisplayEnumerationIndex2
6686 ****************************************************************/
6688 NTSTATUS
_samr_GetDisplayEnumerationIndex2(struct pipes_struct
*p
,
6689 struct samr_GetDisplayEnumerationIndex2
*r
)
6691 struct samr_GetDisplayEnumerationIndex q
;
6693 q
.in
.domain_handle
= r
->in
.domain_handle
;
6694 q
.in
.level
= r
->in
.level
;
6695 q
.in
.name
= r
->in
.name
;
6697 q
.out
.idx
= r
->out
.idx
;
6699 return _samr_GetDisplayEnumerationIndex(p
, &q
);
6702 /****************************************************************
6704 ****************************************************************/
6706 NTSTATUS
_samr_RidToSid(struct pipes_struct
*p
,
6707 struct samr_RidToSid
*r
)
6709 struct samr_domain_info
*dinfo
;
6713 dinfo
= policy_handle_find(p
, r
->in
.domain_handle
,
6715 struct samr_domain_info
, &status
);
6716 if (!NT_STATUS_IS_OK(status
)) {
6720 if (!sid_compose(&sid
, &dinfo
->sid
, r
->in
.rid
)) {
6721 return NT_STATUS_NO_MEMORY
;
6724 *r
->out
.sid
= sid_dup_talloc(p
->mem_ctx
, &sid
);
6726 return NT_STATUS_NO_MEMORY
;
6729 return NT_STATUS_OK
;
6732 /****************************************************************
6733 ****************************************************************/
6735 static enum samr_ValidationStatus
samr_ValidatePassword_Change(TALLOC_CTX
*mem_ctx
,
6736 const struct samr_PwInfo
*dom_pw_info
,
6737 const struct samr_ValidatePasswordReq2
*req
,
6738 struct samr_ValidatePasswordRepCtr
*rep
)
6742 if (req
->password
.string
== NULL
) {
6743 return SAMR_VALIDATION_STATUS_SUCCESS
;
6745 if (strlen(req
->password
.string
) < dom_pw_info
->min_password_length
) {
6746 ZERO_STRUCT(rep
->info
);
6747 return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT
;
6749 if (dom_pw_info
->password_properties
& DOMAIN_PASSWORD_COMPLEX
) {
6750 status
= check_password_complexity(req
->account
.string
,
6751 req
->password
.string
,
6753 if (!NT_STATUS_IS_OK(status
)) {
6754 ZERO_STRUCT(rep
->info
);
6755 return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH
;
6759 return SAMR_VALIDATION_STATUS_SUCCESS
;
6762 /****************************************************************
6763 ****************************************************************/
6765 static enum samr_ValidationStatus
samr_ValidatePassword_Reset(TALLOC_CTX
*mem_ctx
,
6766 const struct samr_PwInfo
*dom_pw_info
,
6767 const struct samr_ValidatePasswordReq3
*req
,
6768 struct samr_ValidatePasswordRepCtr
*rep
)
6772 if (req
->password
.string
== NULL
) {
6773 return SAMR_VALIDATION_STATUS_SUCCESS
;
6775 if (strlen(req
->password
.string
) < dom_pw_info
->min_password_length
) {
6776 ZERO_STRUCT(rep
->info
);
6777 return SAMR_VALIDATION_STATUS_PWD_TOO_SHORT
;
6779 if (dom_pw_info
->password_properties
& DOMAIN_PASSWORD_COMPLEX
) {
6780 status
= check_password_complexity(req
->account
.string
,
6781 req
->password
.string
,
6783 if (!NT_STATUS_IS_OK(status
)) {
6784 ZERO_STRUCT(rep
->info
);
6785 return SAMR_VALIDATION_STATUS_NOT_COMPLEX_ENOUGH
;
6789 return SAMR_VALIDATION_STATUS_SUCCESS
;
6792 /****************************************************************
6793 _samr_ValidatePassword
6794 ****************************************************************/
6796 NTSTATUS
_samr_ValidatePassword(struct pipes_struct
*p
,
6797 struct samr_ValidatePassword
*r
)
6799 union samr_ValidatePasswordRep
*rep
;
6801 struct samr_GetDomPwInfo pw
;
6802 struct samr_PwInfo dom_pw_info
;
6804 if (r
->in
.level
< 1 || r
->in
.level
> 3) {
6805 return NT_STATUS_INVALID_INFO_CLASS
;
6808 pw
.in
.domain_name
= NULL
;
6809 pw
.out
.info
= &dom_pw_info
;
6811 status
= _samr_GetDomPwInfo(p
, &pw
);
6812 if (!NT_STATUS_IS_OK(status
)) {
6816 rep
= talloc_zero(p
->mem_ctx
, union samr_ValidatePasswordRep
);
6818 return NT_STATUS_NO_MEMORY
;
6821 switch (r
->in
.level
) {
6823 status
= NT_STATUS_NOT_SUPPORTED
;
6826 rep
->ctr2
.status
= samr_ValidatePassword_Change(p
->mem_ctx
,
6832 rep
->ctr3
.status
= samr_ValidatePassword_Reset(p
->mem_ctx
,
6838 status
= NT_STATUS_INVALID_INFO_CLASS
;
6842 if (!NT_STATUS_IS_OK(status
)) {
6849 return NT_STATUS_OK
;
6852 /****************************************************************
6853 ****************************************************************/
6855 NTSTATUS
_samr_Shutdown(struct pipes_struct
*p
,
6856 struct samr_Shutdown
*r
)
6858 p
->rng_fault_state
= true;
6859 return NT_STATUS_NOT_IMPLEMENTED
;
6862 /****************************************************************
6863 ****************************************************************/
6865 NTSTATUS
_samr_SetMemberAttributesOfGroup(struct pipes_struct
*p
,
6866 struct samr_SetMemberAttributesOfGroup
*r
)
6868 p
->rng_fault_state
= true;
6869 return NT_STATUS_NOT_IMPLEMENTED
;
6872 /****************************************************************
6873 ****************************************************************/
6875 NTSTATUS
_samr_TestPrivateFunctionsDomain(struct pipes_struct
*p
,
6876 struct samr_TestPrivateFunctionsDomain
*r
)
6878 return NT_STATUS_NOT_IMPLEMENTED
;
6881 /****************************************************************
6882 ****************************************************************/
6884 NTSTATUS
_samr_TestPrivateFunctionsUser(struct pipes_struct
*p
,
6885 struct samr_TestPrivateFunctionsUser
*r
)
6887 return NT_STATUS_NOT_IMPLEMENTED
;
6890 /****************************************************************
6891 ****************************************************************/
6893 NTSTATUS
_samr_AddMultipleMembersToAlias(struct pipes_struct
*p
,
6894 struct samr_AddMultipleMembersToAlias
*r
)
6896 p
->rng_fault_state
= true;
6897 return NT_STATUS_NOT_IMPLEMENTED
;
6900 /****************************************************************
6901 ****************************************************************/
6903 NTSTATUS
_samr_RemoveMultipleMembersFromAlias(struct pipes_struct
*p
,
6904 struct samr_RemoveMultipleMembersFromAlias
*r
)
6906 p
->rng_fault_state
= true;
6907 return NT_STATUS_NOT_IMPLEMENTED
;
6910 /****************************************************************
6911 ****************************************************************/
6913 NTSTATUS
_samr_SetBootKeyInformation(struct pipes_struct
*p
,
6914 struct samr_SetBootKeyInformation
*r
)
6916 p
->rng_fault_state
= true;
6917 return NT_STATUS_NOT_IMPLEMENTED
;
6920 /****************************************************************
6921 ****************************************************************/
6923 NTSTATUS
_samr_GetBootKeyInformation(struct pipes_struct
*p
,
6924 struct samr_GetBootKeyInformation
*r
)
6926 p
->rng_fault_state
= true;
6927 return NT_STATUS_NOT_IMPLEMENTED
;
6930 /****************************************************************
6931 ****************************************************************/
6933 NTSTATUS
_samr_SetDsrmPassword(struct pipes_struct
*p
,
6934 struct samr_SetDsrmPassword
*r
)
6936 p
->rng_fault_state
= true;
6937 return NT_STATUS_NOT_IMPLEMENTED
;