fixed failing auths to auth/vpopmaild, added tests
Apparently the format of vpopmaild responses has been expanded and the responses are conditional. * Replaced the 'sometimes works' eq comparison with a regexp that always works. * added tests for all 3 vpopmail plugins * added cram-md5 auth support to auth_vpopmaild.
This commit is contained in:
parent
cd5f088d69
commit
ed8eca0a63
3
MANIFEST
3
MANIFEST
@ -145,6 +145,9 @@ t/helo.t
|
|||||||
t/misc.t
|
t/misc.t
|
||||||
t/plugin_tests.t
|
t/plugin_tests.t
|
||||||
t/plugin_tests/auth/auth_flat_file
|
t/plugin_tests/auth/auth_flat_file
|
||||||
|
t/plugin_tests/auth/auth_vpopmail
|
||||||
|
t/plugin_tests/auth/auth_vpopmail_sql
|
||||||
|
t/plugin_tests/auth/auth_vpopmaild
|
||||||
t/plugin_tests/auth/authdeny
|
t/plugin_tests/auth/authdeny
|
||||||
t/plugin_tests/auth/authnull
|
t/plugin_tests/auth/authnull
|
||||||
t/plugin_tests/check_badrcptto
|
t/plugin_tests/check_badrcptto
|
||||||
|
@ -105,7 +105,11 @@ sub test_vpopmail {
|
|||||||
|
|
||||||
# vpopmail will not allow vauth_getpw to succeed unless the requesting user is vpopmail or root.
|
# 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.
|
# by default, qpsmtpd runs as the user 'qpsmtpd' and does not have permission.
|
||||||
use vpopmail;
|
eval "use vpopmail";
|
||||||
|
if ( $@ ) {
|
||||||
|
warn "vpopmail perl module not installed.\n";
|
||||||
|
return;
|
||||||
|
};
|
||||||
my ($domain) = vpopmail::vlistdomains();
|
my ($domain) = vpopmail::vlistdomains();
|
||||||
my $r = vauth_getpw('postmaster', $domain);
|
my $r = vauth_getpw('postmaster', $domain);
|
||||||
return if !$r;
|
return if !$r;
|
||||||
|
@ -1,30 +1,26 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use IO::Socket;
|
use IO::Socket;
|
||||||
use version; my $VERSION = qv('1.0.0');
|
use version;
|
||||||
|
my $VERSION = qv('1.0.1');
|
||||||
|
|
||||||
sub register {
|
sub register {
|
||||||
my ($self, $qp, %args) = @_;
|
my ($self, $qp, %args) = @_;
|
||||||
|
|
||||||
my %DEFAULT = (
|
$self->{_vpopmaild_host} = $args{host} || 'localhost';
|
||||||
host => q{localhost},
|
$self->{_vpopmaild_port} = $args{port} || '89';
|
||||||
port => 89,
|
|
||||||
);
|
|
||||||
|
|
||||||
$self->{_vpopmaild_host} =
|
|
||||||
defined $args{host} ? $args{host} : $DEFAULT{host};
|
|
||||||
$self->{_vpopmaild_port} =
|
|
||||||
defined $args{port} ? $args{port} : $DEFAULT{port};
|
|
||||||
|
|
||||||
$self->register_hook('auth-plain', 'auth_vpopmaild');
|
$self->register_hook('auth-plain', 'auth_vpopmaild');
|
||||||
$self->register_hook('auth-login', 'auth_vpopmaild');
|
$self->register_hook('auth-login', 'auth_vpopmaild');
|
||||||
|
$self->register_hook('auth-cram-md5', 'auth_vpopmaild');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub auth_vpopmaild {
|
sub auth_vpopmaild {
|
||||||
my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) =
|
my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) = @_;
|
||||||
@_;
|
|
||||||
|
use Qpsmtpd::Constants;
|
||||||
|
|
||||||
# create socket
|
# create socket
|
||||||
my $vpopmaild_socket =
|
my $vpopmaild_socket =
|
||||||
@ -35,9 +31,15 @@ sub auth_vpopmaild {
|
|||||||
Type => SOCK_STREAM
|
Type => SOCK_STREAM
|
||||||
) or return DECLINED;
|
) or return DECLINED;
|
||||||
|
|
||||||
|
#$self->log(LOGINFO, "Attempting $method auth via vpopmaild");
|
||||||
|
|
||||||
# Get server greeting (+OK)
|
# Get server greeting (+OK)
|
||||||
my $connect_response = <$vpopmaild_socket>;
|
my $connect_response = <$vpopmaild_socket>;
|
||||||
return DECLINED unless $connect_response eq '+OK \r\n';
|
if ( $connect_response !~ /^\+OK/ ) {
|
||||||
|
$self->log(LOGINFO, "Failed to receive vpopmaild connection response: $connect_response");
|
||||||
|
close($vpopmaild_socket);
|
||||||
|
return DECLINED;
|
||||||
|
};
|
||||||
|
|
||||||
# send login details
|
# send login details
|
||||||
print $vpopmaild_socket "login $user $passClear\n\r";
|
print $vpopmaild_socket "login $user $passClear\n\r";
|
||||||
@ -47,14 +49,13 @@ sub auth_vpopmaild {
|
|||||||
|
|
||||||
close($vpopmaild_socket);
|
close($vpopmaild_socket);
|
||||||
|
|
||||||
# check for successful login
|
# check for successful login (single line (+OK) or multiline (+OK+))
|
||||||
if ($login_response eq '+OK+\r\n') {
|
return (OK, 'auth_vpopmaild') if $login_response =~ /^\+OK/;
|
||||||
return (OK, 'authcheckpassword');
|
|
||||||
}
|
$self->log(LOGINFO, "Failed vpopmaild authentication response: $login_response");
|
||||||
else {
|
|
||||||
return DECLINED;
|
return DECLINED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
@ -90,6 +91,8 @@ please read the VPOPMAIL section in doc/authentication.pod
|
|||||||
|
|
||||||
Robin Bowes <robin.bowes@yo61.com>
|
Robin Bowes <robin.bowes@yo61.com>
|
||||||
|
|
||||||
|
Matt Simerson (4/2012: added CRAM-MD5 support, updated response parsing)
|
||||||
|
|
||||||
=head1 COPYRIGHT AND LICENSE
|
=head1 COPYRIGHT AND LICENSE
|
||||||
|
|
||||||
Copyright (c) 2010 Robin Bowes
|
Copyright (c) 2010 Robin Bowes
|
||||||
|
27
t/plugin_tests/auth/auth_vpopmail
Normal file
27
t/plugin_tests/auth/auth_vpopmail
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*-perl-*- [emacs]
|
||||||
|
|
||||||
|
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' ],
|
||||||
|
none => [ 'none@example.com', DECLINED, '' ],
|
||||||
|
);
|
||||||
|
|
||||||
|
sub test_auth_vpopmail {
|
||||||
|
my $self = shift;
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
27
t/plugin_tests/auth/auth_vpopmail_sql
Normal file
27
t/plugin_tests/auth/auth_vpopmail_sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*-perl-*- [emacs]
|
||||||
|
|
||||||
|
sub register_tests {
|
||||||
|
my $self = shift;
|
||||||
|
$self->register_test("auth_vpopmail_sql", 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' ],
|
||||||
|
none => [ 'none@example.com', DECLINED, '' ],
|
||||||
|
);
|
||||||
|
|
||||||
|
sub auth_vpopmail_sql {
|
||||||
|
my $self = shift;
|
||||||
|
my ($tran, $ret, $note, $u, $r, $p, $a );
|
||||||
|
$tran = $self->qp->transaction;
|
||||||
|
for $u ( @u_list ) {
|
||||||
|
( $a,$r,$p ) = @{$u_data{$u}};
|
||||||
|
eval { ($ret, $note) = $self->auth_vmysql($tran,'PLAIN',$a,$p); };
|
||||||
|
defined $note or $note='auth_vpopmail_sql: No-Message';
|
||||||
|
is ($ret, $r, $note);
|
||||||
|
# - for debugging.
|
||||||
|
# warn "$note\n";
|
||||||
|
}
|
||||||
|
}
|
27
t/plugin_tests/auth/auth_vpopmaild
Normal file
27
t/plugin_tests/auth/auth_vpopmaild
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*-perl-*- [emacs]
|
||||||
|
|
||||||
|
warn "loaded test auth_vpopmaild\n";
|
||||||
|
|
||||||
|
sub register_tests {
|
||||||
|
my $self = shift;
|
||||||
|
$self->register_test("test_auth_vpopmaild", 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' ],
|
||||||
|
none => [ 'none@example.com', DECLINED, '' ],
|
||||||
|
);
|
||||||
|
|
||||||
|
sub test_auth_vpopmaild {
|
||||||
|
my $self = shift;
|
||||||
|
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_vpopmaild($tran,'LOGIN',$a,$p);
|
||||||
|
defined $note or $note='No-Message';
|
||||||
|
is ($ret, $r, $note);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user