On 2024/02/19 16:13:49 +0100, Philipp <phil...@bureaucracy.de> wrote: > Hi > > Omar has sugested to update ber. I have implemented this and rebased > my patches to this. > > The "update ber and aldap" patch is acually not correct, because the > aldap_match_attr() has a changed API. The result might not used after > the message was freed. > > The updated aldap also adds the posibility for ldap+tls (starttls) and > ldapi. This is not yet implemented. > > Philipp
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. > 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. > break; > } > if (m->message_type != LDAP_RES_SEARCH_ENTRY) > - goto error; > + goto end; > > - found = 1; > - for (i = 0; i < n; ++i) > - if (aldap_match_attr(m, attributes[i], > &outp[i]) != 1) > - goto error; > + if (found >= nres) { > + if (!realloc_results(&res, &nres)) { > + goto end; > + } > + } > + memset(&res[found], 0, sizeof(res[found])); > + for (i = 0; i < attrn; ++i) { > + if (aldap_match_attr(m, attributes[i], > &ldap_res) != 1) { > + goto end; > + } > + res[found].v[i] = calloc(ldap_res->len + 1, > sizeof(*res[found].v[i])); > + for (j = 0; j < ldap_res->len; j++) { > + res[found].v[i][j] = > strndup(ldap_res->str[j].ostr_val, ldap_res->str[j].ostr_len); > + } > + aldap_free_attr(ldap_res); > + } > aldap_freemsg(m); > m = NULL; > + found++; > } > } while (pg != NULL); > > - ret = found; > - goto end; > - > -error: > - ret = -1; > - > end: > - if (m) > - aldap_freemsg(m); > - log_debug("debug: table_ldap: ldap_query: filter=%s, ret=%d", filter, > ret); > - return ret; > -}