\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); } ?>