xref: /csrg-svn/libexec/telnetd/termstat.c (revision 69786)
138905Sborman /*
261451Sbostic  * Copyright (c) 1989, 1993
361451Sbostic  *	The Regents of the University of California.  All rights reserved.
438905Sborman  *
542673Sbostic  * %sccs.include.redist.c%
638905Sborman  */
738905Sborman 
838905Sborman #ifndef lint
9*69786Sdab static char sccsid[] = "@(#)termstat.c	8.2 (Berkeley) 05/30/95";
1038905Sborman #endif /* not lint */
1138905Sborman 
1238905Sborman #include "telnetd.h"
1338905Sborman 
1438905Sborman /*
1538905Sborman  * local variables
1638905Sborman  */
1746809Sdab int def_tspeed = -1, def_rspeed = -1;
1846809Sdab #ifdef	TIOCSWINSZ
1946809Sdab int def_row = 0, def_col = 0;
2046809Sdab #endif
2138905Sborman #ifdef	LINEMODE
2238905Sborman static int _terminit = 0;
2346809Sdab #endif	/* LINEMODE */
2438905Sborman 
2540242Sborman #if	defined(CRAY2) && defined(UNICOS5)
2638905Sborman int	newmap = 1;	/* nonzero if \n maps to ^M^J */
2738905Sborman #endif
2838905Sborman 
2938905Sborman #ifdef	LINEMODE
3038905Sborman /*
3138905Sborman  * localstat
3238905Sborman  *
3338905Sborman  * This function handles all management of linemode.
3438905Sborman  *
3538905Sborman  * Linemode allows the client to do the local editing of data
3638905Sborman  * and send only complete lines to the server.  Linemode state is
3738905Sborman  * based on the state of the pty driver.  If the pty is set for
3838905Sborman  * external processing, then we can use linemode.  Further, if we
3938905Sborman  * can use real linemode, then we can look at the edit control bits
4038905Sborman  * in the pty to determine what editing the client should do.
4138905Sborman  *
4238905Sborman  * Linemode support uses the following state flags to keep track of
4338905Sborman  * current and desired linemode state.
4438905Sborman  *	alwayslinemode : true if -l was specified on the telnetd
4538905Sborman  * 	command line.  It means to have linemode on as much as
4638905Sborman  *	possible.
4738905Sborman  *
4838905Sborman  * 	lmodetype: signifies whether the client can
4938905Sborman  *	handle real linemode, or if use of kludgeomatic linemode
5038905Sborman  *	is preferred.  It will be set to one of the following:
5138905Sborman  *		REAL_LINEMODE : use linemode option
5257212Sdab  *		NO_KLUDGE : don't initiate kludge linemode.
5338905Sborman  *		KLUDGE_LINEMODE : use kludge linemode
5438905Sborman  *		NO_LINEMODE : client is ignorant of linemode
5538905Sborman  *
5638905Sborman  *	linemode, uselinemode : linemode is true if linemode
5738905Sborman  *	is currently on, uselinemode is the state that we wish
5838905Sborman  *	to be in.  If another function wishes to turn linemode
5938905Sborman  *	on or off, it sets or clears uselinemode.
6038905Sborman  *
6138905Sborman  *	editmode, useeditmode : like linemode/uselinemode, but
6238905Sborman  *	these contain the edit mode states (edit and trapsig).
6338905Sborman  *
6438905Sborman  * The state variables correspond to some of the state information
6538905Sborman  * in the pty.
6638905Sborman  *	linemode:
6738905Sborman  *		In real linemode, this corresponds to whether the pty
6838905Sborman  *		expects external processing of incoming data.
6938905Sborman  *		In kludge linemode, this more closely corresponds to the
7038905Sborman  *		whether normal processing is on or not.  (ICANON in
7138905Sborman  *		system V, or COOKED mode in BSD.)
7238905Sborman  *		If the -l option was specified (alwayslinemode), then
7338905Sborman  *		an attempt is made to force external processing on at
7438905Sborman  *		all times.
7538905Sborman  *
7638905Sborman  * The following heuristics are applied to determine linemode
7738905Sborman  * handling within the server.
7838905Sborman  *	1) Early on in starting up the server, an attempt is made
7938905Sborman  *	   to negotiate the linemode option.  If this succeeds
8038905Sborman  *	   then lmodetype is set to REAL_LINEMODE and all linemode
8138905Sborman  *	   processing occurs in the context of the linemode option.
8238905Sborman  *	2) If the attempt to negotiate the linemode option failed,
8357212Sdab  *	   and the "-k" (don't initiate kludge linemode) isn't set,
8438905Sborman  *	   then we try to use kludge linemode.  We test for this
8538905Sborman  *	   capability by sending "do Timing Mark".  If a positive
8638905Sborman  *	   response comes back, then we assume that the client
8738905Sborman  *	   understands kludge linemode (ech!) and the
8838905Sborman  *	   lmodetype flag is set to KLUDGE_LINEMODE.
8938905Sborman  *	3) Otherwise, linemode is not supported at all and
9038905Sborman  *	   lmodetype remains set to NO_LINEMODE (which happens
9138905Sborman  *	   to be 0 for convenience).
9238905Sborman  *	4) At any time a command arrives that implies a higher
9338905Sborman  *	   state of linemode support in the client, we move to that
9438905Sborman  *	   linemode support.
9538905Sborman  *
9638905Sborman  * A short explanation of kludge linemode is in order here.
9738905Sborman  *	1) The heuristic to determine support for kludge linemode
9838905Sborman  *	   is to send a do timing mark.  We assume that a client
9938905Sborman  *	   that supports timing marks also supports kludge linemode.
10038905Sborman  *	   A risky proposition at best.
10138905Sborman  *	2) Further negotiation of linemode is done by changing the
10238905Sborman  *	   the server's state regarding SGA.  If server will SGA,
10338905Sborman  *	   then linemode is off, if server won't SGA, then linemode
10438905Sborman  *	   is on.
10538905Sborman  */
10646809Sdab 	void
localstat()10738905Sborman localstat()
10838905Sborman {
10938905Sborman 	void netflush();
11046809Sdab 	int need_will_echo = 0;
11138905Sborman 
11244365Sborman #if	defined(CRAY2) && defined(UNICOS5)
11338905Sborman 	/*
11438905Sborman 	 * Keep track of that ol' CR/NL mapping while we're in the
11538905Sborman 	 * neighborhood.
11638905Sborman 	 */
11738905Sborman 	newmap = tty_isnewmap();
11846809Sdab #endif	/* defined(CRAY2) && defined(UNICOS5) */
11938905Sborman 
12038905Sborman 	/*
12138905Sborman 	 * Check for state of BINARY options.
12238905Sborman 	 */
12338905Sborman 	if (tty_isbinaryin()) {
12444365Sborman 		if (his_want_state_is_wont(TELOPT_BINARY))
12539503Sborman 			send_do(TELOPT_BINARY, 1);
12638905Sborman 	} else {
12744365Sborman 		if (his_want_state_is_will(TELOPT_BINARY))
12839503Sborman 			send_dont(TELOPT_BINARY, 1);
12938905Sborman 	}
13038905Sborman 
13138905Sborman 	if (tty_isbinaryout()) {
13244365Sborman 		if (my_want_state_is_wont(TELOPT_BINARY))
13339503Sborman 			send_will(TELOPT_BINARY, 1);
13438905Sborman 	} else {
13544365Sborman 		if (my_want_state_is_will(TELOPT_BINARY))
13639503Sborman 			send_wont(TELOPT_BINARY, 1);
13738905Sborman 	}
13838905Sborman 
13938905Sborman 	/*
14038905Sborman 	 * Check for changes to flow control if client supports it.
14138905Sborman 	 */
14258971Sdab 	flowstat();
14338905Sborman 
14438905Sborman 	/*
14538905Sborman 	 * Check linemode on/off state
14638905Sborman 	 */
14738905Sborman 	uselinemode = tty_linemode();
14838905Sborman 
14938905Sborman 	/*
15038905Sborman 	 * If alwayslinemode is on, and pty is changing to turn it off, then
15138905Sborman 	 * force linemode back on.
15238905Sborman 	 */
15338905Sborman 	if (alwayslinemode && linemode && !uselinemode) {
15438905Sborman 		uselinemode = 1;
15538905Sborman 		tty_setlinemode(uselinemode);
15638905Sborman 	}
15738905Sborman 
15860151Sdab #ifdef	ENCRYPTION
15938905Sborman 	/*
16047611Sdab 	 * If the terminal is not echoing, but editing is enabled,
16147611Sdab 	 * something like password input is going to happen, so
16247611Sdab 	 * if we the other side is not currently sending encrypted
16347611Sdab 	 * data, ask the other side to start encrypting.
16447611Sdab 	 */
16547611Sdab 	if (his_state_is_will(TELOPT_ENCRYPT)) {
16647611Sdab 		static int enc_passwd = 0;
16747611Sdab 		if (uselinemode && !tty_isecho() && tty_isediting()
16847611Sdab 		    && (enc_passwd == 0) && !decrypt_input) {
16947611Sdab 			encrypt_send_request_start();
17047611Sdab 			enc_passwd = 1;
17147611Sdab 		} else if (enc_passwd) {
17247611Sdab 			encrypt_send_request_end();
17347611Sdab 			enc_passwd = 0;
17447611Sdab 		}
17547611Sdab 	}
17660151Sdab #endif	/* ENCRYPTION */
17747611Sdab 
17847611Sdab 	/*
17938905Sborman 	 * Do echo mode handling as soon as we know what the
18038905Sborman 	 * linemode is going to be.
18138905Sborman 	 * If the pty has echo turned off, then tell the client that
18238905Sborman 	 * the server will echo.  If echo is on, then the server
18338905Sborman 	 * will echo if in character mode, but in linemode the
18438905Sborman 	 * client should do local echoing.  The state machine will
18538905Sborman 	 * not send anything if it is unnecessary, so don't worry
18638905Sborman 	 * about that here.
18746809Sdab 	 *
18846809Sdab 	 * If we need to send the WILL ECHO (because echo is off),
18946809Sdab 	 * then delay that until after we have changed the MODE.
19046809Sdab 	 * This way, when the user is turning off both editing
19146809Sdab 	 * and echo, the client will get editing turned off first.
19246809Sdab 	 * This keeps the client from going into encryption mode
19346809Sdab 	 * and then right back out if it is doing auto-encryption
19446809Sdab 	 * when passwords are being typed.
19538905Sborman 	 */
19645234Sborman 	if (uselinemode) {
19745234Sborman 		if (tty_isecho())
19845234Sborman 			send_wont(TELOPT_ECHO, 1);
19945234Sborman 		else
20046809Sdab 			need_will_echo = 1;
20157212Sdab #ifdef	KLUDGELINEMODE
20257212Sdab 		if (lmodetype == KLUDGE_OK)
20357212Sdab 			lmodetype = KLUDGE_LINEMODE;
20457212Sdab #endif
20545234Sborman 	}
20638905Sborman 
20738905Sborman 	/*
20838905Sborman 	 * If linemode is being turned off, send appropriate
20938905Sborman 	 * command and then we're all done.
21038905Sborman 	 */
21138905Sborman 	 if (!uselinemode && linemode) {
21238905Sborman # ifdef	KLUDGELINEMODE
21346809Sdab 		if (lmodetype == REAL_LINEMODE) {
21438905Sborman # endif	/* KLUDGELINEMODE */
21539503Sborman 			send_dont(TELOPT_LINEMODE, 1);
21638905Sborman # ifdef	KLUDGELINEMODE
21746809Sdab 		} else if (lmodetype == KLUDGE_LINEMODE)
21839531Sborman 			send_will(TELOPT_SGA, 1);
21938905Sborman # endif	/* KLUDGELINEMODE */
22046809Sdab 		send_will(TELOPT_ECHO, 1);
22138905Sborman 		linemode = uselinemode;
22238905Sborman 		goto done;
22338905Sborman 	}
22438905Sborman 
22538905Sborman # ifdef	KLUDGELINEMODE
22638905Sborman 	/*
22738905Sborman 	 * If using real linemode check edit modes for possible later use.
22844365Sborman 	 * If we are in kludge linemode, do the SGA negotiation.
22938905Sborman 	 */
23038905Sborman 	if (lmodetype == REAL_LINEMODE) {
23138905Sborman # endif	/* KLUDGELINEMODE */
23238905Sborman 		useeditmode = 0;
23338905Sborman 		if (tty_isediting())
23438905Sborman 			useeditmode |= MODE_EDIT;
23538905Sborman 		if (tty_istrapsig())
23638905Sborman 			useeditmode |= MODE_TRAPSIG;
23744365Sborman 		if (tty_issofttab())
23844365Sborman 			useeditmode |= MODE_SOFT_TAB;
23944365Sborman 		if (tty_islitecho())
24044365Sborman 			useeditmode |= MODE_LIT_ECHO;
24138905Sborman # ifdef	KLUDGELINEMODE
24244365Sborman 	} else if (lmodetype == KLUDGE_LINEMODE) {
24344365Sborman 		if (tty_isediting() && uselinemode)
24444365Sborman 			send_wont(TELOPT_SGA, 1);
24544365Sborman 		else
24644365Sborman 			send_will(TELOPT_SGA, 1);
24738905Sborman 	}
24838905Sborman # endif	/* KLUDGELINEMODE */
24938905Sborman 
25038905Sborman 	/*
25138905Sborman 	 * Negotiate linemode on if pty state has changed to turn it on.
25238905Sborman 	 * Send appropriate command and send along edit mode, then all done.
25338905Sborman 	 */
25438905Sborman 	if (uselinemode && !linemode) {
25538905Sborman # ifdef	KLUDGELINEMODE
25638905Sborman 		if (lmodetype == KLUDGE_LINEMODE) {
25739503Sborman 			send_wont(TELOPT_SGA, 1);
25838905Sborman 		} else if (lmodetype == REAL_LINEMODE) {
25938905Sborman # endif	/* KLUDGELINEMODE */
26039503Sborman 			send_do(TELOPT_LINEMODE, 1);
26138905Sborman 			/* send along edit modes */
26238905Sborman 			(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB,
26338905Sborman 				TELOPT_LINEMODE, LM_MODE, useeditmode,
26438905Sborman 				IAC, SE);
26538905Sborman 			nfrontp += 7;
26638905Sborman 			editmode = useeditmode;
26738905Sborman # ifdef	KLUDGELINEMODE
26838905Sborman 		}
26938905Sborman # endif	/* KLUDGELINEMODE */
27038905Sborman 		linemode = uselinemode;
27138905Sborman 		goto done;
27238905Sborman 	}
27338905Sborman 
27438905Sborman # ifdef	KLUDGELINEMODE
27538905Sborman 	/*
27638905Sborman 	 * None of what follows is of any value if not using
27738905Sborman 	 * real linemode.
27838905Sborman 	 */
27938905Sborman 	if (lmodetype < REAL_LINEMODE)
28038905Sborman 		goto done;
28138905Sborman # endif	/* KLUDGELINEMODE */
28238905Sborman 
28345234Sborman 	if (linemode && his_state_is_will(TELOPT_LINEMODE)) {
28438905Sborman 		/*
28538905Sborman 		 * If edit mode changed, send edit mode.
28638905Sborman 		 */
28738905Sborman 		 if (useeditmode != editmode) {
28838905Sborman 			/*
28938905Sborman 			 * Send along appropriate edit mode mask.
29038905Sborman 			 */
29138905Sborman 			(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB,
29238905Sborman 				TELOPT_LINEMODE, LM_MODE, useeditmode,
29338905Sborman 				IAC, SE);
29438905Sborman 			nfrontp += 7;
29538905Sborman 			editmode = useeditmode;
29638905Sborman 		}
29738905Sborman 
298*69786Sdab 
29938905Sborman 		/*
30038905Sborman 		 * Check for changes to special characters in use.
30138905Sborman 		 */
30238905Sborman 		start_slc(0);
30338905Sborman 		check_slc();
30446809Sdab 		(void) end_slc(0);
30538905Sborman 	}
30638905Sborman 
30738905Sborman done:
30846809Sdab 	if (need_will_echo)
30946809Sdab 		send_will(TELOPT_ECHO, 1);
31038905Sborman 	/*
31138905Sborman 	 * Some things should be deferred until after the pty state has
31238905Sborman 	 * been set by the local process.  Do those things that have been
31338905Sborman 	 * deferred now.  This only happens once.
31438905Sborman 	 */
31538905Sborman 	if (_terminit == 0) {
31638905Sborman 		_terminit = 1;
31738905Sborman 		defer_terminit();
31838905Sborman 	}
31938905Sborman 
32038905Sborman 	netflush();
32138905Sborman 	set_termbuf();
32238905Sborman 	return;
32338905Sborman 
32438905Sborman }  /* end of localstat */
32538905Sborman #endif	/* LINEMODE */
32638905Sborman 
32758971Sdab /*
32858971Sdab  * flowstat
32958971Sdab  *
33058971Sdab  * Check for changes to flow control
33158971Sdab  */
33258971Sdab 	void
flowstat()33358971Sdab flowstat()
33458971Sdab {
33558971Sdab 	if (his_state_is_will(TELOPT_LFLOW)) {
33658971Sdab 		if (tty_flowmode() != flowmode) {
33758971Sdab 			flowmode = tty_flowmode();
33858971Sdab 			(void) sprintf(nfrontp, "%c%c%c%c%c%c",
33958971Sdab 					IAC, SB, TELOPT_LFLOW,
34058971Sdab 					flowmode ? LFLOW_ON : LFLOW_OFF,
34158971Sdab 					IAC, SE);
34258971Sdab 			nfrontp += 6;
34358971Sdab 		}
34458971Sdab 		if (tty_restartany() != restartany) {
34558971Sdab 			restartany = tty_restartany();
34658971Sdab 			(void) sprintf(nfrontp, "%c%c%c%c%c%c",
34758971Sdab 					IAC, SB, TELOPT_LFLOW,
34858971Sdab 					restartany ? LFLOW_RESTART_ANY
34958971Sdab 						   : LFLOW_RESTART_XON,
35058971Sdab 					IAC, SE);
35158971Sdab 			nfrontp += 6;
35258971Sdab 		}
35358971Sdab 	}
35458971Sdab }
35538905Sborman 
35638905Sborman /*
35738905Sborman  * clientstat
35838905Sborman  *
35938905Sborman  * Process linemode related requests from the client.
36038905Sborman  * Client can request a change to only one of linemode, editmode or slc's
36138905Sborman  * at a time, and if using kludge linemode, then only linemode may be
36238905Sborman  * affected.
36338905Sborman  */
36446809Sdab 	void
clientstat(code,parm1,parm2)36538905Sborman clientstat(code, parm1, parm2)
36646809Sdab 	register int code, parm1, parm2;
36738905Sborman {
36838905Sborman 	void netflush();
36938905Sborman 
37038905Sborman 	/*
37138905Sborman 	 * Get a copy of terminal characteristics.
37238905Sborman 	 */
37338905Sborman 	init_termbuf();
37438905Sborman 
37538905Sborman 	/*
37638905Sborman 	 * Process request from client. code tells what it is.
37738905Sborman 	 */
37838905Sborman 	switch (code) {
37938905Sborman #ifdef	LINEMODE
38038905Sborman 	case TELOPT_LINEMODE:
38138905Sborman 		/*
38238905Sborman 		 * Don't do anything unless client is asking us to change
38338905Sborman 		 * modes.
38438905Sborman 		 */
38538905Sborman 		uselinemode = (parm1 == WILL);
38638905Sborman 		if (uselinemode != linemode) {
38738905Sborman # ifdef	KLUDGELINEMODE
38838905Sborman 			/*
38938905Sborman 			 * If using kludge linemode, make sure that
39038905Sborman 			 * we can do what the client asks.
39138905Sborman 			 * We can not turn off linemode if alwayslinemode
39239503Sborman 			 * and the ICANON bit is set.
39338905Sborman 			 */
39438905Sborman 			if (lmodetype == KLUDGE_LINEMODE) {
39539503Sborman 				if (alwayslinemode && tty_isediting()) {
39638905Sborman 					uselinemode = 1;
39738905Sborman 				}
39838905Sborman 			}
399*69786Sdab 
40038905Sborman 			/*
40138905Sborman 			 * Quit now if we can't do it.
40238905Sborman 			 */
40338905Sborman 			if (uselinemode == linemode)
40438905Sborman 				return;
40538905Sborman 
40638905Sborman 			/*
40738905Sborman 			 * If using real linemode and linemode is being
40838905Sborman 			 * turned on, send along the edit mode mask.
40938905Sborman 			 */
41038905Sborman 			if (lmodetype == REAL_LINEMODE && uselinemode)
41138905Sborman # else	/* KLUDGELINEMODE */
41238905Sborman 			if (uselinemode)
41338905Sborman # endif	/* KLUDGELINEMODE */
41438905Sborman 			{
41538905Sborman 				useeditmode = 0;
41638905Sborman 				if (tty_isediting())
41738905Sborman 					useeditmode |= MODE_EDIT;
41846809Sdab 				if (tty_istrapsig)
41938905Sborman 					useeditmode |= MODE_TRAPSIG;
42044365Sborman 				if (tty_issofttab())
42144365Sborman 					useeditmode |= MODE_SOFT_TAB;
42244365Sborman 				if (tty_islitecho())
42344365Sborman 					useeditmode |= MODE_LIT_ECHO;
42438905Sborman 				(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC,
42538905Sborman 					SB, TELOPT_LINEMODE, LM_MODE,
42638905Sborman 							useeditmode, IAC, SE);
42738905Sborman 				nfrontp += 7;
42838905Sborman 				editmode = useeditmode;
42938905Sborman 			}
43038905Sborman 
43138905Sborman 
43238905Sborman 			tty_setlinemode(uselinemode);
43338905Sborman 
43438905Sborman 			linemode = uselinemode;
43538905Sborman 
43657212Sdab 			if (!linemode)
43757212Sdab 				send_will(TELOPT_ECHO, 1);
43838905Sborman 		}
43938905Sborman 		break;
440*69786Sdab 
44138905Sborman 	case LM_MODE:
44238905Sborman 	    {
44344365Sborman 		register int ack, changed;
44438905Sborman 
44538905Sborman 		/*
44638905Sborman 		 * Client has sent along a mode mask.  If it agrees with
44738905Sborman 		 * what we are currently doing, ignore it; if not, it could
44838905Sborman 		 * be viewed as a request to change.  Note that the server
44938905Sborman 		 * will change to the modes in an ack if it is different from
45038905Sborman 		 * what we currently have, but we will not ack the ack.
45138905Sborman 		 */
45238905Sborman 		 useeditmode &= MODE_MASK;
45338905Sborman 		 ack = (useeditmode & MODE_ACK);
45438905Sborman 		 useeditmode &= ~MODE_ACK;
45538905Sborman 
45644365Sborman 		 if (changed = (useeditmode ^ editmode)) {
45746809Sdab 			/*
45846809Sdab 			 * This check is for a timing problem.  If the
45946809Sdab 			 * state of the tty has changed (due to the user
46046809Sdab 			 * application) we need to process that info
46146809Sdab 			 * before we write in the state contained in the
46246809Sdab 			 * ack!!!  This gets out the new MODE request,
46346809Sdab 			 * and when the ack to that command comes back
46446809Sdab 			 * we'll set it and be in the right mode.
46546809Sdab 			 */
46646809Sdab 			if (ack)
46746809Sdab 				localstat();
46844365Sborman 			if (changed & MODE_EDIT)
46944365Sborman 				tty_setedit(useeditmode & MODE_EDIT);
47038905Sborman 
47144365Sborman 			if (changed & MODE_TRAPSIG)
47244365Sborman 				tty_setsig(useeditmode & MODE_TRAPSIG);
47338905Sborman 
47444365Sborman 			if (changed & MODE_SOFT_TAB)
47544365Sborman 				tty_setsofttab(useeditmode & MODE_SOFT_TAB);
47644365Sborman 
47744365Sborman 			if (changed & MODE_LIT_ECHO)
47844365Sborman 				tty_setlitecho(useeditmode & MODE_LIT_ECHO);
47944365Sborman 
48038905Sborman 			set_termbuf();
48138905Sborman 
48238905Sborman  			if (!ack) {
48338905Sborman  				(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC,
48438905Sborman 					SB, TELOPT_LINEMODE, LM_MODE,
48538905Sborman  					useeditmode|MODE_ACK,
48638905Sborman  					IAC, SE);
48738905Sborman  				nfrontp += 7;
48838905Sborman  			}
489*69786Sdab 
49038905Sborman 			editmode = useeditmode;
49138905Sborman 		}
49238905Sborman 
49338905Sborman 		break;
49438905Sborman 
49538905Sborman 	    }  /* end of case LM_MODE */
49638905Sborman #endif	/* LINEMODE */
49738905Sborman 
49838905Sborman 	case TELOPT_NAWS:
49938905Sborman #ifdef	TIOCSWINSZ
50038905Sborman 	    {
50138905Sborman 		struct winsize ws;
50238905Sborman 
50346809Sdab 		def_col = parm1;
50446809Sdab 		def_row = parm2;
50538905Sborman #ifdef	LINEMODE
50638905Sborman 		/*
50738905Sborman 		 * Defer changing window size until after terminal is
50838905Sborman 		 * initialized.
50938905Sborman 		 */
51046809Sdab 		if (terminit() == 0)
51138905Sborman 			return;
51238905Sborman #endif	/* LINEMODE */
51338905Sborman 
51438905Sborman 		/*
51538905Sborman 		 * Change window size as requested by client.
51638905Sborman 		 */
51738905Sborman 
51838905Sborman 		ws.ws_col = parm1;
51938905Sborman 		ws.ws_row = parm2;
52038905Sborman 		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
52138905Sborman 	    }
52238905Sborman #endif	/* TIOCSWINSZ */
523*69786Sdab 
52438905Sborman 		break;
525*69786Sdab 
52638905Sborman 	case TELOPT_TSPEED:
52738905Sborman 	    {
52846809Sdab 		def_tspeed = parm1;
52946809Sdab 		def_rspeed = parm2;
53038905Sborman #ifdef	LINEMODE
53138905Sborman 		/*
53238905Sborman 		 * Defer changing the terminal speed.
53338905Sborman 		 */
53446809Sdab 		if (terminit() == 0)
53538905Sborman 			return;
53638905Sborman #endif	/* LINEMODE */
53738905Sborman 		/*
53838905Sborman 		 * Change terminal speed as requested by client.
53946809Sdab 		 * We set the receive speed first, so that if we can't
54046809Sdab 		 * store seperate receive and transmit speeds, the transmit
54146809Sdab 		 * speed will take precedence.
54238905Sborman 		 */
54346809Sdab 		tty_rspeed(parm2);
54438905Sborman 		tty_tspeed(parm1);
54538905Sborman 		set_termbuf();
54638905Sborman 
54738905Sborman 		break;
54838905Sborman 
54938905Sborman 	    }  /* end of case TELOPT_TSPEED */
55038905Sborman 
55138905Sborman 	default:
55238905Sborman 		/* What? */
55338905Sborman 		break;
55438905Sborman 	}  /* end of switch */
55538905Sborman 
55640242Sborman #if	defined(CRAY2) && defined(UNICOS5)
55738905Sborman 	/*
55838905Sborman 	 * Just in case of the likely event that we changed the pty state.
55938905Sborman 	 */
56038905Sborman 	rcv_ioctl();
56140242Sborman #endif	/* defined(CRAY2) && defined(UNICOS5) */
56238905Sborman 
56338905Sborman 	netflush();
56438905Sborman 
56538905Sborman }  /* end of clientstat */
56638905Sborman 
56740242Sborman #if	defined(CRAY2) && defined(UNICOS5)
56846809Sdab 	void
termstat()56938905Sborman termstat()
57038905Sborman {
57138905Sborman 	needtermstat = 1;
57238905Sborman }
57338905Sborman 
57446809Sdab 	void
_termstat()57538905Sborman _termstat()
57638905Sborman {
57738905Sborman 	needtermstat = 0;
57838905Sborman 	init_termbuf();
57938905Sborman 	localstat();
58038905Sborman 	rcv_ioctl();
58138905Sborman }
58240242Sborman #endif	/* defined(CRAY2) && defined(UNICOS5) */
58338905Sborman 
58438905Sborman #ifdef	LINEMODE
58538905Sborman /*
58638905Sborman  * defer_terminit
58738905Sborman  *
58838905Sborman  * Some things should not be done until after the login process has started
58938905Sborman  * and all the pty modes are set to what they are supposed to be.  This
590*69786Sdab  * function is called when the pty state has been processed for the first time.
59138905Sborman  * It calls other functions that do things that were deferred in each module.
59238905Sborman  */
59346809Sdab 	void
defer_terminit()59438905Sborman defer_terminit()
59538905Sborman {
59638905Sborman 
59738905Sborman 	/*
59838905Sborman 	 * local stuff that got deferred.
59938905Sborman 	 */
60038905Sborman 	if (def_tspeed != -1) {
60138905Sborman 		clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);
60238905Sborman 		def_tspeed = def_rspeed = 0;
60338905Sborman 	}
60438905Sborman 
60538905Sborman #ifdef	TIOCSWINSZ
60638905Sborman 	if (def_col || def_row) {
60738905Sborman 		struct winsize ws;
60838905Sborman 
609*69786Sdab 		memset((char *)&ws, 0, sizeof(ws));
61038905Sborman 		ws.ws_col = def_col;
61138905Sborman 		ws.ws_row = def_row;
61238905Sborman 		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
61338905Sborman 	}
61438905Sborman #endif
61538905Sborman 
61638905Sborman 	/*
61738905Sborman 	 * The only other module that currently defers anything.
61838905Sborman 	 */
61938905Sborman 	deferslc();
62038905Sborman 
62138905Sborman }  /* end of defer_terminit */
62238905Sborman 
62338905Sborman /*
62438905Sborman  * terminit
62538905Sborman  *
62638905Sborman  * Returns true if the pty state has been processed yet.
62738905Sborman  */
62846809Sdab 	int
terminit()62946809Sdab terminit()
63038905Sborman {
63157212Sdab 	return(_terminit);
63238905Sborman 
63338905Sborman }  /* end of terminit */
63438905Sborman #endif	/* LINEMODE */
635