1# $OpenBSD: scp.sh,v 1.10 2014/01/26 10:49:17 djm Exp $ 2# Placed in the Public Domain. 3 4tid="scp" 5 6#set -x 7 8COPY2=${OBJ}/copy2 9DIR=${COPY}.dd 10DIR2=${COPY}.dd2 11 12SRC=`dirname ${SCRIPT}` 13cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp 14chmod 755 ${OBJ}/scp-ssh-wrapper.scp 15scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp" 16export SCP # used in scp-ssh-wrapper.scp 17 18scpclean() { 19 rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} 20 mkdir ${DIR} ${DIR2} 21} 22 23verbose "$tid: simple copy local file to local file" 24scpclean 25$SCP $scpopts ${DATA} ${COPY} || fail "copy failed" 26cmp ${DATA} ${COPY} || fail "corrupted copy" 27 28verbose "$tid: simple copy local file to remote file" 29scpclean 30$SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed" 31cmp ${DATA} ${COPY} || fail "corrupted copy" 32 33verbose "$tid: simple copy remote file to local file" 34scpclean 35$SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed" 36cmp ${DATA} ${COPY} || fail "corrupted copy" 37 38verbose "$tid: simple copy local file to remote dir" 39scpclean 40cp ${DATA} ${COPY} 41$SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed" 42cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 43 44verbose "$tid: simple copy local file to local dir" 45scpclean 46cp ${DATA} ${COPY} 47$SCP $scpopts ${COPY} ${DIR} || fail "copy failed" 48cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 49 50verbose "$tid: simple copy remote file to local dir" 51scpclean 52cp ${DATA} ${COPY} 53$SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed" 54cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 55 56verbose "$tid: recursive local dir to remote dir" 57scpclean 58rm -rf ${DIR2} 59cp ${DATA} ${DIR}/copy 60$SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed" 61diff -rN ${DIR} ${DIR2} || fail "corrupted copy" 62 63verbose "$tid: recursive local dir to local dir" 64scpclean 65rm -rf ${DIR2} 66cp ${DATA} ${DIR}/copy 67$SCP $scpopts -r ${DIR} ${DIR2} || fail "copy failed" 68diff -rN ${DIR} ${DIR2} || fail "corrupted copy" 69 70verbose "$tid: recursive remote dir to local dir" 71scpclean 72rm -rf ${DIR2} 73cp ${DATA} ${DIR}/copy 74$SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed" 75diff -rN ${DIR} ${DIR2} || fail "corrupted copy" 76 77verbose "$tid: shell metacharacters" 78scpclean 79(cd ${DIR} && \ 80 touch '`touch metachartest`' && \ 81 $SCP $scpopts *metachar* ${DIR2} 2>/dev/null; \ 82 [ ! -f metachartest ] ) || fail "shell metacharacters" 83 84if [ ! -z "$SUDO" ]; then 85 verbose "$tid: skipped file after scp -p with failed chown+utimes" 86 scpclean 87 cp -p ${DATA} ${DIR}/copy 88 cp -p ${DATA} ${DIR}/copy2 89 cp ${DATA} ${DIR2}/copy 90 chmod 660 ${DIR2}/copy 91 $SUDO chown root ${DIR2}/copy 92 $SCP -p $scpopts somehost:${DIR}/\* ${DIR2} >/dev/null 2>&1 93 $SUDO diff -rN ${DIR} ${DIR2} || fail "corrupted copy" 94 $SUDO rm ${DIR2}/copy 95fi 96 97for i in 0 1 2 3 4; do 98 verbose "$tid: disallow bad server #$i" 99 SCPTESTMODE=badserver_$i 100 export DIR SCPTESTMODE 101 scpclean 102 $SCP $scpopts somehost:${DATA} ${DIR} >/dev/null 2>/dev/null 103 [ -d {$DIR}/rootpathdir ] && fail "allows dir relative to root dir" 104 [ -d ${DIR}/dotpathdir ] && fail "allows dir creation in non-recursive mode" 105 106 scpclean 107 $SCP -r $scpopts somehost:${DATA} ${DIR2} >/dev/null 2>/dev/null 108 [ -d ${DIR}/dotpathdir ] && fail "allows dir creation outside of subdir" 109done 110 111verbose "$tid: detect non-directory target" 112scpclean 113echo a > ${COPY} 114echo b > ${COPY2} 115$SCP $scpopts ${DATA} ${COPY} ${COPY2} 116cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target" 117 118scpclean 119rm -f ${OBJ}/scp-ssh-wrapper.exe 120