From cbdfedff948b1abba807747327d02e9b8f146196 Mon Sep 17 00:00:00 2001 From: quamrulmina Date: Thu, 19 Nov 2015 00:35:59 -0600 Subject: [PATCH] sshd sets ssh client tty mode to original state after a tty session has ended this is a needed step for our sshd in tty mode as we ask clients to send us CRLF as command terminator. But we must reset the mode when the tty session ends so that sftp running after it does not encounter CRLF mode. Linux openssh sftp client otherwise would show two lines for each command typed when run after an ssh session to our server. --- nchan.c | 18 +++++++++++++++++- serverloop.c | 7 ------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/nchan.c b/nchan.c index 804519e..8d9d132 100644 --- a/nchan.c +++ b/nchan.c @@ -187,8 +187,24 @@ chan_ibuf_empty(Channel *c) switch (c->istate) { case CHAN_INPUT_WAIT_DRAIN: if (compat20) { - if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL))) + if (!(c->flags & (CHAN_CLOSE_SENT | CHAN_LOCAL))) { + #ifdef WIN32_FIXME + // reset the other side if tty to be how it was before + if (c->isatty) { + char *inittermseq = + "\033[?7h" // end-of-line autowrap ON mode + "\033[20l"; // force NewLineMode off + + buffer_append(&c->input, inittermseq, strlen(inittermseq)); + int state = c->istate; + c->istate = CHAN_INPUT_WAIT_DRAIN; + channel_output_poll(); + packet_write_poll(); // packet_write_wait(); + c->istate = state; + } + #endif chan_send_eof2(c); + } chan_set_istate(c, CHAN_INPUT_CLOSED); } else { chan_send_ieof1(c); diff --git a/serverloop.c b/serverloop.c index b59fa1e..f5ee00f 100644 --- a/serverloop.c +++ b/serverloop.c @@ -880,13 +880,6 @@ collect_children(void) process = s->pid; - // send the other side terminal to be how it was before if it was tty - if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) { - char *inittermseq = "\033[20l\033[?7h\0" ; // no LFtoCRLF no AUTOWRAPON - Channel *c=channel_by_id ( s->chanid ); - buffer_append(&c->input, inittermseq, strlen(inittermseq)); - packet_write_poll(); - } session_close_by_pid(s->pid, status); if (s->pid)