Darren Tucker | 438f60e | 2013-05-17 20:43:13 +1000 | [diff] [blame] | 1 | # $OpenBSD: sftp-badcmds.sh,v 1.6 2013/05/17 10:26:26 dtucker Exp $ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="sftp invalid commands" |
| 5 | |
Tim Rice | 9ad7e0e | 2004-02-12 07:17:10 -0800 | [diff] [blame] | 6 | DATA2=/bin/sh${EXEEXT} |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 7 | NONEXIST=/NONEXIST.$$ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 8 | GLOBFILES=`(cd /bin;echo l*)` |
| 9 | |
Tim Rice | 1eb40cf | 2003-09-09 08:35:20 -0700 | [diff] [blame] | 10 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 11 | |
| 12 | rm -f ${COPY} |
| 13 | verbose "$tid: get nonexistent" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 14 | echo "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 15 | || fail "get nonexistent failed" |
| 16 | test -f ${COPY} && fail "existing copy after get nonexistent" |
| 17 | |
| 18 | rm -f ${COPY}.dd/* |
| 19 | verbose "$tid: glob get to nonexistent directory" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 20 | echo "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 21 | || fail "get nonexistent failed" |
| 22 | for x in $GLOBFILES; do |
| 23 | test -f ${COPY}.dd/$x && fail "existing copy after get nonexistent" |
| 24 | done |
| 25 | |
| 26 | rm -f ${COPY} |
| 27 | verbose "$tid: put nonexistent" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 28 | echo "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 29 | || fail "put nonexistent failed" |
| 30 | test -f ${COPY} && fail "existing copy after put nonexistent" |
| 31 | |
| 32 | rm -f ${COPY}.dd/* |
| 33 | verbose "$tid: glob put to nonexistent directory" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 34 | echo "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 35 | || fail "put nonexistent failed" |
| 36 | for x in $GLOBFILES; do |
| 37 | test -f ${COPY}.dd/$x && fail "existing copy after nonexistent" |
| 38 | done |
| 39 | |
| 40 | rm -f ${COPY} |
| 41 | verbose "$tid: rename nonexistent" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 42 | echo "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 43 | || fail "rename nonexist failed" |
| 44 | test -f ${COPY}.1 && fail "file exists after rename nonexistent" |
| 45 | |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 46 | rm -rf ${COPY} ${COPY}.dd |
| 47 | cp $DATA $COPY |
| 48 | mkdir ${COPY}.dd |
| 49 | verbose "$tid: rename target exists (directory)" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 50 | echo "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 51 | || fail "rename target exists (directory) failed" |
| 52 | test -f ${COPY} || fail "oldname missing after rename target exists (directory)" |
| 53 | test -d ${COPY}.dd || fail "newname missing after rename target exists (directory)" |
| 54 | cmp $DATA ${COPY} >/dev/null 2>&1 || fail "corrupted oldname after rename target exists (directory)" |
| 55 | |
| 56 | rm -f ${COPY}.dd/* |
| 57 | rm -rf ${COPY} |
| 58 | cp ${DATA2} ${COPY} |
| 59 | verbose "$tid: glob put files to local file" |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 60 | echo "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 61 | cmp ${DATA2} ${COPY} || fail "put successed when it should have failed" |
| 62 | |
Tim Rice | 1eb40cf | 2003-09-09 08:35:20 -0700 | [diff] [blame] | 63 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd |
Darren Tucker | fc8a7ea | 2003-06-18 22:18:57 +1000 | [diff] [blame] | 64 | |
| 65 | |