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