X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Flookups%2Fldap.c;h=08f68b75e6af285cfac6deb886bc60f243ecfa6c;hb=436bda2ac0c4a245815db3fc1ef2aedee05eab8d;hp=2ebe734cd2c074c312bc38c1da2238992cd504d0;hpb=d9cb3c4537f82c8663c19c391bd727235916db6c;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/lookups/ldap.c b/src/src/lookups/ldap.c index 2ebe734cd..08f68b75e 100644 --- a/src/src/lookups/ldap.c +++ b/src/src/lookups/ldap.c @@ -143,8 +143,6 @@ LDAP_CONNECTION *lcp; struct timeval timeout; struct timeval *timeoutptr = NULL; -uschar *attr; -uschar **attrp; gstring * data = NULL; uschar *dn = NULL; uschar *host; @@ -245,7 +243,7 @@ if (host) /* Count the attributes; we need this later to tell us how to format results */ -for (attrp = USS ludp->lud_attrs; attrp && *attrp; attrp++) +for (uschar ** attrp = USS ludp->lud_attrs; attrp && *attrp; attrp++) attrs_requested++; /* See if we can find a cached connection to this host. The port is not @@ -730,7 +728,7 @@ while ((rc = ldap_result(lcp->ld, msgid, 0, timeoutptr, &result)) == sequence of name=value pairs, separated by (space), with the value always in quotes. If there are multiple values, they are given within the quotes, comma separated. */ - else for (attr = US ldap_first_attribute(lcp->ld, e, &ber); + else for (uschar * attr = US ldap_first_attribute(lcp->ld, e, &ber); attr; attr = US ldap_next_attribute(lcp->ld, e, ber)) { DEBUG(D_lookup) debug_printf("LDAP attr loop\n"); @@ -776,9 +774,7 @@ while ((rc = ldap_result(lcp->ld, msgid, 0, timeoutptr, &result)) == internal quotes, backslashes, newlines, and must double commas. */ if (attrs_requested != 1) - { - int j; - for (j = 0; j < len; j++) + for (int j = 0; j < len; j++) { if (value[j] == '\n') data = string_catn(data, US"\\n", 2); @@ -791,19 +787,15 @@ while ((rc = ldap_result(lcp->ld, msgid, 0, timeoutptr, &result)) == data = string_catn(data, value+j, 1); } } - } /* For single attributes, just double commas */ else - { - int j; - for (j = 0; j < len; j++) + for (int j = 0; j < len; j++) if (value[j] == ',') data = string_catn(data, US",,", 2); else data = string_catn(data, value+j, 1); - } /* Move on to the next value */ @@ -840,13 +832,13 @@ while ((rc = ldap_result(lcp->ld, msgid, 0, timeoutptr, &result)) == result = NULL; } /* End "while" loop for multiple results */ -/* Terminate the dynamic string that we have built and reclaim unused store */ +/* Terminate the dynamic string that we have built and reclaim unused store. +In the odd case of a single attribute with zero-length value, allocate +an empty string. */ -if (data) - { - (void) string_from_gstring(data); - gstring_reset_unused(data); - } +if (!data) data = string_get(1); +(void) string_from_gstring(data); +gstring_release_unused(data); /* Copy the last dn into eldap_dn */ @@ -1205,9 +1197,8 @@ far too complicated. */ if (user != NULL) { - uschar *s; uschar *t = user; - for (s = user; *s != 0; s++) + for (uschar * s = user; *s != 0; s++) { int c, d; if (*s == '%' && isxdigit(c=s[1]) && isxdigit(d=s[2]))