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

Function server_mpvio_read_packet

phx_percona/percona/sql/sql_acl.cc:11067–11154  ·  view source on GitHub ↗

vio->read_packet() callback method for server authentication plugins This function is called by a server authentication plugin, when it wants to read data from the client. It transparently extracts the client plugin data, if embedded into a client authentication handshake packet, and handles plugin negotiation with the client, if necessary. */

Source from the content-addressed store, hash-verified

11065 with the client, if necessary.
11066*/
11067static int server_mpvio_read_packet(MYSQL_PLUGIN_VIO *param, uchar **buf)
11068{
11069 MPVIO_EXT *mpvio= (MPVIO_EXT *) param;
11070 ulong pkt_len;
11071
11072 DBUG_ENTER("server_mpvio_read_packet");
11073 if (mpvio->packets_written == 0)
11074 {
11075 /*
11076 plugin wants to read the data without sending anything first.
11077 send an empty packet to force a server handshake packet to be sent
11078 */
11079 if (mpvio->write_packet(mpvio, 0, 0))
11080 pkt_len= packet_error;
11081 else
11082 pkt_len= my_net_read(mpvio->net);
11083 }
11084 else if (mpvio->cached_client_reply.pkt)
11085 {
11086 DBUG_ASSERT(mpvio->status == MPVIO_EXT::RESTART);
11087 DBUG_ASSERT(mpvio->packets_read > 0);
11088 /*
11089 if the have the data cached from the last server_mpvio_read_packet
11090 (which can be the case if it's a restarted authentication)
11091 and a client has used the correct plugin, then we can return the
11092 cached data straight away and avoid one round trip.
11093 */
11094 const char *client_auth_plugin=
11095 ((st_mysql_auth *) (plugin_decl(mpvio->plugin)->info))->client_auth_plugin;
11096 if (client_auth_plugin == 0 ||
11097 my_strcasecmp(system_charset_info, mpvio->cached_client_reply.plugin,
11098 client_auth_plugin) == 0)
11099 {
11100 mpvio->status= MPVIO_EXT::FAILURE;
11101 *buf= (uchar*) mpvio->cached_client_reply.pkt;
11102 mpvio->cached_client_reply.pkt= 0;
11103 mpvio->packets_read++;
11104 DBUG_RETURN ((int) mpvio->cached_client_reply.pkt_len);
11105 }
11106
11107 /* older clients don't support change of client plugin request */
11108 if (!(mpvio->client_capabilities & CLIENT_PLUGIN_AUTH))
11109 {
11110 mpvio->status= MPVIO_EXT::FAILURE;
11111 pkt_len= packet_error;
11112 goto err;
11113 }
11114
11115 /*
11116 But if the client has used the wrong plugin, the cached data are
11117 useless. Furthermore, we have to send a "change plugin" request
11118 to the client.
11119 */
11120 if (mpvio->write_packet(mpvio, 0, 0))
11121 pkt_len= packet_error;
11122 else
11123 pkt_len= my_net_read(mpvio->net);
11124 }

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected