summary refs log tree commit diff
path: root/src/dns-manager
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-01-22 00:29:39 +0100
committerMichael Biebl <biebl@debian.org>2015-01-22 00:29:39 +0100
commit2c032d8f1c6292c1338a615e6ec40252889ba85c (patch)
tree1f77182220b2b0264288ba4a476ab47e5bc48716 /src/dns-manager
parent33491bc4279481db8ae47213e34a6d695a0e8830 (diff)
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'src/dns-manager')
-rw-r--r--src/dns-manager/nm-dns-dnsmasq.c33
-rw-r--r--src/dns-manager/nm-dns-dnsmasq.h6
-rw-r--r--src/dns-manager/nm-dns-manager.c74
-rw-r--r--src/dns-manager/nm-dns-manager.h17
-rw-r--r--src/dns-manager/nm-dns-plugin.c43
-rw-r--r--src/dns-manager/nm-dns-plugin.h6
-rw-r--r--src/dns-manager/nm-dns-unbound.c2
-rw-r--r--src/dns-manager/nm-dns-unbound.h6
-rw-r--r--src/dns-manager/nm-dns-utils.c3
-rw-r--r--src/dns-manager/nm-dns-utils.h4
10 files changed, 60 insertions, 134 deletions
diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c
index 8367693d..f26ccfaa 100644
--- a/src/dns-manager/nm-dns-dnsmasq.c
+++ b/src/dns-manager/nm-dns-dnsmasq.c
@@ -18,7 +18,8 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -35,6 +36,7 @@
 #include "nm-ip4-config.h"
 #include "nm-ip6-config.h"
 #include "nm-dns-utils.h"
+#include "NetworkManagerUtils.h"
 
 G_DEFINE_TYPE (NMDnsDnsmasq, nm_dns_dnsmasq, NM_TYPE_DNS_PLUGIN)
 
@@ -50,26 +52,6 @@ typedef struct {
 
 /*******************************************/
 
-static inline const char *
-find_dnsmasq (void)
-{
-	static const char *paths[] = {
-		DNSMASQ_PATH,
-		"/usr/local/sbin/dnsmasq",
-		"/usr/sbin/dnsmasq",
-		"/sbin/dnsmasq",
-		NULL
-	};
-	const char **binary = paths;
-
-	while (*binary != NULL) {
-		if (**binary && g_file_test (*binary, G_FILE_TEST_EXISTS))
-			return *binary;
-		binary++;
-	}
-	return NULL;
-}
-
 static gboolean
 add_ip4_config (GString *str, NMIP4Config *ip4, gboolean split)
 {
@@ -225,6 +207,7 @@ update (NMDnsPlugin *plugin,
         const char *hostname)
 {
 	NMDnsDnsmasq *self = NM_DNS_DNSMASQ (plugin);
+	const char *dm_binary;
 	GString *conf;
 	GSList *iter;
 	const char *argv[15];
@@ -240,6 +223,12 @@ update (NMDnsPlugin *plugin,
 	 */
 	nm_dns_plugin_child_kill (plugin);
 
+	dm_binary = nm_utils_find_helper ("dnsmasq", DNSMASQ_PATH, NULL);
+	if (!dm_binary) {
+		nm_log_warn (LOGD_DNS, "Could not find dnsmasq binary");
+		return FALSE;
+	}
+
 	/* Build up the new dnsmasq config file */
 	conf = g_string_sized_new (150);
 
@@ -281,7 +270,7 @@ update (NMDnsPlugin *plugin,
 	nm_log_dbg (LOGD_DNS, "dnsmasq local caching DNS configuration:");
 	nm_log_dbg (LOGD_DNS, "%s", conf->str);
 
-	argv[idx++] = find_dnsmasq ();
+	argv[idx++] = dm_binary;
 	argv[idx++] = "--no-resolv";  /* Use only commandline */
 	argv[idx++] = "--keep-in-foreground";
 	argv[idx++] = "--no-hosts"; /* don't use /etc/hosts to resolve */
diff --git a/src/dns-manager/nm-dns-dnsmasq.h b/src/dns-manager/nm-dns-dnsmasq.h
index 70933c0f..fc80f079 100644
--- a/src/dns-manager/nm-dns-dnsmasq.h
+++ b/src/dns-manager/nm-dns-dnsmasq.h
@@ -16,8 +16,8 @@
  * Copyright (C) 2010 Red Hat, Inc.
  */
 
-#ifndef NM_DNS_DNSMASQ_H
-#define NM_DNS_DNSMASQ_H
+#ifndef __NETWORKMANAGER_DNS_DNSMASQ_H__
+#define __NETWORKMANAGER_DNS_DNSMASQ_H__
 
 #include <glib.h>
 #include <glib-object.h>
@@ -43,5 +43,5 @@ GType nm_dns_dnsmasq_get_type (void);
 
 NMDnsPlugin *nm_dns_dnsmasq_new (void);
 
-#endif /* NM_DNS_DNSMASQ_H */
+#endif /* __NETWORKMANAGER_DNS_DNSMASQ_H__ */
 
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index 466aa9a8..0d93d8bb 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -35,6 +35,7 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#include "nm-utils.h"
 #include "nm-dns-manager.h"
 #include "nm-ip4-config.h"
 #include "nm-ip6-config.h"
@@ -47,7 +48,7 @@
 #include "nm-dns-dnsmasq.h"
 #include "nm-dns-unbound.h"
 
-#if HAVE_LIBSOUP
+#if WITH_LIBSOUP
 #include <libsoup/soup.h>
 
 #ifdef SOUP_CHECK_VERSION
@@ -130,12 +131,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src)
 
 	num = nm_ip4_config_get_num_nameservers (src);
 	for (i = 0; i < num; i++) {
-		guint32 addr;
-		char buf[INET_ADDRSTRLEN];
-
-		addr = nm_ip4_config_get_nameserver (src, i);
-		if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0)
-			add_string_item (rc->nameservers, buf);
+		add_string_item (rc->nameservers,
+		                 nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (src, i), NULL));
 	}
 
 	num = nm_ip4_config_get_num_domains (src);
@@ -161,12 +158,8 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src)
 	/* NIS stuff */
 	num = nm_ip4_config_get_num_nis_servers (src);
 	for (i = 0; i < num; i++) {
-		guint32 addr;
-		char buf[INET_ADDRSTRLEN];
-
-		addr = nm_ip4_config_get_nis_server (src, i);
-		if (inet_ntop (AF_INET, &addr, buf, INET_ADDRSTRLEN) > 0)
-			add_string_item (rc->nis_servers, buf);
+		add_string_item (rc->nis_servers,
+		                 nm_utils_inet4_ntop (nm_ip4_config_get_nis_server (src, i), NULL));
 	}
 
 	if (nm_ip4_config_get_nis_domain (src)) {
@@ -187,25 +180,21 @@ merge_one_ip6_config (NMResolvConfData *rc, NMIP6Config *src)
 	num = nm_ip6_config_get_num_nameservers (src);
 	for (i = 0; i < num; i++) {
 		const struct in6_addr *addr;
-		char buf[INET6_ADDRSTRLEN];
-		char *tmp;
+		char buf[NM_UTILS_INET_ADDRSTRLEN + 50];
 
 		addr = nm_ip6_config_get_nameserver (src, i);
 
 		/* inet_ntop is probably supposed to do this for us, but it doesn't */
-		if (IN6_IS_ADDR_V4MAPPED (addr)) {
-			if (inet_ntop (AF_INET, &(addr->s6_addr32[3]), buf, INET_ADDRSTRLEN) > 0)
-				add_string_item (rc->nameservers, buf);
-		} else {
-			if (inet_ntop (AF_INET6, addr, buf, INET6_ADDRSTRLEN) > 0) {
-				if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) {
-					tmp = g_strdup_printf ("%s%%%s", buf, iface);
-					add_string_item (rc->nameservers, tmp);
-					g_free (tmp);
-				} else
-					add_string_item (rc->nameservers, buf);
+		if (IN6_IS_ADDR_V4MAPPED (addr))
+			nm_utils_inet4_ntop (addr->s6_addr32[3], buf);
+		else {
+			nm_utils_inet6_ntop (addr, buf);
+			if (iface && IN6_IS_ADDR_LINKLOCAL (addr)) {
+				g_strlcat (buf, "%", sizeof (buf));
+				g_strlcat (buf, iface, sizeof (buf));
 			}
 		}
+		add_string_item (rc->nameservers, buf);
 	}
 
 	num = nm_ip6_config_get_num_domains (src);
@@ -359,8 +348,8 @@ write_resolv_conf (FILE *f,
 
 	if (fprintf (f, "%s","# Generated by NetworkManager\n") < 0) {
 		g_set_error (error,
-		             NM_DNS_MANAGER_ERROR,
-		             NM_DNS_MANAGER_ERROR_SYSTEM,
+		             NM_MANAGER_ERROR,
+		             NM_MANAGER_ERROR_FAILED,
 		             "Could not write " _PATH_RESCONF ": %s\n",
 		             g_strerror (errno));
 		return FALSE;
@@ -425,8 +414,8 @@ dispatch_resolvconf (char **searches,
 		nm_log_info (LOGD_DNS, "Writing DNS information to %s", RESOLVCONF_PATH);
 		if ((f = popen (cmd, "w")) == NULL)
 			g_set_error (error,
-			             NM_DNS_MANAGER_ERROR,
-			             NM_DNS_MANAGER_ERROR_SYSTEM,
+			             NM_MANAGER_ERROR,
+			             NM_MANAGER_ERROR_FAILED,
 			             "Could not write to %s: %s\n",
 			             RESOLVCONF_PATH,
 			             g_strerror (errno));
@@ -481,8 +470,8 @@ update_resolv_conf (char **searches,
 		old_errno = errno;
 		if ((f = fopen (_PATH_RESCONF, "w")) == NULL) {
 			g_set_error (error,
-			             NM_DNS_MANAGER_ERROR,
-			             NM_DNS_MANAGER_ERROR_SYSTEM,
+			             NM_MANAGER_ERROR,
+			             NM_MANAGER_ERROR_FAILED,
 			             "Could not open %s: %s\nCould not open %s: %s\n",
 			             tmp_resolv_conf_realpath,
 			             g_strerror (old_errno),
@@ -504,8 +493,8 @@ update_resolv_conf (char **searches,
 			 * since its error is more important.
 			 */
 			g_set_error (error,
-			             NM_DNS_MANAGER_ERROR,
-			             NM_DNS_MANAGER_ERROR_SYSTEM,
+			             NM_MANAGER_ERROR,
+			             NM_MANAGER_ERROR_FAILED,
 			             "Could not close %s: %s\n",
 			             tmp_resolv_conf_realpath,
 			             g_strerror (errno));
@@ -518,8 +507,8 @@ update_resolv_conf (char **searches,
 	if (*error == NULL && do_rename) {
 		if (rename (tmp_resolv_conf_realpath, resolv_conf_realpath) < 0) {
 			g_set_error (error,
-			             NM_DNS_MANAGER_ERROR,
-			             NM_DNS_MANAGER_ERROR_SYSTEM,
+			             NM_MANAGER_ERROR,
+			             NM_MANAGER_ERROR_FAILED,
 			             "Could not replace " _PATH_RESCONF ": %s\n",
 			             g_strerror (errno));
 		}
@@ -972,8 +961,7 @@ nm_dns_manager_set_hostname (NMDnsManager *mgr,
 
 	/* Certain hostnames we don't want to include in resolv.conf 'searches' */
 	if (   hostname
-	    && strcmp (hostname, "localhost.localdomain")
-	    && strcmp (hostname, "localhost6.localdomain6")
+	    && nm_utils_is_specific_hostname (hostname)
 	    && !strstr (hostname, ".in-addr.arpa")
 	    && strchr (hostname, '.')) {
 		filtered = hostname;
@@ -1067,16 +1055,6 @@ nm_dns_manager_get (void)
 	return singleton;
 }
 
-GQuark
-nm_dns_manager_error_quark (void)
-{
-	static GQuark quark = 0;
-	if (!quark)
-		quark = g_quark_from_static_string ("nm_dns_manager_error");
-
-	return quark;
-}
-
 static void
 init_resolv_conf_mode (NMDnsManager *self)
 {
diff --git a/src/dns-manager/nm-dns-manager.h b/src/dns-manager/nm-dns-manager.h
index b2bf2467..bc374fcf 100644
--- a/src/dns-manager/nm-dns-manager.h
+++ b/src/dns-manager/nm-dns-manager.h
@@ -21,30 +21,19 @@
  *   and others
  */
 
-#ifndef NM_DNS_MANAGER_H
-#define NM_DNS_MANAGER_H
+#ifndef __NETWORKMANAGER_DNS_MANAGER_H__
+#define __NETWORKMANAGER_DNS_MANAGER_H__
 
 #include <glib-object.h>
-#include <dbus/dbus.h>
 #include "nm-ip4-config.h"
 #include "nm-ip6-config.h"
 
 typedef enum {
-	NM_DNS_MANAGER_ERROR_SYSTEM,
-	NM_DNS_MANAGER_ERROR_INVALID_NAMESERVER,
-	NM_DNS_MANAGER_ERROR_INVALID_HOST,
-	NM_DNS_MANAGER_ERROR_INVALID_ID
-} NMDnsManagerError;
-
-typedef enum {
 	NM_DNS_IP_CONFIG_TYPE_DEFAULT = 0,
 	NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE,
 	NM_DNS_IP_CONFIG_TYPE_VPN
 } NMDnsIPConfigType;
 
-#define NM_DNS_MANAGER_ERROR nm_dns_manager_error_quark ()
-GQuark nm_dns_manager_error_quark (void);
-
 G_BEGIN_DECLS
 
 #define NM_TYPE_DNS_MANAGER (nm_dns_manager_get_type ())
@@ -114,4 +103,4 @@ NMDnsManagerResolvConfMode nm_dns_manager_get_resolv_conf_mode (NMDnsManager *mg
 
 G_END_DECLS
 
-#endif /* NM_DNS_MANAGER_H */
+#endif /* __NETWORKMANAGER_DNS_MANAGER_H__ */
diff --git a/src/dns-manager/nm-dns-plugin.c b/src/dns-manager/nm-dns-plugin.c
index e85b2a09..b083b105 100644
--- a/src/dns-manager/nm-dns-plugin.c
+++ b/src/dns-manager/nm-dns-plugin.c
@@ -17,7 +17,8 @@
  *
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -28,6 +29,7 @@
 #include "nm-dns-plugin.h"
 #include "nm-logging.h"
 #include "nm-posix-signals.h"
+#include "NetworkManagerUtils.h"
 
 typedef struct {
 	gboolean disposed;
@@ -196,29 +198,6 @@ nm_dns_plugin_child_spawn (NMDnsPlugin *self,
 	return priv->pid;
 }
 
-typedef struct {
-	int pid;
-	char *progname;
-} KillInfo;
-
-static gboolean
-ensure_killed (gpointer data)
-{
-	KillInfo *info = data;
-
-	if (kill (info->pid, 0) == 0)
-		kill (info->pid, SIGKILL);
-
-	/* ensure the child is reaped */
-	nm_log_dbg (LOGD_DNS, "waiting for %s pid %d to exit", info->progname, info->pid);
-	waitpid (info->pid, NULL, 0);
-	nm_log_dbg (LOGD_DNS, "dnsmasq pid %d cleaned up", info->pid);
-
-	g_free (info->progname);
-	g_free (info);
-	return FALSE;
-}
-
 gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self)
 {
 	NMDnsPluginPrivate *priv = NM_DNS_PLUGIN_GET_PRIVATE (self);
@@ -229,21 +208,7 @@ gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self)
 	}
 
 	if (priv->pid) {
-		KillInfo *info;
-
-		if (kill (priv->pid, SIGTERM) == 0) {
-			info = g_malloc0 (sizeof (KillInfo));
-			info->pid = priv->pid;
-			info->progname = g_strdup (priv->progname);
-			g_timeout_add_seconds (2, ensure_killed, info);
-		} else {
-			kill (priv->pid, SIGKILL);
-
-			/* ensure the child is reaped */
-			nm_log_dbg (LOGD_DNS, "waiting for %s pid %d to exit", priv->progname, priv->pid);
-			waitpid (priv->pid, NULL, 0);
-			nm_log_dbg (LOGD_DNS, "%s pid %d cleaned up", priv->progname, priv->pid);
-		}
+		nm_utils_kill_child_async (priv->pid, SIGTERM, LOGD_DNS, priv->progname, 2000, NULL, NULL);
 		priv->pid = 0;
 		g_free (priv->progname);
 		priv->progname = NULL;
diff --git a/src/dns-manager/nm-dns-plugin.h b/src/dns-manager/nm-dns-plugin.h
index 41a12a58..ee735a5a 100644
--- a/src/dns-manager/nm-dns-plugin.h
+++ b/src/dns-manager/nm-dns-plugin.h
@@ -16,8 +16,8 @@
  * Copyright (C) 2010 Red Hat, Inc.
  */
 
-#ifndef NM_DNS_PLUGIN_H
-#define NM_DNS_PLUGIN_H
+#ifndef __NETWORKMANAGER_DNS_PLUGIN_H__
+#define __NETWORKMANAGER_DNS_PLUGIN_H__
 
 #include <glib.h>
 #include <glib-object.h>
@@ -109,5 +109,5 @@ GPid nm_dns_plugin_child_spawn (NMDnsPlugin *self,
 
 gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self);
 
-#endif /* NM_DNS_PLUGIN_H */
+#endif /* __NETWORKMANAGER_DNS_PLUGIN_H__ */
 
diff --git a/src/dns-manager/nm-dns-unbound.c b/src/dns-manager/nm-dns-unbound.c
index 137fd20b..533290c1 100644
--- a/src/dns-manager/nm-dns-unbound.c
+++ b/src/dns-manager/nm-dns-unbound.c
@@ -17,6 +17,8 @@
  * Copyright (C) 2014 Red Hat, Inc.
  * Author: Pavel Šimerda <psimerda@redhat.com>
  */
+#include "config.h"
+
 #include "nm-dns-unbound.h"
 #include "NetworkManagerUtils.h"
 
diff --git a/src/dns-manager/nm-dns-unbound.h b/src/dns-manager/nm-dns-unbound.h
index 2aaae7dd..261326b2 100644
--- a/src/dns-manager/nm-dns-unbound.h
+++ b/src/dns-manager/nm-dns-unbound.h
@@ -15,8 +15,8 @@
  *
  * Copyright (C) 2014 Red Hat, Inc.
  */
-#ifndef NM_DNS_UNBOUND_H
-#define NM_DNS_UNBOUND_H
+#ifndef __NETWORKMANAGER_DNS_UNBOUND_H__
+#define __NETWORKMANAGER_DNS_UNBOUND_H__
 
 #include <glib-object.h>
 
@@ -41,4 +41,4 @@ GType nm_dns_unbound_get_type (void);
 
 NMDnsPlugin *nm_dns_unbound_new (void);
 
-#endif /* NM_DNS_UNBOUND_H */
+#endif /* __NETWORKMANAGER_DNS_UNBOUND_H__ */
diff --git a/src/dns-manager/nm-dns-utils.c b/src/dns-manager/nm-dns-utils.c
index 3e564ace..4a5255a4 100644
--- a/src/dns-manager/nm-dns-utils.c
+++ b/src/dns-manager/nm-dns-utils.c
@@ -17,10 +17,13 @@
  *
  */
 
+#include "config.h"
+
 #include <arpa/inet.h>
 #include <string.h>
 
 #include "nm-dns-utils.h"
+#include "nm-platform.h"
 #include "nm-utils.h"
 
 static void
diff --git a/src/dns-manager/nm-dns-utils.h b/src/dns-manager/nm-dns-utils.h
index daa6711c..75c6b060 100644
--- a/src/dns-manager/nm-dns-utils.h
+++ b/src/dns-manager/nm-dns-utils.h
@@ -17,8 +17,8 @@
  *
  */
 
-#ifndef NM_DNS_UTILS_H
-#define NM_DNS_UTILS_H
+#ifndef __NETWORKMANAGER_DNS_UTILS_H__
+#define __NETWORKMANAGER_DNS_UTILS_H__
 
 #include "nm-ip4-config.h"