4 * A module which implements the LDAP connector for Citadel.
16 #include <sys/types.h>
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
23 # include <sys/time.h>
34 #include "sysdep_decls.h"
35 #include "citserver.h"
38 #include "serv_extensions.h"
48 LDAP *dirserver = NULL;
51 * LDAP connector cleanup function
53 void serv_ldap_cleanup(void)
55 if (!dirserver) return;
57 lprintf(7, "Unbinding from directory server\n");
58 ldap_unbind(dirserver);
62 #endif /* HAVE_LDAP */
65 void CtdlConnectToLdap(void) {
69 lprintf(7, "Connecting to LDAP server %s:%d...\n",
70 config.c_ldap_host, config.c_ldap_port);
72 dirserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
73 if (dirserver == NULL) {
74 lprintf(3, "Could not connect to %s:%d : %s\n",
81 ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
83 lprintf(7, "Binding to %s\n", config.c_ldap_bind_dn);
85 i = ldap_simple_bind_s(dirserver,
86 config.c_ldap_bind_dn,
89 if (i != LDAP_SUCCESS) {
90 lprintf(3, "Cannot bind: %s (%d)\n", ldap_err2string(i), i);
91 dirserver = NULL; /* FIXME disconnect from ldap */
97 * Initialize the LDAP connector module ... or don't, if we don't have LDAP.
99 char *serv_ldap_init(void)
102 CtdlRegisterCleanupHook(serv_ldap_cleanup);
104 if (strlen(config.c_ldap_host) > 0) {
108 #endif /* HAVE_LDAP */