【问题标题】:Get Group Permissions from LDAP with C# (READ ACL)使用 C# 从 LDAP 获取组权限(阅读 ACL)
【发布时间】:2019-04-23 19:05:25
【问题描述】:

我喜欢从组中获取权限。 例如此组中的用户可以读取或写入...

我使用 Microsoft ActiveDirectory。

使用 DirectorySearcher 我这样搜索:

DirectorySearcher searcher = new DirectorySearcher(rootDSE)
{
    Filter = searchString,
    //SecurityMasks = SecurityMasks.Dacl | SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Sacl
    SecurityMasks = SecurityMasks.Dacl | SecurityMasks.Group
    //SecurityMasks = SecurityMasks.Dacl
    //SecurityMasks = SecurityMasks.Group
            };

ntSecurityDescriptor 是我的代码中的一个字节数组

group["ntSecurityDescriptor"][0] as byte[]

到目前为止一切顺利

现在我将尝试列出权限:

static void ReadAccess(byte[] sec)
{
    System.DirectoryServices.ActiveDirectorySecurity retVal = new System.DirectoryServices.ActiveDirectorySecurity();
    retVal.SetSecurityDescriptorBinaryForm(sec);

    //AuthorizationRuleCollection arc = retVal.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount));
    AuthorizationRuleCollection arc = retVal.GetAccessRules(true, false, typeof(System.Security.Principal.SecurityIdentifier));

    Console.WriteLine("\n\n");
    //AuthorizationRule || ActiveDirectoryAccessRule
    foreach (ActiveDirectoryAccessRule acr in arc)
    {
        string sid = null;
        try
        {
            sid = (acr.IdentityReference).Translate(typeof(NTAccount)).Value;
        }
        catch { }

        bool all = acr.ActiveDirectoryRights == ActiveDirectoryRights.GenericAll;
        bool read = acr.ActiveDirectoryRights == ActiveDirectoryRights.GenericRead;
        bool write = acr.ActiveDirectoryRights == ActiveDirectoryRights.GenericWrite;
        bool execute = acr.ActiveDirectoryRights == ActiveDirectoryRights.GenericExecute;
        bool extended = acr.ActiveDirectoryRights == ActiveDirectoryRights.ExtendedRight;

        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", all, read, write, execute, extended);
        Console.WriteLine("{0}\t{1}\t{2}", acr.ActiveDirectoryRights, acr.AccessControlType, sid);
        Console.WriteLine("\n");
    }
}

不明白结果

我想我走错路了 => 我希望任何人都可以帮助我

【问题讨论】:

  • 哪部分不明白?我可以帮忙解释,但我不知道该解释什么部分:)
  • 谢谢。这是一个基本的沟通问题。我想找出组“ADM_Group”对组“Group”有什么权利。目的是找出是否允许“ADM_Group”中的用户“XY”将用户添加到“Group”,以及可以编辑组“Group”的其他方向。可能是我的做法不对,因为这里只能过滤文件夹权限!?

标签: c# permissions active-directory ldap


【解决方案1】:

如果我的理解正确,您会在您的组中看到“ADM_Group”的权限,但是当您查看代码中的权限时,您看不到该权限。

您通过在GetAccessRules() 的第二个参数中传递false 来排除继承的权限:

retVal.GetAccessRules(true, false, typeof(System.Security.Principal.SecurityIdentifier))

因此,如果它是授予“ADM_Group”权限的继承权限,那么也许这就是您看不到它的原因。

在 AD 用户和计算机中,您可以单击“高级”(或在您的情况下为“Erweitert”)以查看权限中的每个单独的 ACL。屏幕截图中的视图结合了 ACL 以提供权限的简化视图。

【讨论】:

  • 是否可以查看组“ADM_Group”在“Group”中具有哪些访问权限?例如他可以更改用户...
猜你喜欢
  • 2017-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-12
  • 1970-01-01
  • 2011-04-29
  • 2016-04-14
相关资源
最近更新 更多