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# We need to use the keys generated for the regression test because sshd -T
7# will fail if we're not running with SUDO (no permissions for real keys) or
8# if we are running tests on a system that has never had sshd installed
9# because the keys won't exist.
10
11grep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal
12SSHD_KEYS="`cat $OBJ/sshd_config_minimal`"
13
14verbose "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
19verbose "reparse regress config"
20($SUDO ${SSHD} -T -f $OBJ/sshd_config >$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 regress config"
23
24verbose "listenaddress order"
25# expected output
26cat > $OBJ/sshd_config.0 <<EOD
27listenaddress 1.2.3.4:1234
28listenaddress 1.2.3.4:5678
29listenaddress [::1]:1234
30listenaddress [::1]:5678
31EOD
32# test input sets.  should all result in the output above.
33# test 1: addressfamily and port first
34cat > $OBJ/sshd_config.1 <<EOD
35${SSHD_KEYS}
36addressfamily any
37port 1234
38port 5678
39listenaddress 1.2.3.4
40listenaddress ::1
41EOD
42($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \
43 grep 'listenaddress ' >$OBJ/sshd_config.2 &&
44 diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \
45 fail "listenaddress order 1"
46# test 2: listenaddress first
47cat > $OBJ/sshd_config.1 <<EOD
48${SSHD_KEYS}
49listenaddress 1.2.3.4
50listenaddress ::1
51port 1234
52port 5678
53addressfamily any
54EOD
55($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \
56 grep 'listenaddress ' >$OBJ/sshd_config.2 &&
57 diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \
58 fail "listenaddress order 2"
59
60# cleanup
61rm -f $OBJ/sshd_config.[012]
62