From febdb001c684b3b9437fe4425e3f70785de9ba73 Mon Sep 17 00:00:00 2001 From: Robin Bowes Date: Sat, 8 May 2010 18:25:08 +0100 Subject: new plugin auth_vpopmaild Signed-off-by: Robert --- MANIFEST | 1 + plugins/auth/auth_vpopmaild | 97 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 0 deletions(-) create mode 100644 plugins/auth/auth_vpopmaild diff --git a/MANIFEST b/MANIFEST index 9d5912a..7ae1b14 100644 --- a/MANIFEST +++ b/MANIFEST @@ -67,6 +67,7 @@ plugins/auth/auth_cvm_unix_local plugins/auth/auth_flat_file plugins/auth/auth_ldap_bind plugins/auth/auth_vpopmail_sql +plugins/auth/auth_vpopmaild plugins/auth/authdeny plugins/check_badmailfrom plugins/check_badmailfromto diff --git a/plugins/auth/auth_vpopmaild b/plugins/auth/auth_vpopmaild new file mode 100644 index 0000000..e4ab940 --- /dev/null +++ b/plugins/auth/auth_vpopmaild @@ -0,0 +1,97 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use IO::Socket; +use version; my $VERSION = qv('1.0.0'); + +sub register { + my ($self, $qp, %args) = @_; + + my %DEFAULT = ( + host => q{localhost}, + 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-login', 'auth_vpopmaild'); +} + +sub auth_vpopmaild { + my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) = + @_; + + # 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; + + # Get server greeting (+OK) + my $connect_response = <$vpopmaild_socket>; + if (!$connect_response =~ /\+OK.*/) { + 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 + if ($login_response =~ /\+OK.*/) { + return (OK, 'authcheckpassword'); + } + else { + 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 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 LINKS + +[1] http://www.qmailwiki.org/Vpopmaild + +=head1 AUTHOR + +Robin Bowes + +=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 -- 1.7.2.2