Looking at ldapr Step by Step
Taking the script step by step, we start on familiar ground:
use strict; use Jabber::Connection; use Jabber::NodeFactory; use Jabber::NS qw(:all); use Net::LDAP; my $ldapsrv = 'cicero'; my $basedn = 'dc=demo,dc=org';
After declaring the modules we want to use (the only one we
haven’t seen so far is the Net::LDAP module
that we’ll need to connect to and query an LDAP server), we
define a couple of variables. $ldapsrv is
the name of the LDAP server that ldapr is going
to be reflecting, and $basedn is the base
distinguished name that will be used as the suffix in all of
the LDAP queries.
If you don’t have an LDAP server of your own, a number
of public ones are available that you could point this script at.
The two variables $ldapsrv and
$basedn go together—make sure you
specify the correct base DN for the LDAP server you want to
reflect.
Note
Depending on the configuration, some LDAP servers will require
you to bind to them with a username and
password before you can perform searches. To do this, you’ll
need to include an extra step in this script, using the
bind() method in Net::LDAP.
Having opened our connection to the LDAP server:
my $ldap = Net::LDAP->new($ldapsrv) or die $@;
we then proceed to connect to the Jabber server as a component. We’re connecting to localhost:9389,
which means this component script is going to run on the
same host as the Jabber server, and connect to it on port
9389:
debug("connecting to Jabber"); my $c = new Jabber::Connection( ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access