Windows 2008 서버에 Active Directory 서비스를 설치했습니다. 사용자를 추가했으며 여기서 DN (DistingushedName)입니다. CN=ashwin,CN=Users,DC=test,DC=com
Windows Active Directory에서 LDAP의 ldap_search_s()가 실패합니다.
DN에 대해 설정된 암호가 없으며 익명 바인드가 허용됩니다. AD에 연결하여 사용자를 검색하는 샘플 (테스트 코드) C++ 프로그램이 있습니다.
#include "windows.h"
#include "winldap.h"
#include "stdio.h"
// Entry point for your application
int main(int argc, char* argv[])
{
LDAP* pLdapConnection = NULL;
INT returnCode = 0;
INT connectSuccess = 0;
ULONG version = LDAP_VERSION3;
LONG lv = 0;
int option(0);
LDAPMessage *vLdapMessage;
// Initialize an LDAP session without SSL.
pLdapConnection = ldap_init("192.168.56.128",389);
if (pLdapConnection == NULL)
{
printf("ldap_init failed with 0x%x.\n",hr);
return -1;
}
// Specify version 3; the default is version 2.
returnCode = ldap_set_option(pLdapConnection,
LDAP_OPT_PROTOCOL_VERSION,
(void*)&version);
if (returnCode != LDAP_SUCCESS)
goto FatalExit;
//Turning off referrals
ldap_set_option(pLdapConnection, LDAP_OPT_REFERRALS, LDAP_OPT_OFF); // required
// Connect to the server.
connectSuccess = ldap_connect(pLdapConnection, NULL);
if(connectSuccess != LDAP_SUCCESS)
{
printf("ldap_connect failed with 0x%x.\n",connectSuccess);
goto FatalExit;
}
// Bind with current credentials.
printf("Binding ...\n");
returnCode = ldap_bind_s(pLdapConnection,NULL, NULL, LDAP_AUTH_SIMPLE);
if (returnCode != LDAP_SUCCESS)
goto FatalExit;
returnCode = ldap_search_s(pLdapConnection, "DC=test, DC=com", LDAP_SCOPE_SUBTREE, "CN=ashwin", NULL, 0, &vLdapMessage);
if (returnCode != LDAP_SUCCESS)
goto FatalExit;
NormalExit:
if (pLdapConnection != NULL)
ldap_unbind_s(pLdapConnection);
return 0;
FatalExit:
if(pLdapConnection != NULL)
ldap_unbind_s(pLdapConnection);
printf("\n\nERROR: 0x%x\n", returnCode);
return returnCode;
}
검색에 실패했습니다. ldap_search_s
은 항상 1을 리턴합니다. Apache 디렉토리 서비스에 대한 동일한 설정 테스트가 정상적으로 작동합니다.
누군가가 Windows AD에서 작동하지 않는 이유를 지적 할 수 있습니까? 프로그램에서 무엇이 잘못 되었습니까?