1*f374ba41SEd Maste# $OpenBSD: connection-timeout.sh,v 1.2 2023/01/17 10:15:10 djm Exp $ 2*f374ba41SEd Maste# Placed in the Public Domain. 3*f374ba41SEd Maste 4*f374ba41SEd Mastetid="unused connection timeout" 5*f374ba41SEd Masteif config_defined DISABLE_FD_PASSING ; then 6*f374ba41SEd Maste skip "not supported on this platform" 7*f374ba41SEd Mastefi 8*f374ba41SEd Maste 9*f374ba41SEd MasteCTL=$OBJ/ctl-sock 10*f374ba41SEd Mastecp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig 11*f374ba41SEd Maste 12*f374ba41SEd Mastecheck_ssh() { 13*f374ba41SEd Maste test -S $CTL || return 1 14*f374ba41SEd Maste if ! ${REAL_SSH} -qF$OBJ/ssh_proxy -O check \ 15*f374ba41SEd Maste -oControlPath=$CTL somehost >/dev/null 2>&1 ; then 16*f374ba41SEd Maste return 1 17*f374ba41SEd Maste fi 18*f374ba41SEd Maste return 0 19*f374ba41SEd Maste} 20*f374ba41SEd Maste 21*f374ba41SEd Mastestart_ssh() { 22*f374ba41SEd Maste trace "start ssh" 23*f374ba41SEd Maste ${SSH} -nNfF $OBJ/ssh_proxy "$@" -oExitOnForwardFailure=yes \ 24*f374ba41SEd Maste -oControlMaster=yes -oControlPath=$CTL somehost 25*f374ba41SEd Maste r=$? 26*f374ba41SEd Maste test $r -eq 0 || fatal "failed to start ssh $r" 27*f374ba41SEd Maste check_ssh || fatal "ssh process unresponsive" 28*f374ba41SEd Maste} 29*f374ba41SEd Maste 30*f374ba41SEd Mastestop_ssh() { 31*f374ba41SEd Maste test -S $CTL || return 32*f374ba41SEd Maste check_ssh || fatal "ssh process is unresponsive: cannot close" 33*f374ba41SEd Maste if ! ${REAL_SSH} -qF$OBJ/ssh_proxy -O exit \ 34*f374ba41SEd Maste -oControlPath=$CTL >/dev/null somehost >/dev/null ; then 35*f374ba41SEd Maste fatal "ssh process did not respond to close" 36*f374ba41SEd Maste fi 37*f374ba41SEd Maste n=0 38*f374ba41SEd Maste while [ "$n" -lt 20 ] ; do 39*f374ba41SEd Maste test -S $CTL || break 40*f374ba41SEd Maste sleep 1 41*f374ba41SEd Maste n=`expr $n + 1` 42*f374ba41SEd Maste done 43*f374ba41SEd Maste if test -S $CTL ; then 44*f374ba41SEd Maste fatal "ssh process did not exit" 45*f374ba41SEd Maste fi 46*f374ba41SEd Maste} 47*f374ba41SEd Maste 48*f374ba41SEd Mastetrap "stop_ssh" EXIT 49*f374ba41SEd Maste 50*f374ba41SEd Masteverbose "no timeout" 51*f374ba41SEd Mastestart_ssh 52*f374ba41SEd Mastesleep 5 53*f374ba41SEd Mastecheck_ssh || fatal "ssh unexpectedly missing" 54*f374ba41SEd Mastestop_ssh 55*f374ba41SEd Maste 56*f374ba41SEd Maste(cat $OBJ/sshd_proxy.orig ; echo "UnusedConnectionTimeout 2") > $OBJ/sshd_proxy 57*f374ba41SEd Maste 58*f374ba41SEd Masteverbose "timeout" 59*f374ba41SEd Mastestart_ssh 60*f374ba41SEd Mastesleep 8 61*f374ba41SEd Mastecheck_ssh && fail "ssh unexpectedly present" 62*f374ba41SEd Mastestop_ssh 63*f374ba41SEd Maste 64*f374ba41SEd Masteverbose "session inhibits timeout" 65*f374ba41SEd Masterm -f $OBJ/copy.1 66*f374ba41SEd Mastestart_ssh 67*f374ba41SEd Maste${REAL_SSH} -qoControlPath=$CTL -oControlMaster=no -Fnone somehost \ 68*f374ba41SEd Maste "sleep 8; touch $OBJ/copy.1" & 69*f374ba41SEd Mastecheck_ssh || fail "ssh unexpectedly missing" 70*f374ba41SEd Mastewait 71*f374ba41SEd Mastetest -f $OBJ/copy.1 || fail "missing result file" 72*f374ba41SEd Maste 73*f374ba41SEd Masteverbose "timeout after session" 74*f374ba41SEd Maste# Session should still be running from previous 75*f374ba41SEd Mastesleep 8 76*f374ba41SEd Mastecheck_ssh && fail "ssh unexpectedly present" 77*f374ba41SEd Mastestop_ssh 78*f374ba41SEd Maste 79*f374ba41SEd MasteLPORT=`expr $PORT + 1` 80*f374ba41SEd MasteRPORT=`expr $LPORT + 1` 81*f374ba41SEd MasteDPORT=`expr $RPORT + 1` 82*f374ba41SEd MasteRDPORT=`expr $DPORT + 1` 83*f374ba41SEd Masteverbose "timeout with listeners" 84*f374ba41SEd Mastestart_ssh -L$LPORT:127.0.0.1:$PORT -R$RPORT:127.0.0.1:$PORT -D$DPORT -R$RDPORT 85*f374ba41SEd Mastesleep 8 86*f374ba41SEd Mastecheck_ssh && fail "ssh unexpectedly present" 87*f374ba41SEd Mastestop_ssh 88