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