From 763d4666a7547e0d40561562fb57de031aa873e0 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 1 Dec 2015 17:34:00 -0800 Subject: [PATCH] dll: CreateSelfRelativeSecurityDescriptor now supports self relative security descriptors as input --- src/dll/fsctl.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/dll/fsctl.c b/src/dll/fsctl.c index 5c979f42..389ed132 100644 --- a/src/dll/fsctl.c +++ b/src/dll/fsctl.c @@ -31,6 +31,8 @@ static NTSTATUS CreateSelfRelativeSecurityDescriptor(PSECURITY_DESCRIPTOR Securi BOOLEAN Success; PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor = 0; DWORD SelfRelativeSecurityDescriptorSize; + SECURITY_DESCRIPTOR_CONTROL SecurityDescriptorControl; + DWORD SecurityDescriptorRevision; SECURITY_DESCRIPTOR SecurityDescriptorStruct; PTOKEN_USER User = 0; PACL Acl = 0; @@ -64,12 +66,29 @@ static NTSTATUS CreateSelfRelativeSecurityDescriptor(PSECURITY_DESCRIPTOR Securi SecurityDescriptor = &SecurityDescriptorStruct; } - SelfRelativeSecurityDescriptorSize = 0; - Success = - (MakeSelfRelativeSD(SecurityDescriptor, 0, &SelfRelativeSecurityDescriptorSize) || - ERROR_INSUFFICIENT_BUFFER == GetLastError()) && - (SelfRelativeSecurityDescriptor = Malloc(SelfRelativeSecurityDescriptorSize)) && - (MakeSelfRelativeSD(SecurityDescriptor, SelfRelativeSecurityDescriptor, &SelfRelativeSecurityDescriptorSize)); + if (!GetSecurityDescriptorControl(SecurityDescriptor, + &SecurityDescriptorControl, &SecurityDescriptorRevision)) + { + Result = FspNtStatusFromWin32(GetLastError()); + goto exit; + } + + if (SecurityDescriptorControl & SE_SELF_RELATIVE) + { + SelfRelativeSecurityDescriptorSize = GetSecurityDescriptorLength(SecurityDescriptor); + Success = + (SelfRelativeSecurityDescriptor = Malloc(SelfRelativeSecurityDescriptorSize)) && + memcpy(SelfRelativeSecurityDescriptor, SecurityDescriptor, SelfRelativeSecurityDescriptorSize); + } + else + { + SelfRelativeSecurityDescriptorSize = 0; + Success = + (MakeSelfRelativeSD(SecurityDescriptor, 0, &SelfRelativeSecurityDescriptorSize) || + ERROR_INSUFFICIENT_BUFFER == GetLastError()) && + (SelfRelativeSecurityDescriptor = Malloc(SelfRelativeSecurityDescriptorSize)) && + (MakeSelfRelativeSD(SecurityDescriptor, SelfRelativeSecurityDescriptor, &SelfRelativeSecurityDescriptorSize)); + } if (!Success) { Result = FspNtStatusFromWin32(GetLastError());