sftp-badcmds.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # $OpenBSD: sftp-badcmds.sh,v 1.7 2020/03/13 03:18:45 djm Exp $
  2. # Placed in the Public Domain.
  3. tid="sftp invalid commands"
  4. DATA2=/bin/sh${EXEEXT}
  5. NONEXIST=/NONEXIST.$$
  6. GLOBFILES=$(
  7. cd /bin
  8. echo l*
  9. )
  10. rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
  11. rm -f ${COPY}
  12. verbose "$tid: get nonexistent"
  13. echo "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  14. fail "get nonexistent failed"
  15. test -f ${COPY} && fail "existing copy after get nonexistent"
  16. rm -f ${COPY}.dd/*
  17. verbose "$tid: glob get to nonexistent directory"
  18. echo "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  19. fail "get nonexistent failed"
  20. for x in $GLOBFILES; do
  21. test -f ${COPY}.dd/$x && fail "existing copy after get nonexistent"
  22. done
  23. rm -f ${COPY}
  24. verbose "$tid: put nonexistent"
  25. echo "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  26. fail "put nonexistent failed"
  27. test -f ${COPY} && fail "existing copy after put nonexistent"
  28. rm -f ${COPY}.dd/*
  29. verbose "$tid: glob put to nonexistent directory"
  30. echo "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  31. fail "put nonexistent failed"
  32. for x in $GLOBFILES; do
  33. test -f ${COPY}.dd/$x && fail "existing copy after nonexistent"
  34. done
  35. rm -f ${COPY}
  36. verbose "$tid: rename nonexistent"
  37. echo "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  38. fail "rename nonexist failed"
  39. test -f ${COPY}.1 && fail "file exists after rename nonexistent"
  40. rm -rf ${COPY} ${COPY}.dd
  41. cp $DATA $COPY
  42. mkdir ${COPY}.dd
  43. verbose "$tid: rename target exists (directory)"
  44. echo "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1 ||
  45. fail "rename target exists (directory) failed"
  46. test -f ${COPY} || fail "oldname missing after rename target exists (directory)"
  47. test -d ${COPY}.dd || fail "newname missing after rename target exists (directory)"
  48. cmp $DATA ${COPY} > /dev/null 2>&1 || fail "corrupted oldname after rename target exists (directory)"
  49. rm -f ${COPY}.dd/*
  50. rm -rf ${COPY}
  51. cp ${DATA2} ${COPY}
  52. verbose "$tid: glob put files to local file"
  53. echo "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} > /dev/null 2>&1
  54. cmp ${DATA2} ${COPY} || fail "put succeeded when it should have failed"
  55. rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd