blob: 7f85c4f229cadda32b1832db16923aa4b50b07e9 [file] [log] [blame]
Darren Tucker438f60e2013-05-17 20:43:13 +10001# $OpenBSD: sftp-badcmds.sh,v 1.6 2013/05/17 10:26:26 dtucker Exp $
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +10002# Placed in the Public Domain.
3
4tid="sftp invalid commands"
5
Tim Rice9ad7e0e2004-02-12 07:17:10 -08006DATA2=/bin/sh${EXEEXT}
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +10007NONEXIST=/NONEXIST.$$
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +10008GLOBFILES=`(cd /bin;echo l*)`
9
Tim Rice1eb40cf2003-09-09 08:35:20 -070010rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100011
12rm -f ${COPY}
13verbose "$tid: get nonexistent"
Darren Tuckered6b0c52009-10-07 10:43:57 +110014echo "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100015 || fail "get nonexistent failed"
16test -f ${COPY} && fail "existing copy after get nonexistent"
17
18rm -f ${COPY}.dd/*
19verbose "$tid: glob get to nonexistent directory"
Darren Tuckered6b0c52009-10-07 10:43:57 +110020echo "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100021 || fail "get nonexistent failed"
22for x in $GLOBFILES; do
23 test -f ${COPY}.dd/$x && fail "existing copy after get nonexistent"
24done
25
26rm -f ${COPY}
27verbose "$tid: put nonexistent"
Darren Tuckered6b0c52009-10-07 10:43:57 +110028echo "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100029 || fail "put nonexistent failed"
30test -f ${COPY} && fail "existing copy after put nonexistent"
31
32rm -f ${COPY}.dd/*
33verbose "$tid: glob put to nonexistent directory"
Darren Tuckered6b0c52009-10-07 10:43:57 +110034echo "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100035 || fail "put nonexistent failed"
36for x in $GLOBFILES; do
37 test -f ${COPY}.dd/$x && fail "existing copy after nonexistent"
38done
39
40rm -f ${COPY}
41verbose "$tid: rename nonexistent"
Darren Tuckered6b0c52009-10-07 10:43:57 +110042echo "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100043 || fail "rename nonexist failed"
44test -f ${COPY}.1 && fail "file exists after rename nonexistent"
45
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100046rm -rf ${COPY} ${COPY}.dd
47cp $DATA $COPY
48mkdir ${COPY}.dd
49verbose "$tid: rename target exists (directory)"
Darren Tuckered6b0c52009-10-07 10:43:57 +110050echo "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100051 || fail "rename target exists (directory) failed"
52test -f ${COPY} || fail "oldname missing after rename target exists (directory)"
53test -d ${COPY}.dd || fail "newname missing after rename target exists (directory)"
54cmp $DATA ${COPY} >/dev/null 2>&1 || fail "corrupted oldname after rename target exists (directory)"
55
56rm -f ${COPY}.dd/*
57rm -rf ${COPY}
58cp ${DATA2} ${COPY}
59verbose "$tid: glob put files to local file"
Darren Tuckered6b0c52009-10-07 10:43:57 +110060echo "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100061cmp ${DATA2} ${COPY} || fail "put successed when it should have failed"
62
Tim Rice1eb40cf2003-09-09 08:35:20 -070063rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
Darren Tuckerfc8a7ea2003-06-18 22:18:57 +100064
65