On Fri, 2005-01-28 at 12:22 +0100, Martin Norbäck wrote: > Hi! > > I've been having multiple domain names in the domain-name option in my > dhcp server. I know this is not standard but it works with dhclient- > script. Is it not standard for the DHCP domainName options field to have a space-separated list of domains, or is it just not standard to put that data in the domain-name option for your DHCP server? > NetworkManager won't have it, however, and claims: > > NetworkManager: : Adding domain search: domain1.com domain2.com > NetworkManager: : Couldn't add domain search: Invalid characters in host Yes; the code intentionally validates returned hostnames in order to ensure that a misconfigured or malicious DHCP server can't badly corrupt your /etc/resolv.conf. > Is it desirable to fix NetworkManager to accept a space delimited list > of domains to search? Can you try this patch? I haven't even tried compiling it, have to head out the door at the moment.
cvs server: Diffing . cvs server: Diffing dhcpcd cvs server: Diffing dispatcher-daemon cvs server: Diffing docs cvs server: Diffing examples cvs server: Diffing examples/python cvs server: Diffing examples/python/systray cvs server: Diffing info-daemon cvs server: Diffing initscript cvs server: Diffing initscript/Debian cvs server: Diffing initscript/Gentoo cvs server: Diffing initscript/RedHat cvs server: Diffing initscript/Slackware cvs server: Diffing libnm_glib cvs server: Diffing named Index: named/nm-named-manager.c =================================================================== RCS file: /cvs/gnome/NetworkManager/named/nm-named-manager.c,v retrieving revision 1.7 diff -u -d -r1.7 nm-named-manager.c --- named/nm-named-manager.c 18 Jan 2005 16:09:22 -0000 1.7 +++ named/nm-named-manager.c 28 Jan 2005 23:52:01 -0000 @@ -556,7 +556,7 @@ g_string_append (str, "search "); g_string_append (str, server); - g_string_append_c (str, '\n'); + g_string_append_c (str, ' '); } static char * @@ -594,7 +594,7 @@ goto lose; searches = compute_domain_searches (mgr); - if (fprintf (f, "%s","; generated by NetworkManager, do not edit!\n") < 0) { + if (fprintf (f, "%s\n","; generated by NetworkManager, do not edit!\n") < 0) { g_free (searches); goto lose; } cvs server: Diffing panel-applet cvs server: Diffing panel-applet/icons cvs server: Diffing po cvs server: Diffing src Index: src/NetworkManagerDHCP.c =================================================================== RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerDHCP.c,v retrieving revision 1.9 diff -u -d -r1.9 NetworkManagerDHCP.c --- src/NetworkManagerDHCP.c 21 Jan 2005 19:32:08 -0000 1.9 +++ src/NetworkManagerDHCP.c 28 Jan 2005 23:52:01 -0000 @@ -81,31 +81,45 @@ } } -static void set_domain_search (NMDevice *dev, const char *domain) +static void set_domain_searches (NMDevice *dev, const char *searches_str) { GError *error = NULL; - guint id; + GList *elt; + char **searches; - if (dev->app_data->domain_search_id - && !nm_named_manager_remove_domain_search (dev->app_data->named, - dev->app_data->domain_search_id, - &error)) + /* Reset our domain search list */ + for (elt = dev->app_data->domain_search_ids; elt; elt = elt->next) { - syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Couldn't remove domain search: %s\n", error->message); - g_clear_error (&error); + if (!nm_named_manager_remove_domain_search (dev->app_data->named, + GPOINTER_TO_UINT (elt->data), + &error)) + { + syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Couldn't remove domain search: %s\n", error->message); + g_clear_error (&error); + } } - - syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Adding domain search: %s\n", domain); - if ((id = nm_named_manager_add_domain_search (dev->app_data->named, - domain, - &error))) - dev->app_data->domain_search_id = id; - else + g_list_free (dev->app_data->domain_search_ids); + dev->app_data->domain_search_ids = NULL; + + searches = g_strsplit (searches_str, " ", 0); + + for (; *searches; searches++) { - dev->app_data->domain_search_id = 0; - syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Couldn't add domain search: %s\n", error->message); - g_clear_error (&error); + const char *search_elt = *searches; + guint id; + + syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Adding domain search: %s\n", search_elt); + if ((id = nm_named_manager_add_domain_search (dev->app_data->named, + search_elt, + &error))) + dev->app_data->domain_search_ids = g_list_append (dev->app_data->domain_search_ids, GUINT_TO_POINTER (id)); + else + { + syslog (LOG_ERR, G_GNUC_PRETTY_FUNCTION ": Couldn't add domain search: %s\n", error->message); + g_clear_error (&error); + } } + g_strfreev (searches); } /* @@ -148,7 +162,7 @@ set_nameservers (dev, dhcp_interface_get_dhcp_field (dev->dhcp_iface, dns), dhcp_interface_get_dhcp_field_len (dev->dhcp_iface, dns)); if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, domainName)) - set_domain_search (dev, dhcp_interface_get_dhcp_field (dev->dhcp_iface, domainName)); + set_domain_searches (dev, dhcp_interface_get_dhcp_field (dev->dhcp_iface, domainName)); } Index: src/NetworkManagerMain.h =================================================================== RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerMain.h,v retrieving revision 1.8 diff -u -d -r1.8 NetworkManagerMain.h --- src/NetworkManagerMain.h 25 Jan 2005 18:21:38 -0000 1.8 +++ src/NetworkManagerMain.h 28 Jan 2005 23:52:01 -0000 @@ -39,7 +39,7 @@ NMNamedManager *named; GList *nameserver_ids; /* For now these are global instead of per-device */ - guint domain_search_id; + GList *domain_search_ids; DBusConnection *dbus_connection; GMainContext *main_context; cvs server: Diffing src/backends cvs server: Diffing test
Attachment:
signature.asc
Description: This is a digitally signed message part