liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#    $OpenBSD: reexec.sh,v 1.10 2016/12/16 01:06:27 dtucker Exp $
#    Placed in the Public Domain.
 
tid="reexec tests"
 
SSHD_ORIG=$SSHD
SSHD_COPY=$OBJ/sshd
 
# Start a sshd and then delete it
start_sshd_copy ()
{
   cp $SSHD_ORIG $SSHD_COPY
   SSHD=$SSHD_COPY
   start_sshd
   SSHD=$SSHD_ORIG
}
 
# Do basic copy tests
copy_tests ()
{
   rm -f ${COPY}
   for p in ${SSH_PROTOCOLS} ; do
       verbose "$tid: proto $p"
       ${SSH} -nqo "Protocol=$p" -F $OBJ/ssh_config somehost \
           cat ${DATA} > ${COPY}
       if [ $? -ne 0 ]; then
           fail "ssh cat $DATA failed"
       fi
       cmp ${DATA} ${COPY}        || fail "corrupted copy"
       rm -f ${COPY}
   done
}
 
verbose "test config passing"
 
cp $OBJ/sshd_config $OBJ/sshd_config.orig
start_sshd
echo "InvalidXXX=no" >> $OBJ/sshd_config
 
copy_tests
 
stop_sshd
 
cp $OBJ/sshd_config.orig $OBJ/sshd_config
 
# cygwin can't fork a deleted binary
if [ "$os" != "cygwin" ]; then
 
verbose "test reexec fallback"
 
start_sshd_copy
rm -f $SSHD_COPY
 
copy_tests
 
stop_sshd
 
verbose "test reexec fallback without privsep"
 
cp $OBJ/sshd_config.orig $OBJ/sshd_config
echo "UsePrivilegeSeparation=no" >> $OBJ/sshd_config
 
start_sshd_copy
rm -f $SSHD_COPY
 
copy_tests
 
stop_sshd
 
fi