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

Relax dhclient hostname checks



Hello,

after a bit of discussion with henning@, we agreed that I should send
this here for more attention and, hopefully, testing.

This is a diff which relaxes the checks dhclient does on hostnames.
More specifically, it allows hostnames to contain underscores. While
this isn't allowed per se, it is used in a number of places, and this
prevents our dhclient from accepting a lease and thus configuring the
network interface.

Note that apart from permitting underscores, the diff also attempts to
improve readability of the code.

Index: dhclient.c
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.63
diff -u -r1.63 dhclient.c
--- dhclient.c	2005/02/06 17:10:13	1.63
+++ dhclient.c	2005/03/23 21:20:47
@@ -56,17 +56,17 @@
 #include "dhcpd.h"
 #include "privsep.h"
 
-#define	PERIOD 0x2e
-#define	hyphenchar(c) ((c) == 0x2d)
-#define	bslashchar(c) ((c) == 0x5c)
-#define	periodchar(c) ((c) == PERIOD)
-#define	asterchar(c) ((c) == 0x2a)
-#define	alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) || \
-	    ((c) >= 0x61 && (c) <= 0x7a))
-#define	digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+#define	hyphenchar(c) ((c) == '-')
+#define	uscorechar(c) ((c) == '_')
+#define	bslashchar(c) ((c) == '\\')
+#define	periodchar(c) ((c) == '.')
+#define	asterchar(c) ((c) == '*')
+#define	alphachar(c) (((c) >= 'a' && (c) <= 'z') || \
+	    ((c) >= 'A' && (c) <= 'Z'))
+#define	digitchar(c) ((c) >= '0' && (c) <= '9')
 
 #define	borderchar(c) (alphachar(c) || digitchar(c))
-#define	middlechar(c) (borderchar(c) || hyphenchar(c))
+#define	middlechar(c) (borderchar(c) || hyphenchar(c) || uscorechar(c))
 #define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
 
 #define	CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin"
@@ -2253,7 +2253,7 @@
 int
 res_hnok(const char *dn)
 {
-	int pch = PERIOD, ch = *dn++;
+	int pch = '.', ch = *dn++;
 
 	while (ch != '\0') {
 		int nch = *dn++;

Please test this both with and without underscored hostnames in your dhcp
config. Report success to me or henning@; breakage goes to the list.

Regards,
Michael.
-- 
Winter meant the coming of the lazy wind, which couldn't be bothered to
blow around people and blew right through them instead.
-- (Terry Pratchett, Wyrd Sisters)