Skip to content

Commit

Permalink
server: Improve compatibility with MySQL 5.5 and 5.6 clients (#32338)
Browse files Browse the repository at this point in the history
close #32334
  • Loading branch information
dveeden authored Mar 3, 2022
1 parent 11a1c18 commit 7e8ca4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 12 additions & 8 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,21 +885,25 @@ func (cc *clientConn) checkAuthPlugin(ctx context.Context, resp *handshakeRespon
if err != nil {
return nil, err
}
if resp.Capability&mysql.ClientPluginAuth > 0 {
_, err = cc.authSwitchRequest(ctx, mysql.AuthNativePassword)
if err != nil {
return nil, err
}
}
return []byte(user.Username), nil
}
if len(userplugin) == 0 {
// No user plugin set, assuming MySQL Native Password
// This happens if the account doesn't exist or if the account doesn't have
// a password set.
if resp.AuthPlugin != mysql.AuthNativePassword {
if resp.Capability&mysql.ClientPluginAuth > 0 {
resp.AuthPlugin = mysql.AuthNativePassword
authData, err := cc.authSwitchRequest(ctx, mysql.AuthNativePassword)
if err != nil {
return nil, err
}
return authData, nil
if resp.Capability&mysql.ClientPluginAuth > 0 {
resp.AuthPlugin = mysql.AuthNativePassword
authData, err := cc.authSwitchRequest(ctx, mysql.AuthNativePassword)
if err != nil {
return nil, err
}
return authData, nil
}
return nil, nil
}
Expand Down
5 changes: 4 additions & 1 deletion server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ func TestHandleAuthPlugin(t *testing.T) {
tk.MustExec("DROP USER unativepassword")
}()

// 5.7 or newer client trying to authenticate with mysql_native_password
// 5.5, 5.6 or 5.7 client trying to authenticate with mysql_native_password, w/o password
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/server/FakeAuthSwitch", "return(1)"))
cc := &clientConn{
connectionID: 1,
alloc: arena.NewAllocator(1024),
Expand All @@ -908,6 +909,8 @@ func TestHandleAuthPlugin(t *testing.T) {
}
err = cc.handleAuthPlugin(ctx, &resp)
require.NoError(t, err)
require.Equal(t, resp.Auth, []byte(mysql.AuthNativePassword))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/server/FakeAuthSwitch"))

// 8.0 or newer client trying to authenticate with caching_sha2_password
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/server/FakeAuthSwitch", "return(1)"))
Expand Down

0 comments on commit 7e8ca4c

Please sign in to comment.