diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /src/dns-manager/nm-dns-manager.c | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'src/dns-manager/nm-dns-manager.c')
| -rw-r--r-- | src/dns-manager/nm-dns-manager.c | 74 |
1 files changed, 26 insertions, 48 deletions
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) { |