summaryrefslogtreecommitdiffstats
path: root/libexec/telnetd/telnetd.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-04-06 23:06:00 +0000
committerbrian <brian@FreeBSD.org>1999-04-06 23:06:00 +0000
commita77173a7cd162a0aa47a96361a70cd43d178b4f6 (patch)
tree745fbd61bf8b21361a25b2cd0184e45153a0211c /libexec/telnetd/telnetd.c
parentcf0ba219f719b19bf1fc5862d698b2713d849705 (diff)
downloadFreeBSD-src-a77173a7cd162a0aa47a96361a70cd43d178b4f6.zip
FreeBSD-src-a77173a7cd162a0aa47a96361a70cd43d178b4f6.tar.gz
Use realhostname() rather than various combinations of
gethostbyaddr() & gethostbyname(). Remove brokeness in ftpd for hosts of MAXHOSTNAMELEN length.
Diffstat (limited to 'libexec/telnetd/telnetd.c')
-rw-r--r--libexec/telnetd/telnetd.c47
1 files changed, 8 insertions, 39 deletions
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 <arpa/inet.h>
#include <sys/mman.h>
+#include <libutil.h>
+#include <utmp.h>
#if defined(_SC_CRAY_SECURE_SYS)
#include <sys/sysv.h>
@@ -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 */
OpenPOWER on IntegriCloud