Implement ObGetObjectSecurity() and ObReleaseObjectSecurity().
authorEric Kohl <eric.kohl@reactos.org>
Fri, 23 Jul 2004 21:44:10 +0000 (21:44 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 23 Jul 2004 21:44:10 +0000 (21:44 +0000)
svn path=/trunk/; revision=10264

reactos/ntoskrnl/include/internal/ob.h
reactos/ntoskrnl/ob/sdcache.c
reactos/ntoskrnl/ob/security.c

index e6184dc..0078396 100644 (file)
@@ -149,5 +149,11 @@ ObpAddSecurityDescriptor(IN PSECURITY_DESCRIPTOR SourceSD,
 NTSTATUS
 ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
 
+VOID
+ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
+
+VOID
+ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
+
 
 #endif /* __INCLUDE_INTERNAL_OBJMGR_H */
index 0b26490..6b95e5a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: sdcache.c,v 1.1 2004/07/16 17:19:15 ekohl Exp $
+/* $Id: sdcache.c,v 1.2 2004/07/23 21:44:10 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -309,4 +309,35 @@ ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
   return STATUS_SUCCESS;
 }
 
+
+VOID
+ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+  PSD_CACHE_ENTRY CacheEntry;
+
+  DPRINT("ObpReferenceCachedSecurityDescriptor() called\n");
+
+  ObpSdCacheLock();
+
+  CacheEntry = (PSD_CACHE_ENTRY)((ULONG_PTR)SecurityDescriptor - sizeof(SD_CACHE_ENTRY));
+
+  CacheEntry->RefCount++;
+  DPRINT("RefCount %lu\n", CacheEntry->RefCount);
+
+  ObpSdCacheUnlock();
+
+  DPRINT("ObpReferenceCachedSecurityDescriptor() done\n");
+}
+
+
+VOID
+ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+  DPRINT("ObpDereferenceCachedSecurityDescriptor() called\n");
+
+  ObpRemoveSecurityDescriptor(SecurityDescriptor);
+
+  DPRINT("ObpDereferenceCachedSecurityDescriptor() done\n");
+}
+
 /* EOF */
index 1aeff4d..dca9187 100644 (file)
@@ -64,26 +64,83 @@ ObAssignSecurity(IN PACCESS_STATE AccessState,
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS STDCALL
 ObGetObjectSecurity(IN PVOID Object,
                    OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
                    OUT PBOOLEAN MemoryAllocated)
 {
-  UNIMPLEMENTED;
-  return(STATUS_NOT_IMPLEMENTED);
+  POBJECT_HEADER Header;
+  ULONG Length;
+  NTSTATUS Status;
+
+  Header = BODY_TO_HEADER(Object);
+  if (Header->ObjectType == NULL)
+    return STATUS_UNSUCCESSFUL;
+
+  if (Header->ObjectType->Security == NULL)
+    {
+      ObpReferenceCachedSecurityDescriptor(Header->SecurityDescriptor);
+      *SecurityDescriptor = Header->SecurityDescriptor;
+      *MemoryAllocated = FALSE;
+      return STATUS_SUCCESS;
+    }
+
+  /* Get the security descriptor size */
+  Length = 0;
+  Status = Header->ObjectType->Security(Object,
+                                       QuerySecurityDescriptor,
+                                       OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
+                                       DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
+                                       NULL,
+                                       &Length);
+  if (Status != STATUS_BUFFER_TOO_SMALL)
+    return Status;
+
+  /* Allocate security descriptor */
+  *SecurityDescriptor = ExAllocatePool(NonPagedPool,
+                                      Length);
+  if (*SecurityDescriptor == NULL)
+    return STATUS_INSUFFICIENT_RESOURCES;
+
+  /* Query security descriptor */
+  Status = Header->ObjectType->Security(Object,
+                                       QuerySecurityDescriptor,
+                                       OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
+                                       DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
+                                       *SecurityDescriptor,
+                                       &Length);
+  if (!NT_SUCCESS(Status))
+    {
+      ExFreePool(*SecurityDescriptor);
+      return Status;
+    }
+
+  *MemoryAllocated = TRUE;
+
+  return STATUS_SUCCESS;
 }
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 VOID STDCALL
 ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
                        IN BOOLEAN MemoryAllocated)
 {
-  UNIMPLEMENTED;
+  if (SecurityDescriptor == NULL)
+    return;
+
+  if (MemoryAllocated)
+    {
+      ExFreePool(SecurityDescriptor);
+    }
+  else
+    {
+      ObpDereferenceCachedSecurityDescriptor(SecurityDescriptor);
+    }
 }
 
 
@@ -109,12 +166,14 @@ NtQuerySecurityObject(IN HANDLE Handle,
                                     NULL);
   if (!NT_SUCCESS(Status))
     {
-      return(Status);
+      return Status;
     }
 
   Header = BODY_TO_HEADER(Object);
-  if (Header->ObjectType == NULL &&
-      Header->ObjectType->Security != NULL)
+  if (Header->ObjectType == NULL)
+    return STATUS_UNSUCCESSFUL;
+
+  if (Header->ObjectType->Security != NULL)
     {
       Status = Header->ObjectType->Security(Object,
                                            QuerySecurityDescriptor,