]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: do not accept IPv6 local address if IPv6 is disabled 23161/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Apr 2022 01:31:55 +0000 (10:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Apr 2022 19:19:49 +0000 (04:19 +0900)
src/test/test-nss-hosts.c

index 69225da8b92ff04b0411579da811c77adda6e429..7b2bea4f647cf264dc05b806802eecff9f35055e 100644 (file)
@@ -20,6 +20,7 @@
 #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"
@@ -134,11 +135,18 @@ static void test_gethostbyname4_r(void *handle, const char *module, const char *
         if (STR_IN_SET(module, "resolve", "mymachines") && status == NSS_STATUS_UNAVAIL)
                 return;
 
-        if (STR_IN_SET(module, "myhostname", "resolve") &&
-            streq(name, "localhost") &&
-            getenv_bool_secure("SYSTEMD_NSS_RESOLVE_SYNTHESIZE") != 0) {
-                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") && getenv_bool_secure("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. */
+                }
         }
 }