DBG_ENTER("mysqlnd_auth_handshake");
- auth_resp_packet = conn->payload_decoder_factory->m.get_auth_response_packet(conn->payload_decoder_factory, FALSE);
-
- if (!auth_resp_packet) {
- SET_OOM_ERROR(conn->error_info);
- goto end;
- }
+ conn->payload_decoder_factory->m.init_auth_response_packet(&auth_resp_packet);
if (use_full_blown_auth_packet != TRUE) {
- change_auth_resp_packet = conn->payload_decoder_factory->m.get_change_auth_response_packet(conn->payload_decoder_factory, FALSE);
- if (!change_auth_resp_packet) {
- SET_OOM_ERROR(conn->error_info);
- goto end;
- }
+ MYSQLND_PACKET_CHANGE_AUTH_RESPONSE change_auth_resp_packet;
- change_auth_resp_packet->auth_data = auth_plugin_data;
- change_auth_resp_packet->auth_data_len = auth_plugin_data_len;
+ conn->payload_decoder_factory->m.init_change_auth_response_packet(&change_auth_resp_packet);
- if (!PACKET_WRITE(change_auth_resp_packet)) {
+ change_auth_resp_packet.auth_data = auth_plugin_data;
+ change_auth_resp_packet.auth_data_len = auth_plugin_data_len;
+
+ if (!PACKET_WRITE(conn, &change_auth_resp_packet)) {
SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
+ PACKET_FREE(&change_auth_resp_packet);
goto end;
}
+ PACKET_FREE(&change_auth_resp_packet);
} else {
- auth_packet = conn->payload_decoder_factory->m.get_auth_packet(conn->payload_decoder_factory, FALSE);
+ MYSQLND_PACKET_AUTH auth_packet;
+
+ conn->payload_decoder_factory->m.init_auth_packet(&auth_packet);
- auth_packet->client_flags = mysql_flags;
- auth_packet->max_packet_size = session_options->max_allowed_packet;
+ auth_packet.client_flags = mysql_flags;
+ auth_packet.max_packet_size = session_options->max_allowed_packet;
if (session_options->charset_name && (charset = mysqlnd_find_charset_name(session_options->charset_name))) {
- auth_packet->charset_no = charset->nr;
+ auth_packet.charset_no = charset->nr;
} else {
- auth_packet->charset_no = server_charset_no;
+ auth_packet.charset_no = server_charset_no;
}
- auth_packet->send_auth_data = TRUE;
- auth_packet->user = user;
- auth_packet->db = db;
- auth_packet->db_len = db_len;
+ auth_packet.send_auth_data = TRUE;
+ auth_packet.user = user;
+ auth_packet.db = db;
+ auth_packet.db_len = db_len;
- auth_packet->auth_data = auth_plugin_data;
- auth_packet->auth_data_len = auth_plugin_data_len;
- auth_packet->auth_plugin_name = auth_protocol;
+ auth_packet.auth_data = auth_plugin_data;
+ auth_packet.auth_data_len = auth_plugin_data_len;
+ auth_packet.auth_plugin_name = auth_protocol;
if (conn->server_capabilities & CLIENT_CONNECT_ATTRS) {
- auth_packet->connect_attr = conn->options->connect_attr;
+ auth_packet.connect_attr = conn->options->connect_attr;
}
- if (!PACKET_WRITE(auth_packet)) {
+ if (!PACKET_WRITE(conn, &auth_packet)) {
+ PACKET_FREE(&auth_packet);
goto end;
}
- }
- if (use_full_blown_auth_packet == TRUE) {
- conn->charset = mysqlnd_find_charset_nr(auth_packet->charset_no);
+
+ if (use_full_blown_auth_packet == TRUE) {
+ conn->charset = mysqlnd_find_charset_nr(auth_packet.charset_no);
+ }
+
+ PACKET_FREE(&auth_packet);
}
- if (auth_plugin && auth_plugin->methods.handle_server_response) {
- auth_plugin->methods.handle_server_response(auth_plugin, conn,
- orig_auth_plugin_data, orig_auth_plugin_data_len, passwd, passwd_len);
- }
-
- if (FAIL == PACKET_READ(auth_resp_packet) || auth_resp_packet->response_code >= 0xFE) {
- if (auth_resp_packet->response_code == 0xFE) {
+ if (FAIL == PACKET_READ(conn, &auth_resp_packet) || auth_resp_packet.response_code >= 0xFE) {
+ if (auth_resp_packet.response_code == 0xFE) {
/* old authentication with new server !*/
- if (!auth_resp_packet->new_auth_protocol) {
+ if (!auth_resp_packet.new_auth_protocol) {
DBG_ERR(mysqlnd_old_passwd);
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
} else {
struct st_mysqlnd_packet_auth_pam;
struct st_mysqlnd_packet_sha256_pk_request;
struct st_mysqlnd_packet_sha256_pk_request_response;
- struct st_mysqlnd_packet_cached_sha2_result;
-typedef struct st_mysqlnd_packet_greet * (*func_mysqlnd_protocol_payload_decoder_factory__get_greet_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_auth * (*func_mysqlnd_protocol_payload_decoder_factory__get_auth_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_auth_response *(*func_mysqlnd_protocol_payload_decoder_factory__get_auth_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_change_auth_response * (*func_mysqlnd_protocol_payload_decoder_factory__get_change_auth_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_ok * (*func_mysqlnd_protocol_payload_decoder_factory__get_ok_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_command * (*func_mysqlnd_protocol_payload_decoder_factory__get_command_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_eof * (*func_mysqlnd_protocol_payload_decoder_factory__get_eof_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_rset_header * (*func_mysqlnd_protocol_payload_decoder_factory__get_rset_header_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_res_field * (*func_mysqlnd_protocol_payload_decoder_factory__get_result_field_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_row * (*func_mysqlnd_protocol_payload_decoder_factory__get_row_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_stats * (*func_mysqlnd_protocol_payload_decoder_factory__get_stats_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_prepare_response *(*func_mysqlnd_protocol_payload_decoder_factory__get_prepare_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_chg_user_resp*(*func_mysqlnd_protocol_payload_decoder_factory__get_change_user_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_sha256_pk_request *(*func_mysqlnd_protocol_payload_decoder_factory__get_sha256_pk_request_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
-typedef struct st_mysqlnd_packet_sha256_pk_request_response *(*func_mysqlnd_protocol_payload_decoder_factory__get_sha256_pk_request_response_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_greet_packet)(struct st_mysqlnd_packet_greet *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_auth_packet)(struct st_mysqlnd_packet_auth *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_auth_response_packet)(struct st_mysqlnd_packet_auth_response *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_change_auth_response_packet)(struct st_mysqlnd_packet_change_auth_response *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_ok_packet)(struct st_mysqlnd_packet_ok *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_command_packet)(struct st_mysqlnd_packet_command *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_eof_packet)(struct st_mysqlnd_packet_eof *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_rset_header_packet)(struct st_mysqlnd_packet_rset_header *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_result_field_packet)(struct st_mysqlnd_packet_res_field *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_row_packet)(struct st_mysqlnd_packet_row *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_stats_packet)(struct st_mysqlnd_packet_stats *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_prepare_response_packet)(struct st_mysqlnd_packet_prepare_response *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet)(struct st_mysqlnd_packet_chg_user_resp *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet)(struct st_mysqlnd_packet_sha256_pk_request *packet);
+typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet)(struct st_mysqlnd_packet_sha256_pk_request_response *packet);
- typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet)(struct st_mysqlnd_packet_cached_sha2_result *packet);
typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command)(
MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * payload_decoder_factory,
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)
{
- func_mysqlnd_protocol_payload_decoder_factory__get_greet_packet get_greet_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_auth_packet get_auth_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_auth_response_packet get_auth_response_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_change_auth_response_packet get_change_auth_response_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_ok_packet get_ok_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_command_packet get_command_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_eof_packet get_eof_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_rset_header_packet get_rset_header_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_result_field_packet get_result_field_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_row_packet get_row_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_stats_packet get_stats_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_prepare_response_packet get_prepare_response_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_change_user_response_packet get_change_user_response_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_sha256_pk_request_packet get_sha256_pk_request_packet;
- func_mysqlnd_protocol_payload_decoder_factory__get_sha256_pk_request_response_packet get_sha256_pk_request_response_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_greet_packet init_greet_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_auth_packet init_auth_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_auth_response_packet init_auth_response_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_change_auth_response_packet init_change_auth_response_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_ok_packet init_ok_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_command_packet init_command_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_eof_packet init_eof_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_rset_header_packet init_rset_header_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_result_field_packet init_result_field_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_row_packet init_row_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_stats_packet init_stats_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_prepare_response_packet init_prepare_response_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet init_change_user_response_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet init_sha256_pk_request_packet;
+ func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet init_sha256_pk_request_response_packet;
- func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet init_cached_sha2_result_packet;
func_mysqlnd_protocol_payload_decoder_factory__send_command send_command;
func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response;
}
/* }}} */
- 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] =
php_mysqlnd_sha256_pk_request_response_read,
NULL, /* write */
php_mysqlnd_sha256_pk_request_response_free_mem,
- }, /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */
- {
- php_mysqlnd_cached_sha2_result_read,
- php_mysqlnd_cached_sha2_result_write,
- NULL
- } /* PROT_CACHED_SHA2_RESULT_PACKET */
+ } /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */
};
- /* }}} */
+ /* }}} */
-/* {{{ mysqlnd_protocol::get_greet_packet */
-static struct st_mysqlnd_packet_greet *
-MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet)(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const factory, const zend_bool persistent)
+/* {{{ mysqlnd_protocol::init_greet_packet */
+static void
+MYSQLND_METHOD(mysqlnd_protocol, init_greet_packet)(struct st_mysqlnd_packet_greet *packet)
{
- struct st_mysqlnd_packet_greet * packet = mnd_pecalloc(1, packet_methods[PROT_GREET_PACKET].struct_size, persistent);
- DBG_ENTER("mysqlnd_protocol::get_greet_packet");
- if (packet) {
- packet->header.m = &packet_methods[PROT_GREET_PACKET];
- packet->header.factory = factory;
-
- packet->header.protocol_frame_codec = factory->conn->protocol_frame_codec;
- packet->header.vio = factory->conn->vio;
- packet->header.stats = factory->conn->stats;
- packet->header.error_info = factory->conn->error_info;
- packet->header.connection_state = &factory->conn->state;
-
- packet->header.persistent = persistent;
- }
- DBG_RETURN(packet);
+ DBG_ENTER("mysqlnd_protocol::init_greet_packet");
+ memset(packet, 0, sizeof(*packet));
+ packet->header.m = &packet_methods[PROT_GREET_PACKET];
+ DBG_VOID_RETURN;
}
/* }}} */
MYSQLND_CLASS_METHODS_START(mysqlnd_protocol_payload_decoder_factory)
- MYSQLND_METHOD(mysqlnd_protocol, get_greet_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_auth_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_auth_response_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_change_auth_response_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_ok_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_command_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_eof_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_rset_header_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_result_field_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_row_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_stats_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_prepare_response_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_change_user_response_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_sha256_pk_request_packet),
- MYSQLND_METHOD(mysqlnd_protocol, get_sha256_pk_request_response_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_greet_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_auth_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_auth_response_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_change_auth_response_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_ok_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_command_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_eof_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_rset_header_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_result_field_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_row_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_stats_packet),
+ MYSQLND_METHOD(mysqlnd_protocol, init_prepare_response_packet),
+ 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),