Skip to content

Commit 29fe029

Browse files
committed
fix(core): remove duplicate MySQL user prefix
PR #53212 implemented a hardcoded database username, instead of deriving it from the Nextcloud admin username, to be able to setup Nextcloud without admin user. This has the additional benefit that knowing one of them does not allow to derive the other. However, it used `oc_admin`, while the MySQL database setup adds `oc_` again in the dedicated `createSpecificUser()` function, resulting in `oc_oc_admin`. In case of PostgreSQL, this was done in `setupDatabase()`, replaced with the hardcoded username. Signed-off-by: MichaIng <micha@dietpi.com>
1 parent e761005 commit 29fe029

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/private/Setup/MySQL.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,22 @@ private function createSpecificUser(string $username, IDBConnection $connection)
142142

143143
//we don't have a dbuser specified in config
144144
if ($this->dbUser !== $oldUser) {
145-
//add prefix to the admin username to prevent collisions
146-
$adminUser = substr('oc_' . $username, 0, 16);
147-
148145
$i = 1;
149146
while (true) {
147+
//cap to 16 characters
148+
$username = substr($username, 0, 16);
149+
150150
//this should be enough to check for admin rights in mysql
151151
$query = 'SELECT user FROM mysql.user WHERE user=?';
152-
$result = $connection->executeQuery($query, [$adminUser]);
152+
$result = $connection->executeQuery($query, [$username]);
153153

154154
//current dbuser has admin rights
155155
$data = $result->fetchAll();
156156
$result->closeCursor();
157157
//new dbuser does not exist
158158
if (count($data) === 0) {
159159
//use the admin login data for the new database user
160-
$this->dbUser = $adminUser;
160+
$this->dbUser = $username;
161161
$this->createDBUser($connection);
162162
// if sharding is used we need to manually call this for every shard as those also need the user setup!
163163
/** @var ConnectionAdapter $connection */
@@ -169,7 +169,7 @@ private function createSpecificUser(string $username, IDBConnection $connection)
169169
} else {
170170
//repeat with different username
171171
$length = strlen((string)$i);
172-
$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
172+
$username = substr($username, 0, 16 - $length) . $i;
173173
$i++;
174174
}
175175
}

0 commit comments

Comments
 (0)