@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return AbstractMapping |
131 | 131 | */ |
132 | 132 | public function getUserMapper() { |
133 | - if(is_null($this->userMapper)) { |
|
133 | + if (is_null($this->userMapper)) { |
|
134 | 134 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
135 | 135 | } |
136 | 136 | return $this->userMapper; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return AbstractMapping |
151 | 151 | */ |
152 | 152 | public function getGroupMapper() { |
153 | - if(is_null($this->groupMapper)) { |
|
153 | + if (is_null($this->groupMapper)) { |
|
154 | 154 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
155 | 155 | } |
156 | 156 | return $this->groupMapper; |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | * @throws ServerNotAvailableException |
184 | 184 | */ |
185 | 185 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
186 | - if(!$this->checkConnection()) { |
|
186 | + if (!$this->checkConnection()) { |
|
187 | 187 | \OCP\Util::writeLog('user_ldap', |
188 | 188 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
189 | 189 | ILogger::WARN); |
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | $cr = $this->connection->getConnectionResource(); |
193 | - if(!$this->ldap->isResource($cr)) { |
|
193 | + if (!$this->ldap->isResource($cr)) { |
|
194 | 194 | //LDAP not available |
195 | 195 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG); |
196 | 196 | return false; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $this->abandonPagedSearch(); |
201 | 201 | // openLDAP requires that we init a new Paged Search. Not needed by AD, |
202 | 202 | // but does not hurt either. |
203 | - $pagingSize = (int)$this->connection->ldapPagingSize; |
|
203 | + $pagingSize = (int) $this->connection->ldapPagingSize; |
|
204 | 204 | // 0 won't result in replies, small numbers may leave out groups |
205 | 205 | // (cf. #12306), 500 is default for paging and should work everywhere. |
206 | 206 | $maxResults = $pagingSize > 20 ? $pagingSize : 500; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $isRangeRequest = false; |
214 | 214 | do { |
215 | 215 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
216 | - if(is_bool($result)) { |
|
216 | + if (is_bool($result)) { |
|
217 | 217 | // when an exists request was run and it was successful, an empty |
218 | 218 | // array must be returned |
219 | 219 | return $result ? [] : false; |
@@ -230,22 +230,22 @@ discard block |
||
230 | 230 | $result = $this->extractRangeData($result, $attr); |
231 | 231 | if (!empty($result)) { |
232 | 232 | $normalizedResult = $this->extractAttributeValuesFromResult( |
233 | - [ $attr => $result['values'] ], |
|
233 | + [$attr => $result['values']], |
|
234 | 234 | $attr |
235 | 235 | ); |
236 | 236 | $values = array_merge($values, $normalizedResult); |
237 | 237 | |
238 | - if($result['rangeHigh'] === '*') { |
|
238 | + if ($result['rangeHigh'] === '*') { |
|
239 | 239 | // when server replies with * as high range value, there are |
240 | 240 | // no more results left |
241 | 241 | return $values; |
242 | 242 | } else { |
243 | - $low = $result['rangeHigh'] + 1; |
|
244 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
243 | + $low = $result['rangeHigh'] + 1; |
|
244 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
245 | 245 | $isRangeRequest = true; |
246 | 246 | } |
247 | 247 | } |
248 | - } while($isRangeRequest); |
|
248 | + } while ($isRangeRequest); |
|
249 | 249 | |
250 | 250 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG); |
251 | 251 | return false; |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | if (!$this->ldap->isResource($rr)) { |
272 | 272 | if ($attribute !== '') { |
273 | 273 | //do not throw this message on userExists check, irritates |
274 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG); |
|
274 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG); |
|
275 | 275 | } |
276 | 276 | //in case an error occurs , e.g. object does not exist |
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
280 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG); |
|
280 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG); |
|
281 | 281 | return true; |
282 | 282 | } |
283 | 283 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function extractAttributeValuesFromResult($result, $attribute) { |
304 | 304 | $values = []; |
305 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
305 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
306 | 306 | $lowercaseAttribute = strtolower($attribute); |
307 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
308 | - if($this->resemblesDN($attribute)) { |
|
307 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
308 | + if ($this->resemblesDN($attribute)) { |
|
309 | 309 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
310 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
310 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
311 | 311 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
312 | 312 | } else { |
313 | 313 | $values[] = $result[$attribute][$i]; |
@@ -329,10 +329,10 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public function extractRangeData($result, $attribute) { |
331 | 331 | $keys = array_keys($result); |
332 | - foreach($keys as $key) { |
|
333 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
332 | + foreach ($keys as $key) { |
|
333 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
334 | 334 | $queryData = explode(';', $key); |
335 | - if(strpos($queryData[1], 'range=') === 0) { |
|
335 | + if (strpos($queryData[1], 'range=') === 0) { |
|
336 | 336 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
337 | 337 | $data = [ |
338 | 338 | 'values' => $result[$key], |
@@ -357,18 +357,18 @@ discard block |
||
357 | 357 | * @throws \Exception |
358 | 358 | */ |
359 | 359 | public function setPassword($userDN, $password) { |
360 | - if((int)$this->connection->turnOnPasswordChange !== 1) { |
|
360 | + if ((int) $this->connection->turnOnPasswordChange !== 1) { |
|
361 | 361 | throw new \Exception('LDAP password changes are disabled.'); |
362 | 362 | } |
363 | 363 | $cr = $this->connection->getConnectionResource(); |
364 | - if(!$this->ldap->isResource($cr)) { |
|
364 | + if (!$this->ldap->isResource($cr)) { |
|
365 | 365 | //LDAP not available |
366 | 366 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG); |
367 | 367 | return false; |
368 | 368 | } |
369 | 369 | try { |
370 | 370 | return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
371 | - } catch(ConstraintViolationException $e) { |
|
371 | + } catch (ConstraintViolationException $e) { |
|
372 | 372 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
373 | 373 | } |
374 | 374 | } |
@@ -410,17 +410,17 @@ discard block |
||
410 | 410 | */ |
411 | 411 | public function getDomainDNFromDN($dn) { |
412 | 412 | $allParts = $this->ldap->explodeDN($dn, 0); |
413 | - if($allParts === false) { |
|
413 | + if ($allParts === false) { |
|
414 | 414 | //not a valid DN |
415 | 415 | return ''; |
416 | 416 | } |
417 | 417 | $domainParts = array(); |
418 | 418 | $dcFound = false; |
419 | - foreach($allParts as $part) { |
|
420 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
419 | + foreach ($allParts as $part) { |
|
420 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
421 | 421 | $dcFound = true; |
422 | 422 | } |
423 | - if($dcFound) { |
|
423 | + if ($dcFound) { |
|
424 | 424 | $domainParts[] = $part; |
425 | 425 | } |
426 | 426 | } |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | |
447 | 447 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
448 | 448 | //server setups |
449 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
449 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
450 | 450 | return $fdn; |
451 | 451 | } |
452 | 452 | |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | //To avoid bypassing the base DN settings under certain circumstances |
464 | 464 | //with the group support, check whether the provided DN matches one of |
465 | 465 | //the given Bases |
466 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
466 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
467 | 467 | return false; |
468 | 468 | } |
469 | 469 | |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function groupsMatchFilter($groupDNs) { |
483 | 483 | $validGroupDNs = []; |
484 | - foreach($groupDNs as $dn) { |
|
484 | + foreach ($groupDNs as $dn) { |
|
485 | 485 | $cacheKey = 'groupsMatchFilter-'.$dn; |
486 | 486 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
487 | - if(!is_null($groupMatchFilter)) { |
|
488 | - if($groupMatchFilter) { |
|
487 | + if (!is_null($groupMatchFilter)) { |
|
488 | + if ($groupMatchFilter) { |
|
489 | 489 | $validGroupDNs[] = $dn; |
490 | 490 | } |
491 | 491 | continue; |
@@ -493,13 +493,13 @@ discard block |
||
493 | 493 | |
494 | 494 | // Check the base DN first. If this is not met already, we don't |
495 | 495 | // need to ask the server at all. |
496 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
496 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
497 | 497 | $this->connection->writeToCache($cacheKey, false); |
498 | 498 | continue; |
499 | 499 | } |
500 | 500 | |
501 | 501 | $result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter); |
502 | - if(is_array($result)) { |
|
502 | + if (is_array($result)) { |
|
503 | 503 | $this->connection->writeToCache($cacheKey, true); |
504 | 504 | $validGroupDNs[] = $dn; |
505 | 505 | } else { |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | //To avoid bypassing the base DN settings under certain circumstances |
521 | 521 | //with the group support, check whether the provided DN matches one of |
522 | 522 | //the given Bases |
523 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
523 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
524 | 524 | return false; |
525 | 525 | } |
526 | 526 | |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | */ |
541 | 541 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
542 | 542 | $newlyMapped = false; |
543 | - if($isUser) { |
|
543 | + if ($isUser) { |
|
544 | 544 | $mapper = $this->getUserMapper(); |
545 | 545 | $nameAttribute = $this->connection->ldapUserDisplayName; |
546 | 546 | $filter = $this->connection->ldapUserFilter; |
@@ -552,15 +552,15 @@ discard block |
||
552 | 552 | |
553 | 553 | //let's try to retrieve the Nextcloud name from the mappings table |
554 | 554 | $ncName = $mapper->getNameByDN($fdn); |
555 | - if(is_string($ncName)) { |
|
555 | + if (is_string($ncName)) { |
|
556 | 556 | return $ncName; |
557 | 557 | } |
558 | 558 | |
559 | 559 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
560 | 560 | $uuid = $this->getUUID($fdn, $isUser, $record); |
561 | - if(is_string($uuid)) { |
|
561 | + if (is_string($uuid)) { |
|
562 | 562 | $ncName = $mapper->getNameByUUID($uuid); |
563 | - if(is_string($ncName)) { |
|
563 | + if (is_string($ncName)) { |
|
564 | 564 | $mapper->setDNbyUUID($fdn, $uuid); |
565 | 565 | return $ncName; |
566 | 566 | } |
@@ -570,17 +570,17 @@ discard block |
||
570 | 570 | return false; |
571 | 571 | } |
572 | 572 | |
573 | - if(is_null($ldapName)) { |
|
573 | + if (is_null($ldapName)) { |
|
574 | 574 | $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); |
575 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
575 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
576 | 576 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO); |
577 | 577 | return false; |
578 | 578 | } |
579 | 579 | $ldapName = $ldapName[0]; |
580 | 580 | } |
581 | 581 | |
582 | - if($isUser) { |
|
583 | - $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr; |
|
582 | + if ($isUser) { |
|
583 | + $usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr; |
|
584 | 584 | if ($usernameAttribute !== '') { |
585 | 585 | $username = $this->readAttribute($fdn, $usernameAttribute); |
586 | 586 | $username = $username[0]; |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | // outside of core user management will still cache the user as non-existing. |
611 | 611 | $originalTTL = $this->connection->ldapCacheTTL; |
612 | 612 | $this->connection->setConfiguration(['ldapCacheTTL' => 0]); |
613 | - if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName)) |
|
613 | + if (($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName)) |
|
614 | 614 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { |
615 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
615 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
616 | 616 | $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); |
617 | - if($this->ncUserManager instanceof PublicEmitter && $isUser) { |
|
617 | + if ($this->ncUserManager instanceof PublicEmitter && $isUser) { |
|
618 | 618 | $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]); |
619 | 619 | } |
620 | 620 | $newlyMapped = true; |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * @throws \Exception |
667 | 667 | */ |
668 | 668 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
669 | - if($isUsers) { |
|
669 | + if ($isUsers) { |
|
670 | 670 | $nameAttribute = $this->connection->ldapUserDisplayName; |
671 | 671 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
672 | 672 | } else { |
@@ -674,9 +674,9 @@ discard block |
||
674 | 674 | } |
675 | 675 | $nextcloudNames = []; |
676 | 676 | |
677 | - foreach($ldapObjects as $ldapObject) { |
|
677 | + foreach ($ldapObjects as $ldapObject) { |
|
678 | 678 | $nameByLDAP = null; |
679 | - if( isset($ldapObject[$nameAttribute]) |
|
679 | + if (isset($ldapObject[$nameAttribute]) |
|
680 | 680 | && is_array($ldapObject[$nameAttribute]) |
681 | 681 | && isset($ldapObject[$nameAttribute][0]) |
682 | 682 | ) { |
@@ -685,13 +685,13 @@ discard block |
||
685 | 685 | } |
686 | 686 | |
687 | 687 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
688 | - if($ncName) { |
|
688 | + if ($ncName) { |
|
689 | 689 | $nextcloudNames[] = $ncName; |
690 | - if($isUsers) { |
|
690 | + if ($isUsers) { |
|
691 | 691 | $this->updateUserState($ncName); |
692 | 692 | //cache the user names so it does not need to be retrieved |
693 | 693 | //again later (e.g. sharing dialogue). |
694 | - if(is_null($nameByLDAP)) { |
|
694 | + if (is_null($nameByLDAP)) { |
|
695 | 695 | continue; |
696 | 696 | } |
697 | 697 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function updateUserState($ncname) { |
713 | 713 | $user = $this->userManager->get($ncname); |
714 | - if($user instanceof OfflineUser) { |
|
714 | + if ($user instanceof OfflineUser) { |
|
715 | 715 | $user->unmark(); |
716 | 716 | } |
717 | 717 | } |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | */ |
743 | 743 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
744 | 744 | $user = $this->userManager->get($ocName); |
745 | - if($user === null) { |
|
745 | + if ($user === null) { |
|
746 | 746 | return; |
747 | 747 | } |
748 | 748 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -762,9 +762,9 @@ discard block |
||
762 | 762 | $attempts = 0; |
763 | 763 | //while loop is just a precaution. If a name is not generated within |
764 | 764 | //20 attempts, something else is very wrong. Avoids infinite loop. |
765 | - while($attempts < 20){ |
|
766 | - $altName = $name . '_' . rand(1000,9999); |
|
767 | - if(!$this->ncUserManager->userExists($altName)) { |
|
765 | + while ($attempts < 20) { |
|
766 | + $altName = $name.'_'.rand(1000, 9999); |
|
767 | + if (!$this->ncUserManager->userExists($altName)) { |
|
768 | 768 | return $altName; |
769 | 769 | } |
770 | 770 | $attempts++; |
@@ -786,25 +786,25 @@ discard block |
||
786 | 786 | */ |
787 | 787 | private function _createAltInternalOwnCloudNameForGroups($name) { |
788 | 788 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
789 | - if(!$usedNames || count($usedNames) === 0) { |
|
789 | + if (!$usedNames || count($usedNames) === 0) { |
|
790 | 790 | $lastNo = 1; //will become name_2 |
791 | 791 | } else { |
792 | 792 | natsort($usedNames); |
793 | 793 | $lastName = array_pop($usedNames); |
794 | - $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1); |
|
794 | + $lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1); |
|
795 | 795 | } |
796 | - $altName = $name.'_'. (string)($lastNo+1); |
|
796 | + $altName = $name.'_'.(string) ($lastNo + 1); |
|
797 | 797 | unset($usedNames); |
798 | 798 | |
799 | 799 | $attempts = 1; |
800 | - while($attempts < 21){ |
|
800 | + while ($attempts < 21) { |
|
801 | 801 | // Check to be really sure it is unique |
802 | 802 | // while loop is just a precaution. If a name is not generated within |
803 | 803 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
804 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
804 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
805 | 805 | return $altName; |
806 | 806 | } |
807 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
807 | + $altName = $name.'_'.($lastNo + $attempts); |
|
808 | 808 | $attempts++; |
809 | 809 | } |
810 | 810 | return false; |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | private function createAltInternalOwnCloudName($name, $isUser) { |
820 | 820 | $originalTTL = $this->connection->ldapCacheTTL; |
821 | 821 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
822 | - if($isUser) { |
|
822 | + if ($isUser) { |
|
823 | 823 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
824 | 824 | } else { |
825 | 825 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -867,13 +867,13 @@ discard block |
||
867 | 867 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
868 | 868 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
869 | 869 | $recordsToUpdate = $ldapRecords; |
870 | - if(!$forceApplyAttributes) { |
|
870 | + if (!$forceApplyAttributes) { |
|
871 | 871 | $isBackgroundJobModeAjax = $this->config |
872 | 872 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
873 | 873 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
874 | 874 | $newlyMapped = false; |
875 | 875 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
876 | - if(is_string($uid)) { |
|
876 | + if (is_string($uid)) { |
|
877 | 877 | $this->cacheUserExists($uid); |
878 | 878 | } |
879 | 879 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -891,15 +891,15 @@ discard block |
||
891 | 891 | * @param array $ldapRecords |
892 | 892 | * @throws \Exception |
893 | 893 | */ |
894 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
894 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
895 | 895 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
896 | - foreach($ldapRecords as $userRecord) { |
|
897 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
896 | + foreach ($ldapRecords as $userRecord) { |
|
897 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
898 | 898 | // displayName is obligatory |
899 | 899 | continue; |
900 | 900 | } |
901 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
902 | - if($ocName === false) { |
|
901 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
902 | + if ($ocName === false) { |
|
903 | 903 | continue; |
904 | 904 | } |
905 | 905 | $this->updateUserState($ocName); |
@@ -932,8 +932,8 @@ discard block |
||
932 | 932 | * @return array |
933 | 933 | */ |
934 | 934 | private function fetchList($list, $manyAttributes) { |
935 | - if(is_array($list)) { |
|
936 | - if($manyAttributes) { |
|
935 | + if (is_array($list)) { |
|
936 | + if ($manyAttributes) { |
|
937 | 937 | return $list; |
938 | 938 | } else { |
939 | 939 | $list = array_reduce($list, function($carry, $item) { |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | // php no longer supports call-time pass-by-reference |
1032 | 1032 | // thus cannot support controlPagedResultResponse as the third argument |
1033 | 1033 | // is a reference |
1034 | - $doMethod = function () use ($command, &$arguments) { |
|
1034 | + $doMethod = function() use ($command, &$arguments) { |
|
1035 | 1035 | if ($command == 'controlPagedResultResponse') { |
1036 | 1036 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
1037 | 1037 | } else { |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | $this->connection->resetConnectionResource(); |
1050 | 1050 | $cr = $this->connection->getConnectionResource(); |
1051 | 1051 | |
1052 | - if(!$this->ldap->isResource($cr)) { |
|
1052 | + if (!$this->ldap->isResource($cr)) { |
|
1053 | 1053 | // Seems like we didn't find any resource. |
1054 | 1054 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG); |
1055 | 1055 | throw $e; |
@@ -1074,13 +1074,13 @@ discard block |
||
1074 | 1074 | * @throws ServerNotAvailableException |
1075 | 1075 | */ |
1076 | 1076 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
1077 | - if(!is_null($attr) && !is_array($attr)) { |
|
1077 | + if (!is_null($attr) && !is_array($attr)) { |
|
1078 | 1078 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | // See if we have a resource, in case not cancel with message |
1082 | 1082 | $cr = $this->connection->getConnectionResource(); |
1083 | - if(!$this->ldap->isResource($cr)) { |
|
1083 | + if (!$this->ldap->isResource($cr)) { |
|
1084 | 1084 | // Seems like we didn't find any resource. |
1085 | 1085 | // Return an empty array just like before. |
1086 | 1086 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG); |
@@ -1088,13 +1088,13 @@ discard block |
||
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | //check whether paged search should be attempted |
1091 | - $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset); |
|
1091 | + $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset); |
|
1092 | 1092 | |
1093 | 1093 | $linkResources = array_pad(array(), count($base), $cr); |
1094 | 1094 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
1095 | 1095 | // cannot use $cr anymore, might have changed in the previous call! |
1096 | 1096 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
1097 | - if(!is_array($sr) || $error !== 0) { |
|
1097 | + if (!is_array($sr) || $error !== 0) { |
|
1098 | 1098 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR); |
1099 | 1099 | return false; |
1100 | 1100 | } |
@@ -1117,29 +1117,29 @@ discard block |
||
1117 | 1117 | */ |
1118 | 1118 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
1119 | 1119 | $cookie = null; |
1120 | - if($pagedSearchOK) { |
|
1120 | + if ($pagedSearchOK) { |
|
1121 | 1121 | $cr = $this->connection->getConnectionResource(); |
1122 | - foreach($sr as $key => $res) { |
|
1123 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
1122 | + foreach ($sr as $key => $res) { |
|
1123 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
1124 | 1124 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
1125 | 1125 | } |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | //browsing through prior pages to get the cookie for the new one |
1129 | - if($skipHandling) { |
|
1129 | + if ($skipHandling) { |
|
1130 | 1130 | return false; |
1131 | 1131 | } |
1132 | 1132 | // if count is bigger, then the server does not support |
1133 | 1133 | // paged search. Instead, he did a normal search. We set a |
1134 | 1134 | // flag here, so the callee knows how to deal with it. |
1135 | - if($iFoundItems <= $limit) { |
|
1135 | + if ($iFoundItems <= $limit) { |
|
1136 | 1136 | $this->pagedSearchedSuccessful = true; |
1137 | 1137 | } |
1138 | 1138 | } else { |
1139 | - if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) { |
|
1139 | + if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) { |
|
1140 | 1140 | \OC::$server->getLogger()->debug( |
1141 | 1141 | 'Paged search was not available', |
1142 | - [ 'app' => 'user_ldap' ] |
|
1142 | + ['app' => 'user_ldap'] |
|
1143 | 1143 | ); |
1144 | 1144 | } |
1145 | 1145 | } |
@@ -1168,8 +1168,8 @@ discard block |
||
1168 | 1168 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1169 | 1169 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), ILogger::DEBUG); |
1170 | 1170 | |
1171 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
1172 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1171 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
1172 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1173 | 1173 | $limitPerPage = $limit; |
1174 | 1174 | } |
1175 | 1175 | |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | |
1180 | 1180 | do { |
1181 | 1181 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
1182 | - if($search === false) { |
|
1182 | + if ($search === false) { |
|
1183 | 1183 | return $counter > 0 ? $counter : false; |
1184 | 1184 | } |
1185 | 1185 | list($sr, $pagedSearchOK) = $search; |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | * Continue now depends on $hasMorePages value |
1199 | 1199 | */ |
1200 | 1200 | $continue = $pagedSearchOK && $hasMorePages; |
1201 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1201 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1202 | 1202 | |
1203 | 1203 | return $counter; |
1204 | 1204 | } |
@@ -1210,8 +1210,8 @@ discard block |
||
1210 | 1210 | private function countEntriesInSearchResults($searchResults) { |
1211 | 1211 | $counter = 0; |
1212 | 1212 | |
1213 | - foreach($searchResults as $res) { |
|
1214 | - $count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
1213 | + foreach ($searchResults as $res) { |
|
1214 | + $count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
1215 | 1215 | $counter += $count; |
1216 | 1216 | } |
1217 | 1217 | |
@@ -1231,8 +1231,8 @@ discard block |
||
1231 | 1231 | * @throws ServerNotAvailableException |
1232 | 1232 | */ |
1233 | 1233 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1234 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
1235 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1234 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
1235 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1236 | 1236 | $limitPerPage = $limit; |
1237 | 1237 | } |
1238 | 1238 | |
@@ -1246,13 +1246,13 @@ discard block |
||
1246 | 1246 | $savedoffset = $offset; |
1247 | 1247 | do { |
1248 | 1248 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
1249 | - if($search === false) { |
|
1249 | + if ($search === false) { |
|
1250 | 1250 | return []; |
1251 | 1251 | } |
1252 | 1252 | list($sr, $pagedSearchOK) = $search; |
1253 | 1253 | $cr = $this->connection->getConnectionResource(); |
1254 | 1254 | |
1255 | - if($skipHandling) { |
|
1255 | + if ($skipHandling) { |
|
1256 | 1256 | //i.e. result do not need to be fetched, we just need the cookie |
1257 | 1257 | //thus pass 1 or any other value as $iFoundItems because it is not |
1258 | 1258 | //used |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | } |
1264 | 1264 | |
1265 | 1265 | $iFoundItems = 0; |
1266 | - foreach($sr as $res) { |
|
1266 | + foreach ($sr as $res) { |
|
1267 | 1267 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
1268 | 1268 | $iFoundItems = max($iFoundItems, $findings['count']); |
1269 | 1269 | unset($findings['count']); |
@@ -1279,27 +1279,27 @@ discard block |
||
1279 | 1279 | |
1280 | 1280 | // if we're here, probably no connection resource is returned. |
1281 | 1281 | // to make Nextcloud behave nicely, we simply give back an empty array. |
1282 | - if(is_null($findings)) { |
|
1282 | + if (is_null($findings)) { |
|
1283 | 1283 | return array(); |
1284 | 1284 | } |
1285 | 1285 | |
1286 | - if(!is_null($attr)) { |
|
1286 | + if (!is_null($attr)) { |
|
1287 | 1287 | $selection = []; |
1288 | 1288 | $i = 0; |
1289 | - foreach($findings as $item) { |
|
1290 | - if(!is_array($item)) { |
|
1289 | + foreach ($findings as $item) { |
|
1290 | + if (!is_array($item)) { |
|
1291 | 1291 | continue; |
1292 | 1292 | } |
1293 | 1293 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
1294 | - foreach($attr as $key) { |
|
1295 | - if(isset($item[$key])) { |
|
1296 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1294 | + foreach ($attr as $key) { |
|
1295 | + if (isset($item[$key])) { |
|
1296 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1297 | 1297 | unset($item[$key]['count']); |
1298 | 1298 | } |
1299 | - if($key !== 'dn') { |
|
1300 | - if($this->resemblesDN($key)) { |
|
1299 | + if ($key !== 'dn') { |
|
1300 | + if ($this->resemblesDN($key)) { |
|
1301 | 1301 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
1302 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
1302 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
1303 | 1303 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
1304 | 1304 | } else { |
1305 | 1305 | $selection[$i][$key] = $item[$key]; |
@@ -1317,14 +1317,14 @@ discard block |
||
1317 | 1317 | //we slice the findings, when |
1318 | 1318 | //a) paged search unsuccessful, though attempted |
1319 | 1319 | //b) no paged search, but limit set |
1320 | - if((!$this->getPagedSearchResultState() |
|
1320 | + if ((!$this->getPagedSearchResultState() |
|
1321 | 1321 | && $pagedSearchOK) |
1322 | 1322 | || ( |
1323 | 1323 | !$pagedSearchOK |
1324 | 1324 | && !is_null($limit) |
1325 | 1325 | ) |
1326 | 1326 | ) { |
1327 | - $findings = array_slice($findings, (int)$offset, $limit); |
|
1327 | + $findings = array_slice($findings, (int) $offset, $limit); |
|
1328 | 1328 | } |
1329 | 1329 | return $findings; |
1330 | 1330 | } |
@@ -1337,13 +1337,13 @@ discard block |
||
1337 | 1337 | public function sanitizeUsername($name) { |
1338 | 1338 | $name = trim($name); |
1339 | 1339 | |
1340 | - if($this->connection->ldapIgnoreNamingRules) { |
|
1340 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
1341 | 1341 | return $name; |
1342 | 1342 | } |
1343 | 1343 | |
1344 | 1344 | // Transliteration to ASCII |
1345 | 1345 | $transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name); |
1346 | - if($transliterated !== false) { |
|
1346 | + if ($transliterated !== false) { |
|
1347 | 1347 | // depending on system config iconv can work or not |
1348 | 1348 | $name = $transliterated; |
1349 | 1349 | } |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | // Every remaining disallowed characters will be removed |
1355 | 1355 | $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name); |
1356 | 1356 | |
1357 | - if($name === '') { |
|
1357 | + if ($name === '') { |
|
1358 | 1358 | throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters'); |
1359 | 1359 | } |
1360 | 1360 | |
@@ -1369,13 +1369,13 @@ discard block |
||
1369 | 1369 | */ |
1370 | 1370 | public function escapeFilterPart($input, $allowAsterisk = false) { |
1371 | 1371 | $asterisk = ''; |
1372 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1372 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1373 | 1373 | $asterisk = '*'; |
1374 | 1374 | $input = mb_substr($input, 1, null, 'UTF-8'); |
1375 | 1375 | } |
1376 | 1376 | $search = array('*', '\\', '(', ')'); |
1377 | 1377 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
1378 | - return $asterisk . str_replace($search, $replace, $input); |
|
1378 | + return $asterisk.str_replace($search, $replace, $input); |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | 1381 | /** |
@@ -1405,13 +1405,13 @@ discard block |
||
1405 | 1405 | */ |
1406 | 1406 | private function combineFilter($filters, $operator) { |
1407 | 1407 | $combinedFilter = '('.$operator; |
1408 | - foreach($filters as $filter) { |
|
1408 | + foreach ($filters as $filter) { |
|
1409 | 1409 | if ($filter !== '' && $filter[0] !== '(') { |
1410 | 1410 | $filter = '('.$filter.')'; |
1411 | 1411 | } |
1412 | - $combinedFilter.=$filter; |
|
1412 | + $combinedFilter .= $filter; |
|
1413 | 1413 | } |
1414 | - $combinedFilter.=')'; |
|
1414 | + $combinedFilter .= ')'; |
|
1415 | 1415 | return $combinedFilter; |
1416 | 1416 | } |
1417 | 1417 | |
@@ -1447,17 +1447,17 @@ discard block |
||
1447 | 1447 | * @throws \Exception |
1448 | 1448 | */ |
1449 | 1449 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
1450 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1450 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1451 | 1451 | throw new \Exception('searchAttributes must be an array with at least two string'); |
1452 | 1452 | } |
1453 | 1453 | $searchWords = explode(' ', trim($search)); |
1454 | 1454 | $wordFilters = array(); |
1455 | - foreach($searchWords as $word) { |
|
1455 | + foreach ($searchWords as $word) { |
|
1456 | 1456 | $word = $this->prepareSearchTerm($word); |
1457 | 1457 | //every word needs to appear at least once |
1458 | 1458 | $wordMatchOneAttrFilters = array(); |
1459 | - foreach($searchAttributes as $attr) { |
|
1460 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
1459 | + foreach ($searchAttributes as $attr) { |
|
1460 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
1461 | 1461 | } |
1462 | 1462 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
1463 | 1463 | } |
@@ -1475,10 +1475,10 @@ discard block |
||
1475 | 1475 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
1476 | 1476 | $filter = array(); |
1477 | 1477 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
1478 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1478 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1479 | 1479 | try { |
1480 | 1480 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
1481 | - } catch(\Exception $e) { |
|
1481 | + } catch (\Exception $e) { |
|
1482 | 1482 | \OCP\Util::writeLog( |
1483 | 1483 | 'user_ldap', |
1484 | 1484 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1488,17 +1488,17 @@ discard block |
||
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | $search = $this->prepareSearchTerm($search); |
1491 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1491 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1492 | 1492 | if ($fallbackAttribute === '') { |
1493 | 1493 | return ''; |
1494 | 1494 | } |
1495 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
1495 | + $filter[] = $fallbackAttribute.'='.$search; |
|
1496 | 1496 | } else { |
1497 | - foreach($searchAttributes as $attribute) { |
|
1498 | - $filter[] = $attribute . '=' . $search; |
|
1497 | + foreach ($searchAttributes as $attribute) { |
|
1498 | + $filter[] = $attribute.'='.$search; |
|
1499 | 1499 | } |
1500 | 1500 | } |
1501 | - if(count($filter) === 1) { |
|
1501 | + if (count($filter) === 1) { |
|
1502 | 1502 | return '('.$filter[0].')'; |
1503 | 1503 | } |
1504 | 1504 | return $this->combineFilterWithOr($filter); |
@@ -1519,7 +1519,7 @@ discard block |
||
1519 | 1519 | if ($term === '') { |
1520 | 1520 | $result = '*'; |
1521 | 1521 | } else if ($allowEnum !== 'no') { |
1522 | - $result = $term . '*'; |
|
1522 | + $result = $term.'*'; |
|
1523 | 1523 | } |
1524 | 1524 | return $result; |
1525 | 1525 | } |
@@ -1531,7 +1531,7 @@ discard block |
||
1531 | 1531 | public function getFilterForUserCount() { |
1532 | 1532 | $filter = $this->combineFilterWithAnd(array( |
1533 | 1533 | $this->connection->ldapUserFilter, |
1534 | - $this->connection->ldapUserDisplayName . '=*' |
|
1534 | + $this->connection->ldapUserDisplayName.'=*' |
|
1535 | 1535 | )); |
1536 | 1536 | |
1537 | 1537 | return $filter; |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | 'ldapAgentName' => $name, |
1550 | 1550 | 'ldapAgentPassword' => $password |
1551 | 1551 | ); |
1552 | - if(!$testConnection->setConfiguration($credentials)) { |
|
1552 | + if (!$testConnection->setConfiguration($credentials)) { |
|
1553 | 1553 | return false; |
1554 | 1554 | } |
1555 | 1555 | return $testConnection->bind(); |
@@ -1571,30 +1571,30 @@ discard block |
||
1571 | 1571 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
1572 | 1572 | // existing DN to be able to reliably detect it. |
1573 | 1573 | $result = $this->search($filter, $base, ['dn'], 1); |
1574 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1574 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1575 | 1575 | throw new \Exception('Cannot determine UUID attribute'); |
1576 | 1576 | } |
1577 | 1577 | $dn = $result[0]['dn'][0]; |
1578 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
1578 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
1579 | 1579 | throw new \Exception('Cannot determine UUID attribute'); |
1580 | 1580 | } |
1581 | 1581 | } else { |
1582 | 1582 | // The UUID attribute is either known or an override is given. |
1583 | 1583 | // By calling this method we ensure that $this->connection->$uuidAttr |
1584 | 1584 | // is definitely set |
1585 | - if(!$this->detectUuidAttribute('', true)) { |
|
1585 | + if (!$this->detectUuidAttribute('', true)) { |
|
1586 | 1586 | throw new \Exception('Cannot determine UUID attribute'); |
1587 | 1587 | } |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
1591 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1591 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1592 | 1592 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
1593 | 1593 | } |
1594 | 1594 | |
1595 | - $filter = $uuidAttr . '=' . $uuid; |
|
1595 | + $filter = $uuidAttr.'='.$uuid; |
|
1596 | 1596 | $result = $this->searchUsers($filter, ['dn'], 2); |
1597 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1597 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1598 | 1598 | // we put the count into account to make sure that this is |
1599 | 1599 | // really unique |
1600 | 1600 | return $result[0]['dn'][0]; |
@@ -1613,7 +1613,7 @@ discard block |
||
1613 | 1613 | * @return bool true on success, false otherwise |
1614 | 1614 | */ |
1615 | 1615 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
1616 | - if($isUser) { |
|
1616 | + if ($isUser) { |
|
1617 | 1617 | $uuidAttr = 'ldapUuidUserAttribute'; |
1618 | 1618 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1619 | 1619 | } else { |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
1622 | 1622 | } |
1623 | 1623 | |
1624 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1624 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1625 | 1625 | return true; |
1626 | 1626 | } |
1627 | 1627 | |
@@ -1630,10 +1630,10 @@ discard block |
||
1630 | 1630 | return true; |
1631 | 1631 | } |
1632 | 1632 | |
1633 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
1634 | - if($ldapRecord !== null) { |
|
1633 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
1634 | + if ($ldapRecord !== null) { |
|
1635 | 1635 | // we have the info from LDAP already, we don't need to talk to the server again |
1636 | - if(isset($ldapRecord[$attribute])) { |
|
1636 | + if (isset($ldapRecord[$attribute])) { |
|
1637 | 1637 | $this->connection->$uuidAttr = $attribute; |
1638 | 1638 | return true; |
1639 | 1639 | } else { |
@@ -1642,7 +1642,7 @@ discard block |
||
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | $value = $this->readAttribute($dn, $attribute); |
1645 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1645 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1646 | 1646 | \OCP\Util::writeLog( |
1647 | 1647 | 'user_ldap', |
1648 | 1648 | 'Setting '.$attribute.' as '.$uuidAttr, |
@@ -1668,7 +1668,7 @@ discard block |
||
1668 | 1668 | * @return bool|string |
1669 | 1669 | */ |
1670 | 1670 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
1671 | - if($isUser) { |
|
1671 | + if ($isUser) { |
|
1672 | 1672 | $uuidAttr = 'ldapUuidUserAttribute'; |
1673 | 1673 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1674 | 1674 | } else { |
@@ -1677,10 +1677,10 @@ discard block |
||
1677 | 1677 | } |
1678 | 1678 | |
1679 | 1679 | $uuid = false; |
1680 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
1680 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
1681 | 1681 | $attr = $this->connection->$uuidAttr; |
1682 | 1682 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
1683 | - if( !is_array($uuid) |
|
1683 | + if (!is_array($uuid) |
|
1684 | 1684 | && $uuidOverride !== '' |
1685 | 1685 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
1686 | 1686 | { |
@@ -1688,7 +1688,7 @@ discard block |
||
1688 | 1688 | ? $ldapRecord[$this->connection->$uuidAttr] |
1689 | 1689 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
1690 | 1690 | } |
1691 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1691 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1692 | 1692 | $uuid = $uuid[0]; |
1693 | 1693 | } |
1694 | 1694 | } |
@@ -1705,19 +1705,19 @@ discard block |
||
1705 | 1705 | private function convertObjectGUID2Str($oguid) { |
1706 | 1706 | $hex_guid = bin2hex($oguid); |
1707 | 1707 | $hex_guid_to_guid_str = ''; |
1708 | - for($k = 1; $k <= 4; ++$k) { |
|
1708 | + for ($k = 1; $k <= 4; ++$k) { |
|
1709 | 1709 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
1710 | 1710 | } |
1711 | 1711 | $hex_guid_to_guid_str .= '-'; |
1712 | - for($k = 1; $k <= 2; ++$k) { |
|
1712 | + for ($k = 1; $k <= 2; ++$k) { |
|
1713 | 1713 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
1714 | 1714 | } |
1715 | 1715 | $hex_guid_to_guid_str .= '-'; |
1716 | - for($k = 1; $k <= 2; ++$k) { |
|
1716 | + for ($k = 1; $k <= 2; ++$k) { |
|
1717 | 1717 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
1718 | 1718 | } |
1719 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
1720 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
1719 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
1720 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
1721 | 1721 | |
1722 | 1722 | return strtoupper($hex_guid_to_guid_str); |
1723 | 1723 | } |
@@ -1734,11 +1734,11 @@ discard block |
||
1734 | 1734 | * @return string |
1735 | 1735 | */ |
1736 | 1736 | public function formatGuid2ForFilterUser($guid) { |
1737 | - if(!is_string($guid)) { |
|
1737 | + if (!is_string($guid)) { |
|
1738 | 1738 | throw new \InvalidArgumentException('String expected'); |
1739 | 1739 | } |
1740 | 1740 | $blocks = explode('-', $guid); |
1741 | - if(count($blocks) !== 5) { |
|
1741 | + if (count($blocks) !== 5) { |
|
1742 | 1742 | /* |
1743 | 1743 | * Why not throw an Exception instead? This method is a utility |
1744 | 1744 | * called only when trying to figure out whether a "missing" known |
@@ -1751,20 +1751,20 @@ discard block |
||
1751 | 1751 | * user. Instead we write a log message. |
1752 | 1752 | */ |
1753 | 1753 | \OC::$server->getLogger()->info( |
1754 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
1754 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
1755 | 1755 | '({uuid}) probably does not match UUID configuration.', |
1756 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
1756 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
1757 | 1757 | ); |
1758 | 1758 | return $guid; |
1759 | 1759 | } |
1760 | - for($i=0; $i < 3; $i++) { |
|
1760 | + for ($i = 0; $i < 3; $i++) { |
|
1761 | 1761 | $pairs = str_split($blocks[$i], 2); |
1762 | 1762 | $pairs = array_reverse($pairs); |
1763 | 1763 | $blocks[$i] = implode('', $pairs); |
1764 | 1764 | } |
1765 | - for($i=0; $i < 5; $i++) { |
|
1765 | + for ($i = 0; $i < 5; $i++) { |
|
1766 | 1766 | $pairs = str_split($blocks[$i], 2); |
1767 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
1767 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
1768 | 1768 | } |
1769 | 1769 | return implode('', $blocks); |
1770 | 1770 | } |
@@ -1778,12 +1778,12 @@ discard block |
||
1778 | 1778 | $domainDN = $this->getDomainDNFromDN($dn); |
1779 | 1779 | $cacheKey = 'getSID-'.$domainDN; |
1780 | 1780 | $sid = $this->connection->getFromCache($cacheKey); |
1781 | - if(!is_null($sid)) { |
|
1781 | + if (!is_null($sid)) { |
|
1782 | 1782 | return $sid; |
1783 | 1783 | } |
1784 | 1784 | |
1785 | 1785 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
1786 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
1786 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
1787 | 1787 | $this->connection->writeToCache($cacheKey, false); |
1788 | 1788 | return false; |
1789 | 1789 | } |
@@ -1841,12 +1841,12 @@ discard block |
||
1841 | 1841 | $belongsToBase = false; |
1842 | 1842 | $bases = $this->helper->sanitizeDN($bases); |
1843 | 1843 | |
1844 | - foreach($bases as $base) { |
|
1844 | + foreach ($bases as $base) { |
|
1845 | 1845 | $belongsToBase = true; |
1846 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
1846 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
1847 | 1847 | $belongsToBase = false; |
1848 | 1848 | } |
1849 | - if($belongsToBase) { |
|
1849 | + if ($belongsToBase) { |
|
1850 | 1850 | break; |
1851 | 1851 | } |
1852 | 1852 | } |
@@ -1875,16 +1875,16 @@ discard block |
||
1875 | 1875 | * @return string containing the key or empty if none is cached |
1876 | 1876 | */ |
1877 | 1877 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
1878 | - if($offset === 0) { |
|
1878 | + if ($offset === 0) { |
|
1879 | 1879 | return ''; |
1880 | 1880 | } |
1881 | 1881 | $offset -= $limit; |
1882 | 1882 | //we work with cache here |
1883 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
1883 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
1884 | 1884 | $cookie = ''; |
1885 | - if(isset($this->cookies[$cacheKey])) { |
|
1885 | + if (isset($this->cookies[$cacheKey])) { |
|
1886 | 1886 | $cookie = $this->cookies[$cacheKey]; |
1887 | - if(is_null($cookie)) { |
|
1887 | + if (is_null($cookie)) { |
|
1888 | 1888 | $cookie = ''; |
1889 | 1889 | } |
1890 | 1890 | } |
@@ -1902,7 +1902,7 @@ discard block |
||
1902 | 1902 | * @return bool |
1903 | 1903 | */ |
1904 | 1904 | public function hasMoreResults() { |
1905 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1905 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1906 | 1906 | // as in RFC 2696, when all results are returned, the cookie will |
1907 | 1907 | // be empty. |
1908 | 1908 | return false; |
@@ -1922,8 +1922,8 @@ discard block |
||
1922 | 1922 | */ |
1923 | 1923 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
1924 | 1924 | // allow '0' for 389ds |
1925 | - if(!empty($cookie) || $cookie === '0') { |
|
1926 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
1925 | + if (!empty($cookie) || $cookie === '0') { |
|
1926 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
1927 | 1927 | $this->cookies[$cacheKey] = $cookie; |
1928 | 1928 | $this->lastCookie = $cookie; |
1929 | 1929 | } |
@@ -1951,16 +1951,16 @@ discard block |
||
1951 | 1951 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
1952 | 1952 | $pagedSearchOK = false; |
1953 | 1953 | if ($limit !== 0) { |
1954 | - $offset = (int)$offset; //can be null |
|
1954 | + $offset = (int) $offset; //can be null |
|
1955 | 1955 | \OCP\Util::writeLog('user_ldap', |
1956 | 1956 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
1957 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
1957 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
1958 | 1958 | ILogger::DEBUG); |
1959 | 1959 | //get the cookie from the search for the previous search, required by LDAP |
1960 | - foreach($bases as $base) { |
|
1960 | + foreach ($bases as $base) { |
|
1961 | 1961 | |
1962 | 1962 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
1963 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1963 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1964 | 1964 | // no cookie known from a potential previous search. We need |
1965 | 1965 | // to start from 0 to come to the desired page. cookie value |
1966 | 1966 | // of '0' is valid, because 389ds |
@@ -1970,17 +1970,17 @@ discard block |
||
1970 | 1970 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
1971 | 1971 | // '0' is valid, because 389ds |
1972 | 1972 | //TODO: remember this, probably does not change in the next request... |
1973 | - if(empty($cookie) && $cookie !== '0') { |
|
1973 | + if (empty($cookie) && $cookie !== '0') { |
|
1974 | 1974 | $cookie = null; |
1975 | 1975 | } |
1976 | 1976 | } |
1977 | - if(!is_null($cookie)) { |
|
1977 | + if (!is_null($cookie)) { |
|
1978 | 1978 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
1979 | 1979 | $this->abandonPagedSearch(); |
1980 | 1980 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
1981 | 1981 | $this->connection->getConnectionResource(), $limit, |
1982 | 1982 | false, $cookie); |
1983 | - if(!$pagedSearchOK) { |
|
1983 | + if (!$pagedSearchOK) { |
|
1984 | 1984 | return false; |
1985 | 1985 | } |
1986 | 1986 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG); |
@@ -2003,7 +2003,7 @@ discard block |
||
2003 | 2003 | $this->abandonPagedSearch(); |
2004 | 2004 | // in case someone set it to 0 … use 500, otherwise no results will |
2005 | 2005 | // be returned. |
2006 | - $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500; |
|
2006 | + $pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500; |
|
2007 | 2007 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
2008 | 2008 | $this->connection->getConnectionResource(), |
2009 | 2009 | $pageSize, false, ''); |