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