1# $OpenBSD: Makefile,v 1.3 2015/07/28 12:25:27 zhuk Exp $ 2 3REGRESS_TARGETS = \ 4 t-okay \ 5 t-fail-quotes \ 6 t-permit-1 \ 7 t-run-keepenv-path 8 9REGRESS_ROOT_TARGETS = ${REGRESS_TARGETS:M*-run*} 10 11TEST_CONFIG_CMD = doas -C ${.CURDIR}/$@.conf >$@.out 2>$@.err 12TEST_ERRORS_CMD = \ 13 if [ -s $@.err -a ! -s ${.CURDIR}/$@.expected.err ]; then \ 14 echo "FAIL: unexpected error output:" >&2; \ 15 cat $@.err >&2; \ 16 exit 1; \ 17 elif [ -s ${.CURDIR}/$@.expected.err ]; then \ 18 diff -u ${.CURDIR}/$@.expected.err $@.err; \ 19 fi 20TEST_OUTPUT_CMD = ${TEST_ERRORS_CMD:C/\.err/.out/:C/error //} 21 22CLEANFILES += ${REGRESS_TARGETS:=.out} 23CLEANFILES += ${REGRESS_TARGETS:=.err} 24 25.for t in ${REGRESS_TARGETS:N*-fail*:N*-permit*:N*-run*} 26${t}: 27 @echo '$@' 28 @${TEST_CONFIG_CMD} 29 @${TEST_ERRORS_CMD} 30 @${TEST_OUTPUT_CMD} 31.endfor 32 33.for t in ${REGRESS_TARGETS:M*-fail*} 34${t}: 35 @echo '$@' 36 @ ! ${TEST_CONFIG_CMD} 37 @${TEST_ERRORS_CMD} 38 @${TEST_OUTPUT_CMD} 39.endfor 40 41.for t in ${REGRESS_TARGETS:M*-permit*} 42${t}: 43 @echo '$@' 44 @rv=true; \ 45 while read ident cmdline; do \ 46 read expected; \ 47 set +e; \ 48 action=$$(doas -C ${.CURDIR}/$@.conf -u $$ident $$cmdline); \ 49 ret=$$?; \ 50 set -e; \ 51 if [ X"$$action" != X"$$expected" ]; then \ 52 echo "FAILED: expected '$$expected'," \ 53 "but got '$$action'" >&2; \ 54 echo " for command: $$cmdline" >&2; \ 55 rv=false; \ 56 fi; \ 57 if [ X"$$action" = Xdeny -a $$ret -eq 0 ]; then \ 58 echo "FAILED: deny without error return" >&2; \ 59 echo " for command: $$cmdline" >&2; \ 60 rv=false; \ 61 elif [ X"$$action" != Xdeny -a $$ret -ne 0 ]; then \ 62 echo "FAILED: permit with error return" >&2; \ 63 echo " for command: $$cmdline" >&2; \ 64 rv=false; \ 65 fi; \ 66 done <${.CURDIR}/$@.patterns; \ 67 $$rv 68.endfor 69 70.for t in ${REGRESS_TARGETS:M*-run*} 71${t}: 72 @echo '$@' 73 @${SUDO} rm -Rf $t.root 74 @${SUDO} install -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} $t.root/etc 75 @${SUDO} install -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} $t.root/bin 76 @${SUDO} install -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} $t.root/usr/bin 77 @${SUDO} install -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} $t.root/usr/lib 78 @${SUDO} install -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} $t.root/usr/libexec 79 @${SUDO} install -o root -g wheel -m 0444 \ 80 ${.CURDIR}/$t.conf $t.root/etc/doas.conf 81 @${SUDO} install -o root -g wheel -m 0400 \ 82 ${.CURDIR}/master.passwd $t.root/etc/master.passwd 83 @${SUDO} pwd_mkdb -d $t.root/etc -p master.passwd 84 @${SUDO} install -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} \ 85 /usr/libexec/ld.so $t.root/usr/libexec/ld.so 86 @${SUDO} install -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 87 /usr/lib/libc.so.* $t.root/usr/lib 88 @${SUDO} install -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 89 /bin/echo $t.root/bin/echo 90 @${SUDO} install -o ${BINOWN} -g ${BINGRP} -m 4555 \ 91 /usr/bin/doas $t.root/usr/bin/doas 92 @${SUDO} env MALLOC_OPTIONS=S chroot -u nobody $t.root /usr/bin/doas echo okay 93.endfor 94# cleanup copied files 95afterclean: cleanroots 96cleanroots: 97.for t in ${REGRESS_TARGETS:M*-run*} 98 ${SUDO} rm -Rf $t.root 99.endfor 100 101.include <bsd.regress.mk> 102