summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2016-01-19 14:30:19 +0200
committerDaniel Black <daniel@mariadb.org>2020-09-20 16:09:57 +1000
commitf8b8d202bc83d3de46c89ef86333fe602e711265 (patch)
tree586fdc23859fc0c8e22e9143a56994ccaed7ea12 /sql
parent6b6f066fdd9f5f64813ded550e7dbda176ee3c82 (diff)
downloadmariadb-git-f8b8d202bc83d3de46c89ef86333fe602e711265.tar.gz
[MDEV-7978] Updated syntax for SHOW CREATE USER
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc1
-rw-r--r--sql/sp_head.cc1
-rw-r--r--sql/sql_acl.cc4
-rw-r--r--sql/sql_acl.h1
-rw-r--r--sql/sql_cmd.h1
-rw-r--r--sql/sql_parse.cc17
-rw-r--r--sql/sql_yacc.yy12
7 files changed, 36 insertions, 1 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 7e18251c670..b28cea5ac46 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3766,6 +3766,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 5749d5df18d..a27f0ef4250 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -241,6 +241,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 24f4042d2a5..74ceb611a8f 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -7811,6 +7811,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<Item> *fields,
const char *name)
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index ac6a064c7e0..b480d488bc3 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -246,6 +246,7 @@ bool get_show_user(THD *thd, LEX_USER *lex_user, const char **username,
void mysql_show_grants_get_fields(THD *thd, List<Item> *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 5c697c4cd10..2350b4be56c 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 77b6f053e79..a5837585b7d 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -422,6 +422,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;
@@ -4715,6 +4716,7 @@ mysql_execute_command(THD *thd)
break;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ case SQLCOM_SHOW_CREATE_USER:
case SQLCOM_SHOW_GRANTS:
{
LEX_USER *grant_user= lex->grant_user;
@@ -4722,7 +4724,20 @@ mysql_execute_command(THD *thd)
goto error;
WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW);
- res = mysql_show_grants(thd, grant_user);
+ if (grant_user->user.str && !strcmp(sctx->priv_user, grant_user->user.str) &&
+ grant_user->host.str && !strcmp(sctx->priv_host, grant_user->host.str))
+ grant_user->user= current_user;
+
+ if (grant_user->user.str == current_user.str ||
+ grant_user->user.str == current_role.str ||
+ grant_user->user.str == current_user_and_current_role.str ||
+ !check_access(thd, SELECT_ACL, "mysql", NULL, NULL, 1, 0))
+ {
+ if (lex->sql_command == SQLCOM_SHOW_GRANTS)
+ res = mysql_show_grants(thd, grant_user);
+ else
+ res = mysql_show_create_user(thd, grant_user);
+ }
break;
}
#endif
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index dd9f2fdf0ae..d7e4fb34005 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -12493,6 +12493,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;