import of openssh-6.1
[openssh.git] / regress / multiplex.sh
1 #       $OpenBSD: multiplex.sh,v 1.13 2012/06/01 00:47:36 djm Exp $
2 #       Placed in the Public Domain.
3
4 CTL=/tmp/openssh.regress.ctl-sock.$$
5
6 tid="connection multiplexing"
7
8 if config_defined DISABLE_FD_PASSING ; then
9         echo "skipped (not supported on this platform)"
10         exit 0
11 fi
12
13 DATA=/bin/ls${EXEEXT}
14 COPY=$OBJ/ls.copy
15
16 start_sshd
17
18 trace "start master, fork to background"
19 ${SSH} -Nn2 -MS$CTL -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" somehost &
20 MASTER_PID=$!
21
22 # Wait for master to start and authenticate
23 sleep 5
24
25 verbose "test $tid: envpass"
26 trace "env passing over multiplexed connection"
27 _XXX_TEST=blah ${SSH} -F $OBJ/ssh_config -oSendEnv="_XXX_TEST" -S$CTL otherhost sh << 'EOF'
28         test X"$_XXX_TEST" = X"blah"
29 EOF
30 if [ $? -ne 0 ]; then
31         fail "environment not found"
32 fi
33
34 verbose "test $tid: transfer"
35 rm -f ${COPY}
36 trace "ssh transfer over multiplexed connection and check result"
37 ${SSH} -F $OBJ/ssh_config -S$CTL otherhost cat ${DATA} > ${COPY}
38 test -f ${COPY}                 || fail "ssh -Sctl: failed copy ${DATA}" 
39 cmp ${DATA} ${COPY}             || fail "ssh -Sctl: corrupted copy of ${DATA}"
40
41 rm -f ${COPY}
42 trace "ssh transfer over multiplexed connection and check result"
43 ${SSH} -F $OBJ/ssh_config -S $CTL otherhost cat ${DATA} > ${COPY}
44 test -f ${COPY}                 || fail "ssh -S ctl: failed copy ${DATA}" 
45 cmp ${DATA} ${COPY}             || fail "ssh -S ctl: corrupted copy of ${DATA}"
46
47 rm -f ${COPY}
48 trace "sftp transfer over multiplexed connection and check result"
49 echo "get ${DATA} ${COPY}" | \
50         ${SFTP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost >>$TEST_SSH_LOGFILE 2>&1
51 test -f ${COPY}                 || fail "sftp: failed copy ${DATA}" 
52 cmp ${DATA} ${COPY}             || fail "sftp: corrupted copy of ${DATA}"
53
54 rm -f ${COPY}
55 trace "scp transfer over multiplexed connection and check result"
56 ${SCP} -S ${SSH} -F $OBJ/ssh_config -oControlPath=$CTL otherhost:${DATA} ${COPY} >>$TEST_SSH_LOGFILE 2>&1
57 test -f ${COPY}                 || fail "scp: failed copy ${DATA}" 
58 cmp ${DATA} ${COPY}             || fail "scp: corrupted copy of ${DATA}"
59
60 rm -f ${COPY}
61
62 for s in 0 1 4 5 44; do
63         trace "exit status $s over multiplexed connection"
64         verbose "test $tid: status $s"
65         ${SSH} -F $OBJ/ssh_config -S $CTL otherhost exit $s
66         r=$?
67         if [ $r -ne $s ]; then
68                 fail "exit code mismatch for protocol $p: $r != $s"
69         fi
70
71         # same with early close of stdout/err
72         trace "exit status $s with early close over multiplexed connection"
73         ${SSH} -F $OBJ/ssh_config -S $CTL -n otherhost \
74                 exec sh -c \'"sleep 2; exec > /dev/null 2>&1; sleep 3; exit $s"\'
75         r=$?
76         if [ $r -ne $s ]; then
77                 fail "exit code (with sleep) mismatch for protocol $p: $r != $s"
78         fi
79 done
80
81 trace "test check command"
82 ${SSH} -F $OBJ/ssh_config -S $CTL -Ocheck otherhost || fail "check command failed" 
83
84 trace "test exit command"
85 ${SSH} -F $OBJ/ssh_config -S $CTL -Oexit otherhost || fail "send exit command failed" 
86
87 # Wait for master to exit
88 sleep 2
89
90 kill -0 $MASTER_PID >/dev/null 2>&1 && fail "exit command failed"