Jelajahi Sumber

Merge commit 'refs/merge-requests/8' of gitorious.org:radicale/radicale into merge-requests/8

Guillaume Ayoub 15 tahun lalu
induk
melakukan
43a1886546
5 mengubah file dengan 46 tambahan dan 5 penghapusan
  1. 10 0
      config
  2. 0 1
      radicale/__init__.py
  3. 28 0
      radicale/acl/authLdap.py
  4. 5 1
      radicale/config.py
  5. 3 3
      radicale/xmlutils.py

+ 10 - 0
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

+ 0 - 1
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)
 

+ 28 - 0
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

+ 5 - 1
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()

+ 3 - 3
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]