delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


Copy NTFS file security from a source to a destinationGo to Wayne Sherman's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
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:
8924
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;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Same code but as pure API call
    Jens Borrisholt (Apr 14 2008 2:21PM)

    SE_WINDOW_OBJECT,
    SE_DS_OBJECT,
    SE_DS_OBJECT_ALL,
    SE_PROVIDER_DEFINED_OBJECT,
    SE_WMIGUID_OBJECT
    );
const
  ModName = 'ADVAPI32.DLL';

function GetNamedSecurityInfo(pObjectName: PAnsiChar; ObjectType: SE_OBJECT_TYPE;
  SecurityInfo: SECURITY_INFORMATION; ppsidOwner, ppsidGroup: PPSID; ppDacl, ppSacl: PACL;
  var ppSecurityDescriptor: PSECURITY_DESCRIPTOR): DWORD; stdcall;
  external ModName name 'GetNamedSecurityInfoA';

function SetNamedSecurityInfo(pObjectName: PAnsiChar; ObjectType: SE_OBJECT_TYPE;
  SecurityInfo: SECURITY_INFORMATION; ppsidOwner, ppsidGroup: PPSID;
  ppDacl, ppSacl: PACL): DWORD; stdcall;
  external ModName name 'SetNamedSecurityInfoA';

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;


All source code 100% stolen from JCL ;o)

Jens B
Respond

Internet
    Toom Hat (Oct 26 2006 4:09PM)

How To Look The All Sockets in Use And Other Port For Find The Any IP Or etc Incoming & OutGouing ? And The Control And Block it ?
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Hans Gulö
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)