From e4e565f82dfc9d41f03192eb23143f31c1921c7a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 10 Apr 2009 07:53:04 +0000 Subject: [PATCH] * LDAP auth config now read from config file --- citadel/citadel_ldap.h | 7 +------ citadel/ldap.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/citadel/citadel_ldap.h b/citadel/citadel_ldap.h index aff1a363f..41cae48ea 100644 --- a/citadel/citadel_ldap.h +++ b/citadel/citadel_ldap.h @@ -1,12 +1,7 @@ /* - * + * Configuration for LDAP authentication. Most of this stuff gets pulled out of our site config file. */ -#define CTDL_LDAP_HOST "ldaptest.xand.com" -#define CTDL_LDAP_PORT LDAP_PORT /* defined as 389 */ -#define BASE_DN "dc=xand,dc=com" -#define BIND_DN NULL /* "cn=Manager,dc=xand,dc=com" for authenticated bind */ -#define BIND_PW NULL /* put pw here for authenticated bind */ #define SEARCH_STRING "(&(objectclass=posixAccount)(uid=%s))" int CtdlTryUserLDAP(char *username, char *found_dn, int found_dn_size, char *fullname, int fullname_size, uid_t *found_uid); diff --git a/citadel/ldap.c b/citadel/ldap.c index 7a59747b3..06f894f7d 100644 --- a/citadel/ldap.c +++ b/citadel/ldap.c @@ -75,17 +75,22 @@ int CtdlTryUserLDAP(char *username, if (fullname) safestrncpy(fullname, username, fullname_size); - ldserver = ldap_init(CTDL_LDAP_HOST, CTDL_LDAP_PORT); + ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port); if (ldserver == NULL) { CtdlLogPrintf(CTDL_ALERT, "LDAP: Could not connect to %s:%d : %s\n", - CTDL_LDAP_HOST, CTDL_LDAP_PORT, + config.c_ldap_host, config.c_ldap_port, strerror(errno)); return(errno); } ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version); - i = ldap_simple_bind_s(ldserver, BIND_DN, BIND_PW); + striplt(config.c_ldap_bind_dn); + striplt(config.c_ldap_bind_pw); + i = ldap_simple_bind_s(ldserver, + (!IsEmptyStr(config.c_ldap_bind_dn) ? config.c_ldap_bind_dn : NULL), + (!IsEmptyStr(config.c_ldap_bind_pw) ? config.c_ldap_bind_pw : NULL) + ); if (i != LDAP_SUCCESS) { CtdlLogPrintf(CTDL_ALERT, "LDAP: Cannot bind: %s (%d)\n", ldap_err2string(i), i); return(i); @@ -97,7 +102,7 @@ int CtdlTryUserLDAP(char *username, sprintf(searchstring, SEARCH_STRING, username); i = ldap_search_st(ldserver, - BASE_DN, + config.c_ldap_base_dn, LDAP_SCOPE_SUBTREE, searchstring, NULL, // return all attributes @@ -181,7 +186,7 @@ int CtdlTryPasswordLDAP(char *user_dn, char *password) LDAP *ldserver = NULL; int i = (-1); - ldserver = ldap_init(CTDL_LDAP_HOST, CTDL_LDAP_PORT); + ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port); if (ldserver) { ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ldap_version); i = ldap_simple_bind_s(ldserver, user_dn, password); -- 2.30.2