qpsmtpd/plugins/auth/auth_vpopmaild
Robert 61de599c1b Normalize #! lines on all plugins
find . -type f | xargs -n1 perl -pi.bak -0777 -e '$want = "#!perl -Tw"; s/\A#!.*\n/$want\n/; s/\A([^#])/$want\n\1/s'
2012-04-28 20:41:31 -07:00

104 lines
2.6 KiB
Perl

#!perl -Tw
use strict;
use warnings;
use IO::Socket;
use version;
my $VERSION = qv('1.0.1');
sub register {
my ($self, $qp, %args) = @_;
$self->{_vpopmaild_host} = $args{host} || 'localhost';
$self->{_vpopmaild_port} = $args{port} || '89';
$self->register_hook('auth-plain', 'auth_vpopmaild');
$self->register_hook('auth-login', 'auth_vpopmaild');
$self->register_hook('auth-cram-md5', 'auth_vpopmaild');
}
sub auth_vpopmaild {
my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) = @_;
use Qpsmtpd::Constants;
# 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;
#$self->log(LOGINFO, "Attempting $method auth via vpopmaild");
# Get server greeting (+OK)
my $connect_response = <$vpopmaild_socket>;
if ( $connect_response !~ /^\+OK/ ) {
$self->log(LOGINFO, "Failed to receive vpopmaild connection response: $connect_response");
close($vpopmaild_socket);
return DECLINED;
};
# send login details
print $vpopmaild_socket "login $user $passClear\n\r";
# get response from server
my $login_response = <$vpopmaild_socket>;
close($vpopmaild_socket);
# check for successful login (single line (+OK) or multiline (+OK+))
return (OK, 'auth_vpopmaild') if $login_response =~ /^\+OK/;
$self->log(LOGINFO, "Failed vpopmaild authentication response: $login_response");
return DECLINED;
}
__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]
=head1 SEE ALSO
For an overview of the vpopmail authentication plugins and their merits,
please read the VPOPMAIL section in doc/authentication.pod
=head1 LINKS
[1] http://www.qmailwiki.org/Vpopmaild
=head1 AUTHOR
Robin Bowes <robin.bowes@yo61.com>
Matt Simerson (4/2012: added CRAM-MD5 support, updated response parsing)
=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