2006-05-24 22:07:11 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/ob/namespce.c
|
|
|
|
* PURPOSE: Manages all functions related to the Object Manager name-
|
|
|
|
* space, such as finding objects or querying their names.
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Eric Kohl
|
|
|
|
* Thomas Weidenmueller (w3seek@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
#define NTDDI_VERSION NTDDI_WINXP
|
2006-05-24 22:07:11 +00:00
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2007-01-08 08:03:47 +00:00
|
|
|
#include <debug.h>
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2007-01-08 08:03:47 +00:00
|
|
|
BOOLEAN ObpCaseInsensitive = TRUE;
|
2006-05-24 22:07:11 +00:00
|
|
|
POBJECT_DIRECTORY NameSpaceRoot = NULL;
|
|
|
|
POBJECT_DIRECTORY ObpTypeDirectoryObject = NULL;
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
- Set OBJ_OPENLINK invalid for core object types.
- Initialize symbolic link in-line with other core object types.
- Use the SePublicDefaultUnrestrictedSd directly instead of building another SD.
- Create core directory objects with Nt* functions instead of Ob*, to insure full accounting and error-handling.
- Create core objects with OBJ_CASE_INSENSITIVE.
- Fix the huge ObInit hack which was manually inserting Directory and Type object types in the type directory, and now loop the type list. Now we don't skip the Process, Token, Thread, Job, Section types anymore.
- Support Quota Information during object allocation and deallocation isntead of ignoring it.
- Use interlocked decrement when touching the object type (since it's a shared structure. We don't use the lock yet, but we won't for this anyways, since it's a simple lockable operation).
- Use the right object key when freeing the object.
- Modify the allocation function for a more optimized way of allocating objects instead of having to keep track of two sets of variables.
- Add various accounting variables.
- Make sure to properly handle allocations without object create info (ie, for object types). Now they get creator info and name info (which allowed us to cleanp the hack in ObInit).
- Add checks to see if Quota informatio is needed.
- Clear CreatorBackTraceIndex during allocation.
- Remove CreatorUniqueProcess hack from back when the idle thread was NULL.
- Do not zero out the header during allocation anymore, since this slows down the routine (instead, simply zero out the 2 fields that are NULL).
- Locate and clearly display that the fact we zero objects on creation is a HACK that needs to be fixed. (The Token code makes this assumption).
- Update HighWaterNumberOfObjects when needed.
- If caller didn't give pool charges, use the one from the object type.
- Clear the Total/HighWater* values for newly created object types instead of using random values.
- Properly typecast the WCHAR tag as CHAR.
- Insert each new object type in the ObTypeObjectType Type List.
- Set the Index member of each new object type and insert each new object type in the ObpObjectTypes array. This is crucial for object type enumeration when implemented.
- Fixup the way we insert new object types into the tree. Allow failure and don't return a type if we couldn't insert it, and only reference the type directory object if it actually exists.
- Move DOS Devices\"??" initialization in its own routine and fix it:
- Use Nt APIs for all operations instead of raw I/O.
- Create GLOBALROOT link to \
- Create \??\Global link to \??
svn path=/trunk/; revision=24568
2006-10-19 02:20:32 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
ObpCreateDosDevicesDirectory(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING Name, LinkName;
|
|
|
|
HANDLE Handle, SymHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Create the '\??' directory */
|
|
|
|
RtlInitUnicodeString(&Name, L"\\??");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&Name,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreateDirectoryObject(&Handle,
|
|
|
|
DIRECTORY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status)) return FALSE;
|
|
|
|
|
|
|
|
/* Initialize the GLOBALROOT path */
|
|
|
|
RtlInitUnicodeString(&LinkName, L"GLOBALROOT");
|
|
|
|
RtlInitUnicodeString(&Name, L"");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&LinkName,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
Handle,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreateSymbolicLinkObject(&SymHandle,
|
|
|
|
SYMBOLIC_LINK_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&Name);
|
|
|
|
if (NT_SUCCESS(Status)) NtClose(SymHandle);
|
|
|
|
|
|
|
|
/* Link \??\Global to \?? */
|
|
|
|
RtlInitUnicodeString(&LinkName, L"Global");
|
|
|
|
RtlInitUnicodeString(&Name, L"\\??");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&LinkName,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
Handle,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreateSymbolicLinkObject(&SymHandle,
|
|
|
|
SYMBOLIC_LINK_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&Name);
|
|
|
|
if (NT_SUCCESS(Status)) NtClose(SymHandle);
|
|
|
|
|
|
|
|
/* Close the directory handle */
|
|
|
|
NtClose(Handle);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Create link from '\DosDevices' to '\??' directory */
|
|
|
|
RtlCreateUnicodeString(&LinkName, L"\\DosDevices");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&LinkName,
|
|
|
|
OBJ_PERMANENT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreateSymbolicLinkObject(&SymHandle,
|
|
|
|
SYMBOLIC_LINK_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&Name);
|
|
|
|
if (NT_SUCCESS(Status)) NtClose(SymHandle);
|
|
|
|
|
|
|
|
/* FIXME: Hack Hack! */
|
|
|
|
ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(*ObSystemDeviceMap),
|
|
|
|
TAG('O', 'b', 'D', 'm'));
|
|
|
|
RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ObDereferenceDeviceMap(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
//KIRQL OldIrql;
|
|
|
|
PDEVICE_MAP DeviceMap = Process->DeviceMap;
|
|
|
|
|
|
|
|
/* FIXME: We don't use Process Devicemaps yet */
|
|
|
|
if (DeviceMap)
|
|
|
|
{
|
|
|
|
/* FIXME: Acquire the DeviceMap Spinlock */
|
|
|
|
// KeAcquireSpinLock(DeviceMap->Lock, &OldIrql);
|
|
|
|
|
|
|
|
/* Delete the device map link and dereference it */
|
|
|
|
Process->DeviceMap = NULL;
|
|
|
|
if (--DeviceMap->ReferenceCount)
|
|
|
|
{
|
|
|
|
/* Nobody is referencing it anymore, unlink the DOS directory */
|
|
|
|
DeviceMap->DosDevicesDirectory->DeviceMap = NULL;
|
|
|
|
|
|
|
|
/* FIXME: Release the DeviceMap Spinlock */
|
|
|
|
// KeReleasepinLock(DeviceMap->Lock, OldIrql);
|
|
|
|
|
|
|
|
/* Dereference the DOS Devices Directory and free the Device Map */
|
|
|
|
ObDereferenceObject(DeviceMap->DosDevicesDirectory);
|
|
|
|
ExFreePool(DeviceMap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: Release the DeviceMap Spinlock */
|
|
|
|
// KeReleasepinLock(DeviceMap->Lock, OldIrql);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ObInheritDeviceMap(IN PEPROCESS Parent,
|
|
|
|
IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* FIXME: Devicemap Support */
|
|
|
|
}
|
|
|
|
|
2006-06-08 18:24:37 +00:00
|
|
|
/*++
|
|
|
|
* @name ObpDeleteNameCheck
|
|
|
|
*
|
|
|
|
* The ObpDeleteNameCheck routine checks if a named object should be
|
|
|
|
* removed from the object directory namespace.
|
|
|
|
*
|
|
|
|
* @param Object
|
|
|
|
* Pointer to the object to check for possible removal.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks An object is removed if the following 4 criteria are met:
|
|
|
|
* 1) The object has 0 handles open
|
|
|
|
* 2) The object is in the directory namespace and has a name
|
|
|
|
* 3) The object is not permanent
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ObpDeleteNameCheck(IN PVOID Object)
|
|
|
|
{
|
|
|
|
POBJECT_HEADER ObjectHeader;
|
|
|
|
OBP_LOOKUP_CONTEXT Context;
|
|
|
|
POBJECT_HEADER_NAME_INFO ObjectNameInfo;
|
|
|
|
POBJECT_TYPE ObjectType;
|
2006-06-14 04:02:02 +00:00
|
|
|
PVOID Directory = NULL;
|
2006-06-08 18:24:37 +00:00
|
|
|
|
|
|
|
/* Get object structures */
|
|
|
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
|
|
|
|
ObjectNameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
|
|
|
|
ObjectType = ObjectHeader->Type;
|
|
|
|
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Check if we have a name information structure */
|
|
|
|
if (ObjectNameInfo)
|
|
|
|
{
|
|
|
|
/* Add a query reference */
|
|
|
|
if (!ObpIncrementQueryReference(ObjectHeader, ObjectNameInfo))
|
|
|
|
{
|
|
|
|
/* No references, so the name info is invalid */
|
|
|
|
ObjectNameInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-08 18:24:37 +00:00
|
|
|
/*
|
|
|
|
* Check if the handle count is 0, if the object is named,
|
|
|
|
* and if the object isn't a permanent object.
|
|
|
|
*/
|
|
|
|
if (!(ObjectHeader->HandleCount) &&
|
|
|
|
(ObjectNameInfo) &&
|
|
|
|
(ObjectNameInfo->Name.Length) &&
|
2007-01-10 01:00:46 +00:00
|
|
|
(ObjectNameInfo->Directory) &&
|
2006-06-08 18:24:37 +00:00
|
|
|
!(ObjectHeader->Flags & OB_FLAG_PERMANENT))
|
|
|
|
{
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Setup a lookup context */
|
2007-01-09 21:48:26 +00:00
|
|
|
ObpInitializeDirectoryLookup(&Context);
|
2007-01-08 08:03:47 +00:00
|
|
|
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Lock the directory */
|
2007-01-10 01:00:46 +00:00
|
|
|
ObpAcquireDirectoryLockExclusive(ObjectNameInfo->Directory, &Context);
|
2007-01-09 07:28:40 +00:00
|
|
|
|
|
|
|
/* Do the lookup */
|
2006-06-08 18:24:37 +00:00
|
|
|
Object = ObpLookupEntryDirectory(ObjectNameInfo->Directory,
|
|
|
|
&ObjectNameInfo->Name,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
&Context);
|
2007-01-09 07:28:40 +00:00
|
|
|
if (Object)
|
2006-06-08 18:24:37 +00:00
|
|
|
{
|
2006-10-19 02:54:48 +00:00
|
|
|
/* Lock the object type */
|
|
|
|
ObpEnterObjectTypeMutex(ObjectType);
|
|
|
|
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Make sure we can still delete the object */
|
|
|
|
if (!(ObjectHeader->HandleCount) &&
|
|
|
|
!(ObjectHeader->Flags & OB_FLAG_PERMANENT))
|
2006-06-08 18:24:37 +00:00
|
|
|
{
|
2007-01-09 07:28:40 +00:00
|
|
|
/* First delete it from the directory */
|
|
|
|
ObpDeleteEntryDirectory(&Context);
|
|
|
|
|
|
|
|
/* Check if this is a symbolic link */
|
|
|
|
if (ObjectType == ObSymbolicLinkType)
|
|
|
|
{
|
|
|
|
/* Remove internal name */
|
|
|
|
ObpDeleteSymbolicLinkName(Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a query reference */
|
|
|
|
ObjectNameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
|
|
|
|
if (!ObpIncrementQueryReference(ObjectHeader, ObjectNameInfo))
|
|
|
|
{
|
|
|
|
/* No references, so the name info is invalid */
|
|
|
|
ObjectNameInfo = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the magic protection flag is set */
|
|
|
|
if ((ObjectNameInfo) &&
|
|
|
|
(ObjectNameInfo->QueryReferences & 0x40000000))
|
|
|
|
{
|
|
|
|
/* Add deletion flag */
|
|
|
|
InterlockedExchangeAdd(&ObjectNameInfo->QueryReferences,
|
|
|
|
0xC0000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the directory */
|
|
|
|
Directory = ObjectNameInfo->Directory;
|
2006-06-08 18:24:37 +00:00
|
|
|
}
|
|
|
|
|
2006-10-19 02:54:48 +00:00
|
|
|
/* Release the lock */
|
|
|
|
ObpLeaveObjectTypeMutex(ObjectType);
|
2007-01-09 07:28:40 +00:00
|
|
|
}
|
2006-10-19 02:54:48 +00:00
|
|
|
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Cleanup after lookup */
|
2007-01-10 01:00:46 +00:00
|
|
|
ObpCleanupDirectoryLookup(&Context);
|
2006-06-08 18:24:37 +00:00
|
|
|
|
2007-01-09 07:28:40 +00:00
|
|
|
/* Remove another query reference since we added one on top */
|
|
|
|
ObpDecrementQueryReference(ObjectNameInfo);
|
2006-06-14 04:02:02 +00:00
|
|
|
|
|
|
|
/* Check if we were inserted in a directory */
|
|
|
|
if (Directory)
|
|
|
|
{
|
2007-01-09 07:28:40 +00:00
|
|
|
/* We were, so first remove the extra reference we had added */
|
|
|
|
ObpDecrementQueryReference(ObjectNameInfo);
|
|
|
|
|
|
|
|
/* Now dereference the object as well */
|
2006-06-14 04:02:02 +00:00
|
|
|
ObDereferenceObject(Object);
|
|
|
|
}
|
2006-06-08 18:24:37 +00:00
|
|
|
}
|
2007-01-09 07:28:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove the reference we added */
|
|
|
|
if (ObjectNameInfo) ObpDecrementQueryReference(ObjectNameInfo);
|
|
|
|
}
|
2006-06-08 18:24:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-24 22:07:11 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2007-01-08 08:03:47 +00:00
|
|
|
ObpLookupObjectName(IN HANDLE RootHandle,
|
|
|
|
IN PUNICODE_STRING ObjectName,
|
|
|
|
IN ULONG Attributes,
|
|
|
|
IN POBJECT_TYPE ObjectType,
|
|
|
|
IN KPROCESSOR_MODE AccessMode,
|
|
|
|
IN OUT PVOID ParseContext,
|
|
|
|
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos,
|
2007-01-09 07:54:19 +00:00
|
|
|
IN PVOID InsertObject,
|
2007-01-08 08:03:47 +00:00
|
|
|
IN PACCESS_STATE AccessState,
|
2007-01-09 07:54:19 +00:00
|
|
|
IN POBP_LOOKUP_CONTEXT LookupContext,
|
|
|
|
OUT PVOID *FoundObject)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2007-01-09 07:54:19 +00:00
|
|
|
PVOID Object;
|
|
|
|
POBJECT_HEADER ObjectHeader;
|
2007-01-09 17:18:22 +00:00
|
|
|
UNICODE_STRING ComponentName, RemainingName;
|
|
|
|
BOOLEAN InsideRoot = FALSE;
|
|
|
|
PDEVICE_MAP DeviceMap = NULL;
|
|
|
|
POBJECT_DIRECTORY Directory = NULL, ParentDirectory = NULL, RootDirectory;
|
|
|
|
POBJECT_DIRECTORY ReferencedDirectory = NULL, ReferencedParentDirectory = NULL;
|
|
|
|
KIRQL CalloutIrql;
|
|
|
|
OB_PARSE_METHOD ParseRoutine;
|
2007-01-09 07:54:19 +00:00
|
|
|
NTSTATUS Status;
|
2007-01-09 17:18:22 +00:00
|
|
|
KPROCESSOR_MODE AccessCheckMode;
|
2007-01-09 07:54:19 +00:00
|
|
|
PWCHAR NewName;
|
2006-06-12 05:58:08 +00:00
|
|
|
POBJECT_HEADER_NAME_INFO ObjectNameInfo;
|
2006-05-24 22:07:11 +00:00
|
|
|
PAGED_CODE();
|
2006-06-12 05:58:08 +00:00
|
|
|
OBTRACE(OB_NAMESPACE_DEBUG,
|
|
|
|
"%s - Finding Object: %wZ. Expecting: %p\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
ObjectName,
|
2007-01-09 07:54:19 +00:00
|
|
|
InsertObject);
|
|
|
|
|
|
|
|
/* Initialize starting state */
|
2007-01-09 21:48:26 +00:00
|
|
|
ObpInitializeDirectoryLookup(LookupContext);
|
2007-01-09 07:54:19 +00:00
|
|
|
*FoundObject = NULL;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Object = NULL;
|
|
|
|
|
|
|
|
/* Check if case-insensitivity is forced */
|
|
|
|
if ((ObpCaseInsensitive) || (ObjectType->TypeInfo.CaseInsensitive))
|
|
|
|
{
|
|
|
|
/* Add the flag to disable case sensitivity */
|
|
|
|
Attributes |= OBJ_CASE_INSENSITIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a access checks are being forced */
|
|
|
|
AccessCheckMode = (Attributes & OBJ_FORCE_ACCESS_CHECK) ?
|
|
|
|
UserMode : AccessMode;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Check if we got a Root Directory */
|
|
|
|
if (RootHandle)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* We did. Reference it */
|
2006-05-28 19:05:19 +00:00
|
|
|
Status = ObReferenceObjectByHandle(RootHandle,
|
2006-06-12 05:58:08 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
AccessMode,
|
2007-01-09 17:18:22 +00:00
|
|
|
(PVOID*)&RootDirectory,
|
2006-06-12 05:58:08 +00:00
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Get the header */
|
2007-01-09 07:54:19 +00:00
|
|
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(RootDirectory);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
|
|
|
/* The name cannot start with a separator, unless this is a file */
|
|
|
|
if ((ObjectName->Buffer) &&
|
|
|
|
(ObjectName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR) &&
|
2007-01-09 07:54:19 +00:00
|
|
|
(ObjectHeader->Type != IoFileObjectType))
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* The syntax is bad, so fail this request */
|
|
|
|
ObDereferenceObject(RootDirectory);
|
|
|
|
return STATUS_OBJECT_PATH_SYNTAX_BAD;
|
2006-05-24 22:07:11 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Don't parse a Directory */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (ObjectHeader->Type != ObDirectoryType)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* Make sure the Object Type has a parse routine */
|
2007-01-09 07:54:19 +00:00
|
|
|
ParseRoutine = ObjectHeader->Type->TypeInfo.ParseProcedure;
|
2006-06-12 05:58:08 +00:00
|
|
|
if (!ParseRoutine)
|
|
|
|
{
|
|
|
|
/* We can't parse a name if we don't have a parse routine */
|
|
|
|
ObDereferenceObject(RootDirectory);
|
|
|
|
return STATUS_INVALID_HANDLE;
|
|
|
|
}
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Now parse */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Start with the full name */
|
2007-01-09 07:54:19 +00:00
|
|
|
RemainingName = *ObjectName;
|
2006-06-12 05:58:08 +00:00
|
|
|
|
|
|
|
/* Call the Parse Procedure */
|
2007-01-09 07:54:19 +00:00
|
|
|
ObpCalloutStart(&CalloutIrql);
|
2006-06-12 05:58:08 +00:00
|
|
|
Status = ParseRoutine(RootDirectory,
|
|
|
|
ObjectType,
|
|
|
|
AccessState,
|
2007-01-09 17:18:22 +00:00
|
|
|
AccessCheckMode,
|
2006-06-12 05:58:08 +00:00
|
|
|
Attributes,
|
|
|
|
ObjectName,
|
2007-01-09 07:54:19 +00:00
|
|
|
&RemainingName,
|
2006-06-12 05:58:08 +00:00
|
|
|
ParseContext,
|
|
|
|
SecurityQos,
|
2007-01-09 07:54:19 +00:00
|
|
|
&Object);
|
|
|
|
ObpCalloutEnd(CalloutIrql, "Parse", ObjectHeader->Type, Object);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
|
|
|
/* Check for success or failure, so not reparse */
|
|
|
|
if ((Status != STATUS_REPARSE) &&
|
|
|
|
(Status != STATUS_REPARSE_OBJECT))
|
|
|
|
{
|
|
|
|
/* Check for failure */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Parse routine might not have cleared this, do it */
|
2007-01-09 07:54:19 +00:00
|
|
|
Object = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
2007-01-09 07:54:19 +00:00
|
|
|
else if (!Object)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* Modify status to reflect failure inside Ob */
|
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We're done, return the status and object */
|
2007-01-09 07:54:19 +00:00
|
|
|
*FoundObject = Object;
|
2006-06-12 05:58:08 +00:00
|
|
|
ObDereferenceObject(RootDirectory);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
else if ((!ObjectName->Length) ||
|
|
|
|
(!ObjectName->Buffer) ||
|
|
|
|
(ObjectName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR))
|
|
|
|
{
|
|
|
|
/* Reparsed to the root directory, so start over */
|
|
|
|
ObDereferenceObject(RootDirectory);
|
|
|
|
RootDirectory = NameSpaceRoot;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Don't use this anymore, since we're starting at root */
|
|
|
|
RootHandle = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(ObjectName->Length) || !(ObjectName->Buffer))
|
|
|
|
{
|
|
|
|
/* Just return the Root Directory if we didn't get a name*/
|
|
|
|
Status = ObReferenceObjectByPointer(RootDirectory,
|
|
|
|
0,
|
|
|
|
ObjectType,
|
|
|
|
AccessMode);
|
2007-01-09 07:54:19 +00:00
|
|
|
if (NT_SUCCESS(Status)) Object = RootDirectory;
|
|
|
|
|
|
|
|
/* Remove the first reference we added and return the object */
|
2006-06-12 05:58:08 +00:00
|
|
|
ObDereferenceObject(RootDirectory);
|
2007-01-09 07:54:19 +00:00
|
|
|
*FoundObject = Object;
|
2006-06-12 05:58:08 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2006-05-24 22:07:11 +00:00
|
|
|
}
|
2006-06-12 05:58:08 +00:00
|
|
|
else
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* We did not get a Root Directory, so use the root */
|
|
|
|
RootDirectory = NameSpaceRoot;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* It must start with a path separator */
|
|
|
|
if (!(ObjectName->Length) ||
|
|
|
|
!(ObjectName->Buffer) ||
|
|
|
|
(ObjectName->Buffer[0] != OBJ_NAME_PATH_SEPARATOR))
|
2006-05-24 23:20:50 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* This name is invalid, so fail */
|
|
|
|
return STATUS_OBJECT_PATH_SYNTAX_BAD;
|
|
|
|
}
|
2006-05-24 23:20:50 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Check if the name is only the path separator */
|
|
|
|
if (ObjectName->Length == sizeof(OBJ_NAME_PATH_SEPARATOR))
|
|
|
|
{
|
|
|
|
/* So the caller only wants the root directory; do we have one? */
|
|
|
|
if (!RootDirectory)
|
2006-05-24 23:20:50 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* This must be the first time we're creating it... right? */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (InsertObject)
|
2006-05-24 23:20:50 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Yes, so return it to ObInsert so that it can create it */
|
2007-01-09 07:54:19 +00:00
|
|
|
Status = ObReferenceObjectByPointer(InsertObject,
|
2006-06-12 05:58:08 +00:00
|
|
|
0,
|
|
|
|
ObjectType,
|
|
|
|
AccessMode);
|
2007-01-09 07:54:19 +00:00
|
|
|
if (NT_SUCCESS(Status)) *FoundObject = InsertObject;
|
2006-06-12 05:58:08 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This should never really happen */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2006-05-24 23:20:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* We do have the root directory, so just return it */
|
|
|
|
Status = ObReferenceObjectByPointer(RootDirectory,
|
|
|
|
0,
|
|
|
|
ObjectType,
|
|
|
|
AccessMode);
|
2007-01-09 07:54:19 +00:00
|
|
|
if (NT_SUCCESS(Status)) *FoundObject = RootDirectory;
|
2006-06-12 05:58:08 +00:00
|
|
|
return Status;
|
2006-05-24 23:20:50 +00:00
|
|
|
}
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-24 23:20:50 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Save the name */
|
|
|
|
ReparseNewDir:
|
2007-01-09 07:54:19 +00:00
|
|
|
RemainingName = *ObjectName;
|
2006-05-24 23:20:50 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Reparse */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Check if we should use the Root Directory */
|
|
|
|
if (!InsideRoot)
|
|
|
|
{
|
|
|
|
/* Yes, use the root directory and remember that */
|
2007-01-09 07:54:19 +00:00
|
|
|
Directory = RootDirectory;
|
2006-06-12 05:58:08 +00:00
|
|
|
InsideRoot = TRUE;
|
2006-05-24 23:20:50 +00:00
|
|
|
}
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Check if the name starts with a path separator */
|
2007-01-09 07:54:19 +00:00
|
|
|
if ((RemainingName.Length) &&
|
|
|
|
(RemainingName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR))
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Skip the path separator */
|
2007-01-09 07:54:19 +00:00
|
|
|
RemainingName.Buffer++;
|
|
|
|
RemainingName.Length -= sizeof(OBJ_NAME_PATH_SEPARATOR);
|
2006-05-24 22:07:11 +00:00
|
|
|
}
|
2006-05-25 01:18:31 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Find the next Part Name */
|
2007-01-09 07:54:19 +00:00
|
|
|
ComponentName = RemainingName;
|
|
|
|
while (RemainingName.Length)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Break if we found the \ ending */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (RemainingName.Buffer[0] == OBJ_NAME_PATH_SEPARATOR) break;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Move on */
|
2007-01-09 07:54:19 +00:00
|
|
|
RemainingName.Buffer++;
|
|
|
|
RemainingName.Length -= sizeof(OBJ_NAME_PATH_SEPARATOR);
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
2006-05-24 23:20:50 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Get its size and make sure it's valid */
|
2007-01-09 09:30:43 +00:00
|
|
|
ComponentName.Length -= RemainingName.Length;
|
|
|
|
if (!ComponentName.Length)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Invalid size, fail */
|
2006-06-12 05:58:08 +00:00
|
|
|
Status = STATUS_OBJECT_NAME_INVALID;
|
2006-05-24 22:07:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Check if this is a user-mode call that needs to traverse */
|
|
|
|
if ((AccessCheckMode != KernelMode) &&
|
|
|
|
!(AccessState->Flags & TOKEN_HAS_TRAVERSE_PRIVILEGE))
|
|
|
|
{
|
2007-01-09 09:37:36 +00:00
|
|
|
/* We shouldn't have referenced a directory yet */
|
|
|
|
ASSERT(ReferencedDirectory == NULL);
|
|
|
|
|
|
|
|
/* Reference the directory */
|
|
|
|
ObReferenceObject(Directory);
|
|
|
|
ReferencedDirectory = Directory;
|
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Check if we have a parent directory */
|
|
|
|
if (ParentDirectory)
|
|
|
|
{
|
|
|
|
/* Check for traverse access */
|
|
|
|
if (!ObpCheckTraverseAccess(ParentDirectory,
|
|
|
|
DIRECTORY_TRAVERSE,
|
|
|
|
AccessState,
|
|
|
|
FALSE,
|
|
|
|
AccessCheckMode,
|
|
|
|
&Status))
|
|
|
|
{
|
|
|
|
/* We don't have it, fail */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we don't have a remaining name yet */
|
|
|
|
if (!RemainingName.Length)
|
|
|
|
{
|
2007-01-09 09:37:36 +00:00
|
|
|
/* Check if we don't have a referenced directory yet */
|
|
|
|
if (!ReferencedDirectory)
|
|
|
|
{
|
|
|
|
/* Reference it */
|
|
|
|
ObReferenceObject(Directory);
|
|
|
|
ReferencedDirectory = Directory;
|
|
|
|
}
|
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Check if we are inserting an object */
|
|
|
|
if (InsertObject)
|
|
|
|
{
|
|
|
|
/* Lock the directory */
|
2007-01-10 01:00:46 +00:00
|
|
|
ObpAcquireDirectoryLockExclusive(Directory, LookupContext);
|
2007-01-09 09:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the lookup */
|
2007-01-09 07:54:19 +00:00
|
|
|
Object = ObpLookupEntryDirectory(Directory,
|
2007-01-09 09:30:43 +00:00
|
|
|
&ComponentName,
|
|
|
|
Attributes,
|
|
|
|
InsertObject ? FALSE : TRUE,
|
|
|
|
LookupContext);
|
2007-01-09 07:54:19 +00:00
|
|
|
if (!Object)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* We didn't find it... do we still have a path? */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (RemainingName.Length)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* Then tell the caller the path wasn't found */
|
|
|
|
Status = STATUS_OBJECT_PATH_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-09 07:54:19 +00:00
|
|
|
else if (!InsertObject)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* Otherwise, we have a path, but the name isn't valid */
|
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Check create access for the object */
|
|
|
|
if (!ObCheckCreateObjectAccess(Directory,
|
|
|
|
ObjectType == ObDirectoryType ?
|
|
|
|
DIRECTORY_CREATE_SUBDIRECTORY :
|
|
|
|
DIRECTORY_CREATE_OBJECT,
|
|
|
|
AccessState,
|
|
|
|
&ComponentName,
|
|
|
|
FALSE,
|
|
|
|
AccessCheckMode,
|
|
|
|
&Status))
|
|
|
|
{
|
|
|
|
/* We don't have create access, fail */
|
|
|
|
break;
|
|
|
|
}
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Get the object header */
|
|
|
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(InsertObject);
|
|
|
|
|
|
|
|
/* FIXME: Check if this is a Section Object or Sym Link */
|
|
|
|
/* FIXME: If it is, then check if this isn't session 0 */
|
|
|
|
/* FIXME: If it isn't, check for SeCreateGlobalPrivilege */
|
|
|
|
/* FIXME: If privilege isn't there, check for unsecure name */
|
|
|
|
/* FIXME: If it isn't a known unsecure name, then fail */
|
|
|
|
|
|
|
|
/* Create Object Name */
|
|
|
|
NewName = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
ComponentName.Length,
|
|
|
|
OB_NAME_TAG);
|
|
|
|
if (!(NewName) ||
|
|
|
|
!(ObpInsertEntryDirectory(Directory,
|
|
|
|
LookupContext,
|
|
|
|
ObjectHeader)))
|
|
|
|
{
|
|
|
|
/* Either couldn't allocate the name, or insert failed */
|
|
|
|
if (NewName) ExFreePool(NewName);
|
2006-05-28 19:05:19 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Fail due to memory reasons */
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Reference newly to be inserted object */
|
|
|
|
ObReferenceObject(InsertObject);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Get the name information */
|
|
|
|
ObjectNameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Reference the directory */
|
|
|
|
ObReferenceObject(Directory);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Copy the Name */
|
|
|
|
RtlCopyMemory(NewName,
|
|
|
|
ComponentName.Buffer,
|
|
|
|
ComponentName.Length);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Check if we had an old name */
|
|
|
|
if (ObjectNameInfo->Name.Buffer)
|
|
|
|
{
|
|
|
|
/* Free it */
|
|
|
|
ExFreePool(ObjectNameInfo->Name.Buffer);
|
|
|
|
}
|
2007-01-09 07:54:19 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Write new one */
|
|
|
|
ObjectNameInfo->Name.Buffer = NewName;
|
|
|
|
ObjectNameInfo->Name.Length = ComponentName.Length;
|
|
|
|
ObjectNameInfo->Name.MaximumLength = ComponentName.Length;
|
2007-01-09 07:54:19 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Return Status and the Expected Object */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Object = InsertObject;
|
2007-01-09 07:54:19 +00:00
|
|
|
|
2007-01-09 09:30:43 +00:00
|
|
|
/* Get out of here */
|
|
|
|
break;
|
2006-05-28 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
Reparse:
|
|
|
|
/* We found it, so now get its header */
|
2007-01-09 07:54:19 +00:00
|
|
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-08 08:03:47 +00:00
|
|
|
/*
|
2006-06-12 05:58:08 +00:00
|
|
|
* Check for a parse Procedure, but don't bother to parse for an insert
|
|
|
|
* unless it's a Symbolic Link, in which case we MUST parse
|
2006-06-08 21:36:44 +00:00
|
|
|
*/
|
2007-01-09 07:54:19 +00:00
|
|
|
ParseRoutine = ObjectHeader->Type->TypeInfo.ParseProcedure;
|
|
|
|
if ((ParseRoutine) &&
|
|
|
|
(!(InsertObject) || (ParseRoutine == ObpParseSymbolicLink)))
|
2006-06-08 21:36:44 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Use the Root Directory next time */
|
|
|
|
InsideRoot = FALSE;
|
|
|
|
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Increment the pointer count */
|
|
|
|
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
|
|
|
|
|
2007-01-09 09:37:36 +00:00
|
|
|
/* Cleanup from the first lookup */
|
2007-01-10 01:00:46 +00:00
|
|
|
ObpCleanupDirectoryLookup(LookupContext);
|
2007-01-09 09:37:36 +00:00
|
|
|
|
|
|
|
/* Check if we have a referenced directory */
|
|
|
|
if (ReferencedDirectory)
|
|
|
|
{
|
|
|
|
/* We do, dereference it */
|
|
|
|
ObDereferenceObject(ReferencedDirectory);
|
|
|
|
ReferencedDirectory = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a referenced parent directory */
|
|
|
|
if (ReferencedParentDirectory)
|
|
|
|
{
|
|
|
|
/* We do, dereference it */
|
|
|
|
ObDereferenceObject(ReferencedParentDirectory);
|
|
|
|
ReferencedParentDirectory = NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Call the Parse Procedure */
|
2007-01-09 07:54:19 +00:00
|
|
|
ObpCalloutStart(&CalloutIrql);
|
|
|
|
Status = ParseRoutine(Object,
|
2006-06-12 05:58:08 +00:00
|
|
|
ObjectType,
|
|
|
|
AccessState,
|
2007-01-09 17:18:22 +00:00
|
|
|
AccessCheckMode,
|
2006-06-12 05:58:08 +00:00
|
|
|
Attributes,
|
|
|
|
ObjectName,
|
2007-01-09 07:54:19 +00:00
|
|
|
&RemainingName,
|
2006-06-12 05:58:08 +00:00
|
|
|
ParseContext,
|
|
|
|
SecurityQos,
|
2007-01-09 07:54:19 +00:00
|
|
|
&Object);
|
|
|
|
ObpCalloutEnd(CalloutIrql, "Parse", ObjectHeader->Type, Object);
|
|
|
|
|
|
|
|
/* Remove our extra reference */
|
|
|
|
ObDereferenceObject(&ObjectHeader->Body);
|
2006-06-12 05:58:08 +00:00
|
|
|
|
|
|
|
/* Check if we have to reparse */
|
|
|
|
if ((Status == STATUS_REPARSE) ||
|
|
|
|
(Status == STATUS_REPARSE_OBJECT))
|
|
|
|
{
|
|
|
|
/* Start over from root if we got sent back there */
|
|
|
|
if ((Status == STATUS_REPARSE_OBJECT) ||
|
|
|
|
(ObjectName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR))
|
|
|
|
{
|
|
|
|
/* Check if we got a root directory */
|
|
|
|
if (RootHandle)
|
|
|
|
{
|
|
|
|
/* Stop using it, because we have a new directory now */
|
|
|
|
ObDereferenceObject(RootDirectory);
|
|
|
|
RootHandle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start at Root */
|
2007-01-09 09:30:43 +00:00
|
|
|
ParentDirectory = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
RootDirectory = NameSpaceRoot;
|
|
|
|
|
|
|
|
/* Check for reparse status */
|
|
|
|
if (Status == STATUS_REPARSE_OBJECT)
|
|
|
|
{
|
|
|
|
/* Did we actually get an object to which to reparse? */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (!Object)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* We didn't, so set a failure status */
|
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We did, so we're free to parse the new object */
|
|
|
|
InsideRoot = TRUE;
|
|
|
|
goto Reparse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restart the search */
|
|
|
|
goto ReparseNewDir;
|
|
|
|
}
|
|
|
|
else if (RootDirectory == NameSpaceRoot)
|
|
|
|
{
|
|
|
|
/* We got STATUS_REPARSE but are at the Root Directory */
|
2007-01-09 07:54:19 +00:00
|
|
|
Object = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Total failure */
|
2007-01-09 07:54:19 +00:00
|
|
|
Object = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
2007-01-09 07:54:19 +00:00
|
|
|
else if (!Object)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* We didn't reparse but we didn't find the Object Either */
|
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
2006-06-08 21:36:44 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Break out of the loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2006-05-28 19:05:19 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* No parse routine...do we still have a remaining name? */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (!RemainingName.Length)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
|
|
|
/* Are we creating an object? */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (!InsertObject)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Check if this is a user-mode call that needs to traverse */
|
|
|
|
if ((AccessCheckMode != KernelMode) &&
|
|
|
|
!(AccessState->Flags & TOKEN_HAS_TRAVERSE_PRIVILEGE))
|
|
|
|
{
|
|
|
|
/* Check if we can get it */
|
|
|
|
if (!ObpCheckTraverseAccess(Directory,
|
|
|
|
DIRECTORY_TRAVERSE,
|
|
|
|
AccessState,
|
|
|
|
FALSE,
|
|
|
|
AccessCheckMode,
|
|
|
|
&Status))
|
|
|
|
{
|
|
|
|
/* We don't have access, fail */
|
|
|
|
Object = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reference the Object */
|
|
|
|
Status = ObReferenceObjectByPointer(Object,
|
2006-06-12 05:58:08 +00:00
|
|
|
0,
|
|
|
|
ObjectType,
|
|
|
|
AccessMode);
|
2007-01-09 07:54:19 +00:00
|
|
|
if (!NT_SUCCESS(Status)) Object = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
2006-05-28 19:05:19 +00:00
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* And get out of the reparse loop */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2006-05-28 19:05:19 +00:00
|
|
|
{
|
2006-06-12 05:58:08 +00:00
|
|
|
/* We still have a name; check if this is a directory object */
|
2007-01-09 07:54:19 +00:00
|
|
|
if (ObjectHeader->Type == ObDirectoryType)
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
2007-01-09 09:37:36 +00:00
|
|
|
/* Check if we have a referenced parent directory */
|
|
|
|
if (ReferencedParentDirectory)
|
|
|
|
{
|
|
|
|
/* Dereference it */
|
|
|
|
ObDereferenceObject(ReferencedParentDirectory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restart the lookup from this directory */
|
|
|
|
ReferencedParentDirectory = ReferencedDirectory;
|
2007-01-09 09:30:43 +00:00
|
|
|
ParentDirectory = Directory;
|
2007-01-09 07:54:19 +00:00
|
|
|
Directory = Object;
|
2007-01-09 09:37:36 +00:00
|
|
|
ReferencedDirectory = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We still have a name, but no parse routine for it */
|
|
|
|
Status = STATUS_OBJECT_TYPE_MISMATCH;
|
2007-01-09 07:54:19 +00:00
|
|
|
Object = NULL;
|
2006-06-12 05:58:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-28 19:05:19 +00:00
|
|
|
}
|
2006-06-08 19:00:22 +00:00
|
|
|
}
|
2006-06-12 05:58:08 +00:00
|
|
|
}
|
2006-05-28 19:05:19 +00:00
|
|
|
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Check if we failed */
|
|
|
|
if (!NT_SUCCESS(Status))
|
2006-06-12 05:58:08 +00:00
|
|
|
{
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Cleanup after lookup */
|
2007-01-10 01:00:46 +00:00
|
|
|
ObpCleanupDirectoryLookup(LookupContext);
|
2006-05-28 19:05:19 +00:00
|
|
|
}
|
2006-06-12 05:58:08 +00:00
|
|
|
|
2007-01-09 09:37:36 +00:00
|
|
|
/* Check if we have a device map and dereference it if so */
|
2007-01-09 17:18:22 +00:00
|
|
|
if (DeviceMap) ObfDereferenceDeviceMap(DeviceMap);
|
2007-01-09 09:37:36 +00:00
|
|
|
|
|
|
|
/* Check if we have a referenced directory and dereference it if so */
|
|
|
|
if (ReferencedDirectory) ObDereferenceObject(ReferencedDirectory);
|
|
|
|
|
|
|
|
/* Check if we have a referenced parent directory */
|
|
|
|
if (ReferencedParentDirectory)
|
|
|
|
{
|
|
|
|
/* We do, dereference it */
|
|
|
|
ObDereferenceObject(ReferencedParentDirectory);
|
|
|
|
}
|
|
|
|
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Set the found object and check if we got one */
|
|
|
|
*FoundObject = Object;
|
|
|
|
if (!Object)
|
2006-05-28 19:05:19 +00:00
|
|
|
{
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Nothing was found. Did we reparse or get success? */
|
|
|
|
if ((Status == STATUS_REPARSE) || (NT_SUCCESS(Status)))
|
|
|
|
{
|
|
|
|
/* Set correct failure */
|
|
|
|
Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
|
|
|
}
|
2006-05-28 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2007-01-09 07:54:19 +00:00
|
|
|
/* Check if we had a root directory */
|
|
|
|
if (RootHandle) ObDereferenceObject(RootDirectory);
|
|
|
|
|
2006-06-12 05:58:08 +00:00
|
|
|
/* Return status to caller */
|
|
|
|
OBTRACE(OB_NAMESPACE_DEBUG,
|
|
|
|
"%s - Found Object: %p. Expected: %p\n",
|
|
|
|
__FUNCTION__,
|
2007-01-09 07:54:19 +00:00
|
|
|
*FoundObject,
|
|
|
|
InsertObject);
|
2006-05-28 19:05:19 +00:00
|
|
|
return Status;
|
2006-05-24 22:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS *********************************************************/
|
|
|
|
|
2006-06-05 06:31:42 +00:00
|
|
|
NTSTATUS
|
2006-06-11 06:52:56 +00:00
|
|
|
NTAPI
|
2007-01-08 08:03:47 +00:00
|
|
|
ObQueryNameString(IN PVOID Object,
|
2006-05-24 22:07:11 +00:00
|
|
|
OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
|
2007-01-08 08:03:47 +00:00
|
|
|
IN ULONG Length,
|
2006-05-24 22:07:11 +00:00
|
|
|
OUT PULONG ReturnLength)
|
|
|
|
{
|
|
|
|
POBJECT_HEADER_NAME_INFO LocalInfo;
|
|
|
|
POBJECT_HEADER ObjectHeader;
|
|
|
|
POBJECT_DIRECTORY ParentDirectory;
|
|
|
|
ULONG NameSize;
|
|
|
|
PWCH ObjectName;
|
|
|
|
|
|
|
|
/* Get the Kernel Meta-Structures */
|
2006-05-25 20:14:09 +00:00
|
|
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
|
|
|
|
LocalInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Check if a Query Name Procedure is available */
|
2006-06-05 00:16:14 +00:00
|
|
|
if (ObjectHeader->Type->TypeInfo.QueryNameProcedure)
|
|
|
|
{
|
2006-05-24 22:07:11 +00:00
|
|
|
/* Call the procedure */
|
2006-06-05 00:16:14 +00:00
|
|
|
return ObjectHeader->Type->TypeInfo.QueryNameProcedure(Object,
|
|
|
|
TRUE, //fixme
|
|
|
|
ObjectNameInfo,
|
|
|
|
Length,
|
2006-06-11 06:52:56 +00:00
|
|
|
ReturnLength,
|
|
|
|
KernelMode);
|
2006-05-24 22:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the object doesn't even have a name */
|
2006-07-27 00:13:14 +00:00
|
|
|
if (!(LocalInfo) || !(LocalInfo->Name.Buffer))
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* We're returning the name structure */
|
|
|
|
*ReturnLength = sizeof(OBJECT_NAME_INFORMATION);
|
|
|
|
|
|
|
|
/* Check if we were given enough space */
|
2006-06-05 00:16:14 +00:00
|
|
|
if (*ReturnLength > Length) return STATUS_INFO_LENGTH_MISMATCH;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Return an empty buffer */
|
2006-06-05 00:16:14 +00:00
|
|
|
RtlInitEmptyUnicodeString(&ObjectNameInfo->Name, NULL, 0);
|
2006-05-24 22:07:11 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-06-05 00:16:14 +00:00
|
|
|
/*
|
2006-05-24 22:07:11 +00:00
|
|
|
* Find the size needed for the name. We won't do
|
|
|
|
* this during the Name Creation loop because we want
|
|
|
|
* to let the caller know that the buffer isn't big
|
|
|
|
* enough right at the beginning, not work our way through
|
|
|
|
* and find out at the end
|
|
|
|
*/
|
2006-06-05 00:16:14 +00:00
|
|
|
if (Object == NameSpaceRoot)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Size of the '\' string */
|
|
|
|
NameSize = sizeof(OBJ_NAME_PATH_SEPARATOR);
|
2006-06-05 00:16:14 +00:00
|
|
|
}
|
|
|
|
else
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Get the Object Directory and add name of Object */
|
|
|
|
ParentDirectory = LocalInfo->Directory;
|
|
|
|
NameSize = sizeof(OBJ_NAME_PATH_SEPARATOR) + LocalInfo->Name.Length;
|
|
|
|
|
|
|
|
/* Loop inside the directory to get the top-most one (meaning root) */
|
2006-06-05 00:16:14 +00:00
|
|
|
while ((ParentDirectory != NameSpaceRoot) && (ParentDirectory))
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Get the Name Information */
|
2006-06-05 00:16:14 +00:00
|
|
|
LocalInfo = OBJECT_HEADER_TO_NAME_INFO(
|
|
|
|
OBJECT_TO_OBJECT_HEADER(ParentDirectory));
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Add the size of the Directory Name */
|
2006-06-05 00:16:14 +00:00
|
|
|
if (LocalInfo && LocalInfo->Directory)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Size of the '\' string + Directory Name */
|
2006-06-05 00:16:14 +00:00
|
|
|
NameSize += sizeof(OBJ_NAME_PATH_SEPARATOR) +
|
|
|
|
LocalInfo->Name.Length;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Move to next parent Directory */
|
|
|
|
ParentDirectory = LocalInfo->Directory;
|
2006-06-05 00:16:14 +00:00
|
|
|
}
|
|
|
|
else
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Directory with no name. We append "...\" */
|
|
|
|
NameSize += sizeof(L"...") + sizeof(OBJ_NAME_PATH_SEPARATOR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, add the name of the structure and the null char */
|
2006-06-05 00:16:14 +00:00
|
|
|
*ReturnLength = NameSize +
|
|
|
|
sizeof(OBJECT_NAME_INFORMATION) +
|
|
|
|
sizeof(UNICODE_NULL);
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Check if we were given enough space */
|
2006-06-05 00:16:14 +00:00
|
|
|
if (*ReturnLength > Length) return STATUS_INFO_LENGTH_MISMATCH;
|
2006-05-24 22:07:11 +00:00
|
|
|
|
2006-06-05 00:16:14 +00:00
|
|
|
/*
|
2006-05-24 22:07:11 +00:00
|
|
|
* Now we will actually create the name. We work backwards because
|
|
|
|
* it's easier to start off from the Name we have and walk up the
|
|
|
|
* parent directories. We use the same logic as Name Length calculation.
|
|
|
|
*/
|
2006-05-25 20:14:09 +00:00
|
|
|
LocalInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
|
2006-05-24 22:07:11 +00:00
|
|
|
ObjectName = (PWCH)((ULONG_PTR)ObjectNameInfo + *ReturnLength);
|
|
|
|
*--ObjectName = UNICODE_NULL;
|
|
|
|
|
2006-06-05 00:16:14 +00:00
|
|
|
/* Check if the object is actually the Root directory */
|
|
|
|
if (Object == NameSpaceRoot)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* This is already the Root Directory, return "\\" */
|
|
|
|
*--ObjectName = OBJ_NAME_PATH_SEPARATOR;
|
|
|
|
ObjectNameInfo->Name.Length = (USHORT)NameSize;
|
2006-06-05 00:16:14 +00:00
|
|
|
ObjectNameInfo->Name.MaximumLength = (USHORT)(NameSize +
|
|
|
|
sizeof(UNICODE_NULL));
|
2006-05-24 22:07:11 +00:00
|
|
|
ObjectNameInfo->Name.Buffer = ObjectName;
|
|
|
|
return STATUS_SUCCESS;
|
2006-06-05 00:16:14 +00:00
|
|
|
}
|
|
|
|
else
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Start by adding the Object's Name */
|
2006-06-05 00:16:14 +00:00
|
|
|
ObjectName = (PWCH)((ULONG_PTR)ObjectName -
|
|
|
|
LocalInfo->Name.Length);
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(ObjectName,
|
2006-06-05 00:16:14 +00:00
|
|
|
LocalInfo->Name.Buffer,
|
|
|
|
LocalInfo->Name.Length);
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Now parse the Parent directories until we reach the top */
|
|
|
|
ParentDirectory = LocalInfo->Directory;
|
2006-06-05 00:16:14 +00:00
|
|
|
while ((ParentDirectory != NameSpaceRoot) && (ParentDirectory))
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Get the name information */
|
2006-06-05 00:16:14 +00:00
|
|
|
LocalInfo = OBJECT_HEADER_TO_NAME_INFO(
|
|
|
|
OBJECT_TO_OBJECT_HEADER(ParentDirectory));
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Add the "\" */
|
|
|
|
*(--ObjectName) = OBJ_NAME_PATH_SEPARATOR;
|
|
|
|
|
|
|
|
/* Add the Parent Directory's Name */
|
2006-06-05 00:16:14 +00:00
|
|
|
if (LocalInfo && LocalInfo->Name.Buffer)
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Add the name */
|
2006-06-05 00:16:14 +00:00
|
|
|
ObjectName = (PWCH)((ULONG_PTR)ObjectName -
|
|
|
|
LocalInfo->Name.Length);
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(ObjectName,
|
2006-06-05 00:16:14 +00:00
|
|
|
LocalInfo->Name.Buffer,
|
|
|
|
LocalInfo->Name.Length);
|
2006-05-24 22:07:11 +00:00
|
|
|
|
|
|
|
/* Move to next parent */
|
|
|
|
ParentDirectory = LocalInfo->Directory;
|
2006-06-05 00:16:14 +00:00
|
|
|
}
|
|
|
|
else
|
2006-05-24 22:07:11 +00:00
|
|
|
{
|
|
|
|
/* Directory without a name, we add "..." */
|
|
|
|
ObjectName -= sizeof(L"...");
|
|
|
|
ObjectName = L"...";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add Root Directory Name */
|
|
|
|
*(--ObjectName) = OBJ_NAME_PATH_SEPARATOR;
|
|
|
|
ObjectNameInfo->Name.Length = (USHORT)NameSize;
|
2006-06-05 00:16:14 +00:00
|
|
|
ObjectNameInfo->Name.MaximumLength = (USHORT)(NameSize +
|
|
|
|
sizeof(UNICODE_NULL));
|
2006-05-24 22:07:11 +00:00
|
|
|
ObjectNameInfo->Name.Buffer = ObjectName;
|
|
|
|
}
|
|
|
|
|
2006-06-05 00:16:14 +00:00
|
|
|
/* Return success */
|
2006-05-24 22:07:11 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ObQueryDeviceMapInformation(IN PEPROCESS Process,
|
|
|
|
IN PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo)
|
|
|
|
{
|
|
|
|
//KIRQL OldIrql ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: This is an ugly hack for now, to always return the System Device Map
|
|
|
|
* instead of returning the Process Device Map. Not important yet since we don't use it
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* FIXME: Acquire the DeviceMap Spinlock */
|
|
|
|
// KeAcquireSpinLock(DeviceMap->Lock, &OldIrql);
|
|
|
|
|
|
|
|
/* Make a copy */
|
|
|
|
DeviceMapInfo->Query.DriveMap = ObSystemDeviceMap->DriveMap;
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(DeviceMapInfo->Query.DriveType,
|
2006-05-24 22:07:11 +00:00
|
|
|
ObSystemDeviceMap->DriveType,
|
|
|
|
sizeof(ObSystemDeviceMap->DriveType));
|
|
|
|
|
|
|
|
/* FIXME: Release the DeviceMap Spinlock */
|
|
|
|
// KeReleasepinLock(DeviceMap->Lock, OldIrql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|