Passed
Push — master ( aff53d...7aa76a )
by Morris
18:07
created
apps/user_ldap/lib/Access.php 1 patch
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return AbstractMapping
131 131
 	 */
132 132
 	public function getUserMapper() {
133
-		if(is_null($this->userMapper)) {
133
+		if (is_null($this->userMapper)) {
134 134
 			throw new \Exception('UserMapper was not assigned to this Access instance.');
135 135
 		}
136 136
 		return $this->userMapper;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @return AbstractMapping
151 151
 	 */
152 152
 	public function getGroupMapper() {
153
-		if(is_null($this->groupMapper)) {
153
+		if (is_null($this->groupMapper)) {
154 154
 			throw new \Exception('GroupMapper was not assigned to this Access instance.');
155 155
 		}
156 156
 		return $this->groupMapper;
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	 * @throws ServerNotAvailableException
184 184
 	 */
185 185
 	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
186
-		if(!$this->checkConnection()) {
186
+		if (!$this->checkConnection()) {
187 187
 			\OCP\Util::writeLog('user_ldap',
188 188
 				'No LDAP Connector assigned, access impossible for readAttribute.',
189 189
 				ILogger::WARN);
190 190
 			return false;
191 191
 		}
192 192
 		$cr = $this->connection->getConnectionResource();
193
-		if(!$this->ldap->isResource($cr)) {
193
+		if (!$this->ldap->isResource($cr)) {
194 194
 			//LDAP not available
195 195
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
196 196
 			return false;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 		$this->abandonPagedSearch();
201 201
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
202 202
 		// but does not hurt either.
203
-		$pagingSize = (int)$this->connection->ldapPagingSize;
203
+		$pagingSize = (int) $this->connection->ldapPagingSize;
204 204
 		// 0 won't result in replies, small numbers may leave out groups
205 205
 		// (cf. #12306), 500 is default for paging and should work everywhere.
206 206
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		$isRangeRequest = false;
214 214
 		do {
215 215
 			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
216
-			if(is_bool($result)) {
216
+			if (is_bool($result)) {
217 217
 				// when an exists request was run and it was successful, an empty
218 218
 				// array must be returned
219 219
 				return $result ? [] : false;
@@ -230,22 +230,22 @@  discard block
 block discarded – undo
230 230
 			$result = $this->extractRangeData($result, $attr);
231 231
 			if (!empty($result)) {
232 232
 				$normalizedResult = $this->extractAttributeValuesFromResult(
233
-					[ $attr => $result['values'] ],
233
+					[$attr => $result['values']],
234 234
 					$attr
235 235
 				);
236 236
 				$values = array_merge($values, $normalizedResult);
237 237
 
238
-				if($result['rangeHigh'] === '*') {
238
+				if ($result['rangeHigh'] === '*') {
239 239
 					// when server replies with * as high range value, there are
240 240
 					// no more results left
241 241
 					return $values;
242 242
 				} else {
243
-					$low  = $result['rangeHigh'] + 1;
244
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
243
+					$low = $result['rangeHigh'] + 1;
244
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
245 245
 					$isRangeRequest = true;
246 246
 				}
247 247
 			}
248
-		} while($isRangeRequest);
248
+		} while ($isRangeRequest);
249 249
 
250 250
 		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
251 251
 		return false;
@@ -271,13 +271,13 @@  discard block
 block discarded – undo
271 271
 		if (!$this->ldap->isResource($rr)) {
272 272
 			if ($attribute !== '') {
273 273
 				//do not throw this message on userExists check, irritates
274
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
274
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG);
275 275
 			}
276 276
 			//in case an error occurs , e.g. object does not exist
277 277
 			return false;
278 278
 		}
279 279
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
280
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
280
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG);
281 281
 			return true;
282 282
 		}
283 283
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -302,12 +302,12 @@  discard block
 block discarded – undo
302 302
 	 */
303 303
 	public function extractAttributeValuesFromResult($result, $attribute) {
304 304
 		$values = [];
305
-		if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
305
+		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
306 306
 			$lowercaseAttribute = strtolower($attribute);
307
-			for($i=0;$i<$result[$attribute]['count'];$i++) {
308
-				if($this->resemblesDN($attribute)) {
307
+			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
308
+				if ($this->resemblesDN($attribute)) {
309 309
 					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
310
-				} elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
310
+				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
311 311
 					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
312 312
 				} else {
313 313
 					$values[] = $result[$attribute][$i];
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 	 */
330 330
 	public function extractRangeData($result, $attribute) {
331 331
 		$keys = array_keys($result);
332
-		foreach($keys as $key) {
333
-			if($key !== $attribute && strpos($key, $attribute) === 0) {
332
+		foreach ($keys as $key) {
333
+			if ($key !== $attribute && strpos($key, $attribute) === 0) {
334 334
 				$queryData = explode(';', $key);
335
-				if(strpos($queryData[1], 'range=') === 0) {
335
+				if (strpos($queryData[1], 'range=') === 0) {
336 336
 					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
337 337
 					$data = [
338 338
 						'values' => $result[$key],
@@ -357,18 +357,18 @@  discard block
 block discarded – undo
357 357
 	 * @throws \Exception
358 358
 	 */
359 359
 	public function setPassword($userDN, $password) {
360
-		if((int)$this->connection->turnOnPasswordChange !== 1) {
360
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
361 361
 			throw new \Exception('LDAP password changes are disabled.');
362 362
 		}
363 363
 		$cr = $this->connection->getConnectionResource();
364
-		if(!$this->ldap->isResource($cr)) {
364
+		if (!$this->ldap->isResource($cr)) {
365 365
 			//LDAP not available
366 366
 			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
367 367
 			return false;
368 368
 		}
369 369
 		try {
370 370
 			return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
371
-		} catch(ConstraintViolationException $e) {
371
+		} catch (ConstraintViolationException $e) {
372 372
 			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
373 373
 		}
374 374
 	}
@@ -410,17 +410,17 @@  discard block
 block discarded – undo
410 410
 	 */
411 411
 	public function getDomainDNFromDN($dn) {
412 412
 		$allParts = $this->ldap->explodeDN($dn, 0);
413
-		if($allParts === false) {
413
+		if ($allParts === false) {
414 414
 			//not a valid DN
415 415
 			return '';
416 416
 		}
417 417
 		$domainParts = array();
418 418
 		$dcFound = false;
419
-		foreach($allParts as $part) {
420
-			if(!$dcFound && strpos($part, 'dc=') === 0) {
419
+		foreach ($allParts as $part) {
420
+			if (!$dcFound && strpos($part, 'dc=') === 0) {
421 421
 				$dcFound = true;
422 422
 			}
423
-			if($dcFound) {
423
+			if ($dcFound) {
424 424
 				$domainParts[] = $part;
425 425
 			}
426 426
 		}
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
 		//Check whether the DN belongs to the Base, to avoid issues on multi-
448 448
 		//server setups
449
-		if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
449
+		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
450 450
 			return $fdn;
451 451
 		}
452 452
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 		//To avoid bypassing the base DN settings under certain circumstances
464 464
 		//with the group support, check whether the provided DN matches one of
465 465
 		//the given Bases
466
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
466
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
467 467
 			return false;
468 468
 		}
469 469
 
@@ -481,11 +481,11 @@  discard block
 block discarded – undo
481 481
 	 */
482 482
 	public function groupsMatchFilter($groupDNs) {
483 483
 		$validGroupDNs = [];
484
-		foreach($groupDNs as $dn) {
484
+		foreach ($groupDNs as $dn) {
485 485
 			$cacheKey = 'groupsMatchFilter-'.$dn;
486 486
 			$groupMatchFilter = $this->connection->getFromCache($cacheKey);
487
-			if(!is_null($groupMatchFilter)) {
488
-				if($groupMatchFilter) {
487
+			if (!is_null($groupMatchFilter)) {
488
+				if ($groupMatchFilter) {
489 489
 					$validGroupDNs[] = $dn;
490 490
 				}
491 491
 				continue;
@@ -493,13 +493,13 @@  discard block
 block discarded – undo
493 493
 
494 494
 			// Check the base DN first. If this is not met already, we don't
495 495
 			// need to ask the server at all.
496
-			if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
496
+			if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) {
497 497
 				$this->connection->writeToCache($cacheKey, false);
498 498
 				continue;
499 499
 			}
500 500
 
501 501
 			$result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter);
502
-			if(is_array($result)) {
502
+			if (is_array($result)) {
503 503
 				$this->connection->writeToCache($cacheKey, true);
504 504
 				$validGroupDNs[] = $dn;
505 505
 			} else {
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 		//To avoid bypassing the base DN settings under certain circumstances
521 521
 		//with the group support, check whether the provided DN matches one of
522 522
 		//the given Bases
523
-		if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
523
+		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
524 524
 			return false;
525 525
 		}
526 526
 
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 	 */
541 541
 	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
542 542
 		$newlyMapped = false;
543
-		if($isUser) {
543
+		if ($isUser) {
544 544
 			$mapper = $this->getUserMapper();
545 545
 			$nameAttribute = $this->connection->ldapUserDisplayName;
546 546
 			$filter = $this->connection->ldapUserFilter;
@@ -552,15 +552,15 @@  discard block
 block discarded – undo
552 552
 
553 553
 		//let's try to retrieve the Nextcloud name from the mappings table
554 554
 		$ncName = $mapper->getNameByDN($fdn);
555
-		if(is_string($ncName)) {
555
+		if (is_string($ncName)) {
556 556
 			return $ncName;
557 557
 		}
558 558
 
559 559
 		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
560 560
 		$uuid = $this->getUUID($fdn, $isUser, $record);
561
-		if(is_string($uuid)) {
561
+		if (is_string($uuid)) {
562 562
 			$ncName = $mapper->getNameByUUID($uuid);
563
-			if(is_string($ncName)) {
563
+			if (is_string($ncName)) {
564 564
 				$mapper->setDNbyUUID($fdn, $uuid);
565 565
 				return $ncName;
566 566
 			}
@@ -570,17 +570,17 @@  discard block
 block discarded – undo
570 570
 			return false;
571 571
 		}
572 572
 
573
-		if(is_null($ldapName)) {
573
+		if (is_null($ldapName)) {
574 574
 			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
575
-			if(!isset($ldapName[0]) && empty($ldapName[0])) {
575
+			if (!isset($ldapName[0]) && empty($ldapName[0])) {
576 576
 				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO);
577 577
 				return false;
578 578
 			}
579 579
 			$ldapName = $ldapName[0];
580 580
 		}
581 581
 
582
-		if($isUser) {
583
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
582
+		if ($isUser) {
583
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
584 584
 			if ($usernameAttribute !== '') {
585 585
 				$username = $this->readAttribute($fdn, $usernameAttribute);
586 586
 				$username = $username[0];
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
 		// outside of core user management will still cache the user as non-existing.
611 611
 		$originalTTL = $this->connection->ldapCacheTTL;
612 612
 		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
613
-		if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
613
+		if (($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
614 614
 			|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
615
-			if($mapper->map($fdn, $intName, $uuid)) {
615
+			if ($mapper->map($fdn, $intName, $uuid)) {
616 616
 				$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
617
-				if($this->ncUserManager instanceof PublicEmitter && $isUser) {
617
+				if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
618 618
 					$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
619 619
 				}
620 620
 				$newlyMapped = true;
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
625 625
 
626 626
 		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
627
-		if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
628
-			if($this->ncUserManager instanceof PublicEmitter && $isUser) {
627
+		if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
628
+			if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
629 629
 				$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
630 630
 			}
631 631
 			$newlyMapped = true;
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 * @throws \Exception
667 667
 	 */
668 668
 	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
669
-		if($isUsers) {
669
+		if ($isUsers) {
670 670
 			$nameAttribute = $this->connection->ldapUserDisplayName;
671 671
 			$sndAttribute  = $this->connection->ldapUserDisplayName2;
672 672
 		} else {
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 		}
675 675
 		$nextcloudNames = [];
676 676
 
677
-		foreach($ldapObjects as $ldapObject) {
677
+		foreach ($ldapObjects as $ldapObject) {
678 678
 			$nameByLDAP = null;
679
-			if(    isset($ldapObject[$nameAttribute])
679
+			if (isset($ldapObject[$nameAttribute])
680 680
 				&& is_array($ldapObject[$nameAttribute])
681 681
 				&& isset($ldapObject[$nameAttribute][0])
682 682
 			) {
@@ -685,13 +685,13 @@  discard block
 block discarded – undo
685 685
 			}
686 686
 
687 687
 			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
688
-			if($ncName) {
688
+			if ($ncName) {
689 689
 				$nextcloudNames[] = $ncName;
690
-				if($isUsers) {
690
+				if ($isUsers) {
691 691
 					$this->updateUserState($ncName);
692 692
 					//cache the user names so it does not need to be retrieved
693 693
 					//again later (e.g. sharing dialogue).
694
-					if(is_null($nameByLDAP)) {
694
+					if (is_null($nameByLDAP)) {
695 695
 						continue;
696 696
 					}
697 697
 					$sndName = isset($ldapObject[$sndAttribute][0])
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
 	public function updateUserState($ncname) {
713 713
 		$user = $this->userManager->get($ncname);
714
-		if($user instanceof OfflineUser) {
714
+		if ($user instanceof OfflineUser) {
715 715
 			$user->unmark();
716 716
 		}
717 717
 	}
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 	 */
743 743
 	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
744 744
 		$user = $this->userManager->get($ocName);
745
-		if($user === null) {
745
+		if ($user === null) {
746 746
 			return;
747 747
 		}
748 748
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 		$attempts = 0;
763 763
 		//while loop is just a precaution. If a name is not generated within
764 764
 		//20 attempts, something else is very wrong. Avoids infinite loop.
765
-		while($attempts < 20){
766
-			$altName = $name . '_' . rand(1000,9999);
767
-			if(!$this->ncUserManager->userExists($altName)) {
765
+		while ($attempts < 20) {
766
+			$altName = $name.'_'.rand(1000, 9999);
767
+			if (!$this->ncUserManager->userExists($altName)) {
768 768
 				return $altName;
769 769
 			}
770 770
 			$attempts++;
@@ -786,25 +786,25 @@  discard block
 block discarded – undo
786 786
 	 */
787 787
 	private function _createAltInternalOwnCloudNameForGroups($name) {
788 788
 		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
789
-		if(!$usedNames || count($usedNames) === 0) {
789
+		if (!$usedNames || count($usedNames) === 0) {
790 790
 			$lastNo = 1; //will become name_2
791 791
 		} else {
792 792
 			natsort($usedNames);
793 793
 			$lastName = array_pop($usedNames);
794
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
794
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
795 795
 		}
796
-		$altName = $name.'_'. (string)($lastNo+1);
796
+		$altName = $name.'_'.(string) ($lastNo + 1);
797 797
 		unset($usedNames);
798 798
 
799 799
 		$attempts = 1;
800
-		while($attempts < 21){
800
+		while ($attempts < 21) {
801 801
 			// Check to be really sure it is unique
802 802
 			// while loop is just a precaution. If a name is not generated within
803 803
 			// 20 attempts, something else is very wrong. Avoids infinite loop.
804
-			if(!\OC::$server->getGroupManager()->groupExists($altName)) {
804
+			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
805 805
 				return $altName;
806 806
 			}
807
-			$altName = $name . '_' . ($lastNo + $attempts);
807
+			$altName = $name.'_'.($lastNo + $attempts);
808 808
 			$attempts++;
809 809
 		}
810 810
 		return false;
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	private function createAltInternalOwnCloudName($name, $isUser) {
820 820
 		$originalTTL = $this->connection->ldapCacheTTL;
821 821
 		$this->connection->setConfiguration(array('ldapCacheTTL' => 0));
822
-		if($isUser) {
822
+		if ($isUser) {
823 823
 			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
824 824
 		} else {
825 825
 			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
@@ -867,13 +867,13 @@  discard block
 block discarded – undo
867 867
 	public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) {
868 868
 		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
869 869
 		$recordsToUpdate = $ldapRecords;
870
-		if(!$forceApplyAttributes) {
870
+		if (!$forceApplyAttributes) {
871 871
 			$isBackgroundJobModeAjax = $this->config
872 872
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
873 873
 			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) {
874 874
 				$newlyMapped = false;
875 875
 				$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
876
-				if(is_string($uid)) {
876
+				if (is_string($uid)) {
877 877
 					$this->cacheUserExists($uid);
878 878
 				}
879 879
 				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
@@ -891,15 +891,15 @@  discard block
 block discarded – undo
891 891
 	 * @param array $ldapRecords
892 892
 	 * @throws \Exception
893 893
 	 */
894
-	public function batchApplyUserAttributes(array $ldapRecords){
894
+	public function batchApplyUserAttributes(array $ldapRecords) {
895 895
 		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
896
-		foreach($ldapRecords as $userRecord) {
897
-			if(!isset($userRecord[$displayNameAttribute])) {
896
+		foreach ($ldapRecords as $userRecord) {
897
+			if (!isset($userRecord[$displayNameAttribute])) {
898 898
 				// displayName is obligatory
899 899
 				continue;
900 900
 			}
901
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], null, true);
902
-			if($ocName === false) {
901
+			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
902
+			if ($ocName === false) {
903 903
 				continue;
904 904
 			}
905 905
 			$this->updateUserState($ocName);
@@ -932,8 +932,8 @@  discard block
 block discarded – undo
932 932
 	 * @return array
933 933
 	 */
934 934
 	private function fetchList($list, $manyAttributes) {
935
-		if(is_array($list)) {
936
-			if($manyAttributes) {
935
+		if (is_array($list)) {
936
+			if ($manyAttributes) {
937 937
 				return $list;
938 938
 			} else {
939 939
 				$list = array_reduce($list, function($carry, $item) {
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 		// php no longer supports call-time pass-by-reference
1032 1032
 		// thus cannot support controlPagedResultResponse as the third argument
1033 1033
 		// is a reference
1034
-		$doMethod = function () use ($command, &$arguments) {
1034
+		$doMethod = function() use ($command, &$arguments) {
1035 1035
 			if ($command == 'controlPagedResultResponse') {
1036 1036
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1037 1037
 			} else {
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 			$this->connection->resetConnectionResource();
1050 1050
 			$cr = $this->connection->getConnectionResource();
1051 1051
 
1052
-			if(!$this->ldap->isResource($cr)) {
1052
+			if (!$this->ldap->isResource($cr)) {
1053 1053
 				// Seems like we didn't find any resource.
1054 1054
 				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1055 1055
 				throw $e;
@@ -1074,13 +1074,13 @@  discard block
 block discarded – undo
1074 1074
 	 * @throws ServerNotAvailableException
1075 1075
 	 */
1076 1076
 	private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) {
1077
-		if(!is_null($attr) && !is_array($attr)) {
1077
+		if (!is_null($attr) && !is_array($attr)) {
1078 1078
 			$attr = array(mb_strtolower($attr, 'UTF-8'));
1079 1079
 		}
1080 1080
 
1081 1081
 		// See if we have a resource, in case not cancel with message
1082 1082
 		$cr = $this->connection->getConnectionResource();
1083
-		if(!$this->ldap->isResource($cr)) {
1083
+		if (!$this->ldap->isResource($cr)) {
1084 1084
 			// Seems like we didn't find any resource.
1085 1085
 			// Return an empty array just like before.
1086 1086
 			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
@@ -1088,13 +1088,13 @@  discard block
 block discarded – undo
1088 1088
 		}
1089 1089
 
1090 1090
 		//check whether paged search should be attempted
1091
-		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
1091
+		$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset);
1092 1092
 
1093 1093
 		$linkResources = array_pad(array(), count($base), $cr);
1094 1094
 		$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
1095 1095
 		// cannot use $cr anymore, might have changed in the previous call!
1096 1096
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1097
-		if(!is_array($sr) || $error !== 0) {
1097
+		if (!is_array($sr) || $error !== 0) {
1098 1098
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), ILogger::ERROR);
1099 1099
 			return false;
1100 1100
 		}
@@ -1117,29 +1117,29 @@  discard block
 block discarded – undo
1117 1117
 	 */
1118 1118
 	private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) {
1119 1119
 		$cookie = null;
1120
-		if($pagedSearchOK) {
1120
+		if ($pagedSearchOK) {
1121 1121
 			$cr = $this->connection->getConnectionResource();
1122
-			foreach($sr as $key => $res) {
1123
-				if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1122
+			foreach ($sr as $key => $res) {
1123
+				if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) {
1124 1124
 					$this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie);
1125 1125
 				}
1126 1126
 			}
1127 1127
 
1128 1128
 			//browsing through prior pages to get the cookie for the new one
1129
-			if($skipHandling) {
1129
+			if ($skipHandling) {
1130 1130
 				return false;
1131 1131
 			}
1132 1132
 			// if count is bigger, then the server does not support
1133 1133
 			// paged search. Instead, he did a normal search. We set a
1134 1134
 			// flag here, so the callee knows how to deal with it.
1135
-			if($iFoundItems <= $limit) {
1135
+			if ($iFoundItems <= $limit) {
1136 1136
 				$this->pagedSearchedSuccessful = true;
1137 1137
 			}
1138 1138
 		} else {
1139
-			if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1139
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1140 1140
 				\OC::$server->getLogger()->debug(
1141 1141
 					'Paged search was not available',
1142
-					[ 'app' => 'user_ldap' ]
1142
+					['app' => 'user_ldap']
1143 1143
 				);
1144 1144
 			}
1145 1145
 		}
@@ -1168,8 +1168,8 @@  discard block
 block discarded – undo
1168 1168
 	private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1169 1169
 		\OCP\Util::writeLog('user_ldap', 'Count filter:  '.print_r($filter, true), ILogger::DEBUG);
1170 1170
 
1171
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1172
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1171
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1172
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1173 1173
 			$limitPerPage = $limit;
1174 1174
 		}
1175 1175
 
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
 		do {
1181 1181
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1182
-			if($search === false) {
1182
+			if ($search === false) {
1183 1183
 				return $counter > 0 ? $counter : false;
1184 1184
 			}
1185 1185
 			list($sr, $pagedSearchOK) = $search;
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 			 * Continue now depends on $hasMorePages value
1199 1199
 			 */
1200 1200
 			$continue = $pagedSearchOK && $hasMorePages;
1201
-		} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1201
+		} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1202 1202
 
1203 1203
 		return $counter;
1204 1204
 	}
@@ -1210,8 +1210,8 @@  discard block
 block discarded – undo
1210 1210
 	private function countEntriesInSearchResults($searchResults) {
1211 1211
 		$counter = 0;
1212 1212
 
1213
-		foreach($searchResults as $res) {
1214
-			$count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1213
+		foreach ($searchResults as $res) {
1214
+			$count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
1215 1215
 			$counter += $count;
1216 1216
 		}
1217 1217
 
@@ -1231,8 +1231,8 @@  discard block
 block discarded – undo
1231 1231
 	 * @throws ServerNotAvailableException
1232 1232
 	 */
1233 1233
 	public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
1234
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1235
-		if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1234
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1235
+		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1236 1236
 			$limitPerPage = $limit;
1237 1237
 		}
1238 1238
 
@@ -1246,13 +1246,13 @@  discard block
 block discarded – undo
1246 1246
 		$savedoffset = $offset;
1247 1247
 		do {
1248 1248
 			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1249
-			if($search === false) {
1249
+			if ($search === false) {
1250 1250
 				return [];
1251 1251
 			}
1252 1252
 			list($sr, $pagedSearchOK) = $search;
1253 1253
 			$cr = $this->connection->getConnectionResource();
1254 1254
 
1255
-			if($skipHandling) {
1255
+			if ($skipHandling) {
1256 1256
 				//i.e. result do not need to be fetched, we just need the cookie
1257 1257
 				//thus pass 1 or any other value as $iFoundItems because it is not
1258 1258
 				//used
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 			}
1264 1264
 
1265 1265
 			$iFoundItems = 0;
1266
-			foreach($sr as $res) {
1266
+			foreach ($sr as $res) {
1267 1267
 				$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res));
1268 1268
 				$iFoundItems = max($iFoundItems, $findings['count']);
1269 1269
 				unset($findings['count']);
@@ -1279,27 +1279,27 @@  discard block
 block discarded – undo
1279 1279
 
1280 1280
 		// if we're here, probably no connection resource is returned.
1281 1281
 		// to make Nextcloud behave nicely, we simply give back an empty array.
1282
-		if(is_null($findings)) {
1282
+		if (is_null($findings)) {
1283 1283
 			return array();
1284 1284
 		}
1285 1285
 
1286
-		if(!is_null($attr)) {
1286
+		if (!is_null($attr)) {
1287 1287
 			$selection = [];
1288 1288
 			$i = 0;
1289
-			foreach($findings as $item) {
1290
-				if(!is_array($item)) {
1289
+			foreach ($findings as $item) {
1290
+				if (!is_array($item)) {
1291 1291
 					continue;
1292 1292
 				}
1293 1293
 				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1294
-				foreach($attr as $key) {
1295
-					if(isset($item[$key])) {
1296
-						if(is_array($item[$key]) && isset($item[$key]['count'])) {
1294
+				foreach ($attr as $key) {
1295
+					if (isset($item[$key])) {
1296
+						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1297 1297
 							unset($item[$key]['count']);
1298 1298
 						}
1299
-						if($key !== 'dn') {
1300
-							if($this->resemblesDN($key)) {
1299
+						if ($key !== 'dn') {
1300
+							if ($this->resemblesDN($key)) {
1301 1301
 								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1302
-							} else if($key === 'objectguid' || $key === 'guid') {
1302
+							} else if ($key === 'objectguid' || $key === 'guid') {
1303 1303
 								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1304 1304
 							} else {
1305 1305
 								$selection[$i][$key] = $item[$key];
@@ -1317,14 +1317,14 @@  discard block
 block discarded – undo
1317 1317
 		//we slice the findings, when
1318 1318
 		//a) paged search unsuccessful, though attempted
1319 1319
 		//b) no paged search, but limit set
1320
-		if((!$this->getPagedSearchResultState()
1320
+		if ((!$this->getPagedSearchResultState()
1321 1321
 			&& $pagedSearchOK)
1322 1322
 			|| (
1323 1323
 				!$pagedSearchOK
1324 1324
 				&& !is_null($limit)
1325 1325
 			)
1326 1326
 		) {
1327
-			$findings = array_slice($findings, (int)$offset, $limit);
1327
+			$findings = array_slice($findings, (int) $offset, $limit);
1328 1328
 		}
1329 1329
 		return $findings;
1330 1330
 	}
@@ -1337,13 +1337,13 @@  discard block
 block discarded – undo
1337 1337
 	public function sanitizeUsername($name) {
1338 1338
 		$name = trim($name);
1339 1339
 
1340
-		if($this->connection->ldapIgnoreNamingRules) {
1340
+		if ($this->connection->ldapIgnoreNamingRules) {
1341 1341
 			return $name;
1342 1342
 		}
1343 1343
 
1344 1344
 		// Transliteration to ASCII
1345 1345
 		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1346
-		if($transliterated !== false) {
1346
+		if ($transliterated !== false) {
1347 1347
 			// depending on system config iconv can work or not
1348 1348
 			$name = $transliterated;
1349 1349
 		}
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 		// Every remaining disallowed characters will be removed
1355 1355
 		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1356 1356
 
1357
-		if($name === '') {
1357
+		if ($name === '') {
1358 1358
 			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1359 1359
 		}
1360 1360
 
@@ -1369,13 +1369,13 @@  discard block
 block discarded – undo
1369 1369
 	*/
1370 1370
 	public function escapeFilterPart($input, $allowAsterisk = false) {
1371 1371
 		$asterisk = '';
1372
-		if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1372
+		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1373 1373
 			$asterisk = '*';
1374 1374
 			$input = mb_substr($input, 1, null, 'UTF-8');
1375 1375
 		}
1376 1376
 		$search  = array('*', '\\', '(', ')');
1377 1377
 		$replace = array('\\*', '\\\\', '\\(', '\\)');
1378
-		return $asterisk . str_replace($search, $replace, $input);
1378
+		return $asterisk.str_replace($search, $replace, $input);
1379 1379
 	}
1380 1380
 
1381 1381
 	/**
@@ -1405,13 +1405,13 @@  discard block
 block discarded – undo
1405 1405
 	 */
1406 1406
 	private function combineFilter($filters, $operator) {
1407 1407
 		$combinedFilter = '('.$operator;
1408
-		foreach($filters as $filter) {
1408
+		foreach ($filters as $filter) {
1409 1409
 			if ($filter !== '' && $filter[0] !== '(') {
1410 1410
 				$filter = '('.$filter.')';
1411 1411
 			}
1412
-			$combinedFilter.=$filter;
1412
+			$combinedFilter .= $filter;
1413 1413
 		}
1414
-		$combinedFilter.=')';
1414
+		$combinedFilter .= ')';
1415 1415
 		return $combinedFilter;
1416 1416
 	}
1417 1417
 
@@ -1447,17 +1447,17 @@  discard block
 block discarded – undo
1447 1447
 	 * @throws \Exception
1448 1448
 	 */
1449 1449
 	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1450
-		if(!is_array($searchAttributes) || count($searchAttributes) < 2) {
1450
+		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1451 1451
 			throw new \Exception('searchAttributes must be an array with at least two string');
1452 1452
 		}
1453 1453
 		$searchWords = explode(' ', trim($search));
1454 1454
 		$wordFilters = array();
1455
-		foreach($searchWords as $word) {
1455
+		foreach ($searchWords as $word) {
1456 1456
 			$word = $this->prepareSearchTerm($word);
1457 1457
 			//every word needs to appear at least once
1458 1458
 			$wordMatchOneAttrFilters = array();
1459
-			foreach($searchAttributes as $attr) {
1460
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1459
+			foreach ($searchAttributes as $attr) {
1460
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1461 1461
 			}
1462 1462
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1463 1463
 		}
@@ -1475,10 +1475,10 @@  discard block
 block discarded – undo
1475 1475
 	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1476 1476
 		$filter = array();
1477 1477
 		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1478
-		if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1478
+		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1479 1479
 			try {
1480 1480
 				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1481
-			} catch(\Exception $e) {
1481
+			} catch (\Exception $e) {
1482 1482
 				\OCP\Util::writeLog(
1483 1483
 					'user_ldap',
1484 1484
 					'Creating advanced filter for search failed, falling back to simple method.',
@@ -1488,17 +1488,17 @@  discard block
 block discarded – undo
1488 1488
 		}
1489 1489
 
1490 1490
 		$search = $this->prepareSearchTerm($search);
1491
-		if(!is_array($searchAttributes) || count($searchAttributes) === 0) {
1491
+		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1492 1492
 			if ($fallbackAttribute === '') {
1493 1493
 				return '';
1494 1494
 			}
1495
-			$filter[] = $fallbackAttribute . '=' . $search;
1495
+			$filter[] = $fallbackAttribute.'='.$search;
1496 1496
 		} else {
1497
-			foreach($searchAttributes as $attribute) {
1498
-				$filter[] = $attribute . '=' . $search;
1497
+			foreach ($searchAttributes as $attribute) {
1498
+				$filter[] = $attribute.'='.$search;
1499 1499
 			}
1500 1500
 		}
1501
-		if(count($filter) === 1) {
1501
+		if (count($filter) === 1) {
1502 1502
 			return '('.$filter[0].')';
1503 1503
 		}
1504 1504
 		return $this->combineFilterWithOr($filter);
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
 		if ($term === '') {
1520 1520
 			$result = '*';
1521 1521
 		} else if ($allowEnum !== 'no') {
1522
-			$result = $term . '*';
1522
+			$result = $term.'*';
1523 1523
 		}
1524 1524
 		return $result;
1525 1525
 	}
@@ -1531,7 +1531,7 @@  discard block
 block discarded – undo
1531 1531
 	public function getFilterForUserCount() {
1532 1532
 		$filter = $this->combineFilterWithAnd(array(
1533 1533
 			$this->connection->ldapUserFilter,
1534
-			$this->connection->ldapUserDisplayName . '=*'
1534
+			$this->connection->ldapUserDisplayName.'=*'
1535 1535
 		));
1536 1536
 
1537 1537
 		return $filter;
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
 			'ldapAgentName' => $name,
1550 1550
 			'ldapAgentPassword' => $password
1551 1551
 		);
1552
-		if(!$testConnection->setConfiguration($credentials)) {
1552
+		if (!$testConnection->setConfiguration($credentials)) {
1553 1553
 			return false;
1554 1554
 		}
1555 1555
 		return $testConnection->bind();
@@ -1571,30 +1571,30 @@  discard block
 block discarded – undo
1571 1571
 			// Sacrebleu! The UUID attribute is unknown :( We need first an
1572 1572
 			// existing DN to be able to reliably detect it.
1573 1573
 			$result = $this->search($filter, $base, ['dn'], 1);
1574
-			if(!isset($result[0]) || !isset($result[0]['dn'])) {
1574
+			if (!isset($result[0]) || !isset($result[0]['dn'])) {
1575 1575
 				throw new \Exception('Cannot determine UUID attribute');
1576 1576
 			}
1577 1577
 			$dn = $result[0]['dn'][0];
1578
-			if(!$this->detectUuidAttribute($dn, true)) {
1578
+			if (!$this->detectUuidAttribute($dn, true)) {
1579 1579
 				throw new \Exception('Cannot determine UUID attribute');
1580 1580
 			}
1581 1581
 		} else {
1582 1582
 			// The UUID attribute is either known or an override is given.
1583 1583
 			// By calling this method we ensure that $this->connection->$uuidAttr
1584 1584
 			// is definitely set
1585
-			if(!$this->detectUuidAttribute('', true)) {
1585
+			if (!$this->detectUuidAttribute('', true)) {
1586 1586
 				throw new \Exception('Cannot determine UUID attribute');
1587 1587
 			}
1588 1588
 		}
1589 1589
 
1590 1590
 		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1591
-		if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1591
+		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1592 1592
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1593 1593
 		}
1594 1594
 
1595
-		$filter = $uuidAttr . '=' . $uuid;
1595
+		$filter = $uuidAttr.'='.$uuid;
1596 1596
 		$result = $this->searchUsers($filter, ['dn'], 2);
1597
-		if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1597
+		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1598 1598
 			// we put the count into account to make sure that this is
1599 1599
 			// really unique
1600 1600
 			return $result[0]['dn'][0];
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
 	 * @return bool true on success, false otherwise
1614 1614
 	 */
1615 1615
 	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1616
-		if($isUser) {
1616
+		if ($isUser) {
1617 1617
 			$uuidAttr     = 'ldapUuidUserAttribute';
1618 1618
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1619 1619
 		} else {
@@ -1621,7 +1621,7 @@  discard block
 block discarded – undo
1621 1621
 			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1622 1622
 		}
1623 1623
 
1624
-		if(($this->connection->$uuidAttr !== 'auto') && !$force) {
1624
+		if (($this->connection->$uuidAttr !== 'auto') && !$force) {
1625 1625
 			return true;
1626 1626
 		}
1627 1627
 
@@ -1630,10 +1630,10 @@  discard block
 block discarded – undo
1630 1630
 			return true;
1631 1631
 		}
1632 1632
 
1633
-		foreach(self::UUID_ATTRIBUTES as $attribute) {
1634
-			if($ldapRecord !== null) {
1633
+		foreach (self::UUID_ATTRIBUTES as $attribute) {
1634
+			if ($ldapRecord !== null) {
1635 1635
 				// we have the info from LDAP already, we don't need to talk to the server again
1636
-				if(isset($ldapRecord[$attribute])) {
1636
+				if (isset($ldapRecord[$attribute])) {
1637 1637
 					$this->connection->$uuidAttr = $attribute;
1638 1638
 					return true;
1639 1639
 				} else {
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
 			}
1643 1643
 
1644 1644
 			$value = $this->readAttribute($dn, $attribute);
1645
-			if(is_array($value) && isset($value[0]) && !empty($value[0])) {
1645
+			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1646 1646
 				\OCP\Util::writeLog(
1647 1647
 					'user_ldap',
1648 1648
 					'Setting '.$attribute.' as '.$uuidAttr,
@@ -1668,7 +1668,7 @@  discard block
 block discarded – undo
1668 1668
 	 * @return bool|string
1669 1669
 	 */
1670 1670
 	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1671
-		if($isUser) {
1671
+		if ($isUser) {
1672 1672
 			$uuidAttr     = 'ldapUuidUserAttribute';
1673 1673
 			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1674 1674
 		} else {
@@ -1677,10 +1677,10 @@  discard block
 block discarded – undo
1677 1677
 		}
1678 1678
 
1679 1679
 		$uuid = false;
1680
-		if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1680
+		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1681 1681
 			$attr = $this->connection->$uuidAttr;
1682 1682
 			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1683
-			if( !is_array($uuid)
1683
+			if (!is_array($uuid)
1684 1684
 				&& $uuidOverride !== ''
1685 1685
 				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord))
1686 1686
 			{
@@ -1688,7 +1688,7 @@  discard block
 block discarded – undo
1688 1688
 					? $ldapRecord[$this->connection->$uuidAttr]
1689 1689
 					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1690 1690
 			}
1691
-			if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1691
+			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1692 1692
 				$uuid = $uuid[0];
1693 1693
 			}
1694 1694
 		}
@@ -1705,19 +1705,19 @@  discard block
 block discarded – undo
1705 1705
 	private function convertObjectGUID2Str($oguid) {
1706 1706
 		$hex_guid = bin2hex($oguid);
1707 1707
 		$hex_guid_to_guid_str = '';
1708
-		for($k = 1; $k <= 4; ++$k) {
1708
+		for ($k = 1; $k <= 4; ++$k) {
1709 1709
 			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1710 1710
 		}
1711 1711
 		$hex_guid_to_guid_str .= '-';
1712
-		for($k = 1; $k <= 2; ++$k) {
1712
+		for ($k = 1; $k <= 2; ++$k) {
1713 1713
 			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1714 1714
 		}
1715 1715
 		$hex_guid_to_guid_str .= '-';
1716
-		for($k = 1; $k <= 2; ++$k) {
1716
+		for ($k = 1; $k <= 2; ++$k) {
1717 1717
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1718 1718
 		}
1719
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1720
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1719
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1720
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1721 1721
 
1722 1722
 		return strtoupper($hex_guid_to_guid_str);
1723 1723
 	}
@@ -1734,11 +1734,11 @@  discard block
 block discarded – undo
1734 1734
 	 * @return string
1735 1735
 	 */
1736 1736
 	public function formatGuid2ForFilterUser($guid) {
1737
-		if(!is_string($guid)) {
1737
+		if (!is_string($guid)) {
1738 1738
 			throw new \InvalidArgumentException('String expected');
1739 1739
 		}
1740 1740
 		$blocks = explode('-', $guid);
1741
-		if(count($blocks) !== 5) {
1741
+		if (count($blocks) !== 5) {
1742 1742
 			/*
1743 1743
 			 * Why not throw an Exception instead? This method is a utility
1744 1744
 			 * called only when trying to figure out whether a "missing" known
@@ -1751,20 +1751,20 @@  discard block
 block discarded – undo
1751 1751
 			 * user. Instead we write a log message.
1752 1752
 			 */
1753 1753
 			\OC::$server->getLogger()->info(
1754
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1754
+				'Passed string does not resemble a valid GUID. Known UUID '.
1755 1755
 				'({uuid}) probably does not match UUID configuration.',
1756
-				[ 'app' => 'user_ldap', 'uuid' => $guid ]
1756
+				['app' => 'user_ldap', 'uuid' => $guid]
1757 1757
 			);
1758 1758
 			return $guid;
1759 1759
 		}
1760
-		for($i=0; $i < 3; $i++) {
1760
+		for ($i = 0; $i < 3; $i++) {
1761 1761
 			$pairs = str_split($blocks[$i], 2);
1762 1762
 			$pairs = array_reverse($pairs);
1763 1763
 			$blocks[$i] = implode('', $pairs);
1764 1764
 		}
1765
-		for($i=0; $i < 5; $i++) {
1765
+		for ($i = 0; $i < 5; $i++) {
1766 1766
 			$pairs = str_split($blocks[$i], 2);
1767
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1767
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1768 1768
 		}
1769 1769
 		return implode('', $blocks);
1770 1770
 	}
@@ -1778,12 +1778,12 @@  discard block
 block discarded – undo
1778 1778
 		$domainDN = $this->getDomainDNFromDN($dn);
1779 1779
 		$cacheKey = 'getSID-'.$domainDN;
1780 1780
 		$sid = $this->connection->getFromCache($cacheKey);
1781
-		if(!is_null($sid)) {
1781
+		if (!is_null($sid)) {
1782 1782
 			return $sid;
1783 1783
 		}
1784 1784
 
1785 1785
 		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1786
-		if(!is_array($objectSid) || empty($objectSid)) {
1786
+		if (!is_array($objectSid) || empty($objectSid)) {
1787 1787
 			$this->connection->writeToCache($cacheKey, false);
1788 1788
 			return false;
1789 1789
 		}
@@ -1841,12 +1841,12 @@  discard block
 block discarded – undo
1841 1841
 		$belongsToBase = false;
1842 1842
 		$bases = $this->helper->sanitizeDN($bases);
1843 1843
 
1844
-		foreach($bases as $base) {
1844
+		foreach ($bases as $base) {
1845 1845
 			$belongsToBase = true;
1846
-			if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) {
1846
+			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1847 1847
 				$belongsToBase = false;
1848 1848
 			}
1849
-			if($belongsToBase) {
1849
+			if ($belongsToBase) {
1850 1850
 				break;
1851 1851
 			}
1852 1852
 		}
@@ -1875,16 +1875,16 @@  discard block
 block discarded – undo
1875 1875
 	 * @return string containing the key or empty if none is cached
1876 1876
 	 */
1877 1877
 	private function getPagedResultCookie($base, $filter, $limit, $offset) {
1878
-		if($offset === 0) {
1878
+		if ($offset === 0) {
1879 1879
 			return '';
1880 1880
 		}
1881 1881
 		$offset -= $limit;
1882 1882
 		//we work with cache here
1883
-		$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1883
+		$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1884 1884
 		$cookie = '';
1885
-		if(isset($this->cookies[$cacheKey])) {
1885
+		if (isset($this->cookies[$cacheKey])) {
1886 1886
 			$cookie = $this->cookies[$cacheKey];
1887
-			if(is_null($cookie)) {
1887
+			if (is_null($cookie)) {
1888 1888
 				$cookie = '';
1889 1889
 			}
1890 1890
 		}
@@ -1902,7 +1902,7 @@  discard block
 block discarded – undo
1902 1902
 	 * @return bool
1903 1903
 	 */
1904 1904
 	public function hasMoreResults() {
1905
-		if(empty($this->lastCookie) && $this->lastCookie !== '0') {
1905
+		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1906 1906
 			// as in RFC 2696, when all results are returned, the cookie will
1907 1907
 			// be empty.
1908 1908
 			return false;
@@ -1922,8 +1922,8 @@  discard block
 block discarded – undo
1922 1922
 	 */
1923 1923
 	private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
1924 1924
 		// allow '0' for 389ds
1925
-		if(!empty($cookie) || $cookie === '0') {
1926
-			$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
1925
+		if (!empty($cookie) || $cookie === '0') {
1926
+			$cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset;
1927 1927
 			$this->cookies[$cacheKey] = $cookie;
1928 1928
 			$this->lastCookie = $cookie;
1929 1929
 		}
@@ -1951,16 +1951,16 @@  discard block
 block discarded – undo
1951 1951
 	private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
1952 1952
 		$pagedSearchOK = false;
1953 1953
 		if ($limit !== 0) {
1954
-			$offset = (int)$offset; //can be null
1954
+			$offset = (int) $offset; //can be null
1955 1955
 			\OCP\Util::writeLog('user_ldap',
1956 1956
 				'initializing paged search for  Filter '.$filter.' base '.print_r($bases, true)
1957
-				.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
1957
+				.' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset,
1958 1958
 				ILogger::DEBUG);
1959 1959
 			//get the cookie from the search for the previous search, required by LDAP
1960
-			foreach($bases as $base) {
1960
+			foreach ($bases as $base) {
1961 1961
 
1962 1962
 				$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
1963
-				if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1963
+				if (empty($cookie) && $cookie !== "0" && ($offset > 0)) {
1964 1964
 					// no cookie known from a potential previous search. We need
1965 1965
 					// to start from 0 to come to the desired page. cookie value
1966 1966
 					// of '0' is valid, because 389ds
@@ -1970,17 +1970,17 @@  discard block
 block discarded – undo
1970 1970
 					//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
1971 1971
 					// '0' is valid, because 389ds
1972 1972
 					//TODO: remember this, probably does not change in the next request...
1973
-					if(empty($cookie) && $cookie !== '0') {
1973
+					if (empty($cookie) && $cookie !== '0') {
1974 1974
 						$cookie = null;
1975 1975
 					}
1976 1976
 				}
1977
-				if(!is_null($cookie)) {
1977
+				if (!is_null($cookie)) {
1978 1978
 					//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
1979 1979
 					$this->abandonPagedSearch();
1980 1980
 					$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
1981 1981
 						$this->connection->getConnectionResource(), $limit,
1982 1982
 						false, $cookie);
1983
-					if(!$pagedSearchOK) {
1983
+					if (!$pagedSearchOK) {
1984 1984
 						return false;
1985 1985
 					}
1986 1986
 					\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG);
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
 			$this->abandonPagedSearch();
2004 2004
 			// in case someone set it to 0 … use 500, otherwise no results will
2005 2005
 			// be returned.
2006
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2006
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
2007 2007
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2008 2008
 				$this->connection->getConnectionResource(),
2009 2009
 				$pageSize, false, '');
Please login to merge, or discard this patch.
apps/user_ldap/lib/Connection.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		$this->configuration = new Configuration($configPrefix,
105 105
 												 !is_null($configID));
106 106
 		$memcache = \OC::$server->getMemCacheFactory();
107
-		if($memcache->isAvailable()) {
107
+		if ($memcache->isAvailable()) {
108 108
 			$this->cache = $memcache->createDistributed();
109 109
 		}
110 110
 		$helper = new Helper(\OC::$server->getConfig());
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	}
114 114
 
115 115
 	public function __destruct() {
116
-		if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
116
+		if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
117 117
 			@$this->ldap->unbind($this->ldapConnectionRes);
118 118
 			$this->bindResult = [];
119 119
 		}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	public function __clone() {
126 126
 		$this->configuration = new Configuration($this->configPrefix,
127 127
 												 !is_null($this->configID));
128
-		if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
128
+		if (count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
129 129
 			$this->bindResult = [];
130 130
 		}
131 131
 		$this->ldapConnectionRes = null;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @return bool|mixed
138 138
 	 */
139 139
 	public function __get($name) {
140
-		if(!$this->configured) {
140
+		if (!$this->configured) {
141 141
 			$this->readConfiguration();
142 142
 		}
143 143
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		$before = $this->configuration->$name;
154 154
 		$this->configuration->$name = $value;
155 155
 		$after = $this->configuration->$name;
156
-		if($before !== $after) {
156
+		if ($before !== $after) {
157 157
 			if ($this->configID !== '' && $this->configID !== null) {
158 158
 				$this->configuration->saveConfiguration();
159 159
 			}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @param bool $state
178 178
 	 */
179 179
 	public function setIgnoreValidation($state) {
180
-		$this->ignoreValidation = (bool)$state;
180
+		$this->ignoreValidation = (bool) $state;
181 181
 	}
182 182
 
183 183
 	/**
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
 	 * Returns the LDAP handler
194 194
 	 */
195 195
 	public function getConnectionResource() {
196
-		if(!$this->ldapConnectionRes) {
196
+		if (!$this->ldapConnectionRes) {
197 197
 			$this->init();
198
-		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
198
+		} else if (!$this->ldap->isResource($this->ldapConnectionRes)) {
199 199
 			$this->ldapConnectionRes = null;
200 200
 			$this->establishConnection();
201 201
 		}
202
-		if(is_null($this->ldapConnectionRes)) {
203
-			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
202
+		if (is_null($this->ldapConnectionRes)) {
203
+			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, ILogger::ERROR);
204 204
 			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
205 205
 		}
206 206
 		return $this->ldapConnectionRes;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 * resets the connection resource
211 211
 	 */
212 212
 	public function resetConnectionResource() {
213
-		if(!is_null($this->ldapConnectionRes)) {
213
+		if (!is_null($this->ldapConnectionRes)) {
214 214
 			@$this->ldap->unbind($this->ldapConnectionRes);
215 215
 			$this->ldapConnectionRes = null;
216 216
 			$this->bindResult = [];
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	private function getCacheKey($key) {
225 225
 		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
226
-		if(is_null($key)) {
226
+		if (is_null($key)) {
227 227
 			return $prefix;
228 228
 		}
229 229
 		return $prefix.hash('sha256', $key);
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
 	 * @return mixed|null
235 235
 	 */
236 236
 	public function getFromCache($key) {
237
-		if(!$this->configured) {
237
+		if (!$this->configured) {
238 238
 			$this->readConfiguration();
239 239
 		}
240
-		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
240
+		if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
241 241
 			return null;
242 242
 		}
243 243
 		$key = $this->getCacheKey($key);
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 * @return string
253 253
 	 */
254 254
 	public function writeToCache($key, $value) {
255
-		if(!$this->configured) {
255
+		if (!$this->configured) {
256 256
 			$this->readConfiguration();
257 257
 		}
258
-		if(is_null($this->cache)
258
+		if (is_null($this->cache)
259 259
 			|| !$this->configuration->ldapCacheTTL
260 260
 			|| !$this->configuration->ldapConfigurationActive) {
261 261
 			return null;
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	}
267 267
 
268 268
 	public function clearCache() {
269
-		if(!is_null($this->cache)) {
269
+		if (!is_null($this->cache)) {
270 270
 			$this->cache->clear($this->getCacheKey(null));
271 271
 		}
272 272
 	}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @return null
279 279
 	 */
280 280
 	private function readConfiguration($force = false) {
281
-		if((!$this->configured || $force) && !is_null($this->configID)) {
281
+		if ((!$this->configured || $force) && !is_null($this->configID)) {
282 282
 			$this->configuration->readConfiguration();
283 283
 			$this->configured = $this->validateConfiguration();
284 284
 		}
@@ -291,12 +291,12 @@  discard block
 block discarded – undo
291 291
 	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
292 292
 	 */
293 293
 	public function setConfiguration($config, &$setParameters = null) {
294
-		if(is_null($setParameters)) {
294
+		if (is_null($setParameters)) {
295 295
 			$setParameters = array();
296 296
 		}
297 297
 		$this->doNotValidate = false;
298 298
 		$this->configuration->setConfiguration($config, $setParameters);
299
-		if(count($setParameters) > 0) {
299
+		if (count($setParameters) > 0) {
300 300
 			$this->configured = $this->validateConfiguration();
301 301
 		}
302 302
 
@@ -323,10 +323,10 @@  discard block
 block discarded – undo
323 323
 		$config = $this->configuration->getConfiguration();
324 324
 		$cta = $this->configuration->getConfigTranslationArray();
325 325
 		$result = array();
326
-		foreach($cta as $dbkey => $configkey) {
327
-			switch($configkey) {
326
+		foreach ($cta as $dbkey => $configkey) {
327
+			switch ($configkey) {
328 328
 				case 'homeFolderNamingRule':
329
-					if(strpos($config[$configkey], 'attr:') === 0) {
329
+					if (strpos($config[$configkey], 'attr:') === 0) {
330 330
 						$result[$dbkey] = substr($config[$configkey], 5);
331 331
 					} else {
332 332
 						$result[$dbkey] = '';
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 				case 'ldapBaseGroups':
338 338
 				case 'ldapAttributesForUserSearch':
339 339
 				case 'ldapAttributesForGroupSearch':
340
-					if(is_array($config[$configkey])) {
340
+					if (is_array($config[$configkey])) {
341 341
 						$result[$dbkey] = implode("\n", $config[$configkey]);
342 342
 						break;
343 343
 					} //else follows default
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
 
351 351
 	private function doSoftValidation() {
352 352
 		//if User or Group Base are not set, take over Base DN setting
353
-		foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
353
+		foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
354 354
 			$val = $this->configuration->$keyBase;
355
-			if(empty($val)) {
355
+			if (empty($val)) {
356 356
 				$this->configuration->$keyBase = $this->configuration->ldapBase;
357 357
 			}
358 358
 		}
359 359
 
360
-		foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
360
+		foreach (array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
361 361
 					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
362 362
 				as $expertSetting => $effectiveSetting) {
363 363
 			$uuidOverride = $this->configuration->$expertSetting;
364
-			if(!empty($uuidOverride)) {
364
+			if (!empty($uuidOverride)) {
365 365
 				$this->configuration->$effectiveSetting = $uuidOverride;
366 366
 			} else {
367 367
 				$uuidAttributes = Access::UUID_ATTRIBUTES;
368 368
 				array_unshift($uuidAttributes, 'auto');
369
-				if(!in_array($this->configuration->$effectiveSetting,
369
+				if (!in_array($this->configuration->$effectiveSetting,
370 370
 							$uuidAttributes)
371 371
 					&& (!is_null($this->configID))) {
372 372
 					$this->configuration->$effectiveSetting = 'auto';
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 			}
381 381
 		}
382 382
 
383
-		$backupPort = (int)$this->configuration->ldapBackupPort;
383
+		$backupPort = (int) $this->configuration->ldapBackupPort;
384 384
 		if ($backupPort <= 0) {
385 385
 			$this->configuration->backupPort = $this->configuration->ldapPort;
386 386
 		}
@@ -388,14 +388,14 @@  discard block
 block discarded – undo
388 388
 		//make sure empty search attributes are saved as simple, empty array
389 389
 		$saKeys = array('ldapAttributesForUserSearch',
390 390
 						'ldapAttributesForGroupSearch');
391
-		foreach($saKeys as $key) {
391
+		foreach ($saKeys as $key) {
392 392
 			$val = $this->configuration->$key;
393
-			if(is_array($val) && count($val) === 1 && empty($val[0])) {
393
+			if (is_array($val) && count($val) === 1 && empty($val[0])) {
394 394
 				$this->configuration->$key = array();
395 395
 			}
396 396
 		}
397 397
 
398
-		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
398
+		if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
399 399
 			&& $this->configuration->ldapTLS) {
400 400
 			$this->configuration->ldapTLS = false;
401 401
 			\OCP\Util::writeLog(
@@ -412,15 +412,15 @@  discard block
 block discarded – undo
412 412
 	private function doCriticalValidation() {
413 413
 		$configurationOK = true;
414 414
 		$errorStr = 'Configuration Error (prefix '.
415
-			(string)$this->configPrefix .'): ';
415
+			(string) $this->configPrefix.'): ';
416 416
 
417 417
 		//options that shall not be empty
418 418
 		$options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
419 419
 						 'ldapGroupDisplayName', 'ldapLoginFilter');
420
-		foreach($options as $key) {
420
+		foreach ($options as $key) {
421 421
 			$val = $this->configuration->$key;
422
-			if(empty($val)) {
423
-				switch($key) {
422
+			if (empty($val)) {
423
+				switch ($key) {
424 424
 					case 'ldapHost':
425 425
 						$subj = 'LDAP Host';
426 426
 						break;
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
 		$agent = $this->configuration->ldapAgentName;
454 454
 		$pwd = $this->configuration->ldapAgentPassword;
455 455
 		if (
456
-			($agent === ''  && $pwd !== '')
456
+			($agent === '' && $pwd !== '')
457 457
 			|| ($agent !== '' && $pwd === '')
458 458
 		) {
459 459
 			\OCP\Util::writeLog(
460 460
 				'user_ldap',
461
-				$errorStr.'either no password is given for the user ' .
461
+				$errorStr.'either no password is given for the user '.
462 462
 					'agent or a password is given, but not an LDAP agent.',
463 463
 				ILogger::WARN);
464 464
 			$configurationOK = false;
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 		$baseUsers = $this->configuration->ldapBaseUsers;
469 469
 		$baseGroups = $this->configuration->ldapBaseGroups;
470 470
 
471
-		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
471
+		if (empty($base) && empty($baseUsers) && empty($baseGroups)) {
472 472
 			\OCP\Util::writeLog(
473 473
 				'user_ldap',
474 474
 				$errorStr.'Not a single Base DN given.',
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 			$configurationOK = false;
478 478
 		}
479 479
 
480
-		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
480
+		if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
481 481
 		   === false) {
482 482
 			\OCP\Util::writeLog(
483 483
 				'user_ldap',
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 	 */
497 497
 	private function validateConfiguration() {
498 498
 
499
-		if($this->doNotValidate) {
499
+		if ($this->doNotValidate) {
500 500
 			//don't do a validation if it is a new configuration with pure
501 501
 			//default values. Will be allowed on changes via __set or
502 502
 			//setConfiguration
@@ -519,14 +519,14 @@  discard block
 block discarded – undo
519 519
 	 * @throws ServerNotAvailableException
520 520
 	 */
521 521
 	private function establishConnection() {
522
-		if(!$this->configuration->ldapConfigurationActive) {
522
+		if (!$this->configuration->ldapConfigurationActive) {
523 523
 			return null;
524 524
 		}
525 525
 		static $phpLDAPinstalled = true;
526
-		if(!$phpLDAPinstalled) {
526
+		if (!$phpLDAPinstalled) {
527 527
 			return false;
528 528
 		}
529
-		if(!$this->ignoreValidation && !$this->configured) {
529
+		if (!$this->ignoreValidation && !$this->configured) {
530 530
 			\OCP\Util::writeLog(
531 531
 				'user_ldap',
532 532
 				'Configuration is invalid, cannot connect',
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
 			);
535 535
 			return false;
536 536
 		}
537
-		if(!$this->ldapConnectionRes) {
538
-			if(!$this->ldap->areLDAPFunctionsAvailable()) {
537
+		if (!$this->ldapConnectionRes) {
538
+			if (!$this->ldap->areLDAPFunctionsAvailable()) {
539 539
 				$phpLDAPinstalled = false;
540 540
 				\OCP\Util::writeLog(
541 541
 					'user_ldap',
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
 
546 546
 				return false;
547 547
 			}
548
-			if($this->configuration->turnOffCertCheck) {
549
-				if(putenv('LDAPTLS_REQCERT=never')) {
548
+			if ($this->configuration->turnOffCertCheck) {
549
+				if (putenv('LDAPTLS_REQCERT=never')) {
550 550
 					\OCP\Util::writeLog('user_ldap',
551 551
 						'Turned off SSL certificate validation successfully.',
552 552
 						ILogger::DEBUG);
@@ -570,20 +570,20 @@  discard block
 block discarded – undo
570 570
 					return $this->bind();
571 571
 				}
572 572
 			} catch (ServerNotAvailableException $e) {
573
-				if(!$isBackupHost) {
573
+				if (!$isBackupHost) {
574 574
 					throw $e;
575 575
 				}
576 576
 			}
577 577
 
578 578
 			//if LDAP server is not reachable, try the Backup (Replica!) Server
579
-			if($isBackupHost || $isOverrideMainServer) {
579
+			if ($isBackupHost || $isOverrideMainServer) {
580 580
 				$this->doConnect($this->configuration->ldapBackupHost,
581 581
 								 $this->configuration->ldapBackupPort);
582 582
 				$this->bindResult = [];
583 583
 				$bindStatus = $this->bind();
584 584
 				$error = $this->ldap->isResource($this->ldapConnectionRes) ?
585 585
 					$this->ldap->errno($this->ldapConnectionRes) : -1;
586
-				if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
586
+				if ($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
587 587
 					//when bind to backup server succeeded and failed to main server,
588 588
 					//skip contacting him until next cache refresh
589 589
 					$this->writeToCache('overrideMainServer', true);
@@ -608,17 +608,17 @@  discard block
 block discarded – undo
608 608
 
609 609
 		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
610 610
 
611
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
611
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
612 612
 			throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
613 613
 		}
614 614
 
615
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
615
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
616 616
 			throw new ServerNotAvailableException('Could not disable LDAP referrals.');
617 617
 		}
618 618
 
619
-		if($this->configuration->ldapTLS) {
620
-			if(!$this->ldap->startTls($this->ldapConnectionRes)) {
621
-				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
619
+		if ($this->configuration->ldapTLS) {
620
+			if (!$this->ldap->startTls($this->ldapConnectionRes)) {
621
+				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host '.$host.'.');
622 622
 			}
623 623
 		}
624 624
 
@@ -629,19 +629,19 @@  discard block
 block discarded – undo
629 629
 	 * Binds to LDAP
630 630
 	 */
631 631
 	public function bind() {
632
-		if(!$this->configuration->ldapConfigurationActive) {
632
+		if (!$this->configuration->ldapConfigurationActive) {
633 633
 			return false;
634 634
 		}
635 635
 		$cr = $this->ldapConnectionRes;
636
-		if(!$this->ldap->isResource($cr)) {
636
+		if (!$this->ldap->isResource($cr)) {
637 637
 			$cr = $this->getConnectionResource();
638 638
 		}
639 639
 
640
-		if(
640
+		if (
641 641
 			count($this->bindResult) !== 0
642 642
 			&& $this->bindResult['dn'] === $this->configuration->ldapAgentName
643 643
 			&& \OC::$server->getHasher()->verify(
644
-				$this->configPrefix . $this->configuration->ldapAgentPassword,
644
+				$this->configPrefix.$this->configuration->ldapAgentPassword,
645 645
 				$this->bindResult['hash']
646 646
 			)
647 647
 		) {
@@ -657,19 +657,19 @@  discard block
 block discarded – undo
657 657
 
658 658
 		$this->bindResult = [
659 659
 			'dn' => $this->configuration->ldapAgentName,
660
-			'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
660
+			'hash' => \OC::$server->getHasher()->hash($this->configPrefix.$this->configuration->ldapAgentPassword),
661 661
 			'result' => $ldapLogin,
662 662
 		];
663 663
 
664
-		if(!$ldapLogin) {
664
+		if (!$ldapLogin) {
665 665
 			$errno = $this->ldap->errno($cr);
666 666
 
667 667
 			\OCP\Util::writeLog('user_ldap',
668
-				'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
668
+				'Bind failed: '.$errno.': '.$this->ldap->error($cr),
669 669
 				ILogger::WARN);
670 670
 
671 671
 			// Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
672
-			if($errno !== 0x00 && $errno !== 0x31) {
672
+			if ($errno !== 0x00 && $errno !== 0x31) {
673 673
 				$this->ldapConnectionRes = null;
674 674
 			}
675 675
 
Please login to merge, or discard this patch.
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		parent::__construct($access);
66 66
 		$filter = $this->access->connection->ldapGroupFilter;
67 67
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
68
-		if(!empty($filter) && !empty($gassoc)) {
68
+		if (!empty($filter) && !empty($gassoc)) {
69 69
 			$this->enabled = true;
70 70
 		}
71 71
 
@@ -83,25 +83,25 @@  discard block
 block discarded – undo
83 83
 	 * Checks whether the user is member of a group or not.
84 84
 	 */
85 85
 	public function inGroup($uid, $gid) {
86
-		if(!$this->enabled) {
86
+		if (!$this->enabled) {
87 87
 			return false;
88 88
 		}
89 89
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
90 90
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
91
-		if(!is_null($inGroup)) {
92
-			return (bool)$inGroup;
91
+		if (!is_null($inGroup)) {
92
+			return (bool) $inGroup;
93 93
 		}
94 94
 
95 95
 		$userDN = $this->access->username2dn($uid);
96 96
 
97
-		if(isset($this->cachedGroupMembers[$gid])) {
97
+		if (isset($this->cachedGroupMembers[$gid])) {
98 98
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
99 99
 			return $isInGroup;
100 100
 		}
101 101
 
102 102
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
103 103
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
104
-		if(!is_null($members)) {
104
+		if (!is_null($members)) {
105 105
 			$this->cachedGroupMembers[$gid] = $members;
106 106
 			$isInGroup = in_array($userDN, $members);
107 107
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 
111 111
 		$groupDN = $this->access->groupname2dn($gid);
112 112
 		// just in case
113
-		if(!$groupDN || !$userDN) {
113
+		if (!$groupDN || !$userDN) {
114 114
 			$this->access->connection->writeToCache($cacheKey, false);
115 115
 			return false;
116 116
 		}
117 117
 
118 118
 		//check primary group first
119
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
119
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
120 120
 			$this->access->connection->writeToCache($cacheKey, true);
121 121
 			return true;
122 122
 		}
@@ -124,21 +124,21 @@  discard block
 block discarded – undo
124 124
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
125 125
 		$members = $this->_groupMembers($groupDN);
126 126
 		$members = array_keys($members); // uids are returned as keys
127
-		if(!is_array($members) || count($members) === 0) {
127
+		if (!is_array($members) || count($members) === 0) {
128 128
 			$this->access->connection->writeToCache($cacheKey, false);
129 129
 			return false;
130 130
 		}
131 131
 
132 132
 		//extra work if we don't get back user DNs
133
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
133
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
134 134
 			$dns = array();
135 135
 			$filterParts = array();
136 136
 			$bytes = 0;
137
-			foreach($members as $mid) {
137
+			foreach ($members as $mid) {
138 138
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
139 139
 				$filterParts[] = $filter;
140 140
 				$bytes += strlen($filter);
141
-				if($bytes >= 9000000) {
141
+				if ($bytes >= 9000000) {
142 142
 					// AD has a default input buffer of 10 MB, we do not want
143 143
 					// to take even the chance to exceed it
144 144
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 					$dns = array_merge($dns, $users);
149 149
 				}
150 150
 			}
151
-			if(count($filterParts) > 0) {
151
+			if (count($filterParts) > 0) {
152 152
 				$filter = $this->access->combineFilterWithOr($filterParts);
153 153
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
154 154
 				$dns = array_merge($dns, $users);
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
 			$pos = strpos($memberURLs[0], '(');
192 192
 			if ($pos !== false) {
193 193
 				$memberUrlFilter = substr($memberURLs[0], $pos);
194
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
194
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
195 195
 				$dynamicMembers = array();
196
-				foreach($foundMembers as $value) {
196
+				foreach ($foundMembers as $value) {
197 197
 					$dynamicMembers[$value['dn'][0]] = 1;
198 198
 				}
199 199
 			} else {
200 200
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
201
-					'of group ' . $dnGroup, ILogger::DEBUG);
201
+					'of group '.$dnGroup, ILogger::DEBUG);
202 202
 			}
203 203
 		}
204 204
 		return $dynamicMembers;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		// used extensively in cron job, caching makes sense for nested groups
223 223
 		$cacheKey = '_groupMembers'.$dnGroup;
224 224
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
225
-		if($groupMembers !== null) {
225
+		if ($groupMembers !== null) {
226 226
 			return $groupMembers;
227 227
 		}
228 228
 		$seen[$dnGroup] = 1;
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 			return array();
267 267
 		}
268 268
 		$groups = $this->access->groupsMatchFilter($groups);
269
-		$allGroups =  $groups;
269
+		$allGroups = $groups;
270 270
 		$nestedGroups = $this->access->connection->ldapNestedGroups;
271
-		if ((int)$nestedGroups === 1) {
271
+		if ((int) $nestedGroups === 1) {
272 272
 			foreach ($groups as $group) {
273 273
 				$subGroups = $this->_getGroupDNsFromMemberOf($group, $seen);
274 274
 				$allGroups = array_merge($allGroups, $subGroups);
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 	 * @return string|bool
285 285
 	 */
286 286
 	public function gidNumber2Name($gid, $dn) {
287
-		$cacheKey = 'gidNumberToName' . $gid;
287
+		$cacheKey = 'gidNumberToName'.$gid;
288 288
 		$groupName = $this->access->connection->getFromCache($cacheKey);
289
-		if(!is_null($groupName) && isset($groupName)) {
289
+		if (!is_null($groupName) && isset($groupName)) {
290 290
 			return $groupName;
291 291
 		}
292 292
 
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 		$filter = $this->access->combineFilterWithAnd([
295 295
 			$this->access->connection->ldapGroupFilter,
296 296
 			'objectClass=posixGroup',
297
-			$this->access->connection->ldapGidNumber . '=' . $gid
297
+			$this->access->connection->ldapGidNumber.'='.$gid
298 298
 		]);
299 299
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
300
-		if(empty($result)) {
300
+		if (empty($result)) {
301 301
 			return false;
302 302
 		}
303 303
 		$dn = $result[0]['dn'][0];
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	private function getEntryGidNumber($dn, $attribute) {
322 322
 		$value = $this->access->readAttribute($dn, $attribute);
323
-		if(is_array($value) && !empty($value)) {
323
+		if (is_array($value) && !empty($value)) {
324 324
 			return $value[0];
325 325
 		}
326 326
 		return false;
@@ -342,9 +342,9 @@  discard block
 block discarded – undo
342 342
 	 */
343 343
 	public function getUserGidNumber($dn) {
344 344
 		$gidNumber = false;
345
-		if($this->access->connection->hasGidNumber) {
345
+		if ($this->access->connection->hasGidNumber) {
346 346
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
347
-			if($gidNumber === false) {
347
+			if ($gidNumber === false) {
348 348
 				$this->access->connection->hasGidNumber = false;
349 349
 			}
350 350
 		}
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 */
362 362
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
363 363
 		$groupID = $this->getGroupGidNumber($groupDN);
364
-		if($groupID === false) {
364
+		if ($groupID === false) {
365 365
 			throw new \Exception('Not a valid group');
366 366
 		}
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		if ($search !== '') {
371 371
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
372 372
 		}
373
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
373
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
374 374
 
375 375
 		return $this->access->combineFilterWithAnd($filterParts);
376 376
 	}
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 		try {
413 413
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
414 414
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
415
-			return (int)$users;
415
+			return (int) $users;
416 416
 		} catch (\Exception $e) {
417 417
 			return 0;
418 418
 		}
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
 	 */
426 426
 	public function getUserGroupByGid($dn) {
427 427
 		$groupID = $this->getUserGidNumber($dn);
428
-		if($groupID !== false) {
428
+		if ($groupID !== false) {
429 429
 			$groupName = $this->gidNumber2Name($groupID, $dn);
430
-			if($groupName !== false) {
430
+			if ($groupName !== false) {
431 431
 				return $groupName;
432 432
 			}
433 433
 		}
@@ -444,22 +444,22 @@  discard block
 block discarded – undo
444 444
 	public function primaryGroupID2Name($gid, $dn) {
445 445
 		$cacheKey = 'primaryGroupIDtoName';
446 446
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
447
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
447
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
448 448
 			return $groupNames[$gid];
449 449
 		}
450 450
 
451 451
 		$domainObjectSid = $this->access->getSID($dn);
452
-		if($domainObjectSid === false) {
452
+		if ($domainObjectSid === false) {
453 453
 			return false;
454 454
 		}
455 455
 
456 456
 		//we need to get the DN from LDAP
457 457
 		$filter = $this->access->combineFilterWithAnd(array(
458 458
 			$this->access->connection->ldapGroupFilter,
459
-			'objectsid=' . $domainObjectSid . '-' . $gid
459
+			'objectsid='.$domainObjectSid.'-'.$gid
460 460
 		));
461 461
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
462
-		if(empty($result)) {
462
+		if (empty($result)) {
463 463
 			return false;
464 464
 		}
465 465
 		$dn = $result[0]['dn'][0];
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 	 */
483 483
 	private function getEntryGroupID($dn, $attribute) {
484 484
 		$value = $this->access->readAttribute($dn, $attribute);
485
-		if(is_array($value) && !empty($value)) {
485
+		if (is_array($value) && !empty($value)) {
486 486
 			return $value[0];
487 487
 		}
488 488
 		return false;
@@ -504,9 +504,9 @@  discard block
 block discarded – undo
504 504
 	 */
505 505
 	public function getUserPrimaryGroupIDs($dn) {
506 506
 		$primaryGroupID = false;
507
-		if($this->access->connection->hasPrimaryGroups) {
507
+		if ($this->access->connection->hasPrimaryGroups) {
508 508
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
509
-			if($primaryGroupID === false) {
509
+			if ($primaryGroupID === false) {
510 510
 				$this->access->connection->hasPrimaryGroups = false;
511 511
 			}
512 512
 		}
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 	 */
524 524
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
525 525
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
526
-		if($groupID === false) {
526
+		if ($groupID === false) {
527 527
 			throw new \Exception('Not a valid group');
528 528
 		}
529 529
 
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		if ($search !== '') {
533 533
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
534 534
 		}
535
-		$filterParts[] = 'primaryGroupID=' . $groupID;
535
+		$filterParts[] = 'primaryGroupID='.$groupID;
536 536
 
537 537
 		return $this->access->combineFilterWithAnd($filterParts);
538 538
 	}
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 		try {
575 575
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
576 576
 			$users = $this->access->countUsers($filter, array('dn'), $limit, $offset);
577
-			return (int)$users;
577
+			return (int) $users;
578 578
 		} catch (\Exception $e) {
579 579
 			return 0;
580 580
 		}
@@ -587,9 +587,9 @@  discard block
 block discarded – undo
587 587
 	 */
588 588
 	public function getUserPrimaryGroup($dn) {
589 589
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
590
-		if($groupID !== false) {
590
+		if ($groupID !== false) {
591 591
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
592
-			if($groupName !== false) {
592
+			if ($groupName !== false) {
593 593
 				return $groupName;
594 594
 			}
595 595
 		}
@@ -608,16 +608,16 @@  discard block
 block discarded – undo
608 608
 	 * This function includes groups based on dynamic group membership.
609 609
 	 */
610 610
 	public function getUserGroups($uid) {
611
-		if(!$this->enabled) {
611
+		if (!$this->enabled) {
612 612
 			return array();
613 613
 		}
614 614
 		$cacheKey = 'getUserGroups'.$uid;
615 615
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
616
-		if(!is_null($userGroups)) {
616
+		if (!is_null($userGroups)) {
617 617
 			return $userGroups;
618 618
 		}
619 619
 		$userDN = $this->access->username2dn($uid);
620
-		if(!$userDN) {
620
+		if (!$userDN) {
621 621
 			$this->access->connection->writeToCache($cacheKey, array());
622 622
 			return array();
623 623
 		}
@@ -631,14 +631,14 @@  discard block
 block discarded – undo
631 631
 		if (!empty($dynamicGroupMemberURL)) {
632 632
 			// look through dynamic groups to add them to the result array if needed
633 633
 			$groupsToMatch = $this->access->fetchListOfGroups(
634
-				$this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL));
635
-			foreach($groupsToMatch as $dynamicGroup) {
634
+				$this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL));
635
+			foreach ($groupsToMatch as $dynamicGroup) {
636 636
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
637 637
 					continue;
638 638
 				}
639 639
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
640 640
 				if ($pos !== false) {
641
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
641
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
642 642
 					// apply filter via ldap search to see if this user is in this
643 643
 					// dynamic group
644 644
 					$userMatch = $this->access->readAttribute(
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 					if ($userMatch !== false) {
650 650
 						// match found so this user is in this group
651 651
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
652
-						if(is_string($groupName)) {
652
+						if (is_string($groupName)) {
653 653
 							// be sure to never return false if the dn could not be
654 654
 							// resolved to a name, for whatever reason.
655 655
 							$groups[] = $groupName;
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 					}
658 658
 				} else {
659 659
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
660
-						'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
660
+						'of group '.print_r($dynamicGroup, true), ILogger::DEBUG);
661 661
 				}
662 662
 			}
663 663
 		}
@@ -665,15 +665,15 @@  discard block
 block discarded – undo
665 665
 		// if possible, read out membership via memberOf. It's far faster than
666 666
 		// performing a search, which still is a fallback later.
667 667
 		// memberof doesn't support memberuid, so skip it here.
668
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
669
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
668
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
669
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
670 670
 		    && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
671 671
 		    ) {
672 672
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
673 673
 			if (is_array($groupDNs)) {
674 674
 				foreach ($groupDNs as $dn) {
675 675
 					$groupName = $this->access->dn2groupname($dn);
676
-					if(is_string($groupName)) {
676
+					if (is_string($groupName)) {
677 677
 						// be sure to never return false if the dn could not be
678 678
 						// resolved to a name, for whatever reason.
679 679
 						$groups[] = $groupName;
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
 				}
682 682
 			}
683 683
 
684
-			if($primaryGroup !== false) {
684
+			if ($primaryGroup !== false) {
685 685
 				$groups[] = $primaryGroup;
686 686
 			}
687
-			if($gidGroupName !== false) {
687
+			if ($gidGroupName !== false) {
688 688
 				$groups[] = $gidGroupName;
689 689
 			}
690 690
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -692,14 +692,14 @@  discard block
 block discarded – undo
692 692
 		}
693 693
 
694 694
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
695
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
695
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
696 696
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
697 697
 		) {
698 698
 			$uid = $userDN;
699
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
699
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
700 700
 			$result = $this->access->readAttribute($userDN, 'uid');
701 701
 			if ($result === false) {
702
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
702
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
703 703
 					$this->access->connection->ldapHost, ILogger::DEBUG);
704 704
 			}
705 705
 			$uid = $result[0];
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 			$uid = $userDN;
709 709
 		}
710 710
 
711
-		if(isset($this->cachedGroupsByMember[$uid])) {
711
+		if (isset($this->cachedGroupsByMember[$uid])) {
712 712
 			$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
713 713
 		} else {
714 714
 			$groupsByMember = array_values($this->getGroupsByMember($uid));
@@ -717,10 +717,10 @@  discard block
 block discarded – undo
717 717
 			$groups = array_merge($groups, $groupsByMember);
718 718
 		}
719 719
 
720
-		if($primaryGroup !== false) {
720
+		if ($primaryGroup !== false) {
721 721
 			$groups[] = $primaryGroup;
722 722
 		}
723
-		if($gidGroupName !== false) {
723
+		if ($gidGroupName !== false) {
724 724
 			$groups[] = $gidGroupName;
725 725
 		}
726 726
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 				$nestedGroups = $this->access->connection->ldapNestedGroups;
759 759
 				if (!empty($nestedGroups)) {
760 760
 					$supergroups = $this->getGroupsByMember($groupDN, $seen);
761
-					if (is_array($supergroups) && (count($supergroups)>0)) {
761
+					if (is_array($supergroups) && (count($supergroups) > 0)) {
762 762
 						$allGroups = array_merge($allGroups, $supergroups);
763 763
 					}
764 764
 				}
@@ -777,33 +777,33 @@  discard block
 block discarded – undo
777 777
 	 * @return array with user ids
778 778
 	 */
779 779
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
780
-		if(!$this->enabled) {
780
+		if (!$this->enabled) {
781 781
 			return array();
782 782
 		}
783
-		if(!$this->groupExists($gid)) {
783
+		if (!$this->groupExists($gid)) {
784 784
 			return array();
785 785
 		}
786 786
 		$search = $this->access->escapeFilterPart($search, true);
787 787
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
788 788
 		// check for cache of the exact query
789 789
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
790
-		if(!is_null($groupUsers)) {
790
+		if (!is_null($groupUsers)) {
791 791
 			return $groupUsers;
792 792
 		}
793 793
 
794 794
 		// check for cache of the query without limit and offset
795 795
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
796
-		if(!is_null($groupUsers)) {
796
+		if (!is_null($groupUsers)) {
797 797
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
798 798
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
799 799
 			return $groupUsers;
800 800
 		}
801 801
 
802
-		if($limit === -1) {
802
+		if ($limit === -1) {
803 803
 			$limit = null;
804 804
 		}
805 805
 		$groupDN = $this->access->groupname2dn($gid);
806
-		if(!$groupDN) {
806
+		if (!$groupDN) {
807 807
 			// group couldn't be found, return empty resultset
808 808
 			$this->access->connection->writeToCache($cacheKey, array());
809 809
 			return array();
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
813 813
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
814 814
 		$members = array_keys($this->_groupMembers($groupDN));
815
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
815
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
816 816
 			//in case users could not be retrieved, return empty result set
817 817
 			$this->access->connection->writeToCache($cacheKey, []);
818 818
 			return [];
@@ -821,29 +821,29 @@  discard block
 block discarded – undo
821 821
 		$groupUsers = array();
822 822
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
823 823
 		$attrs = $this->access->userManager->getAttributes(true);
824
-		foreach($members as $member) {
825
-			if($isMemberUid) {
824
+		foreach ($members as $member) {
825
+			if ($isMemberUid) {
826 826
 				//we got uids, need to get their DNs to 'translate' them to user names
827 827
 				$filter = $this->access->combineFilterWithAnd(array(
828 828
 					str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter),
829 829
 					$this->access->getFilterPartForUserSearch($search)
830 830
 				));
831 831
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
832
-				if(count($ldap_users) < 1) {
832
+				if (count($ldap_users) < 1) {
833 833
 					continue;
834 834
 				}
835 835
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
836 836
 			} else {
837 837
 				//we got DNs, check if we need to filter by search or we can give back all of them
838 838
 				if ($search !== '') {
839
-					if(!$this->access->readAttribute($member,
839
+					if (!$this->access->readAttribute($member,
840 840
 						$this->access->connection->ldapUserDisplayName,
841 841
 						$this->access->getFilterPartForUserSearch($search))) {
842 842
 						continue;
843 843
 					}
844 844
 				}
845 845
 				// dn2username will also check if the users belong to the allowed base
846
-				if($ocname = $this->access->dn2username($member)) {
846
+				if ($ocname = $this->access->dn2username($member)) {
847 847
 					$groupUsers[] = $ocname;
848 848
 				}
849 849
 			}
@@ -871,16 +871,16 @@  discard block
 block discarded – undo
871 871
 		}
872 872
 
873 873
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
874
-		if(!$this->enabled || !$this->groupExists($gid)) {
874
+		if (!$this->enabled || !$this->groupExists($gid)) {
875 875
 			return false;
876 876
 		}
877 877
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
878
-		if(!is_null($groupUsers)) {
878
+		if (!is_null($groupUsers)) {
879 879
 			return $groupUsers;
880 880
 		}
881 881
 
882 882
 		$groupDN = $this->access->groupname2dn($gid);
883
-		if(!$groupDN) {
883
+		if (!$groupDN) {
884 884
 			// group couldn't be found, return empty result set
885 885
 			$this->access->connection->writeToCache($cacheKey, false);
886 886
 			return false;
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 
889 889
 		$members = array_keys($this->_groupMembers($groupDN));
890 890
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
891
-		if(!$members && $primaryUserCount === 0) {
891
+		if (!$members && $primaryUserCount === 0) {
892 892
 			//in case users could not be retrieved, return empty result set
893 893
 			$this->access->connection->writeToCache($cacheKey, false);
894 894
 			return false;
@@ -913,27 +913,27 @@  discard block
 block discarded – undo
913 913
 		//For now this is not important, because the only use of this method
914 914
 		//does not supply a search string
915 915
 		$groupUsers = array();
916
-		foreach($members as $member) {
917
-			if($isMemberUid) {
916
+		foreach ($members as $member) {
917
+			if ($isMemberUid) {
918 918
 				//we got uids, need to get their DNs to 'translate' them to user names
919 919
 				$filter = $this->access->combineFilterWithAnd(array(
920 920
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
921 921
 					$this->access->getFilterPartForUserSearch($search)
922 922
 				));
923 923
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
924
-				if(count($ldap_users) < 1) {
924
+				if (count($ldap_users) < 1) {
925 925
 					continue;
926 926
 				}
927 927
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
928 928
 			} else {
929 929
 				//we need to apply the search filter now
930
-				if(!$this->access->readAttribute($member,
930
+				if (!$this->access->readAttribute($member,
931 931
 					$this->access->connection->ldapUserDisplayName,
932 932
 					$this->access->getFilterPartForUserSearch($search))) {
933 933
 					continue;
934 934
 				}
935 935
 				// dn2username will also check if the users belong to the allowed base
936
-				if($ocname = $this->access->dn2username($member)) {
936
+				if ($ocname = $this->access->dn2username($member)) {
937 937
 					$groupUsers[] = $ocname;
938 938
 				}
939 939
 			}
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 	 * Returns a list with all groups (used by getGroups)
957 957
 	 */
958 958
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
959
-		if(!$this->enabled) {
959
+		if (!$this->enabled) {
960 960
 			return array();
961 961
 		}
962 962
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -964,13 +964,13 @@  discard block
 block discarded – undo
964 964
 		//Check cache before driving unnecessary searches
965 965
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
966 966
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
967
-		if(!is_null($ldap_groups)) {
967
+		if (!is_null($ldap_groups)) {
968 968
 			return $ldap_groups;
969 969
 		}
970 970
 
971 971
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
972 972
 		// error. With a limit of 0, we get 0 results. So we pass null.
973
-		if($limit <= 0) {
973
+		if ($limit <= 0) {
974 974
 			$limit = null;
975 975
 		}
976 976
 		$filter = $this->access->combineFilterWithAnd(array(
@@ -1002,11 +1002,11 @@  discard block
 block discarded – undo
1002 1002
 	 * (active directory has a limit of 1000 by default)
1003 1003
 	 */
1004 1004
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1005
-		if(!$this->enabled) {
1005
+		if (!$this->enabled) {
1006 1006
 			return array();
1007 1007
 		}
1008 1008
 		$search = $this->access->escapeFilterPart($search, true);
1009
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1009
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1010 1010
 		if ($pagingSize <= 0) {
1011 1011
 			return $this->getGroupsChunk($search, $limit, $offset);
1012 1012
 		}
@@ -1049,20 +1049,20 @@  discard block
 block discarded – undo
1049 1049
 	 */
1050 1050
 	public function groupExists($gid) {
1051 1051
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1052
-		if(!is_null($groupExists)) {
1053
-			return (bool)$groupExists;
1052
+		if (!is_null($groupExists)) {
1053
+			return (bool) $groupExists;
1054 1054
 		}
1055 1055
 
1056 1056
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1057 1057
 		//only, requires more checking.
1058 1058
 		$dn = $this->access->groupname2dn($gid);
1059
-		if(!$dn) {
1059
+		if (!$dn) {
1060 1060
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1061 1061
 			return false;
1062 1062
 		}
1063 1063
 
1064 1064
 		//if group really still exists, we will be able to read its objectclass
1065
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1065
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1066 1066
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1067 1067
 			return false;
1068 1068
 		}
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 	* compared with GroupInterface::CREATE_GROUP etc.
1081 1081
 	*/
1082 1082
 	public function implementsActions($actions) {
1083
-		return (bool)((GroupInterface::COUNT_USERS |
1083
+		return (bool) ((GroupInterface::COUNT_USERS |
1084 1084
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1085 1085
 	}
1086 1086
 
Please login to merge, or discard this patch.