Recent

Author Topic: Using Windows ACL-functions  (Read 7602 times)

ChrisTG

  • New member
  • *
  • Posts: 5
Using Windows ACL-functions
« on: July 08, 2014, 11:15:26 am »
Hi there,

I'm trying to use function GetNamedSecurityInfo() to read the ACL of a folder structure.
The code looks like this:
Code: [Select]
dwError := GetNamedSecurityInfo(pAnsiChar(Filename), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, @ExistingDacl, nil, @psd);
Unfortunately the compiler complains:
Code: [Select]
D:\workspace\Libs\MyFileUtils.pas(54,70) Error: Incompatible type for arg no. 2: Got "SE_OBJECT_TYPE", expected "_SE_OBJECT_TYPE"
If I try to change to _SE_FILE_OBJECT, I get the following error message:
Code: [Select]
D:\workspace\Libs\MyFileUtils.pas(54,71) Error: Identifier not found "_SE_FILE_OBJECT"

Strange is, that the function is defined in JwaAclApi as:
Code: [Select]
function GetNamedSecurityInfo(pObjectName: LPTSTR; ObjectType: SE_OBJECT_TYPE;
  SecurityInfo: SECURITY_INFORMATION; ppsidOwner, ppsidGroup: PPSID; ppDacl,
  ppSacl: PPACL; var ppSecurityDescriptor: PSECURITY_DESCRIPTOR): DWORD; stdcall;
So, from my point of view SE_FILE_OBJECT should be fine??

Has anyone a solution for this problem?

TIA,
Chris

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8734
  • FPC developer.
Re: Using Windows ACL-functions
« Reply #1 on: July 08, 2014, 11:29:59 am »
Probably you have some identifier conflict, or multiple getnamedsecurityinfo declarations. Maybe Jedi and FPC Windows unit both define it.

 IOW two different units export the same identifier, and the compiler wants the type one that belongs to the getnamedsecurityinfo call, but you pass a type declared in some other unit.

Try to make a minimal program with only the GetNamedSecurityInfo call (it must only be compilable, not runnable). If that succeeds, then start adding your own units till it goes wrong.

Usually such conflicts are worked around by prefixing the identifiers (getnamesecurityinfo and SE_FILE_OBJECT or its type) with the unit name (e.g. jwaaclapi.getnamedsecurityinfo etc)

ChrisTG

  • New member
  • *
  • Posts: 5
Re: Using Windows ACL-functions
« Reply #2 on: July 08, 2014, 11:40:36 am »
Hi marcov,

thanks for your reply!

Ok, I've created a "bare minimun" version of the problem.
But I still don't see any double definitions that could cause the error.
I've attached the project files to this post, could you please drop a quick look on them?

Thanks,
Chris
« Last Edit: July 08, 2014, 11:44:51 am by ChrisTG »

Cyrax

  • Hero Member
  • *****
  • Posts: 834
Re: Using Windows ACL-functions
« Reply #3 on: July 08, 2014, 11:45:01 am »
Hi there,

I'm trying to use function GetNamedSecurityInfo() to read the ACL of a folder structure.
The code looks like this:
Code: [Select]
dwError := GetNamedSecurityInfo(pAnsiChar(Filename), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, @ExistingDacl, nil, @psd);
...

You need to declare new variable which have type of SE_FILE_OBJECT and feed it to GetNamedSecurityInfo function.

Like this:
Code: [Select]
  Var
    AFileObject : SE_FILE_OBJECT;
...
dwError := GetNamedSecurityInfo(pAnsiChar(Filename), AFileObject, DACL_SECURITY_INFORMATION, nil, nil, @ExistingDacl, nil, @psd);

And I think you need to same for DACL_SECURITY_INFORMATION.

Cyrax

  • Hero Member
  • *****
  • Posts: 834
Re: Using Windows ACL-functions
« Reply #4 on: July 08, 2014, 11:48:35 am »
Hi marcov,

thanks for your reply!

Ok, I've created a "bare minimun" version of the problem.
But I still don't see any double definitions that could cause the error.
I've attached the project files to this post, could you please drop a quick look on them?

Thanks,
Chris

Remove Windows, JwaAclApi and JwaAccCtrl units from uses clause. Then add only JwaWindows in there.

ChrisTG

  • New member
  • *
  • Posts: 5
Re: Using Windows ACL-functions
« Reply #5 on: July 08, 2014, 12:13:41 pm »
Hi Cyrax,

thanks for your reply.

Removing all but JwaWindows solves the problem with the stripped down example project, but I can't use that as a solution in my normal project since I need units like "Windows" there.
Defining variables and passing them to the function call instead of the types does not change anything. The compiler still complains about an incompatible type.
Where is that "correct" SE_FILE_OBJECT defined? Can I use something like <UnitWithCorrectDefinition>.SE_FILE_OBJECT in my code? Would that work?

ChrisTG

  • New member
  • *
  • Posts: 5
Re: Using Windows ACL-functions
« Reply #6 on: July 08, 2014, 12:22:20 pm »
I think I figured it out. I simply have to write "JwaWindows." in front of ALL references in that function call. This way the complier gets the right definitions and the code can be compiled without errors.
Strange, that this is not needed in Delphi.

However, my problem is solved - so thanks again for your support!

cheers,
Chris

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8734
  • FPC developer.
Re: Using Windows ACL-functions
« Reply #7 on: July 08, 2014, 12:30:22 pm »
Maybe Free Pascal has some of these declarations in unit Windows.  The delphi behaviour might be version specific

Leledumbo

  • Hero Member
  • *****
  • Posts: 8267
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Using Windows ACL-functions
« Reply #8 on: July 08, 2014, 04:29:11 pm »
JWA prefix means the unit comes from JEDI Windows API project, which is initially made to be Delphi compatible. FPC also wraps Windows API, but the content might not be compatible with JWA / Delphi one.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8734
  • FPC developer.
Re: Using Windows ACL-functions
« Reply #9 on: July 08, 2014, 04:30:36 pm »
JWAwindows is afaik also not compatible with Delphi windows.  Put the jedi units last in the uses clause.

 

TinyPortal © 2005-2018