diff options
-rw-r--r-- | regress/usr.bin/snmp/Makefile | 15 | ||||
-rw-r--r-- | regress/usr.sbin/snmpd/Makefile | 19 | ||||
-rw-r--r-- | regress/usr.sbin/snmpd/snmpd.sh | 70 |
3 files changed, 72 insertions, 32 deletions
diff --git a/regress/usr.bin/snmp/Makefile b/regress/usr.bin/snmp/Makefile index a4c0f6776d2..983efc2ddf5 100644 --- a/regress/usr.bin/snmp/Makefile +++ b/regress/usr.bin/snmp/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2023/11/06 09:46:04 martijn Exp $ +# $OpenBSD: Makefile,v 1.7 2024/02/08 17:09:51 martijn Exp $ SNMP?= /usr/bin/snmp SNMPD?= /usr/sbin/snmpd -f ${.OBJDIR}/snmpd.conf @@ -31,6 +31,7 @@ snmpd.conf: Makefile printf 'listen on $$listen6_addr snmpv1 snmpv2c snmpv3\n' >> snmpd.conf printf 'listen on tcp $$listen6_addr snmpv1 snmpv2c snmpv3\n' >> snmpd.conf printf 'listen on $$listen_addr notify snmpv1 snmpv2c snmpv3\n\n' >> snmpd.conf + printf 'agentx path "/tmp/agentx"\n\n' >> snmpd.conf printf 'read-only community public\n' >> snmpd.conf printf 'read-write community private\n' >> snmpd.conf printf 'trap community public\n\n' >> snmpd.conf @@ -79,7 +80,19 @@ trap_output: Makefile chmod a+rw trap_output start: stop snmpd.conf traphandle.sh trap_output + rm -f /tmp/agentx 2>/dev/null ${SUDO} ${SNMPD} + @(i=0; \ + while [ ! -S /tmp/agentx ]; do \ + i=$$((i + 1)); \ + [ $$i -eq 100 ] && ( \ + printf "%s\n" '${SUDO} pkill -xf "${SNMPD}"'; \ + printf "Failed to start snmpd\n" >&2; \ + ${SUDO} pkill -xf "${SNMPD}"; \ + exit 1; \ + ); \ + sleep 0.1; \ + done;) stop: -${SUDO} pkill -xf "${SNMPD}" diff --git a/regress/usr.sbin/snmpd/Makefile b/regress/usr.sbin/snmpd/Makefile index 63b0fc01711..22bb422008d 100644 --- a/regress/usr.sbin/snmpd/Makefile +++ b/regress/usr.sbin/snmpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.12 2023/11/20 10:34:21 martijn Exp $ +# $OpenBSD: Makefile,v 1.13 2024/02/08 17:09:51 martijn Exp $ # Regress tests for snmpd PROG = snmpd_regress @@ -261,8 +261,21 @@ transport: ${TRANSPORT_TARGETS} ${REGRESS_TARGETS}: snmpd_regress # Always start snmpd if it's not running - @pgrep -q snmpd || \ - (printf "%s\n" "${SNMPD_START}"; ${SNMPD_START} sleep 0.5) + @pgrep -q snmpd || ( \ + printf "%s\n" "${SNMPD_START}"; \ + rm -f /tmp/agentx 2>/dev/null; \ + ${SNMPD_START} \ + i=0; \ + while [ ! -S /tmp/agentx ]; do \ + i=$$((i + 1)); \ + [ $$i -eq 100 ] && ( \ + printf "Failed to start snmpd\n"; >&2 \ + ${SUDO} pkill -f ${SNMPD}; \ + exit 1; \ + ); \ + sleep 0.1; \ + done \ + ) ./snmpd_regress ${SNMPD_REGRESS_FLAGS} $@ # Make sure that snmpd hasn't crashed in the meantime. @sleep 0.01 diff --git a/regress/usr.sbin/snmpd/snmpd.sh b/regress/usr.sbin/snmpd/snmpd.sh index 29438e33cc4..137d0f7aa9b 100644 --- a/regress/usr.sbin/snmpd/snmpd.sh +++ b/regress/usr.sbin/snmpd/snmpd.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: snmpd.sh,v 1.19 2023/11/04 09:42:17 martijn Exp $ +# $OpenBSD: snmpd.sh,v 1.20 2024/02/08 17:09:51 martijn Exp $ #/* # * Copyright (c) Rob Pierce <rob@openbsd.org> # * @@ -26,6 +26,8 @@ SLEEP=1 PF[0]="disabled" PF[1]="enabled" +STARTSOCK="/tmp/agentx" + # This file will be creatred by traphandler.c as user _snmpd TMPFILE=$(mktemp -q /tmp/_snmpd_traptest.XXXXXX) @@ -38,7 +40,30 @@ then exit 0 fi +snmpdstart() { + rm "${STARTSOCK}" >/dev/null 2>&1 + (cd ${OBJDIR} && nohup snmpd -dvf ./snmpd.conf > snmpd.log 2>&1) & + i=0 + # wait max ~10s + while [ ! -S "$STARTSOCK" ]; do + i=$((i + 1)) + if [ $i -eq 100 ]; then + echo "Failed to start snmpd" >&2 + snmpdstop + fail + fi + sleep 0.1 + done +} + +snmpdstop() { + pkill snmpd + wait + rm -f "${STARTSOCK}" >/dev/null 2>&1 +} + cleanup() { + rm ${STARTSOCK} >/dev/null 2>&1 rm ${TMPFILE} >/dev/null 2>&1 rm ${OBJDIR}/nohup.out >/dev/null 2>&1 rm ${OBJDIR}/snmpd.log >/dev/null 2>&1 @@ -69,6 +94,8 @@ listen on 127.0.0.1 snmpv2c notify listen on ::1 snmpv1 snmpv2c snmpv3 listen on ::1 snmpv2c notify +agentx path "${STARTSOCK}" + # Specify communities read-only community public read-write community private @@ -77,11 +104,7 @@ trap community public trap handle 1.2.3.4 "/usr/bin/touch ${TMPFILE}" EOF -(cd ${OBJDIR} && nohup snmpd -dvf ./snmpd.conf > snmpd.log 2>&1) & - -sleep ${SLEEP} - -[ ! -n "$(pgrep snmpd)" ] && echo "Failed to start snmpd." && fail +snmpdstart # pf (also checks "oid all" which obtains privileged kernel data @@ -166,8 +189,7 @@ fi # FAILED=1 #fi -kill $(pgrep snmpd) >/dev/null 2>&1 -wait +snmpdstop # # # # # CONFIG TWO # # # # # echo "\nConfiguration: seclevel auth\n" @@ -178,16 +200,14 @@ cat > ${OBJDIR}/snmpd.conf <<EOF listen on 127.0.0.1 listen on ::1 +agentx path "${STARTSOCK}" + seclevel auth user "hans" authkey "password123" auth hmac-sha1 EOF -(cd ${OBJDIR} && nohup snmpd -dvf ./snmpd.conf > snmpd.log 2>&1) & - -sleep ${SLEEP} - -[ ! -n "$(pgrep snmpd)" ] && echo "Failed to start snmpd." && fail +snmpdstart # make sure we can't get an oid with deault community string @@ -213,8 +233,7 @@ then FAILED=1 fi -kill $(pgrep snmpd) >/dev/null 2>&1 -wait +snmpdstop # # # # # CONFIG THREE # # # # # echo "\nConfiguration: seclevel enc\n" @@ -225,16 +244,14 @@ cat > ${OBJDIR}/snmpd.conf <<EOF listen on 127.0.0.1 listen on ::1 +agentx path "${STARTSOCK}" + seclevel enc user "hans" authkey "password123" auth hmac-sha1 enc aes enckey "321drowssap" EOF -(cd ${OBJDIR} && nohup snmpd -dvf ./snmpd.conf > snmpd.log 2>&1) & - -sleep ${SLEEP} - -[ ! -n "$(pgrep snmpd)" ] && echo "Failed to start snmpd." && fail +snmpdstart # get with SHA authentication and AES encryption @@ -249,8 +266,7 @@ then FAILED=1 fi -kill $(pgrep snmpd) >/dev/null 2>&1 -wait +snmpdstop # # # # # CONFIG FOUR # # # # # echo "\nConfiguration: non-default community strings, custom oids\n" @@ -264,6 +280,8 @@ cat > ${OBJDIR}/snmpd.conf <<EOF listen on 127.0.0.1 snmpv1 snmpv2c listen on ::1 snmpv1 snmpv2c +agentx path "${STARTSOCK}" + read-only community non-default-ro read-write community non-default-rw @@ -273,11 +291,7 @@ oid 1.3.6.1.4.1.30155.42.2 name myStatus read-only integer 1 # No need to place a full index, we just need the object EOF -(cd ${OBJDIR} && nohup snmpd -dvf ./snmpd.conf > snmpd.log 2>&1) & - -sleep ${SLEEP} - -[ ! -n "$(pgrep snmpd)" ] && echo "Failed to start snmpd." && fail +snmpdstart # carp allow with non-default ro community string @@ -343,7 +357,7 @@ fi # FAILED=1 #fi -kill $(pgrep snmpd) >/dev/null 2>&1 +snmpdstop case $FAILED in 0) echo |