Bug 23562

Summary: [patch] telnetd(8) doesn't show message in file specified by if in gettytab.
Product: Base System Reporter: tanes73 <tanes73>
Component: binAssignee: Mark Murray <markm>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description tanes73 2000-12-15 10:20:01 UTC
Telnetd(8) said that we can use s5 style /etc/issue by using if capability, which would overide im. However, no matter how I set if=/etc/issue: in /etc/gettytab and create (with proper mode) /etc/issue, the content of /etc/issue will not be shown. However, getty does show content inside /etc/issue on console.

Fix: 

Recompile telnetd from /usr/src/libexec/telnetd (4.2 Release) and update new telnetd back into distribution.
How-To-Repeat: in /etc/gettytab add if as shown below.
:cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:if=/etc/issu
e:

create /etc/issue with mode 644 root/wheel and contain any messages such as
Hello Issue<LF>

Reboot. After the system restart, the console will display:

Hello Issue

FreeBSD/i386 (checkserv.Thailand.ncr.com) (ttyv0)

login:

Login and telnet localhost, you will see that it shows:

FreeBSD/i386 (checkserv.Thailand.ncr.com) (ttyp2)

login:

instead of

Hello Issue
login:
Comment 1 un1i 2001-02-18 22:06:25 UTC
  Hi,

the following patch adds the "issue file" capability to the telnetd
in the crypto source tree.  It is almost identical to this commit:
http://www.freebsd.org/cgi/cvsweb.cgi/src/libexec/telnetd/telnetd.c#rev1.14

(This patch also initializes altlogin to NULL.  Without this, there
can be crashes in start_login() in sys_term.c.  They only seem to
occur when telnetd is run with option -debug, though.)

Bye, Philipp


diff -u telnetd/telnetd.8 telnetd.new/telnetd.8
--- telnetd/telnetd.8	Sun Feb  4 11:44:19 2001
+++ telnetd.new/telnetd.8	Sun Feb 18 19:26:49 2001
@@ -527,10 +527,34 @@
 indicates a willingness to decrypt
 the data stream.
 .El
-.Sh ENVIRONMENT
+.Sh NOTES
+By default
+.Nm
+will read the
+.Em \&he ,
+.Em \&hn ,
+and
+.Em \&im
+capabilities from
+.Pa /etc/gettytab
+and use that information (if present) to determine
+what to display before the login: prompt. You can
+also use a System V style
+.Pa /etc/issue
+file by using the
+.Em \&if
+capability, which will override
+.Em \&im .
+The information specified in either
+.Em \&im
+or
+.Em \&if
+will be displayed to both console and remote logins.
+.\" .Sh ENVIRONMENT
 .Sh FILES
 .Bl -tag -width /usr/ucb/bftp -compact
 .It Pa /etc/services
+.It Pa /etc/gettytab
 .It Pa /etc/inittab
 (UNICOS systems only)
 .It Pa /etc/iptos
@@ -541,6 +565,7 @@
 .Sh "SEE ALSO"
 .Xr bftp 1 ,
 .Xr login 1 ,
+.Xr gettytab 5 ,
 .Xr telnet 1
 (if supported)
 .Sh STANDARDS
diff -u telnetd/telnetd.c telnetd.new/telnetd.c
--- telnetd/telnetd.c	Wed Feb  7 20:45:07 2001
+++ telnetd.new/telnetd.c	Sun Feb 18 14:48:05 2001
@@ -60,6 +60,7 @@
 #include <err.h>
 #include <arpa/inet.h>
 
+#include <sys/mman.h>
 #include <libutil.h>
 #include <utmp.h>
 
@@ -149,7 +150,7 @@
 
 int debug = 0;
 int keepalive = 1;
-char *altlogin;
+char *altlogin = NULL;
 
 void doit __P((struct sockaddr *));
 int terminaltypeok __P((char *));
@@ -958,6 +959,11 @@
 	char *HE;
 	char *HN;
 	char *IM;
+	char *IF;
+	char *if_buf;
+	int if_fd;
+	struct stat statbuf;
+
 	void netflush();
 	int nfd;
 
@@ -1157,8 +1163,11 @@
 		HE = Getstr("he", &cp);
 		HN = Getstr("hn", &cp);
 		IM = Getstr("im", &cp);
+		IF = Getstr("if", &cp);
 		if (HN && *HN)
 			(void) strlcpy(host_name, HN, sizeof(host_name));
+		if (IF && (if_fd = open(IF, O_RDONLY, 000)) != -1)
+			IM = 0;
 		if (IM == 0)
 			IM = "";
 	} else {
@@ -1168,6 +1177,14 @@
 	edithost(HE, host_name);
 	if (hostinfo && *IM)
 		putf(IM, ptyibuf2);
+	else if (IF && if_fd != -1) {
+		fstat (if_fd, &statbuf);
+		if_buf = (char *) mmap (0, statbuf.st_size, PROT_READ, 
+		    0, if_fd, 0);
+		putf(if_buf, ptyibuf2);
+		munmap (if_buf, statbuf.st_size);
+		close (if_fd);
+	}
 
 	if (pcc)
 		(void) strncat(ptyibuf2, ptyip, pcc+1);
Comment 2 Yar Tikhiy freebsd_committer freebsd_triage 2003-06-17 08:33:48 UTC
Responsible Changed
From-To: freebsd-bugs->markm

Over to the maintainer of crypto telnetd.
Comment 3 Dan Ponte 2005-10-25 20:41:19 UTC
Hi. I had opened another PR for this patch, which got closed
(understandably). It does the same thing as the above one, however this
one applies on my tree (6.0-RC1 as of yesterday).

--cut--
--- telnetd.c.orig	Sat May 21 11:28:42 2005
+++ telnetd.c	Tue Oct 25 15:28:47 2005
@@ -161,7 +161,7 @@
 	 * change resolves problem reports bin/771 and bin/1037.
 	 */
 
-	linemode=1;	/*Default to mode that works on bulk of clients*/
+	linemode = 1;	/*Default to mode that works on bulk of clients*/
 
 	while ((ch = getopt(argc, argv, valid_opts)) != -1) {
 		switch(ch) {
@@ -740,6 +740,7 @@
 	char *HE;
 	char *HN;
 	char *IM;
+	char *IF;
 	int nfd;
 
 	/*
@@ -900,20 +901,47 @@
 	 */
 
 	if (getent(defent, "default") == 1) {
-		char *cp=defstrs;
+		char *cp;
+
+		cp = defstrs;
 
 		HE = Getstr("he", &cp);
 		HN = Getstr("hn", &cp);
 		IM = Getstr("im", &cp);
+		IF = Getstr("if", &cp);
+
 		if (HN && *HN)
 			(void) strlcpy(host_name, HN, sizeof(host_name));
-		if (IM == 0)
+		else
+			gethostname(host_name, sizeof(host_name));
+
+		if (IM == NULL)
 			IM = strdup("");
+
+		if (IF != NULL) {
+			int tfd;
+			struct stat tst;
+			char *tbf;
+
+			tfd = open(IF, O_RDONLY);
+			if (tfd == -1) {
+				IF = NULL;
+			} else {
+				fstat(tfd, &tst);
+				tbf = (char*)mmap(NULL, tst.st_size, PROT_READ, 0, tfd, 0);
+				putf(tbf, ptyibuf2);
+				munmap(tbf, tst.st_size);
+				close(tfd);
+				IM = "";
+			}
+		}
+
 	} else {
 		IM = strdup(DEFAULT_IM);
 		HE = 0;
 	}
 	edithost(HE, host_name);
+		
 	if (hostinfo && *IM)
 		putf(IM, ptyibuf2);
--cut-- 

-Dan
Comment 4 Devon H. O'Dell 2005-10-25 21:59:27 UTC
This patch applies cleanly against current@ as well. It shouldn't hurt
hushlogin.
Comment 5 Mark Murray freebsd_committer freebsd_triage 2013-08-26 13:55:01 UTC
State Changed
From-To: open->closed

Stale.