qpsmtpd/plugins/random_error
Matt Simerson dbaa9dbd6c POD corrections, additional tests, plugin consistency
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
2012-04-29 00:00:10 -07:00

86 lines
1.7 KiB
Perl

#!perl -Tw
=head1 NAME
random_error
=head1 DESCRIPTION
This plugin randomly disconnects and issues DENYSOFTs.
=head1 CONFIG
one parameter is allowed, which is how often to error, as a percentage
of messages. The default is 1. Use a negative number to disable.
2/5 of failures are DENYSOFT_DISOCNNECT, 3/5 simply DENYSOFT.
For use with other plugins, scribble the revised failure rate to
$self->qp->connection->notes('random_fail_%');
=cut
sub register {
my ($self, $qp, @args) = @_;
die "Invalid args: '@args'" unless @args < 2;
($self->{__PACKAGE__.'_how'}) = $args[0] || 1;
}
sub NEXT() { DECLINED }
sub random_fail {
my $fpct = $_[0]->qp->connection->notes('random_fail_%');
=head1 calculating the probability of failure
There are six tests a message must pass to reach the queueing stage, and we wish to
provide random failure for each one, with the combined probability being out
configuration argument. So we want to solve this equation:
(1-x) ** 6 = ( 1 - input_number )
or
x = 1 - ( (1 - input_number ) ** (1/6) )
=cut
my $successp = 1 - ($fpct / 100);
$_[0]->log(LOGINFO, "to fail, rand(1) must be more than ". ($successp ** (1 / 6)) );
rand(1) < ($successp ** (1 / 6)) and return NEXT;
rand(5) < 2 and return (DENYSOFT_DISCONNECT, "random failure");
return (DENYSOFT, "random failure");
}
sub hook_connect {
$_[0]->qp->connection->notes('random_fail_%', $_[0]->{__PACKAGE__.'_how'});
goto &random_fail
}
sub hook_helo {
goto &random_fail
}
sub hook_ehlo {
goto &random_fail
}
sub hook_mail {
goto &random_fail
}
sub hook_rcpt {
goto &random_fail
}
sub hook_data {
goto &random_fail
}
sub hook_data_post {
goto &random_fail
}