From f50b1977baeaa02ac2862a1cee5a40bb2735d53f Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 9 Jun 2020 13:18:59 +0200 Subject: [PATCH] Use openldap.h on OpenLDAP 2.4.48 OpenLDAP 2.4.48 added openldap.h, which defines ldap_init_fd. Use the header file with 2.4.48 and define the function for older versions. The patch also cleans up #include. All OpenLDAP includes are now in common.h and use global includes ``#include `` instead of local includes ``#include "ldap.h"``. Fixes: https://github.com/python-ldap/python-ldap/issues/353 See: https://bugs.openldap.org/show_bug.cgi?id=8671 Signed-off-by: Christian Heimes --- Modules/LDAPObject.h | 6 ------ Modules/berval.h | 1 - Modules/common.h | 27 +++++++++++++++++++++++++++ Modules/constants.c | 2 -- Modules/constants.h | 2 -- Modules/functions.c | 15 +-------------- Modules/ldapcontrol.c | 2 -- Modules/ldapcontrol.h | 1 - Modules/message.h | 2 -- 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Modules/LDAPObject.h b/Modules/LDAPObject.h index a456bce..1b6066d 100644 --- a/Modules/LDAPObject.h +++ b/Modules/LDAPObject.h @@ -5,12 +5,6 @@ #include "common.h" -#include "lber.h" -#include "ldap.h" -#if LDAP_API_VERSION < 2040 -#error Current python-ldap requires OpenLDAP 2.4.x -#endif - #if PYTHON_API_VERSION < 1007 typedef PyObject *_threadstate; #else diff --git a/Modules/berval.h b/Modules/berval.h index 2aa9c97..9c42724 100644 --- a/Modules/berval.h +++ b/Modules/berval.h @@ -4,7 +4,6 @@ #define __h_berval #include "common.h" -#include "lber.h" PyObject *LDAPberval_to_object(const struct berval *bv); PyObject *LDAPberval_to_unicode_object(const struct berval *bv); diff --git a/Modules/common.h b/Modules/common.h index affa5f9..bde943c 100644 --- a/Modules/common.h +++ b/Modules/common.h @@ -12,6 +12,33 @@ #include "config.h" #endif +#include +#include +#include + +#if LDAP_API_VERSION < 2040 +#error Current python-ldap requires OpenLDAP 2.4.x +#endif + +#if LDAP_VENDOR_VERSION >= 20448 + /* openldap.h with ldap_init_fd() was introduced in 2.4.48 + * see https://bugs.openldap.org/show_bug.cgi?id=8671 + */ +#include +#ifndef HAVE_LDAP_INIT_FD +#define HAVE_LDAP_INIT_FD +#endif +#else + /* ldap_init_fd() has been around for a very long time + * SSSD has been defining the function for a while, so it's probably OK. + */ +#define LDAP_PROTO_TCP 1 +#define LDAP_PROTO_UDP 2 +#define LDAP_PROTO_IPC 3 +extern int ldap_init_fd(ber_socket_t fd, int proto, LDAP_CONST char *url, + LDAP **ldp); +#endif + #if defined(MS_WINDOWS) #include #else /* unix */ diff --git a/Modules/constants.c b/Modules/constants.c index 88658c5..8b902e0 100644 --- a/Modules/constants.c +++ b/Modules/constants.c @@ -4,8 +4,6 @@ #include "common.h" #include "constants.h" #include "ldapcontrol.h" -#include "lber.h" -#include "ldap.h" /* the base exception class */ diff --git a/Modules/constants.h b/Modules/constants.h index b815094..7b9ce53 100644 --- a/Modules/constants.h +++ b/Modules/constants.h @@ -4,8 +4,6 @@ #define __h_constants_ #include "common.h" -#include "lber.h" -#include "ldap.h" extern int LDAPinit_constants(PyObject *m); extern PyObject *LDAPconstant(int); diff --git a/Modules/functions.c b/Modules/functions.c index 9e0312d..e392047 100644 --- a/Modules/functions.c +++ b/Modules/functions.c @@ -32,20 +32,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args) #ifdef HAVE_LDAP_INIT_FD -/* initialize_fd(fileno, url) - * - * ldap_init_fd() is not a private API but it's not in a public header either - * SSSD has been using the function for a while, so it's probably OK. - */ - -#ifndef LDAP_PROTO_TCP -#define LDAP_PROTO_TCP 1 -#define LDAP_PROTO_UDP 2 -#define LDAP_PROTO_IPC 3 -#endif - -extern int - ldap_init_fd(ber_socket_t fd, int proto, LDAP_CONST char *url, LDAP **ldp); +/* initialize_fd(fileno, url) */ static PyObject * l_ldap_initialize_fd(PyObject *unused, PyObject *args) diff --git a/Modules/ldapcontrol.c b/Modules/ldapcontrol.c index 5e2d2ff..e287e9a 100644 --- a/Modules/ldapcontrol.c +++ b/Modules/ldapcontrol.c @@ -6,8 +6,6 @@ #include "berval.h" #include "constants.h" -#include "lber.h" - /* Prints to stdout the contents of an array of LDAPControl objects */ /* XXX: This is a debugging tool, and the printf generates some warnings diff --git a/Modules/ldapcontrol.h b/Modules/ldapcontrol.h index de694c0..74cae42 100644 --- a/Modules/ldapcontrol.h +++ b/Modules/ldapcontrol.h @@ -4,7 +4,6 @@ #define __h_ldapcontrol #include "common.h" -#include "ldap.h" void LDAPinit_control(PyObject *d); void LDAPControl_List_DEL(LDAPControl **); diff --git a/Modules/message.h b/Modules/message.h index 2978ea5..ed73f32 100644 --- a/Modules/message.h +++ b/Modules/message.h @@ -4,8 +4,6 @@ #define __h_message #include "common.h" -#include "lber.h" -#include "ldap.h" extern PyObject *LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls, int add_intermediates);