2012-06-22 11:38:01 +02:00
|
|
|
package Test::Qpsmtpd::Plugin;
|
|
|
|
1;
|
|
|
|
|
|
|
|
# Additional plugin methods used during testing
|
|
|
|
package Qpsmtpd::Plugin;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
use Test::More;
|
|
|
|
|
|
|
|
sub register_tests {
|
2013-04-21 06:08:43 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
# Virtual base method - implement in plugin
|
|
|
|
}
|
|
|
|
|
|
|
|
sub register_test {
|
|
|
|
my ($plugin, $test, $num_tests) = @_;
|
|
|
|
$num_tests = 1 unless defined($num_tests);
|
2013-04-21 06:08:43 +02:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
# print STDERR "Registering test $test ($num_tests)\n";
|
2013-04-21 06:08:43 +02:00
|
|
|
push @{$plugin->{_tests}}, {name => $test, num => $num_tests};
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub total_tests {
|
|
|
|
my ($plugin) = @_;
|
|
|
|
my $total = 0;
|
|
|
|
foreach my $t (@{$plugin->{_tests}}) {
|
|
|
|
$total += $t->{num};
|
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run_tests {
|
|
|
|
my ($plugin, $qp) = @_;
|
|
|
|
foreach my $t (@{$plugin->{_tests}}) {
|
|
|
|
my $method = $t->{name};
|
2013-04-21 06:08:43 +02:00
|
|
|
print "# Running $method tests for plugin "
|
|
|
|
. $plugin->plugin_name . "\n";
|
2012-06-22 11:38:01 +02:00
|
|
|
local $plugin->{_qp} = $qp;
|
|
|
|
$plugin->$method();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub validate_password {
|
2013-04-21 06:08:43 +02:00
|
|
|
my ($self, %a) = @_;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
my ($pkg, $file, $line) = caller();
|
|
|
|
|
|
|
|
my $src_clear = $a{src_clear};
|
|
|
|
my $src_crypt = $a{src_crypt};
|
|
|
|
my $attempt_clear = $a{attempt_clear};
|
|
|
|
my $attempt_hash = $a{attempt_hash};
|
|
|
|
my $method = $a{method} or die "missing method";
|
|
|
|
my $ticket = $a{ticket};
|
|
|
|
my $deny = $a{deny} || DENY;
|
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if (!$src_crypt && !$src_clear) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "fail: missing password");
|
2013-04-21 06:08:43 +02:00
|
|
|
return ($deny, "$file - no such user");
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if (!$src_clear && $method =~ /CRAM-MD5/i) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "skip: cram-md5 not supported w/o clear pass");
|
2013-04-21 06:08:43 +02:00
|
|
|
return (DECLINED, $file);
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if (defined $attempt_clear) {
|
|
|
|
if ($src_clear && $src_clear eq $attempt_clear) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "pass: clear match");
|
2013-04-21 06:08:43 +02:00
|
|
|
return (OK, $file);
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if ($src_crypt && $src_crypt eq crypt($attempt_clear, $src_crypt)) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "pass: crypt match");
|
2013-04-21 06:08:43 +02:00
|
|
|
return (OK, $file);
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
2013-04-21 06:08:43 +02:00
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if (defined $attempt_hash && $src_clear) {
|
|
|
|
if (!$ticket) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGERROR, "skip: missing ticket");
|
2013-04-21 06:08:43 +02:00
|
|
|
return (DECLINED, $file);
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if ($attempt_hash eq hmac_md5_hex($ticket, $src_clear)) {
|
2012-06-22 11:38:01 +02:00
|
|
|
$self->log(LOGINFO, "pass: hash match");
|
2013-04-21 06:08:43 +02:00
|
|
|
return (OK, $file);
|
|
|
|
}
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$self->log(LOGINFO, "fail: wrong password");
|
2013-04-21 06:08:43 +02:00
|
|
|
return ($deny, "$file - wrong password");
|
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
1;
|