Blame SOURCES/0006-ldap-generate-proper-ldap-uri-for-IPv6-addresses.patch

cd9052
From 8cddf81199e96c7edc701bcb7ca782d7bcddbddd Mon Sep 17 00:00:00 2001
cd9052
From: Sumit Bose <sbose@redhat.com>
cd9052
Date: Fri, 30 Oct 2020 19:24:40 +0100
cd9052
Subject: [PATCH 6/6] ldap: generate proper ldap uri for IPv6 addresses
cd9052
cd9052
When using IPv6 addresses the address must be put into brackets.
cd9052
cd9052
Resolves: https://gitlab.freedesktop.org/realmd/realmd/-/issues/23
cd9052
---
cd9052
 service/realm-ldap.c | 16 +++++++++++++---
cd9052
 1 file changed, 13 insertions(+), 3 deletions(-)
cd9052
cd9052
diff --git a/service/realm-ldap.c b/service/realm-ldap.c
cd9052
index 28c5c8a..2076d1e 100644
cd9052
--- a/service/realm-ldap.c
cd9052
+++ b/service/realm-ldap.c
cd9052
@@ -190,6 +190,7 @@ realm_ldap_connect_anonymous (GSocketAddress *address,
cd9052
 	LdapSource *ls;
cd9052
 	gchar *addrname;
cd9052
 	GInetSocketAddress *inet;
cd9052
+	GSocketFamily family;
cd9052
 	struct berval cred;
cd9052
 	Sockbuf *sb = NULL;
cd9052
 	gsize native_len;
cd9052
@@ -204,6 +205,7 @@ realm_ldap_connect_anonymous (GSocketAddress *address,
cd9052
 	inet = G_INET_SOCKET_ADDRESS (address);
cd9052
 	addrname = g_inet_address_to_string (g_inet_socket_address_get_address (inet));
cd9052
 	port = g_inet_socket_address_get_port (inet);
cd9052
+	family = g_inet_address_get_family (g_inet_socket_address_get_address (inet));
cd9052
 	if (port == 0)
cd9052
 		port = 389;
cd9052
 
cd9052
@@ -239,9 +241,17 @@ realm_ldap_connect_anonymous (GSocketAddress *address,
cd9052
 		if (!g_unix_set_fd_nonblocking (ls->sock, FALSE, NULL))
cd9052
 			g_warning ("couldn't set to blocking");
cd9052
 
cd9052
-		url = g_strdup_printf ("%s://%s:%d",
cd9052
-		                       use_ldaps ? "ldaps" : "ldap",
cd9052
-		                       addrname, port);
cd9052
+		if (family == G_SOCKET_FAMILY_IPV4) {
cd9052
+			url = g_strdup_printf ("%s://%s:%d",
cd9052
+			                       use_ldaps ? "ldaps" : "ldap",
cd9052
+			                       addrname, port);
cd9052
+		} else if (family == G_SOCKET_FAMILY_IPV6) {
cd9052
+			url = g_strdup_printf ("%s://[%s]:%d",
cd9052
+			                       use_ldaps ? "ldaps" : "ldap",
cd9052
+			                       addrname, port);
cd9052
+		} else {
cd9052
+			url = NULL;
cd9052
+		}
cd9052
 		rc = ldap_init_fd (ls->sock, 1, url, &ls->ldap);
cd9052
 		g_free (url);
cd9052
 
cd9052
-- 
cd9052
2.26.2
cd9052