Skip to content

Commit f48191b

Browse files
committed
[NTOS:SE] Enable support for principal and restricted SIDs
SepSidInTokenEx function already provides the necessary mechanism to handle scenario where a token has restricted SIDs or a principal SID is given to the call. There's no reason to have these redundant ASSERTs anymore. In addition to that make sure if the SID is not a restricted and if that SID is the first element on the array and it's enabled, this is the primary user.
1 parent bac67a6 commit f48191b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ntoskrnl/se/access.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ERESOURCE SepSubjectContextLock;
3737
*
3838
* @param[in] Restricted
3939
* If set to TRUE, the caller expects that a SID in a token is
40-
* restricted.
40+
* restricted (by the general definition, a token is restricted).
4141
*
4242
* @return
4343
* Returns TRUE if the specified SID in the call is present in the token,
@@ -52,18 +52,14 @@ SepSidInTokenEx(
5252
_In_ BOOLEAN Deny,
5353
_In_ BOOLEAN Restricted)
5454
{
55-
ULONG i;
55+
ULONG SidIndex;
5656
PTOKEN Token = (PTOKEN)_Token;
5757
PISID TokenSid, Sid = (PISID)_Sid;
5858
PSID_AND_ATTRIBUTES SidAndAttributes;
5959
ULONG SidCount, SidLength;
6060
USHORT SidMetadata;
6161
PAGED_CODE();
6262

63-
/* Not yet supported */
64-
ASSERT(PrincipalSelfSid == NULL);
65-
ASSERT(Restricted == FALSE);
66-
6763
/* Check if a principal SID was given, and this is our current SID already */
6864
if ((PrincipalSelfSid) && (RtlEqualSid(SePrincipalSelfSid, Sid)))
6965
{
@@ -91,7 +87,7 @@ SepSidInTokenEx(
9187
SidMetadata = *(PUSHORT)&Sid->Revision;
9288

9389
/* Loop every SID */
94-
for (i = 0; i < SidCount; i++)
90+
for (SidIndex = 0; SidIndex < SidCount; SidIndex++)
9591
{
9692
TokenSid = (PISID)SidAndAttributes->Sid;
9793
#if SE_SID_DEBUG
@@ -106,8 +102,15 @@ SepSidInTokenEx(
106102
/* Check if the SID data matches */
107103
if (RtlEqualMemory(Sid, TokenSid, SidLength))
108104
{
109-
/* Check if the group is enabled, or used for deny only */
110-
if ((!(i) && !(SidAndAttributes->Attributes & SE_GROUP_USE_FOR_DENY_ONLY)) ||
105+
/*
106+
* Check if the group is enabled, or used for deny only.
107+
* Otherwise we have to check if this is the first user.
108+
* We understand that by looking if this SID is not
109+
* restricted, this is the first element we are iterating
110+
* and that it doesn't have SE_GROUP_USE_FOR_DENY_ONLY
111+
* attribute.
112+
*/
113+
if ((!Restricted && (SidIndex == 0) && !(SidAndAttributes->Attributes & SE_GROUP_USE_FOR_DENY_ONLY)) ||
111114
(SidAndAttributes->Attributes & SE_GROUP_ENABLED) ||
112115
((Deny) && (SidAndAttributes->Attributes & SE_GROUP_USE_FOR_DENY_ONLY)))
113116
{

0 commit comments

Comments
 (0)