1#	$OpenBSD: sftp-chroot.sh,v 1.7 2018/11/22 08:48:32 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	echo "need SUDO to create file in /var/run, test won't work without"
13	echo SKIPPED
14	exit 0
15fi
16
17if ! $OBJ/check-perm -m chroot "$CHROOT" ; then
18  echo "skipped: $CHROOT is unsuitable as ChrootDirectory"
19  exit 0
20fi
21
22$SUDO sh -c "echo mekmitastdigoat > $PRIVDATA" || \
23	fatal "create $PRIVDATA failed"
24
25start_sshd -oChrootDirectory=$CHROOT -oForceCommand="internal-sftp -d /"
26
27verbose "test $tid: get"
28${SFTP} -S "$SSH" -F $OBJ/ssh_config host:/${FILENAME} $COPY \
29    >>$TEST_REGRESS_LOGFILE 2>&1 || \
30	fatal "Fetch ${FILENAME} failed"
31cmp $PRIVDATA $COPY || fail "$PRIVDATA $COPY differ"
32