#!/usr/bin/perl
use strict;
use warnings;
use Sendmail::PMilter;
my $conn = 'local:/var/run/mymilter.sock';
my $milter = Sendmail::PMilter->new();
$milter->setconn($conn);
$milter->register('mymilter',
{}
Sendmail::PMilter::SMFI_CURR_ACTS
);
$< = $> = getpwnam 'nobody';
$milter->main()
####
$milter->register('mymilter',
{
envrcpt => \&my_envrcpt_callback,
},
Sendmail::PMilter::SMFI_CURR_ACTS
);
openlog 'mymilter', 'pid', Unix::Syslog::LOG_MAIL();
##
##
use Unix::Syslog qw(:macros :subs);
sub is_valid_host
{
my $host = shift;
return undef unless $host;
my ($name,$aliases,$addrtype,$net) = gethostbyname($host);
defined $name;
}
sub my_envrcpt_callback
{
my $ctx = shift;
my $rcpt_addr = $ctx->getsymval('{rcpt_addr}');
my ($fqdn) = ($rcpt_addr =~ /\@(\S+)/);
if (not is_valid_host($fqdn))
{
# no such machine?
syslog LOG_INFO, "$$: Rejected mail for $fqdn";
return Sendmail::PMilter::SMFIS_ACCEPT;
}
Sendmail::PMilter::SMFIS_ACCEPT;
}
##
##
my %cache;
sub is_valid_host
{
my $host = shift;
return undef unless $host;
$host = lc $host;
unless (exists $cache{$host})
{
my ($name,$aliases,$addrtype,$net) = gethostbyname($host);
$cache{$host} = $name;
}
$cache{$host};
}
##
##
++$msg_count;
$0 = "[mymilter:$msg_count@" . scalar(localtime) . "] Checking $fqdn ($rcpt_addr)";
##
##
#!/usr/bin/perl
use strict;
use warnings;
use Sendmail::PMilter;
use Unix::Syslog qw(:macros :subs);
my $conn = 'inet:33333@127.0.0.1';
$ENV{PMILTER_DISPATCHER} = 'prefork';
my %cache;
sub is_valid_host
{
my $host = shift;
return undef unless $host;
$host = lc $host;
unless (exists $cache{$host})
{
my ($name,$aliases,$addrtype,$net) = gethostbyname($host);
$cache{$host} = $name;
}
$cache{$host};
}
$SIG{ALRM} = sub { die "alarm\n" };
{
my $msg_count = 0;
sub my_envrcpt_callback
{
my $ctx = shift;
# if we're not used in 30 seconds, quit.
alarm 30;
my $rcpt_addr = $ctx->getsymval('{rcpt_addr}');
my ($fqdn) = ($rcpt_addr =~ /\@(\S+)/);
++$msg_count;
$0 = "[mymilter:$msg_count@" . scalar(localtime) . "] Checking $fqdn ($rcpt_addr)";
if (not is_valid_host($fqdn))
{
# no such machine?
syslog LOG_INFO, "$$: Rejected mail for $fqdn";
return Sendmail::PMilter::SMFIS_REJECT;
#return Sendmail::PMilter::SMFIS_ACCEPT;
}
Sendmail::PMilter::SMFIS_ACCEPT;
}
}
my $milter = Sendmail::PMilter->new();
$milter->setconn($conn);
$milter->register('mymilter',
{
envrcpt => \&my_envrcpt_callback,
},
Sendmail::PMilter::SMFI_CURR_ACTS
);
openlog 'mymilter', 'pid', Unix::Syslog::LOG_MAIL();
$< = $> = getpwnam 'nobody';
syslog LOG_INFO, "Starting up: $$";
END { closelog }
$milter->main(10,100);