line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2004-2006 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; |
6
|
|
|
|
|
|
|
$Authen::SASL::VERSION = '2.1700'; # TRIAL |
7
|
16
|
|
|
16
|
|
1055703
|
use strict; |
|
16
|
|
|
|
|
174
|
|
|
16
|
|
|
|
|
495
|
|
8
|
16
|
|
|
16
|
|
83
|
use warnings; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
514
|
|
9
|
16
|
|
|
16
|
|
174
|
use vars qw($VERSION @Plugins); |
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
955
|
|
10
|
16
|
|
|
16
|
|
92
|
use Carp; |
|
16
|
|
|
|
|
54
|
|
|
16
|
|
|
|
|
16011
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = "2.16"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@Plugins = qw( |
15
|
|
|
|
|
|
|
Authen::SASL::XS |
16
|
|
|
|
|
|
|
Authen::SASL::Cyrus |
17
|
|
|
|
|
|
|
Authen::SASL::Perl |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub import { |
22
|
18
|
|
|
18
|
|
1110
|
shift; |
23
|
18
|
100
|
|
|
|
1452
|
return unless @_; |
24
|
|
|
|
|
|
|
|
25
|
17
|
|
|
|
|
80
|
local $SIG{__DIE__}; |
26
|
17
|
50
|
|
|
|
47
|
@Plugins = grep { /^[:\w]+$/ and eval "require $_" } map { /::/ ? $_ : "Authen::SASL::$_" } @_ |
|
17
|
50
|
|
|
|
1114
|
|
|
17
|
50
|
|
|
|
146
|
|
27
|
|
|
|
|
|
|
or croak "no valid Authen::SASL plugins found"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
53
|
|
|
53
|
1
|
21124
|
my $pkg = shift; |
33
|
53
|
100
|
|
|
|
312
|
my %opt = ((@_ % 2 ? 'mechanism' : ()), @_); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $self = bless { |
36
|
|
|
|
|
|
|
mechanism => $opt{mechanism} || $opt{mech}, |
37
|
|
|
|
|
|
|
callback => {}, |
38
|
|
|
|
|
|
|
debug => $opt{debug}, |
39
|
53
|
|
100
|
|
|
294
|
}, $pkg; |
40
|
|
|
|
|
|
|
|
41
|
53
|
100
|
|
|
|
193
|
$self->callback(%{$opt{callback}}) if ref($opt{callback}) eq 'HASH'; |
|
49
|
|
|
|
|
235
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Compat |
44
|
53
|
50
|
|
|
|
165
|
$self->callback(user => ($self->{user} = $opt{user})) if exists $opt{user}; |
45
|
53
|
100
|
|
|
|
142
|
$self->callback(pass => $opt{password}) if exists $opt{password}; |
46
|
53
|
50
|
|
|
|
124
|
$self->callback(pass => $opt{response}) if exists $opt{response}; |
47
|
|
|
|
|
|
|
|
48
|
53
|
|
|
|
|
191
|
$self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub mechanism { |
53
|
80
|
|
|
80
|
1
|
8819
|
my $self = shift; |
54
|
|
|
|
|
|
|
@_ ? $self->{mechanism} = shift |
55
|
80
|
50
|
|
|
|
459
|
: $self->{mechanism}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub callback { |
59
|
106
|
|
|
106
|
1
|
172
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
106
|
50
|
|
|
|
263
|
return $self->{callback}{$_[0]} if @_ == 1; |
62
|
|
|
|
|
|
|
|
63
|
106
|
|
|
|
|
244
|
my %new = @_; |
64
|
106
|
|
|
|
|
230
|
@{$self->{callback}}{keys %new} = values %new; |
|
106
|
|
|
|
|
314
|
|
65
|
|
|
|
|
|
|
|
66
|
106
|
|
|
|
|
792
|
$self->{callback}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# The list of packages should not really be hardcoded here |
70
|
|
|
|
|
|
|
# We need some way to discover what plugins are installed |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub client_new { # $self, $service, $host, $secflags |
73
|
36
|
|
|
36
|
1
|
111
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
36
|
|
|
|
|
56
|
my $err; |
76
|
36
|
|
|
|
|
116
|
foreach my $pkg (@Plugins) { |
77
|
38
|
100
|
66
|
|
|
2128
|
if (eval "require $pkg" and $pkg->can("client_new")) { |
78
|
36
|
50
|
|
|
|
82
|
if ($self->{conn} = eval { $pkg->client_new($self, @_) }) { |
|
36
|
|
|
|
|
135
|
|
79
|
36
|
|
|
|
|
190
|
return $self->{conn}; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
0
|
$err = $@; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
0
|
|
|
0
|
croak $err || "Cannot find a SASL Connection library"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub server_new { # $self, $service, $host, $secflags |
89
|
18
|
|
|
18
|
1
|
4232
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
18
|
|
|
|
|
32
|
my $err; |
92
|
18
|
|
|
|
|
45
|
foreach my $pkg (@Plugins) { |
93
|
18
|
50
|
33
|
|
|
977
|
if (eval "require $pkg" and $pkg->can("server_new")) { |
94
|
18
|
50
|
|
|
|
38
|
if ($self->{conn} = eval { $pkg->server_new($self, @_) } ) { |
|
18
|
|
|
|
|
65
|
|
95
|
18
|
|
|
|
|
129
|
return $self->{conn}; |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
0
|
$err = $@; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
0
|
|
|
0
|
croak $err || "Cannot find a SASL Connection library for server-side authentication"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub error { |
104
|
1
|
|
|
1
|
1
|
412
|
my $self = shift; |
105
|
1
|
50
|
|
|
|
8
|
$self->{conn} && $self->{conn}->error; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Compat. |
109
|
|
|
|
|
|
|
sub user { |
110
|
3
|
|
|
3
|
0
|
15
|
my $self = shift; |
111
|
3
|
|
|
|
|
9
|
my $user = $self->{callback}{user}; |
112
|
3
|
100
|
|
|
|
9
|
$self->{callback}{user} = shift if @_; |
113
|
3
|
|
|
|
|
13
|
$user; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub challenge { |
117
|
1
|
|
|
1
|
0
|
534
|
my $self = shift; |
118
|
1
|
|
|
|
|
6
|
$self->{conn}->client_step(@_); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub initial { |
122
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
123
|
1
|
|
|
|
|
4
|
$self->client_new($self)->client_start; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub name { |
127
|
3
|
|
|
3
|
0
|
574
|
my $self = shift; |
128
|
3
|
100
|
100
|
|
|
28
|
$self->{conn} ? $self->{conn}->mechanism : (($self->{mechanism} || '') =~ /(\S+)/)[0]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |