From 358dbe7e0b80380c6f19bc08dcab28cc7e6d7c1c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 14 Jan 2025 08:45:35 -0700 Subject: [PATCH 1/8] template: allow & in arg string --- usr/local/share/bastille/template.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 3aed8664..3db0cad4 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -54,7 +54,7 @@ get_arg_name() { parse_arg_value() { # Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells - echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' + echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' } get_arg_value() { @@ -299,7 +299,7 @@ for _jail in ${JAILS}; do ;; cmd) # Escape single-quotes in the command being executed. -- cwells - _args=$(echo "${_args}" | sed "s/'/'\\\\''/g") + _args=$(echo "${_args}" | sed "s/'/'\\\\''/g" | sed 's/&/\\&/g') # Allow redirection within the jail. -- cwells _args="sh -c '${_args}'" ;; From a5f66c6e80be2c005950fd1b1c919efcab2a89ff Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:13:52 -0700 Subject: [PATCH 2/8] =?UTF-8?q?template:=20do=20not=20escape=20&=20in=20?= =?UTF-8?q?=E2=80=9Ccmd=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/local/share/bastille/template.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 3db0cad4..58f9891a 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -54,7 +54,7 @@ get_arg_name() { parse_arg_value() { # Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells - echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' + echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/\\\&/\&/g' } get_arg_value() { @@ -299,7 +299,7 @@ for _jail in ${JAILS}; do ;; cmd) # Escape single-quotes in the command being executed. -- cwells - _args=$(echo "${_args}" | sed "s/'/'\\\\''/g" | sed 's/&/\\&/g') + _args=$(echo "${_args}" | sed "s/'/'\\\\''/g") # Allow redirection within the jail. -- cwells _args="sh -c '${_args}'" ;; From 5ac744d652070e0519b10c8b4629f8076b597b6c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:45:30 -0700 Subject: [PATCH 3/8] docs: Document escaping ampersand --- docs/chapters/template.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/chapters/template.rst b/docs/chapters/template.rst index 463fccbf..48e4fdc7 100644 --- a/docs/chapters/template.rst +++ b/docs/chapters/template.rst @@ -45,9 +45,14 @@ Template Automation Hooks | SYSRC | sysrc command(s) | nginx_enable=YES | +---------+-------------------+-----------------------------------------+ -Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped +Special Cases + +SYSRC requires that NO quotes be used or that quotes (`"`) be escaped ie; (`\\"`) +When using an ampersand "\&" in a template hook, and it is to be +interpreted literally, it must be escaped (`\\&`) + Place these uppercase template hook commands into a `Bastillefile` in any order and automate container setup as needed. From 9bf492b275a946a04fdcc05e377ef03935864f85 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:09:55 -0700 Subject: [PATCH 4/8] docs: better ARG documentation for literal ampersand --- docs/chapters/template.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/chapters/template.rst b/docs/chapters/template.rst index 48e4fdc7..82b19541 100644 --- a/docs/chapters/template.rst +++ b/docs/chapters/template.rst @@ -45,13 +45,14 @@ Template Automation Hooks | SYSRC | sysrc command(s) | nginx_enable=YES | +---------+-------------------+-----------------------------------------+ -Special Cases +Special Hook Cases +------------------ SYSRC requires that NO quotes be used or that quotes (`"`) be escaped ie; (`\\"`) -When using an ampersand "\&" in a template hook, and it is to be -interpreted literally, it must be escaped (`\\&`) +ARG requires an ampersand "\&" to be escaped (`\\&`) if it is to be interpreted +literally, otherwise it is treated as a special character. Place these uppercase template hook commands into a `Bastillefile` in any order and automate container setup as needed. From 4d554e19cd965ede58202c0a3fa1fd428f663252 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:54:34 -0700 Subject: [PATCH 5/8] template: Treat ampersand literally --- usr/local/share/bastille/template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 58f9891a..60a63480 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -54,7 +54,7 @@ get_arg_name() { parse_arg_value() { # Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells - echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/\\\&/\&/g' + echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' } get_arg_value() { From 91d41b9b3f0c4aea91519dd4627e1497bbbfe773 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:56:30 -0700 Subject: [PATCH 6/8] docs: Clarify ampersand --- docs/chapters/template.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/chapters/template.rst b/docs/chapters/template.rst index 82b19541..e3a7d5f1 100644 --- a/docs/chapters/template.rst +++ b/docs/chapters/template.rst @@ -51,8 +51,8 @@ Special Hook Cases SYSRC requires that NO quotes be used or that quotes (`"`) be escaped ie; (`\\"`) -ARG requires an ampersand "\&" to be escaped (`\\&`) if it is to be interpreted -literally, otherwise it is treated as a special character. +ARG will always treat an ampersand "\&" literally, without the need to escape it. +Escaping it will cause errors. Place these uppercase template hook commands into a `Bastillefile` in any order and automate container setup as needed. From 4dc2b3b842c349ea9cc87bdab552cca2789257bf Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 10 Feb 2025 12:07:12 -0700 Subject: [PATCH 7/8] template: Fix default value with spaces #692 @michael-o This essentially just makes sure there are not multiple quotes following each other inside the ARG value. --- usr/local/share/bastille/template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 60a63480..a318e3f3 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -54,7 +54,7 @@ get_arg_name() { parse_arg_value() { # Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells - echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' + echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' -e 's/""/"/g' } get_arg_value() { From 813a6ccd26ba376769c0f45adddb719753ce9770 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 13 Feb 2025 06:56:24 -0700 Subject: [PATCH 8/8] template: Remove quotes from args --- usr/local/share/bastille/template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index a318e3f3..9e4f42b2 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -54,7 +54,7 @@ get_arg_name() { parse_arg_value() { # Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells - echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' -e 's/""/"/g' + echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g' -e 's/&/\\&/g' -e 's/"//g' } get_arg_value() {