From 86b43d05a8575d42daf6f77d43e5df5addce1913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Groenvall?= Date: Sat, 2 Sep 1995 13:19:22 +0000 Subject: [PATCH] If remote host name is to long to fit into utmp try to remove domain part if it does match our local domain. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@92 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/telnet/telnetd/telnetd.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/appl/telnet/telnetd/telnetd.c b/appl/telnet/telnetd/telnetd.c index 4baf0ae1a..510786846 100644 --- a/appl/telnet/telnetd/telnetd.c +++ b/appl/telnet/telnetd/telnetd.c @@ -847,9 +847,7 @@ doit(who) if (hp == NULL && 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) <= (unsigned int)((utmp_len < 0) ? -utmp_len - : utmp_len))) { + } else if (hp) { host = hp->h_name; } else { host = inet_ntoa(who->sin_addr); @@ -865,6 +863,27 @@ doit(who) (void) gethostname(host_name, sizeof (host_name)); hostname = host_name; +#define abs(x) ((x < 0) ? (-x) : x) + +#define TRIM_HOSTNAME +#ifdef TRIM_HOSTNAME + /* Only trim if too long (and possible) */ + if (strlen(remote_host_name) > abs(utmp_len)) { + char *domain = strchr(host_name, '.'); + char *p = strchr(remote_host_name, '.'); + if (domain && p && (strcmp(p, domain) == 0)) + *p = 0; /* remove domain part */ + } +#endif /* TRIM_HOSTNAME */ + + /* + * If hostname still doesn't fit utmp, use ipaddr. + */ + if (strlen(remote_host_name) > abs(utmp_len)) + strncpy(remote_host_name, + inet_ntoa(who->sin_addr), + sizeof(remote_host_name)-1); + #if defined(AUTHENTICATION) || defined(ENCRYPTION) auth_encrypt_init(hostname, host, "TELNETD", 1); #endif