git: 9ae40a268c8b - main - sysrc: Add more sanity checks
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 25 Nov 2026 21:51:26 UTC
The branch main has been updated by dteske:
URL: https://cgit.FreeBSD.org/src/commit/?id=9ae40a268c8bbbdc527dfe46282d9f8ebca36e26
commit 9ae40a268c8bbbdc527dfe46282d9f8ebca36e26
Author: Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-11-25 21:45:47 +0000
Commit: Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-11-25 21:47:37 +0000
sysrc: Add more sanity checks
Potentially a breaking change for some folks. MFC discouraged.
This aligns sysrc with the same sanity checks performed by sysconf.
It reduces the chance of POLA violations when people use `sysconf rc'
(where sysrc is hooked into sysconf as the rc target provider).
However, some shell scripts calling out to sysrc may have relied on
some of the leniency that is now cause for exit. For example, using
`-x' with assignments (such as `sysrc -x foo=bar' which now generates
the error `-x does not take a value' -- the same error produced when
you try `sysconf loader -x foo=bar').
Reviewed by: kfv
Differential Revision: https://reviews.freebsd.org/D61735
---
usr.sbin/sysrc/sysrc | 48 ++++++++++++++++++++++++++++++++++--------------
usr.sbin/sysrc/sysrc.8 | 2 +-
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index b1814948330d..617aff16d9ed 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -16,7 +16,7 @@ pgm="${0##*/}" # Program basename
#
# Version information
#
-SYSRC_VERSION="8.6 Nov-18,2026"
+SYSRC_VERSION="8.7 Nov-18,2026"
#
# Options
@@ -123,9 +123,7 @@ help()
f_err "$optfmt" "-i" \
"Ignore unknown variables."
f_err "$optfmt" "-j jail" \
- "The jid or name of the jail to operate within (overrides"
- f_err "$optfmt" "" \
- "\`-R dir'; requires jexec(8))."
+ "The jid or name of the jail to operate within."
f_err "$optfmt" "-L" \
"List all configuration files including rc.conf.d entries."
f_err "$optfmt" "-l" \
@@ -265,6 +263,30 @@ while getopts AacDdEeFf:hij:LlNnqR:rs:vXx flag; do
done
shift $(( $OPTIND - 1 ))
+#
+# Sanity checks
+#
+if [ "$SHOW_ALL" ]; then
+ [ $# -eq 0 ] || usage "-a/-A do not take names" # NOTREACHED
+fi
+if [ "$DESCRIBE" ]; then
+ if [ "$CHECK_ONLY$DELETE$LIST_CONFS$LIST_SERVICE_CONFS$RAW" ]; then
+ if [ "$DELETE" = "2" ]; then
+ # NB: Do not advertise secret `-X' unless it was used
+ usage "-d cannot be combined with -c/-l/-L/-r/-x/-X"
+ # NOTREACHED
+ fi
+ usage "-d cannot be combined with -c/-l/-L/-r/-x" # NOTREACHED
+ fi
+ for item in "$@"; do
+ case "$item" in
+ *=*) usage "-d does not take values" ;; # NOTREACHED
+ esac
+ done
+fi
+[ "$JAIL" -a "$ROOTDIR" ] &&
+ usage "-j and -R are mutually exclusive" # NOTREACHED
+
#
# Process `-L' flag
#
@@ -434,6 +456,14 @@ errmsg="\`-x' option incompatible with \`-a'/\`-A' options"
errmsg="$errmsg (use \`-X' to override)"
if [ "$DELETE" -a "$SHOW_ALL" ]; then
[ "$DELETE" = "2" ] || die "$errmsg"
+elif [ "$DELETE" = "2" ]; then
+ die "-X requires -a/-A" # NOTREACHED
+elif [ "$DELETE" ]; then
+ for item in "$@"; do
+ case "$item" in
+ *=*) die "%s: -x does not take a value" "$item" ;;
+ esac
+ done
fi
#
@@ -727,16 +757,6 @@ while [ $# -gt 0 ]; do
fi
fi
- #
- # If `-x' or `-X' is passed, delete the variable and ignore the
- # desire to set some value
- #
- if [ "$DELETE" ]; then
- f_sysrc_delete "$NAME" || status=$FAILURE
- shift 1
- continue
- fi
-
#
# Determine both `before' value and appropriate `new' value
#
diff --git a/usr.sbin/sysrc/sysrc.8 b/usr.sbin/sysrc/sysrc.8
index 8a3ea74e5216..40f60c6ff077 100644
--- a/usr.sbin/sysrc/sysrc.8
+++ b/usr.sbin/sysrc/sysrc.8
@@ -123,7 +123,7 @@ The
or name of the
.Ar jail
to operate within
-.Pq overrides So Fl R Ar dir Sc ; requires Xr jexec 8 .
+.Pq requires Xr jexec 8 .
.It Fl L
List all configuration files including rc.conf.d entries on stdout and exit.
Can be combined with