From a3644638aaf0418598196a870204e0b632a4c8ad Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 17 Apr 2015 06:28:40 -0400
Subject: [PATCH] Allow preference sections to define CSS class names

---
 plugins/password/drivers/ldap.php |   51 ++++++++++++++++++++++++++-------------------------
 1 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php
index 2cf2c11..6ed5ada 100644
--- a/plugins/password/drivers/ldap.php
+++ b/plugins/password/drivers/ldap.php
@@ -38,7 +38,8 @@
         // Building user DN
         if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) {
             $userDN = self::substitute_vars($userDN);
-        } else {
+        }
+        else {
             $userDN = $this->search_userdn($rcmail);
         }
 
@@ -74,22 +75,8 @@
         $ldap = Net_LDAP2::connect($ldapConfig);
 
         // Checking for connection error
-        if (PEAR::isError($ldap)) {
+        if (is_a($ldap, 'PEAR_Error')) {
             return PASSWORD_CONNECT_ERROR;
-        }
-
-        $encodage = $rcmail->config->get('password_ldap_encodage');
-
-        // Support multiple userPassword values where desired.
-        // multiple encodings can be specified separated by '+' (e.g. "cram-md5+ssha")
-        $encodages = explode('+',$encodage);
-        $crypted_pass = array();
-
-        foreach($encodages as $enc) {
-            $cpw = self::hash_password($passwd, $enc);
-            if(!empty($cpw)) {
-                $crypted_pass[] = $cpw;
-            }
         }
 
         $force        = $rcmail->config->get('password_ldap_force_replace');
@@ -98,6 +85,19 @@
         $smbpwattr    = $rcmail->config->get('password_ldap_samba_pwattr');
         $smblchattr   = $rcmail->config->get('password_ldap_samba_lchattr');
         $samba        = $rcmail->config->get('password_ldap_samba');
+        $encodage     = $rcmail->config->get('password_ldap_encodage');
+
+        // Support multiple userPassword values where desired.
+        // multiple encodings can be specified separated by '+' (e.g. "cram-md5+ssha")
+        $encodages    = explode('+', $encodage);
+        $crypted_pass = array();
+
+        foreach ($encodages as $enc) {
+            $cpw = self::hash_password($passwd, $enc);
+            if (!empty($cpw)) {
+                $crypted_pass[] = $cpw;
+            }
+        }
 
         // Support password_ldap_samba option for backward compat.
         if ($samba && !$smbpwattr) {
@@ -176,7 +176,7 @@
 
         $ldap = Net_LDAP2::connect($ldapConfig);
 
-        if (PEAR::isError($ldap)) {
+        if (is_a($ldap, 'PEAR_Error')) {
             return '';
         }
 
@@ -189,7 +189,7 @@
 
         $result = $ldap->search($base, $filter, $options);
         $ldap->done();
-        if (PEAR::isError($result) || ($result->count() != 1)) {
+        if (is_a($result, 'PEAR_Error') || ($result->count() != 1)) {
             return '';
         }
 
@@ -259,8 +259,12 @@
                 return false;
             }
 
-            /* Hardcoded to second blowfish version and set number of rounds */
-            $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . self::random_salt(13));
+            $rcmail = rcmail::get_instance();
+            $cost   = (int) $rcmail->config->get('password_blowfish_cost');
+            $cost   = $cost < 4 || $cost > 31 ? 12 : $cost;
+            $prefix = sprintf('$2a$%02d$', $cost);
+
+            $crypted_password = '{CRYPT}' . crypt($password_clear, $prefix . self::random_salt(22));
             break;
 
         case 'md5':
@@ -285,7 +289,6 @@
             break;
 
         case 'ssha':
-            mt_srand((double) microtime() * 1000000);
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
 
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
@@ -312,7 +315,6 @@
 
 
         case 'smd5':
-            mt_srand((double) microtime() * 1000000);
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
 
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
@@ -347,8 +349,8 @@
             break;
 
         case 'cram-md5':
-            require_once(dirname(__FILE__).'/../helpers/dovecot_hmacmd5.php');
-			return dovecot_hmacmd5($password_clear);
+            require_once __DIR__ . '/../helpers/dovecot_hmacmd5.php';
+            return dovecot_hmacmd5($password_clear);
             break;
 
         case 'clear':
@@ -369,7 +371,6 @@
     {
         $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './';
         $str = '';
-        // mt_srand((double)microtime() * 1000000);
 
         while (strlen($str) < $length) {
             $str .= substr($possible, (rand() % strlen($possible)), 1);

--
Gitblit v1.9.1