Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for adding new auth method #172

Merged
merged 4 commits into from Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/mysql/auth_server.go
Expand Up @@ -50,7 +50,7 @@ type AuthServer interface {
// expected. If anything else is returned, Negotiate()
// will be called on the connection, and the AuthServer
// needs to handle the packets.
AuthMethod(user string) (string, error)
AuthMethod(user, addr string) (string, error)

// Salt returns the salt to use for a connection.
// It should be 20 bytes of data.
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/auth_server_clientcert.go
Expand Up @@ -46,7 +46,7 @@ func InitAuthServerClientCert() {
}

// AuthMethod is part of the AuthServer interface.
func (ascc *AuthServerClientCert) AuthMethod(user string) (string, error) {
func (ascc *AuthServerClientCert) AuthMethod(user, addr string) (string, error) {
return ascc.Method, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/mysql/auth_server_none.go
Expand Up @@ -31,7 +31,7 @@ type AuthServerNone struct{}

// AuthMethod is part of the AuthServer interface.
// We always return MysqlNativePassword.
func (a *AuthServerNone) AuthMethod(user string) (string, error) {
func (a *AuthServerNone) AuthMethod(user, addr string) (string, error) {
return MysqlNativePassword, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/mysql/auth_server_static.go
Expand Up @@ -225,7 +225,7 @@ func validateConfig(config map[string][]*AuthServerStaticEntry) error {
}

// AuthMethod is part of the AuthServer interface.
func (a *AuthServerStatic) AuthMethod(user string) (string, error) {
func (a *AuthServerStatic) AuthMethod(user, addr string) (string, error) {
return a.Method, nil
}

Expand Down
40 changes: 21 additions & 19 deletions go/mysql/server.go
Expand Up @@ -206,15 +206,16 @@ func NewListener(protocol, address string, authServer AuthServer, handler Handle
// ListenerConfig should be used with NewListenerWithConfig to specify listener parameters.
type ListenerConfig struct {
// Protocol-Address pair and Listener are mutually exclusive parameters
Protocol string
Address string
Listener net.Listener
AuthServer AuthServer
Handler Handler
ConnReadTimeout time.Duration
ConnWriteTimeout time.Duration
ConnReadBufferSize int
MaxConns uint64
Protocol string
Address string
Listener net.Listener
AuthServer AuthServer
Handler Handler
ConnReadTimeout time.Duration
ConnWriteTimeout time.Duration
ConnReadBufferSize int
MaxConns uint64
AllowClearTextWithoutTLS bool
}

// NewListenerWithConfig creates new listener using provided config. There are
Expand All @@ -232,15 +233,16 @@ func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error) {
}

return &Listener{
authServer: cfg.AuthServer,
handler: cfg.Handler,
listener: l,
ServerVersion: DefaultServerVersion,
connectionID: 1,
connReadTimeout: cfg.ConnReadTimeout,
connWriteTimeout: cfg.ConnWriteTimeout,
connReadBufferSize: cfg.ConnReadBufferSize,
maxConns: cfg.MaxConns,
authServer: cfg.AuthServer,
handler: cfg.Handler,
listener: l,
ServerVersion: DefaultServerVersion,
connectionID: 1,
connReadTimeout: cfg.ConnReadTimeout,
connWriteTimeout: cfg.ConnWriteTimeout,
connReadBufferSize: cfg.ConnReadBufferSize,
maxConns: cfg.MaxConns,
AllowClearTextWithoutTLS: sync2.NewAtomicBool(cfg.AllowClearTextWithoutTLS),
}, nil
}

Expand Down Expand Up @@ -362,7 +364,7 @@ func (l *Listener) handle(conn net.Conn, connectionID uint32, acceptTime time.Ti
}

// See what auth method the AuthServer wants to use for that user.
authServerMethod, err := l.authServer.AuthMethod(user)
authServerMethod, err := l.authServer.AuthMethod(user, conn.RemoteAddr().String())
if err != nil {
c.writeErrorPacketFromError(err)
return
Expand Down