diff --git a/src/lib/Conf.pm b/src/lib/Conf.pm index 4a2a2d5fa..10610fcb8 100644 --- a/src/lib/Conf.pm +++ b/src/lib/Conf.pm @@ -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 -# . +# 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 . # # 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 @@ -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 = { @@ -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; } @@ -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'} = {}; @@ -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'}}); @@ -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', diff --git a/src/lib/Sympa/Aliases.pm b/src/lib/Sympa/Aliases.pm index e769c700c..ba202929a 100644 --- a/src/lib/Sympa/Aliases.pm +++ b/src/lib/Sympa/Aliases.pm @@ -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 # . # @@ -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". diff --git a/src/lib/Sympa/List.pm b/src/lib/Sympa/List.pm index c9928553d..c926ed8ce 100644 --- a/src/lib/Sympa/List.pm +++ b/src/lib/Sympa/List.pm @@ -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; diff --git a/src/lib/Sympa/Scenario.pm b/src/lib/Sympa/Scenario.pm index a85f3375e..180454158 100644 --- a/src/lib/Sympa/Scenario.pm +++ b/src/lib/Sympa/Scenario.pm @@ -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 { @@ -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 {}; } @@ -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 @@ -1156,14 +1159,14 @@ 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; } @@ -1171,7 +1174,7 @@ sub do_match { }; } else { eval { - if ($args[0] =~ /$args[1]/i) { + if (($args[0] // '') =~ /$args[1]/i) { $r = 1; } };