From: Michael Prokop Date: Mon, 3 Sep 2012 10:43:44 +0000 (+0200) Subject: grml-hostname: reject invalid hostnames X-Git-Tag: v2.2.0~1 X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=commitdiff_plain;h=refs%2Fheads%2Fmika%2Fvalidate_hostname 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 --- 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