tags:

views:

41

answers:

3

Hi there.

I am performing an LDAP search query in C like so;

ldap_search_ext_s(ld, BASEDN, SCOPE, FILTER, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res);

My search performs fine except when I try to specify FILTER to be; #define FILTER "uid=*", that is, when I try to run a search for all LDAP entries with a uid.

Unfortunately my code just returns the first entry for each result that it finds. So, my code might find 50 results, but will return the first entry 50 times.

Can anyone suspect what I might be doing wrong here?

EDIT: I am stepping through my results like so:

for (msg = ldap_first_message(ld, res); msg != NULL; msg = ldap_next_message(ld, msg))

Any help is really appreciated. Ricky.

A: 

How are you stepping through the results? Your code should be something like:

LDAPMessage *entry;

for (entry = ldap_first_entry(ld, res); entry != NULL; entry = ldap_next_entry(ld, entry)
{
    /* Examine "entry" */
}

In particular, make sure you are passing entry to ldap_next_entry, and not res.

caf
Hi caf, thanks for your reply. I've edited my original post to demonstrate how I'm stepping through my results - it's exactly how you recommended, but the result is the same.
Ricky
I believe you need to use `ldap_*_entry()` instead of `ldap_*_message()`.
caf
I replaced both instances of `ldap_*_message` with `ldap_*_entry`, but I am still getting the same result.
Ricky
A: 

Have you checked that the query works as expected when using, e.g. the command line search tool (assuming you have the OpenLDAP utilities available)?

ldapsearch -b BASEDN '(uid=*)'
TimB
A: 

Sorry everyone. A friend of mine pointed out that I should be passing msg to the ldap_first_entry commands and the like. This resolved the issue and returned each result individually.

Thanks for all your help. Ricky.

Ricky