Skip to content

Commit 1e20c2d

Browse files
committed
Check whether libldap is threadsafe on startup.
Closes #432
1 parent e75c24d commit 1e20c2d

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

Lib/ldap/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ class Str(Constant):
341341
# XXX - these should be errors
342342
Int('URL_ERR_BADSCOPE'),
343343
Int('URL_ERR_MEM'),
344-
# Int('LIBLDAP_R'),
345344

346-
Feature('LIBLDAP_R', 'HAVE_LIBLDAP_R'),
347345
Feature('SASL_AVAIL', 'HAVE_SASL'),
348346
Feature('TLS_AVAIL', 'HAVE_TLS'),
349347
Feature('INIT_FD_AVAIL', 'HAVE_LDAP_INIT_FD'),

Modules/constants.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ int
197197
LDAPinit_constants(PyObject *m)
198198
{
199199
PyObject *exc, *nobj;
200+
struct ldap_apifeature_info info = { 1, "X_OPENLDAP_THREAD_SAFE", 0 };
201+
int thread_safe = 0;
200202

201203
/* simple constants */
202204

@@ -221,6 +223,14 @@ LDAPinit_constants(PyObject *m)
221223
return -1;
222224
Py_INCREF(LDAPexception_class);
223225

226+
#ifdef LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
227+
if (ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &info) == LDAP_SUCCESS) {
228+
thread_safe = (info.ldapaif_version == 1);
229+
}
230+
#endif
231+
if (PyModule_AddIntConstant(m, "LIBLDAP_R", thread_safe) != 0)
232+
return -1;
233+
224234
/* Generated constants -- see Lib/ldap/constants.py */
225235

226236
#define add_err(n) do { \

setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ defines = HAVE_SASL HAVE_TLS HAVE_LIBLDAP_R
2121
extra_compile_args =
2222
extra_objects =
2323

24+
# Uncomment this if your libldap is not thread-safe and you need libldap_r
25+
# instead
2426
# Example for full-featured build:
2527
# Support for StartTLS/LDAPS, SASL bind and reentrant libldap_r.
26-
libs = ldap_r lber
28+
#libs = ldap_r lber
2729

2830
# Installation options
2931
[install]
@@ -33,7 +35,7 @@ optimize = 1
3335
# Linux distributors/packagers should adjust these settings
3436
[bdist_rpm]
3537
provides = python-ldap
36-
requires = python libldap-2_4
38+
requires = python libldap-2
3739
vendor = python-ldap project
3840
packager = python-ldap team
3941
distribution_name = openSUSE 11.x

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class OpenLDAP2:
132132
extra_objects = LDAP_CLASS.extra_objects,
133133
runtime_library_dirs = (not sys.platform.startswith("win"))*LDAP_CLASS.library_dirs,
134134
define_macros = LDAP_CLASS.defines + \
135-
('ldap_r' in LDAP_CLASS.libs or 'oldap_r' in LDAP_CLASS.libs)*[('HAVE_LIBLDAP_R',None)] + \
136135
('sasl' in LDAP_CLASS.libs or 'sasl2' in LDAP_CLASS.libs or 'libsasl' in LDAP_CLASS.libs)*[('HAVE_SASL',None)] + \
137136
('ssl' in LDAP_CLASS.libs and 'crypto' in LDAP_CLASS.libs)*[('HAVE_TLS',None)] + \
138137
[

0 commit comments

Comments
 (0)