summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
authorunknown <Li-Bing.Song@sun.com>2010-07-04 12:02:49 +0800
committerunknown <Li-Bing.Song@sun.com>2010-07-04 12:02:49 +0800
commit1a17d7e8079b4cbda51c311eceaea38b407556f3 (patch)
treee29404dd23f7c3255cc11c86d95218797aaac0d3 /sql/sql_class.cc
parent85d281737f0feccbd43d7f025658d260d340dd84 (diff)
downloadmariadb-git-1a17d7e8079b4cbda51c311eceaea38b407556f3.tar.gz
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() EVENTbut, 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, session's user will be written into query log events if these statements call CURREN_USER() or 'ALTER EVENT' does not assign a definer. mysql-test/include/diff_tables.inc: Expend its abilities. Now it can diff not only in sessions of 'master' and 'slave', but other sessions as well. sql/log_event.cc: session's user will be written into Query_log_event, if is_current_user_used() is TRUE. On slave SQL thread, Only thd->invoker is written into Query_log_event, if it exists. sql/sql_acl.cc: On slave SQL thread, grantor should copy from thd->invoker, if it exists sql/sql_class.h: On slave SQL thread, thd->invoker is used to store the applying event's invoker.
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 93aa6a8268c..2ce03708a9a 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -736,6 +736,9 @@ THD::THD()
thr_lock_owner_init(&main_lock_id, &lock_info);
m_internal_handler= NULL;
+ current_user_used= FALSE;
+ memset(&invoker_user, 0, sizeof(invoker_user));
+ memset(&invoker_host, 0, sizeof(invoker_host));
}
@@ -1236,6 +1239,7 @@ void THD::cleanup_after_query()
where= THD::DEFAULT_WHERE;
/* reset table map for multi-table update */
table_map_for_update= 0;
+ clean_current_user_used();
}
@@ -3267,6 +3271,22 @@ void THD::set_query(char *query_arg, uint32 query_length_arg)
pthread_mutex_unlock(&LOCK_thd_data);
}
+void THD::get_definer(LEX_USER *definer)
+{
+ set_current_user_used();
+#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+ if (slave_thread && has_invoker())
+ {
+ definer->user = invoker_user;
+ definer->host= invoker_host;
+ definer->password.str= NULL;
+ definer->password.length= 0;
+ }
+ else
+#endif
+ get_default_definer(this, definer);
+}
+
/**
Mark transaction to rollback and mark error as fatal to a sub-statement.