24 |
upstream_ldap => 'ldap.ffzg.hr', |
upstream_ldap => 'ldap.ffzg.hr', |
25 |
upstream_ssl => 1, |
upstream_ssl => 1, |
26 |
overlay_prefix => 'ffzg-', |
overlay_prefix => 'ffzg-', |
27 |
|
log_file => 'log', |
28 |
|
|
29 |
}; |
}; |
30 |
|
|
31 |
|
my $log_fh; |
32 |
|
|
33 |
|
sub log { |
34 |
|
if ( ! $log_fh ) { |
35 |
|
open($log_fh, '>>', $config->{log_file}) || die "can't open ", $config->{log_file},": $!"; |
36 |
|
print $log_fh "# " . time; |
37 |
|
} |
38 |
|
$log_fh->autoflush(1); |
39 |
|
print $log_fh join("\n", @_),"\n"; |
40 |
|
} |
41 |
|
|
42 |
|
BEGIN { |
43 |
|
$SIG{'__WARN__'} = sub { warn @_; main::log(@_); } |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
if ( ! -d $config->{yaml_dir} ) { |
if ( ! -d $config->{yaml_dir} ) { |
48 |
warn "DISABLE ", $config->{yaml_dir}," data overlay"; |
warn "DISABLE ", $config->{yaml_dir}," data overlay"; |
49 |
} |
} |
80 |
sub log_request { |
sub log_request { |
81 |
my $pdu=shift; |
my $pdu=shift; |
82 |
|
|
83 |
print '-' x 80,"\n"; |
# print '-' x 80,"\n"; |
84 |
print "Request ASN 1:\n"; |
# print "Request ASN 1:\n"; |
85 |
Convert::ASN1::asn_hexdump(\*STDOUT,$pdu); |
# Convert::ASN1::asn_hexdump(\*STDOUT,$pdu); |
86 |
print "Request Perl:\n"; |
# print "Request Perl:\n"; |
87 |
my $request = $LDAPRequest->decode($pdu); |
my $request = $LDAPRequest->decode($pdu); |
88 |
print dump($request); |
warn "## request = ",dump($request); |
89 |
} |
} |
90 |
|
|
91 |
sub log_response { |
sub log_response { |
92 |
my $pdu=shift; |
my $pdu=shift; |
93 |
|
|
94 |
print '-' x 80,"\n"; |
# print '-' x 80,"\n"; |
95 |
print "Response ASN 1:\n"; |
# print "Response ASN 1:\n"; |
96 |
Convert::ASN1::asn_hexdump(\*STDOUT,$pdu); |
# Convert::ASN1::asn_hexdump(\*STDOUT,$pdu); |
97 |
print "Response Perl:\n"; |
# print "Response Perl:\n"; |
98 |
my $response = $LDAPResponse->decode($pdu); |
my $response = $LDAPResponse->decode($pdu); |
99 |
|
|
100 |
if ( defined $response->{protocolOp}->{searchResEntry} ) { |
if ( defined $response->{protocolOp}->{searchResEntry} ) { |
136 |
$pdu = $LDAPResponse->encode($response); |
$pdu = $LDAPResponse->encode($response); |
137 |
} |
} |
138 |
|
|
139 |
print dump($response); |
warn "## response = ", dump($response); |
140 |
|
|
141 |
return $pdu; |
return $pdu; |
142 |
} |
} |
148 |
die "Could not create listener socket: $!\n" unless $listenersock; |
die "Could not create listener socket: $!\n" unless $listenersock; |
149 |
die "Could not create connection to server: $!\n" unless $targetsock; |
die "Could not create connection to server: $!\n" unless $targetsock; |
150 |
|
|
|
# mark sockets as binary |
|
|
binmode( $listenersock ); |
|
|
binmode( $targetsock ); |
|
|
|
|
151 |
my $sel = IO::Select->new($listenersock); |
my $sel = IO::Select->new($listenersock); |
152 |
my %Handlers; |
my %Handlers; |
153 |
while (my @ready = $sel->can_read) { |
while (my @ready = $sel->can_read) { |
170 |
} |
} |
171 |
|
|
172 |
|
|
173 |
|
$ENV{LANG} = 'C'; # so we don't double-encode utf-8 if LANG is utf-8 |
174 |
|
|
175 |
my $listenersock = IO::Socket::INET->new( |
my $listenersock = IO::Socket::INET->new( |
176 |
Listen => 5, |
Listen => 5, |
177 |
Proto => 'tcp', |
Proto => 'tcp', |
178 |
Reuse => 1, |
Reuse => 1, |
179 |
LocalAddr => $config->{listen}, |
LocalAddr => $config->{listen}, |
180 |
); |
) || die "can't open listen socket: $!"; |
181 |
|
|
182 |
|
|
183 |
my $targetsock = $config->{upstream_ssl} |
my $targetsock = $config->{upstream_ssl} |
187 |
PeerPort => 389, |
PeerPort => 389, |
188 |
) |
) |
189 |
: IO::Socket::SSL->new( $config->{upstream_ldap} . ':ldaps') |
: IO::Socket::SSL->new( $config->{upstream_ldap} . ':ldaps') |
190 |
; |
|| die "can't open upstream socket: $!"; |
191 |
|
|
192 |
|
binmode( $listenersock ); |
193 |
|
binmode( $targetsock ); |
194 |
|
|
195 |
run_proxy($listenersock,$targetsock); |
run_proxy($listenersock,$targetsock); |
196 |
|
|