diff options
author | Werner Koch <[email protected]> | 2017-02-15 18:17:08 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-02-15 18:20:33 +0000 |
commit | a3509e12b6626a585ce7da6ceed8cfddcba2460f (patch) | |
tree | faf3dd0fa4aeb54c3aa13b62450aed64a48f1bf1 | |
parent | dirmngr: Do PTR lookups only for 'keyserver --hosttable'. (diff) | |
download | gnupg-a3509e12b6626a585ce7da6ceed8cfddcba2460f.tar.gz gnupg-a3509e12b6626a585ce7da6ceed8cfddcba2460f.zip |
libdns: Workaround for bracketed numerical addresses.
* dirmngr/dns-stuff.c (resolve_name_libdns): Work around an
incompatibility between the glibc resolver and libdns.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | dirmngr/dns-stuff.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c index e57ddc7e0..074e0128f 100644 --- a/dirmngr/dns-stuff.c +++ b/dirmngr/dns-stuff.c @@ -719,6 +719,7 @@ resolve_name_libdns (const char *name, unsigned short port, struct addrinfo *ent; char portstr_[21]; char *portstr = NULL; + char *namebuf = NULL; int derr; *r_dai = NULL; @@ -731,8 +732,6 @@ resolve_name_libdns (const char *name, unsigned short port, hints.ai_flags = AI_ADDRCONFIG; if (r_canonname) hints.ai_flags |= AI_CANONNAME; - if (is_ip_address (name)) - hints.ai_flags |= AI_NUMERICHOST; if (port) { @@ -744,6 +743,25 @@ resolve_name_libdns (const char *name, unsigned short port, if (err) goto leave; + + if (is_ip_address (name)) + { + hints.ai_flags |= AI_NUMERICHOST; + /* libdns does not grok brackets - remove them. */ + if (*name == '[' && name[strlen(name)-1] == ']') + { + namebuf = xtrymalloc (strlen (name)); + if (!namebuf) + { + err = gpg_error_from_syserror (); + goto leave; + } + strcpy (namebuf, name+1); + namebuf[strlen (namebuf)-1] = 0; + name = namebuf; + } + } + ai = dns_ai_open (name, portstr, 0, &hints, res, &derr); if (!ai) { @@ -825,6 +843,7 @@ resolve_name_libdns (const char *name, unsigned short port, else *r_dai = daihead; + xfree (namebuf); return err; } #endif /*USE_LIBDNS*/ @@ -1208,7 +1227,7 @@ is_ip_address (const char *name) if (*name == '[') return 6; /* yes: A legal DNS name may not contain this character; - this mut be bracketed v6 address. */ + this must be bracketed v6 address. */ if (*name == '.') return 0; /* No. A leading dot is not a valid IP address. */ |