MCPcopy Create free account
hub / github.com/Tencent/phxsql / send_plugin_request_packet

Function send_plugin_request_packet

phx_percona/percona/sql/sql_acl.cc:10016–10090  ·  view source on GitHub ↗

sends a "change plugin" packet, requesting a client to restart authentication using a different authentication plugin Packet format: Bytes Content ----- ---- 1 byte with the value 254 n client plugin to use, \0-terminated n plugin provided data In a special case of switching from native_password_plugin to old_password_plug

Source from the content-addressed store, hash-verified

10014 @retval 1 error
10015*/
10016static bool send_plugin_request_packet(MPVIO_EXT *mpvio,
10017 const uchar *data, uint data_len)
10018{
10019 DBUG_ASSERT(mpvio->packets_written == 1);
10020 DBUG_ASSERT(mpvio->packets_read == 1);
10021 NET *net= mpvio->net;
10022 static uchar switch_plugin_request_buf[]= { 254 };
10023
10024 DBUG_ENTER("send_plugin_request_packet");
10025 mpvio->status= MPVIO_EXT::FAILURE; // the status is no longer RESTART
10026
10027 const char *client_auth_plugin=
10028 ((st_mysql_auth *) (plugin_decl(mpvio->plugin)->info))->client_auth_plugin;
10029
10030 DBUG_ASSERT(client_auth_plugin);
10031
10032 /*
10033 we send an old "short 4.0 scramble request", if we need to request a
10034 client to use 4.0 auth plugin (short scramble) and the scramble was
10035 already sent to the client
10036
10037 below, cached_client_reply.plugin is the plugin name that client has used,
10038 client_auth_plugin is derived from mysql.user table, for the given
10039 user account, it's the plugin that the client need to use to login.
10040 */
10041 bool switch_from_long_to_short_scramble=
10042 native_password_plugin_name.str == mpvio->cached_client_reply.plugin &&
10043 client_auth_plugin == old_password_plugin_name.str;
10044
10045 if (switch_from_long_to_short_scramble)
10046 DBUG_RETURN (secure_auth(mpvio) ||
10047 my_net_write(net, switch_plugin_request_buf, 1) ||
10048 net_flush(net));
10049
10050 /*
10051 We never request a client to switch from a short to long scramble.
10052 Plugin-aware clients can do that, but traditionally it meant to
10053 ask an old 4.0 client to use the new 4.1 authentication protocol.
10054 */
10055 bool switch_from_short_to_long_scramble=
10056 old_password_plugin_name.str == mpvio->cached_client_reply.plugin &&
10057 client_auth_plugin == native_password_plugin_name.str;
10058
10059 if (switch_from_short_to_long_scramble)
10060 {
10061 my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
10062 general_log_print(current_thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
10063 DBUG_RETURN (1);
10064 }
10065
10066 /*
10067 If we're dealing with an older client we can't just send a change plugin
10068 packet to re-initiate the authentication handshake, because the client
10069 won't understand it. The good thing is that we don't need to : the old client
10070 expects us to just check the user credentials here, which we can do by just reading
10071 the cached data that are placed there by parse_com_change_user_packet()
10072 In this case we just do nothing and behave as if normal authentication
10073 should continue.

Callers 2

Calls 1

secure_authFunction · 0.85

Tested by

no test coverage detected