blob: ccf511f6b861e05241431101a8319da339ee44ca [file] [log] [blame]
dtucker@openbsd.orgab0a5362016-06-03 03:47:59 +00001# $OpenBSD: cfgparse.sh,v 1.6 2016/06/03 03:47:59 dtucker Exp $
dtucker@openbsd.org38b82722015-05-04 01:47:53 +00002# Placed in the Public Domain.
3
dtucker@openbsd.orgab0a5362016-06-03 03:47:59 +00004tid="sshd config parse"
dtucker@openbsd.org38b82722015-05-04 01:47:53 +00005
Damien Miller52fb6b92015-06-30 16:05:40 +10006# This is a reasonable proxy for IPv6 support.
7if ! config_defined HAVE_STRUCT_IN6_ADDR ; then
8 SKIP_IPV6=yes
9fi
10
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000011# 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
16grep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal
17SSHD_KEYS="`cat $OBJ/sshd_config_minimal`"
18
19verbose "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
24verbose "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
29verbose "listenaddress order"
30# expected output
31cat > $OBJ/sshd_config.0 <<EOD
32listenaddress 1.2.3.4:1234
33listenaddress 1.2.3.4:5678
Damien Miller52fb6b92015-06-30 16:05:40 +100034EOD
35[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 <<EOD
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000036listenaddress [::1]:1234
37listenaddress [::1]:5678
38EOD
Damien Miller52fb6b92015-06-30 16:05:40 +100039
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000040# test input sets. should all result in the output above.
41# test 1: addressfamily and port first
42cat > $OBJ/sshd_config.1 <<EOD
43${SSHD_KEYS}
44addressfamily any
45port 1234
46port 5678
47listenaddress 1.2.3.4
Damien Miller52fb6b92015-06-30 16:05:40 +100048EOD
49[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000050listenaddress ::1
51EOD
Damien Miller52fb6b92015-06-30 16:05:40 +100052
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000053($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
58cat > $OBJ/sshd_config.1 <<EOD
djm@openbsd.orgdb438f92015-05-29 03:05:13 +000059${SSHD_KEYS}
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000060listenaddress 1.2.3.4
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000061port 1234
62port 5678
63addressfamily any
64EOD
Damien Miller52fb6b92015-06-30 16:05:40 +100065[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
66listenaddress ::1
67EOD
68
dtucker@openbsd.org38b82722015-05-04 01:47:53 +000069($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
75rm -f $OBJ/sshd_config.[012]