diff options
author | Robby Workman <rworkman@slackbuilds.org> | 2011-01-10 12:44:27 -0600 |
---|---|---|
committer | Robby Workman <rworkman@slackbuilds.org> | 2011-01-10 12:44:27 -0600 |
commit | 4851069dfdd41d5cf9071f04ab48fc11b61ccd81 (patch) | |
tree | 801cfe14b0d7b3a90af43d1ce8d241028b63b435 | |
parent | 68c0f83fbbf1e39803c1f76321b50b99a2b124ba (diff) |
network/NetworkManager: Included several patches from upstream
This commit adds quite a few patches from the upstream
NM_0_8 git branch. Most of them are bugfix-only patches,
but the two dealing with /etc/hosts policy are changes in
behavior. This *should* be an improvement for us, but if
you notice any ill effects, please advise.
Signed-off-by: Robby Workman <rworkman@slackbuilds.org>
21 files changed, 2510 insertions, 6 deletions
diff --git a/network/NetworkManager/NetworkManager.SlackBuild b/network/NetworkManager/NetworkManager.SlackBuild index c858e24ea81b9..427360e606bea 100644 --- a/network/NetworkManager/NetworkManager.SlackBuild +++ b/network/NetworkManager/NetworkManager.SlackBuild @@ -69,9 +69,30 @@ find . \ \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ -exec chmod 644 {} \; +# Fix Slackware init script patch -p1 < $CWD/patches/fixup_rc.networkmanager.patch -patch -p1 < $CWD/patches/fix_crash_in_glib_with_time.patch -patch -p1 < $CWD/patches/ignore_temp_files.patch + +# Apply some patches from the 0.8 branch in NM git +patch -p1 < $CWD/patches/keyfile-create-keyfile-data-directory-during-install.patch +patch -p1 < $CWD/patches/keyfile-quiet-keyfile-plugin-when-re-read-connection.patch +patch -p1 < $CWD/patches/build-create-NM-state-directory-at-install-time.patch +patch -p1 < $CWD/patches/keyfile-ignore-temporary-files-bgo-602868.patch +patch -p1 < $CWD/patches/dhcpcd-prevent-dhcpcd-from-messing-with-routing-bgo-.patch +patch -p1 < $CWD/patches/wired-fix-uninitialized-variable.patch +patch -p1 < $CWD/patches/core-correct-TIMESTAMP-type-fixes-potential-crash-wh.patch +patch -p1 < $CWD/patches/dhcp-ensure-that-dhcp-client-is-exited.patch +patch -p1 < $CWD/patches/keyfile-allow-uppercase-MAC-addresses-in-unmanaged-d.patch +patch -p1 < $CWD/patches/core-handle-device-removal-when-properties-are-unrea.patch +patch -p1 < $CWD/patches/examples-fix-querying-active-connections.patch +patch -p1 < $CWD/patches/core-suppress-error-message-when-user-settings-servi.patch +patch -p1 < $CWD/patches/dns-fix-a-crash-due-to-uninitialized-nis_domain-nove.patch +patch -p1 < $CWD/patches/libnm-glib-actually-define-the-ip-interface-property.patch +patch -p1 < $CWD/patches/libnm-util-fix-a-memory-leaks-in-nm_setting_to_strin.patch +patch -p1 < $CWD/patches/dns-direct-IPv4-reverse-DNS-queries-to-split-DNS-ser.patch +patch -p1 < $CWD/patches/policy-stop-touching-etc-hosts.patch +patch -p1 < $CWD/patches/modem-handle-IP-Method-changes-after-modem-has-been-.patch +patch -p1 < $CWD/patches/policy-don-t-update-hostname-on-exit.patch +patch -p1 < $CWD/patches/core-handle-D-Bus-disconnect-better-on-exit.patch autoreconf @@ -110,10 +131,6 @@ mkdir -p $PKG/etc/NetworkManager cat $CWD/NetworkManager.conf.new > \ $PKG/etc/NetworkManager/NetworkManager.conf.new -# Create the /etc/NetworkManager/system-connections/ directory, since the -# install target of the Makefile no longer does this -mkdir -p $PKG/etc/NetworkManager/system-connections/ - # This file should actually be shipped with Slackware's wpa_supplicant # package, but since we missed it there (oops), we'll do it here: mkdir -p $PKG/usr/share/dbus-1/system-services diff --git a/network/NetworkManager/patches/build-create-NM-state-directory-at-install-time.patch b/network/NetworkManager/patches/build-create-NM-state-directory-at-install-time.patch new file mode 100644 index 0000000000000..c2374dd9337c3 --- /dev/null +++ b/network/NetworkManager/patches/build-create-NM-state-directory-at-install-time.patch @@ -0,0 +1,27 @@ +From ce741199c1b304e8f2cc0791f9c4d439ab8bd196 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Mon, 8 Nov 2010 09:09:54 -0600 +Subject: [PATCH 2/3] build: create NM state directory at install time + +--- + src/Makefile.am | 2 ++ + 1 files changed, 2 insertions(+), 0 deletions(-) + +diff --git a/src/Makefile.am b/src/Makefile.am +index 8c01df0..d7dccaa 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -275,8 +275,10 @@ EXTRA_DIST = \ + $(NetworkManager_DATA) + + rundir=$(localstatedir)/run/NetworkManager ++statedir=$(localstatedir)/lib/NetworkManager + install-data-hook: + $(mkinstalldirs) -m 0700 $(DESTDIR)$(rundir) ++ $(mkinstalldirs) -m 0700 $(DESTDIR)$(statedir) + + CLEANFILES = $(BUILT_SOURCES) + +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/fix_crash_in_glib_with_time.patch b/network/NetworkManager/patches/core-correct-TIMESTAMP-type-fixes-potential-crash-wh.patch index 7a2f8782f5631..7a2f8782f5631 100644 --- a/network/NetworkManager/patches/fix_crash_in_glib_with_time.patch +++ b/network/NetworkManager/patches/core-correct-TIMESTAMP-type-fixes-potential-crash-wh.patch diff --git a/network/NetworkManager/patches/core-handle-D-Bus-disconnect-better-on-exit.patch b/network/NetworkManager/patches/core-handle-D-Bus-disconnect-better-on-exit.patch new file mode 100644 index 0000000000000..fc21e53b01c3f --- /dev/null +++ b/network/NetworkManager/patches/core-handle-D-Bus-disconnect-better-on-exit.patch @@ -0,0 +1,35 @@ +From 9751335f013248749d7d05c56c9c18af1410baa1 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Sun, 2 Jan 2011 10:49:36 -0600 +Subject: [PATCH 8/8] core: handle D-Bus disconnect better on exit + +We're just going to quit here anyway, so we don't need to +make sure the property filter is unregistered. Fixes a +crash on exit if D-Bus has quit before NM has. +--- + src/nm-manager.c | 9 +++++---- + 1 files changed, 5 insertions(+), 4 deletions(-) + +diff --git a/src/nm-manager.c b/src/nm-manager.c +index afcc6ad..9bd5354 100644 +--- a/src/nm-manager.c ++++ b/src/nm-manager.c +@@ -4364,10 +4364,11 @@ dispose (GObject *object) + + /* Unregister property filter */ + bus = nm_dbus_manager_get_connection (priv->dbus_mgr); +- g_assert (bus); +- dbus_connection = dbus_g_connection_get_connection (bus); +- g_assert (dbus_connection); +- dbus_connection_remove_filter (dbus_connection, prop_filter, manager); ++ if (bus) { ++ dbus_connection = dbus_g_connection_get_connection (bus); ++ g_assert (dbus_connection); ++ dbus_connection_remove_filter (dbus_connection, prop_filter, manager); ++ } + g_object_unref (priv->dbus_mgr); + + if (priv->bluez_mgr) +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/core-handle-device-removal-when-properties-are-unrea.patch b/network/NetworkManager/patches/core-handle-device-removal-when-properties-are-unrea.patch new file mode 100644 index 0000000000000..4a47f61ef2be6 --- /dev/null +++ b/network/NetworkManager/patches/core-handle-device-removal-when-properties-are-unrea.patch @@ -0,0 +1,37 @@ +From 8698e62fb9ba492bd4decd14d4faa7fded661ba2 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Tue, 23 Nov 2010 13:10:01 -0600 +Subject: [PATCH 1/4] core: handle device removal when properties are unreadable + +By the time we get the udev device removal notification we may not +be able to read properties, since the device has already been +removed from sysfs. That means we can't get the ifindex, so we need +to fall back to the interface name. But we always want to prefer +the ifindex since that will never change as long as the device is +connected, unlike the interface name. +--- + src/nm-manager.c | 8 ++++++++ + 1 files changed, 8 insertions(+), 0 deletions(-) + +diff --git a/src/nm-manager.c b/src/nm-manager.c +index eb393fa..48f2173 100644 +--- a/src/nm-manager.c ++++ b/src/nm-manager.c +@@ -2426,6 +2426,14 @@ udev_device_removed_cb (NMUdevManager *manager, + + ifindex = g_udev_device_get_property_as_int (udev_device, "IFINDEX"); + device = find_device_by_ifindex (self, ifindex); ++ if (!device) { ++ /* On removal we won't always be able to read properties anymore, as ++ * they may have already been removed from sysfs. Instead, we just ++ * have to fall back to the device's interface name. ++ */ ++ device = find_device_by_iface (self, g_udev_device_get_name (udev_device)); ++ } ++ + if (device) + priv->devices = remove_one_device (self, priv->devices, device, FALSE); + } +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/core-suppress-error-message-when-user-settings-servi.patch b/network/NetworkManager/patches/core-suppress-error-message-when-user-settings-servi.patch new file mode 100644 index 0000000000000..f616033c1c4a1 --- /dev/null +++ b/network/NetworkManager/patches/core-suppress-error-message-when-user-settings-servi.patch @@ -0,0 +1,42 @@ +From 83e02840b5ce1cf8c122cc70918ddd57396c91db Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Tue, 23 Nov 2010 22:17:21 -0600 +Subject: [PATCH 3/4] core: suppress error message when user settings service is not active + +Don't bother trying to initialize the user settings proxy when it +isn't even active. Would trigger a warning to syslog if PolicyKit +permissions changed via changes to /usr/share/polkit-1/actions/. +--- + src/nm-manager.c | 9 +++++++-- + 1 files changed, 7 insertions(+), 2 deletions(-) + +diff --git a/src/nm-manager.c b/src/nm-manager.c +index 48f2173..afcc6ad 100644 +--- a/src/nm-manager.c ++++ b/src/nm-manager.c +@@ -1356,6 +1356,12 @@ user_proxy_init (NMManager *self) + g_return_if_fail (self != NULL); + g_return_if_fail (priv->user_proxy == NULL); + ++ /* Don't try to initialize the user settings proxy if the user ++ * settings service doesn't actually exist. ++ */ ++ if (!nm_dbus_manager_name_has_owner (priv->dbus_mgr, NM_DBUS_SERVICE_USER_SETTINGS)) ++ return; ++ + bus = nm_dbus_manager_get_connection (priv->dbus_mgr); + priv->user_proxy = dbus_g_proxy_new_for_name_owner (bus, + NM_DBUS_SERVICE_USER_SETTINGS, +@@ -3975,8 +3981,7 @@ nm_manager_start (NMManager *self) + * they will be queried when the user settings service shows up on the + * bus in nm_manager_name_owner_changed(). + */ +- if (nm_dbus_manager_name_has_owner (priv->dbus_mgr, NM_DBUS_SERVICE_USER_SETTINGS)) +- user_proxy_init (self); ++ user_proxy_init (self); + + nm_udev_manager_query_devices (priv->udev_mgr); + bluez_manager_resync_devices (self); +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/dhcp-ensure-that-dhcp-client-is-exited.patch b/network/NetworkManager/patches/dhcp-ensure-that-dhcp-client-is-exited.patch new file mode 100644 index 0000000000000..41e6bbd3e695a --- /dev/null +++ b/network/NetworkManager/patches/dhcp-ensure-that-dhcp-client-is-exited.patch @@ -0,0 +1,38 @@ +From 3d3c87774381cee77bae911367a12e8c86d6ad99 Mon Sep 17 00:00:00 2001 +From: Mikhail Efremov <sem@altlinux.org> +Date: Fri, 19 Nov 2010 16:52:55 -0600 +Subject: [PATCH 3/4] dhcp: ensure that dhcp client is exited + +On restart ensure that the client we're trying to kill has +actually exited even if it's not our child. +--- + src/dhcp-manager/nm-dhcp-client.c | 12 ++++++++---- + 1 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c +index 0c7f3d4..3a8b194 100644 +--- a/src/dhcp-manager/nm-dhcp-client.c ++++ b/src/dhcp-manager/nm-dhcp-client.c +@@ -156,11 +156,15 @@ stop_process (GPid pid, const char *iface) + + if (ret == -1) { + /* Child already exited */ +- if (errno == ECHILD) ++ if (errno == ECHILD) { ++ /* Was it really our child and it exited? */ ++ if (kill (pid, 0) < 0 && errno == ESRCH) ++ break; ++ } else { ++ /* Took too long; shoot it in the head */ ++ i = 0; + break; +- /* Took too long; shoot it in the head */ +- i = 0; +- break; ++ } + } + g_usleep (G_USEC_PER_SEC / 5); + } +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/dhcpcd-prevent-dhcpcd-from-messing-with-routing-bgo-.patch b/network/NetworkManager/patches/dhcpcd-prevent-dhcpcd-from-messing-with-routing-bgo-.patch new file mode 100644 index 0000000000000..3b374123089a9 --- /dev/null +++ b/network/NetworkManager/patches/dhcpcd-prevent-dhcpcd-from-messing-with-routing-bgo-.patch @@ -0,0 +1,26 @@ +From d60a988518cb0851488bc21732271a971877cdcd Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Thu, 18 Nov 2010 16:30:00 -0600 +Subject: [PATCH 1/4] dhcpcd: prevent dhcpcd from messing with routing (bgo #634983) + +Since NM is already handling that. +--- + src/dhcp-manager/nm-dhcp-dhcpcd.c | 2 ++ + 1 files changed, 2 insertions(+), 0 deletions(-) + +diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c +index 378a97b..4fb703c 100644 +--- a/src/dhcp-manager/nm-dhcp-dhcpcd.c ++++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c +@@ -128,6 +128,8 @@ real_ip4_start (NMDHCPClient *client, + + g_ptr_array_add (argv, (gpointer) "-L"); /* Disable built-in IPv4LL since we use avahi-autoipd */ + ++ g_ptr_array_add (argv, (gpointer) "-G"); /* Let NM handle routing */ ++ + g_ptr_array_add (argv, (gpointer) "-c"); /* Set script file */ + g_ptr_array_add (argv, (gpointer) ACTION_SCRIPT_PATH ); + +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/dns-direct-IPv4-reverse-DNS-queries-to-split-DNS-ser.patch b/network/NetworkManager/patches/dns-direct-IPv4-reverse-DNS-queries-to-split-DNS-ser.patch new file mode 100644 index 0000000000000..fa84e83ddb015 --- /dev/null +++ b/network/NetworkManager/patches/dns-direct-IPv4-reverse-DNS-queries-to-split-DNS-ser.patch @@ -0,0 +1,236 @@ +From 93249f1901cc3f1f08d5f8f66f7cd6f7bd918946 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Thu, 16 Dec 2010 17:47:59 -0600 +Subject: [PATCH] dns: direct IPv4 reverse DNS queries to split DNS servers + +When split DNS is used for a local caching nameserver, make sure +that reverse DNS queries for hosts within the VPN tunnel are directed +to the VPN's nameservers, not to the public upstream nameservers. +--- + src/dns-manager/Makefile.am | 4 +- + src/dns-manager/nm-dns-dnsmasq.c | 22 +++++++-- + src/dns-manager/nm-dns-utils.c | 99 ++++++++++++++++++++++++++++++++++++++ + src/dns-manager/nm-dns-utils.h | 28 +++++++++++ + 4 files changed, 148 insertions(+), 5 deletions(-) + create mode 100644 src/dns-manager/nm-dns-utils.c + create mode 100644 src/dns-manager/nm-dns-utils.h + +diff --git a/src/dns-manager/Makefile.am b/src/dns-manager/Makefile.am +index 1ffe62d..7b5fc4f 100644 +--- a/src/dns-manager/Makefile.am ++++ b/src/dns-manager/Makefile.am +@@ -14,7 +14,9 @@ libdns_manager_la_SOURCES = \ + nm-dns-dnsmasq.h \ + nm-dns-dnsmasq.c \ + nm-dns-bind.h \ +- nm-dns-bind.c ++ nm-dns-bind.c \ ++ nm-dns-utils.h \ ++ nm-dns-utils.c + + libdns_manager_la_CPPFLAGS = \ + $(DBUS_CFLAGS) \ +diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c +index 41c8e2a..9cc0197 100644 +--- a/src/dns-manager/nm-dns-dnsmasq.c ++++ b/src/dns-manager/nm-dns-dnsmasq.c +@@ -33,6 +33,7 @@ + #include "nm-logging.h" + #include "nm-ip4-config.h" + #include "nm-ip6-config.h" ++#include "nm-dns-utils.h" + + G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN) + +@@ -75,9 +76,11 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split) + gboolean added = FALSE; + + if (split) { ++ char **domains, **iter; ++ + /* FIXME: it appears that dnsmasq can only handle one nameserver +- * per domain (at the manpage seems to indicate that) so only use +- * the first nameserver here. ++ * per domain (and the manpage says this too) so only use the first ++ * nameserver here. + */ + addr.s_addr = nm_ip4_config_get_nameserver (ip4, 0); + memset (&buf[0], 0, sizeof (buf)); +@@ -103,6 +106,17 @@ add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split) + added = TRUE; + } + } ++ ++ /* Ensure reverse-DNS works by directing queries for in-addr.arpa ++ * domains to the split domain's nameserver. ++ */ ++ domains = nm_dns_utils_get_ip4_rdns_domains (ip4); ++ if (domains) { ++ for (iter = domains; iter && *iter; iter++) ++ g_string_append_printf (str, "server=/%s/%s\n", *iter, buf); ++ g_strfreev (domains); ++ added = TRUE; ++ } + } + + /* If no searches or domains, just add the namservers */ +@@ -216,7 +230,7 @@ update (NMDnsPlugin *plugin, + } + + /* Now add interface configs without split DNS */ +- for (iter = (GSList *) dev_configs; iter;iter = g_slist_next (iter)) { ++ for (iter = (GSList *) dev_configs; iter; iter = g_slist_next (iter)) { + if (NM_IS_IP4_CONFIG (iter->data)) + add_ip4_config (conf, NM_IP4_CONFIG (iter->data), FALSE); + else if (NM_IS_IP6_CONFIG (iter->data)) +@@ -224,7 +238,7 @@ update (NMDnsPlugin *plugin, + } + + /* And any other random configs */ +- for (iter = (GSList *) other_configs; iter;iter = g_slist_next (iter)) { ++ for (iter = (GSList *) other_configs; iter; iter = g_slist_next (iter)) { + if (NM_IS_IP4_CONFIG (iter->data)) + add_ip4_config (conf, NM_IP4_CONFIG (iter->data), FALSE); + else if (NM_IS_IP6_CONFIG (iter->data)) +diff --git a/src/dns-manager/nm-dns-utils.c b/src/dns-manager/nm-dns-utils.c +new file mode 100644 +index 0000000..615adfd +--- /dev/null ++++ b/src/dns-manager/nm-dns-utils.c +@@ -0,0 +1,99 @@ ++/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ ++/* This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2, or (at your option) ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ * ++ * Copyright (C) 2010 Red Hat, Inc. ++ * ++ */ ++ ++#include <arpa/inet.h> ++#include <string.h> ++ ++#include "nm-dns-utils.h" ++#include "nm-utils.h" ++ ++static void ++add_ip4_to_rdns_array (guint32 ip, GPtrArray *domains) /* network byte order */ ++{ ++ guint32 defprefix; ++ guchar *p; ++ char *str = NULL; ++ int i; ++ ++ defprefix = nm_utils_ip4_get_default_prefix (ip); ++ ++ /* Convert to host byte order, mask the host bits, and convert back */ ++ ip = ntohl (ip); ++ ip &= 0xFFFFFFFF << (32 - defprefix); ++ ip = htonl (ip); ++ p = (guchar *) &ip; ++ ++ if (defprefix == 8) ++ str = g_strdup_printf ("%u.in-addr.arpa", p[0] & 0xFF); ++ else if (defprefix == 16) ++ str = g_strdup_printf ("%u.%u.in-addr.arpa", p[1] & 0xFF, p[0] & 0xFF); ++ else if (defprefix == 24) ++ str = g_strdup_printf ("%u.%u.%u.in-addr.arpa", p[2] & 0xFF, p[1] & 0xFF, p[0] & 0xFF); ++ ++ g_return_if_fail (str != NULL); ++ ++ /* Suppress duplicates */ ++ for (i = 0; i < domains->len; i++) { ++ if (strcmp (str, g_ptr_array_index (domains, i)) == 0) ++ break; ++ } ++ ++ if (i == domains->len) ++ g_ptr_array_add (domains, str); ++ else ++ g_free (str); ++} ++ ++char ** ++nm_dns_utils_get_ip4_rdns_domains (NMIP4Config *ip4) ++{ ++ GPtrArray *domains = NULL; ++ int i; ++ ++ g_return_val_if_fail (ip4 != NULL, NULL); ++ ++ domains = g_ptr_array_sized_new (5); ++ ++ /* To calculate the reverse DNS domains for this IP4 config, we take ++ * all the IP addresses and routes in the config, calculate the network ++ * portion, and convert that to classful, and use the network bits for ++ * the final domain. FIXME: better handle classless routing, which might ++ * require us to add multiple domains for each actual network prefix to ++ * cover all the separate networks in that block. ++ */ ++ ++ for (i = 0; i < nm_ip4_config_get_num_addresses (ip4); i++) { ++ NMIP4Address *addr = nm_ip4_config_get_address (ip4, i); ++ ++ add_ip4_to_rdns_array (nm_ip4_address_get_address (addr), domains); ++ } ++ ++ for (i = 0; i < nm_ip4_config_get_num_routes (ip4); i++) { ++ NMIP4Route *route = nm_ip4_config_get_route (ip4, i); ++ ++ add_ip4_to_rdns_array (nm_ip4_route_get_dest (route), domains); ++ } ++ ++ /* Terminating NULL so we can use g_strfreev() to free it */ ++ g_ptr_array_add (domains, NULL); ++ ++ /* Free the array and return NULL if the only element was the ending NULL */ ++ return (char **) g_ptr_array_free (domains, (domains->len == 1)); ++} ++ +diff --git a/src/dns-manager/nm-dns-utils.h b/src/dns-manager/nm-dns-utils.h +new file mode 100644 +index 0000000..daa6711 +--- /dev/null ++++ b/src/dns-manager/nm-dns-utils.h +@@ -0,0 +1,28 @@ ++/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ ++/* This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2, or (at your option) ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License along ++ * with this program; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ * ++ * Copyright (C) 2010 Red Hat, Inc. ++ * ++ */ ++ ++#ifndef NM_DNS_UTILS_H ++#define NM_DNS_UTILS_H ++ ++#include "nm-ip4-config.h" ++ ++char **nm_dns_utils_get_ip4_rdns_domains (NMIP4Config *ip4); ++ ++#endif /* NM_DNS_UTILS_H */ ++ +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/dns-fix-a-crash-due-to-uninitialized-nis_domain-nove.patch b/network/NetworkManager/patches/dns-fix-a-crash-due-to-uninitialized-nis_domain-nove.patch new file mode 100644 index 0000000000000..b96ab04e6cb5a --- /dev/null +++ b/network/NetworkManager/patches/dns-fix-a-crash-due-to-uninitialized-nis_domain-nove.patch @@ -0,0 +1,25 @@ +From 45ae52523158f4e7c0cc3fb5af56859c41512f66 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com> +Date: Wed, 24 Nov 2010 12:51:08 +0100 +Subject: [PATCH 4/4] dns: fix a crash due to uninitialized nis_domain (novell #655685) + +Reported and tested by Raymond Wooninck. Thanks! +--- + src/dns-manager/nm-dns-manager.c | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + +diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c +index 7a6fbbc..b0cdcc2 100644 +--- a/src/dns-manager/nm-dns-manager.c ++++ b/src/dns-manager/nm-dns-manager.c +@@ -583,6 +583,7 @@ update_dns (NMDnsManager *self, + rc.nameservers = g_ptr_array_new (); + rc.domain = NULL; + rc.searches = g_ptr_array_new (); ++ rc.nis_domain = NULL; + rc.nis_servers = g_ptr_array_new (); + + if (priv->ip4_vpn_config) +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/examples-fix-querying-active-connections.patch b/network/NetworkManager/patches/examples-fix-querying-active-connections.patch new file mode 100644 index 0000000000000..9598cadf767df --- /dev/null +++ b/network/NetworkManager/patches/examples-fix-querying-active-connections.patch @@ -0,0 +1,33 @@ +From 14617f6916124d29f65e380a3602746841203a57 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Tue, 23 Nov 2010 16:28:25 -0600 +Subject: [PATCH 2/4] examples: fix querying active connections + +--- + examples/python/nm-state.py | 6 +++--- + 1 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/examples/python/nm-state.py b/examples/python/nm-state.py +index fddd2da..2bbdd2d 100644 +--- a/examples/python/nm-state.py ++++ b/examples/python/nm-state.py +@@ -47,13 +47,13 @@ active = manager_prop_iface.Get("org.freedesktop.NetworkManager", "ActiveConnect + for a in active: + ac_proxy = bus.get_object("org.freedesktop.NetworkManager", a) + prop_iface = dbus.Interface(ac_proxy, "org.freedesktop.DBus.Properties") +- state = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "State") ++ state = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "State") + + # Connections in NM are a collection of settings that describe everything + # needed to connect to a specific network. Lets get those details so we + # can find the user-readable name of the connection. +- con_path = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "Connection") +- con_service = prop_iface.Get("org.freedesktop.NetworkManager.ActiveConnection", "ServiceName") ++ con_path = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection") ++ con_service = prop_iface.Get("org.freedesktop.NetworkManager.Connection.Active", "ServiceName") + + # ask the provider of the connection for its details + service_proxy = bus.get_object(con_service, con_path) +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/keyfile-allow-uppercase-MAC-addresses-in-unmanaged-d.patch b/network/NetworkManager/patches/keyfile-allow-uppercase-MAC-addresses-in-unmanaged-d.patch new file mode 100644 index 0000000000000..a26f988f2354e --- /dev/null +++ b/network/NetworkManager/patches/keyfile-allow-uppercase-MAC-addresses-in-unmanaged-d.patch @@ -0,0 +1,50 @@ +From e01c7b69abb9c118b9e0087803ca203ff157aa0a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com> +Date: Tue, 23 Nov 2010 16:27:21 +0100 +Subject: [PATCH 4/4] keyfile: allow uppercase MAC addresses in unmanaged-devices in config file (rh #654714) + +--- + system-settings/plugins/keyfile/plugin.c | 20 ++++++++++++++++++-- + 1 files changed, 18 insertions(+), 2 deletions(-) + +diff --git a/system-settings/plugins/keyfile/plugin.c b/system-settings/plugins/keyfile/plugin.c +index 5a927ce..da6456d 100644 +--- a/system-settings/plugins/keyfile/plugin.c ++++ b/system-settings/plugins/keyfile/plugin.c +@@ -23,6 +23,7 @@ + #include <sys/stat.h> + #include <unistd.h> + #include <sys/types.h> ++#include <netinet/ether.h> + #include <string.h> + + #include <gmodule.h> +@@ -418,8 +419,23 @@ get_unmanaged_specs (NMSystemConfigInterface *config) + udis = g_strsplit (str, ";", -1); + g_free (str); + +- for (i = 0; udis[i] != NULL; i++) +- specs = g_slist_append (specs, udis[i]); ++ for (i = 0; udis[i] != NULL; i++) { ++ /* Verify unmanaged specification and add it to the list */ ++ if (strlen (udis[i]) > 4 && !strncmp (udis[i], "mac:", 4) && ether_aton (udis[i] + 4)) { ++ char *p = udis[i]; ++ ++ /* To accept uppercase MACs in configuration file, we have to convert values to lowercase here. ++ * Unmanaged MACs in specs are always in lowercase. */ ++ while (*p) { ++ *p = g_ascii_tolower (*p); ++ p++; ++ } ++ specs = g_slist_append (specs, udis[i]); ++ } else { ++ g_warning ("Error in file '%s': invalid unmanaged-devices entry: '%s'", priv->conf_file, udis[i]); ++ g_free (udis[i]); ++ } ++ } + + g_free (udis); /* Yes, g_free, not g_strfreev because we need the strings in the list */ + } +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/keyfile-create-keyfile-data-directory-during-install.patch b/network/NetworkManager/patches/keyfile-create-keyfile-data-directory-during-install.patch new file mode 100644 index 0000000000000..f43b73c320a47 --- /dev/null +++ b/network/NetworkManager/patches/keyfile-create-keyfile-data-directory-during-install.patch @@ -0,0 +1,26 @@ +From 7deea59ad1d018888f18cee5ae3f70ee79ea6463 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Mon, 8 Nov 2010 09:07:08 -0600 +Subject: [PATCH 1/3] keyfile: create keyfile data directory during install + +So distributions don't have to do it. +--- + system-settings/plugins/keyfile/Makefile.am | 2 ++ + 1 files changed, 2 insertions(+), 0 deletions(-) + +diff --git a/system-settings/plugins/keyfile/Makefile.am b/system-settings/plugins/keyfile/Makefile.am +index 1c1fd4a..c519adc 100644 +--- a/system-settings/plugins/keyfile/Makefile.am ++++ b/system-settings/plugins/keyfile/Makefile.am +@@ -49,6 +49,8 @@ libnm_settings_plugin_keyfile_la_LIBADD = \ + $(DBUS_LIBS) \ + $(GIO_LIBS) + ++keyfiledir=$(sysconfdir)/NetworkManager/system-connections ++ + install-data-hook: + $(mkinstalldirs) -m 0755 $(DESTDIR)$(keyfiledir) + +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/ignore_temp_files.patch b/network/NetworkManager/patches/keyfile-ignore-temporary-files-bgo-602868.patch index c3bc95d11d41b..c3bc95d11d41b 100644 --- a/network/NetworkManager/patches/ignore_temp_files.patch +++ b/network/NetworkManager/patches/keyfile-ignore-temporary-files-bgo-602868.patch diff --git a/network/NetworkManager/patches/keyfile-quiet-keyfile-plugin-when-re-read-connection.patch b/network/NetworkManager/patches/keyfile-quiet-keyfile-plugin-when-re-read-connection.patch new file mode 100644 index 0000000000000..8e2a32217d601 --- /dev/null +++ b/network/NetworkManager/patches/keyfile-quiet-keyfile-plugin-when-re-read-connection.patch @@ -0,0 +1,48 @@ +From 4a15282e97a53d3df9062ec8e7e59288ad61e6f2 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Wed, 10 Nov 2010 16:14:51 +0100 +Subject: [PATCH 3/3] keyfile: quiet keyfile plugin when re-read connection is the same as in-memory one + +It occurs, for example, when NM updates connection's timestamp. +--- + system-settings/plugins/keyfile/plugin.c | 11 ++++++++--- + 1 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/system-settings/plugins/keyfile/plugin.c b/system-settings/plugins/keyfile/plugin.c +index 27ae0a0..f57a4b6 100644 +--- a/system-settings/plugins/keyfile/plugin.c ++++ b/system-settings/plugins/keyfile/plugin.c +@@ -203,15 +203,18 @@ dir_changed (GFileMonitor *monitor, + break; + case G_FILE_MONITOR_EVENT_CREATED: + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: +- PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "updating %s", name); +- + if (connection) { + /* Update */ + NMKeyfileConnection *tmp; + + tmp = nm_keyfile_connection_new (name, &error); + if (tmp) { +- update_connection_settings (connection, tmp); ++ if (!nm_connection_compare (NM_CONNECTION (connection), ++ NM_CONNECTION (tmp), ++ NM_SETTING_COMPARE_FLAG_EXACT)) { ++ PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "updating %s", name); ++ update_connection_settings (connection, tmp); ++ } + g_object_unref (tmp); + } else { + /* Error; remove the connection */ +@@ -221,6 +224,8 @@ dir_changed (GFileMonitor *monitor, + remove_connection (SC_PLUGIN_KEYFILE (config), connection, name); + } + } else { ++ PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "updating %s", name); ++ + /* New */ + connection = nm_keyfile_connection_new (name, &error); + if (connection) { +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/libnm-glib-actually-define-the-ip-interface-property.patch b/network/NetworkManager/patches/libnm-glib-actually-define-the-ip-interface-property.patch new file mode 100644 index 0000000000000..a01f320bf684b --- /dev/null +++ b/network/NetworkManager/patches/libnm-glib-actually-define-the-ip-interface-property.patch @@ -0,0 +1,38 @@ +From d1a92a4d4da80b4cdc53164a42cbe29c03b1c8c1 Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Tue, 7 Dec 2010 14:12:55 -0600 +Subject: [PATCH] libnm-glib: actually define the "ip-interface" property + +Looks like it got left out of 6ab5a9597a26235c9839df346fc3ce95f35a240f +--- + libnm-glib/nm-device.c | 14 ++++++++++++++ + 1 files changed, 14 insertions(+), 0 deletions(-) + +diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c +index ea2a91d..b8998f7 100644 +--- a/libnm-glib/nm-device.c ++++ b/libnm-glib/nm-device.c +@@ -477,6 +477,20 @@ nm_device_class_init (NMDeviceClass *device_class) + G_PARAM_READABLE)); + + /** ++ * NMDevice:ip-interface: ++ * ++ * The IP interface of the device which should be used for all IP-related ++ * operations like addressing and routing. ++ **/ ++ g_object_class_install_property ++ (object_class, PROP_IP_INTERFACE, ++ g_param_spec_string (NM_DEVICE_IP_INTERFACE, ++ "IP Interface", ++ "IP Interface name", ++ NULL, ++ G_PARAM_READABLE)); ++ ++ /** + * NMDevice:udi: + * + * The Unique Device Identifier of the device. +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/libnm-util-fix-a-memory-leaks-in-nm_setting_to_strin.patch b/network/NetworkManager/patches/libnm-util-fix-a-memory-leaks-in-nm_setting_to_strin.patch new file mode 100644 index 0000000000000..bf8ccfc57dfab --- /dev/null +++ b/network/NetworkManager/patches/libnm-util-fix-a-memory-leaks-in-nm_setting_to_strin.patch @@ -0,0 +1,25 @@ +From 71fcccbacd51e939f168d44301393301e9dcb5fe Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes@redhat.com> +Date: Mon, 13 Dec 2010 20:55:02 +0100 +Subject: [PATCH] libnm-util: fix a memory leaks in nm_setting_to_string() + +--- + libnm-util/nm-setting.c | 2 ++ + 1 files changed, 2 insertions(+), 0 deletions(-) + +diff --git a/libnm-util/nm-setting.c b/libnm-util/nm-setting.c +index 06994c7..190199c 100644 +--- a/libnm-util/nm-setting.c ++++ b/libnm-util/nm-setting.c +@@ -620,6 +620,8 @@ nm_setting_to_string (NMSetting *setting) + is_serializable = prop_spec->flags & NM_SETTING_PARAM_SERIALIZE; + is_default = g_param_value_defaults (prop_spec, &value); + ++ g_value_unset (&value); ++ + if (is_serializable || is_default) { + g_string_append (string, " ("); + +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/modem-handle-IP-Method-changes-after-modem-has-been-.patch b/network/NetworkManager/patches/modem-handle-IP-Method-changes-after-modem-has-been-.patch new file mode 100644 index 0000000000000..9226640c7d02a --- /dev/null +++ b/network/NetworkManager/patches/modem-handle-IP-Method-changes-after-modem-has-been-.patch @@ -0,0 +1,31 @@ +From b83322655b6bbf616fb8021a6a69584ae1486f7e Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Sat, 1 Jan 2011 18:00:50 -0600 +Subject: [PATCH 6/8] modem: handle IP Method changes after modem has been created + +Some modems don't know their IP method when they are created, but +will update it later. Handle the changed signal for that. +--- + src/modem-manager/nm-modem.c | 6 ++++++ + 1 files changed, 6 insertions(+), 0 deletions(-) + +diff --git a/src/modem-manager/nm-modem.c b/src/modem-manager/nm-modem.c +index e07b818..b3f7eaa 100644 +--- a/src/modem-manager/nm-modem.c ++++ b/src/modem-manager/nm-modem.c +@@ -876,6 +876,12 @@ modem_properties_changed (DBusGProxy *proxy, + priv->mm_enabled = g_value_get_boolean (value); + g_object_notify (G_OBJECT (self), NM_MODEM_ENABLED); + } ++ ++ value = g_hash_table_lookup (props, "IpMethod"); ++ if (value && G_VALUE_HOLDS_UINT (value)) { ++ priv->ip_method = g_value_get_uint (value); ++ g_object_notify (G_OBJECT (self), NM_MODEM_IP_METHOD); ++ } + } + + /*****************************************************************************/ +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/policy-don-t-update-hostname-on-exit.patch b/network/NetworkManager/patches/policy-don-t-update-hostname-on-exit.patch new file mode 100644 index 0000000000000..720651619d5a0 --- /dev/null +++ b/network/NetworkManager/patches/policy-don-t-update-hostname-on-exit.patch @@ -0,0 +1,42 @@ +From 2ce6f29c2151af3f34976feda6964a21431cdb5f Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Sun, 2 Jan 2011 10:24:23 -0600 +Subject: [PATCH 7/8] policy: don't update hostname on exit + +It's a leftover from when /etc/hosts got fixed up, and since that +isn't being done anymore, there's no reason to touch the hostname +on exit. It will already have been updated in response to device +deactivation (if the hostname was DHCP-provided for example) so +it shouldn't need to be touched on exit. + +This also removes a potential crash on shutdown when systemd or +another startup manager kills D-Bus before NetworkManager, which +made the dispatcher code angry (which got executed on hostname +change). +--- + src/nm-policy.c | 9 --------- + 1 files changed, 0 insertions(+), 9 deletions(-) + +diff --git a/src/nm-policy.c b/src/nm-policy.c +index 709be09..aed2f89 100644 +--- a/src/nm-policy.c ++++ b/src/nm-policy.c +@@ -1195,15 +1195,6 @@ 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); + +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/policy-stop-touching-etc-hosts.patch b/network/NetworkManager/patches/policy-stop-touching-etc-hosts.patch new file mode 100644 index 0000000000000..7591479091802 --- /dev/null +++ b/network/NetworkManager/patches/policy-stop-touching-etc-hosts.patch @@ -0,0 +1,1703 @@ +From 6fe0413366fc02ba3ffdd24db670852bc134110f Mon Sep 17 00:00:00 2001 +From: Dan Williams <dcbw@redhat.com> +Date: Fri, 17 Dec 2010 09:22:11 -0600 +Subject: [PATCH 1/8] policy: stop touching /etc/hosts + +Handling of /etc/hosts is highly site- and admin- specific in +many more complex cases, and it's exceedingly hard and error- +prone for NetworkManager to handle all those cases. So remove +this functionality entirely. That's not a big loss, as it +turns out there's a much more elegant solution. + +The only requirement is that the machine's hostname map back +to an IP address owned by the machine. That requirement can +be satisifed by nss-myhostname or even possibly the distro's +installer. If the user does not want nss-myhostname then it +can be uninstalled. Distros should use a "recommends" feature +in their packaging system so that the NetworkManager package +does *not* have a hard requirement on nss-myhostname. Thus +everyone is happy; things Just Work when nss-myhostname is +installed, but more advanced users can uninstall it and +customize /etc/hosts as they wish. + +Another alternative is a dispatcher script that listents for +the 'hostname' event, and updates /etc/hosts according to the +administrator's preference. +--- + src/main.c | 4 + + src/nm-policy-hostname.c | 56 +--- + src/nm-policy-hostname.h | 5 +- + src/nm-policy-hosts.c | 520 ++-------------------------- + src/nm-policy-hosts.h | 20 +- + src/nm-policy.c | 42 +--- + src/tests/test-policy-hosts.c | 761 ++--------------------------------------- + 7 files changed, 76 insertions(+), 1332 deletions(-) + +diff --git a/src/main.c b/src/main.c +index 7e75f05..2db7345 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -49,6 +49,7 @@ + #include "nm-netlink-monitor.h" + #include "nm-vpn-manager.h" + #include "nm-logging.h" ++#include "nm-policy-hosts.h" + + #if !defined(NM_DIST_VERSION) + # define NM_DIST_VERSION VERSION +@@ -713,6 +714,9 @@ main (int argc, char *argv[]) + goto done; + } + ++ /* Clean leftover "# Added by NetworkManager" entries from /etc/hosts */ ++ nm_policy_hosts_clean_etc_hosts (); ++ + nm_manager_start (manager); + + /* Bring up the loopback interface. */ +diff --git a/src/nm-policy-hostname.c b/src/nm-policy-hostname.c +index 42a2e0f..4fe69c5 100644 +--- a/src/nm-policy-hostname.c ++++ b/src/nm-policy-hostname.c +@@ -30,7 +30,6 @@ + + #include "nm-logging.h" + #include "nm-policy-hostname.h" +-#include "nm-policy-hosts.h" + + /************************************************************************/ + +@@ -206,74 +205,39 @@ hostname_thread_is_dead (HostnameThread *ht) + /************************************************************************/ + + #define FALLBACK_HOSTNAME4 "localhost.localdomain" +-#define FALLBACK_HOSTNAME6 "localhost6.localdomain6" + + gboolean +-nm_policy_set_system_hostname (const char *new_hostname, +- const char *ip4_addr, +- const char *ip6_addr, +- const char *msg) ++nm_policy_set_system_hostname (const char *new_hostname, const char *msg) + { + char old_hostname[HOST_NAME_MAX + 1]; +- int ret = 0; + const char *name; +- gboolean set_hostname = TRUE, changed = FALSE, old_valid = TRUE; ++ int ret; + + if (new_hostname) + g_warn_if_fail (strlen (new_hostname)); + +- name = (new_hostname && strlen (new_hostname)) ? new_hostname : FALLBACK_HOSTNAME4; +- + old_hostname[HOST_NAME_MAX] = '\0'; + errno = 0; + ret = gethostname (old_hostname, HOST_NAME_MAX); + if (ret != 0) { + nm_log_warn (LOGD_DNS, "couldn't get the system hostname: (%d) %s", + errno, strerror (errno)); +- old_valid = FALSE; + } else { + /* Don't set the hostname if it isn't actually changing */ + if ( (new_hostname && !strcmp (old_hostname, new_hostname)) + || (!new_hostname && !strcmp (old_hostname, FALLBACK_HOSTNAME4))) +- set_hostname = FALSE; +- +- if (old_hostname[0] == '\0') +- old_valid = FALSE; +- } +- +- if (set_hostname) { +- nm_log_info (LOGD_DNS, "Setting system hostname to '%s' (%s)", name, msg); +- ret = sethostname (name, strlen (name)); +- if (ret != 0) { +- nm_log_warn (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s", +- name, errno, strerror (errno)); + return FALSE; +- } + } + +- /* But even if the hostname isn't changing, always try updating /etc/hosts +- * just in case the hostname changed while NM wasn't running; we need to +- * make sure that /etc/hosts has valid mappings for '127.0.0.1' and the +- * current system hostname. If those exist, +- * nm_policy_hosts_update_etc_hosts() will just return and won't touch +- * /etc/hosts at all. +- */ +- if (!nm_policy_hosts_update_etc_hosts (name, +- old_valid ? old_hostname : NULL, +- FALLBACK_HOSTNAME4, +- FALLBACK_HOSTNAME6, +- ip4_addr, +- ip6_addr, +- &changed)) { +- /* error updating /etc/hosts; fallback to localhost.localdomain */ +- nm_log_info (LOGD_DNS, "Setting system hostname to '" FALLBACK_HOSTNAME4 "' (error updating /etc/hosts)"); +- ret = sethostname (FALLBACK_HOSTNAME4, strlen (FALLBACK_HOSTNAME4)); +- if (ret != 0) { +- nm_log_warn (LOGD_DNS, "couldn't set the fallback system hostname (%s): (%d) %s", +- FALLBACK_HOSTNAME4, errno, strerror (errno)); +- } ++ name = (new_hostname && strlen (new_hostname)) ? new_hostname : FALLBACK_HOSTNAME4; ++ ++ nm_log_info (LOGD_DNS, "Setting system hostname to '%s' (%s)", name, msg); ++ ret = sethostname (name, strlen (name)); ++ if (ret != 0) { ++ nm_log_warn (LOGD_DNS, "couldn't set the system hostname to '%s': (%d) %s", ++ name, errno, strerror (errno)); + } + +- return changed; ++ return (ret == 0); + } + +diff --git a/src/nm-policy-hostname.h b/src/nm-policy-hostname.h +index 9c76884..e76713f 100644 +--- a/src/nm-policy-hostname.h ++++ b/src/nm-policy-hostname.h +@@ -24,10 +24,7 @@ + + #include <glib.h> + +-gboolean nm_policy_set_system_hostname (const char *new_hostname, +- const char *ip4_addr, +- const char *ip6_addr, +- const char *msg); ++gboolean nm_policy_set_system_hostname (const char *new_hostname, const char *msg); + + + typedef struct HostnameThread HostnameThread; +diff --git a/src/nm-policy-hosts.c b/src/nm-policy-hosts.c +index 7f9cff8..8bbd1d3 100644 +--- a/src/nm-policy-hosts.c ++++ b/src/nm-policy-hosts.c +@@ -20,526 +20,74 @@ + + #include <config.h> + #include <string.h> +-#include <unistd.h> +-#include <errno.h> +-#include <netdb.h> +-#include <ctype.h> +-#include <arpa/inet.h> + + #include "nm-policy-hosts.h" + #include "nm-logging.h" + +-#define IP4_LH "127.0.0.1" +-#define IP6_LH "::1" +- +-gboolean +-nm_policy_hosts_find_token (const char *line, const char *token) +-{ +- const char *start = line, *p = line; +- +- g_return_val_if_fail (line != NULL, FALSE); +- g_return_val_if_fail (token != NULL, FALSE); +- g_return_val_if_fail (strlen (token) > 0, FALSE); +- +- /* Walk through the line to find the next whitespace character */ +- while (p <= line + strlen (line)) { +- if (isblank (*p) || (*p == '\0')) { +- /* Token starts with 'start' and ends with 'end' */ +- if ((p > start) && *start && (p - start == strlen (token)) && !strncmp (start, token, (p - start))) +- return TRUE; /* found */ +- +- /* not found; advance start and continue looking */ +- start = p + 1; +- } +- p++; +- } +- +- return FALSE; +-} +- +-static gboolean +-is_local_mapping (const char *str, gboolean ip6, const char *hostname) +-{ +- const char *addr = ip6 ? IP6_LH : IP4_LH; +- const char *fallback = ip6 ? "localhost6" : "localhost"; +- +- return ( !strncmp (str, addr, strlen (addr)) +- && nm_policy_hosts_find_token (str, hostname ? hostname : fallback)); +-} +- +-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; +- char buf[INET_ADDRSTRLEN + 2]; +- const char *p = str; +- guint32 i = 0; +- +- g_return_val_if_fail (ip4_addr != NULL, FALSE); +- +- memset (buf, 0, sizeof (buf)); +- while (*p && !isblank (*p) && (i < sizeof (buf))) +- buf[i++] = *p++; +- +- if (inet_pton (AF_INET, buf, &found) != 1) +- return FALSE; +- if (inet_pton (AF_INET, ip4_addr, &given) != 1) +- return FALSE; +- +- return memcmp (&found, &given, sizeof (found)) == 0; +-} +- +-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; +- char buf[INET6_ADDRSTRLEN + 2]; +- const char *p = str; +- guint32 i = 0; +- +- g_return_val_if_fail (ip6_addr != NULL, FALSE); +- +- memset (buf, 0, sizeof (buf)); +- while (*p && !isblank (*p) && (i < sizeof (buf))) +- buf[i++] = *p++; +- +- if (inet_pton (AF_INET6, buf, &found) != 1) +- return FALSE; +- if (inet_pton (AF_INET6, ip6_addr, &given) != 1) +- return FALSE; +- +- return memcmp (&found, &given, sizeof (found)) == 0; +-} +- +-static char * +-get_custom_hostnames (const char *line, +- const char *hostname, +- const char *old_hostname, +- const char *short_hostname, +- const char *fallback_hostname) +-{ +- char **items = NULL, **iter; +- guint start = 0; +- GString *str = NULL; +- char *custom = NULL; +- +- g_return_val_if_fail (line != NULL, NULL); +- +- if (!strncmp (line, IP4_LH, strlen (IP4_LH))) +- start = strlen (IP4_LH); +- else if (!strncmp (line, IP6_LH, strlen (IP6_LH))) +- start = strlen (IP6_LH); +- +- g_return_val_if_fail (start > 0, NULL); +- +- /* Split the line into tokens */ +- items = g_strsplit_set (line + start, " \t", -1); +- if (!items) +- return NULL; +- +- str = g_string_sized_new (50); +- /* Ignore current & old hostnames, and localhost-anything */ +- for (iter = items; iter && *iter; iter++) { +- if (*iter[0] == '\0') +- continue; +- if (hostname && !strcmp (*iter, hostname)) +- continue; +- if (old_hostname && !strcmp (*iter, old_hostname)) +- continue; +- if (short_hostname && !strcmp (*iter, short_hostname)) +- continue; +- if (fallback_hostname && !strcmp (*iter, fallback_hostname)) +- continue; +- if (!strcmp (*iter, "localhost")) +- continue; +- if (!strcmp (*iter, "localhost6")) +- continue; +- if (!strcmp (*iter, "localhost.localdomain")) +- continue; +- if (!strcmp (*iter, "localhost4.localdomain4")) +- continue; +- if (!strcmp (*iter, "localhost6.localdomain6")) +- continue; +- +- /* Found a custom hostname */ +- g_string_append_c (str, '\t'); +- g_string_append (str, *iter); +- } +- +- if (str->len) +- custom = g_string_free (str, FALSE); +- else +- g_string_free (str, TRUE); +- +- g_strfreev (items); +- return custom; +-} +- + #define ADDED_TAG "# Added by NetworkManager" + + GString * +-nm_policy_get_etc_hosts (const char **lines, +- gsize existing_len, +- const char *hostname, +- const char *old_hostname, +- const char *fallback_hostname4, +- const char *fallback_hostname6, +- const char *ip4_addr, +- const char *ip6_addr, +- GError **error) ++nm_policy_get_etc_hosts (const char *contents, gsize contents_len) + { +- GString *contents = NULL; +- const char **line; +- gboolean found_localhost4 = FALSE; +- gboolean found_localhost6 = FALSE; +- gboolean found_host4 = FALSE; +- gboolean found_host6 = FALSE; +- gboolean found_user_host4 = FALSE; +- gboolean found_user_host6 = FALSE; +- gboolean initial_comments = TRUE; +- gboolean added = FALSE; +- gboolean hostname4_is_fallback; +- gboolean hostname6_is_fallback; +- gboolean host4_before = FALSE; +- gboolean host6_before = FALSE; +- gboolean no_stale = TRUE; +- char *short_hostname = NULL; +- char *custom4 = NULL; +- char *custom6 = NULL; +- +- g_return_val_if_fail (lines != NULL, FALSE); +- g_return_val_if_fail (hostname != NULL, FALSE); +- +- hostname4_is_fallback = !strcmp (hostname, fallback_hostname4); +- hostname6_is_fallback = !strcmp (hostname, fallback_hostname6); +- +- /* Find the short hostname, like 'foo' from 'foo.bar.baz'; we want to +- * make sure that the entries we add for this host also include the short +- * hostname too so that if the resolver does not answer queries for the +- * machine's actual hostname/domain, that stuff like 'ping foo' still works. +- */ +- if (!hostname4_is_fallback || !hostname6_is_fallback) { +- char *dot; +- +- short_hostname = g_strdup (hostname); +- dot = strchr (short_hostname, '.'); +- if (dot && *(dot+1)) +- *dot = '\0'; +- else { +- g_free (short_hostname); +- short_hostname = NULL; +- } +- } +- +- /* We need the following in /etc/hosts: +- * +- * 1) current hostname mapped to current IPv4 addresses if IPv4 is active +- * 2) current hostname mapped to current IPv6 addresses if IPv6 is active +- * 3) 'localhost' mapped to 127.0.0.1 +- * 4) 'localhost6' mapped to ::1 +- * +- * If all these things exist we don't need to bother updating the file. +- */ +- +- if (!ip4_addr) +- host4_before = TRUE; +- if (!ip6_addr) +- host6_before = TRUE; +- +- /* Look for the four cases from above */ +- for (line = lines; lines && *line; line++) { +- gboolean found_hostname = FALSE; +- +- if ((*line[0] == '\0') || (*line[0] == '#')) +- continue; ++ char **lines = NULL, **iter; ++ GString *new_contents = NULL; + +- found_hostname = nm_policy_hosts_find_token (*line, hostname); +- if (found_hostname) { +- /* Found the current hostname on this line */ +- if (ip4_addr && ip4_addr_matches (*line, ip4_addr)) { +- found_host4 = TRUE; +- if (strstr (*line, ADDED_TAG)) { +- if (!host4_before) +- host4_before = !found_localhost4; +- } else { +- 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)) +- no_stale = FALSE; +- } ++ if (contents_len == 0 || !strstr (contents, ADDED_TAG)) ++ return NULL; + +- if (ip6_addr && ip6_addr_matches (*line, ip6_addr)) { +- found_host6 = TRUE; +- if (strstr (*line, ADDED_TAG)) { +- if (!host6_before) +- host6_before = !found_localhost6; +- } else { +- 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)) +- no_stale = FALSE; +- } +- } ++ new_contents = g_string_sized_new (contents_len); + +- if (is_local_mapping (*line, FALSE, "localhost")) { +- /* a 127.0.0.1 line containing 'localhost' */ +- found_localhost4 = TRUE; +- custom4 = get_custom_hostnames (*line, hostname, old_hostname, short_hostname, fallback_hostname4); +- if (!ip4_addr) { +- /* If there's no IP-specific mapping for the current hostname +- * but that hostname is present on in the local mapping line, +- * we've found our IPv4 hostname mapping. If the hostname is +- * the fallback *IPv6* hostname it's not going to show up in +- * the IPv4 local mapping though, so fake it. +- */ +- if (hostname6_is_fallback || found_hostname) +- found_host4 = TRUE; +- } +- } else if (is_local_mapping (*line, TRUE, "localhost6")) { +- /* a ::1 line containing 'localhost6' */ +- found_localhost6 = TRUE; +- custom6 = get_custom_hostnames (*line, hostname, old_hostname, short_hostname, fallback_hostname6); +- if (!ip6_addr) { +- /* If there's no IP-specific mapping for the current hostname +- * but that hostname is present on in the local mapping line, +- * we've found our IPv6 hostname mapping. If the hostname is +- * the fallback *IPv4* hostname it's not going to show up in +- * the IPv6 local mapping though, so fake it. +- */ +- if (hostname4_is_fallback || found_hostname) +- found_host6 = TRUE; +- } ++ /* Remove "# Added ..." lines */ ++ lines = g_strsplit_set (contents, "\n\r", -1); ++ for (iter = lines; iter && *iter; iter++) { ++ if (!strstr (*iter, ADDED_TAG)) { ++ g_string_append (new_contents, *iter); ++ g_string_append_c (new_contents, '\n'); + } +- +- if ( found_localhost4 +- && found_host4 +- && found_localhost6 +- && found_host6 +- && host4_before +- && host6_before +- && no_stale) +- goto out; /* No update required */ +- } +- +- contents = g_string_sized_new (existing_len ? existing_len + 100 : 200); +- if (!contents) { +- g_set_error_literal (error, 0, 0, "not enough memory"); +- goto out; + } ++ g_strfreev (lines); + +- /* Construct the new hosts file; replace any 127.0.0.1/::1 entry that is +- * at the beginning of the file or right after initial comments and contains +- * the string 'localhost' (for IPv4) or 'localhost6' (for IPv6). If there +- * is no 127.0.0.1 or ::1 entry at the beginning or after initial comments +- * that contains 'localhost' or 'localhost6', add one there +- * and ignore any other 127.0.0.1/::1 entries that contain 'localhost' or +- * 'localhost6'. ++ /* Remove last blank line at end of file, if one exists; this is ++ * an artifact of how g_strsplit_set() works. + */ +- for (line = lines, initial_comments = TRUE; lines && *line; line++) { +- /* This is the first line after the initial comments */ +- if (strlen (*line) && initial_comments && (*line[0] != '#')) { +- initial_comments = FALSE; +- +- /* If the user added their own mapping for the hostname, just make +- * a simple 'localhost' mapping and assume the user knows what they +- * are doing with their manual hostname entry. Otherwise if the +- * hostname wasn't found somewhere else, add it to the localhost +- * mapping line to make sure it's mapped to something. +- */ +- +- /* Add the address mappings first so they take precedence */ +- if (!hostname4_is_fallback && ip4_addr && !found_user_host4) { +- g_string_append_printf (contents, "%s\t%s", ip4_addr, hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- g_string_append_printf (contents, "\t%s\n", ADDED_TAG); +- } +- if (!hostname6_is_fallback && ip6_addr && !found_user_host6) { +- g_string_append_printf (contents, "%s\t%s", ip6_addr, hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- g_string_append_printf (contents, "\t%s\n", ADDED_TAG); +- } ++ if ( (new_contents->len > 2) ++ && (new_contents->str[new_contents->len - 1] == '\n')) ++ g_string_truncate (new_contents, new_contents->len - 1); + +- /* IPv4 localhost line */ +- g_string_append (contents, "127.0.0.1"); +- if (!hostname4_is_fallback && !ip4_addr && !found_user_host4) { +- g_string_append_printf (contents, "\t%s", hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- } +- g_string_append_printf (contents, "\t%s\tlocalhost", fallback_hostname4); +- if (custom4) +- g_string_append (contents, custom4); +- g_string_append_c (contents, '\n'); +- +- /* IPv6 localhost line */ +- g_string_append (contents, "::1"); +- if (!hostname6_is_fallback && !hostname4_is_fallback && !ip6_addr && !found_user_host6) { +- g_string_append_printf (contents, "\t%s", hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- } +- g_string_append_printf (contents, "\t%s\tlocalhost6", fallback_hostname6); +- if (custom6) +- g_string_append (contents, custom6); +- g_string_append_c (contents, '\n'); +- +- added = TRUE; +- } +- +- /* Don't add the original line if it is a localhost mapping */ +- if ( !is_local_mapping (*line, FALSE, "localhost") +- && !is_local_mapping (*line, FALSE, fallback_hostname4) +- && !is_local_mapping (*line, FALSE, hostname) +- && !is_local_mapping (*line, TRUE, "localhost6") +- && !is_local_mapping (*line, TRUE, fallback_hostname6) +- && !is_local_mapping (*line, TRUE, hostname) +- && !strstr (*line, ADDED_TAG)) { +- +- g_string_append (contents, *line); +- /* Only append the new line if this isn't the last line in the file */ +- if (*(line+1)) +- g_string_append_c (contents, '\n'); +- } +- } +- +- /* Hmm, /etc/hosts was empty for some reason */ +- if (!added) { +- g_string_append (contents, "# Do not remove the following lines, or various programs\n"); +- g_string_append (contents, "# that require network functionality will fail.\n"); +- +- /* Add the address mappings first so they take precedence */ +- if (!hostname4_is_fallback && ip4_addr) { +- g_string_append_printf (contents, "%s\t%s", ip4_addr, hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- g_string_append_printf (contents, "\t%s\n", ADDED_TAG); +- } +- if (!hostname6_is_fallback && ip6_addr) { +- g_string_append_printf (contents, "%s\t%s", ip6_addr, hostname); +- if (short_hostname) +- g_string_append_printf (contents, "\t%s", short_hostname); +- g_string_append_printf (contents, "\t%s\n", ADDED_TAG); +- } +- +- g_string_append_printf (contents, "127.0.0.1\t%s\tlocalhost\n", fallback_hostname4); +- g_string_append_printf (contents, "::1\t%s\tlocalhost6\n", fallback_hostname6); +- } +- +-out: +- g_free (custom4); +- g_free (custom6); +- g_free (short_hostname); +- return contents; ++ return new_contents; + } + +-gboolean +-nm_policy_hosts_update_etc_hosts (const char *hostname, +- const char *old_hostname, +- const char *fallback_hostname4, +- const char *fallback_hostname6, +- const char *ip4_addr, +- const char *ip6_addr, +- gboolean *out_changed) ++/* remove any leftover "# Added by NetworkManager" lines */ ++void ++nm_policy_hosts_clean_etc_hosts (void) + { + char *contents = NULL; +- char **lines = NULL; +- GError *error = NULL; +- GString *new_contents = NULL; + gsize contents_len = 0; +- gboolean success = FALSE; +- +- g_return_val_if_fail (hostname != NULL, FALSE); +- g_return_val_if_fail (out_changed != NULL, FALSE); ++ GError *error = NULL; ++ GString *new; + + if (!g_file_get_contents (SYSCONFDIR "/hosts", &contents, &contents_len, &error)) { + nm_log_warn (LOGD_DNS, "couldn't read " SYSCONFDIR "/hosts: (%d) %s", + error ? error->code : 0, + (error && error->message) ? error->message : "(unknown)"); + g_clear_error (&error); +- return FALSE; ++ return; + } + +- /* Get the new /etc/hosts contents */ +- lines = g_strsplit_set (contents, "\n\r", 0); +- new_contents = nm_policy_get_etc_hosts ((const char **) lines, +- contents_len, +- hostname, +- old_hostname, +- fallback_hostname4, +- fallback_hostname6, +- ip4_addr, +- ip6_addr, +- &error); +- g_strfreev (lines); +- g_free (contents); +- +- if (new_contents) { +- nm_log_info (LOGD_DNS, "Updating /etc/hosts with new system hostname"); ++ new = nm_policy_get_etc_hosts (contents, contents_len); ++ if (new && new->len) { ++ nm_log_info (LOGD_DNS, "Cleaning leftovers from /etc/hosts"); + + g_clear_error (&error); +- /* And actually update /etc/hosts */ +- if (!g_file_set_contents (SYSCONFDIR "/hosts", new_contents->str, -1, &error)) { +- nm_log_warn (LOGD_DNS, "couldn't update " SYSCONFDIR "/hosts: (%d) %s", +- error ? error->code : 0, +- (error && error->message) ? error->message : "(unknown)"); ++ if (!g_file_set_contents (SYSCONFDIR "/hosts", new->str, -1, &error)) { ++ nm_log_dbg (LOGD_DNS, "couldn't update " SYSCONFDIR "/hosts: (%d) %s", ++ error ? error->code : 0, ++ (error && error->message) ? error->message : "(unknown)"); + g_clear_error (&error); +- } else { +- success = TRUE; +- *out_changed = TRUE; + } +- +- g_string_free (new_contents, TRUE); +- } else if (!error) { +- /* No change required */ +- success = TRUE; +- } else { +- nm_log_warn (LOGD_DNS, "couldn't read " SYSCONFDIR "/hosts: (%d) %s", +- error->code, error->message ? error->message : "(unknown)"); +- g_clear_error (&error); + } + +- return success; ++ if (new) ++ g_string_free (new, TRUE); + } + +diff --git a/src/nm-policy-hosts.h b/src/nm-policy-hosts.h +index ebaaf0f..9f4bf9a 100644 +--- a/src/nm-policy-hosts.h ++++ b/src/nm-policy-hosts.h +@@ -23,26 +23,10 @@ + + #include <glib.h> + +-gboolean nm_policy_hosts_update_etc_hosts (const char *hostname, +- const char *old_hostname, +- const char *fallback_hostname4, +- const char *fallback_hostname6, +- const char *ip4_addr, +- const char *ip6_addr, +- gboolean *out_changed); ++void nm_policy_hosts_clean_etc_hosts (void); + + /* Only for testcases; don't use outside of nm-policy-hosts.c */ +-gboolean nm_policy_hosts_find_token (const char *line, const char *token); +- +-GString *nm_policy_get_etc_hosts (const char **lines, +- gsize existing_len, +- const char *hostname, +- const char *old_hostname, +- const char *fallback_hostname4, +- const char *fallback_hostname6, +- const char *ip4_addr, +- const char *ip6_addr, +- GError **error); ++GString *nm_policy_get_etc_hosts (const char *contents, gsize contents_len); + + #endif /* NM_POLICY_HOSTS_H */ + +diff --git a/src/nm-policy.c b/src/nm-policy.c +index e8a18d0..709be09 100644 +--- a/src/nm-policy.c ++++ b/src/nm-policy.c +@@ -42,7 +42,6 @@ + #include "nm-system.h" + #include "nm-dns-manager.h" + #include "nm-vpn-manager.h" +-#include "nm-policy-hosts.h" + #include "nm-policy-hostname.h" + + struct NMPolicy { +@@ -233,9 +232,6 @@ _set_hostname (NMPolicy *policy, + const char *new_hostname, + const char *msg) + { +- char ip4_addr[INET_ADDRSTRLEN + 1]; +- char ip6_addr[INET6_ADDRSTRLEN + 1]; +- + if (change_hostname) { + NMDnsManager *dns_mgr; + +@@ -247,43 +243,7 @@ _set_hostname (NMPolicy *policy, + g_object_unref (dns_mgr); + } + +- /* Get the default IPv4 and IPv6 addresses so we can assign +- * the hostname to them in /etc/hosts. +- */ +- memset (ip4_addr, 0, sizeof (ip4_addr)); +- if (policy->default_device4) { +- NMIP4Config *config = NULL; +- NMIP4Address *addr = NULL; +- +- config = nm_device_get_ip4_config (policy->default_device4); +- if (config) +- addr = nm_ip4_config_get_address (config, 0); +- +- if (addr) { +- struct in_addr tmp; +- +- tmp.s_addr = nm_ip4_address_get_address (addr); +- inet_ntop (AF_INET, &tmp, ip4_addr, sizeof (ip4_addr)); +- } +- } +- +- memset (ip6_addr, 0, sizeof (ip6_addr)); +- if (policy->default_device6) { +- NMIP6Config *config = NULL; +- NMIP6Address *addr = NULL; +- +- config = nm_device_get_ip6_config (policy->default_device6); +- if (config) +- addr = nm_ip6_config_get_address (config, 0); +- +- if (addr) +- inet_ntop (AF_INET6, nm_ip6_address_get_address (addr), ip6_addr, sizeof (ip6_addr)); +- } +- +- if (nm_policy_set_system_hostname (policy->cur_hostname, +- strlen (ip4_addr) ? ip4_addr : NULL, +- strlen (ip6_addr) ? ip6_addr : NULL, +- msg)) ++ if (nm_policy_set_system_hostname (policy->cur_hostname, msg)) + nm_utils_call_dispatcher ("hostname", NULL, NULL, NULL); + } + +diff --git a/src/tests/test-policy-hosts.c b/src/tests/test-policy-hosts.c +index 8865c42..62862e7 100644 +--- a/src/tests/test-policy-hosts.c ++++ b/src/tests/test-policy-hosts.c +@@ -23,41 +23,17 @@ + + #include "nm-policy-hosts.h" + +-#define FALLBACK_HOSTNAME4 "localhost.localdomain" +-#define FALLBACK_HOSTNAME6 "localhost6.localdomain6" +- +-#define DEBUG 0 ++#define DEBUG 1 + + static void +-test_generic (const char *before, +- const char *after, +- const char *hostname, +- const char *ip4_addr, +- const char *ip6_addr, +- gboolean expect_error) ++test_generic (const char *before, const char *after) + { +- char **lines; + GString *newc; +- GError *error = NULL; + + /* Get the new /etc/hosts contents */ +- lines = g_strsplit_set (before, "\n\r", 0); +- newc = nm_policy_get_etc_hosts ((const char **) lines, +- strlen (before), +- hostname, +- NULL, +- FALLBACK_HOSTNAME4, +- FALLBACK_HOSTNAME6, +- ip4_addr, +- ip6_addr, +- &error); +- g_strfreev (lines); ++ newc = nm_policy_get_etc_hosts (before, strlen (before)); + +- if (expect_error) { +- g_assert (newc == NULL); +- g_assert (error != NULL); +- g_clear_error (&error); +- } else if (after == NULL) { ++ if (after == NULL) { + /* No change to /etc/hosts required */ + #if DEBUG + if (newc != NULL) { +@@ -68,10 +44,8 @@ test_generic (const char *before, + } + #endif + g_assert (newc == NULL); +- g_assert (error == NULL); + } else { + g_assert (newc != NULL); +- g_assert (error == NULL); + + #if DEBUG + g_message ("\n- NEW ---------------------------------\n" +@@ -81,7 +55,6 @@ test_generic (const char *before, + "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + newc->str, after); + #endif +- g_assert (strlen (newc->str) == strlen (after)); + g_assert (strcmp (newc->str, after) == 0); + g_string_free (newc, TRUE); + } +@@ -99,7 +72,7 @@ static const char *generic_before = \ + static void + test_hosts_generic (void) + { +- test_generic (generic_before, NULL, "localhost.localdomain", NULL, NULL, FALSE); ++ test_generic (generic_before, NULL); + } + + /*******************************************/ +@@ -112,311 +85,25 @@ static const char *generic_no_boilerplate_before = \ + static void + test_hosts_generic_no_boilerplate (void) + { +- test_generic (generic_no_boilerplate_before, NULL, "localhost.localdomain", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *generic_no_boilerplate_no_lh_before = \ +- "127.0.0.1 localhost.localdomain\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *generic_no_boilerplate_no_lh_after = \ +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_generic_no_boilerplate_no_lh (void) +-{ +- test_generic (generic_no_boilerplate_no_lh_before, +- generic_no_boilerplate_no_lh_after, +- "localhost.localdomain", +- NULL, +- NULL, +- FALSE); +-} +- +-/*******************************************/ +- +- +-static const char *generic_no_boilerplate_no_lh_no_host_before = \ +- "127.0.0.1 localhost.localdomain\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *generic_no_boilerplate_no_lh_no_host_after = \ +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_generic_no_boilerplate_no_lh_no_host (void) +-{ +- test_generic (generic_no_boilerplate_no_lh_no_host_before, +- generic_no_boilerplate_no_lh_no_host_after, +- "comet", +- NULL, +- NULL, +- FALSE); +-} +- +-/*******************************************/ +-static const char *named_generic_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 playboy localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *named_generic_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 playboy localhost.localdomain localhost\n" +- "::1 playboy localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named_generic (void) +-{ +- test_generic (named_generic_before, named_generic_after, "playboy", NULL, NULL, FALSE); ++ test_generic (generic_no_boilerplate_before, NULL); + } + + /*******************************************/ + +-static const char *named4_non127_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 tomcat localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "192.168.1.2 tomcat\n"; +- +-static void +-test_hosts_named4_non127 (void) +-{ +- test_generic (named4_non127_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *named6_non127_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 tomcat localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "3001:abba::3234 tomcat\n"; +- +-static void +-test_hosts_named6_non127 (void) +-{ +- test_generic (named6_non127_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named4_non127_more_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 tomcat localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "192.168.1.2 tomcat\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 srx.main.ebayrtm.com\n" +- "127.0.0.1 cdn5.tribalfusion.com\n"; +- +-static void +-test_hosts_named4_non127_more (void) +-{ +- test_generic (named4_non127_more_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *named6_non127_more_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 tomcat localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "3001:abba::3234 tomcat\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 srx.main.ebayrtm.com\n" +- "127.0.0.1 cdn5.tribalfusion.com\n"; +- +-static void +-test_hosts_named6_non127_more (void) +-{ +- test_generic (named6_non127_more_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named_no_lh_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "192.168.1.2 tomcat\n"; +- +-static const char *named_no_lh_after = \ ++static const char *leftover_before = \ + "# Do not remove the following line, or various programs\n" + "# that require network functionality will fail.\n" ++ "192.168.1.2 comet # Added by NetworkManager\n" + "127.0.0.1 localhost.localdomain localhost\n" +- "::1 tomcat localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "192.168.1.2 tomcat\n"; +- +-static void +-test_hosts_named_no_localhost (void) +-{ +- test_generic (named_no_lh_before, named_no_lh_after, "tomcat", "192.168.1.2", NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *no_lh_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 tomcat\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *no_lh_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 tomcat localhost.localdomain localhost\n" +- "::1 tomcat localhost6.localdomain6 localhost6\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_no_localhost (void) +-{ +- test_generic (no_lh_before, no_lh_after, "tomcat", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *named_last_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 sparcbook.ausil.us\n" +- "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 sparcbook.ausil.us\n"; +- +-static void +-test_hosts_named_last (void) +-{ +- test_generic (named_last_before, NULL, "sparcbook.ausil.us", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *no_host4_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 srx.main.ebayrtm.com\n" +- "127.0.0.1 cdn5.tribalfusion.com\n" +- "127.0.0.1 a.tribalfusion.com\n"; +- +-static const char *no_host4_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 srx.main.ebayrtm.com\n" +- "127.0.0.1 cdn5.tribalfusion.com\n" +- "127.0.0.1 a.tribalfusion.com\n"; +- +-static void +-test_hosts_no_host4 (void) +-{ +- test_generic (no_host4_before, no_host4_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *no_host6_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *no_host6_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_no_host6 (void) +-{ +- test_generic (no_host6_before, no_host6_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet\n" +- "3001:abba::3234 comet\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127 (void) +-{ +- test_generic (named46_non127_before, NULL, "comet", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_long_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet.space comet\n" +- "3001:abba::3234 comet.space comet\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127_long (void) +-{ +- test_generic (named46_non127_long_before, NULL, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_other4_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" + "::1 localhost6.localdomain6 localhost6\n" + "192.168.1.3 comet\n" + "3001:abba::3234 comet\n" + "\n" + "127.0.0.1 lcmd.us.intellitxt.com\n"; + +-static const char *named46_non127_other4_after = \ ++static const char *leftover_after = \ + "# Do not remove the following line, or various programs\n" + "# that require network functionality will fail.\n" +- "192.168.1.2 comet # Added by NetworkManager\n" + "127.0.0.1 localhost.localdomain localhost\n" + "::1 localhost6.localdomain6 localhost6\n" + "192.168.1.3 comet\n" +@@ -425,416 +112,44 @@ static const char *named46_non127_other4_after = \ + "127.0.0.1 lcmd.us.intellitxt.com\n"; + + static void +-test_hosts_named46_non127_other4 (void) ++test_hosts_leftover (void) + { +- test_generic (named46_non127_other4_before, named46_non127_other4_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE); ++ test_generic (leftover_before, leftover_after); + } + + /*******************************************/ + +-static const char *named46_non127_other4_long_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.3 comet.space\n" +- "3001:abba::3234 comet.space\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *named46_non127_other4_long_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "192.168.1.2 comet.space comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.3 comet.space\n" +- "3001:abba::3234 comet.space\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127_other4_long (void) +-{ +- test_generic (named46_non127_other4_long_before, named46_non127_other4_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_other6_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet\n" +- "3001:abba::9675 comet\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *named46_non127_other6_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "3001:abba::3234 comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet\n" +- "3001:abba::9675 comet\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127_other6 (void) +-{ +- test_generic (named46_non127_other6_before, named46_non127_other6_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_other6_long_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet.space\n" +- "3001:abba::9675 comet.space\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *named46_non127_other6_long_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "3001:abba::3234 comet.space comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.2 comet.space\n" +- "3001:abba::9675 comet.space\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127_other6_long (void) +-{ +- test_generic (named46_non127_other6_long_before, named46_non127_other6_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *unnamed46_non127_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *unnamed46_non127_after = \ ++static const char *leftover_double_newline_before = \ + "# Do not remove the following line, or various programs\n" + "# that require network functionality will fail.\n" + "192.168.1.2 comet # Added by NetworkManager\n" +- "3001:abba::3234 comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_unnamed46_non127 (void) +-{ +- test_generic (unnamed46_non127_before, unnamed46_non127_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *unnamed46_non127_long_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static const char *unnamed46_non127_long_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "192.168.1.2 comet.space comet # Added by NetworkManager\n" +- "3001:abba::3234 comet.space comet # Added by NetworkManager\n" + "127.0.0.1 localhost.localdomain localhost\n" + "::1 localhost6.localdomain6 localhost6\n" ++ "192.168.1.3 comet\n" ++ "3001:abba::3234 comet\n" + "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_unnamed46_non127_long (void) +-{ +- test_generic (unnamed46_non127_long_before, unnamed46_non127_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *named46_non127_wrong_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "192.168.1.3 comet # Added by NetworkManager\n" +- "3001:abba::9876 comet # Added by NetworkManager\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; ++ "127.0.0.1 lcmd.us.intellitxt.com\n" ++ "\n"; + +-static const char *named46_non127_wrong_after = \ ++static const char *leftover_double_newline_after = \ + "# Do not remove the following line, or various programs\n" + "# that require network functionality will fail.\n" +- "192.168.1.2 comet # Added by NetworkManager\n" +- "3001:abba::3234 comet # Added by NetworkManager\n" + "127.0.0.1 localhost.localdomain localhost\n" + "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n"; +- +-static void +-test_hosts_named46_non127_wrong (void) +-{ +- test_generic (named46_non127_wrong_before, named46_non127_wrong_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE); +-} +- +-/*******************************************/ +- +-static const char *long_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost comet\n" +- "::1 localhost6.localdomain6 localhost6\n" +- "\n" +- "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 adserver.adtech.de\n" +- "127.0.0.1 a.as-us.falkag.net\n" +- "127.0.0.1 a.as-eu.falkag.net\n" +- "127.0.0.1 ads.doubleclick.com\n" +- "\n" +- "# random comment\n" +- "127.0.0.1 m1.2mdn.net\n" +- "127.0.0.1 ds.serving-sys.com\n" +- "127.0.0.1 pagead2.googlesyndication.com\n" +- "127.0.0.1 ad.doubleclick.com\n" +- "127.0.0.1 ad.doubleclick.net\n" +- "127.0.0.1 oascentral.movietickets.com\n" +- "127.0.0.1 view.atdmt.com\n" +- "127.0.0.1 ads.chumcity.com\n"; +- +-static const char *long_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n" ++ "192.168.1.3 comet\n" ++ "3001:abba::3234 comet\n" + "\n" + "127.0.0.1 lcmd.us.intellitxt.com\n" +- "127.0.0.1 adserver.adtech.de\n" +- "127.0.0.1 a.as-us.falkag.net\n" +- "127.0.0.1 a.as-eu.falkag.net\n" +- "127.0.0.1 ads.doubleclick.com\n" +- "\n" +- "# random comment\n" +- "127.0.0.1 m1.2mdn.net\n" +- "127.0.0.1 ds.serving-sys.com\n" +- "127.0.0.1 pagead2.googlesyndication.com\n" +- "127.0.0.1 ad.doubleclick.com\n" +- "127.0.0.1 ad.doubleclick.net\n" +- "127.0.0.1 oascentral.movietickets.com\n" +- "127.0.0.1 view.atdmt.com\n" +- "127.0.0.1 ads.chumcity.com\n"; +- +-static void +-test_hosts_long (void) +-{ +- test_generic (long_before, long_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *custom4_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost pintglass\n" +- "::1 localhost6.localdomain6 localhost6\n"; +- +-static const char *custom4_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost pintglass\n" +- "::1 comet localhost6.localdomain6 localhost6\n"; +- +-static void +-test_hosts_custom4 (void) +-{ +- test_generic (custom4_before, custom4_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *custom6_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6 pintglass\n"; +- +-static const char *custom6_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6 pintglass\n"; +- +-static void +-test_hosts_custom6 (void) +-{ +- test_generic (custom6_before, custom6_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *custom46_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost shotglass\n" +- "::1 localhost6.localdomain6 localhost6 pintglass\n"; +- +-static const char *custom46_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost shotglass\n" +- "::1 comet localhost6.localdomain6 localhost6 pintglass\n"; +- +-static void +-test_hosts_custom46 (void) +-{ +- test_generic (custom46_before, custom46_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *custom46_mixed_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 localhost.localdomain localhost shotglass\n" +- "::1 localhost6.localdomain6 localhost6 pintglass\n"; +- +-static const char *custom46_mixed_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost shotglass\n" +- "::1 comet localhost6.localdomain6 localhost6 pintglass\n"; +- +-static void +-test_hosts_custom46_mixed (void) +-{ +- test_generic (custom46_mixed_before, custom46_mixed_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *stale4_removed_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "1.2.3.4 comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n"; +- +-static const char *stale4_removed_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n"; ++ "\n"; + + static void +-test_hosts_stale4_removed (void) ++test_hosts_leftover_double_newline (void) + { +- test_generic (stale4_removed_before, stale4_removed_after, "comet", NULL, NULL, FALSE); ++ test_generic (leftover_double_newline_before, leftover_double_newline_after); + } + + /*******************************************/ + +-static const char *stale6_removed_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "3001:abba::3234 comet # Added by NetworkManager\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n"; +- +-static const char *stale6_removed_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n"; +- +-static void +-test_hosts_stale6_removed (void) +-{ +- test_generic (stale6_removed_before, stale6_removed_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-static const char *stale46_removed_before = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "1.2.3.4 comet # Added by NetworkManager\n" +- "3001:abba::3234 comet # Added by NetworkManager\n" +- "127.0.0.1 localhost.localdomain localhost\n" +- "::1 localhost6.localdomain6 localhost6\n"; +- +-static const char *stale46_removed_after = \ +- "# Do not remove the following line, or various programs\n" +- "# that require network functionality will fail.\n" +- "127.0.0.1 comet localhost.localdomain localhost\n" +- "::1 comet localhost6.localdomain6 localhost6\n"; +- +-static void +-test_hosts_stale46_removed (void) +-{ +- test_generic (stale46_removed_before, stale46_removed_after, "comet", NULL, NULL, FALSE); +-} +- +-/*******************************************/ +- +-typedef struct { +- const char *line; +- const char *token; +- gboolean expected; +-} Foo; +- +-static Foo foo[] = { +- /* Using \t here to easily differentiate tabs vs. spaces for testing */ +- { "127.0.0.1\tfoobar\tblah", "blah", TRUE }, +- { "", "blah", FALSE }, +- { "1.1.1.1\tbork\tfoo", "blah", FALSE }, +- { "127.0.0.1 foobar\tblah", "blah", TRUE }, +- { "127.0.0.1 foobar blah", "blah", TRUE }, +- { "127.0.0.1 localhost", "localhost.localdomain", FALSE }, +- { "192.168.1.1 blah borkbork", "blah", TRUE }, +- { "192.168.1.1 foobar\tblah borkbork", "blah", TRUE }, +- { "192.168.1.1\tfoobar\tblah\tborkbork", "blah", TRUE }, +- { "192.168.1.1 \tfoobar \tblah \tborkbork\t ", "blah", TRUE }, +- { "\t\t\t\t \t\t\tasdfadf a\t\t\t\t\t \t\t\t\t\t ", "blah", FALSE }, +- { NULL, NULL, FALSE } +-}; +- +-static void +-test_find_token (void) +-{ +- Foo *iter = &foo[0]; +- +- while (iter->line) { +- gboolean found; +- +- found = nm_policy_hosts_find_token (iter->line, iter->token); +- if (found != iter->expected) { +- g_warning ("find-token: unexpected token result %d for '%s' <= '%s' (expected %d)", +- found, iter->line, iter->token, iter->expected); +- } +- g_assert (found == iter->expected); +- iter++; +- } +-} +- + #if GLIB_CHECK_VERSION(2,25,12) + typedef GTestFixtureFunc TCFunc; + #else +@@ -851,38 +166,10 @@ int main (int argc, char **argv) + + suite = g_test_get_root (); + +- g_test_suite_add (suite, TESTCASE (test_find_token, NULL)); + g_test_suite_add (suite, TESTCASE (test_hosts_generic, NULL)); + g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh_no_host, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named_generic, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127_more, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127_more, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_long, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4_long, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6_long, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_wrong, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127_long, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named_no_localhost, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_no_localhost, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_named_last, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_no_host4, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_no_host6, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_long, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_custom4, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_custom6, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_custom46, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_custom46_mixed, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_stale4_removed, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_stale6_removed, NULL)); +- g_test_suite_add (suite, TESTCASE (test_hosts_stale46_removed, NULL)); ++ g_test_suite_add (suite, TESTCASE (test_hosts_leftover, NULL)); ++ g_test_suite_add (suite, TESTCASE (test_hosts_leftover_double_newline, NULL)); + + return g_test_run (); + } +-- +1.7.3.4 + diff --git a/network/NetworkManager/patches/wired-fix-uninitialized-variable.patch b/network/NetworkManager/patches/wired-fix-uninitialized-variable.patch new file mode 100644 index 0000000000000..44499939e94f6 --- /dev/null +++ b/network/NetworkManager/patches/wired-fix-uninitialized-variable.patch @@ -0,0 +1,25 @@ +From 2236c1f318bcbdd50820296136a25bade5fcef9e Mon Sep 17 00:00:00 2001 +From: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com> +Date: Fri, 19 Nov 2010 16:17:40 -0600 +Subject: [PATCH 2/4] wired: fix uninitialized variable + +--- + src/nm-device-ethernet.c | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c +index 08bbc50..251a54c 100644 +--- a/src/nm-device-ethernet.c ++++ b/src/nm-device-ethernet.c +@@ -308,7 +308,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) + const char *iface; + GUdevClient *client; + GUdevDevice *dev; +- GUdevDevice *parent; ++ GUdevDevice *parent = NULL; + const char *parent_path, *item, *driver; + const char *subsystems[] = { "net", NULL }; + GDir *dir; +-- +1.7.3.4 + |