From b90d8c60f7d07d60a06c6547955bbaa1e6c0beb8 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sun, 29 Nov 2020 11:31:14 -0500 Subject: [PATCH] Update existing limit when a new value is provided. Closes #233. --- usr/local/share/bastille/limits.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/limits.sh b/usr/local/share/bastille/limits.sh index ca48427d..d85687da 100644 --- a/usr/local/share/bastille/limits.sh +++ b/usr/local/share/bastille/limits.sh @@ -63,8 +63,12 @@ for _jail in ${JAILS}; do _rctl_rule="jail:${_jail}:${OPTION}:deny=${VALUE}/jail" - ## if entry doesn't exist, add; else show existing entry - if ! grep -qs "${_rctl_rule}" "${bastille_jailsdir}/${_jail}/rctl.conf"; then + # Check whether the entry already exists and, if so, update it. -- cwells + if grep -qs "jail:${_jail}:${OPTION}:deny" "${bastille_jailsdir}/${_jail}/rctl.conf"; then + _escaped_option=$(echo "${OPTION}" | sed 's/\//\\\//g') + _escaped_rctl_rule=$(echo "${_rctl_rule}" | sed 's/\//\\\//g') + sed -i '' -E "s/jail:${_jail}:${_escaped_option}:deny.+/${_escaped_rctl_rule}/" "${bastille_jailsdir}/${_jail}/rctl.conf" + else # Just append the entry. -- cwells echo "${_rctl_rule}" >> "${bastille_jailsdir}/${_jail}/rctl.conf" fi