Solved

Delphi GetFileSecurity Example Needed

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

17 Experts available now in Live!

Get 1:1 Help Now