diff --git a/usr/local/share/bastille/clone.sh b/usr/local/share/bastille/clone.sh index 59d7ae3c..91e17ff8 100644 --- a/usr/local/share/bastille/clone.sh +++ b/usr/local/share/bastille/clone.sh @@ -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 diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index 88a87eb8..31099029 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -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 } diff --git a/usr/local/share/bastille/rename.sh b/usr/local/share/bastille/rename.sh index 744ccbe8..dc039fec 100644 --- a/usr/local/share/bastille/rename.sh +++ b/usr/local/share/bastille/rename.sh @@ -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 }