Skip to content

Commit 605a34b

Browse files
authored
Fix macOS SDK builds without ldap_init_fd
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. #360 Fixes: #359 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 6f06059 commit 605a34b

File tree

13 files changed

+75
-2
lines changed

13 files changed

+75
-2
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

Doc/reference/ldap.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This module defines the following functions:
4949
and explicitly closed after the :class:`~ldap.ldapobject.LDAPObject` is
5050
unbound. The internal connection type is determined from the URI, ``TCP``
5151
for ``ldap://`` / ``ldaps://``, ``IPC`` (``AF_UNIX``) for ``ldapi://``.
52+
The parameter is not available on macOS when python-ldap is compiled with system
53+
libldap, see :py:const:`INIT_FD_AVAIL`.
5254

5355
Note that internally the OpenLDAP function
5456
`ldap_initialize(3) <https://www.openldap.org/software/man.cgi?query=ldap_init&sektion=3>`_
@@ -139,6 +141,12 @@ General
139141
Integer where a non-zero value indicates that python-ldap was built with
140142
support for SSL/TLS (OpenSSL or similar libs).
141143

144+
.. py:data:: INIT_FD_AVAIL
145+
146+
Integer where a non-zero value indicates that python-ldap supports
147+
:py:func:`initialize` from a file descriptor. The feature is generally
148+
available except on macOS when python-ldap is compiled with system libldap.
149+
142150

143151
.. _ldap-options:
144152

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)

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