From 7082902d56ab1aa824e6b86bceaa7e1a14b6ef29 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 1 Jul 2020 16:10:17 +0200 Subject: [PATCH] ldap_client: Make ldap_parse_basic_url() IPv6-address aware Signed-off-by: Volker Lendecke Reviewed-by: Alexander Bokovoy Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Thu Jul 2 12:01:06 UTC 2020 on sn-devel-184 --- source4/libcli/ldap/ldap_client.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c index 5e7e67ceb2f..8614ccdfd54 100644 --- a/source4/libcli/ldap/ldap_client.c +++ b/source4/libcli/ldap/ldap_client.c @@ -376,6 +376,33 @@ static int ldap_parse_basic_url( return EPROTONOSUPPORT; } + if (url[0] == '[') { + /* + * IPv6 with [aa:bb:cc..]:port + */ + const char *end = NULL; + + url +=1; + + end = strchr(url, ']'); + if (end == NULL) { + return EINVAL; + } + + ret = sscanf(end+1, ":%d", &port); + if (ret < 0) { + return EINVAL; + } + + *pdest = talloc_strndup(mem_ctx, url, end-url); + if (*pdest == NULL) { + return ENOMEM; + } + *pproto = proto; + *pport = port; + return 0; + } + ret = sscanf(url, "%m[^:/]:%d", &host, &port); if (ret < 1) { return EINVAL;