diff options
author | msvensson@neptunus.(none) <> | 2005-12-28 14:43:50 +0100 |
---|---|---|
committer | msvensson@neptunus.(none) <> | 2005-12-28 14:43:50 +0100 |
commit | e1ef24e38ce6426688a5f4ca69bfc5426ce39f9a (patch) | |
tree | f891877391b5a4f69beae6e995d17807b88578bc /sql | |
parent | cdd1f5c6fcb31ca8fd70d7fcade824deb1109dde (diff) | |
download | mariadb-git-e1ef24e38ce6426688a5f4ca69bfc5426ce39f9a.tar.gz |
Bug #15775 "drop user" command does not refresh acl_check_hosts
- Update patch for 5.0
- Added common function to be called when 'acl_users' has been modified
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_acl.cc | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index cd83efcac2c..110b529fffc 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -68,6 +68,7 @@ static ulong get_access(TABLE *form,uint fieldnr, uint *next_field=0); static int acl_compare(ACL_ACCESS *a,ACL_ACCESS *b); static ulong get_sort(uint count,...); static void init_check_host(void); +static void rebuild_check_host(void); static ACL_USER *find_acl_user(const char *host, const char *user, my_bool exact); static bool update_user_table(THD *thd, TABLE *table, @@ -1095,10 +1096,8 @@ static void acl_insert_user(const char *user, const char *host, qsort((gptr) dynamic_element(&acl_users,0,ACL_USER*),acl_users.elements, sizeof(ACL_USER),(qsort_cmp) acl_compare); - /* We must free acl_check_hosts as its memory is mapped to acl_user */ - delete_dynamic(&acl_wild_hosts); - hash_free(&acl_check_hosts); - init_check_host(); + /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ + rebuild_check_host(); } @@ -1283,7 +1282,7 @@ static void init_check_host(void) if (j == acl_wild_hosts.elements) // If new (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))) { if (my_hash_insert(&acl_check_hosts,(byte*) acl_user)) @@ -1300,6 +1299,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 */ bool acl_check_host(const char *host, const char *ip) @@ -5241,6 +5256,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)); rw_unlock(&LOCK_grant); close_thread_tables(thd); @@ -5265,7 +5283,7 @@ bool mysql_drop_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; LEX_USER *user_from; LEX_USER *user_to; @@ -5297,6 +5315,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)); rw_unlock(&LOCK_grant); close_thread_tables(thd); |