From 4d94227a08a7855f781e8f4863afb4d72c46c4e2 Mon Sep 17 00:00:00 2001 From: Roland Smith Date: Mon, 27 Apr 2015 19:33:11 +0200 Subject: [PATCH 1/3] Find FreeBSD service binary. --- include/binaries | 1 + 1 file changed, 1 insertion(+) diff --git a/include/binaries b/include/binaries index 844027d3..5b85adb2 100644 --- a/include/binaries +++ b/include/binaries @@ -163,6 +163,7 @@ salt-master) SALTMASTERFOUND=1; SALTMASTERBINARY="${BINARY}"; logtext " Found known binary: salt-master (SaltStack master) - ${BINARY}" ;; salt-minion) SALTMINIONFOUND=1; SALTMINIONBINARY="${BINARY}"; logtext " Found known binary: salt-minion (SaltStack client) - ${BINARY}" ;; samhain) SAMHAINFOUND=1; SAMHAINBINARY="${BINARY}"; logtext " Found known binary: samhain (integrity tool) - ${BINARY}" ;; + service) SERVICEFOUND=1; SERVICEBINARY="${BINARY}"; logtext " Found known binary: service (system services) - ${BINARY}" ;; sestatus) SESTATUSFOUND=1; SESTATUSBINARY="${BINARY}"; logtext " Found known binary: sestatus (SELinux client) - ${BINARY}" ;; slocate) LOCATEFOUND=1; LOCATEBINARY="${BINARY}"; logtext " Found known binary: slocate (file database) - ${BINARY}" ;; smbd) SMBDFOUND=1; SMBDBINARY="${BINARY}"; if [ "${OS}" = "MacOS" ]; then SMBDVERSION="unknown"; else SMBDVERSION=`${BINARY} -V | grep "^Version" | awk '{ print $2 }'`; fi; logtext "Found ${BINARY} (version ${SMBDVERSION})" ;; From db828b5e03653c1159b0e1adaf8190be6574edba Mon Sep 17 00:00:00 2001 From: Roland Smith Date: Mon, 27 Apr 2015 19:58:07 +0200 Subject: [PATCH 2/3] Used service(8) to discover running services. On all supported FreeBSD releases, the service(8) program can be used to discover which services are running. This program has been added to the test for binaries. If available, it will be used to test for services. If not, the original code that parses /etc/rc.conf is used. On my system, the following information is produced in the logfile: [19:51:22] Performing test ID BOOT-5165 (Check for FreeBSD boot services) [19:51:22] Searching for services at startup (service) [19:51:23] Found service (service/rc.conf): bgfsck [19:51:23] Found service (service/rc.conf): cleanvar [19:51:23] Found service (service/rc.conf): cron [19:51:23] Found service (service/rc.conf): cupsd [19:51:23] Found service (service/rc.conf): dbus [19:51:23] Found service (service/rc.conf): devd [19:51:23] Found service (service/rc.conf): dmesg [19:51:23] Found service (service/rc.conf): dnsmasq [19:51:23] Found service (service/rc.conf): gptboot [19:51:23] Found service (service/rc.conf): hostid [19:51:23] Found service (service/rc.conf): hostid_save [19:51:23] Found service (service/rc.conf): ip6addrctl [19:51:23] Found service (service/rc.conf): ipfw [19:51:23] Found service (service/rc.conf): mixer [19:51:23] Found service (service/rc.conf): motd [19:51:23] Found service (service/rc.conf): newsyslog [19:51:23] Found service (service/rc.conf): nginx [19:51:23] Found service (service/rc.conf): openntpd [19:51:23] Found service (service/rc.conf): postfix [19:51:23] Found service (service/rc.conf): powerd [19:51:23] Found service (service/rc.conf): sendmail [19:51:23] Found service (service/rc.conf): smartd [19:51:23] Found service (service/rc.conf): syslogd [19:51:23] Found service (service/rc.conf): virecover [19:51:23] Found 24 services/options to run at startup The report shows: [+] Boot and services ------------------------------------ - Service Manager [ UNKNOWN ] - Checking presence FreeBSD loader [ FOUND ] - Checking services at startup (service/rc.conf) [ DONE ] Result: found 24 services/options set --- include/tests_boot_services | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/tests_boot_services b/include/tests_boot_services index 35fee381..58f6ef5e 100644 --- a/include/tests_boot_services +++ b/include/tests_boot_services @@ -382,16 +382,22 @@ # Description : Check for FreeBSD boot services Register --test-no BOOT-5165 --os FreeBSD --weight L --network NO --description "Check for FreeBSD boot services" if [ ${SKIPTEST} -eq 0 ]; then - # FreeBSD (Read /etc/rc.conf file for enabled services) - logtext "Searching for services at startup (rc.conf)" - FIND=`egrep -v -i '^#|none' /etc/rc.conf | egrep -i '_enable.*(yes|on|1)' | sort | awk -F= '{ print $1 }' | sed 's/_enable//'` + if [ ! "${SERVICEBINARY}" = "" ]; then + # FreeBSD (Ask services(8) for enabled services) + logtext "Searching for services at startup (service)" + FIND=`${SERVICEBINARY} -e | sed 's|^.*\/||' | sort` + else + # FreeBSD (Read /etc/rc.conf file for enabled services) + logtext "Searching for services at startup (rc.conf)" + FIND=`egrep -v -i '^#|none' /etc/rc.conf | egrep -i '_enable.*(yes|on|1)' | sort | awk -F= '{ print $1 }' | sed 's/_enable//'` + fi N=0 for I in ${FIND}; do - logtext "Found service (rc.conf): ${I}" + logtext "Found service (service/rc.conf): ${I}" report "boottask[]=${I}" N=`expr ${N} + 1` done - Display --indent 2 --text "- Checking services at startup (rc.conf)" --result "DONE" --color GREEN + Display --indent 2 --text "- Checking services at startup (service/rc.conf)" --result "DONE" --color GREEN Display --indent 6 --text "Result: found $N services/options set" logtext "Found $N services/options to run at startup" fi From 1bb5b4b0a69694e3e23aa9587a5c73884bd8c0d1 Mon Sep 17 00:00:00 2001 From: Roland Smith Date: Mon, 27 Apr 2015 20:09:18 +0200 Subject: [PATCH 3/3] FreeBSD uses the bsdrc service manager. With this patch, a run on my machine returns: [+] Initializing program ------------------------------------ - Detecting OS... [ DONE ] --------------------------------------------------- Program version: 2.1.1 Operating system: FreeBSD Operating system name: FreeBSD ... [+] Boot and services ------------------------------------ - Service Manager [ bsdrc ] --- include/tests_boot_services | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tests_boot_services b/include/tests_boot_services index 58f6ef5e..4a1f250c 100644 --- a/include/tests_boot_services +++ b/include/tests_boot_services @@ -99,7 +99,7 @@ if [ -f /usr/bin/init-openrc ]; then SERVICE_MANAGER="openrc"; fi fi ;; - "DragonFly"|"NetBSD") + "DragonFly"|"NetBSD"|"FreeBSD") if [ -x /sbin/init -a -d /etc/rc.d -a -f /etc/rc ]; then SERVICE_MANAGER="bsdrc" fi