chiark / gitweb /
util: generalize is_localhost() and use it everywhere where applicable
authorLennart Poettering <lennart@poettering.net>
Wed, 2 Jul 2014 11:41:31 +0000 (13:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 2 Jul 2014 11:41:31 +0000 (13:41 +0200)
src/hostname/hostnamed.c
src/login/pam_systemd.c
src/network/networkd-link.c
src/shared/util.c
src/shared/util.h

index 241d2969166cc4c76f2093d06f7e5395bfdec3f2..c2b6d3d6f3d66adceb9fc541da70a1446f714fdd 100644 (file)
@@ -258,7 +258,7 @@ static char* context_fallback_icon_name(Context *c) {
 }
 
 static bool hostname_is_useful(const char *hn) {
-        return !isempty(hn) && !streq(hn, "localhost");
+        return !isempty(hn) && !is_localhost(hn);
 }
 
 static int context_update_kernel_hostname(Context *c) {
index 262621d43fd3631eaa14b5d033d7be0f58217ac4..f522d6ec4f20fa83b8b1ecefa22bc8cbb0019174 100644 (file)
@@ -357,9 +357,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (isempty(class))
                 class = streq(type, "unspecified") ? "background" : "user";
 
-        remote = !isempty(remote_host) &&
-                !streq_ptr(remote_host, "localhost") &&
-                !streq_ptr(remote_host, "localhost.localdomain");
+        remote = !isempty(remote_host) && !is_localhost(remote_host);
 
         /* Talk to logind over the message bus */
 
index 3324276bcc5b9c6ea2c1ae001f2d9a6b32563b3b..660efedc61b0d0dd515b1ab1cae219e735cde7d8 100644 (file)
@@ -1928,18 +1928,6 @@ static int link_enter_enslave(Link *link) {
         return 0;
 }
 
-/* make sure the hostname is not "localhost" */
-static bool is_localhost(const char *hostname) {
-        assert(hostname);
-
-        return streq(hostname, "localhost") ||
-               streq(hostname, "localhost.") ||
-               endswith(hostname, ".localhost") ||
-               endswith(hostname, ".localhost.") ||
-               endswith(hostname, ".localdomain") ||
-               endswith(hostname, ".localdomain.");
-}
-
 static int link_configure(Link *link) {
         int r;
 
index a1c8baf237f12999d65268e6e6973283def34783..ceafa019a83d60c90472e83edeed1a1ae7c13ec7 100644 (file)
@@ -6732,3 +6732,18 @@ char *tempfn_random(const char *p) {
 
         return t;
 }
+
+/* make sure the hostname is not "localhost" */
+bool is_localhost(const char *hostname) {
+        assert(hostname);
+
+        /* This tries to identify local hostnames described in RFC6761
+         * plus the redhatism of .localdomain */
+
+        return streq(hostname, "localhost") ||
+               streq(hostname, "localhost.") ||
+               endswith(hostname, ".localhost") ||
+               endswith(hostname, ".localhost.") ||
+               endswith(hostname, ".localdomain") ||
+               endswith(hostname, ".localdomain.");
+}
index 6ad43cd2749db490efc0fef6ee223f5ad168881f..6d3791be7f096a8748c5540c2a6dfed3f2507f00 100644 (file)
@@ -959,3 +959,5 @@ int fflush_and_check(FILE *f);
 
 char *tempfn_xxxxxx(const char *p);
 char *tempfn_random(const char *p);
+
+bool is_localhost(const char *hostname);