2012-06-21 35 views
2

我正在嘗試執行LDAP搜索,但它不在我的Active Directory測試服務器上工作。我使用此代碼:在AD服務器上使用winldap.h進行LDAP搜索

#include <winldap.h> 
... 
LDAP* ld = ldap_init("AD-servername", 389); 
int myVersion =LDAP_VERSION3; 
ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &myVersion); 
ldap_connect(ld, NULL); 
//ldap_simple_bind_s(ld, NULL, NULL); I tried using this line too. but got the same error 
LDAPMessage *pMsg = NULL; 
int retVal = ldap_search_s(ld, "dc=myDomain,dc=extension", LDAP_SCOPE_SUBTREE, "(samAccountName=testaccount)", NULL, NULL, &pMsg); 
//retVal = 1 which is LDAP_OPERATIONS_ERROR 

我在做什麼錯了?

+0

的值由 'ldap_set_option' 和 'ldap_connect' 回來怎麼辦?你有沒有試過只使用一個DN而不是2?嘗試使用一些簡單的過濾器。 – besworland

+0

'ldap_set_option'和'ldap_connect'返回'LDAP_SUCCESS'。我的實際DN是'dc = dl,dc = intern',這是我的域名 - >'dl.intern'。 –

回答

3

除非另有配置,您必須使用有效的帳戶名和Microsoft Active Directory服務器的密碼,否則將返回錯誤操作所有查詢,除了a very small handful綁定。

即說:

ldap_simple_bind_s(ld, NULL, NULL); 

需要與像被替換:

char *username = "cn=aUser,ou=Users,dc=myDomain,dc=extension"; 
char *password = "this is the password"; 
ldap_simple_bind_s(ld, username, password); 
+0

太棒了 - 現在可以使用了! –

+0

對,我沒有注意到這一點。 – besworland

相關問題