summaryrefslogtreecommitdiff
path: root/ttymodes.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-04-30 23:13:25 +0000
committerDamien Miller <djm@mindrot.org>2017-05-01 09:42:37 +1000
commit97f4d3083b036ce3e68d6346a6140a22123d5864 (patch)
tree301c95453934721eca9855cd01b1d0da089e3246 /ttymodes.c
parent99f95ba82673d33215dce17bfa1512b57f54ec09 (diff)
upstream commit
remove compat20/compat13/compat15 variables ok markus@ Upstream-ID: 43802c035ceb3fef6c50c400e4ecabf12354691c
Diffstat (limited to 'ttymodes.c')
-rw-r--r--ttymodes.c106
1 files changed, 28 insertions, 78 deletions
diff --git a/ttymodes.c b/ttymodes.c
index db772c39c..2fc783b2f 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.31 2017/04/30 23:13:25 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
@@ -283,18 +283,10 @@ tty_make_modes(int fd, struct termios *tiop)
283 int baud; 283 int baud;
284 Buffer buf; 284 Buffer buf;
285 int tty_op_ospeed, tty_op_ispeed; 285 int tty_op_ospeed, tty_op_ispeed;
286 void (*put_arg)(Buffer *, u_int);
287 286
288 buffer_init(&buf); 287 buffer_init(&buf);
289 if (compat20) { 288 tty_op_ospeed = TTY_OP_OSPEED_PROTO2;
290 tty_op_ospeed = TTY_OP_OSPEED_PROTO2; 289 tty_op_ispeed = TTY_OP_ISPEED_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 290
299 if (tiop == NULL) { 291 if (tiop == NULL) {
300 if (fd == -1) { 292 if (fd == -1) {
@@ -319,11 +311,11 @@ tty_make_modes(int fd, struct termios *tiop)
319 /* Store values of mode flags. */ 311 /* Store values of mode flags. */
320#define TTYCHAR(NAME, OP) \ 312#define TTYCHAR(NAME, OP) \
321 buffer_put_char(&buf, OP); \ 313 buffer_put_char(&buf, OP); \
322 put_arg(&buf, special_char_encode(tio.c_cc[NAME])); 314 buffer_put_int(&buf, special_char_encode(tio.c_cc[NAME]));
323 315
324#define TTYMODE(NAME, FIELD, OP) \ 316#define TTYMODE(NAME, FIELD, OP) \
325 buffer_put_char(&buf, OP); \ 317 buffer_put_char(&buf, OP); \
326 put_arg(&buf, ((tio.FIELD & NAME) != 0)); 318 buffer_put_int(&buf, ((tio.FIELD & NAME) != 0));
327 319
328#include "ttymodes.h" 320#include "ttymodes.h"
329 321
@@ -333,10 +325,7 @@ tty_make_modes(int fd, struct termios *tiop)
333end: 325end:
334 /* Mark end of mode data. */ 326 /* Mark end of mode data. */
335 buffer_put_char(&buf, TTY_OP_END); 327 buffer_put_char(&buf, TTY_OP_END);
336 if (compat20) 328 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); 329 buffer_free(&buf);
341} 330}
342 331
@@ -351,19 +340,10 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
351 int opcode, baud; 340 int opcode, baud;
352 int n_bytes = 0; 341 int n_bytes = 0;
353 int failure = 0; 342 int failure = 0;
354 u_int (*get_arg)(void); 343
355 int arg_size; 344 *n_bytes_ptr = packet_get_int();
356 345 if (*n_bytes_ptr == 0)
357 if (compat20) { 346 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 347
368 /* 348 /*
369 * Get old attributes for the terminal. We will modify these 349 * Get old attributes for the terminal. We will modify these
@@ -404,13 +384,13 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
404 384
405#define TTYCHAR(NAME, OP) \ 385#define TTYCHAR(NAME, OP) \
406 case OP: \ 386 case OP: \
407 n_bytes += arg_size; \ 387 n_bytes += 4; \
408 tio.c_cc[NAME] = special_char_decode(get_arg()); \ 388 tio.c_cc[NAME] = special_char_decode(packet_get_int()); \
409 break; 389 break;
410#define TTYMODE(NAME, FIELD, OP) \ 390#define TTYMODE(NAME, FIELD, OP) \
411 case OP: \ 391 case OP: \
412 n_bytes += arg_size; \ 392 n_bytes += 4; \
413 if (get_arg()) \ 393 if (packet_get_int()) \
414 tio.FIELD |= NAME; \ 394 tio.FIELD |= NAME; \
415 else \ 395 else \
416 tio.FIELD &= ~NAME; \ 396 tio.FIELD &= ~NAME; \
@@ -424,51 +404,21 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
424 default: 404 default:
425 debug("Ignoring unsupported tty mode opcode %d (0x%x)", 405 debug("Ignoring unsupported tty mode opcode %d (0x%x)",
426 opcode, opcode); 406 opcode, opcode);
427 if (!compat20) { 407 /*
428 /* 408 * SSH2:
429 * SSH1: 409 * Opcodes 1 to 159 are defined to have a uint32
430 * Opcodes 1 to 127 are defined to have 410 * argument.
431 * a one-byte argument. 411 * Opcodes 160 to 255 are undefined and cause parsing
432 * Opcodes 128 to 159 are defined to have 412 * to stop.
433 * an integer argument. 413 */
434 */ 414 if (opcode > 0 && opcode < 160) {
435 if (opcode > 0 && opcode < 128) { 415 n_bytes += 4;
436 n_bytes += 1; 416 (void) packet_get_int();
437 (void) packet_get_char(); 417 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 { 418 } else {
456 /* 419 logit("parse_tty_modes: unknown opcode %d",
457 * SSH2: 420 opcode);
458 * Opcodes 1 to 159 are defined to have 421 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 } 422 }
473 } 423 }
474 } 424 }