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
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1489
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
141
|
|
8
|
4
|
|
|
4
|
|
20
|
use vars qw($VERSION @ISA); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
3187
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = "2.14"; |
11
|
|
|
|
|
|
|
@ISA = qw(Authen::SASL::Perl); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %secflags = ( |
14
|
|
|
|
|
|
|
noanonymous => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
36
|
|
|
36
|
|
226
|
sub _order { 1 } |
18
|
|
|
|
|
|
|
sub _secflags { |
19
|
18
|
|
|
18
|
|
30
|
shift; |
20
|
18
|
|
|
|
|
135
|
scalar grep { $secflags{$_} } @_; |
|
0
|
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
5
|
0
|
727
|
sub mechanism { 'LOGIN' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub client_start { |
26
|
4
|
|
|
4
|
0
|
20
|
my $self = shift; |
27
|
4
|
|
|
|
|
10
|
$self->{stage} = 0; |
28
|
4
|
|
|
|
|
14
|
''; |
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
|
|
|
|
|
18
|
my $stage = ++$self->{stage}; |
39
|
9
|
100
|
|
|
|
34
|
if ($stage == 1) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
40
|
4
|
|
|
|
|
23
|
return $self->_call('user'); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ($stage == 2) { |
43
|
4
|
|
|
|
|
13
|
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
|
52
|
my $self = shift; |
56
|
9
|
|
|
|
|
12
|
my $response = shift; |
57
|
9
|
|
50
|
0
|
|
22
|
my $user_cb = shift || sub {}; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
|
59
|
9
|
|
|
|
|
19
|
$self->{answer} = {}; |
60
|
9
|
|
|
|
|
18
|
$self->{stage} = 0; |
61
|
9
|
|
|
|
|
15
|
$self->{need_step} = 1; |
62
|
9
|
|
|
|
|
18
|
$self->{error} = undef; |
63
|
9
|
|
|
|
|
26
|
$user_cb->('Username:'); |
64
|
9
|
|
|
|
|
30
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub server_step { |
68
|
15
|
|
|
15
|
0
|
2831
|
my $self = shift; |
69
|
15
|
|
|
|
|
22
|
my $response = shift; |
70
|
15
|
|
50
|
0
|
|
33
|
my $user_cb = shift || sub {}; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
15
|
|
|
|
|
24
|
my $stage = ++$self->{stage}; |
73
|
|
|
|
|
|
|
|
74
|
15
|
100
|
|
|
|
40
|
if ($stage == 1) { |
|
|
50
|
|
|
|
|
|
75
|
8
|
50
|
|
|
|
15
|
unless (defined $response) { |
76
|
0
|
|
|
|
|
0
|
$self->set_error("Invalid sequence (empty username)"); |
77
|
0
|
|
|
|
|
0
|
return $user_cb->(); |
78
|
|
|
|
|
|
|
} |
79
|
8
|
|
|
|
|
18
|
$self->{answer}{user} = $response; |
80
|
8
|
|
|
|
|
31
|
return $user_cb->("Password:"); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ($stage == 2) { |
83
|
7
|
50
|
|
|
|
15
|
unless (defined $response) { |
84
|
0
|
|
|
|
|
0
|
$self->set_error("Invalid sequence (empty pass)"); |
85
|
0
|
|
|
|
|
0
|
return $user_cb->(); |
86
|
|
|
|
|
|
|
} |
87
|
7
|
|
|
|
|
17
|
$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
|
|
|
|
|
10
|
my $error = "Credentials don't match"; |
94
|
7
|
|
|
|
|
28
|
my $answers = { user => $self->{answer}{user}, pass => $self->{answer}{pass} }; |
95
|
7
|
100
|
|
|
|
32
|
if (my $checkpass = $self->{callback}{checkpass}) { |
|
|
50
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $cb = sub { |
97
|
2
|
|
|
2
|
|
1041
|
my $result = shift; |
98
|
2
|
100
|
|
|
|
4846
|
unless ($result) { |
99
|
1
|
|
|
|
|
6
|
$self->set_error($error); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
1
|
|
|
|
|
5
|
$self->set_success; |
103
|
|
|
|
|
|
|
} |
104
|
2
|
|
|
|
|
7
|
$user_cb->(); |
105
|
2
|
|
|
|
|
11
|
}; |
106
|
2
|
|
|
|
|
13
|
$checkpass->($self => $answers => $cb ); |
107
|
2
|
|
|
|
|
386
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif (my $getsecret = $self->{callback}{getsecret}) { |
110
|
|
|
|
|
|
|
my $cb = sub { |
111
|
5
|
|
|
5
|
|
25
|
my $good_pass = shift; |
112
|
5
|
100
|
50
|
|
|
38
|
if ($good_pass && $good_pass eq ($self->{answer}{pass} || "")) { |
|
|
|
66
|
|
|
|
|
113
|
2
|
|
|
|
|
19
|
$self->set_success; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
else { |
116
|
3
|
|
|
|
|
20
|
$self->set_error($error); |
117
|
|
|
|
|
|
|
} |
118
|
5
|
|
|
|
|
14
|
$user_cb->(); |
119
|
5
|
|
|
|
|
20
|
}; |
120
|
5
|
|
|
|
|
13
|
$getsecret->($self => $answers => $cb ); |
121
|
5
|
|
|
|
|
39
|
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__ |