1*190cef3dSDag-Erling Smørgrav# $OpenBSD: cfgparse.sh,v 1.7 2018/05/11 03:51:06 dtucker Exp $ 2557f75e5SDag-Erling Smørgrav# Placed in the Public Domain. 3557f75e5SDag-Erling Smørgrav 4076ad2f8SDag-Erling Smørgravtid="sshd config parse" 5557f75e5SDag-Erling Smørgrav 6557f75e5SDag-Erling Smørgrav# This is a reasonable proxy for IPv6 support. 7557f75e5SDag-Erling Smørgravif ! config_defined HAVE_STRUCT_IN6_ADDR ; then 8557f75e5SDag-Erling Smørgrav SKIP_IPV6=yes 9557f75e5SDag-Erling Smørgravfi 10557f75e5SDag-Erling Smørgrav 11557f75e5SDag-Erling Smørgrav# We need to use the keys generated for the regression test because sshd -T 12557f75e5SDag-Erling Smørgrav# will fail if we're not running with SUDO (no permissions for real keys) or 13*190cef3dSDag-Erling Smørgrav# if we are running tests on a system that has never had sshd installed 14*190cef3dSDag-Erling Smørgrav# because the keys won't exist. 15557f75e5SDag-Erling Smørgrav 16557f75e5SDag-Erling Smørgravgrep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal 17557f75e5SDag-Erling SmørgravSSHD_KEYS="`cat $OBJ/sshd_config_minimal`" 18557f75e5SDag-Erling Smørgrav 19557f75e5SDag-Erling Smørgravverbose "reparse minimal config" 20557f75e5SDag-Erling Smørgrav($SUDO ${SSHD} -T -f $OBJ/sshd_config_minimal >$OBJ/sshd_config.1 && 21557f75e5SDag-Erling Smørgrav $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 >$OBJ/sshd_config.2 && 22557f75e5SDag-Erling Smørgrav diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse minimal config" 23557f75e5SDag-Erling Smørgrav 24557f75e5SDag-Erling Smørgravverbose "reparse regress config" 25557f75e5SDag-Erling Smørgrav($SUDO ${SSHD} -T -f $OBJ/sshd_config >$OBJ/sshd_config.1 && 26557f75e5SDag-Erling Smørgrav $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 >$OBJ/sshd_config.2 && 27557f75e5SDag-Erling Smørgrav diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse regress config" 28557f75e5SDag-Erling Smørgrav 29557f75e5SDag-Erling Smørgravverbose "listenaddress order" 30557f75e5SDag-Erling Smørgrav# expected output 31557f75e5SDag-Erling Smørgravcat > $OBJ/sshd_config.0 <<EOD 32557f75e5SDag-Erling Smørgravlistenaddress 1.2.3.4:1234 33557f75e5SDag-Erling Smørgravlistenaddress 1.2.3.4:5678 34557f75e5SDag-Erling SmørgravEOD 35557f75e5SDag-Erling Smørgrav[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 <<EOD 36557f75e5SDag-Erling Smørgravlistenaddress [::1]:1234 37557f75e5SDag-Erling Smørgravlistenaddress [::1]:5678 38557f75e5SDag-Erling SmørgravEOD 39557f75e5SDag-Erling Smørgrav 40557f75e5SDag-Erling Smørgrav# test input sets. should all result in the output above. 41557f75e5SDag-Erling Smørgrav# test 1: addressfamily and port first 42557f75e5SDag-Erling Smørgravcat > $OBJ/sshd_config.1 <<EOD 43557f75e5SDag-Erling Smørgrav${SSHD_KEYS} 44557f75e5SDag-Erling Smørgravaddressfamily any 45557f75e5SDag-Erling Smørgravport 1234 46557f75e5SDag-Erling Smørgravport 5678 47557f75e5SDag-Erling Smørgravlistenaddress 1.2.3.4 48557f75e5SDag-Erling SmørgravEOD 49557f75e5SDag-Erling Smørgrav[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD 50557f75e5SDag-Erling Smørgravlistenaddress ::1 51557f75e5SDag-Erling SmørgravEOD 52557f75e5SDag-Erling Smørgrav 53557f75e5SDag-Erling Smørgrav($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \ 54557f75e5SDag-Erling Smørgrav grep 'listenaddress ' >$OBJ/sshd_config.2 && 55557f75e5SDag-Erling Smørgrav diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \ 56557f75e5SDag-Erling Smørgrav fail "listenaddress order 1" 57557f75e5SDag-Erling Smørgrav# test 2: listenaddress first 58557f75e5SDag-Erling Smørgravcat > $OBJ/sshd_config.1 <<EOD 59557f75e5SDag-Erling Smørgrav${SSHD_KEYS} 60557f75e5SDag-Erling Smørgravlistenaddress 1.2.3.4 61557f75e5SDag-Erling Smørgravport 1234 62557f75e5SDag-Erling Smørgravport 5678 63557f75e5SDag-Erling Smørgravaddressfamily any 64557f75e5SDag-Erling SmørgravEOD 65557f75e5SDag-Erling Smørgrav[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD 66557f75e5SDag-Erling Smørgravlistenaddress ::1 67557f75e5SDag-Erling SmørgravEOD 68557f75e5SDag-Erling Smørgrav 69557f75e5SDag-Erling Smørgrav($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \ 70557f75e5SDag-Erling Smørgrav grep 'listenaddress ' >$OBJ/sshd_config.2 && 71557f75e5SDag-Erling Smørgrav diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \ 72557f75e5SDag-Erling Smørgrav fail "listenaddress order 2" 73557f75e5SDag-Erling Smørgrav 74557f75e5SDag-Erling Smørgrav# cleanup 75557f75e5SDag-Erling Smørgravrm -f $OBJ/sshd_config.[012] 76