Module: check_mk
Branch: master
Commit: 6f8248e388f82866ef8d9968d0627502b74f6457
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6f8248e388f828…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon May 28 09:33:19 2018 +0200
LDAP: Cleaned up old python version compatibility things
Change-Id: Iaf1bb9d8740483b2f52730f1c5ea8ee8a18fc828
---
web/plugins/userdb/ldap.py | 41 +++++++++--------------------------------
1 file changed, 9 insertions(+), 32 deletions(-)
diff --git a/web/plugins/userdb/ldap.py b/web/plugins/userdb/ldap.py
index 4b0075f..4886e5a 100644
--- a/web/plugins/userdb/ldap.py
+++ b/web/plugins/userdb/ldap.py
@@ -52,23 +52,10 @@ import watolib
import cmk.paths
import log
-try:
- # docs:
http://www.python-ldap.org/doc/html/index.html
- import ldap
- import ldap.filter
- from ldap.controls import SimplePagedResultsControl
-
- # be compatible to both python-ldap below 2.4 and above
- try:
- # pylint: disable=no-member
- LDAP_CONTROL_PAGED_RESULTS = ldap.LDAP_CONTROL_PAGE_OID
- ldap_compat = False
- except:
- # pylint: disable=no-member
- LDAP_CONTROL_PAGED_RESULTS = ldap.CONTROL_PAGEDRESULTS
- ldap_compat = True
-except:
- pass
+# docs:
http://www.python-ldap.org/doc/html/index.html
+import ldap
+import ldap.filter
+from ldap.controls import SimplePagedResultsControl
# LDAP attributes are case insensitive, we only use lower case!
# Please note: This are only default values. The user might override this
@@ -469,12 +456,7 @@ class LDAPUserConnector(UserConnector):
self._logger.debug(' PAGED ASYNC SEARCH')
page_size = self._config.get('page_size', 1000)
- if ldap_compat:
- lc = SimplePagedResultsControl(size = page_size, cookie = '')
- else:
- lc = SimplePagedResultsControl(
- LDAP_CONTROL_PAGED_RESULTS, True, (page_size, '')
- )
+ lc = SimplePagedResultsControl(size = page_size, cookie = '')
if type(base) == unicode:
base = base.encode("utf-8")
@@ -497,15 +479,10 @@ class LDAPUserConnector(UserConnector):
# Mark current position in pagination control for next loop
cookie = None
for serverctrl in serverctrls:
- if serverctrl.controlType == LDAP_CONTROL_PAGED_RESULTS:
- if ldap_compat:
- cookie = serverctrl.cookie
- if cookie:
- lc.cookie = cookie
- else:
- cookie = serverctrl.controlValue[1]
- if cookie:
- lc.controlValue = (page_size, cookie)
+ if serverctrl.controlType == ldap.CONTROL_PAGEDRESULTS:
+ cookie = serverctrl.cookie
+ if cookie:
+ lc.cookie = cookie
break
if not cookie:
break