From 15afbfd198f9f54cee8717776b4f45f73d9b1cbf Mon Sep 17 00:00:00 2001 From: "Lorenzo M. Catucci" Date: Thu, 6 Dec 2012 18:09:47 +0100 Subject: [PATCH 1/2] Add an $excludingBackend optional parameter to the userExists method both in OCP\User and in OC_User. --- lib/public/user.php | 6 +++--- lib/user.php | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/public/user.php b/lib/public/user.php index b320ce8ea0c..9e50115ab70 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -65,12 +65,12 @@ class User { /** * @brief check if a user exists * @param string $uid the username + * @param string $excludingBackend (default none) * @return boolean */ - public static function userExists( $uid ) { - return \OC_USER::userExists( $uid ); + public static function userExists( $uid, $excludingBackend = null ) { + return \OC_USER::userExists( $uid, $excludingBackend ); } - /** * @brief Loggs the user out including all the session data * @returns true diff --git a/lib/user.php b/lib/user.php index 31c93740d77..d55c6165a09 100644 --- a/lib/user.php +++ b/lib/user.php @@ -407,10 +407,15 @@ class OC_User { /** * @brief check if a user exists * @param string $uid the username + * @param string $excludingBackend (default none) * @return boolean */ - public static function userExists($uid) { + public static function userExists($uid, $excludingBackend=null) { foreach(self::$_usedBackends as $backend) { + if (!is_null($excludingBackend) && !strcmp(get_class($backend),$excludingBackend)) { + OC_Log::write('OC_User', $excludingBackend . 'excluded from user existance check.', OC_Log::DEBUG); + continue; + } $result=$backend->userExists($uid); if($result===true) { return true; From de34f771c22b9a54fa22d9c00741e362f47c852d Mon Sep 17 00:00:00 2001 From: "Lorenzo M. Catucci" Date: Thu, 6 Dec 2012 18:11:14 +0100 Subject: [PATCH 2/2] Exclude LDAP backend from global user searches triggered by itself. --- apps/user_ldap/lib/access.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 53d4edbe69c..f71f4035928 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -281,8 +281,8 @@ abstract class Access { } $ldapname = $this->sanitizeUsername($ldapname); - //a new user/group! Then let's try to add it. We're shooting into the blue with the user/group name, assuming that in most cases there will not be a conflict. Otherwise an error will occur and we will continue with our second shot. - if(($isUser && !\OCP\User::userExists($ldapname)) || (!$isUser && !\OC_Group::groupExists($ldapname))) { + //a new user/group! Add it only if it doesn't conflict with other backend's users or existing groups + if(($isUser && !\OCP\User::userExists($ldapname, 'OCA\\user_ldap\\USER_LDAP')) || (!$isUser && !\OC_Group::groupExists($ldapname))) { if($this->mapComponent($dn, $ldapname, $isUser)) { return $ldapname; } @@ -874,4 +874,4 @@ abstract class Access { return $pagedSearchOK; } -} \ No newline at end of file +}