Skip to content

Commit

Permalink
[MDEV-7978] Update grammar for new syntax
Browse files Browse the repository at this point in the history
Extend the syntax accepted by the grammar to account for the new create user
and alter user syntax.
  • Loading branch information
cvicentiu authored and grooverdan committed Sep 20, 2020
1 parent 873cc1e commit c169838
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
1 change: 1 addition & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3676,6 +3676,7 @@ SHOW_VAR com_status_vars[]= {
{"alter_server", STMT_STATUS(SQLCOM_ALTER_SERVER)},
{"alter_table", STMT_STATUS(SQLCOM_ALTER_TABLE)},
{"alter_tablespace", STMT_STATUS(SQLCOM_ALTER_TABLESPACE)},
{"alter_user", STMT_STATUS(SQLCOM_ALTER_USER)},
{"analyze", STMT_STATUS(SQLCOM_ANALYZE)},
{"assign_to_keycache", STMT_STATUS(SQLCOM_ASSIGN_TO_KEYCACHE)},
{"begin", STMT_STATUS(SQLCOM_BEGIN)},
Expand Down
1 change: 1 addition & 0 deletions sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_CREATE_USER:
case SQLCOM_CREATE_ROLE:
case SQLCOM_ALTER_TABLE:
case SQLCOM_ALTER_USER:
case SQLCOM_GRANT:
case SQLCOM_GRANT_ROLE:
case SQLCOM_REVOKE:
Expand Down
20 changes: 20 additions & 0 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9840,6 +9840,26 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
DBUG_RETURN(result);
}

/*
Alter a user's connection and resource settings.

SYNOPSIS
mysql_alter_user()
thd The current thread.
list The users to alter.

RETURN
> 0 Error. Error message already sent.
0 OK.
< 0 Error. Error message not yet sent.
*/
int mysql_alter_user(THD* thd, List<LEX_USER> &users_list)
{
DBUG_ENTER("mysql_alter_user");
int result= 0;
// TODO implement the alter user logic.
DBUG_RETURN(result);
}

/*
Revoke all privileges from a list of users.
Expand Down
1 change: 1 addition & 0 deletions sql/sql_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ void get_mqh(const char *user, const char *host, USER_CONN *uc);
bool mysql_create_user(THD *thd, List <LEX_USER> &list, bool handle_as_role);
bool mysql_drop_user(THD *thd, List <LEX_USER> &list, bool handle_as_role);
bool mysql_rename_user(THD *thd, List <LEX_USER> &list);
int mysql_alter_user(THD *thd, List <LEX_USER> &list);
bool mysql_revoke_all(THD *thd, List <LEX_USER> &list);
void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
const char *db, const char *table);
Expand Down
1 change: 1 addition & 0 deletions sql/sql_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum enum_sql_command {
SQLCOM_CREATE_ROLE, SQLCOM_DROP_ROLE, SQLCOM_GRANT_ROLE, SQLCOM_REVOKE_ROLE,
SQLCOM_COMPOUND,
SQLCOM_SHOW_GENERIC,
SQLCOM_ALTER_USER,

/*
When a command is added here, be sure it's also added in mysqld.cc
Expand Down
10 changes: 9 additions & 1 deletion sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_CREATE_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_RENAME_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_ALTER_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_ROLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_GRANT]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_GRANT_ROLE]= CF_CHANGES_DATA;
Expand Down Expand Up @@ -506,6 +507,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_CHECKSUM]= CF_REPORT_PROGRESS;

sql_command_flags[SQLCOM_CREATE_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RENAME_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_ROLE]|= CF_AUTO_COMMIT_TRANS;
Expand Down Expand Up @@ -601,6 +603,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_ALTER_EVENT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_EVENT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_RENAME_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_SERVER]|= CF_DISALLOW_IN_RO_TRANS;
Expand Down Expand Up @@ -4403,14 +4406,19 @@ mysql_execute_command(THD *thd)
my_ok(thd);
break;
}
case SQLCOM_ALTER_USER:
case SQLCOM_RENAME_USER:
{
if (check_access(thd, UPDATE_ACL, "mysql", NULL, NULL, 1, 1) &&
check_global_access(thd,CREATE_USER_ACL))
break;
/* Conditionally writes to binlog */
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
if (!(res= mysql_rename_user(thd, lex->users_list)))
if (lex->sql_command == SQLCOM_ALTER_USER)
res= mysql_alter_user(thd, lex->users_list);
else
res= mysql_rename_user(thd, lex->users_list);
if (!res)
my_ok(thd);
break;
}
Expand Down
59 changes: 40 additions & 19 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,8 @@ create:
Lex->create_view_suid= TRUE;
}
view_or_trigger_or_sp_or_event { }
| create_or_replace USER_SYM opt_if_not_exists clear_privileges grant_list
| create_or_replace USER opt_if_not_exists clear_privileges grant_list
require_clause resource_options
{
if (Lex->set_command_with_check(SQLCOM_CREATE_USER, $1 | $3))
MYSQL_YYABORT;
Expand Down Expand Up @@ -7106,6 +7107,11 @@ alter:
lex->sql_command= SQLCOM_ALTER_SERVER;
lex->server_options.reset($3);
} OPTIONS_SYM '(' server_options_list ')' { }
| ALTER opt_if_exists USER clear_privileges user_list
require_clause resource_options
{
Lex->sql_command= SQLCOM_ALTER_USER;
}
;

ev_alter_on_schedule_completion:
Expand Down Expand Up @@ -15412,24 +15418,8 @@ require_clause:
}
;

grant_options:
/* empty */ {}
| WITH grant_option_list
;

opt_grant_option:
/* empty */ {}
| WITH GRANT OPTION { Lex->grant |= GRANT_ACL;}
;

grant_option_list:
grant_option_list grant_option {}
| grant_option {}
;

grant_option:
GRANT OPTION { Lex->grant |= GRANT_ACL;}
| MAX_QUERIES_PER_HOUR ulong_num
resource_option:
MAX_QUERIES_PER_HOUR ulong_num
{
LEX *lex=Lex;
lex->mqh.questions=$2;
Expand Down Expand Up @@ -15461,6 +15451,37 @@ grant_option:
}
;

resource_option_list:
resource_option_list resource_option {}
| resource_option {}
;

resource_options:
/* empty */ {}
| WITH resource_option_list
;


grant_options:
/* empty */ {}
| WITH grant_option_list {}
;

opt_grant_option:
/* empty */ {}
| WITH GRANT OPTION { Lex->grant |= GRANT_ACL;}
;

grant_option_list:
grant_option_list grant_option {}
| grant_option {}
;

grant_option:
GRANT OPTION { Lex->grant |= GRANT_ACL;}
| resource_option {}
;

begin:
BEGIN_SYM
{
Expand Down

0 comments on commit c169838

Please sign in to comment.