Einzelnen Beitrag anzeigen

Benutzerbild von Orakel-von-Delphi
Orakel-von-Delphi

Registriert seit: 27. Jan 2004
Ort: Mittelhessen
45 Beiträge
 
Delphi 2007 Professional
 
#2

Problem gelöst !!!

  Alt 7. Okt 2004, 07:25
Es funktioniert mit 2 kleinen Änderungen:

Code:
function SetFileSecurityRecursive(lpFileName: PChar; SecurityInformation: SECURITY_INFORMATION;
                                 pSecurityDescriptor: PSecurityDescriptor): BOOL;
var
  sr : TSearchRec;
begin
  Result := SetFileSecurity(lpFileName, SecurityInformation, pSecurityDescriptor);

  if Not Result then
      Exit;

  if (FileGetAttr(lpFileName) AND faDirectory) = faDirectory then
    begin
     // Rekursion beginnt
     if FindFirst(IncludeTrailingPathDelimiter(lpFileName) + '*', $EFFF, sr) = 0 then
       begin
        Repeat
         // msp 07.10.2004
         // if ((sr.Attr and faDirectory) = faDirectory) AND (sr.Name <> '.') AND (sr.Name <> '..') then
         if (sr.Name <> '.') AND (sr.Name <> '..') then
            SetFileSecurityRecursive(PChar(IncludeTrailingPathDelimiter(lpFileName) + sr.Name),
                                     SecurityInformation, pSecurityDescriptor);
        until FindNext(sr) <> 0;
        FindClose(sr);
       end;
    end;
end;


Code:
var
   AceFlags : BYTE;      

                .
                .

      //
      // STEP 14: Add the access-allowed ACE to the new DACL.
      // The new ACE added here will be in the correct position,
      // immediately after all existing non-inherited ACEs.
      //
      AceFlags := $1   (* OBJECT_INHERIT_ACE *)
               OR $2   (* CONTAINER_INHERIT_ACE *)
               OR $10  (* INHERITED_ACE*);

      if Not AddAccessAllowedAceEx(pNewACL^, ACL_REVISION2, AceFlags, dwAccessMask,
               pUserSID) then
         raise Exception.Create('AddAccessAllowedAce ' + IntToStr(GetLastError()));
                .
Grund allen Übels war die Funktion AddAccessAllowedAce, die im Gegensatz zu AddAccessAllowedAceEx nicht die AceFlags setzt. Das ist aber gerade bei Verzeichnissen unbedingt notwendig. Außerdem sollen auch neue Verzeichnise und Dateien die Sicherheitseinstellungen des übergeordneten Ordners übernehmen.
Michael
  Mit Zitat antworten Zitat