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