mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Re-commit MySQL 8 cached SHA auth support
With changes to (hopefully) correctly fall back if OpenSSL support is missing. Furthermore the hard-coded dependency on ext/hash is no longer an issue, as this extension is required in master. This reverts commit63072e9c0e
, reversing changes made to4cbabb6852
.
This commit is contained in:
parent
35be0590ed
commit
4f06e67ad2
7 changed files with 392 additions and 29 deletions
|
@ -2123,6 +2123,75 @@ php_mysqlnd_sha256_pk_request_response_free_mem(void * _packet)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
static
|
||||
size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _packet)
|
||||
{
|
||||
MYSQLND_PACKET_CACHED_SHA2_RESULT * packet= (MYSQLND_PACKET_CACHED_SHA2_RESULT *) _packet;
|
||||
MYSQLND_ERROR_INFO * error_info = conn->error_info;
|
||||
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
|
||||
MYSQLND_VIO * vio = conn->vio;
|
||||
MYSQLND_STATS * stats = conn->stats;
|
||||
#if HAVE_COMPILER_C99_VLA
|
||||
zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1];
|
||||
#else
|
||||
ALLOCA_FLAG(use_heap)
|
||||
zend_uchar *buffer = do_alloca(MYSQLND_HEADER_SIZE + packet->password_len + 1, use_heap);
|
||||
#endif
|
||||
size_t sent;
|
||||
|
||||
DBG_ENTER("php_mysqlnd_cached_sha2_result_write");
|
||||
|
||||
if (packet->request == 1) {
|
||||
int1store(buffer + MYSQLND_HEADER_SIZE, '\2');
|
||||
sent = pfc->data->m.send(pfc, vio, buffer, 1, stats, error_info);
|
||||
} else {
|
||||
memcpy(buffer + MYSQLND_HEADER_SIZE, packet->password, packet->password_len);
|
||||
sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
|
||||
}
|
||||
|
||||
#if !HAVE_COMPILER_C99_VLA
|
||||
free_alloca(buffer, use_heap);
|
||||
#endif
|
||||
|
||||
DBG_RETURN(sent);
|
||||
}
|
||||
|
||||
static enum_func_status
|
||||
php_mysqlnd_cached_sha2_result_read(MYSQLND_CONN_DATA * conn, void * _packet)
|
||||
{
|
||||
MYSQLND_PACKET_CACHED_SHA2_RESULT * packet= (MYSQLND_PACKET_CACHED_SHA2_RESULT *) _packet;
|
||||
MYSQLND_ERROR_INFO * error_info = conn->error_info;
|
||||
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
|
||||
MYSQLND_VIO * vio = conn->vio;
|
||||
MYSQLND_STATS * stats = conn->stats;
|
||||
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
|
||||
zend_uchar buf[SHA256_PK_REQUEST_RESP_BUFFER_SIZE];
|
||||
zend_uchar *p = buf;
|
||||
const zend_uchar * const begin = buf;
|
||||
|
||||
DBG_ENTER("php_mysqlnd_cached_sha2_result_read");
|
||||
if (FAIL == mysqlnd_read_packet_header_and_body(&(packet->header), pfc, vio, stats, error_info, connection_state, buf, sizeof(buf), "PROT_CACHED_SHA2_RESULT_PACKET", PROT_CACHED_SHA2_RESULT_PACKET)) {
|
||||
DBG_RETURN(FAIL);
|
||||
}
|
||||
BAIL_IF_NO_MORE_DATA;
|
||||
|
||||
p++;
|
||||
packet->response_code = uint1korr(p);
|
||||
BAIL_IF_NO_MORE_DATA;
|
||||
|
||||
p++;
|
||||
packet->result = uint1korr(p);
|
||||
BAIL_IF_NO_MORE_DATA;
|
||||
|
||||
DBG_RETURN(PASS);
|
||||
|
||||
premature_end:
|
||||
DBG_ERR_FMT("OK packet %d bytes shorter than expected", p - begin - packet->header.size);
|
||||
php_error_docref(NULL, E_WARNING, "SHA256_PK_REQUEST_RESPONSE packet "MYSQLND_SZ_T_SPEC" bytes shorter than expected",
|
||||
p - begin - packet->header.size);
|
||||
DBG_RETURN(FAIL);
|
||||
}
|
||||
|
||||
/* {{{ packet_methods */
|
||||
static
|
||||
mysqlnd_packet_methods packet_methods[PROT_LAST] =
|
||||
|
@ -2201,9 +2270,14 @@ mysqlnd_packet_methods packet_methods[PROT_LAST] =
|
|||
php_mysqlnd_sha256_pk_request_response_read,
|
||||
NULL, /* write */
|
||||
php_mysqlnd_sha256_pk_request_response_free_mem,
|
||||
} /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */
|
||||
}, /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */
|
||||
{
|
||||
php_mysqlnd_cached_sha2_result_read,
|
||||
php_mysqlnd_cached_sha2_result_write,
|
||||
NULL
|
||||
} /* PROT_CACHED_SHA2_RESULT_PACKET */
|
||||
};
|
||||
/* }}} */
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ mysqlnd_protocol::init_greet_packet */
|
||||
|
@ -2385,6 +2459,17 @@ MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_response_packet)(struct
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ mysqlnd_protocol::init_cached_sha2_result_packet */
|
||||
static void
|
||||
MYSQLND_METHOD(mysqlnd_protocol, init_cached_sha2_result_packet)(struct st_mysqlnd_packet_cached_sha2_result *packet)
|
||||
{
|
||||
DBG_ENTER("mysqlnd_protocol::init_cached_sha2_result_packet");
|
||||
memset(packet, 0, sizeof(*packet));
|
||||
packet->header.m = &packet_methods[PROT_CACHED_SHA2_RESULT_PACKET];
|
||||
DBG_VOID_RETURN;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ mysqlnd_protocol::send_command */
|
||||
static enum_func_status
|
||||
|
@ -2603,6 +2688,7 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_protocol_payload_decoder_factory)
|
|||
MYSQLND_METHOD(mysqlnd_protocol, init_change_user_response_packet),
|
||||
MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_packet),
|
||||
MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_response_packet),
|
||||
MYSQLND_METHOD(mysqlnd_protocol, init_cached_sha2_result_packet),
|
||||
|
||||
MYSQLND_METHOD(mysqlnd_protocol, send_command),
|
||||
MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_response),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue