From e557278cdbba0ad343b0c756db286f699b8f00ee Mon Sep 17 00:00:00 2001 From: Gaurav Shah Date: Fri, 5 Nov 2010 12:52:58 -0700 Subject: [PATCH] Refuse to change the chronos password if already set unless explicitly asked. This adds an optional --force argument which is needed if one attempts to change the password on an image where it is already set. BUG=chrome-os-partner:1460 TEST=manually tested Change-Id: I56a95fe4d699ce02c7a68e5be14cc7dce0609a54 Review URL: http://codereview.chromium.org/4480001 --- scripts/image_signing/common.sh | 7 +++++++ scripts/image_signing/set_chronos_password.sh | 20 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh index 17c01ba4bc..5a3e600b31 100755 --- a/scripts/image_signing/common.sh +++ b/scripts/image_signing/common.sh @@ -238,5 +238,12 @@ rw_mount_disabled() { return 1 } +# Check if the 'chronos' user already has a password +# ARGS: rootfs +no_chronos_password() { + local rootfs=$1 + sudo grep -q '^chronos:\*:' "$rootfs/etc/shadow" +} + trap "cleanup_temps_and_mounts" EXIT diff --git a/scripts/image_signing/set_chronos_password.sh b/scripts/image_signing/set_chronos_password.sh index ff71e45867..1319dbf5ba 100755 --- a/scripts/image_signing/set_chronos_password.sh +++ b/scripts/image_signing/set_chronos_password.sh @@ -6,7 +6,7 @@ # Customizes a Chrome OS release image by setting the chronos user password. -# Usage: ./set_chronos_password.sh +# Usage: ./set_chronos_password.sh [--force] # Load common constants and variables. . "$(dirname "$0")/common.sh" @@ -29,17 +29,25 @@ main() { local image=$1 local chronos_password=$2 - if [ $# -ne 2 ]; then - echo "Usage: $PROG " + if [ $# -ne 2 ] && [ $# -ne 3 ] || [ ! $3 = "--force" ] ; then + echo "Usage: $PROG [--force]" exit 1 fi - local rootfs=$(mktemp -d) + local rootfs=$(make_temp_dir) + if [ $# -eq 2 ]; then + mount_image_partition_ro "$image" 3 "$rootfs" + if ! no_chronos_password "$rootfs"; then + echo "Password is already set [use --force if you'd like to update it]" + exit 1 + fi + # Prepare for remounting read/write. + sudo umount -d $rootfs + fi mount_image_partition "$image" 3 "$rootfs" - trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT change_chronos_password "$rootfs" "$chronos_password" touch "$image" # Updates the image modification time. - echo "Done." + echo "Password Changed." } main $@