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 |
|
|
45 |
our $pids; |
our $pids; |
|
our $cache; |
|
|
|
|
|
sub cache { |
|
|
return $cache if $cache; |
|
|
$cache = new A3C::Cache->new({ instance => '', dir => 'ldap' }); |
|
|
} |
|
46 |
|
|
47 |
sub run { |
sub run { |
48 |
my $self = shift; |
my $self = shift; |
78 |
# let's create a new socket |
# let's create a new socket |
79 |
my $psock = $sock->accept; |
my $psock = $sock->accept; |
80 |
$sel->add($psock); |
$sel->add($psock); |
81 |
$Handlers{*$psock} = VLDAP::Server->new($psock); |
$Handlers{*$psock} = LDAP::Virtual->new($psock); |
82 |
} else { |
} else { |
83 |
my $result = $Handlers{*$fh}->handle; |
my $result = $Handlers{*$fh}->handle; |
84 |
if ($result) { |
if ($result) { |
94 |
|
|
95 |
=head2 stop |
=head2 stop |
96 |
|
|
97 |
my $stopped_pids = VLDAP::Server->stop; |
my $stopped_pids = LDAP::Virtual->stop; |
98 |
|
|
99 |
=cut |
=cut |
100 |
|
|
154 |
#$msg = $self->{upstream}->unbind; |
#$msg = $self->{upstream}->unbind; |
155 |
#warn "# unbind msg = ",dump( $msg ); |
#warn "# unbind msg = ",dump( $msg ); |
156 |
|
|
157 |
$msg = $self->{upstream}->bind( |
my $bind; |
158 |
dn => $req->{name}, |
$bind->{dn} = $req->{name} if $req->{name}; |
159 |
password => $req->{authentication}->{simple} |
$bind->{password} = $req->{authentication}->{simple} if $req->{authentication}->{simple}; |
160 |
); |
warn "# bind ",dump( $bind ); |
161 |
|
$msg = $self->{upstream}->bind( %$bind ); |
162 |
|
|
163 |
#warn "# bind msg = ",dump( $msg ); |
#warn "# bind msg = ",dump( $msg ); |
164 |
if ( $msg->code != LDAP_SUCCESS ) { |
if ( $msg->code != LDAP_SUCCESS ) { |
237 |
|
|
238 |
warn "## entries = ",dump( @entries ); |
warn "## entries = ",dump( @entries ); |
239 |
|
|
240 |
$self->cache->write_cache( \@entries, uri_escape( $filter )); |
my $path = 'var/' . uri_escape( $filter ) . '.yml'; |
241 |
|
DumpFile( $path, \@entries ); |
242 |
|
warn "# created $path ", -s $path, " bytes"; |
243 |
|
|
244 |
return RESULT_OK, @entries; |
return RESULT_OK, @entries; |
245 |
} |
} |