From be13a48d8929c6edcc7525749d57ce450204d657 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 30 Mar 2012 12:13:38 -0400 Subject: Debug: Add debugging macro and config options Ticket #43 --- proxy/src/gp_common.h | 2 ++ proxy/src/gp_config.c | 9 +++++++++ proxy/src/gp_debug.c | 10 ++++++++++ proxy/src/gp_debug.h | 10 ++++++++++ proxy/src/gssproxy.c | 7 +++++++ 5 files changed, 38 insertions(+) diff --git a/proxy/src/gp_common.h b/proxy/src/gp_common.h index 3763e12..89c7827 100644 --- a/proxy/src/gp_common.h +++ b/proxy/src/gp_common.h @@ -26,6 +26,8 @@ #ifndef _GP_COMMON_H_ #define _GP_COMMON_H_ +#include "gp_debug.h" + /* add element to list head */ #define LIST_ADD(list, elem) do { \ elem->prev = NULL; \ diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c index ca0f2c1..f20a7b8 100644 --- a/proxy/src/gp_config.c +++ b/proxy/src/gp_config.c @@ -286,6 +286,15 @@ int load_config(struct gp_config *cfg) return ENOENT; } + tmpstr = iniparser_getstring(d, "gssproxy:debug", NULL); + if (tmpstr) { + if (strcasecmp(tmpstr, "1") == 0 || + strcasecmp(tmpstr, "on") == 0 || + strcasecmp(tmpstr, "true") == 0) { + gp_debug_enable(); + } + } + tmpstr = iniparser_getstring(d, "gssproxy:socket", NULL); if (tmpstr) { cfg->socket_name = strdup(tmpstr); diff --git a/proxy/src/gp_debug.c b/proxy/src/gp_debug.c index 2f94738..dbf7c49 100644 --- a/proxy/src/gp_debug.c +++ b/proxy/src/gp_debug.c @@ -24,8 +24,18 @@ */ #include "config.h" +#include #include "gp_debug.h" +/* global debug switch */ +int gp_debug; + +void gp_debug_enable(void) +{ + gp_debug = 1; + GPDEBUG("Debug Enabled\n"); +} + void gp_log_failure(gss_OID mech, uint32_t maj, uint32_t min) { uint32_t msgctx; diff --git a/proxy/src/gp_debug.h b/proxy/src/gp_debug.h index 5f1a525..3bcc3bd 100644 --- a/proxy/src/gp_debug.h +++ b/proxy/src/gp_debug.h @@ -29,6 +29,16 @@ #include #include "rpcgen/gss_proxy.h" +extern int gp_debug; + +void gp_debug_enable(void); + +#define GPDEBUG(...) do { \ + if (gp_debug) { \ + fprintf(stderr, __VA_ARGS__); \ + } \ +} while(0) + void gp_log_failure(gss_OID mech, uint32_t maj, uint32_t min); #endif /* _GP_DEBUG_H_ */ diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index 311cc52..f8a0834 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -36,6 +36,7 @@ int main(int argc, const char *argv[]) int opt_interactive = 0; int opt_version = 0; char *opt_config_file = NULL; + int opt_debug = 0; verto_ctx *vctx; verto_ev *ev; int vflags; @@ -51,6 +52,8 @@ int main(int argc, const char *argv[]) _("Run interactive (not a daemon)"), NULL}, \ {"config", 'c', POPT_ARG_STRING, &opt_config_file, 0, \ _("Specify a non-default config file"), NULL}, \ + {"debug", 'd', POPT_ARG_NONE, &opt_debug, 0, \ + _("Specify a non-default config file"), NULL}, \ {"version", '\0', POPT_ARG_NONE, &opt_version, 0, \ _("Print version number and exit"), NULL }, \ POPT_TABLEEND @@ -72,6 +75,10 @@ int main(int argc, const char *argv[]) return 0; } + if (opt_debug) { + gp_debug_enable(); + } + if (opt_daemon && opt_interactive) { fprintf(stderr, "Option -i|--interactive is not allowed together with -D|--daemon\n"); poptPrintUsage(pc, stderr, 0); -- cgit