From 1d09ee0ce6d50d122352bfde66828d70cd7ed57b Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 26 Feb 2015 12:19:44 -0500
Subject: [PATCH] Added 'kpasswd' driver by Peter Allgeyer

---
 CHANGELOG                            |    1 
 plugins/password/drivers/kpasswd.php |   45 ++++++++++++++++++++++
 plugins/password/README              |    9 ++++
 plugins/password/config.inc.php.dist |    6 +++
 4 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 4855f2c..3bc673d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@
 ===========================
 
 - Plugin API: Add special onload() method to execute plugin actions before startup (session and GUI initialization)
+- Password plugin: Added 'kpasswd' driver by Peter Allgeyer
 - Add possibility to print contact information (of a single contact)
 - Add possibility to configure max_allowed_packet value for all database engines (#1490283)
 - Improved handling of storage errors after message is sent
diff --git a/plugins/password/README b/plugins/password/README
index 8c3a2af..b883211 100644
--- a/plugins/password/README
+++ b/plugins/password/README
@@ -44,6 +44,7 @@
  2.18. Samba (smb)
  2.19. Vpopmail daemon (vpopmaild)
  2.20. Plesk (Plesk RPC-API)
+ 2.21. Kpasswd
  3. Driver API
 
 
@@ -301,6 +302,7 @@
  Driver to change Samba user password via the 'smbpasswd' command.
  See config.inc.php.dist file for configuration description.
 
+
  2.19. Vpopmail daemon (vpopmaild)
  -----------------------------------
 
@@ -330,6 +332,13 @@
  Set the RPC-Path in $config['password_plesk_rpc_path']. Normally this is: enterprise/control/agent.php.
 
 
+ 2.21.  Kpasswd
+ -----------------------------------
+
+ Driver to change the password in Kerberos environments via the 'kpasswd' command.
+ See config.inc.php.dist file for configuration description.
+
+
  3. Driver API
  -------------
 
diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist
index cf02102..1814499 100644
--- a/plugins/password/config.inc.php.dist
+++ b/plugins/password/config.inc.php.dist
@@ -399,3 +399,9 @@
 
 // Plesk RPC Path
 $config['password_plesk_rpc_path'] = 'enterprise/control/agent.php';
+
+
+// kasswd Driver options
+// ---------------------
+// Command to use
+$config['password_kpasswd_cmd'] = '/usr/bin/kpasswd';
diff --git a/plugins/password/drivers/kpasswd.php b/plugins/password/drivers/kpasswd.php
new file mode 100644
index 0000000..ce245b3
--- /dev/null
+++ b/plugins/password/drivers/kpasswd.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * kpasswd Driver
+ *
+ * Driver that adds functionality to change the systems user password via
+ * the 'kpasswd' command.
+ *
+ * For installation instructions please read the README file.
+ *
+ * @version 1.0
+ * @author Peter Allgeyer <peter.allgeyer@salzburgresearch.at>
+ *
+ * Based on chpasswd roundcubemail password driver by
+ * @author Alex Cartwright <acartwright@mutinydesign.co.uk>
+ */
+
+class rcube_kpasswd_password
+{
+    public function save($currpass, $newpass)
+    {
+        $bin      = rcmail::get_instance()->config->get('password_kpasswd_cmd', '/usr/bin/kpasswd');
+        $username = $_SESSION['username'];
+        $cmd      = $bin . ' "' . $username . '" 2>&1';
+
+        $handle = popen($cmd, "w");
+        fwrite($handle, $currpass."\n");
+        fwrite($handle, $newpass."\n");
+        fwrite($handle, $newpass."\n");
+
+        if (pclose($handle) == 0) {
+            return PASSWORD_SUCCESS;
+        }
+        else {
+            rcube::raise_error(array(
+                'code' => 600,
+                'type' => 'php',
+                'file' => __FILE__, 'line' => __LINE__,
+                'message' => "Password plugin: Unable to execute $cmd"
+                ), true, false);
+        }
+
+        return PASSWORD_ERROR;
+    }
+}

--
Gitblit v1.9.1