From 7ef65036c659deee21c77260bfde52749178a539 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 14 Feb 2020 11:00:02 -0400 Subject: [PATCH 1/2] Return proper warning messages, code cleanup --- usr/local/share/bastille/limits.sh | 2 +- usr/local/share/bastille/rdr.sh | 3 --- usr/local/share/bastille/start.sh | 12 ++++++++---- usr/local/share/bastille/stop.sh | 6 ++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/usr/local/share/bastille/limits.sh b/usr/local/share/bastille/limits.sh index 8667d195..b6b4a9d7 100644 --- a/usr/local/share/bastille/limits.sh +++ b/usr/local/share/bastille/limits.sh @@ -69,6 +69,6 @@ fi for _jail in ${JAILS}; do echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" echo -e "${TYPE} ${VALUE}" - rctl -a jail:${_jail}:${OPTION}:deny=${VALUE}/jail + rctl -a jail:${_jail}:${OPTION}:deny=${VALUE}/jail echo -e "${COLOR_RESET}" done diff --git a/usr/local/share/bastille/rdr.sh b/usr/local/share/bastille/rdr.sh index bca00a6d..bf0f8edb 100644 --- a/usr/local/share/bastille/rdr.sh +++ b/usr/local/share/bastille/rdr.sh @@ -113,6 +113,3 @@ while [ $# -gt 0 ]; do ;; esac done - - - diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index f3815cc8..7b0fd9a8 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -55,6 +55,10 @@ if [ "${TARGET}" = 'ALL' ]; then fi if [ "${TARGET}" != 'ALL' ]; then JAILS=$(bastille list jails | awk "/^${TARGET}$/") + ## check if exist + if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then + echo -e "${COLOR_RED}[${TARGET}]: Not found.${COLOR_RESET}" + fi fi for _jail in ${JAILS}; do @@ -64,14 +68,14 @@ for _jail in ${JAILS}; do ## test if not running elif [ ! "$(jls name | awk "/^${_jail}$/")" ]; then - ## warn if matching configured (but not online) ip4.addr + ## warn if matching configured (but not online) ip4.addr ip=$(grep 'ip4.addr' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g') - if ifconfig | grep -w "$ip" >/dev/null; then - echo -e "${COLOR_RED}Error: IP address ($ip) already in use.${COLOR_RESET}" + if ifconfig | grep -w "${ip}" >/dev/null; then + echo -e "${COLOR_RED}Error: IP address (${ip}) already in use.${COLOR_RESET}" exit 1 fi - ## start the container + ## start the container echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail} diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index a66d6d07..9cea237b 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -55,8 +55,10 @@ if [ "${TARGET}" = 'ALL' ]; then fi if [ "${TARGET}" != 'ALL' ]; then JAILS=$(jls name | awk "/^${TARGET}$/") - ## test if not running - if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then + ## check if exist or not running + if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then + echo -e "${COLOR_RED}[${TARGET}]: Not found.${COLOR_RESET}" + elif [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then echo -e "${COLOR_RED}[${TARGET}]: Not started.${COLOR_RESET}" fi fi From 19cadec03e2e1164d448193e230ac00de6924e52 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 14 Feb 2020 11:43:26 -0400 Subject: [PATCH 2/2] Add quoted variables to rctl --- usr/local/share/bastille/limits.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/limits.sh b/usr/local/share/bastille/limits.sh index b6b4a9d7..483a0341 100644 --- a/usr/local/share/bastille/limits.sh +++ b/usr/local/share/bastille/limits.sh @@ -69,6 +69,6 @@ fi for _jail in ${JAILS}; do echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" echo -e "${TYPE} ${VALUE}" - rctl -a jail:${_jail}:${OPTION}:deny=${VALUE}/jail + rctl -a jail:"${_jail}":"${OPTION}":deny="${VALUE}/jail" echo -e "${COLOR_RESET}" done