@@ -64,7 +64,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | // used extensively in cron job, caching makes sense for nested groups |
222 | 222 | $cacheKey = '_groupMembers'.$dnGroup; |
223 | 223 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
224 | - if($groupMembers !== null) { |
|
224 | + if ($groupMembers !== null) { |
|
225 | 225 | return $groupMembers; |
226 | 226 | } |
227 | 227 | $seen[$dnGroup] = 1; |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | return array(); |
266 | 266 | } |
267 | 267 | $groups = $this->access->groupsMatchFilter($groups); |
268 | - $allGroups = $groups; |
|
268 | + $allGroups = $groups; |
|
269 | 269 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
270 | 270 | if (intval($nestedGroups) === 1) { |
271 | 271 | foreach ($groups as $group) { |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | * @return string|bool |
284 | 284 | */ |
285 | 285 | public function gidNumber2Name($gid, $dn) { |
286 | - $cacheKey = 'gidNumberToName' . $gid; |
|
286 | + $cacheKey = 'gidNumberToName'.$gid; |
|
287 | 287 | $groupName = $this->access->connection->getFromCache($cacheKey); |
288 | - if(!is_null($groupName) && isset($groupName)) { |
|
288 | + if (!is_null($groupName) && isset($groupName)) { |
|
289 | 289 | return $groupName; |
290 | 290 | } |
291 | 291 | |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | $filter = $this->access->combineFilterWithAnd([ |
294 | 294 | $this->access->connection->ldapGroupFilter, |
295 | 295 | 'objectClass=posixGroup', |
296 | - $this->access->connection->ldapGidNumber . '=' . $gid |
|
296 | + $this->access->connection->ldapGidNumber.'='.$gid |
|
297 | 297 | ]); |
298 | 298 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
299 | - if(empty($result)) { |
|
299 | + if (empty($result)) { |
|
300 | 300 | return false; |
301 | 301 | } |
302 | 302 | $dn = $result[0]['dn'][0]; |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | */ |
320 | 320 | private function getEntryGidNumber($dn, $attribute) { |
321 | 321 | $value = $this->access->readAttribute($dn, $attribute); |
322 | - if(is_array($value) && !empty($value)) { |
|
322 | + if (is_array($value) && !empty($value)) { |
|
323 | 323 | return $value[0]; |
324 | 324 | } |
325 | 325 | return false; |
@@ -341,9 +341,9 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function getUserGidNumber($dn) { |
343 | 343 | $gidNumber = false; |
344 | - if($this->access->connection->hasGidNumber) { |
|
344 | + if ($this->access->connection->hasGidNumber) { |
|
345 | 345 | $gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber); |
346 | - if($gidNumber === false) { |
|
346 | + if ($gidNumber === false) { |
|
347 | 347 | $this->access->connection->hasGidNumber = false; |
348 | 348 | } |
349 | 349 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | */ |
361 | 361 | private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') { |
362 | 362 | $groupID = $this->getGroupGidNumber($groupDN); |
363 | - if($groupID === false) { |
|
363 | + if ($groupID === false) { |
|
364 | 364 | throw new \Exception('Not a valid group'); |
365 | 365 | } |
366 | 366 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | if ($search !== '') { |
370 | 370 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
371 | 371 | } |
372 | - $filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; |
|
372 | + $filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID; |
|
373 | 373 | |
374 | 374 | $filter = $this->access->combineFilterWithAnd($filterParts); |
375 | 375 | |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | try { |
414 | 414 | $filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search); |
415 | 415 | $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); |
416 | - return (int)$users; |
|
416 | + return (int) $users; |
|
417 | 417 | } catch (\Exception $e) { |
418 | 418 | return 0; |
419 | 419 | } |
@@ -426,9 +426,9 @@ discard block |
||
426 | 426 | */ |
427 | 427 | public function getUserGroupByGid($dn) { |
428 | 428 | $groupID = $this->getUserGidNumber($dn); |
429 | - if($groupID !== false) { |
|
429 | + if ($groupID !== false) { |
|
430 | 430 | $groupName = $this->gidNumber2Name($groupID, $dn); |
431 | - if($groupName !== false) { |
|
431 | + if ($groupName !== false) { |
|
432 | 432 | return $groupName; |
433 | 433 | } |
434 | 434 | } |
@@ -445,22 +445,22 @@ discard block |
||
445 | 445 | public function primaryGroupID2Name($gid, $dn) { |
446 | 446 | $cacheKey = 'primaryGroupIDtoName'; |
447 | 447 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
448 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
448 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
449 | 449 | return $groupNames[$gid]; |
450 | 450 | } |
451 | 451 | |
452 | 452 | $domainObjectSid = $this->access->getSID($dn); |
453 | - if($domainObjectSid === false) { |
|
453 | + if ($domainObjectSid === false) { |
|
454 | 454 | return false; |
455 | 455 | } |
456 | 456 | |
457 | 457 | //we need to get the DN from LDAP |
458 | 458 | $filter = $this->access->combineFilterWithAnd(array( |
459 | 459 | $this->access->connection->ldapGroupFilter, |
460 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
460 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
461 | 461 | )); |
462 | 462 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
463 | - if(empty($result)) { |
|
463 | + if (empty($result)) { |
|
464 | 464 | return false; |
465 | 465 | } |
466 | 466 | $dn = $result[0]['dn'][0]; |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | */ |
484 | 484 | private function getEntryGroupID($dn, $attribute) { |
485 | 485 | $value = $this->access->readAttribute($dn, $attribute); |
486 | - if(is_array($value) && !empty($value)) { |
|
486 | + if (is_array($value) && !empty($value)) { |
|
487 | 487 | return $value[0]; |
488 | 488 | } |
489 | 489 | return false; |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | */ |
506 | 506 | public function getUserPrimaryGroupIDs($dn) { |
507 | 507 | $primaryGroupID = false; |
508 | - if($this->access->connection->hasPrimaryGroups) { |
|
508 | + if ($this->access->connection->hasPrimaryGroups) { |
|
509 | 509 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
510 | - if($primaryGroupID === false) { |
|
510 | + if ($primaryGroupID === false) { |
|
511 | 511 | $this->access->connection->hasPrimaryGroups = false; |
512 | 512 | } |
513 | 513 | } |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | */ |
525 | 525 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
526 | 526 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
527 | - if($groupID === false) { |
|
527 | + if ($groupID === false) { |
|
528 | 528 | throw new \Exception('Not a valid group'); |
529 | 529 | } |
530 | 530 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | if ($search !== '') { |
534 | 534 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
535 | 535 | } |
536 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
536 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
537 | 537 | |
538 | 538 | $filter = $this->access->combineFilterWithAnd($filterParts); |
539 | 539 | |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | try { |
578 | 578 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
579 | 579 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
580 | - return (int)$users; |
|
580 | + return (int) $users; |
|
581 | 581 | } catch (\Exception $e) { |
582 | 582 | return 0; |
583 | 583 | } |
@@ -590,9 +590,9 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function getUserPrimaryGroup($dn) { |
592 | 592 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
593 | - if($groupID !== false) { |
|
593 | + if ($groupID !== false) { |
|
594 | 594 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
595 | - if($groupName !== false) { |
|
595 | + if ($groupName !== false) { |
|
596 | 596 | return $groupName; |
597 | 597 | } |
598 | 598 | } |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | * This function includes groups based on dynamic group membership. |
612 | 612 | */ |
613 | 613 | public function getUserGroups($uid) { |
614 | - if(!$this->enabled) { |
|
614 | + if (!$this->enabled) { |
|
615 | 615 | return array(); |
616 | 616 | } |
617 | 617 | $cacheKey = 'getUserGroups'.$uid; |
618 | 618 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
619 | - if(!is_null($userGroups)) { |
|
619 | + if (!is_null($userGroups)) { |
|
620 | 620 | return $userGroups; |
621 | 621 | } |
622 | 622 | $userDN = $this->access->username2dn($uid); |
623 | - if(!$userDN) { |
|
623 | + if (!$userDN) { |
|
624 | 624 | $this->access->connection->writeToCache($cacheKey, array()); |
625 | 625 | return array(); |
626 | 626 | } |
@@ -634,14 +634,14 @@ discard block |
||
634 | 634 | if (!empty($dynamicGroupMemberURL)) { |
635 | 635 | // look through dynamic groups to add them to the result array if needed |
636 | 636 | $groupsToMatch = $this->access->fetchListOfGroups( |
637 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
638 | - foreach($groupsToMatch as $dynamicGroup) { |
|
637 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
638 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
639 | 639 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
640 | 640 | continue; |
641 | 641 | } |
642 | 642 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
643 | 643 | if ($pos !== false) { |
644 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
644 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
645 | 645 | // apply filter via ldap search to see if this user is in this |
646 | 646 | // dynamic group |
647 | 647 | $userMatch = $this->access->readAttribute( |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | if ($userMatch !== false) { |
653 | 653 | // match found so this user is in this group |
654 | 654 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
655 | - if(is_string($groupName)) { |
|
655 | + if (is_string($groupName)) { |
|
656 | 656 | // be sure to never return false if the dn could not be |
657 | 657 | // resolved to a name, for whatever reason. |
658 | 658 | $groups[] = $groupName; |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | } |
661 | 661 | } else { |
662 | 662 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
663 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
663 | + 'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
664 | 664 | } |
665 | 665 | } |
666 | 666 | } |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | // if possible, read out membership via memberOf. It's far faster than |
669 | 669 | // performing a search, which still is a fallback later. |
670 | 670 | // memberof doesn't support memberuid, so skip it here. |
671 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
671 | + if (intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
672 | 672 | && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
673 | 673 | && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid' |
674 | 674 | ) { |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | if (is_array($groupDNs)) { |
677 | 677 | foreach ($groupDNs as $dn) { |
678 | 678 | $groupName = $this->access->dn2groupname($dn); |
679 | - if(is_string($groupName)) { |
|
679 | + if (is_string($groupName)) { |
|
680 | 680 | // be sure to never return false if the dn could not be |
681 | 681 | // resolved to a name, for whatever reason. |
682 | 682 | $groups[] = $groupName; |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | - if($primaryGroup !== false) { |
|
687 | + if ($primaryGroup !== false) { |
|
688 | 688 | $groups[] = $primaryGroup; |
689 | 689 | } |
690 | - if($gidGroupName !== false) { |
|
690 | + if ($gidGroupName !== false) { |
|
691 | 691 | $groups[] = $gidGroupName; |
692 | 692 | } |
693 | 693 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
698 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
698 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
699 | 699 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
700 | 700 | ) { |
701 | 701 | $uid = $userDN; |
702 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
702 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
703 | 703 | $result = $this->access->readAttribute($userDN, 'uid'); |
704 | 704 | if ($result === false) { |
705 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
705 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
706 | 706 | $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
707 | 707 | } |
708 | 708 | $uid = $result[0]; |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | $uid = $userDN; |
712 | 712 | } |
713 | 713 | |
714 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
714 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
715 | 715 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
716 | 716 | } else { |
717 | 717 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | $groups = array_merge($groups, $groupsByMember); |
721 | 721 | } |
722 | 722 | |
723 | - if($primaryGroup !== false) { |
|
723 | + if ($primaryGroup !== false) { |
|
724 | 724 | $groups[] = $primaryGroup; |
725 | 725 | } |
726 | - if($gidGroupName !== false) { |
|
726 | + if ($gidGroupName !== false) { |
|
727 | 727 | $groups[] = $gidGroupName; |
728 | 728 | } |
729 | 729 | |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
762 | 762 | if (!empty($nestedGroups)) { |
763 | 763 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
764 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
764 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
765 | 765 | $allGroups = array_merge($allGroups, $supergroups); |
766 | 766 | } |
767 | 767 | } |
@@ -780,33 +780,33 @@ discard block |
||
780 | 780 | * @return array with user ids |
781 | 781 | */ |
782 | 782 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
783 | - if(!$this->enabled) { |
|
783 | + if (!$this->enabled) { |
|
784 | 784 | return array(); |
785 | 785 | } |
786 | - if(!$this->groupExists($gid)) { |
|
786 | + if (!$this->groupExists($gid)) { |
|
787 | 787 | return array(); |
788 | 788 | } |
789 | 789 | $search = $this->access->escapeFilterPart($search, true); |
790 | 790 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
791 | 791 | // check for cache of the exact query |
792 | 792 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
793 | - if(!is_null($groupUsers)) { |
|
793 | + if (!is_null($groupUsers)) { |
|
794 | 794 | return $groupUsers; |
795 | 795 | } |
796 | 796 | |
797 | 797 | // check for cache of the query without limit and offset |
798 | 798 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
799 | - if(!is_null($groupUsers)) { |
|
799 | + if (!is_null($groupUsers)) { |
|
800 | 800 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
801 | 801 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
802 | 802 | return $groupUsers; |
803 | 803 | } |
804 | 804 | |
805 | - if($limit === -1) { |
|
805 | + if ($limit === -1) { |
|
806 | 806 | $limit = null; |
807 | 807 | } |
808 | 808 | $groupDN = $this->access->groupname2dn($gid); |
809 | - if(!$groupDN) { |
|
809 | + if (!$groupDN) { |
|
810 | 810 | // group couldn't be found, return empty resultset |
811 | 811 | $this->access->connection->writeToCache($cacheKey, array()); |
812 | 812 | return array(); |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
816 | 816 | $posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset); |
817 | 817 | $members = array_keys($this->_groupMembers($groupDN)); |
818 | - if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
818 | + if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
819 | 819 | //in case users could not be retrieved, return empty result set |
820 | 820 | $this->access->connection->writeToCache($cacheKey, []); |
821 | 821 | return []; |
@@ -824,29 +824,29 @@ discard block |
||
824 | 824 | $groupUsers = array(); |
825 | 825 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
826 | 826 | $attrs = $this->access->userManager->getAttributes(true); |
827 | - foreach($members as $member) { |
|
828 | - if($isMemberUid) { |
|
827 | + foreach ($members as $member) { |
|
828 | + if ($isMemberUid) { |
|
829 | 829 | //we got uids, need to get their DNs to 'translate' them to user names |
830 | 830 | $filter = $this->access->combineFilterWithAnd(array( |
831 | 831 | str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter), |
832 | 832 | $this->access->getFilterPartForUserSearch($search) |
833 | 833 | )); |
834 | 834 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
835 | - if(count($ldap_users) < 1) { |
|
835 | + if (count($ldap_users) < 1) { |
|
836 | 836 | continue; |
837 | 837 | } |
838 | 838 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
839 | 839 | } else { |
840 | 840 | //we got DNs, check if we need to filter by search or we can give back all of them |
841 | 841 | if ($search !== '') { |
842 | - if(!$this->access->readAttribute($member, |
|
842 | + if (!$this->access->readAttribute($member, |
|
843 | 843 | $this->access->connection->ldapUserDisplayName, |
844 | 844 | $this->access->getFilterPartForUserSearch($search))) { |
845 | 845 | continue; |
846 | 846 | } |
847 | 847 | } |
848 | 848 | // dn2username will also check if the users belong to the allowed base |
849 | - if($ocname = $this->access->dn2username($member)) { |
|
849 | + if ($ocname = $this->access->dn2username($member)) { |
|
850 | 850 | $groupUsers[] = $ocname; |
851 | 851 | } |
852 | 852 | } |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | } |
875 | 875 | |
876 | 876 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
877 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
877 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
878 | 878 | return false; |
879 | 879 | } |
880 | 880 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
881 | - if(!is_null($groupUsers)) { |
|
881 | + if (!is_null($groupUsers)) { |
|
882 | 882 | return $groupUsers; |
883 | 883 | } |
884 | 884 | |
885 | 885 | $groupDN = $this->access->groupname2dn($gid); |
886 | - if(!$groupDN) { |
|
886 | + if (!$groupDN) { |
|
887 | 887 | // group couldn't be found, return empty result set |
888 | 888 | $this->access->connection->writeToCache($cacheKey, false); |
889 | 889 | return false; |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | |
892 | 892 | $members = array_keys($this->_groupMembers($groupDN)); |
893 | 893 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
894 | - if(!$members && $primaryUserCount === 0) { |
|
894 | + if (!$members && $primaryUserCount === 0) { |
|
895 | 895 | //in case users could not be retrieved, return empty result set |
896 | 896 | $this->access->connection->writeToCache($cacheKey, false); |
897 | 897 | return false; |
@@ -916,27 +916,27 @@ discard block |
||
916 | 916 | //For now this is not important, because the only use of this method |
917 | 917 | //does not supply a search string |
918 | 918 | $groupUsers = array(); |
919 | - foreach($members as $member) { |
|
920 | - if($isMemberUid) { |
|
919 | + foreach ($members as $member) { |
|
920 | + if ($isMemberUid) { |
|
921 | 921 | //we got uids, need to get their DNs to 'translate' them to user names |
922 | 922 | $filter = $this->access->combineFilterWithAnd(array( |
923 | 923 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
924 | 924 | $this->access->getFilterPartForUserSearch($search) |
925 | 925 | )); |
926 | 926 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
927 | - if(count($ldap_users) < 1) { |
|
927 | + if (count($ldap_users) < 1) { |
|
928 | 928 | continue; |
929 | 929 | } |
930 | 930 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
931 | 931 | } else { |
932 | 932 | //we need to apply the search filter now |
933 | - if(!$this->access->readAttribute($member, |
|
933 | + if (!$this->access->readAttribute($member, |
|
934 | 934 | $this->access->connection->ldapUserDisplayName, |
935 | 935 | $this->access->getFilterPartForUserSearch($search))) { |
936 | 936 | continue; |
937 | 937 | } |
938 | 938 | // dn2username will also check if the users belong to the allowed base |
939 | - if($ocname = $this->access->dn2username($member)) { |
|
939 | + if ($ocname = $this->access->dn2username($member)) { |
|
940 | 940 | $groupUsers[] = $ocname; |
941 | 941 | } |
942 | 942 | } |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | * Returns a list with all groups (used by getGroups) |
960 | 960 | */ |
961 | 961 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
962 | - if(!$this->enabled) { |
|
962 | + if (!$this->enabled) { |
|
963 | 963 | return array(); |
964 | 964 | } |
965 | 965 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -967,13 +967,13 @@ discard block |
||
967 | 967 | //Check cache before driving unnecessary searches |
968 | 968 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
969 | 969 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
970 | - if(!is_null($ldap_groups)) { |
|
970 | + if (!is_null($ldap_groups)) { |
|
971 | 971 | return $ldap_groups; |
972 | 972 | } |
973 | 973 | |
974 | 974 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
975 | 975 | // error. With a limit of 0, we get 0 results. So we pass null. |
976 | - if($limit <= 0) { |
|
976 | + if ($limit <= 0) { |
|
977 | 977 | $limit = null; |
978 | 978 | } |
979 | 979 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | * (active directory has a limit of 1000 by default) |
1006 | 1006 | */ |
1007 | 1007 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
1008 | - if(!$this->enabled) { |
|
1008 | + if (!$this->enabled) { |
|
1009 | 1009 | return array(); |
1010 | 1010 | } |
1011 | 1011 | $search = $this->access->escapeFilterPart($search, true); |
@@ -1052,20 +1052,20 @@ discard block |
||
1052 | 1052 | */ |
1053 | 1053 | public function groupExists($gid) { |
1054 | 1054 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
1055 | - if(!is_null($groupExists)) { |
|
1056 | - return (bool)$groupExists; |
|
1055 | + if (!is_null($groupExists)) { |
|
1056 | + return (bool) $groupExists; |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | //getting dn, if false the group does not exist. If dn, it may be mapped |
1060 | 1060 | //only, requires more checking. |
1061 | 1061 | $dn = $this->access->groupname2dn($gid); |
1062 | - if(!$dn) { |
|
1062 | + if (!$dn) { |
|
1063 | 1063 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1064 | 1064 | return false; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | //if group really still exists, we will be able to read its objectclass |
1068 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
1068 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
1069 | 1069 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1070 | 1070 | return false; |
1071 | 1071 | } |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | * compared with GroupInterface::CREATE_GROUP etc. |
1084 | 1084 | */ |
1085 | 1085 | public function implementsActions($actions) { |
1086 | - return (bool)((GroupInterface::COUNT_USERS | |
|
1086 | + return (bool) ((GroupInterface::COUNT_USERS | |
|
1087 | 1087 | $this->groupPluginManager->getImplementedActions()) & $actions); |
1088 | 1088 | } |
1089 | 1089 |