5 use Data::Dump qw/dump/;
8 use Net::LDAP::Constant qw(LDAP_SUCCESS);
10 use base 'Net::LDAP::Server';
17 # ldapsearch -h localhost -p 2389 -b dc=ffzg,dc=hr -x 'otherPager=200903160021'
20 our $dsn = 'DBI:mysql:dbname=';
21 our $database = 'koha';
22 our $user = 'unconfigured-user';
23 our $passwd = 'unconfigured-password';
25 require 'config.pl' if -e 'config.pl';
27 my $dbh = DBI->connect($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 0 }) || die $DBI::errstr;
29 # Net::LDAP::Entry will lc all our attribute names anyway, so
30 # we don't really care about correctCapitalization for LDAP
31 # attributes which won't pass through DBI
32 my $sth = $dbh->prepare(q{
35 firstname as givenName,
42 cardnumber as otherPager,
49 use constant RESULT_OK => {
52 'resultCode' => LDAP_SUCCESS
57 my ($class, $sock) = @_;
58 my $self = $class->SUPER::new($sock);
59 print "connection from: ", $sock->peerhost(), "\n";
67 warn "# bind ",dump($reqData);
71 # the search operation
75 print "searching...\n";
77 warn "# request = ", dump($reqData);
79 my $base = $reqData->{'baseObject'}; # FIXME use it?
82 if ( $reqData->{'filter'}->{'equalityMatch'}->{'attributeDesc'} eq 'otherPager' ) {
84 my $value = $reqData->{'filter'}->{'equalityMatch'}->{'assertionValue'} || die "no value?";
86 $sth->execute( $value );
88 warn "# ", $sth->rows, " results for: $value\n";
90 while (my $row = $sth->fetchrow_hashref) {
92 warn "## row = ",dump( $row );
94 my $dn = 'uid=' . $row->{uid} || die "no uid";
95 $dn =~ s{[@\.]}{,dc=}g;
97 my $entry = Net::LDAP::Entry->new;
101 #warn "## entry ",dump( $entry );
103 push @entries, $entry;
107 warn "UNKNOWN request: ",dump( $reqData );
110 return RESULT_OK, @entries;
113 # the rest of the operations will return an "unwilling to perform"