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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -58,7 +58,7 @@ PsAssignImpersonationToken(PETHREAD Thread,
PACCESS_TOKEN Token; PACCESS_TOKEN Token;
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
NTSTATUS Status; NTSTATUS Status;
if (TokenHandle != NULL) if (TokenHandle != NULL)
{ {
Status = ObReferenceObjectByHandle(TokenHandle, Status = ObReferenceObjectByHandle(TokenHandle,
@ -78,7 +78,7 @@ PsAssignImpersonationToken(PETHREAD Thread,
Token = NULL; Token = NULL;
ImpersonationLevel = 0; ImpersonationLevel = 0;
} }
PsImpersonateClient(Thread, PsImpersonateClient(Thread,
Token, Token,
0, 0,
@ -183,51 +183,56 @@ NtImpersonateThread(IN HANDLE ThreadHandle,
IN HANDLE ThreadToImpersonateHandle, IN HANDLE ThreadToImpersonateHandle,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService) IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService)
{ {
PETHREAD Thread; SECURITY_CLIENT_CONTEXT ClientContext;
PETHREAD ThreadToImpersonate; PETHREAD Thread;
NTSTATUS Status; PETHREAD ThreadToImpersonate;
SECURITY_CLIENT_CONTEXT ClientContext; NTSTATUS Status;
Status = ObReferenceObjectByHandle(ThreadHandle, Status = ObReferenceObjectByHandle (ThreadHandle,
0, 0,
PsThreadType, PsThreadType,
UserMode, UserMode,
(PVOID*)&Thread, (PVOID*)&Thread,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS (Status))
{ {
return(Status); return Status;
} }
Status = ObReferenceObjectByHandle(ThreadToImpersonateHandle, Status = ObReferenceObjectByHandle (ThreadToImpersonateHandle,
0, 0,
PsThreadType, PsThreadType,
UserMode, UserMode,
(PVOID*)&ThreadToImpersonate, (PVOID*)&ThreadToImpersonate,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ObDereferenceObject(Thread); ObDereferenceObject (Thread);
return(Status); return Status;
} }
Status = SeCreateClientSecurity(ThreadToImpersonate, Status = SeCreateClientSecurity (ThreadToImpersonate,
SecurityQualityOfService, SecurityQualityOfService,
0, 0,
&ClientContext); &ClientContext);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ObDereferenceObject(Thread); ObDereferenceObject (ThreadToImpersonate);
ObDereferenceObject(ThreadToImpersonate); ObDereferenceObject (Thread);
return(Status); return Status;
} }
SeImpersonateClient(&ClientContext, Thread); SeImpersonateClient (&ClientContext,
if (ClientContext.Token != NULL) Thread);
{ if (ClientContext.Token != NULL)
ObDereferenceObject(ClientContext.Token); {
} ObDereferenceObject (ClientContext.Token);
return(STATUS_SUCCESS); }
ObDereferenceObject (ThreadToImpersonate);
ObDereferenceObject (Thread);
return STATUS_SUCCESS;
} }
@ -237,12 +242,11 @@ NtOpenThreadToken (IN HANDLE ThreadHandle,
IN BOOLEAN OpenAsSelf, IN BOOLEAN OpenAsSelf,
OUT PHANDLE TokenHandle) OUT PHANDLE TokenHandle)
{ {
#if 0 PACCESS_TOKEN Token;
PETHREAD Thread; PETHREAD Thread;
NTSTATUS Status; NTSTATUS Status;
PACCESS_TOKEN Token;
Status = ObReferenceObjectByHandle (ThreadHandle,
Status = ObReferenceObjectByHandle(ThreadHandle,
0, 0,
PsThreadType, PsThreadType,
UserMode, UserMode,
@ -252,11 +256,37 @@ NtOpenThreadToken (IN HANDLE ThreadHandle,
{ {
return(Status); return(Status);
} }
Token = PsReferencePrimaryToken(Thread->ThreadsProcess); if (OpenAsSelf)
SepCreateImpersonationTokenDacl(Token); {
#endif if (Thread->ActiveImpersonationInfo == FALSE)
return STATUS_NO_TOKEN; {
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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -22,28 +22,28 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS STDCALL NTSTATUS STDCALL
NtSetInformationThread(HANDLE ThreadHandle, NtSetInformationThread (IN HANDLE ThreadHandle,
THREADINFOCLASS ThreadInformationClass, IN THREADINFOCLASS ThreadInformationClass,
PVOID ThreadInformation, IN PVOID ThreadInformation,
ULONG ThreadInformationLength) IN ULONG ThreadInformationLength)
{ {
PETHREAD Thread; PETHREAD Thread;
NTSTATUS Status; NTSTATUS Status;
Status = ObReferenceObjectByHandle(ThreadHandle, Status = ObReferenceObjectByHandle (ThreadHandle,
THREAD_SET_INFORMATION, THREAD_SET_INFORMATION,
PsThreadType, PsThreadType,
ExGetPreviousMode(), ExGetPreviousMode (),
(PVOID*)&Thread, (PVOID*)&Thread,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return Status;
} }
switch (ThreadInformationClass) switch (ThreadInformationClass)
{ {
case ThreadBasicInformation: case ThreadBasicInformation:
/* Can only be queried */ /* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS; Status = STATUS_INVALID_INFO_CLASS;
@ -57,7 +57,7 @@ NtSetInformationThread(HANDLE ThreadHandle,
case ThreadPriority: case ThreadPriority:
{ {
KPRIORITY Priority; KPRIORITY Priority;
if (ThreadInformationLength != sizeof(KPRIORITY)) if (ThreadInformationLength != sizeof(KPRIORITY))
{ {
Status = STATUS_INFO_LENGTH_MISMATCH; Status = STATUS_INFO_LENGTH_MISMATCH;
@ -77,17 +77,18 @@ NtSetInformationThread(HANDLE ThreadHandle,
case ThreadBasePriority: case ThreadBasePriority:
{ {
LONG Increment; LONG Increment;
if (ThreadInformationLength != sizeof(LONG)) if (ThreadInformationLength != sizeof(LONG))
{ {
Status = STATUS_INFO_LENGTH_MISMATCH; Status = STATUS_INFO_LENGTH_MISMATCH;
break; break;
} }
Status = MmCopyFromCaller(&Increment, Status = MmCopyFromCaller(&Increment,
ThreadInformation, ThreadInformation,
sizeof(ULONG)); sizeof(ULONG));
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
KeSetBasePriorityThread (&Thread->Tcb, Increment); KeSetBasePriorityThread (&Thread->Tcb, Increment);
} }
} }
break; break;
@ -106,7 +107,8 @@ NtSetInformationThread(HANDLE ThreadHandle,
break; break;
} }
TokenHandle = *((PHANDLE)ThreadInformation); TokenHandle = *((PHANDLE)ThreadInformation);
Status = PsAssignImpersonationToken(Thread, TokenHandle); Status = PsAssignImpersonationToken (Thread,
TokenHandle);
break; break;
} }
@ -158,49 +160,51 @@ NtSetInformationThread(HANDLE ThreadHandle,
Thread->u2.Win32StartAddress = (PVOID)*((PULONG)ThreadInformation); Thread->u2.Win32StartAddress = (PVOID)*((PULONG)ThreadInformation);
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
break; break;
case ThreadZeroTlsCell: case ThreadZeroTlsCell:
{ {
Status = STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
break; break;
} }
case ThreadPerformanceCount: case ThreadPerformanceCount:
/* Can only be queried */ /* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS; Status = STATUS_INVALID_INFO_CLASS;
break; break;
case ThreadAmILastThread: case ThreadAmILastThread:
/* Can only be queried */ /* Can only be queried */
Status = STATUS_INVALID_INFO_CLASS; Status = STATUS_INVALID_INFO_CLASS;
break; break;
case ThreadIdealProcessor:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadPriorityBoost:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadSetTlsArrayAddress:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ThreadIsIoPending: case ThreadIdealProcessor:
/* Can only be queried */ Status = STATUS_NOT_IMPLEMENTED;
Status = STATUS_INVALID_INFO_CLASS; break;
break;
case ThreadHideFromDebugger: case ThreadPriorityBoost:
Status = STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
break; 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: default:
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
} }
ObDereferenceObject(Thread);
return Status; ObDereferenceObject (Thread);
return Status;
} }
@ -364,27 +368,31 @@ NtQueryInformationThread (IN HANDLE ThreadHandle,
return(Status); return(Status);
} }
VOID KeSetPreviousMode(ULONG Mode)
VOID
KeSetPreviousMode (ULONG Mode)
{ {
PsGetCurrentThread()->Tcb.PreviousMode = (UCHAR)Mode; PsGetCurrentThread()->Tcb.PreviousMode = (UCHAR)Mode;
} }
/* /*
* @implemented * @implemented
*/ */
ULONG STDCALL ULONG STDCALL
KeGetPreviousMode (VOID) KeGetPreviousMode (VOID)
{ {
return (ULONG)PsGetCurrentThread()->Tcb.PreviousMode; return (ULONG)PsGetCurrentThread()->Tcb.PreviousMode;
} }
/* /*
* @implemented * @implemented
*/ */
KPROCESSOR_MODE STDCALL KPROCESSOR_MODE STDCALL
ExGetPreviousMode (VOID) ExGetPreviousMode (VOID)
{ {
return (KPROCESSOR_MODE)PsGetCurrentThread()->Tcb.PreviousMode; return (KPROCESSOR_MODE)PsGetCurrentThread()->Tcb.PreviousMode;
} }
/* EOF */ /* EOF */