xref: /freebsd/crypto/openssh/regress/cfgparse.sh (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1#	$OpenBSD: cfgparse.sh,v 1.7 2018/05/11 03:51:06 dtucker Exp $
2#	Placed in the Public Domain.
3
4tid="sshd config parse"
5
6# This is a reasonable proxy for IPv6 support.
7if ! config_defined HAVE_STRUCT_IN6_ADDR ; then
8	SKIP_IPV6=yes
9fi
10
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# because the 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
34EOD
35[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 <<EOD
36listenaddress [::1]:1234
37listenaddress [::1]:5678
38EOD
39
40# 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
48EOD
49[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
50listenaddress ::1
51EOD
52
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
58cat > $OBJ/sshd_config.1 <<EOD
59${SSHD_KEYS}
60listenaddress 1.2.3.4
61port 1234
62port 5678
63addressfamily any
64EOD
65[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
66listenaddress ::1
67EOD
68
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
75rm -f $OBJ/sshd_config.[012]
76