Commit 8c06c8c0 authored by unknown's avatar unknown

WL1368: SHOW GRANTS FOR CURRENT USER

  'SHOW GRANTS' syntax is added 
  'SHOW GRANTS FOR CURRENT_USER' syntax is added
  'SHOW GRANTS FOR CURRENT_USER()' syntax is added
 CURRENT_USER without parens in expressions(SELECT CURRENT_USER;) 


mysql-test/r/grant2.result:
  WL1368: SHOW GRANTS FOR CURRENT USER
mysql-test/r/grant_cache.result:
  WL1368: SHOW GRANTS FOR CURRENT USER
mysql-test/t/grant2.test:
  WL1368: SHOW GRANTS FOR CURRENT USER
mysql-test/t/grant_cache.test:
  WL1368: SHOW GRANTS FOR CURRENT USER
sql/lex.h:
  WL1368: SHOW GRANTS FOR CURRENT USER
sql/sql_yacc.yy:
  WL1368: SHOW GRANTS FOR CURRENT USER
parent f8b790d0
...@@ -5,6 +5,9 @@ grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option; ...@@ -5,6 +5,9 @@ grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option;
select current_user(); select current_user();
current_user() current_user()
mysqltest_1@localhost mysqltest_1@localhost
select current_user;
current_user
mysqltest_1@localhost
grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option; grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option;
grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option; grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option;
ERROR 42000: Access denied for user: 'mysqltest_1'@'localhost' to database 'my_%' ERROR 42000: Access denied for user: 'mysqltest_1'@'localhost' to database 'my_%'
......
...@@ -2,6 +2,12 @@ drop table if exists test.t1,mysqltest.t1,mysqltest.t2; ...@@ -2,6 +2,12 @@ drop table if exists test.t1,mysqltest.t1,mysqltest.t2;
drop database if exists mysqltest; drop database if exists mysqltest;
reset query cache; reset query cache;
flush status; flush status;
show grants for current_user;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
show grants;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
create database if not exists mysqltest; create database if not exists mysqltest;
create table mysqltest.t1 (a int,b int,c int); create table mysqltest.t1 (a int,b int,c int);
create table mysqltest.t2 (a int,b int,c int); create table mysqltest.t2 (a int,b int,c int);
...@@ -41,6 +47,10 @@ grant SELECT on mysqltest.* to mysqltest_1@localhost; ...@@ -41,6 +47,10 @@ grant SELECT on mysqltest.* to mysqltest_1@localhost;
grant SELECT on mysqltest.t1 to mysqltest_2@localhost; grant SELECT on mysqltest.t1 to mysqltest_2@localhost;
grant SELECT on test.t1 to mysqltest_2@localhost; grant SELECT on test.t1 to mysqltest_2@localhost;
grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost; grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost;
show grants for current_user();
Grants for mysqltest_1@localhost
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
GRANT SELECT ON `mysqltest`.* TO 'mysqltest_1'@'localhost'
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
Variable_name Value Variable_name Value
Qcache_queries_in_cache 6 Qcache_queries_in_cache 6
...@@ -101,6 +111,9 @@ Qcache_hits 3 ...@@ -101,6 +111,9 @@ Qcache_hits 3
show status like "Qcache_not_cached"; show status like "Qcache_not_cached";
Variable_name Value Variable_name Value
Qcache_not_cached 1 Qcache_not_cached 1
show grants for current_user();
Grants for @localhost
GRANT USAGE ON *.* TO ''@'localhost'
select "user2"; select "user2";
user2 user2
user2 user2
...@@ -158,6 +171,10 @@ Qcache_not_cached 7 ...@@ -158,6 +171,10 @@ Qcache_not_cached 7
select "user4"; select "user4";
user4 user4
user4 user4
show grants;
Grants for mysqltest_1@localhost
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
GRANT SELECT ON `mysqltest`.* TO 'mysqltest_1'@'localhost'
select a from t1; select a from t1;
ERROR 3D000: No Database Selected ERROR 3D000: No Database Selected
select * from mysqltest.t1,test.t1; select * from mysqltest.t1,test.t1;
......
...@@ -15,6 +15,7 @@ grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option; ...@@ -15,6 +15,7 @@ grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option;
connect (user1,localhost,mysqltest_1,,); connect (user1,localhost,mysqltest_1,,);
connection user1; connection user1;
select current_user(); select current_user();
select current_user;
grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option; grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option;
--error 1044 --error 1044
grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option; grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option;
......
...@@ -12,6 +12,8 @@ reset query cache; ...@@ -12,6 +12,8 @@ reset query cache;
flush status; flush status;
connect (root,localhost,root,,test,$MASTER_MYPORT,master.sock); connect (root,localhost,root,,test,$MASTER_MYPORT,master.sock);
connection root; connection root;
show grants for current_user;
show grants;
--disable_warnings --disable_warnings
create database if not exists mysqltest; create database if not exists mysqltest;
--enable_warnings --enable_warnings
...@@ -43,6 +45,7 @@ grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost; ...@@ -43,6 +45,7 @@ grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost;
# The following queries should be fetched from cache # The following queries should be fetched from cache
connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,master.sock); connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,master.sock);
connection user1; connection user1;
show grants for current_user();
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
show status like "Qcache_hits"; show status like "Qcache_hits";
show status like "Qcache_not_cached"; show status like "Qcache_not_cached";
...@@ -64,6 +67,10 @@ show status like "Qcache_queries_in_cache"; ...@@ -64,6 +67,10 @@ show status like "Qcache_queries_in_cache";
show status like "Qcache_hits"; show status like "Qcache_hits";
show status like "Qcache_not_cached"; show status like "Qcache_not_cached";
connect (unkuser,localhost,,,,$MASTER_MYPORT,master.sock);
connection unkuser;
show grants for current_user();
# The following queries should be fetched from cache # The following queries should be fetched from cache
connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,master.sock); connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,master.sock);
connection user2; connection user2;
...@@ -104,6 +111,7 @@ show status like "Qcache_not_cached"; ...@@ -104,6 +111,7 @@ show status like "Qcache_not_cached";
connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,master.sock); connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,master.sock);
connection user4; connection user4;
select "user4"; select "user4";
show grants;
--error 1046 --error 1046
select a from t1; select a from t1;
# The following query is not cached before (different database) # The following query is not cached before (different database)
......
...@@ -122,6 +122,7 @@ static SYMBOL symbols[] = { ...@@ -122,6 +122,7 @@ static SYMBOL symbols[] = {
{ "CURRENT_DATE", SYM(CURDATE)}, { "CURRENT_DATE", SYM(CURDATE)},
{ "CURRENT_TIME", SYM(CURTIME)}, { "CURRENT_TIME", SYM(CURTIME)},
{ "CURRENT_TIMESTAMP", SYM(NOW_SYM)}, { "CURRENT_TIMESTAMP", SYM(NOW_SYM)},
{ "CURRENT_USER", SYM(CURRENT_USER)},
{ "DATA", SYM(DATA_SYM)}, { "DATA", SYM(DATA_SYM)},
{ "DATABASE", SYM(DATABASE)}, { "DATABASE", SYM(DATABASE)},
{ "DATABASES", SYM(DATABASES)}, { "DATABASES", SYM(DATABASES)},
...@@ -481,7 +482,6 @@ static SYMBOL sql_functions[] = { ...@@ -481,7 +482,6 @@ static SYMBOL sql_functions[] = {
{ "CAST", SYM(CAST_SYM)}, { "CAST", SYM(CAST_SYM)},
{ "CEIL", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)}, { "CEIL", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "CEILING", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)}, { "CEILING", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ceiling)},
{ "CURRENT_USER", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_current_user)},
{ "BIT_LENGTH", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)}, { "BIT_LENGTH", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_bit_length)},
{ "CENTROID", F_SYM(FUNC_ARG1),0,CREATE_FUNC_GEOM(create_func_centroid)}, { "CENTROID", F_SYM(FUNC_ARG1),0,CREATE_FUNC_GEOM(create_func_centroid)},
{ "CHAR_LENGTH", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)}, { "CHAR_LENGTH", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_char_length)},
......
...@@ -210,6 +210,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -210,6 +210,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token CONCURRENT %token CONCURRENT
%token CONSTRAINT %token CONSTRAINT
%token CONVERT_SYM %token CONVERT_SYM
%token CURRENT_USER
%token DATABASES %token DATABASES
%token DATA_SYM %token DATA_SYM
%token DEFAULT %token DEFAULT
...@@ -721,7 +722,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -721,7 +722,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
union_clause union_list union_clause union_list
precision subselect_start opt_and charset precision subselect_start opt_and charset
subselect_end select_var_list select_var_list_init help opt_len subselect_end select_var_list select_var_list_init help opt_len
opt_extended_describe opt_extended_describe curr_user
END_OF_INPUT END_OF_INPUT
%type <NONE> %type <NONE>
...@@ -2684,6 +2685,8 @@ simple_expr: ...@@ -2684,6 +2685,8 @@ simple_expr:
$$= new Item_func_curtime_local($3); $$= new Item_func_curtime_local($3);
Lex->safe_to_cache_query=0; Lex->safe_to_cache_query=0;
} }
| curr_user
{ $$= create_func_current_user(); }
| DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')' | DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')'
{ $$= new Item_date_add_interval($3,$5,$6,0); } { $$= new Item_date_add_interval($3,$5,$6,0); }
| DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')' | DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')'
...@@ -4170,6 +4173,29 @@ show_param: ...@@ -4170,6 +4173,29 @@ show_param:
{ Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); } { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
| LOGS_SYM | LOGS_SYM
{ Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); } { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); }
| GRANTS
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_SHOW_GRANTS;
THD *thd= lex->thd;
LEX_USER *curr_user;
if (!(curr_user= (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
YYABORT;
curr_user->user.str= thd->priv_user;
curr_user->user.length= strlen(thd->priv_user);
if (*thd->priv_host != 0)
{
curr_user->host.str= thd->priv_host;
curr_user->host.length= strlen(thd->priv_host);
}
else
{
curr_user->host.str= (char *) "%";
curr_user->host.length= 1;
}
curr_user->password.str=NullS;
lex->grant_user= curr_user;
}
| GRANTS FOR_SYM user | GRANTS FOR_SYM user
{ {
LEX *lex=Lex; LEX *lex=Lex;
...@@ -4744,6 +4770,11 @@ ident_or_text: ...@@ -4744,6 +4770,11 @@ ident_or_text:
| TEXT_STRING_sys { $$=$1;} | TEXT_STRING_sys { $$=$1;}
| LEX_HOSTNAME { $$=$1;}; | LEX_HOSTNAME { $$=$1;};
curr_user:
CURRENT_USER {;}
| CURRENT_USER '(' ')' {;}
;
user: user:
ident_or_text ident_or_text
{ {
...@@ -4760,7 +4791,25 @@ user: ...@@ -4760,7 +4791,25 @@ user:
if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user)))) if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
YYABORT; YYABORT;
$$->user = $1; $$->host=$3; $$->user = $1; $$->host=$3;
}; }
| curr_user
{
THD *thd= YYTHD;
if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
YYABORT;
$$->user.str= thd->priv_user;
$$->user.length= strlen(thd->priv_user);
if (*thd->priv_host != 0)
{
$$->host.str= thd->priv_host;
$$->host.length= strlen(thd->priv_host);
}
else
{
$$->host.str= (char *) "%";
$$->host.length= 1;
}
};
/* Keyword that we allow for identifiers */ /* Keyword that we allow for identifiers */
...@@ -4798,6 +4847,7 @@ keyword: ...@@ -4798,6 +4847,7 @@ keyword:
| COMPRESSED_SYM {} | COMPRESSED_SYM {}
| CONCURRENT {} | CONCURRENT {}
| CUBE_SYM {} | CUBE_SYM {}
| CURRENT_USER {}
| DATA_SYM {} | DATA_SYM {}
| DATETIME {} | DATETIME {}
| DATE_SYM {} | DATE_SYM {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment