File: __init__.py

package info (click to toggle)
python-ldap3 2.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,236 kB
  • sloc: python: 30,487; makefile: 3
file content (334 lines) | stat: -rw-r--r-- 14,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
"""
"""

# Created on 2014.04.28
#
# Author: Giovanni Cannata
#
# Copyright 2014 - 2020 Giovanni Cannata
#
# This file is part of ldap3.
#
# ldap3 is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ldap3 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ldap3 in the COPYING and COPYING.LESSER files.
# If not, see <http://www.gnu.org/licenses/>.

from os import linesep

from .. import SUBTREE, DEREF_ALWAYS, ALL_ATTRIBUTES, DEREF_NEVER
from .microsoft.dirSync import DirSync
from .microsoft.modifyPassword import ad_modify_password
from .microsoft.unlockAccount import ad_unlock_account
from .microsoft.addMembersToGroups import ad_add_members_to_groups
from .microsoft.removeMembersFromGroups import ad_remove_members_from_groups
from .microsoft.persistentSearch import ADPersistentSearch
from .novell.partition_entry_count import PartitionEntryCount
from .novell.replicaInfo import ReplicaInfo
from .novell.listReplicas import ListReplicas
from .novell.getBindDn import GetBindDn
from .novell.nmasGetUniversalPassword import NmasGetUniversalPassword
from .novell.nmasSetUniversalPassword import NmasSetUniversalPassword
from .novell.startTransaction import StartTransaction
from .novell.endTransaction import EndTransaction
from .novell.addMembersToGroups import edir_add_members_to_groups
from .novell.removeMembersFromGroups import edir_remove_members_from_groups
from .novell.checkGroupsMemberships import edir_check_groups_memberships
from .standard.whoAmI import WhoAmI
from .standard.modifyPassword import ModifyPassword
from .standard.PagedSearch import paged_search_generator, paged_search_accumulator
from .standard.PersistentSearch import PersistentSearch


class ExtendedOperationContainer(object):
    def __init__(self, connection):
        self._connection = connection

    def __repr__(self):
        return linesep.join(['  ' + element for element in dir(self) if element[0] != '_'])

    def __str__(self):
        return self.__repr__()


class StandardExtendedOperations(ExtendedOperationContainer):
    def who_am_i(self, controls=None):
        return WhoAmI(self._connection,
                      controls).send()

    def modify_password(self,
                        user=None,
                        old_password=None,
                        new_password=None,
                        hash_algorithm=None,
                        salt=None,
                        controls=None):

        return ModifyPassword(self._connection,
                              user,
                              old_password,
                              new_password,
                              hash_algorithm,
                              salt,
                              controls).send()

    def paged_search(self,
                     search_base,
                     search_filter,
                     search_scope=SUBTREE,
                     dereference_aliases=DEREF_ALWAYS,
                     attributes=None,
                     size_limit=0,
                     time_limit=0,
                     types_only=False,
                     get_operational_attributes=False,
                     controls=None,
                     paged_size=100,
                     paged_criticality=False,
                     generator=True):

        if generator:
            return paged_search_generator(self._connection,
                                          search_base,
                                          search_filter,
                                          search_scope,
                                          dereference_aliases,
                                          attributes,
                                          size_limit,
                                          time_limit,
                                          types_only,
                                          get_operational_attributes,
                                          controls,
                                          paged_size,
                                          paged_criticality)
        else:
            return paged_search_accumulator(self._connection,
                                            search_base,
                                            search_filter,
                                            search_scope,
                                            dereference_aliases,
                                            attributes,
                                            size_limit,
                                            time_limit,
                                            types_only,
                                            get_operational_attributes,
                                            controls,
                                            paged_size,
                                            paged_criticality)

    def persistent_search(self,
                          search_base='',
                          search_filter='(objectclass=*)',
                          search_scope=SUBTREE,
                          dereference_aliases=DEREF_NEVER,
                          attributes=ALL_ATTRIBUTES,
                          size_limit=0,
                          time_limit=0,
                          controls=None,
                          changes_only=True,
                          show_additions=True,
                          show_deletions=True,
                          show_modifications=True,
                          show_dn_modifications=True,
                          notifications=True,
                          streaming=True,
                          callback=None
                          ):
        events_type = 0
        if show_additions:
            events_type += 1
        if show_deletions:
            events_type += 2
        if show_modifications:
            events_type += 4
        if show_dn_modifications:
            events_type += 8

        if callback:
            streaming = False
        return PersistentSearch(self._connection,
                                search_base,
                                search_filter,
                                search_scope,
                                dereference_aliases,
                                attributes,
                                size_limit,
                                time_limit,
                                controls,
                                changes_only,
                                events_type,
                                notifications,
                                streaming,
                                callback)

    def funnel_search(self,
                      search_base='',
                      search_filter='',
                      search_scope=SUBTREE,
                      dereference_aliases=DEREF_NEVER,
                      attributes=ALL_ATTRIBUTES,
                      size_limit=0,
                      time_limit=0,
                      controls=None,
                      streaming=False,
                      callback=None
                      ):
        return PersistentSearch(self._connection,
                                search_base,
                                search_filter,
                                search_scope,
                                dereference_aliases,
                                attributes,
                                size_limit,
                                time_limit,
                                controls,
                                None,
                                None,
                                None,
                                streaming,
                                callback)


class NovellExtendedOperations(ExtendedOperationContainer):
    def get_bind_dn(self, controls=None):
        return GetBindDn(self._connection,
                         controls).send()

    def get_universal_password(self, user, controls=None):
        return NmasGetUniversalPassword(self._connection,
                                        user,
                                        controls).send()

    def set_universal_password(self, user, new_password=None, controls=None):
        return NmasSetUniversalPassword(self._connection,
                                        user,
                                        new_password,
                                        controls).send()

    def list_replicas(self, server_dn, controls=None):
        return ListReplicas(self._connection,
                            server_dn,
                            controls).send()

    def partition_entry_count(self, partition_dn, controls=None):
        return PartitionEntryCount(self._connection,
                                   partition_dn,
                                   controls).send()

    def replica_info(self, server_dn, partition_dn, controls=None):
        return ReplicaInfo(self._connection,
                           server_dn,
                           partition_dn,
                           controls).send()

    def start_transaction(self, controls=None):
        return StartTransaction(self._connection,
                                controls).send()

    def end_transaction(self, commit=True, controls=None):  # attach the groupingControl to commit, None to abort transaction
        return EndTransaction(self._connection,
                              commit,
                              controls).send()

    def add_members_to_groups(self, members, groups, fix=True, transaction=True):
        return edir_add_members_to_groups(self._connection,
                                          members_dn=members,
                                          groups_dn=groups,
                                          fix=fix,
                                          transaction=transaction)

    def remove_members_from_groups(self, members, groups, fix=True, transaction=True):
        return edir_remove_members_from_groups(self._connection,
                                               members_dn=members,
                                               groups_dn=groups,
                                               fix=fix,
                                               transaction=transaction)

    def check_groups_memberships(self, members, groups, fix=False, transaction=True):
        return edir_check_groups_memberships(self._connection,
                                             members_dn=members,
                                             groups_dn=groups,
                                             fix=fix,
                                             transaction=transaction)


class MicrosoftExtendedOperations(ExtendedOperationContainer):
    def dir_sync(self,
                 sync_base,
                 sync_filter='(objectclass=*)',
                 attributes=ALL_ATTRIBUTES,
                 cookie=None,
                 object_security=False,
                 ancestors_first=True,
                 public_data_only=False,
                 incremental_values=True,
                 max_length=2147483647,
                 hex_guid=False):
        return DirSync(self._connection,
                       sync_base=sync_base,
                       sync_filter=sync_filter,
                       attributes=attributes,
                       cookie=cookie,
                       object_security=object_security,
                       ancestors_first=ancestors_first,
                       public_data_only=public_data_only,
                       incremental_values=incremental_values,
                       max_length=max_length,
                       hex_guid=hex_guid)

    def modify_password(self, user, new_password, old_password=None, controls=None):
        return ad_modify_password(self._connection,
                                  user,
                                  new_password,
                                  old_password,
                                  controls)

    def unlock_account(self, user):
        return ad_unlock_account(self._connection,
                                 user)

    def add_members_to_groups(self, members, groups, fix=True):
        return ad_add_members_to_groups(self._connection,
                                        members_dn=members,
                                        groups_dn=groups,
                                        fix=fix)

    def remove_members_from_groups(self, members, groups, fix=True):
        return ad_remove_members_from_groups(self._connection,
                                             members_dn=members,
                                             groups_dn=groups,
                                             fix=fix)

    def persistent_search(self,
                          search_base='',
                          search_scope=SUBTREE,
                          attributes=ALL_ATTRIBUTES,
                          streaming=True,
                          callback=None
                          ):

        if callback:
            streaming = False
        return ADPersistentSearch(self._connection,
                                  search_base,
                                  search_scope,
                                  attributes,
                                  streaming,
                                  callback)


class ExtendedOperationsRoot(ExtendedOperationContainer):
    def __init__(self, connection):
        ExtendedOperationContainer.__init__(self, connection)  # calls super
        self.standard = StandardExtendedOperations(self._connection)
        self.novell = NovellExtendedOperations(self._connection)
        self.microsoft = MicrosoftExtendedOperations(self._connection)