-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathldapmodule.c
More file actions
95 lines (83 loc) · 2.88 KB
/
Copy pathldapmodule.c
File metadata and controls
95 lines (83 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* See https://www.python-ldap.org/ for details. */
#include "pythonldap.h"
#define _STR(x) #x
#define STR(x) _STR(x)
LDAPAPIInfo LDAPMod_version_info = {
.ldapai_info_version = LDAP_API_INFO_VERSION,
};
int LDAPMod_thread_safe;
static char version_str[] = STR(LDAPMODULE_VERSION);
static char author_str[] = STR(LDAPMODULE_AUTHOR);
static char license_str[] = STR(LDAPMODULE_LICENSE);
static int
init_pkginfo(PyObject *m)
{
if (PyModule_AddStringConstant(m, "__version__", version_str) != 0)
return -1;
if (PyModule_AddStringConstant(m, "__author__", author_str) != 0)
return -1;
if (PyModule_AddStringConstant(m, "__license__", license_str) != 0)
return -1;
return 0;
}
static PyMethodDef ldap_functions[] = {
// functions.c
{"initialize", LDAPMod_initialize, METH_VARARGS},
#ifdef HAVE_LDAP_INIT_FD
{"initialize_fd", LDAPMod_initialize_fd, METH_VARARGS},
#endif
{"str2dn", LDAPMod_str2dn, METH_VARARGS},
{"dn2str", LDAPMod_dn2str, METH_VARARGS},
{"set_option", LDAPMod_set_option, METH_VARARGS},
{"get_option", LDAPMod_get_option, METH_VARARGS},
{"is_filter", LDAPMod_is_filter, METH_VARARGS},
// ldapcontrol.c
{"encode_page_control", LDAPMod_encode_rfc2696, METH_VARARGS},
{"decode_page_control", LDAPMod_decode_rfc2696, METH_VARARGS},
{"encode_valuesreturnfilter_control", LDAPMod_encode_rfc3876,
METH_VARARGS},
{"encode_assertion_control", LDAPMod_encode_assertion_control,
METH_VARARGS},
{NULL, NULL}
};
/* module initialisation */
static PyModuleDef_Slot ldap_slots[] = {
#if PY_VERSION_HEX >= 0x030D0000
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
#if PY_VERSION_HEX >= 0x030C0000
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
#endif
{Py_mod_exec, LDAPMod_init_type},
{Py_mod_exec, LDAPMod_init_constants},
{Py_mod_exec, init_pkginfo},
{0, NULL}
};
static struct PyModuleDef ldap_moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_ldap",
.m_size = sizeof(LDAPModState),
.m_methods = ldap_functions,
.m_slots = ldap_slots,
.m_traverse = LDAPMod_traverse,
.m_clear = LDAPMod_clear,
.m_free = LDAPMod_free,
};
struct PyModuleDef *LDAPMod_moduledef;
PyMODINIT_FUNC
PyInit__ldap()
{
/* Prepare global read-only state shared across all copies of this module */
struct ldap_apifeature_info info = { 1, "X_OPENLDAP_THREAD_SAFE", 0 };
if (ldap_get_option(NULL, LDAP_OPT_API_INFO, &LDAPMod_version_info) != LDAP_SUCCESS) {
PyErr_SetString(PyExc_ImportError, "unrecognised libldap version");
return NULL;
}
#ifdef LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE
if (ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &info) == LDAP_SUCCESS) {
LDAPMod_thread_safe = (info.ldapaif_version == 1);
}
#endif
LDAPMod_moduledef = &ldap_moduledef;
return PyModuleDef_Init(LDAPMod_moduledef);
}