Bug 23635

Summary: [PATCH] whois(1) enhancement - smarter whois-servers.net lookups
Product: Base System Reporter: Phil Homewood <pdh>
Component: binAssignee: Mark Linimon <linimon>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.1-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Phil Homewood 2000-12-19 00:50:01 UTC
whois doesn't look up registries for non-TLDs.

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.

How-To-Repeat: 
whois bit.net.au
whois -h net.au.whois-servers.net bit.net.au
Comment 1 pdh 2000-12-19 01:17:59 UTC
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/
Comment 2 Mike Barcroft freebsd_committer freebsd_triage 2001-07-22 20:51:06 UTC
Responsible Changed
From-To: freebsd-bugs->mike


I'll look into this one.
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2006-04-03 22:28:01 UTC
State Changed
From-To: open->feedback

Is this still a problem with recent versions of FreeBSD? 


Comment 4 Mark Linimon freebsd_committer freebsd_triage 2006-04-03 22:28:01 UTC
Responsible Changed
From-To: mike->linimon

Reset PR assigned to inactive committer who has not responded to email.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2006-04-03 22:55:14 UTC
State Changed
From-To: feedback->closed

Submitter's email address bounces.