diff options
-rw-r--r-- | scripts/install-system | 16 | ||||
-rwxr-xr-x | scripts/standalone_root_pw_reset | 41 |
2 files changed, 35 insertions, 22 deletions
diff --git a/scripts/install-system b/scripts/install-system index 5543fecb..d06695e0 100644 --- a/scripts/install-system +++ b/scripts/install-system @@ -840,22 +840,20 @@ change_password() { local pwd1="1" local pwd2="2" - until [ $pwd1 == $pwd2 ] + until [ "$pwd1" == "$pwd2" ] do - echo -n "Enter $user " - pwd1=$(mkpasswd -H md5) - local salt=$(echo $pwd1 | awk -F$ '{print $3}') - - echo -n "Retype $user " - pwd2=$(mkpasswd -H md5 -S $salt) + read -p "Enter $user password:" -r -s pwd1 <>/dev/tty 1>&0 + echo + read -p "Retype $user password:" -r -s pwd2 <>/dev/tty 1>&0 + echo - if [ $pwd1 != $pwd2 ] + if [ "$pwd1" != "$pwd2" ] then echo "Passwords do not match" fi done # escape any slashes in resulting password - local epwd=$(echo $pwd | sed 's:/:\\/:g') + local epwd=$(mkpasswd -H md5 "$pwd1" | sed 's:/:\\/:g') sed -i \ -e "/ user $user {/,/}/s/encrypted-password:.*\$/encrypted-password: \"$epwd\"/" \ diff --git a/scripts/standalone_root_pw_reset b/scripts/standalone_root_pw_reset index 65af7e55..f08bf7d6 100755 --- a/scripts/standalone_root_pw_reset +++ b/scripts/standalone_root_pw_reset @@ -14,7 +14,7 @@ # All Rights Reserved. # # Author: Bob Gilligan <gilligan@vyatta.com> -# Description: Standalone script to reset the root passwd to factory default +# Description: Standalone script to set the root passwd to new value # value. Note: This script can ONLY be run as a standalone # init program by grub. # @@ -23,6 +23,31 @@ # The Vyatta config file: CF=/opt/vyatta/etc/config/config.boot +change_password() { + local user=$1 + local pwd1="1" + local pwd2="2" + + until [ "$pwd1" == "$pwd2" ] + do + read -p "Enter $user password:" -r -s pwd1 <>/dev/tty 1>&0 + echo + read -p "Retype $user password:" -r -s pwd2 <>/dev/tty 1>&0 + echo + + if [ "$pwd1" != "$pwd2" ] + then echo "Passwords do not match" + fi + done + + # escape any slashes in resulting password + local epwd=$(mkpasswd -H md5 "$pwd1" | sed 's:/:\\/:g') + + sed -i \ + -e "/ user $user {/,/}/s/encrypted-password:.*\$/encrypted-password: \"$epwd\"/" \ + $CF +} + echo "Standalone root password recovery tool." echo # @@ -67,19 +92,9 @@ fi echo "Saving backup copy of config.boot..." cp $CF ${CF}.before_pwrecovery -echo "Reseting the root password..." - -# change system first -newpwd=`mkpasswd -H md5 vyatta` -usermod --password "$newpwd" root - -# escape / in encrypted passwd -pw=$(echo $newpwd | sed 's:/:\\/:g') -sed -i \ - -e "/^.* user root {/,/}/s/encrypted-password:* .*\$/encrypted-password \"$pw\"/" \ - $CF +echo "Setting the root password..." -echo $(date "+%b%e %T") $(hostname) "Root password reset to factory value" \ +echo $(date "+%b%e %T") $(hostname) "Root password changed" \ | tee -a /var/log/auth.log >>/var/log/messages sync |