File Coverage

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


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