cfgparse.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # $OpenBSD: cfgparse.sh,v 1.7 2018/05/11 03:51:06 dtucker Exp $
  2. # Placed in the Public Domain.
  3. tid="sshd config parse"
  4. # This is a reasonable proxy for IPv6 support.
  5. if ! config_defined HAVE_STRUCT_IN6_ADDR; then
  6. SKIP_IPV6=yes
  7. fi
  8. # We need to use the keys generated for the regression test because sshd -T
  9. # will fail if we're not running with SUDO (no permissions for real keys) or
  10. # if we are running tests on a system that has never had sshd installed
  11. # because the keys won't exist.
  12. grep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal
  13. SSHD_KEYS="$(cat $OBJ/sshd_config_minimal)"
  14. verbose "reparse minimal config"
  15. ($SUDO ${SSHD} -T -f $OBJ/sshd_config_minimal > $OBJ/sshd_config.1 &&
  16. $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 > $OBJ/sshd_config.2 &&
  17. diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse minimal config"
  18. verbose "reparse regress config"
  19. ($SUDO ${SSHD} -T -f $OBJ/sshd_config > $OBJ/sshd_config.1 &&
  20. $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 > $OBJ/sshd_config.2 &&
  21. diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse regress config"
  22. verbose "listenaddress order"
  23. # expected output
  24. cat > $OBJ/sshd_config.0 << EOD
  25. listenaddress 1.2.3.4:1234
  26. listenaddress 1.2.3.4:5678
  27. EOD
  28. [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 << EOD
  29. listenaddress [::1]:1234
  30. listenaddress [::1]:5678
  31. EOD
  32. # test input sets. should all result in the output above.
  33. # test 1: addressfamily and port first
  34. cat > $OBJ/sshd_config.1 << EOD
  35. ${SSHD_KEYS}
  36. addressfamily any
  37. port 1234
  38. port 5678
  39. listenaddress 1.2.3.4
  40. EOD
  41. [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 << EOD
  42. listenaddress ::1
  43. EOD
  44. ($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 |
  45. grep 'listenaddress ' > $OBJ/sshd_config.2 &&
  46. diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) ||
  47. fail "listenaddress order 1"
  48. # test 2: listenaddress first
  49. cat > $OBJ/sshd_config.1 << EOD
  50. ${SSHD_KEYS}
  51. listenaddress 1.2.3.4
  52. port 1234
  53. port 5678
  54. addressfamily any
  55. EOD
  56. [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 << EOD
  57. listenaddress ::1
  58. EOD
  59. ($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 |
  60. grep 'listenaddress ' > $OBJ/sshd_config.2 &&
  61. diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) ||
  62. fail "listenaddress order 2"
  63. # cleanup
  64. rm -f $OBJ/sshd_config.[012]