Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix exception on LDAP mapping during login #12693

Merged
merged 4 commits into from Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .drone.yml
Expand Up @@ -629,6 +629,11 @@ pipeline:
image: nextcloudci/integration-php7.0:integration-php7.0-6
commands:
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
- ./occ config:system:set redis host --value=cache
- ./occ config:system:set redis port --value=6379 --type=integer
- ./occ config:system:set redis timeout --value=0 --type=integer
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
- ./occ app:enable user_ldap
- cd build/integration
- ./run.sh ldap_features/ldap-openldap.feature
Expand All @@ -639,6 +644,11 @@ pipeline:
image: nextcloudci/integration-php7.0:integration-php7.0-6
commands:
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
- ./occ config:system:set redis host --value=cache
- ./occ config:system:set redis port --value=6379 --type=integer
- ./occ config:system:set redis timeout --value=0 --type=integer
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
- ./occ app:enable user_ldap
- cd build/integration
- ./run.sh ldap_features/openldap-uid-username.feature
Expand All @@ -649,6 +659,11 @@ pipeline:
image: nextcloudci/integration-php7.0:integration-php7.0-6
commands:
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
- ./occ config:system:set redis host --value=cache
- ./occ config:system:set redis port --value=6379 --type=integer
- ./occ config:system:set redis timeout --value=0 --type=integer
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.local
- ./occ config:system:set --type string --value "\\OC\\Memcache\\Redis" memcache.distributed
- ./occ app:enable user_ldap
- cd build/integration
- ./run.sh ldap_features/openldap-numerical-id.feature
Expand Down Expand Up @@ -958,10 +973,13 @@ matrix:
- TESTS: integration-ldap-features
- TESTS: integration-ldap-openldap-features
ENABLE_OPENLDAP: true
ENABLE_REDIS: true
- TESTS: integration-ldap-openldap-uid-features
ENABLE_OPENLDAP: true
ENABLE_REDIS: true
- TESTS: integration-ldap-openldap-numerical-id-features
ENABLE_OPENLDAP: true
ENABLE_REDIS: true
- TESTS: integration-trashbin
- TESTS: integration-remote-api
- TESTS: integration-download
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/SyncService.php
Expand Up @@ -261,7 +261,7 @@ private function parseMultiStatus($body) {
/**
* @param IUser $user
*/
public function updateUser($user) {
public function updateUser(IUser $user) {
$systemAddressBook = $this->getLocalSystemAddressBook();
$addressBookId = $systemAddressBook['id'];
$converter = new Converter($this->accountManager);
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/lib/HookManager.php
Expand Up @@ -101,7 +101,9 @@ public function setup() {

public function postCreateUser($params) {
$user = $this->userManager->get($params['uid']);
$this->syncService->updateUser($user);
if ($user instanceof IUser) {
$this->syncService->updateUser($user);
}
}

public function preDeleteUser($params) {
Expand Down
44 changes: 30 additions & 14 deletions apps/user_ldap/lib/Access.php
Expand Up @@ -609,33 +609,49 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
// outside of core user management will still cache the user as non-existing.
$originalTTL = $this->connection->ldapCacheTTL;
$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
if(($isUser && $intName !== '' && !$this->ncUserManager->userExists($intName))
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
if($mapper->map($fdn, $intName, $uuid)) {
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
if($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$intName]);
}
$newlyMapped = true;
if( $intName !== ''
&& (($isUser && !$this->ncUserManager->userExists($intName))
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
)
) {
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
if($newlyMapped) {
return $intName;
}
}
$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);

$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$altName]);
if (is_string($altName)) {
if($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
$newlyMapped = true;
return $altName;
}
$newlyMapped = true;
return $altName;
}

//if everything else did not help..
\OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', ILogger::INFO);
return false;
}

protected function mapAndAnnounceIfApplicable(
AbstractMapping $mapper,
string $fdn,
string $name,
string $uuid,
bool $isUser
) :bool {
if($mapper->map($fdn, $name, $uuid)) {
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->cacheUserExists($name);
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
}
return true;
}
return false;
}

/**
* gives back the user names as they are used ownClod internally
* @param array $ldapUsers as returned by fetchList()
Expand Down
6 changes: 6 additions & 0 deletions apps/user_ldap/lib/AppInfo/Application.php
Expand Up @@ -24,6 +24,8 @@
namespace OCA\User_LDAP\AppInfo;

use OCA\User_LDAP\Controller\RenewPasswordController;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LDAP;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\IL10N;
Expand All @@ -50,5 +52,9 @@ public function __construct () {
$server->getURLGenerator()
);
});

$container->registerService(ILDAPWrapper::class, function () {
return new LDAP();
});
}
}
5 changes: 5 additions & 0 deletions apps/user_ldap/lib/Command/SetConfig.php
Expand Up @@ -26,6 +26,8 @@

namespace OCA\User_LDAP\Command;

use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\LDAP;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -83,5 +85,8 @@ protected function setValue($configID, $key, $value) {
$configHolder = new Configuration($configID);
$configHolder->$key = $value;
$configHolder->saveConfiguration();

$connectionFactory = new ConnectionFactory(new LDAP());
$connectionFactory->get($configID)->clearCache();
}
}
9 changes: 8 additions & 1 deletion apps/user_ldap/lib/Controller/ConfigAPIController.php
Expand Up @@ -27,6 +27,7 @@
use OC\Core\Controller\OCSController;
use OC\Security\IdentityProof\Manager;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
Expand All @@ -45,6 +46,9 @@ class ConfigAPIController extends OCSController {
/** @var ILogger */
private $logger;

/** @var ConnectionFactory */
private $connectionFactory;

public function __construct(
$appName,
IRequest $request,
Expand All @@ -53,7 +57,8 @@ public function __construct(
IUserManager $userManager,
Manager $keyManager,
Helper $ldapHelper,
ILogger $logger
ILogger $logger,
ConnectionFactory $connectionFactory
) {
parent::__construct(
$appName,
Expand All @@ -67,6 +72,7 @@ public function __construct(

$this->ldapHelper = $ldapHelper;
$this->logger = $logger;
$this->connectionFactory = $connectionFactory;
}

/**
Expand Down Expand Up @@ -198,6 +204,7 @@ public function modify($configID, $configData) {
}

$configuration->saveConfiguration();
$this->connectionFactory->get($configID)->clearCache();
} catch(OCSException $e) {
throw $e;
} catch (\Exception $e) {
Expand Down