【问题标题】:How do I figure out what the values are for SECURITY_INFORMATION?如何确定 SECURITY_INFORMATION 的值是什么?
【发布时间】:2012-11-08 12:50:20
【问题描述】:

所以我现在正在尝试操作几个 pinvoke 函数,但我不知道在哪里可以找到 SECURITY_INFORMATION 中每个标志的值?

这里是link

我已经访问过 PInvoke 站点,它对 SECURITY_INFORMATION 的定义似乎不正确。 Here

我认为它不正确的原因是因为我在尝试调用 ConvertSecurityDescriptorToStringSecurityDescriptor 方法时抛出了以下错误。

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.

但我再次有兴趣弄清楚如何找到我提供的 MSDN 文章中列出的每个标志的十六进制值。就好像人们只是神奇地生成了这些值并且它们是正确的,即使在那篇文章中没有任何记录它们的迹象。

编辑 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
}

【问题讨论】:

  • 为什么在调用 ConvertStringSecurityDescriptorToSecurityDescriptor 时使用 SECURITY_INFORMATION 标志?
  • 因为我没有调用 ConvertStringSecurityDescriptorToSecurityDescriptor 我正在调用 ConvertSecurityDescriptorToStringSecurityDescriptor。
  • 噢!是的,那会更有意义。您可以发布用于函数调用的 PInvoke 签名吗?
  • 有签名和标志,但我的问题是它们如何为枚举生成这些值。十六进制值。

标签: c# pinvoke msdn


【解决方案1】:

有几件事可以尝试。第一:

[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
}

注意底层类型更改为uint。值为defined here

如果还是不行,那就试试吧:

[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);

这会将StringSecurityDescriptorLen 更改为指针。

最后,如果您使用的是 .NET 4.0,显然对调用约定的处理方式已经改变,值得关注。阅读:https://stackoverflow.com/a/6768223/917090

以上内容纯属胡乱猜测,请老师注意!

【讨论】:

    猜你喜欢
    • 2012-11-05
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 2013-04-02
    • 1970-01-01
    相关资源
    最近更新 更多