@@ -49,7 +49,6 @@ |
||
| 49 | 49 | use OCA\User_LDAP\User\Manager; |
| 50 | 50 | use OCA\User_LDAP\User\OfflineUser; |
| 51 | 51 | use OCA\User_LDAP\Mapping\AbstractMapping; |
| 52 | - |
|
| 53 | 52 | use OC\ServerNotAvailableException; |
| 54 | 53 | use OCP\IConfig; |
| 55 | 54 | use OCP\Util; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return AbstractMapping |
| 126 | 126 | */ |
| 127 | 127 | public function getUserMapper() { |
| 128 | - if(is_null($this->userMapper)) { |
|
| 128 | + if (is_null($this->userMapper)) { |
|
| 129 | 129 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
| 130 | 130 | } |
| 131 | 131 | return $this->userMapper; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return AbstractMapping |
| 146 | 146 | */ |
| 147 | 147 | public function getGroupMapper() { |
| 148 | - if(is_null($this->groupMapper)) { |
|
| 148 | + if (is_null($this->groupMapper)) { |
|
| 149 | 149 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
| 150 | 150 | } |
| 151 | 151 | return $this->groupMapper; |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | * array if $attr is empty, false otherwise |
| 177 | 177 | */ |
| 178 | 178 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
| 179 | - if(!$this->checkConnection()) { |
|
| 179 | + if (!$this->checkConnection()) { |
|
| 180 | 180 | \OCP\Util::writeLog('user_ldap', |
| 181 | 181 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
| 182 | 182 | \OCP\Util::WARN); |
| 183 | 183 | return false; |
| 184 | 184 | } |
| 185 | 185 | $cr = $this->connection->getConnectionResource(); |
| 186 | - if(!$this->ldap->isResource($cr)) { |
|
| 186 | + if (!$this->ldap->isResource($cr)) { |
|
| 187 | 187 | //LDAP not available |
| 188 | 188 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 189 | 189 | return false; |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $isRangeRequest = false; |
| 207 | 207 | do { |
| 208 | 208 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
| 209 | - if(is_bool($result)) { |
|
| 209 | + if (is_bool($result)) { |
|
| 210 | 210 | // when an exists request was run and it was successful, an empty |
| 211 | 211 | // array must be returned |
| 212 | 212 | return $result ? [] : false; |
@@ -223,22 +223,22 @@ discard block |
||
| 223 | 223 | $result = $this->extractRangeData($result, $attr); |
| 224 | 224 | if (!empty($result)) { |
| 225 | 225 | $normalizedResult = $this->extractAttributeValuesFromResult( |
| 226 | - [ $attr => $result['values'] ], |
|
| 226 | + [$attr => $result['values']], |
|
| 227 | 227 | $attr |
| 228 | 228 | ); |
| 229 | 229 | $values = array_merge($values, $normalizedResult); |
| 230 | 230 | |
| 231 | - if($result['rangeHigh'] === '*') { |
|
| 231 | + if ($result['rangeHigh'] === '*') { |
|
| 232 | 232 | // when server replies with * as high range value, there are |
| 233 | 233 | // no more results left |
| 234 | 234 | return $values; |
| 235 | 235 | } else { |
| 236 | - $low = $result['rangeHigh'] + 1; |
|
| 237 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
| 236 | + $low = $result['rangeHigh'] + 1; |
|
| 237 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
| 238 | 238 | $isRangeRequest = true; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | - } while($isRangeRequest); |
|
| 241 | + } while ($isRangeRequest); |
|
| 242 | 242 | |
| 243 | 243 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); |
| 244 | 244 | return false; |
@@ -263,13 +263,13 @@ discard block |
||
| 263 | 263 | if (!$this->ldap->isResource($rr)) { |
| 264 | 264 | if ($attribute !== '') { |
| 265 | 265 | //do not throw this message on userExists check, irritates |
| 266 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); |
|
| 266 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); |
|
| 267 | 267 | } |
| 268 | 268 | //in case an error occurs , e.g. object does not exist |
| 269 | 269 | return false; |
| 270 | 270 | } |
| 271 | 271 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
| 272 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); |
|
| 272 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG); |
|
| 273 | 273 | return true; |
| 274 | 274 | } |
| 275 | 275 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public function extractAttributeValuesFromResult($result, $attribute) { |
| 296 | 296 | $values = []; |
| 297 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 297 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 298 | 298 | $lowercaseAttribute = strtolower($attribute); |
| 299 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
| 300 | - if($this->resemblesDN($attribute)) { |
|
| 299 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
| 300 | + if ($this->resemblesDN($attribute)) { |
|
| 301 | 301 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
| 302 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 302 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 303 | 303 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
| 304 | 304 | } else { |
| 305 | 305 | $values[] = $result[$attribute][$i]; |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function extractRangeData($result, $attribute) { |
| 323 | 323 | $keys = array_keys($result); |
| 324 | - foreach($keys as $key) { |
|
| 325 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 324 | + foreach ($keys as $key) { |
|
| 325 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 326 | 326 | $queryData = explode(';', $key); |
| 327 | - if(strpos($queryData[1], 'range=') === 0) { |
|
| 327 | + if (strpos($queryData[1], 'range=') === 0) { |
|
| 328 | 328 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
| 329 | 329 | $data = [ |
| 330 | 330 | 'values' => $result[$key], |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | * @throws \Exception |
| 350 | 350 | */ |
| 351 | 351 | public function setPassword($userDN, $password) { |
| 352 | - if(intval($this->connection->turnOnPasswordChange) !== 1) { |
|
| 352 | + if (intval($this->connection->turnOnPasswordChange) !== 1) { |
|
| 353 | 353 | throw new \Exception('LDAP password changes are disabled.'); |
| 354 | 354 | } |
| 355 | 355 | $cr = $this->connection->getConnectionResource(); |
| 356 | - if(!$this->ldap->isResource($cr)) { |
|
| 356 | + if (!$this->ldap->isResource($cr)) { |
|
| 357 | 357 | //LDAP not available |
| 358 | 358 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 359 | 359 | return false; |
| 360 | 360 | } |
| 361 | 361 | try { |
| 362 | 362 | return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
| 363 | - } catch(ConstraintViolationException $e) { |
|
| 363 | + } catch (ConstraintViolationException $e) { |
|
| 364 | 364 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
| 365 | 365 | } |
| 366 | 366 | } |
@@ -402,17 +402,17 @@ discard block |
||
| 402 | 402 | */ |
| 403 | 403 | public function getDomainDNFromDN($dn) { |
| 404 | 404 | $allParts = $this->ldap->explodeDN($dn, 0); |
| 405 | - if($allParts === false) { |
|
| 405 | + if ($allParts === false) { |
|
| 406 | 406 | //not a valid DN |
| 407 | 407 | return ''; |
| 408 | 408 | } |
| 409 | 409 | $domainParts = array(); |
| 410 | 410 | $dcFound = false; |
| 411 | - foreach($allParts as $part) { |
|
| 412 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 411 | + foreach ($allParts as $part) { |
|
| 412 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 413 | 413 | $dcFound = true; |
| 414 | 414 | } |
| 415 | - if($dcFound) { |
|
| 415 | + if ($dcFound) { |
|
| 416 | 416 | $domainParts[] = $part; |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
| 441 | 441 | //server setups |
| 442 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 442 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 443 | 443 | return $fdn; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | //To avoid bypassing the base DN settings under certain circumstances |
| 457 | 457 | //with the group support, check whether the provided DN matches one of |
| 458 | 458 | //the given Bases |
| 459 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 459 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 460 | 460 | return false; |
| 461 | 461 | } |
| 462 | 462 | |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | public function groupsMatchFilter($groupDNs) { |
| 475 | 475 | $validGroupDNs = []; |
| 476 | - foreach($groupDNs as $dn) { |
|
| 476 | + foreach ($groupDNs as $dn) { |
|
| 477 | 477 | $cacheKey = 'groupsMatchFilter-'.$dn; |
| 478 | 478 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
| 479 | - if(!is_null($groupMatchFilter)) { |
|
| 480 | - if($groupMatchFilter) { |
|
| 479 | + if (!is_null($groupMatchFilter)) { |
|
| 480 | + if ($groupMatchFilter) { |
|
| 481 | 481 | $validGroupDNs[] = $dn; |
| 482 | 482 | } |
| 483 | 483 | continue; |
@@ -485,13 +485,13 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | // Check the base DN first. If this is not met already, we don't |
| 487 | 487 | // need to ask the server at all. |
| 488 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 488 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 489 | 489 | $this->connection->writeToCache($cacheKey, false); |
| 490 | 490 | continue; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | $result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter); |
| 494 | - if(is_array($result)) { |
|
| 494 | + if (is_array($result)) { |
|
| 495 | 495 | $this->connection->writeToCache($cacheKey, true); |
| 496 | 496 | $validGroupDNs[] = $dn; |
| 497 | 497 | } else { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | //To avoid bypassing the base DN settings under certain circumstances |
| 513 | 513 | //with the group support, check whether the provided DN matches one of |
| 514 | 514 | //the given Bases |
| 515 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 515 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 516 | 516 | return false; |
| 517 | 517 | } |
| 518 | 518 | |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | */ |
| 533 | 533 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
| 534 | 534 | $newlyMapped = false; |
| 535 | - if($isUser) { |
|
| 535 | + if ($isUser) { |
|
| 536 | 536 | $mapper = $this->getUserMapper(); |
| 537 | 537 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 538 | 538 | } else { |
@@ -542,15 +542,15 @@ discard block |
||
| 542 | 542 | |
| 543 | 543 | //let's try to retrieve the Nextcloud name from the mappings table |
| 544 | 544 | $ncName = $mapper->getNameByDN($fdn); |
| 545 | - if(is_string($ncName)) { |
|
| 545 | + if (is_string($ncName)) { |
|
| 546 | 546 | return $ncName; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
| 550 | 550 | $uuid = $this->getUUID($fdn, $isUser, $record); |
| 551 | - if(is_string($uuid)) { |
|
| 551 | + if (is_string($uuid)) { |
|
| 552 | 552 | $ncName = $mapper->getNameByUUID($uuid); |
| 553 | - if(is_string($ncName)) { |
|
| 553 | + if (is_string($ncName)) { |
|
| 554 | 554 | $mapper->setDNbyUUID($fdn, $uuid); |
| 555 | 555 | return $ncName; |
| 556 | 556 | } |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | return false; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - if(is_null($ldapName)) { |
|
| 563 | + if (is_null($ldapName)) { |
|
| 564 | 564 | $ldapName = $this->readAttribute($fdn, $nameAttribute); |
| 565 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 565 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 566 | 566 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO); |
| 567 | 567 | return false; |
| 568 | 568 | } |
| 569 | 569 | $ldapName = $ldapName[0]; |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | - if($isUser) { |
|
| 572 | + if ($isUser) { |
|
| 573 | 573 | $usernameAttribute = strval($this->connection->ldapExpertUsernameAttr); |
| 574 | 574 | if ($usernameAttribute !== '') { |
| 575 | 575 | $username = $this->readAttribute($fdn, $usernameAttribute); |
@@ -588,9 +588,9 @@ discard block |
||
| 588 | 588 | // outside of core user management will still cache the user as non-existing. |
| 589 | 589 | $originalTTL = $this->connection->ldapCacheTTL; |
| 590 | 590 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 591 | - if(($isUser && $intName !== '' && !\OCP\User::userExists($intName)) |
|
| 591 | + if (($isUser && $intName !== '' && !\OCP\User::userExists($intName)) |
|
| 592 | 592 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { |
| 593 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
| 593 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
| 594 | 594 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 595 | 595 | $newlyMapped = true; |
| 596 | 596 | return $intName; |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 600 | 600 | |
| 601 | 601 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
| 602 | - if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 602 | + if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 603 | 603 | $newlyMapped = true; |
| 604 | 604 | return $altName; |
| 605 | 605 | } |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | * @return array |
| 638 | 638 | */ |
| 639 | 639 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
| 640 | - if($isUsers) { |
|
| 640 | + if ($isUsers) { |
|
| 641 | 641 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 642 | 642 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
| 643 | 643 | } else { |
@@ -645,9 +645,9 @@ discard block |
||
| 645 | 645 | } |
| 646 | 646 | $nextcloudNames = array(); |
| 647 | 647 | |
| 648 | - foreach($ldapObjects as $ldapObject) { |
|
| 648 | + foreach ($ldapObjects as $ldapObject) { |
|
| 649 | 649 | $nameByLDAP = null; |
| 650 | - if( isset($ldapObject[$nameAttribute]) |
|
| 650 | + if (isset($ldapObject[$nameAttribute]) |
|
| 651 | 651 | && is_array($ldapObject[$nameAttribute]) |
| 652 | 652 | && isset($ldapObject[$nameAttribute][0]) |
| 653 | 653 | ) { |
@@ -656,12 +656,12 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
| 659 | - if($ncName) { |
|
| 659 | + if ($ncName) { |
|
| 660 | 660 | $nextcloudNames[] = $ncName; |
| 661 | - if($isUsers) { |
|
| 661 | + if ($isUsers) { |
|
| 662 | 662 | //cache the user names so it does not need to be retrieved |
| 663 | 663 | //again later (e.g. sharing dialogue). |
| 664 | - if(is_null($nameByLDAP)) { |
|
| 664 | + if (is_null($nameByLDAP)) { |
|
| 665 | 665 | continue; |
| 666 | 666 | } |
| 667 | 667 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
| 701 | 701 | $user = $this->userManager->get($ocName); |
| 702 | - if($user === null) { |
|
| 702 | + if ($user === null) { |
|
| 703 | 703 | return; |
| 704 | 704 | } |
| 705 | 705 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -719,9 +719,9 @@ discard block |
||
| 719 | 719 | $attempts = 0; |
| 720 | 720 | //while loop is just a precaution. If a name is not generated within |
| 721 | 721 | //20 attempts, something else is very wrong. Avoids infinite loop. |
| 722 | - while($attempts < 20){ |
|
| 723 | - $altName = $name . '_' . rand(1000,9999); |
|
| 724 | - if(!\OCP\User::userExists($altName)) { |
|
| 722 | + while ($attempts < 20) { |
|
| 723 | + $altName = $name.'_'.rand(1000, 9999); |
|
| 724 | + if (!\OCP\User::userExists($altName)) { |
|
| 725 | 725 | return $altName; |
| 726 | 726 | } |
| 727 | 727 | $attempts++; |
@@ -743,25 +743,25 @@ discard block |
||
| 743 | 743 | */ |
| 744 | 744 | private function _createAltInternalOwnCloudNameForGroups($name) { |
| 745 | 745 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
| 746 | - if(!($usedNames) || count($usedNames) === 0) { |
|
| 746 | + if (!($usedNames) || count($usedNames) === 0) { |
|
| 747 | 747 | $lastNo = 1; //will become name_2 |
| 748 | 748 | } else { |
| 749 | 749 | natsort($usedNames); |
| 750 | 750 | $lastName = array_pop($usedNames); |
| 751 | 751 | $lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1)); |
| 752 | 752 | } |
| 753 | - $altName = $name.'_'.strval($lastNo+1); |
|
| 753 | + $altName = $name.'_'.strval($lastNo + 1); |
|
| 754 | 754 | unset($usedNames); |
| 755 | 755 | |
| 756 | 756 | $attempts = 1; |
| 757 | - while($attempts < 21){ |
|
| 757 | + while ($attempts < 21) { |
|
| 758 | 758 | // Check to be really sure it is unique |
| 759 | 759 | // while loop is just a precaution. If a name is not generated within |
| 760 | 760 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
| 761 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 761 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 762 | 762 | return $altName; |
| 763 | 763 | } |
| 764 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
| 764 | + $altName = $name.'_'.($lastNo + $attempts); |
|
| 765 | 765 | $attempts++; |
| 766 | 766 | } |
| 767 | 767 | return false; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | private function createAltInternalOwnCloudName($name, $isUser) { |
| 777 | 777 | $originalTTL = $this->connection->ldapCacheTTL; |
| 778 | 778 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 779 | - if($isUser) { |
|
| 779 | + if ($isUser) { |
|
| 780 | 780 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
| 781 | 781 | } else { |
| 782 | 782 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
| 827 | 827 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
| 828 | 828 | $recordsToUpdate = $ldapRecords; |
| 829 | - if(!$forceApplyAttributes) { |
|
| 829 | + if (!$forceApplyAttributes) { |
|
| 830 | 830 | $isBackgroundJobModeAjax = $this->config |
| 831 | 831 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
| 832 | 832 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
| 833 | 833 | $newlyMapped = false; |
| 834 | 834 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
| 835 | - if(is_string($uid)) { |
|
| 835 | + if (is_string($uid)) { |
|
| 836 | 836 | $this->cacheUserExists($uid); |
| 837 | 837 | } |
| 838 | 838 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -848,19 +848,19 @@ discard block |
||
| 848 | 848 | * and their values |
| 849 | 849 | * @param array $ldapRecords |
| 850 | 850 | */ |
| 851 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
| 851 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
| 852 | 852 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
| 853 | - foreach($ldapRecords as $userRecord) { |
|
| 854 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
| 853 | + foreach ($ldapRecords as $userRecord) { |
|
| 854 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
| 855 | 855 | // displayName is obligatory |
| 856 | 856 | continue; |
| 857 | 857 | } |
| 858 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 859 | - if($ocName === false) { |
|
| 858 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 859 | + if ($ocName === false) { |
|
| 860 | 860 | continue; |
| 861 | 861 | } |
| 862 | 862 | $user = $this->userManager->get($ocName); |
| 863 | - if($user instanceof OfflineUser) { |
|
| 863 | + if ($user instanceof OfflineUser) { |
|
| 864 | 864 | $user->unmark(); |
| 865 | 865 | $user = $this->userManager->get($ocName); |
| 866 | 866 | } |
@@ -892,8 +892,8 @@ discard block |
||
| 892 | 892 | * @return array |
| 893 | 893 | */ |
| 894 | 894 | private function fetchList($list, $manyAttributes) { |
| 895 | - if(is_array($list)) { |
|
| 896 | - if($manyAttributes) { |
|
| 895 | + if (is_array($list)) { |
|
| 896 | + if ($manyAttributes) { |
|
| 897 | 897 | return $list; |
| 898 | 898 | } else { |
| 899 | 899 | $list = array_reduce($list, function($carry, $item) { |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | // php no longer supports call-time pass-by-reference |
| 992 | 992 | // thus cannot support controlPagedResultResponse as the third argument |
| 993 | 993 | // is a reference |
| 994 | - $doMethod = function () use ($command, &$arguments) { |
|
| 994 | + $doMethod = function() use ($command, &$arguments) { |
|
| 995 | 995 | if ($command == 'controlPagedResultResponse') { |
| 996 | 996 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
| 997 | 997 | } else { |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | $this->connection->resetConnectionResource(); |
| 1010 | 1010 | $cr = $this->connection->getConnectionResource(); |
| 1011 | 1011 | |
| 1012 | - if(!$this->ldap->isResource($cr)) { |
|
| 1012 | + if (!$this->ldap->isResource($cr)) { |
|
| 1013 | 1013 | // Seems like we didn't find any resource. |
| 1014 | 1014 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG); |
| 1015 | 1015 | throw $e; |
@@ -1034,13 +1034,13 @@ discard block |
||
| 1034 | 1034 | * @throws ServerNotAvailableException |
| 1035 | 1035 | */ |
| 1036 | 1036 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
| 1037 | - if(!is_null($attr) && !is_array($attr)) { |
|
| 1037 | + if (!is_null($attr) && !is_array($attr)) { |
|
| 1038 | 1038 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | // See if we have a resource, in case not cancel with message |
| 1042 | 1042 | $cr = $this->connection->getConnectionResource(); |
| 1043 | - if(!$this->ldap->isResource($cr)) { |
|
| 1043 | + if (!$this->ldap->isResource($cr)) { |
|
| 1044 | 1044 | // Seems like we didn't find any resource. |
| 1045 | 1045 | // Return an empty array just like before. |
| 1046 | 1046 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
| 1055 | 1055 | // cannot use $cr anymore, might have changed in the previous call! |
| 1056 | 1056 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
| 1057 | - if(!is_array($sr) || $error !== 0) { |
|
| 1057 | + if (!is_array($sr) || $error !== 0) { |
|
| 1058 | 1058 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); |
| 1059 | 1059 | return false; |
| 1060 | 1060 | } |
@@ -1077,29 +1077,29 @@ discard block |
||
| 1077 | 1077 | */ |
| 1078 | 1078 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
| 1079 | 1079 | $cookie = null; |
| 1080 | - if($pagedSearchOK) { |
|
| 1080 | + if ($pagedSearchOK) { |
|
| 1081 | 1081 | $cr = $this->connection->getConnectionResource(); |
| 1082 | - foreach($sr as $key => $res) { |
|
| 1083 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1082 | + foreach ($sr as $key => $res) { |
|
| 1083 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1084 | 1084 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | //browsing through prior pages to get the cookie for the new one |
| 1089 | - if($skipHandling) { |
|
| 1089 | + if ($skipHandling) { |
|
| 1090 | 1090 | return false; |
| 1091 | 1091 | } |
| 1092 | 1092 | // if count is bigger, then the server does not support |
| 1093 | 1093 | // paged search. Instead, he did a normal search. We set a |
| 1094 | 1094 | // flag here, so the callee knows how to deal with it. |
| 1095 | - if($iFoundItems <= $limit) { |
|
| 1095 | + if ($iFoundItems <= $limit) { |
|
| 1096 | 1096 | $this->pagedSearchedSuccessful = true; |
| 1097 | 1097 | } |
| 1098 | 1098 | } else { |
| 1099 | - if(!is_null($limit) && intval($this->connection->ldapPagingSize) !== 0) { |
|
| 1099 | + if (!is_null($limit) && intval($this->connection->ldapPagingSize) !== 0) { |
|
| 1100 | 1100 | \OC::$server->getLogger()->debug( |
| 1101 | 1101 | 'Paged search was not available', |
| 1102 | - [ 'app' => 'user_ldap' ] |
|
| 1102 | + ['app' => 'user_ldap'] |
|
| 1103 | 1103 | ); |
| 1104 | 1104 | } |
| 1105 | 1105 | } |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); |
| 1130 | 1130 | |
| 1131 | 1131 | $limitPerPage = intval($this->connection->ldapPagingSize); |
| 1132 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1132 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1133 | 1133 | $limitPerPage = $limit; |
| 1134 | 1134 | } |
| 1135 | 1135 | |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | |
| 1140 | 1140 | do { |
| 1141 | 1141 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1142 | - if($search === false) { |
|
| 1142 | + if ($search === false) { |
|
| 1143 | 1143 | return $counter > 0 ? $counter : false; |
| 1144 | 1144 | } |
| 1145 | 1145 | list($sr, $pagedSearchOK) = $search; |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | * Continue now depends on $hasMorePages value |
| 1159 | 1159 | */ |
| 1160 | 1160 | $continue = $pagedSearchOK && $hasMorePages; |
| 1161 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1161 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1162 | 1162 | |
| 1163 | 1163 | return $counter; |
| 1164 | 1164 | } |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | private function countEntriesInSearchResults($searchResults) { |
| 1171 | 1171 | $counter = 0; |
| 1172 | 1172 | |
| 1173 | - foreach($searchResults as $res) { |
|
| 1173 | + foreach ($searchResults as $res) { |
|
| 1174 | 1174 | $count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res)); |
| 1175 | 1175 | $counter += $count; |
| 1176 | 1176 | } |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | */ |
| 1193 | 1193 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1194 | 1194 | $limitPerPage = intval($this->connection->ldapPagingSize); |
| 1195 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1195 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1196 | 1196 | $limitPerPage = $limit; |
| 1197 | 1197 | } |
| 1198 | 1198 | |
@@ -1206,13 +1206,13 @@ discard block |
||
| 1206 | 1206 | $savedoffset = $offset; |
| 1207 | 1207 | do { |
| 1208 | 1208 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1209 | - if($search === false) { |
|
| 1209 | + if ($search === false) { |
|
| 1210 | 1210 | return []; |
| 1211 | 1211 | } |
| 1212 | 1212 | list($sr, $pagedSearchOK) = $search; |
| 1213 | 1213 | $cr = $this->connection->getConnectionResource(); |
| 1214 | 1214 | |
| 1215 | - if($skipHandling) { |
|
| 1215 | + if ($skipHandling) { |
|
| 1216 | 1216 | //i.e. result do not need to be fetched, we just need the cookie |
| 1217 | 1217 | //thus pass 1 or any other value as $iFoundItems because it is not |
| 1218 | 1218 | //used |
@@ -1223,7 +1223,7 @@ discard block |
||
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | 1225 | $iFoundItems = 0; |
| 1226 | - foreach($sr as $res) { |
|
| 1226 | + foreach ($sr as $res) { |
|
| 1227 | 1227 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
| 1228 | 1228 | $iFoundItems = max($iFoundItems, $findings['count']); |
| 1229 | 1229 | unset($findings['count']); |
@@ -1239,27 +1239,27 @@ discard block |
||
| 1239 | 1239 | |
| 1240 | 1240 | // if we're here, probably no connection resource is returned. |
| 1241 | 1241 | // to make Nextcloud behave nicely, we simply give back an empty array. |
| 1242 | - if(is_null($findings)) { |
|
| 1242 | + if (is_null($findings)) { |
|
| 1243 | 1243 | return array(); |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - if(!is_null($attr)) { |
|
| 1246 | + if (!is_null($attr)) { |
|
| 1247 | 1247 | $selection = []; |
| 1248 | 1248 | $i = 0; |
| 1249 | - foreach($findings as $item) { |
|
| 1250 | - if(!is_array($item)) { |
|
| 1249 | + foreach ($findings as $item) { |
|
| 1250 | + if (!is_array($item)) { |
|
| 1251 | 1251 | continue; |
| 1252 | 1252 | } |
| 1253 | 1253 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
| 1254 | - foreach($attr as $key) { |
|
| 1255 | - if(isset($item[$key])) { |
|
| 1256 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1254 | + foreach ($attr as $key) { |
|
| 1255 | + if (isset($item[$key])) { |
|
| 1256 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1257 | 1257 | unset($item[$key]['count']); |
| 1258 | 1258 | } |
| 1259 | - if($key !== 'dn') { |
|
| 1260 | - if($this->resemblesDN($key)) { |
|
| 1259 | + if ($key !== 'dn') { |
|
| 1260 | + if ($this->resemblesDN($key)) { |
|
| 1261 | 1261 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
| 1262 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
| 1262 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
| 1263 | 1263 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
| 1264 | 1264 | } else { |
| 1265 | 1265 | $selection[$i][$key] = $item[$key]; |
@@ -1277,7 +1277,7 @@ discard block |
||
| 1277 | 1277 | //we slice the findings, when |
| 1278 | 1278 | //a) paged search unsuccessful, though attempted |
| 1279 | 1279 | //b) no paged search, but limit set |
| 1280 | - if((!$this->getPagedSearchResultState() |
|
| 1280 | + if ((!$this->getPagedSearchResultState() |
|
| 1281 | 1281 | && $pagedSearchOK) |
| 1282 | 1282 | || ( |
| 1283 | 1283 | !$pagedSearchOK |
@@ -1294,7 +1294,7 @@ discard block |
||
| 1294 | 1294 | * @return bool|mixed|string |
| 1295 | 1295 | */ |
| 1296 | 1296 | public function sanitizeUsername($name) { |
| 1297 | - if($this->connection->ldapIgnoreNamingRules) { |
|
| 1297 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
| 1298 | 1298 | return trim($name); |
| 1299 | 1299 | } |
| 1300 | 1300 | |
@@ -1319,13 +1319,13 @@ discard block |
||
| 1319 | 1319 | */ |
| 1320 | 1320 | public function escapeFilterPart($input, $allowAsterisk = false) { |
| 1321 | 1321 | $asterisk = ''; |
| 1322 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1322 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1323 | 1323 | $asterisk = '*'; |
| 1324 | 1324 | $input = mb_substr($input, 1, null, 'UTF-8'); |
| 1325 | 1325 | } |
| 1326 | 1326 | $search = array('*', '\\', '(', ')'); |
| 1327 | 1327 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
| 1328 | - return $asterisk . str_replace($search, $replace, $input); |
|
| 1328 | + return $asterisk.str_replace($search, $replace, $input); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | /** |
@@ -1355,13 +1355,13 @@ discard block |
||
| 1355 | 1355 | */ |
| 1356 | 1356 | private function combineFilter($filters, $operator) { |
| 1357 | 1357 | $combinedFilter = '('.$operator; |
| 1358 | - foreach($filters as $filter) { |
|
| 1358 | + foreach ($filters as $filter) { |
|
| 1359 | 1359 | if ($filter !== '' && $filter[0] !== '(') { |
| 1360 | 1360 | $filter = '('.$filter.')'; |
| 1361 | 1361 | } |
| 1362 | - $combinedFilter.=$filter; |
|
| 1362 | + $combinedFilter .= $filter; |
|
| 1363 | 1363 | } |
| 1364 | - $combinedFilter.=')'; |
|
| 1364 | + $combinedFilter .= ')'; |
|
| 1365 | 1365 | return $combinedFilter; |
| 1366 | 1366 | } |
| 1367 | 1367 | |
@@ -1397,17 +1397,17 @@ discard block |
||
| 1397 | 1397 | * @throws \Exception |
| 1398 | 1398 | */ |
| 1399 | 1399 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
| 1400 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1400 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1401 | 1401 | throw new \Exception('searchAttributes must be an array with at least two string'); |
| 1402 | 1402 | } |
| 1403 | 1403 | $searchWords = explode(' ', trim($search)); |
| 1404 | 1404 | $wordFilters = array(); |
| 1405 | - foreach($searchWords as $word) { |
|
| 1405 | + foreach ($searchWords as $word) { |
|
| 1406 | 1406 | $word = $this->prepareSearchTerm($word); |
| 1407 | 1407 | //every word needs to appear at least once |
| 1408 | 1408 | $wordMatchOneAttrFilters = array(); |
| 1409 | - foreach($searchAttributes as $attr) { |
|
| 1410 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
| 1409 | + foreach ($searchAttributes as $attr) { |
|
| 1410 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
| 1411 | 1411 | } |
| 1412 | 1412 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
| 1413 | 1413 | } |
@@ -1425,10 +1425,10 @@ discard block |
||
| 1425 | 1425 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
| 1426 | 1426 | $filter = array(); |
| 1427 | 1427 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
| 1428 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1428 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1429 | 1429 | try { |
| 1430 | 1430 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
| 1431 | - } catch(\Exception $e) { |
|
| 1431 | + } catch (\Exception $e) { |
|
| 1432 | 1432 | \OCP\Util::writeLog( |
| 1433 | 1433 | 'user_ldap', |
| 1434 | 1434 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1438,17 +1438,17 @@ discard block |
||
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | $search = $this->prepareSearchTerm($search); |
| 1441 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1441 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1442 | 1442 | if ($fallbackAttribute === '') { |
| 1443 | 1443 | return ''; |
| 1444 | 1444 | } |
| 1445 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
| 1445 | + $filter[] = $fallbackAttribute.'='.$search; |
|
| 1446 | 1446 | } else { |
| 1447 | - foreach($searchAttributes as $attribute) { |
|
| 1448 | - $filter[] = $attribute . '=' . $search; |
|
| 1447 | + foreach ($searchAttributes as $attribute) { |
|
| 1448 | + $filter[] = $attribute.'='.$search; |
|
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | - if(count($filter) === 1) { |
|
| 1451 | + if (count($filter) === 1) { |
|
| 1452 | 1452 | return '('.$filter[0].')'; |
| 1453 | 1453 | } |
| 1454 | 1454 | return $this->combineFilterWithOr($filter); |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | if ($term === '') { |
| 1470 | 1470 | $result = '*'; |
| 1471 | 1471 | } else if ($allowEnum !== 'no') { |
| 1472 | - $result = $term . '*'; |
|
| 1472 | + $result = $term.'*'; |
|
| 1473 | 1473 | } |
| 1474 | 1474 | return $result; |
| 1475 | 1475 | } |
@@ -1481,7 +1481,7 @@ discard block |
||
| 1481 | 1481 | public function getFilterForUserCount() { |
| 1482 | 1482 | $filter = $this->combineFilterWithAnd(array( |
| 1483 | 1483 | $this->connection->ldapUserFilter, |
| 1484 | - $this->connection->ldapUserDisplayName . '=*' |
|
| 1484 | + $this->connection->ldapUserDisplayName.'=*' |
|
| 1485 | 1485 | )); |
| 1486 | 1486 | |
| 1487 | 1487 | return $filter; |
@@ -1499,7 +1499,7 @@ discard block |
||
| 1499 | 1499 | 'ldapAgentName' => $name, |
| 1500 | 1500 | 'ldapAgentPassword' => $password |
| 1501 | 1501 | ); |
| 1502 | - if(!$testConnection->setConfiguration($credentials)) { |
|
| 1502 | + if (!$testConnection->setConfiguration($credentials)) { |
|
| 1503 | 1503 | return false; |
| 1504 | 1504 | } |
| 1505 | 1505 | return $testConnection->bind(); |
@@ -1521,30 +1521,30 @@ discard block |
||
| 1521 | 1521 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
| 1522 | 1522 | // existing DN to be able to reliably detect it. |
| 1523 | 1523 | $result = $this->search($filter, $base, ['dn'], 1); |
| 1524 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1524 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1525 | 1525 | throw new \Exception('Cannot determine UUID attribute'); |
| 1526 | 1526 | } |
| 1527 | 1527 | $dn = $result[0]['dn'][0]; |
| 1528 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
| 1528 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
| 1529 | 1529 | throw new \Exception('Cannot determine UUID attribute'); |
| 1530 | 1530 | } |
| 1531 | 1531 | } else { |
| 1532 | 1532 | // The UUID attribute is either known or an override is given. |
| 1533 | 1533 | // By calling this method we ensure that $this->connection->$uuidAttr |
| 1534 | 1534 | // is definitely set |
| 1535 | - if(!$this->detectUuidAttribute('', true)) { |
|
| 1535 | + if (!$this->detectUuidAttribute('', true)) { |
|
| 1536 | 1536 | throw new \Exception('Cannot determine UUID attribute'); |
| 1537 | 1537 | } |
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
| 1541 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1541 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1542 | 1542 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | - $filter = $uuidAttr . '=' . $uuid; |
|
| 1545 | + $filter = $uuidAttr.'='.$uuid; |
|
| 1546 | 1546 | $result = $this->searchUsers($filter, ['dn'], 2); |
| 1547 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1547 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1548 | 1548 | // we put the count into account to make sure that this is |
| 1549 | 1549 | // really unique |
| 1550 | 1550 | return $result[0]['dn'][0]; |
@@ -1563,7 +1563,7 @@ discard block |
||
| 1563 | 1563 | * @return bool true on success, false otherwise |
| 1564 | 1564 | */ |
| 1565 | 1565 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
| 1566 | - if($isUser) { |
|
| 1566 | + if ($isUser) { |
|
| 1567 | 1567 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1568 | 1568 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1569 | 1569 | } else { |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1574 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1575 | 1575 | return true; |
| 1576 | 1576 | } |
| 1577 | 1577 | |
@@ -1580,10 +1580,10 @@ discard block |
||
| 1580 | 1580 | return true; |
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
| 1584 | - if($ldapRecord !== null) { |
|
| 1583 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
| 1584 | + if ($ldapRecord !== null) { |
|
| 1585 | 1585 | // we have the info from LDAP already, we don't need to talk to the server again |
| 1586 | - if(isset($ldapRecord[$attribute])) { |
|
| 1586 | + if (isset($ldapRecord[$attribute])) { |
|
| 1587 | 1587 | $this->connection->$uuidAttr = $attribute; |
| 1588 | 1588 | return true; |
| 1589 | 1589 | } else { |
@@ -1592,7 +1592,7 @@ discard block |
||
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | $value = $this->readAttribute($dn, $attribute); |
| 1595 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1595 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1596 | 1596 | \OCP\Util::writeLog('user_ldap', |
| 1597 | 1597 | 'Setting '.$attribute.' as '.$uuidAttr, |
| 1598 | 1598 | \OCP\Util::DEBUG); |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | * @return bool|string |
| 1615 | 1615 | */ |
| 1616 | 1616 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
| 1617 | - if($isUser) { |
|
| 1617 | + if ($isUser) { |
|
| 1618 | 1618 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1619 | 1619 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1620 | 1620 | } else { |
@@ -1623,10 +1623,10 @@ discard block |
||
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | $uuid = false; |
| 1626 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1626 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1627 | 1627 | $attr = $this->connection->$uuidAttr; |
| 1628 | 1628 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
| 1629 | - if( !is_array($uuid) |
|
| 1629 | + if (!is_array($uuid) |
|
| 1630 | 1630 | && $uuidOverride !== '' |
| 1631 | 1631 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
| 1632 | 1632 | { |
@@ -1634,7 +1634,7 @@ discard block |
||
| 1634 | 1634 | ? $ldapRecord[$this->connection->$uuidAttr] |
| 1635 | 1635 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
| 1636 | 1636 | } |
| 1637 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1637 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1638 | 1638 | $uuid = $uuid[0]; |
| 1639 | 1639 | } |
| 1640 | 1640 | } |
@@ -1651,19 +1651,19 @@ discard block |
||
| 1651 | 1651 | private function convertObjectGUID2Str($oguid) { |
| 1652 | 1652 | $hex_guid = bin2hex($oguid); |
| 1653 | 1653 | $hex_guid_to_guid_str = ''; |
| 1654 | - for($k = 1; $k <= 4; ++$k) { |
|
| 1654 | + for ($k = 1; $k <= 4; ++$k) { |
|
| 1655 | 1655 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
| 1656 | 1656 | } |
| 1657 | 1657 | $hex_guid_to_guid_str .= '-'; |
| 1658 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1658 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1659 | 1659 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
| 1660 | 1660 | } |
| 1661 | 1661 | $hex_guid_to_guid_str .= '-'; |
| 1662 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1662 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1663 | 1663 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
| 1664 | 1664 | } |
| 1665 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
| 1666 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
| 1665 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
| 1666 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
| 1667 | 1667 | |
| 1668 | 1668 | return strtoupper($hex_guid_to_guid_str); |
| 1669 | 1669 | } |
@@ -1680,11 +1680,11 @@ discard block |
||
| 1680 | 1680 | * @return string |
| 1681 | 1681 | */ |
| 1682 | 1682 | public function formatGuid2ForFilterUser($guid) { |
| 1683 | - if(!is_string($guid)) { |
|
| 1683 | + if (!is_string($guid)) { |
|
| 1684 | 1684 | throw new \InvalidArgumentException('String expected'); |
| 1685 | 1685 | } |
| 1686 | 1686 | $blocks = explode('-', $guid); |
| 1687 | - if(count($blocks) !== 5) { |
|
| 1687 | + if (count($blocks) !== 5) { |
|
| 1688 | 1688 | /* |
| 1689 | 1689 | * Why not throw an Exception instead? This method is a utility |
| 1690 | 1690 | * called only when trying to figure out whether a "missing" known |
@@ -1697,20 +1697,20 @@ discard block |
||
| 1697 | 1697 | * user. Instead we write a log message. |
| 1698 | 1698 | */ |
| 1699 | 1699 | \OC::$server->getLogger()->info( |
| 1700 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
| 1700 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
| 1701 | 1701 | '({uuid}) probably does not match UUID configuration.', |
| 1702 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
| 1702 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
| 1703 | 1703 | ); |
| 1704 | 1704 | return $guid; |
| 1705 | 1705 | } |
| 1706 | - for($i=0; $i < 3; $i++) { |
|
| 1706 | + for ($i = 0; $i < 3; $i++) { |
|
| 1707 | 1707 | $pairs = str_split($blocks[$i], 2); |
| 1708 | 1708 | $pairs = array_reverse($pairs); |
| 1709 | 1709 | $blocks[$i] = implode('', $pairs); |
| 1710 | 1710 | } |
| 1711 | - for($i=0; $i < 5; $i++) { |
|
| 1711 | + for ($i = 0; $i < 5; $i++) { |
|
| 1712 | 1712 | $pairs = str_split($blocks[$i], 2); |
| 1713 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
| 1713 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
| 1714 | 1714 | } |
| 1715 | 1715 | return implode('', $blocks); |
| 1716 | 1716 | } |
@@ -1724,12 +1724,12 @@ discard block |
||
| 1724 | 1724 | $domainDN = $this->getDomainDNFromDN($dn); |
| 1725 | 1725 | $cacheKey = 'getSID-'.$domainDN; |
| 1726 | 1726 | $sid = $this->connection->getFromCache($cacheKey); |
| 1727 | - if(!is_null($sid)) { |
|
| 1727 | + if (!is_null($sid)) { |
|
| 1728 | 1728 | return $sid; |
| 1729 | 1729 | } |
| 1730 | 1730 | |
| 1731 | 1731 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
| 1732 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
| 1732 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
| 1733 | 1733 | $this->connection->writeToCache($cacheKey, false); |
| 1734 | 1734 | return false; |
| 1735 | 1735 | } |
@@ -1787,12 +1787,12 @@ discard block |
||
| 1787 | 1787 | $belongsToBase = false; |
| 1788 | 1788 | $bases = $this->helper->sanitizeDN($bases); |
| 1789 | 1789 | |
| 1790 | - foreach($bases as $base) { |
|
| 1790 | + foreach ($bases as $base) { |
|
| 1791 | 1791 | $belongsToBase = true; |
| 1792 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
| 1792 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
| 1793 | 1793 | $belongsToBase = false; |
| 1794 | 1794 | } |
| 1795 | - if($belongsToBase) { |
|
| 1795 | + if ($belongsToBase) { |
|
| 1796 | 1796 | break; |
| 1797 | 1797 | } |
| 1798 | 1798 | } |
@@ -1803,7 +1803,7 @@ discard block |
||
| 1803 | 1803 | * resets a running Paged Search operation |
| 1804 | 1804 | */ |
| 1805 | 1805 | private function abandonPagedSearch() { |
| 1806 | - if($this->connection->hasPagedResultSupport) { |
|
| 1806 | + if ($this->connection->hasPagedResultSupport) { |
|
| 1807 | 1807 | $cr = $this->connection->getConnectionResource(); |
| 1808 | 1808 | $this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie); |
| 1809 | 1809 | $this->getPagedSearchResultState(); |
@@ -1821,16 +1821,16 @@ discard block |
||
| 1821 | 1821 | * @return string containing the key or empty if none is cached |
| 1822 | 1822 | */ |
| 1823 | 1823 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
| 1824 | - if($offset === 0) { |
|
| 1824 | + if ($offset === 0) { |
|
| 1825 | 1825 | return ''; |
| 1826 | 1826 | } |
| 1827 | 1827 | $offset -= $limit; |
| 1828 | 1828 | //we work with cache here |
| 1829 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); |
|
| 1829 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
| 1830 | 1830 | $cookie = ''; |
| 1831 | - if(isset($this->cookies[$cacheKey])) { |
|
| 1831 | + if (isset($this->cookies[$cacheKey])) { |
|
| 1832 | 1832 | $cookie = $this->cookies[$cacheKey]; |
| 1833 | - if(is_null($cookie)) { |
|
| 1833 | + if (is_null($cookie)) { |
|
| 1834 | 1834 | $cookie = ''; |
| 1835 | 1835 | } |
| 1836 | 1836 | } |
@@ -1848,11 +1848,11 @@ discard block |
||
| 1848 | 1848 | * @return bool |
| 1849 | 1849 | */ |
| 1850 | 1850 | public function hasMoreResults() { |
| 1851 | - if(!$this->connection->hasPagedResultSupport) { |
|
| 1851 | + if (!$this->connection->hasPagedResultSupport) { |
|
| 1852 | 1852 | return false; |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1855 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1856 | 1856 | // as in RFC 2696, when all results are returned, the cookie will |
| 1857 | 1857 | // be empty. |
| 1858 | 1858 | return false; |
@@ -1872,8 +1872,8 @@ discard block |
||
| 1872 | 1872 | */ |
| 1873 | 1873 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
| 1874 | 1874 | // allow '0' for 389ds |
| 1875 | - if(!empty($cookie) || $cookie === '0') { |
|
| 1876 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); |
|
| 1875 | + if (!empty($cookie) || $cookie === '0') { |
|
| 1876 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
| 1877 | 1877 | $this->cookies[$cacheKey] = $cookie; |
| 1878 | 1878 | $this->lastCookie = $cookie; |
| 1879 | 1879 | } |
@@ -1900,17 +1900,17 @@ discard block |
||
| 1900 | 1900 | */ |
| 1901 | 1901 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
| 1902 | 1902 | $pagedSearchOK = false; |
| 1903 | - if($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1903 | + if ($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1904 | 1904 | $offset = intval($offset); //can be null |
| 1905 | 1905 | \OCP\Util::writeLog('user_ldap', |
| 1906 | 1906 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
| 1907 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
| 1907 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
| 1908 | 1908 | \OCP\Util::DEBUG); |
| 1909 | 1909 | //get the cookie from the search for the previous search, required by LDAP |
| 1910 | - foreach($bases as $base) { |
|
| 1910 | + foreach ($bases as $base) { |
|
| 1911 | 1911 | |
| 1912 | 1912 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
| 1913 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1913 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1914 | 1914 | // no cookie known from a potential previous search. We need |
| 1915 | 1915 | // to start from 0 to come to the desired page. cookie value |
| 1916 | 1916 | // of '0' is valid, because 389ds |
@@ -1920,17 +1920,17 @@ discard block |
||
| 1920 | 1920 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
| 1921 | 1921 | // '0' is valid, because 389ds |
| 1922 | 1922 | //TODO: remember this, probably does not change in the next request... |
| 1923 | - if(empty($cookie) && $cookie !== '0') { |
|
| 1923 | + if (empty($cookie) && $cookie !== '0') { |
|
| 1924 | 1924 | $cookie = null; |
| 1925 | 1925 | } |
| 1926 | 1926 | } |
| 1927 | - if(!is_null($cookie)) { |
|
| 1927 | + if (!is_null($cookie)) { |
|
| 1928 | 1928 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
| 1929 | 1929 | $this->abandonPagedSearch(); |
| 1930 | 1930 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 1931 | 1931 | $this->connection->getConnectionResource(), $limit, |
| 1932 | 1932 | false, $cookie); |
| 1933 | - if(!$pagedSearchOK) { |
|
| 1933 | + if (!$pagedSearchOK) { |
|
| 1934 | 1934 | return false; |
| 1935 | 1935 | } |
| 1936 | 1936 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination |
| 1947 | 1947 | * if we don't have a previous paged search. |
| 1948 | 1948 | */ |
| 1949 | - } else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1949 | + } else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1950 | 1950 | // a search without limit was requested. However, if we do use |
| 1951 | 1951 | // Paged Search once, we always must do it. This requires us to |
| 1952 | 1952 | // initialize it with the configured page size. |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize); |
| 113 | 113 | $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize); |
| 114 | 114 | } |
| 115 | - return (int)$minPagingSize; |
|
| 115 | + return (int) $minPagingSize; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -123,20 +123,20 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $isBackgroundJobModeAjax = $this->config |
| 125 | 125 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
| 126 | - if($isBackgroundJobModeAjax) { |
|
| 126 | + if ($isBackgroundJobModeAjax) { |
|
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $cycleData = $this->getCycle(); |
| 131 | - if($cycleData === null) { |
|
| 131 | + if ($cycleData === null) { |
|
| 132 | 132 | $cycleData = $this->determineNextCycle(); |
| 133 | - if($cycleData === null) { |
|
| 133 | + if ($cycleData === null) { |
|
| 134 | 134 | $this->updateInterval(); |
| 135 | 135 | return; |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if(!$this->qualifiesToRun($cycleData)) { |
|
| 139 | + if (!$this->qualifiesToRun($cycleData)) { |
|
| 140 | 140 | $this->updateInterval(); |
| 141 | 141 | return; |
| 142 | 142 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | $filter = $access->combineFilterWithAnd(array( |
| 167 | 167 | $access->connection->ldapUserFilter, |
| 168 | - $access->connection->ldapUserDisplayName . '=*', |
|
| 168 | + $access->connection->ldapUserDisplayName.'=*', |
|
| 169 | 169 | $access->getFilterPartForUserSearch('') |
| 170 | 170 | )); |
| 171 | 171 | $results = $access->fetchListOfUsers( |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | true |
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - if((int)$connection->ldapPagingSize === 0) { |
|
| 179 | + if ((int) $connection->ldapPagingSize === 0) { |
|
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | - return count($results) >= (int)$connection->ldapPagingSize; |
|
| 182 | + return count($results) >= (int) $connection->ldapPagingSize; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function getCycle() { |
| 192 | 192 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
| 193 | - if(count($prefixes) === 0) { |
|
| 193 | + if (count($prefixes) === 0) { |
|
| 194 | 194 | return null; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $cycleData = [ |
| 198 | 198 | 'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null), |
| 199 | - 'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
| 199 | + 'offset' => (int) $this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
| 200 | 200 | ]; |
| 201 | 201 | |
| 202 | - if( |
|
| 202 | + if ( |
|
| 203 | 203 | $cycleData['prefix'] !== null |
| 204 | 204 | && in_array($cycleData['prefix'], $prefixes) |
| 205 | 205 | ) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | public function determineNextCycle(array $cycleData = null) { |
| 230 | 230 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
| 231 | - if(count($prefixes) === 0) { |
|
| 231 | + if (count($prefixes) === 0) { |
|
| 232 | 232 | return null; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // get the next prefix in line and remember it |
| 236 | 236 | $oldPrefix = $cycleData === null ? null : $cycleData['prefix']; |
| 237 | 237 | $prefix = $this->getNextPrefix($oldPrefix); |
| 238 | - if($prefix === null) { |
|
| 238 | + if ($prefix === null) { |
|
| 239 | 239 | return null; |
| 240 | 240 | } |
| 241 | 241 | $cycleData['prefix'] = $prefix; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @return bool |
| 254 | 254 | */ |
| 255 | 255 | public function qualifiesToRun($cycleData) { |
| 256 | - $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0); |
|
| 257 | - if((time() - $lastChange) > 60 * 30) { |
|
| 256 | + $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'].'_lastChange', 0); |
|
| 257 | + if ((time() - $lastChange) > 60 * 30) { |
|
| 258 | 258 | return true; |
| 259 | 259 | } |
| 260 | 260 | return false; |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | protected function increaseOffset($cycleData) { |
| 269 | 269 | $ldapConfig = new Configuration($cycleData['prefix']); |
| 270 | - $cycleData['offset'] += (int)$ldapConfig->ldapPagingSize; |
|
| 270 | + $cycleData['offset'] += (int) $ldapConfig->ldapPagingSize; |
|
| 271 | 271 | $this->setCycle($cycleData); |
| 272 | 272 | } |
| 273 | 273 | |
@@ -280,17 +280,17 @@ discard block |
||
| 280 | 280 | protected function getNextPrefix($lastPrefix) { |
| 281 | 281 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
| 282 | 282 | $noOfPrefixes = count($prefixes); |
| 283 | - if($noOfPrefixes === 0) { |
|
| 283 | + if ($noOfPrefixes === 0) { |
|
| 284 | 284 | return null; |
| 285 | 285 | } |
| 286 | 286 | $i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true); |
| 287 | - if($i === false) { |
|
| 287 | + if ($i === false) { |
|
| 288 | 288 | $i = -1; |
| 289 | 289 | } else { |
| 290 | 290 | $i++; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if(!isset($prefixes[$i])) { |
|
| 293 | + if (!isset($prefixes[$i])) { |
|
| 294 | 294 | $i = 0; |
| 295 | 295 | } |
| 296 | 296 | return $prefixes[$i]; |
@@ -302,49 +302,49 @@ discard block |
||
| 302 | 302 | * @param array $argument |
| 303 | 303 | */ |
| 304 | 304 | public function setArgument($argument) { |
| 305 | - if(isset($argument['config'])) { |
|
| 305 | + if (isset($argument['config'])) { |
|
| 306 | 306 | $this->config = $argument['config']; |
| 307 | 307 | } else { |
| 308 | 308 | $this->config = \OC::$server->getConfig(); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if(isset($argument['helper'])) { |
|
| 311 | + if (isset($argument['helper'])) { |
|
| 312 | 312 | $this->ldapHelper = $argument['helper']; |
| 313 | 313 | } else { |
| 314 | 314 | $this->ldapHelper = new Helper($this->config); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if(isset($argument['ldapWrapper'])) { |
|
| 317 | + if (isset($argument['ldapWrapper'])) { |
|
| 318 | 318 | $this->ldap = $argument['ldapWrapper']; |
| 319 | 319 | } else { |
| 320 | 320 | $this->ldap = new LDAP(); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if(isset($argument['avatarManager'])) { |
|
| 323 | + if (isset($argument['avatarManager'])) { |
|
| 324 | 324 | $this->avatarManager = $argument['avatarManager']; |
| 325 | 325 | } else { |
| 326 | 326 | $this->avatarManager = \OC::$server->getAvatarManager(); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if(isset($argument['dbc'])) { |
|
| 329 | + if (isset($argument['dbc'])) { |
|
| 330 | 330 | $this->dbc = $argument['dbc']; |
| 331 | 331 | } else { |
| 332 | 332 | $this->dbc = \OC::$server->getDatabaseConnection(); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if(isset($argument['ncUserManager'])) { |
|
| 335 | + if (isset($argument['ncUserManager'])) { |
|
| 336 | 336 | $this->ncUserManager = $argument['ncUserManager']; |
| 337 | 337 | } else { |
| 338 | 338 | $this->ncUserManager = \OC::$server->getUserManager(); |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if(isset($argument['notificationManager'])) { |
|
| 341 | + if (isset($argument['notificationManager'])) { |
|
| 342 | 342 | $this->notificationManager = $argument['notificationManager']; |
| 343 | 343 | } else { |
| 344 | 344 | $this->notificationManager = \OC::$server->getNotificationManager(); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if(isset($argument['userManager'])) { |
|
| 347 | + if (isset($argument['userManager'])) { |
|
| 348 | 348 | $this->userManager = $argument['userManager']; |
| 349 | 349 | } else { |
| 350 | 350 | $this->userManager = new Manager( |
@@ -359,19 +359,19 @@ discard block |
||
| 359 | 359 | ); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if(isset($argument['mapper'])) { |
|
| 362 | + if (isset($argument['mapper'])) { |
|
| 363 | 363 | $this->mapper = $argument['mapper']; |
| 364 | 364 | } else { |
| 365 | 365 | $this->mapper = new UserMapping($this->dbc); |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if(isset($argument['connectionFactory'])) { |
|
| 368 | + if (isset($argument['connectionFactory'])) { |
|
| 369 | 369 | $this->connectionFactory = $argument['connectionFactory']; |
| 370 | 370 | } else { |
| 371 | 371 | $this->connectionFactory = new ConnectionFactory($this->ldap); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if(isset($argument['accessFactory'])) { |
|
| 374 | + if (isset($argument['accessFactory'])) { |
|
| 375 | 375 | $this->accessFactory = $argument['accessFactory']; |
| 376 | 376 | } else { |
| 377 | 377 | $this->accessFactory = new AccessFactory( |