/[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 60 by dpavlin, Wed Mar 25 21:24:33 2009 UTC revision 61 by dpavlin, Sun Dec 13 17:35:36 2009 UTC
# Line 3  Line 3 
3  # This program is free software; you can redistribute it and/or  # This program is free software; you can redistribute it and/or
4  # modify it under the same terms as Perl itself.  # modify it under the same terms as Perl itself.
5    
6    # It's modified by Dobrica Pavlinusic <dpavlin@rot13.org> to include following:
7    #
8    # * rewrite LDAP bind request cn: username@domain.com -> uid=username,dc=domain,dc=com
9    # * rewrite search responses:
10    # ** expand key:value pairs from hrEduPersonUniqueNumber into hrEduPersonUniqueNumber_key
11    # ** augment response with yaml/dn.yaml data (for external data import)
12    
13  use strict;  use strict;
14  use warnings;  use warnings;
# Line 14  use warnings; Line 20  use warnings;
20  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
21  use Convert::ASN1 qw(asn_read);  use Convert::ASN1 qw(asn_read);
22  use Net::LDAP::ASN qw(LDAPRequest LDAPResponse);  use Net::LDAP::ASN qw(LDAPRequest LDAPResponse);
23  our $VERSION = '0.2';  our $VERSION = '0.3';
24  use fields qw(socket target);  use fields qw(socket target);
25  use YAML qw/LoadFile/;  use YAML qw/LoadFile/;
26    
27    my $debug = 1;
28    
29  my $config = {  my $config = {
30          yaml_dir => './yaml/',          yaml_dir => './yaml/',
31          listen => shift @ARGV || 'localhost:1389',          listen => shift @ARGV || 'localhost:1389',
# Line 56  sub handle { Line 64  sub handle {
64    
65          # read from client          # read from client
66          asn_read($clientsocket, my $reqpdu);          asn_read($clientsocket, my $reqpdu);
67          log_request($reqpdu);          if ( ! $reqpdu ) {
68                    warn "WARNING no reqpdu\n";
69          return 1 unless $reqpdu;                  return 1;
70            }
71            $reqpdu = log_request($reqpdu);
72    
73          # send to server          # send to server
74          print $serversocket $reqpdu or die "Could not send PDU to server\n ";          print $serversocket $reqpdu or die "Could not send PDU to server\n ";
# Line 86  sub log_request { Line 96  sub log_request {
96  #       print "Request Perl:\n";  #       print "Request Perl:\n";
97          my $request = $LDAPRequest->decode($pdu);          my $request = $LDAPRequest->decode($pdu);
98          warn "## request = ",dump($request);          warn "## request = ",dump($request);
99    
100            if ( defined $request->{bindRequest} ) {
101                    if ( $request->{bindRequest}->{name} =~ m{@} ) {
102                            my $old = $request->{bindRequest}->{name};
103                            $request->{bindRequest}->{name} =~ s/[@\.]/,dc=/g;
104                            $request->{bindRequest}->{name} =~ s/^/uid=/;
105                            warn "rewrite bind cn $old -> ", $request->{bindRequest}->{name};
106                            Convert::ASN1::asn_hexdump(\*STDOUT,$pdu) if $debug;
107                            $pdu = $LDAPRequest->encode($request);
108                            Convert::ASN1::asn_hexdump(\*STDOUT,$pdu) if $debug;
109                    }
110            }
111    
112            return $pdu;
113  }  }
114    
115  sub log_response {  sub log_response {

Legend:
Removed from v.60  
changed lines
  Added in v.61

  ViewVC Help
Powered by ViewVC 1.1.26