Skip to content

Commit ffb4a60

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: python-ldap#359 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent d0882d3 commit ffb4a60

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: 2.7
1826
env:
1927
- TOXENV=py27
@@ -36,6 +44,7 @@ matrix:
3644
- python: 3.7
3745
env:
3846
- TOXENV=py37
47+
- CFLAGS_std="-std=c99"
3948
- WITH_GCOV=1
4049
dist: xenial
4150
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
@@ -104,6 +104,8 @@ def __init__(
104104
self._uri = uri
105105
self._ldap_object_lock = self._ldap_lock('opcall')
106106
if fileno is not None:
107+
if not hasattr(_ldap, "initialize_fd"):
108+
raise ValueError("libldap does not support initialize_fd")
107109
if hasattr(fileno, "fileno"):
108110
fileno = fileno.fileno()
109111
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
@@ -109,6 +109,14 @@ def requires_ldapi():
109109
else:
110110
return identity
111111

112+
def requires_init_fd():
113+
if not ldap.INIT_FD_AVAIL:
114+
return skip_unless_ci(
115+
"test needs ldap.INIT_FD", feature='INIT_FD')
116+
else:
117+
return identity
118+
119+
112120
def _add_sbin(path):
113121
"""Add /sbin and related directories to a command search path"""
114122
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
@@ -18,7 +18,7 @@
1818

1919
# import the plain C wrapper module
2020
import _ldap
21-
from slapdtest import SlapdTestCase, requires_tls
21+
from slapdtest import SlapdTestCase, requires_tls, requires_init_fd
2222

2323

2424
class TestLdapCExtension(SlapdTestCase):
@@ -251,19 +251,22 @@ def test_simple_bind_fileno(self):
251251
with self._open_conn_fd() as (sock, l):
252252
self.assertEqual(l.whoami_s(), "dn:" + self.server.root_dn)
253253

254+
@requires_init_fd()
254255
def test_simple_bind_fileno_invalid(self):
255256
with open(os.devnull) as f:
256257
l = _ldap.initialize_fd(f.fileno(), self.server.ldap_uri)
257258
with self.assertRaises(_ldap.SERVER_DOWN):
258259
self._bind_conn(l)
259260

261+
@requires_init_fd()
260262
def test_simple_bind_fileno_closed(self):
261263
with self._open_conn_fd() as (sock, l):
262264
self.assertEqual(l.whoami_s(), "dn:" + self.server.root_dn)
263265
sock.close()
264266
with self.assertRaises(_ldap.SERVER_DOWN):
265267
l.whoami_s()
266268

269+
@requires_init_fd()
267270
def test_simple_bind_fileno_rebind(self):
268271
with self._open_conn_fd() as (sock, l):
269272
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
@@ -33,6 +33,7 @@
3333

3434
from slapdtest import SlapdTestCase
3535
from slapdtest import requires_ldapi, requires_sasl, requires_tls
36+
from slapdtest import requires_init_fd
3637

3738

3839
LDIF_TEMPLATE = """dn: %(suffix)s
@@ -811,6 +812,7 @@ def test105_reconnect_restore(self):
811812
self.assertEqual(l1.whoami_s(), 'dn:'+bind_dn)
812813

813814

815+
@requires_init_fd()
814816
class Test03_SimpleLDAPObjectWithFileno(Test00_SimpleLDAPObject):
815817
def _get_bytes_ldapobject(self, explicit=True, **kwargs):
816818
raise unittest.SkipTest("Test opens two sockets")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy