TT#103250 change helper user behaviour

* set_user_protected_password() is renamed to
  create_protected_user() to better match its purpose
* the temporary user to help with grants is now created only once
  and dropped when the script finishes

Change-Id: I30755617859f43fa6c1acd68f46d473c495a36b8
mr9.2
Kirill Solomko 5 years ago
parent 1e5d4c683c
commit 03d83a5785

@ -195,7 +195,7 @@ sub apply_grants {
}
}
if ($new_user && !$check_only) {
set_user_protected_password($user, $host);
create_protected_user($user, $host);
}
} else {
die "Unparsable grants structure elemenent: $key";
@ -283,7 +283,7 @@ SQL
return $rc;
}
sub set_user_protected_password {
sub create_protected_user {
my ($user, $host) = @_;
my ($random_pass) = $dbh->selectrow_array("SELECT PASSWORD(?)",
undef, pwgen());
@ -331,7 +331,6 @@ sub grants_helper {
my $user = $TEMP_GRANT_USER;
my $host = $TEMP_GRANT_HOST;
set_user_protected_password($user, $host);
$dbh->do("REVOKE ALL PRIVILEGES, GRANT OPTION FROM '$user'\@'$host'");
foreach my $grant (@$grants) {
@ -360,9 +359,6 @@ sub grants_helper {
die "Error in checking grants" if $#$temp_grants < 0;
$dbh->do("DROP USER '$user'\@'$host'");
die "Cannot drop grant temp user: $DBI::errstr\n" if $DBI::err;
@$grants = ( map { $_->[0] } @$temp_grants );
return;
@ -472,6 +468,9 @@ sub main {
eval {
my $rc = 0;
create_protected_user($TEMP_GRANT_USER, $TEMP_GRANT_HOST);
foreach my $proc (@{$grants->{order}}) {
SWITCH: for ($proc) {
/^drop$/ && do {
@ -488,6 +487,9 @@ sub main {
} # SWITCH
}
$dbh->do("DROP USER IF EXISTS '$TEMP_GRANT_USER'\@'$TEMP_GRANT_HOST'");
die "Cannot drop temp user: $DBI::errstr\n" if $DBI::err;
if ($rc) {
flush_privs();
}

Loading…
Cancel
Save