From a77173a7cd162a0aa47a96361a70cd43d178b4f6 Mon Sep 17 00:00:00 2001 From: brian Date: Tue, 6 Apr 1999 23:06:00 +0000 Subject: Use realhostname() rather than various combinations of gethostbyaddr() & gethostbyname(). Remove brokeness in ftpd for hosts of MAXHOSTNAMELEN length. --- libexec/telnetd/telnetd.c | 47 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) (limited to 'libexec/telnetd') diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index c825eab..8baaaf4 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)telnetd.c 8.2 (Berkeley) 12/15/93"; #endif static const char rcsid[] = - "$Id: telnetd.c,v 1.15 1998/12/16 06:04:29 peter Exp $"; + "$Id: telnetd.c,v 1.16 1999/04/06 00:29:41 brian Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -61,6 +61,8 @@ static const char rcsid[] = #include #include +#include +#include #if defined(_SC_CRAY_SECURE_SYS) #include @@ -756,7 +758,7 @@ terminaltypeok(s) char *hostname; char host_name[MAXHOSTNAMELEN]; -char remote_host_name[MAXHOSTNAMELEN]; +char remote_hostname[UT_HOSTSIZE + 1]; extern void telnet P((int, int, char *)); @@ -769,8 +771,6 @@ char user_name[256]; doit(who) struct sockaddr_in *who; { - char *host = NULL; - struct hostent *hp; int ptynum; /* @@ -813,47 +813,16 @@ doit(who) #endif /* _SC_CRAY_SECURE_SYS */ /* get name of connected client */ - hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr), - who->sin_family); - - if (hp == NULL && registerd_host_only) { + if (realhostname(remote_hostname, sizeof remote_hostname - 1, + &who->sin_addr) == HOSTNAME_INVALIDADDR && registerd_host_only) fatal(net, "Couldn't resolve your address into a host name.\r\n\ Please contact your net administrator"); - } else if (hp && - (strlen(hp->h_name) <= ((utmp_len < 0) ? -utmp_len : utmp_len))) { - strncpy(remote_host_name, hp->h_name, - sizeof(remote_host_name)-1); - hp = gethostbyname(remote_host_name); - if (hp == NULL) - host = inet_ntoa(who->sin_addr); - else for (; ; hp->h_addr_list++) { - if (hp->h_addr_list[0] == NULL) { - /* End of list - ditch it */ - host = inet_ntoa(who->sin_addr); - break; - } - if (!bcmp(hp->h_addr_list[0], (caddr_t)&who->sin_addr, - sizeof(who->sin_addr))) { - host = hp->h_name; - break; /* OK! */ - } - } - } else { - host = inet_ntoa(who->sin_addr); - } - /* - * We must make a copy because Kerberos is probably going - * to also do a gethost* and overwrite the static data... - */ - strncpy(remote_host_name, host, sizeof(remote_host_name)-1); - remote_host_name[sizeof(remote_host_name)-1] = 0; - host = remote_host_name; (void) gethostname(host_name, sizeof (host_name)); hostname = host_name; #if defined(AUTHENTICATION) - auth_encrypt_init(hostname, host, "TELNETD", 1); + auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1); #endif init_env(); @@ -873,7 +842,7 @@ doit(who) } #endif /* _SC_CRAY_SECURE_SYS */ - telnet(net, pty, host); /* begin server process */ + telnet(net, pty, remote_hostname); /* begin server process */ /*NOTREACHED*/ } /* end of doit */ -- cgit v1.1