summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2012-02-24 10:17:19 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2012-02-24 10:17:19 +0000
commit121ae23a83555b34c28b9967113a0cdf1755387a (patch)
tree8fe7044c54773f041b2111808ff11e973e801a90
parent85fefe3e33be4824377161c4587ec4141bfc57f4 (diff)
- Fixed drivers namespace issues
git-svn-id: https://svn.roundcube.net/trunk@5902 208e9e7b-5314-0410-a742-e7e81cd9613c
-rw-r--r--plugins/password/drivers/chpasswd.php39
-rw-r--r--plugins/password/drivers/cpanel.php69
-rw-r--r--plugins/password/drivers/directadmin.php82
-rw-r--r--plugins/password/drivers/hmail.php92
-rw-r--r--plugins/password/drivers/ldap.php397
-rw-r--r--plugins/password/drivers/ldap_simple.php309
-rw-r--r--plugins/password/drivers/pam.php43
-rw-r--r--plugins/password/drivers/poppassd.php65
-rw-r--r--plugins/password/drivers/sasl.php47
-rw-r--r--plugins/password/drivers/sql.php265
-rw-r--r--plugins/password/drivers/virtualmin.php55
-rw-r--r--plugins/password/drivers/vpopmaild.php64
-rw-r--r--plugins/password/drivers/ximss.php95
-rw-r--r--plugins/password/drivers/xmail.php63
-rw-r--r--plugins/password/package.xml23
-rw-r--r--plugins/password/password.php19
16 files changed, 882 insertions, 845 deletions
diff --git a/plugins/password/drivers/chpasswd.php b/plugins/password/drivers/chpasswd.php
index 28c3e5d7a..cce7c1f42 100644
--- a/plugins/password/drivers/chpasswd.php
+++ b/plugins/password/drivers/chpasswd.php
@@ -8,29 +8,32 @@
*
* For installation instructions please read the README file.
*
- * @version 1.0
+ * @version 2.0
* @author Alex Cartwright <acartwright@mutinydesign.co.uk)
*/
-function password_save($currpass, $newpass)
+class rcube_chpasswd_password
{
- $cmd = rcmail::get_instance()->config->get('password_chpasswd_cmd');
- $username = $_SESSION['username'];
+ public function save($currpass, $newpass)
+ {
+ $cmd = rcmail::get_instance()->config->get('password_chpasswd_cmd');
+ $username = $_SESSION['username'];
- $handle = popen($cmd, "w");
- fwrite($handle, "$username:$newpass\n");
+ $handle = popen($cmd, "w");
+ fwrite($handle, "$username:$newpass\n");
- if (pclose($handle) == 0) {
- return PASSWORD_SUCCESS;
- }
- else {
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to execute $cmd"
- ), true, false);
- }
+ if (pclose($handle) == 0) {
+ return PASSWORD_SUCCESS;
+ }
+ else {
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: Unable to execute $cmd"
+ ), true, false);
+ }
- return PASSWORD_ERROR;
+ return PASSWORD_ERROR;
+ }
}
diff --git a/plugins/password/drivers/cpanel.php b/plugins/password/drivers/cpanel.php
index 82bfe74d2..58351143b 100644
--- a/plugins/password/drivers/cpanel.php
+++ b/plugins/password/drivers/cpanel.php
@@ -7,12 +7,36 @@
* The cPanel PHP API code has been taken from: http://www.phpclasses.org/browse/package/3534.html
*
* This driver has been tested with Hostmonster hosting and seems to work fine.
-
*
- * @version 1.0
+ * @version 2.0
* @author Fulvio Venturelli <fulvio@venturelli.org>
*/
+class rcube_cpanel_password
+{
+ public function save($curpas, $newpass)
+ {
+ $rcmail = rcmail::get_instance();
+
+ // 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'] );
+
+ if ($cPanel->setPassword($newpass)){
+ return PASSWORD_SUCCESS;
+ }
+ else {
+ return PASSWORD_ERROR;
+ }
+ }
+}
+
+
class HTTP
{
function HTTP($host, $username, $password, $port, $ssl, $theme)
@@ -60,7 +84,7 @@ class HTTP
class emailAccount
-{
+{
function emailAccount($host, $username, $password, $port, $ssl, $theme, $address)
{
$this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme);
@@ -74,13 +98,13 @@ class emailAccount
}
}
- /*
- * Change email account password
- *
- * Returns true on success or false on failure.
- * @param string $password email account password
- * @return bool
- */
+ /**
+ * Change email account password
+ *
+ * Returns true on success or false on failure.
+ * @param string $password email account password
+ * @return bool
+ */
function setPassword($password)
{
$data['email'] = $this->email;
@@ -94,28 +118,3 @@ class emailAccount
return false;
}
}
-
-
-function password_save($curpas, $newpass)
-{
- $rcmail = rcmail::get_instance();
-
- // 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'] );
-
- if ($cPanel->setPassword($newpass)){
- return PASSWORD_SUCCESS;
- }
- else
- {
- return PASSWORD_ERROR;
- }
-}
-
-?>
diff --git a/plugins/password/drivers/directadmin.php b/plugins/password/drivers/directadmin.php
index 3b6ae9f03..1be14f6e8 100644
--- a/plugins/password/drivers/directadmin.php
+++ b/plugins/password/drivers/directadmin.php
@@ -5,50 +5,53 @@
*
* Driver to change passwords via DirectAdmin Control Panel
*
- * @version 1.2
+ * @version 2.0
* @author Victor Benincasa <vbenincasa@gmail.com>
*
*/
+class rcube_directadmin_password
+{
+ public function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
+ $Socket = new HTTPSocket;
-function password_save($curpass, $passwd){
-
- $rcmail = rcmail::get_instance();
- $Socket = new HTTPSocket;
-
- $da_user = $_SESSION['username'];
- $da_curpass = $curpass;
- $da_newpass = $passwd;
- $da_host = $rcmail->config->get('password_directadmin_host');
- $da_port = $rcmail->config->get('password_directadmin_port');
-
- if(strpos($da_user, '@') === false) return array('code' => PASSWORD_ERROR, 'message' => 'Change the SYSTEM user password through control panel!');
+ $da_user = $_SESSION['username'];
+ $da_curpass = $curpass;
+ $da_newpass = $passwd;
+ $da_host = $rcmail->config->get('password_directadmin_host');
+ $da_port = $rcmail->config->get('password_directadmin_port');
- $da_host = str_replace('%h', $_SESSION['imap_host'], $da_host);
- $da_host = str_replace('%d', $rcmail->user->get_username('domain'), $da_host);
+ if (strpos($da_user, '@') === false) {
+ return array('code' => PASSWORD_ERROR, 'message' => 'Change the SYSTEM user password through control panel!');
+ }
- $Socket->connect($da_host,$da_port);
- $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'
- ));
- $response = $Socket->fetch_parsed_body();
+ $da_host = str_replace('%h', $_SESSION['imap_host'], $da_host);
+ $da_host = str_replace('%d', $rcmail->user->get_username('domain'), $da_host);
- //DEBUG
- //console("Password Plugin: [USER: $da_user] [HOST: $da_host] - Response: [SOCKET: ".$Socket->result_status_code."] [DA ERROR: ".strip_tags($response['error'])."] [TEXT: ".$response[text]."]");
+ $Socket->connect($da_host,$da_port);
+ $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'
+ ));
+ $response = $Socket->fetch_parsed_body();
- if($Socket->result_status_code != 200)
- return array('code' => PASSWORD_CONNECT_ERROR, 'message' => $Socket->error[0]);
- elseif($response['error'] == 1)
- return array('code' => PASSWORD_ERROR, 'message' => strip_tags($response['text']));
- else
- return PASSWORD_SUCCESS;
+ //DEBUG
+ //console("Password Plugin: [USER: $da_user] [HOST: $da_host] - Response: [SOCKET: ".$Socket->result_status_code."] [DA ERROR: ".strip_tags($response['error'])."] [TEXT: ".$response[text]."]");
+ if($Socket->result_status_code != 200)
+ return array('code' => PASSWORD_CONNECT_ERROR, 'message' => $Socket->error[0]);
+ elseif($response['error'] == 1)
+ return array('code' => PASSWORD_ERROR, 'message' => strip_tags($response['text']));
+ else
+ return PASSWORD_SUCCESS;
+ }
}
@@ -68,7 +71,7 @@ function password_save($curpass, $passwd){
class HTTPSocket {
var $version = '2.7';
-
+
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */
var $method = 'GET';
@@ -169,7 +172,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'];
@@ -322,7 +325,7 @@ class HTTPSocket {
}
}
-
+
list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2);
if ($this->bind_host)
@@ -361,7 +364,6 @@ class HTTPSocket {
$this->query($headers['location']);
}
}
-
}
function getTransferSpeed()
@@ -445,7 +447,7 @@ class HTTPSocket {
function fetch_header( $header = '' )
{
$array_headers = preg_split("/\r\n/",$this->result_header);
-
+
$array_return = array( 0 => $array_headers[0] );
unset($array_headers[0]);
@@ -485,5 +487,3 @@ class HTTPSocket {
}
}
-
-?>
diff --git a/plugins/password/drivers/hmail.php b/plugins/password/drivers/hmail.php
index 39a87ab34..104c851ae 100644
--- a/plugins/password/drivers/hmail.php
+++ b/plugins/password/drivers/hmail.php
@@ -3,59 +3,61 @@
/**
* hMailserver password driver
*
- * @version 1.3 - 05.11.2010
+ * @version 2.0
* @author Roland 'rosali' Liebl <myroundcube@mail4us.net>
*
*/
-function password_save($curpass, $passwd)
+class rcube_hmail_password
{
- $rcmail = rcmail::get_instance();
+ public function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
- if ($curpass == '' || $passwd == '')
- return PASSWORD_ERROR;
+ if ($curpass == '' || $passwd == '') {
+ return PASSWORD_ERROR;
+ }
- try {
- $remote = $rcmail->config->get('hmailserver_remote_dcom', false);
- if ($remote)
- $obApp = new COM("hMailServer.Application", $rcmail->config->get('hmailserver_server'));
- else
- $obApp = new COM("hMailServer.Application");
- }
- catch (Exception $e) {
- write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
- write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
- return PASSWORD_ERROR;
- }
+ try {
+ $remote = $rcmail->config->get('hmailserver_remote_dcom', false);
+ if ($remote)
+ $obApp = new COM("hMailServer.Application", $rcmail->config->get('hmailserver_server'));
+ else
+ $obApp = new COM("hMailServer.Application");
+ }
+ catch (Exception $e) {
+ write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
+ write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
+ return PASSWORD_ERROR;
+ }
- $username = $rcmail->user->data['username'];
- if (strstr($username,'@')){
- $temparr = explode('@', $username);
- $domain = $temparr[1];
- }
- else {
- $domain = $rcmail->config->get('username_domain',false);
- if (!$domain) {
- write_log('errors','Plugin password (hmail driver): $rcmail_config[\'username_domain\'] is not defined.');
- write_log('errors','Plugin password (hmail driver): Hint: Use hmail_login plugin (http://myroundcube.googlecode.com');
- return PASSWORD_ERROR;
- }
- $username = $username . "@" . $domain;
- }
+ $username = $rcmail->user->data['username'];
+ if (strstr($username,'@')){
+ $temparr = explode('@', $username);
+ $domain = $temparr[1];
+ }
+ else {
+ $domain = $rcmail->config->get('username_domain',false);
+ if (!$domain) {
+ write_log('errors','Plugin password (hmail driver): $rcmail_config[\'username_domain\'] is not defined.');
+ write_log('errors','Plugin password (hmail driver): Hint: Use hmail_login plugin (http://myroundcube.googlecode.com');
+ return PASSWORD_ERROR;
+ }
+ $username = $username . "@" . $domain;
+ }
- $obApp->Authenticate($username, $curpass);
- try {
- $obDomain = $obApp->Domains->ItemByName($domain);
- $obAccount = $obDomain->Accounts->ItemByAddress($username);
- $obAccount->Password = $passwd;
- $obAccount->Save();
- return PASSWORD_SUCCESS;
- }
- catch (Exception $e) {
- write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
- write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
- return PASSWORD_ERROR;
+ $obApp->Authenticate($username, $curpass);
+ try {
+ $obDomain = $obApp->Domains->ItemByName($domain);
+ $obAccount = $obDomain->Accounts->ItemByAddress($username);
+ $obAccount->Password = $passwd;
+ $obAccount->Save();
+ return PASSWORD_SUCCESS;
+ }
+ catch (Exception $e) {
+ write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
+ write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
+ return PASSWORD_ERROR;
+ }
}
}
-
-?>
diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php
index e6450e5e1..def07a175 100644
--- a/plugins/password/drivers/ldap.php
+++ b/plugins/password/drivers/ldap.php
@@ -6,206 +6,206 @@
* Driver for passwords stored in LDAP
* This driver use the PEAR Net_LDAP2 class (http://pear.php.net/package/Net_LDAP2).
*
- * @version 1.1 (2010-04-07)
+ * @version 2.0
* @author Edouard MOREAU <edouard.moreau@ensma.fr>
*
- * function hashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
- * function randomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
+ * method hashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
+ * method randomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
*
*/
-function password_save($curpass, $passwd)
+class rcube_ldap_password
{
- $rcmail = rcmail::get_instance();
- require_once ('Net/LDAP2.php');
+ public function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
+ require_once 'Net/LDAP2.php';
- // Building user DN
- if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) {
- $userDN = substitute_vars($userDN);
- } else {
- $userDN = search_userdn($rcmail);
- }
+ // Building user DN
+ if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) {
+ $userDN = $this->substitute_vars($userDN);
+ } else {
+ $userDN = $this->search_userdn($rcmail);
+ }
- if (empty($userDN)) {
- return PASSWORD_CONNECT_ERROR;
- }
+ if (empty($userDN)) {
+ 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 = $userDN;
- $bindpw = $curpass;
- break;
- }
+ // 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 = $userDN;
+ $bindpw = $curpass;
+ break;
+ }
- // Configuration array
- $ldapConfig = array (
- 'binddn' => $binddn,
- 'bindpw' => $bindpw,
- 'basedn' => $rcmail->config->get('password_ldap_basedn'),
- 'host' => $rcmail->config->get('password_ldap_host'),
- 'port' => $rcmail->config->get('password_ldap_port'),
- 'starttls' => $rcmail->config->get('password_ldap_starttls'),
- 'version' => $rcmail->config->get('password_ldap_version'),
- );
+ // Configuration array
+ $ldapConfig = array (
+ 'binddn' => $binddn,
+ 'bindpw' => $bindpw,
+ 'basedn' => $rcmail->config->get('password_ldap_basedn'),
+ 'host' => $rcmail->config->get('password_ldap_host'),
+ 'port' => $rcmail->config->get('password_ldap_port'),
+ 'starttls' => $rcmail->config->get('password_ldap_starttls'),
+ 'version' => $rcmail->config->get('password_ldap_version'),
+ );
- // Connecting using the configuration array
- $ldap = Net_LDAP2::connect($ldapConfig);
+ // Connecting using the configuration array
+ $ldap = Net_LDAP2::connect($ldapConfig);
- // Checking for connection error
- if (PEAR::isError($ldap)) {
- return PASSWORD_CONNECT_ERROR;
- }
+ // Checking for connection error
+ if (PEAR::isError($ldap)) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- $crypted_pass = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage'));
- $force = $rcmail->config->get('password_ldap_force_replace');
- $pwattr = $rcmail->config->get('password_ldap_pwattr');
- $lchattr = $rcmail->config->get('password_ldap_lchattr');
- $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr');
- $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr');
- $samba = $rcmail->config->get('password_ldap_samba');
+ $crypted_pass = $this->hashPassword($passwd, $rcmail->config->get('password_ldap_encodage'));
+ $force = $rcmail->config->get('password_ldap_force_replace');
+ $pwattr = $rcmail->config->get('password_ldap_pwattr');
+ $lchattr = $rcmail->config->get('password_ldap_lchattr');
+ $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr');
+ $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr');
+ $samba = $rcmail->config->get('password_ldap_samba');
- // Support password_ldap_samba option for backward compat.
- if ($samba && !$smbpwattr) {
- $smbpwattr = 'sambaNTPassword';
- $smblchattr = 'sambaPwdLastSet';
- }
+ // Support password_ldap_samba option for backward compat.
+ if ($samba && !$smbpwattr) {
+ $smbpwattr = 'sambaNTPassword';
+ $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 = hashPassword($passwd, 'samba'))) {
- return PASSWORD_CRYPT_ERROR;
- }
+ // Crypt new samba password
+ if ($smbpwattr && !($samba_pass = $this->hashPassword($passwd, 'samba'))) {
+ return PASSWORD_CRYPT_ERROR;
+ }
- // Writing new crypted password to LDAP
- $userEntry = $ldap->getEntry($userDN);
- if (Net_LDAP2::isError($userEntry)) {
- return PASSWORD_CONNECT_ERROR;
- }
+ // Writing new crypted password to LDAP
+ $userEntry = $ldap->getEntry($userDN);
+ if (Net_LDAP2::isError($userEntry)) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- if (!$userEntry->replace(array($pwattr => $crypted_pass), $force)) {
- return PASSWORD_CONNECT_ERROR;
- }
+ if (!$userEntry->replace(array($pwattr => $crypted_pass), $force)) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- // Updating PasswordLastChange Attribute if desired
- if ($lchattr) {
- $current_day = (int)(time() / 86400);
- if (!$userEntry->replace(array($lchattr => $current_day), $force)) {
- return PASSWORD_CONNECT_ERROR;
- }
- }
+ // Updating PasswordLastChange Attribute if desired
+ if ($lchattr) {
+ $current_day = (int)(time() / 86400);
+ if (!$userEntry->replace(array($lchattr => $current_day), $force)) {
+ return PASSWORD_CONNECT_ERROR;
+ }
+ }
- // Update Samba password and last change fields
- if ($smbpwattr) {
- $userEntry->replace(array($smbpwattr => $samba_pass), $force);
- }
- // Update Samba password last change field
- if ($smblchattr) {
- $userEntry->replace(array($smblchattr => time()), $force);
- }
+ // Update Samba password and last change fields
+ if ($smbpwattr) {
+ $userEntry->replace(array($smbpwattr => $samba_pass), $force);
+ }
+ // Update Samba password last change field
+ if ($smblchattr) {
+ $userEntry->replace(array($smblchattr => time()), $force);
+ }
- if (Net_LDAP2::isError($userEntry->update())) {
- return PASSWORD_CONNECT_ERROR;
- }
+ if (Net_LDAP2::isError($userEntry->update())) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- // All done, no error
- return PASSWORD_SUCCESS;
-}
+ // All done, no error
+ return PASSWORD_SUCCESS;
+ }
-/**
- * Bind with searchDN and searchPW and search for the user's DN.
- * Use search_base and search_filter defined in config file.
- * Return the found DN.
- */
-function search_userdn($rcmail)
-{
- $ldapConfig = array (
- 'binddn' => $rcmail->config->get('password_ldap_searchDN'),
- 'bindpw' => $rcmail->config->get('password_ldap_searchPW'),
- 'basedn' => $rcmail->config->get('password_ldap_basedn'),
- 'host' => $rcmail->config->get('password_ldap_host'),
- 'port' => $rcmail->config->get('password_ldap_port'),
- 'starttls' => $rcmail->config->get('password_ldap_starttls'),
- 'version' => $rcmail->config->get('password_ldap_version'),
- );
+ /**
+ * Bind with searchDN and searchPW and search for the user's DN.
+ * Use search_base and search_filter defined in config file.
+ * Return the found DN.
+ */
+ function search_userdn($rcmail)
+ {
+ $ldapConfig = array (
+ 'binddn' => $rcmail->config->get('password_ldap_searchDN'),
+ 'bindpw' => $rcmail->config->get('password_ldap_searchPW'),
+ 'basedn' => $rcmail->config->get('password_ldap_basedn'),
+ 'host' => $rcmail->config->get('password_ldap_host'),
+ 'port' => $rcmail->config->get('password_ldap_port'),
+ 'starttls' => $rcmail->config->get('password_ldap_starttls'),
+ 'version' => $rcmail->config->get('password_ldap_version'),
+ );
- $ldap = Net_LDAP2::connect($ldapConfig);
+ $ldap = Net_LDAP2::connect($ldapConfig);
- if (PEAR::isError($ldap)) {
- return '';
- }
+ if (PEAR::isError($ldap)) {
+ return '';
+ }
- $base = $rcmail->config->get('password_ldap_search_base');
- $filter = substitute_vars($rcmail->config->get('password_ldap_search_filter'));
- $options = array (
+ $base = $rcmail->config->get('password_ldap_search_base');
+ $filter = $this->substitute_vars($rcmail->config->get('password_ldap_search_filter'));
+ $options = array (
'scope' => 'sub',
'attributes' => array(),
- );
+ );
- $result = $ldap->search($base, $filter, $options);
- $ldap->done();
- if (PEAR::isError($result) || ($result->count() != 1)) {
- return '';
- }
+ $result = $ldap->search($base, $filter, $options);
+ $ldap->done();
+ if (PEAR::isError($result) || ($result->count() != 1)) {
+ return '';
+ }
- return $result->current()->dn();
-}
-
-/**
- * Substitute %login, %name, %domain, %dc in $str.
- * See plugin config for details.
- */
-function substitute_vars($str)
-{
- $rcmail = rcmail::get_instance();
- $domain = $rcmail->user->get_username('domain');
- $dc = 'dc='.strtr($domain, array('.' => ',dc=')); // hierarchal domain string
-
- $str = str_replace(array(
- '%login',
- '%name',
- '%domain',
- '%dc',
- ), array(
- $_SESSION['username'],
- $rcmail->user->get_username('local'),
- $domain,
- $dc,
- ), $str
- );
+ return $result->current()->dn();
+ }
- return $str;
-}
+ /**
+ * Substitute %login, %name, %domain, %dc in $str.
+ * See plugin config for details.
+ */
+ function substitute_vars($str)
+ {
+ $rcmail = rcmail::get_instance();
+ $domain = $rcmail->user->get_username('domain');
+ $dc = 'dc='.strtr($domain, array('.' => ',dc=')); // hierarchal domain string
+ $str = str_replace(array(
+ '%login',
+ '%name',
+ '%domain',
+ '%dc',
+ ), array(
+ $_SESSION['username'],
+ $rcmail->user->get_username('local'),
+ $domain,
+ $dc,
+ ), $str
+ );
-/**
- * Code originaly from the phpLDAPadmin development team
- * http://phpldapadmin.sourceforge.net/
- *
- * Hashes a password and returns the hash based on the specified enc_type.
- *
- * @param string $passwordClear The password to hash in clear text.
- * @param string $encodageType Standard LDAP encryption type which must be one of
- * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear.
- * @return string The hashed password.
- *
- */
+ return $str;
+ }
-function hashPassword( $passwordClear, $encodageType )
-{
- $encodageType = strtolower( $encodageType );
- switch( $encodageType ) {
- case 'crypt':
- $cryptedPassword = '{CRYPT}' . crypt($passwordClear,randomSalt(2));
+ /**
+ * Code originaly from the phpLDAPadmin development team
+ * http://phpldapadmin.sourceforge.net/
+ *
+ * Hashes a password and returns the hash based on the specified enc_type.
+ *
+ * @param string $passwordClear The password to hash in clear text.
+ * @param string $encodageType Standard LDAP encryption type which must be one of
+ * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear.
+ * @return string The hashed password.
+ *
+ */
+ function hashPassword( $passwordClear, $encodageType )
+ {
+ $encodageType = strtolower( $encodageType );
+ switch( $encodageType ) {
+ case 'crypt':
+ $cryptedPassword = '{CRYPT}' . crypt($passwordClear, $this->randomSalt(2));
break;
case 'ext_des':
@@ -214,7 +214,7 @@ function hashPassword( $passwordClear, $encodageType )
// Your system crypt library does not support extended DES encryption.
return FALSE;
}
- $cryptedPassword = '{CRYPT}' . crypt( $passwordClear, '_' . randomSalt(8) );
+ $cryptedPassword = '{CRYPT}' . crypt( $passwordClear, '_' . $this->randomSalt(8) );
break;
case 'md5crypt':
@@ -222,7 +222,7 @@ function hashPassword( $passwordClear, $encodageType )
// Your system crypt library does not support md5crypt encryption.
return FALSE;
}
- $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$1$' . randomSalt(9) );
+ $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$1$' . $this->randomSalt(9) );
break;
case 'blowfish':
@@ -231,7 +231,7 @@ function hashPassword( $passwordClear, $encodageType )
return FALSE;
}
// hardcoded to second blowfish version and set number of rounds
- $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$2a$12$' . randomSalt(13) );
+ $cryptedPassword = '{CRYPT}' . crypt( $passwordClear , '$2a$12$' . $this->randomSalt(13) );
break;
case 'md5':
@@ -282,37 +282,38 @@ function hashPassword( $passwordClear, $encodageType )
case 'clear':
default:
$cryptedPassword = $passwordClear;
- }
+ }
- return $cryptedPassword;
-}
+ return $cryptedPassword;
+ }
-/**
- * Code originaly from the phpLDAPadmin development team
- * http://phpldapadmin.sourceforge.net/
- *
- * Used to generate a random salt for crypt-style passwords. Salt strings are used
- * to make pre-built hash cracking dictionaries difficult to use as the hash algorithm uses
- * not only the user's password but also a randomly generated string. The string is
- * stored as the first N characters of the hash for reference of hashing algorithms later.
- *
- * --- added 20021125 by bayu irawan <bayuir@divnet.telkom.co.id> ---
- * --- ammended 20030625 by S C Rigler <srigler@houston.rr.com> ---
- *
- * @param int $length The length of the salt string to generate.
- * @return string The generated salt string.
- */
-function randomSalt( $length )
-{
- $possible = '0123456789'.
- 'abcdefghijklmnopqrstuvwxyz'.
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
- './';
- $str = '';
-// mt_srand((double)microtime() * 1000000);
+ /**
+ * Code originaly from the phpLDAPadmin development team
+ * http://phpldapadmin.sourceforge.net/
+ *
+ * Used to generate a random salt for crypt-style passwords. Salt strings are used
+ * to make pre-built hash cracking dictionaries difficult to use as the hash algorithm uses
+ * not only the user's password but also a randomly generated string. The string is
+ * stored as the first N characters of the hash for reference of hashing algorithms later.
+ *
+ * --- added 20021125 by bayu irawan <bayuir@divnet.telkom.co.id> ---
+ * --- ammended 20030625 by S C Rigler <srigler@houston.rr.com> ---
+ *
+ * @param int $length The length of the salt string to generate.
+ * @return string The generated salt string.
+ */
+ function randomSalt( $length )
+ {
+ $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/ldap_simple.php b/plugins/password/drivers/ldap_simple.php
index 2f51b7547..e1daed9f3 100644
--- a/plugins/password/drivers/ldap_simple.php
+++ b/plugins/password/drivers/ldap_simple.php
@@ -6,48 +6,52 @@
* Driver for passwords stored in LDAP
* This driver is based on Edouard's LDAP Password Driver, but does not
* require PEAR's Net_LDAP2 to be installed
- *
- * @version 1.0 (2010-07-31)
+ *
+ * @version 2.0
* @author Wout Decre <wout@canodus.be>
*/
-function password_save($curpass, $passwd)
+
+class rcube_ldap_simple_password
{
- $rcmail = rcmail::get_instance();
+ 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;
- }
+ // 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;
- }
+ // 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;
- }
- }
+ // 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 = ldap_simple_substitute_vars($user_dn);
- } else {
- $user_dn = ldap_simple_search_userdn($rcmail, $ds);
- }
+ // 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;
- }
+ if (empty($user_dn)) {
+ ldap_unbind($ds);
+ return PASSWORD_CONNECT_ERROR;
+ }
- // Connection method
- switch ($rcmail->config->get('password_ldap_method')) {
+ // 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');
@@ -57,126 +61,125 @@ function password_save($curpass, $passwd)
$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');
- $crypted_pass = ldap_simple_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');
+ // Support password_ldap_samba option for backward compat.
+ if ($samba && !$smbpwattr) {
+ $smbpwattr = 'sambaNTPassword';
+ $smblchattr = 'sambaPwdLastSet';
+ }
- // Support password_ldap_samba option for backward compat.
- if ($samba && !$smbpwattr) {
- $smbpwattr = 'sambaNTPassword';
- $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;
+ }
- // Crypt new Samba password
- if ($smbpwattr && !($samba_pass = ldap_simple_hash_password($passwd, 'samba'))) {
- 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) {
+ $entree[$smbpwattr] = $samba_pass;
+ }
- // Update Samba password
- if ($smbpwattr) {
- $entree[$smbpwattr] = $samba_pass;
- }
+ // Update Samba password last change
+ if ($smblchattr) {
+ $entree[$smblchattr] = time();
+ }
- // Update Samba password last change
- if ($smblchattr) {
- $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;
-}
+ /**
+ * Bind with searchDN and searchPW and search for the user's DN
+ * Use search_base and search_filter defined in config file
+ * Return the found DN
+ */
+ function search_userdn($rcmail, $ds)
+ {
+ /* Bind */
+ if (!ldap_bind($ds, $rcmail->config->get('password_ldap_searchDN'), $rcmail->config->get('password_ldap_searchPW'))) {
+ return false;
+ }
-/**
- * Bind with searchDN and searchPW and search for the user's DN
- * Use search_base and search_filter defined in config file
- * Return the found DN
- */
-function ldap_simple_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;
+ }
- /* Search for the DN */
- if (!$sr = ldap_search($ds, $rcmail->config->get('password_ldap_search_base'), ldap_simple_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;
+ }
- /* 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));
+ }
- return ldap_get_dn($ds, ldap_first_entry($ds, $sr));
-}
+ /**
+ * Substitute %login, %name, %domain, %dc in $str
+ * See plugin config for details
+ */
+ function substitute_vars($str)
+ {
+ $str = str_replace('%login', $_SESSION['username'], $str);
+ $str = str_replace('%l', $_SESSION['username'], $str);
-/**
- * Substitute %login, %name, %domain, %dc in $str
- * See plugin config for details
- */
-function ldap_simple_substitute_vars($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) {
+ $dc = 'dc='.strtr($parts[1], array('.' => ',dc=')); // hierarchal domain string
- if (count($parts) == 2) {
- $dc = 'dc='.strtr($parts[1], array('.' => ',dc=')); // hierarchal domain string
+ $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('%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);
- }
-
- return $str;
-}
+ return $str;
+ }
-/**
- * Code originaly from the phpLDAPadmin development team
- * http://phpldapadmin.sourceforge.net/
- *
- * Hashes a password and returns the hash based on the specified enc_type
- */
-function ldap_simple_hash_password($password_clear, $encodage_type)
-{
- $encodage_type = strtolower($encodage_type);
- switch ($encodage_type) {
+ /**
+ * Code originaly from the phpLDAPadmin development team
+ * http://phpldapadmin.sourceforge.net/
+ *
+ * Hashes a password and returns the hash based on the specified enc_type
+ */
+ function hash_password($password_clear, $encodage_type)
+ {
+ $encodage_type = strtolower($encodage_type);
+ switch ($encodage_type) {
case 'crypt':
- $crypted_password = '{CRYPT}' . crypt($password_clear, ldap_simple_random_salt(2));
+ $crypted_password = '{CRYPT}' . crypt($password_clear, $this->random_salt(2));
break;
case 'ext_des':
/* Extended DES crypt. see OpenBSD crypt man page */
@@ -184,14 +187,14 @@ function ldap_simple_hash_password($password_clear, $encodage_type)
/* Your system crypt library does not support extended DES encryption */
return false;
}
- $crypted_password = '{CRYPT}' . crypt($password_clear, '_' . ldap_simple_random_salt(8));
+ $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$' . ldap_simple_random_salt(9));
+ $crypted_password = '{CRYPT}' . crypt($password_clear, '$1$' . $this->random_salt(9));
break;
case 'blowfish':
if (!defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) {
@@ -199,7 +202,7 @@ function ldap_simple_hash_password($password_clear, $encodage_type)
return false;
}
/* Hardcoded to second blowfish version and set number of rounds */
- $crypted_password = '{CRYPT}' . crypt($password_clear, '$2a$12$' . ldap_simple_random_salt(13));
+ $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)));
@@ -247,25 +250,27 @@ function ldap_simple_hash_password($password_clear, $encodage_type)
case 'clear':
default:
$crypted_password = $password_clear;
- }
+ }
- return $crypted_password;
-}
+ return $crypted_password;
+ }
-/**
- * Code originaly from the phpLDAPadmin development team
- * http://phpldapadmin.sourceforge.net/
- *
- * Used to generate a random salt for crypt-style passwords
- */
-function ldap_simple_random_salt($length)
-{
- $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './';
- $str = '';
- // mt_srand((double)microtime() * 1000000);
- while (strlen($str) < $length) {
- $str .= substr($possible, (rand() % strlen($possible)), 1);
- }
+ /**
+ * Code originaly from the phpLDAPadmin development team
+ * http://phpldapadmin.sourceforge.net/
+ *
+ * Used to generate a random salt for crypt-style passwords
+ */
+ function random_salt($length)
+ {
+ $possible = '0123456789' . 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . './';
+ $str = '';
+ // mt_srand((double)microtime() * 1000000);
+
+ while (strlen($str) < $length) {
+ $str .= substr($possible, (rand() % strlen($possible)), 1);
+ }
- return $str;
+ return $str;
+ }
}
diff --git a/plugins/password/drivers/pam.php b/plugins/password/drivers/pam.php
index e9363cc5a..ed60bd841 100644
--- a/plugins/password/drivers/pam.php
+++ b/plugins/password/drivers/pam.php
@@ -3,18 +3,29 @@
/**
* PAM Password Driver
*
- * @version 1.0
+ * @version 2.0
* @author Aleksander Machniak
*/
-
-function password_save($currpass, $newpass)
+
+class rcube_pam_password
{
- $user = $_SESSION['username'];
+ function save($currpass, $newpass)
+ {
+ $user = $_SESSION['username'];
- if (extension_loaded('pam')) {
- if (pam_auth($user, $currpass, $error, false)) {
- if (pam_chpass($user, $currpass, $newpass)) {
- return PASSWORD_SUCCESS;
+ if (extension_loaded('pam')) {
+ if (pam_auth($user, $currpass, $error, false)) {
+ if (pam_chpass($user, $currpass, $newpass)) {
+ return PASSWORD_SUCCESS;
+ }
+ }
+ else {
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: PAM authentication failed for user $user: $error"
+ ), true, false);
}
}
else {
@@ -22,20 +33,10 @@ function password_save($currpass, $newpass)
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: PAM authentication failed for user $user: $error"
+ 'message' => "Password plugin: PECL-PAM module not loaded"
), true, false);
}
- }
- else {
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: PECL-PAM module not loaded"
- ), true, false);
- }
- return PASSWORD_ERROR;
+ return PASSWORD_ERROR;
+ }
}
-
-?>
diff --git a/plugins/password/drivers/poppassd.php b/plugins/password/drivers/poppassd.php
index fc105de47..e18ec2660 100644
--- a/plugins/password/drivers/poppassd.php
+++ b/plugins/password/drivers/poppassd.php
@@ -5,58 +5,61 @@
*
* Driver to change passwords via Poppassd/Courierpassd
*
- * @version 1.1
+ * @version 2.0
* @author Philip Weir
*
*/
-function format_error_result($code, $line)
+class rcube_poppassd_password
{
- if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) {
- return array('code' => $code, 'message' => $matches[1]);
- } else {
- return $code;
+ function format_error_result($code, $line)
+ {
+ if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) {
+ return array('code' => $code, 'message' => $matches[1]);
+ } else {
+ return $code;
+ }
}
-}
-function password_save($curpass, $passwd)
-{
- $rcmail = rcmail::get_instance();
+ function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
// include('Net/Socket.php');
- $poppassd = new Net_Socket();
+ $poppassd = new Net_Socket();
- $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null);
- if (PEAR::isError($result)) {
- return format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage());
- }
- else {
- $result = $poppassd->readLine();
- if(!preg_match('/^2\d\d/', $result)) {
- $poppassd->disconnect();
- return format_error_result(PASSWORD_ERROR, $result);
+ $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null);
+ if (PEAR::isError($result)) {
+ return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage());
}
else {
- $poppassd->writeLine("user ". $_SESSION['username']);
$result = $poppassd->readLine();
- if(!preg_match('/^[23]\d\d/', $result) ) {
+ if(!preg_match('/^2\d\d/', $result)) {
$poppassd->disconnect();
- return format_error_result(PASSWORD_CONNECT_ERROR, $result);
+ return $this->format_error_result(PASSWORD_ERROR, $result);
}
else {
- $poppassd->writeLine("pass ". $curpass);
+ $poppassd->writeLine("user ". $_SESSION['username']);
$result = $poppassd->readLine();
if(!preg_match('/^[23]\d\d/', $result) ) {
$poppassd->disconnect();
- return format_error_result(PASSWORD_ERROR, $result);
+ return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result);
}
else {
- $poppassd->writeLine("newpass ". $passwd);
+ $poppassd->writeLine("pass ". $curpass);
$result = $poppassd->readLine();
- $poppassd->disconnect();
- if (!preg_match('/^2\d\d/', $result))
- return format_error_result(PASSWORD_ERROR, $result);
- else
- return PASSWORD_SUCCESS;
+ if(!preg_match('/^[23]\d\d/', $result) ) {
+ $poppassd->disconnect();
+ return $this->format_error_result(PASSWORD_ERROR, $result);
+ }
+ else {
+ $poppassd->writeLine("newpass ". $passwd);
+ $result = $poppassd->readLine();
+ $poppassd->disconnect();
+ if (!preg_match('/^2\d\d/', $result))
+ return $this->format_error_result(PASSWORD_ERROR, $result);
+ else
+ return PASSWORD_SUCCESS;
+ }
}
}
}
diff --git a/plugins/password/drivers/sasl.php b/plugins/password/drivers/sasl.php
index f8ac5c606..3e6fe1c8b 100644
--- a/plugins/password/drivers/sasl.php
+++ b/plugins/password/drivers/sasl.php
@@ -12,33 +12,34 @@
*
* For installation instructions please read the README file.
*
- * @version 1.0
+ * @version 2.0
* @author Thomas Bruederli
*/
-
-function password_save($currpass, $newpass)
+
+class rcube_sasl_password
{
- $curdir = realpath(dirname(__FILE__));
- $username = escapeshellcmd($_SESSION['username']);
- $args = rcmail::get_instance()->config->get('password_saslpasswd_args', '');
+ function save($currpass, $newpass)
+ {
+ $curdir = realpath(dirname(__FILE__));
+ $username = escapeshellcmd($_SESSION['username']);
+ $args = rcmail::get_instance()->config->get('password_saslpasswd_args', '');
- if ($fh = popen("$curdir/chgsaslpasswd -p $args $username", 'w')) {
- fwrite($fh, $newpass."\n");
- $code = pclose($fh);
+ if ($fh = popen("$curdir/chgsaslpasswd -p $args $username", 'w')) {
+ fwrite($fh, $newpass."\n");
+ $code = pclose($fh);
- if ($code == 0)
- return PASSWORD_SUCCESS;
- }
- else {
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to execute $curdir/chgsaslpasswd"
- ), true, false);
- }
+ if ($code == 0)
+ return PASSWORD_SUCCESS;
+ }
+ else {
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: Unable to execute $curdir/chgsaslpasswd"
+ ), true, false);
+ }
- return PASSWORD_ERROR;
+ return PASSWORD_ERROR;
+ }
}
-
-?>
diff --git a/plugins/password/drivers/sql.php b/plugins/password/drivers/sql.php
index 06a6b75ff..e9207300e 100644
--- a/plugins/password/drivers/sql.php
+++ b/plugins/password/drivers/sql.php
@@ -5,170 +5,171 @@
*
* Driver for passwords stored in SQL database
*
- * @version 1.4
+ * @version 2.0
* @author Aleksander 'A.L.E.C' Machniak <alec@alec.pl>
*
*/
-function password_save($curpass, $passwd)
+class rcube_sql_password
{
- $rcmail = rcmail::get_instance();
+ function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
- if (!($sql = $rcmail->config->get('password_query')))
- $sql = 'SELECT update_passwd(%c, %u)';
+ if (!($sql = $rcmail->config->get('password_query')))
+ $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';
+ 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';
- $db = new rcube_mdb2($dsn, '', FALSE);
- $db->set_debug((bool)$rcmail->config->get('sql_debug'));
- $db->db_connect('w');
- } else {
- $db = $rcmail->get_dbh();
- }
-
- if ($err = $db->is_error())
- return PASSWORD_ERROR;
-
- // crypted password
- if (strpos($sql, '%c') !== FALSE) {
- $salt = '';
- if (CRYPT_MD5) {
- // Always use eight salt characters for MD5 (#1488136)
- $len = 8;
- } else if (CRYPT_STD_DES) {
- $len = 2;
- } else {
- return PASSWORD_CRYPT_ERROR;
+ $db = new rcube_mdb2($dsn, '', FALSE);
+ $db->set_debug((bool)$rcmail->config->get('sql_debug'));
+ $db->db_connect('w');
}
-
- //Restrict the character set used as salt (#1488136)
- $seedchars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- for ($i = 0; $i < $len ; $i++) {
- $salt .= $seedchars[rand(0, 63)];
+ else {
+ $db = $rcmail->get_dbh();
}
- $sql = str_replace('%c', $db->quote(crypt($passwd, CRYPT_MD5 ? '$1$'.$salt.'$' : $salt)), $sql);
- }
+ if ($err = $db->is_error())
+ return PASSWORD_ERROR;
- // dovecotpw
- if (strpos($sql, '%D') !== FALSE) {
- if (!($dovecotpw = $rcmail->config->get('password_dovecotpw')))
- $dovecotpw = 'dovecotpw';
- if (!($method = $rcmail->config->get('password_dovecotpw_method')))
- $method = 'CRAM-MD5';
+ // crypted password
+ if (strpos($sql, '%c') !== FALSE) {
+ $salt = '';
+ if (CRYPT_MD5) {
+ // Always use eight salt characters for MD5 (#1488136)
+ $len = 8;
+ } else if (CRYPT_STD_DES) {
+ $len = 2;
+ } else {
+ return PASSWORD_CRYPT_ERROR;
+ }
- // use common temp dir
- $tmp_dir = $rcmail->config->get('temp_dir');
- $tmpfile = tempnam($tmp_dir, 'roundcube-');
+ //Restrict the character set used as salt (#1488136)
+ $seedchars = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+ for ($i = 0; $i < $len ; $i++) {
+ $salt .= $seedchars[rand(0, 63)];
+ }
- $pipe = popen("$dovecotpw -s '$method' > '$tmpfile'", "w");
- if (!$pipe) {
- unlink($tmpfile);
- return PASSWORD_CRYPT_ERROR;
+ $sql = str_replace('%c', $db->quote(crypt($passwd, CRYPT_MD5 ? '$1$'.$salt.'$' : $salt)), $sql);
}
- else {
- fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); usleep(1000);
- fwrite($pipe, $passwd . "\n", 1+strlen($passwd));
- pclose($pipe);
- $newpass = trim(file_get_contents($tmpfile), "\n");
- if (!preg_match('/^\{' . $method . '\}/', $newpass)) {
+
+ // dovecotpw
+ if (strpos($sql, '%D') !== FALSE) {
+ if (!($dovecotpw = $rcmail->config->get('password_dovecotpw')))
+ $dovecotpw = 'dovecotpw';
+ if (!($method = $rcmail->config->get('password_dovecotpw_method')))
+ $method = 'CRAM-MD5';
+
+ // use common temp dir
+ $tmp_dir = $rcmail->config->get('temp_dir');
+ $tmpfile = tempnam($tmp_dir, 'roundcube-');
+
+ $pipe = popen("$dovecotpw -s '$method' > '$tmpfile'", "w");
+ if (!$pipe) {
+ unlink($tmpfile);
return PASSWORD_CRYPT_ERROR;
}
- if (!$rcmail->config->get('password_dovecotpw_with_method'))
- $newpass = trim(str_replace('{' . $method . '}', '', $newpass));
- unlink($tmpfile);
+ else {
+ fwrite($pipe, $passwd . "\n", 1+strlen($passwd)); usleep(1000);
+ fwrite($pipe, $passwd . "\n", 1+strlen($passwd));
+ pclose($pipe);
+ $newpass = trim(file_get_contents($tmpfile), "\n");
+ if (!preg_match('/^\{' . $method . '\}/', $newpass)) {
+ return PASSWORD_CRYPT_ERROR;
+ }
+ if (!$rcmail->config->get('password_dovecotpw_with_method'))
+ $newpass = trim(str_replace('{' . $method . '}', '', $newpass));
+ unlink($tmpfile);
+ }
+ $sql = str_replace('%D', $db->quote($newpass), $sql);
}
- $sql = str_replace('%D', $db->quote($newpass), $sql);
- }
- // hashed passwords
- if (preg_match('/%[n|q]/', $sql)) {
+ // 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);
- 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;
+ }
- return PASSWORD_ERROR;
- }
+ if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm'))))
+ $hash_algo = 'sha1';
- if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm'))))
- $hash_algo = 'sha1';
+ $hash_passwd = hash($hash_algo, $passwd);
+ $hash_curpass = hash($hash_algo, $curpass);
- $hash_passwd = hash($hash_algo, $passwd);
- $hash_curpass = hash($hash_algo, $curpass);
+ if ($rcmail->config->get('password_hash_base64')) {
+ $hash_passwd = base64_encode(pack('H*', $hash_passwd));
+ $hash_curpass = base64_encode(pack('H*', $hash_curpass));
+ }
- 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)
- $sql_vars = array();
- if (preg_match_all('/%[p|o]/', $sql, $m)) {
- foreach ($m[0] as $var) {
- if ($var == '%p') {
- $sql = preg_replace('/%p/', '?', $sql, 1);
- $sql_vars[] = (string) $passwd;
- }
- else { // %o
- $sql = preg_replace('/%o/', '?', $sql, 1);
- $sql_vars[] = (string) $curpass;
+ // Handle clear text passwords securely (#1487034)
+ $sql_vars = array();
+ if (preg_match_all('/%[p|o]/', $sql, $m)) {
+ foreach ($m[0] as $var) {
+ if ($var == '%p') {
+ $sql = preg_replace('/%p/', '?', $sql, 1);
+ $sql_vars[] = (string) $passwd;
+ }
+ else { // %o
+ $sql = preg_replace('/%o/', '?', $sql, 1);
+ $sql_vars[] = (string) $curpass;
+ }
}
}
- }
- $local_part = $rcmail->user->get_username('local');
- $domain_part = $rcmail->user->get_username('domain');
- $username = $_SESSION['username'];
- $host = $_SESSION['imap_host'];
+ $local_part = $rcmail->user->get_username('local');
+ $domain_part = $rcmail->user->get_username('domain');
+ $username = $_SESSION['username'];
+ $host = $_SESSION['imap_host'];
- // convert domains to/from punnycode
- if ($rcmail->config->get('password_idn_ascii')) {
- $domain_part = rcube_idn_to_ascii($domain_part);
- $username = rcube_idn_to_ascii($username);
- $host = rcube_idn_to_ascii($host);
- }
- else {
- $domain_part = rcube_idn_to_utf8($domain_part);
- $username = rcube_idn_to_utf8($username);
- $host = rcube_idn_to_utf8($host);
- }
+ // convert domains to/from punnycode
+ if ($rcmail->config->get('password_idn_ascii')) {
+ $domain_part = rcube_idn_to_ascii($domain_part);
+ $username = rcube_idn_to_ascii($username);
+ $host = rcube_idn_to_ascii($host);
+ }
+ else {
+ $domain_part = rcube_idn_to_utf8($domain_part);
+ $username = rcube_idn_to_utf8($username);
+ $host = rcube_idn_to_utf8($host);
+ }
- // at least we should always have the local part
- $sql = str_replace('%l', $db->quote($local_part, 'text'), $sql);
- $sql = str_replace('%d', $db->quote($domain_part, 'text'), $sql);
- $sql = str_replace('%u', $db->quote($username, 'text'), $sql);
- $sql = str_replace('%h', $db->quote($host, 'text'), $sql);
+ // at least we should always have the local part
+ $sql = str_replace('%l', $db->quote($local_part, 'text'), $sql);
+ $sql = str_replace('%d', $db->quote($domain_part, 'text'), $sql);
+ $sql = str_replace('%u', $db->quote($username, 'text'), $sql);
+ $sql = str_replace('%h', $db->quote($host, 'text'), $sql);
- $res = $db->query($sql, $sql_vars);
+ $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 {
- // This is the good case: 1 row updated
- 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?
- }
- }
+ if (!$db->is_error()) {
+ 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;
+ // @TODO: Some queries don't affect any rows
+ // Should we assume a success if there was no error?
+ }
+ }
- return PASSWORD_ERROR;
+ return PASSWORD_ERROR;
+ }
}
-
-?>
diff --git a/plugins/password/drivers/virtualmin.php b/plugins/password/drivers/virtualmin.php
index 78ef4e7c3..5a9d9c0ca 100644
--- a/plugins/password/drivers/virtualmin.php
+++ b/plugins/password/drivers/virtualmin.php
@@ -10,18 +10,20 @@
* It only works with virtualmin on the same host where Roundcube runs
* and requires shell access and gcc in order to compile the binary.
*
- * @version 2.0
+ * @version 3.0
* @author Martijn de Munnik
*/
-function password_save($currpass, $newpass)
+class rcube_virtualmin_password
{
- $rcmail = rcmail::get_instance();
+ function save($currpass, $newpass)
+ {
+ $rcmail = rcmail::get_instance();
- $format = $rcmail->config->get('password_virtualmin_format', 0);
- $username = $_SESSION['username'];
+ $format = $rcmail->config->get('password_virtualmin_format', 0);
+ $username = $_SESSION['username'];
- switch ($format) {
+ switch ($format) {
case 1: // username%domain
$domain = substr(strrchr($username, "%"), 1);
break;
@@ -48,28 +50,27 @@ function password_save($currpass, $newpass)
break;
default: // username@domain
$domain = substr(strrchr($username, "@"), 1);
- }
-
- $username = escapeshellcmd($username);
- $domain = escapeshellcmd($domain);
- $newpass = escapeshellcmd($newpass);
- $curdir = realpath(dirname(__FILE__));
+ }
- exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
+ $username = escapeshellcmd($username);
+ $domain = escapeshellcmd($domain);
+ $newpass = escapeshellcmd($newpass);
+ $curdir = realpath(dirname(__FILE__));
- if ($returnvalue == 0) {
- return PASSWORD_SUCCESS;
- }
- else {
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
- ), true, false);
- }
+ exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
- return PASSWORD_ERROR;
-}
+ if ($returnvalue == 0) {
+ return PASSWORD_SUCCESS;
+ }
+ else {
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
+ ), true, false);
+ }
-?>
+ return PASSWORD_ERROR;
+ }
+}
diff --git a/plugins/password/drivers/vpopmaild.php b/plugins/password/drivers/vpopmaild.php
index b6fb39343..510cf3338 100644
--- a/plugins/password/drivers/vpopmaild.php
+++ b/plugins/password/drivers/vpopmaild.php
@@ -5,47 +5,49 @@
*
* Driver to change passwords via vpopmaild
*
- * @version 1.1
+ * @version 2.0
* @author Johannes Hessellund
*
*/
-function password_save($curpass, $passwd)
+class rcube_vpopmaild_password
{
- $rcmail = rcmail::get_instance();
-// include('Net/Socket.php');
- $vpopmaild = new Net_Socket();
+ function save($curpass, $passwd)
+ {
+ $rcmail = rcmail::get_instance();
+ // include('Net/Socket.php');
+ $vpopmaild = new Net_Socket();
- if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'),
- $rcmail->config->get('password_vpopmaild_port'), null))) {
- return PASSWORD_CONNECT_ERROR;
- }
+ if (PEAR::isError($vpopmaild->connect($rcmail->config->get('password_vpopmaild_host'),
+ $rcmail->config->get('password_vpopmaild_port'), null))) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- $result = $vpopmaild->readLine();
- if(!preg_match('/^\+OK/', $result)) {
- $vpopmaild->disconnect();
- return PASSWORD_CONNECT_ERROR;
- }
+ $result = $vpopmaild->readLine();
+ if(!preg_match('/^\+OK/', $result)) {
+ $vpopmaild->disconnect();
+ return PASSWORD_CONNECT_ERROR;
+ }
+
+ $vpopmaild->writeLine("slogin ". $_SESSION['username'] . " " . $curpass);
+ $result = $vpopmaild->readLine();
+
+ if(!preg_match('/^\+OK/', $result) ) {
+ $vpopmaild->writeLine("quit");
+ $vpopmaild->disconnect();
+ return PASSWORD_ERROR;
+ }
- $vpopmaild->writeLine("slogin ". $_SESSION['username'] . " " . $curpass);
- $result = $vpopmaild->readLine();
- if(!preg_match('/^\+OK/', $result) ) {
+ $vpopmaild->writeLine("mod_user ". $_SESSION['username']);
+ $vpopmaild->writeLine("clear_text_password ". $passwd);
+ $vpopmaild->writeLine(".");
+ $result = $vpopmaild->readLine();
$vpopmaild->writeLine("quit");
$vpopmaild->disconnect();
- return PASSWORD_ERROR;
- }
-
- $vpopmaild->writeLine("mod_user ". $_SESSION['username']);
- $vpopmaild->writeLine("clear_text_password ". $passwd);
- $vpopmaild->writeLine(".");
- $result = $vpopmaild->readLine();
- $vpopmaild->writeLine("quit");
- $vpopmaild->disconnect();
- if (!preg_match('/^\+OK/', $result))
- return PASSWORD_ERROR;
+ if (!preg_match('/^\+OK/', $result))
+ return PASSWORD_ERROR;
- return PASSWORD_SUCCESS;
+ return PASSWORD_SUCCESS;
+ }
}
-
-?>
diff --git a/plugins/password/drivers/ximss.php b/plugins/password/drivers/ximss.php
index 94aba1874..3b5286a27 100644
--- a/plugins/password/drivers/ximss.php
+++ b/plugins/password/drivers/ximss.php
@@ -12,25 +12,28 @@
* References:
* http://www.communigate.com/WebGuide/XMLAPI.html
*
- * @version 1
+ * @version 2.0
* @author Erik Meitner <erik wanderings.us>
*/
-
-function password_save($pass, $newpass)
+
+class rcube_ximss_password
{
+ function save($pass, $newpass)
+ {
+ $rcmail = rcmail::get_instance();
+
+ $host = $rcmail->config->get('password_ximss_host');
+ $port = $rcmail->config->get('password_ximss_port');
+ $sock = stream_socket_client("tcp://$host:$port", $errno, $errstr, 30);
+
+ if ($sock === FALSE) {
+ return PASSWORD_CONNECT_ERROR;
+ }
- $rcmail = rcmail::get_instance();
-
- $sock = stream_socket_client("tcp://".$rcmail->config->get('password_ximss_host').":".$rcmail->config->get('password_ximss_port'), $errno, $errstr, 30) ;
- if( $sock === FALSE )
- {
- return PASSWORD_CONNECT_ERROR;
- }
-
- // send all requests at once(pipelined)
- fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");
- fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'" />'."\0");
- fwrite( $sock, '<bye id="A003" />'."\0");
+ // send all requests at once(pipelined)
+ fwrite( $sock, '<login id="A001" authData="'.$_SESSION['username'].'" password="'.$pass.'" />'."\0");
+ fwrite( $sock, '<passwordModify id="A002" oldPassword="'.$pass.'" newPassword="'.$newpass.'" />'."\0");
+ fwrite( $sock, '<bye id="A003" />'."\0");
//example responses
// <session id="A001" urlID="4815-vN2Txjkggy7gjHRD10jw" userName="user@example.com"/>\0
@@ -40,42 +43,34 @@ function password_save($pass, $newpass)
// or an error:
// <response id="A001" errorText="incorrect password or account name" errorNum="515"/>\0
- $responseblob = '';
- while (!feof($sock)) {
- $responseblob .= fgets($sock, 1024);
- }
+ $responseblob = '';
+ while (!feof($sock)) {
+ $responseblob .= fgets($sock, 1024);
+ }
- fclose($sock);
-
- foreach( explode( "\0",$responseblob) as $response )
- {
- $resp = simplexml_load_string("<xml>".$response."</xml>");
+ fclose($sock);
- if( $resp->response[0]['id'] == 'A001' )
- {
- if( isset( $resp->response[0]['errorNum'] ) )
- {
- return PASSWORD_CONNECT_ERROR;
- }
- }
- else if( $resp->response[0]['id'] == 'A002' )
- {
- if( isset( $resp->response[0]['errorNum'] ))
- {
- return PASSWORD_ERROR;
- }
- }
- else if( $resp->response[0]['id'] == 'A003' )
- {
- if( isset($resp->response[0]['errorNum'] ))
- {
- //There was a problem during logout(This is probably harmless)
- }
- }
- } //foreach
+ foreach( explode( "\0",$responseblob) as $response ) {
+ $resp = simplexml_load_string("<xml>".$response."</xml>");
- return PASSWORD_SUCCESS;
-
+ if( $resp->response[0]['id'] == 'A001' ) {
+ if( isset( $resp->response[0]['errorNum'] ) ) {
+ return PASSWORD_CONNECT_ERROR;
+ }
+ }
+ else if( $resp->response[0]['id'] == 'A002' ) {
+ if( isset( $resp->response[0]['errorNum'] )) {
+ return PASSWORD_ERROR;
+ }
+ }
+ else if( $resp->response[0]['id'] == 'A003' ) {
+ if( isset($resp->response[0]['errorNum'] )) {
+ //There was a problem during logout(This is probably harmless)
+ }
+ }
+ } //foreach
+
+ return PASSWORD_SUCCESS;
+
+ }
}
-
-?> \ No newline at end of file
diff --git a/plugins/password/drivers/xmail.php b/plugins/password/drivers/xmail.php
index c7f426158..33a49ffe3 100644
--- a/plugins/password/drivers/xmail.php
+++ b/plugins/password/drivers/xmail.php
@@ -4,7 +4,7 @@
*
* Driver for XMail password
*
- * @version 1.0
+ * @version 2.0
* @author Helio Cavichiolo Jr <helio@hcsistemas.com.br>
*
* Setup xmail_host, xmail_user, xmail_pass and xmail_port into
@@ -17,38 +17,43 @@
*
*/
-function password_save($currpass, $newpass)
+class rcube_xmail_password
{
- $rcmail = rcmail::get_instance();
- list($user,$domain) = explode('@', $_SESSION['username']);
+ function save($currpass, $newpass)
+ {
+ $rcmail = rcmail::get_instance();
+ list($user,$domain) = explode('@', $_SESSION['username']);
- $xmail = new XMail;
+ $xmail = new XMail;
- $xmail->hostname = $rcmail->config->get('xmail_host');
- $xmail->username = $rcmail->config->get('xmail_user');
- $xmail->password = $rcmail->config->get('xmail_pass');
- $xmail->port = $rcmail->config->get('xmail_port');
+ $xmail->hostname = $rcmail->config->get('xmail_host');
+ $xmail->username = $rcmail->config->get('xmail_user');
+ $xmail->password = $rcmail->config->get('xmail_pass');
+ $xmail->port = $rcmail->config->get('xmail_port');
- if (!$xmail->connect()) {
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to connect to mail server"
- ), true, false);
- return PASSWORD_CONNECT_ERROR;
- } else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) {
- $xmail->close();
- raise_error(array(
- 'code' => 600,
- 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to change password"
- ), true, false);
- return PASSWORD_ERROR;
- } else {
- $xmail->close();
- return PASSWORD_SUCCESS;
+ if (!$xmail->connect()) {
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: Unable to connect to mail server"
+ ), true, false);
+ return PASSWORD_CONNECT_ERROR;
+ }
+ else if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) {
+ $xmail->close();
+ raise_error(array(
+ 'code' => 600,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Password plugin: Unable to change password"
+ ), true, false);
+ return PASSWORD_ERROR;
+ }
+ else {
+ $xmail->close();
+ return PASSWORD_SUCCESS;
+ }
}
}
diff --git a/plugins/password/package.xml b/plugins/password/package.xml
index 45688e118..c2a3442dd 100644
--- a/plugins/password/package.xml
+++ b/plugins/password/package.xml
@@ -17,8 +17,8 @@
</lead>
<date>2011-11-23</date>
<version>
- <release>2.4</release>
- <api>1.6</api>
+ <release>3.0</release>
+ <api>2.0</api>
</version>
<stability>
<release>stable</release>
@@ -26,8 +26,7 @@
</stability>
<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license>
<notes>
-- Added option to use punycode or unicode for domain names (#1488103)
-- Save Samba password hashes in capital letters (#1488197)
+- Fixed drivers namespace issues
</notes>
<contents>
<dir baseinstalldir="/" name="/">
@@ -287,5 +286,21 @@
- Improve generated crypt() passwords (#1488136)
</notes>
</release>
+ <release>
+ <date>2011-11-23</date>
+ <version>
+ <release>2.4</release>
+ <api>1.6</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license>
+ <notes>
+- Added option to use punycode or unicode for domain names (#1488103)
+- Save Samba password hashes in capital letters (#1488197)
+ </notes>
+ </release>
</changelog>
</package>
diff --git a/plugins/password/password.php b/plugins/password/password.php
index db513fc0b..5ed08ed42 100644
--- a/plugins/password/password.php
+++ b/plugins/password/password.php
@@ -177,7 +177,7 @@ class password extends rcube_plugin
$field_id = 'curpasswd';
$input_curpasswd = new html_passwordfield(array('name' => '_curpasswd', 'id' => $field_id,
'size' => 20, 'autocomplete' => 'off'));
-
+
$table->add('title', html::label($field_id, Q($this->gettext('curpasswd'))));
$table->add(null, $input_curpasswd->show());
}
@@ -222,31 +222,34 @@ class password extends rcube_plugin
private function _save($curpass, $passwd)
{
$config = rcmail::get_instance()->config;
- $driver = $this->home.'/drivers/'.$config->get('password_driver', 'sql').'.php';
+ $driver = $config->get('password_driver', 'sql');
+ $class = "rcube_{$driver}_password";
+ $file = $this->home . "/drivers/$driver.php";
- if (!is_readable($driver)) {
+ if (!file_exists($file)) {
raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Unable to open driver file $driver"
+ 'message' => "Password plugin: Unable to open driver file ($file)"
), true, false);
return $this->gettext('internalerror');
}
- include($driver);
+ include_once $file;
- if (!function_exists('password_save')) {
+ if (!class_exists($class, false) || !method_exists($class, 'save')) {
raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Password plugin: Broken driver: $driver"
+ 'message' => "Password plugin: Broken driver $driver"
), true, false);
return $this->gettext('internalerror');
}
- $result = password_save($curpass, $passwd);
+ $object = new $class;
+ $result = $object->save($curpass, $passwd);
if (is_array($result)) {
$message = $result['message'];