From 05735e3921a17af41d8e83c626d748cf84d7e67a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 6 Nov 2014 16:21:05 -0500 Subject: [PATCH] CtdlTryUserLDAP() migrtated to ctdl_ldap_initialize() --- citadel/configure.ac | 2 +- citadel/ldap.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/citadel/configure.ac b/citadel/configure.ac index 381f8ddb2..aa900202e 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -760,7 +760,7 @@ fi dnl Checks for the OpenLDAP client library. if test "x$with_ldap" != xno ; then AC_CHECK_HEADERS(ldap.h, - [AC_CHECK_LIB(ldap, ldap_init, + [AC_CHECK_LIB(ldap, ldap_initialize, [ok_ldap=yes],, )]) fi diff --git a/citadel/ldap.c b/citadel/ldap.c index ea4ad0a3d..cb5a01703 100644 --- a/citadel/ldap.c +++ b/citadel/ldap.c @@ -27,6 +27,36 @@ int ctdl_require_ldap_version = 3; #define LDAP_DEPRECATED 1 /* Suppress libldap's warning that we are using deprecated API calls */ #include + + +/* + * Wrapper function for ldap_initialize() that consistently fills in the correct fields + */ +int ctdl_ldap_initialize(LDAP **ld) { + + char server_url[256]; + int ret; + + snprintf(server_url, sizeof server_url, "ldap://%s:%d", config.c_ldap_host, config.c_ldap_port); + ret = ldap_initialize(ld, server_url); + if (ret != LDAP_SUCCESS) { + syslog(LOG_ALERT, "LDAP: Could not connect to %s : %s", + server_url, + strerror(errno) + ); + *ld = NULL; + return(errno); + } + + return(ret); +} + + + + +/* + * Look up a user in the directory to see if this is an account that can be authenticated + */ int CtdlTryUserLDAP(char *username, char *found_dn, int found_dn_size, char *fullname, int fullname_size, @@ -44,11 +74,7 @@ int CtdlTryUserLDAP(char *username, if (fullname) safestrncpy(fullname, username, fullname_size); ldserver = ldap_init(config.c_ldap_host, config.c_ldap_port); - if (ldserver == NULL) { - syslog(LOG_ALERT, "LDAP: Could not connect to %s:%d : %s", - config.c_ldap_host, config.c_ldap_port, - strerror(errno) - ); + if (ctdl_ldap_initialize(&ldserver) != LDAP_SUCCESS) { return(errno); } -- 2.30.2