1 # $OpenBSD: scp.sh,v 1.9 2013/05/17 10:35:43 dtucker Exp $
2 # Placed in the Public Domain.
8 # Figure out if diff understands "-N"
9 if diff -N ${SRC}/scp.sh ${SRC}/scp.sh 2>/dev/null; then
19 SRC=`dirname ${SCRIPT}`
20 cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
21 chmod 755 ${OBJ}/scp-ssh-wrapper.scp
22 scpopts="-q -S ${OBJ}/scp-ssh-wrapper.scp"
25 rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
29 verbose "$tid: simple copy local file to local file"
31 $SCP $scpopts ${DATA} ${COPY} || fail "copy failed"
32 cmp ${DATA} ${COPY} || fail "corrupted copy"
34 verbose "$tid: simple copy local file to remote file"
36 $SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed"
37 cmp ${DATA} ${COPY} || fail "corrupted copy"
39 verbose "$tid: simple copy remote file to local file"
41 $SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed"
42 cmp ${DATA} ${COPY} || fail "corrupted copy"
44 verbose "$tid: simple copy local file to remote dir"
47 $SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed"
48 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
50 verbose "$tid: simple copy local file to local dir"
53 $SCP $scpopts ${COPY} ${DIR} || fail "copy failed"
54 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
56 verbose "$tid: simple copy remote file to local dir"
59 $SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed"
60 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
62 verbose "$tid: recursive local dir to remote dir"
65 cp ${DATA} ${DIR}/copy
66 $SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed"
67 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
69 verbose "$tid: recursive local dir to local dir"
72 cp ${DATA} ${DIR}/copy
73 $SCP $scpopts -r ${DIR} ${DIR2} || fail "copy failed"
74 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
76 verbose "$tid: recursive remote dir to local dir"
79 cp ${DATA} ${DIR}/copy
80 $SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed"
81 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
83 verbose "$tid: shell metacharacters"
86 touch '`touch metachartest`' && \
87 $SCP $scpopts *metachar* ${DIR2} 2>/dev/null; \
88 [ ! -f metachartest ] ) || fail "shell metacharacters"
90 if [ ! -z "$SUDO" ]; then
91 verbose "$tid: skipped file after scp -p with failed chown+utimes"
93 cp -p ${DATA} ${DIR}/copy
94 cp -p ${DATA} ${DIR}/copy2
95 cp ${DATA} ${DIR2}/copy
96 chmod 660 ${DIR2}/copy
97 $SUDO chown root ${DIR2}/copy
98 $SCP -p $scpopts somehost:${DIR}/\* ${DIR2} >/dev/null 2>&1
99 $SUDO diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
100 $SUDO rm ${DIR2}/copy
103 for i in 0 1 2 3 4; do
104 verbose "$tid: disallow bad server #$i"
105 SCPTESTMODE=badserver_$i
106 export DIR SCPTESTMODE
108 $SCP $scpopts somehost:${DATA} ${DIR} >/dev/null 2>/dev/null
109 [ -d {$DIR}/rootpathdir ] && fail "allows dir relative to root dir"
110 [ -d ${DIR}/dotpathdir ] && fail "allows dir creation in non-recursive mode"
113 $SCP -r $scpopts somehost:${DATA} ${DIR2} >/dev/null 2>/dev/null
114 [ -d ${DIR}/dotpathdir ] && fail "allows dir creation outside of subdir"
117 verbose "$tid: detect non-directory target"
121 $SCP $scpopts ${DATA} ${COPY} ${COPY2}
122 cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target"
125 rm -f ${OBJ}/scp-ssh-wrapper.scp