git: 6a5113a8a1df - releng/14.0 - MFS jail: avoid a clash with /etc/jail.conf.d between rc and jail(8)

From: Jamie Gritton <jamie_at_FreeBSD.org>
Date: Mon, 02 Oct 2023 19:23:41 UTC
The branch releng/14.0 has been updated by jamie:

URL: https://cgit.FreeBSD.org/src/commit/?id=6a5113a8a1df5f93541d2e9af48fd2127bae0793

commit 6a5113a8a1df5f93541d2e9af48fd2127bae0793
Author:     Jamie Gritton <jamie@FreeBSD.org>
AuthorDate: 2023-09-25 00:03:09 +0000
Commit:     Jamie Gritton <jamie@FreeBSD.org>
CommitDate: 2023-10-02 19:22:52 +0000

    MFS jail: avoid a clash with /etc/jail.conf.d between rc and jail(8)
    
    Since 13.1, /etc/rc.d/jail has looked for a per-jail config file in
    /etc/jail.conf.d. For RELENG 14, the ".include" directive was added to
    jail(8), with a sample line in the jail.conf(5) man page that includes
    "/etc/jail.conf.d/*.conf".
    
    These two use cases don't work together. When the jail.conf.d files
    are included from a master jail.conf, the files in jail.conf.d are
    likely to hold only partial configurations, and shouldn't be directly
    loaded by rc.d/jail. But there are existing configurations that depend
    on the current rc.d behavior. While users could be advised not to
    include from /etc/jail.conf.d, it's the natural choice even if not
    mentioned in jail.conf.5.
    
    The workaround is for rc.d/jail to continue to load the individual
    files, but only when /etc/jail.conf doesn't include from that
    directory (via a simple grep test), This allows the current use
    while not breaking the previous use.
    
    Approved by:    re (gjb)
    Reported by:    antranigv at freebsd.am
    Differential Revision:  https://reviews.freebsd.org/D41962
    
    (cherry picked from commit a2440348eed75bb7682579af0905b652747fd016)
    (cherry picked from commit c96d5c97bb65a1b0bc135b452f13d0ca6a8d60c9)
---
 libexec/rc/rc.d/jail | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libexec/rc/rc.d/jail b/libexec/rc/rc.d/jail
index f8995c7e3b00..f12dae280bb0 100755
--- a/libexec/rc/rc.d/jail
+++ b/libexec/rc/rc.d/jail
@@ -126,7 +126,9 @@ parse_options()
 		if [ -r "$_jconf" ]; then
 			_conf="$_jconf"
 			return 0
-		elif [ -r "$_jconfdir" ]; then
+		elif [ -r "$_jconfdir" ] && ! egrep -q \
+		    '^\s*\.include\s*["'\'']?/etc/jail.conf.d/' "$jail_conf" \
+		    2>/dev/null; then
 			_conf="$_jconfdir"
 			return 0
 		elif [ -r "$jail_conf" ]; then