ITADN
curl/curl/Issues

Raw binary in LDIF format when using the WinLDAP backend

#21926Closedoreadvanthink 创建于 2026-06-09
LDAPhelp wantedWindows
O
oreadvanthinkcommented
### I did this I am using `curl_easy_setopt` and `curl_easy_perform` to query a *jpegPhoto* attribute from an LDAP server. My code is equivalent to this CLI command: ```bash curl "ldap://ldap.example.com/uid=jdoe,ou=people,dc=example,dc=com?jpegPhoto?base" ``` On Linux with the OpenLDAP backend, this query returns an LDIF text response, with the *jpegPhoto* value as base64. ```ldif DN: uid=jdoe,ou=people,dc=example,dc=com jpegPhoto:: /9j/4AAQSkZJRgABAQEASABIAAD//gBbUGh<more base64 here> ``` On Windows with the WinLDAP backend, it returns the attribute value as raw binary data. ```ldif DN: uid=jdoe,ou=people,dc=example,dc=com jpegPhoto: <raw binary data here> ``` The above is what the callback I set with `CURLOPT_WRITEFUNCTION` receives. When using ther CLI instead, it stops with a warning as it detects raw binary. ```ldif DN: uid=jdoe,ou=people,dc=example,dc=com jpegPhoto: Warning: Binary output can mess up your terminal. Use "--output -" to tell curl to output it to your terminal anyway, Warning: or consider "--output <FILE>" to save to a file. ``` LDIF is a pure ASCII format, that uses spaces, tabs and newlines as delimiters. Curl chose to return the response as LDIF, but with the WinLDAP backend this LDIF response is malformed due to the injection of raw binary data. It makes the response unparseable. Looking at the code, I see that `lib/openldap.c` is the OpenLDAP backend, and `lib/ldap.c` is the WinLDAP backend, and their logic to encode the values as base64 diverge. https://github.com/curl/curl/blob/feb609f28bc038b158d6e5f00e2aa30473b31d6e/lib/openldap.c#L1177-L1212 https://github.com/curl/curl/blob/feb609f28bc038b158d6e5f00e2aa30473b31d6e/lib/ldap.c#L516-L522 Both check for the *;binary* option, but only the OpenLDAP backend checks for leading and trailing whitespaces and for unprintable characters. The ldap.c code should use the same logic than openldap.c (and possibly using shared code). I don't know any workaround. I tried adding the *;binary* option to the attribute in the query to force the base64 encoding, but it returns no result. It seems this option is reserved for certificate attributes only. ### I expected the following I expect LDAP responses to be in a valid LDIF format. ### curl/libcurl version curl 8.19.0 ### operating system Windows 11 Pro
关闭于 2026-06-14 0 条评论