* Thu Oct 7 2010 Dan Williams <dcbw@redhat.com> - 0.8.1-7

- core: remove stale /etc/hosts mappings (rh #630146)
This commit is contained in:
Dan Williams 2010-10-07 00:41:47 -05:00
parent c52f751c04
commit c28c070c1c
2 changed files with 118 additions and 1 deletions

View File

@ -20,7 +20,7 @@ Name: NetworkManager
Summary: Network connection manager and user applications Summary: Network connection manager and user applications
Epoch: 1 Epoch: 1
Version: 0.8.1 Version: 0.8.1
Release: 6%{snapshot}%{?dist} Release: 7%{snapshot}%{?dist}
Group: System Environment/Base Group: System Environment/Base
License: GPLv2+ License: GPLv2+
URL: http://www.gnome.org/projects/NetworkManager/ URL: http://www.gnome.org/projects/NetworkManager/
@ -31,6 +31,7 @@ Source2: NetworkManager.conf
Patch1: nm-applet-internal-buildfixes.patch Patch1: nm-applet-internal-buildfixes.patch
Patch2: explain-dns1-dns2.patch Patch2: explain-dns1-dns2.patch
Patch3: nm-applet-no-notifications.patch Patch3: nm-applet-no-notifications.patch
Patch4: nm-remove-stale-hosts-mappings.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires(post): chkconfig Requires(post): chkconfig
@ -161,6 +162,7 @@ tar -xjf %{SOURCE1}
%patch1 -p1 -b .buildfix %patch1 -p1 -b .buildfix
%patch2 -p1 -b .explain-dns1-dns2 %patch2 -p1 -b .explain-dns1-dns2
%patch3 -p1 -b .no-notifications %patch3 -p1 -b .no-notifications
%patch4 -p1 -b .remove-stale-hosts-mappings
%build %build
@ -414,6 +416,9 @@ fi
%{_datadir}/gtk-doc/html/libnm-util/* %{_datadir}/gtk-doc/html/libnm-util/*
%changelog %changelog
* Thu Oct 7 2010 Dan Williams <dcbw@redhat.com> - 0.8.1-7
- core: remove stale /etc/hosts mappings (rh #630146)
* Tue Aug 31 2010 Dan Williams <dcbw@redhat.com> - 0.8.1-6 * Tue Aug 31 2010 Dan Williams <dcbw@redhat.com> - 0.8.1-6
- core: add dispatcher events on DHCPv4 and DHCPv6 lease changes - core: add dispatcher events on DHCPv4 and DHCPv6 lease changes
- core: enforce access permissions when enabling/disabling WiFi and WWAN (rh #626337) - core: enforce access permissions when enabling/disabling WiFi and WWAN (rh #626337)

View File

@ -0,0 +1,112 @@
commit 97de44c9a730fbb5a08d27e6899f7caffb015e66
Author: Dan Williams <dcbw@redhat.com>
Date: Thu Oct 7 00:29:44 2010 -0500
policy: ensure stale IP mappings are not left in /etc/hosts (bgo #629020) (rh #630146)
NM-added mappings for active IP addresses were not getting properly
removed when the address disappeared of NM quit, because the bits
of code that determine whether or not /etc/hosts should change were
not taking the disappearance of the IP address into account, and
were leaving the file unchanged.
To fix that, if there is no default IP address, but there are NM-added
IP address entries in /etc/hosts, make sure we update /etc/hosts and
remove them.
diff --git a/src/nm-policy-hosts.c b/src/nm-policy-hosts.c
index 0403b03..1b57d42 100644
--- a/src/nm-policy-hosts.c
+++ b/src/nm-policy-hosts.c
@@ -64,6 +64,21 @@ is_local_mapping (const char *str, gboolean ip6, const char *hostname)
}
static gboolean
+is_ip4_addr (const char *str)
+{
+ struct in_addr found;
+ char buf[INET_ADDRSTRLEN + 2];
+ const char *p = str;
+ guint32 i = 0;
+
+ memset (buf, 0, sizeof (buf));
+ while (*p && !isblank (*p) && (i < sizeof (buf)))
+ buf[i++] = *p++;
+
+ return inet_pton (AF_INET, buf, &found) == 1 ? TRUE : FALSE;
+}
+
+static gboolean
ip4_addr_matches (const char *str, const char *ip4_addr)
{
struct in_addr found, given;
@@ -86,6 +101,21 @@ ip4_addr_matches (const char *str, const char *ip4_addr)
}
static gboolean
+is_ip6_addr (const char *str)
+{
+ struct in6_addr found;
+ char buf[INET6_ADDRSTRLEN + 2];
+ const char *p = str;
+ guint32 i = 0;
+
+ memset (buf, 0, sizeof (buf));
+ while (*p && !isblank (*p) && (i < sizeof (buf)))
+ buf[i++] = *p++;
+
+ return inet_pton (AF_INET6, buf, &found) == 1 ? TRUE : FALSE;
+}
+
+static gboolean
ip6_addr_matches (const char *str, const char *ip6_addr)
{
struct in6_addr found, given;
@@ -176,7 +206,14 @@ nm_policy_get_etc_hosts (const char **lines,
found_user_host4 = TRUE;
host4_before = TRUE; /* Ignore if user added mapping manually */
}
+ } else if (!ip4_addr && strstr (*line, ADDED_TAG)) {
+ /* If this is a stale NM-added IPv4 entry we need to remove it,
+ * so make sure we update /etc/hosts.
+ */
+ if (is_ip4_addr (*line))
+ found_host4 = FALSE;
}
+
if (ip6_addr && ip6_addr_matches (*line, ip6_addr)) {
found_host6 = TRUE;
if (strstr (*line, ADDED_TAG)) {
@@ -186,6 +223,12 @@ nm_policy_get_etc_hosts (const char **lines,
found_user_host6 = TRUE;
host6_before = TRUE; /* Ignore if user added mapping manually */
}
+ } else if (!ip6_addr && strstr (*line, ADDED_TAG)) {
+ /* If this is a stale NM-added IPv6 entry we need to remove it,
+ * so make sure we update /etc/hosts.
+ */
+ if (is_ip6_addr (*line))
+ found_host6 = FALSE;
}
}
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 3ab4db5..7382ece 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1234,6 +1234,15 @@ nm_policy_destroy (NMPolicy *policy)
}
g_slist_free (policy->dev_signal_ids);
+ /* Rewrite /etc/hosts on exit to ensure we don't leave stale IP addresses
+ * lying around. FIXME: this will take out a valid IP address of an
+ * ethernet device we're leaving active (ie, a connection we can "assume"
+ * when NM starts again).
+ */
+ policy->default_device4 = NULL;
+ policy->default_device6 = NULL;
+ update_system_hostname (policy, NULL, NULL);
+
g_free (policy->orig_hostname);
g_free (policy->cur_hostname);