The purpose of this script is to generate configuration file from LDAP entries.
It works using two more configuration files :
- The main configuration file: an ini form configuration containing
informations about the LDAP server, the file which will be created, logging,
etc. See
example.ini - A template file: Your configuraiton template, in jinja2. See
example.tpl
On invocation, ldap2config create a temporary file, then check if there is a
difference between it and the destination before moving it. After that, a script
can be called (for reloading a service, for example).
ldap2config is tested on python 2.7 and 3.5.
There is 4 sections :
[ldap]: which deal with the ldap server connexion[config]: which handle information about the generated configuration file[log]: to control the logging system[$search]: which is one or more sections for controling LDAP search filters. The section name is also the variable name used in template
Contain the following properties :
user: LDAP user (can be empty)pass: Password for given user (can be empty)host: LDAP Hostport: LDAP portsearches: List of search sections
template: Full path to the template file used to generatecfgfilecfgfile: Full path to the output fileowner:cfgfilefile ownergroup:cfgfilefile group ownermode:cfgfilefile rights (in numeric)on_change: Action to do when generated file and destination are different. You can set/bin/trueto do nothing
level: Log level, according to the pythonlogginglibrary
All search sections should contain the following :
base: LDAP base treescope: Search scope, as for LDAP can be (as in pythonldaplibrary) :ldap.SCOPE_BASE,ldap.SCOPE_ONELEVEL,ldap.SCOPE_SUBORDINATE,ldap.SCOPE_SUBTREE
filter: The filter stringattrs: List of attributes that should be returned
Create a configuration file then :
$ ldap2config.py configuration.ini
ldap2config is thinked to be used as a cron job.
That's why it use config.on_change instead of a return values that could
trigger useless mails.
I have few ideas of what can be done next :
- Redirect log output to file or syslog
- Hability to have a per search ldap configuration
For backward compatibility reasons, I don't use the standard python3 LDAP
library (ldap3), but pyldap.