11.1Ssimonb#!/bin/sh 21.1Ssimonb# 31.17Sskrll# $NetBSD: ntpd,v 1.17 2020/07/04 06:24:53 skrll Exp $ 41.1Ssimonb# 51.1Ssimonb 61.1Ssimonb# PROVIDE: ntpd 71.1Ssimonb# REQUIRE: DAEMON 81.6Sthorpej# BEFORE: LOGIN 91.9Slukem# KEYWORD: chrootdir 101.1Ssimonb 111.13Smycroft$_rc_subr_loaded . /etc/rc.subr 121.1Ssimonb 131.1Ssimonbname="ntpd" 141.3Slukemrcvar=$name 151.1Ssimonbcommand="/usr/sbin/${name}" 161.12Sfredbpidfile="/var/run/${name}.pid" 171.4Slukemstart_precmd="ntpd_precmd" 181.1Ssimonbrequired_files="/etc/ntp.conf" 191.4Slukem 201.4Slukemntpd_precmd() 211.4Slukem{ 221.14Sprlw1 rc_flags="-p ${pidfile} $rc_flags" 231.4Slukem if [ -z "$ntpd_chrootdir" ]; then 241.4Slukem return 0; 251.4Slukem fi 261.4Slukem 271.4Slukem # If running in a chroot cage, ensure that the appropriate files 281.17Sskrll # exist inside the cage, as well as helper symlinks into the cage 291.4Slukem # from outside. 301.4Slukem # 311.4Slukem # As this is called after the is_running and required_dir checks 321.4Slukem # are made in run_rc_command(), we can safely assume ${ntpd_chrootdir} 331.4Slukem # exists and ntpd isn't running at this point (unless forcestart 341.4Slukem # is used). 351.7Slukem # 361.8Slukem # Before enabling ntpd_chrootdir, ensure that: 371.8Slukem # - The kernel has "pseudo-device clockctl" compiled in 381.8Slukem # - /dev/clockctl is present 391.4Slukem # 401.10Sitohy if (: </dev/clockctl) 2>/dev/null; then 411.10Sitohy : exists and works 421.10Sitohy else 431.10Sitohy logger -s -p daemon.warning -t ntpd \ 441.10Sitohy "WARNING: not chrooting -- no working /dev/clockctl device" 451.10Sitohy return 0 461.10Sitohy fi 471.4Slukem if [ ! -c "${ntpd_chrootdir}/dev/clockctl" ]; then 481.4Slukem rm -f "${ntpd_chrootdir}/dev/clockctl" 491.4Slukem ( cd /dev ; /bin/pax -rw -pe clockctl "${ntpd_chrootdir}/dev" ) 501.4Slukem fi 511.4Slukem ln -fs "${ntpd_chrootdir}/var/db/ntp.drift" /var/db/ntp.drift 521.4Slukem 531.15Sspz if [ ! -d "${ntpd_chrootdir}/etc" ]; then 541.15Sspz mkdir "${ntpd_chrootdir}/etc" 551.15Sspz fi 561.16Schristos 571.16Schristos for f in resolv.conf; do 581.16Schristos if ! cmp -s "/etc/$f" "${ntpd_chrootdir}/etc/$f"; then 591.16Schristos cp -p "/etc/$f" "${ntpd_chrootdir}/etc/$f" 601.16Schristos fi 611.16Schristos done 621.16Schristos 631.15Sspz if [ ! -f "${ntpd_chrootdir}/etc/services" ]; then 641.15Sspz getent services ntp/udp ntp/tcp \ 651.15Sspz > "${ntpd_chrootdir}/etc/services" 661.15Sspz fi 671.15Sspz if [ ! -d "${ntpd_chrootdir}/var/db" ]; then 681.15Sspz mkdir -p "${ntpd_chrootdir}/var/db" 691.15Sspz fi 701.15Sspz if [ ! -f "${ntpd_chrootdir}/var/db/services.cdb" ]; then 711.15Sspz services_mkdb -o "${ntpd_chrootdir}/var/db/services.cdb" \ 721.15Sspz "${ntpd_chrootdir}/etc/services" 731.15Sspz fi 741.15Sspz 751.4Slukem # Change run_rc_commands()'s internal copy of $ntpd_flags 761.4Slukem # 771.5Slukem rc_flags="-u ntpd:ntpd -i ${ntpd_chrootdir} $rc_flags" 781.4Slukem} 791.1Ssimonb 801.2Slukemload_rc_config $name 811.1Ssimonbrun_rc_command "$1" 82