From 4204a00aee04a058bfe9079d0585347230d4b05c Mon Sep 17 00:00:00 2001 From: xSmurf Date: Wed, 30 Sep 2015 20:01:49 +0000 Subject: [PATCH] Fixed hostname-spoof bugs --- .../etc/init.d/S25hostname-spoof | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/board/coreboot/rootfs-additions/etc/init.d/S25hostname-spoof b/board/coreboot/rootfs-additions/etc/init.d/S25hostname-spoof index 4361a60..efbffcc 100755 --- a/board/coreboot/rootfs-additions/etc/init.d/S25hostname-spoof +++ b/board/coreboot/rootfs-additions/etc/init.d/S25hostname-spoof @@ -20,17 +20,21 @@ do_start() { # Make sure that our selected hostname doesn't appear anywhere in /etc, # this way it should be safe to sed the whole directory # we aren't doing this, but it could be useful in the future. -# NOTFOUND=0 -# until [ "${NOTFOUND}" -gt "0" ]; do -# #WORD=$(/usr/bin/shuf -n1 "$FILE") -# WORD=$(/usr/bin/openssl rand -hex 8) -# -# /bin/fgrep -r $WORD /etc/ 2>&1 >> /dev/null -# NOTFOUND=$? -# done - WORD=$(/usr/bin/openssl rand -hex 8) - - echo "Setting hostname to '$HOSTNAME'" + NOTFOUND=0 + until [ "${NOTFOUND}" -gt "0" ]; do + #WORD=$(/usr/bin/shuf -n1 "$FILE") + WORD=$(/usr/bin/openssl rand -hex 8) + ES=$? + if [ $ES -gt 0 ]; then + echo "Error getting random hostname!" + exit $ES + fi + + /bin/fgrep -r $WORD /etc/ 2>&1 >> /dev/null + NOTFOUND=$? + done + + echo "Setting hostname to '$WORD'" /bin/hostname $WORD @@ -39,7 +43,7 @@ do_start() { echo "$WORD" > /etc/hostname echo "$OLDHOST" > /etc/hostname.old - #/bin/sed -i "s/${OLDHOST}/${WORD}/g" /etc/hosts + /bin/sed -i "s/${OLDHOST}/${WORD}/g" /etc/hosts exit $ES }