MDL-54704 dml: support for SSL with MySQL / MariaDB and PostgreSQL
This commit is contained in:
@@ -44,6 +44,14 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
query_end as read_slave_query_end;
|
||||
}
|
||||
|
||||
/** @var array $sslmodes */
|
||||
private static $sslmodes = [
|
||||
'disable',
|
||||
'prefer',
|
||||
'require',
|
||||
'verify-full'
|
||||
];
|
||||
|
||||
/** @var array $serverinfo cache */
|
||||
private $serverinfo = [];
|
||||
|
||||
@@ -130,6 +138,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
|
||||
* @param array $dboptions driver specific options
|
||||
* @return bool true
|
||||
* @throws moodle_exception
|
||||
* @throws dml_connection_exception if error
|
||||
*/
|
||||
public function raw_connect(string $dbhost, string $dbuser, string $dbpass, string $dbname, $prefix, array $dboptions=null): bool {
|
||||
@@ -187,6 +196,14 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
$connection .= " options='" . implode(' ', $options) . "'";
|
||||
}
|
||||
|
||||
if (isset($this->dboptions['ssl'])) {
|
||||
$sslmode = $this->dboptions['ssl'];
|
||||
if (!in_array($sslmode, self::$sslmodes, true)) {
|
||||
throw new moodle_exception('validateerrorlist', 'admin', '', "'dboptions''ssl': $sslmode");
|
||||
}
|
||||
$connection .= " sslmode=$sslmode";
|
||||
}
|
||||
|
||||
ob_start();
|
||||
// It seems that pg_connect() handles some errors differently.
|
||||
// For example, name resolution error will raise an exception, and non-existing
|
||||
|
||||
Reference in New Issue
Block a user