1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Bug #48321 CURRENT_USER() incorrectly replicated for DROP/RENAME USER;

REVOKE/GRANT; ALTER EVENT.

The following statements support the CURRENT_USER() where a user is needed.
  DROP USER 
  RENAME USER CURRENT_USER() ...
  GRANT ... TO CURRENT_USER()
  REVOKE ... FROM CURRENT_USER()
  ALTER DEFINER = CURRENT_USER() EVENT
but, When these statements are binlogged, CURRENT_USER() just is binlogged
as 'CURRENT_USER()', it is not expanded to the real user name. When slave 
executes the log event, 'CURRENT_USER()' is expand to the user of slave 
SQL thread, but SQL thread's user name always NULL. This breaks the replication.

After this patch, All above statements are rewritten when they are binlogged.
The CURRENT_USER() is expanded to the real user's name and host.
This commit is contained in:
unknown
2010-01-30 20:49:25 +08:00
parent f51a45cdbb
commit d9e9a73e8f
13 changed files with 2319 additions and 104 deletions

View File

@@ -341,31 +341,48 @@ common_1_lev_code:
}
/**
Create a new query string for removing executable comments
for avoiding leak and keeping consistency of the execution
on master and slave.
/*
Binlog '{CREATE|ALTER} EVENT' statements.
Definer part is always rewritten, for definer can be CURRENT_USER() function.
@param[in] thd Thread handler
@param[in] buf Query string
@param[in] create CREATE or ALTER statement
@return
0 ok
1 error
FASE ok
TRUE error
*/
static int
create_query_string(THD *thd, String *buf)
static bool event_write_bin_log(THD *thd, bool create)
{
/* Append the "CREATE" part of the query */
if (buf->append(STRING_WITH_LEN("CREATE ")))
return 1;
/* Append definer */
append_definer(thd, buf, &(thd->lex->definer->user), &(thd->lex->definer->host));
String log_query;
if (create)
{
/* Append the "CREATE" part of the query */
if (log_query.append(STRING_WITH_LEN("CREATE ")))
return TRUE;
}
else
{
/* Append the "ALETR " part of the query */
if (log_query.append(STRING_WITH_LEN("ALTER ")))
return TRUE;
}
/* Append definer
If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
will be written into the binary log as the definer for the SQL thread.
*/
append_definer(thd, &log_query, &(thd->lex->definer->user),
&(thd->lex->definer->host));
/* Append the left part of thd->query after "DEFINER" part */
if (buf->append(thd->lex->stmt_definition_begin))
return 1;
return 0;
if (log_query.append(thd->lex->stmt_definition_begin,
thd->lex->stmt_definition_end -
thd->lex->stmt_definition_begin))
return TRUE;
return write_bin_log(thd, TRUE, log_query.c_ptr_safe(), log_query.length())
!= 0;
}
/**
@@ -380,8 +397,7 @@ create_query_string(THD *thd, String *buf)
@sa Events::drop_event for the notes about locking, pre-locking
and Events DDL.
@retval FALSE OK
@retval TRUE Error (reported)
@retval FALSE OK @retval TRUE Error (reported)
*/
bool
@@ -465,22 +481,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
binlog the create event unless it's been successfully dropped
*/
if (!dropped)
{
/* Binlog the create event. */
DBUG_ASSERT(thd->query() && thd->query_length());
String log_query;
if (create_query_string(thd, &log_query))
{
sql_print_error("Event Error: An error occurred while creating query string, "
"before writing it into binary log.");
/* Restore the state of binlog format */
thd->current_stmt_binlog_row_based= save_binlog_row_based;
DBUG_RETURN(TRUE);
}
/* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
will be written into the binary log as the definer for the SQL thread. */
ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length());
}
ret= event_write_bin_log(thd, TRUE);
}
pthread_mutex_unlock(&LOCK_event_metadata);
/* Restore the state of binlog format */
@@ -602,9 +603,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
if (event_queue)
event_queue->update_event(thd, parse_data->dbname, parse_data->name,
new_element);
/* Binlog the alter event. */
DBUG_ASSERT(thd->query() && thd->query_length());
ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
ret= event_write_bin_log(thd, FALSE);
}
}
pthread_mutex_unlock(&LOCK_event_metadata);