summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorcy <cy@FreeBSD.org>2016-08-27 02:53:21 +0000
committercy <cy@FreeBSD.org>2016-08-27 02:53:21 +0000
commitcd108e3a70d32cac160a084fedee33f0d52a3c58 (patch)
treec59a300721287e23bd64e4e76aa784202daeda4d /etc
parentdbd92a2d58ddf029a5692eca924eac0183ff23c8 (diff)
downloadFreeBSD-src-cd108e3a70d32cac160a084fedee33f0d52a3c58.zip
FreeBSD-src-cd108e3a70d32cac160a084fedee33f0d52a3c58.tar.gz
MFC r304779, r304780, r304781, r304782, r304802
r304779: Revert r298887 (spelling fix) and remove $FreeBSD$ because text changes to leap-seconds invaldidates validation hash at the end of the file. Remove svn:keywords and replace with fbsd:nokeywords=yes to support this change. r304780: Change the algorithm by which /var/db/leap-seconds is updated. 1. Use the leap-seconds version number (update time) to determine whether to update the file or not. 2. If the version numbers of the files is the same, use the later expiry date to determine which file to use. Suggested by: ian@ r304781: Add logic to replace the working ntp leap-seconds file in /var/db if it contains a $FreeBSD$ header. The header will cause the file to fail checksum of the hash causing ntpd to ignore the file. r304782: Make validation of the leap-seconds file unconditional. r304802: Remove the gratuitous check for $FreeBSD$ and rename the function to ntpd_init_leapfile, to ensure a copy exists in /var/db if a copy isn't already there. Reported by: ache@
Diffstat (limited to 'etc')
-rw-r--r--etc/ntp/leap-seconds4
-rwxr-xr-xetc/rc.d/ntpd27
2 files changed, 25 insertions, 6 deletions
diff --git a/etc/ntp/leap-seconds b/etc/ntp/leap-seconds
index c31d19a..68db85e 100644
--- a/etc/ntp/leap-seconds
+++ b/etc/ntp/leap-seconds
@@ -1,6 +1,4 @@
#
-# $FreeBSD$
-#
# In the following text, the symbol '#' introduces
# a comment, which continues from that symbol until
# the end of the line. A plain comment line has a
@@ -46,7 +44,7 @@
# by the International Bureau of Weights and Measures
# (BIPM). See www.bipm.fr for more information.
#
-# 3. The current definition of the relationship between UTC
+# 3. The current defintion of the relationship between UTC
# and TAI dates from 1 January 1972. A number of different
# time scales were in use before than epoch, and it can be
# quite difficult to compute precise timestamps and time
diff --git a/etc/rc.d/ntpd b/etc/rc.d/ntpd
index 91785b3..2ccdef7 100755
--- a/etc/rc.d/ntpd
+++ b/etc/rc.d/ntpd
@@ -28,6 +28,8 @@ ntpd_precmd()
rc_flags="-g $rc_flags"
fi
+ ntpd_init_leapfile
+
if [ ! -f $ntp_db_leapfile ]; then
ntpd_fetch_leapfile
fi
@@ -66,15 +68,27 @@ current_ntp_ts() {
}
get_ntp_leapfile_ver() {
+ # Leapfile update date (version number).
expr "$(awk '$1 == "#$" { print $2 }' "$1" 2>/dev/null)" : \
'^\([1-9][0-9]*\)$' \| 0
}
get_ntp_leapfile_expiry() {
+ # Leapfile expiry date.
expr "$(awk '$1 == "#@" { print $2 }' "$1" 2>/dev/null)" : \
'^\([1-9][0-9]*\)$' \| 0
}
+ntpd_init_leapfile() {
+ # Refresh working leapfile with an invalid hash due to
+ # FreeBSD id header. Ntpd will ignore leapfiles with a
+ # mismatch hash. The file must be the virgin file from
+ # the source.
+ if [ ! -f $ntp_db_leapfile ]; then
+ cp -p $ntp_src_leapfile $ntp_db_leapfile
+ fi
+}
+
ntpd_fetch_leapfile() {
local ntp_tmp_leapfile rc verbose
@@ -87,19 +101,23 @@ ntpd_fetch_leapfile() {
ntp_tmp_leapfile="/var/run/ntpd.leap-seconds.list"
ntp_ver_no_src=$(get_ntp_leapfile_ver $ntp_src_leapfile)
+ ntp_expiry_src=$(get_ntp_leapfile_expiry $ntp_src_leapfile)
ntp_ver_no_db=$(get_ntp_leapfile_ver $ntp_db_leapfile)
+ ntp_expiry_db=$(get_ntp_leapfile_expiry $ntp_db_leapfile)
$verbose ntp_src_leapfile version is $ntp_ver_no_src
$verbose ntp_db_leapfile version is $ntp_ver_no_db
- if [ "$ntp_ver_no_src" -gt "$ntp_ver_no_db" ]; then
+ if [ "$ntp_ver_no_src" -gt "$ntp_ver_no_db" -o \
+ "$ntp_ver_no_src" -eq "$ntp_ver_no_db" -a \
+ "$ntp_expiry_src" -gt "$ntp_expiry_db" ]; then
$verbose replacing $ntp_db_leapfile with $ntp_src_leapfile
cp -p $ntp_src_leapfile $ntp_db_leapfile
ntp_ver_no_db=$ntp_ver_no_src
else
$verbose not replacing $ntp_db_leapfile with $ntp_src_leapfile
fi
- ntp_leap_expiry=$(get_ntp_leapfile_expiry $ntp_db_leapfile)
ntp_leapfile_expiry_seconds=$((ntp_leapfile_expiry_days*86400))
+ ntp_leap_expiry=$(get_ntp_leapfile_expiry $ntp_db_leapfile)
ntp_leap_fetch_date=$((ntp_leap_expiry-ntp_leapfile_expiry_seconds))
if [ $(current_ntp_ts) -ge $ntp_leap_fetch_date ]; then
$verbose Within ntp leapfile expiry limit, initiating fetch
@@ -107,8 +125,11 @@ ntpd_fetch_leapfile() {
$verbose fetching $url
fetch $ntp_leapfile_fetch_opts -o $ntp_tmp_leapfile $url && break
done
+ ntp_ver_no_tmp=$(get_ntp_leapfile_ver $ntp_tmp_leapfile)
ntp_expiry_tmp=$(get_ntp_leapfile_expiry $ntp_tmp_leapfile)
- if [ "$ntp_expiry_tmp" -gt "$ntp_leap_expiry" ]; then
+ if [ "$ntp_ver_no_tmp" -gt "$ntp_ver_no_db" -o \
+ "$ntp_ver_no_tmp" -eq "$ntp_ver_no_db" -a \
+ "$ntp_expiry_tmp" -gt "$ntp_expiry_db" ]; then
$verbose using $url as $ntp_db_leapfile
mv $ntp_tmp_leapfile $ntp_db_leapfile
else
OpenPOWER on IntegriCloud