Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 1 | # $OpenBSD: sftp-glob.sh,v 1.4 2009/08/13 01:11:55 djm Exp $ |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="sftp glob" |
| 5 | |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 6 | config_defined FILESYSTEM_NO_BACKSLASH && nobs="not supported on this platform" |
| 7 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 8 | sftp_ls() { |
| 9 | target=$1 |
| 10 | errtag=$2 |
| 11 | expected=$3 |
| 12 | unexpected=$4 |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 13 | skip=$5 |
| 14 | if test "x$skip" != "x" ; then |
| 15 | verbose "$tid: $errtag (skipped: $skip)" |
| 16 | return |
| 17 | fi |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 18 | verbose "$tid: $errtag" |
Damien Miller | da1e4bd | 2007-10-26 15:35:54 +1000 | [diff] [blame] | 19 | printf "ls -l %s" "${target}" | \ |
Darren Tucker | ed6b0c5 | 2009-10-07 10:43:57 +1100 | [diff] [blame] | 20 | ${SFTP} -b - -D ${SFTPSERVER} 2>/dev/null | \ |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 21 | grep -v "^sftp>" > ${RESULTS} |
| 22 | if [ $? -ne 0 ]; then |
| 23 | fail "$errtag failed" |
| 24 | fi |
Tim Rice | 68d2938 | 2008-03-07 19:00:33 -0800 | [diff] [blame] | 25 | if test "x$expected" != "x" ; then |
| 26 | if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then |
| 27 | : |
| 28 | else |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 29 | fail "$expected missing from $errtag results" |
Tim Rice | 68d2938 | 2008-03-07 19:00:33 -0800 | [diff] [blame] | 30 | fi |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 31 | fi |
| 32 | if test "x$unexpected" != "x" && \ |
| 33 | fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then |
| 34 | fail "$unexpected present in $errtag results" |
| 35 | fi |
| 36 | rm -f ${RESULTS} |
| 37 | } |
| 38 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 39 | BASE=${OBJ}/glob |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 40 | RESULTS=${OBJ}/results |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 41 | DIR=${BASE}/dir |
| 42 | DATA=${DIR}/file |
| 43 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 44 | GLOB1="${DIR}/g-wild*" |
| 45 | GLOB2="${DIR}/g-wildx" |
| 46 | QUOTE="${DIR}/g-quote\"" |
| 47 | SLASH="${DIR}/g-sl\\ash" |
| 48 | ESLASH="${DIR}/g-slash\\" |
| 49 | QSLASH="${DIR}/g-qs\\\"" |
| 50 | SPACE="${DIR}/g-q space" |
| 51 | |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 52 | rm -rf ${BASE} |
| 53 | mkdir -p ${DIR} |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 54 | touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" "${SPACE}" |
| 55 | test "x$nobs" = "x" && touch "${QSLASH}" "${ESLASH}" "${SLASH}" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 56 | |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 57 | # target message expected unexpected |
| 58 | sftp_ls "${DIR}/fil*" "file glob" "${DATA}" "" |
| 59 | sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" "" |
| 60 | sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx" |
| 61 | sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx" |
| 62 | sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" "" |
| 63 | sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" "" |
| 64 | sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" "" |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 65 | sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" "" |
| 66 | sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" "" |
Damien Miller | 5849778 | 2011-01-17 16:17:09 +1100 | [diff] [blame] | 67 | sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" "$nobs" |
| 68 | sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" "$nobs" |
| 69 | sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" "$nobs" |
| 70 | sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" "$nobs" |
| 71 | sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" "$nobs" |
| 72 | sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" "$nobs" |
Darren Tucker | 68f7213 | 2005-03-07 18:25:53 +1100 | [diff] [blame] | 73 | |
| 74 | rm -rf ${BASE} |
Damien Miller | ce0e60e | 2007-10-26 14:54:12 +1000 | [diff] [blame] | 75 | |