[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#606636: Reverse DNS takes precedence over netcfg/get_hostname



On Saturday, December 11, 2010 07:31:48 am Christian PERRIER wrote:
> Correct. Apparently, though, that behaviour didn't bother anybody
> enough to look at current netcfg code and propose the needed patch

Fair enough.

Attached a patch that introduces a new netcfg/hostname option that -if set- takes precedence over the RDNS/DHCP hostname 
magic.


This patch has a dependency on my other bug/patch: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=606515 (Preseed 
installation does not wait for network to be ready)
Because if netcfg/hostname is set, the reverse DNS check is skipped, and the chance is higher that the installer attempts to fetch 
the kickstart file before the network link is up & running.


-- 
Yours sincerely,

Floris Bos
diff -ur netcfg.orig1/debian/netcfg-common.templates netcfg/debian/netcfg-common.templates
--- netcfg.orig1/debian/netcfg-common.templates	2009-09-12 16:13:23.000000000 +0200
+++ netcfg/debian/netcfg-common.templates	2010-12-11 17:20:01.361351304 +0100
@@ -105,6 +105,12 @@
  administrator. If you are setting up your own home network, you can make
  something up here.
 
+Template: netcfg/hostname
+Type: string
+Description: Hostname that can be preseeded.
+ .
+ If specified this disables the automatic detection of the hostname by netcfg.
+
 Template: netcfg/invalid_hostname
 Type: error
 # :sl2:
diff -ur netcfg.orig1/dhcp.c netcfg/dhcp.c
--- netcfg.orig1/dhcp.c	2010-08-06 23:49:44.000000000 +0200
+++ netcfg/dhcp.c	2010-12-11 23:18:25.841977721 +0100
@@ -473,12 +473,19 @@
                 }
 
                 /*
-                 * Default to the hostname returned via DHCP, if any,
+                 * If the netcfg/hostname preseed value is set use that
+                 * Otherwise default to the hostname returned via DHCP, if any,
                  * otherwise to the requested DHCP hostname
                  * otherwise to the hostname found in DNS for the IP address
                  * of the interface
                  */
-                if (gethostname(buf, sizeof(buf)) == 0
+                debconf_get(client, "netcfg/hostname");
+                if (!empty_str(client->value))
+                {
+                    strncpy(buf, client->value, sizeof(buf));
+                    debconf_set(client, "netcfg/get_hostname", buf);
+                }
+                else if (gethostname(buf, sizeof(buf)) == 0
                     && !empty_str(buf)
                     && strcmp(buf, "(none)")
                     && verify_hostname(buf) == 0
diff -ur netcfg.orig1/static.c netcfg/static.c
--- netcfg.orig1/static.c	2010-08-06 06:32:41.000000000 +0200
+++ netcfg/static.c	2010-12-12 00:12:44.691551386 +0100
@@ -454,9 +464,28 @@
                 GET_GATEWAY : CONFIRM;
             break;
         case GET_HOSTNAME:
-            seed_hostname_from_dns(client, &ipaddress);
-            state = (netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 1)) ?
-                GET_NAMESERVERS : GET_DOMAIN;
+            debconf_get(client, "netcfg/hostname");
+            if (!empty_str(client->value)) {
+                /* Copy preseeded netcfg/hostname to hostname variable and netcfg/get_hostname */
+                hostname = strdup(client->value);
+                debconf_set(client, "netcfg/get_hostname", hostname);
+                
+                /* FQDN? Then set domain */
+                char *s = strchr(hostname, '.');
+                if (s && s[1] != '\0') {
+                    domain = strdup(s + 1);
+                    debconf_set(client, "netcfg/get_domain", domain);
+                    have_domain = 1;
+                    *s = '\0';
+                }
+                state = GET_DOMAIN;
+                
+            } else {
+                seed_hostname_from_dns(client, &ipaddress);
+                state = (netcfg_get_hostname(client, "netcfg/get_hostname", &hostname, 1)) ?
+                    GET_NAMESERVERS : GET_DOMAIN;
+            }
+
             break;
         case GET_DOMAIN:
             if (!have_domain) {

Reply to: