None

Setting up LDAP

December 23, 2009

This article looks at my adventures in setting up an LDAP server and talking to it from clients.

Server

For a server, we're going to use the apache-directory project, on Ubuntu. (http://directory.apache.org). The only external dependency is Java 5.0.

To install, download the .deb and install it by double clicking on the file. This installs to the root filesystem. The server is automatically started at boot, by default listening on port 10389. (For login details, see the Admin studio section below).

Admin Studio

From the same website, they have an Eclipse RCP based tool for administering the server, called Apache Directory Studio. Download, extract the archive and run ApacheDirectoryStudio. I had to set export GDK_NATIVE_WINDOWS=1 before running the executable to get the buttons to work.

Once installed and working, you should be able to connect to the LDAP server using No encryption and port 10389 from the LDAP/New Connection menu option. The "Bind DN or user" is uid=admin,ou=system and the default password is secret.

Python Client

The python-ldap library is available from http://www.python-ldap.org/. I downloaded the python_ldap-2.3.9-py2.6-linux-x86_64.egg file from http://svn.kmrc.de/download/distribution/contrib/, and installed with the following command.

On windows you'll need to install easy_install from http://pypi.python.org/pypi/setuptools and add c:\python26\Scripts to your path to get the command to work.

On Fedora, make sure you've installed the python-setuptools-devel package.

$ sudo easy_install python_ldap-2.3.9-py2.6-linux-x86_64.egg
[sudo] password for user:
Processing python_ldap-2.3.9-py2.6-linux-x86_64.egg
creating /usr/local/lib/python2.6/dist-packages/python_ldap-2.3.9-py2.6-linux-x86_64.egg
Extracting python_ldap-2.3.9-py2.6-linux-x86_64.egg to /usr/local/lib/python2.6/dist-packages
 Adding python-ldap 2.3.9 to easy-install.pth file

Installed /usr/local/lib/python2.6/dist-packages/python_ldap-2.3.9-py2.6-linux-x86_64.egg
Processing dependencies for python-ldap==2.3.9
Finished processing dependencies for python-ldap==2.3.9

Now we have the ldap library installed, we can connect to it.

>>> import ldap
>>> con = ldap.initialize('ldap://localhost:10389')
>>> dn = "uid=admin,ou=system"
>>> password = "secret"
>>> con.simple_bind_s(dn,password)
(97, [])