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