2018-11-07 10:36:54 -07:00
|
|
|
#!/bin/sh
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2025-01-11 14:07:41 -05:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2018-2025, Christer Edwards <christer.edwards@gmail.com>
|
2018-11-07 10:36:54 -07:00
|
|
|
# All rights reserved.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2018-11-07 10:36:54 -07:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2018-11-07 10:36:54 -07:00
|
|
|
# * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
# list of conditions and the following disclaimer.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2018-11-07 10:36:54 -07:00
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
# and/or other materials provided with the distribution.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2018-11-07 10:36:54 -07:00
|
|
|
# * Neither the name of the copyright holder nor the names of its
|
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
|
# this software without specific prior written permission.
|
2020-04-14 11:52:29 +02:00
|
|
|
#
|
2018-11-07 10:36:54 -07:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
# 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.
|
|
|
|
|
|
2020-08-30 10:57:14 -04:00
|
|
|
. /usr/local/share/bastille/common.sh
|
2018-11-07 10:36:54 -07:00
|
|
|
. /usr/local/etc/bastille/bastille.conf
|
|
|
|
|
|
|
|
|
|
usage() {
|
2020-08-30 10:57:14 -04:00
|
|
|
error_exit "Usage: bastille start TARGET"
|
2018-11-07 10:36:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Handle special-case commands first.
|
|
|
|
|
case "$1" in
|
|
|
|
|
help|-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
|
|
|
|
usage
|
|
|
|
|
fi
|
|
|
|
|
|
2023-03-16 20:58:11 +01:00
|
|
|
bastille_root_check
|
|
|
|
|
|
2019-11-21 16:49:00 -07:00
|
|
|
TARGET="${1}"
|
2019-11-22 22:04:38 -07:00
|
|
|
shift
|
2019-11-21 16:49:00 -07:00
|
|
|
|
2019-11-22 22:04:38 -07:00
|
|
|
if [ "${TARGET}" = 'ALL' ]; then
|
2019-11-25 17:12:27 -07:00
|
|
|
JAILS=$(bastille list jails)
|
2018-11-07 10:36:54 -07:00
|
|
|
fi
|
2019-11-22 22:04:38 -07:00
|
|
|
if [ "${TARGET}" != 'ALL' ]; then
|
2019-12-27 13:15:58 -04:00
|
|
|
JAILS=$(bastille list jails | awk "/^${TARGET}$/")
|
2020-02-14 11:00:02 -04:00
|
|
|
## check if exist
|
|
|
|
|
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
|
2020-08-30 10:57:14 -04:00
|
|
|
error_exit "[${TARGET}]: Not found."
|
2020-02-14 11:00:02 -04:00
|
|
|
fi
|
2018-11-07 10:36:54 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
for _jail in ${JAILS}; do
|
2019-11-21 16:49:00 -07:00
|
|
|
## test if running
|
2021-12-17 19:09:49 -07:00
|
|
|
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
|
2020-08-30 10:57:14 -04:00
|
|
|
error_notify "[${_jail}]: Already started."
|
2019-11-21 16:49:00 -07:00
|
|
|
|
|
|
|
|
## test if not running
|
2021-12-17 19:09:49 -07:00
|
|
|
elif [ ! "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
|
2020-12-13 20:22:59 -05:00
|
|
|
# Verify that the configured interface exists. -- cwells
|
|
|
|
|
if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then
|
|
|
|
|
_interface=$(bastille config $_jail get interface)
|
|
|
|
|
if ! ifconfig | grep "^${_interface}:" >/dev/null; then
|
|
|
|
|
error_notify "Error: ${_interface} interface does not exist."
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2020-02-14 19:01:08 -04:00
|
|
|
## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry
|
2024-12-10 14:59:02 -07:00
|
|
|
_ip4=$(bastille config "${_jail}" get ip4.addr)
|
|
|
|
|
if [ "${_ip4}" != "not set" ]; then
|
|
|
|
|
if ifconfig | grep -wF "${_ip4}" >/dev/null; then
|
|
|
|
|
error_notify "Error: IP address (${_ip4}) already in use."
|
2020-12-13 20:22:59 -05:00
|
|
|
continue
|
2020-02-14 19:01:08 -04:00
|
|
|
fi
|
2022-11-26 23:24:33 -05:00
|
|
|
## add ip4.addr to firewall table
|
2024-12-10 14:59:02 -07:00
|
|
|
pfctl -q -t "${bastille_network_pf_table}" -T add "${_ip4}"
|
2020-02-04 09:30:03 +01:00
|
|
|
fi
|
2020-02-04 14:52:19 -07:00
|
|
|
|
2020-02-14 11:00:02 -04:00
|
|
|
## start the container
|
2020-11-25 21:19:08 -05:00
|
|
|
info "[${_jail}]:"
|
2020-02-20 18:06:31 -04:00
|
|
|
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c "${_jail}"
|
2020-02-04 14:52:19 -07:00
|
|
|
|
2020-01-26 10:08:42 -07:00
|
|
|
## add rctl limits
|
|
|
|
|
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
|
|
|
|
|
while read _limits; do
|
|
|
|
|
rctl -a "${_limits}"
|
|
|
|
|
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-10-19 15:17:46 +01:00
|
|
|
## add rdr rules
|
|
|
|
|
if [ -s "${bastille_jailsdir}/${_jail}/rdr.conf" ]; then
|
|
|
|
|
while read _rules; do
|
|
|
|
|
bastille rdr "${_jail}" ${_rules}
|
|
|
|
|
done < "${bastille_jailsdir}/${_jail}/rdr.conf"
|
|
|
|
|
fi
|
2018-11-24 09:55:16 -07:00
|
|
|
fi
|
2018-11-13 21:40:11 -07:00
|
|
|
echo
|
2018-11-07 10:36:54 -07:00
|
|
|
done
|