【问题标题】:Why ConvertSecurityDescriptorToStringSecurityDescriptor produce different SDDL when directory inheritance is changed?为什么在更改目录继承时 ConvertSecurityDescriptorToStringSecurityDescriptor 会产生不同的 SDDL?
【发布时间】:2014-01-31 03:40:56
【问题描述】:

我们使用 SDDL 来比较目录权限。

在大多数情况下,当我使用 ConvertSecurityDescriptorToStringSecurityDescriptor 或 GetSecurityDescriptorSddlForm 时,我会得到相同的结果 (SDDL)。

但是当目录权限继承发生变化时,下面的伪代码会产生不同的字符串(SDDL)。

在 Win32 实现中我需要做什么才能使其产生与 .Net 相同的 SDDL?

Win32(从 .Net 应用程序调用):

IntPtr pSidOwner = IntPtr.Zero;
IntPtr pSidGroup = IntPtr.Zero;
IntPtr pDacl = IntPtr.Zero;
IntPtr pSacl = IntPtr.Zero;
IntPtr pSecurityDescriptor = IntPtr.Zero;
uint errorReturn = GetNamedSecurityInfo(path, SE_OBJECT_TYPE.SE_FILE_OBJECT, ACS, out pSidOwner, out pSidGroup, out pDacl, out pSacl, out pSecurityDescriptor);
if (errorReturn != 0)
{
   throw new Win32Exception((int)errorReturn);
}

int len = 0;
IntPtr pBuffer = IntPtr.Zero;
if (ConvertSecurityDescriptorToStringSecurityDescriptor(pSecurityDescriptor, 1, si, out pBuffer, out len))
{
    String sddl = Marshal.PtrToStringAuto(pBuffer);
}

.Net 4.5:

 FileSystemSecurity fss = Directory.GetAccessControl(path);
 String sddl = fss.GetSecurityDescriptorSddlForm(ACS);

ACS = 所有者和 DACL


[编辑]

问题是在其他地方发现的

我怀疑该命令,但在进一步调查后发现问题是代码中缺少使用 SDDL 字符串的标志。
显然,在调用SetNamedSecurityInfo 来设置DACL 时,我必须同时使用DACL_SECURITY_INFORMATIONUNPROTECTED_DACL_SECURITY_INFORMATION。添加标志解决了这个问题。

感谢哈利对此进行调查!

【问题讨论】:

  • 请举个例子。
  • 我创建了一个文件夹并删除了继承(转换为显式)C#调用 sddl=O:S-1-5-21-774854172-2599166104-2634027179-1003D:PAI(A;OICI;0x1301bf; ;;AU)(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;0x1200a9;;;BU)(A;OICI;0x1200a9;;;S-1- 5-21-774854172-2599166104-2634027179-1010) Win32 调用 sddl=O:S-1-5-21-774854172-2599166104-2634027179-1003D:PAI(A;OICI;0x1200a9;;;S-1-5 21-774854172-2599166104-2634027179-1010)(A;OICI;FA;;;BA)(A;OICI;FA;;;SY)(A;OICI;0x1200a9;;;BU)(A;OICI;0x1301bf; ;;AU)
  • 看起来 FileSystemSecurity 正在重新排序 ACE。我最好的猜测是它们是按关联的 SID 排序的,在您提供的示例中,SID 是升序的(S-1-5-11、S-1-5-18、S-1-5-21-.. .-544, S-1-5-21-...-545, S-1-5-21-...-1010)。
  • 当然,由于这是未记录的,它可能取决于 .NET 和/或操作系统的特定版本。根据您要实现的目标,您可能需要自己重新排序两个 SDDL 以确保获得一致的结果。
  • 已解决。我怀疑该命令,但经过进一步调查后发现问题是使用 SDDL 字符串的代码中缺少标志。显然,在调用 SetNamedSecurityInfo 时,您需要同时使用 DACL_SECURITY_INFORMATIONUNPROTECTED_DACL_SECURITY_INFORMATION。添加标志解决了这个问题。感谢 Harry 对此进行调查!

标签: c# .net windows winapi directory


【解决方案1】:

该问题在其他地方发现(请参阅编辑了解详细信息)

我们发现ConvertSecurityDescriptorToStringSecurityDescriptorGetSecurityDescriptorSddlForm 生成相同的SDDL 字符串(在某些情况下不同的顺序)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多