From b4fcd1a408a46dff2fa147ff1c45416d22dfd815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Tue, 19 Jan 2016 14:30:19 +0200 Subject: [PATCH] [MDEV-7978] Updated syntax for SHOW CREATE USER --- sql/mysqld.cc | 1 + sql/sp_head.cc | 1 + sql/sql_acl.cc | 4 ++++ sql/sql_acl.h | 1 + sql/sql_cmd.h | 1 + sql/sql_parse.cc | 7 ++++++- sql/sql_yacc.yy | 12 ++++++++++++ 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 54b04cc0788..52069cf1954 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3917,6 +3917,7 @@ SHOW_VAR com_status_vars[]= { {"show_create_proc", STMT_STATUS(SQLCOM_SHOW_CREATE_PROC)}, {"show_create_table", STMT_STATUS(SQLCOM_SHOW_CREATE)}, {"show_create_trigger", STMT_STATUS(SQLCOM_SHOW_CREATE_TRIGGER)}, + {"show_create_user", STMT_STATUS(SQLCOM_SHOW_CREATE_USER)}, {"show_databases", STMT_STATUS(SQLCOM_SHOW_DATABASES)}, {"show_engine_logs", STMT_STATUS(SQLCOM_SHOW_ENGINE_LOGS)}, {"show_engine_mutex", STMT_STATUS(SQLCOM_SHOW_ENGINE_MUTEX)}, diff --git a/sql/sp_head.cc b/sql/sp_head.cc index f84d8e95ad0..c8ae0028239 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -216,6 +216,7 @@ sp_get_flags_for_command(LEX *lex) case SQLCOM_SHOW_CREATE_PROC: case SQLCOM_SHOW_CREATE_EVENT: case SQLCOM_SHOW_CREATE_TRIGGER: + case SQLCOM_SHOW_CREATE_USER: case SQLCOM_SHOW_DATABASES: case SQLCOM_SHOW_ERRORS: case SQLCOM_SHOW_EXPLAIN: diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index a5907a5d8ba..3a1b541ec46 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -7733,6 +7733,10 @@ static int show_grants_callback(ACL_USER_BASE *role, void *data) return 0; } +bool mysql_show_create_user(THD *thd, LEX_USER *lex_user) +{ + return FALSE; +} void mysql_show_grants_get_fields(THD *thd, List *fields, const char *name) diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 91ae425b88b..be206b1f86f 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -244,6 +244,7 @@ ulong get_column_grant(THD *thd, GRANT_INFO *grant, void mysql_show_grants_get_fields(THD *thd, List *fields, const char *name); bool mysql_show_grants(THD *thd, LEX_USER *user); +bool mysql_show_create_user(THD *thd, LEX_USER *user); int fill_schema_enabled_roles(THD *thd, TABLE_LIST *tables, COND *cond); int fill_schema_applicable_roles(THD *thd, TABLE_LIST *tables, COND *cond); void get_privilege_desc(char *to, uint max_length, ulong access); diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h index 5553090bb8c..92b74bb88ab 100644 --- a/sql/sql_cmd.h +++ b/sql/sql_cmd.h @@ -94,6 +94,7 @@ enum enum_sql_command { SQLCOM_COMPOUND, SQLCOM_SHOW_GENERIC, SQLCOM_ALTER_USER, + SQLCOM_SHOW_CREATE_USER, /* When a command is added here, be sure it's also added in mysqld.cc diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f1a2c760a52..53295a7ccfd 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -417,6 +417,7 @@ void init_update_queries(void) sql_command_flags[SQLCOM_SHOW_EXPLAIN]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_GRANTS]= CF_STATUS_COMMAND; + sql_command_flags[SQLCOM_SHOW_CREATE_USER]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_CREATE_DB]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_CREATE]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_MASTER_STAT]= CF_STATUS_COMMAND; @@ -4946,6 +4947,7 @@ end_with_restore_list: break; #ifndef NO_EMBEDDED_ACCESS_CHECKS + case SQLCOM_SHOW_CREATE_USER: case SQLCOM_SHOW_GRANTS: { LEX_USER *grant_user= lex->grant_user; @@ -4962,7 +4964,10 @@ end_with_restore_list: grant_user->user.str == current_user_and_current_role.str || !check_access(thd, SELECT_ACL, "mysql", NULL, NULL, 1, 0)) { - res = mysql_show_grants(thd, grant_user); + if (lex->sql_command == SQLCOM_SHOW_GRANTS) + res = mysql_show_grants(thd, grant_user); + else + res = mysql_show_create_user(thd, grant_user); } break; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d54e533e800..642767d0127 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -12774,6 +12774,18 @@ show_param: lex->sql_command= SQLCOM_SHOW_CREATE_TRIGGER; lex->spname= $3; } + | CREATE USER + { + Lex->sql_command= SQLCOM_SHOW_CREATE_USER; + if (!(Lex->grant_user= (LEX_USER*)thd->alloc(sizeof(LEX_USER)))) + MYSQL_YYABORT; + Lex->grant_user->user= current_user_and_current_role; + } + | CREATE USER user + { + Lex->sql_command= SQLCOM_SHOW_CREATE_USER; + Lex->grant_user= $3; + } | PROCEDURE_SYM STATUS_SYM wild_and_where { LEX *lex= Lex;