Skip to content

Commit 19d6f7f

Browse files
committed
Fix macOS SDK builds without ldap_init_fd
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable initialize_fd when Apple libldap 2.4.28 is detected. Also run some macOS tests on Travis CI. Since the SDK does not ship slapd, testing is rather limited. Fixes: #359 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 2be2c6b commit 19d6f7f

File tree

11 files changed

+64
-1
lines changed

11 files changed

+64
-1
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: python
2+
group: travis_latest
23

34
sudo: false
45

@@ -14,6 +15,13 @@ addons:
1415
# Note: when updating Python versions, also change setup.py and tox.ini
1516
matrix:
1617
include:
18+
- os: osx
19+
osx_image: xcode11.4
20+
language: minimal
21+
env:
22+
- TOXENV=macos
23+
- CFLAGS_warnings="-Wall -Werror=declaration-after-statement"
24+
- CFLAGS_std="-std=c99"
1725
- python: 3.6
1826
env:
1927
- TOXENV=py36
@@ -25,6 +33,7 @@ matrix:
2533
- python: 3.7
2634
env:
2735
- TOXENV=py37
36+
- CFLAGS_std="-std=c99"
2837
- WITH_GCOV=1
2938
dist: xenial
3039
sudo: true

Lib/ldap/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class Str(Constant):
344344
Feature('LIBLDAP_R', 'HAVE_LIBLDAP_R'),
345345
Feature('SASL_AVAIL', 'HAVE_SASL'),
346346
Feature('TLS_AVAIL', 'HAVE_TLS'),
347+
Feature('INIT_FD_AVAIL', 'HAVE_LDAP_INIT_FD'),
347348

348349
Str("CONTROL_MANAGEDSAIT"),
349350
Str("CONTROL_PROXY_AUTHZ"),

Lib/ldap/ldapobject.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(
7777
self._uri = uri
7878
self._ldap_object_lock = self._ldap_lock('opcall')
7979
if fileno is not None:
80+
if not hasattr(_ldap, "initialize_fd"):
81+
raise ValueError("libldap does not support initialize_fd")
8082
if hasattr(fileno, "fileno"):
8183
fileno = fileno.fileno()
8284
self._l = ldap.functions._ldap_function_call(

Lib/slapdtest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
from slapdtest._slapdtest import SlapdObject, SlapdTestCase, SysLogHandler
1111
from slapdtest._slapdtest import requires_ldapi, requires_sasl, requires_tls
12+
from slapdtest._slapdtest import requires_init_fd
1213
from slapdtest._slapdtest import skip_unless_ci

Lib/slapdtest/_slapdtest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ def requires_ldapi():
107107
else:
108108
return identity
109109

110+
def requires_init_fd():
111+
if not ldap.INIT_FD_AVAIL:
112+
return skip_unless_ci(
113+
"test needs ldap.INIT_FD", feature='INIT_FD')
114+
else:
115+
return identity
116+
117+
110118
def _add_sbin(path):
111119
"""Add /sbin and related directories to a command search path"""
112120
directories = path.split(os.pathsep)

Modules/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
/* openldap.h with ldap_init_fd() was introduced in 2.4.48
2525
* see https://bugs.openldap.org/show_bug.cgi?id=8671
2626
*/
27+
#define HAVE_LDAP_INIT_FD 1
2728
#include <openldap.h>
29+
#elif (defined(__APPLE__) && (LDAP_VENDOR_VERSION == 20428))
30+
/* macOS system libldap 2.4.28 does not have ldap_init_fd symbol */
31+
#undef HAVE_LDAP_INIT_FD
2832
#else
2933
/* ldap_init_fd() has been around for a very long time
3034
* SSSD has been defining the function for a while, so it's probably OK.
3135
*/
36+
#define HAVE_LDAP_INIT_FD 1
3237
#define LDAP_PROTO_TCP 1
3338
#define LDAP_PROTO_UDP 2
3439
#define LDAP_PROTO_IPC 3

Modules/constants_generated.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ if (PyModule_AddIntConstant(m, "TLS_AVAIL", 0) != 0)
329329
return -1;
330330
#endif
331331

332+
#ifdef HAVE_LDAP_INIT_FD
333+
if (PyModule_AddIntConstant(m, "INIT_FD_AVAIL", 1) != 0)
334+
return -1;
335+
#else
336+
if (PyModule_AddIntConstant(m, "INIT_FD_AVAIL", 0) != 0)
337+
return -1;
338+
#endif
339+
332340
add_string(CONTROL_MANAGEDSAIT);
333341
add_string(CONTROL_PROXY_AUTHZ);
334342
add_string(CONTROL_SUBENTRIES);

Modules/functions.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args)
3030
return (PyObject *)newLDAPObject(ld);
3131
}
3232

33+
#ifdef HAVE_LDAP_INIT_FD
3334
/* initialize_fd(fileno, url) */
3435

3536
static PyObject *
@@ -82,6 +83,7 @@ l_ldap_initialize_fd(PyObject *unused, PyObject *args)
8283

8384
return (PyObject *)newLDAPObject(ld);
8485
}
86+
#endif
8587

8688
/* ldap_str2dn */
8789

@@ -190,7 +192,9 @@ l_ldap_get_option(PyObject *self, PyObject *args)
190192

191193
static PyMethodDef methods[] = {
192194
{"initialize", (PyCFunction)l_ldap_initialize, METH_VARARGS},
195+
#ifdef HAVE_LDAP_INIT_FD
193196
{"initialize_fd", (PyCFunction)l_ldap_initialize_fd, METH_VARARGS},
197+
#endif
194198
{"str2dn", (PyCFunction)l_ldap_str2dn, METH_VARARGS},
195199
{"set_option", (PyCFunction)l_ldap_set_option, METH_VARARGS},
196200
{"get_option", (PyCFunction)l_ldap_get_option, METH_VARARGS},

Tests/t_cext.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# import the plain C wrapper module
1717
import _ldap
18-
from slapdtest import SlapdTestCase, requires_tls
18+
from slapdtest import SlapdTestCase, requires_tls, requires_init_fd
1919

2020

2121
class TestLdapCExtension(SlapdTestCase):
@@ -248,19 +248,22 @@ def test_simple_bind_fileno(self):
248248
with self._open_conn_fd() as (sock, l):
249249
self.assertEqual(l.whoami_s(), "dn:" + self.server.root_dn)
250250

251+
@requires_init_fd()
251252
def test_simple_bind_fileno_invalid(self):
252253
with open(os.devnull) as f:
253254
l = _ldap.initialize_fd(f.fileno(), self.server.ldap_uri)
254255
with self.assertRaises(_ldap.SERVER_DOWN):
255256
self._bind_conn(l)
256257

258+
@requires_init_fd()
257259
def test_simple_bind_fileno_closed(self):
258260
with self._open_conn_fd() as (sock, l):
259261
self.assertEqual(l.whoami_s(), "dn:" + self.server.root_dn)
260262
sock.close()
261263
with self.assertRaises(_ldap.SERVER_DOWN):
262264
l.whoami_s()
263265

266+
@requires_init_fd()
264267
def test_simple_bind_fileno_rebind(self):
265268
with self._open_conn_fd() as (sock, l):
266269
self.assertEqual(l.whoami_s(), "dn:" + self.server.root_dn)

Tests/t_ldapobject.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from slapdtest import SlapdTestCase
2121
from slapdtest import requires_ldapi, requires_sasl, requires_tls
22+
from slapdtest import requires_init_fd
2223

2324

2425
LDIF_TEMPLATE = """dn: %(suffix)s
@@ -543,6 +544,7 @@ def test105_reconnect_restore(self):
543544
self.assertEqual(l1.whoami_s(), 'dn:'+bind_dn)
544545

545546

547+
@requires_init_fd()
546548
class Test03_SimpleLDAPObjectWithFileno(Test00_SimpleLDAPObject):
547549
def _open_ldap_conn(self, who=None, cred=None, **kwargs):
548550
if hasattr(self, '_sock'):

tox.ini

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ setenv =
4343
PYTHON_LDAP_TRACE_FILE={envtmpdir}/trace.log
4444
commands = {[testenv]commands}
4545

46+
[testenv:macos]
47+
# Travis CI macOS image does not have slapd
48+
# SDK libldap does not support ldap_init_fd
49+
basepython = python3
50+
deps = {[testenv]deps}
51+
passenv = {[testenv]passenv}
52+
setenv =
53+
CI_DISABLED=INIT_FD
54+
commands =
55+
{envpython} -m unittest -v \
56+
Tests/t_cidict.py \
57+
Tests/t_ldap_dn.py \
58+
Tests/t_ldap_filter.py \
59+
Tests/t_ldap_functions.py \
60+
Tests/t_ldap_modlist.py \
61+
Tests/t_ldap_schema_tokenizer.py \
62+
Tests/t_ldapurl.py \
63+
Tests/t_ldif.py \
64+
Tests/t_untested_mods.py
65+
4666
[testenv:pypy3]
4767
basepython = pypy3
4868
deps = pytest

0 commit comments

Comments
 (0)