authLdap.py 683 B

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. import sys, ldap, syslog
  3. from radicale import config, log
  4. def has_right(owner, user, password):
  5. if user == None:
  6. user=""
  7. if password == None:
  8. password=""
  9. if owner != user:
  10. return False
  11. try:
  12. log.log(10, "Open LDAP server connexion")
  13. l=ldap.open(LDAPSERVER, 389)
  14. cn="%s%s,%s" % (LDAPPREPEND, user, LDAPAPPEND)
  15. log.log(10, "LDAP bind with dn: %s" %(cn))
  16. l.simple_bind_s(cn, password);
  17. log.log(20, "LDAP bind Ok")
  18. return True
  19. except:
  20. log.log(40, "LDAP bind error")
  21. return False
  22. LDAPSERVER = config.get("authLdap", "LDAPServer")
  23. LDAPPREPEND = config.get("authLdap", "LDAPPrepend")
  24. LDAPAPPEND = config.get("authLdap", "LDAPAppend")