SeCaptureSubjectContext() must not crash if no current thread exists.

svn path=/trunk/; revision=10226
This commit is contained in:
Eric Kohl 2004-07-19 12:45:56 +00:00
parent 06272913f0
commit ae95148c4b

View file

@ -1,4 +1,4 @@
/* $Id: semgr.c,v 1.34 2004/07/18 13:02:28 ekohl Exp $ /* $Id: semgr.c,v 1.35 2004/07/19 12:45:56 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -208,19 +208,28 @@ NtAllocateUuids(PULARGE_INTEGER Time,
VOID STDCALL VOID STDCALL
SeCaptureSubjectContext(OUT PSECURITY_SUBJECT_CONTEXT SubjectContext) SeCaptureSubjectContext(OUT PSECURITY_SUBJECT_CONTEXT SubjectContext)
{ {
PEPROCESS Process; PETHREAD Thread;
BOOLEAN CopyOnOpen; BOOLEAN CopyOnOpen;
BOOLEAN EffectiveOnly; BOOLEAN EffectiveOnly;
Process = PsGetCurrentThread ()->ThreadsProcess; Thread = PsGetCurrentThread();
if (Thread == NULL)
SubjectContext->ProcessAuditId = Process; {
SubjectContext->ClientToken = SubjectContext->ProcessAuditId = 0;
PsReferenceImpersonationToken (PsGetCurrentThread(), SubjectContext->PrimaryToken = NULL;
&CopyOnOpen, SubjectContext->ClientToken = NULL;
&EffectiveOnly, SubjectContext->ImpersonationLevel = 0;
&SubjectContext->ImpersonationLevel); }
SubjectContext->PrimaryToken = PsReferencePrimaryToken (Process); else
{
SubjectContext->ProcessAuditId = Thread->ThreadsProcess;
SubjectContext->ClientToken =
PsReferenceImpersonationToken(Thread,
&CopyOnOpen,
&EffectiveOnly,
&SubjectContext->ImpersonationLevel);
SubjectContext->PrimaryToken = PsReferencePrimaryToken(Thread->ThreadsProcess);
}
} }
@ -240,10 +249,14 @@ SeLockSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
VOID STDCALL VOID STDCALL
SeReleaseSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext) SeReleaseSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
{ {
ObDereferenceObject (SubjectContext->PrimaryToken); if (SubjectContext->PrimaryToken != NULL)
{
ObDereferenceObject(SubjectContext->PrimaryToken);
}
if (SubjectContext->ClientToken != NULL) if (SubjectContext->ClientToken != NULL)
{ {
ObDereferenceObject (SubjectContext->ClientToken); ObDereferenceObject(SubjectContext->ClientToken);
} }
} }
@ -262,14 +275,15 @@ SeUnlockSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
* @implemented * @implemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
SeDeassignSecurity(PSECURITY_DESCRIPTOR* SecurityDescriptor) SeDeassignSecurity(PSECURITY_DESCRIPTOR *SecurityDescriptor)
{ {
if ((*SecurityDescriptor) != NULL) if (*SecurityDescriptor != NULL)
{ {
ExFreePool(*SecurityDescriptor); ExFreePool(*SecurityDescriptor);
(*SecurityDescriptor) = NULL; *SecurityDescriptor = NULL;
} }
return(STATUS_SUCCESS);
return STATUS_SUCCESS;
} }