mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-02 12:20:51 +00:00
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
This commit is contained in:
parent
e7c25bd2f6
commit
42ab40e52d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84852
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user