sftp-glob.sh 2.5 KB

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