2

Openldap supportedControl listed: 1.3.6.1.4.1.42.2.27.8.5.1 (Password policy)

Using .Net DirectoryServices.Protocols, I've exhausted all possible methods of retrieving the response information provided by this control.

I'm using the latest Openldap Source built/running locally in a Cygwin environment with all PPolicy related config enabled in the build and the PPolicy configured and working/tested.

By modifying an example from the directory services programming guide, link: http://dunnry.com/blog/2006/05/11/DotNetDevGuideToDirectoryServicesCompanionSiteLaunched.aspx

, to use a SearchRequest populated with a DirectoryControl configured to request the

Password Policy, gets me nothing. Everything looks good in the Server Source: http://www.openldap.org/devel/gitweb.cgi?p=openldap.git;a=blob_plain;f=servers/slapd/overlays/ppolicy.c;hb=HEAD

Has anyone had any luck using .Net DirectoryControls in a SearchRequest?

Here is some code I've been trying:

    _authConnect.AuthType = AuthType.Basic;
// credentials.UserName is a user DN format, w/password and null domain
_authConnect.Credential = credentials;
Debug.WriteLine("PV: " + _authConnect.SessionOptions.ProtocolVersion);

var sr = //new ExtendedRequest();
         new SearchRequest(credentials.UserName, "(objectclass=*)", SearchScope.Base, null);
         //new DsmlAuthRequest(credentials.UserName);
        var isCritical = false;
    var ppolicy = "1.3.6.1.4.1.42.2.27.8.5.1";
        // ppolicy request and response control is referred to by the same OID
        sr.Controls.Add(new DirectoryControl(ppolicy, null, isCritical, true));
    sr.Controls.Add(new DirectoryControl(ppolicy, new byte[8], isCritical, false));

try
{
  var response = (SearchResponse)_authConnect.SendRequest(sr);
  DirectoryControl[] c = response.Controls;
  if (c.Rank > 0 && c.GetLength(0) > 0)
  {
     Debug.WriteLine(c[0].Type + " value: " + c[0].GetValue());
  }
  SearchResultEntry entry = response.Entries[0];
  c = entry.Controls;
  if (c.Rank > 0 && c.GetLength(0) > 0)
  {
     Debug.WriteLine(c[0].Type + " value: " + c[0].GetValue());
  }  
  return true;
}
catch (LdapException ex)
{
  Debug.WriteLine(ex.Message);
}
4

1 回答 1

0

我和你有同样的问题,尝试了很多事情都没有成功,然后就没有时间了。我注意到的问题是 openldap 只在绑定请求中发送密码过期信息。我通过启用服务器上的所有日志记录发现了这一点。所以我开始尝试找到一种方法来使用带有绑定请求的目录控件。我找不到使用 S.DS.P LdapConnection 类的方法。然后我开始修改连接对象并获取 ldaphandle 变量。有了它,我可以像 S.DS.P 一样使用它直接调用 c-api。我环顾了一下 openldap 的源代码,注意到它的工具使用了 sasl 绑定机制,而没有在该库中使用控件的简单绑定机制。它在 winldap 中的工作方式不同。如果这样做,它将返回错误的参数响应代码。我尝试的最后一件事是调用 ldap_bind 的异步版本并读回消息。不幸的是,响应中没有任何控制。我认为,由于我没有发送它们,因此即使 openldap 日志文件说它正在设置警告,它们也没有被退回。这是我使用任何内置 winldap 绑定方法的唯一希望。

我要尝试但没有时间的最后一件事是使用控件构造我自己的绑定消息,并使用 ldap_extended_operation_s 函数将它们发送到服务器。 http://msdn.microsoft.com/en-us/library/aa366580(v=VS.85).aspx 如果我在这个项目上有一些额外的时间,我可能会回去尝试一下。如果我这样做,我会在这里报告。最终,如果这是解决方案,使用 Novell 的 ldapcsharp 库可能会更容易。看起来可以使用它发送带有服务器控件的绑定请求。我只探索了 winldap api,因为我对它有点熟悉,而且我们已经非常熟悉使用 DirectoryServices.Protocols。

于 2011-08-05T20:35:30.057 回答