@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @return AbstractMapping |
113 | 113 | */ |
114 | 114 | public function getUserMapper() { |
115 | - if(is_null($this->userMapper)) { |
|
115 | + if (is_null($this->userMapper)) { |
|
116 | 116 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
117 | 117 | } |
118 | 118 | return $this->userMapper; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @return AbstractMapping |
133 | 133 | */ |
134 | 134 | public function getGroupMapper() { |
135 | - if(is_null($this->groupMapper)) { |
|
135 | + if (is_null($this->groupMapper)) { |
|
136 | 136 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
137 | 137 | } |
138 | 138 | return $this->groupMapper; |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | * array if $attr is empty, false otherwise |
164 | 164 | */ |
165 | 165 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
166 | - if(!$this->checkConnection()) { |
|
166 | + if (!$this->checkConnection()) { |
|
167 | 167 | \OCP\Util::writeLog('user_ldap', |
168 | 168 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
169 | 169 | \OCP\Util::WARN); |
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | $cr = $this->connection->getConnectionResource(); |
173 | - if(!$this->ldap->isResource($cr)) { |
|
173 | + if (!$this->ldap->isResource($cr)) { |
|
174 | 174 | //LDAP not available |
175 | 175 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
176 | 176 | return false; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $isRangeRequest = false; |
194 | 194 | do { |
195 | 195 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
196 | - if(is_bool($result)) { |
|
196 | + if (is_bool($result)) { |
|
197 | 197 | // when an exists request was run and it was successful, an empty |
198 | 198 | // array must be returned |
199 | 199 | return $result ? [] : false; |
@@ -210,22 +210,22 @@ discard block |
||
210 | 210 | $result = $this->extractRangeData($result, $attr); |
211 | 211 | if (!empty($result)) { |
212 | 212 | $normalizedResult = $this->extractAttributeValuesFromResult( |
213 | - [ $attr => $result['values'] ], |
|
213 | + [$attr => $result['values']], |
|
214 | 214 | $attr |
215 | 215 | ); |
216 | 216 | $values = array_merge($values, $normalizedResult); |
217 | 217 | |
218 | - if($result['rangeHigh'] === '*') { |
|
218 | + if ($result['rangeHigh'] === '*') { |
|
219 | 219 | // when server replies with * as high range value, there are |
220 | 220 | // no more results left |
221 | 221 | return $values; |
222 | 222 | } else { |
223 | - $low = $result['rangeHigh'] + 1; |
|
224 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
223 | + $low = $result['rangeHigh'] + 1; |
|
224 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
225 | 225 | $isRangeRequest = true; |
226 | 226 | } |
227 | 227 | } |
228 | - } while($isRangeRequest); |
|
228 | + } while ($isRangeRequest); |
|
229 | 229 | |
230 | 230 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); |
231 | 231 | return false; |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | if (!$this->ldap->isResource($rr)) { |
251 | 251 | if ($attribute !== '') { |
252 | 252 | //do not throw this message on userExists check, irritates |
253 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); |
|
253 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); |
|
254 | 254 | } |
255 | 255 | //in case an error occurs , e.g. object does not exist |
256 | 256 | return false; |
257 | 257 | } |
258 | 258 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
259 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); |
|
259 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG); |
|
260 | 260 | return true; |
261 | 261 | } |
262 | 262 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function extractAttributeValuesFromResult($result, $attribute) { |
283 | 283 | $values = []; |
284 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
284 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
285 | 285 | $lowercaseAttribute = strtolower($attribute); |
286 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
287 | - if($this->resemblesDN($attribute)) { |
|
286 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
287 | + if ($this->resemblesDN($attribute)) { |
|
288 | 288 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
289 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
289 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
290 | 290 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
291 | 291 | } else { |
292 | 292 | $values[] = $result[$attribute][$i]; |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function extractRangeData($result, $attribute) { |
310 | 310 | $keys = array_keys($result); |
311 | - foreach($keys as $key) { |
|
312 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
311 | + foreach ($keys as $key) { |
|
312 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
313 | 313 | $queryData = explode(';', $key); |
314 | - if(strpos($queryData[1], 'range=') === 0) { |
|
314 | + if (strpos($queryData[1], 'range=') === 0) { |
|
315 | 315 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
316 | 316 | $data = [ |
317 | 317 | 'values' => $result[$key], |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | * @throws \Exception |
337 | 337 | */ |
338 | 338 | public function setPassword($userDN, $password) { |
339 | - if(intval($this->connection->turnOnPasswordChange) !== 1) { |
|
339 | + if (intval($this->connection->turnOnPasswordChange) !== 1) { |
|
340 | 340 | throw new \Exception('LDAP password changes are disabled.'); |
341 | 341 | } |
342 | 342 | $cr = $this->connection->getConnectionResource(); |
343 | - if(!$this->ldap->isResource($cr)) { |
|
343 | + if (!$this->ldap->isResource($cr)) { |
|
344 | 344 | //LDAP not available |
345 | 345 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | try { |
349 | 349 | return $this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
350 | - } catch(ConstraintViolationException $e) { |
|
350 | + } catch (ConstraintViolationException $e) { |
|
351 | 351 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
352 | 352 | } |
353 | 353 | } |
@@ -389,17 +389,17 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function getDomainDNFromDN($dn) { |
391 | 391 | $allParts = $this->ldap->explodeDN($dn, 0); |
392 | - if($allParts === false) { |
|
392 | + if ($allParts === false) { |
|
393 | 393 | //not a valid DN |
394 | 394 | return ''; |
395 | 395 | } |
396 | 396 | $domainParts = array(); |
397 | 397 | $dcFound = false; |
398 | - foreach($allParts as $part) { |
|
399 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
398 | + foreach ($allParts as $part) { |
|
399 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
400 | 400 | $dcFound = true; |
401 | 401 | } |
402 | - if($dcFound) { |
|
402 | + if ($dcFound) { |
|
403 | 403 | $domainParts[] = $part; |
404 | 404 | } |
405 | 405 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | |
427 | 427 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
428 | 428 | //server setups |
429 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
429 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
430 | 430 | return $fdn; |
431 | 431 | } |
432 | 432 | |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | //To avoid bypassing the base DN settings under certain circumstances |
444 | 444 | //with the group support, check whether the provided DN matches one of |
445 | 445 | //the given Bases |
446 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
446 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
447 | 447 | return false; |
448 | 448 | } |
449 | 449 | |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | */ |
461 | 461 | public function groupsMatchFilter($groupDNs) { |
462 | 462 | $validGroupDNs = []; |
463 | - foreach($groupDNs as $dn) { |
|
463 | + foreach ($groupDNs as $dn) { |
|
464 | 464 | $cacheKey = 'groupsMatchFilter-'.$dn; |
465 | 465 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
466 | - if(!is_null($groupMatchFilter)) { |
|
467 | - if($groupMatchFilter) { |
|
466 | + if (!is_null($groupMatchFilter)) { |
|
467 | + if ($groupMatchFilter) { |
|
468 | 468 | $validGroupDNs[] = $dn; |
469 | 469 | } |
470 | 470 | continue; |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | |
473 | 473 | // Check the base DN first. If this is not met already, we don't |
474 | 474 | // need to ask the server at all. |
475 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
475 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
476 | 476 | $this->connection->writeToCache($cacheKey, false); |
477 | 477 | continue; |
478 | 478 | } |
479 | 479 | |
480 | 480 | $result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter); |
481 | - if(is_array($result)) { |
|
481 | + if (is_array($result)) { |
|
482 | 482 | $this->connection->writeToCache($cacheKey, true); |
483 | 483 | $validGroupDNs[] = $dn; |
484 | 484 | } else { |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | //To avoid bypassing the base DN settings under certain circumstances |
500 | 500 | //with the group support, check whether the provided DN matches one of |
501 | 501 | //the given Bases |
502 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
502 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
503 | 503 | return false; |
504 | 504 | } |
505 | 505 | |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | * @return string|false with with the name to use in Nextcloud |
515 | 515 | */ |
516 | 516 | public function dn2ocname($fdn, $ldapName = null, $isUser = true) { |
517 | - if($isUser) { |
|
517 | + if ($isUser) { |
|
518 | 518 | $mapper = $this->getUserMapper(); |
519 | 519 | $nameAttribute = $this->connection->ldapUserDisplayName; |
520 | 520 | } else { |
@@ -524,15 +524,15 @@ discard block |
||
524 | 524 | |
525 | 525 | //let's try to retrieve the Nextcloud name from the mappings table |
526 | 526 | $ocName = $mapper->getNameByDN($fdn); |
527 | - if(is_string($ocName)) { |
|
527 | + if (is_string($ocName)) { |
|
528 | 528 | return $ocName; |
529 | 529 | } |
530 | 530 | |
531 | 531 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
532 | 532 | $uuid = $this->getUUID($fdn, $isUser); |
533 | - if(is_string($uuid)) { |
|
533 | + if (is_string($uuid)) { |
|
534 | 534 | $ocName = $mapper->getNameByUUID($uuid); |
535 | - if(is_string($ocName)) { |
|
535 | + if (is_string($ocName)) { |
|
536 | 536 | $mapper->setDNbyUUID($fdn, $uuid); |
537 | 537 | return $ocName; |
538 | 538 | } |
@@ -542,16 +542,16 @@ discard block |
||
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | |
545 | - if(is_null($ldapName)) { |
|
545 | + if (is_null($ldapName)) { |
|
546 | 546 | $ldapName = $this->readAttribute($fdn, $nameAttribute); |
547 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
547 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
548 | 548 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO); |
549 | 549 | return false; |
550 | 550 | } |
551 | 551 | $ldapName = $ldapName[0]; |
552 | 552 | } |
553 | 553 | |
554 | - if($isUser) { |
|
554 | + if ($isUser) { |
|
555 | 555 | $usernameAttribute = strval($this->connection->ldapExpertUsernameAttr); |
556 | 556 | if ($usernameAttribute !== '') { |
557 | 557 | $username = $this->readAttribute($fdn, $usernameAttribute); |
@@ -570,9 +570,9 @@ discard block |
||
570 | 570 | // outside of core user management will still cache the user as non-existing. |
571 | 571 | $originalTTL = $this->connection->ldapCacheTTL; |
572 | 572 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
573 | - if(($isUser && !\OCP\User::userExists($intName)) |
|
573 | + if (($isUser && !\OCP\User::userExists($intName)) |
|
574 | 574 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { |
575 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
575 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
576 | 576 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
577 | 577 | return $intName; |
578 | 578 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
581 | 581 | |
582 | 582 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
583 | - if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
583 | + if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
584 | 584 | return $altName; |
585 | 585 | } |
586 | 586 | |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * @return array |
618 | 618 | */ |
619 | 619 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
620 | - if($isUsers) { |
|
620 | + if ($isUsers) { |
|
621 | 621 | $nameAttribute = $this->connection->ldapUserDisplayName; |
622 | 622 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
623 | 623 | } else { |
@@ -625,9 +625,9 @@ discard block |
||
625 | 625 | } |
626 | 626 | $nextcloudNames = array(); |
627 | 627 | |
628 | - foreach($ldapObjects as $ldapObject) { |
|
628 | + foreach ($ldapObjects as $ldapObject) { |
|
629 | 629 | $nameByLDAP = null; |
630 | - if( isset($ldapObject[$nameAttribute]) |
|
630 | + if (isset($ldapObject[$nameAttribute]) |
|
631 | 631 | && is_array($ldapObject[$nameAttribute]) |
632 | 632 | && isset($ldapObject[$nameAttribute][0]) |
633 | 633 | ) { |
@@ -636,12 +636,12 @@ discard block |
||
636 | 636 | } |
637 | 637 | |
638 | 638 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
639 | - if($ncName) { |
|
639 | + if ($ncName) { |
|
640 | 640 | $nextcloudNames[] = $ncName; |
641 | - if($isUsers) { |
|
641 | + if ($isUsers) { |
|
642 | 642 | //cache the user names so it does not need to be retrieved |
643 | 643 | //again later (e.g. sharing dialogue). |
644 | - if(is_null($nameByLDAP)) { |
|
644 | + if (is_null($nameByLDAP)) { |
|
645 | 645 | continue; |
646 | 646 | } |
647 | 647 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | */ |
680 | 680 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
681 | 681 | $user = $this->userManager->get($ocName); |
682 | - if($user === null) { |
|
682 | + if ($user === null) { |
|
683 | 683 | return; |
684 | 684 | } |
685 | 685 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | $attempts = 0; |
700 | 700 | //while loop is just a precaution. If a name is not generated within |
701 | 701 | //20 attempts, something else is very wrong. Avoids infinite loop. |
702 | - while($attempts < 20){ |
|
703 | - $altName = $name . '_' . rand(1000,9999); |
|
704 | - if(!\OCP\User::userExists($altName)) { |
|
702 | + while ($attempts < 20) { |
|
703 | + $altName = $name.'_'.rand(1000, 9999); |
|
704 | + if (!\OCP\User::userExists($altName)) { |
|
705 | 705 | return $altName; |
706 | 706 | } |
707 | 707 | $attempts++; |
@@ -723,25 +723,25 @@ discard block |
||
723 | 723 | */ |
724 | 724 | private function _createAltInternalOwnCloudNameForGroups($name) { |
725 | 725 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
726 | - if(!($usedNames) || count($usedNames) === 0) { |
|
726 | + if (!($usedNames) || count($usedNames) === 0) { |
|
727 | 727 | $lastNo = 1; //will become name_2 |
728 | 728 | } else { |
729 | 729 | natsort($usedNames); |
730 | 730 | $lastName = array_pop($usedNames); |
731 | 731 | $lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1)); |
732 | 732 | } |
733 | - $altName = $name.'_'.strval($lastNo+1); |
|
733 | + $altName = $name.'_'.strval($lastNo + 1); |
|
734 | 734 | unset($usedNames); |
735 | 735 | |
736 | 736 | $attempts = 1; |
737 | - while($attempts < 21){ |
|
737 | + while ($attempts < 21) { |
|
738 | 738 | // Check to be really sure it is unique |
739 | 739 | // while loop is just a precaution. If a name is not generated within |
740 | 740 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
741 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
741 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
742 | 742 | return $altName; |
743 | 743 | } |
744 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
744 | + $altName = $name.'_'.($lastNo + $attempts); |
|
745 | 745 | $attempts++; |
746 | 746 | } |
747 | 747 | return false; |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | private function createAltInternalOwnCloudName($name, $isUser) { |
757 | 757 | $originalTTL = $this->connection->ldapCacheTTL; |
758 | 758 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
759 | - if($isUser) { |
|
759 | + if ($isUser) { |
|
760 | 760 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
761 | 761 | } else { |
762 | 762 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -814,20 +814,20 @@ discard block |
||
814 | 814 | * and their values |
815 | 815 | * @param array $ldapRecords |
816 | 816 | */ |
817 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
817 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
818 | 818 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
819 | - foreach($ldapRecords as $userRecord) { |
|
820 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
819 | + foreach ($ldapRecords as $userRecord) { |
|
820 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
821 | 821 | // displayName is obligatory |
822 | 822 | continue; |
823 | 823 | } |
824 | - $ocName = $this->dn2ocname($userRecord['dn'][0]); |
|
825 | - if($ocName === false) { |
|
824 | + $ocName = $this->dn2ocname($userRecord['dn'][0]); |
|
825 | + if ($ocName === false) { |
|
826 | 826 | continue; |
827 | 827 | } |
828 | 828 | $this->cacheUserExists($ocName); |
829 | 829 | $user = $this->userManager->get($ocName); |
830 | - if($user instanceof OfflineUser) { |
|
830 | + if ($user instanceof OfflineUser) { |
|
831 | 831 | $user->unmark(); |
832 | 832 | $user = $this->userManager->get($ocName); |
833 | 833 | } |
@@ -859,8 +859,8 @@ discard block |
||
859 | 859 | * @return array |
860 | 860 | */ |
861 | 861 | private function fetchList($list, $manyAttributes) { |
862 | - if(is_array($list)) { |
|
863 | - if($manyAttributes) { |
|
862 | + if (is_array($list)) { |
|
863 | + if ($manyAttributes) { |
|
864 | 864 | return $list; |
865 | 865 | } else { |
866 | 866 | $list = array_reduce($list, function($carry, $item) { |
@@ -957,7 +957,7 @@ discard block |
||
957 | 957 | array_unshift($arguments, $cr); |
958 | 958 | // php no longer supports call-time pass-by-reference |
959 | 959 | // make special case for controlPagedResultResponse as the third argument is a reference |
960 | - $doMethod = function () use ($command, &$arguments) { |
|
960 | + $doMethod = function() use ($command, &$arguments) { |
|
961 | 961 | if ($command == 'controlPagedResultResponse') { |
962 | 962 | return $this->ldap->controlPagedResultResponse($arguments[0], $arguments[1], $arguments[2]); |
963 | 963 | } else { |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | $this->connection->resetConnectionResource(); |
976 | 976 | $cr = $this->connection->getConnectionResource(); |
977 | 977 | |
978 | - if(!$this->ldap->isResource($cr)) { |
|
978 | + if (!$this->ldap->isResource($cr)) { |
|
979 | 979 | // Seems like we didn't find any resource. |
980 | 980 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG); |
981 | 981 | throw $e; |
@@ -996,13 +996,13 @@ discard block |
||
996 | 996 | * @throws \OC\ServerNotAvailableException |
997 | 997 | */ |
998 | 998 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
999 | - if(!is_null($attr) && !is_array($attr)) { |
|
999 | + if (!is_null($attr) && !is_array($attr)) { |
|
1000 | 1000 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | // See if we have a resource, in case not cancel with message |
1004 | 1004 | $cr = $this->connection->getConnectionResource(); |
1005 | - if(!$this->ldap->isResource($cr)) { |
|
1005 | + if (!$this->ldap->isResource($cr)) { |
|
1006 | 1006 | // Seems like we didn't find any resource. |
1007 | 1007 | // Return an empty array just like before. |
1008 | 1008 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); |
@@ -1016,7 +1016,7 @@ discard block |
||
1016 | 1016 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
1017 | 1017 | // cannot use $cr anymore, might have changed in the previous call! |
1018 | 1018 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
1019 | - if(!is_array($sr) || $error !== 0) { |
|
1019 | + if (!is_array($sr) || $error !== 0) { |
|
1020 | 1020 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); |
1021 | 1021 | return false; |
1022 | 1022 | } |
@@ -1039,26 +1039,26 @@ discard block |
||
1039 | 1039 | */ |
1040 | 1040 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
1041 | 1041 | $cookie = null; |
1042 | - if($pagedSearchOK) { |
|
1042 | + if ($pagedSearchOK) { |
|
1043 | 1043 | $cr = $this->connection->getConnectionResource(); |
1044 | - foreach($sr as $key => $res) { |
|
1045 | - if($this->invokeLDAPMethod('controlPagedResultResponse', $cr, $res, $cookie)) { |
|
1044 | + foreach ($sr as $key => $res) { |
|
1045 | + if ($this->invokeLDAPMethod('controlPagedResultResponse', $cr, $res, $cookie)) { |
|
1046 | 1046 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | //browsing through prior pages to get the cookie for the new one |
1051 | - if($skipHandling) { |
|
1051 | + if ($skipHandling) { |
|
1052 | 1052 | return false; |
1053 | 1053 | } |
1054 | 1054 | // if count is bigger, then the server does not support |
1055 | 1055 | // paged search. Instead, he did a normal search. We set a |
1056 | 1056 | // flag here, so the callee knows how to deal with it. |
1057 | - if($iFoundItems <= $limit) { |
|
1057 | + if ($iFoundItems <= $limit) { |
|
1058 | 1058 | $this->pagedSearchedSuccessful = true; |
1059 | 1059 | } |
1060 | 1060 | } else { |
1061 | - if(!is_null($limit)) { |
|
1061 | + if (!is_null($limit)) { |
|
1062 | 1062 | \OCP\Util::writeLog('user_ldap', 'Paged search was not available', \OCP\Util::INFO); |
1063 | 1063 | } |
1064 | 1064 | } |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); |
1088 | 1088 | |
1089 | 1089 | $limitPerPage = intval($this->connection->ldapPagingSize); |
1090 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1090 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1091 | 1091 | $limitPerPage = $limit; |
1092 | 1092 | } |
1093 | 1093 | |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | do { |
1099 | 1099 | $search = $this->executeSearch($filter, $base, $attr, |
1100 | 1100 | $limitPerPage, $offset); |
1101 | - if($search === false) { |
|
1101 | + if ($search === false) { |
|
1102 | 1102 | return $counter > 0 ? $counter : false; |
1103 | 1103 | } |
1104 | 1104 | list($sr, $pagedSearchOK) = $search; |
@@ -1117,7 +1117,7 @@ discard block |
||
1117 | 1117 | * Continue now depends on $hasMorePages value |
1118 | 1118 | */ |
1119 | 1119 | $continue = $pagedSearchOK && $hasMorePages; |
1120 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1120 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1121 | 1121 | |
1122 | 1122 | return $counter; |
1123 | 1123 | } |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | private function countEntriesInSearchResults($searchResults) { |
1130 | 1130 | $counter = 0; |
1131 | 1131 | |
1132 | - foreach($searchResults as $res) { |
|
1132 | + foreach ($searchResults as $res) { |
|
1133 | 1133 | $count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res)); |
1134 | 1134 | $counter += $count; |
1135 | 1135 | } |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | * @return array with the search result |
1149 | 1149 | */ |
1150 | 1150 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1151 | - if($limit <= 0) { |
|
1151 | + if ($limit <= 0) { |
|
1152 | 1152 | //otherwise search will fail |
1153 | 1153 | $limit = null; |
1154 | 1154 | } |
@@ -1163,13 +1163,13 @@ discard block |
||
1163 | 1163 | $savedoffset = $offset; |
1164 | 1164 | do { |
1165 | 1165 | $search = $this->executeSearch($filter, $base, $attr, $limit, $offset); |
1166 | - if($search === false) { |
|
1166 | + if ($search === false) { |
|
1167 | 1167 | return array(); |
1168 | 1168 | } |
1169 | 1169 | list($sr, $pagedSearchOK) = $search; |
1170 | 1170 | $cr = $this->connection->getConnectionResource(); |
1171 | 1171 | |
1172 | - if($skipHandling) { |
|
1172 | + if ($skipHandling) { |
|
1173 | 1173 | //i.e. result do not need to be fetched, we just need the cookie |
1174 | 1174 | //thus pass 1 or any other value as $iFoundItems because it is not |
1175 | 1175 | //used |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | return array(); |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - foreach($sr as $res) { |
|
1182 | + foreach ($sr as $res) { |
|
1183 | 1183 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
1184 | 1184 | } |
1185 | 1185 | |
@@ -1193,25 +1193,25 @@ discard block |
||
1193 | 1193 | |
1194 | 1194 | // if we're here, probably no connection resource is returned. |
1195 | 1195 | // to make Nextcloud behave nicely, we simply give back an empty array. |
1196 | - if(is_null($findings)) { |
|
1196 | + if (is_null($findings)) { |
|
1197 | 1197 | return array(); |
1198 | 1198 | } |
1199 | 1199 | |
1200 | - if(!is_null($attr)) { |
|
1200 | + if (!is_null($attr)) { |
|
1201 | 1201 | $selection = array(); |
1202 | 1202 | $i = 0; |
1203 | - foreach($findings as $item) { |
|
1204 | - if(!is_array($item)) { |
|
1203 | + foreach ($findings as $item) { |
|
1204 | + if (!is_array($item)) { |
|
1205 | 1205 | continue; |
1206 | 1206 | } |
1207 | 1207 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
1208 | - foreach($attr as $key) { |
|
1208 | + foreach ($attr as $key) { |
|
1209 | 1209 | $key = mb_strtolower($key, 'UTF-8'); |
1210 | - if(isset($item[$key])) { |
|
1211 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1210 | + if (isset($item[$key])) { |
|
1211 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1212 | 1212 | unset($item[$key]['count']); |
1213 | 1213 | } |
1214 | - if($key !== 'dn') { |
|
1214 | + if ($key !== 'dn') { |
|
1215 | 1215 | $selection[$i][$key] = $this->resemblesDN($key) ? |
1216 | 1216 | $this->helper->sanitizeDN($item[$key]) |
1217 | 1217 | : $item[$key]; |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | //we slice the findings, when |
1229 | 1229 | //a) paged search unsuccessful, though attempted |
1230 | 1230 | //b) no paged search, but limit set |
1231 | - if((!$this->getPagedSearchResultState() |
|
1231 | + if ((!$this->getPagedSearchResultState() |
|
1232 | 1232 | && $pagedSearchOK) |
1233 | 1233 | || ( |
1234 | 1234 | !$pagedSearchOK |
@@ -1245,7 +1245,7 @@ discard block |
||
1245 | 1245 | * @return bool|mixed|string |
1246 | 1246 | */ |
1247 | 1247 | public function sanitizeUsername($name) { |
1248 | - if($this->connection->ldapIgnoreNamingRules) { |
|
1248 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
1249 | 1249 | return $name; |
1250 | 1250 | } |
1251 | 1251 | |
@@ -1270,13 +1270,13 @@ discard block |
||
1270 | 1270 | */ |
1271 | 1271 | public function escapeFilterPart($input, $allowAsterisk = false) { |
1272 | 1272 | $asterisk = ''; |
1273 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1273 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1274 | 1274 | $asterisk = '*'; |
1275 | 1275 | $input = mb_substr($input, 1, null, 'UTF-8'); |
1276 | 1276 | } |
1277 | 1277 | $search = array('*', '\\', '(', ')'); |
1278 | 1278 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
1279 | - return $asterisk . str_replace($search, $replace, $input); |
|
1279 | + return $asterisk.str_replace($search, $replace, $input); |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | /** |
@@ -1306,13 +1306,13 @@ discard block |
||
1306 | 1306 | */ |
1307 | 1307 | private function combineFilter($filters, $operator) { |
1308 | 1308 | $combinedFilter = '('.$operator; |
1309 | - foreach($filters as $filter) { |
|
1309 | + foreach ($filters as $filter) { |
|
1310 | 1310 | if ($filter !== '' && $filter[0] !== '(') { |
1311 | 1311 | $filter = '('.$filter.')'; |
1312 | 1312 | } |
1313 | - $combinedFilter.=$filter; |
|
1313 | + $combinedFilter .= $filter; |
|
1314 | 1314 | } |
1315 | - $combinedFilter.=')'; |
|
1315 | + $combinedFilter .= ')'; |
|
1316 | 1316 | return $combinedFilter; |
1317 | 1317 | } |
1318 | 1318 | |
@@ -1348,17 +1348,17 @@ discard block |
||
1348 | 1348 | * @throws \Exception |
1349 | 1349 | */ |
1350 | 1350 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
1351 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1351 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1352 | 1352 | throw new \Exception('searchAttributes must be an array with at least two string'); |
1353 | 1353 | } |
1354 | 1354 | $searchWords = explode(' ', trim($search)); |
1355 | 1355 | $wordFilters = array(); |
1356 | - foreach($searchWords as $word) { |
|
1356 | + foreach ($searchWords as $word) { |
|
1357 | 1357 | $word = $this->prepareSearchTerm($word); |
1358 | 1358 | //every word needs to appear at least once |
1359 | 1359 | $wordMatchOneAttrFilters = array(); |
1360 | - foreach($searchAttributes as $attr) { |
|
1361 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
1360 | + foreach ($searchAttributes as $attr) { |
|
1361 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
1362 | 1362 | } |
1363 | 1363 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
1364 | 1364 | } |
@@ -1376,10 +1376,10 @@ discard block |
||
1376 | 1376 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
1377 | 1377 | $filter = array(); |
1378 | 1378 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
1379 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1379 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1380 | 1380 | try { |
1381 | 1381 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
1382 | - } catch(\Exception $e) { |
|
1382 | + } catch (\Exception $e) { |
|
1383 | 1383 | \OCP\Util::writeLog( |
1384 | 1384 | 'user_ldap', |
1385 | 1385 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1389,17 +1389,17 @@ discard block |
||
1389 | 1389 | } |
1390 | 1390 | |
1391 | 1391 | $search = $this->prepareSearchTerm($search); |
1392 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1392 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1393 | 1393 | if ($fallbackAttribute === '') { |
1394 | 1394 | return ''; |
1395 | 1395 | } |
1396 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
1396 | + $filter[] = $fallbackAttribute.'='.$search; |
|
1397 | 1397 | } else { |
1398 | - foreach($searchAttributes as $attribute) { |
|
1399 | - $filter[] = $attribute . '=' . $search; |
|
1398 | + foreach ($searchAttributes as $attribute) { |
|
1399 | + $filter[] = $attribute.'='.$search; |
|
1400 | 1400 | } |
1401 | 1401 | } |
1402 | - if(count($filter) === 1) { |
|
1402 | + if (count($filter) === 1) { |
|
1403 | 1403 | return '('.$filter[0].')'; |
1404 | 1404 | } |
1405 | 1405 | return $this->combineFilterWithOr($filter); |
@@ -1420,7 +1420,7 @@ discard block |
||
1420 | 1420 | if ($term === '') { |
1421 | 1421 | $result = '*'; |
1422 | 1422 | } else if ($allowEnum !== 'no') { |
1423 | - $result = $term . '*'; |
|
1423 | + $result = $term.'*'; |
|
1424 | 1424 | } |
1425 | 1425 | return $result; |
1426 | 1426 | } |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | public function getFilterForUserCount() { |
1433 | 1433 | $filter = $this->combineFilterWithAnd(array( |
1434 | 1434 | $this->connection->ldapUserFilter, |
1435 | - $this->connection->ldapUserDisplayName . '=*' |
|
1435 | + $this->connection->ldapUserDisplayName.'=*' |
|
1436 | 1436 | )); |
1437 | 1437 | |
1438 | 1438 | return $filter; |
@@ -1450,7 +1450,7 @@ discard block |
||
1450 | 1450 | 'ldapAgentName' => $name, |
1451 | 1451 | 'ldapAgentPassword' => $password |
1452 | 1452 | ); |
1453 | - if(!$testConnection->setConfiguration($credentials)) { |
|
1453 | + if (!$testConnection->setConfiguration($credentials)) { |
|
1454 | 1454 | return false; |
1455 | 1455 | } |
1456 | 1456 | return $testConnection->bind(); |
@@ -1472,30 +1472,30 @@ discard block |
||
1472 | 1472 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
1473 | 1473 | // existing DN to be able to reliably detect it. |
1474 | 1474 | $result = $this->search($filter, $base, ['dn'], 1); |
1475 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1475 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1476 | 1476 | throw new \Exception('Cannot determine UUID attribute'); |
1477 | 1477 | } |
1478 | 1478 | $dn = $result[0]['dn'][0]; |
1479 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
1479 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
1480 | 1480 | throw new \Exception('Cannot determine UUID attribute'); |
1481 | 1481 | } |
1482 | 1482 | } else { |
1483 | 1483 | // The UUID attribute is either known or an override is given. |
1484 | 1484 | // By calling this method we ensure that $this->connection->$uuidAttr |
1485 | 1485 | // is definitely set |
1486 | - if(!$this->detectUuidAttribute('', true)) { |
|
1486 | + if (!$this->detectUuidAttribute('', true)) { |
|
1487 | 1487 | throw new \Exception('Cannot determine UUID attribute'); |
1488 | 1488 | } |
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
1492 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1492 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1493 | 1493 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
1494 | 1494 | } |
1495 | 1495 | |
1496 | - $filter = $uuidAttr . '=' . $uuid; |
|
1496 | + $filter = $uuidAttr.'='.$uuid; |
|
1497 | 1497 | $result = $this->searchUsers($filter, ['dn'], 2); |
1498 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1498 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1499 | 1499 | // we put the count into account to make sure that this is |
1500 | 1500 | // really unique |
1501 | 1501 | return $result[0]['dn'][0]; |
@@ -1512,7 +1512,7 @@ discard block |
||
1512 | 1512 | * @return bool true on success, false otherwise |
1513 | 1513 | */ |
1514 | 1514 | private function detectUuidAttribute($dn, $isUser = true, $force = false) { |
1515 | - if($isUser) { |
|
1515 | + if ($isUser) { |
|
1516 | 1516 | $uuidAttr = 'ldapUuidUserAttribute'; |
1517 | 1517 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1518 | 1518 | } else { |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
1521 | 1521 | } |
1522 | 1522 | |
1523 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1523 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1524 | 1524 | return true; |
1525 | 1525 | } |
1526 | 1526 | |
@@ -1532,9 +1532,9 @@ discard block |
||
1532 | 1532 | // for now, supported attributes are entryUUID, nsuniqueid, objectGUID, ipaUniqueID |
1533 | 1533 | $testAttributes = array('entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid'); |
1534 | 1534 | |
1535 | - foreach($testAttributes as $attribute) { |
|
1535 | + foreach ($testAttributes as $attribute) { |
|
1536 | 1536 | $value = $this->readAttribute($dn, $attribute); |
1537 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1537 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1538 | 1538 | \OCP\Util::writeLog('user_ldap', |
1539 | 1539 | 'Setting '.$attribute.' as '.$uuidAttr, |
1540 | 1540 | \OCP\Util::DEBUG); |
@@ -1555,7 +1555,7 @@ discard block |
||
1555 | 1555 | * @return string|bool |
1556 | 1556 | */ |
1557 | 1557 | public function getUUID($dn, $isUser = true) { |
1558 | - if($isUser) { |
|
1558 | + if ($isUser) { |
|
1559 | 1559 | $uuidAttr = 'ldapUuidUserAttribute'; |
1560 | 1560 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1561 | 1561 | } else { |
@@ -1564,15 +1564,15 @@ discard block |
||
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | $uuid = false; |
1567 | - if($this->detectUuidAttribute($dn, $isUser)) { |
|
1567 | + if ($this->detectUuidAttribute($dn, $isUser)) { |
|
1568 | 1568 | $uuid = $this->readAttribute($dn, $this->connection->$uuidAttr); |
1569 | - if( !is_array($uuid) |
|
1569 | + if (!is_array($uuid) |
|
1570 | 1570 | && $uuidOverride !== '' |
1571 | 1571 | && $this->detectUuidAttribute($dn, $isUser, true)) { |
1572 | 1572 | $uuid = $this->readAttribute($dn, |
1573 | 1573 | $this->connection->$uuidAttr); |
1574 | 1574 | } |
1575 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1575 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1576 | 1576 | $uuid = $uuid[0]; |
1577 | 1577 | } |
1578 | 1578 | } |
@@ -1589,19 +1589,19 @@ discard block |
||
1589 | 1589 | private function convertObjectGUID2Str($oguid) { |
1590 | 1590 | $hex_guid = bin2hex($oguid); |
1591 | 1591 | $hex_guid_to_guid_str = ''; |
1592 | - for($k = 1; $k <= 4; ++$k) { |
|
1592 | + for ($k = 1; $k <= 4; ++$k) { |
|
1593 | 1593 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
1594 | 1594 | } |
1595 | 1595 | $hex_guid_to_guid_str .= '-'; |
1596 | - for($k = 1; $k <= 2; ++$k) { |
|
1596 | + for ($k = 1; $k <= 2; ++$k) { |
|
1597 | 1597 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
1598 | 1598 | } |
1599 | 1599 | $hex_guid_to_guid_str .= '-'; |
1600 | - for($k = 1; $k <= 2; ++$k) { |
|
1600 | + for ($k = 1; $k <= 2; ++$k) { |
|
1601 | 1601 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
1602 | 1602 | } |
1603 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
1604 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
1603 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
1604 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
1605 | 1605 | |
1606 | 1606 | return strtoupper($hex_guid_to_guid_str); |
1607 | 1607 | } |
@@ -1618,11 +1618,11 @@ discard block |
||
1618 | 1618 | * @return string |
1619 | 1619 | */ |
1620 | 1620 | public function formatGuid2ForFilterUser($guid) { |
1621 | - if(!is_string($guid)) { |
|
1621 | + if (!is_string($guid)) { |
|
1622 | 1622 | throw new \InvalidArgumentException('String expected'); |
1623 | 1623 | } |
1624 | 1624 | $blocks = explode('-', $guid); |
1625 | - if(count($blocks) !== 5) { |
|
1625 | + if (count($blocks) !== 5) { |
|
1626 | 1626 | /* |
1627 | 1627 | * Why not throw an Exception instead? This method is a utility |
1628 | 1628 | * called only when trying to figure out whether a "missing" known |
@@ -1635,20 +1635,20 @@ discard block |
||
1635 | 1635 | * user. Instead we write a log message. |
1636 | 1636 | */ |
1637 | 1637 | \OC::$server->getLogger()->info( |
1638 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
1638 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
1639 | 1639 | '({uuid}) probably does not match UUID configuration.', |
1640 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
1640 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
1641 | 1641 | ); |
1642 | 1642 | return $guid; |
1643 | 1643 | } |
1644 | - for($i=0; $i < 3; $i++) { |
|
1644 | + for ($i = 0; $i < 3; $i++) { |
|
1645 | 1645 | $pairs = str_split($blocks[$i], 2); |
1646 | 1646 | $pairs = array_reverse($pairs); |
1647 | 1647 | $blocks[$i] = implode('', $pairs); |
1648 | 1648 | } |
1649 | - for($i=0; $i < 5; $i++) { |
|
1649 | + for ($i = 0; $i < 5; $i++) { |
|
1650 | 1650 | $pairs = str_split($blocks[$i], 2); |
1651 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
1651 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
1652 | 1652 | } |
1653 | 1653 | return implode('', $blocks); |
1654 | 1654 | } |
@@ -1662,12 +1662,12 @@ discard block |
||
1662 | 1662 | $domainDN = $this->getDomainDNFromDN($dn); |
1663 | 1663 | $cacheKey = 'getSID-'.$domainDN; |
1664 | 1664 | $sid = $this->connection->getFromCache($cacheKey); |
1665 | - if(!is_null($sid)) { |
|
1665 | + if (!is_null($sid)) { |
|
1666 | 1666 | return $sid; |
1667 | 1667 | } |
1668 | 1668 | |
1669 | 1669 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
1670 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
1670 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
1671 | 1671 | $this->connection->writeToCache($cacheKey, false); |
1672 | 1672 | return false; |
1673 | 1673 | } |
@@ -1725,12 +1725,12 @@ discard block |
||
1725 | 1725 | $belongsToBase = false; |
1726 | 1726 | $bases = $this->helper->sanitizeDN($bases); |
1727 | 1727 | |
1728 | - foreach($bases as $base) { |
|
1728 | + foreach ($bases as $base) { |
|
1729 | 1729 | $belongsToBase = true; |
1730 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
1730 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
1731 | 1731 | $belongsToBase = false; |
1732 | 1732 | } |
1733 | - if($belongsToBase) { |
|
1733 | + if ($belongsToBase) { |
|
1734 | 1734 | break; |
1735 | 1735 | } |
1736 | 1736 | } |
@@ -1741,7 +1741,7 @@ discard block |
||
1741 | 1741 | * resets a running Paged Search operation |
1742 | 1742 | */ |
1743 | 1743 | private function abandonPagedSearch() { |
1744 | - if($this->connection->hasPagedResultSupport) { |
|
1744 | + if ($this->connection->hasPagedResultSupport) { |
|
1745 | 1745 | $cr = $this->connection->getConnectionResource(); |
1746 | 1746 | $this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie); |
1747 | 1747 | $this->getPagedSearchResultState(); |
@@ -1759,16 +1759,16 @@ discard block |
||
1759 | 1759 | * @return string containing the key or empty if none is cached |
1760 | 1760 | */ |
1761 | 1761 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
1762 | - if($offset === 0) { |
|
1762 | + if ($offset === 0) { |
|
1763 | 1763 | return ''; |
1764 | 1764 | } |
1765 | 1765 | $offset -= $limit; |
1766 | 1766 | //we work with cache here |
1767 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); |
|
1767 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
1768 | 1768 | $cookie = ''; |
1769 | - if(isset($this->cookies[$cacheKey])) { |
|
1769 | + if (isset($this->cookies[$cacheKey])) { |
|
1770 | 1770 | $cookie = $this->cookies[$cacheKey]; |
1771 | - if(is_null($cookie)) { |
|
1771 | + if (is_null($cookie)) { |
|
1772 | 1772 | $cookie = ''; |
1773 | 1773 | } |
1774 | 1774 | } |
@@ -1786,11 +1786,11 @@ discard block |
||
1786 | 1786 | * @return bool |
1787 | 1787 | */ |
1788 | 1788 | public function hasMoreResults() { |
1789 | - if(!$this->connection->hasPagedResultSupport) { |
|
1789 | + if (!$this->connection->hasPagedResultSupport) { |
|
1790 | 1790 | return false; |
1791 | 1791 | } |
1792 | 1792 | |
1793 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1793 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1794 | 1794 | // as in RFC 2696, when all results are returned, the cookie will |
1795 | 1795 | // be empty. |
1796 | 1796 | return false; |
@@ -1810,8 +1810,8 @@ discard block |
||
1810 | 1810 | */ |
1811 | 1811 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
1812 | 1812 | // allow '0' for 389ds |
1813 | - if(!empty($cookie) || $cookie === '0') { |
|
1814 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); |
|
1813 | + if (!empty($cookie) || $cookie === '0') { |
|
1814 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
1815 | 1815 | $this->cookies[$cacheKey] = $cookie; |
1816 | 1816 | $this->lastCookie = $cookie; |
1817 | 1817 | } |
@@ -1838,17 +1838,17 @@ discard block |
||
1838 | 1838 | */ |
1839 | 1839 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
1840 | 1840 | $pagedSearchOK = false; |
1841 | - if($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
1841 | + if ($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
1842 | 1842 | $offset = intval($offset); //can be null |
1843 | 1843 | \OCP\Util::writeLog('user_ldap', |
1844 | 1844 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
1845 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
1845 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
1846 | 1846 | \OCP\Util::DEBUG); |
1847 | 1847 | //get the cookie from the search for the previous search, required by LDAP |
1848 | - foreach($bases as $base) { |
|
1848 | + foreach ($bases as $base) { |
|
1849 | 1849 | |
1850 | 1850 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
1851 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1851 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1852 | 1852 | // no cookie known, although the offset is not 0. Maybe cache run out. We need |
1853 | 1853 | // to start all over *sigh* (btw, Dear Reader, did you know LDAP paged |
1854 | 1854 | // searching was designed by MSFT?) |
@@ -1861,18 +1861,18 @@ discard block |
||
1861 | 1861 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
1862 | 1862 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
1863 | 1863 | //TODO: remember this, probably does not change in the next request... |
1864 | - if(empty($cookie) && $cookie !== '0') { |
|
1864 | + if (empty($cookie) && $cookie !== '0') { |
|
1865 | 1865 | // '0' is valid, because 389ds |
1866 | 1866 | $cookie = null; |
1867 | 1867 | } |
1868 | 1868 | } |
1869 | - if(!is_null($cookie)) { |
|
1869 | + if (!is_null($cookie)) { |
|
1870 | 1870 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
1871 | 1871 | $this->abandonPagedSearch(); |
1872 | 1872 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
1873 | 1873 | $this->connection->getConnectionResource(), $limit, |
1874 | 1874 | false, $cookie); |
1875 | - if(!$pagedSearchOK) { |
|
1875 | + if (!$pagedSearchOK) { |
|
1876 | 1876 | return false; |
1877 | 1877 | } |
1878 | 1878 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); |
@@ -1889,7 +1889,7 @@ discard block |
||
1889 | 1889 | * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination |
1890 | 1890 | * if we don't have a previous paged search. |
1891 | 1891 | */ |
1892 | - } else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
1892 | + } else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
1893 | 1893 | // a search without limit was requested. However, if we do use |
1894 | 1894 | // Paged Search once, we always must do it. This requires us to |
1895 | 1895 | // initialize it with the configured page size. |