diff options
Diffstat (limited to 'contrib/telnet/telnetd/telnetd.c')
-rw-r--r-- | contrib/telnet/telnetd/telnetd.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/contrib/telnet/telnetd/telnetd.c b/contrib/telnet/telnetd/telnetd.c index 76cbf59..8b4798c 100644 --- a/contrib/telnet/telnetd/telnetd.c +++ b/contrib/telnet/telnetd/telnetd.c @@ -42,7 +42,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; #endif static const char rcsid[] = - "$Id: telnetd.c,v 1.5 1998/12/16 06:06:06 peter Exp $"; + "$Id: telnetd.c,v 1.7 1999/04/06 23:35:21 brian Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -93,7 +93,8 @@ int auth_level = 0; int require_SecurID = 0; #endif -extern int utmp_len; +char remote_hostname[UT_HOSTSIZE + 1]; +int utmp_len = sizeof(remote_hostname) - 1; int registerd_host_only = 0; #ifdef STREAMSPTY @@ -386,6 +387,10 @@ main(argc, argv) case 'u': utmp_len = atoi(optarg); + if (utmp_len < 0) + utmp_len = -utmp_len; + if (utmp_len >= sizeof(remote_hostname)) + utmp_len = sizeof(remote_hostname) - 1; break; case 'U': @@ -806,7 +811,6 @@ terminaltypeok(s) char *hostname; char host_name[MAXHOSTNAMELEN]; -char remote_hostname[UT_HOSTSIZE + 1]; extern void telnet P((int, int, char *)); @@ -860,14 +864,19 @@ doit(who) } #endif /* _SC_CRAY_SECURE_SYS */ - /* get name of connected client */ - if (realhostname(remote_hostname, sizeof remote_hostname - 1, + 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"); + remote_hostname[sizeof(remote_hostname) - 1] = '\0'; + + if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len) + strncpy(remote_hostname, inet_ntoa(who->sin_addr), + sizeof(remote_hostname) - 1); - (void) gethostname(host_name, sizeof (host_name)); + (void) gethostname(host_name, sizeof(host_name) - 1); + host_name[sizeof(host_name) - 1] = '\0'; hostname = host_name; #if defined(AUTHENTICATION) || defined(ENCRYPTION) |