1255670Sdes#	$OpenBSD: reexec.sh,v 1.7 2013/05/17 10:23:52 dtucker Exp $
2137015Sdes#	Placed in the Public Domain.
3137015Sdes
4137015Sdestid="reexec tests"
5137015Sdes
6255670SdesSSHD_ORIG=$SSHD
7255670SdesSSHD_COPY=$OBJ/sshd
8137015Sdes
9137015Sdes# Start a sshd and then delete it
10146998Sdesstart_sshd_copy ()
11137015Sdes{
12137015Sdes	cp $SSHD_ORIG $SSHD_COPY
13137015Sdes	SSHD=$SSHD_COPY
14137015Sdes	start_sshd
15137015Sdes	SSHD=$SSHD_ORIG
16137015Sdes}
17137015Sdes
18146998Sdes# Do basic copy tests
19146998Sdescopy_tests ()
20146998Sdes{
21146998Sdes	rm -f ${COPY}
22146998Sdes	for p in 1 2; do
23146998Sdes		verbose "$tid: proto $p"
24146998Sdes		${SSH} -nqo "Protocol=$p" -F $OBJ/ssh_config somehost \
25146998Sdes		    cat ${DATA} > ${COPY}
26146998Sdes		if [ $? -ne 0 ]; then
27146998Sdes			fail "ssh cat $DATA failed"
28146998Sdes		fi
29146998Sdes		cmp ${DATA} ${COPY}		|| fail "corrupted copy"
30146998Sdes		rm -f ${COPY}
31146998Sdes	done
32146998Sdes}
33146998Sdes
34137015Sdesverbose "test config passing"
35146998Sdes
36137015Sdescp $OBJ/sshd_config $OBJ/sshd_config.orig
37137015Sdesstart_sshd
38137015Sdesecho "InvalidXXX=no" >> $OBJ/sshd_config
39137015Sdes
40146998Sdescopy_tests
41137015Sdes
42214979Sdes$SUDO kill `$SUDO cat $PIDFILE`
43137015Sdesrm -f $PIDFILE
44137015Sdes
45137015Sdescp $OBJ/sshd_config.orig $OBJ/sshd_config
46137015Sdes
47239849Sdes# cygwin can't fork a deleted binary
48239849Sdesif [ "$os" != "cygwin" ]; then
49239849Sdes
50137015Sdesverbose "test reexec fallback"
51137015Sdes
52146998Sdesstart_sshd_copy
53146998Sdesrm -f $SSHD_COPY
54137015Sdes
55146998Sdescopy_tests
56137015Sdes
57214979Sdes$SUDO kill `$SUDO cat $PIDFILE`
58137015Sdesrm -f $PIDFILE
59137015Sdes
60137015Sdesverbose "test reexec fallback without privsep"
61137015Sdes
62137015Sdescp $OBJ/sshd_config.orig $OBJ/sshd_config
63137015Sdesecho "UsePrivilegeSeparation=no" >> $OBJ/sshd_config
64137015Sdes
65146998Sdesstart_sshd_copy
66146998Sdesrm -f $SSHD_COPY
67137015Sdes
68146998Sdescopy_tests
69137015Sdes
70214979Sdes$SUDO kill `$SUDO cat $PIDFILE`
71137015Sdesrm -f $PIDFILE
72137015Sdes
73239849Sdesfi
74