From owner-svn-ports-head@freebsd.org Sat Feb 8 16:04:14 2020 Return-Path: Delivered-To: svn-ports-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6616E245B58; Sat, 8 Feb 2020 16:04:14 +0000 (UTC) (envelope-from feld@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48FH6Q20yQz401Y; Sat, 8 Feb 2020 16:04:14 +0000 (UTC) (envelope-from feld@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 402811FDE9; Sat, 8 Feb 2020 16:04:14 +0000 (UTC) (envelope-from feld@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 018G4EES062768; Sat, 8 Feb 2020 16:04:14 GMT (envelope-from feld@FreeBSD.org) Received: (from feld@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 018G4DmF062767; Sat, 8 Feb 2020 16:04:13 GMT (envelope-from feld@FreeBSD.org) Message-Id: <202002081604.018G4DmF062767@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: feld set sender to feld@FreeBSD.org using -f From: Mark Felder Date: Sat, 8 Feb 2020 16:04:13 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r525559 - in head/net/ntimed: . files X-SVN-Group: ports-head X-SVN-Commit-Author: feld X-SVN-Commit-Paths: in head/net/ntimed: . files X-SVN-Commit-Revision: 525559 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Feb 2020 16:04:14 -0000 Author: feld Date: Sat Feb 8 16:04:13 2020 New Revision: 525559 URL: https://svnweb.freebsd.org/changeset/ports/525559 Log: net/ntimed: Supervise process and attempt to drop privs PR: 243469 Modified: head/net/ntimed/Makefile head/net/ntimed/files/ntimed.in Modified: head/net/ntimed/Makefile ============================================================================== --- head/net/ntimed/Makefile Sat Feb 8 15:03:50 2020 (r525558) +++ head/net/ntimed/Makefile Sat Feb 8 16:04:13 2020 (r525559) @@ -3,7 +3,7 @@ PORTNAME= ntimed PORTVERSION= 0.0.2015.01.30 -PORTREVISION= 0 +PORTREVISION= 1 CATEGORIES= net MAINTAINER= feld@FreeBSD.org Modified: head/net/ntimed/files/ntimed.in ============================================================================== --- head/net/ntimed/files/ntimed.in Sat Feb 8 15:03:50 2020 (r525558) +++ head/net/ntimed/files/ntimed.in Sat Feb 8 16:04:13 2020 (r525559) @@ -25,14 +25,32 @@ load_rc_config $name start_precmd=ntimed_prestart pidfile=/var/run/ntimed.pid -procname="/usr/local/sbin/ntimed-client" +ntimed_cmd="/usr/local/sbin/ntimed-client" command=/usr/sbin/daemon -command_args=" -p ${pidfile} ${procname} ${ntimed_flags}" +can_run_nonroot() +{ + # Try to set up the the MAC ntpd policy so ntimed can run with reduced + # privileges. Detect whether MAC is compiled into the kernel, load + # the policy module if not already present, then check whether the + # policy has been disabled via tunable or sysctl. + [ -n "$(sysctl -qn security.mac.version)" ] || return 1 + sysctl -qn security.mac.ntpd >/dev/null || kldload -qn mac_ntpd || return 1 + [ "$(sysctl -qn security.mac.ntpd.enabled)" == "1" ] || return 1 +} + ntimed_prestart() { - # Have to empty rc_flags so they don't get passed to daemon(8) - rc_flags="" + # Have to empty rc_flags so they don't get passed to daemon(8) + rc_flags="" + + if can_run_nonroot; then + _ntimed_user="ntpd" + else + _ntimed_user="root" + fi + + command_args=" -r -P ${pidfile} -u ${_ntimed_user} ${ntimed_cmd} ${ntimed_flags}" } run_rc_command "$1"