From 90daeb3786d9bb16ec5aec88378b070b4a0e3a1e Mon Sep 17 00:00:00 2001 From: Robert Spier Date: Thu, 7 Jul 2005 04:17:39 +0000 Subject: [PATCH] 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 --- README.plugins | 79 +++++++++++++++++++++++++++++ lib/Qpsmtpd/Plugin.pm | 34 ++++++++++--- plugins/auth/authdeny | 7 +-- plugins/auth/authnull | 12 +---- plugins/check_badmailfrom | 10 +--- plugins/check_badmailfromto | 10 +--- plugins/check_badrcptto | 7 +-- plugins/check_badrcptto_patterns | 8 +-- plugins/check_basicheaders | 3 +- plugins/check_loop | 3 +- plugins/check_norelay | 7 +-- plugins/check_relay | 7 +-- plugins/check_spamhelo | 10 ++-- plugins/content_log | 7 +-- plugins/count_unrecognized_commands | 3 +- plugins/dns_whitelist_soft | 20 +------- plugins/dnsbl | 11 ++-- plugins/greylisting | 3 +- plugins/http_config | 3 +- plugins/ident/geoip | 8 +-- plugins/ident/p0f | 3 +- plugins/logging/adaptive | 10 ++-- plugins/logging/devnull | 8 +-- plugins/logging/warn | 3 +- plugins/milter | 18 +++---- plugins/queue/maildir | 4 +- plugins/queue/postfix-queue | 3 +- plugins/queue/qmail-queue | 3 +- plugins/queue/smtp-forward | 3 +- plugins/quit_fortune | 6 +-- plugins/rcpt_ok | 7 +-- plugins/require_resolvable_fromhost | 7 +-- plugins/rhsbl | 13 ++--- plugins/sender_permitted_from | 9 ++-- plugins/spamassassin | 3 +- plugins/virus/aveclient | 5 +- plugins/virus/bitdefender | 3 +- plugins/virus/check_for_hi_virus | 7 +-- plugins/virus/clamav | 4 +- plugins/virus/clamdscan | 3 +- plugins/virus/hbedv | 3 +- plugins/virus/kavscanner | 3 +- plugins/virus/klez_filter | 6 +-- plugins/virus/sophie | 3 +- plugins/virus/uvscan | 3 +- 45 files changed, 169 insertions(+), 223 deletions(-) diff --git a/README.plugins b/README.plugins index edea77b..57b7f88 100644 --- a/README.plugins +++ b/README.plugins @@ -270,3 +270,82 @@ ended. Returns the configured system-wide spool directory. =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 ); + } + + + diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 4e227c3..d3200ff 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -1,4 +1,5 @@ package Qpsmtpd::Plugin; +use Qpsmtpd::Constants; use strict; our %hooks = map { $_ => 1 } qw( @@ -16,9 +17,11 @@ sub new { sub register_hook { my ($plugin, $hook, $method, $unshift) = @_; - + 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 # 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(@_) }, @@ -32,7 +35,9 @@ sub _register { my $self = shift; my $qp = shift; 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 { @@ -74,7 +79,7 @@ sub temp_dir { # plugin inheritance: # usage: -# sub register { +# sub init { # my $self = shift; # $self->isa_plugin("rhsbl"); # $self->SUPER::register(@_); @@ -82,18 +87,23 @@ sub temp_dir { sub isa_plugin { my ($self, $parent) = @_; my ($currentPackage) = caller; - my $newPackage = $currentPackage."::_isa_"; + + my $cleanParent = $parent; + $cleanParent =~ s/\W/_/g; + my $newPackage = $currentPackage."::_isa_$cleanParent"; + return if defined &{"${newPackage}::register"}; - Qpsmtpd::_compile($self->plugin_name . "_isa", + $self->compile($self->plugin_name . "_isa_$cleanParent", $newPackage, "plugins/$parent"); # assumes Cwd is qpsmtpd root - + warn "---- $newPackage\n"; no strict 'refs'; push @{"${currentPackage}::ISA"}, $newPackage; } +# why isn't compile private? it's only called from Plugin and Qpsmtpd. sub compile { my ($class, $plugin, $package, $file, $test_mode) = @_; @@ -141,4 +151,16 @@ sub compile { 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; diff --git a/plugins/auth/authdeny b/plugins/auth/authdeny index 3b1abb6..892398b 100644 --- a/plugins/auth/authdeny +++ b/plugins/auth/authdeny @@ -5,12 +5,7 @@ # the Qpsmtpd::Auth module. Don't run this in production!!! # -sub register { - my ( $self, $qp ) = @_; - $self->register_hook( "auth", "authdeny" ); -} - -sub authdeny { +sub hook_auth { my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) = @_; diff --git a/plugins/auth/authnull b/plugins/auth/authnull index 58bcf8e..1eefb9b 100644 --- a/plugins/auth/authnull +++ b/plugins/auth/authnull @@ -5,17 +5,7 @@ # the Qpsmtpd::Auth module. Don't run this in production!!! # -sub register { - 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 { +sub hook_auth { my ( $self, $transaction, $method, $user, $passClear, $passHash, $ticket ) = @_; diff --git a/plugins/check_badmailfrom b/plugins/check_badmailfrom index 3c3c39a..46a2542 100644 --- a/plugins/check_badmailfrom +++ b/plugins/check_badmailfrom @@ -20,13 +20,7 @@ stage, so store it until later. =cut -sub register { - my ($self, $qp) = @_; - $self->register_hook("mail", "mail_handler"); - $self->register_hook("rcpt", "rcpt_handler"); -} - -sub mail_handler { +sub hook_mail { my ($self, $transaction, $sender) = @_; my @badmailfrom = $self->qp->config("badmailfrom") @@ -49,7 +43,7 @@ sub mail_handler { return (DECLINED); } -sub rcpt_handler { +sub hook_rcpt { my ($self, $transaction, $rcpt) = @_; my $note = $transaction->notes('badmailfrom'); if ($note) { diff --git a/plugins/check_badmailfromto b/plugins/check_badmailfromto index 4b9392a..92c5054 100644 --- a/plugins/check_badmailfromto +++ b/plugins/check_badmailfromto @@ -16,13 +16,7 @@ Based heavily on check_badmailfrom. =cut -sub register { - my ($self, $qp) = @_; - $self->register_hook("mail", "mail_handler"); - $self->register_hook("rcpt", "rcpt_handler"); -} - -sub mail_handler { +sub hook_mail { my ($self, $transaction, $sender) = @_; my @badmailfromto = $self->qp->config("badmailfromto") @@ -46,7 +40,7 @@ sub mail_handler { return (DECLINED); } -sub rcpt_handler { +sub hook_rcpt { my ($self, $transaction, $rcpt) = @_; my $recipient = lc($rcpt->user) . '@' . lc($rcpt->host); my $sender = $transaction->notes('badmailfromto'); diff --git a/plugins/check_badrcptto b/plugins/check_badrcptto index eb9e7c3..fb57e9e 100644 --- a/plugins/check_badrcptto +++ b/plugins/check_badrcptto @@ -1,11 +1,6 @@ # this plugin checks the badrcptto config (like badmailfrom for rcpt address) -sub register { - my ($self, $qp) = @_; - $self->register_hook("rcpt", "check_for_badrcptto"); -} - -sub check_for_badrcptto { +sub hook_rcpt { my ($self, $transaction, $recipient) = @_; my @badrcptto = $self->qp->config("badrcptto") or return (DECLINED); return (DECLINED) unless $recipient->host && $recipient->user; diff --git a/plugins/check_badrcptto_patterns b/plugins/check_badrcptto_patterns index 95a480b..7b82945 100644 --- a/plugins/check_badrcptto_patterns +++ b/plugins/check_badrcptto_patterns @@ -26,13 +26,7 @@ terms as Perl itself. =cut -sub register -{ - my ($self, $qp) = @_; - $self->register_hook("rcpt", "check_for_badrcptto_patterns"); -} - -sub check_for_badrcptto_patterns +sub hook_rcpt { my ($self, $transaction, $recipient) = @_; diff --git a/plugins/check_basicheaders b/plugins/check_basicheaders index 8abdc69..5efa438 100644 --- a/plugins/check_basicheaders +++ b/plugins/check_basicheaders @@ -33,7 +33,6 @@ use Date::Parse qw(str2time); sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "check_basic_headers"); if (@args > 0) { $self->{_days} = $args[0]; @@ -41,7 +40,7 @@ sub register { } } -sub check_basic_headers { +sub hook_data_post { my ($self, $transaction) = @_; return (DENY, "You have to send some data first") diff --git a/plugins/check_loop b/plugins/check_loop index b608a9e..ff64ee8 100644 --- a/plugins/check_loop +++ b/plugins/check_loop @@ -28,7 +28,6 @@ Released to the public domain, 17 June 2005. sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "check_loop"); $self->{_max_hops} = $args[0] || 100; @@ -38,7 +37,7 @@ sub register { $self->log(LOGWARN, "Ignoring additional arguments") if @args > 1; } -sub check_loop { +sub hook_data_post { my ($self, $transaction) = @_; my $hops = 0; diff --git a/plugins/check_norelay b/plugins/check_norelay index f5b40b0..8c99aa2 100644 --- a/plugins/check_norelay +++ b/plugins/check_norelay @@ -34,12 +34,7 @@ terms as Perl itself. =cut -sub register { - my ($self, $qp) = @_; - $self->register_hook("connect", "check_norelay"); -} - -sub check_norelay { +sub hook_connect { my ($self, $transaction) = @_; my $connection = $self->qp->connection; diff --git a/plugins/check_relay b/plugins/check_relay index 9f96812..a79da91 100644 --- a/plugins/check_relay +++ b/plugins/check_relay @@ -2,12 +2,7 @@ # $ENV{RELAYCLIENT} to see if relaying is allowed. # -sub register { - my ($self, $qp) = @_; - $self->register_hook("connect", "check_relay"); -} - -sub check_relay { +sub hook_connect { my ($self, $transaction) = @_; my $connection = $self->qp->connection; diff --git a/plugins/check_spamhelo b/plugins/check_spamhelo index 9c81e8e..2461460 100644 --- a/plugins/check_spamhelo +++ b/plugins/check_spamhelo @@ -16,13 +16,7 @@ per line. =cut -sub register { - my ($self, $qp) = @_; - $self->register_hook("helo", "check_helo"); - $self->register_hook("ehlo", "check_helo"); -} - -sub check_helo { +sub hook_helo { my ($self, $transaction, $host) = @_; ($host = lc $host) or return DECLINED; @@ -35,3 +29,5 @@ sub check_helo { return DECLINED; } +# also support EHLO +*hook_ehlo = \&hook_helo; diff --git a/plugins/content_log b/plugins/content_log index 0198105..5bd3715 100644 --- a/plugins/content_log +++ b/plugins/content_log @@ -6,12 +6,7 @@ use POSIX qw:strftime:; -sub register { - my ($self, $qp) = @_; - $self->register_hook("data_post", "mail_handler"); -} - -sub mail_handler { +sub hook_data_post { my ($self, $transaction) = @_; # as a decent default, log on a per-day-basis diff --git a/plugins/count_unrecognized_commands b/plugins/count_unrecognized_commands index f65468a..d369307 100644 --- a/plugins/count_unrecognized_commands +++ b/plugins/count_unrecognized_commands @@ -17,7 +17,6 @@ before we disconnect the client. Defaults to 4. sub register { my ($self, $qp, @args) = @_; - $self->register_hook("unrecognized_command", "check_unrec_cmd"); if (@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]; $self->log(LOGINFO, "Unrecognized command '$cmd'"); diff --git a/plugins/dns_whitelist_soft b/plugins/dns_whitelist_soft index 5eb6b83..0def06a 100644 --- a/plugins/dns_whitelist_soft +++ b/plugins/dns_whitelist_soft @@ -41,14 +41,7 @@ based on the 'whitelist' plugin by Devin Carraway . =cut -sub register { - my ($self, $qp) = @_; - - $self->register_hook("connect", "connect_handler"); - $self->register_hook("rcpt", "rcpt_handler"); -} - -sub connect_handler { +sub hook_connect { my ($self, $transaction) = @_; 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 $ip = $self->qp->connection->remote_ip || return (DECLINED); my $note = $self->process_sockets; @@ -155,13 +148,4 @@ sub rcpt_handler { return DECLINED; } -sub disconnect_handler { - my ($self, $transaction) = @_; - - $self->qp->connection->notes('whitelist_sockets', undef); - - return DECLINED; -} - - 1; diff --git a/plugins/dnsbl b/plugins/dnsbl index 666090d..7bed581 100644 --- a/plugins/dnsbl +++ b/plugins/dnsbl @@ -8,13 +8,10 @@ sub register { else { $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 $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 $connection = $self->qp->connection; @@ -184,7 +181,7 @@ sub rcpt_handler { } -sub disconnect_handler { +sub hook_disconnect { my ($self, $transaction) = @_; $self->qp->connection->notes('dnsbl_sockets', undef); diff --git a/plugins/greylisting b/plugins/greylisting index d346a74..2c9c412 100644 --- a/plugins/greylisting +++ b/plugins/greylisting @@ -137,7 +137,6 @@ sub register { } else { $self->register_hook("rcpt", "rcpt_handler"); } - $self->register_hook("data_post", "data_handler"); } sub mail_handler { @@ -167,7 +166,7 @@ sub rcpt_handler { return DECLINED; } -sub data_handler { +sub hook_data { my ($self, $transaction) = @_; my $note = $transaction->notes('denysoft_greylist'); return DECLINED unless $note; diff --git a/plugins/http_config b/plugins/http_config index a90cbd2..4a2b435 100644 --- a/plugins/http_config +++ b/plugins/http_config @@ -31,10 +31,9 @@ my @urls; sub register { my ($self, $qp, @args) = @_; @urls = @args; - $self->register_hook("config", "http_config"); } -sub http_config { +sub hook_config { my ($self, $transaction, $config) = @_; $self->log(LOGNOTICE, "http_config called with $config"); for my $url (@urls) { diff --git a/plugins/ident/geoip b/plugins/ident/geoip index 692d089..60ab8d0 100644 --- a/plugins/ident/geoip +++ b/plugins/ident/geoip @@ -17,13 +17,7 @@ use Geo::IP; my $geoip = Geo::IP->new(GEOIP_STANDARD); - -sub register { - my ($self, $qp) = @_; - $self->register_hook("connect", "lookup_geoip"); -} - -sub lookup_geoip { +sub hook_connect { my ($self) = @_; my $country = diff --git a/plugins/ident/p0f b/plugins/ident/p0f index efedffc..d219bb2 100644 --- a/plugins/ident/p0f +++ b/plugins/ident/p0f @@ -23,13 +23,12 @@ use Net::IP; sub register { my ($self, $qp, $p0f_socket) = @_; - $self->register_hook("connect", "lookup_p0f"); $p0f_socket =~ /(.*)/; # untaint $self->{_args}->{p0f_socket} = $1; } -sub lookup_p0f { +sub hook_connect { my($self, $qp) = @_; eval { diff --git a/plugins/logging/adaptive b/plugins/logging/adaptive index 2964d90..4e57801 100644 --- a/plugins/logging/adaptive +++ b/plugins/logging/adaptive @@ -30,16 +30,12 @@ sub register { $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 # wait until after you register the plugin $self->log( LOGINFO, 'Initializing logging::adaptive plugin' ); } -sub wlog { +sub hook_logging { # wlog my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_; # Don't log your own log entries! If this is the only logging plugin @@ -66,12 +62,12 @@ sub wlog { return DECLINED; } -sub dlog { +sub hook_deny { # dlog my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_; $self->{_denied} = 1; } -sub slog { +sub hook_reset_transaction { # slog # fires when a message is accepted my ( $self, $transaction, @args ) = @_; diff --git a/plugins/logging/devnull b/plugins/logging/devnull index 33d524e..566ab68 100644 --- a/plugins/logging/devnull +++ b/plugins/logging/devnull @@ -1,13 +1,7 @@ #!/usr/bin/perl # this is a simple 'drop packets on the floor' plugin -sub register { - my $self = shift; - - $self->register_hook('logging', 'wlog'); -} - -sub wlog { +sub hook_logging { return DECLINED; } diff --git a/plugins/logging/warn b/plugins/logging/warn index 4c79ddd..ce25399 100644 --- a/plugins/logging/warn +++ b/plugins/logging/warn @@ -16,14 +16,13 @@ sub register { $self->{_level} = log_level($loglevel); } } - $self->register_hook('logging', 'wlog'); # If you want to capture this log entry with this plugin, you need to # wait until after you register the plugin $self->log(LOGINFO,'Initializing logging::warn plugin'); } -sub wlog { +sub hook_logging { my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; # Don't log your own log entries! If this is the only logging plugin diff --git a/plugins/milter b/plugins/milter index 3997c0b..a577683 100644 --- a/plugins/milter +++ b/plugins/milter @@ -42,15 +42,9 @@ sub register { $self->{host} = $host; $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 $milter = $self->qp->connection->notes('milter') || return DECLINED; @@ -93,7 +87,7 @@ sub check_results { } } -sub connect_handler { +sub hook_connect { my ($self, $transaction) = @_; $self->log(LOGDEBUG, "milter $self->{name} opening connection to milter backend"); @@ -119,7 +113,7 @@ sub connect_handler { return DECLINED; } -sub helo_handler { +sub hook_helo { my ($self, $transaction) = @_; if (my $txt = $self->qp->connection->notes('spam')) { @@ -140,7 +134,7 @@ sub helo_handler { return DECLINED; } -sub mail_handler { +sub hook_mail { my ($self, $transaction, $address) = @_; my $milter = $self->qp->connection->notes('milter'); @@ -153,7 +147,7 @@ sub mail_handler { return DECLINED; } -sub rcpt_handler { +sub hook_rcpt { my ($self, $transaction, $address) = @_; my $milter = $self->qp->connection->notes('milter'); @@ -167,7 +161,7 @@ sub rcpt_handler { return DECLINED; } -sub data_handler { +sub hook_data { my ($self, $transaction) = @_; my $milter = $self->qp->connection->notes('milter'); diff --git a/plugins/queue/maildir b/plugins/queue/maildir index b87886e..120199d 100644 --- a/plugins/queue/maildir +++ b/plugins/queue/maildir @@ -35,13 +35,11 @@ sub register { my $hostname = (hostname =~ m/([\w\._\-]+)/)[0]; $self->{_hostname} = $hostname; - $self->register_hook("queue", "queue_handler"); - } my $maildir_counter = 0; -sub queue_handler { +sub hook_queue { my ($self, $transaction) = @_; my ($time, $microseconds) = gettimeofday; diff --git a/plugins/queue/postfix-queue b/plugins/queue/postfix-queue index 6d563ed..db7259e 100644 --- a/plugins/queue/postfix-queue +++ b/plugins/queue/postfix-queue @@ -18,7 +18,6 @@ use Qpsmtpd::Postfix; sub register { my ($self, $qp, @args) = @_; - $self->register_hook("queue", "queue_handler"); if (@args > 0) { $self->{_queue_socket} = $args[0]; @@ -31,7 +30,7 @@ sub register { } -sub queue_handler { +sub hook_queue { my ($self, $transaction) = @_; my ($status, $qid, $reason) = Qpsmtpd::Postfix->inject_mail($transaction); diff --git a/plugins/queue/qmail-queue b/plugins/queue/qmail-queue index 2b391f6..6bc4a9d 100644 --- a/plugins/queue/qmail-queue +++ b/plugins/queue/qmail-queue @@ -23,7 +23,6 @@ use POSIX (); sub register { my ($self, $qp, @args) = @_; - $self->register_hook("queue", "queue_handler"); if (@args > 0) { $self->{_queue_exec} = $args[0]; @@ -36,7 +35,7 @@ sub register { $self->{_queue_exec} = $ENV{QMAILQUEUE} if $ENV{QMAILQUEUE}; } -sub queue_handler { +sub hook_queue { my ($self, $transaction) = @_; # these bits inspired by Peter Samuels "qmail-queue wrapper" diff --git a/plugins/queue/smtp-forward b/plugins/queue/smtp-forward index eb196d8..1d56a6f 100644 --- a/plugins/queue/smtp-forward +++ b/plugins/queue/smtp-forward @@ -23,7 +23,6 @@ use Net::SMTP; sub register { my ($self, $qp, @args) = @_; - $self->register_hook("queue", "queue_handler"); if (@args > 0) { if ($args[0] =~ /^([\.\w_-]+)$/) { @@ -43,7 +42,7 @@ sub register { } -sub queue_handler { +sub hook_queue { my ($self, $transaction) = @_; $self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}"); diff --git a/plugins/quit_fortune b/plugins/quit_fortune index 43bfaa1..ffcd895 100644 --- a/plugins/quit_fortune +++ b/plugins/quit_fortune @@ -1,9 +1,5 @@ -sub register { - shift->register_hook("quit", "quit_handler"); -} - -sub quit_handler { +sub hook_quit { my $qp = shift->qp; # if she talks EHLO she is probably too sophisticated to enjoy the diff --git a/plugins/rcpt_ok b/plugins/rcpt_ok index a8c51cc..aa547e7 100644 --- a/plugins/rcpt_ok +++ b/plugins/rcpt_ok @@ -3,12 +3,7 @@ # It should be configured to be run _LAST_! # -sub register { - my ($self, $qp) = @_; - $self->register_hook("rcpt", "rcpt_ok"); -} - -sub rcpt_ok { +sub hook_rcpt { my ($self, $transaction, $recipient) = @_; my $host = lc $recipient->host; diff --git a/plugins/require_resolvable_fromhost b/plugins/require_resolvable_fromhost index c469533..1ce0f17 100644 --- a/plugins/require_resolvable_fromhost +++ b/plugins/require_resolvable_fromhost @@ -1,11 +1,6 @@ use Net::DNS qw(mx); -sub register { - my ($self, $qp) = @_; - $self->register_hook("mail", "mail_handler"); -} - -sub mail_handler { +sub hook_mail { my ($self, $transaction, $sender) = @_; return DECLINED diff --git a/plugins/rhsbl b/plugins/rhsbl index 759f9f0..4003630 100644 --- a/plugins/rhsbl +++ b/plugins/rhsbl @@ -1,12 +1,5 @@ -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 hook_mail { my ($self, $transaction, $sender) = @_; my $res = new Net::DNS::Resolver; @@ -40,7 +33,7 @@ sub mail_handler { return DECLINED; } -sub rcpt_handler { +sub hook_rcpt { my ($self, $transaction, $rcpt) = @_; my $host = $transaction->sender->host; my $hello = $self->qp->connection->hello_host; @@ -111,7 +104,7 @@ sub process_sockets { return $trans->notes('rhsbl', $result); } -sub disconnect_handler { +sub hook_disconnect { my ($self, $transaction) = @_; $transaction->notes('rhsbl_sockets', undef); diff --git a/plugins/sender_permitted_from b/plugins/sender_permitted_from index 4d7b989..4297e6c 100644 --- a/plugins/sender_permitted_from +++ b/plugins/sender_permitted_from @@ -31,12 +31,9 @@ use Mail::SPF::Query 1.991; sub register { my ($self, $qp, @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) = @_; return (DECLINED) unless ($sender->format ne "<>" @@ -73,7 +70,7 @@ sub mail_handler { return (DECLINED); } -sub rcpt_handler { +sub hook_rcpt { my ($self, $transaction, $rcpt) = @_; # special addresses don't get SPF-tested. @@ -109,7 +106,7 @@ sub _uri_escape { return $str; } -sub data_handler { +sub hook_data { my ($self, $transaction) = @_; my $query = $transaction->notes('spfquery'); diff --git a/plugins/spamassassin b/plugins/spamassassin index 035cadd..96360c4 100644 --- a/plugins/spamassassin +++ b/plugins/spamassassin @@ -76,7 +76,6 @@ use IO::Handle; sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "check_spam"); $self->log(LOGERROR, "Bad parameters for the spamassassin plugin") if @_ % 2; @@ -91,7 +90,7 @@ sub register { } -sub check_spam { +sub hook_data_post { # check_spam my ($self, $transaction) = @_; $self->log(LOGDEBUG, "check_spam"); diff --git a/plugins/virus/aveclient b/plugins/virus/aveclient index 00609ed..9a02966 100644 --- a/plugins/virus/aveclient +++ b/plugins/virus/aveclient @@ -96,9 +96,6 @@ use Mail::Address; sub register { my ($self, $qp, @args) = @_; - # where to be called - $self->register_hook("data_post", "avscan"); - # defaults to be used $self->{_avclient_bin} = "/opt/kav/bin/aveclient"; $self->{_avdaemon_sock} = "/var/run/aveserver"; @@ -122,7 +119,7 @@ sub register { } } -sub avscan { +sub hook_data_post { my ($self, $transaction) = @_; my ($temp_fh, $filename) = tempfile(); my $description = 'clean'; diff --git a/plugins/virus/bitdefender b/plugins/virus/bitdefender index 1e96152..b29d50c 100644 --- a/plugins/virus/bitdefender +++ b/plugins/virus/bitdefender @@ -67,7 +67,6 @@ use warnings; sub register { my ( $self, $qp, @args ) = @_; - $self->register_hook( "data_post", "bdc_scan" ); while (@args) { $self->{"_bitd"}->{ pop @args } = pop @args; @@ -78,7 +77,7 @@ sub register { $self->{"_bitd"}->{"max_size"} *= 1024; } -sub bdc_scan { +sub hook_data_post { my ( $self, $transaction ) = @_; if ( $transaction->body_size > $self->{"_bitd"}->{"max_size"} ) { diff --git a/plugins/virus/check_for_hi_virus b/plugins/virus/check_for_hi_virus index bc9601f..5844e7d 100644 --- a/plugins/virus/check_for_hi_virus +++ b/plugins/virus/check_for_hi_virus @@ -1,11 +1,6 @@ #!/usr/bin/perl -w -sub register { - my $self = shift; - $self->register_hook('data_post', 'check_for_hi_virus'); -} - -sub check_for_hi_virus { +sub hook_data_post { my ($self, $transaction) = @_; # make sure we read from the beginning; diff --git a/plugins/virus/clamav b/plugins/virus/clamav index 8b29707..85a928a 100644 --- a/plugins/virus/clamav +++ b/plugins/virus/clamav @@ -148,11 +148,9 @@ sub register { return undef; } - $self->register_hook("data_post", "clam_scan"); - 1; } -sub clam_scan { +sub hook_data_post { my ($self, $transaction) = @_; if ($transaction->body_size > $self->{_max_size}) { diff --git a/plugins/virus/clamdscan b/plugins/virus/clamdscan index 3d24dbc..1c35626 100644 --- a/plugins/virus/clamdscan +++ b/plugins/virus/clamdscan @@ -94,7 +94,6 @@ use Clamd; sub register { my ( $self, $qp, @args ) = @_; - $self->register_hook( "data_post", "clamdscan" ); %{ $self->{"_clamd"} } = @args; @@ -104,7 +103,7 @@ sub register { $self->{"_clamd"}->{"max_size"} ||= 128; } -sub clamdscan { +sub hook_data_post { my ( $self, $transaction ) = @_; $DB::single = 1; diff --git a/plugins/virus/hbedv b/plugins/virus/hbedv index 108f7cb..000c923 100644 --- a/plugins/virus/hbedv +++ b/plugins/virus/hbedv @@ -53,7 +53,6 @@ The B plugin is published under the same licence as qpsmtpd itself. sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "hbedv_scan"); if (@args % 2) { $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 $filename = $transaction->body_filename; diff --git a/plugins/virus/kavscanner b/plugins/virus/kavscanner index d6210a3..a57cf6b 100644 --- a/plugins/virus/kavscanner +++ b/plugins/virus/kavscanner @@ -57,7 +57,6 @@ use Mail::Address; sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "kav_scan"); if (@args % 2) { $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 ($temp_fh, $filename) = tempfile(); diff --git a/plugins/virus/klez_filter b/plugins/virus/klez_filter index c169807..4c6b9b8 100644 --- a/plugins/virus/klez_filter +++ b/plugins/virus/klez_filter @@ -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) = @_; # klez files are always sorta big .. how big? Dunno. diff --git a/plugins/virus/sophie b/plugins/virus/sophie index 9da1e29..6850590 100644 --- a/plugins/virus/sophie +++ b/plugins/virus/sophie @@ -3,7 +3,6 @@ use IO::Socket; sub register { my ( $self, $qp, @args ) = @_; - $self->register_hook( "data_post", "sophiescan" ); %{ $self->{"_sophie"} } = @args; @@ -13,7 +12,7 @@ sub register { $self->{"_sophie"}->{"max_size"} ||= 128; } -sub sophiescan { +sub hook_data_post { my ( $self, $transaction ) = @_; $DB::single = 1; diff --git a/plugins/virus/uvscan b/plugins/virus/uvscan index b2bc1a8..55447ed 100644 --- a/plugins/virus/uvscan +++ b/plugins/virus/uvscan @@ -44,7 +44,6 @@ Please see the LICENSE file included with qpsmtpd for details. sub register { my ($self, $qp, @args) = @_; - $self->register_hook("data_post", "uvscan"); while (@args) { $self->{"_uvscan"}->{pop @args}=pop @args; @@ -52,7 +51,7 @@ sub register { $self->{"_uvscan"}->{"uvscan_location"}||="/usr/local/bin/uvscan"; } -sub uvscan { +sub hook_data_post { my ($self, $transaction) = @_; return (DECLINED)