繁体   English   中英

获取给定LDAP服务器的全局目录

[英]Get Global Catalog for a given LDAP server

首先是问题,稍后是解释: 如何获得给定LDAP服务器的GC服务器?

为了理解我的需求,让我解释一下:

我必须扩展Henning Krause的ExchangeAddressListService (我不确定是否应该/可以将Henning的所有代码都放到这篇文章中吗?)以获得有用的调试输出:

private DirectoryEntry GetDirectoryEntry(string path, string protocol)
{
    var ldapPath = string.IsNullOrEmpty(path) ? string.Format("{0}:", protocol) : string.Format("{0}://{1}", protocol, path);
    dbg.Add("Getting DirectoryEntry for path " + ldapPath);
    return new DirectoryEntry(ldapPath);
}
public ActiveDirectoryConnection(Debug dbg)
{
    this.dbg = dbg;
}

并允许选择某个域:

internal AddressList(string path, ActiveDirectoryConnection connection, string domain)
{
    _Path = path;
    _Connection = connection;
    _Domain = domain;
}

...

private IEnumerable<AddressList> GetAddressLists(string containerName)
{
    string exchangeRootPath;
    using (var root = _Connection.GetLdapDirectoryEntry(_Domain+"/RootDSE"))
    ...
        foreach (SearchResult addressBook in searchResultCollection)
        {
            yield return
                new AddressList((string)addressBook.Properties["distinguishedName"][0], _Connection, _Domain);
        }
    ...
}

现在我对域有问题,因为似乎对于某些域SOMEDOMAIN ,无法通过GC://SOMEDOMAIN访问全局目录。 这是我使用的代码:

var domain = User.Identity.Name.Split('\\')[0]; // SOMEDOMAIN\SomeUser -> Domain is SOMEDOMAIN
dbg.Add("User NETBIOS domain is "+domain);
AddressListService addressListService = new ExchangeAddressListService(connection,domain);
IEnumerable<AddressList> addressLists = addressListService.GetGlobalAddressLists();
AddressList addressList = addressLists.First()
try {
    IEnumerable<SearchResult> searchResults = addressList.GetMembers("displayName", "distinguishedname", "mail")
} catch(Exception e) {
    dbg.Add("Error in GetMembers: "+e.Message);
    return new AjaxAnswer(dbg.Flush());
}

它产生错误日志:

User NETBIOS domain is SOMEDOMAIN
Getting DirectoryEntry for path LDAP://SOMEDOMAIN/RootDSE
Getting DirectoryEntry for path LDAP://CN=Microsoft Exchange, CN=Services, CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path LDAP://CN=All Global Address Lists,CN=Address Lists Container, CN=MYMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path LDAP://CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=MYMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path GC://SOMEDOMAIN
Error in GetMembers: The server is not operational.

并非所有DC都是GC。 因此,如果SOMEDOMAIN不是GC, GC://SOMEDOMAIN可能会失败。
在我的项目中,我使用DsGetDcName Win32函数来发现GC。

DsGetDcName函数的详细信息:

http://msdn.microsoft.com/en-us/library/ms675983%28v=vs.85%29.aspx

请参阅以下有关如何拨通呼叫的电话:

http://www.pinvoke.net/default.aspx/netapi32.dsgetdcname

据我所知System.DirectoryServices.ActiveDirectory还提供了用于处理GC的类。
例如Forest.GlobalCatalogs
我已经使用了DsGetDcName函数,所以以前从未尝试过。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM