【问题标题】:LDAP Sort with ordering rule fails使用排序规则的 LDAP 排序失败
【发布时间】:2017-07-09 23:11:15
【问题描述】:

我正在尝试对 AD LDS 进行 ldap 查询,以使用户按 cn 属性排序。排序规则不应该是默认的英文,而是应该按照瑞典语进行排序。我正在使用 .Net 中的 System.DirectoryServices.Protocols API 执行此操作。

为了重现,我安装了一个监听端口 389 的 AD LDS 实例,并安装了用户对象类。

使用以下代码(base 是从 Performing a Simple Search 复制而来的)。排序规则取自here

public class LdapSorter
{

    public void SearchUsersSorted()
    {
        string hostOrDomainName = "localhost";
        string targetOu = "cn=Test";

        // create a search filter to find all objects
        string ldapSearchFilter = "(objectClass=user)";

        // establish a connection to the directory
        LdapConnection connection = new LdapConnection(hostOrDomainName);
        connection.SessionOptions.ProtocolVersion = 3;

        Console.WriteLine("\r\nPerforming a simple search ...");

        try
        {
            SearchRequest searchRequest = new SearchRequest
                                            (targetOu,
                                              ldapSearchFilter,
                                              SearchScope.OneLevel,
                                              null);

            searchRequest.Controls.Add(new SortRequestControl("cn", "1.2.840.113556.1.4.1594", false));
            //searchRequest.Controls.Add(new SortRequestControl("cn", false));
            //searchRequest.Controls.Add(new SortRequestControl("cn", true));

            // cast the returned directory response as a SearchResponse object
            SearchResponse searchResponse =
                        (SearchResponse)connection.SendRequest(searchRequest);

            Console.WriteLine("\r\nSearch Response Entries:{0}",
                        searchResponse.Entries.Count);

            // enumerate the entries in the search response
            foreach (SearchResultEntry entry in searchResponse.Entries)
            {
                Console.WriteLine("{0}:{1}",
                    searchResponse.Entries.IndexOf(entry),
                    entry.DistinguishedName);
            }
        }
        catch (DirectoryOperationException e)
        {
            Console.WriteLine("\nUnexpected exception occured:\n\t{0}\n{1}",
                              e, e.Response.ErrorMessage);
            var control = e.Response.Controls.First(c => c is SortResponseControl) as SortResponseControl;
            if (control != null)
            {
                Console.WriteLine("\nControl result: " + control.Result);
            }
        }
    }
}

这是输出:

Performing a simple search ...

Unexpected exception occured:
    System.DirectoryServices.Protocols.DirectoryOperationException: The server does not support the control. The control is critical.
   at System.DirectoryServices.Protocols.LdapConnection.ConstructResponse(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
   at Sort.LdapSorter.SearchUsersSorted() in C:\Source\slask\DotNetSlask\Sort\LdapSorter.cs:line 41
00000057: LdapErr: DSID-0C090A3D, comment: Error processing control, data 0, v3839

Control result: InappropriateMatching

如果使用被注释掉的两个排序请求控件之一,则它可以工作,但使用英文排序顺序。

【问题讨论】:

  • 是否必须将 ProtocolVersion 设置为 3 才能支持版本 3 排序?
  • 你为搜索生成的LDAP命令是什么,你能举个例子供参考吗?从异常或跟踪来看,您的问题似乎是在您到达 LDAP 服务器之前。

标签: .net active-directory ldap adlds


【解决方案1】:

所以,对于它可能是什么,我有两个主要猜测。首先,(看起来你已经有了一些)看看这篇文章。

How to resolve "The server does not support the control. The control is critical." Active Directory error

可能想尝试 auth 部分,看看它是否对您有任何改变。

其次,您用于排序的 OID 是瑞典语(可能是故意的),但如果没有瑞典语语言包(或类似的东西),服务器可能无法以瑞典语进行排序。您可以尝试“英语(美国)”选项(1.2.840.113556.1.4.1499),看看是否会给您带来不同的结果。

编辑:没关系,我想我错过了您帖子的最后一句话 :) 我假设您正在连接到 Windows Server 来运行这些 LDAP 查询?如果是这样,我的猜测是服务器没有安装瑞典语语言包,但我没有使用 LDAP 和外语的经验,所以不能保证会修复它。

【讨论】:

    猜你喜欢
    • 2012-09-11
    • 2012-01-19
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2021-09-10
    • 2018-12-19
    • 2023-04-11
    相关资源
    最近更新 更多