Skip to content

Commit

Permalink
server: fix authentication with MySQL 5.1 and older clients (#29732) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 authored Nov 16, 2021
1 parent 46bada6 commit c83f032
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,20 @@ func (cc *clientConn) handleAuthPlugin(ctx context.Context, resp *handshakeRespo
}
} else {
logutil.Logger(ctx).Warn("Client without Auth Plugin support; Please upgrade client")
if cc.ctx == nil {
err := cc.openSession()
if err != nil {
return err
}
}
userplugin, err := cc.ctx.AuthPluginForUser(&auth.UserIdentity{Username: cc.user, Hostname: cc.peerHost})
if err != nil {
return err
}
if userplugin != mysql.AuthNativePassword && userplugin != "" {
return errNotSupportedAuthMode
}
resp.AuthPlugin = mysql.AuthNativePassword
}
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ func TestHandleAuthPlugin(t *testing.T) {
pkt: &packetIO{
bufWriter: bufio.NewWriter(bytes.NewBuffer(nil)),
},
server: srv,
collation: mysql.DefaultCollationID,
server: srv,
user: "root",
}
ctx := context.Background()
resp := handshakeResponse41{
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var (
errSecureTransportRequired = dbterror.ClassServer.NewStd(errno.ErrSecureTransportRequired)
errMultiStatementDisabled = dbterror.ClassServer.NewStd(errno.ErrMultiStatementDisabled)
errNewAbortingConnection = dbterror.ClassServer.NewStd(errno.ErrNewAbortingConnection)
errNotSupportedAuthMode = dbterror.ClassServer.NewStd(errno.ErrNotSupportedAuthMode)
)

// DefaultCapability is the capability of the server when it is created using the default configuration.
Expand Down

0 comments on commit c83f032

Please sign in to comment.