Skip to content

Commit 52b1447

Browse files
committed
WIP+reorder: retrieve libldap version on load
1 parent 686a038 commit 52b1447

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Modules/constants.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ LDAPinit_constants(PyObject *m)
231231
if (PyModule_AddIntConstant(m, "LIBLDAP_R", thread_safe) != 0)
232232
return -1;
233233

234+
if (ldap_get_option(NULL, LDAP_OPT_API_INFO, &ldap_version_info) != LDAP_SUCCESS) {
235+
PyErr_SetString(PyExc_ImportError, "unrecognised libldap version");
236+
return -1;
237+
}
238+
if (PyModule_AddIntConstant(m, "VENDOR_VERSION_RUNTIME",
239+
ldap_version_info.ldapai_vendor_version ) != 0)
240+
return -1;
241+
234242
/* Generated constants -- see Lib/ldap/constants.py */
235243

236244
#define add_err(n) do { \

Modules/constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern PyObject *LDAPerror(LDAP *);
1313
extern PyObject *LDAPraise_for_message(LDAP *, LDAPMessage *m);
1414
PyObject *LDAPerr(int errnum);
1515

16+
extern LDAPAPIInfo ldap_version_info;
17+
1618
#ifndef LDAP_CONTROL_PAGE_OID
1719
#define LDAP_CONTROL_PAGE_OID "1.2.840.113556.1.4.319"
1820
#endif /* !LDAP_CONTROL_PAGE_OID */

Modules/ldapmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PyMODINIT_FUNC init_ldap(void);
1616
#define _STR(x) #x
1717
#define STR(x) _STR(x)
1818

19+
LDAPAPIInfo ldap_version_info = {
20+
.ldapai_info_version = LDAP_API_INFO_VERSION,
21+
};
22+
1923
static char version_str[] = STR(LDAPMODULE_VERSION);
2024
static char author_str[] = STR(LDAPMODULE_AUTHOR);
2125
static char license_str[] = STR(LDAPMODULE_LICENSE);

0 commit comments

Comments
 (0)