Placeholder Image

ADN Informatique

Consultant Ingénierie Informatique

Saguenay (Jonquière), Québec, Canada. Tél: (581) 683-9887 Téléc: (581) 221-0874

Placeholder Picture

Retour

LDAP

2008-01-22 14:51:56 (ID: 40, Parent: 33, Type: page)
LDAP Mini How-To
1.0 - What is LDAP
2.0 - Downloading LDAP 3.0 - Setup 4.0 - Other source of information 5.0 - Software that use LDAP  1.0 - What is LDAP?LDAP stands for Lightweight Directory Access Protocol. As the name suggests, it is a lightweight client-server protocol for accessing directory services, specifically X.500-based directory services. LDAP runs over TCP/IP or other connection oriented transfer services. LDAP is defined in RFC2251 "The Lightweight Directory Access Protocol (v3).

More informations could be found on the net, do a search on www.google.com and you'll be able to answer that question in a more detailled way.

2.0 - Downloading LDAP 2.1 - LDAP Server software  2.1.1 - Downloading/Compiling OpenLDAP Server As a prerequisite you must install Berkeley DB
gunzip and untar bdb-x
cd into the bdb-x/build_unix directory and execute ../dist/configure
after that you could make and make install

Dowload open ldap from the official site www.openldap.org

After that, cd into the openldap-x directory and execute ./configure
after that make depend, make and make install.

2.1.2 - Basic configuration file
2.1.3 - Starting the ldap deamon

2.2 - LDAP Client software LDAP Browser/Editor

2.3 - LDAP Library 2.3.1 - Using LDAP from C/C++ Open LDAP install a default c/c++ library
here are some example of how to use it.
Sample Code
Netscape Directory SDK man pages

Here is a sample and how to compile/run it.
== start of test.cpp ==
#include <stdio.h>
#include "ldap.h"

/* Adjust these setting for your own LDAP server */
#define HOSTNAME "ldap.grafsoft.com"
#define PORT_NUMBER  LDAP_PORT
//Find a record
#define FIND_DN "cn=jlcyr,dc=grafsoft,dc=com"
// Find all records
//#define FIND_DN "dc=grafsoft,dc=com"

int
main( int argc, char **argv )
{
LDAP         *ld;
LDAPMessage  *result, *e;
BerElement   *ber;
char         *a;
char         **vals;
int          i, rc;

/* Set LDAP version to 3 */
int          version;
version = LDAP_VERSION3;
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &version);

/* Get a handle to an LDAP connection. */
if ( (ld = ldap_init( HOSTNAME, PORT_NUMBER )) == NULL ) {
perror( "ldap_init" );
return( 1 );
}

/* Bind with a user/password */
//  rc = ldap_simple_bind_s( ld, "cn=Manager,dc=grafsoft,dc=com", "ldappass123" );

  /* Bind anonymously to the LDAP server. */
  rc = ldap_simple_bind_s( ld, NULL, NULL );

if ( rc != LDAP_SUCCESS ) {
fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc));
return( 1 );
}

/* Search for the entry. */
/* Possibles scope are
LDAP_SCOPE_BASE
LDAP_SCOPE_ONELEVEL
LDAP_SCOPE_SUBTREE
*/
if ( ( rc = ldap_search_ext_s( ld, FIND_DN, LDAP_SCOPE_BASE,
"(objectclass=*)", NULL, 0, NULL, NULL, LDAP_NO_LIMIT,
LDAP_NO_LIMIT, &result ) ) != LDAP_SUCCESS ) {
fprintf(stderr, "ldap_search_ext_s: %s\n", ldap_err2string(rc));
return( 1 );
}

/* Since we are doing a base search, there should be only
one matching entry. */
e = ldap_first_entry( ld, result );
while ( e != NULL ) {
printf( "\nFound %s:\n\n", FIND_DN );

/* Iterate through each attribute in the entry. */
for ( a = ldap_first_attribute( ld, e, &ber );
a != NULL; a = ldap_next_attribute( ld, e, ber ) ) {

/* For each attribute, print the attribute name and values. */
if ((vals = ldap_get_values( ld, e, a)) != NULL ) {
for ( i = 0; vals[i] != NULL; i++ ) {
printf( "%s: %s\n", a, vals[i] );
}
ldap_value_free( vals );
}
ldap_memfree( a );
}
if ( ber != NULL ) {
ber_free( ber, 0 );
}
e = ldap_next_entry( ld, e );
}
ldap_msgfree( result );
ldap_unbind( ld );
return( 0 );
}
== end of test.cpp ==
simply compile with gcc test.cpp -lldap and run a.out.

2.3.2 - Using PHP Here is some sample in php using the ldap library.
Note: You must enable ldap support while compiling php


3.0 - Setup
4.0 - Other source of information 4.1 - Other informations on the net
OpenLDAP web site
OpenLDAP 2.2 Administrator Guide
LDAP Linux How-To
Commercial and OpenSource software list
LDAP Guru
LDAP Zone

http://dmoz.org/Computers/Security/Authentication/

4.2 - Obtaining an registered OID

You can get one from IANA at http://www.iana.org/cgi-bin/enterprise.pl
Or from canadian registration (COSIRA) at http://www.pwgsc.gc.ca/cosira/text/index-e.html

5.0 - Software that use LDAP 5.1 - Browser Netscape Directory Server FAQ

Document Informatif

ADN Informatique

2015

Rev. 1

Jean-Luc Cyr