2019-07-05 06:12:46 +02:00
|
|
|
# $OpenBSD: test-exec.sh,v 1.66 2019/07/05 04:12:46 dtucker Exp $
|
2002-05-01 05:17:33 +02:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
#SUDO=sudo
|
|
|
|
|
2005-02-08 10:17:17 +01:00
|
|
|
# Unbreak GNU head(1)
|
|
|
|
_POSIX2_VERSION=199209
|
|
|
|
export _POSIX2_VERSION
|
|
|
|
|
2005-03-09 00:02:55 +01:00
|
|
|
case `uname -s 2>/dev/null` in
|
|
|
|
OSF1*)
|
|
|
|
BIN_SH=xpg4
|
|
|
|
export BIN_SH
|
|
|
|
;;
|
2012-07-02 17:06:49 +02:00
|
|
|
CYGWIN*)
|
|
|
|
os=cygwin
|
|
|
|
;;
|
2005-03-09 00:02:55 +01:00
|
|
|
esac
|
|
|
|
|
2004-06-23 01:28:20 +02:00
|
|
|
if [ ! -z "$TEST_SSH_PORT" ]; then
|
|
|
|
PORT="$TEST_SSH_PORT"
|
|
|
|
else
|
|
|
|
PORT=4242
|
|
|
|
fi
|
|
|
|
|
2003-09-04 07:35:48 +02:00
|
|
|
if [ -x /usr/ucb/whoami ]; then
|
|
|
|
USER=`/usr/ucb/whoami`
|
2003-09-12 07:32:17 +02:00
|
|
|
elif whoami >/dev/null 2>&1; then
|
2003-09-04 07:35:48 +02:00
|
|
|
USER=`whoami`
|
2006-02-01 01:21:01 +01:00
|
|
|
elif logname >/dev/null 2>&1; then
|
|
|
|
USER=`logname`
|
2003-09-04 07:35:48 +02:00
|
|
|
else
|
|
|
|
USER=`id -un`
|
|
|
|
fi
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
OBJ=$1
|
|
|
|
if [ "x$OBJ" = "x" ]; then
|
|
|
|
echo '$OBJ not defined'
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
if [ ! -d $OBJ ]; then
|
|
|
|
echo "not a directory: $OBJ"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
SCRIPT=$2
|
|
|
|
if [ "x$SCRIPT" = "x" ]; then
|
|
|
|
echo '$SCRIPT not defined'
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
if [ ! -f $SCRIPT ]; then
|
|
|
|
echo "not a file: $SCRIPT"
|
|
|
|
exit 2
|
|
|
|
fi
|
2004-02-12 16:17:10 +01:00
|
|
|
if $TEST_SHELL -n $SCRIPT; then
|
2002-05-01 05:17:33 +02:00
|
|
|
true
|
|
|
|
else
|
|
|
|
echo "syntax error in $SCRIPT"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
unset SSH_AUTH_SOCK
|
|
|
|
|
2005-03-07 08:33:02 +01:00
|
|
|
SRC=`dirname ${SCRIPT}`
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
# defaults
|
|
|
|
SSH=ssh
|
|
|
|
SSHD=sshd
|
|
|
|
SSHAGENT=ssh-agent
|
|
|
|
SSHADD=ssh-add
|
|
|
|
SSHKEYGEN=ssh-keygen
|
|
|
|
SSHKEYSCAN=ssh-keyscan
|
|
|
|
SFTP=sftp
|
|
|
|
SFTPSERVER=/usr/libexec/openssh/sftp-server
|
2004-06-16 12:15:59 +02:00
|
|
|
SCP=scp
|
2002-05-01 05:17:33 +02:00
|
|
|
|
2018-07-20 06:53:42 +02:00
|
|
|
# Set by make_tmpdir() on demand (below).
|
|
|
|
SSH_REGRESS_TMP=
|
|
|
|
|
2008-03-12 14:17:00 +01:00
|
|
|
# Interop testing
|
2008-06-30 00:12:37 +02:00
|
|
|
PLINK=plink
|
|
|
|
PUTTYGEN=puttygen
|
|
|
|
CONCH=conch
|
2008-03-12 14:17:00 +01:00
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ "x$TEST_SSH_SSH" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSH="${TEST_SSH_SSH}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SSHD" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSHD="${TEST_SSH_SSHD}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SSHAGENT" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSHAGENT="${TEST_SSH_SSHAGENT}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SSHADD" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSHADD="${TEST_SSH_SSHADD}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSHKEYGEN="${TEST_SSH_SSHKEYGEN}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SSHKEYSCAN="${TEST_SSH_SSHKEYSCAN}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SFTP" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SFTP="${TEST_SSH_SFTP}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then
|
2004-02-29 10:31:08 +01:00
|
|
|
SFTPSERVER="${TEST_SSH_SFTPSERVER}"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
2004-06-16 12:15:59 +02:00
|
|
|
if [ "x$TEST_SSH_SCP" != "x" ]; then
|
|
|
|
SCP="${TEST_SSH_SCP}"
|
|
|
|
fi
|
2008-03-12 14:17:00 +01:00
|
|
|
if [ "x$TEST_SSH_PLINK" != "x" ]; then
|
2008-03-13 02:41:31 +01:00
|
|
|
# Find real binary, if it exists
|
|
|
|
case "${TEST_SSH_PLINK}" in
|
|
|
|
/*) PLINK="${TEST_SSH_PLINK}" ;;
|
2008-03-14 23:25:54 +01:00
|
|
|
*) PLINK=`which ${TEST_SSH_PLINK} 2>/dev/null` ;;
|
2008-03-13 02:41:31 +01:00
|
|
|
esac
|
2008-03-12 14:17:00 +01:00
|
|
|
fi
|
|
|
|
if [ "x$TEST_SSH_PUTTYGEN" != "x" ]; then
|
2008-03-13 02:41:31 +01:00
|
|
|
# Find real binary, if it exists
|
|
|
|
case "${TEST_SSH_PUTTYGEN}" in
|
|
|
|
/*) PUTTYGEN="${TEST_SSH_PUTTYGEN}" ;;
|
2008-03-14 23:25:54 +01:00
|
|
|
*) PUTTYGEN=`which ${TEST_SSH_PUTTYGEN} 2>/dev/null` ;;
|
2008-03-13 02:41:31 +01:00
|
|
|
esac
|
2008-03-12 14:17:00 +01:00
|
|
|
fi
|
2008-06-30 00:07:56 +02:00
|
|
|
if [ "x$TEST_SSH_CONCH" != "x" ]; then
|
2008-06-30 00:12:37 +02:00
|
|
|
# Find real binary, if it exists
|
|
|
|
case "${TEST_SSH_CONCH}" in
|
|
|
|
/*) CONCH="${TEST_SSH_CONCH}" ;;
|
|
|
|
*) CONCH=`which ${TEST_SSH_CONCH} 2>/dev/null` ;;
|
|
|
|
esac
|
2008-06-30 00:07:56 +02:00
|
|
|
fi
|
2002-05-01 05:17:33 +02:00
|
|
|
|
2004-06-25 05:45:18 +02:00
|
|
|
# Path to sshd must be absolute for rexec
|
2005-08-23 15:32:05 +02:00
|
|
|
case "$SSHD" in
|
|
|
|
/*) ;;
|
2013-11-09 06:55:03 +01:00
|
|
|
*) SSHD=`which $SSHD` ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$SSHAGENT" in
|
|
|
|
/*) ;;
|
|
|
|
*) SSHAGENT=`which $SSHAGENT` ;;
|
2005-08-23 15:32:05 +02:00
|
|
|
esac
|
2004-06-25 05:45:18 +02:00
|
|
|
|
2015-02-26 01:58:22 +01:00
|
|
|
# Record the actual binaries used.
|
|
|
|
SSH_BIN=${SSH}
|
|
|
|
SSHD_BIN=${SSHD}
|
|
|
|
SSHAGENT_BIN=${SSHAGENT}
|
|
|
|
SSHADD_BIN=${SSHADD}
|
|
|
|
SSHKEYGEN_BIN=${SSHKEYGEN}
|
|
|
|
SSHKEYSCAN_BIN=${SSHKEYSCAN}
|
|
|
|
SFTP_BIN=${SFTP}
|
|
|
|
SFTPSERVER_BIN=${SFTPSERVER}
|
|
|
|
SCP_BIN=${SCP}
|
|
|
|
|
|
|
|
if [ "x$USE_VALGRIND" != "x" ]; then
|
2019-07-17 13:24:55 +02:00
|
|
|
rm -rf $OBJ/valgrind-out $OBJ/valgrind-vgdb
|
|
|
|
mkdir -p $OBJ/valgrind-out $OBJ/valgrind-vgdb
|
2019-07-18 02:17:54 +02:00
|
|
|
# When using sudo ensure low-priv tests can write pipes and logs.
|
|
|
|
if [ "x$SUDO" != "x" ]; then
|
|
|
|
chmod 777 $OBJ/valgrind-out $OBJ/valgrind-vgdb
|
|
|
|
fi
|
2015-02-26 01:58:22 +01:00
|
|
|
VG_TEST=`basename $SCRIPT .sh`
|
|
|
|
|
|
|
|
# Some tests are difficult to fix.
|
|
|
|
case "$VG_TEST" in
|
2019-07-19 02:41:56 +02:00
|
|
|
reexec)
|
2015-02-26 01:58:22 +01:00
|
|
|
VG_SKIP=1 ;;
|
2019-07-19 10:51:18 +02:00
|
|
|
sftp-chroot)
|
|
|
|
if [ "x${SUDO}" != "x" ]; then
|
|
|
|
VG_SKIP=1
|
|
|
|
fi ;;
|
2015-02-26 01:58:22 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
if [ x"$VG_SKIP" = "x" ]; then
|
2018-07-11 01:56:36 +02:00
|
|
|
VG_LEAK="--leak-check=no"
|
2018-07-11 02:19:56 +02:00
|
|
|
if [ x"$VALGRIND_CHECK_LEAKS" != "x" ]; then
|
2018-07-11 01:56:36 +02:00
|
|
|
VG_LEAK="--leak-check=full"
|
|
|
|
fi
|
2015-02-26 01:58:22 +01:00
|
|
|
VG_IGNORE="/bin/*,/sbin/*,/usr/*,/var/*"
|
|
|
|
VG_LOG="$OBJ/valgrind-out/${VG_TEST}."
|
2018-07-11 01:56:36 +02:00
|
|
|
VG_OPTS="--track-origins=yes $VG_LEAK"
|
2015-02-26 01:58:22 +01:00
|
|
|
VG_OPTS="$VG_OPTS --trace-children=yes"
|
|
|
|
VG_OPTS="$VG_OPTS --trace-children-skip=${VG_IGNORE}"
|
2019-07-17 13:24:55 +02:00
|
|
|
VG_OPTS="$VG_OPTS --vgdb-prefix=$OBJ/valgrind-vgdb/"
|
2015-02-26 01:58:22 +01:00
|
|
|
VG_PATH="valgrind"
|
|
|
|
if [ "x$VALGRIND_PATH" != "x" ]; then
|
|
|
|
VG_PATH="$VALGRIND_PATH"
|
|
|
|
fi
|
|
|
|
VG="$VG_PATH $VG_OPTS"
|
|
|
|
SSH="$VG --log-file=${VG_LOG}ssh.%p $SSH"
|
|
|
|
SSHD="$VG --log-file=${VG_LOG}sshd.%p $SSHD"
|
|
|
|
SSHAGENT="$VG --log-file=${VG_LOG}ssh-agent.%p $SSHAGENT"
|
|
|
|
SSHADD="$VG --log-file=${VG_LOG}ssh-add.%p $SSHADD"
|
|
|
|
SSHKEYGEN="$VG --log-file=${VG_LOG}ssh-keygen.%p $SSHKEYGEN"
|
|
|
|
SSHKEYSCAN="$VG --log-file=${VG_LOG}ssh-keyscan.%p $SSHKEYSCAN"
|
|
|
|
SFTP="$VG --log-file=${VG_LOG}sftp.%p ${SFTP}"
|
|
|
|
SCP="$VG --log-file=${VG_LOG}scp.%p $SCP"
|
|
|
|
cat > $OBJ/valgrind-sftp-server.sh << EOF
|
|
|
|
#!/bin/sh
|
|
|
|
exec $VG --log-file=${VG_LOG}sftp-server.%p $SFTPSERVER "\$@"
|
|
|
|
EOF
|
|
|
|
chmod a+rx $OBJ/valgrind-sftp-server.sh
|
|
|
|
SFTPSERVER="$OBJ/valgrind-sftp-server.sh"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-05-17 01:19:10 +02:00
|
|
|
# Logfiles.
|
|
|
|
# SSH_LOGFILE should be the debug output of ssh(1) only
|
|
|
|
# SSHD_LOGFILE should be the debug output of sshd(8) only
|
|
|
|
# REGRESS_LOGFILE is the output of the test itself stdout and stderr
|
2005-03-07 08:33:02 +01:00
|
|
|
if [ "x$TEST_SSH_LOGFILE" = "x" ]; then
|
2013-05-17 01:19:10 +02:00
|
|
|
TEST_SSH_LOGFILE=$OBJ/ssh.log
|
2005-03-07 08:33:02 +01:00
|
|
|
fi
|
2013-05-17 01:19:10 +02:00
|
|
|
if [ "x$TEST_SSHD_LOGFILE" = "x" ]; then
|
|
|
|
TEST_SSHD_LOGFILE=$OBJ/sshd.log
|
|
|
|
fi
|
|
|
|
if [ "x$TEST_REGRESS_LOGFILE" = "x" ]; then
|
|
|
|
TEST_REGRESS_LOGFILE=$OBJ/regress.log
|
|
|
|
fi
|
|
|
|
|
|
|
|
# truncate logfiles
|
|
|
|
>$TEST_SSH_LOGFILE
|
|
|
|
>$TEST_SSHD_LOGFILE
|
|
|
|
>$TEST_REGRESS_LOGFILE
|
2005-03-07 08:33:02 +01:00
|
|
|
|
2013-05-17 01:31:39 +02:00
|
|
|
# Create wrapper ssh with logging. We can't just specify "SSH=ssh -E..."
|
|
|
|
# because sftp and scp don't handle spaces in arguments.
|
|
|
|
SSHLOGWRAP=$OBJ/ssh-log-wrapper.sh
|
|
|
|
echo "#!/bin/sh" > $SSHLOGWRAP
|
|
|
|
echo "exec ${SSH} -E${TEST_SSH_LOGFILE} "'"$@"' >>$SSHLOGWRAP
|
|
|
|
|
|
|
|
chmod a+rx $OBJ/ssh-log-wrapper.sh
|
2016-04-15 04:57:10 +02:00
|
|
|
REAL_SSH="$SSH"
|
2013-05-17 01:31:39 +02:00
|
|
|
SSH="$SSHLOGWRAP"
|
|
|
|
|
2013-05-17 07:32:29 +02:00
|
|
|
# Some test data. We make a copy because some tests will overwrite it.
|
|
|
|
# The tests may assume that $DATA exists and is writable and $COPY does
|
2013-11-09 06:55:03 +01:00
|
|
|
# not exist. Tests requiring larger data files can call increase_datafile_size
|
|
|
|
# [kbytes] to ensure the file is at least that large.
|
2013-07-25 04:11:18 +02:00
|
|
|
DATANAME=data
|
|
|
|
DATA=$OBJ/${DATANAME}
|
2015-02-26 01:58:22 +01:00
|
|
|
cat ${SSHAGENT_BIN} >${DATA}
|
2013-05-17 07:32:29 +02:00
|
|
|
chmod u+w ${DATA}
|
|
|
|
COPY=$OBJ/copy
|
|
|
|
rm -f ${COPY}
|
|
|
|
|
2013-11-09 06:55:03 +01:00
|
|
|
increase_datafile_size()
|
|
|
|
{
|
|
|
|
while [ `du -k ${DATA} | cut -f1` -lt $1 ]; do
|
2015-02-26 01:58:22 +01:00
|
|
|
cat ${SSHAGENT_BIN} >>${DATA}
|
2013-11-09 06:55:03 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
# these should be used in tests
|
2004-06-16 12:15:59 +02:00
|
|
|
export SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP
|
|
|
|
#echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP
|
2002-05-01 05:17:33 +02:00
|
|
|
|
2013-05-17 11:17:58 +02:00
|
|
|
# Portable specific functions
|
2003-09-12 07:32:17 +02:00
|
|
|
have_prog()
|
|
|
|
{
|
|
|
|
saved_IFS="$IFS"
|
|
|
|
IFS=":"
|
|
|
|
for i in $PATH
|
|
|
|
do
|
|
|
|
if [ -x $i/$1 ]; then
|
|
|
|
IFS="$saved_IFS"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
IFS="$saved_IFS"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-05-17 11:17:58 +02:00
|
|
|
jot() {
|
|
|
|
awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }"
|
|
|
|
}
|
2013-05-17 11:28:51 +02:00
|
|
|
|
|
|
|
# Check whether preprocessor symbols are defined in config.h.
|
|
|
|
config_defined ()
|
|
|
|
{
|
|
|
|
str=$1
|
|
|
|
while test "x$2" != "x" ; do
|
|
|
|
str="$str|$2"
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1
|
|
|
|
}
|
2013-05-17 11:53:25 +02:00
|
|
|
|
|
|
|
md5 () {
|
|
|
|
if have_prog md5sum; then
|
|
|
|
md5sum
|
|
|
|
elif have_prog openssl; then
|
|
|
|
openssl md5
|
|
|
|
elif have_prog cksum; then
|
|
|
|
cksum
|
|
|
|
elif have_prog sum; then
|
|
|
|
sum
|
|
|
|
else
|
|
|
|
wc -c
|
|
|
|
fi
|
|
|
|
}
|
2013-05-17 11:17:58 +02:00
|
|
|
# End of portable specific functions
|
|
|
|
|
2016-12-16 02:06:27 +01:00
|
|
|
stop_sshd ()
|
2002-05-01 05:17:33 +02:00
|
|
|
{
|
|
|
|
if [ -f $PIDFILE ]; then
|
2010-08-12 18:43:13 +02:00
|
|
|
pid=`$SUDO cat $PIDFILE`
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ "X$pid" = "X" ]; then
|
|
|
|
echo no sshd running
|
|
|
|
else
|
|
|
|
if [ $pid -lt 2 ]; then
|
2014-07-09 05:22:03 +02:00
|
|
|
echo bad pid for sshd: $pid
|
2002-05-01 05:17:33 +02:00
|
|
|
else
|
|
|
|
$SUDO kill $pid
|
2010-02-24 07:29:34 +01:00
|
|
|
trace "wait for sshd to exit"
|
|
|
|
i=0;
|
|
|
|
while [ -f $PIDFILE -a $i -lt 5 ]; do
|
|
|
|
i=`expr $i + 1`
|
|
|
|
sleep $i
|
|
|
|
done
|
2017-07-28 12:32:08 +02:00
|
|
|
if test -f $PIDFILE; then
|
|
|
|
if $SUDO kill -0 $pid; then
|
|
|
|
echo "sshd didn't exit " \
|
|
|
|
"port $PORT pid $pid"
|
|
|
|
else
|
|
|
|
echo "sshd died without cleanup"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-20 06:53:42 +02:00
|
|
|
make_tmpdir ()
|
|
|
|
{
|
2018-08-23 07:41:42 +02:00
|
|
|
SSH_REGRESS_TMP="$($OBJ/mkdtemp openssh-XXXXXXXX)" || \
|
2018-07-20 06:53:42 +02:00
|
|
|
fatal "failed to create temporary directory"
|
|
|
|
}
|
|
|
|
|
2016-12-16 02:06:27 +01:00
|
|
|
# helper
|
|
|
|
cleanup ()
|
|
|
|
{
|
|
|
|
if [ "x$SSH_PID" != "x" ]; then
|
|
|
|
if [ $SSH_PID -lt 2 ]; then
|
|
|
|
echo bad pid for ssh: $SSH_PID
|
|
|
|
else
|
|
|
|
kill $SSH_PID
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-20 06:53:42 +02:00
|
|
|
if [ "x$SSH_REGRESS_TMP" != "x" ]; then
|
|
|
|
rm -rf "$SSH_REGRESS_TMP"
|
|
|
|
fi
|
2016-12-16 02:06:27 +01:00
|
|
|
stop_sshd
|
|
|
|
}
|
|
|
|
|
2013-05-17 01:31:39 +02:00
|
|
|
start_debug_log ()
|
|
|
|
{
|
|
|
|
echo "trace: $@" >$TEST_REGRESS_LOGFILE
|
|
|
|
echo "trace: $@" >$TEST_SSH_LOGFILE
|
|
|
|
echo "trace: $@" >$TEST_SSHD_LOGFILE
|
|
|
|
}
|
|
|
|
|
|
|
|
save_debug_log ()
|
|
|
|
{
|
|
|
|
echo $@ >>$TEST_REGRESS_LOGFILE
|
|
|
|
echo $@ >>$TEST_SSH_LOGFILE
|
|
|
|
echo $@ >>$TEST_SSHD_LOGFILE
|
|
|
|
(cat $TEST_REGRESS_LOGFILE; echo) >>$OBJ/failed-regress.log
|
|
|
|
(cat $TEST_SSH_LOGFILE; echo) >>$OBJ/failed-ssh.log
|
|
|
|
(cat $TEST_SSHD_LOGFILE; echo) >>$OBJ/failed-sshd.log
|
|
|
|
}
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
trace ()
|
|
|
|
{
|
2013-05-17 01:31:39 +02:00
|
|
|
start_debug_log $@
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then
|
2007-10-26 07:35:54 +02:00
|
|
|
echo "$@"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
verbose ()
|
|
|
|
{
|
2013-05-17 01:31:39 +02:00
|
|
|
start_debug_log $@
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then
|
2007-10-26 07:35:54 +02:00
|
|
|
echo "$@"
|
2002-05-01 05:17:33 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-09-04 11:04:16 +02:00
|
|
|
warn ()
|
|
|
|
{
|
|
|
|
echo "WARNING: $@" >>$TEST_SSH_LOGFILE
|
|
|
|
echo "WARNING: $@"
|
|
|
|
}
|
2002-05-01 05:17:33 +02:00
|
|
|
|
|
|
|
fail ()
|
|
|
|
{
|
2013-05-17 01:31:39 +02:00
|
|
|
save_debug_log "FAIL: $@"
|
2002-05-01 05:17:33 +02:00
|
|
|
RESULT=1
|
2007-10-26 07:35:54 +02:00
|
|
|
echo "$@"
|
2018-05-22 02:22:49 +02:00
|
|
|
if test "x$TEST_SSH_FAIL_FATAL" != "x" ; then
|
|
|
|
cleanup
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
2002-05-01 05:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fatal ()
|
|
|
|
{
|
2013-05-17 01:31:39 +02:00
|
|
|
save_debug_log "FATAL: $@"
|
2013-05-17 05:28:36 +02:00
|
|
|
printf "FATAL: "
|
2002-05-01 05:17:33 +02:00
|
|
|
fail "$@"
|
|
|
|
cleanup
|
|
|
|
exit $RESULT
|
|
|
|
}
|
|
|
|
|
|
|
|
RESULT=0
|
|
|
|
PIDFILE=$OBJ/pidfile
|
|
|
|
|
|
|
|
trap fatal 3 2
|
|
|
|
|
|
|
|
# create server config
|
|
|
|
cat << EOF > $OBJ/sshd_config
|
2004-06-16 12:36:16 +02:00
|
|
|
StrictModes no
|
2002-05-01 05:17:33 +02:00
|
|
|
Port $PORT
|
2006-01-31 11:59:01 +01:00
|
|
|
AddressFamily inet
|
2002-05-01 05:17:33 +02:00
|
|
|
ListenAddress 127.0.0.1
|
|
|
|
#ListenAddress ::1
|
|
|
|
PidFile $PIDFILE
|
|
|
|
AuthorizedKeysFile $OBJ/authorized_keys_%u
|
2013-05-17 01:31:39 +02:00
|
|
|
LogLevel DEBUG3
|
2004-06-16 12:08:56 +02:00
|
|
|
AcceptEnv _XXX_TEST_*
|
|
|
|
AcceptEnv _XXX_TEST
|
2004-06-16 12:22:22 +02:00
|
|
|
Subsystem sftp $SFTPSERVER
|
2002-05-01 05:17:33 +02:00
|
|
|
EOF
|
|
|
|
|
2016-04-15 01:21:42 +02:00
|
|
|
# This may be necessary if /usr/src and/or /usr/obj are group-writable,
|
|
|
|
# but if you aren't careful with permissions then the unit tests could
|
|
|
|
# be abused to locally escalate privileges.
|
|
|
|
if [ ! -z "$TEST_SSH_UNSAFE_PERMISSIONS" ]; then
|
|
|
|
echo "StrictModes no" >> $OBJ/sshd_config
|
|
|
|
fi
|
|
|
|
|
2004-06-23 01:25:02 +02:00
|
|
|
if [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then
|
|
|
|
trace "adding sshd_config option $TEST_SSH_SSHD_CONFOPTS"
|
|
|
|
echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config
|
|
|
|
fi
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
# server config for proxy connects
|
|
|
|
cp $OBJ/sshd_config $OBJ/sshd_proxy
|
|
|
|
|
|
|
|
# allow group-writable directories in proxy-mode
|
|
|
|
echo 'StrictModes no' >> $OBJ/sshd_proxy
|
|
|
|
|
|
|
|
# create client config
|
|
|
|
cat << EOF > $OBJ/ssh_config
|
|
|
|
Host *
|
|
|
|
Hostname 127.0.0.1
|
|
|
|
HostKeyAlias localhost-with-alias
|
|
|
|
Port $PORT
|
|
|
|
User $USER
|
|
|
|
GlobalKnownHostsFile $OBJ/known_hosts
|
|
|
|
UserKnownHostsFile $OBJ/known_hosts
|
|
|
|
PubkeyAuthentication yes
|
|
|
|
ChallengeResponseAuthentication no
|
|
|
|
HostbasedAuthentication no
|
|
|
|
PasswordAuthentication no
|
|
|
|
BatchMode yes
|
|
|
|
StrictHostKeyChecking yes
|
2013-05-17 01:31:39 +02:00
|
|
|
LogLevel DEBUG3
|
2002-05-01 05:17:33 +02:00
|
|
|
EOF
|
|
|
|
|
2004-06-23 01:25:02 +02:00
|
|
|
if [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then
|
2015-04-07 01:10:00 +02:00
|
|
|
trace "adding ssh_config option $TEST_SSH_SSH_CONFOPTS"
|
2004-06-23 01:25:02 +02:00
|
|
|
echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config
|
|
|
|
fi
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
rm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER
|
|
|
|
|
2019-01-27 07:30:53 +01:00
|
|
|
SSH_KEYTYPES=`$SSH -Q key-plain`
|
2017-05-01 01:34:55 +02:00
|
|
|
|
2015-03-03 23:35:19 +01:00
|
|
|
for t in ${SSH_KEYTYPES}; do
|
2002-05-01 05:17:33 +02:00
|
|
|
# generate user key
|
2019-01-27 07:30:53 +01:00
|
|
|
trace "generating key type $t"
|
2015-02-26 01:58:22 +01:00
|
|
|
if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN_BIN} -nt $OBJ/$t ]; then
|
2013-05-17 01:10:20 +02:00
|
|
|
rm -f $OBJ/$t
|
|
|
|
${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\
|
|
|
|
fail "ssh-keygen for $t failed"
|
|
|
|
fi
|
2002-05-01 05:17:33 +02:00
|
|
|
|
|
|
|
# known hosts file for client
|
|
|
|
(
|
2013-05-17 05:28:36 +02:00
|
|
|
printf 'localhost-with-alias,127.0.0.1,::1 '
|
2002-05-01 05:17:33 +02:00
|
|
|
cat $OBJ/$t.pub
|
|
|
|
) >> $OBJ/known_hosts
|
|
|
|
|
|
|
|
# setup authorized keys
|
|
|
|
cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
|
|
|
|
echo IdentityFile $OBJ/$t >> $OBJ/ssh_config
|
|
|
|
|
|
|
|
# use key as host key, too
|
|
|
|
$SUDO cp $OBJ/$t $OBJ/host.$t
|
|
|
|
echo HostKey $OBJ/host.$t >> $OBJ/sshd_config
|
|
|
|
|
|
|
|
# don't use SUDO for proxy connect
|
|
|
|
echo HostKey $OBJ/$t >> $OBJ/sshd_proxy
|
|
|
|
done
|
|
|
|
chmod 644 $OBJ/authorized_keys_$USER
|
|
|
|
|
2008-06-30 00:07:56 +02:00
|
|
|
# Activate Twisted Conch tests if the binary is present
|
|
|
|
REGRESS_INTEROP_CONCH=no
|
|
|
|
if test -x "$CONCH" ; then
|
|
|
|
REGRESS_INTEROP_CONCH=yes
|
|
|
|
fi
|
|
|
|
|
2008-06-10 15:15:54 +02:00
|
|
|
# If PuTTY is present and we are running a PuTTY test, prepare keys and
|
|
|
|
# configuration
|
2008-03-12 14:17:00 +01:00
|
|
|
REGRESS_INTEROP_PUTTY=no
|
2008-06-10 17:39:38 +02:00
|
|
|
if test -x "$PUTTYGEN" -a -x "$PLINK" ; then
|
2008-06-10 17:38:52 +02:00
|
|
|
REGRESS_INTEROP_PUTTY=yes
|
|
|
|
fi
|
|
|
|
case "$SCRIPT" in
|
|
|
|
*putty*) ;;
|
|
|
|
*) REGRESS_INTEROP_PUTTY=no ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if test "$REGRESS_INTEROP_PUTTY" = "yes" ; then
|
2008-03-12 14:17:00 +01:00
|
|
|
mkdir -p ${OBJ}/.putty
|
|
|
|
|
|
|
|
# Add a PuTTY key to authorized_keys
|
|
|
|
rm -f ${OBJ}/putty.rsa2
|
2016-11-25 04:02:01 +01:00
|
|
|
if ! puttygen -t rsa -o ${OBJ}/putty.rsa2 \
|
2018-03-16 10:06:31 +01:00
|
|
|
--random-device=/dev/urandom \
|
2016-11-25 04:02:01 +01:00
|
|
|
--new-passphrase /dev/null < /dev/null > /dev/null; then
|
|
|
|
echo "Your installed version of PuTTY is too old to support --new-passphrase; trying without (may require manual interaction) ..." >&2
|
|
|
|
puttygen -t rsa -o ${OBJ}/putty.rsa2 < /dev/null > /dev/null
|
|
|
|
fi
|
2008-03-12 14:17:00 +01:00
|
|
|
puttygen -O public-openssh ${OBJ}/putty.rsa2 \
|
|
|
|
>> $OBJ/authorized_keys_$USER
|
|
|
|
|
|
|
|
# Convert rsa2 host key to PuTTY format
|
2019-07-05 06:12:46 +02:00
|
|
|
cp $OBJ/ssh-rsa $OBJ/ssh-rsa_oldfmt
|
|
|
|
${SSHKEYGEN} -p -N '' -m PEM -f $OBJ/ssh-rsa_oldfmt >/dev/null
|
|
|
|
${SRC}/ssh2putty.sh 127.0.0.1 $PORT $OBJ/ssh-rsa_oldfmt > \
|
2008-03-12 14:17:00 +01:00
|
|
|
${OBJ}/.putty/sshhostkeys
|
2019-07-05 06:12:46 +02:00
|
|
|
${SRC}/ssh2putty.sh 127.0.0.1 22 $OBJ/ssh-rsa_oldfmt >> \
|
2008-03-12 14:17:00 +01:00
|
|
|
${OBJ}/.putty/sshhostkeys
|
2019-07-05 06:12:46 +02:00
|
|
|
rm -f $OBJ/ssh-rsa_oldfmt
|
2008-03-12 14:17:00 +01:00
|
|
|
|
|
|
|
# Setup proxied session
|
|
|
|
mkdir -p ${OBJ}/.putty/sessions
|
|
|
|
rm -f ${OBJ}/.putty/sessions/localhost_proxy
|
2016-11-25 04:02:01 +01:00
|
|
|
echo "Protocol=ssh" >> ${OBJ}/.putty/sessions/localhost_proxy
|
|
|
|
echo "HostName=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy
|
2008-03-12 14:17:00 +01:00
|
|
|
echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy
|
|
|
|
echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy
|
2015-02-26 01:58:22 +01:00
|
|
|
echo "ProxyTelnetCommand=sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy
|
2016-11-25 04:02:01 +01:00
|
|
|
echo "ProxyLocalhost=1" >> ${OBJ}/.putty/sessions/localhost_proxy
|
2008-03-12 14:17:00 +01:00
|
|
|
|
2018-03-23 03:21:14 +01:00
|
|
|
PUTTYDIR=${OBJ}/.putty
|
|
|
|
export PUTTYDIR
|
|
|
|
|
2008-03-12 14:17:00 +01:00
|
|
|
REGRESS_INTEROP_PUTTY=yes
|
|
|
|
fi
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
# create a proxy version of the client config
|
|
|
|
(
|
|
|
|
cat $OBJ/ssh_config
|
2015-02-26 01:58:22 +01:00
|
|
|
echo proxycommand ${SUDO} sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy
|
2002-05-01 05:17:33 +02:00
|
|
|
) > $OBJ/ssh_proxy
|
|
|
|
|
|
|
|
# check proxy config
|
|
|
|
${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken"
|
|
|
|
|
|
|
|
start_sshd ()
|
|
|
|
{
|
|
|
|
# start sshd
|
2008-03-12 14:17:00 +01:00
|
|
|
$SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken"
|
2013-05-17 01:31:39 +02:00
|
|
|
$SUDO ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE
|
2002-05-01 05:17:33 +02:00
|
|
|
|
|
|
|
trace "wait for sshd"
|
|
|
|
i=0;
|
2003-09-04 07:35:48 +02:00
|
|
|
while [ ! -f $PIDFILE -a $i -lt 10 ]; do
|
2002-05-01 05:17:33 +02:00
|
|
|
i=`expr $i + 1`
|
|
|
|
sleep $i
|
|
|
|
done
|
|
|
|
|
|
|
|
test -f $PIDFILE || fatal "no sshd running on port $PORT"
|
|
|
|
}
|
|
|
|
|
|
|
|
# source test body
|
|
|
|
. $SCRIPT
|
|
|
|
|
|
|
|
# kill sshd
|
|
|
|
cleanup
|
2019-07-18 03:09:38 +02:00
|
|
|
|
|
|
|
if [ "x$USE_VALGRIND" != "x" ]; then
|
|
|
|
# wait for any running process to complete
|
|
|
|
wait; sleep 1
|
2019-07-18 23:43:07 +02:00
|
|
|
VG_RESULTS=$(find $OBJ/valgrind-out -type f -print)
|
|
|
|
VG_RESULT_COUNT=0
|
2019-07-23 00:11:22 +02:00
|
|
|
VG_FAIL_COUNT=0
|
2019-07-18 23:43:07 +02:00
|
|
|
for i in $VG_RESULTS; do
|
|
|
|
if grep "ERROR SUMMARY" $i >/dev/null; then
|
|
|
|
VG_RESULT_COUNT=$(($VG_RESULT_COUNT + 1))
|
|
|
|
if ! grep "ERROR SUMMARY: 0 errors" $i >/dev/null; then
|
2019-07-23 00:11:22 +02:00
|
|
|
VG_FAIL_COUNT=$(($VG_FAIL_COUNT + 1))
|
2019-07-18 23:43:07 +02:00
|
|
|
RESULT=1
|
|
|
|
verbose valgrind failure $i
|
|
|
|
cat $i
|
|
|
|
fi
|
2019-07-18 03:09:38 +02:00
|
|
|
fi
|
|
|
|
done
|
2019-07-19 05:16:11 +02:00
|
|
|
if [ x"$VG_SKIP" != "x" ]; then
|
|
|
|
verbose valgrind skipped
|
|
|
|
else
|
2019-07-23 00:11:22 +02:00
|
|
|
verbose valgrind results $VG_RESULT_COUNT failures $VG_FAIL_COUNT
|
2019-07-19 05:16:11 +02:00
|
|
|
fi
|
2019-07-18 03:09:38 +02:00
|
|
|
fi
|
|
|
|
|
2002-05-01 05:17:33 +02:00
|
|
|
if [ $RESULT -eq 0 ]; then
|
|
|
|
verbose ok $tid
|
|
|
|
else
|
|
|
|
echo failed $tid
|
|
|
|
fi
|
|
|
|
exit $RESULT
|