Function SetDACL_Dir(DirName, StudName, DomainName :
String):boolean;
var
UserToken : TJwSecurityToken;
FileObject : TJwSecureFileObject;
Owner : TJwSecurityId;
StudSid : TJwSecurityId;
DACL : TJwDAccessControlList;
begin
result:=true;
if not DirectoryExists(DirName)
then
begin
result:=false;
ErrorDialog('
Verzeichnis "'+DirName+'
" nicht gefunden!');
end;
if result
then
begin
JwInitWellKnownSIDs;
UserToken := TJwSecurityToken.CreateTokenEffective(MAXIMUM_ALLOWED);
Owner := UserToken.GetTokenOwner;
try
StudSid := TJwSecurityId.Create(DomainName,Studname);
except
result:=false;
ErrorDialog('
Student "'+StudName+'
" im Verzeichnis "'+DomainName+'
" nicht gefunden!');
end;
if result
then
begin
try
FileObject := TJwSecureFileObject.Create(DirName);
except
result:=false;
ErrorDialog('
Verzeichnis konnte nicht gefunden werden "'+DirName+'
" !');
end;
end;
if result
then
begin
try
if not FileObject.AccessCheck(WRITE_DAC)
then //Make me owner if we cant access DACL
begin //try to become owner
JwEnablePrivilege(SE_TAKE_OWNERSHIP_NAME, pst_Enable);
FileObject.Owner := Owner;
end;
DACL := FileObject.DACL;
dacl.Clear;
DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(
nil, [afObjectInheritAce,afContainerInheritAce], GENERIC_ALL, Owner, false));
DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(
nil, [afObjectInheritAce,afContainerInheritAce], GENERIC_ALL, StudSid, false));
FileObject.SetDACL(DACL);
except
result:=false;
ErrorDialog('
Fehler beim Setzen der Berechtigung auf "'+DirName+'
" !');
end;
end;
Owner.Free;
UserToken.Free;
StudSid.free;
FileObject.Free;
end;
end;
// SetDACL