diff --git a/.gitignore b/.gitignore index f9401dabca..3678dc36e1 100644 --- a/.gitignore +++ b/.gitignore @@ -184,7 +184,6 @@ valgrind-*.log /src/tests/test-general /src/tests/test-ip4-config /src/tests/test-ip6-config -/src/tests/test-policy-hosts /src/tests/test-wifi-ap-utils /src/tests/test-resolvconf-capture /src/dnsmasq-manager/tests/test-dnsmasq-utils diff --git a/src/Makefile.am b/src/Makefile.am index f75f84df6c..b34c1939c9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -232,8 +232,6 @@ nm_sources = \ nm-auth-subject.h \ nm-manager.c \ nm-manager.h \ - nm-policy-hosts.c \ - nm-policy-hosts.h \ nm-policy.c \ nm-policy.h \ nm-properties-changed-signal.c \ diff --git a/src/main.c b/src/main.c index 15ac6a9e33..5f386cef28 100644 --- a/src/main.c +++ b/src/main.c @@ -52,7 +52,6 @@ #include "nm-hostname-provider.h" #include "nm-vpn-manager.h" #include "nm-logging.h" -#include "nm-policy-hosts.h" #include "nm-config.h" #include "nm-posix-signals.h" #include "nm-session-monitor.h" @@ -651,9 +650,6 @@ main (int argc, char *argv[]) } } - /* Clean leftover "# Added by NetworkManager" entries from /etc/hosts */ - nm_policy_hosts_clean_etc_hosts (); - nm_manager_start (manager); /* Make sure the loopback interface is up. If interface is down, we bring diff --git a/src/nm-policy-hosts.c b/src/nm-policy-hosts.c deleted file mode 100644 index 3f3fb35c07..0000000000 --- a/src/nm-policy-hosts.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * 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 of the License, 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) 2004 - 2010 Red Hat, Inc. - */ - -#include -#include - -#include "nm-policy-hosts.h" -#include "nm-logging.h" - -#define ADDED_TAG "# Added by NetworkManager" - -GString * -nm_policy_get_etc_hosts (const char *contents, gsize contents_len) -{ - char **lines = NULL, **iter; - GString *new_contents = NULL; - - if (contents_len == 0 || !strstr (contents, ADDED_TAG)) - return NULL; - - new_contents = g_string_sized_new (contents_len); - - /* 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'); - } - } - g_strfreev (lines); - - /* Remove last blank line at end of file, if one exists; this is - * an artifact of how g_strsplit_set() works. - */ - if ( (new_contents->len > 2) - && (new_contents->str[new_contents->len - 1] == '\n')) - g_string_truncate (new_contents, new_contents->len - 1); - - return new_contents; -} - -/* remove any leftover "# Added by NetworkManager" lines */ -void -nm_policy_hosts_clean_etc_hosts (void) -{ - char *contents = NULL; - gsize contents_len = 0; - GError *error = NULL; - GString *new; - - if (!g_file_get_contents (SYSCONFDIR "/hosts", &contents, &contents_len, &error)) { - nm_log_dbg (LOGD_DNS, "couldn't read " SYSCONFDIR "/hosts: (%d) %s", - error ? error->code : 0, - (error && error->message) ? error->message : "(unknown)"); - g_clear_error (&error); - return; - } - - new = nm_policy_get_etc_hosts (contents, contents_len); - g_free (contents); - - if (new && new->len) { - nm_log_dbg (LOGD_DNS, "Cleaning leftovers from /etc/hosts"); - - g_clear_error (&error); - 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); - } - } - - if (new) - g_string_free (new, TRUE); -} - diff --git a/src/nm-policy-hosts.h b/src/nm-policy-hosts.h deleted file mode 100644 index 9f4bf9a9a9..0000000000 --- a/src/nm-policy-hosts.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * 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 of the License, 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) 2004 - 2010 Red Hat, Inc. - */ - -#ifndef NM_POLICY_HOSTS_H -#define NM_POLICT_HOSTS_H - -#include - -void nm_policy_hosts_clean_etc_hosts (void); - -/* Only for testcases; don't use outside of nm-policy-hosts.c */ -GString *nm_policy_get_etc_hosts (const char *contents, gsize contents_len); - -#endif /* NM_POLICY_HOSTS_H */ - diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index b35eb515ad..e23ad68761 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -16,7 +16,6 @@ AM_CPPFLAGS = \ noinst_PROGRAMS = \ test-dhcp-options \ test-general \ - test-policy-hosts \ test-wifi-ap-utils \ test-ip4-config \ test-ip6-config \ @@ -36,14 +35,6 @@ test_dhcp_options_CPPFLAGS = \ test_dhcp_options_LDADD = \ $(top_builddir)/src/libNetworkManager.la -####### policy /etc/hosts test ####### - -test_policy_hosts_SOURCES = \ - test-policy-hosts.c - -test_policy_hosts_LDADD = \ - $(top_builddir)/src/libNetworkManager.la - ####### wifi ap utils test ####### test_wifi_ap_utils_SOURCES = \ @@ -98,5 +89,5 @@ EXTRA_DIST = test-secret-agent.py ########################################### -TESTS = test-dhcp-options test-policy-hosts test-wifi-ap-utils test-ip4-config test-ip6-config test-dcb test-resolvconf-capture test-general +TESTS = test-dhcp-options test-wifi-ap-utils test-ip4-config test-ip6-config test-dcb test-resolvconf-capture test-general diff --git a/src/tests/test-policy-hosts.c b/src/tests/test-policy-hosts.c deleted file mode 100644 index 5fe8869182..0000000000 --- a/src/tests/test-policy-hosts.c +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- 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 -#include - -#include "nm-policy-hosts.h" - -#define DEBUG 0 - -static void -test_generic (const char *before, const char *after) -{ - GString *newc; - - /* Get the new /etc/hosts contents */ - newc = nm_policy_get_etc_hosts (before, strlen (before)); - - if (after == NULL) { - /* No change to /etc/hosts required */ -#if DEBUG - if (newc != NULL) { - g_message ("\n- NEW ---------------------------------\n" - "%s" - "+ EXPECTED NONE +++++++++++++++++++++++++\n", - newc->str); - } -#endif - g_assert (newc == NULL); - } else { - g_assert (newc != NULL); - -#if DEBUG - g_message ("\n- NEW ---------------------------------\n" - "%s" - "+ EXPECTED ++++++++++++++++++++++++++++++\n" - "%s" - "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - newc->str, after); -#endif - g_assert (strcmp (newc->str, after) == 0); - g_string_free (newc, TRUE); - } -} - -/*******************************************/ - -static const char *generic_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" - "127.0.0.1 lcmd.us.intellitxt.com\n"; - -static void -test_hosts_generic (void) -{ - test_generic (generic_before, NULL); -} - -/*******************************************/ - -static const char *generic_no_boilerplate_before = \ - "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 (void) -{ - test_generic (generic_no_boilerplate_before, NULL); -} - -/*******************************************/ - -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 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 *leftover_after = \ - "# 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 void -test_hosts_leftover (void) -{ - test_generic (leftover_before, leftover_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" - "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" - "\n"; - -static const char *leftover_double_newline_after = \ - "# 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" - "\n"; - -static void -test_hosts_leftover_double_newline (void) -{ - test_generic (leftover_double_newline_before, leftover_double_newline_after); -} - -/*******************************************/ - -int -main (int argc, char **argv) -{ - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/hosts/generic", test_hosts_generic); - g_test_add_func ("/hosts/generic_no_boilerplate", test_hosts_generic_no_boilerplate); - g_test_add_func ("/hosts/leftover", test_hosts_leftover); - g_test_add_func ("/hosts/leftover_double_newline", test_hosts_leftover_double_newline); - - return g_test_run (); -} -