openldap: create ldap URLs correctly for IPv6 addresses
authorDaniel Stenberg <daniel@haxx.se>
Sat, 30 Mar 2024 10:14:54 +0000 (11:14 +0100)
committerGuilherme Puida Moreira <guilherme@puida.xyz>
Tue, 2 Apr 2024 23:02:10 +0000 (20:02 -0300)
Reported-by: Sergio Durigan Junior
Fixes #13228
Closes #13235

More context:

When the user specified an IPv6 address to be used as an LDAP server,
curl will fail to properly enclose it in square brackets, which causes
the connection to fail because the host address cannot be
distinguished from the port:

$ curl -v ldap://[fd42:be5:e632:a6b3:216:3eff:feb1:5bc4]:389
...
* LDAP local: Cannot connect to ldap://fd42:be5:e632:a6b3:216:3eff:feb1:5bc4:389, Bad parameter to an ldap routine
...

Fix this by always enclosing the IPv6 address in square brackets.

Origin: upstream, https://github.com/curl/curl/commit/56935a7dada6975d5a46aa494de0af195e4e8659
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1053643

Gbp-Pq: Name openldap-create-ldap-URLs-correctly-for-IPv6-addresses.patch

lib/openldap.c

index b9feeda0589c99e01533bd66e73a344230517c92..9a7e3da6c4d1cf5c83d181d45fbc148b92e013e6 100644 (file)
@@ -547,9 +547,12 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done)
 
   (void)done;
 
-  hosturl = aprintf("ldap%s://%s:%d",
-                    conn->handler->flags & PROTOPT_SSL? "s": "",
-                    conn->host.name, conn->remote_port);
+  hosturl = aprintf("%s://%s%s%s:%d",
+                    conn->handler->scheme,
+                    conn->bits.ipv6_ip? "[": "",
+                    conn->host.name,
+                    conn->bits.ipv6_ip? "]": "",
+                    conn->remote_port);
   if(!hosturl)
     return CURLE_OUT_OF_MEMORY;