From 88f6c1a7e8dcda5f7f3b7b9f5f96554a00d38afc Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 7 Apr 1999 10:17:24 +0000 Subject: MF libexec/telnetd: MAXHOSTNAMELEN & -u fixes. --- crypto/telnet/telnetd/sys_term.c | 3 +-- crypto/telnet/telnetd/telnetd.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'crypto') diff --git a/crypto/telnet/telnetd/sys_term.c b/crypto/telnet/telnetd/sys_term.c index 9c557b1..e8fc3bb 100644 --- a/crypto/telnet/telnetd/sys_term.c +++ b/crypto/telnet/telnetd/sys_term.c @@ -36,7 +36,7 @@ static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95"; #endif static const char rcsid[] = - "$Id: sys_term.c,v 1.4 1998/01/22 00:04:57 imp Exp $"; + "$Id: sys_term.c,v 1.5 1998/09/01 15:17:28 gpalmer Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -54,7 +54,6 @@ void scrub_env(void); # define PARENT_DOES_UTMP #endif -int utmp_len = MAXHOSTNAMELEN; #ifdef NEWINIT #include #else /* NEWINIT*/ diff --git a/crypto/telnet/telnetd/telnetd.c b/crypto/telnet/telnetd/telnetd.c index 76cbf59..8b4798c 100644 --- a/crypto/telnet/telnetd/telnetd.c +++ b/crypto/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) -- cgit v1.1