1 |
package VLDAP::Server; |
package LDAP::Virtual; |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
20 |
use IO::Socket::INET; |
use IO::Socket::INET; |
21 |
use IO::Select; |
use IO::Select; |
22 |
|
|
23 |
|
use YAML qw/DumpFile/; |
24 |
|
|
25 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
26 |
|
|
27 |
=head1 NAME |
=head1 NAME |
28 |
|
|
29 |
VLDAP::Server |
LDAP::Virtual |
30 |
|
|
31 |
=cut |
=cut |
32 |
|
|
38 |
|
|
39 |
=head2 run |
=head2 run |
40 |
|
|
41 |
my $pid = VLDAP::Server->run({ port => 1389, fork => 0 }); |
my $pid = LDAP::Virtual->run({ port => 1389, fork => 0 }); |
42 |
|
|
43 |
=cut |
=cut |
44 |
|
|
46 |
our $cache; |
our $cache; |
47 |
|
|
48 |
sub cache { |
sub cache { |
49 |
return $cache if $cache; |
return $cache; |
|
$cache = new A3C::Cache->new({ instance => '', dir => 'ldap' }); |
|
50 |
} |
} |
51 |
|
|
52 |
sub run { |
sub run { |
83 |
# let's create a new socket |
# let's create a new socket |
84 |
my $psock = $sock->accept; |
my $psock = $sock->accept; |
85 |
$sel->add($psock); |
$sel->add($psock); |
86 |
$Handlers{*$psock} = VLDAP::Server->new($psock); |
$Handlers{*$psock} = LDAP::Virtual->new($psock); |
87 |
} else { |
} else { |
88 |
my $result = $Handlers{*$fh}->handle; |
my $result = $Handlers{*$fh}->handle; |
89 |
if ($result) { |
if ($result) { |
99 |
|
|
100 |
=head2 stop |
=head2 stop |
101 |
|
|
102 |
my $stopped_pids = VLDAP::Server->stop; |
my $stopped_pids = LDAP::Virtual->stop; |
103 |
|
|
104 |
=cut |
=cut |
105 |
|
|
159 |
#$msg = $self->{upstream}->unbind; |
#$msg = $self->{upstream}->unbind; |
160 |
#warn "# unbind msg = ",dump( $msg ); |
#warn "# unbind msg = ",dump( $msg ); |
161 |
|
|
162 |
$msg = $self->{upstream}->bind( |
my $bind; |
163 |
dn => $req->{name}, |
$bind->{dn} = $req->{name} if $req->{name}; |
164 |
password => $req->{authentication}->{simple} |
$bind->{password} = $req->{authentication}->{simple} if $req->{authentication}->{simple}; |
165 |
); |
warn "# bind ",dump( $bind ); |
166 |
|
$msg = $self->{upstream}->bind( %$bind ); |
167 |
|
|
168 |
#warn "# bind msg = ",dump( $msg ); |
#warn "# bind msg = ",dump( $msg ); |
169 |
if ( $msg->code != LDAP_SUCCESS ) { |
if ( $msg->code != LDAP_SUCCESS ) { |
242 |
|
|
243 |
warn "## entries = ",dump( @entries ); |
warn "## entries = ",dump( @entries ); |
244 |
|
|
245 |
$self->cache->write_cache( \@entries, uri_escape( $filter )); |
# $self->cache->write_cache( \@entries, uri_escape( $filter )); |
246 |
|
|
247 |
|
my $path = uri_escape( $filter ); |
248 |
|
DumpFile( "var/${path}.yml", \@entries ); |
249 |
|
warn "# created $path ", -s $path, " bytes"; |
250 |
|
|
251 |
return RESULT_OK, @entries; |
return RESULT_OK, @entries; |
252 |
} |
} |