diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 003d112be..72aedb611 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -1148,6 +1148,9 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, return ret; } #else +#if defined(HAVE_SYS_IOCTL_H) + #include +#endif /* handles creating a new shell env. and maintains SSH connection for incoming * user input as well as output of the shell. @@ -1314,6 +1317,21 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, return WS_FATAL_ERROR; } + /* set initial size of terminal based on saved size */ +#if defined(HAVE_SYS_IOCTL_H) + { + struct winsize s; + + WMEMSET(&s, 0, sizeof s); + s.ws_col = ssh->curX; + s.ws_row = ssh->curY; + s.ws_xpixel = ssh->curXP; + s.ws_ypixel = ssh->curYP; + ioctl(childFd, TIOCSWINSZ, &s); + } +#endif + + wolfSSH_SetTerminalResizeCtx(ssh, (void*)&childFd); while (ChildRunning) { byte tmp[2]; fd_set readFds; diff --git a/src/internal.c b/src/internal.c index 2b722f7d8..27f308c85 100644 --- a/src/internal.c +++ b/src/internal.c @@ -645,8 +645,9 @@ void CtxResourceFree(WOLFSSH_CTX* ctx) #ifdef WOLFSSH_TERM /* default terminal resize handling callbacks */ -#if defined(USE_WINDOWS_API) && defined(WOLFSSH_SSHD) -static int WS_WindowsTermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP, +#if defined(WOLFSSH_SSHD) && !defined(WOLFSSH_RESIZE_NO_DEFUALT) +#if defined(USE_WINDOWS_API) +static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP, word32 rowP, void* usrCtx) { HPCON* term = (HPCON*)usrCtx; @@ -667,7 +668,33 @@ static int WS_WindowsTermResize(WOLFSSH* ssh, word32 col, word32 row, word32 col return ret; } +#elif defined(HAVE_SYS_IOCTL_H) + +#include +static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP, + word32 rowP, void* usrCtx) +{ + struct winsize s; + int ret = WS_SUCCESS; + int* fd = (int*)usrCtx; + + if (fd != NULL) { + WMEMSET(&s, 0, sizeof s); + s.ws_row = row; + s.ws_col = col; + s.ws_xpixel = colP; + s.ws_ypixel = rowP; + + ioctl(*fd, TIOCSWINSZ, &s); + } + + (void)ssh; + return ret; +} +#else + #define WOLFSSH_RESIZE_NO_DEFUALT #endif +#endif /* WOLFSSH_SSHD */ #endif /* WOLFSSH_TERM */ @@ -763,10 +790,10 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx) ssh->agentEnabled = ctx->agentEnabled; #endif -#ifdef WOLFSSH_TERM - #if defined(USE_WINDOWS_API) && defined(WOLFSSH_SSHD) - ssh->termResizeCb = WS_WindowsTermResize; - #endif +#if defined(WOLFSSH_TERM) && defined(WOLFSSH_SSHD) +#ifndef WOLFSSH_RESIZE_NO_DEFUALT + ssh->termResizeCb = WS_TermResize; +#endif #endif if (BufferInit(&ssh->inputBuffer, 0, ctx->heap) != WS_SUCCESS || @@ -7169,6 +7196,8 @@ static int DoChannelRequest(WOLFSSH* ssh, WLOG(WS_LOG_DEBUG, " heightPixels = %u", heightPixels); ssh->curX = widthChar; ssh->curY = heightRows; + ssh->curXP = widthPixels; + ssh->curYP = heightPixels; if (ssh->termResizeCb) { if (ssh->termResizeCb(ssh, widthChar, heightRows, widthPixels, heightPixels, ssh->termCtx) diff --git a/wolfssh/internal.h b/wolfssh/internal.h index 674f93de2..cb2a4dce3 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -815,6 +815,8 @@ struct WOLFSSH { void* termCtx; word32 curX; /* current terminal width */ word32 curY; /* current terminal height */ + word32 curXP; /* pixel width */ + word32 curYP; /* pixel height */ #endif };