init avoid epair name clash

This commit is contained in:
tschettervictor
2025-09-28 12:59:11 -06:00
parent dda16adf46
commit 838e10b319
3 changed files with 32 additions and 7 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}