From f2edea161ac6aa873065cf089629f952756fd28f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 18 Oct 2018 20:37:33 +0100 Subject: [PATCH] uxpty: give pty_backend_create a struct ssh_ttymodes. This will be applied to the pty's termios settings at creation time, superseding the default settings uxpty has always used. It works by including the new sshttymodes.h with TTYMODES_LOCAL_ONLY defined, so that modes not supported by a particular Unix system are automatically quietly ignored. Of course, a struct ssh_ttymodes always has the option of representing "please make no change to the defaults", and of course, that's precisely what is done by the one that pty_init constructs for clients that aren't calling pty_backend_create directly. --- unix/uxpty.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/unix/uxpty.c b/unix/uxpty.c index ca4d3c04..a2b01e70 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -21,8 +21,10 @@ #include #include #include +#include #include "putty.h" +#include "ssh.h" #include "tree234.h" #ifndef OMIT_UTMP @@ -739,6 +741,35 @@ static void pty_uxsel_setup(Pty *pty) uxsel_set(pty_signal_pipe[0], 1, pty_select_result); } +static void copy_ttymodes_into_termios( + struct termios *attrs, struct ssh_ttymodes modes) +{ +#define TTYMODE_CHAR(name, ssh_opcode, cc_index) { \ + if (modes.have_mode[ssh_opcode]) \ + attrs->c_cc[cc_index] = modes.mode_val[ssh_opcode]; \ + } + +#define TTYMODE_FLAG(flagval, ssh_opcode, field, flagmask) { \ + if (modes.have_mode[ssh_opcode]) { \ + attrs->c_##field##flag &= ~flagmask; \ + if (modes.mode_val[ssh_opcode]) \ + attrs->c_##field##flag |= flagval; \ + } \ + } + +#define TTYMODES_LOCAL_ONLY /* omit any that this platform doesn't know */ +#include "sshttymodes.h" + +#undef TTYMODES_LOCAL_ONLY +#undef TTYMODE_CHAR +#undef TTYMODE_FLAG + + if (modes.have_mode[TTYMODE_ISPEED]) + cfsetispeed(attrs, modes.mode_val[TTYMODE_ISPEED]); + if (modes.have_mode[TTYMODE_OSPEED]) + cfsetospeed(attrs, modes.mode_val[TTYMODE_OSPEED]); +} + /* * The main setup function for the pty back end. This doesn't match * the signature of backend_init(), partly because it has to be able @@ -748,7 +779,8 @@ static void pty_uxsel_setup(Pty *pty) * and port numbers. */ Backend *pty_backend_create( - Seat *seat, LogContext *logctx, Conf *conf, char **argv) + Seat *seat, LogContext *logctx, Conf *conf, char **argv, + struct ssh_ttymodes ttymodes) { int slavefd; pid_t pid, pgrp; @@ -902,6 +934,8 @@ Backend *pty_backend_create( attrs.c_iflag &= ~IUTF8; #endif + copy_ttymodes_into_termios(&attrs, ttymodes); + tcsetattr(0, TCSANOW, &attrs); } @@ -1058,7 +1092,9 @@ static const char *pty_init(Seat *seat, Backend **backend_handle, const char *host, int port, char **realhost, int nodelay, int keepalive) { - *backend_handle= pty_backend_create(seat, logctx, conf, pty_argv); + struct ssh_ttymodes modes; + memset(&modes, 0, sizeof(modes)); + *backend_handle= pty_backend_create(seat, logctx, conf, pty_argv, modes); *realhost = dupstr(""); return NULL; }