r483@dog: rspier | 2005-07-06 21:17:00 -0700

The great plugin renaming in the name of inheritance and standardization commit.
 
 1. new concept of standard hook_ names.
 2. Plugin::init
 3. renamed many subroutines in plugins (and cleaned up register subs)
 4. updated README.plugins
 


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@479 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Robert Spier 2005-07-07 04:17:39 +00:00
parent 254b4fd2b2
commit 90daeb3786
45 changed files with 169 additions and 223 deletions

View File

@ -270,3 +270,82 @@ ended.
Returns the configured system-wide spool directory. Returns the configured system-wide spool directory.
=back =back
=head1 Naming Conventions
Plugins should be written using standard named hook subroutines. This
allows them to be overloaded and extended easily.
Because some of our callback names have characters invalid in
subroutine names, they must be translated. The current translation
routine is: C< s/\W/_/g; >
=head2 Naming Map
hook method
---------- ------------
config hook_config
queue hook_queue
data hook_data
data_post hook_data_post
quit hook_quit
rcpt hook_rcpt
mail hook_mail
ehlo hook_ehlo
helo hook_helo
auth hook_auth
auth-plain hook_auth_plain
auth-login hook_auth_login
auth-cram-md5 hook_auth_cram_md5
connect hook_connect
reset_transaction hook_reset_transaction
unrecognized_command hook_unrecognized_command
=head1 Register
If you choose not to use the default naming convention, you need to
register the hooks in your plugin. You do this with the C< register >
method call on the plugin object.
sub register {
my ($self, $qp) = @_;
$self->register_hook('mail', 'mail_handler');
$self->register_hook('rcpt', 'rcpt_handler');
$self->register_hook('disconnect', 'disconnect_handler');
}
sub mail_handler { ... }
sub rcpt_handler { ... }
sub disconnect_handler { ... }
A single plugin can register as many hooks as it wants, and can
register a hook multiple times.
The C< register > method is also often used for initialization and
reading configuration.
=head1 Init
The 'init' method is the first method called after a plugin is
loaded. It's mostly for inheritance, below.
=head1 Inheritance
Instead of modifying @ISA directly in your plugin, use the
C< plugin_isa > method from the init subroutine.
# rcpt_ok_child
sub init {
my ($self, $qp) = @_;
$self->isa_plugin('rcpt_ok');
}
sub hook_rcpt {
my ($self, $transaction, $recipient) = @_;
# do something special here...
$self->SUPER::hook_rcpt( $transaction, $recipient );
}

View File

@ -1,4 +1,5 @@
package Qpsmtpd::Plugin; package Qpsmtpd::Plugin;
use Qpsmtpd::Constants;
use strict; use strict;
our %hooks = map { $_ => 1 } qw( our %hooks = map { $_ => 1 } qw(
@ -19,6 +20,8 @@ sub register_hook {
die $plugin->plugin_name . " : Invalid hook: $hook" unless $hooks{$hook}; die $plugin->plugin_name . " : Invalid hook: $hook" unless $hooks{$hook};
$plugin->{_qp}->varlog(LOGDEBUG, $plugin->plugin_name, " hooking ", $hook);
# I can't quite decide if it's better to parse this code ref or if # I can't quite decide if it's better to parse this code ref or if
# we should pass the plugin object and method name ... hmn. # we should pass the plugin object and method name ... hmn.
$plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; local $plugin->{_hook} = $hook; $plugin->$method(@_) }, $plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; local $plugin->{_hook} = $hook; $plugin->$method(@_) },
@ -32,7 +35,9 @@ sub _register {
my $self = shift; my $self = shift;
my $qp = shift; my $qp = shift;
local $self->{_qp} = $qp; local $self->{_qp} = $qp;
$self->register($qp, @_); $self->init($qp, @_) if $self->can('init');
$self->_register_standard_hooks($qp, @_);
$self->register($qp, @_) if $self->can('register');
} }
sub qp { sub qp {
@ -74,7 +79,7 @@ sub temp_dir {
# plugin inheritance: # plugin inheritance:
# usage: # usage:
# sub register { # sub init {
# my $self = shift; # my $self = shift;
# $self->isa_plugin("rhsbl"); # $self->isa_plugin("rhsbl");
# $self->SUPER::register(@_); # $self->SUPER::register(@_);
@ -82,18 +87,23 @@ sub temp_dir {
sub isa_plugin { sub isa_plugin {
my ($self, $parent) = @_; my ($self, $parent) = @_;
my ($currentPackage) = caller; my ($currentPackage) = caller;
my $newPackage = $currentPackage."::_isa_";
my $cleanParent = $parent;
$cleanParent =~ s/\W/_/g;
my $newPackage = $currentPackage."::_isa_$cleanParent";
return if defined &{"${newPackage}::register"}; return if defined &{"${newPackage}::register"};
Qpsmtpd::_compile($self->plugin_name . "_isa", $self->compile($self->plugin_name . "_isa_$cleanParent",
$newPackage, $newPackage,
"plugins/$parent"); # assumes Cwd is qpsmtpd root "plugins/$parent"); # assumes Cwd is qpsmtpd root
warn "---- $newPackage\n";
no strict 'refs'; no strict 'refs';
push @{"${currentPackage}::ISA"}, $newPackage; push @{"${currentPackage}::ISA"}, $newPackage;
} }
# why isn't compile private? it's only called from Plugin and Qpsmtpd.
sub compile { sub compile {
my ($class, $plugin, $package, $file, $test_mode) = @_; my ($class, $plugin, $package, $file, $test_mode) = @_;
@ -141,4 +151,16 @@ sub compile {
die "eval $@" if $@; die "eval $@" if $@;
} }
sub _register_standard_hooks {
my ($plugin, $qp) = @_;
for my $hook (keys %hooks) {
my $hooksub = "hook_$hook";
$hooksub =~ s/\W/_/g;
$plugin->register_hook( $hook, $hooksub )
if ($plugin->can($hooksub));
}
}
1; 1;

View File

@ -5,12 +5,7 @@
# the Qpsmtpd::Auth module. Don't run this in production!!! # the Qpsmtpd::Auth module. Don't run this in production!!!
# #
sub register { sub hook_auth {
my ( $self, $qp ) = @_;
$self->register_hook( "auth", "authdeny" );
}
sub authdeny {
my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) = my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) =
@_; @_;

View File

@ -5,17 +5,7 @@
# the Qpsmtpd::Auth module. Don't run this in production!!! # the Qpsmtpd::Auth module. Don't run this in production!!!
# #
sub register { sub hook_auth {
my ( $self, $qp ) = @_;
# $self->register_hook("auth-plain", "authnull");
# $self->register_hook("auth-login", "authnull");
# $self->register_hook("auth-cram-md5", "authnull");
$self->register_hook( "auth", "authnull" );
}
sub authnull {
my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) = my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) =
@_; @_;

View File

@ -20,13 +20,7 @@ stage, so store it until later.
=cut =cut
sub register { sub hook_mail {
my ($self, $qp) = @_;
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
}
sub mail_handler {
my ($self, $transaction, $sender) = @_; my ($self, $transaction, $sender) = @_;
my @badmailfrom = $self->qp->config("badmailfrom") my @badmailfrom = $self->qp->config("badmailfrom")
@ -49,7 +43,7 @@ sub mail_handler {
return (DECLINED); return (DECLINED);
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
my $note = $transaction->notes('badmailfrom'); my $note = $transaction->notes('badmailfrom');
if ($note) { if ($note) {

View File

@ -16,13 +16,7 @@ Based heavily on check_badmailfrom.
=cut =cut
sub register { sub hook_mail {
my ($self, $qp) = @_;
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
}
sub mail_handler {
my ($self, $transaction, $sender) = @_; my ($self, $transaction, $sender) = @_;
my @badmailfromto = $self->qp->config("badmailfromto") my @badmailfromto = $self->qp->config("badmailfromto")
@ -46,7 +40,7 @@ sub mail_handler {
return (DECLINED); return (DECLINED);
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
my $recipient = lc($rcpt->user) . '@' . lc($rcpt->host); my $recipient = lc($rcpt->user) . '@' . lc($rcpt->host);
my $sender = $transaction->notes('badmailfromto'); my $sender = $transaction->notes('badmailfromto');

View File

@ -1,11 +1,6 @@
# this plugin checks the badrcptto config (like badmailfrom for rcpt address) # this plugin checks the badrcptto config (like badmailfrom for rcpt address)
sub register { sub hook_rcpt {
my ($self, $qp) = @_;
$self->register_hook("rcpt", "check_for_badrcptto");
}
sub check_for_badrcptto {
my ($self, $transaction, $recipient) = @_; my ($self, $transaction, $recipient) = @_;
my @badrcptto = $self->qp->config("badrcptto") or return (DECLINED); my @badrcptto = $self->qp->config("badrcptto") or return (DECLINED);
return (DECLINED) unless $recipient->host && $recipient->user; return (DECLINED) unless $recipient->host && $recipient->user;

View File

@ -26,13 +26,7 @@ terms as Perl itself.
=cut =cut
sub register sub hook_rcpt
{
my ($self, $qp) = @_;
$self->register_hook("rcpt", "check_for_badrcptto_patterns");
}
sub check_for_badrcptto_patterns
{ {
my ($self, $transaction, $recipient) = @_; my ($self, $transaction, $recipient) = @_;

View File

@ -33,7 +33,6 @@ use Date::Parse qw(str2time);
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "check_basic_headers");
if (@args > 0) { if (@args > 0) {
$self->{_days} = $args[0]; $self->{_days} = $args[0];
@ -41,7 +40,7 @@ sub register {
} }
} }
sub check_basic_headers { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
return (DENY, "You have to send some data first") return (DENY, "You have to send some data first")

View File

@ -28,7 +28,6 @@ Released to the public domain, 17 June 2005.
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "check_loop");
$self->{_max_hops} = $args[0] || 100; $self->{_max_hops} = $args[0] || 100;
@ -38,7 +37,7 @@ sub register {
$self->log(LOGWARN, "Ignoring additional arguments") if @args > 1; $self->log(LOGWARN, "Ignoring additional arguments") if @args > 1;
} }
sub check_loop { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $hops = 0; my $hops = 0;

View File

@ -34,12 +34,7 @@ terms as Perl itself.
=cut =cut
sub register { sub hook_connect {
my ($self, $qp) = @_;
$self->register_hook("connect", "check_norelay");
}
sub check_norelay {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $connection = $self->qp->connection; my $connection = $self->qp->connection;

View File

@ -2,12 +2,7 @@
# $ENV{RELAYCLIENT} to see if relaying is allowed. # $ENV{RELAYCLIENT} to see if relaying is allowed.
# #
sub register { sub hook_connect {
my ($self, $qp) = @_;
$self->register_hook("connect", "check_relay");
}
sub check_relay {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $connection = $self->qp->connection; my $connection = $self->qp->connection;

View File

@ -16,13 +16,7 @@ per line.
=cut =cut
sub register { sub hook_helo {
my ($self, $qp) = @_;
$self->register_hook("helo", "check_helo");
$self->register_hook("ehlo", "check_helo");
}
sub check_helo {
my ($self, $transaction, $host) = @_; my ($self, $transaction, $host) = @_;
($host = lc $host) or return DECLINED; ($host = lc $host) or return DECLINED;
@ -35,3 +29,5 @@ sub check_helo {
return DECLINED; return DECLINED;
} }
# also support EHLO
*hook_ehlo = \&hook_helo;

View File

@ -6,12 +6,7 @@
use POSIX qw:strftime:; use POSIX qw:strftime:;
sub register { sub hook_data_post {
my ($self, $qp) = @_;
$self->register_hook("data_post", "mail_handler");
}
sub mail_handler {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
# as a decent default, log on a per-day-basis # as a decent default, log on a per-day-basis

View File

@ -17,7 +17,6 @@ before we disconnect the client. Defaults to 4.
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("unrecognized_command", "check_unrec_cmd");
if (@args > 0) { if (@args > 0) {
$self->{_unrec_cmd_max} = $args[0]; $self->{_unrec_cmd_max} = $args[0];
@ -30,7 +29,7 @@ sub register {
} }
sub check_unrec_cmd { sub hook_unrecognized_command {
my ($self, $cmd) = @_[0,2]; my ($self, $cmd) = @_[0,2];
$self->log(LOGINFO, "Unrecognized command '$cmd'"); $self->log(LOGINFO, "Unrecognized command '$cmd'");

View File

@ -41,14 +41,7 @@ based on the 'whitelist' plugin by Devin Carraway <qpsmtpd@devin.com>.
=cut =cut
sub register { sub hook_connect {
my ($self, $qp) = @_;
$self->register_hook("connect", "connect_handler");
$self->register_hook("rcpt", "rcpt_handler");
}
sub connect_handler {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $remote_ip = $self->qp->connection->remote_ip; my $remote_ip = $self->qp->connection->remote_ip;
@ -145,7 +138,7 @@ sub process_sockets {
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
my $ip = $self->qp->connection->remote_ip || return (DECLINED); my $ip = $self->qp->connection->remote_ip || return (DECLINED);
my $note = $self->process_sockets; my $note = $self->process_sockets;
@ -155,13 +148,4 @@ sub rcpt_handler {
return DECLINED; return DECLINED;
} }
sub disconnect_handler {
my ($self, $transaction) = @_;
$self->qp->connection->notes('whitelist_sockets', undef);
return DECLINED;
}
1; 1;

View File

@ -9,12 +9,9 @@ sub register {
$self->{_dnsbl}->{DENY} = DENY; $self->{_dnsbl}->{DENY} = DENY;
} }
$self->register_hook("connect", "connect_handler");
$self->register_hook("rcpt", "rcpt_handler");
$self->register_hook("disconnect", "disconnect_handler");
} }
sub connect_handler { sub hook_connect {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $remote_ip = $self->qp->connection->remote_ip; my $remote_ip = $self->qp->connection->remote_ip;
@ -151,7 +148,7 @@ sub process_sockets {
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
my $connection = $self->qp->connection; my $connection = $self->qp->connection;
@ -184,7 +181,7 @@ sub rcpt_handler {
} }
sub disconnect_handler { sub hook_disconnect {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
$self->qp->connection->notes('dnsbl_sockets', undef); $self->qp->connection->notes('dnsbl_sockets', undef);

View File

@ -137,7 +137,6 @@ sub register {
} else { } else {
$self->register_hook("rcpt", "rcpt_handler"); $self->register_hook("rcpt", "rcpt_handler");
} }
$self->register_hook("data_post", "data_handler");
} }
sub mail_handler { sub mail_handler {
@ -167,7 +166,7 @@ sub rcpt_handler {
return DECLINED; return DECLINED;
} }
sub data_handler { sub hook_data {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $note = $transaction->notes('denysoft_greylist'); my $note = $transaction->notes('denysoft_greylist');
return DECLINED unless $note; return DECLINED unless $note;

View File

@ -31,10 +31,9 @@ my @urls;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
@urls = @args; @urls = @args;
$self->register_hook("config", "http_config");
} }
sub http_config { sub hook_config {
my ($self, $transaction, $config) = @_; my ($self, $transaction, $config) = @_;
$self->log(LOGNOTICE, "http_config called with $config"); $self->log(LOGNOTICE, "http_config called with $config");
for my $url (@urls) { for my $url (@urls) {

View File

@ -17,13 +17,7 @@ use Geo::IP;
my $geoip = Geo::IP->new(GEOIP_STANDARD); my $geoip = Geo::IP->new(GEOIP_STANDARD);
sub hook_connect {
sub register {
my ($self, $qp) = @_;
$self->register_hook("connect", "lookup_geoip");
}
sub lookup_geoip {
my ($self) = @_; my ($self) = @_;
my $country = my $country =

View File

@ -23,13 +23,12 @@ use Net::IP;
sub register { sub register {
my ($self, $qp, $p0f_socket) = @_; my ($self, $qp, $p0f_socket) = @_;
$self->register_hook("connect", "lookup_p0f");
$p0f_socket =~ /(.*)/; # untaint $p0f_socket =~ /(.*)/; # untaint
$self->{_args}->{p0f_socket} = $1; $self->{_args}->{p0f_socket} = $1;
} }
sub lookup_p0f { sub hook_connect {
my($self, $qp) = @_; my($self, $qp) = @_;
eval { eval {

View File

@ -30,16 +30,12 @@ sub register {
$self->{_prefix} = $1; $self->{_prefix} = $1;
} }
$self->register_hook( 'logging', 'wlog' );
$self->register_hook( 'deny', 'dlog' );
$self->register_hook( 'reset_transaction', 'slog' );
# If you want to capture this log entry with this plugin, you need to # If you want to capture this log entry with this plugin, you need to
# wait until after you register the plugin # wait until after you register the plugin
$self->log( LOGINFO, 'Initializing logging::adaptive plugin' ); $self->log( LOGINFO, 'Initializing logging::adaptive plugin' );
} }
sub wlog { sub hook_logging { # wlog
my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_; my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_;
# Don't log your own log entries! If this is the only logging plugin # Don't log your own log entries! If this is the only logging plugin
@ -66,12 +62,12 @@ sub wlog {
return DECLINED; return DECLINED;
} }
sub dlog { sub hook_deny { # dlog
my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_; my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_;
$self->{_denied} = 1; $self->{_denied} = 1;
} }
sub slog { sub hook_reset_transaction { # slog
# fires when a message is accepted # fires when a message is accepted
my ( $self, $transaction, @args ) = @_; my ( $self, $transaction, @args ) = @_;

View File

@ -1,13 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
# this is a simple 'drop packets on the floor' plugin # this is a simple 'drop packets on the floor' plugin
sub register { sub hook_logging {
my $self = shift;
$self->register_hook('logging', 'wlog');
}
sub wlog {
return DECLINED; return DECLINED;
} }

View File

@ -16,14 +16,13 @@ sub register {
$self->{_level} = log_level($loglevel); $self->{_level} = log_level($loglevel);
} }
} }
$self->register_hook('logging', 'wlog');
# If you want to capture this log entry with this plugin, you need to # If you want to capture this log entry with this plugin, you need to
# wait until after you register the plugin # wait until after you register the plugin
$self->log(LOGINFO,'Initializing logging::warn plugin'); $self->log(LOGINFO,'Initializing logging::warn plugin');
} }
sub wlog { sub hook_logging {
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
# Don't log your own log entries! If this is the only logging plugin # Don't log your own log entries! If this is the only logging plugin

View File

@ -42,15 +42,9 @@ sub register {
$self->{host} = $host; $self->{host} = $host;
$self->{port} = $port; $self->{port} = $port;
$self->register_hook("connect", "connect_handler");
$self->register_hook("helo", "helo_handler");
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
$self->register_hook("data_post", "data_handler");
$self->register_hook("disconnect", "disconnect_handler");
} }
sub disconnect_handler { sub hook_disconnect {
my ($self) = @_; my ($self) = @_;
my $milter = $self->qp->connection->notes('milter') || return DECLINED; my $milter = $self->qp->connection->notes('milter') || return DECLINED;
@ -93,7 +87,7 @@ sub check_results {
} }
} }
sub connect_handler { sub hook_connect {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
$self->log(LOGDEBUG, "milter $self->{name} opening connection to milter backend"); $self->log(LOGDEBUG, "milter $self->{name} opening connection to milter backend");
@ -119,7 +113,7 @@ sub connect_handler {
return DECLINED; return DECLINED;
} }
sub helo_handler { sub hook_helo {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
if (my $txt = $self->qp->connection->notes('spam')) { if (my $txt = $self->qp->connection->notes('spam')) {
@ -140,7 +134,7 @@ sub helo_handler {
return DECLINED; return DECLINED;
} }
sub mail_handler { sub hook_mail {
my ($self, $transaction, $address) = @_; my ($self, $transaction, $address) = @_;
my $milter = $self->qp->connection->notes('milter'); my $milter = $self->qp->connection->notes('milter');
@ -153,7 +147,7 @@ sub mail_handler {
return DECLINED; return DECLINED;
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $address) = @_; my ($self, $transaction, $address) = @_;
my $milter = $self->qp->connection->notes('milter'); my $milter = $self->qp->connection->notes('milter');
@ -167,7 +161,7 @@ sub rcpt_handler {
return DECLINED; return DECLINED;
} }
sub data_handler { sub hook_data {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $milter = $self->qp->connection->notes('milter'); my $milter = $self->qp->connection->notes('milter');

View File

@ -35,13 +35,11 @@ sub register {
my $hostname = (hostname =~ m/([\w\._\-]+)/)[0]; my $hostname = (hostname =~ m/([\w\._\-]+)/)[0];
$self->{_hostname} = $hostname; $self->{_hostname} = $hostname;
$self->register_hook("queue", "queue_handler");
} }
my $maildir_counter = 0; my $maildir_counter = 0;
sub queue_handler { sub hook_queue {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my ($time, $microseconds) = gettimeofday; my ($time, $microseconds) = gettimeofday;

View File

@ -18,7 +18,6 @@ use Qpsmtpd::Postfix;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("queue", "queue_handler");
if (@args > 0) { if (@args > 0) {
$self->{_queue_socket} = $args[0]; $self->{_queue_socket} = $args[0];
@ -31,7 +30,7 @@ sub register {
} }
sub queue_handler { sub hook_queue {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my ($status, $qid, $reason) = Qpsmtpd::Postfix->inject_mail($transaction); my ($status, $qid, $reason) = Qpsmtpd::Postfix->inject_mail($transaction);

View File

@ -23,7 +23,6 @@ use POSIX ();
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("queue", "queue_handler");
if (@args > 0) { if (@args > 0) {
$self->{_queue_exec} = $args[0]; $self->{_queue_exec} = $args[0];
@ -36,7 +35,7 @@ sub register {
$self->{_queue_exec} = $ENV{QMAILQUEUE} if $ENV{QMAILQUEUE}; $self->{_queue_exec} = $ENV{QMAILQUEUE} if $ENV{QMAILQUEUE};
} }
sub queue_handler { sub hook_queue {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
# these bits inspired by Peter Samuels "qmail-queue wrapper" # these bits inspired by Peter Samuels "qmail-queue wrapper"

View File

@ -23,7 +23,6 @@ use Net::SMTP;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("queue", "queue_handler");
if (@args > 0) { if (@args > 0) {
if ($args[0] =~ /^([\.\w_-]+)$/) { if ($args[0] =~ /^([\.\w_-]+)$/) {
@ -43,7 +42,7 @@ sub register {
} }
sub queue_handler { sub hook_queue {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
$self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}"); $self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}");

View File

@ -1,9 +1,5 @@
sub register { sub hook_quit {
shift->register_hook("quit", "quit_handler");
}
sub quit_handler {
my $qp = shift->qp; my $qp = shift->qp;
# if she talks EHLO she is probably too sophisticated to enjoy the # if she talks EHLO she is probably too sophisticated to enjoy the

View File

@ -3,12 +3,7 @@
# It should be configured to be run _LAST_! # It should be configured to be run _LAST_!
# #
sub register { sub hook_rcpt {
my ($self, $qp) = @_;
$self->register_hook("rcpt", "rcpt_ok");
}
sub rcpt_ok {
my ($self, $transaction, $recipient) = @_; my ($self, $transaction, $recipient) = @_;
my $host = lc $recipient->host; my $host = lc $recipient->host;

View File

@ -1,11 +1,6 @@
use Net::DNS qw(mx); use Net::DNS qw(mx);
sub register { sub hook_mail {
my ($self, $qp) = @_;
$self->register_hook("mail", "mail_handler");
}
sub mail_handler {
my ($self, $transaction, $sender) = @_; my ($self, $transaction, $sender) = @_;
return DECLINED return DECLINED

View File

@ -1,12 +1,5 @@
sub register {
my ($self, $qp) = @_;
$self->register_hook('mail', 'mail_handler'); sub hook_mail {
$self->register_hook('rcpt', 'rcpt_handler');
$self->register_hook('disconnect', 'disconnect_handler');
}
sub mail_handler {
my ($self, $transaction, $sender) = @_; my ($self, $transaction, $sender) = @_;
my $res = new Net::DNS::Resolver; my $res = new Net::DNS::Resolver;
@ -40,7 +33,7 @@ sub mail_handler {
return DECLINED; return DECLINED;
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
my $host = $transaction->sender->host; my $host = $transaction->sender->host;
my $hello = $self->qp->connection->hello_host; my $hello = $self->qp->connection->hello_host;
@ -111,7 +104,7 @@ sub process_sockets {
return $trans->notes('rhsbl', $result); return $trans->notes('rhsbl', $result);
} }
sub disconnect_handler { sub hook_disconnect {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
$transaction->notes('rhsbl_sockets', undef); $transaction->notes('rhsbl_sockets', undef);

View File

@ -31,12 +31,9 @@ use Mail::SPF::Query 1.991;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
%{$self->{_args}} = @args; %{$self->{_args}} = @args;
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
$self->register_hook("data_post", "data_handler");
} }
sub mail_handler { sub hook_mail {
my ($self, $transaction, $sender) = @_; my ($self, $transaction, $sender) = @_;
return (DECLINED) unless ($sender->format ne "<>" return (DECLINED) unless ($sender->format ne "<>"
@ -73,7 +70,7 @@ sub mail_handler {
return (DECLINED); return (DECLINED);
} }
sub rcpt_handler { sub hook_rcpt {
my ($self, $transaction, $rcpt) = @_; my ($self, $transaction, $rcpt) = @_;
# special addresses don't get SPF-tested. # special addresses don't get SPF-tested.
@ -109,7 +106,7 @@ sub _uri_escape {
return $str; return $str;
} }
sub data_handler { sub hook_data {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $query = $transaction->notes('spfquery'); my $query = $transaction->notes('spfquery');

View File

@ -76,7 +76,6 @@ use IO::Handle;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "check_spam");
$self->log(LOGERROR, "Bad parameters for the spamassassin plugin") $self->log(LOGERROR, "Bad parameters for the spamassassin plugin")
if @_ % 2; if @_ % 2;
@ -91,7 +90,7 @@ sub register {
} }
sub check_spam { sub hook_data_post { # check_spam
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
$self->log(LOGDEBUG, "check_spam"); $self->log(LOGDEBUG, "check_spam");

View File

@ -96,9 +96,6 @@ use Mail::Address;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
# where to be called
$self->register_hook("data_post", "avscan");
# defaults to be used # defaults to be used
$self->{_avclient_bin} = "/opt/kav/bin/aveclient"; $self->{_avclient_bin} = "/opt/kav/bin/aveclient";
$self->{_avdaemon_sock} = "/var/run/aveserver"; $self->{_avdaemon_sock} = "/var/run/aveserver";
@ -122,7 +119,7 @@ sub register {
} }
} }
sub avscan { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my ($temp_fh, $filename) = tempfile(); my ($temp_fh, $filename) = tempfile();
my $description = 'clean'; my $description = 'clean';

View File

@ -67,7 +67,6 @@ use warnings;
sub register { sub register {
my ( $self, $qp, @args ) = @_; my ( $self, $qp, @args ) = @_;
$self->register_hook( "data_post", "bdc_scan" );
while (@args) { while (@args) {
$self->{"_bitd"}->{ pop @args } = pop @args; $self->{"_bitd"}->{ pop @args } = pop @args;
@ -78,7 +77,7 @@ sub register {
$self->{"_bitd"}->{"max_size"} *= 1024; $self->{"_bitd"}->{"max_size"} *= 1024;
} }
sub bdc_scan { sub hook_data_post {
my ( $self, $transaction ) = @_; my ( $self, $transaction ) = @_;
if ( $transaction->body_size > $self->{"_bitd"}->{"max_size"} ) { if ( $transaction->body_size > $self->{"_bitd"}->{"max_size"} ) {

View File

@ -1,11 +1,6 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
sub register { sub hook_data_post {
my $self = shift;
$self->register_hook('data_post', 'check_for_hi_virus');
}
sub check_for_hi_virus {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
# make sure we read from the beginning; # make sure we read from the beginning;

View File

@ -148,11 +148,9 @@ sub register {
return undef; return undef;
} }
$self->register_hook("data_post", "clam_scan");
1;
} }
sub clam_scan { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
if ($transaction->body_size > $self->{_max_size}) { if ($transaction->body_size > $self->{_max_size}) {

View File

@ -94,7 +94,6 @@ use Clamd;
sub register { sub register {
my ( $self, $qp, @args ) = @_; my ( $self, $qp, @args ) = @_;
$self->register_hook( "data_post", "clamdscan" );
%{ $self->{"_clamd"} } = @args; %{ $self->{"_clamd"} } = @args;
@ -104,7 +103,7 @@ sub register {
$self->{"_clamd"}->{"max_size"} ||= 128; $self->{"_clamd"}->{"max_size"} ||= 128;
} }
sub clamdscan { sub hook_data_post {
my ( $self, $transaction ) = @_; my ( $self, $transaction ) = @_;
$DB::single = 1; $DB::single = 1;

View File

@ -53,7 +53,6 @@ The B<hbedv> plugin is published under the same licence as qpsmtpd itself.
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "hbedv_scan");
if (@args % 2) { if (@args % 2) {
$self->log(LOGERROR, "FATAL ERROR: odd number of arguments"); $self->log(LOGERROR, "FATAL ERROR: odd number of arguments");
@ -72,7 +71,7 @@ sub register {
} }
} }
sub hbedv_scan { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my $filename = $transaction->body_filename; my $filename = $transaction->body_filename;

View File

@ -57,7 +57,6 @@ use Mail::Address;
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "kav_scan");
if (@args % 2) { if (@args % 2) {
$self->log(LOGWARN, "kavscanner: Wrong number of arguments"); $self->log(LOGWARN, "kavscanner: Wrong number of arguments");
@ -80,7 +79,7 @@ sub register {
} }
} }
sub kav_scan { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
my ($temp_fh, $filename) = tempfile(); my ($temp_fh, $filename) = tempfile();

View File

@ -1,9 +1,5 @@
sub register {
my ($self, $qp) = @_;
$self->register_hook("data_post", "check_klez");
}
sub check_klez { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
# klez files are always sorta big .. how big? Dunno. # klez files are always sorta big .. how big? Dunno.

View File

@ -3,7 +3,6 @@ use IO::Socket;
sub register { sub register {
my ( $self, $qp, @args ) = @_; my ( $self, $qp, @args ) = @_;
$self->register_hook( "data_post", "sophiescan" );
%{ $self->{"_sophie"} } = @args; %{ $self->{"_sophie"} } = @args;
@ -13,7 +12,7 @@ sub register {
$self->{"_sophie"}->{"max_size"} ||= 128; $self->{"_sophie"}->{"max_size"} ||= 128;
} }
sub sophiescan { sub hook_data_post {
my ( $self, $transaction ) = @_; my ( $self, $transaction ) = @_;
$DB::single = 1; $DB::single = 1;

View File

@ -44,7 +44,6 @@ Please see the LICENSE file included with qpsmtpd for details.
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("data_post", "uvscan");
while (@args) { while (@args) {
$self->{"_uvscan"}->{pop @args}=pop @args; $self->{"_uvscan"}->{pop @args}=pop @args;
@ -52,7 +51,7 @@ sub register {
$self->{"_uvscan"}->{"uvscan_location"}||="/usr/local/bin/uvscan"; $self->{"_uvscan"}->{"uvscan_location"}||="/usr/local/bin/uvscan";
} }
sub uvscan { sub hook_data_post {
my ($self, $transaction) = @_; my ($self, $transaction) = @_;
return (DECLINED) return (DECLINED)