Implement ObGetObjectSecurity() and ObReleaseObjectSecurity().

svn path=/trunk/; revision=10264
This commit is contained in:
Eric Kohl 2004-07-23 21:44:10 +00:00
parent 23cd7fb231
commit 013e3c728c
3 changed files with 105 additions and 9 deletions

View file

@ -149,5 +149,11 @@ ObpAddSecurityDescriptor(IN PSECURITY_DESCRIPTOR SourceSD,
NTSTATUS NTSTATUS
ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor); ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
VOID
ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
VOID
ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */ #endif /* __INCLUDE_INTERNAL_OBJMGR_H */

View 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -309,4 +309,35 @@ ObpRemoveSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
return STATUS_SUCCESS; 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 */ /* EOF */

View file

@ -64,26 +64,83 @@ ObAssignSecurity(IN PACCESS_STATE AccessState,
/* /*
* @unimplemented * @implemented
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
ObGetObjectSecurity(IN PVOID Object, ObGetObjectSecurity(IN PVOID Object,
OUT PSECURITY_DESCRIPTOR *SecurityDescriptor, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
OUT PBOOLEAN MemoryAllocated) OUT PBOOLEAN MemoryAllocated)
{ {
UNIMPLEMENTED; POBJECT_HEADER Header;
return(STATUS_NOT_IMPLEMENTED); 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 VOID STDCALL
ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
IN BOOLEAN MemoryAllocated) IN BOOLEAN MemoryAllocated)
{ {
UNIMPLEMENTED; if (SecurityDescriptor == NULL)
return;
if (MemoryAllocated)
{
ExFreePool(SecurityDescriptor);
}
else
{
ObpDereferenceCachedSecurityDescriptor(SecurityDescriptor);
}
} }
@ -109,12 +166,14 @@ NtQuerySecurityObject(IN HANDLE Handle,
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(Status); return Status;
} }
Header = BODY_TO_HEADER(Object); Header = BODY_TO_HEADER(Object);
if (Header->ObjectType == NULL && if (Header->ObjectType == NULL)
Header->ObjectType->Security != NULL) return STATUS_UNSUCCESSFUL;
if (Header->ObjectType->Security != NULL)
{ {
Status = Header->ObjectType->Security(Object, Status = Header->ObjectType->Security(Object,
QuerySecurityDescriptor, QuerySecurityDescriptor,