@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | case 'database': |
| 95 | 95 | case 'mysql': |
| 96 | 96 | case 'sqlite': |
| 97 | - \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 97 | + \OCP\Util::writeLog('core', 'Adding user backend '.$backend.'.', \OCP\Util::DEBUG); |
|
| 98 | 98 | self::$_usedBackends[$backend] = new \OC\User\Database(); |
| 99 | 99 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 100 | 100 | break; |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 104 | 104 | break; |
| 105 | 105 | default: |
| 106 | - \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); |
|
| 107 | - $className = 'OC_USER_' . strtoupper($backend); |
|
| 106 | + \OCP\Util::writeLog('core', 'Adding default user backend '.$backend.'.', \OCP\Util::DEBUG); |
|
| 107 | + $className = 'OC_USER_'.strtoupper($backend); |
|
| 108 | 108 | self::$_usedBackends[$backend] = new $className(); |
| 109 | 109 | \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); |
| 110 | 110 | break; |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | self::useBackend($backend); |
| 148 | 148 | self::$_setupedBackends[] = $i; |
| 149 | 149 | } else { |
| 150 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', \OCP\Util::DEBUG); |
|
| 150 | + \OCP\Util::writeLog('core', 'User backend '.$class.' already initialized.', \OCP\Util::DEBUG); |
|
| 151 | 151 | } |
| 152 | 152 | } else { |
| 153 | - \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', \OCP\Util::ERROR); |
|
| 153 | + \OCP\Util::writeLog('core', 'User backend '.$class.' not found.', \OCP\Util::ERROR); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -174,15 +174,15 @@ discard block |
||
| 174 | 174 | if (self::getUser() !== $uid) { |
| 175 | 175 | self::setUserId($uid); |
| 176 | 176 | $setUidAsDisplayName = true; |
| 177 | - if($backend instanceof \OCP\UserInterface |
|
| 177 | + if ($backend instanceof \OCP\UserInterface |
|
| 178 | 178 | && $backend->implementsActions(\OC\User\Backend::GET_DISPLAYNAME)) { |
| 179 | 179 | |
| 180 | 180 | $backendDisplayName = $backend->getDisplayName($uid); |
| 181 | - if(is_string($backendDisplayName) && trim($backendDisplayName) !== '') { |
|
| 181 | + if (is_string($backendDisplayName) && trim($backendDisplayName) !== '') { |
|
| 182 | 182 | $setUidAsDisplayName = false; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | - if($setUidAsDisplayName) { |
|
| 185 | + if ($setUidAsDisplayName) { |
|
| 186 | 186 | self::setDisplayName($uid); |
| 187 | 187 | } |
| 188 | 188 | $userSession = self::getUserSession(); |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | if ($user) { |
| 418 | 418 | return $user->getHome(); |
| 419 | 419 | } else { |
| 420 | - return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 420 | + return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$uid; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function canChangeAvatar($uid) { |
| 74 | 74 | $user = $this->access->userManager->get($uid); |
| 75 | - if(!$user instanceof User) { |
|
| 75 | + if (!$user instanceof User) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | - if($user->getAvatarImage() === false) { |
|
| 78 | + if ($user->getAvatarImage() === false) { |
|
| 79 | 79 | return true; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -91,14 +91,14 @@ discard block |
||
| 91 | 91 | public function loginName2UserName($loginName) { |
| 92 | 92 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 93 | 93 | $username = $this->access->connection->getFromCache($cacheKey); |
| 94 | - if(!is_null($username)) { |
|
| 94 | + if (!is_null($username)) { |
|
| 95 | 95 | return $username; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | try { |
| 99 | 99 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 100 | 100 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 101 | - if($user instanceof OfflineUser) { |
|
| 101 | + if ($user instanceof OfflineUser) { |
|
| 102 | 102 | // this path is not really possible, however get() is documented |
| 103 | 103 | // to return User or OfflineUser so we are very defensive here. |
| 104 | 104 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | //find out dn of the user name |
| 135 | 135 | $attrs = $this->access->userManager->getAttributes(); |
| 136 | 136 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
| 137 | - if(count($users) < 1) { |
|
| 138 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 139 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 137 | + if (count($users) < 1) { |
|
| 138 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
| 139 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
| 140 | 140 | } |
| 141 | 141 | return $users[0]; |
| 142 | 142 | } |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | public function checkPassword($uid, $password) { |
| 152 | 152 | try { |
| 153 | 153 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 154 | - } catch(NotOnLDAP $e) { |
|
| 155 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 154 | + } catch (NotOnLDAP $e) { |
|
| 155 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 156 | 156 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 157 | 157 | } |
| 158 | 158 | return false; |
@@ -160,16 +160,16 @@ discard block |
||
| 160 | 160 | $dn = $ldapRecord['dn'][0]; |
| 161 | 161 | $user = $this->access->userManager->get($dn); |
| 162 | 162 | |
| 163 | - if(!$user instanceof User) { |
|
| 163 | + if (!$user instanceof User) { |
|
| 164 | 164 | Util::writeLog('user_ldap', |
| 165 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 165 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 166 | 166 | '. Maybe the LDAP entry has no set display name attribute?', |
| 167 | 167 | Util::WARN); |
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | - if($user->getUsername() !== false) { |
|
| 170 | + if ($user->getUsername() !== false) { |
|
| 171 | 171 | //are the credentials OK? |
| 172 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 172 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -192,11 +192,11 @@ discard block |
||
| 192 | 192 | public function setPassword($uid, $password) { |
| 193 | 193 | $user = $this->access->userManager->get($uid); |
| 194 | 194 | |
| 195 | - if(!$user instanceof User) { |
|
| 196 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 195 | + if (!$user instanceof User) { |
|
| 196 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 197 | 197 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 198 | 198 | } |
| 199 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 199 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 200 | 200 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
| 201 | 201 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
| 202 | 202 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -228,18 +228,18 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | //check if users are cached, if so return |
| 230 | 230 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 231 | - if(!is_null($ldap_users)) { |
|
| 231 | + if (!is_null($ldap_users)) { |
|
| 232 | 232 | return $ldap_users; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 236 | 236 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 237 | - if($limit <= 0) { |
|
| 237 | + if ($limit <= 0) { |
|
| 238 | 238 | $limit = null; |
| 239 | 239 | } |
| 240 | 240 | $filter = $this->access->combineFilterWithAnd(array( |
| 241 | 241 | $this->access->connection->ldapUserFilter, |
| 242 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 242 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 243 | 243 | $this->access->getFilterPartForUserSearch($search) |
| 244 | 244 | )); |
| 245 | 245 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $this->access->userManager->getAttributes(true), |
| 253 | 253 | $limit, $offset); |
| 254 | 254 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
| 255 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 255 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 256 | 256 | |
| 257 | 257 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 258 | 258 | return $ldap_users; |
@@ -268,29 +268,29 @@ discard block |
||
| 268 | 268 | * @throws \OC\ServerNotAvailableException |
| 269 | 269 | */ |
| 270 | 270 | public function userExistsOnLDAP($user) { |
| 271 | - if(is_string($user)) { |
|
| 271 | + if (is_string($user)) { |
|
| 272 | 272 | $user = $this->access->userManager->get($user); |
| 273 | 273 | } |
| 274 | - if(is_null($user)) { |
|
| 274 | + if (is_null($user)) { |
|
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $dn = $user->getDN(); |
| 279 | 279 | //check if user really still exists by reading its entry |
| 280 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 280 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 281 | 281 | $lcr = $this->access->connection->getConnectionResource(); |
| 282 | - if(is_null($lcr)) { |
|
| 283 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 282 | + if (is_null($lcr)) { |
|
| 283 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | try { |
| 287 | 287 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
| 288 | - if(!$uuid) { |
|
| 288 | + if (!$uuid) { |
|
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | $newDn = $this->access->getUserDnByUuid($uuid); |
| 292 | 292 | //check if renamed user is still valid by reapplying the ldap filter |
| 293 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 293 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if($user instanceof OfflineUser) { |
|
| 303 | + if ($user instanceof OfflineUser) { |
|
| 304 | 304 | $user->unmark(); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -315,18 +315,18 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function userExists($uid) { |
| 317 | 317 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 318 | - if(!is_null($userExists)) { |
|
| 319 | - return (bool)$userExists; |
|
| 318 | + if (!is_null($userExists)) { |
|
| 319 | + return (bool) $userExists; |
|
| 320 | 320 | } |
| 321 | 321 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 322 | 322 | $user = $this->access->userManager->get($uid); |
| 323 | 323 | |
| 324 | - if(is_null($user)) { |
|
| 324 | + if (is_null($user)) { |
|
| 325 | 325 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 326 | 326 | $this->access->connection->ldapHost, Util::DEBUG); |
| 327 | 327 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 328 | 328 | return false; |
| 329 | - } else if($user instanceof OfflineUser) { |
|
| 329 | + } else if ($user instanceof OfflineUser) { |
|
| 330 | 330 | //express check for users marked as deleted. Returning true is |
| 331 | 331 | //necessary for cleanup |
| 332 | 332 | return true; |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | $result = $this->userExistsOnLDAP($user); |
| 336 | 336 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 337 | - if($result === true) { |
|
| 337 | + if ($result === true) { |
|
| 338 | 338 | $user->update(); |
| 339 | 339 | } |
| 340 | 340 | return $result; |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | public function deleteUser($uid) { |
| 350 | 350 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 351 | - if(intval($marked) === 0) { |
|
| 351 | + if (intval($marked) === 0) { |
|
| 352 | 352 | \OC::$server->getLogger()->notice( |
| 353 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 353 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 354 | 354 | array('app' => 'user_ldap')); |
| 355 | 355 | return false; |
| 356 | 356 | } |
| 357 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 357 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 358 | 358 | array('app' => 'user_ldap')); |
| 359 | 359 | |
| 360 | 360 | //Get Home Directory out of user preferences so we can return it later, |
@@ -375,27 +375,27 @@ discard block |
||
| 375 | 375 | * @throws \Exception |
| 376 | 376 | */ |
| 377 | 377 | public function getHome($uid) { |
| 378 | - if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 378 | + if (isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 379 | 379 | //a deleted user who needs some clean up |
| 380 | 380 | return $this->homesToKill[$uid]; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // user Exists check required as it is not done in user proxy! |
| 384 | - if(!$this->userExists($uid)) { |
|
| 384 | + if (!$this->userExists($uid)) { |
|
| 385 | 385 | return false; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | $cacheKey = 'getHome'.$uid; |
| 389 | 389 | $path = $this->access->connection->getFromCache($cacheKey); |
| 390 | - if(!is_null($path)) { |
|
| 390 | + if (!is_null($path)) { |
|
| 391 | 391 | return $path; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | $user = $this->access->userManager->get($uid); |
| 395 | - if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 396 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 395 | + if (is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 396 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 397 | 397 | } |
| 398 | - if($user instanceof OfflineUser) { |
|
| 398 | + if ($user instanceof OfflineUser) { |
|
| 399 | 399 | // apparently this user survived the userExistsOnLDAP check, |
| 400 | 400 | // we request the user instance again in order to retrieve a User |
| 401 | 401 | // instance instead |
@@ -413,12 +413,12 @@ discard block |
||
| 413 | 413 | * @return string|false display name |
| 414 | 414 | */ |
| 415 | 415 | public function getDisplayName($uid) { |
| 416 | - if(!$this->userExists($uid)) { |
|
| 416 | + if (!$this->userExists($uid)) { |
|
| 417 | 417 | return false; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | $cacheKey = 'getDisplayName'.$uid; |
| 421 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 421 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 422 | 422 | return $displayName; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -435,10 +435,10 @@ discard block |
||
| 435 | 435 | $this->access->username2dn($uid), |
| 436 | 436 | $this->access->connection->ldapUserDisplayName); |
| 437 | 437 | |
| 438 | - if($displayName && (count($displayName) > 0)) { |
|
| 438 | + if ($displayName && (count($displayName) > 0)) { |
|
| 439 | 439 | $displayName = $displayName[0]; |
| 440 | 440 | |
| 441 | - if (is_array($displayName2)){ |
|
| 441 | + if (is_array($displayName2)) { |
|
| 442 | 442 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 443 | 443 | } |
| 444 | 444 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | */ |
| 468 | 468 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 469 | 469 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 470 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 470 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 471 | 471 | return $displayNames; |
| 472 | 472 | } |
| 473 | 473 | |
@@ -489,12 +489,12 @@ discard block |
||
| 489 | 489 | * compared with \OC\User\Backend::CREATE_USER etc. |
| 490 | 490 | */ |
| 491 | 491 | public function implementsActions($actions) { |
| 492 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 492 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 493 | 493 | | Backend::GET_HOME |
| 494 | 494 | | Backend::GET_DISPLAYNAME |
| 495 | 495 | | Backend::PROVIDE_AVATAR |
| 496 | 496 | | Backend::COUNT_USERS |
| 497 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 497 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
| 498 | 498 | & $actions); |
| 499 | 499 | } |
| 500 | 500 | |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | public function countUsers() { |
| 514 | 514 | $filter = $this->access->getFilterForUserCount(); |
| 515 | 515 | $cacheKey = 'countUsers-'.$filter; |
| 516 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 516 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 517 | 517 | return $entries; |
| 518 | 518 | } |
| 519 | 519 | $entries = $this->access->countUsers($filter); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * Backend name to be shown in user management |
| 526 | 526 | * @return string the name of the backend to be shown |
| 527 | 527 | */ |
| 528 | - public function getBackendName(){ |
|
| 528 | + public function getBackendName() { |
|
| 529 | 529 | return 'LDAP'; |
| 530 | 530 | } |
| 531 | 531 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | parent::__construct($access); |
| 58 | 58 | $filter = $this->access->connection->ldapGroupFilter; |
| 59 | 59 | $gassoc = $this->access->connection->ldapGroupMemberAssocAttr; |
| 60 | - if(!empty($filter) && !empty($gassoc)) { |
|
| 60 | + if (!empty($filter) && !empty($gassoc)) { |
|
| 61 | 61 | $this->enabled = true; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -74,25 +74,25 @@ discard block |
||
| 74 | 74 | * Checks whether the user is member of a group or not. |
| 75 | 75 | */ |
| 76 | 76 | public function inGroup($uid, $gid) { |
| 77 | - if(!$this->enabled) { |
|
| 77 | + if (!$this->enabled) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | $cacheKey = 'inGroup'.$uid.':'.$gid; |
| 81 | 81 | $inGroup = $this->access->connection->getFromCache($cacheKey); |
| 82 | - if(!is_null($inGroup)) { |
|
| 83 | - return (bool)$inGroup; |
|
| 82 | + if (!is_null($inGroup)) { |
|
| 83 | + return (bool) $inGroup; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $userDN = $this->access->username2dn($uid); |
| 87 | 87 | |
| 88 | - if(isset($this->cachedGroupMembers[$gid])) { |
|
| 88 | + if (isset($this->cachedGroupMembers[$gid])) { |
|
| 89 | 89 | $isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]); |
| 90 | 90 | return $isInGroup; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $cacheKeyMembers = 'inGroup-members:'.$gid; |
| 94 | 94 | $members = $this->access->connection->getFromCache($cacheKeyMembers); |
| 95 | - if(!is_null($members)) { |
|
| 95 | + if (!is_null($members)) { |
|
| 96 | 96 | $this->cachedGroupMembers[$gid] = $members; |
| 97 | 97 | $isInGroup = in_array($userDN, $members); |
| 98 | 98 | $this->access->connection->writeToCache($cacheKey, $isInGroup); |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $groupDN = $this->access->groupname2dn($gid); |
| 103 | 103 | // just in case |
| 104 | - if(!$groupDN || !$userDN) { |
|
| 104 | + if (!$groupDN || !$userDN) { |
|
| 105 | 105 | $this->access->connection->writeToCache($cacheKey, false); |
| 106 | 106 | return false; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | //check primary group first |
| 110 | - if($gid === $this->getUserPrimaryGroup($userDN)) { |
|
| 110 | + if ($gid === $this->getUserPrimaryGroup($userDN)) { |
|
| 111 | 111 | $this->access->connection->writeToCache($cacheKey, true); |
| 112 | 112 | return true; |
| 113 | 113 | } |
@@ -115,21 +115,21 @@ discard block |
||
| 115 | 115 | //usually, LDAP attributes are said to be case insensitive. But there are exceptions of course. |
| 116 | 116 | $members = $this->_groupMembers($groupDN); |
| 117 | 117 | $members = array_keys($members); // uids are returned as keys |
| 118 | - if(!is_array($members) || count($members) === 0) { |
|
| 118 | + if (!is_array($members) || count($members) === 0) { |
|
| 119 | 119 | $this->access->connection->writeToCache($cacheKey, false); |
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | //extra work if we don't get back user DNs |
| 124 | - if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 124 | + if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 125 | 125 | $dns = array(); |
| 126 | 126 | $filterParts = array(); |
| 127 | 127 | $bytes = 0; |
| 128 | - foreach($members as $mid) { |
|
| 128 | + foreach ($members as $mid) { |
|
| 129 | 129 | $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); |
| 130 | 130 | $filterParts[] = $filter; |
| 131 | 131 | $bytes += strlen($filter); |
| 132 | - if($bytes >= 9000000) { |
|
| 132 | + if ($bytes >= 9000000) { |
|
| 133 | 133 | // AD has a default input buffer of 10 MB, we do not want |
| 134 | 134 | // to take even the chance to exceed it |
| 135 | 135 | $filter = $this->access->combineFilterWithOr($filterParts); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $dns = array_merge($dns, $users); |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | - if(count($filterParts) > 0) { |
|
| 142 | + if (count($filterParts) > 0) { |
|
| 143 | 143 | $filter = $this->access->combineFilterWithOr($filterParts); |
| 144 | 144 | $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); |
| 145 | 145 | $dns = array_merge($dns, $users); |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | $pos = strpos($memberURLs[0], '('); |
| 183 | 183 | if ($pos !== false) { |
| 184 | 184 | $memberUrlFilter = substr($memberURLs[0], $pos); |
| 185 | - $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); |
|
| 185 | + $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn'); |
|
| 186 | 186 | $dynamicMembers = array(); |
| 187 | - foreach($foundMembers as $value) { |
|
| 187 | + foreach ($foundMembers as $value) { |
|
| 188 | 188 | $dynamicMembers[$value['dn'][0]] = 1; |
| 189 | 189 | } |
| 190 | 190 | } else { |
| 191 | 191 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
| 192 | - 'of group ' . $dnGroup, \OCP\Util::DEBUG); |
|
| 192 | + 'of group '.$dnGroup, \OCP\Util::DEBUG); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | return $dynamicMembers; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | // used extensively in cron job, caching makes sense for nested groups |
| 213 | 213 | $cacheKey = '_groupMembers'.$dnGroup; |
| 214 | 214 | $groupMembers = $this->access->connection->getFromCache($cacheKey); |
| 215 | - if(!is_null($groupMembers)) { |
|
| 215 | + if (!is_null($groupMembers)) { |
|
| 216 | 216 | return $groupMembers; |
| 217 | 217 | } |
| 218 | 218 | $seen[$dnGroup] = 1; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | return array(); |
| 257 | 257 | } |
| 258 | 258 | $groups = $this->access->groupsMatchFilter($groups); |
| 259 | - $allGroups = $groups; |
|
| 259 | + $allGroups = $groups; |
|
| 260 | 260 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
| 261 | 261 | if (intval($nestedGroups) === 1) { |
| 262 | 262 | foreach ($groups as $group) { |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * @return string|bool |
| 275 | 275 | */ |
| 276 | 276 | public function gidNumber2Name($gid, $dn) { |
| 277 | - $cacheKey = 'gidNumberToName' . $gid; |
|
| 277 | + $cacheKey = 'gidNumberToName'.$gid; |
|
| 278 | 278 | $groupName = $this->access->connection->getFromCache($cacheKey); |
| 279 | - if(!is_null($groupName) && isset($groupName)) { |
|
| 279 | + if (!is_null($groupName) && isset($groupName)) { |
|
| 280 | 280 | return $groupName; |
| 281 | 281 | } |
| 282 | 282 | |
@@ -284,10 +284,10 @@ discard block |
||
| 284 | 284 | $filter = $this->access->combineFilterWithAnd([ |
| 285 | 285 | $this->access->connection->ldapGroupFilter, |
| 286 | 286 | 'objectClass=posixGroup', |
| 287 | - $this->access->connection->ldapGidNumber . '=' . $gid |
|
| 287 | + $this->access->connection->ldapGidNumber.'='.$gid |
|
| 288 | 288 | ]); |
| 289 | 289 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
| 290 | - if(empty($result)) { |
|
| 290 | + if (empty($result)) { |
|
| 291 | 291 | return false; |
| 292 | 292 | } |
| 293 | 293 | $dn = $result[0]['dn'][0]; |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | private function getEntryGidNumber($dn, $attribute) { |
| 312 | 312 | $value = $this->access->readAttribute($dn, $attribute); |
| 313 | - if(is_array($value) && !empty($value)) { |
|
| 313 | + if (is_array($value) && !empty($value)) { |
|
| 314 | 314 | return $value[0]; |
| 315 | 315 | } |
| 316 | 316 | return false; |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | public function getUserGidNumber($dn) { |
| 334 | 334 | $gidNumber = false; |
| 335 | - if($this->access->connection->hasGidNumber) { |
|
| 335 | + if ($this->access->connection->hasGidNumber) { |
|
| 336 | 336 | $gidNumber = $this->getEntryGidNumber($dn, 'gidNumber'); |
| 337 | - if($gidNumber === false) { |
|
| 337 | + if ($gidNumber === false) { |
|
| 338 | 338 | $this->access->connection->hasGidNumber = false; |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') { |
| 353 | 353 | $groupID = $this->getGroupGidNumber($groupDN); |
| 354 | - if($groupID === false) { |
|
| 354 | + if ($groupID === false) { |
|
| 355 | 355 | throw new \Exception('Not a valid group'); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | if ($search !== '') { |
| 361 | 361 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
| 362 | 362 | } |
| 363 | - $filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; |
|
| 363 | + $filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID; |
|
| 364 | 364 | |
| 365 | 365 | $filter = $this->access->combineFilterWithAnd($filterParts); |
| 366 | 366 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | try { |
| 405 | 405 | $filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search); |
| 406 | 406 | $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); |
| 407 | - return (int)$users; |
|
| 407 | + return (int) $users; |
|
| 408 | 408 | } catch (\Exception $e) { |
| 409 | 409 | return 0; |
| 410 | 410 | } |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public function getUserGroupByGid($dn) { |
| 419 | 419 | $groupID = $this->getUserGidNumber($dn); |
| 420 | - if($groupID !== false) { |
|
| 420 | + if ($groupID !== false) { |
|
| 421 | 421 | $groupName = $this->gidNumber2Name($groupID, $dn); |
| 422 | - if($groupName !== false) { |
|
| 422 | + if ($groupName !== false) { |
|
| 423 | 423 | return $groupName; |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -436,22 +436,22 @@ discard block |
||
| 436 | 436 | public function primaryGroupID2Name($gid, $dn) { |
| 437 | 437 | $cacheKey = 'primaryGroupIDtoName'; |
| 438 | 438 | $groupNames = $this->access->connection->getFromCache($cacheKey); |
| 439 | - if(!is_null($groupNames) && isset($groupNames[$gid])) { |
|
| 439 | + if (!is_null($groupNames) && isset($groupNames[$gid])) { |
|
| 440 | 440 | return $groupNames[$gid]; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | $domainObjectSid = $this->access->getSID($dn); |
| 444 | - if($domainObjectSid === false) { |
|
| 444 | + if ($domainObjectSid === false) { |
|
| 445 | 445 | return false; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | //we need to get the DN from LDAP |
| 449 | 449 | $filter = $this->access->combineFilterWithAnd(array( |
| 450 | 450 | $this->access->connection->ldapGroupFilter, |
| 451 | - 'objectsid=' . $domainObjectSid . '-' . $gid |
|
| 451 | + 'objectsid='.$domainObjectSid.'-'.$gid |
|
| 452 | 452 | )); |
| 453 | 453 | $result = $this->access->searchGroups($filter, array('dn'), 1); |
| 454 | - if(empty($result)) { |
|
| 454 | + if (empty($result)) { |
|
| 455 | 455 | return false; |
| 456 | 456 | } |
| 457 | 457 | $dn = $result[0]['dn'][0]; |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | */ |
| 475 | 475 | private function getEntryGroupID($dn, $attribute) { |
| 476 | 476 | $value = $this->access->readAttribute($dn, $attribute); |
| 477 | - if(is_array($value) && !empty($value)) { |
|
| 477 | + if (is_array($value) && !empty($value)) { |
|
| 478 | 478 | return $value[0]; |
| 479 | 479 | } |
| 480 | 480 | return false; |
@@ -496,9 +496,9 @@ discard block |
||
| 496 | 496 | */ |
| 497 | 497 | public function getUserPrimaryGroupIDs($dn) { |
| 498 | 498 | $primaryGroupID = false; |
| 499 | - if($this->access->connection->hasPrimaryGroups) { |
|
| 499 | + if ($this->access->connection->hasPrimaryGroups) { |
|
| 500 | 500 | $primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID'); |
| 501 | - if($primaryGroupID === false) { |
|
| 501 | + if ($primaryGroupID === false) { |
|
| 502 | 502 | $this->access->connection->hasPrimaryGroups = false; |
| 503 | 503 | } |
| 504 | 504 | } |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') { |
| 517 | 517 | $groupID = $this->getGroupPrimaryGroupID($groupDN); |
| 518 | - if($groupID === false) { |
|
| 518 | + if ($groupID === false) { |
|
| 519 | 519 | throw new \Exception('Not a valid group'); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | if ($search !== '') { |
| 525 | 525 | $filterParts[] = $this->access->getFilterPartForUserSearch($search); |
| 526 | 526 | } |
| 527 | - $filterParts[] = 'primaryGroupID=' . $groupID; |
|
| 527 | + $filterParts[] = 'primaryGroupID='.$groupID; |
|
| 528 | 528 | |
| 529 | 529 | $filter = $this->access->combineFilterWithAnd($filterParts); |
| 530 | 530 | |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | try { |
| 569 | 569 | $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); |
| 570 | 570 | $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); |
| 571 | - return (int)$users; |
|
| 571 | + return (int) $users; |
|
| 572 | 572 | } catch (\Exception $e) { |
| 573 | 573 | return 0; |
| 574 | 574 | } |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | public function getUserPrimaryGroup($dn) { |
| 583 | 583 | $groupID = $this->getUserPrimaryGroupIDs($dn); |
| 584 | - if($groupID !== false) { |
|
| 584 | + if ($groupID !== false) { |
|
| 585 | 585 | $groupName = $this->primaryGroupID2Name($groupID, $dn); |
| 586 | - if($groupName !== false) { |
|
| 586 | + if ($groupName !== false) { |
|
| 587 | 587 | return $groupName; |
| 588 | 588 | } |
| 589 | 589 | } |
@@ -602,16 +602,16 @@ discard block |
||
| 602 | 602 | * This function includes groups based on dynamic group membership. |
| 603 | 603 | */ |
| 604 | 604 | public function getUserGroups($uid) { |
| 605 | - if(!$this->enabled) { |
|
| 605 | + if (!$this->enabled) { |
|
| 606 | 606 | return array(); |
| 607 | 607 | } |
| 608 | 608 | $cacheKey = 'getUserGroups'.$uid; |
| 609 | 609 | $userGroups = $this->access->connection->getFromCache($cacheKey); |
| 610 | - if(!is_null($userGroups)) { |
|
| 610 | + if (!is_null($userGroups)) { |
|
| 611 | 611 | return $userGroups; |
| 612 | 612 | } |
| 613 | 613 | $userDN = $this->access->username2dn($uid); |
| 614 | - if(!$userDN) { |
|
| 614 | + if (!$userDN) { |
|
| 615 | 615 | $this->access->connection->writeToCache($cacheKey, array()); |
| 616 | 616 | return array(); |
| 617 | 617 | } |
@@ -625,14 +625,14 @@ discard block |
||
| 625 | 625 | if (!empty($dynamicGroupMemberURL)) { |
| 626 | 626 | // look through dynamic groups to add them to the result array if needed |
| 627 | 627 | $groupsToMatch = $this->access->fetchListOfGroups( |
| 628 | - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); |
|
| 629 | - foreach($groupsToMatch as $dynamicGroup) { |
|
| 628 | + $this->access->connection->ldapGroupFilter, array('dn', $dynamicGroupMemberURL)); |
|
| 629 | + foreach ($groupsToMatch as $dynamicGroup) { |
|
| 630 | 630 | if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { |
| 631 | 631 | continue; |
| 632 | 632 | } |
| 633 | 633 | $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); |
| 634 | 634 | if ($pos !== false) { |
| 635 | - $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); |
|
| 635 | + $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos); |
|
| 636 | 636 | // apply filter via ldap search to see if this user is in this |
| 637 | 637 | // dynamic group |
| 638 | 638 | $userMatch = $this->access->readAttribute( |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | if ($userMatch !== false) { |
| 644 | 644 | // match found so this user is in this group |
| 645 | 645 | $groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); |
| 646 | - if(is_string($groupName)) { |
|
| 646 | + if (is_string($groupName)) { |
|
| 647 | 647 | // be sure to never return false if the dn could not be |
| 648 | 648 | // resolved to a name, for whatever reason. |
| 649 | 649 | $groups[] = $groupName; |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | } else { |
| 653 | 653 | \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. |
| 654 | - 'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
| 654 | + 'of group '.print_r($dynamicGroup, true), \OCP\Util::DEBUG); |
|
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | } |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | // if possible, read out membership via memberOf. It's far faster than |
| 660 | 660 | // performing a search, which still is a fallback later. |
| 661 | 661 | // memberof doesn't support memberuid, so skip it here. |
| 662 | - if(intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
| 662 | + if (intval($this->access->connection->hasMemberOfFilterSupport) === 1 |
|
| 663 | 663 | && intval($this->access->connection->useMemberOfToDetectMembership) === 1 |
| 664 | 664 | && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid' |
| 665 | 665 | ) { |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | if (is_array($groupDNs)) { |
| 668 | 668 | foreach ($groupDNs as $dn) { |
| 669 | 669 | $groupName = $this->access->dn2groupname($dn); |
| 670 | - if(is_string($groupName)) { |
|
| 670 | + if (is_string($groupName)) { |
|
| 671 | 671 | // be sure to never return false if the dn could not be |
| 672 | 672 | // resolved to a name, for whatever reason. |
| 673 | 673 | $groups[] = $groupName; |
@@ -675,10 +675,10 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - if($primaryGroup !== false) { |
|
| 678 | + if ($primaryGroup !== false) { |
|
| 679 | 679 | $groups[] = $primaryGroup; |
| 680 | 680 | } |
| 681 | - if($gidGroupName !== false) { |
|
| 681 | + if ($gidGroupName !== false) { |
|
| 682 | 682 | $groups[] = $gidGroupName; |
| 683 | 683 | } |
| 684 | 684 | $this->access->connection->writeToCache($cacheKey, $groups); |
@@ -686,14 +686,14 @@ discard block |
||
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | //uniqueMember takes DN, memberuid the uid, so we need to distinguish |
| 689 | - if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
| 689 | + if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember') |
|
| 690 | 690 | || (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member') |
| 691 | 691 | ) { |
| 692 | 692 | $uid = $userDN; |
| 693 | - } else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 693 | + } else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { |
|
| 694 | 694 | $result = $this->access->readAttribute($userDN, 'uid'); |
| 695 | 695 | if ($result === false) { |
| 696 | - \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. |
|
| 696 | + \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '. |
|
| 697 | 697 | $this->access->connection->ldapHost, \OCP\Util::DEBUG); |
| 698 | 698 | } |
| 699 | 699 | $uid = $result[0]; |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | $uid = $userDN; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - if(isset($this->cachedGroupsByMember[$uid])) { |
|
| 705 | + if (isset($this->cachedGroupsByMember[$uid])) { |
|
| 706 | 706 | $groups = array_merge($groups, $this->cachedGroupsByMember[$uid]); |
| 707 | 707 | } else { |
| 708 | 708 | $groupsByMember = array_values($this->getGroupsByMember($uid)); |
@@ -711,10 +711,10 @@ discard block |
||
| 711 | 711 | $groups = array_merge($groups, $groupsByMember); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if($primaryGroup !== false) { |
|
| 714 | + if ($primaryGroup !== false) { |
|
| 715 | 715 | $groups[] = $primaryGroup; |
| 716 | 716 | } |
| 717 | - if($gidGroupName !== false) { |
|
| 717 | + if ($gidGroupName !== false) { |
|
| 718 | 718 | $groups[] = $gidGroupName; |
| 719 | 719 | } |
| 720 | 720 | |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | $nestedGroups = $this->access->connection->ldapNestedGroups; |
| 753 | 753 | if (!empty($nestedGroups)) { |
| 754 | 754 | $supergroups = $this->getGroupsByMember($groupDN, $seen); |
| 755 | - if (is_array($supergroups) && (count($supergroups)>0)) { |
|
| 755 | + if (is_array($supergroups) && (count($supergroups) > 0)) { |
|
| 756 | 756 | $allGroups = array_merge($allGroups, $supergroups); |
| 757 | 757 | } |
| 758 | 758 | } |
@@ -771,33 +771,33 @@ discard block |
||
| 771 | 771 | * @return array with user ids |
| 772 | 772 | */ |
| 773 | 773 | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
| 774 | - if(!$this->enabled) { |
|
| 774 | + if (!$this->enabled) { |
|
| 775 | 775 | return array(); |
| 776 | 776 | } |
| 777 | - if(!$this->groupExists($gid)) { |
|
| 777 | + if (!$this->groupExists($gid)) { |
|
| 778 | 778 | return array(); |
| 779 | 779 | } |
| 780 | 780 | $search = $this->access->escapeFilterPart($search, true); |
| 781 | 781 | $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; |
| 782 | 782 | // check for cache of the exact query |
| 783 | 783 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
| 784 | - if(!is_null($groupUsers)) { |
|
| 784 | + if (!is_null($groupUsers)) { |
|
| 785 | 785 | return $groupUsers; |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | // check for cache of the query without limit and offset |
| 789 | 789 | $groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); |
| 790 | - if(!is_null($groupUsers)) { |
|
| 790 | + if (!is_null($groupUsers)) { |
|
| 791 | 791 | $groupUsers = array_slice($groupUsers, $offset, $limit); |
| 792 | 792 | $this->access->connection->writeToCache($cacheKey, $groupUsers); |
| 793 | 793 | return $groupUsers; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - if($limit === -1) { |
|
| 796 | + if ($limit === -1) { |
|
| 797 | 797 | $limit = null; |
| 798 | 798 | } |
| 799 | 799 | $groupDN = $this->access->groupname2dn($gid); |
| 800 | - if(!$groupDN) { |
|
| 800 | + if (!$groupDN) { |
|
| 801 | 801 | // group couldn't be found, return empty resultset |
| 802 | 802 | $this->access->connection->writeToCache($cacheKey, array()); |
| 803 | 803 | return array(); |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); |
| 807 | 807 | $posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset); |
| 808 | 808 | $members = array_keys($this->_groupMembers($groupDN)); |
| 809 | - if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
| 809 | + if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) { |
|
| 810 | 810 | //in case users could not be retrieved, return empty result set |
| 811 | 811 | $this->access->connection->writeToCache($cacheKey, []); |
| 812 | 812 | return []; |
@@ -815,29 +815,29 @@ discard block |
||
| 815 | 815 | $groupUsers = array(); |
| 816 | 816 | $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); |
| 817 | 817 | $attrs = $this->access->userManager->getAttributes(true); |
| 818 | - foreach($members as $member) { |
|
| 819 | - if($isMemberUid) { |
|
| 818 | + foreach ($members as $member) { |
|
| 819 | + if ($isMemberUid) { |
|
| 820 | 820 | //we got uids, need to get their DNs to 'translate' them to user names |
| 821 | 821 | $filter = $this->access->combineFilterWithAnd(array( |
| 822 | 822 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
| 823 | 823 | $this->access->getFilterPartForUserSearch($search) |
| 824 | 824 | )); |
| 825 | 825 | $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); |
| 826 | - if(count($ldap_users) < 1) { |
|
| 826 | + if (count($ldap_users) < 1) { |
|
| 827 | 827 | continue; |
| 828 | 828 | } |
| 829 | 829 | $groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]); |
| 830 | 830 | } else { |
| 831 | 831 | //we got DNs, check if we need to filter by search or we can give back all of them |
| 832 | 832 | if ($search !== '') { |
| 833 | - if(!$this->access->readAttribute($member, |
|
| 833 | + if (!$this->access->readAttribute($member, |
|
| 834 | 834 | $this->access->connection->ldapUserDisplayName, |
| 835 | 835 | $this->access->getFilterPartForUserSearch($search))) { |
| 836 | 836 | continue; |
| 837 | 837 | } |
| 838 | 838 | } |
| 839 | 839 | // dn2username will also check if the users belong to the allowed base |
| 840 | - if($ocname = $this->access->dn2username($member)) { |
|
| 840 | + if ($ocname = $this->access->dn2username($member)) { |
|
| 841 | 841 | $groupUsers[] = $ocname; |
| 842 | 842 | } |
| 843 | 843 | } |
@@ -861,16 +861,16 @@ discard block |
||
| 861 | 861 | */ |
| 862 | 862 | public function countUsersInGroup($gid, $search = '') { |
| 863 | 863 | $cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; |
| 864 | - if(!$this->enabled || !$this->groupExists($gid)) { |
|
| 864 | + if (!$this->enabled || !$this->groupExists($gid)) { |
|
| 865 | 865 | return false; |
| 866 | 866 | } |
| 867 | 867 | $groupUsers = $this->access->connection->getFromCache($cacheKey); |
| 868 | - if(!is_null($groupUsers)) { |
|
| 868 | + if (!is_null($groupUsers)) { |
|
| 869 | 869 | return $groupUsers; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | $groupDN = $this->access->groupname2dn($gid); |
| 873 | - if(!$groupDN) { |
|
| 873 | + if (!$groupDN) { |
|
| 874 | 874 | // group couldn't be found, return empty result set |
| 875 | 875 | $this->access->connection->writeToCache($cacheKey, false); |
| 876 | 876 | return false; |
@@ -878,7 +878,7 @@ discard block |
||
| 878 | 878 | |
| 879 | 879 | $members = array_keys($this->_groupMembers($groupDN)); |
| 880 | 880 | $primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, ''); |
| 881 | - if(!$members && $primaryUserCount === 0) { |
|
| 881 | + if (!$members && $primaryUserCount === 0) { |
|
| 882 | 882 | //in case users could not be retrieved, return empty result set |
| 883 | 883 | $this->access->connection->writeToCache($cacheKey, false); |
| 884 | 884 | return false; |
@@ -903,27 +903,27 @@ discard block |
||
| 903 | 903 | //For now this is not important, because the only use of this method |
| 904 | 904 | //does not supply a search string |
| 905 | 905 | $groupUsers = array(); |
| 906 | - foreach($members as $member) { |
|
| 907 | - if($isMemberUid) { |
|
| 906 | + foreach ($members as $member) { |
|
| 907 | + if ($isMemberUid) { |
|
| 908 | 908 | //we got uids, need to get their DNs to 'translate' them to user names |
| 909 | 909 | $filter = $this->access->combineFilterWithAnd(array( |
| 910 | 910 | str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), |
| 911 | 911 | $this->access->getFilterPartForUserSearch($search) |
| 912 | 912 | )); |
| 913 | 913 | $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); |
| 914 | - if(count($ldap_users) < 1) { |
|
| 914 | + if (count($ldap_users) < 1) { |
|
| 915 | 915 | continue; |
| 916 | 916 | } |
| 917 | 917 | $groupUsers[] = $this->access->dn2username($ldap_users[0]); |
| 918 | 918 | } else { |
| 919 | 919 | //we need to apply the search filter now |
| 920 | - if(!$this->access->readAttribute($member, |
|
| 920 | + if (!$this->access->readAttribute($member, |
|
| 921 | 921 | $this->access->connection->ldapUserDisplayName, |
| 922 | 922 | $this->access->getFilterPartForUserSearch($search))) { |
| 923 | 923 | continue; |
| 924 | 924 | } |
| 925 | 925 | // dn2username will also check if the users belong to the allowed base |
| 926 | - if($ocname = $this->access->dn2username($member)) { |
|
| 926 | + if ($ocname = $this->access->dn2username($member)) { |
|
| 927 | 927 | $groupUsers[] = $ocname; |
| 928 | 928 | } |
| 929 | 929 | } |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | * Returns a list with all groups (used by getGroups) |
| 947 | 947 | */ |
| 948 | 948 | protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { |
| 949 | - if(!$this->enabled) { |
|
| 949 | + if (!$this->enabled) { |
|
| 950 | 950 | return array(); |
| 951 | 951 | } |
| 952 | 952 | $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; |
@@ -954,13 +954,13 @@ discard block |
||
| 954 | 954 | //Check cache before driving unnecessary searches |
| 955 | 955 | \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); |
| 956 | 956 | $ldap_groups = $this->access->connection->getFromCache($cacheKey); |
| 957 | - if(!is_null($ldap_groups)) { |
|
| 957 | + if (!is_null($ldap_groups)) { |
|
| 958 | 958 | return $ldap_groups; |
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 962 | 962 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 963 | - if($limit <= 0) { |
|
| 963 | + if ($limit <= 0) { |
|
| 964 | 964 | $limit = null; |
| 965 | 965 | } |
| 966 | 966 | $filter = $this->access->combineFilterWithAnd(array( |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | * (active directory has a limit of 1000 by default) |
| 993 | 993 | */ |
| 994 | 994 | public function getGroups($search = '', $limit = -1, $offset = 0) { |
| 995 | - if(!$this->enabled) { |
|
| 995 | + if (!$this->enabled) { |
|
| 996 | 996 | return array(); |
| 997 | 997 | } |
| 998 | 998 | $search = $this->access->escapeFilterPart($search, true); |
@@ -1039,20 +1039,20 @@ discard block |
||
| 1039 | 1039 | */ |
| 1040 | 1040 | public function groupExists($gid) { |
| 1041 | 1041 | $groupExists = $this->access->connection->getFromCache('groupExists'.$gid); |
| 1042 | - if(!is_null($groupExists)) { |
|
| 1043 | - return (bool)$groupExists; |
|
| 1042 | + if (!is_null($groupExists)) { |
|
| 1043 | + return (bool) $groupExists; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | //getting dn, if false the group does not exist. If dn, it may be mapped |
| 1047 | 1047 | //only, requires more checking. |
| 1048 | 1048 | $dn = $this->access->groupname2dn($gid); |
| 1049 | - if(!$dn) { |
|
| 1049 | + if (!$dn) { |
|
| 1050 | 1050 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
| 1051 | 1051 | return false; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | //if group really still exists, we will be able to read its objectclass |
| 1055 | - if(!is_array($this->access->readAttribute($dn, ''))) { |
|
| 1055 | + if (!is_array($this->access->readAttribute($dn, ''))) { |
|
| 1056 | 1056 | $this->access->connection->writeToCache('groupExists'.$gid, false); |
| 1057 | 1057 | return false; |
| 1058 | 1058 | } |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * compared with \OC\User\Backend::CREATE_USER etc. |
| 1071 | 1071 | */ |
| 1072 | 1072 | public function implementsActions($actions) { |
| 1073 | - return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); |
|
| 1073 | + return (bool) (\OC\Group\Backend::COUNT_USERS & $actions); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | /** |