mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:02:58 +00:00
- Clone ObpCreateHandle to CmpCreateHandle. I am about to fix its implementation and since Cm* currently abuses Ob I feel it safer to give its own internal function.
- Make ObpCreateHandle internal to Ob as it should be. Change NtCreateProcessTokenEx to use ObOpenObjectByPointer, it has no business manually trying to create a handle. Same goes for ExpLoadInitialProcess. svn path=/trunk/; revision=22264
This commit is contained in:
parent
2097dade2d
commit
d2e5bfabe5
4 changed files with 111 additions and 31 deletions
|
@ -30,6 +30,106 @@ FAST_MUTEX CmiCallbackLock;
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
CmpCreateHandle(PVOID ObjectBody,
|
||||||
|
ACCESS_MASK GrantedAccess,
|
||||||
|
ULONG HandleAttributes,
|
||||||
|
PHANDLE HandleReturn)
|
||||||
|
/*
|
||||||
|
* FUNCTION: Add a handle referencing an object
|
||||||
|
* ARGUMENTS:
|
||||||
|
* obj = Object body that the handle should refer to
|
||||||
|
* RETURNS: The created handle
|
||||||
|
* NOTE: The handle is valid only in the context of the current process
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
HANDLE_TABLE_ENTRY NewEntry;
|
||||||
|
PEPROCESS Process, CurrentProcess;
|
||||||
|
POBJECT_HEADER ObjectHeader;
|
||||||
|
HANDLE Handle;
|
||||||
|
KAPC_STATE ApcState;
|
||||||
|
BOOLEAN AttachedToProcess = FALSE;
|
||||||
|
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
DPRINT("CmpCreateHandle(obj %p)\n",ObjectBody);
|
||||||
|
|
||||||
|
ASSERT(ObjectBody);
|
||||||
|
|
||||||
|
CurrentProcess = PsGetCurrentProcess();
|
||||||
|
|
||||||
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
|
||||||
|
|
||||||
|
/* check that this is a valid kernel pointer */
|
||||||
|
ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
|
||||||
|
|
||||||
|
if (GrantedAccess & MAXIMUM_ALLOWED)
|
||||||
|
{
|
||||||
|
GrantedAccess &= ~MAXIMUM_ALLOWED;
|
||||||
|
GrantedAccess |= GENERIC_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GrantedAccess & GENERIC_ACCESS)
|
||||||
|
{
|
||||||
|
RtlMapGenericMask(&GrantedAccess,
|
||||||
|
&ObjectHeader->Type->TypeInfo.GenericMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
NewEntry.Object = ObjectHeader;
|
||||||
|
if(HandleAttributes & OBJ_INHERIT)
|
||||||
|
NewEntry.ObAttributes |= EX_HANDLE_ENTRY_INHERITABLE;
|
||||||
|
else
|
||||||
|
NewEntry.ObAttributes &= ~EX_HANDLE_ENTRY_INHERITABLE;
|
||||||
|
NewEntry.GrantedAccess = GrantedAccess;
|
||||||
|
|
||||||
|
if ((HandleAttributes & OBJ_KERNEL_HANDLE) &&
|
||||||
|
ExGetPreviousMode == KernelMode)
|
||||||
|
{
|
||||||
|
Process = PsInitialSystemProcess;
|
||||||
|
if (Process != CurrentProcess)
|
||||||
|
{
|
||||||
|
KeStackAttachProcess(&Process->Pcb,
|
||||||
|
&ApcState);
|
||||||
|
AttachedToProcess = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Process = CurrentProcess;
|
||||||
|
/* mask out the OBJ_KERNEL_HANDLE attribute */
|
||||||
|
HandleAttributes &= ~OBJ_KERNEL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle = ExCreateHandle(Process->ObjectTable,
|
||||||
|
&NewEntry);
|
||||||
|
|
||||||
|
if (AttachedToProcess)
|
||||||
|
{
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Handle != NULL)
|
||||||
|
{
|
||||||
|
if (HandleAttributes & OBJ_KERNEL_HANDLE)
|
||||||
|
{
|
||||||
|
/* mark the handle value */
|
||||||
|
Handle = ObMarkHandleAsKernelHandle(Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(InterlockedIncrement(&ObjectHeader->HandleCount) == 1)
|
||||||
|
{
|
||||||
|
ObReferenceObject(ObjectBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
*HandleReturn = Handle;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
@ -291,13 +391,13 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ObpCreateHandle(Object,
|
Status = CmpCreateHandle(Object,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
ObjectCreateInfo.Attributes,
|
ObjectCreateInfo.Attributes,
|
||||||
&hKey);
|
&hKey);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
DPRINT1("ObpCreateHandle failed Status 0x%x\n", Status);
|
DPRINT1("CmpCreateHandle failed Status 0x%x\n", Status);
|
||||||
|
|
||||||
PostCreateKeyInfo.Object = NULL;
|
PostCreateKeyInfo.Object = NULL;
|
||||||
PostCreateKeyInfo.Status = Status;
|
PostCreateKeyInfo.Status = Status;
|
||||||
|
@ -1361,7 +1461,7 @@ NtOpenKey(OUT PHANDLE KeyHandle,
|
||||||
goto openkey_cleanup;
|
goto openkey_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ObpCreateHandle(Object,
|
Status = CmpCreateHandle(Object,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
ObjectCreateInfo.Attributes,
|
ObjectCreateInfo.Attributes,
|
||||||
&hKey);
|
&hKey);
|
||||||
|
|
|
@ -426,22 +426,10 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
||||||
{
|
{
|
||||||
UNICODE_STRING CurrentDirectory;
|
UNICODE_STRING CurrentDirectory;
|
||||||
UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
|
UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
|
||||||
HANDLE SystemProcessHandle;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
|
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
|
||||||
RTL_USER_PROCESS_INFORMATION Info;
|
RTL_USER_PROCESS_INFORMATION Info;
|
||||||
|
|
||||||
/* Create a handle to the process */
|
|
||||||
Status = ObpCreateHandle(PsInitialSystemProcess,
|
|
||||||
PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION,
|
|
||||||
OBJ_KERNEL_HANDLE,
|
|
||||||
&SystemProcessHandle);
|
|
||||||
if(!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("Failed to create a handle for the system process!\n");
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlInitUnicodeString(&CurrentDirectory,
|
RtlInitUnicodeString(&CurrentDirectory,
|
||||||
SharedUserData->NtSystemRoot);
|
SharedUserData->NtSystemRoot);
|
||||||
|
|
||||||
|
@ -459,7 +447,6 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
||||||
if(!NT_SUCCESS(Status))
|
if(!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create ppb!\n");
|
DPRINT1("Failed to create ppb!\n");
|
||||||
ZwClose(SystemProcessHandle);
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,14 +456,13 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
||||||
Params,
|
Params,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
SystemProcessHandle,
|
NULL,
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&Info);
|
&Info);
|
||||||
|
|
||||||
/* Close the handle and free the params */
|
/* Close the handle and free the params */
|
||||||
ZwClose(SystemProcessHandle);
|
|
||||||
RtlDestroyProcessParameters(Params);
|
RtlDestroyProcessParameters(Params);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
|
|
@ -70,15 +70,6 @@ ObInitSymbolicLinkImplementation(
|
||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
NTAPI
|
|
||||||
ObpCreateHandle(
|
|
||||||
PVOID ObjectBody,
|
|
||||||
ACCESS_MASK GrantedAccess,
|
|
||||||
ULONG HandleAttributes,
|
|
||||||
PHANDLE Handle
|
|
||||||
);
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
ObpCreateHandleTable(
|
ObpCreateHandleTable(
|
||||||
|
|
|
@ -97,10 +97,13 @@ NtOpenProcessTokenEx(IN HANDLE ProcessHandle,
|
||||||
&Token);
|
&Token);
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
Status = ObpCreateHandle(Token,
|
Status = ObOpenObjectByPointer(Token,
|
||||||
DesiredAccess,
|
0,
|
||||||
HandleAttributes,
|
NULL,
|
||||||
&hToken);
|
DesiredAccess,
|
||||||
|
SepTokenObjectType,
|
||||||
|
PreviousMode,
|
||||||
|
&hToken);
|
||||||
ObDereferenceObject(Token);
|
ObDereferenceObject(Token);
|
||||||
|
|
||||||
if(NT_SUCCESS(Status))
|
if(NT_SUCCESS(Status))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue