#!/usr/bin/env bash{a_output=()a_output2=()a_output3=()a_out=()a_out2=()a_parlist=("NTP=[^#\n\r]+""FallbackNTP=[^#\n\r]+")l_analyze_cmd="$(readlink-f/bin/systemd-analyze)"l_systemd_config_file="/etc/systemd/timesyncd.conf"f_config_file_parameter_chk(){l_used_parameter_setting=""whileIFS=read-rl_file;dol_file="$(tr-d'# '<<<"$l_file")"l_used_parameter_setting="$(grep-PHs--'^\h*'"$l_parameter_name"'\b'"$l_file"|tail-n1)"[-n"$l_used_parameter_setting"]&&breakdone<<($l_analyze_cmdcat-config"$l_systemd_config_file"|tac|grep-Pio'^\h*#\h*\/[^#\n\r\h]+\.conf\b')if[-n"$l_used_parameter_setting"];thenwhileIFS=:read-rl_file_namel_file_parameter;dowhileIFS="="read-rl_file_parameter_namel_file_parameter_value;doifgrep-Pq--"$l_parameter_value"<<<"$l_file_parameter_value";thena_out+=(" - Parameter: \"${l_file_parameter_name// /}\""\"correctlysetto:\"${l_file_parameter_value// /}\"" \"in the file:\"$l_file_name\"")elsea_out2+=(" - Parameter: \"${l_file_parameter_name// /}\""\"incorrectlysetto:\"${l_file_parameter_value// /}\"" \"in the file:\"$l_file_name\""\"Shouldbesetto:\"$l_value_out\"")fidone <<< "$l_file_parameter"done <<< "$l_used_parameter_setting"elsea_out2+=("-Parameter:\"$l_parameter_name\"isnotsetinanincludedfile" \"*** Note: \"$l_parameter_name\" May be set in a file that's ignored by load procedure ***")fi}whileIFS="="read-rl_parameter_namel_parameter_value;do# Assess and check parametersl_parameter_name="${l_parameter_name// /}";l_parameter_value="${l_parameter_value// /}"l_value_out="${l_parameter_value//-/ through }";l_value_out="${l_value_out//|/ or }"l_value_out="$(tr-d'(){}'<<<"$l_value_out")"f_config_file_parameter_chk
done<<(printf'%s\n'"${a_parlist[@]}")if["${#a_out[@]}"-gt0];thena_output+=("${a_out[@]}");["${#a_out2[@]}"-gt0]&&a_output3+=(" ** INFO: **""${a_out2[@]}")elsea_output2+=("${a_out2[@]}")fiif["${#a_output2[@]}"-le0];thenprintf'%s\n'"""- Audit Result:"" ** PASS **""${a_output[@]}"""["${#a_output3[@]}"-gt0]&&printf'%s\n'"${a_output3[@]}"elseprintf'%s\n'"""- Audit Result:"" ** FAIL **"" - Reason(s) for audit failure:""${a_output2[@]}"["${#a_output[@]}"-gt0]&&printf'%s\n'"""- Correctly set:""${a_output[@]}"""fi}
Note: Please ensure the output for NTP and/or FallbackNTP is in accordance with local site policy. The timeservers in the example output are provided as an example of possible timeservers and they may not follow local site policy.
## Remediation
Set **NTP** and/or **FallbackNPT** parameters to local site approved authoritative time server(s) in **/etc/systemd/timesyncd.conf** or a file in **/etc/systemd/timesyncd.conf.d/** ending in **.conf** in the **[Time]** section:
Example file:
```bash
[Time]
NTP=time.nist.gov # Uses the generic name for NIST's time servers
FallbackNTP=time-a-g.nist.gov time-b-g.nist.gov time-c-g.nist.gov # Space separated list of NIST time servers
Example script to create the systemd drop-in configuration file: