Commit fef6fead authored by unknown's avatar unknown

Merge neptunus.(none):/home/msvensson/mysql/bug15775_part2/my50-bug15775_part2

into  neptunus.(none):/home/msvensson/mysql/bug15775_part2/my51-bug15775_part2


sql/sql_acl.cc:
  Auto merged
parents 2c88b639 93bedc1f
...@@ -107,6 +107,17 @@ delete from mysql.columns_priv where user like 'mysqltest\_%'; ...@@ -107,6 +107,17 @@ delete from mysql.columns_priv where user like 'mysqltest\_%';
flush privileges; flush privileges;
drop database mysqltest; drop database mysqltest;
use test; use test;
create user mysqltest_1@host1;
create user mysqltest_2@host2;
create user mysqltest_3@host3;
create user mysqltest_4@host4;
create user mysqltest_5@host5;
create user mysqltest_6@host6;
create user mysqltest_7@host7;
flush privileges;
drop user mysqltest_3@host3;
drop user mysqltest_1@host1, mysqltest_2@host2, mysqltest_4@host4,
mysqltest_5@host5, mysqltest_6@host6, mysqltest_7@host7;
set sql_mode='maxdb'; set sql_mode='maxdb';
drop table if exists t1, t2; drop table if exists t1, t2;
create table t1(c1 int); create table t1(c1 int);
......
...@@ -155,6 +155,38 @@ flush privileges; ...@@ -155,6 +155,38 @@ flush privileges;
drop database mysqltest; drop database mysqltest;
use test; use test;
#
# Bug #15775: "drop user" command does not refresh acl_check_hosts
#
# Create some test users
create user mysqltest_1@host1;
create user mysqltest_2@host2;
create user mysqltest_3@host3;
create user mysqltest_4@host4;
create user mysqltest_5@host5;
create user mysqltest_6@host6;
create user mysqltest_7@host7;
flush privileges;
# Drop one user
drop user mysqltest_3@host3;
# This connect failed before fix since the acl_check_hosts list was corrupted by the "drop user"
connect (con8,127.0.0.1,root,,test,$MASTER_MYPORT,);
disconnect con8;
connection default;
# Clean up - Drop all of the remaining users at once
drop user mysqltest_1@host1, mysqltest_2@host2, mysqltest_4@host4,
mysqltest_5@host5, mysqltest_6@host6, mysqltest_7@host7;
# Check that it's still possible to connect
connect (con9,127.0.0.1,root,,test,$MASTER_MYPORT,);
disconnect con9;
connection default;
# #
# Create and drop user # Create and drop user
# #
......
...@@ -67,6 +67,7 @@ static ulong get_access(TABLE *form,uint fieldnr, uint *next_field=0); ...@@ -67,6 +67,7 @@ static ulong get_access(TABLE *form,uint fieldnr, uint *next_field=0);
static int acl_compare(ACL_ACCESS *a,ACL_ACCESS *b); static int acl_compare(ACL_ACCESS *a,ACL_ACCESS *b);
static ulong get_sort(uint count,...); static ulong get_sort(uint count,...);
static void init_check_host(void); static void init_check_host(void);
static void rebuild_check_host(void);
static ACL_USER *find_acl_user(const char *host, const char *user, static ACL_USER *find_acl_user(const char *host, const char *user,
my_bool exact); my_bool exact);
static bool update_user_table(THD *thd, TABLE *table, static bool update_user_table(THD *thd, TABLE *table,
...@@ -1094,10 +1095,8 @@ static void acl_insert_user(const char *user, const char *host, ...@@ -1094,10 +1095,8 @@ static void acl_insert_user(const char *user, const char *host,
qsort((gptr) dynamic_element(&acl_users,0,ACL_USER*),acl_users.elements, qsort((gptr) dynamic_element(&acl_users,0,ACL_USER*),acl_users.elements,
sizeof(ACL_USER),(qsort_cmp) acl_compare); sizeof(ACL_USER),(qsort_cmp) acl_compare);
/* We must free acl_check_hosts as its memory is mapped to acl_user */ /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
delete_dynamic(&acl_wild_hosts); rebuild_check_host();
hash_free(&acl_check_hosts);
init_check_host();
} }
...@@ -1282,7 +1281,7 @@ static void init_check_host(void) ...@@ -1282,7 +1281,7 @@ static void init_check_host(void)
if (j == acl_wild_hosts.elements) // If new if (j == acl_wild_hosts.elements) // If new
(void) push_dynamic(&acl_wild_hosts,(char*) &acl_user->host); (void) push_dynamic(&acl_wild_hosts,(char*) &acl_user->host);
} }
else if (!hash_search(&acl_check_hosts,(byte*) &acl_user->host, else if (!hash_search(&acl_check_hosts,(byte*) acl_user->host.hostname,
(uint) strlen(acl_user->host.hostname))) (uint) strlen(acl_user->host.hostname)))
{ {
if (my_hash_insert(&acl_check_hosts,(byte*) acl_user)) if (my_hash_insert(&acl_check_hosts,(byte*) acl_user))
...@@ -1299,6 +1298,22 @@ static void init_check_host(void) ...@@ -1299,6 +1298,22 @@ static void init_check_host(void)
} }
/*
Rebuild lists used for checking of allowed hosts
We need to rebuild 'acl_check_hosts' and 'acl_wild_hosts' after adding,
dropping or renaming user, since they contain pointers to elements of
'acl_user' array, which are invalidated by drop operation, and use
ACL_USER::host::hostname as a key, which is changed by rename.
*/
void rebuild_check_host(void)
{
delete_dynamic(&acl_wild_hosts);
hash_free(&acl_check_hosts);
init_check_host();
}
/* Return true if there is no users that can match the given host */ /* Return true if there is no users that can match the given host */
bool acl_check_host(const char *host, const char *ip) bool acl_check_host(const char *host, const char *ip)
...@@ -5251,6 +5266,9 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) ...@@ -5251,6 +5266,9 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
} }
} }
/* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
rebuild_check_host();
VOID(pthread_mutex_unlock(&acl_cache->lock)); VOID(pthread_mutex_unlock(&acl_cache->lock));
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);
...@@ -5275,7 +5293,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) ...@@ -5275,7 +5293,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
bool mysql_rename_user(THD *thd, List <LEX_USER> &list) bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
{ {
int result= 0; int result;
String wrong_users; String wrong_users;
LEX_USER *user_from; LEX_USER *user_from;
LEX_USER *user_to; LEX_USER *user_to;
...@@ -5307,6 +5325,9 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) ...@@ -5307,6 +5325,9 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
} }
} }
/* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
rebuild_check_host();
VOID(pthread_mutex_unlock(&acl_cache->lock)); VOID(pthread_mutex_unlock(&acl_cache->lock));
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);
......
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