From: Alain S. <asp...@gm...> - 2007-01-26 21:39:40
|
When testing ReconnectLDAPObject I found a bug. The object doesn't reconnect after a main failure ! If I shutdown the ldap server and try a request, I get a ldap.SERVER_DOWN, this is correct. (this is what I call the main failure) But if I restart the server, and retry the same request (with the same object), I get an empty answer but no error! I'm expecting a correct answer or an error (exception)! I have a full script that show the problem at the end. It look the object is in an incoherent state after the main failure, in fact in an unauthenticated state ! I thing this is a problem with libldap or openldap, not with python code. I thing the main probleme is here ! Look ! l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl()) l.simple_bind_s('cn=nobody,cn=internal,dc=asxnet,dc=loc', '***********') print 'search', l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE, "(objectClass=*)") works and return all object anonymous can get, but l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl()) print 'search', l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE, "(objectClass=*)") this work too ! And don't give any error while their is no bind ! work like if l.simple_bind_s('', '') where used just before the search ! I wrote a patch but this is only a workaround that detect the main failure, set a flag and force a reconnect before any request if the flag is set. Here is the output of my test case I use a modified python-ldap, that include the patch posted in my previous post that enable reconnect to work with whoami_s() -- without debuging -- OpenPKG: stop: openldap. OpenPKG: start: openldap. Connected whoami dn:cn=nobody,cn=internal,dc=asxnet,dc=loc OpenPKG: stop: openldap. OpenPKG: start: openldap. whoami dn:cn=nobody,cn=internal,dc=asxnet,dc=loc reconnect ok OpenPKG: stop: openldap. ok: ldap.SERVER_DOWN, server is realy down OpenPKG: start: openldap. whoami It look i'am connected, but like anonymous -- with debuging -- OpenPKG: stop: openldap. OpenPKG: start: openldap. *** ldap://localhost:389 - ReconnectLDAPObject.set_option ((17, 3),{}) *** ldap://localhost:389 - ReconnectLDAPObject.simple_bind (('cn=nobody,cn=internal,dc=asxnet,dc=loc', 'iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc', None, None),{}) *** ldap://localhost:389 - ReconnectLDAPObject.result3 ((1, 1, -1),{}) Connected *** ldap://localhost:389 - ReconnectLDAPObject.whoami_s ((None, None),{}) whoami dn:cn=nobody,cn=internal,dc=asxnet,dc=loc OpenPKG: stop: openldap. OpenPKG: start: openldap. *** ldap://localhost:389 - ReconnectLDAPObject.whoami_s ((None, None),{}) *** Try 1. reconnect to ldap://localhost:389... *** ldap://localhost:389 - ReconnectLDAPObject.set_option ((17, 3),{}) *** ldap://localhost:389 - ReconnectLDAPObject.simple_bind (('cn=nobody,cn=internal,dc=asxnet,dc=loc', 'iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc', None, None),{}) *** ldap://localhost:389 - ReconnectLDAPObject.result3 ((1, 1, -1),{}) *** 1. reconnect to ldap://localhost:389 successful, last operation will be repeated *** ldap://localhost:389 - ReconnectLDAPObject.whoami_s ((None, None),{}) whoami dn:cn=nobody,cn=internal,dc=asxnet,dc=loc reconnect ok OpenPKG: stop: openldap. *** ldap://localhost:389 - ReconnectLDAPObject.whoami_s ((None, None),{}) *** Try 1. reconnect to ldap://localhost:389... *** ldap://localhost:389 - ReconnectLDAPObject.set_option ((17, 3),{}) *** ldap://localhost:389 - ReconnectLDAPObject.simple_bind (('cn=nobody,cn=internal,dc=asxnet,dc=loc', 'iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc', None, None),{}) *** 1. reconnect to ldap://localhost:389 failed ok: ldap.SERVER_DOWN, server is realy down OpenPKG: start: openldap. *** ldap://localhost:389 - ReconnectLDAPObject.whoami_s ((None, None),{}) whoami It look i'am connected, but like anonymous ---- and finaly my test case ---- import sys, os, time import ldap, ldapurl host='localhost' port=389 who='cn=nobody,cn=internal,dc=asxnet,dc=loc' cred='iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc' dn='dc=asxnet,dc=loc' def ldap_service(action): os.system('/kolab/bin/openpkg rc openldap %s' % action) if action.endswith('start'): time.sleep(1) def check_connection(): whoami=l.whoami_s() print 'whoami', whoami # this search dont give any result as anonymous, but well if loggged as nobody #result=l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE, "(member=cn=domain.maintainer mydomain.loc,cn=internal,dc=asxnet,dc=loc)") #print 'search', result ldap_url=ldapurl.LDAPUrl('ldap://%s:%d/%s' % (host, port, dn)) ldap_url.applyDefaults({ 'who': who, 'cred' : cred, }) # to be sure the server is up ldap_service('stop') ldap_service('start') l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl(), 1) # l=ldap.ldapobject.LDAPObject(ldap_url.initializeUrl()) l.simple_bind_s(ldap_url.who, ldap_url.cred) print 'Connected' check_connection() ldap_service('stop') ldap_service('start') try: check_connection() except ldap.SERVER_DOWN: print "Error: ldap.SERVER_DOWN !" else: print "reconnect ok" ldap_service('stop') try: check_connection() except ldap.SERVER_DOWN: print "ok: ldap.SERVER_DOWN, server is realy down" ldap_service('start') check_connection() print "It look i'am connected, but like anonymous" import sys, os, time import ldap, ldapurl host='localhost' port=389 who='cn=nobody,cn=internal,dc=asxnet,dc=loc' cred='iMmTWz5pJ+lwY7i6M/BU61ngo1aBLyqQhRrrKbEc' dn='dc=asxnet,dc=loc' def ldap_service(action): os.system('/kolab/bin/openpkg rc openldap %s' % action) if action.endswith('start'): time.sleep(1) def check_connection(): #print 'search', l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE, "(member=cn=domain.maintainer mydomain.loc,cn=internal,dc=asxnet,dc=loc)") print 'whoami', l.whoami_s() ldap_url=ldapurl.LDAPUrl('ldap://%s:%d/%s' % (host, port, dn)) ldap_url.applyDefaults({ 'who': who, 'cred' : cred, }) ldap_service('stop') ldap_service('start') l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl()) # l=ldap.ldapobject.LDAPObject(ldap_url.initializeUrl()) l.simple_bind_s(ldap_url.who, ldap_url.cred) print 'Connected' check_connection() ldap_service('stop') ldap_service('start') try: check_connection() except ldap.SERVER_DOWN: print "Error: ldap.SERVER_DOWN !" ldap_service('stop') try: check_connection() except ldap.SERVER_DOWN: print "Ok: ldap.SERVER_DOWN" ldap_service('start') check_connection() ANY Comments ? -- Alain Spineux aspineux gmail com May the sources be with you |