Skip to content

Commit

Permalink
fix(user_ldap): Improve typing and fix a var name
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Apr 29, 2024
1 parent 0956168 commit 5cee4f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/user_ldap/ajax/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

$con = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix, null);
$con->setConfiguration($configuration->getConfiguration());
$con->ldapConfigurationActive = true;
$con->ldapConfigurationActive = (string)true;
$con->setIgnoreValidation(true);

$factory = \OC::$server->get(\OCA\User_LDAP\AccessFactory::class);
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private function doSoftValidation(): void {

$backupPort = (int)$this->configuration->ldapBackupPort;
if ($backupPort <= 0) {
$this->configuration->backupPort = $this->configuration->ldapPort;
$this->configuration->ldapBackupPort = $this->configuration->ldapPort;
}

//make sure empty search attributes are saved as simple, empty array
Expand All @@ -463,7 +463,7 @@ private function doSoftValidation(): void {

if ((stripos((string)$this->configuration->ldapHost, 'ldaps://') === 0)
&& $this->configuration->ldapTLS) {
$this->configuration->ldapTLS = false;
$this->configuration->ldapTLS = (string)false;
$this->logger->info(
'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
['app' => 'user_ldap']
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Jobs/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function runCycle($cycleData) {
$results = $access->fetchListOfUsers(
$filter,
$access->userManager->getAttributes(),
$connection->ldapPagingSize,
(int)$connection->ldapPagingSize,
$cycleData['offset'],
true
);
Expand Down
16 changes: 11 additions & 5 deletions apps/user_ldap/lib/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private function determineGroups(string $dbKey, string $confKey, bool $testMembe
$this->fetchGroups($dbKey, $confKey);

if ($testMemberOf) {
$this->configuration->hasMemberOfFilterSupport = $this->testMemberOf();
$this->configuration->hasMemberOfFilterSupport = (string)$this->testMemberOf();
$this->result->markChange();
if (!$this->configuration->hasMemberOfFilterSupport) {
throw new \Exception('memberOf is not supported by the server');
Expand Down Expand Up @@ -700,8 +700,8 @@ public function guessPortAndTLS() {

if ($settingsFound === true) {
$config = [
'ldapPort' => $p,
'ldapTLS' => (int)$t
'ldapPort' => (string)$p,
'ldapTLS' => (string)$t,
];
$this->configuration->setConfiguration($config);
$this->logger->debug(
Expand Down Expand Up @@ -1322,7 +1322,7 @@ private function getConnection(): \LDAP\Connection|false {
$this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
$this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0);
$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
if ($this->configuration->ldapTLS === 1) {
if ($this->configuration->ldapTLS) {
$this->ldap->startTls($cr);
}

Expand All @@ -1337,6 +1337,9 @@ private function getConnection(): \LDAP\Connection|false {
return false;
}

/**
* @return array<array{port:int,tls:bool}>
*/
private function getDefaultLdapPortSettings(): array {
static $settings = [
['port' => 7636, 'tls' => false],
Expand All @@ -1349,6 +1352,9 @@ private function getDefaultLdapPortSettings(): array {
return $settings;
}

/**
* @return array<array{port:int,tls:bool}>
*/
private function getPortSettingsToTry(): array {
//389 ← LDAP / Unencrypted or StartTLS
//636 ← LDAPS / SSL
Expand All @@ -1367,7 +1373,7 @@ private function getPortSettingsToTry(): array {
}
$portSettings[] = ['port' => $port, 'tls' => false];
} elseif ($this->configuration->usesLdapi()) {
$portSettings[] = ['port' => '', 'tls' => false];
$portSettings[] = ['port' => 0, 'tls' => false];
}

//default ports
Expand Down

0 comments on commit 5cee4f4

Please sign in to comment.