Skip to content

Commit

Permalink
Merge pull request #1830 from ikedas/issue-1325_part2 by ikedas
Browse files Browse the repository at this point in the history
Noise in Apache error_log (again) (#1325)
  • Loading branch information
ikedas authored Sep 6, 2024
2 parents 2bace30 + b4e9d29 commit d14befd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 72 deletions.
77 changes: 30 additions & 47 deletions src/lib/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2020, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
# Copyright 2017, 2018, 2019, 2020, 2021, 2022, 2024 The Sympa Community.
# See the AUTHORS.md file at the top-level directory of this distribution
# and at <https://github.com/sympa-community/sympa.git>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1517,49 +1517,43 @@ sub _infer_server_specific_parameter_values {

$param->{'config_hash'}{'robot_name'} = '';

unless ($param->{'config_hash'}{'dkim_signer_domain'}) {
$param->{'config_hash'}{'dkim_signer_domain'} =
$param->{'config_hash'}{'domain'};
}
$param->{'config_hash'}{'dkim_signer_domain'} ||=
$param->{'config_hash'}{'domain'};

my @dmarc = split /[,\s]+/,
my @dmarc = grep {length} split /[,\s]+/,
($param->{'config_hash'}{'dmarc_protection.mode'} || '');
if (@dmarc) {
$param->{'config_hash'}{'dmarc_protection.mode'} = \@dmarc;
$param->{'config_hash'}{'dmarc_protection.mode'} = [@dmarc];
} else {
delete $param->{'config_hash'}{'dmarc_protection.mode'};
}

## Set Regexp for accepted list suffixes
if (defined($param->{'config_hash'}{'list_check_suffixes'})) {
$param->{'config_hash'}{'list_check_regexp'} =
$param->{'config_hash'}{'list_check_suffixes'};
$param->{'config_hash'}{'list_check_regexp'} =~ s/[,\s]+/\|/g;
}

# my $p = 1;
# foreach (split(/,/, $param->{'config_hash'}{'sort'})) {
# $param->{'config_hash'}{'poids'}{$_} = $p++;
# }
# $param->{'config_hash'}{'poids'}{'*'} = $p
# if !$param->{'config_hash'}{'poids'}{'*'};
# Accepted list suffixes.
$param->{'config_hash'}{'list_check_suffixes'} = [
grep {length} split /[,\s]+/,
($param->{'config_hash'}{'list_check_suffixes'} // '')
];

## Parameters made of comma-separated list
# Parameters made of comma-separated list.
# Note that whitespace character(s) cannot be a separator, because the
# value of remove_outgoing_headers can contain them.
foreach my $parameter (
'rfc2369_header_fields', 'anonymous_header_fields',
'remove_headers', 'remove_outgoing_headers'
) {
if ($param->{'config_hash'}{$parameter} eq 'none') {
if ('none' eq ($param->{'config_hash'}{$parameter} // '')
or not length($param->{'config_hash'}{$parameter} // '')) {
delete $param->{'config_hash'}{$parameter};
} else {
$param->{'config_hash'}{$parameter} =
[split(/,/, $param->{'config_hash'}{$parameter})];
$param->{'config_hash'}{$parameter} = [
grep {length} split /\s*,\s*/,
$param->{'config_hash'}{$parameter}
];
}
}

foreach
my $action (split /\s*,\s*/, $param->{'config_hash'}{'use_blocklist'})
{
foreach my $action (split /\s*,\s*/,
($param->{'config_hash'}{'use_blocklist'} // '')) {
next unless $action =~ /\A[.\w]+\z/;
# Compat. <= 6.2.38
$action = {
Expand All @@ -1576,20 +1570,6 @@ sub _infer_server_specific_parameter_values {
$param->{'config_hash'}{'blocklist'}{$action} = 1;
}

if ($param->{'config_hash'}{'ldap_export_name'}) {
$param->{'config_hash'}{'ldap_export'} = {
$param->{'config_hash'}{'ldap_export_name'} => {
'host' => $param->{'config_hash'}{'ldap_export_host'},
'suffix' => $param->{'config_hash'}{'ldap_export_suffix'},
'password' => $param->{'config_hash'}{'ldap_export_password'},
'DnManager' =>
$param->{'config_hash'}{'ldap_export_dnmanager'},
'connection_timeout' =>
$param->{'config_hash'}{'ldap_export_connection_timeout'}
}
};
}

return 1;
}

Expand All @@ -1611,7 +1591,8 @@ sub _load_server_specific_secondary_config_files {
|| 'en-US';

## Load charset.conf file if necessary.
if ($param->{'config_hash'}{'legacy_character_support_feature'} eq 'on') {
if ('on' eq
($param->{'config_hash'}{'legacy_character_support_feature'} // '')) {
$param->{'config_hash'}{'locale2charset'} = load_charset();
} else {
$param->{'config_hash'}{'locale2charset'} = {};
Expand Down Expand Up @@ -1694,8 +1675,10 @@ sub _infer_robot_parameter_values {
Sympa::Language::canonic_lang($param->{'config_hash'}{'lang'})
or delete $param->{'config_hash'}{'lang'};

$param->{'config_hash'}{'dkim_signature_apply_on'} =
[split /\s*,\s*/, $param->{'config_hash'}{'dkim_signature_apply_on'}];
$param->{'config_hash'}{'dkim_signature_apply_on'} = [
grep {length} split /[,\s]+/,
($param->{'config_hash'}{'dkim_signature_apply_on'} // '')
];

_parse_custom_robot_parameters(
{'config_hash' => $param->{'config_hash'}});
Expand Down Expand Up @@ -1764,7 +1747,7 @@ sub _check_cpan_modules_required_by_config {
my $number_of_missing_modules = 0;

## Some parameters require CPAN modules
if ($param->{'config_hash'}{'dkim_feature'} eq 'on') {
if ('on' eq ($param->{'config_hash'}{'dkim_feature'} // '')) {
eval "require Mail::DKIM";
if ($EVAL_ERROR) {
$log->syslog('notice',
Expand Down
18 changes: 8 additions & 10 deletions src/lib/Sympa/Aliases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2017, 2018, 2021 The Sympa Community. See the
# Copyright 2017, 2018, 2021, 2024 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -108,15 +108,13 @@ sub check_new_listname {
return ('user', 'incorrect_listname', {bad_listname => $listname});
}

my $regx = Conf::get_robot_conf($robot_id, 'list_check_regexp');
if ($regx) {
if ($listname =~ /^(\S+)-($regx)$/) {
$log->syslog('err',
'Incorrect listname %s matches one of service aliases',
$listname);
return ('user', 'listname_matches_aliases',
{new_listname => $listname});
}
my $sfxs = Conf::get_robot_conf($robot_id, 'list_check_suffixes') // [];
if (grep { lc("-$_") eq substr $listname, -length("-$_") } @$sfxs) {
$log->syslog('err',
'Incorrect listname %s matches one of service aliases',
$listname);
return ('user', 'listname_matches_aliases',
{new_listname => $listname});
}

# Avoid "sympa", "listmaster", "bounce" and "bounce+XXX".
Expand Down
16 changes: 6 additions & 10 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,12 @@ sub new {
$name =~ tr/A-Z/a-z/;

## Reject listnames with reserved list suffixes
my $regx = Conf::get_robot_conf($robot, 'list_check_regexp');
if ($regx) {
if ($name =~ /^(\S+)-($regx)$/) {
$log->syslog(
'err',
'Incorrect name: listname "%s" matches one of service aliases',
$name
) unless ($options->{'just_try'});
return undef;
}
my $sfxs = Conf::get_robot_conf($robot, 'list_check_suffixes') // [];
if (grep { lc("-$_") eq substr $name, -length("-$_") } @$sfxs) {
$log->syslog('err',
'Incorrect listname %s matches one of service aliases', $name)
unless $options->{'just_try'};
return undef;
}

my $status;
Expand Down
13 changes: 8 additions & 5 deletions src/lib/Sympa/Scenario.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ sub do_verify_netmask {
return 0 unless defined $ENV{'REMOTE_ADDR'};

my @cidr;
if ($args[0] eq 'default' or $args[0] eq 'any') {
unless (length($args[0] // '')) {
;
} elsif ($args[0] eq 'default' or $args[0] eq 'any') {
# Compatibility with Net::Netmask, adding IPv6 feature.
@cidr = ('0.0.0.0/0', '::/0');
} else {
Expand All @@ -1048,7 +1050,7 @@ sub do_verify_netmask {
}
unless (@cidr) {
$log->syslog('err', 'Error rule syntax: failed to parse netmask "%s"',
$args[0]);
$args[0] // '');
die {};
}

Expand Down Expand Up @@ -1084,6 +1086,7 @@ sub do_is_owner {
my $condition_key = shift;
my @args = @_;

return 0 unless defined $args[0] and defined $args[1];
return 0 if $args[1] eq 'nobody';

# The list is local or in another local robot
Expand Down Expand Up @@ -1156,22 +1159,22 @@ sub do_match {
my @args = @_;

# Nothing can match an empty regexp.
return 0 unless length $args[1];
return 0 unless length($args[1] // '');

# wrap matches with eval{} to avoid crash by malformed regexp.
my $r = 0;
if (ref $args[0] eq 'ARRAY') {
eval {
foreach my $arg (@{$args[0]}) {
if ($arg =~ /$args[1]/i) {
if (($arg // '') =~ /$args[1]/i) {
$r = 1;
last;
}
}
};
} else {
eval {
if ($args[0] =~ /$args[1]/i) {
if (($args[0] // '') =~ /$args[1]/i) {
$r = 1;
}
};
Expand Down

0 comments on commit d14befd

Please sign in to comment.