Home | History | Annotate | Download | only in regress
      1 #	$OpenBSD: cfgparse.sh,v 1.6 2016/06/03 03:47:59 dtucker Exp $
      2 #	Placed in the Public Domain.
      3 
      4 tid="sshd config parse"
      5 
      6 # This is a reasonable proxy for IPv6 support.
      7 if ! config_defined HAVE_STRUCT_IN6_ADDR ; then
      8 	SKIP_IPV6=yes
      9 fi
     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 # (keys won't exist).
     15 
     16 grep "HostKey " $OBJ/sshd_config > $OBJ/sshd_config_minimal
     17 SSHD_KEYS="`cat $OBJ/sshd_config_minimal`"
     18 
     19 verbose "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 
     24 verbose "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 
     29 verbose "listenaddress order"
     30 # expected output
     31 cat > $OBJ/sshd_config.0 <<EOD
     32 listenaddress 1.2.3.4:1234
     33 listenaddress 1.2.3.4:5678
     34 EOD
     35 [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.0 <<EOD
     36 listenaddress [::1]:1234
     37 listenaddress [::1]:5678
     38 EOD
     39 
     40 # test input sets.  should all result in the output above.
     41 # test 1: addressfamily and port first
     42 cat > $OBJ/sshd_config.1 <<EOD
     43 ${SSHD_KEYS}
     44 addressfamily any
     45 port 1234
     46 port 5678
     47 listenaddress 1.2.3.4
     48 EOD
     49 [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
     50 listenaddress ::1
     51 EOD
     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
     58 cat > $OBJ/sshd_config.1 <<EOD
     59 ${SSHD_KEYS}
     60 listenaddress 1.2.3.4
     61 port 1234
     62 port 5678
     63 addressfamily any
     64 EOD
     65 [ X${SKIP_IPV6} = Xyes ] || cat >> $OBJ/sshd_config.1 <<EOD
     66 listenaddress ::1
     67 EOD
     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
     75 rm -f $OBJ/sshd_config.[012]
     76