core: use nm_utils_is_specific_hostname() instead of hardcoded "localhost"

This commit is contained in:
Jiří Klimeš 2014-06-30 14:14:34 +02:00
parent bf1231d02a
commit 0105fb884a
4 changed files with 7 additions and 11 deletions

View file

@ -507,8 +507,7 @@ nm_dhcp_manager_set_default_hostname (NMDHCPManager *manager, const char *hostna
g_clear_pointer (&priv->default_hostname, g_free);
/* Never send 'localhost'-type names to the DHCP server */
if (g_strcmp0 (hostname, "localhost.localdomain") == 0 ||
g_strcmp0 (hostname, "localhost6.localdomain6") == 0)
if (!nm_utils_is_specific_hostname (hostname))
return;
priv->default_hostname = g_strdup (hostname);

View file

@ -972,8 +972,7 @@ nm_dns_manager_set_hostname (NMDnsManager *mgr,
/* Certain hostnames we don't want to include in resolv.conf 'searches' */
if ( hostname
&& strcmp (hostname, "localhost.localdomain")
&& strcmp (hostname, "localhost6.localdomain6")
&& nm_utils_is_specific_hostname (hostname)
&& !strstr (hostname, ".in-addr.arpa")
&& strchr (hostname, '.')) {
filtered = hostname;

View file

@ -2084,10 +2084,7 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
memset (hostname, 0, sizeof (hostname));
if (gethostname (&hostname[0], HOST_NAME_MAX) == 0) {
/* only cache it if it's a valid hostname */
if ( strlen (hostname)
&& strcmp (hostname, "localhost")
&& strcmp (hostname, "localhost.localdomain")
&& strcmp (hostname, "(none)"))
if (*hostname && nm_utils_is_specific_hostname (hostname))
priv->orig_hostname = g_strdup (hostname);
}

View file

@ -52,6 +52,7 @@
#include "nm-settings-error.h"
#include "nm-config.h"
#include "nm-logging.h"
#include "NetworkManagerUtils.h"
#include "nm-ifcfg-connection.h"
#include "nm-inotify-helper.h"
@ -648,10 +649,10 @@ plugin_get_hostname (SCPluginIfcfg *plugin)
hostname = svGetValue (network, "HOSTNAME", FALSE);
ignore_localhost = svTrueValue (network, "NM_IGNORE_HOSTNAME_LOCALHOST", FALSE);
if (ignore_localhost) {
/* Ignore a hostname of 'localhost' or 'localhost.localdomain' to preserve
* 'network' service behavior.
/* Ignore a default hostname ('localhost[6]' or 'localhost[6].localdomain[6]')
* to preserve 'network' service behavior.
*/
if (hostname && (!strcmp (hostname, "localhost") || !strcmp (hostname, "localhost.localdomain"))) {
if (hostname && !nm_utils_is_specific_hostname (hostname)) {
g_free (hostname);
hostname = NULL;
}