You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by MAILIST <ma...@toolz.com> on 2019/10/25 21:37:37 UTC

Plugin I Authored Stopped Working

When I first wrote this plugin for Spamassassin (using some code from
other plugins) it worked exactly as designed.  About 2 years ago,
Spamassassin had an update, and the plugin quit working.

I have hammered on this code and read all documentation I can find on
S/A plugins using net searches.  I am hoping that there is someone more
expert reading this list than I.  There are no other modules with the
same name.

There are 3 parts:
1. local.cf - loads the plugin
2. LocalBlocklist.pm - the plugin
3. /var/log/mail.log - spamd log with debug on
The environment is CentOS 7 at the latest rev.

Another plugin I wrote that saves spams to a file works correctly.

I would not post an RFC to a mailing list unless I believed I had
exhausted all possible resources.

Todd Merriman
Software Toolz, Inc.

local.cf
---------
loadplugin LocalBlocklist /home/common/shared/perl/LocalBlocklist.pm
....
header   LOCAL_BLOCKLIST eval:check_local_blocklist()
describe LOCAL_BLOCKLIST Sent from network known to primarily source spam
score    LOCAL_BLOCKLIST 3.6


LocalBlocklist.pm
-----------------
package Mail::SpamAssassin::Plugin::LocalBlocklist;
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Logger;
use strict;
use warnings;
use DBI;
use Sys::Hostname;
use lib '/home/common/shared/perl';
require 'syms2.pl';
use libcsub;
use liborder;
use libsql;

our $VERSION = '$Revision: 1.14 $';

use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);

#
# constructor
#

sub new
{
  my ($class, $mailsa) = @_;
  $class = ref($class) || $class;
  my $self = $class->SUPER::new($mailsa);
  bless ($self, $class);
  my $vcstr = '$Id: LocalBlocklist.pm,v 1.14 2019/10/25 21:09:33 todd Exp $';

   # eval rules
   $self->register_eval_rule ("check_local_blocklist");

   info("LocalBlocklist: $vcstr plugin enabled. " . __FILE__ . '/' .
__LINE__);
   dbg("LocalBlocklist: registered
Mail::SpamAssassin::Plugin::LocalBlocklist:
$self");
   return $self;
}

sub check_local_blocklist
{
	use File::Basename;
   my ($self, $pms) = @_;
	my ($ip) = '';
   my $received = $pms->get("Received");
   my $to = $pms->get("To");
   my $from = $pms->get("From");
	$received =~ s/\n/ /g;
	dbg("LocalBlocklist: check_local_blocklist: received=($received) " .
__FILE__ . "/" . __LINE__);
	my $xip = $pms->get('X-Sender-Ip');
	if ("$to" eq "$from")
	{
		dbg("LocalBlocklist: send and receiver are the same: $to");
		return 1;
	}
	dbg("LocalBlocklist: check_local_blocklist: X-Sender-Ip=$xip" . __FILE__
. "/" . __LINE__);
	if ($received =~ m/.+\[(\d+\.\d+\.\d+\.\d+?)\]/)
  {
	 $ip = $1;
	 $ip =~ m/^10\.0\.0\./
	 	and return 0;
	 dbg("LocalBlocklist: ip=($ip) " . __FILE__ . "/" . __LINE__);
		my ($dbh) = orderdb_open;
		my ($sth) = $dbh->prepare("select ip from spamip\
			where inet_aton(\"$ip\") & inet_aton(netmask)\
			= inet_aton(ip) & inet_aton(netmask)");
	 if ($sth->execute > 0)
	 {
	 	my $match = $sth->fetchrow_array;
		$sth->finish;
		use Sys::Hostname;
		my $cl = basename(__FILE__);
		my ($node,undef,undef) = split /\./,hostname();
		$dbh->do("insert into events\
			(eventname,datim,msg,caller,node,remote)\
			values\
			('TRAP',now(),\"match ($match) in spamip
table\",\"$cl\",\"$node\",\"$ip\")");
		orderdb_close($dbh);
		dbg("LocalBlocklist: match in spamip table: $ip $cl");
		return 1;
	 }
	 $sth->finish;
	 orderdb_close($dbh);
  }
  else
  {
		dbg("LocalBlocklist: no IP to check " . __FILE__ . '/' . __LINE__);
  }

   return 0;
}

sub DESTROY
{
}

1;


/var/log/mail.log
-----------------
Oct 25 17:07:02 ms spamd[4048]: rules: failed to run LOCAL_BLOCKLIST test,
skipping:
Oct 25 17:07:02 ms spamd[4048]: (Can't locate object method
"check_local_blocklist" via package "Mail:
[...]:SpamAssassin::PerMsgStatus" at (eval 1655) line 279, <GEN951> line
1231.
Oct 25 17:07:02 ms spamd[4048]: )


Re: Plugin I Authored Stopped Working

Posted by Benny Pedersen <me...@junc.eu>.
MAILIST skrev den 2019-10-25 23:37:

> local.cf
> ---------
> loadplugin LocalBlocklist /home/common/shared/perl/LocalBlocklist.pm

> LocalBlocklist.pm
> -----------------
> package Mail::SpamAssassin::Plugin::LocalBlocklist;

> /var/log/mail.log
> -----------------
> Oct 25 17:07:02 ms spamd[4048]: rules: failed to run LOCAL_BLOCKLIST 
> test,

loadplugin does not match package name

loadplugin Mail::SpamAssassin::Plugin::LocalBlocklist 
/home/common/shared/perl/LocalBlocklist.pm

solved ?

sorry i am not a perl expert :=)