mirror of
https://github.com/reactos/reactos.git
synced 2024-06-29 01:12:06 +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
|
@ -30,6 +30,106 @@ FAST_MUTEX CmiCallbackLock;
|
|||
|
||||
/* 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
|
||||
*/
|
||||
|
@ -291,13 +391,13 @@ NtCreateKey(OUT PHANDLE KeyHandle,
|
|||
goto Cleanup;
|
||||
}
|
||||
|
||||
Status = ObpCreateHandle(Object,
|
||||
Status = CmpCreateHandle(Object,
|
||||
DesiredAccess,
|
||||
ObjectCreateInfo.Attributes,
|
||||
&hKey);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
DPRINT1("ObpCreateHandle failed Status 0x%x\n", Status);
|
||||
DPRINT1("CmpCreateHandle failed Status 0x%x\n", Status);
|
||||
|
||||
PostCreateKeyInfo.Object = NULL;
|
||||
PostCreateKeyInfo.Status = Status;
|
||||
|
@ -1361,7 +1461,7 @@ NtOpenKey(OUT PHANDLE KeyHandle,
|
|||
goto openkey_cleanup;
|
||||
}
|
||||
|
||||
Status = ObpCreateHandle(Object,
|
||||
Status = CmpCreateHandle(Object,
|
||||
DesiredAccess,
|
||||
ObjectCreateInfo.Attributes,
|
||||
&hKey);
|
||||
|
|
|
@ -426,22 +426,10 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
|||
{
|
||||
UNICODE_STRING CurrentDirectory;
|
||||
UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
|
||||
HANDLE SystemProcessHandle;
|
||||
NTSTATUS Status;
|
||||
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
|
||||
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,
|
||||
SharedUserData->NtSystemRoot);
|
||||
|
||||
|
@ -459,7 +447,6 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
|||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to create ppb!\n");
|
||||
ZwClose(SystemProcessHandle);
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -469,14 +456,13 @@ ExpLoadInitialProcess(PHANDLE ProcessHandle,
|
|||
Params,
|
||||
NULL,
|
||||
NULL,
|
||||
SystemProcessHandle,
|
||||
NULL,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL,
|
||||
&Info);
|
||||
|
||||
/* Close the handle and free the params */
|
||||
ZwClose(SystemProcessHandle);
|
||||
RtlDestroyProcessParameters(Params);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
|
|
|
@ -70,15 +70,6 @@ ObInitSymbolicLinkImplementation(
|
|||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
ObpCreateHandle(
|
||||
PVOID ObjectBody,
|
||||
ACCESS_MASK GrantedAccess,
|
||||
ULONG HandleAttributes,
|
||||
PHANDLE Handle
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
ObpCreateHandleTable(
|
||||
|
|
|
@ -97,10 +97,13 @@ NtOpenProcessTokenEx(IN HANDLE ProcessHandle,
|
|||
&Token);
|
||||
if(NT_SUCCESS(Status))
|
||||
{
|
||||
Status = ObpCreateHandle(Token,
|
||||
DesiredAccess,
|
||||
HandleAttributes,
|
||||
&hToken);
|
||||
Status = ObOpenObjectByPointer(Token,
|
||||
0,
|
||||
NULL,
|
||||
DesiredAccess,
|
||||
SepTokenObjectType,
|
||||
PreviousMode,
|
||||
&hToken);
|
||||
ObDereferenceObject(Token);
|
||||
|
||||
if(NT_SUCCESS(Status))
|
||||
|
|
Loading…
Reference in a new issue