3 * Change password vmailmgrd backend
5 * Backend won't work, if vmail.inc file is not included. vmail.inc file
6 * should be part of your vmailmgr install. In some cases it is included in
9 * If you use modified vmail.inc, it must provide vchpass() function that
10 * acts same way as stock (vmailmgr v.0.96.9) vmail.inc function call
11 * and other vmail.inc functions should use same $vm_tcphost and
12 * $vm_tcphost_port globals as used by stock vm_daemon_raw() function call.
13 * If you have heavily modified vmail.inc and this backend does not work
14 * correctly - recheck, if you can reproduce your problem with stock
15 * vmail.inc or adjust backend configuration for your site.
17 * Backend also needs vmailmgrd service. You can find information about
18 * installing this service in vmailmgr FAQ and vmailmgrd.html.
20 * Backend might require functions, that are available only in SquirrelMail
21 * v.1.5.1 and v.1.4.4.
24 * @link http://www.vmailmgr.org vmailmgr site
26 * @subpackage change_password
29 /* Backend configuration */
34 * This variable must provide full path to vmail.inc file including filename.
36 * WARNING: Don't disable this variable. It must be set to correct value or
37 * to empty string. If variable is missing, backend can have security problems
38 * in some php configurations.
39 * @global string $vmail_inc_path
41 global $vmail_inc_path;
45 * address of vmailmgrd host.
47 * Leave it empty, if you want to use unix socket
48 * global is used by vmail.inc functions
49 * @global string $vm_tcphost
57 * global is used by vmail.inc functions.
58 * @global integer $vm_tcphost_port
60 global $vm_tcphost_port;
64 * Option that controls use of 8bit passwords
65 * Use of such passwords is not safe, because squirrelmail interface
66 * can be running in different charsets.
69 global $cpw_vmailmgrd_8bitpw;
70 $cpw_vmailmgrd_8bitpw=false;
72 /* end of backend configuration */
76 * Init change_password plugin hooks.
78 global $squirrelmail_plugin_hooks;
79 $squirrelmail_plugin_hooks['change_password_dochange']['vmailmgrd'] =
80 'cpw_vmailmgrd_dochange';
81 $squirrelmail_plugin_hooks['change_password_init']['vmailmgrd'] =
86 * Use this function to do any backend-specific initialisation,
87 * e.g. checking requirements, before the password change form
88 * is displayed to the user.
90 function cpw_vmailmgrd_init(){
91 global $vmail_inc_path, $color, $username;
94 * If SM_PATH isn't defined, define it. Required to include files.
97 if (!defined('SM_PATH')) {
98 define('SM_PATH','../../../');
101 // load error_box() function
102 include_once(SM_PATH
. 'functions/display_messages.php');
104 if ($vmail_inc_path=='' ||
! file_exists($vmail_inc_path)) {
105 // $vmail_inc_path is not set or file does not exist
106 error_box(_("Incorrent path to vmail.inc file."),$color);
107 // close html and stop script execution
108 echo "</body></html>\n";
112 include_once($vmail_inc_path);
114 if (! function_exists('vchpass')) {
115 // included vmail.inc does not have required functions.
116 error_box(_("Invalid or corrupted vmail.inc file."),$color);
117 // close html and stop script execution
118 echo "</body></html>\n";
122 if (! preg_match("/(.*)\@(.*)/", $username)) {
123 // username does not match vmailmgr syntax
124 error_box(_("Invalid user."),$color);
125 // close html and stop script execution
126 echo "</body></html>\n";
133 * function used to change password in change_password plugin hooks.
135 * @param array data The username/currentpw/newpw data.
136 * @return array Array of error messages.
138 function cpw_vmailmgrd_dochange($data)
140 global $cpw_vmailmgrd_8bitpw;
143 * getting params from hook function.
145 $username = $data['username'];
146 $curpw = $data['curpw'];
147 $newpw = $data['newpw'];
151 // check for new 8bit password
152 if (! $cpw_vmailmgrd_8bitpw && sq_is8bit($newpw)) {
153 // 8bit chars in password when backend is configured to block them
154 array_push($msgs,CPW_INVALID_PW
);
158 // extract username and domain
159 if (preg_match("/(.*)\@(.*)/", $username, $parts)) {
161 $vm_domain=$parts[2];
164 // check if old password matches
165 $vmgrd_response1 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$curpw);
166 if ($vmgrd_response1[0]!=0) {
167 array_push($msgs, CPW_CURRENT_NOMATCH
);
172 $vmgrd_response2 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$newpw);
173 if ($vmgrd_response2[0]!=0) {
174 // TODO: add vmail.inc error message parser.
175 array_push($msgs, $vmgrd_response2[1]);
182 * function that calls required vmail.inc functions and returns error codes.
184 * Information about vmailmgr return codes.
185 * vmailmgr functions return array with two keys.
187 * [0] => error code, integer (0=no error)
188 * [1] => error message, string
192 function cpw_vmailmgrd_passwd($user,$domain,$oldpass,$newpass) {
193 global $vmail_inc_path;
195 // variable should be checked by cpw_vmailmgrd_init function
196 include_once($vmail_inc_path);
198 return vchpass($domain,$oldpass,$user,$newpass);