scp.sh revision 146998
1109998Smarkm# $OpenBSD: scp.sh,v 1.3 2004/07/08 12:59:35 dtucker Exp $ 2109998Smarkm# Placed in the Public Domain. 3109998Smarkm 4109998Smarkmtid="scp" 5109998Smarkm 6109998Smarkm#set -x 7109998Smarkm 8109998Smarkm# Figure out if diff understands "-N" 9280304Sjkimif diff -N ${SRC}/scp.sh ${SRC}/scp.sh 2>/dev/null; then 10109998Smarkm DIFFOPT="-rN" 11109998Smarkmelse 12109998Smarkm DIFFOPT="-r" 13109998Smarkmfi 14109998Smarkm 15109998SmarkmDATA=/bin/ls${EXEEXT} 16109998SmarkmCOPY=${OBJ}/copy 17109998SmarkmCOPY2=${OBJ}/copy2 18109998SmarkmDIR=${COPY}.dd 19109998SmarkmDIR2=${COPY}.dd2 20109998Smarkm 21109998SmarkmSRC=`dirname ${SCRIPT}` 22109998Smarkmcp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp 23109998Smarkmchmod 755 ${OBJ}/scp-ssh-wrapper.scp 24109998Smarkmscpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp" 25109998Smarkm 26109998Smarkmscpclean() { 27109998Smarkm rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} 28109998Smarkm mkdir ${DIR} ${DIR2} 29109998Smarkm} 30109998Smarkm 31109998Smarkmverbose "$tid: simple copy local file to remote file" 32109998Smarkmscpclean 33109998Smarkm$SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed" 34109998Smarkmcmp ${DATA} ${COPY} || fail "corrupted copy" 35109998Smarkm 36109998Smarkmverbose "$tid: simple copy remote file to local file" 37109998Smarkmscpclean 38109998Smarkm$SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed" 39109998Smarkmcmp ${DATA} ${COPY} || fail "corrupted copy" 40109998Smarkm 41109998Smarkmverbose "$tid: simple copy local file to remote dir" 42109998Smarkmscpclean 43109998Smarkmcp ${DATA} ${COPY} 44109998Smarkm$SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed" 45109998Smarkmcmp ${COPY} ${DIR}/copy || fail "corrupted copy" 46109998Smarkm 47109998Smarkmverbose "$tid: simple copy remote file to local dir" 48109998Smarkmscpclean 49109998Smarkmcp ${DATA} ${COPY} 50109998Smarkm$SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed" 51109998Smarkmcmp ${COPY} ${DIR}/copy || fail "corrupted copy" 52109998Smarkm 53109998Smarkmverbose "$tid: recursive local dir to remote dir" 54109998Smarkmscpclean 55109998Smarkmrm -rf ${DIR2} 56109998Smarkmcp ${DATA} ${DIR}/copy 57280304Sjkim$SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed" 58280304Sjkimdiff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy" 59280304Sjkim 60280304Sjkimverbose "$tid: recursive remote dir to local dir" 61280304Sjkimscpclean 62109998Smarkmrm -rf ${DIR2} 63109998Smarkmcp ${DATA} ${DIR}/copy 64109998Smarkm$SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed" 65109998Smarkmdiff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy" 66109998Smarkm 67280304Sjkimif [ ! -z "$SUDO" ]; then 68280304Sjkim verbose "$tid: skipped file after scp -p with failed chown+utimes" 69280304Sjkim scpclean 70109998Smarkm cp -p ${DATA} ${DIR}/copy 71109998Smarkm cp -p ${DATA} ${DIR}/copy2 72280304Sjkim cp ${DATA} ${DIR2}/copy 73280304Sjkim chmod 660 ${DIR2}/copy 74280304Sjkim $SUDO chown root ${DIR2}/copy 75109998Smarkm $SCP -p $scpopts somehost:${DIR}/\* ${DIR2} >/dev/null 2>&1 76109998Smarkm diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy" 77280304Sjkim $SUDO rm ${DIR2}/copy 78280304Sjkimfi 79280304Sjkim 80280304Sjkimfor i in 0 1 2 3 4; do 81280304Sjkim verbose "$tid: disallow bad server #$i" 82280304Sjkim SCPTESTMODE=badserver_$i 83280304Sjkim export DIR SCPTESTMODE 84280304Sjkim scpclean 85280304Sjkim $SCP $scpopts somehost:${DATA} ${DIR} >/dev/null 2>/dev/null 86280304Sjkim [ -d {$DIR}/rootpathdir ] && fail "allows dir relative to root dir" 87280304Sjkim [ -d ${DIR}/dotpathdir ] && fail "allows dir creation in non-recursive mode" 88109998Smarkm 89109998Smarkm scpclean 90280304Sjkim $SCP -r $scpopts somehost:${DATA} ${DIR2} >/dev/null 2>/dev/null 91280304Sjkim [ -d ${DIR}/dotpathdir ] && fail "allows dir creation outside of subdir" 92109998Smarkmdone 93280304Sjkim 94280304Sjkimscpclean 95280304Sjkimrm -f ${OBJ}/scp-ssh-wrapper.scp 96109998Smarkm