From e6aebfe3d0f16c483296fd125b66a44017fe15f4 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 16 Jan 2017 19:04:58 +0100 Subject: [PATCH] dirmngr: Implement hkps lookups using literal addresses. * dirmngr/ks-engine-hkp.c (map_host): For literal addresses do a reverse lookup. Signed-off-by: Werner Koch --- dirmngr/ks-engine-hkp.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c index 8c171a5f7..08ef851b4 100644 --- a/dirmngr/ks-engine-hkp.c +++ b/dirmngr/ks-engine-hkp.c @@ -85,7 +85,7 @@ struct hostinfo_s time_t died_at; /* The time the host was marked dead. If this is 0 the host has been manually marked dead. */ char *cname; /* Canonical name of the host. Only set if this - is a pool. */ + is a pool or NAME has a numerical IP address. */ char *v4addr; /* A string with the v4 IP address of the host. NULL if NAME has a numeric IP address or no v4 address is available. */ @@ -571,6 +571,34 @@ map_host (ctrl_t ctrl, const char *name, const char *srvtag, int force_reselect, hi = hosttable[hi->poolidx]; assert (hi); } + else if (r_httphost && is_ip_address (hi->name)) + { + /* This is a numerical IP address and not a pool. We want to + * find the canonical name so that it can be used in the HTTP + * Host header. Fixme: We should store that name in the + * hosttable. */ + dns_addrinfo_t aibuf, ai; + char *host; + + err = resolve_dns_name (hi->name, 0, 0, SOCK_STREAM, &aibuf, NULL); + if (!err) + { + for (ai = aibuf; ai; ai = ai->next) + { + if (ai->family == AF_INET6 || ai->family == AF_INET) + { + err = resolve_dns_addr (ai->addr, ai->addrlen, 0, &host); + if (!err) + { + /* Okay, we return the first found name. */ + *r_httphost = host; + break; + } + } + } + } + free_dns_addrinfo (aibuf); + } if (hi->dead) {