Completed
Push — master ( ff1b34...d1fb93 )
by Joas
16:03
created
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		parent::__construct($access);
65 65
 		$filter = $this->access->connection->ldapGroupFilter;
66 66
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
67
-		if(!empty($filter) && !empty($gassoc)) {
67
+		if (!empty($filter) && !empty($gassoc)) {
68 68
 			$this->enabled = true;
69 69
 		}
70 70
 
@@ -82,25 +82,25 @@  discard block
 block discarded – undo
82 82
 	 * Checks whether the user is member of a group or not.
83 83
 	 */
84 84
 	public function inGroup($uid, $gid) {
85
-		if(!$this->enabled) {
85
+		if (!$this->enabled) {
86 86
 			return false;
87 87
 		}
88 88
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
89 89
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
90
-		if(!is_null($inGroup)) {
91
-			return (bool)$inGroup;
90
+		if (!is_null($inGroup)) {
91
+			return (bool) $inGroup;
92 92
 		}
93 93
 
94 94
 		$userDN = $this->access->username2dn($uid);
95 95
 
96
-		if(isset($this->cachedGroupMembers[$gid])) {
96
+		if (isset($this->cachedGroupMembers[$gid])) {
97 97
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
98 98
 			return $isInGroup;
99 99
 		}
100 100
 
101 101
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
102 102
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
103
-		if(!is_null($members)) {
103
+		if (!is_null($members)) {
104 104
 			$this->cachedGroupMembers[$gid] = $members;
105 105
 			$isInGroup = in_array($userDN, $members);
106 106
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 
110 110
 		$groupDN = $this->access->groupname2dn($gid);
111 111
 		// just in case
112
-		if(!$groupDN || !$userDN) {
112
+		if (!$groupDN || !$userDN) {
113 113
 			$this->access->connection->writeToCache($cacheKey, false);
114 114
 			return false;
115 115
 		}
116 116
 
117 117
 		//check primary group first
118
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
118
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
119 119
 			$this->access->connection->writeToCache($cacheKey, true);
120 120
 			return true;
121 121
 		}
@@ -123,21 +123,21 @@  discard block
 block discarded – undo
123 123
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
124 124
 		$members = $this->_groupMembers($groupDN);
125 125
 		$members = array_keys($members); // uids are returned as keys
126
-		if(!is_array($members) || count($members) === 0) {
126
+		if (!is_array($members) || count($members) === 0) {
127 127
 			$this->access->connection->writeToCache($cacheKey, false);
128 128
 			return false;
129 129
 		}
130 130
 
131 131
 		//extra work if we don't get back user DNs
132
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
132
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
133 133
 			$dns = array();
134 134
 			$filterParts = array();
135 135
 			$bytes = 0;
136
-			foreach($members as $mid) {
136
+			foreach ($members as $mid) {
137 137
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
138 138
 				$filterParts[] = $filter;
139 139
 				$bytes += strlen($filter);
140
-				if($bytes >= 9000000) {
140
+				if ($bytes >= 9000000) {
141 141
 					// AD has a default input buffer of 10 MB, we do not want
142 142
 					// to take even the chance to exceed it
143 143
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 					$dns = array_merge($dns, $users);
148 148
 				}
149 149
 			}
150
-			if(count($filterParts) > 0) {
150
+			if (count($filterParts) > 0) {
151 151
 				$filter = $this->access->combineFilterWithOr($filterParts);
152 152
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
153 153
 				$dns = array_merge($dns, $users);
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 			$pos = strpos($memberURLs[0], '(');
191 191
 			if ($pos !== false) {
192 192
 				$memberUrlFilter = substr($memberURLs[0], $pos);
193
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
193
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
194 194
 				$dynamicMembers = array();
195
-				foreach($foundMembers as $value) {
195
+				foreach ($foundMembers as $value) {
196 196
 					$dynamicMembers[$value['dn'][0]] = 1;
197 197
 				}
198 198
 			} else {
199 199
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
200
-					'of group ' . $dnGroup, \OCP\Util::DEBUG);
200
+					'of group '.$dnGroup, \OCP\Util::DEBUG);
201 201
 			}
202 202
 		}
203 203
 		return $dynamicMembers;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		// used extensively in cron job, caching makes sense for nested groups
221 221
 		$cacheKey = '_groupMembers'.$dnGroup;
222 222
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
223
-		if(!is_null($groupMembers)) {
223
+		if (!is_null($groupMembers)) {
224 224
 			return $groupMembers;
225 225
 		}
226 226
 		$seen[$dnGroup] = 1;
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 			return array();
265 265
 		}
266 266
 		$groups = $this->access->groupsMatchFilter($groups);
267
-		$allGroups =  $groups;
267
+		$allGroups = $groups;
268 268
 		$nestedGroups = $this->access->connection->ldapNestedGroups;
269
-		if ((int)$nestedGroups === 1) {
269
+		if ((int) $nestedGroups === 1) {
270 270
 			foreach ($groups as $group) {
271 271
 				$subGroups = $this->_getGroupDNsFromMemberOf($group, $seen);
272 272
 				$allGroups = array_merge($allGroups, $subGroups);
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 	 * @return string|bool
283 283
 	 */
284 284
 	public function gidNumber2Name($gid, $dn) {
285
-		$cacheKey = 'gidNumberToName' . $gid;
285
+		$cacheKey = 'gidNumberToName'.$gid;
286 286
 		$groupName = $this->access->connection->getFromCache($cacheKey);
287
-		if(!is_null($groupName) && isset($groupName)) {
287
+		if (!is_null($groupName) && isset($groupName)) {
288 288
 			return $groupName;
289 289
 		}
290 290
 
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 		$filter = $this->access->combineFilterWithAnd([
293 293
 			$this->access->connection->ldapGroupFilter,
294 294
 			'objectClass=posixGroup',
295
-			$this->access->connection->ldapGidNumber . '=' . $gid
295
+			$this->access->connection->ldapGidNumber.'='.$gid
296 296
 		]);
297 297
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
298
-		if(empty($result)) {
298
+		if (empty($result)) {
299 299
 			return false;
300 300
 		}
301 301
 		$dn = $result[0]['dn'][0];
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	private function getEntryGidNumber($dn, $attribute) {
320 320
 		$value = $this->access->readAttribute($dn, $attribute);
321
-		if(is_array($value) && !empty($value)) {
321
+		if (is_array($value) && !empty($value)) {
322 322
 			return $value[0];
323 323
 		}
324 324
 		return false;
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 	 */
341 341
 	public function getUserGidNumber($dn) {
342 342
 		$gidNumber = false;
343
-		if($this->access->connection->hasGidNumber) {
343
+		if ($this->access->connection->hasGidNumber) {
344 344
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
345
-			if($gidNumber === false) {
345
+			if ($gidNumber === false) {
346 346
 				$this->access->connection->hasGidNumber = false;
347 347
 			}
348 348
 		}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
361 361
 		$groupID = $this->getGroupGidNumber($groupDN);
362
-		if($groupID === false) {
362
+		if ($groupID === false) {
363 363
 			throw new \Exception('Not a valid group');
364 364
 		}
365 365
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 		if ($search !== '') {
369 369
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
370 370
 		}
371
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
371
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
372 372
 
373 373
 		return $this->access->combineFilterWithAnd($filterParts);
374 374
 	}
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		try {
411 411
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
412 412
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
413
-			return (int)$users;
413
+			return (int) $users;
414 414
 		} catch (\Exception $e) {
415 415
 			return 0;
416 416
 		}
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	 */
424 424
 	public function getUserGroupByGid($dn) {
425 425
 		$groupID = $this->getUserGidNumber($dn);
426
-		if($groupID !== false) {
426
+		if ($groupID !== false) {
427 427
 			$groupName = $this->gidNumber2Name($groupID, $dn);
428
-			if($groupName !== false) {
428
+			if ($groupName !== false) {
429 429
 				return $groupName;
430 430
 			}
431 431
 		}
@@ -442,22 +442,22 @@  discard block
 block discarded – undo
442 442
 	public function primaryGroupID2Name($gid, $dn) {
443 443
 		$cacheKey = 'primaryGroupIDtoName';
444 444
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
445
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
445
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
446 446
 			return $groupNames[$gid];
447 447
 		}
448 448
 
449 449
 		$domainObjectSid = $this->access->getSID($dn);
450
-		if($domainObjectSid === false) {
450
+		if ($domainObjectSid === false) {
451 451
 			return false;
452 452
 		}
453 453
 
454 454
 		//we need to get the DN from LDAP
455 455
 		$filter = $this->access->combineFilterWithAnd(array(
456 456
 			$this->access->connection->ldapGroupFilter,
457
-			'objectsid=' . $domainObjectSid . '-' . $gid
457
+			'objectsid='.$domainObjectSid.'-'.$gid
458 458
 		));
459 459
 		$result = $this->access->searchGroups($filter, array('dn'), 1);
460
-		if(empty($result)) {
460
+		if (empty($result)) {
461 461
 			return false;
462 462
 		}
463 463
 		$dn = $result[0]['dn'][0];
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 */
481 481
 	private function getEntryGroupID($dn, $attribute) {
482 482
 		$value = $this->access->readAttribute($dn, $attribute);
483
-		if(is_array($value) && !empty($value)) {
483
+		if (is_array($value) && !empty($value)) {
484 484
 			return $value[0];
485 485
 		}
486 486
 		return false;
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 	 */
503 503
 	public function getUserPrimaryGroupIDs($dn) {
504 504
 		$primaryGroupID = false;
505
-		if($this->access->connection->hasPrimaryGroups) {
505
+		if ($this->access->connection->hasPrimaryGroups) {
506 506
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
507
-			if($primaryGroupID === false) {
507
+			if ($primaryGroupID === false) {
508 508
 				$this->access->connection->hasPrimaryGroups = false;
509 509
 			}
510 510
 		}
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
523 523
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
524
-		if($groupID === false) {
524
+		if ($groupID === false) {
525 525
 			throw new \Exception('Not a valid group');
526 526
 		}
527 527
 
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 		if ($search !== '') {
531 531
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
532 532
 		}
533
-		$filterParts[] = 'primaryGroupID=' . $groupID;
533
+		$filterParts[] = 'primaryGroupID='.$groupID;
534 534
 
535 535
 		return $this->access->combineFilterWithAnd($filterParts);
536 536
 	}
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		try {
573 573
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
574 574
 			$users = $this->access->countUsers($filter, array('dn'), $limit, $offset);
575
-			return (int)$users;
575
+			return (int) $users;
576 576
 		} catch (\Exception $e) {
577 577
 			return 0;
578 578
 		}
@@ -585,9 +585,9 @@  discard block
 block discarded – undo
585 585
 	 */
586 586
 	public function getUserPrimaryGroup($dn) {
587 587
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
588
-		if($groupID !== false) {
588
+		if ($groupID !== false) {
589 589
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
590
-			if($groupName !== false) {
590
+			if ($groupName !== false) {
591 591
 				return $groupName;
592 592
 			}
593 593
 		}
@@ -606,16 +606,16 @@  discard block
 block discarded – undo
606 606
 	 * This function includes groups based on dynamic group membership.
607 607
 	 */
608 608
 	public function getUserGroups($uid) {
609
-		if(!$this->enabled) {
609
+		if (!$this->enabled) {
610 610
 			return array();
611 611
 		}
612 612
 		$cacheKey = 'getUserGroups'.$uid;
613 613
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
614
-		if(!is_null($userGroups)) {
614
+		if (!is_null($userGroups)) {
615 615
 			return $userGroups;
616 616
 		}
617 617
 		$userDN = $this->access->username2dn($uid);
618
-		if(!$userDN) {
618
+		if (!$userDN) {
619 619
 			$this->access->connection->writeToCache($cacheKey, array());
620 620
 			return array();
621 621
 		}
@@ -629,14 +629,14 @@  discard block
 block discarded – undo
629 629
 		if (!empty($dynamicGroupMemberURL)) {
630 630
 			// look through dynamic groups to add them to the result array if needed
631 631
 			$groupsToMatch = $this->access->fetchListOfGroups(
632
-				$this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL));
633
-			foreach($groupsToMatch as $dynamicGroup) {
632
+				$this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL));
633
+			foreach ($groupsToMatch as $dynamicGroup) {
634 634
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
635 635
 					continue;
636 636
 				}
637 637
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
638 638
 				if ($pos !== false) {
639
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
639
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
640 640
 					// apply filter via ldap search to see if this user is in this
641 641
 					// dynamic group
642 642
 					$userMatch = $this->access->readAttribute(
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 					if ($userMatch !== false) {
648 648
 						// match found so this user is in this group
649 649
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
650
-						if(is_string($groupName)) {
650
+						if (is_string($groupName)) {
651 651
 							// be sure to never return false if the dn could not be
652 652
 							// resolved to a name, for whatever reason.
653 653
 							$groups[] = $groupName;
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 					}
656 656
 				} else {
657 657
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
658
-						'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG);
658
+						'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG);
659 659
 				}
660 660
 			}
661 661
 		}
@@ -663,15 +663,15 @@  discard block
 block discarded – undo
663 663
 		// if possible, read out membership via memberOf. It's far faster than
664 664
 		// performing a search, which still is a fallback later.
665 665
 		// memberof doesn't support memberuid, so skip it here.
666
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
667
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
666
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
667
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
668 668
 		    && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
669 669
 		    ) {
670 670
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
671 671
 			if (is_array($groupDNs)) {
672 672
 				foreach ($groupDNs as $dn) {
673 673
 					$groupName = $this->access->dn2groupname($dn);
674
-					if(is_string($groupName)) {
674
+					if (is_string($groupName)) {
675 675
 						// be sure to never return false if the dn could not be
676 676
 						// resolved to a name, for whatever reason.
677 677
 						$groups[] = $groupName;
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
 				}
680 680
 			}
681 681
 
682
-			if($primaryGroup !== false) {
682
+			if ($primaryGroup !== false) {
683 683
 				$groups[] = $primaryGroup;
684 684
 			}
685
-			if($gidGroupName !== false) {
685
+			if ($gidGroupName !== false) {
686 686
 				$groups[] = $gidGroupName;
687 687
 			}
688 688
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -690,14 +690,14 @@  discard block
 block discarded – undo
690 690
 		}
691 691
 
692 692
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
693
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
693
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
694 694
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
695 695
 		) {
696 696
 			$uid = $userDN;
697
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
697
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
698 698
 			$result = $this->access->readAttribute($userDN, 'uid');
699 699
 			if ($result === false) {
700
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
700
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
701 701
 					$this->access->connection->ldapHost, \OCP\Util::DEBUG);
702 702
 			}
703 703
 			$uid = $result[0];
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 			$uid = $userDN;
707 707
 		}
708 708
 
709
-		if(isset($this->cachedGroupsByMember[$uid])) {
709
+		if (isset($this->cachedGroupsByMember[$uid])) {
710 710
 			$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
711 711
 		} else {
712 712
 			$groupsByMember = array_values($this->getGroupsByMember($uid));
@@ -715,10 +715,10 @@  discard block
 block discarded – undo
715 715
 			$groups = array_merge($groups, $groupsByMember);
716 716
 		}
717 717
 
718
-		if($primaryGroup !== false) {
718
+		if ($primaryGroup !== false) {
719 719
 			$groups[] = $primaryGroup;
720 720
 		}
721
-		if($gidGroupName !== false) {
721
+		if ($gidGroupName !== false) {
722 722
 			$groups[] = $gidGroupName;
723 723
 		}
724 724
 
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 				$nestedGroups = $this->access->connection->ldapNestedGroups;
757 757
 				if (!empty($nestedGroups)) {
758 758
 					$supergroups = $this->getGroupsByMember($groupDN, $seen);
759
-					if (is_array($supergroups) && (count($supergroups)>0)) {
759
+					if (is_array($supergroups) && (count($supergroups) > 0)) {
760 760
 						$allGroups = array_merge($allGroups, $supergroups);
761 761
 					}
762 762
 				}
@@ -775,33 +775,33 @@  discard block
 block discarded – undo
775 775
 	 * @return array with user ids
776 776
 	 */
777 777
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
778
-		if(!$this->enabled) {
778
+		if (!$this->enabled) {
779 779
 			return array();
780 780
 		}
781
-		if(!$this->groupExists($gid)) {
781
+		if (!$this->groupExists($gid)) {
782 782
 			return array();
783 783
 		}
784 784
 		$search = $this->access->escapeFilterPart($search, true);
785 785
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
786 786
 		// check for cache of the exact query
787 787
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
788
-		if(!is_null($groupUsers)) {
788
+		if (!is_null($groupUsers)) {
789 789
 			return $groupUsers;
790 790
 		}
791 791
 
792 792
 		// check for cache of the query without limit and offset
793 793
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
794
-		if(!is_null($groupUsers)) {
794
+		if (!is_null($groupUsers)) {
795 795
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
796 796
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
797 797
 			return $groupUsers;
798 798
 		}
799 799
 
800
-		if($limit === -1) {
800
+		if ($limit === -1) {
801 801
 			$limit = null;
802 802
 		}
803 803
 		$groupDN = $this->access->groupname2dn($gid);
804
-		if(!$groupDN) {
804
+		if (!$groupDN) {
805 805
 			// group couldn't be found, return empty resultset
806 806
 			$this->access->connection->writeToCache($cacheKey, array());
807 807
 			return array();
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
811 811
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
812 812
 		$members = array_keys($this->_groupMembers($groupDN));
813
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
813
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
814 814
 			//in case users could not be retrieved, return empty result set
815 815
 			$this->access->connection->writeToCache($cacheKey, []);
816 816
 			return [];
@@ -819,29 +819,29 @@  discard block
 block discarded – undo
819 819
 		$groupUsers = array();
820 820
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
821 821
 		$attrs = $this->access->userManager->getAttributes(true);
822
-		foreach($members as $member) {
823
-			if($isMemberUid) {
822
+		foreach ($members as $member) {
823
+			if ($isMemberUid) {
824 824
 				//we got uids, need to get their DNs to 'translate' them to user names
825 825
 				$filter = $this->access->combineFilterWithAnd(array(
826 826
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
827 827
 					$this->access->getFilterPartForUserSearch($search)
828 828
 				));
829 829
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
830
-				if(count($ldap_users) < 1) {
830
+				if (count($ldap_users) < 1) {
831 831
 					continue;
832 832
 				}
833 833
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
834 834
 			} else {
835 835
 				//we got DNs, check if we need to filter by search or we can give back all of them
836 836
 				if ($search !== '') {
837
-					if(!$this->access->readAttribute($member,
837
+					if (!$this->access->readAttribute($member,
838 838
 						$this->access->connection->ldapUserDisplayName,
839 839
 						$this->access->getFilterPartForUserSearch($search))) {
840 840
 						continue;
841 841
 					}
842 842
 				}
843 843
 				// dn2username will also check if the users belong to the allowed base
844
-				if($ocname = $this->access->dn2username($member)) {
844
+				if ($ocname = $this->access->dn2username($member)) {
845 845
 					$groupUsers[] = $ocname;
846 846
 				}
847 847
 			}
@@ -869,16 +869,16 @@  discard block
 block discarded – undo
869 869
 		}
870 870
 
871 871
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
872
-		if(!$this->enabled || !$this->groupExists($gid)) {
872
+		if (!$this->enabled || !$this->groupExists($gid)) {
873 873
 			return false;
874 874
 		}
875 875
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
876
-		if(!is_null($groupUsers)) {
876
+		if (!is_null($groupUsers)) {
877 877
 			return $groupUsers;
878 878
 		}
879 879
 
880 880
 		$groupDN = $this->access->groupname2dn($gid);
881
-		if(!$groupDN) {
881
+		if (!$groupDN) {
882 882
 			// group couldn't be found, return empty result set
883 883
 			$this->access->connection->writeToCache($cacheKey, false);
884 884
 			return false;
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 
887 887
 		$members = array_keys($this->_groupMembers($groupDN));
888 888
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
889
-		if(!$members && $primaryUserCount === 0) {
889
+		if (!$members && $primaryUserCount === 0) {
890 890
 			//in case users could not be retrieved, return empty result set
891 891
 			$this->access->connection->writeToCache($cacheKey, false);
892 892
 			return false;
@@ -911,27 +911,27 @@  discard block
 block discarded – undo
911 911
 		//For now this is not important, because the only use of this method
912 912
 		//does not supply a search string
913 913
 		$groupUsers = array();
914
-		foreach($members as $member) {
915
-			if($isMemberUid) {
914
+		foreach ($members as $member) {
915
+			if ($isMemberUid) {
916 916
 				//we got uids, need to get their DNs to 'translate' them to user names
917 917
 				$filter = $this->access->combineFilterWithAnd(array(
918 918
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
919 919
 					$this->access->getFilterPartForUserSearch($search)
920 920
 				));
921 921
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
922
-				if(count($ldap_users) < 1) {
922
+				if (count($ldap_users) < 1) {
923 923
 					continue;
924 924
 				}
925 925
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
926 926
 			} else {
927 927
 				//we need to apply the search filter now
928
-				if(!$this->access->readAttribute($member,
928
+				if (!$this->access->readAttribute($member,
929 929
 					$this->access->connection->ldapUserDisplayName,
930 930
 					$this->access->getFilterPartForUserSearch($search))) {
931 931
 					continue;
932 932
 				}
933 933
 				// dn2username will also check if the users belong to the allowed base
934
-				if($ocname = $this->access->dn2username($member)) {
934
+				if ($ocname = $this->access->dn2username($member)) {
935 935
 					$groupUsers[] = $ocname;
936 936
 				}
937 937
 			}
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 	 * Returns a list with all groups (used by getGroups)
955 955
 	 */
956 956
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
957
-		if(!$this->enabled) {
957
+		if (!$this->enabled) {
958 958
 			return array();
959 959
 		}
960 960
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -962,13 +962,13 @@  discard block
 block discarded – undo
962 962
 		//Check cache before driving unnecessary searches
963 963
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG);
964 964
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
965
-		if(!is_null($ldap_groups)) {
965
+		if (!is_null($ldap_groups)) {
966 966
 			return $ldap_groups;
967 967
 		}
968 968
 
969 969
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
970 970
 		// error. With a limit of 0, we get 0 results. So we pass null.
971
-		if($limit <= 0) {
971
+		if ($limit <= 0) {
972 972
 			$limit = null;
973 973
 		}
974 974
 		$filter = $this->access->combineFilterWithAnd(array(
@@ -1000,11 +1000,11 @@  discard block
 block discarded – undo
1000 1000
 	 * (active directory has a limit of 1000 by default)
1001 1001
 	 */
1002 1002
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1003
-		if(!$this->enabled) {
1003
+		if (!$this->enabled) {
1004 1004
 			return array();
1005 1005
 		}
1006 1006
 		$search = $this->access->escapeFilterPart($search, true);
1007
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1007
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1008 1008
 		if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) {
1009 1009
 			return $this->getGroupsChunk($search, $limit, $offset);
1010 1010
 		}
@@ -1047,20 +1047,20 @@  discard block
 block discarded – undo
1047 1047
 	 */
1048 1048
 	public function groupExists($gid) {
1049 1049
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1050
-		if(!is_null($groupExists)) {
1051
-			return (bool)$groupExists;
1050
+		if (!is_null($groupExists)) {
1051
+			return (bool) $groupExists;
1052 1052
 		}
1053 1053
 
1054 1054
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1055 1055
 		//only, requires more checking.
1056 1056
 		$dn = $this->access->groupname2dn($gid);
1057
-		if(!$dn) {
1057
+		if (!$dn) {
1058 1058
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1059 1059
 			return false;
1060 1060
 		}
1061 1061
 
1062 1062
 		//if group really still exists, we will be able to read its objectclass
1063
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1063
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1064 1064
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1065 1065
 			return false;
1066 1066
 		}
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 	* compared with GroupInterface::CREATE_GROUP etc.
1079 1079
 	*/
1080 1080
 	public function implementsActions($actions) {
1081
-		return (bool)((GroupInterface::COUNT_USERS |
1081
+		return (bool) ((GroupInterface::COUNT_USERS |
1082 1082
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1083 1083
 	}
1084 1084
 
Please login to merge, or discard this patch.
apps/dav/lib/Upload/UploadHome.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	function createFile($name, $data = null) {
43
-		throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
43
+		throw new Forbidden('Permission denied to create file (filename '.$name.')');
44 44
 	}
45 45
 
46 46
 	function createDirectory($name) {
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
 		$rootView = new View();
86 86
 		$user = \OC::$server->getUserSession()->getUser();
87 87
 		Filesystem::initMountPoints($user->getUID());
88
-		if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) {
89
-			$rootView->mkdir('/' . $user->getUID() . '/uploads');
88
+		if (!$rootView->file_exists('/'.$user->getUID().'/uploads')) {
89
+			$rootView->mkdir('/'.$user->getUID().'/uploads');
90 90
 		}
91
-		$view = new View('/' . $user->getUID() . '/uploads');
91
+		$view = new View('/'.$user->getUID().'/uploads');
92 92
 		$rootInfo = $view->getFileInfo('');
93 93
 		return new Directory($view, $rootInfo);
94 94
 	}
Please login to merge, or discard this patch.
apps/encryption/lib/Crypto/Crypt.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 				['app' => 'encryption']);
119 119
 
120 120
 			if (openssl_error_string()) {
121
-				$log->error('Encryption library openssl_pkey_new() fails: ' . openssl_error_string(),
121
+				$log->error('Encryption library openssl_pkey_new() fails: '.openssl_error_string(),
122 122
 					['app' => 'encryption']);
123 123
 			}
124 124
 		} elseif (openssl_pkey_export($res,
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 				'privateKey' => $privateKey
134 134
 			];
135 135
 		}
136
-		$log->error('Encryption library couldn\'t export users private key, please check your servers OpenSSL configuration.' . $this->user,
136
+		$log->error('Encryption library couldn\'t export users private key, please check your servers OpenSSL configuration.'.$this->user,
137 137
 			['app' => 'encryption']);
138 138
 		if (openssl_error_string()) {
139
-			$log->error('Encryption Library:' . openssl_error_string(),
139
+			$log->error('Encryption Library:'.openssl_error_string(),
140 140
 				['app' => 'encryption']);
141 141
 		}
142 142
 
@@ -209,15 +209,15 @@  discard block
 block discarded – undo
209 209
 	public function generateHeader($keyFormat = 'hash') {
210 210
 
211 211
 		if (in_array($keyFormat, $this->supportedKeyFormats, true) === false) {
212
-			throw new \InvalidArgumentException('key format "' . $keyFormat . '" is not supported');
212
+			throw new \InvalidArgumentException('key format "'.$keyFormat.'" is not supported');
213 213
 		}
214 214
 
215 215
 		$cipher = $this->getCipher();
216 216
 
217 217
 		$header = self::HEADER_START
218
-			. ':cipher:' . $cipher
219
-			. ':keyFormat:' . $keyFormat
220
-			. ':' . self::HEADER_END;
218
+			. ':cipher:'.$cipher
219
+			. ':keyFormat:'.$keyFormat
220
+			. ':'.self::HEADER_END;
221 221
 
222 222
 		return $header;
223 223
 	}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
 		if (!$encryptedContent) {
241 241
 			$error = 'Encryption (symmetric) of content failed';
242
-			$this->logger->error($error . openssl_error_string(),
242
+			$this->logger->error($error.openssl_error_string(),
243 243
 				['app' => 'encryption']);
244 244
 			throw new EncryptionFailedException($error);
245 245
 		}
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 		}
268 268
 
269 269
 		// Workaround for OpenSSL 0.9.8. Fallback to an old cipher that should work.
270
-		if(OPENSSL_VERSION_NUMBER < 0x1000101f) {
271
-			if($cipher === 'AES-256-CTR' || $cipher === 'AES-128-CTR') {
270
+		if (OPENSSL_VERSION_NUMBER < 0x1000101f) {
271
+			if ($cipher === 'AES-256-CTR' || $cipher === 'AES-128-CTR') {
272 272
 				$cipher = self::LEGACY_CIPHER;
273 273
 			}
274 274
 		}
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 * @throws \InvalidArgumentException
285 285
 	 */
286 286
 	protected function getKeySize($cipher) {
287
-		if(isset($this->supportedCiphersAndKeySize[$cipher])) {
287
+		if (isset($this->supportedCiphersAndKeySize[$cipher])) {
288 288
 			return $this->supportedCiphersAndKeySize[$cipher];
289 289
 		}
290 290
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @return string
312 312
 	 */
313 313
 	private function concatIV($encryptedContent, $iv) {
314
-		return $encryptedContent . '00iv00' . $iv;
314
+		return $encryptedContent.'00iv00'.$iv;
315 315
 	}
316 316
 
317 317
 	/**
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * @return string
321 321
 	 */
322 322
 	private function concatSig($encryptedContent, $signature) {
323
-		return $encryptedContent . '00sig00' . $signature;
323
+		return $encryptedContent.'00sig00'.$signature;
324 324
 	}
325 325
 
326 326
 	/**
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @return string
333 333
 	 */
334 334
 	private function addPadding($data) {
335
-		return $data . 'xxx';
335
+		return $data.'xxx';
336 336
 	}
337 337
 
338 338
 	/**
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	protected function generatePasswordHash($password, $cipher, $uid = '') {
347 347
 		$instanceId = $this->config->getSystemValue('instanceid');
348 348
 		$instanceSecret = $this->config->getSystemValue('secret');
349
-		$salt = hash('sha256', $uid . $instanceId . $instanceSecret, true);
349
+		$salt = hash('sha256', $uid.$instanceId.$instanceSecret, true);
350 350
 		$keySize = $this->getKeySize($cipher);
351 351
 
352 352
 		$hash = hash_pbkdf2(
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @return string
493 493
 	 */
494 494
 	private function createSignature($data, $passPhrase) {
495
-		$passPhrase = hash('sha512', $passPhrase . 'a', true);
495
+		$passPhrase = hash('sha512', $passPhrase.'a', true);
496 496
 		return hash_hmac('sha256', $data, $passPhrase);
497 497
 	}
498 498
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		if ($plainContent) {
584 584
 			return $plainContent;
585 585
 		} else {
586
-			throw new DecryptionFailedException('Encryption library: Decryption (symmetric) of content failed: ' . openssl_error_string());
586
+			throw new DecryptionFailedException('Encryption library: Decryption (symmetric) of content failed: '.openssl_error_string());
587 587
 		}
588 588
 	}
589 589
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 		if (openssl_open($encKeyFile, $plainContent, $shareKey, $privateKey)) {
650 650
 			return $plainContent;
651 651
 		} else {
652
-			throw new MultiKeyDecryptException('multikeydecrypt with share key failed:' . openssl_error_string());
652
+			throw new MultiKeyDecryptException('multikeydecrypt with share key failed:'.openssl_error_string());
653 653
 		}
654 654
 	}
655 655
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 				'data' => $sealed
686 686
 			];
687 687
 		} else {
688
-			throw new MultiKeyEncryptException('multikeyencryption failed ' . openssl_error_string());
688
+			throw new MultiKeyEncryptException('multikeyencryption failed '.openssl_error_string());
689 689
 		}
690 690
 	}
691 691
 }
Please login to merge, or discard this patch.