3 # Copyright (C) 2011 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # Provides: ChangePassword
22 # RunBefore: EnforcePersonality
23 # RunAfter: InstallUnattend
24 # Short-Description: Changes Password for specified users
28 . "@commondir@/common.sh"
30 trap task_cleanup EXIT
33 # Check if the task should be prevented from running.
40 echo "@echo off" > "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
42 if [ -z "$SNF_IMAGE_PROPERTY_USERS" ]; then
43 warn "Image property \`USERS' is missing or empty. " \
44 "Changing the password for default user: \`Administrator'."
46 SNF_IMAGE_PROPERTY_USERS="Administrator"
49 for usr in $SNF_IMAGE_PROPERTY_USERS; do
50 echo -n "Installing new password for user \`$usr'..."
51 echo "net user $usr $password" >> \
52 "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
61 local hash=$("@scriptsdir@/snf-passtohash.py" "$password")
62 if [ ! -e "$target/etc/shadow" ]; then
63 log_error "No /etc/shadow found!"
68 if [ -n "$SNF_IMAGE_PROPERTY_USERS" ]; then
69 for usr in $SNF_IMAGE_PROPERTY_USERS; do
73 warn "Image property \`USERS' is missing or empty. " \
74 "Changing the password for default user: \'root'."
78 for i in $(seq 0 1 $((${#users[@]}-1))); do
79 local tmp_shadow="$(mktemp)"
80 add_cleanup rm "$tmp_shadow"
82 echo -n "Setting ${users[$i]} password..."
83 if ! grep "^${users[$i]}:" "$target/etc/shadow" > /dev/null; then
84 log_error "User: \`${users[$i]}' does not exist."
87 echo "${users[$i]}:$hash:15103:0:99999:7:::" > "$tmp_shadow"
88 grep -v "${users[$i]}" "$target/etc/shadow" >> "$tmp_shadow"
89 cat "$tmp_shadow" > "$target/etc/shadow"
94 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
95 log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
98 if [ -z "$SNF_IMAGE_PASSWORD" ]; then
99 log_error "Password is missing"
103 SNF_IMAGE_PROPERTY_USERS=$(echo $SNF_IMAGE_PROPERTY_USERS)
105 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
106 windows_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
107 elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
108 linux_password "$SNF_IMAGE_TARGET" "$SNF_IMAGE_PASSWORD"
113 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :