@@ -54,11 +54,13 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
54
54
MY_MYSQL * mysql = NULL ;
55
55
MYSQLI_RESOURCE * mysqli_resource = NULL ;
56
56
zval * object = getThis ();
57
- char * hostname = NULL , * username = NULL , * passwd = NULL , * dbname = NULL , * socket = NULL ;
58
- size_t hostname_len = 0 , username_len = 0 , passwd_len = 0 , dbname_len = 0 , socket_len = 0 ;
59
- zend_bool persistent = FALSE;
60
- zend_long port = 0 , flags = 0 ;
61
- zend_bool port_is_null = 1 ;
57
+ char * hostname = NULL , * username = NULL , * passwd = NULL , * dbname = NULL , * socket = NULL ,
58
+ * ssl_key = NULL , * ssl_cert = NULL , * ssl_ca = NULL , * ssl_capath = NULL ,
59
+ * ssl_cipher = NULL ;
60
+ size_t hostname_len = 0 , username_len = 0 , passwd_len = 0 , dbname_len = 0 , socket_len = 0 ;
61
+ zend_bool persistent = FALSE, ssl = FALSE;
62
+ zend_long port = 0 , flags = 0 ;
63
+ zend_bool port_is_null = 1 ;
62
64
zend_string * hash_key = NULL ;
63
65
zend_bool new_connection = FALSE;
64
66
zend_resource * le ;
@@ -188,6 +190,33 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
188
190
189
191
goto end ;
190
192
} else {
193
+ #ifdef MYSQLI_USE_MYSQLND
194
+ if (mysql -> mysql -> data -> vio -> data -> ssl ) {
195
+ /* copy over pre-existing ssl settings so we can reuse them when reconnecting */
196
+ ssl = TRUE;
197
+
198
+ ssl_key = mysql -> mysql -> data -> vio -> data -> options .ssl_key ? estrdup (mysql -> mysql -> data -> vio -> data -> options .ssl_key ) : NULL ;
199
+ ssl_cert = mysql -> mysql -> data -> vio -> data -> options .ssl_cert ? estrdup (mysql -> mysql -> data -> vio -> data -> options .ssl_cert ) : NULL ;
200
+ ssl_ca = mysql -> mysql -> data -> vio -> data -> options .ssl_ca ? estrdup (mysql -> mysql -> data -> vio -> data -> options .ssl_ca ) : NULL ;
201
+ ssl_capath = mysql -> mysql -> data -> vio -> data -> options .ssl_capath ? estrdup (mysql -> mysql -> data -> vio -> data -> options .ssl_capath ) : NULL ;
202
+ ssl_cipher = mysql -> mysql -> data -> vio -> data -> options .ssl_cipher ? estrdup (mysql -> mysql -> data -> vio -> data -> options .ssl_cipher ) : NULL ;
203
+ }
204
+ #else
205
+ if (mysql -> mysql -> options .ssl_key
206
+ || mysql -> mysql -> options .ssl_cert
207
+ || mysql -> mysql -> options .ssl_ca
208
+ || mysql -> mysql -> options .ssl_capath
209
+ || mysql -> mysql -> options .ssl_cipher ) {
210
+ /* copy over pre-existing ssl settings so we can reuse them when reconnecting */
211
+ ssl = TRUE;
212
+
213
+ ssl_key = mysql -> mysql -> options .ssl_key ? estrdup (mysql -> mysql -> options .ssl_key ) : NULL ;
214
+ ssl_cert = mysql -> mysql -> options .ssl_cert ? estrdup (mysql -> mysql -> options .ssl_cert ) : NULL ;
215
+ ssl_ca = mysql -> mysql -> options .ssl_ca ? estrdup (mysql -> mysql -> options .ssl_ca ) : NULL ;
216
+ ssl_capath = mysql -> mysql -> options .ssl_capath ? estrdup (mysql -> mysql -> options .ssl_capath ) : NULL ;
217
+ ssl_cipher = mysql -> mysql -> options .ssl_cipher ? estrdup (mysql -> mysql -> options .ssl_cipher ) : NULL ;
218
+ }
219
+ #endif
191
220
mysqli_close (mysql -> mysql , MYSQLI_CLOSE_IMPLICIT );
192
221
mysql -> mysql = NULL ;
193
222
}
@@ -229,8 +258,56 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
229
258
/* BC for prior to bug fix #53425 */
230
259
flags |= CLIENT_MULTI_RESULTS ;
231
260
261
+ if (ssl ) {
262
+ /* if we're here, this means previous conn was ssl, repopulate settings */
263
+ mysql_ssl_set (mysql -> mysql , ssl_key , ssl_cert , ssl_ca , ssl_capath , ssl_cipher );
264
+
265
+ if (ssl_key ) {
266
+ efree (ssl_key );
267
+ }
268
+
269
+ if (ssl_cert ) {
270
+ efree (ssl_cert );
271
+ }
272
+
273
+ if (ssl_ca ) {
274
+ efree (ssl_ca );
275
+ }
276
+
277
+ if (ssl_capath ) {
278
+ efree (ssl_capath );
279
+ }
280
+
281
+ if (ssl_cipher ) {
282
+ efree (ssl_cipher );
283
+ }
284
+ }
232
285
if (mysql_real_connect (mysql -> mysql , hostname , username , passwd , dbname , port , socket , flags ) == NULL )
233
286
#else
287
+ if (ssl ) {
288
+ /* if we're here, this means previous conn was ssl, repopulate settings */
289
+ mysql_ssl_set (mysql -> mysql , ssl_key , ssl_cert , ssl_ca , ssl_capath , ssl_cipher );
290
+
291
+ if (ssl_key ) {
292
+ efree (ssl_key );
293
+ }
294
+
295
+ if (ssl_cert ) {
296
+ efree (ssl_cert );
297
+ }
298
+
299
+ if (ssl_ca ) {
300
+ efree (ssl_ca );
301
+ }
302
+
303
+ if (ssl_capath ) {
304
+ efree (ssl_capath );
305
+ }
306
+
307
+ if (ssl_cipher ) {
308
+ efree (ssl_cipher );
309
+ }
310
+ }
234
311
if (mysqlnd_connect (mysql -> mysql , hostname , username , passwd , passwd_len , dbname , dbname_len ,
235
312
port , socket , flags , MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA ) == NULL )
236
313
#endif
0 commit comments