xref: /freebsd/crypto/openssh/regress/sftp-badcmds.sh (revision aa24f48b361effe51163877d84f1b70d32b77e04)
1#	$OpenBSD: sftp-badcmds.sh,v 1.6 2013/05/17 10:26:26 dtucker Exp $
2#	Placed in the Public Domain.
3
4tid="sftp invalid commands"
5
6DATA2=/bin/sh${EXEEXT}
7NONEXIST=/NONEXIST.$$
8GLOBFILES=`(cd /bin;echo l*)`
9
10rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
11
12rm -f ${COPY}
13verbose "$tid: get nonexistent"
14echo "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
15	|| 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"
20echo "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
21        || 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"
28echo "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
29	|| 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"
34echo "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
35        || 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"
42echo "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
43	|| fail "rename nonexist failed"
44test -f ${COPY}.1 && fail "file exists after rename nonexistent"
45
46rm -rf ${COPY} ${COPY}.dd
47cp $DATA $COPY
48mkdir ${COPY}.dd
49verbose "$tid: rename target exists (directory)"
50echo "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
51	|| 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"
60echo "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1
61cmp ${DATA2} ${COPY} || fail "put successed when it should have failed"
62
63rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
64
65
66