summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/composer/composer/autoload_classmap.php1
-rw-r--r--apps/user_ldap/composer/composer/autoload_static.php1
-rw-r--r--apps/user_ldap/lib/Mapping/AbstractMapping.php4
-rw-r--r--apps/user_ldap/lib/Migration/Version1010Date20200630192842.php4
-rw-r--r--apps/user_ldap/lib/Migration/Version1130Date20211102154716.php6
-rw-r--r--apps/user_ldap/lib/Migration/Version1130Date20220110154718.php2
-rw-r--r--apps/user_ldap/lib/Migration/Version1141Date20220323143801.php113
7 files changed, 123 insertions, 8 deletions
diff --git a/apps/user_ldap/composer/composer/autoload_classmap.php b/apps/user_ldap/composer/composer/autoload_classmap.php
index 7077dfd8ca1..12ede37a941 100644
--- a/apps/user_ldap/composer/composer/autoload_classmap.php
+++ b/apps/user_ldap/composer/composer/autoload_classmap.php
@@ -67,6 +67,7 @@ return array(
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154717' => $baseDir . '/../lib/Migration/Version1130Date20220110154717.php',
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154718' => $baseDir . '/../lib/Migration/Version1130Date20220110154718.php',
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154719' => $baseDir . '/../lib/Migration/Version1130Date20220110154719.php',
+ 'OCA\\User_LDAP\\Migration\\Version1141Date20220323143801' => $baseDir . '/../lib/Migration/Version1141Date20220323143801.php',
'OCA\\User_LDAP\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\User_LDAP\\PagedResults\\IAdapter' => $baseDir . '/../lib/PagedResults/IAdapter.php',
'OCA\\User_LDAP\\PagedResults\\Php73' => $baseDir . '/../lib/PagedResults/Php73.php',
diff --git a/apps/user_ldap/composer/composer/autoload_static.php b/apps/user_ldap/composer/composer/autoload_static.php
index 5928ff78ef0..ecf5e4167f6 100644
--- a/apps/user_ldap/composer/composer/autoload_static.php
+++ b/apps/user_ldap/composer/composer/autoload_static.php
@@ -82,6 +82,7 @@ class ComposerStaticInitUser_LDAP
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154717' => __DIR__ . '/..' . '/../lib/Migration/Version1130Date20220110154717.php',
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154718' => __DIR__ . '/..' . '/../lib/Migration/Version1130Date20220110154718.php',
'OCA\\User_LDAP\\Migration\\Version1130Date20220110154719' => __DIR__ . '/..' . '/../lib/Migration/Version1130Date20220110154719.php',
+ 'OCA\\User_LDAP\\Migration\\Version1141Date20220323143801' => __DIR__ . '/..' . '/../lib/Migration/Version1141Date20220323143801.php',
'OCA\\User_LDAP\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\User_LDAP\\PagedResults\\IAdapter' => __DIR__ . '/..' . '/../lib/PagedResults/IAdapter.php',
'OCA\\User_LDAP\\PagedResults\\Php73' => __DIR__ . '/..' . '/../lib/PagedResults/Php73.php',
diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php
index f26b54a37e8..9026b8cfb78 100644
--- a/apps/user_ldap/lib/Mapping/AbstractMapping.php
+++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php
@@ -355,9 +355,9 @@ abstract class AbstractMapping {
* @return bool
*/
public function map($fdn, $name, $uuid) {
- if (mb_strlen($fdn) > 4096) {
+ if (mb_strlen($fdn) > 4000) {
\OC::$server->getLogger()->error(
- 'Cannot map, because the DN exceeds 4096 characters: {dn}',
+ 'Cannot map, because the DN exceeds 4000 characters: {dn}',
[
'app' => 'user_ldap',
'dn' => $fdn,
diff --git a/apps/user_ldap/lib/Migration/Version1010Date20200630192842.php b/apps/user_ldap/lib/Migration/Version1010Date20200630192842.php
index 939db69a6ab..5c7dc7db95c 100644
--- a/apps/user_ldap/lib/Migration/Version1010Date20200630192842.php
+++ b/apps/user_ldap/lib/Migration/Version1010Date20200630192842.php
@@ -47,7 +47,7 @@ class Version1010Date20200630192842 extends SimpleMigrationStep {
$table = $schema->createTable('ldap_user_mapping');
$table->addColumn('ldap_dn', Types::STRING, [
'notnull' => true,
- 'length' => 255,
+ 'length' => 4000,
'default' => '',
]);
$table->addColumn('owncloud_name', Types::STRING, [
@@ -73,7 +73,7 @@ class Version1010Date20200630192842 extends SimpleMigrationStep {
$table = $schema->createTable('ldap_group_mapping');
$table->addColumn('ldap_dn', Types::STRING, [
'notnull' => true,
- 'length' => 255,
+ 'length' => 4000,
'default' => '',
]);
$table->addColumn('owncloud_name', Types::STRING, [
diff --git a/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php b/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
index 024c5801582..5c5ed44c899 100644
--- a/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
+++ b/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
@@ -95,8 +95,8 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
}
$column = $table->getColumn('ldap_dn');
if ($tableName === 'ldap_user_mapping') {
- if ($column->getLength() < 4096) {
- $column->setLength(4096);
+ if ($column->getLength() < 4000) {
+ $column->setLength(4000);
$changeSchema = true;
}
@@ -117,7 +117,7 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
$table2 = $schema->createTable('ldap_group_mapping_backup');
$table2->addColumn('ldap_dn', Types::STRING, [
'notnull' => true,
- 'length' => 4096,
+ 'length' => 4000,
'default' => '',
]);
$table2->addColumn('owncloud_name', Types::STRING, [
diff --git a/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php b/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php
index 5f146ab06a5..74dd2d873bc 100644
--- a/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php
+++ b/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php
@@ -54,7 +54,7 @@ class Version1130Date20220110154718 extends GroupMappingMigration {
$table = $schema->createTable('ldap_group_mapping');
$table->addColumn('ldap_dn', Types::STRING, [
'notnull' => true,
- 'length' => 4096,
+ 'length' => 4000,
'default' => '',
]);
$table->addColumn('owncloud_name', Types::STRING, [
diff --git a/apps/user_ldap/lib/Migration/Version1141Date20220323143801.php b/apps/user_ldap/lib/Migration/Version1141Date20220323143801.php
new file mode 100644
index 00000000000..be496d9215e
--- /dev/null
+++ b/apps/user_ldap/lib/Migration/Version1141Date20220323143801.php
@@ -0,0 +1,113 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\User_LDAP\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version1141Date20220323143801 extends SimpleMigrationStep {
+
+ private IDBConnection $dbc;
+
+ public function __construct(IDBConnection $dbc) {
+ $this->dbc = $dbc;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ */
+ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
+ foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) {
+ $qb = $this->dbc->getQueryBuilder();
+ $qb->select('ldap_dn')
+ ->from($tableName)
+ ->where($qb->expr()->gt($qb->func()->octetLength('ldap_dn'), '4000', IQueryBuilder::PARAM_INT));
+
+ $dnsTooLong = [];
+ $result = $qb->executeQuery();
+ while (($dn = $result->fetchOne()) !== false) {
+ $dnsTooLong[] = $dn;
+ }
+ $result->closeCursor();
+ $this->shortenDNs($dnsTooLong, $tableName);
+ }
+ }
+
+ protected function shortenDNs(array $dns, string $table): void {
+ $qb = $this->dbc->getQueryBuilder();
+ $qb->update($table)
+ ->set('ldap_dn', $qb->createParameter('shortenedDn'))
+ ->where($qb->expr()->eq('ldap_dn', $qb->createParameter('originalDn')));
+
+ $pageSize = 1000;
+ $page = 0;
+ do {
+ $subset = array_slice($dns, $page * $pageSize, $pageSize);
+ try {
+ $this->dbc->beginTransaction();
+ foreach ($subset as $dn) {
+ $shortenedDN = mb_substr($dn, 0, 4000);
+ $qb->setParameter('shortenedDn', $shortenedDN);
+ $qb->setParameter('originalDn', $dn);
+ $qb->executeStatement();
+ }
+ $this->dbc->commit();
+ } catch (\Throwable $t) {
+ $this->dbc->rollBack();
+ throw $t;
+ }
+ $page++;
+ } while (count($subset) === $pageSize);
+ }
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) {
+ $table = $schema->getTable($tableName);
+ $column = $table->getColumn('ldap_dn');
+ if ($column->getLength() > 4000) {
+ $column->setLength(4000);
+ }
+ }
+
+ return $schema;
+ }
+}