1255670Sdes#	$OpenBSD: sftp-badcmds.sh,v 1.6 2013/05/17 10:26:26 dtucker Exp $
2124208Sdes#	Placed in the Public Domain.
3124208Sdes
4124208Sdestid="sftp invalid commands"
5124208Sdes
6126274SdesDATA2=/bin/sh${EXEEXT}
7124208SdesNONEXIST=/NONEXIST.$$
8124208SdesGLOBFILES=`(cd /bin;echo l*)`
9124208Sdes
10124208Sdesrm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
11124208Sdes
12124208Sdesrm -f ${COPY}
13124208Sdesverbose "$tid: get nonexistent"
14204861Sdesecho "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
15124208Sdes	|| fail "get nonexistent failed"
16124208Sdestest -f ${COPY} && fail "existing copy after get nonexistent"
17124208Sdes
18124208Sdesrm -f ${COPY}.dd/*
19124208Sdesverbose "$tid: glob get to nonexistent directory"
20204861Sdesecho "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
21124208Sdes        || fail "get nonexistent failed"
22124208Sdesfor x in $GLOBFILES; do
23124208Sdes        test -f ${COPY}.dd/$x && fail "existing copy after get nonexistent"
24124208Sdesdone
25124208Sdes
26124208Sdesrm -f ${COPY}
27124208Sdesverbose "$tid: put nonexistent"
28204861Sdesecho "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
29124208Sdes	|| fail "put nonexistent failed"
30124208Sdestest -f ${COPY} && fail "existing copy after put nonexistent"
31124208Sdes
32124208Sdesrm -f ${COPY}.dd/*
33124208Sdesverbose "$tid: glob put to nonexistent directory"
34204861Sdesecho "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
35124208Sdes        || fail "put nonexistent failed"
36124208Sdesfor x in $GLOBFILES; do
37124208Sdes        test -f ${COPY}.dd/$x && fail "existing copy after nonexistent"
38124208Sdesdone
39124208Sdes
40124208Sdesrm -f ${COPY}
41124208Sdesverbose "$tid: rename nonexistent"
42204861Sdesecho "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
43124208Sdes	|| fail "rename nonexist failed"
44124208Sdestest -f ${COPY}.1 && fail "file exists after rename nonexistent"
45124208Sdes
46124208Sdesrm -rf ${COPY} ${COPY}.dd
47124208Sdescp $DATA $COPY
48124208Sdesmkdir ${COPY}.dd
49124208Sdesverbose "$tid: rename target exists (directory)"
50204861Sdesecho "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
51124208Sdes	|| fail "rename target exists (directory) failed"
52124208Sdestest -f ${COPY} || fail "oldname missing after rename target exists (directory)"
53124208Sdestest -d ${COPY}.dd || fail "newname missing after rename target exists (directory)"
54124208Sdescmp $DATA ${COPY} >/dev/null 2>&1 || fail "corrupted oldname after rename target exists (directory)"
55124208Sdes
56124208Sdesrm -f ${COPY}.dd/*
57124208Sdesrm -rf ${COPY}
58124208Sdescp ${DATA2} ${COPY}
59124208Sdesverbose "$tid: glob put files to local file"
60204861Sdesecho "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 
61124208Sdescmp ${DATA2} ${COPY} || fail "put successed when it should have failed"
62124208Sdes
63124208Sdesrm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
64124208Sdes
65124208Sdes
66