Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame] | 1 | # $OpenBSD: scp.sh,v 1.2 2004/06/16 13:15:09 dtucker Exp $ |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="scp" |
| 5 | |
| 6 | #set -x |
| 7 | |
Darren Tucker | 8a2f1b3 | 2004-06-17 15:18:32 +1000 | [diff] [blame] | 8 | # Figure out if diff understands "-N" |
| 9 | if diff -N ${SRC}/scp.sh ${SRC}/scp.sh 2>/dev/null; then |
| 10 | DIFFOPT="-rN" |
| 11 | else |
| 12 | DIFFOPT="-r" |
| 13 | fi |
| 14 | |
Darren Tucker | 0521dcb | 2004-08-29 19:39:09 +1000 | [diff] [blame^] | 15 | DATA=/bin/ls${EXEEXT} |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 16 | COPY=${OBJ}/copy |
| 17 | COPY2=${OBJ}/copy2 |
| 18 | DIR=${COPY}.dd |
| 19 | DIR2=${COPY}.dd2 |
| 20 | |
| 21 | SRC=`dirname ${SCRIPT}` |
Darren Tucker | 0521dcb | 2004-08-29 19:39:09 +1000 | [diff] [blame^] | 22 | cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp |
| 23 | chmod 755 ${OBJ}/scp-ssh-wrapper.scp |
| 24 | scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp" |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 25 | |
| 26 | scpclean() { |
| 27 | rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} |
| 28 | mkdir ${DIR} ${DIR2} |
| 29 | } |
| 30 | |
| 31 | verbose "$tid: simple copy local file to remote file" |
| 32 | scpclean |
| 33 | $SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed" |
| 34 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 35 | |
| 36 | verbose "$tid: simple copy remote file to local file" |
| 37 | scpclean |
| 38 | $SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed" |
| 39 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 40 | |
| 41 | verbose "$tid: simple copy local file to remote dir" |
| 42 | scpclean |
| 43 | cp ${DATA} ${COPY} |
| 44 | $SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed" |
| 45 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 46 | |
| 47 | verbose "$tid: simple copy remote file to local dir" |
| 48 | scpclean |
| 49 | cp ${DATA} ${COPY} |
| 50 | $SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed" |
| 51 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 52 | |
| 53 | verbose "$tid: recursive local dir to remote dir" |
| 54 | scpclean |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame] | 55 | rm -rf ${DIR2} |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 56 | cp ${DATA} ${DIR}/copy |
| 57 | $SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed" |
Darren Tucker | 8a2f1b3 | 2004-06-17 15:18:32 +1000 | [diff] [blame] | 58 | diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy" |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 59 | |
| 60 | verbose "$tid: recursive remote dir to local dir" |
| 61 | scpclean |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame] | 62 | rm -rf ${DIR2} |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 63 | cp ${DATA} ${DIR}/copy |
| 64 | $SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed" |
Darren Tucker | 8a2f1b3 | 2004-06-17 15:18:32 +1000 | [diff] [blame] | 65 | diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy" |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 66 | |
| 67 | for i in 0 1 2 3 4; do |
| 68 | verbose "$tid: disallow bad server #$i" |
| 69 | SCPTESTMODE=badserver_$i |
| 70 | export DIR SCPTESTMODE |
| 71 | scpclean |
| 72 | $SCP $scpopts somehost:${DATA} ${DIR} >/dev/null 2>/dev/null |
| 73 | [ -d {$DIR}/rootpathdir ] && fail "allows dir relative to root dir" |
| 74 | [ -d ${DIR}/dotpathdir ] && fail "allows dir creation in non-recursive mode" |
| 75 | |
| 76 | scpclean |
| 77 | $SCP -r $scpopts somehost:${DATA} ${DIR2} >/dev/null 2>/dev/null |
| 78 | [ -d ${DIR}/dotpathdir ] && fail "allows dir creation outside of subdir" |
| 79 | done |
| 80 | |
| 81 | scpclean |
Darren Tucker | 0521dcb | 2004-08-29 19:39:09 +1000 | [diff] [blame^] | 82 | rm -f ${OBJ}/scp-ssh-wrapper.scp |