auth_vpopmail: refactored, added tests, logging
added more logging standard log prefixes tests run a pretest to make sure tests have a chance to succeed
This commit is contained in:
parent
9059529325
commit
adbbfe6f67
@ -45,11 +45,13 @@ use warnings;
|
||||
use Qpsmtpd::Constants;
|
||||
|
||||
use Digest::HMAC_MD5 qw(hmac_md5_hex);
|
||||
use vpopmail;
|
||||
#use vpopmail; # we eval this in $test_vpopmail
|
||||
|
||||
sub register {
|
||||
my ($self, $qp) = @_;
|
||||
|
||||
return (DECLINED) if ! $self->test_vpopmail_module();
|
||||
|
||||
$self->register_hook("auth-plain", "auth_vpopmail" );
|
||||
$self->register_hook("auth-login", "auth_vpopmail" );
|
||||
$self->register_hook("auth-cram-md5", "auth_vpopmail");
|
||||
@ -62,9 +64,6 @@ sub auth_vpopmail {
|
||||
|
||||
$self->log(LOGINFO, "Authenticating against vpopmail: $user");
|
||||
|
||||
return (DECLINED, "auth_vpopmail - plugin not configured correctly")
|
||||
if !test_vpopmail();
|
||||
|
||||
my $pw = vauth_getpw($pw_name, $pw_domain);
|
||||
my $pw_clear_passwd = $pw->{pw_clear_passwd};
|
||||
my $pw_passwd = $pw->{pw_passwd};
|
||||
@ -104,17 +103,20 @@ sub auth_vpopmail {
|
||||
return (DENY, "auth_vpopmail - unknown error");
|
||||
}
|
||||
|
||||
sub test_vpopmail {
|
||||
|
||||
sub test_vpopmail_module {
|
||||
my $self = shift;
|
||||
# vpopmail will not allow vauth_getpw to succeed unless the requesting user is vpopmail or root.
|
||||
# by default, qpsmtpd runs as the user 'qpsmtpd' and does not have permission.
|
||||
eval "use vpopmail";
|
||||
if ( $@ ) {
|
||||
warn "vpopmail perl module not installed.\n";
|
||||
$self->log(LOGERROR, "skip: is vpopmail perl module installed?");
|
||||
return;
|
||||
};
|
||||
|
||||
my ($domain) = vpopmail::vlistdomains();
|
||||
my $r = vauth_getpw('postmaster', $domain);
|
||||
return if !$r;
|
||||
my $r = vauth_getpw('postmaster', $domain) or do {
|
||||
$self->log(LOGERROR, "skip: could not query vpopmail");
|
||||
return;
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
|
@ -2,26 +2,32 @@
|
||||
|
||||
sub register_tests {
|
||||
my $self = shift;
|
||||
|
||||
$self->register_test("test_auth_vpopmail", 3);
|
||||
}
|
||||
|
||||
my @u_list = qw ( good bad none );
|
||||
my %u_data = (
|
||||
good => [ 'postmaster@example.com', OK, 'Good Strong Passphrase' ],
|
||||
bad => [ 'bad@example.com', DENY, 'not_bad_pass' ],
|
||||
bad => [ 'bad@example.com', DENY, 'not_bad_pass' ],
|
||||
none => [ 'none@example.com', DECLINED, '' ],
|
||||
);
|
||||
|
||||
sub test_auth_vpopmail {
|
||||
my $self = shift;
|
||||
|
||||
if ( ! $self->test_vpopmail_module ) {
|
||||
$self->log(LOGERROR, "vpopmail plugin not configured" );
|
||||
foreach ( 0..2) { ok( 1, "test_auth_vpopmail, skipped") };
|
||||
return;
|
||||
};
|
||||
|
||||
my ($tran, $ret, $note, $u, $r, $p, $a );
|
||||
$tran = $self->qp->transaction;
|
||||
for $u ( @u_list ) {
|
||||
( $a,$r,$p ) = @{$u_data{$u}};
|
||||
($ret, $note) = $self->auth_vpopmail($tran,'CRAMMD5',$a,$p);
|
||||
defined $note or $note='auth_vpopmail: No-Message';
|
||||
is ($ret, $r, $note);
|
||||
# - for debugging.
|
||||
# warn "$note\n";
|
||||
( $a,$r,$p ) = @{$u_data{$u}};
|
||||
($ret, $note) = $self->auth_vpopmail($tran,'CRAMMD5',$a,$p);
|
||||
defined $note or $note='auth_vpopmail: No-Message';
|
||||
is ($ret, $r, $note);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user