From d4fa80b2249a2790aa4f1c7001a9093a63c4b3e5 Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Oct 06 2022 08:22:26 +0000 Subject: ipapython: Support openldap 2.6 While python-ldap is strict dependency of IPA in downstreams, it is optional for IPA packages published on PyPI. Openldap 2.6 no longer ships ldap_r-2, that makes ipapython.dn_ctypes not working against such environments. Thanks @abbra! Fixes: https://pagure.io/freeipa/issue/9255 Signed-off-by: Stanislav Levin Reviewed-By: Alexander Bokovoy Reviewed-By: Rob Crittenden --- diff --git a/ipapython/dn_ctypes.py b/ipapython/dn_ctypes.py index fd073a6..0f7099a 100644 --- a/ipapython/dn_ctypes.py +++ b/ipapython/dn_ctypes.py @@ -12,12 +12,15 @@ import six __all__ = ("str2dn", "dn2str", "DECODING_ERROR", "LDAPError") -# load reentrant ldap client library (libldap_r-*.so.2) -ldap_r_lib = ctypes.util.find_library("ldap_r-2") -if ldap_r_lib is None: - raise ImportError("libldap_r shared library missing") +# load reentrant ldap client library (libldap_r-*.so.2 or libldap.so.2) +ldap_lib_filename = next( + filter(None, map(ctypes.util.find_library, ["ldap_r-2", "ldap"])), None +) + +if ldap_lib_filename is None: + raise ImportError("libldap_r or libldap shared library missing") try: - lib = ctypes.CDLL(ldap_r_lib) + lib = ctypes.CDLL(ldap_lib_filename) except OSError as e: raise ImportError(str(e)) diff --git a/ipatests/azure/templates/prepare-tox-fedora.yml b/ipatests/azure/templates/prepare-tox-fedora.yml index e1f16d2..3386e60 100644 --- a/ipatests/azure/templates/prepare-tox-fedora.yml +++ b/ipatests/azure/templates/prepare-tox-fedora.yml @@ -2,6 +2,5 @@ steps: - script: | set -e sudo dnf -y install nss-tools python3-pip git - sudo ln -s /usr/lib64/libldap.so /usr/lib64/libldap_r.so python3 -m pip install --user --upgrade pip setuptools pycodestyle displayName: Install Tox prerequisites