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"
43 #include "serv_ldap.h"
50 LDAP *dirserver = NULL;
53 * LDAP connector cleanup function
55 void serv_ldap_cleanup(void)
57 if (!dirserver) return;
59 lprintf(7, "Unbinding from directory server\n");
60 ldap_unbind(dirserver);
64 #endif /* HAVE_LDAP */
67 void CtdlConnectToLdap(void) {
71 lprintf(7, "Connecting to LDAP server %s:%d...\n",
72 config.c_ldap_host, config.c_ldap_port);
74 dirserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
75 if (dirserver == NULL) {
76 lprintf(3, "Could not connect to %s:%d : %s\n",
83 ldap_set_option(dirserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
85 lprintf(7, "Binding to %s\n", config.c_ldap_bind_dn);
87 i = ldap_simple_bind_s(dirserver,
88 config.c_ldap_bind_dn,
91 if (i != LDAP_SUCCESS) {
92 lprintf(3, "Cannot bind: %s (%d)\n", ldap_err2string(i), i);
93 dirserver = NULL; /* FIXME disconnect from ldap */
101 * Write (add, or change if already exists) a directory entry to the
102 * LDAP server, based on the information supplied in a vCard.
104 void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
105 struct vCard *v = NULL;
109 if (msg == NULL) return;
110 if (msg->cm_fields['M'] == NULL) return;
111 if (msg->cm_fields['A'] == NULL) return;
112 if (msg->cm_fields['N'] == NULL) return;
114 sprintf(this_dn, "cn=%s,ou=%s,%s",
117 config.c_ldap_base_dn
120 lprintf(9, "this_dn: <%s>\n", this_dn);
122 v = vcard_load(msg->cm_fields['M']);
131 * Initialize the LDAP connector module ... or don't, if we don't have LDAP.
133 char *serv_ldap_init(void)
136 CtdlRegisterCleanupHook(serv_ldap_cleanup);
138 if (strlen(config.c_ldap_host) > 0) {
142 #endif /* HAVE_LDAP */