limits: add action as the second arg

This commit is contained in:
tschettervictor
2025-03-22 23:32:39 -06:00
committed by GitHub
parent 01af65787a
commit bfcce7c65f

View File

@@ -83,8 +83,9 @@ if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
fi
TARGET="${1}"
OPTION="${2}"
VALUE="${3}"
ACTION="${2}"
shift 2
RACCT_ENABLE="$(sysctl -n kern.racct.enable)"
if [ "${RACCT_ENABLE}" != '1' ]; then
error_exit "Racct not enabled. Append 'kern.racct.enable=1' to /boot/loader.conf and reboot"
@@ -104,49 +105,51 @@ for _jail in ${JAILS}; do
error_continue "Use [-a|--auto] to auto-start the jail."
fi
case "${OPTION}" in
case "${ACTION}" in
clear)
# Remove limits
# Remove limits
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
while read _limits; do
rctl -r "${_limits}" 2>/dev/null
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${TARGET}]: RCTL limits cleared."
info "[${_jail}]: RCTL limits cleared."
fi
;;
;;
list|show)
# Show limits
# Show limits
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
if [ "${VALUE}" = "active" ]; then
if [ "${1}" = "active" ]; then
rctl jail:${_jail} 2>/dev/null
else
cat "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
fi
;;
;;
stats)
# Show statistics
# Show statistics
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
rctl -hu jail:${_jail} 2>/dev/null
fi
;;
;;
reset)
# Remove limits and delete rctl.conf
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
# Remove limits and delete rctl.conf
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
while read _limits; do
rctl -r "${_limits}" 2>/dev/null
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${TARGET}]: RCTL limits cleared."
info "[${TARGET}]: RCTL limits cleared."
fi
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
rm -f "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${TARGET}]: rctl.conf removed."
info "[${TARGET}]: rctl.conf removed."
else
error_continue "[${TARGET}]: rctl.conf not found."
fi
;;
*)
# Add rctl rule to rctl.conf
error_continue "[${TARGET}]: rctl.conf not found."
fi
;;
add)
OPTION="${1}"
VALUE="${2}"
# Add rctl rule to rctl.conf
_rctl_rule="jail:${_jail}:${OPTION}:deny=${VALUE}/jail"
_rctl_rule_log="jail:${_jail}:${OPTION}:log=${VALUE}/jail"
@@ -155,7 +158,7 @@ for _jail in ${JAILS}; do
_escaped_option=$(echo "${OPTION}" | sed 's/\//\\\//g')
_escaped_rctl_rule=$(echo "${_rctl_rule}" | sed 's/\//\\\//g')
_escaped_rctl_rule_log=$(echo "${_rctl_rule_log}" | sed 's/\//\\\//g')
sed -i '' -E "s/jail:${_jail}:${_escaped_option}:deny.+/${_escaped_rctl_rule}/" "${bastille_jailsdir}/${_jail}/rctl.conf"
sed -i '' -E "s/jail:${_jail}:${_escaped_option}:deny.+/${_escaped_rctl_rule}/" "${bastille_jailsdir}/${_jail}/rctl.conf"
sed -i '' -E "s/jail:${_jail}:${_escaped_option}:log.+/${_escaped_rctl_rule_log}/" "${bastille_jailsdir}/${_jail}/rctl.conf"
else # Just append the entry. -- cwells
echo "${_rctl_rule}" >> "${bastille_jailsdir}/${_jail}/rctl.conf"
@@ -164,7 +167,7 @@ for _jail in ${JAILS}; do
echo -e "${OPTION} ${VALUE}"
rctl -a "${_rctl_rule}" "${_rctl_rule_log}"
;;
;;
esac
done