@@ -37,197 +37,197 @@ |
||
| 37 | 37 | * Takes care of creating and configuring Doctrine connections. |
| 38 | 38 | */ |
| 39 | 39 | class ConnectionFactory { |
| 40 | - /** |
|
| 41 | - * @var array |
|
| 42 | - * |
|
| 43 | - * Array mapping DBMS type to default connection parameters passed to |
|
| 44 | - * \Doctrine\DBAL\DriverManager::getConnection(). |
|
| 45 | - */ |
|
| 46 | - protected $defaultConnectionParams = [ |
|
| 47 | - 'mysql' => [ |
|
| 48 | - 'adapter' => '\OC\DB\AdapterMySQL', |
|
| 49 | - 'charset' => 'UTF8', |
|
| 50 | - 'driver' => 'pdo_mysql', |
|
| 51 | - 'wrapperClass' => 'OC\DB\Connection', |
|
| 52 | - ], |
|
| 53 | - 'oci' => [ |
|
| 54 | - 'adapter' => '\OC\DB\AdapterOCI8', |
|
| 55 | - 'charset' => 'AL32UTF8', |
|
| 56 | - 'driver' => 'oci8', |
|
| 57 | - 'wrapperClass' => 'OC\DB\OracleConnection', |
|
| 58 | - ], |
|
| 59 | - 'pgsql' => [ |
|
| 60 | - 'adapter' => '\OC\DB\AdapterPgSql', |
|
| 61 | - 'driver' => 'pdo_pgsql', |
|
| 62 | - 'wrapperClass' => 'OC\DB\Connection', |
|
| 63 | - ], |
|
| 64 | - 'sqlite3' => [ |
|
| 65 | - 'adapter' => '\OC\DB\AdapterSqlite', |
|
| 66 | - 'driver' => 'pdo_sqlite', |
|
| 67 | - 'wrapperClass' => 'OC\DB\Connection', |
|
| 68 | - ], |
|
| 69 | - ]; |
|
| 70 | - |
|
| 71 | - /** @var SystemConfig */ |
|
| 72 | - private $config; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * ConnectionFactory constructor. |
|
| 76 | - * |
|
| 77 | - * @param SystemConfig $systemConfig |
|
| 78 | - */ |
|
| 79 | - public function __construct(SystemConfig $systemConfig) { |
|
| 80 | - $this->config = $systemConfig; |
|
| 81 | - if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
| 82 | - $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4'; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @brief Get default connection parameters for a given DBMS. |
|
| 88 | - * @param string $type DBMS type |
|
| 89 | - * @throws \InvalidArgumentException If $type is invalid |
|
| 90 | - * @return array Default connection parameters. |
|
| 91 | - */ |
|
| 92 | - public function getDefaultConnectionParams($type) { |
|
| 93 | - $normalizedType = $this->normalizeType($type); |
|
| 94 | - if (!isset($this->defaultConnectionParams[$normalizedType])) { |
|
| 95 | - throw new \InvalidArgumentException("Unsupported type: $type"); |
|
| 96 | - } |
|
| 97 | - $result = $this->defaultConnectionParams[$normalizedType]; |
|
| 98 | - // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL |
|
| 99 | - // driver is missing. In this case, we won't be able to connect anyway. |
|
| 100 | - if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { |
|
| 101 | - $result['driverOptions'] = array( |
|
| 102 | - \PDO::MYSQL_ATTR_FOUND_ROWS => true, |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - return $result; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @brief Get default connection parameters for a given DBMS. |
|
| 110 | - * @param string $type DBMS type |
|
| 111 | - * @param array $additionalConnectionParams Additional connection parameters |
|
| 112 | - * @return \OC\DB\Connection |
|
| 113 | - */ |
|
| 114 | - public function getConnection($type, $additionalConnectionParams) { |
|
| 115 | - $normalizedType = $this->normalizeType($type); |
|
| 116 | - $eventManager = new EventManager(); |
|
| 117 | - switch ($normalizedType) { |
|
| 118 | - case 'mysql': |
|
| 119 | - $eventManager->addEventSubscriber( |
|
| 120 | - new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); |
|
| 121 | - break; |
|
| 122 | - case 'oci': |
|
| 123 | - $eventManager->addEventSubscriber(new OracleSessionInit); |
|
| 124 | - // the driverOptions are unused in dbal and need to be mapped to the parameters |
|
| 125 | - if (isset($additionalConnectionParams['driverOptions'])) { |
|
| 126 | - $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); |
|
| 127 | - } |
|
| 128 | - $host = $additionalConnectionParams['host']; |
|
| 129 | - $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null; |
|
| 130 | - $dbName = $additionalConnectionParams['dbname']; |
|
| 131 | - |
|
| 132 | - // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string |
|
| 133 | - if ($host === '') { |
|
| 134 | - $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name |
|
| 135 | - } else { |
|
| 136 | - $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; |
|
| 137 | - } |
|
| 138 | - unset($additionalConnectionParams['host']); |
|
| 139 | - break; |
|
| 140 | - case 'sqlite3': |
|
| 141 | - $journalMode = $additionalConnectionParams['sqlite.journal_mode']; |
|
| 142 | - $additionalConnectionParams['platform'] = new OCSqlitePlatform(); |
|
| 143 | - $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode)); |
|
| 144 | - break; |
|
| 145 | - } |
|
| 146 | - /** @var Connection $connection */ |
|
| 147 | - $connection = DriverManager::getConnection( |
|
| 148 | - array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), |
|
| 149 | - new Configuration(), |
|
| 150 | - $eventManager |
|
| 151 | - ); |
|
| 152 | - return $connection; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @brief Normalize DBMS type |
|
| 157 | - * @param string $type DBMS type |
|
| 158 | - * @return string Normalized DBMS type |
|
| 159 | - */ |
|
| 160 | - public function normalizeType($type) { |
|
| 161 | - return $type === 'sqlite' ? 'sqlite3' : $type; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Checks whether the specified DBMS type is valid. |
|
| 166 | - * |
|
| 167 | - * @param string $type |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - public function isValidType($type) { |
|
| 171 | - $normalizedType = $this->normalizeType($type); |
|
| 172 | - return isset($this->defaultConnectionParams[$normalizedType]); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Create the connection parameters for the config |
|
| 177 | - * |
|
| 178 | - * @return array |
|
| 179 | - */ |
|
| 180 | - public function createConnectionParams() { |
|
| 181 | - $type = $this->config->getValue('dbtype', 'sqlite'); |
|
| 182 | - |
|
| 183 | - $connectionParams = [ |
|
| 184 | - 'user' => $this->config->getValue('dbuser', ''), |
|
| 185 | - 'password' => $this->config->getValue('dbpassword', ''), |
|
| 186 | - ]; |
|
| 187 | - $name = $this->config->getValue('dbname', 'owncloud'); |
|
| 188 | - |
|
| 189 | - if ($this->normalizeType($type) === 'sqlite3') { |
|
| 190 | - $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 191 | - $connectionParams['path'] = $dataDir . '/' . $name . '.db'; |
|
| 192 | - } else { |
|
| 193 | - $host = $this->config->getValue('dbhost', ''); |
|
| 194 | - if (strpos($host, ':')) { |
|
| 195 | - // Host variable may carry a port or socket. |
|
| 196 | - list($host, $portOrSocket) = explode(':', $host, 2); |
|
| 197 | - if (ctype_digit($portOrSocket)) { |
|
| 198 | - $connectionParams['port'] = $portOrSocket; |
|
| 199 | - } else { |
|
| 200 | - $connectionParams['unix_socket'] = $portOrSocket; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - $connectionParams['host'] = $host; |
|
| 204 | - $connectionParams['dbname'] = $name; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_'); |
|
| 208 | - $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); |
|
| 209 | - |
|
| 210 | - //additional driver options, eg. for mysql ssl |
|
| 211 | - $driverOptions = $this->config->getValue('dbdriveroptions', null); |
|
| 212 | - if ($driverOptions) { |
|
| 213 | - $connectionParams['driverOptions'] = $driverOptions; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // set default table creation options |
|
| 217 | - $connectionParams['defaultTableOptions'] = [ |
|
| 218 | - 'collate' => 'utf8_bin', |
|
| 219 | - 'tablePrefix' => $connectionParams['tablePrefix'] |
|
| 220 | - ]; |
|
| 221 | - |
|
| 222 | - if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
| 223 | - $connectionParams['defaultTableOptions'] = [ |
|
| 224 | - 'collate' => 'utf8mb4_bin', |
|
| 225 | - 'charset' => 'utf8mb4', |
|
| 226 | - 'row_format' => 'compressed', |
|
| 227 | - 'tablePrefix' => $connectionParams['tablePrefix'] |
|
| 228 | - ]; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $connectionParams; |
|
| 232 | - } |
|
| 40 | + /** |
|
| 41 | + * @var array |
|
| 42 | + * |
|
| 43 | + * Array mapping DBMS type to default connection parameters passed to |
|
| 44 | + * \Doctrine\DBAL\DriverManager::getConnection(). |
|
| 45 | + */ |
|
| 46 | + protected $defaultConnectionParams = [ |
|
| 47 | + 'mysql' => [ |
|
| 48 | + 'adapter' => '\OC\DB\AdapterMySQL', |
|
| 49 | + 'charset' => 'UTF8', |
|
| 50 | + 'driver' => 'pdo_mysql', |
|
| 51 | + 'wrapperClass' => 'OC\DB\Connection', |
|
| 52 | + ], |
|
| 53 | + 'oci' => [ |
|
| 54 | + 'adapter' => '\OC\DB\AdapterOCI8', |
|
| 55 | + 'charset' => 'AL32UTF8', |
|
| 56 | + 'driver' => 'oci8', |
|
| 57 | + 'wrapperClass' => 'OC\DB\OracleConnection', |
|
| 58 | + ], |
|
| 59 | + 'pgsql' => [ |
|
| 60 | + 'adapter' => '\OC\DB\AdapterPgSql', |
|
| 61 | + 'driver' => 'pdo_pgsql', |
|
| 62 | + 'wrapperClass' => 'OC\DB\Connection', |
|
| 63 | + ], |
|
| 64 | + 'sqlite3' => [ |
|
| 65 | + 'adapter' => '\OC\DB\AdapterSqlite', |
|
| 66 | + 'driver' => 'pdo_sqlite', |
|
| 67 | + 'wrapperClass' => 'OC\DB\Connection', |
|
| 68 | + ], |
|
| 69 | + ]; |
|
| 70 | + |
|
| 71 | + /** @var SystemConfig */ |
|
| 72 | + private $config; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * ConnectionFactory constructor. |
|
| 76 | + * |
|
| 77 | + * @param SystemConfig $systemConfig |
|
| 78 | + */ |
|
| 79 | + public function __construct(SystemConfig $systemConfig) { |
|
| 80 | + $this->config = $systemConfig; |
|
| 81 | + if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
| 82 | + $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4'; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @brief Get default connection parameters for a given DBMS. |
|
| 88 | + * @param string $type DBMS type |
|
| 89 | + * @throws \InvalidArgumentException If $type is invalid |
|
| 90 | + * @return array Default connection parameters. |
|
| 91 | + */ |
|
| 92 | + public function getDefaultConnectionParams($type) { |
|
| 93 | + $normalizedType = $this->normalizeType($type); |
|
| 94 | + if (!isset($this->defaultConnectionParams[$normalizedType])) { |
|
| 95 | + throw new \InvalidArgumentException("Unsupported type: $type"); |
|
| 96 | + } |
|
| 97 | + $result = $this->defaultConnectionParams[$normalizedType]; |
|
| 98 | + // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL |
|
| 99 | + // driver is missing. In this case, we won't be able to connect anyway. |
|
| 100 | + if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { |
|
| 101 | + $result['driverOptions'] = array( |
|
| 102 | + \PDO::MYSQL_ATTR_FOUND_ROWS => true, |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + return $result; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @brief Get default connection parameters for a given DBMS. |
|
| 110 | + * @param string $type DBMS type |
|
| 111 | + * @param array $additionalConnectionParams Additional connection parameters |
|
| 112 | + * @return \OC\DB\Connection |
|
| 113 | + */ |
|
| 114 | + public function getConnection($type, $additionalConnectionParams) { |
|
| 115 | + $normalizedType = $this->normalizeType($type); |
|
| 116 | + $eventManager = new EventManager(); |
|
| 117 | + switch ($normalizedType) { |
|
| 118 | + case 'mysql': |
|
| 119 | + $eventManager->addEventSubscriber( |
|
| 120 | + new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); |
|
| 121 | + break; |
|
| 122 | + case 'oci': |
|
| 123 | + $eventManager->addEventSubscriber(new OracleSessionInit); |
|
| 124 | + // the driverOptions are unused in dbal and need to be mapped to the parameters |
|
| 125 | + if (isset($additionalConnectionParams['driverOptions'])) { |
|
| 126 | + $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); |
|
| 127 | + } |
|
| 128 | + $host = $additionalConnectionParams['host']; |
|
| 129 | + $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null; |
|
| 130 | + $dbName = $additionalConnectionParams['dbname']; |
|
| 131 | + |
|
| 132 | + // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string |
|
| 133 | + if ($host === '') { |
|
| 134 | + $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name |
|
| 135 | + } else { |
|
| 136 | + $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; |
|
| 137 | + } |
|
| 138 | + unset($additionalConnectionParams['host']); |
|
| 139 | + break; |
|
| 140 | + case 'sqlite3': |
|
| 141 | + $journalMode = $additionalConnectionParams['sqlite.journal_mode']; |
|
| 142 | + $additionalConnectionParams['platform'] = new OCSqlitePlatform(); |
|
| 143 | + $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode)); |
|
| 144 | + break; |
|
| 145 | + } |
|
| 146 | + /** @var Connection $connection */ |
|
| 147 | + $connection = DriverManager::getConnection( |
|
| 148 | + array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), |
|
| 149 | + new Configuration(), |
|
| 150 | + $eventManager |
|
| 151 | + ); |
|
| 152 | + return $connection; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @brief Normalize DBMS type |
|
| 157 | + * @param string $type DBMS type |
|
| 158 | + * @return string Normalized DBMS type |
|
| 159 | + */ |
|
| 160 | + public function normalizeType($type) { |
|
| 161 | + return $type === 'sqlite' ? 'sqlite3' : $type; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Checks whether the specified DBMS type is valid. |
|
| 166 | + * |
|
| 167 | + * @param string $type |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + public function isValidType($type) { |
|
| 171 | + $normalizedType = $this->normalizeType($type); |
|
| 172 | + return isset($this->defaultConnectionParams[$normalizedType]); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Create the connection parameters for the config |
|
| 177 | + * |
|
| 178 | + * @return array |
|
| 179 | + */ |
|
| 180 | + public function createConnectionParams() { |
|
| 181 | + $type = $this->config->getValue('dbtype', 'sqlite'); |
|
| 182 | + |
|
| 183 | + $connectionParams = [ |
|
| 184 | + 'user' => $this->config->getValue('dbuser', ''), |
|
| 185 | + 'password' => $this->config->getValue('dbpassword', ''), |
|
| 186 | + ]; |
|
| 187 | + $name = $this->config->getValue('dbname', 'owncloud'); |
|
| 188 | + |
|
| 189 | + if ($this->normalizeType($type) === 'sqlite3') { |
|
| 190 | + $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 191 | + $connectionParams['path'] = $dataDir . '/' . $name . '.db'; |
|
| 192 | + } else { |
|
| 193 | + $host = $this->config->getValue('dbhost', ''); |
|
| 194 | + if (strpos($host, ':')) { |
|
| 195 | + // Host variable may carry a port or socket. |
|
| 196 | + list($host, $portOrSocket) = explode(':', $host, 2); |
|
| 197 | + if (ctype_digit($portOrSocket)) { |
|
| 198 | + $connectionParams['port'] = $portOrSocket; |
|
| 199 | + } else { |
|
| 200 | + $connectionParams['unix_socket'] = $portOrSocket; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + $connectionParams['host'] = $host; |
|
| 204 | + $connectionParams['dbname'] = $name; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_'); |
|
| 208 | + $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); |
|
| 209 | + |
|
| 210 | + //additional driver options, eg. for mysql ssl |
|
| 211 | + $driverOptions = $this->config->getValue('dbdriveroptions', null); |
|
| 212 | + if ($driverOptions) { |
|
| 213 | + $connectionParams['driverOptions'] = $driverOptions; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // set default table creation options |
|
| 217 | + $connectionParams['defaultTableOptions'] = [ |
|
| 218 | + 'collate' => 'utf8_bin', |
|
| 219 | + 'tablePrefix' => $connectionParams['tablePrefix'] |
|
| 220 | + ]; |
|
| 221 | + |
|
| 222 | + if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
| 223 | + $connectionParams['defaultTableOptions'] = [ |
|
| 224 | + 'collate' => 'utf8mb4_bin', |
|
| 225 | + 'charset' => 'utf8mb4', |
|
| 226 | + 'row_format' => 'compressed', |
|
| 227 | + 'tablePrefix' => $connectionParams['tablePrefix'] |
|
| 228 | + ]; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $connectionParams; |
|
| 232 | + } |
|
| 233 | 233 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | if ($host === '') { |
| 134 | 134 | $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name |
| 135 | 135 | } else { |
| 136 | - $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; |
|
| 136 | + $additionalConnectionParams['dbname'] = '//'.$host.(!empty($port) ? ":{$port}" : "").'/'.$dbName; |
|
| 137 | 137 | } |
| 138 | 138 | unset($additionalConnectionParams['host']); |
| 139 | 139 | break; |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | $name = $this->config->getValue('dbname', 'owncloud'); |
| 188 | 188 | |
| 189 | 189 | if ($this->normalizeType($type) === 'sqlite3') { |
| 190 | - $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 191 | - $connectionParams['path'] = $dataDir . '/' . $name . '.db'; |
|
| 190 | + $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT.'/data'); |
|
| 191 | + $connectionParams['path'] = $dataDir.'/'.$name.'.db'; |
|
| 192 | 192 | } else { |
| 193 | 193 | $host = $this->config->getValue('dbhost', ''); |
| 194 | 194 | if (strpos($host, ':')) { |
@@ -31,240 +31,240 @@ |
||
| 31 | 31 | namespace OC\Setup; |
| 32 | 32 | |
| 33 | 33 | class OCI extends AbstractDatabase { |
| 34 | - public $dbprettyname = 'Oracle'; |
|
| 34 | + public $dbprettyname = 'Oracle'; |
|
| 35 | 35 | |
| 36 | - protected $dbtablespace; |
|
| 36 | + protected $dbtablespace; |
|
| 37 | 37 | |
| 38 | - public function initialize($config) { |
|
| 39 | - parent::initialize($config); |
|
| 40 | - if (array_key_exists('dbtablespace', $config)) { |
|
| 41 | - $this->dbtablespace = $config['dbtablespace']; |
|
| 42 | - } else { |
|
| 43 | - $this->dbtablespace = 'USERS'; |
|
| 44 | - } |
|
| 45 | - // allow empty hostname for oracle |
|
| 46 | - $this->dbHost = $config['dbhost']; |
|
| 38 | + public function initialize($config) { |
|
| 39 | + parent::initialize($config); |
|
| 40 | + if (array_key_exists('dbtablespace', $config)) { |
|
| 41 | + $this->dbtablespace = $config['dbtablespace']; |
|
| 42 | + } else { |
|
| 43 | + $this->dbtablespace = 'USERS'; |
|
| 44 | + } |
|
| 45 | + // allow empty hostname for oracle |
|
| 46 | + $this->dbHost = $config['dbhost']; |
|
| 47 | 47 | |
| 48 | - $this->config->setValues([ |
|
| 49 | - 'dbhost' => $this->dbHost, |
|
| 50 | - 'dbtablespace' => $this->dbtablespace, |
|
| 51 | - ]); |
|
| 52 | - } |
|
| 48 | + $this->config->setValues([ |
|
| 49 | + 'dbhost' => $this->dbHost, |
|
| 50 | + 'dbtablespace' => $this->dbtablespace, |
|
| 51 | + ]); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function validate($config) { |
|
| 55 | - $errors = array(); |
|
| 56 | - if(empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 57 | - $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); |
|
| 58 | - } else if(empty($config['dbuser'])) { |
|
| 59 | - $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); |
|
| 60 | - } else if(empty($config['dbname'])) { |
|
| 61 | - $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); |
|
| 62 | - } |
|
| 63 | - return $errors; |
|
| 64 | - } |
|
| 54 | + public function validate($config) { |
|
| 55 | + $errors = array(); |
|
| 56 | + if(empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 57 | + $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); |
|
| 58 | + } else if(empty($config['dbuser'])) { |
|
| 59 | + $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); |
|
| 60 | + } else if(empty($config['dbname'])) { |
|
| 61 | + $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); |
|
| 62 | + } |
|
| 63 | + return $errors; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function setupDatabase($username) { |
|
| 67 | - $e_host = addslashes($this->dbHost); |
|
| 68 | - // casting to int to avoid malicious input |
|
| 69 | - $e_port = (int)$this->dbPort; |
|
| 70 | - $e_dbname = addslashes($this->dbName); |
|
| 71 | - //check if the database user has admin right |
|
| 72 | - if ($e_host == '') { |
|
| 73 | - $easy_connect_string = $e_dbname; // use dbname as easy connect name |
|
| 74 | - } else { |
|
| 75 | - $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; |
|
| 76 | - } |
|
| 77 | - $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']); |
|
| 78 | - $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
|
| 79 | - if(!$connection) { |
|
| 80 | - $errorMessage = $this->getLastError(); |
|
| 81 | - if ($errorMessage) { |
|
| 82 | - throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'), |
|
| 83 | - $errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') |
|
| 84 | - .' ORACLE_SID='.getenv('ORACLE_SID') |
|
| 85 | - .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
|
| 86 | - .' NLS_LANG='.getenv('NLS_LANG') |
|
| 87 | - .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 88 | - } |
|
| 89 | - throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
|
| 90 | - 'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') |
|
| 91 | - .' ORACLE_SID='.getenv('ORACLE_SID') |
|
| 92 | - .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
|
| 93 | - .' NLS_LANG='.getenv('NLS_LANG') |
|
| 94 | - .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 95 | - } |
|
| 96 | - //check for roles creation rights in oracle |
|
| 66 | + public function setupDatabase($username) { |
|
| 67 | + $e_host = addslashes($this->dbHost); |
|
| 68 | + // casting to int to avoid malicious input |
|
| 69 | + $e_port = (int)$this->dbPort; |
|
| 70 | + $e_dbname = addslashes($this->dbName); |
|
| 71 | + //check if the database user has admin right |
|
| 72 | + if ($e_host == '') { |
|
| 73 | + $easy_connect_string = $e_dbname; // use dbname as easy connect name |
|
| 74 | + } else { |
|
| 75 | + $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; |
|
| 76 | + } |
|
| 77 | + $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']); |
|
| 78 | + $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
|
| 79 | + if(!$connection) { |
|
| 80 | + $errorMessage = $this->getLastError(); |
|
| 81 | + if ($errorMessage) { |
|
| 82 | + throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'), |
|
| 83 | + $errorMessage.' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') |
|
| 84 | + .' ORACLE_SID='.getenv('ORACLE_SID') |
|
| 85 | + .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
|
| 86 | + .' NLS_LANG='.getenv('NLS_LANG') |
|
| 87 | + .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 88 | + } |
|
| 89 | + throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
|
| 90 | + 'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') |
|
| 91 | + .' ORACLE_SID='.getenv('ORACLE_SID') |
|
| 92 | + .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
|
| 93 | + .' NLS_LANG='.getenv('NLS_LANG') |
|
| 94 | + .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 95 | + } |
|
| 96 | + //check for roles creation rights in oracle |
|
| 97 | 97 | |
| 98 | - $query='SELECT count(*) FROM user_role_privs, role_sys_privs' |
|
| 99 | - ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; |
|
| 100 | - $stmt = oci_parse($connection, $query); |
|
| 101 | - if (!$stmt) { |
|
| 102 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 103 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 104 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 105 | - } |
|
| 106 | - $result = oci_execute($stmt); |
|
| 107 | - if($result) { |
|
| 108 | - $row = oci_fetch_row($stmt); |
|
| 98 | + $query='SELECT count(*) FROM user_role_privs, role_sys_privs' |
|
| 99 | + ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; |
|
| 100 | + $stmt = oci_parse($connection, $query); |
|
| 101 | + if (!$stmt) { |
|
| 102 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 103 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 104 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 105 | + } |
|
| 106 | + $result = oci_execute($stmt); |
|
| 107 | + if($result) { |
|
| 108 | + $row = oci_fetch_row($stmt); |
|
| 109 | 109 | |
| 110 | - if ($row[0] > 0) { |
|
| 111 | - //use the admin login data for the new database user |
|
| 110 | + if ($row[0] > 0) { |
|
| 111 | + //use the admin login data for the new database user |
|
| 112 | 112 | |
| 113 | - //add prefix to the oracle user name to prevent collisions |
|
| 114 | - $this->dbUser='oc_'.$username; |
|
| 115 | - //create a new password so we don't need to store the admin config in the config file |
|
| 116 | - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 113 | + //add prefix to the oracle user name to prevent collisions |
|
| 114 | + $this->dbUser='oc_'.$username; |
|
| 115 | + //create a new password so we don't need to store the admin config in the config file |
|
| 116 | + $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 117 | 117 | |
| 118 | - //oracle passwords are treated as identifiers: |
|
| 119 | - // must start with alphanumeric char |
|
| 120 | - // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. |
|
| 121 | - $this->dbPassword=substr($this->dbPassword, 0, 30); |
|
| 118 | + //oracle passwords are treated as identifiers: |
|
| 119 | + // must start with alphanumeric char |
|
| 120 | + // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. |
|
| 121 | + $this->dbPassword=substr($this->dbPassword, 0, 30); |
|
| 122 | 122 | |
| 123 | - $this->createDBUser($connection); |
|
| 124 | - } |
|
| 125 | - } |
|
| 123 | + $this->createDBUser($connection); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - $this->config->setValues([ |
|
| 128 | - 'dbuser' => $this->dbUser, |
|
| 129 | - 'dbname' => $this->dbName, |
|
| 130 | - 'dbpassword' => $this->dbPassword, |
|
| 131 | - ]); |
|
| 127 | + $this->config->setValues([ |
|
| 128 | + 'dbuser' => $this->dbUser, |
|
| 129 | + 'dbname' => $this->dbName, |
|
| 130 | + 'dbpassword' => $this->dbPassword, |
|
| 131 | + ]); |
|
| 132 | 132 | |
| 133 | - //create the database not necessary, oracle implies user = schema |
|
| 134 | - //$this->createDatabase($this->dbname, $this->dbuser, $connection); |
|
| 133 | + //create the database not necessary, oracle implies user = schema |
|
| 134 | + //$this->createDatabase($this->dbname, $this->dbuser, $connection); |
|
| 135 | 135 | |
| 136 | - //FIXME check tablespace exists: select * from user_tablespaces |
|
| 136 | + //FIXME check tablespace exists: select * from user_tablespaces |
|
| 137 | 137 | |
| 138 | - // the connection to dbname=oracle is not needed anymore |
|
| 139 | - oci_close($connection); |
|
| 138 | + // the connection to dbname=oracle is not needed anymore |
|
| 139 | + oci_close($connection); |
|
| 140 | 140 | |
| 141 | - // connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled |
|
| 142 | - $this->dbUser = $this->config->getValue('dbuser'); |
|
| 143 | - //$this->dbname = \OC_Config::getValue('dbname'); |
|
| 144 | - $this->dbPassword = $this->config->getValue('dbpassword'); |
|
| 141 | + // connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled |
|
| 142 | + $this->dbUser = $this->config->getValue('dbuser'); |
|
| 143 | + //$this->dbname = \OC_Config::getValue('dbname'); |
|
| 144 | + $this->dbPassword = $this->config->getValue('dbpassword'); |
|
| 145 | 145 | |
| 146 | - $e_host = addslashes($this->dbHost); |
|
| 147 | - $e_dbname = addslashes($this->dbName); |
|
| 146 | + $e_host = addslashes($this->dbHost); |
|
| 147 | + $e_dbname = addslashes($this->dbName); |
|
| 148 | 148 | |
| 149 | - if ($e_host == '') { |
|
| 150 | - $easy_connect_string = $e_dbname; // use dbname as easy connect name |
|
| 151 | - } else { |
|
| 152 | - $easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname; |
|
| 153 | - } |
|
| 154 | - $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
|
| 155 | - if(!$connection) { |
|
| 156 | - throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
|
| 157 | - $this->trans->t('You need to enter either an existing account or the administrator.')); |
|
| 158 | - } |
|
| 159 | - $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; |
|
| 160 | - $stmt = oci_parse($connection, $query); |
|
| 161 | - $un = $this->tablePrefix.'users'; |
|
| 162 | - oci_bind_by_name($stmt, ':un', $un); |
|
| 163 | - if (!$stmt) { |
|
| 164 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 165 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 166 | - $this->logger->warning( $entry, ['app' => 'setup.oci']); |
|
| 167 | - } |
|
| 168 | - $result = oci_execute($stmt); |
|
| 149 | + if ($e_host == '') { |
|
| 150 | + $easy_connect_string = $e_dbname; // use dbname as easy connect name |
|
| 151 | + } else { |
|
| 152 | + $easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname; |
|
| 153 | + } |
|
| 154 | + $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
|
| 155 | + if(!$connection) { |
|
| 156 | + throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
|
| 157 | + $this->trans->t('You need to enter either an existing account or the administrator.')); |
|
| 158 | + } |
|
| 159 | + $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; |
|
| 160 | + $stmt = oci_parse($connection, $query); |
|
| 161 | + $un = $this->tablePrefix.'users'; |
|
| 162 | + oci_bind_by_name($stmt, ':un', $un); |
|
| 163 | + if (!$stmt) { |
|
| 164 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 165 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 166 | + $this->logger->warning( $entry, ['app' => 'setup.oci']); |
|
| 167 | + } |
|
| 168 | + $result = oci_execute($stmt); |
|
| 169 | 169 | |
| 170 | - if($result) { |
|
| 171 | - $row = oci_fetch_row($stmt); |
|
| 172 | - } |
|
| 173 | - if(!$result or $row[0]==0) { |
|
| 174 | - \OC_DB::createDbFromStructure($this->dbDefinitionFile); |
|
| 175 | - } |
|
| 176 | - } |
|
| 170 | + if($result) { |
|
| 171 | + $row = oci_fetch_row($stmt); |
|
| 172 | + } |
|
| 173 | + if(!$result or $row[0]==0) { |
|
| 174 | + \OC_DB::createDbFromStructure($this->dbDefinitionFile); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * @param resource $connection |
|
| 180 | - */ |
|
| 181 | - private function createDBUser($connection) { |
|
| 182 | - $name = $this->dbUser; |
|
| 183 | - $password = $this->dbPassword; |
|
| 184 | - $query = "SELECT * FROM all_users WHERE USERNAME = :un"; |
|
| 185 | - $stmt = oci_parse($connection, $query); |
|
| 186 | - if (!$stmt) { |
|
| 187 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 188 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 189 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 190 | - } |
|
| 191 | - oci_bind_by_name($stmt, ':un', $name); |
|
| 192 | - $result = oci_execute($stmt); |
|
| 193 | - if(!$result) { |
|
| 194 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 195 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 196 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 197 | - } |
|
| 178 | + /** |
|
| 179 | + * @param resource $connection |
|
| 180 | + */ |
|
| 181 | + private function createDBUser($connection) { |
|
| 182 | + $name = $this->dbUser; |
|
| 183 | + $password = $this->dbPassword; |
|
| 184 | + $query = "SELECT * FROM all_users WHERE USERNAME = :un"; |
|
| 185 | + $stmt = oci_parse($connection, $query); |
|
| 186 | + if (!$stmt) { |
|
| 187 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 188 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 189 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 190 | + } |
|
| 191 | + oci_bind_by_name($stmt, ':un', $name); |
|
| 192 | + $result = oci_execute($stmt); |
|
| 193 | + if(!$result) { |
|
| 194 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 195 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 196 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - if(! oci_fetch_row($stmt)) { |
|
| 200 | - //user does not exists let's create it :) |
|
| 201 | - //password must start with alphabetic character in oracle |
|
| 202 | - $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace; |
|
| 203 | - $stmt = oci_parse($connection, $query); |
|
| 204 | - if (!$stmt) { |
|
| 205 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 206 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 207 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 199 | + if(! oci_fetch_row($stmt)) { |
|
| 200 | + //user does not exists let's create it :) |
|
| 201 | + //password must start with alphabetic character in oracle |
|
| 202 | + $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace; |
|
| 203 | + $stmt = oci_parse($connection, $query); |
|
| 204 | + if (!$stmt) { |
|
| 205 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 206 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 207 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 208 | 208 | |
| 209 | - } |
|
| 210 | - //oci_bind_by_name($stmt, ':un', $name); |
|
| 211 | - $result = oci_execute($stmt); |
|
| 212 | - if(!$result) { |
|
| 213 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 214 | - $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
|
| 215 | - array($query, $name, $password)) . '<br />'; |
|
| 216 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 209 | + } |
|
| 210 | + //oci_bind_by_name($stmt, ':un', $name); |
|
| 211 | + $result = oci_execute($stmt); |
|
| 212 | + if(!$result) { |
|
| 213 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 214 | + $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
|
| 215 | + array($query, $name, $password)) . '<br />'; |
|
| 216 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 217 | 217 | |
| 218 | - } |
|
| 219 | - } else { // change password of the existing role |
|
| 220 | - $query = "ALTER USER :un IDENTIFIED BY :pw"; |
|
| 221 | - $stmt = oci_parse($connection, $query); |
|
| 222 | - if (!$stmt) { |
|
| 223 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 224 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 225 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 226 | - } |
|
| 227 | - oci_bind_by_name($stmt, ':un', $name); |
|
| 228 | - oci_bind_by_name($stmt, ':pw', $password); |
|
| 229 | - $result = oci_execute($stmt); |
|
| 230 | - if(!$result) { |
|
| 231 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 232 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 233 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - // grant necessary roles |
|
| 237 | - $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; |
|
| 238 | - $stmt = oci_parse($connection, $query); |
|
| 239 | - if (!$stmt) { |
|
| 240 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 241 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 242 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 243 | - } |
|
| 244 | - $result = oci_execute($stmt); |
|
| 245 | - if(!$result) { |
|
| 246 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 247 | - $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
|
| 248 | - array($query, $name, $password)) . '<br />'; |
|
| 249 | - $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 250 | - } |
|
| 251 | - } |
|
| 218 | + } |
|
| 219 | + } else { // change password of the existing role |
|
| 220 | + $query = "ALTER USER :un IDENTIFIED BY :pw"; |
|
| 221 | + $stmt = oci_parse($connection, $query); |
|
| 222 | + if (!$stmt) { |
|
| 223 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 224 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 225 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 226 | + } |
|
| 227 | + oci_bind_by_name($stmt, ':un', $name); |
|
| 228 | + oci_bind_by_name($stmt, ':pw', $password); |
|
| 229 | + $result = oci_execute($stmt); |
|
| 230 | + if(!$result) { |
|
| 231 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 232 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 233 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + // grant necessary roles |
|
| 237 | + $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; |
|
| 238 | + $stmt = oci_parse($connection, $query); |
|
| 239 | + if (!$stmt) { |
|
| 240 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 241 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 242 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 243 | + } |
|
| 244 | + $result = oci_execute($stmt); |
|
| 245 | + if(!$result) { |
|
| 246 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 247 | + $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
|
| 248 | + array($query, $name, $password)) . '<br />'; |
|
| 249 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * @param resource $connection |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - protected function getLastError($connection = null) { |
|
| 258 | - if ($connection) { |
|
| 259 | - $error = oci_error($connection); |
|
| 260 | - } else { |
|
| 261 | - $error = oci_error(); |
|
| 262 | - } |
|
| 263 | - foreach (array('message', 'code') as $key) { |
|
| 264 | - if (isset($error[$key])) { |
|
| 265 | - return $error[$key]; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - return ''; |
|
| 269 | - } |
|
| 253 | + /** |
|
| 254 | + * @param resource $connection |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + protected function getLastError($connection = null) { |
|
| 258 | + if ($connection) { |
|
| 259 | + $error = oci_error($connection); |
|
| 260 | + } else { |
|
| 261 | + $error = oci_error(); |
|
| 262 | + } |
|
| 263 | + foreach (array('message', 'code') as $key) { |
|
| 264 | + if (isset($error[$key])) { |
|
| 265 | + return $error[$key]; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + return ''; |
|
| 269 | + } |
|
| 270 | 270 | } |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function validate($config) { |
| 55 | 55 | $errors = array(); |
| 56 | - if(empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 56 | + if (empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 57 | 57 | $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); |
| 58 | - } else if(empty($config['dbuser'])) { |
|
| 58 | + } else if (empty($config['dbuser'])) { |
|
| 59 | 59 | $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); |
| 60 | - } else if(empty($config['dbname'])) { |
|
| 60 | + } else if (empty($config['dbname'])) { |
|
| 61 | 61 | $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); |
| 62 | 62 | } |
| 63 | 63 | return $errors; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function setupDatabase($username) { |
| 67 | 67 | $e_host = addslashes($this->dbHost); |
| 68 | 68 | // casting to int to avoid malicious input |
| 69 | - $e_port = (int)$this->dbPort; |
|
| 69 | + $e_port = (int) $this->dbPort; |
|
| 70 | 70 | $e_dbname = addslashes($this->dbName); |
| 71 | 71 | //check if the database user has admin right |
| 72 | 72 | if ($e_host == '') { |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | } else { |
| 75 | 75 | $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; |
| 76 | 76 | } |
| 77 | - $this->logger->debug('connect string: ' . $easy_connect_string, ['app' => 'setup.oci']); |
|
| 77 | + $this->logger->debug('connect string: '.$easy_connect_string, ['app' => 'setup.oci']); |
|
| 78 | 78 | $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
| 79 | - if(!$connection) { |
|
| 79 | + if (!$connection) { |
|
| 80 | 80 | $errorMessage = $this->getLastError(); |
| 81 | 81 | if ($errorMessage) { |
| 82 | 82 | throw new \OC\DatabaseSetupException($this->trans->t('Oracle connection could not be established'), |
@@ -84,41 +84,41 @@ discard block |
||
| 84 | 84 | .' ORACLE_SID='.getenv('ORACLE_SID') |
| 85 | 85 | .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
| 86 | 86 | .' NLS_LANG='.getenv('NLS_LANG') |
| 87 | - .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 87 | + .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora') ? '' : 'not ').'readable'); |
|
| 88 | 88 | } |
| 89 | 89 | throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
| 90 | 90 | 'Check environment: ORACLE_HOME='.getenv('ORACLE_HOME') |
| 91 | 91 | .' ORACLE_SID='.getenv('ORACLE_SID') |
| 92 | 92 | .' LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH') |
| 93 | 93 | .' NLS_LANG='.getenv('NLS_LANG') |
| 94 | - .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora')?'':'not ').'readable'); |
|
| 94 | + .' tnsnames.ora is '.(is_readable(getenv('ORACLE_HOME').'/network/admin/tnsnames.ora') ? '' : 'not ').'readable'); |
|
| 95 | 95 | } |
| 96 | 96 | //check for roles creation rights in oracle |
| 97 | 97 | |
| 98 | - $query='SELECT count(*) FROM user_role_privs, role_sys_privs' |
|
| 98 | + $query = 'SELECT count(*) FROM user_role_privs, role_sys_privs' |
|
| 99 | 99 | ." WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; |
| 100 | 100 | $stmt = oci_parse($connection, $query); |
| 101 | 101 | if (!$stmt) { |
| 102 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 103 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 102 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 103 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 104 | 104 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 105 | 105 | } |
| 106 | 106 | $result = oci_execute($stmt); |
| 107 | - if($result) { |
|
| 107 | + if ($result) { |
|
| 108 | 108 | $row = oci_fetch_row($stmt); |
| 109 | 109 | |
| 110 | 110 | if ($row[0] > 0) { |
| 111 | 111 | //use the admin login data for the new database user |
| 112 | 112 | |
| 113 | 113 | //add prefix to the oracle user name to prevent collisions |
| 114 | - $this->dbUser='oc_'.$username; |
|
| 114 | + $this->dbUser = 'oc_'.$username; |
|
| 115 | 115 | //create a new password so we don't need to store the admin config in the config file |
| 116 | 116 | $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
| 117 | 117 | |
| 118 | 118 | //oracle passwords are treated as identifiers: |
| 119 | 119 | // must start with alphanumeric char |
| 120 | 120 | // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. |
| 121 | - $this->dbPassword=substr($this->dbPassword, 0, 30); |
|
| 121 | + $this->dbPassword = substr($this->dbPassword, 0, 30); |
|
| 122 | 122 | |
| 123 | 123 | $this->createDBUser($connection); |
| 124 | 124 | } |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | if ($e_host == '') { |
| 150 | 150 | $easy_connect_string = $e_dbname; // use dbname as easy connect name |
| 151 | 151 | } else { |
| 152 | - $easy_connect_string = '//' . $e_host . (!empty($e_port) ? ":{$e_port}" : "") . '/' . $e_dbname; |
|
| 152 | + $easy_connect_string = '//'.$e_host.(!empty($e_port) ? ":{$e_port}" : "").'/'.$e_dbname; |
|
| 153 | 153 | } |
| 154 | 154 | $connection = @oci_connect($this->dbUser, $this->dbPassword, $easy_connect_string); |
| 155 | - if(!$connection) { |
|
| 155 | + if (!$connection) { |
|
| 156 | 156 | throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), |
| 157 | 157 | $this->trans->t('You need to enter either an existing account or the administrator.')); |
| 158 | 158 | } |
@@ -161,16 +161,16 @@ discard block |
||
| 161 | 161 | $un = $this->tablePrefix.'users'; |
| 162 | 162 | oci_bind_by_name($stmt, ':un', $un); |
| 163 | 163 | if (!$stmt) { |
| 164 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 165 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 166 | - $this->logger->warning( $entry, ['app' => 'setup.oci']); |
|
| 164 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 165 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 166 | + $this->logger->warning($entry, ['app' => 'setup.oci']); |
|
| 167 | 167 | } |
| 168 | 168 | $result = oci_execute($stmt); |
| 169 | 169 | |
| 170 | - if($result) { |
|
| 170 | + if ($result) { |
|
| 171 | 171 | $row = oci_fetch_row($stmt); |
| 172 | 172 | } |
| 173 | - if(!$result or $row[0]==0) { |
|
| 173 | + if (!$result or $row[0] == 0) { |
|
| 174 | 174 | \OC_DB::createDbFromStructure($this->dbDefinitionFile); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -184,35 +184,35 @@ discard block |
||
| 184 | 184 | $query = "SELECT * FROM all_users WHERE USERNAME = :un"; |
| 185 | 185 | $stmt = oci_parse($connection, $query); |
| 186 | 186 | if (!$stmt) { |
| 187 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 188 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 187 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 188 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 189 | 189 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 190 | 190 | } |
| 191 | 191 | oci_bind_by_name($stmt, ':un', $name); |
| 192 | 192 | $result = oci_execute($stmt); |
| 193 | - if(!$result) { |
|
| 194 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 195 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 193 | + if (!$result) { |
|
| 194 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 195 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 196 | 196 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if(! oci_fetch_row($stmt)) { |
|
| 199 | + if (!oci_fetch_row($stmt)) { |
|
| 200 | 200 | //user does not exists let's create it :) |
| 201 | 201 | //password must start with alphabetic character in oracle |
| 202 | 202 | $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$this->dbtablespace; |
| 203 | 203 | $stmt = oci_parse($connection, $query); |
| 204 | 204 | if (!$stmt) { |
| 205 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 206 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 205 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 206 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 207 | 207 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 208 | 208 | |
| 209 | 209 | } |
| 210 | 210 | //oci_bind_by_name($stmt, ':un', $name); |
| 211 | 211 | $result = oci_execute($stmt); |
| 212 | - if(!$result) { |
|
| 213 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 212 | + if (!$result) { |
|
| 213 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 214 | 214 | $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
| 215 | - array($query, $name, $password)) . '<br />'; |
|
| 215 | + array($query, $name, $password)).'<br />'; |
|
| 216 | 216 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 217 | 217 | |
| 218 | 218 | } |
@@ -220,16 +220,16 @@ discard block |
||
| 220 | 220 | $query = "ALTER USER :un IDENTIFIED BY :pw"; |
| 221 | 221 | $stmt = oci_parse($connection, $query); |
| 222 | 222 | if (!$stmt) { |
| 223 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 224 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 223 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 224 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 225 | 225 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 226 | 226 | } |
| 227 | 227 | oci_bind_by_name($stmt, ':un', $name); |
| 228 | 228 | oci_bind_by_name($stmt, ':pw', $password); |
| 229 | 229 | $result = oci_execute($stmt); |
| 230 | - if(!$result) { |
|
| 231 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 232 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 230 | + if (!$result) { |
|
| 231 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 232 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 233 | 233 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 234 | 234 | } |
| 235 | 235 | } |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; |
| 238 | 238 | $stmt = oci_parse($connection, $query); |
| 239 | 239 | if (!$stmt) { |
| 240 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 241 | - $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; |
|
| 240 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 241 | + $entry .= $this->trans->t('Offending command was: "%s"', array($query)).'<br />'; |
|
| 242 | 242 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 243 | 243 | } |
| 244 | 244 | $result = oci_execute($stmt); |
| 245 | - if(!$result) { |
|
| 246 | - $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; |
|
| 245 | + if (!$result) { |
|
| 246 | + $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))).'<br />'; |
|
| 247 | 247 | $entry .= $this->trans->t('Offending command was: "%s", name: %s, password: %s', |
| 248 | - array($query, $name, $password)) . '<br />'; |
|
| 248 | + array($query, $name, $password)).'<br />'; |
|
| 249 | 249 | $this->logger->warning($entry, ['app' => 'setup.oci']); |
| 250 | 250 | } |
| 251 | 251 | } |