Fix RtlEqualSid().

svn path=/trunk/; revision=10062
This commit is contained in:
Eric Kohl 2004-07-10 13:11:18 +00:00
parent 7f900f8f7e
commit 39da3d41f9

View file

@ -1,4 +1,4 @@
/* $Id: sid.c,v 1.2 2004/06/20 23:30:47 gdalsnes Exp $ /* $Id: sid.c,v 1.3 2004/07/10 13:11:18 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -24,15 +24,13 @@
BOOLEAN STDCALL BOOLEAN STDCALL
RtlValidSid(IN PSID Sid) RtlValidSid(IN PSID Sid)
{ {
if ((Sid->Revision & 0xf) != 1) if (((Sid->Revision & 0xf) != 1) ||
{ (Sid->SubAuthorityCount > 15))
return(FALSE); {
} return FALSE;
if (Sid->SubAuthorityCount > 15) }
{
return(FALSE); return TRUE;
}
return(TRUE);
} }
@ -42,7 +40,7 @@ RtlValidSid(IN PSID Sid)
ULONG STDCALL ULONG STDCALL
RtlLengthRequiredSid(IN UCHAR SubAuthorityCount) RtlLengthRequiredSid(IN UCHAR SubAuthorityCount)
{ {
return(sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG)); return (sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
} }
@ -54,12 +52,13 @@ RtlInitializeSid(IN PSID Sid,
IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
IN UCHAR SubAuthorityCount) IN UCHAR SubAuthorityCount)
{ {
Sid->Revision = 1; Sid->Revision = 1;
Sid->SubAuthorityCount = SubAuthorityCount; Sid->SubAuthorityCount = SubAuthorityCount;
memcpy(&Sid->IdentifierAuthority, memcpy(&Sid->IdentifierAuthority,
IdentifierAuthority, IdentifierAuthority,
sizeof(SID_IDENTIFIER_AUTHORITY)); sizeof(SID_IDENTIFIER_AUTHORITY));
return(STATUS_SUCCESS);
return STATUS_SUCCESS;
} }
@ -70,7 +69,7 @@ PULONG STDCALL
RtlSubAuthoritySid(IN PSID Sid, RtlSubAuthoritySid(IN PSID Sid,
IN ULONG SubAuthority) IN ULONG SubAuthority)
{ {
return(&Sid->SubAuthority[SubAuthority]); return &Sid->SubAuthority[SubAuthority];
} }
@ -80,7 +79,7 @@ RtlSubAuthoritySid(IN PSID Sid,
PUCHAR STDCALL PUCHAR STDCALL
RtlSubAuthorityCountSid(IN PSID Sid) RtlSubAuthorityCountSid(IN PSID Sid)
{ {
return(&Sid->SubAuthorityCount); return &Sid->SubAuthorityCount;
} }
@ -91,7 +90,7 @@ BOOLEAN STDCALL
RtlEqualSid(IN PSID Sid1, RtlEqualSid(IN PSID Sid1,
IN PSID Sid2) IN PSID Sid2)
{ {
if (Sid1->Revision != Sid2->Revision) if (Sid1->Revision != Sid2->Revision)
{ {
return(FALSE); return(FALSE);
} }
@ -99,7 +98,7 @@ RtlEqualSid(IN PSID Sid1,
{ {
return(FALSE); return(FALSE);
} }
if (RtlCompareMemory(Sid1, Sid2, RtlLengthSid(Sid1)) != 0) if (RtlCompareMemory(Sid1, Sid2, RtlLengthSid(Sid1)) != RtlLengthSid(Sid1))
{ {
return(FALSE); return(FALSE);
} }
@ -113,7 +112,7 @@ RtlEqualSid(IN PSID Sid1,
ULONG STDCALL ULONG STDCALL
RtlLengthSid(IN PSID Sid) RtlLengthSid(IN PSID Sid)
{ {
return(sizeof(SID) + (Sid->SubAuthorityCount-1)*4); return (sizeof(SID) + (Sid->SubAuthorityCount-1) * sizeof(ULONG));
} }
@ -125,14 +124,16 @@ RtlCopySid(ULONG BufferLength,
PSID Dest, PSID Dest,
PSID Src) PSID Src)
{ {
if (BufferLength < RtlLengthSid(Src)) if (BufferLength < RtlLengthSid(Src))
{ {
return(STATUS_UNSUCCESSFUL); return STATUS_UNSUCCESSFUL;
} }
memmove(Dest,
Src, memmove(Dest,
RtlLengthSid(Src)); Src,
return(STATUS_SUCCESS); RtlLengthSid(Src));
return STATUS_SUCCESS;
} }
@ -181,49 +182,47 @@ RtlCopySidAndAttributesArray(ULONG Count,
PSID_IDENTIFIER_AUTHORITY STDCALL PSID_IDENTIFIER_AUTHORITY STDCALL
RtlIdentifierAuthoritySid(IN PSID Sid) RtlIdentifierAuthoritySid(IN PSID Sid)
{ {
return(&Sid->IdentifierAuthority); return &Sid->IdentifierAuthority;
} }
/* /*
* @implemented * @implemented
*/ */
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
RtlAllocateAndInitializeSid ( UCHAR SubAuthorityCount,
PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, ULONG SubAuthority0,
UCHAR SubAuthorityCount, ULONG SubAuthority1,
ULONG SubAuthority0, ULONG SubAuthority2,
ULONG SubAuthority1, ULONG SubAuthority3,
ULONG SubAuthority2, ULONG SubAuthority4,
ULONG SubAuthority3, ULONG SubAuthority5,
ULONG SubAuthority4, ULONG SubAuthority6,
ULONG SubAuthority5, ULONG SubAuthority7,
ULONG SubAuthority6, PSID *Sid)
ULONG SubAuthority7,
PSID *Sid
)
{ {
PSID pSid; PSID pSid;
if (SubAuthorityCount > 8) if (SubAuthorityCount > 8)
return STATUS_INVALID_SID; return STATUS_INVALID_SID;
if (Sid == NULL) if (Sid == NULL)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
pSid = (PSID)ExAllocatePool(PagedPool, SubAuthorityCount * sizeof(DWORD) + 8); pSid = (PSID)ExAllocatePool(PagedPool,
if (pSid == NULL) sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
return STATUS_NO_MEMORY; if (pSid == NULL)
return STATUS_NO_MEMORY;
pSid->Revision = 1; pSid->Revision = 1;
pSid->SubAuthorityCount = SubAuthorityCount; pSid->SubAuthorityCount = SubAuthorityCount;
memcpy (&pSid->IdentifierAuthority, memcpy(&pSid->IdentifierAuthority,
IdentifierAuthority, IdentifierAuthority,
sizeof(SID_IDENTIFIER_AUTHORITY)); sizeof(SID_IDENTIFIER_AUTHORITY));
switch (SubAuthorityCount) switch (SubAuthorityCount)
{ {
case 8: case 8:
pSid->SubAuthority[7] = SubAuthority7; pSid->SubAuthority[7] = SubAuthority7;
case 7: case 7:
@ -241,11 +240,11 @@ RtlAllocateAndInitializeSid (
case 1: case 1:
pSid->SubAuthority[0] = SubAuthority0; pSid->SubAuthority[0] = SubAuthority0;
break; break;
} }
*Sid = pSid; *Sid = pSid;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }