[pmg-devel] [PATCH pmg-api 1/4] add helper for parsing SA channel.d files

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Dec 30 14:07:03 CET 2020


On December 16, 2020 6:18 pm, Stoiko Ivanov wrote:
> RHEL/CentOS based SpamAssassin implementations ship an update script,
> which reads shell snippets from
> /etc/mail/spamassassin/channel.d/*.conf and uses the information there
> to update SA rules from the configured channels [0].
> 
> Noticed the existence of this directory/mechanism while reading the
> announcement of the updatechannel for the KAM ruleset [1].
> 
> Parsing the file as text, instead of sourcing it in a shell, since I
> hope that the channel files distributed don't rely on running commands
> to get the ruleset url and gpg key.
> 
> [0] https://src.fedoraproject.org/rpms/spamassassin/blob/master/f/sa-update.cronscript
> [1] https://mcgrail.com/template/kam.cf_channel
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/PMG/Utils.pm | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
> index d3fae9e..3f5b045 100644
> --- a/src/PMG/Utils.pm
> +++ b/src/PMG/Utils.pm
> @@ -1442,5 +1442,32 @@ sub domain_regex {
>      return $regex;
>  }
>  
> +sub local_spamassassin_channels {
> +
> +    my $res = [];
> +
> +    my $local_channel_dir = '/etc/mail/spamassassin/channel.d/';
> +    my $read_sa_channel = sub {
> +	my ($filename) = @_;
> +
> +	my $channel_file = $local_channel_dir.$filename;
> +	my $content = PVE::Tools::file_get_contents($channel_file);
> +	my $channel = {
> +	    filename => $channel_file,
> +	};
> +
> +	($channel->{keyid}) = ($content =~ /^KEYID=([a-fA-F0-9]+)$/m);
> +	die "no KEYID in $filename!\n" if !defined($channel->{keyid});
> +	($channel->{channelurl}) = ($content =~ /CHANNELURL=(.+)$/m);

should maybe be anchored as well?

> +	die "no CHANNELURL in $filename!\n" if !defined($channel->{channelurl});
> +	($channel->{gpgkey}) = ($content =~ /(-----BEGIN PGP PUBLIC KEY BLOCK-----.+-----END PGP PUBLIC KEY BLOCK-----)/s);

could also be anchored:

(^|\n)

(\n|$)

or something similar

> +	die "no GPG public key in $filename!\n" if !defined($channel->{gpgkey});
> +
> +	push(@$res, $channel);
> +    };
> +
> +    PVE::Tools::dir_glob_foreach($local_channel_dir, '.*\.conf', $read_sa_channel);
> +    return $res;
> +}
>  
>  1;
> -- 
> 2.20.1
> 
> 
> 
> _______________________________________________
> pmg-devel mailing list
> pmg-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
> 
> 
> 




More information about the pmg-devel mailing list