Michael Ströder wrote:
Michael Ströder wrote:
Routinely in the C module part of python-ldap all calls to libldap functions are wrapped by a thread lock. But I wonder whether that's really necessary for all of them, especially regarding ldap_str2dn() and ldap_dn2str().
Mainly for python-ldap this question boils down to whether ldap_bv2dn_x() and ldap_bv2rdn_x() are re-entrant. Glancing over these it seems they are re-entrant. But it would be nice if one of the OpenLDAP developers could confirm that.
*You're* an OpenLDAP developer... ;)
Yes, these functions are re-entrant. I would say most of libldap's functions *don't* need any locking. The only really important thing is to call ldap_init() once in the main program before any threads start, to make sure that all of the global library options get parsed before threading occurs. Beyond that, if you make sure that only one thread can use an LDAP handle at a time, there's no really re-entrancy issues to speak of.
Of course, there are no guarantees on underlying libraries that libldap uses, like SASL, OpenSSL, etc... If you need those features in a threaded program, you need to use libldap_r because libldap doesn't do any thread initialization for those other libraries.