xref: /freebsd-src/crypto/openssh/regress/scp3.sh (revision edf8578117e8844e02c0121147f45e4609b30680)
1*edf85781SEd Maste#	$OpenBSD: scp3.sh,v 1.5 2023/09/08 06:10:57 djm Exp $
219261079SEd Maste#	Placed in the Public Domain.
319261079SEd Maste
419261079SEd Mastetid="scp3"
519261079SEd Maste
619261079SEd MasteCOPY2=${OBJ}/copy2
719261079SEd MasteDIR=${COPY}.dd
819261079SEd MasteDIR2=${COPY}.dd2
919261079SEd Maste
10f374ba41SEd Mastemaybe_add_scp_path_to_sshd
1138a52bd3SEd Maste
1219261079SEd MasteSRC=`dirname ${SCRIPT}`
1319261079SEd Mastecp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
1419261079SEd Mastechmod 755 ${OBJ}/scp-ssh-wrapper.scp
1519261079SEd Masteexport SCP # used in scp-ssh-wrapper.scp
1619261079SEd Maste
1719261079SEd Mastescpclean() {
1819261079SEd Maste	rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
1919261079SEd Maste	mkdir ${DIR} ${DIR2}
2019261079SEd Maste	chmod 755 ${DIR} ${DIR2}
2119261079SEd Maste}
2219261079SEd Maste
23*edf85781SEd Maste# Create directory structure for recursive copy tests.
24*edf85781SEd Masteforest() {
25*edf85781SEd Maste	scpclean
26*edf85781SEd Maste	rm -rf ${DIR2}
27*edf85781SEd Maste	cp ${DATA} ${DIR}/copy
28*edf85781SEd Maste	ln -s ${DIR}/copy ${DIR}/copy-sym
29*edf85781SEd Maste	mkdir ${DIR}/subdir
30*edf85781SEd Maste	cp ${DATA} ${DIR}/subdir/copy
31*edf85781SEd Maste	ln -s ${DIR}/subdir ${DIR}/subdir-sym
32*edf85781SEd Maste}
33*edf85781SEd Maste
3419261079SEd Mastefor mode in scp sftp ; do
3519261079SEd Maste	scpopts="-F${OBJ}/ssh_proxy -S ${SSH} -q"
3619261079SEd Maste	tag="$tid: $mode mode"
3719261079SEd Maste	if test $mode = scp ; then
3819261079SEd Maste		scpopts="$scpopts -O"
3919261079SEd Maste	else
4019261079SEd Maste		scpopts="-s -D ${SFTPSERVER}"
4119261079SEd Maste	fi
4219261079SEd Maste
4319261079SEd Maste	verbose "$tag: simple copy remote file to remote file"
4419261079SEd Maste	scpclean
4519261079SEd Maste	$SCP $scpopts -3 hostA:${DATA} hostB:${COPY} || fail "copy failed"
4619261079SEd Maste	cmp ${DATA} ${COPY} || fail "corrupted copy"
4719261079SEd Maste
4819261079SEd Maste	verbose "$tag: simple copy remote file to remote dir"
4919261079SEd Maste	scpclean
5019261079SEd Maste	cp ${DATA} ${COPY}
5119261079SEd Maste	$SCP $scpopts -3 hostA:${COPY} hostB:${DIR} || fail "copy failed"
5219261079SEd Maste	cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
5319261079SEd Maste
5419261079SEd Maste	verbose "$tag: recursive remote dir to remote dir"
55*edf85781SEd Maste	forest
5619261079SEd Maste	$SCP $scpopts -3r hostA:${DIR} hostB:${DIR2} || fail "copy failed"
5719261079SEd Maste	diff -r ${DIR} ${DIR2} || fail "corrupted copy"
5819261079SEd Maste	diff -r ${DIR2} ${DIR} || fail "corrupted copy"
5919261079SEd Maste
6019261079SEd Maste	verbose "$tag: detect non-directory target"
6119261079SEd Maste	scpclean
6219261079SEd Maste	echo a > ${COPY}
6319261079SEd Maste	echo b > ${COPY2}
6419261079SEd Maste	$SCP $scpopts -3 hostA:${DATA} hostA:${COPY} hostB:${COPY2}
6519261079SEd Maste	cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target"
6619261079SEd Mastedone
6719261079SEd Maste
6819261079SEd Mastescpclean
6919261079SEd Masterm -f ${OBJ}/scp-ssh-wrapper.exe
70