dbaa9dbd6c
on files in plugins dir: fixed a number of POD errors formatted some # comments into POD removed bare 1; (these are plugins, not perl modules) most instances of this were copy/pasted from a previous plugin that had it removed instances of # vim ts=N ... they weren't consistent, many didn't match .perltidyrc on modules that failed perl -c tests, added 'use Qpsmtpd::Constants;' Conflicts: plugins/async/check_earlytalker plugins/async/dns_whitelist_soft plugins/async/dnsbl plugins/async/queue/smtp-forward plugins/async/require_resolvable_fromhost plugins/async/rhsbl plugins/async/uribl plugins/auth/auth_checkpassword plugins/auth/auth_cvm_unix_local plugins/auth/auth_flat_file plugins/auth/auth_ldap_bind plugins/auth/auth_vpopmail plugins/auth/auth_vpopmail_sql plugins/auth/authdeny plugins/check_badmailfromto plugins/check_badrcptto_patterns plugins/check_bogus_bounce plugins/check_earlytalker plugins/check_norelay plugins/check_spamhelo plugins/connection_time plugins/dns_whitelist_soft plugins/dnsbl plugins/domainkeys plugins/greylisting plugins/hosts_allow plugins/http_config plugins/logging/adaptive plugins/logging/apache plugins/logging/connection_id plugins/logging/transaction_id plugins/logging/warn plugins/milter plugins/queue/exim-bsmtp plugins/queue/maildir plugins/queue/postfix-queue plugins/queue/smtp-forward plugins/quit_fortune plugins/random_error plugins/rcpt_map plugins/rcpt_regexp plugins/relay_only plugins/require_resolvable_fromhost plugins/rhsbl plugins/sender_permitted_from plugins/spamassassin plugins/tls plugins/tls_cert plugins/uribl plugins/virus/aveclient plugins/virus/bitdefender plugins/virus/clamav plugins/virus/clamdscan plugins/virus/hbedv plugins/virus/kavscanner plugins/virus/klez_filter plugins/virus/sophie plugins/virus/uvscan
80 lines
2.4 KiB
Perl
80 lines
2.4 KiB
Perl
#!perl -Tw
|
|
|
|
=head1 NAME
|
|
|
|
hosts_allow - decide if a host is allowed to send mail
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
The B<hosts_allow> module decides before the SMTP-Greeting if a host is
|
|
allowed to connect. It checks for too many (running) connections from one
|
|
host (see -m/--max-from-ip options in qpsmtpd-forkserver) and the config
|
|
file I<hosts_allow>.
|
|
The plugin takes no arguments.
|
|
|
|
=head1 CONFIG
|
|
|
|
The config file contains lines with two or three items. The first is either
|
|
an IP address or a network/mask pair. The second is a (valid) return code
|
|
from Qpsmtpd::Constants. The last is a comment which will be returned to the
|
|
connecting client if the return code is DENY or DENYSOFT (and of course
|
|
DENY_DISCONNECT and DENYSOFT_DISCONNECT).
|
|
Example:
|
|
|
|
192.168.3.4 DECLINED
|
|
192.168.3.0/24 DENY Sorry, known spam only source
|
|
|
|
This would exclude 192.168.3.4 from the DENY of 192.168.3.0/24.
|
|
|
|
=cut
|
|
|
|
use Qpsmtpd::Constants;
|
|
use Socket;
|
|
|
|
sub hook_pre_connection {
|
|
my ($self,$transaction,%args) = @_;
|
|
|
|
# remote_ip => inet_ntoa($iaddr),
|
|
# remote_port => $port,
|
|
# local_ip => inet_ntoa($laddr),
|
|
# local_port => $lport,
|
|
# max_conn_ip => $MAXCONNIP,
|
|
# child_addrs => [values %childstatus],
|
|
|
|
my $remote = $args{remote_ip};
|
|
|
|
if ($args{max_conn_ip}) {
|
|
my $num_conn = 1; # seed with current value
|
|
my $raddr = inet_aton($remote);
|
|
foreach my $rip (@{$args{child_addrs}}) {
|
|
++$num_conn if (defined $rip && $rip eq $raddr);
|
|
}
|
|
if ($num_conn > $args{max_conn_ip}) {
|
|
$self->log(LOGINFO,
|
|
"Too many connections from $remote: "
|
|
. "$num_conn > " . $args{max_conn_ip}
|
|
. "Denying connection.");
|
|
return (DENYSOFT, "Sorry, too many connections from $remote, "
|
|
."try again later");
|
|
}
|
|
}
|
|
|
|
foreach ($self->qp->config("hosts_allow")) {
|
|
s/^\s*//;
|
|
my ($ipmask, $const, $message) = split /\s+/, $_, 3;
|
|
next unless defined $const;
|
|
|
|
my ($net,$mask) = split '/', $ipmask, 2;
|
|
if (!defined $mask) {
|
|
$mask = 32;
|
|
}
|
|
$mask = pack "B32", "1"x($mask)."0"x(32-$mask);
|
|
if (join(".", unpack("C4", inet_aton($remote) & $mask)) eq $net) {
|
|
$const = Qpsmtpd::Constants::return_code($const) || DECLINED;
|
|
return($const, $message);
|
|
}
|
|
}
|
|
|
|
return (DECLINED);
|
|
}
|