1 |
package VLDAP::Server; |
package LDAP::Virtual; |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
14 |
use base qw(Net::LDAP::Server); |
use base qw(Net::LDAP::Server); |
15 |
use fields qw(upstream); |
use fields qw(upstream); |
16 |
|
|
17 |
|
use Net::LDAP; |
18 |
|
|
19 |
use URI::Escape; # uri_escape |
use URI::Escape; # uri_escape |
20 |
use IO::Socket::INET; |
use IO::Socket::INET; |
21 |
use IO::Select; |
use IO::Select; |
24 |
|
|
25 |
=head1 NAME |
=head1 NAME |
26 |
|
|
27 |
A3C::LDAP::Server |
LDAP::Virtual |
28 |
|
|
29 |
=cut |
=cut |
30 |
|
|
31 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
32 |
|
|
33 |
Provide LDAP server functionality for L<A3C> somewhat similar to C<slapo-rwm> |
Provide LDAP server functionality somewhat similar to C<slapo-rwm> |
34 |
|
|
35 |
=head1 METHODS |
=head1 METHODS |
36 |
|
|
37 |
=head2 run |
=head2 run |
38 |
|
|
39 |
my $pid = A3C::LDAP::Server->run({ port => 1389, fork => 0 }); |
my $pid = LDAP::Virtual->run({ port => 1389, fork => 0 }); |
40 |
|
|
41 |
=cut |
=cut |
42 |
|
|
44 |
our $cache; |
our $cache; |
45 |
|
|
46 |
sub cache { |
sub cache { |
47 |
return $cache if $cache; |
return $cache; |
|
$cache = new A3C::Cache->new({ instance => '', dir => 'ldap' }); |
|
48 |
} |
} |
49 |
|
|
50 |
sub run { |
sub run { |
81 |
# let's create a new socket |
# let's create a new socket |
82 |
my $psock = $sock->accept; |
my $psock = $sock->accept; |
83 |
$sel->add($psock); |
$sel->add($psock); |
84 |
$Handlers{*$psock} = A3C::LDAP::Server->new($psock); |
$Handlers{*$psock} = LDAP::Virtual->new($psock); |
85 |
} else { |
} else { |
86 |
my $result = $Handlers{*$fh}->handle; |
my $result = $Handlers{*$fh}->handle; |
87 |
if ($result) { |
if ($result) { |
97 |
|
|
98 |
=head2 stop |
=head2 stop |
99 |
|
|
100 |
my $stopped_pids = A3C::LDAP::Server->stop; |
my $stopped_pids = LDAP::Virtual->stop; |
101 |
|
|
102 |
=cut |
=cut |
103 |
|
|
142 |
resultCode => LDAP_STRONG_AUTH_NOT_SUPPORTED, |
resultCode => LDAP_STRONG_AUTH_NOT_SUPPORTED, |
143 |
}; |
}; |
144 |
|
|
145 |
$self->{upstream} ||= A3C::LDAP->new->ldap or return { |
$self->{upstream} ||= Net::LDAP->new( 'ldaps://ldap.ffzg.hr/' ) or return { |
146 |
matchedDN => '', |
matchedDN => '', |
147 |
errorMessage => $@, |
errorMessage => $@, |
148 |
resultCode => LDAP_UNAVAILABLE, |
resultCode => LDAP_UNAVAILABLE, |
149 |
}; |
}; |
150 |
|
|
151 |
# warn "## upstream = ",dump( $self->{upstream} ); |
warn "## upstream = ",dump( $self->{upstream} ); |
152 |
# warn "upstream not Net::LDAP but ",ref($self->{upstream}) unless ref($self->{upstream}) eq 'Net::LDAP'; |
warn "upstream not Net::LDAP but ",ref($self->{upstream}) unless ref($self->{upstream}) eq 'Net::LDAP'; |
153 |
|
|
154 |
my $msg; |
my $msg; |
155 |
|
|
156 |
# FIXME we would need to unbind because A3C::LDAP binds us automatically, but that doesn't really work |
# FIXME we would need to unbind because VLDAP binds us automatically, but that doesn't really work |
157 |
#$msg = $self->{upstream}->unbind; |
#$msg = $self->{upstream}->unbind; |
158 |
#warn "# unbind msg = ",dump( $msg ); |
#warn "# unbind msg = ",dump( $msg ); |
159 |
|
|
160 |
$msg = $self->{upstream}->bind( |
my $bind; |
161 |
dn => $req->{name}, |
$bind->{dn} = $req->{name} if $req->{name}; |
162 |
password => $req->{authentication}->{simple} |
$bind->{password} = $req->{authentication}->{simple} if $req->{authentication}->{simple}; |
163 |
); |
warn "# bind ",dump( $bind ); |
164 |
|
$msg = $self->{upstream}->bind( %$bind ); |
165 |
|
|
166 |
#warn "# bind msg = ",dump( $msg ); |
#warn "# bind msg = ",dump( $msg ); |
167 |
if ( $msg->code != LDAP_SUCCESS ) { |
if ( $msg->code != LDAP_SUCCESS ) { |
240 |
|
|
241 |
warn "## entries = ",dump( @entries ); |
warn "## entries = ",dump( @entries ); |
242 |
|
|
243 |
$self->cache->write_cache( \@entries, uri_escape( $filter )); |
# $self->cache->write_cache( \@entries, uri_escape( $filter )); |
244 |
|
|
245 |
return RESULT_OK, @entries; |
return RESULT_OK, @entries; |
246 |
} |
} |