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