@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | parent::__construct($access); |
58 | 58 | $filter = $this->access->connection->ldapGroupFilter; |
59 | 59 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
60 | - if(!empty($filter) && !empty($gassoc)) { |
|
60 | + if (!empty($filter) && !empty($gassoc)) { |
|
61 | 61 | $this->enabled = true; |
62 | 62 | } |
63 | 63 | |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | * Checks whether the user is member of a group or not. |
75 | 75 | */ |
76 | 76 | public function inGroup($uid, $gid) { |
77 | - if(!$this->enabled) { |
|
77 | + if (!$this->enabled) { |
|
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
81 | 81 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
82 | - if(!is_null($inGroup)) { |
|
83 | - return (bool)$inGroup; |
|
82 | + if (!is_null($inGroup)) { |
|
83 | + return (bool) $inGroup; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $userDN = $this->access->username2dn($uid); |
87 | 87 | |
88 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
88 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
89 | 89 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
90 | 90 | return $isInGroup; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
94 | 94 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
95 | - if(!is_null($members)) { |
|
95 | + if (!is_null($members)) { |
|
96 | 96 | $this->cachedGroupMembers[$gid] = $members; |
97 | 97 | $isInGroup = in_array($userDN, $members); |
98 | 98 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | |
102 | 102 | $groupDN = $this->access->groupname2dn($gid); |
103 | 103 | // just in case |
104 | - if(!$groupDN || !$userDN) { |
|
104 | + if (!$groupDN || !$userDN) { |
|
105 | 105 | $this->access->connection->writeToCache($cacheKey, false); |
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | |
109 | 109 | //check primary group first |
110 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
110 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
111 | 111 | $this->access->connection->writeToCache($cacheKey, true); |
112 | 112 | return true; |
113 | 113 | } |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
116 | 116 | $members = $this->_groupMembers($groupDN); |
117 | 117 | $members = array_keys($members); // uids are returned as keys |
118 | - if(!is_array($members) || count($members) === 0) { |
|
118 | + if (!is_array($members) || count($members) === 0) { |
|
119 | 119 | $this->access->connection->writeToCache($cacheKey, false); |
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | 123 | //extra work if we don't get back user DNs |
124 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
124 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
125 | 125 | $dns = array(); |
126 | 126 | $filterParts = array(); |
127 | 127 | $bytes = 0; |
128 | - foreach($members as $mid) { |
|
128 | + foreach ($members as $mid) { |
|
129 | 129 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
130 | 130 | $filterParts[] = $filter; |
131 | 131 | $bytes += strlen($filter); |
132 | - if($bytes >= 9000000) { |
|
132 | + if ($bytes >= 9000000) { |
|
133 | 133 | // AD has a default input buffer of 10 MB, we do not want |
134 | 134 | // to take even the chance to exceed it |
135 | 135 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $dns = array_merge($dns, $users); |
140 | 140 | } |
141 | 141 | } |
142 | - if(count($filterParts) > 0) { |
|
142 | + if (count($filterParts) > 0) { |
|
143 | 143 | $filter = $this->access->combineFilterWithOr($filterParts); |
144 | 144 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
145 | 145 | $dns = array_merge($dns, $users); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | $pos = strpos($memberURLs[0], '('); |
183 | 183 | if ($pos !== false) { |
184 | 184 | $memberUrlFilter = substr($memberURLs[0], $pos); |
185 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
185 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
186 | 186 | $dynamicMembers = array(); |
187 | - foreach($foundMembers as $value) { |
|
187 | + foreach ($foundMembers as $value) { |
|
188 | 188 | $dynamicMembers[$value['dn'][0]] = 1; |
189 | 189 | } |
190 | 190 | } else { |
191 | 191 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
192 | - 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
192 | + 'of group '.$dnGroup, \OCP\Util::DEBUG); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | return $dynamicMembers; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | // used extensively in cron job, caching makes sense for nested groups |
213 | 213 | $cacheKey = '_groupMembers'.$dnGroup; |
214 | 214 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
215 | - if(!is_null($groupMembers)) { |
|
215 | + if (!is_null($groupMembers)) { |
|
216 | 216 | return $groupMembers; |
217 | 217 | } |
218 | 218 | $seen[$dnGroup] = 1; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | return array(); |
257 | 257 | } |
258 | 258 | $groups = $this->access->groupsMatchFilter($groups); |
259 | - $allGroups = $groups; |
|
259 | + $allGroups = $groups; |
|
260 | 260 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
261 | 261 | if (intval($nestedGroups) === 1) { |
262 | 262 | foreach ($groups as $group) { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | public function gidNumber2Name($gid, $dn) { |
277 | 277 | $cacheKey = 'gidNumberToName'; |
278 | 278 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
279 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
279 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
280 | 280 | return $groupNames[$gid]; |
281 | 281 | } |
282 | 282 | |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | $filter = $this->access->combineFilterWithAnd([ |
285 | 285 | $this->access->connection->ldapGroupFilter, |
286 | 286 | 'objectClass=posixGroup', |
287 | - $this->access->connection->ldapGidNumber . '=' . $gid |
|
287 | + $this->access->connection->ldapGidNumber.'='.$gid |
|
288 | 288 | ]); |
289 | 289 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
290 | - if(empty($result)) { |
|
290 | + if (empty($result)) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | $dn = $result[0]['dn'][0]; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | private function getEntryGidNumber($dn, $attribute) { |
312 | 312 | $value = $this->access->readAttribute($dn, $attribute); |
313 | - if(is_array($value) && !empty($value)) { |
|
313 | + if (is_array($value) && !empty($value)) { |
|
314 | 314 | return $value[0]; |
315 | 315 | } |
316 | 316 | return false; |
@@ -332,9 +332,9 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function getUserGidNumber($dn) { |
334 | 334 | $gidNumber = false; |
335 | - if($this->access->connection->hasGidNumber) { |
|
335 | + if ($this->access->connection->hasGidNumber) { |
|
336 | 336 | $gidNumber = $this->getEntryGidNumber($dn, 'gidNumber'); |
337 | - if($gidNumber === false) { |
|
337 | + if ($gidNumber === false) { |
|
338 | 338 | $this->access->connection->hasGidNumber = false; |
339 | 339 | } |
340 | 340 | } |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | */ |
352 | 352 | private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') { |
353 | 353 | $groupID = $this->getGroupGidNumber($groupDN); |
354 | - if($groupID === false) { |
|
354 | + if ($groupID === false) { |
|
355 | 355 | throw new \Exception('Not a valid group'); |
356 | 356 | } |
357 | 357 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | if ($search !== '') { |
361 | 361 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
362 | 362 | } |
363 | - $filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; |
|
363 | + $filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID; |
|
364 | 364 | |
365 | 365 | $filter = $this->access->combineFilterWithAnd($filterParts); |
366 | 366 | |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | try { |
405 | 405 | $filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search); |
406 | 406 | $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); |
407 | - return (int)$users; |
|
407 | + return (int) $users; |
|
408 | 408 | } catch (\Exception $e) { |
409 | 409 | return 0; |
410 | 410 | } |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | */ |
418 | 418 | public function getUserGroupByGid($dn) { |
419 | 419 | $groupID = $this->getUserGidNumber($dn); |
420 | - if($groupID !== false) { |
|
420 | + if ($groupID !== false) { |
|
421 | 421 | $groupName = $this->gidNumber2Name($groupID, $dn); |
422 | - if($groupName !== false) { |
|
422 | + if ($groupName !== false) { |
|
423 | 423 | return $groupName; |
424 | 424 | } |
425 | 425 | } |
@@ -436,22 +436,22 @@ discard block |
||
436 | 436 | public function primaryGroupID2Name($gid, $dn) { |
437 | 437 | $cacheKey = 'primaryGroupIDtoName'; |
438 | 438 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
439 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
439 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
440 | 440 | return $groupNames[$gid]; |
441 | 441 | } |
442 | 442 | |
443 | 443 | $domainObjectSid = $this->access->getSID($dn); |
444 | - if($domainObjectSid === false) { |
|
444 | + if ($domainObjectSid === false) { |
|
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | |
448 | 448 | //we need to get the DN from LDAP |
449 | 449 | $filter = $this->access->combineFilterWithAnd(array( |
450 | 450 | $this->access->connection->ldapGroupFilter, |
451 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
451 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
452 | 452 | )); |
453 | 453 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
454 | - if(empty($result)) { |
|
454 | + if (empty($result)) { |
|
455 | 455 | return false; |
456 | 456 | } |
457 | 457 | $dn = $result[0]['dn'][0]; |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | */ |
475 | 475 | private function getEntryGroupID($dn, $attribute) { |
476 | 476 | $value = $this->access->readAttribute($dn, $attribute); |
477 | - if(is_array($value) && !empty($value)) { |
|
477 | + if (is_array($value) && !empty($value)) { |
|
478 | 478 | return $value[0]; |
479 | 479 | } |
480 | 480 | return false; |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | */ |
497 | 497 | public function getUserPrimaryGroupIDs($dn) { |
498 | 498 | $primaryGroupID = false; |
499 | - if($this->access->connection->hasPrimaryGroups) { |
|
499 | + if ($this->access->connection->hasPrimaryGroups) { |
|
500 | 500 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
501 | - if($primaryGroupID === false) { |
|
501 | + if ($primaryGroupID === false) { |
|
502 | 502 | $this->access->connection->hasPrimaryGroups = false; |
503 | 503 | } |
504 | 504 | } |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | */ |
516 | 516 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
517 | 517 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
518 | - if($groupID === false) { |
|
518 | + if ($groupID === false) { |
|
519 | 519 | throw new \Exception('Not a valid group'); |
520 | 520 | } |
521 | 521 | |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | if ($search !== '') { |
525 | 525 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
526 | 526 | } |
527 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
527 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
528 | 528 | |
529 | 529 | $filter = $this->access->combineFilterWithAnd($filterParts); |
530 | 530 | |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | try { |
569 | 569 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
570 | 570 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
571 | - return (int)$users; |
|
571 | + return (int) $users; |
|
572 | 572 | } catch (\Exception $e) { |
573 | 573 | return 0; |
574 | 574 | } |
@@ -581,9 +581,9 @@ discard block |
||
581 | 581 | */ |
582 | 582 | public function getUserPrimaryGroup($dn) { |
583 | 583 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
584 | - if($groupID !== false) { |
|
584 | + if ($groupID !== false) { |
|
585 | 585 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
586 | - if($groupName !== false) { |
|
586 | + if ($groupName !== false) { |
|
587 | 587 | return $groupName; |
588 | 588 | } |
589 | 589 | } |
@@ -602,16 +602,16 @@ discard block |
||
602 | 602 | * This function includes groups based on dynamic group membership. |
603 | 603 | */ |
604 | 604 | public function getUserGroups($uid) { |
605 | - if(!$this->enabled) { |
|
605 | + if (!$this->enabled) { |
|
606 | 606 | return array(); |
607 | 607 | } |
608 | 608 | $cacheKey = 'getUserGroups'.$uid; |
609 | 609 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
610 | - if(!is_null($userGroups)) { |
|
610 | + if (!is_null($userGroups)) { |
|
611 | 611 | return $userGroups; |
612 | 612 | } |
613 | 613 | $userDN = $this->access->username2dn($uid); |
614 | - if(!$userDN) { |
|
614 | + if (!$userDN) { |
|
615 | 615 | $this->access->connection->writeToCache($cacheKey, array()); |
616 | 616 | return array(); |
617 | 617 | } |
@@ -625,14 +625,14 @@ discard block |
||
625 | 625 | if (!empty($dynamicGroupMemberURL)) { |
626 | 626 | // look through dynamic groups to add them to the result array if needed |
627 | 627 | $groupsToMatch = $this->access->fetchListOfGroups( |
628 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
629 | - foreach($groupsToMatch as $dynamicGroup) { |
|
628 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
629 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
630 | 630 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
631 | 631 | continue; |
632 | 632 | } |
633 | 633 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
634 | 634 | if ($pos !== false) { |
635 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
635 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
636 | 636 | // apply filter via ldap search to see if this user is in this |
637 | 637 | // dynamic group |
638 | 638 | $userMatch = $this->access->readAttribute( |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | if ($userMatch !== false) { |
644 | 644 | // match found so this user is in this group |
645 | 645 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
646 | - if(is_string($groupName)) { |
|
646 | + if (is_string($groupName)) { |
|
647 | 647 | // be sure to never return false if the dn could not be |
648 | 648 | // resolved to a name, for whatever reason. |
649 | 649 | $groups[] = $groupName; |
@@ -651,21 +651,21 @@ discard block |
||
651 | 651 | } |
652 | 652 | } else { |
653 | 653 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
654 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
654 | + 'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
655 | 655 | } |
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | 659 | // if possible, read out membership via memberOf. It's far faster than |
660 | 660 | // performing a search, which still is a fallback later. |
661 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
661 | + if (intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
662 | 662 | && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
663 | 663 | ) { |
664 | 664 | $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
665 | 665 | if (is_array($groupDNs)) { |
666 | 666 | foreach ($groupDNs as $dn) { |
667 | 667 | $groupName = $this->access->dn2groupname($dn); |
668 | - if(is_string($groupName)) { |
|
668 | + if (is_string($groupName)) { |
|
669 | 669 | // be sure to never return false if the dn could not be |
670 | 670 | // resolved to a name, for whatever reason. |
671 | 671 | $groups[] = $groupName; |
@@ -673,10 +673,10 @@ discard block |
||
673 | 673 | } |
674 | 674 | } |
675 | 675 | |
676 | - if($primaryGroup !== false) { |
|
676 | + if ($primaryGroup !== false) { |
|
677 | 677 | $groups[] = $primaryGroup; |
678 | 678 | } |
679 | - if($gidGroupName !== false) { |
|
679 | + if ($gidGroupName !== false) { |
|
680 | 680 | $groups[] = $gidGroupName; |
681 | 681 | } |
682 | 682 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -684,14 +684,14 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
687 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
687 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
688 | 688 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
689 | 689 | ) { |
690 | 690 | $uid = $userDN; |
691 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
691 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
692 | 692 | $result = $this->access->readAttribute($userDN, 'uid'); |
693 | 693 | if ($result === false) { |
694 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
694 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
695 | 695 | $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
696 | 696 | } |
697 | 697 | $uid = $result[0]; |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $uid = $userDN; |
701 | 701 | } |
702 | 702 | |
703 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
703 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
704 | 704 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
705 | 705 | } else { |
706 | 706 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -709,10 +709,10 @@ discard block |
||
709 | 709 | $groups = array_merge($groups, $groupsByMember); |
710 | 710 | } |
711 | 711 | |
712 | - if($primaryGroup !== false) { |
|
712 | + if ($primaryGroup !== false) { |
|
713 | 713 | $groups[] = $primaryGroup; |
714 | 714 | } |
715 | - if($gidGroupName !== false) { |
|
715 | + if ($gidGroupName !== false) { |
|
716 | 716 | $groups[] = $gidGroupName; |
717 | 717 | } |
718 | 718 | |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
751 | 751 | if (!empty($nestedGroups)) { |
752 | 752 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
753 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
753 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
754 | 754 | $allGroups = array_merge($allGroups, $supergroups); |
755 | 755 | } |
756 | 756 | } |
@@ -769,33 +769,33 @@ discard block |
||
769 | 769 | * @return array with user ids |
770 | 770 | */ |
771 | 771 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
772 | - if(!$this->enabled) { |
|
772 | + if (!$this->enabled) { |
|
773 | 773 | return array(); |
774 | 774 | } |
775 | - if(!$this->groupExists($gid)) { |
|
775 | + if (!$this->groupExists($gid)) { |
|
776 | 776 | return array(); |
777 | 777 | } |
778 | 778 | $search = $this->access->escapeFilterPart($search, true); |
779 | 779 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
780 | 780 | // check for cache of the exact query |
781 | 781 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
782 | - if(!is_null($groupUsers)) { |
|
782 | + if (!is_null($groupUsers)) { |
|
783 | 783 | return $groupUsers; |
784 | 784 | } |
785 | 785 | |
786 | 786 | // check for cache of the query without limit and offset |
787 | 787 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
788 | - if(!is_null($groupUsers)) { |
|
788 | + if (!is_null($groupUsers)) { |
|
789 | 789 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
790 | 790 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
791 | 791 | return $groupUsers; |
792 | 792 | } |
793 | 793 | |
794 | - if($limit === -1) { |
|
794 | + if ($limit === -1) { |
|
795 | 795 | $limit = null; |
796 | 796 | } |
797 | 797 | $groupDN = $this->access->groupname2dn($gid); |
798 | - if(!$groupDN) { |
|
798 | + if (!$groupDN) { |
|
799 | 799 | // group couldn't be found, return empty resultset |
800 | 800 | $this->access->connection->writeToCache($cacheKey, array()); |
801 | 801 | return array(); |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | |
804 | 804 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
805 | 805 | $members = array_keys($this->_groupMembers($groupDN)); |
806 | - if(!$members && empty($primaryUsers)) { |
|
806 | + if (!$members && empty($primaryUsers)) { |
|
807 | 807 | //in case users could not be retrieved, return empty result set |
808 | 808 | $this->access->connection->writeToCache($cacheKey, array()); |
809 | 809 | return array(); |
@@ -812,29 +812,29 @@ discard block |
||
812 | 812 | $groupUsers = array(); |
813 | 813 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
814 | 814 | $attrs = $this->access->userManager->getAttributes(true); |
815 | - foreach($members as $member) { |
|
816 | - if($isMemberUid) { |
|
815 | + foreach ($members as $member) { |
|
816 | + if ($isMemberUid) { |
|
817 | 817 | //we got uids, need to get their DNs to 'translate' them to user names |
818 | 818 | $filter = $this->access->combineFilterWithAnd(array( |
819 | 819 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
820 | 820 | $this->access->getFilterPartForUserSearch($search) |
821 | 821 | )); |
822 | 822 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
823 | - if(count($ldap_users) < 1) { |
|
823 | + if (count($ldap_users) < 1) { |
|
824 | 824 | continue; |
825 | 825 | } |
826 | 826 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
827 | 827 | } else { |
828 | 828 | //we got DNs, check if we need to filter by search or we can give back all of them |
829 | 829 | if ($search !== '') { |
830 | - if(!$this->access->readAttribute($member, |
|
830 | + if (!$this->access->readAttribute($member, |
|
831 | 831 | $this->access->connection->ldapUserDisplayName, |
832 | 832 | $this->access->getFilterPartForUserSearch($search))) { |
833 | 833 | continue; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | // dn2username will also check if the users belong to the allowed base |
837 | - if($ocname = $this->access->dn2username($member)) { |
|
837 | + if ($ocname = $this->access->dn2username($member)) { |
|
838 | 838 | $groupUsers[] = $ocname; |
839 | 839 | } |
840 | 840 | } |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | */ |
860 | 860 | public function countUsersInGroup($gid, $search = '') { |
861 | 861 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
862 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
862 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
863 | 863 | return false; |
864 | 864 | } |
865 | 865 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
866 | - if(!is_null($groupUsers)) { |
|
866 | + if (!is_null($groupUsers)) { |
|
867 | 867 | return $groupUsers; |
868 | 868 | } |
869 | 869 | |
870 | 870 | $groupDN = $this->access->groupname2dn($gid); |
871 | - if(!$groupDN) { |
|
871 | + if (!$groupDN) { |
|
872 | 872 | // group couldn't be found, return empty result set |
873 | 873 | $this->access->connection->writeToCache($cacheKey, false); |
874 | 874 | return false; |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | |
877 | 877 | $members = array_keys($this->_groupMembers($groupDN)); |
878 | 878 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
879 | - if(!$members && $primaryUserCount === 0) { |
|
879 | + if (!$members && $primaryUserCount === 0) { |
|
880 | 880 | //in case users could not be retrieved, return empty result set |
881 | 881 | $this->access->connection->writeToCache($cacheKey, false); |
882 | 882 | return false; |
@@ -901,27 +901,27 @@ discard block |
||
901 | 901 | //For now this is not important, because the only use of this method |
902 | 902 | //does not supply a search string |
903 | 903 | $groupUsers = array(); |
904 | - foreach($members as $member) { |
|
905 | - if($isMemberUid) { |
|
904 | + foreach ($members as $member) { |
|
905 | + if ($isMemberUid) { |
|
906 | 906 | //we got uids, need to get their DNs to 'translate' them to user names |
907 | 907 | $filter = $this->access->combineFilterWithAnd(array( |
908 | 908 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
909 | 909 | $this->access->getFilterPartForUserSearch($search) |
910 | 910 | )); |
911 | 911 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
912 | - if(count($ldap_users) < 1) { |
|
912 | + if (count($ldap_users) < 1) { |
|
913 | 913 | continue; |
914 | 914 | } |
915 | 915 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
916 | 916 | } else { |
917 | 917 | //we need to apply the search filter now |
918 | - if(!$this->access->readAttribute($member, |
|
918 | + if (!$this->access->readAttribute($member, |
|
919 | 919 | $this->access->connection->ldapUserDisplayName, |
920 | 920 | $this->access->getFilterPartForUserSearch($search))) { |
921 | 921 | continue; |
922 | 922 | } |
923 | 923 | // dn2username will also check if the users belong to the allowed base |
924 | - if($ocname = $this->access->dn2username($member)) { |
|
924 | + if ($ocname = $this->access->dn2username($member)) { |
|
925 | 925 | $groupUsers[] = $ocname; |
926 | 926 | } |
927 | 927 | } |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | * Returns a list with all groups (used by getGroups) |
945 | 945 | */ |
946 | 946 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
947 | - if(!$this->enabled) { |
|
947 | + if (!$this->enabled) { |
|
948 | 948 | return array(); |
949 | 949 | } |
950 | 950 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -952,13 +952,13 @@ discard block |
||
952 | 952 | //Check cache before driving unnecessary searches |
953 | 953 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
954 | 954 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
955 | - if(!is_null($ldap_groups)) { |
|
955 | + if (!is_null($ldap_groups)) { |
|
956 | 956 | return $ldap_groups; |
957 | 957 | } |
958 | 958 | |
959 | 959 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
960 | 960 | // error. With a limit of 0, we get 0 results. So we pass null. |
961 | - if($limit <= 0) { |
|
961 | + if ($limit <= 0) { |
|
962 | 962 | $limit = null; |
963 | 963 | } |
964 | 964 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | * (active directory has a limit of 1000 by default) |
991 | 991 | */ |
992 | 992 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
993 | - if(!$this->enabled) { |
|
993 | + if (!$this->enabled) { |
|
994 | 994 | return array(); |
995 | 995 | } |
996 | 996 | $search = $this->access->escapeFilterPart($search, true); |
@@ -1037,20 +1037,20 @@ discard block |
||
1037 | 1037 | */ |
1038 | 1038 | public function groupExists($gid) { |
1039 | 1039 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
1040 | - if(!is_null($groupExists)) { |
|
1041 | - return (bool)$groupExists; |
|
1040 | + if (!is_null($groupExists)) { |
|
1041 | + return (bool) $groupExists; |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | //getting dn, if false the group does not exist. If dn, it may be mapped |
1045 | 1045 | //only, requires more checking. |
1046 | 1046 | $dn = $this->access->groupname2dn($gid); |
1047 | - if(!$dn) { |
|
1047 | + if (!$dn) { |
|
1048 | 1048 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1049 | 1049 | return false; |
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | //if group really still exists, we will be able to read its objectclass |
1053 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
1053 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
1054 | 1054 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1055 | 1055 | return false; |
1056 | 1056 | } |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
1069 | 1069 | */ |
1070 | 1070 | public function implementsActions($actions) { |
1071 | - return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
1071 | + return (bool) (\OC\Group\Backend::COUNT_USERS & $actions); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | /** |