0
votes

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.

3
I have tried that but the result is the same.Ricky

3 Answers

1
votes

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.

1
votes

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.

0
votes

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=*)'