首页 > 解决方案 > 读取活动目录 msDS-ReplAttributeMetaData 的权限

问题描述

我需要msDS-ReplAttributeMetaData在我的 C# 应用程序中从 Active Directory 中读取属性。当我以我的身份运行我的代码时,使用普通DirectorySearcher用户可以看到比以不同用户身份运行时更多的属性。我的 AD 管理员告诉我帐户之间应该没有区别。

有谁知道我可以让他们查看的特定权限?我要阅读的具体项目是在哪里,pszAttributeName以便unicodePwd我可以获得最后的更改日期。

我知道该PwdLastSet属性,但是当帐户设置为永不过期时,密码将经常具有值 0,因此我必须进入元数据。

这是我用来运行查询的代码。

var searcher = new DirectorySearcher {
    SearchRoot = new DirectoryEntry("GC://DC=..."),
    SearchScope = SearchScope.Subtree,
    Filter = "(&(objectCategory=User)(SamAccountName=...))",
    PageSize = 1000
};

var numFound = 0;

try {
    searcher.PropertiesToLoad.Clear();
    searcher.PropertiesToLoad.Add("msDS-ReplAttributeMetaData");


    var result = searcher.FindOne();
    foreach (string xml in result.Properties["msDS-ReplAttributeMetaData"]) {
        numFound++;

        var doc = XDocument.Parse(xml);
        var element = doc.XPathSelectElement("//ftimeLastOriginatingChange[../pszAttributeName='unicodePwd']");
        if (element == null)
            continue;

        Console.WriteLine(element.Value);
    }
} finally {
    searcher.Dispose();
}

Console.WriteLine($"Done - I found {numFound}");

在我的帐户上显示找到 40,而在另一个帐户上显示为 33。

标签: active-directory

解决方案


尝试使用LDAP://而不是GC://. GC 可能会给您不同的结果,因为并非所有属性都复制到全局目录中。该msDS-ReplAttributeMetaData属性是在您请求时构建的,因此取决于您请求构建​​它的服务器。因此,它可能只报告实际复制到该服务器的属性。

如果您最终访问不同域上的服务器(如果您的环境中有多个域),则尤其如此。


推荐阅读