1 # $OpenBSD: channel-timeout.sh,v 1.2 2024/01/09 22:19:36 djm Exp $
2 # Placed in the Public Domain.
6 # XXX not comprehensive. Still need -R -L agent X11 forwarding + interactive
8 rm -f $OBJ/finished.
* $OBJ/mux.
*
12 ${SSH} -nNfM -oControlPath=$MUXPATH -F $OBJ/ssh_proxy
"$@" somehost ||
13 fatal
"open mux failed"
14 test -e $MUXPATH || fatal
"mux socket $MUXPATH not established"
18 test -e $MUXPATH || fatal
"mux socket $MUXPATH missing"
19 ${SSH} -qF $OBJ/ssh_proxy
-oControlPath=$MUXPATH -O exit somehost ||
20 fatal
"could not terminate mux process"
21 for x
in 1 2 3 4 5 6 7 8 9 10 ; do
22 test -e $OBJ/mux
&& break
25 test -e $MUXPATH && fatal
"mux did not clean up"
28 ${SSH} -F $OBJ/ssh_proxy
-oControlPath=$MUXPATH somehost
"$@"
31 rm -f $OBJ/sshd_proxy.orig
32 cp $OBJ/sshd_proxy
$OBJ/sshd_proxy.orig
35 ${SSH} -F $OBJ/ssh_proxy somehost
"sleep 5 ; exit 23"
37 if [ $r -ne 23 ]; then
41 verbose
"command timeout"
42 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:command=1") \
44 ${SSH} -F $OBJ/ssh_proxy somehost
"sleep 5 ; exit 23"
46 if [ $r -ne 255 ]; then
47 fail
"ssh returned unexpected error code $r"
50 verbose
"command long timeout"
51 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:command=60") \
53 ${SSH} -F $OBJ/ssh_proxy somehost
"exit 23"
55 if [ $r -ne 23 ]; then
56 fail
"ssh returned unexpected error code $r"
59 verbose
"command wildcard timeout"
60 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:*=1") \
62 ${SSH} -F $OBJ/ssh_proxy somehost
"sleep 5 ; exit 23"
64 if [ $r -ne 255 ]; then
65 fail
"ssh returned unexpected error code $r"
68 verbose
"command irrelevant timeout"
69 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:shell=1") \
71 ${SSH} -F $OBJ/ssh_proxy somehost
"sleep 5 ; exit 23"
73 if [ $r -ne 23 ]; then
77 if config_defined DISABLE_FD_PASSING
; then
78 verbose
"skipping multiplexing tests"
80 verbose
"multiplexed command timeout"
81 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:command=1") \
84 mux_client
"sleep 5 ; exit 23"
86 if [ $r -ne 255 ]; then
87 fail
"ssh returned unexpected error code $r"
91 verbose
"irrelevant multiplexed command timeout"
92 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout session:shell=1") \
95 mux_client
"sleep 5 ; exit 23"
97 if [ $r -ne 23 ]; then
98 fail
"ssh returned unexpected error code $r"
102 verbose
"global command timeout"
103 (cat $OBJ/sshd_proxy.orig
; echo "ChannelTimeout global=10") \
106 mux_client
"sleep 1 ; echo ok ; sleep 1; echo ok; sleep 60; touch $OBJ/finished.1" >/dev
/null
&
107 mux_client
"sleep 60 ; touch $OBJ/finished.2" >/dev
/null
&
108 mux_client
"sleep 2 ; touch $OBJ/finished.3" >/dev
/null
&
110 test -f $OBJ/finished
.1 && fail
"first mux process completed"
111 test -f $OBJ/finished
.2 && fail
"second mux process completed"
112 test -f $OBJ/finished
.3 || fail
"third mux process did not complete"
116 # Set up a "slow sftp server" that sleeps before executing the real one.
117 cat > $OBJ/slow-sftp-server.sh
<< _EOF
123 chmod a
+x
$OBJ/slow-sftp-server.sh
125 verbose
"sftp no timeout"
126 (grep -vi subsystem.
*sftp
$OBJ/sshd_proxy.orig
;
127 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
130 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost
:$DATA $COPY
132 if [ $r -ne 0 ]; then
135 cmp $DATA $COPY || fail
"corrupted copy"
137 verbose
"sftp timeout"
138 (grep -vi subsystem.
*sftp
$OBJ/sshd_proxy.orig
;
139 echo "ChannelTimeout session:subsystem:sftp=1" ;
140 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
143 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost
:$DATA $COPY
145 if [ $r -eq 0 ]; then
146 fail
"sftp succeeded unexpectedly"
148 test -f $COPY && cmp $DATA $COPY && fail
"intact copy"
150 verbose
"sftp irrelevant timeout"
151 (grep -vi subsystem.
*sftp
$OBJ/sshd_proxy.orig
;
152 echo "ChannelTimeout session:subsystem:command=1" ;
153 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
156 $SFTP -qS $SSH -F $OBJ/ssh_proxy somehost
:$DATA $COPY
158 if [ $r -ne 0 ]; then
161 cmp $DATA $COPY || fail
"corrupted copy"