Skip to content

Commit f50b197

Browse files
tiranencukou
authored andcommitted
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 <ldap.h>`` instead of local includes ``#include "ldap.h"``. Fixes: #353 See: https://bugs.openldap.org/show_bug.cgi?id=8671 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 8f79376 commit f50b197

File tree

9 files changed

+28
-30
lines changed

9 files changed

+28
-30
lines changed

Modules/LDAPObject.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
#include "common.h"
77

8-
#include "lber.h"
9-
#include "ldap.h"
10-
#if LDAP_API_VERSION < 2040
11-
#error Current python-ldap requires OpenLDAP 2.4.x
12-
#endif
13-
148
#if PYTHON_API_VERSION < 1007
159
typedef PyObject *_threadstate;
1610
#else

Modules/berval.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define __h_berval
55

66
#include "common.h"
7-
#include "lber.h"
87

98
PyObject *LDAPberval_to_object(const struct berval *bv);
109
PyObject *LDAPberval_to_unicode_object(const struct berval *bv);

Modules/common.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@
1212
#include "config.h"
1313
#endif
1414

15+
#include <lber.h>
16+
#include <ldap.h>
17+
#include <ldap_features.h>
18+
19+
#if LDAP_API_VERSION < 2040
20+
#error Current python-ldap requires OpenLDAP 2.4.x
21+
#endif
22+
23+
#if LDAP_VENDOR_VERSION >= 20448
24+
/* openldap.h with ldap_init_fd() was introduced in 2.4.48
25+
* see https://bugs.openldap.org/show_bug.cgi?id=8671
26+
*/
27+
#include <openldap.h>
28+
#ifndef HAVE_LDAP_INIT_FD
29+
#define HAVE_LDAP_INIT_FD
30+
#endif
31+
#else
32+
/* ldap_init_fd() has been around for a very long time
33+
* SSSD has been defining the function for a while, so it's probably OK.
34+
*/
35+
#define LDAP_PROTO_TCP 1
36+
#define LDAP_PROTO_UDP 2
37+
#define LDAP_PROTO_IPC 3
38+
extern int ldap_init_fd(ber_socket_t fd, int proto, LDAP_CONST char *url,
39+
LDAP **ldp);
40+
#endif
41+
1542
#if defined(MS_WINDOWS)
1643
#include <winsock.h>
1744
#else /* unix */

Modules/constants.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "common.h"
55
#include "constants.h"
66
#include "ldapcontrol.h"
7-
#include "lber.h"
8-
#include "ldap.h"
97

108
/* the base exception class */
119

Modules/constants.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#define __h_constants_
55

66
#include "common.h"
7-
#include "lber.h"
8-
#include "ldap.h"
97

108
extern int LDAPinit_constants(PyObject *m);
119
extern PyObject *LDAPconstant(int);

Modules/functions.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args)
3232

3333
#ifdef HAVE_LDAP_INIT_FD
3434

35-
/* initialize_fd(fileno, url)
36-
*
37-
* ldap_init_fd() is not a private API but it's not in a public header either
38-
* SSSD has been using the function for a while, so it's probably OK.
39-
*/
40-
41-
#ifndef LDAP_PROTO_TCP
42-
#define LDAP_PROTO_TCP 1
43-
#define LDAP_PROTO_UDP 2
44-
#define LDAP_PROTO_IPC 3
45-
#endif
46-
47-
extern int
48-
ldap_init_fd(ber_socket_t fd, int proto, LDAP_CONST char *url, LDAP **ldp);
35+
/* initialize_fd(fileno, url) */
4936

5037
static PyObject *
5138
l_ldap_initialize_fd(PyObject *unused, PyObject *args)

Modules/ldapcontrol.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include "berval.h"
77
#include "constants.h"
88

9-
#include "lber.h"
10-
119
/* Prints to stdout the contents of an array of LDAPControl objects */
1210

1311
/* XXX: This is a debugging tool, and the printf generates some warnings

Modules/ldapcontrol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define __h_ldapcontrol
55

66
#include "common.h"
7-
#include "ldap.h"
87

98
void LDAPinit_control(PyObject *d);
109
void LDAPControl_List_DEL(LDAPControl **);

Modules/message.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#define __h_message
55

66
#include "common.h"
7-
#include "lber.h"
8-
#include "ldap.h"
97

108
extern PyObject *LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls,
119
int add_intermediates);

0 commit comments

Comments
 (0)