Skip to content

Commit

Permalink
Use openldap.h on OpenLDAP 2.4.48
Browse files Browse the repository at this point in the history
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 <ldap.h>`` 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 <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Jun 18, 2020
1 parent 8f79376 commit f50b197
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
6 changes: 0 additions & 6 deletions Modules/LDAPObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Modules/berval.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions Modules/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@
#include "config.h"
#endif

#include <lber.h>
#include <ldap.h>
#include <ldap_features.h>

#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 <openldap.h>
#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 <winsock.h>
#else /* unix */
Expand Down
2 changes: 0 additions & 2 deletions Modules/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "common.h"
#include "constants.h"
#include "ldapcontrol.h"
#include "lber.h"
#include "ldap.h"

/* the base exception class */

Expand Down
2 changes: 0 additions & 2 deletions Modules/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions Modules/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions Modules/ldapcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Modules/ldapcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define __h_ldapcontrol

#include "common.h"
#include "ldap.h"

void LDAPinit_control(PyObject *d);
void LDAPControl_List_DEL(LDAPControl **);
Expand Down
2 changes: 0 additions & 2 deletions Modules/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f50b197

Please sign in to comment.