Merge pull request #993 from Varbin/more-cron-ntp

[TIME-3104] Find more time synchronization commands
This commit is contained in:
Michael Boelen 2020-08-07 11:46:51 +02:00 committed by GitHub
commit 30e0fed04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,17 +134,20 @@
# Check crontab for OpenBSD/FreeBSD # Check crontab for OpenBSD/FreeBSD
# Check anacrontab for Linux # Check anacrontab for Linux
CRONTAB_FILES="/etc/anacrontab /etc/crontab" CRONTAB_FILES="/etc/anacrontab /etc/crontab"
# Regex for matching multiple time synchronisation binaries
# Partial sanity check for sntp and ntpdig, but this does not consider all corner cases
CRONTAB_REGEX='ntpdate|rdate|sntp.+-(s|j|--adj)|ntpdig.+-(S|s)'
for I in ${CRONTAB_FILES}; do for I in ${CRONTAB_FILES}; do
if [ -f ${I} ]; then if [ -f ${I} ]; then
LogText "Test: checking for ntpdate or rdate in crontab file ${I}" LogText "Test: checking for ntpdate, rdate, sntp or ntpdig in crontab file ${I}"
FIND=$(${EGREPBINARY} "ntpdate|rdate" ${I} | ${GREPBINARY} -v '^#') FIND=$(${EGREPBINARY} "${CRONTAB_REGEX}" ${I} | ${GREPBINARY} -v '^#')
if [ -n "${FIND}" ]; then if [ -n "${FIND}" ]; then
FOUND=1; NTP_CONFIG_TYPE_SCHEDULED=1 FOUND=1; NTP_CONFIG_TYPE_SCHEDULED=1
Display --indent 2 --text "- Checking NTP client in crontab file (${I})" --result "${STATUS_FOUND}" --color GREEN Display --indent 2 --text "- Checking NTP client in crontab file (${I})" --result "${STATUS_FOUND}" --color GREEN
LogText "Result: found ntpdate or rdate reference in crontab file ${I}" LogText "Result: found ntpdate, rdate, sntp or ntpdig reference in crontab file ${I}"
else else
#Display --indent 2 --text "- Checking NTP client in crontab file (${I})" --result "${STATUS_NOT_FOUND}" --color WHITE #Display --indent 2 --text "- Checking NTP client in crontab file (${I})" --result "${STATUS_NOT_FOUND}" --color WHITE
LogText "Result: no ntpdate or rdate reference found in crontab file ${I}" LogText "Result: no ntpdate, rdate, sntp or ntpdig reference found in crontab file ${I}"
fi fi
else else
LogText "Result: crontab file ${I} not found" LogText "Result: crontab file ${I} not found"
@ -157,31 +160,18 @@
# Check cron jobs # Check cron jobs
for I in ${CRON_DIRS}; do for I in ${CRON_DIRS}; do
if [ -d ${I} ]; then for J in "${I}"/*; do # iterate over folders in a safe way
if FileIsReadable ${I}; then # Check: regular file, readable and not called .placeholder
FIND=$(${FINDBINARY} ${I} -type f -a ! -name ".placeholder" -print 2> /dev/null | ${SEDBINARY} 's/ /__space__/g' | ${TRBINARY} '\n' '\0' | ${TRBINARY} -cd '[:print:]\0' | ${TRBINARY} '\0' ' ') FIND=$(echo "${J}" | ${EGREPBINARY} '/.placeholder$')
if [ -f "${J}" ] && [ -r "${J}" ] && [ -z "${FIND}" ]; then
LogText "Test: checking for ntpdate, rdate, sntp or ntpdig in ${J}"
FIND=$("${EGREPBINARY}" "${CRONTAB_REGEX}" "${J}" | "${GREPBINARY}" -v "^#")
if [ -n "${FIND}" ]; then if [ -n "${FIND}" ]; then
for J in ${FIND}; do FOUND=1; FOUND_IN_CRON=1; NTP_CONFIG_TYPE_SCHEDULED=1
# Place back spaces if needed LogText "Result: found ntpdate, rdate, sntp or ntpdig in ${J}"
J=$(echo ${J} | ${SEDBINARY} 's/__space__/ /g')
LogText "Test: checking for ntpdate or rdate in ${J}"
if FileIsReadable ${J}; then
FIND2=$(${EGREPBINARY} "rdate|ntpdate" "${J}" | ${GREPBINARY} -v "^#")
if [ -n "${FIND2}" ]; then
LogText "Positive match found: ${FIND2}"
FOUND=1; FOUND_IN_CRON=1; NTP_CONFIG_TYPE_SCHEDULED=1
fi
else
LogText "Result: could not test in file '${J}' as it is not readable"
fi
done
else
LogText "Result: ${I} is empty, skipping search in directory"
fi fi
else
LogText "Result: could not search in directory due to permissions"
fi fi
fi done
done done
if [ ${FOUND_IN_CRON} -eq 1 ]; then if [ ${FOUND_IN_CRON} -eq 1 ]; then