2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2010-05-08 19:25:08 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-05-04 22:04:28 +02:00
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
2010-05-08 19:25:08 +02:00
|
|
|
use IO::Socket;
|
2012-04-07 23:52:44 +02:00
|
|
|
use version;
|
2012-05-04 22:04:28 +02:00
|
|
|
my $VERSION = qv('1.0.2');
|
2010-05-08 19:25:08 +02:00
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $qp, %args) = @_;
|
|
|
|
|
2012-04-07 23:52:44 +02:00
|
|
|
$self->{_vpopmaild_host} = $args{host} || 'localhost';
|
|
|
|
$self->{_vpopmaild_port} = $args{port} || '89';
|
2010-05-08 19:25:08 +02:00
|
|
|
|
|
|
|
$self->register_hook('auth-plain', 'auth_vpopmaild');
|
|
|
|
$self->register_hook('auth-login', 'auth_vpopmaild');
|
2012-05-04 22:04:28 +02:00
|
|
|
#$self->register_hook('auth-cram-md5', 'auth_vpopmaild'); # not supported
|
2010-05-08 19:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub auth_vpopmaild {
|
2012-04-07 23:52:44 +02:00
|
|
|
my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) = @_;
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
if ( ! $passClear ) {
|
|
|
|
$self->log(LOGINFO, "vpopmaild does not support cram-md5");
|
|
|
|
return DECLINED;
|
|
|
|
}
|
2010-05-08 19:25:08 +02:00
|
|
|
|
|
|
|
# create socket
|
|
|
|
my $vpopmaild_socket =
|
|
|
|
IO::Socket::INET->new(
|
|
|
|
PeerAddr => $self->{_vpopmaild_host},
|
|
|
|
PeerPort => $self->{_vpopmaild_port},
|
|
|
|
Proto => 'tcp',
|
|
|
|
Type => SOCK_STREAM
|
|
|
|
) or return DECLINED;
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
$self->log(LOGDEBUG, "attempting $method");
|
2012-04-07 23:52:44 +02:00
|
|
|
|
2010-05-08 19:25:08 +02:00
|
|
|
# Get server greeting (+OK)
|
|
|
|
my $connect_response = <$vpopmaild_socket>;
|
2012-05-04 22:04:28 +02:00
|
|
|
if ( ! $connect_response ) {
|
|
|
|
$self->log(LOGERROR, "no connection response");
|
2012-04-07 23:52:44 +02:00
|
|
|
close($vpopmaild_socket);
|
|
|
|
return DECLINED;
|
|
|
|
};
|
2010-05-08 19:25:08 +02:00
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
if ( $connect_response !~ /^\+OK/ ) {
|
|
|
|
$self->log(LOGERROR, "bad connection response: $connect_response");
|
|
|
|
close($vpopmaild_socket);
|
|
|
|
return DECLINED;
|
|
|
|
};
|
2010-05-08 19:25:08 +02:00
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
print $vpopmaild_socket "login $user $passClear\n\r"; # send login details
|
|
|
|
my $login_response = <$vpopmaild_socket>; # get response from server
|
2010-05-08 19:25:08 +02:00
|
|
|
close($vpopmaild_socket);
|
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
if ( ! $login_response ) {
|
|
|
|
$self->log(LOGERROR, "no login response");
|
|
|
|
return DECLINED;
|
|
|
|
};
|
|
|
|
|
2012-04-07 23:52:44 +02:00
|
|
|
# check for successful login (single line (+OK) or multiline (+OK+))
|
2012-05-04 22:04:28 +02:00
|
|
|
if ( $login_response =~ /^\+OK/ ) {
|
|
|
|
$self->log(LOGDEBUG, "auth success");
|
|
|
|
return (OK, 'auth_vpopmaild');
|
|
|
|
};
|
2012-04-07 23:52:44 +02:00
|
|
|
|
2012-05-04 22:04:28 +02:00
|
|
|
$self->log(LOGNOTICE, "failed authentication response: $login_response");
|
2012-04-07 23:52:44 +02:00
|
|
|
|
|
|
|
return DECLINED;
|
2010-05-08 19:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
auth_vpopmaild - Authenticate to vpopmaild
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Authenticates the user against against vpopmaild [1] daemon.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Add a line to C<config/plugins> as follows:
|
|
|
|
|
|
|
|
auth_vpopmaild
|
|
|
|
|
|
|
|
By default, the plugin connects to localhot on port 89. If your vpopmaild
|
|
|
|
daemon is running on a different host or port, specify as follows:
|
|
|
|
|
|
|
|
auth_vpopmaild host [host] port [port]
|
|
|
|
|
2010-05-11 08:19:05 +02:00
|
|
|
=head1 SEE ALSO
|
|
|
|
|
|
|
|
For an overview of the vpopmail authentication plugins and their merits,
|
|
|
|
please read the VPOPMAIL section in doc/authentication.pod
|
|
|
|
|
2010-05-08 19:25:08 +02:00
|
|
|
=head1 LINKS
|
|
|
|
|
|
|
|
[1] http://www.qmailwiki.org/Vpopmaild
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Robin Bowes <robin.bowes@yo61.com>
|
|
|
|
|
2012-04-07 23:52:44 +02:00
|
|
|
Matt Simerson (4/2012: added CRAM-MD5 support, updated response parsing)
|
|
|
|
|
2010-05-08 19:25:08 +02:00
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
Copyright (c) 2010 Robin Bowes
|
|
|
|
|
|
|
|
This plugin is licensed under the same terms as the qpsmtpd package itself.
|
|
|
|
Please see the LICENSE file included with qpsmtpd for details.
|
|
|
|
|
|
|
|
=cut
|