#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"
}
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);
.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);
#if ENABLE_NSS_MYMACHINES
"mymachines",
#endif
- "dns");
+ NULL);
assert_se(modules);
if (argc > 2) {
- char **name;
int family;
union in_addr_union address;
}
}
} else {
- _cleanup_free_ char *hostname;
+ _cleanup_free_ char *hostname = NULL;
assert_se(hostname = gethostname_malloc());
- assert_se(names = strv_new("localhost", "_gateway", "_outbound", "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);