From m.seaman@infracaninophile.co.uk  Thu Oct 13 16:33:54 2011
Return-Path: <m.seaman@infracaninophile.co.uk>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 199E7106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 13 Oct 2011 16:33:54 +0000 (UTC)
	(envelope-from m.seaman@infracaninophile.co.uk)
Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3fd3:cd67:fafa:3d78])
	by mx1.freebsd.org (Postfix) with ESMTP id 8D8C38FC14
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 13 Oct 2011 16:33:53 +0000 (UTC)
Received: from lucid-nonsense.infracaninophile.co.uk (localhost [IPv6:::1])
	by smtp.infracaninophile.co.uk (8.14.5/8.14.5) with ESMTP id p9DGXnJR067218
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 13 Oct 2011 17:33:49 +0100 (BST)
	(envelope-from matthew@lucid-nonsense.infracaninophile.co.uk)
Received: (from matthew@localhost)
	by lucid-nonsense.infracaninophile.co.uk (8.14.5/8.14.5/Submit) id p9DGXn5G067217;
	Thu, 13 Oct 2011 17:33:49 +0100 (BST)
	(envelope-from matthew)
Message-Id: <201110131633.p9DGXn5G067217@lucid-nonsense.infracaninophile.co.uk>
Date: Thu, 13 Oct 2011 17:33:49 +0100 (BST)
From: Matthew Seaman <m.seaman@infracaninophile.co.uk>
Reply-To: Matthew Seaman <m.seaman@infracaninophile.co.uk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] getent(1) inconsistent treatment of IPv6 host data
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         161548
>Category:       bin
>Synopsis:       [patch] getent(1) inconsistent treatment of IPv6 host data
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 13 16:40:03 UTC 2011
>Closed-Date:    Wed Sep 26 09:30:38 UTC 2012
>Last-Modified:  Sun Sep 30 16:20:15 UTC 2012
>Originator:     Matthew Seaman
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
Infracaninophile
>Environment:
System: FreeBSD lucid-nonsense.infracaninophile.co.uk 8.2-STABLE FreeBSD 8.2-STABLE #3 r226035: Wed Oct 5 14:26:52 BST 2011 root@lucid-nonsense.infracaninophile.co.uk:/usr/obj/usr/src/sys/LUCID-NONSENSE amd64


	
>Description:

getent(1) can be used to resolve an IPv6 address into a hostname, but
you can't look up a hostname and find IPv6 addresses.  This is annoyingly
inconsistent.

>How-To-Repeat:
	
>Fix:

	

--- getent.c.diff begins here ---
Index: usr.bin/getent/getent.c
===================================================================
--- usr.bin/getent/getent.c	(revision 226035)
+++ usr.bin/getent/getent.c	(working copy)
@@ -280,7 +280,7 @@
 static int
 hosts(int argc, char *argv[])
 {
-	struct hostent	*he;
+	struct hostent	*he4, *he6;
 	char		addr[IN6ADDRSZ];
 	int		i, rv;
 
@@ -290,19 +290,27 @@
 	sethostent(1);
 	rv = RV_OK;
 	if (argc == 2) {
-		while ((he = gethostent()) != NULL)
-			hostsprint(he);
+		while ((he4 = gethostent()) != NULL)
+			hostsprint(he4);
 	} else {
 		for (i = 2; i < argc; i++) {
-			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
-				he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
-			else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
-				he = gethostbyaddr(addr, INADDRSZ, AF_INET);
-			else
-				he = gethostbyname(argv[i]);
-			if (he != NULL)
-				hostsprint(he);
-			else {
+			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) {
+				he6 = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
+				if (he6 != NULL)
+					hostsprint(he6);
+			} else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) {
+				he4 = gethostbyaddr(addr, INADDRSZ, AF_INET);
+				if (he4 != NULL)
+					hostsprint(he4);
+	       		} else {
+				he6 = gethostbyname2(argv[i], AF_INET6);
+				if (he6 != NULL)
+					hostsprint(he6);
+				he4 = gethostbyname(argv[i]);
+				if (he4 != NULL)
+					hostsprint(he4);
+			}
+			if ( he4 == NULL && he6 == NULL ) {
 				rv = RV_NOTFOUND;
 				break;
 			}
--- getent.c.diff ends here ---


>Release-Note:
>Audit-Trail:

From: Matthew Seaman <m.seaman@infracaninophile.co.uk>
To: bug-followup@FreeBSD.org, m.seaman@infracaninophile.co.uk
Cc:  
Subject: Re: bin/161548: [patch] getent(1) inconsistent treatment of IPv6
 host data
Date: Sun, 04 Mar 2012 20:54:46 +0000

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enigB21C0AF02D70136FAF89589A
 Content-Type: multipart/mixed;
  boundary="------------060107050309040500000709"
 
 This is a multi-part message in MIME format.
 --------------060107050309040500000709
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 
 This fixes a potential use-before-initialization problem and compiles
 with clang.
 
 --=20
 Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                   Flat 3
 PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
 JID: matthew@infracaninophile.co.uk               Kent, CT11 9PW
 
 --------------060107050309040500000709
 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
  name="getent.diff"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
  filename="getent.diff"
 
 Index: usr.bin/getent/getent.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 --- usr.bin/getent/getent.c	(revision 232455)
 +++ usr.bin/getent/getent.c	(working copy)
 @@ -277,7 +277,7 @@
  static int
  hosts(int argc, char *argv[])
  {
 -	struct hostent	*he;
 +	struct hostent	*he4 =3D NULL, *he6 =3D NULL;
  	char		addr[IN6ADDRSZ];
  	int		i, rv;
 =20
 @@ -287,19 +287,27 @@
  	sethostent(1);
  	rv =3D RV_OK;
  	if (argc =3D=3D 2) {
 -		while ((he =3D gethostent()) !=3D NULL)
 -			hostsprint(he);
 +		while ((he4 =3D gethostent()) !=3D NULL)
 +			hostsprint(he4);
  	} else {
  		for (i =3D 2; i < argc; i++) {
 -			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
 -				he =3D gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 -			else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
 -				he =3D gethostbyaddr(addr, INADDRSZ, AF_INET);
 -			else
 -				he =3D gethostbyname(argv[i]);
 -			if (he !=3D NULL)
 -				hostsprint(he);
 -			else {
 +			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) {
 +				he6 =3D gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 +				if (he6 !=3D NULL)
 +					hostsprint(he6);
 +			} else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) {
 +				he4 =3D gethostbyaddr(addr, INADDRSZ, AF_INET);
 +				if (he4 !=3D NULL)
 +					hostsprint(he4);
 +	       		} else {
 +				he6 =3D gethostbyname2(argv[i], AF_INET6);
 +				if (he6 !=3D NULL)
 +					hostsprint(he6);
 +				he4 =3D gethostbyname(argv[i]);
 +				if (he4 !=3D NULL)
 +					hostsprint(he4);
 +			}
 +			if ( he4 =3D=3D NULL && he6 =3D=3D NULL ) {
  				rv =3D RV_NOTFOUND;
  				break;
  			}
 
 --------------060107050309040500000709--
 
 --------------enigB21C0AF02D70136FAF89589A
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iEYEARECAAYFAk9T1pYACgkQ8Mjk52CukIwfigCfepp3/RXcKSGyYXkgNkk7SzeR
 vggAn3izHRpHjGBnWQvvv46L45CQAO63
 =vXZ1
 -----END PGP SIGNATURE-----
 
 --------------enigB21C0AF02D70136FAF89589A--
State-Changed-From-To: open->		 closed 
State-Changed-By: kevlo 
State-Changed-When: Wed Sep 26 09:30:19 UTC 2012 
State-Changed-Why:  
Committed, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161548 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161548: commit references a PR
Date: Wed, 26 Sep 2012 09:31:29 +0000 (UTC)

 Author: kevlo
 Date: Wed Sep 26 09:29:48 2012
 New Revision: 240954
 URL: http://svn.freebsd.org/changeset/base/240954
 
 Log:
   Teach getent(1) to look up a hostname and find IPv6 addresses.
   
   PR:	bin/161548
   Submitted by:	matthew
 
 Modified:
   head/usr.bin/getent/getent.c
 
 Modified: head/usr.bin/getent/getent.c
 ==============================================================================
 --- head/usr.bin/getent/getent.c	Wed Sep 26 09:27:38 2012	(r240953)
 +++ head/usr.bin/getent/getent.c	Wed Sep 26 09:29:48 2012	(r240954)
 @@ -277,7 +277,7 @@ hostsprint(const struct hostent *he)
  static int
  hosts(int argc, char *argv[])
  {
 -	struct hostent	*he;
 +	struct hostent	*he4, *he6;
  	char		addr[IN6ADDRSZ];
  	int		i, rv;
  
 @@ -285,21 +285,31 @@ hosts(int argc, char *argv[])
  	assert(argv != NULL);
  
  	sethostent(1);
 +	he4 = he6 = NULL;
  	rv = RV_OK;
  	if (argc == 2) {
 -		while ((he = gethostent()) != NULL)
 -			hostsprint(he);
 +		while ((he4 = gethostent()) != NULL)
 +			hostsprint(he4);
  	} else {
  		for (i = 2; i < argc; i++) {
 -			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
 -				he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 -			else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
 -				he = gethostbyaddr(addr, INADDRSZ, AF_INET);
 -			else
 -				he = gethostbyname(argv[i]);
 -			if (he != NULL)
 -				hostsprint(he);
 -			else {
 +			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) {
 +				he6 = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 +				if (he6 != NULL)
 +					hostsprint(he6);
 +			} else if (inet_pton(AF_INET, argv[i],
 +			    (void *)addr) > 0) {
 +				he4 = gethostbyaddr(addr, INADDRSZ, AF_INET);
 +				if (he4 != NULL)
 +					hostsprint(he4);
 +	       		} else {
 +				he6 = gethostbyname2(argv[i], AF_INET6);
 +				if (he6 != NULL)
 +					hostsprint(he6);
 +				he4 = gethostbyname(argv[i]);
 +				if (he4 != NULL)
 +					hostsprint(he4);
 +			}
 +			if ( he4 == NULL && he6 == NULL ) {
  				rv = RV_NOTFOUND;
  				break;
  			}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/161548: commit references a PR
Date: Sun, 30 Sep 2012 16:19:10 +0000 (UTC)

 Author: kevlo
 Date: Sun Sep 30 16:17:54 2012
 New Revision: 241075
 URL: http://svn.freebsd.org/changeset/base/241075
 
 Log:
   MFC r240954:
   Teach getent(1) to look up a hostname and find IPv6 addresses.
   
   PR:	bin/161548
   Submitted by:	matthew
 
 Modified:
   stable/9/usr.bin/getent/getent.c
 Directory Properties:
   stable/9/usr.bin/   (props changed)
 
 Modified: stable/9/usr.bin/getent/getent.c
 ==============================================================================
 --- stable/9/usr.bin/getent/getent.c	Sun Sep 30 16:11:50 2012	(r241074)
 +++ stable/9/usr.bin/getent/getent.c	Sun Sep 30 16:17:54 2012	(r241075)
 @@ -277,7 +277,7 @@ hostsprint(const struct hostent *he)
  static int
  hosts(int argc, char *argv[])
  {
 -	struct hostent	*he;
 +	struct hostent	*he4, *he6;
  	char		addr[IN6ADDRSZ];
  	int		i, rv;
  
 @@ -285,21 +285,31 @@ hosts(int argc, char *argv[])
  	assert(argv != NULL);
  
  	sethostent(1);
 +	he4 = he6 = NULL;
  	rv = RV_OK;
  	if (argc == 2) {
 -		while ((he = gethostent()) != NULL)
 -			hostsprint(he);
 +		while ((he4 = gethostent()) != NULL)
 +			hostsprint(he4);
  	} else {
  		for (i = 2; i < argc; i++) {
 -			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
 -				he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 -			else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
 -				he = gethostbyaddr(addr, INADDRSZ, AF_INET);
 -			else
 -				he = gethostbyname(argv[i]);
 -			if (he != NULL)
 -				hostsprint(he);
 -			else {
 +			if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) {
 +				he6 = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
 +				if (he6 != NULL)
 +					hostsprint(he6);
 +			} else if (inet_pton(AF_INET, argv[i],
 +			    (void *)addr) > 0) {
 +				he4 = gethostbyaddr(addr, INADDRSZ, AF_INET);
 +				if (he4 != NULL)
 +					hostsprint(he4);
 +	       		} else {
 +				he6 = gethostbyname2(argv[i], AF_INET6);
 +				if (he6 != NULL)
 +					hostsprint(he6);
 +				he4 = gethostbyname(argv[i]);
 +				if (he4 != NULL)
 +					hostsprint(he4);
 +			}
 +			if ( he4 == NULL && he6 == NULL ) {
  				rv = RV_NOTFOUND;
  				break;
  			}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
