diff options
author | Simo Sorce <simo@redhat.com> | 2014-08-09 16:17:48 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2014-08-10 14:29:38 -0400 |
commit | 3914c4b1bd9a94dc9998e7e1a7105a9835da84e0 (patch) | |
tree | dec059b4e29cb28bca3572abf4d82ab9d019ea87 /src | |
parent | 3d32e76f1c1380f7aa304ad44b95fe132775f864 (diff) | |
download | gss-ntlmssp-3914c4b1bd9a94dc9998e7e1a7105a9835da84e0.tar.gz gss-ntlmssp-3914c4b1bd9a94dc9998e7e1a7105a9835da84e0.tar.xz gss-ntlmssp-3914c4b1bd9a94dc9998e7e1a7105a9835da84e0.zip |
Add debug helpers to be used to trace gss-ntlmssp
If the GSSNTLMSSP_DEBUG environment variable is set to a file that
can be opened for writing, then trace information will be written to
that file whenever DEBUG macros are called in the code.
Diffstat (limited to 'src')
-rw-r--r-- | src/debug.c | 33 | ||||
-rw-r--r-- | src/debug.h | 37 | ||||
-rw-r--r-- | src/gss_ntlmssp.h | 1 |
3 files changed, 71 insertions, 0 deletions
diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..e6185b4 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2014 GSS-NTLMSSP contributors, see COPYING for license */ + +#define _GNU_SOURCE +#include <stdarg.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +bool gssntlm_debug_initialized = false; +bool gssntlm_debug_enabled = false; +static FILE *debug_fd = NULL; + +void gssntlm_debug_init(void) +{ + char *env; + + env = secure_getenv("GSSNTLMSSP_DEBUG"); + if (env) { + debug_fd = fopen(env, "a"); + if (debug_fd) gssntlm_debug_enabled = true; + } + gssntlm_debug_initialized = true; +} + +void gssntlm_debug_printf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(debug_fd, fmt, ap); + va_end(ap); + fflush(debug_fd); +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..81ed247 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2014 GSS-NTLMSSP contributors, see COPYING for license */ + +#ifndef _GSSNTLMSSP_DEBUG_H_ +#define _GSSNTLMSSP_DEBUG_H_ + +#include <stdbool.h> +#include <time.h> + +extern bool gssntlm_debug_initialized; +extern bool gssntlm_debug_enabled; + +void gssntlm_debug_init(void); +void gssntlm_debug_printf(const char *fmt, ...); + +#define unlikely(x) __builtin_expect(!!(x), 0) + +static inline int debug_gss_errors(const char *function, + const char *file, + unsigned int line, + unsigned int maj, + unsigned int min) +{ + if (unlikely(gssntlm_debug_initialized == false)) { + gssntlm_debug_init(); + } + if (unlikely(gssntlm_debug_enabled == true)) { + gssntlm_debug_printf("[%ld] %s: %s() @ %s:%u [%u:%u]\n", + (long)time(NULL), + GSS_ERROR(maj) ? "ERROR" : "ALLOK", + function, file, line, maj, min); + } + return 0; +} +#define DEBUG_GSS_ERRORS(maj, min) \ + debug_gss_errors(__FUNCTION__, __FILE__, __LINE__, maj, min) + +#endif /* _GSSNTLMSSP_DEBUG_H_ */ diff --git a/src/gss_ntlmssp.h b/src/gss_ntlmssp.h index 68dde38..33b3279 100644 --- a/src/gss_ntlmssp.h +++ b/src/gss_ntlmssp.h @@ -21,6 +21,7 @@ #include "ntlm.h" #include "crypto.h" #include "gssapi_ntlmssp.h" +#include "debug.h" #define MAX_CHALRESP_LIFETIME 36 * 60 * 60 /* 36 hours in seconds */ |