From 363577822aa74772f7c99e588dbcea5df5abe79d Mon Sep 17 00:00:00 2001 From: Ludwig Krispenz Date: Sun, 14 Feb 2016 17:21:18 +0100 Subject: [PATCH] Enable logging of error messages from the openldap client library into ns-slapd error log. This is just a proof of concept, where an how the debug leve is set needs to be defined --- ldap/servers/slapd/ldaputil.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c index 9281e20..787bd68 100644 --- a/ldap/servers/slapd/ldaputil.c +++ b/ldap/servers/slapd/ldaputil.c @@ -124,6 +124,28 @@ slapi_ldap_unbind( LDAP *ld ) where PROTO is ldap or ldaps or ldapi if proto is NULL, assume hostname_or_uri is really a valid ldap uri */ + +static int log_initialized = 0; + +void slapi_util_log_print(char *buffer) +{ + slapi_log_error(SLAPI_LOG_FATAL, "Openldap Client", + "Log: %s", buffer); +} + +static int +slapi_util_set_log_fn(void) +{ + int rc = ber_set_option(NULL, LBER_OPT_LOG_PRINT_FN, slapi_util_log_print); + if (rc == LBER_OPT_SUCCESS) { + log_initialized = 1; + } else { + slapi_log_error(SLAPI_LOG_FATAL, "Openldap Client", + "Failed to init Log Function, err = %d\n", rc); + } + return rc; +} + static char * convert_to_openldap_uri(const char *hostname_or_uri, int port, const char *proto) { @@ -658,6 +680,11 @@ slapi_ldap_init_ext( char *configpluginpath = config_get_saslpath(); char *pluginpath = configpluginpath; char *pp = NULL; + int dbglvl = 1; + + if (!log_initialized) slapi_util_set_log_fn(); + ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &dbglvl); + ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &dbglvl); if (NULL == pluginpath || (*pluginpath == '\0')) { slapi_log_error(SLAPI_LOG_SHELL, "slapi_ldap_init_ext", -- 2.4.3