[Date Prev][Date Next] [Chronological] [Thread] [Top]

OpenLDAP with PostgreSQL Backend (ITS#1454)

Full_Name: Gilles DAROLD
Version: 2.0.18
OS: Linux
URL: http://www.samse.fr/GPL/ldap_pg/ldap_pg.tar.gz 
Submission from: (NULL) (

OpenLDAP need five small patches to have OpenLDAP working with PostgreSQL.

1) servers/slapd/back-sql/search.c

The first patch is used to cast the objectClass statement into search queries.
I've defined a new slapd.conf option named 'oc_cast' to be portable to other
RDBMS that could need this feature. This option allow a call to a cast
For PostgreSQL it must be set to 'text' that will result as the following query
for example:

SELECT DISTINCT ldap_entries.id,documents.id, text('document') AS objectClass,
                ldap_entries.dn AS dn FROM ldap_entries,documents
   WHERE documents.id=ldap_entries.keyval AND ldap_entries.oc_map_id=2
   AND ldap_entries.parent=1 AND NOT ('document' IS NULL)

In the slapd.conf it is set as:

oc_cast		"text"

A more portable way should be to implement a pattern replacement to allow more
syntax. For example the followings setting are both possible with PostgreSQL:

oc_cast		"text(?)"
oc_cast		"?::text"

My knowledge in C++ is not enougth to code that, if someone is easy with this
it should be a good contribution to portability over all RDBMS backend.

2) servers/slapd/back-sql/entry-id.c

The second patch is used to preserve the alias name of a column in the SQL
This feature is not yet implemented into the ODBC driver for PostgreSQL and
some other RDBMS driver. Hiroshi Inoue that handle the PostgreSQL ODBC driver
that it will be fixed into the next release but other SQL backend could need
patch too.

For example the following SQL query:

	SELECT persons.name AS sn FROM persons WHERE persons.id=2

may return 'sn' as column named that it was not done. So the patch force the
to be at->name intstead of row.col_names[i].

3) servers/slapd/back-sql/modify.c

The third patch concerne the update of the internal unique id (new_keyval) that
expected to be modified by the 'create_proc' procedure call as a parameter
by reference to the SQL procedure used to create the new entry.
With PostgreSQL you can't pass a parameter to SQL function by reference like
Oracle (INOUT param), it simply receive parameters and return a result. So to
this problem that can also be found in other SQL backend I have added an other
configuration option called 'id_notbyref' that activate the update of the
by reading the value return as result of the SQL procedure.

Usage in slapd.conf is:

	id_notbyref	"1"

4) server/slapd/back-sql.h and servers/slapd/back-sql/config.c

The two other patches concerne the definition and the retrieving of the two new
configuration options that may be used into the slapd.conf to have PostgreSQL


I think that these patches should improve support to many other SQL backend
without any change to the current supported SQL backend and any change into the
running slapd.conf.

There's still a problem when you use a openLDAP SQL backend as slave server
seems to affect all RDBMS: back-sql doesn't support the ManageDsaIT...

In the uploading URL I have made a tarball including:

- all these patches,
- the HOWTO explaining the implementation of PostgreSQL as OpenLDAP backend
  (can also be usefull for other RDBMS)
- the rdbms_depend/postgres/directory with all SQL test scripts and the odbc
- and some LDIFF file to test the installation as explained in the HOWTO

Let me know if you need more information.

I will add a live example of the back-sql implementation into the HOWTO asap.