Password: Added password_username_format option (#5766)

pull/6263/head
Aleksander Machniak 7 years ago
parent c5f91540f2
commit 60922dc3d5

@ -39,6 +39,7 @@ CHANGELOG Roundcube Webmail
- Managesieve: Support GSSAPI authentication with krb_authentication plugin (#5779)
- Password: Support host variables in password_db_dsn option (#5955)
- Password: Automatic virtualmin domain setting, removed password_virtualmin_format option (#5759)
- Password: Added password_username_format option (#5766)
- subscriptions_option: show \\Noselect folders greyed out (#5621)
- zipdownload: Added option to define size limit for multiple messages download (#5696)
- vcard_attachments: Add possibility to send contact vCard from Contacts toolbar (#6080)

@ -372,6 +372,7 @@
Extended result (as a hash-array with 'message' and 'code' items) can be returned
too. See existing drivers in drivers/ directory for examples.
4. Sudo setup
-------------

@ -3,7 +3,7 @@
"type": "roundcube-plugin",
"description": "Password Change for Roundcube. Plugin adds a possibility to change user password using many methods (drivers) via Settings/Password tab.",
"license": "GPLv3+",
"version": "4.3",
"version": "4.4",
"authors": [
{
"name": "Aleksander Machniak",

@ -78,6 +78,15 @@ $config['password_blowfish_cost'] = 12;
// which will replace the default.
$config['password_disabled'] = false;
// Various drivers/setups use different format of the username.
// This option allows you to force specified format use. Default: '%u'.
// Supported variables:
// %u - full username,
// %l - the local part of the username (in case the username is an email address)
// %d - the domain part of the username (in case the username is an email address)
// Note: This may no apply to some drivers implementing their own rules, e.g. sql.
$config['password_username_format'] = '%u';
// SQL Driver options
// ------------------

@ -29,10 +29,9 @@
class rcube_chpasswd_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$cmd = rcmail::get_instance()->config->get('password_chpasswd_cmd');
$username = $_SESSION['username'];
$handle = popen($cmd, "w");
fwrite($handle, "$username:$newpass\n");
@ -40,14 +39,13 @@ class rcube_chpasswd_password
if (pclose($handle) == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $cmd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -90,9 +90,10 @@ class rcube_cpanel_password
// Get the cPanel user
$query = $this->xmlapi->listaccts('domain', $data['domain']);
$query = json_decode($query, true);
if ( $query['status'] != 1) {
if ($query['status'] != 1) {
return false;
}
$cpanel_user = $query['acct'][0]['user'];
$query = $this->xmlapi->api2_query($cpanel_user, 'Email', 'passwdpop', $data);

@ -39,16 +39,13 @@ class rcube_cpanel_webmail_password
*/
public function save($curpas, $newpass)
{
$user = $_SESSION['username'];
$url = self::url();
$userpwd = "$user:$curpas";
list($login) = explode('@', $user);
$data = array(
'email' => $login,
$data = array(
'email' => password::username('%l'),
'password' => $newpass
);
$url = self::url();
$response = $this->curl_auth_post($userpwd, $url, $data);
return self::decode_response($response);

@ -32,10 +32,10 @@
class rcube_dbmail_password
{
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
$curdir = RCUBE_PLUGINS_DIR . 'password/helpers';
$username = escapeshellarg($_SESSION['username']);
$username = escapeshellarg($username);
$password = escapeshellarg($newpass);
$args = rcmail::get_instance()->config->get('password_dbmail_args', '');
$command = "$curdir/chgdbmailusers -c $username -w $password $args";
@ -45,14 +45,13 @@ class rcube_dbmail_password
if ($return_value == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $curdir/chgdbmailusers"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -59,12 +59,15 @@ class rcube_directadmin_password
//DEBUG
//rcube::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)
if ($Socket->result_status_code != 200) {
return array('code' => PASSWORD_CONNECT_ERROR, 'message' => $Socket->error[0]);
elseif($response['error'] == 1)
}
if ($response['error'] == 1) {
return array('code' => PASSWORD_ERROR, 'message' => strip_tags($response['text']));
else
return PASSWORD_SUCCESS;
}
return PASSWORD_SUCCESS;
}
}

@ -28,7 +28,7 @@
class rcube_domainfactory_password
{
function save($curpass, $passwd)
function save($curpass, $passwd, $username)
{
$rcmail = rcmail::get_instance();
@ -39,7 +39,7 @@ class rcube_domainfactory_password
CURLOPT_URL => 'https://ssl.df.eu/chmail.php',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array(
'login' => $rcmail->user->get_username(),
'login' => $username,
'pwd' => $curpass,
'action' => 'change'
))

@ -42,13 +42,12 @@
class rcube_expect_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$rcmail = rcmail::get_instance();
$bin = $rcmail->config->get('password_expect_bin');
$script = $rcmail->config->get('password_expect_script');
$params = $rcmail->config->get('password_expect_params');
$username = $_SESSION['username'];
$cmd = $bin . ' -f ' . $script . ' -- ' . $params;
$handle = popen($cmd, "w");
@ -59,14 +58,13 @@ class rcube_expect_password
if (pclose($handle) == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $cmd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -27,13 +27,12 @@
class rcube_gearman_password
{
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
if (extension_loaded('gearman')) {
$rcmail = rcmail::get_instance();
$user = $_SESSION['username'];
$payload = array(
'username' => $user,
'username' => $username,
'oldPassword' => $currpass,
'newPassword' => $newpass,
);
@ -52,7 +51,7 @@ class rcube_gearman_password
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Gearman authentication failed for user $user: $error"
'message' => "Password plugin: Gearman authentication failed for user $username: $error"
), true, false);
}
}

@ -24,14 +24,10 @@
class rcube_hmail_password
{
public function save($curpass, $passwd)
public function save($curpass, $passwd, $username)
{
$rcmail = rcmail::get_instance();
if ($curpass == '' || $passwd == '') {
return PASSWORD_ERROR;
}
try {
$remote = $rcmail->config->get('hmailserver_remote_dcom', false);
if ($remote)
@ -42,11 +38,11 @@ class rcube_hmail_password
catch (Exception $e) {
rcube::write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
rcube::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,'@')){
if (strstr($username,'@')) {
$temparr = explode('@', $username);
$domain = $temparr[1];
}
@ -61,15 +57,17 @@ class rcube_hmail_password
$obApp->Authenticate($username, $curpass);
try {
$obDomain = $obApp->Domains->ItemByName($domain);
$obDomain = $obApp->Domains->ItemByName($domain);
$obAccount = $obDomain->Accounts->ItemByAddress($username);
$obAccount->Password = $passwd;
$obAccount->Save();
return PASSWORD_SUCCESS;
}
catch (Exception $e) {
rcube::write_log('errors', "Plugin password (hmail driver): " . trim(strip_tags($e->getMessage())));
rcube::write_log('errors', "Plugin password (hmail driver): This problem is often caused by DCOM permissions not being set.");
return PASSWORD_ERROR;
}
}

@ -17,11 +17,10 @@
class rcube_kpasswd_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$bin = rcmail::get_instance()->config->get('password_kpasswd_cmd', '/usr/bin/kpasswd');
$username = $_SESSION['username'];
$cmd = $bin . ' "' . $username . '" 2>&1';
$cmd = $bin . ' "' . escapeshellarg($username) . '" 2>&1';
$handle = popen($cmd, "w");
fwrite($handle, $currpass."\n");
@ -31,14 +30,13 @@ class rcube_kpasswd_password
if (pclose($handle) == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $cmd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -13,7 +13,7 @@
class rcube_ldap_ppolicy_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$rcmail = rcmail::get_instance();
$this->debug = $rcmail->config->get('ldap_debug');
@ -56,7 +56,7 @@ class rcube_ldap_ppolicy_password
fwrite($pipes[0], $filter."\n");
fwrite($pipes[0], $bindDN."\n");
fwrite($pipes[0], $bindPW."\n");
fwrite($pipes[0], $_SESSION['username']."\n");
fwrite($pipes[0], $username."\n");
fwrite($pipes[0], $currpass."\n");
fwrite($pipes[0], $newpass."\n");
fwrite($pipes[0], $cafile);

@ -24,14 +24,13 @@
class rcube_pam_password
{
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
$user = $_SESSION['username'];
$error = '';
if (extension_loaded('pam') || extension_loaded('pam_auth')) {
if (pam_auth($user, $currpass, $error, false)) {
if (pam_chpass($user, $currpass, $newpass)) {
if (pam_auth($username, $currpass, $error, false)) {
if (pam_chpass($username, $currpass, $newpass)) {
return PASSWORD_SUCCESS;
}
}
@ -40,7 +39,7 @@ class rcube_pam_password
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: PAM authentication failed for user $user: $error"
'message' => "Password plugin: PAM authentication failed for user $username: $error"
), true, false);
}
}

@ -49,7 +49,7 @@ class rcube_plesk_password
* @param string $newpass New password
* @returns int PASSWORD_SUCCESS|PASSWORD_ERROR
*/
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
// get config
$rcmail = rcmail::get_instance();
@ -64,7 +64,7 @@ class rcube_plesk_password
$plesk->init($host, $port, $path, $user, $pass);
// try to change password and return the status
$result = $plesk->change_mailbox_password($_SESSION['username'], $newpass);
$result = $plesk->change_mailbox_password($username, $newpass);
//$plesk->destroy();
if ($result) {

@ -35,7 +35,7 @@ class rcube_poppassd_password
return $code;
}
function save($curpass, $passwd)
function save($curpass, $passwd, $username)
{
$rcmail = rcmail::get_instance();
$poppassd = new Net_Socket();
@ -57,7 +57,7 @@ class rcube_poppassd_password
return $this->format_error_result(PASSWORD_ERROR, $result);
}
$poppassd->writeLine("user ". $_SESSION['username']);
$poppassd->writeLine("user ". $username);
$result = $poppassd->readLine();
if (!preg_match('/^[23]\d\d/', $result)) {

@ -30,26 +30,24 @@
class rcube_pw_usermod_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$username = $_SESSION['username'];
$cmd = rcmail::get_instance()->config->get('password_pw_usermod_cmd');
$cmd .= " $username > /dev/null";
$cmd .= ' ' . escapeshellarg($username) . ' > /dev/null';
$handle = popen($cmd, "w");
$handle = popen($cmd, 'w');
fwrite($handle, "$newpass\n");
if (pclose($handle) == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $cmd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -33,27 +33,27 @@
class rcube_sasl_password
{
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
$curdir = RCUBE_PLUGINS_DIR . 'password/helpers';
$username = escapeshellarg($_SESSION['username']);
$username = escapeshellarg($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 ($code == 0)
if ($code == 0) {
return PASSWORD_SUCCESS;
}
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $curdir/chgsaslpasswd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -39,15 +39,13 @@
class rcube_smb_password
{
public function save($currpass, $newpass)
public function save($currpass, $newpass, $username)
{
$host = rcmail::get_instance()->config->get('password_smb_host','localhost');
$bin = rcmail::get_instance()->config->get('password_smb_cmd','/usr/bin/smbpasswd');
$username = $_SESSION['username'];
$host = rcube_utils::parse_host($host);
$tmpfile = tempnam(sys_get_temp_dir(),'smb');
$cmd = $bin . ' -r ' . $host . ' -s -U "' . $username . '" > ' . $tmpfile . ' 2>&1';
$cmd = $bin . ' -r ' . escapeshellarg($host) . ' -s -U "' . escapeshellarg($username) . '" > ' . $tmpfile . ' 2>&1';
$handle = @popen($cmd, 'w');
fputs($handle, $currpass."\n");
@ -60,14 +58,13 @@ class rcube_smb_password
if (strstr($res[count($res) - 1], 'Password changed for user') !== false) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $cmd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -31,10 +31,9 @@
class rcube_virtualmin_password
{
function save($currpass, $newpass)
function save($currpass, $newpass, $username)
{
$rcmail = rcmail::get_instance();
$username = $_SESSION['username'];
$curdir = RCUBE_PLUGINS_DIR . 'password/helpers';
$username = escapeshellarg($username);
@ -54,21 +53,20 @@ class rcube_virtualmin_password
return PASSWORD_ERROR;
}
$domain = escapeshellarg($domain);
$newpass = escapeshellarg($newpass);
$domain = escapeshellarg($domain);
$newpass = escapeshellarg($newpass);
exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
if ($returnvalue == 0) {
return PASSWORD_SUCCESS;
}
else {
rcube::raise_error(array(
rcube::raise_error(array(
'code' => 600,
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
), true, false);
}
), true, false);
return PASSWORD_ERROR;
}

@ -26,7 +26,7 @@
class rcube_vpopmaild_password
{
function save($curpass, $passwd)
function save($curpass, $passwd, $username)
{
$rcmail = rcmail::get_instance();
$vpopmaild = new Net_Socket();
@ -46,7 +46,7 @@ class rcube_vpopmaild_password
return PASSWORD_CONNECT_ERROR;
}
$vpopmaild->writeLine("slogin ". $_SESSION['username'] . " " . $curpass);
$vpopmaild->writeLine("slogin ". $username . " " . $curpass);
$result = $vpopmaild->readLine();
if(!preg_match('/^\+OK/', $result) ) {
@ -55,7 +55,7 @@ class rcube_vpopmaild_password
return PASSWORD_ERROR;
}
$vpopmaild->writeLine("mod_user ". $_SESSION['username']);
$vpopmaild->writeLine("mod_user ". $username);
$vpopmaild->writeLine("clear_text_password ". $passwd);
$vpopmaild->writeLine(".");
$result = $vpopmaild->readLine();

@ -32,7 +32,7 @@
class rcube_ximss_password
{
function save($pass, $newpass)
function save($pass, $newpass, $username)
{
$rcmail = rcmail::get_instance();
@ -45,9 +45,9 @@ class rcube_ximss_password
}
// 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");
fwrite($sock, '<login id="A001" authData="'.$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
@ -67,22 +67,22 @@ class rcube_ximss_password
foreach (explode( "\0",$responseblob) as $response) {
$resp = simplexml_load_string("<xml>".$response."</xml>");
if( $resp->response[0]['id'] == 'A001' ) {
if( isset( $resp->response[0]['errorNum'] ) ) {
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'] )) {
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)
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;
}

@ -36,14 +36,14 @@ class rcube_xmail_password
function save($currpass, $newpass)
{
$rcmail = rcmail::get_instance();
list($user,$domain) = explode('@', $_SESSION['username']);
list($user, $domain) = explode('@', $_SESSION['username']);
$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->port = $rcmail->config->get('xmail_port');
if (!$xmail->connect()) {
rcube::raise_error(array(
@ -52,9 +52,11 @@ class rcube_xmail_password
'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")) {
if (!$xmail->send("userpasswd\t".$domain."\t".$user."\t".$newpass."\n")) {
$xmail->close();
rcube::raise_error(array(
'code' => 600,
@ -62,12 +64,12 @@ class rcube_xmail_password
'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Unable to change password"
), true, false);
return PASSWORD_ERROR;
}
else {
$xmail->close();
return PASSWORD_SUCCESS;
}
$xmail->close();
return PASSWORD_SUCCESS;
}
}

@ -5,7 +5,7 @@
*
* @author Aleksander Machniak <alec@alec.pl>
*
* Copyright (C) 2005-2015, The Roundcube Dev Team
* Copyright (C) 2005-2018, The Roundcube Dev Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -122,7 +122,7 @@ class password extends rcube_plugin
$required_length = intval($rcmail->config->get('password_minimum_length'));
$check_strength = $rcmail->config->get('password_require_nonalpha');
if (($confirm && !isset($_POST['_curpasswd'])) || !isset($_POST['_newpasswd'])) {
if (($confirm && !isset($_POST['_curpasswd'])) || !isset($_POST['_newpasswd']) || !strlen($_POST['_newpasswd'])) {
$rcmail->output->command('display_message', $this->gettext('nopassword'), 'error');
}
else {
@ -330,8 +330,8 @@ class password extends rcube_plugin
return $this->gettext('internalerror');
}
$object = new $class;
$result = $object->save($curpass, $passwd);
$object = new $class;
$result = $object->save($curpass, $passwd, self::username());
$message = '';
if (is_array($result)) {
@ -673,4 +673,30 @@ class password extends rcube_plugin
return $crypted;
}
/**
* Returns username in a configured form appropriate for the driver
*
* @param string $format Username format
*
* @return string Username
*/
static function username($format = null)
{
$rcmail = rcmail::get_instance();
if (!$format) {
$format = $rcmail->config->get('password_username_format');
}
if (!$format) {
return $_SESSION['username'];
}
return strtr($format, array(
'%l' => $rcmail->user->get_username('local'),
'%d' => $rcmail->user->get_username('domain'),
'%u' => $_SESSION['username'],
));
}
}

Loading…
Cancel
Save