2004-03-14 18:13:19 +00:00
|
|
|
/* $Id: semgr.c,v 1.29 2004/03/14 18:13:19 ekohl Exp $
|
1999-12-26 17:22:19 +00:00
|
|
|
*
|
1998-08-25 04:27:26 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: Security manager
|
|
|
|
* FILE: kernel/se/semgr.c
|
|
|
|
* PROGRAMER: ?
|
|
|
|
* REVISION HISTORY:
|
|
|
|
* 26/07/98: Added stubs for security functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
#include <internal/ps.h>
|
|
|
|
#include <internal/se.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
|
|
|
#include <internal/debug.h>
|
|
|
|
|
2002-02-20 20:16:49 +00:00
|
|
|
#define TAG_SXPT TAG('S', 'X', 'P', 'T')
|
|
|
|
|
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
PSE_EXPORTS EXPORTED SeExports = NULL;
|
2002-02-20 20:16:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* PROTOTYPES ***************************************************************/
|
|
|
|
|
|
|
|
static BOOLEAN SepInitExports(VOID);
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
|
2003-10-12 17:05:50 +00:00
|
|
|
BOOLEAN INIT_FUNCTION
|
2002-02-20 20:16:49 +00:00
|
|
|
SeInit1(VOID)
|
|
|
|
{
|
|
|
|
SepInitLuid();
|
|
|
|
|
|
|
|
if (!SepInitSecurityIDs())
|
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
if (!SepInitDACLs())
|
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
if (!SepInitSDs())
|
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
SepInitPrivileges();
|
|
|
|
|
|
|
|
if (!SepInitExports())
|
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 17:05:50 +00:00
|
|
|
BOOLEAN INIT_FUNCTION
|
2002-02-20 20:16:49 +00:00
|
|
|
SeInit2(VOID)
|
|
|
|
{
|
2002-06-04 14:14:07 +00:00
|
|
|
SepInitializeTokenImplementation();
|
2002-06-04 13:44:06 +00:00
|
|
|
|
|
|
|
return(TRUE);
|
2002-02-20 20:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 21:07:49 +00:00
|
|
|
BOOLEAN
|
|
|
|
SeInitSRM(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
HANDLE DirectoryHandle;
|
|
|
|
HANDLE EventHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Create '\Security' directory */
|
|
|
|
RtlInitUnicodeString(&Name,
|
|
|
|
L"\\Security");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Name,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreateDirectoryObject(&DirectoryHandle,
|
|
|
|
DIRECTORY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create 'Security' directory!\n");
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create 'LSA_AUTHENTICATION_INITALIZED' event */
|
|
|
|
RtlInitUnicodeString(&Name,
|
|
|
|
L"\\LSA_AUTHENTICATION_INITALIZED");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Name,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
DirectoryHandle,
|
|
|
|
SePublicDefaultSd);
|
|
|
|
Status = NtCreateEvent(&EventHandle,
|
|
|
|
EVENT_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
FALSE,
|
|
|
|
FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create 'Security' directory!\n");
|
|
|
|
NtClose(DirectoryHandle);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NtClose(EventHandle);
|
|
|
|
NtClose(DirectoryHandle);
|
|
|
|
|
|
|
|
/* FIXME: Create SRM port and listener thread */
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 17:05:50 +00:00
|
|
|
static BOOLEAN INIT_FUNCTION
|
2002-02-20 20:16:49 +00:00
|
|
|
SepInitExports(VOID)
|
|
|
|
{
|
|
|
|
SeExports = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(SE_EXPORTS),
|
|
|
|
TAG_SXPT);
|
|
|
|
if (SeExports == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
|
|
|
|
SeExports->SeCreateTokenPrivilege = SeCreateTokenPrivilege;
|
|
|
|
SeExports->SeAssignPrimaryTokenPrivilege = SeAssignPrimaryTokenPrivilege;
|
|
|
|
SeExports->SeLockMemoryPrivilege = SeLockMemoryPrivilege;
|
|
|
|
SeExports->SeIncreaseQuotaPrivilege = SeIncreaseQuotaPrivilege;
|
|
|
|
SeExports->SeUnsolicitedInputPrivilege = SeUnsolicitedInputPrivilege;
|
|
|
|
SeExports->SeTcbPrivilege = SeTcbPrivilege;
|
|
|
|
SeExports->SeSecurityPrivilege = SeSecurityPrivilege;
|
|
|
|
SeExports->SeTakeOwnershipPrivilege = SeTakeOwnershipPrivilege;
|
|
|
|
SeExports->SeLoadDriverPrivilege = SeLoadDriverPrivilege;
|
|
|
|
SeExports->SeCreatePagefilePrivilege = SeCreatePagefilePrivilege;
|
|
|
|
SeExports->SeIncreaseBasePriorityPrivilege = SeIncreaseBasePriorityPrivilege;
|
|
|
|
SeExports->SeSystemProfilePrivilege = SeSystemProfilePrivilege;
|
|
|
|
SeExports->SeSystemtimePrivilege = SeSystemtimePrivilege;
|
|
|
|
SeExports->SeProfileSingleProcessPrivilege = SeProfileSingleProcessPrivilege;
|
|
|
|
SeExports->SeCreatePermanentPrivilege = SeCreatePermanentPrivilege;
|
|
|
|
SeExports->SeBackupPrivilege = SeBackupPrivilege;
|
|
|
|
SeExports->SeRestorePrivilege = SeRestorePrivilege;
|
|
|
|
SeExports->SeShutdownPrivilege = SeShutdownPrivilege;
|
|
|
|
SeExports->SeDebugPrivilege = SeDebugPrivilege;
|
|
|
|
SeExports->SeAuditPrivilege = SeAuditPrivilege;
|
|
|
|
SeExports->SeSystemEnvironmentPrivilege = SeSystemEnvironmentPrivilege;
|
|
|
|
SeExports->SeChangeNotifyPrivilege = SeChangeNotifyPrivilege;
|
|
|
|
SeExports->SeRemoteShutdownPrivilege = SeRemoteShutdownPrivilege;
|
|
|
|
|
|
|
|
SeExports->SeNullSid = SeNullSid;
|
|
|
|
SeExports->SeWorldSid = SeWorldSid;
|
|
|
|
SeExports->SeLocalSid = SeLocalSid;
|
|
|
|
SeExports->SeCreatorOwnerSid = SeCreatorOwnerSid;
|
|
|
|
SeExports->SeCreatorGroupSid = SeCreatorGroupSid;
|
|
|
|
SeExports->SeNtAuthoritySid = SeNtAuthoritySid;
|
|
|
|
SeExports->SeDialupSid = SeDialupSid;
|
|
|
|
SeExports->SeNetworkSid = SeNetworkSid;
|
|
|
|
SeExports->SeBatchSid = SeBatchSid;
|
|
|
|
SeExports->SeInteractiveSid = SeInteractiveSid;
|
|
|
|
SeExports->SeLocalSystemSid = SeLocalSystemSid;
|
|
|
|
SeExports->SeAliasAdminsSid = SeAliasAdminsSid;
|
|
|
|
SeExports->SeAliasUsersSid = SeAliasUsersSid;
|
|
|
|
SeExports->SeAliasGuestsSid = SeAliasGuestsSid;
|
|
|
|
SeExports->SeAliasPowerUsersSid = SeAliasPowerUsersSid;
|
|
|
|
SeExports->SeAliasAccountOpsSid = SeAliasAccountOpsSid;
|
|
|
|
SeExports->SeAliasSystemOpsSid = SeAliasSystemOpsSid;
|
|
|
|
SeExports->SeAliasPrintOpsSid = SeAliasPrintOpsSid;
|
|
|
|
SeExports->SeAliasBackupOpsSid = SeAliasBackupOpsSid;
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2000-01-05 21:57:00 +00:00
|
|
|
VOID SepReferenceLogonSession(PLUID AuthenticationId)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID SepDeReferenceLogonSession(PLUID AuthenticationId)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1998-10-05 04:01:30 +00:00
|
|
|
|
1999-06-18 22:11:21 +00:00
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2002-02-20 20:16:49 +00:00
|
|
|
NTSTATUS STDCALL
|
2002-09-08 10:23:54 +00:00
|
|
|
NtAllocateUuids(PULARGE_INTEGER Time,
|
|
|
|
PULONG Range,
|
|
|
|
PULONG Sequence)
|
1998-10-05 04:01:30 +00:00
|
|
|
{
|
2002-02-20 20:16:49 +00:00
|
|
|
UNIMPLEMENTED;
|
2003-12-14 17:44:02 +00:00
|
|
|
return(STATUS_NOT_IMPLEMENTED);
|
1998-10-05 04:01:30 +00:00
|
|
|
}
|
|
|
|
|
1999-06-18 22:11:21 +00:00
|
|
|
|
2002-02-20 20:16:49 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
NtAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
|
|
|
|
IN HANDLE ClientToken,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
IN PGENERIC_MAPPING GenericMapping,
|
|
|
|
OUT PPRIVILEGE_SET PrivilegeSet,
|
|
|
|
OUT PULONG ReturnLength,
|
|
|
|
OUT PULONG GrantedAccess,
|
|
|
|
OUT PBOOLEAN AccessStatus)
|
1998-10-05 04:01:30 +00:00
|
|
|
{
|
2002-02-20 20:16:49 +00:00
|
|
|
UNIMPLEMENTED;
|
2003-12-14 17:44:02 +00:00
|
|
|
return(STATUS_NOT_IMPLEMENTED);
|
1998-10-05 04:01:30 +00:00
|
|
|
}
|
|
|
|
|
1999-05-31 18:53:33 +00:00
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-03-14 18:13:19 +00:00
|
|
|
VOID STDCALL
|
|
|
|
SeReleaseSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2004-03-14 18:13:19 +00:00
|
|
|
ObDereferenceObject (SubjectContext->PrimaryToken);
|
|
|
|
if (SubjectContext->ClientToken != NULL)
|
|
|
|
{
|
|
|
|
ObDereferenceObject (SubjectContext->ClientToken);
|
|
|
|
}
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 18:13:19 +00:00
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-03-14 18:13:19 +00:00
|
|
|
VOID STDCALL
|
|
|
|
SeCaptureSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2004-03-14 18:13:19 +00:00
|
|
|
PEPROCESS Process;
|
|
|
|
BOOLEAN CopyOnOpen;
|
|
|
|
BOOLEAN EffectiveOnly;
|
|
|
|
|
|
|
|
Process = PsGetCurrentThread ()->ThreadsProcess;
|
|
|
|
|
|
|
|
SubjectContext->ProcessAuditId = Process;
|
|
|
|
SubjectContext->ClientToken =
|
|
|
|
PsReferenceImpersonationToken (PsGetCurrentThread(),
|
|
|
|
&CopyOnOpen,
|
|
|
|
&EffectiveOnly,
|
1999-12-26 15:50:53 +00:00
|
|
|
&SubjectContext->ImpersonationLevel);
|
2004-03-14 18:13:19 +00:00
|
|
|
SubjectContext->PrimaryToken = PsReferencePrimaryToken (Process);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
2002-02-20 20:16:49 +00:00
|
|
|
|
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2002-02-20 20:16:49 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
SeDeassignSecurity(PSECURITY_DESCRIPTOR* SecurityDescriptor)
|
2000-01-26 10:07:30 +00:00
|
|
|
{
|
2002-02-20 20:16:49 +00:00
|
|
|
if ((*SecurityDescriptor) != NULL)
|
|
|
|
{
|
|
|
|
ExFreePool(*SecurityDescriptor);
|
|
|
|
(*SecurityDescriptor) = NULL;
|
|
|
|
}
|
|
|
|
return(STATUS_SUCCESS);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
2000-01-26 10:07:30 +00:00
|
|
|
|
2002-02-20 20:16:49 +00:00
|
|
|
|
2000-01-26 10:07:30 +00:00
|
|
|
#if 0
|
|
|
|
VOID SepGetDefaultsSubjectContext(PSECURITY_SUBJECT_CONTEXT SubjectContext,
|
|
|
|
PSID* Owner,
|
|
|
|
PSID* PrimaryGroup,
|
|
|
|
PSID* ProcessOwner,
|
|
|
|
PSID* ProcessPrimaryGroup,
|
|
|
|
PACL* DefaultDacl)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
PACCESS_TOKEN Token;
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2000-01-26 10:07:30 +00:00
|
|
|
if (SubjectContext->ClientToken != NULL)
|
1999-12-26 15:50:53 +00:00
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
Token = SubjectContext->ClientToken;
|
1999-12-26 15:50:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
Token = SubjectContext->PrimaryToken;
|
1999-12-26 15:50:53 +00:00
|
|
|
}
|
2000-01-26 10:07:30 +00:00
|
|
|
*Owner = Token->UserAndGroups[Token->DefaultOwnerIndex].Sid;
|
|
|
|
*PrimaryGroup = Token->PrimaryGroup;
|
|
|
|
*DefaultDacl = Token->DefaultDacl;
|
|
|
|
*ProcessOwner = SubjectContext->PrimaryToken->
|
|
|
|
UserAndGroups[Token->DefaultOwnerIndex].Sid;
|
|
|
|
*ProcessPrimaryGroup = SubjectContext->PrimaryToken->PrimaryGroup;
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 10:07:30 +00:00
|
|
|
NTSTATUS SepInheritAcl(PACL Acl,
|
|
|
|
BOOLEAN IsDirectoryObject,
|
|
|
|
PSID Owner,
|
|
|
|
PSID PrimaryGroup,
|
|
|
|
PACL DefaultAcl,
|
|
|
|
PSID ProcessOwner,
|
|
|
|
PSID ProcessGroup,
|
|
|
|
PGENERIC_MAPPING GenericMapping)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
if (Acl == NULL)
|
1999-12-26 15:50:53 +00:00
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
return(STATUS_UNSUCCESSFUL);
|
1999-12-26 15:50:53 +00:00
|
|
|
}
|
2000-01-26 10:07:30 +00:00
|
|
|
if (Acl->AclRevision != 2 &&
|
|
|
|
Acl->AclRevision != 3 )
|
|
|
|
{
|
|
|
|
return(STATUS_UNSUCCESSFUL);
|
|
|
|
}
|
|
|
|
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
2000-01-26 10:07:30 +00:00
|
|
|
#endif
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2002-02-20 20:16:49 +00:00
|
|
|
NTSTATUS STDCALL
|
|
|
|
SeAssignSecurity(PSECURITY_DESCRIPTOR ParentDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR ExplicitDescriptor,
|
|
|
|
PSECURITY_DESCRIPTOR* NewDescriptor,
|
|
|
|
BOOLEAN IsDirectoryObject,
|
|
|
|
PSECURITY_SUBJECT_CONTEXT SubjectContext,
|
|
|
|
PGENERIC_MAPPING GenericMapping,
|
|
|
|
POOL_TYPE PoolType)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2000-01-26 10:07:30 +00:00
|
|
|
#if 0
|
|
|
|
PSECURITY_DESCRIPTOR Descriptor;
|
|
|
|
PSID Owner;
|
|
|
|
PSID PrimaryGroup;
|
|
|
|
PACL DefaultDacl;
|
|
|
|
PSID ProcessOwner;
|
|
|
|
PSID ProcessPrimaryGroup;
|
|
|
|
PACL Sacl;
|
|
|
|
|
|
|
|
if (ExplicitDescriptor == NULL)
|
|
|
|
{
|
|
|
|
RtlCreateSecurityDescriptor(&Descriptor, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor = ExplicitDescriptor;
|
|
|
|
}
|
|
|
|
SeLockSubjectContext(SubjectContext);
|
|
|
|
SepGetDefaultsSubjectContext(SubjectContext,
|
|
|
|
&Owner,
|
|
|
|
&PrimaryGroup,
|
|
|
|
&DefaultDacl,
|
|
|
|
&ProcessOwner,
|
|
|
|
&ProcessPrimaryGroup);
|
|
|
|
if (Descriptor->Control & SE_SACL_PRESENT ||
|
|
|
|
Descriptor->Control & SE_SACL_DEFAULTED)
|
|
|
|
{
|
|
|
|
if (ParentDescriptor == NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if (Descriptor->Control & SE_SACL_PRESENT ||
|
|
|
|
Descriptor->Sacl == NULL ||)
|
|
|
|
{
|
|
|
|
Sacl = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sacl = Descriptor->Sacl;
|
|
|
|
if (Descriptor->Control & SE_SELF_RELATIVE)
|
|
|
|
{
|
|
|
|
Sacl = (PACL)(((PVOID)Sacl) + (PVOID)Descriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SepInheritAcl(Sacl,
|
|
|
|
IsDirectoryObject,
|
|
|
|
Owner,
|
|
|
|
PrimaryGroup,
|
|
|
|
DefaultDacl,
|
|
|
|
ProcessOwner,
|
|
|
|
GenericMapping);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
UNIMPLEMENTED;
|
2003-12-14 17:44:02 +00:00
|
|
|
return(STATUS_NOT_IMPLEMENTED);
|
2000-01-26 10:07:30 +00:00
|
|
|
#endif
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
BOOLEAN SepSidInToken(PACCESS_TOKEN Token,
|
2000-01-05 21:57:00 +00:00
|
|
|
PSID Sid)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
if (Token->UserAndGroupCount == 0)
|
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<Token->UserAndGroupCount; i++)
|
|
|
|
{
|
2002-09-08 10:23:54 +00:00
|
|
|
if (RtlEqualSid(Sid, Token->UserAndGroups[i].Sid))
|
2000-01-05 21:57:00 +00:00
|
|
|
{
|
|
|
|
if (i == 0 ||
|
2002-09-08 10:23:54 +00:00
|
|
|
(!(Token->UserAndGroups[i].Attributes & SE_GROUP_ENABLED)))
|
2000-01-05 21:57:00 +00:00
|
|
|
{
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2002-02-20 20:16:49 +00:00
|
|
|
|
2003-07-11 01:23:16 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2002-02-20 20:16:49 +00:00
|
|
|
BOOLEAN STDCALL
|
|
|
|
SeAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
|
|
|
|
IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
|
|
|
|
IN BOOLEAN SubjectContextLocked,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
IN ACCESS_MASK PreviouslyGrantedAccess,
|
|
|
|
OUT PPRIVILEGE_SET* Privileges,
|
|
|
|
IN PGENERIC_MAPPING GenericMapping,
|
|
|
|
IN KPROCESSOR_MODE AccessMode,
|
|
|
|
OUT PACCESS_MODE GrantedAccess,
|
|
|
|
OUT PNTSTATUS AccessStatus)
|
1998-08-25 04:27:26 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Determines whether the requested access rights can be granted
|
|
|
|
* to an object protected by a security descriptor and an object owner
|
|
|
|
* ARGUMENTS:
|
1999-12-26 15:50:53 +00:00
|
|
|
* SecurityDescriptor = Security descriptor protecting the object
|
1998-08-25 04:27:26 +00:00
|
|
|
* SubjectSecurityContext = Subject's captured security context
|
|
|
|
* SubjectContextLocked = Indicates the user's subject context is locked
|
|
|
|
* DesiredAccess = Access rights the caller is trying to acquire
|
|
|
|
* PreviouslyGrantedAccess = Specified the access rights already granted
|
1999-12-26 15:50:53 +00:00
|
|
|
* Privileges = ?
|
1998-08-25 04:27:26 +00:00
|
|
|
* GenericMapping = Generic mapping associated with the object
|
|
|
|
* AccessMode = Access mode used for the check
|
|
|
|
* GrantedAccess (OUT) = On return specifies the access granted
|
|
|
|
* AccessStatus (OUT) = Status indicating why access was denied
|
|
|
|
* RETURNS: If access was granted, returns TRUE
|
|
|
|
*/
|
|
|
|
{
|
1999-12-26 15:50:53 +00:00
|
|
|
ULONG i;
|
|
|
|
PACL Dacl;
|
|
|
|
BOOLEAN Present;
|
|
|
|
BOOLEAN Defaulted;
|
|
|
|
NTSTATUS Status;
|
2002-09-08 10:23:54 +00:00
|
|
|
PACE CurrentAce;
|
1999-12-26 15:50:53 +00:00
|
|
|
PSID Sid;
|
|
|
|
ACCESS_MASK CurrentAccess;
|
|
|
|
|
|
|
|
CurrentAccess = PreviouslyGrantedAccess;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore the SACL for now
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the DACL
|
|
|
|
*/
|
|
|
|
Status = RtlGetDaclSecurityDescriptor(SecurityDescriptor,
|
|
|
|
&Present,
|
|
|
|
&Dacl,
|
|
|
|
&Defaulted);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
CurrentAce = (PACE)(Dacl + 1);
|
1999-12-26 15:50:53 +00:00
|
|
|
for (i = 0; i < Dacl->AceCount; i++)
|
|
|
|
{
|
|
|
|
Sid = (PSID)(CurrentAce + 1);
|
|
|
|
if (CurrentAce->Header.AceType == ACCESS_DENIED_ACE_TYPE)
|
|
|
|
{
|
2000-01-05 21:57:00 +00:00
|
|
|
if (SepSidInToken(SubjectSecurityContext->ClientToken, Sid))
|
1999-12-26 15:50:53 +00:00
|
|
|
{
|
|
|
|
*AccessStatus = STATUS_ACCESS_DENIED;
|
|
|
|
*GrantedAccess = 0;
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CurrentAce->Header.AceType == ACCESS_ALLOWED_ACE_TYPE)
|
|
|
|
{
|
2000-01-05 21:57:00 +00:00
|
|
|
if (SepSidInToken(SubjectSecurityContext->ClientToken, Sid))
|
1999-12-26 15:50:53 +00:00
|
|
|
{
|
|
|
|
CurrentAccess = CurrentAccess |
|
2002-10-25 21:48:00 +00:00
|
|
|
CurrentAce->AccessMask;
|
1999-12-26 15:50:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(CurrentAccess & DesiredAccess) &&
|
|
|
|
!((~CurrentAccess) & DesiredAccess))
|
|
|
|
{
|
|
|
|
*AccessStatus = STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*AccessStatus = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
*GrantedAccess = CurrentAccess;
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-26 17:22:19 +00:00
|
|
|
/* EOF */
|