@@ -136,6 +136,7 @@ mysqlnd_run_authentication(
136
136
ret = mysqlnd_auth_change_user (conn , user , strlen (user ), passwd , passwd_len , db , db_len , silent ,
137
137
first_call ,
138
138
requested_protocol ,
139
+ auth_plugin , plugin_data , plugin_data_len ,
139
140
scrambled_data , scrambled_data_len ,
140
141
& switch_to_auth_protocol , & switch_to_auth_protocol_len ,
141
142
& switch_to_auth_protocol_data , & switch_to_auth_protocol_data_len
@@ -318,8 +319,12 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
318
319
}
319
320
320
321
if (auth_plugin && auth_plugin -> methods .handle_server_response ) {
321
- auth_plugin -> methods .handle_server_response (auth_plugin , conn ,
322
- orig_auth_plugin_data , orig_auth_plugin_data_len , passwd , passwd_len );
322
+ if (FAIL == auth_plugin -> methods .handle_server_response (auth_plugin , conn ,
323
+ orig_auth_plugin_data , orig_auth_plugin_data_len , passwd , passwd_len ,
324
+ switch_to_auth_protocol , switch_to_auth_protocol_len ,
325
+ switch_to_auth_protocol_data , switch_to_auth_protocol_data_len )) {
326
+ goto end ;
327
+ }
323
328
}
324
329
325
330
if (FAIL == PACKET_READ (conn , & auth_resp_packet ) || auth_resp_packet .response_code >= 0xFE ) {
@@ -371,6 +376,9 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
371
376
const zend_bool silent ,
372
377
const zend_bool use_full_blown_auth_packet ,
373
378
const char * const auth_protocol ,
379
+ struct st_mysqlnd_authentication_plugin * auth_plugin ,
380
+ const zend_uchar * const orig_auth_plugin_data ,
381
+ const size_t orig_auth_plugin_data_len ,
374
382
const zend_uchar * const auth_plugin_data ,
375
383
const size_t auth_plugin_data_len ,
376
384
char * * switch_to_auth_protocol ,
@@ -436,6 +444,15 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
436
444
PACKET_FREE (& auth_packet );
437
445
}
438
446
447
+ if (auth_plugin && auth_plugin -> methods .handle_server_response ) {
448
+ if (FAIL == auth_plugin -> methods .handle_server_response (auth_plugin , conn ,
449
+ orig_auth_plugin_data , orig_auth_plugin_data_len , passwd , passwd_len ,
450
+ switch_to_auth_protocol , switch_to_auth_protocol_len ,
451
+ switch_to_auth_protocol_data , switch_to_auth_protocol_data_len )) {
452
+ goto end ;
453
+ }
454
+ }
455
+
439
456
ret = PACKET_READ (conn , & chg_user_resp );
440
457
COPY_CLIENT_ERROR (conn -> error_info , chg_user_resp .error_info );
441
458
@@ -1026,47 +1043,77 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,
1026
1043
}
1027
1044
/* }}} */
1028
1045
1029
- /* {{{ mysqlnd_native_auth_get_auth_data */
1030
- static void
1046
+ static int is_secure_transport (MYSQLND_CONN_DATA * conn ) {
1047
+ if (conn -> vio -> data -> ssl ) {
1048
+ return 1 ;
1049
+ }
1050
+
1051
+ return strcmp (conn -> vio -> data -> stream -> ops -> label , "unix_socket" ) == 0 ;
1052
+ }
1053
+
1054
+ /* {{{ mysqlnd_caching_sha2_handle_server_response */
1055
+ static enum_func_status
1031
1056
mysqlnd_caching_sha2_handle_server_response (struct st_mysqlnd_authentication_plugin * self ,
1032
1057
MYSQLND_CONN_DATA * conn ,
1033
1058
const zend_uchar * auth_plugin_data , const size_t auth_plugin_data_len ,
1034
1059
const char * const passwd ,
1035
- const size_t passwd_len )
1060
+ const size_t passwd_len ,
1061
+ char * * new_auth_protocol , size_t * new_auth_protocol_len ,
1062
+ zend_uchar * * new_auth_protocol_data , size_t * new_auth_protocol_data_len
1063
+ )
1036
1064
{
1037
1065
DBG_ENTER ("mysqlnd_caching_sha2_handle_server_response" );
1038
1066
MYSQLND_PACKET_CACHED_SHA2_RESULT result_packet ;
1039
- conn -> payload_decoder_factory -> m .init_cached_sha2_result_packet (& result_packet );
1040
1067
1068
+ if (passwd_len == 0 ) {
1069
+ DBG_INF ("empty password fast path" );
1070
+ DBG_RETURN (PASS );
1071
+ }
1072
+
1073
+ conn -> payload_decoder_factory -> m .init_cached_sha2_result_packet (& result_packet );
1041
1074
if (FAIL == PACKET_READ (conn , & result_packet )) {
1042
- DBG_VOID_RETURN ;
1075
+ DBG_RETURN ( PASS ) ;
1043
1076
}
1044
1077
1045
1078
switch (result_packet .response_code ) {
1079
+ case 0xFF :
1080
+ if (result_packet .sqlstate [0 ]) {
1081
+ strlcpy (conn -> error_info -> sqlstate , result_packet .sqlstate , sizeof (conn -> error_info -> sqlstate ));
1082
+ DBG_ERR_FMT ("ERROR:%u [SQLSTATE:%s] %s" , result_packet .error_no , result_packet .sqlstate , result_packet .error );
1083
+ }
1084
+ SET_CLIENT_ERROR (conn -> error_info , result_packet .error_no , UNKNOWN_SQLSTATE , result_packet .error );
1085
+ DBG_RETURN (FAIL );
1086
+ case 0xFE :
1087
+ DBG_INF ("auth switch response" );
1088
+ * new_auth_protocol = result_packet .new_auth_protocol ;
1089
+ * new_auth_protocol_len = result_packet .new_auth_protocol_len ;
1090
+ * new_auth_protocol_data = result_packet .new_auth_protocol_data ;
1091
+ * new_auth_protocol_data_len = result_packet .new_auth_protocol_data_len ;
1092
+ DBG_RETURN (FAIL );
1046
1093
case 3 :
1047
1094
DBG_INF ("fast path succeeded" );
1048
- DBG_VOID_RETURN ;
1095
+ DBG_RETURN ( PASS ) ;
1049
1096
case 4 :
1050
- if (conn -> vio -> data -> ssl || conn -> unix_socket . s ) {
1051
- DBG_INF ("fast path failed, doing full auth via SSL " );
1097
+ if (is_secure_transport ( conn ) ) {
1098
+ DBG_INF ("fast path failed, doing full auth via secure transport " );
1052
1099
result_packet .password = (zend_uchar * )passwd ;
1053
1100
result_packet .password_len = passwd_len + 1 ;
1054
1101
PACKET_WRITE (conn , & result_packet );
1055
1102
} else {
1056
- DBG_INF ("fast path failed, doing full auth without SSL " );
1103
+ DBG_INF ("fast path failed, doing full auth via insecure transport " );
1057
1104
result_packet .password_len = mysqlnd_caching_sha2_get_and_use_key (conn , auth_plugin_data , auth_plugin_data_len , & result_packet .password , passwd , passwd_len );
1058
1105
PACKET_WRITE (conn , & result_packet );
1059
1106
efree (result_packet .password );
1060
1107
}
1061
- DBG_VOID_RETURN ;
1108
+ DBG_RETURN ( PASS ) ;
1062
1109
case 2 :
1063
1110
// The server tried to send a key, which we didn't expect
1064
1111
// fall-through
1065
1112
default :
1066
1113
php_error_docref (NULL , E_WARNING , "Unexpected server response while doing caching_sha2 auth: %i" , result_packet .response_code );
1067
1114
}
1068
1115
1069
- DBG_VOID_RETURN ;
1116
+ DBG_RETURN ( PASS ) ;
1070
1117
}
1071
1118
/* }}} */
1072
1119
0 commit comments