2015-01-14 17:11:12 +01:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2000-07-07 06:18:00 +00:00
Samba utility functions
Copyright ( C ) Andrew Tridgell 1992 - 1999
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1999
2015-01-14 17:11:12 +01:00
2000-07-07 06:18:00 +00: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 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2000-07-07 06:18:00 +00:00
( at your option ) any later version .
2015-01-14 17:11:12 +01:00
This program is distributed in the hope that it will be useful ,
2000-07-07 06:18:00 +00:00
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 .
2015-01-14 17:11:12 +01:00
2000-07-07 06:18:00 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-07-07 06:18:00 +00:00
*/
2023-03-03 18:41:33 +01:00
# include "replace.h"
2010-10-12 15:27:50 +11:00
# include "libcli/security/security.h"
2009-03-25 21:29:13 +01:00
# include "librpc/ndr/libndr.h"
2011-02-24 10:47:16 +01:00
# include "libcli/security/display_sec.h"
2000-07-07 06:18:00 +00:00
/****************************************************************************
convert a security permissions into a string
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-17 18:32:27 -08:00
2009-03-15 17:14:25 +01:00
char * get_sec_mask_str ( TALLOC_CTX * ctx , uint32_t type )
2000-07-07 06:18:00 +00:00
{
2007-12-17 18:32:27 -08:00
char * typestr = talloc_strdup ( ctx , " " ) ;
2000-07-07 06:18:00 +00:00
2009-03-25 21:29:13 +01:00
if ( type & SEC_GENERIC_ALL ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " Generic all access " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_GENERIC_EXECUTE ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " Generic execute access " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_GENERIC_WRITE ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " Generic write access " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_GENERIC_READ ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " Generic read access " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_FLAG_MAXIMUM_ALLOWED ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " MAXIMUM_ALLOWED_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_FLAG_SYSTEM_SECURITY ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " SYSTEM_SECURITY_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_STD_SYNCHRONIZE ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " SYNCHRONIZE_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_STD_WRITE_OWNER ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " WRITE_OWNER_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_STD_WRITE_DAC ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " WRITE_DAC_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_STD_READ_CONTROL ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " READ_CONTROL_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2009-03-25 21:29:13 +01:00
if ( type & SEC_STD_DELETE ) {
2021-10-06 10:33:50 +02:00
talloc_asprintf_addbuf ( & typestr , " DELETE_ACCESS " ) ;
2007-12-17 18:32:27 -08:00
}
2001-12-11 02:17:26 +00:00
2009-03-25 21:29:13 +01:00
printf ( " \t \t Specific bits: 0x%lx \n " , ( unsigned long ) type & SEC_MASK_SPECIFIC ) ;
2000-07-07 06:18:00 +00:00
return typestr ;
}
/****************************************************************************
display sec_access structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 09:49:03 -07:00
void display_sec_access ( uint32_t * info )
2000-07-07 06:18:00 +00:00
{
2007-12-17 18:32:27 -08:00
char * mask_str = get_sec_mask_str ( NULL , * info ) ;
printf ( " \t \t Permissions: 0x%x: %s \n " , * info , mask_str ? mask_str : " " ) ;
2009-03-15 17:14:25 +01:00
talloc_free ( mask_str ) ;
2000-07-07 06:18:00 +00:00
}
2007-10-26 12:58:01 +02:00
/****************************************************************************
display sec_ace flags
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void display_sec_ace_flags ( uint8_t flags )
{
if ( flags & SEC_ACE_FLAG_OBJECT_INHERIT )
printf ( " SEC_ACE_FLAG_OBJECT_INHERIT " ) ;
if ( flags & SEC_ACE_FLAG_CONTAINER_INHERIT )
printf ( " SEC_ACE_FLAG_CONTAINER_INHERIT " ) ;
if ( flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT )
printf ( " SEC_ACE_FLAG_NO_PROPAGATE_INHERIT " ) ;
if ( flags & SEC_ACE_FLAG_INHERIT_ONLY )
printf ( " SEC_ACE_FLAG_INHERIT_ONLY " ) ;
if ( flags & SEC_ACE_FLAG_INHERITED_ACE )
printf ( " SEC_ACE_FLAG_INHERITED_ACE " ) ;
/* if (flags & SEC_ACE_FLAG_VALID_INHERIT)
printf ( " SEC_ACE_FLAG_VALID_INHERIT " ) ; */
if ( flags & SEC_ACE_FLAG_SUCCESSFUL_ACCESS )
printf ( " SEC_ACE_FLAG_SUCCESSFUL_ACCESS " ) ;
if ( flags & SEC_ACE_FLAG_FAILED_ACCESS )
printf ( " SEC_ACE_FLAG_FAILED_ACCESS " ) ;
printf ( " \n " ) ;
}
2007-10-11 02:25:44 +02:00
/****************************************************************************
display sec_ace object
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void disp_sec_ace_object ( struct security_ace_object * object )
{
2010-06-21 12:33:57 +02:00
char * str ;
2009-03-01 04:59:07 +01:00
if ( object - > flags & SEC_ACE_OBJECT_TYPE_PRESENT ) {
2010-06-21 12:33:57 +02:00
str = GUID_string ( NULL , & object - > type . type ) ;
if ( str = = NULL ) return ;
2009-03-01 04:59:07 +01:00
printf ( " Object type: SEC_ACE_OBJECT_TYPE_PRESENT \n " ) ;
2010-06-21 12:33:57 +02:00
printf ( " Object GUID: %s \n " , str ) ;
talloc_free ( str ) ;
2007-10-11 02:25:44 +02:00
}
2009-03-01 04:59:07 +01:00
if ( object - > flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT ) {
2010-06-21 12:33:57 +02:00
str = GUID_string ( NULL , & object - > inherited_type . inherited_type ) ;
if ( str = = NULL ) return ;
2009-03-01 04:59:07 +01:00
printf ( " Object type: SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT \n " ) ;
2010-06-21 12:33:57 +02:00
printf ( " Object GUID: %s \n " , str ) ;
talloc_free ( str ) ;
2007-10-11 02:25:44 +02:00
}
}
2000-07-07 06:18:00 +00:00
/****************************************************************************
display sec_ace structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-25 21:29:13 +01:00
void display_sec_ace ( struct security_ace * ace )
2000-07-07 06:18:00 +00:00
{
2018-10-26 14:15:43 +02:00
struct dom_sid_buf sid_str ;
2001-12-11 02:17:26 +00:00
printf ( " \t ACE \n \t \t type: " ) ;
switch ( ace - > type ) {
case SEC_ACE_TYPE_ACCESS_ALLOWED :
printf ( " ACCESS ALLOWED " ) ;
break ;
case SEC_ACE_TYPE_ACCESS_DENIED :
printf ( " ACCESS DENIED " ) ;
2000-07-07 06:18:00 +00:00
break ;
2001-12-11 02:17:26 +00:00
case SEC_ACE_TYPE_SYSTEM_AUDIT :
printf ( " SYSTEM AUDIT " ) ;
break ;
case SEC_ACE_TYPE_SYSTEM_ALARM :
printf ( " SYSTEM ALARM " ) ;
break ;
2022-12-14 10:56:42 +13:00
# define ACE_CASE(x) case x: printf(#x); break
2023-09-06 09:36:45 +12:00
ACE_CASE ( SEC_ACE_TYPE_ALLOWED_COMPOUND ) ;
ACE_CASE ( SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT ) ;
2022-12-14 10:56:42 +13:00
ACE_CASE ( SEC_ACE_TYPE_ACCESS_ALLOWED_CALLBACK ) ;
ACE_CASE ( SEC_ACE_TYPE_ACCESS_DENIED_CALLBACK ) ;
ACE_CASE ( SEC_ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_AUDIT_CALLBACK ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_ALARM_CALLBACK ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT ) ;
ACE_CASE ( SEC_ACE_TYPE_SYSTEM_ALARM_CALLBACK_OBJECT ) ;
# undef ACE_CASE
2001-12-11 02:17:26 +00:00
default :
printf ( " ???? " ) ;
2000-07-07 06:18:00 +00:00
break ;
}
2007-10-11 02:25:44 +02:00
2007-10-26 12:58:01 +02:00
printf ( " (%d) flags: 0x%02x " , ace - > type , ace - > flags ) ;
display_sec_ace_flags ( ace - > flags ) ;
2006-09-20 22:23:12 +00:00
display_sec_access ( & ace - > access_mask ) ;
2018-10-26 14:15:43 +02:00
printf ( " \t \t SID: %s \n \n " , dom_sid_str_buf ( & ace - > trustee , & sid_str ) ) ;
2007-10-11 02:25:44 +02:00
if ( sec_ace_object ( ace - > type ) ) {
disp_sec_ace_object ( & ace - > object . object ) ;
}
2000-07-07 06:18:00 +00:00
}
/****************************************************************************
display sec_acl structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-25 21:29:13 +01:00
void display_sec_acl ( struct security_acl * sec_acl )
2000-07-07 06:18:00 +00:00
{
2011-02-16 09:12:17 +01:00
uint32_t i ;
2000-07-07 06:18:00 +00:00
2011-02-10 10:17:33 +01:00
printf ( " \t ACL \t Num ACEs: \t %u \t revision: \t %x \n " ,
2015-01-14 17:11:12 +01:00
sec_acl - > num_aces , sec_acl - > revision ) ;
2001-12-11 02:17:26 +00:00
printf ( " \t --- \n " ) ;
2007-10-26 12:58:01 +02:00
if ( sec_acl - > size ! = 0 & & sec_acl - > num_aces ! = 0 ) {
for ( i = 0 ; i < sec_acl - > num_aces ; i + + ) {
2006-09-20 22:23:12 +00:00
display_sec_ace ( & sec_acl - > aces [ i ] ) ;
2007-10-26 12:58:01 +02:00
}
}
2000-07-07 06:18:00 +00:00
}
2009-03-15 17:14:25 +01:00
void display_acl_type ( uint16_t type )
2006-03-06 15:22:00 +00:00
{
2009-03-25 21:29:13 +01:00
printf ( " type: 0x%04x: " , type ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_OWNER_DEFAULTED ) /* 0x0001 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_OWNER_DEFAULTED " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_GROUP_DEFAULTED ) /* 0x0002 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_GROUP_DEFAULTED " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_DACL_PRESENT ) /* 0x0004 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_PRESENT " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_DACL_DEFAULTED ) /* 0x0008 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_DEFAULTED " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_SACL_PRESENT ) /* 0x0010 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SACL_PRESENT " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_SACL_DEFAULTED ) /* 0x0020 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SACL_DEFAULTED " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_DACL_TRUSTED ) /* 0x0040 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_TRUSTED " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_SERVER_SECURITY ) /* 0x0080 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SERVER_SECURITY " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_DACL_AUTO_INHERIT_REQ ) /* 0x0100 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_AUTO_INHERIT_REQ " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_SACL_AUTO_INHERIT_REQ ) /* 0x0200 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SACL_AUTO_INHERIT_REQ " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_DACL_AUTO_INHERITED ) /* 0x0400 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_AUTO_INHERITED " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_SACL_AUTO_INHERITED ) /* 0x0800 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SACL_AUTO_INHERITED " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_DACL_PROTECTED ) /* 0x1000 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_DACL_PROTECTED " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_SACL_PROTECTED ) /* 0x2000 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SACL_PROTECTED " ) ;
2007-07-11 15:23:51 +00:00
if ( type & SEC_DESC_RM_CONTROL_VALID ) /* 0x4000 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_RM_CONTROL_VALID " ) ;
2006-03-06 15:22:00 +00:00
if ( type & SEC_DESC_SELF_RELATIVE ) /* 0x8000 */
2009-03-25 21:29:13 +01:00
printf ( " SEC_DESC_SELF_RELATIVE " ) ;
2015-01-14 17:11:12 +01:00
2009-03-25 21:29:13 +01:00
printf ( " \n " ) ;
2006-03-06 15:22:00 +00:00
}
2000-07-07 06:18:00 +00:00
/****************************************************************************
display sec_desc structure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-25 21:29:13 +01:00
void display_sec_desc ( struct security_descriptor * sec )
2000-07-07 06:18:00 +00:00
{
2018-10-26 14:15:43 +02:00
struct dom_sid_buf sid_str ;
2000-07-07 06:18:00 +00:00
2006-03-06 15:22:00 +00:00
if ( ! sec ) {
printf ( " NULL \n " ) ;
return ;
}
printf ( " revision: %d \n " , sec - > revision ) ;
display_acl_type ( sec - > type ) ;
2002-03-07 04:22:16 +00:00
if ( sec - > sacl ) {
printf ( " SACL \n " ) ;
2001-12-11 02:17:26 +00:00
display_sec_acl ( sec - > sacl ) ;
}
2002-03-07 04:22:16 +00:00
if ( sec - > dacl ) {
printf ( " DACL \n " ) ;
2001-12-11 02:17:26 +00:00
display_sec_acl ( sec - > dacl ) ;
2000-07-07 06:18:00 +00:00
}
2002-03-07 04:22:16 +00:00
if ( sec - > owner_sid ) {
2018-10-26 14:15:43 +02:00
printf ( " \t Owner SID: \t %s \n " ,
dom_sid_str_buf ( sec - > owner_sid , & sid_str ) ) ;
2001-12-11 02:17:26 +00:00
}
2006-09-20 22:23:12 +00:00
if ( sec - > group_sid ) {
2018-10-26 14:15:43 +02:00
printf ( " \t Group SID: \t %s \n " ,
dom_sid_str_buf ( sec - > group_sid , & sid_str ) ) ;
2001-12-11 02:17:26 +00:00
}
}