Blame SOURCES/0002-krb5-locator-fix-IPv6-support.patch

ca1eb8
From 45a48b9a73f39e9ef9e622dbcf87cc05a2a54e40 Mon Sep 17 00:00:00 2001
ca1eb8
From: Sumit Bose <sbose@redhat.com>
ca1eb8
Date: Tue, 22 May 2018 17:59:52 +0200
ca1eb8
Subject: [PATCH] krb5 locator: fix IPv6 support
ca1eb8
ca1eb8
IPv6 addresses are added with surrounding '[' and ']' to the kdcinfo
ca1eb8
file to be able to specify a port number properly. The Kerberos location
ca1eb8
plugin didn't handle those entries properly.
ca1eb8
ca1eb8
Related to https://pagure.io/SSSD/sssd/issue/941
ca1eb8
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ca1eb8
ca1eb8
(cherry picked from commit 9f683246228848173c57ad02bde241bd761481ea)
ca1eb8
---
ca1eb8
 src/krb5_plugin/sssd_krb5_locator_plugin.c | 19 +++++++++++++++++--
ca1eb8
 1 file changed, 17 insertions(+), 2 deletions(-)
ca1eb8
ca1eb8
diff --git a/src/krb5_plugin/sssd_krb5_locator_plugin.c b/src/krb5_plugin/sssd_krb5_locator_plugin.c
ca1eb8
index 82fb5c7b2ffa319ed250e54cdf9a0b6798d4ff51..58cac7f4b244903347e6f1811cd8de2d61281c4f 100644
ca1eb8
--- a/src/krb5_plugin/sssd_krb5_locator_plugin.c
ca1eb8
+++ b/src/krb5_plugin/sssd_krb5_locator_plugin.c
ca1eb8
@@ -159,6 +159,8 @@ static int buf_to_addr_port_list(struct sssd_ctx *ctx,
ca1eb8
     uint8_t *pn;
ca1eb8
     size_t c;
ca1eb8
     size_t len;
ca1eb8
+    size_t addr_len;
ca1eb8
+    char *addr_str = NULL;
ca1eb8
     char *tmp = NULL;
ca1eb8
     char *port_str;
ca1eb8
     long port;
ca1eb8
@@ -206,6 +208,9 @@ static int buf_to_addr_port_list(struct sssd_ctx *ctx,
ca1eb8
         port_str = strrchr(tmp, ':');
ca1eb8
         if (port_str == NULL) {
ca1eb8
             port = 0;
ca1eb8
+        } else if (tmp[0] == '[' && *(port_str - 1) != ']') {
ca1eb8
+            /* IPv6 address without port number */
ca1eb8
+            port = 0;
ca1eb8
         } else {
ca1eb8
             *port_str = '\0';
ca1eb8
             ++port_str;
ca1eb8
@@ -239,9 +244,19 @@ static int buf_to_addr_port_list(struct sssd_ctx *ctx,
ca1eb8
             }
ca1eb8
         }
ca1eb8
 
ca1eb8
-        PLUGIN_DEBUG(("Found [%s][%d].\n", tmp, port));
ca1eb8
+        /* make sure tmp is not modified so that it can be freed later */
ca1eb8
+        addr_str = tmp;
ca1eb8
+        /* strip leading '[' and trailing ']' from IPv6 addresses */
ca1eb8
+        if (addr_str[0] == '['
ca1eb8
+                && (addr_len = strlen(addr_str))
ca1eb8
+                && addr_str[addr_len - 1] == ']') {
ca1eb8
+            addr_str[addr_len -1] = '\0';
ca1eb8
+            addr_str++;
ca1eb8
+        }
ca1eb8
 
ca1eb8
-        l[c].addr = strdup(tmp);
ca1eb8
+        PLUGIN_DEBUG(("Found [%s][%d].\n", addr_str, port));
ca1eb8
+
ca1eb8
+        l[c].addr = strdup(addr_str);
ca1eb8
         if (l[c].addr == NULL) {
ca1eb8
             ret = ENOMEM;
ca1eb8
             goto done;
ca1eb8
-- 
ca1eb8
2.17.1
ca1eb8