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.

dirSync.py 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. """
  3. # Created on 2015.10.21
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2015 - 2018 Giovanni Cannata
  8. #
  9. # This file is part of ldap3.
  10. #
  11. # ldap3 is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Lesser General Public License as published
  13. # by the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # ldap3 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Lesser General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Lesser General Public License
  22. # along with ldap3 in the COPYING and COPYING.LESSER files.
  23. # If not, see <http://www.gnu.org/licenses/>.
  24. from ...core.exceptions import LDAPExtensionError
  25. from ...protocol.microsoft import dir_sync_control, extended_dn_control, show_deleted_control
  26. from ... import SUBTREE, DEREF_NEVER
  27. from ...utils.dn import safe_dn
  28. class DirSync(object):
  29. def __init__(self,
  30. connection,
  31. sync_base,
  32. sync_filter,
  33. attributes,
  34. cookie,
  35. object_security,
  36. ancestors_first,
  37. public_data_only,
  38. incremental_values,
  39. max_length,
  40. hex_guid
  41. ):
  42. self.connection = connection
  43. if self.connection.check_names and sync_base:
  44. self. base = safe_dn(sync_base)
  45. else:
  46. self.base = sync_base
  47. self.filter = sync_filter
  48. self.attributes = attributes
  49. self.cookie = cookie
  50. self.object_security = object_security
  51. self.ancestors_first = ancestors_first
  52. self.public_data_only = public_data_only
  53. self.incremental_values = incremental_values
  54. self.max_length = max_length
  55. self.hex_guid = hex_guid
  56. self.more_results = True
  57. def loop(self):
  58. result = self.connection.search(search_base=self.base,
  59. search_filter=self.filter,
  60. search_scope=SUBTREE,
  61. attributes=self.attributes,
  62. dereference_aliases=DEREF_NEVER,
  63. controls=[dir_sync_control(criticality=True,
  64. object_security=self.object_security,
  65. ancestors_first=self.ancestors_first,
  66. public_data_only=self.public_data_only,
  67. incremental_values=self.incremental_values,
  68. max_length=self.max_length, cookie=self.cookie),
  69. extended_dn_control(criticality=False, hex_format=self.hex_guid),
  70. show_deleted_control(criticality=False)]
  71. )
  72. if not self.connection.strategy.sync:
  73. response, result = self.connection.get_response(result)
  74. else:
  75. response = self.connection.response
  76. result = self.connection.result
  77. if result['description'] == 'success' and 'controls' in result and '1.2.840.113556.1.4.841' in result['controls']:
  78. self.more_results = result['controls']['1.2.840.113556.1.4.841']['value']['more_results']
  79. self.cookie = result['controls']['1.2.840.113556.1.4.841']['value']['cookie']
  80. return response
  81. elif 'controls' in result:
  82. raise LDAPExtensionError('Missing DirSync control in response from server')
  83. else:
  84. raise LDAPExtensionError('error %r in DirSync' % result)