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 |
|
|
28 |
|
}; |
29 |
|
|
30 |
|
if ( ! -d $config->{yaml_dir} ) { |
31 |
|
warn "DISABLE ", $config->{yaml_dir}," data overlay"; |
32 |
|
} |
33 |
|
|
34 |
|
warn "# config = ",dump( $config ); |
35 |
|
|
36 |
sub handle { |
sub handle { |
37 |
my $clientsocket=shift; |
my $clientsocket=shift; |
38 |
my $serversocket=shift; |
my $serversocket=shift; |
84 |
my $uid = $response->{protocolOp}->{searchResEntry}->{objectName}; |
my $uid = $response->{protocolOp}->{searchResEntry}->{objectName}; |
85 |
warn "## SEARCH $uid"; |
warn "## SEARCH $uid"; |
86 |
|
|
87 |
if(0) { |
my @attrs; |
88 |
|
|
89 |
map { |
map { |
90 |
if ( $_->{type} eq 'postalAddress' ) { |
if ( $_->{type} eq 'hrEduPersonUniqueNumber' ) { |
91 |
$_->{vals} = [ 'foobar' ]; |
foreach my $val ( @{ $_->{vals} } ) { |
92 |
|
next if $val !~ m{.+:.+}; |
93 |
|
my ( $n, $v ) = split(/\s*:\s*/, $val ); |
94 |
|
push @attrs, { type => $_->{type} . '_' . $n, vals => [ $v ] }; |
95 |
|
} |
96 |
} |
} |
97 |
} @{ $response->{protocolOp}->{searchResEntry}->{attributes} }; |
} @{ $response->{protocolOp}->{searchResEntry}->{attributes} }; |
|
} |
|
98 |
|
|
99 |
my $path = "yaml/$uid.yaml"; |
warn "# ++ attrs ",dump( @attrs ); |
100 |
|
|
101 |
|
push @{ $response->{protocolOp}->{searchResEntry}->{attributes} }, $_ foreach @attrs; |
102 |
|
|
103 |
|
my $path = $config->{yaml_dir} . "$uid.yaml"; |
104 |
if ( -e $path ) { |
if ( -e $path ) { |
105 |
my $data = LoadFile($path); |
my $data = LoadFile($path); |
106 |
warn "# yaml = ",dump($data); |
warn "# yaml = ",dump($data); |
108 |
foreach my $type ( keys %$data ) { |
foreach my $type ( keys %$data ) { |
109 |
|
|
110 |
my $vals = $data->{$type}; |
my $vals = $data->{$type}; |
|
$vals =~ s{#\s*$}{}; |
|
|
|
|
|
my @vals = split(/\s*#\s*/, $vals); |
|
111 |
|
|
112 |
push @{ $response->{protocolOp}->{searchResEntry}->{attributes} }, |
push @{ $response->{protocolOp}->{searchResEntry}->{attributes} }, { |
113 |
{ type => "ffzg-$type", vals => [ @vals ] }; |
type => $config->{overlay_prefix} . $type, |
114 |
|
vals => ref($vals) eq 'ARRAY' ? $vals : [ $vals ], |
115 |
|
}; |
116 |
} |
} |
117 |
} |
} |
118 |
|
|
131 |
die "Could not create listener socket: $!\n" unless $listenersock; |
die "Could not create listener socket: $!\n" unless $listenersock; |
132 |
die "Could not create connection to server: $!\n" unless $targetsock; |
die "Could not create connection to server: $!\n" unless $targetsock; |
133 |
|
|
134 |
|
# mark sockets as binary |
135 |
|
binmode( $listenersock ); |
136 |
|
binmode( $targetsock ); |
137 |
|
|
138 |
my $sel = IO::Select->new($listenersock); |
my $sel = IO::Select->new($listenersock); |
139 |
my %Handlers; |
my %Handlers; |
140 |
while (my @ready = $sel->can_read) { |
while (my @ready = $sel->can_read) { |
161 |
Listen => 5, |
Listen => 5, |
162 |
Proto => 'tcp', |
Proto => 'tcp', |
163 |
Reuse => 1, |
Reuse => 1, |
164 |
LocalPort => 1389 |
LocalAddr => $config->{listen}, |
165 |
); |
); |
166 |
|
|
167 |
|
|
168 |
my $targetsock = new IO::Socket::INET ( |
my $targetsock = $config->{upstream_ssl} |
169 |
Proto => 'tcp', |
? IO::Socket::INET->new( |
170 |
PeerAddr => 'ldap.ffzg.hr', |
Proto => 'tcp', |
171 |
PeerPort => 389, |
PeerAddr => $config->{upstream_ldap}, |
172 |
); |
PeerPort => 389, |
173 |
|
) |
174 |
$targetsock = IO::Socket::SSL->new("ldap.ffzg.hr:ldaps"); |
: IO::Socket::SSL->new( $config->{upstream_ldap} . ':ldaps') |
175 |
|
; |
176 |
|
|
177 |
run_proxy($listenersock,$targetsock); |
run_proxy($listenersock,$targetsock); |
178 |
|
|