@@ -36,6 +36,9 @@ type AuthPlugin interface {
36
36
// Next takes a server's challenge and returns
37
37
// the bytes to send back or an error.
38
38
Next (challenge []byte ) ([]byte , error )
39
+
40
+ // Close cleans up the resources of the plugin.
41
+ Close ()
39
42
}
40
43
41
44
type clearTextPlugin struct {
@@ -51,6 +54,8 @@ func (p *clearTextPlugin) Next(challenge []byte) ([]byte, error) {
51
54
return append ([]byte (p .cfg .Passwd ), 0 ), nil
52
55
}
53
56
57
+ func (p * clearTextPlugin ) Close () {}
58
+
54
59
type nativePasswordPlugin struct {
55
60
cfg * Config
56
61
}
@@ -64,6 +69,8 @@ func (p *nativePasswordPlugin) Next(challenge []byte) ([]byte, error) {
64
69
return scramblePassword (challenge , []byte (p .cfg .Passwd )), nil
65
70
}
66
71
72
+ func (p * nativePasswordPlugin ) Close () {}
73
+
67
74
type oldPasswordPlugin struct {
68
75
cfg * Config
69
76
}
@@ -77,7 +84,9 @@ func (p *oldPasswordPlugin) Next(challenge []byte) ([]byte, error) {
77
84
return append (scrambleOldPassword (challenge , []byte (p .cfg .Passwd )), 0 ), nil
78
85
}
79
86
80
- func handleAuthResult (mc * mysqlConn , plugin AuthPlugin , oldCipher []byte ) error {
87
+ func (p * oldPasswordPlugin ) Close () {}
88
+
89
+ func handleAuthResult (mc * mysqlConn , oldCipher []byte ) error {
81
90
data , err := mc .readPacket ()
82
91
if err != nil {
83
92
return err
@@ -91,11 +100,12 @@ func handleAuthResult(mc *mysqlConn, plugin AuthPlugin, oldCipher []byte) error
91
100
return mc .handleOkPacket (data )
92
101
93
102
case iEOF : // auth switch
103
+ mc .authPlugin .Close ()
94
104
if len (data ) > 1 {
95
105
pluginEndIndex := bytes .IndexByte (data , 0x00 )
96
106
pluginName := string (data [1 :pluginEndIndex ])
97
107
if apf , ok := authPluginFactories [pluginName ]; ok {
98
- plugin = apf (mc .cfg )
108
+ mc . authPlugin = apf (mc .cfg )
99
109
} else {
100
110
return ErrUnknownPlugin
101
111
}
@@ -105,7 +115,7 @@ func handleAuthResult(mc *mysqlConn, plugin AuthPlugin, oldCipher []byte) error
105
115
}
106
116
} else {
107
117
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
108
- plugin = authPluginFactories [mysqlOldPassword ](mc .cfg )
118
+ mc . authPlugin = authPluginFactories [mysqlOldPassword ](mc .cfg )
109
119
authData = oldCipher
110
120
}
111
121
case iAuthContinue :
@@ -115,7 +125,7 @@ func handleAuthResult(mc *mysqlConn, plugin AuthPlugin, oldCipher []byte) error
115
125
return mc .handleErrorPacket (data )
116
126
}
117
127
118
- authData , err = plugin .Next (authData )
128
+ authData , err = mc . authPlugin .Next (authData )
119
129
if err != nil {
120
130
return err
121
131
}
@@ -125,5 +135,5 @@ func handleAuthResult(mc *mysqlConn, plugin AuthPlugin, oldCipher []byte) error
125
135
return err
126
136
}
127
137
128
- return handleAuthResult (mc , plugin , authData )
138
+ return handleAuthResult (mc , authData )
129
139
}
0 commit comments