blob: db772c39c7435e7f7c2e2b5b8f0b5b10e34af136 [file] [log] [blame]
markus@openbsd.org05164542016-05-04 14:22:33 +00001/* $OpenBSD: ttymodes.c,v 1.30 2016/05/04 14:22:33 markus Exp $ */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10002/*
Damien Miller95def091999-11-25 00:26:21 +11003 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
Damien Millere4340be2000-09-16 13:29:08 +11006 *
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110012 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
Ben Lindstromae8e2d32001-04-14 23:13:02 +000014/*
15 * SSH2 tty modes support by Kevin Steves.
16 * Copyright (c) 2001 Kevin Steves. All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * Encoding and decoding of terminal modes in a portable way.
41 * Much of the format is defined in ttymodes.h; it is included multiple times
42 * into this file with the appropriate macro definitions to generate the
43 * suitable code.
44 */
45
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046#include "includes.h"
Damien Miller99bd21e2006-03-15 11:11:28 +110047
Damien Millerd7834352006-08-05 12:39:39 +100048#include <sys/types.h>
49
Darren Tucker39972492006-07-12 22:22:46 +100050#include <errno.h>
Damien Millere3476ed2006-07-24 14:13:33 +100051#include <string.h>
Damien Miller99bd21e2006-03-15 11:11:28 +110052#include <termios.h>
Damien Millerd7834352006-08-05 12:39:39 +100053#include <stdarg.h>
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054
55#include "packet.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000056#include "log.h"
Ben Lindstromae8e2d32001-04-14 23:13:02 +000057#include "compat.h"
58#include "buffer.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100059
Ben Lindstromae8e2d32001-04-14 23:13:02 +000060#define TTY_OP_END 0
61/*
62 * uint32 (u_int) follows speed in SSH1 and SSH2
63 */
64#define TTY_OP_ISPEED_PROTO1 192
65#define TTY_OP_OSPEED_PROTO1 193
66#define TTY_OP_ISPEED_PROTO2 128
67#define TTY_OP_OSPEED_PROTO2 129
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068
Damien Miller95def091999-11-25 00:26:21 +110069/*
70 * Converts POSIX speed_t to a baud rate. The values of the
71 * constants for speed_t are not themselves portable.
72 */
Damien Miller4af51302000-04-16 11:18:38 +100073static int
Damien Miller95def091999-11-25 00:26:21 +110074speed_to_baud(speed_t speed)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100075{
Damien Miller95def091999-11-25 00:26:21 +110076 switch (speed) {
77 case B0:
78 return 0;
79 case B50:
80 return 50;
81 case B75:
82 return 75;
83 case B110:
84 return 110;
85 case B134:
86 return 134;
87 case B150:
88 return 150;
89 case B200:
90 return 200;
91 case B300:
92 return 300;
93 case B600:
94 return 600;
95 case B1200:
96 return 1200;
97 case B1800:
98 return 1800;
99 case B2400:
100 return 2400;
101 case B4800:
102 return 4800;
103 case B9600:
104 return 9600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105
106#ifdef B19200
Damien Miller95def091999-11-25 00:26:21 +1100107 case B19200:
108 return 19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109#else /* B19200 */
110#ifdef EXTA
Damien Miller95def091999-11-25 00:26:21 +1100111 case EXTA:
112 return 19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000113#endif /* EXTA */
114#endif /* B19200 */
115
116#ifdef B38400
Damien Miller95def091999-11-25 00:26:21 +1100117 case B38400:
118 return 38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119#else /* B38400 */
120#ifdef EXTB
Damien Miller95def091999-11-25 00:26:21 +1100121 case EXTB:
122 return 38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123#endif /* EXTB */
124#endif /* B38400 */
125
126#ifdef B7200
Damien Miller95def091999-11-25 00:26:21 +1100127 case B7200:
128 return 7200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000129#endif /* B7200 */
130#ifdef B14400
Damien Miller95def091999-11-25 00:26:21 +1100131 case B14400:
132 return 14400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000133#endif /* B14400 */
134#ifdef B28800
Damien Miller95def091999-11-25 00:26:21 +1100135 case B28800:
136 return 28800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#endif /* B28800 */
138#ifdef B57600
Damien Miller95def091999-11-25 00:26:21 +1100139 case B57600:
140 return 57600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000141#endif /* B57600 */
142#ifdef B76800
Damien Miller95def091999-11-25 00:26:21 +1100143 case B76800:
144 return 76800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000145#endif /* B76800 */
146#ifdef B115200
Damien Miller95def091999-11-25 00:26:21 +1100147 case B115200:
148 return 115200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000149#endif /* B115200 */
150#ifdef B230400
Damien Miller95def091999-11-25 00:26:21 +1100151 case B230400:
152 return 230400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153#endif /* B230400 */
Damien Miller95def091999-11-25 00:26:21 +1100154 default:
155 return 9600;
156 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000157}
158
Damien Miller95def091999-11-25 00:26:21 +1100159/*
160 * Converts a numeric baud rate to a POSIX speed_t.
161 */
Damien Miller4af51302000-04-16 11:18:38 +1000162static speed_t
Damien Miller95def091999-11-25 00:26:21 +1100163baud_to_speed(int baud)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000164{
Damien Miller95def091999-11-25 00:26:21 +1100165 switch (baud) {
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000166 case 0:
Damien Miller95def091999-11-25 00:26:21 +1100167 return B0;
168 case 50:
169 return B50;
170 case 75:
171 return B75;
172 case 110:
173 return B110;
174 case 134:
175 return B134;
176 case 150:
177 return B150;
178 case 200:
179 return B200;
180 case 300:
181 return B300;
182 case 600:
183 return B600;
184 case 1200:
185 return B1200;
186 case 1800:
187 return B1800;
188 case 2400:
189 return B2400;
190 case 4800:
191 return B4800;
192 case 9600:
193 return B9600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000194
195#ifdef B19200
Damien Miller95def091999-11-25 00:26:21 +1100196 case 19200:
197 return B19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198#else /* B19200 */
199#ifdef EXTA
Damien Miller95def091999-11-25 00:26:21 +1100200 case 19200:
201 return EXTA;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000202#endif /* EXTA */
203#endif /* B19200 */
204
205#ifdef B38400
Damien Miller95def091999-11-25 00:26:21 +1100206 case 38400:
207 return B38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208#else /* B38400 */
209#ifdef EXTB
Damien Miller95def091999-11-25 00:26:21 +1100210 case 38400:
211 return EXTB;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212#endif /* EXTB */
213#endif /* B38400 */
214
215#ifdef B7200
Damien Miller95def091999-11-25 00:26:21 +1100216 case 7200:
217 return B7200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000218#endif /* B7200 */
219#ifdef B14400
Damien Miller95def091999-11-25 00:26:21 +1100220 case 14400:
221 return B14400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000222#endif /* B14400 */
223#ifdef B28800
Damien Miller95def091999-11-25 00:26:21 +1100224 case 28800:
225 return B28800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226#endif /* B28800 */
227#ifdef B57600
Damien Miller95def091999-11-25 00:26:21 +1100228 case 57600:
229 return B57600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000230#endif /* B57600 */
231#ifdef B76800
Damien Miller95def091999-11-25 00:26:21 +1100232 case 76800:
233 return B76800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000234#endif /* B76800 */
235#ifdef B115200
Damien Miller95def091999-11-25 00:26:21 +1100236 case 115200:
237 return B115200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238#endif /* B115200 */
239#ifdef B230400
Damien Miller95def091999-11-25 00:26:21 +1100240 case 230400:
241 return B230400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242#endif /* B230400 */
Damien Miller95def091999-11-25 00:26:21 +1100243 default:
244 return B9600;
245 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000246}
247
Damien Miller95def091999-11-25 00:26:21 +1100248/*
Damien Miller1d109762005-08-16 21:32:09 +1000249 * Encode a special character into SSH line format.
250 */
251static u_int
252special_char_encode(cc_t c)
253{
254#ifdef _POSIX_VDISABLE
255 if (c == _POSIX_VDISABLE)
256 return 255;
257#endif /* _POSIX_VDISABLE */
258 return c;
259}
260
261/*
262 * Decode a special character from SSH line format.
263 */
264static cc_t
265special_char_decode(u_int c)
266{
267#ifdef _POSIX_VDISABLE
268 if (c == 255)
269 return _POSIX_VDISABLE;
270#endif /* _POSIX_VDISABLE */
271 return c;
272}
273
274/*
Damien Miller95def091999-11-25 00:26:21 +1100275 * Encodes terminal modes for the terminal referenced by fd
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000276 * or tiop in a portable manner, and appends the modes to a packet
Damien Miller95def091999-11-25 00:26:21 +1100277 * being constructed.
278 */
Damien Miller4af51302000-04-16 11:18:38 +1000279void
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000280tty_make_modes(int fd, struct termios *tiop)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000281{
Damien Miller95def091999-11-25 00:26:21 +1100282 struct termios tio;
283 int baud;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000284 Buffer buf;
285 int tty_op_ospeed, tty_op_ispeed;
286 void (*put_arg)(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000287
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000288 buffer_init(&buf);
289 if (compat20) {
290 tty_op_ospeed = TTY_OP_OSPEED_PROTO2;
291 tty_op_ispeed = TTY_OP_ISPEED_PROTO2;
292 put_arg = buffer_put_int;
293 } else {
294 tty_op_ospeed = TTY_OP_OSPEED_PROTO1;
295 tty_op_ispeed = TTY_OP_ISPEED_PROTO1;
296 put_arg = (void (*)(Buffer *, u_int)) buffer_put_char;
Damien Miller95def091999-11-25 00:26:21 +1100297 }
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000298
299 if (tiop == NULL) {
Darren Tuckerdd392642008-06-08 12:53:20 +1000300 if (fd == -1) {
301 debug("tty_make_modes: no fd or tio");
302 goto end;
303 }
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000304 if (tcgetattr(fd, &tio) == -1) {
Damien Miller996acd22003-04-09 20:59:48 +1000305 logit("tcgetattr: %.100s", strerror(errno));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000306 goto end;
307 }
308 } else
309 tio = *tiop;
310
Damien Miller95def091999-11-25 00:26:21 +1100311 /* Store input and output baud rates. */
312 baud = speed_to_baud(cfgetospeed(&tio));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000313 buffer_put_char(&buf, tty_op_ospeed);
314 buffer_put_int(&buf, baud);
Damien Miller95def091999-11-25 00:26:21 +1100315 baud = speed_to_baud(cfgetispeed(&tio));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000316 buffer_put_char(&buf, tty_op_ispeed);
317 buffer_put_int(&buf, baud);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000318
Damien Miller95def091999-11-25 00:26:21 +1100319 /* Store values of mode flags. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000320#define TTYCHAR(NAME, OP) \
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000321 buffer_put_char(&buf, OP); \
Damien Miller1d109762005-08-16 21:32:09 +1000322 put_arg(&buf, special_char_encode(tio.c_cc[NAME]));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000323
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000324#define TTYMODE(NAME, FIELD, OP) \
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000325 buffer_put_char(&buf, OP); \
326 put_arg(&buf, ((tio.FIELD & NAME) != 0));
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000327
328#include "ttymodes.h"
329
330#undef TTYCHAR
331#undef TTYMODE
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000332
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000333end:
Damien Miller95def091999-11-25 00:26:21 +1100334 /* Mark end of mode data. */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000335 buffer_put_char(&buf, TTY_OP_END);
336 if (compat20)
337 packet_put_string(buffer_ptr(&buf), buffer_len(&buf));
338 else
339 packet_put_raw(buffer_ptr(&buf), buffer_len(&buf));
340 buffer_free(&buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000341}
342
Damien Miller95def091999-11-25 00:26:21 +1100343/*
344 * Decodes terminal modes for the terminal referenced by fd in a portable
345 * manner from a packet being read.
346 */
Damien Miller4af51302000-04-16 11:18:38 +1000347void
Damien Miller95def091999-11-25 00:26:21 +1100348tty_parse_modes(int fd, int *n_bytes_ptr)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000349{
Damien Miller95def091999-11-25 00:26:21 +1100350 struct termios tio;
351 int opcode, baud;
352 int n_bytes = 0;
353 int failure = 0;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000354 u_int (*get_arg)(void);
Damien Miller2f7faf12008-07-11 17:34:35 +1000355 int arg_size;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000356
357 if (compat20) {
358 *n_bytes_ptr = packet_get_int();
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000359 if (*n_bytes_ptr == 0)
360 return;
361 get_arg = packet_get_int;
362 arg_size = 4;
363 } else {
364 get_arg = packet_get_char;
365 arg_size = 1;
366 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367
Damien Miller95def091999-11-25 00:26:21 +1100368 /*
369 * Get old attributes for the terminal. We will modify these
370 * flags. I am hoping that if there are any machine-specific
371 * modes, they will initially have reasonable values.
372 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000373 if (tcgetattr(fd, &tio) == -1) {
Damien Miller996acd22003-04-09 20:59:48 +1000374 logit("tcgetattr: %.100s", strerror(errno));
Damien Miller95def091999-11-25 00:26:21 +1100375 failure = -1;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000376 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000377
Damien Miller95def091999-11-25 00:26:21 +1100378 for (;;) {
379 n_bytes += 1;
380 opcode = packet_get_char();
381 switch (opcode) {
382 case TTY_OP_END:
383 goto set;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000384
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000385 /* XXX: future conflict possible */
386 case TTY_OP_ISPEED_PROTO1:
387 case TTY_OP_ISPEED_PROTO2:
Damien Miller95def091999-11-25 00:26:21 +1100388 n_bytes += 4;
389 baud = packet_get_int();
Damien Millera5a28592006-03-26 14:10:34 +1100390 if (failure != -1 &&
391 cfsetispeed(&tio, baud_to_speed(baud)) == -1)
Damien Miller95def091999-11-25 00:26:21 +1100392 error("cfsetispeed failed for %d", baud);
393 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000394
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000395 /* XXX: future conflict possible */
396 case TTY_OP_OSPEED_PROTO1:
397 case TTY_OP_OSPEED_PROTO2:
Damien Miller95def091999-11-25 00:26:21 +1100398 n_bytes += 4;
399 baud = packet_get_int();
Damien Millera5a28592006-03-26 14:10:34 +1100400 if (failure != -1 &&
401 cfsetospeed(&tio, baud_to_speed(baud)) == -1)
Damien Miller95def091999-11-25 00:26:21 +1100402 error("cfsetospeed failed for %d", baud);
403 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000404
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000405#define TTYCHAR(NAME, OP) \
406 case OP: \
407 n_bytes += arg_size; \
Damien Miller1d109762005-08-16 21:32:09 +1000408 tio.c_cc[NAME] = special_char_decode(get_arg()); \
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000409 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000410#define TTYMODE(NAME, FIELD, OP) \
411 case OP: \
412 n_bytes += arg_size; \
Damien Miller2f7faf12008-07-11 17:34:35 +1000413 if (get_arg()) \
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000414 tio.FIELD |= NAME; \
415 else \
416 tio.FIELD &= ~NAME; \
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000417 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000418
419#include "ttymodes.h"
420
421#undef TTYCHAR
422#undef TTYMODE
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000423
Damien Miller95def091999-11-25 00:26:21 +1100424 default:
425 debug("Ignoring unsupported tty mode opcode %d (0x%x)",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100426 opcode, opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000427 if (!compat20) {
428 /*
429 * SSH1:
430 * Opcodes 1 to 127 are defined to have
431 * a one-byte argument.
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000432 * Opcodes 128 to 159 are defined to have
433 * an integer argument.
434 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000435 if (opcode > 0 && opcode < 128) {
436 n_bytes += 1;
437 (void) packet_get_char();
438 break;
439 } else if (opcode >= 128 && opcode < 160) {
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000440 n_bytes += 4;
441 (void) packet_get_int();
442 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000443 } else {
444 /*
445 * It is a truly undefined opcode (160 to 255).
446 * We have no idea about its arguments. So we
Damien Millera5a28592006-03-26 14:10:34 +1100447 * must stop parsing. Note that some data
448 * may be left in the packet; hopefully there
449 * is nothing more coming after the mode data.
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000450 */
Damien Millera5a28592006-03-26 14:10:34 +1100451 logit("parse_tty_modes: unknown opcode %d",
452 opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000453 goto set;
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000454 }
Damien Miller95def091999-11-25 00:26:21 +1100455 } else {
456 /*
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000457 * SSH2:
Ben Lindstromac2f0032001-04-15 14:25:12 +0000458 * Opcodes 1 to 159 are defined to have
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000459 * a uint32 argument.
460 * Opcodes 160 to 255 are undefined and
461 * cause parsing to stop.
Damien Miller95def091999-11-25 00:26:21 +1100462 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000463 if (opcode > 0 && opcode < 160) {
Damien Miller95def091999-11-25 00:26:21 +1100464 n_bytes += 4;
465 (void) packet_get_int();
466 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000467 } else {
Damien Millera5a28592006-03-26 14:10:34 +1100468 logit("parse_tty_modes: unknown opcode %d",
469 opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000470 goto set;
Damien Miller95def091999-11-25 00:26:21 +1100471 }
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000472 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000473 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000474 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000475
Damien Miller95def091999-11-25 00:26:21 +1100476set:
477 if (*n_bytes_ptr != n_bytes) {
478 *n_bytes_ptr = n_bytes;
Damien Miller996acd22003-04-09 20:59:48 +1000479 logit("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d",
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000480 *n_bytes_ptr, n_bytes);
Damien Miller95def091999-11-25 00:26:21 +1100481 return; /* Don't process bytes passed */
482 }
483 if (failure == -1)
Ben Lindstromac2f0032001-04-15 14:25:12 +0000484 return; /* Packet parsed ok but tcgetattr() failed */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000485
Damien Miller95def091999-11-25 00:26:21 +1100486 /* Set the new modes for the terminal. */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000487 if (tcsetattr(fd, TCSANOW, &tio) == -1)
Damien Miller996acd22003-04-09 20:59:48 +1000488 logit("Setting tty modes failed: %.100s", strerror(errno));
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489}