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; |
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', |
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 "; |
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 { |