From pdh@minotaur.int.bit.net.au  Mon Dec 18 16:41:53 2000
Return-Path: <pdh@minotaur.int.bit.net.au>
Received: from minotaur.int.bit.net.au (fw-hme0.bne.au.asiaonline.net [210.215.40.126])
	by hub.freebsd.org (Postfix) with ESMTP id A838637B400
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 18 Dec 2000 16:41:50 -0800 (PST)
Received: (from pdh@localhost)
	by minotaur.int.bit.net.au (8.11.0/8.11.0) id eBJ0fjl00856;
	Tue, 19 Dec 2000 10:41:45 +1000 (EST)
	(envelope-from pdh)
Message-Id: <200012190041.eBJ0fjl00856@minotaur.int.bit.net.au>
Date: Tue, 19 Dec 2000 10:41:45 +1000 (EST)
From: Phil Homewood <pdh@minotaur.int.bit.net.au>
Reply-To: pdh@minotaur.int.bit.net.au
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] whois enhancement - smarter whois-servers.net lookups
X-Send-Pr-Version: 3.2

>Number:         23635
>Category:       bin
>Synopsis:       [PATCH] whois(1) enhancement - smarter whois-servers.net lookups
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    linimon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 18 16:50:01 PST 2000
>Closed-Date:    Mon Apr 03 21:55:23 GMT 2006
>Last-Modified:  Mon Apr 03 21:55:23 GMT 2006
>Originator:     Phil Homewood
>Release:        FreeBSD 4.1-STABLE i386
>Organization:
Asia Online
>Environment:

FreeBSD 4.2-STABLE #0: Tue Dec 12 11:14:33 EST 2000

>Description:

whois doesn't look up registries for non-TLDs.

>How-To-Repeat:

whois bit.net.au
whois -h net.au.whois-servers.net bit.net.au

>Fix:

The following patch tries ever-shortening suffixes of the given
domain until it finds a whois-server to ask. It also fixes a
minor annoyance in that "whois example.com." fails.


--- usr.bin/whois/whois.c.orig	Sat Jul 15 17:29:31 2000
+++ usr.bin/whois/whois.c	Tue Dec 19 10:26:21 2000
@@ -84,6 +84,7 @@
 {
 	int ch, i, j, error;
 	int use_qnichost, flags;
+	int found = 0;
 	char *host;
 	char *qnichost;
 	struct addrinfo hints, *res;
@@ -160,29 +161,42 @@
 				free(qnichost);
 				qnichost = NULL;
 			}
-			for (i = j = 0; (*argv)[i]; i++) {
-				if ((*argv)[i] == '.') {
-					j = i;
-				}
+			for (i = 0; (*argv)[i]; i++);
+			if (i <= 1) {
+				errx(EX_NOHOST,
+					"Can't search for the null string.");
 			}
-			if (j != 0) {
-				qnichost = (char *) calloc(i - j + 1 +
-				    strlen(QNICHOST_TAIL), sizeof(char));
-				if (!qnichost) {
-					err(1, "calloc");
+			if (*argv[i] == '.') i--;
+			for (j = 0; (*argv)[j]; j++) {
+				if (((*argv)[j] == '.') && !found) {
+					qnichost = (char *) calloc(i - j + 1 +
+					    	strlen(QNICHOST_TAIL),
+						sizeof(char));
+					if (!qnichost) {
+						err(1, "calloc");
+					}
+					strcpy(qnichost, *argv + j + 1);
+					strcat(qnichost, QNICHOST_TAIL);
+	
+					memset(&hints, 0, sizeof(hints));
+					hints.ai_flags = 0;
+					hints.ai_family = AF_UNSPEC;
+					hints.ai_socktype = SOCK_STREAM;
+					error = getaddrinfo(qnichost, "whois",
+							&hints, &res);
+					if (error == 0) {
+						found = 1;
+					} else {
+						free(qnichost);
+						qnichost = NULL;
+					}
 				}
-				strcpy(qnichost, *argv + j + 1);
-				strcat(qnichost, QNICHOST_TAIL);
 
-				memset(&hints, 0, sizeof(hints));
-				hints.ai_flags = 0;
-				hints.ai_family = AF_UNSPEC;
-				hints.ai_socktype = SOCK_STREAM;
-				error = getaddrinfo(qnichost, "whois",
-						&hints, &res);
-				if (error != 0)
-					errx(EX_NOHOST, "%s: %s", qnichost,
-						gai_strerror(error));
+			}
+			if (!found) {
+				errx(EX_NOHOST,
+					"Cannot locate whois server for %s",
+					*argv);
 			}
 		}
 		if (!qnichost) {

>Release-Note:
>Audit-Trail:

From: Phil Homewood <pdh@bit.net.au>
To: gnats-admin@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: bin/23635: [PATCH] whois enhancement - smarter whois-servers.net lookups
Date: Tue, 19 Dec 2000 11:17:59 +1000

 I said:
 > It also fixes a minor annoyance in that "whois example.com." fails.
 
 Oops, that version doesn't. This one does.
 Please supersede my previous patch with this one.
 
 
 --- usr.bin/whois/whois.c.orig	Sat Jul 15 17:29:31 2000
 +++ usr.bin/whois/whois.c	Tue Dec 19 11:14:33 2000
 @@ -84,6 +84,7 @@
  {
  	int ch, i, j, error;
  	int use_qnichost, flags;
 +	int found = 0;
  	char *host;
  	char *qnichost;
  	struct addrinfo hints, *res;
 @@ -160,29 +161,43 @@
  				free(qnichost);
  				qnichost = NULL;
  			}
 -			for (i = j = 0; (*argv)[i]; i++) {
 -				if ((*argv)[i] == '.') {
 -					j = i;
 -				}
 +			for (i = 0; (*argv)[i]; i++);
 +			if (i <= 1) {
 +				errx(EX_NOHOST,
 +					"Can't search for the null string.");
  			}
 -			if (j != 0) {
 -				qnichost = (char *) calloc(i - j + 1 +
 -				    strlen(QNICHOST_TAIL), sizeof(char));
 -				if (!qnichost) {
 -					err(1, "calloc");
 +			if ((*argv)[i - 1] == '.') i--;
 +			for (j = 0; (*argv)[j]; j++) {
 +				if (((*argv)[j] == '.') && !found) {
 +					qnichost = (char *) calloc(i - j + 1 +
 +					    	strlen(QNICHOST_TAIL),
 +						sizeof(char));
 +					if (!qnichost) {
 +						err(1, "calloc");
 +					}
 +					strncpy(qnichost, *argv + j + 1,
 +						i - j - 1);
 +					strcat(qnichost, QNICHOST_TAIL);
 +
 +					memset(&hints, 0, sizeof(hints));
 +					hints.ai_flags = 0;
 +					hints.ai_family = AF_UNSPEC;
 +					hints.ai_socktype = SOCK_STREAM;
 +					error = getaddrinfo(qnichost, "whois",
 +							&hints, &res);
 +					if (error == 0) {
 +						found = 1;
 +					} else {
 +						free(qnichost);
 +						qnichost = NULL;
 +					}
  				}
 -				strcpy(qnichost, *argv + j + 1);
 -				strcat(qnichost, QNICHOST_TAIL);
  
 -				memset(&hints, 0, sizeof(hints));
 -				hints.ai_flags = 0;
 -				hints.ai_family = AF_UNSPEC;
 -				hints.ai_socktype = SOCK_STREAM;
 -				error = getaddrinfo(qnichost, "whois",
 -						&hints, &res);
 -				if (error != 0)
 -					errx(EX_NOHOST, "%s: %s", qnichost,
 -						gai_strerror(error));
 +			}
 +			if (!found) {
 +				errx(EX_NOHOST,
 +					"Cannot locate whois server for %s",
 +					*argv);
  			}
  		}
  		if (!qnichost) {
 -- 
 Phil Homewood                 pdh@asiaonline.net
 Senior Technician             +61 7 3620 1930
 Asia Online (Queensland)      http://www.asiaonline.net/
 
Responsible-Changed-From-To: freebsd-bugs->mike 
Responsible-Changed-By: mike 
Responsible-Changed-When: Sun Jul 22 12:51:06 PDT 2001 
Responsible-Changed-Why:  

I'll look into this one. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=23635 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Mon Apr 3 21:28:01 UTC 2006 
State-Changed-Why:  
Is this still a problem with recent versions of FreeBSD? 


Responsible-Changed-From-To: mike->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Apr 3 21:28:01 UTC 2006 
Responsible-Changed-Why:  
Reset PR assigned to inactive committer who has not responded to email. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23635 
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Apr 3 21:55:14 UTC 2006 
State-Changed-Why:  
Submitter's email address bounces. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23635 
>Unformatted:
