Use proper PISID pointer to SID structure, fix wrong LUID definition, and remove duplicate code in Security Manager

svn path=/trunk/; revision=12806
This commit is contained in:
Alex Ionescu 2005-01-04 22:44:50 +00:00
parent ddd07cb377
commit 4dba0925ac
8 changed files with 76 additions and 263 deletions

View file

@ -193,6 +193,18 @@ RtlpInitDeferedCriticalSection(
VOID VOID
); );
VOID
STDCALL
RtlpFreeDebugInfo(
PRTL_CRITICAL_SECTION_DEBUG DebugInfo
);
PRTL_CRITICAL_SECTION_DEBUG
STDCALL
RtlpAllocateDebugInfo(
VOID
);
NTSTATUS STDCALL NTSTATUS STDCALL
RtlAddAccessAllowedAceEx (IN OUT PACL Acl, RtlAddAccessAllowedAceEx (IN OUT PACL Acl,
IN ULONG Revision, IN ULONG Revision,

View file

@ -83,8 +83,8 @@ typedef struct _OBJECT_ATTRIBUTES
HANDLE RootDirectory; HANDLE RootDirectory;
PUNICODE_STRING ObjectName; PUNICODE_STRING ObjectName;
ULONG Attributes; ULONG Attributes;
SECURITY_DESCRIPTOR *SecurityDescriptor; PVOID SecurityDescriptor;
SECURITY_QUALITY_OF_SERVICE *SecurityQualityOfService; PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
#endif /* __USE_W32API */ #endif /* __USE_W32API */

View file

@ -74,6 +74,18 @@ typedef struct _SECURITY_DESCRIPTOR_CONTEXT
#ifndef __USE_W32API #ifndef __USE_W32API
#ifndef _MSC_VER
#define SYSTEM_LUID {{ 0x3E7, 0x0 }}
#define ANONYMOUS_LOGON_LUID {{ 0x3e6, 0x0 }}
#define LOCALSERVICE_LUID {{ 0x3e5, 0x0 }}
#define NETWORKSERVICE_LUID {{ 0x3e4, 0x0 }}
#else
#define SYSTEM_LUID { 0x3E7, 0x0 }
#define ANONYMOUS_LOGON_LUID { 0x3e6, 0x0 }
#define LOCALSERVICE_LUID { 0x3e5, 0x0 }
#define NETWORKSERVICE_LUID { 0x3e4, 0x0 }
#endif
/* SID Auhority */ /* SID Auhority */
#define SECURITY_NULL_SID_AUTHORITY {0,0,0,0,0,0} #define SECURITY_NULL_SID_AUTHORITY {0,0,0,0,0,0}
#define SECURITY_WORLD_SID_AUTHORITY {0,0,0,0,0,1} #define SECURITY_WORLD_SID_AUTHORITY {0,0,0,0,0,1}
@ -227,7 +239,9 @@ typedef struct _SID
UCHAR SubAuthorityCount; UCHAR SubAuthorityCount;
SID_IDENTIFIER_AUTHORITY IdentifierAuthority; SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
ULONG SubAuthority[1]; ULONG SubAuthority[1];
} SID, *PSID; } SID, *PISID;
typedef PVOID PSID;
typedef struct _ACL typedef struct _ACL
{ {

View file

@ -1,4 +1,4 @@
/* $Id: sid.c,v 1.4 2004/07/12 19:39:29 ekohl Exp $ /* $Id$
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -22,8 +22,10 @@
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
BOOLEAN STDCALL BOOLEAN STDCALL
RtlValidSid(IN PSID Sid) RtlValidSid(IN PSID Sid_)
{ {
PISID Sid = Sid_;
if ((Sid->Revision != SID_REVISION) || if ((Sid->Revision != SID_REVISION) ||
(Sid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES)) (Sid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES))
{ {
@ -48,10 +50,12 @@ RtlLengthRequiredSid(IN UCHAR SubAuthorityCount)
* @implemented * @implemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
RtlInitializeSid(IN PSID Sid, RtlInitializeSid(IN PSID Sid_,
IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
IN UCHAR SubAuthorityCount) IN UCHAR SubAuthorityCount)
{ {
PISID Sid = Sid_;
Sid->Revision = SID_REVISION; Sid->Revision = SID_REVISION;
Sid->SubAuthorityCount = SubAuthorityCount; Sid->SubAuthorityCount = SubAuthorityCount;
memcpy(&Sid->IdentifierAuthority, memcpy(&Sid->IdentifierAuthority,
@ -66,9 +70,11 @@ RtlInitializeSid(IN PSID Sid,
* @implemented * @implemented
*/ */
PULONG STDCALL PULONG STDCALL
RtlSubAuthoritySid(IN PSID Sid, RtlSubAuthoritySid(IN PSID Sid_,
IN ULONG SubAuthority) IN ULONG SubAuthority)
{ {
PISID Sid = Sid_;
return &Sid->SubAuthority[SubAuthority]; return &Sid->SubAuthority[SubAuthority];
} }
@ -77,8 +83,10 @@ RtlSubAuthoritySid(IN PSID Sid,
* @implemented * @implemented
*/ */
PUCHAR STDCALL PUCHAR STDCALL
RtlSubAuthorityCountSid(IN PSID Sid) RtlSubAuthorityCountSid(IN PSID Sid_)
{ {
PISID Sid = Sid_;
return &Sid->SubAuthorityCount; return &Sid->SubAuthorityCount;
} }
@ -87,9 +95,12 @@ RtlSubAuthorityCountSid(IN PSID Sid)
* @implemented * @implemented
*/ */
BOOLEAN STDCALL BOOLEAN STDCALL
RtlEqualSid(IN PSID Sid1, RtlEqualSid(IN PSID Sid1_,
IN PSID Sid2) IN PSID Sid2_)
{ {
PISID Sid1 = Sid1_;
PISID Sid2 = Sid2_;
if (Sid1->Revision != Sid2->Revision) if (Sid1->Revision != Sid2->Revision)
{ {
return(FALSE); return(FALSE);
@ -110,8 +121,10 @@ RtlEqualSid(IN PSID Sid1,
* @implemented * @implemented
*/ */
ULONG STDCALL ULONG STDCALL
RtlLengthSid(IN PSID Sid) RtlLengthSid(IN PSID Sid_)
{ {
PISID Sid = Sid_;
return (sizeof(SID) + (Sid->SubAuthorityCount-1) * sizeof(ULONG)); return (sizeof(SID) + (Sid->SubAuthorityCount-1) * sizeof(ULONG));
} }
@ -180,8 +193,10 @@ RtlCopySidAndAttributesArray(ULONG Count,
* @implemented * @implemented
*/ */
PSID_IDENTIFIER_AUTHORITY STDCALL PSID_IDENTIFIER_AUTHORITY STDCALL
RtlIdentifierAuthoritySid(IN PSID Sid) RtlIdentifierAuthoritySid(IN PSID Sid_)
{ {
PISID Sid = Sid_;
return &Sid->IdentifierAuthority; return &Sid->IdentifierAuthority;
} }
@ -202,7 +217,7 @@ RtlAllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
ULONG SubAuthority7, ULONG SubAuthority7,
PSID *Sid) PSID *Sid)
{ {
PSID pSid; PISID pSid;
if (SubAuthorityCount > 8) if (SubAuthorityCount > 8)
return STATUS_INVALID_SID; return STATUS_INVALID_SID;
@ -267,9 +282,12 @@ RtlFreeSid(IN PSID Sid)
* @implemented * @implemented
*/ */
BOOLEAN STDCALL BOOLEAN STDCALL
RtlEqualPrefixSid(IN PSID Sid1, RtlEqualPrefixSid(IN PSID Sid1_,
IN PSID Sid2) IN PSID Sid2_)
{ {
PISID Sid1 = Sid1_;
PISID Sid2 = Sid2_;
return(Sid1->SubAuthorityCount == Sid2->SubAuthorityCount && return(Sid1->SubAuthorityCount == Sid2->SubAuthorityCount &&
!RtlCompareMemory(Sid1, Sid2, !RtlCompareMemory(Sid1, Sid2,
(Sid1->SubAuthorityCount - 1) * sizeof(DWORD) + 8)); (Sid1->SubAuthorityCount - 1) * sizeof(DWORD) + 8));
@ -281,13 +299,14 @@ RtlEqualPrefixSid(IN PSID Sid1,
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
RtlConvertSidToUnicodeString(PUNICODE_STRING String, RtlConvertSidToUnicodeString(PUNICODE_STRING String,
PSID Sid, PSID Sid_,
BOOLEAN AllocateBuffer) BOOLEAN AllocateBuffer)
{ {
WCHAR Buffer[256]; WCHAR Buffer[256];
PWSTR wcs; PWSTR wcs;
ULONG Length; ULONG Length;
ULONG i; ULONG i;
PISID Sid = Sid_;
if (RtlValidSid (Sid) == FALSE) if (RtlValidSid (Sid) == FALSE)
return STATUS_INVALID_SID; return STATUS_INVALID_SID;

View file

@ -1,4 +1,4 @@
/* $Id: luid.c,v 1.10 2004/08/15 16:39:11 chorns Exp $ /* $Id$
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -20,15 +20,15 @@ static KSPIN_LOCK LuidLock;
static LARGE_INTEGER LuidIncrement; static LARGE_INTEGER LuidIncrement;
static LARGE_INTEGER LuidValue; static LARGE_INTEGER LuidValue;
#define SYSTEM_LUID 0x3E7;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID INIT_FUNCTION VOID INIT_FUNCTION
SepInitLuid(VOID) SepInitLuid(VOID)
{ {
LARGE_INTEGER DummyLuidValue = SYSTEM_LUID;
KeInitializeSpinLock(&LuidLock); KeInitializeSpinLock(&LuidLock);
LuidValue.QuadPart = SYSTEM_LUID; LuidValue = DummyLuidValue;
LuidIncrement.QuadPart = 1; LuidIncrement.QuadPart = 1;
} }

View file

@ -1,4 +1,4 @@
/* $Id: sd.c,v 1.20 2004/08/15 16:39:12 chorns Exp $ /* $Id$
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -319,7 +319,7 @@ SeValidSecurityDescriptor(IN ULONG Length,
IN PSECURITY_DESCRIPTOR SecurityDescriptor) IN PSECURITY_DESCRIPTOR SecurityDescriptor)
{ {
ULONG SdLength; ULONG SdLength;
PSID Sid; PISID Sid;
PACL Acl; PACL Acl;
if (Length < SECURITY_DESCRIPTOR_MIN_LENGTH) if (Length < SECURITY_DESCRIPTOR_MIN_LENGTH)
@ -355,7 +355,7 @@ SeValidSecurityDescriptor(IN ULONG Length,
return FALSE; return FALSE;
} }
Sid = (PSID)((ULONG_PTR)SecurityDescriptor + (ULONG_PTR)SecurityDescriptor->Owner); Sid = (PISID)((ULONG_PTR)SecurityDescriptor + (ULONG_PTR)SecurityDescriptor->Owner);
if (Sid->Revision != SID_REVISION) if (Sid->Revision != SID_REVISION)
{ {
DPRINT1("Invalid Owner SID revision\n"); DPRINT1("Invalid Owner SID revision\n");

View file

@ -1,4 +1,4 @@
/* $Id: sid.c,v 1.16 2003/12/30 18:52:06 fireball Exp $ /* $Id$
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -11,9 +11,9 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ntoskrnl.h>
#include <internal/se.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#define TAG_SID TAG('S', 'I', 'D', 'T') #define TAG_SID TAG('S', 'I', 'D', 'T')
@ -467,230 +467,4 @@ SepInitSecurityIDs(VOID)
return(TRUE); return(TRUE);
} }
/*
* @implemented
*/
BOOLEAN STDCALL
RtlValidSid(PSID Sid)
{
if ((Sid->Revision & 0xf) != 1)
{
return(FALSE);
}
if (Sid->SubAuthorityCount > 15)
{
return(FALSE);
}
return(TRUE);
}
/*
* @implemented
*/
ULONG STDCALL
RtlLengthRequiredSid(UCHAR SubAuthorityCount)
{
return(sizeof(SID) + (SubAuthorityCount - 1) * sizeof(ULONG));
}
/*
* @implemented
*/
NTSTATUS STDCALL
RtlInitializeSid(PSID Sid,
PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
UCHAR SubAuthorityCount)
{
Sid->Revision = 1;
Sid->SubAuthorityCount = SubAuthorityCount;
RtlCopyMemory(&Sid->IdentifierAuthority,
IdentifierAuthority,
sizeof(SID_IDENTIFIER_AUTHORITY));
return(STATUS_SUCCESS);
}
/*
* @implemented
*/
PULONG STDCALL
RtlSubAuthoritySid(PSID Sid,
ULONG SubAuthority)
{
return(&Sid->SubAuthority[SubAuthority]);
}
/*
* @implemented
*/
PUCHAR STDCALL
RtlSubAuthorityCountSid(PSID Sid)
{
return(&Sid->SubAuthorityCount);
}
/*
* @implemented
*/
BOOLEAN STDCALL
RtlEqualSid(PSID Sid1,
PSID Sid2)
{
if (Sid1->Revision != Sid2->Revision)
{
return(FALSE);
}
if ((*RtlSubAuthorityCountSid(Sid1)) !=
(*RtlSubAuthorityCountSid(Sid2)))
{
return(FALSE);
}
if (memcmp(Sid1, Sid2, RtlLengthSid(Sid1)) != 0)
{
return(FALSE);
}
return(TRUE);
}
/*
* @implemented
*/
ULONG STDCALL
RtlLengthSid(PSID Sid)
{
return(sizeof(SID) + (Sid->SubAuthorityCount-1)*4);
}
/*
* @implemented
*/
NTSTATUS STDCALL
RtlCopySid(ULONG BufferLength,
PSID Dest,
PSID Src)
{
if (BufferLength < RtlLengthSid(Src))
{
return(STATUS_UNSUCCESSFUL);
}
memmove(Dest, Src, RtlLengthSid(Src));
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL
RtlCopySidAndAttributesArray(ULONG Count,
PSID_AND_ATTRIBUTES Src,
ULONG SidAreaSize,
PSID_AND_ATTRIBUTES Dest,
PVOID SidArea,
PVOID* RemainingSidArea,
PULONG RemainingSidAreaSize)
{
ULONG Length;
ULONG i;
Length = SidAreaSize;
for (i=0; i<Count; i++)
{
if (RtlLengthSid(Src[i].Sid) > Length)
{
return(STATUS_BUFFER_TOO_SMALL);
}
Length = Length - RtlLengthSid(Src[i].Sid);
Dest[i].Sid = SidArea;
Dest[i].Attributes = Src[i].Attributes;
RtlCopySid(RtlLengthSid(Src[i].Sid), SidArea, Src[i].Sid);
SidArea = (char*)SidArea + RtlLengthSid(Src[i].Sid);
}
*RemainingSidArea = SidArea;
*RemainingSidAreaSize = Length;
return(STATUS_SUCCESS);
}
/*
* @implemented
*/
NTSTATUS STDCALL
RtlConvertSidToUnicodeString(PUNICODE_STRING String,
PSID Sid,
BOOLEAN AllocateString)
{
WCHAR Buffer[256];
PWSTR Ptr;
ULONG Length;
ULONG i;
if (!RtlValidSid(Sid))
return STATUS_INVALID_SID;
Ptr = Buffer;
Ptr += swprintf (Ptr,
L"S-%u-",
Sid->Revision);
if(!Sid->IdentifierAuthority.Value[0] &&
!Sid->IdentifierAuthority.Value[1])
{
Ptr += swprintf(Ptr,
L"%u",
(ULONG)Sid->IdentifierAuthority.Value[2] << 24 |
(ULONG)Sid->IdentifierAuthority.Value[3] << 16 |
(ULONG)Sid->IdentifierAuthority.Value[4] << 8 |
(ULONG)Sid->IdentifierAuthority.Value[5]);
}
else
{
Ptr += swprintf(Ptr,
L"0x%02hx%02hx%02hx%02hx%02hx%02hx",
Sid->IdentifierAuthority.Value[0],
Sid->IdentifierAuthority.Value[1],
Sid->IdentifierAuthority.Value[2],
Sid->IdentifierAuthority.Value[3],
Sid->IdentifierAuthority.Value[4],
Sid->IdentifierAuthority.Value[5]);
}
for (i = 0; i < Sid->SubAuthorityCount; i++)
{
Ptr += swprintf(Ptr,
L"-%u",
Sid->SubAuthority[i]);
}
Length = (Ptr - Buffer) * sizeof(WCHAR);
if (AllocateString)
{
String->Buffer = ExAllocatePool(NonPagedPool,
Length + sizeof(WCHAR));
if (String->Buffer == NULL)
return STATUS_NO_MEMORY;
String->MaximumLength = Length + sizeof(WCHAR);
}
else
{
if (Length > String->MaximumLength)
return STATUS_BUFFER_TOO_SMALL;
}
String->Length = Length;
memmove(String->Buffer,
Buffer,
Length);
if (Length < String->MaximumLength)
String->Buffer[Length/sizeof(WCHAR)] = 0;
return STATUS_SUCCESS;
}
/* EOF */ /* EOF */

View file

@ -11,13 +11,7 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <limits.h> #include <ntoskrnl.h>
#define NTOS_MODE_KERNEL
#include <ntos.h>
#include <internal/ob.h>
#include <internal/ps.h>
#include <internal/se.h>
#include <internal/safe.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
@ -31,8 +25,6 @@ static GENERIC_MAPPING SepTokenMapping = {TOKEN_READ,
TOKEN_EXECUTE, TOKEN_EXECUTE,
TOKEN_ALL_ACCESS}; TOKEN_ALL_ACCESS};
//#define SYSTEM_LUID 0x3E7;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID SepFreeProxyData(PVOID ProxyData) VOID SepFreeProxyData(PVOID ProxyData)
@ -1028,6 +1020,7 @@ NtSetInformationToken(IN HANDLE TokenHandle,
* NOTE: Some sources claim 4th param is ImpersonationLevel, but on W2K * NOTE: Some sources claim 4th param is ImpersonationLevel, but on W2K
* this is certainly NOT true, thou i can't say for sure that EffectiveOnly * this is certainly NOT true, thou i can't say for sure that EffectiveOnly
* is correct either. -Gunnar * is correct either. -Gunnar
* This is true. EffectiveOnly overrides SQOS.EffectiveOnly. - IAI
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
NtDuplicateToken(IN HANDLE ExistingTokenHandle, NtDuplicateToken(IN HANDLE ExistingTokenHandle,
@ -1060,7 +1053,7 @@ NtDuplicateToken(IN HANDLE ExistingTokenHandle,
EffectiveOnly, EffectiveOnly,
TokenType, TokenType,
ObjectAttributes->SecurityQualityOfService ? ObjectAttributes->SecurityQualityOfService ?
ObjectAttributes->SecurityQualityOfService->ImpersonationLevel : ((PSECURITY_QUALITY_OF_SERVICE)(ObjectAttributes->SecurityQualityOfService))->ImpersonationLevel :
0 /*SecurityAnonymous*/, 0 /*SecurityAnonymous*/,
PreviousMode, PreviousMode,
&NewToken); &NewToken);
@ -1645,7 +1638,8 @@ NtCreateToken(OUT PHANDLE UnsafeTokenHandle,
AccessToken->Privileges = 0; AccessToken->Privileges = 0;
AccessToken->TokenType = TokenType; AccessToken->TokenType = TokenType;
AccessToken->ImpersonationLevel = ObjectAttributes->SecurityQualityOfService->ImpersonationLevel; AccessToken->ImpersonationLevel = ((PSECURITY_QUALITY_OF_SERVICE)
(ObjectAttributes->SecurityQualityOfService))->ImpersonationLevel;
/* /*
* Normally we would just point these members into the variable information * Normally we would just point these members into the variable information