Skip to content

Commit

Permalink
[MDEV-7978] Updated syntax for SHOW CREATE USER
Browse files Browse the repository at this point in the history
  • Loading branch information
cvicentiu authored and grooverdan committed Sep 20, 2020
1 parent 6b6f066 commit f8b8d20
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions sql/mysqld.cc
Expand Up @@ -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)},
Expand Down
1 change: 1 addition & 0 deletions sql/sp_head.cc
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions sql/sql_acl.cc
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sql/sql_acl.h
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions sql/sql_cmd.h
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion sql/sql_parse.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -4715,14 +4716,28 @@ 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;
if (!grant_user)
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
Expand Down
12 changes: 12 additions & 0 deletions sql/sql_yacc.yy
Expand Up @@ -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;
Expand Down

0 comments on commit f8b8d20

Please sign in to comment.