config->get('password_dovecot_passwdfile_path') ?: '/etc/mail/imap.passwd'; $password = password::hash_password($newpass); $username = escapeshellcmd($username); // FIXME: Do we need this? $content = ''; // read the entire mail user file $fp = fopen($mailuserfile, 'r'); if (empty($fp)) { rcube::raise_error([ 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Unable to read password file $mailuserfile." ], true, false ); return PASSWORD_CONNECT_ERROR; } if (flock($fp, LOCK_EX)) { // Read the file and replace the user password while (($line = fgets($fp, 40960)) !== false) { if (strpos($line, "$username:") === 0) { $pos = strpos($line, ':', strlen("$username:") + 1); $line = "$username:$password" . substr($line, $pos); } $content .= $line; } // Write back the entire file if (file_put_contents($mailuserfile, $content)) { flock($fp, LOCK_UN); fclose($fp); return PASSWORD_SUCCESS; } } fclose($fp); rcube::raise_error([ 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Failed to save file $mailuserfile." ], true, false ); return PASSWORD_ERROR; } }