console: Allow multiple targets

This commit is contained in:
tschettervictor
2025-04-04 15:55:48 -06:00
committed by GitHub
parent 321a0975e0
commit a38a76843a

View File

@@ -83,46 +83,54 @@ TARGET="${1}"
USER="${2}" USER="${2}"
bastille_root_check bastille_root_check
set_target_single "${TARGET}" set_target "${TARGET}"
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${TARGET}"
else
error_notify "Jail is not running."
error_exit "Use [-a|--auto] to auto-start the jail."
fi
validate_user() { validate_user() {
if jexec -l "${TARGET}" id "${USER}" >/dev/null 2>&1; then local _jail="${1}"
USER_SHELL="$(jexec -l "${TARGET}" getent passwd "${USER}" | cut -d: -f7)" local _user="${2}"
if jexec -l "${_jail}" id "${_user}" >/dev/null 2>&1; then
USER_SHELL="$(jexec -l "${_jail}" getent passwd "${_user}}" | cut -d: -f7)"
if [ -n "${USER_SHELL}" ]; then if [ -n "${USER_SHELL}" ]; then
if jexec -l "${TARGET}" grep -qwF "${USER_SHELL}" /etc/shells; then if jexec -l "${_jail}" grep -qwF "${USER_SHELL}" /etc/shells; then
jexec -l "${TARGET}" $LOGIN -f "${USER}" jexec -l "${_jail}" $LOGIN -f "${_user}}"
else else
echo "Invalid shell for user ${USER}" echo "Invalid shell for user ${_user}}"
fi fi
else else
echo "User ${USER} has no shell" echo "User ${_user}} has no shell"
fi fi
else else
echo "Unknown user ${USER}" echo "Unknown user ${_user}}"
fi fi
} }
check_fib() { check_fib() {
fib=$(grep 'exec.fib' "${bastille_jailsdir}/${TARGET}/jail.conf" | awk '{print $3}' | sed 's/\;//g') local _jail="${1}"
fib=$(grep 'exec.fib' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g')
if [ -n "${fib}" ]; then if [ -n "${fib}" ]; then
_setfib="setfib -F ${fib}" _setfib="setfib -F ${fib}"
else else
_setfib="" _setfib=""
fi fi
} }
for _jail in JAILS; do
info "[${TARGET}]:" info "[${_jail}]:"
LOGIN="$(jexec -l "${TARGET}" which login)"
if [ -n "${USER}" ]; then check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
validate_user bastille start "${_jail}"
else else
check_fib error_notify "Jail is not running."
LOGIN="$(jexec -l "${TARGET}" which login)" error_exit "Use [-a|--auto] to auto-start the jail."
${_setfib} jexec -l "${TARGET}" $LOGIN -f root fi
fi
LOGIN="$(jexec -l "${_jail}" which login)"
if [ -n "${USER}" ]; then
validate_user "${_jail}" "${USER}"
else
check_fib "${_jail}"
LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi
done