Skip to content

Commit

Permalink
privilege: fix grant for global level grant(cherry-pick from 4.0) (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwen92 authored Dec 20, 2021
1 parent a0a8a97 commit 49117ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,8 @@ func collectVisitInfoFromRevokeStmt(sctx sessionctx.Context, vi []visitInfo, stm
// and you must have the privileges that you are granting.
dbName := stmt.Level.DBName
tableName := stmt.Level.TableName
if dbName == "" {
// do not add dbName to the visitInfo of a *.* grant.
if dbName == "" && stmt.Level.Level != ast.GrantLevelGlobal {
dbName = sctx.GetSessionVars().CurrentDB
}
vi = appendVisitInfo(vi, mysql.GrantPriv, dbName, tableName, "", nil)
Expand Down Expand Up @@ -2304,7 +2305,8 @@ func collectVisitInfoFromGrantStmt(sctx sessionctx.Context, vi []visitInfo, stmt
// and you must have the privileges that you are granting.
dbName := stmt.Level.DBName
tableName := stmt.Level.TableName
if dbName == "" {
// do not add dbName to the visitInfo of a *.* grant.
if dbName == "" && stmt.Level.Level != ast.GrantLevelGlobal {
dbName = sctx.GetSessionVars().CurrentDB
}
vi = appendVisitInfo(vi, mysql.GrantPriv, dbName, tableName, "", nil)
Expand Down
11 changes: 11 additions & 0 deletions privilege/privileges/privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,17 @@ func (s *testPrivilegeSuite) TestCheckAuthenticate(c *C) {
mustExec(c, se1, "drop user 'r3@example.com'@'localhost'")
}

func (s *testPrivilegeSuite) TestGlobalGrantInfoDB(c *C) {
se := newSession(c, s.store, "INFORMATION_SCHEMA")
//mustExec(c, se, "USE information_schema'")
mustExec(c, se, "CREATE USER 'global'")
// can be executed in information schema for *.*
_, e := se.Execute(context.Background(), "GRANT all privileges ON *.* TO 'global'")
c.Assert(e, IsNil)
_, e = se.Execute(context.Background(), "REVOKE all privileges on *.* FROM 'global'")
c.Assert(e, IsNil)
}

func (s *testPrivilegeSuite) TestUseDB(c *C) {

se := newSession(c, s.store, s.dbName)
Expand Down

0 comments on commit 49117ed

Please sign in to comment.