x
Loading
 Loading
Hello, Guest | Login | Register

Using Perl and LDAP

A walkthrus of the basics: making connections, creating and modifying entries, and searching.

So, you have your LDAP server all set up and purring along happily — great! You can if you want perform all your interactions with LDAP — adding, deleting, and modifying records — by writing LDIF files and using the command line commands. And sometimes that’s fine. But it can also be very useful to be able to script those interactions: for example, to create a script which will take arguments and then add a new user. What you need at this point is perl-ldap — a collection of Perl modules providing an OO interface to LDAP servers. Unlike some other perl/LDAP implementations, perl-ldap doesn’t require a C compiler, but runs as straight perl, making it more cross-platform compatible. It is under active development, and a reasonably recent version is available packaged for most distros (e.g. libnet-ldap-perl for Debian/Ubuntu). Or you can install it from CPAN with the command perl -m CPAN -e "install perl-ldap". In the following, I’ll construct a script to add a new user. I’ll assume that you’re familiar with basic perl programming and with perl OO — there are plenty of resources available online if not. I’m also not going to give the command-line parsing parts — assume that any undeclared variables have been taken from the command line! I also haven’t tackled the business of authentication, which may be needed for the parts of this which go beyond just searching.

Making a connection

Net::LDAP and Net::LDAPS are the modules which handle connecting and…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace