X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FLdapCommon%2FLdapCommon.php;h=7d052d5b24ec84a0de0fe703b65787bcc195d24b;hb=ff004c5912eb71926a39cc64181601b1c4208088;hp=1f1647a75306581b03863b247e11663c29580566;hpb=c6b1e25d1732471f91687cc09ace5face1820b72;p=quix0rs-gnu-social.git diff --git a/plugins/LdapCommon/LdapCommon.php b/plugins/LdapCommon/LdapCommon.php index 1f1647a753..7d052d5b24 100644 --- a/plugins/LdapCommon/LdapCommon.php +++ b/plugins/LdapCommon/LdapCommon.php @@ -60,18 +60,22 @@ class LdapCommon $this->ldap_config = $this->get_ldap_config(); if(!isset($this->host)){ - throw new Exception("must specify a host"); + // 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)){ - throw new Exception("must specify a 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'])){ - throw new Exception("username attribute must be set."); + // 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,15 +128,19 @@ 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 = common_memcache(); + $c = Cache::instance(); if (!empty($c)) { $cacheObj = new MemcacheSchemaCache( array('c'=>$c, - 'cacheKey' => common_cache_key('ldap_schema:' . $config_id))); + 'cacheKey' => Cache::key('ldap_schema:' . $config_id))); $ldap->registerSchemaCache($cacheObj); } self::$ldap_connections[$config_id] = $ldap; @@ -140,10 +150,16 @@ class LdapCommon function checkPassword($username, $password) { - $entry = $this->get_user($username); + $entry = $this->get_user($username,array('dn' => 'dn')); if(!$entry){ return false; }else{ + if(empty($password)) { + //NET_LDAP2 will do an anonymous bind if bindpw is not set / empty string + //which causes all login attempts that involve a blank password to appear + //to succeed. Which is obviously not good. + return false; + } $config = $this->get_ldap_config(); $config['binddn']=$entry->dn(); $config['bindpw']=$password; @@ -159,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{ @@ -173,7 +189,7 @@ class LdapCommon $ldap = $this->get_ldap_connection($config); $entry = $this->get_user($username,array(),$ldap); - + $newCryptedPassword = $this->hashPassword($newpassword, $this->password_encoding); if ($newCryptedPassword===false) { return false; @@ -254,15 +270,14 @@ class LdapCommon * @return string The hashed password. * */ - - function hashPassword( $passwordClear, $encodageType ) + function hashPassword( $passwordClear, $encodageType ) { $encodageType = strtolower( $encodageType ); switch( $encodageType ) { - case 'crypt': - $cryptedPassword = '{CRYPT}' . crypt($passwordClear,$this->randomSalt(2)); + case 'crypt': + $cryptedPassword = '{CRYPT}' . crypt($passwordClear,$this->randomSalt(2)); break; - + case 'ext_des': // extended des crypt. see OpenBSD crypt man page. if ( ! defined( 'CRYPT_EXT_DES' ) || CRYPT_EXT_DES == 0 ) {return FALSE;} //Your system crypt library does not support extended DES encryption. @@ -345,8 +360,7 @@ class LdapCommon * @param int $length The length of the salt string to generate. * @return string The generated salt string. */ - - function randomSalt( $length ) + function randomSalt( $length ) { $possible = '0123456789'. 'abcdefghijklmnopqrstuvwxyz'. @@ -360,10 +374,8 @@ class LdapCommon return $str; } - } class LdapInvalidCredentialsException extends Exception { - }