Skip to content

Commit a4e5908

Browse files
committed
Control and extop rework
1 parent e75c24d commit a4e5908

File tree

15 files changed

+66
-66
lines changed

15 files changed

+66
-66
lines changed

Lib/ldap/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
if k.startswith('OPT_'):
4444
OPT_NAMES_DICT[v]=k
4545

46+
# OID to class registries
47+
KNOWN_RESPONSE_CONTROLS = {}
48+
KNOWN_INTERMEDIATE_RESPONSES = {}
49+
KNOWN_EXTENDED_RESPONSES = {}
50+
51+
4652
class DummyLock:
4753
"""Define dummy class with methods compatible to threading.Lock"""
4854
def __init__(self):

Lib/ldap/controls/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
ImportError(f'ldap {__version__} and _ldap {_ldap.__version__} version mismatch!')
1616

1717
import ldap
18+
from ldap import KNOWN_RESPONSE_CONTROLS
1819

1920
from pyasn1.error import PyAsn1Error
2021

2122

2223
__all__ = [
23-
'KNOWN_RESPONSE_CONTROLS',
2424
# Classes
2525
'AssertionControl',
2626
'BooleanControl',
@@ -37,9 +37,6 @@
3737
'DecodeControlTuples',
3838
]
3939

40-
# response control OID to class registry
41-
KNOWN_RESPONSE_CONTROLS = {}
42-
4340

4441
class RequestControl:
4542
"""
@@ -77,6 +74,12 @@ class ResponseControl:
7774
sets the criticality of the received control (boolean)
7875
"""
7976

77+
def __init_subclass__(cls):
78+
if not getattr(cls, 'controlType', None):
79+
return
80+
81+
KNOWN_RESPONSE_CONTROLS.setdefault(cls.controlType, cls)
82+
8083
def __init__(self,controlType=None,criticality=False):
8184
self.controlType = controlType
8285
self.criticality = criticality

Lib/ldap/controls/deref.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
]
1212

1313
import ldap.controls
14-
from ldap.controls import LDAPControl,KNOWN_RESPONSE_CONTROLS
14+
from ldap.controls import LDAPControl
1515

1616
import pyasn1_modules.rfc2251
1717
from pyasn1.type import namedtype,univ,tag
@@ -114,5 +114,3 @@ def decodeControlValue(self,encodedControlValue):
114114
self.derefRes[str(deref_attr)].append((str(deref_val),partial_attrs_dict))
115115
except KeyError:
116116
self.derefRes[str(deref_attr)] = [(str(deref_val),partial_attrs_dict)]
117-
118-
KNOWN_RESPONSE_CONTROLS[DereferenceControl.controlType] = DereferenceControl

Lib/ldap/controls/libldap.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import ldap
1515

16-
from ldap.controls import RequestControl,LDAPControl,KNOWN_RESPONSE_CONTROLS
16+
from ldap.controls import RequestControl,LDAPControl
1717

1818

1919
class AssertionControl(RequestControl):
@@ -33,8 +33,6 @@ def __init__(self,criticality=True,filterstr='(objectClass=*)'):
3333
def encodeControlValue(self):
3434
return _ldap.encode_assertion_control(self.filterstr)
3535

36-
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_ASSERT] = AssertionControl
37-
3836

3937
class MatchedValuesControl(RequestControl):
4038
"""
@@ -54,8 +52,6 @@ def __init__(self,criticality=False,filterstr='(objectClass=*)'):
5452
def encodeControlValue(self):
5553
return _ldap.encode_valuesreturnfilter_control(self.filterstr)
5654

57-
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_VALUESRETURNFILTER] = MatchedValuesControl
58-
5955

6056
class SimplePagedResultsControl(LDAPControl):
6157
"""
@@ -77,5 +73,3 @@ def encodeControlValue(self):
7773

7874
def decodeControlValue(self,encodedControlValue):
7975
self.size,self.cookie = _ldap.decode_page_control(encodedControlValue)
80-
81-
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_PAGEDRESULTS] = SimplePagedResultsControl

Lib/ldap/controls/openldap.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ def decodeControlValue(self,encodedControlValue):
3939
self.numSearchContinuations = int(decodedValue[2])
4040

4141

42-
ldap.controls.KNOWN_RESPONSE_CONTROLS[SearchNoOpControl.controlType] = SearchNoOpControl
43-
44-
4542
class SearchNoOpMixIn:
4643
"""
4744
Mix-in class to be used with class LDAPObject and friends.

Lib/ldap/controls/pagedresults.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Imports from python-ldap 2.4+
1313
import ldap.controls
14-
from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS
14+
from ldap.controls import RequestControl,ResponseControl
1515

1616
# Imports from pyasn1
1717
from pyasn1.type import tag,namedtype,univ,constraint
@@ -44,6 +44,3 @@ def decodeControlValue(self,encodedControlValue):
4444
decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=PagedResultsControlValue())
4545
self.size = int(decodedValue.getComponentByName('size'))
4646
self.cookie = bytes(decodedValue.getComponentByName('cookie'))
47-
48-
49-
KNOWN_RESPONSE_CONTROLS[SimplePagedResultsControl.controlType] = SimplePagedResultsControl

Lib/ldap/controls/ppolicy.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Imports from python-ldap 2.4+
1313
from ldap.controls import (
14-
ResponseControl, ValueLessRequestControl, KNOWN_RESPONSE_CONTROLS
14+
ResponseControl, ValueLessRequestControl
1515
)
1616

1717
# Imports from pyasn1
@@ -99,6 +99,3 @@ def decodeControlValue(self,encodedControlValue):
9999
error = ppolicyValue.getComponentByName('error')
100100
if error.hasValue():
101101
self.error = int(error)
102-
103-
104-
KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl

Lib/ldap/controls/psearch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Imports from python-ldap 2.4+
1616
import ldap.controls
17-
from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS
17+
from ldap.controls import RequestControl,ResponseControl
1818

1919
# Imports from pyasn1
2020
from pyasn1.type import namedtype,namedval,univ,constraint
@@ -125,5 +125,3 @@ def decodeControlValue(self,encodedControlValue):
125125
else:
126126
self.changeNumber = None
127127
return (self.changeType,self.previousDN,self.changeNumber)
128-
129-
KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl

Lib/ldap/controls/pwdpolicy.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Imports from python-ldap 2.4+
1414
import ldap.controls
15-
from ldap.controls import RequestControl,ResponseControl,ValueLessRequestControl,KNOWN_RESPONSE_CONTROLS
15+
from ldap.controls import ResponseControl
1616

1717

1818
class PasswordExpiringControl(ResponseControl):
@@ -24,8 +24,6 @@ class PasswordExpiringControl(ResponseControl):
2424
def decodeControlValue(self,encodedControlValue):
2525
self.gracePeriod = int(encodedControlValue)
2626

27-
KNOWN_RESPONSE_CONTROLS[PasswordExpiringControl.controlType] = PasswordExpiringControl
28-
2927

3028
class PasswordExpiredControl(ResponseControl):
3129
"""
@@ -35,5 +33,3 @@ class PasswordExpiredControl(ResponseControl):
3533

3634
def decodeControlValue(self,encodedControlValue):
3735
self.passwordExpired = encodedControlValue=='0'
38-
39-
KNOWN_RESPONSE_CONTROLS[PasswordExpiredControl.controlType] = PasswordExpiredControl

Lib/ldap/controls/readentry.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import ldap
99

1010
from pyasn1.codec.ber import encoder,decoder
11-
from ldap.controls import LDAPControl,KNOWN_RESPONSE_CONTROLS
11+
from ldap.controls import LDAPControl
1212

1313
from pyasn1_modules.rfc2251 import AttributeDescriptionList,SearchResultEntry
1414

@@ -63,8 +63,6 @@ class PreReadControl(ReadEntryControl):
6363
"""
6464
controlType = ldap.CONTROL_PRE_READ
6565

66-
KNOWN_RESPONSE_CONTROLS[PreReadControl.controlType] = PreReadControl
67-
6866

6967
class PostReadControl(ReadEntryControl):
7068
"""
@@ -83,5 +81,3 @@ class PostReadControl(ReadEntryControl):
8381
after the operation was done by the server
8482
"""
8583
controlType = ldap.CONTROL_POST_READ
86-
87-
KNOWN_RESPONSE_CONTROLS[PostReadControl.controlType] = PostReadControl

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy