From ebf9211b46d097c8ff4e8b6f6ab8c3a2c12731fd Mon Sep 17 00:00:00 2001 From: tokul Date: Tue, 8 Feb 2005 19:19:10 +0000 Subject: [PATCH] adding vmailmgrd backend and making change_password_init hook work. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8827 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/change_password/backend/vmailmgrd.php | 200 ++++++++++++++++++ plugins/change_password/options.php | 5 + 2 files changed, 205 insertions(+) create mode 100644 plugins/change_password/backend/vmailmgrd.php diff --git a/plugins/change_password/backend/vmailmgrd.php b/plugins/change_password/backend/vmailmgrd.php new file mode 100644 index 00000000..208a677f --- /dev/null +++ b/plugins/change_password/backend/vmailmgrd.php @@ -0,0 +1,200 @@ +\n"; + exit(); + } + + include_once($vmail_inc_path); + + if (! function_exists('vchpass')) { + // included vmail.inc does not have required functions. + error_box(_("Invalid or corrupted vmail.inc file."),$color); + // close html and stop script execution + echo "\n"; + exit(); + } + + if (! preg_match("/(.*)\@(.*)/", $username)) { + // username does not match vmailmgr syntax + error_box(_("Invalid user."),$color); + // close html and stop script execution + echo "\n"; + exit(); + } +} + + +/** + * function used to change password in change_password plugin hooks. + * + * @param array data The username/currentpw/newpw data. + * @return array Array of error messages. + */ +function cpw_vmailmgrd_dochange($data) +{ + global $cpw_vmailmgrd_8bitpw; + + /** + * getting params from hook function. + */ + $username = $data['username']; + $curpw = $data['curpw']; + $newpw = $data['newpw']; + + $msgs = array(); + + // check for new 8bit password + if (! $cpw_vmailmgrd_8bitpw && sq_is8bit($newpw)) { + // 8bit chars in password when backend is configured to block them + array_push($msgs,CPW_INVALID_PW); + return $msgs; + } + + // extract username and domain + if (preg_match("/(.*)\@(.*)/", $username, $parts)) { + $vm_user=$parts[1]; + $vm_domain=$parts[2]; + } + + // check if old password matches + $vmgrd_response1 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$curpw); + if ($vmgrd_response1[0]!=0) { + array_push($msgs, CPW_CURRENT_NOMATCH); + return $msgs; + } + + // change password + $vmgrd_response2 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$newpw); + if ($vmgrd_response2[0]!=0) { + // TODO: add vmail.inc error message parser. + array_push($msgs, $vmgrd_response2[1]); + } + + return $msgs; +} + +/** + * function that calls required vmail.inc functions and returns error codes. + * + * Information about vmailmgr return codes. + * vmailmgr functions return array with two keys. + * Array( + * [0] => error code, integer (0=no error) + * [1] => error message, string + * ) + * @return array + */ +function cpw_vmailmgrd_passwd($user,$domain,$oldpass,$newpass) { + global $vmail_inc_path; + + // variable should be checked by cpw_vmailmgrd_init function + include_once($vmail_inc_path); + + return vchpass($domain,$oldpass,$user,$newpass); +} +?> \ No newline at end of file diff --git a/plugins/change_password/options.php b/plugins/change_password/options.php index 983be0d5..3a9d69c2 100644 --- a/plugins/change_password/options.php +++ b/plugins/change_password/options.php @@ -20,6 +20,11 @@ require_once (SM_PATH . 'plugins/change_password/functions.php'); require_once (SM_PATH . 'plugins/change_password/config.php'); require_once (SM_PATH . 'functions/forms.php'); +// you must load backend configuration here in order to get working change_password_init hook. +if (file_exists(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php')) { + include_once(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php'); +} + /* the form was submitted, go for it */ if(sqgetGlobalVar('cpw_go', $cpw_go, SQ_POST)) { -- 2.25.1