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