List:Commits« Previous MessageNext Message »
From:msvensson Date:December 28 2005 1:43pm
Subject:bk commit into 5.0 tree (msvensson:1.1991) BUG#15775
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1991 05/12/28 14:43:50 msvensson@neptunus.(none) +3 -0
  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

  sql/sql_acl.cc
    1.186 05/12/28 14:43:44 msvensson@neptunus.(none) +27 -6
    Add new function "rebuild_check_host" that is to be called when the 'acl_users'
    list has changed.
    Call function "rebuild_check_host" from mysql_drop_user, mysql_rename_user and acl_insert_user.
    Use "acl_user->host.hostname" as key when searching the acl_check_hosts in init_check_host.

  mysql-test/t/grant2.test
    1.29 05/12/28 14:43:44 msvensson@neptunus.(none) +7 -8
    Use "create user" to avoid warnings about missing fields

  mysql-test/r/grant2.result
    1.23 05/12/28 14:43:44 msvensson@neptunus.(none) +7 -8
    Use "create user" to avoid warnings about missing fields

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/bug15775_part2/my50-bug15775_part2

--- 1.185/sql/sql_acl.cc	2005-12-28 09:31:37 +01:00
+++ 1.186/sql/sql_acl.cc	2005-12-28 14:43:44 +01:00
@@ -68,6 +68,7 @@
 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 @@
   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 @@
 	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 @@
 }
 
 
+/*
+  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 @@
     }
   }
 
+  /* 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_rename_user(THD *thd, List <LEX_USER> &list)
 {
-  int result= 0;
+  int result;
   String wrong_users;
   LEX_USER *user_from;
   LEX_USER *user_to;
@@ -5296,6 +5314,9 @@
       result= TRUE;
     }
   }
+
+  /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
+  rebuild_check_host();
 
   VOID(pthread_mutex_unlock(&acl_cache->lock));
   rw_unlock(&LOCK_grant);

--- 1.22/mysql-test/r/grant2.result	2005-12-28 09:31:37 +01:00
+++ 1.23/mysql-test/r/grant2.result	2005-12-28 14:43:44 +01:00
@@ -107,14 +107,13 @@
 flush privileges;
 drop database mysqltest;
 use test;
-insert into mysql.user (user, host) values
-('mysqltest_1', 'host1'),
-('mysqltest_2', 'host2'),
-('mysqltest_3', 'host3'),
-('mysqltest_4', 'host4'),
-('mysqltest_5', 'host5'),
-('mysqltest_6', 'host6'),
-('mysqltest_7', 'host7');
+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,

--- 1.28/mysql-test/t/grant2.test	2005-12-28 09:31:37 +01:00
+++ 1.29/mysql-test/t/grant2.test	2005-12-28 14:43:44 +01:00
@@ -161,14 +161,13 @@
 #
 
 # Create some test users
-insert into mysql.user (user, host) values
-	('mysqltest_1', 'host1'),
-	('mysqltest_2', 'host2'),
-	('mysqltest_3', 'host3'),
-	('mysqltest_4', 'host4'),
-	('mysqltest_5', 'host5'),
-	('mysqltest_6', 'host6'),
-	('mysqltest_7', 'host7');
+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
Thread
bk commit into 5.0 tree (msvensson:1.1991) BUG#15775msvensson28 Dec