summaryrefslogtreecommitdiffstats
path: root/dirmngr/ks-engine-hkp.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2014-03-11 18:02:29 +0100
committerWerner Koch <wk@gnupg.org>2014-03-11 18:02:29 +0100
commit0b2cca807d5a4a3664145032271141da853e7bac (patch)
tree8083890ad4a31cbff0768c05a8e3f9834580cec6 /dirmngr/ks-engine-hkp.c
parentdirmngr: Add command option to mark hosts as dead or alive. (diff)
downloadgnupg2-0b2cca807d5a4a3664145032271141da853e7bac.tar.xz
gnupg2-0b2cca807d5a4a3664145032271141da853e7bac.zip
dirmngr: Put brackets around IP addresses in the hosttable.
* dirmngr/ks-engine-hkp.c (EAI_OVERFLOW): Provide a substitute. (my_getnameinfo): New. (map_host): Use it.
Diffstat (limited to 'dirmngr/ks-engine-hkp.c')
-rw-r--r--dirmngr/ks-engine-hkp.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
index 40759304d..13da3cb15 100644
--- a/dirmngr/ks-engine-hkp.c
+++ b/dirmngr/ks-engine-hkp.c
@@ -40,6 +40,12 @@
#include "userids.h"
#include "ks-engine.h"
+/* Substitute a missing Mingw macro. */
+#ifndef EAI_OVERFLOW
+# define EAI_OVERFLOW EAI_FAIL
+#endif
+
+
/* To match the behaviour of our old gpgkeys helper code we escape
more characters than actually needed. */
#define EXTRA_ESCAPE_CHARS "@!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
@@ -200,6 +206,35 @@ select_random_host (int *table)
}
+/* Simplified version of getnameinfo which also returns a numeric
+ hostname inside of brackets. The caller should provide a buffer
+ for TMPHOST which is 2 bytes larger than the the largest hostname.
+ returns 0 on success or an EAI error code. */
+static int
+my_getnameinfo (const struct sockaddr *sa, socklen_t salen,
+ char *host, size_t hostlen)
+{
+ int ec;
+
+ if (hostlen < 5)
+ return EAI_OVERFLOW;
+
+ ec = getnameinfo (sa, salen, host, hostlen, NULL, 0, NI_NAMEREQD);
+ if (!ec && *host == '[')
+ ec = EAI_FAIL; /* A name may never start with a bracket. */
+ else if (ec == EAI_NONAME)
+ {
+ *host = '[';
+ ec = getnameinfo (sa, salen, host + 1, hostlen - 2,
+ NULL, 0, NI_NUMERICHOST);
+ if (!ec)
+ strcat (host, "]");
+ }
+
+ return ec;
+}
+
+
/* Map the host name NAME to the actual to be used host name. This
allows us to manage round robin DNS names. We use our own strategy
to choose one of the hosts. For example we skip those hosts which
@@ -256,9 +291,8 @@ map_host (const char *name, int force_reselect)
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
continue;
- if ((ec=getnameinfo (ai->ai_addr, ai->ai_addrlen,
- tmphost, sizeof tmphost,
- NULL, 0, 0)))
+ if ((ec = my_getnameinfo (ai->ai_addr, ai->ai_addrlen,
+ tmphost, sizeof tmphost)))
{
log_info ("getnameinfo failed while checking '%s': %s\n",
name, gai_strerror (ec));