diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-12-17 14:38:59 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-12-17 14:38:59 +0100 |
commit | d6938bd1ea3058b21efa25a17a4437195c484067 (patch) | |
tree | 6ec7f24edbdceac7bf4c06ceae6f4da0a7e245f2 | |
parent | a2b638320425309dd9af9ec8d53b925890628783 (diff) |
CS fixes, mostly tabs to spaces conversion
-rw-r--r-- | plugins/password/drivers/cpanel.php | 138 | ||||
-rw-r--r-- | plugins/password/drivers/directadmin.php | 20 | ||||
-rw-r--r-- | plugins/password/drivers/ldap.php | 6 | ||||
-rw-r--r-- | plugins/password/drivers/ldap_simple.php | 348 | ||||
-rw-r--r-- | plugins/password/drivers/smb.php | 1 | ||||
-rw-r--r-- | plugins/password/drivers/sql.php | 60 | ||||
-rw-r--r-- | plugins/password/drivers/virtualmin.php | 8 | ||||
-rw-r--r-- | plugins/password/drivers/vpopmaild.php | 2 |
8 files changed, 288 insertions, 295 deletions
diff --git a/plugins/password/drivers/cpanel.php b/plugins/password/drivers/cpanel.php index 58351143b..79887109b 100644 --- a/plugins/password/drivers/cpanel.php +++ b/plugins/password/drivers/cpanel.php @@ -20,14 +20,14 @@ class rcube_cpanel_password // Create a cPanel email object $cPanel = new emailAccount($rcmail->config->get('password_cpanel_host'), - $rcmail->config->get('password_cpanel_username'), - $rcmail->config->get('password_cpanel_password'), - $rcmail->config->get('password_cpanel_port'), - $rcmail->config->get('password_cpanel_ssl'), - $rcmail->config->get('password_cpanel_theme'), - $_SESSION['username'] ); + $rcmail->config->get('password_cpanel_username'), + $rcmail->config->get('password_cpanel_password'), + $rcmail->config->get('password_cpanel_port'), + $rcmail->config->get('password_cpanel_ssl'), + $rcmail->config->get('password_cpanel_theme'), + $_SESSION['username'] ); - if ($cPanel->setPassword($newpass)){ + if ($cPanel->setPassword($newpass)) { return PASSWORD_SUCCESS; } else { @@ -39,64 +39,60 @@ class rcube_cpanel_password class HTTP { - function HTTP($host, $username, $password, $port, $ssl, $theme) - { - $this->ssl = $ssl ? 'ssl://' : ''; - $this->username = $username; - $this->password = $password; - $this->theme = $theme; - $this->auth = base64_encode($username . ':' . $password); - $this->port = $port; - $this->host = $host; - $this->path = '/frontend/' . $theme . '/'; - } + function HTTP($host, $username, $password, $port, $ssl, $theme) + { + $this->ssl = $ssl ? 'ssl://' : ''; + $this->username = $username; + $this->password = $password; + $this->theme = $theme; + $this->auth = base64_encode($username . ':' . $password); + $this->port = $port; + $this->host = $host; + $this->path = '/frontend/' . $theme . '/'; + } + + function getData($url, $data = '') + { + $url = $this->path . $url; + if (is_array($data)) { + $url = $url . '?'; + foreach ($data as $key => $value) { + $url .= urlencode($key) . '=' . urlencode($value) . '&'; + } + $url = substr($url, 0, -1); + } - function getData($url, $data = '') - { - $url = $this->path . $url; - if(is_array($data)) - { - $url = $url . '?'; - foreach($data as $key=>$value) - { - $url .= urlencode($key) . '=' . urlencode($value) . '&'; - } - $url = substr($url, 0, -1); - } - $response = ''; - $fp = fsockopen($this->ssl . $this->host, $this->port); - if(!$fp) - { - return false; - } - $out = 'GET ' . $url . ' HTTP/1.0' . "\r\n"; - $out .= 'Authorization: Basic ' . $this->auth . "\r\n"; - $out .= 'Connection: Close' . "\r\n\r\n"; - fwrite($fp, $out); - while (!feof($fp)) - { - $response .= @fgets($fp); - } - fclose($fp); - return $response; - } + $response = ''; + $fp = fsockopen($this->ssl . $this->host, $this->port); + if (!$fp) { + return false; + } + + $out = 'GET ' . $url . ' HTTP/1.0' . "\r\n"; + $out .= 'Authorization: Basic ' . $this->auth . "\r\n"; + $out .= 'Connection: Close' . "\r\n\r\n"; + fwrite($fp, $out); + while (!feof($fp)) { + $response .= @fgets($fp); + } + fclose($fp); + return $response; + } } class emailAccount { - function emailAccount($host, $username, $password, $port, $ssl, $theme, $address) - { - $this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme); - if(strpos($address, '@')) - { - list($this->email, $this->domain) = explode('@', $address); - } - else - { - list($this->email, $this->domain) = array($address, ''); - } - } + function emailAccount($host, $username, $password, $port, $ssl, $theme, $address) + { + $this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme); + if (strpos($address, '@')) { + list($this->email, $this->domain) = explode('@', $address); + } + else { + list($this->email, $this->domain) = array($address, ''); + } + } /** * Change email account password @@ -105,16 +101,16 @@ class emailAccount * @param string $password email account password * @return bool */ - function setPassword($password) - { - $data['email'] = $this->email; - $data['domain'] = $this->domain; - $data['password'] = $password; - $response = $this->HTTP->getData('mail/dopasswdpop.html', $data); - if(strpos($response, 'success') && !strpos($response, 'failure')) - { - return true; - } - return false; - } + function setPassword($password) + { + $data['email'] = $this->email; + $data['domain'] = $this->domain; + $data['password'] = $password; + $response = $this->HTTP->getData('mail/dopasswdpop.html', $data); + + if (strpos($response, 'success') && !strpos($response, 'failure')) { + return true; + } + return false; + } } diff --git a/plugins/password/drivers/directadmin.php b/plugins/password/drivers/directadmin.php index 657c21eb4..fb156cea9 100644 --- a/plugins/password/drivers/directadmin.php +++ b/plugins/password/drivers/directadmin.php @@ -34,11 +34,11 @@ class rcube_directadmin_password $Socket->set_method('POST'); $Socket->query('/CMD_CHANGE_EMAIL_PASSWORD', array( - 'email' => $da_user, - 'oldpassword' => $da_curpass, - 'password1' => $da_newpass, - 'password2' => $da_newpass, - 'api' => '1' + 'email' => $da_user, + 'oldpassword' => $da_curpass, + 'password1' => $da_newpass, + 'password2' => $da_newpass, + 'api' => '1' )); $response = $Socket->fetch_parsed_body(); @@ -72,7 +72,7 @@ class rcube_directadmin_password class HTTPSocket { var $version = '2.8'; - + /* all vars are private except $error, $query_cache, and $doFollowLocationHeader */ var $method = 'GET'; @@ -173,7 +173,7 @@ class HTTPSocket { $location = parse_url($request); $this->connect($location['host'],$location['port']); $this->set_login($location['user'],$location['pass']); - + $request = $location['path']; $content = $location['query']; @@ -326,7 +326,7 @@ class HTTPSocket { } } - + list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2); if ($this->bind_host) @@ -365,7 +365,6 @@ class HTTPSocket { $this->query($headers['location']); } } - } function getTransferSpeed() @@ -449,8 +448,7 @@ class HTTPSocket { function fetch_header( $header = '' ) { $array_headers = preg_split("/\r\n/",$this->result_header); - - $array_return = array( 0 => $array_headers[0] ); + $array_return = array( 0 => $array_headers[0] ); unset($array_headers[0]); foreach ( $array_headers as $pair ) diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php index def07a175..f773335ac 100644 --- a/plugins/password/drivers/ldap.php +++ b/plugins/password/drivers/ldap.php @@ -85,7 +85,7 @@ class rcube_ldap_password // Crypt new samba password if ($smbpwattr && !($samba_pass = $this->hashPassword($passwd, 'samba'))) { - return PASSWORD_CRYPT_ERROR; + return PASSWORD_CRYPT_ERROR; } // Writing new crypted password to LDAP @@ -274,8 +274,8 @@ class rcube_ldap_password $cryptedPassword = hash('md4', rcube_charset_convert($passwordClear, RCMAIL_CHARSET, 'UTF-16LE')); $cryptedPassword = strtoupper($cryptedPassword); } else { - /* Your PHP install does not have the hash() function */ - return false; + /* Your PHP install does not have the hash() function */ + return false; } break; diff --git a/plugins/password/drivers/ldap_simple.php b/plugins/password/drivers/ldap_simple.php index e1daed9f3..01385f2d0 100644 --- a/plugins/password/drivers/ldap_simple.php +++ b/plugins/password/drivers/ldap_simple.php @@ -15,57 +15,57 @@ class rcube_ldap_simple_password { function save($curpass, $passwd) { - $rcmail = rcmail::get_instance(); - - // Connect - if (!$ds = ldap_connect($rcmail->config->get('password_ldap_host'), $rcmail->config->get('password_ldap_port'))) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } - - // Set protocol version - if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $rcmail->config->get('password_ldap_version'))) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } - - // Start TLS - if ($rcmail->config->get('password_ldap_starttls')) { - if (!ldap_start_tls($ds)) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } - } - - // Build user DN - if ($user_dn = $rcmail->config->get('password_ldap_userDN_mask')) { - $user_dn = $this->substitute_vars($user_dn); - } - else { - $user_dn = $this->search_userdn($rcmail, $ds); - } - - if (empty($user_dn)) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } - - // Connection method - switch ($rcmail->config->get('password_ldap_method')) { - case 'admin': - $binddn = $rcmail->config->get('password_ldap_adminDN'); - $bindpw = $rcmail->config->get('password_ldap_adminPW'); - break; - case 'user': - default: - $binddn = $user_dn; - $bindpw = $curpass; - break; - } - - $crypted_pass = $this->hash_password($passwd, $rcmail->config->get('password_ldap_encodage')); - $lchattr = $rcmail->config->get('password_ldap_lchattr'); - $pwattr = $rcmail->config->get('password_ldap_pwattr'); + $rcmail = rcmail::get_instance(); + + // Connect + if (!$ds = ldap_connect($rcmail->config->get('password_ldap_host'), $rcmail->config->get('password_ldap_port'))) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } + + // Set protocol version + if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $rcmail->config->get('password_ldap_version'))) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } + + // Start TLS + if ($rcmail->config->get('password_ldap_starttls')) { + if (!ldap_start_tls($ds)) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } + } + + // Build user DN + if ($user_dn = $rcmail->config->get('password_ldap_userDN_mask')) { + $user_dn = $this->substitute_vars($user_dn); + } + else { + $user_dn = $this->search_userdn($rcmail, $ds); + } + + if (empty($user_dn)) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } + + // Connection method + switch ($rcmail->config->get('password_ldap_method')) { + case 'admin': + $binddn = $rcmail->config->get('password_ldap_adminDN'); + $bindpw = $rcmail->config->get('password_ldap_adminPW'); + break; + case 'user': + default: + $binddn = $user_dn; + $bindpw = $curpass; + break; + } + + $crypted_pass = $this->hash_password($passwd, $rcmail->config->get('password_ldap_encodage')); + $lchattr = $rcmail->config->get('password_ldap_lchattr'); + $pwattr = $rcmail->config->get('password_ldap_pwattr'); $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); $samba = $rcmail->config->get('password_ldap_samba'); @@ -76,28 +76,28 @@ class rcube_ldap_simple_password $smblchattr = 'sambaPwdLastSet'; } - // Crypt new password - if (!$crypted_pass) { - return PASSWORD_CRYPT_ERROR; - } + // Crypt new password + if (!$crypted_pass) { + return PASSWORD_CRYPT_ERROR; + } // Crypt new Samba password if ($smbpwattr && !($samba_pass = $this->hash_password($passwd, 'samba'))) { - return PASSWORD_CRYPT_ERROR; + return PASSWORD_CRYPT_ERROR; } - // Bind - if (!ldap_bind($ds, $binddn, $bindpw)) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } + // Bind + if (!ldap_bind($ds, $binddn, $bindpw)) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } - $entree[$pwattr] = $crypted_pass; + $entree[$pwattr] = $crypted_pass; - // Update PasswordLastChange Attribute if desired - if ($lchattr) { - $entree[$lchattr] = (int)(time() / 86400); - } + // Update PasswordLastChange Attribute if desired + if ($lchattr) { + $entree[$lchattr] = (int)(time() / 86400); + } // Update Samba password if ($smbpwattr) { @@ -109,14 +109,14 @@ class rcube_ldap_simple_password $entree[$smblchattr] = time(); } - if (!ldap_modify($ds, $user_dn, $entree)) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } + if (!ldap_modify($ds, $user_dn, $entree)) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } - // All done, no error - ldap_unbind($ds); - return PASSWORD_SUCCESS; + // All done, no error + ldap_unbind($ds); + return PASSWORD_SUCCESS; } /** @@ -126,22 +126,22 @@ class rcube_ldap_simple_password */ function search_userdn($rcmail, $ds) { - /* Bind */ - if (!ldap_bind($ds, $rcmail->config->get('password_ldap_searchDN'), $rcmail->config->get('password_ldap_searchPW'))) { - return false; - } - - /* Search for the DN */ - if (!$sr = ldap_search($ds, $rcmail->config->get('password_ldap_search_base'), $this->substitute_vars($rcmail->config->get('password_ldap_search_filter')))) { - return false; - } - - /* If no or more entries were found, return false */ - if (ldap_count_entries($ds, $sr) != 1) { - return false; - } - - return ldap_get_dn($ds, ldap_first_entry($ds, $sr)); + /* Bind */ + if (!ldap_bind($ds, $rcmail->config->get('password_ldap_searchDN'), $rcmail->config->get('password_ldap_searchPW'))) { + return false; + } + + /* Search for the DN */ + if (!$sr = ldap_search($ds, $rcmail->config->get('password_ldap_search_base'), $this->substitute_vars($rcmail->config->get('password_ldap_search_filter')))) { + return false; + } + + /* If no or more entries were found, return false */ + if (ldap_count_entries($ds, $sr) != 1) { + return false; + } + + return ldap_get_dn($ds, ldap_first_entry($ds, $sr)); } /** @@ -150,22 +150,22 @@ class rcube_ldap_simple_password */ function substitute_vars($str) { - $str = str_replace('%login', $_SESSION['username'], $str); - $str = str_replace('%l', $_SESSION['username'], $str); + $str = str_replace('%login', $_SESSION['username'], $str); + $str = str_replace('%l', $_SESSION['username'], $str); - $parts = explode('@', $_SESSION['username']); + $parts = explode('@', $_SESSION['username']); - if (count($parts) == 2) { + if (count($parts) == 2) { $dc = 'dc='.strtr($parts[1], array('.' => ',dc=')); // hierarchal domain string - $str = str_replace('%name', $parts[0], $str); + $str = str_replace('%name', $parts[0], $str); $str = str_replace('%n', $parts[0], $str); $str = str_replace('%dc', $dc, $str); - $str = str_replace('%domain', $parts[1], $str); - $str = str_replace('%d', $parts[1], $str); - } + $str = str_replace('%domain', $parts[1], $str); + $str = str_replace('%d', $parts[1], $str); + } - return $str; + return $str; } /** @@ -176,83 +176,83 @@ class rcube_ldap_simple_password */ function hash_password($password_clear, $encodage_type) { - $encodage_type = strtolower($encodage_type); - switch ($encodage_type) { - case 'crypt': - $crypted_password = '{CRYPT}' . crypt($password_clear, $this->random_salt(2)); - break; - case 'ext_des': - /* Extended DES crypt. see OpenBSD crypt man page */ - if (!defined('CRYPT_EXT_DES') || CRYPT_EXT_DES == 0) { - /* Your system crypt library does not support extended DES encryption */ - return false; - } - $crypted_password = '{CRYPT}' . crypt($password_clear, '_' . $this->random_salt(8)); - break; - case 'md5crypt': - if (!defined('CRYPT_MD5') || CRYPT_MD5 == 0) { - /* Your system crypt library does not support md5crypt encryption */ - return false; - } - $crypted_password = '{CRYPT}' . crypt($password_clear, '$1$' . $this->random_salt(9)); - break; - case 'blowfish': - if (!defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) { - /* Your system crypt library does not support blowfish encryption */ - return false; - } - /* Hardcoded to second blowfish version and set number of rounds */ - $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . $this->random_salt(13)); - break; - case 'md5': - $crypted_password = '{MD5}' . base64_encode(pack('H*', md5($password_clear))); - break; - case 'sha': - if (function_exists('sha1')) { - /* Use PHP 4.3.0+ sha1 function, if it is available */ - $crypted_password = '{SHA}' . base64_encode(pack('H*', sha1($password_clear))); - } else if (function_exists('mhash')) { - $crypted_password = '{SHA}' . base64_encode(mhash(MHASH_SHA1, $password_clear)); - } else { - /* Your PHP install does not have the mhash() function */ - return false; - } - break; - case 'ssha': - if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) { - mt_srand((double) microtime() * 1000000 ); - $salt = mhash_keygen_s2k(MHASH_SHA1, $password_clear, substr(pack('h*', md5(mt_rand())), 0, 8), 4); - $crypted_password = '{SSHA}' . base64_encode(mhash(MHASH_SHA1, $password_clear . $salt) . $salt); - } else { - /* Your PHP install does not have the mhash() function */ - return false; - } - break; - case 'smd5': - if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) { - mt_srand((double) microtime() * 1000000 ); - $salt = mhash_keygen_s2k(MHASH_MD5, $password_clear, substr(pack('h*', md5(mt_rand())), 0, 8), 4); - $crypted_password = '{SMD5}' . base64_encode(mhash(MHASH_MD5, $password_clear . $salt) . $salt); - } else { - /* Your PHP install does not have the mhash() function */ - return false; - } - break; + $encodage_type = strtolower($encodage_type); + switch ($encodage_type) { + case 'crypt': + $crypted_password = '{CRYPT}' . crypt($password_clear, $this->random_salt(2)); + break; + case 'ext_des': + /* Extended DES crypt. see OpenBSD crypt man page */ + if (!defined('CRYPT_EXT_DES') || CRYPT_EXT_DES == 0) { + /* Your system crypt library does not support extended DES encryption */ + return false; + } + $crypted_password = '{CRYPT}' . crypt($password_clear, '_' . $this->random_salt(8)); + break; + case 'md5crypt': + if (!defined('CRYPT_MD5') || CRYPT_MD5 == 0) { + /* Your system crypt library does not support md5crypt encryption */ + return false; + } + $crypted_password = '{CRYPT}' . crypt($password_clear, '$1$' . $this->random_salt(9)); + break; + case 'blowfish': + if (!defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) { + /* Your system crypt library does not support blowfish encryption */ + return false; + } + /* Hardcoded to second blowfish version and set number of rounds */ + $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . $this->random_salt(13)); + break; + case 'md5': + $crypted_password = '{MD5}' . base64_encode(pack('H*', md5($password_clear))); + break; + case 'sha': + if (function_exists('sha1')) { + /* Use PHP 4.3.0+ sha1 function, if it is available */ + $crypted_password = '{SHA}' . base64_encode(pack('H*', sha1($password_clear))); + } else if (function_exists('mhash')) { + $crypted_password = '{SHA}' . base64_encode(mhash(MHASH_SHA1, $password_clear)); + } else { + /* Your PHP install does not have the mhash() function */ + return false; + } + break; + case 'ssha': + if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) { + mt_srand((double) microtime() * 1000000 ); + $salt = mhash_keygen_s2k(MHASH_SHA1, $password_clear, substr(pack('h*', md5(mt_rand())), 0, 8), 4); + $crypted_password = '{SSHA}' . base64_encode(mhash(MHASH_SHA1, $password_clear . $salt) . $salt); + } else { + /* Your PHP install does not have the mhash() function */ + return false; + } + break; + case 'smd5': + if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) { + mt_srand((double) microtime() * 1000000 ); + $salt = mhash_keygen_s2k(MHASH_MD5, $password_clear, substr(pack('h*', md5(mt_rand())), 0, 8), 4); + $crypted_password = '{SMD5}' . base64_encode(mhash(MHASH_MD5, $password_clear . $salt) . $salt); + } else { + /* Your PHP install does not have the mhash() function */ + return false; + } + break; case 'samba': if (function_exists('hash')) { $crypted_password = hash('md4', rcube_charset_convert($password_clear, RCMAIL_CHARSET, 'UTF-16LE')); $crypted_password = strtoupper($crypted_password); } else { - /* Your PHP install does not have the hash() function */ - return false; + /* Your PHP install does not have the hash() function */ + return false; } break; - case 'clear': - default: - $crypted_password = $password_clear; - } + case 'clear': + default: + $crypted_password = $password_clear; + } - return $crypted_password; + return $crypted_password; } /** @@ -263,14 +263,14 @@ class rcube_ldap_simple_password */ function random_salt($length) { - $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './'; - $str = ''; - // mt_srand((double)microtime() * 1000000); + $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './'; + $str = ''; + // mt_srand((double)microtime() * 1000000); - while (strlen($str) < $length) { - $str .= substr($possible, (rand() % strlen($possible)), 1); - } + while (strlen($str) < $length) { + $str .= substr($possible, (rand() % strlen($possible)), 1); + } - return $str; + return $str; } } diff --git a/plugins/password/drivers/smb.php b/plugins/password/drivers/smb.php index 138313be8..88021156f 100644 --- a/plugins/password/drivers/smb.php +++ b/plugins/password/drivers/smb.php @@ -56,4 +56,3 @@ class rcube_smb_password } } -?> diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php index 8bdcabf83..b08833dbf 100644 --- a/plugins/password/drivers/sql.php +++ b/plugins/password/drivers/sql.php @@ -20,11 +20,11 @@ class rcube_sql_password $sql = 'SELECT update_passwd(%c, %u)'; if ($dsn = $rcmail->config->get('password_db_dsn')) { - // #1486067: enable new_link option - if (is_array($dsn) && empty($dsn['new_link'])) - $dsn['new_link'] = true; - else if (!is_array($dsn) && !preg_match('/\?new_link=true/', $dsn)) - $dsn .= '?new_link=true'; + // #1486067: enable new_link option + if (is_array($dsn) && empty($dsn['new_link'])) + $dsn['new_link'] = true; + else if (!is_array($dsn) && !preg_match('/\?new_link=true/', $dsn)) + $dsn .= '?new_link=true'; $db = rcube_db::factory($dsn, '', false); $db->set_debug((bool)$rcmail->config->get('sql_debug')); @@ -48,7 +48,7 @@ class rcube_sql_password else if (CRYPT_STD_DES) $crypt_hash = 'des'; } - + switch ($crypt_hash) { case 'md5': @@ -77,7 +77,7 @@ class rcube_sql_password //Restrict the character set used as salt (#1488136) $seedchars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; for ($i = 0; $i < $len ; $i++) { - $salt .= $seedchars[rand(0, 63)]; + $salt .= $seedchars[rand(0, 63)]; } $sql = str_replace('%c', $db->quote(crypt($passwd, $salt_hashindicator ? $salt_hashindicator .$salt.'$' : $salt)), $sql); @@ -116,30 +116,30 @@ class rcube_sql_password // hashed passwords if (preg_match('/%[n|q]/', $sql)) { - if (!extension_loaded('hash')) { - raise_error(array( - 'code' => 600, - 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Password plugin: 'hash' extension not loaded!" - ), true, false); - - return PASSWORD_ERROR; - } - - if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm')))) + if (!extension_loaded('hash')) { + raise_error(array( + 'code' => 600, + 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Password plugin: 'hash' extension not loaded!" + ), true, false); + + return PASSWORD_ERROR; + } + + if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm')))) $hash_algo = 'sha1'; - $hash_passwd = hash($hash_algo, $passwd); + $hash_passwd = hash($hash_algo, $passwd); $hash_curpass = hash($hash_algo, $curpass); - if ($rcmail->config->get('password_hash_base64')) { + if ($rcmail->config->get('password_hash_base64')) { $hash_passwd = base64_encode(pack('H*', $hash_passwd)); $hash_curpass = base64_encode(pack('H*', $hash_curpass)); } - $sql = str_replace('%n', $db->quote($hash_passwd, 'text'), $sql); - $sql = str_replace('%q', $db->quote($hash_curpass, 'text'), $sql); + $sql = str_replace('%n', $db->quote($hash_passwd, 'text'), $sql); + $sql = str_replace('%q', $db->quote($hash_curpass, 'text'), $sql); } // Handle clear text passwords securely (#1487034) @@ -183,16 +183,16 @@ class rcube_sql_password $res = $db->query($sql, $sql_vars); if (!$db->is_error()) { - if (strtolower(substr(trim($query),0,6))=='select') { - if ($result = $db->fetch_array($res)) - return PASSWORD_SUCCESS; - } else { + if (strtolower(substr(trim($query),0,6))=='select') { + if ($result = $db->fetch_array($res)) + return PASSWORD_SUCCESS; + } else { // This is the good case: 1 row updated - if ($db->affected_rows($res) == 1) - return PASSWORD_SUCCESS; + if ($db->affected_rows($res) == 1) + return PASSWORD_SUCCESS; // @TODO: Some queries don't affect any rows // Should we assume a success if there was no error? - } + } } return PASSWORD_ERROR; diff --git a/plugins/password/drivers/virtualmin.php b/plugins/password/drivers/virtualmin.php index 69f1475d4..d2b765a9e 100644 --- a/plugins/password/drivers/virtualmin.php +++ b/plugins/password/drivers/virtualmin.php @@ -48,10 +48,10 @@ class rcube_virtualmin_password $pieces = explode("_", $username); $domain = $pieces[0]; break; - case 8: // domain taken from alias, username left as it was - $email = $rcmail->user->data['alias']; - $domain = substr(strrchr($email, "@"), 1); - break; + case 8: // domain taken from alias, username left as it was + $email = $rcmail->user->data['alias']; + $domain = substr(strrchr($email, "@"), 1); + break; default: // username@domain $domain = substr(strrchr($username, "@"), 1); } diff --git a/plugins/password/drivers/vpopmaild.php b/plugins/password/drivers/vpopmaild.php index 510cf3338..6c1a9ee9d 100644 --- a/plugins/password/drivers/vpopmaild.php +++ b/plugins/password/drivers/vpopmaild.php @@ -19,7 +19,7 @@ class rcube_vpopmaild_password $vpopmaild = new Net_Socket(); if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'), - $rcmail->config->get('password_vpopmaild_port'), null))) { + $rcmail->config->get('password_vpopmaild_port'), null))) { return PASSWORD_CONNECT_ERROR; } |