]> source.dussan.org Git - nextcloud-server.git/commitdiff
Return true or false from readAttribute if $attr is empty
authorLorenzo M. Catucci <lorenzo@sancho.ccd.uniroma2.it>
Mon, 5 Nov 2012 14:38:49 +0000 (15:38 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Tue, 6 Nov 2012 15:43:36 +0000 (16:43 +0100)
This way, readAttribute can act as an existence checker.

apps/user_ldap/lib/access.php
apps/user_ldap/user_ldap.php

index a500e1bf5b43b81d6f49403ceab237eded4de886..b09b6e7d71927dee2d81b6a71172512a39626aa6 100644 (file)
@@ -38,9 +38,10 @@ abstract class Access {
         * @brief reads a given attribute for an LDAP record identified by a DN
         * @param $dn the record in question
         * @param $attr the attribute that shall be retrieved
-        * @returns the values in an array on success, false otherwise
+        *        if empty, just check the record's existence
+        * @returns true or the values in an array on success, false otherwise
         *
-        * Reads an attribute from an LDAP entry
+        * Reads an attribute from an LDAP entry or check if entry exists
         */
        public function readAttribute($dn, $attr) {
                if(!$this->checkConnection()) {
@@ -55,10 +56,14 @@ abstract class Access {
                }
                $rr = @ldap_read($cr, $dn, 'objectClass=*', array($attr));
                if(!is_resource($rr)) {
-                       \OCP\Util::writeLog('user_ldap', 'readAttribute '.$attr.' failed for DN '.$dn, \OCP\Util::DEBUG);
+                       \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
                        //in case an error occurs , e.g. object does not exist
                        return false;
                }
+               if (empty($attr)) {
+                       \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG);
+                       return true;
+               }
                $er = ldap_first_entry($cr, $rr);
                //LDAP attributes are not case sensitive
                $result = \OCP\Util::mb_array_change_key_case(ldap_get_attributes($cr, $er), MB_CASE_LOWER, 'UTF-8');
index e104c8d1764925cde9d016d4d024ecbeb02ded9d..5e5af44d55e5b384f86352f76b9be6b485e4015f 100644 (file)
@@ -141,9 +141,8 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
                        return false;
                }
 
-               //if user really still exists, we will be able to read his objectclass
-               $objcs = $this->readAttribute($dn, 'objectclass');
-               if(!$objcs || empty($objcs)) {
+               //check if user really still exists by reading its entry
+               if(!$this->readAttribute($dn, '') ) {
                        $this->connection->writeToCache('userExists'.$uid, false);
                        return false;
                }