Team Ai
Datasetpublic

codekingpro/portable-devtools

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