From 147e7d5db31157e48f9d1e20c135188c3aa9e07f Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 22 May 2020 21:46:03 -0400 Subject: [PATCH 1/3] User option to force destroy jail in ZFS --- usr/local/share/bastille/destroy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index f6aabc99..5eff79ff 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -60,8 +60,12 @@ destroy_jail() { if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${TARGET}" ]; then + local OPTIONS="-r" + if [ "${FORCE}" = "1" ]; then + local OPTIONS="-rf" + fi ## remove jail zfs dataset recursively - zfs destroy -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}" + zfs destroy "${OPTIONS}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}" fi fi fi From 6fb6e49c6c9a9e524694bf84f5462dd80abd7fb6 Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 25 May 2020 19:35:38 -0400 Subject: [PATCH 2/3] Define local variables just once --- usr/local/share/bastille/destroy.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index 5eff79ff..b4c84a3f 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -37,6 +37,7 @@ usage() { } destroy_jail() { + local OPTIONS bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file @@ -60,9 +61,9 @@ destroy_jail() { if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${TARGET}" ]; then - local OPTIONS="-r" + OPTIONS="-r" if [ "${FORCE}" = "1" ]; then - local OPTIONS="-rf" + OPTIONS="-rf" fi ## remove jail zfs dataset recursively zfs destroy "${OPTIONS}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}" From 932f1afae1d7d1d2e348b255a25bf604d4688698 Mon Sep 17 00:00:00 2001 From: Jose Date: Mon, 25 May 2020 22:09:17 -0400 Subject: [PATCH 3/3] Append PATH over defined PATH, fix colors.pre on bastille command --- usr/local/bin/bastille | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 1fab1637..d4e7e18a 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -28,14 +28,17 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin +PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +bastille_colors_pre() { + ## so we can make it colorful + . /usr/local/share/bastille/colors.pre.sh +} ## root check first. bastille_root_check() { if [ "$(id -u)" -ne 0 ]; then - ## so we can make it colorful - . /usr/local/share/bastille/colors.pre.sh - + bastille_colors_pre ## permission denied echo -e "${COLOR_RED}Bastille: Permission Denied${COLOR_RESET}" 1>&2 echo -e "${COLOR_RED}root / sudo / doas required${COLOR_RESET}" 1>&2 @@ -47,7 +50,8 @@ bastille_root_check ## check for config existance bastille_conf_check() { - if [ ! -r /usr/local/etc/bastille/bastille.conf ]; then + if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then + bastille_colors_pre echo -e "${COLOR_RED}Missing Configuration${COLOR_RESET}" 1>&2 exit 1 fi @@ -64,6 +68,7 @@ bastille_perms_check() { if [ -d "${bastille_prefix}" ]; then BASTILLE_PREFIX_PERMS=$(stat -f "%Op" "${bastille_prefix}") if [ "${BASTILLE_PREFIX_PERMS}" != 40750 ]; then + bastille_colors_pre echo -e "${COLOR_RED}Insecure permissions on ${bastille_prefix}${COLOR_RESET}" 1>&2 echo -e "${COLOR_RED}Try: chmod 0750 ${bastille_prefix}${COLOR_RESET}" 1>&2 echo @@ -130,6 +135,7 @@ shift # Handle special-case commands first. case "${CMD}" in version|-v|--version) + bastille_colors_pre echo -e "${COLOR_GREEN}${BASTILLE_VERSION}${COLOR_RESET}" exit 0 ;; @@ -162,5 +168,6 @@ if [ -f "${SCRIPTPATH}" ]; then exec "${SH}" "${SCRIPTPATH}" "$@" else + bastille_colors_pre echo -e "${COLOR_RED}${SCRIPTPATH} not found.${COLOR_RESET}" 1>&2 fi