xref: /freebsd/crypto/openssh/regress/channel-timeout.sh (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1#	$OpenBSD: channel-timeout.sh,v 1.1 2023/01/06 08:07:39 djm Exp $
2#	Placed in the Public Domain.
3
4tid="channel timeout"
5
6# XXX not comprehensive. Still need -R -L agent X11 forwarding + interactive
7
8rm -f $OBJ/sshd_proxy.orig
9cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig
10
11verbose "no timeout"
12${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
13r=$?
14if [ $r -ne 23 ]; then
15	fail "ssh failed"
16fi
17
18verbose "command timeout"
19(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \
20	> $OBJ/sshd_proxy
21${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
22r=$?
23if [ $r -ne 255 ]; then
24	fail "ssh returned unexpected error code $r"
25fi
26
27verbose "command wildcard timeout"
28(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:*=1") \
29	> $OBJ/sshd_proxy
30${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
31r=$?
32if [ $r -ne 255 ]; then
33	fail "ssh returned unexpected error code $r"
34fi
35
36verbose "command irrelevant timeout"
37(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \
38	> $OBJ/sshd_proxy
39${SSH} -F $OBJ/ssh_proxy somehost "sleep 5 ; exit 23"
40r=$?
41if [ $r -ne 23 ]; then
42	fail "ssh failed"
43fi
44
45# Set up a "slow sftp server" that sleeps before executing the real one.
46cat > $OBJ/slow-sftp-server.sh << _EOF
47#!/bin/sh
48
49sleep 5
50$SFTPSERVER
51_EOF
52chmod a+x $OBJ/slow-sftp-server.sh
53
54verbose "sftp no timeout"
55(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
56 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
57
58rm -f ${COPY}
59$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
60r=$?
61if [ $r -ne 0 ]; then
62	fail "sftp failed"
63fi
64cmp $DATA $COPY || fail "corrupted copy"
65
66verbose "sftp timeout"
67(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
68 echo "ChannelTimeout session:subsystem:sftp=1" ;
69 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
70
71rm -f ${COPY}
72$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
73r=$?
74if [ $r -eq 0 ]; then
75	fail "sftp succeeded unexpectedly"
76fi
77test -f $COPY && cmp $DATA $COPY && fail "intact copy"
78
79verbose "sftp irrelevant timeout"
80(grep -vi subsystem.*sftp $OBJ/sshd_proxy.orig;
81 echo "ChannelTimeout session:subsystem:command=1" ;
82 echo "Subsystem sftp $OBJ/slow-sftp-server.sh" ) > $OBJ/sshd_proxy
83
84rm -f ${COPY}
85$SFTP -qS $SSH -F $OBJ/ssh_proxy somehost:$DATA $COPY
86r=$?
87if [ $r -ne 0 ]; then
88	fail "sftp failed"
89fi
90cmp $DATA $COPY || fail "corrupted copy"
91
92