ldap_search_ext返回额外的结果

时间:2013-06-25 21:51:25

标签: c ldap openldap

我有一些c代码根据用户cn查询openldap服务器的用户DN,如下所示。当我使用Apache DS搜索ldap服务器时,只显示结果。然而,我的C代码返回2条记录;一个具有预期用户的DN,另一个具有空白DN的记录!!这第二条记录是什么?这是预期的行为吗?

为了清楚起见,我已将下面的代码示例包含在内,并删除了所有错误检查。

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: ()

2 个答案:

答案 0 :(得分:0)

做了更多的故障排除,我发现有两种方法:

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

现在,我不完全确定'entry'和'message'之间的区别是什么,但至少它部分解决了这个谜。

答案 1 :(得分:0)

ldap_count_entries及其相关例程(ldap_first_entryldap_next_entry)仅返回条目,即搜索结果。

ldap_count_messages(和ldap_first_messageldap_next_message)也包含搜索引用,即对其他服务器或命名上下文的引用。

Source。我发现旧的Mozilla LDAP文档对于解释LDAP概念非常有用。