Skip to content

Commit daf266a

Browse files
spaceoneencukou
authored andcommitted
Ensure self._l is not left in an only partially initialized state
If the timeout is reached and a reconnection was not successfull in that time, a ldap.SERVER_DOWN exception is raised. If later on, when it's assured that the ldap server is running again, the connection is used again, the reconnection is not performed and the ldap connection in an incosistent unbind state. Traceback (most recent call last): File "reproduce.py", line 23, in <module> _ = lo.search_s('l=school,l=dev', ldap.SCOPE_SUBTREE, '(uid=Administrator)') File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 597, in search_s return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 997, in search_ext_s return self._apply_method_s(SimpleLDAPObject.search_ext_s,*args,**kwargs) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 935, in _apply_method_s return func(self,*args,**kwargs) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 591, in search_ext_s return self.result(msgid,all=1,timeout=timeout)[1] File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 503, in result resp_type, resp_data, resp_msgid = self.result2(msgid,all,timeout) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 507, in result2 resp_type, resp_data, resp_msgid, resp_ctrls = self.result3(msgid,all,timeout) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 514, in result3 resp_ctrl_classes=resp_ctrl_classes File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 521, in result4 ldap_result = self._ldap_call(self._l.result4,msgid,all,timeout,add_ctrls,add_intermediates,add_extop) File "/usr/lib/python2.7/dist-packages/ldap/ldapobject.py", line 106, in _ldap_call result = func(*args,**kwargs) ldap.INSUFFICIENT_ACCESS: {'desc': 'Insufficient access'}
1 parent 689f7df commit daf266a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Lib/ldap/ldapobject.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,14 +1166,18 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
11661166
counter_text,uri
11671167
))
11681168
try:
1169-
# Do the connect
1170-
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
1171-
self._restore_options()
1172-
# StartTLS extended operation in case this was called before
1173-
if self._start_tls:
1174-
SimpleLDAPObject.start_tls_s(self)
1175-
# Repeat last simple or SASL bind
1176-
self._apply_last_bind()
1169+
try:
1170+
# Do the connect
1171+
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
1172+
self._restore_options()
1173+
# StartTLS extended operation in case this was called before
1174+
if self._start_tls:
1175+
SimpleLDAPObject.start_tls_s(self)
1176+
# Repeat last simple or SASL bind
1177+
self._apply_last_bind()
1178+
except ldap.LDAPError:
1179+
SimpleLDAPObject.unbind_s(self)
1180+
raise
11771181
except (ldap.SERVER_DOWN,ldap.TIMEOUT):
11781182
if __debug__ and self._trace_level>=1:
11791183
self._trace_file.write('*** %s reconnect to %s failed\n' % (
@@ -1185,7 +1189,6 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
11851189
if __debug__ and self._trace_level>=1:
11861190
self._trace_file.write('=> delay %s...\n' % (retry_delay))
11871191
time.sleep(retry_delay)
1188-
SimpleLDAPObject.unbind_s(self)
11891192
else:
11901193
if __debug__ and self._trace_level>=1:
11911194
self._trace_file.write('*** %s reconnect to %s successful => repeat last operation\n' % (

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