{ "info": { "author": "Giuseppe De Marco", "author_email": "giuseppe.demarco@unical.it", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "pyMultiLDAP\n-----\n\npyMultiLDAP can gather data from multiple LDAP servers, can do data aggregation and manipulation with rewrite rules.\npyMultiLDAP can act also as a proxy server, behind openldap's slapd-sock backend or any custom implementation.\n\n### Features\n\n- LDAP client to many servers as a single one;\n- Custom functions to manipulate returning data (rewrite rules);\n- Export data in python dictionary, json or ldiff format;\n- Proxy Server, exposing a server daemon usable with [slapd-sock backend](https://www.openldap.org/software/man.cgi?query=slapd-sock).\n\npyMultiLDAP do not write data to LDAP servers, it just permit us to handle readonly data\nin a way that could be very simple to automate smart data processing on-the-fly.\n\nSee `example/settings.py.example` and `multildap/attr_rewrite.py` to understand how to configure and extend it.\n\n### Tested on\n\n- Debian9;\n- Debian10.\n\n### Setup\nConfigure multiple connections and search paramenters in `settings.py`.\n\nInstall\n````\ngit clone https://github.com/peppelinux/pyMultiLDAP.git\ncd pyMultiLDAP\npip install -r requirements\npython3 setup.py install\n````\n\nor use pipy [WIP]\n\n````\npip install pyMultiLDAP\n````\n\n#### LdapClient Class usage\n````\nfrom multildap.client import LdapClient\nfrom settings import LDAP_CONNECTIONS\n\nlc = LdapClient(LDAP_CONNECTIONS['SAMVICE'])\n\n# get all the results\nlc.get()\n\n# apply a filter\nlc.get(search=\"(&(sn=de marco)(schacPersonalUniqueId=*DMRGPP83*))\")\n````\n\n##### Search and get\n\nSee `examples/run_test.py`.\n\nDifference between `.search` and `.get`:\n- *search* relyies on connection configuration and returns result as it come (raw);\n- *get* handles custom search filter and retrieve result as dictionary, json, ldif or python object format. It also apply rewrite rules.\n\n````\nimport copy\n\nfrom multildap.client import LdapClient\nfrom settings import LDAP_CONNECTIONS\n\nlc = LdapClient(LDAP_CONNECTIONS['DEFAULT'])\n\nkwargs = copy.copy(lc.conf)\nkwargs['search']['search_filter'] = \"(&(sn=de medici)(givenName=aurora))\"\nr = lc.search(**kwargs['search'])\n````\n\n#### Results in json format\n````\nfrom multildap.client import LdapClient\nfrom . settings import LDAP_CONNECTIONS\n\n\nfor i in LDAP_CONNECTIONS:\n lc = LdapClient(LDAP_CONNECTIONS[i])\n print('# Results from: {} ...'.format(lc))\n\n # get all as defined search_filter configured in settings connection\n # but in json format\n r = lc.get(format='json')\n print(r)\n\n # set a custom search as method argument\n r = lc.get(search=\"(&(sn=de marco)(schacPersonalUniqueId=*DMRGPP345tg86H))\", format='json')\n print(r)\n\n print('# End {}'.format(i))\n````\n\n#### Run the server\n\nNetwork address\n````\nmultildapd.py -conf settings.py -port 1234\n````\n\nUnix domain socket (for slapd-sock backend)\n````\nmultildapd.py -conf ./settings.py -loglevel \"DEBUG\" -socket /var/run/multildap.sock -pid /var/run/multildap.pid -uid openldap\n````\n\nDummy test without any ldap client connection configured, just to test slapd-sock:\n````\nmultildapd.py -conf ./settings.py -dummy -loglevel \"DEBUG\" -socket /var/run/multildap.sock -pid /var/run/multildap.pid\n````\n\nTest Unix domain socket from cli\n````\nnc -U /tmp/multildap.sock\n````\n\n#### Interfacing it with OpenLDAP slapd-sock\n\nThe [Slapd-sock](https://www.openldap.org/software/man.cgi?query=slapd-sock)\n backend to slapd uses an external program to handle\n queries. This makes it\n possible to have a pool of processes, which persist between requests.\n This allows multithreaded operation and a higher level of efficiency.\n Multildapd listens on a Unix domain socket and it must have been started independently;\n\nThis module may also be used as an overlay on top of some other\n database. Use as an overlay allows external actions to be triggered in\n response to operations on the main database.\n\n#### Configure slapd-sock as database\n\nAdd the module.\n````\nldapadd -Y EXTERNAL -H ldapi:/// <