]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - crypto/openssh/regress/scp.sh
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / crypto / openssh / regress / scp.sh
1 #       $OpenBSD: scp.sh,v 1.9 2013/05/17 10:35:43 dtucker 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
24 scpclean() {
25         rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
26         mkdir ${DIR} ${DIR2}
27 }
28
29 verbose "$tid: simple copy local file to local file"
30 scpclean
31 $SCP $scpopts ${DATA} ${COPY} || fail "copy failed"
32 cmp ${DATA} ${COPY} || fail "corrupted copy"
33
34 verbose "$tid: simple copy local file to remote file"
35 scpclean
36 $SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed"
37 cmp ${DATA} ${COPY} || fail "corrupted copy"
38
39 verbose "$tid: simple copy remote file to local file"
40 scpclean
41 $SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed"
42 cmp ${DATA} ${COPY} || fail "corrupted copy"
43
44 verbose "$tid: simple copy local file to remote dir"
45 scpclean
46 cp ${DATA} ${COPY}
47 $SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed"
48 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
49
50 verbose "$tid: simple copy local file to local dir"
51 scpclean
52 cp ${DATA} ${COPY}
53 $SCP $scpopts ${COPY} ${DIR} || fail "copy failed"
54 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
55
56 verbose "$tid: simple copy remote file to local dir"
57 scpclean
58 cp ${DATA} ${COPY}
59 $SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed"
60 cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
61
62 verbose "$tid: recursive local dir to remote dir"
63 scpclean
64 rm -rf ${DIR2}
65 cp ${DATA} ${DIR}/copy
66 $SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed"
67 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
68
69 verbose "$tid: recursive local dir to local dir"
70 scpclean
71 rm -rf ${DIR2}
72 cp ${DATA} ${DIR}/copy
73 $SCP $scpopts -r ${DIR} ${DIR2} || fail "copy failed"
74 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
75
76 verbose "$tid: recursive remote dir to local dir"
77 scpclean
78 rm -rf ${DIR2}
79 cp ${DATA} ${DIR}/copy
80 $SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed"
81 diff ${DIFFOPT} ${DIR} ${DIR2} || fail "corrupted copy"
82
83 verbose "$tid: shell metacharacters"
84 scpclean
85 (cd ${DIR} && \
86 touch '`touch metachartest`' && \
87 $SCP $scpopts *metachar* ${DIR2} 2>/dev/null; \
88 [ ! -f metachartest ] ) || fail "shell metacharacters"
89
90 if [ ! -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
101 fi
102
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
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"
115 done
116
117 verbose "$tid: detect non-directory target"
118 scpclean
119 echo a > ${COPY}
120 echo b > ${COPY2}
121 $SCP $scpopts ${DATA} ${COPY} ${COPY2}
122 cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target"
123
124 scpclean
125 rm -f ${OBJ}/scp-ssh-wrapper.scp