@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | parent::__construct($access); |
| 57 | 57 | $filter = $this->access->connection->ldapGroupFilter; |
| 58 | 58 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
| 59 | - if(!empty($filter) && !empty($gassoc)) { |
|
| 59 | + if (!empty($filter) && !empty($gassoc)) { |
|
| 60 | 60 | $this->enabled = true; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -73,25 +73,25 @@ discard block |
||
| 73 | 73 | * Checks whether the user is member of a group or not. |
| 74 | 74 | */ |
| 75 | 75 | public function inGroup($uid, $gid) { |
| 76 | - if(!$this->enabled) { |
|
| 76 | + if (!$this->enabled) { |
|
| 77 | 77 | return false; |
| 78 | 78 | } |
| 79 | 79 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
| 80 | 80 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
| 81 | - if(!is_null($inGroup)) { |
|
| 82 | - return (bool)$inGroup; |
|
| 81 | + if (!is_null($inGroup)) { |
|
| 82 | + return (bool) $inGroup; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $userDN = $this->access->username2dn($uid); |
| 86 | 86 | |
| 87 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
| 87 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
| 88 | 88 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
| 89 | 89 | return $isInGroup; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
| 93 | 93 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
| 94 | - if(!is_null($members)) { |
|
| 94 | + if (!is_null($members)) { |
|
| 95 | 95 | $this->cachedGroupMembers[$gid] = $members; |
| 96 | 96 | $isInGroup = in_array($userDN, $members); |
| 97 | 97 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | $groupDN = $this->access->groupname2dn($gid); |
| 102 | 102 | // just in case |
| 103 | - if(!$groupDN || !$userDN) { |
|
| 103 | + if (!$groupDN || !$userDN) { |
|
| 104 | 104 | $this->access->connection->writeToCache($cacheKey, false); |
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | //check primary group first |
| 109 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
| 109 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
| 110 | 110 | $this->access->connection->writeToCache($cacheKey, true); |
| 111 | 111 | return true; |
| 112 | 112 | } |
@@ -114,21 +114,21 @@ discard block |
||
| 114 | 114 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
| 115 | 115 | $members = $this->_groupMembers($groupDN); |
| 116 | 116 | $members = array_keys($members); // uids are returned as keys |
| 117 | - if(!is_array($members) || count($members) === 0) { |
|
| 117 | + if (!is_array($members) || count($members) === 0) { |
|
| 118 | 118 | $this->access->connection->writeToCache($cacheKey, false); |
| 119 | 119 | return false; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | //extra work if we don't get back user DNs |
| 123 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 123 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 124 | 124 | $dns = array(); |
| 125 | 125 | $filterParts = array(); |
| 126 | 126 | $bytes = 0; |
| 127 | - foreach($members as $mid) { |
|
| 127 | + foreach ($members as $mid) { |
|
| 128 | 128 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
| 129 | 129 | $filterParts[] = $filter; |
| 130 | 130 | $bytes += strlen($filter); |
| 131 | - if($bytes >= 9000000) { |
|
| 131 | + if ($bytes >= 9000000) { |
|
| 132 | 132 | // AD has a default input buffer of 10 MB, we do not want |
| 133 | 133 | // to take even the chance to exceed it |
| 134 | 134 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $dns = array_merge($dns, $users); |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | - if(count($filterParts) > 0) { |
|
| 141 | + if (count($filterParts) > 0) { |
|
| 142 | 142 | $filter = $this->access->combineFilterWithOr($filterParts); |
| 143 | 143 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
| 144 | 144 | $dns = array_merge($dns, $users); |
@@ -181,14 +181,14 @@ discard block |
||
| 181 | 181 | $pos = strpos($memberURLs[0], '('); |
| 182 | 182 | if ($pos !== false) { |
| 183 | 183 | $memberUrlFilter = substr($memberURLs[0], $pos); |
| 184 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
| 184 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
| 185 | 185 | $dynamicMembers = array(); |
| 186 | - foreach($foundMembers as $value) { |
|
| 186 | + foreach ($foundMembers as $value) { |
|
| 187 | 187 | $dynamicMembers[$value['dn'][0]] = 1; |
| 188 | 188 | } |
| 189 | 189 | } else { |
| 190 | 190 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
| 191 | - 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
| 191 | + 'of group '.$dnGroup, \OCP\Util::DEBUG); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | return $dynamicMembers; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | // used extensively in cron job, caching makes sense for nested groups |
| 212 | 212 | $cacheKey = '_groupMembers'.$dnGroup; |
| 213 | 213 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
| 214 | - if(!is_null($groupMembers)) { |
|
| 214 | + if (!is_null($groupMembers)) { |
|
| 215 | 215 | return $groupMembers; |
| 216 | 216 | } |
| 217 | 217 | $seen[$dnGroup] = 1; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | return array(); |
| 256 | 256 | } |
| 257 | 257 | $groups = $this->access->groupsMatchFilter($groups); |
| 258 | - $allGroups = $groups; |
|
| 258 | + $allGroups = $groups; |
|
| 259 | 259 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
| 260 | 260 | if (intval($nestedGroups) === 1) { |
| 261 | 261 | foreach ($groups as $group) { |
@@ -275,22 +275,22 @@ discard block |
||
| 275 | 275 | public function primaryGroupID2Name($gid, $dn) { |
| 276 | 276 | $cacheKey = 'primaryGroupIDtoName'; |
| 277 | 277 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
| 278 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
| 278 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
| 279 | 279 | return $groupNames[$gid]; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $domainObjectSid = $this->access->getSID($dn); |
| 283 | - if($domainObjectSid === false) { |
|
| 283 | + if ($domainObjectSid === false) { |
|
| 284 | 284 | return false; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | //we need to get the DN from LDAP |
| 288 | 288 | $filter = $this->access->combineFilterWithAnd(array( |
| 289 | 289 | $this->access->connection->ldapGroupFilter, |
| 290 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
| 290 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
| 291 | 291 | )); |
| 292 | 292 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
| 293 | - if(empty($result)) { |
|
| 293 | + if (empty($result)) { |
|
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | $dn = $result[0]['dn'][0]; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | private function getEntryGroupID($dn, $attribute) { |
| 315 | 315 | $value = $this->access->readAttribute($dn, $attribute); |
| 316 | - if(is_array($value) && !empty($value)) { |
|
| 316 | + if (is_array($value) && !empty($value)) { |
|
| 317 | 317 | return $value[0]; |
| 318 | 318 | } |
| 319 | 319 | return false; |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function getUserPrimaryGroupIDs($dn) { |
| 337 | 337 | $primaryGroupID = false; |
| 338 | - if($this->access->connection->hasPrimaryGroups) { |
|
| 338 | + if ($this->access->connection->hasPrimaryGroups) { |
|
| 339 | 339 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
| 340 | - if($primaryGroupID === false) { |
|
| 340 | + if ($primaryGroupID === false) { |
|
| 341 | 341 | $this->access->connection->hasPrimaryGroups = false; |
| 342 | 342 | } |
| 343 | 343 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
| 356 | 356 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
| 357 | - if($groupID === false) { |
|
| 357 | + if ($groupID === false) { |
|
| 358 | 358 | throw new \Exception('Not a valid group'); |
| 359 | 359 | } |
| 360 | 360 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | if ($search !== '') { |
| 364 | 364 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
| 365 | 365 | } |
| 366 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
| 366 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
| 367 | 367 | |
| 368 | 368 | $filter = $this->access->combineFilterWithAnd($filterParts); |
| 369 | 369 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | try { |
| 408 | 408 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
| 409 | 409 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
| 410 | - return (int)$users; |
|
| 410 | + return (int) $users; |
|
| 411 | 411 | } catch (\Exception $e) { |
| 412 | 412 | return 0; |
| 413 | 413 | } |
@@ -420,9 +420,9 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | public function getUserPrimaryGroup($dn) { |
| 422 | 422 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
| 423 | - if($groupID !== false) { |
|
| 423 | + if ($groupID !== false) { |
|
| 424 | 424 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
| 425 | - if($groupName !== false) { |
|
| 425 | + if ($groupName !== false) { |
|
| 426 | 426 | return $groupName; |
| 427 | 427 | } |
| 428 | 428 | } |
@@ -441,16 +441,16 @@ discard block |
||
| 441 | 441 | * This function includes groups based on dynamic group membership. |
| 442 | 442 | */ |
| 443 | 443 | public function getUserGroups($uid) { |
| 444 | - if(!$this->enabled) { |
|
| 444 | + if (!$this->enabled) { |
|
| 445 | 445 | return array(); |
| 446 | 446 | } |
| 447 | 447 | $cacheKey = 'getUserGroups'.$uid; |
| 448 | 448 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
| 449 | - if(!is_null($userGroups)) { |
|
| 449 | + if (!is_null($userGroups)) { |
|
| 450 | 450 | return $userGroups; |
| 451 | 451 | } |
| 452 | 452 | $userDN = $this->access->username2dn($uid); |
| 453 | - if(!$userDN) { |
|
| 453 | + if (!$userDN) { |
|
| 454 | 454 | $this->access->connection->writeToCache($cacheKey, array()); |
| 455 | 455 | return array(); |
| 456 | 456 | } |
@@ -463,14 +463,14 @@ discard block |
||
| 463 | 463 | if (!empty($dynamicGroupMemberURL)) { |
| 464 | 464 | // look through dynamic groups to add them to the result array if needed |
| 465 | 465 | $groupsToMatch = $this->access->fetchListOfGroups( |
| 466 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
| 467 | - foreach($groupsToMatch as $dynamicGroup) { |
|
| 466 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
| 467 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
| 468 | 468 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
| 469 | 469 | continue; |
| 470 | 470 | } |
| 471 | 471 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
| 472 | 472 | if ($pos !== false) { |
| 473 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
| 473 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
| 474 | 474 | // apply filter via ldap search to see if this user is in this |
| 475 | 475 | // dynamic group |
| 476 | 476 | $userMatch = $this->access->readAttribute( |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | if ($userMatch !== false) { |
| 482 | 482 | // match found so this user is in this group |
| 483 | 483 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
| 484 | - if(is_string($groupName)) { |
|
| 484 | + if (is_string($groupName)) { |
|
| 485 | 485 | // be sure to never return false if the dn could not be |
| 486 | 486 | // resolved to a name, for whatever reason. |
| 487 | 487 | $groups[] = $groupName; |
@@ -489,21 +489,21 @@ discard block |
||
| 489 | 489 | } |
| 490 | 490 | } else { |
| 491 | 491 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
| 492 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
| 492 | + 'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // if possible, read out membership via memberOf. It's far faster than |
| 498 | 498 | // performing a search, which still is a fallback later. |
| 499 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
| 499 | + if (intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
| 500 | 500 | && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
| 501 | 501 | ) { |
| 502 | 502 | $groupDNs = $this->_getGroupDNsFromMemberOf($userDN); |
| 503 | 503 | if (is_array($groupDNs)) { |
| 504 | 504 | foreach ($groupDNs as $dn) { |
| 505 | 505 | $groupName = $this->access->dn2groupname($dn); |
| 506 | - if(is_string($groupName)) { |
|
| 506 | + if (is_string($groupName)) { |
|
| 507 | 507 | // be sure to never return false if the dn could not be |
| 508 | 508 | // resolved to a name, for whatever reason. |
| 509 | 509 | $groups[] = $groupName; |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if($primaryGroup !== false) { |
|
| 514 | + if ($primaryGroup !== false) { |
|
| 515 | 515 | $groups[] = $primaryGroup; |
| 516 | 516 | } |
| 517 | 517 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -519,14 +519,14 @@ discard block |
||
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
| 522 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
| 522 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
| 523 | 523 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
| 524 | 524 | ) { |
| 525 | 525 | $uid = $userDN; |
| 526 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 526 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 527 | 527 | $result = $this->access->readAttribute($userDN, 'uid'); |
| 528 | 528 | if ($result === false) { |
| 529 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
| 529 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
| 530 | 530 | $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
| 531 | 531 | } |
| 532 | 532 | $uid = $result[0]; |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $uid = $userDN; |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
| 538 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
| 539 | 539 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
| 540 | 540 | } else { |
| 541 | 541 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | $groups = array_merge($groups, $groupsByMember); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - if($primaryGroup !== false) { |
|
| 547 | + if ($primaryGroup !== false) { |
|
| 548 | 548 | $groups[] = $primaryGroup; |
| 549 | 549 | } |
| 550 | 550 | |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
| 583 | 583 | if (!empty($nestedGroups)) { |
| 584 | 584 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
| 585 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
| 585 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
| 586 | 586 | $allGroups = array_merge($allGroups, $supergroups); |
| 587 | 587 | } |
| 588 | 588 | } |
@@ -601,33 +601,33 @@ discard block |
||
| 601 | 601 | * @return array with user ids |
| 602 | 602 | */ |
| 603 | 603 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
| 604 | - if(!$this->enabled) { |
|
| 604 | + if (!$this->enabled) { |
|
| 605 | 605 | return array(); |
| 606 | 606 | } |
| 607 | - if(!$this->groupExists($gid)) { |
|
| 607 | + if (!$this->groupExists($gid)) { |
|
| 608 | 608 | return array(); |
| 609 | 609 | } |
| 610 | 610 | $search = $this->access->escapeFilterPart($search, true); |
| 611 | 611 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
| 612 | 612 | // check for cache of the exact query |
| 613 | 613 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
| 614 | - if(!is_null($groupUsers)) { |
|
| 614 | + if (!is_null($groupUsers)) { |
|
| 615 | 615 | return $groupUsers; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | // check for cache of the query without limit and offset |
| 619 | 619 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
| 620 | - if(!is_null($groupUsers)) { |
|
| 620 | + if (!is_null($groupUsers)) { |
|
| 621 | 621 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
| 622 | 622 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
| 623 | 623 | return $groupUsers; |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - if($limit === -1) { |
|
| 626 | + if ($limit === -1) { |
|
| 627 | 627 | $limit = null; |
| 628 | 628 | } |
| 629 | 629 | $groupDN = $this->access->groupname2dn($gid); |
| 630 | - if(!$groupDN) { |
|
| 630 | + if (!$groupDN) { |
|
| 631 | 631 | // group couldn't be found, return empty resultset |
| 632 | 632 | $this->access->connection->writeToCache($cacheKey, array()); |
| 633 | 633 | return array(); |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | |
| 636 | 636 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
| 637 | 637 | $members = array_keys($this->_groupMembers($groupDN)); |
| 638 | - if(!$members && empty($primaryUsers)) { |
|
| 638 | + if (!$members && empty($primaryUsers)) { |
|
| 639 | 639 | //in case users could not be retrieved, return empty result set |
| 640 | 640 | $this->access->connection->writeToCache($cacheKey, array()); |
| 641 | 641 | return array(); |
@@ -644,29 +644,29 @@ discard block |
||
| 644 | 644 | $groupUsers = array(); |
| 645 | 645 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
| 646 | 646 | $attrs = $this->access->userManager->getAttributes(true); |
| 647 | - foreach($members as $member) { |
|
| 648 | - if($isMemberUid) { |
|
| 647 | + foreach ($members as $member) { |
|
| 648 | + if ($isMemberUid) { |
|
| 649 | 649 | //we got uids, need to get their DNs to 'translate' them to user names |
| 650 | 650 | $filter = $this->access->combineFilterWithAnd(array( |
| 651 | 651 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
| 652 | 652 | $this->access->getFilterPartForUserSearch($search) |
| 653 | 653 | )); |
| 654 | 654 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
| 655 | - if(count($ldap_users) < 1) { |
|
| 655 | + if (count($ldap_users) < 1) { |
|
| 656 | 656 | continue; |
| 657 | 657 | } |
| 658 | 658 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
| 659 | 659 | } else { |
| 660 | 660 | //we got DNs, check if we need to filter by search or we can give back all of them |
| 661 | 661 | if ($search !== '') { |
| 662 | - if(!$this->access->readAttribute($member, |
|
| 662 | + if (!$this->access->readAttribute($member, |
|
| 663 | 663 | $this->access->connection->ldapUserDisplayName, |
| 664 | 664 | $this->access->getFilterPartForUserSearch($search))) { |
| 665 | 665 | continue; |
| 666 | 666 | } |
| 667 | 667 | } |
| 668 | 668 | // dn2username will also check if the users belong to the allowed base |
| 669 | - if($ocname = $this->access->dn2username($member)) { |
|
| 669 | + if ($ocname = $this->access->dn2username($member)) { |
|
| 670 | 670 | $groupUsers[] = $ocname; |
| 671 | 671 | } |
| 672 | 672 | } |
@@ -691,16 +691,16 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | public function countUsersInGroup($gid, $search = '') { |
| 693 | 693 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
| 694 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
| 694 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
| 695 | 695 | return false; |
| 696 | 696 | } |
| 697 | 697 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
| 698 | - if(!is_null($groupUsers)) { |
|
| 698 | + if (!is_null($groupUsers)) { |
|
| 699 | 699 | return $groupUsers; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | $groupDN = $this->access->groupname2dn($gid); |
| 703 | - if(!$groupDN) { |
|
| 703 | + if (!$groupDN) { |
|
| 704 | 704 | // group couldn't be found, return empty result set |
| 705 | 705 | $this->access->connection->writeToCache($cacheKey, false); |
| 706 | 706 | return false; |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | |
| 709 | 709 | $members = array_keys($this->_groupMembers($groupDN)); |
| 710 | 710 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
| 711 | - if(!$members && $primaryUserCount === 0) { |
|
| 711 | + if (!$members && $primaryUserCount === 0) { |
|
| 712 | 712 | //in case users could not be retrieved, return empty result set |
| 713 | 713 | $this->access->connection->writeToCache($cacheKey, false); |
| 714 | 714 | return false; |
@@ -733,27 +733,27 @@ discard block |
||
| 733 | 733 | //For now this is not important, because the only use of this method |
| 734 | 734 | //does not supply a search string |
| 735 | 735 | $groupUsers = array(); |
| 736 | - foreach($members as $member) { |
|
| 737 | - if($isMemberUid) { |
|
| 736 | + foreach ($members as $member) { |
|
| 737 | + if ($isMemberUid) { |
|
| 738 | 738 | //we got uids, need to get their DNs to 'translate' them to user names |
| 739 | 739 | $filter = $this->access->combineFilterWithAnd(array( |
| 740 | 740 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
| 741 | 741 | $this->access->getFilterPartForUserSearch($search) |
| 742 | 742 | )); |
| 743 | 743 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
| 744 | - if(count($ldap_users) < 1) { |
|
| 744 | + if (count($ldap_users) < 1) { |
|
| 745 | 745 | continue; |
| 746 | 746 | } |
| 747 | 747 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
| 748 | 748 | } else { |
| 749 | 749 | //we need to apply the search filter now |
| 750 | - if(!$this->access->readAttribute($member, |
|
| 750 | + if (!$this->access->readAttribute($member, |
|
| 751 | 751 | $this->access->connection->ldapUserDisplayName, |
| 752 | 752 | $this->access->getFilterPartForUserSearch($search))) { |
| 753 | 753 | continue; |
| 754 | 754 | } |
| 755 | 755 | // dn2username will also check if the users belong to the allowed base |
| 756 | - if($ocname = $this->access->dn2username($member)) { |
|
| 756 | + if ($ocname = $this->access->dn2username($member)) { |
|
| 757 | 757 | $groupUsers[] = $ocname; |
| 758 | 758 | } |
| 759 | 759 | } |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * Returns a list with all groups (used by getGroups) |
| 777 | 777 | */ |
| 778 | 778 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
| 779 | - if(!$this->enabled) { |
|
| 779 | + if (!$this->enabled) { |
|
| 780 | 780 | return array(); |
| 781 | 781 | } |
| 782 | 782 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -784,13 +784,13 @@ discard block |
||
| 784 | 784 | //Check cache before driving unnecessary searches |
| 785 | 785 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
| 786 | 786 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
| 787 | - if(!is_null($ldap_groups)) { |
|
| 787 | + if (!is_null($ldap_groups)) { |
|
| 788 | 788 | return $ldap_groups; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 792 | 792 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 793 | - if($limit <= 0) { |
|
| 793 | + if ($limit <= 0) { |
|
| 794 | 794 | $limit = null; |
| 795 | 795 | } |
| 796 | 796 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * (active directory has a limit of 1000 by default) |
| 823 | 823 | */ |
| 824 | 824 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
| 825 | - if(!$this->enabled) { |
|
| 825 | + if (!$this->enabled) { |
|
| 826 | 826 | return array(); |
| 827 | 827 | } |
| 828 | 828 | $search = $this->access->escapeFilterPart($search, true); |
@@ -869,20 +869,20 @@ discard block |
||
| 869 | 869 | */ |
| 870 | 870 | public function groupExists($gid) { |
| 871 | 871 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
| 872 | - if(!is_null($groupExists)) { |
|
| 873 | - return (bool)$groupExists; |
|
| 872 | + if (!is_null($groupExists)) { |
|
| 873 | + return (bool) $groupExists; |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | //getting dn, if false the group does not exist. If dn, it may be mapped |
| 877 | 877 | //only, requires more checking. |
| 878 | 878 | $dn = $this->access->groupname2dn($gid); |
| 879 | - if(!$dn) { |
|
| 879 | + if (!$dn) { |
|
| 880 | 880 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
| 881 | 881 | return false; |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | //if group really still exists, we will be able to read its objectclass |
| 885 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
| 885 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
| 886 | 886 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
| 887 | 887 | return false; |
| 888 | 888 | } |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
| 901 | 901 | */ |
| 902 | 902 | public function implementsActions($actions) { |
| 903 | - return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
| 903 | + return (bool) (\OC\Group\Backend::COUNT_USERS & $actions); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $this->isAllowed($input->getOption('force')); |
| 87 | 87 | $this->confirmUserIsMapped($uid); |
| 88 | 88 | $exists = $this->backend->userExistsOnLDAP($uid); |
| 89 | - if($exists === true) { |
|
| 89 | + if ($exists === true) { |
|
| 90 | 90 | $output->writeln('The user is still available on LDAP.'); |
| 91 | 91 | return; |
| 92 | 92 | } |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | $this->dui->markUser($uid); |
| 95 | 95 | $output->writeln('The user does not exists on LDAP anymore.'); |
| 96 | 96 | $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
| 97 | - . $uid . '"'); |
|
| 97 | + . $uid.'"'); |
|
| 98 | 98 | } catch (\Exception $e) { |
| 99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
| 99 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return true |
| 122 | 122 | */ |
| 123 | 123 | protected function isAllowed($force) { |
| 124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
| 124 | + if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
| 125 | 125 | throw new \Exception('Cannot check user existence, because ' |
| 126 | 126 | . 'disabled LDAP configurations are present.'); |
| 127 | 127 | } |
@@ -87,16 +87,16 @@ discard block |
||
| 87 | 87 | * @throws \InvalidArgumentException |
| 88 | 88 | */ |
| 89 | 89 | protected function validateOffsetAndLimit($offset, $limit) { |
| 90 | - if($limit < 0) { |
|
| 90 | + if ($limit < 0) { |
|
| 91 | 91 | throw new \InvalidArgumentException('limit must be 0 or greater'); |
| 92 | 92 | } |
| 93 | - if($offset < 0) { |
|
| 93 | + if ($offset < 0) { |
|
| 94 | 94 | throw new \InvalidArgumentException('offset must be 0 or greater'); |
| 95 | 95 | } |
| 96 | - if($limit === 0 && $offset !== 0) { |
|
| 96 | + if ($limit === 0 && $offset !== 0) { |
|
| 97 | 97 | throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
| 98 | 98 | } |
| 99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
| 99 | + if ($offset > 0 && ($offset % $limit !== 0)) { |
|
| 100 | 100 | throw new \InvalidArgumentException('offset must be a multiple of limit'); |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $limit = intval($input->getOption('limit')); |
| 111 | 111 | $this->validateOffsetAndLimit($offset, $limit); |
| 112 | 112 | |
| 113 | - if($input->getOption('group')) { |
|
| 113 | + if ($input->getOption('group')) { |
|
| 114 | 114 | $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
| 115 | 115 | $getMethod = 'getGroups'; |
| 116 | 116 | $printID = false; |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
| 124 | - foreach($result as $id => $name) { |
|
| 125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
| 124 | + foreach ($result as $id => $name) { |
|
| 125 | + $line = $name.($printID ? ' ('.$id.')' : ''); |
|
| 126 | 126 | $output->writeln($line); |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | |
| 63 | 63 | $success = $this->helper->deleteServerConfiguration($configPrefix); |
| 64 | 64 | |
| 65 | - if($success) { |
|
| 65 | + if ($success) { |
|
| 66 | 66 | $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
| 67 | 67 | } else { |
| 68 | 68 | $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
@@ -50,17 +50,17 @@ discard block |
||
| 50 | 50 | $helper = new Helper(\OC::$server->getConfig()); |
| 51 | 51 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
| 52 | 52 | $configID = $input->getArgument('configID'); |
| 53 | - if(!in_array($configID, $availableConfigs)) { |
|
| 53 | + if (!in_array($configID, $availableConfigs)) { |
|
| 54 | 54 | $output->writeln("Invalid configID"); |
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $result = $this->testConfig($configID); |
| 59 | - if($result === 0) { |
|
| 59 | + if ($result === 0) { |
|
| 60 | 60 | $output->writeln('The configuration is valid and the connection could be established!'); |
| 61 | - } else if($result === 1) { |
|
| 61 | + } else if ($result === 1) { |
|
| 62 | 62 | $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
| 63 | - } else if($result === 2) { |
|
| 63 | + } else if ($result === 2) { |
|
| 64 | 64 | $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
| 65 | 65 | } else { |
| 66 | 66 | $output->writeln('Your LDAP server was kidnapped by aliens.'); |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | //ensure validation is run before we attempt the bind |
| 80 | 80 | $connection->getConfiguration(); |
| 81 | 81 | |
| 82 | - if(!$connection->setConfiguration(array( |
|
| 82 | + if (!$connection->setConfiguration(array( |
|
| 83 | 83 | 'ldap_configuration_active' => 1, |
| 84 | 84 | ))) { |
| 85 | 85 | return 1; |
| 86 | 86 | } |
| 87 | - if($connection->bind()) { |
|
| 87 | + if ($connection->bind()) { |
|
| 88 | 88 | return 0; |
| 89 | 89 | } |
| 90 | 90 | return 2; |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $helper = new Helper(\OC::$server->getConfig()); |
| 61 | 61 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
| 62 | 62 | $configID = $input->getArgument('configID'); |
| 63 | - if(!in_array($configID, $availableConfigs)) { |
|
| 63 | + if (!in_array($configID, $availableConfigs)) { |
|
| 64 | 64 | $output->writeln("Invalid configID"); |
| 65 | 65 | return; |
| 66 | 66 | } |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | 'Dir', 'Sharer')); |
| 72 | 72 | $rows = array(); |
| 73 | 73 | $resultSet = $this->dui->getUsers(); |
| 74 | - foreach($resultSet as $user) { |
|
| 74 | + foreach ($resultSet as $user) { |
|
| 75 | 75 | $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
| 76 | 76 | $lastLogin = ($user->getLastLogin() > 0) ? |
| 77 | 77 | $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $configHolder->saveConfiguration(); |
| 64 | 64 | |
| 65 | 65 | $prose = ''; |
| 66 | - if(!$input->getOption('only-print-prefix')) { |
|
| 66 | + if (!$input->getOption('only-print-prefix')) { |
|
| 67 | 67 | $prose = 'Created new configuration with configID '; |
| 68 | 68 | } |
| 69 | - $output->writeln($prose . "{$configPrefix}"); |
|
| 69 | + $output->writeln($prose."{$configPrefix}"); |
|
| 70 | 70 | } |
| 71 | 71 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 68 | 68 | $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
| 69 | 69 | $configID = $input->getArgument('configID'); |
| 70 | - if(!is_null($configID)) { |
|
| 70 | + if (!is_null($configID)) { |
|
| 71 | 71 | $configIDs[] = $configID; |
| 72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
| 72 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
| 73 | 73 | $output->writeln("Invalid configID"); |
| 74 | 74 | return; |
| 75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
| 88 | 88 | */ |
| 89 | 89 | protected function renderConfigs($configIDs, $output, $withPassword) { |
| 90 | - foreach($configIDs as $id) { |
|
| 90 | + foreach ($configIDs as $id) { |
|
| 91 | 91 | $configHolder = new Configuration($id); |
| 92 | 92 | $configuration = $configHolder->getConfiguration(); |
| 93 | 93 | ksort($configuration); |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | $table = new Table($output); |
| 96 | 96 | $table->setHeaders(array('Configuration', $id)); |
| 97 | 97 | $rows = array(); |
| 98 | - foreach($configuration as $key => $value) { |
|
| 99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 98 | + foreach ($configuration as $key => $value) { |
|
| 99 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
| 100 | 100 | $value = '***'; |
| 101 | 101 | } |
| 102 | - if(is_array($value)) { |
|
| 102 | + if (is_array($value)) { |
|
| 103 | 103 | $value = implode(';', $value); |
| 104 | 104 | } |
| 105 | 105 | $rows[] = array($key, $value); |