@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | parent::__construct($access); |
66 | 66 | $filter = $this->access->connection->ldapGroupFilter; |
67 | 67 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
68 | - if(!empty($filter) && !empty($gassoc)) { |
|
68 | + if (!empty($filter) && !empty($gassoc)) { |
|
69 | 69 | $this->enabled = true; |
70 | 70 | } |
71 | 71 | |
@@ -83,25 +83,25 @@ discard block |
||
83 | 83 | * Checks whether the user is member of a group or not. |
84 | 84 | */ |
85 | 85 | public function inGroup($uid, $gid) { |
86 | - if(!$this->enabled) { |
|
86 | + if (!$this->enabled) { |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
90 | 90 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
91 | - if(!is_null($inGroup)) { |
|
92 | - return (bool)$inGroup; |
|
91 | + if (!is_null($inGroup)) { |
|
92 | + return (bool) $inGroup; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $userDN = $this->access->username2dn($uid); |
96 | 96 | |
97 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
97 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
98 | 98 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
99 | 99 | return $isInGroup; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
103 | 103 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
104 | - if(!is_null($members)) { |
|
104 | + if (!is_null($members)) { |
|
105 | 105 | $this->cachedGroupMembers[$gid] = $members; |
106 | 106 | $isInGroup = in_array($userDN, $members); |
107 | 107 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | |
111 | 111 | $groupDN = $this->access->groupname2dn($gid); |
112 | 112 | // just in case |
113 | - if(!$groupDN || !$userDN) { |
|
113 | + if (!$groupDN || !$userDN) { |
|
114 | 114 | $this->access->connection->writeToCache($cacheKey, false); |
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | 118 | //check primary group first |
119 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
119 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
120 | 120 | $this->access->connection->writeToCache($cacheKey, true); |
121 | 121 | return true; |
122 | 122 | } |
@@ -124,21 +124,21 @@ discard block |
||
124 | 124 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
125 | 125 | $members = $this->_groupMembers($groupDN); |
126 | 126 | $members = array_keys($members); // uids are returned as keys |
127 | - if(!is_array($members) || count($members) === 0) { |
|
127 | + if (!is_array($members) || count($members) === 0) { |
|
128 | 128 | $this->access->connection->writeToCache($cacheKey, false); |
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | 132 | //extra work if we don't get back user DNs |
133 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
133 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
134 | 134 | $dns = array(); |
135 | 135 | $filterParts = array(); |
136 | 136 | $bytes = 0; |
137 | - foreach($members as $mid) { |
|
137 | + foreach ($members as $mid) { |
|
138 | 138 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
139 | 139 | $filterParts[] = $filter; |
140 | 140 | $bytes += strlen($filter); |
141 | - if($bytes >= 9000000) { |
|
141 | + if ($bytes >= 9000000) { |
|
142 | 142 | // AD has a default input buffer of 10 MB, we do not want |
143 | 143 | // to take even the chance to exceed it |
144 | 144 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $dns = array_merge($dns, $users); |
149 | 149 | } |
150 | 150 | } |
151 | - if(count($filterParts) > 0) { |
|
151 | + if (count($filterParts) > 0) { |
|
152 | 152 | $filter = $this->access->combineFilterWithOr($filterParts); |
153 | 153 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
154 | 154 | $dns = array_merge($dns, $users); |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | $pos = strpos($memberURLs[0], '('); |
192 | 192 | if ($pos !== false) { |
193 | 193 | $memberUrlFilter = substr($memberURLs[0], $pos); |
194 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
194 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
195 | 195 | $dynamicMembers = array(); |
196 | - foreach($foundMembers as $value) { |
|
196 | + foreach ($foundMembers as $value) { |
|
197 | 197 | $dynamicMembers[$value['dn'][0]] = 1; |
198 | 198 | } |
199 | 199 | } else { |
200 | 200 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
201 | - 'of group ' . $dnGroup, ILogger::DEBUG); |
|
201 | + 'of group '.$dnGroup, ILogger::DEBUG); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | return $dynamicMembers; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | // used extensively in cron job, caching makes sense for nested groups |
223 | 223 | $cacheKey = '_groupMembers'.$dnGroup; |
224 | 224 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
225 | - if($groupMembers !== null) { |
|
225 | + if ($groupMembers !== null) { |
|
226 | 226 | return $groupMembers; |
227 | 227 | } |
228 | 228 | $seen[$dnGroup] = 1; |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | return array(); |
267 | 267 | } |
268 | 268 | $groups = $this->access->groupsMatchFilter($groups); |
269 | - $allGroups = $groups; |
|
269 | + $allGroups = $groups; |
|
270 | 270 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
271 | - if ((int)$nestedGroups === 1) { |
|
271 | + if ((int) $nestedGroups === 1) { |
|
272 | 272 | foreach ($groups as $group) { |
273 | 273 | $subGroups = $this->_getGroupDNsFromMemberOf($group, $seen); |
274 | 274 | $allGroups = array_merge($allGroups, $subGroups); |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | * @return string|bool |
285 | 285 | */ |
286 | 286 | public function gidNumber2Name($gid, $dn) { |
287 | - $cacheKey = 'gidNumberToName' . $gid; |
|
287 | + $cacheKey = 'gidNumberToName'.$gid; |
|
288 | 288 | $groupName = $this->access->connection->getFromCache($cacheKey); |
289 | - if(!is_null($groupName) && isset($groupName)) { |
|
289 | + if (!is_null($groupName) && isset($groupName)) { |
|
290 | 290 | return $groupName; |
291 | 291 | } |
292 | 292 | |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | $filter = $this->access->combineFilterWithAnd([ |
295 | 295 | $this->access->connection->ldapGroupFilter, |
296 | 296 | 'objectClass=posixGroup', |
297 | - $this->access->connection->ldapGidNumber . '=' . $gid |
|
297 | + $this->access->connection->ldapGidNumber.'='.$gid |
|
298 | 298 | ]); |
299 | 299 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
300 | - if(empty($result)) { |
|
300 | + if (empty($result)) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | $dn = $result[0]['dn'][0]; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | */ |
321 | 321 | private function getEntryGidNumber($dn, $attribute) { |
322 | 322 | $value = $this->access->readAttribute($dn, $attribute); |
323 | - if(is_array($value) && !empty($value)) { |
|
323 | + if (is_array($value) && !empty($value)) { |
|
324 | 324 | return $value[0]; |
325 | 325 | } |
326 | 326 | return false; |
@@ -342,9 +342,9 @@ discard block |
||
342 | 342 | */ |
343 | 343 | public function getUserGidNumber($dn) { |
344 | 344 | $gidNumber = false; |
345 | - if($this->access->connection->hasGidNumber) { |
|
345 | + if ($this->access->connection->hasGidNumber) { |
|
346 | 346 | $gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber); |
347 | - if($gidNumber === false) { |
|
347 | + if ($gidNumber === false) { |
|
348 | 348 | $this->access->connection->hasGidNumber = false; |
349 | 349 | } |
350 | 350 | } |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | */ |
362 | 362 | private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') { |
363 | 363 | $groupID = $this->getGroupGidNumber($groupDN); |
364 | - if($groupID === false) { |
|
364 | + if ($groupID === false) { |
|
365 | 365 | throw new \Exception('Not a valid group'); |
366 | 366 | } |
367 | 367 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | if ($search !== '') { |
371 | 371 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
372 | 372 | } |
373 | - $filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; |
|
373 | + $filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID; |
|
374 | 374 | |
375 | 375 | return $this->access->combineFilterWithAnd($filterParts); |
376 | 376 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | try { |
413 | 413 | $filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search); |
414 | 414 | $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); |
415 | - return (int)$users; |
|
415 | + return (int) $users; |
|
416 | 416 | } catch (\Exception $e) { |
417 | 417 | return 0; |
418 | 418 | } |
@@ -425,9 +425,9 @@ discard block |
||
425 | 425 | */ |
426 | 426 | public function getUserGroupByGid($dn) { |
427 | 427 | $groupID = $this->getUserGidNumber($dn); |
428 | - if($groupID !== false) { |
|
428 | + if ($groupID !== false) { |
|
429 | 429 | $groupName = $this->gidNumber2Name($groupID, $dn); |
430 | - if($groupName !== false) { |
|
430 | + if ($groupName !== false) { |
|
431 | 431 | return $groupName; |
432 | 432 | } |
433 | 433 | } |
@@ -444,22 +444,22 @@ discard block |
||
444 | 444 | public function primaryGroupID2Name($gid, $dn) { |
445 | 445 | $cacheKey = 'primaryGroupIDtoName'; |
446 | 446 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
447 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
447 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
448 | 448 | return $groupNames[$gid]; |
449 | 449 | } |
450 | 450 | |
451 | 451 | $domainObjectSid = $this->access->getSID($dn); |
452 | - if($domainObjectSid === false) { |
|
452 | + if ($domainObjectSid === false) { |
|
453 | 453 | return false; |
454 | 454 | } |
455 | 455 | |
456 | 456 | //we need to get the DN from LDAP |
457 | 457 | $filter = $this->access->combineFilterWithAnd(array( |
458 | 458 | $this->access->connection->ldapGroupFilter, |
459 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
459 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
460 | 460 | )); |
461 | 461 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
462 | - if(empty($result)) { |
|
462 | + if (empty($result)) { |
|
463 | 463 | return false; |
464 | 464 | } |
465 | 465 | $dn = $result[0]['dn'][0]; |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | */ |
483 | 483 | private function getEntryGroupID($dn, $attribute) { |
484 | 484 | $value = $this->access->readAttribute($dn, $attribute); |
485 | - if(is_array($value) && !empty($value)) { |
|
485 | + if (is_array($value) && !empty($value)) { |
|
486 | 486 | return $value[0]; |
487 | 487 | } |
488 | 488 | return false; |
@@ -504,9 +504,9 @@ discard block |
||
504 | 504 | */ |
505 | 505 | public function getUserPrimaryGroupIDs($dn) { |
506 | 506 | $primaryGroupID = false; |
507 | - if($this->access->connection->hasPrimaryGroups) { |
|
507 | + if ($this->access->connection->hasPrimaryGroups) { |
|
508 | 508 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
509 | - if($primaryGroupID === false) { |
|
509 | + if ($primaryGroupID === false) { |
|
510 | 510 | $this->access->connection->hasPrimaryGroups = false; |
511 | 511 | } |
512 | 512 | } |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | */ |
524 | 524 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
525 | 525 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
526 | - if($groupID === false) { |
|
526 | + if ($groupID === false) { |
|
527 | 527 | throw new \Exception('Not a valid group'); |
528 | 528 | } |
529 | 529 | |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | if ($search !== '') { |
533 | 533 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
534 | 534 | } |
535 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
535 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
536 | 536 | |
537 | 537 | return $this->access->combineFilterWithAnd($filterParts); |
538 | 538 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | try { |
575 | 575 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
576 | 576 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
577 | - return (int)$users; |
|
577 | + return (int) $users; |
|
578 | 578 | } catch (\Exception $e) { |
579 | 579 | return 0; |
580 | 580 | } |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function getUserPrimaryGroup($dn) { |
589 | 589 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
590 | - if($groupID !== false) { |
|
590 | + if ($groupID !== false) { |
|
591 | 591 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
592 | - if($groupName !== false) { |
|
592 | + if ($groupName !== false) { |
|
593 | 593 | return $groupName; |
594 | 594 | } |
595 | 595 | } |
@@ -608,16 +608,16 @@ discard block |
||
608 | 608 | * This function includes groups based on dynamic group membership. |
609 | 609 | */ |
610 | 610 | public function getUserGroups($uid) { |
611 | - if(!$this->enabled) { |
|
611 | + if (!$this->enabled) { |
|
612 | 612 | return array(); |
613 | 613 | } |
614 | 614 | $cacheKey = 'getUserGroups'.$uid; |
615 | 615 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
616 | - if(!is_null($userGroups)) { |
|
616 | + if (!is_null($userGroups)) { |
|
617 | 617 | return $userGroups; |
618 | 618 | } |
619 | 619 | $userDN = $this->access->username2dn($uid); |
620 | - if(!$userDN) { |
|
620 | + if (!$userDN) { |
|
621 | 621 | $this->access->connection->writeToCache($cacheKey, array()); |
622 | 622 | return array(); |
623 | 623 | } |
@@ -631,14 +631,14 @@ discard block |
||
631 | 631 | if (!empty($dynamicGroupMemberURL)) { |
632 | 632 | // look through dynamic groups to add them to the result array if needed |
633 | 633 | $groupsToMatch = $this->access->fetchListOfGroups( |
634 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
635 | - foreach($groupsToMatch as $dynamicGroup) { |
|
634 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
635 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
636 | 636 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
637 | 637 | continue; |
638 | 638 | } |
639 | 639 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
640 | 640 | if ($pos !== false) { |
641 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
641 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
642 | 642 | // apply filter via ldap search to see if this user is in this |
643 | 643 | // dynamic group |
644 | 644 | $userMatch = $this->access->readAttribute( |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | if ($userMatch !== false) { |
650 | 650 | // match found so this user is in this group |
651 | 651 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
652 | - if(is_string($groupName)) { |
|
652 | + if (is_string($groupName)) { |
|
653 | 653 | // be sure to never return false if the dn could not be |
654 | 654 | // resolved to a name, for whatever reason. |
655 | 655 | $groups[] = $groupName; |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | } |
658 | 658 | } else { |
659 | 659 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
660 | - 'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG); |
|
660 | + 'of group '.print_r($dynamicGroup, true), ILogger::DEBUG); |
|
661 | 661 | } |
662 | 662 | } |
663 | 663 | } |
@@ -665,15 +665,15 @@ discard block |
||
665 | 665 | // if possible, read out membership via memberOf. It's far faster than |
666 | 666 | // performing a search, which still is a fallback later. |
667 | 667 | // memberof doesn't support memberuid, so skip it here. |
668 | - if((int)$this->access->connection->hasMemberOfFilterSupport === 1 |
|
669 | - && (int)$this->access->connection->useMemberOfToDetectMembership === 1 |
|
668 | + if ((int) $this->access->connection->hasMemberOfFilterSupport === 1 |
|
669 | + && (int) $this->access->connection->useMemberOfToDetectMembership === 1 |
|
670 | 670 | && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid' |
671 | 671 | ) { |
672 | 672 | $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
673 | 673 | if (is_array($groupDNs)) { |
674 | 674 | foreach ($groupDNs as $dn) { |
675 | 675 | $groupName = $this->access->dn2groupname($dn); |
676 | - if(is_string($groupName)) { |
|
676 | + if (is_string($groupName)) { |
|
677 | 677 | // be sure to never return false if the dn could not be |
678 | 678 | // resolved to a name, for whatever reason. |
679 | 679 | $groups[] = $groupName; |
@@ -681,10 +681,10 @@ discard block |
||
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
684 | - if($primaryGroup !== false) { |
|
684 | + if ($primaryGroup !== false) { |
|
685 | 685 | $groups[] = $primaryGroup; |
686 | 686 | } |
687 | - if($gidGroupName !== false) { |
|
687 | + if ($gidGroupName !== false) { |
|
688 | 688 | $groups[] = $gidGroupName; |
689 | 689 | } |
690 | 690 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -692,14 +692,14 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
695 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
695 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
696 | 696 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
697 | 697 | ) { |
698 | 698 | $uid = $userDN; |
699 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
699 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
700 | 700 | $result = $this->access->readAttribute($userDN, 'uid'); |
701 | 701 | if ($result === false) { |
702 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
702 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
703 | 703 | $this->access->connection->ldapHost, ILogger::DEBUG); |
704 | 704 | } |
705 | 705 | $uid = $result[0]; |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | $uid = $userDN; |
709 | 709 | } |
710 | 710 | |
711 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
711 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
712 | 712 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
713 | 713 | } else { |
714 | 714 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -717,10 +717,10 @@ discard block |
||
717 | 717 | $groups = array_merge($groups, $groupsByMember); |
718 | 718 | } |
719 | 719 | |
720 | - if($primaryGroup !== false) { |
|
720 | + if ($primaryGroup !== false) { |
|
721 | 721 | $groups[] = $primaryGroup; |
722 | 722 | } |
723 | - if($gidGroupName !== false) { |
|
723 | + if ($gidGroupName !== false) { |
|
724 | 724 | $groups[] = $gidGroupName; |
725 | 725 | } |
726 | 726 | |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
759 | 759 | if (!empty($nestedGroups)) { |
760 | 760 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
761 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
761 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
762 | 762 | $allGroups = array_merge($allGroups, $supergroups); |
763 | 763 | } |
764 | 764 | } |
@@ -777,33 +777,33 @@ discard block |
||
777 | 777 | * @return array with user ids |
778 | 778 | */ |
779 | 779 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
780 | - if(!$this->enabled) { |
|
780 | + if (!$this->enabled) { |
|
781 | 781 | return array(); |
782 | 782 | } |
783 | - if(!$this->groupExists($gid)) { |
|
783 | + if (!$this->groupExists($gid)) { |
|
784 | 784 | return array(); |
785 | 785 | } |
786 | 786 | $search = $this->access->escapeFilterPart($search, true); |
787 | 787 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
788 | 788 | // check for cache of the exact query |
789 | 789 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
790 | - if(!is_null($groupUsers)) { |
|
790 | + if (!is_null($groupUsers)) { |
|
791 | 791 | return $groupUsers; |
792 | 792 | } |
793 | 793 | |
794 | 794 | // check for cache of the query without limit and offset |
795 | 795 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
796 | - if(!is_null($groupUsers)) { |
|
796 | + if (!is_null($groupUsers)) { |
|
797 | 797 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
798 | 798 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
799 | 799 | return $groupUsers; |
800 | 800 | } |
801 | 801 | |
802 | - if($limit === -1) { |
|
802 | + if ($limit === -1) { |
|
803 | 803 | $limit = null; |
804 | 804 | } |
805 | 805 | $groupDN = $this->access->groupname2dn($gid); |
806 | - if(!$groupDN) { |
|
806 | + if (!$groupDN) { |
|
807 | 807 | // group couldn't be found, return empty resultset |
808 | 808 | $this->access->connection->writeToCache($cacheKey, array()); |
809 | 809 | return array(); |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
813 | 813 | $posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset); |
814 | 814 | $members = array_keys($this->_groupMembers($groupDN)); |
815 | - if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
815 | + if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
816 | 816 | //in case users could not be retrieved, return empty result set |
817 | 817 | $this->access->connection->writeToCache($cacheKey, []); |
818 | 818 | return []; |
@@ -821,29 +821,29 @@ discard block |
||
821 | 821 | $groupUsers = array(); |
822 | 822 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
823 | 823 | $attrs = $this->access->userManager->getAttributes(true); |
824 | - foreach($members as $member) { |
|
825 | - if($isMemberUid) { |
|
824 | + foreach ($members as $member) { |
|
825 | + if ($isMemberUid) { |
|
826 | 826 | //we got uids, need to get their DNs to 'translate' them to user names |
827 | 827 | $filter = $this->access->combineFilterWithAnd(array( |
828 | 828 | str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter), |
829 | 829 | $this->access->getFilterPartForUserSearch($search) |
830 | 830 | )); |
831 | 831 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
832 | - if(count($ldap_users) < 1) { |
|
832 | + if (count($ldap_users) < 1) { |
|
833 | 833 | continue; |
834 | 834 | } |
835 | 835 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
836 | 836 | } else { |
837 | 837 | //we got DNs, check if we need to filter by search or we can give back all of them |
838 | 838 | if ($search !== '') { |
839 | - if(!$this->access->readAttribute($member, |
|
839 | + if (!$this->access->readAttribute($member, |
|
840 | 840 | $this->access->connection->ldapUserDisplayName, |
841 | 841 | $this->access->getFilterPartForUserSearch($search))) { |
842 | 842 | continue; |
843 | 843 | } |
844 | 844 | } |
845 | 845 | // dn2username will also check if the users belong to the allowed base |
846 | - if($ocname = $this->access->dn2username($member)) { |
|
846 | + if ($ocname = $this->access->dn2username($member)) { |
|
847 | 847 | $groupUsers[] = $ocname; |
848 | 848 | } |
849 | 849 | } |
@@ -871,16 +871,16 @@ discard block |
||
871 | 871 | } |
872 | 872 | |
873 | 873 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
874 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
874 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
875 | 875 | return false; |
876 | 876 | } |
877 | 877 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
878 | - if(!is_null($groupUsers)) { |
|
878 | + if (!is_null($groupUsers)) { |
|
879 | 879 | return $groupUsers; |
880 | 880 | } |
881 | 881 | |
882 | 882 | $groupDN = $this->access->groupname2dn($gid); |
883 | - if(!$groupDN) { |
|
883 | + if (!$groupDN) { |
|
884 | 884 | // group couldn't be found, return empty result set |
885 | 885 | $this->access->connection->writeToCache($cacheKey, false); |
886 | 886 | return false; |
@@ -888,7 +888,7 @@ discard block |
||
888 | 888 | |
889 | 889 | $members = array_keys($this->_groupMembers($groupDN)); |
890 | 890 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
891 | - if(!$members && $primaryUserCount === 0) { |
|
891 | + if (!$members && $primaryUserCount === 0) { |
|
892 | 892 | //in case users could not be retrieved, return empty result set |
893 | 893 | $this->access->connection->writeToCache($cacheKey, false); |
894 | 894 | return false; |
@@ -913,27 +913,27 @@ discard block |
||
913 | 913 | //For now this is not important, because the only use of this method |
914 | 914 | //does not supply a search string |
915 | 915 | $groupUsers = array(); |
916 | - foreach($members as $member) { |
|
917 | - if($isMemberUid) { |
|
916 | + foreach ($members as $member) { |
|
917 | + if ($isMemberUid) { |
|
918 | 918 | //we got uids, need to get their DNs to 'translate' them to user names |
919 | 919 | $filter = $this->access->combineFilterWithAnd(array( |
920 | 920 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
921 | 921 | $this->access->getFilterPartForUserSearch($search) |
922 | 922 | )); |
923 | 923 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
924 | - if(count($ldap_users) < 1) { |
|
924 | + if (count($ldap_users) < 1) { |
|
925 | 925 | continue; |
926 | 926 | } |
927 | 927 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
928 | 928 | } else { |
929 | 929 | //we need to apply the search filter now |
930 | - if(!$this->access->readAttribute($member, |
|
930 | + if (!$this->access->readAttribute($member, |
|
931 | 931 | $this->access->connection->ldapUserDisplayName, |
932 | 932 | $this->access->getFilterPartForUserSearch($search))) { |
933 | 933 | continue; |
934 | 934 | } |
935 | 935 | // dn2username will also check if the users belong to the allowed base |
936 | - if($ocname = $this->access->dn2username($member)) { |
|
936 | + if ($ocname = $this->access->dn2username($member)) { |
|
937 | 937 | $groupUsers[] = $ocname; |
938 | 938 | } |
939 | 939 | } |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * Returns a list with all groups (used by getGroups) |
957 | 957 | */ |
958 | 958 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
959 | - if(!$this->enabled) { |
|
959 | + if (!$this->enabled) { |
|
960 | 960 | return array(); |
961 | 961 | } |
962 | 962 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -964,13 +964,13 @@ discard block |
||
964 | 964 | //Check cache before driving unnecessary searches |
965 | 965 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG); |
966 | 966 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
967 | - if(!is_null($ldap_groups)) { |
|
967 | + if (!is_null($ldap_groups)) { |
|
968 | 968 | return $ldap_groups; |
969 | 969 | } |
970 | 970 | |
971 | 971 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
972 | 972 | // error. With a limit of 0, we get 0 results. So we pass null. |
973 | - if($limit <= 0) { |
|
973 | + if ($limit <= 0) { |
|
974 | 974 | $limit = null; |
975 | 975 | } |
976 | 976 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -1002,11 +1002,11 @@ discard block |
||
1002 | 1002 | * (active directory has a limit of 1000 by default) |
1003 | 1003 | */ |
1004 | 1004 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
1005 | - if(!$this->enabled) { |
|
1005 | + if (!$this->enabled) { |
|
1006 | 1006 | return array(); |
1007 | 1007 | } |
1008 | 1008 | $search = $this->access->escapeFilterPart($search, true); |
1009 | - $pagingSize = (int)$this->access->connection->ldapPagingSize; |
|
1009 | + $pagingSize = (int) $this->access->connection->ldapPagingSize; |
|
1010 | 1010 | if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) { |
1011 | 1011 | return $this->getGroupsChunk($search, $limit, $offset); |
1012 | 1012 | } |
@@ -1049,20 +1049,20 @@ discard block |
||
1049 | 1049 | */ |
1050 | 1050 | public function groupExists($gid) { |
1051 | 1051 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
1052 | - if(!is_null($groupExists)) { |
|
1053 | - return (bool)$groupExists; |
|
1052 | + if (!is_null($groupExists)) { |
|
1053 | + return (bool) $groupExists; |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | //getting dn, if false the group does not exist. If dn, it may be mapped |
1057 | 1057 | //only, requires more checking. |
1058 | 1058 | $dn = $this->access->groupname2dn($gid); |
1059 | - if(!$dn) { |
|
1059 | + if (!$dn) { |
|
1060 | 1060 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1061 | 1061 | return false; |
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | //if group really still exists, we will be able to read its objectclass |
1065 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
1065 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
1066 | 1066 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
1067 | 1067 | return false; |
1068 | 1068 | } |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | * compared with GroupInterface::CREATE_GROUP etc. |
1081 | 1081 | */ |
1082 | 1082 | public function implementsActions($actions) { |
1083 | - return (bool)((GroupInterface::COUNT_USERS | |
|
1083 | + return (bool) ((GroupInterface::COUNT_USERS | |
|
1084 | 1084 | $this->groupPluginManager->getImplementedActions()) & $actions); |
1085 | 1085 | } |
1086 | 1086 |