#include "af-list.h"
#include "alloc-util.h"
#include "dlfcn-util.h"
+#include "env-util.h"
#include "errno-list.h"
#include "format-util.h"
#include "hexdecoct.h"
#include "nss-util.h"
#include "parse-util.h"
#include "path-util.h"
+#include "socket-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
if (name)
return name;
- snprintf(buf, buf_len, "%i", family);
+ (void) snprintf(buf, buf_len, "%i", family);
return buf;
}
static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
- int n = 0;
+ int r, n = 0;
for (const struct gaih_addrtuple *it = tuples; it; it = it->next) {
_cleanup_free_ char *a = NULL;
union in_addr_union u;
- int r;
char family_name[DECIMAL_STR_MAX(int)];
- char ifname[IF_NAMESIZE + 1];
memcpy(&u, it->addr, 16);
r = in_addr_to_string(it->family, &u, &a);
if (r == -EAFNOSUPPORT)
assert_se(a = hexmem(it->addr, 16));
- if (it->scopeid == 0)
- goto numerical_index;
-
- if (!format_ifname(it->scopeid, ifname)) {
- log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid);
- numerical_index:
- xsprintf(ifname, "%i", it->scopeid);
- };
-
- log_info(" \"%s\" %s %s %%%s",
+ log_info(" \"%s\" %s %s %s",
it->name,
af_to_string(it->family, family_name, sizeof family_name),
a,
- ifname);
- n ++;
+ FORMAT_IFNAME_FULL(it->scopeid, FORMAT_IFNAME_IFINDEX_WITH_PERCENT));
+
+ n++;
}
return n;
}
static void print_struct_hostent(struct hostent *host, const char *canon) {
- char **s;
-
log_info(" \"%s\"", host->h_name);
STRV_FOREACH(s, host->h_aliases)
log_info(" alias \"%s\"", *s);
status = f(name, &pat, buffer, sizeof buffer, &errno1, &errno2, &ttl);
if (status == NSS_STATUS_SUCCESS) {
- log_info("%s(\"%s\") → status=%s%-20spat=buffer+0x%tx errno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
+ log_info("%s(\"%s\") → status=%s%-20spat=buffer+0x%"PRIxPTR" errno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
fname, name,
nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
- pat ? (char*) pat - buffer : 0,
+ pat ? (uintptr_t) pat - (uintptr_t) buffer : 0,
errno1, errno_to_name(errno1) ?: "---",
errno2, hstrerror(errno2),
ttl);
if (STR_IN_SET(module, "resolve", "mymachines") && status == NSS_STATUS_UNAVAIL)
return;
- if (STR_IN_SET(module, "myhostname", "resolve") && streq(name, "localhost")) {
- assert_se(status == NSS_STATUS_SUCCESS);
- assert_se(n == 2);
+ if (streq(name, "localhost")) {
+ if (streq(module, "myhostname")) {
+ assert_se(status == NSS_STATUS_SUCCESS);
+ assert_se(n == socket_ipv6_is_enabled() + 1);
+
+ } else if (streq(module, "resolve") && secure_getenv_bool("SYSTEMD_NSS_RESOLVE_SYNTHESIZE") != 0) {
+ assert_se(status == NSS_STATUS_SUCCESS);
+ if (socket_ipv6_is_enabled())
+ assert_se(n == 2);
+ else
+ assert_se(n <= 2); /* Even if IPv6 is disabled, /etc/hosts may contain ::1. */
+ }
}
}
puts("");
test_gethostbyname3_r(handle, module, name, AF_UNSPEC);
puts("");
- test_gethostbyname3_r(handle, module, name, AF_LOCAL);
+ test_gethostbyname3_r(handle, module, name, AF_UNIX);
puts("");
test_gethostbyname2_r(handle, module, name, AF_INET);
puts("");
test_gethostbyname2_r(handle, module, name, AF_UNSPEC);
puts("");
- test_gethostbyname2_r(handle, module, name, AF_LOCAL);
+ test_gethostbyname2_r(handle, module, name, AF_UNIX);
puts("");
test_gethostbyname_r(handle, module, name);
static int make_addresses(struct local_address **addresses) {
int n;
- size_t n_alloc;
_cleanup_free_ struct local_address *addrs = NULL;
n = local_addresses(NULL, 0, AF_UNSPEC, &addrs);
if (n < 0)
log_info_errno(n, "Failed to query local addresses: %m");
- n_alloc = n; /* we _can_ do that */
- assert_se(GREEDY_REALLOC(addrs, n_alloc, n + 3));
+ assert_se(GREEDY_REALLOC(addrs, n + 3));
addrs[n++] = (struct local_address) { .family = AF_INET,
.address.in = { htobe32(0x7F000001) } };
.address.in = { htobe32(0x7F000002) } };
addrs[n++] = (struct local_address) { .family = AF_INET6,
.address.in6 = in6addr_loopback };
- return 0;
+
+ *addresses = TAKE_PTR(addrs);
+ return n;
}
static int test_one_module(const char *dir,
if (!handle)
return -EINVAL;
- char **name;
STRV_FOREACH(name, names)
test_byname(handle, module, *name);
_cleanup_strv_free_ char **modules = NULL, **names = NULL;
_cleanup_free_ struct local_address *addrs = NULL;
- size_t n_allocated = 0;
const char *p;
int r, n = 0;
#if ENABLE_NSS_MYMACHINES
"mymachines",
#endif
- "dns");
+ NULL);
assert_se(modules);
if (argc > 2) {
- char **name;
int family;
union in_addr_union address;
if (r < 0)
return r;
} else {
- assert_se(GREEDY_REALLOC0(addrs, n_allocated, n + 1));
+ assert_se(GREEDY_REALLOC0(addrs, n + 1));
addrs[n++] = (struct local_address) { .family = family,
.address = address };
}
}
} else {
- _cleanup_free_ char *hostname;
+ _cleanup_free_ char *hostname = NULL;
assert_se(hostname = gethostname_malloc());
-
- assert_se(names = strv_new("localhost", "_gateway", "foo_no_such_host", hostname));
+ assert_se(names = strv_new("localhost",
+ "_gateway",
+ "_outbound",
+ hostname,
+ slow_tests_enabled() ? "foo_no_such_host" : NULL));
n = make_addresses(&addrs);
assert_se(n >= 0);
_cleanup_strv_free_ char **modules = NULL, **names = NULL;
_cleanup_free_ struct local_address *addresses = NULL;
int n_addresses = 0;
- char **module;
int r;
test_setup_logging(LOG_INFO);