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.

__init__.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. """
  2. """
  3. # Created on 2014.04.28
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2014 - 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 os import linesep
  25. from .. import SUBTREE, DEREF_ALWAYS, ALL_ATTRIBUTES, DEREF_NEVER
  26. from .microsoft.dirSync import DirSync
  27. from .microsoft.modifyPassword import ad_modify_password
  28. from .microsoft.unlockAccount import ad_unlock_account
  29. from .microsoft.addMembersToGroups import ad_add_members_to_groups
  30. from .microsoft.removeMembersFromGroups import ad_remove_members_from_groups
  31. from .novell.partition_entry_count import PartitionEntryCount
  32. from .novell.replicaInfo import ReplicaInfo
  33. from .novell.listReplicas import ListReplicas
  34. from .novell.getBindDn import GetBindDn
  35. from .novell.nmasGetUniversalPassword import NmasGetUniversalPassword
  36. from .novell.nmasSetUniversalPassword import NmasSetUniversalPassword
  37. from .novell.startTransaction import StartTransaction
  38. from .novell.endTransaction import EndTransaction
  39. from .novell.addMembersToGroups import edir_add_members_to_groups
  40. from .novell.removeMembersFromGroups import edir_remove_members_from_groups
  41. from .novell.checkGroupsMemberships import edir_check_groups_memberships
  42. from .standard.whoAmI import WhoAmI
  43. from .standard.modifyPassword import ModifyPassword
  44. from .standard.PagedSearch import paged_search_generator, paged_search_accumulator
  45. from .standard.PersistentSearch import PersistentSearch
  46. class ExtendedOperationContainer(object):
  47. def __init__(self, connection):
  48. self._connection = connection
  49. def __repr__(self):
  50. return linesep.join([' ' + element for element in dir(self) if element[0] != '_'])
  51. def __str__(self):
  52. return self.__repr__()
  53. class StandardExtendedOperations(ExtendedOperationContainer):
  54. def who_am_i(self, controls=None):
  55. return WhoAmI(self._connection,
  56. controls).send()
  57. def modify_password(self,
  58. user=None,
  59. old_password=None,
  60. new_password=None,
  61. hash_algorithm=None,
  62. salt=None,
  63. controls=None):
  64. return ModifyPassword(self._connection,
  65. user,
  66. old_password,
  67. new_password,
  68. hash_algorithm,
  69. salt,
  70. controls).send()
  71. def paged_search(self,
  72. search_base,
  73. search_filter,
  74. search_scope=SUBTREE,
  75. dereference_aliases=DEREF_ALWAYS,
  76. attributes=None,
  77. size_limit=0,
  78. time_limit=0,
  79. types_only=False,
  80. get_operational_attributes=False,
  81. controls=None,
  82. paged_size=100,
  83. paged_criticality=False,
  84. generator=True):
  85. if generator:
  86. return paged_search_generator(self._connection,
  87. search_base,
  88. search_filter,
  89. search_scope,
  90. dereference_aliases,
  91. attributes,
  92. size_limit,
  93. time_limit,
  94. types_only,
  95. get_operational_attributes,
  96. controls,
  97. paged_size,
  98. paged_criticality)
  99. else:
  100. return paged_search_accumulator(self._connection,
  101. search_base,
  102. search_filter,
  103. search_scope,
  104. dereference_aliases,
  105. attributes,
  106. size_limit,
  107. time_limit,
  108. types_only,
  109. get_operational_attributes,
  110. controls,
  111. paged_size,
  112. paged_criticality)
  113. def persistent_search(self,
  114. search_base='',
  115. search_filter='(objectclass=*)',
  116. search_scope=SUBTREE,
  117. dereference_aliases=DEREF_NEVER,
  118. attributes=ALL_ATTRIBUTES,
  119. size_limit=0,
  120. time_limit=0,
  121. controls=None,
  122. changes_only=True,
  123. show_additions=True,
  124. show_deletions=True,
  125. show_modifications=True,
  126. show_dn_modifications=True,
  127. notifications=True,
  128. streaming=True,
  129. callback=None
  130. ):
  131. events_type = 0
  132. if show_additions:
  133. events_type += 1
  134. if show_deletions:
  135. events_type += 2
  136. if show_modifications:
  137. events_type += 4
  138. if show_dn_modifications:
  139. events_type += 8
  140. if callback:
  141. streaming = False
  142. return PersistentSearch(self._connection,
  143. search_base,
  144. search_filter,
  145. search_scope,
  146. dereference_aliases,
  147. attributes,
  148. size_limit,
  149. time_limit,
  150. controls,
  151. changes_only,
  152. events_type,
  153. notifications,
  154. streaming,
  155. callback)
  156. class NovellExtendedOperations(ExtendedOperationContainer):
  157. def get_bind_dn(self, controls=None):
  158. return GetBindDn(self._connection,
  159. controls).send()
  160. def get_universal_password(self, user, controls=None):
  161. return NmasGetUniversalPassword(self._connection,
  162. user,
  163. controls).send()
  164. def set_universal_password(self, user, new_password=None, controls=None):
  165. return NmasSetUniversalPassword(self._connection,
  166. user,
  167. new_password,
  168. controls).send()
  169. def list_replicas(self, server_dn, controls=None):
  170. return ListReplicas(self._connection,
  171. server_dn,
  172. controls).send()
  173. def partition_entry_count(self, partition_dn, controls=None):
  174. return PartitionEntryCount(self._connection,
  175. partition_dn,
  176. controls).send()
  177. def replica_info(self, server_dn, partition_dn, controls=None):
  178. return ReplicaInfo(self._connection,
  179. server_dn,
  180. partition_dn,
  181. controls).send()
  182. def start_transaction(self, controls=None):
  183. return StartTransaction(self._connection,
  184. controls).send()
  185. def end_transaction(self, commit=True, controls=None): # attach the groupingControl to commit, None to abort transaction
  186. return EndTransaction(self._connection,
  187. commit,
  188. controls).send()
  189. def add_members_to_groups(self, members, groups, fix=True, transaction=True):
  190. return edir_add_members_to_groups(self._connection,
  191. members_dn=members,
  192. groups_dn=groups,
  193. fix=fix,
  194. transaction=transaction)
  195. def remove_members_from_groups(self, members, groups, fix=True, transaction=True):
  196. return edir_remove_members_from_groups(self._connection,
  197. members_dn=members,
  198. groups_dn=groups,
  199. fix=fix,
  200. transaction=transaction)
  201. def check_groups_memberships(self, members, groups, fix=False, transaction=True):
  202. return edir_check_groups_memberships(self._connection,
  203. members_dn=members,
  204. groups_dn=groups,
  205. fix=fix,
  206. transaction=transaction)
  207. class MicrosoftExtendedOperations(ExtendedOperationContainer):
  208. def dir_sync(self,
  209. sync_base,
  210. sync_filter='(objectclass=*)',
  211. attributes=ALL_ATTRIBUTES,
  212. cookie=None,
  213. object_security=False,
  214. ancestors_first=True,
  215. public_data_only=False,
  216. incremental_values=True,
  217. max_length=2147483647,
  218. hex_guid=False):
  219. return DirSync(self._connection,
  220. sync_base=sync_base,
  221. sync_filter=sync_filter,
  222. attributes=attributes,
  223. cookie=cookie,
  224. object_security=object_security,
  225. ancestors_first=ancestors_first,
  226. public_data_only=public_data_only,
  227. incremental_values=incremental_values,
  228. max_length=max_length,
  229. hex_guid=hex_guid)
  230. def modify_password(self, user, new_password, old_password=None, controls=None):
  231. return ad_modify_password(self._connection,
  232. user,
  233. new_password,
  234. old_password,
  235. controls)
  236. def unlock_account(self, user):
  237. return ad_unlock_account(self._connection,
  238. user)
  239. def add_members_to_groups(self, members, groups, fix=True):
  240. return ad_add_members_to_groups(self._connection,
  241. members_dn=members,
  242. groups_dn=groups,
  243. fix=fix)
  244. def remove_members_from_groups(self, members, groups, fix=True):
  245. return ad_remove_members_from_groups(self._connection,
  246. members_dn=members,
  247. groups_dn=groups,
  248. fix=fix)
  249. class ExtendedOperationsRoot(ExtendedOperationContainer):
  250. def __init__(self, connection):
  251. ExtendedOperationContainer.__init__(self, connection) # calls super
  252. self.standard = StandardExtendedOperations(self._connection)
  253. self.novell = NovellExtendedOperations(self._connection)
  254. self.microsoft = MicrosoftExtendedOperations(self._connection)