Commit 4a73b9ce authored by Leigh Stoller's avatar Leigh Stoller

Move chpass into an accountproxy command, rather the ssh invoking

chpass directly.
parent 59fb0036
......@@ -42,6 +42,7 @@ sub usage()
print "Usage: accountsetup adduser ...\n";
print " accountsetup deluser ...\n";
print " accountsetup moduser ...\n";
print " accountsetup chpass ...\n";
print " accountsetup addproject ...\n";
print " accountsetup addgroup ...\n";
print " accountsetup delproject ...\n";
......@@ -124,6 +125,7 @@ my @GDIRLIST = ("exp", "images", "logs", "tarfiles", "rpms", "tiplogs");
sub AddUser();
sub DeleteUser();
sub ModifyUser();
sub ChangePassword();
sub AddProject();
sub AddGroup();
sub DelProject();
......@@ -177,6 +179,10 @@ SWITCH: for ($cmd) {
ModifyUser();
last SWITCH;
};
/^chpass$/ && do {
ChangePassword();
last SWITCH;
};
/^addproject$/ && do {
AddProject();
last SWITCH;
......@@ -233,7 +239,6 @@ sub AddUser()
my $hdir = shift(@ARGV);
my $gid = shift(@ARGV);
my $shell = shift(@ARGV);
my $hash = (@ARGV ? shift(@ARGV) : undef);
if (! -d "$hdir") {
# XXX we only handle homedirs of the form /users/$user here...
......@@ -284,13 +289,6 @@ sub AddUser()
chmod(0700, "$hdir/$dir")
or fatal("Could not chmod '$hdir/$dir' to 0700: $!");
}
#
# Finally, set any initial password hash
#
if (defined($hash) &&
mysystem("$CHPASS -p '$hash' $user")) {
fatal("Could not initialize password");
}
return 0;
}
......@@ -346,6 +344,20 @@ sub ModifyUser()
return 0;
}
sub ChangePassword()
{
if (@ARGV != 2) {
fatal("chpass: Wrong number of arguments");
}
my $user = shift(@ARGV);
my $hash = shift(@ARGV);
if (mysystem("$CHPASS -p '$hash' $user")) {
fatal("Could not change password");
}
return 0;
}
#
# Usage: deactivate username
#
......
......@@ -467,7 +467,8 @@ sub AddUser()
$pswd =~ s/\*/\\\*/g;
print "Initializing user $user password on $CONTROL.\n";
if (system("$SSH -host $CONTROL $CHPASS -p '$pswd' $user")) {
if (system("$SSH -host $CONTROL ".
" \"$ACCOUNTPROXY chpass $user '$pswd'\"")) {
fatal("Could not initialize password for $user on $CONTROL!");
}
}
......@@ -678,7 +679,7 @@ sub UpdatePassword()
my $new_pswd = shift(@ARGV);
# Lets not do this if no changes.
if ($new_pswd eq $target_user->pswd()) {
if ($new_pswd eq $target_user->pswd() && !$force) {
print "Password has not changed ...\n";
return 0;
}
......@@ -752,9 +753,10 @@ sub UpdatePassword()
$UID = 0;
if ($CONTROL ne $BOSSNODE) {
print "Updating user $user password on $CONTROL.\n";
if (system("$SSH -host $CONTROL $CHPASS -p '$safe_pswd' $user")) {
fatal("Could not change password for user $user on $CONTROL!");
if (system("$SSH -host $CONTROL ".
" \"$ACCOUNTPROXY chpass $user '$safe_pswd'\"")) {
fatal("Could not change password for $user on $CONTROL!");
}
}
$UID = $SAVEUID;
......
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