Book Image

Mastering OpenLDAP: Configuring, Securing and Integrating Directory Services

Book Image

Mastering OpenLDAP: Configuring, Securing and Integrating Directory Services

Overview of this book

This book is the ideal introduction to using OpenLDAP for Application Developers and will also benefit System Administrators running OpenLDAP. It prepares the reader to build a directory using OpenLDAP, and then employ this directory in the context of the network, taking a practical approach that emphasizes how to get things done. On occasion, it delves into theoretical aspects of LDAP, but only where understanding the theory helps to answer practical questions. The reader requires no knowledge of OpenLDAP, but even readers already familiar with the technology will find new things and techniques. This book is organized into three major sections: the first section covers the basics of LDAP directory services and the OpenLDAP server; the second focuses on building directory services with OpenLDAP; in the third section of the book, we look at how OpenLDAP is integrated with other applications and services on the network. This book not only demystifies OpenLDAP, but gives System Administrators and Application Developers a solid understanding of how to make use of OpenLDAP's directory services.The OpenLDAP directory server is a mature product that has been around (in one form or another) since 1995. It is an open-source server that provides network clients with directory services. All major Linux distributions include the OpenLDAP server, and many major applications, both open-source and proprietary, are directory aware and can make use of the services provided by OpenLDAP.The OpenLDAP directory server can be used to store organizational information in a centralized location, and make this information available to authorized applications. Client applications connect to OpenLDAP using the Lightweight Directory Access Protocol (LDAP) and can then search the directory and (if they have appropriate access) modify and manipulate records. LDAP servers are most frequently used to provide network-based authentication services for users; but there are many other uses for an LDAP server, including using the directory as an address book, a DNS database, an organizational tool, or even as a network object store for applications.
Table of Contents (17 chapters)
Mastering OpenLDAP
Credits
About the Author
About the Reviewers
Preface
Index

The Tools for Compiling


Whenever you build an application from source code, you need the right set of tools and libraries. OpenLDAP is no exception. Thankfully, OpenLDAP is a little lighter on requirements than some server applications out there.

Compiling is done on the command line, so you will need to open a terminal or otherwise gain access to the shell.

Build Tools

You will need the standard tool chain for working with C and C++ applications; a C compiler, a linker, and a make program. Fortunately, all of these come as standard with almost every Linux distribution available. You can test your system for the appropriate tools using the which command, which will tell you where the tools are located on your filesystem (assuming they are in one of the directories listed in your $PATH environment variable).

Here's a quick example of how you can check to see where the tools are and what the current version of each tool is. My system is Ubuntu Linux 6.06. Version numbers on your own system may vary. That's okay. OpenLDAP should compile on all modern Linux distributions, and probably on all modern UNIX distributions as well.

$ gcc --version
gcc (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ which ld
/usr/bin/ld
$ ld --version
GNU ld version 2.16.91 20060118 Debian GNU/Linux
Copyright 2005 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of the GNU General Public License.  This program has absolutely no warranty.
$ which make
/usr/bin/make
$ make --version
GNU Make 3.81beta4
Copyright (C) 2003  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i486-pc-linux-gnu
$ 

In each case I used the which tool to know where the tool was located. The programs I checked were gcc, ld, and make—the compiler, linker, and make program (respectively). As long as some path is returned, this indicates that the tool is installed. If no command is found, which returns without any output. Thus, if I searched for a fake command, blah, the output would look like this:

$ which blah
$

Thus, if you run which for any of the programs (gcc, ld, or make), and get no output, it indicates that you do not have the required tool.

Note

On some UNIX systems, the GCC compiler (gcc) may not be present, but another C compiler may exist. The de facto name for C compilers is cc, and if which gcc yields no result, you may want to try which cc.

After the which command in the given example, I ran each command with the --version flag (with two dashes before version) to tell me which version was installed. The --version flag is a GNU standard, but non-GNU programs (such as other versions of make or cc) may not support it.

The next thing to do is set a couple of environment variables that will provide some basic settings for the given tools. While there are many options that you can provide to your tools through environment variables, here we will just provide the basics for building OpenLDAP.

Note

Some Linux and UNIX distributions set the necessary environment variables for you. In such cases, it is almost always better to use the already-defined environment variables, which are often optimized specifically for your system, rather than the generic ones we will be setting now.

To find out if you have the necessary environment variables, run the env command (with no arguments) and check the output to see if CC, CFLAGS, and PATH are defined.

One way to set environment variables is with the export command. When you use the export command, the environment variables will be stored for the duration of your shell session (in other words, until you exit from the shell or close the terminal window). Here we will set the necessary environment variables using export:

$ export CC=gcc
$ export CFLAGS="-O2"

The first export sets the $CC environment variable to gcc. The make program will use this to determine which compiler to use. (If you are using the cc compiler instead, then adjust the example to point to cc instead of gcc). Note that when you set an environment variable, you do not use the dollar sign ($) before the variable name. When you reference the variable however, you will need to include the dollar sign.

The second line sets the $CFLAGS variable. The $CFLAGS variables are the options that get passed to the compiler during compilation. In this case, we are passing it the option -O2 (that's a captial letter O, not a zero). This tells the compiler to use level 2 optimization when compiling the code.

The $PATH environment variable should also be set. However, by using the which command to see where our tools were, we have already verified that the necessary directories (that is, the directories that contain our tools) are specified in the $PATH variable.

If you are dealing with a non-standard system or non-standard builds of any of the libraries, or if you are interested in passing some other options to the build tools, you may also have to use some additional environment variables. You can use $CPPFLAGS to pass options to the C preprocessor (cpp, part of GCC). Likewise, you can pass the linker (ld) options with the $LDFLAGS variable. Finally, if you have libraries (compiled modules of code used by other applications) that are stored in non-standard places, you can use the $LIBS variable to specify the location of these libraries. If you need to use the variables you should consult the documentation for the tools and libraries.

At any point you can check your environment variables with some simple commands. The env command (executed with no arguments) will list all of the environment variables currently defined, as well as their values. You can also check an individual environment variable with the echo command. Simply type echo, followed by the name of the environment variable to display the value of that environment variable:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin
/X11:/usr/games

In this example echo $PATH shows the list of directories the shell searches to find programs. As you may recall the which command, when run, printed out the location of the specified tool. To find tools it searched each of the directories specified in the $PATH variable.

At this point we are ready to move on to the next step: installing the necessary dependencies.

Installing Dependencies

Dependencies are packages that OpenLDAP will require to compile and to run. Installing these dependencies will vary from platform to platform (and from Linux distro to Linux distro). Here, I will use the Debian tools (included in Ubuntu Linux) to install packages.

OpenLDAP requires standard C libraries, regular expression libraries, and the Berkeley DB 4.2 (or later) libraries. These are almost always included in modern Linux distributions. In addition to the libraries, the header files are also required. Often these are stored in separate packages (usually called DEV packages). To install, for example, the Berkeley DB 4.2 development package in Ubuntu, you can execute the following command from the command line:

  $ sudo apt-get install libdb4.2-dev

This will fetch and install the required package.

There are various other packages that are useful to install, and we will need them in order to build all of the features that we use in this book. You will need to install:

  • OpenSSL (for SSL and TLS support)

  • SASL 2 (for SASL authentication support)

If you are interested in storing your directory in a relational database engine, such as MySQL or Oracle, you might also want to install iODBC2 (for database backend support).

All of these packages are common on modern Linux system. Make sure that the packages are installed, and that the DEV (or -dev) add-ons for each of these is installed as well. In Ubuntu 6.06 these can be installed with one (rather long) command:

  $ apt-get install libssl0.9.8 libssl-dev libiodbc2 libiodbc2-dev 
            libsasl2 libsasl2-dev

Other distributions may use different installers, and even different package names, but you should have no problem finding them based on the bullet list of names that have been provided.

Note

OpenLDAP includes many optional modules that provide additional functionality (such as debugging or integration with other services). These modules are not covered in this book, though you may choose to explore them on your own. Some of these modules require additional libraries. Consult the OpenLDAP documentation included in the source code for more specific information.

At this point you have all the tools and requirements necessary for building OpenLDAP. Now we move onward to the actual compiling process.