1# $OpenBSD: reexec.sh,v 1.13 2023/01/19 07:53:45 dtucker Exp $ 2# Placed in the Public Domain. 3 4tid="reexec tests" 5 6SSHD_ORIG=$SSHD 7SSHD_COPY=$OBJ/sshd 8 9# Start a sshd and then delete it 10start_sshd_copy () 11{ 12 # NB. prefer ln to cp here. On some OSX 19.4 configurations, 13 # djm has seen failure after fork() when the executable image 14 # has been removed from the filesystem. 15 ln $SSHD_ORIG $SSHD_COPY || cp $SSHD_ORIG $SSHD_COPY 16 SSHD=$SSHD_COPY 17 start_sshd 18 SSHD=$SSHD_ORIG 19} 20 21# Do basic copy tests 22copy_tests () 23{ 24 rm -f ${COPY} 25 ${SSH} -nq -F $OBJ/ssh_config somehost \ 26 cat ${DATA} > ${COPY} 27 if [ $? -ne 0 ]; then 28 fail "ssh cat $DATA failed" 29 fi 30 cmp ${DATA} ${COPY} || fail "corrupted copy" 31 rm -f ${COPY} 32} 33 34verbose "test config passing" 35 36cp $OBJ/sshd_config $OBJ/sshd_config.orig 37start_sshd 38echo "InvalidXXX=no" >> $OBJ/sshd_config 39 40copy_tests 41 42stop_sshd 43 44cp $OBJ/sshd_config.orig $OBJ/sshd_config 45 46# cygwin can't fork a deleted binary 47if [ "$os" != "cygwin" ]; then 48 49verbose "test reexec fallback" 50 51start_sshd_copy 52$SUDO rm -f $SSHD_COPY 53 54copy_tests 55 56stop_sshd 57fi 58