diff options
-rw-r--r-- | src/hostname/hostnamed.c | 2 | ||||
-rw-r--r-- | src/login/pam_systemd.c | 4 | ||||
-rw-r--r-- | src/network/networkd-link.c | 12 | ||||
-rw-r--r-- | src/shared/util.c | 15 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
5 files changed, 19 insertions, 16 deletions
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 241d29691..c2b6d3d6f 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -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) { diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 262621d43..f522d6ec4 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -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 */ diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 3324276bc..660efedc6 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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; diff --git a/src/shared/util.c b/src/shared/util.c index a1c8baf23..ceafa019a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -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."); +} diff --git a/src/shared/util.h b/src/shared/util.h index 6ad43cd27..6d3791be7 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -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); |