Changeset 5902 in subversion
- Timestamp:
- Feb 24, 2012 5:17:19 AM (15 months ago)
- Location:
- trunk/plugins/password
- Files:
-
- 16 edited
-
drivers/chpasswd.php (modified) (1 diff)
-
drivers/cpanel.php (modified) (4 diffs)
-
drivers/directadmin.php (modified) (7 diffs)
-
drivers/hmail.php (modified) (1 diff)
-
drivers/ldap.php (modified) (5 diffs)
-
drivers/ldap_simple.php (modified) (6 diffs)
-
drivers/pam.php (modified) (2 diffs)
-
drivers/poppassd.php (modified) (1 diff)
-
drivers/sasl.php (modified) (1 diff)
-
drivers/sql.php (modified) (1 diff)
-
drivers/virtualmin.php (modified) (2 diffs)
-
drivers/vpopmaild.php (modified) (1 diff)
-
drivers/ximss.php (modified) (2 diffs)
-
drivers/xmail.php (modified) (2 diffs)
-
package.xml (modified) (3 diffs)
-
password.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/password/drivers/chpasswd.php
r4291 r5902 9 9 * For installation instructions please read the README file. 10 10 * 11 * @version 1.011 * @version 2.0 12 12 * @author Alex Cartwright <acartwright@mutinydesign.co.uk) 13 13 */ 14 14 15 function password_save($currpass, $newpass) 15 class rcube_chpasswd_password 16 16 { 17 $cmd = rcmail::get_instance()->config->get('password_chpasswd_cmd'); 18 $username = $_SESSION['username']; 17 public function save($currpass, $newpass) 18 { 19 $cmd = rcmail::get_instance()->config->get('password_chpasswd_cmd'); 20 $username = $_SESSION['username']; 19 21 20 $handle = popen($cmd, "w");21 fwrite($handle, "$username:$newpass\n");22 $handle = popen($cmd, "w"); 23 fwrite($handle, "$username:$newpass\n"); 22 24 23 if (pclose($handle) == 0) { 24 return PASSWORD_SUCCESS; 25 if (pclose($handle) == 0) { 26 return PASSWORD_SUCCESS; 27 } 28 else { 29 raise_error(array( 30 'code' => 600, 31 'type' => 'php', 32 'file' => __FILE__, 'line' => __LINE__, 33 'message' => "Password plugin: Unable to execute $cmd" 34 ), true, false); 35 } 36 37 return PASSWORD_ERROR; 25 38 } 26 else {27 raise_error(array(28 'code' => 600,29 'type' => 'php',30 'file' => __FILE__, 'line' => __LINE__,31 'message' => "Password plugin: Unable to execute $cmd"32 ), true, false);33 }34 35 return PASSWORD_ERROR;36 39 } -
trunk/plugins/password/drivers/cpanel.php
r3008 r5902 8 8 * 9 9 * This driver has been tested with Hostmonster hosting and seems to work fine. 10 11 10 * 12 * @version 1.011 * @version 2.0 13 12 * @author Fulvio Venturelli <fulvio@venturelli.org> 14 13 */ 14 15 class rcube_cpanel_password 16 { 17 public function save($curpas, $newpass) 18 { 19 $rcmail = rcmail::get_instance(); 20 21 // Create a cPanel email object 22 $cPanel = new emailAccount($rcmail->config->get('password_cpanel_host'), 23 $rcmail->config->get('password_cpanel_username'), 24 $rcmail->config->get('password_cpanel_password'), 25 $rcmail->config->get('password_cpanel_port'), 26 $rcmail->config->get('password_cpanel_ssl'), 27 $rcmail->config->get('password_cpanel_theme'), 28 $_SESSION['username'] ); 29 30 if ($cPanel->setPassword($newpass)){ 31 return PASSWORD_SUCCESS; 32 } 33 else { 34 return PASSWORD_ERROR; 35 } 36 } 37 } 38 15 39 16 40 class HTTP … … 61 85 62 86 class emailAccount 63 { 87 { 64 88 function emailAccount($host, $username, $password, $port, $ssl, $theme, $address) 65 89 { … … 75 99 } 76 100 77 /*78 * Change email account password79 *80 * Returns true on success or false on failure.81 * @param string $password email account password82 * @return bool83 */101 /** 102 * Change email account password 103 * 104 * Returns true on success or false on failure. 105 * @param string $password email account password 106 * @return bool 107 */ 84 108 function setPassword($password) 85 109 { … … 95 119 } 96 120 } 97 98 99 function password_save($curpas, $newpass)100 {101 $rcmail = rcmail::get_instance();102 103 // Create a cPanel email object104 $cPanel = new emailAccount($rcmail->config->get('password_cpanel_host'),105 $rcmail->config->get('password_cpanel_username'),106 $rcmail->config->get('password_cpanel_password'),107 $rcmail->config->get('password_cpanel_port'),108 $rcmail->config->get('password_cpanel_ssl'),109 $rcmail->config->get('password_cpanel_theme'),110 $_SESSION['username'] );111 112 if ($cPanel->setPassword($newpass)){113 return PASSWORD_SUCCESS;114 }115 else116 {117 return PASSWORD_ERROR;118 }119 }120 121 ?> -
trunk/plugins/password/drivers/directadmin.php
r4726 r5902 6 6 * Driver to change passwords via DirectAdmin Control Panel 7 7 * 8 * @version 1.28 * @version 2.0 9 9 * @author Victor Benincasa <vbenincasa@gmail.com> 10 10 * 11 11 */ 12 12 13 14 function password_save($curpass, $passwd){ 15 16 $rcmail = rcmail::get_instance(); 17 $Socket = new HTTPSocket; 18 19 $da_user = $_SESSION['username']; 20 $da_curpass = $curpass; 21 $da_newpass = $passwd; 22 $da_host = $rcmail->config->get('password_directadmin_host'); 23 $da_port = $rcmail->config->get('password_directadmin_port'); 24 25 if(strpos($da_user, '@') === false) return array('code' => PASSWORD_ERROR, 'message' => 'Change the SYSTEM user password through control panel!'); 26 27 $da_host = str_replace('%h', $_SESSION['imap_host'], $da_host); 28 $da_host = str_replace('%d', $rcmail->user->get_username('domain'), $da_host); 29 30 $Socket->connect($da_host,$da_port); 31 $Socket->set_method('POST'); 32 $Socket->query('/CMD_CHANGE_EMAIL_PASSWORD', 33 array( 34 'email' => $da_user, 35 'oldpassword' => $da_curpass, 36 'password1' => $da_newpass, 37 'password2' => $da_newpass, 38 'api' => '1' 39 )); 40 $response = $Socket->fetch_parsed_body(); 41 42 //DEBUG 43 //console("Password Plugin: [USER: $da_user] [HOST: $da_host] - Response: [SOCKET: ".$Socket->result_status_code."] [DA ERROR: ".strip_tags($response['error'])."] [TEXT: ".$response[text]."]"); 44 45 if($Socket->result_status_code != 200) 46 return array('code' => PASSWORD_CONNECT_ERROR, 'message' => $Socket->error[0]); 47 elseif($response['error'] == 1) 48 return array('code' => PASSWORD_ERROR, 'message' => strip_tags($response['text'])); 49 else 50 return PASSWORD_SUCCESS; 51 13 class rcube_directadmin_password 14 { 15 public function save($curpass, $passwd) 16 { 17 $rcmail = rcmail::get_instance(); 18 $Socket = new HTTPSocket; 19 20 $da_user = $_SESSION['username']; 21 $da_curpass = $curpass; 22 $da_newpass = $passwd; 23 $da_host = $rcmail->config->get('password_directadmin_host'); 24 $da_port = $rcmail->config->get('password_directadmin_port'); 25 26 if (strpos($da_user, '@') === false) { 27 return array('code' => PASSWORD_ERROR, 'message' => 'Change the SYSTEM user password through control panel!'); 28 } 29 30 $da_host = str_replace('%h', $_SESSION['imap_host'], $da_host); 31 $da_host = str_replace('%d', $rcmail->user->get_username('domain'), $da_host); 32 33 $Socket->connect($da_host,$da_port); 34 $Socket->set_method('POST'); 35 $Socket->query('/CMD_CHANGE_EMAIL_PASSWORD', 36 array( 37 'email' => $da_user, 38 'oldpassword' => $da_curpass, 39 'password1' => $da_newpass, 40 'password2' => $da_newpass, 41 'api' => '1' 42 )); 43 $response = $Socket->fetch_parsed_body(); 44 45 //DEBUG 46 //console("Password Plugin: [USER: $da_user] [HOST: $da_host] - Response: [SOCKET: ".$Socket->result_status_code."] [DA ERROR: ".strip_tags($response['error'])."] [TEXT: ".$response[text]."]"); 47 48 if($Socket->result_status_code != 200) 49 return array('code' => PASSWORD_CONNECT_ERROR, 'message' => $Socket->error[0]); 50 elseif($response['error'] == 1) 51 return array('code' => PASSWORD_ERROR, 'message' => strip_tags($response['text'])); 52 else 53 return PASSWORD_SUCCESS; 54 } 52 55 } 53 56 … … 69 72 70 73 var $version = '2.7'; 71 74 72 75 /* all vars are private except $error, $query_cache, and $doFollowLocationHeader */ 73 76 … … 170 173 $this->connect($location['host'],$location['port']); 171 174 $this->set_login($location['user'],$location['pass']); 172 175 173 176 $request = $location['path']; 174 177 $content = $location['query']; … … 323 326 324 327 } 325 328 326 329 list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2); 327 330 … … 362 365 } 363 366 } 364 365 367 } 366 368 … … 446 448 { 447 449 $array_headers = preg_split("/\r\n/",$this->result_header); 448 450 449 451 $array_return = array( 0 => $array_headers[0] ); 450 452 unset($array_headers[0]); … … 486 488 487 489 } 488 489 ?> -
trunk/plugins/password/drivers/hmail.php
r4183 r5902 4 4 * hMailserver password driver 5 5 * 6 * @version 1.3 - 05.11.20106 * @version 2.0 7 7 * @author Roland 'rosali' Liebl <myroundcube@mail4us.net> 8 8 * 9 9 */ 10 10 11 function password_save($curpass, $passwd) 11 class rcube_hmail_password 12 12 { 13 $rcmail = rcmail::get_instance(); 13 public function save($curpass, $passwd) 14 { 15 $rcmail = rcmail::get_instance(); 14 16 15 if ($curpass == '' || $passwd == '') 16 return PASSWORD_ERROR; 17 if ($curpass == '' || $passwd == '') { 18 return PASSWORD_ERROR; 19 } 17 20 18 try {19 $remote = $rcmail->config->get('hmailserver_remote_dcom', false);20 if ($remote)21 $obApp = new COM("hMailServer.Application", $rcmail->config->get('hmailserver_server'));22 else23 $obApp = new COM("hMailServer.Application");24 }25 catch (Exception $e) {26 write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));27 write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");28 return PASSWORD_ERROR;29 }21 try { 22 $remote = $rcmail->config->get('hmailserver_remote_dcom', false); 23 if ($remote) 24 $obApp = new COM("hMailServer.Application", $rcmail->config->get('hmailserver_server')); 25 else 26 $obApp = new COM("hMailServer.Application"); 27 } 28 catch (Exception $e) { 29 write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage()))); 30 write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set."); 31 return PASSWORD_ERROR; 32 } 30 33 31 $username = $rcmail->user->data['username'];32 if (strstr($username,'@')){33 $temparr = explode('@', $username);34 $domain = $temparr[1];35 }36 else {37 $domain = $rcmail->config->get('username_domain',false);38 if (!$domain) {39 write_log('errors','Plugin password (hmail driver): $rcmail_config[\'username_domain\'] is not defined.');40 write_log('errors','Plugin password (hmail driver): Hint: Use hmail_login plugin (http://myroundcube.googlecode.com');41 return PASSWORD_ERROR;42 }43 $username = $username . "@" . $domain;44 }34 $username = $rcmail->user->data['username']; 35 if (strstr($username,'@')){ 36 $temparr = explode('@', $username); 37 $domain = $temparr[1]; 38 } 39 else { 40 $domain = $rcmail->config->get('username_domain',false); 41 if (!$domain) { 42 write_log('errors','Plugin password (hmail driver): $rcmail_config[\'username_domain\'] is not defined.'); 43 write_log('errors','Plugin password (hmail driver): Hint: Use hmail_login plugin (http://myroundcube.googlecode.com'); 44 return PASSWORD_ERROR; 45 } 46 $username = $username . "@" . $domain; 47 } 45 48 46 $obApp->Authenticate($username, $curpass); 47 try { 48 $obDomain = $obApp->Domains->ItemByName($domain); 49 $obAccount = $obDomain->Accounts->ItemByAddress($username); 50 $obAccount->Password = $passwd; 51 $obAccount->Save(); 52 return PASSWORD_SUCCESS; 53 } 54 catch (Exception $e) { 55 write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage()))); 56 write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set."); 57 return PASSWORD_ERROR; 49 $obApp->Authenticate($username, $curpass); 50 try { 51 $obDomain = $obApp->Domains->ItemByName($domain); 52 $obAccount = $obDomain->Accounts->ItemByAddress($username); 53 $obAccount->Password = $passwd; 54 $obAccount->Save(); 55 return PASSWORD_SUCCESS; 56 } 57 catch (Exception $e) { 58 write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage()))); 59 write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set."); 60 return PASSWORD_ERROR; 61 } 58 62 } 59 63 } 60 61 ?> -
trunk/plugins/password/drivers/ldap.php
r5467 r5902 7 7 * This driver use the PEAR Net_LDAP2 class (http://pear.php.net/package/Net_LDAP2). 8 8 * 9 * @version 1.1 (2010-04-07)9 * @version 2.0 10 10 * @author Edouard MOREAU <edouard.moreau@ensma.fr> 11 11 * 12 * functionhashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).13 * functionrandomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).12 * method hashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/). 13 * method randomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/). 14 14 * 15 15 */ 16 16 17 function password_save($curpass, $passwd) 17 class rcube_ldap_password 18 18 { 19 $rcmail = rcmail::get_instance(); 20 require_once ('Net/LDAP2.php'); 21 22 // Building user DN 23 if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) { 24 $userDN = substitute_vars($userDN); 25 } else { 26 $userDN = search_userdn($rcmail); 27 } 28 29 if (empty($userDN)) { 30 return PASSWORD_CONNECT_ERROR; 31 } 32 33 // Connection Method 34 switch($rcmail->config->get('password_ldap_method')) { 35 case 'admin': 36 $binddn = $rcmail->config->get('password_ldap_adminDN'); 37 $bindpw = $rcmail->config->get('password_ldap_adminPW'); 38 break; 39 case 'user': 40 default: 41 $binddn = $userDN; 42 $bindpw = $curpass; 43 break; 44 } 45 46 // Configuration array 47 $ldapConfig = array ( 48 'binddn' => $binddn, 49 'bindpw' => $bindpw, 50 'basedn' => $rcmail->config->get('password_ldap_basedn'), 51 'host' => $rcmail->config->get('password_ldap_host'), 52 'port' => $rcmail->config->get('password_ldap_port'), 53 'starttls' => $rcmail->config->get('password_ldap_starttls'), 54 'version' => $rcmail->config->get('password_ldap_version'), 55 ); 56 57 // Connecting using the configuration array 58 $ldap = Net_LDAP2::connect($ldapConfig); 59 60 // Checking for connection error 61 if (PEAR::isError($ldap)) { 62 return PASSWORD_CONNECT_ERROR; 63 } 64 65 $crypted_pass = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage')); 66 $force = $rcmail->config->get('password_ldap_force_replace'); 67 $pwattr = $rcmail->config->get('password_ldap_pwattr'); 68 $lchattr = $rcmail->config->get('password_ldap_lchattr'); 69 $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); 70 $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); 71 $samba = $rcmail->config->get('password_ldap_samba'); 72 73 // Support password_ldap_samba option for backward compat. 74 if ($samba && !$smbpwattr) { 75 $smbpwattr = 'sambaNTPassword'; 76 $smblchattr = 'sambaPwdLastSet'; 77 } 78 79 // Crypt new password 80 if (!$crypted_pass) { 81 return PASSWORD_CRYPT_ERROR; 82 } 83 84 // Crypt new samba password 85 if ($smbpwattr && !($samba_pass = hashPassword($passwd, 'samba'))) { 86 return PASSWORD_CRYPT_ERROR; 87 } 88 89 // Writing new crypted password to LDAP 90 $userEntry = $ldap->getEntry($userDN); 91 if (Net_LDAP2::isError($userEntry)) { 92 return PASSWORD_CONNECT_ERROR; 93 } 94 95 if (!$userEntry->replace(array($pwattr => $crypted_pass), $force)) { 96 return PASSWORD_CONNECT_ERROR; 97 } 98 99 // Updating PasswordLastChange Attribute if desired 100 if ($lchattr) { 101 $current_day = (int)(time() / 86400); 102 if (!$userEntry->replace(array($lchattr => $current_day), $force)) { 103 return PASSWORD_CONNECT_ERROR; 104 } 105 } 106 107 // Update Samba password and last change fields 108 if ($smbpwattr) { 109 $userEntry->replace(array($smbpwattr => $samba_pass), $force); 110 } 111 // Update Samba password last change field 112 if ($smblchattr) { 113 $userEntry->replace(array($smblchattr => time()), $force); 114 } 115 116 if (Net_LDAP2::isError($userEntry->update())) { 117 return PASSWORD_CONNECT_ERROR; 118 } 119 120 // All done, no error 121 return PASSWORD_SUCCESS; 122 } 123 124 /** 125 * Bind with searchDN and searchPW and search for the user's DN. 126 * Use search_base and search_filter defined in config file. 127 * Return the found DN. 128 */ 129 function search_userdn($rcmail) 130 { 131 $ldapConfig = array ( 132 'binddn' => $rcmail->config->get('password_ldap_searchDN'), 133 'bindpw' => $rcmail->config->get('password_ldap_searchPW'), 134 'basedn' => $rcmail->config->get('password_ldap_basedn'), 135 'host' => $rcmail->config->get('password_ldap_host'), 136 'port' => $rcmail->config->get('password_ldap_port'), 137 'starttls' => $rcmail->config->get('password_ldap_starttls'), 138 'version' => $rcmail->config->get('password_ldap_version'), 139 ); 140 141 $ldap = Net_LDAP2::connect($ldapConfig); 142 143 if (PEAR::isError($ldap)) { 144 return ''; 145 } 146 147 $base = $rcmail->config->get('password_ldap_search_base'); 148 $filter = substitute_vars($rcmail->config->get('password_ldap_search_filter')); 149 $options = array ( 19 public function save($curpass, $passwd) 20 { 21 $rcmail = rcmail::get_instance(); 22 require_once 'Net/LDAP2.php'; 23 24 // Building user DN 25 if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) { 26 $userDN = $this->substitute_vars($userDN); 27 } else { 28 $userDN = $this->search_userdn($rcmail); 29 } 30 31 if (empty($userDN)) { 32 return PASSWORD_CONNECT_ERROR; 33 } 34 35 // Connection Method 36 switch($rcmail->config->get('password_ldap_method')) { 37 case 'admin': 38 $binddn = $rcmail->config->get('password_ldap_adminDN'); 39 $bindpw = $rcmail->config->get('password_ldap_adminPW'); 40 break; 41 case 'user': 42 default: 43 $binddn = $userDN; 44 $bindpw = $curpass; 45 break; 46 } 47 48 // Configuration array 49 $ldapConfig = array ( 50 'binddn' => $binddn, 51 'bindpw' => $bindpw, 52 'basedn' => $rcmail->config->get('password_ldap_basedn'), 53 'host' => $rcmail->config->get('password_ldap_host'), 54 'port' => $rcmail->config->get('password_ldap_port'), 55 'starttls' => $rcmail->config->get('password_ldap_starttls'), 56 'version' => $rcmail->config->get('password_ldap_version'), 57 ); 58 59 // Connecting using the configuration array 60 $ldap = Net_LDAP2::connect($ldapConfig); 61 62 // Checking for connection error 63 if (PEAR::isError($ldap)) { 64 return PASSWORD_CONNECT_ERROR; 65 } 66 67 $crypted_pass = $this->hashPassword($passwd, $rcmail->config->get('password_ldap_encodage')); 68 $force = $rcmail->config->get('password_ldap_force_replace'); 69 $pwattr = $rcmail->config->get('password_ldap_pwattr'); 70 $lchattr = $rcmail->config->get('password_ldap_lchattr'); 71 $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); 72 $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); 73 $samba = $rcmail->config->get('password_ldap_samba'); 74 75 // Support password_ldap_samba option for backward compat. 76 if ($samba && !$smbpwattr) { 77 $smbpwattr = 'sambaNTPassword'; 78 $smblchattr = 'sambaPwdLastSet'; 79 } 80 81 // Crypt new password 82 if (!$crypted_pass) { 83 return PASSWORD_CRYPT_ERROR; 84 } 85 86 // Crypt new samba password 87 if ($smbpwattr && !($samba_pass = $this->hashPassword($passwd, 'samba'))) { 88 return PASSWORD_CRYPT_ERROR; 89 } 90 91 // Writing new crypted password to LDAP 92 $userEntry = $ldap->getEntry($userDN); 93 if (Net_LDAP2::isError($userEntry)) { 94 return PASSWORD_CONNECT_ERROR; 95 } 96 97 if (!$userEntry->replace(array($pwattr => $crypted_pass), $force)) { 98 return PASSWORD_CONNECT_ERROR; 99 } 100 101 // Updating PasswordLastChange Attribute if desired 102 if ($lchattr) { 103 $current_day = (int)(time() / 86400); 104 if (!$userEntry->replace(array($lchattr => $current_day), $force)) { 105 return PASSWORD_CONNECT_ERROR; 106 } 107 } 108 109 // Update Samba password and last change fields 110 if ($smbpwattr) { 111 $userEntry->replace(array($smbpwattr => $samba_pass), $force); 112 } 113 // Update Samba password last change field 114 if ($smblchattr) { 115 $userEntry->replace(array($smblchattr => time()), $force); 116 } 117 118 if (Net_LDAP2::isError($userEntry->update())) { 119 return PASSWORD_CONNECT_ERROR; 120 } 121 122 // All done, no error 123 return PASSWORD_SUCCESS; 124 } 125 126 /** 127 * Bind with searchDN and searchPW and search for the user's DN. 128 * Use search_base and search_filter defined in config file. 129 * Return the found DN. 130 */ 131 function search_userdn($rcmail) 132 { 133 $ldapConfig = array ( 134 'binddn' => $rcmail->config->get('password_ldap_searchDN'), 135 'bindpw' => $rcmail->config->get('password_ldap_searchPW'), 136 'basedn' => $rcmail->config->get('password_ldap_basedn'), 137 'host' => $rcmail->config->get('password_ldap_host'), 138 'port' => $rcmail->config->get('password_ldap_port'), 139 'starttls' => $rcmail->config->get('password_ldap_starttls'), 140 'version' => $rcmail->config->get('password_ldap_version'), 141 ); 142 143 $ldap = Net_LDAP2::connect($ldapConfig); 144 145 if (PEAR::isError($ldap)) { 146 return ''; 147 } 148 149 $base = $rcmail->config->get('password_ldap_search_base'); 150 $filter = $this->substitute_vars($rcmail->config->get('password_ldap_search_filter')); 151 $options = array ( 150 152 'scope' => 'sub', 151 153 'attributes' => array(), 152 ); 153 154 $result = $ldap->search($base, $filter, $options); 155 $ldap->done(); 156 if (PEAR::isError($result) || ($result->count() != 1)) { 157 return ''; 158 } 159 160 return $result->current()->dn(); 161 } 162 163 /** 164 * Substitute %login, %name, %domain, %dc in $str. 165 * See plugin config for details. 166 */ 167 function substitute_vars($str) 168 { 169 $rcmail = rcmail::get_instance(); 170 $domain = $rcmail->user->get_username('domain'); 171 $dc = 'dc='.strtr($domain, array('.' => ',dc=')); // hierarchal domain string 172 173 $str = str_replace(array( 174 '%login', 175 '%name', 176 '%domain', 177 '%dc', 178 ), array( 179 $_SESSION['username'], 180 $rcmail->user->get_username('local'), 181 $domain, 182 $dc, 183 ), $str 184 ); 185 186 return $str; 187 } 188 189 190 /** 191 * Code originaly from the phpLDAPadmin development team 192 * http://phpldapadmin.sourceforge.net/ 193 * 194 * Hashes a password and returns the hash based on the specified enc_type. 195 * 196 * @param string $passwordClear The password to hash in clear text. 197 * @param string $encodageType Standard LDAP encryption type which must be one of 198 * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear. 199 * @return string The hashed password. 200 * 201 */ 202 203 function hashPassword( $passwordClear, $encodageType ) 204 { 205 $encodageType = strtolower( $encodageType ); 206 switch( $encodageType ) { 207 case 'crypt': 208 $cryptedPassword = '{CRYPT}' . crypt($passwordClear,randomSalt(2)); 154 ); 155 156 $result = $ldap->search($base, $filter, $options); 157 $ldap->done(); 158 if (PEAR::isError($result) || ($result->count() != 1)) { 159 return ''; 160 } 161 162 return $result->current()->dn(); 163 } 164 165 /** 166 * Substitute %login, %name, %domain, %dc in $str. 167 * See plugin config for details. 168 */ 169 function substitute_vars($str) 170 { 171 $rcmail = rcmail::get_instance(); 172 $domain = $rcmail->user->get_username('domain'); 173 $dc = 'dc='.strtr($domain, array('.' => ',dc=')); // hierarchal domain string 174 175 $str = str_replace(array( 176 '%login', 177 '%name', 178 '%domain', 179 '%dc', 180 ), array( 181 $_SESSION['username'], 182 $rcmail->user->get_username('local'), 183 $domain, 184 $dc, 185 ), $str 186 ); 187 188 return $str; 189 } 190 191 /** 192 * Code originaly from the phpLDAPadmin development team 193 * http://phpldapadmin.sourceforge.net/ 194 * 195 * Hashes a password and returns the hash based on the specified enc_type. 196 * 197 * @param string $passwordClear The password to hash in clear text. 198 * @param string $encodageType Standard LDAP encryption type which must be one of 199 * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear. 200 * @return string The hashed password. 201 * 202 */ 203 function hashPassword( $passwordClear, $encodageType ) 204 { 205 $encodageType = strtolower( $encodageType ); 206 switch( $encodageType ) { 207 case 'crypt': 208 $cryptedPassword = '{CRYPT}' . crypt($passwordClear, $this->randomSalt(2)); 209 209 break; 210 210 … … 215 215 return FALSE; 216 216 } 217 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear, '_' . randomSalt(8) );217 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear, '_' . $this->randomSalt(8) ); 218 218 break; 219 219 … … 223 223 return FALSE; 224 224 } 225 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$1$' . randomSalt(9) );225 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$1$' . $this->randomSalt(9) ); 226 226 break; 227 227 … … 232 232 } 233 233 // hardcoded to second blowfish version and set number of rounds 234 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$2a$12$' . randomSalt(13) );234 $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$2a$12$' . $this->randomSalt(13) ); 235 235 break; 236 236 … … 283 283 default: 284 284 $cryptedPassword = $passwordClear; 285 } 286 287 return $cryptedPassword; 285 } 286 287 return $cryptedPassword; 288 } 289 290 /** 291 * Code originaly from the phpLDAPadmin development team 292 * http://phpldapadmin.sourceforge.net/ 293 * 294 * Used to generate a random salt for crypt-style passwords. Salt strings are used 295 * to make pre-built hash cracking dictionaries difficult to use as the hash algorithm uses 296 * not only the user's password but also a randomly generated string. The string is 297 * stored as the first N characters of the hash for reference of hashing algorithms later. 298 * 299 * --- added 20021125 by bayu irawan <bayuir@divnet.telkom.co.id> --- 300 * --- ammended 20030625 by S C Rigler <srigler@houston.rr.com> --- 301 * 302 * @param int $length The length of the salt string to generate. 303 * @return string The generated salt string. 304 */ 305 function randomSalt( $length ) 306 { 307 $possible = '0123456789'. 308 'abcdefghijklmnopqrstuvwxyz'. 309 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. 310 './'; 311 $str = ''; 312 // mt_srand((double)microtime() * 1000000); 313 314 while (strlen($str) < $length) 315 $str .= substr($possible, (rand() % strlen($possible)), 1); 316 317 return $str; 318 } 288 319 } 289 290 /**291 * Code originaly from the phpLDAPadmin development team292 * http://phpldapadmin.sourceforge.net/293 *294 * Used to generate a random salt for crypt-style passwords. Salt strings are used295 * to make pre-built hash cracking dictionaries difficult to use as the hash algorithm uses296 * not only the user's password but also a randomly generated string. The string is297 * stored as the first N characters of the hash for reference of hashing algorithms later.298 *299 * --- added 20021125 by bayu irawan <bayuir@divnet.telkom.co.id> ---300 * --- ammended 20030625 by S C Rigler <srigler@houston.rr.com> ---301 *302 * @param int $length The length of the salt string to generate.303 * @return string The generated salt string.304 */305 function randomSalt( $length )306 {307 $possible = '0123456789'.308 'abcdefghijklmnopqrstuvwxyz'.309 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.310 './';311 $str = '';312 // mt_srand((double)microtime() * 1000000);313 314 while (strlen($str) < $length)315 $str .= substr($possible, (rand() % strlen($possible)), 1);316 317 return $str;318 } -
trunk/plugins/password/drivers/ldap_simple.php
r5467 r5902 7 7 * This driver is based on Edouard's LDAP Password Driver, but does not 8 8 * require PEAR's Net_LDAP2 to be installed 9 * 10 * @version 1.0 (2010-07-31)9 * 10 * @version 2.0 11 11 * @author Wout Decre <wout@canodus.be> 12 12 */ 13 function password_save($curpass, $passwd) 13 14 class rcube_ldap_simple_password 14 15 { 15 $rcmail = rcmail::get_instance(); 16 17 // Connect 18 if (!$ds = ldap_connect($rcmail->config->get('password_ldap_host'), $rcmail->config->get('password_ldap_port'))) { 19 ldap_unbind($ds); 20 return PASSWORD_CONNECT_ERROR; 21 } 22 23 // Set protocol version 24 if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $rcmail->config->get('password_ldap_version'))) { 25 ldap_unbind($ds); 26 return PASSWORD_CONNECT_ERROR; 27 } 28 29 // Start TLS 30 if ($rcmail->config->get('password_ldap_starttls')) { 31 if (!ldap_start_tls($ds)) { 32 ldap_unbind($ds); 33 return PASSWORD_CONNECT_ERROR; 34 } 35 } 36 37 // Build user DN 38 if ($user_dn = $rcmail->config->get('password_ldap_userDN_mask')) { 39 $user_dn = ldap_simple_substitute_vars($user_dn); 40 } else { 41 $user_dn = ldap_simple_search_userdn($rcmail, $ds); 42 } 43 44 if (empty($user_dn)) { 45 ldap_unbind($ds); 46 return PASSWORD_CONNECT_ERROR; 47 } 48 49 // Connection method 50 switch ($rcmail->config->get('password_ldap_method')) { 16 function save($curpass, $passwd) 17 { 18 $rcmail = rcmail::get_instance(); 19 20 // Connect 21 if (!$ds = ldap_connect($rcmail->config->get('password_ldap_host'), $rcmail->config->get('password_ldap_port'))) { 22 ldap_unbind($ds); 23 return PASSWORD_CONNECT_ERROR; 24 } 25 26 // Set protocol version 27 if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $rcmail->config->get('password_ldap_version'))) { 28 ldap_unbind($ds); 29 return PASSWORD_CONNECT_ERROR; 30 } 31 32 // Start TLS 33 if ($rcmail->config->get('password_ldap_starttls')) { 34 if (!ldap_start_tls($ds)) { 35 ldap_unbind($ds); 36 return PASSWORD_CONNECT_ERROR; 37 } 38 } 39 40 // Build user DN 41 if ($user_dn = $rcmail->config->get('password_ldap_userDN_mask')) { 42 $user_dn = $this->substitute_vars($user_dn); 43 } 44 else { 45 $user_dn = $this->search_userdn($rcmail, $ds); 46 } 47 48 if (empty($user_dn)) { 49 ldap_unbind($ds); 50 return PASSWORD_CONNECT_ERROR; 51 } 52 53 // Connection method 54 switch ($rcmail->config->get('password_ldap_method')) { 51 55 case 'admin': 52 56 $binddn = $rcmail->config->get('password_ldap_adminDN'); … … 58 62 $bindpw = $curpass; 59 63 break; 60 } 61 62 63 $crypted_pass = ldap_simple_hash_password($passwd, $rcmail->config->get('password_ldap_encodage')); 64 $lchattr = $rcmail->config->get('password_ldap_lchattr'); 65 $pwattr = $rcmail->config->get('password_ldap_pwattr'); 66 $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); 67 $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); 68 $samba = $rcmail->config->get('password_ldap_samba'); 69 70 // Support password_ldap_samba option for backward compat. 71 if ($samba && !$smbpwattr) { 72 $smbpwattr = 'sambaNTPassword'; 73 $smblchattr = 'sambaPwdLastSet'; 74 } 75 76 // Crypt new password 77 if (!$crypted_pass) { 78 return PASSWORD_CRYPT_ERROR; 79 } 80 81 // Crypt new Samba password 82 if ($smbpwattr && !($samba_pass = ldap_simple_hash_password($passwd, 'samba'))) { 83 return PASSWORD_CRYPT_ERROR; 84 } 85 86 // Bind 87 if (!ldap_bind($ds, $binddn, $bindpw)) { 88 ldap_unbind($ds); 89 return PASSWORD_CONNECT_ERROR; 90 } 91 92 $entree[$pwattr] = $crypted_pass; 93 94 // Update PasswordLastChange Attribute if desired 95 if ($lchattr) { 96 $entree[$lchattr] = (int)(time() / 86400); 97 } 98 99 // Update Samba password 100 if ($smbpwattr) { 101 $entree[$smbpwattr] = $samba_pass; 102 } 103 104 // Update Samba password last change 105 if ($smblchattr) { 106 $entree[$smblchattr] = time(); 107 } 108 109 if (!ldap_modify($ds, $user_dn, $entree)) { 110 ldap_unbind($ds); 111 return PASSWORD_CONNECT_ERROR; 112 } 113 114 // All done, no error 115 ldap_unbind($ds); 116 return PASSWORD_SUCCESS; 117 } 118 119 /** 120 * Bind with searchDN and searchPW and search for the user's DN 121 * Use search_base and search_filter defined in config file 122 * Return the found DN 123 */ 124 function ldap_simple_search_userdn($rcmail, $ds) 125 { 126 /* Bind */ 127 if (!ldap_bind($ds, $rcmail->config->get('password_ldap_searchDN'), $rcmail->config->get('password_ldap_searchPW'))) { 128 return false; 129 } 130 131 /* Search for the DN */ 132 if (!$sr = ldap_search($ds, $rcmail->config->get('password_ldap_search_base'), ldap_simple_substitute_vars($rcmail->config->get('password_ldap_search_filter')))) { 133 return false; 134 } 135 136 /* If no or more entries were found, return false */ 137 if (ldap_count_entries($ds, $sr) != 1) { 138 return false; 139 } 140 141 return ldap_get_dn($ds, ldap_first_entry($ds, $sr)); 142 } 143 144 /** 145 * Substitute %login, %name, %domain, %dc in $str 146 * See plugin config for details 147 */ 148 function ldap_simple_substitute_vars($str) 149 { 150 $str = str_replace('%login', $_SESSION['username'], $str); 151 $str = str_replace('%l', $_SESSION['username'], $str); 152 153 $parts = explode('@', $_SESSION['username']); 154 155 if (count($parts) == 2) { 156 $dc = 'dc='.strtr($parts[1], array('.' => ',dc=')); // hierarchal domain string 157 158 $str = str_replace('%name', $parts[0], $str); 159 $str = str_replace('%n', $parts[0], $str); 160 $str = str_replace('%dc', $dc, $str); 161 $str = str_replace('%domain', $parts[1], $str); 162 $str = str_replace('%d', $parts[1], $str); 163 } 164 165 return $str; 166 } 167 168 /** 169 * Code originaly from the phpLDAPadmin development team 170 * http://phpldapadmin.sourceforge.net/ 171 * 172 * Hashes a password and returns the hash based on the specified enc_type 173 */ 174 function ldap_simple_hash_password($password_clear, $encodage_type) 175 { 176 $encodage_type = strtolower($encodage_type); 177 switch ($encodage_type) { 64 } 65 66 $crypted_pass = $this->hash_password($passwd, $rcmail->config->get('password_ldap_encodage')); 67 $lchattr = $rcmail->config->get('password_ldap_lchattr'); 68 $pwattr = $rcmail->config->get('password_ldap_pwattr'); 69 $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); 70 $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); 71 $samba = $rcmail->config->get('password_ldap_samba'); 72 73 // Support password_ldap_samba option for backward compat. 74 if ($samba && !$smbpwattr) { 75 $smbpwattr = 'sambaNTPassword'; 76 $smblchattr = 'sambaPwdLastSet'; 77 } 78 79 // Crypt new password 80 if (!$crypted_pass) { 81 return PASSWORD_CRYPT_ERROR; 82 } 83 84 // Crypt new Samba password 85 if ($smbpwattr && !($samba_pass = $this->hash_password($passwd, 'samba'))) { 86 return PASSWORD_CRYPT_ERROR; 87 } 88 89 // Bind 90 if (!ldap_bind($ds, $binddn, $bindpw)) { 91 ldap_unbind($ds); 92 return PASSWORD_CONNECT_ERROR; 93 } 94 95 $entree[$pwattr] = $crypted_pass; 96 97 // Update PasswordLastChange Attribute if desired 98 if ($lchattr) { 99 $entree[$lchattr] = (int)(time() / 86400); 100 } 101 102 // Update Samba password 103 if ($smbpwattr) { 104 $entree[$smbpwattr] = $samba_pass; 105 } 106 107 // Update Samba password last change 108 if ($smblchattr) { 109 $entree[$smblchattr] = time(); 110 } 111 112 if (!ldap_modify($ds, $user_dn, $entree)) { 113 ldap_unbind($ds); 114 return PASSWORD_CONNECT_ERROR; 115 } 116 117 // All done, no error 118 ldap_unbind($ds); 119 return PASSWORD_SUCCESS; 120 } 121 122 /** 123 * Bind with searchDN and searchPW and search for the user's DN 124 * Use search_base and search_filter defined in config file 125 * Return the found DN 126 */ 127 function search_userdn($rcmail, $ds) 128 { 129 /* Bind */ 130 if (!ldap_bind($ds, $rcmail->config->get('password_ldap_searchDN'), $rcmail->config->get('password_ldap_searchPW'))) { 131 return false; 132 } 133 134 /* Search for the DN */ 135 if (!$sr = ldap_search($ds, $rcmail->config->get('password_ldap_search_base'), $this->substitute_vars($rcmail->config->get('password_ldap_search_filter')))) { 136 return false; 137 } 138 139 /* If no or more entries were found, return false */ 140 if (ldap_count_entries($ds, $sr) != 1) { 141 return false; 142 } 143 144 return ldap_get_dn($ds, ldap_first_entry($ds, $sr)); 145 } 146 147 /** 148 * Substitute %login, %name, %domain, %dc in $str 149 * See plugin config for details 150 */ 151 function substitute_vars($str) 152 { 153 $str = str_replace('%login', $_SESSION['username'], $str); 154 $str = str_replace('%l', $_SESSION['username'], $str); 155 156 $parts = explode('@', $_SESSION['username']); 157 158 if (count($parts) == 2) { 159 $dc = 'dc='.strtr($parts[1], array('.' => ',dc=')); // hierarchal domain string 160 161 $str = str_replace('%name', $parts[0], $str); 162 $str = str_replace('%n', $parts[0], $str); 163 $str = str_replace('%dc', $dc, $str); 164 $str = str_replace('%domain', $parts[1], $str); 165 $str = str_replace('%d', $parts[1], $str); 166 } 167 168 return $str; 169 } 170 171 /** 172 * Code originaly from the phpLDAPadmin development team 173 * http://phpldapadmin.sourceforge.net/ 174 * 175 * Hashes a password and returns the hash based on the specified enc_type 176 */ 177 function hash_password($password_clear, $encodage_type) 178 { 179 $encodage_type = strtolower($encodage_type); 180 switch ($encodage_type) { 178 181 case 'crypt': 179 $crypted_password = '{CRYPT}' . crypt($password_clear, ldap_simple_random_salt(2));182 $crypted_password = '{CRYPT}' . crypt($password_clear, $this->random_salt(2)); 180 183 break; 181 184 case 'ext_des': … … 185 188 return false; 186 189 } 187 $crypted_password = '{CRYPT}' . crypt($password_clear, '_' . ldap_simple_random_salt(8));190 $crypted_password = '{CRYPT}' . crypt($password_clear, '_' . $this->random_salt(8)); 188 191 break; 189 192 case 'md5crypt': … … 192 195 return false; 193 196 } 194 $crypted_password = '{CRYPT}' . crypt($password_clear, '$1$' . ldap_simple_random_salt(9));197 $crypted_password = '{CRYPT}' . crypt($password_clear, '$1$' . $this->random_salt(9)); 195 198 break; 196 199 case 'blowfish': … … 200 203 } 201 204 /* Hardcoded to second blowfish version and set number of rounds */ 202 $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . ldap_simple_random_salt(13));205 $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . $this->random_salt(13)); 203 206 break; 204 207 case 'md5': … … 248 251 default: 249 252 $crypted_password = $password_clear; 250 } 251 252 return $crypted_password; 253 } 254 255 return $crypted_password; 256 } 257 258 /** 259 * Code originaly from the phpLDAPadmin development team 260 * http://phpldapadmin.sourceforge.net/ 261 * 262 * Used to generate a random salt for crypt-style passwords 263 */ 264 function random_salt($length) 265 { 266 $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './'; 267 $str = ''; 268 // mt_srand((double)microtime() * 1000000); 269 270 while (strlen($str) < $length) { 271 $str .= substr($possible, (rand() % strlen($possible)), 1); 272 } 273 274 return $str; 275 } 253 276 } 254 255 /**256 * Code originaly from the phpLDAPadmin development team257 * http://phpldapadmin.sourceforge.net/258 *259 * Used to generate a random salt for crypt-style passwords260 */261 function ldap_simple_random_salt($length)262 {263 $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './';264 $str = '';265 // mt_srand((double)microtime() * 1000000);266 while (strlen($str) < $length) {267 $str .= substr($possible, (rand() % strlen($possible)), 1);268 }269 270 return $str;271 } -
trunk/plugins/password/drivers/pam.php
r4199 r5902 4 4 * PAM Password Driver 5 5 * 6 * @version 1.06 * @version 2.0 7 7 * @author Aleksander Machniak 8 8 */ 9 10 function password_save($currpass, $newpass) 9 10 class rcube_pam_password 11 11 { 12 $user = $_SESSION['username']; 12 function save($currpass, $newpass) 13 { 14 $user = $_SESSION['username']; 13 15 14 if (extension_loaded('pam')) { 15 if (pam_auth($user, $currpass, $error, false)) { 16 if (pam_chpass($user, $currpass, $newpass)) { 17 return PASSWORD_SUCCESS; 16 if (extension_loaded('pam')) { 17 if (pam_auth($user, $currpass, $error, false)) { 18 if (pam_chpass($user, $currpass, $newpass)) { 19 return PASSWORD_SUCCESS; 20 } 21 } 22 else { 23 raise_error(array( 24 'code' => 600, 25 'type' => 'php', 26 'file' => __FILE__, 'line' => __LINE__, 27 'message' => "Password plugin: PAM authentication failed for user $user: $error" 28 ), true, false); 18 29 } 19 30 } … … 23 34 'type' => 'php', 24 35 'file' => __FILE__, 'line' => __LINE__, 25 'message' => "Password plugin: P AM authentication failed for user $user: $error"36 'message' => "Password plugin: PECL-PAM module not loaded" 26 37 ), true, false); 27 38 } 39 40 return PASSWORD_ERROR; 28 41 } 29 else {30 raise_error(array(31 'code' => 600,32 'type' => 'php',33 'file' => __FILE__, 'line' => __LINE__,34 'message' => "Password plugin: PECL-PAM module not loaded"35 ), true, false);36 }37 38 return PASSWORD_ERROR;39 42 } 40 41 ?> -
trunk/plugins/password/drivers/poppassd.php
r4016 r5902 6 6 * Driver to change passwords via Poppassd/Courierpassd 7 7 * 8 * @version 1.18 * @version 2.0 9 9 * @author Philip Weir 10 10 * 11 11 */ 12 12 13 function format_error_result($code, $line) 13 class rcube_poppassd_password 14 14 { 15 if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) { 16 return array('code' => $code, 'message' => $matches[1]); 17 } else { 18 return $code; 15 function format_error_result($code, $line) 16 { 17 if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) { 18 return array('code' => $code, 'message' => $matches[1]); 19 } else { 20 return $code; 21 } 19 22 } 20 }21 23 22 function password_save($curpass, $passwd)23 {24 $rcmail = rcmail::get_instance();24 function save($curpass, $passwd) 25 { 26 $rcmail = rcmail::get_instance(); 25 27 // include('Net/Socket.php'); 26 $poppassd = new Net_Socket();28 $poppassd = new Net_Socket(); 27 29 28 $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); 29 if (PEAR::isError($result)) { 30 return format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); 31 } 32 else { 33 $result = $poppassd->readLine(); 34 if(!preg_match('/^2\d\d/', $result)) { 35 $poppassd->disconnect(); 36 return format_error_result(PASSWORD_ERROR, $result); 30 $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); 31 if (PEAR::isError($result)) { 32 return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); 37 33 } 38 34 else { 39 $poppassd->writeLine("user ". $_SESSION['username']);40 35 $result = $poppassd->readLine(); 41 if(!preg_match('/^ [23]\d\d/', $result)) {36 if(!preg_match('/^2\d\d/', $result)) { 42 37 $poppassd->disconnect(); 43 return format_error_result(PASSWORD_CONNECT_ERROR, $result);38 return $this->format_error_result(PASSWORD_ERROR, $result); 44 39 } 45 40 else { 46 $poppassd->writeLine(" pass ". $curpass);41 $poppassd->writeLine("user ". $_SESSION['username']); 47 42 $result = $poppassd->readLine(); 48 43 if(!preg_match('/^[23]\d\d/', $result) ) { 49 44 $poppassd->disconnect(); 50 return format_error_result(PASSWORD_ERROR, $result);45 return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result); 51 46 } 52 47 else { 53 $poppassd->writeLine(" newpass ". $passwd);48 $poppassd->writeLine("pass ". $curpass); 54 49 $result = $poppassd->readLine(); 55 $poppassd->disconnect(); 56 if (!preg_match('/^2\d\d/', $result)) 57 return format_error_result(PASSWORD_ERROR, $result); 58 else 59 return PASSWORD_SUCCESS; 50 if(!preg_match('/^[23]\d\d/', $result) ) { 51 $poppassd->disconnect(); 52 return $this->format_error_result(PASSWORD_ERROR, $result); 53 } 54 else { 55 $poppassd->writeLine("newpass ". $passwd); 56 $result = $poppassd->readLine(); 57 $poppassd->disconnect(); 58 if (!preg_match('/^2\d\d/', $result)) 59 return $this->format_error_result(PASSWORD_ERROR, $result); 60 else 61 return PASSWORD_SUCCESS; 62 } 60 63 } 61 64 } -
trunk/plugins/password/drivers/sasl.php
r4199 r5902 13 13 * For installation instructions please read the README file. 14 14 * 15 * @version 1.015 * @version 2.0 16 16 * @author Thomas Bruederli 17 17 */ 18 19 function password_save($currpass, $newpass) 18 19 class rcube_sasl_password 20 20 { 21 $curdir = realpath(dirname(__FILE__)); 22 $username = escapeshellcmd($_SESSION['username']); 23 $args = rcmail::get_instance()->config->get('password_saslpasswd_args', ''); 21 function save($currpass, $newpass) 22 { 23 $curdir = realpath(dirname(__FILE__)); 24 $username = escapeshellcmd($_SESSION['username']); 25 $args = rcmail::get_instance()->config->get('password_saslpasswd_args', ''); 24 26 25 if ($fh = popen("$curdir/chgsaslpasswd -p $args $username", 'w')) {26 fwrite($fh, $newpass."\n");27 $code = pclose($fh);27 if ($fh = popen("$curdir/chgsaslpasswd -p $args $username", 'w')) { 28 fwrite($fh, $newpass."\n"); 29 $code = pclose($fh); 28 30 29 if ($code == 0) 30 return PASSWORD_SUCCESS; 31 if ($code == 0) 32 return PASSWORD_SUCCESS; 33 } 34 else { 35 raise_error(array( 36 'code' => 600, 37 'type' => 'php', 38 'file' => __FILE__, 'line' => __LINE__, 39 'message' => "Password plugin: Unable to execute $curdir/chgsaslpasswd" 40 ), true, false); 41 } 42 43 return PASSWORD_ERROR; 31 44 } 32 else {33 raise_error(array(34 'code' => 600,35 'type' => 'php',36 'file' => __FILE__, 'line' => __LINE__,37 'message' => "Password plugin: Unable to execute $curdir/chgsaslpasswd"38 ), true, false);39 }40 41 return PASSWORD_ERROR;42 45 } 43 44 ?> -
trunk/plugins/password/drivers/sql.php
r5419 r5902 6 6 * Driver for passwords stored in SQL database 7 7 * 8 * @version 1.48 * @version 2.0 9 9 * @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl> 10 10 * 11 11 */ 12 12 13 function password_save($curpass, $passwd) 13 class rcube_sql_password 14 14 { 15 $rcmail = rcmail::get_instance(); 15 function save($curpass, $passwd) 16 { 17 $rcmail = rcmail::get_instance(); 16 18 17 if (!($sql = $rcmail->config->get('password_query')))18 $sql = 'SELECT update_passwd(%c, %u)';19 if (!($sql = $rcmail->config->get('password_query'))) 20 $sql = 'SELECT update_passwd(%c, %u)'; 19 21 20 if ($dsn = $rcmail->config->get('password_db_dsn')) {21 // #1486067: enable new_link option22 if (is_array($dsn) && empty($dsn['new_link']))23 $dsn['new_link'] = true;24 else if (!is_array($dsn) && !preg_match('/\?new_link=true/', $dsn))25 $dsn .= '?new_link=true';22 if ($dsn = $rcmail->config->get('password_db_dsn')) { 23 // #1486067: enable new_link option 24 if (is_array($dsn) && empty($dsn['new_link'])) 25 $dsn['new_link'] = true; 26 else if (!is_array($dsn) && !preg_match('/\?new_link=true/', $dsn)) 27 $dsn .= '?new_link=true'; 26 28 27 $db = new rcube_mdb2($dsn, '', FALSE); 28 $db->set_debug((bool)$rcmail->config->get('sql_debug')); 29 $db->db_connect('w'); 30 } else { 31 $db = $rcmail->get_dbh(); 32 } 33 34 if ($err = $db->is_error()) 35 return PASSWORD_ERROR; 36 37 // crypted password 38 if (strpos($sql, '%c') !== FALSE) { 39 $salt = ''; 40 if (CRYPT_MD5) { 41 // Always use eight salt characters for MD5 (#1488136) 42 $len = 8; 43 } else if (CRYPT_STD_DES) { 44 $len = 2; 45 } else { 46 return PASSWORD_CRYPT_ERROR; 29 $db = new rcube_mdb2($dsn, '', FALSE); 30 $db->set_debug((bool)$rcmail->config->get('sql_debug')); 31 $db->db_connect('w'); 32 } 33 else { 34 $db = $rcmail->get_dbh(); 47 35 } 48 36 49 //Restrict the character set used as salt (#1488136) 50 $seedchars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 51 for ($i = 0; $i < $len ; $i++) { 52 $salt .= $seedchars[rand(0, 63)]; 37 if ($err = $db->is_error()) 38 return PASSWORD_ERROR; 39 40 // crypted password 41 if (strpos($sql, '%c') !== FALSE) { 42 $salt = ''; 43 if (CRYPT_MD5) { 44 // Always use eight salt characters for MD5 (#1488136) 45 $len = 8; 46 } else if (CRYPT_STD_DES) { 47 $len = 2; 48 } else { 49 return PASSWORD_CRYPT_ERROR; 50 } 51 52 //Restrict the character set used as salt (#1488136) 53 $seedchars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 54 for ($i = 0; $i < $len ; $i++) { 55 $salt .= $seedchars[rand(0, 63)]; 56 } 57 58 $sql = str_replace('%c', $db->quote(crypt($passwd, CRYPT_MD5 ? '$1$'.$salt.'$' : $salt)), $sql); 53 59 } 54 60 55 $sql = str_replace('%c', $db->quote(crypt($passwd, CRYPT_MD5 ? '$1$'.$salt.'$' : $salt)), $sql); 56 } 61 // dovecotpw 62 if (strpos($sql, '%D') !== FALSE) { 63 if (!($dovecotpw = $rcmail->config->get('password_dovecotpw'))) 64 $dovecotpw = 'dovecotpw'; 65 if (!($method = $rcmail->config->get('password_dovecotpw_method'))) 66 $method = 'CRAM-MD5'; 57 67 58 // dovecotpw 59 if (strpos($sql, '%D') !== FALSE) { 60 if (!($dovecotpw = $rcmail->config->get('password_dovecotpw'))) 61 $dovecotpw = 'dovecotpw'; 62 if (!($method = $rcmail->config->get('password_dovecotpw_method'))) 63 $method = 'CRAM-MD5'; 68 // use common temp dir 69 $tmp_dir = $rcmail->config->get('temp_dir'); 70 $tmpfile = tempnam($tmp_dir, 'roundcube-'); 64 71 65 // use common temp dir 66 $tmp_dir = $rcmail->config->get('temp_dir'); 67 $tmpfile = tempnam($tmp_dir, 'roundcube-'); 72 $pipe = popen("$dovecotpw -s '$method' > '$tmpfile'", "w"); 73 if (!$pipe) { 74 unlink($tmpfile); 75 return PASSWORD_CRYPT_ERROR; 76 } 77 else { 78 fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); usleep(1000); 79 fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); 80 pclose($pipe); 81 $newpass = trim(file_get_contents($tmpfile), "\n"); 82 if (!preg_match('/^\{' . $method . '\}/', $newpass)) { 83 return PASSWORD_CRYPT_ERROR; 84 } 85 if (!$rcmail->config->get('password_dovecotpw_with_method')) 86 $newpass = trim(str_replace('{' . $method . '}', '', $newpass)); 87 unlink($tmpfile); 88 } 89 $sql = str_replace('%D', $db->quote($newpass), $sql); 90 } 68 91 69 $pipe = popen("$dovecotpw -s '$method' > '$tmpfile'", "w"); 70 if (!$pipe) { 71 unlink($tmpfile); 72 return PASSWORD_CRYPT_ERROR; 92 // hashed passwords 93 if (preg_match('/%[n|q]/', $sql)) { 94 if (!extension_loaded('hash')) { 95 raise_error(array( 96 'code' => 600, 97 'type' => 'php', 98 'file' => __FILE__, 'line' => __LINE__, 99 'message' => "Password plugin: 'hash' extension not loaded!" 100 ), true, false); 101 102 return PASSWORD_ERROR; 103 } 104 105 if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm')))) 106 $hash_algo = 'sha1'; 107 108 $hash_passwd = hash($hash_algo, $passwd); 109 $hash_curpass = hash($hash_algo, $curpass); 110 111 if ($rcmail->config->get('password_hash_base64')) { 112 $hash_passwd = base64_encode(pack('H*', $hash_passwd)); 113 $hash_curpass = base64_encode(pack('H*', $hash_curpass)); 114 } 115 116 $sql = str_replace('%n', $db->quote($hash_passwd, 'text'), $sql); 117 $sql = str_replace('%q', $db->quote($hash_curpass, 'text'), $sql); 118 } 119 120 // Handle clear text passwords securely (#1487034) 121 $sql_vars = array(); 122 if (preg_match_all('/%[p|o]/', $sql, $m)) { 123 foreach ($m[0] as $var) { 124 if ($var == '%p') { 125 $sql = preg_replace('/%p/', '?', $sql, 1); 126 $sql_vars[] = (string) $passwd; 127 } 128 else { // %o 129 $sql = preg_replace('/%o/', '?', $sql, 1); 130 $sql_vars[] = (string) $curpass; 131 } 132 } 133 } 134 135 $local_part = $rcmail->user->get_username('local'); 136 $domain_part = $rcmail->user->get_username('domain'); 137 $username = $_SESSION['username']; 138 $host = $_SESSION['imap_host']; 139 140 // convert domains to/from punnycode 141 if ($rcmail->config->get('password_idn_ascii')) { 142 $domain_part = rcube_idn_to_ascii($domain_part); 143 $username = rcube_idn_to_ascii($username); 144 $host = rcube_idn_to_ascii($host); 73 145 } 74 146 else { 75 fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); usleep(1000); 76 fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); 77 pclose($pipe); 78 $newpass = trim(file_get_contents($tmpfile), "\n"); 79 if (!preg_match('/^\{' . $method . '\}/', $newpass)) { 80 return PASSWORD_CRYPT_ERROR; 81 } 82 if (!$rcmail->config->get('password_dovecotpw_with_method')) 83 $newpass = trim(str_replace('{' . $method . '}', '', $newpass)); 84 unlink($tmpfile); 85 } 86 $sql = str_replace('%D', $db->quote($newpass), $sql); 87 } 88 89 // hashed passwords 90 if (preg_match('/%[n|q]/', $sql)) { 91 92 if (!extension_loaded('hash')) { 93 raise_error(array( 94 'code' => 600, 95 'type' => 'php', 96 'file' => __FILE__, 'line' => __LINE__, 97 'message' => "Password plugin: 'hash' extension not loaded!" 98 ), true, false); 99 100 return PASSWORD_ERROR; 101 } 102 103 if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm')))) 104 $hash_algo = 'sha1'; 105 106 $hash_passwd = hash($hash_algo, $passwd); 107 $hash_curpass = hash($hash_algo, $curpass); 108 109 if ($rcmail->config->get('password_hash_base64')) { 110 $hash_passwd = base64_encode(pack('H*', $hash_passwd)); 111 $hash_curpass = base64_encode(pack('H*', $hash_curpass)); 147 $domain_part = rcube_idn_to_utf8($domain_part); 148 $username = rcube_idn_to_utf8($username); 149 $host = rcube_idn_to_utf8($host); 112 150 } 113 151 114 $sql = str_replace('%n', $db->quote($hash_passwd, 'text'), $sql); 115 $sql = str_replace('%q', $db->quote($hash_curpass, 'text'), $sql); 152 // at least we should always have the local part 153 $sql = str_replace('%l', $db->quote($local_part, 'text'), $sql); 154 $sql = str_replace('%d', $db->quote($domain_part, 'text'), $sql); 155 $sql = str_replace('%u', $db->quote($username, 'text'), $sql); 156 $sql = str_replace('%h', $db->quote($host, 'text'), $sql); 157 158 $res = $db->query($sql, $sql_vars); 159 160 if (!$db->is_error()) { 161 if (strtolower(substr(trim($query),0,6))=='select') { 162 if ($result = $db->fetch_array($res)) 163 return PASSWORD_SUCCESS; 164 } else { 165 // This is the good case: 1 row updated 166 if ($db->affected_rows($res) == 1) 167 return PASSWORD_SUCCESS; 168 // @TODO: Some queries don't affect any rows 169 // Should we assume a success if there was no error? 170 } 171 } 172 173 return PASSWORD_ERROR; 116 174 } 117 118 // Handle clear text passwords securely (#1487034)119 $sql_vars = array();120 if (preg_match_all('/%[p|o]/', $sql, $m)) {121 foreach ($m[0] as $var) {122 if ($var == '%p') {123 $sql = preg_replace('/%p/', '?', $sql, 1);124 $sql_vars[] = (string) $passwd;125 }126 else { // %o127 $sql = preg_replace('/%o/', '?', $sql, 1);128 $sql_vars[] = (string) $curpass;129 }130 }131 }132 133 $local_part = $rcmail->user->get_username('local');134 $domain_part = $rcmail->user->get_username('domain');135 $username = $_SESSION['username'];136 $host = $_SESSION['imap_host'];137 138 // convert domains to/from punnycode139 if ($rcmail->config->get('password_idn_ascii')) {140 $domain_part = rcube_idn_to_ascii($domain_part);141 $username = rcube_idn_to_ascii($username);142 $host = rcube_idn_to_ascii($host);143 }144 else {145 $domain_part = rcube_idn_to_utf8($domain_part);146 $username = rcube_idn_to_utf8($username);147 $host = rcube_idn_to_utf8($host);148 }149 150 // at least we should always have the local part151 $sql = str_replace('%l', $db->quote($local_part, 'text'), $sql);152 $sql = str_replace('%d', $db->quote($domain_part, 'text'), $sql);153 $sql = str_replace('%u', $db->quote($username, 'text'), $sql);154 $sql = str_replace('%h', $db->quote($host, 'text'), $sql);155 156 $res = $db->query($sql, $sql_vars);157 158 if (!$db->is_error()) {159 if (strtolower(substr(trim($query),0,6))=='select') {160 if ($result = $db->fetch_array($res))161 return PASSWORD_SUCCESS;162 } else {163 // This is the good case: 1 row updated164 if ($db->affected_rows($res) == 1)165 return PASSWORD_SUCCESS;166 // @TODO: Some queries don't affect any rows167 // Should we assume a success if there was no error?168 }169 }170 171 return PASSWORD_ERROR;172 175 } 173 174 ?> -
trunk/plugins/password/drivers/virtualmin.php
r4546 r5902 11 11 * and requires shell access and gcc in order to compile the binary. 12 12 * 13 * @version 2.013 * @version 3.0 14 14 * @author Martijn de Munnik 15 15 */ 16 16 17 function password_save($currpass, $newpass) 17 class rcube_virtualmin_password 18 18 { 19 $rcmail = rcmail::get_instance(); 19 function save($currpass, $newpass) 20 { 21 $rcmail = rcmail::get_instance(); 20 22 21 $format = $rcmail->config->get('password_virtualmin_format', 0);22 $username = $_SESSION['username'];23 $format = $rcmail->config->get('password_virtualmin_format', 0); 24 $username = $_SESSION['username']; 23 25 24 switch ($format) {26 switch ($format) { 25 27 case 1: // username%domain 26 28 $domain = substr(strrchr($username, "%"), 1); … … 49 51 default: // username@domain 50 52 $domain = substr(strrchr($username, "@"), 1); 53 } 54 55 $username = escapeshellcmd($username); 56 $domain = escapeshellcmd($domain); 57 $newpass = escapeshellcmd($newpass); 58 $curdir = realpath(dirname(__FILE__)); 59 60 exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue); 61 62 if ($returnvalue == 0) { 63 return PASSWORD_SUCCESS; 64 } 65 else { 66 raise_error(array( 67 'code' => 600, 68 'type' => 'php', 69 'file' => __FILE__, 'line' => __LINE__, 70 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd" 71 ), true, false); 72 } 73 74 return PASSWORD_ERROR; 51 75 } 52 53 $username = escapeshellcmd($username);54 $domain = escapeshellcmd($domain);55 $newpass = escapeshellcmd($newpass);56 $curdir = realpath(dirname(__FILE__));57 58 exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);59 60 if ($returnvalue == 0) {61 return PASSWORD_SUCCESS;62 }63 else {64 raise_error(array(65 'code' => 600,66 'type' => 'php',67 'file' => __FILE__, 'line' => __LINE__,68 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"69 ), true, false);70 }71 72 return PASSWORD_ERROR;73 76 } 74 75 ?> -
trunk/plugins/password/drivers/vpopmaild.php
r3257 r5902 6 6 * Driver to change passwords via vpopmaild 7 7 * 8 * @version 1.18 * @version 2.0 9 9 * @author Johannes Hessellund 10 10 * 11 11 */ 12 12 13 function password_save($curpass, $passwd) 13 class rcube_vpopmaild_password 14 14 { 15 $rcmail = rcmail::get_instance(); 16 // include('Net/Socket.php'); 17 $vpopmaild = new Net_Socket(); 15 function save($curpass, $passwd) 16 { 17 $rcmail = rcmail::get_instance(); 18 // include('Net/Socket.php'); 19 $vpopmaild = new Net_Socket(); 18 20 19 if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'),20 $rcmail->config->get('password_vpopmaild_port'), null))) {21 return PASSWORD_CONNECT_ERROR;22 }21 if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'), 22 $rcmail->config->get('password_vpopmaild_port'), null))) { 23 return PASSWORD_CONNECT_ERROR; 24 } 23 25 24 $result = $vpopmaild->readLine();25 if(!preg_match('/^\+OK/', $result)) {26 $vpopmaild->disconnect();27 return PASSWORD_CONNECT_ERROR;28 }26 $result = $vpopmaild->readLine(); 27 if(!preg_match('/^\+OK/', $result)) { 28 $vpopmaild->disconnect(); 29 return PASSWORD_CONNECT_ERROR; 30 } 29 31 30 $vpopmaild->writeLine("slogin ". $_SESSION['username'] . " " . $curpass); 31 $result = $vpopmaild->readLine(); 32 if(!preg_match('/^\+OK/', $result) ) { 32 $vpopmaild->writeLine("slogin ". $_SESSION['username'] . " " . $curpass); 33 $result = $vpopmaild->readLine(); 34 35 if(!preg_match('/^\+OK/', $result) ) { 36 $vpopmaild->writeLine("quit"); 37 $vpopmaild->disconnect(); 38 return PASSWORD_ERROR; 39 } 40 41 $vpopmaild->writeLine("mod_user ". $_SESSION['username']); 42 $vpopmaild->writeLine("clear_text_password ". $passwd); 43 $vpopmaild->writeLine("."); 44 $result = $vpopmaild->readLine(); 33 45 $vpopmaild->writeLine("quit"); 34 46 $vpopmaild->disconnect(); 35 return PASSWORD_ERROR; 47 48 if (!preg_match('/^\+OK/', $result)) 49 return PASSWORD_ERROR; 50 51 return PASSWORD_SUCCESS; 36 52 } 37 38 $vpopmaild->writeLine("mod_user ". $_SESSION['username']);39 $vpopmaild->writeLine("clear_text_password ". $passwd);40 $vpopmaild->writeLine(".");41 $result = $vpopmaild->readLine();42 $vpopmaild->writeLine("quit");43 $vpopmaild->disconnect();44 45 if (!preg_match('/^\+OK/', $result))46 return PASSWORD_ERROR;47 48 return PASSWORD_SUCCESS;49 53 } 50 51 ?> -
trunk/plugins/password/drivers/ximss.php
r3030 r5902 13 13 * http://www.communigate.com/WebGuide/XMLAPI.html 14 14 * 15 * @version 115 * @version 2.0 16 16 * @author Erik Meitner <erik wanderings.us> 17 17 */ 18 19 function password_save($pass, $newpass) 18 19 class rcube_ximss_password 20 20 { 21 function save($pass, $newpass) 22 { 23 $rcmail = rcmail::get_instance(); 21 24 22 $rcmail = rcmail::get_instance();23 24 $sock = stream_socket_client("tcp://".$rcmail->config->get('password_ximss_host').":".$rcmail->config->get('password_ximss_port'), $errno, $errstr, 30);25 if( $sock === FALSE ) 26 {27 return PASSWORD_CONNECT_ERROR;28 }29 30 // send all requests at once(pipelined)31 fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");32 fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'" />'."\0");33 fwrite( $sock, '<bye id="A003" />'."\0");25 $host = $rcmail->config->get('password_ximss_host'); 26 $port = $rcmail->config->get('password_ximss_port'); 27 $sock = stream_socket_client("tcp://$host:$port", $errno, $errstr, 30); 28 29 if ($sock === FALSE) { 30 return PASSWORD_CONNECT_ERROR; 31 } 32 33 // send all requests at once(pipelined) 34 fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0"); 35 fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'" />'."\0"); 36 fwrite( $sock, '<bye id="A003" />'."\0"); 34 37 35 38 //example responses … … 41 44 // <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0 42 45 43 $responseblob = '';44 while (!feof($sock)) {45 $responseblob .= fgets($sock, 1024);46 }46 $responseblob = ''; 47 while (!feof($sock)) { 48 $responseblob .= fgets($sock, 1024); 49 } 47 50 48 fclose($sock); 49 50 foreach( explode( "\0",$responseblob) as $response ) 51 { 52 $resp = simplexml_load_string("<xml>".$response."</xml>"); 51 fclose($sock); 53 52 54 if( $resp->response[0]['id'] == 'A001' ) 55 { 56 if( isset( $resp->response[0]['errorNum'] ) ) 57 { 58 return PASSWORD_CONNECT_ERROR; 59 } 53 foreach( explode( "\0",$responseblob) as $response ) { 54 $resp = simplexml_load_string("<xml>".$response."</xml>"); 55 56 if( $resp->response[0]['id'] == 'A001' ) { 57 if( isset( $resp->response[0]['errorNum'] ) ) { 58 return PASSWORD_CONNECT_ERROR; 59 } 60 } 61 else if( $resp->response[0]['id'] == 'A002' ) { 62 if( isset( $resp->response[0]['errorNum'] )) { 63 return PASSWORD_ERROR; 64 } 65 } 66 else if( $resp->response[0]['id'] == 'A003' ) { 67 if( isset($resp->response[0]['errorNum'] )) { 68 //There was a problem during logout(This is probably harmless) 69 } 70 } 71 } //foreach 72 73 return PASSWORD_SUCCESS; 74 60 75 } 61 else if( $resp->response[0]['id'] == 'A002' )62 {63 if( isset( $resp->response[0]['errorNum'] ))64 {65 return PASSWORD_ERROR;66 }67 }68 else if( $resp->response[0]['id'] == 'A003' )69 {70 if( isset($resp->response[0]['errorNum'] ))71 {72 //There was a problem during logout(This is probably harmless)73 }74 }75 } //foreach76 77 return PASSWORD_SUCCESS;78 79 76 } 80 81 ?> -
trunk/plugins/password/drivers/xmail.php
r4507 r5902 5 5 * Driver for XMail password 6 6 * 7 * @version 1.07 * @version 2.0 8 8 * @author Helio Cavichiolo Jr <helio@hcsistemas.com.br> 9 9 * … … 18 18 */ 19 19 20 function password_save($currpass, $newpass) 20 class rcube_xmail_password 21 21 { 22 $rcmail = rcmail::get_instance(); 23 list($user,$domain) = explode('@', $_SESSION['username']); 22 function save($currpass, $newpass) 23 { 24 $rcmail = rcmail::get_instance(); 25 list($user,$domain) = explode('@', $_SESSION['username']); 24 26 25 $xmail = new XMail;27 $xmail = new XMail; 26 28 27 $xmail->hostname = $rcmail->config->get('xmail_host');28 $xmail->username = $rcmail->config->get('xmail_user');29 $xmail->password = $rcmail->config->get('xmail_pass');30 $xmail->port = $rcmail->config->get('xmail_port');29 $xmail->hostname = $rcmail->config->get('xmail_host'); 30 $xmail->username = $rcmail->config->get('xmail_user'); 31 $xmail->password = $rcmail->config->get('xmail_pass'); 32 $xmail->port = $rcmail->config->get('xmail_port'); 31 33 32 if (!$xmail->connect()) { 33 raise_error(array( 34 'code' => 600, 35 'type' => 'php', 36 'file' => __FILE__, 'line' => __LINE__, 37 'message' => "Password plugin: Unable to connect to mail server" 38 ), true, false); 39 return PASSWORD_CONNECT_ERROR; 40 } else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) { 41 $xmail->close(); 42 raise_error(array( 43 'code' => 600, 44 'type' => 'php', 45 'file' => __FILE__, 'line' => __LINE__, 46 'message' => "Password plugin: Unable to change password" 47 ), true, false); 48 return PASSWORD_ERROR; 49 } else { 50 $xmail->close(); 51 return PASSWORD_SUCCESS; 34 if (!$xmail->connect()) { 35 raise_error(array( 36 'code' => 600, 37 'type' => 'php', 38 'file' => __FILE__, 'line' => __LINE__, 39 'message' => "Password plugin: Unable to connect to mail server" 40 ), true, false); 41 return PASSWORD_CONNECT_ERROR; 42 } 43 else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) { 44 $xmail->close(); 45 raise_error(array( 46 'code' => 600, 47 'type' => 'php', 48 'file' => __FILE__, 'line' => __LINE__, 49 'message' => "Password plugin: Unable to change password" 50 ), true, false); 51 return PASSWORD_ERROR; 52 } 53 else { 54 $xmail->close(); 55 return PASSWORD_SUCCESS; 56 } 52 57 } 53 58 } -
trunk/plugins/password/package.xml
r5467 r5902 18 18 <date>2011-11-23</date> 19 19 <version> 20 <release> 2.4</release>21 <api> 1.6</api>20 <release>3.0</release> 21 <api>2.0</api> 22 22 </version> 23 23 <stability> … … 27 27 <license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license> 28 28 <notes> 29 - Added option to use punycode or unicode for domain names (#1488103) 30 - Save Samba password hashes in capital letters (#1488197) 29 - Fixed drivers namespace issues 31 30 </notes> 32 31 <contents> … … 288 287 </notes> 289 288 </release> 289 <release> 290 <date>2011-11-23</date> 291 <version> 292 <release>2.4</release> 293 <api>1.6</api> 294 </version> 295 <stability> 296 <release>stable</release> 297 <api>stable</api> 298 </stability> 299 <license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license> 300 <notes> 301 - Added option to use punycode or unicode for domain names (#1488103) 302 - Save Samba password hashes in capital letters (#1488197) 303 </notes> 304 </release> 290 305 </changelog> 291 306 </package> -
trunk/plugins/password/password.php
r5901 r5902 178 178 $input_curpasswd = new html_passwordfield(array('name' => '_curpasswd', 'id' => $field_id, 179 179 'size' => 20, 'autocomplete' => 'off')); 180 180 181 181 $table->add('title', html::label($field_id, Q($this->gettext('curpasswd')))); 182 182 $table->add(null, $input_curpasswd->show()); … … 223 223 { 224 224 $config = rcmail::get_instance()->config; 225 $driver = $this->home.'/drivers/'.$config->get('password_driver', 'sql').'.php'; 226 227 if (!is_readable($driver)) { 225 $driver = $config->get('password_driver', 'sql'); 226 $class = "rcube_{$driver}_password"; 227 $file = $this->home . "/drivers/$driver.php"; 228 229 if (!file_exists($file)) { 228 230 raise_error(array( 229 231 'code' => 600, 230 232 'type' => 'php', 231 233 'file' => __FILE__, 'line' => __LINE__, 232 'message' => "Password plugin: Unable to open driver file $driver"234 'message' => "Password plugin: Unable to open driver file ($file)" 233 235 ), true, false); 234 236 return $this->gettext('internalerror'); 235 237 } 236 238 237 include ($driver);238 239 if (! function_exists('password_save')) {239 include_once $file; 240 241 if (!class_exists($class, false) || !method_exists($class, 'save')) { 240 242 raise_error(array( 241 243 'code' => 600, 242 244 'type' => 'php', 243 245 'file' => __FILE__, 'line' => __LINE__, 244 'message' => "Password plugin: Broken driver :$driver"246 'message' => "Password plugin: Broken driver $driver" 245 247 ), true, false); 246 248 return $this->gettext('internalerror'); 247 249 } 248 250 249 $result = password_save($curpass, $passwd); 251 $object = new $class; 252 $result = $object->save($curpass, $passwd); 250 253 251 254 if (is_array($result)) {
Note: See TracChangeset
for help on using the changeset viewer.
