Net::L...:Server(3pm)
π Net::LDAP::Server β LDAP server side protocol handling π
okay so bestie, welcome to Net::LDAP::Server π
this is the Perl page for it, from the User Contributed Perl Documentation (that's the 3pm bit, iykyk). It's giving server-side LDAP protocol energy and honestly? she eats. Let's get into it π«Ά
β¨ NAME β¨
Net::LDAP::Server β LDAP server side protocol handling π¦
β¨ 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;
# or with distinct input and output handles
package main;
my $handler = MyServer->new( $input_handle, $output_handle );
$handler->handle;
β¨ ABSTRACT β¨
So basically πββοΈ this class does the protocol handling for an LDAP server. You subclass it, you implement the methods you actually care about (they're all listed below, don't worry), and then you just instantiate your subclass and call its handle method to establish a connection with the client. That's it. That's the whole vibe. β¨
β¨ SUBCLASSING β¨
You can subclass Net::LDAP::Server with these lines right here:
package MyServer;
use Net::LDAP::Server;
use base 'Net::LDAP::Server';
Then you just add your own custom methods by implementing a subroutine named after the name of each method π These are the supported methods, bestie:
"bind""unbind""search""add""modify""delete""modifyDN""compare""abandon"
For any method that is not supplied, Net::LDAP::Server will return an "LDAP_UNWILLING_TO_PERFORM". She's not being rude, she's just not doing it π
πΈ new() πΈ
You can also subclass the "new" constructor to do something at connection time, like so:
sub new {
my ($class, $sock) = @_;
my $self = $class->SUPER::new($sock);
printf "Accepted connection from: %s\n", $sock->peerhost();
return $self;
}
Quick heads up though π«Ά $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);
π Methods π
When a method is invoked it will be obviously passed $self as generated by "new", 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 "LDAP_OPERATIONS_ERROR" where the errorMessage will specify what went wrong. Not ideal, but at least she tells you π
All methods should return a LDAPresult hashref, for example:
return({
'matchedDN' => '',
'errorMessage' => '',
'resultCode' => LDAP_SUCCESS
});
"search" 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. Slay, options β¨
β¨ CLIENT HANDLING β¨
π handle() π
When you get a socket from a client you can instantiate the class and handle the request:
my $handler = MyServer->new($socket);
$handler->handle;
Or, alternatively, you can pass two handles for input and output, respectively. Very main character of you π
my $handler = MyServer->new(*STDIN{IO},*STDOUT{IO});
$handler->handle;
See examples in examples/ directory for sample servers, using IO::Select, Net::Daemon or Net::Server. Go look, they're iconic π¦
β¨ DEPENDENCIES β¨
Net::LDAP::ASN
Net::LDAP::Constant
β¨ SEE ALSO β¨
- Net::LDAP
- Examples in
"examples"directory.
β¨ BUGS AND FEEDBACK β¨
There are no known bugs π (we love a clean record). You are very welcome to write mail to the maintainer (aar@cpan.org) with your contributions, comments, suggestions, bug reports or complaints. Fr fr, she wants to hear from you π«Ά
β¨ COPYRIGHT β¨
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
β¨ AUTHOR β¨
Alessandro Ranellucci <aar@cpan.org>
The original author of a Net::LDAP::Daemon module is Hans Klunder <hans.klunder@bigfoot.com> π
and that's the whole page bestie, no cap πΈ this was perl v5.36.0, dated 2022-12-11, brought to you by the User Contributed Perl Documentation for Net::LDAP::Server(3pm) β go forth and handle some protocols π
β¨π¦
π¦ where this page comes from
- debian bookworm: libnet-ldap-server-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-ldap-server-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-ldap-server-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-ldap-server-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-ldap-server-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms