From 6327adebcb125b534262ac885e1cf6a5e5896d91 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 13 Jul 2006 12:19:01 +0200 Subject: WL #3337 (Event scheduler new architecture) move back THD::change_security_context to event_change_security_context sql/event_data_objects.cc: move THD::change_security_context to event_change_security_context sql/sql_class.cc: move THD::change_security_context to event_change_security_context sql/sql_class.h: move THD::change_security_context to event_change_security_context --- sql/event_data_objects.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++--- sql/sql_class.cc | 58 --------------------------------------- sql/sql_class.h | 7 ----- 3 files changed, 65 insertions(+), 69 deletions(-) diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index a367e058f0e..8d990def32d 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -25,6 +25,65 @@ #define EVEX_MAX_INTERVAL_VALUE 1000000000L +/* + Switches the security context + SYNOPSIS + event_change_security_context() + thd Thread + user The user + host The host of the user + db The schema for which the security_ctx will be loaded + backup Where to store the old context + + RETURN VALUE + FALSE OK + TRUE Error (generates error too) +*/ + +static bool +event_change_security_context(THD *thd, LEX_STRING user, LEX_STRING host, + LEX_STRING db, Security_context *backup) +{ + DBUG_ENTER("event_change_security_context"); + DBUG_PRINT("info",("%s@%s@%s", user.str, host.str, db.str)); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + + *backup= thd->main_security_ctx; + if (acl_getroot_no_password(&thd->main_security_ctx, user.str, host.str, + host.str, db.str)) + { + my_error(ER_NO_SUCH_USER, MYF(0), user.str, host.str); + DBUG_RETURN(TRUE); + } + thd->security_ctx= &thd->main_security_ctx; +#endif + DBUG_RETURN(FALSE); +} + + +/* + Restores the security context + SYNOPSIS + event_restore_security_context() + thd Thread + backup Context to switch to +*/ + +static void +event_restore_security_context(THD *thd, Security_context *backup) +{ + DBUG_ENTER("event_restore_security_context"); +#ifndef NO_EMBEDDED_ACCESS_CHECKS + if (backup) + { + thd->main_security_ctx= *backup; + thd->security_ctx= &thd->main_security_ctx; + } +#endif + DBUG_VOID_RETURN; +} + + /* Returns a new instance @@ -1686,7 +1745,8 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root) thd->query_length= show_create.length(); DBUG_PRINT("info", ("query:%s",thd->query)); - thd->change_security_context(definer_user, definer_host, dbname, &save_ctx); + event_change_security_context(thd, definer_user, definer_host, dbname, + &save_ctx); thd->lex= &lex; mysql_init_query(thd, (uchar*) thd->query, thd->query_length); if (MYSQLparse((void *)thd) || thd->is_fatal_error) @@ -1717,7 +1777,7 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root) done: lex_end(&lex); - thd->restore_security_context(&save_ctx); + event_restore_security_context(thd, &save_ctx); DBUG_PRINT("note", ("return old data on its place. set back NAMES")); thd->lex= old_lex; @@ -1765,7 +1825,8 @@ Event_job_data::execute(THD *thd) if ((ret= compile(thd, NULL))) goto done; - thd->change_security_context(definer_user, definer_host, dbname, &save_ctx); + event_change_security_context(thd, definer_user, definer_host, dbname, + &save_ctx); /* THD::~THD will clean this or if there is DROP DATABASE in the SP then it will be free there. It should not point to our buffer which is allocated @@ -1790,7 +1851,7 @@ Event_job_data::execute(THD *thd) ret= -99; } - thd->restore_security_context(&save_ctx); + event_restore_security_context(thd, &save_ctx); done: thd->end_statement(); thd->cleanup_after_query(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6ce5a8fa01d..1b41a6d1aca 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2068,64 +2068,6 @@ bool Security_context::set_user(char *user_arg) return user == 0; } -/* - Switches the security context - SYNOPSIS - THD::change_security_context() - user The user - host The host of the user - db The schema for which the security_ctx will be loaded - s_ctx Security context to load state into - backup Where to store the old context - - RETURN VALUE - FALSE OK - TRUE Error (generates error too) -*/ - -bool -THD::change_security_context(LEX_STRING user, LEX_STRING host, - LEX_STRING db, Security_context *backup) -{ - DBUG_ENTER("change_security_context"); - DBUG_PRINT("info",("%s@%s@%s", user.str, host.str, db.str)); -#ifndef NO_EMBEDDED_ACCESS_CHECKS - - *backup= main_security_ctx; - if (acl_getroot_no_password(&main_security_ctx, user.str, host.str, host.str, - db.str)) - { - my_error(ER_NO_SUCH_USER, MYF(0), user.str, host.str); - DBUG_RETURN(TRUE); - } - security_ctx= &main_security_ctx; -#endif - DBUG_RETURN(FALSE); -} - - -/* - Restores the security context - SYNOPSIS - restore_security_context() - thd Thread - backup Context to switch to -*/ - -void -THD::restore_security_context(Security_context *backup) -{ - DBUG_ENTER("restore_security_context"); -#ifndef NO_EMBEDDED_ACCESS_CHECKS - if (backup) - { - main_security_ctx= *backup; - security_ctx= &main_security_ctx; - } -#endif - DBUG_VOID_RETURN; -} - /**************************************************************************** Handling of open and locked tables states. diff --git a/sql/sql_class.h b/sql/sql_class.h index 1283f55cea6..b79f0753603 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -868,13 +868,6 @@ public: char *db, *catalog; Security_context main_security_ctx; Security_context *security_ctx; - - bool - change_security_context(LEX_STRING user, LEX_STRING host, - LEX_STRING db, Security_context *backup); - - void - restore_security_context(Security_context *backup); /* remote (peer) port */ uint16 peer_port; -- cgit v1.2.1