@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $user = $this->access->userManager->get($uid); |
| 104 | - if(!$user instanceof User) { |
|
| 104 | + if (!$user instanceof User) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | - if($user->getAvatarImage() === false) { |
|
| 107 | + if ($user->getAvatarImage() === false) { |
|
| 108 | 108 | return true; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | public function loginName2UserName($loginName) { |
| 121 | 121 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 122 | 122 | $username = $this->access->connection->getFromCache($cacheKey); |
| 123 | - if(!is_null($username)) { |
|
| 123 | + if (!is_null($username)) { |
|
| 124 | 124 | return $username; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | try { |
| 128 | 128 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 129 | 129 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 130 | - if($user instanceof OfflineUser) { |
|
| 130 | + if ($user instanceof OfflineUser) { |
|
| 131 | 131 | // this path is not really possible, however get() is documented |
| 132 | 132 | // to return User or OfflineUser so we are very defensive here. |
| 133 | 133 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | //find out dn of the user name |
| 164 | 164 | $attrs = $this->access->userManager->getAttributes(); |
| 165 | 165 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
| 166 | - if(count($users) < 1) { |
|
| 167 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 168 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 166 | + if (count($users) < 1) { |
|
| 167 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
| 168 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
| 169 | 169 | } |
| 170 | 170 | return $users[0]; |
| 171 | 171 | } |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | public function checkPassword($uid, $password) { |
| 181 | 181 | try { |
| 182 | 182 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 183 | - } catch(NotOnLDAP $e) { |
|
| 184 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 183 | + } catch (NotOnLDAP $e) { |
|
| 184 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 185 | 185 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 186 | 186 | } |
| 187 | 187 | return false; |
@@ -189,16 +189,16 @@ discard block |
||
| 189 | 189 | $dn = $ldapRecord['dn'][0]; |
| 190 | 190 | $user = $this->access->userManager->get($dn); |
| 191 | 191 | |
| 192 | - if(!$user instanceof User) { |
|
| 192 | + if (!$user instanceof User) { |
|
| 193 | 193 | Util::writeLog('user_ldap', |
| 194 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 194 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 195 | 195 | '. Maybe the LDAP entry has no set display name attribute?', |
| 196 | 196 | Util::WARN); |
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | - if($user->getUsername() !== false) { |
|
| 199 | + if ($user->getUsername() !== false) { |
|
| 200 | 200 | //are the credentials OK? |
| 201 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 201 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | $user = $this->access->userManager->get($uid); |
| 227 | 227 | |
| 228 | - if(!$user instanceof User) { |
|
| 229 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 228 | + if (!$user instanceof User) { |
|
| 229 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 230 | 230 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 231 | 231 | } |
| 232 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 232 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 233 | 233 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
| 234 | 234 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
| 235 | 235 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | //check if users are cached, if so return |
| 263 | 263 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 264 | - if(!is_null($ldap_users)) { |
|
| 264 | + if (!is_null($ldap_users)) { |
|
| 265 | 265 | return $ldap_users; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 269 | 269 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 270 | - if($limit <= 0) { |
|
| 270 | + if ($limit <= 0) { |
|
| 271 | 271 | $limit = null; |
| 272 | 272 | } |
| 273 | 273 | $filter = $this->access->combineFilterWithAnd(array( |
| 274 | 274 | $this->access->connection->ldapUserFilter, |
| 275 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 275 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 276 | 276 | $this->access->getFilterPartForUserSearch($search) |
| 277 | 277 | )); |
| 278 | 278 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $this->access->userManager->getAttributes(true), |
| 286 | 286 | $limit, $offset); |
| 287 | 287 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
| 288 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 288 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 289 | 289 | |
| 290 | 290 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 291 | 291 | return $ldap_users; |
@@ -301,19 +301,19 @@ discard block |
||
| 301 | 301 | * @throws \OC\ServerNotAvailableException |
| 302 | 302 | */ |
| 303 | 303 | public function userExistsOnLDAP($user) { |
| 304 | - if(is_string($user)) { |
|
| 304 | + if (is_string($user)) { |
|
| 305 | 305 | $user = $this->access->userManager->get($user); |
| 306 | 306 | } |
| 307 | - if(is_null($user)) { |
|
| 307 | + if (is_null($user)) { |
|
| 308 | 308 | return false; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | $dn = $user->getDN(); |
| 312 | 312 | //check if user really still exists by reading its entry |
| 313 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 313 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 314 | 314 | $lcr = $this->access->connection->getConnectionResource(); |
| 315 | - if(is_null($lcr)) { |
|
| 316 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 315 | + if (is_null($lcr)) { |
|
| 316 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | try { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if($user instanceof OfflineUser) { |
|
| 338 | + if ($user instanceof OfflineUser) { |
|
| 339 | 339 | $user->unmark(); |
| 340 | 340 | } |
| 341 | 341 | |
@@ -350,18 +350,18 @@ discard block |
||
| 350 | 350 | */ |
| 351 | 351 | public function userExists($uid) { |
| 352 | 352 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 353 | - if(!is_null($userExists)) { |
|
| 354 | - return (bool)$userExists; |
|
| 353 | + if (!is_null($userExists)) { |
|
| 354 | + return (bool) $userExists; |
|
| 355 | 355 | } |
| 356 | 356 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 357 | 357 | $user = $this->access->userManager->get($uid); |
| 358 | 358 | |
| 359 | - if(is_null($user)) { |
|
| 359 | + if (is_null($user)) { |
|
| 360 | 360 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 361 | 361 | $this->access->connection->ldapHost, Util::DEBUG); |
| 362 | 362 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 363 | 363 | return false; |
| 364 | - } else if($user instanceof OfflineUser) { |
|
| 364 | + } else if ($user instanceof OfflineUser) { |
|
| 365 | 365 | //express check for users marked as deleted. Returning true is |
| 366 | 366 | //necessary for cleanup |
| 367 | 367 | return true; |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | |
| 370 | 370 | $result = $this->userExistsOnLDAP($user); |
| 371 | 371 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 372 | - if($result === true) { |
|
| 372 | + if ($result === true) { |
|
| 373 | 373 | $user->update(); |
| 374 | 374 | } |
| 375 | 375 | return $result; |
@@ -387,13 +387,13 @@ discard block |
||
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 390 | - if(intval($marked) === 0) { |
|
| 390 | + if (intval($marked) === 0) { |
|
| 391 | 391 | \OC::$server->getLogger()->notice( |
| 392 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 392 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 393 | 393 | array('app' => 'user_ldap')); |
| 394 | 394 | return false; |
| 395 | 395 | } |
| 396 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 396 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 397 | 397 | array('app' => 'user_ldap')); |
| 398 | 398 | |
| 399 | 399 | $this->access->getUserMapper()->unmap($uid); |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function getHome($uid) { |
| 413 | 413 | // user Exists check required as it is not done in user proxy! |
| 414 | - if(!$this->userExists($uid)) { |
|
| 414 | + if (!$this->userExists($uid)) { |
|
| 415 | 415 | return false; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -421,22 +421,22 @@ discard block |
||
| 421 | 421 | |
| 422 | 422 | $cacheKey = 'getHome'.$uid; |
| 423 | 423 | $path = $this->access->connection->getFromCache($cacheKey); |
| 424 | - if(!is_null($path)) { |
|
| 424 | + if (!is_null($path)) { |
|
| 425 | 425 | return $path; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | // early return path if it is a deleted user |
| 429 | 429 | $user = $this->access->userManager->get($uid); |
| 430 | - if($user instanceof OfflineUser) { |
|
| 431 | - if($this->currentUserInDeletionProcess !== null |
|
| 430 | + if ($user instanceof OfflineUser) { |
|
| 431 | + if ($this->currentUserInDeletionProcess !== null |
|
| 432 | 432 | && $this->currentUserInDeletionProcess === $user->getOCName() |
| 433 | 433 | ) { |
| 434 | 434 | return $user->getHomePath(); |
| 435 | 435 | } else { |
| 436 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 436 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 437 | 437 | } |
| 438 | 438 | } else if ($user === null) { |
| 439 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 439 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | $path = $user->getHomePath(); |
@@ -455,12 +455,12 @@ discard block |
||
| 455 | 455 | return $this->userPluginManager->getDisplayName($uid); |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - if(!$this->userExists($uid)) { |
|
| 458 | + if (!$this->userExists($uid)) { |
|
| 459 | 459 | return false; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | $cacheKey = 'getDisplayName'.$uid; |
| 463 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 463 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 464 | 464 | return $displayName; |
| 465 | 465 | } |
| 466 | 466 | |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | $this->access->username2dn($uid), |
| 478 | 478 | $this->access->connection->ldapUserDisplayName); |
| 479 | 479 | |
| 480 | - if($displayName && (count($displayName) > 0)) { |
|
| 480 | + if ($displayName && (count($displayName) > 0)) { |
|
| 481 | 481 | $displayName = $displayName[0]; |
| 482 | 482 | |
| 483 | - if (is_array($displayName2)){ |
|
| 483 | + if (is_array($displayName2)) { |
|
| 484 | 484 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 485 | 485 | } |
| 486 | 486 | |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 524 | 524 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 525 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 525 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 526 | 526 | return $displayNames; |
| 527 | 527 | } |
| 528 | 528 | |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | * compared with \OC\User\Backend::CREATE_USER etc. |
| 545 | 545 | */ |
| 546 | 546 | public function implementsActions($actions) { |
| 547 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 547 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 548 | 548 | | Backend::GET_HOME |
| 549 | 549 | | Backend::GET_DISPLAYNAME |
| 550 | 550 | | Backend::PROVIDE_AVATAR |
| 551 | 551 | | Backend::COUNT_USERS |
| 552 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0) |
|
| 552 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0) |
|
| 553 | 553 | | $this->userPluginManager->getImplementedActions()) |
| 554 | 554 | & $actions); |
| 555 | 555 | } |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | |
| 574 | 574 | $filter = $this->access->getFilterForUserCount(); |
| 575 | 575 | $cacheKey = 'countUsers-'.$filter; |
| 576 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 576 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 577 | 577 | return $entries; |
| 578 | 578 | } |
| 579 | 579 | $entries = $this->access->countUsers($filter); |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | * Backend name to be shown in user management |
| 586 | 586 | * @return string the name of the backend to be shown |
| 587 | 587 | */ |
| 588 | - public function getBackendName(){ |
|
| 588 | + public function getBackendName() { |
|
| 589 | 589 | return 'LDAP'; |
| 590 | 590 | } |
| 591 | 591 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return AbstractMapping |
| 126 | 126 | */ |
| 127 | 127 | public function getUserMapper() { |
| 128 | - if(is_null($this->userMapper)) { |
|
| 128 | + if (is_null($this->userMapper)) { |
|
| 129 | 129 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
| 130 | 130 | } |
| 131 | 131 | return $this->userMapper; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return AbstractMapping |
| 146 | 146 | */ |
| 147 | 147 | public function getGroupMapper() { |
| 148 | - if(is_null($this->groupMapper)) { |
|
| 148 | + if (is_null($this->groupMapper)) { |
|
| 149 | 149 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
| 150 | 150 | } |
| 151 | 151 | return $this->groupMapper; |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | * @throws ServerNotAvailableException |
| 179 | 179 | */ |
| 180 | 180 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
| 181 | - if(!$this->checkConnection()) { |
|
| 181 | + if (!$this->checkConnection()) { |
|
| 182 | 182 | \OCP\Util::writeLog('user_ldap', |
| 183 | 183 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
| 184 | 184 | \OCP\Util::WARN); |
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | $cr = $this->connection->getConnectionResource(); |
| 188 | - if(!$this->ldap->isResource($cr)) { |
|
| 188 | + if (!$this->ldap->isResource($cr)) { |
|
| 189 | 189 | //LDAP not available |
| 190 | 190 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 191 | 191 | return false; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $isRangeRequest = false; |
| 209 | 209 | do { |
| 210 | 210 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
| 211 | - if(is_bool($result)) { |
|
| 211 | + if (is_bool($result)) { |
|
| 212 | 212 | // when an exists request was run and it was successful, an empty |
| 213 | 213 | // array must be returned |
| 214 | 214 | return $result ? [] : false; |
@@ -225,22 +225,22 @@ discard block |
||
| 225 | 225 | $result = $this->extractRangeData($result, $attr); |
| 226 | 226 | if (!empty($result)) { |
| 227 | 227 | $normalizedResult = $this->extractAttributeValuesFromResult( |
| 228 | - [ $attr => $result['values'] ], |
|
| 228 | + [$attr => $result['values']], |
|
| 229 | 229 | $attr |
| 230 | 230 | ); |
| 231 | 231 | $values = array_merge($values, $normalizedResult); |
| 232 | 232 | |
| 233 | - if($result['rangeHigh'] === '*') { |
|
| 233 | + if ($result['rangeHigh'] === '*') { |
|
| 234 | 234 | // when server replies with * as high range value, there are |
| 235 | 235 | // no more results left |
| 236 | 236 | return $values; |
| 237 | 237 | } else { |
| 238 | - $low = $result['rangeHigh'] + 1; |
|
| 239 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
| 238 | + $low = $result['rangeHigh'] + 1; |
|
| 239 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
| 240 | 240 | $isRangeRequest = true; |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | - } while($isRangeRequest); |
|
| 243 | + } while ($isRangeRequest); |
|
| 244 | 244 | |
| 245 | 245 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); |
| 246 | 246 | return false; |
@@ -266,13 +266,13 @@ discard block |
||
| 266 | 266 | if (!$this->ldap->isResource($rr)) { |
| 267 | 267 | if ($attribute !== '') { |
| 268 | 268 | //do not throw this message on userExists check, irritates |
| 269 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); |
|
| 269 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); |
|
| 270 | 270 | } |
| 271 | 271 | //in case an error occurs , e.g. object does not exist |
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
| 275 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); |
|
| 275 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG); |
|
| 276 | 276 | return true; |
| 277 | 277 | } |
| 278 | 278 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function extractAttributeValuesFromResult($result, $attribute) { |
| 299 | 299 | $values = []; |
| 300 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 300 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 301 | 301 | $lowercaseAttribute = strtolower($attribute); |
| 302 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
| 303 | - if($this->resemblesDN($attribute)) { |
|
| 302 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
| 303 | + if ($this->resemblesDN($attribute)) { |
|
| 304 | 304 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
| 305 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 305 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 306 | 306 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
| 307 | 307 | } else { |
| 308 | 308 | $values[] = $result[$attribute][$i]; |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | public function extractRangeData($result, $attribute) { |
| 326 | 326 | $keys = array_keys($result); |
| 327 | - foreach($keys as $key) { |
|
| 328 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 327 | + foreach ($keys as $key) { |
|
| 328 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 329 | 329 | $queryData = explode(';', $key); |
| 330 | - if(strpos($queryData[1], 'range=') === 0) { |
|
| 330 | + if (strpos($queryData[1], 'range=') === 0) { |
|
| 331 | 331 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
| 332 | 332 | $data = [ |
| 333 | 333 | 'values' => $result[$key], |
@@ -352,18 +352,18 @@ discard block |
||
| 352 | 352 | * @throws \Exception |
| 353 | 353 | */ |
| 354 | 354 | public function setPassword($userDN, $password) { |
| 355 | - if(intval($this->connection->turnOnPasswordChange) !== 1) { |
|
| 355 | + if (intval($this->connection->turnOnPasswordChange) !== 1) { |
|
| 356 | 356 | throw new \Exception('LDAP password changes are disabled.'); |
| 357 | 357 | } |
| 358 | 358 | $cr = $this->connection->getConnectionResource(); |
| 359 | - if(!$this->ldap->isResource($cr)) { |
|
| 359 | + if (!$this->ldap->isResource($cr)) { |
|
| 360 | 360 | //LDAP not available |
| 361 | 361 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 362 | 362 | return false; |
| 363 | 363 | } |
| 364 | 364 | try { |
| 365 | 365 | return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
| 366 | - } catch(ConstraintViolationException $e) { |
|
| 366 | + } catch (ConstraintViolationException $e) { |
|
| 367 | 367 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
| 368 | 368 | } |
| 369 | 369 | } |
@@ -405,17 +405,17 @@ discard block |
||
| 405 | 405 | */ |
| 406 | 406 | public function getDomainDNFromDN($dn) { |
| 407 | 407 | $allParts = $this->ldap->explodeDN($dn, 0); |
| 408 | - if($allParts === false) { |
|
| 408 | + if ($allParts === false) { |
|
| 409 | 409 | //not a valid DN |
| 410 | 410 | return ''; |
| 411 | 411 | } |
| 412 | 412 | $domainParts = array(); |
| 413 | 413 | $dcFound = false; |
| 414 | - foreach($allParts as $part) { |
|
| 415 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 414 | + foreach ($allParts as $part) { |
|
| 415 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 416 | 416 | $dcFound = true; |
| 417 | 417 | } |
| 418 | - if($dcFound) { |
|
| 418 | + if ($dcFound) { |
|
| 419 | 419 | $domainParts[] = $part; |
| 420 | 420 | } |
| 421 | 421 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | |
| 443 | 443 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
| 444 | 444 | //server setups |
| 445 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 445 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 446 | 446 | return $fdn; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | //To avoid bypassing the base DN settings under certain circumstances |
| 460 | 460 | //with the group support, check whether the provided DN matches one of |
| 461 | 461 | //the given Bases |
| 462 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 462 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | public function groupsMatchFilter($groupDNs) { |
| 478 | 478 | $validGroupDNs = []; |
| 479 | - foreach($groupDNs as $dn) { |
|
| 479 | + foreach ($groupDNs as $dn) { |
|
| 480 | 480 | $cacheKey = 'groupsMatchFilter-'.$dn; |
| 481 | 481 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
| 482 | - if(!is_null($groupMatchFilter)) { |
|
| 483 | - if($groupMatchFilter) { |
|
| 482 | + if (!is_null($groupMatchFilter)) { |
|
| 483 | + if ($groupMatchFilter) { |
|
| 484 | 484 | $validGroupDNs[] = $dn; |
| 485 | 485 | } |
| 486 | 486 | continue; |
@@ -488,13 +488,13 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | // Check the base DN first. If this is not met already, we don't |
| 490 | 490 | // need to ask the server at all. |
| 491 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 491 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 492 | 492 | $this->connection->writeToCache($cacheKey, false); |
| 493 | 493 | continue; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | $result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter); |
| 497 | - if(is_array($result)) { |
|
| 497 | + if (is_array($result)) { |
|
| 498 | 498 | $this->connection->writeToCache($cacheKey, true); |
| 499 | 499 | $validGroupDNs[] = $dn; |
| 500 | 500 | } else { |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | //To avoid bypassing the base DN settings under certain circumstances |
| 516 | 516 | //with the group support, check whether the provided DN matches one of |
| 517 | 517 | //the given Bases |
| 518 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 518 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 519 | 519 | return false; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | */ |
| 536 | 536 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
| 537 | 537 | $newlyMapped = false; |
| 538 | - if($isUser) { |
|
| 538 | + if ($isUser) { |
|
| 539 | 539 | $mapper = $this->getUserMapper(); |
| 540 | 540 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 541 | 541 | } else { |
@@ -545,15 +545,15 @@ discard block |
||
| 545 | 545 | |
| 546 | 546 | //let's try to retrieve the Nextcloud name from the mappings table |
| 547 | 547 | $ncName = $mapper->getNameByDN($fdn); |
| 548 | - if(is_string($ncName)) { |
|
| 548 | + if (is_string($ncName)) { |
|
| 549 | 549 | return $ncName; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
| 553 | 553 | $uuid = $this->getUUID($fdn, $isUser, $record); |
| 554 | - if(is_string($uuid)) { |
|
| 554 | + if (is_string($uuid)) { |
|
| 555 | 555 | $ncName = $mapper->getNameByUUID($uuid); |
| 556 | - if(is_string($ncName)) { |
|
| 556 | + if (is_string($ncName)) { |
|
| 557 | 557 | $mapper->setDNbyUUID($fdn, $uuid); |
| 558 | 558 | return $ncName; |
| 559 | 559 | } |
@@ -563,16 +563,16 @@ discard block |
||
| 563 | 563 | return false; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - if(is_null($ldapName)) { |
|
| 566 | + if (is_null($ldapName)) { |
|
| 567 | 567 | $ldapName = $this->readAttribute($fdn, $nameAttribute); |
| 568 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 568 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 569 | 569 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO); |
| 570 | 570 | return false; |
| 571 | 571 | } |
| 572 | 572 | $ldapName = $ldapName[0]; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - if($isUser) { |
|
| 575 | + if ($isUser) { |
|
| 576 | 576 | $usernameAttribute = strval($this->connection->ldapExpertUsernameAttr); |
| 577 | 577 | if ($usernameAttribute !== '') { |
| 578 | 578 | $username = $this->readAttribute($fdn, $usernameAttribute); |
@@ -591,9 +591,9 @@ discard block |
||
| 591 | 591 | // outside of core user management will still cache the user as non-existing. |
| 592 | 592 | $originalTTL = $this->connection->ldapCacheTTL; |
| 593 | 593 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 594 | - if(($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName)) |
|
| 594 | + if (($isUser && $intName !== '' && !\OC::$server->getUserManager()->userExists($intName)) |
|
| 595 | 595 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { |
| 596 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
| 596 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
| 597 | 597 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 598 | 598 | $newlyMapped = true; |
| 599 | 599 | return $intName; |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 603 | 603 | |
| 604 | 604 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
| 605 | - if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 605 | + if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 606 | 606 | $newlyMapped = true; |
| 607 | 607 | return $altName; |
| 608 | 608 | } |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | * @return array |
| 641 | 641 | */ |
| 642 | 642 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
| 643 | - if($isUsers) { |
|
| 643 | + if ($isUsers) { |
|
| 644 | 644 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 645 | 645 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
| 646 | 646 | } else { |
@@ -648,9 +648,9 @@ discard block |
||
| 648 | 648 | } |
| 649 | 649 | $nextcloudNames = array(); |
| 650 | 650 | |
| 651 | - foreach($ldapObjects as $ldapObject) { |
|
| 651 | + foreach ($ldapObjects as $ldapObject) { |
|
| 652 | 652 | $nameByLDAP = null; |
| 653 | - if( isset($ldapObject[$nameAttribute]) |
|
| 653 | + if (isset($ldapObject[$nameAttribute]) |
|
| 654 | 654 | && is_array($ldapObject[$nameAttribute]) |
| 655 | 655 | && isset($ldapObject[$nameAttribute][0]) |
| 656 | 656 | ) { |
@@ -659,12 +659,12 @@ discard block |
||
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
| 662 | - if($ncName) { |
|
| 662 | + if ($ncName) { |
|
| 663 | 663 | $nextcloudNames[] = $ncName; |
| 664 | - if($isUsers) { |
|
| 664 | + if ($isUsers) { |
|
| 665 | 665 | //cache the user names so it does not need to be retrieved |
| 666 | 666 | //again later (e.g. sharing dialogue). |
| 667 | - if(is_null($nameByLDAP)) { |
|
| 667 | + if (is_null($nameByLDAP)) { |
|
| 668 | 668 | continue; |
| 669 | 669 | } |
| 670 | 670 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
| 704 | 704 | $user = $this->userManager->get($ocName); |
| 705 | - if($user === null) { |
|
| 705 | + if ($user === null) { |
|
| 706 | 706 | return; |
| 707 | 707 | } |
| 708 | 708 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -722,9 +722,9 @@ discard block |
||
| 722 | 722 | $attempts = 0; |
| 723 | 723 | //while loop is just a precaution. If a name is not generated within |
| 724 | 724 | //20 attempts, something else is very wrong. Avoids infinite loop. |
| 725 | - while($attempts < 20){ |
|
| 726 | - $altName = $name . '_' . rand(1000,9999); |
|
| 727 | - if(!\OC::$server->getUserManager()->userExists($altName)) { |
|
| 725 | + while ($attempts < 20) { |
|
| 726 | + $altName = $name.'_'.rand(1000, 9999); |
|
| 727 | + if (!\OC::$server->getUserManager()->userExists($altName)) { |
|
| 728 | 728 | return $altName; |
| 729 | 729 | } |
| 730 | 730 | $attempts++; |
@@ -746,25 +746,25 @@ discard block |
||
| 746 | 746 | */ |
| 747 | 747 | private function _createAltInternalOwnCloudNameForGroups($name) { |
| 748 | 748 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
| 749 | - if(!($usedNames) || count($usedNames) === 0) { |
|
| 749 | + if (!($usedNames) || count($usedNames) === 0) { |
|
| 750 | 750 | $lastNo = 1; //will become name_2 |
| 751 | 751 | } else { |
| 752 | 752 | natsort($usedNames); |
| 753 | 753 | $lastName = array_pop($usedNames); |
| 754 | 754 | $lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1)); |
| 755 | 755 | } |
| 756 | - $altName = $name.'_'.strval($lastNo+1); |
|
| 756 | + $altName = $name.'_'.strval($lastNo + 1); |
|
| 757 | 757 | unset($usedNames); |
| 758 | 758 | |
| 759 | 759 | $attempts = 1; |
| 760 | - while($attempts < 21){ |
|
| 760 | + while ($attempts < 21) { |
|
| 761 | 761 | // Check to be really sure it is unique |
| 762 | 762 | // while loop is just a precaution. If a name is not generated within |
| 763 | 763 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
| 764 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 764 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 765 | 765 | return $altName; |
| 766 | 766 | } |
| 767 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
| 767 | + $altName = $name.'_'.($lastNo + $attempts); |
|
| 768 | 768 | $attempts++; |
| 769 | 769 | } |
| 770 | 770 | return false; |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | private function createAltInternalOwnCloudName($name, $isUser) { |
| 780 | 780 | $originalTTL = $this->connection->ldapCacheTTL; |
| 781 | 781 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 782 | - if($isUser) { |
|
| 782 | + if ($isUser) { |
|
| 783 | 783 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
| 784 | 784 | } else { |
| 785 | 785 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -829,13 +829,13 @@ discard block |
||
| 829 | 829 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
| 830 | 830 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
| 831 | 831 | $recordsToUpdate = $ldapRecords; |
| 832 | - if(!$forceApplyAttributes) { |
|
| 832 | + if (!$forceApplyAttributes) { |
|
| 833 | 833 | $isBackgroundJobModeAjax = $this->config |
| 834 | 834 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
| 835 | 835 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
| 836 | 836 | $newlyMapped = false; |
| 837 | 837 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
| 838 | - if(is_string($uid)) { |
|
| 838 | + if (is_string($uid)) { |
|
| 839 | 839 | $this->cacheUserExists($uid); |
| 840 | 840 | } |
| 841 | 841 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -851,19 +851,19 @@ discard block |
||
| 851 | 851 | * and their values |
| 852 | 852 | * @param array $ldapRecords |
| 853 | 853 | */ |
| 854 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
| 854 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
| 855 | 855 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
| 856 | - foreach($ldapRecords as $userRecord) { |
|
| 857 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
| 856 | + foreach ($ldapRecords as $userRecord) { |
|
| 857 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
| 858 | 858 | // displayName is obligatory |
| 859 | 859 | continue; |
| 860 | 860 | } |
| 861 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 862 | - if($ocName === false) { |
|
| 861 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 862 | + if ($ocName === false) { |
|
| 863 | 863 | continue; |
| 864 | 864 | } |
| 865 | 865 | $user = $this->userManager->get($ocName); |
| 866 | - if($user instanceof OfflineUser) { |
|
| 866 | + if ($user instanceof OfflineUser) { |
|
| 867 | 867 | $user->unmark(); |
| 868 | 868 | $user = $this->userManager->get($ocName); |
| 869 | 869 | } |
@@ -895,8 +895,8 @@ discard block |
||
| 895 | 895 | * @return array |
| 896 | 896 | */ |
| 897 | 897 | private function fetchList($list, $manyAttributes) { |
| 898 | - if(is_array($list)) { |
|
| 899 | - if($manyAttributes) { |
|
| 898 | + if (is_array($list)) { |
|
| 899 | + if ($manyAttributes) { |
|
| 900 | 900 | return $list; |
| 901 | 901 | } else { |
| 902 | 902 | $list = array_reduce($list, function($carry, $item) { |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | // php no longer supports call-time pass-by-reference |
| 995 | 995 | // thus cannot support controlPagedResultResponse as the third argument |
| 996 | 996 | // is a reference |
| 997 | - $doMethod = function () use ($command, &$arguments) { |
|
| 997 | + $doMethod = function() use ($command, &$arguments) { |
|
| 998 | 998 | if ($command == 'controlPagedResultResponse') { |
| 999 | 999 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
| 1000 | 1000 | } else { |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | $this->connection->resetConnectionResource(); |
| 1013 | 1013 | $cr = $this->connection->getConnectionResource(); |
| 1014 | 1014 | |
| 1015 | - if(!$this->ldap->isResource($cr)) { |
|
| 1015 | + if (!$this->ldap->isResource($cr)) { |
|
| 1016 | 1016 | // Seems like we didn't find any resource. |
| 1017 | 1017 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG); |
| 1018 | 1018 | throw $e; |
@@ -1037,13 +1037,13 @@ discard block |
||
| 1037 | 1037 | * @throws ServerNotAvailableException |
| 1038 | 1038 | */ |
| 1039 | 1039 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
| 1040 | - if(!is_null($attr) && !is_array($attr)) { |
|
| 1040 | + if (!is_null($attr) && !is_array($attr)) { |
|
| 1041 | 1041 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | // See if we have a resource, in case not cancel with message |
| 1045 | 1045 | $cr = $this->connection->getConnectionResource(); |
| 1046 | - if(!$this->ldap->isResource($cr)) { |
|
| 1046 | + if (!$this->ldap->isResource($cr)) { |
|
| 1047 | 1047 | // Seems like we didn't find any resource. |
| 1048 | 1048 | // Return an empty array just like before. |
| 1049 | 1049 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); |
@@ -1057,7 +1057,7 @@ discard block |
||
| 1057 | 1057 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
| 1058 | 1058 | // cannot use $cr anymore, might have changed in the previous call! |
| 1059 | 1059 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
| 1060 | - if(!is_array($sr) || $error !== 0) { |
|
| 1060 | + if (!is_array($sr) || $error !== 0) { |
|
| 1061 | 1061 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); |
| 1062 | 1062 | return false; |
| 1063 | 1063 | } |
@@ -1080,29 +1080,29 @@ discard block |
||
| 1080 | 1080 | */ |
| 1081 | 1081 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
| 1082 | 1082 | $cookie = null; |
| 1083 | - if($pagedSearchOK) { |
|
| 1083 | + if ($pagedSearchOK) { |
|
| 1084 | 1084 | $cr = $this->connection->getConnectionResource(); |
| 1085 | - foreach($sr as $key => $res) { |
|
| 1086 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1085 | + foreach ($sr as $key => $res) { |
|
| 1086 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1087 | 1087 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
| 1088 | 1088 | } |
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | //browsing through prior pages to get the cookie for the new one |
| 1092 | - if($skipHandling) { |
|
| 1092 | + if ($skipHandling) { |
|
| 1093 | 1093 | return false; |
| 1094 | 1094 | } |
| 1095 | 1095 | // if count is bigger, then the server does not support |
| 1096 | 1096 | // paged search. Instead, he did a normal search. We set a |
| 1097 | 1097 | // flag here, so the callee knows how to deal with it. |
| 1098 | - if($iFoundItems <= $limit) { |
|
| 1098 | + if ($iFoundItems <= $limit) { |
|
| 1099 | 1099 | $this->pagedSearchedSuccessful = true; |
| 1100 | 1100 | } |
| 1101 | 1101 | } else { |
| 1102 | - if(!is_null($limit) && intval($this->connection->ldapPagingSize) !== 0) { |
|
| 1102 | + if (!is_null($limit) && intval($this->connection->ldapPagingSize) !== 0) { |
|
| 1103 | 1103 | \OC::$server->getLogger()->debug( |
| 1104 | 1104 | 'Paged search was not available', |
| 1105 | - [ 'app' => 'user_ldap' ] |
|
| 1105 | + ['app' => 'user_ldap'] |
|
| 1106 | 1106 | ); |
| 1107 | 1107 | } |
| 1108 | 1108 | } |
@@ -1132,7 +1132,7 @@ discard block |
||
| 1132 | 1132 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); |
| 1133 | 1133 | |
| 1134 | 1134 | $limitPerPage = intval($this->connection->ldapPagingSize); |
| 1135 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1135 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1136 | 1136 | $limitPerPage = $limit; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
@@ -1142,7 +1142,7 @@ discard block |
||
| 1142 | 1142 | |
| 1143 | 1143 | do { |
| 1144 | 1144 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1145 | - if($search === false) { |
|
| 1145 | + if ($search === false) { |
|
| 1146 | 1146 | return $counter > 0 ? $counter : false; |
| 1147 | 1147 | } |
| 1148 | 1148 | list($sr, $pagedSearchOK) = $search; |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | * Continue now depends on $hasMorePages value |
| 1162 | 1162 | */ |
| 1163 | 1163 | $continue = $pagedSearchOK && $hasMorePages; |
| 1164 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1164 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1165 | 1165 | |
| 1166 | 1166 | return $counter; |
| 1167 | 1167 | } |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | private function countEntriesInSearchResults($searchResults) { |
| 1174 | 1174 | $counter = 0; |
| 1175 | 1175 | |
| 1176 | - foreach($searchResults as $res) { |
|
| 1176 | + foreach ($searchResults as $res) { |
|
| 1177 | 1177 | $count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res)); |
| 1178 | 1178 | $counter += $count; |
| 1179 | 1179 | } |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | */ |
| 1196 | 1196 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1197 | 1197 | $limitPerPage = intval($this->connection->ldapPagingSize); |
| 1198 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1198 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1199 | 1199 | $limitPerPage = $limit; |
| 1200 | 1200 | } |
| 1201 | 1201 | |
@@ -1209,13 +1209,13 @@ discard block |
||
| 1209 | 1209 | $savedoffset = $offset; |
| 1210 | 1210 | do { |
| 1211 | 1211 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1212 | - if($search === false) { |
|
| 1212 | + if ($search === false) { |
|
| 1213 | 1213 | return []; |
| 1214 | 1214 | } |
| 1215 | 1215 | list($sr, $pagedSearchOK) = $search; |
| 1216 | 1216 | $cr = $this->connection->getConnectionResource(); |
| 1217 | 1217 | |
| 1218 | - if($skipHandling) { |
|
| 1218 | + if ($skipHandling) { |
|
| 1219 | 1219 | //i.e. result do not need to be fetched, we just need the cookie |
| 1220 | 1220 | //thus pass 1 or any other value as $iFoundItems because it is not |
| 1221 | 1221 | //used |
@@ -1226,7 +1226,7 @@ discard block |
||
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | $iFoundItems = 0; |
| 1229 | - foreach($sr as $res) { |
|
| 1229 | + foreach ($sr as $res) { |
|
| 1230 | 1230 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
| 1231 | 1231 | $iFoundItems = max($iFoundItems, $findings['count']); |
| 1232 | 1232 | unset($findings['count']); |
@@ -1242,27 +1242,27 @@ discard block |
||
| 1242 | 1242 | |
| 1243 | 1243 | // if we're here, probably no connection resource is returned. |
| 1244 | 1244 | // to make Nextcloud behave nicely, we simply give back an empty array. |
| 1245 | - if(is_null($findings)) { |
|
| 1245 | + if (is_null($findings)) { |
|
| 1246 | 1246 | return array(); |
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | - if(!is_null($attr)) { |
|
| 1249 | + if (!is_null($attr)) { |
|
| 1250 | 1250 | $selection = []; |
| 1251 | 1251 | $i = 0; |
| 1252 | - foreach($findings as $item) { |
|
| 1253 | - if(!is_array($item)) { |
|
| 1252 | + foreach ($findings as $item) { |
|
| 1253 | + if (!is_array($item)) { |
|
| 1254 | 1254 | continue; |
| 1255 | 1255 | } |
| 1256 | 1256 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
| 1257 | - foreach($attr as $key) { |
|
| 1258 | - if(isset($item[$key])) { |
|
| 1259 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1257 | + foreach ($attr as $key) { |
|
| 1258 | + if (isset($item[$key])) { |
|
| 1259 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1260 | 1260 | unset($item[$key]['count']); |
| 1261 | 1261 | } |
| 1262 | - if($key !== 'dn') { |
|
| 1263 | - if($this->resemblesDN($key)) { |
|
| 1262 | + if ($key !== 'dn') { |
|
| 1263 | + if ($this->resemblesDN($key)) { |
|
| 1264 | 1264 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
| 1265 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
| 1265 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
| 1266 | 1266 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
| 1267 | 1267 | } else { |
| 1268 | 1268 | $selection[$i][$key] = $item[$key]; |
@@ -1280,7 +1280,7 @@ discard block |
||
| 1280 | 1280 | //we slice the findings, when |
| 1281 | 1281 | //a) paged search unsuccessful, though attempted |
| 1282 | 1282 | //b) no paged search, but limit set |
| 1283 | - if((!$this->getPagedSearchResultState() |
|
| 1283 | + if ((!$this->getPagedSearchResultState() |
|
| 1284 | 1284 | && $pagedSearchOK) |
| 1285 | 1285 | || ( |
| 1286 | 1286 | !$pagedSearchOK |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | * @return bool|mixed|string |
| 1298 | 1298 | */ |
| 1299 | 1299 | public function sanitizeUsername($name) { |
| 1300 | - if($this->connection->ldapIgnoreNamingRules) { |
|
| 1300 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
| 1301 | 1301 | return trim($name); |
| 1302 | 1302 | } |
| 1303 | 1303 | |
@@ -1322,13 +1322,13 @@ discard block |
||
| 1322 | 1322 | */ |
| 1323 | 1323 | public function escapeFilterPart($input, $allowAsterisk = false) { |
| 1324 | 1324 | $asterisk = ''; |
| 1325 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1325 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1326 | 1326 | $asterisk = '*'; |
| 1327 | 1327 | $input = mb_substr($input, 1, null, 'UTF-8'); |
| 1328 | 1328 | } |
| 1329 | 1329 | $search = array('*', '\\', '(', ')'); |
| 1330 | 1330 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
| 1331 | - return $asterisk . str_replace($search, $replace, $input); |
|
| 1331 | + return $asterisk.str_replace($search, $replace, $input); |
|
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | /** |
@@ -1358,13 +1358,13 @@ discard block |
||
| 1358 | 1358 | */ |
| 1359 | 1359 | private function combineFilter($filters, $operator) { |
| 1360 | 1360 | $combinedFilter = '('.$operator; |
| 1361 | - foreach($filters as $filter) { |
|
| 1361 | + foreach ($filters as $filter) { |
|
| 1362 | 1362 | if ($filter !== '' && $filter[0] !== '(') { |
| 1363 | 1363 | $filter = '('.$filter.')'; |
| 1364 | 1364 | } |
| 1365 | - $combinedFilter.=$filter; |
|
| 1365 | + $combinedFilter .= $filter; |
|
| 1366 | 1366 | } |
| 1367 | - $combinedFilter.=')'; |
|
| 1367 | + $combinedFilter .= ')'; |
|
| 1368 | 1368 | return $combinedFilter; |
| 1369 | 1369 | } |
| 1370 | 1370 | |
@@ -1400,17 +1400,17 @@ discard block |
||
| 1400 | 1400 | * @throws \Exception |
| 1401 | 1401 | */ |
| 1402 | 1402 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
| 1403 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1403 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1404 | 1404 | throw new \Exception('searchAttributes must be an array with at least two string'); |
| 1405 | 1405 | } |
| 1406 | 1406 | $searchWords = explode(' ', trim($search)); |
| 1407 | 1407 | $wordFilters = array(); |
| 1408 | - foreach($searchWords as $word) { |
|
| 1408 | + foreach ($searchWords as $word) { |
|
| 1409 | 1409 | $word = $this->prepareSearchTerm($word); |
| 1410 | 1410 | //every word needs to appear at least once |
| 1411 | 1411 | $wordMatchOneAttrFilters = array(); |
| 1412 | - foreach($searchAttributes as $attr) { |
|
| 1413 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
| 1412 | + foreach ($searchAttributes as $attr) { |
|
| 1413 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
| 1414 | 1414 | } |
| 1415 | 1415 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
| 1416 | 1416 | } |
@@ -1428,10 +1428,10 @@ discard block |
||
| 1428 | 1428 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
| 1429 | 1429 | $filter = array(); |
| 1430 | 1430 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
| 1431 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1431 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1432 | 1432 | try { |
| 1433 | 1433 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
| 1434 | - } catch(\Exception $e) { |
|
| 1434 | + } catch (\Exception $e) { |
|
| 1435 | 1435 | \OCP\Util::writeLog( |
| 1436 | 1436 | 'user_ldap', |
| 1437 | 1437 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1441,17 +1441,17 @@ discard block |
||
| 1441 | 1441 | } |
| 1442 | 1442 | |
| 1443 | 1443 | $search = $this->prepareSearchTerm($search); |
| 1444 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1444 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1445 | 1445 | if ($fallbackAttribute === '') { |
| 1446 | 1446 | return ''; |
| 1447 | 1447 | } |
| 1448 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
| 1448 | + $filter[] = $fallbackAttribute.'='.$search; |
|
| 1449 | 1449 | } else { |
| 1450 | - foreach($searchAttributes as $attribute) { |
|
| 1451 | - $filter[] = $attribute . '=' . $search; |
|
| 1450 | + foreach ($searchAttributes as $attribute) { |
|
| 1451 | + $filter[] = $attribute.'='.$search; |
|
| 1452 | 1452 | } |
| 1453 | 1453 | } |
| 1454 | - if(count($filter) === 1) { |
|
| 1454 | + if (count($filter) === 1) { |
|
| 1455 | 1455 | return '('.$filter[0].')'; |
| 1456 | 1456 | } |
| 1457 | 1457 | return $this->combineFilterWithOr($filter); |
@@ -1472,7 +1472,7 @@ discard block |
||
| 1472 | 1472 | if ($term === '') { |
| 1473 | 1473 | $result = '*'; |
| 1474 | 1474 | } else if ($allowEnum !== 'no') { |
| 1475 | - $result = $term . '*'; |
|
| 1475 | + $result = $term.'*'; |
|
| 1476 | 1476 | } |
| 1477 | 1477 | return $result; |
| 1478 | 1478 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | public function getFilterForUserCount() { |
| 1485 | 1485 | $filter = $this->combineFilterWithAnd(array( |
| 1486 | 1486 | $this->connection->ldapUserFilter, |
| 1487 | - $this->connection->ldapUserDisplayName . '=*' |
|
| 1487 | + $this->connection->ldapUserDisplayName.'=*' |
|
| 1488 | 1488 | )); |
| 1489 | 1489 | |
| 1490 | 1490 | return $filter; |
@@ -1502,7 +1502,7 @@ discard block |
||
| 1502 | 1502 | 'ldapAgentName' => $name, |
| 1503 | 1503 | 'ldapAgentPassword' => $password |
| 1504 | 1504 | ); |
| 1505 | - if(!$testConnection->setConfiguration($credentials)) { |
|
| 1505 | + if (!$testConnection->setConfiguration($credentials)) { |
|
| 1506 | 1506 | return false; |
| 1507 | 1507 | } |
| 1508 | 1508 | return $testConnection->bind(); |
@@ -1524,30 +1524,30 @@ discard block |
||
| 1524 | 1524 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
| 1525 | 1525 | // existing DN to be able to reliably detect it. |
| 1526 | 1526 | $result = $this->search($filter, $base, ['dn'], 1); |
| 1527 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1527 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1528 | 1528 | throw new \Exception('Cannot determine UUID attribute'); |
| 1529 | 1529 | } |
| 1530 | 1530 | $dn = $result[0]['dn'][0]; |
| 1531 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
| 1531 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
| 1532 | 1532 | throw new \Exception('Cannot determine UUID attribute'); |
| 1533 | 1533 | } |
| 1534 | 1534 | } else { |
| 1535 | 1535 | // The UUID attribute is either known or an override is given. |
| 1536 | 1536 | // By calling this method we ensure that $this->connection->$uuidAttr |
| 1537 | 1537 | // is definitely set |
| 1538 | - if(!$this->detectUuidAttribute('', true)) { |
|
| 1538 | + if (!$this->detectUuidAttribute('', true)) { |
|
| 1539 | 1539 | throw new \Exception('Cannot determine UUID attribute'); |
| 1540 | 1540 | } |
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
| 1544 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1544 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1545 | 1545 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | - $filter = $uuidAttr . '=' . $uuid; |
|
| 1548 | + $filter = $uuidAttr.'='.$uuid; |
|
| 1549 | 1549 | $result = $this->searchUsers($filter, ['dn'], 2); |
| 1550 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1550 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1551 | 1551 | // we put the count into account to make sure that this is |
| 1552 | 1552 | // really unique |
| 1553 | 1553 | return $result[0]['dn'][0]; |
@@ -1566,7 +1566,7 @@ discard block |
||
| 1566 | 1566 | * @return bool true on success, false otherwise |
| 1567 | 1567 | */ |
| 1568 | 1568 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
| 1569 | - if($isUser) { |
|
| 1569 | + if ($isUser) { |
|
| 1570 | 1570 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1571 | 1571 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1572 | 1572 | } else { |
@@ -1574,7 +1574,7 @@ discard block |
||
| 1574 | 1574 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1577 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1578 | 1578 | return true; |
| 1579 | 1579 | } |
| 1580 | 1580 | |
@@ -1583,10 +1583,10 @@ discard block |
||
| 1583 | 1583 | return true; |
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
| 1587 | - if($ldapRecord !== null) { |
|
| 1586 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
| 1587 | + if ($ldapRecord !== null) { |
|
| 1588 | 1588 | // we have the info from LDAP already, we don't need to talk to the server again |
| 1589 | - if(isset($ldapRecord[$attribute])) { |
|
| 1589 | + if (isset($ldapRecord[$attribute])) { |
|
| 1590 | 1590 | $this->connection->$uuidAttr = $attribute; |
| 1591 | 1591 | return true; |
| 1592 | 1592 | } else { |
@@ -1595,7 +1595,7 @@ discard block |
||
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | $value = $this->readAttribute($dn, $attribute); |
| 1598 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1598 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1599 | 1599 | \OCP\Util::writeLog('user_ldap', |
| 1600 | 1600 | 'Setting '.$attribute.' as '.$uuidAttr, |
| 1601 | 1601 | \OCP\Util::DEBUG); |
@@ -1617,7 +1617,7 @@ discard block |
||
| 1617 | 1617 | * @return bool|string |
| 1618 | 1618 | */ |
| 1619 | 1619 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
| 1620 | - if($isUser) { |
|
| 1620 | + if ($isUser) { |
|
| 1621 | 1621 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1622 | 1622 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1623 | 1623 | } else { |
@@ -1626,10 +1626,10 @@ discard block |
||
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | $uuid = false; |
| 1629 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1629 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1630 | 1630 | $attr = $this->connection->$uuidAttr; |
| 1631 | 1631 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
| 1632 | - if( !is_array($uuid) |
|
| 1632 | + if (!is_array($uuid) |
|
| 1633 | 1633 | && $uuidOverride !== '' |
| 1634 | 1634 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
| 1635 | 1635 | { |
@@ -1637,7 +1637,7 @@ discard block |
||
| 1637 | 1637 | ? $ldapRecord[$this->connection->$uuidAttr] |
| 1638 | 1638 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
| 1639 | 1639 | } |
| 1640 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1640 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1641 | 1641 | $uuid = $uuid[0]; |
| 1642 | 1642 | } |
| 1643 | 1643 | } |
@@ -1654,19 +1654,19 @@ discard block |
||
| 1654 | 1654 | private function convertObjectGUID2Str($oguid) { |
| 1655 | 1655 | $hex_guid = bin2hex($oguid); |
| 1656 | 1656 | $hex_guid_to_guid_str = ''; |
| 1657 | - for($k = 1; $k <= 4; ++$k) { |
|
| 1657 | + for ($k = 1; $k <= 4; ++$k) { |
|
| 1658 | 1658 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
| 1659 | 1659 | } |
| 1660 | 1660 | $hex_guid_to_guid_str .= '-'; |
| 1661 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1661 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1662 | 1662 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
| 1663 | 1663 | } |
| 1664 | 1664 | $hex_guid_to_guid_str .= '-'; |
| 1665 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1665 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1666 | 1666 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
| 1667 | 1667 | } |
| 1668 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
| 1669 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
| 1668 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
| 1669 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
| 1670 | 1670 | |
| 1671 | 1671 | return strtoupper($hex_guid_to_guid_str); |
| 1672 | 1672 | } |
@@ -1683,11 +1683,11 @@ discard block |
||
| 1683 | 1683 | * @return string |
| 1684 | 1684 | */ |
| 1685 | 1685 | public function formatGuid2ForFilterUser($guid) { |
| 1686 | - if(!is_string($guid)) { |
|
| 1686 | + if (!is_string($guid)) { |
|
| 1687 | 1687 | throw new \InvalidArgumentException('String expected'); |
| 1688 | 1688 | } |
| 1689 | 1689 | $blocks = explode('-', $guid); |
| 1690 | - if(count($blocks) !== 5) { |
|
| 1690 | + if (count($blocks) !== 5) { |
|
| 1691 | 1691 | /* |
| 1692 | 1692 | * Why not throw an Exception instead? This method is a utility |
| 1693 | 1693 | * called only when trying to figure out whether a "missing" known |
@@ -1700,20 +1700,20 @@ discard block |
||
| 1700 | 1700 | * user. Instead we write a log message. |
| 1701 | 1701 | */ |
| 1702 | 1702 | \OC::$server->getLogger()->info( |
| 1703 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
| 1703 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
| 1704 | 1704 | '({uuid}) probably does not match UUID configuration.', |
| 1705 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
| 1705 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
| 1706 | 1706 | ); |
| 1707 | 1707 | return $guid; |
| 1708 | 1708 | } |
| 1709 | - for($i=0; $i < 3; $i++) { |
|
| 1709 | + for ($i = 0; $i < 3; $i++) { |
|
| 1710 | 1710 | $pairs = str_split($blocks[$i], 2); |
| 1711 | 1711 | $pairs = array_reverse($pairs); |
| 1712 | 1712 | $blocks[$i] = implode('', $pairs); |
| 1713 | 1713 | } |
| 1714 | - for($i=0; $i < 5; $i++) { |
|
| 1714 | + for ($i = 0; $i < 5; $i++) { |
|
| 1715 | 1715 | $pairs = str_split($blocks[$i], 2); |
| 1716 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
| 1716 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
| 1717 | 1717 | } |
| 1718 | 1718 | return implode('', $blocks); |
| 1719 | 1719 | } |
@@ -1727,12 +1727,12 @@ discard block |
||
| 1727 | 1727 | $domainDN = $this->getDomainDNFromDN($dn); |
| 1728 | 1728 | $cacheKey = 'getSID-'.$domainDN; |
| 1729 | 1729 | $sid = $this->connection->getFromCache($cacheKey); |
| 1730 | - if(!is_null($sid)) { |
|
| 1730 | + if (!is_null($sid)) { |
|
| 1731 | 1731 | return $sid; |
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
| 1735 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
| 1735 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
| 1736 | 1736 | $this->connection->writeToCache($cacheKey, false); |
| 1737 | 1737 | return false; |
| 1738 | 1738 | } |
@@ -1790,12 +1790,12 @@ discard block |
||
| 1790 | 1790 | $belongsToBase = false; |
| 1791 | 1791 | $bases = $this->helper->sanitizeDN($bases); |
| 1792 | 1792 | |
| 1793 | - foreach($bases as $base) { |
|
| 1793 | + foreach ($bases as $base) { |
|
| 1794 | 1794 | $belongsToBase = true; |
| 1795 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
| 1795 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
| 1796 | 1796 | $belongsToBase = false; |
| 1797 | 1797 | } |
| 1798 | - if($belongsToBase) { |
|
| 1798 | + if ($belongsToBase) { |
|
| 1799 | 1799 | break; |
| 1800 | 1800 | } |
| 1801 | 1801 | } |
@@ -1806,7 +1806,7 @@ discard block |
||
| 1806 | 1806 | * resets a running Paged Search operation |
| 1807 | 1807 | */ |
| 1808 | 1808 | private function abandonPagedSearch() { |
| 1809 | - if($this->connection->hasPagedResultSupport) { |
|
| 1809 | + if ($this->connection->hasPagedResultSupport) { |
|
| 1810 | 1810 | $cr = $this->connection->getConnectionResource(); |
| 1811 | 1811 | $this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie); |
| 1812 | 1812 | $this->getPagedSearchResultState(); |
@@ -1824,16 +1824,16 @@ discard block |
||
| 1824 | 1824 | * @return string containing the key or empty if none is cached |
| 1825 | 1825 | */ |
| 1826 | 1826 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
| 1827 | - if($offset === 0) { |
|
| 1827 | + if ($offset === 0) { |
|
| 1828 | 1828 | return ''; |
| 1829 | 1829 | } |
| 1830 | 1830 | $offset -= $limit; |
| 1831 | 1831 | //we work with cache here |
| 1832 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); |
|
| 1832 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
| 1833 | 1833 | $cookie = ''; |
| 1834 | - if(isset($this->cookies[$cacheKey])) { |
|
| 1834 | + if (isset($this->cookies[$cacheKey])) { |
|
| 1835 | 1835 | $cookie = $this->cookies[$cacheKey]; |
| 1836 | - if(is_null($cookie)) { |
|
| 1836 | + if (is_null($cookie)) { |
|
| 1837 | 1837 | $cookie = ''; |
| 1838 | 1838 | } |
| 1839 | 1839 | } |
@@ -1851,11 +1851,11 @@ discard block |
||
| 1851 | 1851 | * @return bool |
| 1852 | 1852 | */ |
| 1853 | 1853 | public function hasMoreResults() { |
| 1854 | - if(!$this->connection->hasPagedResultSupport) { |
|
| 1854 | + if (!$this->connection->hasPagedResultSupport) { |
|
| 1855 | 1855 | return false; |
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1858 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1859 | 1859 | // as in RFC 2696, when all results are returned, the cookie will |
| 1860 | 1860 | // be empty. |
| 1861 | 1861 | return false; |
@@ -1875,8 +1875,8 @@ discard block |
||
| 1875 | 1875 | */ |
| 1876 | 1876 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
| 1877 | 1877 | // allow '0' for 389ds |
| 1878 | - if(!empty($cookie) || $cookie === '0') { |
|
| 1879 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); |
|
| 1878 | + if (!empty($cookie) || $cookie === '0') { |
|
| 1879 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
| 1880 | 1880 | $this->cookies[$cacheKey] = $cookie; |
| 1881 | 1881 | $this->lastCookie = $cookie; |
| 1882 | 1882 | } |
@@ -1903,17 +1903,17 @@ discard block |
||
| 1903 | 1903 | */ |
| 1904 | 1904 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
| 1905 | 1905 | $pagedSearchOK = false; |
| 1906 | - if($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1906 | + if ($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1907 | 1907 | $offset = intval($offset); //can be null |
| 1908 | 1908 | \OCP\Util::writeLog('user_ldap', |
| 1909 | 1909 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
| 1910 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
| 1910 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
| 1911 | 1911 | \OCP\Util::DEBUG); |
| 1912 | 1912 | //get the cookie from the search for the previous search, required by LDAP |
| 1913 | - foreach($bases as $base) { |
|
| 1913 | + foreach ($bases as $base) { |
|
| 1914 | 1914 | |
| 1915 | 1915 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
| 1916 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1916 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1917 | 1917 | // no cookie known from a potential previous search. We need |
| 1918 | 1918 | // to start from 0 to come to the desired page. cookie value |
| 1919 | 1919 | // of '0' is valid, because 389ds |
@@ -1923,17 +1923,17 @@ discard block |
||
| 1923 | 1923 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
| 1924 | 1924 | // '0' is valid, because 389ds |
| 1925 | 1925 | //TODO: remember this, probably does not change in the next request... |
| 1926 | - if(empty($cookie) && $cookie !== '0') { |
|
| 1926 | + if (empty($cookie) && $cookie !== '0') { |
|
| 1927 | 1927 | $cookie = null; |
| 1928 | 1928 | } |
| 1929 | 1929 | } |
| 1930 | - if(!is_null($cookie)) { |
|
| 1930 | + if (!is_null($cookie)) { |
|
| 1931 | 1931 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
| 1932 | 1932 | $this->abandonPagedSearch(); |
| 1933 | 1933 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 1934 | 1934 | $this->connection->getConnectionResource(), $limit, |
| 1935 | 1935 | false, $cookie); |
| 1936 | - if(!$pagedSearchOK) { |
|
| 1936 | + if (!$pagedSearchOK) { |
|
| 1937 | 1937 | return false; |
| 1938 | 1938 | } |
| 1939 | 1939 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination |
| 1950 | 1950 | * if we don't have a previous paged search. |
| 1951 | 1951 | */ |
| 1952 | - } else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1952 | + } else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1953 | 1953 | // a search without limit was requested. However, if we do use |
| 1954 | 1954 | // Paged Search once, we always must do it. This requires us to |
| 1955 | 1955 | // initialize it with the configured page size. |