Commit 8f2144e2 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Check if user exists before changing password

Check if a user exists before assigning a password in ChangePassword
task.
parent fdc3b4da
......@@ -75,9 +75,15 @@ netbsd_change_shadow_entry() {
}
windows_password() {
local target password
local target password sam names namespace wcm xpath unattend
target="$1"
password="$2"
sam="$target/windows/system32/config/sam"
if [ ! -f "$sam" ]; then
log_error "SAM file: $sam is missing"
fi
echo "@echo off" > "$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
......@@ -88,7 +94,25 @@ windows_password() {
SNF_IMAGE_PROPERTY_USERS="Administrator"
fi
names="$($HIVEXREGEDIT --export "$sam" '\SAM\Domains\Account\Users\Names' \
| awk 'match($0, /Names\\([^\\]+)\]/, n) { print n[1]; }' )"
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = 'windows' ]; then
# Add the users that get created by the unattend.xml file
unattend="$(get_unattend "$target")"
namespace="urn:schemas-microsoft-com:unattend"
wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xpath='/x:unattend/x:settings/x:component/x:UserAccounts/'
xpath+='x:LocalAccounts/x:LocalAccount[@wcm:action="add"]/x:Name'
names+=$($XMLSTARLET sel -N x="$namespace" -N wcm="$wcm" -t -v \
"$xpath" "$unattend") || true
fi
for usr in $SNF_IMAGE_PROPERTY_USERS; do
if ! grep "$usr" >/dev/null <<< "$names"; then
log_error "User: \`$usr' does not exist."
fi
echo -n "Installing new password for user \`$usr'..."
echo "net user $usr $password /ACTIVE:YES /EXPIRES:NEVER /PASSWORDREQ:YES" >> \
"$target/Windows/SnfScripts/ChangeAdminPassword.cmd"
......@@ -148,7 +172,7 @@ unix_password() {
add_cleanup rm "$tmp_shadow"
echo -n "Setting ${users[$i]} password ... "
entry=$(grep "^${users[$i]}:" "$target${!shadow}")
entry=$(grep "^${users[$i]}:" "$target${!shadow}") || true
if [ -z "$entry" ]; then
log_error "User: \`${users[$i]}' does not exist."
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment