2001-02-27 21:22:39 +03:00
/*
2002-01-30 09:08:46 +03:00
* Unix SMB / CIFS implementation .
2001-02-27 21:22:39 +03:00
* RPC Pipe client / server routines
2005-01-19 19:52:19 +03:00
* Copyright ( C ) Andrew Tridgell 1992 - 1997 ,
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997 ,
2002-08-17 19:34:15 +04:00
* Copyright ( C ) Paul Ashton 1997 ,
* Copyright ( C ) Marc Jacobsen 1999 ,
2005-11-27 04:17:24 +03:00
* Copyright ( C ) Jeremy Allison 2001 - 2005 ,
2005-09-30 21:13:37 +04:00
* Copyright ( C ) Jean François Micouleau 1998 - 2001 ,
2004-04-13 18:39:48 +04:00
* Copyright ( C ) Jim McDonough < jmcd @ us . ibm . com > 2002 ,
2005-01-19 19:52:19 +03:00
* Copyright ( C ) Gerald ( Jerry ) Carter 2003 - 2004 ,
2005-06-14 22:38:15 +04:00
* Copyright ( C ) Simo Sorce 2003.
2005-11-27 04:17:24 +03:00
* Copyright ( C ) Volker Lendecke 2005.
2001-02-27 21:22:39 +03:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2001-02-27 21:22:39 +03:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2007-07-10 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2001-02-27 21:22:39 +03:00
*/
/*
* This is the implementation of the SAMR code .
*/
# include "includes.h"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
2005-02-01 01:42:30 +03:00
# define SAMR_USR_RIGHTS_WRITE_PW \
( READ_CONTROL_ACCESS | \
SA_RIGHT_USER_CHANGE_PASSWORD | \
SA_RIGHT_USER_SET_LOC_COM )
2006-10-03 21:14:18 +04:00
# define SAMR_USR_RIGHTS_CANT_WRITE_PW \
( READ_CONTROL_ACCESS | SA_RIGHT_USER_SET_LOC_COM )
2005-02-01 01:42:30 +03:00
2005-11-22 23:26:23 +03:00
# define DISP_INFO_CACHE_TIMEOUT 10
2005-11-19 02:15:47 +03:00
2005-04-15 17:41:49 +04:00
typedef struct disp_info {
2005-11-19 02:15:47 +03:00
DOM_SID sid ; /* identify which domain this is. */
2007-10-19 04:40:25 +04:00
bool builtin_domain ; /* Quick flag to check if this is the builtin domain. */
2005-06-22 18:16:10 +04:00
struct pdb_search * users ; /* querydispinfo 1 and 4 */
struct pdb_search * machines ; /* querydispinfo 2 */
struct pdb_search * groups ; /* querydispinfo 3 and 5, enumgroups */
struct pdb_search * aliases ; /* enumaliases */
uint16 enum_acb_mask ;
struct pdb_search * enum_users ; /* enumusers with a mask */
2005-11-19 02:15:47 +03:00
2007-03-11 19:49:16 +03:00
struct timed_event * cache_timeout_event ; /* cache idle timeout
* handler . */
2001-12-21 16:36:14 +03:00
} DISP_INFO ;
2005-11-19 02:15:47 +03:00
/* We keep a static list of these by SID as modern clients close down
all resources between each request in a complete enumeration . */
2001-03-11 03:32:10 +03:00
struct samr_info {
2001-12-21 16:36:14 +03:00
/* for use by the \PIPE\samr policy */
DOM_SID sid ;
2007-10-19 04:40:25 +04:00
bool builtin_domain ; /* Quick flag to check if this is the builtin domain. */
2001-12-21 16:36:14 +03:00
uint32 status ; /* some sort of flag. best to record it. comes from opnum 0x39 */
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info ;
2002-07-15 14:35:28 +04:00
TALLOC_CTX * mem_ctx ;
2001-03-11 03:32:10 +03:00
} ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping sam_generic_mapping = {
2005-11-26 23:28:12 +03:00
GENERIC_RIGHTS_SAM_READ ,
GENERIC_RIGHTS_SAM_WRITE ,
GENERIC_RIGHTS_SAM_EXECUTE ,
GENERIC_RIGHTS_SAM_ALL_ACCESS } ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping dom_generic_mapping = {
2005-11-26 23:28:12 +03:00
GENERIC_RIGHTS_DOMAIN_READ ,
GENERIC_RIGHTS_DOMAIN_WRITE ,
GENERIC_RIGHTS_DOMAIN_EXECUTE ,
GENERIC_RIGHTS_DOMAIN_ALL_ACCESS } ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping usr_generic_mapping = {
2005-11-26 23:28:12 +03:00
GENERIC_RIGHTS_USER_READ ,
GENERIC_RIGHTS_USER_WRITE ,
GENERIC_RIGHTS_USER_EXECUTE ,
GENERIC_RIGHTS_USER_ALL_ACCESS } ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping usr_nopwchange_generic_mapping = {
2006-10-03 21:14:18 +04:00
GENERIC_RIGHTS_USER_READ ,
GENERIC_RIGHTS_USER_WRITE ,
GENERIC_RIGHTS_USER_EXECUTE & ~ SA_RIGHT_USER_CHANGE_PASSWORD ,
GENERIC_RIGHTS_USER_ALL_ACCESS } ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping grp_generic_mapping = {
2005-11-26 23:28:12 +03:00
GENERIC_RIGHTS_GROUP_READ ,
GENERIC_RIGHTS_GROUP_WRITE ,
GENERIC_RIGHTS_GROUP_EXECUTE ,
GENERIC_RIGHTS_GROUP_ALL_ACCESS } ;
2007-10-06 01:41:17 +04:00
static const struct generic_mapping ali_generic_mapping = {
2005-11-26 23:28:12 +03:00
GENERIC_RIGHTS_ALIAS_READ ,
GENERIC_RIGHTS_ALIAS_WRITE ,
GENERIC_RIGHTS_ALIAS_EXECUTE ,
GENERIC_RIGHTS_ALIAS_ALL_ACCESS } ;
2002-07-15 14:35:28 +04:00
2008-02-06 23:29:17 +03:00
/*******************************************************************
inits a structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void init_lsa_String ( struct lsa_String * name , const char * s )
{
name - > string = s ;
}
2005-01-26 23:36:44 +03:00
/*******************************************************************
2005-02-01 01:42:30 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-01-26 23:36:44 +03:00
2005-02-01 01:42:30 +03:00
static NTSTATUS make_samr_object_sd ( TALLOC_CTX * ctx , SEC_DESC * * psd , size_t * sd_size ,
2007-10-06 01:41:17 +04:00
const struct generic_mapping * map ,
2005-02-01 01:42:30 +03:00
DOM_SID * sid , uint32 sid_access )
2005-01-26 23:36:44 +03:00
{
2005-06-14 22:38:15 +04:00
DOM_SID domadmin_sid ;
2005-02-01 01:42:30 +03:00
SEC_ACE ace [ 5 ] ; /* at most 5 entries */
2005-01-26 23:36:44 +03:00
SEC_ACCESS mask ;
size_t i = 0 ;
SEC_ACL * psa = NULL ;
2005-02-01 01:42:30 +03:00
/* basic access for Everyone */
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
init_sec_access ( & mask , map - > generic_execute | map - > generic_read ) ;
init_sec_ace ( & ace [ i + + ] , & global_sid_World , SEC_ACE_TYPE_ACCESS_ALLOWED , mask , 0 ) ;
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
/* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
init_sec_access ( & mask , map - > generic_all ) ;
2008-02-05 14:54:19 +03:00
2005-06-14 22:38:15 +04:00
init_sec_ace ( & ace [ i + + ] , & global_sid_Builtin_Administrators , SEC_ACE_TYPE_ACCESS_ALLOWED , mask , 0 ) ;
init_sec_ace ( & ace [ i + + ] , & global_sid_Builtin_Account_Operators , SEC_ACE_TYPE_ACCESS_ALLOWED , mask , 0 ) ;
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
/* Add Full Access for Domain Admins if we are a DC */
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( IS_DC ) {
sid_copy ( & domadmin_sid , get_global_sam_sid ( ) ) ;
sid_append_rid ( & domadmin_sid , DOMAIN_GROUP_RID_ADMINS ) ;
init_sec_ace ( & ace [ i + + ] , & domadmin_sid , SEC_ACE_TYPE_ACCESS_ALLOWED , mask , 0 ) ;
}
2005-02-01 01:42:30 +03:00
/* if we have a sid, give it some special access */
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
if ( sid ) {
init_sec_access ( & mask , sid_access ) ;
init_sec_ace ( & ace [ i + + ] , sid , SEC_ACE_TYPE_ACCESS_ALLOWED , mask , 0 ) ;
2006-02-04 01:19:41 +03:00
}
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
/* create the security descriptor */
2005-09-30 21:13:37 +04:00
2005-02-01 01:42:30 +03:00
if ( ( psa = make_sec_acl ( ctx , NT4_ACL_REVISION , i , ace ) ) = = NULL )
2005-01-26 23:36:44 +03:00
return NT_STATUS_NO_MEMORY ;
2007-12-21 00:27:01 +03:00
if ( ( * psd = make_sec_desc ( ctx , SECURITY_DESCRIPTOR_REVISION_1 ,
SEC_DESC_SELF_RELATIVE , NULL , NULL , NULL ,
psa , sd_size ) ) = = NULL )
2005-01-26 23:36:44 +03:00
return NT_STATUS_NO_MEMORY ;
return NT_STATUS_OK ;
}
2002-07-15 14:35:28 +04:00
/*******************************************************************
Checks if access to an object should be granted , and returns that
level of access for further checks .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 14:54:19 +03:00
static NTSTATUS access_check_samr_object ( SEC_DESC * psd , NT_USER_TOKEN * token ,
2005-01-26 23:36:44 +03:00
SE_PRIV * rights , uint32 rights_mask ,
2008-02-05 14:54:19 +03:00
uint32 des_access , uint32 * acc_granted ,
2005-01-26 23:36:44 +03:00
const char * debug )
2002-07-15 14:35:28 +04:00
{
NTSTATUS status = NT_STATUS_ACCESS_DENIED ;
2005-01-26 23:36:44 +03:00
uint32 saved_mask = 0 ;
2002-07-15 14:35:28 +04:00
2008-02-05 14:54:19 +03:00
/* check privileges; certain SAM access bits should be overridden
by privileges ( mostly having to do with creating / modifying / deleting
2005-01-26 23:36:44 +03:00
users and groups ) */
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( rights & & user_has_any_privilege ( token , rights ) ) {
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
saved_mask = ( des_access & rights_mask ) ;
des_access & = ~ saved_mask ;
2008-02-05 14:54:19 +03:00
2005-01-28 19:55:09 +03:00
DEBUG ( 4 , ( " access_check_samr_object: user rights access mask [0x%x] \n " ,
rights_mask ) ) ;
2005-01-26 23:36:44 +03:00
}
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
/* check the security descriptor first */
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( se_access_check ( psd , token , des_access , acc_granted , & status ) )
goto done ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
/* give root a free pass */
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( geteuid ( ) = = sec_initial_uid ( ) ) {
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
DEBUG ( 4 , ( " %s: ACCESS should be DENIED (requested: %#010x) \n " , debug , des_access ) ) ;
DEBUGADD ( 4 , ( " but overritten by euid == sec_initial_uid() \n " ) ) ;
2008-02-05 14:54:19 +03:00
2003-03-21 16:35:15 +03:00
* acc_granted = des_access ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
status = NT_STATUS_OK ;
goto done ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
done :
2008-02-05 14:54:19 +03:00
/* add in any bits saved during the privilege check (only
2005-01-28 19:55:09 +03:00
matters is status is ok ) */
2008-02-05 14:54:19 +03:00
2005-01-28 19:55:09 +03:00
* acc_granted | = rights_mask ;
2005-01-27 05:16:02 +03:00
2008-02-05 14:54:19 +03:00
DEBUG ( 4 , ( " %s: access %s (requested: 0x%08x, granted: 0x%08x) \n " ,
debug , NT_STATUS_IS_OK ( status ) ? " GRANTED " : " DENIED " ,
2005-01-27 05:16:02 +03:00
des_access , * acc_granted ) ) ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
return status ;
}
/*******************************************************************
Checks if access to a function can be granted
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-01-14 22:26:13 +03:00
static NTSTATUS access_check_samr_function ( uint32 acc_granted , uint32 acc_required , const char * debug )
2002-07-15 14:35:28 +04:00
{
2008-02-05 14:54:19 +03:00
DEBUG ( 5 , ( " %s: access check ((granted: %#010x; required: %#010x) \n " ,
2005-01-26 23:36:44 +03:00
debug , acc_granted , acc_required ) ) ;
/* check the security descriptor first */
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ( acc_granted & acc_required ) = = acc_required )
return NT_STATUS_OK ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
/* give root a free pass */
if ( geteuid ( ) = = sec_initial_uid ( ) ) {
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
DEBUG ( 4 , ( " %s: ACCESS should be DENIED (granted: %#010x; required: %#010x) \n " ,
2002-07-15 14:35:28 +04:00
debug , acc_granted , acc_required ) ) ;
2005-01-26 23:36:44 +03:00
DEBUGADD ( 4 , ( " but overwritten by euid == 0 \n " ) ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
return NT_STATUS_OK ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
DEBUG ( 2 , ( " %s: ACCESS DENIED (granted: %#010x; required: %#010x) \n " ,
2005-01-26 23:36:44 +03:00
debug , acc_granted , acc_required ) ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
return NT_STATUS_ACCESS_DENIED ;
2002-07-15 14:35:28 +04:00
}
2005-11-19 02:15:47 +03:00
/*******************************************************************
Fetch or create a dispinfo struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-02-27 20:21:21 +03:00
static DISP_INFO * get_samr_dispinfo_by_sid ( DOM_SID * psid )
2005-11-19 02:15:47 +03:00
{
2007-02-27 20:21:21 +03:00
/*
* We do a static cache for DISP_INFO ' s here . Explanation can be found
* in Jeremy ' s checkin message to r11793 :
*
* Fix the SAMR cache so it works across completely insane
* client behaviour ( ie . :
* open pipe / open SAMR handle / enumerate 0 - 1024
* close SAMR handle , close pipe .
* open pipe / open SAMR handle / enumerate 1024 - 2048. . .
* close SAMR handle , close pipe .
* And on ad - nausium . Amazing . . . . probably object - oriented
* client side programming in action yet again .
* This change should * massively * improve performance when
* enumerating users from an LDAP database .
* Jeremy .
*
* " Our " and the builtin domain are the only ones where we ever
* enumerate stuff , so just cache 2 entries .
*/
static struct disp_info builtin_dispinfo ;
static struct disp_info domain_dispinfo ;
2005-11-19 02:15:47 +03:00
2007-02-27 02:06:17 +03:00
/* There are two cases to consider here:
1 ) The SID is a domain SID and we look for an equality match , or
2008-02-05 14:54:19 +03:00
2 ) This is an account SID and so we return the DISP_INFO * for our
2007-02-27 02:06:17 +03:00
domain */
2007-02-27 20:21:21 +03:00
if ( psid = = NULL ) {
2005-11-19 02:15:47 +03:00
return NULL ;
2007-02-27 20:21:21 +03:00
}
2005-11-19 02:15:47 +03:00
2007-02-27 20:21:21 +03:00
if ( sid_check_is_builtin ( psid ) | | sid_check_is_in_builtin ( psid ) ) {
/*
* Necessary only once , but it does not really hurt .
*/
sid_copy ( & builtin_dispinfo . sid , & global_sid_Builtin ) ;
2005-11-27 04:17:24 +03:00
2007-02-27 20:21:21 +03:00
return & builtin_dispinfo ;
2007-02-27 02:06:17 +03:00
}
2008-02-05 14:54:19 +03:00
2007-02-27 20:21:21 +03:00
if ( sid_check_is_domain ( psid ) | | sid_check_is_in_our_domain ( psid ) ) {
/*
* Necessary only once , but it does not really hurt .
*/
sid_copy ( & domain_dispinfo . sid , get_global_sam_sid ( ) ) ;
2005-11-19 02:15:47 +03:00
2007-02-27 20:21:21 +03:00
return & domain_dispinfo ;
}
2005-11-19 02:15:47 +03:00
2007-02-27 20:21:21 +03:00
return NULL ;
2005-11-19 02:15:47 +03:00
}
2002-07-15 14:35:28 +04:00
2002-01-02 10:27:33 +03:00
/*******************************************************************
Create a samr_info struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct samr_info * get_samr_info_by_sid ( DOM_SID * psid )
{
struct samr_info * info ;
fstring sid_str ;
2002-07-15 14:35:28 +04:00
TALLOC_CTX * mem_ctx ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
if ( psid ) {
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_str , psid ) ;
2002-07-15 14:35:28 +04:00
} else {
fstrcpy ( sid_str , " (NULL) " ) ;
}
2002-12-20 23:21:31 +03:00
mem_ctx = talloc_init ( " samr_info for domain sid %s " , sid_str ) ;
2002-01-02 10:27:33 +03:00
2005-04-15 17:41:49 +04:00
if ( ( info = TALLOC_ZERO_P ( mem_ctx , struct samr_info ) ) = = NULL )
2002-01-02 10:27:33 +03:00
return NULL ;
2002-07-15 14:35:28 +04:00
DEBUG ( 10 , ( " get_samr_info_by_sid: created new info for sid %s \n " , sid_str ) ) ;
2002-01-02 10:27:33 +03:00
if ( psid ) {
sid_copy ( & info - > sid , psid ) ;
2007-02-27 02:06:17 +03:00
info - > builtin_domain = sid_check_is_builtin ( psid ) ;
2002-01-02 10:27:33 +03:00
} else {
DEBUG ( 10 , ( " get_samr_info_by_sid: created new info for NULL sid. \n " ) ) ;
2007-02-27 02:06:17 +03:00
info - > builtin_domain = False ;
2002-01-02 10:27:33 +03:00
}
2002-07-15 14:35:28 +04:00
info - > mem_ctx = mem_ctx ;
2005-11-19 02:15:47 +03:00
2007-02-27 20:21:21 +03:00
info - > disp_info = get_samr_dispinfo_by_sid ( psid ) ;
2007-02-27 02:06:17 +03:00
2002-01-02 10:27:33 +03:00
return info ;
}
2001-03-11 03:32:10 +03:00
/*******************************************************************
2005-11-19 02:15:47 +03:00
Function to free the per SID data .
2001-03-11 03:32:10 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-09 01:58:29 +04:00
2007-03-11 19:49:16 +03:00
static void free_samr_cache ( DISP_INFO * disp_info )
2005-11-19 02:15:47 +03:00
{
2007-03-11 19:49:16 +03:00
DEBUG ( 10 , ( " free_samr_cache: deleting cache for SID %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & disp_info - > sid ) ) ) ;
2005-11-19 02:15:47 +03:00
2005-11-25 13:19:24 +03:00
/* We need to become root here because the paged search might have to
* tell the LDAP server we ' re not interested in the rest anymore . */
become_root ( ) ;
2005-11-19 02:15:47 +03:00
if ( disp_info - > users ) {
DEBUG ( 10 , ( " free_samr_cache: deleting users cache \n " ) ) ;
pdb_search_destroy ( disp_info - > users ) ;
disp_info - > users = NULL ;
}
if ( disp_info - > machines ) {
DEBUG ( 10 , ( " free_samr_cache: deleting machines cache \n " ) ) ;
pdb_search_destroy ( disp_info - > machines ) ;
disp_info - > machines = NULL ;
}
if ( disp_info - > groups ) {
DEBUG ( 10 , ( " free_samr_cache: deleting groups cache \n " ) ) ;
pdb_search_destroy ( disp_info - > groups ) ;
disp_info - > groups = NULL ;
}
if ( disp_info - > aliases ) {
DEBUG ( 10 , ( " free_samr_cache: deleting aliases cache \n " ) ) ;
pdb_search_destroy ( disp_info - > aliases ) ;
disp_info - > aliases = NULL ;
}
if ( disp_info - > enum_users ) {
DEBUG ( 10 , ( " free_samr_cache: deleting enum_users cache \n " ) ) ;
pdb_search_destroy ( disp_info - > enum_users ) ;
disp_info - > enum_users = NULL ;
}
disp_info - > enum_acb_mask = 0 ;
2005-11-25 13:19:24 +03:00
unbecome_root ( ) ;
2005-11-19 02:15:47 +03:00
}
2002-09-25 19:19:00 +04:00
/*******************************************************************
Function to free the per handle data .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-09 01:58:29 +04:00
2001-12-22 01:34:49 +03:00
static void free_samr_info ( void * ptr )
{
struct samr_info * info = ( struct samr_info * ) ptr ;
2005-11-19 02:15:47 +03:00
/* Only free the dispinfo cache if no one bothered to set up
a timeout . */
2007-03-11 19:49:16 +03:00
if ( info - > disp_info & & info - > disp_info - > cache_timeout_event = = NULL ) {
free_samr_cache ( info - > disp_info ) ;
2005-11-19 02:15:47 +03:00
}
2002-07-15 14:35:28 +04:00
talloc_destroy ( info - > mem_ctx ) ;
2001-03-11 03:32:10 +03:00
}
2005-11-19 02:15:47 +03:00
/*******************************************************************
Idle event handler . Throw away the disp info cache .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-03-11 19:49:16 +03:00
static void disp_info_cache_idle_timeout_handler ( struct event_context * ev_ctx ,
struct timed_event * te ,
const struct timeval * now ,
void * private_data )
2005-11-19 02:15:47 +03:00
{
2007-03-11 19:49:16 +03:00
DISP_INFO * disp_info = ( DISP_INFO * ) private_data ;
2005-11-22 23:26:23 +03:00
2007-03-11 19:49:16 +03:00
TALLOC_FREE ( disp_info - > cache_timeout_event ) ;
2005-11-19 02:15:47 +03:00
2007-03-11 19:49:16 +03:00
DEBUG ( 10 , ( " disp_info_cache_idle_timeout_handler: caching timed "
" out \n " ) ) ;
free_samr_cache ( disp_info ) ;
2005-11-19 02:15:47 +03:00
}
/*******************************************************************
Setup cache removal idle event handler .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void set_disp_info_cache_timeout ( DISP_INFO * disp_info , time_t secs_fromnow )
{
/* Remove any pending timeout and update. */
2007-03-11 19:49:16 +03:00
TALLOC_FREE ( disp_info - > cache_timeout_event ) ;
2005-11-19 02:15:47 +03:00
2007-03-11 19:49:16 +03:00
DEBUG ( 10 , ( " set_disp_info_cache_timeout: caching enumeration for "
2007-12-15 23:11:36 +03:00
" SID %s for %u seconds \n " , sid_string_dbg ( & disp_info - > sid ) ,
2007-03-11 19:49:16 +03:00
( unsigned int ) secs_fromnow ) ) ;
2005-11-19 02:15:47 +03:00
2007-03-11 19:49:16 +03:00
disp_info - > cache_timeout_event = event_add_timed (
smbd_event_context ( ) , NULL ,
timeval_current_ofs ( secs_fromnow , 0 ) ,
" disp_info_cache_idle_timeout_handler " ,
disp_info_cache_idle_timeout_handler , ( void * ) disp_info ) ;
2005-11-19 02:15:47 +03:00
}
/*******************************************************************
Force flush any cache . We do this on any samr_set_xxx call .
2005-11-22 23:26:23 +03:00
We must also remove the timeout handler .
2005-11-19 02:15:47 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void force_flush_samr_cache ( DISP_INFO * disp_info )
{
2007-03-11 19:49:16 +03:00
if ( ( disp_info = = NULL ) | | ( disp_info - > cache_timeout_event = = NULL ) ) {
return ;
2005-11-19 02:15:47 +03:00
}
2007-03-11 19:49:16 +03:00
DEBUG ( 10 , ( " force_flush_samr_cache: clearing idle event \n " ) ) ;
TALLOC_FREE ( disp_info - > cache_timeout_event ) ;
free_samr_cache ( disp_info ) ;
2005-11-19 02:15:47 +03:00
}
2001-03-13 03:32:43 +03:00
/*******************************************************************
Ensure password info is never given out . Paranioa . . . JRA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-02-20 23:09:36 +03:00
static void samr_clear_sam_passwd ( struct samu * sam_pass )
2001-03-13 03:32:43 +03:00
{
2008-02-05 14:54:19 +03:00
2001-03-13 03:32:43 +03:00
if ( ! sam_pass )
return ;
2002-01-02 10:41:54 +03:00
/* These now zero out the old password */
2002-11-02 06:47:48 +03:00
pdb_set_lanman_passwd ( sam_pass , NULL , PDB_DEFAULT ) ;
pdb_set_nt_passwd ( sam_pass , NULL , PDB_DEFAULT ) ;
2001-03-13 03:32:43 +03:00
}
2006-02-27 13:32:45 +03:00
static uint32 count_sam_users ( struct disp_info * info , uint32 acct_flags )
2001-12-21 16:36:14 +03:00
{
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entry ;
2005-11-27 04:17:24 +03:00
2007-02-27 02:06:17 +03:00
if ( info - > builtin_domain ) {
2005-11-27 04:17:24 +03:00
/* No users in builtin. */
return 0 ;
}
2005-11-19 02:15:47 +03:00
if ( info - > users = = NULL ) {
2005-04-15 17:41:49 +04:00
info - > users = pdb_search_users ( acct_flags ) ;
2005-11-19 02:15:47 +03:00
if ( info - > users = = NULL ) {
return 0 ;
}
}
2005-04-15 17:41:49 +04:00
/* Fetch the last possible entry, thus trigger an enumeration */
pdb_search_entries ( info - > users , 0xffffffff , 1 , & entry ) ;
2005-11-19 02:15:47 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info , DISP_INFO_CACHE_TIMEOUT ) ;
2005-04-15 17:41:49 +04:00
return info - > users - > num_entries ;
2001-12-21 16:36:14 +03:00
}
2005-04-15 17:41:49 +04:00
static uint32 count_sam_groups ( struct disp_info * info )
2001-12-21 16:36:14 +03:00
{
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entry ;
2005-11-27 04:17:24 +03:00
2007-02-27 02:06:17 +03:00
if ( info - > builtin_domain ) {
2005-11-27 04:17:24 +03:00
/* No groups in builtin. */
return 0 ;
}
2005-11-19 02:15:47 +03:00
if ( info - > groups = = NULL ) {
2005-04-15 17:41:49 +04:00
info - > groups = pdb_search_groups ( ) ;
2005-11-19 02:15:47 +03:00
if ( info - > groups = = NULL ) {
return 0 ;
}
}
2005-04-15 17:41:49 +04:00
/* Fetch the last possible entry, thus trigger an enumeration */
pdb_search_entries ( info - > groups , 0xffffffff , 1 , & entry ) ;
2005-11-19 02:15:47 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info , DISP_INFO_CACHE_TIMEOUT ) ;
2005-04-15 17:41:49 +04:00
return info - > groups - > num_entries ;
2001-12-21 16:36:14 +03:00
}
2005-11-27 04:17:24 +03:00
static uint32 count_sam_aliases ( struct disp_info * info )
{
struct samr_displayentry * entry ;
if ( info - > aliases = = NULL ) {
info - > aliases = pdb_search_aliases ( & info - > sid ) ;
if ( info - > aliases = = NULL ) {
return 0 ;
}
}
/* Fetch the last possible entry, thus trigger an enumeration */
pdb_search_entries ( info - > aliases , 0xffffffff , 1 , & entry ) ;
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info , DISP_INFO_CACHE_TIMEOUT ) ;
return info - > aliases - > num_entries ;
}
2002-07-15 14:35:28 +04:00
/*******************************************************************
2008-01-30 14:53:09 +03:00
_samr_Close
2002-07-15 14:35:28 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-30 14:53:09 +03:00
NTSTATUS _samr_Close ( pipes_struct * p , struct samr_Close * r )
2002-07-15 14:35:28 +04:00
{
2008-01-30 14:53:09 +03:00
if ( ! close_policy_hnd ( p , r - > in . handle ) ) {
return NT_STATUS_INVALID_HANDLE ;
}
2002-07-15 14:35:28 +04:00
2008-01-31 16:24:33 +03:00
ZERO_STRUCTP ( r - > out . handle ) ;
2002-07-15 14:35:28 +04:00
2008-01-30 14:53:09 +03:00
return NT_STATUS_OK ;
2005-01-26 23:36:44 +03:00
}
2002-07-15 14:35:28 +04:00
2005-01-26 23:36:44 +03:00
/*******************************************************************
2008-02-01 02:23:50 +03:00
_samr_OpenDomain
2005-01-26 23:36:44 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
2008-02-01 02:23:50 +03:00
NTSTATUS _samr_OpenDomain ( pipes_struct * p ,
struct samr_OpenDomain * r )
2005-01-26 23:36:44 +03:00
{
struct samr_info * info ;
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-01 02:23:50 +03:00
uint32 des_access = r - > in . access_mask ;
2005-01-26 23:36:44 +03:00
NTSTATUS status ;
2005-09-30 21:13:37 +04:00
size_t sd_size ;
2005-01-26 23:36:44 +03:00
SE_PRIV se_rights ;
2002-07-15 14:35:28 +04:00
2005-01-26 23:36:44 +03:00
/* find the connection policy handle. */
2008-02-05 14:54:19 +03:00
2008-02-01 02:23:50 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . connect_handle , ( void * * ) ( void * ) & info ) )
2005-01-26 23:36:44 +03:00
return NT_STATUS_INVALID_HANDLE ;
2002-07-15 14:35:28 +04:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_SAM_OPEN_DOMAIN ,
" _samr_OpenDomain " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
/*check if access can be granted as requested by client. */
2008-02-05 14:54:19 +03:00
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & dom_generic_mapping , NULL , 0 ) ;
2005-01-26 23:36:44 +03:00
se_map_generic ( & des_access , & dom_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
se_priv_copy ( & se_rights , & se_machine_account ) ;
se_priv_add ( & se_rights , & se_add_users ) ;
2008-02-05 14:54:19 +03:00
status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
& se_rights , GENERIC_RIGHTS_DOMAIN_WRITE , des_access ,
2008-02-01 02:23:50 +03:00
& acc_granted , " _samr_OpenDomain " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2008-02-01 02:23:50 +03:00
if ( ! sid_check_is_domain ( r - > in . sid ) & &
! sid_check_is_builtin ( r - > in . sid ) ) {
2005-11-27 00:35:43 +03:00
return NT_STATUS_NO_SUCH_DOMAIN ;
}
2005-01-26 23:36:44 +03:00
/* associate the domain SID with the (unique) handle. */
2008-02-01 02:23:50 +03:00
if ( ( info = get_samr_info_by_sid ( r - > in . sid ) ) = = NULL )
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2005-01-26 23:36:44 +03:00
info - > acc_granted = acc_granted ;
2001-02-27 21:22:39 +03:00
2005-01-26 23:36:44 +03:00
/* get a (unique) handle. open a policy on it. */
2008-02-01 02:23:50 +03:00
if ( ! create_policy_hnd ( p , r - > out . domain_handle , free_samr_info , ( void * ) info ) )
2005-01-26 23:36:44 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2008-02-01 02:23:50 +03:00
DEBUG ( 5 , ( " _samr_OpenDomain: %d \n " , __LINE__ ) ) ;
2005-01-26 23:36:44 +03:00
2008-02-01 02:23:50 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
2002-07-15 14:35:28 +04:00
/*******************************************************************
2008-02-05 00:53:03 +03:00
_samr_GetUserPwInfo
2002-07-15 14:35:28 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 00:53:03 +03:00
NTSTATUS _samr_GetUserPwInfo ( pipes_struct * p ,
struct samr_GetUserPwInfo * r )
2002-07-15 14:35:28 +04:00
{
2005-01-26 23:36:44 +03:00
struct samr_info * info = NULL ;
2002-07-15 14:35:28 +04:00
2005-01-26 23:36:44 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 00:53:03 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . user_handle , ( void * * ) ( void * ) & info ) )
2005-01-26 23:36:44 +03:00
return NT_STATUS_INVALID_HANDLE ;
2002-07-15 14:35:28 +04:00
2005-01-26 23:36:44 +03:00
if ( ! sid_check_is_in_our_domain ( & info - > sid ) )
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2002-07-15 14:35:28 +04:00
2008-02-05 00:53:03 +03:00
ZERO_STRUCTP ( r - > out . info ) ;
2002-07-15 14:35:28 +04:00
2008-02-05 00:53:03 +03:00
DEBUG ( 5 , ( " _samr_GetUserPwInfo: %d \n " , __LINE__ ) ) ;
2002-07-15 14:35:28 +04:00
2008-02-05 00:53:03 +03:00
/*
2005-01-26 23:36:44 +03:00
* NT sometimes return NT_STATUS_ACCESS_DENIED
* I don ' t know yet why .
*/
2002-07-15 14:35:28 +04:00
2008-02-05 00:53:03 +03:00
return NT_STATUS_OK ;
2005-01-26 23:36:44 +03:00
}
2002-07-15 14:35:28 +04:00
2005-01-26 23:36:44 +03:00
/*******************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 14:54:19 +03:00
static bool get_lsa_policy_samr_sid ( pipes_struct * p , POLICY_HND * pol ,
2005-11-19 02:15:47 +03:00
DOM_SID * sid , uint32 * acc_granted ,
DISP_INFO * * ppdisp_info )
2001-03-11 03:32:10 +03:00
{
struct samr_info * info = NULL ;
/* find the policy handle. open a policy on it. */
2005-12-03 09:46:46 +03:00
if ( ! find_policy_by_hnd ( p , pol , ( void * * ) ( void * ) & info ) )
2001-03-11 03:32:10 +03:00
return False ;
if ( ! info )
return False ;
* sid = info - > sid ;
2002-07-15 14:35:28 +04:00
* acc_granted = info - > acc_granted ;
2005-11-19 02:15:47 +03:00
if ( ppdisp_info ) {
* ppdisp_info = info - > disp_info ;
}
2001-03-11 03:32:10 +03:00
return True ;
}
2006-10-03 21:14:18 +04:00
/*******************************************************************
2008-02-01 19:29:03 +03:00
_samr_SetSecurity
2006-10-03 21:14:18 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 19:29:03 +03:00
NTSTATUS _samr_SetSecurity ( pipes_struct * p ,
struct samr_SetSecurity * r )
2006-10-03 21:14:18 +04:00
{
DOM_SID pol_sid ;
uint32 acc_granted , i ;
SEC_ACL * dacl ;
2007-10-19 04:40:25 +04:00
bool ret ;
2006-10-03 21:14:18 +04:00
struct samu * sampass = NULL ;
NTSTATUS status ;
2008-02-01 19:29:03 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . handle , & pol_sid , & acc_granted , NULL ) )
2006-10-03 21:14:18 +04:00
return NT_STATUS_INVALID_HANDLE ;
if ( ! ( sampass = samu_new ( p - > mem_ctx ) ) ) {
DEBUG ( 0 , ( " No memory! \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
/* get the user record */
become_root ( ) ;
ret = pdb_getsampwsid ( sampass , & pol_sid ) ;
unbecome_root ( ) ;
if ( ! ret ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( & pol_sid ) ) ) ;
2006-10-03 21:14:18 +04:00
TALLOC_FREE ( sampass ) ;
return NT_STATUS_INVALID_HANDLE ;
}
2008-02-01 19:29:03 +03:00
dacl = r - > in . sdbuf - > sd - > dacl ;
2006-10-03 21:14:18 +04:00
for ( i = 0 ; i < dacl - > num_aces ; i + + ) {
if ( sid_equal ( & pol_sid , & dacl - > aces [ i ] . trustee ) ) {
2008-02-05 14:54:19 +03:00
ret = pdb_set_pass_can_change ( sampass ,
( dacl - > aces [ i ] . access_mask &
SA_RIGHT_USER_CHANGE_PASSWORD ) ?
2006-10-03 21:14:18 +04:00
True : False ) ;
break ;
}
}
if ( ! ret ) {
TALLOC_FREE ( sampass ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_USER_SET_ATTRIBUTES ,
" _samr_SetSecurity " ) ;
2007-04-24 22:01:46 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
2007-04-24 19:56:02 +04:00
become_root ( ) ;
status = pdb_update_sam_account ( sampass ) ;
unbecome_root ( ) ;
}
2006-10-03 21:14:18 +04:00
TALLOC_FREE ( sampass ) ;
return status ;
}
/*******************************************************************
build correct perms based on policies and password times for _samr_query_sec_obj
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool check_change_pw_access ( TALLOC_CTX * mem_ctx , DOM_SID * user_sid )
2006-10-03 21:14:18 +04:00
{
struct samu * sampass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2006-10-03 21:14:18 +04:00
if ( ! ( sampass = samu_new ( mem_ctx ) ) ) {
DEBUG ( 0 , ( " No memory! \n " ) ) ;
return False ;
}
become_root ( ) ;
ret = pdb_getsampwsid ( sampass , user_sid ) ;
unbecome_root ( ) ;
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2006-10-03 21:14:18 +04:00
TALLOC_FREE ( sampass ) ;
return False ;
}
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( sampass ) ) ) ;
if ( pdb_get_pass_can_change ( sampass ) ) {
TALLOC_FREE ( sampass ) ;
return True ;
}
TALLOC_FREE ( sampass ) ;
return False ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2008-02-01 19:28:01 +03:00
_samr_QuerySecurity
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 19:28:01 +03:00
NTSTATUS _samr_QuerySecurity ( pipes_struct * p ,
struct samr_QuerySecurity * r )
2001-02-27 21:22:39 +03:00
{
2008-02-01 19:28:01 +03:00
NTSTATUS status ;
2001-02-27 21:22:39 +03:00
DOM_SID pol_sid ;
2002-07-15 14:35:28 +04:00
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2005-02-01 01:42:30 +03:00
size_t sd_size ;
2001-02-27 21:22:39 +03:00
/* Get the SID. */
2008-02-01 19:28:01 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . handle , & pol_sid , & acc_granted , NULL ) )
2001-03-11 03:32:10 +03:00
return NT_STATUS_INVALID_HANDLE ;
2001-02-27 21:22:39 +03:00
2008-02-01 19:28:01 +03:00
DEBUG ( 10 , ( " _samr_QuerySecurity: querying security on SID: %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & pol_sid ) ) ) ;
2001-12-02 03:06:10 +03:00
2002-07-15 14:35:28 +04:00
/* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
/* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
2005-11-19 02:15:47 +03:00
if ( pol_sid . sid_rev_num = = 0 ) {
2008-02-01 19:28:01 +03:00
DEBUG ( 5 , ( " _samr_QuerySecurity: querying security on SAM \n " ) ) ;
status = make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & sam_generic_mapping , NULL , 0 ) ;
2008-02-05 14:54:19 +03:00
} else if ( sid_equal ( & pol_sid , get_global_sam_sid ( ) ) ) {
2005-11-19 02:15:47 +03:00
/* check if it is our domain SID */
2008-02-01 19:28:01 +03:00
DEBUG ( 5 , ( " _samr_QuerySecurity: querying security on Domain "
2007-12-15 23:11:36 +03:00
" with SID: %s \n " , sid_string_dbg ( & pol_sid ) ) ) ;
2008-02-01 19:28:01 +03:00
status = make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & dom_generic_mapping , NULL , 0 ) ;
2005-11-19 02:15:47 +03:00
} else if ( sid_equal ( & pol_sid , & global_sid_Builtin ) ) {
/* check if it is the Builtin Domain */
2002-07-15 14:35:28 +04:00
/* TODO: Builtin probably needs a different SD with restricted write access*/
2008-02-01 19:28:01 +03:00
DEBUG ( 5 , ( " _samr_QuerySecurity: querying security on Builtin "
2007-12-15 23:11:36 +03:00
" Domain with SID: %s \n " , sid_string_dbg ( & pol_sid ) ) ) ;
2008-02-01 19:28:01 +03:00
status = make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & dom_generic_mapping , NULL , 0 ) ;
2005-11-19 02:15:47 +03:00
} else if ( sid_check_is_in_our_domain ( & pol_sid ) | |
sid_check_is_in_builtin ( & pol_sid ) ) {
2002-07-15 14:35:28 +04:00
/* TODO: different SDs have to be generated for aliases groups and users.
Currently all three get a default user SD */
2008-02-01 19:28:01 +03:00
DEBUG ( 10 , ( " _samr_QuerySecurity: querying security on Object "
2007-12-15 23:11:36 +03:00
" with SID: %s \n " , sid_string_dbg ( & pol_sid ) ) ) ;
2006-10-03 21:14:18 +04:00
if ( check_change_pw_access ( p - > mem_ctx , & pol_sid ) ) {
2008-02-01 19:28:01 +03:00
status = make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & usr_generic_mapping ,
2006-10-03 21:14:18 +04:00
& pol_sid , SAMR_USR_RIGHTS_WRITE_PW ) ;
} else {
2008-02-01 19:28:01 +03:00
status = make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & usr_nopwchange_generic_mapping ,
2006-10-03 21:14:18 +04:00
& pol_sid , SAMR_USR_RIGHTS_CANT_WRITE_PW ) ;
}
2005-11-19 02:15:47 +03:00
} else {
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2002-07-15 14:35:28 +04:00
}
2008-02-01 19:28:01 +03:00
if ( ( * r - > out . sdbuf = make_sec_desc_buf ( p - > mem_ctx , sd_size , psd ) ) = = NULL )
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_MEMORY ;
2001-02-27 21:22:39 +03:00
2008-02-01 19:28:01 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
makes a SAM_ENTRY / UNISTR2 * structure from a user list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 05:33:41 +03:00
static NTSTATUS make_user_sam_entry_list ( TALLOC_CTX * ctx ,
struct samr_SamEntry * * sam_pp ,
uint32_t num_entries ,
uint32_t start_idx ,
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entries )
2001-02-27 21:22:39 +03:00
{
2008-02-12 05:33:41 +03:00
uint32_t i ;
struct samr_SamEntry * sam ;
2008-02-05 14:54:19 +03:00
2001-02-27 21:22:39 +03:00
* sam_pp = NULL ;
2008-02-12 05:33:41 +03:00
if ( num_entries = = 0 ) {
2002-07-15 14:35:28 +04:00
return NT_STATUS_OK ;
2008-02-12 05:33:41 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-12 05:33:41 +03:00
sam = TALLOC_ZERO_ARRAY ( ctx , struct samr_SamEntry , num_entries ) ;
if ( sam = = NULL ) {
2007-04-28 03:18:41 +04:00
DEBUG ( 0 , ( " make_user_sam_entry_list: TALLOC_ZERO failed! \n " ) ) ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_MEMORY ;
2001-02-27 21:22:39 +03:00
}
2002-07-15 14:35:28 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2008-02-12 05:33:41 +03:00
#if 0
2004-09-17 02:08:26 +04:00
/*
* usrmgr expects a non - NULL terminated string with
* trust relationships
*/
2005-04-15 17:41:49 +04:00
if ( entries [ i ] . acct_flags & ACB_DOMTRUST ) {
init_unistr2 ( & uni_temp_name , entries [ i ] . account_name ,
UNI_FLAGS_NONE ) ;
2004-09-17 02:08:26 +04:00
} else {
2005-04-15 17:41:49 +04:00
init_unistr2 ( & uni_temp_name , entries [ i ] . account_name ,
UNI_STR_TERMINATE ) ;
2004-09-17 02:08:26 +04:00
}
2008-02-12 05:33:41 +03:00
# endif
init_lsa_String ( & sam [ i ] . name , entries [ i ] . account_name ) ;
sam [ i ] . idx = entries [ i ] . rid ;
2001-02-27 21:22:39 +03:00
}
* sam_pp = sam ;
2008-02-12 05:33:41 +03:00
2002-07-15 14:35:28 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-12 05:33:41 +03:00
_samr_EnumDomainUsers
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 05:33:41 +03:00
NTSTATUS _samr_EnumDomainUsers ( pipes_struct * p ,
struct samr_EnumDomainUsers * r )
2001-02-27 21:22:39 +03:00
{
2008-02-12 05:33:41 +03:00
NTSTATUS status ;
2002-07-15 14:35:28 +04:00
struct samr_info * info = NULL ;
int num_account ;
2008-02-12 05:33:41 +03:00
uint32 enum_context = * r - > in . resume_handle ;
2002-07-15 14:35:28 +04:00
enum remote_arch_types ra_type = get_remote_arch ( ) ;
int max_sam_entries = ( ra_type = = RA_WIN95 ) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K ;
uint32 max_entries = max_sam_entries ;
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entries = NULL ;
2008-02-12 05:33:41 +03:00
struct samr_SamArray * samr_array = NULL ;
struct samr_SamEntry * samr_entries = NULL ;
2001-02-27 21:22:39 +03:00
/* find the policy handle. open a policy on it. */
2008-02-12 05:33:41 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , ( void * * ) ( void * ) & info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-12 12:07:50 +03:00
status = access_check_samr_function ( info - > acc_granted ,
2008-02-12 05:33:41 +03:00
SA_RIGHT_DOMAIN_ENUM_ACCOUNTS ,
" _samr_EnumDomainUsers " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-12 12:07:50 +03:00
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2008-02-12 05:33:41 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainUsers: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2007-02-27 02:06:17 +03:00
if ( info - > builtin_domain ) {
2005-11-27 04:26:52 +03:00
/* No users in builtin. */
2008-02-12 05:33:41 +03:00
* r - > out . resume_handle = * r - > in . resume_handle ;
DEBUG ( 5 , ( " _samr_EnumDomainUsers: No users in BUILTIN \n " ) ) ;
return status ;
}
samr_array = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_SamArray ) ;
if ( ! samr_array ) {
return NT_STATUS_NO_MEMORY ;
2005-11-27 04:26:52 +03:00
}
2001-02-27 21:22:39 +03:00
become_root ( ) ;
2005-11-19 02:15:47 +03:00
/* AS ROOT !!!! */
if ( ( info - > disp_info - > enum_users ! = NULL ) & &
2008-02-12 05:33:41 +03:00
( info - > disp_info - > enum_acb_mask ! = r - > in . acct_flags ) ) {
2005-11-19 02:15:47 +03:00
pdb_search_destroy ( info - > disp_info - > enum_users ) ;
info - > disp_info - > enum_users = NULL ;
2005-06-22 18:16:10 +04:00
}
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > enum_users = = NULL ) {
2008-02-12 05:33:41 +03:00
info - > disp_info - > enum_users = pdb_search_users ( r - > in . acct_flags ) ;
info - > disp_info - > enum_acb_mask = r - > in . acct_flags ;
2005-06-22 18:16:10 +04:00
}
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > enum_users = = NULL ) {
/* END AS ROOT !!!! */
unbecome_root ( ) ;
2005-04-15 17:41:49 +04:00
return NT_STATUS_ACCESS_DENIED ;
2005-11-19 02:15:47 +03:00
}
num_account = pdb_search_entries ( info - > disp_info - > enum_users ,
2005-04-15 17:41:49 +04:00
enum_context , max_entries ,
& entries ) ;
2005-11-19 02:15:47 +03:00
/* END AS ROOT !!!! */
2001-02-27 21:22:39 +03:00
unbecome_root ( ) ;
2002-07-15 14:35:28 +04:00
2005-04-15 17:41:49 +04:00
if ( num_account = = 0 ) {
2008-02-12 05:33:41 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainUsers: enumeration handle over "
2005-04-15 17:41:49 +04:00
" total entries \n " ) ) ;
2008-02-12 05:33:41 +03:00
* r - > out . resume_handle = * r - > in . resume_handle ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_OK ;
}
2008-02-12 05:33:41 +03:00
status = make_user_sam_entry_list ( p - > mem_ctx , & samr_entries ,
num_account , enum_context ,
entries ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2002-07-15 14:35:28 +04:00
2005-11-19 02:15:47 +03:00
if ( max_entries < = num_account ) {
2008-02-12 05:33:41 +03:00
status = STATUS_MORE_ENTRIES ;
2005-11-19 02:15:47 +03:00
} else {
2008-02-12 05:33:41 +03:00
status = NT_STATUS_OK ;
2005-11-19 02:15:47 +03:00
}
2001-02-27 21:22:39 +03:00
2005-11-22 23:26:23 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info - > disp_info , DISP_INFO_CACHE_TIMEOUT ) ;
2008-02-12 05:33:41 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainUsers: %d \n " , __LINE__ ) ) ;
samr_array - > count = num_account ;
samr_array - > entries = samr_entries ;
2002-07-15 14:35:28 +04:00
2008-02-12 05:33:41 +03:00
* r - > out . resume_handle = * r - > in . resume_handle + num_account ;
* r - > out . sam = samr_array ;
* r - > out . num_entries = num_account ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:33:41 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainUsers: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:33:41 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
makes a SAM_ENTRY / UNISTR2 * structure from a group list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 05:15:03 +03:00
static void make_group_sam_entry_list ( TALLOC_CTX * ctx ,
struct samr_SamEntry * * sam_pp ,
uint32_t num_sam_entries ,
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entries )
2001-02-27 21:22:39 +03:00
{
2008-02-12 05:15:03 +03:00
struct samr_SamEntry * sam ;
uint32_t i ;
2001-02-27 21:22:39 +03:00
* sam_pp = NULL ;
2008-02-12 05:15:03 +03:00
if ( num_sam_entries = = 0 ) {
2001-02-27 21:22:39 +03:00
return ;
2008-02-12 05:15:03 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
sam = TALLOC_ZERO_ARRAY ( ctx , struct samr_SamEntry , num_sam_entries ) ;
if ( sam = = NULL ) {
2001-02-27 21:22:39 +03:00
return ;
}
for ( i = 0 ; i < num_sam_entries ; i + + ) {
/*
* JRA . I think this should include the null . TNG does not .
*/
2008-02-12 05:15:03 +03:00
init_lsa_String ( & sam [ i ] . name , entries [ i ] . account_name ) ;
sam [ i ] . idx = entries [ i ] . rid ;
2001-02-27 21:22:39 +03:00
}
* sam_pp = sam ;
}
/*******************************************************************
2008-02-12 05:15:03 +03:00
_samr_EnumDomainGroups
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 05:15:03 +03:00
NTSTATUS _samr_EnumDomainGroups ( pipes_struct * p ,
struct samr_EnumDomainGroups * r )
2001-02-27 21:22:39 +03:00
{
2008-02-12 05:15:03 +03:00
NTSTATUS status ;
2005-04-15 17:41:49 +04:00
struct samr_info * info = NULL ;
struct samr_displayentry * groups ;
uint32 num_groups ;
2008-02-12 05:15:03 +03:00
struct samr_SamArray * samr_array = NULL ;
struct samr_SamEntry * samr_entries = NULL ;
2001-02-27 21:22:39 +03:00
2005-04-15 17:41:49 +04:00
/* find the policy handle. open a policy on it. */
2008-02-12 05:15:03 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , ( void * * ) ( void * ) & info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2005-04-15 17:41:49 +04:00
2008-02-12 05:15:03 +03:00
status = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_DOMAIN_ENUM_ACCOUNTS ,
" _samr_EnumDomainGroups " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainGroups: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2007-02-27 02:06:17 +03:00
if ( info - > builtin_domain ) {
2005-11-27 04:26:52 +03:00
/* No groups in builtin. */
2008-02-12 05:15:03 +03:00
* r - > out . resume_handle = * r - > in . resume_handle ;
DEBUG ( 5 , ( " _samr_EnumDomainGroups: No groups in BUILTIN \n " ) ) ;
return status ;
}
samr_array = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_SamArray ) ;
if ( ! samr_array ) {
return NT_STATUS_NO_MEMORY ;
2005-11-27 04:26:52 +03:00
}
2001-05-04 19:44:27 +04:00
/* the domain group array is being allocated in the function below */
2005-04-10 21:12:25 +04:00
2005-04-15 17:41:49 +04:00
become_root ( ) ;
2001-02-27 21:22:39 +03:00
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > groups = = NULL ) {
info - > disp_info - > groups = pdb_search_groups ( ) ;
2005-04-15 17:41:49 +04:00
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > groups = = NULL ) {
unbecome_root ( ) ;
return NT_STATUS_ACCESS_DENIED ;
}
}
2008-02-12 05:15:03 +03:00
num_groups = pdb_search_entries ( info - > disp_info - > groups ,
* r - > in . resume_handle ,
2005-04-15 17:41:49 +04:00
MAX_SAM_ENTRIES , & groups ) ;
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info - > disp_info , DISP_INFO_CACHE_TIMEOUT ) ;
2008-02-12 05:15:03 +03:00
make_group_sam_entry_list ( p - > mem_ctx , & samr_entries ,
2005-04-15 17:41:49 +04:00
num_groups , groups ) ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
samr_array - > count = num_groups ;
samr_array - > entries = samr_entries ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
* r - > out . sam = samr_array ;
* r - > out . num_entries = num_groups ;
/* this was missing, IMHO:
* r - > out . resume_handle = num_groups + * r - > in . resume_handle ;
*/
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainGroups: %d \n " , __LINE__ ) ) ;
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-12 05:15:03 +03:00
_samr_EnumDomainAliases
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 05:15:03 +03:00
NTSTATUS _samr_EnumDomainAliases ( pipes_struct * p ,
struct samr_EnumDomainAliases * r )
2001-02-27 21:22:39 +03:00
{
2008-02-12 05:15:03 +03:00
NTSTATUS status ;
2005-04-15 17:41:49 +04:00
struct samr_info * info ;
struct samr_displayentry * aliases ;
uint32 num_aliases = 0 ;
2008-02-12 05:15:03 +03:00
struct samr_SamArray * samr_array = NULL ;
struct samr_SamEntry * samr_entries = NULL ;
2001-02-27 21:22:39 +03:00
2005-04-15 17:41:49 +04:00
/* find the policy handle. open a policy on it. */
2008-02-12 05:15:03 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , ( void * * ) ( void * ) & info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-12 05:15:03 +03:00
status = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_DOMAIN_ENUM_ACCOUNTS ,
" _samr_EnumDomainAliases " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainAliases: sid %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & info - > sid ) ) ) ;
2005-04-15 17:41:49 +04:00
2008-02-12 05:15:03 +03:00
samr_array = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_SamArray ) ;
if ( ! samr_array ) {
return NT_STATUS_NO_MEMORY ;
}
2005-04-15 17:41:49 +04:00
become_root ( ) ;
2005-11-27 04:17:24 +03:00
if ( info - > disp_info - > aliases = = NULL ) {
info - > disp_info - > aliases = pdb_search_aliases ( & info - > sid ) ;
if ( info - > disp_info - > aliases = = NULL ) {
2005-11-19 02:15:47 +03:00
unbecome_root ( ) ;
return NT_STATUS_ACCESS_DENIED ;
}
}
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
num_aliases = pdb_search_entries ( info - > disp_info - > aliases ,
* r - > in . resume_handle ,
2005-04-15 17:41:49 +04:00
MAX_SAM_ENTRIES , & aliases ) ;
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info - > disp_info , DISP_INFO_CACHE_TIMEOUT ) ;
2008-02-12 05:15:03 +03:00
make_group_sam_entry_list ( p - > mem_ctx , & samr_entries ,
2005-04-15 17:41:49 +04:00
num_aliases , aliases ) ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
DEBUG ( 5 , ( " _samr_EnumDomainAliases: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
samr_array - > count = num_aliases ;
samr_array - > entries = samr_entries ;
2001-02-27 21:22:39 +03:00
2008-02-12 05:15:03 +03:00
* r - > out . sam = samr_array ;
* r - > out . num_entries = num_aliases ;
* r - > out . resume_handle = num_aliases + * r - > in . resume_handle ;
return status ;
2001-02-27 21:22:39 +03:00
}
2008-02-12 14:16:02 +03:00
/*******************************************************************
inits a structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void init_lsa_AsciiString ( struct lsa_AsciiString * name , const char * s )
{
name - > string = s ;
}
/*******************************************************************
inits a samr_DispInfoGeneral structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS init_samr_dispinfo_1 ( TALLOC_CTX * ctx ,
struct samr_DispInfoGeneral * r ,
uint32_t num_entries ,
uint32_t start_idx ,
struct samr_displayentry * entries )
{
uint32 i ;
DEBUG ( 10 , ( " init_samr_dispinfo_1: num_entries: %d \n " , num_entries ) ) ;
if ( num_entries = = 0 ) {
return NT_STATUS_OK ;
}
r - > count = num_entries ;
r - > entries = TALLOC_ZERO_ARRAY ( ctx , struct samr_DispEntryGeneral , num_entries ) ;
if ( ! r - > entries ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
init_lsa_String ( & r - > entries [ i ] . account_name ,
entries [ i ] . account_name ) ;
init_lsa_String ( & r - > entries [ i ] . description ,
entries [ i ] . description ) ;
init_lsa_String ( & r - > entries [ i ] . full_name ,
entries [ i ] . fullname ) ;
r - > entries [ i ] . rid = entries [ i ] . rid ;
r - > entries [ i ] . acct_flags = entries [ i ] . acct_flags ;
r - > entries [ i ] . idx = start_idx + i + 1 ;
}
return NT_STATUS_OK ;
}
/*******************************************************************
inits a samr_DispInfoFull structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS init_samr_dispinfo_2 ( TALLOC_CTX * ctx ,
struct samr_DispInfoFull * r ,
uint32_t num_entries ,
uint32_t start_idx ,
struct samr_displayentry * entries )
{
uint32_t i ;
DEBUG ( 10 , ( " init_samr_dispinfo_2: num_entries: %d \n " , num_entries ) ) ;
if ( num_entries = = 0 ) {
return NT_STATUS_OK ;
}
r - > count = num_entries ;
r - > entries = TALLOC_ZERO_ARRAY ( ctx , struct samr_DispEntryFull , num_entries ) ;
if ( ! r - > entries ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
init_lsa_String ( & r - > entries [ i ] . account_name ,
entries [ i ] . account_name ) ;
init_lsa_String ( & r - > entries [ i ] . description ,
entries [ i ] . description ) ;
r - > entries [ i ] . rid = entries [ i ] . rid ;
r - > entries [ i ] . acct_flags = entries [ i ] . acct_flags ;
r - > entries [ i ] . idx = start_idx + i + 1 ;
}
return NT_STATUS_OK ;
}
/*******************************************************************
inits a samr_DispInfoFullGroups structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS init_samr_dispinfo_3 ( TALLOC_CTX * ctx ,
struct samr_DispInfoFullGroups * r ,
uint32_t num_entries ,
uint32_t start_idx ,
struct samr_displayentry * entries )
{
uint32_t i ;
DEBUG ( 5 , ( " init_samr_dispinfo_3: num_entries: %d \n " , num_entries ) ) ;
if ( num_entries = = 0 ) {
return NT_STATUS_OK ;
}
r - > count = num_entries ;
r - > entries = TALLOC_ZERO_ARRAY ( ctx , struct samr_DispEntryFullGroup , num_entries ) ;
if ( ! r - > entries ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
init_lsa_String ( & r - > entries [ i ] . account_name ,
entries [ i ] . account_name ) ;
init_lsa_String ( & r - > entries [ i ] . description ,
entries [ i ] . description ) ;
r - > entries [ i ] . rid = entries [ i ] . rid ;
r - > entries [ i ] . acct_flags = entries [ i ] . acct_flags ;
r - > entries [ i ] . idx = start_idx + i + 1 ;
}
return NT_STATUS_OK ;
}
/*******************************************************************
inits a samr_DispInfoAscii structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS init_samr_dispinfo_4 ( TALLOC_CTX * ctx ,
struct samr_DispInfoAscii * r ,
uint32_t num_entries ,
uint32_t start_idx ,
struct samr_displayentry * entries )
{
uint32_t i ;
DEBUG ( 5 , ( " init_samr_dispinfo_4: num_entries: %d \n " , num_entries ) ) ;
if ( num_entries = = 0 ) {
return NT_STATUS_OK ;
}
r - > count = num_entries ;
r - > entries = TALLOC_ZERO_ARRAY ( ctx , struct samr_DispEntryAscii , num_entries ) ;
if ( ! r - > entries ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
init_lsa_AsciiString ( & r - > entries [ i ] . account_name ,
entries [ i ] . account_name ) ;
r - > entries [ i ] . idx = start_idx + i + 1 ;
}
return NT_STATUS_OK ;
}
/*******************************************************************
inits a samr_DispInfoAscii structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS init_samr_dispinfo_5 ( TALLOC_CTX * ctx ,
struct samr_DispInfoAscii * r ,
uint32_t num_entries ,
uint32_t start_idx ,
struct samr_displayentry * entries )
{
uint32_t i ;
DEBUG ( 5 , ( " init_samr_dispinfo_5: num_entries: %d \n " , num_entries ) ) ;
if ( num_entries = = 0 ) {
return NT_STATUS_OK ;
}
r - > count = num_entries ;
r - > entries = TALLOC_ZERO_ARRAY ( ctx , struct samr_DispEntryAscii , num_entries ) ;
if ( ! r - > entries ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
init_lsa_AsciiString ( & r - > entries [ i ] . account_name ,
entries [ i ] . account_name ) ;
r - > entries [ i ] . idx = start_idx + i + 1 ;
}
return NT_STATUS_OK ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2008-02-07 19:57:20 +03:00
_samr_QueryDisplayInfo
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-09 01:58:29 +04:00
2008-02-07 19:57:20 +03:00
NTSTATUS _samr_QueryDisplayInfo ( pipes_struct * p ,
struct samr_QueryDisplayInfo * r )
2001-02-27 21:22:39 +03:00
{
2008-02-07 19:57:20 +03:00
NTSTATUS status ;
2001-12-21 16:36:14 +03:00
struct samr_info * info = NULL ;
2001-12-22 01:34:49 +03:00
uint32 struct_size = 0x20 ; /* W2K always reply that, client doesn't care */
2008-02-05 14:54:19 +03:00
2008-02-07 19:57:20 +03:00
uint32 max_entries = r - > in . max_entries ;
uint32 enum_context = r - > in . start_idx ;
uint32 max_size = r - > in . buf_size ;
union samr_DispInfo * disp_info = r - > out . info ;
2001-12-21 16:36:14 +03:00
uint32 temp_size = 0 , total_data_size = 0 ;
2005-11-02 03:19:26 +03:00
NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL ;
2002-01-02 10:27:33 +03:00
uint32 num_account = 0 ;
enum remote_arch_types ra_type = get_remote_arch ( ) ;
2002-07-15 14:35:28 +04:00
int max_sam_entries = ( ra_type = = RA_WIN95 ) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K ;
2005-04-15 17:41:49 +04:00
struct samr_displayentry * entries = NULL ;
2001-02-27 21:22:39 +03:00
2008-02-07 19:57:20 +03:00
DEBUG ( 5 , ( " _samr_QueryDisplayInfo: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2001-12-21 16:36:14 +03:00
/* find the policy handle. open a policy on it. */
2008-02-07 19:57:20 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , ( void * * ) ( void * ) & info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2001-12-21 16:36:14 +03:00
/*
* calculate how many entries we will return .
2008-02-05 14:54:19 +03:00
* based on
2001-12-21 16:36:14 +03:00
* - the number of entries the client asked
* - our limit on that
* - the starting point ( enumeration context )
* - the buffer size the client will accept
*/
2001-07-09 22:25:40 +04:00
2001-12-21 16:36:14 +03:00
/*
* We are a lot more like W2K . Instead of reading the SAM
* each time to find the records we need to send back ,
* we read it once and link that copy to the sam handle .
* For large user list ( over the MAX_SAM_ENTRIES )
* it ' s a definitive win .
* second point to notice : between enumerations
* our sam is now the same as it ' s a snapshoot .
* third point : got rid of the static SAM_USER_21 struct
* no more intermediate .
* con : it uses much more memory , as a full copy is stored
* in memory .
*
* If you want to change it , think twice and think
* of the second point , that ' s really important .
*
* JFM , 12 / 20 / 2001
*/
2001-02-27 21:22:39 +03:00
2008-02-07 19:57:20 +03:00
if ( ( r - > in . level < 1 ) | | ( r - > in . level > 5 ) ) {
DEBUG ( 0 , ( " _samr_QueryDisplayInfo: Unknown info level (%u) \n " ,
( unsigned int ) r - > in . level ) ) ;
2005-04-15 17:41:49 +04:00
return NT_STATUS_INVALID_INFO_CLASS ;
2001-02-27 21:22:39 +03:00
}
2001-12-21 16:36:14 +03:00
/* first limit the number of entries we will return */
2002-01-02 10:27:33 +03:00
if ( max_entries > max_sam_entries ) {
2008-02-07 19:57:20 +03:00
DEBUG ( 5 , ( " _samr_QueryDisplayInfo: client requested %d "
2005-04-15 17:41:49 +04:00
" entries, limiting to %d \n " , max_entries ,
max_sam_entries ) ) ;
2002-01-02 10:27:33 +03:00
max_entries = max_sam_entries ;
2001-12-21 16:36:14 +03:00
}
2005-04-15 17:41:49 +04:00
/* calculate the size and limit on the number of entries we will
* return */
2001-02-27 21:22:39 +03:00
2002-03-30 00:50:21 +03:00
temp_size = max_entries * struct_size ;
2008-02-05 14:54:19 +03:00
2001-12-22 01:34:49 +03:00
if ( temp_size > max_size ) {
2002-03-30 00:50:21 +03:00
max_entries = MIN ( ( max_size / struct_size ) , max_entries ) ; ;
2008-02-07 19:57:20 +03:00
DEBUG ( 5 , ( " _samr_QueryDisplayInfo: buffer size limits to "
2005-04-15 17:41:49 +04:00
" only %d entries \n " , max_entries ) ) ;
2001-12-21 16:36:14 +03:00
}
2001-02-27 21:22:39 +03:00
2005-04-15 17:41:49 +04:00
become_root ( ) ;
2005-11-19 02:15:47 +03:00
/* THe following done as ROOT. Don't return without unbecome_root(). */
2008-02-07 19:57:20 +03:00
switch ( r - > in . level ) {
2005-04-15 17:41:49 +04:00
case 0x1 :
case 0x4 :
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > users = = NULL ) {
info - > disp_info - > users = pdb_search_users ( ACB_NORMAL ) ;
if ( info - > disp_info - > users = = NULL ) {
unbecome_root ( ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: starting user enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
} else {
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: using cached user enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
}
num_account = pdb_search_entries ( info - > disp_info - > users ,
2005-04-15 17:41:49 +04:00
enum_context , max_entries ,
& entries ) ;
break ;
case 0x2 :
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > machines = = NULL ) {
info - > disp_info - > machines =
2005-04-15 17:41:49 +04:00
pdb_search_users ( ACB_WSTRUST | ACB_SVRTRUST ) ;
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > machines = = NULL ) {
unbecome_root ( ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: starting machine enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
} else {
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: using cached machine enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
}
num_account = pdb_search_entries ( info - > disp_info - > machines ,
2005-04-15 17:41:49 +04:00
enum_context , max_entries ,
& entries ) ;
break ;
case 0x3 :
case 0x5 :
2005-11-19 02:15:47 +03:00
if ( info - > disp_info - > groups = = NULL ) {
info - > disp_info - > groups = pdb_search_groups ( ) ;
if ( info - > disp_info - > groups = = NULL ) {
unbecome_root ( ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: starting group enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
} else {
2008-02-07 19:57:20 +03:00
DEBUG ( 10 , ( " _samr_QueryDisplayInfo: using cached group enumeration at index %u \n " ,
2005-11-19 02:15:47 +03:00
( unsigned int ) enum_context ) ) ;
}
num_account = pdb_search_entries ( info - > disp_info - > groups ,
2005-04-15 17:41:49 +04:00
enum_context , max_entries ,
& entries ) ;
break ;
default :
2005-11-19 02:15:47 +03:00
unbecome_root ( ) ;
2005-04-15 17:41:49 +04:00
smb_panic ( " info class changed " ) ;
break ;
}
unbecome_root ( ) ;
2008-02-07 19:57:20 +03:00
2001-02-27 21:22:39 +03:00
/* Now create reply structure */
2008-02-07 19:57:20 +03:00
switch ( r - > in . level ) {
2001-02-27 21:22:39 +03:00
case 0x1 :
2008-02-12 14:16:02 +03:00
disp_ret = init_samr_dispinfo_1 ( p - > mem_ctx , & disp_info - > info1 ,
num_account , enum_context ,
entries ) ;
2001-02-27 21:22:39 +03:00
break ;
case 0x2 :
2008-02-12 14:16:02 +03:00
disp_ret = init_samr_dispinfo_2 ( p - > mem_ctx , & disp_info - > info2 ,
num_account , enum_context ,
entries ) ;
2001-02-27 21:22:39 +03:00
break ;
case 0x3 :
2008-02-12 14:16:02 +03:00
disp_ret = init_samr_dispinfo_3 ( p - > mem_ctx , & disp_info - > info3 ,
num_account , enum_context ,
entries ) ;
2001-02-27 21:22:39 +03:00
break ;
case 0x4 :
2008-02-12 14:16:02 +03:00
disp_ret = init_samr_dispinfo_4 ( p - > mem_ctx , & disp_info - > info4 ,
num_account , enum_context ,
entries ) ;
2001-02-27 21:22:39 +03:00
break ;
case 0x5 :
2008-02-12 14:16:02 +03:00
disp_ret = init_samr_dispinfo_5 ( p - > mem_ctx , & disp_info - > info5 ,
num_account , enum_context ,
entries ) ;
2001-02-27 21:22:39 +03:00
break ;
default :
2005-04-15 17:41:49 +04:00
smb_panic ( " info class changed " ) ;
break ;
2001-02-27 21:22:39 +03:00
}
2005-04-15 17:41:49 +04:00
if ( ! NT_STATUS_IS_OK ( disp_ret ) )
return disp_ret ;
2001-12-21 16:36:14 +03:00
/* calculate the total size */
2002-01-02 10:27:33 +03:00
total_data_size = num_account * struct_size ;
2001-02-27 21:22:39 +03:00
2005-11-19 02:15:47 +03:00
if ( num_account ) {
2008-02-07 19:57:20 +03:00
status = STATUS_MORE_ENTRIES ;
2005-11-19 02:15:47 +03:00
} else {
2008-02-07 19:57:20 +03:00
status = NT_STATUS_OK ;
2005-11-19 02:15:47 +03:00
}
2001-07-06 02:36:25 +04:00
2005-11-22 23:26:23 +03:00
/* Ensure we cache this enumeration. */
set_disp_info_cache_timeout ( info - > disp_info , DISP_INFO_CACHE_TIMEOUT ) ;
2008-02-07 19:57:20 +03:00
DEBUG ( 5 , ( " _samr_QueryDisplayInfo: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-07 19:57:20 +03:00
* r - > out . total_size = total_data_size ;
* r - > out . returned_size = temp_size ;
2001-12-21 16:36:14 +03:00
2008-02-07 19:57:20 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-07 15:14:40 +03:00
_samr_QueryAliasInfo
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-07 15:14:40 +03:00
NTSTATUS _samr_QueryAliasInfo ( pipes_struct * p ,
struct samr_QueryAliasInfo * r )
2001-02-27 21:22:39 +03:00
{
2002-07-15 14:35:28 +04:00
DOM_SID sid ;
2004-04-07 16:43:44 +04:00
struct acct_info info ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2007-05-11 12:46:54 +04:00
NTSTATUS status ;
2008-02-07 15:14:40 +03:00
union samr_AliasInfo * alias_info = NULL ;
const char * alias_name = NULL ;
const char * alias_description = NULL ;
2001-02-27 21:22:39 +03:00
2008-02-07 15:14:40 +03:00
DEBUG ( 5 , ( " _samr_QueryAliasInfo: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-07 15:14:40 +03:00
alias_info = TALLOC_ZERO_P ( p - > mem_ctx , union samr_AliasInfo ) ;
if ( ! alias_info ) {
return NT_STATUS_NO_MEMORY ;
}
2001-02-27 21:22:39 +03:00
/* find the policy handle. open a policy on it. */
2008-02-07 15:14:40 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & sid , & acc_granted , NULL ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-07 15:14:40 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_ALIAS_LOOKUP_INFO ,
" _samr_QueryAliasInfo " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
2003-12-10 19:40:17 +03:00
become_root ( ) ;
2007-05-11 12:46:54 +04:00
status = pdb_get_aliasinfo ( & sid , & info ) ;
2003-12-10 19:40:17 +03:00
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2007-05-11 12:46:54 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2001-02-27 21:22:39 +03:00
2008-02-07 15:14:40 +03:00
/* FIXME: info contains fstrings */
alias_name = talloc_strdup ( r , info . acct_name ) ;
alias_description = talloc_strdup ( r , info . acct_desc ) ;
2005-05-03 18:01:39 +04:00
2008-02-07 15:14:40 +03:00
switch ( r - > in . level ) {
case ALIASINFOALL :
init_samr_alias_info1 ( & alias_info - > all ,
alias_name ,
1 ,
alias_description ) ;
2001-12-19 03:15:29 +03:00
break ;
2008-02-07 15:14:40 +03:00
case ALIASINFODESCRIPTION :
init_samr_alias_info3 ( & alias_info - > description ,
alias_description ) ;
2001-02-27 21:22:39 +03:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
}
2008-02-07 15:14:40 +03:00
* r - > out . info = alias_info ;
2001-02-27 21:22:39 +03:00
2008-02-07 15:14:40 +03:00
DEBUG ( 5 , ( " _samr_QueryAliasInfo: %d \n " , __LINE__ ) ) ;
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
#if 0
/*******************************************************************
samr_reply_lookup_ids
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint32 _samr_lookup_ids ( pipes_struct * p , SAMR_Q_LOOKUP_IDS * q_u , SAMR_R_LOOKUP_IDS * r_u )
{
uint32 rid [ MAX_SAM_ENTRIES ] ;
int num_rids = q_u - > num_sids1 ;
2001-08-27 23:46:22 +04:00
r_u - > status = NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
DEBUG ( 5 , ( " _samr_lookup_ids: %d \n " , __LINE__ ) ) ;
if ( num_rids > MAX_SAM_ENTRIES ) {
num_rids = MAX_SAM_ENTRIES ;
DEBUG ( 5 , ( " _samr_lookup_ids: truncating entries to %d \n " , num_rids ) ) ;
}
#if 0
int i ;
SMB_ASSERT_ARRAY ( q_u - > uni_user_name , num_rids ) ;
for ( i = 0 ; i < num_rids & & status = = 0 ; i + + )
{
struct sam_passwd * sam_pass ;
fstring user_name ;
fstrcpy ( user_name , unistrn2 ( q_u - > uni_user_name [ i ] . buffer ,
q_u - > uni_user_name [ i ] . uni_str_len ) ) ;
/* find the user account */
become_root ( ) ;
sam_pass = get_smb21pwd_entry ( user_name , 0 ) ;
unbecome_root ( ) ;
if ( sam_pass = = NULL )
{
status = 0xC0000000 | NT_STATUS_NO_SUCH_USER ;
rid [ i ] = 0 ;
}
else
{
rid [ i ] = sam_pass - > user_rid ;
}
}
# endif
num_rids = 1 ;
rid [ 0 ] = BUILTIN_ALIAS_RID_USERS ;
2001-08-27 23:46:22 +04:00
init_samr_r_lookup_ids ( & r_u , num_rids , rid , NT_STATUS_OK ) ;
2001-02-27 21:22:39 +03:00
DEBUG ( 5 , ( " _samr_lookup_ids: %d \n " , __LINE__ ) ) ;
return r_u - > status ;
}
# endif
/*******************************************************************
2008-02-08 15:29:01 +03:00
_samr_LookupNames
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-08 15:29:01 +03:00
NTSTATUS _samr_LookupNames ( pipes_struct * p ,
struct samr_LookupNames * r )
2001-02-27 21:22:39 +03:00
{
2008-02-08 15:29:01 +03:00
NTSTATUS status ;
2001-12-02 03:06:10 +03:00
uint32 rid [ MAX_SAM_ENTRIES ] ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType type [ MAX_SAM_ENTRIES ] ;
2001-12-02 03:06:10 +03:00
int i ;
2008-02-08 15:29:01 +03:00
int num_rids = r - > in . num_names ;
2001-12-02 03:06:10 +03:00
DOM_SID pol_sid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2008-02-08 15:29:01 +03:00
struct samr_Ids rids , types ;
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
DEBUG ( 5 , ( " _samr_LookupNames: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2001-12-02 03:06:10 +03:00
ZERO_ARRAY ( rid ) ;
ZERO_ARRAY ( type ) ;
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & pol_sid , & acc_granted , NULL ) ) {
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2001-12-02 03:06:10 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-08 15:29:01 +03:00
status = access_check_samr_function ( acc_granted ,
0 , /* Don't know the acc_bits yet */
" _samr_LookupNames " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
2001-12-02 03:06:10 +03:00
if ( num_rids > MAX_SAM_ENTRIES ) {
num_rids = MAX_SAM_ENTRIES ;
2008-02-08 15:29:01 +03:00
DEBUG ( 5 , ( " _samr_LookupNames: truncating entries to %d \n " , num_rids ) ) ;
2001-12-02 03:06:10 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
DEBUG ( 5 , ( " _samr_LookupNames: looking name on SID %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & pol_sid ) ) ) ;
2008-02-05 14:54:19 +03:00
2001-12-02 03:06:10 +03:00
for ( i = 0 ; i < num_rids ; i + + ) {
2008-02-08 15:29:01 +03:00
status = NT_STATUS_NONE_MAPPED ;
2005-12-03 21:34:13 +03:00
type [ i ] = SID_NAME_UNKNOWN ;
2001-12-02 03:06:10 +03:00
2008-02-08 15:29:01 +03:00
rid [ i ] = 0xffffffff ;
2005-12-03 21:34:13 +03:00
if ( sid_check_is_builtin ( & pol_sid ) ) {
2008-02-08 15:29:01 +03:00
if ( lookup_builtin_name ( r - > in . names [ i ] . string ,
& rid [ i ] ) )
{
2005-12-03 21:34:13 +03:00
type [ i ] = SID_NAME_ALIAS ;
2001-12-02 03:06:10 +03:00
}
2005-12-03 21:34:13 +03:00
} else {
2008-02-08 15:29:01 +03:00
lookup_global_sam_name ( r - > in . names [ i ] . string , 0 ,
& rid [ i ] , & type [ i ] ) ;
2005-12-03 21:34:13 +03:00
}
if ( type [ i ] ! = SID_NAME_UNKNOWN ) {
2008-02-08 15:29:01 +03:00
status = NT_STATUS_OK ;
2005-12-03 21:34:13 +03:00
}
2001-12-02 03:06:10 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
rids . count = num_rids ;
rids . ids = rid ;
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
types . count = num_rids ;
types . ids = type ;
2001-02-27 21:22:39 +03:00
2008-02-08 15:29:01 +03:00
* r - > out . rids = rids ;
* r - > out . types = types ;
DEBUG ( 5 , ( " _samr_LookupNames: %d \n " , __LINE__ ) ) ;
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-02 01:06:43 +03:00
_samr_ChangePasswordUser2
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-08 21:42:23 +03:00
2008-02-02 01:06:43 +03:00
NTSTATUS _samr_ChangePasswordUser2 ( pipes_struct * p ,
struct samr_ChangePasswordUser2 * r )
2001-02-27 21:22:39 +03:00
{
2008-02-02 01:06:43 +03:00
NTSTATUS status ;
2003-07-31 05:33:44 +04:00
fstring user_name ;
fstring wks ;
2001-02-27 21:22:39 +03:00
2008-02-02 01:06:43 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser2: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-02 01:06:43 +03:00
fstrcpy ( user_name , r - > in . account - > string ) ;
fstrcpy ( wks , r - > in . server - > string ) ;
2001-02-27 21:22:39 +03:00
2008-02-02 01:06:43 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser2: user: %s wks: %s \n " , user_name , wks ) ) ;
2001-02-27 21:22:39 +03:00
2001-04-16 02:29:36 +04:00
/*
* Pass the user through the NT - > unix user mapping
* function .
*/
2008-02-05 14:54:19 +03:00
2001-04-16 02:29:36 +04:00
( void ) map_username ( user_name ) ;
2008-02-05 14:54:19 +03:00
2001-04-16 02:29:36 +04:00
/*
2008-02-05 14:54:19 +03:00
* UNIX username case mangling not required , pass_oem_change
2002-01-17 11:45:58 +03:00
* is case insensitive .
2001-04-16 02:29:36 +04:00
*/
2008-02-08 21:42:23 +03:00
status = pass_oem_change ( user_name ,
r - > in . lm_password - > data ,
r - > in . lm_verifier - > hash ,
r - > in . nt_password - > data ,
r - > in . nt_verifier - > hash ,
NULL ) ;
2001-02-27 21:22:39 +03:00
2008-02-02 01:06:43 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser2: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-02 01:06:43 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
2006-02-11 02:09:00 +03:00
/*******************************************************************
2008-02-05 20:44:30 +03:00
_samr_ChangePasswordUser3
2006-02-11 02:09:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 20:44:30 +03:00
NTSTATUS _samr_ChangePasswordUser3 ( pipes_struct * p ,
struct samr_ChangePasswordUser3 * r )
2006-02-11 02:09:00 +03:00
{
2008-02-05 20:44:30 +03:00
NTSTATUS status ;
2006-02-11 02:09:00 +03:00
fstring user_name ;
2008-02-05 20:44:30 +03:00
const char * wks = NULL ;
2006-02-11 02:09:00 +03:00
uint32 reject_reason ;
2008-02-05 20:44:30 +03:00
struct samr_DomInfo1 * dominfo = NULL ;
struct samr_ChangeReject * reject = NULL ;
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser3: %d \n " , __LINE__ ) ) ;
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
fstrcpy ( user_name , r - > in . account - > string ) ;
if ( r - > in . server & & r - > in . server - > string ) {
wks = r - > in . server - > string ;
}
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser3: user: %s wks: %s \n " , user_name , wks ) ) ;
2006-02-11 02:09:00 +03:00
/*
* Pass the user through the NT - > unix user mapping
* function .
*/
2008-02-05 14:54:19 +03:00
2006-02-11 02:09:00 +03:00
( void ) map_username ( user_name ) ;
2008-02-05 14:54:19 +03:00
2006-02-11 02:09:00 +03:00
/*
2008-02-05 14:54:19 +03:00
* UNIX username case mangling not required , pass_oem_change
2006-02-11 02:09:00 +03:00
* is case insensitive .
*/
2008-02-05 20:44:30 +03:00
status = pass_oem_change ( user_name ,
r - > in . lm_password - > data ,
r - > in . lm_verifier - > hash ,
r - > in . nt_password - > data ,
r - > in . nt_verifier - > hash ,
& reject_reason ) ;
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_PASSWORD_RESTRICTION ) | |
NT_STATUS_EQUAL ( status , NT_STATUS_ACCOUNT_RESTRICTION ) ) {
2006-02-11 02:09:00 +03:00
uint32 min_pass_len , pass_hist , password_properties ;
time_t u_expire , u_min_age ;
NTTIME nt_expire , nt_min_age ;
uint32 account_policy_temp ;
2008-02-05 20:44:30 +03:00
dominfo = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_DomInfo1 ) ;
if ( ! dominfo ) {
2006-02-11 02:09:00 +03:00
return NT_STATUS_NO_MEMORY ;
}
2008-02-05 20:44:30 +03:00
reject = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_ChangeReject ) ;
if ( ! reject ) {
2006-02-11 02:09:00 +03:00
return NT_STATUS_NO_MEMORY ;
}
become_root ( ) ;
/* AS ROOT !!! */
pdb_get_account_policy ( AP_MIN_PASSWORD_LEN , & account_policy_temp ) ;
min_pass_len = account_policy_temp ;
pdb_get_account_policy ( AP_PASSWORD_HISTORY , & account_policy_temp ) ;
pass_hist = account_policy_temp ;
pdb_get_account_policy ( AP_USER_MUST_LOGON_TO_CHG_PASS , & account_policy_temp ) ;
password_properties = account_policy_temp ;
pdb_get_account_policy ( AP_MAX_PASSWORD_AGE , & account_policy_temp ) ;
u_expire = account_policy_temp ;
pdb_get_account_policy ( AP_MIN_PASSWORD_AGE , & account_policy_temp ) ;
u_min_age = account_policy_temp ;
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2006-02-11 02:09:00 +03:00
unbecome_root ( ) ;
unix_to_nt_time_abs ( & nt_expire , u_expire ) ;
unix_to_nt_time_abs ( & nt_min_age , u_min_age ) ;
2008-02-05 20:44:30 +03:00
if ( lp_check_password_script ( ) & & * lp_check_password_script ( ) ) {
password_properties | = DOMAIN_PASSWORD_COMPLEX ;
}
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
init_samr_DomInfo1 ( dominfo ,
min_pass_len ,
pass_hist ,
password_properties ,
u_expire ,
u_min_age ) ;
2008-02-05 14:54:19 +03:00
2008-02-05 20:44:30 +03:00
reject - > reason = reject_reason ;
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
* r - > out . dominfo = dominfo ;
* r - > out . reject = reject ;
}
2006-02-11 02:09:00 +03:00
2008-02-05 20:44:30 +03:00
DEBUG ( 5 , ( " _samr_ChangePasswordUser3: %d \n " , __LINE__ ) ) ;
return status ;
2006-02-11 02:09:00 +03:00
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
makes a SAMR_R_LOOKUP_RIDS structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool make_samr_lookup_rids ( TALLOC_CTX * ctx , uint32 num_names ,
2008-02-06 23:29:17 +03:00
const char * * names ,
struct lsa_String * * lsa_name_array_p )
2001-02-27 21:22:39 +03:00
{
2008-02-06 23:29:17 +03:00
struct lsa_String * lsa_name_array = NULL ;
uint32_t i ;
2001-02-27 21:22:39 +03:00
2008-02-06 23:29:17 +03:00
* lsa_name_array_p = NULL ;
2001-02-27 21:22:39 +03:00
if ( num_names ! = 0 ) {
2008-02-06 23:29:17 +03:00
lsa_name_array = TALLOC_ZERO_ARRAY ( ctx , struct lsa_String , num_names ) ;
if ( ! lsa_name_array ) {
return false ;
}
2001-02-27 21:22:39 +03:00
}
for ( i = 0 ; i < num_names ; i + + ) {
2005-08-05 08:48:02 +04:00
DEBUG ( 10 , ( " names[%d]:%s \n " , i , names [ i ] & & * names [ i ] ? names [ i ] : " " ) ) ;
2008-02-06 23:29:17 +03:00
init_lsa_String ( & lsa_name_array [ i ] , names [ i ] ) ;
2001-02-27 21:22:39 +03:00
}
2008-02-06 23:29:17 +03:00
* lsa_name_array_p = lsa_name_array ;
2001-02-27 21:22:39 +03:00
2008-02-06 23:29:17 +03:00
return true ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-06 23:29:17 +03:00
_samr_LookupRids
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-06 23:29:17 +03:00
NTSTATUS _samr_LookupRids ( pipes_struct * p ,
struct samr_LookupRids * r )
2001-02-27 21:22:39 +03:00
{
2008-02-06 23:29:17 +03:00
NTSTATUS status ;
2005-03-22 23:50:29 +03:00
const char * * names ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType * attrs = NULL ;
2006-06-29 21:03:19 +04:00
uint32 * wire_attrs = NULL ;
2001-02-27 21:22:39 +03:00
DOM_SID pol_sid ;
2008-02-06 23:29:17 +03:00
int num_rids = ( int ) r - > in . num_rids ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2006-06-29 21:03:19 +04:00
int i ;
2008-02-06 23:29:17 +03:00
struct lsa_Strings names_array ;
struct samr_Ids types_array ;
struct lsa_String * lsa_names = NULL ;
2006-06-29 21:03:19 +04:00
2008-02-06 23:29:17 +03:00
DEBUG ( 5 , ( " _samr_LookupRids: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
/* find the policy handle. open a policy on it. */
2008-02-06 23:29:17 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & pol_sid , & acc_granted , NULL ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2005-02-20 18:15:33 +03:00
if ( num_rids > 1000 ) {
DEBUG ( 0 , ( " Got asked for %d rids (more than 1000) -- according "
" to samba4 idl this is not possible \n " , num_rids ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
2001-02-27 21:22:39 +03:00
}
2007-04-30 04:53:17 +04:00
if ( num_rids ) {
names = TALLOC_ZERO_ARRAY ( p - > mem_ctx , const char * , num_rids ) ;
attrs = TALLOC_ZERO_ARRAY ( p - > mem_ctx , enum lsa_SidType , num_rids ) ;
wire_attrs = TALLOC_ZERO_ARRAY ( p - > mem_ctx , uint32 , num_rids ) ;
2005-03-22 23:50:29 +03:00
2007-04-30 04:53:17 +04:00
if ( ( names = = NULL ) | | ( attrs = = NULL ) | | ( wire_attrs = = NULL ) )
return NT_STATUS_NO_MEMORY ;
} else {
names = NULL ;
attrs = NULL ;
wire_attrs = NULL ;
}
2005-03-22 23:50:29 +03:00
2002-01-26 13:03:25 +03:00
become_root ( ) ; /* lookup_sid can require root privs */
2008-02-06 23:29:17 +03:00
status = pdb_lookup_rids ( & pol_sid , num_rids , r - > in . rids ,
names , attrs ) ;
2002-01-26 13:03:25 +03:00
unbecome_root ( ) ;
2008-02-06 23:29:17 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NONE_MAPPED ) & & ( num_rids = = 0 ) ) {
status = NT_STATUS_OK ;
2006-03-15 03:10:38 +03:00
}
2008-02-06 23:29:17 +03:00
if ( ! make_samr_lookup_rids ( p - > mem_ctx , num_rids , names ,
& lsa_names ) ) {
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2008-02-06 23:29:17 +03:00
}
2001-02-27 21:22:39 +03:00
2006-09-08 18:28:06 +04:00
/* Convert from enum lsa_SidType to uint32 for wire format. */
2006-06-29 21:03:19 +04:00
for ( i = 0 ; i < num_rids ; i + + ) {
wire_attrs [ i ] = ( uint32 ) attrs [ i ] ;
}
2008-02-06 23:29:17 +03:00
names_array . count = num_rids ;
names_array . names = lsa_names ;
2001-02-27 21:22:39 +03:00
2008-02-06 23:29:17 +03:00
types_array . count = num_rids ;
types_array . ids = wire_attrs ;
2001-02-27 21:22:39 +03:00
2008-02-06 23:29:17 +03:00
* r - > out . names = names_array ;
* r - > out . types = types_array ;
DEBUG ( 5 , ( " _samr_LookupRids: %d \n " , __LINE__ ) ) ;
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-01 02:39:06 +03:00
_samr_OpenUser
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-02-27 21:22:39 +03:00
2008-02-01 02:39:06 +03:00
NTSTATUS _samr_OpenUser ( pipes_struct * p ,
struct samr_OpenUser * r )
2001-02-27 21:22:39 +03:00
{
2006-02-20 23:09:36 +03:00
struct samu * sampass = NULL ;
2001-05-04 19:44:27 +04:00
DOM_SID sid ;
2008-02-01 02:39:06 +03:00
POLICY_HND domain_pol = * r - > in . domain_handle ;
POLICY_HND * user_pol = r - > out . user_handle ;
2001-03-11 03:32:10 +03:00
struct samr_info * info = NULL ;
2002-07-15 14:35:28 +04:00
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-01 02:39:06 +03:00
uint32 des_access = r - > in . access_mask ;
2002-07-15 14:35:28 +04:00
size_t sd_size ;
2007-10-19 04:40:25 +04:00
bool ret ;
2002-07-15 14:35:28 +04:00
NTSTATUS nt_status ;
2005-01-26 23:36:44 +03:00
SE_PRIV se_rights ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* find the domain policy handle and get domain SID / access bits in the domain policy. */
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
if ( ! get_lsa_policy_samr_sid ( p , & domain_pol , & sid , & acc_granted , NULL ) )
2001-05-04 19:44:27 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
nt_status = access_check_samr_function ( acc_granted ,
SA_RIGHT_DOMAIN_OPEN_ACCOUNT ,
" _samr_OpenUser " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2002-07-15 14:35:28 +04:00
return nt_status ;
2006-02-21 17:34:11 +03:00
if ( ! ( sampass = samu_new ( p - > mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* append the user's RID to it */
2008-02-05 14:54:19 +03:00
2008-02-01 02:39:06 +03:00
if ( ! sid_append_rid ( & sid , r - > in . rid ) )
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_SUCH_USER ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
/* check if access can be granted as requested by client. */
2008-02-05 14:54:19 +03:00
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & usr_generic_mapping , & sid , SAMR_USR_RIGHTS_WRITE_PW ) ;
2002-07-15 14:35:28 +04:00
se_map_generic ( & des_access , & usr_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
se_priv_copy ( & se_rights , & se_machine_account ) ;
se_priv_add ( & se_rights , & se_add_users ) ;
2008-02-05 14:54:19 +03:00
nt_status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
& se_rights , GENERIC_RIGHTS_USER_WRITE , des_access ,
2008-02-01 02:39:06 +03:00
& acc_granted , " _samr_OpenUser " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2002-07-15 14:35:28 +04:00
return nt_status ;
2001-05-08 20:33:18 +04:00
2001-05-04 19:44:27 +04:00
become_root ( ) ;
2002-07-15 14:35:28 +04:00
ret = pdb_getsampwsid ( sampass , & sid ) ;
2001-05-04 19:44:27 +04:00
unbecome_root ( ) ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* check that the SID exists in our domain. */
2001-05-04 19:44:27 +04:00
if ( ret = = False ) {
return NT_STATUS_NO_SUCH_USER ;
}
2001-02-27 21:22:39 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sampass ) ;
2001-03-13 03:32:43 +03:00
2002-07-15 14:35:28 +04:00
/* associate the user's SID and access bits with the new handle. */
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & sid ) ) = = NULL )
2001-05-04 19:44:27 +04:00
return NT_STATUS_NO_MEMORY ;
2002-07-15 14:35:28 +04:00
info - > acc_granted = acc_granted ;
2001-03-11 03:32:10 +03:00
2001-05-04 19:44:27 +04:00
/* get a (unique) handle. open a policy on it. */
if ( ! create_policy_hnd ( p , user_pol , free_samr_info , ( void * ) info ) )
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2001-02-27 21:22:39 +03:00
2008-02-01 02:39:06 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
2005-01-22 14:26:13 +03:00
/*************************************************************************
get_user_info_7 . Safe . Only gives out account_name .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS get_user_info_7 ( TALLOC_CTX * mem_ctx , SAM_USER_INFO_7 * id7 , DOM_SID * user_sid )
{
2006-02-20 23:09:36 +03:00
struct samu * smbpass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2005-01-22 14:26:13 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( smbpass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
2005-01-22 14:26:13 +03:00
}
2008-02-05 14:54:19 +03:00
2005-01-22 14:26:13 +03:00
become_root ( ) ;
ret = pdb_getsampwsid ( smbpass , user_sid ) ;
unbecome_root ( ) ;
2006-02-21 17:34:11 +03:00
if ( ! ret ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2005-01-22 14:26:13 +03:00
return NT_STATUS_NO_SUCH_USER ;
}
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( smbpass ) ) ) ;
ZERO_STRUCTP ( id7 ) ;
init_sam_user_info7 ( id7 , pdb_get_username ( smbpass ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2005-01-22 14:26:13 +03:00
return NT_STATUS_OK ;
}
2006-01-14 15:37:25 +03:00
/*************************************************************************
get_user_info_9 . Only gives out primary group SID .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS get_user_info_9 ( TALLOC_CTX * mem_ctx , SAM_USER_INFO_9 * id9 , DOM_SID * user_sid )
{
2006-02-20 23:09:36 +03:00
struct samu * smbpass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2006-01-14 15:37:25 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( smbpass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
2006-01-14 15:37:25 +03:00
}
become_root ( ) ;
ret = pdb_getsampwsid ( smbpass , user_sid ) ;
unbecome_root ( ) ;
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2006-01-14 15:37:25 +03:00
return NT_STATUS_NO_SUCH_USER ;
}
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( smbpass ) ) ) ;
ZERO_STRUCTP ( id9 ) ;
init_sam_user_info9 ( id9 , pdb_get_group_rid ( smbpass ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2006-01-14 15:37:25 +03:00
return NT_STATUS_OK ;
}
2001-02-27 21:22:39 +03:00
/*************************************************************************
2005-07-19 04:59:25 +04:00
get_user_info_16 . Safe . Only gives out acb bits .
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-07-19 04:59:25 +04:00
static NTSTATUS get_user_info_16 ( TALLOC_CTX * mem_ctx , SAM_USER_INFO_16 * id16 , DOM_SID * user_sid )
2001-02-27 21:22:39 +03:00
{
2006-02-20 23:09:36 +03:00
struct samu * smbpass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-02-27 21:22:39 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( smbpass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
2001-05-04 19:44:27 +04:00
become_root ( ) ;
2002-07-15 14:35:28 +04:00
ret = pdb_getsampwsid ( smbpass , user_sid ) ;
2001-05-04 19:44:27 +04:00
unbecome_root ( ) ;
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_SUCH_USER ;
2001-05-04 19:44:27 +04:00
}
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( smbpass ) ) ) ;
2001-02-27 21:22:39 +03:00
2005-07-19 04:59:25 +04:00
ZERO_STRUCTP ( id16 ) ;
init_sam_user_info16 ( id16 , pdb_get_acct_ctrl ( smbpass ) ) ;
2001-02-27 21:22:39 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*************************************************************************
2005-07-19 04:59:25 +04:00
get_user_info_18 . OK - this is the killer as it gives out password info .
2001-03-13 03:32:43 +03:00
Ensure that this is only allowed on an encrypted connection with a root
2008-02-05 14:54:19 +03:00
user . JRA .
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-07-19 04:59:25 +04:00
static NTSTATUS get_user_info_18 ( pipes_struct * p , TALLOC_CTX * mem_ctx , SAM_USER_INFO_18 * id18 , DOM_SID * user_sid )
2001-02-27 21:22:39 +03:00
{
2006-02-20 23:09:36 +03:00
struct samu * smbpass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-02-27 21:22:39 +03:00
2005-09-30 21:13:37 +04:00
if ( p - > auth . auth_type ! = PIPE_AUTH_TYPE_NTLMSSP | | p - > auth . auth_type ! = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ) {
2001-03-13 03:32:43 +03:00
return NT_STATUS_ACCESS_DENIED ;
2005-09-30 21:13:37 +04:00
}
2001-03-13 03:32:43 +03:00
2005-09-30 21:13:37 +04:00
if ( p - > auth . auth_level ! = PIPE_AUTH_LEVEL_PRIVACY ) {
2001-03-13 03:32:43 +03:00
return NT_STATUS_ACCESS_DENIED ;
2005-09-30 21:13:37 +04:00
}
2001-03-13 03:32:43 +03:00
/*
* Do * NOT * do become_root ( ) / unbecome_root ( ) here ! JRA .
*/
2006-02-21 17:34:11 +03:00
if ( ! ( smbpass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
2002-07-15 14:35:28 +04:00
}
ret = pdb_getsampwsid ( smbpass , user_sid ) ;
2001-02-27 21:22:39 +03:00
2001-05-04 19:44:27 +04:00
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2001-03-13 03:32:43 +03:00
return ( geteuid ( ) = = ( uid_t ) 0 ) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED ;
2001-02-27 21:22:39 +03:00
}
2001-05-04 19:44:27 +04:00
DEBUG ( 3 , ( " User:[%s] 0x%x \n " , pdb_get_username ( smbpass ) , pdb_get_acct_ctrl ( smbpass ) ) ) ;
2001-02-27 21:22:39 +03:00
2001-05-04 19:44:27 +04:00
if ( pdb_get_acct_ctrl ( smbpass ) & ACB_DISABLED ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2001-05-04 19:44:27 +04:00
return NT_STATUS_ACCOUNT_DISABLED ;
}
2001-02-27 21:22:39 +03:00
2005-07-19 04:59:25 +04:00
ZERO_STRUCTP ( id18 ) ;
init_sam_user_info18 ( id18 , pdb_get_lanman_passwd ( smbpass ) , pdb_get_nt_passwd ( smbpass ) ) ;
2008-02-05 14:54:19 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( smbpass ) ;
2001-02-27 21:22:39 +03:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
2001-07-09 22:25:40 +04:00
/*************************************************************************
get_user_info_20
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-07-15 14:35:28 +04:00
static NTSTATUS get_user_info_20 ( TALLOC_CTX * mem_ctx , SAM_USER_INFO_20 * id20 , DOM_SID * user_sid )
2001-07-09 22:25:40 +04:00
{
2006-02-20 23:09:36 +03:00
struct samu * sampass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-07-09 22:25:40 +04:00
2006-02-21 17:34:11 +03:00
if ( ! ( sampass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2001-07-09 22:25:40 +04:00
become_root ( ) ;
2002-07-15 14:35:28 +04:00
ret = pdb_getsampwsid ( sampass , user_sid ) ;
2001-07-09 22:25:40 +04:00
unbecome_root ( ) ;
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_SUCH_USER ;
2001-07-09 22:25:40 +04:00
}
samr_clear_sam_passwd ( sampass ) ;
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( sampass ) ) ) ;
ZERO_STRUCTP ( id20 ) ;
init_sam_user_info20A ( id20 , sampass ) ;
2008-02-05 14:54:19 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sampass ) ;
2001-07-09 22:25:40 +04:00
2002-07-15 14:35:28 +04:00
return NT_STATUS_OK ;
2001-07-09 22:25:40 +04:00
}
2001-02-27 21:22:39 +03:00
/*************************************************************************
get_user_info_21
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 14:54:19 +03:00
static NTSTATUS get_user_info_21 ( TALLOC_CTX * mem_ctx , SAM_USER_INFO_21 * id21 ,
2002-07-15 14:35:28 +04:00
DOM_SID * user_sid , DOM_SID * domain_sid )
2001-02-27 21:22:39 +03:00
{
2006-02-20 23:09:36 +03:00
struct samu * sampass = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2002-07-15 14:35:28 +04:00
NTSTATUS nt_status ;
2001-02-27 21:22:39 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( sampass = samu_new ( mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
2002-07-15 14:35:28 +04:00
}
2001-05-08 20:33:18 +04:00
2001-05-04 19:44:27 +04:00
become_root ( ) ;
2002-07-15 14:35:28 +04:00
ret = pdb_getsampwsid ( sampass , user_sid ) ;
2001-05-04 19:44:27 +04:00
unbecome_root ( ) ;
2001-02-27 21:22:39 +03:00
2001-05-04 19:44:27 +04:00
if ( ret = = False ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 4 , ( " User %s not found \n " , sid_string_dbg ( user_sid ) ) ) ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_SUCH_USER ;
2001-05-04 19:44:27 +04:00
}
2001-02-27 21:22:39 +03:00
2001-03-13 03:32:43 +03:00
samr_clear_sam_passwd ( sampass ) ;
2001-05-04 19:44:27 +04:00
DEBUG ( 3 , ( " User:[%s] \n " , pdb_get_username ( sampass ) ) ) ;
2001-03-11 03:32:10 +03:00
2001-07-09 22:25:40 +04:00
ZERO_STRUCTP ( id21 ) ;
2002-07-15 14:35:28 +04:00
nt_status = init_sam_user_info21A ( id21 , sampass , domain_sid ) ;
2008-02-05 14:54:19 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sampass ) ;
2001-02-27 21:22:39 +03:00
2006-06-27 04:49:14 +04:00
return nt_status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
_samr_query_userinfo
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-27 23:46:22 +04:00
NTSTATUS _samr_query_userinfo ( pipes_struct * p , SAMR_Q_QUERY_USERINFO * q_u , SAMR_R_QUERY_USERINFO * r_u )
2001-02-27 21:22:39 +03:00
{
SAM_USERINFO_CTR * ctr ;
2001-03-11 03:32:10 +03:00
struct samr_info * info = NULL ;
2002-07-15 14:35:28 +04:00
DOM_SID domain_sid ;
uint32 rid ;
2008-02-05 14:54:19 +03:00
2001-08-27 23:46:22 +04:00
r_u - > status = NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
/* search for the handle */
2005-12-03 09:46:46 +03:00
if ( ! find_policy_by_hnd ( p , & q_u - > pol , ( void * * ) ( void * ) & info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2002-07-15 14:35:28 +04:00
domain_sid = info - > sid ;
sid_split_rid ( & domain_sid , & rid ) ;
2001-12-05 00:53:47 +03:00
if ( ! sid_check_is_in_our_domain ( & info - > sid ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2007-12-15 23:11:36 +03:00
DEBUG ( 5 , ( " _samr_query_userinfo: sid:%s \n " ,
sid_string_dbg ( & info - > sid ) ) ) ;
2001-02-27 21:22:39 +03:00
2004-12-07 21:25:53 +03:00
ctr = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USERINFO_CTR ) ;
2001-02-27 21:22:39 +03:00
if ( ! ctr )
return NT_STATUS_NO_MEMORY ;
ZERO_STRUCTP ( ctr ) ;
/* ok! user info levels (lots: see MSDEV help), off we go... */
ctr - > switch_value = q_u - > switch_value ;
2006-01-14 15:37:25 +03:00
DEBUG ( 5 , ( " _samr_query_userinfo: user info level: %d \n " , q_u - > switch_value ) ) ;
2001-02-27 21:22:39 +03:00
switch ( q_u - > switch_value ) {
2005-07-19 04:59:25 +04:00
case 7 :
2005-01-22 14:26:13 +03:00
ctr - > info . id7 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_7 ) ;
if ( ctr - > info . id7 = = NULL )
return NT_STATUS_NO_MEMORY ;
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_7 ( p - > mem_ctx , ctr - > info . id7 , & info - > sid ) ) )
return r_u - > status ;
break ;
2006-01-14 15:37:25 +03:00
case 9 :
ctr - > info . id9 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_9 ) ;
if ( ctr - > info . id9 = = NULL )
return NT_STATUS_NO_MEMORY ;
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_9 ( p - > mem_ctx , ctr - > info . id9 , & info - > sid ) ) )
return r_u - > status ;
break ;
2005-07-19 04:59:25 +04:00
case 16 :
ctr - > info . id16 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_16 ) ;
if ( ctr - > info . id16 = = NULL )
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2005-07-19 04:59:25 +04:00
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_16 ( p - > mem_ctx , ctr - > info . id16 , & info - > sid ) ) )
2002-07-15 14:35:28 +04:00
return r_u - > status ;
2001-02-27 21:22:39 +03:00
break ;
2005-07-19 04:59:25 +04:00
case 18 :
ctr - > info . id18 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_18 ) ;
if ( ctr - > info . id18 = = NULL )
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2005-07-19 04:59:25 +04:00
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_18 ( p , p - > mem_ctx , ctr - > info . id18 , & info - > sid ) ) )
2001-03-13 03:32:43 +03:00
return r_u - > status ;
2001-02-27 21:22:39 +03:00
break ;
2008-02-05 14:54:19 +03:00
2001-07-09 22:25:40 +04:00
case 20 :
2004-12-07 21:25:53 +03:00
ctr - > info . id20 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_20 ) ;
2001-07-09 22:25:40 +04:00
if ( ctr - > info . id20 = = NULL )
return NT_STATUS_NO_MEMORY ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_20 ( p - > mem_ctx , ctr - > info . id20 , & info - > sid ) ) )
return r_u - > status ;
2001-07-09 22:25:40 +04:00
break ;
2001-02-27 21:22:39 +03:00
case 21 :
2004-12-07 21:25:53 +03:00
ctr - > info . id21 = TALLOC_ZERO_P ( p - > mem_ctx , SAM_USER_INFO_21 ) ;
2001-02-27 21:22:39 +03:00
if ( ctr - > info . id21 = = NULL )
return NT_STATUS_NO_MEMORY ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( r_u - > status = get_user_info_21 ( p - > mem_ctx , ctr - > info . id21 ,
2002-07-15 14:35:28 +04:00
& info - > sid , & domain_sid ) ) )
return r_u - > status ;
2001-02-27 21:22:39 +03:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
}
init_samr_r_query_userinfo ( r_u , ctr , r_u - > status ) ;
DEBUG ( 5 , ( " _samr_query_userinfo: %d \n " , __LINE__ ) ) ;
2008-02-05 14:54:19 +03:00
2001-02-27 21:22:39 +03:00
return r_u - > status ;
}
/*******************************************************************
2008-02-06 18:06:04 +03:00
_samr_GetGroupsForUser
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-06 18:06:04 +03:00
NTSTATUS _samr_GetGroupsForUser ( pipes_struct * p ,
struct samr_GetGroupsForUser * r )
2001-02-27 21:22:39 +03:00
{
2006-02-20 23:09:36 +03:00
struct samu * sam_pass = NULL ;
2002-07-15 14:35:28 +04:00
DOM_SID sid ;
2004-11-12 18:49:47 +03:00
DOM_SID * sids ;
2008-02-06 18:06:04 +03:00
struct samr_RidWithAttribute dom_gid ;
struct samr_RidWithAttribute * gids = NULL ;
2006-02-04 01:19:41 +03:00
uint32 primary_group_rid ;
2005-10-18 07:24:00 +04:00
size_t num_groups = 0 ;
2004-11-12 18:49:47 +03:00
gid_t * unix_gids ;
2005-10-18 07:24:00 +04:00
size_t i , num_gids ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2007-10-19 04:40:25 +04:00
bool ret ;
2004-11-12 18:49:47 +03:00
NTSTATUS result ;
2007-10-19 04:40:25 +04:00
bool success = False ;
2001-02-27 21:22:39 +03:00
2008-02-06 18:06:04 +03:00
struct samr_RidWithAttributeArray * rids = NULL ;
2001-12-02 04:45:50 +03:00
/*
* from the SID in the request :
* we should send back the list of DOMAIN GROUPS
* the user is a member of
*
* and only the DOMAIN GROUPS
* no ALIASES ! ! ! neither aliases of the domain
* nor aliases of the builtin SID
*
* JFM , 12 / 2 / 2001
*/
2008-02-06 18:06:04 +03:00
DEBUG ( 5 , ( " _samr_GetGroupsForUser: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-06 18:06:04 +03:00
rids = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_RidWithAttributeArray ) ;
if ( ! rids ) {
return NT_STATUS_NO_MEMORY ;
}
2001-02-27 21:22:39 +03:00
2001-05-04 19:44:27 +04:00
/* find the policy handle. open a policy on it. */
2008-02-06 18:06:04 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . user_handle , & sid , & acc_granted , NULL ) )
2001-05-04 19:44:27 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-06 18:06:04 +03:00
result = access_check_samr_function ( acc_granted ,
SA_RIGHT_USER_GET_GROUPS ,
" _samr_GetGroupsForUser " ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sid_check_is_in_our_domain ( & sid ) )
2001-05-04 19:44:27 +04:00
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2001-02-27 21:22:39 +03:00
2006-02-21 17:34:11 +03:00
if ( ! ( sam_pass = samu_new ( p - > mem_ctx ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2001-05-04 19:44:27 +04:00
become_root ( ) ;
2002-07-15 14:35:28 +04:00
ret = pdb_getsampwsid ( sam_pass , & sid ) ;
2001-05-04 19:44:27 +04:00
unbecome_root ( ) ;
2001-02-27 21:22:39 +03:00
2006-02-04 01:19:41 +03:00
if ( ! ret ) {
DEBUG ( 10 , ( " pdb_getsampwsid failed for %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & sid ) ) ) ;
2004-11-12 18:49:47 +03:00
return NT_STATUS_NO_SUCH_USER ;
}
sids = NULL ;
2007-02-22 23:52:27 +03:00
/* make both calls inside the root block */
2004-11-12 18:49:47 +03:00
become_root ( ) ;
2006-02-04 01:19:41 +03:00
result = pdb_enum_group_memberships ( p - > mem_ctx , sam_pass ,
2004-11-12 18:49:47 +03:00
& sids , & unix_gids , & num_groups ) ;
2007-02-22 23:52:27 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2008-02-05 14:54:19 +03:00
success = sid_peek_check_rid ( get_global_sam_sid ( ) ,
2007-02-22 23:52:27 +03:00
pdb_get_group_sid ( sam_pass ) ,
& primary_group_rid ) ;
}
2004-11-12 18:49:47 +03:00
unbecome_root ( ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 10 , ( " pdb_enum_group_memberships failed for %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & sid ) ) ) ;
2004-11-12 18:49:47 +03:00
return result ;
2006-02-04 01:19:41 +03:00
}
2004-11-12 18:49:47 +03:00
2007-02-22 23:52:27 +03:00
if ( ! success ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 5 , ( " Group sid %s for user %s not in our domain \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( pdb_get_group_sid ( sam_pass ) ) ,
2006-02-04 01:19:41 +03:00
pdb_get_username ( sam_pass ) ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INTERNAL_DB_CORRUPTION ;
}
2007-02-22 23:52:27 +03:00
gids = NULL ;
num_gids = 0 ;
2006-02-04 01:19:41 +03:00
2008-02-06 18:06:04 +03:00
dom_gid . attributes = ( SE_GROUP_MANDATORY | SE_GROUP_ENABLED_BY_DEFAULT |
SE_GROUP_ENABLED ) ;
dom_gid . rid = primary_group_rid ;
ADD_TO_ARRAY ( p - > mem_ctx , struct samr_RidWithAttribute , dom_gid , & gids , & num_gids ) ;
2006-02-04 01:19:41 +03:00
2004-11-12 18:49:47 +03:00
for ( i = 0 ; i < num_groups ; i + + ) {
if ( ! sid_peek_check_rid ( get_global_sam_sid ( ) ,
2008-02-06 18:06:04 +03:00
& ( sids [ i ] ) , & dom_gid . rid ) ) {
2006-02-04 01:19:41 +03:00
DEBUG ( 10 , ( " Found sid %s not in our domain \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & sids [ i ] ) ) ) ;
2006-02-04 01:19:41 +03:00
continue ;
}
2008-02-06 18:06:04 +03:00
if ( dom_gid . rid = = primary_group_rid ) {
2006-02-04 01:19:41 +03:00
/* We added the primary group directly from the
* sam_account . The other SIDs are unique from
* enum_group_memberships */
2004-11-12 18:49:47 +03:00
continue ;
2006-02-04 01:19:41 +03:00
}
2004-11-12 18:49:47 +03:00
2008-02-06 18:06:04 +03:00
ADD_TO_ARRAY ( p - > mem_ctx , struct samr_RidWithAttribute , dom_gid , & gids , & num_gids ) ;
2001-12-05 00:53:47 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-06 18:06:04 +03:00
rids - > count = num_gids ;
rids - > rids = gids ;
2008-02-05 14:54:19 +03:00
2008-02-06 18:06:04 +03:00
* r - > out . rids = rids ;
2008-02-05 14:54:19 +03:00
2008-02-06 18:06:04 +03:00
DEBUG ( 5 , ( " _samr_GetGroupsForUser: %d \n " , __LINE__ ) ) ;
return result ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-05 17:03:54 +03:00
samr_QueryDomainInfo_internal
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 17:03:54 +03:00
static NTSTATUS samr_QueryDomainInfo_internal ( const char * fn_name ,
pipes_struct * p ,
struct policy_handle * handle ,
uint32_t level ,
union samr_DomainInfo * * dom_info_ptr )
2001-02-27 21:22:39 +03:00
{
2008-02-05 17:03:54 +03:00
NTSTATUS status = NT_STATUS_OK ;
2001-12-22 01:34:49 +03:00
struct samr_info * info = NULL ;
2008-02-05 17:03:54 +03:00
union samr_DomainInfo * dom_info ;
2006-02-11 02:09:00 +03:00
uint32 min_pass_len , pass_hist , password_properties ;
2001-12-03 20:14:23 +03:00
time_t u_expire , u_min_age ;
NTTIME nt_expire , nt_min_age ;
time_t u_lock_duration , u_reset_time ;
NTTIME nt_lock_duration , nt_reset_time ;
uint32 lockout ;
time_t u_logout ;
NTTIME nt_logout ;
2002-08-17 19:34:15 +04:00
uint32 account_policy_temp ;
2005-09-30 21:13:37 +04:00
time_t seq_num ;
2005-02-07 17:14:44 +03:00
uint32 server_role ;
2002-08-17 19:34:15 +04:00
2001-12-22 01:34:49 +03:00
uint32 num_users = 0 , num_groups = 0 , num_aliases = 0 ;
2001-02-27 21:22:39 +03:00
2008-02-05 17:03:54 +03:00
DEBUG ( 5 , ( " %s: %d \n " , fn_name , __LINE__ ) ) ;
dom_info = TALLOC_ZERO_P ( p - > mem_ctx , union samr_DomainInfo ) ;
if ( ! dom_info ) {
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2005-11-01 02:47:57 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-05 17:03:54 +03:00
* dom_info_ptr = dom_info ;
2008-02-05 14:54:19 +03:00
2001-12-03 20:14:23 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 17:03:54 +03:00
if ( ! find_policy_by_hnd ( p , handle , ( void * * ) ( void * ) & info ) ) {
2001-12-03 20:14:23 +03:00
return NT_STATUS_INVALID_HANDLE ;
2005-11-01 02:47:57 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
switch ( level ) {
2001-12-03 20:14:23 +03:00
case 0x01 :
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
become_root ( ) ;
/* AS ROOT !!! */
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_MIN_PASSWORD_LEN , & account_policy_temp ) ;
2002-08-17 19:34:15 +04:00
min_pass_len = account_policy_temp ;
2001-12-03 20:14:23 +03:00
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_PASSWORD_HISTORY , & account_policy_temp ) ;
2002-08-17 19:34:15 +04:00
pass_hist = account_policy_temp ;
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_USER_MUST_LOGON_TO_CHG_PASS , & account_policy_temp ) ;
2006-02-11 02:09:00 +03:00
password_properties = account_policy_temp ;
2002-08-17 19:34:15 +04:00
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_MAX_PASSWORD_AGE , & account_policy_temp ) ;
2002-08-17 19:34:15 +04:00
u_expire = account_policy_temp ;
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_MIN_PASSWORD_AGE , & account_policy_temp ) ;
2002-08-17 19:34:15 +04:00
u_min_age = account_policy_temp ;
2005-11-01 02:47:57 +03:00
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
unbecome_root ( ) ;
2001-12-03 20:14:23 +03:00
unix_to_nt_time_abs ( & nt_expire , u_expire ) ;
unix_to_nt_time_abs ( & nt_min_age , u_min_age ) ;
2008-02-05 17:03:54 +03:00
init_samr_DomInfo1 ( & dom_info - > info1 ,
( uint16 ) min_pass_len ,
( uint16 ) pass_hist ,
password_properties ,
nt_expire ,
nt_min_age ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x02 :
2005-11-01 02:47:57 +03:00
2005-04-15 17:41:49 +04:00
become_root ( ) ;
2005-11-01 02:47:57 +03:00
/* AS ROOT !!! */
2005-11-27 04:17:24 +03:00
num_users = count_sam_users ( info - > disp_info , ACB_NORMAL ) ;
num_groups = count_sam_groups ( info - > disp_info ) ;
num_aliases = count_sam_aliases ( info - > disp_info ) ;
2004-12-23 02:50:31 +03:00
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_TIME_TO_LOGOUT , & account_policy_temp ) ;
2004-12-23 02:50:31 +03:00
u_logout = account_policy_temp ;
unix_to_nt_time_abs ( & nt_logout , u_logout ) ;
2005-09-30 21:13:37 +04:00
if ( ! pdb_get_seq_num ( & seq_num ) )
seq_num = time ( NULL ) ;
2005-11-01 02:47:57 +03:00
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
unbecome_root ( ) ;
2005-02-07 17:14:44 +03:00
server_role = ROLE_DOMAIN_PDC ;
if ( lp_server_role ( ) = = ROLE_DOMAIN_BDC )
server_role = ROLE_DOMAIN_BDC ;
2008-02-05 17:03:54 +03:00
init_samr_DomInfo2 ( & dom_info - > info2 ,
nt_logout ,
lp_serverstring ( ) ,
lp_workgroup ( ) ,
global_myname ( ) ,
seq_num ,
1 ,
server_role ,
1 ,
num_users ,
num_groups ,
num_aliases ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x03 :
2005-11-01 02:47:57 +03:00
become_root ( ) ;
/* AS ROOT !!! */
2005-12-03 09:46:46 +03:00
{
uint32 ul ;
pdb_get_account_policy ( AP_TIME_TO_LOGOUT , & ul ) ;
u_logout = ( time_t ) ul ;
}
2005-11-01 02:47:57 +03:00
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
unbecome_root ( ) ;
2001-12-03 20:14:23 +03:00
unix_to_nt_time_abs ( & nt_logout , u_logout ) ;
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
init_samr_DomInfo3 ( & dom_info - > info3 ,
nt_logout ) ;
2001-12-03 20:14:23 +03:00
break ;
2006-05-05 12:26:34 +04:00
case 0x04 :
2008-02-05 17:03:54 +03:00
init_samr_DomInfo4 ( & dom_info - > info4 ,
lp_serverstring ( ) ) ;
2006-05-05 12:26:34 +04:00
break ;
2001-12-03 20:14:23 +03:00
case 0x05 :
2008-02-05 17:03:54 +03:00
init_samr_DomInfo5 ( & dom_info - > info5 ,
get_global_sam_name ( ) ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x06 :
2006-05-04 23:01:11 +04:00
/* NT returns its own name when a PDC. win2k and later
* only the name of the PDC if itself is a BDC ( samba4
* idl ) */
2008-02-05 17:03:54 +03:00
init_samr_DomInfo6 ( & dom_info - > info6 ,
global_myname ( ) ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x07 :
2005-02-07 17:14:44 +03:00
server_role = ROLE_DOMAIN_PDC ;
if ( lp_server_role ( ) = = ROLE_DOMAIN_BDC )
server_role = ROLE_DOMAIN_BDC ;
2008-02-05 17:03:54 +03:00
init_samr_DomInfo7 ( & dom_info - > info7 ,
server_role ) ;
2001-12-03 20:14:23 +03:00
break ;
2004-12-22 19:58:43 +03:00
case 0x08 :
2005-11-01 02:47:57 +03:00
become_root ( ) ;
/* AS ROOT !!! */
if ( ! pdb_get_seq_num ( & seq_num ) ) {
2005-09-30 21:13:37 +04:00
seq_num = time ( NULL ) ;
2005-11-01 02:47:57 +03:00
}
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
unbecome_root ( ) ;
2005-09-30 21:13:37 +04:00
2008-02-05 17:03:54 +03:00
init_samr_DomInfo8 ( & dom_info - > info8 ,
seq_num ,
0 ) ;
2004-12-22 19:58:43 +03:00
break ;
2001-12-03 20:14:23 +03:00
case 0x0c :
2005-11-01 02:47:57 +03:00
become_root ( ) ;
/* AS ROOT !!! */
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_LOCK_ACCOUNT_DURATION , & account_policy_temp ) ;
2005-01-10 18:28:07 +03:00
u_lock_duration = account_policy_temp ;
2005-11-01 02:47:57 +03:00
if ( u_lock_duration ! = - 1 ) {
2005-01-10 18:28:07 +03:00
u_lock_duration * = 60 ;
2005-11-01 02:47:57 +03:00
}
2002-08-17 19:34:15 +04:00
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_RESET_COUNT_TIME , & account_policy_temp ) ;
2004-02-25 23:02:47 +03:00
u_reset_time = account_policy_temp * 60 ;
2002-08-17 19:34:15 +04:00
2005-09-30 21:13:37 +04:00
pdb_get_account_policy ( AP_BAD_ATTEMPT_LOCKOUT , & account_policy_temp ) ;
2002-08-17 19:34:15 +04:00
lockout = account_policy_temp ;
2005-11-01 02:47:57 +03:00
/* !AS ROOT */
2008-02-05 14:54:19 +03:00
2005-11-01 02:47:57 +03:00
unbecome_root ( ) ;
2001-12-03 20:14:23 +03:00
unix_to_nt_time_abs ( & nt_lock_duration , u_lock_duration ) ;
unix_to_nt_time_abs ( & nt_reset_time , u_reset_time ) ;
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
init_samr_DomInfo12 ( & dom_info - > info12 ,
nt_lock_duration ,
nt_reset_time ,
( uint16 ) lockout ) ;
2001-12-03 20:14:23 +03:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
2008-02-05 17:03:54 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
DEBUG ( 5 , ( " %s: %d \n " , fn_name , __LINE__ ) ) ;
2005-11-01 02:47:57 +03:00
2008-02-05 17:03:54 +03:00
return status ;
}
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
/*******************************************************************
_samr_QueryDomainInfo
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 14:54:19 +03:00
2008-02-05 17:03:54 +03:00
NTSTATUS _samr_QueryDomainInfo ( pipes_struct * p ,
struct samr_QueryDomainInfo * r )
{
return samr_QueryDomainInfo_internal ( " _samr_QueryDomainInfo " ,
p ,
r - > in . domain_handle ,
r - > in . level ,
r - > out . info ) ;
2001-02-27 21:22:39 +03:00
}
2005-12-03 21:34:13 +03:00
/* W2k3 seems to use the same check for all 3 objects that can be created via
* SAMR , if you try to create for example " Dialup " as an alias it says
* " NT_STATUS_USER_EXISTS " . This is racy , but we can ' t really lock the user
* database . */
static NTSTATUS can_create ( TALLOC_CTX * mem_ctx , const char * new_name )
{
2006-09-08 18:28:06 +04:00
enum lsa_SidType type ;
2007-10-19 04:40:25 +04:00
bool result ;
2005-12-03 21:34:13 +03:00
2005-12-08 22:34:22 +03:00
DEBUG ( 10 , ( " Checking whether [%s] can be created \n " , new_name ) ) ;
2005-12-03 21:34:13 +03:00
become_root ( ) ;
2007-12-17 13:32:21 +03:00
/* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
2005-12-03 21:34:13 +03:00
* whether the name already exists */
2007-12-17 13:32:21 +03:00
result = lookup_name ( mem_ctx , new_name , LOOKUP_NAME_LOCAL ,
2005-12-03 21:34:13 +03:00
NULL , NULL , NULL , & type ) ;
unbecome_root ( ) ;
if ( ! result ) {
2005-12-08 22:34:22 +03:00
DEBUG ( 10 , ( " %s does not exist, can create it \n " , new_name ) ) ;
2005-12-03 21:34:13 +03:00
return NT_STATUS_OK ;
}
DEBUG ( 5 , ( " trying to create %s, exists as %s \n " ,
new_name , sid_type_lookup ( type ) ) ) ;
if ( type = = SID_NAME_DOM_GRP ) {
return NT_STATUS_GROUP_EXISTS ;
}
if ( type = = SID_NAME_ALIAS ) {
return NT_STATUS_ALIAS_EXISTS ;
}
/* Yes, the default is NT_STATUS_USER_EXISTS */
return NT_STATUS_USER_EXISTS ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2008-02-01 16:50:33 +03:00
_samr_CreateUser2
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 16:50:33 +03:00
NTSTATUS _samr_CreateUser2 ( pipes_struct * p ,
struct samr_CreateUser2 * r )
2001-02-27 21:22:39 +03:00
{
2008-02-01 16:50:33 +03:00
const char * account = NULL ;
2001-05-04 19:44:27 +04:00
DOM_SID sid ;
2008-02-01 16:50:33 +03:00
POLICY_HND dom_pol = * r - > in . domain_handle ;
uint32_t acb_info = r - > in . acct_flags ;
POLICY_HND * user_pol = r - > out . user_handle ;
2001-03-11 03:32:10 +03:00
struct samr_info * info = NULL ;
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
NTSTATUS nt_status ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
SEC_DESC * psd ;
size_t sd_size ;
2003-04-23 05:04:20 +04:00
/* check this, when giving away 'add computer to domain' privs */
2003-03-21 16:35:15 +03:00
uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS ;
2007-10-19 04:40:25 +04:00
bool can_add_account = False ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* Get the domain SID stored in the domain policy */
2006-02-04 01:19:41 +03:00
if ( ! get_lsa_policy_samr_sid ( p , & dom_pol , & sid , & acc_granted ,
& disp_info ) )
2001-05-04 19:44:27 +04:00
return NT_STATUS_INVALID_HANDLE ;
2001-02-27 21:22:39 +03:00
2006-02-04 01:19:41 +03:00
nt_status = access_check_samr_function ( acc_granted ,
SA_RIGHT_DOMAIN_CREATE_USER ,
2008-02-01 16:50:33 +03:00
" _samr_CreateUser2 " ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-07-15 14:35:28 +04:00
return nt_status ;
}
2006-02-04 01:19:41 +03:00
if ( ! ( acb_info = = ACB_NORMAL | | acb_info = = ACB_DOMTRUST | |
2008-02-05 14:54:19 +03:00
acb_info = = ACB_WSTRUST | | acb_info = = ACB_SVRTRUST ) ) {
/* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
2004-01-03 02:55:44 +03:00
this parameter is not an account type */
2003-12-02 15:48:15 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-02-01 16:50:33 +03:00
account = r - > in . account_name - > string ;
2006-02-13 20:08:25 +03:00
if ( account = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2005-09-30 21:13:37 +04:00
2005-12-03 21:34:13 +03:00
nt_status = can_create ( p - > mem_ctx , account ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
2001-05-04 19:44:27 +04:00
}
2001-02-27 21:22:39 +03:00
2005-01-27 05:16:02 +03:00
/* determine which user right we need to check based on the acb_info */
2008-02-05 14:54:19 +03:00
2005-02-03 19:23:49 +03:00
if ( acb_info & ACB_WSTRUST )
2005-02-03 18:14:54 +03:00
{
se_priv_copy ( & se_rights , & se_machine_account ) ;
2006-02-04 01:19:41 +03:00
can_add_account = user_has_privileges (
p - > pipe_user . nt_user_token , & se_rights ) ;
2008-02-05 14:54:19 +03:00
}
/* usrmgr.exe (and net rpc trustdom grant) creates a normal user
2005-04-21 21:13:50 +04:00
account for domain trusts and changes the ACB flags later */
2006-02-04 01:19:41 +03:00
else if ( acb_info & ACB_NORMAL & &
( account [ strlen ( account ) - 1 ] ! = ' $ ' ) )
2005-02-03 18:14:54 +03:00
{
se_priv_copy ( & se_rights , & se_add_users ) ;
2006-02-04 01:19:41 +03:00
can_add_account = user_has_privileges (
p - > pipe_user . nt_user_token , & se_rights ) ;
2008-02-05 14:54:19 +03:00
}
2006-02-04 01:19:41 +03:00
else /* implicit assumption of a BDC or domain trust account here
* ( we already check the flags earlier ) */
2005-02-03 18:14:54 +03:00
{
2005-02-03 19:23:49 +03:00
if ( lp_enable_privileges ( ) ) {
/* only Domain Admins can add a BDC or domain trust */
se_priv_copy ( & se_rights , & se_priv_none ) ;
2006-02-04 01:19:41 +03:00
can_add_account = nt_token_check_domain_rid (
p - > pipe_user . nt_user_token ,
DOMAIN_GROUP_RID_ADMINS ) ;
}
2005-09-30 21:13:37 +04:00
}
2008-02-05 14:54:19 +03:00
2008-02-01 16:50:33 +03:00
DEBUG ( 5 , ( " _samr_CreateUser2: %s can add this account : %s \n " ,
2006-07-11 22:01:26 +04:00
uidtoname ( p - > pipe_user . ut . uid ) ,
can_add_account ? " True " : " False " ) ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/********** BEGIN Admin BLOCK **********/
2005-09-30 21:13:37 +04:00
2005-01-19 19:52:19 +03:00
if ( can_add_account )
2005-01-07 02:27:28 +03:00
become_root ( ) ;
2005-09-30 21:13:37 +04:00
2006-02-13 20:08:25 +03:00
nt_status = pdb_create_user ( p - > mem_ctx , account , acb_info ,
2008-02-01 16:50:33 +03:00
r - > out . rid ) ;
2003-07-09 20:44:47 +04:00
2005-01-19 19:52:19 +03:00
if ( can_add_account )
2005-01-07 02:27:28 +03:00
unbecome_root ( ) ;
2005-01-19 19:52:19 +03:00
/********** END Admin BLOCK **********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/* now check for failure */
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
return nt_status ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
/* Get the user's SID */
2006-02-13 20:08:25 +03:00
2008-02-01 16:50:33 +03:00
sid_compose ( & sid , get_global_sam_sid ( ) , * r - > out . rid ) ;
2008-02-05 14:54:19 +03:00
2006-02-04 01:19:41 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & usr_generic_mapping ,
& sid , SAMR_USR_RIGHTS_WRITE_PW ) ;
2002-07-15 14:35:28 +04:00
se_map_generic ( & des_access , & usr_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
nt_status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
& se_rights , GENERIC_RIGHTS_USER_WRITE , des_access ,
2008-02-01 16:50:33 +03:00
& acc_granted , " _samr_CreateUser2 " ) ;
2008-02-05 14:54:19 +03:00
2005-01-07 02:27:28 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-07-15 14:35:28 +04:00
return nt_status ;
2001-05-04 19:44:27 +04:00
}
/* associate the user's SID with the new handle. */
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & sid ) ) = = NULL ) {
2001-05-04 19:44:27 +04:00
return NT_STATUS_NO_MEMORY ;
}
ZERO_STRUCTP ( info ) ;
info - > sid = sid ;
2002-07-15 14:35:28 +04:00
info - > acc_granted = acc_granted ;
2001-05-04 19:44:27 +04:00
/* get a (unique) handle. open a policy on it. */
if ( ! create_policy_hnd ( p , user_pol , free_samr_info , ( void * ) info ) ) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
}
2005-11-19 02:15:47 +03:00
/* After a "set" ensure we have no cached display info. */
force_flush_samr_cache ( info - > disp_info ) ;
2008-02-01 16:50:33 +03:00
* r - > out . access_granted = acc_granted ;
2001-05-04 19:44:27 +04:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-04 18:17:20 +03:00
_samr_Connect
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 18:17:20 +03:00
NTSTATUS _samr_Connect ( pipes_struct * p ,
struct samr_Connect * r )
2001-02-27 21:22:39 +03:00
{
2001-03-11 03:32:10 +03:00
struct samr_info * info = NULL ;
2008-02-04 18:17:20 +03:00
uint32 des_access = r - > in . access_mask ;
2001-03-11 03:32:10 +03:00
2002-07-15 14:35:28 +04:00
/* Access check */
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
if ( ! pipe_access_check ( p ) ) {
2008-02-04 18:17:20 +03:00
DEBUG ( 3 , ( " access denied to _samr_Connect \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2002-07-15 14:35:28 +04:00
}
/* set up the SAMR connect_anon response */
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* associate the user's SID with the new handle. */
if ( ( info = get_samr_info_by_sid ( NULL ) ) = = NULL )
return NT_STATUS_NO_MEMORY ;
2001-03-11 03:32:10 +03:00
2003-08-13 07:59:41 +04:00
/* don't give away the farm but this is probably ok. The SA_RIGHT_SAM_ENUM_DOMAINS
2008-02-05 14:54:19 +03:00
was observed from a win98 client trying to enumerate users ( when configured
2003-08-13 07:59:41 +04:00
user level access control on shares ) - - jerry */
2008-02-05 14:54:19 +03:00
2006-02-09 03:23:40 +03:00
if ( des_access = = MAXIMUM_ALLOWED_ACCESS ) {
/* Map to max possible knowing we're filtered below. */
des_access = GENERIC_ALL_ACCESS ;
}
2003-08-13 07:59:41 +04:00
se_map_generic ( & des_access , & sam_generic_mapping ) ;
info - > acc_granted = des_access & ( SA_RIGHT_SAM_ENUM_DOMAINS | SA_RIGHT_SAM_OPEN_DOMAIN ) ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* get a (unique) handle. open a policy on it. */
2008-02-04 18:17:20 +03:00
if ( ! create_policy_hnd ( p , r - > out . connect_handle , free_samr_info , ( void * ) info ) )
2002-07-15 14:35:28 +04:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2001-02-27 21:22:39 +03:00
2008-02-04 18:17:20 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-04 18:23:46 +03:00
_samr_Connect2
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 18:23:46 +03:00
NTSTATUS _samr_Connect2 ( pipes_struct * p ,
struct samr_Connect2 * r )
2001-02-27 21:22:39 +03:00
{
2001-03-11 03:32:10 +03:00
struct samr_info * info = NULL ;
2002-07-15 14:35:28 +04:00
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-04 18:23:46 +03:00
uint32 des_access = r - > in . access_mask ;
2002-07-15 14:35:28 +04:00
NTSTATUS nt_status ;
2005-09-30 21:13:37 +04:00
size_t sd_size ;
2001-03-11 03:32:10 +03:00
2001-02-27 21:22:39 +03:00
2008-02-04 18:23:46 +03:00
DEBUG ( 5 , ( " _samr_Connect2: %d \n " , __LINE__ ) ) ;
2002-07-15 14:35:28 +04:00
/* Access check */
if ( ! pipe_access_check ( p ) ) {
2008-02-04 18:23:46 +03:00
DEBUG ( 3 , ( " access denied to _samr_Connect2 \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2002-07-15 14:35:28 +04:00
}
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & sam_generic_mapping , NULL , 0 ) ;
2002-07-15 14:35:28 +04:00
se_map_generic ( & des_access , & sam_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
nt_status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
2008-02-04 18:23:46 +03:00
NULL , 0 , des_access , & acc_granted , " _samr_Connect2 " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2002-07-15 14:35:28 +04:00
return nt_status ;
/* associate the user's SID and access granted with the new handle. */
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( NULL ) ) = = NULL )
2002-07-15 14:35:28 +04:00
return NT_STATUS_NO_MEMORY ;
2001-03-11 03:32:10 +03:00
2002-07-15 14:35:28 +04:00
info - > acc_granted = acc_granted ;
2008-02-04 18:23:46 +03:00
info - > status = r - > in . access_mask ; /* this looks so wrong... - gd */
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* get a (unique) handle. open a policy on it. */
2008-02-04 18:23:46 +03:00
if ( ! create_policy_hnd ( p , r - > out . connect_handle , free_samr_info , ( void * ) info ) )
2002-07-15 14:35:28 +04:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2001-02-27 21:22:39 +03:00
2008-02-04 18:23:46 +03:00
DEBUG ( 5 , ( " _samr_Connect2: %d \n " , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-04 18:23:46 +03:00
return nt_status ;
2001-02-27 21:22:39 +03:00
}
2002-08-17 19:34:15 +04:00
/*******************************************************************
2008-02-04 18:35:32 +03:00
_samr_Connect4
2002-08-17 19:34:15 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 18:35:32 +03:00
NTSTATUS _samr_Connect4 ( pipes_struct * p ,
struct samr_Connect4 * r )
2002-08-17 19:34:15 +04:00
{
struct samr_info * info = NULL ;
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-04 18:35:32 +03:00
uint32 des_access = r - > in . access_mask ;
2002-08-17 19:34:15 +04:00
NTSTATUS nt_status ;
2005-09-30 21:13:37 +04:00
size_t sd_size ;
2002-08-17 19:34:15 +04:00
2008-02-04 18:35:32 +03:00
DEBUG ( 5 , ( " _samr_Connect4: %d \n " , __LINE__ ) ) ;
2002-08-17 19:34:15 +04:00
/* Access check */
if ( ! pipe_access_check ( p ) ) {
2008-02-04 18:35:32 +03:00
DEBUG ( 3 , ( " access denied to samr_Connect4 \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2002-08-17 19:34:15 +04:00
}
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & sam_generic_mapping , NULL , 0 ) ;
2002-08-17 19:34:15 +04:00
se_map_generic ( & des_access , & sam_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
nt_status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
2008-02-04 18:35:32 +03:00
NULL , 0 , des_access , & acc_granted , " _samr_Connect4 " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2002-08-17 19:34:15 +04:00
return nt_status ;
/* associate the user's SID and access granted with the new handle. */
if ( ( info = get_samr_info_by_sid ( NULL ) ) = = NULL )
return NT_STATUS_NO_MEMORY ;
info - > acc_granted = acc_granted ;
2008-02-04 18:35:32 +03:00
info - > status = r - > in . access_mask ; /* ??? */
2002-08-17 19:34:15 +04:00
/* get a (unique) handle. open a policy on it. */
2008-02-04 18:35:32 +03:00
if ( ! create_policy_hnd ( p , r - > out . connect_handle , free_samr_info , ( void * ) info ) )
2002-08-17 19:34:15 +04:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2008-02-04 18:35:32 +03:00
DEBUG ( 5 , ( " _samr_Connect4: %d \n " , __LINE__ ) ) ;
2002-08-17 19:34:15 +04:00
2008-02-04 18:35:32 +03:00
return NT_STATUS_OK ;
2002-08-17 19:34:15 +04:00
}
2005-11-18 01:40:10 +03:00
/*******************************************************************
2008-02-04 19:10:16 +03:00
_samr_Connect5
2005-11-18 01:40:10 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 19:10:16 +03:00
NTSTATUS _samr_Connect5 ( pipes_struct * p ,
struct samr_Connect5 * r )
2005-11-18 01:40:10 +03:00
{
struct samr_info * info = NULL ;
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-04 19:10:16 +03:00
uint32 des_access = r - > in . access_mask ;
2005-11-18 01:40:10 +03:00
NTSTATUS nt_status ;
size_t sd_size ;
2008-02-04 19:10:16 +03:00
struct samr_ConnectInfo1 info1 ;
2005-11-18 01:40:10 +03:00
2008-02-04 19:10:16 +03:00
DEBUG ( 5 , ( " _samr_Connect5: %d \n " , __LINE__ ) ) ;
2005-11-18 01:40:10 +03:00
/* Access check */
if ( ! pipe_access_check ( p ) ) {
2008-02-04 19:10:16 +03:00
DEBUG ( 3 , ( " access denied to samr_Connect5 \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2005-11-18 01:40:10 +03:00
}
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & sam_generic_mapping , NULL , 0 ) ;
se_map_generic ( & des_access , & sam_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
nt_status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
2008-02-04 19:10:16 +03:00
NULL , 0 , des_access , & acc_granted , " _samr_Connect5 " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2005-11-18 01:40:10 +03:00
return nt_status ;
/* associate the user's SID and access granted with the new handle. */
if ( ( info = get_samr_info_by_sid ( NULL ) ) = = NULL )
return NT_STATUS_NO_MEMORY ;
info - > acc_granted = acc_granted ;
2008-02-04 19:10:16 +03:00
info - > status = r - > in . access_mask ; /* ??? */
2005-11-18 01:40:10 +03:00
/* get a (unique) handle. open a policy on it. */
2008-02-04 19:10:16 +03:00
if ( ! create_policy_hnd ( p , r - > out . connect_handle , free_samr_info , ( void * ) info ) )
2005-11-18 01:40:10 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2008-02-04 19:10:16 +03:00
DEBUG ( 5 , ( " _samr_Connect5: %d \n " , __LINE__ ) ) ;
2005-11-18 01:40:10 +03:00
2008-02-05 15:38:48 +03:00
info1 . client_version = SAMR_CONNECT_AFTER_W2K ;
2008-02-04 19:10:16 +03:00
info1 . unknown2 = 0 ;
2005-11-18 01:40:10 +03:00
2008-02-04 19:10:16 +03:00
* r - > out . level_out = 1 ;
r - > out . info_out - > info1 = info1 ;
return NT_STATUS_OK ;
2005-11-18 01:40:10 +03:00
}
2001-02-27 21:22:39 +03:00
/**********************************************************************
2008-02-05 03:29:49 +03:00
_samr_LookupDomain
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-08 21:42:23 +03:00
2008-02-05 03:29:49 +03:00
NTSTATUS _samr_LookupDomain ( pipes_struct * p ,
struct samr_LookupDomain * r )
2001-02-27 21:22:39 +03:00
{
2008-02-05 03:29:49 +03:00
NTSTATUS status = NT_STATUS_OK ;
2002-07-15 14:35:28 +04:00
struct samr_info * info ;
2008-02-05 03:29:49 +03:00
const char * domain_name ;
DOM_SID * sid = NULL ;
2001-02-27 21:22:39 +03:00
2008-02-05 03:29:49 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . connect_handle , ( void * * ) ( void * ) & info ) )
2002-03-10 04:45:49 +03:00
return NT_STATUS_INVALID_HANDLE ;
2001-02-27 21:22:39 +03:00
2008-02-05 14:54:19 +03:00
/* win9x user manager likes to use SA_RIGHT_SAM_ENUM_DOMAINS here.
2005-01-20 20:05:10 +03:00
Reverted that change so we will work with RAS servers again */
2008-02-05 03:29:49 +03:00
status = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_SAM_OPEN_DOMAIN ,
" _samr_LookupDomain " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 03:29:49 +03:00
domain_name = r - > in . domain_name - > string ;
2001-02-27 21:22:39 +03:00
2008-02-05 03:29:49 +03:00
sid = TALLOC_ZERO_P ( p - > mem_ctx , struct dom_sid2 ) ;
if ( ! sid ) {
return NT_STATUS_NO_MEMORY ;
}
2002-03-10 04:45:49 +03:00
2006-01-14 15:37:25 +03:00
if ( strequal ( domain_name , builtin_domain_name ( ) ) ) {
2008-02-05 03:29:49 +03:00
sid_copy ( sid , & global_sid_Builtin ) ;
2006-01-14 15:37:25 +03:00
} else {
2008-02-05 03:29:49 +03:00
if ( ! secrets_fetch_domain_sid ( domain_name , sid ) ) {
status = NT_STATUS_NO_SUCH_DOMAIN ;
2006-01-14 15:37:25 +03:00
}
2002-03-10 04:45:49 +03:00
}
2007-12-15 23:11:36 +03:00
DEBUG ( 2 , ( " Returning domain sid for domain %s -> %s \n " , domain_name ,
2008-02-05 03:29:49 +03:00
sid_string_dbg ( sid ) ) ) ;
2002-03-10 04:45:49 +03:00
2008-02-05 03:29:49 +03:00
* r - > out . sid = sid ;
2002-03-10 04:45:49 +03:00
2008-02-05 03:29:49 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/**********************************************************************
2008-02-09 03:55:49 +03:00
_samr_EnumDomains
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-09 03:55:49 +03:00
NTSTATUS _samr_EnumDomains ( pipes_struct * p ,
struct samr_EnumDomains * r )
2001-02-27 21:22:39 +03:00
{
2008-02-09 03:55:49 +03:00
NTSTATUS status ;
2002-07-15 14:35:28 +04:00
struct samr_info * info ;
2008-02-09 03:55:49 +03:00
uint32_t num_entries = 2 ;
struct samr_SamEntry * entry_array = NULL ;
struct samr_SamArray * sam ;
2008-02-05 14:54:19 +03:00
2008-02-09 03:55:49 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . connect_handle , ( void * * ) ( void * ) & info ) )
2002-07-15 14:35:28 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-09 03:55:49 +03:00
status = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_SAM_ENUM_DOMAINS ,
" _samr_EnumDomains " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
2008-02-09 03:55:49 +03:00
sam = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_SamArray ) ;
if ( ! sam ) {
return NT_STATUS_NO_MEMORY ;
}
2001-02-27 21:22:39 +03:00
2008-02-09 03:55:49 +03:00
entry_array = TALLOC_ZERO_ARRAY ( p - > mem_ctx ,
struct samr_SamEntry ,
num_entries ) ;
if ( ! entry_array ) {
2001-02-27 21:22:39 +03:00
return NT_STATUS_NO_MEMORY ;
2008-02-09 03:55:49 +03:00
}
2001-02-27 21:22:39 +03:00
2008-02-09 03:55:49 +03:00
entry_array [ 0 ] . idx = 0 ;
init_lsa_String ( & entry_array [ 0 ] . name , get_global_sam_name ( ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-09 03:55:49 +03:00
entry_array [ 1 ] . idx = 1 ;
init_lsa_String ( & entry_array [ 1 ] . name , " Builtin " ) ;
sam - > count = num_entries ;
sam - > entries = entry_array ;
* r - > out . sam = sam ;
* r - > out . num_entries = num_entries ;
return status ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2008-02-01 02:48:40 +03:00
_samr_OpenAlias
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 02:48:40 +03:00
NTSTATUS _samr_OpenAlias ( pipes_struct * p ,
struct samr_OpenAlias * r )
2001-02-27 21:22:39 +03:00
{
DOM_SID sid ;
2008-02-01 02:48:40 +03:00
POLICY_HND domain_pol = * r - > in . domain_handle ;
uint32 alias_rid = r - > in . rid ;
POLICY_HND * alias_pol = r - > out . alias_handle ;
2002-07-15 14:35:28 +04:00
struct samr_info * info = NULL ;
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-01 02:48:40 +03:00
uint32 des_access = r - > in . access_mask ;
2002-07-15 14:35:28 +04:00
size_t sd_size ;
NTSTATUS status ;
2005-01-26 23:36:44 +03:00
SE_PRIV se_rights ;
2001-02-27 21:22:39 +03:00
2002-07-15 14:35:28 +04:00
/* find the domain policy and get the SID / access bits stored in the domain policy */
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
if ( ! get_lsa_policy_samr_sid ( p , & domain_pol , & sid , & acc_granted , NULL ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
status = access_check_samr_function ( acc_granted ,
2008-02-08 21:42:23 +03:00
SA_RIGHT_DOMAIN_OPEN_ACCOUNT ,
" _samr_OpenAlias " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
2002-07-15 14:35:28 +04:00
return status ;
2001-03-11 03:32:10 +03:00
/* append the alias' RID to it */
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sid_append_rid ( & sid , alias_rid ) )
2005-12-03 21:34:13 +03:00
return NT_STATUS_NO_SUCH_ALIAS ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
/*check if access can be granted as requested by client. */
2008-02-05 14:54:19 +03:00
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & ali_generic_mapping , NULL , 0 ) ;
2002-07-15 14:35:28 +04:00
se_map_generic ( & des_access , & ali_generic_mapping ) ;
2008-02-05 14:54:19 +03:00
2005-05-13 13:18:50 +04:00
se_priv_copy ( & se_rights , & se_add_users ) ;
2008-02-05 14:54:19 +03:00
status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
& se_rights , GENERIC_RIGHTS_ALIAS_WRITE , des_access ,
2008-02-01 02:48:40 +03:00
& acc_granted , " _samr_OpenAlias " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
2002-07-15 14:35:28 +04:00
return status ;
2001-02-27 21:22:39 +03:00
2005-12-03 21:34:13 +03:00
{
/* Check we actually have the requested alias */
2006-09-08 18:28:06 +04:00
enum lsa_SidType type ;
2007-10-19 04:40:25 +04:00
bool result ;
2006-03-15 03:10:38 +03:00
gid_t gid ;
2001-02-27 21:22:39 +03:00
2005-12-03 21:34:13 +03:00
become_root ( ) ;
result = lookup_sid ( NULL , & sid , NULL , NULL , & type ) ;
unbecome_root ( ) ;
if ( ! result | | ( type ! = SID_NAME_ALIAS ) ) {
return NT_STATUS_NO_SUCH_ALIAS ;
}
2006-03-15 03:10:38 +03:00
/* make sure there is a mapping */
2008-02-05 14:54:19 +03:00
2006-03-15 03:10:38 +03:00
if ( ! sid_to_gid ( & sid , & gid ) ) {
return NT_STATUS_NO_SUCH_ALIAS ;
}
2005-12-03 21:34:13 +03:00
}
/* associate the alias SID with the new handle. */
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & sid ) ) = = NULL )
2001-12-05 00:53:47 +03:00
return NT_STATUS_NO_MEMORY ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
info - > acc_granted = acc_granted ;
2001-02-27 21:22:39 +03:00
2001-03-11 03:32:10 +03:00
/* get a (unique) handle. open a policy on it. */
if ( ! create_policy_hnd ( p , alias_pol , free_samr_info , ( void * ) info ) )
2001-02-27 21:22:39 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2008-02-01 02:48:40 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
2005-10-12 00:14:04 +04:00
/*******************************************************************
set_user_info_7
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
2005-12-03 21:34:13 +03:00
static NTSTATUS set_user_info_7 ( TALLOC_CTX * mem_ctx ,
2008-02-11 23:09:21 +03:00
struct samr_UserInfo7 * id7 ,
struct samu * pwd )
2005-10-12 00:14:04 +04:00
{
NTSTATUS rc ;
if ( id7 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_7: NULL id7 \n " ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2005-10-12 00:14:04 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
2008-02-11 23:09:21 +03:00
if ( ! id7 - > account_name . string ) {
2005-10-12 00:14:04 +04:00
DEBUG ( 5 , ( " set_user_info_7: failed to get new username \n " ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2005-10-12 00:14:04 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
2005-10-21 00:40:47 +04:00
/* check to see if the new username already exists. Note: we can't
2008-02-05 14:54:19 +03:00
reliably lock all backends , so there is potentially the
2005-10-21 00:40:47 +04:00
possibility that a user can be created in between this check and
the rename . The rename should fail , but may not get the
exact same failure status code . I think this is small enough
of a window for this type of operation and the results are
simply that the rename fails with a slightly different status
code ( like UNSUCCESSFUL instead of ALREADY_EXISTS ) . */
2008-02-11 23:09:21 +03:00
rc = can_create ( mem_ctx , id7 - > account_name . string ) ;
2005-12-03 21:34:13 +03:00
if ( ! NT_STATUS_IS_OK ( rc ) ) {
return rc ;
2005-10-21 00:40:47 +04:00
}
2008-02-11 23:09:21 +03:00
rc = pdb_rename_sam_account ( pwd , id7 - > account_name . string ) ;
2005-10-12 00:14:04 +04:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2005-10-12 00:14:04 +04:00
return rc ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2005-07-19 04:59:25 +04:00
set_user_info_16
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static bool set_user_info_16 ( struct samr_UserInfo16 * id16 ,
struct samu * pwd )
2001-02-27 21:22:39 +03:00
{
2005-07-19 04:59:25 +04:00
if ( id16 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_16: NULL id16 \n " ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
}
2008-02-05 14:54:19 +03:00
2002-11-02 06:47:48 +03:00
/* FIX ME: check if the value is really changed --metze */
2008-02-11 23:09:21 +03:00
if ( ! pdb_set_acct_ctrl ( pwd , id16 - > acct_flags , PDB_CHANGED ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-09-29 17:08:26 +04:00
return False ;
}
2001-02-27 21:22:39 +03:00
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( pdb_update_sam_account ( pwd ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
2001-05-04 19:44:27 +04:00
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return True ;
}
/*******************************************************************
2005-07-19 04:59:25 +04:00
set_user_info_18
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static bool set_user_info_18 ( struct samr_UserInfo18 * id18 ,
struct samu * pwd )
2001-02-27 21:22:39 +03:00
{
2005-07-19 04:59:25 +04:00
if ( id18 = = NULL ) {
DEBUG ( 2 , ( " set_user_info_18: id18 is NULL \n " ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
}
2008-02-05 14:54:19 +03:00
2008-02-11 23:09:21 +03:00
if ( ! pdb_set_lanman_passwd ( pwd , id18 - > lm_pwd . hash , PDB_CHANGED ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-09-29 17:08:26 +04:00
return False ;
}
2008-02-11 23:09:21 +03:00
if ( ! pdb_set_nt_passwd ( pwd , id18 - > nt_pwd . hash , PDB_CHANGED ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-09-29 17:08:26 +04:00
return False ;
}
2006-10-03 21:14:18 +04:00
if ( ! pdb_set_pass_last_set_time ( pwd , time ( NULL ) , PDB_CHANGED ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2008-02-05 14:54:19 +03:00
return False ;
2001-10-29 10:15:51 +03:00
}
2008-02-05 14:54:19 +03:00
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( pdb_update_sam_account ( pwd ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
2001-05-04 19:44:27 +04:00
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return True ;
}
2003-11-07 21:32:23 +03:00
/*******************************************************************
set_user_info_20
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static bool set_user_info_20 ( struct samr_UserInfo20 * id20 ,
struct samu * pwd )
2003-11-07 21:32:23 +03:00
{
if ( id20 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_20: NULL id20 \n " ) ) ;
return False ;
}
2008-02-05 14:54:19 +03:00
2003-11-07 21:32:23 +03:00
copy_id20_to_sam_passwd ( pwd , id20 ) ;
/* write the change out */
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( pdb_update_sam_account ( pwd ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2003-11-07 21:32:23 +03:00
return False ;
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2003-11-07 21:32:23 +03:00
return True ;
}
2008-02-11 23:09:21 +03:00
2001-02-27 21:22:39 +03:00
/*******************************************************************
set_user_info_21
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static NTSTATUS set_user_info_21 ( TALLOC_CTX * mem_ctx ,
struct samr_UserInfo21 * id21 ,
2006-02-20 23:09:36 +03:00
struct samu * pwd )
2001-02-27 21:22:39 +03:00
{
2006-02-13 20:08:25 +03:00
NTSTATUS status ;
2008-02-05 14:54:19 +03:00
2001-02-27 21:22:39 +03:00
if ( id21 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_21: NULL id21 \n " ) ) ;
2006-02-13 20:08:25 +03:00
return NT_STATUS_INVALID_PARAMETER ;
2001-02-27 21:22:39 +03:00
}
2006-02-22 13:28:02 +03:00
/* we need to separately check for an account rename first */
2008-02-05 14:54:19 +03:00
2008-02-11 23:09:21 +03:00
if ( id21 - > account_name . string & &
( ! strequal ( id21 - > account_name . string , pdb_get_username ( pwd ) ) ) )
2006-07-11 22:01:26 +04:00
{
2006-02-22 13:28:02 +03:00
/* check to see if the new username already exists. Note: we can't
2008-02-05 14:54:19 +03:00
reliably lock all backends , so there is potentially the
2006-02-22 13:28:02 +03:00
possibility that a user can be created in between this check and
the rename . The rename should fail , but may not get the
exact same failure status code . I think this is small enough
of a window for this type of operation and the results are
simply that the rename fails with a slightly different status
code ( like UNSUCCESSFUL instead of ALREADY_EXISTS ) . */
2008-02-11 23:09:21 +03:00
status = can_create ( mem_ctx , id21 - > account_name . string ) ;
2006-02-22 13:28:02 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2008-02-11 23:09:21 +03:00
status = pdb_rename_sam_account ( pwd , id21 - > account_name . string ) ;
2006-02-22 13:28:02 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-05 14:54:19 +03:00
DEBUG ( 0 , ( " set_user_info_21: failed to rename account: %s \n " ,
2006-02-22 13:28:02 +03:00
nt_errstr ( status ) ) ) ;
TALLOC_FREE ( pwd ) ;
return status ;
}
2008-02-05 14:54:19 +03:00
/* set the new username so that later
2006-02-22 13:28:02 +03:00
functions can work on the new account */
2008-02-11 23:09:21 +03:00
pdb_set_username ( pwd , id21 - > account_name . string , PDB_SET ) ;
2006-02-22 13:28:02 +03:00
}
2008-02-12 00:47:49 +03:00
copy_id21_to_sam_passwd ( " INFO_21 " , pwd , id21 ) ;
2008-02-05 14:54:19 +03:00
2001-03-11 03:32:10 +03:00
/*
* The funny part about the previous two calls is
* that pwd still has the password hashes from the
* passdb entry . These have not been updated from
* id21 . I don ' t know if they need to be set . - - jerry
*/
2008-02-05 14:54:19 +03:00
2006-02-25 00:36:40 +03:00
if ( IS_SAM_CHANGED ( pwd , PDB_GROUPSID ) ) {
status = pdb_set_unix_primary_group ( mem_ctx , pwd ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2006-02-13 20:08:25 +03:00
}
2008-02-05 14:54:19 +03:00
2006-02-25 00:36:40 +03:00
/* Don't worry about writing out the user account since the
2008-02-05 14:54:19 +03:00
primary group SID is generated solely from the user ' s Unix
2006-02-25 00:36:40 +03:00
primary group . */
2001-05-04 19:44:27 +04:00
2006-02-27 17:45:27 +03:00
/* write the change out */
if ( ! NT_STATUS_IS_OK ( status = pdb_update_sam_account ( pwd ) ) ) {
TALLOC_FREE ( pwd ) ;
return status ;
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-05-04 19:44:27 +04:00
2006-02-13 20:08:25 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
set_user_info_23
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static NTSTATUS set_user_info_23 ( TALLOC_CTX * mem_ctx ,
struct samr_UserInfo23 * id23 ,
2006-02-20 23:09:36 +03:00
struct samu * pwd )
2001-02-27 21:22:39 +03:00
{
2007-11-13 02:02:50 +03:00
char * plaintext_buf = NULL ;
uint32 len = 0 ;
2001-03-11 03:32:10 +03:00
uint16 acct_ctrl ;
2006-02-13 20:08:25 +03:00
NTSTATUS status ;
2007-11-13 02:02:50 +03:00
2001-05-04 19:44:27 +04:00
if ( id23 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_23: NULL id23 \n " ) ) ;
2006-02-13 20:08:25 +03:00
return NT_STATUS_INVALID_PARAMETER ;
2001-05-04 19:44:27 +04:00
}
2007-11-13 02:02:50 +03:00
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
DEBUG ( 5 , ( " Attempting administrator password change (level 23) for user %s \n " ,
pdb_get_username ( pwd ) ) ) ;
2001-05-04 19:44:27 +04:00
acct_ctrl = pdb_get_acct_ctrl ( pwd ) ;
2007-11-13 02:02:50 +03:00
if ( ! decode_pw_buffer ( mem_ctx ,
2008-02-11 23:09:21 +03:00
id23 - > password . data ,
2007-11-13 02:02:50 +03:00
& plaintext_buf ,
& len ,
STR_UNICODE ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-13 20:08:25 +03:00
return NT_STATUS_INVALID_PARAMETER ;
2001-05-04 19:44:27 +04:00
}
2007-11-13 02:02:50 +03:00
2001-11-24 03:36:37 +03:00
if ( ! pdb_set_plaintext_passwd ( pwd , plaintext_buf ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-13 20:08:25 +03:00
return NT_STATUS_ACCESS_DENIED ;
2001-09-29 17:08:26 +04:00
}
2007-11-13 02:02:50 +03:00
2002-09-26 22:37:55 +04:00
copy_id23_to_sam_passwd ( pwd , id23 ) ;
2007-11-13 02:02:50 +03:00
2001-02-27 21:22:39 +03:00
/* if it's a trust account, don't update /etc/passwd */
2003-05-12 22:12:31 +04:00
if ( ( ( acct_ctrl & ACB_DOMTRUST ) = = ACB_DOMTRUST ) | |
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
( ( acct_ctrl & ACB_WSTRUST ) = = ACB_WSTRUST ) | |
( ( acct_ctrl & ACB_SVRTRUST ) = = ACB_SVRTRUST ) ) {
2006-07-20 00:59:04 +04:00
DEBUG ( 5 , ( " Changing trust account. Not updating /etc/passwd \n " ) ) ;
2001-03-11 03:32:10 +03:00
} else {
2001-02-27 21:22:39 +03:00
/* update the UNIX password */
2004-02-02 03:08:35 +03:00
if ( lp_unix_password_sync ( ) ) {
2006-06-20 13:16:53 +04:00
struct passwd * passwd ;
if ( pdb_get_username ( pwd ) = = NULL ) {
DEBUG ( 1 , ( " chgpasswd: User without name??? \n " ) ) ;
TALLOC_FREE ( pwd ) ;
return NT_STATUS_ACCESS_DENIED ;
}
2007-12-19 17:02:59 +03:00
passwd = Get_Pwnam_alloc ( pwd , pdb_get_username ( pwd ) ) ;
if ( passwd = = NULL ) {
2004-02-02 03:08:35 +03:00
DEBUG ( 1 , ( " chgpasswd: Username does not exist in system !?! \n " ) ) ;
}
2007-11-13 02:02:50 +03:00
2004-02-02 03:08:35 +03:00
if ( ! chgpasswd ( pdb_get_username ( pwd ) , passwd , " " , plaintext_buf , True ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-13 20:08:25 +03:00
return NT_STATUS_ACCESS_DENIED ;
2001-05-04 19:44:27 +04:00
}
2007-12-19 17:02:59 +03:00
TALLOC_FREE ( passwd ) ;
2004-02-02 03:08:35 +03:00
}
2001-02-27 21:22:39 +03:00
}
2007-11-13 02:02:50 +03:00
memset ( plaintext_buf , ' \0 ' , strlen ( plaintext_buf ) ) ;
2006-02-13 20:08:25 +03:00
if ( IS_SAM_CHANGED ( pwd , PDB_GROUPSID ) & &
( ! NT_STATUS_IS_OK ( status = pdb_set_unix_primary_group ( mem_ctx ,
pwd ) ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-13 20:08:25 +03:00
return status ;
}
2003-06-12 00:42:10 +04:00
2006-02-13 20:08:25 +03:00
if ( ! NT_STATUS_IS_OK ( status = pdb_update_sam_account ( pwd ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2006-02-13 20:08:25 +03:00
return status ;
2001-05-04 19:44:27 +04:00
}
2007-11-13 02:02:50 +03:00
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-05-04 19:44:27 +04:00
2006-02-13 20:08:25 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*******************************************************************
2001-06-20 23:55:59 +04:00
set_user_info_pw
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool set_user_info_pw ( uint8 * pass , struct samu * pwd )
2001-02-27 21:22:39 +03:00
{
2007-11-13 02:02:50 +03:00
uint32 len = 0 ;
char * plaintext_buf = NULL ;
2006-02-27 13:32:45 +03:00
uint32 acct_ctrl ;
2007-06-27 00:09:41 +04:00
time_t last_set_time ;
enum pdb_value_state last_set_state ;
2007-11-13 02:02:50 +03:00
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
DEBUG ( 5 , ( " Attempting administrator password change for user %s \n " ,
pdb_get_username ( pwd ) ) ) ;
2001-03-11 03:32:10 +03:00
acct_ctrl = pdb_get_acct_ctrl ( pwd ) ;
2007-06-27 00:09:41 +04:00
/* we need to know if it's expired, because this is an admin change, not a
user change , so it ' s still expired when we ' re done */
last_set_state = pdb_get_init_flags ( pwd , PDB_PASSLASTSET ) ;
last_set_time = pdb_get_pass_last_set_time ( pwd ) ;
2001-02-27 21:22:39 +03:00
2007-11-13 02:02:50 +03:00
if ( ! decode_pw_buffer ( talloc_tos ( ) ,
pass ,
& plaintext_buf ,
& len ,
STR_UNICODE ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
2001-05-04 19:44:27 +04:00
}
2001-09-29 17:08:26 +04:00
if ( ! pdb_set_plaintext_passwd ( pwd , plaintext_buf ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-09-29 17:08:26 +04:00
return False ;
}
2007-11-13 02:02:50 +03:00
2001-02-27 21:22:39 +03:00
/* if it's a trust account, don't update /etc/passwd */
2003-05-12 22:12:31 +04:00
if ( ( ( acct_ctrl & ACB_DOMTRUST ) = = ACB_DOMTRUST ) | |
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
( ( acct_ctrl & ACB_WSTRUST ) = = ACB_WSTRUST ) | |
( ( acct_ctrl & ACB_SVRTRUST ) = = ACB_SVRTRUST ) ) {
DEBUG ( 5 , ( " Changing trust account or non-unix-user password, not updating /etc/passwd \n " ) ) ;
2001-02-27 21:22:39 +03:00
} else {
/* update the UNIX password */
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
if ( lp_unix_password_sync ( ) ) {
2006-06-20 13:16:53 +04:00
struct passwd * passwd ;
if ( pdb_get_username ( pwd ) = = NULL ) {
DEBUG ( 1 , ( " chgpasswd: User without name??? \n " ) ) ;
TALLOC_FREE ( pwd ) ;
return False ;
}
2007-12-19 17:02:59 +03:00
passwd = Get_Pwnam_alloc ( pwd , pdb_get_username ( pwd ) ) ;
if ( passwd = = NULL ) {
2004-02-02 03:08:35 +03:00
DEBUG ( 1 , ( " chgpasswd: Username does not exist in system !?! \n " ) ) ;
}
2007-11-13 02:02:50 +03:00
2004-02-02 03:08:35 +03:00
if ( ! chgpasswd ( pdb_get_username ( pwd ) , passwd , " " , plaintext_buf , True ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-02-27 21:22:39 +03:00
return False ;
2001-05-04 19:44:27 +04:00
}
2007-12-19 17:02:59 +03:00
TALLOC_FREE ( passwd ) ;
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
}
2001-02-27 21:22:39 +03:00
}
2007-11-13 02:02:50 +03:00
memset ( plaintext_buf , ' \0 ' , strlen ( plaintext_buf ) ) ;
2007-06-27 00:09:41 +04:00
/* restore last set time as this is an admin change, not a user pw change */
pdb_set_pass_last_set_time ( pwd , last_set_time , last_set_state ) ;
2007-11-13 02:02:50 +03:00
This is another *BIG* change...
Samba now features a pluggable passdb interface, along the same lines as the
one in use in the auth subsystem. In this case, only one backend may be active
at a time by the 'normal' interface, and only one backend per passdb_context is
permitted outside that.
This pluggable interface is designed to allow any number of passdb backends to
be compiled in, with the selection at runtime. The 'passdb backend' paramater
has been created (and documented!) to support this.
As such, configure has been modfied to allow (for example) --with-ldap and the
old smbpasswd to be selected at the same time.
This patch also introduces two new backends: smbpasswd_nua and tdbsam_nua.
These two backends accept 'non unix accounts', where the user does *not* exist
in /etc/passwd. These accounts' don't have UIDs in the unix sense, but to
avoid conflicts in the algroitmic mapping of RIDs, they use the values
specified in the 'non unix account range' paramter - in the same way as the
winbind ranges are specifed.
While I was at it, I cleaned up some of the code in pdb_tdb (code copied
directly from smbpasswd and not really considered properly). Most of this was
to do with % macro expansion on stored data. It isn't easy to get the macros
into the tdb, and the first password change will 'expand' them. tdbsam needs
to use a similar system to pdb_ldap in this regard.
This patch only makes minor adjustments to pdb_nisplus and pdb_ldap, becouse I
don't have the test facilities for these. I plan to incoroprate at least
pdb_ldap into this scheme after consultation with Jerry.
Each (converted) passdb module now no longer has any 'static' variables, and
only exports 1 init function outside its .c file.
The non-unix-account support in this patch has been proven! It is now possible
to join a win2k machine to a Samba PDC without an account in /etc/passwd!
Other changes:
Minor interface adjustments:
pdb_delete_sam_account() now takes a SAM_ACCOUNT, not a char*.
pdb_update_sam_account() no longer takes the 'override' argument that was being
ignored so often (every other passdb backend). Extra checks have been added in
some places.
Minor code changes:
smbpasswd no longer attempts to initialise the passdb at startup, this is
now done on first use.
pdbedit has lost some of its 'machine account' logic, as this behaviour is now
controlled by the passdb subsystem directly.
The samr subsystem no longer calls 'local password change', but does the pdb
interactions directly. This allow the ACB_ flags specifed to be transferred
direct to the backend, without interference.
Doco:
I've updated the doco to reflect some of the changes, and removed some paramters
no longer applicable to HEAD.
(This used to be commit ff354c99c585068af6dc1ff35a1f109a806b326b)
2002-01-20 17:30:58 +03:00
DEBUG ( 5 , ( " set_user_info_pw: pdb_update_pwd() \n " ) ) ;
2007-11-13 02:02:50 +03:00
2001-05-04 19:44:27 +04:00
/* update the SAMBA password */
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( pdb_update_sam_account ( pwd ) ) ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-05-04 19:44:27 +04:00
return False ;
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2001-05-04 19:44:27 +04:00
return True ;
2001-02-27 21:22:39 +03:00
}
2006-06-06 18:18:12 +04:00
/*******************************************************************
set_user_info_25
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
static NTSTATUS set_user_info_25 ( TALLOC_CTX * mem_ctx ,
struct samr_UserInfo25 * id25 ,
2006-06-06 18:18:12 +04:00
struct samu * pwd )
{
NTSTATUS status ;
2008-02-05 14:54:19 +03:00
2006-06-06 18:18:12 +04:00
if ( id25 = = NULL ) {
DEBUG ( 5 , ( " set_user_info_25: NULL id25 \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
copy_id25_to_sam_passwd ( pwd , id25 ) ;
2008-02-05 14:54:19 +03:00
2006-08-01 18:46:08 +04:00
/* write the change out */
if ( ! NT_STATUS_IS_OK ( status = pdb_update_sam_account ( pwd ) ) ) {
TALLOC_FREE ( pwd ) ;
return status ;
}
2006-06-06 18:18:12 +04:00
/*
2006-08-01 18:46:08 +04:00
* We need to " pdb_update_sam_account " before the unix primary group
* is set , because the idealx scripts would also change the
* sambaPrimaryGroupSid using the ldap replace method . pdb_ldap uses
* the delete explicit / add explicit , which would then fail to find
* the previous primaryGroupSid value .
2006-06-06 18:18:12 +04:00
*/
2006-08-01 18:46:08 +04:00
2006-06-06 18:18:12 +04:00
if ( IS_SAM_CHANGED ( pwd , PDB_GROUPSID ) ) {
status = pdb_set_unix_primary_group ( mem_ctx , pwd ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
}
2008-02-05 14:54:19 +03:00
2006-06-06 18:18:12 +04:00
/* WARNING: No TALLOC_FREE(pwd), we are about to set the password
* hereafter ! */
return NT_STATUS_OK ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2008-02-12 04:10:40 +03:00
samr_SetUserInfo_internal
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-12 04:10:40 +03:00
static NTSTATUS samr_SetUserInfo_internal ( const char * fn_name ,
pipes_struct * p ,
struct policy_handle * user_handle ,
uint16_t level ,
union samr_UserInfo * info )
2001-02-27 21:22:39 +03:00
{
2008-02-11 23:09:21 +03:00
NTSTATUS status ;
2006-02-20 23:09:36 +03:00
struct samu * pwd = NULL ;
2001-02-27 21:22:39 +03:00
DOM_SID sid ;
2008-02-12 04:10:40 +03:00
POLICY_HND * pol = user_handle ;
uint16_t switch_value = level ;
uint32_t acc_granted ;
uint32_t acc_required ;
2007-10-19 04:40:25 +04:00
bool ret ;
bool has_enough_rights = False ;
2008-02-12 04:10:40 +03:00
uint32_t acb_info ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-02-27 21:22:39 +03:00
2008-02-12 04:10:40 +03:00
DEBUG ( 5 , ( " %s: %d \n " , fn_name , __LINE__ ) ) ;
2001-02-27 21:22:39 +03:00
/* find the policy handle. open a policy on it. */
2008-02-12 04:10:40 +03:00
if ( ! get_lsa_policy_samr_sid ( p , pol , & sid , & acc_granted , & disp_info ) ) {
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-12 04:10:40 +03:00
}
2005-01-07 02:27:28 +03:00
2008-02-05 14:54:19 +03:00
/* This is tricky. A WinXP domain join sets
2006-07-20 00:59:04 +04:00
( SA_RIGHT_USER_SET_PASSWORD | SA_RIGHT_USER_SET_ATTRIBUTES | SA_RIGHT_USER_ACCT_FLAGS_EXPIRY )
2008-02-05 14:54:19 +03:00
The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser ( ) . But the
standard Win32 API calls just ask for SA_RIGHT_USER_SET_PASSWORD in the SamrOpenUser ( ) .
This should be enough for levels 18 , 24 , 25 , & 26. Info level 23 can set more so
2006-07-20 00:59:04 +04:00
we ' ll use the set from the WinXP join as the basis . */
2008-02-05 14:54:19 +03:00
2006-07-20 00:59:04 +04:00
switch ( switch_value ) {
case 18 :
case 24 :
case 25 :
case 26 :
acc_required = SA_RIGHT_USER_SET_PASSWORD ;
break ;
default :
2008-02-12 04:10:40 +03:00
acc_required = SA_RIGHT_USER_SET_PASSWORD |
SA_RIGHT_USER_SET_ATTRIBUTES |
SA_RIGHT_USER_ACCT_FLAGS_EXPIRY ;
2006-07-20 00:59:04 +04:00
break ;
}
2008-02-05 14:54:19 +03:00
2008-02-11 23:09:21 +03:00
status = access_check_samr_function ( acc_granted ,
acc_required ,
2008-02-12 04:10:40 +03:00
fn_name ) ;
2008-02-11 23:09:21 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2005-09-30 21:13:37 +04:00
2008-02-12 04:10:40 +03:00
DEBUG ( 5 , ( " %s: sid:%s, level:%d \n " ,
fn_name , sid_string_dbg ( & sid ) , switch_value ) ) ;
2001-02-27 21:22:39 +03:00
2008-02-11 23:09:21 +03:00
if ( info = = NULL ) {
2008-02-12 04:10:40 +03:00
DEBUG ( 5 , ( " %s: NULL info level \n " , fn_name ) ) ;
2001-02-27 21:22:39 +03:00
return NT_STATUS_INVALID_INFO_CLASS ;
}
2008-02-05 14:54:19 +03:00
2008-02-12 04:10:40 +03:00
if ( ! ( pwd = samu_new ( NULL ) ) ) {
2006-02-21 17:34:11 +03:00
return NT_STATUS_NO_MEMORY ;
}
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
become_root ( ) ;
ret = pdb_getsampwsid ( pwd , & sid ) ;
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-12 04:10:40 +03:00
if ( ! ret ) {
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( pwd ) ;
2005-01-26 23:36:44 +03:00
return NT_STATUS_NO_SUCH_USER ;
}
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
/* deal with machine password changes differently from userinfo changes */
/* check to see if we have the sufficient rights */
2008-02-05 14:54:19 +03:00
2005-02-03 19:23:49 +03:00
acb_info = pdb_get_acct_ctrl ( pwd ) ;
2008-02-12 04:10:40 +03:00
if ( acb_info & ACB_WSTRUST )
has_enough_rights = user_has_privileges ( p - > pipe_user . nt_user_token ,
& se_machine_account ) ;
else if ( acb_info & ACB_NORMAL )
has_enough_rights = user_has_privileges ( p - > pipe_user . nt_user_token ,
& se_add_users ) ;
else if ( acb_info & ( ACB_SVRTRUST | ACB_DOMTRUST ) ) {
if ( lp_enable_privileges ( ) ) {
has_enough_rights = nt_token_check_domain_rid ( p - > pipe_user . nt_user_token ,
DOMAIN_GROUP_RID_ADMINS ) ;
}
2005-02-03 19:23:49 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-12 04:10:40 +03:00
DEBUG ( 5 , ( " %s: %s does%s possess sufficient rights \n " ,
fn_name ,
2006-07-11 22:01:26 +04:00
uidtoname ( p - > pipe_user . ut . uid ) ,
has_enough_rights ? " " : " not " ) ) ;
2005-01-07 02:27:28 +03:00
2005-01-13 21:20:37 +03:00
/* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
2008-02-05 14:54:19 +03:00
2008-02-12 04:10:40 +03:00
if ( has_enough_rights ) {
2008-02-05 14:54:19 +03:00
become_root ( ) ;
2008-02-12 04:10:40 +03:00
}
2008-02-05 14:54:19 +03:00
2001-02-27 21:22:39 +03:00
/* ok! user info levels (lots: see MSDEV help), off we go... */
2005-01-07 02:27:28 +03:00
2001-02-27 21:22:39 +03:00
switch ( switch_value ) {
2008-02-12 04:10:40 +03:00
case 7 :
status = set_user_info_7 ( p - > mem_ctx ,
& info - > info7 , pwd ) ;
break ;
case 16 :
if ( ! set_user_info_16 ( & info - > info16 , pwd ) ) {
status = NT_STATUS_ACCESS_DENIED ;
}
break ;
2005-01-26 23:36:44 +03:00
case 18 :
2008-02-12 04:10:40 +03:00
/* Used by AS/U JRA. */
if ( ! set_user_info_18 ( & info - > info18 , pwd ) ) {
status = NT_STATUS_ACCESS_DENIED ;
}
break ;
case 20 :
if ( ! set_user_info_20 ( & info - > info20 , pwd ) ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_ACCESS_DENIED ;
2008-02-12 04:10:40 +03:00
}
break ;
case 21 :
status = set_user_info_21 ( p - > mem_ctx ,
& info - > info21 , pwd ) ;
break ;
case 23 :
if ( ! p - > session_key . length ) {
status = NT_STATUS_NO_USER_SESSION_KEY ;
}
SamOEMhashBlob ( info - > info23 . password . data , 516 ,
& p - > session_key ) ;
dump_data ( 100 , info - > info23 . password . data , 516 ) ;
status = set_user_info_23 ( p - > mem_ctx ,
& info - > info23 , pwd ) ;
2001-02-27 21:22:39 +03:00
break ;
case 24 :
2003-11-23 03:04:29 +03:00
if ( ! p - > session_key . length ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_NO_USER_SESSION_KEY ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2008-02-11 23:09:21 +03:00
SamOEMhashBlob ( info - > info24 . password . data ,
516 ,
& p - > session_key ) ;
2001-06-20 23:55:59 +04:00
2008-02-11 23:09:21 +03:00
dump_data ( 100 , info - > info24 . password . data , 516 ) ;
2001-06-20 23:55:59 +04:00
2008-02-12 04:10:40 +03:00
if ( ! set_user_info_pw ( info - > info24 . password . data , pwd ) ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_ACCESS_DENIED ;
2008-02-12 04:10:40 +03:00
}
2001-02-27 21:22:39 +03:00
break ;
2001-06-20 23:55:59 +04:00
case 25 :
2003-11-23 03:04:29 +03:00
if ( ! p - > session_key . length ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_NO_USER_SESSION_KEY ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2008-02-12 04:10:40 +03:00
encode_or_decode_arc4_passwd_buffer ( info - > info25 . password . data ,
& p - > session_key ) ;
2001-06-20 23:55:59 +04:00
2008-02-11 23:09:21 +03:00
dump_data ( 100 , info - > info25 . password . data , 532 ) ;
2001-06-20 23:55:59 +04:00
2008-02-11 23:09:21 +03:00
status = set_user_info_25 ( p - > mem_ctx ,
& info - > info25 , pwd ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-06-06 18:18:12 +04:00
goto done ;
}
2008-02-12 04:10:40 +03:00
if ( ! set_user_info_pw ( info - > info25 . password . data , pwd ) ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_ACCESS_DENIED ;
2008-02-12 04:10:40 +03:00
}
2001-06-20 23:55:59 +04:00
break ;
2006-02-09 01:16:03 +03:00
case 26 :
if ( ! p - > session_key . length ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_NO_USER_SESSION_KEY ;
2006-02-09 01:16:03 +03:00
}
2008-02-12 04:10:40 +03:00
encode_or_decode_arc4_passwd_buffer ( info - > info26 . password . data ,
& p - > session_key ) ;
2006-02-09 01:16:03 +03:00
2008-02-11 23:09:21 +03:00
dump_data ( 100 , info - > info26 . password . data , 516 ) ;
2006-02-09 01:16:03 +03:00
2008-02-12 04:10:40 +03:00
if ( ! set_user_info_pw ( info - > info26 . password . data , pwd ) ) {
2008-02-11 23:09:21 +03:00
status = NT_STATUS_ACCESS_DENIED ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2001-02-27 21:22:39 +03:00
break ;
default :
2008-02-11 23:09:21 +03:00
status = NT_STATUS_INVALID_INFO_CLASS ;
2001-02-27 21:22:39 +03:00
}
2006-06-06 18:18:12 +04:00
done :
2008-02-05 14:54:19 +03:00
2008-02-12 04:10:40 +03:00
if ( has_enough_rights ) {
2005-01-07 02:27:28 +03:00
unbecome_root ( ) ;
2008-02-12 04:10:40 +03:00
}
2008-02-05 14:54:19 +03:00
2005-01-13 21:20:37 +03:00
/* ================ END SeMachineAccountPrivilege BLOCK ================ */
2005-01-07 02:27:28 +03:00
2008-02-11 23:09:21 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
}
2008-02-11 23:09:21 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
2008-02-12 04:10:40 +03:00
/*******************************************************************
_samr_SetUserInfo
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_SetUserInfo ( pipes_struct * p ,
struct samr_SetUserInfo * r )
{
return samr_SetUserInfo_internal ( " _samr_SetUserInfo " ,
p ,
r - > in . user_handle ,
r - > in . level ,
r - > in . info ) ;
}
2001-02-27 21:22:39 +03:00
/*******************************************************************
2008-02-11 23:09:21 +03:00
_samr_SetUserInfo2
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-11 23:09:21 +03:00
NTSTATUS _samr_SetUserInfo2 ( pipes_struct * p ,
struct samr_SetUserInfo2 * r )
2001-02-27 21:22:39 +03:00
{
2008-02-12 04:10:40 +03:00
return samr_SetUserInfo_internal ( " _samr_SetUserInfo2 " ,
p ,
r - > in . user_handle ,
r - > in . level ,
r - > in . info ) ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 04:04:56 +03:00
_samr_GetAliasMembership
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 04:04:56 +03:00
NTSTATUS _samr_GetAliasMembership ( pipes_struct * p ,
struct samr_GetAliasMembership * r )
2001-02-27 21:22:39 +03:00
{
2005-10-18 07:24:00 +04:00
size_t num_alias_rids ;
2005-03-27 20:33:04 +04:00
uint32 * alias_rids ;
2001-12-05 18:41:44 +03:00
struct samr_info * info = NULL ;
2005-10-18 07:24:00 +04:00
size_t i ;
2008-02-05 14:54:19 +03:00
2002-09-26 22:37:55 +04:00
NTSTATUS ntstatus1 ;
NTSTATUS ntstatus2 ;
2004-11-06 02:34:00 +03:00
DOM_SID * members ;
2001-03-23 03:50:31 +03:00
2008-02-05 04:04:56 +03:00
DEBUG ( 5 , ( " _samr_GetAliasMembership: %d \n " , __LINE__ ) ) ;
2001-03-23 03:50:31 +03:00
2001-12-05 18:41:44 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 04:04:56 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , ( void * * ) ( void * ) & info ) )
2001-12-05 18:41:44 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 04:04:56 +03:00
2008-02-08 21:42:23 +03:00
ntstatus1 = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_DOMAIN_LOOKUP_ALIAS_BY_MEM ,
" _samr_GetAliasMembership " ) ;
ntstatus2 = access_check_samr_function ( info - > acc_granted ,
SA_RIGHT_DOMAIN_OPEN_ACCOUNT ,
" _samr_GetAliasMembership " ) ;
2008-02-05 04:04:56 +03:00
2002-09-26 22:37:55 +04:00
if ( ! NT_STATUS_IS_OK ( ntstatus1 ) | | ! NT_STATUS_IS_OK ( ntstatus2 ) ) {
if ( ! ( NT_STATUS_EQUAL ( ntstatus1 , NT_STATUS_ACCESS_DENIED ) & & NT_STATUS_IS_OK ( ntstatus2 ) ) & &
! ( NT_STATUS_EQUAL ( ntstatus1 , NT_STATUS_ACCESS_DENIED ) & & NT_STATUS_IS_OK ( ntstatus1 ) ) ) {
return ( NT_STATUS_IS_OK ( ntstatus1 ) ) ? ntstatus2 : ntstatus1 ;
}
2008-02-05 14:54:19 +03:00
}
2001-03-23 03:50:31 +03:00
2001-12-05 18:41:44 +03:00
if ( ! sid_check_is_domain ( & info - > sid ) & &
! sid_check_is_builtin ( & info - > sid ) )
return NT_STATUS_OBJECT_TYPE_MISMATCH ;
2008-02-05 04:04:56 +03:00
if ( r - > in . sids - > num_sids ) {
members = TALLOC_ARRAY ( p - > mem_ctx , DOM_SID , r - > in . sids - > num_sids ) ;
2001-12-05 18:41:44 +03:00
2007-04-30 04:53:17 +04:00
if ( members = = NULL )
return NT_STATUS_NO_MEMORY ;
} else {
members = NULL ;
}
2001-12-05 18:41:44 +03:00
2008-02-05 04:04:56 +03:00
for ( i = 0 ; i < r - > in . sids - > num_sids ; i + + )
sid_copy ( & members [ i ] , r - > in . sids - > sids [ i ] . sid ) ;
2001-03-23 03:50:31 +03:00
2005-03-27 20:33:04 +04:00
alias_rids = NULL ;
num_alias_rids = 0 ;
2004-11-06 02:34:00 +03:00
become_root ( ) ;
2006-02-04 01:19:41 +03:00
ntstatus1 = pdb_enum_alias_memberships ( p - > mem_ctx , & info - > sid , members ,
2008-02-05 04:04:56 +03:00
r - > in . sids - > num_sids ,
2006-02-04 01:19:41 +03:00
& alias_rids , & num_alias_rids ) ;
2004-11-06 02:34:00 +03:00
unbecome_root ( ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( ntstatus1 ) ) {
return ntstatus1 ;
}
2001-12-05 18:41:44 +03:00
2008-02-05 04:04:56 +03:00
r - > out . rids - > count = num_alias_rids ;
r - > out . rids - > ids = alias_rids ;
2001-12-05 18:41:44 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 02:29:11 +03:00
_samr_GetMembersInAlias
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 02:29:11 +03:00
NTSTATUS _samr_GetMembersInAlias ( pipes_struct * p ,
struct samr_GetMembersInAlias * r )
2001-02-27 21:22:39 +03:00
{
2006-02-04 01:19:41 +03:00
NTSTATUS status ;
2005-10-18 07:24:00 +04:00
size_t i ;
size_t num_sids = 0 ;
2008-02-05 02:29:11 +03:00
struct lsa_SidPtr * sids = NULL ;
DOM_SID * pdb_sids = NULL ;
2001-03-23 03:50:31 +03:00
DOM_SID alias_sid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2001-03-23 03:50:31 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 02:29:11 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & alias_sid , & acc_granted , NULL ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 02:29:11 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_ALIAS_GET_MEMBERS ,
" _samr_GetMembersInAlias " ) ;
2008-02-05 02:29:11 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-03-23 03:50:31 +03:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & alias_sid ) ) ) ;
2001-03-23 03:50:31 +03:00
2006-07-24 16:05:20 +04:00
become_root ( ) ;
2008-02-05 02:29:11 +03:00
status = pdb_enum_aliasmem ( & alias_sid , & pdb_sids , & num_sids ) ;
2006-07-24 16:05:20 +04:00
unbecome_root ( ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2001-03-23 03:50:31 +03:00
2007-04-30 04:53:17 +04:00
if ( num_sids ) {
2008-02-05 02:29:11 +03:00
sids = TALLOC_ZERO_ARRAY ( p - > mem_ctx , struct lsa_SidPtr , num_sids ) ;
if ( sids = = NULL ) {
TALLOC_FREE ( pdb_sids ) ;
2007-04-30 04:53:17 +04:00
return NT_STATUS_NO_MEMORY ;
}
2004-01-02 08:32:07 +03:00
}
2001-03-23 03:50:31 +03:00
2004-01-02 08:32:07 +03:00
for ( i = 0 ; i < num_sids ; i + + ) {
2008-02-05 02:29:11 +03:00
sids [ i ] . sid = sid_dup_talloc ( p - > mem_ctx , & pdb_sids [ i ] ) ;
if ( ! sids [ i ] . sid ) {
TALLOC_FREE ( pdb_sids ) ;
return NT_STATUS_NO_MEMORY ;
}
2001-03-23 03:50:31 +03:00
}
2008-02-05 02:29:11 +03:00
r - > out . sids - > num_sids = num_sids ;
r - > out . sids - > sids = sids ;
2004-01-02 08:32:07 +03:00
2008-02-05 02:29:11 +03:00
TALLOC_FREE ( pdb_sids ) ;
2001-03-23 03:50:31 +03:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 05:17:12 +03:00
_samr_QueryGroupMember
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 05:17:12 +03:00
NTSTATUS _samr_QueryGroupMember ( pipes_struct * p ,
struct samr_QueryGroupMember * r )
2001-02-27 21:22:39 +03:00
{
2001-03-23 03:50:31 +03:00
DOM_SID group_sid ;
2005-10-18 07:24:00 +04:00
size_t i , num_members ;
2001-03-23 03:50:31 +03:00
uint32 * rid = NULL ;
uint32 * attr = NULL ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2001-03-23 03:50:31 +03:00
2008-02-05 05:17:12 +03:00
NTSTATUS status ;
struct samr_RidTypeArray * rids = NULL ;
rids = TALLOC_ZERO_P ( p - > mem_ctx , struct samr_RidTypeArray ) ;
if ( ! rids ) {
return NT_STATUS_NO_MEMORY ;
}
2005-02-20 16:47:16 +03:00
2001-03-23 03:50:31 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , NULL ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 05:17:12 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_GROUP_GET_MEMBERS ,
" _samr_QueryGroupMember " ) ;
2008-02-05 05:17:12 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 05:17:12 +03:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & group_sid ) ) ) ;
2001-03-23 03:50:31 +03:00
2004-02-16 17:24:35 +03:00
if ( ! sid_check_is_in_our_domain ( & group_sid ) ) {
2007-12-15 23:11:36 +03:00
DEBUG ( 3 , ( " sid %s is not in our domain \n " ,
sid_string_dbg ( & group_sid ) ) ) ;
2001-03-23 03:50:31 +03:00
return NT_STATUS_NO_SUCH_GROUP ;
2004-02-16 17:24:35 +03:00
}
2001-03-23 03:50:31 +03:00
DEBUG ( 10 , ( " lookup on Domain SID \n " ) ) ;
2005-02-20 16:47:16 +03:00
become_root ( ) ;
2008-02-05 05:17:12 +03:00
status = pdb_enum_group_members ( p - > mem_ctx , & group_sid ,
2005-02-20 16:47:16 +03:00
& rid , & num_members ) ;
unbecome_root ( ) ;
2001-03-23 03:50:31 +03:00
2008-02-05 05:17:12 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2001-03-23 03:50:31 +03:00
2007-04-30 05:17:34 +04:00
if ( num_members ) {
attr = TALLOC_ZERO_ARRAY ( p - > mem_ctx , uint32 , num_members ) ;
if ( attr = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
} else {
attr = NULL ;
}
2008-02-05 14:54:19 +03:00
2005-02-20 16:47:16 +03:00
for ( i = 0 ; i < num_members ; i + + )
attr [ i ] = SID_NAME_USER ;
2004-04-07 16:43:44 +04:00
2008-02-05 05:17:12 +03:00
rids - > count = num_members ;
rids - > types = attr ;
rids - > rids = rid ;
* r - > out . rids = rids ;
2001-03-23 03:50:31 +03:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 01:40:19 +03:00
_samr_AddAliasMember
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 01:40:19 +03:00
NTSTATUS _samr_AddAliasMember ( pipes_struct * p ,
struct samr_AddAliasMember * r )
2001-02-27 21:22:39 +03:00
{
2001-03-23 03:50:31 +03:00
DOM_SID alias_sid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2008-02-05 01:40:19 +03:00
NTSTATUS status ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-03-23 03:50:31 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 01:40:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & alias_sid , & acc_granted , & disp_info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 01:40:19 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_ALIAS_ADD_MEMBER ,
" _samr_AddAliasMember " ) ;
2008-02-05 01:40:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 01:40:19 +03:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & alias_sid ) ) ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
2001-11-29 19:05:05 +03:00
2005-01-19 19:52:19 +03:00
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-05 01:40:19 +03:00
status = pdb_add_aliasmem ( & alias_sid , r - > in . sid ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2008-02-05 01:40:19 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
}
2008-02-05 01:40:19 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 01:27:22 +03:00
_samr_DeleteAliasMember
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 01:27:22 +03:00
NTSTATUS _samr_DeleteAliasMember ( pipes_struct * p ,
struct samr_DeleteAliasMember * r )
2001-02-27 21:22:39 +03:00
{
2001-12-10 18:03:16 +03:00
DOM_SID alias_sid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2008-02-05 01:27:22 +03:00
NTSTATUS status ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-12-10 18:03:16 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & alias_sid , & acc_granted , & disp_info ) )
2001-12-10 18:03:16 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_ALIAS_REMOVE_MEMBER ,
" _samr_DeleteAliasMember " ) ;
2008-02-05 01:27:22 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2004-04-07 16:43:44 +04:00
DEBUG ( 10 , ( " _samr_del_aliasmem:sid is %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & alias_sid ) ) ) ;
2001-12-10 18:03:16 +03:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-05 01:27:22 +03:00
status = pdb_del_aliasmem ( & alias_sid , r - > in . sid ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2008-02-05 01:27:22 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
}
2008-02-05 01:27:22 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-04 20:36:44 +03:00
_samr_AddGroupMember
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 20:36:44 +03:00
NTSTATUS _samr_AddGroupMember ( pipes_struct * p ,
struct samr_AddGroupMember * r )
2001-02-27 21:22:39 +03:00
{
2008-02-04 20:36:44 +03:00
NTSTATUS status ;
2001-03-23 03:50:31 +03:00
DOM_SID group_sid ;
2006-02-13 20:08:25 +03:00
uint32 group_rid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-03-23 03:50:31 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-04 20:36:44 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , & disp_info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-04 20:36:44 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_GROUP_ADD_MEMBER ,
" _samr_AddGroupMember " ) ;
2008-02-04 20:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-03-23 03:50:31 +03:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & group_sid ) ) ) ;
2001-03-23 03:50:31 +03:00
2006-02-13 20:08:25 +03:00
if ( ! sid_peek_check_rid ( get_global_sam_sid ( ) , & group_sid ,
& group_rid ) ) {
return NT_STATUS_INVALID_HANDLE ;
2002-11-02 06:47:48 +03:00
}
2001-03-23 03:50:31 +03:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2001-03-23 03:50:31 +03:00
2008-02-04 20:36:44 +03:00
status = pdb_add_groupmem ( p - > mem_ctx , group_rid , r - > in . rid ) ;
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2008-02-04 20:36:44 +03:00
return status ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-04 20:09:35 +03:00
_samr_DeleteGroupMember
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-04 20:09:35 +03:00
NTSTATUS _samr_DeleteGroupMember ( pipes_struct * p ,
struct samr_DeleteGroupMember * r )
2001-02-27 21:22:39 +03:00
{
2008-02-04 20:09:35 +03:00
NTSTATUS status ;
2001-12-10 18:03:16 +03:00
DOM_SID group_sid ;
2006-02-13 20:08:25 +03:00
uint32 group_rid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-12-10 18:03:16 +03:00
/*
2008-02-04 20:09:35 +03:00
* delete the group member named r - > in . rid
2001-12-10 18:03:16 +03:00
* who is a member of the sid associated with the handle
* the rid is a user ' s rid as the group is a domain group .
*/
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , & disp_info ) )
2001-12-10 18:03:16 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_GROUP_REMOVE_MEMBER ,
" _samr_DeleteGroupMember " ) ;
2008-02-04 20:09:35 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-12-10 18:03:16 +03:00
2006-02-13 20:08:25 +03:00
if ( ! sid_peek_check_rid ( get_global_sam_sid ( ) , & group_sid ,
& group_rid ) ) {
return NT_STATUS_INVALID_HANDLE ;
2001-12-10 18:03:16 +03:00
}
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
2001-12-10 18:03:16 +03:00
2005-01-19 19:52:19 +03:00
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-04 20:09:35 +03:00
status = pdb_del_groupmem ( p - > mem_ctx , group_rid , r - > in . rid ) ;
2001-12-10 18:03:16 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2008-02-04 20:09:35 +03:00
return status ;
2002-07-15 14:35:28 +04:00
}
2001-02-27 21:22:39 +03:00
/*********************************************************************
2008-02-01 03:30:50 +03:00
_samr_DeleteUser
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 03:30:50 +03:00
NTSTATUS _samr_DeleteUser ( pipes_struct * p ,
struct samr_DeleteUser * r )
2001-02-27 21:22:39 +03:00
{
2008-02-01 03:30:50 +03:00
NTSTATUS status ;
2001-12-10 18:03:16 +03:00
DOM_SID user_sid ;
2006-02-20 23:09:36 +03:00
struct samu * sam_pass = NULL ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2006-03-02 00:56:59 +03:00
uint32 acb_info ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-12-10 18:03:16 +03:00
2008-02-01 03:30:50 +03:00
DEBUG ( 5 , ( " _samr_DeleteUser: %d \n " , __LINE__ ) ) ;
2001-12-10 18:03:16 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . user_handle , & user_sid , & acc_granted , & disp_info ) )
2001-12-10 18:03:16 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
STD_RIGHT_DELETE_ACCESS ,
" _samr_DeleteUser " ) ;
2008-02-01 03:30:50 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2001-12-10 18:03:16 +03:00
if ( ! sid_check_is_in_our_domain ( & user_sid ) )
return NT_STATUS_CANNOT_DELETE ;
/* check if the user exists before trying to delete */
2006-02-21 17:34:11 +03:00
if ( ! ( sam_pass = samu_new ( NULL ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2006-07-20 00:59:04 +04:00
become_root ( ) ;
ret = pdb_getsampwsid ( sam_pass , & user_sid ) ;
unbecome_root ( ) ;
if ( ! ret ) {
2008-02-05 14:54:19 +03:00
DEBUG ( 5 , ( " _samr_DeleteUser: User %s doesn't exist. \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & user_sid ) ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2001-12-10 18:03:16 +03:00
return NT_STATUS_NO_SUCH_USER ;
}
2008-02-05 14:54:19 +03:00
2006-03-02 00:56:59 +03:00
acb_info = pdb_get_acct_ctrl ( sam_pass ) ;
/* For machine accounts it's the SeMachineAccountPrivilege that counts. */
if ( acb_info & ACB_WSTRUST ) {
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_machine_account ) ;
} else {
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_add_users ) ;
2008-02-05 14:54:19 +03:00
}
2001-12-10 18:03:16 +03:00
2005-01-19 19:52:19 +03:00
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-01 03:30:50 +03:00
status = pdb_delete_user ( p - > mem_ctx , sam_pass ) ;
2006-02-13 20:08:25 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2008-02-01 03:30:50 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 5 , ( " _samr_DeleteUser: Failed to delete entry for "
2006-02-13 20:08:25 +03:00
" user %s: %s. \n " , pdb_get_username ( sam_pass ) ,
2008-02-01 03:30:50 +03:00
nt_errstr ( status ) ) ) ;
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2008-02-01 03:30:50 +03:00
return status ;
2004-09-22 04:33:09 +04:00
}
2006-02-20 23:09:36 +03:00
TALLOC_FREE ( sam_pass ) ;
2001-12-10 18:03:16 +03:00
2008-02-01 03:30:50 +03:00
if ( ! close_policy_hnd ( p , r - > in . user_handle ) )
2001-12-10 18:03:16 +03:00
return NT_STATUS_OBJECT_NAME_INVALID ;
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2001-12-10 18:03:16 +03:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-01 03:31:45 +03:00
_samr_DeleteDomainGroup
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 03:31:45 +03:00
NTSTATUS _samr_DeleteDomainGroup ( pipes_struct * p ,
struct samr_DeleteDomainGroup * r )
2001-02-27 21:22:39 +03:00
{
2008-02-01 03:31:45 +03:00
NTSTATUS status ;
2001-07-09 22:25:40 +04:00
DOM_SID group_sid ;
uint32 group_rid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-07-09 22:25:40 +04:00
2008-02-01 03:31:45 +03:00
DEBUG ( 5 , ( " samr_DeleteDomainGroup: %d \n " , __LINE__ ) ) ;
2001-07-09 22:25:40 +04:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , & disp_info ) )
2001-07-09 22:25:40 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-01 03:31:45 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
STD_RIGHT_DELETE_ACCESS ,
" _samr_DeleteDomainGroup " ) ;
2008-02-01 03:31:45 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-07-09 22:25:40 +04:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & group_sid ) ) ) ;
2001-07-09 22:25:40 +04:00
2006-02-13 20:08:25 +03:00
if ( ! sid_peek_check_rid ( get_global_sam_sid ( ) , & group_sid ,
& group_rid ) ) {
2001-07-09 22:25:40 +04:00
return NT_STATUS_NO_SUCH_GROUP ;
2006-02-13 20:08:25 +03:00
}
2001-07-09 22:25:40 +04:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-01 03:31:45 +03:00
status = pdb_delete_dom_group ( p - > mem_ctx , group_rid ) ;
2001-07-09 22:25:40 +04:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2008-02-01 03:31:45 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 5 , ( " _samr_DeleteDomainGroup: Failed to delete mapping "
2006-02-13 20:08:25 +03:00
" entry for group %s: %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & group_sid ) ,
2008-02-01 03:31:45 +03:00
nt_errstr ( status ) ) ) ;
return status ;
2005-01-19 19:52:19 +03:00
}
2008-02-05 14:54:19 +03:00
2008-02-01 03:31:45 +03:00
if ( ! close_policy_hnd ( p , r - > in . group_handle ) )
2001-07-09 22:25:40 +04:00
return NT_STATUS_OBJECT_NAME_INVALID ;
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-01 03:32:18 +03:00
_samr_DeleteDomAlias
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 03:32:18 +03:00
NTSTATUS _samr_DeleteDomAlias ( pipes_struct * p ,
struct samr_DeleteDomAlias * r )
2001-02-27 21:22:39 +03:00
{
2001-07-09 22:25:40 +04:00
DOM_SID alias_sid ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2007-05-11 12:46:54 +04:00
NTSTATUS status ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-07-09 22:25:40 +04:00
2008-02-01 03:32:18 +03:00
DEBUG ( 5 , ( " _samr_DeleteDomAlias: %d \n " , __LINE__ ) ) ;
2001-07-09 22:25:40 +04:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & alias_sid , & acc_granted , & disp_info ) )
2001-07-09 22:25:40 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2006-03-22 11:04:13 +03:00
/* copy the handle to the outgoing reply */
2008-02-01 03:32:18 +03:00
memcpy ( r - > out . alias_handle , r - > in . alias_handle , sizeof ( r - > out . alias_handle ) ) ;
2006-03-22 11:04:13 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
STD_RIGHT_DELETE_ACCESS ,
" _samr_DeleteDomAlias " ) ;
2008-02-01 03:32:18 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2001-07-09 22:25:40 +04:00
2007-12-15 23:11:36 +03:00
DEBUG ( 10 , ( " sid is %s \n " , sid_string_dbg ( & alias_sid ) ) ) ;
2001-07-09 22:25:40 +04:00
2006-03-22 11:04:13 +03:00
/* Don't let Windows delete builtin groups */
if ( sid_check_is_in_builtin ( & alias_sid ) ) {
return NT_STATUS_SPECIAL_ACCOUNT ;
}
2004-04-07 16:43:44 +04:00
if ( ! sid_check_is_in_our_domain ( & alias_sid ) )
2001-07-09 22:25:40 +04:00
return NT_STATUS_NO_SUCH_ALIAS ;
2008-02-05 14:54:19 +03:00
2001-07-09 22:25:40 +04:00
DEBUG ( 10 , ( " lookup on Local SID \n " ) ) ;
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2004-04-07 16:43:44 +04:00
/* Have passdb delete the alias */
2007-05-11 12:46:54 +04:00
status = pdb_delete_alias ( & alias_sid ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2007-05-11 12:46:54 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2001-07-09 22:25:40 +04:00
2008-02-01 03:32:18 +03:00
if ( ! close_policy_hnd ( p , r - > in . alias_handle ) )
2001-07-09 22:25:40 +04:00
return NT_STATUS_OBJECT_NAME_INVALID ;
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-01 16:49:23 +03:00
_samr_CreateDomainGroup
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 16:49:23 +03:00
NTSTATUS _samr_CreateDomainGroup ( pipes_struct * p ,
struct samr_CreateDomainGroup * r )
2001-02-27 21:22:39 +03:00
{
2008-02-01 16:49:23 +03:00
NTSTATUS status ;
2001-03-23 03:50:31 +03:00
DOM_SID dom_sid ;
DOM_SID info_sid ;
2006-02-13 20:08:25 +03:00
const char * name ;
2001-03-23 03:50:31 +03:00
struct samr_info * info ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-11-29 19:05:05 +03:00
2001-03-23 03:50:31 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & dom_sid , & acc_granted , & disp_info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_DOMAIN_CREATE_GROUP ,
" _samr_CreateDomainGroup " ) ;
2008-02-01 16:49:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sid_equal ( & dom_sid , get_global_sam_sid ( ) ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_ACCESS_DENIED ;
2008-02-01 16:49:23 +03:00
name = r - > in . name - > string ;
2006-02-13 20:08:25 +03:00
if ( name = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2001-03-23 03:50:31 +03:00
2008-02-01 16:49:23 +03:00
status = can_create ( p - > mem_ctx , name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2005-12-03 21:34:13 +03:00
}
2001-03-23 03:50:31 +03:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
2001-03-23 03:50:31 +03:00
2005-01-19 19:52:19 +03:00
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/* check that we successfully create the UNIX group */
2008-02-05 14:54:19 +03:00
2008-02-01 16:49:23 +03:00
status = pdb_create_dom_group ( p - > mem_ctx , name , r - > out . rid ) ;
2001-03-23 03:50:31 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/* check if we should bail out here */
2008-02-05 14:54:19 +03:00
2008-02-01 16:49:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2006-02-13 20:08:25 +03:00
2008-02-01 16:49:23 +03:00
sid_compose ( & info_sid , get_global_sam_sid ( ) , * r - > out . rid ) ;
2008-02-05 14:54:19 +03:00
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & info_sid ) ) = = NULL )
2001-03-23 03:50:31 +03:00
return NT_STATUS_NO_MEMORY ;
2005-05-07 18:55:44 +04:00
/* they created it; let the user do what he wants with it */
info - > acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS ;
2001-03-23 03:50:31 +03:00
/* get a (unique) handle. open a policy on it. */
2008-02-01 16:49:23 +03:00
if ( ! create_policy_hnd ( p , r - > out . group_handle , free_samr_info , ( void * ) info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-01 16:48:42 +03:00
_samr_CreateDomAlias
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 16:48:42 +03:00
NTSTATUS _samr_CreateDomAlias ( pipes_struct * p ,
struct samr_CreateDomAlias * r )
2001-02-27 21:22:39 +03:00
{
2001-03-23 03:50:31 +03:00
DOM_SID dom_sid ;
2002-01-02 10:27:33 +03:00
DOM_SID info_sid ;
2008-02-01 16:48:42 +03:00
const char * name = NULL ;
2001-03-23 03:50:31 +03:00
struct samr_info * info ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2002-09-25 19:19:00 +04:00
gid_t gid ;
2004-04-10 20:09:48 +04:00
NTSTATUS result ;
2005-01-19 19:52:19 +03:00
SE_PRIV se_rights ;
2007-10-19 04:40:25 +04:00
bool can_add_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-11-29 19:05:05 +03:00
2001-03-23 03:50:31 +03:00
/* Find the policy handle. Open a policy on it. */
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & dom_sid , & acc_granted , & disp_info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
result = access_check_samr_function ( acc_granted ,
SA_RIGHT_DOMAIN_CREATE_ALIAS ,
" _samr_CreateDomAlias " ) ;
2008-02-01 16:48:42 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sid_equal ( & dom_sid , get_global_sam_sid ( ) ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_ACCESS_DENIED ;
2008-02-01 16:48:42 +03:00
name = r - > in . alias_name - > string ;
2001-03-23 03:50:31 +03:00
2005-01-19 19:52:19 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
can_add_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_rights ) ;
2005-12-08 22:34:22 +03:00
result = can_create ( p - > mem_ctx , name ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2005-01-19 19:52:19 +03:00
/******** BEGIN SeAddUsers BLOCK *********/
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
become_root ( ) ;
2004-04-07 16:43:44 +04:00
/* Have passdb create the alias */
2008-02-01 16:48:42 +03:00
result = pdb_create_alias ( name , r - > out . rid ) ;
2004-04-10 20:09:48 +04:00
2005-01-19 19:52:19 +03:00
if ( can_add_accounts )
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2005-01-19 19:52:19 +03:00
/******** END SeAddUsers BLOCK *********/
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
DEBUG ( 10 , ( " pdb_create_alias failed: %s \n " ,
nt_errstr ( result ) ) ) ;
2004-04-10 20:09:48 +04:00
return result ;
2006-02-04 01:19:41 +03:00
}
2001-03-23 03:50:31 +03:00
2002-07-15 14:35:28 +04:00
sid_copy ( & info_sid , get_global_sam_sid ( ) ) ;
2008-02-01 16:48:42 +03:00
sid_append_rid ( & info_sid , * r - > out . rid ) ;
2001-03-23 03:50:31 +03:00
2006-02-04 01:19:41 +03:00
if ( ! sid_to_gid ( & info_sid , & gid ) ) {
DEBUG ( 10 , ( " Could not find alias just created \n " ) ) ;
2004-04-07 16:43:44 +04:00
return NT_STATUS_ACCESS_DENIED ;
2006-02-04 01:19:41 +03:00
}
2004-04-07 16:43:44 +04:00
/* check if the group has been successfully created */
2006-02-04 01:19:41 +03:00
if ( getgrgid ( gid ) = = NULL ) {
DEBUG ( 10 , ( " getgrgid(%d) of just created alias failed \n " ,
gid ) ) ;
2001-05-08 20:33:18 +04:00
return NT_STATUS_ACCESS_DENIED ;
2006-02-04 01:19:41 +03:00
}
2001-05-08 20:33:18 +04:00
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & info_sid ) ) = = NULL )
return NT_STATUS_NO_MEMORY ;
2005-05-02 00:05:16 +04:00
/* they created it; let the user do what he wants with it */
info - > acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS ;
2001-03-23 03:50:31 +03:00
/* get a (unique) handle. open a policy on it. */
2008-02-01 16:48:42 +03:00
if ( ! create_policy_hnd ( p , r - > out . alias_handle , free_samr_info , ( void * ) info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-07 15:58:53 +03:00
_samr_QueryGroupInfo
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-07 15:58:53 +03:00
NTSTATUS _samr_QueryGroupInfo ( pipes_struct * p ,
struct samr_QueryGroupInfo * r )
2001-02-27 21:22:39 +03:00
{
2008-02-07 15:58:53 +03:00
NTSTATUS status ;
2001-03-23 03:50:31 +03:00
DOM_SID group_sid ;
GROUP_MAP map ;
2008-02-07 15:58:53 +03:00
union samr_GroupInfo * info = NULL ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2007-10-19 04:40:25 +04:00
bool ret ;
2008-02-07 15:58:53 +03:00
uint32_t attributes = SE_GROUP_MANDATORY |
SE_GROUP_ENABLED_BY_DEFAULT |
SE_GROUP_ENABLED ;
const char * group_name = NULL ;
const char * group_description = NULL ;
2001-03-23 03:50:31 +03:00
2008-02-07 15:58:53 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , NULL ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-07 15:58:53 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_GROUP_LOOKUP_INFO ,
" _samr_QueryGroupInfo " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2003-11-08 02:04:06 +03:00
become_root ( ) ;
2006-08-15 18:07:15 +04:00
ret = get_domain_group_from_sid ( group_sid , & map ) ;
2003-11-08 02:04:06 +03:00
unbecome_root ( ) ;
if ( ! ret )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2001-11-29 19:05:05 +03:00
2008-02-07 15:58:53 +03:00
/* FIXME: map contains fstrings */
group_name = talloc_strdup ( r , map . nt_name ) ;
group_description = talloc_strdup ( r , map . comment ) ;
info = TALLOC_ZERO_P ( p - > mem_ctx , union samr_GroupInfo ) ;
if ( ! info ) {
2001-03-23 03:50:31 +03:00
return NT_STATUS_NO_MEMORY ;
2008-02-07 15:58:53 +03:00
}
2001-03-23 03:50:31 +03:00
2008-02-07 15:58:53 +03:00
switch ( r - > in . level ) {
2006-02-13 20:08:25 +03:00
case 1 : {
uint32 * members ;
size_t num_members ;
become_root ( ) ;
2008-02-07 15:58:53 +03:00
status = pdb_enum_group_members (
2006-02-13 20:08:25 +03:00
p - > mem_ctx , & group_sid , & members , & num_members ) ;
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-07 15:58:53 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2006-02-13 20:08:25 +03:00
}
2008-02-07 15:58:53 +03:00
init_samr_group_info1 ( & info - > all ,
group_name ,
attributes ,
num_members ,
group_description ) ;
2001-03-23 03:50:31 +03:00
break ;
2006-02-13 20:08:25 +03:00
}
2006-03-22 18:00:42 +03:00
case 2 :
2008-02-07 15:58:53 +03:00
init_samr_group_info2 ( & info - > name ,
group_name ) ;
2006-03-22 18:00:42 +03:00
break ;
2001-12-10 18:03:16 +03:00
case 3 :
2008-02-07 15:58:53 +03:00
init_samr_group_info3 ( & info - > attributes ,
attributes ) ;
2001-12-10 18:03:16 +03:00
break ;
2001-03-23 03:50:31 +03:00
case 4 :
2008-02-07 15:58:53 +03:00
init_samr_group_info4 ( & info - > description ,
group_description ) ;
2001-03-23 03:50:31 +03:00
break ;
2006-03-22 18:00:42 +03:00
case 5 : {
/*
uint32 * members ;
size_t num_members ;
*/
/*
become_root ( ) ;
2008-02-07 15:58:53 +03:00
status = pdb_enum_group_members (
2006-03-22 18:00:42 +03:00
p - > mem_ctx , & group_sid , & members , & num_members ) ;
unbecome_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-07 15:58:53 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2006-03-22 18:00:42 +03:00
}
*/
2008-02-07 15:58:53 +03:00
init_samr_group_info5 ( & info - > all2 ,
group_name ,
attributes ,
0 , /* num_members - in w2k3 this is always 0 */
group_description ) ;
2006-03-22 18:00:42 +03:00
break ;
}
2001-03-23 03:50:31 +03:00
default :
return NT_STATUS_INVALID_INFO_CLASS ;
}
2008-02-07 15:58:53 +03:00
* r - > out . info = info ;
2001-03-23 03:50:31 +03:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-06 14:57:59 +03:00
_samr_SetGroupInfo
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-06 14:57:59 +03:00
NTSTATUS _samr_SetGroupInfo ( pipes_struct * p ,
struct samr_SetGroupInfo * r )
2001-02-27 21:22:39 +03:00
{
2001-03-23 03:50:31 +03:00
DOM_SID group_sid ;
GROUP_MAP map ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2008-02-06 14:57:59 +03:00
NTSTATUS status ;
bool ret ;
2007-10-19 04:40:25 +04:00
bool can_mod_accounts ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-03-23 03:50:31 +03:00
2008-02-06 14:57:59 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . group_handle , & group_sid , & acc_granted , & disp_info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-06 14:57:59 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_GROUP_SET_INFO ,
" _samr_SetGroupInfo " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2006-01-26 00:29:36 +03:00
become_root ( ) ;
2008-02-06 14:57:59 +03:00
ret = get_domain_group_from_sid ( group_sid , & map ) ;
2006-01-26 00:29:36 +03:00
unbecome_root ( ) ;
2008-02-06 14:57:59 +03:00
if ( ! ret )
2001-03-23 03:50:31 +03:00
return NT_STATUS_NO_SUCH_GROUP ;
2008-02-05 14:54:19 +03:00
2008-02-06 14:57:59 +03:00
switch ( r - > in . level ) {
2001-03-23 03:50:31 +03:00
case 1 :
2008-02-06 14:57:59 +03:00
fstrcpy ( map . comment , r - > in . info - > all . description . string ) ;
2001-03-23 03:50:31 +03:00
break ;
case 4 :
2008-02-06 14:57:59 +03:00
fstrcpy ( map . comment , r - > in . info - > description . string ) ;
2001-05-08 20:33:18 +04:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
}
2005-09-02 17:42:56 +04:00
can_mod_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_add_users ) ;
2001-11-29 19:05:05 +03:00
2005-09-02 17:42:56 +04:00
/******** BEGIN SeAddUsers BLOCK *********/
if ( can_mod_accounts )
become_root ( ) ;
2008-02-05 14:54:19 +03:00
2008-02-06 14:57:59 +03:00
status = pdb_update_group_mapping_entry ( & map ) ;
2005-09-02 17:42:56 +04:00
if ( can_mod_accounts )
unbecome_root ( ) ;
/******** End SeAddUsers BLOCK *********/
2008-02-06 14:57:59 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
}
2008-02-06 14:57:59 +03:00
return status ;
2001-05-08 20:33:18 +04:00
}
/*********************************************************************
2008-02-06 14:53:43 +03:00
_samr_SetAliasInfo
2001-05-08 20:33:18 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-06 14:53:43 +03:00
NTSTATUS _samr_SetAliasInfo ( pipes_struct * p ,
struct samr_SetAliasInfo * r )
2001-05-08 20:33:18 +04:00
{
DOM_SID group_sid ;
2004-04-07 16:43:44 +04:00
struct acct_info info ;
2002-07-15 14:35:28 +04:00
uint32 acc_granted ;
2007-10-19 04:40:25 +04:00
bool can_mod_accounts ;
2007-05-11 12:46:54 +04:00
NTSTATUS status ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2001-05-08 20:33:18 +04:00
2008-02-06 14:53:43 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . alias_handle , & group_sid , & acc_granted , & disp_info ) )
2001-05-08 20:33:18 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-06 14:53:43 +03:00
status = access_check_samr_function ( acc_granted ,
SA_RIGHT_ALIAS_SET_INFO ,
" _samr_SetAliasInfo " ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2002-07-15 14:35:28 +04:00
}
2008-02-05 14:54:19 +03:00
2006-03-22 11:04:13 +03:00
/* get the current group information */
2006-07-24 16:05:20 +04:00
become_root ( ) ;
2007-05-11 12:46:54 +04:00
status = pdb_get_aliasinfo ( & group_sid , & info ) ;
2006-07-24 16:05:20 +04:00
unbecome_root ( ) ;
2007-05-11 12:46:54 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
2006-03-22 11:04:13 +03:00
2008-02-06 14:53:43 +03:00
switch ( r - > in . level ) {
case ALIASINFONAME :
2006-07-12 00:02:22 +04:00
{
2008-02-06 14:53:43 +03:00
fstring group_name ;
2006-07-12 00:02:22 +04:00
2006-03-22 11:04:13 +03:00
/* We currently do not support renaming groups in the
2008-02-05 14:54:19 +03:00
the BUILTIN domain . Refer to util_builtin . c to understand
2006-03-22 11:04:13 +03:00
why . The eventually needs to be fixed to be like Windows
where you can rename builtin groups , just not delete them */
if ( sid_check_is_in_builtin ( & group_sid ) ) {
return NT_STATUS_SPECIAL_ACCOUNT ;
}
2006-08-24 16:49:18 +04:00
/* There has to be a valid name (and it has to be different) */
2008-02-06 14:53:43 +03:00
if ( ! r - > in . info - > name . string )
2006-07-12 00:02:22 +04:00
return NT_STATUS_INVALID_PARAMETER ;
2006-08-24 16:49:18 +04:00
/* If the name is the same just reply "ok". Yes this
doesn ' t allow you to change the case of a group name . */
2008-02-06 14:53:43 +03:00
if ( strequal ( r - > in . info - > name . string , info . acct_name ) )
2006-08-24 16:49:18 +04:00
return NT_STATUS_OK ;
2006-07-12 00:02:22 +04:00
2008-02-06 14:53:43 +03:00
fstrcpy ( info . acct_name , r - > in . info - > name . string ) ;
2006-09-12 22:02:33 +04:00
2008-02-05 14:54:19 +03:00
/* make sure the name doesn't already exist as a user
2006-07-12 00:02:22 +04:00
or local group */
fstr_sprintf ( group_name , " %s \\ %s " , global_myname ( ) , info . acct_name ) ;
2006-07-12 00:31:13 +04:00
status = can_create ( p - > mem_ctx , group_name ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
2006-07-12 00:31:13 +04:00
return status ;
2006-03-22 11:04:13 +03:00
break ;
2006-07-12 00:02:22 +04:00
}
2008-02-06 14:53:43 +03:00
case ALIASINFODESCRIPTION :
if ( r - > in . info - > description . string ) {
fstrcpy ( info . acct_desc ,
r - > in . info - > description . string ) ;
} else {
2005-12-15 21:39:28 +03:00
fstrcpy ( info . acct_desc , " " ) ;
2008-02-06 14:53:43 +03:00
}
2001-03-23 03:50:31 +03:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
}
2005-09-02 17:42:56 +04:00
can_mod_accounts = user_has_privileges ( p - > pipe_user . nt_user_token , & se_add_users ) ;
2001-11-29 19:05:05 +03:00
2005-09-02 17:42:56 +04:00
/******** BEGIN SeAddUsers BLOCK *********/
if ( can_mod_accounts )
become_root ( ) ;
2007-05-11 12:46:54 +04:00
status = pdb_set_aliasinfo ( & group_sid , & info ) ;
2005-09-02 17:42:56 +04:00
if ( can_mod_accounts )
unbecome_root ( ) ;
/******** End SeAddUsers BLOCK *********/
2007-05-11 12:46:54 +04:00
if ( NT_STATUS_IS_OK ( status ) )
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2007-05-11 12:46:54 +04:00
return status ;
2001-02-27 21:22:39 +03:00
}
2008-01-30 23:55:03 +03:00
/****************************************************************
_samr_GetDomPwInfo
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-02-27 21:22:39 +03:00
2008-01-30 23:55:03 +03:00
NTSTATUS _samr_GetDomPwInfo ( pipes_struct * p ,
struct samr_GetDomPwInfo * r )
2001-02-27 21:22:39 +03:00
{
2002-07-15 14:35:28 +04:00
/* Perform access check. Since this rpc does not require a
policy handle it will not be caught by the access checks on
SAMR_CONNECT or SAMR_CONNECT_ANON . */
if ( ! pipe_access_check ( p ) ) {
2008-01-30 23:55:03 +03:00
DEBUG ( 3 , ( " access denied to _samr_GetDomPwInfo \n " ) ) ;
return NT_STATUS_ACCESS_DENIED ;
2002-07-15 14:35:28 +04:00
}
2001-03-13 03:32:43 +03:00
/* Actually, returning zeros here works quite well :-). */
2008-01-30 23:55:03 +03:00
ZERO_STRUCTP ( r - > out . info ) ;
2002-07-15 14:35:28 +04:00
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-01 02:49:32 +03:00
_samr_OpenGroup
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-01 02:49:32 +03:00
NTSTATUS _samr_OpenGroup ( pipes_struct * p ,
struct samr_OpenGroup * r )
2001-02-27 21:22:39 +03:00
{
2001-03-23 03:50:31 +03:00
DOM_SID sid ;
2002-01-02 10:27:33 +03:00
DOM_SID info_sid ;
2001-03-23 03:50:31 +03:00
GROUP_MAP map ;
struct samr_info * info ;
2002-07-15 14:35:28 +04:00
SEC_DESC * psd = NULL ;
uint32 acc_granted ;
2008-02-01 02:49:32 +03:00
uint32 des_access = r - > in . access_mask ;
2002-07-15 14:35:28 +04:00
size_t sd_size ;
NTSTATUS status ;
2001-03-23 03:50:31 +03:00
fstring sid_string ;
2007-10-19 04:40:25 +04:00
bool ret ;
2005-01-26 23:36:44 +03:00
SE_PRIV se_rights ;
2001-03-23 03:50:31 +03:00
2008-02-05 14:54:19 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & sid , & acc_granted , NULL ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
status = access_check_samr_function ( acc_granted ,
2008-02-08 21:42:23 +03:00
SA_RIGHT_DOMAIN_OPEN_ACCOUNT ,
" _samr_OpenGroup " ) ;
2008-02-05 14:54:19 +03:00
2005-01-26 23:36:44 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
2002-07-15 14:35:28 +04:00
return status ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
/*check if access can be granted as requested by client. */
2005-02-01 01:42:30 +03:00
make_samr_object_sd ( p - > mem_ctx , & psd , & sd_size , & grp_generic_mapping , NULL , 0 ) ;
2002-07-15 14:35:28 +04:00
se_map_generic ( & des_access , & grp_generic_mapping ) ;
2005-01-26 23:36:44 +03:00
se_priv_copy ( & se_rights , & se_add_users ) ;
2008-02-05 14:54:19 +03:00
status = access_check_samr_object ( psd , p - > pipe_user . nt_user_token ,
& se_rights , GENERIC_RIGHTS_GROUP_WRITE , des_access ,
2008-02-01 02:49:32 +03:00
& acc_granted , " _samr_OpenGroup " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-01-26 23:36:44 +03:00
return status ;
2001-03-23 03:50:31 +03:00
/* this should not be hard-coded like this */
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
if ( ! sid_equal ( & sid , get_global_sam_sid ( ) ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_ACCESS_DENIED ;
2002-07-15 14:35:28 +04:00
sid_copy ( & info_sid , get_global_sam_sid ( ) ) ;
2008-02-01 02:49:32 +03:00
sid_append_rid ( & info_sid , r - > in . rid ) ;
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_string , & info_sid ) ;
2001-03-23 03:50:31 +03:00
2002-01-02 10:27:33 +03:00
if ( ( info = get_samr_info_by_sid ( & info_sid ) ) = = NULL )
return NT_STATUS_NO_MEMORY ;
2008-02-05 14:54:19 +03:00
2002-07-15 14:35:28 +04:00
info - > acc_granted = acc_granted ;
2001-03-23 03:50:31 +03:00
2008-02-01 02:49:32 +03:00
DEBUG ( 10 , ( " _samr_OpenGroup:Opening SID: %s \n " , sid_string ) ) ;
2001-03-23 03:50:31 +03:00
/* check if that group really exists */
2003-11-08 02:04:06 +03:00
become_root ( ) ;
2006-08-15 18:07:15 +04:00
ret = get_domain_group_from_sid ( info - > sid , & map ) ;
2003-11-08 02:04:06 +03:00
unbecome_root ( ) ;
if ( ! ret )
2001-12-02 03:06:10 +03:00
return NT_STATUS_NO_SUCH_GROUP ;
2001-03-23 03:50:31 +03:00
/* get a (unique) handle. open a policy on it. */
2008-02-01 02:49:32 +03:00
if ( ! create_policy_hnd ( p , r - > out . group_handle , free_samr_info , ( void * ) info ) )
2001-03-23 03:50:31 +03:00
return NT_STATUS_OBJECT_NAME_NOT_FOUND ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-02-27 21:22:39 +03:00
}
/*********************************************************************
2008-02-05 13:16:58 +03:00
_samr_RemoveMemberFromForeignDomain
2001-02-27 21:22:39 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 13:16:58 +03:00
NTSTATUS _samr_RemoveMemberFromForeignDomain ( pipes_struct * p ,
struct samr_RemoveMemberFromForeignDomain * r )
2001-02-27 21:22:39 +03:00
{
2005-04-15 17:41:49 +04:00
DOM_SID delete_sid , domain_sid ;
2003-08-20 20:07:19 +04:00
uint32 acc_granted ;
2003-12-04 06:35:46 +03:00
NTSTATUS result ;
2005-11-19 02:15:47 +03:00
DISP_INFO * disp_info = NULL ;
2008-02-05 13:16:58 +03:00
sid_copy ( & delete_sid , r - > in . sid ) ;
2007-12-15 23:11:36 +03:00
2008-02-05 13:16:58 +03:00
DEBUG ( 5 , ( " _samr_RemoveMemberFromForeignDomain: removing SID [%s] \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & delete_sid ) ) ) ;
2003-08-20 20:07:19 +04:00
/* Find the policy handle. Open a policy on it. */
2007-12-15 23:11:36 +03:00
2008-02-05 13:16:58 +03:00
if ( ! get_lsa_policy_samr_sid ( p , r - > in . domain_handle , & domain_sid ,
2008-02-05 14:54:19 +03:00
& acc_granted , & disp_info ) )
2003-08-20 20:07:19 +04:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 14:54:19 +03:00
2008-02-08 21:42:23 +03:00
result = access_check_samr_function ( acc_granted ,
STD_RIGHT_DELETE_ACCESS ,
" _samr_RemoveMemberFromForeignDomain " ) ;
2008-02-05 14:54:19 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
2003-12-04 06:35:46 +03:00
return result ;
2008-02-05 14:54:19 +03:00
2008-02-05 13:16:58 +03:00
DEBUG ( 8 , ( " _samr_RemoveMemberFromForeignDomain: sid is %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & domain_sid ) ) ) ;
2003-08-20 20:07:19 +04:00
2008-02-05 14:54:19 +03:00
/* we can only delete a user from a group since we don't have
2003-12-04 06:35:46 +03:00
nested groups anyways . So in the latter case , just say OK */
2003-08-20 20:07:19 +04:00
2005-04-15 17:41:49 +04:00
/* TODO: The above comment nowadays is bogus. Since we have nested
* groups now , and aliases members are never reported out of the unix
* group membership , the " just say OK " makes this call a no - op . For
* us . This needs fixing however . */
/* I've only ever seen this in the wild when deleting a user from
* usrmgr . exe . domain_sid is the builtin domain , and the sid to delete
* is the user about to be deleted . I very much suspect this is the
* only application of this call . To verify this , let people report
* other cases . */
if ( ! sid_check_is_builtin ( & domain_sid ) ) {
2008-02-05 13:16:58 +03:00
DEBUG ( 1 , ( " _samr_RemoveMemberFromForeignDomain: domain_sid = %s, "
2005-04-15 17:41:49 +04:00
" global_sam_sid() = %s \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & domain_sid ) ,
sid_string_dbg ( get_global_sam_sid ( ) ) ) ) ;
2005-04-15 17:41:49 +04:00
DEBUGADD ( 1 , ( " please report to samba-technical@samba.org! \n " ) ) ;
return NT_STATUS_OK ;
2003-08-20 20:07:19 +04:00
}
2003-12-04 06:35:46 +03:00
2005-11-19 02:15:47 +03:00
force_flush_samr_cache ( disp_info ) ;
2005-04-15 17:41:49 +04:00
result = NT_STATUS_OK ;
2003-08-20 20:07:19 +04:00
2003-12-04 06:35:46 +03:00
return result ;
2001-02-27 21:22:39 +03:00
}
2001-11-28 03:06:00 +03:00
/*******************************************************************
2008-02-05 17:03:54 +03:00
_samr_QueryDomainInfo2
2001-11-28 03:06:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 17:03:54 +03:00
NTSTATUS _samr_QueryDomainInfo2 ( pipes_struct * p ,
struct samr_QueryDomainInfo2 * r )
2001-11-28 03:06:00 +03:00
{
2008-02-05 17:03:54 +03:00
return samr_QueryDomainInfo_internal ( " _samr_QueryDomainInfo2 " ,
p ,
r - > in . domain_handle ,
r - > in . level ,
r - > out . info ) ;
2001-11-28 03:06:00 +03:00
}
/*******************************************************************
2008-02-05 17:08:31 +03:00
_samr_SetDomainInfo
2001-11-28 03:06:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-02-05 17:08:31 +03:00
NTSTATUS _samr_SetDomainInfo ( pipes_struct * p ,
struct samr_SetDomainInfo * r )
2001-11-28 03:06:00 +03:00
{
2001-12-03 20:14:23 +03:00
time_t u_expire , u_min_age ;
time_t u_logout ;
time_t u_lock_duration , u_reset_time ;
2008-02-05 17:08:31 +03:00
DEBUG ( 5 , ( " _samr_SetDomainInfo: %d \n " , __LINE__ ) ) ;
2001-11-28 03:06:00 +03:00
/* find the policy handle. open a policy on it. */
2008-02-05 17:08:31 +03:00
if ( ! find_policy_by_hnd ( p , r - > in . domain_handle , NULL ) )
2001-11-28 03:06:00 +03:00
return NT_STATUS_INVALID_HANDLE ;
2008-02-05 17:08:31 +03:00
DEBUG ( 5 , ( " _samr_SetDomainInfo: level: %d \n " , r - > in . level ) ) ;
2001-11-28 03:06:00 +03:00
2008-02-05 17:08:31 +03:00
switch ( r - > in . level ) {
2001-12-03 20:14:23 +03:00
case 0x01 :
2008-02-05 17:08:31 +03:00
u_expire = nt_time_to_unix_abs ( ( NTTIME * ) & r - > in . info - > info1 . max_password_age ) ;
u_min_age = nt_time_to_unix_abs ( ( NTTIME * ) & r - > in . info - > info1 . min_password_age ) ;
pdb_set_account_policy ( AP_MIN_PASSWORD_LEN , ( uint32 ) r - > in . info - > info1 . min_password_length ) ;
pdb_set_account_policy ( AP_PASSWORD_HISTORY , ( uint32 ) r - > in . info - > info1 . password_history_length ) ;
pdb_set_account_policy ( AP_USER_MUST_LOGON_TO_CHG_PASS , ( uint32 ) r - > in . info - > info1 . password_properties ) ;
2005-09-30 21:13:37 +04:00
pdb_set_account_policy ( AP_MAX_PASSWORD_AGE , ( int ) u_expire ) ;
pdb_set_account_policy ( AP_MIN_PASSWORD_AGE , ( int ) u_min_age ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x02 :
break ;
case 0x03 :
2008-02-05 17:08:31 +03:00
u_logout = nt_time_to_unix_abs ( ( NTTIME * ) & r - > in . info - > info3 . force_logoff_time ) ;
2005-09-30 21:13:37 +04:00
pdb_set_account_policy ( AP_TIME_TO_LOGOUT , ( int ) u_logout ) ;
2001-12-03 20:14:23 +03:00
break ;
case 0x05 :
break ;
case 0x06 :
break ;
case 0x07 :
break ;
case 0x0c :
2008-02-05 17:08:31 +03:00
u_lock_duration = nt_time_to_unix_abs ( ( NTTIME * ) & r - > in . info - > info12 . lockout_duration ) ;
2005-01-10 18:28:07 +03:00
if ( u_lock_duration ! = - 1 )
u_lock_duration / = 60 ;
2005-01-22 06:37:09 +03:00
2008-02-05 17:08:31 +03:00
u_reset_time = nt_time_to_unix_abs ( ( NTTIME * ) & r - > in . info - > info12 . lockout_window ) / 60 ;
2008-02-05 14:54:19 +03:00
2005-09-30 21:13:37 +04:00
pdb_set_account_policy ( AP_LOCK_ACCOUNT_DURATION , ( int ) u_lock_duration ) ;
pdb_set_account_policy ( AP_RESET_COUNT_TIME , ( int ) u_reset_time ) ;
2008-02-05 17:08:31 +03:00
pdb_set_account_policy ( AP_BAD_ATTEMPT_LOCKOUT , ( uint32 ) r - > in . info - > info12 . lockout_threshold ) ;
2001-12-03 20:14:23 +03:00
break ;
default :
return NT_STATUS_INVALID_INFO_CLASS ;
2001-11-28 03:06:00 +03:00
}
2008-02-05 17:08:31 +03:00
DEBUG ( 5 , ( " _samr_SetDomainInfo: %d \n " , __LINE__ ) ) ;
2001-11-28 03:06:00 +03:00
2008-02-05 17:08:31 +03:00
return NT_STATUS_OK ;
2001-11-28 03:06:00 +03:00
}
2008-01-30 14:53:09 +03:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_Shutdown ( pipes_struct * p ,
struct samr_Shutdown * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_CreateUser ( pipes_struct * p ,
struct samr_CreateUser * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_SetMemberAttributesOfGroup ( pipes_struct * p ,
struct samr_SetMemberAttributesOfGroup * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_QueryUserInfo ( pipes_struct * p ,
struct samr_QueryUserInfo * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_ChangePasswordUser ( pipes_struct * p ,
struct samr_ChangePasswordUser * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_GetDisplayEnumerationIndex ( pipes_struct * p ,
struct samr_GetDisplayEnumerationIndex * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_TestPrivateFunctionsDomain ( pipes_struct * p ,
struct samr_TestPrivateFunctionsDomain * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_TestPrivateFunctionsUser ( pipes_struct * p ,
struct samr_TestPrivateFunctionsUser * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_QueryUserInfo2 ( pipes_struct * p ,
struct samr_QueryUserInfo2 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_QueryDisplayInfo2 ( pipes_struct * p ,
struct samr_QueryDisplayInfo2 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_GetDisplayEnumerationIndex2 ( pipes_struct * p ,
struct samr_GetDisplayEnumerationIndex2 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_QueryDisplayInfo3 ( pipes_struct * p ,
struct samr_QueryDisplayInfo3 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_AddMultipleMembersToAlias ( pipes_struct * p ,
struct samr_AddMultipleMembersToAlias * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_RemoveMultipleMembersFromAlias ( pipes_struct * p ,
struct samr_RemoveMultipleMembersFromAlias * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_OemChangePasswordUser2 ( pipes_struct * p ,
struct samr_OemChangePasswordUser2 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_SetBootKeyInformation ( pipes_struct * p ,
struct samr_SetBootKeyInformation * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_GetBootKeyInformation ( pipes_struct * p ,
struct samr_GetBootKeyInformation * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_Connect3 ( pipes_struct * p ,
struct samr_Connect3 * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_RidToSid ( pipes_struct * p ,
struct samr_RidToSid * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_SetDsrmPassword ( pipes_struct * p ,
struct samr_SetDsrmPassword * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS _samr_ValidatePassword ( pipes_struct * p ,
struct samr_ValidatePassword * r )
{
p - > rng_fault_state = true ;
return NT_STATUS_NOT_IMPLEMENTED ;
}