Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
persistentSearch.py86 linesDownload Raw Back to protocol
1"""
2"""
3
4# Created on 2016.07.09
5#
6# Author: Giovanni Cannata
7#
8# Copyright 2016 - 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 pyasn1.type.namedtype import NamedTypes, NamedType, OptionalNamedType
27from pyasn1.type.namedval import NamedValues
28from pyasn1.type.univ import Sequence, Integer, Boolean, Enumerated
29from .rfc4511 import LDAPDN
30from .controls import build_control
31
32
33class PersistentSearchControl(Sequence):
34    # PersistentSearch ::= SEQUENCE {
35    #     changeTypes INTEGER,
36    #     changesOnly BOOLEAN,
37    #     returnECs BOOLEAN
38    # }
39
40    componentType = NamedTypes(NamedType('changeTypes', Integer()),
41                               NamedType('changesOnly', Boolean()),
42                               NamedType('returnECs', Boolean())
43                               )
44
45
46class ChangeType(Enumerated):
47    # changeType ENUMERATED {
48    #     add             (1),
49    #     delete          (2),
50    #     modify          (4),
51    #     modDN           (8)
52    #     }
53
54    namedValues = NamedValues(('add', 1),
55                              ('delete', 2),
56                              ('modify', 4),
57                              ('modDN', 8))
58
59
60class EntryChangeNotificationControl(Sequence):
61    # EntryChangeNotification ::= SEQUENCE {
62    #     changeType ENUMERATED {
63    #         add             (1),
64    #         delete          (2),
65    #         modify          (4),
66    #         modDN           (8)
67    #     },
68    #     previousDN   LDAPDN OPTIONAL,     -- modifyDN ops. only
69    #     changeNumber INTEGER OPTIONAL     -- if supported
70    # }
71
72    # tagSet = TagSet()
73    # tagSet = Sequence.tagSet.tagImplicitly(Tag(tagClassUniversal, tagFormatConstructed, 16))
74    componentType = NamedTypes(NamedType('changeType', ChangeType()),
75                               OptionalNamedType('previousDN', LDAPDN()),
76                               OptionalNamedType('changeNumber', Integer())
77                               )
78
79
80def persistent_search_control(change_types, changes_only=True, return_ecs=True, criticality=False):
81    control_value = PersistentSearchControl()
82    control_value.setComponentByName('changeTypes', Integer(change_types))
83    control_value.setComponentByName('changesOnly', Boolean(changes_only))
84    control_value.setComponentByName('returnECs', Boolean(return_ecs))
85    return build_control('2.16.840.1.113730.3.4.3', criticality, control_value)
86 
codekingpro/portable-devtools · Team Ai