rewrite DN from login@domain.com into uid=login,dc=domain,dc=com
[virtual-ldap] / lib / LDAP / Virtual.pm
index 3b17bd4..4ee090e 100644 (file)
@@ -20,6 +20,8 @@ use URI::Escape;      # uri_escape
 use IO::Socket::INET;
 use IO::Select;
 
+use YAML qw/DumpFile/;
+
 use Data::Dump qw/dump/;
 
 =head1 NAME
@@ -41,12 +43,6 @@ Provide LDAP server functionality somewhat similar to C<slapo-rwm>
 =cut
 
 our $pids;
-our $cache;
-
-sub cache {
-       return $cache if $cache;
-       $cache = new A3C::Cache->new({ instance => '', dir => 'ldap' });
-}
 
 sub run {
        my $self = shift;
@@ -160,6 +156,14 @@ sub bind {
 
        my $bind;
        $bind->{dn} = $req->{name} if $req->{name};
+
+       if ( $bind->{dn} =~ m{@} ) {
+
+                       $bind->{dn} =~ s/[@\.]/,dc=/g;
+                       $bind->{dn} =~ s/^/uid=/;
+
+       }
+
        $bind->{password} = $req->{authentication}->{simple} if $req->{authentication}->{simple};
        warn "# bind ",dump( $bind );
        $msg = $self->{upstream}->bind( %$bind );
@@ -241,7 +245,9 @@ sub search {
 
        warn "## entries = ",dump( @entries );
 
-       $self->cache->write_cache( \@entries, uri_escape( $filter ));
+       my $path = 'var/' . uri_escape( $filter ) . '.yml';
+       DumpFile( $path, \@entries );
+       warn "# created $path ", -s $path, " bytes";
 
        return RESULT_OK, @entries;
 }