util: generalize is_localhost() and use it everywhere where applicable
This commit is contained in:
parent
9a00f57a5b
commit
fecc80c1ba
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue