From 8217d08fc0a3b65d2fa920eb6a753b217a561e77 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Mon, 3 Sep 2012 12:43:44 +0200 Subject: [PATCH] grml-hostname: reject invalid hostnames The check doesn't fully verify RFC 952, but it catches some known-problematic situations and it's better than nothing. Closes: gf-issue127 Thanks: Evgeni Golov for review --- usr_sbin/grml-hostname | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/usr_sbin/grml-hostname b/usr_sbin/grml-hostname index b529d17..b7a6eab 100755 --- a/usr_sbin/grml-hostname +++ b/usr_sbin/grml-hostname @@ -37,6 +37,20 @@ else retval=0 fi +# stupid + simplified checking for valid hostname (according to RFC 952) +VALIDATE=$(echo "$NEW_HOSTNAME" | tr --delete '[:alnum:]-') +if [ -n "$VALIDATE" ] ; then + if [ -z "$NONINTERACTIVE" ] ; then + dialog --title "${PN}" \ + --msgbox "Error: invalid characters specified in hostname: '$VALIDATE' can not be used inside hostnames." \ + 0 0 + exec "$0" + else + echo "Error: invalid characters specified in hostname: '$VALIDATE' can not be used inside hostnames." >&2 + exit 1 + fi +fi + case $retval in 0) echo "$NEW_HOSTNAME" > /etc/hostname -- 2.1.4