Skip to content

Commit 6f18831

Browse files
committed
WL#15239: Fix plugin option name and empty callback in the driver.
1 parent 895cf84 commit 6f18831

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

jdbc/driver/mysql_connection.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,16 @@ struct MySQL_Driver::WebAuthn_Callback_Setter
468468

469469
driver = &drv; // Set current driver.
470470

471-
register_callback(prx, "fido", callback_type % 3 > 1);
472-
register_callback(prx, "webauthn", callback_type % 3 > 0);
471+
/*
472+
Note: A webauthn callback (callback_type 2 or 5) is registered with both
473+
"fido" and "webauthn" plugins. A fido callback (callback_type 1 or 4)
474+
is registered only with "fido" plugin. And if user did not register any
475+
callback (callback_type 0 or 3) then both plugin callbacks are re-set
476+
to null.
477+
*/
478+
479+
register_callback(prx, "fido", (callback_type % 3) > 1);
480+
register_callback(prx, "webauthn", (callback_type % 3) > 0);
473481

474482
/*
475483
Note: This will be reset to value 0-2 when user deregisters
@@ -504,7 +512,9 @@ struct MySQL_Driver::WebAuthn_Callback_Setter
504512
void register_callback(Proxy *proxy, std::string which, bool set_or_reset)
505513
{
506514
std::string plugin = "authentication_" + which + "_client";
507-
std::string opt = which + "_messages_callback";
515+
std::string opt = (which == "webauthn" ?
516+
"plugin_authentication_webauthn_client" : which) +
517+
"_messages_callback";
508518

509519
try
510520
{

jdbc/driver/mysql_driver.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,13 @@ void MySQL_Driver::threadEnd()
185185

186186
void MySQL_Driver::setCallBack(sql::WebAuthn_Callback&& cb)
187187
{
188-
webauthn_callback = cb ? std::move(cb) : nullptr;
188+
if (cb)
189+
webauthn_callback = std::move(cb);
190+
else
191+
webauthn_callback = nullptr;
192+
189193
fido_callback
190-
= reinterpret_cast<Fido_Callback*>(cb ? 1LL : 0LL);
194+
= reinterpret_cast<Fido_Callback*>(webauthn_callback ? 1LL : 0LL);
191195
}
192196

193197
void MySQL_Driver::setCallBack(sql::WebAuthn_Callback& cb)
@@ -198,15 +202,20 @@ void MySQL_Driver::setCallBack(sql::WebAuthn_Callback& cb)
198202
webauthn_callback = nullptr;
199203

200204
fido_callback
201-
= reinterpret_cast<Fido_Callback*>(cb ? 1LL : 0LL);
205+
= reinterpret_cast<Fido_Callback*>(webauthn_callback ? 1LL : 0LL);
202206
}
203207

204208

205-
// Note: Values 1 and 4 of `fido_callback` mean that user has set an WebAuthn
206-
// callback before.
209+
/*
210+
Note: Values 1 and 4 of `fido_callback` mean that user has set a WebAuthn
211+
callback before and it can not be overwritten by Fido one. If later user
212+
de-registers a WebAuthn callaback then `fido_callback` becomes 0 or 4 and
213+
error will not be thrown -- user can set a new Fido callback in this
214+
situation.
215+
*/
207216

208217
#define CHECK_FIDO_ERROR \
209-
if (1 == reinterpret_cast<intptr_t>(fido_callback) % 3) \
218+
if (1 == (reinterpret_cast<intptr_t>(fido_callback) % 3)) \
210219
throw sql::SQLException{ \
211220
"You are trying to overwrithe WebAuthn callback with FIDO one. " \
212221
"FIDO authentication plugin and the corresponding callback type " \
@@ -217,9 +226,14 @@ void MySQL_Driver::setCallBack(sql::WebAuthn_Callback& cb)
217226
void MySQL_Driver::setCallBack(sql::Fido_Callback&& cb)
218227
{
219228
CHECK_FIDO_ERROR;
220-
webauthn_callback = cb ? std::move(cb) : nullptr;
229+
230+
if (cb)
231+
webauthn_callback = std::move(cb);
232+
else
233+
webauthn_callback = nullptr;
234+
221235
fido_callback
222-
= reinterpret_cast<Fido_Callback*>(cb ? 2LL : 0LL);
236+
= reinterpret_cast<Fido_Callback*>(webauthn_callback ? 2LL : 0LL);
223237
}
224238

225239
void MySQL_Driver::setCallBack(sql::Fido_Callback& cb)
@@ -232,7 +246,7 @@ void MySQL_Driver::setCallBack(sql::Fido_Callback& cb)
232246
webauthn_callback = nullptr;
233247

234248
fido_callback
235-
= reinterpret_cast<Fido_Callback*>(cb ? 2LL : 0LL);
249+
= reinterpret_cast<Fido_Callback*>(webauthn_callback ? 2LL : 0LL);
236250
}
237251

238252
} /* namespace mysql */

0 commit comments

Comments
 (0)