package/ntp: run ntpd as ntp user

- in case libcap is enabled use the now enabled '-u' option to run nptd as
  user/group ntp

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Peter Seiderer 2021-11-10 20:37:28 +01:00 committed by Thomas Petazzoni
parent f84350e725
commit 0f0b1f59c3
3 changed files with 15 additions and 4 deletions

View File

@ -6,7 +6,7 @@
DAEMON="ntpd" DAEMON="ntpd"
PIDFILE="/var/run/$DAEMON.pid" PIDFILE="/var/run/$DAEMON.pid"
NTPD_ARGS="-g" NTPD_ARGS="@NTPD_EXTRA_ARGS@ -g"
# shellcheck source=/dev/null # shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" [ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"

View File

@ -44,6 +44,10 @@ endif
ifeq ($(BR2_PACKAGE_LIBCAP),y) ifeq ($(BR2_PACKAGE_LIBCAP),y)
NTP_CONF_OPTS += --enable-linuxcaps NTP_CONF_OPTS += --enable-linuxcaps
NTP_DEPENDENCIES += libcap NTP_DEPENDENCIES += libcap
define NTP_USERS
ntp -1 ntp -1 * - - - ntpd user
endef
NTP_DAEMON_EXTRA_ARGS = -u ntp:ntp
else else
NTP_CONF_OPTS += --disable-linuxcaps NTP_CONF_OPTS += --disable-linuxcaps
endif endif
@ -109,11 +113,18 @@ endif
ifeq ($(BR2_PACKAGE_NTP_NTPD),y) ifeq ($(BR2_PACKAGE_NTP_NTPD),y)
define NTP_INSTALL_INIT_SYSV_NTPD define NTP_INSTALL_INIT_SYSV_NTPD
$(INSTALL) -D -m 755 package/ntp/S49ntp $(TARGET_DIR)/etc/init.d/S49ntp mkdir -p $(TARGET_DIR)/etc/init.d
sed -e 's%@NTPD_EXTRA_ARGS@%$(NTP_DAEMON_EXTRA_ARGS)%g' \
package/ntp/S49ntp.in \
> $(TARGET_DIR)/etc/init.d/S49ntp
chmod 0755 $(TARGET_DIR)/etc/init.d/S49ntp
endef endef
define NTP_INSTALL_INIT_SYSTEMD define NTP_INSTALL_INIT_SYSTEMD
$(INSTALL) -D -m 644 package/ntp/ntpd.service $(TARGET_DIR)/usr/lib/systemd/system/ntpd.service mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
sed -e 's%@NTPD_EXTRA_ARGS@%$(NTP_DAEMON_EXTRA_ARGS)%g' \
package/ntp/ntpd.service.in \
> $(TARGET_DIR)/usr/lib/systemd/system/ntpd.service
endef endef
endif endif

View File

@ -9,7 +9,7 @@ PIDFile=/run/ntpd.pid
# correct time to work, but we likely won't acquire that without NTP. Let's # correct time to work, but we likely won't acquire that without NTP. Let's
# break this chicken-and-egg cycle here. # break this chicken-and-egg cycle here.
Environment=SYSTEMD_NSS_RESOLVE_VALIDATE=0 Environment=SYSTEMD_NSS_RESOLVE_VALIDATE=0
ExecStart=/usr/sbin/ntpd -g -p /run/ntpd.pid ExecStart=/usr/sbin/ntpd @NTPD_EXTRA_ARGS@ -g -p /run/ntpd.pid
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target