New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Support "show grants for current_user();" #5697

Merged
merged 5 commits into from Mar 27, 2018
Merged
Diff settings

Always

Just for now

Copy path View file
@@ -549,6 +549,9 @@ func (s *testSuite) TestShow2(c *C) {

tk.MustExec(`grant all on *.* to 'root'@'%'`)
tk.MustQuery("show grants").Check(testkit.Rows(`GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'`))

tk.MustQuery("show grants for current_user()").Check(testkit.Rows(`GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'`))
tk.MustQuery("show grants for current_user").Check(testkit.Rows(`GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'`))
}

func (s *testSuite) TestCollation(c *C) {
Copy path View file
@@ -4759,6 +4759,10 @@ Username:
{
$$ = &auth.UserIdentity{Username: $1.(string), Hostname: strings.TrimPrefix($2, "@")}
}
| "CURRENT_USER" OptionalBraces
{
$$ = &auth.UserIdentity{CurrentUser: true}
}
UsernameList:
Username
Copy path View file
@@ -482,6 +482,8 @@ func (s *testParserSuite) TestDBAStmt(c *C) {
{`SHOW FULL TABLES WHERE Table_Type != 'VIEW'`, true},
{`SHOW GRANTS`, true},
{`SHOW GRANTS FOR 'test'@'localhost'`, true},
{`SHOW GRANTS FOR current_user()`, true},
{`SHOW GRANTS FOR current_user`, true},
{`SHOW COLUMNS FROM City;`, true},
{`SHOW COLUMNS FROM tv189.1_t_1_x;`, true},
{`SHOW FIELDS FROM City;`, true},
@@ -2028,8 +2030,7 @@ func (s *testParserSuite) TestView(c *C) {
{"create or replace algorithm = merge definer = 'root' sql security invoker view v(a,b) as select * from t", true},
{"create or replace algorithm = merge definer = 'root' sql security invoker view v(a,b) as select * from t with local check option", true},
{"create or replace algorithm = merge definer = 'root' sql security invoker view v(a,b) as select * from t with cascaded check option", true},
// fixme: should be true
{"create or replace algorithm = merge definer = current_user view v as select * from t", false},
{"create or replace algorithm = merge definer = current_user view v as select * from t", true},
}
s.RunTest(c, table)

Copy path View file
@@ -43,7 +43,7 @@ type preprocessor struct {
ctx sessionctx.Context
err error
inPrepare bool
// When visiting create/drop table statement.
// inCreateOrDropTable is true when visiting create/drop table statement.
inCreateOrDropTable bool
}

@@ -423,7 +423,7 @@ func checkColumn(colDef *ast.ColumnDef) error {
return nil
}

// isNowSymFunc checks whether default value is a NOW() builtin function.
// isDefaultValNowSymFunc checks whether defaul value is a NOW() builtin function.

This comment has been minimized.

@tiancaiamao

tiancaiamao Mar 28, 2018

Contributor

s/defaul/default

func isDefaultValNowSymFunc(expr ast.ExprNode) bool {
if funcCall, ok := expr.(*ast.FuncCallExpr); ok {
// Default value NOW() is transformed to CURRENT_TIMESTAMP() in parser.
@@ -450,6 +450,7 @@ func isInvalidDefaultValue(colDef *ast.ColumnDef) bool {
return false
}

// isIncorrectName checks if the identifier is incorrect.
// See https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
func isIncorrectName(name string) bool {
if len(name) == 0 {
@@ -495,6 +496,14 @@ func (p *preprocessor) resolveShowStmt(node *ast.ShowStmt) {
} else if node.Table != nil && node.Table.Schema.L == "" {
node.Table.Schema = model.NewCIStr(node.DBName)
}
if node.User != nil && node.User.CurrentUser {
// Fill the Username and Hostname with the current user.
currentUser := p.ctx.GetSessionVars().User
if currentUser != nil {
node.User.Username = currentUser.Username
node.User.Hostname = currentUser.Hostname
}
}
}

func (p *preprocessor) resolveAlterTableStmt(node *ast.AlterTableStmt) {
Copy path View file
@@ -25,8 +25,9 @@ import (

// UserIdentity represents username and hostname.
type UserIdentity struct {
Username string
Hostname string
Username string
Hostname string
CurrentUser bool
}

// String converts UserIdentity to the format user@host.
ProTip! Use n and p to navigate between commits in a pull request.