Commit 437b8ebf authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Reorg the deleteuser stuff. In the perl script, watch for non-existent

accounts and do not die. Also, no longer rename the home dir; just
leave it where it is; not sure that served any purpose at all.
Also mark nodes as needing account updates (this requires that the
group_membership remain intact until after the script runs).

In the php script, also purge the sfskeys table and the new
widearea_accounts table.
parent 68afca6f
......@@ -23,14 +23,15 @@ use English;
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $CONTROL = "@USERNODE@";
my $BOSSNODE= "@BOSSNODE@";
my $HOMEDIR = "/users";
my $SSH = "$TB/bin/sshtb";
my $USERDEL = "/usr/sbin/pw userdel";
my $GENELISTS = "$TB/sbin/genelists";
my $user;
my $query_result;
my $errors = 0;
#
# We don't want to run this script unless its the real version.
......@@ -96,32 +97,26 @@ $UID = $EUID;
print "Removing user $user from local node.\n";
if (system("$USERDEL $user")) {
fatal("Could not remove user $user from local node.");
if (($? >> 8) != 67) {
print("Could not remove user $user from local node.\n");
$errors++;
}
}
print "Removing user $user from $control_node.\n";
if (system("$SSH -host $control_node '$USERDEL $user'")) {
fatal("Could not remove user $user from $control_node.\n");
if ($control_node ne $BOSSNODE) {
print "Removing user $user from $control_node.\n";
if (system("$SSH -host $control_node '$USERDEL $user'")) {
if (($? >> 8) != 67) {
print("Could not remove user $user from $control_node.\n");
$errors++;
}
}
}
#
# Rename the user directory instead of deleting it.
#
my $newname = "$HOMEDIR/$user-" . TBDateTimeFSSafe();
if (! -e "$HOMEDIR/$user") {
fatal("User directory '$HOMEDIR/$user' does not exist!");
}
if (! rename("$HOMEDIR/$user", $newname)) {
fatal("Could not rename user directory $user to $newname: $!");
}
exit(0);
sub fatal {
local($msg) = $_[0];
# Now schedule account updates on all the nodes that this person has
# an account on.
#
TBNodeUpdateAccountsByUID($user);
SENDMAIL($TBOPS, "rmacct-ctrl Failed", $msg);
die("$0: $msg");
}
exit(1);
......@@ -94,16 +94,24 @@ if (!$confirmed_twice) {
}
#
# The group membership table needs to be cleaned.
# Set the status to frozen. This prevents possible race conditions.
#
$query_result =
DBQueryFatal("delete FROM group_membership where uid='$target_uid'");
DBQueryFatal("update users set status='" . TBDB_USERSTATUS_FROZEN . "'" .
"where uid='$target_uid'");
#
# Remove the user account before killing the user entry.
# Remove the user account before killing the user entry. The side
# effect is to also set the update_accounts flag for of the nodes the
# user had access to.
#
SUEXEC($uid, $TBADMINGROUP, "rmacct-ctrl $target_uid", 0);
#
# Now it is okay to clean the group membership table.
#
$query_result =
DBQueryFatal("delete FROM group_membership where uid='$target_uid'");
#
# Then the users table,
#
......@@ -111,10 +119,18 @@ $query_result =
DBQueryFatal("delete FROM users where uid='$target_uid'");
#
# Then the pubkey table,
# Then the pubkey tables.
#
$query_result =
DBQueryFatal("delete FROM user_pubkeys where uid='$target_uid'");
$query_result =
DBQueryFatal("delete FROM user_sfskeys where uid='$target_uid'");
#
# Must do widearea_accounts too!
#
$query_result =
DBQueryFatal("delete FROM widearea_accounts where uid='$target_uid'");
#
# Warm fuzzies.
......@@ -131,7 +147,7 @@ TBUserInfo($uid, $uid_name, $uid_email);
TBMAIL($TBMAIL_OPS,
"User $target_uid removed",
"User '$target_uid' has been removed by $uid ($uid_name).\n\n".
"Please remember to remove the backup directory in /users\n\n",
"Please remember to remove the directory in /users if appropriate\n\n",
"From: $uid_name <$uid_email>\n".
"Errors-To: $TBMAIL_WWW");
......
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