Skip to content

Commit

Permalink
Compability changes for pyasn1 0.3.x or newer
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Nov 11, 2017
1 parent cd3d83b commit dab08df
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Released 2.5.0 2017-11-xx

Changes since 2.4.45:

This release requires pyasn1 0.3.x or newer!

Lib/
* slapdtest.SlapdObject.restart() just restarts slapd
without cleaning any data
* Compability changes for pyasn1 0.3.x or newer
(thanks to Ilya Etingof and Christian Heimes)

Tests/
* added explicit reconnect tests for ReconnectLDAPObject
Expand Down
12 changes: 6 additions & 6 deletions Lib/ldap/controls/ppolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ def __init__(self,criticality=False):
def decodeControlValue(self,encodedControlValue):
ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue())
warning = ppolicyValue.getComponentByName('warning')
if warning is None:
if not warning.hasValue():
self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None
else:
timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration')
if timeBeforeExpiration!=None:
if timeBeforeExpiration.hasValue():
self.timeBeforeExpiration = int(timeBeforeExpiration)
else:
self.timeBeforeExpiration = None
graceAuthNsRemaining = warning.getComponentByName('graceAuthNsRemaining')
if graceAuthNsRemaining!=None:
if graceAuthNsRemaining.hasValue():
self.graceAuthNsRemaining = int(graceAuthNsRemaining)
else:
self.graceAuthNsRemaining = None
error = ppolicyValue.getComponentByName('error')
if error is None:
self.error = None
else:
if error.hasValue():
self.error = int(error)
else:
self.error = None


KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl
20 changes: 9 additions & 11 deletions Lib/ldap/controls/psearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,16 @@ class EntryChangeNotificationControl(ResponseControl):
def decodeControlValue(self,encodedControlValue):
ecncValue,_ = decoder.decode(encodedControlValue,asn1Spec=EntryChangeNotificationValue())
self.changeType = int(ecncValue.getComponentByName('changeType'))
if len(ecncValue)==3:
self.previousDN = str(ecncValue.getComponentByName('previousDN'))
self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
elif len(ecncValue)==2:
if self.changeType==8:
self.previousDN = str(ecncValue.getComponentByName('previousDN'))
self.changeNumber = None
else:
self.previousDN = None
self.changeNumber = int(ecncValue.getComponentByName('changeNumber'))
previousDN = ecncValue.getComponentByName('previousDN')
if previousDN.hasValue():
self.previousDN = str(previousDN)
else:
self.previousDN,self.changeNumber = None,None
self.previousDN = None
changeNumber = ecncValue.getComponentByName('changeNumber')
if changeNumber.hasValue():
self.changeNumber = int(changeNumber)
else:
self.changeNumber = None
return (self.changeType,self.previousDN,self.changeNumber)

KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl
6 changes: 5 additions & 1 deletion Lib/ldap/controls/sss.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def decodeControlValue(self, encoded):
assert not rest, 'all data could not be decoded'
self.result = int(p.getComponentByName('sortResult'))
self.result_code = p.getComponentByName('sortResult').prettyOut(self.result)
self.attribute_type_error = p.getComponentByName('attributeType')
attribute_type_error = p.getComponentByName('attributeType')
if attribute_type_error.hasValue():
self.attribute_type_error = attribute_type_error
else:
self.attribute_type_error = None


KNOWN_RESPONSE_CONTROLS[SSSRequestControl.controlType] = SSSRequestControl
Expand Down
12 changes: 7 additions & 5 deletions Lib/ldap/controls/vlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ def decodeControlValue(self,encoded):
self.target_position = int(p.getComponentByName('targetPosition'))
self.content_count = int(p.getComponentByName('contentCount'))
self.result = int(p.getComponentByName('virtualListViewResult'))
self.result_code = p.getComponentByName('virtualListViewResult') \
.prettyOut(self.result)
self.context_id = p.getComponentByName('contextID')
if self.context_id:
self.context_id = str(self.context_id)
self.result_code = p.getComponentByName('virtualListViewResult').prettyOut(self.result)
context_id = p.getComponentByName('contextID')
if context_id.hasValue():
self.context_id = str(context_id)
else:
self.context_id = None


KNOWN_RESPONSE_CONTROLS[VLVResponseControl.controlType] = VLVResponseControl
28 changes: 17 additions & 11 deletions Lib/ldap/syncrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ def decodeControlValue(self, encodedControlValue):
d = decoder.decode(encodedControlValue, asn1Spec = syncStateValue())
state = d[0].getComponentByName('state')
uuid = UUID(bytes=d[0].getComponentByName('entryUUID'))
self.cookie = d[0].getComponentByName('cookie')
cookie = d[0].getComponentByName('cookie')
if cookie.hasValue():
self.cookie = str(self.cookie)
else:
self.cookie = None
self.state = self.__class__.opnames[int(state)]
self.entryUUID = str(uuid)
if self.cookie is not None:
self.cookie = str(self.cookie)

KNOWN_RESPONSE_CONTROLS[SyncStateControl.controlType] = SyncStateControl

Expand Down Expand Up @@ -165,12 +167,16 @@ class SyncDoneControl(ResponseControl):

def decodeControlValue(self, encodedControlValue):
d = decoder.decode(encodedControlValue, asn1Spec = syncDoneValue())
self.cookie = d[0].getComponentByName('cookie')
self.refreshDeletes = d[0].getComponentByName('refreshDeletes')
if self.cookie is not None:
self.cookie = str(self.cookie)
if self.refreshDeletes is not None:
self.refreshDeletes = bool(self.refreshDeletes)
cookie = d[0].getComponentByName('cookie')
if cookie.hasValue():
self.cookie = str(cookie)
else:
self.cookie = None
refresh_deletes = d[0].getComponentByName('refreshDeletes')
if refresh_deletes.hasValue():
self.refreshDeletes = bool(refresh_deletes)
else:
self.refreshDeletes = None

KNOWN_RESPONSE_CONTROLS[SyncDoneControl.controlType] = SyncDoneControl

Expand Down Expand Up @@ -263,7 +269,7 @@ def __init__(self, encodedMessage):
for attr in [ 'newcookie', 'refreshDelete', 'refreshPresent', 'syncIdSet']:
comp = d[0].getComponentByName(attr)

if comp is not None:
if comp.hasValue():

if attr == 'newcookie':
self.newcookie = str(comp)
Expand All @@ -272,7 +278,7 @@ def __init__(self, encodedMessage):
val = dict()

cookie = comp.getComponentByName('cookie')
if cookie is not None:
if cookie.hasValue():
val['cookie'] = str(cookie)

if attr.startswith('refresh'):
Expand Down

0 comments on commit dab08df

Please sign in to comment.