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("Password plugin: Unable to read password file {$mailuserfile}.", true); 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) { $tokens = explode(':', $line); $tokens[1] = $password; $line = implode(':', $tokens); } $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("Password plugin: Failed to save file {$mailuserfile}.", true); return PASSWORD_ERROR; } }