From: Arthur Schiwon Date: Fri, 22 Jun 2012 10:42:07 +0000 (+0200) Subject: LDAP: cheaper userExists() implementation X-Git-Tag: v4.0.3~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0d9534eb4b7bb0c1f62e32397fc1f7166934a32e;p=nextcloud-server.git LDAP: cheaper userExists() implementation --- diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 9281aebe81d..48e7d429fcb 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -124,7 +124,19 @@ class OC_USER_LDAP extends OC_User_Backend { * @return boolean */ public function userExists($uid){ - return in_array($uid, $this->getUsers()); + //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. + $dn = OC_LDAP::username2dn($uid); + if(!$dn) { + return false; + } + + //if user really still exists, we will be able to read his cn + $cn = OC_LDAP::readAttribute($dn, 'cn'); + if(!$cn || empty($cn)) { + return false; + } + + return true; } }