-/* $Id: sid.c,v 1.1 2004/05/31 19:29:02 gdalsnes Exp $
+/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#define __NTDRIVER__
#include <ddk/ntddk.h>
+#include <ntdll/rtl.h>
#include <string.h>
/* FUNCTIONS ***************************************************************/
BOOLEAN STDCALL
-RtlValidSid(IN PSID Sid)
+RtlValidSid(IN PSID Sid_)
{
- if ((Sid->Revision & 0xf) != 1)
- {
- return(FALSE);
- }
- if (Sid->SubAuthorityCount > 15)
- {
- return(FALSE);
- }
- return(TRUE);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ if ((Sid->Revision != SID_REVISION) ||
+ (Sid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
ULONG STDCALL
RtlLengthRequiredSid(IN UCHAR SubAuthorityCount)
{
- return(sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
+ PAGED_CODE_RTL();
+
+ return (sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
}
* @implemented
*/
NTSTATUS STDCALL
-RtlInitializeSid(IN PSID Sid,
+RtlInitializeSid(IN PSID Sid_,
IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
IN UCHAR SubAuthorityCount)
{
- Sid->Revision = 1;
- Sid->SubAuthorityCount = SubAuthorityCount;
- memcpy(&Sid->IdentifierAuthority,
- IdentifierAuthority,
- sizeof(SID_IDENTIFIER_AUTHORITY));
- return(STATUS_SUCCESS);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ Sid->Revision = SID_REVISION;
+ Sid->SubAuthorityCount = SubAuthorityCount;
+ memcpy(&Sid->IdentifierAuthority,
+ IdentifierAuthority,
+ sizeof(SID_IDENTIFIER_AUTHORITY));
+
+ return STATUS_SUCCESS;
}
* @implemented
*/
PULONG STDCALL
-RtlSubAuthoritySid(IN PSID Sid,
+RtlSubAuthoritySid(IN PSID Sid_,
IN ULONG SubAuthority)
{
- return(&Sid->SubAuthority[SubAuthority]);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ return &Sid->SubAuthority[SubAuthority];
}
* @implemented
*/
PUCHAR STDCALL
-RtlSubAuthorityCountSid(IN PSID Sid)
+RtlSubAuthorityCountSid(IN PSID Sid_)
{
- return(&Sid->SubAuthorityCount);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ return &Sid->SubAuthorityCount;
}
* @implemented
*/
BOOLEAN STDCALL
-RtlEqualSid(IN PSID Sid1,
- IN PSID Sid2)
+RtlEqualSid(IN PSID Sid1_,
+ IN PSID Sid2_)
{
- if (Sid1->Revision != Sid2->Revision)
+ PISID Sid1 = Sid1_;
+ PISID Sid2 = Sid2_;
+
+ PAGED_CODE_RTL();
+
+ if (Sid1->Revision != Sid2->Revision)
{
return(FALSE);
}
{
return(FALSE);
}
- if (RtlCompareMemory(Sid1, Sid2, RtlLengthSid(Sid1)) != 0)
+ if (RtlCompareMemory(Sid1, Sid2, RtlLengthSid(Sid1)) != RtlLengthSid(Sid1))
{
return(FALSE);
}
* @implemented
*/
ULONG STDCALL
-RtlLengthSid(IN PSID Sid)
+RtlLengthSid(IN PSID Sid_)
{
- return(sizeof(SID) + (Sid->SubAuthorityCount-1)*4);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ return (sizeof(SID) + (Sid->SubAuthorityCount-1) * sizeof(ULONG));
}
PSID Dest,
PSID Src)
{
- if (BufferLength < RtlLengthSid(Src))
- {
- return(STATUS_UNSUCCESSFUL);
- }
- memmove(Dest,
- Src,
- RtlLengthSid(Src));
- return(STATUS_SUCCESS);
+ PAGED_CODE_RTL();
+
+ if (BufferLength < RtlLengthSid(Src))
+ {
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ memmove(Dest,
+ Src,
+ RtlLengthSid(Src));
+
+ return STATUS_SUCCESS;
}
ULONG SidLength;
ULONG Length;
ULONG i;
+
+ PAGED_CODE_RTL();
Length = SidAreaSize;
RtlCopySid(SidLength,
SidArea,
Src[i].Sid);
- SidArea = SidArea + SidLength;
+ SidArea = (PVOID)((ULONG_PTR)SidArea + SidLength);
}
*RemainingSidArea = SidArea;
*RemainingSidAreaSize = Length;
* @implemented
*/
PSID_IDENTIFIER_AUTHORITY STDCALL
-RtlIdentifierAuthoritySid(IN PSID Sid)
+RtlIdentifierAuthoritySid(IN PSID Sid_)
{
- return(&Sid->IdentifierAuthority);
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
+
+ return &Sid->IdentifierAuthority;
}
/*
* @implemented
*/
-NTSTATUS
-STDCALL
-RtlAllocateAndInitializeSid (
- PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
- UCHAR SubAuthorityCount,
- ULONG SubAuthority0,
- ULONG SubAuthority1,
- ULONG SubAuthority2,
- ULONG SubAuthority3,
- ULONG SubAuthority4,
- ULONG SubAuthority5,
- ULONG SubAuthority6,
- ULONG SubAuthority7,
- PSID *Sid
-)
+NTSTATUS STDCALL
+RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
+ UCHAR SubAuthorityCount,
+ ULONG SubAuthority0,
+ ULONG SubAuthority1,
+ ULONG SubAuthority2,
+ ULONG SubAuthority3,
+ ULONG SubAuthority4,
+ ULONG SubAuthority5,
+ ULONG SubAuthority6,
+ ULONG SubAuthority7,
+ PSID *Sid)
{
- PSID pSid;
+ PISID pSid;
+
+ PAGED_CODE_RTL();
- if (SubAuthorityCount > 8)
- return STATUS_INVALID_SID;
+ if (SubAuthorityCount > 8)
+ return STATUS_INVALID_SID;
- if (Sid == NULL)
- return STATUS_INVALID_PARAMETER;
+ if (Sid == NULL)
+ return STATUS_INVALID_PARAMETER;
- pSid = (PSID)RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- SubAuthorityCount * sizeof(DWORD) + 8);
- if (pSid == NULL)
- return STATUS_NO_MEMORY;
+ pSid = (PSID)ExAllocatePool(PagedPool,
+ sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
+ if (pSid == NULL)
+ return STATUS_NO_MEMORY;
- pSid->Revision = 1;
- pSid->SubAuthorityCount = SubAuthorityCount;
- memcpy (&pSid->IdentifierAuthority,
- IdentifierAuthority,
- sizeof(SID_IDENTIFIER_AUTHORITY));
+ pSid->Revision = SID_REVISION;
+ pSid->SubAuthorityCount = SubAuthorityCount;
+ memcpy(&pSid->IdentifierAuthority,
+ IdentifierAuthority,
+ sizeof(SID_IDENTIFIER_AUTHORITY));
- switch (SubAuthorityCount)
- {
+ switch (SubAuthorityCount)
+ {
case 8:
pSid->SubAuthority[7] = SubAuthority7;
case 7:
case 1:
pSid->SubAuthority[0] = SubAuthority0;
break;
- }
+ }
- *Sid = pSid;
+ *Sid = pSid;
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
/*
* @implemented
+ *
+ * RETURNS
+ * Docs says FreeSid does NOT return a value
+ * even thou it's defined to return a PVOID...
*/
-PSID STDCALL
+PVOID STDCALL
RtlFreeSid(IN PSID Sid)
{
- RtlFreeHeap(RtlGetProcessHeap(),
- 0,
- Sid);
- return(Sid);
+ PAGED_CODE_RTL();
+
+ ExFreePool(Sid);
+ return NULL;
}
* @implemented
*/
BOOLEAN STDCALL
-RtlEqualPrefixSid(IN PSID Sid1,
- IN PSID Sid2)
+RtlEqualPrefixSid(IN PSID Sid1_,
+ IN PSID Sid2_)
{
+ PISID Sid1 = Sid1_;
+ PISID Sid2 = Sid2_;
+
+ PAGED_CODE_RTL();
+
return(Sid1->SubAuthorityCount == Sid2->SubAuthorityCount &&
!RtlCompareMemory(Sid1, Sid2,
(Sid1->SubAuthorityCount - 1) * sizeof(DWORD) + 8));
*/
NTSTATUS STDCALL
RtlConvertSidToUnicodeString(PUNICODE_STRING String,
- PSID Sid,
+ PSID Sid_,
BOOLEAN AllocateBuffer)
{
WCHAR Buffer[256];
PWSTR wcs;
ULONG Length;
ULONG i;
+ PISID Sid = Sid_;
+
+ PAGED_CODE_RTL();
if (RtlValidSid (Sid) == FALSE)
return STATUS_INVALID_SID;
Length = (wcs - Buffer) * sizeof(WCHAR);
if (AllocateBuffer)
{
- String->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
- 0,
- Length + sizeof(WCHAR));
+ String->Buffer = ExAllocatePool(PagedPool,Length + sizeof(WCHAR));
if (String->Buffer == NULL)
return STATUS_NO_MEMORY;
String->MaximumLength = Length + sizeof(WCHAR);