mirror of
https://github.com/hackacad/bastille.git
synced 2026-03-26 02:35:20 +01:00
init avoid epair name clash
This commit is contained in:
@@ -102,10 +102,19 @@ IP="${3}"
|
||||
bastille_root_check
|
||||
set_target_single "${TARGET}"
|
||||
|
||||
## don't allow for dots(.) in container names
|
||||
if echo "${NEWNAME}" | grep -q "[.]"; then
|
||||
error_exit "[ERROR]: Jail names may not contain a dot(.)!"
|
||||
fi
|
||||
clone_validate_jail_name() {
|
||||
if echo "${NEWNAME}" | grep -q "[.]"; then
|
||||
error_exit "[ERROR]: Jail names may not contain a dot(.)!"
|
||||
elif [ "$(bastille config ${TARGET} get vnet)" = "enabled" ]; then
|
||||
if [ "$(echo -n "e0a_${NEWNAME}" | awk '{print length}')" -ge 16 ]; then
|
||||
name_prefix="$(echo ${NEWNAME} | cut -c1-7)"
|
||||
name_suffix="$(echo ${NEWNAME} | rev | cut -c1-2 | rev)"
|
||||
if find "${bastille_jailsdir}"/*/jail.conf -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -oqs "e0b_"${name_prefix}"xx"${name_suffix}" 2>/dev/null; then
|
||||
error_exit "[ERROR]: Invalid jail name due to epair naming limitations. See documentation for details."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
validate_ip() {
|
||||
|
||||
@@ -554,6 +563,6 @@ clone_jail() {
|
||||
|
||||
info "\nAttempting to clone '${TARGET}' to '${NEWNAME}'..."
|
||||
|
||||
clone_jail
|
||||
clone_validate_jail_name
|
||||
|
||||
echo
|
||||
clone_jail
|
||||
|
||||
@@ -76,6 +76,12 @@ validate_name() {
|
||||
error_exit "[ERROR]: Jail names may not contain special characters!"
|
||||
elif echo "${NAME_VERIFY}" | grep -qE '^[0-9]+$'; then
|
||||
error_exit "[ERROR]: Jail names may not contain only digits."
|
||||
elif { [ "${VNET_JAIL_BRIDGE}" -eq 1 ] || [ "${VNET_JAIL_STANDARD}" -eq 1 ]; } && [ "$(echo -n "e0a_${NAME_VERIFY}" | awk '{print length}')" -ge 16 ]; then
|
||||
name_prefix="$(echo ${NAME_VERIFY} | cut -c1-7)"
|
||||
name_suffix="$(echo ${NAME_VERIFY} | rev | cut -c1-2 | rev)"
|
||||
if find "${bastille_jailsdir}"/*/jail.conf -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -oqs "e0b_"${name_prefix}"xx"${name_suffix}" 2>/dev/null; then
|
||||
error_exit "[ERROR]: Invalid jail name, due to epair naming limitations. See documentation for details."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,20 @@ validate_name() {
|
||||
local NAME_VERIFY="${NEWNAME}"
|
||||
local NAME_SANITY="$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')"
|
||||
|
||||
if [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
|
||||
if echo "${NAME_VERIFY}" | grep -q "[.]"; then
|
||||
error_exit "[ERROR]: Jail names may not contain a dot(.)!"
|
||||
elif [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
|
||||
error_exit "[ERROR]: Jail names may not begin with (-|_) characters!"
|
||||
elif [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
|
||||
error_exit "[ERROR]: Jail names may not contain special characters!"
|
||||
elif [ "$(bastille config ${TARGET} get vnet)" = "enabled" ]; then
|
||||
if [ "$(echo -n "e0a_${NAME_VERIFY}" | awk '{print length}')" -ge 16 ]; then
|
||||
name_prefix="$(echo ${NAME_VERIFY} | cut -c1-7)"
|
||||
name_suffix="$(echo ${NAME_VERIFY} | rev | cut -c1-2 | rev)"
|
||||
if find "${bastille_jailsdir}"/*/jail.conf -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -oqs "e0b_"${name_prefix}"xx"${name_suffix}" 2>/dev/null; then
|
||||
error_exit "[ERROR]: Invalid jail name due to epair naming limitations. See documentation for details."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user