SYNOPSIS

  package MyServer;
  use Net::LDAP::Server;
  use Net::LDAP::Constant qw(LDAP_SUCCESS);
  use base 'Net::LDAP::Server';
  sub search {
      my $self = shift;
      my ($reqData, $fullRequest) = @_;
      print "Searching\n";
      ...
      return {
          'matchedDN' => '',
          'errorMessage' => '',
          'resultCode' => LDAP_SUCCESS
      }, @entries;
  }

package main; my $handler = MyServer->new($socket); $handler->handle;

ABSTRACT

This class provides the protocol handling for an \s-1LDAP\s0 server. You can subclass it and implement the methods you need (see below). Then you just instantiate your subclass and call its \*(C`handle\*(C' method to establish a connection with the client.

SUBCLASSING

You can subclass Net::LDAP::Server with the following lines:

package MyServer; use Net::LDAP::Server; use base 'Net::LDAP::Server';

Then you can add your custom methods by just implementing a subroutine named after the name of each method. These are supported methods:

For any method that is not supplied, Net::LDAP::Server will return an \*(C`LDAP_UNWILLING_TO_PERFORM\*(C'.

\$1

You can also subclass the \*(C`new\*(C' constructor to do something at connection time:

sub new { my ($class, $sock) = @_; my $self = $class->SUPER::new($sock); printf "Accepted connection from: %s\n", $sock->peerhost(); return $self; }

Note that $self is constructed using the fields pragma, so if you want to add data to it you should add a line like this in your subclass:

use fields qw(myCustomField1 myCustomField2); When a method is invoked it will be obviously passed $self as generated by \*(C`new\*(C', and two variables:

* the Request datastructure that is specific for this method (e.g. BindRequest);
* the full request message (useful if you want to access messageID or controls parts)

You can look at Net::LDAP::ASN or use Data::Dumper to find out what is presented to your method:

use Data::Dumper; sub search { print Dumper \@_; }

If anything goes wrong in the module you specify (e.g. it died or the result is not a correct ldapresult structure) Net::LDAP::Server will return an \*(C`LDAP_OPERATIONS_ERROR\*(C' where the errorMessage will specify what went wrong.

All methods should return a LDAPresult hashref, for example:

return({ 'matchedDN' => '', 'errorMessage' => '', 'resultCode' => LDAP_SUCCESS });

\*(C`search\*(C' should return a LDAPresult hashref followed by a list of entries (if applicable). Entries may be coded either as searchResEntry or searchRefEntry structures or as Net::LDAP::Entry or Net::LDAP::Reference objects.

CLIENT HANDLING

When you get a socket from a client you can instantiate the class and handle the request:

my $handler = MyServer->new($socket); $handler->handle;

See examples in examples/ directory for sample servers, using IO::Select or Net::Daemon.

DEPENDENCIES

Net::LDAP::ASN Net::LDAP::Constant

RELATED TO Net::LDAP::Server…

Net::LDAP
Examples in examples directory.

BUGS AND FEEDBACK

There are no known bugs. You are very welcome to write mail to the maintainer ([email protected]) with your contributions, comments, suggestions, bug reports or complaints.

COPYRIGHT

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Alessandro Ranellucci <[email protected]> The original author of a Net::LDAP::Daemon module is Hans Klunder <[email protected]>