]> source.dussan.org Git - nextcloud-server.git/commitdiff
LDAP: only connect to LDAP once on login
authorArthur Schiwon <blizzz@owncloud.com>
Wed, 14 Aug 2013 14:03:18 +0000 (16:03 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Wed, 14 Aug 2013 14:03:18 +0000 (16:03 +0200)
apps/user_ldap/lib/connection.php
apps/user_ldap/user_ldap.php

index 2011ba3878ddf78c9349c174888ea6f6e28baf01..b1dc0ecd5028655f3daee625abc813533ff32119 100644 (file)
@@ -29,6 +29,9 @@ class Connection {
        private $configID;
        private $configured = false;
 
+       //whether connection should be kept on __destruct
+       private $dontDestruct = false;
+
        //cache handler
        protected $cache;
 
@@ -83,11 +86,20 @@ class Connection {
        }
 
        public function __destruct() {
-               if(is_resource($this->ldapConnectionRes)) {
+               if(!$this->dontDestruct && is_resource($this->ldapConnectionRes)) {
                        @ldap_unbind($this->ldapConnectionRes);
                };
        }
 
+       /**
+        * @brief defines behaviour when the instance is cloned
+        */
+       public function __clone() {
+               //a cloned instance inherits the connection resource. It may use it,
+               //but it may not disconnect it
+               $this->dontDestruct = true;
+       }
+
        public function __get($name) {
                if(!$this->configured) {
                        $this->readConfiguration();
index 1277e074714619b9fea87c232a475a8da17cc097..60000cfb2f4b7f60820a481558da8adc196f1b48 100644 (file)
@@ -77,11 +77,6 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
                }
                $dn = $ldap_users[0];
 
-               //are the credentials OK?
-               if(!$this->areCredentialsValid($dn, $password)) {
-                       return false;
-               }
-
                //do we have a username for him/her?
                $ocname = $this->dn2username($dn);
 
@@ -90,6 +85,11 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
                        $this->updateQuota($dn);
                        $this->updateEmail($dn);
 
+                       //are the credentials OK?
+                       if(!$this->areCredentialsValid($dn, $password)) {
+                               return false;
+                       }
+
                        //give back the display name
                        return $ocname;
                }