line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
# # |
3
|
|
|
|
|
|
|
# Sasl Auth Daemon Client module for Perl # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# Author: Piotr Klaban (c)2001 |
6
|
|
|
|
|
|
|
# All Rights Reserved. See the Perl Artistic License for copying & usage # |
7
|
|
|
|
|
|
|
# policy. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# See the file 'Changes' in the distrution archive. # |
10
|
|
|
|
|
|
|
# # |
11
|
|
|
|
|
|
|
############################################################################# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Authen::CyrusSASL; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
1756
|
use IO::Socket; |
|
1
|
|
|
|
|
36641
|
|
|
1
|
|
|
|
|
5
|
|
16
|
1
|
|
|
1
|
|
253954
|
use IO::Select; |
|
1
|
|
|
|
|
2032
|
|
|
1
|
|
|
|
|
75
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION @ISA @EXPORT); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
727
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
21
|
|
|
|
|
|
|
require AutoLoader; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
24
|
|
|
|
|
|
|
@EXPORT = qw(SASL_OK SASL_BADAUTH SASL_FAIL SASL_PWCHECK SASL_AUTHD); |
25
|
|
|
|
|
|
|
$VERSION = '0.01'; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
0
|
0
|
sub SASL_OK { 0; } # values from the sasl.h cyrus-sasl's file |
28
|
0
|
|
|
0
|
0
|
0
|
sub SASL_BADAUTH { -13; } |
29
|
0
|
|
|
0
|
0
|
0
|
sub SASL_FAIL { -1; } |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
1
|
0
|
sub SASL_PWCHECK { 1; } |
32
|
2
|
|
|
2
|
1
|
57
|
sub SASL_AUTHD { 2; } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
1
|
|
|
1
|
1
|
28
|
my $class = shift; |
36
|
1
|
|
|
|
|
6
|
my %h = @_; |
37
|
1
|
|
|
|
|
2
|
my ($pwpath); |
38
|
1
|
|
|
|
|
3
|
my $self = {}; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
bless $self, $class; |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
6
|
if (!defined($h{'Type'})) { |
43
|
0
|
|
|
|
|
0
|
die('Define Type attribute for Authen::CyrusSASL object'); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# default values |
47
|
1
|
0
|
|
|
|
4
|
my ($sock_type, $def_dir, $def_file) = |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
($h{'Type'} == SASL_AUTHD) ? (SOCK_STREAM, '/var/run/saslauthd', 'mux') |
49
|
|
|
|
|
|
|
: ($h{'Type'} == SASL_PWCHECK) ? (SOCK_DGRAM, '/var/run/pwcheck', 'pwcheck') |
50
|
|
|
|
|
|
|
: die ('Unknown Authen::CyrusSASL object type, use SASL_AUTHD or SASL_PWCHECK'); |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
5
|
$h{'Dir'} = $def_dir if not defined $h{'Dir'}; |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
33
|
|
|
170
|
if (defined($h{'Dir'}) && !-d $h{'Dir'}) { |
55
|
1
|
|
|
|
|
9
|
$! = 'Directory ' . $h{'Dir'} . ': not found'; |
56
|
1
|
|
|
|
|
17
|
return undef; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
$h{'Path'} = $h{'Dir'} . '/' . $def_file if not defined $h{'Path'}; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$pwpath = $h{'Path'}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (!-e $pwpath) { |
64
|
0
|
|
|
|
|
|
$! = 'File ' . $pwpath . ': file not found'; |
65
|
0
|
|
|
|
|
|
return undef; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->{'type'} = $h{'Type'}; |
69
|
0
|
0
|
|
|
|
|
$self->{'timeout'} = $h{'TimeOut'} ? $h{'TimeOut'} : 5; |
70
|
0
|
0
|
|
|
|
|
$self->{'sock'} = new IO::Socket::UNIX( |
71
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
72
|
|
|
|
|
|
|
Peer => $pwpath |
73
|
|
|
|
|
|
|
) or return undef; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub check_pwd { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $pwd) = @_; |
80
|
0
|
|
|
|
|
|
my ($req, $res, $sh); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$req = "$name\0$pwd\0"; |
83
|
0
|
|
|
|
|
|
$res = ' ' x 1024; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# send request |
86
|
0
|
0
|
|
|
|
|
$self->{'sock'}->send ($req) || return SASL_FAIL; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# recv response |
89
|
0
|
0
|
|
|
|
|
$sh = new IO::Select($self->{'sock'}) or return SASL_FAIL; |
90
|
0
|
0
|
|
|
|
|
$sh->can_read($self->{'timeout'}) or return SASL_FAIL; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
recv( $self->{'sock'}, $res, 1024, 0 ); |
93
|
|
|
|
|
|
|
# sock->recv does not work |
94
|
|
|
|
|
|
|
#$self->{'sock'}->recv ($res, 1024, 0) or return SASL_FAIL; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if (substr($res, 0, 2) ne 'OK') { |
97
|
0
|
|
|
|
|
|
$! = substr($res, 3); |
98
|
0
|
|
|
|
|
|
return SASL_BADAUTH; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return SASL_OK; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |