]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/LdapCommon/LdapCommon.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / LdapCommon / LdapCommon.php
index 579fe4b64b474fe649198170037e9c1ba1a6ad33..aea1b72ea4f409f4a641b3542721ed20102adcb2 100644 (file)
@@ -60,18 +60,22 @@ class LdapCommon
         $this->ldap_config = $this->get_ldap_config();
 
         if(!isset($this->host)){
-            throw new Exception(_m("A host must be specified."));
+            // TRANS: Exception thrown when initialising the LDAP Common plugin fails because of an incorrect configuration.
+            throw new Exception(_m('A host must be specified.'));
         }
         if(!isset($this->basedn)){
+            // TRANS: Exception thrown when initialising the LDAP Common plugin fails because of an incorrect configuration.
             throw new Exception(_m('"basedn" must be specified.'));
         }
         if(!isset($this->attributes['username'])){
+            // TRANS: Exception thrown when initialising the LDAP Common plugin fails because of an incorrect configuration.
             throw new Exception(_m('The username attribute must be set.'));
         }
     }
 
     function onAutoload($cls)
     {
+        // we've added an extra include-path in the beginning of this file
         switch ($cls)
         {
          case 'MemcacheSchemaCache':
@@ -90,6 +94,8 @@ class LdapCommon
             require_once 'Net/LDAP2/Entry.php';
             return false;
         }
+
+        return true;
     }
 
     function get_ldap_config(){
@@ -122,9 +128,13 @@ class LdapCommon
                 // if we were called with a config, assume caller will handle
                 // incorrect username/password (LDAP_INVALID_CREDENTIALS)
                 if (isset($config) && $err->getCode() == 0x31) {
-                    throw new LdapInvalidCredentialsException('Could not connect to LDAP server: '.$err->getMessage());
+                    // TRANS: Exception thrown in the LDAP Common plugin when LDAP server is not available.
+                    // TRANS: %s is the error message.
+                    throw new LdapInvalidCredentialsException(sprintf(_m('Could not connect to LDAP server: %s'),$err->getMessage()));
                 }
-                throw new Exception('Could not connect to LDAP server: '.$err->getMessage());
+                // TRANS: Exception thrown in the LDAP Common plugin when LDAP server is not available.
+                // TRANS: %s is the error message.
+                throw new Exception(sprintf(_m('Could not connect to LDAP server: %s.'),$err->getMessage()));
             }
             $c = Cache::instance();
             if (!empty($c)) {
@@ -140,7 +150,7 @@ class LdapCommon
 
     function checkPassword($username, $password)
     {
-        $entry = $this->get_user($username);
+        $entry = $this->get_user($username,array('dn' => 'dn'));
         if(!$entry){
             return false;
         }else{
@@ -165,10 +175,10 @@ class LdapCommon
     function changePassword($username,$oldpassword,$newpassword)
     {
         if(! isset($this->attributes['password']) || !isset($this->password_encoding)){
-            //throw new Exception(_('Sorry, changing LDAP passwords is not supported at this time'));
+            //throw new Exception(_m('Sorry, changing LDAP passwords is not supported at this time.'));
             return false;
         }
-        $entry = $this->get_user($username);
+        $entry = $this->get_user($username,array('dn' => 'dn'));
         if(!$entry){
             return false;
         }else{
@@ -360,7 +370,7 @@ class LdapCommon
         mt_srand((double)microtime() * 1000000);
 
         while( strlen( $str ) < $length )
-            $str .= substr( $possible, ( rand() % strlen( $possible ) ), 1 );
+            $str .= substr( $possible, ( mt_rand() % strlen( $possible ) ), 1 );
 
         return $str;
     }