[2024-02-24 12:31] Omar Polo <o...@omarpolo.com>
> Thanks, I have committed the first two diffs (update ber and aldap, and
> request only required attributes), but I'm probably missing something in
> the third diff.

Thanks.

> > From 8498921f8e6c106a04c49586f8045867b4902b4f Mon Sep 17 00:00:00 2001
> > From: Philipp Takacs <phil...@bureaucracy.de>
> > Date: Sun, 18 Feb 2024 18:55:04 +0100
> > Subject: [PATCH 3/4] table-ldap handle more then one result
> > [...]
> > +static int
> > +ldap_query(const char *filter, const char *key, char **attributes, size_t 
> > attrn, struct query_result **results, size_t *nresults)
> >  {
> >     struct aldap_message            *m = NULL;
> >     struct aldap_page_control       *pg = NULL;
> > -   int                              ret, found;
> > -   size_t                           i;
> > +   struct aldap_stringset          *ldap_res;
> > +   struct query_result             *res = NULL;
> > +   int                              ret;
> > +   size_t                           i, j, k, found = 0, nres = 0;
> >     char                             basedn__[MAX_LDAP_BASELEN];
> >     char                             filter__[MAX_LDAP_FILTERLEN];
> >     char                             key__[MAX_LDAP_IDENTIFIER];
> > @@ -363,12 +381,12 @@ ldap_query(const char *filter, const char *key, char 
> > **attributes, struct aldap_
> >             return -1;
> >     if (strlcpy(key__, key, sizeof key__) >= sizeof key__)
> >             return -1;
> > -   found = -1;
> > +
> >     do {
> > -           if ((ret = aldap_search(aldap, basedn__, LDAP_SCOPE_SUBTREE,
> > -               filter__, key__, attributes, 0, 0, 0, pg)) == -1) {
> > -                   log_debug("ret=%d", ret);
> > -                   return -1;
> > +           ret = -1;
> > +           if (aldap_search(aldap, basedn__, LDAP_SCOPE_SUBTREE,
> > +               filter__, key__, attributes, 0, 0, 0, pg) == -1) {
> > +                   goto end;
> >             }
> >             if (pg != NULL) {
> >                     aldap_freepage(pg);
> > @@ -377,59 +395,60 @@ ldap_query(const char *filter, const char *key, char 
> > **attributes, struct aldap_
> >  
> >             while ((m = aldap_parse(aldap)) != NULL) {
> >                     if (aldap->msgid != m->msgid)
> > -                           goto error;
> > +                           goto end;
> >                     if (m->message_type == LDAP_RES_SEARCH_RESULT) {
> >                             if (m->page != NULL && m->page->cookie_len)
> >                                     pg = m->page;
> >                             aldap_freemsg(m);
> >                             m = NULL;
> > -                           if (found == -1)
> > -                                   found = 0;
> > +                           ret = 0;
>
> here we set ret to zero and exit the inner loop, but ret will be set to
> -1 again.  We also optionally set pg to something that's probably
> non-NULL, so it should loop again.
>
> i'm a bit lost.

Each ldap search return some entries and end with a result. So I set
ret to 0 after I have sucessfull seen the result. The result optional
contains a cookie when not all entries are send by the server. The
client can use this cookie to do another search and get more results.
Because each search might fail I set ret to -1 before each search.

I hope this help to understand.

Philipp

Reply via email to