Next: , Previous: , Up: Top   [Contents][Index]


5 LDAP as a DBM Database

You can use LDAP as a storage backend for DBM database, accessible using MFL db* functions (see Database Functions in Mailfromd Manual). Any number of such databases can be defined, allowing for different key ⇒ value mappings.

An LDAP-backed database is defined using the following function:

Function: void ldap_define_db (string name, string base, string get_filter, string resp_fmt, string seq_filter, string key_fmt)

Defines new database. Arguments:

name

Name of the database. The new database can be accessed as ‘ldap://name’.

base

Base DN. If empty, the default base DN (as configured in ldap.conf will be used.

get_filter

Template string for generating LDAP filter for use by dbget routine. It can get refer to at most one input attribute using the syntax ‘$attr’ or ‘${attr}’. For example, if this argument is given as

'(&(objectClass=posixAccount)(uid=$uid))'

then the call to ‘dbget("smith")’ will use the following filter string when accessing the LDAP database: ‘(&(objectClass=posixAccount)(uid=smith))’.

resp_fmt

A format string used to convert the returned LDAP object to a string. It can refer to object’s attributes using the same syntax as described for get_filter. Any number of attribute references is allowed. Example:

'"$cn" <$mail>'
seq_filter

Template string used to generate filter for sequential access to the database (see Sequential Access in Mailfromd Manual). It will be used as is, no attribute references are allowed.

Normally this filter is a sub-set of get_filter, e.g.:

'(objectClass=posixAccount)'
key_fmt

A format string used to convert the returned LDAP object to a key string. The syntax is as described under resp_fmt. Calling dbget with the resulting string as argument must return the object used as input to generate the key.

An example usage:

prog begin
do
  ldap_define_db('users', 'ou=People,dc=example,dc=org',
                 '(&(objectClass=posixAccount)(uid=${uid}))',
                 '"$cn" <$mail>',
                 '(objectClass=posixAccount)',
                 '$uid')
done

The defined database maps the user ID to their full email address. It can be addressed as ‘ldap://users’. For example:

set email dbget('ldap://users')

or

#pragma dbprop users ldap://
...
set email dbget('users')

The following code fragment illustrates the use of sequential access functions to list all user emails:

#pragma dbprop users ldap://

func main(...)
  returns number
do
  loop for number dbn dbfirst('users')
  do
    echo dbkey(dbn)." ".dbvalue(dbn)
  done while dbnext(dbn)
done

Next: , Previous: , Up: Top   [Contents][Index]