[RTL] Improve usage of absolte vs self-relative security descriptors

- RtlpQuerySecurityDescriptor: Change argument type of first parameter from PISECURITY_DESCRIPTOR to PSECURITY_DESCRIPTOR, since it handles both absolute and self-relative SDs.
- RtlMakeSelfRelativeSD: rename first parameter from AbsoluteSD to SecurityDescriptor, since it handles both absolute and self-relative SDs.
- SepGetGroupFromDescriptor/SepGetOwnerFromDescriptor/SepGetDaclFromDescriptor/SepGetSaclFromDescriptor: Change parameter type from PVOID to PSECURITY_DESCRIPTOR for clarity.
This commit is contained in:
Timo Kreuzer 2023-09-23 17:49:27 +03:00
parent 389d04650f
commit df053d4e43
2 changed files with 8 additions and 9 deletions

View file

@ -87,7 +87,7 @@ typedef struct _TOKEN_AUDIT_POLICY_INFORMATION
FORCEINLINE FORCEINLINE
PSID PSID
SepGetGroupFromDescriptor( SepGetGroupFromDescriptor(
_Inout_ PVOID _Descriptor) _Inout_ PSECURITY_DESCRIPTOR _Descriptor)
{ {
PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor; PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor;
PISECURITY_DESCRIPTOR_RELATIVE SdRel; PISECURITY_DESCRIPTOR_RELATIVE SdRel;
@ -107,7 +107,7 @@ SepGetGroupFromDescriptor(
FORCEINLINE FORCEINLINE
PSID PSID
SepGetOwnerFromDescriptor( SepGetOwnerFromDescriptor(
_Inout_ PVOID _Descriptor) _Inout_ PSECURITY_DESCRIPTOR _Descriptor)
{ {
PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor; PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor;
PISECURITY_DESCRIPTOR_RELATIVE SdRel; PISECURITY_DESCRIPTOR_RELATIVE SdRel;
@ -127,7 +127,7 @@ SepGetOwnerFromDescriptor(
FORCEINLINE FORCEINLINE
PACL PACL
SepGetDaclFromDescriptor( SepGetDaclFromDescriptor(
_Inout_ PVOID _Descriptor) _Inout_ PSECURITY_DESCRIPTOR _Descriptor)
{ {
PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor; PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor;
PISECURITY_DESCRIPTOR_RELATIVE SdRel; PISECURITY_DESCRIPTOR_RELATIVE SdRel;
@ -149,7 +149,7 @@ SepGetDaclFromDescriptor(
FORCEINLINE FORCEINLINE
PACL PACL
SepGetSaclFromDescriptor( SepGetSaclFromDescriptor(
_Inout_ PVOID _Descriptor) _Inout_ PSECURITY_DESCRIPTOR _Descriptor)
{ {
PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor; PISECURITY_DESCRIPTOR Descriptor = (PISECURITY_DESCRIPTOR)_Descriptor;
PISECURITY_DESCRIPTOR_RELATIVE SdRel; PISECURITY_DESCRIPTOR_RELATIVE SdRel;

View file

@ -42,7 +42,7 @@ RtlpValidateSDOffsetAndSize(IN ULONG Offset,
VOID VOID
NTAPI NTAPI
RtlpQuerySecurityDescriptor(IN PISECURITY_DESCRIPTOR SecurityDescriptor, RtlpQuerySecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
OUT PSID *Owner, OUT PSID *Owner,
OUT PULONG OwnerSize, OUT PULONG OwnerSize,
OUT PSID *PrimaryGroup, OUT PSID *PrimaryGroup,
@ -644,7 +644,7 @@ RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
*/ */
NTSTATUS NTSTATUS
NTAPI NTAPI
RtlMakeSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSD, RtlMakeSelfRelativeSD(IN PSECURITY_DESCRIPTOR SecurityDescriptor,
OUT PSECURITY_DESCRIPTOR SelfRelativeSD, OUT PSECURITY_DESCRIPTOR SelfRelativeSD,
IN OUT PULONG BufferLength) IN OUT PULONG BufferLength)
{ {
@ -652,12 +652,11 @@ RtlMakeSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSD,
PACL Sacl, Dacl; PACL Sacl, Dacl;
ULONG OwnerLength, GroupLength, SaclLength, DaclLength, TotalLength; ULONG OwnerLength, GroupLength, SaclLength, DaclLength, TotalLength;
ULONG_PTR Current; ULONG_PTR Current;
PISECURITY_DESCRIPTOR Sd = (PISECURITY_DESCRIPTOR)AbsoluteSD;
PISECURITY_DESCRIPTOR_RELATIVE RelSd = (PISECURITY_DESCRIPTOR_RELATIVE)SelfRelativeSD; PISECURITY_DESCRIPTOR_RELATIVE RelSd = (PISECURITY_DESCRIPTOR_RELATIVE)SelfRelativeSD;
PAGED_CODE_RTL(); PAGED_CODE_RTL();
/* Query all components */ /* Query all components */
RtlpQuerySecurityDescriptor(Sd, RtlpQuerySecurityDescriptor(SecurityDescriptor,
&Owner, &Owner,
&OwnerLength, &OwnerLength,
&Group, &Group,
@ -687,7 +686,7 @@ RtlMakeSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSD,
/* Copy the header fields */ /* Copy the header fields */
RtlCopyMemory(RelSd, RtlCopyMemory(RelSd,
Sd, SecurityDescriptor,
FIELD_OFFSET(SECURITY_DESCRIPTOR_RELATIVE, Owner)); FIELD_OFFSET(SECURITY_DESCRIPTOR_RELATIVE, Owner));
/* Set the current copy pointer */ /* Set the current copy pointer */