From b0faccce56bdc075d58724ecf9e4c4eeb399ddd1 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 11 May 2000 09:48:40 +0000 Subject: [PATCH] Added debuglevel parameter to ldap_int_initialize(). --- libraries/libldap/init.c | 26 +++++++++++++++++++++++--- libraries/libldap/ldap-int.h | 3 +-- libraries/libldap/open.c | 2 +- libraries/libldap/options.c | 13 +++++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 816cc28881..df24f1fe61 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -101,12 +101,16 @@ static void openldap_ldap_init_w_conf( return; } + Debug(LDAP_DEBUG_TRACE, "ldap_init: trying %s\n", file, 0, 0); + fp = fopen(file, "r"); if(fp == NULL) { /* could not open file */ return; } + Debug(LDAP_DEBUG_TRACE, "ldap_init: using %s\n", file, 0, 0); + while((start = fgets(linebuf, sizeof(linebuf), fp)) != NULL) { /* skip lines starting with '#' */ if(*start == '#') continue; @@ -220,7 +224,7 @@ static void openldap_ldap_init_w_sysconf(const char *file) static void openldap_ldap_init_w_userconf(const char *file) { char *home; - char *path; + char *path = NULL; if (file == NULL) { /* no file name */ @@ -230,9 +234,12 @@ static void openldap_ldap_init_w_userconf(const char *file) home = getenv("HOME"); if (home != NULL) { + Debug(LDAP_DEBUG_TRACE, "ldap_init: HOME env is %s\n", + home, 0, 0); path = LDAP_MALLOC(strlen(home) + strlen(file) + 3); } else { - path = LDAP_MALLOC(strlen(file) + 3); + Debug(LDAP_DEBUG_TRACE, "ldap_init: HOME env is NULL\n", + 0, 0, 0); } if(home != NULL && path != NULL) { @@ -337,7 +344,7 @@ static void openldap_ldap_init_w_env(const char *prefix) } } -void ldap_int_initialize( void ) +void ldap_int_initialize( int *dbglvl ) { if ( gopts.ldo_valid == LDAP_INITIALIZED ) { return; @@ -356,6 +363,9 @@ void ldap_int_initialize( void ) if ( ldap_int_tblsize == 0 ) ldap_int_ip_init(); + if (dbglvl) + gopts.ldo_debug = *dbglvl; + else gopts.ldo_debug = 0; gopts.ldo_version = LDAP_VERSION2; @@ -399,16 +409,26 @@ void ldap_int_initialize( void ) char *altfile = getenv(LDAP_ENV_PREFIX "CONF"); if( altfile != NULL ) { + Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is %s\n", + LDAP_ENV_PREFIX "CONF", altfile, 0); openldap_ldap_init_w_sysconf( altfile ); } + else + Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is NULL\n", + LDAP_ENV_PREFIX "CONF", 0, 0); } { char *altfile = getenv(LDAP_ENV_PREFIX "RC"); if( altfile != NULL ) { + Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is %s\n", + LDAP_ENV_PREFIX "RC", altfile, 0); openldap_ldap_init_w_userconf( altfile ); } + else + Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is NULL\n", + LDAP_ENV_PREFIX "RC", 0, 0); } openldap_ldap_init_w_env(NULL); diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index a19ea260e8..c0957b68fc 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -291,8 +291,7 @@ extern ldap_pvt_thread_mutex_t ldap_int_resolv_mutex; */ LIBLDAP_F ( struct ldapoptions ) ldap_int_global_options; -LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((void)); - +LIBLDAP_F ( void ) ldap_int_initialize LDAP_P((int *)); /* memory.c */ /* simple macros to realloc for now */ diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 29a9dded37..7339bc3415 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -80,7 +80,7 @@ ldap_create( LDAP **ldp ) *ldp = NULL; if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) { - ldap_int_initialize(); + ldap_int_initialize(NULL); } Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 ); diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index d7db40b27e..dbc4fd5d98 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -87,7 +87,7 @@ ldap_get_option( const struct ldapoptions *lo; if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) { - ldap_int_initialize(); + ldap_int_initialize(NULL); } if(ld == NULL) { @@ -308,9 +308,18 @@ ldap_set_option( LDAP_CONST void *invalue) { struct ldapoptions *lo; + int *dbglvl = NULL; + + /* + * The architecture to turn on debugging has a chicken and egg + * problem. Thus, we introduce a fix here. + */ + + if (option == LDAP_OPT_DEBUG_LEVEL) + dbglvl = (int *) invalue; if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) { - ldap_int_initialize(); + ldap_int_initialize(dbglvl); } if(ld == NULL) { -- 2.39.5