1a91a2465SEd Maste# $OpenBSD: test-exec.sh,v 1.108 2024/03/08 11:34:10 dtucker Exp $ 2ce3adf43SDag-Erling Smørgrav# Placed in the Public Domain. 3ce3adf43SDag-Erling Smørgrav 4ce3adf43SDag-Erling Smørgrav#SUDO=sudo 5ce3adf43SDag-Erling Smørgrav 638a52bd3SEd Masteif [ ! -z "$TEST_SSH_ELAPSED_TIMES" ]; then 719261079SEd Maste STARTTIME=`date '+%s'` 819261079SEd Mastefi 9ce3adf43SDag-Erling Smørgrav 10ce3adf43SDag-Erling Smørgravif [ ! -z "$TEST_SSH_PORT" ]; then 11ce3adf43SDag-Erling Smørgrav PORT="$TEST_SSH_PORT" 12ce3adf43SDag-Erling Smørgravelse 13ce3adf43SDag-Erling Smørgrav PORT=4242 14ce3adf43SDag-Erling Smørgravfi 15ce3adf43SDag-Erling Smørgrav 16ce3adf43SDag-Erling SmørgravOBJ=$1 17ce3adf43SDag-Erling Smørgravif [ "x$OBJ" = "x" ]; then 18ce3adf43SDag-Erling Smørgrav echo '$OBJ not defined' 19ce3adf43SDag-Erling Smørgrav exit 2 20ce3adf43SDag-Erling Smørgravfi 21ce3adf43SDag-Erling Smørgravif [ ! -d $OBJ ]; then 22ce3adf43SDag-Erling Smørgrav echo "not a directory: $OBJ" 23ce3adf43SDag-Erling Smørgrav exit 2 24ce3adf43SDag-Erling Smørgravfi 25ce3adf43SDag-Erling SmørgravSCRIPT=$2 26ce3adf43SDag-Erling Smørgravif [ "x$SCRIPT" = "x" ]; then 27ce3adf43SDag-Erling Smørgrav echo '$SCRIPT not defined' 28ce3adf43SDag-Erling Smørgrav exit 2 29ce3adf43SDag-Erling Smørgravfi 30ce3adf43SDag-Erling Smørgravif [ ! -f $SCRIPT ]; then 31ce3adf43SDag-Erling Smørgrav echo "not a file: $SCRIPT" 32ce3adf43SDag-Erling Smørgrav exit 2 33ce3adf43SDag-Erling Smørgravfi 34ce3adf43SDag-Erling Smørgravif $TEST_SHELL -n $SCRIPT; then 35ce3adf43SDag-Erling Smørgrav true 36ce3adf43SDag-Erling Smørgravelse 37ce3adf43SDag-Erling Smørgrav echo "syntax error in $SCRIPT" 38ce3adf43SDag-Erling Smørgrav exit 2 39ce3adf43SDag-Erling Smørgravfi 40ce3adf43SDag-Erling Smørgravunset SSH_AUTH_SOCK 41ce3adf43SDag-Erling Smørgrav 4219261079SEd Maste# Portable-specific settings. 4319261079SEd Maste 4419261079SEd Masteif [ -x /usr/ucb/whoami ]; then 4519261079SEd Maste USER=`/usr/ucb/whoami` 4619261079SEd Masteelif whoami >/dev/null 2>&1; then 4719261079SEd Maste USER=`whoami` 4819261079SEd Masteelif logname >/dev/null 2>&1; then 4919261079SEd Maste USER=`logname` 5019261079SEd Masteelse 5119261079SEd Maste USER=`id -un` 5219261079SEd Mastefi 5319261079SEd Masteif test -z "$LOGNAME"; then 5419261079SEd Maste LOGNAME="${USER}" 5519261079SEd Maste export LOGNAME 5619261079SEd Mastefi 5719261079SEd Maste 5819261079SEd Maste# Unbreak GNU head(1) 5919261079SEd Maste_POSIX2_VERSION=199209 6019261079SEd Masteexport _POSIX2_VERSION 6119261079SEd Maste 6219261079SEd Mastecase `uname -s 2>/dev/null` in 6319261079SEd MasteOSF1*) 6419261079SEd Maste BIN_SH=xpg4 6519261079SEd Maste export BIN_SH 6619261079SEd Maste ;; 6719261079SEd MasteCYGWIN*) 6819261079SEd Maste os=cygwin 6919261079SEd Maste ;; 7019261079SEd Masteesac 7119261079SEd Maste 7219261079SEd Maste# If configure tells us to use a different egrep, create a wrapper function 7319261079SEd Maste# to call it. This means we don't need to change all the tests that depend 7419261079SEd Maste# on a good implementation. 7519261079SEd Masteif test "x${EGREP}" != "x"; then 7619261079SEd Maste egrep () 7719261079SEd Maste{ 7819261079SEd Maste ${EGREP} "$@" 7919261079SEd Maste} 8019261079SEd Mastefi 8119261079SEd Maste 82ce3adf43SDag-Erling SmørgravSRC=`dirname ${SCRIPT}` 83ce3adf43SDag-Erling Smørgrav 84ce3adf43SDag-Erling Smørgrav# defaults 85ce3adf43SDag-Erling SmørgravSSH=ssh 86ce3adf43SDag-Erling SmørgravSSHD=sshd 87ce3adf43SDag-Erling SmørgravSSHAGENT=ssh-agent 88ce3adf43SDag-Erling SmørgravSSHADD=ssh-add 89ce3adf43SDag-Erling SmørgravSSHKEYGEN=ssh-keygen 90ce3adf43SDag-Erling SmørgravSSHKEYSCAN=ssh-keyscan 91ce3adf43SDag-Erling SmørgravSFTP=sftp 92ce3adf43SDag-Erling SmørgravSFTPSERVER=/usr/libexec/openssh/sftp-server 93ce3adf43SDag-Erling SmørgravSCP=scp 94ce3adf43SDag-Erling Smørgrav 95190cef3dSDag-Erling Smørgrav# Set by make_tmpdir() on demand (below). 96190cef3dSDag-Erling SmørgravSSH_REGRESS_TMP= 97190cef3dSDag-Erling Smørgrav 98ce3adf43SDag-Erling Smørgrav# Interop testing 99069ac184SEd MastePLINK=/usr/local/bin/plink 100069ac184SEd MastePUTTYGEN=/usr/local/bin/puttygen 101069ac184SEd MasteCONCH=/usr/local/bin/conch 102069ac184SEd MasteDROPBEAR=/usr/local/bin/dropbear 103069ac184SEd MasteDBCLIENT=/usr/local/bin/dbclient 104069ac184SEd MasteDROPBEARKEY=/usr/local/bin/dropbearkey 105069ac184SEd MasteDROPBEARCONVERT=/usr/local/bin/dropbearconvert 106ce3adf43SDag-Erling Smørgrav 107a91a2465SEd Maste# So we can override this in Portable. 108a91a2465SEd MasteTEST_SHELL="${TEST_SHELL:-/bin/sh}" 109a91a2465SEd Maste 11019261079SEd Maste# Tools used by multiple tests 11119261079SEd MasteNC=$OBJ/netcat 1124d3fc8b0SEd Maste# Always use the one configure tells us to, even if that's empty. 1134d3fc8b0SEd Maste#OPENSSL_BIN="${OPENSSL_BIN:-openssl}" 11419261079SEd Maste 115ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSH" != "x" ]; then 116ce3adf43SDag-Erling Smørgrav SSH="${TEST_SSH_SSH}" 117ce3adf43SDag-Erling Smørgravfi 118ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSHD" != "x" ]; then 119ce3adf43SDag-Erling Smørgrav SSHD="${TEST_SSH_SSHD}" 120ce3adf43SDag-Erling Smørgravfi 121ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSHAGENT" != "x" ]; then 122ce3adf43SDag-Erling Smørgrav SSHAGENT="${TEST_SSH_SSHAGENT}" 123ce3adf43SDag-Erling Smørgravfi 124ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSHADD" != "x" ]; then 125ce3adf43SDag-Erling Smørgrav SSHADD="${TEST_SSH_SSHADD}" 126ce3adf43SDag-Erling Smørgravfi 127ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSHKEYGEN" != "x" ]; then 128ce3adf43SDag-Erling Smørgrav SSHKEYGEN="${TEST_SSH_SSHKEYGEN}" 129ce3adf43SDag-Erling Smørgravfi 130ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SSHKEYSCAN" != "x" ]; then 131ce3adf43SDag-Erling Smørgrav SSHKEYSCAN="${TEST_SSH_SSHKEYSCAN}" 132ce3adf43SDag-Erling Smørgravfi 133ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SFTP" != "x" ]; then 134ce3adf43SDag-Erling Smørgrav SFTP="${TEST_SSH_SFTP}" 135ce3adf43SDag-Erling Smørgravfi 136ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SFTPSERVER" != "x" ]; then 137ce3adf43SDag-Erling Smørgrav SFTPSERVER="${TEST_SSH_SFTPSERVER}" 138ce3adf43SDag-Erling Smørgravfi 139ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_SCP" != "x" ]; then 140ce3adf43SDag-Erling Smørgrav SCP="${TEST_SSH_SCP}" 141ce3adf43SDag-Erling Smørgravfi 142ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_PLINK" != "x" ]; then 143069ac184SEd Maste PLINK="${TEST_SSH_PLINK}" 144ce3adf43SDag-Erling Smørgravfi 145ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_PUTTYGEN" != "x" ]; then 146069ac184SEd Maste PUTTYGEN="${TEST_SSH_PUTTYGEN}" 147ce3adf43SDag-Erling Smørgravfi 148ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_CONCH" != "x" ]; then 149069ac184SEd Maste CONCH="${TEST_SSH_CONCH}" 150069ac184SEd Mastefi 151069ac184SEd Masteif [ "x$TEST_SSH_DROPBEAR" != "x" ]; then 152069ac184SEd Maste DROPBEAR="${TEST_SSH_DROPBEAR}" 153069ac184SEd Mastefi 154069ac184SEd Masteif [ "x$TEST_SSH_DBCLIENT" != "x" ]; then 155069ac184SEd Maste DBCLIENT="${TEST_SSH_DBCLIENT}" 156069ac184SEd Mastefi 157069ac184SEd Masteif [ "x$TEST_SSH_DROPBEARKEY" != "x" ]; then 158069ac184SEd Maste DROPBEARKEY="${TEST_SSH_DROPBEARKEY}" 159069ac184SEd Mastefi 160069ac184SEd Masteif [ "x$TEST_SSH_DROPBEARCONVERT" != "x" ]; then 161069ac184SEd Maste DROPBEARCONVERT="${TEST_SSH_DROPBEARCONVERT}" 162ce3adf43SDag-Erling Smørgravfi 16319261079SEd Masteif [ "x$TEST_SSH_PKCS11_HELPER" != "x" ]; then 16419261079SEd Maste SSH_PKCS11_HELPER="${TEST_SSH_PKCS11_HELPER}" 16519261079SEd Mastefi 16619261079SEd Masteif [ "x$TEST_SSH_SK_HELPER" != "x" ]; then 16719261079SEd Maste SSH_SK_HELPER="${TEST_SSH_SK_HELPER}" 16819261079SEd Mastefi 16919261079SEd Masteif [ "x$TEST_SSH_OPENSSL" != "x" ]; then 17019261079SEd Maste OPENSSL_BIN="${TEST_SSH_OPENSSL}" 17119261079SEd Mastefi 172ce3adf43SDag-Erling Smørgrav 173ce3adf43SDag-Erling Smørgrav# Path to sshd must be absolute for rexec 174ce3adf43SDag-Erling Smørgravcase "$SSHD" in 175ce3adf43SDag-Erling Smørgrav/*) ;; 176f7167e0eSDag-Erling Smørgrav*) SSHD=`which $SSHD` ;; 177f7167e0eSDag-Erling Smørgravesac 178f7167e0eSDag-Erling Smørgrav 179f7167e0eSDag-Erling Smørgravcase "$SSHAGENT" in 180f7167e0eSDag-Erling Smørgrav/*) ;; 181f7167e0eSDag-Erling Smørgrav*) SSHAGENT=`which $SSHAGENT` ;; 182ce3adf43SDag-Erling Smørgravesac 183ce3adf43SDag-Erling Smørgrav 184bc5531deSDag-Erling Smørgrav# Record the actual binaries used. 185bc5531deSDag-Erling SmørgravSSH_BIN=${SSH} 186bc5531deSDag-Erling SmørgravSSHD_BIN=${SSHD} 187bc5531deSDag-Erling SmørgravSSHAGENT_BIN=${SSHAGENT} 188bc5531deSDag-Erling SmørgravSSHADD_BIN=${SSHADD} 189bc5531deSDag-Erling SmørgravSSHKEYGEN_BIN=${SSHKEYGEN} 190bc5531deSDag-Erling SmørgravSSHKEYSCAN_BIN=${SSHKEYSCAN} 191bc5531deSDag-Erling SmørgravSFTP_BIN=${SFTP} 192bc5531deSDag-Erling SmørgravSFTPSERVER_BIN=${SFTPSERVER} 193bc5531deSDag-Erling SmørgravSCP_BIN=${SCP} 194bc5531deSDag-Erling Smørgrav 195bc5531deSDag-Erling Smørgravif [ "x$USE_VALGRIND" != "x" ]; then 19619261079SEd Maste rm -rf $OBJ/valgrind-out $OBJ/valgrind-vgdb 19719261079SEd Maste mkdir -p $OBJ/valgrind-out $OBJ/valgrind-vgdb 19819261079SEd Maste # When using sudo ensure low-priv tests can write pipes and logs. 19919261079SEd Maste if [ "x$SUDO" != "x" ]; then 20019261079SEd Maste chmod 777 $OBJ/valgrind-out $OBJ/valgrind-vgdb 20119261079SEd Maste fi 202bc5531deSDag-Erling Smørgrav VG_TEST=`basename $SCRIPT .sh` 203bc5531deSDag-Erling Smørgrav 204bc5531deSDag-Erling Smørgrav # Some tests are difficult to fix. 205bc5531deSDag-Erling Smørgrav case "$VG_TEST" in 20619261079SEd Maste reexec) 207bc5531deSDag-Erling Smørgrav VG_SKIP=1 ;; 20819261079SEd Maste sftp-chroot) 20919261079SEd Maste if [ "x${SUDO}" != "x" ]; then 21019261079SEd Maste VG_SKIP=1 21119261079SEd Maste fi ;; 212bc5531deSDag-Erling Smørgrav esac 213bc5531deSDag-Erling Smørgrav 214bc5531deSDag-Erling Smørgrav if [ x"$VG_SKIP" = "x" ]; then 215190cef3dSDag-Erling Smørgrav VG_LEAK="--leak-check=no" 216190cef3dSDag-Erling Smørgrav if [ x"$VALGRIND_CHECK_LEAKS" != "x" ]; then 217190cef3dSDag-Erling Smørgrav VG_LEAK="--leak-check=full" 218190cef3dSDag-Erling Smørgrav fi 219bc5531deSDag-Erling Smørgrav VG_IGNORE="/bin/*,/sbin/*,/usr/*,/var/*" 220bc5531deSDag-Erling Smørgrav VG_LOG="$OBJ/valgrind-out/${VG_TEST}." 221190cef3dSDag-Erling Smørgrav VG_OPTS="--track-origins=yes $VG_LEAK" 222bc5531deSDag-Erling Smørgrav VG_OPTS="$VG_OPTS --trace-children=yes" 223bc5531deSDag-Erling Smørgrav VG_OPTS="$VG_OPTS --trace-children-skip=${VG_IGNORE}" 22419261079SEd Maste VG_OPTS="$VG_OPTS --vgdb-prefix=$OBJ/valgrind-vgdb/" 225bc5531deSDag-Erling Smørgrav VG_PATH="valgrind" 226bc5531deSDag-Erling Smørgrav if [ "x$VALGRIND_PATH" != "x" ]; then 227bc5531deSDag-Erling Smørgrav VG_PATH="$VALGRIND_PATH" 228bc5531deSDag-Erling Smørgrav fi 229bc5531deSDag-Erling Smørgrav VG="$VG_PATH $VG_OPTS" 230bc5531deSDag-Erling Smørgrav SSH="$VG --log-file=${VG_LOG}ssh.%p $SSH" 231bc5531deSDag-Erling Smørgrav SSHD="$VG --log-file=${VG_LOG}sshd.%p $SSHD" 232bc5531deSDag-Erling Smørgrav SSHAGENT="$VG --log-file=${VG_LOG}ssh-agent.%p $SSHAGENT" 233bc5531deSDag-Erling Smørgrav SSHADD="$VG --log-file=${VG_LOG}ssh-add.%p $SSHADD" 234bc5531deSDag-Erling Smørgrav SSHKEYGEN="$VG --log-file=${VG_LOG}ssh-keygen.%p $SSHKEYGEN" 235bc5531deSDag-Erling Smørgrav SSHKEYSCAN="$VG --log-file=${VG_LOG}ssh-keyscan.%p $SSHKEYSCAN" 236bc5531deSDag-Erling Smørgrav SFTP="$VG --log-file=${VG_LOG}sftp.%p ${SFTP}" 237bc5531deSDag-Erling Smørgrav SCP="$VG --log-file=${VG_LOG}scp.%p $SCP" 238bc5531deSDag-Erling Smørgrav cat > $OBJ/valgrind-sftp-server.sh << EOF 239bc5531deSDag-Erling Smørgrav#!/bin/sh 240bc5531deSDag-Erling Smørgravexec $VG --log-file=${VG_LOG}sftp-server.%p $SFTPSERVER "\$@" 241bc5531deSDag-Erling SmørgravEOF 242bc5531deSDag-Erling Smørgrav chmod a+rx $OBJ/valgrind-sftp-server.sh 243bc5531deSDag-Erling Smørgrav SFTPSERVER="$OBJ/valgrind-sftp-server.sh" 244bc5531deSDag-Erling Smørgrav fi 245bc5531deSDag-Erling Smørgravfi 246bc5531deSDag-Erling Smørgrav 247ce3adf43SDag-Erling Smørgrav# Logfiles. 248ce3adf43SDag-Erling Smørgrav# SSH_LOGFILE should be the debug output of ssh(1) only 249ce3adf43SDag-Erling Smørgrav# SSHD_LOGFILE should be the debug output of sshd(8) only 2504d3fc8b0SEd Maste# REGRESS_LOGFILE is the log of progress of the regress test itself. 2514d3fc8b0SEd Maste# TEST_SSH_LOGDIR will contain datestamped logs of all binaries run in 2524d3fc8b0SEd Maste# chronological order. 2534d3fc8b0SEd Masteif [ "x$TEST_SSH_LOGDIR" = "x" ]; then 2544d3fc8b0SEd Maste TEST_SSH_LOGDIR=$OBJ/log 2554d3fc8b0SEd Maste mkdir -p $TEST_SSH_LOGDIR 2564d3fc8b0SEd Mastefi 257ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSH_LOGFILE" = "x" ]; then 258ce3adf43SDag-Erling Smørgrav TEST_SSH_LOGFILE=$OBJ/ssh.log 259ce3adf43SDag-Erling Smørgravfi 260ce3adf43SDag-Erling Smørgravif [ "x$TEST_SSHD_LOGFILE" = "x" ]; then 261ce3adf43SDag-Erling Smørgrav TEST_SSHD_LOGFILE=$OBJ/sshd.log 262ce3adf43SDag-Erling Smørgravfi 263ce3adf43SDag-Erling Smørgravif [ "x$TEST_REGRESS_LOGFILE" = "x" ]; then 264ce3adf43SDag-Erling Smørgrav TEST_REGRESS_LOGFILE=$OBJ/regress.log 265ce3adf43SDag-Erling Smørgravfi 266ce3adf43SDag-Erling Smørgrav 26738a52bd3SEd Maste# If set, keep track of successful tests and skip them them if we've 26838a52bd3SEd Maste# previously completed that test. 26938a52bd3SEd Masteif [ "x$TEST_REGRESS_CACHE_DIR" != "x" ]; then 27038a52bd3SEd Maste if [ ! -d "$TEST_REGRESS_CACHE_DIR" ]; then 27138a52bd3SEd Maste mkdir -p "$TEST_REGRESS_CACHE_DIR" 27238a52bd3SEd Maste fi 27338a52bd3SEd Maste TEST="`basename $SCRIPT .sh`" 27438a52bd3SEd Maste CACHE="${TEST_REGRESS_CACHE_DIR}/${TEST}.cache" 27538a52bd3SEd Maste for i in ${SSH} ${SSHD} ${SSHAGENT} ${SSHADD} ${SSHKEYGEN} ${SCP} \ 27638a52bd3SEd Maste ${SFTP} ${SFTPSERVER} ${SSHKEYSCAN}; do 27738a52bd3SEd Maste case $i in 27838a52bd3SEd Maste /*) bin="$i" ;; 27938a52bd3SEd Maste *) bin="`which $i`" ;; 28038a52bd3SEd Maste esac 28138a52bd3SEd Maste if [ "$bin" -nt "$CACHE" ]; then 28238a52bd3SEd Maste rm -f "$CACHE" 28338a52bd3SEd Maste fi 28438a52bd3SEd Maste done 28538a52bd3SEd Maste if [ -f "$CACHE" ]; then 28638a52bd3SEd Maste echo ok cached $CACHE 28738a52bd3SEd Maste exit 0 28838a52bd3SEd Maste fi 28938a52bd3SEd Mastefi 29038a52bd3SEd Maste 291ce3adf43SDag-Erling Smørgrav# truncate logfiles 292ce3adf43SDag-Erling Smørgrav>$TEST_REGRESS_LOGFILE 293ce3adf43SDag-Erling Smørgrav 2944d3fc8b0SEd Maste# Create ssh and sshd wrappers with logging. These create a datestamped 2954d3fc8b0SEd Maste# unique file for every invocation so that we can retain all logs from a 2964d3fc8b0SEd Maste# given test no matter how many times it's invoked. It also leaves a 2974d3fc8b0SEd Maste# symlink with the original name for tests (and people) who look for that. 2984d3fc8b0SEd Maste 2994d3fc8b0SEd Maste# For ssh, e can't just specify "SSH=ssh -E..." because sftp and scp don't 3004d3fc8b0SEd Maste# handle spaces in arguments. scp and sftp like to use -q so we remove those 3014d3fc8b0SEd Maste# to preserve our debug logging. In the rare instance where -q is desirable 3024d3fc8b0SEd Maste# -qq is equivalent and is not removed. 303ce3adf43SDag-Erling SmørgravSSHLOGWRAP=$OBJ/ssh-log-wrapper.sh 30419261079SEd Mastecat >$SSHLOGWRAP <<EOD 30519261079SEd Maste#!/bin/sh 3064d3fc8b0SEd Mastetimestamp="\`$OBJ/timestamp\`" 3074d3fc8b0SEd Mastelogfile="${TEST_SSH_LOGDIR}/\${timestamp}.ssh.\$\$.log" 3084d3fc8b0SEd Masteecho "Executing: ${SSH} \$@" log \${logfile} >>$TEST_REGRESS_LOGFILE 3094d3fc8b0SEd Masteecho "Executing: ${SSH} \$@" >>\${logfile} 31019261079SEd Mastefor i in "\$@";do shift;case "\$i" in -q):;; *) set -- "\$@" "\$i";;esac;done 3114d3fc8b0SEd Masterm -f $TEST_SSH_LOGFILE 3124d3fc8b0SEd Masteln -f -s \${logfile} $TEST_SSH_LOGFILE 3134d3fc8b0SEd Masteexec ${SSH} -E\${logfile} "\$@" 31419261079SEd MasteEOD 315ce3adf43SDag-Erling Smørgrav 316ce3adf43SDag-Erling Smørgravchmod a+rx $OBJ/ssh-log-wrapper.sh 317076ad2f8SDag-Erling SmørgravREAL_SSH="$SSH" 31819261079SEd MasteREAL_SSHD="$SSHD" 319ce3adf43SDag-Erling SmørgravSSH="$SSHLOGWRAP" 320ce3adf43SDag-Erling Smørgrav 3214d3fc8b0SEd MasteSSHDLOGWRAP=$OBJ/sshd-log-wrapper.sh 3224d3fc8b0SEd Mastecat >$SSHDLOGWRAP <<EOD 3234d3fc8b0SEd Maste#!/bin/sh 3244d3fc8b0SEd Mastetimestamp="\`$OBJ/timestamp\`" 3254d3fc8b0SEd Mastelogfile="${TEST_SSH_LOGDIR}/\${timestamp}.sshd.\$\$.log" 3264d3fc8b0SEd Masterm -f $TEST_SSHD_LOGFILE 327069ac184SEd Mastetouch \$logfile 328069ac184SEd Mastetest -z "$SUDO" || chown $USER \$logfile 3294d3fc8b0SEd Masteln -f -s \${logfile} $TEST_SSHD_LOGFILE 3304d3fc8b0SEd Masteecho "Executing: ${SSHD} \$@" log \${logfile} >>$TEST_REGRESS_LOGFILE 3314d3fc8b0SEd Masteecho "Executing: ${SSHD} \$@" >>\${logfile} 3324d3fc8b0SEd Masteexec ${SSHD} -E\${logfile} "\$@" 3334d3fc8b0SEd MasteEOD 3344d3fc8b0SEd Mastechmod a+rx $OBJ/sshd-log-wrapper.sh 3354d3fc8b0SEd Maste 3364d3fc8b0SEd Mastessh_logfile () 3374d3fc8b0SEd Maste{ 3384d3fc8b0SEd Maste tool="$1" 3394d3fc8b0SEd Maste timestamp="`$OBJ/timestamp`" 3404d3fc8b0SEd Maste logfile="${TEST_SSH_LOGDIR}/${timestamp}.$tool.$$.log" 3414d3fc8b0SEd Maste echo "Logging $tool to log \${logfile}" >>$TEST_REGRESS_LOGFILE 3424d3fc8b0SEd Maste echo $logfile 3434d3fc8b0SEd Maste} 3444d3fc8b0SEd Maste 345ce3adf43SDag-Erling Smørgrav# Some test data. We make a copy because some tests will overwrite it. 346ce3adf43SDag-Erling Smørgrav# The tests may assume that $DATA exists and is writable and $COPY does 347f7167e0eSDag-Erling Smørgrav# not exist. Tests requiring larger data files can call increase_datafile_size 348f7167e0eSDag-Erling Smørgrav# [kbytes] to ensure the file is at least that large. 349ce3adf43SDag-Erling SmørgravDATANAME=data 350ce3adf43SDag-Erling SmørgravDATA=$OBJ/${DATANAME} 351bc5531deSDag-Erling Smørgravcat ${SSHAGENT_BIN} >${DATA} 352ce3adf43SDag-Erling Smørgravchmod u+w ${DATA} 353ce3adf43SDag-Erling SmørgravCOPY=$OBJ/copy 354ce3adf43SDag-Erling Smørgravrm -f ${COPY} 355ce3adf43SDag-Erling Smørgrav 356f7167e0eSDag-Erling Smørgravincrease_datafile_size() 357f7167e0eSDag-Erling Smørgrav{ 358f7167e0eSDag-Erling Smørgrav while [ `du -k ${DATA} | cut -f1` -lt $1 ]; do 359bc5531deSDag-Erling Smørgrav cat ${SSHAGENT_BIN} >>${DATA} 360f7167e0eSDag-Erling Smørgrav done 361f7167e0eSDag-Erling Smørgrav} 362f7167e0eSDag-Erling Smørgrav 363ce3adf43SDag-Erling Smørgrav# these should be used in tests 364ce3adf43SDag-Erling Smørgravexport SSH SSHD SSHAGENT SSHADD SSHKEYGEN SSHKEYSCAN SFTP SFTPSERVER SCP 36519261079SEd Masteexport SSH_PKCS11_HELPER SSH_SK_HELPER 366ce3adf43SDag-Erling Smørgrav#echo $SSH $SSHD $SSHAGENT $SSHADD $SSHKEYGEN $SSHKEYSCAN $SFTP $SFTPSERVER $SCP 367ce3adf43SDag-Erling Smørgrav 368ce3adf43SDag-Erling Smørgrav# Portable specific functions 36938a52bd3SEd Mastewhich() 370ce3adf43SDag-Erling Smørgrav{ 371ce3adf43SDag-Erling Smørgrav saved_IFS="$IFS" 372ce3adf43SDag-Erling Smørgrav IFS=":" 373ce3adf43SDag-Erling Smørgrav for i in $PATH 374ce3adf43SDag-Erling Smørgrav do 375ce3adf43SDag-Erling Smørgrav if [ -x $i/$1 ]; then 376ce3adf43SDag-Erling Smørgrav IFS="$saved_IFS" 37738a52bd3SEd Maste echo "$i/$1" 378ce3adf43SDag-Erling Smørgrav return 0 379ce3adf43SDag-Erling Smørgrav fi 380ce3adf43SDag-Erling Smørgrav done 381ce3adf43SDag-Erling Smørgrav IFS="$saved_IFS" 38238a52bd3SEd Maste echo "$i/$1" 383ce3adf43SDag-Erling Smørgrav return 1 384ce3adf43SDag-Erling Smørgrav} 385ce3adf43SDag-Erling Smørgrav 38638a52bd3SEd Mastehave_prog() 38738a52bd3SEd Maste{ 38838a52bd3SEd Maste which "$1" >/dev/null 2>&1 38938a52bd3SEd Maste return $? 39038a52bd3SEd Maste} 39138a52bd3SEd Maste 392ce3adf43SDag-Erling Smørgravjot() { 393ce3adf43SDag-Erling Smørgrav awk "BEGIN { for (i = $2; i < $2 + $1; i++) { printf \"%d\n\", i } exit }" 394ce3adf43SDag-Erling Smørgrav} 3951323ec57SEd Masteif [ ! -x "`which rev`" ]; then 3961323ec57SEd Masterev() 3971323ec57SEd Maste{ 3981323ec57SEd Maste awk '{for (i=length; i>0; i--) printf "%s", substr($0, i, 1); print ""}' 3991323ec57SEd Maste} 4001323ec57SEd Mastefi 401ce3adf43SDag-Erling Smørgrav 402ce3adf43SDag-Erling Smørgrav# Check whether preprocessor symbols are defined in config.h. 403ce3adf43SDag-Erling Smørgravconfig_defined () 404ce3adf43SDag-Erling Smørgrav{ 405ce3adf43SDag-Erling Smørgrav str=$1 406ce3adf43SDag-Erling Smørgrav while test "x$2" != "x" ; do 407ce3adf43SDag-Erling Smørgrav str="$str|$2" 408ce3adf43SDag-Erling Smørgrav shift 409ce3adf43SDag-Erling Smørgrav done 410ce3adf43SDag-Erling Smørgrav egrep "^#define.*($str)" ${BUILDDIR}/config.h >/dev/null 2>&1 411ce3adf43SDag-Erling Smørgrav} 412ce3adf43SDag-Erling Smørgrav 413ce3adf43SDag-Erling Smørgravmd5 () { 414ce3adf43SDag-Erling Smørgrav if have_prog md5sum; then 415ce3adf43SDag-Erling Smørgrav md5sum 416ce3adf43SDag-Erling Smørgrav elif have_prog openssl; then 417ce3adf43SDag-Erling Smørgrav openssl md5 418ce3adf43SDag-Erling Smørgrav elif have_prog cksum; then 419ce3adf43SDag-Erling Smørgrav cksum 420ce3adf43SDag-Erling Smørgrav elif have_prog sum; then 421ce3adf43SDag-Erling Smørgrav sum 42219261079SEd Maste elif [ -x ${OPENSSL_BIN} ]; then 42319261079SEd Maste ${OPENSSL_BIN} md5 424ce3adf43SDag-Erling Smørgrav else 425ce3adf43SDag-Erling Smørgrav wc -c 426ce3adf43SDag-Erling Smørgrav fi 427ce3adf43SDag-Erling Smørgrav} 42819261079SEd Maste 42919261079SEd Maste# Some platforms don't have hostname at all, but on others uname -n doesn't 43019261079SEd Maste# provide the fully qualified name we need, so in the former case we create 43119261079SEd Maste# our own hostname function. 43219261079SEd Masteif ! have_prog hostname; then 43319261079SEd Maste hostname() { 43419261079SEd Maste uname -n 43519261079SEd Maste } 43619261079SEd Mastefi 43719261079SEd Maste 43819261079SEd Mastemake_tmpdir () 43919261079SEd Maste{ 44019261079SEd Maste SSH_REGRESS_TMP="$($OBJ/mkdtemp openssh-XXXXXXXX)" || \ 44119261079SEd Maste fatal "failed to create temporary directory" 44219261079SEd Maste} 443ce3adf43SDag-Erling Smørgrav# End of portable specific functions 444ce3adf43SDag-Erling Smørgrav 445ca86bcf2SDag-Erling Smørgravstop_sshd () 446ce3adf43SDag-Erling Smørgrav{ 447ce3adf43SDag-Erling Smørgrav if [ -f $PIDFILE ]; then 448ce3adf43SDag-Erling Smørgrav pid=`$SUDO cat $PIDFILE` 449ce3adf43SDag-Erling Smørgrav if [ "X$pid" = "X" ]; then 450ce3adf43SDag-Erling Smørgrav echo no sshd running 451ce3adf43SDag-Erling Smørgrav else 452ce3adf43SDag-Erling Smørgrav if [ $pid -lt 2 ]; then 453a0ee8cc6SDag-Erling Smørgrav echo bad pid for sshd: $pid 454ce3adf43SDag-Erling Smørgrav else 455ce3adf43SDag-Erling Smørgrav $SUDO kill $pid 456ce3adf43SDag-Erling Smørgrav trace "wait for sshd to exit" 457ce3adf43SDag-Erling Smørgrav i=0; 458ce3adf43SDag-Erling Smørgrav while [ -f $PIDFILE -a $i -lt 5 ]; do 459ce3adf43SDag-Erling Smørgrav i=`expr $i + 1` 460ce3adf43SDag-Erling Smørgrav sleep $i 461ce3adf43SDag-Erling Smørgrav done 4624f52dfbbSDag-Erling Smørgrav if test -f $PIDFILE; then 4634f52dfbbSDag-Erling Smørgrav if $SUDO kill -0 $pid; then 4644f52dfbbSDag-Erling Smørgrav echo "sshd didn't exit " \ 4654f52dfbbSDag-Erling Smørgrav "port $PORT pid $pid" 4664f52dfbbSDag-Erling Smørgrav else 4674f52dfbbSDag-Erling Smørgrav echo "sshd died without cleanup" 4684f52dfbbSDag-Erling Smørgrav fi 4694f52dfbbSDag-Erling Smørgrav exit 1 4704f52dfbbSDag-Erling Smørgrav fi 471ce3adf43SDag-Erling Smørgrav fi 472ce3adf43SDag-Erling Smørgrav fi 473ce3adf43SDag-Erling Smørgrav fi 474ce3adf43SDag-Erling Smørgrav} 475ce3adf43SDag-Erling Smørgrav 476ca86bcf2SDag-Erling Smørgrav# helper 477ca86bcf2SDag-Erling Smørgravcleanup () 478ca86bcf2SDag-Erling Smørgrav{ 479ca86bcf2SDag-Erling Smørgrav if [ "x$SSH_PID" != "x" ]; then 480ca86bcf2SDag-Erling Smørgrav if [ $SSH_PID -lt 2 ]; then 481ca86bcf2SDag-Erling Smørgrav echo bad pid for ssh: $SSH_PID 482ca86bcf2SDag-Erling Smørgrav else 483ca86bcf2SDag-Erling Smørgrav kill $SSH_PID 484ca86bcf2SDag-Erling Smørgrav fi 485ca86bcf2SDag-Erling Smørgrav fi 486190cef3dSDag-Erling Smørgrav if [ "x$SSH_REGRESS_TMP" != "x" ]; then 487190cef3dSDag-Erling Smørgrav rm -rf "$SSH_REGRESS_TMP" 488190cef3dSDag-Erling Smørgrav fi 489ca86bcf2SDag-Erling Smørgrav stop_sshd 49019261079SEd Maste if [ ! -z "$TEST_SSH_ELAPSED_TIMES" ]; then 49119261079SEd Maste now=`date '+%s'` 49219261079SEd Maste elapsed=$(($now - $STARTTIME)) 49319261079SEd Maste echo elapsed $elapsed `basename $SCRIPT .sh` 49419261079SEd Maste fi 495ca86bcf2SDag-Erling Smørgrav} 496ca86bcf2SDag-Erling Smørgrav 497ce3adf43SDag-Erling Smørgravstart_debug_log () 498ce3adf43SDag-Erling Smørgrav{ 4994d3fc8b0SEd Maste echo "trace: $@" >>$TEST_REGRESS_LOGFILE 5004d3fc8b0SEd Maste if [ -d "$TEST_SSH_LOGDIR" ]; then 5014d3fc8b0SEd Maste rm -f $TEST_SSH_LOGDIR/* 5024d3fc8b0SEd Maste fi 503ce3adf43SDag-Erling Smørgrav} 504ce3adf43SDag-Erling Smørgrav 505ce3adf43SDag-Erling Smørgravsave_debug_log () 506ce3adf43SDag-Erling Smørgrav{ 5074d3fc8b0SEd Maste testname=`echo $tid | tr ' ' _` 5084d3fc8b0SEd Maste tarname="$OBJ/failed-$testname-logs.tar" 5094d3fc8b0SEd Maste 510069ac184SEd Maste for logfile in $TEST_SSH_LOGDIR $TEST_REGRESS_LOGFILE \ 511069ac184SEd Maste $TEST_SSH_LOGFILE $TEST_SSHD_LOGFILE; do 512069ac184SEd Maste if [ ! -z "$SUDO" ] && [ -f "$logfile" ]; then 513069ac184SEd Maste $SUDO chown -R $USER $logfile 514069ac184SEd Maste fi 515069ac184SEd Maste done 516ce3adf43SDag-Erling Smørgrav echo $@ >>$TEST_REGRESS_LOGFILE 517ce3adf43SDag-Erling Smørgrav echo $@ >>$TEST_SSH_LOGFILE 518ce3adf43SDag-Erling Smørgrav echo $@ >>$TEST_SSHD_LOGFILE 5194d3fc8b0SEd Maste echo "Saving debug logs to $tarname" >>$TEST_REGRESS_LOGFILE 520ce3adf43SDag-Erling Smørgrav (cat $TEST_REGRESS_LOGFILE; echo) >>$OBJ/failed-regress.log 521ce3adf43SDag-Erling Smørgrav (cat $TEST_SSH_LOGFILE; echo) >>$OBJ/failed-ssh.log 522ce3adf43SDag-Erling Smørgrav (cat $TEST_SSHD_LOGFILE; echo) >>$OBJ/failed-sshd.log 5234d3fc8b0SEd Maste 5244d3fc8b0SEd Maste # Save all logfiles in a tarball. 5254d3fc8b0SEd Maste (cd $OBJ && 5264d3fc8b0SEd Maste logfiles="" 5274d3fc8b0SEd Maste for i in $TEST_REGRESS_LOGFILE $TEST_SSH_LOGFILE $TEST_SSHD_LOGFILE \ 5284d3fc8b0SEd Maste $TEST_SSH_LOGDIR; do 5294d3fc8b0SEd Maste if [ -e "`basename $i`" ]; then 5304d3fc8b0SEd Maste logfiles="$logfiles `basename $i`" 5314d3fc8b0SEd Maste else 5324d3fc8b0SEd Maste logfiles="$logfiles $i" 5334d3fc8b0SEd Maste fi 5344d3fc8b0SEd Maste done 5354d3fc8b0SEd Maste tar cf "$tarname" $logfiles) 536ce3adf43SDag-Erling Smørgrav} 537ce3adf43SDag-Erling Smørgrav 538ce3adf43SDag-Erling Smørgravtrace () 539ce3adf43SDag-Erling Smørgrav{ 540ce3adf43SDag-Erling Smørgrav start_debug_log $@ 541ce3adf43SDag-Erling Smørgrav if [ "X$TEST_SSH_TRACE" = "Xyes" ]; then 542ce3adf43SDag-Erling Smørgrav echo "$@" 543ce3adf43SDag-Erling Smørgrav fi 544ce3adf43SDag-Erling Smørgrav} 545ce3adf43SDag-Erling Smørgrav 546ce3adf43SDag-Erling Smørgravverbose () 547ce3adf43SDag-Erling Smørgrav{ 548ce3adf43SDag-Erling Smørgrav start_debug_log $@ 549ce3adf43SDag-Erling Smørgrav if [ "X$TEST_SSH_QUIET" != "Xyes" ]; then 550ce3adf43SDag-Erling Smørgrav echo "$@" 551ce3adf43SDag-Erling Smørgrav fi 552ce3adf43SDag-Erling Smørgrav} 553ce3adf43SDag-Erling Smørgrav 554ce3adf43SDag-Erling Smørgravfail () 555ce3adf43SDag-Erling Smørgrav{ 556ce3adf43SDag-Erling Smørgrav save_debug_log "FAIL: $@" 557ce3adf43SDag-Erling Smørgrav RESULT=1 558ce3adf43SDag-Erling Smørgrav echo "$@" 559190cef3dSDag-Erling Smørgrav if test "x$TEST_SSH_FAIL_FATAL" != "x" ; then 560190cef3dSDag-Erling Smørgrav cleanup 561190cef3dSDag-Erling Smørgrav exit $RESULT 562190cef3dSDag-Erling Smørgrav fi 563ce3adf43SDag-Erling Smørgrav} 564ce3adf43SDag-Erling Smørgrav 565ce3adf43SDag-Erling Smørgravfatal () 566ce3adf43SDag-Erling Smørgrav{ 567ce3adf43SDag-Erling Smørgrav save_debug_log "FATAL: $@" 568ce3adf43SDag-Erling Smørgrav printf "FATAL: " 569ce3adf43SDag-Erling Smørgrav fail "$@" 570ce3adf43SDag-Erling Smørgrav cleanup 571ce3adf43SDag-Erling Smørgrav exit $RESULT 572ce3adf43SDag-Erling Smørgrav} 573ce3adf43SDag-Erling Smørgrav 574e9e8876aSEd Maste# Skip remaining tests in script. 575e9e8876aSEd Masteskip () 576e9e8876aSEd Maste{ 577e9e8876aSEd Maste echo "SKIPPED: $@" 578e9e8876aSEd Maste cleanup 579e9e8876aSEd Maste exit $RESULT 580e9e8876aSEd Maste} 581e9e8876aSEd Maste 582f374ba41SEd Mastemaybe_add_scp_path_to_sshd () 583f374ba41SEd Maste{ 584f374ba41SEd Maste # If we're testing a non-installed scp, add its directory to sshd's 585f374ba41SEd Maste # PATH so we can test it. We don't do this for all tests as it 586f374ba41SEd Maste # breaks the SetEnv tests. 587f374ba41SEd Maste case "$SCP" in 588f374ba41SEd Maste /*) PATH_WITH_SCP="`dirname $SCP`:$PATH" 589f374ba41SEd Maste echo " SetEnv PATH='$PATH_WITH_SCP'" >>$OBJ/sshd_config 590f374ba41SEd Maste echo " SetEnv PATH='$PATH_WITH_SCP'" >>$OBJ/sshd_proxy ;; 591f374ba41SEd Maste esac 592f374ba41SEd Maste} 593f374ba41SEd Maste 594ce3adf43SDag-Erling SmørgravRESULT=0 595ce3adf43SDag-Erling SmørgravPIDFILE=$OBJ/pidfile 596ce3adf43SDag-Erling Smørgrav 597ce3adf43SDag-Erling Smørgravtrap fatal 3 2 598ce3adf43SDag-Erling Smørgrav 599ce3adf43SDag-Erling Smørgrav# create server config 600ce3adf43SDag-Erling Smørgravcat << EOF > $OBJ/sshd_config 601ce3adf43SDag-Erling Smørgrav StrictModes no 602ce3adf43SDag-Erling Smørgrav Port $PORT 603ce3adf43SDag-Erling Smørgrav AddressFamily inet 604ce3adf43SDag-Erling Smørgrav ListenAddress 127.0.0.1 605ce3adf43SDag-Erling Smørgrav #ListenAddress ::1 606ce3adf43SDag-Erling Smørgrav PidFile $PIDFILE 607ce3adf43SDag-Erling Smørgrav AuthorizedKeysFile $OBJ/authorized_keys_%u 608ce3adf43SDag-Erling Smørgrav LogLevel DEBUG3 609ce3adf43SDag-Erling Smørgrav AcceptEnv _XXX_TEST_* 610ce3adf43SDag-Erling Smørgrav AcceptEnv _XXX_TEST 611ce3adf43SDag-Erling Smørgrav Subsystem sftp $SFTPSERVER 612ce3adf43SDag-Erling SmørgravEOF 613ce3adf43SDag-Erling Smørgrav 614076ad2f8SDag-Erling Smørgrav# This may be necessary if /usr/src and/or /usr/obj are group-writable, 615076ad2f8SDag-Erling Smørgrav# but if you aren't careful with permissions then the unit tests could 616076ad2f8SDag-Erling Smørgrav# be abused to locally escalate privileges. 617076ad2f8SDag-Erling Smørgravif [ ! -z "$TEST_SSH_UNSAFE_PERMISSIONS" ]; then 618076ad2f8SDag-Erling Smørgrav echo " StrictModes no" >> $OBJ/sshd_config 61919261079SEd Masteelse 62019261079SEd Maste # check and warn if excessive permissions are likely to cause failures. 62119261079SEd Maste unsafe="" 62219261079SEd Maste dir="${OBJ}" 62319261079SEd Maste while test ${dir} != "/"; do 62419261079SEd Maste if test -d "${dir}" && ! test -h "${dir}"; then 62519261079SEd Maste perms=`ls -ld ${dir}` 62619261079SEd Maste case "${perms}" in 62719261079SEd Maste ?????w????*|????????w?*) unsafe="${unsafe} ${dir}" ;; 62819261079SEd Maste esac 62919261079SEd Maste fi 63019261079SEd Maste dir=`dirname ${dir}` 63119261079SEd Maste done 63219261079SEd Maste if ! test -z "${unsafe}"; then 63319261079SEd Maste cat <<EOD 63419261079SEd Maste 63519261079SEd MasteWARNING: Unsafe (group or world writable) directory permissions found: 63619261079SEd Maste${unsafe} 63719261079SEd Maste 63819261079SEd MasteThese could be abused to locally escalate privileges. If you are 63919261079SEd Mastesure that this is not a risk (eg there are no other users), you can 64019261079SEd Mastebypass this check by setting TEST_SSH_UNSAFE_PERMISSIONS=1 64119261079SEd Maste 64219261079SEd MasteEOD 64319261079SEd Maste fi 64419261079SEd Mastefi 64519261079SEd Maste 64619261079SEd Masteif [ ! -z "$TEST_SSH_MODULI_FILE" ]; then 64719261079SEd Maste trace "adding modulifile='$TEST_SSH_MODULI_FILE' to sshd_config" 64819261079SEd Maste echo " ModuliFile '$TEST_SSH_MODULI_FILE'" >> $OBJ/sshd_config 649076ad2f8SDag-Erling Smørgravfi 650076ad2f8SDag-Erling Smørgrav 651ce3adf43SDag-Erling Smørgravif [ ! -z "$TEST_SSH_SSHD_CONFOPTS" ]; then 652ce3adf43SDag-Erling Smørgrav trace "adding sshd_config option $TEST_SSH_SSHD_CONFOPTS" 653ce3adf43SDag-Erling Smørgrav echo "$TEST_SSH_SSHD_CONFOPTS" >> $OBJ/sshd_config 654ce3adf43SDag-Erling Smørgravfi 655ce3adf43SDag-Erling Smørgrav 656ce3adf43SDag-Erling Smørgrav# server config for proxy connects 657ce3adf43SDag-Erling Smørgravcp $OBJ/sshd_config $OBJ/sshd_proxy 658ce3adf43SDag-Erling Smørgrav 659ce3adf43SDag-Erling Smørgrav# allow group-writable directories in proxy-mode 660ce3adf43SDag-Erling Smørgravecho 'StrictModes no' >> $OBJ/sshd_proxy 661ce3adf43SDag-Erling Smørgrav 662ce3adf43SDag-Erling Smørgrav# create client config 663ce3adf43SDag-Erling Smørgravcat << EOF > $OBJ/ssh_config 664ce3adf43SDag-Erling SmørgravHost * 665ce3adf43SDag-Erling Smørgrav Hostname 127.0.0.1 666ce3adf43SDag-Erling Smørgrav HostKeyAlias localhost-with-alias 667ce3adf43SDag-Erling Smørgrav Port $PORT 668ce3adf43SDag-Erling Smørgrav User $USER 669ce3adf43SDag-Erling Smørgrav GlobalKnownHostsFile $OBJ/known_hosts 670ce3adf43SDag-Erling Smørgrav UserKnownHostsFile $OBJ/known_hosts 671ce3adf43SDag-Erling Smørgrav PubkeyAuthentication yes 672ce3adf43SDag-Erling Smørgrav ChallengeResponseAuthentication no 673ce3adf43SDag-Erling Smørgrav PasswordAuthentication no 674ce3adf43SDag-Erling Smørgrav BatchMode yes 675ce3adf43SDag-Erling Smørgrav StrictHostKeyChecking yes 676ce3adf43SDag-Erling Smørgrav LogLevel DEBUG3 677ce3adf43SDag-Erling SmørgravEOF 678ce3adf43SDag-Erling Smørgrav 679ce3adf43SDag-Erling Smørgravif [ ! -z "$TEST_SSH_SSH_CONFOPTS" ]; then 680557f75e5SDag-Erling Smørgrav trace "adding ssh_config option $TEST_SSH_SSH_CONFOPTS" 681ce3adf43SDag-Erling Smørgrav echo "$TEST_SSH_SSH_CONFOPTS" >> $OBJ/ssh_config 682ce3adf43SDag-Erling Smørgravfi 683ce3adf43SDag-Erling Smørgrav 684ce3adf43SDag-Erling Smørgravrm -f $OBJ/known_hosts $OBJ/authorized_keys_$USER 685ce3adf43SDag-Erling Smørgrav 68619261079SEd MasteSSH_SK_PROVIDER= 68719261079SEd Masteif ! config_defined ENABLE_SK; then 68819261079SEd Maste trace skipping sk-dummy 68919261079SEd Masteelif [ -f "${SRC}/misc/sk-dummy/obj/sk-dummy.so" ] ; then 69019261079SEd Maste SSH_SK_PROVIDER="${SRC}/misc/sk-dummy/obj/sk-dummy.so" 6911323ec57SEd Masteelif [ -f "${OBJ}/misc/sk-dummy/sk-dummy.so" ] ; then 6921323ec57SEd Maste SSH_SK_PROVIDER="${OBJ}/misc/sk-dummy/sk-dummy.so" 69319261079SEd Masteelif [ -f "${SRC}/misc/sk-dummy/sk-dummy.so" ] ; then 69419261079SEd Maste SSH_SK_PROVIDER="${SRC}/misc/sk-dummy/sk-dummy.so" 69519261079SEd Mastefi 69619261079SEd Masteexport SSH_SK_PROVIDER 6974f52dfbbSDag-Erling Smørgrav 69819261079SEd Masteif ! test -z "$SSH_SK_PROVIDER"; then 69919261079SEd Maste EXTRA_AGENT_ARGS='-P/*' # XXX want realpath(1)... 70019261079SEd Maste echo "SecurityKeyProvider $SSH_SK_PROVIDER" >> $OBJ/ssh_config 70119261079SEd Maste echo "SecurityKeyProvider $SSH_SK_PROVIDER" >> $OBJ/sshd_config 70219261079SEd Maste echo "SecurityKeyProvider $SSH_SK_PROVIDER" >> $OBJ/sshd_proxy 70319261079SEd Mastefi 70419261079SEd Masteexport EXTRA_AGENT_ARGS 70519261079SEd Maste 70619261079SEd Mastemaybe_filter_sk() { 70719261079SEd Maste if test -z "$SSH_SK_PROVIDER" ; then 70819261079SEd Maste grep -v ^sk 70919261079SEd Maste else 71019261079SEd Maste cat 71119261079SEd Maste fi 71219261079SEd Maste} 71319261079SEd Maste 71419261079SEd MasteSSH_KEYTYPES=`$SSH -Q key-plain | maybe_filter_sk` 71519261079SEd MasteSSH_HOSTKEY_TYPES=`$SSH -Q key-plain | maybe_filter_sk` 71619261079SEd Maste 717bc5531deSDag-Erling Smørgravfor t in ${SSH_KEYTYPES}; do 718ce3adf43SDag-Erling Smørgrav # generate user key 719bc5531deSDag-Erling Smørgrav if [ ! -f $OBJ/$t ] || [ ${SSHKEYGEN_BIN} -nt $OBJ/$t ]; then 72019261079SEd Maste trace "generating key type $t" 721ce3adf43SDag-Erling Smørgrav rm -f $OBJ/$t 722ce3adf43SDag-Erling Smørgrav ${SSHKEYGEN} -q -N '' -t $t -f $OBJ/$t ||\ 723ce3adf43SDag-Erling Smørgrav fail "ssh-keygen for $t failed" 72419261079SEd Maste else 72519261079SEd Maste trace "using cached key type $t" 726ce3adf43SDag-Erling Smørgrav fi 727ce3adf43SDag-Erling Smørgrav 72819261079SEd Maste # setup authorized keys 72919261079SEd Maste cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER 73019261079SEd Maste echo IdentityFile $OBJ/$t >> $OBJ/ssh_config 73119261079SEd Mastedone 73219261079SEd Maste 73319261079SEd Mastefor t in ${SSH_HOSTKEY_TYPES}; do 734ce3adf43SDag-Erling Smørgrav # known hosts file for client 735ce3adf43SDag-Erling Smørgrav ( 736ce3adf43SDag-Erling Smørgrav printf 'localhost-with-alias,127.0.0.1,::1 ' 737ce3adf43SDag-Erling Smørgrav cat $OBJ/$t.pub 738ce3adf43SDag-Erling Smørgrav ) >> $OBJ/known_hosts 739ce3adf43SDag-Erling Smørgrav 740ce3adf43SDag-Erling Smørgrav # use key as host key, too 74119261079SEd Maste (umask 077; $SUDO cp $OBJ/$t $OBJ/host.$t) 742ce3adf43SDag-Erling Smørgrav echo HostKey $OBJ/host.$t >> $OBJ/sshd_config 743ce3adf43SDag-Erling Smørgrav 744ce3adf43SDag-Erling Smørgrav # don't use SUDO for proxy connect 745ce3adf43SDag-Erling Smørgrav echo HostKey $OBJ/$t >> $OBJ/sshd_proxy 746ce3adf43SDag-Erling Smørgravdone 747ce3adf43SDag-Erling Smørgravchmod 644 $OBJ/authorized_keys_$USER 748ce3adf43SDag-Erling Smørgrav 749ce3adf43SDag-Erling Smørgrav# Activate Twisted Conch tests if the binary is present 750ce3adf43SDag-Erling SmørgravREGRESS_INTEROP_CONCH=no 751ce3adf43SDag-Erling Smørgravif test -x "$CONCH" ; then 752ce3adf43SDag-Erling Smørgrav REGRESS_INTEROP_CONCH=yes 753ce3adf43SDag-Erling Smørgravfi 754ce3adf43SDag-Erling Smørgrav 75519261079SEd Maste# If PuTTY is present, new enough and we are running a PuTTY test, prepare 75619261079SEd Maste# keys and configuration. 757ce3adf43SDag-Erling SmørgravREGRESS_INTEROP_PUTTY=no 75819261079SEd Masteif test -x "$PUTTYGEN" -a -x "$PLINK" && 75919261079SEd Maste "$PUTTYGEN" --help 2>&1 | grep -- --new-passphrase >/dev/null; then 760ce3adf43SDag-Erling Smørgrav REGRESS_INTEROP_PUTTY=yes 761ce3adf43SDag-Erling Smørgravfi 762ce3adf43SDag-Erling Smørgravcase "$SCRIPT" in 763ce3adf43SDag-Erling Smørgrav*putty*) ;; 764ce3adf43SDag-Erling Smørgrav*) REGRESS_INTEROP_PUTTY=no ;; 765ce3adf43SDag-Erling Smørgravesac 766ce3adf43SDag-Erling Smørgrav 767a91a2465SEd Masteputtysetup() { 768a91a2465SEd Maste if test "x$REGRESS_INTEROP_PUTTY" != "xyes" ; then 769a91a2465SEd Maste skip "putty interop tests not enabled" 770a91a2465SEd Maste fi 771a91a2465SEd Maste 772ce3adf43SDag-Erling Smørgrav mkdir -p ${OBJ}/.putty 773ce3adf43SDag-Erling Smørgrav 774ce3adf43SDag-Erling Smørgrav # Add a PuTTY key to authorized_keys 775ce3adf43SDag-Erling Smørgrav rm -f ${OBJ}/putty.rsa2 77619261079SEd Maste if ! "$PUTTYGEN" -t rsa -o ${OBJ}/putty.rsa2 \ 77747dd1d1bSDag-Erling Smørgrav --random-device=/dev/urandom \ 778ca86bcf2SDag-Erling Smørgrav --new-passphrase /dev/null < /dev/null > /dev/null; then 77919261079SEd Maste echo "Your installed version of PuTTY is too old to support --new-passphrase, skipping test" >&2 78019261079SEd Maste exit 1 781ca86bcf2SDag-Erling Smørgrav fi 78219261079SEd Maste "$PUTTYGEN" -O public-openssh ${OBJ}/putty.rsa2 \ 783ce3adf43SDag-Erling Smørgrav >> $OBJ/authorized_keys_$USER 784ce3adf43SDag-Erling Smørgrav 785ce3adf43SDag-Erling Smørgrav # Convert rsa2 host key to PuTTY format 78619261079SEd Maste cp $OBJ/ssh-rsa $OBJ/ssh-rsa_oldfmt 78719261079SEd Maste ${SSHKEYGEN} -p -N '' -m PEM -f $OBJ/ssh-rsa_oldfmt >/dev/null 78819261079SEd Maste ${SRC}/ssh2putty.sh 127.0.0.1 $PORT $OBJ/ssh-rsa_oldfmt > \ 789ce3adf43SDag-Erling Smørgrav ${OBJ}/.putty/sshhostkeys 79019261079SEd Maste ${SRC}/ssh2putty.sh 127.0.0.1 22 $OBJ/ssh-rsa_oldfmt >> \ 791ce3adf43SDag-Erling Smørgrav ${OBJ}/.putty/sshhostkeys 79219261079SEd Maste rm -f $OBJ/ssh-rsa_oldfmt 793ce3adf43SDag-Erling Smørgrav 794ce3adf43SDag-Erling Smørgrav # Setup proxied session 795ce3adf43SDag-Erling Smørgrav mkdir -p ${OBJ}/.putty/sessions 796ce3adf43SDag-Erling Smørgrav rm -f ${OBJ}/.putty/sessions/localhost_proxy 797ca86bcf2SDag-Erling Smørgrav echo "Protocol=ssh" >> ${OBJ}/.putty/sessions/localhost_proxy 798ca86bcf2SDag-Erling Smørgrav echo "HostName=127.0.0.1" >> ${OBJ}/.putty/sessions/localhost_proxy 799ce3adf43SDag-Erling Smørgrav echo "PortNumber=$PORT" >> ${OBJ}/.putty/sessions/localhost_proxy 800ce3adf43SDag-Erling Smørgrav echo "ProxyMethod=5" >> ${OBJ}/.putty/sessions/localhost_proxy 8014d3fc8b0SEd Maste echo "ProxyTelnetCommand=${OBJ}/sshd-log-wrapper.sh -i -f $OBJ/sshd_proxy" >> ${OBJ}/.putty/sessions/localhost_proxy 802ca86bcf2SDag-Erling Smørgrav echo "ProxyLocalhost=1" >> ${OBJ}/.putty/sessions/localhost_proxy 803ce3adf43SDag-Erling Smørgrav 804a91a2465SEd Maste PUTTYVER="`${PLINK} --version | awk '/plink: Release/{print $3}'`" 805a91a2465SEd Maste PUTTYMINORVER="`echo ${PUTTYVER} | cut -f2 -d.`" 806a91a2465SEd Maste verbose "plink version ${PUTTYVER} minor ${PUTTYMINORVER}" 807a91a2465SEd Maste 808a91a2465SEd Maste # Re-enable ssh-rsa on older PuTTY versions since they don't do newer 809a91a2465SEd Maste # key types. 810a91a2465SEd Maste if [ "$PUTTYMINORVER" -lt "76" ]; then 811a91a2465SEd Maste echo "HostKeyAlgorithms +ssh-rsa" >> ${OBJ}/sshd_proxy 812a91a2465SEd Maste echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> ${OBJ}/sshd_proxy 813a91a2465SEd Maste fi 814a91a2465SEd Maste 815a91a2465SEd Maste if [ "$PUTTYMINORVER" -le "64" ]; then 816a91a2465SEd Maste echo "KexAlgorithms +diffie-hellman-group14-sha1" \ 817a91a2465SEd Maste >>${OBJ}/sshd_proxy 818a91a2465SEd Maste fi 81947dd1d1bSDag-Erling Smørgrav PUTTYDIR=${OBJ}/.putty 82047dd1d1bSDag-Erling Smørgrav export PUTTYDIR 821a91a2465SEd Maste} 822ce3adf43SDag-Erling Smørgrav 823069ac184SEd MasteREGRESS_INTEROP_DROPBEAR=no 824069ac184SEd Masteif test -x "$DROPBEARKEY" -a -x "$DBCLIENT" -a -x "$DROPBEARCONVERT"; then 825069ac184SEd Maste REGRESS_INTEROP_DROPBEAR=yes 826069ac184SEd Mastefi 827069ac184SEd Mastecase "$SCRIPT" in 828069ac184SEd Maste*dropbear*) ;; 829069ac184SEd Maste*) REGRESS_INTEROP_DROPBEAR=no ;; 830069ac184SEd Masteesac 831069ac184SEd Maste 832069ac184SEd Masteif test "$REGRESS_INTEROP_DROPBEAR" = "yes" ; then 833069ac184SEd Maste trace Create dropbear keys and add to authorized_keys 834069ac184SEd Maste mkdir -p $OBJ/.dropbear 835069ac184SEd Maste for i in rsa ecdsa ed25519 dss; do 836069ac184SEd Maste if [ ! -f "$OBJ/.dropbear/id_$i" ]; then 837069ac184SEd Maste ($DROPBEARKEY -t $i -f $OBJ/.dropbear/id_$i 838069ac184SEd Maste $DROPBEARCONVERT dropbear openssh \ 839069ac184SEd Maste $OBJ/.dropbear/id_$i $OBJ/.dropbear/ossh.id_$i 840069ac184SEd Maste ) > /dev/null 2>&1 841069ac184SEd Maste fi 842069ac184SEd Maste $SSHKEYGEN -y -f $OBJ/.dropbear/ossh.id_$i \ 843069ac184SEd Maste >>$OBJ/authorized_keys_$USER 844069ac184SEd Maste done 845069ac184SEd Mastefi 846069ac184SEd Maste 847ce3adf43SDag-Erling Smørgrav# create a proxy version of the client config 848ce3adf43SDag-Erling Smørgrav( 849ce3adf43SDag-Erling Smørgrav cat $OBJ/ssh_config 8504d3fc8b0SEd Maste echo proxycommand ${SUDO} env SSH_SK_HELPER=\"$SSH_SK_HELPER\" ${OBJ}/sshd-log-wrapper.sh -i -f $OBJ/sshd_proxy 851ce3adf43SDag-Erling Smørgrav) > $OBJ/ssh_proxy 852ce3adf43SDag-Erling Smørgrav 853ce3adf43SDag-Erling Smørgrav# check proxy config 854ce3adf43SDag-Erling Smørgrav${SSHD} -t -f $OBJ/sshd_proxy || fatal "sshd_proxy broken" 855ce3adf43SDag-Erling Smørgrav 856069ac184SEd Maste# extract proxycommand into separate shell script for use by Dropbear. 857069ac184SEd Masteecho '#!/bin/sh' >$OBJ/ssh_proxy.sh 858069ac184SEd Masteawk '/^proxycommand/' $OBJ/ssh_proxy | sed 's/^proxycommand//' \ 859069ac184SEd Maste >>$OBJ/ssh_proxy.sh 860069ac184SEd Mastechmod a+x $OBJ/ssh_proxy.sh 861069ac184SEd Maste 862ce3adf43SDag-Erling Smørgravstart_sshd () 863ce3adf43SDag-Erling Smørgrav{ 864ce3adf43SDag-Erling Smørgrav # start sshd 8654d3fc8b0SEd Maste logfile="${TEST_SSH_LOGDIR}/sshd.`$OBJ/timestamp`.$$.log" 866ce3adf43SDag-Erling Smørgrav $SUDO ${SSHD} -f $OBJ/sshd_config "$@" -t || fatal "sshd_config broken" 86719261079SEd Maste $SUDO env SSH_SK_HELPER="$SSH_SK_HELPER" \ 86819261079SEd Maste ${SSHD} -f $OBJ/sshd_config "$@" -E$TEST_SSHD_LOGFILE 869ce3adf43SDag-Erling Smørgrav 870ce3adf43SDag-Erling Smørgrav trace "wait for sshd" 871ce3adf43SDag-Erling Smørgrav i=0; 872ce3adf43SDag-Erling Smørgrav while [ ! -f $PIDFILE -a $i -lt 10 ]; do 873ce3adf43SDag-Erling Smørgrav i=`expr $i + 1` 874ce3adf43SDag-Erling Smørgrav sleep $i 875ce3adf43SDag-Erling Smørgrav done 876ce3adf43SDag-Erling Smørgrav 877ce3adf43SDag-Erling Smørgrav test -f $PIDFILE || fatal "no sshd running on port $PORT" 878ce3adf43SDag-Erling Smørgrav} 879ce3adf43SDag-Erling Smørgrav 880069ac184SEd Maste# Find a PKCS#11 library. 881069ac184SEd Mastep11_find_lib() { 882069ac184SEd Maste TEST_SSH_PKCS11="" 883069ac184SEd Maste for _lib in "$@" ; do 884069ac184SEd Maste if test -f "$_lib" ; then 885069ac184SEd Maste TEST_SSH_PKCS11="$_lib" 886069ac184SEd Maste return 887069ac184SEd Maste fi 888069ac184SEd Maste done 889069ac184SEd Maste} 890069ac184SEd Maste 891069ac184SEd Maste# Perform PKCS#11 setup: prepares a softhsm2 token configuration, generated 892069ac184SEd Maste# keys and loads them into the virtual token. 893069ac184SEd MastePKCS11_OK= 894069ac184SEd Masteexport PKCS11_OK 895069ac184SEd Mastep11_setup() { 896069ac184SEd Maste p11_find_lib \ 897069ac184SEd Maste /usr/local/lib/softhsm/libsofthsm2.so \ 898069ac184SEd Maste /usr/lib64/pkcs11/libsofthsm2.so \ 899069ac184SEd Maste /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so 900069ac184SEd Maste test -z "$TEST_SSH_PKCS11" && return 1 901069ac184SEd Maste verbose "using token library $TEST_SSH_PKCS11" 902069ac184SEd Maste TEST_SSH_PIN=1234 903069ac184SEd Maste TEST_SSH_SOPIN=12345678 904069ac184SEd Maste if [ "x$TEST_SSH_SSHPKCS11HELPER" != "x" ]; then 905069ac184SEd Maste SSH_PKCS11_HELPER="${TEST_SSH_SSHPKCS11HELPER}" 906069ac184SEd Maste export SSH_PKCS11_HELPER 907069ac184SEd Maste fi 908069ac184SEd Maste 909069ac184SEd Maste # setup environment for softhsm2 token 910069ac184SEd Maste SSH_SOFTHSM_DIR=$OBJ/SOFTHSM 911069ac184SEd Maste export SSH_SOFTHSM_DIR 912069ac184SEd Maste rm -rf $SSH_SOFTHSM_DIR 913069ac184SEd Maste TOKEN=$SSH_SOFTHSM_DIR/tokendir 914069ac184SEd Maste mkdir -p $TOKEN 915069ac184SEd Maste SOFTHSM2_CONF=$SSH_SOFTHSM_DIR/softhsm2.conf 916069ac184SEd Maste export SOFTHSM2_CONF 917069ac184SEd Maste cat > $SOFTHSM2_CONF << EOF 918069ac184SEd Maste# SoftHSM v2 configuration file 919069ac184SEd Mastedirectories.tokendir = ${TOKEN} 920069ac184SEd Masteobjectstore.backend = file 921069ac184SEd Maste# ERROR, WARNING, INFO, DEBUG 922069ac184SEd Mastelog.level = DEBUG 923069ac184SEd Maste# If CKF_REMOVABLE_DEVICE flag should be set 924069ac184SEd Masteslots.removable = false 925069ac184SEd MasteEOF 926069ac184SEd Maste out=$(softhsm2-util --init-token --free --label token-slot-0 --pin "$TEST_SSH_PIN" --so-pin "$TEST_SSH_SOPIN") 927069ac184SEd Maste slot=$(echo -- $out | sed 's/.* //') 928069ac184SEd Maste trace "generating keys" 929069ac184SEd Maste # RSA key 930069ac184SEd Maste RSA=${SSH_SOFTHSM_DIR}/RSA 931069ac184SEd Maste RSAP8=${SSH_SOFTHSM_DIR}/RSAP8 932069ac184SEd Maste $OPENSSL_BIN genpkey -algorithm rsa > $RSA 2>/dev/null || \ 933069ac184SEd Maste fatal "genpkey RSA fail" 934069ac184SEd Maste $OPENSSL_BIN pkcs8 -nocrypt -in $RSA > $RSAP8 || fatal "pkcs8 RSA fail" 935069ac184SEd Maste softhsm2-util --slot "$slot" --label 01 --id 01 --pin "$TEST_SSH_PIN" \ 936069ac184SEd Maste --import $RSAP8 >/dev/null || fatal "softhsm import RSA fail" 937069ac184SEd Maste chmod 600 $RSA 938069ac184SEd Maste ssh-keygen -y -f $RSA > ${RSA}.pub 939069ac184SEd Maste # ECDSA key 940069ac184SEd Maste ECPARAM=${SSH_SOFTHSM_DIR}/ECPARAM 941069ac184SEd Maste EC=${SSH_SOFTHSM_DIR}/EC 942069ac184SEd Maste ECP8=${SSH_SOFTHSM_DIR}/ECP8 943069ac184SEd Maste $OPENSSL_BIN genpkey -genparam -algorithm ec \ 944069ac184SEd Maste -pkeyopt ec_paramgen_curve:prime256v1 > $ECPARAM || \ 945069ac184SEd Maste fatal "param EC fail" 946069ac184SEd Maste $OPENSSL_BIN genpkey -paramfile $ECPARAM > $EC || \ 947069ac184SEd Maste fatal "genpkey EC fail" 948069ac184SEd Maste $OPENSSL_BIN pkcs8 -nocrypt -in $EC > $ECP8 || fatal "pkcs8 EC fail" 949069ac184SEd Maste softhsm2-util --slot "$slot" --label 02 --id 02 --pin "$TEST_SSH_PIN" \ 950069ac184SEd Maste --import $ECP8 >/dev/null || fatal "softhsm import EC fail" 951069ac184SEd Maste chmod 600 $EC 952069ac184SEd Maste ssh-keygen -y -f $EC > ${EC}.pub 953069ac184SEd Maste # Prepare askpass script to load PIN. 954069ac184SEd Maste PIN_SH=$SSH_SOFTHSM_DIR/pin.sh 955069ac184SEd Maste cat > $PIN_SH << EOF 956069ac184SEd Maste#!/bin/sh 957069ac184SEd Masteecho "${TEST_SSH_PIN}" 958069ac184SEd MasteEOF 959069ac184SEd Maste chmod 0700 "$PIN_SH" 960069ac184SEd Maste PKCS11_OK=yes 961069ac184SEd Maste return 0 962069ac184SEd Maste} 963069ac184SEd Maste 964069ac184SEd Maste# Peforms ssh-add with the right token PIN. 965069ac184SEd Mastep11_ssh_add() { 966069ac184SEd Maste env SSH_ASKPASS="$PIN_SH" SSH_ASKPASS_REQUIRE=force ${SSHADD} "$@" 967069ac184SEd Maste} 968069ac184SEd Maste 969ce3adf43SDag-Erling Smørgrav# source test body 970ce3adf43SDag-Erling Smørgrav. $SCRIPT 971ce3adf43SDag-Erling Smørgrav 972ce3adf43SDag-Erling Smørgrav# kill sshd 973ce3adf43SDag-Erling Smørgravcleanup 97419261079SEd Maste 97519261079SEd Masteif [ "x$USE_VALGRIND" != "x" ]; then 9761323ec57SEd Maste # If there is an EXIT trap handler, invoke it now. 9771323ec57SEd Maste # Some tests set these to clean up processes such as ssh-agent. We 9781323ec57SEd Maste # need to wait for all valgrind processes to complete so we can check 9791323ec57SEd Maste # their logs, but since the EXIT traps are not invoked until 9801323ec57SEd Maste # test-exec.sh exits, waiting here will deadlock. 9811323ec57SEd Maste # This is not very portable but then neither is valgrind itself. 9821323ec57SEd Maste # As a bonus, dash (as used on the runners) has a "trap" that doesn't 9831323ec57SEd Maste # work in a pipeline (hence the temp file) or a subshell. 9841323ec57SEd Maste exithandler="" 9851323ec57SEd Maste trap >/tmp/trap.$$ && exithandler=$(cat /tmp/trap.$$ | \ 9861323ec57SEd Maste awk -F "'" '/EXIT$/{print $2}') 9871323ec57SEd Maste rm -f /tmp/trap.$$ 9881323ec57SEd Maste if [ "x${exithandler}" != "x" ]; then 9891323ec57SEd Maste verbose invoking EXIT trap handler early: ${exithandler} 9901323ec57SEd Maste eval "${exithandler}" 9911323ec57SEd Maste trap '' EXIT 9921323ec57SEd Maste fi 9931323ec57SEd Maste 99419261079SEd Maste # wait for any running process to complete 99519261079SEd Maste wait; sleep 1 99619261079SEd Maste VG_RESULTS=$(find $OBJ/valgrind-out -type f -print) 99719261079SEd Maste VG_RESULT_COUNT=0 99819261079SEd Maste VG_FAIL_COUNT=0 99919261079SEd Maste for i in $VG_RESULTS; do 100019261079SEd Maste if grep "ERROR SUMMARY" $i >/dev/null; then 100119261079SEd Maste VG_RESULT_COUNT=$(($VG_RESULT_COUNT + 1)) 100219261079SEd Maste if ! grep "ERROR SUMMARY: 0 errors" $i >/dev/null; then 100319261079SEd Maste VG_FAIL_COUNT=$(($VG_FAIL_COUNT + 1)) 100419261079SEd Maste RESULT=1 100519261079SEd Maste verbose valgrind failure $i 100619261079SEd Maste cat $i 100719261079SEd Maste fi 100819261079SEd Maste fi 100919261079SEd Maste done 101019261079SEd Maste if [ x"$VG_SKIP" != "x" ]; then 101119261079SEd Maste verbose valgrind skipped 101219261079SEd Maste else 101319261079SEd Maste verbose valgrind results $VG_RESULT_COUNT failures $VG_FAIL_COUNT 101419261079SEd Maste fi 101519261079SEd Mastefi 101619261079SEd Maste 1017ce3adf43SDag-Erling Smørgravif [ $RESULT -eq 0 ]; then 1018ce3adf43SDag-Erling Smørgrav verbose ok $tid 101938a52bd3SEd Maste if [ "x$CACHE" != "x" ]; then 102038a52bd3SEd Maste touch "$CACHE" 102138a52bd3SEd Maste fi 1022ce3adf43SDag-Erling Smørgravelse 1023ce3adf43SDag-Erling Smørgrav echo failed $tid 1024ce3adf43SDag-Erling Smørgravfi 1025ce3adf43SDag-Erling Smørgravexit $RESULT 1026