From beb5bc650559db7771a78e57cecbe6c4fccbd4aa Mon Sep 17 00:00:00 2001 From: alec Date: Wed, 7 Mar 2012 09:48:33 +0000 Subject: - Added pw_usermod driver (#1487826) - Added option password_login_exceptions (#1487826) git-svn-id: https://svn.roundcube.net/trunk@5973 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/password/README | 8 +++++++ plugins/password/config.inc.php.dist | 12 ++++++++++ plugins/password/drivers/chpasswd.php | 2 +- plugins/password/drivers/pw_usermod.php | 41 +++++++++++++++++++++++++++++++++ plugins/password/package.xml | 23 +++++++++++++++--- plugins/password/password.php | 19 ++++++++++++--- 6 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 plugins/password/drivers/pw_usermod.php (limited to 'plugins/password') diff --git a/plugins/password/README b/plugins/password/README index d9280fb03..268d5194c 100644 --- a/plugins/password/README +++ b/plugins/password/README @@ -39,6 +39,7 @@ 2.11. Chpasswd (chpasswd) 2.12. LDAP - no PEAR (ldap_simple) 2.13. XMail (xmail) + 2.14. Pw (pw_usermod) 3. Driver API @@ -253,6 +254,13 @@ for configuration description. + 2.14. Pw (pw_usermod) + ----------------------------------- + + Driver to change the systems user password via the 'pw usermod' 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 313e47fda..689c4de26 100644 --- a/plugins/password/config.inc.php.dist +++ b/plugins/password/config.inc.php.dist @@ -21,6 +21,10 @@ $rcmail_config['password_require_nonalpha'] = false; // Enables logging of password changes into logs/password $rcmail_config['password_log'] = false; +// Comma-separated list of login exceptions for which password change +// will be not available (no Password tab in Settings) +$rcmail_config['password_login_exceptions'] = null; + // SQL Driver options // ------------------ @@ -305,3 +309,11 @@ $rcmail_config['hmailserver_server'] = array( // 6: username_domain // 7: domain_username $rcmail_config['password_virtualmin_format'] = 0; + + +// pw_usermod Driver options +// -------------------------- +// Use comma delimited exlist to disable password change for users +// Add the following line to visudo to tighten security: +// www ALL=NOPASSWORD: /usr/sbin/pw +$rcmail_config['password_pw_usermod_cmd'] = 'sudo /usr/sbin/pw usermod -h 0 -n'; diff --git a/plugins/password/drivers/chpasswd.php b/plugins/password/drivers/chpasswd.php index cce7c1f42..3ea10159c 100644 --- a/plugins/password/drivers/chpasswd.php +++ b/plugins/password/drivers/chpasswd.php @@ -9,7 +9,7 @@ * For installation instructions please read the README file. * * @version 2.0 - * @author Alex Cartwright */ class rcube_chpasswd_password diff --git a/plugins/password/drivers/pw_usermod.php b/plugins/password/drivers/pw_usermod.php new file mode 100644 index 000000000..ca3d068a7 --- /dev/null +++ b/plugins/password/drivers/pw_usermod.php @@ -0,0 +1,41 @@ + + * @author Adamson Huang + */ + +class rcube_pw_usermod_password +{ + public function save($currpass, $newpass) + { + $cmd = rcmail::get_instance()->config->get('password_pw_usermod_cmd'); + $username = $_SESSION['username']; + $cmd .= " $username > /dev/null"; + + $handle = popen($cmd, "w"); + fwrite($handle, "$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); + } + + return PASSWORD_ERROR; + } +} diff --git a/plugins/password/package.xml b/plugins/password/package.xml index c2a3442dd..39fb2aad8 100644 --- a/plugins/password/package.xml +++ b/plugins/password/package.xml @@ -15,9 +15,9 @@ alec@alec.pl yes - 2011-11-23 + 2012-03-07 - 3.0 + 3.1 2.0 @@ -26,7 +26,8 @@ GNU GPLv2 -- Fixed drivers namespace issues +- Added pw_usermod driver (#1487826) +- Added option password_login_exceptions (#1487826) @@ -85,6 +86,7 @@ + @@ -302,5 +304,20 @@ - Save Samba password hashes in capital letters (#1488197) + + 2011-11-23 + + 3.0 + 2.0 + + + stable + stable + + GNU GPLv2 + +- Fixed drivers namespace issues + + diff --git a/plugins/password/password.php b/plugins/password/password.php index 5ed08ed42..58b6f8cd9 100644 --- a/plugins/password/password.php +++ b/plugins/password/password.php @@ -53,6 +53,22 @@ class password extends rcube_plugin function init() { $rcmail = rcmail::get_instance(); + + $this->load_config(); + + // Exceptions list + if ($exceptions = $rcmail->config->get('password_login_exceptions')) { + $exceptions = array_map('trim', (array) $exceptions); + $exceptions = array_filter($exceptions); + $username = $_SESSION['username']; + + foreach ($exceptions as $ec) { + if ($username === $ec) { + return; + } + } + } + // add Tab label $rcmail->output->add_label('password'); $this->register_action('plugin.password', array($this, 'password_init')); @@ -73,7 +89,6 @@ class password extends rcube_plugin function password_save() { $rcmail = rcmail::get_instance(); - $this->load_config(); $this->add_texts('localization/'); $this->register_handler('plugin.body', array($this, 'password_form')); @@ -87,7 +102,6 @@ class password extends rcube_plugin $rcmail->output->command('display_message', $this->gettext('nopassword'), 'error'); } else { - $charset = strtoupper($rcmail->config->get('password_charset', 'ISO-8859-1')); $rc_charset = strtoupper($rcmail->output->get_charset()); @@ -159,7 +173,6 @@ class password extends rcube_plugin function password_form() { $rcmail = rcmail::get_instance(); - $this->load_config(); // add some labels to client $rcmail->output->add_label( -- cgit v1.2.3