Solved

Delphi GetFileSecurity Example Needed

Posted on 2012-03-29
3
1,273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

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 23

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

Technology Partners: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 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