bluhm@openbsd.org | ce44c97 | 2016-09-26 21:34:38 +0000 | [diff] [blame] | 1 | # $OpenBSD: sftp-chroot.sh,v 1.5 2016/09/26 21:34:38 bluhm Exp $ |
Darren Tucker | f3568fc | 2013-05-17 09:35:26 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="sftp in chroot" |
| 5 | |
Darren Tucker | f3568fc | 2013-05-17 09:35:26 +1000 | [diff] [blame] | 6 | CHROOT=/var/run |
| 7 | FILENAME=testdata_${USER} |
| 8 | PRIVDATA=${CHROOT}/${FILENAME} |
| 9 | |
bluhm@openbsd.org | ce44c97 | 2016-09-26 21:34:38 +0000 | [diff] [blame] | 10 | if [ -z "$SUDO" -a ! -w /var/run ]; then |
Tim Rice | 3f3064c | 2013-06-02 15:13:09 -0700 | [diff] [blame] | 11 | echo "skipped: need SUDO to create file in /var/run, test won't work without" |
| 12 | exit 0 |
Darren Tucker | f3568fc | 2013-05-17 09:35:26 +1000 | [diff] [blame] | 13 | fi |
| 14 | |
Damien Miller | 1acc058 | 2016-02-23 16:12:13 +1100 | [diff] [blame] | 15 | if ! $OBJ/check-perm -m chroot "$CHROOT" ; then |
| 16 | echo "skipped: $CHROOT is unsuitable as ChrootDirectory" |
| 17 | exit 0 |
| 18 | fi |
| 19 | |
Darren Tucker | f3568fc | 2013-05-17 09:35:26 +1000 | [diff] [blame] | 20 | $SUDO sh -c "echo mekmitastdigoat > $PRIVDATA" || \ |
| 21 | fatal "create $PRIVDATA failed" |
| 22 | |
| 23 | start_sshd -oChrootDirectory=$CHROOT -oForceCommand="internal-sftp -d /" |
| 24 | |
| 25 | verbose "test $tid: get" |
Damien Miller | f483cc1 | 2014-02-28 10:19:11 +1100 | [diff] [blame] | 26 | ${SFTP} -S "$SSH" -F $OBJ/ssh_config host:/${FILENAME} $COPY \ |
Damien Miller | 1e2aa3d | 2014-02-28 10:19:51 +1100 | [diff] [blame] | 27 | >>$TEST_REGRESS_LOGFILE 2>&1 || \ |
Darren Tucker | f3568fc | 2013-05-17 09:35:26 +1000 | [diff] [blame] | 28 | fatal "Fetch ${FILENAME} failed" |
| 29 | cmp $PRIVDATA $COPY || fail "$PRIVDATA $COPY differ" |
| 30 | |
| 31 | $SUDO rm $PRIVDATA |