Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#6

AW: Manipulieren der Benutzerangaben bei Named Pipes

  Alt 26. Jul 2011, 16:47
Ich habe das ganze bei mir umgebastelt für das Verwenden der Zugriffsrechte einer Datei, welche als Property eingetragen werden kann.
Vielleciht kannst Du etwas von den Auszügen brauchen ....


Delphi-Quellcode:
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;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat