blob: 2c95938d97f405853e39bf4b9329b7e007fe0c1a [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Millere4340be2000-09-16 13:29:08 +11005 *
6 * As far as I am concerned, the code I have written for this software
7 * can be used freely for any purpose. Any derived versions of this
8 * software must be clearly marked as such, and if the derived work is
9 * incompatible with the protocol description in the RFC file, it must be
10 * called by a name other than "ssh" or "Secure Shell".
Damien Miller95def091999-11-25 00:26:21 +110011 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100012
Ben Lindstromae8e2d32001-04-14 23:13:02 +000013/*
14 * SSH2 tty modes support by Kevin Steves.
15 * Copyright (c) 2001 Kevin Steves. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38/*
39 * Encoding and decoding of terminal modes in a portable way.
40 * Much of the format is defined in ttymodes.h; it is included multiple times
41 * into this file with the appropriate macro definitions to generate the
42 * suitable code.
43 */
44
Damien Millerd4a8b7e1999-10-27 13:42:43 +100045#include "includes.h"
Damien Miller99bd21e2006-03-15 11:11:28 +110046
47#include <termios.h>
Damien Millerd4a8b7e1999-10-27 13:42:43 +100048
49#include "packet.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000050#include "log.h"
51#include "ssh1.h"
Ben Lindstromae8e2d32001-04-14 23:13:02 +000052#include "compat.h"
53#include "buffer.h"
54#include "bufaux.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055
Ben Lindstromae8e2d32001-04-14 23:13:02 +000056#define TTY_OP_END 0
57/*
58 * uint32 (u_int) follows speed in SSH1 and SSH2
59 */
60#define TTY_OP_ISPEED_PROTO1 192
61#define TTY_OP_OSPEED_PROTO1 193
62#define TTY_OP_ISPEED_PROTO2 128
63#define TTY_OP_OSPEED_PROTO2 129
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064
Damien Miller95def091999-11-25 00:26:21 +110065/*
66 * Converts POSIX speed_t to a baud rate. The values of the
67 * constants for speed_t are not themselves portable.
68 */
Damien Miller4af51302000-04-16 11:18:38 +100069static int
Damien Miller95def091999-11-25 00:26:21 +110070speed_to_baud(speed_t speed)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100071{
Damien Miller95def091999-11-25 00:26:21 +110072 switch (speed) {
73 case B0:
74 return 0;
75 case B50:
76 return 50;
77 case B75:
78 return 75;
79 case B110:
80 return 110;
81 case B134:
82 return 134;
83 case B150:
84 return 150;
85 case B200:
86 return 200;
87 case B300:
88 return 300;
89 case B600:
90 return 600;
91 case B1200:
92 return 1200;
93 case B1800:
94 return 1800;
95 case B2400:
96 return 2400;
97 case B4800:
98 return 4800;
99 case B9600:
100 return 9600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101
102#ifdef B19200
Damien Miller95def091999-11-25 00:26:21 +1100103 case B19200:
104 return 19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105#else /* B19200 */
106#ifdef EXTA
Damien Miller95def091999-11-25 00:26:21 +1100107 case EXTA:
108 return 19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000109#endif /* EXTA */
110#endif /* B19200 */
111
112#ifdef B38400
Damien Miller95def091999-11-25 00:26:21 +1100113 case B38400:
114 return 38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000115#else /* B38400 */
116#ifdef EXTB
Damien Miller95def091999-11-25 00:26:21 +1100117 case EXTB:
118 return 38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000119#endif /* EXTB */
120#endif /* B38400 */
121
122#ifdef B7200
Damien Miller95def091999-11-25 00:26:21 +1100123 case B7200:
124 return 7200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000125#endif /* B7200 */
126#ifdef B14400
Damien Miller95def091999-11-25 00:26:21 +1100127 case B14400:
128 return 14400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000129#endif /* B14400 */
130#ifdef B28800
Damien Miller95def091999-11-25 00:26:21 +1100131 case B28800:
132 return 28800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000133#endif /* B28800 */
134#ifdef B57600
Damien Miller95def091999-11-25 00:26:21 +1100135 case B57600:
136 return 57600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#endif /* B57600 */
138#ifdef B76800
Damien Miller95def091999-11-25 00:26:21 +1100139 case B76800:
140 return 76800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000141#endif /* B76800 */
142#ifdef B115200
Damien Miller95def091999-11-25 00:26:21 +1100143 case B115200:
144 return 115200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000145#endif /* B115200 */
146#ifdef B230400
Damien Miller95def091999-11-25 00:26:21 +1100147 case B230400:
148 return 230400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000149#endif /* B230400 */
Damien Miller95def091999-11-25 00:26:21 +1100150 default:
151 return 9600;
152 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000153}
154
Damien Miller95def091999-11-25 00:26:21 +1100155/*
156 * Converts a numeric baud rate to a POSIX speed_t.
157 */
Damien Miller4af51302000-04-16 11:18:38 +1000158static speed_t
Damien Miller95def091999-11-25 00:26:21 +1100159baud_to_speed(int baud)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000160{
Damien Miller95def091999-11-25 00:26:21 +1100161 switch (baud) {
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000162 case 0:
Damien Miller95def091999-11-25 00:26:21 +1100163 return B0;
164 case 50:
165 return B50;
166 case 75:
167 return B75;
168 case 110:
169 return B110;
170 case 134:
171 return B134;
172 case 150:
173 return B150;
174 case 200:
175 return B200;
176 case 300:
177 return B300;
178 case 600:
179 return B600;
180 case 1200:
181 return B1200;
182 case 1800:
183 return B1800;
184 case 2400:
185 return B2400;
186 case 4800:
187 return B4800;
188 case 9600:
189 return B9600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000190
191#ifdef B19200
Damien Miller95def091999-11-25 00:26:21 +1100192 case 19200:
193 return B19200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000194#else /* B19200 */
195#ifdef EXTA
Damien Miller95def091999-11-25 00:26:21 +1100196 case 19200:
197 return EXTA;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000198#endif /* EXTA */
199#endif /* B19200 */
200
201#ifdef B38400
Damien Miller95def091999-11-25 00:26:21 +1100202 case 38400:
203 return B38400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000204#else /* B38400 */
205#ifdef EXTB
Damien Miller95def091999-11-25 00:26:21 +1100206 case 38400:
207 return EXTB;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000208#endif /* EXTB */
209#endif /* B38400 */
210
211#ifdef B7200
Damien Miller95def091999-11-25 00:26:21 +1100212 case 7200:
213 return B7200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000214#endif /* B7200 */
215#ifdef B14400
Damien Miller95def091999-11-25 00:26:21 +1100216 case 14400:
217 return B14400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000218#endif /* B14400 */
219#ifdef B28800
Damien Miller95def091999-11-25 00:26:21 +1100220 case 28800:
221 return B28800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000222#endif /* B28800 */
223#ifdef B57600
Damien Miller95def091999-11-25 00:26:21 +1100224 case 57600:
225 return B57600;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000226#endif /* B57600 */
227#ifdef B76800
Damien Miller95def091999-11-25 00:26:21 +1100228 case 76800:
229 return B76800;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000230#endif /* B76800 */
231#ifdef B115200
Damien Miller95def091999-11-25 00:26:21 +1100232 case 115200:
233 return B115200;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000234#endif /* B115200 */
235#ifdef B230400
Damien Miller95def091999-11-25 00:26:21 +1100236 case 230400:
237 return B230400;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000238#endif /* B230400 */
Damien Miller95def091999-11-25 00:26:21 +1100239 default:
240 return B9600;
241 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000242}
243
Damien Miller95def091999-11-25 00:26:21 +1100244/*
Damien Miller1d109762005-08-16 21:32:09 +1000245 * Encode a special character into SSH line format.
246 */
247static u_int
248special_char_encode(cc_t c)
249{
250#ifdef _POSIX_VDISABLE
251 if (c == _POSIX_VDISABLE)
252 return 255;
253#endif /* _POSIX_VDISABLE */
254 return c;
255}
256
257/*
258 * Decode a special character from SSH line format.
259 */
260static cc_t
261special_char_decode(u_int c)
262{
263#ifdef _POSIX_VDISABLE
264 if (c == 255)
265 return _POSIX_VDISABLE;
266#endif /* _POSIX_VDISABLE */
267 return c;
268}
269
270/*
Damien Miller95def091999-11-25 00:26:21 +1100271 * Encodes terminal modes for the terminal referenced by fd
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000272 * or tiop in a portable manner, and appends the modes to a packet
Damien Miller95def091999-11-25 00:26:21 +1100273 * being constructed.
274 */
Damien Miller4af51302000-04-16 11:18:38 +1000275void
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000276tty_make_modes(int fd, struct termios *tiop)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000277{
Damien Miller95def091999-11-25 00:26:21 +1100278 struct termios tio;
279 int baud;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000280 Buffer buf;
281 int tty_op_ospeed, tty_op_ispeed;
282 void (*put_arg)(Buffer *, u_int);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000283
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000284 buffer_init(&buf);
285 if (compat20) {
286 tty_op_ospeed = TTY_OP_OSPEED_PROTO2;
287 tty_op_ispeed = TTY_OP_ISPEED_PROTO2;
288 put_arg = buffer_put_int;
289 } else {
290 tty_op_ospeed = TTY_OP_OSPEED_PROTO1;
291 tty_op_ispeed = TTY_OP_ISPEED_PROTO1;
292 put_arg = (void (*)(Buffer *, u_int)) buffer_put_char;
Damien Miller95def091999-11-25 00:26:21 +1100293 }
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000294
295 if (tiop == NULL) {
296 if (tcgetattr(fd, &tio) == -1) {
Damien Miller996acd22003-04-09 20:59:48 +1000297 logit("tcgetattr: %.100s", strerror(errno));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000298 goto end;
299 }
300 } else
301 tio = *tiop;
302
Damien Miller95def091999-11-25 00:26:21 +1100303 /* Store input and output baud rates. */
304 baud = speed_to_baud(cfgetospeed(&tio));
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000305 debug3("tty_make_modes: ospeed %d", baud);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000306 buffer_put_char(&buf, tty_op_ospeed);
307 buffer_put_int(&buf, baud);
Damien Miller95def091999-11-25 00:26:21 +1100308 baud = speed_to_baud(cfgetispeed(&tio));
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000309 debug3("tty_make_modes: ispeed %d", baud);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000310 buffer_put_char(&buf, tty_op_ispeed);
311 buffer_put_int(&buf, baud);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000312
Damien Miller95def091999-11-25 00:26:21 +1100313 /* Store values of mode flags. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000314#define TTYCHAR(NAME, OP) \
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000315 debug3("tty_make_modes: %d %d", OP, tio.c_cc[NAME]); \
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000316 buffer_put_char(&buf, OP); \
Damien Miller1d109762005-08-16 21:32:09 +1000317 put_arg(&buf, special_char_encode(tio.c_cc[NAME]));
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000318
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000319#define TTYMODE(NAME, FIELD, OP) \
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000320 debug3("tty_make_modes: %d %d", OP, ((tio.FIELD & NAME) != 0)); \
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000321 buffer_put_char(&buf, OP); \
322 put_arg(&buf, ((tio.FIELD & NAME) != 0));
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000323
324#include "ttymodes.h"
325
326#undef TTYCHAR
327#undef TTYMODE
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000328
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000329end:
Damien Miller95def091999-11-25 00:26:21 +1100330 /* Mark end of mode data. */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000331 buffer_put_char(&buf, TTY_OP_END);
332 if (compat20)
333 packet_put_string(buffer_ptr(&buf), buffer_len(&buf));
334 else
335 packet_put_raw(buffer_ptr(&buf), buffer_len(&buf));
336 buffer_free(&buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000337}
338
Damien Miller95def091999-11-25 00:26:21 +1100339/*
340 * Decodes terminal modes for the terminal referenced by fd in a portable
341 * manner from a packet being read.
342 */
Damien Miller4af51302000-04-16 11:18:38 +1000343void
Damien Miller95def091999-11-25 00:26:21 +1100344tty_parse_modes(int fd, int *n_bytes_ptr)
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000345{
Damien Miller95def091999-11-25 00:26:21 +1100346 struct termios tio;
347 int opcode, baud;
348 int n_bytes = 0;
349 int failure = 0;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000350 u_int (*get_arg)(void);
351 int arg, arg_size;
352
353 if (compat20) {
354 *n_bytes_ptr = packet_get_int();
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000355 debug3("tty_parse_modes: SSH2 n_bytes %d", *n_bytes_ptr);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000356 if (*n_bytes_ptr == 0)
357 return;
358 get_arg = packet_get_int;
359 arg_size = 4;
360 } else {
361 get_arg = packet_get_char;
362 arg_size = 1;
363 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000364
Damien Miller95def091999-11-25 00:26:21 +1100365 /*
366 * Get old attributes for the terminal. We will modify these
367 * flags. I am hoping that if there are any machine-specific
368 * modes, they will initially have reasonable values.
369 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000370 if (tcgetattr(fd, &tio) == -1) {
Damien Miller996acd22003-04-09 20:59:48 +1000371 logit("tcgetattr: %.100s", strerror(errno));
Damien Miller95def091999-11-25 00:26:21 +1100372 failure = -1;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000373 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000374
Damien Miller95def091999-11-25 00:26:21 +1100375 for (;;) {
376 n_bytes += 1;
377 opcode = packet_get_char();
378 switch (opcode) {
379 case TTY_OP_END:
380 goto set;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000381
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000382 /* XXX: future conflict possible */
383 case TTY_OP_ISPEED_PROTO1:
384 case TTY_OP_ISPEED_PROTO2:
Damien Miller95def091999-11-25 00:26:21 +1100385 n_bytes += 4;
386 baud = packet_get_int();
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000387 debug3("tty_parse_modes: ispeed %d", baud);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000388 if (failure != -1 && cfsetispeed(&tio, baud_to_speed(baud)) == -1)
Damien Miller95def091999-11-25 00:26:21 +1100389 error("cfsetispeed failed for %d", baud);
390 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000391
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000392 /* XXX: future conflict possible */
393 case TTY_OP_OSPEED_PROTO1:
394 case TTY_OP_OSPEED_PROTO2:
Damien Miller95def091999-11-25 00:26:21 +1100395 n_bytes += 4;
396 baud = packet_get_int();
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000397 debug3("tty_parse_modes: ospeed %d", baud);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000398 if (failure != -1 && cfsetospeed(&tio, baud_to_speed(baud)) == -1)
Damien Miller95def091999-11-25 00:26:21 +1100399 error("cfsetospeed failed for %d", baud);
400 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000401
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000402#define TTYCHAR(NAME, OP) \
403 case OP: \
404 n_bytes += arg_size; \
Damien Miller1d109762005-08-16 21:32:09 +1000405 tio.c_cc[NAME] = special_char_decode(get_arg()); \
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000406 debug3("tty_parse_modes: %d %d", OP, tio.c_cc[NAME]); \
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000407 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000408#define TTYMODE(NAME, FIELD, OP) \
409 case OP: \
410 n_bytes += arg_size; \
411 if ((arg = get_arg())) \
412 tio.FIELD |= NAME; \
413 else \
414 tio.FIELD &= ~NAME; \
Ben Lindstrom491bbb82001-06-25 05:24:16 +0000415 debug3("tty_parse_modes: %d %d", OP, arg); \
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000416 break;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000417
418#include "ttymodes.h"
419
420#undef TTYCHAR
421#undef TTYMODE
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422
Damien Miller95def091999-11-25 00:26:21 +1100423 default:
424 debug("Ignoring unsupported tty mode opcode %d (0x%x)",
Damien Miller9f0f5c62001-12-21 14:45:46 +1100425 opcode, opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000426 if (!compat20) {
427 /*
428 * SSH1:
429 * Opcodes 1 to 127 are defined to have
430 * a one-byte argument.
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000431 * Opcodes 128 to 159 are defined to have
432 * an integer argument.
433 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000434 if (opcode > 0 && opcode < 128) {
435 n_bytes += 1;
436 (void) packet_get_char();
437 break;
438 } else if (opcode >= 128 && opcode < 160) {
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000439 n_bytes += 4;
440 (void) packet_get_int();
441 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000442 } else {
443 /*
444 * It is a truly undefined opcode (160 to 255).
445 * We have no idea about its arguments. So we
446 * must stop parsing. Note that some data may be
447 * left in the packet; hopefully there is nothing
448 * more coming after the mode data.
449 */
Damien Miller996acd22003-04-09 20:59:48 +1000450 logit("parse_tty_modes: unknown opcode %d", opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000451 goto set;
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000452 }
Damien Miller95def091999-11-25 00:26:21 +1100453 } else {
454 /*
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000455 * SSH2:
Ben Lindstromac2f0032001-04-15 14:25:12 +0000456 * Opcodes 1 to 159 are defined to have
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000457 * a uint32 argument.
458 * Opcodes 160 to 255 are undefined and
459 * cause parsing to stop.
Damien Miller95def091999-11-25 00:26:21 +1100460 */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000461 if (opcode > 0 && opcode < 160) {
Damien Miller95def091999-11-25 00:26:21 +1100462 n_bytes += 4;
463 (void) packet_get_int();
464 break;
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000465 } else {
Damien Miller996acd22003-04-09 20:59:48 +1000466 logit("parse_tty_modes: unknown opcode %d", opcode);
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000467 goto set;
Damien Miller95def091999-11-25 00:26:21 +1100468 }
Ben Lindstrom6328ab32002-03-22 02:54:23 +0000469 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000470 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000471 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000472
Damien Miller95def091999-11-25 00:26:21 +1100473set:
474 if (*n_bytes_ptr != n_bytes) {
475 *n_bytes_ptr = n_bytes;
Damien Miller996acd22003-04-09 20:59:48 +1000476 logit("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d",
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000477 *n_bytes_ptr, n_bytes);
Damien Miller95def091999-11-25 00:26:21 +1100478 return; /* Don't process bytes passed */
479 }
480 if (failure == -1)
Ben Lindstromac2f0032001-04-15 14:25:12 +0000481 return; /* Packet parsed ok but tcgetattr() failed */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000482
Damien Miller95def091999-11-25 00:26:21 +1100483 /* Set the new modes for the terminal. */
Ben Lindstromae8e2d32001-04-14 23:13:02 +0000484 if (tcsetattr(fd, TCSANOW, &tio) == -1)
Damien Miller996acd22003-04-09 20:59:48 +1000485 logit("Setting tty modes failed: %.100s", strerror(errno));
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000486}