Commit 272ff453 authored by unknown's avatar unknown

sql_acl.cc:

  BUG #5831 Revoke privileges in a loop until no more privileges are revoked, because acl_dbs and column_priv_hash can re-organize during privilege removal.


sql/sql_acl.cc:
  BUG #5831 Revoke privileges in a loop until no more privileges are revoked, because acl_dbs and column_priv_hash can re-organize during privilege removal.
parent 1412365a
...@@ -3623,6 +3623,14 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) ...@@ -3623,6 +3623,14 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
} }
/* Remove db access privileges */ /* Remove db access privileges */
/*
Because acl_dbs and column_priv_hash shrink and may re-order
as privileges are removed, removal occurs in a repeated loop
until no more privileges are revoked.
*/
while (1)
{
int revoke= 0;
for (counter= 0 ; counter < acl_dbs.elements ; ) for (counter= 0 ; counter < acl_dbs.elements ; )
{ {
const char *user,*host; const char *user,*host;
...@@ -3639,16 +3647,25 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) ...@@ -3639,16 +3647,25 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
if (replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1)) if (replace_db_table(tables[1].table, acl_db->db, *lex_user, ~0, 1))
result= -1; result= -1;
else else
{
revoke= 1;
continue; continue;
} }
}
++counter; ++counter;
} }
if (!revoke)
break;
}
/* Remove column access */ /* Remove column access */
while (1)
{
int revoke= 0;
for (counter= 0 ; counter < column_priv_hash.records ; ) for (counter= 0 ; counter < column_priv_hash.records ; )
{ {
const char *user,*host; const char *user,*host;
GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash, GRANT_TABLE *grant_table= (GRANT_TABLE*)hash_element(&column_priv_hash,
counter); counter);
if (!(user=grant_table->user)) if (!(user=grant_table->user))
user= ""; user= "";
...@@ -3662,9 +3679,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) ...@@ -3662,9 +3679,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
grant_table->db, grant_table->db,
grant_table->tname, grant_table->tname,
~0, 0, 1)) ~0, 0, 1))
{
result= -1; result= -1;
}
else else
{ {
if (grant_table->cols) if (grant_table->cols)
...@@ -3677,14 +3692,23 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) ...@@ -3677,14 +3692,23 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list)
~0, 1)) ~0, 1))
result= -1; result= -1;
else else
{
revoke= 1;
continue; continue;
} }
}
else else
{
revoke= 1;
continue; continue;
} }
} }
}
++counter; ++counter;
} }
if (!revoke)
break;
}
} }
VOID(pthread_mutex_unlock(&acl_cache->lock)); VOID(pthread_mutex_unlock(&acl_cache->lock));
......
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