1Net::LDAP::Server(3)  User Contributed Perl Documentation Net::LDAP::Server(3)
2
3
4

NAME

6       Net::LDAP::Server - LDAP server side protocol handling
7

SYNOPSIS

9         package MyServer;
10         use Net::LDAP::Server;
11         use Net::LDAP::Constant qw(LDAP_SUCCESS);
12         use base 'Net::LDAP::Server';
13         sub search {
14             my $self = shift;
15             my ($reqData, $fullRequest) = @_;
16             print "Searching\n";
17             ...
18             return {
19                 'matchedDN' => '',
20                 'errorMessage' => '',
21                 'resultCode' => LDAP_SUCCESS
22             }, @entries;
23         }
24
25         package main;
26         my $handler = MyServer->new($socket);
27         $handler->handle;
28
29         # or with distinct input and output handles
30         package main;
31         my $handler = MyServer->new( $input_handle, $output_handle );
32         $handler->handle;
33

ABSTRACT

35       This class provides the protocol handling for an LDAP server. You can
36       subclass it and implement the methods you need (see below). Then you
37       just instantiate your subclass and call its "handle" method to
38       establish a connection with the client.
39

SUBCLASSING

41       You can subclass Net::LDAP::Server with the following lines:
42
43         package MyServer;
44         use Net::LDAP::Server;
45         use base 'Net::LDAP::Server';
46
47       Then you can add your custom methods by just implementing a subroutine
48       named after the name of each method. These are supported methods:
49
50       "bind"
51       "unbind"
52       "search"
53       "add"
54       "modify"
55       "delete"
56       "modifyDN"
57       "compare"
58       "abandon"
59
60       For any method that is not supplied, Net::LDAP::Server will return an
61       "LDAP_UNWILLING_TO_PERFORM".
62
63   new()
64       You can also subclass the "new" constructor to do something at
65       connection time:
66
67         sub new {
68            my ($class, $sock) = @_;
69            my $self = $class->SUPER::new($sock);
70            printf "Accepted connection from: %s\n", $sock->peerhost();
71            return $self;
72         }
73
74       Note that $self is constructed using the fields pragma, so if you want
75       to add data to it you should add a line like this in your subclass:
76
77         use fields qw(myCustomField1 myCustomField2);
78
79   Methods
80       When a method is invoked it will be obviously passed $self as generated
81       by "new", and two variables:
82
83       •   the Request datastructure that is specific for this method (e.g.
84           BindRequest);
85
86       •   the full request message (useful if you want to access messageID or
87           controls parts)
88
89       You can look at Net::LDAP::ASN or use Data::Dumper to find out what is
90       presented to your method:
91
92         use Data::Dumper;
93         sub search {
94            print Dumper \@_;
95         }
96
97       If anything goes wrong in the module you specify (e.g. it died or the
98       result is not a correct ldapresult structure) Net::LDAP::Server will
99       return an "LDAP_OPERATIONS_ERROR" where the errorMessage will specify
100       what went wrong.
101
102       All methods should return a LDAPresult hashref, for example:
103
104         return({
105             'matchedDN' => '',
106             'errorMessage' => '',
107             'resultCode' => LDAP_SUCCESS
108         });
109
110       "search" should return a LDAPresult hashref followed by a list of
111       entries (if applicable). Entries may be coded either as searchResEntry
112       or searchRefEntry structures or as Net::LDAP::Entry or
113       Net::LDAP::Reference objects.
114

CLIENT HANDLING

116   handle()
117       When you get a socket from a client you can instantiate the class and
118       handle the request:
119
120         my $handler = MyServer->new($socket);
121         $handler->handle;
122
123       Or, alternatively, you can pass two handles for input and output,
124       respectively.
125
126         my $handler = MyServer->new(*STDIN{IO},*STDOUT{IO});
127         $handler->handle;
128
129       See examples in examples/ directory for sample servers, using
130       IO::Select, Net::Daemon or Net::Server.
131

DEPENDENCIES

133        Net::LDAP::ASN
134        Net::LDAP::Constant
135

SEE ALSO

137       Net::LDAP
138       Examples in "examples" directory.
139

BUGS AND FEEDBACK

141       There are no known bugs. You are very welcome to write mail to the
142       maintainer (aar@cpan.org) with your contributions, comments,
143       suggestions, bug reports or complaints.
144
146       This library is free software; you can redistribute it and/or modify it
147       under the same terms as Perl itself.
148

AUTHOR

150       Alessandro Ranellucci <aar@cpan.org> The original author of a
151       Net::LDAP::Daemon module is Hans Klunder <hans.klunder@bigfoot.com>
152
153
154
155perl v5.34.0                      2021-07-27              Net::LDAP::Server(3)
Impressum