@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return bool |
| 54 | 54 | */ |
| 55 | 55 | public function isColNameValid($col) { |
| 56 | - switch($col) { |
|
| 56 | + switch ($col) { |
|
| 57 | 57 | case 'ldap_dn': |
| 58 | 58 | case 'owncloud_name': |
| 59 | 59 | case 'directory_uuid': |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | * @return string|false |
| 73 | 73 | */ |
| 74 | 74 | protected function getXbyY($fetchCol, $compareCol, $search) { |
| 75 | - if(!$this->isColNameValid($fetchCol)) { |
|
| 75 | + if (!$this->isColNameValid($fetchCol)) { |
|
| 76 | 76 | //this is used internally only, but we don't want to risk |
| 77 | 77 | //having SQL injection at all. |
| 78 | 78 | throw new \Exception('Invalid Column Name'); |
| 79 | 79 | } |
| 80 | 80 | $query = $this->dbc->prepare(' |
| 81 | - SELECT `' . $fetchCol . '` |
|
| 82 | - FROM `'. $this->getTableName() .'` |
|
| 83 | - WHERE `' . $compareCol . '` = ? |
|
| 81 | + SELECT `' . $fetchCol.'` |
|
| 82 | + FROM `'. $this->getTableName().'` |
|
| 83 | + WHERE `' . $compareCol.'` = ? |
|
| 84 | 84 | '); |
| 85 | 85 | |
| 86 | 86 | $res = $query->execute(array($search)); |
| 87 | - if($res !== false) { |
|
| 87 | + if ($res !== false) { |
|
| 88 | 88 | return $query->fetchColumn(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function setDNbyUUID($fdn, $uuid) { |
| 122 | 122 | $query = $this->dbc->prepare(' |
| 123 | - UPDATE `' . $this->getTableName() . '` |
|
| 123 | + UPDATE `' . $this->getTableName().'` |
|
| 124 | 124 | SET `ldap_dn` = ? |
| 125 | 125 | WHERE `directory_uuid` = ? |
| 126 | 126 | '); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function setUUIDbyDN($uuid, $fdn) { |
| 141 | 141 | $query = $this->dbc->prepare(' |
| 142 | - UPDATE `' . $this->getTableName() . '` |
|
| 142 | + UPDATE `' . $this->getTableName().'` |
|
| 143 | 143 | SET `directory_uuid` = ? |
| 144 | 144 | WHERE `ldap_dn` = ? |
| 145 | 145 | '); |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") { |
| 167 | 167 | $query = $this->dbc->prepare(' |
| 168 | 168 | SELECT `owncloud_name` |
| 169 | - FROM `'. $this->getTableName() .'` |
|
| 169 | + FROM `'. $this->getTableName().'` |
|
| 170 | 170 | WHERE `owncloud_name` LIKE ? |
| 171 | 171 | '); |
| 172 | 172 | |
| 173 | 173 | $res = $query->execute(array($prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch)); |
| 174 | 174 | $names = array(); |
| 175 | - if($res !== false) { |
|
| 176 | - while($row = $query->fetch()) { |
|
| 175 | + if ($res !== false) { |
|
| 176 | + while ($row = $query->fetch()) { |
|
| 177 | 177 | $names[] = $row['owncloud_name']; |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | `ldap_dn` AS `dn`, |
| 212 | 212 | `owncloud_name` AS `name`, |
| 213 | 213 | `directory_uuid` AS `uuid` |
| 214 | - FROM `' . $this->getTableName() . '`', |
|
| 214 | + FROM `' . $this->getTableName().'`', |
|
| 215 | 215 | $limit, |
| 216 | 216 | $offset |
| 217 | 217 | ); |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * @return bool |
| 229 | 229 | */ |
| 230 | 230 | public function map($fdn, $name, $uuid) { |
| 231 | - if(mb_strlen($fdn) > 255) { |
|
| 231 | + if (mb_strlen($fdn) > 255) { |
|
| 232 | 232 | \OC::$server->getLogger()->error( |
| 233 | 233 | 'Cannot map, because the DN exceeds 255 characters: {dn}', |
| 234 | 234 | [ |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | try { |
| 249 | 249 | $result = $this->dbc->insertIfNotExist($this->getTableName(), $row); |
| 250 | 250 | // insertIfNotExist returns values as int |
| 251 | - return (bool)$result; |
|
| 251 | + return (bool) $result; |
|
| 252 | 252 | } catch (\Exception $e) { |
| 253 | 253 | return false; |
| 254 | 254 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function unmap($name) { |
| 263 | 263 | $query = $this->dbc->prepare(' |
| 264 | - DELETE FROM `'. $this->getTableName() .'` |
|
| 264 | + DELETE FROM `'. $this->getTableName().'` |
|
| 265 | 265 | WHERE `owncloud_name` = ?'); |
| 266 | 266 | |
| 267 | 267 | return $this->modify($query, array($name)); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | public function clear() { |
| 275 | 275 | $sql = $this->dbc |
| 276 | 276 | ->getDatabasePlatform() |
| 277 | - ->getTruncateTableSQL('`' . $this->getTableName() . '`'); |
|
| 277 | + ->getTruncateTableSQL('`'.$this->getTableName().'`'); |
|
| 278 | 278 | return $this->dbc->prepare($sql)->execute(); |
| 279 | 279 | } |
| 280 | 280 | |
@@ -293,9 +293,9 @@ discard block |
||
| 293 | 293 | ->from($this->getTableName()); |
| 294 | 294 | $cursor = $picker->execute(); |
| 295 | 295 | $result = true; |
| 296 | - while($id = $cursor->fetchColumn(0)) { |
|
| 296 | + while ($id = $cursor->fetchColumn(0)) { |
|
| 297 | 297 | $preCallback($id); |
| 298 | - if($isUnmapped = $this->unmap($id)) { |
|
| 298 | + if ($isUnmapped = $this->unmap($id)) { |
|
| 299 | 299 | $postCallback($id); |
| 300 | 300 | } |
| 301 | 301 | $result &= $isUnmapped; |
@@ -316,6 +316,6 @@ discard block |
||
| 316 | 316 | $res = $query->execute(); |
| 317 | 317 | $count = $res->fetchColumn(); |
| 318 | 318 | $res->closeCursor(); |
| 319 | - return (int)$count; |
|
| 319 | + return (int) $count; |
|
| 320 | 320 | } |
| 321 | 321 | } |
@@ -50,7 +50,6 @@ |
||
| 50 | 50 | use OCA\User_LDAP\User\Manager; |
| 51 | 51 | use OCA\User_LDAP\User\OfflineUser; |
| 52 | 52 | use OCA\User_LDAP\Mapping\AbstractMapping; |
| 53 | - |
|
| 54 | 53 | use OC\ServerNotAvailableException; |
| 55 | 54 | use OCP\IConfig; |
| 56 | 55 | use OCP\IUserManager; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @return AbstractMapping |
| 132 | 132 | */ |
| 133 | 133 | public function getUserMapper() { |
| 134 | - if(is_null($this->userMapper)) { |
|
| 134 | + if (is_null($this->userMapper)) { |
|
| 135 | 135 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
| 136 | 136 | } |
| 137 | 137 | return $this->userMapper; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @return AbstractMapping |
| 152 | 152 | */ |
| 153 | 153 | public function getGroupMapper() { |
| 154 | - if(is_null($this->groupMapper)) { |
|
| 154 | + if (is_null($this->groupMapper)) { |
|
| 155 | 155 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
| 156 | 156 | } |
| 157 | 157 | return $this->groupMapper; |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | * @throws ServerNotAvailableException |
| 185 | 185 | */ |
| 186 | 186 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
| 187 | - if(!$this->checkConnection()) { |
|
| 187 | + if (!$this->checkConnection()) { |
|
| 188 | 188 | \OCP\Util::writeLog('user_ldap', |
| 189 | 189 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
| 190 | 190 | \OCP\Util::WARN); |
| 191 | 191 | return false; |
| 192 | 192 | } |
| 193 | 193 | $cr = $this->connection->getConnectionResource(); |
| 194 | - if(!$this->ldap->isResource($cr)) { |
|
| 194 | + if (!$this->ldap->isResource($cr)) { |
|
| 195 | 195 | //LDAP not available |
| 196 | 196 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 197 | 197 | return false; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $this->abandonPagedSearch(); |
| 202 | 202 | // openLDAP requires that we init a new Paged Search. Not needed by AD, |
| 203 | 203 | // but does not hurt either. |
| 204 | - $pagingSize = (int)$this->connection->ldapPagingSize; |
|
| 204 | + $pagingSize = (int) $this->connection->ldapPagingSize; |
|
| 205 | 205 | // 0 won't result in replies, small numbers may leave out groups |
| 206 | 206 | // (cf. #12306), 500 is default for paging and should work everywhere. |
| 207 | 207 | $maxResults = $pagingSize > 20 ? $pagingSize : 500; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $isRangeRequest = false; |
| 215 | 215 | do { |
| 216 | 216 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
| 217 | - if(is_bool($result)) { |
|
| 217 | + if (is_bool($result)) { |
|
| 218 | 218 | // when an exists request was run and it was successful, an empty |
| 219 | 219 | // array must be returned |
| 220 | 220 | return $result ? [] : false; |
@@ -231,22 +231,22 @@ discard block |
||
| 231 | 231 | $result = $this->extractRangeData($result, $attr); |
| 232 | 232 | if (!empty($result)) { |
| 233 | 233 | $normalizedResult = $this->extractAttributeValuesFromResult( |
| 234 | - [ $attr => $result['values'] ], |
|
| 234 | + [$attr => $result['values']], |
|
| 235 | 235 | $attr |
| 236 | 236 | ); |
| 237 | 237 | $values = array_merge($values, $normalizedResult); |
| 238 | 238 | |
| 239 | - if($result['rangeHigh'] === '*') { |
|
| 239 | + if ($result['rangeHigh'] === '*') { |
|
| 240 | 240 | // when server replies with * as high range value, there are |
| 241 | 241 | // no more results left |
| 242 | 242 | return $values; |
| 243 | 243 | } else { |
| 244 | - $low = $result['rangeHigh'] + 1; |
|
| 245 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
| 244 | + $low = $result['rangeHigh'] + 1; |
|
| 245 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
| 246 | 246 | $isRangeRequest = true; |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | - } while($isRangeRequest); |
|
| 249 | + } while ($isRangeRequest); |
|
| 250 | 250 | |
| 251 | 251 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); |
| 252 | 252 | return false; |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | if (!$this->ldap->isResource($rr)) { |
| 273 | 273 | if ($attribute !== '') { |
| 274 | 274 | //do not throw this message on userExists check, irritates |
| 275 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); |
|
| 275 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); |
|
| 276 | 276 | } |
| 277 | 277 | //in case an error occurs , e.g. object does not exist |
| 278 | 278 | return false; |
| 279 | 279 | } |
| 280 | 280 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
| 281 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); |
|
| 281 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG); |
|
| 282 | 282 | return true; |
| 283 | 283 | } |
| 284 | 284 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
@@ -303,12 +303,12 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function extractAttributeValuesFromResult($result, $attribute) { |
| 305 | 305 | $values = []; |
| 306 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 306 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
| 307 | 307 | $lowercaseAttribute = strtolower($attribute); |
| 308 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
| 309 | - if($this->resemblesDN($attribute)) { |
|
| 308 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
| 309 | + if ($this->resemblesDN($attribute)) { |
|
| 310 | 310 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
| 311 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 311 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
| 312 | 312 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
| 313 | 313 | } else { |
| 314 | 314 | $values[] = $result[$attribute][$i]; |
@@ -330,10 +330,10 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public function extractRangeData($result, $attribute) { |
| 332 | 332 | $keys = array_keys($result); |
| 333 | - foreach($keys as $key) { |
|
| 334 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 333 | + foreach ($keys as $key) { |
|
| 334 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
| 335 | 335 | $queryData = explode(';', $key); |
| 336 | - if(strpos($queryData[1], 'range=') === 0) { |
|
| 336 | + if (strpos($queryData[1], 'range=') === 0) { |
|
| 337 | 337 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
| 338 | 338 | $data = [ |
| 339 | 339 | 'values' => $result[$key], |
@@ -358,18 +358,18 @@ discard block |
||
| 358 | 358 | * @throws \Exception |
| 359 | 359 | */ |
| 360 | 360 | public function setPassword($userDN, $password) { |
| 361 | - if((int)$this->connection->turnOnPasswordChange !== 1) { |
|
| 361 | + if ((int) $this->connection->turnOnPasswordChange !== 1) { |
|
| 362 | 362 | throw new \Exception('LDAP password changes are disabled.'); |
| 363 | 363 | } |
| 364 | 364 | $cr = $this->connection->getConnectionResource(); |
| 365 | - if(!$this->ldap->isResource($cr)) { |
|
| 365 | + if (!$this->ldap->isResource($cr)) { |
|
| 366 | 366 | //LDAP not available |
| 367 | 367 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
| 368 | 368 | return false; |
| 369 | 369 | } |
| 370 | 370 | try { |
| 371 | 371 | return @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); |
| 372 | - } catch(ConstraintViolationException $e) { |
|
| 372 | + } catch (ConstraintViolationException $e) { |
|
| 373 | 373 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -411,17 +411,17 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function getDomainDNFromDN($dn) { |
| 413 | 413 | $allParts = $this->ldap->explodeDN($dn, 0); |
| 414 | - if($allParts === false) { |
|
| 414 | + if ($allParts === false) { |
|
| 415 | 415 | //not a valid DN |
| 416 | 416 | return ''; |
| 417 | 417 | } |
| 418 | 418 | $domainParts = array(); |
| 419 | 419 | $dcFound = false; |
| 420 | - foreach($allParts as $part) { |
|
| 421 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 420 | + foreach ($allParts as $part) { |
|
| 421 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
| 422 | 422 | $dcFound = true; |
| 423 | 423 | } |
| 424 | - if($dcFound) { |
|
| 424 | + if ($dcFound) { |
|
| 425 | 425 | $domainParts[] = $part; |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
| 449 | 449 | //server setups |
| 450 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 450 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 451 | 451 | return $fdn; |
| 452 | 452 | } |
| 453 | 453 | |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | //To avoid bypassing the base DN settings under certain circumstances |
| 465 | 465 | //with the group support, check whether the provided DN matches one of |
| 466 | 466 | //the given Bases |
| 467 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 467 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
| 468 | 468 | return false; |
| 469 | 469 | } |
| 470 | 470 | |
@@ -482,11 +482,11 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | public function groupsMatchFilter($groupDNs) { |
| 484 | 484 | $validGroupDNs = []; |
| 485 | - foreach($groupDNs as $dn) { |
|
| 485 | + foreach ($groupDNs as $dn) { |
|
| 486 | 486 | $cacheKey = 'groupsMatchFilter-'.$dn; |
| 487 | 487 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
| 488 | - if(!is_null($groupMatchFilter)) { |
|
| 489 | - if($groupMatchFilter) { |
|
| 488 | + if (!is_null($groupMatchFilter)) { |
|
| 489 | + if ($groupMatchFilter) { |
|
| 490 | 490 | $validGroupDNs[] = $dn; |
| 491 | 491 | } |
| 492 | 492 | continue; |
@@ -494,13 +494,13 @@ discard block |
||
| 494 | 494 | |
| 495 | 495 | // Check the base DN first. If this is not met already, we don't |
| 496 | 496 | // need to ask the server at all. |
| 497 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 497 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
| 498 | 498 | $this->connection->writeToCache($cacheKey, false); |
| 499 | 499 | continue; |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | $result = $this->readAttribute($dn, '', $this->connection->ldapGroupFilter); |
| 503 | - if(is_array($result)) { |
|
| 503 | + if (is_array($result)) { |
|
| 504 | 504 | $this->connection->writeToCache($cacheKey, true); |
| 505 | 505 | $validGroupDNs[] = $dn; |
| 506 | 506 | } else { |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | //To avoid bypassing the base DN settings under certain circumstances |
| 522 | 522 | //with the group support, check whether the provided DN matches one of |
| 523 | 523 | //the given Bases |
| 524 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 524 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
| 525 | 525 | return false; |
| 526 | 526 | } |
| 527 | 527 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | */ |
| 542 | 542 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
| 543 | 543 | $newlyMapped = false; |
| 544 | - if($isUser) { |
|
| 544 | + if ($isUser) { |
|
| 545 | 545 | $mapper = $this->getUserMapper(); |
| 546 | 546 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 547 | 547 | $filter = $this->connection->ldapUserFilter; |
@@ -553,15 +553,15 @@ discard block |
||
| 553 | 553 | |
| 554 | 554 | //let's try to retrieve the Nextcloud name from the mappings table |
| 555 | 555 | $ncName = $mapper->getNameByDN($fdn); |
| 556 | - if(is_string($ncName)) { |
|
| 556 | + if (is_string($ncName)) { |
|
| 557 | 557 | return $ncName; |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
| 561 | 561 | $uuid = $this->getUUID($fdn, $isUser, $record); |
| 562 | - if(is_string($uuid)) { |
|
| 562 | + if (is_string($uuid)) { |
|
| 563 | 563 | $ncName = $mapper->getNameByUUID($uuid); |
| 564 | - if(is_string($ncName)) { |
|
| 564 | + if (is_string($ncName)) { |
|
| 565 | 565 | $mapper->setDNbyUUID($fdn, $uuid); |
| 566 | 566 | return $ncName; |
| 567 | 567 | } |
@@ -571,17 +571,17 @@ discard block |
||
| 571 | 571 | return false; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - if(is_null($ldapName)) { |
|
| 574 | + if (is_null($ldapName)) { |
|
| 575 | 575 | $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); |
| 576 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 576 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
| 577 | 577 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', \OCP\Util::INFO); |
| 578 | 578 | return false; |
| 579 | 579 | } |
| 580 | 580 | $ldapName = $ldapName[0]; |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if($isUser) { |
|
| 584 | - $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr; |
|
| 583 | + if ($isUser) { |
|
| 584 | + $usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr; |
|
| 585 | 585 | if ($usernameAttribute !== '') { |
| 586 | 586 | $username = $this->readAttribute($fdn, $usernameAttribute); |
| 587 | 587 | $username = $username[0]; |
@@ -611,11 +611,11 @@ discard block |
||
| 611 | 611 | // outside of core user management will still cache the user as non-existing. |
| 612 | 612 | $originalTTL = $this->connection->ldapCacheTTL; |
| 613 | 613 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 614 | - if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName)) |
|
| 614 | + if (($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName)) |
|
| 615 | 615 | || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { |
| 616 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
| 616 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
| 617 | 617 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 618 | - if($this->ncUserManager instanceof PublicEmitter) { |
|
| 618 | + if ($this->ncUserManager instanceof PublicEmitter) { |
|
| 619 | 619 | $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]); |
| 620 | 620 | } |
| 621 | 621 | $newlyMapped = true; |
@@ -625,8 +625,8 @@ discard block |
||
| 625 | 625 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
| 626 | 626 | |
| 627 | 627 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
| 628 | - if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 629 | - if($this->ncUserManager instanceof PublicEmitter) { |
|
| 628 | + if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
| 629 | + if ($this->ncUserManager instanceof PublicEmitter) { |
|
| 630 | 630 | $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]); |
| 631 | 631 | } |
| 632 | 632 | $newlyMapped = true; |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | * @return array |
| 667 | 667 | */ |
| 668 | 668 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
| 669 | - if($isUsers) { |
|
| 669 | + if ($isUsers) { |
|
| 670 | 670 | $nameAttribute = $this->connection->ldapUserDisplayName; |
| 671 | 671 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
| 672 | 672 | } else { |
@@ -674,9 +674,9 @@ discard block |
||
| 674 | 674 | } |
| 675 | 675 | $nextcloudNames = array(); |
| 676 | 676 | |
| 677 | - foreach($ldapObjects as $ldapObject) { |
|
| 677 | + foreach ($ldapObjects as $ldapObject) { |
|
| 678 | 678 | $nameByLDAP = null; |
| 679 | - if( isset($ldapObject[$nameAttribute]) |
|
| 679 | + if (isset($ldapObject[$nameAttribute]) |
|
| 680 | 680 | && is_array($ldapObject[$nameAttribute]) |
| 681 | 681 | && isset($ldapObject[$nameAttribute][0]) |
| 682 | 682 | ) { |
@@ -685,12 +685,12 @@ discard block |
||
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
| 688 | - if($ncName) { |
|
| 688 | + if ($ncName) { |
|
| 689 | 689 | $nextcloudNames[] = $ncName; |
| 690 | - if($isUsers) { |
|
| 690 | + if ($isUsers) { |
|
| 691 | 691 | //cache the user names so it does not need to be retrieved |
| 692 | 692 | //again later (e.g. sharing dialogue). |
| 693 | - if(is_null($nameByLDAP)) { |
|
| 693 | + if (is_null($nameByLDAP)) { |
|
| 694 | 694 | continue; |
| 695 | 695 | } |
| 696 | 696 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | */ |
| 729 | 729 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
| 730 | 730 | $user = $this->userManager->get($ocName); |
| 731 | - if($user === null) { |
|
| 731 | + if ($user === null) { |
|
| 732 | 732 | return; |
| 733 | 733 | } |
| 734 | 734 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -748,9 +748,9 @@ discard block |
||
| 748 | 748 | $attempts = 0; |
| 749 | 749 | //while loop is just a precaution. If a name is not generated within |
| 750 | 750 | //20 attempts, something else is very wrong. Avoids infinite loop. |
| 751 | - while($attempts < 20){ |
|
| 752 | - $altName = $name . '_' . rand(1000,9999); |
|
| 753 | - if(!$this->ncUserManager->userExists($altName)) { |
|
| 751 | + while ($attempts < 20) { |
|
| 752 | + $altName = $name.'_'.rand(1000, 9999); |
|
| 753 | + if (!$this->ncUserManager->userExists($altName)) { |
|
| 754 | 754 | return $altName; |
| 755 | 755 | } |
| 756 | 756 | $attempts++; |
@@ -772,25 +772,25 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | private function _createAltInternalOwnCloudNameForGroups($name) { |
| 774 | 774 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
| 775 | - if(!$usedNames || count($usedNames) === 0) { |
|
| 775 | + if (!$usedNames || count($usedNames) === 0) { |
|
| 776 | 776 | $lastNo = 1; //will become name_2 |
| 777 | 777 | } else { |
| 778 | 778 | natsort($usedNames); |
| 779 | 779 | $lastName = array_pop($usedNames); |
| 780 | - $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1); |
|
| 780 | + $lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1); |
|
| 781 | 781 | } |
| 782 | - $altName = $name.'_'. (string)($lastNo+1); |
|
| 782 | + $altName = $name.'_'.(string) ($lastNo + 1); |
|
| 783 | 783 | unset($usedNames); |
| 784 | 784 | |
| 785 | 785 | $attempts = 1; |
| 786 | - while($attempts < 21){ |
|
| 786 | + while ($attempts < 21) { |
|
| 787 | 787 | // Check to be really sure it is unique |
| 788 | 788 | // while loop is just a precaution. If a name is not generated within |
| 789 | 789 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
| 790 | - if(!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 790 | + if (!\OC::$server->getGroupManager()->groupExists($altName)) { |
|
| 791 | 791 | return $altName; |
| 792 | 792 | } |
| 793 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
| 793 | + $altName = $name.'_'.($lastNo + $attempts); |
|
| 794 | 794 | $attempts++; |
| 795 | 795 | } |
| 796 | 796 | return false; |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | private function createAltInternalOwnCloudName($name, $isUser) { |
| 806 | 806 | $originalTTL = $this->connection->ldapCacheTTL; |
| 807 | 807 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
| 808 | - if($isUser) { |
|
| 808 | + if ($isUser) { |
|
| 809 | 809 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
| 810 | 810 | } else { |
| 811 | 811 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -853,13 +853,13 @@ discard block |
||
| 853 | 853 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
| 854 | 854 | $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset); |
| 855 | 855 | $recordsToUpdate = $ldapRecords; |
| 856 | - if(!$forceApplyAttributes) { |
|
| 856 | + if (!$forceApplyAttributes) { |
|
| 857 | 857 | $isBackgroundJobModeAjax = $this->config |
| 858 | 858 | ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
| 859 | 859 | $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { |
| 860 | 860 | $newlyMapped = false; |
| 861 | 861 | $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); |
| 862 | - if(is_string($uid)) { |
|
| 862 | + if (is_string($uid)) { |
|
| 863 | 863 | $this->cacheUserExists($uid); |
| 864 | 864 | } |
| 865 | 865 | return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); |
@@ -875,19 +875,19 @@ discard block |
||
| 875 | 875 | * and their values |
| 876 | 876 | * @param array $ldapRecords |
| 877 | 877 | */ |
| 878 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
| 878 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
| 879 | 879 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
| 880 | - foreach($ldapRecords as $userRecord) { |
|
| 881 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
| 880 | + foreach ($ldapRecords as $userRecord) { |
|
| 881 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
| 882 | 882 | // displayName is obligatory |
| 883 | 883 | continue; |
| 884 | 884 | } |
| 885 | - $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 886 | - if($ocName === false) { |
|
| 885 | + $ocName = $this->dn2ocname($userRecord['dn'][0], null, true); |
|
| 886 | + if ($ocName === false) { |
|
| 887 | 887 | continue; |
| 888 | 888 | } |
| 889 | 889 | $user = $this->userManager->get($ocName); |
| 890 | - if($user instanceof OfflineUser) { |
|
| 890 | + if ($user instanceof OfflineUser) { |
|
| 891 | 891 | $user->unmark(); |
| 892 | 892 | $user = $this->userManager->get($ocName); |
| 893 | 893 | } |
@@ -919,8 +919,8 @@ discard block |
||
| 919 | 919 | * @return array |
| 920 | 920 | */ |
| 921 | 921 | private function fetchList($list, $manyAttributes) { |
| 922 | - if(is_array($list)) { |
|
| 923 | - if($manyAttributes) { |
|
| 922 | + if (is_array($list)) { |
|
| 923 | + if ($manyAttributes) { |
|
| 924 | 924 | return $list; |
| 925 | 925 | } else { |
| 926 | 926 | $list = array_reduce($list, function($carry, $item) { |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | // php no longer supports call-time pass-by-reference |
| 1019 | 1019 | // thus cannot support controlPagedResultResponse as the third argument |
| 1020 | 1020 | // is a reference |
| 1021 | - $doMethod = function () use ($command, &$arguments) { |
|
| 1021 | + $doMethod = function() use ($command, &$arguments) { |
|
| 1022 | 1022 | if ($command == 'controlPagedResultResponse') { |
| 1023 | 1023 | throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); |
| 1024 | 1024 | } else { |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | $this->connection->resetConnectionResource(); |
| 1037 | 1037 | $cr = $this->connection->getConnectionResource(); |
| 1038 | 1038 | |
| 1039 | - if(!$this->ldap->isResource($cr)) { |
|
| 1039 | + if (!$this->ldap->isResource($cr)) { |
|
| 1040 | 1040 | // Seems like we didn't find any resource. |
| 1041 | 1041 | \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG); |
| 1042 | 1042 | throw $e; |
@@ -1061,13 +1061,13 @@ discard block |
||
| 1061 | 1061 | * @throws ServerNotAvailableException |
| 1062 | 1062 | */ |
| 1063 | 1063 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
| 1064 | - if(!is_null($attr) && !is_array($attr)) { |
|
| 1064 | + if (!is_null($attr) && !is_array($attr)) { |
|
| 1065 | 1065 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | // See if we have a resource, in case not cancel with message |
| 1069 | 1069 | $cr = $this->connection->getConnectionResource(); |
| 1070 | - if(!$this->ldap->isResource($cr)) { |
|
| 1070 | + if (!$this->ldap->isResource($cr)) { |
|
| 1071 | 1071 | // Seems like we didn't find any resource. |
| 1072 | 1072 | // Return an empty array just like before. |
| 1073 | 1073 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); |
@@ -1075,13 +1075,13 @@ discard block |
||
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | //check whether paged search should be attempted |
| 1078 | - $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset); |
|
| 1078 | + $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, $offset); |
|
| 1079 | 1079 | |
| 1080 | 1080 | $linkResources = array_pad(array(), count($base), $cr); |
| 1081 | 1081 | $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); |
| 1082 | 1082 | // cannot use $cr anymore, might have changed in the previous call! |
| 1083 | 1083 | $error = $this->ldap->errno($this->connection->getConnectionResource()); |
| 1084 | - if(!is_array($sr) || $error !== 0) { |
|
| 1084 | + if (!is_array($sr) || $error !== 0) { |
|
| 1085 | 1085 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); |
| 1086 | 1086 | return false; |
| 1087 | 1087 | } |
@@ -1104,29 +1104,29 @@ discard block |
||
| 1104 | 1104 | */ |
| 1105 | 1105 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
| 1106 | 1106 | $cookie = null; |
| 1107 | - if($pagedSearchOK) { |
|
| 1107 | + if ($pagedSearchOK) { |
|
| 1108 | 1108 | $cr = $this->connection->getConnectionResource(); |
| 1109 | - foreach($sr as $key => $res) { |
|
| 1110 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1109 | + foreach ($sr as $key => $res) { |
|
| 1110 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
| 1111 | 1111 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
| 1112 | 1112 | } |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | //browsing through prior pages to get the cookie for the new one |
| 1116 | - if($skipHandling) { |
|
| 1116 | + if ($skipHandling) { |
|
| 1117 | 1117 | return false; |
| 1118 | 1118 | } |
| 1119 | 1119 | // if count is bigger, then the server does not support |
| 1120 | 1120 | // paged search. Instead, he did a normal search. We set a |
| 1121 | 1121 | // flag here, so the callee knows how to deal with it. |
| 1122 | - if($iFoundItems <= $limit) { |
|
| 1122 | + if ($iFoundItems <= $limit) { |
|
| 1123 | 1123 | $this->pagedSearchedSuccessful = true; |
| 1124 | 1124 | } |
| 1125 | 1125 | } else { |
| 1126 | - if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) { |
|
| 1126 | + if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) { |
|
| 1127 | 1127 | \OC::$server->getLogger()->debug( |
| 1128 | 1128 | 'Paged search was not available', |
| 1129 | - [ 'app' => 'user_ldap' ] |
|
| 1129 | + ['app' => 'user_ldap'] |
|
| 1130 | 1130 | ); |
| 1131 | 1131 | } |
| 1132 | 1132 | } |
@@ -1155,8 +1155,8 @@ discard block |
||
| 1155 | 1155 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1156 | 1156 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); |
| 1157 | 1157 | |
| 1158 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
| 1159 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1158 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
| 1159 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1160 | 1160 | $limitPerPage = $limit; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | |
| 1167 | 1167 | do { |
| 1168 | 1168 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1169 | - if($search === false) { |
|
| 1169 | + if ($search === false) { |
|
| 1170 | 1170 | return $counter > 0 ? $counter : false; |
| 1171 | 1171 | } |
| 1172 | 1172 | list($sr, $pagedSearchOK) = $search; |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | * Continue now depends on $hasMorePages value |
| 1186 | 1186 | */ |
| 1187 | 1187 | $continue = $pagedSearchOK && $hasMorePages; |
| 1188 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1188 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
| 1189 | 1189 | |
| 1190 | 1190 | return $counter; |
| 1191 | 1191 | } |
@@ -1197,8 +1197,8 @@ discard block |
||
| 1197 | 1197 | private function countEntriesInSearchResults($searchResults) { |
| 1198 | 1198 | $counter = 0; |
| 1199 | 1199 | |
| 1200 | - foreach($searchResults as $res) { |
|
| 1201 | - $count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
| 1200 | + foreach ($searchResults as $res) { |
|
| 1201 | + $count = (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res); |
|
| 1202 | 1202 | $counter += $count; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1218,8 +1218,8 @@ discard block |
||
| 1218 | 1218 | * @throws ServerNotAvailableException |
| 1219 | 1219 | */ |
| 1220 | 1220 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
| 1221 | - $limitPerPage = (int)$this->connection->ldapPagingSize; |
|
| 1222 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1221 | + $limitPerPage = (int) $this->connection->ldapPagingSize; |
|
| 1222 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
| 1223 | 1223 | $limitPerPage = $limit; |
| 1224 | 1224 | } |
| 1225 | 1225 | |
@@ -1233,13 +1233,13 @@ discard block |
||
| 1233 | 1233 | $savedoffset = $offset; |
| 1234 | 1234 | do { |
| 1235 | 1235 | $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); |
| 1236 | - if($search === false) { |
|
| 1236 | + if ($search === false) { |
|
| 1237 | 1237 | return []; |
| 1238 | 1238 | } |
| 1239 | 1239 | list($sr, $pagedSearchOK) = $search; |
| 1240 | 1240 | $cr = $this->connection->getConnectionResource(); |
| 1241 | 1241 | |
| 1242 | - if($skipHandling) { |
|
| 1242 | + if ($skipHandling) { |
|
| 1243 | 1243 | //i.e. result do not need to be fetched, we just need the cookie |
| 1244 | 1244 | //thus pass 1 or any other value as $iFoundItems because it is not |
| 1245 | 1245 | //used |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | $iFoundItems = 0; |
| 1253 | - foreach($sr as $res) { |
|
| 1253 | + foreach ($sr as $res) { |
|
| 1254 | 1254 | $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $res)); |
| 1255 | 1255 | $iFoundItems = max($iFoundItems, $findings['count']); |
| 1256 | 1256 | unset($findings['count']); |
@@ -1266,27 +1266,27 @@ discard block |
||
| 1266 | 1266 | |
| 1267 | 1267 | // if we're here, probably no connection resource is returned. |
| 1268 | 1268 | // to make Nextcloud behave nicely, we simply give back an empty array. |
| 1269 | - if(is_null($findings)) { |
|
| 1269 | + if (is_null($findings)) { |
|
| 1270 | 1270 | return array(); |
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | - if(!is_null($attr)) { |
|
| 1273 | + if (!is_null($attr)) { |
|
| 1274 | 1274 | $selection = []; |
| 1275 | 1275 | $i = 0; |
| 1276 | - foreach($findings as $item) { |
|
| 1277 | - if(!is_array($item)) { |
|
| 1276 | + foreach ($findings as $item) { |
|
| 1277 | + if (!is_array($item)) { |
|
| 1278 | 1278 | continue; |
| 1279 | 1279 | } |
| 1280 | 1280 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
| 1281 | - foreach($attr as $key) { |
|
| 1282 | - if(isset($item[$key])) { |
|
| 1283 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1281 | + foreach ($attr as $key) { |
|
| 1282 | + if (isset($item[$key])) { |
|
| 1283 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
| 1284 | 1284 | unset($item[$key]['count']); |
| 1285 | 1285 | } |
| 1286 | - if($key !== 'dn') { |
|
| 1287 | - if($this->resemblesDN($key)) { |
|
| 1286 | + if ($key !== 'dn') { |
|
| 1287 | + if ($this->resemblesDN($key)) { |
|
| 1288 | 1288 | $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]); |
| 1289 | - } else if($key === 'objectguid' || $key === 'guid') { |
|
| 1289 | + } else if ($key === 'objectguid' || $key === 'guid') { |
|
| 1290 | 1290 | $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])]; |
| 1291 | 1291 | } else { |
| 1292 | 1292 | $selection[$i][$key] = $item[$key]; |
@@ -1304,14 +1304,14 @@ discard block |
||
| 1304 | 1304 | //we slice the findings, when |
| 1305 | 1305 | //a) paged search unsuccessful, though attempted |
| 1306 | 1306 | //b) no paged search, but limit set |
| 1307 | - if((!$this->getPagedSearchResultState() |
|
| 1307 | + if ((!$this->getPagedSearchResultState() |
|
| 1308 | 1308 | && $pagedSearchOK) |
| 1309 | 1309 | || ( |
| 1310 | 1310 | !$pagedSearchOK |
| 1311 | 1311 | && !is_null($limit) |
| 1312 | 1312 | ) |
| 1313 | 1313 | ) { |
| 1314 | - $findings = array_slice($findings, (int)$offset, $limit); |
|
| 1314 | + $findings = array_slice($findings, (int) $offset, $limit); |
|
| 1315 | 1315 | } |
| 1316 | 1316 | return $findings; |
| 1317 | 1317 | } |
@@ -1324,13 +1324,13 @@ discard block |
||
| 1324 | 1324 | public function sanitizeUsername($name) { |
| 1325 | 1325 | $name = trim($name); |
| 1326 | 1326 | |
| 1327 | - if($this->connection->ldapIgnoreNamingRules) { |
|
| 1327 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
| 1328 | 1328 | return $name; |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | // Transliteration to ASCII |
| 1332 | 1332 | $transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name); |
| 1333 | - if($transliterated !== false) { |
|
| 1333 | + if ($transliterated !== false) { |
|
| 1334 | 1334 | // depending on system config iconv can work or not |
| 1335 | 1335 | $name = $transliterated; |
| 1336 | 1336 | } |
@@ -1341,7 +1341,7 @@ discard block |
||
| 1341 | 1341 | // Every remaining disallowed characters will be removed |
| 1342 | 1342 | $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name); |
| 1343 | 1343 | |
| 1344 | - if($name === '') { |
|
| 1344 | + if ($name === '') { |
|
| 1345 | 1345 | throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters'); |
| 1346 | 1346 | } |
| 1347 | 1347 | |
@@ -1356,13 +1356,13 @@ discard block |
||
| 1356 | 1356 | */ |
| 1357 | 1357 | public function escapeFilterPart($input, $allowAsterisk = false) { |
| 1358 | 1358 | $asterisk = ''; |
| 1359 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1359 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
| 1360 | 1360 | $asterisk = '*'; |
| 1361 | 1361 | $input = mb_substr($input, 1, null, 'UTF-8'); |
| 1362 | 1362 | } |
| 1363 | 1363 | $search = array('*', '\\', '(', ')'); |
| 1364 | 1364 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
| 1365 | - return $asterisk . str_replace($search, $replace, $input); |
|
| 1365 | + return $asterisk.str_replace($search, $replace, $input); |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | /** |
@@ -1392,13 +1392,13 @@ discard block |
||
| 1392 | 1392 | */ |
| 1393 | 1393 | private function combineFilter($filters, $operator) { |
| 1394 | 1394 | $combinedFilter = '('.$operator; |
| 1395 | - foreach($filters as $filter) { |
|
| 1395 | + foreach ($filters as $filter) { |
|
| 1396 | 1396 | if ($filter !== '' && $filter[0] !== '(') { |
| 1397 | 1397 | $filter = '('.$filter.')'; |
| 1398 | 1398 | } |
| 1399 | - $combinedFilter.=$filter; |
|
| 1399 | + $combinedFilter .= $filter; |
|
| 1400 | 1400 | } |
| 1401 | - $combinedFilter.=')'; |
|
| 1401 | + $combinedFilter .= ')'; |
|
| 1402 | 1402 | return $combinedFilter; |
| 1403 | 1403 | } |
| 1404 | 1404 | |
@@ -1434,17 +1434,17 @@ discard block |
||
| 1434 | 1434 | * @throws \Exception |
| 1435 | 1435 | */ |
| 1436 | 1436 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
| 1437 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1437 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
| 1438 | 1438 | throw new \Exception('searchAttributes must be an array with at least two string'); |
| 1439 | 1439 | } |
| 1440 | 1440 | $searchWords = explode(' ', trim($search)); |
| 1441 | 1441 | $wordFilters = array(); |
| 1442 | - foreach($searchWords as $word) { |
|
| 1442 | + foreach ($searchWords as $word) { |
|
| 1443 | 1443 | $word = $this->prepareSearchTerm($word); |
| 1444 | 1444 | //every word needs to appear at least once |
| 1445 | 1445 | $wordMatchOneAttrFilters = array(); |
| 1446 | - foreach($searchAttributes as $attr) { |
|
| 1447 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
| 1446 | + foreach ($searchAttributes as $attr) { |
|
| 1447 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
| 1448 | 1448 | } |
| 1449 | 1449 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
| 1450 | 1450 | } |
@@ -1462,10 +1462,10 @@ discard block |
||
| 1462 | 1462 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
| 1463 | 1463 | $filter = array(); |
| 1464 | 1464 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
| 1465 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1465 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
| 1466 | 1466 | try { |
| 1467 | 1467 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
| 1468 | - } catch(\Exception $e) { |
|
| 1468 | + } catch (\Exception $e) { |
|
| 1469 | 1469 | \OCP\Util::writeLog( |
| 1470 | 1470 | 'user_ldap', |
| 1471 | 1471 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1475,17 +1475,17 @@ discard block |
||
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | $search = $this->prepareSearchTerm($search); |
| 1478 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1478 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
| 1479 | 1479 | if ($fallbackAttribute === '') { |
| 1480 | 1480 | return ''; |
| 1481 | 1481 | } |
| 1482 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
| 1482 | + $filter[] = $fallbackAttribute.'='.$search; |
|
| 1483 | 1483 | } else { |
| 1484 | - foreach($searchAttributes as $attribute) { |
|
| 1485 | - $filter[] = $attribute . '=' . $search; |
|
| 1484 | + foreach ($searchAttributes as $attribute) { |
|
| 1485 | + $filter[] = $attribute.'='.$search; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | } |
| 1488 | - if(count($filter) === 1) { |
|
| 1488 | + if (count($filter) === 1) { |
|
| 1489 | 1489 | return '('.$filter[0].')'; |
| 1490 | 1490 | } |
| 1491 | 1491 | return $this->combineFilterWithOr($filter); |
@@ -1506,7 +1506,7 @@ discard block |
||
| 1506 | 1506 | if ($term === '') { |
| 1507 | 1507 | $result = '*'; |
| 1508 | 1508 | } else if ($allowEnum !== 'no') { |
| 1509 | - $result = $term . '*'; |
|
| 1509 | + $result = $term.'*'; |
|
| 1510 | 1510 | } |
| 1511 | 1511 | return $result; |
| 1512 | 1512 | } |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | public function getFilterForUserCount() { |
| 1519 | 1519 | $filter = $this->combineFilterWithAnd(array( |
| 1520 | 1520 | $this->connection->ldapUserFilter, |
| 1521 | - $this->connection->ldapUserDisplayName . '=*' |
|
| 1521 | + $this->connection->ldapUserDisplayName.'=*' |
|
| 1522 | 1522 | )); |
| 1523 | 1523 | |
| 1524 | 1524 | return $filter; |
@@ -1536,7 +1536,7 @@ discard block |
||
| 1536 | 1536 | 'ldapAgentName' => $name, |
| 1537 | 1537 | 'ldapAgentPassword' => $password |
| 1538 | 1538 | ); |
| 1539 | - if(!$testConnection->setConfiguration($credentials)) { |
|
| 1539 | + if (!$testConnection->setConfiguration($credentials)) { |
|
| 1540 | 1540 | return false; |
| 1541 | 1541 | } |
| 1542 | 1542 | return $testConnection->bind(); |
@@ -1558,30 +1558,30 @@ discard block |
||
| 1558 | 1558 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
| 1559 | 1559 | // existing DN to be able to reliably detect it. |
| 1560 | 1560 | $result = $this->search($filter, $base, ['dn'], 1); |
| 1561 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1561 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
| 1562 | 1562 | throw new \Exception('Cannot determine UUID attribute'); |
| 1563 | 1563 | } |
| 1564 | 1564 | $dn = $result[0]['dn'][0]; |
| 1565 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
| 1565 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
| 1566 | 1566 | throw new \Exception('Cannot determine UUID attribute'); |
| 1567 | 1567 | } |
| 1568 | 1568 | } else { |
| 1569 | 1569 | // The UUID attribute is either known or an override is given. |
| 1570 | 1570 | // By calling this method we ensure that $this->connection->$uuidAttr |
| 1571 | 1571 | // is definitely set |
| 1572 | - if(!$this->detectUuidAttribute('', true)) { |
|
| 1572 | + if (!$this->detectUuidAttribute('', true)) { |
|
| 1573 | 1573 | throw new \Exception('Cannot determine UUID attribute'); |
| 1574 | 1574 | } |
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
| 1578 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1578 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
| 1579 | 1579 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - $filter = $uuidAttr . '=' . $uuid; |
|
| 1582 | + $filter = $uuidAttr.'='.$uuid; |
|
| 1583 | 1583 | $result = $this->searchUsers($filter, ['dn'], 2); |
| 1584 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1584 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
| 1585 | 1585 | // we put the count into account to make sure that this is |
| 1586 | 1586 | // really unique |
| 1587 | 1587 | return $result[0]['dn'][0]; |
@@ -1600,7 +1600,7 @@ discard block |
||
| 1600 | 1600 | * @return bool true on success, false otherwise |
| 1601 | 1601 | */ |
| 1602 | 1602 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
| 1603 | - if($isUser) { |
|
| 1603 | + if ($isUser) { |
|
| 1604 | 1604 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1605 | 1605 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1606 | 1606 | } else { |
@@ -1608,7 +1608,7 @@ discard block |
||
| 1608 | 1608 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1611 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
| 1612 | 1612 | return true; |
| 1613 | 1613 | } |
| 1614 | 1614 | |
@@ -1617,10 +1617,10 @@ discard block |
||
| 1617 | 1617 | return true; |
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | - foreach(self::UUID_ATTRIBUTES as $attribute) { |
|
| 1621 | - if($ldapRecord !== null) { |
|
| 1620 | + foreach (self::UUID_ATTRIBUTES as $attribute) { |
|
| 1621 | + if ($ldapRecord !== null) { |
|
| 1622 | 1622 | // we have the info from LDAP already, we don't need to talk to the server again |
| 1623 | - if(isset($ldapRecord[$attribute])) { |
|
| 1623 | + if (isset($ldapRecord[$attribute])) { |
|
| 1624 | 1624 | $this->connection->$uuidAttr = $attribute; |
| 1625 | 1625 | return true; |
| 1626 | 1626 | } else { |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | } |
| 1630 | 1630 | |
| 1631 | 1631 | $value = $this->readAttribute($dn, $attribute); |
| 1632 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1632 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
| 1633 | 1633 | \OCP\Util::writeLog('user_ldap', |
| 1634 | 1634 | 'Setting '.$attribute.' as '.$uuidAttr, |
| 1635 | 1635 | \OCP\Util::DEBUG); |
@@ -1651,7 +1651,7 @@ discard block |
||
| 1651 | 1651 | * @return bool|string |
| 1652 | 1652 | */ |
| 1653 | 1653 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
| 1654 | - if($isUser) { |
|
| 1654 | + if ($isUser) { |
|
| 1655 | 1655 | $uuidAttr = 'ldapUuidUserAttribute'; |
| 1656 | 1656 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
| 1657 | 1657 | } else { |
@@ -1660,10 +1660,10 @@ discard block |
||
| 1660 | 1660 | } |
| 1661 | 1661 | |
| 1662 | 1662 | $uuid = false; |
| 1663 | - if($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1663 | + if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) { |
|
| 1664 | 1664 | $attr = $this->connection->$uuidAttr; |
| 1665 | 1665 | $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr); |
| 1666 | - if( !is_array($uuid) |
|
| 1666 | + if (!is_array($uuid) |
|
| 1667 | 1667 | && $uuidOverride !== '' |
| 1668 | 1668 | && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) |
| 1669 | 1669 | { |
@@ -1671,7 +1671,7 @@ discard block |
||
| 1671 | 1671 | ? $ldapRecord[$this->connection->$uuidAttr] |
| 1672 | 1672 | : $this->readAttribute($dn, $this->connection->$uuidAttr); |
| 1673 | 1673 | } |
| 1674 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1674 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
| 1675 | 1675 | $uuid = $uuid[0]; |
| 1676 | 1676 | } |
| 1677 | 1677 | } |
@@ -1688,19 +1688,19 @@ discard block |
||
| 1688 | 1688 | private function convertObjectGUID2Str($oguid) { |
| 1689 | 1689 | $hex_guid = bin2hex($oguid); |
| 1690 | 1690 | $hex_guid_to_guid_str = ''; |
| 1691 | - for($k = 1; $k <= 4; ++$k) { |
|
| 1691 | + for ($k = 1; $k <= 4; ++$k) { |
|
| 1692 | 1692 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
| 1693 | 1693 | } |
| 1694 | 1694 | $hex_guid_to_guid_str .= '-'; |
| 1695 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1695 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1696 | 1696 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
| 1697 | 1697 | } |
| 1698 | 1698 | $hex_guid_to_guid_str .= '-'; |
| 1699 | - for($k = 1; $k <= 2; ++$k) { |
|
| 1699 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 1700 | 1700 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
| 1701 | 1701 | } |
| 1702 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
| 1703 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
| 1702 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
| 1703 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
| 1704 | 1704 | |
| 1705 | 1705 | return strtoupper($hex_guid_to_guid_str); |
| 1706 | 1706 | } |
@@ -1717,11 +1717,11 @@ discard block |
||
| 1717 | 1717 | * @return string |
| 1718 | 1718 | */ |
| 1719 | 1719 | public function formatGuid2ForFilterUser($guid) { |
| 1720 | - if(!is_string($guid)) { |
|
| 1720 | + if (!is_string($guid)) { |
|
| 1721 | 1721 | throw new \InvalidArgumentException('String expected'); |
| 1722 | 1722 | } |
| 1723 | 1723 | $blocks = explode('-', $guid); |
| 1724 | - if(count($blocks) !== 5) { |
|
| 1724 | + if (count($blocks) !== 5) { |
|
| 1725 | 1725 | /* |
| 1726 | 1726 | * Why not throw an Exception instead? This method is a utility |
| 1727 | 1727 | * called only when trying to figure out whether a "missing" known |
@@ -1734,20 +1734,20 @@ discard block |
||
| 1734 | 1734 | * user. Instead we write a log message. |
| 1735 | 1735 | */ |
| 1736 | 1736 | \OC::$server->getLogger()->info( |
| 1737 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
| 1737 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
| 1738 | 1738 | '({uuid}) probably does not match UUID configuration.', |
| 1739 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
| 1739 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
| 1740 | 1740 | ); |
| 1741 | 1741 | return $guid; |
| 1742 | 1742 | } |
| 1743 | - for($i=0; $i < 3; $i++) { |
|
| 1743 | + for ($i = 0; $i < 3; $i++) { |
|
| 1744 | 1744 | $pairs = str_split($blocks[$i], 2); |
| 1745 | 1745 | $pairs = array_reverse($pairs); |
| 1746 | 1746 | $blocks[$i] = implode('', $pairs); |
| 1747 | 1747 | } |
| 1748 | - for($i=0; $i < 5; $i++) { |
|
| 1748 | + for ($i = 0; $i < 5; $i++) { |
|
| 1749 | 1749 | $pairs = str_split($blocks[$i], 2); |
| 1750 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
| 1750 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
| 1751 | 1751 | } |
| 1752 | 1752 | return implode('', $blocks); |
| 1753 | 1753 | } |
@@ -1761,12 +1761,12 @@ discard block |
||
| 1761 | 1761 | $domainDN = $this->getDomainDNFromDN($dn); |
| 1762 | 1762 | $cacheKey = 'getSID-'.$domainDN; |
| 1763 | 1763 | $sid = $this->connection->getFromCache($cacheKey); |
| 1764 | - if(!is_null($sid)) { |
|
| 1764 | + if (!is_null($sid)) { |
|
| 1765 | 1765 | return $sid; |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
| 1769 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
| 1769 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
| 1770 | 1770 | $this->connection->writeToCache($cacheKey, false); |
| 1771 | 1771 | return false; |
| 1772 | 1772 | } |
@@ -1824,12 +1824,12 @@ discard block |
||
| 1824 | 1824 | $belongsToBase = false; |
| 1825 | 1825 | $bases = $this->helper->sanitizeDN($bases); |
| 1826 | 1826 | |
| 1827 | - foreach($bases as $base) { |
|
| 1827 | + foreach ($bases as $base) { |
|
| 1828 | 1828 | $belongsToBase = true; |
| 1829 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
| 1829 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
| 1830 | 1830 | $belongsToBase = false; |
| 1831 | 1831 | } |
| 1832 | - if($belongsToBase) { |
|
| 1832 | + if ($belongsToBase) { |
|
| 1833 | 1833 | break; |
| 1834 | 1834 | } |
| 1835 | 1835 | } |
@@ -1840,7 +1840,7 @@ discard block |
||
| 1840 | 1840 | * resets a running Paged Search operation |
| 1841 | 1841 | */ |
| 1842 | 1842 | private function abandonPagedSearch() { |
| 1843 | - if($this->connection->hasPagedResultSupport) { |
|
| 1843 | + if ($this->connection->hasPagedResultSupport) { |
|
| 1844 | 1844 | $cr = $this->connection->getConnectionResource(); |
| 1845 | 1845 | $this->invokeLDAPMethod('controlPagedResult', $cr, 0, false, $this->lastCookie); |
| 1846 | 1846 | $this->getPagedSearchResultState(); |
@@ -1858,16 +1858,16 @@ discard block |
||
| 1858 | 1858 | * @return string containing the key or empty if none is cached |
| 1859 | 1859 | */ |
| 1860 | 1860 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
| 1861 | - if($offset === 0) { |
|
| 1861 | + if ($offset === 0) { |
|
| 1862 | 1862 | return ''; |
| 1863 | 1863 | } |
| 1864 | 1864 | $offset -= $limit; |
| 1865 | 1865 | //we work with cache here |
| 1866 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
| 1866 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
| 1867 | 1867 | $cookie = ''; |
| 1868 | - if(isset($this->cookies[$cacheKey])) { |
|
| 1868 | + if (isset($this->cookies[$cacheKey])) { |
|
| 1869 | 1869 | $cookie = $this->cookies[$cacheKey]; |
| 1870 | - if(is_null($cookie)) { |
|
| 1870 | + if (is_null($cookie)) { |
|
| 1871 | 1871 | $cookie = ''; |
| 1872 | 1872 | } |
| 1873 | 1873 | } |
@@ -1885,11 +1885,11 @@ discard block |
||
| 1885 | 1885 | * @return bool |
| 1886 | 1886 | */ |
| 1887 | 1887 | public function hasMoreResults() { |
| 1888 | - if(!$this->connection->hasPagedResultSupport) { |
|
| 1888 | + if (!$this->connection->hasPagedResultSupport) { |
|
| 1889 | 1889 | return false; |
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1892 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
| 1893 | 1893 | // as in RFC 2696, when all results are returned, the cookie will |
| 1894 | 1894 | // be empty. |
| 1895 | 1895 | return false; |
@@ -1909,8 +1909,8 @@ discard block |
||
| 1909 | 1909 | */ |
| 1910 | 1910 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
| 1911 | 1911 | // allow '0' for 389ds |
| 1912 | - if(!empty($cookie) || $cookie === '0') { |
|
| 1913 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset; |
|
| 1912 | + if (!empty($cookie) || $cookie === '0') { |
|
| 1913 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.(int) $limit.'-'.(int) $offset; |
|
| 1914 | 1914 | $this->cookies[$cacheKey] = $cookie; |
| 1915 | 1915 | $this->lastCookie = $cookie; |
| 1916 | 1916 | } |
@@ -1937,17 +1937,17 @@ discard block |
||
| 1937 | 1937 | */ |
| 1938 | 1938 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
| 1939 | 1939 | $pagedSearchOK = false; |
| 1940 | - if($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1941 | - $offset = (int)$offset; //can be null |
|
| 1940 | + if ($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
| 1941 | + $offset = (int) $offset; //can be null |
|
| 1942 | 1942 | \OCP\Util::writeLog('user_ldap', |
| 1943 | 1943 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
| 1944 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
| 1944 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
| 1945 | 1945 | \OCP\Util::DEBUG); |
| 1946 | 1946 | //get the cookie from the search for the previous search, required by LDAP |
| 1947 | - foreach($bases as $base) { |
|
| 1947 | + foreach ($bases as $base) { |
|
| 1948 | 1948 | |
| 1949 | 1949 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
| 1950 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1950 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
| 1951 | 1951 | // no cookie known from a potential previous search. We need |
| 1952 | 1952 | // to start from 0 to come to the desired page. cookie value |
| 1953 | 1953 | // of '0' is valid, because 389ds |
@@ -1957,17 +1957,17 @@ discard block |
||
| 1957 | 1957 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
| 1958 | 1958 | // '0' is valid, because 389ds |
| 1959 | 1959 | //TODO: remember this, probably does not change in the next request... |
| 1960 | - if(empty($cookie) && $cookie !== '0') { |
|
| 1960 | + if (empty($cookie) && $cookie !== '0') { |
|
| 1961 | 1961 | $cookie = null; |
| 1962 | 1962 | } |
| 1963 | 1963 | } |
| 1964 | - if(!is_null($cookie)) { |
|
| 1964 | + if (!is_null($cookie)) { |
|
| 1965 | 1965 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
| 1966 | 1966 | $this->abandonPagedSearch(); |
| 1967 | 1967 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 1968 | 1968 | $this->connection->getConnectionResource(), $limit, |
| 1969 | 1969 | false, $cookie); |
| 1970 | - if(!$pagedSearchOK) { |
|
| 1970 | + if (!$pagedSearchOK) { |
|
| 1971 | 1971 | return false; |
| 1972 | 1972 | } |
| 1973 | 1973 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); |
@@ -1983,14 +1983,14 @@ discard block |
||
| 1983 | 1983 | * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination |
| 1984 | 1984 | * if we don't have a previous paged search. |
| 1985 | 1985 | */ |
| 1986 | - } else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1986 | + } else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
| 1987 | 1987 | // a search without limit was requested. However, if we do use |
| 1988 | 1988 | // Paged Search once, we always must do it. This requires us to |
| 1989 | 1989 | // initialize it with the configured page size. |
| 1990 | 1990 | $this->abandonPagedSearch(); |
| 1991 | 1991 | // in case someone set it to 0 … use 500, otherwise no results will |
| 1992 | 1992 | // be returned. |
| 1993 | - $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500; |
|
| 1993 | + $pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500; |
|
| 1994 | 1994 | $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', |
| 1995 | 1995 | $this->connection->getConnectionResource(), |
| 1996 | 1996 | $pageSize, false, ''); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | 'post_createUser', |
| 78 | 78 | $this, |
| 79 | 79 | 'postCreateUser'); |
| 80 | - \OC::$server->getUserManager()->listen('\OC\User', 'assignedUserId', function ($uid) { |
|
| 80 | + \OC::$server->getUserManager()->listen('\OC\User', 'assignedUserId', function($uid) { |
|
| 81 | 81 | $this->postCreateUser(['uid' => $uid]); |
| 82 | 82 | }); |
| 83 | 83 | Util::connectHook('OC_User', |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | 'post_deleteUser', |
| 90 | 90 | $this, |
| 91 | 91 | 'postDeleteUser'); |
| 92 | - \OC::$server->getUserManager()->listen('\OC\User', 'postUnassignedUserId', function ($uid) { |
|
| 92 | + \OC::$server->getUserManager()->listen('\OC\User', 'postUnassignedUserId', function($uid) { |
|
| 93 | 93 | $this->postDeleteUser(['uid' => $uid]); |
| 94 | 94 | }); |
| 95 | 95 | \OC::$server->getUserManager()->listen('\OC\User', 'postUnassignedUserId', [$this, 'postUnassignedUserId']); |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | public function preDeleteUser($params) { |
| 108 | 108 | $uid = $params['uid']; |
| 109 | 109 | $this->usersToDelete[$uid] = $this->userManager->get($uid); |
| 110 | - $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid); |
|
| 111 | - $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid); |
|
| 110 | + $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/'.$uid); |
|
| 111 | + $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/'.$uid); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public function preUnassignedUserId($uid) { |
@@ -117,14 +117,14 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function postDeleteUser($params) { |
| 119 | 119 | $uid = $params['uid']; |
| 120 | - if (isset($this->usersToDelete[$uid])){ |
|
| 120 | + if (isset($this->usersToDelete[$uid])) { |
|
| 121 | 121 | $this->syncService->deleteUser($this->usersToDelete[$uid]); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | foreach ($this->calendarsToDelete as $calendar) { |
| 125 | 125 | $this->calDav->deleteCalendar($calendar['id']); |
| 126 | 126 | } |
| 127 | - $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
| 127 | + $this->calDav->deleteAllSharesByUser('principals/users/'.$uid); |
|
| 128 | 128 | |
| 129 | 129 | foreach ($this->addressBooksToDelete as $addressBook) { |
| 130 | 130 | $this->cardDav->deleteAddressBook($addressBook['id']); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public function postUnassignedUserId($uid) { |
| 135 | - if (isset($this->usersToDelete[$uid])){ |
|
| 135 | + if (isset($this->usersToDelete[$uid])) { |
|
| 136 | 136 | $this->syncService->deleteUser($this->usersToDelete[$uid]); |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public function firstLogin(IUser $user = null) { |
| 146 | 146 | if (!is_null($user)) { |
| 147 | - $principal = 'principals/users/' . $user->getUID(); |
|
| 147 | + $principal = 'principals/users/'.$user->getUID(); |
|
| 148 | 148 | if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
| 149 | 149 | try { |
| 150 | 150 | $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
@@ -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,14 +225,14 @@ 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 | - if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) { |
|
| 235 | + if (!empty($ldapDefaultPPolicyDN) && ((int) $turnOnPasswordChange === 1)) { |
|
| 236 | 236 | //remove last password expiry warning if any |
| 237 | 237 | $notification = $this->notificationManager->createNotification(); |
| 238 | 238 | $notification->setApp('user_ldap') |
@@ -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((int)$marked === 0) { |
|
| 390 | + if ((int) $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); // we don't emit unassign signals here, since it is implicit to delete signals fired from core |
@@ -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 | - | (((int)$this->access->connection->turnOnPasswordChange === 1)? Backend::SET_PASSWORD :0) |
|
| 552 | + | (((int) $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 | |
@@ -31,25 +31,25 @@ |
||
| 31 | 31 | \OC_JSON::checkAppEnabled('user_ldap'); |
| 32 | 32 | \OC_JSON::callCheck(); |
| 33 | 33 | |
| 34 | -$subject = (string)$_POST['ldap_clear_mapping']; |
|
| 34 | +$subject = (string) $_POST['ldap_clear_mapping']; |
|
| 35 | 35 | $mapping = null; |
| 36 | 36 | try { |
| 37 | - if($subject === 'user') { |
|
| 37 | + if ($subject === 'user') { |
|
| 38 | 38 | $mapping = new UserMapping(\OC::$server->getDatabaseConnection()); |
| 39 | 39 | $result = $mapping->clearCb( |
| 40 | - function ($uid) { |
|
| 40 | + function($uid) { |
|
| 41 | 41 | \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]); |
| 42 | 42 | }, |
| 43 | - function ($uid) { |
|
| 43 | + function($uid) { |
|
| 44 | 44 | \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]); |
| 45 | 45 | } |
| 46 | 46 | ); |
| 47 | - } else if($subject === 'group') { |
|
| 47 | + } else if ($subject === 'group') { |
|
| 48 | 48 | $mapping = new GroupMapping(\OC::$server->getDatabaseConnection()); |
| 49 | 49 | $result = $mapping->clear(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if($mapping === null || !$result) { |
|
| 52 | + if ($mapping === null || !$result) { |
|
| 53 | 53 | $l = \OC::$server->getL10N('user_ldap'); |
| 54 | 54 | throw new \Exception($l->t('Failed to clear the mappings.')); |
| 55 | 55 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
| 5 | 5 | * |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | protected function userManagementHooks(ILogger $logger) { |
| 87 | 87 | $userActions = new UserManagement($logger); |
| 88 | 88 | |
| 89 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 90 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 91 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 89 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 90 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 91 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 92 | 92 | |
| 93 | 93 | /** @var IUserSession|Session $userSession */ |
| 94 | 94 | $userSession = $this->getContainer()->getServer()->getUserSession(); |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - protected function groupHooks(ILogger $logger) { |
|
| 100 | + protected function groupHooks(ILogger $logger) { |
|
| 101 | 101 | $groupActions = new GroupManagement($logger); |
| 102 | 102 | |
| 103 | 103 | /** @var IGroupManager|Manager $groupManager */ |
| 104 | 104 | $groupManager = $this->getContainer()->getServer()->getGroupManager(); |
| 105 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 106 | - $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 107 | - $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 108 | - $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 105 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 106 | + $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 107 | + $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 108 | + $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | protected function sharingHooks(ILogger $logger) { |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | protected function versionsHooks(ILogger $logger) { |
| 219 | 219 | $versionsActions = new Versions($logger); |
| 220 | 220 | Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
| 221 | - Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete'); |
|
| 221 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | protected function trashbinHooks(ILogger $logger) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]> |
| 5 | 5 | * |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | public function assign(string $uid) { |
| 59 | 59 | $this->log( |
| 60 | 60 | 'UserID assigned: "%s"', |
| 61 | - [ 'uid' => $uid ], |
|
| 62 | - [ 'uid' ] |
|
| 61 | + ['uid' => $uid], |
|
| 62 | + ['uid'] |
|
| 63 | 63 | ); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | public function unassign(string $uid) { |
| 87 | 87 | $this->log( |
| 88 | 88 | 'UserID unassigned: "%s"', |
| 89 | - [ 'uid' => $uid ], |
|
| 90 | - [ 'uid' ] |
|
| 89 | + ['uid' => $uid], |
|
| 90 | + ['uid'] |
|
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param IUser $user |
| 115 | 115 | */ |
| 116 | 116 | public function setPassword(IUser $user) { |
| 117 | - if($user->getBackendClassName() === 'Database') { |
|
| 117 | + if ($user->getBackendClassName() === 'Database') { |
|
| 118 | 118 | $this->log( |
| 119 | 119 | 'Password of user "%s" has been changed', |
| 120 | 120 | [ |