Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libldap.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. """
  3. controls.libldap - LDAP controls wrapper classes with en-/decoding done
  4. by OpenLDAP functions
  5. See https://www.python-ldap.org/ for details.
  6. """
  7. from ldap.pkginfo import __version__
  8. import _ldap
  9. assert _ldap.__version__==__version__, \
  10. ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
  11. import ldap
  12. from ldap.controls import RequestControl,LDAPControl,KNOWN_RESPONSE_CONTROLS
  13. class AssertionControl(RequestControl):
  14. """
  15. LDAP Assertion control, as defined in RFC 4528
  16. filterstr
  17. LDAP filter string specifying which assertions have to match
  18. so that the server processes the operation
  19. """
  20. controlType = ldap.CONTROL_ASSERT
  21. def __init__(self,criticality=True,filterstr='(objectClass=*)'):
  22. self.criticality = criticality
  23. self.filterstr = filterstr
  24. def encodeControlValue(self):
  25. return _ldap.encode_assertion_control(self.filterstr)
  26. KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_ASSERT] = AssertionControl
  27. class MatchedValuesControl(RequestControl):
  28. """
  29. LDAP Matched Values control, as defined in RFC 3876
  30. filterstr
  31. LDAP filter string specifying which attribute values
  32. should be returned
  33. """
  34. controlType = ldap.CONTROL_VALUESRETURNFILTER
  35. def __init__(self,criticality=False,filterstr='(objectClass=*)'):
  36. self.criticality = criticality
  37. self.filterstr = filterstr
  38. def encodeControlValue(self):
  39. return _ldap.encode_valuesreturnfilter_control(self.filterstr)
  40. KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_VALUESRETURNFILTER] = MatchedValuesControl
  41. class SimplePagedResultsControl(LDAPControl):
  42. """
  43. LDAP Control Extension for Simple Paged Results Manipulation
  44. size
  45. Page size requested (number of entries to be returned)
  46. cookie
  47. Cookie string received with last page
  48. """
  49. controlType = ldap.CONTROL_PAGEDRESULTS
  50. def __init__(self,criticality=False,size=None,cookie=None):
  51. self.criticality = criticality
  52. self.size,self.cookie = size,cookie
  53. def encodeControlValue(self):
  54. return _ldap.encode_page_control(self.size,self.cookie)
  55. def decodeControlValue(self,encodedControlValue):
  56. self.size,self.cookie = _ldap.decode_page_control(encodedControlValue)
  57. KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_PAGEDRESULTS] = SimplePagedResultsControl