Debian Codegraph @

plugins/auth/auth_vpopmail

raw
1 #!perl -w
2
3 =head1 NAME
4
5 auth_vpopmail - Authenticate against libvpopmail.a
6
7 =head1 DESCRIPTION
8
9 This plugin authenticates vpopmail users using p5-vpopmail.
10 Using CRAM-MD5 requires that vpopmail be built with the
11 '--enable-clear-passwd=y' option.
12
13 =head1 CONFIGURATION
14
15 This module will only work if qpsmtpd is running as the 'vpopmail' user.
16
17 CRAM-MD5 authentication will only work with p5-vpopmail 0.09 or higher.
18 http://github.com/sscanlon/vpopmail
19
20 Decide which authentication methods you are willing to support and uncomment
21 the lines in the register() sub. See the POD for Qspmtpd::Auth for more
22 details on the ramifications of supporting various authentication methods.
23
24 =head1 SEE ALSO
25
26 For an overview of the vpopmail authentication plugins and their merits,
27 please read the VPOPMAIL section in docs/authentication.pod
28
29 =head1 AUTHOR
30
31 Matt Simerson <[email protected]>
32
33 =head1 COPYRIGHT AND LICENSE
34
35 Copyright (c) 2010 Matt Simerson
36
37 This plugin is licensed under the same terms as the qpsmtpd package itself.
38 Please see the LICENSE file included with qpsmtpd for details.
39
40 =cut
41
42 use strict;
43 use warnings;
44
45 use Qpsmtpd::Auth;
46 use Qpsmtpd::Constants;
47
48 #use vpopmail; # we eval this in $test_vpopmail_module
49
50 sub register {
51 my ($self, $qp) = @_;
52
53 return (DECLINED) if !$self->test_vpopmail_module();
54
55 $self->register_hook("auth-plain", "auth_vpopmail");
56 $self->register_hook("auth-login", "auth_vpopmail");
57 $self->register_hook("auth-cram-md5", "auth_vpopmail");
58 }
59
60 sub auth_vpopmail {
61 my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) =
62 @_;
63
64 my $pw = vauth_getpw(split /@/, lc($user));
65 my $pw_clear_passwd = $pw->{pw_clear_passwd};
66 my $pw_passwd = $pw->{pw_passwd};
67
68 if (!$pw || (!$pw_clear_passwd && !$pw_passwd)) {
69 $self->log(LOGINFO, "fail: invalid user $user");
70 return (DENY, "auth_vpopmail - invalid user");
71
72 # change DENY to DECLINED to support multiple auth plugins
73 }
74
75 return
76 Qpsmtpd::Auth::validate_password(
77 $self,
78 src_clear => $pw->{pw_clear_passwd},
79 src_crypt => $pw->{pw_passwd},
80 attempt_clear => $passClear,
81 attempt_hash => $passHash,
82 method => $method,
83 ticket => $ticket,
84 deny => DENY,
85 );
86 }
87
88 sub test_vpopmail_module {
89 my $self = shift;
90
91 # vpopmail will not allow vauth_getpw to succeed unless the requesting user is vpopmail or root.
92 # by default, qpsmtpd runs as the user 'qpsmtpd' and does not have permission.
93 eval 'use vpopmail';
94 if ($@) {
95 $self->log(LOGERROR, "skip: is vpopmail perl module installed?");
96 return;
97 }
98
99 my ($domain) = vpopmail::vlistdomains();
100 my $r = vauth_getpw('postmaster', $domain) or do {
101 $self->log(LOGERROR, "skip: could not query vpopmail");
102 return;
103 };
104 return 1;
105 }