From: millert Date: Sat, 16 Mar 2024 02:00:31 +0000 (+0000) Subject: whois: trim output after ">>> Last update of WHOIS database:" X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c5e54dfbb406dd6c177137bb1418cf564dc9389c;p=openbsd whois: trim output after ">>> Last update of WHOIS database:" Currently, whois(1) displays the full output it receives from the server. With this change, any text after a line starting with ">>> Last update of WHOIS database:" is dropped. This trims a lot of useless text that would otherwise cause the data you care about to scroll off the screen. From FreeBSD. OK deraadt@ --- diff --git a/usr.bin/whois/whois.1 b/usr.bin/whois/whois.1 index 7477324bbcd..f5318951e07 100644 --- a/usr.bin/whois/whois.1 +++ b/usr.bin/whois/whois.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: whois.1,v 1.39 2024/03/05 16:06:32 millert Exp $ +.\" $OpenBSD: whois.1,v 1.40 2024/03/16 02:00:31 millert Exp $ .\" $NetBSD: whois.1,v 1.5 1995/08/31 21:51:32 jtc Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)whois.1 8.2 (Berkeley) 6/20/94 .\" -.Dd $Mdocdate: March 5 2024 $ +.Dd $Mdocdate: March 16 2024 $ .Dt WHOIS 1 .Os .Sh NAME @@ -38,7 +38,7 @@ .Nd Internet domain name and network number directory service .Sh SYNOPSIS .Nm whois -.Op Fl AadgIilmPQRr +.Op Fl AadgIilmPQRrS .Oo .Fl c Ar country-code | Fl h Ar host .Oc @@ -201,6 +201,16 @@ Use the Reseaux IP Europeens .Pq Tn RIPE database. It contains network numbers and domain contact information for Europe. +.It Fl S +By default +.Nm +adjusts simple queries (without spaces) to produce more useful output +from certain whois servers, and it suppresses some uninformative output. +With the +.Fl S +option, +.Nm +sends the query and prints the output verbatim. .El .Pp The default action, unless directed otherwise with a special diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c index 7f922488cf3..8421baeb91a 100644 --- a/usr.bin/whois/whois.c +++ b/usr.bin/whois/whois.c @@ -1,4 +1,4 @@ -/* $OpenBSD: whois.c,v 1.59 2024/03/05 16:06:32 millert Exp $ */ +/* $OpenBSD: whois.c,v 1.60 2024/03/16 02:00:31 millert Exp $ */ /* * Copyright (c) 1980, 1993 @@ -64,8 +64,11 @@ #define WHOIS_PORT "whois" #define WHOIS_SERVER_ID "Registrar WHOIS Server:" -#define WHOIS_RECURSE 0x01 -#define WHOIS_QUICK 0x02 +#define WHOIS_RECURSE 0x01 +#define WHOIS_QUICK 0x02 +#define WHOIS_SPAM_ME 0x04 + +#define CHOPSPAM ">>> Last update of WHOIS database:" const char *port_whois = WHOIS_PORT; const char *ip_whois[] = { LNICHOST, RNICHOST, PNICHOST, BNICHOST, @@ -83,7 +86,7 @@ main(int argc, char *argv[]) country = host = NULL; flags = rval = 0; - while ((ch = getopt(argc, argv, "aAc:dgh:iIlmp:PqQrR")) != -1) + while ((ch = getopt(argc, argv, "aAc:dgh:iIlmp:PqQrRS")) != -1) switch (ch) { case 'a': host = ANICHOST; @@ -133,6 +136,9 @@ main(int argc, char *argv[]) case 'R': host = RUNICHOST; break; + case 'S': + flags |= WHOIS_SPAM_ME; + break; default: usage(); } @@ -206,11 +212,13 @@ whois(const char *query, const char *server, const char *port, int flags) return (1); } - if (strcmp(server, "whois.denic.de") == 0 || - strcmp(server, "de" QNICHOST_TAIL) == 0) + if (!(flags & WHOIS_SPAM_ME) && + (strcmp(server, "whois.denic.de") == 0 || + strcmp(server, "de" QNICHOST_TAIL) == 0)) fmt = "-T dn,ace -C ISO-8859-1 %s\r\n"; - else if (strcmp(server, "whois.dk-hostmaster.dk") == 0 || - strcmp(server, "dk" QNICHOST_TAIL) == 0) + else if (!(flags & WHOIS_SPAM_ME) && + (strcmp(server, "whois.dk-hostmaster.dk") == 0 || + strcmp(server, "dk" QNICHOST_TAIL) == 0)) fmt = "--show-handles %s\r\n"; else fmt = "%s\r\n"; @@ -222,6 +230,11 @@ whois(const char *query, const char *server, const char *port, int flags) fflush(fp); nhost = NULL; while ((buf = fgetln(fp, &len)) != NULL) { + /* Nominet */ + if (!(flags & WHOIS_SPAM_ME) && + len == 5 && strncmp(buf, "-- \r\n", 5) == 0) + break; + p = buf + len - 1; if (isspace((unsigned char)*p)) { do @@ -236,31 +249,39 @@ whois(const char *query, const char *server, const char *port, int flags) } puts(buf); - if (nhost != NULL || !(flags & WHOIS_RECURSE)) - continue; - - if ((p = strstr(buf, WHOIS_SERVER_ID))) { - p += sizeof(WHOIS_SERVER_ID) - 1; - while (isblank((unsigned char)*p)) - p++; - if ((len = strcspn(p, " \t\n\r"))) { - if ((nhost = malloc(len + 1)) == NULL) - err(1, "malloc"); - memcpy(nhost, p, len); - nhost[len] = '\0'; - } - } else if (strcmp(server, ANICHOST) == 0) { - for (p = buf; *p != '\0'; p++) - *p = tolower((unsigned char)*p); - for (i = 0; ip_whois[i] != NULL; i++) { - if (strstr(buf, ip_whois[i]) != NULL) { - nhost = strdup(ip_whois[i]); - if (nhost == NULL) - err(1, "strdup"); - break; + if (nhost == NULL && (flags & WHOIS_RECURSE)) { + if ((p = strstr(buf, WHOIS_SERVER_ID))) { + p += sizeof(WHOIS_SERVER_ID) - 1; + while (isblank((unsigned char)*p)) + p++; + if ((len = strcspn(p, " \t\n\r"))) { + if ((nhost = malloc(len + 1)) == NULL) + err(1, "malloc"); + memcpy(nhost, p, len); + nhost[len] = '\0'; + } + } else if (strcmp(server, ANICHOST) == 0) { + for (p = buf; *p != '\0'; p++) + *p = tolower((unsigned char)*p); + for (i = 0; ip_whois[i] != NULL; i++) { + if (strstr(buf, ip_whois[i]) != NULL) { + nhost = strdup(ip_whois[i]); + if (nhost == NULL) + err(1, "strdup"); + break; + } } } } + + /* Verisign etc. */ + if (!(flags & WHOIS_SPAM_ME) && + len >= sizeof(CHOPSPAM)-1 && + (strncasecmp(buf, CHOPSPAM, sizeof(CHOPSPAM)-1) == 0 || + strncasecmp(buf, &CHOPSPAM[4], sizeof(CHOPSPAM)-5) == 0)) { + printf("\n"); + break; + } } fclose(fp); free(nbuf);