Skip to content

Commit a3e51f3

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 a3e51f3

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

lib/private/Setup/MySQL.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,19 @@ 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) {
150147
//this should be enough to check for admin rights in mysql
151148
$query = 'SELECT user FROM mysql.user WHERE user=?';
152-
$result = $connection->executeQuery($query, [$adminUser]);
149+
$result = $connection->executeQuery($query, [$username]);
153150

154151
//current dbuser has admin rights
155152
$data = $result->fetchAll();
156153
$result->closeCursor();
157154
//new dbuser does not exist
158155
if (count($data) === 0) {
159156
//use the admin login data for the new database user
160-
$this->dbUser = $adminUser;
157+
$this->dbUser = $username;
161158
$this->createDBUser($connection);
162159
// if sharding is used we need to manually call this for every shard as those also need the user setup!
163160
/** @var ConnectionAdapter $connection */
@@ -169,7 +166,7 @@ private function createSpecificUser(string $username, IDBConnection $connection)
169166
} else {
170167
//repeat with different username
171168
$length = strlen((string)$i);
172-
$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
169+
$username = substr($username, 0, 16 - $length) . $i;
173170
$i++;
174171
}
175172
}

0 commit comments

Comments
 (0)