Fix NtOpenThreadToken() and NtSetInformationThread().

svn path=/trunk/; revision=8791
This commit is contained in:
Eric Kohl 2004-03-19 12:45:07 +00:00
parent d037d068ff
commit c89688b59d
2 changed files with 134 additions and 96 deletions

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.71 2004/03/14 18:12:07 ekohl Exp $
/* $Id: create.c,v 1.72 2004/03/19 12:45:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -58,7 +58,7 @@ PsAssignImpersonationToken(PETHREAD Thread,
PACCESS_TOKEN Token;
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
NTSTATUS Status;
if (TokenHandle != NULL)
{
Status = ObReferenceObjectByHandle(TokenHandle,
@ -78,7 +78,7 @@ PsAssignImpersonationToken(PETHREAD Thread,
Token = NULL;
ImpersonationLevel = 0;
}
PsImpersonateClient(Thread,
Token,
0,
@ -183,51 +183,56 @@ NtImpersonateThread(IN HANDLE ThreadHandle,
IN HANDLE ThreadToImpersonateHandle,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService)
{
PETHREAD Thread;
PETHREAD ThreadToImpersonate;
NTSTATUS Status;
SECURITY_CLIENT_CONTEXT ClientContext;
Status = ObReferenceObjectByHandle(ThreadHandle,
SECURITY_CLIENT_CONTEXT ClientContext;
PETHREAD Thread;
PETHREAD ThreadToImpersonate;
NTSTATUS Status;
Status = ObReferenceObjectByHandle (ThreadHandle,
0,
PsThreadType,
UserMode,
(PVOID*)&Thread,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = ObReferenceObjectByHandle(ThreadToImpersonateHandle,
if (!NT_SUCCESS (Status))
{
return Status;
}
Status = ObReferenceObjectByHandle (ThreadToImpersonateHandle,
0,
PsThreadType,
UserMode,
(PVOID*)&ThreadToImpersonate,
NULL);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Thread);
return(Status);
}
Status = SeCreateClientSecurity(ThreadToImpersonate,
if (!NT_SUCCESS(Status))
{
ObDereferenceObject (Thread);
return Status;
}
Status = SeCreateClientSecurity (ThreadToImpersonate,
SecurityQualityOfService,
0,
&ClientContext);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Thread);
ObDereferenceObject(ThreadToImpersonate);
return(Status);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject (ThreadToImpersonate);
ObDereferenceObject (Thread);
return Status;
}
SeImpersonateClient(&ClientContext, Thread);
if (ClientContext.Token != NULL)
{
ObDereferenceObject(ClientContext.Token);
}
return(STATUS_SUCCESS);
SeImpersonateClient (&ClientContext,
Thread);
if (ClientContext.Token != NULL)
{
ObDereferenceObject (ClientContext.Token);
}
ObDereferenceObject (ThreadToImpersonate);
ObDereferenceObject (Thread);
return STATUS_SUCCESS;
}
@ -237,12 +242,11 @@ NtOpenThreadToken (IN HANDLE ThreadHandle,
IN BOOLEAN OpenAsSelf,
OUT PHANDLE TokenHandle)
{
#if 0
PETHREAD Thread;
NTSTATUS Status;
PACCESS_TOKEN Token;
Status = ObReferenceObjectByHandle(ThreadHandle,
PACCESS_TOKEN Token;
PETHREAD Thread;
NTSTATUS Status;
Status = ObReferenceObjectByHandle (ThreadHandle,
0,
PsThreadType,
UserMode,
@ -252,11 +256,37 @@ NtOpenThreadToken (IN HANDLE ThreadHandle,
{
return(Status);
}
Token = PsReferencePrimaryToken(Thread->ThreadsProcess);
SepCreateImpersonationTokenDacl(Token);
#endif
return STATUS_NO_TOKEN;
if (OpenAsSelf)
{
if (Thread->ActiveImpersonationInfo == FALSE)
{
ObDereferenceObject (Thread);
return STATUS_NO_TOKEN;
}
Token = Thread->ImpersonationInfo->Token;
}
else
{
Token = Thread->ThreadsProcess->Token;
}
if (Token == NULL)
{
ObDereferenceObject (Thread);
return STATUS_NO_TOKEN;
}
Status = ObCreateHandle (PsGetCurrentProcess(),
Token,
DesiredAccess,
FALSE,
TokenHandle);
ObDereferenceObject (Thread);
return Status;
}

View file

@ -1,4 +1,4 @@
/* $Id: tinfo.c,v 1.24 2003/12/30 18:52:05 fireball Exp $
/* $Id: tinfo.c,v 1.25 2004/03/19 12:45:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -22,28 +22,28 @@
/* FUNCTIONS *****************************************************************/
NTSTATUS STDCALL
NtSetInformationThread(HANDLE ThreadHandle,
THREADINFOCLASS ThreadInformationClass,
PVOID ThreadInformation,
ULONG ThreadInformationLength)
NTSTATUS STDCALL
NtSetInformationThread (IN HANDLE ThreadHandle,
IN THREADINFOCLASS ThreadInformationClass,
IN PVOID ThreadInformation,
IN ULONG ThreadInformationLength)
{
PETHREAD Thread;
NTSTATUS Status;
Status = ObReferenceObjectByHandle(ThreadHandle,
PETHREAD Thread;
NTSTATUS Status;
Status = ObReferenceObjectByHandle (ThreadHandle,
THREAD_SET_INFORMATION,
PsThreadType,
ExGetPreviousMode(),
ExGetPreviousMode (),
(PVOID*)&Thread,
NULL);
if (!NT_SUCCESS(Status))
{
return Status;
}
switch (ThreadInformationClass)
{
switch (ThreadInformationClass)
{
case ThreadBasicInformation:
/* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS;
@ -57,7 +57,7 @@ NtSetInformationThread(HANDLE ThreadHandle,
case ThreadPriority:
{
KPRIORITY Priority;
if (ThreadInformationLength != sizeof(KPRIORITY))
{
Status = STATUS_INFO_LENGTH_MISMATCH;
@ -77,17 +77,18 @@ NtSetInformationThread(HANDLE ThreadHandle,
case ThreadBasePriority:
{
LONG Increment;
if (ThreadInformationLength != sizeof(LONG))
{
Status = STATUS_INFO_LENGTH_MISMATCH;
break;
}
Status = MmCopyFromCaller(&Increment,
ThreadInformation,
sizeof(ULONG));
if (NT_SUCCESS(Status))
{
KeSetBasePriorityThread (&Thread->Tcb, Increment);
Status = MmCopyFromCaller(&Increment,
ThreadInformation,
sizeof(ULONG));
if (NT_SUCCESS(Status))
{
KeSetBasePriorityThread (&Thread->Tcb, Increment);
}
}
break;
@ -106,7 +107,8 @@ NtSetInformationThread(HANDLE ThreadHandle,
break;
}
TokenHandle = *((PHANDLE)ThreadInformation);
Status = PsAssignImpersonationToken(Thread, TokenHandle);
Status = PsAssignImpersonationToken (Thread,
TokenHandle);
break;
}
@ -158,49 +160,51 @@ NtSetInformationThread(HANDLE ThreadHandle,
Thread->u2.Win32StartAddress = (PVOID)*((PULONG)ThreadInformation);
Status = STATUS_SUCCESS;
break;
case ThreadZeroTlsCell:
{
Status = STATUS_NOT_IMPLEMENTED;
break;
}
case ThreadPerformanceCount:
/* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS;
break;
case ThreadAmILastThread:
/* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS;
break;
case ThreadIdealProcessor:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadPriorityBoost:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadSetTlsArrayAddress:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadIsIoPending:
/* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS;
break;
case ThreadIdealProcessor:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadHideFromDebugger:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadPriorityBoost:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadSetTlsArrayAddress:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadIsIoPending:
/* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS;
break;
case ThreadHideFromDebugger:
Status = STATUS_NOT_IMPLEMENTED;
break;
default:
Status = STATUS_UNSUCCESSFUL;
}
ObDereferenceObject(Thread);
return Status;
}
ObDereferenceObject (Thread);
return Status;
}
@ -364,27 +368,31 @@ NtQueryInformationThread (IN HANDLE ThreadHandle,
return(Status);
}
VOID KeSetPreviousMode(ULONG Mode)
VOID
KeSetPreviousMode (ULONG Mode)
{
PsGetCurrentThread()->Tcb.PreviousMode = (UCHAR)Mode;
PsGetCurrentThread()->Tcb.PreviousMode = (UCHAR)Mode;
}
/*
* @implemented
*/
ULONG STDCALL
KeGetPreviousMode (VOID)
{
return (ULONG)PsGetCurrentThread()->Tcb.PreviousMode;
return (ULONG)PsGetCurrentThread()->Tcb.PreviousMode;
}
/*
* @implemented
*/
KPROCESSOR_MODE STDCALL
ExGetPreviousMode (VOID)
{
return (KPROCESSOR_MODE)PsGetCurrentThread()->Tcb.PreviousMode;
return (KPROCESSOR_MODE)PsGetCurrentThread()->Tcb.PreviousMode;
}
/* EOF */