0

我可以通过以下代码行检查用户是否是域管理员:

using (DirectoryEntry domainEntry = new DirectoryEntry(string.Format("LDAP://{0}", domain)))
{
    byte[] domainSIdArray = (byte[])domainEntry.Properties["objectSid"].Value;

    SecurityIdentifier domainSId = new SecurityIdentifier(domainSIdArray, 0);
    SecurityIdentifier domainAdminsSId = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, domainSId);

    using (DirectoryEntry groupEntry = new DirectoryEntry(string.Format("LDAP://<SID={0}>", BuildOctetString(domainAdminsSId))))
    {
        string adminDn = groupEntry.Properties["distinguishedname"].Value as string;
        SearchResult result = (new DirectorySearcher(domainEntry, string.Format("(&(objectCategory=user)(samAccountName={0}))", userName), new[] { "memberOf" })).FindOne();
        return result.Properties["memberOf"].Contains(adminDn);
    }
}

更多细节在这里

但是当域控制器关闭或离线(没有任何连接)时,我收到以下错误:

服务器无法运行。

在 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
在 System.DirectoryServices.DirectoryEntry.Bind()
在 System.DirectoryServices.DirectoryEntry.get_AdsObject()
在 System.DirectoryServices.PropertyValueCollection.PopulateList()
在 System.DirectoryServices.PropertyValueCollection..
System.DirectoryServices.PropertyCollection.get_Item(String propertyName ) 处的 ctor(DirectoryEntry entry, String propertyName)

是否有能力检查用户是否是关闭域控制器的域管理员?

4

1 回答 1

1

您可以在不联系域控制器的情况下检查当前用户是否是域管理员。

如果您的要求是检查任意用户是否是域管理员,我认为没有域控制器就无法做到。

确实,Windows 会为断开连接的登录目的缓存登录凭据。缓存以HKEY_LOCAL_MACHINE\SECURITY\Cache. 按照设计,缓存只能由 LSA 解密。如果你找到了一些其他方法来解密或查询信息而不通过 LSA,这是一个安全漏洞,微软可能会立即修复它。因此,您唯一的希望是 LSA 以某种方式公开一个 API 来查询存储在凭证缓存中的组信息。据我所知,我没有看到这样的 API 存在。有关文档化的 LSA API,请参见此处

于 2012-08-18T17:09:48.300 回答