Skip to content

Commit

Permalink
wolfSSHd Terminal
Browse files Browse the repository at this point in the history
1. Modified the ssh terminal size test to be agnostic to the version of
   sed used.
2. Add some guards around the mode setting code for ioctl() availability
   so it would build for Windows.
  • Loading branch information
ejohnstown committed Dec 30, 2023
1 parent 92c4242 commit 72d083d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 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
6 changes: 6 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7132,6 +7132,9 @@ static int DoChannelClose(WOLFSSH* ssh,
}


#if !defined(NO_TERMIOS) && defined(WOLFSSH_TERM)
#if defined(HAVE_SYS_IOCTL_H)

#define TTY_SET_CHAR(x,y,z) (x)[(y)] = (byte)(z)
#define TTY_SET_FLAG(x,y,z) (x) = (z) ? ((x) | (y)) : ((x) & ~(y))

Expand Down Expand Up @@ -7368,6 +7371,9 @@ int wolfSSH_DoModes(const byte* modes, word32 modesSz, int fd)
return 0;
}

#endif /* HAVE_SYS_IOCTL_H */
#endif /* !NO_TERMIOS && WOLFSSH_TERM */


static int DoChannelRequest(WOLFSSH* ssh,
byte* buf, word32 len, word32* idx)
Expand Down

0 comments on commit 72d083d

Please sign in to comment.