| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Server::Mail::ESMTP::AUTH; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7485
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use base qw(Net::Server::Mail::ESMTP::Extension); |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
932
|
|
|
6
|
1
|
|
|
1
|
|
1219
|
use MIME::Base64; |
|
|
1
|
|
|
|
|
1189
|
|
|
|
1
|
|
|
|
|
70
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use vars qw( $VERSION ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
837
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.1'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::Server::Mail::ESMTP::AUTH - An extension to provide |
|
14
|
|
|
|
|
|
|
support for SMTP Authentification with Net::Server::Mail::ESMTP module |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Net::Server::Mail::ESMTP; |
|
19
|
|
|
|
|
|
|
my @local_domains = qw(example.com example.org); |
|
20
|
|
|
|
|
|
|
my $server = new IO::Socket::INET Listen => 1, LocalPort => 25; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $conn; |
|
23
|
|
|
|
|
|
|
while($conn = $server->accept) |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
|
|
|
|
|
|
my $esmtp = new Net::Server::Mail::ESMTP socket => $conn; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# activate AUTH extension |
|
28
|
|
|
|
|
|
|
$esmtp->register('Net::Server::Mail::ESMTP::AUTH'); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# adding AUTH handler |
|
31
|
|
|
|
|
|
|
$esmtp->set_callback(AUTH => \&validate_auth); |
|
32
|
|
|
|
|
|
|
$esmtp->process; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub validate_auth |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
|
|
|
|
|
|
my ($session, $username, $password) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if ($username eq 'ROBERT' and $password eq 'TOTO04') { |
|
40
|
|
|
|
|
|
|
# AUTH SUCCESFULL |
|
41
|
|
|
|
|
|
|
return 1; |
|
42
|
|
|
|
|
|
|
} else { |
|
43
|
|
|
|
|
|
|
# AUTH FAILED |
|
44
|
|
|
|
|
|
|
return 0; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 FEATURES |
|
49
|
|
|
|
|
|
|
* AUTH LOGIN method support |
|
50
|
|
|
|
|
|
|
* AUTH PLAIN method support |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
"Net::Server::Mail::ESMTP::AUTH" is an extension to provide |
|
55
|
|
|
|
|
|
|
ESMTP Authentification support to Net::Server::Mail::ESMTP module. |
|
56
|
|
|
|
|
|
|
Actually only AUTH LOGIN and AUTH PLAIN methods are supported. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
AUTH callback is called with login and password who was given |
|
59
|
|
|
|
|
|
|
by user's mail client, AUTH callback should return 1 when authentification |
|
60
|
|
|
|
|
|
|
mechanism was succesfull otherwise 0. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
our $verb = 'AUTH'; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub init |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
|
|
0
|
0
|
|
my ($self, $parent) = @_; |
|
69
|
0
|
|
|
|
|
|
$self->{AUTH} = (); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $self; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub verb |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
0
|
|
|
0
|
0
|
|
return ( [ 'AUTH' => \&process, ],); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub keyword |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
0
|
|
|
0
|
0
|
|
return 'AUTH LOGIN PLAIN'; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub reply |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
0
|
|
return ( [ 'AUTH', ]); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub process_authlogin_username |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
0
|
|
|
0
|
0
|
|
my ($self, $operation) = @_; |
|
92
|
0
|
|
|
|
|
|
$self->{AUTH}->{username} = decode_base64($operation); |
|
93
|
0
|
|
|
|
|
|
$self->{AUTH}->{password} = ''; |
|
94
|
0
|
|
|
|
|
|
$self->reply(334, "UGFzc3dvcmQ6"); |
|
95
|
0
|
|
|
|
|
|
$self->next_input_to(\&process_authlogin_password); |
|
96
|
0
|
|
|
|
|
|
return 1; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub process_authlogin_password |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
0
|
|
|
0
|
0
|
|
my ($self, $operation) = @_; |
|
102
|
0
|
|
|
|
|
|
$self->{AUTH}->{password} = decode_base64($operation); |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
exec_auth_callback($self); |
|
105
|
0
|
|
|
|
|
|
return 1; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub exec_auth_callback |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $authok=0; |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $ref = $self->{callback}->{AUTH}; |
|
115
|
0
|
0
|
0
|
|
|
|
if (ref $ref eq 'ARRAY' && ref $ref->[0] eq 'CODE') { |
|
116
|
0
|
|
|
|
|
|
my $code = $ref->[0]; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$authok = &$code($self, $self->{AUTH}->{username}, $self->{AUTH}->{password}); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
if ($authok) { |
|
122
|
0
|
|
|
|
|
|
$self->reply(235, "Authentification successful."); |
|
123
|
|
|
|
|
|
|
} else { |
|
124
|
0
|
|
|
|
|
|
$self->reply(535, "Authentification failed."); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub process |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
|
131
|
0
|
0
|
|
|
|
|
my ($operation, $param) = $data=~/^(.+?)\s(.*)$/ ? ($1, $2) : ($data, ''); |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$self->{AUTH}->{type} = $operation; |
|
134
|
0
|
|
|
|
|
|
map { $self->{AUTH}->{$_} = '' } ('username', 'password', 'challenge', 'ticket', ); |
|
|
0
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if ($operation eq '*') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$self->reply(501, "Authentification aborted."); |
|
138
|
0
|
|
|
|
|
|
return (); |
|
139
|
|
|
|
|
|
|
} elsif ($operation eq 'PLAIN') { |
|
140
|
0
|
|
|
|
|
|
$param=decode_base64($param); |
|
141
|
0
|
|
|
|
|
|
my @plaindata = split /\0/, $param; |
|
142
|
0
|
0
|
|
|
|
|
unless (@plaindata > 2) { |
|
143
|
0
|
|
|
|
|
|
$self->reply(535, "Authentification failed."); |
|
144
|
0
|
|
|
|
|
|
return (); |
|
145
|
|
|
|
|
|
|
} else { |
|
146
|
0
|
|
|
|
|
|
$self->{AUTH}->{username} = $plaindata[@plaindata-2]; |
|
147
|
0
|
|
|
|
|
|
$self->{AUTH}->{password} = $plaindata[@plaindata-1]; |
|
148
|
0
|
|
|
|
|
|
exec_auth_callback($self); |
|
149
|
0
|
|
|
|
|
|
return (); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} elsif ($operation eq 'LOGIN') { |
|
152
|
0
|
|
|
|
|
|
$param=decode_base64($param); |
|
153
|
0
|
|
|
|
|
|
warn " ==> LOGIN ==> $param\n"; |
|
154
|
0
|
|
|
|
|
|
$self->reply(334, "VXNlcm5hbWU6"); |
|
155
|
0
|
|
|
|
|
|
$self->next_input_to(\&process_authlogin_username); |
|
156
|
0
|
|
|
|
|
|
return (); |
|
157
|
|
|
|
|
|
|
} else { |
|
158
|
0
|
|
|
|
|
|
$self->reply(504, "Unrecognized authentification type."); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return (); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=pod |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Please, see L and L for |
|
169
|
|
|
|
|
|
|
more documentations. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Sylvain Cresto Etost@softhome.netE |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 BUGS |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Please send bug-reports to tost@softhome.net. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 LICENCE |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
182
|
|
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as |
|
183
|
|
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the |
|
184
|
|
|
|
|
|
|
License, or (at your option) any later version. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful, but |
|
187
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
188
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
189
|
|
|
|
|
|
|
Lesser General Public License for more details. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public |
|
192
|
|
|
|
|
|
|
License along with this library; if not, write to the Free Software |
|
193
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
194
|
|
|
|
|
|
|
USA |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright (C) 2004 - Sylvain Cresto |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |