2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2010-05-11 08:19:05 +02:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
auth_vpopmail - Authenticate against libvpopmail.a
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This plugin authenticates vpopmail users using p5-vpopmail.
|
|
|
|
Using CRAM-MD5 requires that vpopmail be built with the
|
|
|
|
'--enable-clear-passwd=y' option.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
This module will only work if qpsmtpd is running as the 'vpopmail' user.
|
|
|
|
|
|
|
|
CRAM-MD5 authentication will only work with p5-vpopmail 0.09 or higher.
|
|
|
|
http://github.com/sscanlon/vpopmail
|
|
|
|
|
|
|
|
Decide which authentication methods you are willing to support and uncomment
|
|
|
|
the lines in the register() sub. See the POD for Qspmtpd::Auth for more
|
|
|
|
details on the ramifications of supporting various authentication methods.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
For an overview of the vpopmail authentication plugins and their merits,
|
|
|
|
please read the VPOPMAIL section in docs/authentication.pod
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Matt Simerson <msimerson@cpan.org>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
Copyright (c) 2010 Matt Simerson
|
|
|
|
|
|
|
|
This plugin is licensed under the same terms as the qpsmtpd package itself.
|
|
|
|
Please see the LICENSE file included with qpsmtpd for details.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2012-04-08 02:11:16 +02:00
|
|
|
use strict;
|
2012-05-04 22:04:28 +02:00
|
|
|
use warnings;
|
2012-04-08 02:11:16 +02:00
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
use Digest::HMAC_MD5 qw(hmac_md5_hex);
|
2012-05-07 09:35:58 +02:00
|
|
|
#use vpopmail; # we eval this in $test_vpopmail
|
2012-05-04 22:04:28 +02:00
|
|
|
|
2010-05-11 08:19:05 +02:00
|
|
|
sub register {
|
|
|
|
my ($self, $qp) = @_;
|
|
|
|
|
2012-05-07 09:35:58 +02:00
|
|
|
return (DECLINED) if ! $self->test_vpopmail_module();
|
|
|
|
|
2010-05-11 08:19:05 +02:00
|
|
|
$self->register_hook("auth-plain", "auth_vpopmail" );
|
|
|
|
$self->register_hook("auth-login", "auth_vpopmail" );
|
|
|
|
$self->register_hook("auth-cram-md5", "auth_vpopmail");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub auth_vpopmail {
|
|
|
|
my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) =
|
|
|
|
@_;
|
|
|
|
my ($pw_name, $pw_domain) = split "@", lc($user);
|
|
|
|
|
|
|
|
$self->log(LOGINFO, "Authenticating against vpopmail: $user");
|
|
|
|
|
|
|
|
my $pw = vauth_getpw($pw_name, $pw_domain);
|
|
|
|
my $pw_clear_passwd = $pw->{pw_clear_passwd};
|
|
|
|
my $pw_passwd = $pw->{pw_passwd};
|
|
|
|
|
|
|
|
# make sure the user exists
|
|
|
|
if (!$pw || (!$pw_clear_passwd && !$pw_passwd)) {
|
2012-05-04 22:04:28 +02:00
|
|
|
return (DENY, "auth_vpopmail - invalid user");
|
2010-05-11 08:19:05 +02:00
|
|
|
|
|
|
|
# change DENY to DECLINED to support multiple auth plugins
|
|
|
|
}
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
return (OK, "auth_vpopmail")
|
2010-05-11 08:19:05 +02:00
|
|
|
if $pw_passwd eq crypt($passClear, $pw_passwd);
|
|
|
|
|
|
|
|
# simplest case: clear text passwords
|
|
|
|
if (defined $passClear && defined $pw_clear_passwd) {
|
2012-05-04 22:04:28 +02:00
|
|
|
return (DENY, "auth_vpopmail - incorrect password")
|
2010-05-11 08:19:05 +02:00
|
|
|
if $passClear ne $pw_clear_passwd;
|
2012-05-04 22:04:28 +02:00
|
|
|
return (OK, "auth_vpopmail");
|
2010-05-11 08:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($method =~ /CRAM-MD5/i) {
|
|
|
|
|
|
|
|
# clear_passwd isn't defined so we cannot support CRAM-MD5
|
2012-05-04 22:04:28 +02:00
|
|
|
return (DECLINED, "auth_vpopmail") if !defined $pw_clear_passwd;
|
2010-05-11 08:19:05 +02:00
|
|
|
|
|
|
|
if (defined $passHash
|
|
|
|
and $passHash eq hmac_md5_hex($ticket, $pw_clear_passwd))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
return (OK, "auth_vpopmail")
|
2010-05-11 08:19:05 +02:00
|
|
|
if (defined $passHash
|
|
|
|
&& $passHash eq hmac_md5_hex($ticket, $pw_clear_passwd));
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
return (DENY, "auth_vpopmail - unknown error");
|
2010-05-11 08:19:05 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 09:35:58 +02:00
|
|
|
sub test_vpopmail_module {
|
|
|
|
my $self = shift;
|
2010-05-11 08:19:05 +02:00
|
|
|
# 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.
|
2012-04-07 23:52:44 +02:00
|
|
|
eval "use vpopmail";
|
|
|
|
if ( $@ ) {
|
2012-05-07 09:35:58 +02:00
|
|
|
$self->log(LOGERROR, "skip: is vpopmail perl module installed?");
|
2012-04-07 23:52:44 +02:00
|
|
|
return;
|
|
|
|
};
|
2012-05-07 09:35:58 +02:00
|
|
|
|
2010-05-11 08:19:05 +02:00
|
|
|
my ($domain) = vpopmail::vlistdomains();
|
2012-05-07 09:35:58 +02:00
|
|
|
my $r = vauth_getpw('postmaster', $domain) or do {
|
|
|
|
$self->log(LOGERROR, "skip: could not query vpopmail");
|
|
|
|
return;
|
|
|
|
};
|
2010-05-11 08:19:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|