Implement FR #48587 (MySQL PDO driver doesn't support SSL connections)

This commit is contained in:
Rob Richards 2011-04-15 14:24:40 +00:00
parent 92e5b10c41
commit 1b6dd18082
4 changed files with 44 additions and 2 deletions

4
NEWS
View File

@ -64,6 +64,10 @@ PHP NEWS
. Fixed bug #54167 (PDO_DBLIB returns null on SQLUNIQUE field).
(mjh at hodginsmedia dot com, Felipe)
- PDO MySQL driver:
. Implemented FR #48587 (MySQL PDO driver doesn't support SSL connections).
(Rob)
- PDO PostgreSQL driver:
. Fixed bug #54318 (Non-portable grep option used in PDO pgsql
configuration). (bwalton at artsci dot utoronto dot ca)

View File

@ -624,6 +624,9 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
#ifndef PDO_USE_MYSQLND
char *default_file = NULL, *default_group = NULL;
long compress = 0;
#endif
#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSLQND
char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL;
#endif
H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1 TSRMLS_CC);
@ -708,6 +711,32 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
goto cleanup;
}
}
#endif
#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSLQND
ssl_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_KEY, NULL TSRMLS_CC);
ssl_cert = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CERT, NULL TSRMLS_CC);
ssl_ca = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CA, NULL TSRMLS_CC);
ssl_capath = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CAPATH, NULL TSRMLS_CC);
ssl_cipher = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CIPHER, NULL TSRMLS_CC);
if (ssl_key || ssl_cert || ssl_ca || ssl_capath || ssl_cipher) {
mysql_ssl_set(H->server, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher);
if (ssl_key) {
efree(ssl_key);
}
if (ssl_cert) {
efree(ssl_cert);
}
if (ssl_ca) {
efree(ssl_ca);
}
if (ssl_capath) {
efree(ssl_capath);
}
if (ssl_cipher) {
efree(ssl_cipher);
}
}
#endif
}

View File

@ -79,7 +79,11 @@ static PHP_MINIT_FUNCTION(pdo_mysql)
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (long)PDO_MYSQL_ATTR_DIRECT_QUERY);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (long)PDO_MYSQL_ATTR_FOUND_ROWS);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (long)PDO_MYSQL_ATTR_IGNORE_SPACE);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_KEY", (long)PDO_MYSQL_ATTR_SSL_KEY);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CERT", (long)PDO_MYSQL_ATTR_SSL_CERT);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (long)PDO_MYSQL_ATTR_SSL_CA);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (long)PDO_MYSQL_ATTR_SSL_CAPATH);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (long)PDO_MYSQL_ATTR_SSL_CIPHER);
return php_pdo_register_driver(&pdo_mysql_driver);
}
/* }}} */

View File

@ -168,7 +168,12 @@ enum {
#endif
PDO_MYSQL_ATTR_DIRECT_QUERY,
PDO_MYSQL_ATTR_FOUND_ROWS,
PDO_MYSQL_ATTR_IGNORE_SPACE
PDO_MYSQL_ATTR_IGNORE_SPACE,
PDO_MYSQL_ATTR_SSL_KEY,
PDO_MYSQL_ATTR_SSL_CERT,
PDO_MYSQL_ATTR_SSL_CA,
PDO_MYSQL_ATTR_SSL_CAPATH,
PDO_MYSQL_ATTR_SSL_CIPHER
};
#endif