3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/se/sd.c
6 * PURPOSE: Security manager
8 * PROGRAMMERS: David Welch <welch@cwcom.net>
11 /* INCLUDES *****************************************************************/
14 #include <internal/debug.h>
16 /* GLOBALS ******************************************************************/
18 PSECURITY_DESCRIPTOR SePublicDefaultSd
= NULL
;
19 PSECURITY_DESCRIPTOR SePublicDefaultUnrestrictedSd
= NULL
;
20 PSECURITY_DESCRIPTOR SePublicOpenSd
= NULL
;
21 PSECURITY_DESCRIPTOR SePublicOpenUnrestrictedSd
= NULL
;
22 PSECURITY_DESCRIPTOR SeSystemDefaultSd
= NULL
;
23 PSECURITY_DESCRIPTOR SeUnrestrictedSd
= NULL
;
25 /* FUNCTIONS ***************************************************************/
30 /* Create PublicDefaultSd */
31 SePublicDefaultSd
= ExAllocatePool(NonPagedPool
,
32 sizeof(SECURITY_DESCRIPTOR
));
33 if (SePublicDefaultSd
== NULL
)
36 RtlCreateSecurityDescriptor(SePublicDefaultSd
,
37 SECURITY_DESCRIPTOR_REVISION
);
38 RtlSetDaclSecurityDescriptor(SePublicDefaultSd
,
43 /* Create PublicDefaultUnrestrictedSd */
44 SePublicDefaultUnrestrictedSd
= ExAllocatePool(NonPagedPool
,
45 sizeof(SECURITY_DESCRIPTOR
));
46 if (SePublicDefaultUnrestrictedSd
== NULL
)
49 RtlCreateSecurityDescriptor(SePublicDefaultUnrestrictedSd
,
50 SECURITY_DESCRIPTOR_REVISION
);
51 RtlSetDaclSecurityDescriptor(SePublicDefaultUnrestrictedSd
,
53 SePublicDefaultUnrestrictedDacl
,
56 /* Create PublicOpenSd */
57 SePublicOpenSd
= ExAllocatePool(NonPagedPool
,
58 sizeof(SECURITY_DESCRIPTOR
));
59 if (SePublicOpenSd
== NULL
)
62 RtlCreateSecurityDescriptor(SePublicOpenSd
,
63 SECURITY_DESCRIPTOR_REVISION
);
64 RtlSetDaclSecurityDescriptor(SePublicOpenSd
,
69 /* Create PublicOpenUnrestrictedSd */
70 SePublicOpenUnrestrictedSd
= ExAllocatePool(NonPagedPool
,
71 sizeof(SECURITY_DESCRIPTOR
));
72 if (SePublicOpenUnrestrictedSd
== NULL
)
75 RtlCreateSecurityDescriptor(SePublicOpenUnrestrictedSd
,
76 SECURITY_DESCRIPTOR_REVISION
);
77 RtlSetDaclSecurityDescriptor(SePublicOpenUnrestrictedSd
,
79 SePublicOpenUnrestrictedDacl
,
82 /* Create SystemDefaultSd */
83 SeSystemDefaultSd
= ExAllocatePool(NonPagedPool
,
84 sizeof(SECURITY_DESCRIPTOR
));
85 if (SeSystemDefaultSd
== NULL
)
88 RtlCreateSecurityDescriptor(SeSystemDefaultSd
,
89 SECURITY_DESCRIPTOR_REVISION
);
90 RtlSetDaclSecurityDescriptor(SeSystemDefaultSd
,
95 /* Create UnrestrictedSd */
96 SeUnrestrictedSd
= ExAllocatePool(NonPagedPool
,
97 sizeof(SECURITY_DESCRIPTOR
));
98 if (SeUnrestrictedSd
== NULL
)
101 RtlCreateSecurityDescriptor(SeUnrestrictedSd
,
102 SECURITY_DESCRIPTOR_REVISION
);
103 RtlSetDaclSecurityDescriptor(SeUnrestrictedSd
,
113 SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL
,
114 IN KPROCESSOR_MODE AccessMode
,
115 IN POOL_TYPE PoolType
,
116 IN BOOLEAN CaptureIfKernel
,
117 OUT PSECURITY_QUALITY_OF_SERVICE
*CapturedSecurityQualityOfService
,
118 OUT PBOOLEAN Present
)
120 PSECURITY_QUALITY_OF_SERVICE CapturedQos
;
121 NTSTATUS Status
= STATUS_SUCCESS
;
125 ASSERT(CapturedSecurityQualityOfService
);
128 if(ObjectAttributes
!= NULL
)
130 if(AccessMode
!= KernelMode
)
132 SECURITY_QUALITY_OF_SERVICE SafeQos
;
136 ProbeForRead(ObjectAttributes
,
137 sizeof(ObjectAttributes
),
139 if(ObjectAttributes
->Length
== sizeof(OBJECT_ATTRIBUTES
))
141 if(ObjectAttributes
->SecurityQualityOfService
!= NULL
)
143 ProbeForRead(ObjectAttributes
->SecurityQualityOfService
,
144 sizeof(SECURITY_QUALITY_OF_SERVICE
),
147 if(((PSECURITY_QUALITY_OF_SERVICE
)ObjectAttributes
->SecurityQualityOfService
)->Length
==
148 sizeof(SECURITY_QUALITY_OF_SERVICE
))
150 /* don't allocate memory here because ExAllocate should bugcheck
151 the system if it's buggy, SEH would catch that! So make a local
152 copy of the qos structure.*/
153 RtlCopyMemory(&SafeQos
,
154 ObjectAttributes
->SecurityQualityOfService
,
155 sizeof(SECURITY_QUALITY_OF_SERVICE
));
160 Status
= STATUS_INVALID_PARAMETER
;
165 *CapturedSecurityQualityOfService
= NULL
;
171 Status
= STATUS_INVALID_PARAMETER
;
176 Status
= _SEH_GetExceptionCode();
180 if(NT_SUCCESS(Status
))
184 CapturedQos
= ExAllocatePool(PoolType
,
185 sizeof(SECURITY_QUALITY_OF_SERVICE
));
186 if(CapturedQos
!= NULL
)
188 RtlCopyMemory(CapturedQos
,
190 sizeof(SECURITY_QUALITY_OF_SERVICE
));
191 *CapturedSecurityQualityOfService
= CapturedQos
;
195 Status
= STATUS_INSUFFICIENT_RESOURCES
;
200 *CapturedSecurityQualityOfService
= NULL
;
206 if(ObjectAttributes
->Length
== sizeof(OBJECT_ATTRIBUTES
))
210 if(ObjectAttributes
->SecurityQualityOfService
!= NULL
)
212 if(((PSECURITY_QUALITY_OF_SERVICE
)ObjectAttributes
->SecurityQualityOfService
)->Length
==
213 sizeof(SECURITY_QUALITY_OF_SERVICE
))
215 CapturedQos
= ExAllocatePool(PoolType
,
216 sizeof(SECURITY_QUALITY_OF_SERVICE
));
217 if(CapturedQos
!= NULL
)
219 RtlCopyMemory(CapturedQos
,
220 ObjectAttributes
->SecurityQualityOfService
,
221 sizeof(SECURITY_QUALITY_OF_SERVICE
));
222 *CapturedSecurityQualityOfService
= CapturedQos
;
227 Status
= STATUS_INSUFFICIENT_RESOURCES
;
232 Status
= STATUS_INVALID_PARAMETER
;
237 *CapturedSecurityQualityOfService
= NULL
;
243 *CapturedSecurityQualityOfService
= (PSECURITY_QUALITY_OF_SERVICE
)ObjectAttributes
->SecurityQualityOfService
;
244 *Present
= (ObjectAttributes
->SecurityQualityOfService
!= NULL
);
249 Status
= STATUS_INVALID_PARAMETER
;
255 *CapturedSecurityQualityOfService
= NULL
;
264 SepReleaseSecurityQualityOfService(IN PSECURITY_QUALITY_OF_SERVICE CapturedSecurityQualityOfService OPTIONAL
,
265 IN KPROCESSOR_MODE AccessMode
,
266 IN BOOLEAN CaptureIfKernel
)
270 if(CapturedSecurityQualityOfService
!= NULL
&&
271 (AccessMode
== UserMode
||
272 (AccessMode
== KernelMode
&& CaptureIfKernel
)))
274 ExFreePool(CapturedSecurityQualityOfService
);
284 SeCaptureSecurityDescriptor(
285 IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor
,
286 IN KPROCESSOR_MODE CurrentMode
,
287 IN POOL_TYPE PoolType
,
288 IN BOOLEAN CaptureIfKernel
,
289 OUT PSECURITY_DESCRIPTOR
*CapturedSecurityDescriptor
292 SECURITY_DESCRIPTOR DescriptorCopy
;
293 PSECURITY_DESCRIPTOR NewDescriptor
;
294 ULONG OwnerSAC
= 0, GroupSAC
= 0;
295 ULONG OwnerSize
= 0, GroupSize
= 0;
296 ULONG SaclSize
= 0, DaclSize
= 0;
297 ULONG DescriptorSize
= 0;
298 NTSTATUS Status
= STATUS_SUCCESS
;
300 if(OriginalSecurityDescriptor
!= NULL
)
302 if(CurrentMode
!= KernelMode
)
306 /* first only probe and copy until the control field of the descriptor
307 to determine whether it's a self-relative descriptor */
308 DescriptorSize
= (ULONG
)((ULONG_PTR
)&OriginalSecurityDescriptor
->Control
-
309 (ULONG_PTR
)OriginalSecurityDescriptor
) +
310 sizeof(OriginalSecurityDescriptor
->Control
);
311 ProbeForRead(OriginalSecurityDescriptor
,
315 if(OriginalSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
317 Status
= STATUS_UNKNOWN_REVISION
;
321 /* make a copy on the stack */
322 DescriptorCopy
.Revision
= OriginalSecurityDescriptor
->Revision
;
323 DescriptorCopy
.Sbz1
= OriginalSecurityDescriptor
->Sbz1
;
324 DescriptorCopy
.Control
= OriginalSecurityDescriptor
->Control
;
325 DescriptorSize
= ((DescriptorCopy
.Control
& SE_SELF_RELATIVE
) ?
326 sizeof(SECURITY_DESCRIPTOR_RELATIVE
) : sizeof(SECURITY_DESCRIPTOR
));
328 /* probe and copy the entire security descriptor structure. The SIDs
329 and ACLs will be probed and copied later though */
330 ProbeForRead(OriginalSecurityDescriptor
,
333 if(DescriptorCopy
.Control
& SE_SELF_RELATIVE
)
335 PSECURITY_DESCRIPTOR_RELATIVE RelSD
= (PSECURITY_DESCRIPTOR_RELATIVE
)OriginalSecurityDescriptor
;
337 DescriptorCopy
.Owner
= (PSID
)RelSD
->Owner
;
338 DescriptorCopy
.Group
= (PSID
)RelSD
->Group
;
339 DescriptorCopy
.Sacl
= (PACL
)RelSD
->Sacl
;
340 DescriptorCopy
.Dacl
= (PACL
)RelSD
->Dacl
;
344 DescriptorCopy
.Owner
= OriginalSecurityDescriptor
->Owner
;
345 DescriptorCopy
.Group
= OriginalSecurityDescriptor
->Group
;
346 DescriptorCopy
.Sacl
= OriginalSecurityDescriptor
->Sacl
;
347 DescriptorCopy
.Dacl
= OriginalSecurityDescriptor
->Dacl
;
352 Status
= _SEH_GetExceptionCode();
356 if(!NT_SUCCESS(Status
))
361 else if(!CaptureIfKernel
)
363 if(OriginalSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
365 return STATUS_UNKNOWN_REVISION
;
368 *CapturedSecurityDescriptor
= OriginalSecurityDescriptor
;
369 return STATUS_SUCCESS
;
373 if(OriginalSecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
375 return STATUS_UNKNOWN_REVISION
;
378 /* make a copy on the stack */
379 DescriptorCopy
.Revision
= OriginalSecurityDescriptor
->Revision
;
380 DescriptorCopy
.Sbz1
= OriginalSecurityDescriptor
->Sbz1
;
381 DescriptorCopy
.Control
= OriginalSecurityDescriptor
->Control
;
382 DescriptorSize
= ((DescriptorCopy
.Control
& SE_SELF_RELATIVE
) ?
383 sizeof(SECURITY_DESCRIPTOR_RELATIVE
) : sizeof(SECURITY_DESCRIPTOR
));
384 if(DescriptorCopy
.Control
& SE_SELF_RELATIVE
)
386 PSECURITY_DESCRIPTOR_RELATIVE RelSD
= (PSECURITY_DESCRIPTOR_RELATIVE
)OriginalSecurityDescriptor
;
388 DescriptorCopy
.Owner
= (PSID
)RelSD
->Owner
;
389 DescriptorCopy
.Group
= (PSID
)RelSD
->Group
;
390 DescriptorCopy
.Sacl
= (PACL
)RelSD
->Sacl
;
391 DescriptorCopy
.Dacl
= (PACL
)RelSD
->Dacl
;
395 DescriptorCopy
.Owner
= OriginalSecurityDescriptor
->Owner
;
396 DescriptorCopy
.Group
= OriginalSecurityDescriptor
->Group
;
397 DescriptorCopy
.Sacl
= OriginalSecurityDescriptor
->Sacl
;
398 DescriptorCopy
.Dacl
= OriginalSecurityDescriptor
->Dacl
;
402 if(DescriptorCopy
.Control
& SE_SELF_RELATIVE
)
404 /* in case we're dealing with a self-relative descriptor, do a basic convert
405 to an absolute descriptor. We do this so we can simply access the data
406 using the pointers without calculating them again. */
407 DescriptorCopy
.Control
&= ~SE_SELF_RELATIVE
;
408 if(DescriptorCopy
.Owner
!= NULL
)
410 DescriptorCopy
.Owner
= (PSID
)((ULONG_PTR
)OriginalSecurityDescriptor
+ (ULONG_PTR
)DescriptorCopy
.Owner
);
412 if(DescriptorCopy
.Group
!= NULL
)
414 DescriptorCopy
.Group
= (PSID
)((ULONG_PTR
)OriginalSecurityDescriptor
+ (ULONG_PTR
)DescriptorCopy
.Group
);
416 if(DescriptorCopy
.Dacl
!= NULL
)
418 DescriptorCopy
.Dacl
= (PACL
)((ULONG_PTR
)OriginalSecurityDescriptor
+ (ULONG_PTR
)DescriptorCopy
.Dacl
);
420 if(DescriptorCopy
.Sacl
!= NULL
)
422 DescriptorCopy
.Sacl
= (PACL
)((ULONG_PTR
)OriginalSecurityDescriptor
+ (ULONG_PTR
)DescriptorCopy
.Sacl
);
426 /* determine the size of the SIDs */
427 #define DetermineSIDSize(SidType) \
429 if(DescriptorCopy.SidType != NULL) \
431 SID *SidType = (SID*)DescriptorCopy.SidType; \
433 if(CurrentMode != KernelMode) \
435 /* securely access the buffers! */ \
438 ProbeForRead(&SidType->SubAuthorityCount, \
439 sizeof(SidType->SubAuthorityCount), \
441 SidType##SAC = SidType->SubAuthorityCount; \
442 SidType##Size = RtlLengthRequiredSid(SidType##SAC); \
443 DescriptorSize += ROUND_UP(SidType##Size, sizeof(ULONG)); \
444 ProbeForRead(SidType, \
447 if(!RtlValidSid(SidType)) \
449 Status = STATUS_INVALID_SID; \
454 Status = _SEH_GetExceptionCode(); \
458 if(!NT_SUCCESS(Status)) \
465 SidType##SAC = SidType->SubAuthorityCount; \
466 SidType##Size = RtlLengthRequiredSid(SidType##SAC); \
467 DescriptorSize += ROUND_UP(SidType##Size, sizeof(ULONG)); \
472 DetermineSIDSize(Owner
);
473 DetermineSIDSize(Group
);
475 /* determine the size of the ACLs */
476 #define DetermineACLSize(AclType, AclFlag) \
478 if((DescriptorCopy.Control & SE_##AclFlag##_PRESENT) && \
479 DescriptorCopy.AclType != NULL) \
481 PACL AclType = (PACL)DescriptorCopy.AclType; \
483 if(CurrentMode != KernelMode) \
485 /* securely access the buffers! */ \
488 ProbeForRead(&AclType->AclSize, \
489 sizeof(AclType->AclSize), \
491 AclType##Size = AclType->AclSize; \
492 DescriptorSize += ROUND_UP(AclType##Size, sizeof(ULONG)); \
493 ProbeForRead(AclType, \
496 if(!RtlValidAcl(AclType)) \
498 Status = STATUS_INVALID_ACL; \
503 Status = _SEH_GetExceptionCode(); \
507 if(!NT_SUCCESS(Status)) \
514 AclType##Size = AclType->AclSize; \
515 DescriptorSize += ROUND_UP(AclType##Size, sizeof(ULONG)); \
520 DescriptorCopy.AclType = NULL; \
524 DetermineACLSize(Sacl
, SACL
);
525 DetermineACLSize(Dacl
, DACL
);
527 /* allocate enough memory to store a complete copy of a self-relative
528 security descriptor */
529 NewDescriptor
= ExAllocatePool(PoolType
,
531 if(NewDescriptor
!= NULL
)
533 ULONG_PTR Offset
= sizeof(SECURITY_DESCRIPTOR
);
535 NewDescriptor
->Revision
= DescriptorCopy
.Revision
;
536 NewDescriptor
->Sbz1
= DescriptorCopy
.Sbz1
;
537 NewDescriptor
->Control
= DescriptorCopy
.Control
| SE_SELF_RELATIVE
;
541 /* setup the offsets and copy the SIDs and ACLs to the new
542 self-relative security descriptor. Probing the pointers is not
543 neccessary anymore as we did that when collecting the sizes! */
544 #define CopySIDOrACL(Type) \
546 if(DescriptorCopy.Type != NULL) \
548 NewDescriptor->Type = (PVOID)Offset; \
549 RtlCopyMemory((PVOID)((ULONG_PTR)NewDescriptor + \
550 (ULONG_PTR)NewDescriptor->Type), \
551 DescriptorCopy.Type, \
553 Offset += ROUND_UP(Type##Size, sizeof(ULONG)); \
564 Status
= _SEH_GetExceptionCode();
568 if(NT_SUCCESS(Status
))
570 /* we're finally done! copy the pointer to the captured descriptor to
572 *CapturedSecurityDescriptor
= NewDescriptor
;
573 return STATUS_SUCCESS
;
577 /* we failed to copy the data to the new descriptor */
578 ExFreePool(NewDescriptor
);
583 Status
= STATUS_INSUFFICIENT_RESOURCES
;
588 /* nothing to do... */
589 *CapturedSecurityDescriptor
= NULL
;
599 SeQuerySecurityDescriptorInfo(IN PSECURITY_INFORMATION SecurityInformation
,
600 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor
,
601 IN OUT PULONG Length
,
602 IN PSECURITY_DESCRIPTOR
*ObjectsSecurityDescriptor OPTIONAL
)
604 PSECURITY_DESCRIPTOR ObjectSd
;
605 PSECURITY_DESCRIPTOR_RELATIVE RelSD
;
610 ULONG OwnerLength
= 0;
611 ULONG GroupLength
= 0;
612 ULONG DaclLength
= 0;
613 ULONG SaclLength
= 0;
618 RelSD
= (PSECURITY_DESCRIPTOR_RELATIVE
)SecurityDescriptor
;
620 if (*ObjectsSecurityDescriptor
== NULL
)
622 if (*Length
< sizeof(SECURITY_DESCRIPTOR_RELATIVE
))
624 *Length
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
625 return STATUS_BUFFER_TOO_SMALL
;
628 *Length
= sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
629 RtlCreateSecurityDescriptorRelative(RelSD
,
630 SECURITY_DESCRIPTOR_REVISION
);
631 return STATUS_SUCCESS
;
634 ObjectSd
= *ObjectsSecurityDescriptor
;
636 /* Calculate the required security descriptor length */
637 Control
= SE_SELF_RELATIVE
;
638 if ((*SecurityInformation
& OWNER_SECURITY_INFORMATION
) &&
639 (ObjectSd
->Owner
!= NULL
))
641 Owner
= (PSID
)((ULONG_PTR
)ObjectSd
->Owner
+ (ULONG_PTR
)ObjectSd
);
642 OwnerLength
= ROUND_UP(RtlLengthSid(Owner
), 4);
643 Control
|= (ObjectSd
->Control
& SE_OWNER_DEFAULTED
);
646 if ((*SecurityInformation
& GROUP_SECURITY_INFORMATION
) &&
647 (ObjectSd
->Group
!= NULL
))
649 Group
= (PSID
)((ULONG_PTR
)ObjectSd
->Group
+ (ULONG_PTR
)ObjectSd
);
650 GroupLength
= ROUND_UP(RtlLengthSid(Group
), 4);
651 Control
|= (ObjectSd
->Control
& SE_GROUP_DEFAULTED
);
654 if ((*SecurityInformation
& DACL_SECURITY_INFORMATION
) &&
655 (ObjectSd
->Control
& SE_DACL_PRESENT
))
657 if (ObjectSd
->Dacl
!= NULL
)
659 Dacl
= (PACL
)((ULONG_PTR
)ObjectSd
->Dacl
+ (ULONG_PTR
)ObjectSd
);
660 DaclLength
= ROUND_UP((ULONG
)Dacl
->AclSize
, 4);
662 Control
|= (ObjectSd
->Control
& (SE_DACL_DEFAULTED
| SE_DACL_PRESENT
));
665 if ((*SecurityInformation
& SACL_SECURITY_INFORMATION
) &&
666 (ObjectSd
->Control
& SE_SACL_PRESENT
))
668 if (ObjectSd
->Sacl
!= NULL
)
670 Sacl
= (PACL
)((ULONG_PTR
)ObjectSd
->Sacl
+ (ULONG_PTR
)ObjectSd
);
671 SaclLength
= ROUND_UP(Sacl
->AclSize
, 4);
673 Control
|= (ObjectSd
->Control
& (SE_SACL_DEFAULTED
| SE_SACL_PRESENT
));
676 SdLength
= OwnerLength
+ GroupLength
+ DaclLength
+
677 SaclLength
+ sizeof(SECURITY_DESCRIPTOR_RELATIVE
);
678 if (*Length
< SdLength
)
681 return STATUS_BUFFER_TOO_SMALL
;
684 /* Build the new security descrtiptor */
685 RtlCreateSecurityDescriptorRelative(RelSD
,
686 SECURITY_DESCRIPTOR_REVISION
);
687 RelSD
->Control
= Control
;
689 Current
= (ULONG_PTR
)(RelSD
+ 1);
691 if (OwnerLength
!= 0)
693 RtlCopyMemory((PVOID
)Current
,
696 RelSD
->Owner
= (ULONG
)(Current
- (ULONG_PTR
)SecurityDescriptor
);
697 Current
+= OwnerLength
;
700 if (GroupLength
!= 0)
702 RtlCopyMemory((PVOID
)Current
,
705 RelSD
->Group
= (ULONG
)(Current
- (ULONG_PTR
)SecurityDescriptor
);
706 Current
+= GroupLength
;
711 RtlCopyMemory((PVOID
)Current
,
714 RelSD
->Dacl
= (ULONG
)(Current
- (ULONG_PTR
)SecurityDescriptor
);
715 Current
+= DaclLength
;
720 RtlCopyMemory((PVOID
)Current
,
723 RelSD
->Sacl
= (ULONG
)(Current
- (ULONG_PTR
)SecurityDescriptor
);
724 Current
+= SaclLength
;
729 return STATUS_SUCCESS
;
737 SeReleaseSecurityDescriptor(
738 IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor
,
739 IN KPROCESSOR_MODE CurrentMode
,
740 IN BOOLEAN CaptureIfKernelMode
745 /* WARNING! You need to call this function with the same value for CurrentMode
746 and CaptureIfKernelMode that you previously passed to
747 SeCaptureSecurityDescriptor() in order to avoid memory leaks! */
748 if(CapturedSecurityDescriptor
!= NULL
&&
749 (CurrentMode
== UserMode
||
750 (CurrentMode
== KernelMode
&& CaptureIfKernelMode
)))
752 /* only delete the descriptor when SeCaptureSecurityDescriptor() allocated one! */
753 ExFreePool(CapturedSecurityDescriptor
);
756 return STATUS_SUCCESS
;
763 SeSetSecurityDescriptorInfo(IN PVOID Object OPTIONAL
,
764 IN PSECURITY_INFORMATION SecurityInformation
,
765 IN PSECURITY_DESCRIPTOR SecurityDescriptor
,
766 IN OUT PSECURITY_DESCRIPTOR
*ObjectsSecurityDescriptor
,
767 IN POOL_TYPE PoolType
,
768 IN PGENERIC_MAPPING GenericMapping
)
771 return STATUS_NOT_IMPLEMENTED
;
779 SeSetSecurityDescriptorInfoEx(
780 IN PVOID Object OPTIONAL
,
781 IN PSECURITY_INFORMATION SecurityInformation
,
782 IN PSECURITY_DESCRIPTOR ModificationDescriptor
,
783 IN OUT PSECURITY_DESCRIPTOR
*ObjectsSecurityDescriptor
,
784 IN ULONG AutoInheritFlags
,
785 IN POOL_TYPE PoolType
,
786 IN PGENERIC_MAPPING GenericMapping
790 return STATUS_NOT_IMPLEMENTED
;
798 SeValidSecurityDescriptor(IN ULONG Length
,
799 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
805 if (Length
< SECURITY_DESCRIPTOR_MIN_LENGTH
)
807 DPRINT1("Invalid Security Descriptor revision\n");
811 if (SecurityDescriptor
->Revision
!= SECURITY_DESCRIPTOR_REVISION1
)
813 DPRINT1("Invalid Security Descriptor revision\n");
817 if (!(SecurityDescriptor
->Control
& SE_SELF_RELATIVE
))
819 DPRINT1("No self-relative Security Descriptor\n");
823 SdLength
= sizeof(SECURITY_DESCRIPTOR
);
825 /* Check Owner SID */
826 if (SecurityDescriptor
->Owner
== NULL
)
828 DPRINT1("No Owner SID\n");
832 if ((ULONG_PTR
)SecurityDescriptor
->Owner
% sizeof(ULONG
))
834 DPRINT1("Invalid Owner SID alignment\n");
838 Sid
= (PISID
)((ULONG_PTR
)SecurityDescriptor
+ (ULONG_PTR
)SecurityDescriptor
->Owner
);
839 if (Sid
->Revision
!= SID_REVISION
)
841 DPRINT1("Invalid Owner SID revision\n");
845 SdLength
+= (sizeof(SID
) + (Sid
->SubAuthorityCount
- 1) * sizeof(ULONG
));
846 if (Length
< SdLength
)
848 DPRINT1("Invalid Owner SID size\n");
852 /* Check Group SID */
853 if (SecurityDescriptor
->Group
!= NULL
)
855 if ((ULONG_PTR
)SecurityDescriptor
->Group
% sizeof(ULONG
))
857 DPRINT1("Invalid Group SID alignment\n");
861 Sid
= (PSID
)((ULONG_PTR
)SecurityDescriptor
+ (ULONG_PTR
)SecurityDescriptor
->Group
);
862 if (Sid
->Revision
!= SID_REVISION
)
864 DPRINT1("Invalid Group SID revision\n");
868 SdLength
+= (sizeof(SID
) + (Sid
->SubAuthorityCount
- 1) * sizeof(ULONG
));
869 if (Length
< SdLength
)
871 DPRINT1("Invalid Group SID size\n");
877 if (SecurityDescriptor
->Dacl
!= NULL
)
879 if ((ULONG_PTR
)SecurityDescriptor
->Dacl
% sizeof(ULONG
))
881 DPRINT1("Invalid DACL alignment\n");
885 Acl
= (PACL
)((ULONG_PTR
)SecurityDescriptor
+ (ULONG_PTR
)SecurityDescriptor
->Dacl
);
886 if ((Acl
->AclRevision
< MIN_ACL_REVISION
) &&
887 (Acl
->AclRevision
> MAX_ACL_REVISION
))
889 DPRINT1("Invalid DACL revision\n");
893 SdLength
+= Acl
->AclSize
;
894 if (Length
< SdLength
)
896 DPRINT1("Invalid DACL size\n");
902 if (SecurityDescriptor
->Sacl
!= NULL
)
904 if ((ULONG_PTR
)SecurityDescriptor
->Sacl
% sizeof(ULONG
))
906 DPRINT1("Invalid SACL alignment\n");
910 Acl
= (PACL
)((ULONG_PTR
)SecurityDescriptor
+ (ULONG_PTR
)SecurityDescriptor
->Sacl
);
911 if ((Acl
->AclRevision
< MIN_ACL_REVISION
) ||
912 (Acl
->AclRevision
> MAX_ACL_REVISION
))
914 DPRINT1("Invalid SACL revision\n");
918 SdLength
+= Acl
->AclSize
;
919 if (Length
< SdLength
)
921 DPRINT1("Invalid SACL size\n");