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>
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2005-10-19 17:03:38 +00:00
|
|
|
BOOLEAN NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlFirstFreeAce(PACL Acl,
|
|
|
|
PACE* Ace)
|
|
|
|
{
|
|
|
|
PACE Current;
|
2005-06-30 21:38:39 +00:00
|
|
|
ULONG_PTR AclEnd;
|
2004-05-31 19:33:59 +00:00
|
|
|
ULONG i;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
Current = (PACE)(Acl + 1);
|
|
|
|
*Ace = NULL;
|
2005-06-30 21:38:39 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
if (Acl->AceCount == 0)
|
|
|
|
{
|
|
|
|
*Ace = Current;
|
|
|
|
return(TRUE);
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
i = 0;
|
|
|
|
AclEnd = (ULONG_PTR)Acl + Acl->AclSize;
|
2004-05-31 19:33:59 +00:00
|
|
|
do
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
if ((ULONG_PTR)Current >= AclEnd)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (Current->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE &&
|
2004-11-27 16:33:21 +00:00
|
|
|
Acl->AclRevision < ACL_REVISION3)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
2005-06-30 21:38:39 +00:00
|
|
|
Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
2005-06-30 21:38:39 +00:00
|
|
|
while (++i < Acl->AceCount);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
if ((ULONG_PTR)Current < AclEnd)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
*Ace = Current;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlGetAce(PACL Acl,
|
|
|
|
ULONG AceIndex,
|
2005-09-05 18:06:20 +00:00
|
|
|
PVOID *Ace)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
ULONG i;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2005-06-30 21:38:39 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION ||
|
|
|
|
AceIndex >= Acl->AceCount)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-05 18:06:20 +00:00
|
|
|
*Ace = (PVOID)((PACE)(Acl + 1));
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
for (i = 0; i < AceIndex; i++)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
2005-09-05 18:06:20 +00:00
|
|
|
*Ace = (PVOID)((PACE)((ULONG_PTR)(*Ace) + ((PACE)(*Ace))->Header.AceSize));
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
RtlpAddKnownAce (PACL Acl,
|
|
|
|
ULONG Revision,
|
|
|
|
ULONG Flags,
|
|
|
|
ACCESS_MASK AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
GUID *InheritedObjectTypeGuid OPTIONAL,
|
2004-05-31 19:33:59 +00:00
|
|
|
PSID Sid,
|
|
|
|
ULONG Type)
|
|
|
|
{
|
|
|
|
PACE Ace;
|
2006-05-10 09:32:23 +00:00
|
|
|
PSID SidStart;
|
|
|
|
ULONG AceSize, InvalidFlags;
|
|
|
|
ULONG AceObjectFlags = 0;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
#if DBG
|
|
|
|
/* check if RtlpAddKnownAce was called incorrectly */
|
|
|
|
if (ObjectTypeGuid != NULL || InheritedObjectTypeGuid != NULL)
|
|
|
|
{
|
|
|
|
ASSERT(Type == ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE ||
|
|
|
|
Type == ACCESS_ALLOWED_OBJECT_ACE_TYPE ||
|
|
|
|
Type == ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE ||
|
|
|
|
Type == ACCESS_DENIED_OBJECT_ACE_TYPE ||
|
|
|
|
Type == SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE ||
|
|
|
|
Type == SYSTEM_AUDIT_OBJECT_ACE_TYPE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(Type != ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE &&
|
|
|
|
Type != ACCESS_ALLOWED_OBJECT_ACE_TYPE &&
|
|
|
|
Type != ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE &&
|
|
|
|
Type != ACCESS_DENIED_OBJECT_ACE_TYPE &&
|
|
|
|
Type != SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE &&
|
|
|
|
Type != SYSTEM_AUDIT_OBJECT_ACE_TYPE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
if (!RtlValidSid(Sid))
|
|
|
|
{
|
|
|
|
return(STATUS_INVALID_SID);
|
|
|
|
}
|
2006-10-15 16:52:25 +00:00
|
|
|
|
|
|
|
if (Type == SYSTEM_MANDATORY_LABEL_ACE_TYPE)
|
|
|
|
{
|
|
|
|
static const SID_IDENTIFIER_AUTHORITY MandatoryLabelAuthority = {SECURITY_MANDATORY_LABEL_AUTHORITY};
|
|
|
|
|
|
|
|
/* The SID's identifier authority must be SECURITY_MANDATORY_LABEL_AUTHORITY! */
|
|
|
|
if (RtlCompareMemory(&((PISID)Sid)->IdentifierAuthority,
|
|
|
|
&MandatoryLabelAuthority,
|
|
|
|
sizeof(MandatoryLabelAuthority)) != sizeof(MandatoryLabelAuthority))
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
if (Acl->AclRevision > MAX_ACL_REVISION ||
|
2004-11-27 16:33:21 +00:00
|
|
|
Revision > MAX_ACL_REVISION)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_UNKNOWN_REVISION);
|
|
|
|
}
|
|
|
|
if (Revision < Acl->AclRevision)
|
|
|
|
{
|
|
|
|
Revision = Acl->AclRevision;
|
|
|
|
}
|
2006-03-09 21:43:58 +00:00
|
|
|
|
|
|
|
/* Validate the flags */
|
2006-05-10 09:32:23 +00:00
|
|
|
if (Type == SYSTEM_AUDIT_ACE_TYPE ||
|
|
|
|
Type == SYSTEM_AUDIT_OBJECT_ACE_TYPE ||
|
|
|
|
Type == SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE)
|
|
|
|
{
|
2006-03-09 21:43:58 +00:00
|
|
|
InvalidFlags = Flags & ~(VALID_INHERIT_FLAGS |
|
|
|
|
SUCCESSFUL_ACCESS_ACE_FLAG | FAILED_ACCESS_ACE_FLAG);
|
2006-05-10 09:32:23 +00:00
|
|
|
}
|
2006-03-09 21:43:58 +00:00
|
|
|
else
|
2006-05-10 09:32:23 +00:00
|
|
|
{
|
2006-03-09 21:43:58 +00:00
|
|
|
InvalidFlags = Flags & ~VALID_INHERIT_FLAGS;
|
2006-05-10 09:32:23 +00:00
|
|
|
}
|
2006-03-09 21:43:58 +00:00
|
|
|
|
|
|
|
if (InvalidFlags != 0)
|
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
if (!RtlFirstFreeAce(Acl, &Ace))
|
|
|
|
{
|
|
|
|
return(STATUS_INVALID_ACL);
|
|
|
|
}
|
|
|
|
if (Ace == NULL)
|
|
|
|
{
|
|
|
|
return(STATUS_ALLOTTED_SPACE_EXCEEDED);
|
|
|
|
}
|
2006-05-10 09:32:23 +00:00
|
|
|
|
|
|
|
/* Calculate the size of the ACE */
|
|
|
|
AceSize = RtlLengthSid(Sid) + sizeof(ACE);
|
|
|
|
if (ObjectTypeGuid != NULL)
|
|
|
|
{
|
|
|
|
AceObjectFlags |= ACE_OBJECT_TYPE_PRESENT;
|
|
|
|
AceSize += sizeof(GUID);
|
|
|
|
}
|
|
|
|
if (InheritedObjectTypeGuid != NULL)
|
|
|
|
{
|
|
|
|
AceObjectFlags |= ACE_INHERITED_OBJECT_TYPE_PRESENT;
|
|
|
|
AceSize += sizeof(GUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AceObjectFlags != 0)
|
|
|
|
{
|
|
|
|
/* Don't forget the ACE object flags
|
|
|
|
(corresponds to the Flags field in the *_OBJECT_ACE structures) */
|
|
|
|
AceSize += sizeof(ULONG);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ULONG_PTR)Ace + AceSize >
|
2004-11-06 21:32:16 +00:00
|
|
|
(ULONG_PTR)Acl + Acl->AclSize)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_ALLOTTED_SPACE_EXCEEDED);
|
|
|
|
}
|
2006-05-10 09:32:23 +00:00
|
|
|
|
|
|
|
/* initialize the header and common fields */
|
2004-05-31 19:33:59 +00:00
|
|
|
Ace->Header.AceFlags = Flags;
|
|
|
|
Ace->Header.AceType = Type;
|
2006-05-10 09:32:23 +00:00
|
|
|
Ace->Header.AceSize = (WORD)AceSize;
|
2004-05-31 19:33:59 +00:00
|
|
|
Ace->AccessMask = AccessMask;
|
2006-05-10 09:32:23 +00:00
|
|
|
|
|
|
|
if (AceObjectFlags != 0)
|
|
|
|
{
|
|
|
|
/* Write the ACE flags to the ACE
|
|
|
|
(corresponds to the Flags field in the *_OBJECT_ACE structures) */
|
|
|
|
*(PULONG)(Ace + 1) = AceObjectFlags;
|
|
|
|
SidStart = (PSID)((ULONG_PTR)(Ace + 1) + sizeof(ULONG));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SidStart = (PSID)(Ace + 1);
|
|
|
|
|
|
|
|
/* copy the GUIDs */
|
|
|
|
if (ObjectTypeGuid != NULL)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(SidStart,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
sizeof(GUID));
|
|
|
|
SidStart = (PSID)((ULONG_PTR)SidStart + sizeof(GUID));
|
|
|
|
}
|
|
|
|
if (InheritedObjectTypeGuid != NULL)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(SidStart,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
sizeof(GUID));
|
|
|
|
SidStart = (PSID)((ULONG_PTR)SidStart + sizeof(GUID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the SID */
|
|
|
|
RtlCopySid(RtlLengthSid(Sid),
|
|
|
|
SidStart,
|
|
|
|
Sid);
|
2004-05-31 19:33:59 +00:00
|
|
|
Acl->AceCount++;
|
|
|
|
Acl->AclRevision = Revision;
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAccessAllowedAce (IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
0,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-05-31 19:33:59 +00:00
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAccessAllowedAceEx (IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-05-31 19:33:59 +00:00
|
|
|
Sid,
|
|
|
|
ACCESS_ALLOWED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ULONG Type;
|
|
|
|
|
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
|
|
|
/* make sure we call RtlpAddKnownAce correctly */
|
|
|
|
if (ObjectTypeGuid != NULL || InheritedObjectTypeGuid != NULL)
|
|
|
|
Type = ACCESS_ALLOWED_OBJECT_ACE_TYPE;
|
|
|
|
else
|
|
|
|
Type = ACCESS_ALLOWED_ACE_TYPE;
|
|
|
|
|
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAccessDeniedAce (PACL Acl,
|
|
|
|
ULONG Revision,
|
|
|
|
ACCESS_MASK AccessMask,
|
|
|
|
PSID Sid)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
0,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-05-31 19:33:59 +00:00
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAccessDeniedAceEx (IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ACCESS_MASK AccessMask,
|
|
|
|
IN PSID Sid)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-05-31 19:33:59 +00:00
|
|
|
Sid,
|
|
|
|
ACCESS_DENIED_ACE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ULONG Type;
|
|
|
|
|
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
|
|
|
/* make sure we call RtlpAddKnownAce correctly */
|
|
|
|
if (ObjectTypeGuid != NULL || InheritedObjectTypeGuid != NULL)
|
|
|
|
Type = ACCESS_DENIED_OBJECT_ACE_TYPE;
|
|
|
|
else
|
|
|
|
Type = ACCESS_DENIED_ACE_TYPE;
|
|
|
|
|
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
static VOID
|
|
|
|
RtlpAddData(PVOID AceList,
|
|
|
|
ULONG AceListLength,
|
|
|
|
PVOID Ace,
|
|
|
|
ULONG Offset)
|
|
|
|
{
|
|
|
|
if (Offset > 0)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
RtlCopyMemory((PVOID)((ULONG_PTR)Ace + AceListLength),
|
|
|
|
Ace,
|
|
|
|
Offset);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (AceListLength != 0)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
RtlCopyMemory(Ace,
|
|
|
|
AceList,
|
|
|
|
AceListLength);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAce(PACL Acl,
|
|
|
|
ULONG AclRevision,
|
|
|
|
ULONG StartingIndex,
|
2005-09-05 18:06:20 +00:00
|
|
|
PVOID AceList,
|
2004-05-31 19:33:59 +00:00
|
|
|
ULONG AceListLength)
|
|
|
|
{
|
|
|
|
PACE Ace;
|
|
|
|
PACE Current;
|
2005-08-01 08:55:22 +00:00
|
|
|
ULONG NewAceCount;
|
|
|
|
ULONG Index;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2005-06-30 21:38:39 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION ||
|
|
|
|
!RtlFirstFreeAce(Acl, &Ace))
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Acl->AclRevision <= AclRevision)
|
|
|
|
{
|
|
|
|
AclRevision = Acl->AclRevision;
|
|
|
|
}
|
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
if (((ULONG_PTR)AceList + AceListLength) <= (ULONG_PTR)AceList)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
2005-08-01 08:55:22 +00:00
|
|
|
for (Current = AceList, NewAceCount = 0;
|
|
|
|
(ULONG_PTR)Current < ((ULONG_PTR)AceList + AceListLength);
|
|
|
|
Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize),
|
|
|
|
++NewAceCount)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-05 18:06:20 +00:00
|
|
|
if (((PACE)AceList)->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE &&
|
2004-11-27 16:33:21 +00:00
|
|
|
AclRevision < ACL_REVISION3)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
if (Ace == NULL ||
|
2005-08-01 08:55:22 +00:00
|
|
|
((ULONG_PTR)Ace + AceListLength) > ((ULONG_PTR)Acl + Acl->AclSize))
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_BUFFER_TOO_SMALL);
|
|
|
|
}
|
|
|
|
|
2005-08-01 08:55:22 +00:00
|
|
|
Current = (PACE)(Acl + 1);
|
|
|
|
for (Index = 0; Index < StartingIndex && Index < Acl->AceCount; Index++)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-08-01 08:55:22 +00:00
|
|
|
Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RtlpAddData(AceList,
|
|
|
|
AceListLength,
|
|
|
|
Current,
|
2005-06-30 21:38:39 +00:00
|
|
|
(ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
|
2005-08-01 08:55:22 +00:00
|
|
|
Acl->AceCount = Acl->AceCount + NewAceCount;
|
2004-05-31 19:33:59 +00:00
|
|
|
Acl->AclRevision = AclRevision;
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAddAuditAccessAce(PACL Acl,
|
|
|
|
ULONG Revision,
|
|
|
|
ACCESS_MASK AccessMask,
|
|
|
|
PSID Sid,
|
|
|
|
BOOLEAN Success,
|
|
|
|
BOOLEAN Failure)
|
|
|
|
{
|
|
|
|
ULONG Flags = 0;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2006-03-09 21:43:58 +00:00
|
|
|
if (Success)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
2006-03-09 21:43:58 +00:00
|
|
|
if (Failure)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
Flags |= FAILED_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
2006-03-09 21:43:58 +00:00
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-03-09 21:43:58 +00:00
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_ACE_TYPE);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-15 08:15:49 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-07-15 08:15:49 +00:00
|
|
|
RtlAddAuditAccessAceEx(PACL Acl,
|
|
|
|
ULONG Revision,
|
|
|
|
ULONG Flags,
|
|
|
|
ACCESS_MASK AccessMask,
|
|
|
|
PSID Sid,
|
|
|
|
BOOLEAN Success,
|
|
|
|
BOOLEAN Failure)
|
|
|
|
{
|
2006-03-09 21:43:58 +00:00
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Failure)
|
|
|
|
{
|
|
|
|
Flags |= FAILED_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
2006-05-10 09:32:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-03-09 21:43:58 +00:00
|
|
|
Sid,
|
|
|
|
SYSTEM_AUDIT_ACE_TYPE);
|
2004-07-15 08:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-10 09:32:23 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
RtlAddAuditAccessObjectAce(PACL Acl,
|
|
|
|
ULONG Revision,
|
|
|
|
ULONG Flags,
|
|
|
|
ACCESS_MASK AccessMask,
|
|
|
|
IN GUID *ObjectTypeGuid OPTIONAL,
|
|
|
|
IN GUID *InheritedObjectTypeGuid OPTIONAL,
|
|
|
|
PSID Sid,
|
|
|
|
BOOLEAN Success,
|
|
|
|
BOOLEAN Failure)
|
|
|
|
{
|
|
|
|
ULONG Type;
|
|
|
|
|
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
Flags |= SUCCESSFUL_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Failure)
|
|
|
|
{
|
|
|
|
Flags |= FAILED_ACCESS_ACE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we call RtlpAddKnownAce correctly */
|
|
|
|
if (ObjectTypeGuid != NULL || InheritedObjectTypeGuid != NULL)
|
|
|
|
Type = SYSTEM_AUDIT_OBJECT_ACE_TYPE;
|
|
|
|
else
|
|
|
|
Type = SYSTEM_AUDIT_ACE_TYPE;
|
|
|
|
|
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
AccessMask,
|
|
|
|
ObjectTypeGuid,
|
|
|
|
InheritedObjectTypeGuid,
|
|
|
|
Sid,
|
|
|
|
Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-15 16:52:25 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
RtlAddMandatoryAce(IN OUT PACL Acl,
|
|
|
|
IN ULONG Revision,
|
|
|
|
IN ULONG Flags,
|
|
|
|
IN ULONG MandatoryFlags,
|
|
|
|
IN ULONG AceType,
|
|
|
|
IN PSID LabelSid)
|
|
|
|
{
|
|
|
|
if (MandatoryFlags & ~SYSTEM_MANDATORY_LABEL_VALID_MASK)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (AceType != SYSTEM_MANDATORY_LABEL_ACE_TYPE)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return RtlpAddKnownAce (Acl,
|
|
|
|
Revision,
|
|
|
|
Flags,
|
|
|
|
(ACCESS_MASK)MandatoryFlags,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
LabelSid,
|
|
|
|
AceType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
static VOID
|
|
|
|
RtlpDeleteData(PVOID Ace,
|
|
|
|
ULONG AceSize,
|
|
|
|
ULONG Offset)
|
|
|
|
{
|
|
|
|
if (AceSize < Offset)
|
|
|
|
{
|
2006-09-27 12:28:25 +00:00
|
|
|
RtlMoveMemory(Ace,
|
2005-06-30 21:38:39 +00:00
|
|
|
(PVOID)((ULONG_PTR)Ace + AceSize),
|
|
|
|
Offset - AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Offset - AceSize < Offset)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
RtlZeroMemory((PVOID)((ULONG_PTR)Ace + Offset - AceSize),
|
|
|
|
AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlDeleteAce(PACL Acl,
|
|
|
|
ULONG AceIndex)
|
|
|
|
{
|
|
|
|
PACE Ace;
|
|
|
|
PACE Current;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2005-06-30 21:38:39 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION ||
|
|
|
|
Acl->AceCount <= AceIndex ||
|
|
|
|
!RtlFirstFreeAce(Acl, &Ace))
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
Current = (PACE)(Acl + 1);
|
|
|
|
|
|
|
|
while(AceIndex--)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RtlpDeleteData(Current,
|
|
|
|
Current->Header.AceSize,
|
2005-06-30 21:38:39 +00:00
|
|
|
(ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
|
|
|
|
Acl->AceCount--;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCreateAcl(PACL Acl,
|
|
|
|
ULONG AclSize,
|
|
|
|
ULONG AclRevision)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-06-30 21:38:39 +00:00
|
|
|
if (AclSize < sizeof(ACL))
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_BUFFER_TOO_SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AclRevision < MIN_ACL_REVISION ||
|
2005-06-30 21:38:39 +00:00
|
|
|
AclRevision > MAX_ACL_REVISION ||
|
|
|
|
AclSize > 0xffff)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
2004-11-27 16:33:21 +00:00
|
|
|
AclSize = ROUND_UP(AclSize, 4);
|
2004-05-31 19:33:59 +00:00
|
|
|
Acl->AclSize = AclSize;
|
|
|
|
Acl->AclRevision = AclRevision;
|
|
|
|
Acl->AceCount = 0;
|
|
|
|
Acl->Sbz1 = 0;
|
|
|
|
Acl->Sbz2 = 0;
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlQueryInformationAcl(PACL Acl,
|
|
|
|
PVOID Information,
|
|
|
|
ULONG InformationLength,
|
|
|
|
ACL_INFORMATION_CLASS InformationClass)
|
|
|
|
{
|
|
|
|
PACE Ace;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2004-11-27 16:33:21 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (InformationClass)
|
|
|
|
{
|
|
|
|
case AclRevisionInformation:
|
|
|
|
{
|
|
|
|
PACL_REVISION_INFORMATION Info = (PACL_REVISION_INFORMATION)Information;
|
|
|
|
|
|
|
|
if (InformationLength < sizeof(ACL_REVISION_INFORMATION))
|
|
|
|
{
|
|
|
|
return(STATUS_BUFFER_TOO_SMALL);
|
|
|
|
}
|
|
|
|
Info->AclRevision = Acl->AclRevision;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AclSizeInformation:
|
|
|
|
{
|
|
|
|
PACL_SIZE_INFORMATION Info = (PACL_SIZE_INFORMATION)Information;
|
|
|
|
|
|
|
|
if (InformationLength < sizeof(ACL_SIZE_INFORMATION))
|
|
|
|
{
|
|
|
|
return(STATUS_BUFFER_TOO_SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RtlFirstFreeAce(Acl, &Ace))
|
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
Info->AceCount = Acl->AceCount;
|
|
|
|
if (Ace != NULL)
|
|
|
|
{
|
2005-06-30 21:38:39 +00:00
|
|
|
Info->AclBytesInUse = (DWORD)((ULONG_PTR)Ace - (ULONG_PTR)Acl);
|
2004-05-31 19:33:59 +00:00
|
|
|
Info->AclBytesFree = Acl->AclSize - Info->AclBytesInUse;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info->AclBytesInUse = Acl->AclSize;
|
|
|
|
Info->AclBytesFree = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(STATUS_INVALID_INFO_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
NTSTATUS NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlSetInformationAcl(PACL Acl,
|
|
|
|
PVOID Information,
|
|
|
|
ULONG InformationLength,
|
|
|
|
ACL_INFORMATION_CLASS InformationClass)
|
|
|
|
{
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2004-11-27 16:33:21 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (InformationClass)
|
|
|
|
{
|
|
|
|
case AclRevisionInformation:
|
|
|
|
{
|
|
|
|
PACL_REVISION_INFORMATION Info = (PACL_REVISION_INFORMATION)Information;
|
|
|
|
|
|
|
|
if (InformationLength < sizeof(ACL_REVISION_INFORMATION))
|
|
|
|
{
|
|
|
|
return(STATUS_BUFFER_TOO_SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Acl->AclRevision >= Info->AclRevision)
|
|
|
|
{
|
|
|
|
return(STATUS_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
Acl->AclRevision = Info->AclRevision;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(STATUS_INVALID_INFO_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-10-19 17:03:38 +00:00
|
|
|
BOOLEAN NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlValidAcl (PACL Acl)
|
|
|
|
{
|
|
|
|
PACE Ace;
|
|
|
|
USHORT Size;
|
2005-05-09 01:41:02 +00:00
|
|
|
|
2005-02-22 17:58:19 +00:00
|
|
|
PAGED_CODE_RTL();
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2004-11-27 16:33:21 +00:00
|
|
|
Size = ROUND_UP(Acl->AclSize, 4);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
if (Acl->AclRevision < MIN_ACL_REVISION ||
|
2004-11-27 16:33:21 +00:00
|
|
|
Acl->AclRevision > MAX_ACL_REVISION)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Size != Acl->AclSize)
|
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(RtlFirstFreeAce(Acl, &Ace));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|