pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkg/47149 (net/ntp4 fails to ntp.conf)



The following reply was made to PR pkg/47149; it has been noted by GNATS.

From: Showta Ishizaki <zakinko%snowrabbit.org@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: pkg/47149 (net/ntp4 fails to ntp.conf)
Date: Wed, 19 Aug 2026 09:06:03 +0900 (JST)

 Fourteen years on, this is still present in pkgsrc HEAD: net/ntp4
 (ntp-4.2.8p15) compiles CONFIG_FILE as "/etc/ntp.conf" while the
 package's rc.d script requires ${PKG_SYSCONFDIR}/ntp.conf.  The
 --sysconfdir configure argument does not move it; the only thing
 configure.ac derives from sysconfdir is NTP_KEYSDIR.
 
 It bites non-NetBSD users too: on Linux, /etc/ntp.conf belongs to the
 host distribution, and pkgsrc's ntpd silently reads the distribution's
 file.  Independently reported on pkgsrc-users in 2020:
 
   https://mail-index.netbsd.org/pkgsrc-users/2020/10/08/msg032396.html
 
 This is not the patch I sent in 2012.  That one rewrote six files,
 including AutoGen-generated documentation, and would not have survived
 the 4.2.8 update.  This one adds no source patch to ntpd at all.
 
 The compiled-in paths are all #ifndef-guarded, so CPPFLAGS is enough:
 
   CPPFLAGS+= -DCONFIG_FILE=\"${PKG_SYSCONFDIR}/ntp.conf\"
   CPPFLAGS+= -DKEYFILE=\"${PKG_SYSCONFDIR}/ntp.keys\"
 
 This is not novel: OpenBSD's ports tree has done exactly this for
 years, in net/ntp/Makefile:
 
   CONFIGURE_ENV= CPPFLAGS='-DCONFIG_FILE="\"${SYSCONFDIR}/ntp.conf\"" \
                            -DKEYFILE="\"${SYSCONFDIR}/ntp.keys\""'
 
 sntp is the one exception.  It keeps its keys-file default as a byte
 offset into a single concatenated string table, so substituting a
 longer path in place would shift every following offset.  The one
 patch in this diff only wraps that macro in #ifndef, leaving the table
 untouched, so the value can come from CPPFLAGS like the others.
 
 The manual pages are handled with SUBST rather than patches.  A patch
 would have to hardcode one prefix, and pkgsrc is built with many --
 /usr/pkg, /opt/local, /opt/pkg, and whatever a bootstrap chose.  Note
 that the installed pages come from the *.man.in files via config.status,
 not from the AutoGen *.1ntpdman intermediates; the rule that regenerates
 the former from the latter does not run in an ordinary build.  Doing it
 this way also fixes ntp.conf(5), ntp.keys(5) and sntp(1), which were
 left saying /etc before.
 
 A default configuration is installed with CONF_FILES when no file
 exists, the standard pkgsrc arrangement.  It is modelled on the base
 system's /etc/ntp.conf, with the generic pool zone rather than
 2.netbsd.pool.ntp.org, since this package is built on many operating
 systems.  Its pid and drift file paths follow VARBASE.
 
 The reservations recorded in PR pkg/28583 in 2005 are addressed:
 
   - With PKG_SYSCONFBASE=/etc the two paths coincide, so nothing
     changes for users who set that.
 
   - The dhclient concern is moot.  NetBSD's dhclient-script never wrote
     /etc/ntp.conf -- the 2005 comment described a Linux distribution --
     and dhclient was removed from base in 2018.  The file is now written
     by dhcpcd's 50-ntp.conf hook, which already searches ${PREFIX}/etc
     and can be pointed anywhere with "env NTP_CONF=..." in
     dhcpcd.conf(5).
 
   - Users who keep their configuration in /etc/ntp.conf are not left
     silently unconfigured: MESSAGE tells them to move it, or to replace
     the installed file with the single line "includefile /etc/ntp.conf".
     pkginstall never overwrites a modified file.
 
 I tried making ntpd fall back to /etc/ntp.conf when
 ${PKG_SYSCONFDIR}/ntp.conf is absent, and dropped it.  With CONF_FILES
 installing a default, the fallback can only fire if the admin deletes
 that file, and in the meantime an upgrade would quietly switch a
 working /etc/ntp.conf for the pkgsrc default -- which is the failure
 mode fredb warned about in 2005, reintroduced by the mechanism meant to
 prevent it.  An explicit migration note is better than a clever
 fallback.
 
 Tested on NetBSD 9.4/i386, built and installed from pkgsrc.
 CONF_FILES left a pre-existing, 14-year-old ${PKG_SYSCONFDIR}/ntp.conf
 from an earlier net/ntp4 install untouched, and the rc.d install
 likewise declined to overwrite the base system's /etc/rc.d/ntpd,
 installing the pkgsrc version as an example instead.  The installed
 ntpd reads ${PKG_SYSCONFDIR}/ntp.conf; sntp -a reports the relocated
 keys file; ntpd.8, ntp.conf.5, ntp.keys.5 and sntp.1 all name the
 package's paths.
 
 I have also asked upstream to make this unnecessary.  ntp.org bug 382,
 "ntpd does not honor sysconfdir argument to configure script", has been
 open since 2005; I attached a patch there on 18 August 2026 that
 derives the path from sysconfdir the way NTP_KEYSDIR already is, but
 only behind --enable-sysconfdir-paths so the default build is
 unchanged.  If that is ever taken, this package can drop the CPPFLAGS
 lines and pass the flag instead.  I would not hold the pkgsrc fix for
 it: the bug was deferred from 4.2.8 to 4.4 in November 2023, and
 upstream has not made a release since May 2024.
 
   https://bugs.ntp.org/show_bug.cgi?id=382
 
 Index: net/ntp4/MESSAGE
 --- net/ntp4/MESSAGE.orig	1970-01-01 09:00:00
 +++ net/ntp4/MESSAGE	2026-08-18 23:24:54
 @@ -0,0 +1,25 @@
 +===========================================================================
 +$NetBSD$
 +
 +The NTP daemon and utilities in this package read their configuration
 +from
 +
 +	${PKG_SYSCONFDIR}/ntp.conf
 +
 +A default configuration, modelled on the NetBSD base system's, has been
 +installed there unless a file already existed.  Earlier versions of this
 +package ignored that path and read /etc/ntp.conf instead, so if you have
 +been keeping the configuration for this package in /etc/ntp.conf, either
 +move it here or replace the contents of ${PKG_SYSCONFDIR}/ntp.conf with
 +the single line
 +
 +	includefile /etc/ntp.conf
 +
 +A modified file is preserved across package upgrades.
 +
 +If you use dhcpcd's 50-ntp.conf hook, it updates the first ntp.conf it
 +finds under /etc, ${PREFIX}/etc and /usr/local/etc.  To make it manage
 +${PKG_SYSCONFDIR}/ntp.conf, add the following line to /etc/dhcpcd.conf:
 +
 +	env NTP_CONF=${PKG_SYSCONFDIR}/ntp.conf
 +===========================================================================
 Index: net/ntp4/Makefile
 --- net/ntp4/Makefile.orig	2025-10-18 09:42:04
 +++ net/ntp4/Makefile	2026-08-18 23:25:05
 @@ -2,7 +2,7 @@
  #
  
  DISTNAME=	ntp-4.2.8p15
 -PKGREVISION=	4
 +PKGREVISION=	5
  CATEGORIES=	net time
  MASTER_SITES=	https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/
  
 @@ -20,6 +20,43 @@
  CONFIGURE_ARGS+=	--with-locfile=loc/pkgsrc
  CONFIGURE_ENV+=		PATH_PERL=${PERL5}
  
 +# The paths to the configuration and keys files are hardcoded #defines
 +# that ignore --sysconfdir (PR pkg/47149), so the rc.d script required
 +# ${PKG_SYSCONFDIR}/ntp.conf while the daemon read /etc/ntp.conf.  They
 +# are all #ifndef-guarded, so setting them here is enough; sntp keeps
 +# its default in a generated string table rather than a plain #define,
 +# and the patch adds the guard so it can be set from here too.
 +CPPFLAGS+=	-DCONFIG_FILE=\"${PKG_SYSCONFDIR}/ntp.conf\"
 +CPPFLAGS+=	-DKEYFILE=\"${PKG_SYSCONFDIR}/ntp.keys\"
 +CPPFLAGS+=	-DKEYFILE_DFT_ARG=\"${PKG_SYSCONFDIR}/ntp.keys\"
 +
 +# The manual pages name the compiled-in paths, so they have to follow
 +# PKG_SYSCONFDIR as well.  They are generated by AutoGen, which is not a
 +# build dependency here, so substitute rather than patch: a patch would
 +# have to hardcode one prefix, and pkgsrc is built with many.
 +# The .man.in files are what configure turns into the installed pages;
 +# the mdoc and texi forms feed the html documentation.
 +SUBST_CLASSES+=		ntpconf
 +SUBST_STAGE.ntpconf=	pre-configure
 +SUBST_MESSAGE.ntpconf=	Setting the configuration file paths in the documentation.
 +SUBST_FILES.ntpconf=	ntpd/ntpd.man.in ntpd/ntpd.mdoc.in
 +SUBST_FILES.ntpconf+=	ntpd/ntp.conf.man.in ntpd/ntp.conf.mdoc.in
 +SUBST_FILES.ntpconf+=	ntpd/ntp.keys.man.in ntpd/ntp.keys.mdoc.in
 +SUBST_FILES.ntpconf+=	sntp/sntp.man.in sntp/sntp.mdoc.in
 +SUBST_SED.ntpconf=	-e 's,/etc/ntp\.conf,${PKG_SYSCONFDIR}/ntp.conf,g'
 +SUBST_SED.ntpconf+=	-e 's,/etc/ntp\.keys,${PKG_SYSCONFDIR}/ntp.keys,g'
 +
 +# The default configuration installed below names the pid and drift
 +# files, which live under VARBASE rather than a fixed /var.
 +SUBST_CLASSES+=		ntpvar
 +SUBST_STAGE.ntpvar=	pre-configure
 +SUBST_MESSAGE.ntpvar=	Setting the state file paths in the default configuration.
 +SUBST_FILES.ntpvar=	pkgsrc-ntp.conf
 +SUBST_SED.ntpvar=	-e 's,/var/run/,${VARBASE}/run/,g'
 +SUBST_SED.ntpvar+=	-e 's,/var/db/,${VARBASE}/db/,g'
 +
 +BUILD_DEFS+=		VARBASE
 +
  OVERRIDE_DIRDEPTH=	4
  
  DOCS+=		COPYRIGHT ChangeLog NEWS README* TODO
 @@ -31,9 +68,18 @@
  
  RCD_SCRIPTS=	ntpd ntpdate
  
 +# Install a default configuration, modelled on the NetBSD base
 +# system's /etc/ntp.conf, unless the admin already has one there.
 +CONF_FILES=	${PREFIX}/${EXAMPLESDIR}/ntp.conf ${PKG_SYSCONFDIR}/ntp.conf
 +
 +post-extract:
 +	${CP} ${FILESDIR}/ntp.conf ${WRKSRC}/pkgsrc-ntp.conf
 +
  post-install:
  	cd ${WRKSRC} && ${INSTALL_DATA} ${DOCS} ${DESTDIR}${PREFIX}/${DOCDIR}
  	cd ${WRKSRC}/conf && pax -rw -pm . ${DESTDIR}${PREFIX}/${EXAMPLESDIR}
 +	${INSTALL_DATA} ${WRKSRC}/pkgsrc-ntp.conf \
 +		${DESTDIR}${PREFIX}/${EXAMPLESDIR}/ntp.conf
  	${CHOWN} -R ${SHAREOWN}:${SHAREGRP} ${ALL_NTP_DOCS}
  	${FIND} ${ALL_NTP_DOCS} -type d -print | ${XARGS} ${CHMOD} ${PKGDIRMODE}
  	${FIND} ${ALL_NTP_DOCS} -type f -print | ${XARGS} ${CHMOD} ${SHAREMODE}
 Index: net/ntp4/PLIST
 --- net/ntp4/PLIST.orig	2021-02-15 22:11:25
 +++ net/ntp4/PLIST	2026-08-18 23:24:54
 @@ -284,6 +284,7 @@
  share/examples/ntp4/beauregard.conf
  share/examples/ntp4/grundoon.conf
  share/examples/ntp4/malarky.conf
 +share/examples/ntp4/ntp.conf
  share/examples/ntp4/pogo.conf
  share/examples/ntp4/rackety.conf
  share/ntp/lib/NTP/Util.pm
 Index: net/ntp4/distinfo
 --- net/ntp4/distinfo.orig	2021-10-26 23:31:38
 +++ net/ntp4/distinfo	2026-08-18 23:25:05
 @@ -37,5 +37,6 @@
  SHA1 (patch-sntp_libopts_enum.c) = 7d6624ed84a6ea6f85b4de4c37480041a7603252
  SHA1 (patch-sntp_libopts_usage.c) = ec77942c98965c13de625b930db3458d5b81d28b
  SHA1 (patch-sntp_loc_pkgsrc) = 6e46ffc0cc2afcfdc1d01297cbe04cb80d103575
 +SHA1 (patch-sntp_sntp-opts.c) = 72c29cbf14380848ed5178e03037a8ff6b15b50d
  SHA1 (patch-util_ntp-keygen.c) = e66348e2fcf7da4bf9ee35e66e3f891cb436f338
  SHA1 (patch-util_ntptime.c) = 897c3986661a9e655eeb7a7eeb10816996c31301
 Index: net/ntp4/files/ntp.conf
 --- net/ntp4/files/ntp.conf.orig	2021-02-15 22:11:25
 +++ net/ntp4/files/ntp.conf	2026-08-18 23:24:51
 @@ -1,42 +1,36 @@
  # $NetBSD: ntp.conf,v 1.1 2004/03/11 20:39:40 reed Exp $
  #
 -# NetBSD default Network Time Protocol (NTP) configuration file
 -# for ntpd
 +# Default Network Time Protocol (NTP) configuration file for the
 +# pkgsrc ntpd, modelled on the NetBSD base system's /etc/ntp.conf.
 +#
 +# If you prefer to keep your configuration in /etc/ntp.conf, replace
 +# the contents of this file with the single line
 +#
 +#	includefile /etc/ntp.conf
 +#
 +# A modified file is preserved across package upgrades.
  
 -# Process ID file, so that the daemon can be signalled from scripts
 -
  pidfile		/var/run/ntpd.pid
 -
 -# The correction calculated by ntpd(8) for the local system clock's
 -# drift is stored here
 -
  driftfile	/var/db/ntp.drift
  
  # suppress the syslog(3) message for each peer synchronization change
 -
  logconfig	-syncstatus
  
 -# Hereafter should be "server" or "peer" statements to configure
 -# other hosts to exchange NTP packets with. Peers should be selected
 -# in such a way that the network path to them is symmetric (that is,
 -# the series of links and routers used to get to the peer is the same
 -# one that the peer uses to get back. NTP assumes such symmetry
 -# in its network delay calculation. NTP will apply an incorrect
 -# adjustment to timestamps received from the peer if the path is not
 -# symmetric. This can result in clock skew (your system clock being
 -# maintained consistently wrong by a certain amount).
 -# 
 -# The best way to select symmetric peers is to make sure that the
 -# network path to them is as short as possible (this reduces the
 -# chance that there is more than one network path between you and
 -# your peer). You can measure these distances with the traceroute(8)
 -# program. The best place to start looking for NTP peers for your
 -# system is within your own network, or at your Internet Service
 -# Provider (ISP).
 -#
 -# Ideally, you should select at least three other systems to talk
 -# NTP with, for an "what I tell you three times is true" effect.
 -#
 +tos minsane 2
 +tos minclock 3 maxclock 6
  
 -#peer		an.ntp.peer.goes.here
 -#server		an.ntp.server.goes.here
 +# Serve time only; do not allow modification or queries.
 +restrict default limited kod nomodify notrap nopeer noquery
 +restrict source nomodify notrap noquery
 +restrict 127.0.0.1
 +restrict ::1
 +
 +# The pool.ntp.org project coordinates public time servers provided by
 +# volunteers.  See <http://www.pool.ntp.org>.  A single pool statement
 +# adds several servers, according to the tos targets above.
 +#
 +# The vendor zones (*.netbsd.pool.ntp.org and friends) are allocated to
 +# a particular operating system, and this package is built on many, so
 +# the generic zone is used here.  If your system has a vendor zone of
 +# its own, prefer it.
 +pool 2.pool.ntp.org iburst
 Index: net/ntp4/patches/patch-sntp_sntp-opts.c
 --- net/ntp4/patches/patch-sntp_sntp-opts.c.orig	1970-01-01 09:00:00
 +++ net/ntp4/patches/patch-sntp_sntp-opts.c	2026-08-18 23:24:54
 @@ -0,0 +1,28 @@
 +$NetBSD$
 +
 +* Changes from NetBSD base.
 +* Let the compiled-in default keys file be overridden from CPPFLAGS so
 +  it can follow PKG_SYSCONFDIR (PR pkg/47149).  This is a pre-generated
 +  file (from sntp/sntp-opts.def via AutoGen); patch it directly rather
 +  than the .def source, which would make the .def newer than the shipped
 +  generated files and trigger AutoGen regeneration at build time --
 +  AutoGen is not a build dependency of this package.
 +
 +  The default is a byte offset into a single concatenated string table,
 +  so substituting a longer path in place would shift every following
 +  offset.  Guarding the macro instead leaves the table untouched and
 +  keeps the substitution a build-time matter, which also keeps it
 +  correct for any PKG_SYSCONFDIR rather than one hardcoded prefix.
 +
 +--- sntp/sntp-opts.c.orig	2020-06-23 16:03:47.000000000 +0000
 ++++ sntp/sntp-opts.c
 +@@ -302,7 +302,9 @@
 + /** Name string for the keyfile option */
 + #define KEYFILE_name      (sntp_opt_strs+1593)
 + /** The compiled in default value for the keyfile option argument */
 ++#ifndef KEYFILE_DFT_ARG
 + #define KEYFILE_DFT_ARG   (sntp_opt_strs+1601)
 ++#endif
 + /** Compiled in flag settings for the keyfile option */
 + #define KEYFILE_FLAGS     (OPTST_DISABLED \
 +         | OPTST_SET_ARGTYPE(OPARG_TYPE_FILE))
 



Home | Main Index | Thread Index | Old Index