summaryrefslogtreecommitdiffstats
path: root/usr.bin/whois
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2001-10-12 17:39:36 +0000
committermike <mike@FreeBSD.org>2001-10-12 17:39:36 +0000
commit2abcf6c606de386ba30e4e9328c174e6bac0898b (patch)
treefda7d312fa778e308b2c6694539cdf45ba3863e6 /usr.bin/whois
parent56d6381b9065cb870fb7706d9b1ed9916b7b9a7d (diff)
downloadFreeBSD-src-2abcf6c606de386ba30e4e9328c174e6bac0898b.zip
FreeBSD-src-2abcf6c606de386ba30e4e9328c174e6bac0898b.tar.gz
o Treat a buffer as a non-NUL terminated string, because the whois
server may not return a new line character on the final line. o Remove the whois.networksolutions.com fallback code, which is no longer needed. o Instead of determining a hostname by terminating it when we see whitespace, only allow hostname characters and terminate the string when it's not such a character. o Add a small optimization in a for loop. PR: 30968 Reviewed by: -audit MFC after: 4 days
Diffstat (limited to 'usr.bin/whois')
-rw-r--r--usr.bin/whois/whois.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index 9cae44a..d2a239a 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -71,11 +71,11 @@ static const char rcsid[] =
#define SNICHOST "whois.6bone.net"
#define DEFAULT_PORT "whois"
#define WHOIS_SERVER_ID "Whois Server: "
-#define NO_MATCH_ID "No match for \""
#define WHOIS_RECURSE 0x01
-#define WHOIS_INIC_FALLBACK 0x02
-#define WHOIS_QUICK 0x04
+#define WHOIS_QUICK 0x02
+
+#define ishost(h) (isalnum((unsigned char)h) || h == '.' || h == '-')
const char *ip_whois[] = { RNICHOST, PNICHOST, NULL };
const char *port = DEFAULT_PORT;
@@ -164,7 +164,7 @@ main(int argc, char *argv[])
use_qnichost = 1;
host = NICHOST;
if (!(flags & WHOIS_QUICK))
- flags |= WHOIS_INIC_FALLBACK | WHOIS_RECURSE;
+ flags |= WHOIS_RECURSE;
}
while (argc--) {
if (country != NULL) {
@@ -251,8 +251,8 @@ whois(char *name, struct addrinfo *res, int flags)
{
FILE *sfi, *sfo;
struct addrinfo *res2;
- char *buf, *nhost, *p;
- int i, nomatch, s;
+ char *buf, *host, *nhost, *p;
+ int i, s;
size_t len;
for (; res; res = res->ai_next) {
@@ -273,45 +273,35 @@ whois(char *name, struct addrinfo *res, int flags)
fprintf(sfo, "%s\r\n", name);
fflush(sfo);
nhost = NULL;
- nomatch = 0;
while ((buf = fgetln(sfi, &len)) != NULL) {
- while (len && isspace(buf[len - 1]))
+ while (len > 0 && isspace((unsigned char)buf[len - 1]))
buf[--len] = '\0';
+ printf("%.*s\n", (int)len, buf);
if ((flags & WHOIS_RECURSE) && nhost == NULL) {
- p = strstr(buf, WHOIS_SERVER_ID);
- if (p != NULL) {
- p += sizeof(WHOIS_SERVER_ID) - 1;
- if ((len = strcspn(p, " \t\n\r")) != 0) {
- s_asprintf(&nhost, "%s", p);
+ host = strnstr(buf, WHOIS_SERVER_ID, len);
+ if (host != NULL) {
+ host += sizeof(WHOIS_SERVER_ID) - 1;
+ for (p = host; p < buf + len; p++) {
+ if (!ishost(*p)) {
+ *p = '\0';
+ break;
+ }
}
+ s_asprintf(&nhost, "%.*s",
+ (int)(buf + len - host), host);
} else {
for (i = 0; ip_whois[i] != NULL; i++) {
- if (strstr(buf, ip_whois[i]) == NULL)
- continue;
- s_asprintf(&nhost, "%s", ip_whois[i]);
+ if (strnstr(buf, ip_whois[i], len) !=
+ NULL) {
+ s_asprintf(&nhost, "%s",
+ ip_whois[i]);
+ break;
+ }
}
}
}
-
- if ((flags & WHOIS_INIC_FALLBACK) && nhost == NULL &&
- !nomatch && (p = strstr(buf, NO_MATCH_ID)) != NULL) {
- p += sizeof(NO_MATCH_ID) - 1;
- if ((len = strcspn(p, "\"")) &&
- strncasecmp(name, p, len) == 0 &&
- name[len] == '\0' &&
- strchr(name, '.') == NULL)
- nomatch = 1;
- }
- printf("%s\n", buf);
}
-
- /* Do second lookup as needed. */
- if (nomatch && nhost == NULL) {
- printf("Looking up %s at %s.\n\n", name, INICHOST);
- s_asprintf(&nhost, "%s", INICHOST);
- }
-
if (nhost != NULL) {
if ((res2 = gethostinfo(nhost, 0)) == NULL) {
free(nhost);
OpenPOWER on IntegriCloud