summaryrefslogtreecommitdiff
path: root/ttymodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'ttymodes.c')
-rw-r--r--ttymodes.c125
1 files changed, 33 insertions, 92 deletions
diff --git a/ttymodes.c b/ttymodes.c
index db772c39c..845139635 100644
--- a/ttymodes.c
+++ b/ttymodes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ttymodes.c,v 1.30 2016/05/04 14:22:33 markus Exp $ */ 1/* $OpenBSD: ttymodes.c,v 1.32 2017/04/30 23:26:54 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -59,12 +59,10 @@
59 59
60#define TTY_OP_END 0 60#define TTY_OP_END 0
61/* 61/*
62 * uint32 (u_int) follows speed in SSH1 and SSH2 62 * uint32 (u_int) follows speed.
63 */ 63 */
64#define TTY_OP_ISPEED_PROTO1 192 64#define TTY_OP_ISPEED 128
65#define TTY_OP_OSPEED_PROTO1 193 65#define TTY_OP_OSPEED 129
66#define TTY_OP_ISPEED_PROTO2 128
67#define TTY_OP_OSPEED_PROTO2 129
68 66
69/* 67/*
70 * Converts POSIX speed_t to a baud rate. The values of the 68 * Converts POSIX speed_t to a baud rate. The values of the
@@ -282,19 +280,8 @@ tty_make_modes(int fd, struct termios *tiop)
282 struct termios tio; 280 struct termios tio;
283 int baud; 281 int baud;
284 Buffer buf; 282 Buffer buf;
285 int tty_op_ospeed, tty_op_ispeed;
286 void (*put_arg)(Buffer *, u_int);
287 283
288 buffer_init(&buf); 284 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;
297 }
298 285
299 if (tiop == NULL) { 286 if (tiop == NULL) {
300 if (fd == -1) { 287 if (fd == -1) {
@@ -310,20 +297,20 @@ tty_make_modes(int fd, struct termios *tiop)
310 297
311 /* Store input and output baud rates. */ 298 /* Store input and output baud rates. */
312 baud = speed_to_baud(cfgetospeed(&tio)); 299 baud = speed_to_baud(cfgetospeed(&tio));
313 buffer_put_char(&buf, tty_op_ospeed); 300 buffer_put_char(&buf, TTY_OP_OSPEED);
314 buffer_put_int(&buf, baud); 301 buffer_put_int(&buf, baud);
315 baud = speed_to_baud(cfgetispeed(&tio)); 302 baud = speed_to_baud(cfgetispeed(&tio));
316 buffer_put_char(&buf, tty_op_ispeed); 303 buffer_put_char(&buf, TTY_OP_ISPEED);
317 buffer_put_int(&buf, baud); 304 buffer_put_int(&buf, baud);
318 305
319 /* Store values of mode flags. */ 306 /* Store values of mode flags. */
320#define TTYCHAR(NAME, OP) \ 307#define TTYCHAR(NAME, OP) \
321 buffer_put_char(&buf, OP); \ 308 buffer_put_char(&buf, OP); \
322 put_arg(&buf, special_char_encode(tio.c_cc[NAME])); 309 buffer_put_int(&buf, special_char_encode(tio.c_cc[NAME]));
323 310
324#define TTYMODE(NAME, FIELD, OP) \ 311#define TTYMODE(NAME, FIELD, OP) \
325 buffer_put_char(&buf, OP); \ 312 buffer_put_char(&buf, OP); \
326 put_arg(&buf, ((tio.FIELD & NAME) != 0)); 313 buffer_put_int(&buf, ((tio.FIELD & NAME) != 0));
327 314
328#include "ttymodes.h" 315#include "ttymodes.h"
329 316
@@ -333,10 +320,7 @@ tty_make_modes(int fd, struct termios *tiop)
333end: 320end:
334 /* Mark end of mode data. */ 321 /* Mark end of mode data. */
335 buffer_put_char(&buf, TTY_OP_END); 322 buffer_put_char(&buf, TTY_OP_END);
336 if (compat20) 323 packet_put_string(buffer_ptr(&buf), buffer_len(&buf));
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); 324 buffer_free(&buf);
341} 325}
342 326
@@ -351,19 +335,10 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
351 int opcode, baud; 335 int opcode, baud;
352 int n_bytes = 0; 336 int n_bytes = 0;
353 int failure = 0; 337 int failure = 0;
354 u_int (*get_arg)(void); 338
355 int arg_size; 339 *n_bytes_ptr = packet_get_int();
356 340 if (*n_bytes_ptr == 0)
357 if (compat20) { 341 return;
358 *n_bytes_ptr = packet_get_int();
359 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 }
367 342
368 /* 343 /*
369 * Get old attributes for the terminal. We will modify these 344 * Get old attributes for the terminal. We will modify these
@@ -382,9 +357,7 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
382 case TTY_OP_END: 357 case TTY_OP_END:
383 goto set; 358 goto set;
384 359
385 /* XXX: future conflict possible */ 360 case TTY_OP_ISPEED:
386 case TTY_OP_ISPEED_PROTO1:
387 case TTY_OP_ISPEED_PROTO2:
388 n_bytes += 4; 361 n_bytes += 4;
389 baud = packet_get_int(); 362 baud = packet_get_int();
390 if (failure != -1 && 363 if (failure != -1 &&
@@ -392,9 +365,7 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
392 error("cfsetispeed failed for %d", baud); 365 error("cfsetispeed failed for %d", baud);
393 break; 366 break;
394 367
395 /* XXX: future conflict possible */ 368 case TTY_OP_OSPEED:
396 case TTY_OP_OSPEED_PROTO1:
397 case TTY_OP_OSPEED_PROTO2:
398 n_bytes += 4; 369 n_bytes += 4;
399 baud = packet_get_int(); 370 baud = packet_get_int();
400 if (failure != -1 && 371 if (failure != -1 &&
@@ -404,13 +375,13 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
404 375
405#define TTYCHAR(NAME, OP) \ 376#define TTYCHAR(NAME, OP) \
406 case OP: \ 377 case OP: \
407 n_bytes += arg_size; \ 378 n_bytes += 4; \
408 tio.c_cc[NAME] = special_char_decode(get_arg()); \ 379 tio.c_cc[NAME] = special_char_decode(packet_get_int()); \
409 break; 380 break;
410#define TTYMODE(NAME, FIELD, OP) \ 381#define TTYMODE(NAME, FIELD, OP) \
411 case OP: \ 382 case OP: \
412 n_bytes += arg_size; \ 383 n_bytes += 4; \
413 if (get_arg()) \ 384 if (packet_get_int()) \
414 tio.FIELD |= NAME; \ 385 tio.FIELD |= NAME; \
415 else \ 386 else \
416 tio.FIELD &= ~NAME; \ 387 tio.FIELD &= ~NAME; \
@@ -424,51 +395,21 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
424 default: 395 default:
425 debug("Ignoring unsupported tty mode opcode %d (0x%x)", 396 debug("Ignoring unsupported tty mode opcode %d (0x%x)",
426 opcode, opcode); 397 opcode, opcode);
427 if (!compat20) { 398 /*
428 /* 399 * SSH2:
429 * SSH1: 400 * Opcodes 1 to 159 are defined to have a uint32
430 * Opcodes 1 to 127 are defined to have 401 * argument.
431 * a one-byte argument. 402 * Opcodes 160 to 255 are undefined and cause parsing
432 * Opcodes 128 to 159 are defined to have 403 * to stop.
433 * an integer argument. 404 */
434 */ 405 if (opcode > 0 && opcode < 160) {
435 if (opcode > 0 && opcode < 128) { 406 n_bytes += 4;
436 n_bytes += 1; 407 (void) packet_get_int();
437 (void) packet_get_char(); 408 break;
438 break;
439 } else if (opcode >= 128 && opcode < 160) {
440 n_bytes += 4;
441 (void) packet_get_int();
442 break;
443 } else {
444 /*
445 * It is a truly undefined opcode (160 to 255).
446 * We have no idea about its arguments. So we
447 * 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.
450 */
451 logit("parse_tty_modes: unknown opcode %d",
452 opcode);
453 goto set;
454 }
455 } else { 409 } else {
456 /* 410 logit("parse_tty_modes: unknown opcode %d",
457 * SSH2: 411 opcode);
458 * Opcodes 1 to 159 are defined to have 412 goto set;
459 * a uint32 argument.
460 * Opcodes 160 to 255 are undefined and
461 * cause parsing to stop.
462 */
463 if (opcode > 0 && opcode < 160) {
464 n_bytes += 4;
465 (void) packet_get_int();
466 break;
467 } else {
468 logit("parse_tty_modes: unknown opcode %d",
469 opcode);
470 goto set;
471 }
472 } 413 }
473 } 414 }
474 } 415 }