[Svn] r4016 - in trunk/plugins/password: . drivers

trac at roundcube.net trac at roundcube.net
Wed Sep 29 19:23:26 CEST 2010


Author: alec
Date: 2010-09-29 12:23:26 -0500 (Wed, 29 Sep 2010)
New Revision: 4016

Modified:
   trunk/plugins/password/drivers/poppassd.php
   trunk/plugins/password/package.xml
   trunk/plugins/password/password.php
Log:
- Added possibility to display extended error messages (#1486704)
- Added extended error messages in Poppassd driver (#1486704)


Modified: trunk/plugins/password/drivers/poppassd.php
===================================================================
--- trunk/plugins/password/drivers/poppassd.php	2010-09-29 16:47:05 UTC (rev 4015)
+++ trunk/plugins/password/drivers/poppassd.php	2010-09-29 17:23:26 UTC (rev 4016)
@@ -5,46 +5,56 @@
  *
  * Driver to change passwords via Poppassd/Courierpassd
  *
- * @version 1.0
+ * @version 1.1
  * @author Philip Weir
  *
  */
 
+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();
 //    include('Net/Socket.php');
     $poppassd = new Net_Socket();
 
-    if (PEAR::isError($poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null))) {
-        return PASSWORD_CONNECT_ERROR;
+    $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 PASSWORD_ERROR;
+            return format_error_result(PASSWORD_ERROR, $result);
         }
         else {
             $poppassd->writeLine("user ". $_SESSION['username']);
             $result = $poppassd->readLine();
             if(!preg_match('/^[23]\d\d/', $result) ) {
                 $poppassd->disconnect();
-                return PASSWORD_CONNECT_ERROR;
+                return format_error_result(PASSWORD_CONNECT_ERROR, $result);
             }
             else {
                 $poppassd->writeLine("pass ". $curpass);
                 $result = $poppassd->readLine();
                 if(!preg_match('/^[23]\d\d/', $result) ) {
                     $poppassd->disconnect();
-                    return PASSWORD_ERROR;
+                    return format_error_result(PASSWORD_ERROR, $result);
                 }
                 else {
                     $poppassd->writeLine("newpass ". $passwd);
                     $result = $poppassd->readLine();
                     $poppassd->disconnect();
                     if (!preg_match('/^2\d\d/', $result))
-                        return PASSWORD_ERROR;
+                        return format_error_result(PASSWORD_ERROR, $result);
                     else
                         return PASSWORD_SUCCESS;
                 }
@@ -52,5 +62,3 @@
         }
     }
 }
-
-?>

Modified: trunk/plugins/password/package.xml
===================================================================
--- trunk/plugins/password/package.xml	2010-09-29 16:47:05 UTC (rev 4015)
+++ trunk/plugins/password/package.xml	2010-09-29 17:23:26 UTC (rev 4016)
@@ -15,11 +15,11 @@
 		<email>alec at alec.pl</email>
 		<active>yes</active>
 	</lead>
-	<date>2010-09-10</date>
-	<time>09:00:00</time>
+	<date>2010-09-29</date>
+	<time>19:00:00</time>
 	<version>
-		<release>1.7</release>
-		<api>1.5</api>
+		<release>1.8</release>
+		<api>1.6</api>
 	</version>
 	<stability>
 		<release>stable</release>
@@ -27,9 +27,8 @@
 	</stability>
 	<license uri="http://www.gnu.org/licenses/gpl-2.0.html">GNU GPLv2</license>
 	<notes>
-- Added XMail driver
-- Improve security of chpasswd driver using popen instead of exec+echo (#1486987)
-- Added chpass-wrapper.py script to improve security (#1486987)
+- Added possibility to display extended error messages (#1486704)
+- Added extended error messages in Poppassd driver (#1486704)
     </notes>
 	<contents>
 		<dir baseinstalldir="/" name="/">
@@ -153,5 +152,23 @@
 - Added ldap_simple driver
             </notes>
         </release>
-	</changelog>
+        <release>
+	        <date>2010-09-10</date>
+	        <time>09:00:00</time>
+	        <version>
+		        <release>1.7</release>
+		        <api>1.5</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 XMail driver
+- Improve security of chpasswd driver using popen instead of exec+echo (#1486987)
+- Added chpass-wrapper.py script to improve security (#1486987)
+            </notes>
+	    </release>
+    </changelog>
 </package>

Modified: trunk/plugins/password/password.php
===================================================================
--- trunk/plugins/password/password.php	2010-09-29 16:47:05 UTC (rev 4015)
+++ trunk/plugins/password/password.php	2010-09-29 17:23:26 UTC (rev 4016)
@@ -5,7 +5,7 @@
  | Password Plugin for Roundcube                                           |
  | @version @package_version@                                                             |
  |                                                                         |
- | Copyright (C) 2009, Roundcube Dev.                                      |
+ | Copyright (C) 2009-2010, Roundcube Dev.                                 |
  |                                                                         |
  | This program is free software; you can redistribute it and/or modify    |
  | it under the terms of the GNU General Public License version 2          |
@@ -124,7 +124,7 @@
                 $rcmail->output->command('display_message', $this->gettext('passwordweak'), 'error');
             }
             // try to save the password
-            else if (!($res = $this->_save($curpwd,$newpwd))) {
+            else if (!($res = $this->_save($curpwd, $newpwd))) {
                 $rcmail->output->command('display_message', $this->gettext('successfullysaved'), 'confirmation');
                 $_SESSION['password'] = $rcmail->encrypt($newpwd);
             }
@@ -229,18 +229,27 @@
 
         $result = password_save($curpass, $passwd);
 
+        if (is_array($result)) {
+            $result  = $result['code'];
+            $message = $result['message'];
+        }
+
         switch ($result) {
             case PASSWORD_SUCCESS:
                 return;
             case PASSWORD_CRYPT_ERROR;
-                return $this->gettext('crypterror');
+                $reason = $this->gettext('crypterror');
             case PASSWORD_CONNECT_ERROR;
-                return $this->gettext('connecterror');
+                $reason = $this->gettext('connecterror');
             case PASSWORD_ERROR:
             default:
-                return $this->gettext('internalerror');
+                $reason = $this->gettext('internalerror');
         }
+
+        if ($message) {
+            $reason .= ' ' . $message;
+        }
+
+        return $reason;
     }                                     
 }
-
-?>

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list