Skip to contentSkip to conversation

package/ntp: run ntpd as ntp user

PATCH Applied Peter Seiderer 2 participants 2 messages Nov 10, 2021 – Nov 14, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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

---
 package/ntp/{S49ntp => S49ntp.in}             |  2 +-
 package/ntp/ntp.mk                            | 15 +++++++++++++--
 package/ntp/{ntpd.service => ntpd.service.in} |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
 rename package/ntp/{S49ntp => S49ntp.in} (96%)
 rename package/ntp/{ntpd.service => ntpd.service.in} (85%)
package/ntp/S49ntp.in renamed from package/ntp/S49ntp +1 -1
similarity index 96%
rename from package/ntp/S49ntp
rename to package/ntp/S49ntp.in
index 66c5f70a5f..11c03b888f 100644
@@ -6,7 +6,7 @@
 DAEMON="ntpd"
 PIDFILE="/var/run/$DAEMON.pid"
 
-NTPD_ARGS="-g"
+NTPD_ARGS="@NTPD_EXTRA_ARGS@ -g"
 
 # shellcheck source=/dev/null
 [ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
package/ntp/ntp.mk +13 -2
index ff23cdc2b6..3ffd2b6fc5 100644
@@ -44,6 +44,10 @@ endif
 ifeq ($(BR2_PACKAGE_LIBCAP),y)
 NTP_CONF_OPTS += --enable-linuxcaps
 NTP_DEPENDENCIES += libcap
+define NTP_USERS
+        ntp -1 ntp -1 * - - - ntpd user
+endef
+NTP_DAEMON_EXTRA_ARGS = -u ntp:ntp
 else
 NTP_CONF_OPTS += --disable-linuxcaps
 endif
@@ -109,11 +113,18 @@ endif
 
 ifeq ($(BR2_PACKAGE_NTP_NTPD),y)
 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
 
 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
 endif
 
package/ntp/ntpd.service.in renamed from package/ntp/ntpd.service +1 -1
similarity index 85%
rename from package/ntp/ntpd.service
rename to package/ntp/ntpd.service.in
index 9a0f4c6dbf..b7db4a2878 100644
@@ -9,7 +9,7 @@ PIDFile=/run/ntpd.pid
 # correct time to work, but we likely won't acquire that without NTP. Let's
 # break this chicken-and-egg cycle here.
 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]
 WantedBy=multi-user.target
Signature · 6 lines
2.33.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 11 lines · On Wed, 10 Nov 2021 20:37:28 +0100 Peter Seiderer <[email protected]> wrote:

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

---
 package/ntp/{S49ntp => S49ntp.in}             |  2 +-
 package/ntp/ntp.mk                            | 15 +++++++++++++--
 package/ntp/{ntpd.service => ntpd.service.in} |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)
 rename package/ntp/{S49ntp => S49ntp.in} (96%)
 rename package/ntp/{ntpd.service => ntpd.service.in} (85%)

Applied to next, thanks.

Thomas

Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot