Server/DefaultAuth.pm

filter: Statementstmt 44.0% 11 / 25 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 37.5% 3 / 8 Podpod 100% 4 / 4 totaltotal 36.0% 18 / 50 CC 5 SCAR 26.0
CC
5
Cov
31%
__ANON__
30.0
provides_plain
2.0
auth_plain
2.0
CRAP 13.4
« Server.pm ↑ Summary Server/Command/Check.pm »
1 package Net::IMAP::Server::DefaultAuth;
2  
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 __PACKAGE__->mk_accessors(qw(user));
8  
9 =head1 NAME
10  
11 Net::IMAP::Server::DefaultAuth - Encapsulates per-connection
12 authorization information for an IMAP user.
13  
14 =head1 DESCRIPTION
15  
16 IMAP credentials are passed in one of two ways: using the L<LOGIN>
17 command, or the C<AUTHENTICATE> command. L<LOGIN> sends the password
18 unencrypted; note, however, that L<Net::IMAP::Server> will not allow
19 the LOGIN command unless the connection is protected by either SSL or
20 TLS. Thus, even when the C<LOGIN> command is used, the password is
21 not sent in the clear.
22  
23 The default implementation accepts any username and password. Most
24 subclasses will simply want to override L</auth_plain>, unless they
25 need to implement other forms of authorization than C<LOGIN> or
26 C<AUTHENTICATE PLAIN>.
27  
28 =cut
29  
30 =head1 METHODS
31  
32 =head2 user [VALUE]
33  
34 Gets or sets the plaintext username of the authenticated user.
35  
36 =head2 provides_plain
37  
38 If L</provides_plain> returns true (the default), C<LOGIN> capability
39 will be advertised when under a layer, and L</auth_plain> will be
40 called if the user sends the C<LOGIN> command.
41  
42 =cut
43  
44 0 ▶sub provides_plain { return 1; }
Subroutine provides_plain: not called CC=1 SCAR=6.9
Pod documented
45  
46 =head2 auth_plain USER, PASSWORD
47  
48 Returns true if the given C<USER> is allowed to log in using the
49 provided C<PASSWORD>. This should also set L</user> to the username
50 if login was successful. This path is used by both C<LOGIN> and
51 C<AUTHENTICATE PLAIN> commands.
52  
53 =cut
54  
55 sub auth_plain {
56 0 ▶ my $self = shift;
Subroutine auth_plain: not called CC=1 SCAR=6.9
Pod documented
57 0 my ( $user, $pass ) = @_;
58 0 $self->user($user);
59 0 return 1;
60 }
61  
62 =head2 sasl_provides
63  
64 The C<AUTHENTICATE> command checks that the provided SASL
65 authentication type is in the list that L</sasl_provides> returns. It
66 defaults to only C<PLAIN>.
67  
68 =cut
69  
70 sub sasl_provides {
71 0 ▶ my $self = shift;
Subroutine sasl_provides: not called CC=1 SCAR=6.9
Pod documented
72 0 return ("PLAIN");
73 }
74  
75 =head2 sasl_plain
76  
77 Called when the client requests C<PLAIN> SASL authentication. This
78 parses the SASL protocol, and defers to L</auth_plain> to determine if
79 the username and password is actually allowed to log in.
80  
81 =cut
82  
83 sub sasl_plain {
84 0 ▶ my $self = shift;
Subroutine sasl_plain: not called CC=1 SCAR=6.9
Pod documented
85 return sub {
86 0 ▶ my $line = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
87 0 ▶ return \"" unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
88  
89 0 my ( $authz, $user, $pass ) = split /\x{0}/, $line, 3;
90 0 ▶ return -1 unless defined $authz and defined $user and defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authz and defined $user and defined $pass 0 0 0
Condition0%0/6
defined $authz and defined $user and defined $pass
!ll&&!rl&&r
000
defined $authz and defined $user
!ll&&!rl&&r
000
MC/DC0%0/3
defined $authz and defined $user and defined $pass
defined $authz defined $user defined $pass
Truth table0%0/4
A and B and C
A= defined $authzB= defined $userC= defined $pass
ABCresult
0XX0
10X0
1100
1111
91 0 return $self->auth_plain( $user, $pass );
92 0 };
93 }
94  
95 =head1 IMPLEMENTING NEW SASL METHODS
96  
97 The L</sasl_plain> method is a simple example of implementing a SASL
98 protocol, albeit a very simple one. SASL authentication methods
99 should expect to be called with no arguments, and should return an
100 anonymous function, which will be called each time the client
101 transmits more information.
102  
103 Each time it is called, it will be passed the client data, which will
104 already have been base-64 decoded (the exception being the first time
105 it is called, when it will be called with the empty string).
106  
107 If the function returns a scalar reference, the scalar will be base-64
108 encoded and transmitted to the client. Anything which is not a scalar
109 reference will be interpreted as a boolean, as to whether the
110 authentication was successful. Successful authentications should be
111 sure to set L</user> themselves.
112  
113 =cut
114  
115 13 1;
« Server.pm ↑ Summary Server/Command/Check.pm »