From c0e1a362ab9a44a721a3db73a568689f667b4a89 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Jan 17 2017 17:18:51 +0000 Subject: Improved debug options Add krb5 tracing at debug level 3 Always override config file options via command line options. Allow debug level to be reset when configuration changes. Signed-off-by: Simo Sorce Reviewed-by: Robbie Harwood --- diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c index 6398f28..2e14072 100644 --- a/proxy/src/gp_config.c +++ b/proxy/src/gp_config.c @@ -478,6 +478,7 @@ int load_config(struct gp_config *cfg) { struct gp_ini_context *ctx; const char *tmpstr; + int tmp_dbg_lvl = 0; int tmpint = 0; int ret; @@ -489,7 +490,9 @@ int load_config(struct gp_config *cfg) ret = gp_config_get_string(ctx, "gssproxy", "debug", &tmpstr); if (ret == 0) { if (gp_boolean_is_true(tmpstr)) { - gp_debug_enable(1); + if (tmp_dbg_lvl == 0) { + tmp_dbg_lvl = 1; + } } } else if (ret != ENOENT) { goto done; @@ -497,7 +500,7 @@ int load_config(struct gp_config *cfg) ret = gp_config_get_int(ctx, "gssproxy", "debug_level", &tmpint); if (ret == 0) { - gp_debug_enable(tmpint); + tmp_dbg_lvl = tmpint; } else if (ret != ENOENT) { goto done; } @@ -525,6 +528,7 @@ done: if (ret != 0) { GPERROR("Error reading configuration %d: %s", ret, gp_strerror(ret)); } + gp_debug_toggle(tmp_dbg_lvl); gp_config_close(ctx); safefree(ctx); return ret; diff --git a/proxy/src/gp_debug.c b/proxy/src/gp_debug.c index 4a1a26c..3029574 100644 --- a/proxy/src/gp_debug.c +++ b/proxy/src/gp_debug.c @@ -1,16 +1,41 @@ /* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */ #include "config.h" +#include +#include #include "gp_debug.h" #include "gp_log.h" /* global debug switch */ int gp_debug; -void gp_debug_enable(int level) +int gp_debug_args(int level) { + static int args_level = 0; + + if (level != 0) { + args_level = level; + } + return args_level; +} + +void gp_debug_toggle(int level) { - if (level == 0) level = 1; - gp_debug = level; + static bool krb5_trace_set = false; + + /* Command line and environment options override config file */ + gp_debug = gp_debug_args(0); + if (gp_debug == 0) { + gp_debug = level; + } + if (level >= 3) { + if (!getenv("KRB5_TRACE")) { + setenv("KRB5_TRACE", "/dev/stderr", 1); + krb5_trace_set = true; + } + } else if (krb5_trace_set) { + unsetenv("KRB5_TRACE"); + krb5_trace_set = false; + } GPDEBUG("Debug Enabled (level: %d)\n", level); } diff --git a/proxy/src/gp_debug.h b/proxy/src/gp_debug.h index b4dbf80..d3420b0 100644 --- a/proxy/src/gp_debug.h +++ b/proxy/src/gp_debug.h @@ -10,7 +10,8 @@ extern int gp_debug; -void gp_debug_enable(int); +int gp_debug_args(int level); +void gp_debug_toggle(int); void gp_debug_printf(const char *format, ...); void gp_debug_time_printf(const char *format, ...); diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index 02edbac..561188e 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -197,7 +197,8 @@ int main(int argc, const char *argv[]) } if (opt_debug || opt_debug_level > 0) { - gp_debug_enable(opt_debug_level); + if (opt_debug_level == 0) opt_debug_level = 1; + gp_debug_args(opt_debug_level); } if (opt_daemon && opt_interactive) { diff --git a/proxy/tests/testlib.py b/proxy/tests/testlib.py old mode 100644 new mode 100755 index 01ffdc8..66c5672 --- a/proxy/tests/testlib.py +++ b/proxy/tests/testlib.py @@ -477,7 +477,7 @@ def setup_gssapi_env(testdir, wrapenv): GSSPROXY_CONF_TEMPLATE = ''' [gssproxy] - debug_level = 2 + debug_level = 3 [service/test] mechs = krb5 @@ -547,12 +547,14 @@ def setup_gssproxy(testdir, logfile, env): update_gssproxy_conf(testdir, env, GSSPROXY_CONF_TEMPLATE) + gpenv = env.copy() + gpenv['KRB5_TRACE'] = os.path.join(testdir, 'gp_krb5_trace.log') + socket = os.path.join(gssproxy, 'gp.sock') conf = os.path.join(gssproxy, 'gp.conf') gproc = subprocess.Popen(["valgrind", "--track-origins=yes", - "./gssproxy", "-i", "-d", - "-s", socket, "-c", conf], + "./gssproxy", "-i", "-s", socket, "-c", conf], stdout=logfile, stderr=logfile, - env=env, preexec_fn=os.setsid) + env=gpenv, preexec_fn=os.setsid) return gproc, socket