Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nslcd
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2009-04-30 10:45:33 +0200
committerArthur de Jong <arthur@arthurdejong.org>2009-04-30 10:45:33 +0200
commit77c0429d691f1b3477803413210e55940330f9e8 (patch)
tree100d45cf4e11674a8fa2429da33db7c8f9320e2c /nslcd
parent81386e8ddac69ca5f5cd27c952a0ff8c65e79873 (diff)
move debugging initialisation to myldap_set_debuglevel() function
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@852 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd')
-rw-r--r--nslcd/cfg.c3
-rw-r--r--nslcd/cfg.h2
-rw-r--r--nslcd/myldap.c74
-rw-r--r--nslcd/myldap.h5
-rw-r--r--nslcd/nslcd.c4
5 files changed, 51 insertions, 37 deletions
diff --git a/nslcd/cfg.c b/nslcd/cfg.c
index 97ddf5f..5f0c620 100644
--- a/nslcd/cfg.c
+++ b/nslcd/cfg.c
@@ -5,7 +5,7 @@
Copyright (C) 1997-2005 Luke Howard
Copyright (C) 2007 West Consulting
- Copyright (C) 2007, 2008 Arthur de Jong
+ Copyright (C) 2007, 2008, 2009 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -108,7 +108,6 @@ static void cfg_defaults(struct ldap_config *cfg)
#endif /* LDAP_OPT_X_TLS */
cfg->ldc_restart=1;
cfg->ldc_pagesize=0;
- cfg->ldc_debug=0;
}
/* simple strdup wrapper */
diff --git a/nslcd/cfg.h b/nslcd/cfg.h
index 72eec98..71a4417 100644
--- a/nslcd/cfg.h
+++ b/nslcd/cfg.h
@@ -140,8 +140,6 @@ struct ldap_config
int ldc_restart;
/* set to a greater than 0 to enable handling of paged results with the specified size */
int ldc_pagesize;
- /* LDAP debug level */
- int ldc_debug;
};
/* this is a pointer to the global configuration, it should be available
diff --git a/nslcd/myldap.c b/nslcd/myldap.c
index 993745e..f35b004 100644
--- a/nslcd/myldap.c
+++ b/nslcd/myldap.c
@@ -454,37 +454,6 @@ static int do_set_options(MYLDAP_SESSION *session)
int rc;
struct timeval tv;
int i;
- /* turn on debugging */
- if (nslcd_cfg->ldc_debug)
- {
-#ifdef LBER_OPT_LOG_PRINT_FILE
- log_log(LOG_DEBUG,"ber_set_option(LBER_OPT_LOG_PRINT_FILE)"); \
- rc=ber_set_option(NULL,LBER_OPT_LOG_PRINT_FILE,stderr);
- if (rc!=LDAP_SUCCESS)
- {
- log_log(LOG_ERR,"ber_set_option(LBER_OPT_LOG_PRINT_FILE) failed: %s",ldap_err2string(rc));
- return rc;
- }
-#endif /* LBER_OPT_LOG_PRINT_FILE */
-#ifdef LBER_OPT_DEBUG_LEVEL
- if (nslcd_cfg->ldc_debug>1)
- {
- i=-1;
- log_log(LOG_DEBUG,"ber_set_option(LBER_OPT_DEBUG_LEVEL,-1)");
- rc=ber_set_option(NULL,LBER_OPT_DEBUG_LEVEL,&i);
- if (rc!=LDAP_SUCCESS)
- {
- log_log(LOG_ERR,"ber_set_option(LBER_OPT_DEBUG_LEVEL) failed: %s",ldap_err2string(rc));
- return rc;
- }
- }
-#endif /* LBER_OPT_DEBUG_LEVEL */
-#ifdef LDAP_OPT_DEBUG_LEVEL
- i=-1;
- log_log(LOG_DEBUG,"ldap_set_option(LDAP_OPT_DEBUG_LEVEL,-1)");
- LDAP_SET_OPTION(NULL,LDAP_OPT_DEBUG_LEVEL,&i);
-#endif /* LDAP_OPT_DEBUG_LEVEL */
- }
#ifdef HAVE_LDAP_SET_REBIND_PROC
/* the rebind function that is called when chasing referrals, see
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/topic/apis/ldap_set_rebind_proc.htm
@@ -1633,3 +1602,46 @@ int myldap_escape(const char *src,char *buffer,size_t buflen)
buffer[pos]='\0';
return 0;
}
+
+int myldap_set_debuglevel(int level)
+{
+ int i;
+ int rc;
+ /* turn on debugging */
+ if (level>1)
+ {
+#ifdef LBER_OPT_LOG_PRINT_FILE
+ log_log(LOG_DEBUG,"ber_set_option(LBER_OPT_LOG_PRINT_FILE)"); \
+ rc=ber_set_option(NULL,LBER_OPT_LOG_PRINT_FILE,stderr);
+ if (rc!=LDAP_SUCCESS)
+ {
+ log_log(LOG_ERR,"ber_set_option(LBER_OPT_LOG_PRINT_FILE) failed: %s",ldap_err2string(rc));
+ return rc;
+ }
+#endif /* LBER_OPT_LOG_PRINT_FILE */
+#ifdef LBER_OPT_DEBUG_LEVEL
+ if (level>2)
+ {
+ i=-1;
+ log_log(LOG_DEBUG,"ber_set_option(LBER_OPT_DEBUG_LEVEL,-1)");
+ rc=ber_set_option(NULL,LBER_OPT_DEBUG_LEVEL,&i);
+ if (rc!=LDAP_SUCCESS)
+ {
+ log_log(LOG_ERR,"ber_set_option(LBER_OPT_DEBUG_LEVEL) failed: %s",ldap_err2string(rc));
+ return rc;
+ }
+ }
+#endif /* LBER_OPT_DEBUG_LEVEL */
+#ifdef LDAP_OPT_DEBUG_LEVEL
+ i=-1;
+ log_log(LOG_DEBUG,"ldap_set_option(LDAP_OPT_DEBUG_LEVEL,-1)");
+ rc=ldap_set_option(NULL,LDAP_OPT_DEBUG_LEVEL,&i);
+ if (rc!=LDAP_SUCCESS)
+ {
+ log_log(LOG_ERR,"ldap_set_option(LDAP_OPT_DEBUG_LEVEL) failed: %s",ldap_err2string(rc));
+ return rc;
+ }
+#endif /* LDAP_OPT_DEBUG_LEVEL */
+ }
+ return LDAP_SUCCESS;
+}
diff --git a/nslcd/myldap.h b/nslcd/myldap.h
index 106d803..01ee55d 100644
--- a/nslcd/myldap.h
+++ b/nslcd/myldap.h
@@ -2,7 +2,7 @@
myldap.h - simple interface to do LDAP requests
This file is part of the nss-ldapd library.
- Copyright (C) 2007, 2008 Arthur de Jong
+ Copyright (C) 2007, 2008, 2009 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -122,4 +122,7 @@ MUST_USE const char *myldap_cpy_rdn_value(const char *dn,const char *attr,
/* Escapes characters in a string for use in a search filter. */
MUST_USE int myldap_escape(const char *src,char *buffer,size_t buflen);
+/* Set the debug level globally. */
+int myldap_set_debuglevel(int i);
+
#endif /* not _MYLDAP_H */
diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c
index f50ddeb..816aa0a 100644
--- a/nslcd/nslcd.c
+++ b/nslcd/nslcd.c
@@ -553,9 +553,11 @@ int main(int argc,char *argv[])
log_log(LOG_ERR,"unable to override hosts lookup method: %s",strerror(errno));
#endif /* HAVE___NSS_CONFIGURE_LOOKUP */
/* FIXME: have some other mechanism for systems that don't have this */
+ /* set LDAP log level */
+ if (myldap_set_debuglevel(nslcd_debugging)!=LDAP_SUCCESS)
+ exit(EXIT_FAILURE);
/* read configuration file */
cfg_init(NSS_LDAP_PATH_CONF);
- nslcd_cfg->ldc_debug=nslcd_debugging?nslcd_debugging-1:0;
/* daemonize */
if ((!nslcd_debugging)&&(daemon(0,0)<0))
{