/[virtual-ldap]/bin/ldap-rewrite.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/ldap-rewrite.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 16 by dpavlin, Sun Mar 15 21:20:35 2009 UTC revision 27 by dpavlin, Mon Mar 16 18:11:12 2009 UTC
# Line 18  our $VERSION = '0.2'; Line 18  our $VERSION = '0.2';
18  use fields qw(socket target);  use fields qw(socket target);
19  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
20    
21    my $config = {
22            yaml_dir => './yaml/',
23            listen => 'localhost:1389',
24            upstream_ldap => 'ldap.ffzg.hr',
25            upstream_ssl => 1,
26            overlay_prefix => 'ffzg-',
27            log_file => 'log',
28    
29    };
30    
31    my $log_fh;
32    
33    sub log {
34            open($log_fh, '>', $config->{log_file}) || die "can't open ", $config->{log_file},": $!";
35            $log_fh->autoflush(1);
36            print $log_fh join("\n", @_),"\n";
37    }
38    
39    BEGIN {
40            $SIG{'__WARN__'} = sub { warn @_; main::log(@_); }
41    }
42    
43    
44    if ( ! -d $config->{yaml_dir} ) {
45            warn "DISABLE ", $config->{yaml_dir}," data overlay";
46    }
47    
48    warn "# config = ",dump( $config );
49    
50  sub handle {  sub handle {
51          my $clientsocket=shift;          my $clientsocket=shift;
52          my $serversocket=shift;          my $serversocket=shift;
# Line 69  sub log_response { Line 98  sub log_response {
98                  my $uid = $response->{protocolOp}->{searchResEntry}->{objectName};                  my $uid = $response->{protocolOp}->{searchResEntry}->{objectName};
99                  warn "## SEARCH $uid";                  warn "## SEARCH $uid";
100    
101  if(0) {                  my @attrs;
102    
103                  map {                  map {
104                          if ( $_->{type} eq 'postalAddress' ) {                          if ( $_->{type} eq 'hrEduPersonUniqueNumber' ) {
105                                  $_->{vals} = [ 'foobar' ];                                  foreach my $val ( @{ $_->{vals} } ) {
106                                            next if $val !~ m{.+:.+};
107                                            my ( $n, $v ) = split(/\s*:\s*/, $val );
108                                            push @attrs, { type => $_->{type} . '_' . $n, vals => [ $v ] };
109                                    }
110                          }                          }
111                  } @{ $response->{protocolOp}->{searchResEntry}->{attributes} };                  } @{ $response->{protocolOp}->{searchResEntry}->{attributes} };
 }  
112    
113                  my $path = "yaml/$uid.yaml";                  warn "# ++ attrs ",dump( @attrs );
114    
115                    push @{ $response->{protocolOp}->{searchResEntry}->{attributes} }, $_ foreach @attrs;
116    
117                    my $path = $config->{yaml_dir} . "$uid.yaml";
118                  if ( -e $path ) {                  if ( -e $path ) {
119                          my $data = LoadFile($path);                          my $data = LoadFile($path);
120                          warn "# yaml = ",dump($data);                          warn "# yaml = ",dump($data);
# Line 85  if(0) { Line 122  if(0) {
122                          foreach my $type ( keys %$data ) {                          foreach my $type ( keys %$data ) {
123    
124                                  my $vals = $data->{$type};                                  my $vals = $data->{$type};
                                 $vals =~ s{#\s*$}{};  
                                   
                                 my @vals = split(/\s*#\s*/, $vals);  
125    
126                                  push @{ $response->{protocolOp}->{searchResEntry}->{attributes} },                                  push @{ $response->{protocolOp}->{searchResEntry}->{attributes} }, {
127                                          { type => "ffzg-$type", vals => [ @vals ] };                                          type => $config->{overlay_prefix} . $type,
128                                            vals => ref($vals) eq 'ARRAY' ? $vals : [ $vals ],
129                                    };
130                          }                          }
131                  }                  }
132    
# Line 131  sub run_proxy { Line 167  sub run_proxy {
167  }  }
168    
169    
170    $ENV{LANG} = 'C'; # so we don't double-encode utf-8 if LANG is utf-8
171    
172  my $listenersock = IO::Socket::INET->new(  my $listenersock = IO::Socket::INET->new(
173          Listen => 5,          Listen => 5,
174          Proto => 'tcp',          Proto => 'tcp',
175          Reuse => 1,          Reuse => 1,
176          LocalPort => 1389          LocalAddr => $config->{listen},
177  );  );
178    
179    
180  my $targetsock = new IO::Socket::INET (  my $targetsock = $config->{upstream_ssl}
181          Proto => 'tcp',          ? IO::Socket::INET->new(
182          PeerAddr => 'ldap.ffzg.hr',                  Proto => 'tcp',
183          PeerPort => 389,                  PeerAddr => $config->{upstream_ldap},
184  );                  PeerPort => 389,
185            )
186  $targetsock = IO::Socket::SSL->new("ldap.ffzg.hr:ldaps");          : IO::Socket::SSL->new( $config->{upstream_ldap} . ':ldaps')
187            ;
188    
189  run_proxy($listenersock,$targetsock);  run_proxy($listenersock,$targetsock);
190    

Legend:
Removed from v.16  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26