Skip to content

Commit 545dda2

Browse files
committed
Add ANSI processing in ssh client pty code to detect LF to CRLF mode
Whether LF should be changed to CR-LF is determined by what the remote sshd server wants. Sequences like ESC[20h is sent by sshd servers in pty ANSI mode. Unix servers usually want LF and Windows servers CR-LF. Added simple ANSI data check now for pty use in interactive mode. Need to expand to simple ANSI engine in future for processing other ANSI terminal attributes.
1 parent 522af15 commit 545dda2

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

channels.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,8 +2395,9 @@ channel_output_poll(void)
23952395
}
23962396
}
23972397
}
2398-
2399-
2398+
#ifdef WIN32_FIXME
2399+
int lftocrlf = 0;
2400+
#endif
24002401
/* -- protocol input */
24012402

24022403
/* ARGSUSED */
@@ -2452,6 +2453,17 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
24522453
}
24532454
c->local_window -= win_len;
24542455
}
2456+
2457+
#ifdef WIN32_FIXME
2458+
if ( (c->client_tty) && (data_len >= 5) ) {
2459+
if ( data[0] == '\033' ) { // escape char octal 33, decimal 27
2460+
if ( (data[1] == '[') && (data[2]== '2') && (data[3]== '0') && ( data[4]== 'h' )) {
2461+
lftocrlf = 1;
2462+
}
2463+
}
2464+
}
2465+
#endif
2466+
24552467
if (c->datagram)
24562468
buffer_put_string(&c->output, data, data_len);
24572469
else

clientloop.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,14 @@ process_escapes(Channel *c, Buffer *bin, Buffer *bout, Buffer *berr,
13201320
* and append it to the buffer.
13211321
*/
13221322
last_was_cr = (ch == '\r' || ch == '\n');
1323+
#ifdef WIN32_FIXME
1324+
extern int lftocrlf ; // defined in channels.c file's channel_input_data() function for now
1325+
if ( (lftocrlf == 1) && ( ch == '\n') ) {
1326+
// add a \r before \n if sshd server sent us ESC[20h during initial tty mode setting
1327+
buffer_put_char(bin, '\r');
1328+
bytes++;
1329+
}
1330+
#endif
13231331
buffer_put_char(bin, ch);
13241332
bytes++;
13251333
}

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
#define SSH_VERSION "OpenSSH_7.1"
44

5-
#define SSH_PORTABLE "p1 Microsoft Pragma Win32 port Sep 30 2015"
5+
#define SSH_PORTABLE "p1 Microsoft Pragma Win32 port Oct 7 2015"
66
#define SSH_RELEASE SSH_VERSION SSH_PORTABLE

0 commit comments

Comments
 (0)