diff --git a/config b/config index 670dd3c7..03e1457a 100644 --- a/config +++ b/config @@ -38,6 +38,16 @@ filename = /etc/radicale/users # Value: plain | sha1 | crypt encryption = crypt +[authLdap] +#LDAP Host +LDAPServer = 127.0.0.1 +#Fields to create a LDAP bind +#Value to add before the user name in a LDAP bind +LDAPPrepend = uid= +#Value to add after the user name in a LDAP bind +LDAPAppend = ou=users,dc=exmaple,dc=dom +#=> uid=corentin,ou=users,dc=exmaple,dc=dom + [storage] # Folder for storing local calendars, # created if not present diff --git a/radicale/__init__.py b/radicale/__init__.py index c8a0794c..1a7afbc3 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -56,7 +56,6 @@ VERSION = "git" def _check(request, function): """Check if user has sufficient rights for performing ``request``.""" - # If we have no calendar or no acl, don't check rights if not request._calendar or not request.server.acl: return function(request) diff --git a/radicale/acl/authLdap.py b/radicale/acl/authLdap.py new file mode 100644 index 00000000..c9c67d23 --- /dev/null +++ b/radicale/acl/authLdap.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +import sys +import ldap +import radicale + +LDAPSERVER = config.get("authLdap", "LDAPServer") +LDAPPREPEND = config.get("authLdap", "LDAPPrepend") +LDAPAPPEND = config.get("authLdap", "LDAPAppend") + +def has_right(owner, user, password): + if user == None: + user="" + if password == None: + password="" + if owner != user: + return False + try: + radicale.log.LOGGER.info("Open LDAP server connexion") + l=ldap.open(LDAPSERVER, 389) + cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND) + radicale.log.LOGGER.info("LDAP bind with dn: %s" % (cn)) + l.simple_bind_s(cn, password); + radicale.log.LOGGER.info("LDAP bind ok") + return True + except: + radicale.log.LOGGER.info("Nu such credential") + return False diff --git a/radicale/config.py b/radicale/config.py index 014baae0..c285ca03 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -56,7 +56,11 @@ INITIAL_CONFIG = { "folder": os.path.expanduser("~/.config/radicale/calendars")}, "logging": { "config": "/etc/radicale/logging", - "debug": "False"}} + "debug": "False"}, + "authLdap": { + "LDAPServer": "127.0.0.1", + "LDAPPrepend": "uid=", + "LDAPAppend": "ou=users,dc=example,dc=com"}} # Create a ConfigParser and configure it _CONFIG_PARSER = ConfigParser() diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index ed73c170..fe9ed33c 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -29,7 +29,7 @@ in them for XML requests (all but PUT). import xml.etree.ElementTree as ET -from radicale import client, config, ical +from radicale import client, config, ical, log NAMESPACES = { @@ -83,11 +83,11 @@ def propfind(path, xml_request, calendar, depth): """Read and answer PROPFIND requests. Read rfc4918-9.1 for info. - + """ # Reading request root = ET.fromstring(xml_request) - + prop_element = root.find(_tag("D", "prop")) prop_list = prop_element.getchildren() props = [prop.tag for prop in prop_list]