-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Support LDAP dns longer than 255 characters #29523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
662e324
Support LDAP dns longer than 255 characters
come-nc 31a503b
Change column names to ldap_dn and ldap_dn_hash and add migration
come-nc 9a1df9d
Fix variable names
nickvergessen ce5192a
Fixed migration step for user_ldap
come-nc d4c49a3
Put back length check to have a clear error
come-nc c4d8bd9
Fixes in migration step
come-nc 14f0020
Add the columns and alter the index in Version1010Date20200630192842
come-nc df25a6d
Make sure that hash function returns a string
come-nc 5143249
Add an index for directory_uuid as well
come-nc a359047
Use clearer names for variables
come-nc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Change column names to ldap_dn and ldap_dn_hash and add migration
Signed-off-by: Côme Chilliet <[email protected]>
- Loading branch information
commit 31a503b387aea7d47f1e071dc16a9bf757e4cbb3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| <?php | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyright |
||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\User_LDAP\Migration; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\Exception; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\DB\Types; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class Version1130Date20211102154716 extends SimpleMigrationStep { | ||
|
|
||
| /** @var IDBConnection */ | ||
| private $dbc; | ||
| /** @var LoggerInterface */ | ||
| private $logger; | ||
|
|
||
| public function __construct(IDBConnection $dbc, LoggerInterface $logger) { | ||
| $this->dbc = $dbc; | ||
| $this->logger = $logger; | ||
| } | ||
|
|
||
| public function getName() { | ||
| return 'Adjust LDAP user and group ldap_dn column lengths and add ldap_dn_hash columns'; | ||
| } | ||
|
|
||
| /** | ||
| * @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(); | ||
|
|
||
| $changeSchema = false; | ||
| foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) { | ||
| $table = $schema->getTable($tableName); | ||
| $column = $table->getColumn('ldap_dn_hash'); | ||
| if (!$column) { | ||
| $table->addColumn('ldap_dn_hash', Types::STRING, [ | ||
| 'notnull' => true, | ||
| 'length' => 64, | ||
| 'default' => '', | ||
| ]); | ||
| $changeSchema = true; | ||
| } | ||
| $column = $table->getColumn('ldap_dn'); | ||
| if ($column->getLength() < 4096) { | ||
| $column->setLength(4096); | ||
| $changeSchema = true; | ||
| } | ||
| if ($table === 'ldap_user_mapping') { | ||
| if ($table->hasIndex('ldap_dn_users')) { | ||
| $table->dropIndex('ldap_dn_users'); | ||
| $changeSchema = true; | ||
| } | ||
| if (!$table->hasIndex('ldap_user_dn_hashes')) { | ||
| $table->addUniqueIndex(['ldap_dn_hash'], 'ldap_user_dn_hashes'); | ||
| $changeSchema = true; | ||
| } | ||
| } else { | ||
| if ($table->hasIndex('owncloud_name_groups')) { | ||
| $table->dropIndex('owncloud_name_groups'); | ||
| $changeSchema = true; | ||
| } | ||
| if (!$table->hasIndex('ldap_group_dn_hashes')) { | ||
| $table->addUniqueIndex(['ldap_dn_hash'], 'ldap_group_dn_hashes'); | ||
| $changeSchema = true; | ||
| } | ||
| if ($table->getPrimaryKeyColumns() !== ['owncloud_name']) { | ||
| $table->setPrimaryKey(['owncloud_name']); | ||
| $changeSchema = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $changeSchema ? $schema : null; | ||
| } | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
| * @param array $options | ||
| */ | ||
| public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { | ||
| $this->handleDNHashes('ldap_group_mapping'); | ||
| $this->handleDNHashes('ldap_user_mapping'); | ||
| } | ||
|
|
||
| protected function handleDNHashes(string $table): void { | ||
| $q = $this->getSelectQuery($table); | ||
| $u = $this->getUpdateQuery($table); | ||
come-nc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $r = $q->executeQuery(); | ||
| while ($row = $r->fetch()) { | ||
| $dnHash = hash('sha256', $row['ldap_dn'], false); | ||
| $u->setParameter('name', $row['owncloud_name']); | ||
| $u->setParameter('dn_hash', $dnHash); | ||
| try { | ||
| $u->executeStatement(); | ||
| } catch (Exception $e) { | ||
| $this->logger->error('Failed to add hash "{dnHash}" ("{name}" of {table})', | ||
| [ | ||
| 'app' => 'user_ldap', | ||
| 'name' => $row['owncloud_name'], | ||
| 'dnHash' => $dnHash, | ||
| 'table' => $table, | ||
| 'exception' => $e, | ||
| ] | ||
| ); | ||
| } | ||
| } | ||
| $r->closeCursor(); | ||
| } | ||
|
|
||
| protected function getSelectQuery(string $table): IQueryBuilder { | ||
| $q = $this->dbc->getQueryBuilder(); | ||
| $q->select('owncloud_name', 'ldap_dn', 'ldap_dn_hash') | ||
| ->from($table) | ||
| ->where($q->expr()->isNull('ldap_dn_hash')); | ||
| return $q; | ||
| } | ||
|
|
||
| protected function getUpdateQuery(string $table): IQueryBuilder { | ||
| $q = $this->dbc->getQueryBuilder(); | ||
| $q->update($table) | ||
| ->set('ldap_dn_hash', $query->createParameter('dn_hash')) | ||
| ->where($q->expr()->eq('owncloud_name', $q->createParameter('name'))); | ||
| return $q; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.