Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 97 23:26 CST
From:      uhclem@nemesis.lonestar.org (Frank Durda IV)
To:        mpp@freefall.freebsd.org, bugs@freebsd.org, FreeBSD-gnats-submit@freebsd.org
Cc:        uhclem@nemesis.lonestar.org
Subject:   re: bin/1037 and bin/771  Patch included
Message-ID:  <m0w4gYP-000twvC@nemesis.lonestar.org>

next in thread | raw e-mail | index | archive | help
[0]Are you still seeing the problem reported in your FreeBSD problem
[0]report # 1037?  Have you tried later versions of FreeBSD, such as 
[0]FreeBSD 2.2 GAMMA or FreeBSD 3.0-current?  Any other information 
[0]you could provide would be helpful.  If you are still seeing the 
[0]problem, what version of FreeBSD are you running right now?
[0]Mike Pritchard

Regarding:
bin/1037:
Synopsis:       2.x telnetd handles CTRL-M differently than other ttys	FDIV044
bin/771:
Synopsis:	telnet character mode not set and broken when set - FDIV034


No, these items remain broken in 2.2-GAMMA, and all releases back to
at least the 2.1.0-RELEASE.  It worked correctly in 1.1.5.1.

I've been hoping somebody would quit stalling over the religious issues
here and fix this, but apparently that won't happen after a year on the
books, so here is a patch that solves the religious issue with a
technical fix:


-----FIX BEGINS-----
*** telnetd.c.00	Sun Jan 12 15:56:33 1997
--- telnetd.c	Wed Feb 26 16:07:15 1997
***************
*** 179,184 ****
--- 179,187 ----
  
  	progname = *argv;
  
+ 	linemode=1;			/*Default to mode that all brands
+ 					  of telnets handle correctly*/
+ 
  #ifdef CRAY
  	/*
  	 * Get number of pty's before trying to process options,
-----FIX ENDS-----


That's it.  The patch works on all telnetds released from 2.1.0
thru 2.2-GAMMAs and would close bin/771 and bin/1037 if applied.
It might even resolve bin/1073, but I don't have a way to test that.


Discussion

The problem was, is, and apparently will always be that starting with
2.x, telnetd has wanted to run in LINEMODE by default, because it
is more efficient in using the TCP/IP transport media than the
character-at-a-time modes used previously in 1.1.5.1 and earlier
as well as BSD 4.3.

The problem with that was, is, and will always be that not all TELNET
clients on all known platforms implement LINEMODE correctly in that
they don't know about what to do for various action (wakeup)
control-characters, such as the ones available in csh for command editing
and completion.  ^D, ^W, ^R, <ESC>, ^U, etc.   These commands break in
the presence of LINEMODE in various ways.   To demonstrate, try this simple
test.

Login into a csh session on a FreeBSD target via the console or
a serial connection and follow this command sequence:

	% set filec
	% cd /stand
	% ls i<CTRL-D>		should display
	ifconfig*
	% ls i<ESC>		should finish command string:  % ls ifconfig
	% ls ifconfig<CTRL-W>	should erase "ifconfig": % ls 
	% ls <CTRL-R>		should redraw on next line: ls
	ls f<CTRL-D>		should display
	find* fsck* ft*
	% ls fs<CTRL-D>		should finish "fsck": % ls fsck
	% ls fsck<CTRL-U>	should erase: %
	%

Now telnet into the same system (try "telnet ." if you like and
see the behavior difference).   Login as the same user and repeat
the sequence above.

I don't care if you telnet from any FreeBSD 2.x release, SCO UNIX 3.2,
DEC OSF 3.2G or 4.0B, IRIX V.4, from NETBSD 1.x, Windows '95 TELNET,
or from NCSA Telnet 2.3.07 (I've tested all of these), they will all
malfunction telnetting to FreeBSD 2.x, at least until you apply the patch.

The other aspect of the bad behavior of telnetd was shown by two different
programs provided previously, but I'll repeat one here.  This is code
pulled from an existing application written in the BSD 4.2/3 days, which
ran fine on 1.1.5.1 and works on 2.x from the console or serial
ports, but not via telnet, unless you apply the patch:

-----chars.c-----
#include <stdio.h>
#include  <sgtty.h>
#include <sys/stat.h>
extern char	*ttyname();

static	struct  stat	ttystatus;
int	stdin_isatty, stdout_isatty;
char	*ttynam_stdout;
static  struct	sgttyb	old, new;
static	struct  stat	ttystatus;
int	stdin_isatty, stdout_isatty;
char	*ttynam_stdout;

#define	EOT	'\004'
static int	eof=EOT,  killc=CTRL('U'),  erase=CTRL('H'),  werase=CTRL('W');

main()
{
	char c;
	printf("Press these keys  [T] [E] [S] [T] [Enter] [CTRL][J] [CTRL][M] [Esc]\n");
	save_tty();
	set_tty();

	while((c=getchar())!=EOF && c!=0x1b) {
		printf("%02x ",c);
	}

	restore_tty();
	printf("\nYou should see 74 65 73 74 0a 0a 0a\n");
}


save_tty()
{
	struct tchars	tc;
	struct ltchars t;

	fstat(fileno(stdout), &ttystatus);
	ttynam_stdout = ttyname(fileno(stdout));
	stdout_isatty = (ioctl(fileno(stdout), TIOCGETP, &old) >= 0);
	stdin_isatty = (ioctl(fileno(stdin), TIOCGETP, &old) >= 0);
	if (ioctl(fileno(stdin), TIOCGLTC, &t) == 0)
		werase = (int)t.t_werasc;

	killc = (int)old.sg_kill;
	erase = (int)old.sg_erase;
	if (ioctl(fileno(stdin), TIOCGETC, &tc) == 0)
		eof = (int)tc.t_eofc;

	new = old;
	new.sg_flags |= CBREAK;
	new.sg_flags &= ~ECHO;
}

set_tty()
{
	ioctl(fileno(stdin), TIOCSETN, &new);
}

restore_tty()
{
	if (stdout_isatty)
		chmod(ttynam_stdout, (int)ttystatus.st_mode&0777);
	if (stdin_isatty)
		ioctl(fileno(stdin), TIOCSETP, &old);
}

-----END of chars.c-----

Compile this program on FreeBSD, and then execute it and follow
the instructions.  Telnetting into FreeBSD 2.x without the above
patch will give incorrect results in that CTRL-J/CTRL-M entered by
the telnet user are not read as 0x0a by the program as they are when
the same program is run on a console or serial session.

Running the program with a telnetd that is patched, OR from the console
or serial ports will work correctly CTRL-M/CTRL-J both are read as 0x0a.

The program also behaves correctly when compiled and run on
the other platforms mentioned, demonstrating that the problem is in the
FreeBSD telnetd because it tries to force a mode that the clients can't
handle correctly.


All the patch does is instruct telnetd to negotiate a character mode by
default that all of the above telnet clients handle correctly.
If the user wants additional link efficiency at the cost of the
problems shown above, then by all means he/she can switch to
LINEMODE once the telnet connection is started if that mode can be used.
No feature or capability is taken away by the patch.

Yes, we could simply have everybody using every telnet client
everywhere have to turn off LINEMODE each time they use telnet
to a FreeBSD platform in order for existing shells and applications
to work via telnet.  This is the religious argument that all the
clients everywhere are broken and the FreeBSD telnetd isn't.
Sorry, but I don't buy this.  We must fit in with the rest of the
universe.

It still seems that the default setting should provide maximum
compatibility, which is the case with this patch installed.


I recommend that this change be included in 2.2-RELEASE.


Frank Durda IV <uhclem@nemesis.lonestar.org>|"The Knights who say "LETNi"
or uhclem%nemesis@rwsystr.nkn.net           | demand...  A SEGMENT REGISTER!!!"
					    |"A what?"
or ...letni!rwsys!nemesis!uhclem	    |"LETNi! LETNi! LETNi!"  - 1983




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m0w4gYP-000twvC>