Respect OBJ_OPENIF flag in ObCreateObject
[reactos.git] / reactos / ntoskrnl / ob / namespc.c
index 5e8525f..99a635c 100644 (file)
@@ -1,30 +1,19 @@
-/* $Id: namespc.c,v 1.35 2002/11/10 13:36:15 robd Exp $
+/* $Id$
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
  * FILE:           ntoskrnl/ob/namespc.c
  * PURPOSE:        Manages the system namespace
- * PROGRAMMER:     David Welch (welch@mcmail.com)
- * UPDATE HISTORY:
- *                 22/05/98: Created
+ * 
+ * PROGRAMMERS:    David Welch (welch@mcmail.com)
  */
 
 /* INCLUDES ***************************************************************/
 
-#ifdef WIN32_REGDBG
-#include "cm_win32.h"
-#else
-
-#include <limits.h>
-#include <ddk/ntddk.h>
-#include <internal/ob.h>
-#include <internal/io.h>
-#include <internal/pool.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
-#endif
 
 /* GLOBALS ****************************************************************/
 
@@ -32,6 +21,8 @@ POBJECT_TYPE ObDirectoryType = NULL;
 POBJECT_TYPE ObTypeObjectType = NULL;
 
 PDIRECTORY_OBJECT NameSpaceRoot = 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,
@@ -46,7 +37,10 @@ static GENERIC_MAPPING ObpTypeMapping = {
        0x000F0001};
 
 /* FUNCTIONS **************************************************************/
-#ifndef WIN32_REGDBG
+
+/*
+ * @implemented
+ */
 NTSTATUS STDCALL
 ObReferenceObjectByName(PUNICODE_STRING ObjectPath,
                        ULONG Attributes,
@@ -61,10 +55,12 @@ ObReferenceObjectByName(PUNICODE_STRING ObjectPath,
    UNICODE_STRING RemainingPath;
    OBJECT_ATTRIBUTES ObjectAttributes;
    NTSTATUS Status;
+   
+   PAGED_CODE();
 
    InitializeObjectAttributes(&ObjectAttributes,
                              ObjectPath,
-                             Attributes,
+                             Attributes | OBJ_OPENIF,
                              NULL,
                              NULL);
    Status = ObFindObject(&ObjectAttributes,
@@ -84,13 +80,13 @@ CHECKPOINT;
 DPRINT("Object %p\n", Object);
        *ObjectPtr = NULL;
        RtlFreeUnicodeString (&RemainingPath);
-       return(STATUS_UNSUCCESSFUL);
+       return(STATUS_OBJECT_NAME_NOT_FOUND);
      }
    *ObjectPtr = Object;
    RtlFreeUnicodeString (&RemainingPath);
    return(STATUS_SUCCESS);
 }
-#endif // WIN32_REGDBG
+
 
 /**********************************************************************
  * NAME                                                        EXPORTED
@@ -117,6 +113,8 @@ DPRINT("Object %p\n", Object);
  *
  * RETURN VALUE
  *     Status.
+ *
+ * @implemented
  */
 NTSTATUS STDCALL
 ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
@@ -130,6 +128,8 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
    UNICODE_STRING RemainingPath;
    PVOID Object = NULL;
    NTSTATUS Status;
+   
+   PAGED_CODE();
 
    DPRINT("ObOpenObjectByName(...)\n");
 
@@ -139,6 +139,7 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
                         ObjectType);
    if (!NT_SUCCESS(Status))
      {
+       DPRINT("ObFindObject() failed (Status %lx)\n", Status);
        return Status;
      }
 
@@ -161,7 +162,29 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
    return Status;
 }
 
-
+VOID
+STDCALL
+ObQueryDeviceMapInformation(PEPROCESS Process,
+                           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;
+        RtlMoveMemory(DeviceMapInfo->Query.DriveType, ObSystemDeviceMap->DriveType, sizeof(ObSystemDeviceMap->DriveType));
+        
+        /* FIXME: Release the DeviceMap Spinlock */
+        // KeReleasepinLock(DeviceMap->Lock, OldIrql);
+}       
+        
 VOID
 ObpAddEntryDirectory(PDIRECTORY_OBJECT Parent,
                     POBJECT_HEADER Header,
@@ -176,7 +199,7 @@ ObpAddEntryDirectory(PDIRECTORY_OBJECT Parent,
 {
   KIRQL oldlvl;
 
-  RtlCreateUnicodeString(&Header->Name, Name);
+  RtlpCreateUnicodeString(&Header->Name, Name, NonPagedPool);
   Header->Parent = Parent;
 
   KeAcquireSpinLock(&Parent->Lock, &oldlvl);
@@ -184,6 +207,7 @@ ObpAddEntryDirectory(PDIRECTORY_OBJECT Parent,
   KeReleaseSpinLock(&Parent->Lock, oldlvl);
 }
 
+
 VOID
 ObpRemoveEntryDirectory(POBJECT_HEADER Header)
 /*
@@ -201,6 +225,7 @@ ObpRemoveEntryDirectory(POBJECT_HEADER Header)
   KeReleaseSpinLock(&(Header->Parent->Lock),oldlvl);
 }
 
+
 PVOID
 ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject,
                      PWSTR Name,
@@ -249,6 +274,7 @@ ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject,
    return(NULL);
 }
 
+
 NTSTATUS STDCALL
 ObpParseDirectory(PVOID Object,
                  PVOID * NextObject,
@@ -256,56 +282,61 @@ ObpParseDirectory(PVOID Object,
                  PWSTR * Path,
                  ULONG Attributes)
 {
-   PWSTR end;
-   PVOID FoundObject;
-   
-   DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %S)\n",
-         Object,Path,*Path);
-   
-   *NextObject = NULL;
-   
-   if ((*Path) == NULL)
-     {
-       return STATUS_UNSUCCESSFUL;
-     }
-   
-   end = wcschr((*Path)+1, '\\');
-   if (end != NULL)
-     {
-       *end = 0;
-     }
-   
-   FoundObject = ObpFindEntryDirectory(Object, (*Path)+1, Attributes);
-   
-   if (FoundObject == NULL)
-     {
-       if (end != NULL)
-         {
-            *end = '\\';
-         }
-       return STATUS_UNSUCCESSFUL;
-     }
-   
-   ObReferenceObjectByPointer(FoundObject,
-                             STANDARD_RIGHTS_REQUIRED,
-                             NULL,
-                             UserMode);
-   
-   if (end != NULL)
-     {
-       *end = '\\';
-       *Path = end;
-     }
-   else
-     {
-       *Path = NULL;
-     }
-   
-   *NextObject = FoundObject;
-   
-   return STATUS_SUCCESS;
+  PWSTR Start;
+  PWSTR End;
+  PVOID FoundObject;
+
+  DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %S)\n",
+        Object,Path,*Path);
+
+  *NextObject = NULL;
+
+  if ((*Path) == NULL)
+    {
+      return STATUS_UNSUCCESSFUL;
+    }
+
+  Start = *Path;
+  if (*Start == L'\\')
+    Start++;
+
+  End = wcschr(Start, L'\\');
+  if (End != NULL)
+    {
+      *End = 0;
+    }
+
+  FoundObject = ObpFindEntryDirectory(Object, Start, Attributes);
+  if (FoundObject == NULL)
+    {
+      if (End != NULL)
+       {
+         *End = L'\\';
+       }
+      return STATUS_UNSUCCESSFUL;
+    }
+
+  ObReferenceObjectByPointer(FoundObject,
+                            STANDARD_RIGHTS_REQUIRED,
+                            NULL,
+                            UserMode);
+
+  if (End != NULL)
+    {
+      *End = L'\\';
+      *Path = End;
+    }
+  else
+    {
+      *Path = NULL;
+    }
+
+  *NextObject = FoundObject;
+
+  return STATUS_SUCCESS;
 }
 
+
 NTSTATUS STDCALL
 ObpCreateDirectory(PVOID ObjectBody,
                   PVOID Parent,
@@ -329,7 +360,7 @@ ObpCreateDirectory(PVOID ObjectBody,
 }
 
 
-VOID
+VOID INIT_FUNCTION
 ObInit(VOID)
 /*
  * FUNCTION: Initialize the object manager namespace
@@ -337,6 +368,10 @@ ObInit(VOID)
 {
   OBJECT_ATTRIBUTES ObjectAttributes;
   UNICODE_STRING Name;
+  SECURITY_DESCRIPTOR SecurityDescriptor;
+
+  /* Initialize the security descriptor cache */
+  ObpInitSdCache();
 
   /* create 'directory' object type */
   ObDirectoryType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
@@ -344,8 +379,8 @@ ObInit(VOID)
   ObDirectoryType->Tag = TAG('D', 'I', 'R', 'T');
   ObDirectoryType->TotalObjects = 0;
   ObDirectoryType->TotalHandles = 0;
-  ObDirectoryType->MaxObjects = ULONG_MAX;
-  ObDirectoryType->MaxHandles = ULONG_MAX;
+  ObDirectoryType->PeakObjects = 0;
+  ObDirectoryType->PeakHandles = 0;
   ObDirectoryType->PagedPoolCharge = 0;
   ObDirectoryType->NonpagedPoolCharge = sizeof(DIRECTORY_OBJECT);
   ObDirectoryType->Mapping = &ObpDirectoryMapping;
@@ -359,8 +394,8 @@ ObInit(VOID)
   ObDirectoryType->OkayToClose = NULL;
   ObDirectoryType->Create = ObpCreateDirectory;
   ObDirectoryType->DuplicationNotify = NULL;
-  
-  RtlInitUnicodeStringFromLiteral(&ObDirectoryType->TypeName,
+
+  RtlInitUnicodeString(&ObDirectoryType->TypeName,
                       L"Directory");
 
   /* create 'type' object type*/
@@ -369,8 +404,8 @@ ObInit(VOID)
   ObTypeObjectType->Tag = TAG('T', 'y', 'p', 'T');
   ObTypeObjectType->TotalObjects = 0;
   ObTypeObjectType->TotalHandles = 0;
-  ObTypeObjectType->MaxObjects = ULONG_MAX;
-  ObTypeObjectType->MaxHandles = ULONG_MAX;
+  ObTypeObjectType->PeakObjects = 0;
+  ObTypeObjectType->PeakHandles = 0;
   ObTypeObjectType->PagedPoolCharge = 0;
   ObTypeObjectType->NonpagedPoolCharge = sizeof(TYPE_OBJECT);
   ObTypeObjectType->Mapping = &ObpTypeMapping;
@@ -384,33 +419,70 @@ ObInit(VOID)
   ObTypeObjectType->OkayToClose = NULL;
   ObTypeObjectType->Create = NULL;
   ObTypeObjectType->DuplicationNotify = NULL;
-  
-  RtlInitUnicodeStringFromLiteral(&ObTypeObjectType->TypeName,
+
+  RtlInitUnicodeString(&ObTypeObjectType->TypeName,
                       L"ObjectType");
 
-  /* create root directory */
-  ObCreateObject(NULL,
-                STANDARD_RIGHTS_REQUIRED,
-                NULL,
+  /* Create security descriptor */
+  RtlCreateSecurityDescriptor(&SecurityDescriptor,
+                             SECURITY_DESCRIPTOR_REVISION1);
+
+  RtlSetOwnerSecurityDescriptor(&SecurityDescriptor,
+                               SeAliasAdminsSid,
+                               FALSE);
+
+  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 */
-  RtlInitUnicodeStringFromLiteral(&Name,
+  /* Create '\ObjectTypes' directory */
+  RtlRosInitUnicodeStringFromLiteral(&Name,
                       L"\\ObjectTypes");
   InitializeObjectAttributes(&ObjectAttributes,
                             &Name,
                             OBJ_PERMANENT,
                             NULL,
-                            NULL);
-  ObCreateObject(NULL,
-                STANDARD_RIGHTS_REQUIRED,
-                &ObjectAttributes,
+                            &SecurityDescriptor);
+  ObCreateObject(KernelMode,
                 ObDirectoryType,
+                &ObjectAttributes,
+                KernelMode,
+                NULL,
+                sizeof(DIRECTORY_OBJECT),
+                0,
+                0,
                 NULL);
 
   ObpCreateTypeObject(ObDirectoryType);
   ObpCreateTypeObject(ObTypeObjectType);
+
+  /* Create 'symbolic link' object type */
+  ObInitSymbolicLinkImplementation();
+  
+  /* FIXME: Hack Hack! */
+  ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool, sizeof(*ObSystemDeviceMap), TAG('O', 'b', 'D', 'm'));
+  RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
 }
 
 
@@ -434,10 +506,14 @@ ObpCreateTypeObject(POBJECT_TYPE ObjectType)
                             OBJ_PERMANENT,
                             NULL,
                             NULL);
-  Status = ObCreateObject(NULL,
-                         STANDARD_RIGHTS_REQUIRED,
-                         &ObjectAttributes,
+  Status = ObCreateObject(KernelMode,
                          ObTypeObjectType,
+                         &ObjectAttributes,
+                         KernelMode,
+                         NULL,
+                         sizeof(TYPE_OBJECT),
+                         0,
+                         0,
                          (PVOID*)&TypeObject);
   if (NT_SUCCESS(Status))
     {
@@ -447,5 +523,4 @@ ObpCreateTypeObject(POBJECT_TYPE ObjectType)
   return(STATUS_SUCCESS);
 }
 
-
 /* EOF */