Previous Contents Index DocHome Next |
Netscape LDAP SDK for C LDAP SDK for C |
Chapter 1 The Netscape LDAP SDK for C
This chapter introduces the Lightweight Directory Access Protocol (LDAP) Application Programming Interface (API) and describes the Netscape LDAP SDK for C.This chapter contains the following sections:
The LDAP API
The Lightweight Directory Access Protocol (v3), RFC 2251 defines a set of API functions that you can use to build LDAP-enabled clients. The functionality implemented in this SDK closely follows the interfaces outlined in RFC 2251. Using the functionality provided with this SDK, you can enable your clients to connect to LDAPv3-compliant servers and perform standard LDAP functions. Among other things, with this SDK you can:For example, if you are writing an email application, you can use the functions in the LDAP API to retrieve email addresses from an LDAP server.
The API functions allow you to perform LDAP operations synchronously or asynchronously.
You can call a synchronous function if you want to wait for the operation to complete before receiving the return value of a function.
The LDAP API also includes functionality defined in LDAPv3. For example, you can call functions to request extended operations from an LDAPv3 server.If you want to perform other work while waiting for an operation to complete, you can call an asynchronous function and poll the LDAP client library to check the status of the operation.
Subsequent chapters in this manual explain how to use the LDAP API functions contained in the LDAP SDK for C. For a complete list of the functions implemented in this SDK, refer to Chapter 18 "Function Reference."
Files Provided With the LDAP SDK for C
The Netscape LDAP SDK for C is a Software Development Kit (SDK) that contains C header files, C libraries, tools, and example programs. To install the SKD, you download the compressed SDK package from the iPlanet web site on the Internet, and unpack the files to the directory of your choice. When you unpack the SDK, it will create several directories and populate them with the various files provided with the SDK. The directories and files supplied with the SDK are detailed in the sections below.
Directories Installed With the SDK
The LDAP SDK for C installation process creates several directories. These directories are populated with the files provided by the SDK. The table below outlines the directories that are created by the installation process:
Table 1-1    LDAP SDK for C directories
Directory
Description
include
This directory contains the header files for the LDAP SDK for C. In your client source files, you must include the files contained in this directory as described in the section "Include Files Supplied with the LDAP SDK for C."
lib
This directory contains the C library files provided with the LDAP SDK for C. For details on these files, see the section "Libraries Supplied with the LDAP SDK for C."
examples
This directory contains sample source code and makefiles for LDAP clients. See the README file in this directory for information about building these client programs.
tools
This directory contains the LDAP command-line tools. These are similar to the tools provided with the iPlanet Directory Server and are described in the iPlanet Directory Server Command and File Reference (see http://docs.iplanet.com/docs/manuals/directory/ for details).
Note that in order to use these applications, you need to make sure that the application can find the LDAP API shared library or dynamic link library, as described in the section "Libraries Supplied with the LDAP SDK for C."
docs
Initially this directory contains only the README file that is shipped with this version of the SDK. However, the directory is intended as a location for this guide (the LDAP SDK for C Programmer's Guide) and the associated product Release Notes, which you can download from the iPlanet documentation web site detailed in the README file.
Include Files Supplied with the LDAP SDK for C
The Netscape LDAP SDK for C ships with the following header files:
Libraries Supplied with the LDAP SDK for C
The Netscape LDAP SDK for C comes with several different library sets. The specific library files that you link with depend on the type of application(s) you are building. Table 1-3 outlines the library files provided with the Netscape LDAP SDK for C, v4.1:
Tools Supplied With the LDAP SDK for C
The LDAP SDK for C includes the following utilities that help you to work with LDAP data sets:
A list of options for each utility can be obtained by typing the utility name at the command line. For detailed documentation on these utilities, refer to the Command and File Reference shipped with the iPlanet Directory Server.
Compiling LDAP Clients
The Netscape LDAP SDK for C includes the header files and libraries for the LDAP API functions. You can include these header files and link to these libraries to enable your application to use LDAP.
Including the LDAP Header File
To make use of the functions contained in the LDAP SDK, whether you are developing on UNIX or in a 32-bit Windows system, you must include the ldap.h header file in your C source files. The following line of code shows as shown in the following line of code:The ldap.h header file declares the functions and structures contained in the LDAP API.
You do not need to explicitly include the lber.h header file; lber.h is already included in ldap.h.
If you are calling the LDAP SSL functions, you also need to include the ldap_ssl.h header file, as follows:
To make use of the Netscape Portable Runtime (NSPR) with your LDAP applications, you must include ldappr.h (this header file contains the prototypes for functions that tie the LDAP libraries to NSPR). You can find more information on NSPR in the ldappr.h header file and at the following URL:
http://www.mozilla.org/projects/nspr
Compiling Clients on UNIX
The Netscape LDAP SDK for C has an include directory that contains C header files and a lib directory that contains the shared libraries and objects to which you must link.When compiling clients on UNIX platforms, you need to link to the appropriate LDAP API shared library. On Solaris, AIX, Linux, and OSF, the shared library is libldapssl41.so. On HP-UX, the library is named libldapssl41.sl. For example, on Solaris, you would use the following link option:
Refer to the Makefile in the examples directory for details on compiling your applications.
Note The NSPR libraries are now distributed with the LDAP SDK for C. When linking with the SSL-enabled applications, you must also link with the NSPR libraries. For more information on the NSPR libraries, refer to the documentation at the following URL (follow the "Documentation and Training" link):
http://www.mozilla.org/projects/nspr/
If you linked the shared library, you need to make sure that the LDAP client can find the library. Do one of the following:
Make sure that the LDAP API shared library file (such as libldap41.so for Solaris) is in a standard location, as in /usr/lib. Alternatively, you can use environment variables to specify the library location.
See the makefile in the examples directory for examples of additional flags and defines that you might need to specify when compiling and linking your LDAP client. Different platforms might require different sets of define statements.On some platforms, if you have compiled your client with certain flags set, you can set an environment variable to specify the run-time path to check when loading libraries. If you do this, you can set this variable to the location of the LDAP library.
Use a link flag that specifies the path where the executable can find the library. For example, on Solaris, you can use the -R flag to specify the path where the executable can find the library.
- For example, on Solaris and Linux, you can use the LD_LIBRARY_PATH environment variable. On HP-UX, you can use the SHLIB_PATH environment variable if you use the -Wl,+s+b flag when compiling and linking. On AIX, you can use the LIBPATH environment variable.
Compiling Clients on 32-bit Windows Systems
When compiling clients on 32-bit Windows systems (Windows NT, Windows 95, Windows 98, and Windows ME), make sure to define _CONSOLE if you are writing a console application, or _WINDOWS if you are writing a standard Windows GUI application.Make sure to link to the LDAP API import library. The name of the library is nsldapssl32v41.lib for Microsoft compilers.
Make sure to copy the nsldap32v41.dll dynamic link library to a directory where your client can find it.
During run-time, your client searches for the LDAP API dynamic link library in the following locations:
The directory from which the application loaded.
The 32-bit Windows system directory, typically winnt\system32.
The Windows directory.
- Note that a version of the LDAP API DLL may already exist in this directory. For example, other iPlanet servers might install a different version of this DLL. To avoid potential conflicts, you should not install the DLL in this directory.
Running LDAP Application Programs
When you run LDAP clients on UNIX or Windows system, you must ensure that the operating system can find the libraries that support the LDAP functions that are called by your application. On UNIX, these files are called shared objects; on Windows, they are call Dynamic Link Libraries. Generally, these files are referred to as runtime libraries.
The UNIX Runtime Library Files
On Unix systems (such as Solaris, AIX, and HP-UX), the library files consist of a shared object library. When running clients built with these libraries, make sure to set the appropriate environment variable that specifies the run-time path used to find libraries.For example, on Solaris and Linux, set the LD_LIBRARY_PATH environment variable to the location of the shared library. On HP-UX, set the SHLIB_PATH environment variable if you are using the -Wl,+s+b flag to compile your client application. On AIX, set the LIBPATH environment variable.
The Windows Runtime Library Files
For Windows applications, the library files include an import library and a dynamic link library. When running clients built with these libraries, make sure to copy the dynamic link library to the directory containing your client or copy it to a location where the DLL can be found by the operating system.
The Example Programs
The Netscape LDAP SDK for C ships with several examples that demonstrate the use of the functions contained in the LDAP SDK for C library. This code was tested on a Solaris 2.6 machine and on a Windows NT 4.0 machine with Microsoft Visual C++ 6.0 SP3.Located in the examples directory of the installed the SDK, the example code assumes that you are running clients against a directory server that is compliant with LDAPv3 (such as the Netscape Directory Server, version 4.12) and that you have the sample database (airius.com) loaded on the server. (If you want to run the examples, you will need to have a working LDAP server running and the sample data contained in airius.com must be properly loaded.)
To compile and run these examples, refer to the README file contained in the examples directory. The Windows NT versions of the LDAP SDK for C include sample project files. Sample Visual C++ makefiles for a 32-bit Windows application (winldap) are included in the windows example directory. The Win32 version of the makefile is named winldap.mak.
Synchronous Examples
These samples use the synchronous LDAP calls. These function calls are more straightforward to use than their asynchronous counterparts. Because of this, it is suggested you look at these examples first.The synchronous calls block the calling process until all results have been returned, so they are probably not appropriate for use with clients that implement a graphical user interface (GUI) in a single-threaded environment because these programs usually rely on event loops. However, these sample programs fine for command-line clients and CGI programs.
Asynchronous Examples
These examples use the asynchronous LDAP calls. The general idea is that you begin an operation, and then periodically poll to see if any results have been returned.
Previous Contents Index DocHome Next
Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.
Last Updated November 16, 2000