Solved

Delphi GetFileSecurity Example Needed

Posted on 2012-03-29
3
1,228 Views
Last Modified: 2012-03-30
Does anybody have example code of being able to fetch the ACL's of a file or directory using Delphi?  I'm trying to work through the Microsoft SDK but the more I delve into it, the more confusing it's getting.  I've managed to get this far but I don't know where to go from here.

ProcedureTForm1.GetPermissions(Path : String);
var
    SecDescSize: Cardinal;
    SecDesc: PSECURITY_DESCRIPTOR;
    ACL: PACL;
    DaclPresent, DaclDefaulted : LongBool;

begin
  GetFileSecurity(PChar(Path), OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION or DACL_SECURITY_INFORMATION, nil, 0, SecDescSize);
  SecDesc := GetMemory(SecDescSize);
  if GetFileSecurity(PChar(Path), OWNER_SECURITY_INFORMATION or GROUP_SECURITY_INFORMATION or DACL_SECURITY_INFORMATION, SecDesc, SecDescSize, SecDescSize) then
    Begin
      If GetSecurityDescriptorDacl(SecDesc,DaclPresent,ACL,DaclDefaulted) Then
        Begin
          if DaclPresent then
            Begin
              // I don't know where to go from here!
            End;
        End;
    End
  Else
    Begin
      // No Access to read security
    End;
  FreeMem(SecDesc, SecDescSize);
  //
end;

Open in new window


I don't need to know who the owner of the file/directory is, nor do I need to modify the ACL's - I just want to see what the permisisons are - like if I was getting the output from ICACLS.

I could write a wrapper application to get the output of ICACLS and then get the information that way, but that's cheating, and will slow down my application a great deal.  I want to use native API calls.

Google has not been helpful enough, everything I find is incomplete information.

Thanks in advance!
0
Comment
Question by:LesterClayton
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 37782484
There's a good package by madshi called madSecurity
It's part of the free for non commercial use package madCollection
With it you can do all you need with ACE and ACL and there're also example round the internet and also here on exex

Take a look here at the madshi online help support http://help.madshi.net/ACLs.htm to have an idea about it
0
 
LVL 18

Author Closing Comment

by:LesterClayton
ID: 37784406
Yes, thank you very much for this suggestion.  My application is working just great, and I'm able to pull the ACL's very easily.  It doesn't support 64 bit yet but he says it's currently in progress :)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37785944
Glad to have helped you. Stay sure that Madshi will update his packages often an for long time.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question