|
| Copy NTFS file security from a source to a destination |  
|
|---|
| Simple function to copy NTFS file/folder security settings | Product: Delphi all versions | Category: Win API | Skill Level:
 | Scoring:  | Last Update: 11/18/2002 | Search Keys: delphi delphi3000 article borland vcl code-snippet NTFS ACL security descriptor copy file folder access control | Times Scored: 6 | Visits: 9683 | Uploader: Wayne Sherman Company: System Design Works | Reference: System Design Works | | | Question/Problem/Abstract:
By default, copying a folder or file to a destination on an NTFS partition, the destination file takes on the security and access control settings of the destinations parent folder. This function provides an easy way to also copy the original security/ACL settings to the destination file, or copy security settings from another file/folder. | Answer:
Requires JEDI JCL - http://sourceforge.net/projects/jcl
uses Windows, JwaAclApi, JwaWinNT, JwaAccCtrl, JwaWinBase;
function CopyNTFSSecurity(const Source, Dest: string): boolean;
var
SidOwner: PSID;
SidGroup: PSID;
Dacl: PACL;
Sacl: PACL;
SecDescPtr: PSECURITY_DESCRIPTOR;
begin
Result := false;
if GetNamedSecurityInfo(PChar(Source), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION or SACL_SECURITY_INFORMATION or
OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION,
@SidOwner, @SidGroup, @Dacl, @Sacl, SecDescPtr) = ERROR_SUCCESS then
begin
Result := SetNamedSecurityInfo(PChar(Dest), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION or SACL_SECURITY_INFORMATION or
OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION,
SidOwner, SidGroup, Dacl, Sacl) = ERROR_SUCCESS;
LocalFree(HLOCAL(SecDescPtr));
end;
end;
|
|