Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Biewald <simon@fam-biewald.de>2020-07-09 19:19:35 +0300
committerSimon Biewald <simon@fam-biewald.de>2020-07-09 19:19:35 +0300
commitb2be7c160e865252d0c589089e444a259576904f (patch)
treed38b1ef3b41299f3306577a06502402f4c348a04
parent6355360972136ee8eb9d8781f8732fee2812d441 (diff)
detect and test for timesyncd w/o working timedatectl
On systems without dbus timedatectl does not work. Thus it is checked if timesyncd currently runs and when /run/systemd/timesyncd/synchronized was last modified. Timesyncd touches this file on any sucessfull synchronization. This is documented in systemd-timesyncd(8). The new test for successfull documentation has the id TIME-3185.
-rw-r--r--include/tests_time57
1 files changed, 40 insertions, 17 deletions
diff --git a/include/tests_time b/include/tests_time
index 7c15d0a3..1985aa44 100644
--- a/include/tests_time
+++ b/include/tests_time
@@ -124,23 +124,11 @@
fi
# Check timedate daemon (systemd)
- if [ -n "${TIMEDATECTL}" ]; then
- FIND=$(${TIMEDATECTL} status | ${EGREPBINARY} "(NTP|System clock) synchronized: yes")
- if [ -n "${FIND}" ]; then
- # Check for systemd-timesyncd
- if [ -f ${ROOTDIR}etc/systemd/timesyncd.conf ]; then
- LogText "Result: found ${ROOTDIR}etc/systemd/timesyncd.conf"
- FOUND=1; NTP_DAEMON_RUNNING=1; NTP_CONFIG_TYPE_DAEMON=1; NTP_DAEMON="systemd-timesyncd"
- Display --indent 2 --text "- NTP daemon found: systemd (timesyncd)" --result "${STATUS_FOUND}" --color GREEN
- SYSTEMD_NTP_ENABLED=1
- else
- LogText "Result: ${ROOTDIR}etc/systemd/timesyncd.conf does not exist"
- fi
- else
- LogText "Result: time synchronization not performed according timedatectl command"
- fi
- else
- LogText "Result: timedatectl command not available on this system"
+ FIND=$(${PSBINARY} ax | ${GREPBINARY} "systemd-timesyncd" | ${GREPBINARY} -v "grep")
+ if [ -n "${FIND}" ]; then
+ FOUND=1; NTP_DAEMON_RUNNING=1; NTP_CONFIG_TYPE_DAEMON=1; NTP_DAEMON="systemd-timesyncd"
+ Display --indent 2 --text "- NTP daemon found: systemd (timesyncd)" --result "${STATUS_FOUND}" --color GREEN
+ LogText "Result: Found running systemd-timesyncd in process list"
fi
# Check crontab for OpenBSD/FreeBSD
@@ -581,6 +569,41 @@
ReportWarning "${TEST_NO}" "OpenNTPD has no peers" "${NTPCTLBINARY} -s status"
fi
fi
+
+#
+#################################################################################
+#
+
+ # Test : TIME-3185
+ # Description : Check systemd-timesyncd synchronized time
+
+ if [ "${NTP_DAEMON}" = "systemd-timesyncd" ]; then
+ PREQS_MET="YES"
+ else
+ PREQS_MET="NO"
+ fi
+
+
+ Register --test-no TIME-3185 --preqs-met "${PREQS_MET}" --weight L --network NO --category "time" --description "Check systemd-timesyncd synchronized time"
+ if [ ${SKIPTEST} -eq 0 ]; then
+ if [ -e /run/systemd/timesync/synchronized ]; then
+ FIND=$(( $(date +%s) - $(stat -L --format %Y /run/systemd/timesync/synchronized) ))
+ # Check if last sync was more than 2048 seconds (= the default of systemd) ago
+ if [ ${FIND} -ge 2048 ]; then
+ COLOR=RED
+ ReportWarning "${TEST_NO}" "systemd-timesyncd did not synchronized the time recently."
+ else
+ COLOR=GREEN
+ fi
+ Display --indent 2 --text "- Last time synchronization" --result "${FIND}s" --color "${COLOR}"
+ LogText "Result: systemd-timesyncd synchronized time ${FIND} seconds ago."
+ else
+ Display --indent 2 --text "- Last time synchronization" --result "${STATUS_NOT_FOUND}" --color RED
+ ReportWarning "${TEST_NO}" "systemd-timesyncd never successfully synchronized time"
+ fi
+ fi
+
+
#
#################################################################################
#