chiark / gitweb /
dirmngr: Avoid PTR lookup for hosts in a pool
authorWerner Koch <wk@gnupg.org>
Wed, 15 Feb 2017 16:03:57 +0000 (17:03 +0100)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Mon, 18 Sep 2017 20:41:12 +0000 (21:41 +0100)
* 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>
(cherry picked from commit da2ba20868093e3054d18adc2b1bc56cb23e4ba7)

Gbp-Pq: Name 0039-dirmngr-Avoid-PTR-lookup-for-hosts-in-a-pool.patch

dirmngr/ks-engine-hkp.c

index be8b08333d146967ac5a47e641ee6366c929f4eb..32db4bc697dd6f79173a910a84cbc75a3ae7c0de 100644 (file)
@@ -320,10 +320,17 @@ add_host (const char *name, int is_pool,
 
   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
-         as given without going through resolve_dns_addr.  */
+      /* For a pool immediately convert the address to a string.  */
+      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);
       if (!tmphost)
         tmperr = gpg_error_from_syserror ();
@@ -332,6 +339,10 @@ add_host (const char *name, int is_pool,
     }
   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,
                                  DNS_WITHBRACKET, &tmphost);
       if (tmphost && is_ip_address (tmphost))
@@ -364,8 +375,7 @@ add_host (const char *name, int is_pool,
 
       if (tmpidx == -1)
         {
-          log_error ("map_host for '%s' problem: %s - '%s'"
-                     " [ignored]\n",
+          log_error ("map_host for '%s' problem: %s - '%s' [ignored]\n",
                      name, strerror (errno), tmphost);
         }
       else  /* Set or update the entry. */
@@ -375,6 +385,9 @@ add_host (const char *name, int is_pool,
           if (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)
             {
               xfree (tmphost);