Skip to content

Commit

Permalink
Merge pull request #640 from ejohnstown/wolfsshd-term
Browse files Browse the repository at this point in the history
wolfSSHd Terminal
  • Loading branch information
douzzer authored Jan 4, 2024
2 parents f3752a9 + 72d083d commit f481ed5
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 35 deletions.
18 changes: 8 additions & 10 deletions apps/wolfsshd/test/sshd_term_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ COL=`tmux display -p -t test '#{pane_width}'`
ROW=`tmux display -p -t test '#{pane_height}'`

# get the terminals columns and lines
tmux send-keys -t test 'echo col=$COLUMNS row=$LINES'
tmux send-keys -t test 'echo;echo $COLUMNS $LINES;echo'
tmux send-keys -t test 'ENTER'
tmux capture-pane -t test
RESULT=`tmux show-buffer | grep -v echo | grep -v rejecting | grep "col="`
RESULT=$(tmux show-buffer | grep '^[0-9]* [0-9]*$')

echo "$RESULT"
echo ""
echo ""
ROW_FOUND=`echo "$RESULT" | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'`
COL_FOUND=`echo "$RESULT" | sed -r 's/^[^0-9]*([0-9]+).*$/\1/'`
ROW_FOUND=$(echo "$RESULT" | sed -e 's/[0-9]* \([0-9]*\)/\1/')
COL_FOUND=$(echo "$RESULT" | sed -e 's/\([0-9]*\) [0-9]*/\1/')

if [ "$COL" != "$COL_FOUND" ]; then
echo "Col found was $COL_FOUND which does not match expected $COL"
Expand Down Expand Up @@ -67,15 +67,13 @@ tmux new-session -d -x 50 -y 10 -s test "$TEST_CLIENT -t -u $USER -i $PRIVATE_KE
# give the command a second to establish SSH connection
sleep 0.5

echo "New COL=$COL ROW=$ROW"

tmux send-keys -t test 'echo col=$COLUMNS row=$LINES'
tmux send-keys -t test 'echo;echo $COLUMNS $LINES;echo'
tmux send-keys -t test 'ENTER'
tmux capture-pane -t test
RESULT=`tmux show-buffer | grep -v echo | grep -v rejecting | grep "col="`
RESULT=$(tmux show-buffer | grep '^[0-9]* [0-9]*$')

ROW_FOUND=`echo "$RESULT" | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'`
COL_FOUND=`echo "$RESULT" | sed -r 's/^[^0-9]*([0-9]+).*$/\1/'`
ROW_FOUND=$(echo "$RESULT" | sed -e 's/[0-9]* \([0-9]*\)/\1/')
COL_FOUND=$(echo "$RESULT" | sed -e 's/\([0-9]*\) [0-9]*/\1/')

if [ "50" != "$COL_FOUND" ]; then
echo "Col found was $COL_FOUND which does not match expected 50"
Expand Down
34 changes: 28 additions & 6 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
/* Child process */
const char *args[] = {"-sh", NULL, NULL, NULL};
char cmd[MAX_COMMAND_SZ];
char shell[MAX_COMMAND_SZ];
int ret;

signal(SIGINT, SIG_DFL);
Expand Down Expand Up @@ -1258,6 +1259,25 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,

setenv("HOME", pPasswd->pw_dir, 1);
setenv("LOGNAME", pPasswd->pw_name, 1);
setenv("SHELL", pPasswd->pw_shell, 1);

if (pPasswd->pw_shell) {
word32 shellSz = (word32)WSTRLEN(pPasswd->pw_shell);

if (shellSz < sizeof(shell)) {
char* cursor;
char* start;

WSTRNCPY(shell, pPasswd->pw_shell, sizeof(shell));
cursor = shell;
do {
start = cursor;
*cursor = '-';
cursor = WSTRCHR(start, '/');
} while (cursor && *cursor != '\0');
args[0] = start;
}
}

rc = chdir(pPasswd->pw_dir);
if (rc != 0) {
Expand Down Expand Up @@ -1323,19 +1343,21 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,

/* set initial size of terminal based on saved size */
#if defined(HAVE_SYS_IOCTL_H)
wolfSSH_DoModes(ssh->modes, ssh->modesSz, childFd);
{
struct winsize s;
struct winsize s = {0};

s.ws_col = ssh->widthChar;
s.ws_row = ssh->heightRows;
s.ws_xpixel = ssh->widthPixels;
s.ws_ypixel = ssh->heightPixels;

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;
Expand Down
Loading

0 comments on commit f481ed5

Please sign in to comment.