1
0
mirror of https://github.com/systemd/systemd synced 2026-04-26 17:04:50 +02:00

Compare commits

..

No commits in common. "cf393c5f441cbeaf346fb1970582838a8c423de8" and "6ed7b6977f5a7d0b1fa3c892dc600dcf4e76b05c" have entirely different histories.

2 changed files with 34 additions and 48 deletions

View File

@ -13,7 +13,6 @@
#include "macro.h" #include "macro.h"
#include "nss-util.h" #include "nss-util.h"
#include "signal-util.h" #include "signal-util.h"
#include "socket-util.h"
#include "string-util.h" #include "string-util.h"
/* We use 127.0.0.2 as IPv4 address. This has the advantage over /* We use 127.0.0.2 as IPv4 address. This has the advantage over
@ -96,7 +95,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
} }
l = strlen(canonical); l = strlen(canonical);
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 1 + socket_ipv6_is_enabled()); ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * (n_addresses > 0 ? n_addresses : 2);
if (buflen < ms) { if (buflen < ms) {
UNPROTECT_ERRNO; UNPROTECT_ERRNO;
*errnop = ERANGE; *errnop = ERANGE;
@ -112,7 +111,6 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
assert(n_addresses >= 0); assert(n_addresses >= 0);
if (n_addresses == 0) { if (n_addresses == 0) {
/* Second, fill in IPv6 tuple */ /* Second, fill in IPv6 tuple */
if (socket_ipv6_is_enabled()) {
r_tuple = (struct gaih_addrtuple*) (buffer + idx); r_tuple = (struct gaih_addrtuple*) (buffer + idx);
r_tuple->next = r_tuple_prev; r_tuple->next = r_tuple_prev;
r_tuple->name = r_name; r_tuple->name = r_name;
@ -122,7 +120,6 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
idx += ALIGN(sizeof(struct gaih_addrtuple)); idx += ALIGN(sizeof(struct gaih_addrtuple));
r_tuple_prev = r_tuple; r_tuple_prev = r_tuple;
}
/* Third, fill in IPv4 tuple */ /* Third, fill in IPv4 tuple */
r_tuple = (struct gaih_addrtuple*) (buffer + idx); r_tuple = (struct gaih_addrtuple*) (buffer + idx);
@ -192,7 +189,6 @@ static enum nss_status fill_in_hostent(
unsigned n, c; unsigned n, c;
assert(canonical); assert(canonical);
assert(IN_SET(af, AF_INET, AF_INET6));
assert(result); assert(result);
assert(buffer); assert(buffer);
assert(errnop); assert(errnop);
@ -212,8 +208,8 @@ static enum nss_status fill_in_hostent(
(additional ? ALIGN(l_additional+1) : 0) + (additional ? ALIGN(l_additional+1) : 0) +
sizeof(char*) + sizeof(char*) +
(additional ? sizeof(char*) : 0) + (additional ? sizeof(char*) : 0) +
(c > 0 ? c : af == AF_INET ? 1 : socket_ipv6_is_enabled()) * ALIGN(alen) + (c > 0 ? c : 1) * ALIGN(alen) +
(c > 0 ? c+1 : af == AF_INET ? 2 : (unsigned) socket_ipv6_is_enabled() + 1) * sizeof(char*); (c > 0 ? c+1 : 2) * sizeof(char*);
if (buflen < ms) { if (buflen < ms) {
UNPROTECT_ERRNO; UNPROTECT_ERRNO;
@ -259,12 +255,12 @@ static enum nss_status fill_in_hostent(
assert(i == c); assert(i == c);
idx += c*ALIGN(alen); idx += c*ALIGN(alen);
} else {
} else if (af == AF_INET) { if (af == AF_INET)
*(uint32_t*) r_addr = local_address_ipv4; *(uint32_t*) r_addr = local_address_ipv4;
idx += ALIGN(alen); else
} else if (socket_ipv6_is_enabled()) {
memcpy(r_addr, LOCALADDRESS_IPV6, 16); memcpy(r_addr, LOCALADDRESS_IPV6, 16);
idx += ALIGN(alen); idx += ALIGN(alen);
} }
@ -279,13 +275,10 @@ static enum nss_status fill_in_hostent(
((char**) r_addr_list)[i] = NULL; ((char**) r_addr_list)[i] = NULL;
idx += (c+1) * sizeof(char*); idx += (c+1) * sizeof(char*);
} else if (af == AF_INET || socket_ipv6_is_enabled()) { } else {
((char**) r_addr_list)[0] = r_addr; ((char**) r_addr_list)[0] = r_addr;
((char**) r_addr_list)[1] = NULL; ((char**) r_addr_list)[1] = NULL;
idx += 2 * sizeof(char*); idx += 2 * sizeof(char*);
} else {
((char**) r_addr_list)[0] = NULL;
idx += sizeof(char*);
} }
/* Verify the size matches */ /* Verify the size matches */
@ -346,9 +339,6 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
} }
if (is_localhost(name)) { if (is_localhost(name)) {
if (af == AF_INET6 && !socket_ipv6_is_enabled())
goto not_found;
canonical = "localhost"; canonical = "localhost";
local_address_ipv4 = htobe32(INADDR_LOOPBACK); local_address_ipv4 = htobe32(INADDR_LOOPBACK);
@ -460,9 +450,6 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
} else { } else {
assert(af == AF_INET6); assert(af == AF_INET6);
if (socket_ipv6_is_enabled())
goto not_found;
if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) { if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) {
canonical = "localhost"; canonical = "localhost";
additional_from_hostname = true; additional_from_hostname = true;
@ -470,21 +457,28 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
} }
} }
n_addresses = local_addresses(NULL, 0, af, &addresses); n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses);
for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) {
if (af != a->family)
continue;
if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0)
goto found; goto found;
}
addresses = mfree(addresses); addresses = mfree(addresses);
n_addresses = local_gateways(NULL, 0, af, &addresses); n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) {
if (af != a->family)
continue;
if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) { if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) {
canonical = "_gateway"; canonical = "_gateway";
goto found; goto found;
} }
}
not_found:
*h_errnop = HOST_NOT_FOUND; *h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND; return NSS_STATUS_NOTFOUND;

View File

@ -20,7 +20,6 @@
#include "nss-util.h" #include "nss-util.h"
#include "parse-util.h" #include "parse-util.h"
#include "path-util.h" #include "path-util.h"
#include "socket-util.h"
#include "stdio-util.h" #include "stdio-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
@ -135,18 +134,11 @@ static void test_gethostbyname4_r(void *handle, const char *module, const char *
if (STR_IN_SET(module, "resolve", "mymachines") && status == NSS_STATUS_UNAVAIL) if (STR_IN_SET(module, "resolve", "mymachines") && status == NSS_STATUS_UNAVAIL)
return; return;
if (streq(name, "localhost")) { if (STR_IN_SET(module, "myhostname", "resolve") &&
if (streq(module, "myhostname")) { streq(name, "localhost") &&
getenv_bool_secure("SYSTEMD_NSS_RESOLVE_SYNTHESIZE") != 0) {
assert_se(status == NSS_STATUS_SUCCESS); assert_se(status == NSS_STATUS_SUCCESS);
assert_se(n == socket_ipv6_is_enabled() + 1);
} else if (streq(module, "resolve") && getenv_bool_secure("SYSTEMD_NSS_RESOLVE_SYNTHESIZE") != 0) {
assert_se(status == NSS_STATUS_SUCCESS);
if (socket_ipv6_is_enabled())
assert_se(n == 2); assert_se(n == 2);
else
assert_se(n <= 2); /* Even if IPv6 is disabled, /etc/hosts may contain ::1. */
}
} }
} }