util: generalize is_localhost() and use it everywhere where applicable

This commit is contained in:
Lennart Poettering 2014-07-02 13:41:31 +02:00
parent 9a00f57a5b
commit fecc80c1ba
5 changed files with 19 additions and 16 deletions

View 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) {

View 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 */

View 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;

View 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.");
}

View 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);