Solved

Delphi GetFileSecurity Example Needed

Posted on 2012-03-29
3
1,188 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now