From 8b78abd6ef45bd144091a506e09cfa9f4b2ee37c Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Nov 07 2017 15:03:26 +0000 Subject: Accommodate changed pyasn1 behaviour pyasn1 versions prior to 0.2.3 indicate absent value by returning `None` object, later pyasn1 versions use the `noValue` sentinel object which is the basis for the `.hasValue()` method call (and .isValue property). This fix makes the code compatible with both `None` sentinel and the `.hasValue()` test call thus making it compatible with all reasonable pyasn1 versions in circulation. Fixes RHBZ#1489184 Original patch by Ilya Etingof Signed-off-by: Christian Heimes --- diff --git a/accommodate-changed-pyasn1-behaviour.patch b/accommodate-changed-pyasn1-behaviour.patch new file mode 100644 index 0000000..42e39df --- /dev/null +++ b/accommodate-changed-pyasn1-behaviour.patch @@ -0,0 +1,168 @@ +From a89bd2361a3971d0dc11908707509bbf5e1fd1ac Mon Sep 17 00:00:00 2001 +From: Ilya Etingof +Date: Wed, 11 Oct 2017 20:27:41 +0200 +Subject: [PATCH] accommodate changed pyasn1 behaviour + +pyasn1 versions prior to 0.2.3 indicate absent value by +returning `None` object, later pyasn1 versions use +the `noValue` sentinel object which is the basis for +the `.hasValue()` method call (and .isValue property). + +This fix makes the code compatible with both `None` sentinel +and the `.hasValue()` test thus making it compatible with all +reasonable pyasn1 versions in circulation. +--- +Index: Lib/ldap/syncrepl.py +=================================================================== +RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/syncrepl.py,v +retrieving revision 1.9 +diff -u -r1.9 syncrepl.py +--- Lib/ldap/syncrepl.py 9 Oct 2017 15:09:28 -0000 1.9 ++++ Lib/ldap/syncrepl.py 7 Nov 2017 13:40:32 -0000 +@@ -131,11 +131,13 @@ + 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 is None or not cookie.hasValue(): ++ self.cookie = None ++ else: ++ self.cookie = str(self.cookie) + 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 + +@@ -165,10 +167,10 @@ + + def decodeControlValue(self, encodedControlValue): + d = decoder.decode(encodedControlValue, asn1Spec = syncDoneValue()) +- self.cookie = d[0].getComponentByName('cookie') ++ cookie = d[0].getComponentByName('cookie') ++ if cookie is not None and cookie.hasValue(): ++ self.cookie = str(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) + +@@ -263,7 +265,7 @@ + for attr in [ 'newcookie', 'refreshDelete', 'refreshPresent', 'syncIdSet']: + comp = d[0].getComponentByName(attr) + +- if comp is not None: ++ if comp is not None and comp.hasValue(): + + if attr == 'newcookie': + self.newcookie = str(comp) +@@ -272,7 +274,7 @@ + val = dict() + + cookie = comp.getComponentByName('cookie') +- if cookie is not None: ++ if cookie is not None and cookie.hasValue(): + val['cookie'] = str(cookie) + + if attr.startswith('refresh'): +Index: Lib/ldap/controls/ppolicy.py +=================================================================== +RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/ppolicy.py,v +retrieving revision 1.6 +diff -u -r1.6 ppolicy.py +--- Lib/ldap/controls/ppolicy.py 9 Oct 2017 15:09:28 -0000 1.6 ++++ Lib/ldap/controls/ppolicy.py 7 Nov 2017 13:40:32 -0000 +@@ -71,7 +71,7 @@ + def decodeControlValue(self,encodedControlValue): + ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue()) + warning = ppolicyValue.getComponentByName('warning') +- if warning is None: ++ if warning is None or not warning.hasValue(): + self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None + else: + timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration') +@@ -85,7 +85,7 @@ + else: + self.graceAuthNsRemaining = None + error = ppolicyValue.getComponentByName('error') +- if error is None: ++ if error is None or not error.hasValue(): + self.error = None + else: + self.error = int(error) +Index: Lib/ldap/controls/psearch.py +=================================================================== +RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/psearch.py,v +retrieving revision 1.6 +diff -u -r1.6 psearch.py +--- Lib/ldap/controls/psearch.py 9 Oct 2017 15:09:28 -0000 1.6 ++++ Lib/ldap/controls/psearch.py 7 Nov 2017 13:40:32 -0000 +@@ -115,18 +115,16 @@ + 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 is None or not previousDN.hasValue(): ++ self.previousDN = None + else: +- self.previousDN,self.changeNumber = None,None ++ self.previousDN = str(previousDN) ++ changeNumber = ecncValue.getComponentByName('changeNumber') ++ if changeNumber is None or not changeNumber.hasValue(): ++ self.changeNumber = None ++ else: ++ self.changeNumber = int(changeNumber) + return (self.changeType,self.previousDN,self.changeNumber) + + KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl +Index: Lib/ldap/controls/sss.py +=================================================================== +RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/sss.py,v +retrieving revision 1.5 +diff -u -r1.5 sss.py +--- Lib/ldap/controls/sss.py 9 Oct 2017 15:09:28 -0000 1.5 ++++ Lib/ldap/controls/sss.py 7 Nov 2017 13:40:32 -0000 +@@ -121,7 +121,9 @@ + 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 is not None and attribute_type_error.hasValue(): ++ self.attribute_type_error = attribute_type_error + + + KNOWN_RESPONSE_CONTROLS[SSSRequestControl.controlType] = SSSRequestControl +Index: Lib/ldap/controls/vlv.py +=================================================================== +RCS file: /cvsroot/python-ldap/python-ldap/Lib/ldap/controls/vlv.py,v +retrieving revision 1.5 +diff -u -r1.5 vlv.py +--- Lib/ldap/controls/vlv.py 9 Oct 2017 15:09:28 -0000 1.5 ++++ Lib/ldap/controls/vlv.py 7 Nov 2017 13:40:32 -0000 +@@ -130,8 +130,9 @@ + 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) ++ context_id = p.getComponentByName('contextID') ++ if context_id is not None and context_id.hasValue(): ++ self.context_id = str(context_id) ++ + + KNOWN_RESPONSE_CONTROLS[VLVResponseControl.controlType] = VLVResponseControl diff --git a/python-ldap.spec b/python-ldap.spec index 3aad57b..61db466 100644 --- a/python-ldap.spec +++ b/python-ldap.spec @@ -2,7 +2,7 @@ Name: python-ldap Version: 2.4.25 -Release: 7%{?dist} +Release: 8%{?dist} Epoch: 0 License: Python Group: System Environment/Libraries @@ -13,6 +13,9 @@ Source0: http://pypi.python.org/packages/source/p/python-ldap/python-ldap-%{vers ### Patches ### # Fedora specific patch Patch0: python-ldap-2.4.16-dirs.patch +# Fix for pyasn1 >= 0.3 +# https://github.com/pyldap/pyldap/pull/126 +Patch1: accommodate-changed-pyasn1-behaviour.patch ### Dependencies ### # LDAP controls, extop, syncrepl require pyasn1 @@ -48,6 +51,7 @@ Requires: python-pyasn1, python-pyasn1-modules %prep %setup -q -n python-ldap-%{version} %patch0 -p1 -b .dirs +%patch1 -p0 -b accommodate-changed-pyasn1-behaviour.patch # clean up cvs hidden files rm -rf Demo/Lib/ldap/.cvsignore Demo/.cvsignore Demo/Lib/ldif/.cvsignore Demo/Lib/ldap/async/.cvsignore \ @@ -74,6 +78,9 @@ sed -i 's|#! python|#!/usr/bin/python|g' Demo/simplebrowse.py %{python_sitearch}/python_ldap-%{version}-*.egg-info %changelog +* Tue Nov 07 2017 Christian Heimes - 0:2.4.25-8 +- Apply fix for pyasn1 >= 0.3 + * Sat Aug 19 2017 Zbigniew Jędrzejewski-Szmek - 0:2.4.25-7 - Python 2 binary package renamed to python2-ldap See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3