From nobody@FreeBSD.org  Wed Feb 13 03:45:42 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id E9F38DD3
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Feb 2013 03:45:42 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id B7DF6892
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Feb 2013 03:45:42 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r1D3jf4L064764
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Feb 2013 03:45:41 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r1D3jfX4064763;
	Wed, 13 Feb 2013 03:45:41 GMT
	(envelope-from nobody)
Message-Id: <201302130345.r1D3jfX4064763@red.freebsd.org>
Date: Wed, 13 Feb 2013 03:45:41 GMT
From: Landon Fuller <landonf@bikemonkey.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Fix resolver support for '_' character in hostnames
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         176093
>Category:       kern
>Synopsis:       [libc] [patch] Fix resolver support for '_' character in hostnames
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 13 03:50:01 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Feb 15 13:50:00 UTC 2013
>Originator:     Landon Fuller
>Release:        9.1-RELEASE
>Organization:
>Environment:
FreeBSD directory2 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec  4 06:55:39 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
Back in 2008, the libc resolver was modified to accept Microsoft's non-standard use of '_' in host names:

http://svnweb.freebsd.org/base?view=revision&revision=176325

The fix appears to be incomplete, as it only covered the case where an underscore occurs within a domain component (eg, 'example_name', rather than at the beginning or end.

The attached patch adds support for '_' occurring at the beginning, middle, or end of a name component. This style of name is required by AD, and by extension, by Samba4; this patch fixes issues with samba4 replication on FreeBSD.

>How-To-Repeat:
Try resolving a name containing a leading '_', such as 'gc._msdcs.example.org'

>Fix:
See attached patch

Patch attached with submission follows:

--- lib/libc/resolv/res_comp.c.orig	2013-02-12 21:50:31.000000000 -0500
+++ lib/libc/resolv/res_comp.c	2013-02-12 21:51:05.000000000 -0500
@@ -147,12 +147,12 @@
 		   || ((c) >= 0x61 && (c) <= 0x7a))
 #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
 
-#define borderchar(c) (alphachar(c) || digitchar(c))
 #ifdef	RES_ENFORCE_RFC1034
-#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define borderchar(c) (alphachar(c) || digitchar(c))
 #else
-#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
+#define borderchar(c) (alphachar(c) || digitchar(c) || underscorechar(c))
 #endif
+#define middlechar(c) (borderchar(c) || hyphenchar(c))
 #define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
 
 int


>Release-Note:
>Audit-Trail:

From: Landon Fuller <landonf@bikemonkey.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/176093: [libc] [patch] Fix resolver support for &#39;_&#39; character in hostnames
Date: Fri, 15 Feb 2013 08:39:04 -0500

 A simpler test case:
 
 #include <netinet/in.h>
 #include <resolv.h>
 
 int main (int argc, char *argv[]) {
     if (argc < 2) return 1;
     int ret = res_hnok(argv[1]);
     printf("%d\n", ret);
 }
 
 Usage:
 
 landonf:~> ./test-res_hnok gc._msdcs.example.org
 0
 
 landonf:~> ./test-res_hnok gc.msdcs.example.org 
 1
>Unformatted:
