From f8c7e8c816cf88af180f2ca3536e3af0c6bfb34c Mon Sep 17 00:00:00 2001 From: Lingyu Song Date: Mon, 30 Mar 2020 18:10:19 +0800 Subject: [PATCH] cherry pick #15825 to release-3.0 Signed-off-by: sre-bot --- executor/builder.go | 2 ++ executor/show_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/executor/builder.go b/executor/builder.go index 26180bbb04e62..2e6a85af00a1d 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -626,6 +626,8 @@ func (b *executorBuilder) buildShow(v *plannercore.Show) Executor { // The former determine privileges with roles, while the later doesn't. vars := e.ctx.GetSessionVars() e.User = vars.User + e.User.Hostname = vars.User.AuthHostname + e.User.Username = vars.User.AuthUsername e.Roles = vars.ActiveRoles } if e.Tp == ast.ShowMasterStatus { diff --git a/executor/show_test.go b/executor/show_test.go index ef08c6d7c40f7..39a52da9787ce 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -139,7 +139,31 @@ func (s *testSuite2) TestShowErrors(c *C) { tk.MustQuery("show errors").Check(testutil.RowsWithSep("|", "Error|1050|Table 'test.show_errors' already exists")) } +<<<<<<< HEAD func (s *testSuite2) TestIssue3641(c *C) { +======= +func (s *testSuite5) TestShowGrantsPrivilege(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("create user show_grants") + tk.MustExec("show grants for show_grants") + tk1 := testkit.NewTestKit(c, s.store) + se, err := session.CreateSession4Test(s.store) + c.Assert(err, IsNil) + c.Assert(se.Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "%"}, nil, nil), IsTrue) + tk1.Se = se + err = tk1.QueryToErr("show grants for root") + c.Assert(err.Error(), Equals, executor.ErrDBaccessDenied.GenWithStackByArgs("show_grants", "%", mysql.SystemDB).Error()) + // Test show grants for user with auth host name `%`. + tk2 := testkit.NewTestKit(c, s.store) + se2, err := session.CreateSession4Test(s.store) + c.Assert(err, IsNil) + c.Assert(se2.Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "127.0.0.1", AuthUsername: "show_grants", AuthHostname: "%"}, nil, nil), IsTrue) + tk2.Se = se2 + tk2.MustQuery("show grants") +} + +func (s *testSuite5) TestIssue3641(c *C) { +>>>>>>> 1142e65... privilege: fix user with `%` hostname can not show grants. (#15825) tk := testkit.NewTestKit(c, s.store) _, err := tk.Exec("show tables;") c.Assert(err.Error(), Equals, plannercore.ErrNoDB.Error())