From nobody Wed Nov 25 21:51:29 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jZYKY6xSkz72HLS for ; Wed, 25 Nov 2026 21:51:29 +0000 (UTC) (envelope-from git@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) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jZYKY3N3yz4lPv for ; Wed, 25 Nov 2026 21:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795643489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9Zle4a2x3sF8qgLTHiuWzNzHPqJlFe3iF+ZOBQ3aoSU=; b=X5N7AAh4QbPTfIwh6AlDI32g0k9713mKa8fD39HUwR+Z/vRbndNLsSZJ/V7t01idbmvLHK nWzg594qBK9B+28RK1/jkKYpCRWCK9mVfSKDRFE7Rv6TyL7YsxnR6M3Ty/5oLUBgasMVqc o89uvrhqzdyiI/2Vo0pIqplZ6z9vaDe5EaSSLSK1oBjIoMOerlmCT2pwfGGv8GJQTP5/ji ghYyxJuxa4sZ+LxZA/d4BfBxFpWEA4NSOxjx90uDoSXRTgmufnmAc39jfEDPljuUpVboq7 mdql55DSdy23SGyv5D09LXjgjSXLTeKbZG262a2yoo+DikwX3nVzI/MNJPQlJA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795643489; b=PmEIJwXyU5hJIMP1OLYbWUFrOCvQIXj26u2nebcy9yRXgGiZnYiORMjJbyhgtXv/1b9QAT 8i/9vecOf4VAWuKz+tL5Hy2ojn4o5/rN+A1LNUqXrlqACyM4EIjv+nFqDBkHHLKsnWC2mL 8KI3ZVuRxkuDJiGEinpzXpxTEdf1PPiiD5ZMeadtQPmXVX1q3GHj7a0aIIzbOoNdbG+fXu KEfGElbPV4Zt2K5UGZo1RgsXrgGFNqbIDTx5Wl0I3I1WxkrABDunoOTnPJnrX+0ljzX301 9dDiOmEdW8bbVYml7JeAdBySzk/5o8YRQnOvC4sRzQ2b93qaVfG1ePt3KHhxnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795643489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9Zle4a2x3sF8qgLTHiuWzNzHPqJlFe3iF+ZOBQ3aoSU=; b=TIXh4aZFb2HtRHRNXRg1kfutQuVXwHDUaejCJq914TQN9JwdZIv9oRmuy1NqWZ1oJBoId3 BMMcsOq7mQwQbraD5FbDE4jrjF6CpGKXVxQfP/GdwtLMeXZu7EGWDLYe4iOHrg2mlWszmj IAZtjG9NbwpFo5LWBp4NCzptUWQmrPs2I0oxE+eSK25DU4dPJQoHcCjSelMFKMAia2u4dY pS2s/d0oaMYiKDnGyaw9rEc/bgPuZawY8wrhYr90uC9o+5rQIEcW1Z3yVGzXu2pRQMvsgU +R2SM/wXxpkuGjRuivqduxHHIyVQkWixJzwiI2FEkPaB01I201bblKVS0vRcFg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jZYKY32pQzkbQ for ; Wed, 25 Nov 2026 21:51:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 129d5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 25 Nov 2026 21:51:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Devin Teske Subject: git: d0a167652278 - main - sysrc: Support special characters in file names List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dteske X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d0a167652278ed81d259a1b77620b0c1cb9f72c8 Auto-Submitted: auto-generated Date: Wed, 25 Nov 2026 21:51:29 +0000 Message-Id: <6b075861.129d5.534ba65@gitrepo.freebsd.org> The branch main has been updated by dteske: URL: https://cgit.FreeBSD.org/src/commit/?id=d0a167652278ed81d259a1b77620b0c1cb9f72c8 commit d0a167652278ed81d259a1b77620b0c1cb9f72c8 Author: Devin Teske AuthorDate: 2026-11-25 21:46:30 +0000 Commit: Devin Teske CommitDate: 2026-11-25 21:47:38 +0000 sysrc: Support special characters in file names Previously, passing -f "abc'123" (for example) would break sysrc. Support special characters such as single-quote, double-quote, dollar sign, backtick, asterisk, and more. It was previously impossible to handle file names with glob characters. If you absolutely need to use a glob to expand a list of potential files for `-f' you can still do it in two ways: sysrc -f "$( echo glob )" ... RC_CONFS=$( echo glob ) sysrc ... While here, clean up trailing whitespace on 3 lines. Reviewed by: kfv Differential Revision: https://reviews.freebsd.org/D61740 --- usr.sbin/sysrc/sysrc | 20 ++++++++++--- usr.sbin/sysrc/sysrc.subr | 72 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc index c5bb85be3be1..1e8cfb74bba8 100644 --- a/usr.sbin/sysrc/sysrc +++ b/usr.sbin/sysrc/sysrc @@ -16,7 +16,7 @@ pgm="${0##*/}" # Program basename # # Version information # -SYSRC_VERSION="8.9 Nov-18,2026" +SYSRC_VERSION="9.0 Nov-18,2026" # # Options @@ -316,13 +316,14 @@ fi # Process `-L' flag # if [ "$LIST_SERVICE_CONFS" ]; then - list= + list= # # List rc_conf_files if no service names given # files= [ $# -eq 0 ] && files=$( f_sysrc_get rc_conf_files ) + set -f # noglob for file in $files; do if [ "$EXISTING_ONLY" ]; then [ -e "$file" -a ! -d "$file" ] || continue @@ -333,6 +334,7 @@ if [ "$LIST_SERVICE_CONFS" ]; then list="$list $file" [ "$VERBOSE$SHOW_EQUALS" ] || echo "$file" done + set +f # glob list="${list# }" if [ $# -eq 0 ]; then if [ "$VERBOSE" ]; then @@ -349,6 +351,7 @@ if [ "$LIST_SERVICE_CONFS" ]; then for service in ${*:-$( service -l )}; do slist= f_sysrc_service_configs $service files || retval=$? continue + set -f # noglob for file in $files; do if [ "$EXISTING_ONLY" ]; then [ -e "$file" -a ! -d "$file" ] || continue @@ -360,6 +363,7 @@ if [ "$LIST_SERVICE_CONFS" ]; then fi slist="$slist $file" done + set +f # glob slist="${slist# }" if [ $# -gt 0 ]; then [ "$slist" ] || retval=$? @@ -371,9 +375,11 @@ if [ "$LIST_SERVICE_CONFS" ]; then [ "$slist" ] && shell_fmt "$service=%s\n" "$slist" continue elif [ $# -eq 0 -o ! "$QUIET" ]; then + set -f # noglob for item in $slist; do echo "$item" done + set +f # glob fi list="$list${slist:+ }$slist" done @@ -415,7 +421,7 @@ if [ "$EXISTING_ONLY" ]; then # RC_CONFS to override the unpreened value. If RC_CONFS already has a # value (`-D', `-f file', `-s name', or inherited from parent), use it. # Otherwise, include filtered contents of rc_conf_files. - # + # RC_CONFS=$( if [ "${RC_CONFS+set}" ]; then set -- $RC_CONFS @@ -442,9 +448,11 @@ if [ "$LIST_CONFS" ]; then else list=$( f_sysrc_get rc_conf_files ) fi + set -f # noglob for item in $list; do echo "$item" done + set +f # glob exit $SUCCESS fi @@ -458,7 +466,8 @@ fi # errmsg="Exiting due to previous syntax errors" if [ "${RC_CONFS+set}" ]; then - ( for i in $RC_CONFS; do + ( set -f # noglob + for i in $RC_CONFS; do [ -e "$i" ] || continue /bin/sh -n "$i" || exit $FAILURE done @@ -467,6 +476,7 @@ if [ "${RC_CONFS+set}" ]; then else /bin/sh -n "$RC_DEFAULTS" || die "$errmsg" ( . "$RC_DEFAULTS" + set -f # noglob for i in $rc_conf_files; do [ -e "$i" ] || continue /bin/sh -n "$i" || exit $FAILURE @@ -680,7 +690,9 @@ if [ "$SHOW_ALL" ]; then rc_conf_files="${rc_conf_files% }" fi + set -f # noglob source_rc_confs + set +f # glob # # If passed `-a' (rather than `-A'), remove diff --git a/usr.sbin/sysrc/sysrc.subr b/usr.sbin/sysrc/sysrc.subr index 2e4ab79706f0..9ee396f96086 100644 --- a/usr.sbin/sysrc/sysrc.subr +++ b/usr.sbin/sysrc/sysrc.subr @@ -290,6 +290,7 @@ f_sysrc_get() _rc_confs_set=1 fi + set -f # noglob source_rc_confs > /dev/null 2>&1 # @@ -832,6 +833,7 @@ f_sysrc_service_configs() { local OPTIND=1 OPTARG __flag __append= __prepend= local __local_startup __dir __spath __stype __names= + local __noglob= while getopts ap __flag; do case "$__flag" in @@ -844,12 +846,18 @@ f_sysrc_service_configs() [ $# -gt 0 ] || return $FAILURE local __sname="$1" __var_to_set="$2" + case "$-" in + *f*) __noglob=1 ;; + esac + __local_startup=$( f_sysrc_get local_startup ) + set -f # noglob for __dir in /etc/rc.d $__local_startup; do __spath="$__dir/$__sname" [ -f "$__spath" -a -x "$__spath" ] || __spath= continue break done + [ "$__noglob" ] || set +f # glob [ "$__spath" ] || return $FAILURE __stype=$( file -b "$__spath" 2> /dev/null ) @@ -876,17 +884,21 @@ f_sysrc_service_configs() esac local __name __test_path __configs= + set -f # noglob for __name in $__names; do for __dir in /etc/rc.d $__local_startup; do __test_path="${__dir%/rc.d}/rc.conf.d/$__name" [ -d "$__test_path" ] || __configs="$__configs $__test_path" continue + set +f # glob for __test_path in "$__test_path"/*; do [ -f "$__test_path" ] || continue __configs="$__configs $__test_path" - done + done + set -f # noglob done done + [ "$__noglob" ] || set +f # glob __configs="${__configs# }" if [ "$__var_to_set" ]; then @@ -961,6 +973,7 @@ f_sysrc_find() local rc_conf_files="$( f_sysrc_get rc_conf_files )" local conf_files= local file + local noglob= # Check parameters case "$varname" in @@ -973,6 +986,15 @@ f_sysrc_find() # [ "${RC_CONFS+set}" ] && rc_conf_files="$RC_CONFS" + # + # Determine if caller has set noglob before we disable filename + # globbing, so we can later return to the inherited state. + # + case "$-" in + *f*) noglob=1 ;; + esac + set -f # noglob + # # Reverse the order of files in rc_conf_files (the boot process sources # these in order, so we will search them in reverse-order to find the @@ -996,10 +1018,12 @@ f_sysrc_find() [ -f "$file" -a -r "$file" ] || continue if grep -Eq "$regex" $file; then echo $file + [ "$noglob" ] || set +f # glob return $SUCCESS fi done + [ "$noglob" ] || set +f # glob return $FAILURE # Not found } @@ -1163,8 +1187,15 @@ f_sysrc_set() # if [ "$not_found" ]; then # Add a newline if missing before appending to the file - [ ! -e "$file" ] || awk 'BEGIN { wc = 0 } NR == 1 { - (cmd = "wc -l " FILENAME) | getline + [ ! -e "$file" ] || awk ' + BEGIN { + wc = 0 + sq = "\047" + } + NR == 1 { + file = FILENAME + gsub(sq, sq "\\" sq sq, file) + (cmd = "wc -l " sq file sq) | getline close(cmd) wc = $1 } END { exit wc != NR }' "$file" || @@ -1198,8 +1229,9 @@ f_sysrc_set() # temporary file over the destination, the destination will inherit the # permissions from the temporary file). # - local mode - f_eval_catch -dk mode $funcname stat 'stat -f "%%#Lp" "%s"' "$file" || + local _file mode + f_shell_escape "$file" _file + f_eval_catch -dk mode $funcname stat "stat -f '%%#Lp' '%s'" "$_file" || mode=0644 f_eval_catch -d $funcname chmod 'chmod "%s" "%s"' "$mode" "$tmpfile" @@ -1210,7 +1242,7 @@ f_sysrc_set() # local owner f_eval_catch -dk owner $funcname stat \ - 'stat -f "%%u:%%g" "%s"' "$file" || owner="root:wheel" + "stat -f '%%u:%%g' '%s'" "$_file" || owner="root:wheel" f_eval_catch -d $funcname chown 'chown "%s" "%s"' "$owner" "$tmpfile" # @@ -1245,7 +1277,7 @@ f_sysrc_set() # # Finally, move the temporary file into place. # - f_eval_catch -de $funcname mv 'mv "%s" "%s"' "$tmpfile" "$file" + f_eval_catch -de $funcname mv "mv '%s' '%s'" "$tmpfile" "$_file" } # f_sysrc_delete $varname @@ -1278,7 +1310,8 @@ f_sysrc_delete() { local funcname=f_sysrc_delete local varname="$1" - local file + local file _file + local noglob= # Check arguments [ "$varname" ] || return $FAILURE @@ -1287,8 +1320,13 @@ f_sysrc_delete() # Operate on each of the specified files # local tmpfile + case "$-" in + *f*) noglob=1 ;; + esac + set -f # noglob for file in ${RC_CONFS-$( f_sysrc_get rc_conf_files )}; do [ -e "$file" ] || continue + f_shell_escape "$file" _file # # Create a new temporary file to write to. @@ -1297,6 +1335,7 @@ f_sysrc_delete() 'mktemp -t "%s"' "$pgm" then echo "$tmpfile" >&2 + [ "$noglob" ] || set +f # glob return $FAILURE fi @@ -1306,9 +1345,9 @@ f_sysrc_delete() # local mode owner f_eval_catch -dk mode $funcname stat \ - 'stat -f "%%#Lp" "%s"' "$file" || mode=0644 + "stat -f '%%#Lp' '%s'" "$_file" || mode=0644 f_eval_catch -dk owner $funcname stat \ - 'stat -f "%%u:%%g" "%s"' "$file" || owner="root:wheel" + "stat -f '%%u:%%g' '%s'" "$_file" || owner="root:wheel" f_eval_catch -d $funcname chmod \ 'chmod "%s" "%s"' "$mode" "$tmpfile" f_eval_catch -d $funcname chown \ @@ -1334,6 +1373,7 @@ f_sysrc_delete() f_err "$msg_previous_syntax_errors\n" \ "$pgm" "$file" rm -f "$tmpfile" + [ "$noglob" ] || set +f # glob return $FAILURE fi @@ -1343,15 +1383,23 @@ f_sysrc_delete() if [ ! -w "$file" ]; then f_err "$msg_permission_denied\n" "$pgm" "$file" rm -f "$tmpfile" + [ "$noglob" ] || set +f # glob return $FAILURE fi # # Finally, move the temporary file into place. # - f_eval_catch -de $funcname mv \ - 'mv "%s" "%s"' "$tmpfile" "$file" || return $FAILURE + if ! f_eval_catch -de $funcname mv \ + "mv '%s' '%s'" "$tmpfile" "$_file" + then + [ "$noglob" ] || set +f + return $FAILURE + fi done + + [ "$noglob" ] || set +f # glob + return $SUCCESS } ############################################################ MAIN