@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @return AbstractMapping |
| 130 | 130 | */ |
| 131 | 131 | public function getUserMapper() { |
| 132 | - if(is_null($this->userMapper)) { |
|
| 132 | + if (is_null($this->userMapper)) { |
|
| 133 | 133 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
| 134 | 134 | } |
| 135 | 135 | return $this->userMapper; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return AbstractMapping |
| 150 | 150 | */ |
| 151 | 151 | public function getGroupMapper() { |
| 152 | - if(is_null($this->groupMapper)) { |
|
| 152 | + if (is_null($this->groupMapper)) { |
|
| 153 | 153 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
| 154 | 154 | } |
| 155 | 155 | return $this->groupMapper; |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @throws ServerNotAvailableException |
| 183 | 183 | */ |
| 184 | 184 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
| 185 | - if(!$this->checkConnection()) { |
|
| 185 | + if (!$this->checkConnection()) { |
|
| 186 | 186 | \OCP\Util::writeLog('user_ldap', |
| 187 | 187 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
| 188 | 188 | ILogger::WARN); |
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | 191 | $cr = $this->connection->getConnectionResource(); |
| 192 | - if(!$this->ldap->isResource($cr)) { |
|
| 192 | + if (!$this->ldap->isResource($cr)) { |
|
| 193 | 193 | //LDAP not available |
| 194 | 194 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG); |
| 195 | 195 | return false; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $this->abandonPagedSearch(); |
| 200 | 200 | // openLDAP requires that we init a new Paged Search. Not needed by AD, |
| 201 | 201 | // but does not hurt either. |
| 202 | - $pagingSize = (int)$this->connection->ldapPagingSize; |
|
| 202 | + $pagingSize = (int) $this->connection->ldapPagingSize; |
|
| 203 | 203 | // 0 won't result in replies, small numbers may leave out groups |
| 204 | 204 | // (cf. #12306), 500 is default for paging and should work everywhere. |
| 205 | 205 | $maxResults = $pagingSize > 20 ? $pagingSize : 500; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $isRangeRequest = false; |
| 213 | 213 | do { |
| 214 | 214 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
| 215 | - if(is_bool($result)) { |
|
| 215 | + if (is_bool($result)) { |
|
| 216 | 216 | // when an exists request was run and it was successful, an empty |
| 217 | 217 | // array must be returned |
| 218 | 218 | return $result ? [] : false; |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | $result = $this->extractRangeData($result, $attr); |
| 230 | 230 | if (!empty($result)) { |
| 231 | 231 | $normalizedResult = $this->extractAttributeValuesFromResult( |
| 232 | - [ $attr => $result['values'] ], |
|
| 232 | + [$attr => $result['values']], |
|
| 233 | 233 | $attr |
| 234 | 234 | ); |
| 235 | 235 | $values = array_merge($values, $normalizedResult); |
| 236 | 236 | |
| 237 | - if($result['rangeHigh'] === '*') { |
|
| 237 | + if ($result['rangeHigh'] === '*') { |
|
| 238 | 238 | // when server replies with * as high range value, there are |
| 239 | 239 | // no more results left |
| 240 | 240 | return $values; |
| 241 | 241 | } else { |
| 242 | - $low = $result['rangeHigh'] + 1; |
|
| 243 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
| 242 | + $low = $result['rangeHigh'] + 1; |
|
| 243 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
| 244 | 244 | $isRangeRequest = true; |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | - } while($isRangeRequest); |
|
| 247 | + } while ($isRangeRequest); |
|
| 248 | 248 | |
| 249 | 249 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG); |
| 250 | 250 | return false; |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | if (!$this->ldap->isResource($rr)) { |
| 271 | 271 | if ($attribute !== '') { |
| 272 | 272 | //do not throw this message on userExists check, irritates |
| 273 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG); |
|
| 273 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG); |
|
| 274 | 274 | } |
| 275 | 275 | //in case an error occurs , e.g. object does not exist |
| 276 | 276 | return false; |
| 277 | 277 | } |
| 278 | 278 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
| 279 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG); |
|
| 279 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG); |
|
| 280 | 280 | return true; |
| 281 | 281 | } |
| 282 | 282 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | public function extractAttributeValuesFromResult($result, $attribute) { |
| 303 | 303 | $values = []; |
| 304 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 304 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 305 | 305 | $lowercaseAttribute = strtolower($attribute); |
| 306 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
| 307 | - if($this->resemblesDN($attribute)) { |
|
| 306 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
| 307 | + if ($this->resemblesDN($attribute)) { |
|
| 308 | 308 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
| 309 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 309 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 310 | 310 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
| 311 | 311 | } else { |
| 312 | 312 | $values[] = $result[$attribute][$i]; |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | public function extractRangeData($result, $attribute) { |
| 330 | 330 | $keys = array_keys($result); |
| 331 | - foreach($keys as $key) { |
|
| 332 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 331 | + foreach ($keys as $key) { |
|
| 332 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 333 | 333 | $queryData = explode(';', $key); |
| 334 | - if(strpos($queryData[1], 'range=') === 0) { |
|
| 334 | + if (strpos($queryData[1], 'range=') === 0) { |
|
| 335 | 335 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
| 336 | 336 | $data = [ |
| 337 | 337 | 'values' => $result[$key], |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | * @throws \Exception |
| 357 | 357 | */ |
| 358 | 358 | public function setPassword($userDN, $password) { |
| 359 | - if((int)$this->connection->turnOnPasswordChange !== 1) { |
|
| 359 | + if ((int) $this->connection->turnOnPasswordChange !== 1) { |
|
| 360 | 360 | throw new \Exception('LDAP password changes are disabled.'); |
| 361 | 361 | } |
| 362 | 362 | $cr = $this->connection->getConnectionResource(); |
| 363 | - if(!$this->ldap->isResource($cr)) { |
|
| 363 | + if (!$this->ldap->isResource($cr)) { |
|
| 364 | 364 | //LDAP not available |
| 365 | 365 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG); |
| 366 | 366 | return false; |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | // try PASSWD extended operation first |
| 370 | 370 | return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) || |
| 371 | 371 | @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
| 372 | - } catch(ConstraintViolationException $e) { |
|
| 372 | + } catch (ConstraintViolationException $e) { |
|
| 373 | 373 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -411,17 +411,17 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function getDomainDNFromDN($dn) { |
| 413 | 413 | $allParts = $this->ldap->explodeDN($dn, 0); |
| 414 | - if($allParts === false) { |
|
| 414 | + if ($allParts === false) { |
|
| 415 | 415 | //not a valid DN |
| 416 | 416 | return ''; |
| 417 | 417 | } |
| 418 | 418 | $domainParts = array(); |
| 419 | 419 | $dcFound = false; |
| 420 | - foreach($allParts as $part) { |
|
| 421 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 420 | + foreach ($allParts as $part) { |
|
| 421 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 422 | 422 | $dcFound = true; |
| 423 | 423 | } |
| 424 | - if($dcFound) { |
|
| 424 | + if ($dcFound) { |
|
| 425 | 425 | $domainParts[] = $part; |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
| 449 | 449 | //server setups |
| 450 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 450 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 451 | 451 | return $fdn; |
| 452 | 452 | } |
| 453 | 453 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | //To avoid bypassing the base DN settings under certain circumstances |
| 467 | 467 | //with the group support, check whether the provided DN matches one of |
| 468 | 468 | //the given Bases |
| 469 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 469 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
@@ -484,11 +484,11 @@ discard block |
||
| 484 | 484 | */ |
| 485 | 485 | public function groupsMatchFilter($groupDNs) { |
| 486 | 486 | $validGroupDNs = []; |
| 487 | - foreach($groupDNs as $dn) { |
|
| 487 | + foreach ($groupDNs as $dn) { |
|
| 488 | 488 | $cacheKey = 'groupsMatchFilter-'.$dn; |
| 489 | 489 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
| 490 | - if(!is_null($groupMatchFilter)) { |
|
| 491 | - if($groupMatchFilter) { |
|
| 490 | + if (!is_null($groupMatchFilter)) { |
|
| 491 | + if ($groupMatchFilter) { |
|
| 492 | 492 | $validGroupDNs[] = $dn; |
| 493 | 493 | } |
| 494 | 494 | continue; |
@@ -496,13 +496,13 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | // Check the base DN first. If this is not met already, we don't |
| 498 | 498 | // need to ask the server at all. |
| 499 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 499 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 500 | 500 | $this->connection->writeToCache($cacheKey, false); |
| 501 | 501 | continue; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | $result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter); |
| 505 | - if(is_array($result)) { |
|
| 505 | + if (is_array($result)) { |
|
| 506 | 506 | $this->connection->writeToCache($cacheKey, true); |
| 507 | 507 | $validGroupDNs[] = $dn; |
| 508 | 508 | } else { |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | //To avoid bypassing the base DN settings under certain circumstances |
| 526 | 526 | //with the group support, check whether the provided DN matches one of |
| 527 | 527 | //the given Bases |
| 528 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 528 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 529 | 529 | return false; |
| 530 | 530 | } |
| 531 | 531 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
| 547 | 547 | $newlyMapped = false; |
| 548 | - if($isUser) { |
|
| 548 | + if ($isUser) { |
|
| 549 | 549 | $mapper = $this->getUserMapper(); |
| 550 | 550 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 551 | 551 | $filter = $this->connection->ldapUserFilter; |
@@ -557,15 +557,15 @@ discard block |
||
| 557 | 557 | |
| 558 | 558 | //let's try to retrieve the Nextcloud name from the mappings table |
| 559 | 559 | $ncName = $mapper->getNameByDN($fdn); |
| 560 | - if(is_string($ncName)) { |
|
| 560 | + if (is_string($ncName)) { |
|
| 561 | 561 | return $ncName; |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
| 565 | 565 | $uuid = $this->getUUID($fdn, $isUser, $record); |
| 566 | - if(is_string($uuid)) { |
|
| 566 | + if (is_string($uuid)) { |
|
| 567 | 567 | $ncName = $mapper->getNameByUUID($uuid); |
| 568 | - if(is_string($ncName)) { |
|
| 568 | + if (is_string($ncName)) { |
|
| 569 | 569 | $mapper->setDNbyUUID($fdn, $uuid); |
| 570 | 570 | return $ncName; |
| 571 | 571 | } |
@@ -575,17 +575,17 @@ discard block |
||
| 575 | 575 | return false; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - if(is_null($ldapName)) { |
|
| 578 | + if (is_null($ldapName)) { |
|
| 579 | 579 | $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); |
| 580 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 580 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 581 | 581 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO); |
| 582 | 582 | return false; |
| 583 | 583 | } |
| 584 | 584 | $ldapName = $ldapName[0]; |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - if($isUser) { |
|
| 588 | - $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr; |
|
| 587 | + if ($isUser) { |
|
| 588 | + $usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr; |
|
| 589 | 589 | if ($usernameAttribute !== '') { |
| 590 | 590 | $username = $this->readAttribute($fdn, $usernameAttribute); |
| 591 | 591 | $username = $username[0]; |
@@ -615,14 +615,14 @@ discard block |
||
| 615 | 615 | // outside of core user management will still cache the user as non-existing. |
| 616 | 616 | $originalTTL = $this->connection->ldapCacheTTL; |
| 617 | 617 | $this->connection->setConfiguration(['ldapCacheTTL' => 0]); |
| 618 | - if( $intName !== '' |
|
| 618 | + if ($intName !== '' |
|
| 619 | 619 | && (($isUser && !$this->ncUserManager->userExists($intName)) |
| 620 | 620 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName)) |
| 621 | 621 | ) |
| 622 | 622 | ) { |
| 623 | 623 | $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); |
| 624 | 624 | $newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser); |
| 625 | - if($newlyMapped) { |
|
| 625 | + if ($newlyMapped) { |
|
| 626 | 626 | return $intName; |
| 627 | 627 | } |
| 628 | 628 | } |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); |
| 631 | 631 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
| 632 | 632 | if (is_string($altName)) { |
| 633 | - if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) { |
|
| 633 | + if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) { |
|
| 634 | 634 | $newlyMapped = true; |
| 635 | 635 | return $altName; |
| 636 | 636 | } |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | string $uuid, |
| 649 | 649 | bool $isUser |
| 650 | 650 | ) :bool { |
| 651 | - if($mapper->map($fdn, $name, $uuid)) { |
|
| 651 | + if ($mapper->map($fdn, $name, $uuid)) { |
|
| 652 | 652 | if ($this->ncUserManager instanceof PublicEmitter && $isUser) { |
| 653 | 653 | $this->cacheUserExists($name); |
| 654 | 654 | $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]); |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | * @throws \Exception |
| 692 | 692 | */ |
| 693 | 693 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
| 694 | - if($isUsers) { |
|
| 694 | + if ($isUsers) { |
|
| 695 | 695 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 696 | 696 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
| 697 | 697 | } else { |
@@ -699,9 +699,9 @@ discard block |
||
| 699 | 699 | } |
| 700 | 700 | $nextcloudNames = []; |
| 701 | 701 | |
| 702 | - foreach($ldapObjects as $ldapObject) { |
|
| 702 | + foreach ($ldapObjects as $ldapObject) { |
|
| 703 | 703 | $nameByLDAP = null; |
| 704 | - if( isset($ldapObject[$nameAttribute]) |
|
| 704 | + if (isset($ldapObject[$nameAttribute]) |
|
| 705 | 705 | && is_array($ldapObject[$nameAttribute]) |
| 706 | 706 | && isset($ldapObject[$nameAttribute][0]) |
| 707 | 707 | ) { |
@@ -710,19 +710,19 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
| 713 | - if($ncName) { |
|
| 713 | + if ($ncName) { |
|
| 714 | 714 | $nextcloudNames[] = $ncName; |
| 715 | - if($isUsers) { |
|
| 715 | + if ($isUsers) { |
|
| 716 | 716 | $this->updateUserState($ncName); |
| 717 | 717 | //cache the user names so it does not need to be retrieved |
| 718 | 718 | //again later (e.g. sharing dialogue). |
| 719 | - if(is_null($nameByLDAP)) { |
|
| 719 | + if (is_null($nameByLDAP)) { |
|
| 720 | 720 | continue; |
| 721 | 721 | } |
| 722 | 722 | $sndName = isset($ldapObject[$sndAttribute][0]) |
| 723 | 723 | ? $ldapObject[$sndAttribute][0] : ''; |
| 724 | 724 | $this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName); |
| 725 | - } else if($nameByLDAP !== null) { |
|
| 725 | + } else if ($nameByLDAP !== null) { |
|
| 726 | 726 | $this->cacheGroupDisplayName($ncName, $nameByLDAP); |
| 727 | 727 | } |
| 728 | 728 | } |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | */ |
| 739 | 739 | public function updateUserState($ncname) { |
| 740 | 740 | $user = $this->userManager->get($ncname); |
| 741 | - if($user instanceof OfflineUser) { |
|
| 741 | + if ($user instanceof OfflineUser) { |
|
| 742 | 742 | $user->unmark(); |
| 743 | 743 | } |
| 744 | 744 | } |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | */ |
| 772 | 772 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
| 773 | 773 | $user = $this->userManager->get($ocName); |
| 774 | - if($user === null) { |
|
| 774 | + if ($user === null) { |
|
| 775 | 775 | return; |
| 776 | 776 | } |
| 777 | 777 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | public function cacheGroupDisplayName(string $ncName, string $displayName): void { |
| 783 | - $cacheKey = 'group_getDisplayName' . $ncName; |
|
| 783 | + $cacheKey = 'group_getDisplayName'.$ncName; |
|
| 784 | 784 | $this->connection->writeToCache($cacheKey, $displayName); |
| 785 | 785 | } |
| 786 | 786 | |
@@ -796,9 +796,9 @@ discard block |
||
| 796 | 796 | $attempts = 0; |
| 797 | 797 | //while loop is just a precaution. If a name is not generated within |
| 798 | 798 | //20 attempts, something else is very wrong. Avoids infinite loop. |
| 799 | - while($attempts < 20){ |
|
| 800 | - $altName = $name . '_' . rand(1000,9999); |
|
| 801 | - if(!$this->ncUserManager->userExists($altName)) { |
|
| 799 | + while ($attempts < 20) { |
|
| 800 | + $altName = $name.'_'.rand(1000, 9999); |
|
| 801 | + if (!$this->ncUserManager->userExists($altName)) { |
|
| 802 | 802 | return $altName; |
| 803 | 803 | } |
| 804 | 804 | $attempts++; |
@@ -820,25 +820,25 @@ discard block |
||
| 820 | 820 | */ |
| 821 | 821 | private function _createAltInternalOwnCloudNameForGroups($name) { |
| 822 | 822 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
| 823 | - if(!$usedNames || count($usedNames) === 0) { |
|
| 823 | + if (!$usedNames || count($usedNames) === 0) { |
|
| 824 | 824 | $lastNo = 1; //will become name_2 |
| 825 | 825 | } else { |
| 826 | 826 | natsort($usedNames); |
| 827 | 827 | $lastName = array_pop($usedNames); |
| 828 | - $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1); |
|
| 828 | + $lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1); |
|
| 829 | 829 | } |
| 830 | - $altName = $name.'_'. (string)($lastNo+1); |
|
| 830 | + $altName = $name.'_'.(string) ($lastNo + 1); |
|
| 831 | 831 | unset($usedNames); |
| 832 | 832 | |
| 833 | 833 | $attempts = 1; |
| 834 | - while($attempts < 21){ |
|
| 834 | + while ($attempts < 21) { |
|
| 835 | 835 | // Check to be really sure it is unique |
| 836 | 836 | // while loop is just a precaution. If a name is not generated within |
| 837 | 837 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
| 838 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 838 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 839 | 839 | return $altName; |
| 840 | 840 | } |
| 841 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
| 841 | + $altName = $name.'_'.($lastNo + $attempts); |
|
| 842 | 842 | $attempts++; |
| 843 | 843 | } |
| 844 | 844 | return false; |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | private function createAltInternalOwnCloudName($name, $isUser) { |
| 854 | 854 | $originalTTL = $this->connection->ldapCacheTTL; |
| 855 | 855 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 856 | - if($isUser) { |
|
| 856 | + if ($isUser) { |
|
| 857 | 857 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
| 858 | 858 | } else { |
| 859 | 859 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -902,13 +902,13 @@ discard block |
||
| 902 | 902 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
| 903 | 903 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
| 904 | 904 | $recordsToUpdate = $ldapRecords; |
| 905 | - if(!$forceApplyAttributes) { |
|
| 905 | + if (!$forceApplyAttributes) { |
|
| 906 | 906 | $isBackgroundJobModeAjax = $this->config |
| 907 | 907 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
| 908 | 908 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
| 909 | 909 | $newlyMapped = false; |
| 910 | 910 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
| 911 | - if(is_string($uid)) { |
|
| 911 | + if (is_string($uid)) { |
|
| 912 | 912 | $this->cacheUserExists($uid); |
| 913 | 913 | } |
| 914 | 914 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -926,15 +926,15 @@ discard block |
||
| 926 | 926 | * @param array $ldapRecords |
| 927 | 927 | * @throws \Exception |
| 928 | 928 | */ |
| 929 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
| 929 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
| 930 | 930 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
| 931 | - foreach($ldapRecords as $userRecord) { |
|
| 932 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
| 931 | + foreach ($ldapRecords as $userRecord) { |
|
| 932 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
| 933 | 933 | // displayName is obligatory |
| 934 | 934 | continue; |
| 935 | 935 | } |
| 936 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 937 | - if($ocName === false) { |
|
| 936 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 937 | + if ($ocName === false) { |
|
| 938 | 938 | continue; |
| 939 | 939 | } |
| 940 | 940 | $this->updateUserState($ocName); |
@@ -967,8 +967,8 @@ discard block |
||
| 967 | 967 | * @return array |
| 968 | 968 | */ |
| 969 | 969 | private function fetchList($list, $manyAttributes) { |
| 970 | - if(is_array($list)) { |
|
| 971 | - if($manyAttributes) { |
|
| 970 | + if (is_array($list)) { |
|
| 971 | + if ($manyAttributes) { |
|
| 972 | 972 | return $list; |
| 973 | 973 | } else { |
| 974 | 974 | $list = array_reduce($list, function($carry, $item) { |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | */ |
| 999 | 999 | public function searchUsers($filter, $attr = null, $limit = null, $offset = null) { |
| 1000 | 1000 | $result = []; |
| 1001 | - foreach($this->connection->ldapBaseUsers as $base) { |
|
| 1001 | + foreach ($this->connection->ldapBaseUsers as $base) { |
|
| 1002 | 1002 | $result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset)); |
| 1003 | 1003 | } |
| 1004 | 1004 | return $result; |
@@ -1014,9 +1014,9 @@ discard block |
||
| 1014 | 1014 | */ |
| 1015 | 1015 | public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { |
| 1016 | 1016 | $result = false; |
| 1017 | - foreach($this->connection->ldapBaseUsers as $base) { |
|
| 1017 | + foreach ($this->connection->ldapBaseUsers as $base) { |
|
| 1018 | 1018 | $count = $this->count($filter, [$base], $attr, $limit, $offset); |
| 1019 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
| 1019 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | return $result; |
| 1022 | 1022 | } |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | */ |
| 1036 | 1036 | public function searchGroups($filter, $attr = null, $limit = null, $offset = null) { |
| 1037 | 1037 | $result = []; |
| 1038 | - foreach($this->connection->ldapBaseGroups as $base) { |
|
| 1038 | + foreach ($this->connection->ldapBaseGroups as $base) { |
|
| 1039 | 1039 | $result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset)); |
| 1040 | 1040 | } |
| 1041 | 1041 | return $result; |
@@ -1053,9 +1053,9 @@ discard block |
||
| 1053 | 1053 | */ |
| 1054 | 1054 | public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) { |
| 1055 | 1055 | $result = false; |
| 1056 | - foreach($this->connection->ldapBaseGroups as $base) { |
|
| 1056 | + foreach ($this->connection->ldapBaseGroups as $base) { |
|
| 1057 | 1057 | $count = $this->count($filter, [$base], $attr, $limit, $offset); |
| 1058 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
| 1058 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | return $result; |
| 1061 | 1061 | } |
@@ -1070,9 +1070,9 @@ discard block |
||
| 1070 | 1070 | */ |
| 1071 | 1071 | public function countObjects($limit = null, $offset = null) { |
| 1072 | 1072 | $result = false; |
| 1073 | - foreach($this->connection->ldapBase as $base) { |
|
| 1073 | + foreach ($this->connection->ldapBase as $base) { |
|
| 1074 | 1074 | $count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset); |
| 1075 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
| 1075 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
| 1076 | 1076 | } |
| 1077 | 1077 | return $result; |
| 1078 | 1078 | } |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | // php no longer supports call-time pass-by-reference |
| 1098 | 1098 | // thus cannot support controlPagedResultResponse as the third argument |
| 1099 | 1099 | // is a reference |
| 1100 | - $doMethod = function () use ($command, &$arguments) { |
|
| 1100 | + $doMethod = function() use ($command, &$arguments) { |
|
| 1101 | 1101 | if ($command == 'controlPagedResultResponse') { |
| 1102 | 1102 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
| 1103 | 1103 | } else { |
@@ -1115,7 +1115,7 @@ discard block |
||
| 1115 | 1115 | $this->connection->resetConnectionResource(); |
| 1116 | 1116 | $cr = $this->connection->getConnectionResource(); |
| 1117 | 1117 | |
| 1118 | - if(!$this->ldap->isResource($cr)) { |
|
| 1118 | + if (!$this->ldap->isResource($cr)) { |
|
| 1119 | 1119 | // Seems like we didn't find any resource. |
| 1120 | 1120 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG); |
| 1121 | 1121 | throw $e; |
@@ -1140,13 +1140,13 @@ discard block |
||
| 1140 | 1140 | * @throws ServerNotAvailableException |
| 1141 | 1141 | */ |
| 1142 | 1142 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
| 1143 | - if(!is_null($attr) && !is_array($attr)) { |
|
| 1143 | + if (!is_null($attr) && !is_array($attr)) { |
|
| 1144 | 1144 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | // See if we have a resource, in case not cancel with message |
| 1148 | 1148 | $cr = $this->connection->getConnectionResource(); |
| 1149 | - if(!$this->ldap->isResource($cr)) { |
|
| 1149 | + if (!$this->ldap->isResource($cr)) { |
|
| 1150 | 1150 | // Seems like we didn't find any resource. |
| 1151 | 1151 | // Return an empty array just like before. |
| 1152 | 1152 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG); |
@@ -1154,13 +1154,13 @@ discard block |
||
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | //check whether paged search should be attempted |
| 1157 | - $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset); |
|
| 1157 | + $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset); |
|
| 1158 | 1158 | |
| 1159 | 1159 | $linkResources = array_pad(array(), count($base), $cr); |
| 1160 | 1160 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
| 1161 | 1161 | // cannot use $cr anymore, might have changed in the previous call! |
| 1162 | 1162 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
| 1163 | - if(!is_array($sr) || $error !== 0) { |
|
| 1163 | + if (!is_array($sr) || $error !== 0) { |
|
| 1164 | 1164 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR); |
| 1165 | 1165 | return false; |
| 1166 | 1166 | } |
@@ -1185,29 +1185,29 @@ discard block |
||
| 1185 | 1185 | */ |
| 1186 | 1186 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
| 1187 | 1187 | $cookie = null; |
| 1188 | - if($pagedSearchOK) { |
|
| 1188 | + if ($pagedSearchOK) { |
|
| 1189 | 1189 | $cr = $this->connection->getConnectionResource(); |
| 1190 | - foreach($sr as $key => $res) { |
|
| 1191 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1190 | + foreach ($sr as $key => $res) { |
|
| 1191 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1192 | 1192 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
| 1193 | 1193 | } |
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | 1196 | //browsing through prior pages to get the cookie for the new one |
| 1197 | - if($skipHandling) { |
|
| 1197 | + if ($skipHandling) { |
|
| 1198 | 1198 | return false; |
| 1199 | 1199 | } |
| 1200 | 1200 | // if count is bigger, then the server does not support |
| 1201 | 1201 | // paged search. Instead, he did a normal search. We set a |
| 1202 | 1202 | // flag here, so the callee knows how to deal with it. |
| 1203 | - if($iFoundItems <= $limit) { |
|
| 1203 | + if ($iFoundItems <= $limit) { |
|
| 1204 | 1204 | $this->pagedSearchedSuccessful = true; |
| 1205 | 1205 | } |
| 1206 | 1206 | } else { |
| 1207 | - if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) { |
|
| 1207 | + if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) { |
|
| 1208 | 1208 | \OC::$server->getLogger()->debug( |
| 1209 | 1209 | 'Paged search was not available', |
| 1210 | - [ 'app' => 'user_ldap' ] |
|
| 1210 | + ['app' => 'user_ldap'] |
|
| 1211 | 1211 | ); |
| 1212 | 1212 | } |
| 1213 | 1213 | } |
@@ -1236,8 +1236,8 @@ discard block |
||
| 1236 | 1236 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1237 | 1237 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), ILogger::DEBUG); |
| 1238 | 1238 | |
| 1239 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
| 1240 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1239 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
| 1240 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1241 | 1241 | $limitPerPage = $limit; |
| 1242 | 1242 | } |
| 1243 | 1243 | |
@@ -1247,7 +1247,7 @@ discard block |
||
| 1247 | 1247 | |
| 1248 | 1248 | do { |
| 1249 | 1249 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1250 | - if($search === false) { |
|
| 1250 | + if ($search === false) { |
|
| 1251 | 1251 | return $counter > 0 ? $counter : false; |
| 1252 | 1252 | } |
| 1253 | 1253 | list($sr, $pagedSearchOK) = $search; |
@@ -1266,7 +1266,7 @@ discard block |
||
| 1266 | 1266 | * Continue now depends on $hasMorePages value |
| 1267 | 1267 | */ |
| 1268 | 1268 | $continue = $pagedSearchOK && $hasMorePages; |
| 1269 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1269 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1270 | 1270 | |
| 1271 | 1271 | return $counter; |
| 1272 | 1272 | } |
@@ -1279,8 +1279,8 @@ discard block |
||
| 1279 | 1279 | private function countEntriesInSearchResults($searchResults) { |
| 1280 | 1280 | $counter = 0; |
| 1281 | 1281 | |
| 1282 | - foreach($searchResults as $res) { |
|
| 1283 | - $count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
| 1282 | + foreach ($searchResults as $res) { |
|
| 1283 | + $count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
| 1284 | 1284 | $counter += $count; |
| 1285 | 1285 | } |
| 1286 | 1286 | |
@@ -1300,8 +1300,8 @@ discard block |
||
| 1300 | 1300 | * @throws ServerNotAvailableException |
| 1301 | 1301 | */ |
| 1302 | 1302 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1303 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
| 1304 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1303 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
| 1304 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1305 | 1305 | $limitPerPage = $limit; |
| 1306 | 1306 | } |
| 1307 | 1307 | |
@@ -1315,13 +1315,13 @@ discard block |
||
| 1315 | 1315 | $savedoffset = $offset; |
| 1316 | 1316 | do { |
| 1317 | 1317 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1318 | - if($search === false) { |
|
| 1318 | + if ($search === false) { |
|
| 1319 | 1319 | return []; |
| 1320 | 1320 | } |
| 1321 | 1321 | list($sr, $pagedSearchOK) = $search; |
| 1322 | 1322 | $cr = $this->connection->getConnectionResource(); |
| 1323 | 1323 | |
| 1324 | - if($skipHandling) { |
|
| 1324 | + if ($skipHandling) { |
|
| 1325 | 1325 | //i.e. result do not need to be fetched, we just need the cookie |
| 1326 | 1326 | //thus pass 1 or any other value as $iFoundItems because it is not |
| 1327 | 1327 | //used |
@@ -1332,7 +1332,7 @@ discard block |
||
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | $iFoundItems = 0; |
| 1335 | - foreach($sr as $res) { |
|
| 1335 | + foreach ($sr as $res) { |
|
| 1336 | 1336 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
| 1337 | 1337 | $iFoundItems = max($iFoundItems, $findings['count']); |
| 1338 | 1338 | unset($findings['count']); |
@@ -1348,27 +1348,27 @@ discard block |
||
| 1348 | 1348 | |
| 1349 | 1349 | // if we're here, probably no connection resource is returned. |
| 1350 | 1350 | // to make Nextcloud behave nicely, we simply give back an empty array. |
| 1351 | - if(is_null($findings)) { |
|
| 1351 | + if (is_null($findings)) { |
|
| 1352 | 1352 | return array(); |
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | - if(!is_null($attr)) { |
|
| 1355 | + if (!is_null($attr)) { |
|
| 1356 | 1356 | $selection = []; |
| 1357 | 1357 | $i = 0; |
| 1358 | - foreach($findings as $item) { |
|
| 1359 | - if(!is_array($item)) { |
|
| 1358 | + foreach ($findings as $item) { |
|
| 1359 | + if (!is_array($item)) { |
|
| 1360 | 1360 | continue; |
| 1361 | 1361 | } |
| 1362 | 1362 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
| 1363 | - foreach($attr as $key) { |
|
| 1364 | - if(isset($item[$key])) { |
|
| 1365 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1363 | + foreach ($attr as $key) { |
|
| 1364 | + if (isset($item[$key])) { |
|
| 1365 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1366 | 1366 | unset($item[$key]['count']); |
| 1367 | 1367 | } |
| 1368 | - if($key !== 'dn') { |
|
| 1369 | - if($this->resemblesDN($key)) { |
|
| 1368 | + if ($key !== 'dn') { |
|
| 1369 | + if ($this->resemblesDN($key)) { |
|
| 1370 | 1370 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
| 1371 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
| 1371 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
| 1372 | 1372 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
| 1373 | 1373 | } else { |
| 1374 | 1374 | $selection[$i][$key] = $item[$key]; |
@@ -1386,14 +1386,14 @@ discard block |
||
| 1386 | 1386 | //we slice the findings, when |
| 1387 | 1387 | //a) paged search unsuccessful, though attempted |
| 1388 | 1388 | //b) no paged search, but limit set |
| 1389 | - if((!$this->getPagedSearchResultState() |
|
| 1389 | + if ((!$this->getPagedSearchResultState() |
|
| 1390 | 1390 | && $pagedSearchOK) |
| 1391 | 1391 | || ( |
| 1392 | 1392 | !$pagedSearchOK |
| 1393 | 1393 | && !is_null($limit) |
| 1394 | 1394 | ) |
| 1395 | 1395 | ) { |
| 1396 | - $findings = array_slice($findings, (int)$offset, $limit); |
|
| 1396 | + $findings = array_slice($findings, (int) $offset, $limit); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | return $findings; |
| 1399 | 1399 | } |
@@ -1406,13 +1406,13 @@ discard block |
||
| 1406 | 1406 | public function sanitizeUsername($name) { |
| 1407 | 1407 | $name = trim($name); |
| 1408 | 1408 | |
| 1409 | - if($this->connection->ldapIgnoreNamingRules) { |
|
| 1409 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
| 1410 | 1410 | return $name; |
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | 1413 | // Transliteration to ASCII |
| 1414 | 1414 | $transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name); |
| 1415 | - if($transliterated !== false) { |
|
| 1415 | + if ($transliterated !== false) { |
|
| 1416 | 1416 | // depending on system config iconv can work or not |
| 1417 | 1417 | $name = $transliterated; |
| 1418 | 1418 | } |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | // Every remaining disallowed characters will be removed |
| 1424 | 1424 | $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name); |
| 1425 | 1425 | |
| 1426 | - if($name === '') { |
|
| 1426 | + if ($name === '') { |
|
| 1427 | 1427 | throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters'); |
| 1428 | 1428 | } |
| 1429 | 1429 | |
@@ -1438,13 +1438,13 @@ discard block |
||
| 1438 | 1438 | */ |
| 1439 | 1439 | public function escapeFilterPart($input, $allowAsterisk = false) { |
| 1440 | 1440 | $asterisk = ''; |
| 1441 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1441 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1442 | 1442 | $asterisk = '*'; |
| 1443 | 1443 | $input = mb_substr($input, 1, null, 'UTF-8'); |
| 1444 | 1444 | } |
| 1445 | 1445 | $search = array('*', '\\', '(', ')'); |
| 1446 | 1446 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
| 1447 | - return $asterisk . str_replace($search, $replace, $input); |
|
| 1447 | + return $asterisk.str_replace($search, $replace, $input); |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | /** |
@@ -1474,13 +1474,13 @@ discard block |
||
| 1474 | 1474 | */ |
| 1475 | 1475 | private function combineFilter($filters, $operator) { |
| 1476 | 1476 | $combinedFilter = '('.$operator; |
| 1477 | - foreach($filters as $filter) { |
|
| 1477 | + foreach ($filters as $filter) { |
|
| 1478 | 1478 | if ($filter !== '' && $filter[0] !== '(') { |
| 1479 | 1479 | $filter = '('.$filter.')'; |
| 1480 | 1480 | } |
| 1481 | - $combinedFilter.=$filter; |
|
| 1481 | + $combinedFilter .= $filter; |
|
| 1482 | 1482 | } |
| 1483 | - $combinedFilter.=')'; |
|
| 1483 | + $combinedFilter .= ')'; |
|
| 1484 | 1484 | return $combinedFilter; |
| 1485 | 1485 | } |
| 1486 | 1486 | |
@@ -1516,17 +1516,17 @@ discard block |
||
| 1516 | 1516 | * @throws \Exception |
| 1517 | 1517 | */ |
| 1518 | 1518 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
| 1519 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1519 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1520 | 1520 | throw new \Exception('searchAttributes must be an array with at least two string'); |
| 1521 | 1521 | } |
| 1522 | 1522 | $searchWords = explode(' ', trim($search)); |
| 1523 | 1523 | $wordFilters = array(); |
| 1524 | - foreach($searchWords as $word) { |
|
| 1524 | + foreach ($searchWords as $word) { |
|
| 1525 | 1525 | $word = $this->prepareSearchTerm($word); |
| 1526 | 1526 | //every word needs to appear at least once |
| 1527 | 1527 | $wordMatchOneAttrFilters = array(); |
| 1528 | - foreach($searchAttributes as $attr) { |
|
| 1529 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
| 1528 | + foreach ($searchAttributes as $attr) { |
|
| 1529 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
| 1532 | 1532 | } |
@@ -1544,10 +1544,10 @@ discard block |
||
| 1544 | 1544 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
| 1545 | 1545 | $filter = array(); |
| 1546 | 1546 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
| 1547 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1547 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1548 | 1548 | try { |
| 1549 | 1549 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
| 1550 | - } catch(\Exception $e) { |
|
| 1550 | + } catch (\Exception $e) { |
|
| 1551 | 1551 | \OCP\Util::writeLog( |
| 1552 | 1552 | 'user_ldap', |
| 1553 | 1553 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1557,17 +1557,17 @@ discard block |
||
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | $search = $this->prepareSearchTerm($search); |
| 1560 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1560 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1561 | 1561 | if ($fallbackAttribute === '') { |
| 1562 | 1562 | return ''; |
| 1563 | 1563 | } |
| 1564 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
| 1564 | + $filter[] = $fallbackAttribute.'='.$search; |
|
| 1565 | 1565 | } else { |
| 1566 | - foreach($searchAttributes as $attribute) { |
|
| 1567 | - $filter[] = $attribute . '=' . $search; |
|
| 1566 | + foreach ($searchAttributes as $attribute) { |
|
| 1567 | + $filter[] = $attribute.'='.$search; |
|
| 1568 | 1568 | } |
| 1569 | 1569 | } |
| 1570 | - if(count($filter) === 1) { |
|
| 1570 | + if (count($filter) === 1) { |
|
| 1571 | 1571 | return '('.$filter[0].')'; |
| 1572 | 1572 | } |
| 1573 | 1573 | return $this->combineFilterWithOr($filter); |
@@ -1588,7 +1588,7 @@ discard block |
||
| 1588 | 1588 | if ($term === '') { |
| 1589 | 1589 | $result = '*'; |
| 1590 | 1590 | } else if ($allowEnum !== 'no') { |
| 1591 | - $result = $term . '*'; |
|
| 1591 | + $result = $term.'*'; |
|
| 1592 | 1592 | } |
| 1593 | 1593 | return $result; |
| 1594 | 1594 | } |
@@ -1600,7 +1600,7 @@ discard block |
||
| 1600 | 1600 | public function getFilterForUserCount() { |
| 1601 | 1601 | $filter = $this->combineFilterWithAnd(array( |
| 1602 | 1602 | $this->connection->ldapUserFilter, |
| 1603 | - $this->connection->ldapUserDisplayName . '=*' |
|
| 1603 | + $this->connection->ldapUserDisplayName.'=*' |
|
| 1604 | 1604 | )); |
| 1605 | 1605 | |
| 1606 | 1606 | return $filter; |
@@ -1618,7 +1618,7 @@ discard block |
||
| 1618 | 1618 | 'ldapAgentName' => $name, |
| 1619 | 1619 | 'ldapAgentPassword' => $password |
| 1620 | 1620 | ); |
| 1621 | - if(!$testConnection->setConfiguration($credentials)) { |
|
| 1621 | + if (!$testConnection->setConfiguration($credentials)) { |
|
| 1622 | 1622 | return false; |
| 1623 | 1623 | } |
| 1624 | 1624 | return $testConnection->bind(); |
@@ -1640,30 +1640,30 @@ discard block |
||
| 1640 | 1640 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
| 1641 | 1641 | // existing DN to be able to reliably detect it. |
| 1642 | 1642 | $result = $this->search($filter, $base, ['dn'], 1); |
| 1643 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1643 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1644 | 1644 | throw new \Exception('Cannot determine UUID attribute'); |
| 1645 | 1645 | } |
| 1646 | 1646 | $dn = $result[0]['dn'][0]; |
| 1647 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
| 1647 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
| 1648 | 1648 | throw new \Exception('Cannot determine UUID attribute'); |
| 1649 | 1649 | } |
| 1650 | 1650 | } else { |
| 1651 | 1651 | // The UUID attribute is either known or an override is given. |
| 1652 | 1652 | // By calling this method we ensure that $this->connection->$uuidAttr |
| 1653 | 1653 | // is definitely set |
| 1654 | - if(!$this->detectUuidAttribute('', true)) { |
|
| 1654 | + if (!$this->detectUuidAttribute('', true)) { |
|
| 1655 | 1655 | throw new \Exception('Cannot determine UUID attribute'); |
| 1656 | 1656 | } |
| 1657 | 1657 | } |
| 1658 | 1658 | |
| 1659 | 1659 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
| 1660 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1660 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1661 | 1661 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
| 1662 | 1662 | } |
| 1663 | 1663 | |
| 1664 | - $filter = $uuidAttr . '=' . $uuid; |
|
| 1664 | + $filter = $uuidAttr.'='.$uuid; |
|
| 1665 | 1665 | $result = $this->searchUsers($filter, ['dn'], 2); |
| 1666 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1666 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1667 | 1667 | // we put the count into account to make sure that this is |
| 1668 | 1668 | // really unique |
| 1669 | 1669 | return $result[0]['dn'][0]; |
@@ -1683,7 +1683,7 @@ discard block |
||
| 1683 | 1683 | * @throws ServerNotAvailableException |
| 1684 | 1684 | */ |
| 1685 | 1685 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
| 1686 | - if($isUser) { |
|
| 1686 | + if ($isUser) { |
|
| 1687 | 1687 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1688 | 1688 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1689 | 1689 | } else { |
@@ -1691,7 +1691,7 @@ discard block |
||
| 1691 | 1691 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1694 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1695 | 1695 | return true; |
| 1696 | 1696 | } |
| 1697 | 1697 | |
@@ -1700,10 +1700,10 @@ discard block |
||
| 1700 | 1700 | return true; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
| 1704 | - if($ldapRecord !== null) { |
|
| 1703 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
| 1704 | + if ($ldapRecord !== null) { |
|
| 1705 | 1705 | // we have the info from LDAP already, we don't need to talk to the server again |
| 1706 | - if(isset($ldapRecord[$attribute])) { |
|
| 1706 | + if (isset($ldapRecord[$attribute])) { |
|
| 1707 | 1707 | $this->connection->$uuidAttr = $attribute; |
| 1708 | 1708 | return true; |
| 1709 | 1709 | } else { |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | 1714 | $value = $this->readAttribute($dn, $attribute); |
| 1715 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1715 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1716 | 1716 | \OCP\Util::writeLog( |
| 1717 | 1717 | 'user_ldap', |
| 1718 | 1718 | 'Setting '.$attribute.' as '.$uuidAttr, |
@@ -1739,7 +1739,7 @@ discard block |
||
| 1739 | 1739 | * @throws ServerNotAvailableException |
| 1740 | 1740 | */ |
| 1741 | 1741 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
| 1742 | - if($isUser) { |
|
| 1742 | + if ($isUser) { |
|
| 1743 | 1743 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1744 | 1744 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1745 | 1745 | } else { |
@@ -1748,10 +1748,10 @@ discard block |
||
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | $uuid = false; |
| 1751 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1751 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1752 | 1752 | $attr = $this->connection->$uuidAttr; |
| 1753 | 1753 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
| 1754 | - if( !is_array($uuid) |
|
| 1754 | + if (!is_array($uuid) |
|
| 1755 | 1755 | && $uuidOverride !== '' |
| 1756 | 1756 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
| 1757 | 1757 | { |
@@ -1759,7 +1759,7 @@ discard block |
||
| 1759 | 1759 | ? $ldapRecord[$this->connection->$uuidAttr] |
| 1760 | 1760 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
| 1761 | 1761 | } |
| 1762 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1762 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1763 | 1763 | $uuid = $uuid[0]; |
| 1764 | 1764 | } |
| 1765 | 1765 | } |
@@ -1776,19 +1776,19 @@ discard block |
||
| 1776 | 1776 | private function convertObjectGUID2Str($oguid) { |
| 1777 | 1777 | $hex_guid = bin2hex($oguid); |
| 1778 | 1778 | $hex_guid_to_guid_str = ''; |
| 1779 | - for($k = 1; $k <= 4; ++$k) { |
|
| 1779 | + for ($k = 1; $k <= 4; ++$k) { |
|
| 1780 | 1780 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
| 1781 | 1781 | } |
| 1782 | 1782 | $hex_guid_to_guid_str .= '-'; |
| 1783 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1783 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1784 | 1784 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
| 1785 | 1785 | } |
| 1786 | 1786 | $hex_guid_to_guid_str .= '-'; |
| 1787 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1787 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1788 | 1788 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
| 1789 | 1789 | } |
| 1790 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
| 1791 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
| 1790 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
| 1791 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
| 1792 | 1792 | |
| 1793 | 1793 | return strtoupper($hex_guid_to_guid_str); |
| 1794 | 1794 | } |
@@ -1805,11 +1805,11 @@ discard block |
||
| 1805 | 1805 | * @return string |
| 1806 | 1806 | */ |
| 1807 | 1807 | public function formatGuid2ForFilterUser($guid) { |
| 1808 | - if(!is_string($guid)) { |
|
| 1808 | + if (!is_string($guid)) { |
|
| 1809 | 1809 | throw new \InvalidArgumentException('String expected'); |
| 1810 | 1810 | } |
| 1811 | 1811 | $blocks = explode('-', $guid); |
| 1812 | - if(count($blocks) !== 5) { |
|
| 1812 | + if (count($blocks) !== 5) { |
|
| 1813 | 1813 | /* |
| 1814 | 1814 | * Why not throw an Exception instead? This method is a utility |
| 1815 | 1815 | * called only when trying to figure out whether a "missing" known |
@@ -1822,20 +1822,20 @@ discard block |
||
| 1822 | 1822 | * user. Instead we write a log message. |
| 1823 | 1823 | */ |
| 1824 | 1824 | \OC::$server->getLogger()->info( |
| 1825 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
| 1825 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
| 1826 | 1826 | '({uuid}) probably does not match UUID configuration.', |
| 1827 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
| 1827 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
| 1828 | 1828 | ); |
| 1829 | 1829 | return $guid; |
| 1830 | 1830 | } |
| 1831 | - for($i=0; $i < 3; $i++) { |
|
| 1831 | + for ($i = 0; $i < 3; $i++) { |
|
| 1832 | 1832 | $pairs = str_split($blocks[$i], 2); |
| 1833 | 1833 | $pairs = array_reverse($pairs); |
| 1834 | 1834 | $blocks[$i] = implode('', $pairs); |
| 1835 | 1835 | } |
| 1836 | - for($i=0; $i < 5; $i++) { |
|
| 1836 | + for ($i = 0; $i < 5; $i++) { |
|
| 1837 | 1837 | $pairs = str_split($blocks[$i], 2); |
| 1838 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
| 1838 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
| 1839 | 1839 | } |
| 1840 | 1840 | return implode('', $blocks); |
| 1841 | 1841 | } |
@@ -1851,12 +1851,12 @@ discard block |
||
| 1851 | 1851 | $domainDN = $this->getDomainDNFromDN($dn); |
| 1852 | 1852 | $cacheKey = 'getSID-'.$domainDN; |
| 1853 | 1853 | $sid = $this->connection->getFromCache($cacheKey); |
| 1854 | - if(!is_null($sid)) { |
|
| 1854 | + if (!is_null($sid)) { |
|
| 1855 | 1855 | return $sid; |
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | 1858 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
| 1859 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
| 1859 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
| 1860 | 1860 | $this->connection->writeToCache($cacheKey, false); |
| 1861 | 1861 | return false; |
| 1862 | 1862 | } |
@@ -1914,12 +1914,12 @@ discard block |
||
| 1914 | 1914 | $belongsToBase = false; |
| 1915 | 1915 | $bases = $this->helper->sanitizeDN($bases); |
| 1916 | 1916 | |
| 1917 | - foreach($bases as $base) { |
|
| 1917 | + foreach ($bases as $base) { |
|
| 1918 | 1918 | $belongsToBase = true; |
| 1919 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
| 1919 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
| 1920 | 1920 | $belongsToBase = false; |
| 1921 | 1921 | } |
| 1922 | - if($belongsToBase) { |
|
| 1922 | + if ($belongsToBase) { |
|
| 1923 | 1923 | break; |
| 1924 | 1924 | } |
| 1925 | 1925 | } |
@@ -1948,16 +1948,16 @@ discard block |
||
| 1948 | 1948 | * @return string containing the key or empty if none is cached |
| 1949 | 1949 | */ |
| 1950 | 1950 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
| 1951 | - if($offset === 0) { |
|
| 1951 | + if ($offset === 0) { |
|
| 1952 | 1952 | return ''; |
| 1953 | 1953 | } |
| 1954 | 1954 | $offset -= $limit; |
| 1955 | 1955 | //we work with cache here |
| 1956 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
| 1956 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
| 1957 | 1957 | $cookie = ''; |
| 1958 | - if(isset($this->cookies[$cacheKey])) { |
|
| 1958 | + if (isset($this->cookies[$cacheKey])) { |
|
| 1959 | 1959 | $cookie = $this->cookies[$cacheKey]; |
| 1960 | - if(is_null($cookie)) { |
|
| 1960 | + if (is_null($cookie)) { |
|
| 1961 | 1961 | $cookie = ''; |
| 1962 | 1962 | } |
| 1963 | 1963 | } |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | * @return bool |
| 1976 | 1976 | */ |
| 1977 | 1977 | public function hasMoreResults() { |
| 1978 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1978 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1979 | 1979 | // as in RFC 2696, when all results are returned, the cookie will |
| 1980 | 1980 | // be empty. |
| 1981 | 1981 | return false; |
@@ -1995,8 +1995,8 @@ discard block |
||
| 1995 | 1995 | */ |
| 1996 | 1996 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
| 1997 | 1997 | // allow '0' for 389ds |
| 1998 | - if(!empty($cookie) || $cookie === '0') { |
|
| 1999 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
| 1998 | + if (!empty($cookie) || $cookie === '0') { |
|
| 1999 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
| 2000 | 2000 | $this->cookies[$cacheKey] = $cookie; |
| 2001 | 2001 | $this->lastCookie = $cookie; |
| 2002 | 2002 | } |
@@ -2026,16 +2026,16 @@ discard block |
||
| 2026 | 2026 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
| 2027 | 2027 | $pagedSearchOK = false; |
| 2028 | 2028 | if ($limit !== 0) { |
| 2029 | - $offset = (int)$offset; //can be null |
|
| 2029 | + $offset = (int) $offset; //can be null |
|
| 2030 | 2030 | \OCP\Util::writeLog('user_ldap', |
| 2031 | 2031 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
| 2032 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
| 2032 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
| 2033 | 2033 | ILogger::DEBUG); |
| 2034 | 2034 | //get the cookie from the search for the previous search, required by LDAP |
| 2035 | - foreach($bases as $base) { |
|
| 2035 | + foreach ($bases as $base) { |
|
| 2036 | 2036 | |
| 2037 | 2037 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
| 2038 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 2038 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 2039 | 2039 | // no cookie known from a potential previous search. We need |
| 2040 | 2040 | // to start from 0 to come to the desired page. cookie value |
| 2041 | 2041 | // of '0' is valid, because 389ds |
@@ -2045,17 +2045,17 @@ discard block |
||
| 2045 | 2045 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
| 2046 | 2046 | // '0' is valid, because 389ds |
| 2047 | 2047 | //TODO: remember this, probably does not change in the next request... |
| 2048 | - if(empty($cookie) && $cookie !== '0') { |
|
| 2048 | + if (empty($cookie) && $cookie !== '0') { |
|
| 2049 | 2049 | $cookie = null; |
| 2050 | 2050 | } |
| 2051 | 2051 | } |
| 2052 | - if(!is_null($cookie)) { |
|
| 2052 | + if (!is_null($cookie)) { |
|
| 2053 | 2053 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
| 2054 | 2054 | $this->abandonPagedSearch(); |
| 2055 | 2055 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 2056 | 2056 | $this->connection->getConnectionResource(), $limit, |
| 2057 | 2057 | false, $cookie); |
| 2058 | - if(!$pagedSearchOK) { |
|
| 2058 | + if (!$pagedSearchOK) { |
|
| 2059 | 2059 | return false; |
| 2060 | 2060 | } |
| 2061 | 2061 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG); |
@@ -2078,7 +2078,7 @@ discard block |
||
| 2078 | 2078 | $this->abandonPagedSearch(); |
| 2079 | 2079 | // in case someone set it to 0 … use 500, otherwise no results will |
| 2080 | 2080 | // be returned. |
| 2081 | - $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500; |
|
| 2081 | + $pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500; |
|
| 2082 | 2082 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 2083 | 2083 | $this->connection->getConnectionResource(), |
| 2084 | 2084 | $pageSize, false, ''); |