File Coverage

blib/lib/Authen/SASL/Perl/LOGIN.pm
Criterion Covered Total %
statement 61 72 84.7
branch 17 22 77.2
condition 5 11 45.4
subroutine 12 14 85.7
pod 0 5 0.0
total 95 124 76.6


line stmt bran cond sub pod time code
1             # Copyright (c) 2002 Graham Barr . All rights reserved.
2             # This program is free software; you can redistribute it and/or
3             # modify it under the same terms as Perl itself.
4              
5             package Authen::SASL::Perl::LOGIN 2.2000;
6              
7 4     4   283277 use strict;
  4         11  
  4         191  
8 4     4   34 use warnings;
  4         7  
  4         270  
9 4     4   23 use vars qw(@ISA);
  4         8  
  4         3772  
10              
11             @ISA = qw(Authen::SASL::Perl);
12              
13             my %secflags = (
14             noanonymous => 1,
15             );
16              
17 54     54   131 sub _order { 1 }
18             sub _secflags {
19 18     18   34 shift;
20 18         92 scalar grep { $secflags{$_} } @_;
  0         0  
21             }
22              
23 6     6 0 800 sub mechanism { 'LOGIN' }
24              
25             sub client_start {
26 4     4 0 18 my $self = shift;
27 4         9 $self->{stage} = 0;
28 4         13 '';
29             }
30              
31             sub client_step {
32 9     9 0 30 my ($self, $string) = @_;
33              
34             # XXX technically this is wrong. I might want to change that.
35             # spec say it's "staged" and that the content of the challenge doesn't
36             # matter
37             # actually, let's try
38 9         13 my $stage = ++$self->{stage};
39 9 100       56 if ($stage == 1) {
    100          
    50          
40 4         20 return $self->_call('user');
41             }
42             elsif ($stage == 2) {
43 4         12 return $self->_call('pass');
44             }
45             elsif ($stage == 3) {
46 1         4 $self->set_success;
47 1         3 return;
48             }
49             else {
50 0         0 return $self->set_error("Invalid sequence");
51             }
52             }
53              
54             sub server_start {
55 9     9 0 72 my $self = shift;
56 9         18 my $response = shift;
57 9   33 0   26 my $user_cb = shift || sub {};
58              
59 9         27 $self->{answer} = {};
60 9         23 $self->{stage} = 0;
61 9         17 $self->{need_step} = 1;
62 9         21 $self->{error} = undef;
63 9         65 $user_cb->('Username:');
64 9         42 return;
65             }
66              
67             sub server_step {
68 15     15 0 1788 my $self = shift;
69 15         43 my $response = shift;
70 15   33 0   44 my $user_cb = shift || sub {};
71              
72 15         31 my $stage = ++$self->{stage};
73              
74 15 100       58 if ($stage == 1) {
    50          
75 8 50       21 unless (defined $response) {
76 0         0 $self->set_error("Invalid sequence (empty username)");
77 0         0 return $user_cb->();
78             }
79 8         24 $self->{answer}{user} = $response;
80 8         20 return $user_cb->("Password:");
81             }
82             elsif ($stage == 2) {
83 7 50       20 unless (defined $response) {
84 0         0 $self->set_error("Invalid sequence (empty pass)");
85 0         0 return $user_cb->();
86             }
87 7         52 $self->{answer}{pass} = $response;
88             }
89             else {
90 0         0 $self->set_error("Invalid sequence (end)");
91 0         0 return $user_cb->();
92             }
93 7         17 my $error = "Credentials don't match";
94 7         27 my $answers = { user => $self->{answer}{user}, pass => $self->{answer}{pass} };
95 7 100       29 if (my $checkpass = $self->{callback}{checkpass}) {
    50          
96             my $cb = sub {
97 2     2   1977 my $result = shift;
98 2 100       7 unless ($result) {
99 1         4 $self->set_error($error);
100             }
101             else {
102 1         5 $self->set_success;
103             }
104 2         9 $user_cb->();
105 2         12 };
106 2         10 $checkpass->($self => $answers => $cb );
107 2         19 return;
108             }
109             elsif (my $getsecret = $self->{callback}{getsecret}) {
110             my $cb = sub {
111 5     5   26 my $good_pass = shift;
112 5 100 50     52 if ($good_pass && $good_pass eq ($self->{answer}{pass} || "")) {
      66        
113 2         20 $self->set_success;
114             }
115             else {
116 3         22 $self->set_error($error);
117             }
118 5         11 $user_cb->();
119 5         31 };
120 5         23 $getsecret->($self => $answers => $cb );
121 5         45 return;
122             }
123             else {
124 0           $self->set_error($error);
125 0           $user_cb->();
126             }
127 0           return;
128             }
129              
130             1;
131              
132             __END__