Skip to content

Commit

Permalink
planner, privilege: check user priv on SET GLOBAL (#8837)
Browse files Browse the repository at this point in the history
* planner, privilege: check user priv on SET GLOBAL
  • Loading branch information
morgo authored Jan 5, 2019
1 parent cfff965 commit 081a2c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ func (b *PlanBuilder) buildDo(v *ast.DoStmt) (Plan, error) {
func (b *PlanBuilder) buildSet(v *ast.SetStmt) (Plan, error) {
p := &Set{}
for _, vars := range v.Variables {
if vars.IsGlobal {
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SuperPriv, "", "", "", nil)
}
assign := &expression.VarAssignment{
Name: vars.Name,
IsGlobal: vars.IsGlobal,
Expand Down
15 changes: 15 additions & 0 deletions privilege/privileges/privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ func (s *testPrivilegeSuite) TestUseDb(c *C) {

}

func (s *testPrivilegeSuite) TestSetGlobal(c *C) {
se := newSession(c, s.store, s.dbName)
mustExec(c, se, `CREATE USER setglobal_a@localhost`)
mustExec(c, se, `CREATE USER setglobal_b@localhost`)
mustExec(c, se, `GRANT SUPER ON *.* to setglobal_a@localhost`)
mustExec(c, se, `FLUSH PRIVILEGES`)

c.Assert(se.Auth(&auth.UserIdentity{Username: "setglobal_a", Hostname: "localhost"}, nil, nil), IsTrue)
mustExec(c, se, `set global innodb_commit_concurrency=16`)

c.Assert(se.Auth(&auth.UserIdentity{Username: "setglobal_b", Hostname: "localhost"}, nil, nil), IsTrue)
_, err := se.Execute(context.Background(), `set global innodb_commit_concurrency=16`)
c.Assert(strings.Contains(err.Error(), "privilege check fail"), IsTrue)
}

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

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

0 comments on commit 081a2c5

Please sign in to comment.