2003-10-06 05:24:48 +04:00
/*
* Unix SMB / Netbios implementation .
* SEC_DESC handling functions
* Copyright ( C ) Andrew Tridgell 1992 - 1998 ,
* Copyright ( C ) Jeremy R . Allison 1995 - 2003.
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998 ,
* Copyright ( C ) Paul Ashton 1997 - 1998.
*
* 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
2003-10-06 05:24:48 +04: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/>.
2003-10-06 05:24:48 +04:00
*/
# include "includes.h"
2006-02-04 01:19:41 +03:00
/* Map generic permissions to file object specific permissions */
2007-10-06 01:41:17 +04:00
const struct generic_mapping file_generic_mapping = {
2006-02-04 01:19:41 +03:00
FILE_GENERIC_READ ,
FILE_GENERIC_WRITE ,
FILE_GENERIC_EXECUTE ,
FILE_GENERIC_ALL
} ;
2003-10-06 05:24:48 +04:00
/*******************************************************************
Compares two SEC_DESC structures
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool sec_desc_equal ( SEC_DESC * s1 , SEC_DESC * s2 )
2003-10-06 05:24:48 +04:00
{
/* Trivial case */
if ( ! s1 & & ! s2 ) {
goto done ;
}
2006-03-08 04:04:17 +03:00
if ( ! s1 | | ! s2 ) {
return False ;
}
2003-10-06 05:24:48 +04:00
/* Check top level stuff */
if ( s1 - > revision ! = s2 - > revision ) {
DEBUG ( 10 , ( " sec_desc_equal(): revision differs (%d != %d) \n " ,
s1 - > revision , s2 - > revision ) ) ;
return False ;
}
if ( s1 - > type ! = s2 - > type ) {
DEBUG ( 10 , ( " sec_desc_equal(): type differs (%d != %d) \n " ,
s1 - > type , s2 - > type ) ) ;
return False ;
}
/* Check owner and group */
if ( ! sid_equal ( s1 - > owner_sid , s2 - > owner_sid ) ) {
DEBUG ( 10 , ( " sec_desc_equal(): owner differs (%s != %s) \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( s1 - > owner_sid ) ,
sid_string_dbg ( s2 - > owner_sid ) ) ) ;
2003-10-06 05:24:48 +04:00
return False ;
}
2006-09-21 02:23:12 +04:00
if ( ! sid_equal ( s1 - > group_sid , s2 - > group_sid ) ) {
2003-10-06 05:24:48 +04:00
DEBUG ( 10 , ( " sec_desc_equal(): group differs (%s != %s) \n " ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( s1 - > group_sid ) ,
sid_string_dbg ( s2 - > group_sid ) ) ) ;
2003-10-06 05:24:48 +04:00
return False ;
}
/* Check ACLs present in one but not the other */
if ( ( s1 - > dacl & & ! s2 - > dacl ) | | ( ! s1 - > dacl & & s2 - > dacl ) | |
( s1 - > sacl & & ! s2 - > sacl ) | | ( ! s1 - > sacl & & s2 - > sacl ) ) {
DEBUG ( 10 , ( " sec_desc_equal(): dacl or sacl not present \n " ) ) ;
return False ;
}
/* Sigh - we have to do it the hard way by iterating over all
the ACEs in the ACLs */
if ( ! sec_acl_equal ( s1 - > dacl , s2 - > dacl ) | |
! sec_acl_equal ( s1 - > sacl , s2 - > sacl ) ) {
DEBUG ( 10 , ( " sec_desc_equal(): dacl/sacl list not equal \n " ) ) ;
return False ;
}
done :
DEBUG ( 10 , ( " sec_desc_equal(): secdescs are identical \n " ) ) ;
return True ;
}
/*******************************************************************
Merge part of security descriptor old_sec in to the empty sections of
security descriptor new_sec .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SEC_DESC_BUF * sec_desc_merge ( TALLOC_CTX * ctx , SEC_DESC_BUF * new_sdb , SEC_DESC_BUF * old_sdb )
{
DOM_SID * owner_sid , * group_sid ;
SEC_DESC_BUF * return_sdb ;
SEC_ACL * dacl , * sacl ;
SEC_DESC * psd = NULL ;
uint16 secdesc_type ;
size_t secdesc_size ;
/* Copy over owner and group sids. There seems to be no flag for
this so just check the pointer values . */
2006-09-21 02:23:12 +04:00
owner_sid = new_sdb - > sd - > owner_sid ? new_sdb - > sd - > owner_sid :
old_sdb - > sd - > owner_sid ;
2003-10-06 05:24:48 +04:00
2006-09-21 02:23:12 +04:00
group_sid = new_sdb - > sd - > group_sid ? new_sdb - > sd - > group_sid :
old_sdb - > sd - > group_sid ;
2003-10-06 05:24:48 +04:00
2006-09-21 02:23:12 +04:00
secdesc_type = new_sdb - > sd - > type ;
2003-10-06 05:24:48 +04:00
/* Ignore changes to the system ACL. This has the effect of making
changes through the security tab audit button not sticking .
Perhaps in future Samba could implement these settings somehow . */
sacl = NULL ;
secdesc_type & = ~ SEC_DESC_SACL_PRESENT ;
/* Copy across discretionary ACL */
if ( secdesc_type & SEC_DESC_DACL_PRESENT ) {
2006-09-21 02:23:12 +04:00
dacl = new_sdb - > sd - > dacl ;
2003-10-06 05:24:48 +04:00
} else {
2006-09-21 02:23:12 +04:00
dacl = old_sdb - > sd - > dacl ;
2003-10-06 05:24:48 +04:00
}
/* Create new security descriptor from bits */
2006-09-21 02:23:12 +04:00
psd = make_sec_desc ( ctx , new_sdb - > sd - > revision , secdesc_type ,
2003-10-06 05:24:48 +04:00
owner_sid , group_sid , sacl , dacl , & secdesc_size ) ;
return_sdb = make_sec_desc_buf ( ctx , secdesc_size , psd ) ;
return ( return_sdb ) ;
}
/*******************************************************************
Creates a SEC_DESC structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-21 00:27:01 +03:00
SEC_DESC * make_sec_desc ( TALLOC_CTX * ctx ,
enum security_descriptor_revision revision ,
uint16 type ,
2005-04-09 15:46:40 +04:00
const DOM_SID * owner_sid , const DOM_SID * grp_sid ,
2003-10-06 05:24:48 +04:00
SEC_ACL * sacl , SEC_ACL * dacl , size_t * sd_size )
{
SEC_DESC * dst ;
uint32 offset = 0 ;
* sd_size = 0 ;
2004-12-07 21:25:53 +03:00
if ( ( dst = TALLOC_ZERO_P ( ctx , SEC_DESC ) ) = = NULL )
2003-10-06 05:24:48 +04:00
return NULL ;
dst - > revision = revision ;
dst - > type = type ;
if ( sacl )
dst - > type | = SEC_DESC_SACL_PRESENT ;
if ( dacl )
dst - > type | = SEC_DESC_DACL_PRESENT ;
2006-09-21 02:23:12 +04:00
dst - > owner_sid = NULL ;
dst - > group_sid = NULL ;
dst - > sacl = NULL ;
dst - > dacl = NULL ;
2003-10-06 05:24:48 +04:00
2006-11-30 10:38:40 +03:00
if ( owner_sid & & ( ( dst - > owner_sid = sid_dup_talloc ( dst , owner_sid ) ) = = NULL ) )
2003-10-06 05:24:48 +04:00
goto error_exit ;
2006-11-30 10:38:40 +03:00
if ( grp_sid & & ( ( dst - > group_sid = sid_dup_talloc ( dst , grp_sid ) ) = = NULL ) )
2003-10-06 05:24:48 +04:00
goto error_exit ;
2006-11-30 10:38:40 +03:00
if ( sacl & & ( ( dst - > sacl = dup_sec_acl ( dst , sacl ) ) = = NULL ) )
2003-10-06 05:24:48 +04:00
goto error_exit ;
2006-11-30 10:38:40 +03:00
if ( dacl & & ( ( dst - > dacl = dup_sec_acl ( dst , dacl ) ) = = NULL ) )
2003-10-06 05:24:48 +04:00
goto error_exit ;
offset = SEC_DESC_HEADER_SIZE ;
/*
* Work out the linearization sizes .
*/
if ( dst - > sacl ! = NULL ) {
offset + = dst - > sacl - > size ;
}
if ( dst - > dacl ! = NULL ) {
offset + = dst - > dacl - > size ;
}
if ( dst - > owner_sid ! = NULL ) {
2007-12-30 00:16:31 +03:00
offset + = ndr_size_dom_sid ( dst - > owner_sid , 0 ) ;
2003-10-06 05:24:48 +04:00
}
2006-09-21 02:23:12 +04:00
if ( dst - > group_sid ! = NULL ) {
2007-12-30 00:16:31 +03:00
offset + = ndr_size_dom_sid ( dst - > group_sid , 0 ) ;
2003-10-06 05:24:48 +04:00
}
* sd_size = ( size_t ) offset ;
return dst ;
error_exit :
* sd_size = 0 ;
return NULL ;
}
/*******************************************************************
Duplicate a SEC_DESC structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SEC_DESC * dup_sec_desc ( TALLOC_CTX * ctx , const SEC_DESC * src )
{
size_t dummy ;
if ( src = = NULL )
return NULL ;
return make_sec_desc ( ctx , src - > revision , src - > type ,
2006-09-21 02:23:12 +04:00
src - > owner_sid , src - > group_sid , src - > sacl ,
2003-10-06 05:24:48 +04:00
src - > dacl , & dummy ) ;
}
2006-11-30 10:38:40 +03:00
/*******************************************************************
Convert a secdesc into a byte stream
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS marshall_sec_desc ( TALLOC_CTX * mem_ctx ,
struct security_descriptor * secdesc ,
uint8 * * data , size_t * len )
{
2007-12-30 00:54:51 +03:00
DATA_BLOB blob ;
enum ndr_err_code ndr_err ;
2006-11-30 10:38:40 +03:00
2007-12-30 00:54:51 +03:00
ndr_err = ndr_push_struct_blob (
2008-09-23 11:49:56 +04:00
& blob , mem_ctx , NULL , secdesc ,
2007-12-30 00:54:51 +03:00
( ndr_push_flags_fn_t ) ndr_push_security_descriptor ) ;
2006-11-30 10:38:40 +03:00
2007-12-30 00:54:51 +03:00
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
DEBUG ( 0 , ( " ndr_push_security_descriptor failed: %s \n " ,
ndr_errstr ( ndr_err ) ) ) ;
return ndr_map_error2ntstatus ( ndr_err ) ; ;
2006-11-30 10:38:40 +03:00
}
2007-12-30 00:54:51 +03:00
* data = blob . data ;
* len = blob . length ;
2006-11-30 10:38:40 +03:00
return NT_STATUS_OK ;
}
/*******************************************************************
Parse a byte stream into a secdesc
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS unmarshall_sec_desc ( TALLOC_CTX * mem_ctx , uint8 * data , size_t len ,
struct security_descriptor * * psecdesc )
{
2007-12-30 00:54:51 +03:00
DATA_BLOB blob ;
enum ndr_err_code ndr_err ;
struct security_descriptor * result ;
2006-11-30 10:38:40 +03:00
2007-12-30 00:54:51 +03:00
if ( ( data = = NULL ) | | ( len = = 0 ) ) {
return NT_STATUS_INVALID_PARAMETER ;
2006-11-30 10:38:40 +03:00
}
2007-12-30 00:54:51 +03:00
result = TALLOC_ZERO_P ( mem_ctx , struct security_descriptor ) ;
if ( result = = NULL ) {
2006-11-30 10:38:40 +03:00
return NT_STATUS_NO_MEMORY ;
}
2007-12-30 00:54:51 +03:00
blob = data_blob_const ( data , len ) ;
2006-11-30 10:38:40 +03:00
2007-12-30 00:54:51 +03:00
ndr_err = ndr_pull_struct_blob (
2008-09-23 11:49:56 +04:00
& blob , result , NULL , result ,
2007-12-30 00:54:51 +03:00
( ndr_pull_flags_fn_t ) ndr_pull_security_descriptor ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
DEBUG ( 0 , ( " ndr_pull_security_descriptor failed: %s \n " ,
ndr_errstr ( ndr_err ) ) ) ;
TALLOC_FREE ( result ) ;
return ndr_map_error2ntstatus ( ndr_err ) ; ;
2006-11-30 10:38:40 +03:00
}
2007-12-30 00:54:51 +03:00
* psecdesc = result ;
2006-11-30 10:38:40 +03:00
return NT_STATUS_OK ;
}
2003-10-06 05:24:48 +04:00
/*******************************************************************
Creates a SEC_DESC structure with typical defaults .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-04-09 15:46:40 +04:00
SEC_DESC * make_standard_sec_desc ( TALLOC_CTX * ctx , const DOM_SID * owner_sid , const DOM_SID * grp_sid ,
2003-10-06 05:24:48 +04:00
SEC_ACL * dacl , size_t * sd_size )
{
2007-12-21 00:27:01 +03:00
return make_sec_desc ( ctx , SECURITY_DESCRIPTOR_REVISION_1 ,
SEC_DESC_SELF_RELATIVE , owner_sid , grp_sid , NULL ,
dacl , sd_size ) ;
2003-10-06 05:24:48 +04:00
}
/*******************************************************************
Creates a SEC_DESC_BUF structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SEC_DESC_BUF * make_sec_desc_buf ( TALLOC_CTX * ctx , size_t len , SEC_DESC * sec_desc )
{
SEC_DESC_BUF * dst ;
2004-12-07 21:25:53 +03:00
if ( ( dst = TALLOC_ZERO_P ( ctx , SEC_DESC_BUF ) ) = = NULL )
2003-10-06 05:24:48 +04:00
return NULL ;
/* max buffer size (allocated size) */
2006-09-21 02:23:12 +04:00
dst - > sd_size = ( uint32 ) len ;
2003-10-06 05:24:48 +04:00
2006-09-21 02:23:12 +04:00
if ( sec_desc & & ( ( dst - > sd = dup_sec_desc ( ctx , sec_desc ) ) = = NULL ) ) {
2003-10-06 05:24:48 +04:00
return NULL ;
}
return dst ;
}
/*******************************************************************
Duplicates a SEC_DESC_BUF structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SEC_DESC_BUF * dup_sec_desc_buf ( TALLOC_CTX * ctx , SEC_DESC_BUF * src )
{
if ( src = = NULL )
return NULL ;
2006-09-21 02:23:12 +04:00
return make_sec_desc_buf ( ctx , src - > sd_size , src - > sd ) ;
2003-10-06 05:24:48 +04:00
}
/*******************************************************************
Add a new SID with its permissions to SEC_DESC .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS sec_desc_add_sid ( TALLOC_CTX * ctx , SEC_DESC * * psd , DOM_SID * sid , uint32 mask , size_t * sd_size )
{
SEC_DESC * sd = 0 ;
SEC_ACL * dacl = 0 ;
SEC_ACE * ace = 0 ;
NTSTATUS status ;
if ( ! ctx | | ! psd | | ! sid | | ! sd_size )
return NT_STATUS_INVALID_PARAMETER ;
2006-03-13 04:49:01 +03:00
* sd_size = 0 ;
2006-09-21 02:23:12 +04:00
status = sec_ace_add_sid ( ctx , & ace , psd [ 0 ] - > dacl - > aces , & psd [ 0 ] - > dacl - > num_aces , sid , mask ) ;
2003-10-06 05:24:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
if ( ! ( dacl = make_sec_acl ( ctx , psd [ 0 ] - > dacl - > revision , psd [ 0 ] - > dacl - > num_aces , ace ) ) )
return NT_STATUS_UNSUCCESSFUL ;
if ( ! ( sd = make_sec_desc ( ctx , psd [ 0 ] - > revision , psd [ 0 ] - > type , psd [ 0 ] - > owner_sid ,
2006-09-21 02:23:12 +04:00
psd [ 0 ] - > group_sid , psd [ 0 ] - > sacl , dacl , sd_size ) ) )
2003-10-06 05:24:48 +04:00
return NT_STATUS_UNSUCCESSFUL ;
* psd = sd ;
sd = 0 ;
return NT_STATUS_OK ;
}
/*******************************************************************
Modify a SID ' s permissions in a SEC_DESC .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS sec_desc_mod_sid ( SEC_DESC * sd , DOM_SID * sid , uint32 mask )
{
NTSTATUS status ;
if ( ! sd | | ! sid )
return NT_STATUS_INVALID_PARAMETER ;
2006-09-21 02:23:12 +04:00
status = sec_ace_mod_sid ( sd - > dacl - > aces , sd - > dacl - > num_aces , sid , mask ) ;
2003-10-06 05:24:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
return NT_STATUS_OK ;
}
/*******************************************************************
Delete a SID from a SEC_DESC .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS sec_desc_del_sid ( TALLOC_CTX * ctx , SEC_DESC * * psd , DOM_SID * sid , size_t * sd_size )
{
SEC_DESC * sd = 0 ;
SEC_ACL * dacl = 0 ;
SEC_ACE * ace = 0 ;
NTSTATUS status ;
if ( ! ctx | | ! psd [ 0 ] | | ! sid | | ! sd_size )
return NT_STATUS_INVALID_PARAMETER ;
2006-03-13 04:49:01 +03:00
* sd_size = 0 ;
2006-09-21 02:23:12 +04:00
status = sec_ace_del_sid ( ctx , & ace , psd [ 0 ] - > dacl - > aces , & psd [ 0 ] - > dacl - > num_aces , sid ) ;
2003-10-06 05:24:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
return status ;
if ( ! ( dacl = make_sec_acl ( ctx , psd [ 0 ] - > dacl - > revision , psd [ 0 ] - > dacl - > num_aces , ace ) ) )
return NT_STATUS_UNSUCCESSFUL ;
if ( ! ( sd = make_sec_desc ( ctx , psd [ 0 ] - > revision , psd [ 0 ] - > type , psd [ 0 ] - > owner_sid ,
2006-09-21 02:23:12 +04:00
psd [ 0 ] - > group_sid , psd [ 0 ] - > sacl , dacl , sd_size ) ) )
2003-10-06 05:24:48 +04:00
return NT_STATUS_UNSUCCESSFUL ;
* psd = sd ;
sd = 0 ;
return NT_STATUS_OK ;
}
2008-10-29 23:27:14 +03:00
/*
* Determine if an ACE is inheritable
*/
static bool is_inheritable_ace ( const SEC_ACE * ace ,
bool container )
{
if ( ! container ) {
return ( ( ace - > flags & SEC_ACE_FLAG_OBJECT_INHERIT ) ! = 0 ) ;
}
if ( ace - > flags & SEC_ACE_FLAG_CONTAINER_INHERIT ) {
return true ;
}
if ( ( ace - > flags & SEC_ACE_FLAG_OBJECT_INHERIT ) & &
! ( ace - > flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT ) ) {
return true ;
}
return false ;
}
2003-10-06 05:24:48 +04:00
/* Create a child security descriptor using another security descriptor as
the parent container . This child object can either be a container or
non - container object . */
2008-10-29 23:27:14 +03:00
NTSTATUS se_create_child_secdesc ( TALLOC_CTX * ctx ,
SEC_DESC * * ppsd ,
size_t * psize ,
const SEC_DESC * parent_ctr ,
const DOM_SID * owner_sid ,
const DOM_SID * group_sid ,
bool container )
2003-10-06 05:24:48 +04:00
{
2008-10-29 23:27:14 +03:00
SEC_ACL * new_dacl = NULL , * the_acl = NULL ;
2003-10-06 05:24:48 +04:00
SEC_ACE * new_ace_list = NULL ;
unsigned int new_ace_list_ndx = 0 , i ;
2008-10-29 23:27:14 +03:00
* ppsd = NULL ;
* psize = 0 ;
2003-10-06 05:24:48 +04:00
/* Currently we only process the dacl when creating the child. The
sacl should also be processed but this is left out as sacls are
not implemented in Samba at the moment . */
the_acl = parent_ctr - > dacl ;
2007-04-30 06:39:34 +04:00
if ( the_acl - > num_aces ) {
2008-10-29 23:27:14 +03:00
if ( 2 * the_acl - > num_aces < the_acl - > num_aces ) {
return NT_STATUS_NO_MEMORY ;
}
if ( ! ( new_ace_list = TALLOC_ARRAY ( ctx , SEC_ACE ,
2 * the_acl - > num_aces ) ) ) {
return NT_STATUS_NO_MEMORY ;
}
2007-04-30 06:39:34 +04:00
} else {
new_ace_list = NULL ;
}
2003-10-06 05:24:48 +04:00
2006-03-12 21:01:36 +03:00
for ( i = 0 ; i < the_acl - > num_aces ; i + + ) {
2008-10-29 23:27:14 +03:00
const SEC_ACE * ace = & the_acl - > aces [ i ] ;
2003-10-06 05:24:48 +04:00
SEC_ACE * new_ace = & new_ace_list [ new_ace_list_ndx ] ;
2008-10-29 23:27:14 +03:00
const DOM_SID * ptrustee = & ace - > trustee ;
const DOM_SID * creator = NULL ;
uint8 new_flags = ace - > flags ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
if ( ! is_inheritable_ace ( ace , container ) ) {
continue ;
}
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
/* see the RAW-ACLS inheritance test for details on these rules */
if ( ! container ) {
new_flags = 0 ;
} else {
new_flags & = ~ SEC_ACE_FLAG_INHERIT_ONLY ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
if ( ! ( new_flags & SEC_ACE_FLAG_CONTAINER_INHERIT ) ) {
2003-10-06 05:24:48 +04:00
new_flags | = SEC_ACE_FLAG_INHERIT_ONLY ;
}
2008-10-29 23:27:14 +03:00
if ( new_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT ) {
new_flags = 0 ;
}
2003-10-06 05:24:48 +04:00
}
2008-10-29 23:27:14 +03:00
/* The CREATOR sids are special when inherited */
if ( sid_equal ( ptrustee , & global_sid_Creator_Owner ) ) {
creator = & global_sid_Creator_Owner ;
ptrustee = owner_sid ;
} else if ( sid_equal ( ptrustee , & global_sid_Creator_Group ) ) {
creator = & global_sid_Creator_Group ;
ptrustee = group_sid ;
2003-10-06 05:24:48 +04:00
}
2008-10-29 23:27:14 +03:00
if ( creator & & container & &
( new_flags & SEC_ACE_FLAG_CONTAINER_INHERIT ) ) {
2003-10-06 05:24:48 +04:00
2008-10-30 23:51:28 +03:00
/* First add the regular ACE entry. */
2008-10-29 23:27:14 +03:00
init_sec_ace ( new_ace , ptrustee , ace - > type ,
2008-11-01 04:04:53 +03:00
ace - > access_mask , 0 ) ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
DEBUG ( 5 , ( " se_create_child_secdesc(): %s:%d/0x%02x/0x%08x "
" inherited as %s:%d/0x%02x/0x%08x \n " ,
sid_string_dbg ( & ace - > trustee ) ,
ace - > type , ace - > flags , ace - > access_mask ,
sid_string_dbg ( & new_ace - > trustee ) ,
new_ace - > type , new_ace - > flags ,
new_ace - > access_mask ) ) ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
new_ace_list_ndx + + ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
/* Now add the extra creator ACE. */
new_ace = & new_ace_list [ new_ace_list_ndx ] ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
ptrustee = creator ;
new_flags | = SEC_ACE_FLAG_INHERIT_ONLY ;
}
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
init_sec_ace ( new_ace , ptrustee , ace - > type ,
2008-11-01 04:04:53 +03:00
ace - > access_mask , new_flags ) ;
2003-10-06 05:24:48 +04:00
DEBUG ( 5 , ( " se_create_child_secdesc(): %s:%d/0x%02x/0x%08x "
2007-12-15 23:11:36 +03:00
" inherited as %s:%d/0x%02x/0x%08x \n " ,
sid_string_dbg ( & ace - > trustee ) ,
2006-09-21 02:23:12 +04:00
ace - > type , ace - > flags , ace - > access_mask ,
2007-12-15 23:11:36 +03:00
sid_string_dbg ( & ace - > trustee ) ,
new_ace - > type , new_ace - > flags ,
2006-09-21 02:23:12 +04:00
new_ace - > access_mask ) ) ;
2003-10-06 05:24:48 +04:00
new_ace_list_ndx + + ;
}
/* Create child security descriptor to return */
2008-10-29 23:27:14 +03:00
new_dacl = make_sec_acl ( ctx ,
2008-11-01 04:04:53 +03:00
NT4_ACL_REVISION ,
2008-10-29 23:27:14 +03:00
new_ace_list_ndx ,
new_ace_list ) ;
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
if ( ! new_dacl ) {
return NT_STATUS_NO_MEMORY ;
}
* ppsd = make_sec_desc ( ctx ,
SECURITY_DESCRIPTOR_REVISION_1 ,
SEC_DESC_SELF_RELATIVE | SEC_DESC_DACL_PRESENT |
SEC_DESC_DACL_DEFAULTED ,
owner_sid ,
group_sid ,
NULL ,
new_dacl ,
psize ) ;
if ( ! * ppsd ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
NTSTATUS se_create_child_secdesc_buf ( TALLOC_CTX * ctx ,
SEC_DESC_BUF * * ppsdb ,
const SEC_DESC * parent_ctr ,
bool container )
{
NTSTATUS status ;
size_t size = 0 ;
SEC_DESC * sd = NULL ;
* ppsdb = NULL ;
status = se_create_child_secdesc ( ctx ,
& sd ,
& size ,
parent_ctr ,
parent_ctr - > owner_sid ,
parent_ctr - > group_sid ,
container ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2003-10-06 05:24:48 +04:00
2008-10-29 23:27:14 +03:00
* ppsdb = make_sec_desc_buf ( ctx , size , sd ) ;
if ( ! * ppsdb ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
2003-10-06 05:24:48 +04:00
}