Fugu/LDAP.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 64 CC 5 SCAR 21.6
CC
5
Cov
0%
run
20.0
bind
6.0
new
2.0
CRAP 8.7
1 use strict;
2 use warnings;
3  
4 package App::Squid::Redirector::Fugu::LDAP;
5  
6 use Net::LDAP;
7  
8  
9 sub new {
10 my $class = shift;
11 return bless({}, $class);
12 }
13  
14 sub bind {
15 my($self, $dn, $password) = @_;
16
17 if($dn && $password) {
18 $self->{conn}->bind($dn, password => $password);
19 } else {
20 # anonymous bind
21 $self->{conn}->bind();
22 }
23 }
24  
25 sub run {
26 my($self, $fn, %attrs) = @_;
27  
28 my $mesg;
29  
30 if($attrs{base} && $attrs{filter}) {
31
32 # default scope
33 $attrs{scope} = 'subtree' unless($attrs{scope});
34
35 # default attr
36 $attrs{attr} = 'sAMAccountName' unless($attrs{attr});
37
38 $mesg = $self->{conn}->search(
39 base => $attrs{base},
40 scope => $attrs{scope},
41 filter => $attrs{filter},
42 attrs => [$attrs{attr}]
43 );
44 }
45
46 # function will receive mesg as param
47 &$fn($mesg);
48  
49 }
50  
51 sub set_logger {
52 my($self, $logger) = @_;
53 $self->{logger} = $logger;
54 }
55  
56 sub set_server {
57 my($self, $server) = @_;
58 $self->{conn} = Net::LDAP->new($server) or $self->{logger}->die("Unable to connecto to ldap server $server: $@");
59 }
60  
61 1;