Skip to content

Commit cbdfedf

Browse files
committed
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.
1 parent 5b34ab6 commit cbdfedf

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

nchan.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,24 @@ chan_ibuf_empty(Channel *c)
187187
switch (c->istate) {
188188
case CHAN_INPUT_WAIT_DRAIN:
189189
if (compat20) {
190-
if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL)))
190+
if (!(c->flags & (CHAN_CLOSE_SENT | CHAN_LOCAL))) {
191+
#ifdef WIN32_FIXME
192+
// reset the other side if tty to be how it was before
193+
if (c->isatty) {
194+
char *inittermseq =
195+
"\033[?7h" // end-of-line autowrap ON mode
196+
"\033[20l"; // force NewLineMode off
197+
198+
buffer_append(&c->input, inittermseq, strlen(inittermseq));
199+
int state = c->istate;
200+
c->istate = CHAN_INPUT_WAIT_DRAIN;
201+
channel_output_poll();
202+
packet_write_poll(); // packet_write_wait();
203+
c->istate = state;
204+
}
205+
#endif
191206
chan_send_eof2(c);
207+
}
192208
chan_set_istate(c, CHAN_INPUT_CLOSED);
193209
} else {
194210
chan_send_ieof1(c);

serverloop.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,6 @@ collect_children(void)
880880

881881
process = s->pid;
882882

883-
// send the other side terminal to be how it was before if it was tty
884-
if ( (!s -> is_subsystem) && (s ->ttyfd != -1)) {
885-
char *inittermseq = "\033[20l\033[?7h\0" ; // no LFtoCRLF no AUTOWRAPON
886-
Channel *c=channel_by_id ( s->chanid );
887-
buffer_append(&c->input, inittermseq, strlen(inittermseq));
888-
packet_write_poll();
889-
}
890883
session_close_by_pid(s->pid, status);
891884

892885
if (s->pid)

0 commit comments

Comments
 (0)