xref: /csrg-svn/libexec/telnetd/termstat.c (revision 57212)
138905Sborman /*
238905Sborman  * Copyright (c) 1989 Regents of the University of California.
338905Sborman  * All rights reserved.
438905Sborman  *
542673Sbostic  * %sccs.include.redist.c%
638905Sborman  */
738905Sborman 
838905Sborman #ifndef lint
9*57212Sdab static char sccsid[] = "@(#)termstat.c	5.11 (Berkeley) 12/18/92";
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
52*57212Sdab  *		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,
83*57212Sdab  *	   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
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 	 */
14244365Sborman 	if (his_state_is_will(TELOPT_LFLOW)) {
14338905Sborman 		if (tty_flowmode() != flowmode) {
14438905Sborman 			flowmode = tty_flowmode();
14538905Sborman 			(void) sprintf(nfrontp, "%c%c%c%c%c%c", IAC, SB,
146*57212Sdab 				TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF,
147*57212Sdab 				IAC, SE);
14838905Sborman 			nfrontp += 6;
149*57212Sdab 			restartany = tty_restartany();
150*57212Sdab 			if (restartany >= 0) {
151*57212Sdab 				(void) sprintf(nfrontp, "%c%c%c%c%c%c",
152*57212Sdab 					IAC, SB, TELOPT_LFLOW,
153*57212Sdab 					restartany ? LFLOW_RESTART_ANY
154*57212Sdab 						   : LFLOW_RESTART_XON,
155*57212Sdab 					IAC, SE);
156*57212Sdab 			}
157*57212Sdab 			nfrontp += 6;
15838905Sborman 		}
15938905Sborman 	}
16038905Sborman 
16138905Sborman 	/*
16238905Sborman 	 * Check linemode on/off state
16338905Sborman 	 */
16438905Sborman 	uselinemode = tty_linemode();
16538905Sborman 
16638905Sborman 	/*
16738905Sborman 	 * If alwayslinemode is on, and pty is changing to turn it off, then
16838905Sborman 	 * force linemode back on.
16938905Sborman 	 */
17038905Sborman 	if (alwayslinemode && linemode && !uselinemode) {
17138905Sborman 		uselinemode = 1;
17238905Sborman 		tty_setlinemode(uselinemode);
17338905Sborman 	}
17438905Sborman 
175*57212Sdab #if	defined(ENCRYPTION)
17638905Sborman 	/*
17747611Sdab 	 * If the terminal is not echoing, but editing is enabled,
17847611Sdab 	 * something like password input is going to happen, so
17947611Sdab 	 * if we the other side is not currently sending encrypted
18047611Sdab 	 * data, ask the other side to start encrypting.
18147611Sdab 	 */
18247611Sdab 	if (his_state_is_will(TELOPT_ENCRYPT)) {
18347611Sdab 		static int enc_passwd = 0;
18447611Sdab 		if (uselinemode && !tty_isecho() && tty_isediting()
18547611Sdab 		    && (enc_passwd == 0) && !decrypt_input) {
18647611Sdab 			encrypt_send_request_start();
18747611Sdab 			enc_passwd = 1;
18847611Sdab 		} else if (enc_passwd) {
18947611Sdab 			encrypt_send_request_end();
19047611Sdab 			enc_passwd = 0;
19147611Sdab 		}
19247611Sdab 	}
19347611Sdab #endif
19447611Sdab 
19547611Sdab 	/*
19638905Sborman 	 * Do echo mode handling as soon as we know what the
19738905Sborman 	 * linemode is going to be.
19838905Sborman 	 * If the pty has echo turned off, then tell the client that
19938905Sborman 	 * the server will echo.  If echo is on, then the server
20038905Sborman 	 * will echo if in character mode, but in linemode the
20138905Sborman 	 * client should do local echoing.  The state machine will
20238905Sborman 	 * not send anything if it is unnecessary, so don't worry
20338905Sborman 	 * about that here.
20446809Sdab 	 *
20546809Sdab 	 * If we need to send the WILL ECHO (because echo is off),
20646809Sdab 	 * then delay that until after we have changed the MODE.
20746809Sdab 	 * This way, when the user is turning off both editing
20846809Sdab 	 * and echo, the client will get editing turned off first.
20946809Sdab 	 * This keeps the client from going into encryption mode
21046809Sdab 	 * and then right back out if it is doing auto-encryption
21146809Sdab 	 * when passwords are being typed.
21238905Sborman 	 */
21345234Sborman 	if (uselinemode) {
21445234Sborman 		if (tty_isecho())
21545234Sborman 			send_wont(TELOPT_ECHO, 1);
21645234Sborman 		else
21746809Sdab 			need_will_echo = 1;
218*57212Sdab #ifdef	KLUDGELINEMODE
219*57212Sdab 		if (lmodetype == KLUDGE_OK)
220*57212Sdab 			lmodetype = KLUDGE_LINEMODE;
221*57212Sdab #endif
22245234Sborman 	}
22338905Sborman 
22438905Sborman 	/*
22538905Sborman 	 * If linemode is being turned off, send appropriate
22638905Sborman 	 * command and then we're all done.
22738905Sborman 	 */
22838905Sborman 	 if (!uselinemode && linemode) {
22938905Sborman # ifdef	KLUDGELINEMODE
23046809Sdab 		if (lmodetype == REAL_LINEMODE) {
23138905Sborman # endif	/* KLUDGELINEMODE */
23239503Sborman 			send_dont(TELOPT_LINEMODE, 1);
23338905Sborman # ifdef	KLUDGELINEMODE
23446809Sdab 		} else if (lmodetype == KLUDGE_LINEMODE)
23539531Sborman 			send_will(TELOPT_SGA, 1);
23638905Sborman # endif	/* KLUDGELINEMODE */
23746809Sdab 		send_will(TELOPT_ECHO, 1);
23838905Sborman 		linemode = uselinemode;
23938905Sborman 		goto done;
24038905Sborman 	}
24138905Sborman 
24238905Sborman # ifdef	KLUDGELINEMODE
24338905Sborman 	/*
24438905Sborman 	 * If using real linemode check edit modes for possible later use.
24544365Sborman 	 * If we are in kludge linemode, do the SGA negotiation.
24638905Sborman 	 */
24738905Sborman 	if (lmodetype == REAL_LINEMODE) {
24838905Sborman # endif	/* KLUDGELINEMODE */
24938905Sborman 		useeditmode = 0;
25038905Sborman 		if (tty_isediting())
25138905Sborman 			useeditmode |= MODE_EDIT;
25238905Sborman 		if (tty_istrapsig())
25338905Sborman 			useeditmode |= MODE_TRAPSIG;
25444365Sborman 		if (tty_issofttab())
25544365Sborman 			useeditmode |= MODE_SOFT_TAB;
25644365Sborman 		if (tty_islitecho())
25744365Sborman 			useeditmode |= MODE_LIT_ECHO;
25838905Sborman # ifdef	KLUDGELINEMODE
25944365Sborman 	} else if (lmodetype == KLUDGE_LINEMODE) {
26044365Sborman 		if (tty_isediting() && uselinemode)
26144365Sborman 			send_wont(TELOPT_SGA, 1);
26244365Sborman 		else
26344365Sborman 			send_will(TELOPT_SGA, 1);
26438905Sborman 	}
26538905Sborman # endif	/* KLUDGELINEMODE */
26638905Sborman 
26738905Sborman 	/*
26838905Sborman 	 * Negotiate linemode on if pty state has changed to turn it on.
26938905Sborman 	 * Send appropriate command and send along edit mode, then all done.
27038905Sborman 	 */
27138905Sborman 	if (uselinemode && !linemode) {
27238905Sborman # ifdef	KLUDGELINEMODE
27338905Sborman 		if (lmodetype == KLUDGE_LINEMODE) {
27439503Sborman 			send_wont(TELOPT_SGA, 1);
27538905Sborman 		} else if (lmodetype == REAL_LINEMODE) {
27638905Sborman # endif	/* KLUDGELINEMODE */
27739503Sborman 			send_do(TELOPT_LINEMODE, 1);
27838905Sborman 			/* send along edit modes */
27938905Sborman 			(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB,
28038905Sborman 				TELOPT_LINEMODE, LM_MODE, useeditmode,
28138905Sborman 				IAC, SE);
28238905Sborman 			nfrontp += 7;
28338905Sborman 			editmode = useeditmode;
28438905Sborman # ifdef	KLUDGELINEMODE
28538905Sborman 		}
28638905Sborman # endif	/* KLUDGELINEMODE */
28738905Sborman 		linemode = uselinemode;
28838905Sborman 		goto done;
28938905Sborman 	}
29038905Sborman 
29138905Sborman # ifdef	KLUDGELINEMODE
29238905Sborman 	/*
29338905Sborman 	 * None of what follows is of any value if not using
29438905Sborman 	 * real linemode.
29538905Sborman 	 */
29638905Sborman 	if (lmodetype < REAL_LINEMODE)
29738905Sborman 		goto done;
29838905Sborman # endif	/* KLUDGELINEMODE */
29938905Sborman 
30045234Sborman 	if (linemode && his_state_is_will(TELOPT_LINEMODE)) {
30138905Sborman 		/*
30238905Sborman 		 * If edit mode changed, send edit mode.
30338905Sborman 		 */
30438905Sborman 		 if (useeditmode != editmode) {
30538905Sborman 			/*
30638905Sborman 			 * Send along appropriate edit mode mask.
30738905Sborman 			 */
30838905Sborman 			(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB,
30938905Sborman 				TELOPT_LINEMODE, LM_MODE, useeditmode,
31038905Sborman 				IAC, SE);
31138905Sborman 			nfrontp += 7;
31238905Sborman 			editmode = useeditmode;
31338905Sborman 		}
31438905Sborman 
31538905Sborman 
31638905Sborman 		/*
31738905Sborman 		 * Check for changes to special characters in use.
31838905Sborman 		 */
31938905Sborman 		start_slc(0);
32038905Sborman 		check_slc();
32146809Sdab 		(void) end_slc(0);
32238905Sborman 	}
32338905Sborman 
32438905Sborman done:
32546809Sdab 	if (need_will_echo)
32646809Sdab 		send_will(TELOPT_ECHO, 1);
32738905Sborman 	/*
32838905Sborman 	 * Some things should be deferred until after the pty state has
32938905Sborman 	 * been set by the local process.  Do those things that have been
33038905Sborman 	 * deferred now.  This only happens once.
33138905Sborman 	 */
33238905Sborman 	if (_terminit == 0) {
33338905Sborman 		_terminit = 1;
33438905Sborman 		defer_terminit();
33538905Sborman 	}
33638905Sborman 
33738905Sborman 	netflush();
33838905Sborman 	set_termbuf();
33938905Sborman 	return;
34038905Sborman 
34138905Sborman }  /* end of localstat */
34238905Sborman #endif	/* LINEMODE */
34338905Sborman 
34438905Sborman 
34538905Sborman /*
34638905Sborman  * clientstat
34738905Sborman  *
34838905Sborman  * Process linemode related requests from the client.
34938905Sborman  * Client can request a change to only one of linemode, editmode or slc's
35038905Sborman  * at a time, and if using kludge linemode, then only linemode may be
35138905Sborman  * affected.
35238905Sborman  */
35346809Sdab 	void
35438905Sborman clientstat(code, parm1, parm2)
35546809Sdab 	register int code, parm1, parm2;
35638905Sborman {
35738905Sborman 	void netflush();
35838905Sborman 
35938905Sborman 	/*
36038905Sborman 	 * Get a copy of terminal characteristics.
36138905Sborman 	 */
36238905Sborman 	init_termbuf();
36338905Sborman 
36438905Sborman 	/*
36538905Sborman 	 * Process request from client. code tells what it is.
36638905Sborman 	 */
36738905Sborman 	switch (code) {
36838905Sborman #ifdef	LINEMODE
36938905Sborman 	case TELOPT_LINEMODE:
37038905Sborman 		/*
37138905Sborman 		 * Don't do anything unless client is asking us to change
37238905Sborman 		 * modes.
37338905Sborman 		 */
37438905Sborman 		uselinemode = (parm1 == WILL);
37538905Sborman 		if (uselinemode != linemode) {
37638905Sborman # ifdef	KLUDGELINEMODE
37738905Sborman 			/*
37838905Sborman 			 * If using kludge linemode, make sure that
37938905Sborman 			 * we can do what the client asks.
38038905Sborman 			 * We can not turn off linemode if alwayslinemode
38139503Sborman 			 * and the ICANON bit is set.
38238905Sborman 			 */
38338905Sborman 			if (lmodetype == KLUDGE_LINEMODE) {
38439503Sborman 				if (alwayslinemode && tty_isediting()) {
38538905Sborman 					uselinemode = 1;
38638905Sborman 				}
38738905Sborman 			}
38838905Sborman 
38938905Sborman 			/*
39038905Sborman 			 * Quit now if we can't do it.
39138905Sborman 			 */
39238905Sborman 			if (uselinemode == linemode)
39338905Sborman 				return;
39438905Sborman 
39538905Sborman 			/*
39638905Sborman 			 * If using real linemode and linemode is being
39738905Sborman 			 * turned on, send along the edit mode mask.
39838905Sborman 			 */
39938905Sborman 			if (lmodetype == REAL_LINEMODE && uselinemode)
40038905Sborman # else	/* KLUDGELINEMODE */
40138905Sborman 			if (uselinemode)
40238905Sborman # endif	/* KLUDGELINEMODE */
40338905Sborman 			{
40438905Sborman 				useeditmode = 0;
40538905Sborman 				if (tty_isediting())
40638905Sborman 					useeditmode |= MODE_EDIT;
40746809Sdab 				if (tty_istrapsig)
40838905Sborman 					useeditmode |= MODE_TRAPSIG;
40944365Sborman 				if (tty_issofttab())
41044365Sborman 					useeditmode |= MODE_SOFT_TAB;
41144365Sborman 				if (tty_islitecho())
41244365Sborman 					useeditmode |= MODE_LIT_ECHO;
41338905Sborman 				(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC,
41438905Sborman 					SB, TELOPT_LINEMODE, LM_MODE,
41538905Sborman 							useeditmode, IAC, SE);
41638905Sborman 				nfrontp += 7;
41738905Sborman 				editmode = useeditmode;
41838905Sborman 			}
41938905Sborman 
42038905Sborman 
42138905Sborman 			tty_setlinemode(uselinemode);
42238905Sborman 
42338905Sborman 			linemode = uselinemode;
42438905Sborman 
425*57212Sdab 			if (!linemode)
426*57212Sdab 				send_will(TELOPT_ECHO, 1);
42738905Sborman 		}
42838905Sborman 		break;
42938905Sborman 
43038905Sborman 	case LM_MODE:
43138905Sborman 	    {
43244365Sborman 		register int ack, changed;
43338905Sborman 
43438905Sborman 		/*
43538905Sborman 		 * Client has sent along a mode mask.  If it agrees with
43638905Sborman 		 * what we are currently doing, ignore it; if not, it could
43738905Sborman 		 * be viewed as a request to change.  Note that the server
43838905Sborman 		 * will change to the modes in an ack if it is different from
43938905Sborman 		 * what we currently have, but we will not ack the ack.
44038905Sborman 		 */
44138905Sborman 		 useeditmode &= MODE_MASK;
44238905Sborman 		 ack = (useeditmode & MODE_ACK);
44338905Sborman 		 useeditmode &= ~MODE_ACK;
44438905Sborman 
44544365Sborman 		 if (changed = (useeditmode ^ editmode)) {
44646809Sdab 			/*
44746809Sdab 			 * This check is for a timing problem.  If the
44846809Sdab 			 * state of the tty has changed (due to the user
44946809Sdab 			 * application) we need to process that info
45046809Sdab 			 * before we write in the state contained in the
45146809Sdab 			 * ack!!!  This gets out the new MODE request,
45246809Sdab 			 * and when the ack to that command comes back
45346809Sdab 			 * we'll set it and be in the right mode.
45446809Sdab 			 */
45546809Sdab 			if (ack)
45646809Sdab 				localstat();
45744365Sborman 			if (changed & MODE_EDIT)
45844365Sborman 				tty_setedit(useeditmode & MODE_EDIT);
45938905Sborman 
46044365Sborman 			if (changed & MODE_TRAPSIG)
46144365Sborman 				tty_setsig(useeditmode & MODE_TRAPSIG);
46238905Sborman 
46344365Sborman 			if (changed & MODE_SOFT_TAB)
46444365Sborman 				tty_setsofttab(useeditmode & MODE_SOFT_TAB);
46544365Sborman 
46644365Sborman 			if (changed & MODE_LIT_ECHO)
46744365Sborman 				tty_setlitecho(useeditmode & MODE_LIT_ECHO);
46844365Sborman 
46938905Sborman 			set_termbuf();
47038905Sborman 
47138905Sborman  			if (!ack) {
47238905Sborman  				(void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC,
47338905Sborman 					SB, TELOPT_LINEMODE, LM_MODE,
47438905Sborman  					useeditmode|MODE_ACK,
47538905Sborman  					IAC, SE);
47638905Sborman  				nfrontp += 7;
47738905Sborman  			}
47838905Sborman 
47938905Sborman 			editmode = useeditmode;
48038905Sborman 		}
48138905Sborman 
48238905Sborman 		break;
48338905Sborman 
48438905Sborman 	    }  /* end of case LM_MODE */
48538905Sborman #endif	/* LINEMODE */
48638905Sborman 
48738905Sborman 	case TELOPT_NAWS:
48838905Sborman #ifdef	TIOCSWINSZ
48938905Sborman 	    {
49038905Sborman 		struct winsize ws;
49138905Sborman 
49246809Sdab 		def_col = parm1;
49346809Sdab 		def_row = parm2;
49438905Sborman #ifdef	LINEMODE
49538905Sborman 		/*
49638905Sborman 		 * Defer changing window size until after terminal is
49738905Sborman 		 * initialized.
49838905Sborman 		 */
49946809Sdab 		if (terminit() == 0)
50038905Sborman 			return;
50138905Sborman #endif	/* LINEMODE */
50238905Sborman 
50338905Sborman 		/*
50438905Sborman 		 * Change window size as requested by client.
50538905Sborman 		 */
50638905Sborman 
50738905Sborman 		ws.ws_col = parm1;
50838905Sborman 		ws.ws_row = parm2;
50938905Sborman 		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
51038905Sborman 	    }
51138905Sborman #endif	/* TIOCSWINSZ */
51238905Sborman 
51338905Sborman 		break;
51438905Sborman 
51538905Sborman 	case TELOPT_TSPEED:
51638905Sborman 	    {
51746809Sdab 		def_tspeed = parm1;
51846809Sdab 		def_rspeed = parm2;
51938905Sborman #ifdef	LINEMODE
52038905Sborman 		/*
52138905Sborman 		 * Defer changing the terminal speed.
52238905Sborman 		 */
52346809Sdab 		if (terminit() == 0)
52438905Sborman 			return;
52538905Sborman #endif	/* LINEMODE */
52638905Sborman 		/*
52738905Sborman 		 * Change terminal speed as requested by client.
52846809Sdab 		 * We set the receive speed first, so that if we can't
52946809Sdab 		 * store seperate receive and transmit speeds, the transmit
53046809Sdab 		 * speed will take precedence.
53138905Sborman 		 */
53246809Sdab 		tty_rspeed(parm2);
53338905Sborman 		tty_tspeed(parm1);
53438905Sborman 		set_termbuf();
53538905Sborman 
53638905Sborman 		break;
53738905Sborman 
53838905Sborman 	    }  /* end of case TELOPT_TSPEED */
53938905Sborman 
54038905Sborman 	default:
54138905Sborman 		/* What? */
54238905Sborman 		break;
54338905Sborman 	}  /* end of switch */
54438905Sborman 
54540242Sborman #if	defined(CRAY2) && defined(UNICOS5)
54638905Sborman 	/*
54738905Sborman 	 * Just in case of the likely event that we changed the pty state.
54838905Sborman 	 */
54938905Sborman 	rcv_ioctl();
55040242Sborman #endif	/* defined(CRAY2) && defined(UNICOS5) */
55138905Sborman 
55238905Sborman 	netflush();
55338905Sborman 
55438905Sborman }  /* end of clientstat */
55538905Sborman 
55640242Sborman #if	defined(CRAY2) && defined(UNICOS5)
55746809Sdab 	void
55838905Sborman termstat()
55938905Sborman {
56038905Sborman 	needtermstat = 1;
56138905Sborman }
56238905Sborman 
56346809Sdab 	void
56438905Sborman _termstat()
56538905Sborman {
56638905Sborman 	needtermstat = 0;
56738905Sborman 	init_termbuf();
56838905Sborman 	localstat();
56938905Sborman 	rcv_ioctl();
57038905Sborman }
57140242Sborman #endif	/* defined(CRAY2) && defined(UNICOS5) */
57238905Sborman 
57338905Sborman #ifdef	LINEMODE
57438905Sborman /*
57538905Sborman  * defer_terminit
57638905Sborman  *
57738905Sborman  * Some things should not be done until after the login process has started
57838905Sborman  * and all the pty modes are set to what they are supposed to be.  This
57938905Sborman  * function is called when the pty state has been processed for the first time.
58038905Sborman  * It calls other functions that do things that were deferred in each module.
58138905Sborman  */
58246809Sdab 	void
58338905Sborman defer_terminit()
58438905Sborman {
58538905Sborman 
58638905Sborman 	/*
58738905Sborman 	 * local stuff that got deferred.
58838905Sborman 	 */
58938905Sborman 	if (def_tspeed != -1) {
59038905Sborman 		clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);
59138905Sborman 		def_tspeed = def_rspeed = 0;
59238905Sborman 	}
59338905Sborman 
59438905Sborman #ifdef	TIOCSWINSZ
59538905Sborman 	if (def_col || def_row) {
59638905Sborman 		struct winsize ws;
59738905Sborman 
59846809Sdab 		bzero((char *)&ws, sizeof(ws));
59938905Sborman 		ws.ws_col = def_col;
60038905Sborman 		ws.ws_row = def_row;
60138905Sborman 		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
60238905Sborman 	}
60338905Sborman #endif
60438905Sborman 
60538905Sborman 	/*
60638905Sborman 	 * The only other module that currently defers anything.
60738905Sborman 	 */
60838905Sborman 	deferslc();
60938905Sborman 
61038905Sborman }  /* end of defer_terminit */
61138905Sborman 
61238905Sborman /*
61338905Sborman  * terminit
61438905Sborman  *
61538905Sborman  * Returns true if the pty state has been processed yet.
61638905Sborman  */
61746809Sdab 	int
61846809Sdab terminit()
61938905Sborman {
620*57212Sdab 	return(_terminit);
62138905Sborman 
62238905Sborman }  /* end of terminit */
62338905Sborman #endif	/* LINEMODE */
624