List:Commits« Previous MessageNext Message »
From:Chad MILLER Date:February 22 2008 3:44pm
Subject:bk commit into 5.1 tree (cmiller:1.2525)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of cmiller.  When cmiller 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@stripped, 2008-02-22 10:44:00-05:00, cmiller@stripped +3 -0
  Accomodate Kostja's suggestions.  Use an error handler to mutate
  errors into messages.

  mysql-test/r/drop.result@stripped, 2008-02-22 10:43:57-05:00, cmiller@stripped +5 -0
    Add new warnings that are raised because we no longer pretend some
    warnings/errors are not errors.

  mysql-test/t/drop.test@stripped, 2008-02-22 10:43:57-05:00, cmiller@stripped +1 -0
    Clean up after ourselves.

  sql/sql_acl.cc@stripped, 2008-02-22 10:43:57-05:00, cmiller@stripped +67 -49
    Rip out hacky conditions and instead push a new handler onto the 
    error-handler stack.

diff -Nrup a/mysql-test/r/drop.result b/mysql-test/r/drop.result
--- a/mysql-test/r/drop.result	2008-02-21 13:56:09 -05:00
+++ b/mysql-test/r/drop.result	2008-02-22 10:43:57 -05:00
@@ -131,12 +131,17 @@ dbbug33464	fn2	FUNCTION	userbug33464@loc
 DROP FUNCTION fn1;
 Warnings:
 Warning	1403	There is no such grant defined for user 'userbug33464' on host 'localhost' on routine 'fn1'
+Warning	1269	Can't revoke all privileges for one or more of the requested users
+Warning	1405	Failed to revoke all privileges to dropped routine
 DROP FUNCTION fn2;
 Warnings:
 Warning	1403	There is no such grant defined for user 'userbug33464' on host 'localhost' on routine 'fn2'
+Warning	1269	Can't revoke all privileges for one or more of the requested users
+Warning	1405	Failed to revoke all privileges to dropped routine
 DROP PROCEDURE sp3;
 DROP USER 'userbug33464'@'localhost';
 SHOW FUNCTION STATUS WHERE DEFINER='userbug33464@localhost';
 Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
 use test;
+DROP DATABASE dbbug33464;
 End of 5.1 tests
diff -Nrup a/mysql-test/t/drop.test b/mysql-test/t/drop.test
--- a/mysql-test/t/drop.test	2008-02-21 13:55:39 -05:00
+++ b/mysql-test/t/drop.test	2008-02-22 10:43:57 -05:00
@@ -201,5 +201,6 @@ DROP USER 'userbug33464'@'localhost';
 SHOW FUNCTION STATUS WHERE DEFINER='userbug33464@localhost';
 
 use test;
+DROP DATABASE dbbug33464;
 
 --echo End of 5.1 tests
diff -Nrup a/sql/sql_acl.cc b/sql/sql_acl.cc
--- a/sql/sql_acl.cc	2008-02-21 13:56:28 -05:00
+++ b/sql/sql_acl.cc	2008-02-22 10:43:57 -05:00
@@ -2781,8 +2781,7 @@ table_error:
 
 /**
   @retval       0  success
-  @retval      -1  error, and message emitted
-  @retval myerrno  error, and message not emitted
+  @retval      -1  error
 */
 static int replace_routine_table(THD *thd, GRANT_NAME *grant_name,
 			      TABLE *table, const LEX_USER &combo,
@@ -2842,8 +2841,9 @@ static int replace_routine_table(THD *th
     */
     if (revoke_grant)
     { // no row, no revoke
-      /* Callers differ in whether this is dire.  Let caller decide. */
-      DBUG_RETURN(ER_NONEXISTING_PROC_GRANT);
+      my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
+               combo.user.str, combo.host.str, routine_name);
+      DBUG_RETURN(-1);
     }
     old_row_exists= 0;
     restore_record(table,record[1]);			// Get saved record
@@ -3328,20 +3328,11 @@ bool mysql_routine_grant(THD *thd, TABLE
       my_hash_insert(is_proc ? &proc_priv_hash : &func_priv_hash,(uchar*) grant_name);
     }
 
-    int returned_myerrno;
-    if ((returned_myerrno= replace_routine_table(thd, grant_name, 
-                                                 tables[1].table, *Str,
+    if (replace_routine_table(thd, grant_name, tables[1].table, *Str,
                                                  db_name, table_name, 
                                                  is_proc, rights, 
-                                                 revoke_grant)) != 0)
+                                                 revoke_grant) != 0)
     {
-
-      if (returned_myerrno == ER_NONEXISTING_PROC_GRANT)
-        my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
-                 Str->user.str, Str->host.str, table_name);
-      else
-        DBUG_ASSERT(returned_myerrno == -1);
-
       result= TRUE;
       continue;
     }
@@ -5968,24 +5959,14 @@ bool mysql_revoke_all(THD *thd,  List <L
 	if (!strcmp(lex_user->user.str,user) &&
             !strcmp(lex_user->host.str, host))
 	{
-          int returned_myerrno;
-	  returned_myerrno= replace_routine_table(thd,grant_proc,tables[4].table,*lex_user,
+	  if (replace_routine_table(thd,grant_proc,tables[4].table,*lex_user,
 				  grant_proc->db,
 				  grant_proc->tname,
                                   is_proc,
-				  ~(ulong)0, 1);
-	  if (returned_myerrno == 0)
+				  ~(ulong)0, 1) == 0)
 	  {
 	    revoked= 1;
 	    continue;
-	  }
-          else
-          {
-            if (returned_myerrno == ER_NONEXISTING_PROC_GRANT)
-              my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
-                       lex_user->user.str, lex_user->host.str, grant_proc->tname);
-            else
-              DBUG_ASSERT(returned_myerrno == -1);
           }
 	  result= -1;	// Something went wrong
 	}
@@ -6008,17 +5989,63 @@ bool mysql_revoke_all(THD *thd,  List <L
 }
 
 
-/*
-  Revoke privileges for all users on a stored procedure
 
-  SYNOPSIS
-    sp_revoke_privileges()
+
+/**
+  Silence all errors and warnings reported when performing a write
+  to a log table.
+  Errors and warnings are not reported to the client or SQL exception
+  handlers, so that the presence of logging does not interfere and affect
+  the logic of an application.
+*/
+class Silence_routine_definer_errors : public Internal_error_handler
+{
+public:
+  Silence_routine_definer_errors()
+  {}
+
+  virtual ~Silence_routine_definer_errors() {}
+
+  virtual bool handle_error(uint sql_errno, const char *message,
+                            MYSQL_ERROR::enum_warning_level level,
+                            THD *thd);
+};
+
+bool
+Silence_routine_definer_errors::handle_error(uint sql_errno,
+                                       const char *message,
+                                       MYSQL_ERROR::enum_warning_level level,
+                                       THD *thd)
+{
+  if (level == MYSQL_ERROR::WARN_LEVEL_ERROR)
+  {
+    switch (sql_errno)
+    {
+      case ER_NONEXISTING_PROC_GRANT:
+      case ER_REVOKE_GRANTS:
+        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, sql_errno, message);
+        return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
+
+/**
+  Revoke privileges for all users on a stored procedure.  Use an error handler
+  that converts errors about missing grants into warnings.
+
+  @param
     thd                         The current thread.
+  @param
     db				DB of the stored procedure
+  @param
     name			Name of the stored procedure
 
-  RETURN
+  @retval
     0           OK.
+  @retval
     < 0         Error. Error message not yet sent.
 */
 
@@ -6029,11 +6056,15 @@ bool sp_revoke_privileges(THD *thd, cons
   int result;
   TABLE_LIST tables[GRANT_TABLES];
   HASH *hash= is_proc ? &proc_priv_hash : &func_priv_hash;
+  Silence_routine_definer_errors error_handler;
   DBUG_ENTER("sp_revoke_privileges");
 
   if ((result= open_grant_tables(thd, tables)))
     DBUG_RETURN(result != 1);
 
+  /* Be sure to pop this before exiting this scope! */
+  thd->push_internal_handler(&error_handler);
+
   rw_wrlock(&LOCK_grant);
   VOID(pthread_mutex_lock(&acl_cache->lock));
 
@@ -6061,29 +6092,15 @@ bool sp_revoke_privileges(THD *thd, cons
 	lex_user.host.length= grant_proc->host.hostname ?
 	  strlen(grant_proc->host.hostname) : 0;
 
-        int returned_myerrno;
-	returned_myerrno= replace_routine_table(thd,grant_proc,tables[4].table,lex_user,
-				   grant_proc->db, grant_proc->tname,
-                                   is_proc, ~(ulong)0, 1);
-
-        /* Make sure replace_routine_table returns something we know about. */
-        if (returned_myerrno == 0)
+	if (replace_routine_table(thd,grant_proc,tables[4].table,lex_user,
+				  grant_proc->db, grant_proc->tname,
+                                  is_proc, ~(ulong)0, 1) == 0)
         {
 	  revoked= 1;
 	  continue;
         }
-        else if (returned_myerrno == ER_NONEXISTING_PROC_GRANT)
-        { 
-          /* It is not an error to lack the defining user of this routine.  */
-          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                              ER_NONEXISTING_PROC_GRANT, ER(ER_NONEXISTING_PROC_GRANT),
-                              lex_user.user.str, lex_user.host.str, grant_proc->tname);
-        } 
         else
-        {
-          DBUG_ASSERT(returned_myerrno == -1);
           result= -1;	// Something went wrong
-        }
       }
       counter++;
     }
@@ -6096,6 +6113,7 @@ bool sp_revoke_privileges(THD *thd, cons
   if (result)
     my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0));
 
+  thd->pop_internal_handler();
   DBUG_RETURN(result);
 }
 
Thread
bk commit into 5.1 tree (cmiller:1.2525)Chad MILLER22 Feb