2005-09-08 00:09:32 +00:00
|
|
|
/* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Security manager
|
|
|
|
* FILE: lib/rtl/acl.c
|
|
|
|
* PROGRAMER: David Welch <welch@cwcom.net>
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-26 08:39:07 +00:00
|
|
|
#include <rtl.h>
|
2012-09-19 02:32:58 +00:00
|
|
|
#include <../../ntoskrnl/include/internal/se.h>
|
2004-05-31 19:33:59 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 15:10:05 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlFirstFreeAce(IN PACL Acl,
|
|
|
|
OUT PACE* FirstFreeAce)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PACE Current;
|
|
|
|
ULONG_PTR AclEnd;
|
|
|
|
ULONG i;
|
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Assume failure */
|
|
|
|
*FirstFreeAce = NULL;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Get the start and end pointers */
|
|
|
|
Current = (PACE)(Acl + 1);
|
2011-09-18 15:10:05 +00:00
|
|
|
AclEnd = (ULONG_PTR)Acl + Acl->AclSize;
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Loop all the ACEs */
|
|
|
|
for (i = 0; i < Acl->AceCount; i++)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If any is beyond the DACL, bail out, otherwise keep going */
|
|
|
|
if ((ULONG_PTR)Current >= AclEnd) return FALSE;
|
|
|
|
Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If the last spot is empty and still valid, return it */
|
|
|
|
if ((ULONG_PTR)Current < AclEnd) *FirstFreeAce = Current;
|
2011-09-18 15:10:05 +00:00
|
|
|
return TRUE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
VOID
|
2011-09-18 15:10:05 +00:00
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlpAddData(IN PVOID AceList,
|
|
|
|
IN ULONG AceListLength,
|
|
|
|
IN PVOID Ace,
|
|
|
|
IN ULONG Offset)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Shift the buffer down */
|
|
|
|
if (Offset > 0)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlCopyMemory((PVOID)((ULONG_PTR)Ace + AceListLength),
|
|
|
|
Ace,
|
|
|
|
Offset);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Copy the new data in */
|
|
|
|
if (AceListLength) RtlCopyMemory(Ace, AceList, AceListLength);
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
RtlpDeleteData(IN PVOID Ace,
|
|
|
|
IN ULONG AceSize,
|
|
|
|
IN ULONG Offset)
|
|
|
|
{
|
|
|
|
/* Move the data up */
|
|
|
|
if (AceSize < Offset)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlMoveMemory(Ace,
|
|
|
|
(PVOID)((ULONG_PTR)Ace + AceSize),
|
|
|
|
Offset - AceSize);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Zero the rest */
|
|
|
|
if ((Offset - AceSize) < Offset)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlZeroMemory((PVOID)((ULONG_PTR)Ace + Offset - AceSize), AceSize);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
2012-09-19 02:32:58 +00:00
|
|
|
NTAPI
|
|
|
|
RtlpAddKnownAce(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid,
|
|
|
|
IN UCHAR Type)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
PKNOWN_ACE Ace;
|
2011-09-18 15:10:05 +00:00
|
|
|
ULONG AceSize, InvalidFlags;
|
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Check the validity of the SID */
|
|
|
|
if (!RtlValidSid(Sid)) return STATUS_INVALID_SID;
|
|
|
|
|
|
|
|
/* Check the validity of the revision */
|
|
|
|
if ((Acl->AclRevision > ACL_REVISION4) || (Revision > ACL_REVISION4))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
|
|
|
|
/* Pick the smallest of the revisions */
|
|
|
|
if (Revision < Acl->AclRevision) Revision = Acl->AclRevision;
|
|
|
|
|
|
|
|
/* Validate the flags */
|
|
|
|
if (Type == SYSTEM_AUDIT_ACE_TYPE)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
InvalidFlags = Flags & ~(VALID_INHERIT_FLAGS |
|
|
|
|
SUCCESSFUL_ACCESS_ACE_FLAG |
|
|
|
|
FAILED_ACCESS_ACE_FLAG);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
else
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
InvalidFlags = Flags & ~VALID_INHERIT_FLAGS;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If flags are invalid, bail out */
|
|
|
|
if (InvalidFlags != 0) return STATUS_INVALID_PARAMETER;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If ACL is invalid, bail out */
|
|
|
|
if (!RtlValidAcl(Acl)) return STATUS_INVALID_ACL;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If there's no free ACE, bail out */
|
|
|
|
if (!RtlFirstFreeAce(Acl, (PACE*)&Ace)) return STATUS_INVALID_ACL;
|
|
|
|
|
|
|
|
/* Calculate the size of the ACE and bail out if it's too small */
|
|
|
|
AceSize = RtlLengthSid(Sid) + sizeof(ACE);
|
|
|
|
if (!(Ace) || ((ULONG_PTR)Ace + AceSize > (ULONG_PTR)Acl + Acl->AclSize))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_ALLOTTED_SPACE_EXCEEDED;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Initialize the header and common fields */
|
|
|
|
Ace->Header.AceFlags = (BYTE)Flags;
|
|
|
|
Ace->Header.AceType = Type;
|
|
|
|
Ace->Header.AceSize = (WORD)AceSize;
|
|
|
|
Ace->Mask = AccessMask;
|
|
|
|
|
|
|
|
/* Copy the SID */
|
|
|
|
RtlCopySid(RtlLengthSid(Sid), &Ace->SidStart, Sid);
|
|
|
|
|
|
|
|
/* Fill out the ACL header and return */
|
|
|
|
Acl->AceCount++;
|
|
|
|
Acl->AclRevision = (BYTE)Revision;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlpAddKnownObjectAce(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
IN GUID *InheritedObjectTypeGuid OPTIONAL,
|
|
|
|
IN PSID Sid,
|
|
|
|
IN UCHAR Type)
|
|
|
|
{
|
|
|
|
PKNOWN_OBJECT_ACE Ace;
|
|
|
|
ULONG_PTR SidStart;
|
|
|
|
ULONG AceSize, InvalidFlags, AceObjectFlags = 0;
|
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
|
|
|
/* Check the validity of the SID */
|
|
|
|
if (!RtlValidSid(Sid)) return STATUS_INVALID_SID;
|
|
|
|
|
|
|
|
/* Check the validity of the revision */
|
|
|
|
if ((Acl->AclRevision > ACL_REVISION4) || (Revision > ACL_REVISION4))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Pick the smallest of the revisions */
|
|
|
|
if (Revision < Acl->AclRevision) Revision = Acl->AclRevision;
|
|
|
|
|
2011-09-18 15:10:05 +00:00
|
|
|
/* Validate the flags */
|
2012-09-19 02:32:58 +00:00
|
|
|
if ((Type == SYSTEM_AUDIT_OBJECT_ACE_TYPE) ||
|
|
|
|
(Type == SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
InvalidFlags = Flags & ~(VALID_INHERIT_FLAGS |
|
2006-03-09 21:43:58 +00:00
|
|
|
SUCCESSFUL_ACCESS_ACE_FLAG | FAILED_ACCESS_ACE_FLAG);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InvalidFlags = Flags & ~VALID_INHERIT_FLAGS;
|
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If flags are invalid, bail out */
|
|
|
|
if (InvalidFlags != 0) return STATUS_INVALID_PARAMETER;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* If ACL is invalid, bail out */
|
|
|
|
if (!RtlValidAcl(Acl)) return STATUS_INVALID_ACL;
|
|
|
|
|
|
|
|
/* If there's no free ACE, bail out */
|
|
|
|
if (!RtlFirstFreeAce(Acl, (PACE*)&Ace)) return STATUS_INVALID_ACL;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
|
|
|
/* Calculate the size of the ACE */
|
2012-09-19 02:32:58 +00:00
|
|
|
AceSize = RtlLengthSid(Sid) + sizeof(ACE) + sizeof(ULONG);
|
|
|
|
|
|
|
|
/* Add-in the size of the GUIDs if any and update flags as needed */
|
|
|
|
if (ObjectTypeGuid)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
AceObjectFlags |= ACE_OBJECT_TYPE_PRESENT;
|
|
|
|
AceSize += sizeof(GUID);
|
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
if (InheritedObjectTypeGuid)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
AceObjectFlags |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
|
|
|
|
AceSize += sizeof(GUID);
|
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if there's not enough space in the ACL */
|
|
|
|
if (!(Ace) || ((ULONG_PTR)Ace + AceSize > (ULONG_PTR)Acl + Acl->AclSize))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
return STATUS_ALLOTTED_SPACE_EXCEEDED;
|
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Initialize the header and common fields */
|
2011-09-19 11:09:09 +00:00
|
|
|
Ace->Header.AceFlags = (BYTE)Flags;
|
2011-09-18 15:10:05 +00:00
|
|
|
Ace->Header.AceType = Type;
|
|
|
|
Ace->Header.AceSize = (WORD)AceSize;
|
2012-09-19 02:32:58 +00:00
|
|
|
Ace->Mask = AccessMask;
|
|
|
|
Ace->Flags = AceObjectFlags;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Copy the GUIDs */
|
|
|
|
SidStart = (ULONG_PTR)&Ace->SidStart;
|
|
|
|
if (ObjectTypeGuid )
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlCopyMemory((PVOID)SidStart, ObjectTypeGuid, sizeof(GUID));
|
|
|
|
SidStart += sizeof(GUID);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
if (InheritedObjectTypeGuid)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlCopyMemory((PVOID)SidStart, InheritedObjectTypeGuid, sizeof(GUID));
|
|
|
|
SidStart += sizeof(GUID);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Copy the SID */
|
|
|
|
RtlCopySid(RtlLengthSid(Sid), (PSID)SidStart, Sid);
|
|
|
|
|
|
|
|
/* Fill out the ACL header and return */
|
2011-09-18 15:10:05 +00:00
|
|
|
Acl->AceCount++;
|
2011-09-19 11:09:09 +00:00
|
|
|
Acl->AclRevision = (BYTE)Revision;
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessAllowedAce(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker function */
|
2011-09-18 15:10:05 +00:00
|
|
|
return RtlpAddKnownAce(Acl,
|
2004-05-31 19:33:59 +00:00
|
|
|
Revision,
|
|
|
|
0,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessAllowedAceEx(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker function */
|
2011-09-18 15:10:05 +00:00
|
|
|
return RtlpAddKnownAce(Acl,
|
2004-05-31 19:33:59 +00:00
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessAllowedObjectAce(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
IN GUID *InheritedObjectTypeGuid OPTIONAL,
|
|
|
|
IN PSID Sid)
|
2006-05-10 09:32:23 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Is there no object data? */
|
|
|
|
if (!(ObjectTypeGuid) && !(InheritedObjectTypeGuid))
|
|
|
|
{
|
|
|
|
/* Use the usual routine */
|
|
|
|
return RtlpAddKnownAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the object routine */
|
|
|
|
return RtlpAddKnownObjectAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_OBJECT_ACE_TYPE);
|
2006-05-10 09:32:23 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessDeniedAce(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker function */
|
2011-09-18 15:10:05 +00:00
|
|
|
return RtlpAddKnownAce(Acl,
|
2004-05-31 19:33:59 +00:00
|
|
|
Revision,
|
|
|
|
0,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessDeniedAceEx(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker function */
|
2011-09-18 15:10:05 +00:00
|
|
|
return RtlpAddKnownAce(Acl,
|
2004-05-31 19:33:59 +00:00
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAccessDeniedObjectAce(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
IN GUID *InheritedObjectTypeGuid OPTIONAL,
|
|
|
|
IN PSID Sid)
|
2006-05-10 09:32:23 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Is there no object data? */
|
|
|
|
if (!(ObjectTypeGuid) && !(InheritedObjectTypeGuid))
|
|
|
|
{
|
|
|
|
/* Use the usual routine */
|
|
|
|
return RtlpAddKnownAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There's object data, use the object routine */
|
|
|
|
return RtlpAddKnownObjectAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_OBJECT_ACE_TYPE);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAuditAccessAce(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid,
|
|
|
|
IN BOOLEAN Success,
|
|
|
|
IN BOOLEAN Failure)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
ULONG Flags = 0;
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Add flags */
|
|
|
|
if (Success) Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
if (Failure) Flags |= FAILED_ACCESS_ACE_FLAG;
|
2011-09-18 15:10:05 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker routine */
|
|
|
|
return RtlpAddKnownAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_ACE_TYPE);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAuditAccessAceEx(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid,
|
|
|
|
IN BOOLEAN Success,
|
|
|
|
IN BOOLEAN Failure)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Add flags */
|
2011-09-18 15:10:05 +00:00
|
|
|
if (Success) Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
if (Failure) Flags |= FAILED_ACCESS_ACE_FLAG;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Call the worker routine */
|
2011-09-18 15:10:05 +00:00
|
|
|
return RtlpAddKnownAce(Acl,
|
2006-03-09 21:43:58 +00:00
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_ACE_TYPE);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2004-07-15 08:15:49 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAuditAccessObjectAce(IN PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
IN GUID *InheritedObjectTypeGuid OPTIONAL,
|
|
|
|
IN PSID Sid,
|
|
|
|
IN BOOLEAN Success,
|
|
|
|
IN BOOLEAN Failure)
|
2004-07-15 08:15:49 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Add flags */
|
2011-09-18 15:10:05 +00:00
|
|
|
if (Success) Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
if (Failure) Flags |= FAILED_ACCESS_ACE_FLAG;
|
2006-03-09 21:43:58 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Is there no object data? */
|
|
|
|
if (!(ObjectTypeGuid) && !(InheritedObjectTypeGuid))
|
|
|
|
{
|
|
|
|
/* Call the normal routine */
|
|
|
|
return RtlpAddKnownAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There's object data, use the object routine */
|
|
|
|
return RtlpAddKnownObjectAce(Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_OBJECT_ACE_TYPE);
|
2004-07-15 08:15:49 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlGetAce(IN PACL Acl,
|
|
|
|
IN ULONG AceIndex,
|
|
|
|
OUT PVOID *Ace)
|
2006-05-10 09:32:23 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
ULONG i;
|
|
|
|
PAGED_CODE_RTL();
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if the revision or the index are invalid */
|
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION) ||
|
|
|
|
(AceIndex >= Acl->AceCount))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Loop through the ACEs */
|
|
|
|
*Ace = (PVOID)((PACE)(Acl + 1));
|
|
|
|
for (i = 0; i < AceIndex; i++)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if an invalid ACE is ever found */
|
|
|
|
if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep going */
|
|
|
|
*Ace = (PVOID)((PACE)((ULONG_PTR)(*Ace) + ((PACE)(*Ace))->Header.AceSize));
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Check if the last ACE is still valid */
|
|
|
|
if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2006-05-10 09:32:23 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* All good, return */
|
|
|
|
return STATUS_SUCCESS;
|
2006-05-10 09:32:23 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 16:52:25 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlAddAce(IN PACL Acl,
|
|
|
|
IN ULONG AclRevision,
|
|
|
|
IN ULONG StartingIndex,
|
|
|
|
IN PVOID AceList,
|
|
|
|
IN ULONG AceListLength)
|
2006-10-15 16:52:25 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
PACE Ace, FreeAce;
|
|
|
|
USHORT NewAceCount;
|
|
|
|
ULONG Index;
|
|
|
|
PAGED_CODE_RTL();
|
2006-10-15 16:52:25 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if the ACL is invalid */
|
|
|
|
if (!RtlValidAcl(Acl)) return STATUS_INVALID_PARAMETER;
|
2006-10-15 16:52:25 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if there's no space */
|
|
|
|
if (!RtlFirstFreeAce(Acl, &FreeAce)) return STATUS_INVALID_PARAMETER;
|
2006-10-15 16:52:25 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Loop over all the ACEs, keeping track of new ACEs as we go along */
|
|
|
|
for (Ace = AceList, NewAceCount = 0;
|
|
|
|
Ace < (PACE)((ULONG_PTR)AceList + AceListLength);
|
|
|
|
NewAceCount++)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2013-10-23 19:31:41 +00:00
|
|
|
/* Make sure that the revision of this ACE is valid in this list.
|
|
|
|
The initial check looks strange, but it is what Windows does. */
|
|
|
|
if (Ace->Header.AceType <= ACCESS_MAX_MS_ACE_TYPE)
|
2012-09-19 02:32:58 +00:00
|
|
|
{
|
2013-10-23 19:31:41 +00:00
|
|
|
if (Ace->Header.AceType > ACCESS_MAX_MS_V3_ACE_TYPE)
|
|
|
|
{
|
|
|
|
if (AclRevision < ACL_REVISION4) return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else if (Ace->Header.AceType > ACCESS_MAX_MS_V2_ACE_TYPE)
|
|
|
|
{
|
|
|
|
if (AclRevision < ACL_REVISION3) return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next ACE */
|
|
|
|
Ace = (PACE)((ULONG_PTR)Ace + Ace->Header.AceSize);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if there's no more space for us */
|
|
|
|
if ((ULONG_PTR)Ace > ((ULONG_PTR)AceList + AceListLength))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if there's no free ACE spot, or if we would overflow it */
|
|
|
|
if (!(FreeAce) ||
|
|
|
|
((ULONG_PTR)FreeAce + AceListLength > (ULONG_PTR)Acl + Acl->AclSize))
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go down the list until we find our index */
|
|
|
|
Ace = (PACE)(Acl + 1);
|
|
|
|
for (Index = 0; (Index < StartingIndex) && (Index < Acl->AceCount); Index++)
|
|
|
|
{
|
|
|
|
Ace = (PACE)((ULONG_PTR)Ace + Ace->Header.AceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Found where we want to do, add us to the list */
|
|
|
|
RtlpAddData(AceList,
|
|
|
|
AceListLength,
|
|
|
|
Ace,
|
|
|
|
(ULONG_PTR)FreeAce - (ULONG_PTR)Ace);
|
|
|
|
|
2013-10-23 19:31:41 +00:00
|
|
|
/* Update the header and return */
|
|
|
|
Acl->AceCount += NewAceCount;
|
|
|
|
Acl->AclRevision = (UCHAR)min(Acl->AclRevision, AclRevision);
|
2012-09-19 02:32:58 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlDeleteAce(IN PACL Acl,
|
|
|
|
IN ULONG AceIndex)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
PACE FreeAce, Ace;
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if the ACL is invalid */
|
|
|
|
if (!RtlValidAcl(Acl)) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* Bail out if there's no space or if we're full */
|
|
|
|
if ((Acl->AceCount <= AceIndex) || !(RtlFirstFreeAce(Acl, &FreeAce)))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Enumerate until the indexed ACE is reached */
|
|
|
|
Ace = (PACE)(Acl + 1);
|
|
|
|
while (AceIndex--) Ace = (PACE)((ULONG_PTR)Ace + Ace->Header.AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Delete this ACE */
|
|
|
|
RtlpDeleteData(Ace,
|
|
|
|
Ace->Header.AceSize,
|
|
|
|
(ULONG)((ULONG_PTR)FreeAce - (ULONG_PTR)Ace));
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Decrease an ACE and return success */
|
2011-09-18 15:10:05 +00:00
|
|
|
Acl->AceCount--;
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlCreateAcl(IN PACL Acl,
|
|
|
|
IN ULONG AclSize,
|
|
|
|
IN ULONG AclRevision)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if too small */
|
|
|
|
if (AclSize < sizeof(ACL)) return STATUS_BUFFER_TOO_SMALL;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if too large or invalid revision */
|
|
|
|
if ((AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(AclRevision > MAX_ACL_REVISION) ||
|
|
|
|
(AclSize > MAXUSHORT))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Setup the header */
|
|
|
|
Acl->AclSize = (USHORT)ROUND_UP(AclSize, 4);
|
|
|
|
Acl->AclRevision = (UCHAR)AclRevision;
|
2011-09-18 15:10:05 +00:00
|
|
|
Acl->AceCount = 0;
|
|
|
|
Acl->Sbz1 = 0;
|
|
|
|
Acl->Sbz2 = 0;
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlQueryInformationAcl(IN PACL Acl,
|
|
|
|
IN PVOID Information,
|
|
|
|
IN ULONG InformationLength,
|
|
|
|
IN ACL_INFORMATION_CLASS InformationClass)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
PACE Ace;
|
2012-09-19 02:32:58 +00:00
|
|
|
PACL_REVISION_INFORMATION RevisionInfo;
|
|
|
|
PACL_SIZE_INFORMATION SizeInfo;
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Validate the ACL revision */
|
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Check what the caller is querying */
|
2011-09-18 15:10:05 +00:00
|
|
|
switch (InformationClass)
|
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Revision data */
|
2011-09-18 15:10:05 +00:00
|
|
|
case AclRevisionInformation:
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if the buffer is too small */
|
2004-05-31 19:33:59 +00:00
|
|
|
if (InformationLength < sizeof(ACL_REVISION_INFORMATION))
|
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Return the current revision */
|
|
|
|
RevisionInfo = (PACL_REVISION_INFORMATION)Information;
|
|
|
|
RevisionInfo->AclRevision = Acl->AclRevision;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Size data */
|
2011-09-18 15:10:05 +00:00
|
|
|
case AclSizeInformation:
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if the buffer is too small */
|
2004-05-31 19:33:59 +00:00
|
|
|
if (InformationLength < sizeof(ACL_SIZE_INFORMATION))
|
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Bail out if there's no space in the ACL */
|
|
|
|
if (!RtlFirstFreeAce(Acl, &Ace)) return STATUS_INVALID_PARAMETER;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Read the number of ACEs and check if there was a free ACE */
|
|
|
|
SizeInfo = (PACL_SIZE_INFORMATION)Information;
|
|
|
|
SizeInfo->AceCount = Acl->AceCount;
|
|
|
|
if (Ace)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Return how much space there is in the ACL */
|
|
|
|
SizeInfo->AclBytesInUse = (ULONG_PTR)Ace - (ULONG_PTR)Acl;
|
|
|
|
SizeInfo->AclBytesFree = Acl->AclSize - SizeInfo->AclBytesInUse;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* No free ACE, means the whole ACL is full */
|
|
|
|
SizeInfo->AclBytesInUse = Acl->AclSize;
|
|
|
|
SizeInfo->AclBytesFree = 0;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
break;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 15:10:05 +00:00
|
|
|
default:
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Anything else is illegal */
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* All done */
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-09-19 02:32:58 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlSetInformationAcl(IN PACL Acl,
|
|
|
|
IN PVOID Information,
|
|
|
|
IN ULONG InformationLength,
|
|
|
|
IN ACL_INFORMATION_CLASS InformationClass)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
PACL_REVISION_INFORMATION Info ;
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Validate the ACL revision */
|
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION))
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* What is the caller trying to set? */
|
2011-09-18 15:10:05 +00:00
|
|
|
switch (InformationClass)
|
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* This is the only info class */
|
2011-09-18 15:10:05 +00:00
|
|
|
case AclRevisionInformation:
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Make sure the buffer is large enough */
|
2004-05-31 19:33:59 +00:00
|
|
|
if (InformationLength < sizeof(ACL_REVISION_INFORMATION))
|
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Make sure the new revision is within the acceptable bounds*/
|
|
|
|
Info = (PACL_REVISION_INFORMATION)Information;
|
2004-05-31 19:33:59 +00:00
|
|
|
if (Acl->AclRevision >= Info->AclRevision)
|
|
|
|
{
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Set the new revision */
|
2011-09-20 17:33:51 +00:00
|
|
|
Acl->AclRevision = (BYTE)Info->AclRevision;
|
2012-09-19 02:32:58 +00:00
|
|
|
break;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 15:10:05 +00:00
|
|
|
default:
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Anything else is invalid */
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* All good */
|
2011-09-18 15:10:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 15:10:05 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2012-09-19 02:32:58 +00:00
|
|
|
RtlValidAcl(IN PACL Acl)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
PACE_HEADER Ace;
|
|
|
|
PISID Sid;
|
|
|
|
ULONG i;
|
2011-09-18 15:10:05 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
_SEH2_TRY
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* First, validate the revision */
|
|
|
|
if ((Acl->AclRevision < MIN_ACL_REVISION) ||
|
|
|
|
(Acl->AclRevision > MAX_ACL_REVISION))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACL revision\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Next, validate that the ACL is USHORT-aligned */
|
|
|
|
if (ROUND_DOWN(Acl->AclSize, sizeof(USHORT)) != Acl->AclSize)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACL size\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* And that it's big enough */
|
|
|
|
if (Acl->AclSize < sizeof(ACL))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACL size\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop each ACE */
|
|
|
|
Ace = (PACE_HEADER)((ULONG_PTR)Acl + sizeof(ACL));
|
|
|
|
for (i = 0; i < Acl->AceCount; i++)
|
|
|
|
{
|
|
|
|
/* Validate we have space for this ACE header */
|
|
|
|
if (((ULONG_PTR)Ace + sizeof(ACE_HEADER)) >= ((ULONG_PTR)Acl + Acl->AclSize))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Validate the length of this ACE */
|
|
|
|
if (ROUND_DOWN(Ace->AceSize, sizeof(USHORT)) != Ace->AceSize)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size: %lx\n", Ace->AceSize);
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate we have space for the entire ACE */
|
|
|
|
if (((ULONG_PTR)Ace + Ace->AceSize) > ((ULONG_PTR)Acl + Acl->AclSize))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size %lx %lx\n", Ace->AceSize, Acl->AclSize);
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check what kind of ACE this is */
|
2013-05-24 09:50:49 +00:00
|
|
|
if (Ace->AceType <= ACCESS_MAX_MS_V2_ACE_TYPE)
|
2012-09-19 02:32:58 +00:00
|
|
|
{
|
|
|
|
/* Validate the length of this ACE */
|
|
|
|
if (ROUND_DOWN(Ace->AceSize, sizeof(ULONG)) != Ace->AceSize)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The ACE size should at least have enough for the header */
|
|
|
|
if (Ace->AceSize < sizeof(ACE_HEADER))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size: %lx %lx\n", Ace->AceSize, sizeof(ACE_HEADER));
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the SID revision is valid */
|
|
|
|
Sid = (PISID)&((PKNOWN_ACE)Ace)->SidStart;
|
|
|
|
if (Sid->Revision != SID_REVISION)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid SID\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the SID is out of bounds */
|
|
|
|
if (Sid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid SID\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The ACE size should at least have enough for the header and SID */
|
|
|
|
if (Ace->AceSize < (sizeof(ACE_HEADER) + RtlLengthSid(Sid)))
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid ACE size\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Ace->AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE)
|
|
|
|
{
|
|
|
|
DPRINT1("Unsupported ACE in ReactOS, assuming valid\n");
|
|
|
|
}
|
2013-05-24 09:50:49 +00:00
|
|
|
else if ((Ace->AceType >= ACCESS_MIN_MS_OBJECT_ACE_TYPE) &&
|
2012-10-05 15:20:10 +00:00
|
|
|
(Ace->AceType <= ACCESS_MAX_MS_OBJECT_ACE_TYPE))
|
2012-09-19 02:32:58 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Unsupported ACE in ReactOS, assuming valid\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Unknown ACE, see if it's as big as a header at least */
|
|
|
|
if (Ace->AceSize < sizeof(ACE_HEADER))
|
|
|
|
{
|
|
|
|
DPRINT1("Unknown ACE\n");
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2012-09-19 02:32:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next ace */
|
|
|
|
Ace = (PACE_HEADER)((ULONG_PTR)Ace + Ace->AceSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2011-09-18 15:10:05 +00:00
|
|
|
{
|
2012-09-19 02:32:58 +00:00
|
|
|
/* Something was invalid, fail */
|
2013-10-23 19:38:49 +00:00
|
|
|
_SEH2_YIELD(return FALSE);
|
2011-09-18 15:10:05 +00:00
|
|
|
}
|
2012-09-19 02:32:58 +00:00
|
|
|
_SEH2_END;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2012-09-19 02:32:58 +00:00
|
|
|
/* The ACL looks ok */
|
|
|
|
return TRUE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|