return STATUS_INVALID_HANDLE;
/* Check if we're dealing with a kernel handle */
- if (ObIsKernelHandle(Handle, AccessMode))
+ if (ObpIsKernelHandle(Handle, AccessMode))
{
/* Use the kernel table and convert the handle */
HandleTable = ObpKernelHandleTable;
{
PVOID Object = NULL;
UNICODE_STRING ObjectName;
- NTSTATUS Status;
+ NTSTATUS Status, Status2;
POBJECT_HEADER ObjectHeader;
PGENERIC_MAPPING GenericMapping = NULL;
OB_OPEN_REASON OpenReason;
PassedAccessState->SecurityDescriptor =
TempBuffer->ObjectCreateInfo.SecurityDescriptor;
}
-
+
/* Validate the access mask */
Status = ObpValidateAccessMask(PassedAccessState);
if (!NT_SUCCESS(Status))
else
{
/* Create the actual handle now */
- Status = ObpCreateHandle(OpenReason,
- Object,
- ObjectType,
- PassedAccessState,
- 0,
- TempBuffer->ObjectCreateInfo.Attributes,
- &TempBuffer->LookupContext,
- AccessMode,
- NULL,
- Handle);
- if (!NT_SUCCESS(Status)) ObDereferenceObject(Object);
+ Status2 = ObpCreateHandle(OpenReason,
+ Object,
+ ObjectType,
+ PassedAccessState,
+ 0,
+ TempBuffer->ObjectCreateInfo.Attributes,
+ &TempBuffer->LookupContext,
+ AccessMode,
+ NULL,
+ Handle);
+ if (!NT_SUCCESS(Status))
+ {
+ ObDereferenceObject(Object);
+ Status = Status2;
+ }
}
Cleanup:
IN POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags,
IN KPROCESSOR_MODE PreviousMode)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ OBP_SET_HANDLE_ATTRIBUTES_CONTEXT SetHandleAttributesContext;
+ BOOLEAN Result, AttachedToSystemProcess = FALSE;
+ PHANDLE_TABLE HandleTable;
+ KAPC_STATE ApcState;
+ PAGED_CODE();
+
+ /* Check if this is a kernel handle */
+ if (ObpIsKernelHandle(Handle, PreviousMode))
+ {
+ /* Use the kernel table and convert the handle */
+ HandleTable = ObpKernelHandleTable;
+ Handle = ObKernelHandleToHandle(Handle);
+
+ /* Check if we're not in the system process */
+ if (PsGetCurrentProcess() != PsInitialSystemProcess)
+ {
+ /* Attach to the system process */
+ KeStackAttachProcess(&PsInitialSystemProcess->Pcb, &ApcState);
+ AttachedToSystemProcess = TRUE;
+ }
+ }
+ else
+ {
+ /* Get the current process' handle table */
+ HandleTable = PsGetCurrentProcess()->ObjectTable;
+ }
+
+ /* Initialize the handle attribute context */
+ SetHandleAttributesContext.PreviousMode = PreviousMode;
+ SetHandleAttributesContext.Information = *HandleFlags;
+
+ /* Invoke the ObpSetHandleAttributes callback */
+ Result = ExChangeHandle(HandleTable,
+ Handle,
+ ObpSetHandleAttributes,
+ (ULONG_PTR)&SetHandleAttributesContext);
+
+ /* Did we attach to the system process? */
+ if (AttachedToSystemProcess)
+ {
+ /* Detach from it */
+ KeUnstackDetachProcess(&ApcState);
+ }
+
+ /* Return the result as an NTSTATUS value */
+ return Result ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
}
/*++
return Status;
}
-#undef ObIsKernelHandle
BOOLEAN
NTAPI
ObIsKernelHandle(IN HANDLE Handle)
{
- /* We know we're kernel mode, so just check for the kernel handle flag */
- return (BOOLEAN)(((ULONG_PTR)Handle & KERNEL_HANDLE_FLAG) != 0);
+ /* Use the inlined version. We know we are in kernel mode. */
+ return ObpIsKernelHandle(Handle, KernelMode);
}
/* EOF */