Skip to content

Commit d4c8ef9

Browse files
committed
Improved SSH client interactive mode and fixed control-c to work
Console API is now used for interactive tty mode. Thus ssh.exe client can now pass each character to remote side as one types so that programs like more works correctly. Control-c now will stop the remote program instead of exiting the ssh.exe.
1 parent 1c258ec commit d4c8ef9

File tree

8 files changed

+845
-16
lines changed

8 files changed

+845
-16
lines changed

channels.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,10 @@ channel_handle_rfd(Channel *c, fd_set *readset, fd_set *writeset)
16851685
if (c->rfd != -1 && (force || FD_ISSET(c->rfd, readset))) {
16861686
errno = 0;
16871687
len = read(c->rfd, buf, sizeof(buf));
1688+
#ifdef WIN32_FIXME
1689+
if (len == 0)
1690+
return 1; // in Win32 console read, there may be no data, but is ok
1691+
#endif
16881692
if (len < 0 && (errno == EINTR ||
16891693
((errno == EAGAIN || errno == EWOULDBLOCK) && !force)))
16901694
return 1;
@@ -2395,9 +2399,7 @@ channel_output_poll(void)
23952399
}
23962400
}
23972401
}
2398-
#ifdef WIN32_FIXME
2399-
int lftocrlf = 0;
2400-
#endif
2402+
24012403
/* -- protocol input */
24022404

24032405
/* ARGSUSED */

clientloop.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,14 +1348,14 @@ process_escapes(Channel *c, Buffer *bin, Buffer *bout, Buffer *berr,
13481348
* and append it to the buffer.
13491349
*/
13501350
last_was_cr = (ch == '\r' || ch == '\n');
1351-
#ifdef WIN32_FIXME
1352-
extern int lftocrlf ; // defined in channels.c file's channel_input_data() function for now
1353-
if ( (lftocrlf == 1) && ( ch == '\n') ) {
1351+
//#ifdef WIN32_FIXME
1352+
//extern int lftocrlf ; // defined in channels.c file's channel_input_data() function for now
1353+
//if ( (lftocrlf == 1) && ( ch == '\n') ) {
13541354
// add a \r before \n if sshd server sent us ESC[20h during initial tty mode setting
1355-
buffer_put_char(bin, '\r');
1356-
bytes++;
1357-
}
1358-
#endif
1355+
//buffer_put_char(bin, '\r');
1356+
//bytes++;
1357+
//}
1358+
//#endif
13591359
buffer_put_char(bin, ch);
13601360
bytes++;
13611361
}

contrib/win32/win32compat/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ LDFLAGS=-L. @LDFLAGS@ -L/lib/win32api
1919

2020
WIN32COMPATFILES = daemon.o gettimeofday.o homedirhelp.o pwd.o sfds.o \
2121
socket.o startupneeds.o strcasecmp.o syslog.o lsalogon.o lsastring.o \
22-
stringhelp.o deskright.o win32auth.o kerberos.o cng_cipher.o ansiprsr.o console.o tnnet.o conio.o
22+
stringhelp.o deskright.o win32auth.o kerberos.o cng_cipher.o ansiprsr.o \
23+
console.o tnnet.o conio.o tncon.o
2324

2425
WIN32COMPATLIB=@LIBWIN32COMPAT@
2526

contrib/win32/win32compat/ansiprsr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// items used from other modules
5252
int NetWriteString(char* pszString, size_t cbString);
5353
TelParams Parameters;
54-
extern int lftocrlf;
54+
int lftocrlf = 0;
5555

5656
extern int ScreenX;
5757
extern int ScreenY;

contrib/win32/win32compat/ansiprsr.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,28 @@ unsigned char * ParseVT52(unsigned char * pszBuffer, unsigned char * pszBufferEn
5555

5656
typedef struct _TelParams
5757
{
58+
int fLogging;
59+
FILE *fplogfile;
60+
61+
char *pInputFile;
62+
63+
char * szDebugInputFile;
64+
BOOL fDebugWait;
65+
5866
int timeOut;
5967
int fLocalEcho;
6068
int fTreatLFasCRLF;
6169
int fSendCROnly;
6270
int nReceiveCRLF;
71+
//_crlftype nReceiveCRLF;
72+
char sleepChar;
73+
char menuChar;
74+
75+
SOCKET Socket;
76+
BOOL bVT100Mode;
77+
78+
char *pAltKey;
79+
6380
} TelParams;
6481

6582
#endif

contrib/win32/win32compat/socket.c

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern void debug3(const char *fmt,...);
5454
extern void error(const char *fmt,...);
5555
extern void fatal(const char *fmt,...);
5656

57+
int glob_itissshclient = 0; // ssh client turns it to 1
5758
static int winsock_initialized = 0;
5859

5960
extern int logfd;
@@ -1545,7 +1546,26 @@ int socketpair(int socks[2])
15451546
return SOCKET_ERROR;
15461547
}
15471548

1549+
int DataAvailable ( HANDLE h )
1550+
{
1551+
INPUT_RECORD irec = {0};
1552+
1553+
DWORD events_read = 0;
1554+
1555+
int ret = PeekConsoleInput (h, &irec, 1, &events_read);
1556+
1557+
if (!ret)
1558+
{
1559+
return 0;
1560+
}
1561+
1562+
if (events_read) // && irec.EventType == KEY_EVENT)
1563+
{
1564+
return events_read ;
1565+
}
15481566

1567+
return 0;
1568+
}
15491569
int peekConsoleRead(int sfd)
15501570
{
15511571
DWORD sleep_time = 0;
@@ -2391,8 +2411,9 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
23912411
SOCKET sock;
23922412

23932413
int ret = -1;
2414+
int sfd_type = get_sfd_type(sfd);
23942415

2395-
switch(get_sfd_type(sfd))
2416+
switch (sfd_type)
23962417
{
23972418
case SFD_TYPE_SOCKET:
23982419
{
@@ -2450,8 +2471,9 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
24502471

24512472
case SFD_TYPE_FD:
24522473
case SFD_TYPE_PIPE:
2453-
case SFD_TYPE_CONSOLE:
2474+
//case SFD_TYPE_CONSOLE:
24542475
{
2476+
24552477
ret = _read(sfd_to_fd(sfd), dst, max);
24562478

24572479
if (FD_ISSET(sfd_to_fd(sfd), &debug_sfds))
@@ -2470,6 +2492,25 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
24702492
sfd, GetLastError());
24712493
}
24722494

2495+
break;
2496+
}
2497+
case SFD_TYPE_CONSOLE:
2498+
{
2499+
//if (sfd_type == SFD_TYPE_CONSOLE) {
2500+
// we could be send here due to ctrl-c input, so no data to read
2501+
//if ( DataAvailable (sfd_to_handle(sfd)) <=0 )
2502+
//return 1; // no data to read
2503+
//}
2504+
ret = ReadConsoleForTermEmul( sfd_to_handle(sfd), dst, max);
2505+
2506+
if (ret < 0)
2507+
{
2508+
error("read from pipe/console sfd [%d] failed with error code [%d]",
2509+
sfd, GetLastError());
2510+
}
2511+
if (ret == 0)
2512+
return 0; //1;
2513+
24732514
break;
24742515
}
24752516
case 99:
@@ -2519,7 +2560,11 @@ int WSHELPwrite(int sfd, const char *buf, unsigned int max)
25192560

25202561
int ret = -1;
25212562

2522-
switch(get_sfd_type(sfd))
2563+
int sfd_type = get_sfd_type(sfd);
2564+
if ( (glob_itissshclient) && ( sfd_type == SFD_TYPE_CONSOLE ) )
2565+
sfd_type = SFD_TYPE_PIPE ; // client write type uses _write() in place ofn console insertion
2566+
2567+
switch(sfd_type)
25232568
{
25242569
case SFD_TYPE_SOCKET:
25252570
{

0 commit comments

Comments
 (0)