Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wolfSSHd Terminal #640

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading