sftp-chroot.sh 854 B

1234567891011121314151617181920212223242526272829303132
  1. # $OpenBSD: sftp-chroot.sh,v 1.7 2018/11/22 08:48:32 dtucker Exp $
  2. # Placed in the Public Domain.
  3. tid="sftp in chroot"
  4. CHROOT=/var/run
  5. FILENAME=testdata_${USER}.$$
  6. PRIVDATA=${CHROOT}/${FILENAME}
  7. trap "${SUDO} rm -f ${PRIVDATA}" 0
  8. if [ -z "$SUDO" -a ! -w /var/run ]; then
  9. echo "need SUDO to create file in /var/run, test won't work without"
  10. echo SKIPPED
  11. exit 0
  12. fi
  13. if ! $OBJ/check-perm -m chroot "$CHROOT"; then
  14. echo "skipped: $CHROOT is unsuitable as ChrootDirectory"
  15. exit 0
  16. fi
  17. $SUDO sh -c "echo mekmitastdigoat > $PRIVDATA" ||
  18. fatal "create $PRIVDATA failed"
  19. start_sshd -oChrootDirectory=$CHROOT -oForceCommand="internal-sftp -d /"
  20. verbose "test $tid: get"
  21. ${SFTP} -S "$SSH" -F $OBJ/ssh_config host:/${FILENAME} $COPY \
  22. >> $TEST_REGRESS_LOGFILE 2>&1 ||
  23. fatal "Fetch ${FILENAME} failed"
  24. cmp $PRIVDATA $COPY || fail "$PRIVDATA $COPY differ"