2008-08-12 Tambet Ingo <tambet@gmail.com>
* src/backends/*: Get rid of nm_system_should_modify_resolv_conf(). * src/named-manager/nm-named-manager.c (rewrite_resolv_conf): Calculate the composite result of all the IP4 configurations and call a distro specific update_resolv_conf(). (update_resolv_conf): Implement one for directly writing to /etc/resolv.conf and one for opensuse to call netconfig. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3931 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2008-08-12 Tambet Ingo <tambet@gmail.com>
|
||||||
|
|
||||||
|
* src/backends/*: Get rid of nm_system_should_modify_resolv_conf().
|
||||||
|
|
||||||
|
* src/named-manager/nm-named-manager.c (rewrite_resolv_conf): Calculate
|
||||||
|
the composite result of all the IP4 configurations and call a distro
|
||||||
|
specific update_resolv_conf().
|
||||||
|
(update_resolv_conf): Implement one for directly writing to
|
||||||
|
/etc/resolv.conf and one for opensuse to call netconfig.
|
||||||
|
|
||||||
2008-08-11 Dan Williams <dcbw@redhat.com>
|
2008-08-11 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* src/ppp-manager/nm-ppp-manager.c
|
* src/ppp-manager/nm-ppp-manager.c
|
||||||
|
@@ -122,7 +122,6 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update)
|
|||||||
NMActRequest *best_req = NULL;
|
NMActRequest *best_req = NULL;
|
||||||
GSList *devices, *iter;
|
GSList *devices, *iter;
|
||||||
NMNamedManager *named_mgr;
|
NMNamedManager *named_mgr;
|
||||||
NMIP4Config *config;
|
|
||||||
|
|
||||||
devices = nm_manager_get_devices (policy->manager);
|
devices = nm_manager_get_devices (policy->manager);
|
||||||
for (iter = devices; iter; iter = g_slist_next (iter)) {
|
for (iter = devices; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -196,8 +195,10 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update)
|
|||||||
}
|
}
|
||||||
|
|
||||||
named_mgr = nm_named_manager_get ();
|
named_mgr = nm_named_manager_get ();
|
||||||
config = nm_device_get_ip4_config (best);
|
nm_named_manager_add_ip4_config (named_mgr,
|
||||||
nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE);
|
nm_device_get_ip_iface (best),
|
||||||
|
nm_device_get_ip4_config (best),
|
||||||
|
NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE);
|
||||||
g_object_unref (named_mgr);
|
g_object_unref (named_mgr);
|
||||||
|
|
||||||
/* Now set new default active connection _after_ updating DNS info, so that
|
/* Now set new default active connection _after_ updating DNS info, so that
|
||||||
|
@@ -385,7 +385,7 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
named_mgr = nm_named_manager_get ();
|
named_mgr = nm_named_manager_get ();
|
||||||
nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
|
nm_named_manager_add_ip4_config (named_mgr, iface, config, NM_NAMED_IP_CONFIG_TYPE_VPN);
|
||||||
g_object_unref (named_mgr);
|
g_object_unref (named_mgr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -406,7 +406,7 @@ gboolean nm_system_vpn_device_unset_from_ip4_config (NMDevice *active_device, co
|
|||||||
g_return_val_if_fail (config != NULL, FALSE);
|
g_return_val_if_fail (config != NULL, FALSE);
|
||||||
|
|
||||||
named_mgr = nm_named_manager_get ();
|
named_mgr = nm_named_manager_get ();
|
||||||
nm_named_manager_remove_ip4_config (named_mgr, config);
|
nm_named_manager_remove_ip4_config (named_mgr, iface, config);
|
||||||
g_object_unref (named_mgr);
|
g_object_unref (named_mgr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@@ -66,6 +66,4 @@ void nm_system_set_hostname (NMIP4Config *config);
|
|||||||
|
|
||||||
gboolean nm_system_device_set_mtu (const char *iface, guint32 mtu);
|
gboolean nm_system_device_set_mtu (const char *iface, guint32 mtu);
|
||||||
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -78,16 +78,6 @@ void nm_system_update_dns (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_set_hostname
|
* nm_system_set_hostname
|
||||||
*
|
*
|
||||||
|
@@ -73,14 +73,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -71,14 +71,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -238,14 +238,3 @@ NMIP4Config *nm_generic_device_new_ip4_system_config (NMDevice *dev)
|
|||||||
void nm_generic_set_hostname (NMIP4Config *config)
|
void nm_generic_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_generic_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_generic_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -52,6 +52,4 @@ gboolean nm_generic_device_set_up_down_with_iface (NMDevice *dev, const char *
|
|||||||
|
|
||||||
void nm_generic_set_hostname (NMIP4Config *config);
|
void nm_generic_set_hostname (NMIP4Config *config);
|
||||||
|
|
||||||
gboolean nm_generic_should_modify_resolv_conf (void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -80,15 +80,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -74,15 +74,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -73,15 +73,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -72,15 +72,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -69,14 +69,3 @@ void nm_system_update_dns (void)
|
|||||||
void nm_system_set_hostname (NMIP4Config *config)
|
void nm_system_set_hostname (NMIP4Config *config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -131,36 +131,3 @@ out_close:
|
|||||||
out_gfree:
|
out_gfree:
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_system_should_modify_resolv_conf
|
|
||||||
*
|
|
||||||
* Can NM update resolv.conf, or is it locked down?
|
|
||||||
*/
|
|
||||||
gboolean nm_system_should_modify_resolv_conf (void)
|
|
||||||
{
|
|
||||||
char *name, *buf;
|
|
||||||
shvarFile *file;
|
|
||||||
gboolean ret = TRUE;
|
|
||||||
|
|
||||||
name = g_strdup_printf (SYSCONFDIR"/sysconfig/network/dhcp");
|
|
||||||
file = svNewFile (name);
|
|
||||||
if (!file)
|
|
||||||
goto out_gfree;
|
|
||||||
|
|
||||||
buf = svGetValue (file, "DHCLIENT_MODIFY_RESOLV_CONF");
|
|
||||||
if (!buf)
|
|
||||||
goto out_close;
|
|
||||||
|
|
||||||
if (strcmp (buf, "no") == 0)
|
|
||||||
ret = FALSE;
|
|
||||||
|
|
||||||
free (buf);
|
|
||||||
out_close:
|
|
||||||
svCloseFile (file);
|
|
||||||
out_gfree:
|
|
||||||
g_free (name);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2004 - 2008 Red Hat, Inc.
|
* Copyright (C) 2004 - 2008 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
@@ -26,6 +28,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
@@ -85,50 +89,6 @@ nm_named_manager_error_quark (void)
|
|||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
compute_nameservers (NMIP4Config *config)
|
|
||||||
{
|
|
||||||
int i, num;
|
|
||||||
GString *str = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (config != NULL, NULL);
|
|
||||||
|
|
||||||
num = nm_ip4_config_get_num_nameservers (config);
|
|
||||||
if (num == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
str = g_string_new ("");
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
#define ADDR_BUF_LEN 50
|
|
||||||
struct in_addr addr;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
addr.s_addr = nm_ip4_config_get_nameserver (config, i);
|
|
||||||
buf = g_malloc0 (ADDR_BUF_LEN);
|
|
||||||
if (!buf)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN))
|
|
||||||
nm_warning ("%s: error converting IP4 address 0x%X",
|
|
||||||
__func__, ntohl (addr.s_addr));
|
|
||||||
|
|
||||||
if (i == 3) {
|
|
||||||
g_string_append (str, "\n# ");
|
|
||||||
g_string_append (str, _("NOTE: the glibc resolver does not support more than 3 nameservers."));
|
|
||||||
g_string_append (str, "\n# ");
|
|
||||||
g_string_append (str, _("The nameservers listed below may not be recognized."));
|
|
||||||
g_string_append_c (str, '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
g_string_append (str, "nameserver ");
|
|
||||||
g_string_append (str, buf);
|
|
||||||
g_string_append_c (str, '\n');
|
|
||||||
g_free (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_string_free (str, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
merge_one_ip4_config (NMIP4Config *dst, NMIP4Config *src)
|
merge_one_ip4_config (NMIP4Config *dst, NMIP4Config *src)
|
||||||
{
|
{
|
||||||
@@ -155,49 +115,221 @@ merge_one_ip4_config (NMIP4Config *dst, NMIP4Config *src)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
#if defined(TARGET_SUSE)
|
||||||
rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
|
/**********************************/
|
||||||
|
/* SUSE */
|
||||||
|
|
||||||
|
static void
|
||||||
|
netconfig_child_setup (gpointer user_data G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
NMNamedManagerPrivate *priv;
|
pid_t pid = getpid ();
|
||||||
const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
|
setpgid (pid, pid);
|
||||||
char *searches = NULL, *domain = NULL;
|
}
|
||||||
char *nameservers = NULL;
|
|
||||||
guint32 num_domains, num_searches, i;
|
|
||||||
NMIP4Config *composite;
|
|
||||||
GSList *iter;
|
|
||||||
FILE *f;
|
|
||||||
GString *str;
|
|
||||||
|
|
||||||
g_return_val_if_fail (error != NULL, FALSE);
|
static gint
|
||||||
g_return_val_if_fail (*error == NULL, FALSE);
|
run_netconfig (GError **error)
|
||||||
|
{
|
||||||
|
GPtrArray *argv;
|
||||||
|
gint stdin_fd;
|
||||||
|
|
||||||
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
argv = g_ptr_array_new ();
|
||||||
|
g_ptr_array_add (argv, "/sbin/netconfig");
|
||||||
|
g_ptr_array_add (argv, "modify");
|
||||||
|
g_ptr_array_add (argv, "--service");
|
||||||
|
g_ptr_array_add (argv, "NetworkManager");
|
||||||
|
g_ptr_array_add (argv, NULL);
|
||||||
|
|
||||||
/* If the sysadmin disabled modifying resolv.conf, exit silently */
|
if (!g_spawn_async_with_pipes (NULL, (char **) argv->pdata, NULL,
|
||||||
if (!nm_system_should_modify_resolv_conf ()) {
|
G_SPAWN_DO_NOT_REAP_CHILD,
|
||||||
nm_info ("DHCP returned name servers but system has disabled dynamic modification!");
|
netconfig_child_setup,
|
||||||
return TRUE;
|
NULL, NULL, &stdin_fd,
|
||||||
|
NULL, NULL, error)) {
|
||||||
|
stdin_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_ptr_array_free (argv, TRUE);
|
||||||
|
|
||||||
|
return stdin_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
write_to_netconfig (gint fd, const char *key, const char *value)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
str = g_strdup_printf ("%s='%s'\n", key, value);
|
||||||
|
x = write (fd, str, strlen (str));
|
||||||
|
g_free (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
update_resolv_conf (const char *iface,
|
||||||
|
const char *domain,
|
||||||
|
char **searches,
|
||||||
|
char **nameservers,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gint fd;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
fd = run_netconfig (error);
|
||||||
|
if (fd < 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
write_to_netconfig (fd, "INTERFACE", iface);
|
||||||
|
|
||||||
|
if (searches) {
|
||||||
|
str = g_strjoinv (" ", searches);
|
||||||
|
write_to_netconfig (fd, "DNSDOMAIN", str);
|
||||||
|
g_free (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameservers) {
|
||||||
|
str = g_strjoinv (" ", nameservers);
|
||||||
|
write_to_netconfig (fd, "DNSSERVERS", str);
|
||||||
|
g_free (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
close (fd);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**********************************/
|
||||||
|
/* Generic */
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
update_resolv_conf (const char *iface,
|
||||||
|
const char *domain,
|
||||||
|
char **searches,
|
||||||
|
char **nameservers,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
const char *tmp_resolv_conf = RESOLV_CONF ".tmp";
|
||||||
|
char *domain_str = NULL;
|
||||||
|
char *searches_str = NULL;
|
||||||
|
char *nameservers_str = NULL;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen (tmp_resolv_conf, "w")) == NULL) {
|
if ((f = fopen (tmp_resolv_conf, "w")) == NULL) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_NAMED_MANAGER_ERROR,
|
NM_NAMED_MANAGER_ERROR,
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
"Could not open " RESOLV_CONF ": %s\n",
|
"Could not open " RESOLV_CONF ": %s\n",
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fprintf (f, "%s","# generated by NetworkManager, do not edit!\n\n") < 0) {
|
if (fprintf (f, "%s","# generated by NetworkManager, do not edit!\n\n") < 0) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
NM_NAMED_MANAGER_ERROR,
|
NM_NAMED_MANAGER_ERROR,
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
"Could not write " RESOLV_CONF ": %s\n",
|
"Could not write " RESOLV_CONF ": %s\n",
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
fclose (f);
|
fclose (f);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (domain)
|
||||||
|
domain_str = g_strconcat ("domain ", domain, "\n\n", NULL);
|
||||||
|
|
||||||
|
if (searches) {
|
||||||
|
char *tmp_str;
|
||||||
|
|
||||||
|
tmp_str = g_strjoinv (" ", searches);
|
||||||
|
searches_str = g_strconcat ("search ", tmp_str, "\n\n", NULL);
|
||||||
|
g_free (tmp_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameservers) {
|
||||||
|
GString *str;
|
||||||
|
int num;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
str = g_string_new ("");
|
||||||
|
num = g_strv_length (nameservers);
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
if (i == 3) {
|
||||||
|
g_string_append (str, "\n# ");
|
||||||
|
g_string_append (str, _("NOTE: the glibc resolver does not support more than 3 nameservers."));
|
||||||
|
g_string_append (str, "\n# ");
|
||||||
|
g_string_append (str, _("The nameservers listed below may not be recognized."));
|
||||||
|
g_string_append_c (str, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
g_string_append (str, "nameserver ");
|
||||||
|
g_string_append (str, nameservers[i]);
|
||||||
|
g_string_append_c (str, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
nameservers_str = g_string_free (str, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fprintf (f, "%s%s%s\n",
|
||||||
|
domain ? domain : "",
|
||||||
|
searches_str ? searches_str : "",
|
||||||
|
nameservers_str ? nameservers_str : "") < 0) {
|
||||||
|
g_set_error (error,
|
||||||
|
NM_NAMED_MANAGER_ERROR,
|
||||||
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
|
"Could not write to " RESOLV_CONF ": %s\n",
|
||||||
|
g_strerror (errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (domain_str);
|
||||||
|
g_free (searches_str);
|
||||||
|
g_free (nameservers_str);
|
||||||
|
|
||||||
|
if (fclose (f) < 0) {
|
||||||
|
if (*error == NULL) {
|
||||||
|
g_set_error (error,
|
||||||
|
NM_NAMED_MANAGER_ERROR,
|
||||||
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
|
"Could not close " RESOLV_CONF ": %s\n",
|
||||||
|
g_strerror (errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*error == NULL) {
|
||||||
|
if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
|
||||||
|
g_set_error (error,
|
||||||
|
NM_NAMED_MANAGER_ERROR,
|
||||||
|
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
||||||
|
"Could not replace " RESOLV_CONF ": %s\n",
|
||||||
|
g_strerror (errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *error ? FALSE : TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ADDR_BUF_LEN 50
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
rewrite_resolv_conf (NMNamedManager *mgr, const char *iface, GError **error)
|
||||||
|
{
|
||||||
|
NMNamedManagerPrivate *priv;
|
||||||
|
NMIP4Config *composite;
|
||||||
|
GSList *iter;
|
||||||
|
GPtrArray *array;
|
||||||
|
const char *domain = NULL;
|
||||||
|
char **searches = NULL;
|
||||||
|
char **nameservers = NULL;
|
||||||
|
int num_domains;
|
||||||
|
int num_searches;
|
||||||
|
int num_nameservers;
|
||||||
|
int i;
|
||||||
|
gboolean success;
|
||||||
|
|
||||||
|
g_return_val_if_fail (error != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (*error == NULL, FALSE);
|
||||||
|
|
||||||
|
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
||||||
|
|
||||||
/* Construct the composite config from all the currently active IP4Configs */
|
/* Construct the composite config from all the currently active IP4Configs */
|
||||||
composite = nm_ip4_config_new ();
|
composite = nm_ip4_config_new ();
|
||||||
|
|
||||||
@@ -239,79 +371,65 @@ rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
|
|||||||
num_domains = nm_ip4_config_get_num_domains (composite);
|
num_domains = nm_ip4_config_get_num_domains (composite);
|
||||||
num_searches = nm_ip4_config_get_num_searches (composite);
|
num_searches = nm_ip4_config_get_num_searches (composite);
|
||||||
|
|
||||||
|
/* Domain */
|
||||||
|
if (num_domains > 0)
|
||||||
|
domain = nm_ip4_config_get_domain (composite, 0);
|
||||||
|
|
||||||
|
/* Searches */
|
||||||
if ((num_searches == 0) && (num_domains > 0)) {
|
if ((num_searches == 0) && (num_domains > 0)) {
|
||||||
str = g_string_new ("search");
|
array = g_ptr_array_sized_new (num_domains + 1);
|
||||||
for (i = 0; i < num_domains; i++) {
|
for (i = 0; i < num_domains; i++)
|
||||||
g_string_append_c (str, ' ');
|
g_ptr_array_add (array, g_strdup (nm_ip4_config_get_domain (composite, i)));
|
||||||
g_string_append (str, nm_ip4_config_get_domain (composite, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_string_append (str, "\n\n");
|
g_ptr_array_add (array, NULL);
|
||||||
searches = g_string_free (str, FALSE);
|
searches = (char **) g_ptr_array_free (array, FALSE);
|
||||||
} else if (num_searches > 0) {
|
} else if (num_searches > 0) {
|
||||||
str = g_string_new ("search");
|
array = g_ptr_array_sized_new (num_searches + 1);
|
||||||
for (i = 0; i < num_searches; i++) {
|
for (i = 0; i < num_searches; i++)
|
||||||
g_string_append_c (str, ' ');
|
g_ptr_array_add (array, g_strdup (nm_ip4_config_get_search (composite, i)));
|
||||||
g_string_append (str, nm_ip4_config_get_search (composite, i));
|
|
||||||
|
g_ptr_array_add (array, NULL);
|
||||||
|
searches = (char **) g_ptr_array_free (array, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Name servers */
|
||||||
|
num_nameservers = nm_ip4_config_get_num_nameservers (composite);
|
||||||
|
if (num_nameservers > 0) {
|
||||||
|
array = g_ptr_array_sized_new (num_nameservers + 1);
|
||||||
|
for (i = 0; i < num_nameservers; i++) {
|
||||||
|
struct in_addr addr;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
addr.s_addr = nm_ip4_config_get_nameserver (composite, i);
|
||||||
|
buf = g_malloc0 (ADDR_BUF_LEN);
|
||||||
|
if (!buf)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (inet_ntop (AF_INET, &addr, buf, ADDR_BUF_LEN))
|
||||||
|
g_ptr_array_add (array, buf);
|
||||||
|
else
|
||||||
|
nm_warning ("%s: error converting IP4 address 0x%X",
|
||||||
|
__func__, ntohl (addr.s_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_append (str, "\n\n");
|
g_ptr_array_add (array, NULL);
|
||||||
searches = g_string_free (str, FALSE);
|
nameservers = (char **) g_ptr_array_free (array, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute resolv.conf domain */
|
success = update_resolv_conf (iface, domain, searches, nameservers, error);
|
||||||
if (num_domains > 0) {
|
|
||||||
str = g_string_new ("domain ");
|
|
||||||
g_string_append (str, nm_ip4_config_get_domain (composite, 0));
|
|
||||||
g_string_append (str, "\n\n");
|
|
||||||
|
|
||||||
domain = g_string_free (str, FALSE);
|
g_strfreev (searches);
|
||||||
}
|
g_strfreev (nameservers);
|
||||||
|
|
||||||
/* Using glibc resolver */
|
if (success)
|
||||||
nameservers = compute_nameservers (composite);
|
nm_system_update_dns ();
|
||||||
if (fprintf (f, "%s%s%s\n",
|
|
||||||
domain ? domain : "",
|
|
||||||
searches ? searches : "",
|
|
||||||
nameservers ? nameservers : "") < 0) {
|
|
||||||
g_set_error (error,
|
|
||||||
NM_NAMED_MANAGER_ERROR,
|
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
|
||||||
"Could not write to " RESOLV_CONF ": %s\n",
|
|
||||||
g_strerror (errno));
|
|
||||||
}
|
|
||||||
g_free (nameservers);
|
|
||||||
|
|
||||||
if (fclose (f) < 0) {
|
return success;
|
||||||
if (*error == NULL) {
|
|
||||||
g_set_error (error,
|
|
||||||
NM_NAMED_MANAGER_ERROR,
|
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
|
||||||
"Could not close " RESOLV_CONF ": %s\n",
|
|
||||||
g_strerror (errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (domain);
|
|
||||||
g_free (searches);
|
|
||||||
|
|
||||||
if (*error == NULL) {
|
|
||||||
if (rename (tmp_resolv_conf, RESOLV_CONF) < 0) {
|
|
||||||
g_set_error (error,
|
|
||||||
NM_NAMED_MANAGER_ERROR,
|
|
||||||
NM_NAMED_MANAGER_ERROR_SYSTEM,
|
|
||||||
"Could not replace " RESOLV_CONF ": %s\n",
|
|
||||||
g_strerror (errno));
|
|
||||||
} else {
|
|
||||||
nm_system_update_dns ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return *error ? FALSE : TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
||||||
|
const char *iface,
|
||||||
NMIP4Config *config,
|
NMIP4Config *config,
|
||||||
NMNamedIPConfigType cfg_type)
|
NMNamedIPConfigType cfg_type)
|
||||||
{
|
{
|
||||||
@@ -319,6 +437,7 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (mgr != NULL, FALSE);
|
g_return_val_if_fail (mgr != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (iface != NULL, FALSE);
|
||||||
g_return_val_if_fail (config != NULL, FALSE);
|
g_return_val_if_fail (config != NULL, FALSE);
|
||||||
|
|
||||||
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
||||||
@@ -338,7 +457,7 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
|||||||
if (!g_slist_find (priv->configs, config))
|
if (!g_slist_find (priv->configs, config))
|
||||||
priv->configs = g_slist_append (priv->configs, g_object_ref (config));
|
priv->configs = g_slist_append (priv->configs, g_object_ref (config));
|
||||||
|
|
||||||
if (!rewrite_resolv_conf (mgr, &error)) {
|
if (!rewrite_resolv_conf (mgr, iface, &error)) {
|
||||||
nm_warning ("Could not commit DNS changes. Error: '%s'", error ? error->message : "(none)");
|
nm_warning ("Could not commit DNS changes. Error: '%s'", error ? error->message : "(none)");
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
@@ -347,12 +466,15 @@ nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config)
|
nm_named_manager_remove_ip4_config (NMNamedManager *mgr,
|
||||||
|
const char *iface,
|
||||||
|
NMIP4Config *config)
|
||||||
{
|
{
|
||||||
NMNamedManagerPrivate *priv;
|
NMNamedManagerPrivate *priv;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (mgr != NULL, FALSE);
|
g_return_val_if_fail (mgr != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (iface != NULL, FALSE);
|
||||||
g_return_val_if_fail (config != NULL, FALSE);
|
g_return_val_if_fail (config != NULL, FALSE);
|
||||||
|
|
||||||
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
priv = NM_NAMED_MANAGER_GET_PRIVATE (mgr);
|
||||||
@@ -371,7 +493,7 @@ nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config)
|
|||||||
|
|
||||||
g_object_unref (config);
|
g_object_unref (config);
|
||||||
|
|
||||||
if (!rewrite_resolv_conf (mgr, &error)) {
|
if (!rewrite_resolv_conf (mgr, iface, &error)) {
|
||||||
nm_warning ("Could not commit DNS changes. Error: '%s'", error ? error->message : "(none)");
|
nm_warning ("Could not commit DNS changes. Error: '%s'", error ? error->message : "(none)");
|
||||||
if (error)
|
if (error)
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
@@ -68,10 +68,13 @@ GType nm_named_manager_get_type (void);
|
|||||||
NMNamedManager * nm_named_manager_get (void);
|
NMNamedManager * nm_named_manager_get (void);
|
||||||
|
|
||||||
gboolean nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
gboolean nm_named_manager_add_ip4_config (NMNamedManager *mgr,
|
||||||
|
const char *iface,
|
||||||
NMIP4Config *config,
|
NMIP4Config *config,
|
||||||
NMNamedIPConfigType cfg_type);
|
NMNamedIPConfigType cfg_type);
|
||||||
|
|
||||||
gboolean nm_named_manager_remove_ip4_config (NMNamedManager *mgr, NMIP4Config *config);
|
gboolean nm_named_manager_remove_ip4_config (NMNamedManager *mgr,
|
||||||
|
const char *iface,
|
||||||
|
NMIP4Config *config);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@@ -1734,13 +1734,14 @@ nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, NMDeviceStateReas
|
|||||||
g_return_val_if_fail (reason != NULL, FALSE);
|
g_return_val_if_fail (reason != NULL, FALSE);
|
||||||
|
|
||||||
priv = NM_DEVICE_GET_PRIVATE (self);
|
priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
|
ip_iface = nm_device_get_ip_iface (self);
|
||||||
|
|
||||||
if (priv->ip4_config) {
|
if (priv->ip4_config) {
|
||||||
NMNamedManager *named_mgr;
|
NMNamedManager *named_mgr;
|
||||||
|
|
||||||
/* Remove any previous IP4 Config from the named manager */
|
/* Remove any previous IP4 Config from the named manager */
|
||||||
named_mgr = nm_named_manager_get ();
|
named_mgr = nm_named_manager_get ();
|
||||||
nm_named_manager_remove_ip4_config (named_mgr, priv->ip4_config);
|
nm_named_manager_remove_ip4_config (named_mgr, ip_iface, priv->ip4_config);
|
||||||
g_object_unref (named_mgr);
|
g_object_unref (named_mgr);
|
||||||
|
|
||||||
g_object_unref (priv->ip4_config);
|
g_object_unref (priv->ip4_config);
|
||||||
@@ -1752,8 +1753,6 @@ nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config, NMDeviceStateReas
|
|||||||
|
|
||||||
priv->ip4_config = g_object_ref (config);
|
priv->ip4_config = g_object_ref (config);
|
||||||
|
|
||||||
ip_iface = nm_device_get_ip_iface (self);
|
|
||||||
|
|
||||||
success = nm_system_device_set_from_ip4_config (ip_iface, config);
|
success = nm_system_device_set_from_ip4_config (ip_iface, config);
|
||||||
if (success) {
|
if (success) {
|
||||||
nm_device_update_ip4_address (self);
|
nm_device_update_ip4_address (self);
|
||||||
|
Reference in New Issue
Block a user