diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-05 16:23:21 +0100 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2015-02-03 17:25:34 +0000 |
commit | df0082ede6d0ca4db6773747eaf1c36d97458744 (patch) | |
tree | 74b4286ee00d74b4e02556757ffce9ebbc34eb34 | |
parent | 820aced6f6067a6b7c57b7d36e44f64378870cbf (diff) | |
download | systemd-baserock/v218-with-canonical-hostname-fix.tar.gz |
nss-myhostname: always will in canonical hostname field when resolving addresses to hostnamesbaserock/v218-with-canonical-hostname-fixbaserock/pedroalvarez/v218
https://bugs.freedesktop.org/show_bug.cgi?id=87634
-rw-r--r-- | src/nss-myhostname/nss-myhostname.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index aa92cc96e4..5c13adb144 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -38,7 +38,7 @@ /* We use 127.0.0.2 as IPv4 address. This has the advantage over * 127.0.0.1 that it can be translated back to the local hostname. For * IPv6 we use ::1 which unfortunately will not translate back to the - * hostname but instead something like "localhost6" or so. */ + * hostname but instead something like "localhost" or so. */ #define LOCALADDRESS_IPV4 (htonl(0x7F000002)) #define LOCALADDRESS_IPV6 &in6addr_loopback @@ -408,6 +408,7 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( _cleanup_free_ char *hn = NULL; int n_addresses = 0; struct local_address *a; + bool additional_from_hostname = false; unsigned n; assert(addr); @@ -429,7 +430,6 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( } if (af == AF_INET) { - if ((*(uint32_t*) addr) == LOCALADDRESS_IPV4) goto found; @@ -443,10 +443,10 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( assert(af == AF_INET6); if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) { - additional = "localhost"; + canonical = "localhost"; + additional_from_hostname = true; goto found; } - } n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses); @@ -455,18 +455,8 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( if (af != a->family) continue; - if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) { - - hn = gethostname_malloc(); - if (!hn) { - *errnop = ENOMEM; - *h_errnop = NO_RECOVERY; - return NSS_STATUS_TRYAGAIN; - } - - canonical = hn; + if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) goto found; - } } } @@ -480,7 +470,6 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( continue; if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) { - canonical = "gateway"; goto found; } @@ -493,6 +482,20 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r( return NSS_STATUS_NOTFOUND; found: + if (!canonical || (!additional && additional_from_hostname)) { + hn = gethostname_malloc(); + if (!hn) { + *errnop = ENOMEM; + *h_errnop = NO_RECOVERY; + return NSS_STATUS_TRYAGAIN; + } + + if (!canonical) + canonical = hn; + + if (!additional && additional_from_hostname) + additional = hn; + } return fill_in_hostent( canonical, additional, @@ -504,7 +507,6 @@ found: errnop, h_errnop, ttlp, NULL); - } NSS_GETHOSTBYNAME_FALLBACKS(myhostname); |