Add missing processor architecture cases
[reactos.git] / reactos / ntoskrnl / se / sd.c
index 8e61acc..651defd 100644 (file)
 #include <ntoskrnl.h>
 #include <internal/debug.h>
 
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, SepInitSDs)
+#endif
+
+
 /* GLOBALS ******************************************************************/
 
 PSECURITY_DESCRIPTOR SePublicDefaultSd = NULL;
@@ -24,12 +29,14 @@ PSECURITY_DESCRIPTOR SeUnrestrictedSd = NULL;
 
 /* FUNCTIONS ***************************************************************/
 
-BOOLEAN INIT_FUNCTION
+BOOLEAN
+INIT_FUNCTION
+NTAPI
 SepInitSDs(VOID)
 {
   /* Create PublicDefaultSd */
-  SePublicDefaultSd = ExAllocatePool(NonPagedPool,
-                                    sizeof(SECURITY_DESCRIPTOR));
+  SePublicDefaultSd = ExAllocatePoolWithTag(PagedPool,
+                                    sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SePublicDefaultSd == NULL)
     return FALSE;
 
@@ -41,8 +48,8 @@ SepInitSDs(VOID)
                               FALSE);
 
   /* Create PublicDefaultUnrestrictedSd */
-  SePublicDefaultUnrestrictedSd = ExAllocatePool(NonPagedPool,
-                                                sizeof(SECURITY_DESCRIPTOR));
+  SePublicDefaultUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
+                                                sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SePublicDefaultUnrestrictedSd == NULL)
     return FALSE;
 
@@ -54,8 +61,8 @@ SepInitSDs(VOID)
                               FALSE);
 
   /* Create PublicOpenSd */
-  SePublicOpenSd = ExAllocatePool(NonPagedPool,
-                                 sizeof(SECURITY_DESCRIPTOR));
+  SePublicOpenSd = ExAllocatePoolWithTag(PagedPool,
+                                 sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SePublicOpenSd == NULL)
     return FALSE;
 
@@ -67,8 +74,8 @@ SepInitSDs(VOID)
                               FALSE);
 
   /* Create PublicOpenUnrestrictedSd */
-  SePublicOpenUnrestrictedSd = ExAllocatePool(NonPagedPool,
-                                             sizeof(SECURITY_DESCRIPTOR));
+  SePublicOpenUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
+                                             sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SePublicOpenUnrestrictedSd == NULL)
     return FALSE;
 
@@ -80,8 +87,8 @@ SepInitSDs(VOID)
                               FALSE);
 
   /* Create SystemDefaultSd */
-  SeSystemDefaultSd = ExAllocatePool(NonPagedPool,
-                                    sizeof(SECURITY_DESCRIPTOR));
+  SeSystemDefaultSd = ExAllocatePoolWithTag(PagedPool,
+                                    sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SeSystemDefaultSd == NULL)
     return FALSE;
 
@@ -93,8 +100,8 @@ SepInitSDs(VOID)
                               FALSE);
 
   /* Create UnrestrictedSd */
-  SeUnrestrictedSd = ExAllocatePool(NonPagedPool,
-                                   sizeof(SECURITY_DESCRIPTOR));
+  SeUnrestrictedSd = ExAllocatePoolWithTag(PagedPool,
+                                   sizeof(SECURITY_DESCRIPTOR), TAG_SD);
   if (SeUnrestrictedSd == NULL)
     return FALSE;
 
@@ -111,7 +118,7 @@ SepInitSDs(VOID)
 NTSTATUS
 STDCALL
 SeSetWorldSecurityDescriptor(SECURITY_INFORMATION SecurityInformation,
-                             PSECURITY_DESCRIPTOR SecurityDescriptor,
+                             PISECURITY_DESCRIPTOR SecurityDescriptor,
                              PULONG BufferLength)
 {
   ULONG_PTR Current;
@@ -180,6 +187,7 @@ SeSetWorldSecurityDescriptor(SECURITY_INFORMATION SecurityInformation,
 
 
 NTSTATUS
+NTAPI
 SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
                                    IN KPROCESSOR_MODE AccessMode,
                                    IN POOL_TYPE PoolType,
@@ -331,6 +339,7 @@ SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIO
 
 
 VOID
+NTAPI
 SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecurityQualityOfService  OPTIONAL,
                                    IN KPROCESSOR_MODE AccessMode,
                                    IN BOOLEAN CaptureIfKernel)
@@ -338,7 +347,7 @@ SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecur
   PAGED_CODE();
 
   if(CapturedSecurityQualityOfService != NULL &&
-     (AccessMode == UserMode ||
+     (AccessMode != KernelMode ||
       (AccessMode == KernelMode && CaptureIfKernel)))
   {
     ExFreePool(CapturedSecurityQualityOfService);
@@ -352,15 +361,16 @@ SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecur
 NTSTATUS
 STDCALL
 SeCaptureSecurityDescriptor(
-       IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor,
+       IN PSECURITY_DESCRIPTOR _OriginalSecurityDescriptor,
        IN KPROCESSOR_MODE CurrentMode,
        IN POOL_TYPE PoolType,
        IN BOOLEAN CaptureIfKernel,
        OUT PSECURITY_DESCRIPTOR *CapturedSecurityDescriptor
        )
 {
+  PISECURITY_DESCRIPTOR OriginalSecurityDescriptor = _OriginalSecurityDescriptor;
   SECURITY_DESCRIPTOR DescriptorCopy;
-  PSECURITY_DESCRIPTOR NewDescriptor;
+  PISECURITY_DESCRIPTOR NewDescriptor;
   ULONG OwnerSAC = 0, GroupSAC = 0;
   ULONG OwnerSize = 0, GroupSize = 0;
   ULONG SaclSize = 0, DaclSize = 0;
@@ -404,7 +414,7 @@ SeCaptureSecurityDescriptor(
                      sizeof(ULONG));
         if(DescriptorCopy.Control & SE_SELF_RELATIVE)
         {
-          PSECURITY_DESCRIPTOR_RELATIVE RelSD = (PSECURITY_DESCRIPTOR_RELATIVE)OriginalSecurityDescriptor;
+          PISECURITY_DESCRIPTOR_RELATIVE RelSD = (PISECURITY_DESCRIPTOR_RELATIVE)OriginalSecurityDescriptor;
 
           DescriptorCopy.Owner = (PSID)RelSD->Owner;
           DescriptorCopy.Group = (PSID)RelSD->Group;
@@ -455,7 +465,7 @@ SeCaptureSecurityDescriptor(
                         sizeof(SECURITY_DESCRIPTOR_RELATIVE) : sizeof(SECURITY_DESCRIPTOR));
       if(DescriptorCopy.Control & SE_SELF_RELATIVE)
       {
-        PSECURITY_DESCRIPTOR_RELATIVE RelSD = (PSECURITY_DESCRIPTOR_RELATIVE)OriginalSecurityDescriptor;
+        PISECURITY_DESCRIPTOR_RELATIVE RelSD = (PISECURITY_DESCRIPTOR_RELATIVE)OriginalSecurityDescriptor;
 
         DescriptorCopy.Owner = (PSID)RelSD->Owner;
         DescriptorCopy.Group = (PSID)RelSD->Group;
@@ -604,6 +614,7 @@ SeCaptureSecurityDescriptor(
     {
       ULONG_PTR Offset = sizeof(SECURITY_DESCRIPTOR);
 
+      RtlZeroMemory(NewDescriptor, DescriptorSize);
       NewDescriptor->Revision = DescriptorCopy.Revision;
       NewDescriptor->Sbz1 = DescriptorCopy.Sbz1;
       NewDescriptor->Control = DescriptorCopy.Control | SE_SELF_RELATIVE;
@@ -673,8 +684,8 @@ SeQuerySecurityDescriptorInfo(IN PSECURITY_INFORMATION SecurityInformation,
                              IN OUT PULONG Length,
                              IN PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor OPTIONAL)
 {
-  PSECURITY_DESCRIPTOR ObjectSd;
-  PSECURITY_DESCRIPTOR_RELATIVE RelSD;
+  PISECURITY_DESCRIPTOR ObjectSd;
+  PISECURITY_DESCRIPTOR_RELATIVE RelSD;
   PSID Owner = NULL;
   PSID Group = NULL;
   PACL Dacl = NULL;
@@ -687,7 +698,7 @@ SeQuerySecurityDescriptorInfo(IN PSECURITY_INFORMATION SecurityInformation,
   ULONG_PTR Current;
   ULONG SdLength;
 
-  RelSD = (PSECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
+  RelSD = (PISECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
 
   if (*ObjectsSecurityDescriptor == NULL)
     {
@@ -818,7 +829,7 @@ SeReleaseSecurityDescriptor(
               and CaptureIfKernelMode that you previously passed to
               SeCaptureSecurityDescriptor() in order to avoid memory leaks! */
   if(CapturedSecurityDescriptor != NULL &&
-     (CurrentMode == UserMode ||
+     (CurrentMode != KernelMode ||
       (CurrentMode == KernelMode && CaptureIfKernelMode)))
   {
     /* only delete the descriptor when SeCaptureSecurityDescriptor() allocated one! */
@@ -868,11 +879,12 @@ SeSetSecurityDescriptorInfoEx(
  */
 BOOLEAN STDCALL
 SeValidSecurityDescriptor(IN ULONG Length,
-                         IN PSECURITY_DESCRIPTOR SecurityDescriptor)
+                         IN PSECURITY_DESCRIPTOR _SecurityDescriptor)
 {
   ULONG SdLength;
   PISID Sid;
   PACL Acl;
+  PISECURITY_DESCRIPTOR SecurityDescriptor = _SecurityDescriptor;
 
   if (Length < SECURITY_DESCRIPTOR_MIN_LENGTH)
     {