Solved

Delphi GetFileSecurity Example Needed

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 131
Create a path if not exists 7 89
When i run adoquery my application freezes 26 178
Firemonkey DbLookupComboBox equivalent ? 2 55
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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