@@ -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,18 +356,18 @@ 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; |
367 | 367 | } |
368 | 368 | try { |
369 | 369 | return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
370 | - } catch(ConstraintViolationException $e) { |
|
370 | + } catch (ConstraintViolationException $e) { |
|
371 | 371 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
372 | 372 | } |
373 | 373 | } |
@@ -409,17 +409,17 @@ discard block |
||
409 | 409 | */ |
410 | 410 | public function getDomainDNFromDN($dn) { |
411 | 411 | $allParts = $this->ldap->explodeDN($dn, 0); |
412 | - if($allParts === false) { |
|
412 | + if ($allParts === false) { |
|
413 | 413 | //not a valid DN |
414 | 414 | return ''; |
415 | 415 | } |
416 | 416 | $domainParts = array(); |
417 | 417 | $dcFound = false; |
418 | - foreach($allParts as $part) { |
|
419 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
418 | + foreach ($allParts as $part) { |
|
419 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
420 | 420 | $dcFound = true; |
421 | 421 | } |
422 | - if($dcFound) { |
|
422 | + if ($dcFound) { |
|
423 | 423 | $domainParts[] = $part; |
424 | 424 | } |
425 | 425 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | |
446 | 446 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
447 | 447 | //server setups |
448 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
448 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
449 | 449 | return $fdn; |
450 | 450 | } |
451 | 451 | |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | //To avoid bypassing the base DN settings under certain circumstances |
463 | 463 | //with the group support, check whether the provided DN matches one of |
464 | 464 | //the given Bases |
465 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
465 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
466 | 466 | return false; |
467 | 467 | } |
468 | 468 | |
@@ -480,11 +480,11 @@ discard block |
||
480 | 480 | */ |
481 | 481 | public function groupsMatchFilter($groupDNs) { |
482 | 482 | $validGroupDNs = []; |
483 | - foreach($groupDNs as $dn) { |
|
483 | + foreach ($groupDNs as $dn) { |
|
484 | 484 | $cacheKey = 'groupsMatchFilter-'.$dn; |
485 | 485 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
486 | - if(!is_null($groupMatchFilter)) { |
|
487 | - if($groupMatchFilter) { |
|
486 | + if (!is_null($groupMatchFilter)) { |
|
487 | + if ($groupMatchFilter) { |
|
488 | 488 | $validGroupDNs[] = $dn; |
489 | 489 | } |
490 | 490 | continue; |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | |
493 | 493 | // Check the base DN first. If this is not met already, we don't |
494 | 494 | // need to ask the server at all. |
495 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
495 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
496 | 496 | $this->connection->writeToCache($cacheKey, false); |
497 | 497 | continue; |
498 | 498 | } |
499 | 499 | |
500 | 500 | $result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter); |
501 | - if(is_array($result)) { |
|
501 | + if (is_array($result)) { |
|
502 | 502 | $this->connection->writeToCache($cacheKey, true); |
503 | 503 | $validGroupDNs[] = $dn; |
504 | 504 | } else { |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | //To avoid bypassing the base DN settings under certain circumstances |
520 | 520 | //with the group support, check whether the provided DN matches one of |
521 | 521 | //the given Bases |
522 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
522 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
523 | 523 | return false; |
524 | 524 | } |
525 | 525 | |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
541 | 541 | $newlyMapped = false; |
542 | - if($isUser) { |
|
542 | + if ($isUser) { |
|
543 | 543 | $mapper = $this->getUserMapper(); |
544 | 544 | $nameAttribute = $this->connection->ldapUserDisplayName; |
545 | 545 | $filter = $this->connection->ldapUserFilter; |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | |
552 | 552 | //let's try to retrieve the Nextcloud name from the mappings table |
553 | 553 | $ncName = $mapper->getNameByDN($fdn); |
554 | - if(is_string($ncName)) { |
|
554 | + if (is_string($ncName)) { |
|
555 | 555 | return $ncName; |
556 | 556 | } |
557 | 557 | |
558 | 558 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
559 | 559 | $uuid = $this->getUUID($fdn, $isUser, $record); |
560 | - if(is_string($uuid)) { |
|
560 | + if (is_string($uuid)) { |
|
561 | 561 | $ncName = $mapper->getNameByUUID($uuid); |
562 | - if(is_string($ncName)) { |
|
562 | + if (is_string($ncName)) { |
|
563 | 563 | $mapper->setDNbyUUID($fdn, $uuid); |
564 | 564 | return $ncName; |
565 | 565 | } |
@@ -569,17 +569,17 @@ discard block |
||
569 | 569 | return false; |
570 | 570 | } |
571 | 571 | |
572 | - if(is_null($ldapName)) { |
|
572 | + if (is_null($ldapName)) { |
|
573 | 573 | $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); |
574 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
574 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
575 | 575 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO); |
576 | 576 | return false; |
577 | 577 | } |
578 | 578 | $ldapName = $ldapName[0]; |
579 | 579 | } |
580 | 580 | |
581 | - if($isUser) { |
|
582 | - $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr; |
|
581 | + if ($isUser) { |
|
582 | + $usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr; |
|
583 | 583 | if ($usernameAttribute !== '') { |
584 | 584 | $username = $this->readAttribute($fdn, $usernameAttribute); |
585 | 585 | $username = $username[0]; |
@@ -609,14 +609,14 @@ discard block |
||
609 | 609 | // outside of core user management will still cache the user as non-existing. |
610 | 610 | $originalTTL = $this->connection->ldapCacheTTL; |
611 | 611 | $this->connection->setConfiguration(['ldapCacheTTL' => 0]); |
612 | - if( $intName !== '' |
|
612 | + if ($intName !== '' |
|
613 | 613 | && (($isUser && !$this->ncUserManager->userExists($intName)) |
614 | 614 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName)) |
615 | 615 | ) |
616 | 616 | ) { |
617 | 617 | $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); |
618 | 618 | $newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser); |
619 | - if($newlyMapped) { |
|
619 | + if ($newlyMapped) { |
|
620 | 620 | return $intName; |
621 | 621 | } |
622 | 622 | } |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); |
625 | 625 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
626 | 626 | if (is_string($altName)) { |
627 | - if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) { |
|
627 | + if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) { |
|
628 | 628 | $newlyMapped = true; |
629 | 629 | return $altName; |
630 | 630 | } |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | string $uuid, |
643 | 643 | bool $isUser |
644 | 644 | ) :bool { |
645 | - if($mapper->map($fdn, $name, $uuid)) { |
|
645 | + if ($mapper->map($fdn, $name, $uuid)) { |
|
646 | 646 | if ($this->ncUserManager instanceof PublicEmitter && $isUser) { |
647 | 647 | $this->cacheUserExists($name); |
648 | 648 | $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]); |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | * @throws \Exception |
682 | 682 | */ |
683 | 683 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
684 | - if($isUsers) { |
|
684 | + if ($isUsers) { |
|
685 | 685 | $nameAttribute = $this->connection->ldapUserDisplayName; |
686 | 686 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
687 | 687 | } else { |
@@ -689,9 +689,9 @@ discard block |
||
689 | 689 | } |
690 | 690 | $nextcloudNames = []; |
691 | 691 | |
692 | - foreach($ldapObjects as $ldapObject) { |
|
692 | + foreach ($ldapObjects as $ldapObject) { |
|
693 | 693 | $nameByLDAP = null; |
694 | - if( isset($ldapObject[$nameAttribute]) |
|
694 | + if (isset($ldapObject[$nameAttribute]) |
|
695 | 695 | && is_array($ldapObject[$nameAttribute]) |
696 | 696 | && isset($ldapObject[$nameAttribute][0]) |
697 | 697 | ) { |
@@ -700,19 +700,19 @@ discard block |
||
700 | 700 | } |
701 | 701 | |
702 | 702 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
703 | - if($ncName) { |
|
703 | + if ($ncName) { |
|
704 | 704 | $nextcloudNames[] = $ncName; |
705 | - if($isUsers) { |
|
705 | + if ($isUsers) { |
|
706 | 706 | $this->updateUserState($ncName); |
707 | 707 | //cache the user names so it does not need to be retrieved |
708 | 708 | //again later (e.g. sharing dialogue). |
709 | - if(is_null($nameByLDAP)) { |
|
709 | + if (is_null($nameByLDAP)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | $sndName = isset($ldapObject[$sndAttribute][0]) |
713 | 713 | ? $ldapObject[$sndAttribute][0] : ''; |
714 | 714 | $this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName); |
715 | - } else if($nameByLDAP !== null) { |
|
715 | + } else if ($nameByLDAP !== null) { |
|
716 | 716 | $this->cacheGroupDisplayName($ncName, $nameByLDAP); |
717 | 717 | } |
718 | 718 | } |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | */ |
729 | 729 | public function updateUserState($ncname) { |
730 | 730 | $user = $this->userManager->get($ncname); |
731 | - if($user instanceof OfflineUser) { |
|
731 | + if ($user instanceof OfflineUser) { |
|
732 | 732 | $user->unmark(); |
733 | 733 | } |
734 | 734 | } |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | */ |
760 | 760 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
761 | 761 | $user = $this->userManager->get($ocName); |
762 | - if($user === null) { |
|
762 | + if ($user === null) { |
|
763 | 763 | return; |
764 | 764 | } |
765 | 765 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | } |
769 | 769 | |
770 | 770 | public function cacheGroupDisplayName(string $ncName, string $displayName): void { |
771 | - $cacheKey = 'group_getDisplayName' . $ncName; |
|
771 | + $cacheKey = 'group_getDisplayName'.$ncName; |
|
772 | 772 | $this->connection->writeToCache($cacheKey, $displayName); |
773 | 773 | } |
774 | 774 | |
@@ -784,9 +784,9 @@ discard block |
||
784 | 784 | $attempts = 0; |
785 | 785 | //while loop is just a precaution. If a name is not generated within |
786 | 786 | //20 attempts, something else is very wrong. Avoids infinite loop. |
787 | - while($attempts < 20){ |
|
788 | - $altName = $name . '_' . rand(1000,9999); |
|
789 | - if(!$this->ncUserManager->userExists($altName)) { |
|
787 | + while ($attempts < 20) { |
|
788 | + $altName = $name.'_'.rand(1000, 9999); |
|
789 | + if (!$this->ncUserManager->userExists($altName)) { |
|
790 | 790 | return $altName; |
791 | 791 | } |
792 | 792 | $attempts++; |
@@ -808,25 +808,25 @@ discard block |
||
808 | 808 | */ |
809 | 809 | private function _createAltInternalOwnCloudNameForGroups($name) { |
810 | 810 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
811 | - if(!$usedNames || count($usedNames) === 0) { |
|
811 | + if (!$usedNames || count($usedNames) === 0) { |
|
812 | 812 | $lastNo = 1; //will become name_2 |
813 | 813 | } else { |
814 | 814 | natsort($usedNames); |
815 | 815 | $lastName = array_pop($usedNames); |
816 | - $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1); |
|
816 | + $lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1); |
|
817 | 817 | } |
818 | - $altName = $name.'_'. (string)($lastNo+1); |
|
818 | + $altName = $name.'_'.(string) ($lastNo + 1); |
|
819 | 819 | unset($usedNames); |
820 | 820 | |
821 | 821 | $attempts = 1; |
822 | - while($attempts < 21){ |
|
822 | + while ($attempts < 21) { |
|
823 | 823 | // Check to be really sure it is unique |
824 | 824 | // while loop is just a precaution. If a name is not generated within |
825 | 825 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
826 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
826 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
827 | 827 | return $altName; |
828 | 828 | } |
829 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
829 | + $altName = $name.'_'.($lastNo + $attempts); |
|
830 | 830 | $attempts++; |
831 | 831 | } |
832 | 832 | return false; |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | private function createAltInternalOwnCloudName($name, $isUser) { |
842 | 842 | $originalTTL = $this->connection->ldapCacheTTL; |
843 | 843 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
844 | - if($isUser) { |
|
844 | + if ($isUser) { |
|
845 | 845 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
846 | 846 | } else { |
847 | 847 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -889,13 +889,13 @@ discard block |
||
889 | 889 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
890 | 890 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
891 | 891 | $recordsToUpdate = $ldapRecords; |
892 | - if(!$forceApplyAttributes) { |
|
892 | + if (!$forceApplyAttributes) { |
|
893 | 893 | $isBackgroundJobModeAjax = $this->config |
894 | 894 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
895 | 895 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
896 | 896 | $newlyMapped = false; |
897 | 897 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
898 | - if(is_string($uid)) { |
|
898 | + if (is_string($uid)) { |
|
899 | 899 | $this->cacheUserExists($uid); |
900 | 900 | } |
901 | 901 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -913,15 +913,15 @@ discard block |
||
913 | 913 | * @param array $ldapRecords |
914 | 914 | * @throws \Exception |
915 | 915 | */ |
916 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
916 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
917 | 917 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
918 | - foreach($ldapRecords as $userRecord) { |
|
919 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
918 | + foreach ($ldapRecords as $userRecord) { |
|
919 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
920 | 920 | // displayName is obligatory |
921 | 921 | continue; |
922 | 922 | } |
923 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
924 | - if($ocName === false) { |
|
923 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
924 | + if ($ocName === false) { |
|
925 | 925 | continue; |
926 | 926 | } |
927 | 927 | $this->updateUserState($ocName); |
@@ -954,8 +954,8 @@ discard block |
||
954 | 954 | * @return array |
955 | 955 | */ |
956 | 956 | private function fetchList($list, $manyAttributes) { |
957 | - if(is_array($list)) { |
|
958 | - if($manyAttributes) { |
|
957 | + if (is_array($list)) { |
|
958 | + if ($manyAttributes) { |
|
959 | 959 | return $list; |
960 | 960 | } else { |
961 | 961 | $list = array_reduce($list, function($carry, $item) { |
@@ -983,7 +983,7 @@ discard block |
||
983 | 983 | */ |
984 | 984 | public function searchUsers($filter, $attr = null, $limit = null, $offset = null) { |
985 | 985 | $result = []; |
986 | - foreach($this->connection->ldapBaseUsers as $base) { |
|
986 | + foreach ($this->connection->ldapBaseUsers as $base) { |
|
987 | 987 | $result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset)); |
988 | 988 | } |
989 | 989 | return $result; |
@@ -998,9 +998,9 @@ discard block |
||
998 | 998 | */ |
999 | 999 | public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { |
1000 | 1000 | $result = false; |
1001 | - foreach($this->connection->ldapBaseUsers as $base) { |
|
1001 | + foreach ($this->connection->ldapBaseUsers as $base) { |
|
1002 | 1002 | $count = $this->count($filter, [$base], $attr, $limit, $offset); |
1003 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
1003 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
1004 | 1004 | } |
1005 | 1005 | return $result; |
1006 | 1006 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | */ |
1018 | 1018 | public function searchGroups($filter, $attr = null, $limit = null, $offset = null) { |
1019 | 1019 | $result = []; |
1020 | - foreach($this->connection->ldapBaseGroups as $base) { |
|
1020 | + foreach ($this->connection->ldapBaseGroups as $base) { |
|
1021 | 1021 | $result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset)); |
1022 | 1022 | } |
1023 | 1023 | return $result; |
@@ -1033,9 +1033,9 @@ discard block |
||
1033 | 1033 | */ |
1034 | 1034 | public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) { |
1035 | 1035 | $result = false; |
1036 | - foreach($this->connection->ldapBaseGroups as $base) { |
|
1036 | + foreach ($this->connection->ldapBaseGroups as $base) { |
|
1037 | 1037 | $count = $this->count($filter, [$base], $attr, $limit, $offset); |
1038 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
1038 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
1039 | 1039 | } |
1040 | 1040 | return $result; |
1041 | 1041 | } |
@@ -1049,9 +1049,9 @@ discard block |
||
1049 | 1049 | */ |
1050 | 1050 | public function countObjects($limit = null, $offset = null) { |
1051 | 1051 | $result = false; |
1052 | - foreach($this->connection->ldapBase as $base) { |
|
1052 | + foreach ($this->connection->ldapBase as $base) { |
|
1053 | 1053 | $count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset); |
1054 | - $result = is_int($count) ? (int)$result + $count : $result; |
|
1054 | + $result = is_int($count) ? (int) $result + $count : $result; |
|
1055 | 1055 | } |
1056 | 1056 | return $result; |
1057 | 1057 | } |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | // php no longer supports call-time pass-by-reference |
1077 | 1077 | // thus cannot support controlPagedResultResponse as the third argument |
1078 | 1078 | // is a reference |
1079 | - $doMethod = function () use ($command, &$arguments) { |
|
1079 | + $doMethod = function() use ($command, &$arguments) { |
|
1080 | 1080 | if ($command == 'controlPagedResultResponse') { |
1081 | 1081 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
1082 | 1082 | } else { |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | $this->connection->resetConnectionResource(); |
1095 | 1095 | $cr = $this->connection->getConnectionResource(); |
1096 | 1096 | |
1097 | - if(!$this->ldap->isResource($cr)) { |
|
1097 | + if (!$this->ldap->isResource($cr)) { |
|
1098 | 1098 | // Seems like we didn't find any resource. |
1099 | 1099 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG); |
1100 | 1100 | throw $e; |
@@ -1119,13 +1119,13 @@ discard block |
||
1119 | 1119 | * @throws ServerNotAvailableException |
1120 | 1120 | */ |
1121 | 1121 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
1122 | - if(!is_null($attr) && !is_array($attr)) { |
|
1122 | + if (!is_null($attr) && !is_array($attr)) { |
|
1123 | 1123 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | // See if we have a resource, in case not cancel with message |
1127 | 1127 | $cr = $this->connection->getConnectionResource(); |
1128 | - if(!$this->ldap->isResource($cr)) { |
|
1128 | + if (!$this->ldap->isResource($cr)) { |
|
1129 | 1129 | // Seems like we didn't find any resource. |
1130 | 1130 | // Return an empty array just like before. |
1131 | 1131 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG); |
@@ -1133,13 +1133,13 @@ discard block |
||
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | //check whether paged search should be attempted |
1136 | - $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset); |
|
1136 | + $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset); |
|
1137 | 1137 | |
1138 | 1138 | $linkResources = array_pad(array(), count($base), $cr); |
1139 | 1139 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
1140 | 1140 | // cannot use $cr anymore, might have changed in the previous call! |
1141 | 1141 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
1142 | - if(!is_array($sr) || $error !== 0) { |
|
1142 | + if (!is_array($sr) || $error !== 0) { |
|
1143 | 1143 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR); |
1144 | 1144 | return false; |
1145 | 1145 | } |
@@ -1162,29 +1162,29 @@ discard block |
||
1162 | 1162 | */ |
1163 | 1163 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
1164 | 1164 | $cookie = null; |
1165 | - if($pagedSearchOK) { |
|
1165 | + if ($pagedSearchOK) { |
|
1166 | 1166 | $cr = $this->connection->getConnectionResource(); |
1167 | - foreach($sr as $key => $res) { |
|
1168 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
1167 | + foreach ($sr as $key => $res) { |
|
1168 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
1169 | 1169 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | //browsing through prior pages to get the cookie for the new one |
1174 | - if($skipHandling) { |
|
1174 | + if ($skipHandling) { |
|
1175 | 1175 | return false; |
1176 | 1176 | } |
1177 | 1177 | // if count is bigger, then the server does not support |
1178 | 1178 | // paged search. Instead, he did a normal search. We set a |
1179 | 1179 | // flag here, so the callee knows how to deal with it. |
1180 | - if($iFoundItems <= $limit) { |
|
1180 | + if ($iFoundItems <= $limit) { |
|
1181 | 1181 | $this->pagedSearchedSuccessful = true; |
1182 | 1182 | } |
1183 | 1183 | } else { |
1184 | - if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) { |
|
1184 | + if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) { |
|
1185 | 1185 | \OC::$server->getLogger()->debug( |
1186 | 1186 | 'Paged search was not available', |
1187 | - [ 'app' => 'user_ldap' ] |
|
1187 | + ['app' => 'user_ldap'] |
|
1188 | 1188 | ); |
1189 | 1189 | } |
1190 | 1190 | } |
@@ -1213,8 +1213,8 @@ discard block |
||
1213 | 1213 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1214 | 1214 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), ILogger::DEBUG); |
1215 | 1215 | |
1216 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
1217 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1216 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
1217 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1218 | 1218 | $limitPerPage = $limit; |
1219 | 1219 | } |
1220 | 1220 | |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | |
1225 | 1225 | do { |
1226 | 1226 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
1227 | - if($search === false) { |
|
1227 | + if ($search === false) { |
|
1228 | 1228 | return $counter > 0 ? $counter : false; |
1229 | 1229 | } |
1230 | 1230 | list($sr, $pagedSearchOK) = $search; |
@@ -1243,7 +1243,7 @@ discard block |
||
1243 | 1243 | * Continue now depends on $hasMorePages value |
1244 | 1244 | */ |
1245 | 1245 | $continue = $pagedSearchOK && $hasMorePages; |
1246 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1246 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1247 | 1247 | |
1248 | 1248 | return $counter; |
1249 | 1249 | } |
@@ -1255,8 +1255,8 @@ discard block |
||
1255 | 1255 | private function countEntriesInSearchResults($searchResults) { |
1256 | 1256 | $counter = 0; |
1257 | 1257 | |
1258 | - foreach($searchResults as $res) { |
|
1259 | - $count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
1258 | + foreach ($searchResults as $res) { |
|
1259 | + $count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
1260 | 1260 | $counter += $count; |
1261 | 1261 | } |
1262 | 1262 | |
@@ -1276,8 +1276,8 @@ discard block |
||
1276 | 1276 | * @throws ServerNotAvailableException |
1277 | 1277 | */ |
1278 | 1278 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1279 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
1280 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1279 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
1280 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1281 | 1281 | $limitPerPage = $limit; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1291,13 +1291,13 @@ discard block |
||
1291 | 1291 | $savedoffset = $offset; |
1292 | 1292 | do { |
1293 | 1293 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
1294 | - if($search === false) { |
|
1294 | + if ($search === false) { |
|
1295 | 1295 | return []; |
1296 | 1296 | } |
1297 | 1297 | list($sr, $pagedSearchOK) = $search; |
1298 | 1298 | $cr = $this->connection->getConnectionResource(); |
1299 | 1299 | |
1300 | - if($skipHandling) { |
|
1300 | + if ($skipHandling) { |
|
1301 | 1301 | //i.e. result do not need to be fetched, we just need the cookie |
1302 | 1302 | //thus pass 1 or any other value as $iFoundItems because it is not |
1303 | 1303 | //used |
@@ -1308,7 +1308,7 @@ discard block |
||
1308 | 1308 | } |
1309 | 1309 | |
1310 | 1310 | $iFoundItems = 0; |
1311 | - foreach($sr as $res) { |
|
1311 | + foreach ($sr as $res) { |
|
1312 | 1312 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
1313 | 1313 | $iFoundItems = max($iFoundItems, $findings['count']); |
1314 | 1314 | unset($findings['count']); |
@@ -1324,27 +1324,27 @@ discard block |
||
1324 | 1324 | |
1325 | 1325 | // if we're here, probably no connection resource is returned. |
1326 | 1326 | // to make Nextcloud behave nicely, we simply give back an empty array. |
1327 | - if(is_null($findings)) { |
|
1327 | + if (is_null($findings)) { |
|
1328 | 1328 | return array(); |
1329 | 1329 | } |
1330 | 1330 | |
1331 | - if(!is_null($attr)) { |
|
1331 | + if (!is_null($attr)) { |
|
1332 | 1332 | $selection = []; |
1333 | 1333 | $i = 0; |
1334 | - foreach($findings as $item) { |
|
1335 | - if(!is_array($item)) { |
|
1334 | + foreach ($findings as $item) { |
|
1335 | + if (!is_array($item)) { |
|
1336 | 1336 | continue; |
1337 | 1337 | } |
1338 | 1338 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
1339 | - foreach($attr as $key) { |
|
1340 | - if(isset($item[$key])) { |
|
1341 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1339 | + foreach ($attr as $key) { |
|
1340 | + if (isset($item[$key])) { |
|
1341 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1342 | 1342 | unset($item[$key]['count']); |
1343 | 1343 | } |
1344 | - if($key !== 'dn') { |
|
1345 | - if($this->resemblesDN($key)) { |
|
1344 | + if ($key !== 'dn') { |
|
1345 | + if ($this->resemblesDN($key)) { |
|
1346 | 1346 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
1347 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
1347 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
1348 | 1348 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
1349 | 1349 | } else { |
1350 | 1350 | $selection[$i][$key] = $item[$key]; |
@@ -1362,14 +1362,14 @@ discard block |
||
1362 | 1362 | //we slice the findings, when |
1363 | 1363 | //a) paged search unsuccessful, though attempted |
1364 | 1364 | //b) no paged search, but limit set |
1365 | - if((!$this->getPagedSearchResultState() |
|
1365 | + if ((!$this->getPagedSearchResultState() |
|
1366 | 1366 | && $pagedSearchOK) |
1367 | 1367 | || ( |
1368 | 1368 | !$pagedSearchOK |
1369 | 1369 | && !is_null($limit) |
1370 | 1370 | ) |
1371 | 1371 | ) { |
1372 | - $findings = array_slice($findings, (int)$offset, $limit); |
|
1372 | + $findings = array_slice($findings, (int) $offset, $limit); |
|
1373 | 1373 | } |
1374 | 1374 | return $findings; |
1375 | 1375 | } |
@@ -1382,13 +1382,13 @@ discard block |
||
1382 | 1382 | public function sanitizeUsername($name) { |
1383 | 1383 | $name = trim($name); |
1384 | 1384 | |
1385 | - if($this->connection->ldapIgnoreNamingRules) { |
|
1385 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
1386 | 1386 | return $name; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | // Transliteration to ASCII |
1390 | 1390 | $transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name); |
1391 | - if($transliterated !== false) { |
|
1391 | + if ($transliterated !== false) { |
|
1392 | 1392 | // depending on system config iconv can work or not |
1393 | 1393 | $name = $transliterated; |
1394 | 1394 | } |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | // Every remaining disallowed characters will be removed |
1400 | 1400 | $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name); |
1401 | 1401 | |
1402 | - if($name === '') { |
|
1402 | + if ($name === '') { |
|
1403 | 1403 | throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters'); |
1404 | 1404 | } |
1405 | 1405 | |
@@ -1414,13 +1414,13 @@ discard block |
||
1414 | 1414 | */ |
1415 | 1415 | public function escapeFilterPart($input, $allowAsterisk = false) { |
1416 | 1416 | $asterisk = ''; |
1417 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1417 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1418 | 1418 | $asterisk = '*'; |
1419 | 1419 | $input = mb_substr($input, 1, null, 'UTF-8'); |
1420 | 1420 | } |
1421 | 1421 | $search = array('*', '\\', '(', ')'); |
1422 | 1422 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
1423 | - return $asterisk . str_replace($search, $replace, $input); |
|
1423 | + return $asterisk.str_replace($search, $replace, $input); |
|
1424 | 1424 | } |
1425 | 1425 | |
1426 | 1426 | /** |
@@ -1450,13 +1450,13 @@ discard block |
||
1450 | 1450 | */ |
1451 | 1451 | private function combineFilter($filters, $operator) { |
1452 | 1452 | $combinedFilter = '('.$operator; |
1453 | - foreach($filters as $filter) { |
|
1453 | + foreach ($filters as $filter) { |
|
1454 | 1454 | if ($filter !== '' && $filter[0] !== '(') { |
1455 | 1455 | $filter = '('.$filter.')'; |
1456 | 1456 | } |
1457 | - $combinedFilter.=$filter; |
|
1457 | + $combinedFilter .= $filter; |
|
1458 | 1458 | } |
1459 | - $combinedFilter.=')'; |
|
1459 | + $combinedFilter .= ')'; |
|
1460 | 1460 | return $combinedFilter; |
1461 | 1461 | } |
1462 | 1462 | |
@@ -1492,17 +1492,17 @@ discard block |
||
1492 | 1492 | * @throws \Exception |
1493 | 1493 | */ |
1494 | 1494 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
1495 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1495 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1496 | 1496 | throw new \Exception('searchAttributes must be an array with at least two string'); |
1497 | 1497 | } |
1498 | 1498 | $searchWords = explode(' ', trim($search)); |
1499 | 1499 | $wordFilters = array(); |
1500 | - foreach($searchWords as $word) { |
|
1500 | + foreach ($searchWords as $word) { |
|
1501 | 1501 | $word = $this->prepareSearchTerm($word); |
1502 | 1502 | //every word needs to appear at least once |
1503 | 1503 | $wordMatchOneAttrFilters = array(); |
1504 | - foreach($searchAttributes as $attr) { |
|
1505 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
1504 | + foreach ($searchAttributes as $attr) { |
|
1505 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
1506 | 1506 | } |
1507 | 1507 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
1508 | 1508 | } |
@@ -1520,10 +1520,10 @@ discard block |
||
1520 | 1520 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
1521 | 1521 | $filter = array(); |
1522 | 1522 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
1523 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1523 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1524 | 1524 | try { |
1525 | 1525 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
1526 | - } catch(\Exception $e) { |
|
1526 | + } catch (\Exception $e) { |
|
1527 | 1527 | \OCP\Util::writeLog( |
1528 | 1528 | 'user_ldap', |
1529 | 1529 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1533,17 +1533,17 @@ discard block |
||
1533 | 1533 | } |
1534 | 1534 | |
1535 | 1535 | $search = $this->prepareSearchTerm($search); |
1536 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1536 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1537 | 1537 | if ($fallbackAttribute === '') { |
1538 | 1538 | return ''; |
1539 | 1539 | } |
1540 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
1540 | + $filter[] = $fallbackAttribute.'='.$search; |
|
1541 | 1541 | } else { |
1542 | - foreach($searchAttributes as $attribute) { |
|
1543 | - $filter[] = $attribute . '=' . $search; |
|
1542 | + foreach ($searchAttributes as $attribute) { |
|
1543 | + $filter[] = $attribute.'='.$search; |
|
1544 | 1544 | } |
1545 | 1545 | } |
1546 | - if(count($filter) === 1) { |
|
1546 | + if (count($filter) === 1) { |
|
1547 | 1547 | return '('.$filter[0].')'; |
1548 | 1548 | } |
1549 | 1549 | return $this->combineFilterWithOr($filter); |
@@ -1564,7 +1564,7 @@ discard block |
||
1564 | 1564 | if ($term === '') { |
1565 | 1565 | $result = '*'; |
1566 | 1566 | } else if ($allowEnum !== 'no') { |
1567 | - $result = $term . '*'; |
|
1567 | + $result = $term.'*'; |
|
1568 | 1568 | } |
1569 | 1569 | return $result; |
1570 | 1570 | } |
@@ -1576,7 +1576,7 @@ discard block |
||
1576 | 1576 | public function getFilterForUserCount() { |
1577 | 1577 | $filter = $this->combineFilterWithAnd(array( |
1578 | 1578 | $this->connection->ldapUserFilter, |
1579 | - $this->connection->ldapUserDisplayName . '=*' |
|
1579 | + $this->connection->ldapUserDisplayName.'=*' |
|
1580 | 1580 | )); |
1581 | 1581 | |
1582 | 1582 | return $filter; |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | 'ldapAgentName' => $name, |
1595 | 1595 | 'ldapAgentPassword' => $password |
1596 | 1596 | ); |
1597 | - if(!$testConnection->setConfiguration($credentials)) { |
|
1597 | + if (!$testConnection->setConfiguration($credentials)) { |
|
1598 | 1598 | return false; |
1599 | 1599 | } |
1600 | 1600 | return $testConnection->bind(); |
@@ -1616,30 +1616,30 @@ discard block |
||
1616 | 1616 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
1617 | 1617 | // existing DN to be able to reliably detect it. |
1618 | 1618 | $result = $this->search($filter, $base, ['dn'], 1); |
1619 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1619 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1620 | 1620 | throw new \Exception('Cannot determine UUID attribute'); |
1621 | 1621 | } |
1622 | 1622 | $dn = $result[0]['dn'][0]; |
1623 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
1623 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
1624 | 1624 | throw new \Exception('Cannot determine UUID attribute'); |
1625 | 1625 | } |
1626 | 1626 | } else { |
1627 | 1627 | // The UUID attribute is either known or an override is given. |
1628 | 1628 | // By calling this method we ensure that $this->connection->$uuidAttr |
1629 | 1629 | // is definitely set |
1630 | - if(!$this->detectUuidAttribute('', true)) { |
|
1630 | + if (!$this->detectUuidAttribute('', true)) { |
|
1631 | 1631 | throw new \Exception('Cannot determine UUID attribute'); |
1632 | 1632 | } |
1633 | 1633 | } |
1634 | 1634 | |
1635 | 1635 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
1636 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1636 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1637 | 1637 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
1638 | 1638 | } |
1639 | 1639 | |
1640 | - $filter = $uuidAttr . '=' . $uuid; |
|
1640 | + $filter = $uuidAttr.'='.$uuid; |
|
1641 | 1641 | $result = $this->searchUsers($filter, ['dn'], 2); |
1642 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1642 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1643 | 1643 | // we put the count into account to make sure that this is |
1644 | 1644 | // really unique |
1645 | 1645 | return $result[0]['dn'][0]; |
@@ -1658,7 +1658,7 @@ discard block |
||
1658 | 1658 | * @return bool true on success, false otherwise |
1659 | 1659 | */ |
1660 | 1660 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
1661 | - if($isUser) { |
|
1661 | + if ($isUser) { |
|
1662 | 1662 | $uuidAttr = 'ldapUuidUserAttribute'; |
1663 | 1663 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1664 | 1664 | } else { |
@@ -1666,7 +1666,7 @@ discard block |
||
1666 | 1666 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
1667 | 1667 | } |
1668 | 1668 | |
1669 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1669 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1670 | 1670 | return true; |
1671 | 1671 | } |
1672 | 1672 | |
@@ -1675,10 +1675,10 @@ discard block |
||
1675 | 1675 | return true; |
1676 | 1676 | } |
1677 | 1677 | |
1678 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
1679 | - if($ldapRecord !== null) { |
|
1678 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
1679 | + if ($ldapRecord !== null) { |
|
1680 | 1680 | // we have the info from LDAP already, we don't need to talk to the server again |
1681 | - if(isset($ldapRecord[$attribute])) { |
|
1681 | + if (isset($ldapRecord[$attribute])) { |
|
1682 | 1682 | $this->connection->$uuidAttr = $attribute; |
1683 | 1683 | return true; |
1684 | 1684 | } else { |
@@ -1687,7 +1687,7 @@ discard block |
||
1687 | 1687 | } |
1688 | 1688 | |
1689 | 1689 | $value = $this->readAttribute($dn, $attribute); |
1690 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1690 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1691 | 1691 | \OCP\Util::writeLog( |
1692 | 1692 | 'user_ldap', |
1693 | 1693 | 'Setting '.$attribute.' as '.$uuidAttr, |
@@ -1713,7 +1713,7 @@ discard block |
||
1713 | 1713 | * @return bool|string |
1714 | 1714 | */ |
1715 | 1715 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
1716 | - if($isUser) { |
|
1716 | + if ($isUser) { |
|
1717 | 1717 | $uuidAttr = 'ldapUuidUserAttribute'; |
1718 | 1718 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1719 | 1719 | } else { |
@@ -1722,10 +1722,10 @@ discard block |
||
1722 | 1722 | } |
1723 | 1723 | |
1724 | 1724 | $uuid = false; |
1725 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
1725 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
1726 | 1726 | $attr = $this->connection->$uuidAttr; |
1727 | 1727 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
1728 | - if( !is_array($uuid) |
|
1728 | + if (!is_array($uuid) |
|
1729 | 1729 | && $uuidOverride !== '' |
1730 | 1730 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
1731 | 1731 | { |
@@ -1733,7 +1733,7 @@ discard block |
||
1733 | 1733 | ? $ldapRecord[$this->connection->$uuidAttr] |
1734 | 1734 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
1735 | 1735 | } |
1736 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1736 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1737 | 1737 | $uuid = $uuid[0]; |
1738 | 1738 | } |
1739 | 1739 | } |
@@ -1750,19 +1750,19 @@ discard block |
||
1750 | 1750 | private function convertObjectGUID2Str($oguid) { |
1751 | 1751 | $hex_guid = bin2hex($oguid); |
1752 | 1752 | $hex_guid_to_guid_str = ''; |
1753 | - for($k = 1; $k <= 4; ++$k) { |
|
1753 | + for ($k = 1; $k <= 4; ++$k) { |
|
1754 | 1754 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
1755 | 1755 | } |
1756 | 1756 | $hex_guid_to_guid_str .= '-'; |
1757 | - for($k = 1; $k <= 2; ++$k) { |
|
1757 | + for ($k = 1; $k <= 2; ++$k) { |
|
1758 | 1758 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
1759 | 1759 | } |
1760 | 1760 | $hex_guid_to_guid_str .= '-'; |
1761 | - for($k = 1; $k <= 2; ++$k) { |
|
1761 | + for ($k = 1; $k <= 2; ++$k) { |
|
1762 | 1762 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
1763 | 1763 | } |
1764 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
1765 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
1764 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
1765 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
1766 | 1766 | |
1767 | 1767 | return strtoupper($hex_guid_to_guid_str); |
1768 | 1768 | } |
@@ -1779,11 +1779,11 @@ discard block |
||
1779 | 1779 | * @return string |
1780 | 1780 | */ |
1781 | 1781 | public function formatGuid2ForFilterUser($guid) { |
1782 | - if(!is_string($guid)) { |
|
1782 | + if (!is_string($guid)) { |
|
1783 | 1783 | throw new \InvalidArgumentException('String expected'); |
1784 | 1784 | } |
1785 | 1785 | $blocks = explode('-', $guid); |
1786 | - if(count($blocks) !== 5) { |
|
1786 | + if (count($blocks) !== 5) { |
|
1787 | 1787 | /* |
1788 | 1788 | * Why not throw an Exception instead? This method is a utility |
1789 | 1789 | * called only when trying to figure out whether a "missing" known |
@@ -1796,20 +1796,20 @@ discard block |
||
1796 | 1796 | * user. Instead we write a log message. |
1797 | 1797 | */ |
1798 | 1798 | \OC::$server->getLogger()->info( |
1799 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
1799 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
1800 | 1800 | '({uuid}) probably does not match UUID configuration.', |
1801 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
1801 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
1802 | 1802 | ); |
1803 | 1803 | return $guid; |
1804 | 1804 | } |
1805 | - for($i=0; $i < 3; $i++) { |
|
1805 | + for ($i = 0; $i < 3; $i++) { |
|
1806 | 1806 | $pairs = str_split($blocks[$i], 2); |
1807 | 1807 | $pairs = array_reverse($pairs); |
1808 | 1808 | $blocks[$i] = implode('', $pairs); |
1809 | 1809 | } |
1810 | - for($i=0; $i < 5; $i++) { |
|
1810 | + for ($i = 0; $i < 5; $i++) { |
|
1811 | 1811 | $pairs = str_split($blocks[$i], 2); |
1812 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
1812 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
1813 | 1813 | } |
1814 | 1814 | return implode('', $blocks); |
1815 | 1815 | } |
@@ -1823,12 +1823,12 @@ discard block |
||
1823 | 1823 | $domainDN = $this->getDomainDNFromDN($dn); |
1824 | 1824 | $cacheKey = 'getSID-'.$domainDN; |
1825 | 1825 | $sid = $this->connection->getFromCache($cacheKey); |
1826 | - if(!is_null($sid)) { |
|
1826 | + if (!is_null($sid)) { |
|
1827 | 1827 | return $sid; |
1828 | 1828 | } |
1829 | 1829 | |
1830 | 1830 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
1831 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
1831 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
1832 | 1832 | $this->connection->writeToCache($cacheKey, false); |
1833 | 1833 | return false; |
1834 | 1834 | } |
@@ -1886,12 +1886,12 @@ discard block |
||
1886 | 1886 | $belongsToBase = false; |
1887 | 1887 | $bases = $this->helper->sanitizeDN($bases); |
1888 | 1888 | |
1889 | - foreach($bases as $base) { |
|
1889 | + foreach ($bases as $base) { |
|
1890 | 1890 | $belongsToBase = true; |
1891 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
1891 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
1892 | 1892 | $belongsToBase = false; |
1893 | 1893 | } |
1894 | - if($belongsToBase) { |
|
1894 | + if ($belongsToBase) { |
|
1895 | 1895 | break; |
1896 | 1896 | } |
1897 | 1897 | } |
@@ -1920,16 +1920,16 @@ discard block |
||
1920 | 1920 | * @return string containing the key or empty if none is cached |
1921 | 1921 | */ |
1922 | 1922 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
1923 | - if($offset === 0) { |
|
1923 | + if ($offset === 0) { |
|
1924 | 1924 | return ''; |
1925 | 1925 | } |
1926 | 1926 | $offset -= $limit; |
1927 | 1927 | //we work with cache here |
1928 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
1928 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
1929 | 1929 | $cookie = ''; |
1930 | - if(isset($this->cookies[$cacheKey])) { |
|
1930 | + if (isset($this->cookies[$cacheKey])) { |
|
1931 | 1931 | $cookie = $this->cookies[$cacheKey]; |
1932 | - if(is_null($cookie)) { |
|
1932 | + if (is_null($cookie)) { |
|
1933 | 1933 | $cookie = ''; |
1934 | 1934 | } |
1935 | 1935 | } |
@@ -1947,7 +1947,7 @@ discard block |
||
1947 | 1947 | * @return bool |
1948 | 1948 | */ |
1949 | 1949 | public function hasMoreResults() { |
1950 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1950 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1951 | 1951 | // as in RFC 2696, when all results are returned, the cookie will |
1952 | 1952 | // be empty. |
1953 | 1953 | return false; |
@@ -1967,8 +1967,8 @@ discard block |
||
1967 | 1967 | */ |
1968 | 1968 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
1969 | 1969 | // allow '0' for 389ds |
1970 | - if(!empty($cookie) || $cookie === '0') { |
|
1971 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
1970 | + if (!empty($cookie) || $cookie === '0') { |
|
1971 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
1972 | 1972 | $this->cookies[$cacheKey] = $cookie; |
1973 | 1973 | $this->lastCookie = $cookie; |
1974 | 1974 | } |
@@ -1996,16 +1996,16 @@ discard block |
||
1996 | 1996 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
1997 | 1997 | $pagedSearchOK = false; |
1998 | 1998 | if ($limit !== 0) { |
1999 | - $offset = (int)$offset; //can be null |
|
1999 | + $offset = (int) $offset; //can be null |
|
2000 | 2000 | \OCP\Util::writeLog('user_ldap', |
2001 | 2001 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
2002 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
2002 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
2003 | 2003 | ILogger::DEBUG); |
2004 | 2004 | //get the cookie from the search for the previous search, required by LDAP |
2005 | - foreach($bases as $base) { |
|
2005 | + foreach ($bases as $base) { |
|
2006 | 2006 | |
2007 | 2007 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
2008 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
2008 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
2009 | 2009 | // no cookie known from a potential previous search. We need |
2010 | 2010 | // to start from 0 to come to the desired page. cookie value |
2011 | 2011 | // of '0' is valid, because 389ds |
@@ -2015,17 +2015,17 @@ discard block |
||
2015 | 2015 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
2016 | 2016 | // '0' is valid, because 389ds |
2017 | 2017 | //TODO: remember this, probably does not change in the next request... |
2018 | - if(empty($cookie) && $cookie !== '0') { |
|
2018 | + if (empty($cookie) && $cookie !== '0') { |
|
2019 | 2019 | $cookie = null; |
2020 | 2020 | } |
2021 | 2021 | } |
2022 | - if(!is_null($cookie)) { |
|
2022 | + if (!is_null($cookie)) { |
|
2023 | 2023 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
2024 | 2024 | $this->abandonPagedSearch(); |
2025 | 2025 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
2026 | 2026 | $this->connection->getConnectionResource(), $limit, |
2027 | 2027 | false, $cookie); |
2028 | - if(!$pagedSearchOK) { |
|
2028 | + if (!$pagedSearchOK) { |
|
2029 | 2029 | return false; |
2030 | 2030 | } |
2031 | 2031 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG); |
@@ -2048,7 +2048,7 @@ discard block |
||
2048 | 2048 | $this->abandonPagedSearch(); |
2049 | 2049 | // in case someone set it to 0 … use 500, otherwise no results will |
2050 | 2050 | // be returned. |
2051 | - $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500; |
|
2051 | + $pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500; |
|
2052 | 2052 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
2053 | 2053 | $this->connection->getConnectionResource(), |
2054 | 2054 | $pageSize, false, ''); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | parent::__construct($access); |
72 | 72 | $filter = $this->access->connection->ldapGroupFilter; |
73 | 73 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
74 | - if(!empty($filter) && !empty($gassoc)) { |
|
74 | + if (!empty($filter) && !empty($gassoc)) { |
|
75 | 75 | $this->enabled = true; |
76 | 76 | } |
77 | 77 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * Checks whether the user is member of a group or not. |
91 | 91 | */ |
92 | 92 | public function inGroup($uid, $gid) { |
93 | - if(!$this->enabled) { |
|
93 | + if (!$this->enabled) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
97 | 97 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
98 | - if(!is_null($inGroup)) { |
|
99 | - return (bool)$inGroup; |
|
98 | + if (!is_null($inGroup)) { |
|
99 | + return (bool) $inGroup; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | $userDN = $this->access->username2dn($uid); |
103 | 103 | |
104 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
104 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
105 | 105 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
106 | 106 | return $isInGroup; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
110 | 110 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
111 | - if(!is_null($members)) { |
|
111 | + if (!is_null($members)) { |
|
112 | 112 | $this->cachedGroupMembers[$gid] = $members; |
113 | 113 | $isInGroup = in_array($userDN, $members); |
114 | 114 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | |
118 | 118 | $groupDN = $this->access->groupname2dn($gid); |
119 | 119 | // just in case |
120 | - if(!$groupDN || !$userDN) { |
|
120 | + if (!$groupDN || !$userDN) { |
|
121 | 121 | $this->access->connection->writeToCache($cacheKey, false); |
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | 125 | //check primary group first |
126 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
126 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
127 | 127 | $this->access->connection->writeToCache($cacheKey, true); |
128 | 128 | return true; |
129 | 129 | } |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
132 | 132 | $members = $this->_groupMembers($groupDN); |
133 | 133 | $members = array_keys($members); // uids are returned as keys |
134 | - if(!is_array($members) || count($members) === 0) { |
|
134 | + if (!is_array($members) || count($members) === 0) { |
|
135 | 135 | $this->access->connection->writeToCache($cacheKey, false); |
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
139 | 139 | //extra work if we don't get back user DNs |
140 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
140 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
141 | 141 | $dns = array(); |
142 | 142 | $filterParts = array(); |
143 | 143 | $bytes = 0; |
144 | - foreach($members as $mid) { |
|
144 | + foreach ($members as $mid) { |
|
145 | 145 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
146 | 146 | $filterParts[] = $filter; |
147 | 147 | $bytes += strlen($filter); |
148 | - if($bytes >= 9000000) { |
|
148 | + if ($bytes >= 9000000) { |
|
149 | 149 | // AD has a default input buffer of 10 MB, we do not want |
150 | 150 | // to take even the chance to exceed it |
151 | 151 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $dns = array_merge($dns, $users); |
156 | 156 | } |
157 | 157 | } |
158 | - if(count($filterParts) > 0) { |
|
158 | + if (count($filterParts) > 0) { |
|
159 | 159 | $filter = $this->access->combineFilterWithOr($filterParts); |
160 | 160 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
161 | 161 | $dns = array_merge($dns, $users); |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | $pos = strpos($memberURLs[0], '('); |
199 | 199 | if ($pos !== false) { |
200 | 200 | $memberUrlFilter = substr($memberURLs[0], $pos); |
201 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
201 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
202 | 202 | $dynamicMembers = array(); |
203 | - foreach($foundMembers as $value) { |
|
203 | + foreach ($foundMembers as $value) { |
|
204 | 204 | $dynamicMembers[$value['dn'][0]] = 1; |
205 | 205 | } |
206 | 206 | } else { |
207 | 207 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
208 | - 'of group ' . $dnGroup, ILogger::DEBUG); |
|
208 | + 'of group '.$dnGroup, ILogger::DEBUG); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | return $dynamicMembers; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | // used extensively in cron job, caching makes sense for nested groups |
230 | 230 | $cacheKey = '_groupMembers'.$dnGroup; |
231 | 231 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
232 | - if($groupMembers !== null) { |
|
232 | + if ($groupMembers !== null) { |
|
233 | 233 | return $groupMembers; |
234 | 234 | } |
235 | 235 | $seen[$dnGroup] = 1; |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | $recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]); |
290 | 290 | |
291 | 291 | if ($nesting !== 1) { |
292 | - if($recordMode) { |
|
292 | + if ($recordMode) { |
|
293 | 293 | // the keys are numeric, but should hold the DN |
294 | - return array_reduce($list, function ($transformed, $record) use ($dn) { |
|
295 | - if($record['dn'][0] != $dn) { |
|
294 | + return array_reduce($list, function($transformed, $record) use ($dn) { |
|
295 | + if ($record['dn'][0] != $dn) { |
|
296 | 296 | $transformed[$record['dn'][0]] = $record; |
297 | 297 | } |
298 | 298 | return $transformed; |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | * @return string|bool |
324 | 324 | */ |
325 | 325 | public function gidNumber2Name($gid, $dn) { |
326 | - $cacheKey = 'gidNumberToName' . $gid; |
|
326 | + $cacheKey = 'gidNumberToName'.$gid; |
|
327 | 327 | $groupName = $this->access->connection->getFromCache($cacheKey); |
328 | - if(!is_null($groupName) && isset($groupName)) { |
|
328 | + if (!is_null($groupName) && isset($groupName)) { |
|
329 | 329 | return $groupName; |
330 | 330 | } |
331 | 331 | |
@@ -333,10 +333,10 @@ discard block |
||
333 | 333 | $filter = $this->access->combineFilterWithAnd([ |
334 | 334 | $this->access->connection->ldapGroupFilter, |
335 | 335 | 'objectClass=posixGroup', |
336 | - $this->access->connection->ldapGidNumber . '=' . $gid |
|
336 | + $this->access->connection->ldapGidNumber.'='.$gid |
|
337 | 337 | ]); |
338 | 338 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
339 | - if(empty($result)) { |
|
339 | + if (empty($result)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | $dn = $result[0]['dn'][0]; |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | private function getEntryGidNumber($dn, $attribute) { |
361 | 361 | $value = $this->access->readAttribute($dn, $attribute); |
362 | - if(is_array($value) && !empty($value)) { |
|
362 | + if (is_array($value) && !empty($value)) { |
|
363 | 363 | return $value[0]; |
364 | 364 | } |
365 | 365 | return false; |
@@ -381,9 +381,9 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function getUserGidNumber($dn) { |
383 | 383 | $gidNumber = false; |
384 | - if($this->access->connection->hasGidNumber) { |
|
384 | + if ($this->access->connection->hasGidNumber) { |
|
385 | 385 | $gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber); |
386 | - if($gidNumber === false) { |
|
386 | + if ($gidNumber === false) { |
|
387 | 387 | $this->access->connection->hasGidNumber = false; |
388 | 388 | } |
389 | 389 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | */ |
401 | 401 | private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') { |
402 | 402 | $groupID = $this->getGroupGidNumber($groupDN); |
403 | - if($groupID === false) { |
|
403 | + if ($groupID === false) { |
|
404 | 404 | throw new \Exception('Not a valid group'); |
405 | 405 | } |
406 | 406 | |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | if ($search !== '') { |
410 | 410 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
411 | 411 | } |
412 | - $filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; |
|
412 | + $filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID; |
|
413 | 413 | |
414 | 414 | return $this->access->combineFilterWithAnd($filterParts); |
415 | 415 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | try { |
452 | 452 | $filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search); |
453 | 453 | $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); |
454 | - return (int)$users; |
|
454 | + return (int) $users; |
|
455 | 455 | } catch (\Exception $e) { |
456 | 456 | return 0; |
457 | 457 | } |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function getUserGroupByGid($dn) { |
466 | 466 | $groupID = $this->getUserGidNumber($dn); |
467 | - if($groupID !== false) { |
|
467 | + if ($groupID !== false) { |
|
468 | 468 | $groupName = $this->gidNumber2Name($groupID, $dn); |
469 | - if($groupName !== false) { |
|
469 | + if ($groupName !== false) { |
|
470 | 470 | return $groupName; |
471 | 471 | } |
472 | 472 | } |
@@ -483,22 +483,22 @@ discard block |
||
483 | 483 | public function primaryGroupID2Name($gid, $dn) { |
484 | 484 | $cacheKey = 'primaryGroupIDtoName'; |
485 | 485 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
486 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
486 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
487 | 487 | return $groupNames[$gid]; |
488 | 488 | } |
489 | 489 | |
490 | 490 | $domainObjectSid = $this->access->getSID($dn); |
491 | - if($domainObjectSid === false) { |
|
491 | + if ($domainObjectSid === false) { |
|
492 | 492 | return false; |
493 | 493 | } |
494 | 494 | |
495 | 495 | //we need to get the DN from LDAP |
496 | 496 | $filter = $this->access->combineFilterWithAnd(array( |
497 | 497 | $this->access->connection->ldapGroupFilter, |
498 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
498 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
499 | 499 | )); |
500 | 500 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
501 | - if(empty($result)) { |
|
501 | + if (empty($result)) { |
|
502 | 502 | return false; |
503 | 503 | } |
504 | 504 | $dn = $result[0]['dn'][0]; |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | */ |
522 | 522 | private function getEntryGroupID($dn, $attribute) { |
523 | 523 | $value = $this->access->readAttribute($dn, $attribute); |
524 | - if(is_array($value) && !empty($value)) { |
|
524 | + if (is_array($value) && !empty($value)) { |
|
525 | 525 | return $value[0]; |
526 | 526 | } |
527 | 527 | return false; |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function getUserPrimaryGroupIDs($dn) { |
545 | 545 | $primaryGroupID = false; |
546 | - if($this->access->connection->hasPrimaryGroups) { |
|
546 | + if ($this->access->connection->hasPrimaryGroups) { |
|
547 | 547 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
548 | - if($primaryGroupID === false) { |
|
548 | + if ($primaryGroupID === false) { |
|
549 | 549 | $this->access->connection->hasPrimaryGroups = false; |
550 | 550 | } |
551 | 551 | } |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | */ |
563 | 563 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
564 | 564 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
565 | - if($groupID === false) { |
|
565 | + if ($groupID === false) { |
|
566 | 566 | throw new \Exception('Not a valid group'); |
567 | 567 | } |
568 | 568 | |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | if ($search !== '') { |
572 | 572 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
573 | 573 | } |
574 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
574 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
575 | 575 | |
576 | 576 | return $this->access->combineFilterWithAnd($filterParts); |
577 | 577 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | try { |
614 | 614 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
615 | 615 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
616 | - return (int)$users; |
|
616 | + return (int) $users; |
|
617 | 617 | } catch (\Exception $e) { |
618 | 618 | return 0; |
619 | 619 | } |
@@ -626,9 +626,9 @@ discard block |
||
626 | 626 | */ |
627 | 627 | public function getUserPrimaryGroup($dn) { |
628 | 628 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
629 | - if($groupID !== false) { |
|
629 | + if ($groupID !== false) { |
|
630 | 630 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
631 | - if($groupName !== false) { |
|
631 | + if ($groupName !== false) { |
|
632 | 632 | return $groupName; |
633 | 633 | } |
634 | 634 | } |
@@ -647,16 +647,16 @@ discard block |
||
647 | 647 | * This function includes groups based on dynamic group membership. |
648 | 648 | */ |
649 | 649 | public function getUserGroups($uid) { |
650 | - if(!$this->enabled) { |
|
650 | + if (!$this->enabled) { |
|
651 | 651 | return array(); |
652 | 652 | } |
653 | 653 | $cacheKey = 'getUserGroups'.$uid; |
654 | 654 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
655 | - if(!is_null($userGroups)) { |
|
655 | + if (!is_null($userGroups)) { |
|
656 | 656 | return $userGroups; |
657 | 657 | } |
658 | 658 | $userDN = $this->access->username2dn($uid); |
659 | - if(!$userDN) { |
|
659 | + if (!$userDN) { |
|
660 | 660 | $this->access->connection->writeToCache($cacheKey, array()); |
661 | 661 | return array(); |
662 | 662 | } |
@@ -670,14 +670,14 @@ discard block |
||
670 | 670 | if (!empty($dynamicGroupMemberURL)) { |
671 | 671 | // look through dynamic groups to add them to the result array if needed |
672 | 672 | $groupsToMatch = $this->access->fetchListOfGroups( |
673 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
674 | - foreach($groupsToMatch as $dynamicGroup) { |
|
673 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
674 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
675 | 675 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
676 | 676 | continue; |
677 | 677 | } |
678 | 678 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
679 | 679 | if ($pos !== false) { |
680 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
680 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
681 | 681 | // apply filter via ldap search to see if this user is in this |
682 | 682 | // dynamic group |
683 | 683 | $userMatch = $this->access->readAttribute( |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | if ($userMatch !== false) { |
689 | 689 | // match found so this user is in this group |
690 | 690 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
691 | - if(is_string($groupName)) { |
|
691 | + if (is_string($groupName)) { |
|
692 | 692 | // be sure to never return false if the dn could not be |
693 | 693 | // resolved to a name, for whatever reason. |
694 | 694 | $groups[] = $groupName; |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | } |
697 | 697 | } else { |
698 | 698 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
699 | - 'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG); |
|
699 | + 'of group '.print_r($dynamicGroup, true), ILogger::DEBUG); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | } |
@@ -704,15 +704,15 @@ discard block |
||
704 | 704 | // if possible, read out membership via memberOf. It's far faster than |
705 | 705 | // performing a search, which still is a fallback later. |
706 | 706 | // memberof doesn't support memberuid, so skip it here. |
707 | - if((int)$this->access->connection->hasMemberOfFilterSupport === 1 |
|
708 | - && (int)$this->access->connection->useMemberOfToDetectMembership === 1 |
|
707 | + if ((int) $this->access->connection->hasMemberOfFilterSupport === 1 |
|
708 | + && (int) $this->access->connection->useMemberOfToDetectMembership === 1 |
|
709 | 709 | && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid' |
710 | 710 | ) { |
711 | 711 | $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
712 | 712 | if (is_array($groupDNs)) { |
713 | 713 | foreach ($groupDNs as $dn) { |
714 | 714 | $groupName = $this->access->dn2groupname($dn); |
715 | - if(is_string($groupName)) { |
|
715 | + if (is_string($groupName)) { |
|
716 | 716 | // be sure to never return false if the dn could not be |
717 | 717 | // resolved to a name, for whatever reason. |
718 | 718 | $groups[] = $groupName; |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | } |
721 | 721 | } |
722 | 722 | |
723 | - if($primaryGroup !== false) { |
|
723 | + if ($primaryGroup !== false) { |
|
724 | 724 | $groups[] = $primaryGroup; |
725 | 725 | } |
726 | - if($gidGroupName !== false) { |
|
726 | + if ($gidGroupName !== false) { |
|
727 | 727 | $groups[] = $gidGroupName; |
728 | 728 | } |
729 | 729 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -731,14 +731,14 @@ discard block |
||
731 | 731 | } |
732 | 732 | |
733 | 733 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
734 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
734 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
735 | 735 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
736 | 736 | ) { |
737 | 737 | $uid = $userDN; |
738 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
738 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
739 | 739 | $result = $this->access->readAttribute($userDN, 'uid'); |
740 | 740 | if ($result === false) { |
741 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
741 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
742 | 742 | $this->access->connection->ldapHost, ILogger::DEBUG); |
743 | 743 | } |
744 | 744 | $uid = $result[0]; |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | $uid = $userDN; |
748 | 748 | } |
749 | 749 | |
750 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
750 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
751 | 751 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
752 | 752 | } else { |
753 | 753 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -756,10 +756,10 @@ discard block |
||
756 | 756 | $groups = array_merge($groups, $groupsByMember); |
757 | 757 | } |
758 | 758 | |
759 | - if($primaryGroup !== false) { |
|
759 | + if ($primaryGroup !== false) { |
|
760 | 760 | $groups[] = $primaryGroup; |
761 | 761 | } |
762 | - if($gidGroupName !== false) { |
|
762 | + if ($gidGroupName !== false) { |
|
763 | 763 | $groups[] = $gidGroupName; |
764 | 764 | } |
765 | 765 | |
@@ -788,8 +788,8 @@ discard block |
||
788 | 788 | $groups = $this->access->fetchListOfGroups($filter, |
789 | 789 | [$this->access->connection->ldapGroupDisplayName, 'dn']); |
790 | 790 | if (is_array($groups)) { |
791 | - $fetcher = function ($dn, &$seen) { |
|
792 | - if(is_array($dn) && isset($dn['dn'][0])) { |
|
791 | + $fetcher = function($dn, &$seen) { |
|
792 | + if (is_array($dn) && isset($dn['dn'][0])) { |
|
793 | 793 | $dn = $dn['dn'][0]; |
794 | 794 | } |
795 | 795 | return $this->getGroupsByMember($dn, $seen); |
@@ -810,33 +810,33 @@ discard block |
||
810 | 810 | * @return array with user ids |
811 | 811 | */ |
812 | 812 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
813 | - if(!$this->enabled) { |
|
813 | + if (!$this->enabled) { |
|
814 | 814 | return array(); |
815 | 815 | } |
816 | - if(!$this->groupExists($gid)) { |
|
816 | + if (!$this->groupExists($gid)) { |
|
817 | 817 | return array(); |
818 | 818 | } |
819 | 819 | $search = $this->access->escapeFilterPart($search, true); |
820 | 820 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
821 | 821 | // check for cache of the exact query |
822 | 822 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
823 | - if(!is_null($groupUsers)) { |
|
823 | + if (!is_null($groupUsers)) { |
|
824 | 824 | return $groupUsers; |
825 | 825 | } |
826 | 826 | |
827 | 827 | // check for cache of the query without limit and offset |
828 | 828 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
829 | - if(!is_null($groupUsers)) { |
|
829 | + if (!is_null($groupUsers)) { |
|
830 | 830 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
831 | 831 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
832 | 832 | return $groupUsers; |
833 | 833 | } |
834 | 834 | |
835 | - if($limit === -1) { |
|
835 | + if ($limit === -1) { |
|
836 | 836 | $limit = null; |
837 | 837 | } |
838 | 838 | $groupDN = $this->access->groupname2dn($gid); |
839 | - if(!$groupDN) { |
|
839 | + if (!$groupDN) { |
|
840 | 840 | // group couldn't be found, return empty resultset |
841 | 841 | $this->access->connection->writeToCache($cacheKey, array()); |
842 | 842 | return array(); |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
846 | 846 | $posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset); |
847 | 847 | $members = $this->_groupMembers($groupDN); |
848 | - if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
848 | + if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
849 | 849 | //in case users could not be retrieved, return empty result set |
850 | 850 | $this->access->connection->writeToCache($cacheKey, []); |
851 | 851 | return []; |
@@ -854,29 +854,29 @@ discard block |
||
854 | 854 | $groupUsers = array(); |
855 | 855 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
856 | 856 | $attrs = $this->access->userManager->getAttributes(true); |
857 | - foreach($members as $member) { |
|
858 | - if($isMemberUid) { |
|
857 | + foreach ($members as $member) { |
|
858 | + if ($isMemberUid) { |
|
859 | 859 | //we got uids, need to get their DNs to 'translate' them to user names |
860 | 860 | $filter = $this->access->combineFilterWithAnd(array( |
861 | 861 | str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter), |
862 | 862 | $this->access->getFilterPartForUserSearch($search) |
863 | 863 | )); |
864 | 864 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
865 | - if(count($ldap_users) < 1) { |
|
865 | + if (count($ldap_users) < 1) { |
|
866 | 866 | continue; |
867 | 867 | } |
868 | 868 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
869 | 869 | } else { |
870 | 870 | //we got DNs, check if we need to filter by search or we can give back all of them |
871 | 871 | if ($search !== '') { |
872 | - if(!$this->access->readAttribute($member, |
|
872 | + if (!$this->access->readAttribute($member, |
|
873 | 873 | $this->access->connection->ldapUserDisplayName, |
874 | 874 | $this->access->getFilterPartForUserSearch($search))) { |
875 | 875 | continue; |
876 | 876 | } |
877 | 877 | } |
878 | 878 | // dn2username will also check if the users belong to the allowed base |
879 | - if($ocname = $this->access->dn2username($member)) { |
|
879 | + if ($ocname = $this->access->dn2username($member)) { |
|
880 | 880 | $groupUsers[] = $ocname; |
881 | 881 | } |
882 | 882 | } |
@@ -904,16 +904,16 @@ discard block |
||
904 | 904 | } |
905 | 905 | |
906 | 906 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
907 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
907 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
908 | 908 | return false; |
909 | 909 | } |
910 | 910 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
911 | - if(!is_null($groupUsers)) { |
|
911 | + if (!is_null($groupUsers)) { |
|
912 | 912 | return $groupUsers; |
913 | 913 | } |
914 | 914 | |
915 | 915 | $groupDN = $this->access->groupname2dn($gid); |
916 | - if(!$groupDN) { |
|
916 | + if (!$groupDN) { |
|
917 | 917 | // group couldn't be found, return empty result set |
918 | 918 | $this->access->connection->writeToCache($cacheKey, false); |
919 | 919 | return false; |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | |
922 | 922 | $members = $this->_groupMembers($groupDN); |
923 | 923 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
924 | - if(!$members && $primaryUserCount === 0) { |
|
924 | + if (!$members && $primaryUserCount === 0) { |
|
925 | 925 | //in case users could not be retrieved, return empty result set |
926 | 926 | $this->access->connection->writeToCache($cacheKey, false); |
927 | 927 | return false; |
@@ -946,27 +946,27 @@ discard block |
||
946 | 946 | //For now this is not important, because the only use of this method |
947 | 947 | //does not supply a search string |
948 | 948 | $groupUsers = array(); |
949 | - foreach($members as $member) { |
|
950 | - if($isMemberUid) { |
|
949 | + foreach ($members as $member) { |
|
950 | + if ($isMemberUid) { |
|
951 | 951 | //we got uids, need to get their DNs to 'translate' them to user names |
952 | 952 | $filter = $this->access->combineFilterWithAnd(array( |
953 | 953 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
954 | 954 | $this->access->getFilterPartForUserSearch($search) |
955 | 955 | )); |
956 | 956 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
957 | - if(count($ldap_users) < 1) { |
|
957 | + if (count($ldap_users) < 1) { |
|
958 | 958 | continue; |
959 | 959 | } |
960 | 960 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
961 | 961 | } else { |
962 | 962 | //we need to apply the search filter now |
963 | - if(!$this->access->readAttribute($member, |
|
963 | + if (!$this->access->readAttribute($member, |
|
964 | 964 | $this->access->connection->ldapUserDisplayName, |
965 | 965 | $this->access->getFilterPartForUserSearch($search))) { |
966 | 966 | continue; |
967 | 967 | } |
968 | 968 | // dn2username will also check if the users belong to the allowed base |
969 | - if($ocname = $this->access->dn2username($member)) { |
|
969 | + if ($ocname = $this->access->dn2username($member)) { |
|
970 | 970 | $groupUsers[] = $ocname; |
971 | 971 | } |
972 | 972 | } |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | * Returns a list with all groups (used by getGroups) |
990 | 990 | */ |
991 | 991 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
992 | - if(!$this->enabled) { |
|
992 | + if (!$this->enabled) { |
|
993 | 993 | return array(); |
994 | 994 | } |
995 | 995 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -997,13 +997,13 @@ discard block |
||
997 | 997 | //Check cache before driving unnecessary searches |
998 | 998 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG); |
999 | 999 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
1000 | - if(!is_null($ldap_groups)) { |
|
1000 | + if (!is_null($ldap_groups)) { |
|
1001 | 1001 | return $ldap_groups; |
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
1005 | 1005 | // error. With a limit of 0, we get 0 results. So we pass null. |
1006 | - if($limit <= 0) { |
|
1006 | + if ($limit <= 0) { |
|
1007 | 1007 | $limit = null; |
1008 | 1008 | } |
1009 | 1009 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -1035,11 +1035,11 @@ discard block |
||
1035 | 1035 | * (active directory has a limit of 1000 by default) |
1036 | 1036 | */ |
1037 | 1037 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
1038 | - if(!$this->enabled) { |
|
1038 | + if (!$this->enabled) { |
|
1039 | 1039 | return array(); |
1040 | 1040 | } |
1041 | 1041 | $search = $this->access->escapeFilterPart($search, true); |
1042 | - $pagingSize = (int)$this->access->connection->ldapPagingSize; |
|
1042 | + $pagingSize = (int) $this->access->connection->ldapPagingSize; |
|
1043 | 1043 | if ($pagingSize <= 0) { |
1044 | 1044 | return $this->getGroupsChunk($search, $limit, $offset); |
1045 | 1045 | } |
@@ -1082,20 +1082,20 @@ discard block |
||
1082 | 1082 | */ |
1083 | 1083 | public function groupExists($gid) { |
1084 | 1084 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
1085 | - if(!is_null($groupExists)) { |
|
1086 | - return (bool)$groupExists; |
|
1085 | + if (!is_null($groupExists)) { |
|
1086 | + return (bool) $groupExists; |
|
1087 | 1087 | } |
1088 | 1088 | |
1089 | 1089 | //getting dn, if false the group does not exist. If dn, it may be mapped |
1090 | 1090 | //only, requires more checking. |
1091 | 1091 | $dn = $this->access->groupname2dn($gid); |
1092 | - if(!$dn) { |
|
1092 | + if (!$dn) { |
|
1093 | 1093 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1094 | 1094 | return false; |
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | //if group really still exists, we will be able to read its objectclass |
1098 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
1098 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
1099 | 1099 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1100 | 1100 | return false; |
1101 | 1101 | } |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | * compared with GroupInterface::CREATE_GROUP etc. |
1114 | 1114 | */ |
1115 | 1115 | public function implementsActions($actions) { |
1116 | - return (bool)((GroupInterface::COUNT_USERS | |
|
1116 | + return (bool) ((GroupInterface::COUNT_USERS | |
|
1117 | 1117 | $this->groupPluginManager->getImplementedActions()) & $actions); |
1118 | 1118 | } |
1119 | 1119 | |
@@ -1230,7 +1230,7 @@ discard block |
||
1230 | 1230 | return $this->groupPluginManager->getDisplayName($gid); |
1231 | 1231 | } |
1232 | 1232 | |
1233 | - $cacheKey = 'group_getDisplayName' . $gid; |
|
1233 | + $cacheKey = 'group_getDisplayName'.$gid; |
|
1234 | 1234 | if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
1235 | 1235 | return $displayName; |
1236 | 1236 | } |