procedure TPipeServer.GenACLFromFile;
//20110228 by Thomas Wassermann
var
res : Boolean;
len : Cardinal;
fDaclPresent,fDaclDefaulted:Bool;
begin
FACL :=
nil;
if Assigned(FpFileSD)
then DoHeapFree(FpFileSD);
if FileExists(FACLFileName)
then
begin
res := GetFileSecurity(PChar(FACLFileName),DACL_SECURITY_INFORMATION,FpFileSD,0,len);
if res
or (GetLastError() = ERROR_INSUFFICIENT_BUFFER)
then
begin
FpFileSD := DoHeapAlloc(len);
GetFileSecurity(PChar(FACLFileName),DACL_SECURITY_INFORMATION,FpFileSD,len,len);
GetSecurityDescriptorDacl(FpFileSD,fDaclPresent,FACL,fDaclDefaulted);
end;
end;
end;
.....
.....
procedure TPipeServer.SetActive(Value: Boolean);
begin
// Check against current state
GenACLFromFile;
if (FActive <> Value)
then
begin
// Shutdown if active
if FActive
then DoShutdown;
// Startup if not active
if Value
then DoStartup
end;
end;
.....
.....
procedure InitializeSecurity(
var SA: TSecurityAttributes;
ACL:PACL=nil);
var sd: PSecurityDescriptor;
begin
// Allocate memory for the security descriptor
sd:=AllocMem(SECURITY_DESCRIPTOR_MIN_LENGTH);
// Initialise the new security descriptor
InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
// Add a NULL descriptor ACL to the security descriptor
SetSecurityDescriptorDacl(sd, True,
ACL, False);
// Set up the security attributes structure
with SA
do
begin
nLength:=SizeOf(TSecurityAttributes) ;
lpSecurityDescriptor:=sd;
bInheritHandle:=True;
end;
end;