1 From: Werner Koch <wk@gnupg.org>
2 Date: Wed, 15 Feb 2017 17:03:57 +0100
3 Subject: dirmngr: Avoid PTR lookup for hosts in a pool
5 * dirmngr/ks-engine-hkp.c (add_host): Don't to a PTR lookup for hosts
10 Signed-off-by: Werner Koch <wk@gnupg.org>
11 (cherry picked from commit da2ba20868093e3054d18adc2b1bc56cb23e4ba7)
13 dirmngr/ks-engine-hkp.c | 23 ++++++++++++++++++-----
14 1 file changed, 18 insertions(+), 5 deletions(-)
16 diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
17 index be8b083..32db4bc 100644
18 --- a/dirmngr/ks-engine-hkp.c
19 +++ b/dirmngr/ks-engine-hkp.c
20 @@ -320,10 +320,17 @@ add_host (const char *name, int is_pool,
22 idx = find_hostinfo (name);
24 - if (!is_pool && !is_ip_address (name))
27 - /* This is a hostname but not a pool. Use the name
28 - as given without going through resolve_dns_addr. */
29 + /* For a pool immediately convert the address to a string. */
30 + tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
31 + (DNS_NUMERICHOST | DNS_WITHBRACKET), &tmphost);
34 + else if (!is_ip_address (name))
36 + /* This is a hostname. Use the name as given without going
37 + * through resolve_dns_addr. */
38 tmphost = xtrystrdup (name);
40 tmperr = gpg_error_from_syserror ();
41 @@ -332,6 +339,10 @@ add_host (const char *name, int is_pool,
45 + /* Do a PTR lookup on AI. If a name was not found the function
46 + * returns the numeric address (with brackets) and we set a flag
47 + * so that we know that the conversion to a numerical string has
48 + * already be done. */
49 tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
50 DNS_WITHBRACKET, &tmphost);
51 if (tmphost && is_ip_address (tmphost))
52 @@ -364,8 +375,7 @@ add_host (const char *name, int is_pool,
56 - log_error ("map_host for '%s' problem: %s - '%s'"
58 + log_error ("map_host for '%s' problem: %s - '%s' [ignored]\n",
59 name, strerror (errno), tmphost);
61 else /* Set or update the entry. */
62 @@ -375,6 +385,9 @@ add_host (const char *name, int is_pool,
64 hosttable[tmpidx]->port = port;
66 + /* If TMPHOST is not yet a numerical value do this now.
67 + * Note: This is a simple string operations and not a PTR
68 + * lookup (due to DNS_NUMERICHOST). */