【发布时间】:2017-05-26 11:08:16
【问题描述】:
最初的问题始于 .NET\C# 和 ValidateCredentials 方法 - 没有 SSL 它可以工作,使用 SSL 它会返回“服务器无法处理目录请求”。但我缩小了范围并简化为下面发布的 C++ 代码。
MSDN 说 LDAP_OPT_FAST_CONCURRENT_BIND 支持多个简单绑定,并且不适用于接下来的 2 个选项:LDAP_OPT_SIGN、LDAP_OPT_ENCRYPT。它还说使用不带 SSL 的简单绑定是not good,因为当通过网络发送时,您将以明文形式公开您的凭据。
因此,当您在没有签名和加密的情况下通过 SSL 使用 LDAP 时,您似乎可以启用 FCB。但每次我这样做时,我都会收到 0x35(不愿意执行)。 Article 关于密码认证也没有提到 SSL。所以,问题是 - 我做错了什么?或者,Microsoft 是否应该在其文档中声明 LDAP_OPT_FAST_CONCURRENT_BIND 不支持 SSL?
#include "stdafx.h"
#include <windows.h>
#include <winldap.h>
int main()
{
PCHAR username = "bla-bla-bla";
PCHAR password = "bla-bla-bla";
PCHAR hostName = "bla-bla-bla";
ULONG lRtn = 0;
LDAP* pLdapConnection = NULL;
pLdapConnection = ldap_init(hostName, LDAP_PORT);
// NOTE: those 2 below - will return 0x35 (Unwilling to perform) during setting LDAP_OPT_FAST_CONCURRENT_BIND option
//pLdapConnection = ldap_init(hostName, LDAP_SSL_PORT);
//pLdapConnection = ldap_sslinit(hostName, LDAP_SSL_PORT, 1);
if (pLdapConnection == NULL)
{
printf("ldap_init failed with 0x%x.\n", LdapGetLastError());
ldap_unbind(pLdapConnection);
return -1;
}
else
printf("ldap_init succeeded \n");
lRtn = ldap_connect(pLdapConnection, NULL);
if (lRtn == LDAP_SUCCESS)
printf("ldap_connect succeeded \n");
else
{
printf("ldap_connect failed with 0x%lx.\n", lRtn);
ldap_unbind(pLdapConnection);
return -1;
}
// Enable concurrent binding - returns 0x35 when used with SSL.
lRtn = ldap_set_option(pLdapConnection, LDAP_OPT_FAST_CONCURRENT_BIND, LDAP_OPT_ON);
if (lRtn == LDAP_SUCCESS)
printf("Fast concurrent binding enabled\n");
else
{
printf("SetOption Error:%0lX\n", lRtn);
ldap_unbind(pLdapConnection);
return -1;
}
lRtn = ldap_simple_bind_s(pLdapConnection, username, password);
if (lRtn == LDAP_SUCCESS)
{
printf("ldap_simple_bind_s succeeded \n");
password = NULL; // Remove password pointer
}
else
{
printf("ldap_bind_s failed with 0x%lx.\n", lRtn);
ldap_unbind(pLdapConnection);
return -1;
}
ldap_unbind(pLdapConnection);
return 0;
}
【问题讨论】:
-
发现应该启用服务器支持才能使用 FCB:msdn.microsoft.com/en-us/library/cc223355.aspx。而且我在我的服务器的 RootDSE 中看不到那个 OID。奇怪的是它在没有 SSL 的情况下仍然可以工作。
标签: c# ssl active-directory ldap directoryservices