From a1df7cd597fb1087b678933c2bc3c5f95ed7a1ff Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 16 Jun 2014 16:48:53 +0100 Subject: Raise an error when system name is invalid This is better than proceeding to add a system with a different name to the one the user specified, without telling them that the name was mangled. --- manage-baserock | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/manage-baserock b/manage-baserock index acee510..8210812 100755 --- a/manage-baserock +++ b/manage-baserock @@ -21,9 +21,20 @@ BASEROCK_BASE="${BASEROCK_BASE:-/opt/baserock/chroots}" ACTION="$1" -SYSTEM=$(echo $2 | tr -c -d A-Za-z0-9_-.) +SYSTEM="$2" URL="$3" +check_system_name () { + local system="$1" + local valid_chars='A-Za-z0-9_-.' + case $system in + *[^${valid_chars}]*) + echo "The specified name '${system}' contains invalid characters." + echo "Valid characters are ${valid_chars}." + exit 1 + esac +} + list_baserocks () { (cd "${BASEROCK_BASE}" && ls -d */baserock) 2>/dev/null | sed -e's@/baserock$@@' } @@ -43,6 +54,8 @@ case "${ACTION}" in exec sudo "$0" "$@" fi + check_system_name $SYSTEM + if test -d "${BASEROCK_BASE}/${SYSTEM}/baserock"; then echo "Sorry, $SYSTEM already exists" exit 1 @@ -105,7 +118,7 @@ EOF fi br-ct-sync-chroots - + ;; rm) if test $(id -u) != "0"; then -- cgit v1.2.1