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 my $sth = $dbh->prepare(q{
32 firstname as givenName,
34 cardnumber as otherPager,
41 use constant RESULT_OK => {
44 'resultCode' => LDAP_SUCCESS
49 my ($class, $sock) = @_;
50 my $self = $class->SUPER::new($sock);
51 print "connection from: ", $sock->peerhost(), "\n";
59 warn "# bind ",dump($reqData);
63 # the search operation
67 print "searching...\n";
69 warn "# request = ", dump($reqData);
71 my $base = $reqData->{'baseObject'}; # FIXME use it?
74 if ( $reqData->{'filter'}->{'equalityMatch'}->{'attributeDesc'} eq 'otherPager' ) {
76 my $value = $reqData->{'filter'}->{'equalityMatch'}->{'assertionValue'} || die "no value?";
78 $sth->execute( $value );
80 warn "# ", $sth->rows, " results for: $value\n";
82 while (my $row = $sth->fetchrow_hashref) {
84 warn "## row = ",dump( $row );
86 my $dn = 'uid=' . $row->{uid} || die "no uid";
87 $dn =~ s{[@\.]}{,dc=}g;
89 my $entry = Net::LDAP::Entry->new;
93 #warn "## entry ",dump( $entry );
95 push @entries, $entry;
99 warn "UNKNOWN request: ",dump( $reqData );
102 return RESULT_OK, @entries;
105 # the rest of the operations will return an "unwilling to perform"