mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 00:51:29 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# Customizes a Chrome OS release image by setting the chronos user password.
|
||||
|
||||
# Usage: ./set_chronos_password.sh <image.bin> <chronos_password>
|
||||
# Usage: ./set_chronos_password.sh <image.bin> <chronos_password> [--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 <image.bin> <chronos_password>"
|
||||
if [ $# -ne 2 ] && [ $# -ne 3 ] || [ ! $3 = "--force" ] ; then
|
||||
echo "Usage: $PROG <image.bin> <chronos_password> [--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 $@
|
||||
|
||||
Reference in New Issue
Block a user