From 45f9247be9df55a4e25e15c3bd87b4f940a2a6eb Mon Sep 17 00:00:00 2001 From: hackacad Date: Tue, 4 Feb 2020 09:30:03 +0100 Subject: [PATCH] Check if IP address is in use. --- usr/local/share/bastille/create.sh | 5 ++++- usr/local/share/bastille/start.sh | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index 68b36842..476931ec 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -58,7 +58,10 @@ validate_ip() { exit 1 fi done - echo -e "${COLOR_GREEN}Valid: ($ip).${COLOR_RESET}" + if ifconfig | grep -w "$ip" >/dev/null; then + echo -e "${COLOR_YELLOW}Warning: ip address already in use ($ip).${COLOR_RESET}" + else + echo -e "${COLOR_GREEN}Valid: ($ip).${COLOR_RESET}" else echo -e "${COLOR_RED}Invalid: ($ip).${COLOR_RESET}" exit 1 diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index a1f5e89b..c16e6cae 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -66,7 +66,11 @@ for _jail in ${JAILS}; do elif [ ! "$(jls name | awk "/^${_jail}$/")" ]; then echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail} - + ip=$(grep 'ip4.addr' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g') + if ifconfig | grep -w "$ip" >/dev/null; then + echo -e "${COLOR_RED}Error: IP address ($ip) already in use.${COLOR_RESET}" + exit 1 + fi ## add rctl limits if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then while read _limits; do