2020-10-18 14:32:01 +03:00
|
|
|
/* $OpenBSD: ttymodes.c,v 1.35 2020/10/18 11:32:02 djm Exp $ */
|
1999-10-27 07:42:43 +04:00
|
|
|
/*
|
1999-11-24 16:26:21 +03:00
|
|
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
2000-09-16 06:29:08 +04:00
|
|
|
*
|
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
1999-11-24 16:26:21 +03:00
|
|
|
*/
|
1999-10-27 07:42:43 +04:00
|
|
|
|
2001-04-15 03:13:02 +04:00
|
|
|
/*
|
|
|
|
* SSH2 tty modes support by Kevin Steves.
|
|
|
|
* Copyright (c) 2001 Kevin Steves. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encoding and decoding of terminal modes in a portable way.
|
|
|
|
* Much of the format is defined in ttymodes.h; it is included multiple times
|
|
|
|
* into this file with the appropriate macro definitions to generate the
|
|
|
|
* suitable code.
|
|
|
|
*/
|
|
|
|
|
1999-10-27 07:42:43 +04:00
|
|
|
#include "includes.h"
|
2006-03-15 03:11:28 +03:00
|
|
|
|
2006-08-05 06:39:39 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-07-12 16:22:46 +04:00
|
|
|
#include <errno.h>
|
2006-07-24 08:13:33 +04:00
|
|
|
#include <string.h>
|
2006-03-15 03:11:28 +03:00
|
|
|
#include <termios.h>
|
2006-08-05 06:39:39 +04:00
|
|
|
#include <stdarg.h>
|
1999-10-27 07:42:43 +04:00
|
|
|
|
|
|
|
#include "packet.h"
|
2001-01-22 08:34:40 +03:00
|
|
|
#include "log.h"
|
2001-04-15 03:13:02 +04:00
|
|
|
#include "compat.h"
|
2018-07-10 00:20:26 +03:00
|
|
|
#include "sshbuf.h"
|
|
|
|
#include "ssherr.h"
|
1999-10-27 07:42:43 +04:00
|
|
|
|
2001-04-15 03:13:02 +04:00
|
|
|
#define TTY_OP_END 0
|
|
|
|
/*
|
2017-05-01 02:26:54 +03:00
|
|
|
* uint32 (u_int) follows speed.
|
2001-04-15 03:13:02 +04:00
|
|
|
*/
|
2017-05-01 02:26:54 +03:00
|
|
|
#define TTY_OP_ISPEED 128
|
|
|
|
#define TTY_OP_OSPEED 129
|
1999-10-27 07:42:43 +04:00
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/*
|
|
|
|
* Converts POSIX speed_t to a baud rate. The values of the
|
|
|
|
* constants for speed_t are not themselves portable.
|
|
|
|
*/
|
2000-04-16 05:18:38 +04:00
|
|
|
static int
|
1999-11-24 16:26:21 +03:00
|
|
|
speed_to_baud(speed_t speed)
|
1999-10-27 07:42:43 +04:00
|
|
|
{
|
1999-11-24 16:26:21 +03:00
|
|
|
switch (speed) {
|
|
|
|
case B0:
|
|
|
|
return 0;
|
|
|
|
case B50:
|
|
|
|
return 50;
|
|
|
|
case B75:
|
|
|
|
return 75;
|
|
|
|
case B110:
|
|
|
|
return 110;
|
|
|
|
case B134:
|
|
|
|
return 134;
|
|
|
|
case B150:
|
|
|
|
return 150;
|
|
|
|
case B200:
|
|
|
|
return 200;
|
|
|
|
case B300:
|
|
|
|
return 300;
|
|
|
|
case B600:
|
|
|
|
return 600;
|
|
|
|
case B1200:
|
|
|
|
return 1200;
|
|
|
|
case B1800:
|
|
|
|
return 1800;
|
|
|
|
case B2400:
|
|
|
|
return 2400;
|
|
|
|
case B4800:
|
|
|
|
return 4800;
|
|
|
|
case B9600:
|
|
|
|
return 9600;
|
1999-10-27 07:42:43 +04:00
|
|
|
|
|
|
|
#ifdef B19200
|
1999-11-24 16:26:21 +03:00
|
|
|
case B19200:
|
|
|
|
return 19200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#else /* B19200 */
|
|
|
|
#ifdef EXTA
|
1999-11-24 16:26:21 +03:00
|
|
|
case EXTA:
|
|
|
|
return 19200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* EXTA */
|
|
|
|
#endif /* B19200 */
|
|
|
|
|
|
|
|
#ifdef B38400
|
1999-11-24 16:26:21 +03:00
|
|
|
case B38400:
|
|
|
|
return 38400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#else /* B38400 */
|
|
|
|
#ifdef EXTB
|
1999-11-24 16:26:21 +03:00
|
|
|
case EXTB:
|
|
|
|
return 38400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* EXTB */
|
|
|
|
#endif /* B38400 */
|
|
|
|
|
|
|
|
#ifdef B7200
|
1999-11-24 16:26:21 +03:00
|
|
|
case B7200:
|
|
|
|
return 7200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B7200 */
|
|
|
|
#ifdef B14400
|
1999-11-24 16:26:21 +03:00
|
|
|
case B14400:
|
|
|
|
return 14400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B14400 */
|
|
|
|
#ifdef B28800
|
1999-11-24 16:26:21 +03:00
|
|
|
case B28800:
|
|
|
|
return 28800;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B28800 */
|
|
|
|
#ifdef B57600
|
1999-11-24 16:26:21 +03:00
|
|
|
case B57600:
|
|
|
|
return 57600;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B57600 */
|
|
|
|
#ifdef B76800
|
1999-11-24 16:26:21 +03:00
|
|
|
case B76800:
|
|
|
|
return 76800;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B76800 */
|
|
|
|
#ifdef B115200
|
1999-11-24 16:26:21 +03:00
|
|
|
case B115200:
|
|
|
|
return 115200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B115200 */
|
|
|
|
#ifdef B230400
|
1999-11-24 16:26:21 +03:00
|
|
|
case B230400:
|
|
|
|
return 230400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B230400 */
|
1999-11-24 16:26:21 +03:00
|
|
|
default:
|
|
|
|
return 9600;
|
|
|
|
}
|
1999-10-27 07:42:43 +04:00
|
|
|
}
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/*
|
|
|
|
* Converts a numeric baud rate to a POSIX speed_t.
|
|
|
|
*/
|
2000-04-16 05:18:38 +04:00
|
|
|
static speed_t
|
1999-11-24 16:26:21 +03:00
|
|
|
baud_to_speed(int baud)
|
1999-10-27 07:42:43 +04:00
|
|
|
{
|
1999-11-24 16:26:21 +03:00
|
|
|
switch (baud) {
|
2001-04-15 03:13:02 +04:00
|
|
|
case 0:
|
1999-11-24 16:26:21 +03:00
|
|
|
return B0;
|
|
|
|
case 50:
|
|
|
|
return B50;
|
|
|
|
case 75:
|
|
|
|
return B75;
|
|
|
|
case 110:
|
|
|
|
return B110;
|
|
|
|
case 134:
|
|
|
|
return B134;
|
|
|
|
case 150:
|
|
|
|
return B150;
|
|
|
|
case 200:
|
|
|
|
return B200;
|
|
|
|
case 300:
|
|
|
|
return B300;
|
|
|
|
case 600:
|
|
|
|
return B600;
|
|
|
|
case 1200:
|
|
|
|
return B1200;
|
|
|
|
case 1800:
|
|
|
|
return B1800;
|
|
|
|
case 2400:
|
|
|
|
return B2400;
|
|
|
|
case 4800:
|
|
|
|
return B4800;
|
|
|
|
case 9600:
|
|
|
|
return B9600;
|
1999-10-27 07:42:43 +04:00
|
|
|
|
|
|
|
#ifdef B19200
|
1999-11-24 16:26:21 +03:00
|
|
|
case 19200:
|
|
|
|
return B19200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#else /* B19200 */
|
|
|
|
#ifdef EXTA
|
1999-11-24 16:26:21 +03:00
|
|
|
case 19200:
|
|
|
|
return EXTA;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* EXTA */
|
|
|
|
#endif /* B19200 */
|
|
|
|
|
|
|
|
#ifdef B38400
|
1999-11-24 16:26:21 +03:00
|
|
|
case 38400:
|
|
|
|
return B38400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#else /* B38400 */
|
|
|
|
#ifdef EXTB
|
1999-11-24 16:26:21 +03:00
|
|
|
case 38400:
|
|
|
|
return EXTB;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* EXTB */
|
|
|
|
#endif /* B38400 */
|
|
|
|
|
|
|
|
#ifdef B7200
|
1999-11-24 16:26:21 +03:00
|
|
|
case 7200:
|
|
|
|
return B7200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B7200 */
|
|
|
|
#ifdef B14400
|
1999-11-24 16:26:21 +03:00
|
|
|
case 14400:
|
|
|
|
return B14400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B14400 */
|
|
|
|
#ifdef B28800
|
1999-11-24 16:26:21 +03:00
|
|
|
case 28800:
|
|
|
|
return B28800;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B28800 */
|
|
|
|
#ifdef B57600
|
1999-11-24 16:26:21 +03:00
|
|
|
case 57600:
|
|
|
|
return B57600;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B57600 */
|
|
|
|
#ifdef B76800
|
1999-11-24 16:26:21 +03:00
|
|
|
case 76800:
|
|
|
|
return B76800;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B76800 */
|
|
|
|
#ifdef B115200
|
1999-11-24 16:26:21 +03:00
|
|
|
case 115200:
|
|
|
|
return B115200;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B115200 */
|
|
|
|
#ifdef B230400
|
1999-11-24 16:26:21 +03:00
|
|
|
case 230400:
|
|
|
|
return B230400;
|
1999-10-27 07:42:43 +04:00
|
|
|
#endif /* B230400 */
|
1999-11-24 16:26:21 +03:00
|
|
|
default:
|
|
|
|
return B9600;
|
|
|
|
}
|
1999-10-27 07:42:43 +04:00
|
|
|
}
|
|
|
|
|
2005-08-16 15:32:09 +04:00
|
|
|
/*
|
|
|
|
* Encode a special character into SSH line format.
|
|
|
|
*/
|
|
|
|
static u_int
|
|
|
|
special_char_encode(cc_t c)
|
|
|
|
{
|
|
|
|
#ifdef _POSIX_VDISABLE
|
|
|
|
if (c == _POSIX_VDISABLE)
|
|
|
|
return 255;
|
|
|
|
#endif /* _POSIX_VDISABLE */
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a special character from SSH line format.
|
|
|
|
*/
|
|
|
|
static cc_t
|
|
|
|
special_char_decode(u_int c)
|
|
|
|
{
|
|
|
|
#ifdef _POSIX_VDISABLE
|
|
|
|
if (c == 255)
|
|
|
|
return _POSIX_VDISABLE;
|
|
|
|
#endif /* _POSIX_VDISABLE */
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/*
|
|
|
|
* Encodes terminal modes for the terminal referenced by fd
|
2001-04-15 03:13:02 +04:00
|
|
|
* or tiop in a portable manner, and appends the modes to a packet
|
1999-11-24 16:26:21 +03:00
|
|
|
* being constructed.
|
|
|
|
*/
|
2000-04-16 05:18:38 +04:00
|
|
|
void
|
2018-07-10 00:20:26 +03:00
|
|
|
ssh_tty_make_modes(struct ssh *ssh, int fd, struct termios *tiop)
|
1999-10-27 07:42:43 +04:00
|
|
|
{
|
1999-11-24 16:26:21 +03:00
|
|
|
struct termios tio;
|
2018-07-10 00:20:26 +03:00
|
|
|
struct sshbuf *buf;
|
|
|
|
int r, ibaud, obaud;
|
1999-11-24 16:26:21 +03:00
|
|
|
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((buf = sshbuf_new()) == NULL)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_f("sshbuf_new failed");
|
2001-04-15 03:13:02 +04:00
|
|
|
|
|
|
|
if (tiop == NULL) {
|
2008-06-08 06:53:20 +04:00
|
|
|
if (fd == -1) {
|
2020-10-18 14:32:01 +03:00
|
|
|
debug_f("no fd or tio");
|
2008-06-08 06:53:20 +04:00
|
|
|
goto end;
|
|
|
|
}
|
2001-04-15 03:13:02 +04:00
|
|
|
if (tcgetattr(fd, &tio) == -1) {
|
2003-04-09 14:59:48 +04:00
|
|
|
logit("tcgetattr: %.100s", strerror(errno));
|
2001-04-15 03:13:02 +04:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
tio = *tiop;
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/* Store input and output baud rates. */
|
2018-07-10 00:20:26 +03:00
|
|
|
obaud = speed_to_baud(cfgetospeed(&tio));
|
|
|
|
ibaud = speed_to_baud(cfgetispeed(&tio));
|
|
|
|
if ((r = sshbuf_put_u8(buf, TTY_OP_OSPEED)) != 0 ||
|
|
|
|
(r = sshbuf_put_u32(buf, obaud)) != 0 ||
|
|
|
|
(r = sshbuf_put_u8(buf, TTY_OP_ISPEED)) != 0 ||
|
|
|
|
(r = sshbuf_put_u32(buf, ibaud)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "compose");
|
1999-11-24 16:26:21 +03:00
|
|
|
|
|
|
|
/* Store values of mode flags. */
|
1999-10-27 07:42:43 +04:00
|
|
|
#define TTYCHAR(NAME, OP) \
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((r = sshbuf_put_u8(buf, OP)) != 0 || \
|
|
|
|
(r = sshbuf_put_u32(buf, \
|
|
|
|
special_char_encode(tio.c_cc[NAME]))) != 0) \
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "compose %s", #NAME);
|
2001-04-15 03:13:02 +04:00
|
|
|
|
2018-02-16 07:43:11 +03:00
|
|
|
#define SSH_TTYMODE_IUTF8 42 /* for SSH_BUG_UTF8TTYMODE */
|
|
|
|
|
1999-10-27 07:42:43 +04:00
|
|
|
#define TTYMODE(NAME, FIELD, OP) \
|
2018-02-16 07:43:11 +03:00
|
|
|
if (OP == SSH_TTYMODE_IUTF8 && (datafellows & SSH_BUG_UTF8TTYMODE)) { \
|
2020-10-18 14:32:01 +03:00
|
|
|
debug3_f("SSH_BUG_UTF8TTYMODE"); \
|
2018-07-10 00:20:26 +03:00
|
|
|
} else if ((r = sshbuf_put_u8(buf, OP)) != 0 || \
|
|
|
|
(r = sshbuf_put_u32(buf, ((tio.FIELD & NAME) != 0))) != 0) \
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "compose %s", #NAME);
|
1999-10-27 07:42:43 +04:00
|
|
|
|
|
|
|
#include "ttymodes.h"
|
|
|
|
|
|
|
|
#undef TTYCHAR
|
|
|
|
#undef TTYMODE
|
|
|
|
|
2001-04-15 03:13:02 +04:00
|
|
|
end:
|
1999-11-24 16:26:21 +03:00
|
|
|
/* Mark end of mode data. */
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((r = sshbuf_put_u8(buf, TTY_OP_END)) != 0 ||
|
|
|
|
(r = sshpkt_put_stringb(ssh, buf)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "compose end");
|
2018-07-10 00:20:26 +03:00
|
|
|
sshbuf_free(buf);
|
1999-10-27 07:42:43 +04:00
|
|
|
}
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/*
|
|
|
|
* Decodes terminal modes for the terminal referenced by fd in a portable
|
|
|
|
* manner from a packet being read.
|
|
|
|
*/
|
2000-04-16 05:18:38 +04:00
|
|
|
void
|
2018-07-10 00:20:26 +03:00
|
|
|
ssh_tty_parse_modes(struct ssh *ssh, int fd)
|
1999-10-27 07:42:43 +04:00
|
|
|
{
|
1999-11-24 16:26:21 +03:00
|
|
|
struct termios tio;
|
2018-07-10 00:20:26 +03:00
|
|
|
struct sshbuf *buf;
|
|
|
|
const u_char *data;
|
|
|
|
u_char opcode;
|
|
|
|
u_int baud, u;
|
|
|
|
int r, failure = 0;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if ((r = sshpkt_get_string_direct(ssh, &data, &len)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse");
|
2018-07-10 00:20:26 +03:00
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
if ((buf = sshbuf_from(data, len)) == NULL) {
|
2020-10-18 14:32:01 +03:00
|
|
|
error_f("sshbuf_from failed");
|
2017-05-01 02:13:25 +03:00
|
|
|
return;
|
2018-07-10 00:20:26 +03:00
|
|
|
}
|
1999-11-24 16:26:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get old attributes for the terminal. We will modify these
|
|
|
|
* flags. I am hoping that if there are any machine-specific
|
|
|
|
* modes, they will initially have reasonable values.
|
|
|
|
*/
|
2001-04-15 03:13:02 +04:00
|
|
|
if (tcgetattr(fd, &tio) == -1) {
|
2003-04-09 14:59:48 +04:00
|
|
|
logit("tcgetattr: %.100s", strerror(errno));
|
1999-11-24 16:26:21 +03:00
|
|
|
failure = -1;
|
2001-04-15 03:13:02 +04:00
|
|
|
}
|
1999-11-24 16:26:21 +03:00
|
|
|
|
2018-07-10 00:20:26 +03:00
|
|
|
while (sshbuf_len(buf) > 0) {
|
|
|
|
if ((r = sshbuf_get_u8(buf, &opcode)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse opcode");
|
1999-11-24 16:26:21 +03:00
|
|
|
switch (opcode) {
|
|
|
|
case TTY_OP_END:
|
|
|
|
goto set;
|
|
|
|
|
2017-05-01 02:26:54 +03:00
|
|
|
case TTY_OP_ISPEED:
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((r = sshbuf_get_u32(buf, &baud)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse ispeed");
|
2006-03-26 07:10:34 +04:00
|
|
|
if (failure != -1 &&
|
|
|
|
cfsetispeed(&tio, baud_to_speed(baud)) == -1)
|
1999-11-24 16:26:21 +03:00
|
|
|
error("cfsetispeed failed for %d", baud);
|
|
|
|
break;
|
|
|
|
|
2017-05-01 02:26:54 +03:00
|
|
|
case TTY_OP_OSPEED:
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((r = sshbuf_get_u32(buf, &baud)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse ospeed");
|
2006-03-26 07:10:34 +04:00
|
|
|
if (failure != -1 &&
|
|
|
|
cfsetospeed(&tio, baud_to_speed(baud)) == -1)
|
1999-11-24 16:26:21 +03:00
|
|
|
error("cfsetospeed failed for %d", baud);
|
|
|
|
break;
|
1999-10-27 07:42:43 +04:00
|
|
|
|
2001-04-15 03:13:02 +04:00
|
|
|
#define TTYCHAR(NAME, OP) \
|
2018-07-10 00:20:26 +03:00
|
|
|
case OP: \
|
|
|
|
if ((r = sshbuf_get_u32(buf, &u)) != 0) \
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse %s", #NAME); \
|
2018-07-10 00:20:26 +03:00
|
|
|
tio.c_cc[NAME] = special_char_decode(u); \
|
|
|
|
break;
|
2001-04-15 03:13:02 +04:00
|
|
|
#define TTYMODE(NAME, FIELD, OP) \
|
2018-07-10 00:20:26 +03:00
|
|
|
case OP: \
|
|
|
|
if ((r = sshbuf_get_u32(buf, &u)) != 0) \
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse %s", #NAME); \
|
2018-07-10 00:20:26 +03:00
|
|
|
if (u) \
|
|
|
|
tio.FIELD |= NAME; \
|
|
|
|
else \
|
|
|
|
tio.FIELD &= ~NAME; \
|
|
|
|
break;
|
1999-10-27 07:42:43 +04:00
|
|
|
|
|
|
|
#include "ttymodes.h"
|
|
|
|
|
|
|
|
#undef TTYCHAR
|
|
|
|
#undef TTYMODE
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
default:
|
|
|
|
debug("Ignoring unsupported tty mode opcode %d (0x%x)",
|
2001-12-21 06:45:46 +03:00
|
|
|
opcode, opcode);
|
2017-05-01 02:13:25 +03:00
|
|
|
/*
|
|
|
|
* SSH2:
|
|
|
|
* Opcodes 1 to 159 are defined to have a uint32
|
|
|
|
* argument.
|
|
|
|
* Opcodes 160 to 255 are undefined and cause parsing
|
|
|
|
* to stop.
|
|
|
|
*/
|
|
|
|
if (opcode > 0 && opcode < 160) {
|
2018-07-10 00:20:26 +03:00
|
|
|
if ((r = sshbuf_get_u32(buf, NULL)) != 0)
|
2020-10-18 14:32:01 +03:00
|
|
|
fatal_fr(r, "parse arg");
|
2017-05-01 02:13:25 +03:00
|
|
|
break;
|
1999-11-24 16:26:21 +03:00
|
|
|
} else {
|
2020-10-18 14:32:01 +03:00
|
|
|
logit_f("unknown opcode %d", opcode);
|
2017-05-01 02:13:25 +03:00
|
|
|
goto set;
|
2002-03-22 05:54:23 +03:00
|
|
|
}
|
1999-10-27 07:42:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
set:
|
2018-07-10 00:20:26 +03:00
|
|
|
len = sshbuf_len(buf);
|
|
|
|
sshbuf_free(buf);
|
|
|
|
if (len > 0) {
|
2020-10-18 14:32:01 +03:00
|
|
|
logit_f("%zu bytes left", len);
|
1999-11-24 16:26:21 +03:00
|
|
|
return; /* Don't process bytes passed */
|
|
|
|
}
|
|
|
|
if (failure == -1)
|
2001-04-15 18:25:12 +04:00
|
|
|
return; /* Packet parsed ok but tcgetattr() failed */
|
1999-10-27 07:42:43 +04:00
|
|
|
|
1999-11-24 16:26:21 +03:00
|
|
|
/* Set the new modes for the terminal. */
|
2001-04-15 03:13:02 +04:00
|
|
|
if (tcsetattr(fd, TCSANOW, &tio) == -1)
|
2003-04-09 14:59:48 +04:00
|
|
|
logit("Setting tty modes failed: %.100s", strerror(errno));
|
1999-10-27 07:42:43 +04:00
|
|
|
}
|