iPlanet LDAP and C# PageResultRequestControl

2020-01-29 18:22发布

问题:

I am trying to do a paged search on an iPlanet LDAP. Here's my code:

LdapConnection ldap = new LdapConnection("foo.bar.com:389");
ldap.AuthType = AuthType.Anonymous;
ldap.SessionOptions.ProtocolVersion = 3;
PageResultRequestControl prc = new PageResultRequestControl(1000);
string[] param = new string[] { "givenName" };
SearchRequest req = new SearchRequest("ou=people,dc=bar,dc=com", "(ou=MyDivision)", SearchScope.Subtree, param);
req.Controls.Add(prc);
while (true)
{
    SearchResponse sr = (SearchResponse)ldap.SendRequest(req);
    ... snip ...
}

When I run this, I get an exception that states "The server does not support the control. The control is critical" on the line before the snip. Quick Google search turns up nothing. Does iPlanet support paging? If so, what am I doing wrong? Thanks.

回答1:

All LDAP v3 compliant directories must contain a list of OIDs for the controls that the server supports. The list can be accessed by issuing a base-level search with a null/empty search root DN to get the directory server root DSE and reading the multi-value supportedControl-attribute.

The OID for paged search support is 1.2.840.113556.1.4.319.

Here's a code snippet to get you started:

LdapConnection lc = new LdapConnection("ldap.server.name");
// Reading the Root DSE can always be done anonymously, but the AuthType
// must be set to Anonymous when connecting to some directories:
lc.AuthType = AuthType.Anonymous;
using (lc)
{
  // Issue a base level search request with a null search base:
  SearchRequest sReq = new SearchRequest(
    null,
    "(objectClass=*)",
    SearchScope.Base,
    "supportedControl");
  SearchResponse sRes = (SearchResponse)lc.SendRequest(sReq);
  foreach (String supportedControlOID in
    sRes.Entries[0].Attributes["supportedControl"].GetValues(typeof(String)))
  {
    Console.WriteLine(supportedControlOID);
    if (supportedControlOID == "1.2.840.113556.1.4.319")
    {
      Console.WriteLine("PAGING SUPPORTED!");
    }
  }
}

I don't think iPlanet supports paging but that might depend on the version you're using. Newer versions of Sun-made directories seem to support paging. You're probably best off checking your server using the method I've described.



标签: c# ldap