1

So I am trying to manipulate several pinvoke functions right now and I can't figure out where I find the values for each flag in SECURITY_INFORMATION at?

Here is the link

I have already visited the PInvoke site and its definition of SECURITY_INFORMATION seems to be incorrect. Here

The reason I think it is incorrect is because I am throwing the following error when I try to call ConvertSecurityDescriptorToStringSecurityDescriptor method.

A call to PInvoke function 'ConvertSecurityDescriptorToStringSecurityDescriptor' 
has unbalanced the stack. This is likely because the managed PInvoke signature 
does not match the unmanaged target signature. Check that the calling 
convention and parameters of the PInvoke signature match the target 
unmanaged signature.

But again I am interested in figuring out how to find the Hexadecimal values of each flag listed in the MSDN article I supplied. Its as if people just magically generate the values and they are correct even though there is no sign of them anywhere documented in that article.

EDIT 1

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool ConvertSecurityDescriptorToStringSecurityDescriptor(IntPtr SecurityDescriptor, 
    uint RequestedStringSDRevision, 
    SECURITY_INFORMATION SecurityInformation,
    out IntPtr StringSecurityDescriptor, 
    out int StringSecurityDescriptorLen);

[Flags]
public enum SECURITY_INFORMATION  {
    OWNER_SECURITY_INFORMATION = 0x00000001,
    GROUP_SECURITY_INFORMATION = 0x00000002,
    DACL_SECURITY_INFORMATION = 0x00000004,
    SACL_SECURITY_INFORMATION = 0x00000008,
    UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000,
    UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000,
    PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
}
Steven Combs
  • 1,890
  • 6
  • 29
  • 54

1 Answers1

0

A few things to try. First:

[Flags]
public enum SECURITY_INFORMATION : uint  {
    OWNER_SECURITY_INFORMATION = 0x00000001,
    GROUP_SECURITY_INFORMATION = 0x00000002,
    DACL_SECURITY_INFORMATION = 0x00000004,
    SACL_SECURITY_INFORMATION = 0x00000008,
    UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000,
    UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000,
    PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
}

Note the underlying type is changed to uint. The values are defined here.

If it still doesn't work, then try:

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool ConvertSecurityDescriptorToStringSecurityDescriptor(
    IntPtr SecurityDescriptor, 
    uint RequestedStringSDRevision, 
    SECURITY_INFORMATION SecurityInformation,
    out IntPtr StringSecurityDescriptor, 
    out IntPtr StringSecurityDescriptorLen);

Which changes StringSecurityDescriptorLen to a pointer.

Finally, if you are using .NET 4.0, apparently treatment of calling conventions has been changed and could be something to look at. Read this: https://stackoverflow.com/a/6768223/917090

All the above are really just wild guesses, so caveat lector!

Community
  • 1
  • 1
Paul Walls
  • 5,884
  • 2
  • 22
  • 23