hardened printf

This commit is contained in:
m8in
2026-06-10 20:51:08 +02:00
parent 93f3dfdb5f
commit d90d5769ff
10 changed files with 38 additions and 37 deletions
+6 -5
View File
@@ -81,20 +81,21 @@ function setup() {
readonly _COMMAND _PAM_FILE
! [ -f "${_PAM_FILE}" ] \
&& printf "FAILURE: Missing file: %s\n" "${_PAM_FILE:?"Missing PAM_FILE"}" >&2 \
&& printf -- "FAILURE: Missing file: %s\n" "${_PAM_FILE:?"Missing PAM_FILE"}" >&2 \
&& exit 1
# Lines are already appended, so nothing is to do, therefore no setup.
grep -q -F "/${CIS[SCRIPTNAME]?:"Missing SCRIPTNAME"}" "${_PAM_FILE}" \
&& printf -- "FAILURE: Command have already been appended to the file: '%s'\n" "${_PAM_FILE}" >&2 \
&& return 1
# Append command to call this script, which is the setup.
printf "Appending the following command to file '%s':\n - %s\n" "${_PAM_FILE}" "${_COMMAND}" >&2 \
&& printf "\n#Call this script on each ssh-login\n%s\n" "${_COMMAND}" >> "${_PAM_FILE}" \
&& printf "SUCCESS: Setup completed.\n" >&2 \
printf -- "Appending the following command to file '%s':\n - %s\n" "${_PAM_FILE}" "${_COMMAND}" >&2 \
&& printf -- "\n#Call this script on each ssh-login\n%s\n" "${_COMMAND}" >> "${_PAM_FILE}" \
&& printf -- "SUCCESS: Setup completed.\n" >&2 \
&& return 0
printf "FAILURE: Setup of '%s' failed.\n" "${CIS[SCRIPTNAME]}" >&2
printf -- "FAILURE: Setup of '%s' failed.\n" "${CIS[SCRIPTNAME]}" >&2
exit 1
}