blob: 4ea2fce8570dfb3164b859b015e9f892a29b671b [file] [log] [blame]
bluhm@openbsd.orgce44c972016-09-26 21:34:38 +00001# $OpenBSD: sftp-chroot.sh,v 1.5 2016/09/26 21:34:38 bluhm Exp $
Darren Tuckerf3568fc2013-05-17 09:35:26 +10002# Placed in the Public Domain.
3
4tid="sftp in chroot"
5
Darren Tuckerf3568fc2013-05-17 09:35:26 +10006CHROOT=/var/run
7FILENAME=testdata_${USER}
8PRIVDATA=${CHROOT}/${FILENAME}
9
bluhm@openbsd.orgce44c972016-09-26 21:34:38 +000010if [ -z "$SUDO" -a ! -w /var/run ]; then
Tim Rice3f3064c2013-06-02 15:13:09 -070011 echo "skipped: need SUDO to create file in /var/run, test won't work without"
12 exit 0
Darren Tuckerf3568fc2013-05-17 09:35:26 +100013fi
14
Damien Miller1acc0582016-02-23 16:12:13 +110015if ! $OBJ/check-perm -m chroot "$CHROOT" ; then
16 echo "skipped: $CHROOT is unsuitable as ChrootDirectory"
17 exit 0
18fi
19
Darren Tuckerf3568fc2013-05-17 09:35:26 +100020$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"
Damien Millerf483cc12014-02-28 10:19:11 +110026${SFTP} -S "$SSH" -F $OBJ/ssh_config host:/${FILENAME} $COPY \
Damien Miller1e2aa3d2014-02-28 10:19:51 +110027 >>$TEST_REGRESS_LOGFILE 2>&1 || \
Darren Tuckerf3568fc2013-05-17 09:35:26 +100028 fatal "Fetch ${FILENAME} failed"
29cmp $PRIVDATA $COPY || fail "$PRIVDATA $COPY differ"
30
31$SUDO rm $PRIVDATA