summaryrefslogtreecommitdiff
path: root/src/tcs/log.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-11-25 14:36:20 +0000
committerIgor Pashev <pashev.igor@gmail.com>2012-11-25 14:36:20 +0000
commitc3649a2def02c41d837ae1f79dda729ccb91e677 (patch)
treebea46dff212fdef977fe9094a70a939e8cc21885 /src/tcs/log.c
downloadtrousers-upstream/0.3.9.tar.gz
Imported Upstream version 0.3.9upstream/0.3.9upstream
Diffstat (limited to 'src/tcs/log.c')
-rw-r--r--src/tcs/log.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/tcs/log.c b/src/tcs/log.c
new file mode 100644
index 0000000..8f3d0b4
--- /dev/null
+++ b/src/tcs/log.c
@@ -0,0 +1,87 @@
+
+/*
+ * Licensed Materials - Property of IBM
+ *
+ * trousers - An open source TCG Software Stack
+ *
+ * (C) Copyright International Business Machines Corp. 2004-2006
+ *
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "trousers/tss.h"
+#include "tcslog.h"
+
+#ifdef TSS_DEBUG
+
+/*
+ * LogBlobData()
+ *
+ * Log a blob's data to the debugging stream
+ *
+ * szDescriptor - The APPID tag found in the caller's environment at build time
+ * sizeOfBlob - The size of the data to log
+ * blob - the data to log
+ *
+ */
+
+void
+LogBlobData(char *szDescriptor, unsigned long sizeOfBlob, unsigned char *blob)
+{
+ char temp[64];
+ unsigned int i;
+
+
+ if (getenv("TCSD_FOREGROUND") == NULL)
+ openlog(szDescriptor, LOG_NDELAY|LOG_PID, TSS_SYSLOG_LVL);
+ memset(temp, 0, sizeof(temp));
+
+ for (i = 0; (unsigned long)i < sizeOfBlob; i++) {
+ if ((i > 0) && ((i % 16) == 0)) {
+ if (getenv("TCSD_FOREGROUND") != NULL)
+ fprintf(stdout, "%s %s\n", szDescriptor, temp);
+ else
+ syslog(LOG_DEBUG, "%s", temp);
+ memset(temp, 0, sizeof(temp));
+ }
+ snprintf(&temp[(i%16)*3], 4, "%.2X ", blob[i]);
+ }
+
+ if (i == sizeOfBlob) {
+ if (getenv("TCSD_FOREGROUND") != NULL)
+ fprintf(stdout, "%s %s\n", szDescriptor, temp);
+ else
+ syslog(LOG_DEBUG, "%s", temp);
+ }
+}
+
+void
+LogTPMERR(TSS_RESULT result, char *file, int line)
+{
+ if (getenv("TSS_DEBUG_OFF") == NULL)
+ fprintf(stderr, "%s %s %s:%d: 0x%x\n", "LOG_RETERR", "TPM", file, line, result);
+}
+
+TSS_RESULT
+LogTDDLERR(TSS_RESULT result, char *file, int line)
+{
+ if (getenv("TSS_DEBUG_OFF") == NULL)
+ fprintf(stderr, "%s %s %s:%d: 0x%x\n", "LOG_RETERR", APPID, file, line, result);
+
+ return (result | TSS_LAYER_TDDL);
+}
+
+TSS_RESULT
+LogTCSERR(TSS_RESULT result, char *file, int line)
+{
+ if (getenv("TSS_DEBUG_OFF") == NULL)
+ fprintf(stderr, "%s %s %s:%d: 0x%x\n", "LOG_RETERR", APPID, file, line, result);
+
+ return (result | TSS_LAYER_TCS);
+}
+
+#endif