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,
37 cardnumber as otherPager,
44 use constant RESULT_OK => {
47 'resultCode' => LDAP_SUCCESS
52 my ($class, $sock) = @_;
53 my $self = $class->SUPER::new($sock);
54 print "connection from: ", $sock->peerhost(), "\n";
62 warn "# bind ",dump($reqData);
66 # the search operation
70 print "searching...\n";
72 warn "# request = ", dump($reqData);
74 my $base = $reqData->{'baseObject'}; # FIXME use it?
77 if ( $reqData->{'filter'}->{'equalityMatch'}->{'attributeDesc'} eq 'otherPager' ) {
79 my $value = $reqData->{'filter'}->{'equalityMatch'}->{'assertionValue'} || die "no value?";
81 $sth->execute( $value );
83 warn "# ", $sth->rows, " results for: $value\n";
85 while (my $row = $sth->fetchrow_hashref) {
87 warn "## row = ",dump( $row );
89 my $dn = 'uid=' . $row->{uid} || die "no uid";
90 $dn =~ s{[@\.]}{,dc=}g;
92 my $entry = Net::LDAP::Entry->new;
96 #warn "## entry ",dump( $entry );
98 push @entries, $entry;
102 warn "UNKNOWN request: ",dump( $reqData );
105 return RESULT_OK, @entries;
108 # the rest of the operations will return an "unwilling to perform"