commit bea88ec6ff12e8eb86480a34c3c2478bc9ba81c6 Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 11:10:18 2019 -0400 Package init diff --git a/bugfix-fix-autokey-condition-error.patch b/bugfix-fix-autokey-condition-error.patch new file mode 100644 index 0000000..0d76b6b --- /dev/null +++ b/bugfix-fix-autokey-condition-error.patch @@ -0,0 +1,13 @@ +diff -Nur ntp-4.2.8p12.bak/ntpd/ntp_crypto.c ntp-4.2.8p12/ntpd/ntp_crypto.c +--- ntp-4.2.8p12.bak/ntpd/ntp_crypto.c 2019-01-22 20:41:39.485000000 -0500 ++++ ntp-4.2.8p12/ntpd/ntp_crypto.c 2019-01-22 20:42:07.748000000 -0500 +@@ -3387,9 +3387,6 @@ + */ + peer->crypto |= CRYPTO_FLAG_CERT; + peer->grpkey = yp->grpkey; +- if (peer->ident == NULL || !(peer->crypto & +- CRYPTO_FLAG_MASK)) +- peer->crypto |= CRYPTO_FLAG_VRFY; + } + + /* diff --git a/bugfix-fix-bind-port-in-debug-mode.patch b/bugfix-fix-bind-port-in-debug-mode.patch new file mode 100644 index 0000000..ea81ca3 --- /dev/null +++ b/bugfix-fix-bind-port-in-debug-mode.patch @@ -0,0 +1,61 @@ +diff -Nur ntp-4.2.8p12.bak/ntpdate/ntpdate.c ntp-4.2.8p12/ntpdate/ntpdate.c +--- ntp-4.2.8p12.bak/ntpdate/ntpdate.c 2018-08-14 07:51:07.000000000 -0400 ++++ ntp-4.2.8p12/ntpdate/ntpdate.c 2019-01-22 20:20:02.484000000 -0500 +@@ -172,6 +172,7 @@ + * Counter for keeping track of completed servers + */ + int complete_servers = 0; ++int bind_port = 0; + + /* + * File of encryption keys +@@ -346,7 +347,7 @@ + /* + * Decode argument list + */ +- while ((c = ntp_getopt(argc, argv, "46a:bBde:k:o:p:qst:uv")) != EOF) ++ while ((c = ntp_getopt(argc, argv, "46a:bBdr:e:k:o:p:qst:uv")) != EOF) + switch (c) + { + case '4': +@@ -371,6 +372,9 @@ + case 'd': + ++debug; + break; ++ case 'r': ++ bind_port = atoi(ntp_optarg); ++ break; + case 'e': + if (!atolfp(ntp_optarg, &tmp) + || tmp.l_ui != 0) { +@@ -432,7 +436,7 @@ + + if (errflg) { + (void) fprintf(stderr, +- "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...\n", ++ "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] [-r port] server ...\n", + progname); + exit(2); + } +@@ -1774,6 +1778,21 @@ + exit(1); + } + } ++ else if (debug && bind_port > 0) { ++ ((struct sockaddr_in *)(res->ai_addr))->sin_port = htons(bind_port); ++ if (bind(fd[nbsock], res->ai_addr, ++ SOCKLEN((sockaddr_u *)res->ai_addr)) < 0) { ++#ifndef SYS_WINNT ++ if (errno == EADDRINUSE) ++#else ++ if (WSAGetLastError() == WSAEADDRINUSE) ++#endif /* SYS_WINNT */ ++ msyslog(LOG_ERR, "the NTP socket is in use, exiting"); ++ else ++ msyslog(LOG_ERR, "bind() fails: %m"); ++ exit(1); ++ } ++ } + + #ifdef HAVE_POLL_H + fdmask[nbsock].fd = fd[nbsock]; diff --git a/bugfix-fix-ifindex-length.patch b/bugfix-fix-ifindex-length.patch new file mode 100644 index 0000000..74322e2 --- /dev/null +++ b/bugfix-fix-ifindex-length.patch @@ -0,0 +1,11 @@ +--- ntp-4.2.6p5/lib/isc/unix/interfaceiter.c.orig 2018-10-15 15:16:00.414796346 +0800 ++++ ntp-4.2.6p5/lib/isc/unix/interfaceiter.c 2018-10-15 15:16:26.605794341 +0800 +@@ -151,7 +151,7 @@ get_addr(unsigned int family, isc_netadd + + #ifdef __linux + #define ISC_IF_INET6_SZ \ +- sizeof("00000000000000000000000000000001 01 80 10 80 XXXXXXloXXXXXXXX\n") ++ sizeof("00000000000000000000000000000001 00000001 80 10 80 XXXXXXloXXXXXXXX\n") + static isc_result_t linux_if_inet6_next(isc_interfaceiter_t *); + static isc_result_t linux_if_inet6_current(isc_interfaceiter_t *); + static void linux_if_inet6_first(isc_interfaceiter_t *iter); diff --git a/ntp-4.2.8p13.tar.gz b/ntp-4.2.8p13.tar.gz new file mode 100644 index 0000000..a8ea053 Binary files /dev/null and b/ntp-4.2.8p13.tar.gz differ diff --git a/ntp-sntp-sysexits.patch b/ntp-sntp-sysexits.patch new file mode 100644 index 0000000..31e9368 --- /dev/null +++ b/ntp-sntp-sysexits.patch @@ -0,0 +1,14 @@ +diff -up ntp-4.2.8p8/sntp/main.c.orig ntp-4.2.8p8/sntp/main.c +--- ntp-4.2.8p8/sntp/main.c.orig 2016-10-19 10:18:41.690800420 +0200 ++++ ntp-4.2.8p8/sntp/main.c 2016-10-19 10:19:31.900966925 +0200 +@@ -8,6 +8,10 @@ + # include + #endif + ++#ifdef HAVE_SYSEXITS_H ++#include ++#endif ++ + #include "main.h" + #include "ntp_libopts.h" + #include "kod_management.h" diff --git a/ntp-ssl-libs.patch b/ntp-ssl-libs.patch new file mode 100644 index 0000000..f2b12fc --- /dev/null +++ b/ntp-ssl-libs.patch @@ -0,0 +1,24 @@ +diff -up ntp-4.2.8p13/configure.ssl-libs ntp-4.2.8p13/configure +--- ntp-4.2.8p13/configure.ssl-libs 2019-02-20 18:56:00.000000000 +0100 ++++ ntp-4.2.8p13/configure 2019-05-20 10:20:54.700427323 +0200 +@@ -30257,7 +30257,7 @@ $as_echo_n "checking pkg-config for $pkg + CPPFLAGS_NTP="$CPPFLAGS_NTP `$PKG_CONFIG --cflags-only-I $pkg`" + CFLAGS_NTP="$CFLAGS_NTP `$PKG_CONFIG --cflags-only-other $pkg`" + LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-L $pkg`" +- LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l --static $pkg`" ++ LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l $pkg`" + LDFLAGS_NTP="$LDFLAGS_NTP `$PKG_CONFIG --libs-only-other $pkg`" + VER_SUFFIX=o + ntp_openssl=yes +diff -up ntp-4.2.8p13/sntp/configure.ssl-libs ntp-4.2.8p13/sntp/configure +--- ntp-4.2.8p13/sntp/configure.ssl-libs 2019-02-20 18:55:31.000000000 +0100 ++++ ntp-4.2.8p13/sntp/configure 2019-05-20 10:20:43.575400947 +0200 +@@ -25185,7 +25185,7 @@ $as_echo_n "checking pkg-config for $pkg + CPPFLAGS_NTP="$CPPFLAGS_NTP `$PKG_CONFIG --cflags-only-I $pkg`" + CFLAGS_NTP="$CFLAGS_NTP `$PKG_CONFIG --cflags-only-other $pkg`" + LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-L $pkg`" +- LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l --static $pkg`" ++ LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l $pkg`" + LDFLAGS_NTP="$LDFLAGS_NTP `$PKG_CONFIG --libs-only-other $pkg`" + VER_SUFFIX=o + ntp_openssl=yes diff --git a/ntp-wait.service b/ntp-wait.service new file mode 100644 index 0000000..8d67e13 --- /dev/null +++ b/ntp-wait.service @@ -0,0 +1,14 @@ +[Unit] +Description=Wait for ntpd to synchronize system clock +After=ntpd.service +Requires=ntpd.service +Before=time-sync.target +Wants=time-sync.target + +[Service] +Type=oneshot +ExecStart=/usr/sbin/ntp-wait +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/ntp.conf b/ntp.conf new file mode 100644 index 0000000..206a865 --- /dev/null +++ b/ntp.conf @@ -0,0 +1,48 @@ +# For more information about this file, see the ntp.conf(5) man page. + +# Record the frequency of the system clock. +driftfile VARNTP/drift + +# Permit time synchronization with our time source, but do not +# permit the source to query or modify the service on this system. +restrict default nomodify notrap nopeer noepeer noquery + +# Permit association with pool servers. +restrict source nomodify notrap noepeer noquery + +# Permit all access over the loopback interface. This could +# be tightened as well, but to do so would effect some of +# the administrative functions. +restrict 127.0.0.1 +restrict ::1 + +# Hosts on local network are less restricted. +#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap + +# Use public servers from the pool.ntp.org project. +# Please consider joining the pool (http://www.pool.ntp.org/join.html). +pool 2.VENDORZONE.pool.ntp.org iburst + +# Reduce the maximum number of servers used from the pool. +tos maxclock 5 + +# Enable public key cryptography. +#crypto + +includefile ETCNTP/crypto/pw + +# Key file containing the keys and key identifiers used when operating +# with symmetric key cryptography. +keys ETCNTP/keys + +# Specify the key identifiers which are trusted. +#trustedkey 4 8 42 + +# Specify the key identifier to use with the ntpdc utility. +#requestkey 8 + +# Specify the key identifier to use with the ntpq utility. +#controlkey 8 + +# Enable writing of statistics records. +#statistics clockstats cryptostats loopstats peerstats diff --git a/ntp.cryptopw b/ntp.cryptopw new file mode 100644 index 0000000..7e96fc2 --- /dev/null +++ b/ntp.cryptopw @@ -0,0 +1,5 @@ +# This file is included from /etc/ntp.conf. It specifies the password used to +# decrypt files containing private keys and identity parameters. The password +# is required only if the files have been encrypted. +# +#crypto pw apassword diff --git a/ntp.dhclient b/ntp.dhclient new file mode 100644 index 0000000..1cc9f43 --- /dev/null +++ b/ntp.dhclient @@ -0,0 +1,63 @@ +#!/bin/bash +# +# ntp.sh: dhclient-script plugin for NTP settings, +# place in /etc/dhcp/dhclient.d and 'chmod +x ntp.sh' to enable +# +# Copyright (C) 2008 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author(s): David Cantrell +# Miroslav Lichvar +# + +CONF=/etc/ntp.conf +SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface} + +ntp_replace_conf() { + echo "$1" | diff -q ${CONF} - > /dev/null 2>&1 + if [ $? -eq 1 ]; then + echo "$1" > ${CONF} + restorecon ${CONF} >/dev/null 2>&1 + systemctl try-restart ntpd.service > /dev/null 2>&1 || + service ntpd condrestart > /dev/null 2>&1 + fi +} + +ntp_config() { + if [ ! "${PEERNTP}" = "no" ] && [ -n "${new_ntp_servers}" ] && + [ -e ${CONF} ] && [ -d ${SAVEDIR} ]; then + local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF}) + local unique_servers=$(comm -23 \ + <(for s in ${new_ntp_servers}; do echo $s; done | sort -u) \ + <(echo "$conf" | awk '$1=="peer"||$1=="server"{print $2}' | sort -u)) + + conf=$(echo "$conf" + for s in ${unique_servers}; do + echo "server ${s} ${NTPSERVERARGS} # added by /sbin/dhclient-script" + done) + + [ -f ${SAVECONF} ] || touch ${SAVECONF} + ntp_replace_conf "$conf" + fi +} + +ntp_restore() { + if [ -e ${CONF} ] && [ -f ${SAVECONF} ]; then + local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF}) + + ntp_replace_conf "$conf" + rm -f ${SAVECONF} + fi +} diff --git a/ntp.keys b/ntp.keys new file mode 100644 index 0000000..80ab8c4 --- /dev/null +++ b/ntp.keys @@ -0,0 +1,3 @@ +# For more information about this file, see the man page ntp_auth(5). +# +# id type key diff --git a/ntp.spec b/ntp.spec new file mode 100644 index 0000000..f4de01a --- /dev/null +++ b/ntp.spec @@ -0,0 +1,218 @@ +%global _hardened_build 1 + +Name: ntp +Version: 4.2.8p13 +Release: 1 +Summary: A protocol designed to synchronize the clocks of computers over a network +License: MIT and BSD and BSD with advertising +URL: https://www.ntp.org/ +Source0: https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-%{version}.tar.gz +Source1: ntp.conf +Source2: ntp.keys +Source4: ntpd.sysconfig +Source6: ntp.step-tickers +Source7: ntpdate.wrapper +Source8: ntp.cryptopw +Source9: ntpdate.sysconfig +#source file ntp.dhclient comes from redhat +Source10: ntp.dhclient +Source12: ntpd.service +Source13: ntpdate.service +Source14: ntp-wait.service +Source15: sntp.service +Source16: sntp.sysconfig +#Patch0001 comes from fedora +Patch1: ntp-sntp-sysexits.patch +#patch0002 comes from fedora +Patch2: ntp-ssl-libs.patch + +Patch9000: bugfix-fix-bind-port-in-debug-mode.patch +Patch9001: bugfix-fix-autokey-condition-error.patch +Patch9002: bugfix-fix-ifindex-length.patch +Patch9003: revert-ntpd-fix-autokey-condition-error.patch + +BuildRequires: libcap-devel openssl-devel libedit-devel libevent-devel pps-tools-devel +BuildRequires: autogen autogen-libopts-devel systemd gcc perl-generators perl-HTML-Parser +Requires(pre): shadow-utils +%{?systemd_requires} +Recommends: ntpstat timedatex +Provides: ntpdate sntp +Obsoletes: ntpdate sntp + +%description +NTP is a protocol designed to synchronize the clocks of computers over a network, \ +NTP version 4, a significant revision of the previous NTP standard, is the current \ +development version. It is formalized by RFCs released by the IETF. + +%package perl +Summary: NTP utilities present with Perl +Requires: %{name} = %{version}-%{release} +%{?systemd_requires} +BuildArch: noarch + +%description perl +Provides Perl scripts calc_tickadj, ntp-wait and ntptrace. + +%package_help + +%global ntpdocdir %{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}} + +%if 0%{!?vendorzone:1} +%global vendorzone %(source /etc/os-release && echo ${ID}.) +%endif + +%prep +%autosetup -n %{name}-%{version} -p1 + +sed -i 's|\r||g' html/scripts/{footer.txt,style.css} +for f in COPYRIGHT; do + iconv -f iso8859-1 -t utf8 -o ${f}{_,} && touch -r ${f}{,_} && mv -f ${f}{_,} +done + +%build +sed -i 's|$CFLAGS -Wstrict-overflow|$CFLAGS|' configure sntp/configure +export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing -fno-strict-overflow" +%configure \ + --sysconfdir=%{_sysconfdir}/ntp/crypto --with-locfile=redhat \ + --without-ntpsnmpd --enable-all-clocks --enable-parse-clocks \ + --enable-ntp-signd=%{_localstatedir}/run/ntp_signd --disable-local-libopts + +sed -i 's|/var/db/ntp-kod|%{_localstatedir}/lib/sntp/kod|' sntp/sntp{-opts.c,.1*} +sed -i 's|/etc/ntp/drift|%{_localstatedir}/lib/ntp/drift|' \ + scripts/calc_tickadj/calc_tickadj{,.m*.in} +echo '#define KEYFILE "%{_sysconfdir}/ntp/keys"' >> ntpdate/ntpdate.h +echo '#define NTP_VAR "%{_localstatedir}/log/ntpstats/"' >> config.h + +%make_build + +sed -e 's|@PATH_PERL@|%{_bindir}/perl|' -e 's|@[^@]*_MS@|8|g' \ + < scripts/deprecated/html2man.in \ + > scripts/deprecated/html2man +pushd html +perl ../scripts/deprecated/html2man +sed -i 's/^[\t\ ]*$//;/./,/^$/!d' man/man*/*.[58] +popd + +%install +%make_install + +cp -r html/man/man8/{ntpdate,ntptime,tickadj}* $RPM_BUILD_ROOT%{_mandir}/man8 + +rm -rf $RPM_BUILD_ROOT%{_docdir} +install -d $RPM_BUILD_ROOT%{ntpdocdir} +cp -p COPYRIGHT ChangeLog NEWS $RPM_BUILD_ROOT%{ntpdocdir} + +find html | grep -E '\.(html|css|txt|jpg|gif)$' | grep -v '/build/\|sntp' | \ + cpio -pmd $RPM_BUILD_ROOT%{ntpdocdir} +find $RPM_BUILD_ROOT%{ntpdocdir} -type f | xargs chmod 644 +find $RPM_BUILD_ROOT%{ntpdocdir} -type d | xargs chmod 755 + +pushd $RPM_BUILD_ROOT +install -d .%{_sysconfdir}/{ntp/crypto,sysconfig,dhcp/dhclient.d} .%{_libexecdir} +install -d .%{_localstatedir}/{lib/{s,}ntp,log/ntpstats} .%{_unitdir} +touch .%{_localstatedir}/lib/{ntp/drift,sntp/kod} +sed -e 's|VENDORZONE\.|%{vendorzone}|' \ + -e 's|ETCNTP|%{_sysconfdir}/ntp|' \ + -e 's|VARNTP|%{_localstatedir}/lib/ntp|' \ + < %{SOURCE1} > .%{_sysconfdir}/ntp.conf +touch -r %{SOURCE1} .%{_sysconfdir}/ntp.conf +install -p -m600 %{SOURCE2} .%{_sysconfdir}/ntp/keys +install -p -m755 %{SOURCE7} .%{_libexecdir}/ntpdate-wrapper +install -p -m644 %{SOURCE4} .%{_sysconfdir}/sysconfig/ntpd +install -p -m644 %{SOURCE9} .%{_sysconfdir}/sysconfig/ntpdate +sed -e 's|VENDORZONE\.|%{vendorzone}|' \ + < %{SOURCE6} > .%{_sysconfdir}/ntp/step-tickers +touch -r %{SOURCE6} .%{_sysconfdir}/ntp/step-tickers +sed -e 's|VENDORZONE\.|%{vendorzone}|' \ + < %{SOURCE16} > .%{_sysconfdir}/sysconfig/sntp +touch -r %{SOURCE16} .%{_sysconfdir}/sysconfig/sntp +install -p -m600 %{SOURCE8} .%{_sysconfdir}/ntp/crypto/pw +install -p -m755 %{SOURCE10} .%{_sysconfdir}/dhcp/dhclient.d/ntp.sh +install -p -m644 %{SOURCE12} .%{_unitdir}/ntpd.service +install -p -m644 %{SOURCE13} .%{_unitdir}/ntpdate.service +install -p -m644 %{SOURCE14} .%{_unitdir}/ntp-wait.service +install -p -m644 %{SOURCE15} .%{_unitdir}/sntp.service + +mkdir .%{_prefix}/lib/systemd/ntp-units.d +echo 'ntpd.service' > .%{_prefix}/lib/systemd/ntp-units.d/60-ntpd.list + +popd + +%pre +/usr/sbin/groupadd -g 38 ntp 2> /dev/null || : +/usr/sbin/useradd -u 38 -g 38 -s /sbin/nologin -M -r -d %{_sysconfdir}/ntp ntp 2>/dev/null || : + +%post +%systemd_post ntpd.service ntpdate.service sntp.service + +%post perl +%systemd_post ntp-wait.service + +%preun +%systemd_preun ntpd.service ntpdate.service sntp.service + +%preun perl +%systemd_preun ntp-wait.service + +%postun +%systemd_postun_with_restart ntpd.service ntpdate.service sntp.service + +%postun perl +%systemd_postun ntp-wait.service + +%files +%defattr(-,root,root) +%doc COPYRIGHT ChangeLog NEWS +%dir %attr(-,ntp,ntp) %{_localstatedir}/lib/ntp +%dir %attr(-,ntp,ntp) %{_localstatedir}/log/ntpstats +%dir %{_localstatedir}/lib/sntp +%dir %{_sysconfdir}/ntp +%dir %attr(750,root,ntp) %{_sysconfdir}/ntp/crypto +%dir %{_sysconfdir}/dhcp/dhclient.d +%config(noreplace) %{_sysconfdir}/sysconfig/ntpd +%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/ntp.conf +%config(noreplace) %{_sysconfdir}/sysconfig/ntpdate +%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/ntp/step-tickers +%config(noreplace) %{_sysconfdir}/ntp/keys +%config(noreplace) %{_sysconfdir}/ntp/crypto/pw +%config(noreplace) %{_sysconfdir}/sysconfig/sntp +%{_sysconfdir}/dhcp/dhclient.d/ntp.sh +%{_sbindir}/ntp-keygen +%{_sbindir}/ntpd +%{_sbindir}/ntpdc +%{_sbindir}/ntpq +%{_sbindir}/ntptime +%{_sbindir}/tickadj +%{_sbindir}/ntpdate +%{_sbindir}/sntp +%ghost %attr(644,ntp,ntp) %{_localstatedir}/lib/ntp/drift +%ghost %{_localstatedir}/lib/sntp/kod + +%{_unitdir}/*.service +%{_prefix}/lib/systemd/ntp-units.d/*.list +%{_libexecdir}/ntpdate-wrapper + +%files perl +%defattr(-,root,root) +%{_sbindir}/calc_tickadj +%{_sbindir}/ntp-wait +%{_sbindir}/ntptrace +%{_unitdir}/ntp-wait.service +%{_datadir}/ntp + +%files help +%defattr(-,root,root) +%dir %{ntpdocdir} +%{ntpdocdir}/html +%{_mandir}/man5/*.5* +%{_mandir}/man8/*.8* + +%changelog +* Mon Sep 16 2019 openEuler Buildteam - 1.12.0-1 +- Type:enhancement +- Id:NA +- SUG:NA +- DESC:Fix building without zlib-devel + +* Tue Sep 3 2019 liyongqiang - 4.2.8p12-2 +- Package init diff --git a/ntp.step-tickers b/ntp.step-tickers new file mode 100644 index 0000000..8b4b1fd --- /dev/null +++ b/ntp.step-tickers @@ -0,0 +1,3 @@ +# List of NTP servers used by the ntpdate service. + +0.VENDORZONE.pool.ntp.org diff --git a/ntpd.service b/ntpd.service new file mode 100644 index 0000000..a638dad --- /dev/null +++ b/ntpd.service @@ -0,0 +1,13 @@ +[Unit] +Description=Network Time Service +After=syslog.target ntpdate.service sntp.service +Conflicts=systemd-timesyncd.service + +[Service] +Type=forking +EnvironmentFile=-/etc/sysconfig/ntpd +ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/ntpd.sysconfig b/ntpd.sysconfig new file mode 100644 index 0000000..49394c7 --- /dev/null +++ b/ntpd.sysconfig @@ -0,0 +1,2 @@ +# Command line options for ntpd +OPTIONS="-g" diff --git a/ntpdate.service b/ntpdate.service new file mode 100644 index 0000000..8e6e616 --- /dev/null +++ b/ntpdate.service @@ -0,0 +1,13 @@ +[Unit] +Description=Set time via NTP +After=network-online.target nss-lookup.target +Before=time-sync.target +Wants=time-sync.target network-online.target + +[Service] +Type=oneshot +ExecStart=/usr/libexec/ntpdate-wrapper +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/ntpdate.sysconfig b/ntpdate.sysconfig new file mode 100644 index 0000000..54676b4 --- /dev/null +++ b/ntpdate.sysconfig @@ -0,0 +1,5 @@ +# Options for ntpdate +OPTIONS="-p 2" + +# Set to 'yes' to sync hw clock after successful ntpdate +SYNC_HWCLOCK=no diff --git a/ntpdate.wrapper b/ntpdate.wrapper new file mode 100644 index 0000000..42ddda2 --- /dev/null +++ b/ntpdate.wrapper @@ -0,0 +1,29 @@ +#!/bin/bash + +ntpconf=/etc/ntp.conf +ntpstep=/etc/ntp/step-tickers + +[ "$EUID" != "0" ] && exit 4 +[ -x /usr/sbin/ntpdate ] || exit 5 +[ -f /etc/sysconfig/ntpdate ] || exit 6 +. /etc/sysconfig/ntpdate + +[ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers= + +if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then + # the step-tickers file doesn't specify a server, + # use servers from ntp.conf instead + tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \ + grep -Ev '127\.127\.[0-9]+\.[0-9]+') +fi + +if ! echo "$tickers" | grep -qi '[a-z0-9]'; then + echo "NTP server not specified in $ntpstep or $ntpconf" + exit 6 +fi + +/usr/sbin/ntpdate -s -b $OPTIONS $tickers &> /dev/null +RETVAL=$? + +[ $RETVAL -eq 0 ] && [ "$SYNC_HWCLOCK" = "yes" ] && /sbin/hwclock --systohc +exit $RETVAL diff --git a/revert-ntpd-fix-autokey-condition-error.patch b/revert-ntpd-fix-autokey-condition-error.patch new file mode 100644 index 0000000..9d6094f --- /dev/null +++ b/revert-ntpd-fix-autokey-condition-error.patch @@ -0,0 +1,27 @@ +From 302cec597f3ab4e522dacc3563953d10c0f7e656 Mon Sep 17 00:00:00 2001 +From: zhangyao +Date: Thu, 25 Jul 2019 16:42:51 +0000 +Subject: [PATCH] revert-ntpd-fix-autokey-condition-error + + +--- + ntpd/ntp_crypto.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c +index 53f3253..62ea72c 100644 +--- a/ntpd/ntp_crypto.c ++++ b/ntpd/ntp_crypto.c +@@ -3387,6 +3387,9 @@ cert_hike( + */ + peer->crypto |= CRYPTO_FLAG_CERT; + peer->grpkey = yp->grpkey; ++ if (peer->ident == NULL || !(peer->crypto & ++ CRYPTO_FLAG_MASK)) ++ peer->crypto |= CRYPTO_FLAG_VRFY; + } + + /* +-- +1.8.3.1 + diff --git a/sntp.service b/sntp.service new file mode 100644 index 0000000..caba3a0 --- /dev/null +++ b/sntp.service @@ -0,0 +1,14 @@ +[Unit] +Description=Set time via SNTP +After=network-online.target +Before=time-sync.target +Wants=time-sync.target network-online.target + +[Service] +Type=oneshot +EnvironmentFile=/etc/sysconfig/sntp +ExecStart=/usr/sbin/sntp $OPTIONS +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/sntp.sysconfig b/sntp.sysconfig new file mode 100644 index 0000000..1bf1c01 --- /dev/null +++ b/sntp.sysconfig @@ -0,0 +1,2 @@ +# Options for sntp +OPTIONS="-s 0.VENDORZONE.pool.ntp.org"