2 # Copyright (c) 2006 Hans Klunder <hans.klunder@bigfoot.com>. All rights reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the same terms as Perl itself.
14 use Data::Dump qw/dump/;
15 use Convert::ASN1 qw(asn_read);
16 use Net::LDAP::ASN qw(LDAPRequest LDAPResponse);
18 use fields qw(socket target);
19 use YAML qw/LoadFile/;
22 my $clientsocket=shift;
23 my $serversocket=shift;
26 asn_read($clientsocket, my $reqpdu);
29 return 1 unless $reqpdu;
32 print $serversocket $reqpdu or die "Could not send PDU to server\n ";
36 my $sel = IO::Select->new($serversocket);
37 for( $ready = 1 ; $ready ; $ready = $sel->can_read(0)) {
38 asn_read($serversocket, my $respdu) or return 1;
39 $respdu = log_response($respdu);
40 # and send the result to the client
41 print $clientsocket $respdu;
52 print "Request ASN 1:\n";
53 Convert::ASN1::asn_hexdump(\*STDOUT,$pdu);
54 print "Request Perl:\n";
55 my $request = $LDAPRequest->decode($pdu);
63 print "Response ASN 1:\n";
64 Convert::ASN1::asn_hexdump(\*STDOUT,$pdu);
65 print "Response Perl:\n";
66 my $response = $LDAPResponse->decode($pdu);
68 if ( defined $response->{protocolOp}->{searchResEntry} ) {
69 my $uid = $response->{protocolOp}->{searchResEntry}->{objectName};
70 warn "## SEARCH $uid";
74 if ( $_->{type} eq 'postalAddress' ) {
75 $_->{vals} = [ 'foobar' ];
77 } @{ $response->{protocolOp}->{searchResEntry}->{attributes} };
80 my $path = "yaml/$uid.yaml";
82 my $data = LoadFile($path);
83 warn "# yaml = ",dump($data);
85 foreach my $type ( keys %$data ) {
87 my $vals = $data->{$type};
90 my @vals = split(/\s*#\s*/, $vals);
92 push @{ $response->{protocolOp}->{searchResEntry}->{attributes} },
93 { type => "ffzg-$type", vals => [ @vals ] };
97 $pdu = $LDAPResponse->encode($response);
100 print dump($response);
106 my $listenersock = shift;
107 my $targetsock=shift;
109 die "Could not create listener socket: $!\n" unless $listenersock;
110 die "Could not create connection to server: $!\n" unless $targetsock;
112 my $sel = IO::Select->new($listenersock);
114 while (my @ready = $sel->can_read) {
115 foreach my $fh (@ready) {
116 if ($fh == $listenersock) {
117 # let's create a new socket
118 my $psock = $listenersock->accept;
121 my $result = handle($fh,$targetsock);
123 # we have finished with the socket
126 delete $Handlers{*$fh};
134 my $listenersock = IO::Socket::INET->new(
142 my $targetsock = new IO::Socket::INET (
144 PeerAddr => 'ldap.ffzg.hr',
148 $targetsock = IO::Socket::SSL->new("ldap.ffzg.hr:ldaps");
150 run_proxy($listenersock,$targetsock);