Skip to content

Commit

Permalink
Infer file/line location in rcube::raise_error() from backtrace (#9422)
Browse files Browse the repository at this point in the history
* \n\s+'file' => __FILE__,

* \n\s+'line' => __LINE__,

* 'line' => __LINE__, 'file' => __FILE__,

* 'file' => __FILE__, 'line' => __LINE__,

* rest

* more

* improve cs

* more cs

* revert rcube_utils::preg_error changes

* impl file/line from backtrace

* Revert "revert rcube_utils::preg_error changes"
  • Loading branch information
mvorisek authored Apr 21, 2024
1 parent ff59ade commit a30e0ad
Show file tree
Hide file tree
Showing 63 changed files with 127 additions and 210 deletions.
5 changes: 4 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@
// check access to disabled actions
$disabled_actions = (array) $RCMAIL->config->get('disabled_actions');
if (in_array($RCMAIL->task . '.' . ($RCMAIL->action ?: 'index'), $disabled_actions)) {
rcube::raise_error(['code' => 404, 'message' => 'Action disabled'], true, true);
rcube::raise_error([
'code' => 404,
'message' => 'Action disabled',
], true, true);
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/enigma/bin/import_keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function import_dir($user_id, $dir, $dry_run = false)

if ($datasize > $maxsize) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to save {$file}. Size exceeds max_allowed_packet.",
], true, false);

Expand All @@ -177,7 +177,7 @@ function import_dir($user_id, $dir, $dry_run = false)

if ($db->is_error($result)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to save {$file} into database.",
], true, false);
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/enigma/lib/enigma_driver_gnupg.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ protected function db_sync()
// @phpstan-ignore-next-line
if (!is_array($data)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to sync {$file} ({$file_id}). Decode error.",
], true, false);

Expand Down Expand Up @@ -631,7 +631,7 @@ protected function db_sync()
@unlink($tmpfile);

rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to sync {$file}.",
], true, false);
}
Expand Down Expand Up @@ -699,7 +699,7 @@ protected function db_save($is_empty = false)

if ($datasize > $maxsize) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to save {$file}. Size exceeds max_allowed_packet.",
], true, false);

Expand All @@ -711,7 +711,7 @@ protected function db_save($is_empty = false)

if ($db->is_error($result)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to save {$file} into database.",
], true, false);

Expand All @@ -733,7 +733,7 @@ protected function db_save($is_empty = false)

if ($db->is_error($result)) {
rcube::raise_error([
'code' => 605, 'line' => __LINE__, 'file' => __FILE__,
'code' => 605,
'message' => "Enigma: Failed to delete {$file} from database.",
], true, false);

Expand Down
1 change: 0 additions & 1 deletion plugins/enigma/lib/enigma_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,6 @@ protected static function raise_error($result, $line, $abort = false)
if ($result->getCode() != enigma_error::BADPASS) {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => $line,
'message' => 'Enigma plugin: ' . $result->getMessage(),
], true, $abort);
Expand Down
5 changes: 0 additions & 5 deletions plugins/filesystem_attachments/filesystem_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function init()
$plugin = $this->api->get_plugin($plugin_name);
if (($plugin instanceof self) && $plugin->initialized) {
rcube::raise_error([
'file' => __FILE__, 'line' => __LINE__,
'message' => "Can use only one plugin for attachments/file uploads! Using '{$plugin_name}', ignoring others.",
], true, false);
return;
Expand Down Expand Up @@ -203,8 +202,6 @@ protected static function verify_path($path)
// We allow that, but we'll let to know the user about the misconfiguration.
if ($file_path == sys_get_temp_dir()) {
rcube::raise_error([
'file' => __FILE__,
'line' => __LINE__,
'message' => "Detected 'temp_dir' change. "
. "Access to '{$temp_dir}' restricted by filesystem permissions or open_basedir",
], true, false);
Expand All @@ -213,8 +210,6 @@ protected static function verify_path($path)
}

rcube::raise_error([
'file' => __FILE__,
'line' => __LINE__,
'message' => sprintf("%s can't read %s (not in temp_dir)",
$rcmail->get_user_name(), substr($path, 0, 512)),
], true, false);
Expand Down
6 changes: 2 additions & 4 deletions plugins/identicon/identicon_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ private function generate()
$this->generateGD();
} else {
// log an error
$error = [
rcube::raise_error([
'code' => 500,
'message' => "PHP-GD module not found. It's required by identicon plugin.",
];

rcube::raise_error($error, true, false);
], true, false);
}
}

Expand Down
6 changes: 2 additions & 4 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ public function connect($username, $password)
if ($error) {
rcube::raise_error([
'code' => 403,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Unable to connect to managesieve on {$host}:{$port}",
], true, false);
}
Expand Down Expand Up @@ -510,15 +508,15 @@ public function save()
// check request size limit
if ($max_post && count($_POST, \COUNT_RECURSIVE) >= $max_post) {
rcube::raise_error([
'code' => 500, 'file' => __FILE__, 'line' => __LINE__,
'code' => 500,
'message' => 'Request size limit exceeded (one of max_input_vars/suhosin.request.max_vars/suhosin.post.max_vars)',
], true, false);
$this->rc->output->show_message('managesieve.filtersaveerror', 'error');
}
// check request depth limits
elseif ($max_depth && count($_POST['_header']) > $max_depth) {
rcube::raise_error([
'code' => 500, 'file' => __FILE__, 'line' => __LINE__,
'code' => 500,
'message' => 'Request size limit exceeded (one of suhosin.request.max_array_depth/suhosin.post.max_array_depth)',
], true, false);
$this->rc->output->show_message('managesieve.filtersaveerror', 'error');
Expand Down
2 changes: 1 addition & 1 deletion plugins/markasjunk/drivers/amavis_blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function _do_list($uids, $spam)

if (is_file($config_file) && !$rcube->config->load_from_file($config_file)) {
rcube::raise_error([
'code' => 527, 'file' => __FILE__, 'line' => __LINE__,
'code' => 527,
'message' => "Failed to load config from {$config_file}",
], true, false);

Expand Down
2 changes: 1 addition & 1 deletion plugins/markasjunk/drivers/sa_blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function _do_list($uids, $spam)

if (is_file($config_file) && !$rcube->config->load_from_file($config_file)) {
rcube::raise_error([
'code' => 527, 'file' => __FILE__, 'line' => __LINE__,
'code' => 527,
'message' => "Failed to load config from {$config_file}",
], true, false);

Expand Down
4 changes: 0 additions & 4 deletions plugins/markasjunk/markasjunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ private function _init_driver()
if (!is_readable($driver)) {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "markasjunk plugin: Unable to open driver file {$driver}",
], true, false);
}
Expand All @@ -326,8 +324,6 @@ private function _init_driver()
if (!class_exists($class, false) || !method_exists($class, 'spam') || !method_exists($class, 'ham')) {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "markasjunk plugin: Broken driver: {$driver}",
], true, false);
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/chpasswd.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$cmd}",
], true, false);

Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/dbmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$curdir}/chgdbmailusers",
], true, false);

Expand Down
4 changes: 2 additions & 2 deletions plugins/password/drivers/dovecot_passwdfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function save($currpass, $newpass, $username)

if (empty($fp)) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Unable to read password file {$mailuserfile}.",
], true, false);

Expand Down Expand Up @@ -79,7 +79,7 @@ public function save($currpass, $newpass, $username)
fclose($fp);

rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Failed to save file {$mailuserfile}.",
], true, false);

Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$cmd}",
], true, false);

Expand Down
4 changes: 0 additions & 4 deletions plugins/password/drivers/gearman.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Gearman authentication failed for user {$username}",
], true, false);
} else {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => 'Password plugin: PECL Gearman module not loaded',
], true, false);
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/password/drivers/httpapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function save($curpass, $newpass, $username)
$params['query'] = $vars;
} else {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => 'Password plugin: Invalid httpapi method',
], true, false);

Expand All @@ -95,7 +95,7 @@ public function save($curpass, $newpass, $username)
$result = $response->getBody();
} catch (Exception $e) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => 'Password plugin: ' . $e->getMessage(),
], true, false);

Expand All @@ -105,7 +105,7 @@ public function save($curpass, $newpass, $username)
// Non-2xx response codes mean the password change failed
if ($response_code < 200 || $response_code > 299) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Unexpected response code {$response_code}: "
. substr($result, 0, 1024),
], true, false);
Expand All @@ -116,7 +116,7 @@ public function save($curpass, $newpass, $username)
// If configured, check the body of the response
if ($expect && !preg_match($expect, $result)) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => 'Password plugin: Unexpected response body: ' . substr($result, 0, 1024),
], true, false);

Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/kpasswd.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$cmd}",
], true, false);

Expand Down
4 changes: 2 additions & 2 deletions plugins/password/drivers/ldap_exop.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function save($curpass, $passwd)
{
if (!function_exists('ldap_exop_passwd')) {
rcube::raise_error([
'code' => 100, 'type' => 'ldap',
'file' => __FILE__, 'line' => __LINE__,
'code' => 100,
'type' => 'ldap',
'message' => 'ldap_exop_passwd not supported',
], true);

Expand Down
2 changes: 1 addition & 1 deletion plugins/password/drivers/ldap_ppolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function save($currpass, $newpass, $username)
return PASSWORD_CONNECT_ERROR;
default:
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Failed to execute command: {$cmd}. Output: {$result}. Error: {$stderr}",
], true, false);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/password/drivers/ldap_samba_ad.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function save($curpass, $passwd)
{
if (!function_exists('ldap_mod_replace')) {
rcube::raise_error([
'code' => 100, 'type' => 'ldap',
'file' => __FILE__, 'line' => __LINE__,
'code' => 100,
'type' => 'ldap',
'message' => 'ldap_mod_replace() not supported',
], true);

Expand Down
4 changes: 2 additions & 2 deletions plugins/password/drivers/ldap_simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function connect($curpass)
$this->_debug('S: NOT OK');

rcube::raise_error([
'code' => 100, 'type' => 'ldap',
'file' => __FILE__, 'line' => __LINE__,
'code' => 100,
'type' => 'ldap',
'message' => 'Could not connect to LDAP server',
], true);

Expand Down
2 changes: 1 addition & 1 deletion plugins/password/drivers/mailcow.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function save($curpass, $passwd, $username)
}

rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Problem with Mailcow API: {$result}",
], true, false);

Expand Down
2 changes: 1 addition & 1 deletion plugins/password/drivers/miab.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function save($currpass, $newpass, $username)
}

rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'code' => 600,
'message' => "Password plugin: Unable to change password. {$result}",
], true, false);

Expand Down
4 changes: 0 additions & 4 deletions plugins/password/drivers/pam.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ public function save($currpass, $newpass, $username)
} else {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: PAM authentication failed for user {$username}: {$error}",
], true, false);
}
} else {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => 'Password plugin: PECL-PAM module not loaded',
], true, false);
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/pw_usermod.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$cmd}",
], true, false);

Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/pwned.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ public function retrieve_suffixes($url)
} catch (Exception $e) {
rcube::raise_error([
'message' => "Error fetching {$url} : {$e->getMessage()}",
'file' => __FILE__,
'line' => __LINE__,
], true, false);
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/sasl.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function save($currpass, $newpass, $username)

rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Password plugin: Unable to execute {$curdir}/chgsaslpasswd",
], true, false);

Expand Down
Loading

0 comments on commit a30e0ad

Please sign in to comment.