summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-08-09 16:17:48 -0400
committerSimo Sorce <simo@redhat.com>2014-08-10 14:29:38 -0400
commit3914c4b1bd9a94dc9998e7e1a7105a9835da84e0 (patch)
treedec059b4e29cb28bca3572abf4d82ab9d019ea87
parent3d32e76f1c1380f7aa304ad44b95fe132775f864 (diff)
downloadgss-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.
-rw-r--r--Makefile.am2
-rw-r--r--src/debug.c33
-rw-r--r--src/debug.h37
-rw-r--r--src/gss_ntlmssp.h1
-rw-r--r--tests/ntlmssptest.c3
5 files changed, 76 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 047f0d7..5df5d89 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,6 +72,7 @@ GN_MECHGLUE_OBJ = \
src/crypto.c \
src/ntlm_crypto.c \
src/ntlm.c \
+ src/debug.c \
src/gss_err.c \
src/gss_spi.c \
src/gss_names.c \
@@ -88,6 +89,7 @@ dist_noinst_HEADERS = \
src/crypto.h \
src/ntlm_common.h \
src/ntlm.h \
+ src/debug.h \
src/gss_ntlmssp.h \
src/gss_ntlmssp_winbind.h
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 */
diff --git a/tests/ntlmssptest.c b/tests/ntlmssptest.c
index 8a61a2f..ddc9d75 100644
--- a/tests/ntlmssptest.c
+++ b/tests/ntlmssptest.c
@@ -1975,6 +1975,9 @@ int main(int argc, const char *argv[])
struct ntlm_ctx *ctx;
int ret;
+ /* enable trace debugging by dfault in tests */
+ setenv("GSSNTLMSSP_DEBUG", "tests-trace.log", 0);
+
ret = ntlm_init_ctx(&ctx);
if (ret) goto done;