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