2008-03-09 14:11:42 +00:00
|
|
|
/*
|
2005-01-26 13:58:37 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: ntoskrnl/se/sd.c
|
|
|
|
* PURPOSE: Security manager
|
2005-05-09 01:38:29 +00:00
|
|
|
*
|
2005-01-26 13:58:37 +00:00
|
|
|
* PROGRAMMERS: David Welch <welch@cwcom.net>
|
1999-12-26 15:50:53 +00:00
|
|
|
*/
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2008-04-23 20:38:37 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2005-11-28 23:25:31 +00:00
|
|
|
#if defined (ALLOC_PRAGMA)
|
|
|
|
#pragma alloc_text(INIT, SepInitSDs)
|
|
|
|
#endif
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
2003-02-15 21:07:49 +00:00
|
|
|
|
|
|
|
PSECURITY_DESCRIPTOR SePublicDefaultSd = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR SePublicDefaultUnrestrictedSd = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR SePublicOpenSd = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR SePublicOpenUnrestrictedSd = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR SeSystemDefaultSd = NULL;
|
|
|
|
PSECURITY_DESCRIPTOR SeUnrestrictedSd = NULL;
|
2002-02-20 20:16:49 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2005-09-13 23:28:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
INIT_FUNCTION
|
|
|
|
NTAPI
|
2002-02-20 20:16:49 +00:00
|
|
|
SepInitSDs(VOID)
|
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create PublicDefaultSd */
|
|
|
|
SePublicDefaultSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SePublicDefaultSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SePublicDefaultSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SePublicDefaultSd,
|
|
|
|
TRUE,
|
|
|
|
SePublicDefaultDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create PublicDefaultUnrestrictedSd */
|
|
|
|
SePublicDefaultUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SePublicDefaultUnrestrictedSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SePublicDefaultUnrestrictedSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SePublicDefaultUnrestrictedSd,
|
|
|
|
TRUE,
|
|
|
|
SePublicDefaultUnrestrictedDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create PublicOpenSd */
|
|
|
|
SePublicOpenSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SePublicOpenSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SePublicOpenSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SePublicOpenSd,
|
|
|
|
TRUE,
|
|
|
|
SePublicOpenDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create PublicOpenUnrestrictedSd */
|
|
|
|
SePublicOpenUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SePublicOpenUnrestrictedSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SePublicOpenUnrestrictedSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SePublicOpenUnrestrictedSd,
|
|
|
|
TRUE,
|
|
|
|
SePublicOpenUnrestrictedDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create SystemDefaultSd */
|
|
|
|
SeSystemDefaultSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SeSystemDefaultSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SeSystemDefaultSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SeSystemDefaultSd,
|
|
|
|
TRUE,
|
|
|
|
SeSystemDefaultDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Create UnrestrictedSd */
|
|
|
|
SeUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR), TAG_SD);
|
|
|
|
if (SeUnrestrictedSd == NULL)
|
|
|
|
return FALSE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCreateSecurityDescriptor(SeUnrestrictedSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
RtlSetDaclSecurityDescriptor(SeUnrestrictedSd,
|
|
|
|
TRUE,
|
|
|
|
SeUnrestrictedDacl,
|
|
|
|
FALSE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return TRUE;
|
2002-02-20 20:16:49 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 03:58:35 +00:00
|
|
|
NTSTATUS
|
2006-07-05 20:36:56 +00:00
|
|
|
NTAPI
|
2005-05-09 03:58:35 +00:00
|
|
|
SeSetWorldSecurityDescriptor(SECURITY_INFORMATION SecurityInformation,
|
2005-11-28 21:40:21 +00:00
|
|
|
PISECURITY_DESCRIPTOR SecurityDescriptor,
|
2005-05-09 03:58:35 +00:00
|
|
|
PULONG BufferLength)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
ULONG Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
ULONG SidSize;
|
|
|
|
ULONG SdSize;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE SdRel = (PISECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT("SeSetWorldSecurityDescriptor() called\n");
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityInformation == 0)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_ACCESS_DENIED;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* calculate the minimum size of the buffer */
|
|
|
|
SidSize = RtlLengthSid(SeWorldSid);
|
|
|
|
SdSize = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
|
|
|
if (SecurityInformation & OWNER_SECURITY_INFORMATION)
|
|
|
|
SdSize += SidSize;
|
|
|
|
if (SecurityInformation & GROUP_SECURITY_INFORMATION)
|
|
|
|
SdSize += SidSize;
|
|
|
|
if (SecurityInformation & DACL_SECURITY_INFORMATION)
|
2006-01-14 14:52:50 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
SdSize += sizeof(ACL) + sizeof(ACE) + SidSize;
|
2006-01-14 14:52:50 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (*BufferLength < SdSize)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
*BufferLength = SdSize;
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
*BufferLength = SdSize;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Status = RtlCreateSecurityDescriptorRelative(SdRel,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
return Status;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Current = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityInformation & OWNER_SECURITY_INFORMATION)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)SdRel + Current, SeWorldSid, SidSize);
|
|
|
|
SdRel->Owner = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
Current += SidSize;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityInformation & GROUP_SECURITY_INFORMATION)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)SdRel + Current, SeWorldSid, SidSize);
|
|
|
|
SdRel->Group = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
Current += SidSize;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityInformation & DACL_SECURITY_INFORMATION)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
PACL Dacl = (PACL)((PUCHAR)SdRel + Current);
|
2008-04-23 20:38:37 +00:00
|
|
|
SdRel->Control |= SE_DACL_PRESENT;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Status = RtlCreateAcl(Dacl,
|
|
|
|
sizeof(ACL) + sizeof(ACE) + SidSize,
|
|
|
|
ACL_REVISION);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Status = RtlAddAccessAllowedAce(Dacl,
|
|
|
|
ACL_REVISION,
|
|
|
|
GENERIC_ALL,
|
|
|
|
SeWorldSid);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
SdRel->Dacl = Current;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityInformation & SACL_SECURITY_INFORMATION)
|
2005-05-09 03:58:35 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
/* FIXME - SdRel->Control |= SE_SACL_PRESENT; */
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2005-05-09 03:58:35 +00:00
|
|
|
}
|
|
|
|
|
2005-03-12 22:16:02 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2017-06-19 14:48:59 +00:00
|
|
|
SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
2005-03-12 22:16:02 +00:00
|
|
|
IN KPROCESSOR_MODE AccessMode,
|
|
|
|
IN POOL_TYPE PoolType,
|
|
|
|
IN BOOLEAN CaptureIfKernel,
|
|
|
|
OUT PSECURITY_QUALITY_OF_SERVICE *CapturedSecurityQualityOfService,
|
|
|
|
OUT PBOOLEAN Present)
|
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
PSECURITY_QUALITY_OF_SERVICE CapturedQos;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
PAGED_CODE();
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
ASSERT(CapturedSecurityQualityOfService);
|
|
|
|
ASSERT(Present);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
|
|
|
if (ObjectAttributes != NULL)
|
2005-03-12 22:16:02 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (AccessMode != KernelMode)
|
2005-03-12 22:16:02 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
SECURITY_QUALITY_OF_SERVICE SafeQos;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-03-12 22:16:02 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
ProbeForRead(ObjectAttributes,
|
|
|
|
sizeof(OBJECT_ATTRIBUTES),
|
|
|
|
sizeof(ULONG));
|
2010-05-28 16:28:27 +00:00
|
|
|
if (ObjectAttributes->Length == sizeof(OBJECT_ATTRIBUTES))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (ObjectAttributes->SecurityQualityOfService != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
ProbeForRead(ObjectAttributes->SecurityQualityOfService,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE),
|
|
|
|
sizeof(ULONG));
|
2012-02-05 17:57:34 +00:00
|
|
|
|
2010-05-28 16:28:27 +00:00
|
|
|
if (((PSECURITY_QUALITY_OF_SERVICE)ObjectAttributes->SecurityQualityOfService)->Length ==
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-29 20:40:28 +00:00
|
|
|
/*
|
|
|
|
* Don't allocate memory here because ExAllocate should bugcheck
|
|
|
|
* the system if it's buggy, SEH would catch that! So make a local
|
|
|
|
* copy of the qos structure.
|
|
|
|
*/
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCopyMemory(&SafeQos,
|
|
|
|
ObjectAttributes->SecurityQualityOfService,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE));
|
|
|
|
*Present = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CapturedSecurityQualityOfService = NULL;
|
|
|
|
*Present = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-03-12 22:16:02 +00:00
|
|
|
{
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (*Present)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2015-03-29 06:04:19 +00:00
|
|
|
CapturedQos = ExAllocatePoolWithTag(PoolType,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE),
|
|
|
|
TAG_QOS);
|
2010-05-28 16:28:27 +00:00
|
|
|
if (CapturedQos != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
RtlCopyMemory(CapturedQos,
|
|
|
|
&SafeQos,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE));
|
|
|
|
*CapturedSecurityQualityOfService = CapturedQos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CapturedSecurityQualityOfService = NULL;
|
|
|
|
}
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (ObjectAttributes->Length == sizeof(OBJECT_ATTRIBUTES))
|
2005-03-12 22:16:02 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (CaptureIfKernel)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (ObjectAttributes->SecurityQualityOfService != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-28 16:28:27 +00:00
|
|
|
if (((PSECURITY_QUALITY_OF_SERVICE)ObjectAttributes->SecurityQualityOfService)->Length ==
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2015-03-29 06:04:19 +00:00
|
|
|
CapturedQos = ExAllocatePoolWithTag(PoolType,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE),
|
|
|
|
TAG_QOS);
|
2010-05-28 16:28:27 +00:00
|
|
|
if (CapturedQos != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
RtlCopyMemory(CapturedQos,
|
|
|
|
ObjectAttributes->SecurityQualityOfService,
|
|
|
|
sizeof(SECURITY_QUALITY_OF_SERVICE));
|
|
|
|
*CapturedSecurityQualityOfService = CapturedQos;
|
|
|
|
*Present = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CapturedSecurityQualityOfService = NULL;
|
|
|
|
*Present = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CapturedSecurityQualityOfService = (PSECURITY_QUALITY_OF_SERVICE)ObjectAttributes->SecurityQualityOfService;
|
|
|
|
*Present = (ObjectAttributes->SecurityQualityOfService != NULL);
|
|
|
|
}
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CapturedSecurityQualityOfService = NULL;
|
|
|
|
*Present = FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return Status;
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
2005-09-13 23:28:21 +00:00
|
|
|
NTAPI
|
2005-03-12 22:16:02 +00:00
|
|
|
SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecurityQualityOfService OPTIONAL,
|
|
|
|
IN KPROCESSOR_MODE AccessMode,
|
|
|
|
IN BOOLEAN CaptureIfKernel)
|
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
PAGED_CODE();
|
2010-05-28 16:28:27 +00:00
|
|
|
|
|
|
|
if (CapturedSecurityQualityOfService != NULL &&
|
|
|
|
(AccessMode != KernelMode || CaptureIfKernel))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2015-03-29 06:04:19 +00:00
|
|
|
ExFreePoolWithTag(CapturedSecurityQualityOfService, TAG_QOS);
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2005-03-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
2005-03-12 22:16:02 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
static
|
|
|
|
ULONG
|
|
|
|
DetermineSIDSize(
|
|
|
|
PISID Sid,
|
|
|
|
PULONG OutSAC,
|
|
|
|
KPROCESSOR_MODE ProcessorMode)
|
|
|
|
{
|
|
|
|
ULONG Size;
|
|
|
|
|
|
|
|
if (!Sid)
|
|
|
|
{
|
|
|
|
*OutSAC = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProcessorMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* Securely access the buffers! */
|
|
|
|
*OutSAC = ProbeForReadUchar(&Sid->SubAuthorityCount);
|
|
|
|
Size = RtlLengthRequiredSid(*OutSAC);
|
|
|
|
ProbeForRead(Sid, Size, sizeof(ULONG));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*OutSAC = Sid->SubAuthorityCount;
|
|
|
|
Size = RtlLengthRequiredSid(*OutSAC);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
ULONG
|
|
|
|
DetermineACLSize(
|
|
|
|
PACL Acl,
|
|
|
|
KPROCESSOR_MODE ProcessorMode)
|
|
|
|
{
|
|
|
|
ULONG Size;
|
|
|
|
|
|
|
|
if (!Acl) return 0;
|
|
|
|
|
|
|
|
if (ProcessorMode == KernelMode) return Acl->AclSize;
|
|
|
|
|
|
|
|
/* Probe the buffers! */
|
|
|
|
Size = ProbeForReadUshort(&Acl->AclSize);
|
|
|
|
ProbeForRead(Acl, Size, sizeof(ULONG));
|
|
|
|
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
2004-08-03 19:20:39 +00:00
|
|
|
NTSTATUS
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2012-02-05 17:57:34 +00:00
|
|
|
SeCaptureSecurityDescriptor(
|
|
|
|
IN PSECURITY_DESCRIPTOR _OriginalSecurityDescriptor,
|
|
|
|
IN KPROCESSOR_MODE CurrentMode,
|
|
|
|
IN POOL_TYPE PoolType,
|
|
|
|
IN BOOLEAN CaptureIfKernel,
|
|
|
|
OUT PSECURITY_DESCRIPTOR *CapturedSecurityDescriptor)
|
2004-08-03 19:20:39 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
PISECURITY_DESCRIPTOR OriginalDescriptor = _OriginalSecurityDescriptor;
|
2008-04-23 20:38:37 +00:00
|
|
|
SECURITY_DESCRIPTOR DescriptorCopy;
|
2012-02-05 17:57:34 +00:00
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE NewDescriptor;
|
2008-04-23 20:38:37 +00:00
|
|
|
ULONG OwnerSAC = 0, GroupSAC = 0;
|
|
|
|
ULONG OwnerSize = 0, GroupSize = 0;
|
|
|
|
ULONG SaclSize = 0, DaclSize = 0;
|
|
|
|
ULONG DescriptorSize = 0;
|
2012-02-05 17:57:34 +00:00
|
|
|
ULONG Offset;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (!OriginalDescriptor)
|
2005-01-21 02:14:52 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Nothing to do... */
|
|
|
|
*CapturedSecurityDescriptor = NULL;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Quick path */
|
|
|
|
if (CurrentMode == KernelMode && !CaptureIfKernel)
|
|
|
|
{
|
|
|
|
/* Check descriptor version */
|
|
|
|
if (OriginalDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION1)
|
|
|
|
{
|
|
|
|
return STATUS_UNKNOWN_REVISION;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
*CapturedSecurityDescriptor = _OriginalSecurityDescriptor;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
if (CurrentMode != KernelMode)
|
|
|
|
{
|
|
|
|
ProbeForRead(OriginalDescriptor,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR_RELATIVE),
|
|
|
|
sizeof(ULONG));
|
|
|
|
}
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Check the descriptor version */
|
|
|
|
if (OriginalDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION1)
|
|
|
|
{
|
|
|
|
_SEH2_YIELD(return STATUS_UNKNOWN_REVISION);
|
2005-02-12 11:47:03 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
|
|
|
|
if (CurrentMode != KernelMode)
|
2005-02-12 11:47:03 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Get the size of the descriptor */
|
|
|
|
DescriptorSize = (OriginalDescriptor->Control & SE_SELF_RELATIVE) ?
|
|
|
|
sizeof(SECURITY_DESCRIPTOR_RELATIVE) : sizeof(SECURITY_DESCRIPTOR);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Probe the entire security descriptor structure. The SIDs
|
|
|
|
* and ACLs will be probed and copied later though */
|
|
|
|
ProbeForRead(OriginalDescriptor, DescriptorSize, sizeof(ULONG));
|
2005-02-12 11:47:03 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Now capture all fields and convert to an absolute descriptor */
|
|
|
|
DescriptorCopy.Revision = OriginalDescriptor->Revision;
|
|
|
|
DescriptorCopy.Sbz1 = OriginalDescriptor->Sbz1;
|
|
|
|
DescriptorCopy.Control = OriginalDescriptor->Control & ~SE_SELF_RELATIVE;
|
|
|
|
DescriptorCopy.Owner = SepGetOwnerFromDescriptor(OriginalDescriptor);
|
|
|
|
DescriptorCopy.Group = SepGetGroupFromDescriptor(OriginalDescriptor);
|
|
|
|
DescriptorCopy.Sacl = SepGetSaclFromDescriptor(OriginalDescriptor);
|
|
|
|
DescriptorCopy.Dacl = SepGetDaclFromDescriptor(OriginalDescriptor);
|
|
|
|
DescriptorSize = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
|
|
|
|
|
|
|
/* Determine owner and group sizes */
|
|
|
|
OwnerSize = DetermineSIDSize(DescriptorCopy.Owner, &OwnerSAC, CurrentMode);
|
|
|
|
DescriptorSize += ROUND_UP(OwnerSize, sizeof(ULONG));
|
|
|
|
GroupSize = DetermineSIDSize(DescriptorCopy.Group, &GroupSAC, CurrentMode);
|
|
|
|
DescriptorSize += ROUND_UP(GroupSize, sizeof(ULONG));
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Determine the size of the ACLs */
|
|
|
|
if (DescriptorCopy.Control & SE_SACL_PRESENT)
|
|
|
|
{
|
|
|
|
/* Get the size and probe if user mode */
|
|
|
|
SaclSize = DetermineACLSize(DescriptorCopy.Sacl, CurrentMode);
|
|
|
|
DescriptorSize += ROUND_UP(SaclSize, sizeof(ULONG));
|
2005-02-12 11:47:03 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (DescriptorCopy.Control & SE_DACL_PRESENT)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
/* Get the size and probe if user mode */
|
|
|
|
DaclSize = DetermineACLSize(DescriptorCopy.Dacl, CurrentMode);
|
|
|
|
DescriptorSize += ROUND_UP(DaclSize, sizeof(ULONG));
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
}
|
2016-09-24 09:34:09 +00:00
|
|
|
_SEH2_END;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/*
|
|
|
|
* Allocate enough memory to store a complete copy of a self-relative
|
|
|
|
* security descriptor
|
|
|
|
*/
|
|
|
|
NewDescriptor = ExAllocatePoolWithTag(PoolType,
|
|
|
|
DescriptorSize,
|
|
|
|
TAG_SD);
|
|
|
|
if (!NewDescriptor) return STATUS_INSUFFICIENT_RESOURCES;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlZeroMemory(NewDescriptor, DescriptorSize);
|
|
|
|
NewDescriptor->Revision = DescriptorCopy.Revision;
|
|
|
|
NewDescriptor->Sbz1 = DescriptorCopy.Sbz1;
|
|
|
|
NewDescriptor->Control = DescriptorCopy.Control | SE_SELF_RELATIVE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2010-05-29 20:40:28 +00:00
|
|
|
/*
|
2012-02-05 17:57:34 +00:00
|
|
|
* Setup the offsets and copy the SIDs and ACLs to the new
|
|
|
|
* self-relative security descriptor. Probing the pointers is not
|
|
|
|
* neccessary anymore as we did that when collecting the sizes!
|
|
|
|
* Make sure to validate the SIDs and ACLs *again* as they could have
|
|
|
|
* been modified in the meanwhile!
|
2010-05-29 20:40:28 +00:00
|
|
|
*/
|
2012-02-05 17:57:34 +00:00
|
|
|
Offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (DescriptorCopy.Owner)
|
|
|
|
{
|
|
|
|
if (!RtlValidSid(DescriptorCopy.Owner)) RtlRaiseStatus(STATUS_INVALID_SID);
|
|
|
|
NewDescriptor->Owner = Offset;
|
|
|
|
RtlCopyMemory((PUCHAR)NewDescriptor + Offset,
|
|
|
|
DescriptorCopy.Owner,
|
|
|
|
OwnerSize);
|
|
|
|
Offset += ROUND_UP(OwnerSize, sizeof(ULONG));
|
|
|
|
}
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (DescriptorCopy.Group)
|
|
|
|
{
|
|
|
|
if (!RtlValidSid(DescriptorCopy.Group)) RtlRaiseStatus(STATUS_INVALID_SID);
|
|
|
|
NewDescriptor->Group = Offset;
|
|
|
|
RtlCopyMemory((PUCHAR)NewDescriptor + Offset,
|
|
|
|
DescriptorCopy.Group,
|
|
|
|
GroupSize);
|
|
|
|
Offset += ROUND_UP(GroupSize, sizeof(ULONG));
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (DescriptorCopy.Sacl)
|
|
|
|
{
|
|
|
|
if (!RtlValidAcl(DescriptorCopy.Sacl)) RtlRaiseStatus(STATUS_INVALID_ACL);
|
|
|
|
NewDescriptor->Sacl = Offset;
|
|
|
|
RtlCopyMemory((PUCHAR)NewDescriptor + Offset,
|
|
|
|
DescriptorCopy.Sacl,
|
|
|
|
SaclSize);
|
|
|
|
Offset += ROUND_UP(SaclSize, sizeof(ULONG));
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
|
|
|
|
if (DescriptorCopy.Dacl)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
if (!RtlValidAcl(DescriptorCopy.Dacl)) RtlRaiseStatus(STATUS_INVALID_ACL);
|
|
|
|
NewDescriptor->Dacl = Offset;
|
|
|
|
RtlCopyMemory((PUCHAR)NewDescriptor + Offset,
|
|
|
|
DescriptorCopy.Dacl,
|
|
|
|
DaclSize);
|
|
|
|
Offset += ROUND_UP(DaclSize, sizeof(ULONG));
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
|
|
|
|
/* Make sure the size was correct */
|
|
|
|
ASSERT(Offset == DescriptorSize);
|
2005-01-21 02:14:52 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-01-21 02:14:52 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
/* We failed to copy the data to the new descriptor */
|
|
|
|
ExFreePoolWithTag(NewDescriptor, TAG_SD);
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-01-21 02:14:52 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
_SEH2_END;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
/*
|
|
|
|
* We're finally done!
|
|
|
|
* Copy the pointer to the captured descriptor to to the caller.
|
|
|
|
*/
|
|
|
|
*CapturedSecurityDescriptor = NewDescriptor;
|
|
|
|
return STATUS_SUCCESS;
|
2004-08-03 19:20:39 +00:00
|
|
|
}
|
2002-02-20 20:16:49 +00:00
|
|
|
|
2004-05-20 12:42:51 +00:00
|
|
|
/*
|
2004-07-31 12:21:19 +00:00
|
|
|
* @implemented
|
2004-05-20 12:42:51 +00:00
|
|
|
*/
|
2014-11-04 18:40:24 +00:00
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeQuerySecurityDescriptorInfo(
|
|
|
|
_In_ PSECURITY_INFORMATION SecurityInformation,
|
|
|
|
_Out_writes_bytes_(*Length) PSECURITY_DESCRIPTOR SecurityDescriptor,
|
|
|
|
_Inout_ PULONG Length,
|
|
|
|
_Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor)
|
2004-05-20 12:42:51 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
PISECURITY_DESCRIPTOR ObjectSd;
|
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE RelSD;
|
|
|
|
PSID Owner = NULL;
|
|
|
|
PSID Group = NULL;
|
|
|
|
PACL Dacl = NULL;
|
|
|
|
PACL Sacl = NULL;
|
|
|
|
ULONG OwnerLength = 0;
|
|
|
|
ULONG GroupLength = 0;
|
|
|
|
ULONG DaclLength = 0;
|
|
|
|
ULONG SaclLength = 0;
|
2014-11-04 18:47:13 +00:00
|
|
|
SECURITY_DESCRIPTOR_CONTROL Control = 0;
|
2008-04-23 20:38:37 +00:00
|
|
|
ULONG_PTR Current;
|
|
|
|
ULONG SdLength;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-04 18:40:24 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
RelSD = (PISECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (*ObjectsSecurityDescriptor == NULL)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
if (*Length < sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
|
|
|
{
|
|
|
|
*Length = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
*Length = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
|
|
|
RtlCreateSecurityDescriptorRelative(RelSD,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
return STATUS_SUCCESS;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
ObjectSd = *ObjectsSecurityDescriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Calculate the required security descriptor length */
|
|
|
|
Control = SE_SELF_RELATIVE;
|
|
|
|
if ((*SecurityInformation & OWNER_SECURITY_INFORMATION) &&
|
|
|
|
(ObjectSd->Owner != NULL))
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
Owner = (PSID)((ULONG_PTR)ObjectSd->Owner + (ULONG_PTR)ObjectSd);
|
|
|
|
OwnerLength = ROUND_UP(RtlLengthSid(Owner), 4);
|
|
|
|
Control |= (ObjectSd->Control & SE_OWNER_DEFAULTED);
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if ((*SecurityInformation & GROUP_SECURITY_INFORMATION) &&
|
|
|
|
(ObjectSd->Group != NULL))
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
Group = (PSID)((ULONG_PTR)ObjectSd->Group + (ULONG_PTR)ObjectSd);
|
|
|
|
GroupLength = ROUND_UP(RtlLengthSid(Group), 4);
|
|
|
|
Control |= (ObjectSd->Control & SE_GROUP_DEFAULTED);
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if ((*SecurityInformation & DACL_SECURITY_INFORMATION) &&
|
|
|
|
(ObjectSd->Control & SE_DACL_PRESENT))
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
if (ObjectSd->Dacl != NULL)
|
|
|
|
{
|
|
|
|
Dacl = (PACL)((ULONG_PTR)ObjectSd->Dacl + (ULONG_PTR)ObjectSd);
|
|
|
|
DaclLength = ROUND_UP((ULONG)Dacl->AclSize, 4);
|
|
|
|
}
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Control |= (ObjectSd->Control & (SE_DACL_DEFAULTED | SE_DACL_PRESENT));
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if ((*SecurityInformation & SACL_SECURITY_INFORMATION) &&
|
|
|
|
(ObjectSd->Control & SE_SACL_PRESENT))
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
if (ObjectSd->Sacl != NULL)
|
|
|
|
{
|
|
|
|
Sacl = (PACL)((ULONG_PTR)ObjectSd->Sacl + (ULONG_PTR)ObjectSd);
|
|
|
|
SaclLength = ROUND_UP(Sacl->AclSize, 4);
|
|
|
|
}
|
2010-05-29 20:40:28 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Control |= (ObjectSd->Control & (SE_SACL_DEFAULTED | SE_SACL_PRESENT));
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength = OwnerLength + GroupLength + DaclLength +
|
|
|
|
SaclLength + sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
|
|
|
if (*Length < SdLength)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
*Length = SdLength;
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Build the new security descrtiptor */
|
|
|
|
RtlCreateSecurityDescriptorRelative(RelSD,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION);
|
2014-11-04 18:47:13 +00:00
|
|
|
RelSD->Control = Control;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
Current = (ULONG_PTR)(RelSD + 1);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (OwnerLength != 0)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCopyMemory((PVOID)Current,
|
|
|
|
Owner,
|
|
|
|
OwnerLength);
|
|
|
|
RelSD->Owner = (ULONG)(Current - (ULONG_PTR)SecurityDescriptor);
|
|
|
|
Current += OwnerLength;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (GroupLength != 0)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCopyMemory((PVOID)Current,
|
|
|
|
Group,
|
|
|
|
GroupLength);
|
|
|
|
RelSD->Group = (ULONG)(Current - (ULONG_PTR)SecurityDescriptor);
|
|
|
|
Current += GroupLength;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (DaclLength != 0)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCopyMemory((PVOID)Current,
|
|
|
|
Dacl,
|
|
|
|
DaclLength);
|
|
|
|
RelSD->Dacl = (ULONG)(Current - (ULONG_PTR)SecurityDescriptor);
|
|
|
|
Current += DaclLength;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SaclLength != 0)
|
2004-07-31 12:21:19 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
RtlCopyMemory((PVOID)Current,
|
|
|
|
Sacl,
|
|
|
|
SaclLength);
|
|
|
|
RelSD->Sacl = (ULONG)(Current - (ULONG_PTR)SecurityDescriptor);
|
|
|
|
Current += SaclLength;
|
2004-07-31 12:21:19 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
*Length = SdLength;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-20 12:42:51 +00:00
|
|
|
}
|
|
|
|
|
2004-08-03 19:20:39 +00:00
|
|
|
/*
|
2005-01-21 02:14:52 +00:00
|
|
|
* @implemented
|
2004-08-03 19:20:39 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2008-04-23 20:38:37 +00:00
|
|
|
SeReleaseSecurityDescriptor(IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor,
|
|
|
|
IN KPROCESSOR_MODE CurrentMode,
|
|
|
|
IN BOOLEAN CaptureIfKernelMode)
|
2004-08-03 19:20:39 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
PAGED_CODE();
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2010-05-29 20:40:28 +00:00
|
|
|
/*
|
|
|
|
* WARNING! You need to call this function with the same value for CurrentMode
|
|
|
|
* and CaptureIfKernelMode that you previously passed to
|
|
|
|
* SeCaptureSecurityDescriptor() in order to avoid memory leaks!
|
|
|
|
*/
|
|
|
|
if (CapturedSecurityDescriptor != NULL &&
|
|
|
|
(CurrentMode != KernelMode ||
|
|
|
|
(CurrentMode == KernelMode && CaptureIfKernelMode)))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2010-05-29 20:40:28 +00:00
|
|
|
/* Only delete the descriptor when SeCaptureSecurityDescriptor() allocated one! */
|
2008-08-31 15:29:21 +00:00
|
|
|
ExFreePoolWithTag(CapturedSecurityDescriptor, TAG_SD);
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-03 19:20:39 +00:00
|
|
|
}
|
2004-05-20 12:42:51 +00:00
|
|
|
|
|
|
|
/*
|
2008-03-31 20:07:02 +00:00
|
|
|
* @implemented
|
2004-05-20 12:42:51 +00:00
|
|
|
*/
|
2014-11-04 18:40:24 +00:00
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeSetSecurityDescriptorInfo(
|
|
|
|
_In_opt_ PVOID Object,
|
|
|
|
_In_ PSECURITY_INFORMATION SecurityInformation,
|
|
|
|
_In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
|
|
|
|
_Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
|
|
|
|
_In_ POOL_TYPE PoolType,
|
|
|
|
_In_ PGENERIC_MAPPING GenericMapping)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
return SeSetSecurityDescriptorInfoEx(Object,
|
|
|
|
SecurityInformation,
|
|
|
|
SecurityDescriptor,
|
|
|
|
ObjectsSecurityDescriptor,
|
|
|
|
0,
|
|
|
|
PoolType,
|
|
|
|
GenericMapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeSetSecurityDescriptorInfoEx(
|
|
|
|
_In_opt_ PVOID Object,
|
|
|
|
_In_ PSECURITY_INFORMATION _SecurityInformation,
|
|
|
|
_In_ PSECURITY_DESCRIPTOR _SecurityDescriptor,
|
|
|
|
_Inout_ PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
|
|
|
|
_In_ ULONG AutoInheritFlags,
|
|
|
|
_In_ POOL_TYPE PoolType,
|
|
|
|
_In_ PGENERIC_MAPPING GenericMapping)
|
2004-05-20 12:42:51 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE ObjectSd;
|
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE NewSd;
|
2008-03-31 20:07:02 +00:00
|
|
|
PISECURITY_DESCRIPTOR SecurityDescriptor = _SecurityDescriptor;
|
2014-11-04 18:47:13 +00:00
|
|
|
PSID Owner;
|
|
|
|
PSID Group;
|
|
|
|
PACL Dacl;
|
|
|
|
PACL Sacl;
|
|
|
|
ULONG OwnerLength;
|
|
|
|
ULONG GroupLength;
|
|
|
|
ULONG DaclLength;
|
|
|
|
ULONG SaclLength;
|
|
|
|
SECURITY_DESCRIPTOR_CONTROL Control = 0;
|
2012-02-05 17:57:34 +00:00
|
|
|
ULONG Current;
|
2008-03-31 20:07:02 +00:00
|
|
|
SECURITY_INFORMATION SecurityInformation;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-04 18:40:24 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2008-04-01 00:31:56 +00:00
|
|
|
ObjectSd = *ObjectsSecurityDescriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2010-05-29 20:40:28 +00:00
|
|
|
/* The object does not have a security descriptor. */
|
2008-04-01 00:31:56 +00:00
|
|
|
if (!ObjectSd)
|
2010-05-29 20:40:28 +00:00
|
|
|
return STATUS_NO_SECURITY_ON_OBJECT;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-06-26 08:36:58 +00:00
|
|
|
ASSERT(ObjectSd->Control & SE_SELF_RELATIVE);
|
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
SecurityInformation = *_SecurityInformation;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
/* Get owner and owner size */
|
|
|
|
if (SecurityInformation & OWNER_SECURITY_INFORMATION)
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Owner = SepGetOwnerFromDescriptor(SecurityDescriptor);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (SecurityDescriptor->Control & SE_OWNER_DEFAULTED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Owner = SepGetOwnerFromDescriptor(ObjectSd);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (ObjectSd->Control & SE_OWNER_DEFAULTED);
|
|
|
|
}
|
2014-11-04 18:47:13 +00:00
|
|
|
OwnerLength = Owner ? RtlLengthSid(Owner) : 0;
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(OwnerLength % sizeof(ULONG) == 0);
|
2012-02-05 17:57:34 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
/* Get group and group size */
|
|
|
|
if (SecurityInformation & GROUP_SECURITY_INFORMATION)
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Group = SepGetGroupFromDescriptor(SecurityDescriptor);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (SecurityDescriptor->Control & SE_GROUP_DEFAULTED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Group = SepGetGroupFromDescriptor(ObjectSd);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (ObjectSd->Control & SE_GROUP_DEFAULTED);
|
|
|
|
}
|
2014-11-04 18:47:13 +00:00
|
|
|
GroupLength = Group ? RtlLengthSid(Group) : 0;
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(GroupLength % sizeof(ULONG) == 0);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
/* Get DACL and DACL size */
|
|
|
|
if (SecurityInformation & DACL_SECURITY_INFORMATION)
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Dacl = SepGetDaclFromDescriptor(SecurityDescriptor);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (SecurityDescriptor->Control & (SE_DACL_DEFAULTED | SE_DACL_PRESENT));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Dacl = SepGetDaclFromDescriptor(ObjectSd);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (ObjectSd->Control & (SE_DACL_DEFAULTED | SE_DACL_PRESENT));
|
|
|
|
}
|
2014-11-04 18:47:13 +00:00
|
|
|
DaclLength = Dacl ? ROUND_UP((ULONG)Dacl->AclSize, 4) : 0;
|
2012-02-05 17:57:34 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
/* Get SACL and SACL size */
|
|
|
|
if (SecurityInformation & SACL_SECURITY_INFORMATION)
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Sacl = SepGetSaclFromDescriptor(SecurityDescriptor);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (SecurityDescriptor->Control & (SE_SACL_DEFAULTED | SE_SACL_PRESENT));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 18:47:13 +00:00
|
|
|
Sacl = SepGetSaclFromDescriptor(ObjectSd);
|
2008-03-31 20:07:02 +00:00
|
|
|
Control |= (ObjectSd->Control & (SE_SACL_DEFAULTED | SE_SACL_PRESENT));
|
|
|
|
}
|
2014-11-04 18:47:13 +00:00
|
|
|
SaclLength = Sacl ? ROUND_UP((ULONG)Sacl->AclSize, 4) : 0;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2015-03-29 06:04:19 +00:00
|
|
|
NewSd = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(SECURITY_DESCRIPTOR_RELATIVE) +
|
|
|
|
OwnerLength + GroupLength +
|
|
|
|
DaclLength + SaclLength,
|
|
|
|
TAG_SD);
|
2008-03-31 20:07:02 +00:00
|
|
|
if (NewSd == NULL)
|
|
|
|
{
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
RtlCreateSecurityDescriptor(NewSd,
|
|
|
|
SECURITY_DESCRIPTOR_REVISION1);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
/* We always build a self-relative descriptor */
|
2014-11-04 18:47:13 +00:00
|
|
|
NewSd->Control = Control | SE_SELF_RELATIVE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Current = sizeof(SECURITY_DESCRIPTOR);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
if (OwnerLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)NewSd + Current, Owner, OwnerLength);
|
|
|
|
NewSd->Owner = Current;
|
2008-03-31 20:07:02 +00:00
|
|
|
Current += OwnerLength;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
if (GroupLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)NewSd + Current, Group, GroupLength);
|
|
|
|
NewSd->Group = Current;
|
2008-03-31 20:07:02 +00:00
|
|
|
Current += GroupLength;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
if (DaclLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)NewSd + Current, Dacl, DaclLength);
|
|
|
|
NewSd->Dacl = Current;
|
2008-03-31 20:07:02 +00:00
|
|
|
Current += DaclLength;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
if (SaclLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)NewSd + Current, Sacl, SaclLength);
|
|
|
|
NewSd->Sacl = Current;
|
2008-03-31 20:07:02 +00:00
|
|
|
Current += SaclLength;
|
2010-05-28 16:28:27 +00:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:02 +00:00
|
|
|
*ObjectsSecurityDescriptor = NewSd;
|
|
|
|
return STATUS_SUCCESS;
|
2004-08-03 19:20:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-20 12:42:51 +00:00
|
|
|
|
|
|
|
/*
|
2004-07-26 12:44:40 +00:00
|
|
|
* @implemented
|
2004-05-20 12:42:51 +00:00
|
|
|
*/
|
2008-11-29 20:47:48 +00:00
|
|
|
BOOLEAN NTAPI
|
2004-05-20 12:42:51 +00:00
|
|
|
SeValidSecurityDescriptor(IN ULONG Length,
|
2008-04-23 20:38:37 +00:00
|
|
|
IN PSECURITY_DESCRIPTOR _SecurityDescriptor)
|
2004-05-20 12:42:51 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
ULONG SdLength;
|
|
|
|
PISID Sid;
|
|
|
|
PACL Acl;
|
2012-02-05 17:57:34 +00:00
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE SecurityDescriptor = _SecurityDescriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (Length < SECURITY_DESCRIPTOR_MIN_LENGTH)
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("Invalid Security Descriptor revision\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION1)
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("Invalid Security Descriptor revision\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (!(SecurityDescriptor->Control & SE_SELF_RELATIVE))
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("No self-relative Security Descriptor\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength = sizeof(SECURITY_DESCRIPTOR);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Check Owner SID */
|
2014-11-13 20:10:52 +00:00
|
|
|
if (!SecurityDescriptor->Owner)
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("No Owner SID\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Owner % sizeof(ULONG))
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("Invalid Owner SID alignment\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Sid = (PISID)((ULONG_PTR)SecurityDescriptor + SecurityDescriptor->Owner);
|
2008-04-23 20:38:37 +00:00
|
|
|
if (Sid->Revision != SID_REVISION)
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("Invalid Owner SID revision\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength += (sizeof(SID) + (Sid->SubAuthorityCount - 1) * sizeof(ULONG));
|
|
|
|
if (Length < SdLength)
|
2004-07-26 12:44:40 +00:00
|
|
|
{
|
2008-04-23 20:38:37 +00:00
|
|
|
DPRINT1("Invalid Owner SID size\n");
|
|
|
|
return FALSE;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Check Group SID */
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Group)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Group % sizeof(ULONG))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Invalid Group SID alignment\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Sid = (PSID)((ULONG_PTR)SecurityDescriptor + SecurityDescriptor->Group);
|
2008-04-23 20:38:37 +00:00
|
|
|
if (Sid->Revision != SID_REVISION)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid Group SID revision\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength += (sizeof(SID) + (Sid->SubAuthorityCount - 1) * sizeof(ULONG));
|
|
|
|
if (Length < SdLength)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid Group SID size\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Check DACL */
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Dacl)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Dacl % sizeof(ULONG))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Invalid DACL alignment\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Acl = (PACL)((ULONG_PTR)SecurityDescriptor + SecurityDescriptor->Dacl);
|
2013-05-24 09:07:46 +00:00
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
2008-04-23 20:38:37 +00:00
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid DACL revision\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength += Acl->AclSize;
|
|
|
|
if (Length < SdLength)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid DACL size\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Check SACL */
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Sacl)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
if (SecurityDescriptor->Sacl % sizeof(ULONG))
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Invalid SACL alignment\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Acl = (PACL)((ULONG_PTR)SecurityDescriptor + SecurityDescriptor->Sacl);
|
2008-04-23 20:38:37 +00:00
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid SACL revision\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
SdLength += Acl->AclSize;
|
|
|
|
if (Length < SdLength)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid SACL size\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-07-26 12:44:40 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2014-11-02 15:41:20 +00:00
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeDeassignSecurity(
|
|
|
|
_Inout_ PSECURITY_DESCRIPTOR *SecurityDescriptor)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
PAGED_CODE();
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (*SecurityDescriptor != NULL)
|
|
|
|
{
|
2011-06-01 13:39:36 +00:00
|
|
|
ExFreePoolWithTag(*SecurityDescriptor, TAG_SD);
|
2008-04-23 20:38:37 +00:00
|
|
|
*SecurityDescriptor = NULL;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-07-26 12:44:40 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2014-11-02 15:41:20 +00:00
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeAssignSecurityEx(
|
|
|
|
_In_opt_ PSECURITY_DESCRIPTOR _ParentDescriptor,
|
|
|
|
_In_opt_ PSECURITY_DESCRIPTOR _ExplicitDescriptor,
|
|
|
|
_Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
|
|
|
|
_In_opt_ GUID *ObjectType,
|
|
|
|
_In_ BOOLEAN IsDirectoryObject,
|
|
|
|
_In_ ULONG AutoInheritFlags,
|
|
|
|
_In_ PSECURITY_SUBJECT_CONTEXT SubjectContext,
|
|
|
|
_In_ PGENERIC_MAPPING GenericMapping,
|
|
|
|
_In_ POOL_TYPE PoolType)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
PISECURITY_DESCRIPTOR ParentDescriptor = _ParentDescriptor;
|
|
|
|
PISECURITY_DESCRIPTOR ExplicitDescriptor = _ExplicitDescriptor;
|
2012-02-05 17:57:34 +00:00
|
|
|
PISECURITY_DESCRIPTOR_RELATIVE Descriptor;
|
2008-04-23 20:38:37 +00:00
|
|
|
PTOKEN Token;
|
2014-11-04 12:35:22 +00:00
|
|
|
ULONG OwnerLength;
|
|
|
|
ULONG GroupLength;
|
|
|
|
ULONG DaclLength;
|
|
|
|
ULONG SaclLength;
|
|
|
|
ULONG Length;
|
|
|
|
SECURITY_DESCRIPTOR_CONTROL Control = 0;
|
2012-02-05 17:57:34 +00:00
|
|
|
ULONG Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
PSID Owner = NULL;
|
|
|
|
PSID Group = NULL;
|
2014-11-04 22:44:50 +00:00
|
|
|
PACL ExplicitAcl;
|
|
|
|
BOOLEAN ExplicitPresent;
|
|
|
|
BOOLEAN ExplicitDefaulted;
|
|
|
|
PACL ParentAcl;
|
2008-04-23 20:38:37 +00:00
|
|
|
PACL Dacl = NULL;
|
|
|
|
PACL Sacl = NULL;
|
2014-11-04 22:44:50 +00:00
|
|
|
BOOLEAN DaclIsInherited;
|
|
|
|
BOOLEAN SaclIsInherited;
|
|
|
|
BOOLEAN DaclPresent;
|
|
|
|
BOOLEAN SaclPresent;
|
|
|
|
NTSTATUS Status;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-02 15:41:20 +00:00
|
|
|
DBG_UNREFERENCED_PARAMETER(ObjectType);
|
|
|
|
DBG_UNREFERENCED_PARAMETER(AutoInheritFlags);
|
|
|
|
UNREFERENCED_PARAMETER(PoolType);
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
PAGED_CODE();
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-04 12:35:22 +00:00
|
|
|
*NewDescriptor = NULL;
|
|
|
|
|
|
|
|
if (!ARGUMENT_PRESENT(SubjectContext))
|
|
|
|
{
|
|
|
|
return STATUS_NO_TOKEN;
|
|
|
|
}
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Lock subject context */
|
|
|
|
SeLockSubjectContext(SubjectContext);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SubjectContext->ClientToken != NULL)
|
|
|
|
{
|
|
|
|
Token = SubjectContext->ClientToken;
|
2004-07-26 12:44:40 +00:00
|
|
|
}
|
2008-04-23 20:38:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Token = SubjectContext->PrimaryToken;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Inherit the Owner SID */
|
2012-02-05 17:57:34 +00:00
|
|
|
if (ExplicitDescriptor != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
|
|
|
DPRINT("Use explicit owner sid!\n");
|
2012-02-05 17:57:34 +00:00
|
|
|
Owner = SepGetOwnerFromDescriptor(ExplicitDescriptor);
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
if (!Owner)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2015-02-01 23:01:31 +00:00
|
|
|
if (AutoInheritFlags & 0x20 /* FIXME: SEF_DEFAULT_OWNER_FROM_PARENT */)
|
|
|
|
{
|
|
|
|
DPRINT("Use parent owner sid!\n");
|
|
|
|
if (!ARGUMENT_PRESENT(ParentDescriptor))
|
|
|
|
{
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
|
|
|
return STATUS_INVALID_OWNER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Owner = SepGetOwnerFromDescriptor(ParentDescriptor);
|
|
|
|
if (!Owner)
|
|
|
|
{
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
|
|
|
return STATUS_INVALID_OWNER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT("Use token owner sid!\n");
|
|
|
|
Owner = Token->UserAndGroups[Token->DefaultOwnerIndex].Sid;
|
|
|
|
}
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2014-11-04 12:35:22 +00:00
|
|
|
OwnerLength = RtlLengthSid(Owner);
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(OwnerLength % sizeof(ULONG) == 0);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Inherit the Group SID */
|
2012-02-05 17:57:34 +00:00
|
|
|
if (ExplicitDescriptor != NULL)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
Group = SepGetGroupFromDescriptor(ExplicitDescriptor);
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2012-02-05 17:57:34 +00:00
|
|
|
if (!Group)
|
2008-04-23 20:38:37 +00:00
|
|
|
{
|
2015-02-01 23:01:31 +00:00
|
|
|
if (AutoInheritFlags & 0x40 /* FIXME: SEF_DEFAULT_GROUP_FROM_PARENT */)
|
|
|
|
{
|
|
|
|
DPRINT("Use parent group sid!\n");
|
|
|
|
if (!ARGUMENT_PRESENT(ParentDescriptor))
|
|
|
|
{
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
|
|
|
return STATUS_INVALID_PRIMARY_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
Group = SepGetGroupFromDescriptor(ParentDescriptor);
|
|
|
|
if (!Group)
|
|
|
|
{
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
|
|
|
return STATUS_INVALID_PRIMARY_GROUP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT("Use token group sid!\n");
|
|
|
|
Group = Token->PrimaryGroup;
|
|
|
|
}
|
2014-11-04 12:35:22 +00:00
|
|
|
}
|
|
|
|
if (!Group)
|
|
|
|
{
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
|
|
|
return STATUS_INVALID_PRIMARY_GROUP;
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2014-11-04 12:35:22 +00:00
|
|
|
GroupLength = RtlLengthSid(Group);
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(GroupLength % sizeof(ULONG) == 0);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Inherit the DACL */
|
2014-11-04 22:44:50 +00:00
|
|
|
DaclLength = 0;
|
|
|
|
ExplicitAcl = NULL;
|
|
|
|
ExplicitPresent = FALSE;
|
|
|
|
ExplicitDefaulted = FALSE;
|
2008-04-23 20:38:37 +00:00
|
|
|
if (ExplicitDescriptor != NULL &&
|
2014-11-04 22:44:50 +00:00
|
|
|
(ExplicitDescriptor->Control & SE_DACL_PRESENT))
|
|
|
|
{
|
|
|
|
ExplicitAcl = SepGetDaclFromDescriptor(ExplicitDescriptor);
|
|
|
|
ExplicitPresent = TRUE;
|
|
|
|
if (ExplicitDescriptor->Control & SE_DACL_DEFAULTED)
|
|
|
|
ExplicitDefaulted = TRUE;
|
|
|
|
}
|
|
|
|
ParentAcl = NULL;
|
|
|
|
if (ParentDescriptor != NULL &&
|
|
|
|
(ParentDescriptor->Control & SE_DACL_PRESENT))
|
|
|
|
{
|
|
|
|
ParentAcl = SepGetDaclFromDescriptor(ParentDescriptor);
|
|
|
|
}
|
|
|
|
Dacl = SepSelectAcl(ExplicitAcl,
|
|
|
|
ExplicitPresent,
|
|
|
|
ExplicitDefaulted,
|
|
|
|
ParentAcl,
|
|
|
|
Token->DefaultDacl,
|
|
|
|
&DaclLength,
|
|
|
|
Owner,
|
|
|
|
Group,
|
|
|
|
&DaclPresent,
|
|
|
|
&DaclIsInherited,
|
|
|
|
IsDirectoryObject,
|
|
|
|
GenericMapping);
|
|
|
|
if (DaclPresent)
|
2008-04-23 20:38:37 +00:00
|
|
|
Control |= SE_DACL_PRESENT;
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(DaclLength % sizeof(ULONG) == 0);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Inherit the SACL */
|
2014-11-04 22:44:50 +00:00
|
|
|
SaclLength = 0;
|
|
|
|
ExplicitAcl = NULL;
|
|
|
|
ExplicitPresent = FALSE;
|
|
|
|
ExplicitDefaulted = FALSE;
|
2008-04-23 20:38:37 +00:00
|
|
|
if (ExplicitDescriptor != NULL &&
|
2014-11-04 22:44:50 +00:00
|
|
|
(ExplicitDescriptor->Control & SE_SACL_PRESENT))
|
|
|
|
{
|
|
|
|
ExplicitAcl = SepGetSaclFromDescriptor(ExplicitDescriptor);
|
|
|
|
ExplicitPresent = TRUE;
|
|
|
|
if (ExplicitDescriptor->Control & SE_SACL_DEFAULTED)
|
|
|
|
ExplicitDefaulted = TRUE;
|
|
|
|
}
|
|
|
|
ParentAcl = NULL;
|
|
|
|
if (ParentDescriptor != NULL &&
|
|
|
|
(ParentDescriptor->Control & SE_SACL_PRESENT))
|
|
|
|
{
|
|
|
|
ParentAcl = SepGetSaclFromDescriptor(ParentDescriptor);
|
|
|
|
}
|
|
|
|
Sacl = SepSelectAcl(ExplicitAcl,
|
|
|
|
ExplicitPresent,
|
|
|
|
ExplicitDefaulted,
|
|
|
|
ParentAcl,
|
|
|
|
NULL,
|
|
|
|
&SaclLength,
|
|
|
|
Owner,
|
|
|
|
Group,
|
|
|
|
&SaclPresent,
|
|
|
|
&SaclIsInherited,
|
|
|
|
IsDirectoryObject,
|
|
|
|
GenericMapping);
|
|
|
|
if (SaclPresent)
|
2008-04-23 20:38:37 +00:00
|
|
|
Control |= SE_SACL_PRESENT;
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(SaclLength % sizeof(ULONG) == 0);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Allocate and initialize the new security descriptor */
|
2012-02-05 17:57:34 +00:00
|
|
|
Length = sizeof(SECURITY_DESCRIPTOR_RELATIVE) +
|
|
|
|
OwnerLength + GroupLength + DaclLength + SaclLength;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("L: sizeof(SECURITY_DESCRIPTOR) %u OwnerLength %lu GroupLength %lu DaclLength %lu SaclLength %lu\n",
|
2008-04-23 20:38:37 +00:00
|
|
|
sizeof(SECURITY_DESCRIPTOR),
|
|
|
|
OwnerLength,
|
|
|
|
GroupLength,
|
|
|
|
DaclLength,
|
|
|
|
SaclLength);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Descriptor = ExAllocatePoolWithTag(PagedPool, Length, TAG_SD);
|
2008-04-23 20:38:37 +00:00
|
|
|
if (Descriptor == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("ExAlloctePool() failed\n");
|
2014-11-02 15:41:20 +00:00
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlZeroMemory(Descriptor, Length);
|
|
|
|
RtlCreateSecurityDescriptor(Descriptor, SECURITY_DESCRIPTOR_REVISION);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-04 12:35:22 +00:00
|
|
|
Descriptor->Control = Control | SE_SELF_RELATIVE;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2012-02-05 17:57:34 +00:00
|
|
|
Current = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (SaclLength != 0)
|
|
|
|
{
|
2014-11-04 22:44:50 +00:00
|
|
|
Status = SepPropagateAcl((PACL)((PUCHAR)Descriptor + Current),
|
|
|
|
&SaclLength,
|
|
|
|
Sacl,
|
|
|
|
Owner,
|
|
|
|
Group,
|
|
|
|
SaclIsInherited,
|
|
|
|
IsDirectoryObject,
|
|
|
|
GenericMapping);
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
2012-02-05 17:57:34 +00:00
|
|
|
Descriptor->Sacl = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
Current += SaclLength;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (DaclLength != 0)
|
|
|
|
{
|
2014-11-04 22:44:50 +00:00
|
|
|
Status = SepPropagateAcl((PACL)((PUCHAR)Descriptor + Current),
|
|
|
|
&DaclLength,
|
|
|
|
Dacl,
|
|
|
|
Owner,
|
|
|
|
Group,
|
|
|
|
DaclIsInherited,
|
|
|
|
IsDirectoryObject,
|
|
|
|
GenericMapping);
|
2015-09-01 01:45:59 +00:00
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
2012-02-05 17:57:34 +00:00
|
|
|
Descriptor->Dacl = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
Current += DaclLength;
|
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (OwnerLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)Descriptor + Current, Owner, OwnerLength);
|
|
|
|
Descriptor->Owner = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
Current += OwnerLength;
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("Owner of %p at %x\n", Descriptor, Descriptor->Owner);
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
|
|
|
else
|
2010-05-28 16:28:27 +00:00
|
|
|
{
|
2013-08-31 16:02:13 +00:00
|
|
|
DPRINT("Owner of %p is zero length\n", Descriptor);
|
2010-05-28 16:28:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
if (GroupLength != 0)
|
|
|
|
{
|
2012-02-05 17:57:34 +00:00
|
|
|
RtlCopyMemory((PUCHAR)Descriptor + Current, Group, GroupLength);
|
|
|
|
Descriptor->Group = Current;
|
2008-04-23 20:38:37 +00:00
|
|
|
}
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
/* Unlock subject context */
|
|
|
|
SeUnlockSubjectContext(SubjectContext);
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
*NewDescriptor = Descriptor;
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2014-11-02 15:41:20 +00:00
|
|
|
DPRINT("Descriptor %p\n", Descriptor);
|
2008-04-23 20:38:37 +00:00
|
|
|
ASSERT(RtlLengthSecurityDescriptor(Descriptor));
|
2010-05-28 16:28:27 +00:00
|
|
|
|
2008-04-23 20:38:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-20 12:42:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 15:41:20 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
_IRQL_requires_max_(PASSIVE_LEVEL)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SeAssignSecurity(
|
|
|
|
_In_opt_ PSECURITY_DESCRIPTOR ParentDescriptor,
|
|
|
|
_In_opt_ PSECURITY_DESCRIPTOR ExplicitDescriptor,
|
|
|
|
_Out_ PSECURITY_DESCRIPTOR *NewDescriptor,
|
|
|
|
_In_ BOOLEAN IsDirectoryObject,
|
|
|
|
_In_ PSECURITY_SUBJECT_CONTEXT SubjectContext,
|
|
|
|
_In_ PGENERIC_MAPPING GenericMapping,
|
|
|
|
_In_ POOL_TYPE PoolType)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
return SeAssignSecurityEx(ParentDescriptor,
|
|
|
|
ExplicitDescriptor,
|
|
|
|
NewDescriptor,
|
|
|
|
NULL,
|
|
|
|
IsDirectoryObject,
|
|
|
|
0,
|
|
|
|
SubjectContext,
|
|
|
|
GenericMapping,
|
|
|
|
PoolType);
|
|
|
|
}
|
|
|
|
|
1999-12-26 17:22:19 +00:00
|
|
|
/* EOF */
|