From 62617b89cf11da4b63b1760d50c6d3236882eb8b Mon Sep 17 00:00:00 2001 From: Culsu Date: Mon, 30 Nov 2020 22:22:36 +0100 Subject: [PATCH] added a security check for overwriting the hostname inside the jails rc.conf --- jaildk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jaildk b/jaildk index f2086ca..f2c7d7f 100755 --- a/jaildk +++ b/jaildk @@ -764,7 +764,7 @@ Create a new jail from template." jaildk_create() { jail=$1 - # $jail gets overwritten in jaildk_clone or somewhere... + # $jail gets overwritten in jaildk_clone or some subcall to .template :-( ... newjail=$jail src=.template @@ -782,11 +782,11 @@ jaildk_create() { jaildk_clone -s $src -d $jail -o $srcversion -n $newversion # some perl magic to extract the hostname (if any) from /etc/jail.conf - and write it into the jails rc.conf jailhostname=$(cat /etc/jail.conf | tr -d '\t\r\n ' | perl -ne '$_ =~ /.*'"$newjail"'(\{(?:\{.*\}|[^{])*\})|\w+/; print $1;' | grep -oE 'hostname=[^;]+' | cut -d= -f2) - echo "new name: $jailhostname" - echo "in path $j/etc/$jail/local-etc-$newversion/rc.conf" - sed -iE 's/^hostname.*$/hostname="'"$jailhostname"'"/' $j/etc/$newjail/local-etc-$newversion/rc.conf - - + if [ -n "$jailhostname" ]; then + echo "new name: $jailhostname" + echo "in path $j/etc/$jail/local-etc-$newversion/rc.conf" + sed -iE 's/^hostname.*$/hostname="'"$jailhostname"'"/' $j/etc/$newjail/local-etc-$newversion/rc.conf + fi } remove() {