Problem is that the result type of ldap_get_option() is char** instead of char* like assumed until now. :-(
Note outvalue differs in type from invalue!
At first glance it seems to be the same for all string-based results of ldap_get_option().
Excerpt from OpenLDAP's man-page:
LDAP_OPT_DIAGNOSTIC_MESSAGE
Sets/gets a string containing the error string associated to the LDAP handle. [..} outvalue must be a char **, and the caller is responsible of freeing the returned string by calling ldap_memfree(3), while invalue must be a char *; the library duplicates the corresponding string.
Logged In: YES
user_id=132815
Originator: NO
LDAP_get_option() provides the correct type for outvalue ("&strval"
evaluates to a "char **"), but doesn't expect ldap_get_option(3) to
return NULL.
I don't seem to have permission to upload files, so I've left a patch at
http://people.debian.org/~vela/python-ldap-1926507.diff
It converts NULL to None, and fixes a couple of associated memory leaks.
Hope that helps.
vela's patch
Logged In: YES
user_id=10218
Originator: NO
Here is vela's patch. It looks pretty decent.
Can a test case be added for this?
File Added: python-ldap-1926507.diff
Logged In: YES
user_id=64920
Originator: YES
Many thanks for the patch. But now there's another issue when LDAPObject.unbind() is called:
python2.5: options.c:108: ldap_get_option: Assertion `( (ld)->ld_options.ldo_valid == 0x2 )' failed.
Aborted
I've tested it with OpenLDAP libs 2.3.41 and 2.4.8 and Python 2.5.1 and 2.6a1. Could you please look into it?
Logged In: YES
user_id=132815
Originator: NO
> python2.5: options.c:108: ldap_get_option: Assertion `(
> (ld)->ld_options.ldo_valid == 0x2 )' failed.
> Aborted
I don't get this (OpenLDAP 2.4.8 here). But I think it's happening
because l_ldap_unbind_ext() calls LDAPerror() with an already
invalidated LDAP object. Please try an additional patch from
http://people.debian.org/~vela/python-ldap-1926507-unbind.diff
It may not fix the underlying problem, but at least you should get a
proper exception.
Logged In: NO
Well, unbind() used to work. I'd rather suspect there's something wrong with the patch you provided first. Could you please test with
python Tests/search.py ldap://x500.bund.de/o=bund,c=de??one??trace=1
I've added this test script right now. Thanks for your efforts.
Logged In: YES
user_id=64920
Originator: YES
Aargh! Sorry, my fault. I've added locally a call to self._l.get_option() after result = func(*args,**kwargs) to LDAPObject._ldap_call() to grab the diagnosticMessage in case of a successful operation and send that to the trace log. Obviously this goes wrong if LDAPObject.unbind() is invoked. I have to find another solution for that.
Matej, thanks for the patch. It's committed now.