Skip to content

Commit de4ae13

Browse files
committed
ssh.exe client sends current window size and TERM value when pty-req is made
This was not coded before for Win32 port. Remote sshd server is now aware of our client's screen size and VT/ANSI TERM emulation.
1 parent f1d8b2e commit de4ae13

File tree

4 files changed

+67
-10
lines changed

4 files changed

+67
-10
lines changed

channels.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,10 +3913,11 @@ channel_connect_to_path(const char *path, char *ctype, char *rname)
39133913
return connect_to(path, PORT_STREAMLOCAL, ctype, rname);
39143914
}
39153915

3916+
#ifndef WIN32_FIXME
39163917
void
39173918
channel_send_window_changes(void)
39183919
{
3919-
#ifndef WIN32_FIXME
3920+
39203921
u_int i;
39213922
struct winsize ws;
39223923

@@ -3933,9 +3934,30 @@ channel_send_window_changes(void)
39333934
packet_put_int((u_int)ws.ws_ypixel);
39343935
packet_send();
39353936
}
3936-
#endif
39373937
}
39383938

3939+
#else // WIN32_FIXME
3940+
void
3941+
channel_send_window_changes(int col, int row, int xpixel, int ypixel)
3942+
{
3943+
u_int i;
3944+
struct winsize ws;
3945+
3946+
for (i = 0; i < channels_alloc; i++) {
3947+
if (channels[i] == NULL || !channels[i]->client_tty ||
3948+
channels[i]->type != SSH_CHANNEL_OPEN)
3949+
continue;
3950+
channel_request_start(i, "window-change", 0);
3951+
packet_put_int((u_int)col);
3952+
packet_put_int((u_int)row);
3953+
packet_put_int((u_int)xpixel);
3954+
packet_put_int((u_int)ypixel);
3955+
packet_send();
3956+
}
3957+
}
3958+
#endif
3959+
3960+
39393961
/* -- X11 forwarding */
39403962

39413963
/*

channels.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ void channel_register_status_confirm(int, channel_confirm_cb *,
226226
channel_confirm_abandon_cb *, void *);
227227
void channel_cancel_cleanup(int);
228228
int channel_close_fd(int *);
229+
#ifndef WIN32_FIXME
229230
void channel_send_window_changes(void);
231+
#else
232+
void channel_send_window_changes(int, int, int, int);
233+
#endif
234+
230235

231236
/* protocol handler */
232237

clientloop.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@
119119
#include <sys/stat.h>
120120

121121
#define isatty(a) WSHELPisatty(a)
122+
123+
// Windows Console screen size change related
124+
extern int ScreenX;
125+
extern int ScrollBottom;
126+
int win_received_window_change_signal = 1;
127+
122128
#endif
123129

124130
/* import options */
@@ -563,6 +569,25 @@ client_check_window_change(void)
563569
packet_put_int((u_int)ws.ws_ypixel);
564570
packet_send();
565571
}
572+
#else
573+
574+
if (! win_received_window_change_signal)
575+
return;
576+
/** XXX race */
577+
win_received_window_change_signal = 0;
578+
579+
debug2("client_check_window_change: changed");
580+
581+
if (compat20) {
582+
channel_send_window_changes(ScreenX, ScrollBottom, 640, 480);
583+
} else {
584+
packet_start(SSH_CMSG_WINDOW_SIZE);
585+
packet_put_int((u_int)ScreenX);
586+
packet_put_int((u_int)ScrollBottom);
587+
packet_put_int((u_int)640);
588+
packet_put_int((u_int)480);
589+
packet_send();
590+
}
566591
#endif /* !WIN32_FIXME */
567592
}
568593

@@ -2571,11 +2596,11 @@ client_session2_setup(int id, int want_tty, int want_subsystem,
25712596
tty_make_modes(-1, tiop);
25722597

25732598
#else
2574-
packet_put_cstring(term != NULL ? term : "");
2575-
packet_put_int((u_int) 80 /*ws.ws_col*/);
2576-
packet_put_int((u_int) 25 /*ws.ws_row*/);
2577-
packet_put_int((u_int) 640 /*ws.ws_xpixel*/);
2578-
packet_put_int((u_int) 480 /*ws.ws_ypixel*/);
2599+
packet_put_cstring(term != NULL ? term : "vt220");
2600+
packet_put_int((u_int) ScreenX);
2601+
packet_put_int((u_int) ScrollBottom);
2602+
packet_put_int((u_int) 640);
2603+
packet_put_int((u_int) 480);
25792604
tty_make_modes(-1, NULL);
25802605
#endif /* else !WIN32_FIXME */
25812606
packet_send();

ssh.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ set_addrinfo_port(struct addrinfo *addrs, int port)
580580
/*
581581
* Main program for the ssh client.
582582
*/
583+
583584
int
584585
main(int ac, char **av)
585586
{
@@ -605,9 +606,6 @@ main(int ac, char **av)
605606
* Setup exit signal handler for receiving signal, when
606607
* parent server is stopped.
607608
*/
608-
609-
AllocConsole();
610-
ConInit( STD_OUTPUT_HANDLE, TRUE );
611609

612610
SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE);
613611

@@ -1502,6 +1500,13 @@ main(int ac, char **av)
15021500
}
15031501
}
15041502

1503+
#ifdef WIN32_FIXME
1504+
if (tty_flag) {
1505+
//AllocConsole();
1506+
ConInit( STD_OUTPUT_HANDLE, TRUE );
1507+
}
1508+
#endif
1509+
15051510
exit_status = compat20 ? ssh_session2() : ssh_session();
15061511
packet_close();
15071512

0 commit comments

Comments
 (0)