File Coverage

blib/lib/DJabberd/Authen/Dovecot.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package DJabberd::Authen::Dovecot;
4 1     1   682 use strict;
  1         2  
  1         36  
5 1     1   6 use base 'DJabberd::Authen';
  1         2  
  1         512  
6 1     1   350 use DJabberd::Log;
  0            
  0            
7              
8             our $VERSION = '0.1';
9              
10             use Socket;
11             use MIME::Base64;
12              
13             sub set_config_socket {
14             my ($self, $sock) = @_;
15             $self->{sock} = $sock;
16             }
17              
18             sub set_config_realm {
19             my ($self, $realm) = @_;
20             $self->{realm} = $realm;
21             }
22              
23             sub finalize {
24             my $self = shift;
25             $self->{realm} ||= '';
26             $self->{sock} ||="/var/run/dovecot/auth-client";
27             }
28              
29             sub can_retrieve_cleartext { 0 }
30              
31             sub check_cleartext {
32             my $self = shift;
33             my $cb = shift;
34             my %args = @_;
35             my $user=$args{username};
36             my $pass=$args{password};
37             my $ch=encode_base64("\0$user\0$pass");
38             my $auth;
39             socket($auth,PF_UNIX,SOCK_STREAM,0);
40             connect($auth,scalar(sockaddr_un($self->{sock})));
41             my $cpid="CPID\t$$\n";
42             my $data;
43             sysread($auth,$data,1024);
44             my @data=split("\n",$data);
45             while(my $l=shift(@data)) {
46             if($l eq "DONE") {
47             syswrite($auth,"VERSION\t1\t1\n");
48             syswrite($auth,$cpid);
49             syswrite($auth,"AUTH\t1\tPLAIN\tservice=xmpp\tresp=$ch");
50             sysread($auth,$data,1024);
51             @data=split("\n",$data);
52             } elsif($l =~/^FAIL/) {
53             @data=();
54             $cb->reject();
55             } elsif($l =~/^OK/) {
56             @data=();
57             $cb->accept();
58             }
59             }
60             close($auth);
61             return 1;
62             }
63              
64             1;
65              
66             __END__