Properly create the Object Type Type and remove previous hacks added

svn path=/trunk/; revision=15319
This commit is contained in:
Alex Ionescu 2005-05-15 19:40:57 +00:00
parent cf6037ee37
commit 19ea176f6d
3 changed files with 207 additions and 224 deletions

View file

@ -115,16 +115,6 @@ typedef struct _SYMLINK_OBJECT
LARGE_INTEGER CreateTime;
} SYMLINK_OBJECT, *PSYMLINK_OBJECT;
typedef struct _TYPE_OBJECT
{
CSHORT Type;
CSHORT Size;
/* pointer to object type data */
POBJECT_TYPE ObjectType;
} TYPE_OBJECT, *PTYPE_OBJECT;
/*
* Enumeration of object types
*/
@ -197,6 +187,7 @@ ObpSetHandleAttributes(HANDLE Handle,
POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo);
NTSTATUS
STDCALL
ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
PUNICODE_STRING TypeName,
POBJECT_TYPE *ObjectType);

View file

@ -21,9 +21,11 @@ POBJECT_TYPE ObDirectoryType = NULL;
POBJECT_TYPE ObTypeObjectType = NULL;
PDIRECTORY_OBJECT NameSpaceRoot = NULL;
PDIRECTORY_OBJECT ObpTypeDirectoryObject = NULL;
/* FIXME: Move this somewhere else once devicemap support is in */
PDEVICE_MAP ObSystemDeviceMap = NULL;
static GENERIC_MAPPING ObpDirectoryMapping = {
STANDARD_RIGHTS_READ|DIRECTORY_QUERY|DIRECTORY_TRAVERSE,
STANDARD_RIGHTS_WRITE|DIRECTORY_CREATE_OBJECT|DIRECTORY_CREATE_SUBDIRECTORY,
@ -36,6 +38,13 @@ static GENERIC_MAPPING ObpTypeMapping = {
STANDARD_RIGHTS_EXECUTE,
0x000F0001};
NTSTATUS
STDCALL
ObpAllocateObject(POBJECT_ATTRIBUTES ObjectAttributes,
POBJECT_TYPE ObjectType,
ULONG ObjectSize,
POBJECT_HEADER *ObjectHeader);
/* FUNCTIONS **************************************************************/
/*
@ -367,193 +376,152 @@ ObpParseDirectory(PVOID Object,
return STATUS_SUCCESS;
}
/* HACKS FOR COMPATIBILITY. TEMPORARY */
NTSTATUS
ObpCreateInitTypeObject(POBJECT_TYPE ObjectType)
{
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR NameString[120];
PTYPE_OBJECT TypeObject = NULL;
UNICODE_STRING Name;
NTSTATUS Status;
DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", &ObjectType->Name);
wcscpy(NameString, L"\\ObjectTypes\\");
wcscat(NameString, ObjectType->Name.Buffer);
RtlInitUnicodeString(&Name,
NameString);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_PERMANENT,
NULL,
NULL);
Status = ObCreateObject(KernelMode,
ObTypeObjectType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(TYPE_OBJECT),
0,
0,
(PVOID*)&TypeObject);
if (NT_SUCCESS(Status))
{
TypeObject->ObjectType = ObjectType;
}
return(STATUS_SUCCESS);
}
VOID INIT_FUNCTION
VOID
INIT_FUNCTION
ObInit(VOID)
/*
* FUNCTION: Initialize the object manager namespace
*/
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name;
SECURITY_DESCRIPTOR SecurityDescriptor;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING Name;
SECURITY_DESCRIPTOR SecurityDescriptor;
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
/* Initialize the security descriptor cache */
ObpInitSdCache();
/* Initialize the security descriptor cache */
ObpInitSdCache();
/* HACKS FOR COMPATIBILITY. TEMPORARY */
/* create 'directory' object type */
ObDirectoryType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
RtlZeroMemory(ObDirectoryType, sizeof(OBJECT_TYPE));
ObDirectoryType->TypeInfo.DefaultNonPagedPoolCharge = sizeof(DIRECTORY_OBJECT);
ObDirectoryType->TypeInfo.GenericMapping = ObpDirectoryMapping;
ObDirectoryType->TypeInfo.ParseProcedure = ObpParseDirectory;
ObDirectoryType->TypeInfo.OpenProcedure = ObpCreateDirectory;
/* Create the Type Type */
DPRINT1("Creating Type Type\n");
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
RtlInitUnicodeString(&Name, L"Type");
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
ObjectTypeInitializer.ValidAccessMask = OBJECT_TYPE_ALL_ACCESS;
ObjectTypeInitializer.UseDefaultObject = TRUE;
ObjectTypeInitializer.MaintainTypeList = TRUE;
ObjectTypeInitializer.PoolType = NonPagedPool;
ObjectTypeInitializer.GenericMapping = ObpTypeMapping;
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(OBJECT_TYPE);
ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ObTypeObjectType);
RtlInitUnicodeString(&ObDirectoryType->Name,
L"Directory");
/* Create the Directory Type */
DPRINT1("Creating Directory Type\n");
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
RtlInitUnicodeString(&Name, L"Directory");
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
ObjectTypeInitializer.ValidAccessMask = DIRECTORY_ALL_ACCESS;
ObjectTypeInitializer.UseDefaultObject = FALSE;
ObjectTypeInitializer.OpenProcedure = ObpCreateDirectory;
ObjectTypeInitializer.ParseProcedure = ObpParseDirectory;
ObjectTypeInitializer.MaintainTypeList = FALSE;
ObjectTypeInitializer.GenericMapping = ObpDirectoryMapping;
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(DIRECTORY_OBJECT);
ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &ObDirectoryType);
/* HACKS FOR COMPATIBILITY. TEMPORARY */
/* create 'type' object type*/
ObTypeObjectType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
RtlZeroMemory(ObTypeObjectType, sizeof(OBJECT_TYPE));
ObTypeObjectType->TypeInfo.DefaultNonPagedPoolCharge = sizeof(TYPE_OBJECT);
ObTypeObjectType->TypeInfo.GenericMapping = ObpTypeMapping;
/* Create security descriptor */
RtlCreateSecurityDescriptor(&SecurityDescriptor,
SECURITY_DESCRIPTOR_REVISION1);
RtlSetOwnerSecurityDescriptor(&SecurityDescriptor,
SeAliasAdminsSid,
FALSE);
RtlSetGroupSecurityDescriptor(&SecurityDescriptor,
SeLocalSystemSid,
FALSE);
RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
TRUE,
SePublicDefaultDacl,
FALSE);
/* Create root directory */
DPRINT1("Creating Root Directory\n");
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_PERMANENT,
NULL,
&SecurityDescriptor);
ObCreateObject(KernelMode,
ObDirectoryType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(DIRECTORY_OBJECT),
0,
0,
(PVOID*)&NameSpaceRoot);
RtlInitUnicodeString(&ObTypeObjectType->Name,
L"ObjectType");
/* Create '\ObjectTypes' directory */
RtlInitUnicodeString(&Name, L"\\ObjectTypes");
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_PERMANENT,
NULL,
&SecurityDescriptor);
ObCreateObject(KernelMode,
ObDirectoryType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(DIRECTORY_OBJECT),
0,
0,
(PVOID*)&ObpTypeDirectoryObject);
/* Create security descriptor */
RtlCreateSecurityDescriptor(&SecurityDescriptor,
SECURITY_DESCRIPTOR_REVISION1);
/* Insert the two objects we already created but couldn't add */
/* NOTE: Uses TypeList & Creator Info in OB 2.0 */
ObpAddEntryDirectory(ObpTypeDirectoryObject, BODY_TO_HEADER(ObTypeObjectType), L"Type");
ObpAddEntryDirectory(ObpTypeDirectoryObject, BODY_TO_HEADER(ObDirectoryType), L"Directory");
RtlSetOwnerSecurityDescriptor(&SecurityDescriptor,
SeAliasAdminsSid,
FALSE);
/* Create 'symbolic link' object type */
ObInitSymbolicLinkImplementation();
RtlSetGroupSecurityDescriptor(&SecurityDescriptor,
SeLocalSystemSid,
FALSE);
RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
TRUE,
SePublicDefaultDacl,
FALSE);
/* Create root directory */
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_PERMANENT,
NULL,
&SecurityDescriptor);
ObCreateObject(KernelMode,
ObDirectoryType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(DIRECTORY_OBJECT),
0,
0,
(PVOID*)&NameSpaceRoot);
/* Create '\ObjectTypes' directory */
RtlRosInitUnicodeStringFromLiteral(&Name,
L"\\ObjectTypes");
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_PERMANENT,
NULL,
&SecurityDescriptor);
ObCreateObject(KernelMode,
ObDirectoryType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(DIRECTORY_OBJECT),
0,
0,
NULL);
/* HACKS FOR COMPATIBILITY. TEMPORARY */
ObpCreateInitTypeObject(ObDirectoryType);
ObpCreateInitTypeObject(ObTypeObjectType);
/* Create 'symbolic link' object type */
ObInitSymbolicLinkImplementation();
/* FIXME: Hack Hack! */
ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm'));
RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
/* FIXME: Hack Hack! */
ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm'));
RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
}
NTSTATUS
STDCALL
ObpCreateTypeObject(POBJECT_TYPE_INITIALIZER ObjectTypeInitializer,
PUNICODE_STRING TypeName,
POBJECT_TYPE *ObjectType)
{
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR NameString[120];
PTYPE_OBJECT TypeObject = NULL;
POBJECT_HEADER Header;
POBJECT_TYPE LocalObjectType;
UNICODE_STRING Name;
NTSTATUS Status;
DPRINT("ObpCreateTypeObject(ObjectType: %wZ)\n", TypeName);
/* Set up the Name */
wcscpy(NameString, L"\\ObjectTypes\\");
wcscat(NameString, TypeName->Buffer);
RtlInitUnicodeString(&Name, NameString);
/* Allocate the Object */
Status = ObpAllocateObject(NULL,
ObTypeObjectType,
OBJECT_ALLOC_SIZE(sizeof(OBJECT_TYPE)),
&Header);
if (!NT_SUCCESS(Status))
{
DPRINT1("ObpAllocateObject failed!\n");
return Status;
}
/* Allocate the Object Type */
LocalObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
LocalObjectType = HEADER_TO_BODY(Header);
/* Check if this is the first Object Type */
if (!ObTypeObjectType)
{
ObTypeObjectType = LocalObjectType;
Header->ObjectType = ObTypeObjectType;
}
/* FIXME: Generate Tag */
/* Set it up */
LocalObjectType->TypeInfo = *ObjectTypeInitializer;
LocalObjectType->Name = *TypeName;
/* FIXME: Generate Tag */
/* Create the Object Type Type (WRONG, it shoudl be OBJECT_TYPE itself!) */
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_PERMANENT,
NULL,
NULL);
Status = ObCreateObject(KernelMode,
ObTypeObjectType,
&ObjectAttributes,
KernelMode,
NULL,
sizeof(TYPE_OBJECT),
0,
0,
(PVOID*)&TypeObject);
if (NT_SUCCESS(Status))
/* Insert it into the Object Directory */
if (ObpTypeDirectoryObject)
{
TypeObject->ObjectType = LocalObjectType;
*ObjectType = LocalObjectType;
ObpAddEntryDirectory(ObpTypeDirectoryObject, Header, TypeName->Buffer);
ObReferenceObject(ObpTypeDirectoryObject);
}
*ObjectType = LocalObjectType;
return Status;
}

View file

@ -637,6 +637,57 @@ ObQueryNameString (IN PVOID Object,
return Status;
}
NTSTATUS
STDCALL
ObpAllocateObject(POBJECT_ATTRIBUTES ObjectAttributes,
POBJECT_TYPE ObjectType,
ULONG ObjectSize,
POBJECT_HEADER *ObjectHeader)
{
POBJECT_HEADER Header;
POOL_TYPE PoolType;
ULONG Tag;
/* If we don't have an Object Type yet, force NonPaged */
DPRINT("ObpAllocateObject\n");
if (!ObjectType)
{
PoolType = NonPagedPool;
Tag = TAG('O', 'b', 'j', 'T');
}
else
{
PoolType = ObjectType->TypeInfo.PoolType;
Tag = ObjectType->Key;
}
/* Allocate memory for the Object */
Header = (POBJECT_HEADER)ExAllocatePoolWithTag(PoolType, ObjectSize, Tag);
if (!Header) {
DPRINT1("Not enough memory!\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Initialize the object header */
RtlZeroMemory(Header, ObjectSize);
DPRINT("Initalizing header %p\n", Header);
Header->HandleCount = 0;
Header->RefCount = 1;
Header->ObjectType = ObjectType;
if (ObjectAttributes && ObjectAttributes->Attributes & OBJ_PERMANENT)
{
Header->Permanent = TRUE;
}
if (ObjectAttributes && ObjectAttributes->Attributes & OBJ_INHERIT)
{
Header->Inherit = TRUE;
}
RtlInitUnicodeString(&Header->Name, NULL);
/* Return Header */
*ObjectHeader = Header;
return STATUS_SUCCESS;
}
/**********************************************************************
* NAME EXPORTED
@ -666,7 +717,7 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
UNICODE_STRING RemainingPath;
POBJECT_HEADER Header;
POBJECT_HEADER ParentHeader = NULL;
NTSTATUS Status = 0;
NTSTATUS Status;
BOOLEAN ObjectAttached = FALSE;
PWCHAR NamePtr;
PSECURITY_DESCRIPTOR NewSecurityDescriptor = NULL;
@ -739,43 +790,16 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
RtlInitUnicodeString(&RemainingPath, NULL);
}
DPRINT("Allocating memory\n");
Header = (POBJECT_HEADER)ExAllocatePoolWithTag(NonPagedPool,
OBJECT_ALLOC_SIZE(ObjectSize),
Type->Key);
if (Header == NULL) {
DPRINT1("Not enough memory!\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(Header, OBJECT_ALLOC_SIZE(ObjectSize));
/* Initialize the object header */
DPRINT("Initalizing header 0x%x (%wZ)\n", Header, &Type->TypeName);
Header->HandleCount = 0;
Header->RefCount = 1;
Header->ObjectType = Type;
if (ObjectAttributes != NULL &&
ObjectAttributes->Attributes & OBJ_PERMANENT)
/* Allocate the Object */
Status = ObpAllocateObject(ObjectAttributes,
Type,
OBJECT_ALLOC_SIZE(ObjectSize),
&Header);
if (!NT_SUCCESS(Status))
{
Header->Permanent = TRUE;
DPRINT1("ObpAllocateObject failed!\n");
return Status;
}
else
{
Header->Permanent = FALSE;
}
if (ObjectAttributes != NULL &&
ObjectAttributes->Attributes & OBJ_INHERIT)
{
Header->Inherit = TRUE;
}
else
{
Header->Inherit = FALSE;
}
RtlInitUnicodeString(&(Header->Name),NULL);
DPRINT("Getting Parent and adding entry\n");
if (ParentHeader != NULL &&