Debian Codegraph @

plugins/auth/auth_flat_file

raw
1 #!perl -w
2
3 =head1 NAME
4
5 auth_flat_file - simple CRAM MD5 auth plugin using a flat password file
6
7 =head1 SYNOPSIS
8
9 in config/plugins:
10
11 auth/auth_flat_file
12
13 in config/flat_auth_pw
14
15 username1:password1
16 username2:password2
17 ...
18
19 =head1 DESCRIPTION
20
21 This plugin implements a very simple authentication plugin using a flat password
22 file containing username and password separated by colons.
23
24 Note that this plugin enforces the use of a full email address (including
25 @domain) as the username. There's no particular reason for this so feel free
26 to modify the code to suit your setup.
27
28 The password is stored on disk unencrypted, however authentication uses a HMAC
29 algorithm so no password is transfered in the clear.
30
31 =cut
32
33 use strict;
34 use warnings;
35
36 use Qpsmtpd::Auth;
37 use Qpsmtpd::Constants;
38
39 sub register {
40 my ($self, $qp) = @_;
41
42 $self->register_hook('auth-plain', 'auth_flat_file');
43 $self->register_hook('auth-login', 'auth_flat_file');
44 $self->register_hook('auth-cram-md5', 'auth_flat_file');
45 }
46
47 sub auth_flat_file {
48 my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) =
49 @_;
50
51 if (!defined $passClear && !defined $passHash) {
52 $self->log(LOGINFO, "fail: missing password");
53 return (DENY, "authflat - missing password");
54 }
55
56 my ($pw_name, $pw_domain) = split /@/, lc($user);
57
58 unless (defined $pw_domain) {
59 $self->log(LOGINFO, "fail: missing domain");
60 return DECLINED;
61 }
62
63 my ($auth_line) =
64 grep { /^$pw_name\@$pw_domain:/ } $self->qp->config('flat_auth_pw');
65
66 if (!defined $auth_line) {
67 $self->log(LOGINFO, "fail: no such user: $user");
68 return DECLINED;
69 }
70
71 my ($auth_user, $auth_pass) = split(/:/, $auth_line, 2);
72
73 # at this point we can assume the user name matched
74 return
75 Qpsmtpd::Auth::validate_password(
76 $self,
77 src_clear => $auth_pass,
78 src_crypt => undef,
79 attempt_clear => $passClear,
80 attempt_hash => $passHash,
81 method => $method,
82 ticket => $ticket,
83 deny => DENY,
84 );
85 }
86