xref: /freebsd/crypto/openssh/regress/sftp-chroot.sh (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1#	$OpenBSD: sftp-chroot.sh,v 1.8 2021/09/01 00:50:27 dtucker Exp $
2#	Placed in the Public Domain.
3
4tid="sftp in chroot"
5
6CHROOT=/var/run
7FILENAME=testdata_${USER}.$$
8PRIVDATA=${CHROOT}/${FILENAME}
9trap "${SUDO} rm -f ${PRIVDATA}" 0
10
11if [ -z "$SUDO" -a ! -w /var/run ]; then
12	skip "need SUDO to create file in /var/run, test won't work without"
13fi
14
15if ! $OBJ/check-perm -m chroot "$CHROOT" ; then
16  skip "$CHROOT is unsuitable as ChrootDirectory"
17fi
18
19$SUDO sh -c "echo mekmitastdigoat > $PRIVDATA" || \
20	fatal "create $PRIVDATA failed"
21
22start_sshd -oChrootDirectory=$CHROOT -oForceCommand="internal-sftp -d /"
23
24verbose "test $tid: get"
25${SFTP} -S "$SSH" -F $OBJ/ssh_config host:/${FILENAME} $COPY \
26    >>$TEST_REGRESS_LOGFILE 2>&1 || \
27	fatal "Fetch ${FILENAME} failed"
28cmp $PRIVDATA $COPY || fail "$PRIVDATA $COPY differ"
29