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.
13 use Data::Dump qw/dump/;
14 use Convert::ASN1 qw(asn_read);
15 use Net::LDAP::ASN qw(LDAPRequest LDAPResponse);
17 use fields qw(socket target);
18 use YAML qw/LoadFile/;
21 my $clientsocket=shift;
22 my $serversocket=shift;
25 asn_read($clientsocket, my $reqpdu);
28 return 1 unless $reqpdu;
31 print $serversocket $reqpdu or die "Could not send PDU to server\n ";
35 my $sel = IO::Select->new($serversocket);
36 for( $ready = 1 ; $ready ; $ready = $sel->can_read(0)) {
37 asn_read($serversocket, my $respdu) or return 1;
38 $respdu = log_response($respdu);
39 # and send the result to the client
40 print $clientsocket $respdu;
51 print "Request ASN 1:\n";
52 Convert::ASN1::asn_hexdump(\*STDOUT,$pdu);
53 print "Request Perl:\n";
54 my $request = $LDAPRequest->decode($pdu);
62 print "Response ASN 1:\n";
63 Convert::ASN1::asn_hexdump(\*STDOUT,$pdu);
64 print "Response Perl:\n";
65 my $response = $LDAPResponse->decode($pdu);
67 if ( defined $response->{protocolOp}->{searchResEntry} ) {
68 my $uid = $response->{protocolOp}->{searchResEntry}->{objectName};
69 warn "## SEARCH $uid";
73 if ( $_->{type} eq 'postalAddress' ) {
74 $_->{vals} = [ 'foobar' ];
76 } @{ $response->{protocolOp}->{searchResEntry}->{attributes} };
79 my $path = "yaml/$uid.yaml";
81 my $data = LoadFile($path);
82 warn "# yaml = ",dump($data);
84 foreach my $type ( keys %$data ) {
86 my $vals = $data->{$type};
89 my @vals = split(/\s*#\s*/, $vals);
91 push @{ $response->{protocolOp}->{searchResEntry}->{attributes} },
92 { type => "ffzg-$type", vals => [ @vals ] };
96 $pdu = $LDAPResponse->encode($response);
99 print dump($response);
105 my $listenersock = shift;
106 my $targetsock=shift;
108 die "Could not create listener socket: $!\n" unless $listenersock;
109 die "Could not create connection to server: $!\n" unless $targetsock;
111 my $sel = IO::Select->new($listenersock);
113 while (my @ready = $sel->can_read) {
114 foreach my $fh (@ready) {
115 if ($fh == $listenersock) {
116 # let's create a new socket
117 my $psock = $listenersock->accept;
120 my $result = handle($fh,$targetsock);
122 # we have finished with the socket
125 delete $Handlers{*$fh};
133 my $listenersock = IO::Socket::INET->new(
141 my $targetsock = new IO::Socket::INET (
143 PeerAddr => 'ldap.ffzg.hr',
147 run_proxy($listenersock,$targetsock);