2013-06-25 109 views
0

我有一些c代碼根據用戶cn爲用戶DN查詢openldap服務器,如下所示。當我使用Apache DS搜索ldap服務器時,僅顯示結果。我的C代碼返回2條記錄;一個與預期的用戶DN一樣,另一個記錄與空白DN!這是第二個記錄是什麼?這是預期的行爲?ldap_search_ext返回額外結果

爲了清晰起見,我已經包含下面的代碼示例,並刪除了所有錯誤檢查。

ldap_search_ext(ld, (char *)baseDN, LDAP_SCOPE_SUBTREE, "(&(objectClass=person)(cn=test00002))", NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &msgid); 
ldap_result(ld, msgid, 1, NULL, &res); 
numUsersFound = ldap_count_messages(ld, res); 
syslog(LOG_DEBUG, "DEBUG Number of users found: (%d)", numUsersFound); 

結果

DEBUG Number of users found: 2 
DEBUG User DN: (cn=test00002,ou=defaultRealm,dc=company,dc=com) 
DEBUG User DN:() 

回答

0

做了一些更多的故障診斷,我發現,有2種方法:

> int ldap_count_entries(LDAP *ld, LDAPMessage *result); => returns 1 
> int ldap_count_messages(LDAP *ld, LDAPMessage *result); => returns 2 

現在,我不能完全肯定有什麼區別「進入」之間和'消息',但至少它部分解決了這個謎團。

0

ldap_count_entries及其相關例程(ldap_first_entryldap_next_entry)只返回條目,即搜索結果。

ldap_count_messages(和ldap_first_message,ldap_next_message)也包括搜索引用,即對其他服務器或命名上下文的引用。

Source。我發現舊的Mozilla LDAP文檔對於解釋LDAP概念非常有用。