dirmngr: Avoid PTR lookup for hosts in a pool

* dirmngr/ks-engine-hkp.c (add_host): Don't to a PTR lookup for hosts
in a pool.
--

GnuPG-bug-id: 2928
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-02-15 17:03:57 +01:00
parent 2f7b6cb279
commit da2ba20868
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 18 additions and 5 deletions

View File

@ -300,10 +300,17 @@ add_host (const char *name, int is_pool,
idx = find_hostinfo (name); idx = find_hostinfo (name);
if (!is_pool && !is_ip_address (name)) if (is_pool)
{ {
/* This is a hostname but not a pool. Use the name /* For a pool immediately convert the address to a string. */
as given without going through resolve_dns_addr. */ tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
(DNS_NUMERICHOST | DNS_WITHBRACKET), &tmphost);
is_numeric = 1;
}
else if (!is_ip_address (name))
{
/* This is a hostname. Use the name as given without going
* through resolve_dns_addr. */
tmphost = xtrystrdup (name); tmphost = xtrystrdup (name);
if (!tmphost) if (!tmphost)
tmperr = gpg_error_from_syserror (); tmperr = gpg_error_from_syserror ();
@ -312,6 +319,10 @@ add_host (const char *name, int is_pool,
} }
else else
{ {
/* Do a PTR lookup on AI. If a name was not found the function
* returns the numeric address (with brackets) and we set a flag
* so that we know that the conversion to a numerical string has
* already be done. */
tmperr = resolve_dns_addr (ai->addr, ai->addrlen, tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
DNS_WITHBRACKET, &tmphost); DNS_WITHBRACKET, &tmphost);
if (tmphost && is_ip_address (tmphost)) if (tmphost && is_ip_address (tmphost))
@ -344,8 +355,7 @@ add_host (const char *name, int is_pool,
if (tmpidx == -1) if (tmpidx == -1)
{ {
log_error ("map_host for '%s' problem: %s - '%s'" log_error ("map_host for '%s' problem: %s - '%s' [ignored]\n",
" [ignored]\n",
name, strerror (errno), tmphost); name, strerror (errno), tmphost);
} }
else /* Set or update the entry. */ else /* Set or update the entry. */
@ -355,6 +365,9 @@ add_host (const char *name, int is_pool,
if (port) if (port)
hosttable[tmpidx]->port = port; hosttable[tmpidx]->port = port;
/* If TMPHOST is not yet a numerical value do this now.
* Note: This is a simple string operations and not a PTR
* lookup (due to DNS_NUMERICHOST). */
if (!is_numeric) if (!is_numeric)
{ {
xfree (tmphost); xfree (tmphost);