2009-10-06 23:43:57 +00:00
|
|
|
# $OpenBSD: sftp-glob.sh,v 1.4 2009/08/13 01:11:55 djm Exp $
|
2005-03-07 07:25:53 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="sftp glob"
|
|
|
|
|
2011-01-17 05:17:09 +00:00
|
|
|
config_defined FILESYSTEM_NO_BACKSLASH && nobs="not supported on this platform"
|
|
|
|
|
2007-10-26 04:54:12 +00:00
|
|
|
sftp_ls() {
|
|
|
|
target=$1
|
|
|
|
errtag=$2
|
|
|
|
expected=$3
|
|
|
|
unexpected=$4
|
2011-01-17 05:17:09 +00:00
|
|
|
skip=$5
|
|
|
|
if test "x$skip" != "x" ; then
|
|
|
|
verbose "$tid: $errtag (skipped: $skip)"
|
|
|
|
return
|
|
|
|
fi
|
2007-10-26 04:54:12 +00:00
|
|
|
verbose "$tid: $errtag"
|
2007-10-26 05:35:54 +00:00
|
|
|
printf "ls -l %s" "${target}" | \
|
2009-10-06 23:43:57 +00:00
|
|
|
${SFTP} -b - -D ${SFTPSERVER} 2>/dev/null | \
|
2007-10-26 04:54:12 +00:00
|
|
|
grep -v "^sftp>" > ${RESULTS}
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
fail "$errtag failed"
|
|
|
|
fi
|
2008-03-08 03:00:33 +00:00
|
|
|
if test "x$expected" != "x" ; then
|
|
|
|
if fgrep "$expected" ${RESULTS} >/dev/null 2>&1 ; then
|
|
|
|
:
|
|
|
|
else
|
2007-10-26 04:54:12 +00:00
|
|
|
fail "$expected missing from $errtag results"
|
2008-03-08 03:00:33 +00:00
|
|
|
fi
|
2007-10-26 04:54:12 +00:00
|
|
|
fi
|
|
|
|
if test "x$unexpected" != "x" && \
|
|
|
|
fgrep "$unexpected" ${RESULTS} >/dev/null 2>&1 ; then
|
|
|
|
fail "$unexpected present in $errtag results"
|
|
|
|
fi
|
|
|
|
rm -f ${RESULTS}
|
|
|
|
}
|
|
|
|
|
2005-03-07 07:25:53 +00:00
|
|
|
BASE=${OBJ}/glob
|
2007-10-26 04:54:12 +00:00
|
|
|
RESULTS=${OBJ}/results
|
2005-03-07 07:25:53 +00:00
|
|
|
DIR=${BASE}/dir
|
|
|
|
DATA=${DIR}/file
|
|
|
|
|
2007-10-26 04:54:12 +00:00
|
|
|
GLOB1="${DIR}/g-wild*"
|
|
|
|
GLOB2="${DIR}/g-wildx"
|
|
|
|
QUOTE="${DIR}/g-quote\""
|
|
|
|
SLASH="${DIR}/g-sl\\ash"
|
|
|
|
ESLASH="${DIR}/g-slash\\"
|
|
|
|
QSLASH="${DIR}/g-qs\\\""
|
|
|
|
SPACE="${DIR}/g-q space"
|
|
|
|
|
2005-03-07 07:25:53 +00:00
|
|
|
rm -rf ${BASE}
|
|
|
|
mkdir -p ${DIR}
|
2011-01-17 05:17:09 +00:00
|
|
|
touch "${DATA}" "${GLOB1}" "${GLOB2}" "${QUOTE}" "${SPACE}"
|
|
|
|
test "x$nobs" = "x" && touch "${QSLASH}" "${ESLASH}" "${SLASH}"
|
2007-10-26 04:54:12 +00:00
|
|
|
|
|
|
|
# target message expected unexpected
|
|
|
|
sftp_ls "${DIR}/fil*" "file glob" "${DATA}" ""
|
|
|
|
sftp_ls "${BASE}/d*" "dir glob" "`basename ${DATA}`" ""
|
|
|
|
sftp_ls "${DIR}/g-wild\"*\"" "quoted glob" "g-wild*" "g-wildx"
|
|
|
|
sftp_ls "${DIR}/g-wild\*" "escaped glob" "g-wild*" "g-wildx"
|
|
|
|
sftp_ls "${DIR}/g-quote\\\"" "escaped quote" "g-quote\"" ""
|
|
|
|
sftp_ls "\"${DIR}/g-quote\\\"\"" "quoted quote" "g-quote\"" ""
|
|
|
|
sftp_ls "'${DIR}/g-quote\"'" "single-quoted quote" "g-quote\"" ""
|
|
|
|
sftp_ls "${DIR}/g-q\\ space" "escaped space" "g-q space" ""
|
|
|
|
sftp_ls "'${DIR}/g-q space'" "quoted space" "g-q space" ""
|
2011-01-17 05:17:09 +00:00
|
|
|
sftp_ls "${DIR}/g-sl\\\\ash" "escaped slash" "g-sl\\ash" "" "$nobs"
|
|
|
|
sftp_ls "'${DIR}/g-sl\\\\ash'" "quoted slash" "g-sl\\ash" "" "$nobs"
|
|
|
|
sftp_ls "${DIR}/g-slash\\\\" "escaped slash at EOL" "g-slash\\" "" "$nobs"
|
|
|
|
sftp_ls "'${DIR}/g-slash\\\\'" "quoted slash at EOL" "g-slash\\" "" "$nobs"
|
|
|
|
sftp_ls "${DIR}/g-qs\\\\\\\"" "escaped slash+quote" "g-qs\\\"" "" "$nobs"
|
|
|
|
sftp_ls "'${DIR}/g-qs\\\\\"'" "quoted slash+quote" "g-qs\\\"" "" "$nobs"
|
2005-03-07 07:25:53 +00:00
|
|
|
|
|
|
|
rm -rf ${BASE}
|
2007-10-26 04:54:12 +00:00
|
|
|
|