/*
- *
+ * $Id$
+ *
+ * These functions implement the portions of AUTHMODE_LDAP and AUTHMODE_LDAP_AD which
+ * actually speak to the LDAP server.
+ *
+ * Copyright (c) 2009 by Art Cancro and the citadel.org development team.
+ * This program is released under the terms of the GNU General Public License v3
*/
-int ldap_version = 3;
+int ctdl_require_ldap_version = 3;
#include "sysdep.h"
#include "threads.h"
#include "citadel_ldap.h"
+#include "ctdl_module.h"
+
+
#ifdef HAVE_LDAP
#define LDAP_DEPRECATED 1 /* Needed to suppress misleading warnings */
return(errno);
}
- ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
+ ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ctdl_require_ldap_version);
striplt(config.c_ldap_bind_dn);
striplt(config.c_ldap_bind_pw);
tv.tv_sec = 10;
tv.tv_usec = 0;
- sprintf(searchstring, SEARCH_STRING, username);
+ if (config.c_auth_mode == AUTHMODE_LDAP_AD) {
+ sprintf(searchstring, "(sAMAccountName=%s)", username);
+ }
+ else {
+ sprintf(searchstring, "(&(objectclass=posixAccount)(uid=%s))", username);
+ }
i = ldap_search_st(ldserver,
config.c_ldap_base_dn,
CtdlLogPrintf(CTDL_DEBUG, "dn = %s\n", user_dn);
}
- values = ldap_get_values(ldserver, search_result, "cn");
- if (values) {
- if (values[0]) {
- if (fullname) safestrncpy(fullname, values[0], fullname_size);
- CtdlLogPrintf(CTDL_DEBUG, "cn = %s\n", values[0]);
+ if (config.c_auth_mode == AUTHMODE_LDAP_AD) {
+ values = ldap_get_values(ldserver, search_result, "displayName");
+ if (values) {
+ if (values[0]) {
+ if (fullname) safestrncpy(fullname, values[0], fullname_size);
+ CtdlLogPrintf(CTDL_DEBUG, "displayName = %s\n", values[0]);
+ }
+ ldap_value_free(values);
}
- ldap_value_free(values);
}
-
- values = ldap_get_values(ldserver, search_result, "uidNumber");
- if (values) {
- if (values[0]) {
- CtdlLogPrintf(CTDL_DEBUG, "uidNumber = %s\n", values[0]);
- if (uid != NULL) {
- *uid = atoi(values[0]);
+ else {
+ values = ldap_get_values(ldserver, search_result, "cn");
+ if (values) {
+ if (values[0]) {
+ if (fullname) safestrncpy(fullname, values[0], fullname_size);
+ CtdlLogPrintf(CTDL_DEBUG, "cn = %s\n", values[0]);
}
+ ldap_value_free(values);
}
- ldap_value_free(values);
}
- values = ldap_get_values(ldserver, search_result, "objectGUID");
- if (values) {
- if (values[0]) {
- CtdlLogPrintf(CTDL_DEBUG, "objectGUID = (%d characers)\n", strlen(values[0]));
+ if (config.c_auth_mode == AUTHMODE_LDAP_AD) {
+ values = ldap_get_values(ldserver, search_result, "objectGUID");
+ if (values) {
+ if (values[0]) {
+ if (uid != NULL) {
+ *uid = abs(HashLittle(values[0], strlen(values[0])));
+ CtdlLogPrintf(CTDL_DEBUG, "uid hashed from objectGUID = %d\n", *uid);
+ }
+ }
+ ldap_value_free(values);
+ }
+ }
+ else {
+ values = ldap_get_values(ldserver, search_result, "uidNumber");
+ if (values) {
+ if (values[0]) {
+ CtdlLogPrintf(CTDL_DEBUG, "uidNumber = %s\n", values[0]);
+ if (uid != NULL) {
+ *uid = atoi(values[0]);
+ }
+ }
+ ldap_value_free(values);
}
- ldap_value_free(values);
}
}
ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port);
if (ldserver) {
- ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version);
+ ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ctdl_require_ldap_version);
i = ldap_simple_bind_s(ldserver, user_dn, password);
if (i == LDAP_SUCCESS) {
CtdlLogPrintf(CTDL_DEBUG, "LDAP: bind succeeded\n");
}
+/*
+ * Learn LDAP attributes and stuff them into the vCard.
+ * Returns nonzero if we changed anything.
+ */
+int Ctdl_LDAP_to_vCard(char *ldap_dn, struct vCard *v)
+{
+ if (!ldap_dn) return(0);
+ if (!v) return(0);
+
+ /*
+ * FIXME LDAPSTUB this is a stub function
+ *
+ * ldap_dn will contain the DN of the user, and v will contain a pointer to
+ * the vCard that needs to be (re-)populated. Put the requisite LDAP code here.
+ *
+ vcard_set_prop(v, "email;internet", xxx, 0);
+ return(1); * return nonzero to tell the caller that we made changes that need to be saved *
+ *
+ */
+ return(0); /* return zero to tell the caller that we didn't make any changes */
+}
#endif /* HAVE_LDAP */