1285033Sdes# $OpenBSD: cfgparse.sh,v 1.5 2015/05/29 03:05:13 djm Exp $ 2285033Sdes# Placed in the Public Domain. 3285033Sdes 4285033Sdestid="config parse" 5285033Sdes 6285033Sdes# This is a reasonable proxy for IPv6 support. 7285033Sdesif ! config_defined HAVE_STRUCT_IN6_ADDR ; then 8285033Sdes SKIP_IPV6=yes 9285033Sdesfi 10285033Sdes 11285033Sdes# We need to use the keys generated for the regression test because sshd -T 12285033Sdes# will fail if we're not running with SUDO (no permissions for real keys) or 13285033Sdes# if we are # running tests on a system that has never had sshd installed 14285033Sdes# (keys won't exist). 15285033Sdes 16285033Sdesgrep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal 17285033SdesSSHD_KEYS="`cat $OBJ/sshd_config_minimal`" 18285033Sdes 19285033Sdesverbose "reparse minimal config" 20285033Sdes($SUDO ${SSHD} -T -f $OBJ/sshd_config_minimal >$OBJ/sshd_config.1 && 21285033Sdes $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 >$OBJ/sshd_config.2 && 22285033Sdes diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse minimal config" 23285033Sdes 24285033Sdesverbose "reparse regress config" 25285033Sdes($SUDO ${SSHD} -T -f $OBJ/sshd_config >$OBJ/sshd_config.1 && 26285033Sdes $SUDO ${SSHD} -T -f $OBJ/sshd_config.1 >$OBJ/sshd_config.2 && 27285033Sdes diff $OBJ/sshd_config.1 $OBJ/sshd_config.2) || fail "reparse regress config" 28285033Sdes 29285033Sdesverbose "listenaddress order" 30285033Sdes# expected output 31285033Sdescat > $OBJ/sshd_config.0 <<EOD 32285033Sdeslistenaddress 1.2.3.4:1234 33285033Sdeslistenaddress 1.2.3.4:5678 34285033SdesEOD 35285033Sdes[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 <<EOD 36285033Sdeslistenaddress [::1]:1234 37285033Sdeslistenaddress [::1]:5678 38285033SdesEOD 39285033Sdes 40285033Sdes# test input sets. should all result in the output above. 41285033Sdes# test 1: addressfamily and port first 42285033Sdescat > $OBJ/sshd_config.1 <<EOD 43285033Sdes${SSHD_KEYS} 44285033Sdesaddressfamily any 45285033Sdesport 1234 46285033Sdesport 5678 47285033Sdeslistenaddress 1.2.3.4 48285033SdesEOD 49285033Sdes[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD 50285033Sdeslistenaddress ::1 51285033SdesEOD 52285033Sdes 53285033Sdes($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \ 54285033Sdes grep 'listenaddress ' >$OBJ/sshd_config.2 && 55285033Sdes diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \ 56285033Sdes fail "listenaddress order 1" 57285033Sdes# test 2: listenaddress first 58285033Sdescat > $OBJ/sshd_config.1 <<EOD 59285033Sdes${SSHD_KEYS} 60285033Sdeslistenaddress 1.2.3.4 61285033Sdesport 1234 62285033Sdesport 5678 63285033Sdesaddressfamily any 64285033SdesEOD 65285033Sdes[ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD 66285033Sdeslistenaddress ::1 67285033SdesEOD 68285033Sdes 69285033Sdes($SUDO ${SSHD} -T -f $OBJ/sshd_config.1 | \ 70285033Sdes grep 'listenaddress ' >$OBJ/sshd_config.2 && 71285033Sdes diff $OBJ/sshd_config.0 $OBJ/sshd_config.2) || \ 72285033Sdes fail "listenaddress order 2" 73285033Sdes 74285033Sdes# cleanup 75285033Sdesrm -f $OBJ/sshd_config.[012] 76