summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOleksandr Kuchmystyi <o.kuchmystyi@vyos.io>2026-06-03 15:11:37 +0300
committerOleksandr Kuchmystyi <o.kuchmystyi@vyos.io>2026-06-04 13:47:11 +0300
commit1e4be728442a782e3dbfaa877104e879c9022f61 (patch)
tree1749d1230035577c34560db6f8fa5625d7b5dd86 /src
parent88dfc8cd43521ae489900fb9746c56545140df54 (diff)
downloadvyos-1x-1e4be728442a782e3dbfaa877104e879c9022f61.tar.gz
vyos-1x-1e4be728442a782e3dbfaa877104e879c9022f61.zip
password-reset: T8346: Fix password recovery when only `plaintext-password` is set
When a user account was provisioned with only `plaintext-password` (e.g. via cloud-init), the password recovery tool failed to persist the new password across reboots. On the next boot, VyOS would re-apply the `plaintext-password` from config.boot, silently overwriting the recovered encrypted password.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/system/standalone_root_pw_reset24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/system/standalone_root_pw_reset b/src/system/standalone_root_pw_reset
index 9a7da8e4c..aa712ad52 100755
--- a/src/system/standalone_root_pw_reset
+++ b/src/system/standalone_root_pw_reset
@@ -27,8 +27,23 @@ CF=/opt/vyatta/etc/config/config.boot
ADMIN=vyos
set_encrypted_password() {
- sed -i \
- -e "/ user $1 {/,/encrypted-password/s/encrypted-password .*\$/encrypted-password \"$2\"/" $3
+ local user=$1 epwd=$2 file=$3
+
+ # Check if encrypted-password exists within this specific user's block
+ if awk "/ user $user \{/{f=1} f && /encrypted-password/{found=1; exit} f && /^ }/{exit} END{exit !found}" "$file"; then
+ # Replace existing encrypted-password line
+ sed -i \
+ -e "/ user $user {/,/encrypted-password/s/encrypted-password .*\$/encrypted-password \"$epwd\"/" "$file"
+ else
+ # Insert encrypted-password after plaintext-password
+ sed -i \
+ -e "/ user $user {/,/plaintext-password/s/\(plaintext-password .*\)\$/\1\n encrypted-password \"$epwd\"/" "$file"
+ fi
+}
+
+clear_plaintext_password() {
+ sed -i \
+ -e "/ user $1 {/,/plaintext-password/s/plaintext-password .*\$/plaintext-password \"\"/" $2
}
@@ -58,6 +73,11 @@ change_password() {
# escape any slashes in resulting password
local eepwd=$(sed 's:/:\\/:g' <<< $epwd)
set_encrypted_password $user $eepwd $CF
+
+ # There is issue that 'set_encrypted_password' only handles the 'encrypted-password' line,
+ # but leaves any existing 'plaintext-password' untouched (T8346).
+ # We need to clear 'plaintext-password' for the user during the password change flow.
+ clear_plaintext_password $user $CF
}
# System is so messed up that doing anything would be a mistake