OSDN Git Service

Re-organize console out and logging out
authorSeiji Munetoh <munetoh@jp.ibm.com>
Wed, 4 Jan 2012 08:09:31 +0000 (17:09 +0900)
committerSeiji Munetoh <munetoh@jp.ibm.com>
Wed, 4 Jan 2012 08:09:31 +0000 (17:09 +0900)
51 files changed:
Makefile.am
configure.in
dist/ptsc.conf.in
include/openpts_log.h
man/Makefile.am
man/man8/Makefile.am
man/man8/openpts.8
src/Makefile.am
src/action.c
src/aide.c
src/aru.c
src/base64.c
src/collector.c
src/conf.c
src/ctx.c
src/fsm.c
src/ifm.c
src/imc.c
src/iml.c
src/iml2aide.c
src/iml2text.c
src/imv.c
src/ir.c
src/ir2text.c
src/log.c
src/misc.c
src/nonce.c
src/openpts.c
src/policy.c
src/prop.c
src/ptsc.c
src/ptsevtd.c
src/reason.c
src/rm.c
src/rm2dot.c
src/smbios.c
src/snapshot.c
src/ssh.c
src/target.c
src/tboot2iml.c
src/tpm.c
src/tpm_createkey.c
src/tpm_extendpcr.c
src/tpm_readpcr.c
src/tss.c
src/uml.c
src/uml2dot.c
src/uuid.c
src/uuid_libc.c
src/uuid_libuuid.c
src/verifier.c

index d52e8da..764100b 100644 (file)
@@ -35,7 +35,7 @@ ACLOCAL_AMFLAGS = -I m4
 #
 #EXTRA_DIST = LICENSE
 
-SUBDIRS = m4 po src doc models
+SUBDIRS = m4 po include src doc models man
 
 #
 # Symlink to openpts-version dir
index e23fedf..1bc79e0 100644 (file)
@@ -334,6 +334,7 @@ AC_CONFIG_FILES(Makefile  \
         man/Makefile      \
         man/man1/Makefile \
         man/man3/Makefile \
+        man/man5/Makefile \
         man/man8/Makefile)
 
 AC_OUTPUT
index 3738c51..e73c8eb 100644 (file)
 openpts.version=@VERSION@
 
 #
+# Logging&Debug
+# logging.file=./openpts.log
+logging.location=syslog
+debug.mode=0x0
+
+#
 # Platform metadata (SMBIOS) - TBD
 #
 #   set manually
index aac0d3f..5169ae6 100644 (file)
@@ -34,7 +34,6 @@
 #define INCLUDE_OPENPTS_LOG_H_
 
 #include <syslog.h>
-#include <assert.h>
 
 #ifdef NLS
 #undef NLS
@@ -59,12 +58,35 @@ extern nl_catd catd;
 extern int debugBits;
 extern int verbosity;
 
+/* Macro for console out (stdout) */
+
+#define OUTPUT(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
+
+/* Macro for console out (stderr) */
+
+#define ERROR(fmt, ...)  fprintf(stderr, fmt, ##__VA_ARGS__)
+
+/* Macro for console out (stderr) */
+
+#define VERBOSE(v, fmt, ...) if (verbosity >= v) fprintf(stderr, fmt, ##__VA_ARGS__)
+/* helpers */
+#define setVerbosity(x) (verbosity = (x))
+#define incVerbosity()  (verbosity++)
+#define getVerbosity()  (verbosity)
+
+/* Macro for logging out (syslog/file/console) */
+
 #define OPENPTS_LOG_UNDEFINED 0
 #define OPENPTS_LOG_SYSLOG    1
 #define OPENPTS_LOG_CONSOLE   2
 #define OPENPTS_LOG_FILE      3
 #define OPENPTS_LOG_NULL      4
 
+/* ERROR/INFO/TODO */
+#define LOG_TODO        0x0006  // = LOG_INFO
+#define LOG(type, fmt, ...) writeLog(type,  "%s:%d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
+
+/* DEBUG */
 #define DEBUG_FLAG     0x01
 #define DEBUG_FSM_FLAG 0x02
 #define DEBUG_XML_FLAG 0x04
@@ -73,23 +95,6 @@ extern int verbosity;
 #define DEBUG_TPM_FLAG 0x20
 #define DEBUG_CAL_FLAG 0x40
 
-#define isDebugFlagSet(x) (debugBits & (x))
-#define isAnyDebugFlagSet(x) (debugBits != 0)
-#define setDebugFlags(x) (debugBits = (x))
-#define getDebugFlags() (debugBits)
-#define addDebugFlags(x) (debugBits |= (x))
-
-#define setVerbosity(x) (verbosity = (x))
-#define incVerbosity() (verbosity++)
-#define getVerbosity() (verbosity)
-
-#define OUTPUT(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
-#define VERBOSE(v, fmt, ...) if (verbosity >= v) fprintf(stderr, fmt, ##__VA_ARGS__)
-
-#define ERROR(fmt, ...) writeLog(LOG_ERR,  "%s:%d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
-#define TODO(fmt, ...)  writeLog(LOG_INFO, "%s:%d TODO " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
-#define INFO(fmt, ...)  writeLog(LOG_INFO, fmt, ##__VA_ARGS__)
-
 #define DEBUG_WITH_FLAG(debug_level, fmt, ...) if (debugBits & debug_level) \
 writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
 
@@ -101,6 +106,16 @@ writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
 #define DEBUG_TPM(fmt, ...) DEBUG_WITH_FLAG(DEBUG_TPM_FLAG, fmt, ##__VA_ARGS__)
 #define DEBUG_CAL(fmt, ...) DEBUG_WITH_FLAG(DEBUG_CAL_FLAG, fmt, ##__VA_ARGS__)
 
+/* helpers */
+#define isDebugFlagSet(x) (debugBits & (x))
+#define isAnyDebugFlagSet(x) (debugBits != 0)
+#define setDebugFlags(x) (debugBits = (x))
+#define getDebugFlags() (debugBits)
+#define addDebugFlags(x) (debugBits |= (x))
+
+
+
+
 void writeLog(int priority, const char *format, ...);
 void initCatalog(void);
 void setLogLocation(int ll, char *filename);
index 8f9f742..2af4b58 100644 (file)
@@ -23,4 +23,4 @@
 # http://www.opensource.org/licenses/cpl1.0.php.
 #
 
-SUBDIRS = man1 man3 man8
+SUBDIRS = man1 man3 man5 man8
index a1c2c7a..e399cc9 100644 (file)
 # http://www.opensource.org/licenses/cpl1.0.php.
 #
 
-man8_MANS =    openpts.8
-
-#              tpm_clear.8             \
-#              tpm_createek.8          \
-#              tpm_getpubek.8          \
-#              tpm_restrictpubek.8     \
-#              tpm_selftest.8          \
-#              tpm_setactive.8         \
-#              tpm_setclearable.8      \
-#              tpm_setenable.8         \
-#              tpm_setownable.8        \
-#              tpm_setpresence.8       \
-#              tpm_takeownership.8
-#
-#if TSS_LIB_IS_12
-#man8_MANS+=tpm_revokeek.8 tpm_setoperatorauth.8 tpm_resetdalock.8
-#endif
+man8_MANS = openpts.8 \
+            ptsc.8 \
+            iml2text.8
 
 EXTRA_DIST = $(man8_MANS)
index e69de29..0497a65 100644 (file)
@@ -0,0 +1,79 @@
+.\" Copyright (C) 2011 International Business Machines Corporation
+.\"
+.de Sh \" Subsection
+.br
+.ie \\n(.$>=3 .ne \\$3
+.el .ne 3
+.IP "\\$1" \\$2
+..
+.TH "openpts" 8 "2012-01-04"  "Platform Trust Services(PTS)"
+.ce 1
+Platform Trust Services(PTS) - openpts
+.SH NAME
+openpts \- PTS verifier command
+.SH "SYNOPSIS"
+.ad l
+.hy 0
+.B openpts
+.RB [ OPTION ]
+.RB <target>
+
+.SH "DESCRIPTION"
+.PP
+\fBopenpts\fR is a verifier side application of Platform Trust Services(PTS).
+
+
+.SH "COMMANDS"
+
+.TP
+\fB-i\fR
+Enroll a target node and acquire [overwrite (-f)] the reference measurement.
+
+.TP
+\fB-v\fR
+Verify target (collector) integrity against known measurement.
+
+.TP
+\fB-r\fR
+Remove the target from the set of known reference measurements.
+
+.TP
+\fB\-h\fR
+Display command usage info.
+
+.TP
+\fB-D\fR
+Display the configuration (target/ALL)
+
+.SH "OPTIONS"
+
+.TP
+\fB-u\fR
+Accept a measurement update during attestation, if there are any available.
+
+
+.TP
+\fB-l username\fR
+ssh username [ssh default]
+
+.TP
+\fB-p port\fR
+ssh port number [ssh default]
+
+.TP
+\fB-c configfile\fR
+Set configuration file [~/.openpts/openpts.conf]
+
+.TP
+\fB-V\fR
+Verbose mode. Multiple -V options increase the verbosity.
+
+
+.SH "SEE ALSO"
+.PP
+\fBptsc\fR(8)
+.SH "AUTHOR"
+Seiji Munetoh
+.SH "REPORTING BUGS"
+Report bugs to <openpts-users@lists.sourceforge.jp>
+
index f15fae9..d1e55cb 100644 (file)
@@ -99,13 +99,14 @@ ir2text_SOURCES = ir2text.c
 
 #base64.c log.c
 
-ptsevt_CFLAGS = $(AM_CFLAGS)
-ptsevt_LDFLAGS = $(AM_LDFLAGS)
-ptsevt_SOURCES = ptsevt.c
+# AIX
+#ptsevt_CFLAGS = $(AM_CFLAGS)
+#ptsevt_LDFLAGS = $(AM_LDFLAGS)
+#ptsevt_SOURCES = ptsevt.c
 
-ptsevtd_CFLAGS = $(AM_CFLAGS)
-ptsevtd_LDFLAGS = $(AM_LDFLAGS) -lrt
-ptsevtd_SOURCES = ptsevtd.c
+#ptsevtd_CFLAGS = $(AM_CFLAGS)
+#ptsevtd_LDFLAGS = $(AM_LDFLAGS) -lrt
+#ptsevtd_SOURCES = ptsevtd.c
 
 
 if HAVE_LIBUUID
index e32dfc7..a40ff34 100644 (file)
@@ -90,7 +90,7 @@ int resetPCR(OPENPTS_CONTEXT *ctx, char *value) {
     DEBUG_FSM("resetPCR(%d)\n", pcr_index);
     rc = resetTpmPcr(&ctx->tpm, pcr_index);
     if (rc != PTS_SUCCESS) {
-        ERROR("reset PCR[%d] was failed, check the model");
+        LOG(LOG_ERR, "reset PCR[%d] was failed, check the model");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -126,7 +126,7 @@ int addBIOSAction(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
 
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -175,13 +175,13 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
 
     /* event */
     if (eventWrapper == NULL) {
-        ERROR("addBIOSSpecificProperty- eventWrapper is NULL\n");
+        LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1
     }
     event = eventWrapper->event;
 
     if (event->eventType != 0x06) {
-        ERROR("addBIOSSpecificProperty - bad event type 0x%x !- 0x06\n", event->eventType);
+        LOG(LOG_ERR, "addBIOSSpecificProperty - bad event type 0x%x !- 0x06\n", event->eventType);
         return PTS_INTERNAL_ERROR;  // -1
     }
 
@@ -190,11 +190,11 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
 
     /* check EventData */
     if (event->ulEventLength == 0) {
-        ERROR("addBIOSSpecificProperty - Bad IML, ulEventLength is 0.");
+        LOG(LOG_ERR, "addBIOSSpecificProperty - Bad IML, ulEventLength is 0.");
         return PTS_FATAL;
     }
     if (&event->rgbEvent[0] == NULL) {
-        ERROR("addBIOSSpecificProperty - Bad IML, rgbEvent is NULL.");
+        LOG(LOG_ERR, "addBIOSSpecificProperty - Bad IML, rgbEvent is NULL.");
         return PTS_FATAL;
     }
 
@@ -220,11 +220,11 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
                         ctx->conf->smbios_length,
                         &buf_len);
                 if (buf == NULL) {
-                    ERROR("encodeBase64 fail");
+                    LOG(LOG_ERR, "encodeBase64 fail");
                     return PTS_FATAL;
                 }
                 if (buf_len > BUF_SIZE) {
-                    ERROR("SMBIOS size = %d\n", buf_len);  // Thinkpad X200 => 3324
+                    LOG(LOG_ERR, "SMBIOS size = %d\n", buf_len);  // Thinkpad X200 => 3324
                     setProperty(ctx, "bios.smbios", "too big");
                 } else {
                     setProperty(ctx, "bios.smbios", buf);
@@ -254,14 +254,14 @@ int validateMBR(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
     TSS_PCR_EVENT *event;
 
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
     event = eventWrapper->event;
 
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
@@ -290,13 +290,13 @@ int validateEltoritoBootImage(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *e
     // DEBUG("validateEltoritoBootImage - NA\n");
 
     if (eventWrapper == NULL) {
-        ERROR("eventWrapper is NULL\n");
+        LOG(LOG_ERR, "eventWrapper is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
@@ -324,14 +324,14 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("eventWrapper is NULL\n");
+        LOG(LOG_ERR, "eventWrapper is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
     event = eventWrapper->event;
 
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
@@ -341,7 +341,7 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap
         SHA1_DIGEST_SIZE,
         &buf_len);
     if (buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     setProperty(ctx, "kernel.initrd.digest", buf);
@@ -393,23 +393,23 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP
 
     /* input check */
     if (eventWrapper == NULL) {
-        ERROR("eventWrapper is NULL\n");
+        LOG(LOG_ERR, "eventWrapper is NULL\n");
         return PTS_FATAL;
     }
 
     event = eventWrapper->event;
 
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_FATAL;
     }
 
     if (event->rgbEvent == NULL) {
-        ERROR("event->rgbEvent is NULL, BAD IML?\n");
+        LOG(LOG_ERR, "event->rgbEvent is NULL, BAD IML?\n");
         return PTS_FATAL;
     }
     if (event->ulEventLength == 0) {
-        ERROR("event->ulEventLength is 0, BAD IML?\n");
+        LOG(LOG_ERR, "event->ulEventLength is 0, BAD IML?\n");
         return PTS_FATAL;
     }
 
@@ -455,7 +455,7 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP
  * deprecated
  */
 int validateKernelCmdline(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
-    TODO("validateKernelCmdline - NA\n");
+    LOG(LOG_TODO, "validateKernelCmdline - NA\n");
     setProperty(ctx, "kernel.commandline", "TBD");
     return PTS_SUCCESS;
 }
@@ -482,14 +482,14 @@ int validateImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventW
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
     event = eventWrapper->event;
 
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
@@ -517,7 +517,7 @@ int validateImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventW
         if (isDebugFlagSet(DEBUG_FLAG)) {
             int j;
             BYTE pcr[SHA1_DIGEST_SIZE];
-            TODO("validateImaAggregate - "
+            LOG(LOG_TODO, "validateImaAggregate - "
                  "Wrong IMA aggregete - check FSM, "
                  "maybe it should use validateOldImaAggregate()\n");
             OUTPUT("PCR   =  ");
@@ -571,13 +571,13 @@ int validateOldImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("eventWrapper is NULL\n");
+        LOG(LOG_ERR, "eventWrapper is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("event is NULL\n");
+        LOG(LOG_ERR, "event is NULL\n");
         return PTS_INTERNAL_ERROR;  // -1;
     }
 
@@ -694,7 +694,7 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
                 SHA1_DIGEST_SIZE,
                 &buf_len);
             if (buf == NULL) {
-                ERROR("encodeBase64 fail");
+                LOG(LOG_ERR, "encodeBase64 fail");
                 return PTS_INTERNAL_ERROR;
             }
             updateImaProperty(ctx, md->name, buf, "valid");
@@ -718,7 +718,7 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
                 SHA1_DIGEST_SIZE,
                 &buf_len);
             if (buf == NULL) {
-                ERROR("encodeBase64 fail");
+                LOG(LOG_ERR, "encodeBase64 fail");
                 return PTS_INTERNAL_ERROR;
             }
             updateImaProperty(ctx, name, buf, "unknown");  // action.c
@@ -736,7 +736,7 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
             return PTS_SUCCESS;
         } else {
             // ERROR
-            ERROR("validateImaMeasurement - checkEventByAide fail, rc - %d\n", rc);
+            LOG(LOG_ERR, "validateImaMeasurement - checkEventByAide fail, rc - %d\n", rc);
             eventWrapper->status = PTS_INTERNAL_ERROR;  // OPENPTS_RESULT_INT_ERROR;
             xfree(name);
             return PTS_INTERNAL_ERROR;  // -1;
@@ -745,25 +745,25 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
         // freeAideMetadata(md);
         // xfree(name);
     } else if (ctx->conf->ima_validation_mode == OPENPTS_VALIDATION_MODE_IIDB) {
-        ERROR("validateImaMeasurementNG w/ IIDB - NA\n");
+        LOG(LOG_ERR, "validateImaMeasurementNG w/ IIDB - NA\n");
     }
 #else  // !CONFIG_AIDE
     if (ctx->conf->ima_validation_mode == OPENPTS_VALIDATION_MODE_IIDB) {
-        ERROR("validateImaMeasurementNG w/ IIDB - NA\n");
+        LOG(LOG_ERR, "validateImaMeasurementNG w/ IIDB - NA\n");
     }
 #endif
     else {
         return PTS_SUCCESS;
     }
 
-    ERROR("validateImaMeasurement - ERROR\n");
+    LOG(LOG_ERR, "validateImaMeasurement - ERROR\n");
     return PTS_INTERNAL_ERROR;  // -1;
 }
 
 /* IMA NG */
 
 int validateImaAggregateNG(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
-    ERROR("validateImaAggregateNG - NA\n");
+    LOG(LOG_ERR, "validateImaAggregateNG - NA\n");
     setProperty(ctx, "ima.aggregate", "TBD");
     return PTS_INTERNAL_ERROR;  // -1;
 }
@@ -810,7 +810,7 @@ int startCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper
 
     /* check ctx */
     if (ctx == NULL) {
-        ERROR("startCollector() - ctx is null");
+        LOG(LOG_ERR, "startCollector() - ctx is null");
         return PTS_FATAL;
     }
     if (ctx->target_conf == NULL) {
@@ -820,22 +820,22 @@ int startCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper
     }
     if (ctx->target_conf->uuid == NULL) {
         /* collector */
-        ERROR("startCollector() - uuid is NULL\n");
+        LOG(LOG_ERR, "startCollector() - uuid is NULL\n");
         return PTS_FATAL;
     }
 
     /* check eventWrapper */
     if (eventWrapper == NULL) {
-        ERROR("startCollector() - eventWrapper is NULL\n");
+        LOG(LOG_ERR, "startCollector() - eventWrapper is NULL\n");
         return PTS_FATAL;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("startCollector() - event is NULL\n");
+        LOG(LOG_ERR, "startCollector() - event is NULL\n");
         return PTS_FATAL;
     }
     if (event->ulEventLength != sizeof(OPENPTS_EVENT_COLLECTOR_START)) {
-        ERROR("startCollector() - Bad eventData size %d != %d\n",
+        LOG(LOG_ERR, "startCollector() - Bad eventData size %d != %d\n",
             event->ulEventLength,
             sizeof(OPENPTS_EVENT_COLLECTOR_START));
         return PTS_FATAL;
@@ -850,20 +850,20 @@ int startCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper
 
     /* validation - TSS version */
     if (memcmp(&start->pts_version, &ctx->target_conf->pts_version, 4) != 0) {
-        ERROR("startCollector() - Bad PTS version\n");
+        LOG(LOG_ERR, "startCollector() - Bad PTS version\n");
         rc = PTS_INVALID_COLLECTOR;
     }
 
     /* validation - Collector UUID */
     if (memcmp(&start->collector_uuid, ctx->target_conf->uuid->uuid, 16) != 0) {
-        ERROR("startCollector() - Bad Collector UUID (Unit Testing?)\n");
+        LOG(LOG_ERR, "startCollector() - Bad Collector UUID (Unit Testing?)\n");
         rc = PTS_INVALID_COLLECTOR;
     }
 
     /* validation - Manifest UUID */
     if (memcmp(&start->manifest_uuid, ctx->target_conf->rm_uuid->uuid, 16) != 0) {
         // TODO in the test ptsc generate new RM UUID
-        ERROR("startCollector() - Bad Manifest UUID (Unit Testing?)\n");
+        LOG(LOG_ERR, "startCollector() - Bad Manifest UUID (Unit Testing?)\n");
         rc = PTS_INVALID_COLLECTOR;
     }
 
@@ -879,7 +879,7 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
 
     /* event */
     if (eventWrapper == NULL) {
-        ERROR("addBIOSSpecificProperty- eventWrapper is NULL\n");
+        LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n");
         return -1;
     }
     event = eventWrapper->event;
@@ -951,7 +951,7 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
 
                 if (event->ulEventLength < 48) {
                     // Bad EventData
-                    TODO("addIntelTxtTbootProperty() bad eventdata, size = %d\n",
+                    LOG(LOG_TODO, "addIntelTxtTbootProperty() bad eventdata, size = %d\n",
                         event->ulEventLength);
                 } else {
                     // EventData
@@ -999,7 +999,7 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
             break;
 
         default:
-            ERROR("Unknown event tupe 0x%x\n", event->eventType);
+            LOG(LOG_ERR, "Unknown event tupe 0x%x\n", event->eventType);
             break;
     }
 
@@ -1215,11 +1215,11 @@ int doActivity(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("doActivity - ctx is NULL");
+        LOG(LOG_ERR, "doActivity - ctx is NULL");
         return PTS_FATAL;
     }
     if (action == NULL) {
-        ERROR("doActivity - action is NULL");
+        LOG(LOG_ERR, "doActivity - action is NULL");
         return PTS_FATAL;
     }
     if (eventWrapper == NULL) {
@@ -1295,14 +1295,14 @@ int doActivity(
                 rc = action_table[i].func_7(ctx, value, eventWrapper);
                 goto end;
             default:
-                ERROR("unknown OPENPTS_ACTION_TABLE func tyoe\n");
+                LOG(LOG_ERR, "unknown OPENPTS_ACTION_TABLE func tyoe\n");
                 break;
             }
         }
     }
 
     /* error */
-    ERROR("unknown action '%s'\n", action);
+    LOG(LOG_ERR, "unknown action '%s'\n", action);
     addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_ACTION_UNKNOWN, "[FSM] Unknown action='%s'"), action);
     rc = OPENPTS_FSM_ERROR;
 
index 323c2b2..5c8690d 100644 (file)
@@ -82,7 +82,7 @@ AIDE_METADATA * newAideMetadata() {
     AIDE_METADATA *metadata;
     metadata = (AIDE_METADATA *) xmalloc(sizeof(AIDE_METADATA));
     if (metadata == NULL) {
-        // ERROR("no memory\n");
+        // LOG(LOG_ERR, "no memory\n");
         return NULL;
     }
     memset(metadata, 0, sizeof(AIDE_METADATA));
@@ -173,7 +173,7 @@ AIDE_CONTEXT * newAideContext() {
     memset(ctx->aide_md_table, 0, sizeof(struct hsearch_data));
     rc = hcreate_r(AIDE_HASH_TABLE_SIZE, ctx->aide_md_table);  // hash table for metadata
     if (rc == 0) {
-        ERROR("hcreate faild, errno=%x\n", errno);
+        LOG(LOG_ERR, "hcreate faild, errno=%x\n", errno);
         goto error;
     }
     ctx->aide_md_table_size = 0;
@@ -184,7 +184,7 @@ AIDE_CONTEXT * newAideContext() {
     //  4096 full
     rc = hcreate_r(AIDE_HASH_TABLE_SIZE, ctx->aide_in_table);  // hash table for ignore name
     if (rc == 0) {
-        ERROR("hcreate faild\n");
+        LOG(LOG_ERR, "hcreate faild\n");
         goto error;
     }
     ctx->aide_in_table_size = 0;
@@ -226,7 +226,7 @@ void freeAideIgnoreList(AIDE_LIST *list) {
 void freeAideContext(AIDE_CONTEXT *ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("ctx is NULL\n");
+        LOG(LOG_ERR, "ctx is NULL\n");
         return;
     }
     DEBUG("freeAideContext %p \n", ctx);
@@ -315,7 +315,7 @@ int getAideItemIndex(char *buf) {
     } else if (!strncmp(buf, "xattrs", 6)) {
         return AIDE_ITEM_XATTRS;
     } else {
-        ERROR("Unknown AIDE item [%s]\n", buf);
+        LOG(LOG_ERR, "Unknown AIDE item [%s]\n", buf);
         return -1;
     }
 }
@@ -352,7 +352,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
 
     fp = gzopen(filename, "r");
     if (fp == NULL) {
-        ERROR("%s missing\n", filename);
+        LOG(LOG_ERR, "%s missing\n", filename);
         return -1;
     }
 
@@ -372,14 +372,14 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
             while (ptr < end) {
                 /* skip space */
                 while ((ptr < end) && (*ptr == 0x20)) {
-                    printf("skip %d ", *ptr);
+                    // skip
                     ptr++;
                 }
 
                 /* find sep */
                 sep = strstr(ptr, " ");
                 if (sep == NULL) {
-                    ERROR("bad data, %s\n", buf);
+                    LOG(LOG_ERR, "bad data, %s\n", buf);
                     return -1;
                 } else {
                     // terminate at " "
@@ -389,7 +389,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
                 items[item_num] = getAideItemIndex(ptr);
 
                 if (items[item_num] < 0) {
-                    ERROR("Bad spec\n");
+                    LOG(LOG_ERR, "Bad spec\n");
                     return -1;
                 }
                 item_num++;
@@ -400,7 +400,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
             body = 2;
 
             if (item_num > AIDE_MAX_ITEM_NUM) {
-                ERROR("loadAideDatabaseFile - %d items > %d \n", item_num, AIDE_MAX_ITEM_NUM);
+                LOG(LOG_ERR, "loadAideDatabaseFile - %d items > %d \n", item_num, AIDE_MAX_ITEM_NUM);
                 return -1;
             }
             DEBUG("loadAideDatabaseFile - has %d items\n", item_num);
@@ -421,10 +421,9 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
             for (i = 0; i < item_num; i++) {
                 /* space -> \0 */
                 if (i != item_num - 1) {
-                    // printf("SEP %d %d\n",i, item_num);
                     sep = strstr(ptr, " ");
                     if (sep == NULL) {
-                        ERROR("bad data, %s\n", buf);
+                        LOG(LOG_ERR, "bad data, %s\n", buf);
                         freeAideMetadata(md);
                         return -1;
                     } else {
@@ -463,14 +462,12 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
                                 SHA1_BASE64_DIGEST_SIZE,
                                 &len);
                             if (md->sha1 == NULL) {
-                                ERROR("decodeBase64 fail");
+                                LOG(LOG_ERR, "decodeBase64 fail");
                                 goto close;
                             }
                             if (len != SHA1_DIGEST_SIZE) {
-                                ERROR("bad SHA1 size %d  %s\n", len, ptr);
-                                // printf("base64 [%s] => [", ptr);
+                                LOG(LOG_ERR, "bad SHA1 size %d  %s\n", len, ptr);
                                 printHex("digest", md->sha1, len, "\n");
-                                // printf("]\n");
                             }
                         }
                         break;
@@ -481,16 +478,16 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
                                 SHA256_BASE64_DIGEST_SIZE,
                                 &len);
                             if (md->sha256 == NULL) {
-                                ERROR("decodeBase64 fail");
+                                LOG(LOG_ERR, "decodeBase64 fail");
                                 goto close;
                             }
                             if (len != SHA256_DIGEST_SIZE) {
-                                ERROR("bad SHA256 size %d\n", len);
-                                printf("base64 [%s] => [", ptr);
+                                LOG(LOG_ERR, "bad SHA256 size %d\n", len);
+                                OUTPUT("base64 [%s] => [", ptr);
                                 printHex("", (BYTE *)ptr, 2, " ");
-                                printf("][\n");
+                                OUTPUT("][\n");
                                 printHex("", md->sha256, len, " ");
-                                printf("]\n");
+                                OUTPUT("]\n");
                             }
                         }
                         break;
@@ -501,16 +498,16 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
                                 SHA512_BASE64_DIGEST_SIZE,
                                 &len);
                             if (md->sha512 == NULL) {
-                                ERROR("decodeBase64 fail");
+                                LOG(LOG_ERR, "decodeBase64 fail");
                                 goto close;
                             }
                             if (len != SHA512_DIGEST_SIZE) {
-                                ERROR("bad SHA512 size %d\n", len);
-                                printf("base64 [%s] => [", ptr);
+                                LOG(LOG_ERR, "bad SHA512 size %d\n", len);
+                                OUTPUT("base64 [%s] => [", ptr);
                                 printHex("", (BYTE *)ptr, 2, "");
-                                printf("][\n");
+                                OUTPUT("][\n");
                                 printHex("", md->sha512, len, "");
-                                printf("]\n");
+                                OUTPUT("]\n");
                             }
                         }
                         break;
@@ -543,17 +540,15 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
 
                 if (rc == 0) {
                     if (errno == ENOMEM) {
-                        ERROR("  hsearch_r failed, table is full, errno=%x\n", errno);
+                        LOG(LOG_ERR, "  hsearch_r failed, table is full, errno=%x\n", errno);
                     } else {
-                        ERROR("  hsearch_r failed, errno=%x\n", errno);
+                        LOG(LOG_ERR, "  hsearch_r failed, errno=%x\n", errno);
                     }
                 }
                 // CAUTION too many messages, use for debugging the unit test
                 // DEBUG("Hash Table <-  %4d [%s] %s\n", ctx->aide_md_table_size, md->hash_key, md->name);
                 ctx->aide_md_table_size++;
             }
-
-
 #if 0
             if (ctx->start == NULL) {
                 ctx->start = md;
@@ -566,7 +561,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
             ctx->metadata_num++;
 #endif
         } else {
-            // ignore printf("??? [%s]\n", buf);
+            // ignore
         }  // if
     }  // while
  close:
@@ -623,7 +618,7 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) {
             /* new  */
             list = xmalloc(sizeof(AIDE_LIST));
             if (list == NULL) {
-                ERROR("no mem\n");
+                LOG(LOG_ERR, "no mem\n");
                 rc = PTS_OS_ERROR;
                 goto error;  // return -1;
             }
@@ -649,9 +644,9 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) {
             rc = hsearch_r(e, ENTER, &ep, ctx->aide_in_table);
             if (rc == 0) {
                 if (errno == ENOMEM) {
-                    ERROR("  hsearch_r failed, ignore name table is full, errno=%x\n", errno);
+                    LOG(LOG_ERR, "  hsearch_r failed, ignore name table is full, errno=%x\n", errno);
                 } else {
-                    ERROR("  hsearch_r failed, errno=%x\n", errno);
+                    LOG(LOG_ERR, "  hsearch_r failed, errno=%x\n", errno);
                 }
             }
             ctx->aide_in_table_size++;
@@ -682,21 +677,21 @@ int printAideData(AIDE_CONTEXT *ctx) {
     md = ctx->start;
 
     for (i = 0; i < ctx->metadata_num; i++) {
-        printf("%4d ", i);
-        if ( md->name  != NULL) printf("%30s ", md->name);
-        if ( md->lname != NULL) printf("%20s ", md->lname);
-        if ( md->attr  != 0)    printf("%08X ", md->attr);
+        OUTPUT("%4d ", i);
+        if ( md->name  != NULL) OUTPUT("%30s ", md->name);
+        if ( md->lname != NULL) OUTPUT("%20s ", md->lname);
+        if ( md->attr  != 0)    OUTPUT("%08X ", md->attr);
         if (md->sha1   != NULL)
             printHex("", md->sha1, 20, " ");
         else
-            printf("                                        -");
+            OUTPUT("                                        -");
 
         if (md->sha256 != NULL)
             printHex("", md->sha256, 32, " ");
         else
-            printf("                                                                -");
+            OUTPUT("                                                                -");
 
-        printf(" <<\n");
+        OUTPUT(" <<\n");
         md = md->next;
     }
 
@@ -779,7 +774,7 @@ int checkIgnoreList(AIDE_CONTEXT *ctx, char *name) {
 
     /* check */
     if (name == NULL) {
-        ERROR("checkIgnoreList() - name is null\n");
+        LOG(LOG_ERR, "checkIgnoreList() - name is null\n");
         return -2;
     }
 
@@ -794,7 +789,7 @@ int checkIgnoreList(AIDE_CONTEXT *ctx, char *name) {
                 return 0;
             }
         } else {
-            ERROR("checkIgnoreList() - list->name is null\n");
+            LOG(LOG_ERR, "checkIgnoreList() - list->name is null\n");
             return -2;
         }
 
@@ -840,12 +835,12 @@ int checkEventByAide(AIDE_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
     // DEBUG("checkEventByAide - start\n");
 
     if (ctx == NULL) {
-        ERROR("checkEventByAide - AIDE_CONTEXT is NULL\n");
+        LOG(LOG_ERR, "checkEventByAide - AIDE_CONTEXT is NULL\n");
         return -1;
     }
 
     if (eventWrapper == NULL) {
-        ERROR("OcheckEventByAide - PENPTS_PCR_EVENT_WRAPPER is NULL\n");
+        LOG(LOG_ERR, "OcheckEventByAide - PENPTS_PCR_EVENT_WRAPPER is NULL\n");
         return -1;
     }
 
@@ -853,7 +848,7 @@ int checkEventByAide(AIDE_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
 
     // 20100627 ignore pseudo event
     if (event->eventType == OPENPTS_PSEUDO_EVENT_TYPE) {
-        ERROR("validateImaMeasurement - event->eventType == OPENPTS_PSEUDO_EVENT_TYPE\n");
+        LOG(LOG_ERR, "validateImaMeasurement - event->eventType == OPENPTS_PSEUDO_EVENT_TYPE\n");
         return 1;
     }
 
@@ -875,7 +870,7 @@ int checkEventByAide(AIDE_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
             20
             &buf_len);
     if (buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return -1;
     }
     rc = verifyBySQLite(ctx, (char*)buf);
@@ -923,7 +918,7 @@ int checkEventByAide(AIDE_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
             20,
             &buf_len);
     if (buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return -1;
     }
     e.key = (char *) buf;  // size?
@@ -1140,7 +1135,7 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
     /* file open for write */
     fp = gzopen(filename, "wb");
     if (fp == NULL) {
-        ERROR("%s fail to open\n", filename);
+        LOG(LOG_ERR, "%s fail to open\n", filename);
         return -1;
     }
 
@@ -1152,12 +1147,12 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
     /* IMLs */
     ss = getSnapshotFromTable(ctx->ss_table, 10, 1);  // TODO def or conf
     if (ss == NULL) {
-        ERROR("events is missing\n");
+        LOG(LOG_ERR, "events is missing\n");
         goto close;
     }
     eventWrapper = ss->start;
     if (eventWrapper == NULL) {
-        ERROR("events is missing\n");
+        LOG(LOG_ERR, "events is missing\n");
         goto close;
     }
 
@@ -1171,12 +1166,12 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
         // DEBUG("SM DEBUG event %p\n",event);
 
         if (event == NULL) {
-            ERROR("event is NULL\n");
+            LOG(LOG_ERR, "event is NULL\n");
             goto close;
         }
 
         if (event->rgbEvent == NULL) {
-            ERROR("event->rgbEvent is NULL\n");
+            LOG(LOG_ERR, "event->rgbEvent is NULL\n");
             goto close;
         }
 
@@ -1197,7 +1192,7 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
         /* filename (allocated) */
         len = escapeFilename(&aide_filename, (char *) &eventWrapper->event->rgbEvent[20]);
         if (len < 0) {
-            ERROR("convertImlToAideDbFile - no mem?\n");
+            LOG(LOG_ERR, "convertImlToAideDbFile - no mem?\n");
             gzprintf(fp, "bad_filename ");
         } else {
             gzprintf(fp, "%s ", aide_filename);
@@ -1211,14 +1206,12 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
             SHA1_DIGEST_SIZE,
             &buf_len);
         if (buf == NULL) {
-            ERROR("encodeBase64 fail");
+            LOG(LOG_ERR, "encodeBase64 fail");
             goto close;
         }
         gzprintf(fp, "%s \n", buf);
         xfree(buf);
 
-        // printf("%d %s\n", i, buf);
-
         eventWrapper = eventWrapper->next_pcr;
         if (eventWrapper == NULL) break;
         event = eventWrapper->event;
@@ -1271,7 +1264,7 @@ int writeReducedAidbDatabase(AIDE_CONTEXT *ctx, char *filename) {
     /* file open for write */
     fp = gzopen(filename, "wb");
     if (fp == NULL) {
-        ERROR("%s fail to open\n", filename);
+        LOG(LOG_ERR, "%s fail to open\n", filename);
         return -1;
     }
 
@@ -1289,13 +1282,12 @@ int writeReducedAidbDatabase(AIDE_CONTEXT *ctx, char *filename) {
         }
 
         if (md->status == OPENPTS_AIDE_MD_STATUS_HIT) {
-            // printf("+");
             buf = encodeBase64(
                 (unsigned char *)md->sha1,
                 SHA1_DIGEST_SIZE,
                 &buf_len);
             if (buf == NULL) {
-                ERROR("encodeBase64 fail");
+                LOG(LOG_ERR, "encodeBase64 fail");
                 return -1;
             }
             gzprintf(fp, "%s ", md->name);
@@ -1340,11 +1332,11 @@ int convertAideDbfileToSQLiteDbFile(char * aide_filename, char * sqlite_filename
 
     /* check */
     if (aide_filename == NULL) {
-        ERROR("AIDE file is null\n");
+        LOG(LOG_ERR, "AIDE file is null\n");
         return PTS_INTERNAL_ERROR;
     }
     if (sqlite_filename == NULL) {
-        ERROR("sqlite file is null\n");
+        LOG(LOG_ERR, "sqlite file is null\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1355,7 +1347,7 @@ int convertAideDbfileToSQLiteDbFile(char * aide_filename, char * sqlite_filename
     /* read AIDE DB file -> ctx */
     rc = loadAideDatabaseFile(ctx, aide_filename);
     if (rc < 0) {
-        ERROR("read AIDE DB %s fail, rc = %d", aide_filename, rc);
+        LOG(LOG_ERR, "read AIDE DB %s fail, rc = %d", aide_filename, rc);
         return -1;
     }
 
@@ -1368,7 +1360,7 @@ int convertAideDbfileToSQLiteDbFile(char * aide_filename, char * sqlite_filename
     /* open */
     sqlite3_open(sqlite_filename, &db);
     if (db == NULL) {
-        ERROR("open AIDE DB fail\n");
+        LOG(LOG_ERR, "open AIDE DB fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1424,18 +1416,18 @@ int convertAideDbfileToSQLiteDbFile(char * aide_filename, char * sqlite_filename
 int loadSQLiteDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
     /* check */
     if (ctx == NULL) {
-        ERROR("ctx == NULL\n");
+        LOG(LOG_ERR, "ctx == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
     if (filename == NULL) {
-        ERROR("filename == NULL\n");
+        LOG(LOG_ERR, "filename == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
     /* open */
     sqlite3_open(filename, &ctx->sqlite_db);
     if (ctx->sqlite_db == NULL) {
-        ERROR("open AIDE SQLite DB %s fail\n", filename);
+        LOG(LOG_ERR, "open AIDE SQLite DB %s fail\n", filename);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1453,11 +1445,11 @@ int verifyBySQLite(AIDE_CONTEXT *ctx, char * key) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("ctx == NULL\n");
+        LOG(LOG_ERR, "ctx == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
     if (ctx->sqlite_db == NULL) {
-        ERROR("ctx->sqlite_db == NULL\n");
+        LOG(LOG_ERR, "ctx->sqlite_db == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1469,7 +1461,7 @@ int verifyBySQLite(AIDE_CONTEXT *ctx, char * key) {
         return OPENPTS_RESULT_VALID;
     }
 
-    // ERROR("row = %d\n",row);
+    // LOG(LOG_ERR, "row = %d\n",row);
 
     /* free */
     sqlite3_free(sql);
index ac42aa8..3adae64 100644 (file)
--- a/src/aru.c
+++ b/src/aru.c
@@ -75,7 +75,7 @@ OPENPTS_UPDATE_CONTEXT *newUpdateCtx() {
 
     ctx = xmalloc(sizeof(OPENPTS_UPDATE_CONTEXT));
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(ctx, 0, sizeof(OPENPTS_UPDATE_CONTEXT));
@@ -97,7 +97,7 @@ OPENPTS_UPDATE_SNAPSHOT *newUpdateSnapshot() {
 
     uss = xmalloc(sizeof(OPENPTS_UPDATE_SNAPSHOT));
     if (uss == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(uss, 0, sizeof(OPENPTS_UPDATE_SNAPSHOT));
@@ -131,7 +131,7 @@ void freeUpdateCtx(OPENPTS_UPDATE_CONTEXT* ctx) {
 int resetFsm(OPENPTS_SNAPSHOT *ss) {
     /* check */
     if (ss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -194,12 +194,12 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     /* check conf */
@@ -212,25 +212,25 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if (event->ulEventLength <= 20) {  // TODO sizeof
-        ERROR("startUpdate() - bad eventdata\n");
+        LOG(LOG_ERR, "startUpdate() - bad eventdata\n");
         return PTS_FATAL;
     }
     if (event->rgbEvent == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (conf->update == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -262,12 +262,12 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
         ctx->conf->iml_endian);
 
     if (target_pcr_index >= MAX_PCRNUM) {
-        ERROR("startUpdate() - Bad PCR index %d 0x%08x\n",
+        LOG(LOG_ERR, "startUpdate() - Bad PCR index %d 0x%08x\n",
             target_pcr_index, target_pcr_index);
         return PTS_INTERNAL_ERROR;
     }
     if (target_snapshot_level >= MAX_SSLEVEL) {
-        ERROR("startUpdate() - Bad SS Level %d 0x%08x\n",
+        LOG(LOG_ERR, "startUpdate() - Bad SS Level %d 0x%08x\n",
             target_snapshot_level, target_snapshot_level);
         return PTS_INTERNAL_ERROR;
     }
@@ -329,12 +329,12 @@ int deputyEvent(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -346,17 +346,17 @@ int deputyEvent(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     update = conf->update;
     if (update == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -365,7 +365,7 @@ int deputyEvent(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
             [update->target_pcr_index]
             [update->target_snapshot_level];
     if (uss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -398,12 +398,12 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -421,17 +421,17 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     update = conf->update;
     if (update == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -439,14 +439,14 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
             [update->target_pcr_index]
             [update->target_snapshot_level];
     if (uss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* start structure */
     start = uss->start;
     if (start == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -462,7 +462,7 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
     /* check the event num */
     if (uss->event_count != event_num) {
         /* actual event number is different with the number in start event */
-        ERROR("number of events (%08x) are not same with definition at start (%08x), BAD eventlog?\n",
+        LOG(LOG_ERR, "number of events (%08x) are not same with definition at start (%08x), BAD eventlog?\n",
             uss->event_count, event_num);
         return PTS_INVALID_SNAPSHOT;
     }
@@ -483,28 +483,28 @@ int updateCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrappe
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if (event->ulEventLength != sizeof(OPENPTS_EVENT_COLLECTOR_UPDATE)) {
-        ERROR("updateCollector() - Bad eventData size %d != %d\n",
+        LOG(LOG_ERR, "updateCollector() - Bad eventData size %d != %d\n",
             event->ulEventLength,
             sizeof(OPENPTS_EVENT_COLLECTOR_UPDATE));
         return PTS_INVALID_SNAPSHOT;
@@ -517,7 +517,7 @@ int updateCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrappe
     if (conf->target_newrm_uuid == NULL) {
         conf->target_newrm_uuid = xmalloc(sizeof(PTS_UUID));
         if (NULL == conf->target_newrm_uuid) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             return PTS_FATAL;
         }
     }
@@ -591,11 +591,11 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (uss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -620,7 +620,7 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
     /* update target snaposhot */
     ss =  getSnapshotFromTable(ctx->ss_table, i, j);
     if (NULL == ss) {
-        ERROR("null snapshot\n");
+        LOG(LOG_ERR, "null snapshot\n");
         return PTS_FATAL;
     }
 
@@ -655,7 +655,7 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
         /* WORK NEEDED: I guess that bosrenew should really pass in all IPL events including the final one */
         num++;
 #endif
-        INFO("UPDATE_IPL_IMAGE  iml.ipl.maxcount=%d (0x%x)\n", num, num);
+        LOG(LOG_INFO, "UPDATE_IPL_IMAGE  iml.ipl.maxcount=%d (0x%x)\n", num, num);
         snprintf(buf, BUF_SIZE, "%d", num);
         setProperty(ctx, "iml.ipl.maxcount", buf);
     }
@@ -708,7 +708,7 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
             // goto end;
             break;
         } else {
-            ERROR("updateFsm rc=%d\n", rc);
+            LOG(LOG_ERR, "updateFsm rc=%d\n", rc);
         }
 
         /* update SS chain */
@@ -761,15 +761,15 @@ int extendEvCollectorUpdate(OPENPTS_CONFIG *conf) {
 
     /*check */
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (conf->newrm_uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (conf->newrm_uuid->uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -831,24 +831,24 @@ int updateSnapshots(OPENPTS_CONTEXT *ctx) {
 
     /* check input */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
 
     if (conf->update_exist == 0) {
-        TODO("updateSnapshots() - done, no update\n");
+        LOG(LOG_TODO, "updateSnapshots() - done, no update\n");
         return PTS_SUCCESS;
     }
 
     update = (OPENPTS_UPDATE_CONTEXT *)conf->update;
     if (update == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -901,14 +901,14 @@ int update(
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
     /* ctx for init */
     ctx = newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
@@ -916,11 +916,11 @@ int update(
     if (prop_count > 0) {
         /* check */
         if (prop_start == NULL) {
-            ERROR("null input\n");
+            LOG(LOG_ERR, "null input\n");
             return PTS_FATAL;
         }
         if (prop_end == NULL) {
-            ERROR("null input\n");
+            LOG(LOG_ERR, "null input\n");
             return PTS_FATAL;
         }
         ctx->prop_start = prop_start;
@@ -955,7 +955,7 @@ int update(
     /* read FSM */
     rc = readFsmFromPropFile(ctx, conf->config_file);
     if (rc != PTS_SUCCESS) {
-        ERROR("update() - read FSM failed\n");
+        LOG(LOG_ERR, "update() - read FSM failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -976,7 +976,7 @@ int update(
     /* load current IML using FSMs */
     if (conf->iml_mode == 0) {  // TODO use def
 #ifdef CONFIG_NO_TSS
-        ERROR("update() - Build with --without-tss. iml.mode=tss is not supported\n");
+        LOG(LOG_ERR, "update() - Build with --without-tss. iml.mode=tss is not supported\n");
 #else
         rc = getIml(ctx, 0);
         rc = getPcr(ctx);
@@ -1012,13 +1012,13 @@ int update(
                     conf->runtime_iml_filename,
                     conf->runtime_iml_type, 0, &count);  // TODO endian?
             if (rc < 0) {
-                ERROR("read IMA IML, %s has failed\n", conf->runtime_iml_filename);
+                LOG(LOG_ERR, "read IMA IML, %s has failed\n", conf->runtime_iml_filename);
                 rc = PTS_INTERNAL_ERROR;
                 goto free;
             }
         }
     } else {
-        ERROR("unknown IML mode, %d\n", conf->iml_mode);
+        LOG(LOG_ERR, "unknown IML mode, %d\n", conf->iml_mode);
     }
 
     /* get SMBIOS data */
@@ -1031,13 +1031,13 @@ int update(
         /* Update the Manifests */
         rc = updateSnapshots(ctx);
         if (rc != PTS_SUCCESS) {
-            ERROR("update() - updateSnapshots fail\n");
+            LOG(LOG_ERR, "update() - updateSnapshots fail\n");
             goto free;
         }
 
         /* new UUID for this RM set */
         if (conf->newrm_uuid == NULL) {
-            INFO("conf->newrm_uuid == NULL, generate new reference manifest UUID\n");
+            LOG(LOG_INFO, "conf->newrm_uuid == NULL, generate new reference manifest UUID\n");
             conf->newrm_uuid = newOpenptsUuid();  // empty
             conf->newrm_uuid->filename =  getFullpathName(conf->config_dir, "newrm_uuid");
             DEBUG("conf->newrm_uuid->filename %s\n", conf->newrm_uuid->filename);
@@ -1059,8 +1059,8 @@ int update(
             rc = genOpenptsUuid(conf->newrm_uuid);
             // TODO
         } else {
-            ERROR("update() - conf->newrm_uuid->status %d\n", conf->newrm_uuid->status);
-            ERROR("update() - use given reference manifest UUID %s (for test)\n", conf->rm_uuid->str);
+            LOG(LOG_ERR, "update() - conf->newrm_uuid->status %d\n", conf->newrm_uuid->status);
+            LOG(LOG_ERR, "update() - use given reference manifest UUID %s (for test)\n", conf->rm_uuid->str);
             rc = PTS_FATAL;
             goto free;
         }
@@ -1078,7 +1078,7 @@ int update(
         /* RM set DIR */
         rc = makeNewRmSetDir(conf);
         if (rc != PTS_SUCCESS) {
-            ERROR("mkdir of RM set dir was failed\n");
+            LOG(LOG_ERR, "mkdir of RM set dir was failed\n");
             goto free;
         }
 
@@ -1110,7 +1110,7 @@ int update(
                 DEBUG("update() - writeRm %s\n", conf->newrm_filename[i]);
                 rc = writeRm(ctx, conf->newrm_filename[i], i);
                 if (rc < 0) {
-                    ERROR("write RM, %s was failed\n", conf->newrm_filename[i]);
+                    LOG(LOG_ERR, "write RM, %s was failed\n", conf->newrm_filename[i]);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1120,7 +1120,7 @@ int update(
                 DEBUG("update() - dowriteRm %s\n", conf->newrm_filename[i]);
                 rc = writeRm(ctx, conf->newrm_filename[i], i);
                 if (rc < 0) {
-                    ERROR("write RM, %s was failed\n", conf->newrm_filename[i]);
+                    LOG(LOG_ERR, "write RM, %s was failed\n", conf->newrm_filename[i]);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1130,17 +1130,20 @@ int update(
         /* Extend Collector Update event */
         rc = extendEvCollectorUpdate(conf);
         if (rc != PTS_SUCCESS) {
-            ERROR("updateSnapshots() - extendEvCollectorUpdate fail\n");
+            LOG(LOG_ERR, "updateSnapshots() - extendEvCollectorUpdate fail\n");
             goto free;
         }
-        printf(NLS(MS_OPENPTS, OPENPTS_UPDATE_SUCCESS, "Successfully updated the reference manifests\n\n"));
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_UPDATE_SUCCESS,
+            "Successfully updated the reference manifests\n\n"));
     } else {
-        printf(NLS(MS_OPENPTS, OPENPTS_UPDATE_NONE, "There is no update.\n\n"));
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_UPDATE_NONE,
+            "There is no update.\n\n"));
     }
 
   free:
     if ( rc != PTS_SUCCESS ) {
-        printf(NLS(MS_OPENPTS, OPENPTS_UPDATE_FAILED, "Failed to update the reference manifests\n"));
+        ERROR(NLS(MS_OPENPTS, OPENPTS_UPDATE_FAILED,
+            "Failed to update the reference manifests\n"));
     }
 
     if ( NULL != ctx ) {
@@ -1165,9 +1168,9 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) {
     int fd = open(fileName, O_RDONLY);
 
     if (fd == -1) {
-        ERROR("Failed to open '%s', errno %d\n", fileName, errno);
+        LOG(LOG_ERR, "Failed to open '%s', errno %d\n", fileName, errno);
     } else if (fstat(fd, &statBuf) == -1) {
-        ERROR("Failed to stat '%s' (fd %d), errno %d\n", fileName, fd, errno);
+        LOG(LOG_ERR, "Failed to stat '%s' (fd %d), errno %d\n", fileName, fd, errno);
     } else if ( len != statBuf.st_size ) {
         DEBUG("File length for pending RM '%s' (%d) does not match cached length (%d) from collector.\n",
               fileName, (int)statBuf.st_size, len);
@@ -1177,11 +1180,11 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) {
             char page[4096];
             ssize_t bytesRead = read(fd, page, 4096);
             if ( -1 == bytesRead ) {
-                ERROR("Failed to read from fd %d, errno %d\n", fd, errno);
+                LOG(LOG_ERR, "Failed to read from fd %d, errno %d\n", fd, errno);
                 break;
             } else if ( bytesRead == 0) {
                 if (totalBytesRead != len) {
-                    ERROR("Finished reading from file prematurely, still expecting data.");
+                    LOG(LOG_ERR, "Finished reading from file prematurely, still expecting data.");
                     return PTS_FATAL;
                 }
                 rc = PTS_SUCCESS;
@@ -1189,7 +1192,7 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) {
             } else {
                 totalBytesRead += bytesRead;
                 if (totalBytesRead > len) {
-                    ERROR("Read more data from RM file than expected.");
+                    LOG(LOG_ERR, "Read more data from RM file than expected.");
                     return PTS_FATAL;
                 }
                 DEBUG("Read %ld bytes, total = %d out of %d\n", bytesRead, totalBytesRead, len);
@@ -1234,12 +1237,12 @@ int isNewRmStillValid(OPENPTS_CONTEXT *ctx, char *conf_dir) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -1249,20 +1252,20 @@ int isNewRmStillValid(OPENPTS_CONTEXT *ctx, char *conf_dir) {
 
     newRmSet = conf->newRmSet;
     if (newRmSet == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     target_conf = ctx->target_conf;
     if (target_conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (target_conf->uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (target_conf->rm_uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -1303,7 +1306,7 @@ int isNewRmStillValid(OPENPTS_CONTEXT *ctx, char *conf_dir) {
         rc = checkDir(collector_dir);
         if (rc != PTS_SUCCESS) {
             /* unknwon collector */
-            ERROR("isNewRmStillValid() - Unknown collector, UUID= %s dir=%s\n",
+            LOG(LOG_ERR, "isNewRmStillValid() - Unknown collector, UUID= %s dir=%s\n",
                 str_collector_uuid, collector_dir);
             addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_ARU_MISSING_COLLECTOR_CONFIG,
                 "Missing collector configuration"));
@@ -1328,7 +1331,7 @@ int isNewRmStillValid(OPENPTS_CONTEXT *ctx, char *conf_dir) {
         newRmSet += 4;
 
         if (num > MAX_RM_NUM) {
-            ERROR("Bad NUM %d\n", num);
+            LOG(LOG_ERR, "Bad NUM %d\n", num);
             goto out;
         }
 
@@ -1401,12 +1404,12 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -1415,19 +1418,19 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
 
     newRmSet = conf->newRmSet;
     if (newRmSet == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (ctx->target_conf == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (ctx->target_conf->uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if (ctx->target_conf->rm_uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
@@ -1458,7 +1461,7 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
     // TODO check
     rc = readTargetConf(target_conf, target_conf_filename);
     if (rc != PTS_SUCCESS) {
-        ERROR("updateNewRm() - readTargetConf failed\n");
+        LOG(LOG_ERR, "updateNewRm() - readTargetConf failed\n");
         // TODO so?
     }
 
@@ -1479,7 +1482,7 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
         rc = checkDir(collector_dir);
         if (rc != PTS_SUCCESS) {
             /* unknwon collector */
-            ERROR("updateNewRm() - Unknown collector, UUID= %s dir=%s\n",
+            LOG(LOG_ERR, "updateNewRm() - Unknown collector, UUID= %s dir=%s\n",
                 str_collector_uuid, collector_dir);
             addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_ARU_MISSING_COLLECTOR_CONFIG,
                 "Missing collector configuration"));
@@ -1506,7 +1509,7 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
             rc = makeDir(rm_dir);
             if (rc != PTS_SUCCESS) {
                 /* unknwon collector */
-                ERROR("updateNewRm() - Create New RM dir failed, %s\n", rm_dir);
+                LOG(LOG_ERR, "updateNewRm() - Create New RM dir failed, %s\n", rm_dir);
                 rc = PTS_INTERNAL_ERROR;
                 goto out;
             }
@@ -1528,7 +1531,7 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
         newRmSet += 4;
 
         if (num >  MAX_RM_NUM) {
-            ERROR("Bad NUM %d\n", num);
+            LOG(LOG_ERR, "Bad NUM %d\n", num);
             rc = PTS_INTERNAL_ERROR;
             goto out;
         }
@@ -1552,7 +1555,7 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
 
             rc = saveToFile(rm_filename[i], len, newRmSet);
             if (rc != PTS_SUCCESS) {
-                ERROR("updateNewRm() - save RM[%d], %s failed\n", i, rm_filename[i]);
+                LOG(LOG_ERR, "updateNewRm() - save RM[%d], %s failed\n", i, rm_filename[i]);
                 goto out;
             }
             target_conf->rm_filename[i] = smalloc_assert(rm_filename[i]);
index 3604a86..7d4a60a 100644 (file)
@@ -62,7 +62,7 @@ int getDecodedBase64Size(unsigned char *in, int inLen) {
 
     /* check */
     if (in == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -128,7 +128,7 @@ int _encodeBase64(char *out, unsigned char * in, int len) {
 
     /* check */
     if (out == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return -1;
     }
     if (len == 0) {
@@ -136,7 +136,7 @@ int _encodeBase64(char *out, unsigned char * in, int len) {
         return 0;
     }
     if (in == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -192,14 +192,14 @@ char *encodeBase64(unsigned char * in, int inlen, int *outlen) {
 
     /* check */
     if (in == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return NULL;
     }
 
     *outlen = _sizeofBase64Encode(inlen);
     out = (char *) xmalloc_assert(*outlen);
     if (out == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         *outlen = 0;
         return NULL;
     }
@@ -207,7 +207,7 @@ char *encodeBase64(unsigned char * in, int inlen, int *outlen) {
 
     len2 = _encodeBase64(out, in, inlen);
     if (len2 > *outlen) {
-        ERROR("fatal error");
+        LOG(LOG_ERR, "fatal error");
         xfree(out);
         *outlen = 0;
         return NULL;
@@ -240,7 +240,7 @@ int _strippedlength(char * in, int len) {
 
     /* check */
     if (in == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return -1;
     }
 
@@ -281,12 +281,12 @@ int _decodeBase64(unsigned char *out, char * in, int len) {
 
     /* check */
     if (out == NULL) {
-        ERROR("decodeBase64core - out is NULL\n");
+        LOG(LOG_ERR, "decodeBase64core - out is NULL\n");
         return -1;
     }
     /* null input? */
     if (in == NULL) {
-        ERROR("decodeBase64core - in is NULL\n");
+        LOG(LOG_ERR, "decodeBase64core - in is NULL\n");
         return -1;
     }
     /* in[0] => out[0]=\0 */
@@ -302,7 +302,7 @@ int _decodeBase64(unsigned char *out, char * in, int len) {
     while (1) {
         /* check remain buffer size >= 4 */
         if (len2 < 4) {
-            ERROR("bad base64 data size");
+            LOG(LOG_ERR, "bad base64 data size");
             goto error;
         }
         /* remove CR and Space and check bad string */
@@ -327,7 +327,7 @@ int _decodeBase64(unsigned char *out, char * in, int len) {
                     j++;
                 } else {
                     /* BAD BASE64 String */
-                    ERROR("bad base64 data string, 0x%0x", in2[i]);
+                    LOG(LOG_ERR, "bad base64 data string, 0x%0x", in2[i]);
                     goto error;
                 }
             }
@@ -396,14 +396,14 @@ unsigned char *decodeBase64(char * in, int inlen, int *outlen) {
 
     /* check */
     if (in == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return NULL;
     }
 
     len1 = _sizeofBase64Decode(inlen);
     out = (unsigned char *) xmalloc_assert(len1);
     if (out == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         *outlen = 0;
         return NULL;
     }
@@ -411,7 +411,7 @@ unsigned char *decodeBase64(char * in, int inlen, int *outlen) {
 
     len2 = _decodeBase64(out, in, inlen);
     if (len2 < 0) {
-        ERROR("fatal error");
+        LOG(LOG_ERR, "fatal error");
         xfree(out);
         *outlen = 0;
         return NULL;
index f93c31f..6c1b91c 100644 (file)
@@ -175,15 +175,15 @@ int init(
 
     /* check */
     if (conf == NULL) {
-        ERROR("FATAL");
+        LOG(LOG_ERR, "FATAL");
         return PTS_FATAL;
     }
     if (conf->uuid == NULL) {
-        ERROR("FATAL");
+        LOG(LOG_ERR, "FATAL");
         return PTS_FATAL;
     }
     if (conf->uuid->filename == NULL) {
-        ERROR("FATAL");
+        LOG(LOG_ERR, "FATAL");
         return PTS_FATAL;
     }
 
@@ -234,7 +234,7 @@ int init(
     /* ctx for init */
     ctx = newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("no memory?");
+        LOG(LOG_ERR, "no memory?");
         return PTS_FATAL;
     }
 
@@ -431,7 +431,7 @@ int init(
     /* UUID for RM */
     if (conf->rm_uuid == NULL) {
         // init/set by readPtsConf
-        // ERROR("conf->rm_uuid == NULL\n");
+        // LOG(LOG_ERR, "conf->rm_uuid == NULL\n");
         addReason(ctx, -1,
             "[PTSC-INIT] RM_UUID file is not defined (rm.uuid.file) in the ptsc configulation, %s",
             conf->config_file);
@@ -472,7 +472,7 @@ int init(
         if (conf->rm_filename[i] != NULL) {
             rc = writeRm(ctx, conf->rm_filename[i], i);
             if (rc != PTS_SUCCESS) {
-                ERROR("ERROR, initialization was failed\n");
+                LOG(LOG_ERR, "ERROR, initialization was failed\n");
                 // WORK NEEDED: Reason need putting in NLS
                 addReason(ctx, -1,
                     "[PTSC-INIT] Couldn't create the manifest file, %s",
@@ -517,7 +517,7 @@ int init(
 
     OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_SUCCESS,
         "\nptsc has successfully initialized!\n\n"));
-    INFO("ptsc has successfully initialized!\n");
+    LOG(LOG_INFO, "ptsc has successfully initialized!\n");
     goto free;
 
  error:
@@ -525,7 +525,7 @@ int init(
     OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_FAIL,
         "ptsc initialization was failed\n\n"));
     printReason(ctx, 0);
-    INFO("ptsc initialization was failed\n");
+    LOG(LOG_INFO, "ptsc initialization was failed\n");
 
  free:
     /* free */
@@ -581,7 +581,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
     prop = prop_start;
     for (i = 0; i < prop_count; i++) {
         if (prop == NULL) {
-            ERROR("prop == NULL\n");
+            LOG(LOG_ERR, "prop == NULL\n");
             return PTS_INTERNAL_ERROR;  // TODO free
         }
         addProperty(ctx, prop->name, prop->value);
@@ -601,7 +601,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
     /* gen IR */
     rc = genIr(ctx, NULL);
     if (rc != PTS_SUCCESS) {
-        ERROR("selftest() - genIR failed\n");
+        LOG(LOG_ERR, "selftest() - genIR failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -634,9 +634,9 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
     /* setup RMs */
     rc = getRmSetDir(conf);
     if (rc != PTS_SUCCESS) {
-        ERROR("selftest() - getRmSetDir() failed\n");
-        TODO("conf->rm_uuid->filename %s\n", conf->rm_uuid->filename);
-        TODO("conf->rm_uuid->str      %s\n", conf->rm_uuid->str);
+        LOG(LOG_ERR, "selftest() - getRmSetDir() failed\n");
+        LOG(LOG_TODO, "conf->rm_uuid->filename %s\n", conf->rm_uuid->filename);
+        LOG(LOG_TODO, "conf->rm_uuid->str      %s\n", conf->rm_uuid->str);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -645,7 +645,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
     for (i = 0; i <  conf->rm_num; i++) {
         rc = readRmFile(ctx, conf->rm_filename[i], i);
         if (rc < 0) {
-            ERROR("readRmFile fail\n");
+            LOG(LOG_ERR, "readRmFile fail\n");
             rc = PTS_INTERNAL_ERROR;
             goto free;
         }
@@ -704,7 +704,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
                 /* update rm_uuid */
                 rc = writeOpenptsUuidFile(conf->rm_uuid, 1);
                 if (rc != PTS_SUCCESS) {
-                    ERROR("writeOpenptsUuidFile fail\n");
+                    LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
                 }
 
                 // TODO check rc
@@ -714,7 +714,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
                 rc = OPENPTS_SELFTEST_RENEWED;
             } else {
                 /* fail */
-                TODO("\n");
+                LOG(LOG_ERR, "sleftest fail\n");
                 addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_2,
                                "[SELFTEST] The self test using both current and new UUIDs has failed"));
                 printReason(ctx, 0);
@@ -775,7 +775,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
     prop = prop_start;
     for (i = 0; i < prop_count; i++) {
         if (prop == NULL) {
-            ERROR("prop == NULL\n");
+            LOG(LOG_ERR, "prop == NULL\n");
             return PTS_INTERNAL_ERROR;  // TODO free
         }
         addProperty(ctx, prop->name, prop->value);
@@ -795,14 +795,15 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
     /* read FSM */
     rc = readFsmFromPropFile(ctx, conf->config_file);
     if (rc != PTS_SUCCESS) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_FSM, "Failed to read the FSM file\n"));
+        ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_FSM,
+            "Failed to read the FSM file.\n"));
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
 
     /* UUID for RM */
     if (conf->rm_uuid == NULL) {
-        ERROR("conf->rm_uuid == NULL");
+        LOG(LOG_ERR, "conf->rm_uuid == NULL");
     } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
         rc = genOpenptsUuid(conf->rm_uuid);
         // TODO
@@ -813,13 +814,13 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
     /* save/update rm_uuid file */
     rc = writeOpenptsUuidFile(conf->rm_uuid, 1);  // TODO overwite?
     if (rc != PTS_SUCCESS) {
-        ERROR("writeOpenptsUuidFile fail\n");
+        LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
     }
 
     /* RM set DIR */
     rc = makeRmSetDir(conf);
     if (rc != PTS_SUCCESS) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED,
+        ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED,
             "Failed to create the reference manifest set directory\n"));
         goto free;
     }
@@ -832,7 +833,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
     /* load current IML using FSMs */
     if (conf->iml_mode == 0) {  // TODO use def
 #ifdef CONFIG_NO_TSS
-        ERROR("Build with --without-tss. iml.mode=tss is not supported\n");
+        LOG(LOG_ERR, "Build with --without-tss. iml.mode=tss is not supported\n");
 #else
         rc = getIml(ctx, 0);
         rc = getPcr(ctx);
@@ -846,7 +847,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
                 conf->bios_iml_filename, conf->iml_endian);
         if (rc != PTS_SUCCESS) {
             DEBUG("getBiosImlFile() was failed\n");
-            ERROR("Oops! Something is wrong. Please see the reason below\n");
+            LOG(LOG_ERR, "Oops! Something is wrong. Please see the reason below\n");
             printReason(ctx, 0);
             goto free;
         }
@@ -859,13 +860,13 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
                     conf->runtime_iml_filename,
                     conf->runtime_iml_type, 0, &count);  // TODO endian?
             if (rc != PTS_SUCCESS) {
-                ERROR("read IMA IML, %s was failed\n", conf->runtime_iml_filename);
+                LOG(LOG_ERR, "read IMA IML, %s was failed\n", conf->runtime_iml_filename);
                 rc = PTS_INTERNAL_ERROR;
                 goto free;
             }
         }
     } else {
-        ERROR("unknown IML mode, %d\n", conf->iml_mode);
+        LOG(LOG_ERR, "unknown IML mode, %d\n", conf->iml_mode);
     }
 
     /* get SMBIOS data */
@@ -876,13 +877,13 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
         if (conf->rm_filename[i] != NULL) {
             rc = writeRm(ctx, conf->rm_filename[i], i);
             if (rc != PTS_SUCCESS) {
-                ERROR("write RM, %s was failed\n", conf->rm_filename[i]);
+                LOG(LOG_ERR, "write RM, %s was failed\n", conf->rm_filename[i]);
                 rc = PTS_INTERNAL_ERROR;
                 goto free;
             }
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_RM, "level %d Reference Manifest: %s\n"), i, conf->rm_filename[i]);
         } else {
-            ERROR("missing RM file for level %d\n", i);
+            LOG(LOG_ERR, "missing RM file for level %d\n", i);
         }
     }
     // OUTPUT("\nptsc is successfully initialized!\n");
@@ -928,7 +929,7 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) {
                "  Runtime IML file: %s\n"
                "  PCR file: %s\n"), conf->bios_iml_filename, conf->runtime_iml_filename, conf->pcrs_filename);
     } else {
-        ERROR("unknown IML mode, %d\n", conf->iml_mode);
+        LOG(LOG_ERR, "unknown IML mode, %d\n", conf->iml_mode);
     }
 
     /* Linux IMA mode */
@@ -980,7 +981,7 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) {
     /* Models */
     rc = readFsmFromPropFile(ctx, conf->config_file);
     if (rc != PTS_SUCCESS) {
-        ERROR("read FSM failed\n");
+        LOG(LOG_ERR, "read FSM failed\n");
         goto free;
     }
 
@@ -1014,11 +1015,11 @@ int clear(
 
     /* check */
     if (conf == NULL) {
-        ERROR("conf == NULL");
+        LOG(LOG_ERR, "conf == NULL");
         return PTS_FATAL;
     }
     if (conf->config_dir == NULL) {
-        ERROR("conf->config_dir == NULL");
+        LOG(LOG_ERR, "conf->config_dir == NULL");
         return PTS_FATAL;
     }
 
@@ -1028,7 +1029,7 @@ int clear(
     /* clear */
     if (isatty(STDIN_FILENO) && (force == 0) ) {
         char *lineFeed;
-        printf(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR,
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR,
             "Clear the PTS collector [y/N]:"));
         if ( NULL != fgets(ans, 32, stdin) ) {
             // strip the ending line-feed
@@ -1052,7 +1053,7 @@ int clear(
 
         rc = unlinkDir(conf->config_dir);
         if (rc != PTS_SUCCESS) {
-            ERROR("unlinkDir(%s) fail", conf->config_dir);
+            LOG(LOG_ERR, "unlinkDir(%s) fail", conf->config_dir);
         }
         OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR_YES_DONE,
             "%s has been cleared\n\n") , conf->config_dir);
index 3e4b58d..8c26f3d 100644 (file)
@@ -128,7 +128,7 @@ void freeTargetList(OPENPTS_TARGET_LIST *list) {
     for (i = 0; i < num; i++) {
         target = &list->target[i];
         if (target == NULL) {
-            ERROR("no memory cnt=%d\n", i);
+            LOG(LOG_ERR, "no memory cnt=%d\n", i);
         } else {
             if (target->uuid != NULL) freeUuid(target->uuid);
             if (target->str_uuid != NULL) xfree(target->str_uuid);
@@ -190,7 +190,7 @@ int freePtsConfig(OPENPTS_CONFIG * conf) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -419,12 +419,12 @@ static int readPtsConfig_CompID(
     level = strtoul(levelStr, &attributeName, 10);
 
     if (levelStr == attributeName) {
-        ERROR("readPtsConfig_CompID()- invalid level number ('%s')\n", name);
+        LOG(LOG_ERR, "readPtsConfig_CompID()- invalid level number ('%s')\n", name);
         return PTS_FATAL;
     }
 
     if (*attributeName != '.') {
-        ERROR("readPtsConfig_CompID()- missing '.' after level ('%s')\n", name);
+        LOG(LOG_ERR, "readPtsConfig_CompID()- missing '.' after level ('%s')\n", name);
         return PTS_FATAL;
     }
 
@@ -435,7 +435,7 @@ static int readPtsConfig_CompID(
     /******************/
 
     if (level >= MAX_RM_NUM) {
-        ERROR("readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
+        LOG(LOG_ERR, "readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
             attributeName, level, MAX_RM_NUM);
         return PTS_FATAL;
     }
@@ -476,7 +476,7 @@ static int readPtsConfig_CompID(
         conf->compIDs[level].VendorID_type = VENDORID_TYPE_GUID;
         attributeValue = &conf->compIDs[level].VendorID_Value;
     } else {
-        ERROR("unknown Component ID attribute: '%s'\n", attributeName);
+        LOG(LOG_ERR, "unknown Component ID attribute: '%s'\n", attributeName);
         return PTS_FATAL;
     }
 
@@ -526,7 +526,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
     DEBUG("readPtsConfig()            : %s\n", filename);
 
     if (filename == NULL) {
-        ERROR("readPtsConfig - filename is NULL\n");
+        LOG(LOG_ERR, "readPtsConfig - filename is NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -535,7 +535,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
         /* => get fullpath */
         path = getenv("PWD");
         if (path[0] != '/') {
-            ERROR("readPtsConfig() - path, '%s' is not a full path", path);
+            LOG(LOG_ERR, "readPtsConfig() - path, '%s' is not a full path", path);
         }
         filename2 = getFullpathName(path, filename);
     } else {
@@ -577,7 +577,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
 
         /* check for line length */
         if (line_len == LINE_BUF_SIZE) {
-            ERROR("Line too long in %s at line %d\n", filename2, cnt);
+            LOG(LOG_ERR, "Line too long in %s at line %d\n", filename2, cnt);
             isFileIncorrect = 1;
             goto free;
         }
@@ -629,7 +629,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 } else if (!strncmp(value, "tss", 3)) {
                     conf->iml_mode = 0;
                 } else {
-                    ERROR("iml.mode is neither 'securityfs' or 'tss'\n");
+                    LOG(LOG_ERR, "iml.mode is neither 'securityfs' or 'tss'\n");
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -644,7 +644,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->srk_password_mode = 1;
                     DEBUG("conf->srk_password_mode    : known\n");
                 } else {
-                    ERROR("Bad srk.password.mode flag '%s' in %s\n",
+                    LOG(LOG_ERR, "Bad srk.password.mode flag '%s' in %s\n",
                         value, filename);
                     isFileIncorrect = 1;
                     goto free;
@@ -660,7 +660,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->tpm_resetdalock = 0;  // default
                     DEBUG("conf->tpm_resetdalock      : off (default)\n");
                 } else {
-                    ERROR("Bad tpm.resetdalock flag '%s' in %s\n",
+                    LOG(LOG_ERR, "Bad tpm.resetdalock flag '%s' in %s\n",
                         value, filename);
                     isFileIncorrect = 1;
                     goto free;
@@ -676,7 +676,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->tpm_quote_type = 1;
                     DEBUG("conf->tpm_quote_type       : quote\n");
                 } else {
-                    ERROR("Bad tpm.quote.type flag %s\n", value);
+                    LOG(LOG_ERR, "Bad tpm.quote.type flag %s\n", value);
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -700,7 +700,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     DEBUG("endian mode            : convert\n");
 #endif
                 } else {
-                    ERROR("iml.endian is neither 'big' or 'little'\n");
+                    LOG(LOG_ERR, "iml.endian is neither 'big' or 'little'\n");
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -730,7 +730,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 } else if (!strncmp(value, "IMA", 3)) {
                     conf->runtime_iml_type = BINARY_IML_TYPE_IMA_ORIGINAL;
                 } else {
-                    ERROR("unknown runtime.iml.type %s\n", value);
+                    LOG(LOG_ERR, "unknown runtime.iml.type %s\n", value);
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -752,7 +752,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
             if (!strncmp(name, "rm.num", 6)) {
                 conf->rm_num = atoi(value);
                 if (conf->rm_num > MAX_RM_NUM) {
-                    ERROR("RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n", conf->rm_num, MAX_RM_NUM);
+                    LOG(LOG_ERR, "RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n", conf->rm_num, MAX_RM_NUM);
                     conf->rm_num = MAX_RM_NUM;
                 }
                 DEBUG("conf->rm_num               : %d\n", conf->rm_num);
@@ -767,7 +767,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 }
                 conf->ir_filename = getFullpathName(conf->config_dir, value);
                 DEBUG("conf->ir_filename          : %s\n", conf->ir_filename);
-                // ERROR("ir.file is obsolute, please use ir.dir");  /// Collectror TODO 
+                // LOG(LOG_ERR, "ir.file is obsolute, please use ir.dir");  /// Collectror TODO 
             }
             /* IR dir (collector side) */
             if (!strncmp(name, "ir.dir", 6)) {
@@ -794,7 +794,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
             if (!strncmp(name, "ir.quote", 8)) {
                 if (!strncmp(value, "WITHOUT_QUOTE", 13)) {
                     conf->ir_without_quote = 1;
-                    TODO("Generate IR without TPM_Quote signature\n");
+                    LOG(LOG_TODO, "Generate IR without TPM_Quote signature\n");
                 }
             }
 
@@ -828,7 +828,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
 #if 0
             if (!strncmp(name, "config.dir", 10)) {
                 if (conf->config_dir != NULL) {
-                    TODO("conf dir %s ->%s\n", conf->config_dir, value);
+                    LOG(LOG_TODO, "conf dir %s ->%s\n", conf->config_dir, value);
                     //
                 } else {
                     conf->config_dir = getFullpathName(config_path, value);
@@ -843,7 +843,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 } else if (!strncmp(value, "none", 4)) {
                     conf->ima_validation_mode = OPENPTS_VALIDATION_MODE_NONE;
                 } else {
-                    ERROR("unknown ima.validation.mode [%s]\n", value);
+                    LOG(LOG_ERR, "unknown ima.validation.mode [%s]\n", value);
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -888,22 +888,22 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     DEBUG("conf->uuid->str            : %s\n", conf->uuid->str);
                 }
             } else if (!strncmp(name, "uuid", 4)) {
-                ERROR("uuid=XXX is deprecated, in %s\n", filename);
+                LOG(LOG_ERR, "uuid=XXX is deprecated, in %s\n", filename);
                 if (conf->uuid == NULL) {
                     conf->uuid = newOpenptsUuid();
                 }
                 if (conf->uuid->uuid != NULL) {
-                    TODO("free conf->uuid \n");
+                    LOG(LOG_TODO, "free conf->uuid \n");
                     xfree(conf->uuid->uuid);
                 }
                 /* set */
                 conf->uuid->uuid = getUuidFromString(value);
                 if (conf->uuid->uuid == NULL) {
-                    ERROR("read UUID fail\n");
+                    LOG(LOG_ERR, "read UUID fail\n");
                 }
                 conf->uuid->str = getStringOfUuid(conf->uuid->uuid);
                 if (conf->uuid->str == NULL) {
-                    ERROR("read UUID fail\n");
+                    LOG(LOG_ERR, "read UUID fail\n");
                 }
             }
 
@@ -986,7 +986,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 }
                 conf->target_uuid = getUuidFromString(value);
                 if (conf->target_uuid == NULL) {
-                    ERROR("bad UUID ? %s\n", value);
+                    LOG(LOG_ERR, "bad UUID ? %s\n", value);
                 } else {
                     // add string too
                     if (conf->str_target_uuid != NULL) {
@@ -995,7 +995,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     }
                     conf->str_target_uuid = getStringOfUuid(conf->target_uuid);
                     if (conf->str_target_uuid == NULL) {
-                        ERROR("bad UUID ? %s\n", value);
+                        LOG(LOG_ERR, "bad UUID ? %s\n", value);
                     }
                 }
             }
@@ -1010,7 +1010,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     strlen(value),
                     &buf_len);
                 if (conf->pubkey == NULL) {
-                    ERROR("decodeBase64");
+                    LOG(LOG_ERR, "decodeBase64");
                     conf->pubkey_length = 0;
                 } else {
                     conf->pubkey_length = buf_len;
@@ -1049,7 +1049,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 } else if (!strncmp(value, "off", 3)) {
                     conf->selftest = 0;  // default
                 } else {
-                    ERROR("unknown selftest %s\n", value);
+                    LOG(LOG_ERR, "unknown selftest %s\n", value);
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -1063,7 +1063,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->autoupdate = 0;  // default
                     DEBUG("conf->autoupdate           : off\n");
                 } else {
-                    ERROR("unknown autoupdate %s\n", value);  // TODO
+                    LOG(LOG_ERR, "unknown autoupdate %s\n", value);  // TODO
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -1087,7 +1087,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->enrollment = IMV_ENROLLMENT_AUTO;
                     DEBUG("conf->enrollment           : auto\n");
                 } else {
-                    ERROR("unknown enrollment %s\n", value);  // TODO
+                    LOG(LOG_ERR, "unknown enrollment %s\n", value);  // TODO
                     conf->enrollment = 0;
                 }
             }
@@ -1101,7 +1101,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->aik_storage_type = OPENPTS_AIK_STORAGE_TYPE_BLOB;
                     DEBUG("conf->aik_storage_type     : blob\n");
                 } else {
-                    ERROR("unknown aik.storage.type %s\n", value);  // TODO
+                    LOG(LOG_ERR, "unknown aik.storage.type %s\n", value);  // TODO
                     conf->aik_storage_type = 0;
                 }
             }
@@ -1120,7 +1120,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     conf->aik_auth_type = OPENPTS_AIK_AUTH_TYPE_COMMON;
                     DEBUG("conf->aik_auth_type        : common\n");
                 } else {
-                    ERROR("unknown aik.auth.type %s\n", value);  // TODO
+                    LOG(LOG_ERR, "unknown aik.auth.type %s\n", value);  // TODO
                     conf->aik_auth_type = 0;
                 }
             }
@@ -1136,9 +1136,9 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                     DEBUG("Logging location           : syslog\n");
                 } else if (!strncmp(value, "console", 6)) {
                     setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
-                    DEBUG("Logging location           : syslog\n");
+                    DEBUG("Logging location           : console\n");
                 } else {
-                    ERROR("unknown aik.storage.type %s\n", value);  // TODO
+                    LOG(LOG_ERR, "unknown aik.storage.type %s\n", value);  // TODO
                     conf->aik_storage_type = 0;
                 }
             }
@@ -1149,6 +1149,10 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
                 DEBUG("Logging location           : file (%s)\n", log_filename);
                 xfree(log_filename);
             }
+            if (!strncmp(name, "debug.mode", 11)) {
+                debugBits = (int) strtol(value, NULL, 16);
+                DEBUG("DEBUG mode                 : 0x%x\n", debugBits);
+            }
 
             cnt++;
         } else {
@@ -1158,7 +1162,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
             ptr = line;
             while (*ptr != '\0') {
                 if (!isspace(*ptr)) {
-                    ERROR("Syntax error in %s at line %d\n", filename2, cnt);
+                    LOG(LOG_ERR, "Syntax error in %s at line %d\n", filename2, cnt);
                     isFileIncorrect = 1;
                     goto free;
                 }
@@ -1282,7 +1286,7 @@ int writeTargetConf(OPENPTS_CONFIG *conf, PTS_UUID *uuid, char *filename) {
 
     /* open */
     if ((fp = fopen(filename, "w")) == NULL) {
-        ERROR("writeTargetConf - Conf File %s open was failed\n", filename);
+        LOG(LOG_ERR, "writeTargetConf - Conf File %s open was failed\n", filename);
         return -1;
     }
 
@@ -1369,7 +1373,7 @@ int readTargetConf(OPENPTS_CONFIG *conf, char *filename) {
 
     rc = readPtsConfig(conf, filename);
     if (rc != PTS_SUCCESS) {
-        ERROR("readTargetConf - fail, rc = %d\n", rc);
+        LOG(LOG_ERR, "readTargetConf - fail, rc = %d\n", rc);
     }
 
     return rc;
@@ -1393,7 +1397,7 @@ int writeOpenptsConf(OPENPTS_CONFIG *conf, char *filename) {
 
     /* open */
     if ((fp = fopen(filename, "w")) == NULL) {
-        ERROR("writeOpenptsConf - Conf File %s open was failed\n", filename);
+        LOG(LOG_ERR, "writeOpenptsConf - Conf File %s open was failed\n", filename);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1420,17 +1424,17 @@ int readOpenptsConf(OPENPTS_CONFIG *conf, char *filename) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     rc = readPtsConfig(conf, filename);
     if (rc < 0) {
-        ERROR("readOpenptsConf - fail, rc = %d\n", rc);
+        LOG(LOG_ERR, "readOpenptsConf - fail, rc = %d\n", rc);
     }
 
     return rc;
@@ -1444,12 +1448,13 @@ int readOpenptsConf(OPENPTS_CONFIG *conf, char *filename) {
 int setModelFile(OPENPTS_CONFIG *conf, int index, int level, char *filename) {
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if (level >= MAX_RM_NUM) {
-        ERROR("setModelFile()- PCR[%d] trying to affect a model file(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
+        LOG(LOG_ERR,
+            "setModelFile()- PCR[%d] trying to affect a model file(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
         index, filename, level, MAX_RM_NUM);
         return PTS_FATAL;
     }
index f127dc6..9ca6f92 100644 (file)
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -204,7 +204,7 @@ char * getAlgString(int type) {
     } else if (type == ALGTYPE_MD5) {
         return "md5";
     } else {
-        ERROR("unknown type %d\n", type);
+        LOG(LOG_ERR, "unknown type %d\n", type);
         return NULL;
     }
 }
@@ -263,8 +263,8 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
 
         /* check for line length */
         if (len == FSM_BUF_SIZE) {
-            ERROR("Line too long in %s\n", filename);
-            OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
+            LOG(LOG_ERR, "Line too long in %s\n", filename);
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_CONFIG_BAD_CONFIG_FILE, "Bad configuration file\n"));
             rc = PTS_FATAL;
             goto error;
         }
@@ -283,16 +283,16 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
 #if 1
             // Using config file <= version 0.2.3
             if (strstr(buf, "platform.model.") != NULL) {
-                ERROR("ptsc.conf has old format <=v0.2.3 %s\n", filename);
-                ERROR("change platform.model to rm.model.0\n");
+                LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename);
+                LOG(LOG_ERR, "change platform.model to rm.model.0\n");
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
                 rc = PTS_FATAL;
                 goto error;
             }
 
             if (strstr(buf, "runtime.model.") != NULL) {
-                ERROR("ptsc.conf has old format <=v0.2.3 %s\n", filename);
-                ERROR("change runtime.model to rm.model.1\n");
+                LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename);
+                LOG(LOG_ERR, "change runtime.model to rm.model.1\n");
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
                 rc = PTS_FATAL;
                 goto error;
@@ -322,7 +322,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
                 rc = readUmlModel(fsm, buf2);
                 // TODO(munetoh) cehck rc
                 if (rc != PTS_SUCCESS) {
-                    ERROR("addFsmByPropFile -  [%s] / [%s] -> [%s] fail rc=%d, pwd = %s\n",
+                    LOG(LOG_ERR, "addFsmByPropFile -  [%s] / [%s] -> [%s] fail rc=%d, pwd = %s\n",
                         conf->model_dir, model_filename, buf2, rc,
                         getenv("PWD"));
                     goto error;  // return -1;
@@ -331,7 +331,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
                 /* setup the NEW snapshots, BIOS, GRUB */
                 ss = getNewSnapshotFromTable(ctx->ss_table, pcr_index, level);
                 if (ss == NULL) {
-                    ERROR("FSM has been assigned at lvl=%d pcr=%d  %s. check the config file\n",
+                    LOG(LOG_ERR, "FSM has been assigned at lvl=%d pcr=%d  %s. check the config file\n",
                         level, pcr_index, buf);
                     rc = PTS_FATAL;
                     goto error;
@@ -361,7 +361,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
             ptr = buf;
             while (*ptr != '\0') {
                 if (!isspace(*ptr)) {
-                    ERROR("Syntax error in %s\n", filename);
+                    LOG(LOG_ERR, "Syntax error in %s\n", filename);
                     OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
                     rc =  PTS_FATAL;
                     goto error;
index 9b7bcae..ee9bd56 100644 (file)
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -58,7 +58,7 @@ OPENPTS_FSM_CONTEXT *newFsmContext() {
     /* malloc */
     ctx = (OPENPTS_FSM_CONTEXT *) xmalloc(sizeof(OPENPTS_FSM_CONTEXT));
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     /* init */
@@ -78,7 +78,7 @@ OPENPTS_FSM_CONTEXT *newFsmContext() {
 void freeFsmTransitionChain(OPENPTS_FSM_Transition *fsm_trans) {
     /* check */
     if (fsm_trans == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -102,7 +102,7 @@ void freeFsmSubvertexChain(OPENPTS_FSM_Subvertex *fsm_sub) {
 
     /* check */
     if (fsm_sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -122,7 +122,7 @@ int freeFsmContext(OPENPTS_FSM_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -157,7 +157,7 @@ int freeFsmContext(OPENPTS_FSM_CONTEXT *ctx) {
 void resetFsmSubvertex(OPENPTS_FSM_CONTEXT *ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -171,7 +171,7 @@ void resetFsmSubvertex(OPENPTS_FSM_CONTEXT *ctx) {
 void resetFsmTransition(OPENPTS_FSM_CONTEXT *ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -197,23 +197,23 @@ void addFsmSubvertex(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (type == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (id == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (action == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -253,7 +253,7 @@ void addFsmSubvertex(
                 ptr_pre->next = ptr;  // else
                 ptr->prev = ptr_pre;
             } else {
-                ERROR("BAD, free last one");
+                LOG(LOG_ERR, "BAD, free last one");
                 xfree(ptr);  // free last one
                 return;
             }
@@ -274,11 +274,11 @@ OPENPTS_FSM_Subvertex * getSubvertex(OPENPTS_FSM_CONTEXT *ctx, char * id) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (id == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -304,11 +304,11 @@ char * getSubvertexName(OPENPTS_FSM_CONTEXT *ctx, char * id) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (id == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -333,11 +333,11 @@ char * getSubvertexId(OPENPTS_FSM_CONTEXT *ctx, char * name) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -358,7 +358,7 @@ static char *skipWhiteSpace(char *str, int *len /* out */) {
 
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -375,7 +375,7 @@ static char *skipWhiteSpace(char *str, int *len /* out */) {
 static int isEndOfString(char *str) {
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;  // TODO
     }
 
@@ -387,7 +387,7 @@ static char *skipParameter(char *str, int *len /* out */) {
 
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -420,7 +420,7 @@ int getTypeFlag(char * cond, UINT32 *eventtype /* out */) {
 
     /* check */
     if (cond == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -442,7 +442,7 @@ int getTypeFlag(char * cond, UINT32 *eventtype /* out */) {
 
         /* operation */
         if (len < 2) {
-            ERROR("ERROR 001\n");
+            LOG(LOG_ERR, "ERROR 001\n");
             return -1;  // end
         }
         if ((loc[0] == '=') && (loc[1] == '=')) {  // ==
@@ -454,7 +454,7 @@ int getTypeFlag(char * cond, UINT32 *eventtype /* out */) {
         } else if ((loc[0] == 'n') && (loc[1] == 'e')) {  // !=
             rc = 2;
         } else {
-            ERROR("ERROR 002 %c %c \n", loc[0], loc[1]);
+            LOG(LOG_ERR, "ERROR 002 %c %c \n", loc[0], loc[1]);
             return -1;  // unknown operand
         }
         loc += 2;
@@ -506,7 +506,7 @@ int getDigestFlag(char * cond, BYTE **digest, int *digest_size) {
 
     /* check */
     if (cond == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -528,13 +528,13 @@ int getDigestFlag(char * cond, BYTE **digest, int *digest_size) {
 
         /* operation, "==" only */
         if (len < 2) {
-            ERROR("ERROR 001\n");
+            LOG(LOG_ERR, "ERROR 001\n");
             return -1;  // end
         }
         if ((loc[0] == '=') && (loc[1] == '=')) {  // ==
             // operand is ==
         } else {
-            ERROR("ERROR 002 [%c%c]  not  ==, (cond = %s)\n", loc[0], loc[1], cond);
+            LOG(LOG_ERR, "ERROR 002 [%c%c]  not  ==, (cond = %s)\n", loc[0], loc[1], cond);
             return -1;  // unknown operand
         }
         loc +=2;
@@ -564,7 +564,7 @@ int getDigestFlag(char * cond, BYTE **digest, int *digest_size) {
                 SHA1_BASE64_DIGEST_SIZE,
                 &buf_len);
             if (buf == NULL) {
-                ERROR("decodeBase64 fail");
+                LOG(LOG_ERR, "decodeBase64 fail");
                 *digest = NULL;
                 *digest_size = 0;
                 return -1;
@@ -573,7 +573,7 @@ int getDigestFlag(char * cond, BYTE **digest, int *digest_size) {
                 *digest_size = SHA1_DIGEST_SIZE;
                 return DIGEST_FLAG_EQUAL;  // 1
             } else {
-                ERROR("getDigestFlag() - decodeBase64() was failed \n");
+                LOG(LOG_ERR, "getDigestFlag() - decodeBase64() was failed \n");
                 xfree(buf);
                 *digest = NULL;
                 *digest_size = 0;
@@ -603,11 +603,11 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
 
     /* check */
     if (cond == NULL) {
-        ERROR("Null condition found");
+        LOG(LOG_ERR, "Null condition found");
         return 0;
     }
     if (name == NULL) {
-        ERROR("Null condition found");
+        LOG(LOG_ERR, "Null condition found");
         return 0;
     }
 
@@ -665,7 +665,7 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
             loc +=2;
             len -=2;
         } else {
-            ERROR("unknown operand [%s]", &loc[0]);
+            LOG(LOG_ERR, "unknown operand [%s]", &loc[0]);
             goto error;  //return -1;
         }
 
@@ -698,7 +698,7 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
     return rc;
 
   error:
-    ERROR("getCounterFlag(\"%s\",\"%s\") fail", cond, name);
+    LOG(LOG_ERR, "getCounterFlag(\"%s\",\"%s\") fail", cond, name);
     return -1;
 }
 
@@ -725,7 +725,7 @@ int getLastFlag(char * cond) {
 
     /* check */
     if (cond == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -758,13 +758,13 @@ int getLastFlag(char * cond) {
             loc +=2;
             len -=2;
         } else {
-            ERROR("Unknown operation [%s], cond=[%s], BAD Validation Model\n", &loc[0], cond);
+            LOG(LOG_ERR, "Unknown operation [%s], cond=[%s], BAD Validation Model\n", &loc[0], cond);
             return -1;
         }
 
         loc = skipWhiteSpace(loc, &len);
         if (isEndOfString(loc)) {
-            ERROR("Unknown operation [%s]\n", &loc[0]);
+            LOG(LOG_ERR, "Unknown operation [%s]\n", &loc[0]);
             return -1;
         }
 
@@ -784,7 +784,7 @@ int getLastFlag(char * cond) {
                 rc = LAST_FLAG_EQ;
             }
         } else {
-            ERROR("unknown value, %s\n", loc2);
+            LOG(LOG_ERR, "unknown value, %s\n", loc2);
         }
     }
 
@@ -816,19 +816,19 @@ int addFsmTransition(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (source == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (target == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (cond == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -844,7 +844,7 @@ int addFsmTransition(
             ptr = (OPENPTS_FSM_Transition *)
                     xmalloc(sizeof(OPENPTS_FSM_Transition));
             if (ptr == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 return PTS_INTERNAL_ERROR;
             }
             /* init */
@@ -867,12 +867,12 @@ int addFsmTransition(
                 // 0:don't care, 1:<, 2:>=
                 ptr->counter_flag = getCounterFlag(cond, "digest_count", &ptr->counter_name);
                 if (ptr->counter_flag < 0) {
-                    ERROR("getCounterFlag() fail (%s => %s [%s])", source, target, cond);
+                    LOG(LOG_ERR, "getCounterFlag() fail (%s => %s [%s])", source, target, cond);
                 }
                 // 0:don't care, 1:<, 2:>=
                 ptr->fatal_counter_flag = getCounterFlag(cond, "fatal_count", &ptr->fatal_counter_name);
                 if (ptr->fatal_counter_flag < 0) {
-                    ERROR("getCounterFlag() fail (%s => %s [%s])", source, target, cond);
+                    LOG(LOG_ERR, "getCounterFlag() fail (%s => %s [%s])", source, target, cond);
                 }
                 // 0:don't care 1: ==last 2: != last
                 ptr->last_flag = getLastFlag(cond);
@@ -897,7 +897,7 @@ int addFsmTransition(
                 ptr->prev = ptr_pre;
                 ptr->next = NULL;  // last trans
             } else {
-                ERROR("BAD, free last one");
+                LOG(LOG_ERR, "BAD, free last one");
                 xfree(ptr);  // free last one
                 return PTS_INTERNAL_ERROR;
             }
@@ -910,7 +910,7 @@ int addFsmTransition(
         ptr = (OPENPTS_FSM_Transition *)ptr->next;
     }
 
-    ERROR("missing?\n");
+    LOG(LOG_ERR, "missing?\n");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -935,7 +935,7 @@ char *getEventString(OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
     if (event != NULL) {
         // len = snprintf(buf, size, "PCR[%d],TYPE=%d", (int)event->ulPcrIndex, event->eventType);
     } else {
-        ERROR("NULL event\n");  // TODO(munetoh)
+        LOG(LOG_ERR, "NULL event\n");  // TODO(munetoh)
         xfree(buf);
         return NULL;
     }
@@ -960,11 +960,11 @@ int getCountFromProperty(OPENPTS_CONTEXT *ctx, char * name) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -1027,11 +1027,11 @@ int updateFsm(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (fsm == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1060,7 +1060,7 @@ int updateFsm(
         /*  push */
         rc = updateFsm(ctx, fsm, eventWrapper);
         if (rc == OPENPTS_FSM_ERROR) {
-            ERROR("updateFsm() - updateFsm push was fail\n");
+            LOG(LOG_ERR, "updateFsm() - updateFsm push was fail\n");
         }
         if (rc == OPENPTS_FSM_ERROR_LOOP) {
             // DEBUG("updateFsm -- updateFsm push - loop \n");
@@ -1083,7 +1083,7 @@ int updateFsm(
                 return OPENPTS_FSM_ERROR_LOOP;
             }
         } else {
-           ERROR("missing event body\n");
+           LOG(LOG_ERR, "missing event body\n");
            return OPENPTS_FSM_ERROR;
         }
     } else {
@@ -1163,7 +1163,7 @@ int updateFsm(
                     if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                         rc = OPENPTS_FSM_FINISH;
                     } else {
-                        ERROR("updateFsm - flash FSM was failed\n");
+                        LOG(LOG_ERR, "updateFsm - flash FSM was failed\n");
                         rc = OPENPTS_FSM_ERROR;
                     }
                 } else if (rc == OPENPTS_FSM_TRANSIT) {
@@ -1175,14 +1175,14 @@ int updateFsm(
                     if  (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                         rc = OPENPTS_FSM_TRANSIT;
                     } else {
-                        ERROR("updateFsm - FSM did not finish\n");
+                        LOG(LOG_ERR, "updateFsm - FSM did not finish\n");
                         rc = OPENPTS_FSM_ERROR;
                     }
                 } else if (rc == OPENPTS_FSM_ERROR) {
-                    ERROR("updateFsm - FSM doActivity False\n");
+                    LOG(LOG_ERR, "updateFsm - FSM doActivity False\n");
                     return rc;
                 } else if (rc == OPENPTS_FSM_MIGRATE_EVENT) {
-                    TODO("updateFsm - OPENPTS_FSM_MIGRATE_EVENT \n");
+                    LOG(LOG_TODO, "updateFsm - OPENPTS_FSM_MIGRATE_EVENT \n");
                     return rc;
                 } else if (rc == OPENPTS_FSM_SUCCESS) {
                     rc = updateFsm(ctx, fsm, eventWrapper);
@@ -1190,12 +1190,12 @@ int updateFsm(
                     // TODO  << INFO:(TODO) action.c:97 addBIOSAction() - eventWrapper is NULL
                     rc = updateFsm(ctx, fsm, eventWrapper);
                 } else {
-                    TODO("updateFsm() - rc = %d, call updateFsm() again\n", rc);
+                    LOG(LOG_TODO, "updateFsm() - rc = %d, call updateFsm() again\n", rc);
                     rc = updateFsm(ctx, fsm, eventWrapper);
                 }
             }  // curr state
         } else {  // hit
-            TODO("no trans\n");
+            LOG(LOG_TODO, "no trans\n");
         }
     } else {
         /* check trans chain */
@@ -1300,7 +1300,7 @@ int updateFsm(
                     int fatal_count = getCountFromProperty(ctx, trans->fatal_counter_name);
 
                     if (fatal_count < 0) {
-                        ERROR("getCountFromProperty() fail");
+                        LOG(LOG_ERR, "getCountFromProperty() fail");
                     } else if (ctx->count < fatal_count) {
                         DEBUG_FSM("FATAL COUNTER %d < %d - HIT\n", ctx->count, fatal_count);
                         fatal_counter_check = 1;  // HIT
@@ -1314,7 +1314,7 @@ int updateFsm(
 
                     // TODO at this moment we ignore >= condition,
                     if (fatal_count < 0) {
-                        ERROR("getCountFromProperty() fail");
+                        LOG(LOG_ERR, "getCountFromProperty() fail");
                     } else if (ctx->count >= fatal_count) {
                         DEBUG_FSM("FATAL COUNTER %d >= %d - HIT\n", ctx->count, fatal_count);
                         fatal_counter_check = 1;  // HIT
@@ -1330,7 +1330,7 @@ int updateFsm(
                     int thisCount = 1 + trans->event_num;
                     int maxCount = getCountFromProperty(ctx, trans->counter_name);
                     if (maxCount < 0) {
-                        ERROR("getCountFromProperty() fail, trans->counter_flag=%d", trans->counter_flag);
+                        LOG(LOG_ERR, "getCountFromProperty() fail, trans->counter_flag=%d", trans->counter_flag);
                     } else if (trans->counter_flag == COUNTER_FLAG_GE &&
                         thisCount >= maxCount) {
                         DEBUG_FSM("DIGEST COUNTER %d >= %d ('%s') - digest is transparent\n",
@@ -1356,7 +1356,7 @@ int updateFsm(
                         /* Final state */
                         DEBUG_FSM("\tPCR[%d] level %d, Final state!! move to the next snapshot\n",
                             fsm->pcr_index, fsm->level);
-                        // ERROR("PCR[%d] level %d, Final\n", fsm->pcr_index, fsm->level);
+                        // LOG(LOG_ERR, "PCR[%d] level %d, Final\n", fsm->pcr_index, fsm->level);
                         fsm->status = OPENPTS_FSM_FINISH;
                         return OPENPTS_FSM_FINISH_WO_HIT;  // FINAL
                     }
@@ -1390,7 +1390,7 @@ int updateFsm(
                                 if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                                     rc = OPENPTS_FSM_FINISH;
                                 } else {
-                                    ERROR("flash FSM was failed\n");
+                                    LOG(LOG_ERR, "flash FSM was failed\n");
                                     rc = OPENPTS_FSM_ERROR;
                                 }
                             } else if (rc == OPENPTS_FSM_TRANSIT) {
@@ -1402,7 +1402,7 @@ int updateFsm(
                                 if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                                     rc = OPENPTS_FSM_TRANSIT;
                                 } else {
-                                    ERROR("updateFsm - FSM did not finish\n");
+                                    LOG(LOG_ERR, "updateFsm - FSM did not finish\n");
                                     rc = OPENPTS_FSM_ERROR;
                                 }
                             } else if (rc == OPENPTS_FSM_ERROR) {
@@ -1414,12 +1414,12 @@ int updateFsm(
                                     fsm->pcr_index, (char *)fsm->curr_state->action, fsm->curr_state->name);
                                 return rc;
                             } else if (rc == OPENPTS_FSM_MIGRATE_EVENT) {
-                                TODO("updateFsm - OPENPTS_FSM_MIGRATE_EVENT \n");
+                                LOG(LOG_TODO, "updateFsm - OPENPTS_FSM_MIGRATE_EVENT \n");
                                 return rc;
                             } else if (rc == OPENPTS_FSM_SUCCESS) {
                                 rc = updateFsm(ctx, fsm, eventWrapper);
                             } else {
-                                TODO("rc = %d\n", rc);
+                                LOG(LOG_TODO, "rc = %d\n", rc);
                                 rc = updateFsm(ctx, fsm, eventWrapper);
                             }
                         }
@@ -1446,7 +1446,7 @@ int updateFsm(
                                 if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                                     rc = OPENPTS_FSM_FINISH;
                                 } else {
-                                    ERROR("updateFsm - flash FSM was failed, rc = %d\n", rc);
+                                    LOG(LOG_ERR, "updateFsm - flash FSM was failed, rc = %d\n", rc);
                                     rc = OPENPTS_FSM_ERROR;
                                 }
                             } else if (rc == OPENPTS_FSM_TRANSIT) {
@@ -1458,11 +1458,11 @@ int updateFsm(
                                 if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
                                     rc = OPENPTS_FSM_TRANSIT;
                                 } else {
-                                    ERROR("updateFsm - FSM did not finish\n");
+                                    LOG(LOG_ERR, "updateFsm - FSM did not finish\n");
                                     rc = OPENPTS_FSM_ERROR;
                                 }
                             } else if (rc == OPENPTS_FSM_ERROR) {
-                                ERROR("updateFsm - FSM doActivity False, rc = %d\n", rc);
+                                LOG(LOG_ERR, "updateFsm - FSM doActivity False, rc = %d\n", rc);
                                 return rc;
                             } else if (rc == OPENPTS_FSM_MIGRATE_EVENT) {
                                 // DEBUG("updateFsm - OPENPTS_FSM_MIGRATE_EVENT \n");
@@ -1475,7 +1475,7 @@ int updateFsm(
                                 rc = OPENPTS_FSM_SUCCESS;
                             }
                         } else {
-                            ERROR("curr_state is NULL, missing %s\n", trans->target);
+                            LOG(LOG_ERR, "curr_state is NULL, missing %s\n", trans->target);
                             rc = OPENPTS_FSM_ERROR;
                             return rc;
                         }
@@ -1545,7 +1545,7 @@ OPENPTS_FSM_CONTEXT *copyFsm(OPENPTS_FSM_CONTEXT *src_fsm) {
     count = 0;
     src_fsm_sub = src_fsm->fsm_sub;
     if (src_fsm_sub == NULL) {
-        ERROR("ERROR No FSM SUB\n");
+        LOG(LOG_ERR, "ERROR No FSM SUB\n");
         goto error;
     }
 
@@ -1583,7 +1583,7 @@ OPENPTS_FSM_CONTEXT *copyFsm(OPENPTS_FSM_CONTEXT *src_fsm) {
     src_fsm_trans = src_fsm->fsm_trans;
 
     if (src_fsm_trans == NULL) {
-        ERROR("ERROR No FSM TRANS\n");
+        LOG(LOG_ERR, "ERROR No FSM TRANS\n");
         goto error;
     }
 
@@ -1611,7 +1611,7 @@ OPENPTS_FSM_CONTEXT *copyFsm(OPENPTS_FSM_CONTEXT *src_fsm) {
         if (src_fsm_sub != NULL) {
             dst_fsm_trans->source_subvertex = src_fsm_sub->link;
         } else {
-            ERROR("ERROR BHV trans %s source_subvertex is NULL\n",
+            LOG(LOG_ERR, "ERROR BHV trans %s source_subvertex is NULL\n",
                 src_fsm_trans->source);
         }
 
@@ -1669,15 +1669,15 @@ int changeTargetSubvertex(
 
     /* check */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (old_sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (new_sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1726,15 +1726,15 @@ int changeTransTargetSubvertex(
 
     /* check */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (old_sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (new_sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1824,30 +1824,30 @@ int insertFsmNew(
 
     /* check input */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     if (fsm_trans == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     event = eventWrapper->event;
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
     if (fsm_trans->source_subvertex == NULL) {
-        ERROR("ERROR fsm_trans->source_subvertex == NULL, %s -> %s\n",
+        LOG(LOG_ERR, "ERROR fsm_trans->source_subvertex == NULL, %s -> %s\n",
             fsm_trans->source, fsm_trans->target);
         return -1;
     }
     if (fsm_trans->target_subvertex == NULL) {
-        ERROR("ERROR fsm_trans->target_subvertex == NULL\n");
+        LOG(LOG_ERR, "ERROR fsm_trans->target_subvertex == NULL\n");
         return -1;
     }
 
@@ -1994,11 +1994,11 @@ int insertFsmNew(
             DEBUG_FSM("\tUpdate Trans BIN(%s -> %s)\n",
                       fsm_trans->source, fsm_trans->target);
         } else {
-            ERROR("BAD LOOP");
+            LOG(LOG_ERR, "BAD LOOP");
             return PTS_FATAL;
         }
     } else {
-        ERROR("Not a loop");
+        LOG(LOG_ERR, "Not a loop");
         return PTS_FATAL;
     }
 
@@ -2019,11 +2019,11 @@ int removeFsmTrans(
 
     /* check */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (trans == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2060,11 +2060,11 @@ int removeFsmSub(
 
     /* check */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2106,7 +2106,7 @@ int cleanupFsm(OPENPTS_FSM_CONTEXT *fsm_ctx) {
 
     /* check */
     if (fsm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2117,7 +2117,7 @@ int cleanupFsm(OPENPTS_FSM_CONTEXT *fsm_ctx) {
     trans = fsm_ctx->fsm_trans;
 
     if (trans == NULL) {
-        ERROR("ERROR No FSM TRANS\n");
+        LOG(LOG_ERR, "ERROR No FSM TRANS\n");
         return -1;
     }
 
@@ -2129,7 +2129,7 @@ int cleanupFsm(OPENPTS_FSM_CONTEXT *fsm_ctx) {
                       trans->source, trans->target);
             rc = removeFsmTrans(fsm_ctx, trans);  // remove Trans
             if (rc < 0) {
-                ERROR("removeFsmTrans of %s -> %s was failed\n",
+                LOG(LOG_ERR, "removeFsmTrans of %s -> %s was failed\n",
                       trans->source, trans->target);
                 return -1;
             }
@@ -2146,7 +2146,7 @@ int cleanupFsm(OPENPTS_FSM_CONTEXT *fsm_ctx) {
     /* Delete state which does not have incomming trans */
     sub = fsm_ctx->fsm_sub;
     if (sub == NULL) {
-        ERROR("ERROR No FSM SUB\n");
+        LOG(LOG_ERR, "ERROR No FSM SUB\n");
         return -1;
     }
 
@@ -2201,7 +2201,7 @@ int cleanupFsm(OPENPTS_FSM_CONTEXT *fsm_ctx) {
     trans = fsm_ctx->fsm_trans;
 
     if (trans == NULL) {
-        ERROR("No FSM TRANS\n");
+        LOG(LOG_ERR, "No FSM TRANS\n");
         return -1;
     }
 
@@ -2252,7 +2252,7 @@ int writeDotModel(OPENPTS_FSM_CONTEXT *ctx, char * filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2260,7 +2260,7 @@ int writeDotModel(OPENPTS_FSM_CONTEXT *ctx, char * filename) {
         fp = stdout;
     } else {
         if ((fp = fopen(filename, "w")) == NULL) {
-            ERROR("fopen fail %s\n", filename);
+            LOG(LOG_ERR, "fopen fail %s\n", filename);
             return PTS_OS_ERROR;
         }
     }
@@ -2347,11 +2347,11 @@ int writeCsvTable(OPENPTS_FSM_CONTEXT *ctx, char * filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     if (filename == NULL) {
-        ERROR("writeCsvTable - filename is NULL\n");
+        LOG(LOG_ERR, "writeCsvTable - filename is NULL\n");
         return -1;
     }
 
@@ -2410,7 +2410,7 @@ int printFsmModel(OPENPTS_FSM_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2424,7 +2424,7 @@ int printFsmModel(OPENPTS_FSM_CONTEXT *ctx) {
     ptr = ctx->fsm_trans;
     for (i = 0; i < ctx->transition_num; i++) {
         if (ptr == NULL) {
-            ERROR("PTR is NULL at %d\n", i);
+            LOG(LOG_ERR, "PTR is NULL at %d\n", i);
             return PTS_FATAL;
         }
         OUTPUT("%5d ", i);
index e055c76..8b00ef3 100644 (file)
--- a/src/ifm.c
+++ b/src/ifm.c
@@ -61,7 +61,7 @@
 void htoncl(uint8_t *ptr, uint32_t value) {
     /* check */
     if (ptr == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     /* Convert value to network endian */
@@ -74,7 +74,7 @@ void htoncl(uint8_t *ptr, uint32_t value) {
 uint32_t nctohl(uint8_t *ptr) {
     /* check */
     if (ptr == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -121,12 +121,12 @@ ssize_t my_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
         write_size = wrapWrite(out_fd, buf, read_size);
 
         if (write_size < 0) {
-            ERROR("\n");
+            LOG(LOG_ERR, "\n");
             sum = -1;
             break;
         }
         if (write_size != read_size) {
-            ERROR("\n");
+            LOG(LOG_ERR, "\n");
             sum = -1;
             break;
         }
@@ -150,7 +150,7 @@ ssize_t copyfile(BYTE *buf, int in_fd, size_t count) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -198,7 +198,7 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) {
     /* malloc TLV for read */
     read_tlv = (PTS_IF_M_Attribute *)xmalloc(sizeof(PTS_IF_M_Attribute));
     if (read_tlv == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(read_tlv, 0, sizeof(PTS_IF_M_Attribute));
@@ -225,7 +225,7 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) {
 
     /* check the length */
     if (read_tlv->length > MAX_TLV_MESSAGE_LENGTH) {
-        ERROR("read_tlv->length = %d (0x%X)> %d\n",
+        LOG(LOG_ERR, "read_tlv->length = %d (0x%X)> %d\n",
             read_tlv->length, read_tlv->length, MAX_TLV_MESSAGE_LENGTH);
         goto error;
     }
@@ -281,7 +281,7 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) {
 void freePtsTlv(PTS_IF_M_Attribute *tlv) {
     /* check */
     if (tlv == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -307,7 +307,7 @@ BYTE *getTlvBuffer(int type, int length) {
     PTS_IF_M_Attribute *write_tlv;
 
     if ((buf = xmalloc(12 + length)) == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     /* setup TLV header */
@@ -345,12 +345,12 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -374,7 +374,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 #endif
         buf = getTlvBuffer(type, 0);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         break;
@@ -385,7 +385,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
 
@@ -435,7 +435,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             length = ctx->conf->pubkey_length;
             buf = getTlvBuffer(type, length);
             if (buf == NULL) {
-                ERROR("getTlvBuffer() is null");
+                LOG(LOG_ERR, "getTlvBuffer() is null");
                 goto error;
             }
 
@@ -444,7 +444,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         } else {
             /* PUB key is missing */
-            ERROR("writePtsTlvToSock - PUBKEY blob is missing\n");
+            LOG(LOG_ERR, "writePtsTlvToSock - PUBKEY blob is missing\n");
             ctx->ifm_errno = PTS_FATAL;
             ctx->ifm_strerror = smalloc_assert("Public key is missing");
             length = 0;
@@ -463,7 +463,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             fd[i] = open(ctx->conf->rm_filename[i], O_RDONLY);
             if (fd[i] < 0) {
                 // 20101124 SM must be a fullpath for Daemon
-                ERROR("Can't open RM[%d] files, %s\n",
+                LOG(LOG_ERR, "Can't open RM[%d] files, %s\n",
                     i, ctx->conf->rm_filename[i]);
                 /* send Error massage */
                 ctx->ifm_errno = PTS_FATAL;
@@ -473,7 +473,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             }
             /* size */
             if (-1 == fstat(fd[i], &st[i])) {
-                ERROR("fstat failed with errno %d\n", errno);
+                LOG(LOG_ERR, "fstat failed with errno %d\n", errno);
                 goto error;
             }
             fsize[i] = st[i].st_size;
@@ -499,7 +499,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
             count[i] = copyfile(&buf[ptr], fd[i], fsize[i]);
             if (count[i] != fsize[i]) {
-                ERROR("copyfile() faild %d != %d\n", count[i], fsize[i]);
+                LOG(LOG_ERR, "copyfile() faild %d != %d\n", count[i], fsize[i]);
             }
 
             /* close */
@@ -529,7 +529,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             fd[i] = open(ctx->conf->newrm_filename[i], O_RDONLY);
             if (fd[i] < 0) {
                 // 20101124 SM must be a fullpath for Daemon
-                ERROR("Error RM file, %s not found\n", ctx->conf->newrm_filename[i]);
+                LOG(LOG_ERR, "Error RM file, %s not found\n", ctx->conf->newrm_filename[i]);
                 /* send Error massage */
                 ctx->ifm_errno = PTS_FATAL;
                 ctx->ifm_strerror =
@@ -538,7 +538,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             }
             /* check the size */
             if (-1 == fstat(fd[i], &st[i])) {
-                ERROR("fstat failed with errno %d\n", errno);
+                LOG(LOG_ERR, "fstat failed with errno %d\n", errno);
                 goto error;
             }
             fsize[i] = st[i].st_size;
@@ -550,7 +550,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
@@ -586,7 +586,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
         length = ctx->nonce->nonce_length;
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         memcpy(&buf[12], ctx->nonce->nonce, length);
@@ -600,7 +600,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
            gets closed you lose the IR! */
         rc = genIr(ctx, &fd[0]);
         if (rc != PTS_SUCCESS) {
-            ERROR("writePtsTlvToSock - gen IR failed\n");
+            LOG(LOG_ERR, "writePtsTlvToSock - gen IR failed\n");
             /* send Error massage */
             ctx->ifm_errno = PTS_FATAL;
             ctx->ifm_strerror = smalloc_assert("Generation of IR failed");
@@ -609,7 +609,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         /* check the IR size */
         if (-1 == fstat(fd[0], &st[0])) {
-            ERROR("fstat failed with errno %d\n", errno);
+            LOG(LOG_ERR, "fstat failed with errno %d\n", errno);
             goto error;
         }
         fsize[0] = st[0].st_size;
@@ -617,19 +617,19 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
 
         if (-1 == lseek(fd[0], 0, SEEK_SET)) {
-            ERROR("Could not seek to start of %s (fd '%d')\n", ctx->conf->ir_filename, fd[0]);
+            LOG(LOG_ERR, "Could not seek to start of %s (fd '%d')\n", ctx->conf->ir_filename, fd[0]);
             goto error;
         }
 
         count[0] = copyfile(&buf[ptr], fd[0], fsize[0]);
         if (count[0] != fsize[0]) {
-            ERROR("copyfile() faild %d != %d\n", count[0], fsize[0]);
+            LOG(LOG_ERR, "copyfile() faild %d != %d\n", count[0], fsize[0]);
         }
 
         /* close */
@@ -654,7 +654,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             fd[0] = open(ctx->conf->aide_database_filename, O_RDONLY);
             if (fd[0] < 0) {
                 /* AIDE file is missing, erorr */
-                ERROR("writePtsTlvToSock - Error AIDE DB file, %s not found\n",
+                LOG(LOG_ERR, "writePtsTlvToSock - Error AIDE DB file, %s not found\n",
                     ctx->conf->aide_database_filename);
                 /* send Error massage */
                 ctx->ifm_errno = PTS_FATAL;
@@ -663,7 +663,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             } else {
                 /* OK */
                 if (-1 == fstat(fd[0], &st[0])) {
-                    ERROR("fstat failed with errno %d\n", errno);
+                    LOG(LOG_ERR, "fstat failed with errno %d\n", errno);
                     goto error;
                 }
                 fsize[0] = st[0].st_size;
@@ -673,7 +673,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
@@ -683,7 +683,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
             // BODY1
             count[0] = copyfile(&buf[ptr], fd[0], fsize[0]);
             if (count[0] != fsize[0]) {
-                ERROR("copyfile() faild %d != %d\n", count[0], fsize[0]);
+                LOG(LOG_ERR, "copyfile() faild %d != %d\n", count[0], fsize[0]);
             }
 
             /* close */
@@ -734,7 +734,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
@@ -783,7 +783,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
@@ -827,7 +827,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
         buf = getTlvBuffer(type, length);
         if (buf == NULL) {
-            ERROR("getTlvBuffer() is null");
+            LOG(LOG_ERR, "getTlvBuffer() is null");
             goto error;
         }
         ptr = 12;
@@ -866,7 +866,7 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
 
     default:
         // BAD type
-        ERROR("BAD IF-M OPENPTS MESSAGE TYPE, type=0x%x\n", type);
+        LOG(LOG_ERR, "BAD IF-M OPENPTS MESSAGE TYPE, type=0x%x\n", type);
         return NULL;
     }
 
@@ -909,7 +909,7 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fdout, int type) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -934,7 +934,7 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fdout, int type) {
     /* send ERROR */
     len = writePtsTlv(ctx, fdout, OPENPTS_ERROR);
     if (len < 0) {
-        ERROR("send OPENPTS_ERROR was faild");
+        LOG(LOG_ERR, "send OPENPTS_ERROR was faild");
     }
 
     return -1;
index a374b92..09d4c26 100644 (file)
--- a/src/imc.c
+++ b/src/imc.c
@@ -111,14 +111,14 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
         imcID, minVersion, maxVersion);
 
     if (initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_ALREADY_INITIALIZED;
     }
 
     /* check version - Only support version 1 */
     if ((minVersion < TNC_IFIMC_VERSION_1) ||
         (maxVersion > TNC_IFIMC_VERSION_1)) {
-        ERROR("no common version");
+        LOG(LOG_ERR, "no common version");
         return TNC_RESULT_NO_COMMON_VERSION;
     }
 
@@ -129,13 +129,13 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
     /* initialize PTS Collector */
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
     ctx =  newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("no memory\n");
+        LOG(LOG_ERR, "no memory\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
@@ -145,14 +145,14 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
     /* configure PTS Collector */
     rc = readPtsConfig(conf, PTSC_CONFIG_FILE);
     if (rc != PTS_SUCCESS) {
-        ERROR("read config file, '%s' was failed - abort\n", PTSC_CONFIG_FILE);
+        LOG(LOG_ERR, "read config file, '%s' was failed - abort\n", PTSC_CONFIG_FILE);
         rc = TNC_RESULT_FATAL;
         goto error;
     }
 
     /* check IR dir */
     if (checkDir(conf->ir_dir) != PTS_SUCCESS) {
-        ERROR("Initialize the IMC. e.g. ptsc -i\n");
+        LOG(LOG_ERR, "Initialize the IMC. e.g. ptsc -i\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
@@ -160,7 +160,7 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
     /* RM UUID */
     rc = readOpenptsUuidFile(conf->rm_uuid);
     if (rc != PTS_SUCCESS) {
-        ERROR("read RM UUID file %s was failed, initialize ptscd first\n", conf->rm_uuid->filename);
+        LOG(LOG_ERR, "read RM UUID file %s was failed, initialize ptscd first\n", conf->rm_uuid->filename);
         rc = TNC_RESULT_FATAL;
         goto error;
     } else {
@@ -189,7 +189,7 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
             &conf->pubkey_length,
             &conf->pubkey);
     if (rc != TSS_SUCCESS) {
-        ERROR("getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
+        LOG(LOG_ERR, "getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
             rc, conf->srk_password_mode, conf->uuid->str);
         rc = TNC_RESULT_FATAL;
         goto error;
@@ -226,13 +226,13 @@ TNC_IMC_API TNC_Result TNC_IMC_NotifyConnectionChange(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("BAD id");
+        LOG(LOG_ERR, "BAD id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -257,13 +257,13 @@ TNC_IMC_API TNC_Result TNC_IMC_BeginHandshake(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("bad id");
+        LOG(LOG_ERR, "bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -306,19 +306,19 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("bad id");
+        LOG(LOG_ERR, "bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
     /* connection ID */
     if (connectionID != cid) {
-        ERROR("bad cid");
+        LOG(LOG_ERR, "bad cid");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -332,7 +332,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
         read_tlv = (PTS_IF_M_Attribute*)messageBuffer;
         if (read_tlv == NULL) {
             // TODO should send error?
-            ERROR("TLV is null");
+            LOG(LOG_ERR, "TLV is null");
             return TNC_RESULT_FATAL;
         }
 
@@ -357,7 +357,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
             /* send TPM_PUBKEY */
             msg = getPtsTlvMessage(ctx, TPM_PUBKEY, &len);
             if (msg == NULL) {
-                ERROR("return  OPENPTS_ERROR");
+                LOG(LOG_ERR, "return  OPENPTS_ERROR");
                 msg = getPtsTlvMessage(ctx, OPENPTS_ERROR, &len);
             }
 
@@ -368,7 +368,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
                 len,
                 ((TNC_VENDORID_OPENPTS << 8) | TNC_SUBTYPE_OPENPTS));
             if (rc != TNC_RESULT_SUCCESS) {
-                ERROR("[C->V] TPM_PUBKEY[%d] fail", len);
+                LOG(LOG_ERR, "[C->V] TPM_PUBKEY[%d] fail", len);
                 return TNC_RESULT_FATAL;
             } else {
                 DEBUG_IFM("[C->V] TPM_PUBKEY[%d]\n", len);
@@ -381,14 +381,14 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
             /* set RM filename */
             rc = getRmSetDir(conf);
             if (rc != PTS_SUCCESS) {
-                ERROR("collector() - getRmSetDir() was failed\n");
+                LOG(LOG_ERR, "collector() - getRmSetDir() was failed\n");
                 return PTS_INTERNAL_ERROR;
             }
 
             /* send RIMM_SET */
             msg = getPtsTlvMessage(ctx, RIMM_SET, &len);
             if (msg == NULL) {
-                ERROR("Get RIMM_SET message was faild, return  OPENPTS_ERROR");
+                LOG(LOG_ERR, "Get RIMM_SET message was faild, return  OPENPTS_ERROR");
                 msg = getPtsTlvMessage(ctx, OPENPTS_ERROR, &len);
             }
 
@@ -399,7 +399,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
                 len,
                 ((TNC_VENDORID_OPENPTS << 8) | TNC_SUBTYPE_OPENPTS));
             if (rc != TNC_RESULT_SUCCESS) {
-                ERROR("[C->V] RIMM_SET[%d] fail\n", len);
+                LOG(LOG_ERR, "[C->V] RIMM_SET[%d] fail\n", len);
                 return TNC_RESULT_FATAL;
             } else {
                 DEBUG_IFM("[C->V] RIMM_SET[%d]\n", len);
@@ -419,7 +419,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
             /* send INTEGRITY_REPORT */
             msg = getPtsTlvMessage(ctx, INTEGRITY_REPORT, &len);
             if (msg == NULL) {
-                ERROR("return  OPENPTS_ERROR");
+                LOG(LOG_ERR, "return  OPENPTS_ERROR");
                 msg = getPtsTlvMessage(ctx, OPENPTS_ERROR, &len);
             }
 
@@ -430,7 +430,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
                 len,
                 ((TNC_VENDORID_OPENPTS << 8) | TNC_SUBTYPE_OPENPTS));
             if (rc != TNC_RESULT_SUCCESS) {
-                ERROR("[C->V] INTEGRITY_REPORT[%d] fail", len);
+                LOG(LOG_ERR, "[C->V] INTEGRITY_REPORT[%d] fail", len);
                 return TNC_RESULT_FATAL;
             } else {
                 DEBUG_IFM("[C->V] INTEGRITY_REPORT[%d]\n", len);
@@ -438,16 +438,16 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
             break;
 
         default:
-            ERROR("Unknown type %08X", type);
+            LOG(LOG_ERR, "Unknown type %08X", type);
             break;
         }
         return rc;
     } else if (messageType == ((TNC_VENDORID_TCG_PEN << 8) | TNC_SUBTYPE_TCG_PTS)) {
         /* TCG */
-        ERROR("TBD\n");
+        LOG(LOG_ERR, "TBD\n");
         return TNC_RESULT_FATAL;
     } else {
-        ERROR("bad msg from collector");
+        LOG(LOG_ERR, "bad msg from collector");
         return TNC_RESULT_FATAL;
     }
 
@@ -464,19 +464,19 @@ TNC_IMC_API TNC_Result TNC_IMC_BatchEnding(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("bad id");
+        LOG(LOG_ERR, "bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
     /* connection ID */
     if (connectionID != cid) {
-        ERROR("bad cid");
+        LOG(LOG_ERR, "bad cid");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -494,13 +494,13 @@ TNC_IMC_API TNC_Result TNC_IMC_Terminate(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("bad id");
+        LOG(LOG_ERR, "bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -530,7 +530,7 @@ static TNC_Result reportMessageTypes(
         imcID, supportedTypes, typeCount);
 
     if (!reportMessageTypesPtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -554,7 +554,7 @@ static TNC_Result sendMessage(
             message, (int)messageType);
 
     if (!sendMessagePtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -615,13 +615,13 @@ TNC_IMC_API TNC_Result TNC_IMC_ProvideBindFunction(
 
     /* check internal status */
     if (!initialized) {
-        ERROR("not initialized");
+        LOG(LOG_ERR, "not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     /* check ID */
     if (imcID != id) {
-        ERROR("bad id");
+        LOG(LOG_ERR, "bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -631,7 +631,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ProvideBindFunction(
                             "TNC_TNCC_ReportMessageTypes",
                             (void**)&reportMessageTypesPtr)
                 != TNC_RESULT_SUCCESS) {
-            ERROR("bind function fails -TNC_TNCC_ReportMessageTypes\n");
+            LOG(LOG_ERR, "bind function fails -TNC_TNCC_ReportMessageTypes\n");
             rc = TNC_RESULT_FATAL;
             return rc;
         }
@@ -639,7 +639,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ProvideBindFunction(
                             "TNC_TNCC_RequestHandshakeRetry",
                             (void**)&requestHandshakeRetryPtr)
                 != TNC_RESULT_SUCCESS) {
-            ERROR("bind function fails - TNC_TNCC_RequestHandshakeRetry\n");
+            LOG(LOG_ERR, "bind function fails - TNC_TNCC_RequestHandshakeRetry\n");
             rc = TNC_RESULT_FATAL;
             return rc;
         }
@@ -647,7 +647,7 @@ TNC_IMC_API TNC_Result TNC_IMC_ProvideBindFunction(
                             "TNC_TNCC_SendMessage",
                             (void**)&sendMessagePtr)
                 != TNC_RESULT_SUCCESS) {
-            ERROR("bind functionfails -  TNC_TNCC_SendMessage\n");
+            LOG(LOG_ERR, "bind functionfails -  TNC_TNCC_SendMessage\n");
             rc = TNC_RESULT_FATAL;
             return rc;
         }
index 9421286..ce13d75 100644 (file)
--- a/src/iml.c
+++ b/src/iml.c
@@ -58,7 +58,7 @@ int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) {
 
     /* check */
     if (snapshots == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -75,7 +75,7 @@ int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) {
                     xfree(event->rgbEvent);
                 xfree(event);
             } else {
-                ERROR("resetSnapshot - NULL event\n");  // TODO(munetoh)
+                LOG(LOG_ERR, "resetSnapshot - NULL event\n");  // TODO(munetoh)
             }
             eventWrapper_next = eventWrapper->next_pcr;
             xfree(eventWrapper);
@@ -100,7 +100,7 @@ OPENPTS_PCR_EVENT_WRAPPER * newEventWrapper() {
 
     ew = (OPENPTS_PCR_EVENT_WRAPPER *)xmalloc(sizeof(OPENPTS_PCR_EVENT_WRAPPER));
     if (ew == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -115,7 +115,7 @@ OPENPTS_PCR_EVENT_WRAPPER * newEventWrapper() {
 void freeEventWrapper(OPENPTS_PCR_EVENT_WRAPPER * ew) {
     /* check */
     if (ew == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -130,7 +130,7 @@ void freeEventWrapperChain(OPENPTS_PCR_EVENT_WRAPPER * ew) {
 
     /* check */
     if (ew == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -147,7 +147,7 @@ void freeEventWrapperChain(OPENPTS_PCR_EVENT_WRAPPER * ew) {
             xfree(event->rgbEvent);
         xfree(event);
     } else {
-        ERROR("freeSnapshot - NULL event\n");  // TODO(munetoh)
+        LOG(LOG_ERR, "freeSnapshot - NULL event\n");  // TODO(munetoh)
     }
     xfree(ew);
     ew = NULL;
@@ -188,15 +188,15 @@ int addEventToSnapshotBhv(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (eventWrapper->event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -233,7 +233,7 @@ int addEventToSnapshotBhv(
             /* level 0 SS is null => check Level 1 SS */
             ss = getSnapshotFromTable(ctx->ss_table, index, 1);
             if (ss == NULL) {
-                ERROR("getSnapshotFromTable(%d,1) is null", index);
+                LOG(LOG_ERR, "getSnapshotFromTable(%d,1) is null", index);
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING,
                     "[PCR%02d] Snapshot(FSM) is missing for PCR%d. "
                     "Please check the configuration file '%s'"),
@@ -252,7 +252,7 @@ int addEventToSnapshotBhv(
                 DEBUG_FSM("[PCR%02d] RM0 -> RM1 (RM0 is missing)\n", index);
             } else {
                 /* FSM is missing */
-                ERROR("getSnapshotFromTable(), FSM is null");
+                LOG(LOG_ERR, "getSnapshotFromTable(), FSM is null");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_FSM_MISSING,
                     "[RM01-PCR%02d] FSM is missing for PCR%d, Level 1. "
                     "Please check the configuration file '%s'"),
@@ -272,7 +272,7 @@ int addEventToSnapshotBhv(
             ss = getSnapshotFromTable(ctx->ss_table, index, 1);
             if (ss == NULL) {
                 /* SS is missing */
-                ERROR("getSnapshotFromTable(), ss is null");
+                LOG(LOG_ERR, "getSnapshotFromTable(), ss is null");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_2,
                     "[PCR%02d] Snapshot is missing for PCR%d for Level 0 and 1. "
                     "Please check the configuration file '%s'"),
@@ -291,7 +291,7 @@ int addEventToSnapshotBhv(
                 active_level = 1;
             } else {
                 /* FSM is missing*/
-                ERROR("getSnapshotFromTable(), FSM is null");
+                LOG(LOG_ERR, "getSnapshotFromTable(), FSM is null");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_FSM_MISSING_2,
                     "[RM01-PCR%02d] FSM is missing for PCR%d, Level 1. Please check the configuration file '%s'"),
                     index,
@@ -305,7 +305,7 @@ int addEventToSnapshotBhv(
         ss = getSnapshotFromTable(ctx->ss_table, index, 1);
         if (ss == NULL) {
             /* SS is missing */
-            ERROR("getSnapshotFromTable(), ss is null");
+            LOG(LOG_ERR, "getSnapshotFromTable(), ss is null");
             addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_6,
                 "[RM%02d-PCR%02d] Snapshot is missing for PCR%d, Level %d. Please check the configuration file '%s'"),
                 active_level,
@@ -319,7 +319,7 @@ int addEventToSnapshotBhv(
         /* check FSM */
         if (ss->fsm_behavior == NULL) {
             /* FSm is missing */
-            ERROR("getSnapshotFromTable(), FSM is null");
+            LOG(LOG_ERR, "getSnapshotFromTable(), FSM is null");
             addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_FSM_MISSING_3,
                 "[RM%02d-PCR%02d] FSM is missing for PCR%d, Level %d. Please check the configuration file '%s'"),
                 active_level,
@@ -333,7 +333,7 @@ int addEventToSnapshotBhv(
         /* OK, the BHV-FSM exists at Level 1*/
 
     } else {
-        ERROR("level >1 is TBD, pcr=%d level=%d\n", index, active_level);
+        LOG(LOG_ERR, "level >1 is TBD, pcr=%d level=%d\n", index, active_level);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -348,7 +348,7 @@ int addEventToSnapshotBhv(
         DEBUG("[RM%02d-PCR%02d] updateFsm() => OPENPTS_FSM_ERROR   ===>  rc=PTS_INVALID_SNAPSHOT, added Reason\n",
             active_level, index);
         if (ss->fsm_behavior->curr_state == NULL) {
-            ERROR("ss->fsm_behavior->curr_state == NULL");
+            LOG(LOG_ERR, "ss->fsm_behavior->curr_state == NULL");
             addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_VALIDATION_FAILED,
                            "[RM%02d-PCR%02d] IML validation by FSM has failed. State='%s' at the FSM is '%s'"),
                 active_level,
@@ -356,13 +356,13 @@ int addEventToSnapshotBhv(
                 "unknown",
                 ss->fsm_behavior->uml_file);
         } else if (ss->fsm_behavior->curr_state->name == NULL) {
-            ERROR("ss->fsm_behavior->curr_state->name == NULL");
+            LOG(LOG_ERR, "ss->fsm_behavior->curr_state->name == NULL");
             // TODO
         } else if (ss->fsm_behavior->uml_file == NULL) {
-            ERROR("ss->fsm_behavior->uml_file == NULL");
+            LOG(LOG_ERR, "ss->fsm_behavior->uml_file == NULL");
             // TODO
         } else {
-            ERROR("IML validation by FSM has failed.");
+            LOG(LOG_ERR, "IML validation by FSM has failed.");
             addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_VALIDATION_FAILED,
                            "[RM%02d-PCR%02d] IML validation by FSM has failed. State='%s' at the FSM is '%s'"),
                 active_level,
@@ -403,7 +403,7 @@ int addEventToSnapshotBhv(
         /* this event is migrated to target PCR, remove from this SS (did not put the EW chain) */
         goto end;
     } else {
-        ERROR("updateFsm rc=%d\n", rc);
+        LOG(LOG_ERR, "updateFsm rc=%d\n", rc);
     }
 
 
@@ -447,15 +447,15 @@ int addEventToSnapshotBin(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (eventWrapper->event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -474,7 +474,7 @@ int addEventToSnapshotBin(
 
         /* check next level (1) */
         if (ss == NULL) {
-            ERROR("addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n",index, active_level);
+            LOG(LOG_ERR, "addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n",index, active_level);
             addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_3, "[PCR%02d] Snapshot(FSM) is missing"),
                 index);
             ctx->ss_table->error[index] = PTS_INTERNAL_ERROR;
@@ -505,19 +505,19 @@ int addEventToSnapshotBin(
             DEBUG_FSM("addEventToSnapshotBin() - No trans, return PTS_INVALID_SNAPSHOT\n");
             // TODO Broken FSM - 20110115 SM under ARU test
             if (ss->fsm_binary == NULL) {
-                ERROR("ss->fsm_binary == NULLn");
+                LOG(LOG_ERR, "ss->fsm_binary == NULLn");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_IR_VALIDATION_FAILED_1,
                                 "[RM%02d-PCR%02d-MissingFSM] IR validation by RM has failed"),
                     active_level,
                     index);
             } else if (ss->fsm_binary->curr_state == NULL) {
-                ERROR("ss->fsm_binary->curr_state == NULL\n");
+                LOG(LOG_ERR, "ss->fsm_binary->curr_state == NULL\n");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_IR_VALIDATION_FAILED_2,
                                 "[RM%02d-PCR%02d-MissingState] IR validation by RM has failed"),
                     active_level,
                     index);
             } else if (ss->fsm_binary->curr_state->name == NULL) {
-                ERROR("ss->fsm_binary->curr_state->name == NULL\n");
+                LOG(LOG_ERR, "ss->fsm_binary->curr_state->name == NULL\n");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_IR_VALIDATION_FAILED_3,
                                 "[RM%02d-PCR%02d-MissingStateName] IR validation by RM has failed"),
                     active_level,
@@ -540,7 +540,7 @@ int addEventToSnapshotBin(
             /* check the next level */
             ss = getSnapshotFromTable(ctx->ss_table, index, 1);
             if (ss == NULL) {
-                ERROR("no BIN-FSM at level 0,  no SS at level 1\n");
+                LOG(LOG_ERR, "no BIN-FSM at level 0,  no SS at level 1\n");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_4,
                     "[PCR%02d] Snapshot(FSM) is missing"),
                     index);
@@ -556,14 +556,14 @@ int addEventToSnapshotBin(
                 /* Update with new SS */
                 ss = getSnapshotFromTable(ctx->ss_table, index, 1);  // TODO new func for next
                 if (ss == NULL) {
-                    ERROR("getSnapshotFromTable(%d,%d) is NULL\n", index, 1);
+                    LOG(LOG_ERR, "getSnapshotFromTable(%d,%d) is NULL\n", index, 1);
                     return PTS_INTERNAL_ERROR;
                 } else {
                     eventWrapper->snapshot = ss;
                     rc = updateFsm(ctx, ss->fsm_binary, eventWrapper);
                     if (rc == OPENPTS_FSM_ERROR) {
                         DEBUG_FSM("No trans, return PTS_INVALID_SNAPSHOT at %s\n", ss->fsm_binary->curr_state->name);
-                        ERROR("updateFsm fail\n");
+                        LOG(LOG_ERR, "updateFsm fail\n");
                         addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_IR_VALIDATION_FAILED_5,
                                   "[RM%02d-PCR%02d-%s] IR validation by RM has failed"),
                                   active_level + 1,
@@ -574,7 +574,7 @@ int addEventToSnapshotBin(
                     }
                 }
             } else {
-                ERROR("no BIN-FSM at level 0,  no BIN-FSM at level 1\n");
+                LOG(LOG_ERR, "no BIN-FSM at level 0,  no BIN-FSM at level 1\n");
                 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_5,
                           "[PCR%02d] Snapshot(FSM) is missing"),
                           index);
@@ -622,7 +622,7 @@ int flashSnapshot(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -641,13 +641,13 @@ int flashSnapshot(
     /* Get Snapshot */
     ss = getSnapshotFromTable(ctx->ss_table, index, active_level);
     if (ss == NULL) {
-        ERROR("No Snapshot at PCR[%d]. level %d\n", index, active_level);
+        LOG(LOG_ERR, "No Snapshot at PCR[%d]. level %d\n", index, active_level);
         // return PTS_INTERNAL_ERROR;
         // TODO 2011-05-02
         active_level++;
         ss = getSnapshotFromTable(ctx->ss_table, index, active_level);
         if (ss == NULL) {
-            ERROR("No Snapshot at PCR[%d], level %d\n", index, active_level);
+            LOG(LOG_ERR, "No Snapshot at PCR[%d], level %d\n", index, active_level);
             return PTS_INTERNAL_ERROR;
         } else {
             DEBUG("Skip Null SS level. level = %d\n", active_level);
@@ -661,7 +661,7 @@ int flashSnapshot(
             ss_lv0 = ss;
             ss = getSnapshotFromTable(ctx->ss_table, index, 1);
             if (ss == NULL) {
-                ERROR("PCR[%d] level 1 SS is null\n", index);
+                LOG(LOG_ERR, "PCR[%d] level 1 SS is null\n", index);
                 return PTS_INTERNAL_ERROR;
             }
 
@@ -671,20 +671,20 @@ int flashSnapshot(
                 setActiveSnapshotLevel(ctx->ss_table, index, 1);
                 active_level = 1;
             } else {
-                ERROR("level 1 BHV-FSM is null\n");
+                LOG(LOG_ERR, "level 1 BHV-FSM is null\n");
                 return PTS_INTERNAL_ERROR;
             }
         }
     } else if (active_level == 1) {
         /* use level 1 snapshot */
         if (ss->fsm_binary == NULL) {
-            ERROR("Missing BIB-FSM pcr=%d,level=%d, ss=%p -> %p\n",
+            LOG(LOG_ERR, "Missing BIB-FSM pcr=%d,level=%d, ss=%p -> %p\n",
                 index, active_level, ss_lv0, ss);
             // printeventWrapper(eventWrapper);
             return PTS_INTERNAL_ERROR;
         }
     } else {
-        ERROR("level %d is not supported yet\n", active_level);
+        LOG(LOG_ERR, "level %d is not supported yet\n", active_level);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -722,12 +722,12 @@ int flashSnapshot(
         DEBUG_FSM("updateFsm, OPENPTS_FSM_SUCCESS => PCR[%d] level == %d\n",
             index, getActiveSnapshotLevel(ctx->ss_table, index));
     } else if (rc == OPENPTS_FSM_ERROR) {
-        ERROR("flashSnapshot - updateFsm fail, rc = %d\n", rc);
+        LOG(LOG_ERR, "flashSnapshot - updateFsm fail, rc = %d\n", rc);
     } else if (rc == OPENPTS_FSM_ERROR_LOOP) {
         // IMA's last
         // DEBUG("flashSnapshot - updateFsm looped - end of the IMA IML, rc = %d\n", rc);
     } else {
-        ERROR("flashSnapshot - updateFsm rc=%d\n", rc);
+        LOG(LOG_ERR, "flashSnapshot - updateFsm rc=%d\n", rc);
     }
 
     DEBUG_CAL("flashSnapshot - done\n");
@@ -769,7 +769,7 @@ int getIml(OPENPTS_CONTEXT * ctx, int option) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -778,27 +778,27 @@ int getIml(OPENPTS_CONTEXT * ctx, int option) {
 
     /* check SS table */
     if (ctx->ss_table == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Create failed rc=0x%x\n", result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Connect failed rc=0x%x\n", result);
         goto close;
     }
 
     /* Get TPM handles */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -806,7 +806,7 @@ int getIml(OPENPTS_CONTEXT * ctx, int option) {
     /* Get Log */
     result = Tspi_TPM_GetEventLog(hTPM, &ulEventNumber, &pcrEvents);
     if (result != TSS_SUCCESS) {  // ERROR
-        ERROR("ERROR: Tspi_TPM_GetEventLog failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_TPM_GetEventLog failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -881,13 +881,13 @@ int getIml(OPENPTS_CONTEXT * ctx, int option) {
                 rc = addEventToSnapshotBhv(ctx, ew_new);  // iml.c
             } else {
                 /* Unknwon error */
-                ERROR("getIml - addEventToSnapshotBhv rc = %d\n", rc);
+                LOG(LOG_ERR, "getIml - addEventToSnapshotBhv rc = %d\n", rc);
             }
 
             /* TPM Extend */
             rc = extendTpm(&ctx->tpm, ew_new->event);
             if (rc < 0) {
-                ERROR("getIml - extendTpm fail\n");
+                LOG(LOG_ERR, "getIml - extendTpm fail\n");
                 goto free;
             }
         }
@@ -937,7 +937,7 @@ UINT32 freadUint32(FILE * stream, int endian) {
 
     /* check */
     if (stream == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0xFFFFFFFF;
     }
 
@@ -945,7 +945,7 @@ UINT32 freadUint32(FILE * stream, int endian) {
     size = fread(&data, 1, 4, stream);
 
     if (size != 4) {
-        // This is EOF ERROR("\n");
+        // This is EOF LOG(LOG_ERR, "\n");
         return 0xFFFFFFFF;  // TODO
     }
 
@@ -1014,17 +1014,17 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* open file */
     if ((fp = fopen(filename, "rb")) == NULL) {
-        ERROR("%s missing", filename);
+        LOG(LOG_ERR, "%s missing", filename);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1056,7 +1056,7 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
 
         event = (TSS_PCR_EVENT *) xmalloc(sizeof(TSS_PCR_EVENT));
         if (event == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
@@ -1070,13 +1070,13 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
         event->ulPcrValueLength = SHA1_DIGEST_SIZE;
         event->rgbPcrValue = (BYTE *) xmalloc(SHA1_DIGEST_SIZE);  // leaked
         if (event->rgbPcrValue == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
         size = fread(event->rgbPcrValue, 1, SHA1_DIGEST_SIZE, fp);
         if (size != SHA1_DIGEST_SIZE) {  // TODO(munetoh) SHA1 only
-            ERROR("BIOS IML File %s, bad pcr size %d at %d event\n",
+            LOG(LOG_ERR, "BIOS IML File %s, bad pcr size %d at %d event\n",
                 filename, (int)size, i);
             rc = PTS_INTERNAL_ERROR;
             goto close;
@@ -1094,14 +1094,14 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
         }
         /* malloc EventData */
         if ((event->rgbEvent = xmalloc_assert(eventLength)) == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
         // TODO if rgbevent is huge 0x4000000 #=> check the endian
         size = fread(event->rgbEvent, 1, eventLength, fp);
         if (size != eventLength) {
-            ERROR("BIOS IML File %s, bad eventdata size 0x%x != 0x%x at %d event\n",
+            LOG(LOG_ERR, "BIOS IML File %s, bad eventdata size 0x%x != 0x%x at %d event\n",
                 filename, (int)size, (int)eventLength, i);
             rc = PTS_INTERNAL_ERROR;
             goto close;
@@ -1111,7 +1111,7 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
         ew_new = (OPENPTS_PCR_EVENT_WRAPPER *)
             xmalloc(sizeof(OPENPTS_PCR_EVENT_WRAPPER));
         if (ew_new == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
@@ -1140,7 +1140,7 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
                 /* SKIP */
             } else {
                 /* Unknwon error */
-                ERROR("getBiosImlFile - addEventToSnapshotBhv rc = %d\n", rc);
+                LOG(LOG_ERR, "getBiosImlFile - addEventToSnapshotBhv rc = %d\n", rc);
             }
         } else {  // USE_BIN_FSM
             /* BIN-FSM - map to the snapshot */
@@ -1154,24 +1154,24 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
                 DEBUG_FSM("\tTransit to next FSM ======================================\n");
                 result = addEventToSnapshotBin(ctx, ew_new);  // iml.c
                 if (result < 0) {  // TODO
-                    TODO("getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
+                    LOG(LOG_TODO, "getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
                 }
             } else if (result == OPENPTS_FSM_FINISH_WO_HIT) {
                 DEBUG_FSM("\tTransit to next FSM ======================================\n");
                 result = addEventToSnapshotBin(ctx, ew_new);  // iml.c
                 if (result < 0) {  // TODO
-                    TODO("getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
+                    LOG(LOG_TODO, "getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
                 }
             } else {
                 /* Unknwon error */
-                ERROR("getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
+                LOG(LOG_ERR, "getBiosImlFile - addEventToSnapshotBin rc = %d\n", rc);
             }
         }
 
         /* TPM Extend */
         result = extendTpm(&ctx->tpm, ew_new->event);
         if (result != PTS_SUCCESS) {
-            ERROR("extend TPM fail\n");
+            LOG(LOG_ERR, "extend TPM fail\n");
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -1188,7 +1188,7 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
 
   close:
     if (fclose(fp) == EOF) {
-        ERROR("BIOS IML File %s, read fail\n", filename);
+        LOG(LOG_ERR, "BIOS IML File %s, read fail\n", filename);
         rc = PTS_INTERNAL_ERROR;
     }
     DEBUG("read BIOS IML, file %s => %d events\n", filename, ctx->ss_table->event_num);
@@ -1410,17 +1410,17 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* open file */
     if ((fp = fopen(filename, "rb")) == NULL) {
-        ERROR("readImaImlFile - file open was failed, [%s]\n", filename);
+        LOG(LOG_ERR, "readImaImlFile - file open was failed, [%s]\n", filename);
         return -1;
     }
 
@@ -1439,7 +1439,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             break;
         }
         if (pcr_index > MAX_PCRNUM) {
-            ERROR("Linux-IMA IML File %s, bad pcr index value %d at %d event\n",
+            LOG(LOG_ERR, "Linux-IMA IML File %s, bad pcr index value %d at %d event\n",
                 filename, pcr_index, i);
             rc = PTS_INTERNAL_ERROR;
             goto close;
@@ -1448,7 +1448,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
         /* alloc event structure */
         event = (TSS_PCR_EVENT *) xmalloc(sizeof(TSS_PCR_EVENT));
         if (event == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
@@ -1464,7 +1464,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read type */
             size = fread(&event->eventType, 1, 4, fp);
             if (size != 4) {
-                ERROR("Linux-IMA(ORIGINAL) IML File %s, bad eventType at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(ORIGINAL) IML File %s, bad eventType at %d event\n",
                     filename, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1474,13 +1474,13 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             event->ulPcrValueLength = SHA1_DIGEST_SIZE;
             event->rgbPcrValue = (BYTE *) xmalloc(SHA1_DIGEST_SIZE);
             if (event->rgbPcrValue == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 rc = PTS_FATAL;
                 goto close;
             }
             size = fread(event->rgbPcrValue, 1, SHA1_DIGEST_SIZE, fp);
             if (size != SHA1_DIGEST_SIZE) {
-                ERROR("Linux-IMA(ORIGINAL) IML File %s, bad pcr size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(ORIGINAL) IML File %s, bad pcr size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1489,14 +1489,14 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read eventdata length */
             size = fread(&event->ulEventLength, 1, 4, fp);
             if (size != 4) {
-                ERROR("Linux-IMA(ORIGINAL) IML File %s, bad event length size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(ORIGINAL) IML File %s, bad event length size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
             /* alloc eventdata */
             if ((event->rgbEvent = xmalloc(event->ulEventLength)) == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 rc = PTS_FATAL;
                 goto close;
             }
@@ -1505,7 +1505,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read filename */
             size = fread(event->rgbEvent, 1, event->ulEventLength, fp);
             if (size != event->ulEventLength) {
-                ERROR("Linux-IMA(ORIGINAL) IML File %s, bad event size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(ORIGINAL) IML File %s, bad event size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1515,7 +1515,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read type */
             size = fread(&event_type, 1, 4, fp);
             if (size != 4) {
-                ERROR("Linux-IMA(IMA_31) IML File %s, bad eventType at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(IMA_31) IML File %s, bad eventType at %d event\n",
                     filename, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1525,13 +1525,13 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             event->ulPcrValueLength = SHA1_DIGEST_SIZE;
             event->rgbPcrValue = (BYTE *) xmalloc(SHA1_DIGEST_SIZE);
             if (event->rgbPcrValue == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 rc = PTS_FATAL;
                 goto close;
             }
             size = fread(event->rgbPcrValue, 1, SHA1_DIGEST_SIZE, fp);
             if (size != SHA1_DIGEST_SIZE) {
-                ERROR("Linux-IMA(IMA_31) IML File %s, bad pcr size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(IMA_31) IML File %s, bad pcr size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1540,7 +1540,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read Template length */
             size = fread(&template_len, 1, 4, fp);
             if (size != 4) {
-                ERROR("Linux-IMA(IMA_31) IML File %s, bad template size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(IMA_31) IML File %s, bad template size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1551,7 +1551,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             event->ulEventLength = 20 + 256;  // TODO(munetoh)
             event->rgbEvent = xmalloc(event->ulEventLength);
             if (event->rgbEvent == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 rc = PTS_FATAL;
                 goto close;
             }
@@ -1560,7 +1560,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read Template digest */
             size = fread(event->rgbEvent, 1, SHA1_DIGEST_SIZE, fp);
             if (size != SHA1_DIGEST_SIZE) {
-                ERROR("Linux-IMA(IMA_31) IML File %s, bad event size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(IMA_31) IML File %s, bad event size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1571,7 +1571,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read filename */
             size = fread(&event->rgbEvent[20], 1, filename_len, fp);
             if (size != filename_len) {
-                ERROR("Linux-IMA(IMA_31) IML File %s, bad event size %d != %dat %d event\n",
+                LOG(LOG_ERR, "Linux-IMA(IMA_31) IML File %s, bad event size %d != %dat %d event\n",
                     filename, (int)size, (int)filename_len, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1581,14 +1581,14 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             event->ulPcrValueLength = SHA1_DIGEST_SIZE;
             event->rgbPcrValue = (BYTE *) xmalloc_assert(SHA1_DIGEST_SIZE);
             if (event->rgbPcrValue == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 rc = PTS_FATAL;
                 goto close;
             }
 
             size = fread(event->rgbPcrValue, 1, SHA1_DIGEST_SIZE, fp);
             if (size != SHA1_DIGEST_SIZE) {
-                ERROR("Linux-IMA() IML File %s, bad pcr size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA() IML File %s, bad pcr size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
@@ -1597,14 +1597,14 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read Template type length */
             size = fread(&template_type_len, 1, 4, fp);
             if (size != 4) {
-                ERROR("Linux-IMA() IML File %s, bad template size %d at %d event\n",
+                LOG(LOG_ERR, "Linux-IMA() IML File %s, bad template size %d at %d event\n",
                     filename, size, i);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
 
             if (template_type_len >= TEMPLATE_TYPE_SIZE) {
-                ERROR("template_type_len %d(0x%x) is too big\n", template_type_len, template_type_len);
+                LOG(LOG_ERR, "template_type_len %d(0x%x) is too big\n", template_type_len, template_type_len);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1613,7 +1613,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* read Template type */
             size = fread(&buf, 1, template_type_len, fp);
             if (size != template_type_len) {
-                ERROR("missing\n");
+                LOG(LOG_ERR, "missing\n");
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1629,7 +1629,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
                 event->ulEventLength = 20 + 256;  // TODO(munetoh)
                 event->rgbEvent = xmalloc(event->ulEventLength);
                 if (event->rgbEvent == NULL) {
-                    ERROR("no memory");
+                    LOG(LOG_ERR, "no memory");
                     rc = PTS_FATAL;
                     goto close;
                 }
@@ -1638,7 +1638,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
                 /* read Template digest */
                 size = fread(event->rgbEvent, 1, SHA1_DIGEST_SIZE, fp);
                 if (size != SHA1_DIGEST_SIZE) {
-                    ERROR("missing\n");
+                    LOG(LOG_ERR, "missing\n");
                     rc = PTS_INTERNAL_ERROR;
                     goto close;
                 }
@@ -1646,13 +1646,13 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
                 /* read filename len */
                 size = fread(&filename_len, 1, 4, fp);
                 if (size != 4) {
-                    ERROR("missing\n");
+                    LOG(LOG_ERR, "missing\n");
                     rc = PTS_INTERNAL_ERROR;
                     goto close;
                 }
 
                 if (filename_len > 255) {
-                    ERROR("filename_len is too big, %d, 0x%x\n", filename_len, filename_len);
+                    LOG(LOG_ERR, "filename_len is too big, %d, 0x%x\n", filename_len, filename_len);
                     rc = PTS_INTERNAL_ERROR;
                     goto close;
                 }
@@ -1662,13 +1662,13 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
                 /* read filename */
                 size = fread(&event->rgbEvent[20], 1, filename_len, fp);
                 if (size != filename_len) {
-                    ERROR("missing\n");
+                    LOG(LOG_ERR, "missing\n");
                     rc = PTS_INTERNAL_ERROR;
                     goto close;
                 }
 
             } else {
-                ERROR("Unknown template [%s]\n", buf);
+                LOG(LOG_ERR, "Unknown template [%s]\n", buf);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1679,7 +1679,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
         ew = (OPENPTS_PCR_EVENT_WRAPPER *)
             xmalloc(sizeof(OPENPTS_PCR_EVENT_WRAPPER));
         if (ew == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             rc = PTS_FATAL;
             goto close;
         }
@@ -1699,7 +1699,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* map to the snapshot */
             result = addEventToSnapshotBhv(ctx, ew_last);  // iml.c
             if (result != PTS_SUCCESS) {
-                ERROR("readImaImlFile - addEventToSnapshotBhv fail, rc = %d\n", rc);
+                LOG(LOG_ERR, "readImaImlFile - addEventToSnapshotBhv fail, rc = %d\n", rc);
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1707,7 +1707,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
             /* map to the snapshot */
             result = addEventToSnapshotBin(ctx, ew_last);  // iml.c
             if (result != PTS_SUCCESS) {
-                ERROR("readImaImlFile - addEventToSnapshotBin fail\n");
+                LOG(LOG_ERR, "readImaImlFile - addEventToSnapshotBin fail\n");
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1718,7 +1718,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
         /* TPM Extend */
         result = extendTpm(&ctx->tpm, ew_last->event);
         if (result !=0) {
-            ERROR("extend TPM fail\n");
+            LOG(LOG_ERR, "extend TPM fail\n");
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -1737,7 +1737,7 @@ int readImaImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int type, int mo
     fclose(fp);
 
     // DEBUG("iml.c - getBiosImlFile - done, %d events\n", event_num);
-    // ERROR("SS LEVEL %d  == 1?, ss->event_num =%d\n",ss->level,ss->event_num );
+    // LOG(LOG_ERR, "SS LEVEL %d  == 1?, ss->event_num =%d\n",ss->level,ss->event_num );
     DEBUG("read IMA IML, file %s => %d events\n", filename, event_num);
     DEBUG_CAL("readImaImlFile - done, %d events\n", event_num);
 
@@ -1774,11 +1774,11 @@ int setPcrsToSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_PCRS *pcrs) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (pcrs == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1846,20 +1846,20 @@ int getPcr(OPENPTS_CONTEXT * ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Create failed rc=0x%x\n", result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Connect failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -1867,7 +1867,7 @@ int getPcr(OPENPTS_CONTEXT * ctx) {
     /* Get TPM handles */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -1881,7 +1881,7 @@ int getPcr(OPENPTS_CONTEXT * ctx) {
                 &blobLength,
                 &blob);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_TPM_GetCapability failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_TPM_GetCapability failed rc=0x%x\n", result);
         goto free;
     }
 
@@ -1893,7 +1893,7 @@ int getPcr(OPENPTS_CONTEXT * ctx) {
         result = Tspi_TPM_PcrRead(hTPM, i, &blobLength, &blob);
 
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: Tspi_TPM_PcrRead failed rc=0x%x\n", result);
+            LOG(LOG_ERR, "ERROR: Tspi_TPM_PcrRead failed rc=0x%x\n", result);
             pcrNum = 0;
             goto free;
         }
@@ -1957,7 +1957,7 @@ BYTE hex2byte(char *buf, int offset) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -1986,17 +1986,17 @@ int getPcrBySysfsFile(OPENPTS_CONTEXT * ctx, const char *filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* open */
     if ((fp = fopen(filename, "r")) == NULL) {
-        TODO("getPcrBySysfsFile - pcr file is %s missing  -- ignore in test\n", filename);
+        LOG(LOG_TODO, "getPcrBySysfsFile - pcr file is %s missing  -- ignore in test\n", filename);
         return -1;  // TODO
     }
 
@@ -2053,7 +2053,7 @@ int validatePcr(OPENPTS_CONTEXT * ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -2105,7 +2105,7 @@ void printEventWrapper(OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
 
     /* check */
     if (eventWrapper == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -2118,7 +2118,7 @@ void printEventWrapper(OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
         }
         OUTPUT("eventdata[%4d]\n", event->ulEventLength);
     } else {
-        ERROR("NULL event\n");  // TODO(munetoh)
+        LOG(LOG_ERR, "NULL event\n");  // TODO(munetoh)
     }
 }
 
@@ -2134,7 +2134,7 @@ void printSnapshotsInfo(OPENPTS_CONTEXT * ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -2159,7 +2159,7 @@ void printSnapshotsInfo(OPENPTS_CONTEXT * ctx) {
         if (ss != NULL) {
             OUTPUT(" %6d\n", ss->event_num);
             level1_num += ss->event_num;
-            if (ss->level != 1) ERROR("bad level %d\n", ss->level);
+            if (ss->level != 1) LOG(LOG_ERR, "bad level %d\n", ss->level);
         } else {
             OUTPUT("\n");
         }
index df5c8ea..b4b2ea3 100644 (file)
@@ -95,58 +95,60 @@ void printFsmInfo2(OPENPTS_CONTEXT *ctx) {
     int level0_num = 0;
     int level1_num = 0;
 
-    printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENT, "Number of events\n"
-           "PCR Level0 Level1\n"));
-    printf("--------------------------\n");
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENT,
+        "Number of events\n"
+        "PCR Level0 Level1\n"));
+    OUTPUT("--------------------------\n");
 
     for (i = 0; i < MAX_PCRNUM; i++) {
-        printf("%2d ", i);
+        OUTPUT("%2d ", i);
         ss = getSnapshotFromTable(ctx->ss_table, i, 0);
         if (ss == NULL) {
-            printf(" ----- - - ");
+            OUTPUT(" ----- - - ");
         } else {
-            printf(" %p ", ss);
-            if (ss->fsm_behavior != NULL) printf(" O ");
-            else                          printf(" X ");
+            OUTPUT(" %p ", ss);
+            if (ss->fsm_behavior != NULL) OUTPUT(" O ");
+            else                          OUTPUT(" X ");
 
-            if (ss->fsm_binary   != NULL) printf(" O ");
-            else                          printf(" X ");
+            if (ss->fsm_binary   != NULL) OUTPUT(" O ");
+            else                          OUTPUT(" X ");
 
             /* level 1 */
             ss = getSnapshotFromTable(ctx->ss_table, i, 1);
             if (ss != NULL) {
-                printf("  ");
-                printf(" %p ", ss);
-                if (ss->fsm_behavior != NULL) printf(" O ");
-                else                          printf(" X ");
+                OUTPUT("  ");
+                OUTPUT(" %p ", ss);
+                if (ss->fsm_behavior != NULL) OUTPUT(" O ");
+                else                          OUTPUT(" X ");
 
-                if (ss->fsm_binary   != NULL) printf(" O ");
-                else                          printf(" X ");
+                if (ss->fsm_binary   != NULL) OUTPUT(" O ");
+                else                          OUTPUT(" X ");
             }
         }
 
-        printf("\n");
+        OUTPUT("\n");
     }
-    printf("---------------------------\n");
-    printf("level 0 total = %d\n", level0_num);
-    printf("level 1 total = %d\n", level1_num);
-    printf("---------------------------\n");
+    OUTPUT("---------------------------\n");
+    OUTPUT("level 0 total = %d\n", level0_num);
+    OUTPUT("level 1 total = %d\n", level1_num);
+    OUTPUT("---------------------------\n");
 }
 
 /**
  * usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IML2AIDE_USAGE, "OpenPTS command\n\n"
-                    "Usage: iml2aide [options]\n\n"
-                    "Options:\n"
-                    "  -c filename           Set config file\n"
-                    "  -i filename           Set IMA IML file. default, get IML via TSS\n"
-                    "  -r filename           Set AIDE DB file as reference of fullpathname\n"
-                    "  -o filename           Set output file (AIDE DB format, gziped)\n"
-                    "  -w filename           Set output file (Ignore name list, plain text format)\n"
-                    "  -h                    Show this help message\n"
-                    "\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_USAGE,
+        "OpenPTS command\n\n"
+        "Usage: iml2aide [options]\n\n"
+        "Options:\n"
+        "  -c filename           Set config file\n"
+        "  -i filename           Set IMA IML file. default, get IML via TSS\n"
+        "  -r filename           Set AIDE DB file as reference of fullpathname\n"
+        "  -o filename           Set output file (AIDE DB format, gziped)\n"
+        "  -w filename           Set output file (Ignore name list, plain text format)\n"
+        "  -h                    Show this help message\n"
+        "\n"));
 }
 
 /**
@@ -212,13 +214,13 @@ int main(int argc, char *argv[]) {
     /* ctx */
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("Internal Error\n");
+        LOG(LOG_ERR, "Internal Error\n");
         return -1;
     }
 
     ctx = newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("Internal Error\n");
+        LOG(LOG_ERR, "Internal Error\n");
         return -1;
     }
 
@@ -228,7 +230,7 @@ int main(int argc, char *argv[]) {
     /* FSM */
     rc = readFsmFromPropFile(ctx, config_filename);
     if (rc != PTS_SUCCESS) {
-        ERROR("read FSM failed\n");
+        LOG(LOG_ERR, "read FSM failed\n");
         printFsmInfo2(ctx);
     }
 
@@ -244,10 +246,10 @@ int main(int argc, char *argv[]) {
 
         rc = loadAideDatabaseFile(ctx->aide_ctx, aideref_filename);  // ir.c
         if (rc < 0) {
-            ERROR("Internal Error, load AIDE DB() was failed\n");
+            LOG(LOG_ERR, "Internal Error, load AIDE DB() was failed\n");
             return -1;
         }
-        printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE,
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE,
             "AIDE Database(ref): %d entries (< %s)\n"), rc, aideref_filename);
 
         /* set flags */
@@ -261,7 +263,8 @@ int main(int argc, char *argv[]) {
     if (ima_filename == NULL) {
         /* IML -> TSS -> Struct */
         rc = getIml(ctx, 0);
-        printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS, "IML: %d events (< TSS)\n"), rc);
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS,
+            "IML: %d events (< TSS)\n"), rc);
     } else {
         int count;
         /* IML(file) -> Struct */
@@ -271,13 +274,14 @@ int main(int argc, char *argv[]) {
                 ima_type, 0, &count);
 
         if (rc != PTS_SUCCESS) {
-            ERROR("Internal Error, raild atr ead IMA's IML\n");
+            LOG(LOG_ERR, "Internal Error, raild atr ead IMA's IML\n");
             return -1;
         }
-        printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS_2, "IML: %d events (< %s)\n"), rc, ima_filename);
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS_2,
+            "IML: %d events (< %s)\n"), rc, ima_filename);
     }
     if (rc < 0) {
-        ERROR("Internal Error\n");
+        LOG(LOG_ERR, "Internal Error\n");
         return -1;
     }
 
@@ -290,16 +294,16 @@ int main(int argc, char *argv[]) {
         rc = writeReducedAidbDatabase(ctx->aide_ctx, aide_filename);
     }
     if (rc < 0) {
-        ERROR("Internal Error\n");
+        LOG(LOG_ERR, "Internal Error\n");
         return -1;
     }
 
-    printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE_2,
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE_2,
         "AIDE Database      : %d entries (> %s) \n"), rc, aide_filename);
 
     if (ignorelist_filename != NULL) {
         rc = writeAideIgnoreList(ctx, ignorelist_filename);
-        printf(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_IGN_LIST,
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_IGN_LIST,
             "Ignore list  : %d entries (> %s) \n"), rc, ignorelist_filename);
     }
 
index 3fdad59..cc38b75 100644 (file)
@@ -773,7 +773,7 @@ EventData
                     len,
                     &b64buf_len);
                 if (b64buf == NULL) {
-                    ERROR("encodeBase64 fail");
+                    LOG(LOG_ERR, "encodeBase64 fail");
                 } else {
                     fprintf(fp, ", base64(%s)", b64buf);
                     fprintf(fp, "]");
@@ -852,7 +852,7 @@ TSS_RESULT getEventLog(char *filename, int endian, int aligned, UINT32 *event_nu
 
     /* check */
     if (filename == NULL) {
-        ERROR("filename is NULL\n");
+        LOG(LOG_ERR, "filename is NULL\n");
         return TSS_E_INTERNAL_ERROR;
     }
 
@@ -911,7 +911,7 @@ TSS_RESULT getEventLog(char *filename, int endian, int aligned, UINT32 *event_nu
         }
         size = fread(ew->event->rgbPcrValue, 1, SHA1_DIGEST_SIZE, fp);
         if (size != SHA1_DIGEST_SIZE) {  // TODO(munetoh) SHA1 only
-            ERROR("SHA1 only");
+            LOG(LOG_ERR, "SHA1 only");
             rc =  TSS_E_INTERNAL_ERROR;
             goto close;
         }
@@ -924,7 +924,7 @@ TSS_RESULT getEventLog(char *filename, int endian, int aligned, UINT32 *event_nu
         /* EventData len */
         size = fread(&eventLength, 1, 4, fp);
         if (size != 4) {
-            ERROR("fread NG\n");
+            LOG(LOG_ERR, "fread NG\n");
             rc =  TSS_E_INTERNAL_ERROR;
             goto close;
         }
@@ -952,7 +952,7 @@ TSS_RESULT getEventLog(char *filename, int endian, int aligned, UINT32 *event_nu
         }
         size = fread(ew->event->rgbEvent, 1, aligned_length, fp);
         if (size != aligned_length) {
-            ERROR("fread NG, size = %d != %d (@PCR[%d])\n",
+            LOG(LOG_ERR, "fread NG, size = %d != %d (@PCR[%d])\n",
                 (unsigned int) size,
                 (unsigned int) ew->event->ulEventLength,
                 pcrIndex);
@@ -1037,7 +1037,7 @@ TSS_RESULT getEventLog(char *filename, int endian, int aligned, UINT32 *event_nu
  * Usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IML2TEXT_USAGE,
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2TEXT_USAGE,
         "OpenPTS command\n\n"
         "Usage: iml2text [options]\n\n"
         "Options:\n"
@@ -1122,7 +1122,8 @@ int main(int argc, char *argv[]) {
             usage();
             return 0;
         default:
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IML2TEXT_BAD_OPTION_C, "bad option '%c'\n"), c);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_IML2TEXT_BAD_OPTION_C,
+                "bad option '%c'\n"), c);
             usage();
             return -1;
         }
@@ -1153,14 +1154,14 @@ int main(int argc, char *argv[]) {
         /* in both cases, we have to connect to TCSD */
         result = Tspi_Context_Create(&hContext);
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n",
+            LOG(LOG_ERR, "ERROR: Tspi_Context_Create failed rc=0x%x\n",
                    result);
             goto close;
         }
 
         result = Tspi_Context_Connect(hContext, SERVER);
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n",
+            LOG(LOG_ERR, "ERROR: Tspi_Context_Connect failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1168,7 +1169,7 @@ int main(int argc, char *argv[]) {
         /* Get TPM handles */
         result = Tspi_Context_GetTpmObject(hContext, &hTPM);
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
+            LOG(LOG_ERR, "ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1182,7 +1183,7 @@ int main(int argc, char *argv[]) {
                     &ulEventNumber,
                     &PcrEvents);
         if (result != TSS_SUCCESS) {  // ERROR
-            ERROR("ERROR: Tspi_TPM_GetEventLog failed rc=0x%x\n",
+            LOG(LOG_ERR, "ERROR: Tspi_TPM_GetEventLog failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1190,7 +1191,7 @@ int main(int argc, char *argv[]) {
         /* Get EventLog File */
         result = getEventLog(filename, endian, aligned, &ulEventNumber, &PcrEvents);
         if (result != TSS_SUCCESS) {  // ERROR
-            ERROR("getEventLog failed rc=0x%x\n",
+            LOG(LOG_ERR, "getEventLog failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1259,7 +1260,7 @@ int main(int argc, char *argv[]) {
             // actual
             result = Tspi_TPM_PcrRead(hTPM, i, &blobLength, &blob);
             if (result != TSS_SUCCESS) {  // ERROR
-                ERROR("PrcRead failed rc=0x%x\n",
+                LOG(LOG_ERR, "PrcRead failed rc=0x%x\n",
                        result);
                 goto free;
             }
index 8a031cc..519c71a 100644 (file)
--- a/src/imv.c
+++ b/src/imv.c
@@ -164,19 +164,19 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
 
     /* */
     if (initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_ALREADY_INITIALIZED;
     }
 
     /* Only support version 1 */
     if ((minVersion < TNC_IFIMV_VERSION_1 ) ||
         (maxVersion > TNC_IFIMV_VERSION_1)) {
-        ERROR("TNC_RESULT_NO_COMMON_VERSION\n");
+        LOG(LOG_ERR, "TNC_RESULT_NO_COMMON_VERSION\n");
         return TNC_RESULT_NO_COMMON_VERSION;
     }
 
     if (!pOutActualVersion) {
-        ERROR("TNC_RESULT_INVALID_PARAMETER\n");
+        LOG(LOG_ERR, "TNC_RESULT_INVALID_PARAMETER\n");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -186,14 +186,14 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
     /* initialize PTS */
     conf =  newPtsConfig();
     if (conf == NULL) {
-        ERROR("Can not allocate OPENPTS_CONFIG\n");
+        LOG(LOG_ERR, "Can not allocate OPENPTS_CONFIG\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
 
     ctx =  newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("Can not allocate OPENPTS_CONTEXT\n");
+        LOG(LOG_ERR, "Can not allocate OPENPTS_CONTEXT\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
@@ -201,7 +201,7 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
     /* configure PTS Verifier (System wide) */
     rc = readPtsConfig(conf, PTSV_CONFIG_FILE);
     if (rc != PTS_SUCCESS) {
-        ERROR("read config file, '%s' was failed - abort\n",
+        LOG(LOG_ERR, "read config file, '%s' was failed - abort\n",
             PTSV_CONFIG_FILE);
         rc = TNC_RESULT_FATAL;
         goto error;
@@ -214,14 +214,14 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
         /* 1st use?,  create new UUID */
         rc = genOpenptsUuid(conf->uuid);
         if (rc != PTS_SUCCESS) {
-            ERROR("generation of UUID was failed\n");
+            LOG(LOG_ERR, "generation of UUID was failed\n");
             rc = TNC_RESULT_FATAL;
             goto error;
         }
         /* save to the file */
         rc = writeOpenptsUuidFile(conf->uuid, 1);
         if (rc != PTS_SUCCESS) {
-            ERROR("Creation of UUID file, %s was failed\n",
+            LOG(LOG_ERR, "Creation of UUID file, %s was failed\n",
                 conf->uuid->filename);
             rc = TNC_RESULT_FATAL;
             goto error;
@@ -269,12 +269,12 @@ TNC_IMV_API TNC_Result TNC_IMV_NotifyConnectionChange(
     DEBUG("TNC_IMV_NotifyConnectionChange\n");
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     if (imvID != imv_id)
-        ERROR("imvID != imv_id");
+        LOG(LOG_ERR, "imvID != imv_id");
         return TNC_RESULT_INVALID_PARAMETER;
 
     DEBUG_IFM("V    imvID=%d, connectionID=%d - TNC_IMV_NotifyConnectionChange\n",
@@ -375,7 +375,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
         messageLength, (int)messageType);
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
@@ -390,7 +390,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
         read_tlv = (PTS_IF_M_Attribute*)messageBuffer;  // NBO
 
         if (read_tlv == NULL) {
-            ERROR("null input");
+            LOG(LOG_ERR, "null input");
             return TNC_RESULT_FATAL;
         }
 
@@ -399,7 +399,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
         vid += read_tlv->vid[1] << 8;
         vid += read_tlv->vid[2];
         if (vid != TNC_VENDORID_OPENPTS) {
-            ERROR("read_tlv->vid = 0x%X (!= 0x%X)",
+            LOG(LOG_ERR, "read_tlv->vid = 0x%X (!= 0x%X)",
                 vid, TNC_VENDORID_OPENPTS);
             return TNC_RESULT_FATAL;
         }
@@ -411,7 +411,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
 
         /* check length */
         if (messageLength != (TNC_UInt32) (12 + length)) {
-            ERROR("Bad message %d != %d\n",
+            LOG(LOG_ERR, "Bad message %d != %d\n",
                 messageLength, 12 + length);
             return TNC_RESULT_FATAL;
         }
@@ -425,7 +425,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             DEBUG_IFM("[C->V] OPENPTS_CAPABILITIES[%d]\n", 12 + length);
             if (ctx->tnc_state != TNC_STATE_START) {
                 /* Bad message order */
-                ERROR("Bad message order state=%d != %d, type=%08x",
+                LOG(LOG_ERR, "Bad message order state=%d != %d, type=%08x",
                     ctx->tnc_state, TNC_STATE_START, type);
                 return TNC_RESULT_FATAL;
             }
@@ -496,10 +496,10 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
                     /* then allow the 1st connection */
                     enrollment = 1;
                 } else if (conf->enrollment == IMV_ENROLLMENT_CREDENTIAL) {
-                    TODO("TBD\n");
+                    LOG(LOG_TODO, "TBD\n");
                     return rc;
                 } else {
-                    ERROR("Collector is not initialized yet\n");
+                    LOG(LOG_ERR, "Collector is not initialized yet\n");
                     return rc;
                 }
             } else if (rc != PTS_SUCCESS) {
@@ -541,7 +541,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
                 ctx->nonce->nonce = xmalloc_assert(20);
                 rc = getRandom(ctx->nonce->nonce, 20);
                 if (rc != PTS_SUCCESS) {
-                    ERROR("getRandom() fail\n");
+                    LOG(LOG_ERR, "getRandom() fail\n");
                 }
 
                 ctx->tnc_state = TNC_STATE_NONCE;
@@ -574,7 +574,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             // TODO check the state
 
             if (ctx->target_conf == NULL) {
-                ERROR("Bad sequence\n");
+                LOG(LOG_ERR, "Bad sequence\n");
             } else {
                 /* PUBKEY -> target_conf */
                 ctx->target_conf->pubkey_length = length;
@@ -610,7 +610,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             /* save to the file, UUID/UUID/rmN.xml*/
             rc = verifierHandleRimmSet(ctx, value);
             if (rc != PTS_SUCCESS) {
-                ERROR("verifierHandleRimmSet() fail\n");
+                LOG(LOG_ERR, "verifierHandleRimmSet() fail\n");
                 return TNC_RESULT_FATAL;
             }
 
@@ -625,7 +625,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             ctx->nonce->nonce = xmalloc_assert(20);
             rc = getRandom(ctx->nonce->nonce, 20);
             if (rc != PTS_SUCCESS) {
-                ERROR("getRandom() fail\n");
+                LOG(LOG_ERR, "getRandom() fail\n");
             }
 
             ctx->tnc_state = TNC_STATE_NONCE_ENROLL;
@@ -664,14 +664,14 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
                 mode = OPENPTS_VERIFY_MODE;
             } else {
                 /* BAD STATE */
-                ERROR("bad state");
+                LOG(LOG_ERR, "bad state");
             }
 
 
             /* verify */
             rc = verifierHandleIR(ctx, length, value, mode, &result);
             if (rc != PTS_SUCCESS) {
-                ERROR("verifierHandleIR() fail rc = %d\n", rc);
+                LOG(LOG_ERR, "verifierHandleIR() fail rc = %d\n", rc);
                 // 25 PTS_INVALID_SNAPSHOT?
                 // return TNC_RESULT_FATAL;
             }
@@ -679,23 +679,23 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             // TODO create
             break;
         case OPENPTS_ERROR:
-            ERROR("The corrector returns ERROR message");
+            LOG(LOG_ERR, "The corrector returns ERROR message");
             // TODO invalid
             result = OPENPTS_RESULT_UNKNOWN;
             // break;
             return TNC_RESULT_FATAL;
         default:
-            ERROR("Unknown type %08X", type);
+            LOG(LOG_ERR, "Unknown type %08X", type);
             result = OPENPTS_RESULT_UNKNOWN;
             break;
         }
         return rc;
     } else if (messageType == ((TNC_VENDORID_TCG_PEN << 8) | TNC_SUBTYPE_TCG_PTS)) {
         /* TCG */
-        ERROR("TBD\n");
+        LOG(LOG_ERR, "TBD\n");
         return TNC_RESULT_FATAL;
     } else {
-        ERROR("bad msg from collector");
+        LOG(LOG_ERR, "bad msg from collector");
         return TNC_RESULT_FATAL;
     }
 
@@ -750,12 +750,12 @@ TNC_IMV_API TNC_Result TNC_IMV_SolicitRecommendation(
     DEBUG("TNC_IMV_SolicitRecommendation\n");
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     if (imvID != imv_id) {
-        ERROR("Bad ID");
+        LOG(LOG_ERR, "Bad ID");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -771,7 +771,7 @@ TNC_IMV_API TNC_Result TNC_IMV_SolicitRecommendation(
         recommendation = TNC_IMV_ACTION_RECOMMENDATION_ISOLATE;
         evaluation     = TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR;
     } else if (result == OPENPTS_RESULT_INVALID) {
-        TODO("verifier() result      : INVALID");
+        LOG(LOG_TODO, "verifier() result      : INVALID");
         str            = (TNC_BufferReference)"invalid";
         recommendation = TNC_IMV_ACTION_RECOMMENDATION_ISOLATE;
         evaluation     = TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR;
@@ -853,12 +853,12 @@ TNC_IMV_API TNC_Result TNC_IMV_BatchEnding(
     DEBUG("TNC_IMV_BatchEnding\n");
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     if (imvID != imv_id) {
-        ERROR("imvID != imv_id");
+        LOG(LOG_ERR, "imvID != imv_id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -877,12 +877,12 @@ TNC_IMV_API TNC_Result TNC_IMV_Terminate(
     DEBUG("TNC_IMV_Terminate\n");
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     if (imvID != imv_id) {
-        ERROR("Bad id");
+        LOG(LOG_ERR, "Bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -911,7 +911,7 @@ static TNC_Result reportMessageTypes(
     DEBUG("reportMessageTypes %d\n", (int)imvID);
 
     if (!reportMessageTypesPtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -935,7 +935,7 @@ static TNC_Result sendMessage(
     DEBUG("sendMessage\n");
 
     if (!sendMessagePtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -984,7 +984,7 @@ static TNC_Result provideRecommendation(
     DEBUG("provideRecommendation\n");
 
     if (!provideRecommendationPtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -1038,7 +1038,7 @@ static TNC_Result setAttribute(
     DEBUG("setAttribute\n");
 
     if (!setAttributePtr) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TNC_RESULT_FATAL;
     }
 
@@ -1065,12 +1065,12 @@ TNC_IMV_API TNC_Result TNC_IMV_ProvideBindFunction(
     DEBUG("TNC_IMV_ProvideBindFunction\n");
 
     if (!initialized) {
-        ERROR("Not initialized");
+        LOG(LOG_ERR, "Not initialized");
         return TNC_RESULT_NOT_INITIALIZED;
     }
 
     if (imvID != imv_id) {
-        ERROR("Bad id");
+        LOG(LOG_ERR, "Bad id");
         return TNC_RESULT_INVALID_PARAMETER;
     }
 
@@ -1079,39 +1079,39 @@ TNC_IMV_API TNC_Result TNC_IMV_ProvideBindFunction(
         if ((*bindFunction)(imvID, "TNC_TNCS_ReportMessageTypes",
                             (void**)&reportMessageTypesPtr) !=
                 TNC_RESULT_SUCCESS) {
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
         if ((*bindFunction)(imvID, "TNC_TNCS_RequestHandshakeRetry",
                             (void**)&requestHandshakeRetryPtr) !=
                 TNC_RESULT_SUCCESS) {
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
         if ((*bindFunction)(imvID, "TNC_TNCS_ProvideRecommendation",
                             (void**)&provideRecommendationPtr) !=
                 TNC_RESULT_SUCCESS) {
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
         if ((*bindFunction)(imvID, "TNC_TNCS_SendMessage",
                             (void**)&sendMessagePtr) !=
                 TNC_RESULT_SUCCESS) {
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
         if ((*bindFunction)(imvID, "TNC_TNCS_GetAttribute",
                             (void**)&getAttributePtr) !=
                 TNC_RESULT_SUCCESS) {
             // TODO(munetoh) optional
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
         if ((*bindFunction)(imvID, "TNC_TNCS_SetAttribute",
                             (void**)&setAttributePtr) !=
                 TNC_RESULT_SUCCESS) {
             // TODO(munetoh) optional
-            ERROR("TBD");
+            LOG(LOG_ERR, "TBD");
             return TNC_RESULT_FATAL;
         }
     }
@@ -1122,7 +1122,7 @@ TNC_IMV_API TNC_Result TNC_IMV_ProvideBindFunction(
             TNC_RESULT_SUCCESS) {
         return TNC_RESULT_SUCCESS;
     } else {
-        ERROR("TBD");
+        LOG(LOG_ERR, "TBD");
         return TNC_RESULT_FATAL;
     }
 }
index 50b7bbb..6baa7ff 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -87,12 +87,12 @@ void displayXmlError(int errorIndex, int rc) {
 
     /* check */
     if (errorIndex >= XML_FUNC_END) {
-        ERROR("errorIndex(%d) > XML_FUNC_END(%d)",errorIndex, XML_FUNC_END);
+        LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)",errorIndex, XML_FUNC_END);
         return;
     }
 
     /* log */
-    ERROR("XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
+    LOG(LOG_ERR, "XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
 }
 
 /**
@@ -109,7 +109,7 @@ int freeAllFsm(OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -168,14 +168,14 @@ OPENPTS_IR_CONTEXT *newIrContext() {
 
     ctx = (OPENPTS_IR_CONTEXT *) xmalloc(sizeof(OPENPTS_IR_CONTEXT));
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(ctx, 0, sizeof(OPENPTS_IR_CONTEXT));
 
     ctx->buf = xmalloc(EVENTDATA_BUF_SIZE);
     if (ctx->buf == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         xfree(ctx);
         return NULL;
     }
@@ -193,7 +193,7 @@ OPENPTS_IR_CONTEXT *newIrContext() {
 void freeIrContext(OPENPTS_IR_CONTEXT *ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -227,7 +227,7 @@ int writeComponentID(
 
     /* check */
     if (cid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -449,7 +449,7 @@ int writeStuffObjects(
 
     /* check */
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -564,7 +564,7 @@ int writeStuffObjects(
             goto error;
         }
     } else {
-        // printf("SM DEBUG no eventdata\n");
+        // no eventdata
     }
 
     /* Close the element named "stuff:Objects". */
@@ -577,7 +577,7 @@ int writeStuffObjects(
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeStuffObjects() XML ERROR\n");
+    LOG(LOG_ERR, "writeStuffObjects() XML ERROR\n");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -612,11 +612,11 @@ int writePcrHash(
 
     /* check */
     if (startHash == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (hash == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -680,7 +680,6 @@ int writePcrHash(
     /* Write a text */
     rc = xmlTextWriterWriteBase64(writer, (const char *) hash, 0, 20);
     if (rc < 0) {
-        // printf("SM DEBUG ERROR  digest len %d \n", 20);
         displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
         goto error;
     }
@@ -720,15 +719,15 @@ int writeSnapshot(
 
     /* check */
     if (tpm == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (cid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     level = ss->level;
@@ -737,7 +736,7 @@ int writeSnapshot(
     /* reset PCR */
     // FSM resetPCR(n) exist
     if (ss->reset_pcr == 1) {
-        TODO("reset PCR[%d]\n", index);
+        LOG(LOG_TODO, "reset PCR[%d]\n", index);
         resetTpmPcr(tpm, index);
     }
 
@@ -759,13 +758,13 @@ int writeSnapshot(
     /* new UUID */
     ir_uuid = newUuid();
     if (ir_uuid == NULL) {
-        ERROR("UUID \n");
+        LOG(LOG_ERR, "UUID \n");
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
     str_ir_uuid = getStringOfUuid(ir_uuid);
     if (str_ir_uuid == NULL) {
-        ERROR("UUID \n");
+        LOG(LOG_ERR, "UUID \n");
         rc = PTS_INTERNAL_ERROR;
         xfree(ir_uuid);
         goto error;
@@ -823,7 +822,7 @@ int writeSnapshot(
     eventWrapper = ss->start;
 
     if (eventWrapper == NULL) {
-        ERROR("writeSnapshot- eventWrapper is NULL\n");
+        LOG(LOG_ERR, "writeSnapshot- eventWrapper is NULL\n");
         rc = PTS_FATAL;
         goto free;
     }
@@ -857,7 +856,7 @@ int writeSnapshot(
     /* set curr PCR value */
     rc = getTpmPcrValue(tpm, index, ss->curr_pcr);
     if (rc != PTS_SUCCESS) {
-        ERROR("getTpmPcrValue() fail");
+        LOG(LOG_ERR, "getTpmPcrValue() fail");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -868,7 +867,7 @@ int writeSnapshot(
     /* add PcrHash element */
     rc = writePcrHash(writer, index, level, ss->start_pcr, ss->curr_pcr, ALGTYPE_SHA1);
     if (rc != PTS_SUCCESS) {
-        ERROR("writePcrHash() fail");
+        LOG(LOG_ERR, "writePcrHash() fail");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -939,15 +938,15 @@ int writeQuote(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx->pcrs == NULL) {
-        TODO("writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+        LOG(LOG_TODO, "writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
         return PTS_FATAL;
     }
     if (ctx->validation_data == NULL) {
-        TODO("writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+        LOG(LOG_TODO, "writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
         return PTS_FATAL;
     }
 
@@ -1001,7 +1000,7 @@ int writeQuote(
         select_byte[2] = select_int & 0xFF;
     } else {
         // TODO
-        ERROR(" PCR NUM != 24\n");
+        LOG(LOG_ERR, " PCR NUM != 24\n");
     }
 
     /* Start an element named "PcrSelection" as child of PcrComposit. */
@@ -1025,12 +1024,12 @@ int writeQuote(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");  // TODO ERROR => displayXmlError
+        LOG(LOG_ERR, "encodeBase64 fail");  // TODO ERROR => displayXmlError
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1040,7 +1039,7 @@ int writeQuote(
     /* Close the element named "PcrSelection". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1112,7 +1111,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMajor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMajor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1120,7 +1119,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMinor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMinor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1128,7 +1127,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMajor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMajor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1137,7 +1136,7 @@ int writeQuote(
     snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMinor);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMinor", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1145,7 +1144,7 @@ int writeQuote(
     /* Add an attribute with name "Fixed", int */
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST "QUOT");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return -1;
     }
@@ -1156,7 +1155,7 @@ int writeQuote(
         20,
         &b64buf_len);  // ctx->validation_data->ulDataLength);
     if (b64buf == NULL) {
-        ERROR("encodeBase64() fail");
+        LOG(LOG_ERR, "encodeBase64() fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DigestValue", BAD_CAST b64buf);
@@ -1175,12 +1174,12 @@ int writeQuote(
         ctx->validation_data->ulExternalDataLength,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64() fail");
+        LOG(LOG_ERR, "encodeBase64() fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1190,7 +1189,7 @@ int writeQuote(
     /* Close the element named "QuoteInfo". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1198,7 +1197,7 @@ int writeQuote(
     /* Close the element named "Quote". */
     rc = xmlTextWriterEndElement(writer);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterEndElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
         displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1310,15 +1309,15 @@ int writeQuote2(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx->pcrs == NULL) {
-        TODO("writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+        LOG(LOG_TODO, "writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
         return PTS_FATAL;
     }
     if (ctx->validation_data == NULL) {
-        TODO("writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+        LOG(LOG_TODO, "writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
         return PTS_FATAL;
     }
 
@@ -1398,13 +1397,13 @@ int writeQuote2(
         ctx->validation_data->ulExternalDataLength,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
     free(b64buf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1412,7 +1411,7 @@ int writeQuote2(
     /* PcrInfoShort - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrInfoShort");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1420,7 +1419,7 @@ int writeQuote2(
     /* PcrSelection - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1428,7 +1427,7 @@ int writeQuote2(
     snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1438,7 +1437,7 @@ int writeQuote2(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
@@ -1468,7 +1467,7 @@ int writeQuote2(
         20,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CompositeHash", "%s", b64buf);
@@ -1482,7 +1481,7 @@ int writeQuote2(
     /* PcrComposite - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1490,7 +1489,7 @@ int writeQuote2(
     /* PcrSelection - start */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterStartElement\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
         displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1498,7 +1497,7 @@ int writeQuote2(
     snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
     if (rc < 0) {
-        // ERROR("Error at xmlTextWriterWriteAttribute\n");
+        // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
         return PTS_INTERNAL_ERROR;
     }
@@ -1508,7 +1507,7 @@ int writeQuote2(
         size_of_select,
         &b64buf_len);
     if (b64buf == NULL) {
-        ERROR("encodeBase64 fail");
+        LOG(LOG_ERR, "encodeBase64 fail");
         return PTS_INTERNAL_ERROR;
     }
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
@@ -1535,7 +1534,7 @@ int writeQuote2(
             /* PcrValue - start */
             rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
             if (rc < 0) {
-                // ERROR("Error at xmlTextWriterStartElement\n");
+                // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
                 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1543,7 +1542,7 @@ int writeQuote2(
             snprintf(tagbuf, sizeof(tagbuf), "%d", i);
             rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
             if (rc < 0) {
-                // ERROR("Error at xmlTextWriterWriteAttribute\n");
+                // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
                 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
                 return PTS_INTERNAL_ERROR;
             }
@@ -1715,7 +1714,7 @@ int writeIr(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1763,7 +1762,7 @@ int writeIr(
     /* Create a new XML buffer */
     xmlbuf = xmlBufferCreate();
     if (xmlbuf == NULL) {
-        ERROR("creating the xml buffer fail\n");
+        LOG(LOG_ERR, "creating the xml buffer fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
@@ -1771,7 +1770,7 @@ int writeIr(
     /* Create a new XmlWriter for memory */
     writer = xmlNewTextWriterMemory(xmlbuf, 0);
     if (writer == NULL) {
-        ERROR("creating the xml writer fail\n");
+        LOG(LOG_ERR, "creating the xml writer fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
@@ -1839,14 +1838,14 @@ int writeIr(
     /* generate UUID */
     ir_uuid = newUuid();
     if (ir_uuid == NULL) {
-        ERROR("fail UUID generation\n");
+        LOG(LOG_ERR, "fail UUID generation\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
 
     str_ir_uuid = getStringOfUuid(ir_uuid);
     if (str_ir_uuid == NULL) {
-        ERROR("fail UUID generation\n");
+        LOG(LOG_ERR, "fail UUID generation\n");
         rc = PTS_INTERNAL_ERROR;
         xfree(ir_uuid);
         goto freexml;
@@ -1875,13 +1874,13 @@ int writeIr(
     /* Quote*/
     if (ctx->conf->iml_mode == 0) {
         if (ctx->conf->ir_without_quote == 1) {
-            TODO("skip TPM_Quote\n");
+            LOG(LOG_TODO, "skip TPM_Quote\n");
         } else {
             if (ctx->conf->tpm_quote_type == 1) {
                 /* Quote */
                 rc = writeQuote(writer, ctx);
                 if (rc < 0) {
-                    ERROR("writeIr - writeQuote() rc = %d\n", rc);
+                    LOG(LOG_ERR, "writeIr - writeQuote() rc = %d\n", rc);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1889,7 +1888,7 @@ int writeIr(
                 /* Quote2 */
                 rc = writeQuote2(writer, ctx);
                 if (rc < 0) {
-                    ERROR("writeIr - writeQuote2() rc = %d\n", rc);
+                    LOG(LOG_ERR, "writeIr - writeQuote2() rc = %d\n", rc);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1908,8 +1907,7 @@ int writeIr(
         if (ss != NULL) {
             if (ss->event_num > 0) {
                 // level 0
-                // printf("DEBUG add level %d snapshot for PCR%d\n",ss->level, i);
-                // ERROR("writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
+                // LOG(LOG_ERR, "writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
                 writeSnapshot(writer, &tpm, &cid, i, ss);
             }
         }
@@ -1918,7 +1916,7 @@ int writeIr(
         ss = getSnapshotFromTable(ctx->ss_table, i, 1);
         if (ss != NULL) {
             if (ss->event_num > 0) {
-                // ERROR("writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
+                // LOG(LOG_ERR, "writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
                 // writeSnapshot(writer, &tpm, &cid, i, ss);
                 if (i == OPENPTS_PCR_INDEX) {
                     DEBUG("genIr - Not writing snapshot for OPENPTS_PCR_INDEX (%d)\n",
@@ -1940,7 +1938,7 @@ int writeIr(
 
     rc = xmlTextWriterFlush(writer);
     if (rc < 0) {
-        // ERROR("writeRm: Error at xmlTextWriterFlush\n");
+        // LOG(LOG_ERR, "writeRm: Error at xmlTextWriterFlush\n");
         displayXmlError(TEXT_WRITER_FLUSH, rc);
         rc = PTS_INTERNAL_ERROR;
         goto free;
@@ -1949,7 +1947,7 @@ int writeIr(
     /* Close all elements */
     rc = xmlTextWriterEndDocument(writer);
     if (rc < 0) {
-        ERROR("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
+        LOG(LOG_ERR, "testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1964,7 +1962,7 @@ int writeIr(
         char buf[1024];
         /* use default filename */
         if (ctx->conf->ir_dir == NULL) {
-            ERROR("Set ir.dir in %s.\n", ctx->conf->config_file);
+            LOG(LOG_ERR, "Set ir.dir in %s.\n", ctx->conf->config_file);
             ctx->conf->ir_dir = smalloc("/tmp/.ptsc");
         }
         snprintf(buf, sizeof(buf), "%s_%s.xml",
@@ -1983,7 +1981,7 @@ int writeIr(
 
     irFd = open(filenameDP, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
     if (-1 == irFd) {
-        ERROR("Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
+        LOG(LOG_ERR, "Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1994,14 +1992,14 @@ int writeIr(
        serious hackers probably wouldn't be deterred by this ... */
     if (NULL != savedFd &&
         -1 == unlink(filenameDP)) {
-        ERROR("Failed to unlink file '%s', errno = %d\n", filename, errno);
+        LOG(LOG_ERR, "Failed to unlink file '%s', errno = %d\n", filename, errno);
     }
 
     lengthOfIrFile = xmlbuf->use;
     {
         int writeRc = write(irFd, xmlbuf->content, lengthOfIrFile);
         if ( lengthOfIrFile != writeRc ) {
-            ERROR("Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
+            LOG(LOG_ERR, "Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
             rc = PTS_INTERNAL_ERROR;
             close(irFd);
         } else {
@@ -2067,7 +2065,7 @@ void  irStartDocument(void * ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -2084,11 +2082,9 @@ void  irStartDocument(void * ctx) {
 void  irEndDocument(void * ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
-
-    // printf("END DOC \n");
 }
 
 /* This prevents real world buffer over-run attacks using malformed IRs
@@ -2100,7 +2096,7 @@ static int getPcrIndexFromIR(char *value) {
 
     /* check */
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -2128,22 +2124,22 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     ir_ctx = pctx->ir_ctx;
     if (ir_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pcrs = pctx->pcrs;
     if (pcrs == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     validation_data = pctx->validation_data;  // ckeck later
@@ -2171,33 +2167,31 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         //
     } else if (!strcmp((char *)name, "pcrindex")) {
         /* stuff:Hash -> PCR value (base64) */
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_PCR_INDEX;
 
     } else if (!strcmp((char *)name, "eventtype")) {
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_EVENT_TYPE;
 
     } else if (!strcmp((char *)name, "stuff:Hash")) {
-        // printf("START ELEMENT [%s]  <<<< DIGEST \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< DIGEST \n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_DIGEST;
 
     } else if (!strcmp((char *)name, "eventdata")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_EVENT_DATA;
 
     } else if (!strcmp((char *)name, "PcrHash")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ir_ctx->sax_state = IR_SAX_STATE_PCR;
 
         /* get Number =pcrindex) attribute ( */
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "Number")) {
                         ir_ctx->pcr_index = getPcrIndexFromIR(value);
                     }
@@ -2246,10 +2240,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "SizeOfSelect")) {
                         /* TPM1.2 - 24 PCRS -> 3 */
                         pcrs->pcr_select_size = atoi(value);
@@ -2259,7 +2251,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                     if (!strcmp(type, "PcrSelect")) {
                         /* used later */
                         if (b64buf != NULL) {
-                            ERROR("bad memory management");
+                            LOG(LOG_ERR, "bad memory management");
                             free(b64buf);
                         }
                         b64buf = (BYTE *) decodeBase64(
@@ -2269,7 +2261,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                         // attr_cnt++;
                         // DEBUG("PcrSelect = 0x%02x %02x %02x \n", buf[0],buf[1],buf[2]);
                         if (b64buf == NULL) {
-                            ERROR("Failed to decode base64 string\n");
+                            LOG(LOG_ERR, "Failed to decode base64 string\n");
                             ir_ctx->sax_error++;
                             pcrs->pcr_select_size = 0;
                         } else {
@@ -2291,14 +2283,14 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                 if (b64buf != NULL) {
                     memcpy(pcrs->pcr_select_byte, b64buf, pcrs->pcr_select_size);
                 } else {
-                    ERROR("pcr_select_byte is missing");
+                    LOG(LOG_ERR, "pcr_select_byte is missing");
                 }
             } else {
-                ERROR("no memory\n");
+                LOG(LOG_ERR, "no memory\n");
             }
         } else {
             /* BAD IR */
-            ERROR("BAD IR SizeOfSelect or PcrSelect are missing\n");
+            LOG(LOG_ERR, "BAD IR SizeOfSelect or PcrSelect are missing\n");
         }
         /* free Base64 buffer */
         if (b64buf != NULL) {
@@ -2315,10 +2307,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "PcrNumber")) {
                         ir_ctx->pcr_index = getPcrIndexFromIR(value);
                     }
@@ -2338,7 +2328,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                 type = (char *)atts[i++];
 
                 if (validation_data == NULL) {
-                    ERROR("validation_data == NULL");
+                    LOG(LOG_ERR, "validation_data == NULL");
                     return;
                 }
                 if (validation_data->rgbData == NULL) {
@@ -2347,10 +2337,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                     validation_data->rgbData = xmalloc_assert(48);
                 }
 
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "VersionMajor")) {
                         validation_data->versionInfo.bMajor = atoi(value);
                         validation_data->rgbData[0] = atoi(value);
@@ -2381,14 +2369,14 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;  // TODO  return?
                         }
                         if (b64buf_len == 20) {
                             memcpy(&validation_data->rgbData[8], b64buf, 20);
                         } else {
-                            ERROR("size of decodeBase64 out is not 20 but %d", b64buf_len);
+                            LOG(LOG_ERR, "size of decodeBase64 out is not 20 but %d", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2401,7 +2389,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2415,7 +2403,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             // memcpy(validation_data->rgbExternalData, buf, rc);
                             memcpy(&validation_data->rgbData[28], b64buf, 20);
                         } else {
-                            ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+                            LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2430,7 +2418,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                 type = (char *)atts[i++];
 
                 if (validation_data == NULL) {
-                    ERROR("validation_data == NULL");
+                    LOG(LOG_ERR, "validation_data == NULL");
                     return;
                 }
                 if (validation_data->rgbData == NULL) {
@@ -2439,10 +2427,8 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                     validation_data->rgbData = xmalloc_assert(52);
                 }
 
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "Tag")) {
                         int tag = atoi(value);
                         validation_data->rgbData[0] = (tag >> 8) & 0xFF;
@@ -2461,7 +2447,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             strlen(value),
                             &b64buf_len);
                         if (b64buf == NULL) {
-                            ERROR("decodeBase64 fail");
+                            LOG(LOG_ERR, "decodeBase64 fail");
                             ir_ctx->sax_error++;
                             return;
                         }
@@ -2471,7 +2457,7 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                             // memcpy(validation_data->rgbExternalData, b64buf, rc);
                             memcpy(&validation_data->rgbData[6], b64buf, 20);
                         } else {
-                            ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+                            LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
                             ir_ctx->sax_error++;
                             return;  // TODO
                         }
@@ -2490,13 +2476,13 @@ void  irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
     } else if (!strcmp((char *)name, "SignatureMethod")) {
         // TODO check alg
     } else if (!strcmp((char *)name, "SignatureValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else if (!strcmp((char *)name, "KeyInfo")) {
         // TODO
     } else if (!strcmp((char *)name, "KeyValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else { /* Else? */
-        ERROR("START ELEMENT [%s] \n", name);
+        LOG(LOG_ERR, "START ELEMENT [%s] \n", name);
         ir_ctx->sax_state = IR_SAX_STATE_IDOL;
     }
 }
@@ -2515,22 +2501,22 @@ void irEndElement(void * ctx, const xmlChar * name) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     ir_ctx = pctx->ir_ctx;
     if (ir_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pcrs = pctx->pcrs;
     if (pcrs == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     validation_data = pctx->validation_data;  // ckeck later
@@ -2557,7 +2543,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
 
         /* set the event structure */
         if (ir_ctx->event == NULL) {
-            ERROR("internal error\n");
+            LOG(LOG_ERR, "internal error\n");
             ir_ctx->ew_new->event = NULL;
             ir_ctx->sax_error++;
         } else {
@@ -2574,7 +2560,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
         /* map to the snapshot, push FSM  */
         rc = addEventToSnapshotBin(pctx, ir_ctx->ew_new);  // iml.c
         if (rc != PTS_SUCCESS) {
-            // ERROR("validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
+            // LOG(LOG_ERR, "validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
             ir_ctx->integrity = OPENPTS_RESULT_INVALID;
             return;
         }
@@ -2596,7 +2582,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             DEBUG_FSM("irEndElement() -- SS has validation error\n");
             ir_ctx->fsm_error_count++;
         } else if (rc != PTS_SUCCESS) {
-            ERROR("SnapshotCollection -> FSM flash was fail\n");
+            LOG(LOG_ERR, "SnapshotCollection -> FSM flash was fail\n");
             ir_ctx->sax_error++;
             return;
         }
@@ -2612,7 +2598,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (ir_ctx->event->rgbPcrValue == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         } else {
@@ -2629,7 +2615,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (ir_ctx->event->rgbEvent == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         } else {
@@ -2644,12 +2630,12 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;  // TODO
         }
         if (b64buf_len > MAX_DIGEST_SIZE) {
-            ERROR("decodeBase64 out is too latge, %d > %d",
+            LOG(LOG_ERR, "decodeBase64 out is too latge, %d > %d",
                 b64buf_len, MAX_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;  // TODO
@@ -2660,7 +2646,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
         /* Check with PCR in TPM */
         rc = checkTpmPcr2(&pctx->tpm, ir_ctx->pcr_index, ir_ctx->pcr);
         if (rc != PTS_SUCCESS) {
-            ERROR("ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
+            LOG(LOG_ERR, "ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
             ir_ctx->sax_error = 1;
             // verbose = DEBUG_FLAG | DEBUG_TPM_FLAG;  // switch DEBUG MODE
             if (isDebugFlagSet(DEBUG_FLAG)) {
@@ -2679,10 +2665,10 @@ void irEndElement(void * ctx, const xmlChar * name) {
             if (pctx->conf->iml_mode == 0) {
                 if (pcrs == NULL) {
                     /* malloc OPENPTS_PCRS */
-                    // ERROR("PCR is not intialized - No QuoteData element\n");
+                    // LOG(LOG_ERR, "PCR is not intialized - No QuoteData element\n");
                     pcrs = xmalloc(sizeof(OPENPTS_PCRS));
                     if (pcrs == NULL) {
-                        ERROR("no memory\n");
+                        LOG(LOG_ERR, "no memory\n");
                         return;
                     }
                     memset(pcrs, 0, sizeof(OPENPTS_PCRS));
@@ -2699,14 +2685,14 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "LocalityAtRelease")) {
         // TODO
         if (validation_data == NULL) {
-            ERROR("validation_data == NULL");
+            LOG(LOG_ERR, "validation_data == NULL");
             return;
         }
         validation_data->rgbData[31] = atoi(ir_ctx->buf);
     } else if (!strcmp((char *)name, "CompositeHash")) {
         // DEBUG("CompositeHash %s", ir_ctx->buf);
         if (validation_data == NULL) {
-            ERROR("validation_data == NULL");
+            LOG(LOG_ERR, "validation_data == NULL");
             return;
         }
         b64buf = decodeBase64(
@@ -2714,7 +2700,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;
         }
@@ -2734,17 +2720,17 @@ void irEndElement(void * ctx, const xmlChar * name) {
             ir_ctx->char_size,
             &b64buf_len);
         if (b64buf == NULL) {
-            ERROR("decodeBase64 fail");
+            LOG(LOG_ERR, "decodeBase64 fail");
             ir_ctx->sax_error++;
             return;
         }
         if (b64buf_len < SHA1_DIGEST_SIZE) {
-            ERROR("decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
+            LOG(LOG_ERR, "decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;
         }
         if (b64buf_len > MAX_DIGEST_SIZE) {
-            ERROR("decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
+            LOG(LOG_ERR, "decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
             ir_ctx->sax_error++;
             return;
         }
@@ -2778,10 +2764,10 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "QuoteInfo2")) {
         /* pcr select => validation_data */
         if (pcrs->pcr_select_byte == NULL) {
-            ERROR("pcrs->pcr_select_byte is null");
+            LOG(LOG_ERR, "pcrs->pcr_select_byte is null");
         } else {
             if (validation_data == NULL) {
-                ERROR("validation_data == NULL");
+                LOG(LOG_ERR, "validation_data == NULL");
                 return;
             }
             validation_data->rgbData[26] = 0;
@@ -2793,11 +2779,11 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "SignatureValue")) {
         ir_ctx->buf[ir_ctx->char_size] = 0;
         if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) {  // TODO check buf size
-            ERROR("buf is small %d \n", ir_ctx->char_size);
+            LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
             ir_ctx->sax_error++;
         } else {
             if (validation_data == NULL) {
-                ERROR("validation_data == NULL");
+                LOG(LOG_ERR, "validation_data == NULL");
                 return;
             }
             if (validation_data->rgbValidationData != NULL) {
@@ -2809,7 +2795,7 @@ void irEndElement(void * ctx, const xmlChar * name) {
                 ir_ctx->char_size,
                 &b64buf_len);
             if (validation_data->rgbValidationData == NULL) {
-                ERROR("decodeBase64 fail");
+                LOG(LOG_ERR, "decodeBase64 fail");
                 ir_ctx->sax_error++;
                 return;  // TODO
             }
@@ -2818,14 +2804,14 @@ void irEndElement(void * ctx, const xmlChar * name) {
     } else if (!strcmp((char *)name, "KeyValue")) {
         ir_ctx->buf[ir_ctx->char_size] = 0;
         if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) {  // TODO check buf size
-            ERROR("buf is small %d \n", ir_ctx->char_size);
+            LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
         } else {
             pcrs->pubkey = decodeBase64(
                 (char *)ir_ctx->buf,
                 ir_ctx->char_size,
                 &b64buf_len);
             if (pcrs->pubkey == NULL) {
-                ERROR("decodeBase64 fail");
+                LOG(LOG_ERR, "decodeBase64 fail");
                 ir_ctx->sax_error++;
                 return;
             }
@@ -2836,22 +2822,22 @@ void irEndElement(void * ctx, const xmlChar * name) {
         /* Validate QuoteData */
 
         if ( ir_ctx->sax_error > 0 ) {
-            ERROR("Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
+            LOG(LOG_ERR, "Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
         } else {
             rc = validateQuoteData(pcrs, validation_data);
             // DEBUG("validateQuoteData = %d\n", rc);
             if (rc != PTS_SUCCESS) {
-                ERROR("---------------------------------------------------------------------------\n");
-                ERROR("BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!\n");
-                ERROR("---------------------------------------------------------------------------\n");
+                LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
+                LOG(LOG_ERR, "BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!  BAD QUOTE DATA!!!\n");
+                LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
                 addProperty(pctx, "tpm.quote.signature", "invalid");
                 // TODO set error
                 ir_ctx->bad_quote = 1;
             } else {
 #if 0
-                TODO("---------------------------------------------------------------------------\n");
-                TODO("GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
-                TODO("---------------------------------------------------------------------------\n");
+                LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
+                LOG(LOG_TODO, "GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
+                LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
 #endif
                 addProperty(pctx, "tpm.quote.signature", "valid");
             }
@@ -2860,7 +2846,6 @@ void irEndElement(void * ctx, const xmlChar * name) {
         pctx->conf->ir_without_quote = 0;
     } else {
         /* Else? */
-        // printf("END ELEMENT [%s] ",name);
     }
 
     ir_ctx->sax_state = IR_SAX_STATE_IDOL;
@@ -2878,17 +2863,17 @@ void irCharacters(void* ctx, const xmlChar * ch, int len) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     ir_ctx = pctx->ir_ctx;
     if (ir_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     //if (ch == NULL) {
-    //    ERROR("null input");
+    //    LOG(LOG_ERR, "null input");
     //    return;
     //}
 
@@ -2896,7 +2881,7 @@ void irCharacters(void* ctx, const xmlChar * ch, int len) {
     /* copy to buf at ir_ctx, but check length first, ensuring additional space
        for NULL terminator */
     if ((ir_ctx->char_size + len + 1) > EVENTDATA_BUF_SIZE) {
-        ERROR("Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
+        LOG(LOG_ERR, "Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
         return;
     }
     memcpy(&ir_ctx->buf[ir_ctx->char_size], ch, len);
@@ -2945,20 +2930,20 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx->target_conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx->ir_filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     conf = ctx->target_conf;
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -3005,7 +2990,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
             // DEBUG("loadSQLiteDatabaseFile %s\n", ctx->conf->aide_sqlite_filename);
             rc = loadSQLiteDatabaseFile(ctx->aide_ctx, conf->aide_sqlite_filename);
             if (rc != PTS_SUCCESS) {
-                ERROR("loadSQLiteDatabaseFile fail\n");
+                LOG(LOG_ERR, "loadSQLiteDatabaseFile fail\n");
                 rc = PTS_FATAL;
                 goto free;
             }
@@ -3015,7 +3000,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
 #endif
         } else {
             // pre loaded (see iml2aide.c)
-            TODO("AIDE DB pre loaded\n");
+            LOG(LOG_TODO, "AIDE DB pre loaded\n");
         }
 
         if (ctx->conf->aide_ignorelist_filename != NULL) {
@@ -3048,7 +3033,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
     }
 
     // DEBUG("validatePcrComposite, ctx->conf->ir_without_quote %d\n", ctx->conf->ir_without_quote);
-    // ERROR("conf->pubkey_length %d\n",conf->pubkey_length);
+    // LOG(LOG_ERR, "conf->pubkey_length %d\n",conf->pubkey_length);
 
     /* validate PCR values by QuoteData */
     if ((conf->iml_mode == 0) && (conf->ir_without_quote == 0)) {
@@ -3087,7 +3072,7 @@ int validateIr(OPENPTS_CONTEXT *ctx) {
                 addProperty(ctx, "tpm.quote.pcrs", "invalid");
             }
         } else {
-            ERROR("PUBKEY is missing\n");
+            LOG(LOG_ERR, "PUBKEY is missing\n");
             addProperty(ctx, "tpm.quote.pcrs", "unknown");
         }
     } else {
@@ -3182,7 +3167,7 @@ int genIrFromSecurityfs(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -3195,14 +3180,14 @@ int genIrFromSecurityfs(
     /* setup FSM */
     rc = readFsmFromPropFile(ctx, ctx->conf->config_file);
     if (rc != PTS_SUCCESS) {
-        ERROR("readFsmFromPropFile %s failed\n", ctx->conf->config_file);
+        LOG(LOG_ERR, "readFsmFromPropFile %s failed\n", ctx->conf->config_file);
         return PTS_INTERNAL_ERROR;
     }
 
     /* read BIOS IML */
     rc = readBiosImlFile(ctx, ctx->conf->bios_iml_filename, ctx->conf->iml_endian);
     if (rc != PTS_SUCCESS) {
-        ERROR("fail to load BIOS IML, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3212,7 +3197,7 @@ int genIrFromSecurityfs(
         rc = readImaImlFile(ctx, ctx->conf->runtime_iml_filename,
                 ctx->conf->runtime_iml_type, 0, &count);  // TODO endian?
         if (rc != PTS_SUCCESS) {
-            ERROR("fail to load IMA IML, rc = %d\n", rc);
+            LOG(LOG_ERR, "fail to load IMA IML, rc = %d\n", rc);
             return PTS_INTERNAL_ERROR;
         }
     }
@@ -3220,14 +3205,14 @@ int genIrFromSecurityfs(
     /* read PCRS */
     rc = getPcrBySysfsFile(ctx, ctx->conf->pcrs_filename);
     if (rc < 0) {
-        ERROR("fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
-        TODO("Get or Create PCR file for this testcase\n");
+        LOG(LOG_ERR, "fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
+        LOG(LOG_TODO, "Get or Create PCR file for this testcase\n");
         // return -1;
     }
 
     // do not use tempnum,
     // if (ctx->conf->ir_filename != NULL) {
-    //    ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+    //    LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
     // }
     // ctx->conf->ir_filename = tempnam(NULL, "ir_");
 
@@ -3235,7 +3220,7 @@ int genIrFromSecurityfs(
     rc = writeIr(ctx, NULL, savedFd);
     // rc = writeIr(ctx, ctx->ir_filename, savedFd);
     if (rc != 0) {
-        ERROR("fail to write IR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3256,7 +3241,7 @@ int genIrFromTss(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -3279,7 +3264,7 @@ int genIrFromTss(
     // pcrSelect is set at PCR with FSM
     rc = readFsmFromPropFile(ctx, ctx->conf->config_file);  // fsm.c
     if (rc != PTS_SUCCESS) {
-        ERROR("read FSM failed\n");
+        LOG(LOG_ERR, "read FSM failed\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3295,7 +3280,7 @@ int genIrFromTss(
         /* copy */
         ctx->validation_data->rgbExternalData = malloc(ctx->nonce->nonce_length);
         if (ctx->validation_data->rgbExternalData == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             return PTS_FATAL;
         }
         memcpy(
@@ -3303,7 +3288,7 @@ int genIrFromTss(
             ctx->nonce->nonce,
             ctx->nonce->nonce_length);
     } else {
-        ERROR("genIrFromTss - nonce is missing, DH-nonce? \n");
+        LOG(LOG_ERR, "genIrFromTss - nonce is missing, DH-nonce? \n");
         ctx->validation_data->ulExternalDataLength = 0;
         ctx->validation_data->rgbExternalData = NULL;
     }
@@ -3316,7 +3301,7 @@ int genIrFromTss(
 
 
     if (ctx->conf->ir_without_quote == 1) {
-        TODO("skip TPM_Quote\n");
+        LOG(LOG_TODO, "skip TPM_Quote\n");
     } else {
         /* TPM Quote or TPM Quote2 */
         if (ctx->conf->tpm_quote_type == 1) {
@@ -3341,7 +3326,7 @@ int genIrFromTss(
                     ctx->validation_data);  // tss.c
         }
         if (rc != 0) {
-            ERROR("quoteTss fail, rc = 0x%04d\n", rc);
+            LOG(LOG_ERR, "quoteTss fail, rc = 0x%04d\n", rc);
             return PTS_INTERNAL_ERROR;
         }
     }
@@ -3349,19 +3334,19 @@ int genIrFromTss(
     /* set PCR to snapshot */
     rc = setPcrsToSnapshot(ctx, ctx->pcrs);  // TODO
     if (rc < 0) {
-        ERROR("fail to load PCR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load PCR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
     /* get BIOS/IMA IML */
     rc = getIml(ctx, 0);
     if (rc < 0) {
-        ERROR("fail to load BIOS IML, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
     if (ctx->conf->ir_filename != NULL) {
-        ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+        LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
     }
     //ctx->conf->ir_filename = tempnam(NULL, "ir_");
     //DEBUG("ctx->conf->ir_filename : %s\n", ctx->conf->ir_filename);
@@ -3370,7 +3355,7 @@ int genIrFromTss(
     rc = writeIr(ctx, NULL, savedFd);
     // rc = writeIr(ctx, ctx->ir_filename, savedFd);  // ir.c
     if (rc != 0) {
-        ERROR("fail to write IR, rc = %d\n", rc);
+        LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -3391,7 +3376,7 @@ int genIr(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -3400,17 +3385,17 @@ int genIr(
     if (ctx->conf->iml_mode == 1) {
         rc = genIrFromSecurityfs(ctx, savedFd);
         if (rc != PTS_SUCCESS) {
-            ERROR("writePtsTlvToSock - gen IR failed\n");
+            LOG(LOG_ERR, "writePtsTlvToSock - gen IR failed\n");
             return rc;
         }
     } else {
 #ifdef CONFIG_NO_TSS
-        TODO("OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
+        LOG(LOG_TODO, "OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
 #else
         // DEBUG("get IML/PCR via TSS is not ready\n");
         rc = genIrFromTss(ctx, savedFd);
         if (rc != PTS_SUCCESS) {
-            ERROR("gen IR failed\n");
+            LOG(LOG_ERR, "gen IR failed\n");
             return rc;
         }
 #endif
index a354f3e..852d506 100644 (file)
@@ -279,7 +279,7 @@ void  irStartDocument(void * ctx) {
  * SAX parser
  */
 void  irEndDocument(void * ctx) {
-    // printf("END DOC \n");
+    // END DOC
 }
 
 /**
@@ -313,29 +313,27 @@ void  irStartElement(void* context, const xmlChar* name, const xmlChar** atts) {
         //
     } else if (!strcmp((char *)name, "pcrindex")) {
         /* stuff:Hash -> PCR value (base64) */
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ctx->sax_state = IR_SAX_STATE_PCR_INDEX;
     } else if (!strcmp((char *)name, "eventtype")) {
-        // printf("START ELEMENT [%s]  <<<< HASH HASH \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< HASH HASH \n",name);
         // ctx->sax_state = IR_SAX_STATE_EVENT_TYPE;
     } else if (!strcmp((char *)name, "stuff:Hash")) {
-        // printf("START ELEMENT [%s]  <<<< DIGEST \n",name);
+        // DEBUG("START ELEMENT [%s]  <<<< DIGEST \n",name);
         // ctx->sax_state = IR_SAX_STATE_DIGEST;
     } else if (!strcmp((char *)name, "eventdata")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ctx->sax_state = IR_SAX_STATE_EVENT_DATA;
     } else if (!strcmp((char *)name, "PcrHash")) {
-        // printf("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
+        // DEBUG("START ELEMENT [%s]  <<<<  EVENT_DATA\n",name);
         // ctx->sax_state = IR_SAX_STATE_PCR;
 
         /* get Number =pcrindex) attribute ( */
         if (atts != NULL) {
             for (i = 0;(atts[i] != NULL);i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "Number")) {
                         ctx->pcr_index = atoi(value);
                     }
@@ -365,13 +363,13 @@ void  irStartElement(void* context, const xmlChar* name, const xmlChar** atts) {
     } else if (!strcmp((char *)name, "SignatureMethod")) {
         // TODO check alg
     } else if (!strcmp((char *)name, "SignatureValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else if (!strcmp((char *)name, "KeyInfo")) {
     } else if (!strcmp((char *)name, "KeyValue")) {
-        // DONE TODO("get value(base64)\n");
+        // DONE LOG(LOG_TODO, "get value(base64)\n");
     } else {
         /* Else? */
-        ERROR("START ELEMENT [%s] \n", name);
+        LOG(LOG_ERR, "START ELEMENT [%s] \n", name);
         ctx->sax_state = IR_SAX_STATE_IDOL;
     }
 }
@@ -391,7 +389,7 @@ void irEndElement(void * context, const xmlChar * name) {
 
         /* set the event structure */
         if (ctx->event == NULL) {
-            ERROR("internal error\n");
+            LOG(LOG_ERR, "internal error\n");
             ctx->sax_error++;
         } else {
             if (ctx->binary == 0) {
@@ -434,7 +432,7 @@ void irEndElement(void * context, const xmlChar * name) {
                     if (pad_len > 0) {
                         /* add padding */
                         rc = fwrite((BYTE *)&padding, 1, pad_len, ctx->fp);  // Padding
-                        TODO("%d mod  %d => %d\n", ctx->event->ulEventLength, ctx->aligned, pad_len);
+                        LOG(LOG_TODO, "%d mod  %d => %d\n", ctx->event->ulEventLength, ctx->aligned, pad_len);
                     }
                 }
             }
@@ -458,7 +456,7 @@ void irEndElement(void * context, const xmlChar * name) {
             ctx->char_size,
             (int *)&ctx->event->ulPcrValueLength);
         if (ctx->event->rgbEvent == NULL) {
-            // ERROR()
+            // LOG(LOG_ERR, )
             ctx->event->ulPcrValueLength = 0;
         }
     } else if (!strcmp((char *)name, "eventtype")) {
@@ -471,7 +469,7 @@ void irEndElement(void * context, const xmlChar * name) {
             ctx->char_size,
             (int *)&ctx->event->ulEventLength);
         if (ctx->event->rgbEvent == NULL) {
-            // ERROR()
+            // LOG(LOG_ERR, )
             ctx->event->ulEventLength = 0;
         }
     } else if (!strcmp((char *)name, "PcrHash")) {
@@ -483,7 +481,7 @@ void irEndElement(void * context, const xmlChar * name) {
         // rc = checkTpmPcr2(&pctx->tpm, ctx->pcr_index, ctx->pcr);
 
         if (rc != 0) {
-            ERROR("ERROR PCR[%d] != IML\n", ctx->pcr_index);
+            LOG(LOG_ERR, "ERROR PCR[%d] != IML\n", ctx->pcr_index);
             ctx->sax_error = 1;
         } else {
             /* IML and PCR are consistent :-) */
@@ -495,7 +493,7 @@ void irEndElement(void * context, const xmlChar * name) {
             if (pctx->conf->iml_mode == 0) {
                 if (pcrs == NULL) {
                     /* malloc OPENPTS_PCRS */
-                    // ERROR("PCR is not intialized - No QuoteData element\n");
+                    // LOG(LOG_ERR, "PCR is not intialized - No QuoteData element\n");
                     pcrs = xmalloc(sizeof(OPENPTS_PCRS));
                     if (pcrs == NULL) {
                         return;
@@ -522,7 +520,7 @@ void irEndElement(void * context, const xmlChar * name) {
         DEBUG("ignore QuoteData\n");
     } else {
         /* Else? */
-        // printf("END ELEMENT [%s] ",name);
+        DEBUG("END ELEMENT [%s] ",name);
     }
 
     ctx->sax_state = IR_SAX_STATE_IDOL;
@@ -539,7 +537,7 @@ void irCharacters(void* context, const xmlChar * ch, int len) {
 
     /* copy to buf at ctx */
     if (ctx->char_size + len > EVENTDATA_BUF_SIZE) {
-        ERROR("Buffer for EVENTDATA is too small, %d + %d > %d\n", ctx->char_size, len, EVENTDATA_BUF_SIZE);
+        LOG(LOG_ERR, "Buffer for EVENTDATA is too small, %d + %d > %d\n", ctx->char_size, len, EVENTDATA_BUF_SIZE);
         return;
     }
     memcpy(&ctx->buf[ctx->char_size], ch, len);
@@ -580,16 +578,17 @@ int readIr(IR_CONTEXT *context, const char *filename) {
  * Usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IR2TEXT_USAGE, "OpenPTS command\n\n"
-                    "Usage: ir2text [options]\n\n"
-                    "Options:\n"
-                    "  -i filename           Set IR file\n"
-                    "  -o filename           Set output file, else stdout\n"
-                    "  -P filename           Set PCR output file (option)\n"
-                    "  -b                    Binary, (Convert IR to IML)\n"
-                    "  -E                    Enable endian conversion (BE->LE or LE->BE)\n"
-                    "  -h                    Show this help message\n"
-                    "\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_IR2TEXT_USAGE,
+        "OpenPTS command\n\n"
+        "Usage: ir2text [options]\n\n"
+        "Options:\n"
+        "  -i filename           Set IR file\n"
+        "  -o filename           Set output file, else stdout\n"
+        "  -P filename           Set PCR output file (option)\n"
+        "  -b                    Binary, (Convert IR to IML)\n"
+        "  -E                    Enable endian conversion (BE->LE or LE->BE)\n"
+        "  -h                    Show this help message\n"
+        "\n"));
 }
 
 int main(int argc, char *argv[]) {
@@ -649,7 +648,8 @@ int main(int argc, char *argv[]) {
             usage();
             return 0;
         default:
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IR2TEXT_BAD_OPTION_C, "bad option %c\n"), c);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_IR2TEXT_BAD_OPTION_C,
+                "bad option %c\n"), c);
             usage();
             return -1;
         }
@@ -666,14 +666,14 @@ int main(int argc, char *argv[]) {
             /* open output file */
             ctx->fp = fopen(out_filename, "w");
             if (ctx->fp == NULL) {
-                ERROR("output file %s - open failed\n", out_filename);
+                LOG(LOG_ERR, "output file %s - open failed\n", out_filename);
                 return rc;
             }
         }
     } else {
         /* print IR in binary text, with -o option */
         if (out_filename == NULL) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_IR2TEXT_OUTPUT_BINARY_MODE,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_IR2TEXT_OUTPUT_BINARY_MODE,
                 "set the output file for the binary mode\n"));
             usage();
             return -1;
@@ -683,7 +683,7 @@ int main(int argc, char *argv[]) {
         /* open output file */
         ctx->fp = fopen(out_filename, "wb");
         if (ctx->fp == NULL) {
-            ERROR("output file %s - open failed\n", out_filename);
+            LOG(LOG_ERR, "output file %s - open failed\n", out_filename);
             return rc;
         }
     }
@@ -702,12 +702,12 @@ int main(int argc, char *argv[]) {
     if (pcrout_filename != NULL) {
         FILE *fp;
         int i, j;
-        TODO("pcrout_filename = %s\n", pcrout_filename);
+        LOG(LOG_TODO, "pcrout_filename = %s\n", pcrout_filename);
 
         /* open output file */
         fp = fopen(pcrout_filename, "w");
         if (fp == NULL) {
-            ERROR("PCR output file %s - open failed\n", pcrout_filename);
+            LOG(LOG_ERR, "PCR output file %s - open failed\n", pcrout_filename);
             return -1;
         }
 
index 1274957..bd8bbc2 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 #endif  // AIX
 
 #ifdef ENABLE_NLS
+#include <locale.h>
 #ifdef HAVE_CATGETS
 #include <nl_types.h>
 nl_catd catd;
@@ -184,8 +185,6 @@ void determineLogLocationByEnv(void) {
     char *tempLogFileName = NULL;
     char *tempDebugMode = NULL;
 
-
-
     /* Location */
     if (getenv("OPENPTS_LOG_SYSLOG") != NULL) {
         logLocation = OPENPTS_LOG_SYSLOG;
@@ -219,7 +218,27 @@ void setLogLocation(int ll, char *filename) {
     logLocation = ll;
 
     if (ll == OPENPTS_LOG_FILE) {
-        expandLogFilePath(filename);
+        if (logFileFd != -1) {
+            char * oldlog;
+            /* already open */
+            LOG(LOG_INFO, "Logfile changed from %s to %s\n", logFileName, filename);
+            oldlog=strdup(logFileName);
+            if (oldlog == NULL) {
+                LOG(LOG_ERR, "no memory");
+                return;
+            }
+            close(logFileFd);
+            logFileFd = -1;
+            expandLogFilePath(filename);
+            LOG(LOG_INFO, "Logfile changed from %s to %s\n", oldlog, logFileName);
+            free(oldlog);
+        } else {
+            if (filename != NULL) {
+                expandLogFilePath(filename);
+            } else {
+                expandLogFilePath(DEFAULT_LOG_FILE);
+            }
+        }
     }
 }
 
@@ -240,7 +259,7 @@ char *getLogLocationString() {
     } else if (logLocation == OPENPTS_LOG_FILE) {
         return logFileName;
     } else {
-        ERROR("logLocation %d\n", logLocation);
+        LOG(LOG_ERR, "logLocation %d\n", logLocation);
         return "TBD";
     }
 }
@@ -299,17 +318,16 @@ void writeLog(int priority, const char *format, ...) {
     int len;
     char *format2 = NULL;
     va_list list;
-    // char buf[SYSLOG_BUF_SIZE];
     va_start(list, format);
 
-
+    /* check def */
     if (logLocation == OPENPTS_LOG_UNDEFINED) {
         determineLogLocationByEnv();
-        // fprintf(stderr, "logLocation == OPENPTS_LOG_UNDEFINED\n");
         return;
     }
 
     if (logLocation == OPENPTS_LOG_NULL) {
+        /* disable logging */
         return;
     }
 
index b39deed..f7db06e 100644 (file)
@@ -65,9 +65,9 @@
 void *xmalloc(size_t size) {
     char *result = malloc(size);
     if (NULL == result) {
-        ERROR("Failed to allocate %d bytes of memory\n", size);
+        LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size);
         // if ( size > 0 ) {
-        //     ERROR("malloc");
+        //     LOG(LOG_ERR, "malloc");
         // }
     }
     return result;
@@ -77,7 +77,7 @@ void *xmalloc(size_t size) {
 void *xmalloc_assert(size_t size) {
     char *result = malloc(size);
     if (NULL == result) {
-        ERROR("Failed to allocate %d bytes of memory\n", size);
+        LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size);
         OUTPUT("About to return NULL pointer - cannot continue\n");
         exit(1);
     }
@@ -86,7 +86,7 @@ void *xmalloc_assert(size_t size) {
 
 void xfree(void *buf) {
     if (buf == NULL) {
-        ERROR("Freeing a NULL pointer is bad");
+        LOG(LOG_ERR, "Freeing a NULL pointer is bad");
         return;
     }
 #ifndef NEVER_FREE_MEMORY
@@ -110,7 +110,7 @@ char *smalloc(char *str) {
     /* check string length */
     out = strdup(str);
     if (out == NULL) {
-        ERROR("Failed to duplicate string '%s'\n", str);
+        LOG(LOG_ERR, "Failed to duplicate string '%s'\n", str);
     }
 
     return out;
@@ -132,7 +132,7 @@ char *smalloc_assert(char *str) {
     /* check string length */
     out = strdup(str);
     if (NULL == out) {
-        ERROR("Failed to duplicate string '%s'\n", str);
+        LOG(LOG_ERR, "Failed to duplicate string '%s'\n", str);
         OUTPUT("About to return NULL pointer - cannot continue\n");
         exit(1);
     }
@@ -154,7 +154,7 @@ char *snmalloc(char *str, int len) {
 
     /* check */
     if (str == NULL) {
-        ERROR("smalloc - string is NULL\n");
+        LOG(LOG_ERR, "smalloc - string is NULL\n");
         return NULL;
     }
 
@@ -187,15 +187,15 @@ BYTE *snmalloc2(BYTE *buf, int offset, int len) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (offset < 0) {
-        ERROR("offset < 0");
+        LOG(LOG_ERR, "offset < 0");
         return NULL;
     }
     if (len < 0) {
-        ERROR("len < 0");
+        LOG(LOG_ERR, "len < 0");
         return NULL;
     }
 
@@ -239,11 +239,11 @@ char *getFullpathName(char *basepath, char *filename) {
 
     /* check */
     if (basepath == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -256,7 +256,7 @@ char *getFullpathName(char *basepath, char *filename) {
     /* basepath + filename */
     if (basepath[0] != '/') {
         /* relative path -> error when it run as daemon */
-        TODO("getFullpathName() - basepath, '%s' is not started from root\n", basepath);
+        LOG(LOG_TODO, "getFullpathName() - basepath, '%s' is not started from root\n", basepath);
     }
 
 
@@ -272,7 +272,7 @@ char *getFullpathName(char *basepath, char *filename) {
     filename_len = strlen(filename);
 
     if (filename_len < 2) {
-        ERROR("ilename len < 2\n");
+        LOG(LOG_ERR, "ilename len < 2\n");
         return NULL;
     }
 
@@ -318,7 +318,7 @@ char *getFullpathName(char *basepath, char *filename) {
             fullpath[basepath_len + filename_len - 1] = 0;
             break;
         default:
-            ERROR("internal error\n");
+            LOG(LOG_ERR, "internal error\n");
             break;
     }  // switch
 
@@ -340,7 +340,7 @@ char *getFullpathDir(char *filename) {
 
     /* check */
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -369,7 +369,7 @@ UINT32 byte2uint32(BYTE *b) {
     UINT32 a = 0;
 
     if (b == NULL) {
-        ERROR("byte2uint32 - NULL");
+        LOG(LOG_ERR, "byte2uint32 - NULL");
         OUTPUT("About to return NULL pointer - cannot continue\n");  // TODO
         exit(1);
     }
@@ -397,7 +397,7 @@ char * trim(char *str) {
 
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -438,7 +438,7 @@ char *getHexString(BYTE *bin, int size) {
 
     /* check */
     if (bin == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -448,7 +448,7 @@ char *getHexString(BYTE *bin, int size) {
         // len = snprintf(ptr, sizeof(ptr), "%02x", bin[i]);
         len = snprintf(ptr, 3, "%02x", bin[i]);
         if (len != 2) {
-            ERROR("FATAL");
+            LOG(LOG_ERR, "FATAL");
             free(buf);
             return NULL;
         }
@@ -469,19 +469,19 @@ void snprintHex(
 
     /* check */
     if (outBuf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (head == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (data == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (tail == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -518,11 +518,11 @@ void fprintHex(FILE *fp, BYTE *data, int num) {
 
     /* check */
     if (fp == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (data == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -570,20 +570,20 @@ int saveToFile(
 
     /* check */
     if (len < 0) {
-        ERROR("len <0 \n");
+        LOG(LOG_ERR, "len <0 \n");
         return PTS_FATAL;
     }
     if (msg == NULL) {
-        ERROR("msg is NULL \n");
+        LOG(LOG_ERR, "msg is NULL \n");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("filename is NULL \n");
+        LOG(LOG_ERR, "filename is NULL \n");
         return PTS_FATAL;
     }
 
     if ((fp = fopen(filename, "w+b")) == NULL) {
-        ERROR("File open failed, %s \n", filename);
+        LOG(LOG_ERR, "File open failed, %s \n", filename);
         return PTS_FATAL;  // TODO(munetoh): set PTS error code.
     }
 
@@ -605,7 +605,7 @@ int saveToFile(
     fclose(fp);
 
     if (len > 0) {
-        ERROR("After %d retries still have %d bytes unwritten to '%s'\n", max_retries, len, filename);
+        LOG(LOG_ERR, "After %d retries still have %d bytes unwritten to '%s'\n", max_retries, len, filename);
         return PTS_FATAL;
     } else {
         return PTS_SUCCESS;
@@ -620,7 +620,7 @@ UINT32 getUint32(BYTE *buf) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;  // TODO
     }
     // TODO check the size?
@@ -643,7 +643,7 @@ int makeDir(char *dirname) {
 
     /* check */
     if (dirname == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -653,7 +653,7 @@ int makeDir(char *dirname) {
     if (rc != 0) {
         switch (errno) {
         case EACCES:
-            ERROR("mkdir %s failed, EACCES", dirname);
+            LOG(LOG_ERR, "mkdir %s failed, EACCES", dirname);
             rc = PTS_FATAL;
             break;
         case EEXIST:
@@ -661,7 +661,7 @@ int makeDir(char *dirname) {
             rc = lstat(dirname, &st);
             if (rc == 0) {
                 if ((st.st_mode & S_IFMT) != S_IFDIR) {
-                    ERROR("directory, %s is not a directory %x %x\n",
+                    LOG(LOG_ERR, "directory, %s is not a directory %x %x\n",
                         dirname, (st.st_mode & S_IFMT), S_IFDIR);
                     rc = PTS_INTERNAL_ERROR;
                 } else {
@@ -669,17 +669,17 @@ int makeDir(char *dirname) {
                     rc = PTS_SUCCESS;
                 }
             } else {
-                ERROR("lstat(%s) failed, errno=%d\n", dirname, errno);
+                LOG(LOG_ERR, "lstat(%s) failed, errno=%d\n", dirname, errno);
                 rc = PTS_FATAL;
             }
             break;
         case EFAULT:
-            ERROR("mkdir %s failed, EFAULT", dirname);
+            LOG(LOG_ERR, "mkdir %s failed, EFAULT", dirname);
             rc = PTS_FATAL;
             break;
         // TODO add others :-)
         default:
-            ERROR("mkdir %s failed, errono = 0x%X", dirname, errno);
+            LOG(LOG_ERR, "mkdir %s failed, errono = 0x%X", dirname, errno);
             rc = PTS_FATAL;
             break;
         }
@@ -701,7 +701,7 @@ int checkDir(char *dirname) {
 
     /* check */
     if (dirname == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -724,7 +724,7 @@ int checkFile(char *filename) {
 
     /* check */
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -747,7 +747,7 @@ ssize_t wrapRead(int fd, void *buf, size_t count) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;  // TODO
     }
 
@@ -768,7 +768,7 @@ ssize_t wrapWrite(int fd, const void *buf, size_t count) {
 
     /* check */
     if (buf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;  // TODO
     }
 
@@ -793,13 +793,13 @@ static int unlinkDir_(char *dirPath) {
 
     /* check */
     if (dirPath == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     dirHandle = opendir(dirPath);
     if (dirHandle == NULL) {
-        ERROR("opendir(%s) fail", dirPath);
+        LOG(LOG_ERR, "opendir(%s) fail", dirPath);
         return PTS_FATAL;
     }
 
@@ -815,7 +815,7 @@ static int unlinkDir_(char *dirPath) {
 
         snprintf(path, sizeof(path), "%s/%s", dirPath, entry->d_name);
         if (stat(path, &st) != 0) {
-            ERROR("stat(%s) fail", path);
+            LOG(LOG_ERR, "stat(%s) fail", path);
             rc = PTS_FATAL;
             goto free_error;
         }
@@ -827,7 +827,7 @@ static int unlinkDir_(char *dirPath) {
             }
         } else if (S_ISREG(st.st_mode)) {
             if (unlink(path) != 0) {
-                ERROR("unlink(%s) fail", path);
+                LOG(LOG_ERR, "unlink(%s) fail", path);
                 rc = PTS_FATAL;
                 goto free_error;
             }
@@ -836,7 +836,7 @@ static int unlinkDir_(char *dirPath) {
 
     /* rm this dir */
     if (rmdir(dirPath) != 0) {
-        ERROR("rmdir(%s) fail", dirPath);
+        LOG(LOG_ERR, "rmdir(%s) fail", dirPath);
         rc = PTS_FATAL;
         goto free_error;
     }
@@ -857,11 +857,11 @@ int unlinkDir(const char *dirPath) {
 
     /* check */
     if (dirPath == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (dirPath[0] == '\0' || strlen(dirPath) >= PATH_MAX) {
-        ERROR("bad dirPath, %s", dirPath);
+        LOG(LOG_ERR, "bad dirPath, %s", dirPath);
         return PTS_FATAL;
     }
 
index 561eadc..a515a05 100644 (file)
@@ -119,7 +119,7 @@ OPENPTS_NONCE *newNonceContext() {
     /* malloc */
     ctx = xmalloc(sizeof(OPENPTS_NONCE));
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(ctx, 0, sizeof(OPENPTS_NONCE));
@@ -127,7 +127,7 @@ OPENPTS_NONCE *newNonceContext() {
     /* malloc req */
     ctx->req = (PTS_IF_M_DH_Nonce_Parameters_Request *)xmalloc(sizeof(PTS_IF_M_DH_Nonce_Parameters_Request));
     if (ctx->req == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         xfree(ctx);
         return NULL;
     }
@@ -136,7 +136,7 @@ OPENPTS_NONCE *newNonceContext() {
     /* malloc res */
     ctx->res = xmalloc(sizeof(PTS_IF_M_DH_Nonce_Parameters_Responce));
     if (ctx->res == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         xfree(ctx->req);
         xfree(ctx);
         return NULL;
@@ -146,7 +146,7 @@ OPENPTS_NONCE *newNonceContext() {
     /* malloc fin */
     ctx->fin = xmalloc(sizeof(PTS_IF_M_DH_Nonce_Finish));
     if (ctx->fin == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         xfree(ctx->req);
         xfree(ctx->res);
         xfree(ctx);
@@ -176,7 +176,7 @@ int freeNonceContext(OPENPTS_NONCE *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -236,14 +236,14 @@ int calcExternalDataValue(OPENPTS_NONCE *ctx) {
     // DEBUG("calcExternalDataValue\n");
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     ctx->nonce_length = SHA1_DIGEST_SIZE;
     ctx->nonce = xmalloc_assert(SHA1_DIGEST_SIZE);
     if (ctx->nonce == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
@@ -255,7 +255,7 @@ int calcExternalDataValue(OPENPTS_NONCE *ctx) {
     SHA1_Final(ctx->nonce, &sha_ctx);
 
     if (isDebugFlagSet(DEBUG_FLAG)) {
-        TODO("calcExternalDataValue - nonce\n");
+        LOG(LOG_TODO, "calcExternalDataValue - nonce\n");
         debugHex("\t\tinitiator_nonce:", ctx->initiator_nonce, ctx->initiator_nonce_length, "\n");
         debugHex("\t\trespondor_nonce:", ctx->respondor_nonce, ctx->respondor_nonce_length, "\n");
         debugHex("\t\tsecret         :", ctx->secret, ctx->secret_length, "\n");
@@ -283,21 +283,21 @@ int getDhResponce(OPENPTS_NONCE *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     req = ctx->req;
     if (req == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     res = ctx->res;
     if (res == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (req->reserved != 0) {
-        ERROR("reserved must be 0\n");
+        LOG(LOG_ERR, "reserved must be 0\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -336,7 +336,7 @@ int getDhResponce(OPENPTS_NONCE *ctx) {
         BN_hex2bn(&p, group14);
     } else {
         res->selected_dh_group = 0;
-        ERROR("Unknown DH group set 0x%x", req->dh_group_set);
+        LOG(LOG_ERR, "Unknown DH group set 0x%x", req->dh_group_set);
         return PTS_DENIED;
     }
 
@@ -353,14 +353,14 @@ int getDhResponce(OPENPTS_NONCE *ctx) {
     /* malloc */
     res->dh_respondor_nonce = xmalloc(res->nonce_length);
     if (res->dh_respondor_nonce == NULL) {
-        ERROR("dh_respondor_nonce is null");
+        LOG(LOG_ERR, "dh_respondor_nonce is null");
         return PTS_INTERNAL_ERROR;
     }
 
     /* set random */
     rc = getRandom(res->dh_respondor_nonce, res->nonce_length);
     if (rc != TSS_SUCCESS) {
-        ERROR("get random fail\n");
+        LOG(LOG_ERR, "get random fail\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -373,7 +373,7 @@ int getDhResponce(OPENPTS_NONCE *ctx) {
     /* malloc */
     res->dh_respondor_public = xmalloc(DH_size(ctx->dh));
     if (res->dh_respondor_public == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
@@ -402,7 +402,7 @@ int setDhPubkeylength(OPENPTS_NONCE *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -414,7 +414,7 @@ int setDhPubkeylength(OPENPTS_NONCE *ctx) {
     } else if (res->selected_dh_group == DH_GROUP_14) {
         ctx->pubkey_length = DH_GROUP_14_SIZE;
     } else {
-        ERROR("Bad DH group 0x%x\n", res->selected_dh_group);
+        LOG(LOG_ERR, "Bad DH group 0x%x\n", res->selected_dh_group);
         return PTS_DENIED;  // TODO
     }
 
@@ -439,23 +439,23 @@ int calcDh(OPENPTS_NONCE *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     res = ctx->res;
     if (res == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     fin = ctx->fin;
     if (fin == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if (res->reserved[0] != 0) {
         // TODO check 1,2 too
-        ERROR("reserved must be 0\n");
+        LOG(LOG_ERR, "reserved must be 0\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -465,7 +465,7 @@ int calcDh(OPENPTS_NONCE *ctx) {
         fin->selected_hash_alg = DH_HASH_SHA1;
         ctx->selected_hash_alg = DH_HASH_SHA1;
     } else {
-        ERROR("Bad DH hash set 0x%x\n", res->hash_alg_set);
+        LOG(LOG_ERR, "Bad DH hash set 0x%x\n", res->hash_alg_set);
         return PTS_DENIED;
     }
 
@@ -493,7 +493,7 @@ int calcDh(OPENPTS_NONCE *ctx) {
         BN_hex2bn(&p, group14);
         ctx->pubkey_length = DH_GROUP_14_SIZE;
     } else {
-        ERROR("Bad DH group 0x%x\n", res->selected_dh_group);
+        LOG(LOG_ERR, "Bad DH group 0x%x\n", res->selected_dh_group);
         return  PTS_DENIED;
     }
 
@@ -514,7 +514,7 @@ int calcDh(OPENPTS_NONCE *ctx) {
     /* malloc */
     ctx->secret = xmalloc(ctx->secret_length);
     if (ctx->secret == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
@@ -524,14 +524,14 @@ int calcDh(OPENPTS_NONCE *ctx) {
     /* initiator nonce */
     fin->dh_initiator_nonce = xmalloc(fin->nonce_length);
     if (fin->dh_initiator_nonce == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
     /* set random */
     rc = getRandom(fin->dh_initiator_nonce, fin->nonce_length);
     if (rc != TSS_SUCCESS) {
-        ERROR("get random fail\n");
+        LOG(LOG_ERR, "get random fail\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -572,12 +572,12 @@ int calcDhFin(OPENPTS_NONCE *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     fin = ctx->fin;
     if (fin == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
index 8791eb3..ee8b9d7 100644 (file)
@@ -78,7 +78,8 @@ extern char *ptsc_command;
  * Usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_USAGE, "OpenPTS command\n\n"
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_USAGE_1,
+        "OpenPTS command\n\n"
         "Usage: openpts [options] {-i [-f]|[-v]||-r|-D} <target>\n"
         "       openpts -D\n\n"
         "Commands:\n"
@@ -91,10 +92,12 @@ void usage(void) {
         "  -h                    Show this help message\n"
         "  -V                    Verbose mode. Multiple -V options increase the verbosity.\n"
         "\n"
-        "Options:\n"
+        "Options:\n"));
 #ifdef CONFIG_AUTO_RM_UPDATE
-        "  -u                    Accept a measurement update during attestation, if there are any available.\n"
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_USAGE_2,
+        "  -u                    Accept a measurement update during attestation, if there are any available.\n"));
 #endif
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_USAGE_3,
         "  -l username           ssh username [ssh default]\n"
         "  -p port               ssh port number [ssh default]\n"
         "  -c configfile         Set configuration file [~/.openpts/openpts.conf]\n"
@@ -110,7 +113,7 @@ void usage(void) {
 #define DISPLAY 4
 #define NONE    5
 
-
+#define OPENPTS_LOG_FILENAME  "~/.openpts/openpts.log"
 
 
 
@@ -229,46 +232,27 @@ int main(int argc, char *argv[]) {
 
     cmdline_hostname = argv[0];
 
+    /* default logging scheme */
+    debugBits = 0;
+    setLogLocation(OPENPTS_LOG_FILE, OPENPTS_LOG_FILENAME);
 
     /* check */
     if ((ptsc_path != NULL) && (ptsc_conf != NULL)) {
         int len;
         // char ptsc_command[PATH_MAX];
-        INFO("ptsc debug mode\n");
+        LOG(LOG_INFO, "ptsc debug mode\n");
         // len = strlen(ptsc_path) + strlen(ptsc_conf) + 13;
         // snprintf(ptsc_command, PATH_MAX - 1, "%s -m -v -c %s", ptsc_path, ptsc_conf);
 
         len =  strlen(ptsc_path) + strlen(ptsc_conf) + 13;
         ptsc_command = xmalloc(len);
         snprintf(ptsc_command, len, "%s -m -v -c %s", ptsc_path, ptsc_conf);
-        INFO("command: %s\n", ptsc_command);
+        LOG(LOG_INFO, "command: %s\n", ptsc_command);
     }
 
     /* default command is to verify */
     if (command == NONE) command = VERIFY;
 
-#if 0  // 2011-12-28 controlled by conf
-    /* Log */
-    setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
-#ifdef OPENPTS_DEBUG
-    setDebugFlags(DEBUG_FLAG | DEBUG_FSM_FLAG | DEBUG_IFM_FLAG);
-#else
-    /* set the DEBUG level, 1,2,3
-       WORK NEEDED - should have a debug flag too. */
-
-    if (getVerbosity() > 2) {
-        setDebugFlags(DEBUG_FLAG | DEBUG_FSM_FLAG | DEBUG_IFM_FLAG);
-        DEBUG("verbose mode            : >=3");
-    } else if (getVerbosity() > 1) {
-        setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG);
-        DEBUG("verbose mode            : 2");
-    } else if (getVerbosity() > 0) {
-        setDebugFlags(DEBUG_FLAG);
-        DEBUG("verbose mode            : 1");
-    }
-#endif
-#endif // 0
-
     /* Set logging (location,filename)  by ENV */
     determineLogLocationByEnv();
 
@@ -304,13 +288,13 @@ int main(int argc, char *argv[]) {
 
     // setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
 
-    VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONFIG_FILE,
+    VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONFIG_FILE,
         "Config file         : %s\n"), conf->config_file);
-    VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_VERBOSITY,
+    VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_VERBOSITY,
         "Verbosity           : %d\n"), getVerbosity());
-    VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_DEBUG_OUT,
+    VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_DEBUG_OUT,
         "Logging location    : %s\n"), getLogLocationString());
-    VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_DEBUG_MODE,
+    VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_DEBUG_MODE,
         "Logging(debig) mode : 0x%x\n"), getDebugFlags());
 
     /* we always need the target list */
@@ -339,7 +323,7 @@ int main(int argc, char *argv[]) {
         /* look up the conf of target(hostname) */
         /* set the target hostname:port and search */
         if (conf->hostname != NULL) {
-            TODO("realloc conf->hostname\n");
+            LOG(LOG_TODO, "realloc conf->hostname\n");
             xfree(conf->hostname);
         }
         conf->hostname = smalloc_assert(cmdline_hostname);
@@ -381,11 +365,11 @@ int main(int argc, char *argv[]) {
             /* look up */
             if (target_collector != NULL) {
                 // WORK NEEDED: Please use NLS for i18n output
-                printf("hostname  : %s\n", target_hostname);
-                printf("UUID      : %s\n", target_collector->str_uuid);
-                printf("State     : %d\n", target_collector->state);
-                printf("Dir       : %s\n", target_collector->dir);
-                printf("Manifests :\n");
+                OUTPUT("hostname  : %s\n", target_hostname);
+                OUTPUT("UUID      : %s\n", target_collector->str_uuid);
+                OUTPUT("State     : %d\n", target_collector->state);
+                OUTPUT("Dir       : %s\n", target_collector->dir);
+                OUTPUT("Manifests :\n");
 
                 getRmList(target_conf, target_conf->config_dir);
                 printRmList(target_conf, "");
@@ -423,7 +407,7 @@ int main(int argc, char *argv[]) {
     if (command == REMOVE) {
         /* delete */
         if (unlinkDir(target_conf_dir) != 0) {
-            ERROR("unlinkDir(%s) failed", target_conf_dir);
+            LOG(LOG_ERR, "unlinkDir(%s) failed", target_conf_dir);
             retVal = RETVAL_TARGET_ERROR;
             goto out_free;
         }
@@ -440,7 +424,7 @@ int main(int argc, char *argv[]) {
     if (ssh_username != NULL) {
         target_conf->ssh_username = strdup(ssh_username);
         if (target_conf->ssh_username == NULL) {
-            ERROR("No memory");
+            LOG(LOG_ERR, "No memory");
             retVal = RETVAL_GLOBAL_ERROR;
             goto out_free;
         }
@@ -486,7 +470,8 @@ int main(int argc, char *argv[]) {
         DEBUG("conf->config_dir %s\n", conf->config_dir);
         rc = enroll(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, force);  // verifier.c
         if (rc != 0) {
-            DEBUG("enroll was failed, rc = %d\n", rc);
+            ERROR(  // TODO NLS
+                "enroll was failed, rc = %d\n", rc);
             printReason(ctx, print_pcr_hints);
             retVal = RETVAL_NOTENROLLED;
             goto out_free;
@@ -495,7 +480,9 @@ int main(int argc, char *argv[]) {
         DEBUG("conf->config_dir %s\n", conf->config_dir);
         rc =  verifier(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, 1);  // init
         if (rc != OPENPTS_RESULT_VALID) {
-            ERROR("initial verification was failed, rc = %d\n", rc);
+            LOG(LOG_ERR, "initial verification was failed, rc = %d\n", rc);
+            ERROR(  // TODO NLS
+                "initial verification was failed, rc = %d\n", rc);
             printReason(ctx, print_pcr_hints);
             retVal = RETVAL_NOTTRUSTED;
             goto out_free;
@@ -504,28 +491,30 @@ int main(int argc, char *argv[]) {
         retVal = RETVAL_OK_TRUSTED;
 
         /* message */
-        printf(NLS(MS_OPENPTS, OPENPTS_INIT_TARGET, "Target: %s\n"), target_hostname);
+        VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_TARGET,
+            "Target: %s\n"), target_hostname);
 
         if (ctx->target_conf != NULL) {
             if (ctx->target_conf->rm_uuid != NULL) {
-                printf(NLS(MS_OPENPTS, OPENPTS_INIT_MANIFEST_UUID,
+                VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_MANIFEST_UUID,
                     "Manifest UUID: %s\n"), ctx->target_conf->rm_uuid->str);
                 for (i = 0; i< ctx->conf->rm_num; i ++) {
-                    printf(NLS(MS_OPENPTS, OPENPTS_INIT_MANIFEST,
+                    VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_MANIFEST,
                         "Manifest[%d]: %s\n"), i, ctx->target_conf->rm_filename[i]);
                 }
             }
             /* having indentation specific to one language will make the
                translated versions (i.e. french, japanese) look ugly */
-            printf(NLS(MS_OPENPTS, OPENPTS_INIT_COLLECTOR_UUID,
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_COLLECTOR_UUID,
                 "Collector UUID: %s\n"), ctx->target_conf->uuid->str);
-            printf(NLS(MS_OPENPTS, OPENPTS_INIT_CONFIG,
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_CONFIG,
                 "Configuration: %s\n"), ctx->target_conf->config_file);
-            printf(NLS(MS_OPENPTS, OPENPTS_INIT_VALIDATION,
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_INIT_VALIDATION,
                 "Validation policy: %s\n"), ctx->target_conf->policy_filename);
         } else {
             // TODO never happen?
-            printf(NLS(MS_OPENPTS, OPENPTS_INIT_NEW_CONFIG, "Configuration: new target\n"));
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_NEW_CONFIG,
+                "Configuration: new target\n"));
         }
         break;
     }
@@ -538,24 +527,26 @@ int main(int argc, char *argv[]) {
         rc = verifier(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, 0);  // normal
 
         /* messages */
-        // printf("target        : %s\n", argv[0]);
-        printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_TARGET, "Target: %s\n"), target_hostname);
+        VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_TARGET,
+            "Target: %s\n"), target_hostname);
         if (target_conf != NULL) {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_COLLECTOR_UUID, "Collector UUID: %s "), target_conf->uuid->str);
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_COLLECTOR_UUID, "Collector UUID: %s "), target_conf->uuid->str);
             // TODO set this when load the uuid
             if (target_conf->uuid->time == NULL) {
                 target_conf->uuid->time = getDateTimeOfUuid(target_conf->uuid->uuid);
             }
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE, "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE,
+                "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
                 target_conf->uuid->time->year + 1900,
                 target_conf->uuid->time->mon + 1,
                 target_conf->uuid->time->mday,
                 target_conf->uuid->time->hour,
                 target_conf->uuid->time->min,
                 target_conf->uuid->time->sec);
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_MANIFEST_UUID,
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_MANIFEST_UUID,
                 "Manifest UUID: %s "), target_conf->rm_uuid->str);
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE, "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE,
+                "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
                 target_conf->rm_uuid->time->year + 1900,
                 target_conf->rm_uuid->time->mon + 1,
                 target_conf->rm_uuid->time->mday,
@@ -563,12 +554,15 @@ int main(int argc, char *argv[]) {
                 target_conf->rm_uuid->time->min,
                 target_conf->rm_uuid->time->sec);
 
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_USERNAME, "username(ssh): %s\n"),
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_USERNAME,
+                "username(ssh): %s\n"),
                 conf->ssh_username ? conf->ssh_username : "default");
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_PORT, "port(ssh): %s\n"),
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_PORT,
+                "port(ssh): %s\n"),
                 conf->ssh_port ? conf->ssh_port : "default");
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_POLICY, "policy file: %s\n"), target_conf->policy_filename);
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_PROPERTY,
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_POLICY,
+                "policy file: %s\n"), target_conf->policy_filename);
+            VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_VERIFY_PROPERTY,
                 "property file: %s\n"), target_conf->prop_filename);  // TODO property or prop
         } else {
             retVal = RETVAL_GLOBAL_ERROR;
@@ -576,24 +570,27 @@ int main(int argc, char *argv[]) {
         }
 
         if (rc == OPENPTS_RESULT_VALID) {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_VALID, "integrity: valid\n"));
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_VALID, "integrity: valid\n"));
             retVal = RETVAL_OK_TRUSTED;
         } else if (rc == OPENPTS_RESULT_INVALID ||
                    rc == PTS_VERIFY_FAILED ||
                    rc == PTS_NOT_INITIALIZED ||  // <-- happens when a target changed its UUID (re-init)
                    rc == PTS_RULE_NOT_FOUND) {   // <-- happens when a target has updated its RM
                                                  //     (failed selftest using -s)
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_INVALID, "integrity: invalid\n"));
+            ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFY_INVALID,
+                "integrity: invalid\n"));
             printReason(ctx, print_pcr_hints);
             retVal = RETVAL_NOTTRUSTED;
             goto out_free;
         } else if (rc == OPENPTS_RESULT_UNKNOWN) {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_UNKNOWN, "integrity: unknown\n"));
+            ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFY_UNKNOWN,
+                "integrity: unknown\n"));
             printReason(ctx, print_pcr_hints);
             retVal = RETVAL_TARGET_ERROR;
             goto out_free;
         } else {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_ERROR, "integrity: unknown (INTERNAL ERROR) rc=%d\n"), rc);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFY_ERROR,
+                "integrity: unknown (INTERNAL ERROR) rc=%d\n"), rc);
             printReason(ctx, print_pcr_hints);
             retVal = RETVAL_TARGET_ERROR;
             goto out_free;
@@ -619,7 +616,8 @@ int main(int argc, char *argv[]) {
                     printHex(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_UUID_LOCAL,
                         "NEWRM UUID (local): "), (BYTE*)target_conf->newrm_uuid->uuid, 16, "\n");
                 } else {
-                    printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_UUID_MISSING, "NEWRM UUID (local): missing\n"));
+                    OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_UUID_MISSING,
+                        "NEWRM UUID (local): missing\n"));
                 }
             }
 
@@ -630,10 +628,11 @@ int main(int argc, char *argv[]) {
                                 (BYTE*)target_conf->newrm_uuid->uuid, 16) &&
                     0 == isNewRmStillValid(ctx, conf->config_dir) ) {
                     /* HIT */
-                    printf("---------------------------------------------------------\n");
-                    printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UUID,
+                    OUTPUT("---------------------------------------------------------\n");
+                    OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UUID,
                         "New Manifest UUID: %s "), target_conf->newrm_uuid->str);
-                    printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE, "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
+                    OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE,
+                        "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
                         target_conf->newrm_uuid->time->year + 1900,
                         target_conf->newrm_uuid->time->mon + 1,
                         target_conf->newrm_uuid->time->mday,
@@ -644,17 +643,19 @@ int main(int argc, char *argv[]) {
                     goto out_free;
                 } else {
                     /* local is old? */
-                    printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_ALREADY_EXISTS,
+                    OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_ALREADY_EXISTS,
                            "A new reference manifest has been received, but an update exists\n"));
                 }
             }
 
             /* msg */
-            printf("---------------------------------------------------------\n");
+            OUTPUT("---------------------------------------------------------\n");
             uuid_time = getDateTimeOfUuid(conf->target_newrm_uuid);
             uuid_str = getStringOfUuid(conf->target_newrm_uuid);
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UUID, "New Manifest UUID: %s "), uuid_str);
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE, "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UUID,
+                "New Manifest UUID: %s "), uuid_str);
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_DATE,
+                "(date: %04d-%02d-%02d-%02d:%02d:%02d)\n"),
                 uuid_time->year + 1900,
                 uuid_time->mon + 1,
                 uuid_time->mday,
@@ -665,7 +666,7 @@ int main(int argc, char *argv[]) {
 
             if (isatty(STDIN_FILENO) && !update_by_default) {
                 char *lineFeed;
-                printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UPDATE,
+                OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_NEW_MANIFEST_UPDATE,
                     "A new reference manifest exists. Update? [Y/n]\n"));
                 if ( NULL != fgets(ans, 32, stdin) ) {
                     // strip the ending line-feed
@@ -691,17 +692,19 @@ int main(int argc, char *argv[]) {
             if (ansIsYes) {
                 rc = updateNewRm(ctx, target_hostname, conf->config_dir);  // aru.c
                 if (rc == PTS_SUCCESS) {
-                    printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_SAVE_NEW_MANIFEST, "Save new reference manifest\n"));
+                    OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_SAVE_NEW_MANIFEST,
+                        "Save new reference manifest\n"));
                     // TODO UUID
                     retVal = RETVAL_OK_TRUSTED;
                 } else {
                     retVal = RETVAL_TARGET_ERROR;
                 }
             } else if (ansIsNo) {
-                printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_KEEP_CURRENT_MANIFEST, "Keep current manifest\n"));
+                OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_KEEP_CURRENT_MANIFEST,
+                    "Keep current manifest\n"));
                 retVal = RETVAL_OK_PENDINGUPDATE;
             } else {
-                ERROR("Bad answer %s, exit\n", ans);
+                LOG(LOG_ERR, "Bad answer %s, exit\n", ans);
                 retVal = RETVAL_GLOBAL_ERROR;
                 goto out_free;
             }
@@ -709,7 +712,7 @@ int main(int argc, char *argv[]) {
             // TODO validate new RM
             // TODO e.g. gen new RM by verifier and compare both
         } else if (rc == PTS_RULE_NOT_FOUND) {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_RUN_OPENPTS,
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_RUN_OPENPTS,
                 "A new reference manifest exists. If this is expected, "
                 "please update the manifest with 'openpts -i -f'\n"));
             retVal = RETVAL_NOTENROLLED;
@@ -719,7 +722,7 @@ int main(int argc, char *argv[]) {
         }
 #else
         if (rc == PTS_RULE_NOT_FOUND) {
-            printf(NLS(MS_OPENPTS, OPENPTS_VERIFY_RUN_OPENPTS,
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_VERIFY_RUN_OPENPTS,
                 "A new reference manifest exists. If this is expected, "
                 "please update the manifest with 'openpts -i -f'\n"));
             retVal = RETVAL_NOTENROLLED;
index ed13880..1c8ef9a 100644 (file)
@@ -50,7 +50,7 @@
 int freePolicyChain(OPENPTS_POLICY *pol) {
     /* check */
     if (pol == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -83,11 +83,11 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -120,7 +120,7 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
             /* new  */
             pol = xmalloc(sizeof(OPENPTS_POLICY));
             if (pol == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 cnt = -1;  // return -1;
                 goto error;
             }
@@ -183,7 +183,7 @@ int checkPolicy(OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     pol = ctx->policy_start;
@@ -253,7 +253,7 @@ int printPolicy(OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     pol = ctx->policy_start;
index 9edd2e1..3bc5be5 100644 (file)
@@ -59,29 +59,29 @@ OPENPTS_PROPERTY * newProperty(char *name, char *value) {
 
     /* check */
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     prop = (OPENPTS_PROPERTY *) xmalloc(sizeof(OPENPTS_PROPERTY));
     if (prop == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(prop, 0, sizeof(OPENPTS_PROPERTY));
 
     prop->name = smalloc_assert(name);
     if (prop->name == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     prop->value = smalloc_assert(value);
     if (prop->value == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -94,7 +94,7 @@ OPENPTS_PROPERTY * newProperty(char *name, char *value) {
 void freeProperty(OPENPTS_PROPERTY *prop) {
     /* check */
     if (prop == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -132,7 +132,7 @@ OPENPTS_PROPERTY* getProperty(OPENPTS_CONTEXT *ctx, char *name) {
 
     /* check */
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -140,7 +140,7 @@ OPENPTS_PROPERTY* getProperty(OPENPTS_CONTEXT *ctx, char *name) {
     prop = ctx->prop_start;
     while (prop != NULL) {
         if (prop->name == NULL) {
-            ERROR("getProperty(%s) fail, bad property entry exist", name);
+            LOG(LOG_ERR, "getProperty(%s) fail, bad property entry exist", name);
             return NULL;
         }
 
@@ -170,7 +170,7 @@ int addProperty(OPENPTS_CONTEXT *ctx, char *name, char *value) {
     /* malloc new prop */
     prop = newProperty(name, value);
     if (prop == NULL) {
-        ERROR("newProperty() fail");
+        LOG(LOG_ERR, "newProperty() fail");
         return PTS_FATAL;
     }
 
@@ -203,15 +203,15 @@ int setProperty(OPENPTS_CONTEXT *ctx, char *name, char *value) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -238,15 +238,15 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -264,15 +264,15 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
 
         /* check, missing event */
         if (eventWrapper == NULL) {
-            ERROR("setEventProperty() - eventWrapper is NULL\n");
+            LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n");
             return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
         }
         if (eventWrapper->event == NULL) {
-            ERROR("setEventProperty() - event is NULL\n");
+            LOG(LOG_ERR, "setEventProperty() - event is NULL\n");
             return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
         }
         if (eventWrapper->event->rgbPcrValue == NULL) {
-            ERROR("setEventProperty() - rgbPcrValue is NULL\n");
+            LOG(LOG_ERR, "setEventProperty() - rgbPcrValue is NULL\n");
             return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
         }
 
@@ -281,14 +281,14 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
             SHA1_DIGEST_SIZE,
             &buf_len);
         if (buf == NULL) {
-            ERROR("encodeBase64 fail");
+            LOG(LOG_ERR, "encodeBase64 fail");
             return PTS_FATAL;
         }
         rc = setProperty(ctx, name, buf);
         free(buf);
 
         if (rc != PTS_SUCCESS) {
-            ERROR("setProperty() fail");
+            LOG(LOG_ERR, "setProperty() fail");
             return PTS_FATAL;
         }
         return rc;
@@ -302,36 +302,36 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
 
         /* check, missing event */
         if (eventWrapper == NULL) {
-            ERROR("setEventProperty() - eventWrapper is NULL\n");
+            LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n");
             return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
         }
         event = eventWrapper->event;
         if (event == NULL) {
-            ERROR("setEventProperty() - event is NULL\n");
+            LOG(LOG_ERR, "setEventProperty() - event is NULL\n");
             return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
         }
         if (event->ulEventLength > 0) {
             char * str;
             if (event->rgbEvent == NULL) {
-                ERROR("setEventProperty() - rgbEvent is NULL\n");
+                LOG(LOG_ERR, "setEventProperty() - rgbEvent is NULL\n");
                 return PTS_FATAL; // 0;  // PTS_INTERNAL_ERROR;
             }
             /* get String */
 
             str = snmalloc((char*)event->rgbEvent, event->ulEventLength);
             if (str == NULL) {
-                ERROR("no memory");
+                LOG(LOG_ERR, "no memory");
                 return PTS_INTERNAL_ERROR;
             }
             xfree(str);
             rc = setProperty(ctx, name, str);  // TODO 2011-02-03 SM implement
             if (rc != PTS_SUCCESS) {
-                ERROR("setProperty() fail");
+                LOG(LOG_ERR, "setProperty() fail");
                 return PTS_FATAL;
             }
             return rc;
         } else {
-            ERROR("missing rgbEvent");
+            LOG(LOG_ERR, "missing rgbEvent");
             return PTS_INTERNAL_ERROR;
         }
         // NULL
@@ -339,7 +339,7 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
     if (!strcmp(value, "notexist")) {
         rc = setProperty(ctx, name, value);  // TODO
         if (rc != PTS_SUCCESS) {
-            ERROR("setProperty() fail");
+            LOG(LOG_ERR, "setProperty() fail");
             return PTS_FATAL;
         }
         return rc;
@@ -348,7 +348,7 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
     /* others */
     rc =  setProperty(ctx, name, value);
     if (rc != PTS_SUCCESS) {
-        ERROR("setProperty() fail");
+        LOG(LOG_ERR, "setProperty() fail");
         return PTS_FATAL;
     }
     return rc;
@@ -372,15 +372,15 @@ int validateProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, char *action
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -392,7 +392,7 @@ int validateProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, char *action
 
     if (prop == NULL) {
         /* name miss? */
-        ERROR("validateProperty - property %s is missing\n", name);
+        LOG(LOG_ERR, "validateProperty - property %s is missing\n", name);
         rc = OPENPTS_FSM_ERROR;
     } else {
         /* name hit? check the value */
@@ -435,7 +435,7 @@ void printProperties(OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -458,24 +458,24 @@ int saveProperties(OPENPTS_CONTEXT *ctx, char * filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* open */
     if ((fp = fopen(filename, "w")) == NULL) {
-        ERROR("File %s open was failed\n", filename);
+        LOG(LOG_ERR, "File %s open was failed\n", filename);
         return PTS_INTERNAL_ERROR;
     }
 
     /* get properties chain*/
     prop = ctx->prop_start;
     if (prop == NULL) {
-        ERROR("properties is NULL\n");
+        LOG(LOG_ERR, "properties is NULL\n");
         fclose(fp);
         return PTS_INTERNAL_ERROR;
     }
@@ -496,11 +496,11 @@ int addPropertiesFromConfig(OPENPTS_CONFIG *conf, OPENPTS_CONTEXT *ctx) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
index 0a5d38f..c86d2e7 100644 (file)
@@ -73,7 +73,7 @@ int collector2(OPENPTS_CONFIG *conf) {
     /* Init RMs */
     rc = getRmSetDir(conf);
     if (rc != PTS_SUCCESS) {
-        ERROR("collector() - getRmSetDir() was failed\n");
+        LOG(LOG_ERR, "collector() - getRmSetDir() was failed\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -84,7 +84,7 @@ int collector2(OPENPTS_CONFIG *conf) {
     }
 
 
-    INFO("start collector (System UUID=%s, RM UUID = %s)\n",
+    LOG(LOG_INFO, "start collector (System UUID=%s, RM UUID = %s)\n",
         conf->uuid->str, conf->rm_uuid->str);
 
     /* Collector <-> Verifier - handshake loop */
@@ -111,12 +111,12 @@ int collector2(OPENPTS_CONFIG *conf) {
 
         /* check bad TLV */
         if (read_tlv->type == 0) {
-            ERROR("Bad TLV type received - quit");
+            LOG(LOG_ERR, "Bad TLV type received - quit");
             break;
         }
 
         if (read_tlv->length > 0 && read_tlv->value == NULL) {
-            ERROR("Malformed TLV message (ghost body) - quit");
+            LOG(LOG_ERR, "Malformed TLV message (ghost body) - quit");
             break;
         }
 
@@ -131,7 +131,7 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M OPENPTS_CAPABILITIES\n");
                 /* check the UUID */
                 if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) {  // TODO use defined name
-                    ERROR("Bad PTS_CAPABILITIES, len = %d != %d\n",
+                    LOG(LOG_ERR, "Bad PTS_CAPABILITIES, len = %d != %d\n",
                         read_tlv->length, sizeof(OPENPTS_IF_M_Capability));
                     terminate = 1;
                 } else {
@@ -146,12 +146,12 @@ int collector2(OPENPTS_CONFIG *conf) {
                     ctx->str_uuid = getStringOfUuid(ctx->uuid);
 
                     /* syslog */
-                    INFO("verifier (UUID=%s)\n", ctx->str_uuid);
+                    LOG(LOG_INFO, "verifier (UUID=%s)\n", ctx->str_uuid);
 
                     /* send PTS_CAPABILITIES msg. to verifier (=UUID) */
                     rc = writePtsTlv(ctx, STDOUT_FILENO, OPENPTS_CAPABILITIES);
                     if (rc < 0) {
-                        ERROR("Send CAPABILITY answer failed - quit");
+                        LOG(LOG_ERR, "Send CAPABILITY answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -161,7 +161,7 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M DH_NONCE_PARAMETERS_REQUEST\n");
                 /* check */
                 if (read_tlv->length != 4) {
-                    ERROR("Bad DH_NONCE_PARAMETERS_REQUEST, len = %d != 4\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad DH_NONCE_PARAMETERS_REQUEST, len = %d != 4\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     /* req -> res */
@@ -176,7 +176,7 @@ int collector2(OPENPTS_CONFIG *conf) {
                     rc = writePtsTlv(
                             ctx, STDOUT_FILENO, DH_NONCE_PARAMETORS_RESPONSE);
                     if (rc < 0) {
-                        ERROR("Send NONCE answer failed - quit");
+                        LOG(LOG_ERR, "Send NONCE answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -185,7 +185,7 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M DH_NONCE_FINISH\n");
                 /* check */
                 if (read_tlv->length != 152) {  // TODO  how to calc this size?
-                    ERROR("Bad DH_NONCE_FINISH, len = %d != 152\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad DH_NONCE_FINISH, len = %d != 152\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     /* finish  */
@@ -217,13 +217,13 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M REQUEST_RIMM_SET\n");
                 /* check */
                 if (read_tlv->length != 0) {
-                    ERROR("Bad REQUEST__RIMM_SET, len = %d != 0\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad REQUEST__RIMM_SET, len = %d != 0\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     rc = writePtsTlv(
                             ctx, STDOUT_FILENO, RIMM_SET);
                     if (rc < 0) {
-                        ERROR("Send RIMM_SET answer failed - quit");
+                        LOG(LOG_ERR, "Send RIMM_SET answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -232,7 +232,7 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M REQUEST_NEW_RIMM_SET\n");
                 /* check */
                 if (read_tlv->length != 0) {
-                    ERROR("Bad REQUEST_NEW_RIMM_SET, len = %d != 0\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad REQUEST_NEW_RIMM_SET, len = %d != 0\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     rc = writePtsTlv(
@@ -248,12 +248,12 @@ int collector2(OPENPTS_CONFIG *conf) {
                 DEBUG("IF-M REQUEST_INTEGRITY_REPORT\n");
                 /* check */
                 if (read_tlv->length != 0) {
-                    ERROR("Bad REQUEST_INTEGRITY_REPORT, len = %d != 0\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad REQUEST_INTEGRITY_REPORT, len = %d != 0\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     rc = writePtsTlv(ctx, STDOUT_FILENO, INTEGRITY_REPORT);
                     if (rc < 0) {
-                        ERROR("Send INTEGRITY_REPORT answer failed - quit");
+                        LOG(LOG_ERR, "Send INTEGRITY_REPORT answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -266,15 +266,15 @@ int collector2(OPENPTS_CONFIG *conf) {
                 break;
 #ifdef CONFIG_AIDE
             case REQUEST_AIDE_DATABASE:
-                INFO("IF-M REQUEST_AIDE_DATABASE\n");
+                LOG(LOG_INFO, "IF-M REQUEST_AIDE_DATABASE\n");
                 /* check */
                 if (read_tlv->length != 0) {
-                    ERROR("Bad REQUEST_AIDE_DATABASE, len = %d != 0\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad REQUEST_AIDE_DATABASE, len = %d != 0\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     rc = writePtsTlv(ctx, STDOUT_FILENO, AIDE_DATABASE);
                     if (rc < 0) {
-                        ERROR("Send REQUEST_AIDE_DATABASE answer failed - quit");
+                        LOG(LOG_ERR, "Send REQUEST_AIDE_DATABASE answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -283,12 +283,12 @@ int collector2(OPENPTS_CONFIG *conf) {
             case REQUEST_TPM_PUBKEY:
                 /* check */
                 if (read_tlv->length != 0) {
-                    ERROR("Bad REQUEST_TPM_PUBKEY, len = %d != 0\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad REQUEST_TPM_PUBKEY, len = %d != 0\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     rc = writePtsTlv(ctx, STDOUT_FILENO, TPM_PUBKEY);  // ifm.c
                     if (rc < 0) {
-                        ERROR("Send TPM_PUBKEY answer failed - quit");
+                        LOG(LOG_ERR, "Send TPM_PUBKEY answer failed - quit");
                         terminate = 1;
                     }
                 }
@@ -296,7 +296,7 @@ int collector2(OPENPTS_CONFIG *conf) {
             case NONCE:
                 /* check */
                 if (read_tlv->length != 20) {
-                    ERROR("Bad NONCE, len = %d != 20\n", read_tlv->length);
+                    LOG(LOG_ERR, "Bad NONCE, len = %d != 20\n", read_tlv->length);
                     terminate = 1;
                 } else {
                     /* set nonce */
@@ -310,12 +310,12 @@ int collector2(OPENPTS_CONFIG *conf) {
                 }
                 break;
             case OPENPTS_ERROR:
-                ERROR("verifier returns error, termnate\n");
+                LOG(LOG_ERR, "verifier returns error, termnate\n");
                 terminate = 1;
                 break;
             default:
-                ERROR("PTS IF-M type 0x%08x is not supported\n", read_tlv->type);
-                INFO("send OPENPTS_ERROR msg to verifier, then terminate the conenction");
+                LOG(LOG_ERR, "PTS IF-M type 0x%08x is not supported\n", read_tlv->type);
+                LOG(LOG_INFO, "send OPENPTS_ERROR msg to verifier, then terminate the conenction");
                 ctx->ifm_errno = PTS_UNRECOGNIZED_COMMAND;
                 if (ctx->ifm_strerror != NULL) {
                     xfree(ctx->ifm_strerror);
@@ -342,31 +342,32 @@ int collector2(OPENPTS_CONFIG *conf) {
  * Usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS,  OPENPTS_COLLECTOR_USAGE_1, "OpenPTS Collector\n\n"
-                    "Usage: ptsc [options] [command]\n\n"
-                    "Commands: (foreground)\n"
-                    "  -i                    Initialize PTS collector\n"
-                    "  -t                    Self test (attestation)\n"
-                    "  -s                    Startup (selftest + timestamp)\n"
-                    "  -u                    Update the RM\n"
-                    "  -e                    Clear PTS collector\n"));
+    OUTPUT(NLS(MS_OPENPTS,  OPENPTS_COLLECTOR_USAGE_1,
+        "OpenPTS Collector\n\n"
+        "Usage: ptsc [options] [command]\n\n"
+        "Commands: (foreground)\n"
+        "  -i                    Initialize PTS collector\n"
+        "  -t                    Self test (attestation)\n"
+        "  -s                    Startup (selftest + timestamp)\n"
+        "  -u                    Update the RM\n"
+        "  -e                    Clear PTS collector\n"));
 #ifdef CONFIG_AUTO_RM_UPDATE
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_2,
-                    "  -U                    Update the RM (auto)\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_2,
+        "  -U                    Update the RM (auto)\n"));
 #endif
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_3,
-                    "  -D                    Display the configuration\n"
-                    "  -m                    IF-M mode\n"
-                    "\n"
-                    "Miscellaneous:\n"
-                    "  -h                    Show this help message\n"
-                    "  -v                    Verbose mode. Multiple -v options increase the verbosity.\n"
-                    "\n"
-                    "Options:\n"
-                    "  -c configfile         Set configuration file. defalt is %s\n"
-                    "  -P name=value         Set properties.\n"
-                    "  -R                    Remove RMs\n"
-                    "  -z                    Set the SRK secret to all zeros (20 bytes of zeros)\n"), PTSC_CONFIG_FILE);
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_USAGE_3,
+        "  -D                    Display the configuration\n"
+        "  -m                    IF-M mode\n"
+        "\n"
+        "Miscellaneous:\n"
+        "  -h                    Show this help message\n"
+        "  -v                    Verbose mode. Multiple -v options increase the verbosity.\n"
+        "\n"
+        "Options:\n"
+        "  -c configfile         Set configuration file. defalt is %s\n"
+        "  -P name=value         Set properties.\n"
+        "  -R                    Remove RMs\n"
+        "  -z                    Set the SRK secret to all zeros (20 bytes of zeros)\n"), PTSC_CONFIG_FILE);
 }
 
 enum COMMAND {
@@ -400,7 +401,7 @@ OPENPTS_PROPERTY *getPropertyFromArg(char *arg) {
         prop = newProperty(name, value);
         return prop;
     } else {
-        ERROR("bad property %s\n", arg);
+        LOG(LOG_ERR, "bad property %s\n", arg);
         return NULL;
     }
 }
@@ -435,7 +436,7 @@ void ptsc_lock(void) {
         }
         buf = xmalloc(buf_len);
         if (buf == NULL) {
-            ERROR("no memory");
+            LOG(LOG_ERR, "no memory");
             exit(1);
         }
 
@@ -454,7 +455,7 @@ void ptsc_lock(void) {
 
     oldmask = umask(0);
     if (mkdir(LOCK_DIR, 0775) < 0 && errno != EEXIST) {
-        ERROR("mkdir(%s) fail", LOCK_DIR);
+        LOG(LOG_ERR, "mkdir(%s) fail", LOCK_DIR);
         exit(1);
     }
     if (grpent) {
@@ -463,12 +464,12 @@ void ptsc_lock(void) {
     }
     fd = open(LOCK_FILE, O_RDWR | O_CREAT | O_TRUNC, 0660);
     if (fd < 0) {
-        ERROR("open(%s) fail", LOCK_DIR);
+        LOG(LOG_ERR, "open(%s) fail", LOCK_DIR);
         exit(1);
     }
     umask(oldmask);
     if (lockf(fd, F_LOCK, 0) < 0) {
-        ERROR("lockf(%s) fail", LOCK_DIR);
+        LOG(LOG_ERR, "lockf(%s) fail", LOCK_DIR);
         exit(1);
     }
 
@@ -488,7 +489,7 @@ static int preparePriv() {
 #if 0
     /* check UID */
     if ((ptscd_pwd = getpwnam_r(PTSCD_USER_NAME)) == NULL) {
-        ERROR("Looking up for user %s", PTSCD_USER_NAME);
+        LOG(LOG_ERR, "Looking up for user %s", PTSCD_USER_NAME);
         return PTS_FATAL;
     }
 #endif
@@ -496,7 +497,7 @@ static int preparePriv() {
     /* check GID */
     // ptsc_grp = getgrnam(PTSC_GROUP_NAME);  // TODO use getgrnam_r
     // if (ptsc_grp == NULL) {
-    //     ERROR("Looking up for group (name=%s) fail", PTSC_GROUP_NAME);
+    //     LOG(LOG_ERR, "Looking up for group (name=%s) fail", PTSC_GROUP_NAME);
     //     return PTS_FATAL;
     // }
     buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
@@ -505,18 +506,18 @@ static int preparePriv() {
     }
     buf = xmalloc(buf_len);
     if (buf == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
     rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
     if (rc != 0) {
-        ERROR("getgrnam_r(%s) fail", PTSC_GROUP_NAME);
+        LOG(LOG_ERR, "getgrnam_r(%s) fail", PTSC_GROUP_NAME);
         rc = PTS_FATAL;
         goto free;
     }
     if (ptsc_grp == NULL) {
-        ERROR("ptsc_grp == NULL");
+        LOG(LOG_ERR, "ptsc_grp == NULL");
         rc = PTS_FATAL;
         goto free;
     }
@@ -525,7 +526,7 @@ static int preparePriv() {
     rc = setgid(grp.gr_gid);
     if (rc < 0) {
         // TODO do not need for IF-M access (read only)
-        INFO("Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno));
+        LOG(LOG_INFO, "Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno));
         // TODO 20110927 FAIL
         rc = PTS_FATAL;
         goto free;
@@ -533,7 +534,7 @@ static int preparePriv() {
 
 #if 0
     if (setuid(ptscd_pwd->pw_uid) == -1) {
-        ERROR("Switching to user %s", PTSCD_USER_NAME);
+        LOG(LOG_ERR, "Switching to user %s", PTSCD_USER_NAME);
         return PTS_FATAL;
     }
 #endif
@@ -561,7 +562,7 @@ static int chmodDir(char *dirpath, int flag) {
     /* check GID */
     // ptsc_grp = getgrnam(PTSC_GROUP_NAME);  // TODO use getgrnam_r
     // if (ptsc_grp == NULL) {
-    //     ERROR("Looking up for group %s", PTSC_GROUP_NAME);
+    //     LOG(LOG_ERR, "Looking up for group %s", PTSC_GROUP_NAME);
     //     return PTS_FATAL;
     // }
     buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
@@ -570,18 +571,18 @@ static int chmodDir(char *dirpath, int flag) {
     }
     buf = xmalloc(buf_len);
     if (buf == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
 
     rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &ptsc_grp);
     if (rc != 0) {
-        ERROR("getgrnam_r");
+        LOG(LOG_ERR, "getgrnam_r");
         rc = PTS_FATAL;
         goto free;
     }
     if (ptsc_grp == NULL) {
-        ERROR("ptsc_grp == NULL");
+        LOG(LOG_ERR, "ptsc_grp == NULL");
         rc = PTS_FATAL;
         goto free;
     }
@@ -647,12 +648,12 @@ int main(int argc, char *argv[]) {
     // TODO chgrp
     rc = preparePriv();
     if (rc != PTS_SUCCESS) {
-        ERROR("preparePriv fail\n");
+        LOG(LOG_ERR, "preparePriv fail\n");
     }
 
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("internal error\n");  // TODO(munetoh)
+        LOG(LOG_ERR, "internal error\n");  // TODO(munetoh)
         return -1;
     }
 #endif
@@ -753,21 +754,16 @@ int main(int argc, char *argv[]) {
         // TODO chgrp
         rc = preparePriv();
         if (rc != PTS_SUCCESS) {
-            INFO("preparePriv fail\n");
+            LOG(LOG_INFO, "preparePriv fail\n");
         }
     }
 
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("internal error\n");  // TODO(munetoh)
+        LOG(LOG_ERR, "internal error\n");  // TODO(munetoh)
         return -1;
     }
 
-//#if 0  // TODO Renew in v0.2.6
-//    /* DEBUG level, 1,2,3 */
-//#ifdef OPENPTS_DEBUG
-//    setDebugFlags(DEBUG_FLAG | DEBUG_FSM_FLAG | DEBUG_IFM_FLAG);
-//#else
     /* set the DEBUG level, 1,2,3 */
     if (getVerbosity() > 2) {
         setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG );
@@ -776,8 +772,6 @@ int main(int argc, char *argv[]) {
     } else if (getVerbosity() > 0) {
         setDebugFlags(DEBUG_FLAG);
     }
-//#endif
-//#endif
 
     DEBUG("VERBOSITY (%d), DEBUG mode (0x%x)\n", getVerbosity(), getDebugFlags());
 
@@ -802,32 +796,32 @@ int main(int argc, char *argv[]) {
         }
     }
 
-    /* PTSC IF-M DEBUG MODE */
-    // TODO SET BY CONF
+    /* logging */
 
     /* Check initialization */
     if (command != COMMAND_INIT) {
         /* initilized? */
         if (checkFile(conf->uuid->filename) != OPENPTS_FILE_EXISTS) {
             // missing
-            printf("ptsc is not initialized yet.\n\n");
+            LOG(LOG_ERR, "ptsc is not initialized yet");
+            ERROR(  // TODO NLS
+                "ptsc is not initialized yet.\n\n");
             goto free;
         }
     }
 
-
     /* only do this when needed */
     if (command != COMMAND_STATUS) {
         /* check IR dir */
         if (checkDir(conf->ir_dir) != PTS_SUCCESS) {
             rc = makeDir(conf->ir_dir);
             if (rc != PTS_SUCCESS) {
-                ERROR("Can not create the dir to store IR, %s\n", conf->ir_dir);
+                LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
                 goto free;
             }
             rc = chmodDir(conf->ir_dir, 1);
             if (rc != PTS_SUCCESS) {
-                ERROR("Can not create the dir to store IR, %s\n", conf->ir_dir);
+                LOG(LOG_ERR, "Can not create the dir to store IR, %s\n", conf->ir_dir);
                 goto free;
             }
         }
@@ -851,7 +845,7 @@ int main(int argc, char *argv[]) {
 
     /* RM UUID */
     if (conf->rm_uuid == NULL) {
-        ERROR("rm_uuid is missing");
+        LOG(LOG_ERR, "rm_uuid is missing");
         /* Exit */
         goto free;
     } else {
@@ -872,7 +866,7 @@ int main(int argc, char *argv[]) {
 
     /* NEWRM UUID */
     if (conf->newrm_uuid == NULL) {
-        ERROR("newrm_uuid is missing.");
+        LOG(LOG_ERR, "newrm_uuid is missing.");
         /* Exit */
         goto free;
     } else {
@@ -888,7 +882,7 @@ int main(int argc, char *argv[]) {
     /* load RSA PUB key */
     // TODO single key => multiple keys?
 #ifdef CONFIG_NO_TSS
-    TODO("CONFIG_NO_TSS, no TPM_PUBKEY\n");
+    LOG(LOG_TODO, "CONFIG_NO_TSS, no TPM_PUBKEY\n");
     conf->pubkey_length = 0;
     conf->pubkey = NULL;
 #else
@@ -905,7 +899,7 @@ int main(int argc, char *argv[]) {
                 &conf->pubkey_length,
                 &conf->pubkey);
         if (rc != TSS_SUCCESS) {
-            ERROR("getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
+            LOG(LOG_ERR, "getTssPubKey() fail rc=0x%x srk password mode=%d, key =%s\n",
                 rc, conf->srk_password_mode, conf->uuid->str);
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE,
                 "TSS communications failure. Is tcsd running?\n"));
@@ -924,7 +918,7 @@ int main(int argc, char *argv[]) {
             /* update RMs */
             rc = update(conf, prop_num, start, end, remove);
             if (rc != PTS_SUCCESS) {
-                ERROR("update was fail\n");
+                LOG(LOG_ERR, "update was fail\n");
             }
             break;
 #endif
@@ -935,42 +929,42 @@ int main(int argc, char *argv[]) {
             rc = selftest(conf, prop_num, start, end);
             if (rc == OPENPTS_SELFTEST_SUCCESS) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
-                INFO("selftest - OK\n");
+                LOG(LOG_INFO, "selftest - OK\n");
             } else if (rc == OPENPTS_SELFTEST_RENEWED) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
-                INFO("selftest - Renewed\n");
+                LOG(LOG_INFO, "selftest - Renewed\n");
             } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
-                INFO("selftest - fallback\n");
+                LOG(LOG_INFO, "selftest - fallback\n");
             } else if (rc == OPENPTS_SELFTEST_FAILED) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
-                INFO("selftest - fail\n");
+                LOG(LOG_INFO, "selftest - fail\n");
             } else {
-                ERROR("TBD\n");
+                LOG(LOG_ERR, "TBD\n");
             }
             break;
         case COMMAND_STARTUP:
             rc = selftest(conf, prop_num, start, end);
             if (rc == OPENPTS_SELFTEST_SUCCESS) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
-                INFO("selftest - OK\n");
+                LOG(LOG_INFO, "selftest - OK\n");
                 /* timestamp */
                 extendEvCollectorStart(conf);  // collector.c
             } else if (rc == OPENPTS_SELFTEST_RENEWED) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
-                INFO("selftest - Renewed\n");
+                LOG(LOG_INFO, "selftest - Renewed\n");
                 /* timestamp */
                 extendEvCollectorStart(conf);
             } else if (rc == OPENPTS_SELFTEST_FALLBACK) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FALLBACK, "selftest - fallback\n"));
-                INFO("selftest - fallback\n");
+                LOG(LOG_INFO, "selftest - fallback\n");
                 /* timestamp */
                 extendEvCollectorStart(conf);
             } else if (rc == OPENPTS_SELFTEST_FAILED) {
                 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAIL, "selftest - fail\n"));
-                INFO("selftest - fail\n");
+                LOG(LOG_INFO, "selftest - fail\n");
                 if (conf->autoupdate == 1) {
-                    ERROR("selftest failed, trying to generate a new manifest\n");
+                    LOG(LOG_ERR, "selftest failed, trying to generate a new manifest\n");
                     /* del RM_UUID */
                     conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
                     if (conf->rm_uuid->uuid != NULL) freeUuid(conf->rm_uuid->uuid);
@@ -985,7 +979,7 @@ int main(int argc, char *argv[]) {
                     if (rc != PTS_SUCCESS) {
                         OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_FAIL,
                             "Failed to generated a reference manifest\n"));
-                        INFO("Failed to generated a reference manifest\n");
+                        LOG(LOG_INFO, "Failed to generated a reference manifest\n");
                         goto free;
                     }
                     rc = selftest(conf, prop_num, start, end);
@@ -993,21 +987,21 @@ int main(int argc, char *argv[]) {
                         OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SUCCESS, "selftest - OK\n"));
                         OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
                             "Successfully generated the reference manifest\n"));
-                        INFO("selftest - OK\n");
-                        INFO("Successfully generated the reference manifest\n");
+                        LOG(LOG_INFO, "selftest - OK\n");
+                        LOG(LOG_INFO, "Successfully generated the reference manifest\n");
                     } else if (rc == OPENPTS_SELFTEST_RENEWED) {
                         OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_RENEWED, "selftest - Renewed\n"));
-                        INFO("selftest - Renewed\n");
+                        LOG(LOG_INFO, "selftest - Renewed\n");
                     } else {
-                        ERROR("TBD\n");
+                        LOG(LOG_ERR, "TBD\n");
                     }
                 } else {
                     OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_WONT,
                         "selftest failed, keeping existing manifests as requested by configuration\n"));
-                    INFO("selftest failed, keeping existing manifests as requested by configuration\n");
+                    LOG(LOG_INFO, "selftest failed, keeping existing manifests as requested by configuration\n");
                 }
             } else {
-                ERROR("TBD\n");
+                LOG(LOG_ERR, "TBD\n");
             }
             break;
         case COMMAND_UPDATE:
@@ -1023,7 +1017,7 @@ int main(int argc, char *argv[]) {
             /* gen new RM_UUID and RM */
             rc = newrm(conf, prop_num, start, end);
             if (rc != PTS_SUCCESS) {
-                ERROR("newrm() fail\n");
+                LOG(LOG_ERR, "newrm() fail\n");
                 goto free;
             }
 
@@ -1033,9 +1027,9 @@ int main(int argc, char *argv[]) {
                 VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_UPDATE_RM_SUCCESS,
                     "Successfully generated the reference manifest\n"));
             } else if (rc == OPENPTS_SELFTEST_RENEWED) {
-                TODO("TBD\n");
+                LOG(LOG_TODO, "TBD\n");
             } else {
-                TODO("TBD\n");
+                LOG(LOG_TODO, "TBD\n");
             }
             break;
         case COMMAND_IFM:
@@ -1043,7 +1037,7 @@ int main(int argc, char *argv[]) {
             rc = collector2(conf);
             break;
         default:
-            ERROR("bad command\n");
+            LOG(LOG_ERR, "bad command\n");
             break;
     }
 
index c20071d..6238ea1 100644 (file)
@@ -103,10 +103,11 @@ void vlogn(unsigned msglevel, char *fmt, va_list ap) {
     vsnprintf(buf, LOGMAX, fmt, ap);
     va_end(ap);
     if (foreground) {
-        fprintf(stderr, "%s\n", buf);
+        ERROR(  // TODO NLS
+            "%s\n", buf);
         fflush(stderr);
     } else {
-        syslog(msglevel ? LOG_INFO : LOG_CRIT, "%s", buf);
+        syslog(msglevel ? LOG_INFO : LOG_CRIT, "%s", buf);  // TODO use LOG?
     }
 }
 
@@ -351,7 +352,7 @@ main(int argc, char **argv) {
 
     if (argc > 0) {
     usage:
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_PTSEVTD_USAGE,
+        OUTPUT(NLS(MS_OPENPTS, OPENPTS_PTSEVTD_USAGE,
             "syntax: ptsevtd [-df] [-p port] [-c command]\n"));
         exit(1);
     }
index 44ea732..7da896a 100644 (file)
@@ -48,7 +48,7 @@
 void freeReason(OPENPTS_REASON *reason) {
     /* check */
     if (reason == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -65,7 +65,7 @@ void freeReason(OPENPTS_REASON *reason) {
 int freeReasonChain(OPENPTS_REASON *reason) {
     /* check */
     if (reason == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -92,7 +92,7 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -103,7 +103,7 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
 
     reason = (OPENPTS_REASON *) xmalloc(sizeof(OPENPTS_REASON));
     if (reason == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return PTS_FATAL;
     }
     memset(reason, 0, sizeof(OPENPTS_REASON));
@@ -124,7 +124,7 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
     reason->pcr = pcr;
     reason->message = xmalloc(len +1);
     if (reason->message == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         xfree(reason);
         return PTS_FATAL;
     }
@@ -149,7 +149,7 @@ int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -217,7 +217,7 @@ void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     reason = ctx->reason_start;
index a7b1c0d..349bd6f 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -57,7 +57,7 @@ OPENPTS_RM_CONTEXT *newRmContext() {
 
     ctx = (OPENPTS_RM_CONTEXT *) xmalloc(sizeof(OPENPTS_RM_CONTEXT));
     if (ctx == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -70,7 +70,7 @@ OPENPTS_RM_CONTEXT *newRmContext() {
 void freeRmContext(OPENPTS_RM_CONTEXT *ctx) {
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -107,15 +107,15 @@ static int writeCoreComponentID(xmlTextWriterPtr writer,
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (id == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -214,7 +214,7 @@ static int writeCoreComponentID(xmlTextWriterPtr writer,
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeCoreComponentID - internal error\n");
+    LOG(LOG_ERR, "writeCoreComponentID - internal error\n");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -236,15 +236,15 @@ int writeCoreValues(xmlTextWriterPtr writer,
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (id == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (event == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -298,7 +298,7 @@ int writeCoreValues(xmlTextWriterPtr writer,
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeCoreValues() internal error");
+    LOG(LOG_ERR, "writeCoreValues() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -326,18 +326,18 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* Events at PCR[index] & Snapshot */
     eventWrapper = ss->start;
     if (eventWrapper == NULL) {
-        ERROR("writeAllCoreValues() - ERROR: eventWrapper is NULL\n");
+        LOG(LOG_ERR, "writeAllCoreValues() - ERROR: eventWrapper is NULL\n");
         return PTS_FATAL;
     }
     fsm_binary   = ss->fsm_binary;
@@ -347,7 +347,7 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
         DEBUG_FSM("writeAllCoreValues - PCR[%d] event %d/%d\n", ss->pcrIndex, j + 1, ss->event_num);
 
         if (eventWrapper == NULL) {
-            ERROR("writeAllCoreValues() - eventWrapper is NULL, pcr[%d], event_num = %d count = %d\n",
+            LOG(LOG_ERR, "writeAllCoreValues() - eventWrapper is NULL, pcr[%d], event_num = %d count = %d\n",
                 ss->pcrIndex, ss->event_num, j);
             return PTS_FATAL;
         }
@@ -355,7 +355,7 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
         event = eventWrapper->event;
 
         if (event == NULL) {
-            ERROR("writeAllCoreValues() - Event is missing\n");
+            LOG(LOG_ERR, "writeAllCoreValues() - Event is missing\n");
             return PTS_FATAL;
         }
 
@@ -377,11 +377,11 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
         bin_trans = bhv_trans->link;          // BHV keeps the link to BIN
         if (bin_trans == NULL) {  // TODO old
             UINT32 i;
-            ERROR("writeAllCoreValues() - BIN Trans is missing");
-            ERROR("\tat the event: pcrindex=%d, eventype=%d, digest=",
+            LOG(LOG_ERR, "writeAllCoreValues() - BIN Trans is missing");
+            LOG(LOG_ERR, "\tat the event: pcrindex=%d, eventype=%d, digest=",
                   event->ulPcrIndex, event->eventType);
             for (i = 0;i < event->ulPcrValueLength; i++)
-                ERROR("%02x", event->rgbPcrValue[i]);
+                LOG(LOG_ERR, "%02x", event->rgbPcrValue[i]);
             return PTS_FATAL;
         }
 
@@ -423,7 +423,7 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
                         DEBUG_FSM("LOOP, base64->real digest\n");
                         rc = insertFsmNew(fsm_binary, bin_trans, eventWrapper);
                         if (rc != PTS_SUCCESS) {
-                            ERROR("insertFsmNew() fail");
+                            LOG(LOG_ERR, "insertFsmNew() fail");
                             goto error;
                         }
                     } else {
@@ -445,12 +445,12 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
 
                 rc = writeCoreValues(writer, algtype, id, event);
                 if (rc != PTS_SUCCESS) {
-                    ERROR("writeCoreValues() fail");
+                    LOG(LOG_ERR, "writeCoreValues() fail");
                     goto error;
                 }
             }
         } else {  // NULL?
-            ERROR("ERROR no trans\n");
+            LOG(LOG_ERR, "ERROR no trans\n");
             rc = PTS_INTERNAL_ERROR;
             goto error;
         }
@@ -463,7 +463,7 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeCoreValues ERROR\n");
+    LOG(LOG_ERR, "writeCoreValues ERROR\n");
 
     return PTS_INTERNAL_ERROR;
 }
@@ -484,11 +484,11 @@ int writeFsmSubvertex(xmlTextWriterPtr writer,
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (sub == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -532,7 +532,7 @@ int writeFsmSubvertex(xmlTextWriterPtr writer,
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeFsmSubvertex() internal error");
+    LOG(LOG_ERR, "writeFsmSubvertex() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -559,11 +559,11 @@ int writeFsmTransition(xmlTextWriterPtr writer,
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (trans == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -659,7 +659,7 @@ int writeFsmTransition(xmlTextWriterPtr writer,
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeFsmTransition() internal error");
+    LOG(LOG_ERR, "writeFsmTransition() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -691,11 +691,11 @@ int writeFsmModel(xmlTextWriterPtr writer, OPENPTS_FSM_CONTEXT * fsm) {
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (fsm == NULL) {
-        ERROR("writeFsmModel - FSM is NULL");
+        LOG(LOG_ERR, "writeFsmModel - FSM is NULL");
         return PTS_FATAL;
     }
 
@@ -772,7 +772,7 @@ int writeFsmModel(xmlTextWriterPtr writer, OPENPTS_FSM_CONTEXT * fsm) {
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeFsmModel() internal error");
+    LOG(LOG_ERR, "writeFsmModel() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -799,11 +799,11 @@ int writeValidationModel(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ss == NULL) {
-        ERROR("writeValidationModel - OPENPTS_SNAPSHOT is NULL\n");
+        LOG(LOG_ERR, "writeValidationModel - OPENPTS_SNAPSHOT is NULL\n");
         return PTS_FATAL;
     }
 
@@ -831,7 +831,7 @@ int writeValidationModel(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
     // TODO(munetoh)
     rc = writeFsmModel(writer, ss->fsm_binary);
     if (rc < 0) {
-        ERROR("writeValidationModel() pcr=%d BIN-FSM is NULL\n", ss->pcrIndex);
+        LOG(LOG_ERR, "writeValidationModel() pcr=%d BIN-FSM is NULL\n", ss->pcrIndex);
         goto error;
     }
 
@@ -843,7 +843,7 @@ int writeValidationModel(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeValidationModel() internal error");
+    LOG(LOG_ERR, "writeValidationModel() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -862,11 +862,11 @@ int writeCoreAssertionInfo(xmlTextWriterPtr writer, OPENPTS_CONTEXT * ctx, int l
 
     /* check */
     if (writer == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -886,7 +886,7 @@ int writeCoreAssertionInfo(xmlTextWriterPtr writer, OPENPTS_CONTEXT * ctx, int l
         if ((ss != NULL) && (ss->event_num > 0)) {
             rc = writeValidationModel(writer, ss);
             if (rc < 0) {
-                ERROR("writeCoreAssertionInfo() - pcr=%d, level=%d\n", i, level);
+                LOG(LOG_ERR, "writeCoreAssertionInfo() - pcr=%d, level=%d\n", i, level);
                 goto error;
             }
         }
@@ -902,7 +902,7 @@ int writeCoreAssertionInfo(xmlTextWriterPtr writer, OPENPTS_CONTEXT * ctx, int l
     return PTS_SUCCESS;
 
   error:
-    ERROR("writeCoreAssertionInfo() internal error");
+    LOG(LOG_ERR, "writeCoreAssertionInfo() internal error");
     return PTS_INTERNAL_ERROR;
 }
 
@@ -932,11 +932,11 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (file == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -944,7 +944,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* Create a new XML buffer */
     buf = xmlBufferCreate();
     if (buf == NULL) {
-        ERROR("Error creating the xml buffer\n");
+        LOG(LOG_ERR, "Error creating the xml buffer\n");
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
@@ -952,7 +952,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* Create a new XmlWriter for memory */
     writer = xmlNewTextWriterMemory(buf, 0);
     if (writer == NULL) {
-        ERROR("Error creating the xml writer\n");
+        LOG(LOG_ERR, "Error creating the xml writer\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
@@ -961,7 +961,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* indent the XML :-) */
     rc = xmlTextWriterSetIndent(writer, 1);  // libxml2
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterSetIndent\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterSetIndent\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -970,7 +970,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* Start the document */
     rc = xmlTextWriterStartDocument(writer, "1.0", XML_ENCODING, "no");
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterStartDocument\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterStartDocument\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -978,7 +978,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* Start an element named "Report", the root element of the document. */
     rc = xmlTextWriterStartElement(writer, BAD_CAST "Rimm");
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterStartElement\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -986,13 +986,13 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* new UUID */
     ir_uuid = newUuid();
     if (ir_uuid == NULL) {
-        ERROR("UUID gen\n");
+        LOG(LOG_ERR, "UUID gen\n");
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
     }
     str_ir_uuid = getStringOfUuid(ir_uuid);
     if (str_ir_uuid == NULL) {
-        ERROR("UUID gen\n");
+        LOG(LOG_ERR, "UUID gen\n");
         xfree(ir_uuid);
         rc = PTS_INTERNAL_ERROR;
         goto freexml;
@@ -1005,7 +1005,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
             BAD_CAST "xmlns:core",
             BAD_CAST XMLNS_CORE);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1014,7 +1014,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
             BAD_CAST "xmlns:stuff",
             BAD_CAST XMLNS_STUFF);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1023,7 +1023,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
             BAD_CAST "xmlns:xsi",
             BAD_CAST XMLNS_XSI);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1032,7 +1032,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
             BAD_CAST "xmlns",
             BAD_CAST XMLNS_RIMM);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1042,7 +1042,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
 
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Id", BAD_CAST id);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1050,7 +1050,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     // TODO(munetoh) set the level
     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "RevLevel", BAD_CAST "0");
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1059,7 +1059,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     rc = xmlTextWriterWriteAttribute(writer,
                                      BAD_CAST "UUID", BAD_CAST str_ir_uuid);
     if (rc < 0) {
-        ERROR("Error at xmlTextWriterWriteAttribute\n");
+        LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1091,7 +1091,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
                 /* copy BHV-FSM to BIN-FSM */
                 ss->fsm_binary = copyFsm(ss->fsm_behavior);
                 if (ss->fsm_binary == NULL) {
-                    ERROR("writeRm() - copy BHV-FSM to BIN-FSM failed at pcr=%d, level=%d\n", i, level);
+                    LOG(LOG_ERR, "writeRm() - copy BHV-FSM to BIN-FSM failed at pcr=%d, level=%d\n", i, level);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1100,7 +1100,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
                 rc = writeAllCoreValues(writer, ss);
                 if (rc != PTS_SUCCESS) {
                     // WORK NEEDED: Please use NLS for i18n
-                    ERROR("writeAllCoreValues() fail");
+                    LOG(LOG_ERR, "writeAllCoreValues() fail");
                     addReason(ctx, i,
                         "[RM] The manifest generation was failed at pcr=%d, level=%d", i, level);
                     addReason(ctx, i,
@@ -1116,7 +1116,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
                 // single FSM supports various (BIOS) implementations.
                 rc = cleanupFsm(ss->fsm_binary);
                 if (rc != PTS_SUCCESS) {
-                    ERROR("writeRm() - bad IML or FSM at pcr=%d, level=%d\n", i, level);
+                    LOG(LOG_ERR, "writeRm() - bad IML or FSM at pcr=%d, level=%d\n", i, level);
                     rc = PTS_INTERNAL_ERROR;
                     goto free;
                 }
@@ -1131,7 +1131,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* add FSMs */
     rc = writeCoreAssertionInfo(writer, ctx, level);
     if (rc != PTS_SUCCESS) {
-        ERROR("writeRm - ERROR file %s\n", file);
+        LOG(LOG_ERR, "writeRm - ERROR file %s\n", file);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1141,7 +1141,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
 
     rc = writeCoreComponentID(writer, id, ctx, level);
     if (rc != PTS_SUCCESS) {
-        ERROR("writeRm - ERROR file %s\n", file);
+        LOG(LOG_ERR, "writeRm - ERROR file %s\n", file);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1149,14 +1149,14 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     /* Close all elements */
     rc = xmlTextWriterEndDocument(writer);  // libxml2
     if (rc < 0) {
-        ERROR("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
+        LOG(LOG_ERR, "testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
 
     rc = xmlTextWriterFlush(writer);  // libxml2
     if (rc < 0) {
-        ERROR("writeRm: Error at xmlTextWriterFlush\n");
+        LOG(LOG_ERR, "writeRm: Error at xmlTextWriterFlush\n");
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
@@ -1164,13 +1164,13 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
 
     fp = fopen(file, "w");
     if (fp == NULL) {
-        ERROR("writeRm - fopen fail, file, %s\n", file);
+        LOG(LOG_ERR, "writeRm - fopen fail, file, %s\n", file);
         rc = PTS_INTERNAL_ERROR;
         goto free;
     }
 
     if (fprintf(fp, "%s", (const char *) buf->content) <= 0) {
-        ERROR("Failed to write to file %s\n", file);
+        LOG(LOG_ERR, "Failed to write to file %s\n", file);
         rc = PTS_INTERNAL_ERROR;
     } else {
         rc = PTS_SUCCESS;
@@ -1191,7 +1191,7 @@ int writeRm(OPENPTS_CONTEXT * ctx, const char *file, int level) {
     xmlBufferFree(buf);
 
     if (rc != PTS_SUCCESS) {
-        ERROR("writeRm - fail");
+        LOG(LOG_ERR, "writeRm - fail");
     } else {
         DEBUG_FSM("writeRm - done\n");
     }
@@ -1223,17 +1223,17 @@ void  rmStartDocument(void * ctx) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     if (pctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     rm_ctx = pctx->rm_ctx;
     if (rm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -1268,11 +1268,11 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -1310,10 +1310,10 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
                     if (!strcmp(type, "level")) {
                         int level = atoi(value);
                         if (level != rm_ctx->level) {
-                            TODO("RM level is %d not %d\n", level, rm_ctx->level);
+                            LOG(LOG_TODO, "RM level is %d not %d\n", level, rm_ctx->level);
                             rm_ctx->level = level;
                             if (level < 0 || level >= MAX_RM_NUM) {
-                                ERROR("level found in RM (%d) is greater or equal to MAX_RM_NUM (%d)\n",
+                                LOG(LOG_ERR, "level found in RM (%d) is greater or equal to MAX_RM_NUM (%d)\n",
                                     level, MAX_RM_NUM);
                                 return;
                             }
@@ -1331,7 +1331,7 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         /*new SS */
         rm_ctx->snapshot = getNewSnapshotFromTable(pctx->ss_table, rm_ctx->pcr_index, rm_ctx->level);
         if (rm_ctx->snapshot == NULL) {
-            ERROR("SS is NULL\n");
+            LOG(LOG_ERR, "SS is NULL\n");
             return;
         }
 
@@ -1361,10 +1361,8 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "xmi:type")) {
                         snprintf(rm_ctx->subvertex_xmitype, sizeof(rm_ctx->subvertex_xmitype),
                                  "%s", value);
@@ -1392,10 +1390,8 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "source")) {
                         snprintf(rm_ctx->source_xmiid, sizeof(rm_ctx->source_xmiid), "%s", value);
                     }
@@ -1410,10 +1406,8 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "name")) {
                         snprintf(rm_ctx->doactivity_name, sizeof(rm_ctx->doactivity_name),
                                  "%s", value);
@@ -1422,7 +1416,7 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
             }
         }
         DEBUG_SAX("doActivity %s\n", rm_ctx->doactivity_name);
-        // ERROR("doActivity %s\n", rm_ctx->doactivity_name);
+        // LOG(LOG_ERR, "doActivity %s\n", rm_ctx->doactivity_name);
     } else if (!strcmp((char *)name, "name")) {
         // TODO(munetoh)
     } else if (!strcmp((char *)name, "ownedRule")) {
@@ -1476,7 +1470,7 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
             } else if (strcmp(attributeName, "DiscretePatches") == 0) {
                 attributeValue = &pctx->compIDs[level].DiscretePatches;
             } else {
-                ERROR("unknown attribute for Component ID: '%s'\n", attributeName);
+                LOG(LOG_ERR, "unknown attribute for Component ID: '%s'\n", attributeName);
                 attrIdx++;  // attribute
                 attrIdx++;  // skip
                 continue;
@@ -1525,7 +1519,7 @@ void  rmStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
         // VendorID_Value
 
     } else {
-        ERROR("Unknown  ELEMENT [%s] \n", name);
+        LOG(LOG_ERR, "Unknown  ELEMENT [%s] \n", name);
         rm_ctx->sax_state = RM_SAX_STATE_IDLE;
     }
 }
@@ -1540,21 +1534,21 @@ void rmEndElement(void * ctx, const xmlChar * name) {
 
     /* check*/
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (name == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     if (pctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     rm_ctx = pctx->rm_ctx;
     if (rm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -1571,7 +1565,7 @@ void rmEndElement(void * ctx, const xmlChar * name) {
             rm_ctx->subvertex_name,
             rm_ctx->doactivity_name);
         // DEBUG
-        // ERROR("doActivity %s\n", rm_ctx->doactivity_name);
+        // LOG(LOG_ERR, "doActivity %s\n", rm_ctx->doactivity_name);
     } else if (!strcmp((char *)name, "transition")) {
         DEBUG_SAX("add transition %s -> %s\n",
             rm_ctx->source_xmiid, rm_ctx->target_xmiid);
@@ -1606,21 +1600,21 @@ void rmCharacters(void* ctx, const xmlChar * ch, int len) {
 
     /* check*/
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (ch == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     pctx = (OPENPTS_CONTEXT *)ctx;
     if (pctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     rm_ctx = pctx->rm_ctx;
     if (rm_ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -1666,11 +1660,11 @@ int readRmFile(OPENPTS_CONTEXT *ctx, const char *filename, int level) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1681,7 +1675,7 @@ int readRmFile(OPENPTS_CONTEXT *ctx, const char *filename, int level) {
     } else {
         /* use existing table */
         // TODO
-        // ERROR("SS TABLE exist\n");
+        // LOG(LOG_ERR, "SS TABLE exist\n");
     }
 
     /* SAX variables */
@@ -1693,7 +1687,7 @@ int readRmFile(OPENPTS_CONTEXT *ctx, const char *filename, int level) {
     }
 
     if (level < 0 || level >= MAX_RM_NUM) {
-        ERROR("readRmFile - level (%d) is greater or equal to MAX_RM_NUM (%d)\n", level, MAX_RM_NUM);
+        LOG(LOG_ERR, "readRmFile - level (%d) is greater or equal to MAX_RM_NUM (%d)\n", level, MAX_RM_NUM);
         return -1;
     }
     ctx->rm_ctx->level = level;
@@ -1737,7 +1731,7 @@ int getRmSetDir(OPENPTS_CONFIG *conf) {
 
     /* check*/
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1754,8 +1748,8 @@ int getRmSetDir(OPENPTS_CONFIG *conf) {
 
         if (lstat(buf, &st) == -1) {
             /* Missing conf dir => Error */
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_RM_CONF_DIR_MISSING,
-                        "The configuration directory '%s' is missing. Please initialize the collector first\n"), buf);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_RM_CONF_DIR_MISSING,
+                "The configuration directory '%s' is missing. Please initialize the collector first\n"), buf);
             rc = PTS_INTERNAL_ERROR;
             goto end;
         }
@@ -1774,7 +1768,7 @@ int getRmSetDir(OPENPTS_CONFIG *conf) {
             DEBUG("RM File                      : %s\n", conf->rm_filename[i]);
         }
     } else {
-        TODO("getRmSetDir() - conf->rm_basedir == NULL\n");
+        LOG(LOG_TODO, "getRmSetDir() - conf->rm_basedir == NULL\n");
     }
     rc = PTS_SUCCESS;
 
@@ -1796,7 +1790,7 @@ int getNewRmSetDir(OPENPTS_CONFIG *conf) {
 
     /* check*/
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1838,7 +1832,7 @@ int getNewRmSetDir(OPENPTS_CONFIG *conf) {
             DEBUG("NEWRM File                  : %s\n", conf->newrm_filename[i]);
         }
     } else {
-        TODO("getNewRmSetDir() - conf->rm_basedir == NULL\n");
+        LOG(LOG_TODO, "getNewRmSetDir() - conf->rm_basedir == NULL\n");
     }
     rc = PTS_SUCCESS;
 
@@ -1856,7 +1850,7 @@ int makeRmSetDir(OPENPTS_CONFIG *conf) {
 
     /* check*/
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1870,7 +1864,7 @@ int makeRmSetDir(OPENPTS_CONFIG *conf) {
 
         rc = makeDir(buf);
         if (rc != PTS_SUCCESS) {
-            ERROR("create conf directory, %s was failed\n", buf);
+            LOG(LOG_ERR, "create conf directory, %s was failed\n", buf);
             rc = PTS_INTERNAL_ERROR;
             goto end;
         }
@@ -1900,7 +1894,7 @@ int makeNewRmSetDir(OPENPTS_CONFIG *conf) {
 
     /* check*/
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
index 3ca3708..043cfde 100644 (file)
  * usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_RM2DOT_USAGE, "usage: rm2dot [options] RMfile \n"
-                    "\t-o output\tset output file (default is stdout)\n"
-                    "\t-p pcrindex\tset PCR index\n"
-                    "\t-l level\tset snapshot level (0 or 1)\n"
-                    "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
-                    "\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_RM2DOT_USAGE,
+        "usage: rm2dot [options] RMfile \n"
+        "\t-o output\tset output file (default is stdout)\n"
+        "\t-p pcrindex\tset PCR index\n"
+        "\t-l level\tset snapshot level (0 or 1)\n"
+        "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
+        "\n"));
 }
 
 /**
@@ -116,7 +117,8 @@ int main(int argc, char *argv[]) {
     /* Read RM(XML) file */
 
     if (input_filename == NULL) {
-        printf(NLS(MS_OPENPTS, OPENPTS_RM2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
+        ERROR(NLS(MS_OPENPTS, OPENPTS_RM2DOT_MISSING_XML_FILE,
+            "Missing XML file\n"));
         usage();
         return -1;
     }
@@ -124,20 +126,20 @@ int main(int argc, char *argv[]) {
     /* new pts context */
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("ERROR\n");
+        LOG(LOG_ERR, "ERROR\n");
         return -1;
     }
 
     ctx = newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("ERROR\n");
+        LOG(LOG_ERR, "ERROR\n");
         return -1;
     }
 
     /* read RM */
     rc = readRmFile(ctx, input_filename, 0);
     if (rc != PTS_SUCCESS) {
-        ERROR("ERROR readRmFile\n");
+        LOG(LOG_ERR, "ERROR readRmFile\n");
         goto error;
     }
 
@@ -146,13 +148,14 @@ int main(int argc, char *argv[]) {
     } else if (level == 1) {
         ss =  getSnapshotFromTable(ctx->ss_table, pcr_index, 1);
     } else {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_RM2DOT_BAD_LEVEL, "ERROR bad level %d\n"), level);
+        ERROR(NLS(MS_OPENPTS, OPENPTS_RM2DOT_BAD_LEVEL,
+            "Bad level %d, the level should be 0 or 1\n"), level);
         goto error;
     }
 
     rc = writeDotModel(ss->fsm_binary, output_filename);
     if (rc != PTS_SUCCESS) {
-        ERROR("ERROR writeDotModel\n");
+        LOG(LOG_ERR, "ERROR writeDotModel\n");
         goto error;
     }
 
index 6d2396e..310f267 100644 (file)
@@ -26,7 +26,7 @@
  * \brief parse SMBIOS info
  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
  * @date 2010-08-29
- * cleanup 2011-01-22 SM
+ * cleanup 2012-01-03 SM
  *
  * SMBIOS Info in BIOS IML -> platform properties
  *
@@ -79,7 +79,7 @@ int genSmbiosFileByDmidecode(char * filename) {
     /* exec dmidecode */
     pid = fork();
     if (pid < 0) {
-        ERROR("\n");
+        LOG(LOG_ERR, "\n");
         return -1;
     }
     if (pid == 0) {
@@ -94,13 +94,13 @@ int genSmbiosFileByDmidecode(char * filename) {
         // DEBUG("status = %d\n", status);
         if (WIFEXITED(status)) {
             /* 1 : OK */
-            TODO("Exit status %d\n", WEXITSTATUS(status));
+            LOG(LOG_TODO, "Exit status %d\n", WEXITSTATUS(status));
             return 1;
         } else if (WIFSIGNALED(status)) {
-            ERROR("Signal status %d\n", WIFSIGNALED(status));
+            LOG(LOG_ERR, "Signal status %d\n", WIFSIGNALED(status));
             return -1;
         } else {
-            ERROR("Bad exit");
+            LOG(LOG_ERR, "Bad exit");
             return -1;
         }
     }
@@ -129,7 +129,7 @@ int readSmbiosFile(char * filename, BYTE **data, int *len) {
     }
 
     if ((fp = fopen(filename, "rb")) == NULL) {
-        ERROR("%s missing\n", filename);
+        LOG(LOG_ERR, "%s missing\n", filename);
         rc = PTS_INTERNAL_ERROR;
         goto error;
     }
@@ -171,26 +171,18 @@ int printSmbios(BYTE *data, int length) {
         /* */
         str_length = ptr[0x16] + (ptr[0x17]<<8);
         str_num = ptr[0x1C] + (ptr[0x1D]<<8);
-        printf(NLS(MS_OPENPTS, OPENPTS_SMBIOS_STRUCTURES,
-            "%d structures occupying %d bytes.\n"), str_num, str_length);
         eod = ptr + str_length + 32;
         // SKIP Head
         ptr += 32;
     }
 
-
-
     while (1) {
         type = ptr[0];
         len = ptr[1];
         handle = ptr[2] + ptr[3]*256;
-        printf(NLS(MS_OPENPTS, OPENPTS_SMBIOS_HANDLE,
-            "Handle 0x%04x, DMI type %d(0x%x), %d bytes\n"), handle, type, type, len);
-        printHex(NLS(MS_OPENPTS, OPENPTS_SMBIOS_HEAD, "  head"), ptr, len, "\n");
 
         if (type == 127) {
-            printf(NLS(MS_OPENPTS, OPENPTS_SMBIOS_END_OF_TABLE, "End Of Table\n"));
-            // printf("%ld\n", ptr - data);
+            // End Of Table
             break;
         }
 
@@ -202,7 +194,7 @@ int printSmbios(BYTE *data, int length) {
         }
 
         if (ptr >  eod) {
-            printf(NLS(MS_OPENPTS, OPENPTS_SMBIOS_END_OF_TABLE, "End Of Table\n"));
+            // End Of Table
             break;
         }
 
@@ -216,9 +208,6 @@ int printSmbios(BYTE *data, int length) {
         ptr++;
         ptr++;
 
-        printHex(NLS(MS_OPENPTS, OPENPTS_SMBIOS_BODY, "  body"), strings, ptr - strings, "\n");
-
-
         if (ptr > eod) {
             break;
         }
@@ -275,7 +264,6 @@ int parseSmbios(OPENPTS_CONTEXT *ctx, BYTE *data, int length) {
     BYTE *strings[10];  // TODO size
     BYTE *eod = data + length;
     int str_length;
-    // int str_num;
     int cnt = 0;
     int scnt;
     OPENPTS_CONFIG *conf = ctx->conf;
@@ -285,7 +273,6 @@ int parseSmbios(OPENPTS_CONTEXT *ctx, BYTE *data, int length) {
         /* */
         str_length = ptr[0x16] + (ptr[0x17]<<8);
         // str_num = ptr[0x1C] + (ptr[0x1D]<<8);
-        // printf("%d structures occupying %d bytes.\n", str_num, str_length);
         eod = ptr + str_length + 32;
         // SKIP Head
         ptr += 32;
@@ -300,12 +287,9 @@ int parseSmbios(OPENPTS_CONTEXT *ctx, BYTE *data, int length) {
         type = ptr[0];
         len = ptr[1];
         handle = ptr[2] + ptr[3]*256;
-        // printf("Handle 0x%04x, DMI type %d(0x%x), %d bytes\n", handle, type,type, len);
-        // printHex("  head",ptr, len, "\n");
 
         if (type == 127) {
-            // printf("End Of Table\n");
-            // printf("%ld\n", ptr - data);
+            // End Of Table
             break;
         }
 
@@ -318,7 +302,6 @@ int parseSmbios(OPENPTS_CONTEXT *ctx, BYTE *data, int length) {
         }
 
         if (ptr >  eod) {
-            // printf("End Of Table\n");
             break;
         }
 
@@ -336,12 +319,6 @@ int parseSmbios(OPENPTS_CONTEXT *ctx, BYTE *data, int length) {
         ptr++;
         ptr++;
 
-        // printHex("  body", strings[0], ptr - strings[0], "\n");
-        // printf("  scnt %d\n",scnt);
-        // for (i=0;i<scnt;i++) {
-        //     printf("    %d %s\n",i, strings[i]);
-        // }
-
         /* to config  */
         switch (type) {
             case 0x0: /* BIOS Information */
index cedeaf2..bea28d8 100644 (file)
@@ -96,7 +96,7 @@ OPENPTS_SNAPSHOT * newSnapshot() {
 
     ss = (OPENPTS_SNAPSHOT*) xmalloc(sizeof(OPENPTS_SNAPSHOT));  // leaked
     if (ss == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(ss, 0, sizeof(OPENPTS_SNAPSHOT));
@@ -119,7 +119,7 @@ int freeSnapshot(OPENPTS_SNAPSHOT * ss) {
 
     /* check */
     if (ss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -159,7 +159,7 @@ OPENPTS_SNAPSHOT_TABLE * newSnapshotTable() {
 
     sst = (OPENPTS_SNAPSHOT_TABLE *) xmalloc(sizeof(OPENPTS_SNAPSHOT_TABLE));  // leaked
     if (sst == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(sst, 0, sizeof(OPENPTS_SNAPSHOT_TABLE));
@@ -178,7 +178,7 @@ int freeSnapshotTable(OPENPTS_SNAPSHOT_TABLE * sst) {
 
     /* check */
     if (sst == NULL) {
-        ERROR(" OPENPTS_SNAPSHOT_TABLE was NULL\n");
+        LOG(LOG_ERR, " OPENPTS_SNAPSHOT_TABLE was NULL\n");
         return PTS_FATAL;
     }
 
@@ -202,26 +202,26 @@ int freeSnapshotTable(OPENPTS_SNAPSHOT_TABLE * sst) {
 int addSnapshotToTable(OPENPTS_SNAPSHOT_TABLE * sst, OPENPTS_SNAPSHOT * ss, int pcr_index, int level) {
     /* check 1 */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (ss == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index )) {
-        ERROR("bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "bad PCR index, %d\n", pcr_index);
         return PTS_INTERNAL_ERROR;
     }
     if ((level < 0) || (MAX_SSLEVEL <= level)) {
-        ERROR("bad level, %d\n", level);
+        LOG(LOG_ERR, "bad level, %d\n", level);
         return PTS_INTERNAL_ERROR;
     }
 
     /* check 2 */
     if (sst->snapshot[pcr_index][level] != NULL) {
-        ERROR("snapshot[%d][%d] already exist", pcr_index, level);
+        LOG(LOG_ERR, "snapshot[%d][%d] already exist", pcr_index, level);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -239,16 +239,16 @@ int addSnapshotToTable(OPENPTS_SNAPSHOT_TABLE * sst, OPENPTS_SNAPSHOT * ss, int
 OPENPTS_SNAPSHOT *getSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index, int level) {
     /* check 1 */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
         return NULL;
     }
     if ((level < 0) || (MAX_SSLEVEL <= level)) {
-        ERROR("getSnapshotFromTable() - bad level, %d\n", level);
+        LOG(LOG_ERR, "getSnapshotFromTable() - bad level, %d\n", level);
         return NULL;
     }
 
@@ -269,16 +269,16 @@ OPENPTS_SNAPSHOT *getSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_ind
 OPENPTS_SNAPSHOT *getNewSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index, int level) {
     /* check 1 */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
         return NULL;
     }
     if ((level < 0) || (MAX_SSLEVEL <= level)) {
-        ERROR("getSnapshotFromTable() - bad level, %d\n", level);
+        LOG(LOG_ERR, "getSnapshotFromTable() - bad level, %d\n", level);
         return NULL;
     }
 
@@ -290,7 +290,7 @@ OPENPTS_SNAPSHOT *getNewSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_
         sst->snapshot[pcr_index][level]->pcrIndex = pcr_index;
         sst->snapshot[pcr_index][level]->level = level;
     } else {
-        ERROR("getNewSnapshotFromTable() - SS pcr=%d,level=%d already exist\n", pcr_index, level);
+        LOG(LOG_ERR, "getNewSnapshotFromTable() - SS pcr=%d,level=%d already exist\n", pcr_index, level);
         return NULL;
     }
 
@@ -305,12 +305,12 @@ OPENPTS_SNAPSHOT *getActiveSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int p
     int level;
     /* check 1 */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "getSnapshotFromTable() - bad PCR index, %d\n", pcr_index);
         return NULL;
     }
 
@@ -327,16 +327,16 @@ OPENPTS_SNAPSHOT *getActiveSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int p
 int setActiveSnapshotLevel(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index, int level) {
     /* check */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("setActiveSnapshotLevel() - bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "setActiveSnapshotLevel() - bad PCR index, %d\n", pcr_index);
         return PTS_INTERNAL_ERROR;
     }
     if ((level < 0) || (MAX_SSLEVEL <= level)) {
-        ERROR("setActiveSnapshotLevel() - bad level, %d\n", level);
+        LOG(LOG_ERR, "setActiveSnapshotLevel() - bad level, %d\n", level);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -351,12 +351,12 @@ int setActiveSnapshotLevel(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index, int leve
 int incActiveSnapshotLevel(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index) {
     /* check */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "bad PCR index, %d\n", pcr_index);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -372,12 +372,12 @@ int incActiveSnapshotLevel(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index) {
 int getActiveSnapshotLevel(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_index) {
     /* check */
     if (sst == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
     if ((pcr_index < 0) || (MAX_PCRNUM <= pcr_index)) {
-        ERROR("bad PCR index, %d\n", pcr_index);
+        LOG(LOG_ERR, "bad PCR index, %d\n", pcr_index);
         return PTS_INTERNAL_ERROR;
     }
 
index 7b3a894..250bd42 100644 (file)
--- a/src/ssh.c
+++ b/src/ssh.c
@@ -63,19 +63,19 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file
 
     /* check */
     if (host == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
 
     /* socket */
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair) == -1) {
-        ERROR("socketpair() fail");
+        LOG(LOG_ERR, "socketpair() fail");
         goto err;
     }
 
     if ((pid = fork()) == -1) {
-        ERROR("fork() fail");
+        LOG(LOG_ERR, "fork() fail");
         goto err_close;
     }
 
@@ -130,7 +130,7 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file
         DEBUG("ptsc_command %s\n", ptsc_command);
 
         execvp("ssh", arguments);
-        ERROR("execvp(ssh)");
+        LOG(LOG_ERR, "execvp(ssh)");
         exit(1);
     }
 
index 504645c..bd43c07 100644 (file)
@@ -63,11 +63,11 @@ int cmpDateTime(PTS_DateTime *time1, PTS_DateTime *time2) {
 
     /* check */
     if (time1 == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
     if (time2 == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -120,7 +120,7 @@ static int selectUuidDir(const struct dirent *entry) {
 
     /* check */
     if (entry == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return 0;
     }
 
@@ -166,40 +166,37 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) {
     int dir_num;
     struct dirent **dir_list;
     int i, j;
-
     char         *tmp_str_uuid;
     PTS_UUID     *tmp_uuid;
     PTS_DateTime *tmp_time;
     int           tmp_state;
     char         *tmp_dir;
-
     OPENPTS_RMSET *rmset;
     OPENPTS_RMSET *rmset1;
     OPENPTS_RMSET *rmset2;
 
-    // printf("Show RMs by UUID\n");
-    // printf("config dir                  : %s\n", config_dir);
-
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (config_dir == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     /* move to config dir */
     if ((chdir(conf->config_dir)) != 0) {
-        fprintf(stderr, "Accessing config directory %s\n", conf->config_dir);
+        ERROR(  // TODO NLS
+            "Accessing config directory %s\n", conf->config_dir);
         return PTS_INTERNAL_ERROR;
     }
 
     /* scan dirs */
     dir_num = scandir(".", &dir_list, &selectUuidDir, NULL);
     if ( dir_num == -1 ) {
-        fprintf(stderr, "no target data\n");
+        ERROR( // TODO NLS
+            "No target data.\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -215,7 +212,7 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) {
     for (cnt = 0; cnt < dir_num; cnt++) {
         rmset = &conf->rmsets->rmset[cnt];
         if (rmset == NULL) {
-            ERROR("no memory cnt=%d\n", cnt);
+            LOG(LOG_ERR, "no memory cnt=%d\n", cnt);
             return PTS_INTERNAL_ERROR;
         }
         rmset->str_uuid = smalloc(dir_list[cnt]->d_name);
@@ -250,12 +247,9 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) {
     /* sort (bub) */
     for (i = 0; i< dir_num - 1; i++) {
         for (j = dir_num - 1; j > i; j--) {
-            // printf("i=%d, j=%d\n",i,j);
             rmset1 = &conf->rmsets->rmset[j-1];
             rmset2 = &conf->rmsets->rmset[j];
             if (cmpDateTime(rmset1->time, rmset2->time) > 0) {
-                // printf("%d <-> %d\n", j-1, j);
-
                 tmp_str_uuid = rmset2->str_uuid;
                 tmp_uuid     = rmset2->uuid;
                 tmp_time     = rmset2->time;
@@ -321,7 +315,7 @@ int rmRmsetDir(char * dir) {
 
     /* check */
     if (dir == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -353,11 +347,11 @@ int purgeRenewedRm(OPENPTS_CONFIG *conf) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (conf->rmsets == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -369,7 +363,8 @@ int purgeRenewedRm(OPENPTS_CONFIG *conf) {
         state = rmset->state;
 
         if (state == OPENPTS_RM_STATE_TRASH) {
-            INFO(NLS(MS_OPENPTS, OPENPTS_PURGE_RENEWED_RM, "  purge %s\n"), rmset->str_uuid);
+            // INFO(NLS(MS_OPENPTS, OPENPTS_PURGE_RENEWED_RM, "  purge %s\n"), rmset->str_uuid);
+            LOG(LOG_INFO, "  purge %s\n", rmset->str_uuid);
             rc = rmRmsetDir(rmset->dir);
             if (rc != PTS_SUCCESS) {
                 rc2 = PTS_OS_ERROR;
@@ -390,11 +385,11 @@ void printRmList(OPENPTS_CONFIG *conf, char *indent) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (conf->rmsets == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -465,11 +460,11 @@ int getTargetList(OPENPTS_CONFIG *conf, char * config_dir) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (config_dir == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (conf->target_list != NULL) {
@@ -478,14 +473,14 @@ int getTargetList(OPENPTS_CONFIG *conf, char * config_dir) {
 
     /* move to config dir */
     if ((chdir(conf->config_dir)) != 0) {
-        ERROR("Accessing config directory %s\n", conf->config_dir);
+        LOG(LOG_ERR, "Accessing config directory %s\n", conf->config_dir);
         return PTS_INTERNAL_ERROR;
     }
 
     /* scan dirs */
     dir_num = scandir(".", &dir_list, &selectUuidDir, NULL);
     if ( dir_num == -1 ) {
-        ERROR("no target data\n");
+        LOG(LOG_ERR, "no target data\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -523,7 +518,7 @@ int getTargetList(OPENPTS_CONFIG *conf, char * config_dir) {
         /* set RM UUID (Mandatory) */
         rc = readOpenptsUuidFile(target_conf->rm_uuid);
         if (rc != PTS_SUCCESS) {
-            ERROR("getTargetList() - readOpenptsUuidFile() fail rc=%d\n", rc);
+            LOG(LOG_ERR, "getTargetList() - readOpenptsUuidFile() fail rc=%d\n", rc);
             freeOpenptsUuid(target_conf->rm_uuid);
             target_conf->rm_uuid = NULL;
             return  PTS_INTERNAL_ERROR;
@@ -574,15 +569,15 @@ char *getTargetConfDir(OPENPTS_CONFIG *conf) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (conf->hostname == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (conf->target_list == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -621,11 +616,11 @@ OPENPTS_TARGET *getTargetCollector(OPENPTS_CONFIG *conf) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (conf->hostname == NULL) {
-        ERROR("null hostname");
+        LOG(LOG_ERR, "null hostname");
         return NULL;
     }
     if (conf->target_list == NULL) {
@@ -668,15 +663,15 @@ OPENPTS_TARGET *getTargetCollectorByUUID(OPENPTS_CONFIG *conf, const char *uuid)
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (conf->target_list == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
@@ -769,18 +764,19 @@ void printTargetList(OPENPTS_CONFIG *conf, char *indent) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
     if (conf->target_list == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
     num = conf->target_list->target_num;
 
     if (num == 0) {
-        printf("There is no enrolled target platform.\n");
+        OUTPUT(  // TODO NLS
+            "There is no enrolled target platform.\n");
         return;
     }
 
@@ -817,7 +813,6 @@ void printTargetList(OPENPTS_CONFIG *conf, char *indent) {
                 target_conf->ssh_port ? target_conf->ssh_port : "default");
         } else {
             DEBUG("target[%d] is NULL, SKIP\n", cnt);
-            // printf("--\n");
         }
     }
     OUTPUT("%s%s\n", indent, SEP_LINE);
index c9a5a61..0bb5979 100644 (file)
@@ -78,11 +78,11 @@ unsigned char pcr[MAX_PCRNUM][SHA1_DIGEST_SIZE];
 void debugPrintHex(char *head, BYTE *data, int num, char *tail) {
     int i;
     if (verbose > 0) {
-        printf("%s", head);
+        OUTPUT("%s", head);
         for (i = 0; i < num; i++) {
-            printf("%02X", data[i]);
+            OUTPUT("%02X", data[i]);
         }
-        printf("%s", tail);
+        OUTPUT("%s", tail);
     }
 }
 
@@ -161,7 +161,7 @@ int parseTxtStatFile(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
     if (filename != NULL) {
         /* open */
         if ((fp = fopen(filename, "r")) == NULL) {
-            ERROR("parseTxtStatFile - %s file is missing\n", filename);
+            LOG(LOG_ERR, "parseTxtStatFile - %s file is missing\n", filename);
             return PTS_FATAL;  // TODO
         }
     } else {
@@ -482,7 +482,7 @@ int sinit_acm_hash(char *filename, int size, BYTE *sha1_digest, BYTE *sha256_dig
     /* open */
     fp = fopen(filename, "rb");
     if (fp == NULL) {
-        ERROR("File %s does not exist\n", filename);
+        LOG(LOG_ERR, "File %s does not exist\n", filename);
         rc = PTS_FATAL;
         goto error;
     }
@@ -543,7 +543,7 @@ int sha1sum_unzip(char *filename, int *filesize, BYTE *digest) {
     /* open */
     fp = gzopen(filename, "rb");
     if (fp == NULL) {
-        ERROR("File %s does not exist\n", filename);
+        LOG(LOG_ERR, "File %s does not exist\n", filename);
         return 0;
     }
 
@@ -592,7 +592,7 @@ int parseGrubConfFile(OPENPTS_TBOOT_CONTEXT *ctx, char *filename, char *path) {
 
     /* open */
     if ((fp = fopen(filename, "r")) == NULL) {
-        ERROR("parseTxtStatFile - %s file is missing\n", filename);
+        LOG(LOG_ERR, "parseTxtStatFile - %s file is missing\n", filename);
         return PTS_FATAL;  // TODO
     }
 
@@ -846,7 +846,7 @@ int emulateTboot(OPENPTS_TBOOT_CONTEXT *ctx) {
         extend(17, digest);
         debugPrintHex("  mle v8 PCR17 ", &pcr[17][0], 20, "\n");
     } else {
-        ERROR("mle_version = %d \n", ctx->mle_version);
+        LOG(LOG_ERR, "mle_version = %d \n", ctx->mle_version);
     }
 
     extend(18, ctx->mle_hash);
@@ -879,12 +879,12 @@ int emulateTboot(OPENPTS_TBOOT_CONTEXT *ctx) {
 
     /* check (within TXT-STAT) */
     if (memcmp(&pcr[17][0], ctx->final_pcr17, 20) != 0) {
-        ERROR("bad PCR17\n");
+        LOG(LOG_ERR, "bad PCR17\n");
         printHex("PCR-17", &pcr[17][0], 20, "\n");
         rc = PTS_FATAL;
     }
     if (memcmp(&pcr[18][0], ctx->final_pcr18, 20) != 0) {
-        ERROR("bad PCR18\n");
+        LOG(LOG_ERR, "bad PCR18\n");
         printHex("PCR-18", &pcr[18][0], 20, "\n");
         rc = PTS_FATAL;
     }
@@ -925,7 +925,7 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
     if (filename != NULL) {
         /* open */
         if ((fp = fopen(filename, "wb")) == NULL) {
-            ERROR("generateEventlog - %s file can't open\n", filename);
+            LOG(LOG_ERR, "generateEventlog - %s file can't open\n", filename);
             return PTS_FATAL;  // TODO
         }
     } else {
@@ -1010,9 +1010,9 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
 
 
     } else if (ctx->mle_version == 8) {
-         TODO("TBD mle_version = %d \n", ctx->mle_version);
+         LOG(LOG_TODO, "TBD mle_version = %d \n", ctx->mle_version);
     } else {
-         TODO("TBD mle_version = %d \n", ctx->mle_version);
+         LOG(LOG_TODO, "TBD mle_version = %d \n", ctx->mle_version);
     }
 
 
@@ -1064,7 +1064,7 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
 
         module = ctx->module;
         if (memcmp(module->digest, ctx->vl_pcr18, 20) != 0) {
-            ERROR("Module[0] digest did not match\n");
+            LOG(LOG_ERR, "Module[0] digest did not match\n");
             debugPrintHex("  TXT-STAT : ", ctx->vl_pcr18, 20, "\n");
             debugPrintHex("  Calc     : ", module->digest, 20, "\n");
         }
@@ -1107,7 +1107,7 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
 
         module = ctx->module->next;
         if (memcmp(module->digest, ctx->vl_pcr19, 20) != 0) {
-            ERROR("Module[1] digest did not match\n");
+            LOG(LOG_ERR, "Module[1] digest did not match\n");
             debugPrintHex("  TXT-STAT : ", ctx->vl_pcr19, 20, "\n");
             debugPrintHex("  Calc     : ", module->digest, 20, "\n");
         }
@@ -1158,16 +1158,17 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
 
 
 void usage(void) {
-    fprintf(stderr, "OpenPTS command\n\n");
-    fprintf(stderr, "Usage: tboot2iml [options]\n\n");
-    fprintf(stderr, "Options:\n");
-    fprintf(stderr, "  -i filename           txt-stat file to read (default is STDIN)\n");
-    fprintf(stderr, "  -g filename           grub.conf file to read (OPTION)\n");
-    fprintf(stderr, "  -p path               grub path (OPTION)\n");
-    fprintf(stderr, "  -o filename           Output to file (default is STDOUT)\n");
-    fprintf(stderr, "  -v                    Verbose message\n");
-    fprintf(stderr, "  -h                    Help\n");
-    fprintf(stderr, "\n");
+    OUTPUT( // TODO NLS
+        "OpenPTS command\n\n"
+        "Usage: tboot2iml [options]\n\n"
+        "Options:\n"
+        "  -i filename           txt-stat file to read (default is STDIN)\n"
+        "  -g filename           grub.conf file to read (OPTION)\n"
+        "  -p path               grub path (OPTION)\n"
+        "  -o filename           Output to file (default is STDOUT)\n"
+        "  -v                    Verbose message\n"
+        "  -h                    Help\n"
+        "\n");
 }
 
 int main(int argc, char *argv[]) {
@@ -1206,11 +1207,10 @@ int main(int argc, char *argv[]) {
         }
     }
 
-    // printf("tboot to IML (%s)\n", txt_stat_filename);
-
     /* check */
     if ((grub_conf_filename != NULL) && (grub_path == NULL)) {
-        fprintf(stderr, "set the root path used by crub.conf\n");
+        ERROR(  // TODO NLS
+            "set the root path used by crub.conf\n");
         usage();
         goto close;
     }
@@ -1223,7 +1223,7 @@ int main(int argc, char *argv[]) {
     /* parse TXT stat */
     rc = parseTxtStatFile(ctx, txt_stat_filename);
     if (rc != PTS_SUCCESS) {
-        ERROR("parse of %s file was failed\n", txt_stat_filename);
+        LOG(LOG_ERR, "parse of %s file was failed\n", txt_stat_filename);
     }
 
     /* parse grub.conf */
index ba08d9f..f4416e9 100644 (file)
--- a/src/tpm.c
+++ b/src/tpm.c
@@ -59,7 +59,7 @@ int resetTpm(OPENPTS_TPM_CONTEXT *tctx, int drtm) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("ERROR TPM_CONTEXT is NULL");
+        LOG(LOG_ERR, "ERROR TPM_CONTEXT is NULL");
         return -1;
     }
 
@@ -91,7 +91,7 @@ int resetTpmPcr(OPENPTS_TPM_CONTEXT *tctx, int index) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("ERROR TPM_CONTEXT is NULL");
+        LOG(LOG_ERR, "ERROR TPM_CONTEXT is NULL");
         return -1;
     }
 
@@ -112,7 +112,7 @@ int isZero(BYTE * digest) {
 
     /* check */
     if (digest == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return -1;
     }
 
@@ -133,7 +133,7 @@ void setFF(BYTE * digest) {
 
     /* check */
     if (digest == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -156,28 +156,28 @@ int extendTpm(OPENPTS_TPM_CONTEXT *tctx, TSS_PCR_EVENT *event) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("TPM_CONTEXT is NULL\n");
+        LOG(LOG_ERR, "TPM_CONTEXT is NULL\n");
         return PTS_FATAL;
     }
     if (event == NULL) {
-        ERROR("TSS_PCR_EVENT is NULL\n");
+        LOG(LOG_ERR, "TSS_PCR_EVENT is NULL\n");
         return PTS_FATAL;
     }
 
     digest = event->rgbPcrValue;
     if (digest == NULL) {
-        ERROR("event->rgbPcrValue is NULL\n");
+        LOG(LOG_ERR, "event->rgbPcrValue is NULL\n");
         return PTS_FATAL;
     }
 
     index = event->ulPcrIndex;
     if (index >= MAX_PCRNUM) {
-        ERROR("BAD PCR INDEX %d >= %d\n", index, MAX_PCRNUM);
+        LOG(LOG_ERR, "BAD PCR INDEX %d >= %d\n", index, MAX_PCRNUM);
         return PTS_INTERNAL_ERROR;
     }
 
     if (index < 0) {
-        ERROR("ERROR BAD PCR INDEX %d < 0\n", index);
+        LOG(LOG_ERR, "ERROR BAD PCR INDEX %d < 0\n", index);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -216,16 +216,16 @@ int extendTpm2(OPENPTS_TPM_CONTEXT *tctx, int index, BYTE * digest) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("TPM_CONTEXT is NULL\n");
+        LOG(LOG_ERR, "TPM_CONTEXT is NULL\n");
         return PTS_FATAL;
     }
     if (digest == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
 
     if (index >= MAX_PCRNUM) {
-        ERROR("BAD pcr index, %d >= %d", index, MAX_PCRNUM);
+        LOG(LOG_ERR, "BAD pcr index, %d >= %d", index, MAX_PCRNUM);
         return PTS_INTERNAL_ERROR;
     }
 
@@ -263,7 +263,7 @@ int checkTpmPcr2(OPENPTS_TPM_CONTEXT *tctx, int index, BYTE * digest) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("TPM_CONTEXT is NULL\n");
+        LOG(LOG_ERR, "TPM_CONTEXT is NULL\n");
         return PTS_FATAL;
     }
 
@@ -283,7 +283,7 @@ int printTpm(OPENPTS_TPM_CONTEXT *tctx) {
 
     /* check */
     if (tctx == NULL) {
-        ERROR("TPM_CONTEXT is NULL\n");
+        LOG(LOG_ERR, "TPM_CONTEXT is NULL\n");
         return PTS_FATAL;
     }
 
@@ -308,19 +308,19 @@ int getTpmPcrValue(OPENPTS_TPM_CONTEXT *tpm, int index, BYTE *digest) {
 
     /* check */
     if (tpm == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (digest == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (index >= MAX_PCRNUM) {
-        ERROR("BAD PCR INDEX %d >= %d\n", index, MAX_PCRNUM);
+        LOG(LOG_ERR, "BAD PCR INDEX %d >= %d\n", index, MAX_PCRNUM);
         return PTS_INTERNAL_ERROR;
     }
     if (index < 0) {
-        ERROR("ERROR BAD PCR INDEX %d < 0\n", index);
+        LOG(LOG_ERR, "ERROR BAD PCR INDEX %d < 0\n", index);
         return PTS_INTERNAL_ERROR;
     }
 
index 17d2092..40f6962 100644 (file)
@@ -72,8 +72,7 @@ const char short_option[] = "u:flNPt:a:hSUB:Cvz";
 int hex2bin(void *dest, const void *src, size_t n);
 
 void usage() {
-//<<<<<<< HEAD
-    printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_USAGE,
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_USAGE,
            "Usage: tpm_createkey [options]\n"
            "\t-h           Display command usage info.\n"
            "\t-u           Set UUID of key. Default is randum number\n"
@@ -86,22 +85,6 @@ void usage() {
            "\t-S           Use SYSTEM_PS\n"
            "\t-U           Use USER_PS\n"
            "\t-B filename  Use blob file\n"));
-//=======
-//    printf("Usage: tpm_createkey [options]\n");
-//    printf("\t-h\tDisplay command usage info.\n");
-//    printf("\t-u\tSet UUID of key. Default is randum number\n");
-//    printf("\t-N\tCreate key without auth secret\n");
-//    printf("\t-a PASSWORD\tCreate key with auth secret, PASSWORD\n");
-//    printf("\t-P\tUse TSS diaglog to set the authsecret\n");
-//    printf("\t-C\tUse common authsecret\n");
-//    printf("\t-f\tUpdate the key\n");
-//    printf("\t-z\tUse the SRK secret of all zeros (20 bytes of zeros).\n");
-
-//    /* Key storage */
-///    printf("\t-S\tUse SYSTEM_PS\n");
-//    printf("\t-U\tUse USER_PS\n");
-//    printf("\t-B\tUse blob file\n");
-//>>>>>>> 042e40b0979f3e44e75200271e4d1282ce08f72c
 }
 
 int hex2bin(void *dest, const void *src, size_t n) {
@@ -110,7 +93,7 @@ int hex2bin(void *dest, const void *src, size_t n) {
     unsigned char *ussrc = (unsigned char *) src;
 
     if (n & 0x01) {
-        ERROR("ERROR: hex2bin wrong size %d\n", (int)n);
+        LOG(LOG_ERR, "ERROR: hex2bin wrong size %d\n", (int)n);
         return -1;
     }
 
@@ -217,7 +200,7 @@ int main(int argc, char *argv[]) {
         switch (so) {
         case 'u':  /* UUID of AIK/SignKey */
             if (strlen(optarg) != 32) {
-                printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_INVALID_UUID_SIZE, "ERROR invalid UUID size, %s\n"),
+                OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_INVALID_UUID_SIZE, "ERROR invalid UUID size, %s\n"),
                        optarg);
                 usage();
                 return -1;
@@ -279,14 +262,11 @@ int main(int argc, char *argv[]) {
         }
     }
 
-    printf("SM DEBUG\n");
-
     if (noauth != 1) {
         /* key needs authorization */
         initFlag |= TSS_KEY_AUTHORIZATION;
     }
 
-
     /* SRK well_known = 0x00 x 20 */
     if (srk_password_mode == 1) {
         srk_auth = xmalloc(20);
@@ -306,14 +286,14 @@ int main(int argc, char *argv[]) {
 
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Create failed rc=0x%x\n",
                result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -335,14 +315,14 @@ int main(int argc, char *argv[]) {
                     ppKeyHierarchy);
 
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: Tspi_Context_GetRegisteredKeysByUUID failed rc=0x%x\n",
+            LOG(LOG_ERR, "ERROR: Tspi_Context_GetRegisteredKeysByUUID failed rc=0x%x\n",
              result);
         } else {
             int i;
             TSS_KM_KEYINFO *info = ppKeyHierarchy[0];
-            printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_KEYNUM, "Key number   : %d\n"), ulKeyHierarchySize);
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_KEYNUM, "Key number   : %d\n"), ulKeyHierarchySize);
             for (i = 0; i < (int)ulKeyHierarchySize; i++) {
-                printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_KEY, "Key %d\n"), i);
+                OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_KEY, "Key %d\n"), i);
                 buf = (BYTE *) & info->versionInfo;
                 printHex(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_VERSION, " version     : "), buf, 4, "\n");
                 buf = (BYTE *) & info->keyUUID;
@@ -360,7 +340,7 @@ int main(int argc, char *argv[]) {
 
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -373,10 +353,10 @@ int main(int argc, char *argv[]) {
                                         &hSRK);
 
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
               result);
         if (result == 0x2020) {
-            printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_BAD_STORAGE,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_BAD_STORAGE,
                 "The key storage for tcsd is damaged or missing.\n"));
         }
         goto close;
@@ -386,7 +366,7 @@ int main(int argc, char *argv[]) {
 
     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
     if (result != TSS_SUCCESS) {
-        printf("ERROR: Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -397,7 +377,7 @@ int main(int argc, char *argv[]) {
                 srk_auth_len,
                 srk_auth);
     if (result != TSS_SUCCESS) {
-        printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -407,7 +387,7 @@ int main(int argc, char *argv[]) {
     if (createUuid == 1) {
         result = Tspi_TPM_GetRandom(hTPM, sizeof(TSS_UUID), &buf);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_TPM_GetRandom failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_TPM_GetRandom failed rc=0x%x\n",
                   result);
             Tspi_Context_FreeMemory(hContext, NULL);
             goto close;
@@ -425,7 +405,7 @@ int main(int argc, char *argv[]) {
                                        TSS_OBJECT_TYPE_RSAKEY,
                                        initFlag, &hKey);
     if (result != TSS_SUCCESS) {
-        printf("ERROR: Tspi_Context_CreateObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -440,49 +420,16 @@ int main(int argc, char *argv[]) {
         char *ps1;
         int size0, size1;
 
-#if 0
-        // result = Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &hKeyPolicy);
-
-        // -a option
-        result =
-            Tspi_Context_CreateObject(hContext,
-                                      TSS_OBJECT_TYPE_POLICY,
-                                      TSS_POLICY_USAGE,
-                                      &hKeyPolicy);
-
-        if (result != TSS_SUCCESS) {
-            printf
-            ("ERROR: Tspi_GetPolicyObject failed rc=0x%x\n",
-             result);
-            goto close;
-        }
-#endif
 
         if (popup == 1) {
-#if 0
-            result = Tspi_SetAttribUint32(
-                        hContext,
-                        TSS_TSPATTRIB_CONTEXT_SILENT_MODE,
-                        0,
-                        TSS_TSPATTRIB_CONTEXT_NOT_SILENT);
-
-            if (result != TSS_SUCCESS) {
-                printf
-                ("ERROR: Tspi_SetAttribUint32 failed rc=0x%x, TSS_TSPATTRIB_CONTEXT_NOT_SILENT\n",
-                 result);
-                goto close;
-            }
-#endif
             result = Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &hKeyPolicy);
             if (result != TSS_SUCCESS) {
-                printf("ERROR: Tspi_GetPolicyObject failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                       result);
                 goto close;
             }
 
             /* popup - set message */
-#if 1
-            // TODO did not work???
             // char *popupMsg = "Signature Key Password";
             uint16_t popupMsg[] = {
                 'S', 'e', 't', ' ',
@@ -490,8 +437,6 @@ int main(int argc, char *argv[]) {
                 'K', 'e', 'y', ' ',
                 'P', 'a', 's', 's', 'w', 'o', 'r', 'd'
             };
-            // printf("DEBUG popupMsg %s\n",popupMsg);
-            // printf("POPUP\n");
             result = Tspi_SetAttribData(
                         hKeyPolicy,
                         TSS_TSPATTRIB_POLICY_POPUPSTRING,
@@ -500,23 +445,21 @@ int main(int argc, char *argv[]) {
                         (BYTE *) popupMsg);
 
             if (result != TSS_SUCCESS) {
-                printf("ERROR: Tspi_SetAttribData failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_SetAttribData failed rc=0x%x\n",
                       result);
                 goto close;
             }
-#endif
+
             /* popup - go */
-            // printf("POPUP\n");
             result = Tspi_Policy_SetSecret(hKeyPolicy,
                                            TSS_SECRET_MODE_POPUP,
                                            0, NULL);
 
             if (result != TSS_SUCCESS) {
-                printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x @POPUP\n",
+                LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x @POPUP\n",
                       result);
                 goto close;
             }
-            // printf("POPUP\n");
         } else {  // CUI or commandline
             result =
                 Tspi_Context_CreateObject(hContext,
@@ -525,7 +468,7 @@ int main(int argc, char *argv[]) {
                                           &hKeyPolicy);
 
             if (result != TSS_SUCCESS) {
-                ERROR("ERROR: Tspi_Context_CreateObject failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                       result);
                 goto close;
             }
@@ -542,14 +485,14 @@ int main(int argc, char *argv[]) {
                 size1 = strlen(ps1);
 
                 if (size0 != size1) {
-                    printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_PASSWORD_MISMATCH, "Passwords didn't match %d %d\n"),
+                    ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_PASSWORD_MISMATCH, "Passwords didn't match %d %d\n"),
                            size0, size1);
                     xfree(ps0);
                     goto close;
                 }
 
                 if (strncmp(ps0, ps1, size0) != 0) {
-                    printf(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_PASSWORD_MISMATCH_2, "Passwords didn't match %d\n"),
+                    ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_CREATEKEY_PASSWORD_MISMATCH_2, "Passwords didn't match %d\n"),
                      strncmp(ps0, ps1, size0));
                     xfree(ps0);
                     goto close;
@@ -583,7 +526,7 @@ int main(int argc, char *argv[]) {
                                            len,
                                            (BYTE *) str);
             if (result != TSS_SUCCESS) {
-                ERROR("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                       result);
                 goto close;
             }
@@ -591,7 +534,7 @@ int main(int argc, char *argv[]) {
             result = Tspi_Policy_AssignToObject(hKeyPolicy, hKey);
 
             if (result != TSS_SUCCESS) {
-                ERROR("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                       result);
                 goto close;
             }
@@ -605,8 +548,7 @@ int main(int argc, char *argv[]) {
                         TSS_POLICY_USAGE,
                         &hKeyPolicy);
             if (result != TSS_SUCCESS) {
-                printf
-                ("ERROR: Tspi_Context_CreateObject failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                  result);
                 goto close;
             }
@@ -617,8 +559,7 @@ int main(int argc, char *argv[]) {
                         strlen(TPMSIGKEY_SECRET),
                         (BYTE *)TPMSIGKEY_SECRET);
             if (result != TSS_SUCCESS) {
-                printf
-                ("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                  result);
                 goto close;
             }
@@ -627,20 +568,17 @@ int main(int argc, char *argv[]) {
                         hKeyPolicy,
                         hKey);
             if (result != TSS_SUCCESS) {
-                printf
-                ("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                  result);
                 goto close;
             }
         }
     }
 
-    printf("SM DEBUG call Tspi_Key_CreateKey()\n");
-
     result = Tspi_Key_CreateKey(hKey, hSRK, 0);
 
     if (result != TSS_SUCCESS) {
-        printf("ERROR: Tspi_Key_CreateKey failed rc=0x%04x\n",
+        LOG(LOG_ERR, "Tspi_Key_CreateKey failed rc=0x%04x\n",
               result);
         goto close;
     }
@@ -651,7 +589,6 @@ int main(int argc, char *argv[]) {
         /* save as blob */
         fp = fopen(filename, "w");
 
-        printf("SM DEBUG save to %s\n",filename);
         result = Tspi_GetAttribData(
                      hKey,
                      TSS_TSPATTRIB_KEY_BLOB,
@@ -660,7 +597,7 @@ int main(int argc, char *argv[]) {
                      &keyBlob);
 
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_GetAttribData failed rc=0x%04x\n",
+            LOG(LOG_ERR, "Tspi_GetAttribData failed rc=0x%04x\n",
                   result);
             fclose(fp);
             goto close;
@@ -694,21 +631,21 @@ int main(int argc, char *argv[]) {
                                                    uuid,
                                                    &hKey);
                     if (result != TSS_SUCCESS) {
-                        ERROR("ERROR: Tspi_Context_UnregisterKey failed rc=0x%x\n",
+                        LOG(LOG_ERR, "ERROR: Tspi_Context_UnregisterKey failed rc=0x%x\n",
                               result);
                     } else {
                         /* try again */
                         goto regkey;
                     }
                 } else {
-                    printf("ERROR: Tspi_Context_RegisterKey failed rc=0x%x\n",
+                    LOG(LOG_ERR, "Tspi_Context_RegisterKey failed rc=0x%x\n",
                           result);
-                    printf("       TSS_E_KEY_ALREADY_REGISTERED\n");
+                    ERROR("       TSS_E_KEY_ALREADY_REGISTERED\n");
                     buf = (BYTE *) & uuid;
                     printHex("       uuid=", buf, 16, "\n");
                 }
             } else {
-                printf("ERROR: Tspi_Context_RegisterKey failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_Context_RegisterKey failed rc=0x%x\n",
                       result);
             }
             goto close;
index 2b15cf2..6eafe03 100644 (file)
@@ -94,7 +94,7 @@ int hex2bin(void *dest, const void *src, size_t n) {
     unsigned char *ussrc = (unsigned char *) src;
 
     if (n & 0x01) {
-        ERROR("ERROR: hex2bin wrong size %d\n", (int)n);
+        LOG(LOG_ERR, "ERROR: hex2bin wrong size %d\n", (int)n);
         return -1;
     }
 
@@ -126,15 +126,15 @@ int hex2bin(void *dest, const void *src, size_t n) {
 }
 
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_USAGE,
-                    "OpenPTS command\n\n"
-                    "Usage: tpm_extendpcr [options] filename\n\n"
-                    "  filename              file to be measured\n"
-                    "Options:\n"
-                    "  -p pcr_index          Set PCR index to extend\n"
-                    "  -t event_type         Set event type\n"
-                    "  -h                    Help\n"
-                    "\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_USAGE,
+        "OpenPTS command\n\n"
+        "Usage: tpm_extendpcr [options] filename\n\n"
+        "  filename              file to be measured\n"
+        "Options:\n"
+        "  -p pcr_index          Set PCR index to extend\n"
+        "  -t event_type         Set event type\n"
+        "  -h                    Help\n"
+        "\n"));
 }
 
 
@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
     filename = argv[0];
 
     if (filename == NULL) {
-        printf("ERROR: missing filename\n");
+        ERROR("Missing filename\n");
         usage();
         goto end;
     }
@@ -210,14 +210,14 @@ int main(int argc, char *argv[]) {
     /* TSS open */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
               result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -225,7 +225,7 @@ int main(int argc, char *argv[]) {
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -242,14 +242,14 @@ int main(int argc, char *argv[]) {
                                     &prgbRespData);
 
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_TPM_GetCapability() failed, rc=0x%x\n", result);
         goto close;
     }
 
     pcrnum = * (UINT32 *) prgbRespData;
     if (pcrindex > (int) pcrnum) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_BAD_RANGE,
-            "ERROR: pcrindex %d is out of range, this must be 0 to %d\n"),
+        ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_BAD_RANGE,
+            "pcrindex %d is out of range, this must be 0 to %d\n"),
             pcrindex, pcrnum);
         goto close;
     }
@@ -266,7 +266,7 @@ int main(int argc, char *argv[]) {
 
 
         if ((fd = open(filename, O_RDONLY)) < 0) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_OPEN_FAIL,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_OPEN_FAIL,
                 "Failed to open file '%s'\n"), filename);
             goto close;
         }
@@ -274,12 +274,12 @@ int main(int argc, char *argv[]) {
         fileLength = lseek(fd, 0, SEEK_END);
         if (fileLength < 0) {
             // WORK NEEDED: Please use NLS for i18n
-            fprintf(stderr, "file %s seek fail\n", filename);
+            ERROR("file %s seek fail\n", filename);
             goto close;
         }
 
         if ((fileMap = mmap(NULL, fileLength, PROT_READ, MAP_SHARED, fd, 0)) == NULL) {
-            perror("mmap");
+            ERROR("mmap fail\n");
             exit(1);
         }
 
@@ -316,11 +316,11 @@ int main(int argc, char *argv[]) {
                         &prgbPcrValue);
 
             if (result != TSS_SUCCESS) {
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FAILED,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FAILED,
                     "Failed to extend PCR at event %d\n"), eventCount);
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_INDEX,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_INDEX,
                     " pcr index: %d\n"), pcrEvent.ulPcrIndex);
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_EVENT_TYPE,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_EVENT_TYPE,
                     " event type: 0x%x\n"), pcrEvent.eventType);
                 exit(1);
             }
@@ -339,13 +339,13 @@ int main(int argc, char *argv[]) {
         close(fd);
 
         if (getVerbosity() > 0) {
-            printf(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FED_TPM,
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FED_TPM,
                 "Fed the TPM/log with %d events\n"), eventCount);
         }
     } else {
         /* File => mmap */
         if ((fd = open(filename, O_RDONLY)) < 0) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_OPEN_FAIL,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_OPEN_FAIL,
                 "Failed to open file '%s'"), filename);
             goto close;
         }
@@ -353,7 +353,7 @@ int main(int argc, char *argv[]) {
         fileLength = lseek(fd, 0, SEEK_END);
 
         if ((fileMap = mmap(NULL, fileLength, PROT_READ, MAP_SHARED, fd, 0)) == NULL) {
-            perror("mmap");
+            ERROR("mmap fail\n");
             exit(1);
         }
 
@@ -365,7 +365,7 @@ int main(int argc, char *argv[]) {
         memcpy(fscan->filename, filename, filename_len);
 
         if (stat(filename, &stat_buf) != 0) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_STAT_FAILED,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_EXTENDPCR_STAT_FAILED,
                 "Failed to retrieve file information for '%s'\n"), filename);
             exit(1);
         }
@@ -381,7 +381,7 @@ int main(int argc, char *argv[]) {
         SHA1_Final(fscan->fileDigest, &sha_ctx);
 
         if (getVerbosity() > 0) {
-            printf(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FILENAME, "Filename: %s\n"), filename);
+            OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_FILENAME, "Filename: %s\n"), filename);
             printHex(NLS(MS_OPENPTS, OPENPTS_TPM_EXTENDPCR_DIGEST, "Digest: "), fscan->fileDigest, 20, "");
         }
 
@@ -408,7 +408,7 @@ int main(int argc, char *argv[]) {
                                     &ulPcrValueLength,
                                     &rgbPcrValue);
         if (result != TSS_SUCCESS) {
-            ERROR("ERROR: failed rc=0x%x\n", result);
+            LOG(LOG_ERR, "ERROR: failed rc=0x%x\n", result);
             goto free;
         }
 
index 8c47a02..dc640e9 100644 (file)
@@ -65,7 +65,7 @@ int hex2bin(void *dest, const void *src, size_t n) {
     unsigned char *ussrc = (unsigned char *) src;
 
     if (n & 0x01) {
-        ERROR("ERROR: hex2bin wrong size %d\n", (int)n);
+        LOG(LOG_ERR, "ERROR: hex2bin wrong size %d\n", (int)n);
         return -1;
     }
 
@@ -98,10 +98,10 @@ int hex2bin(void *dest, const void *src, size_t n) {
 
 void printhex(char *str, unsigned char *buf, int len) {
     int i;
-    printf("%s", str);
+    OUTPUT("%s", str);
     for (i = 0; i < len; i++)
-        printf("%02x", buf[i]);
-    printf("\n");
+        OUTPUT("%02x", buf[i]);
+    OUTPUT("\n");
 }
 
 void fprinthex(FILE * fp, char *str, unsigned char *buf, int len) {
@@ -123,16 +123,16 @@ void fprinthex2(FILE * fp, char *str, unsigned char *buf, int len) {
 
 
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TPM_READPCR_USAGE,
-                    "OpenPTS command\n\n"
-                    "Usage: tpm_readpcr [options]\n\n"
-                    "Options:\n"
-                    "  -p pcr_index          Set PCR index to read\n"
-                    "  -a                    Show all PCRs value (default)\n"
-                    "  -k                    Display PCR same as kernel format (/sys/class/misc/tpm0/device/pcrs)\n"
-                    "  -o filename           Output to file (default is STDOUT)\n"
-                    "  -h                    Help\n"
-                    "\n"));
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_READPCR_USAGE,
+        "OpenPTS command\n\n"
+        "Usage: tpm_readpcr [options]\n\n"
+        "Options:\n"
+        "  -p pcr_index          Set PCR index to read\n"
+        "  -a                    Show all PCRs value (default)\n"
+        "  -k                    Display PCR same as kernel format (/sys/class/misc/tpm0/device/pcrs)\n"
+        "  -o filename           Output to file (default is STDOUT)\n"
+        "  -h                    Help\n"
+        "\n"));
 }
 
 
@@ -197,14 +197,14 @@ int main(int argc, char *argv[]) {
 
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Create failed rc=0x%x\n",
               result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "ERROR: Tspi_Context_Connect failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -213,7 +213,7 @@ int main(int argc, char *argv[]) {
     /* Get TPM handles */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "ERROR: Tspi_Context_GetTpmObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -231,7 +231,7 @@ int main(int argc, char *argv[]) {
     pcrNum = *(UINT32 *) blob;
 
     if (result != TSS_SUCCESS) {
-        ERROR("ERROR: Tspi_TPM_GetCapability failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "ERROR: Tspi_TPM_GetCapability failed rc=0x%x\n", result);
         goto free;
     }
 
@@ -243,7 +243,7 @@ int main(int argc, char *argv[]) {
                                  &blob);
 
             if (result != TSS_SUCCESS) {
-                ERROR("ERROR: Tspi_TPM_PcrRead failed rc=0x%x\n", result);
+                LOG(LOG_ERR, "ERROR: Tspi_TPM_PcrRead failed rc=0x%x\n", result);
                 goto free;
             }
 
index 4bc6d36..5a647c9 100644 (file)
--- a/src/tss.c
+++ b/src/tss.c
@@ -81,12 +81,23 @@ int printTssKeyList(int ps_type) {
     return TSS_SUCCESS;
 }
 
-int createTssSignKey(PTS_UUID *uuid, int key_storage_type, char *filename, int force, int srk_password_mode) {
+int createTssSignKey(
+    PTS_UUID *uuid,
+    int key_storage_type,
+    char *filename,
+    int auth_type,
+    int force,
+    int srk_password_mode)
+{
     /* dummy */
     return TSS_SUCCESS;
 }
 
-int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) {
+int deleteTssKey(
+    PTS_UUID *uuid,
+    int key_storage_type,
+    char *filename)
+{
     /* dummy */
     return TSS_SUCCESS;
 }
@@ -98,46 +109,47 @@ int getTpmVersion(TSS_VERSION *version) {
 
 int createAIK() {
     /* dummy */
-    TODO("createAIK - TBD\n");
+    LOG(LOG_TODO, "createAIK - TBD\n");
     return TSS_E_FAIL;
 }
 
 int getTssPubKey(
     PTS_UUID *uuid,
-    int key_storage_type, int srk_password_mode,
-    int resetdalock, char *filename, int *pubkey_length, BYTE **pubkey) {
+    int key_storage_type,
+    int srk_password_mode,
+    int resetdalock,
+    char *filename,
+    int auth_type,
+    int *pubkey_length, BYTE **pubkey)
+{
     /* dummy */
     return TSS_SUCCESS;
 }
 
 int quoteTss(
-        /* Key */
-        PTS_UUID *uuid,
-        int key_storage_type,
-        int srk_password_mode,
-        char *filename,
-        /* Nonce */
-        BYTE *nonce,
-        /* PCR selection */
-        OPENPTS_PCRS *pcrs,
-        /* Output */
-        TSS_VALIDATION *validationData) {
+    PTS_UUID *uuid,
+    int key_storage_type,
+    int srk_password_mode,
+    char *filename,
+    int auth_type,
+    BYTE *nonce,
+    OPENPTS_PCRS *pcrs,
+    TSS_VALIDATION *validationData)
+{
     /* dummy */
     return TSS_SUCCESS;
 }
 
 int quote2Tss(
-        /* Key */
-        PTS_UUID *uuid,
-        int key_storage_type,
-        int srk_password_mode,
-        char *filename,
-        /* Nonce */
-        BYTE *nonce,
-        /* PCR selection */
-        OPENPTS_PCRS *pcrs,
-        /* Output */
-        TSS_VALIDATION *validationData) {
+    PTS_UUID *uuid,
+    int key_storage_type,
+    int srk_password_mode,
+    char *filename,
+    int auth_type,
+    BYTE *nonce,
+    OPENPTS_PCRS *pcrs,
+    TSS_VALIDATION *validationData)
+{
     /* dummy */
     return TSS_SUCCESS;
 }
@@ -185,7 +197,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
@@ -195,7 +207,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -203,7 +215,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -211,7 +223,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
     /* Get TPM policy */
     result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTPMPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -226,7 +238,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
         tpm_auth = null_srk_auth;
         tpm_auth_len = 0;
     } else {
-        ERROR("TPM secret\n");
+        LOG(LOG_ERR, "TPM secret\n");
         result = PTS_INTERNAL_ERROR;  // TODO
         goto close;
     }
@@ -236,7 +248,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
                 tpm_auth_len,
                 tpm_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -248,7 +260,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
                 flag,
                 value);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_TPM_GetStatus failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_TPM_GetStatus failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -276,7 +288,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
@@ -286,7 +298,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -294,7 +306,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -302,7 +314,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
     /* Get TPM policy */
     result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hTPMPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -317,7 +329,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
         tpm_auth = null_srk_auth;
         tpm_auth_len = 0;
     } else {
-        ERROR("TPM secret\n");
+        LOG(LOG_ERR, "TPM secret\n");
         result = PTS_INTERNAL_ERROR;  // TODO
         goto close;
     }
@@ -327,7 +339,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
                 tpm_auth_len,
                 tpm_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -339,7 +351,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
                 flag,  // TSS_TPMSTATUS_RESETLOCK,
                 value);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -367,14 +379,14 @@ int printTssKeyList(int ps_type) {
     /* Open TSS */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -394,7 +406,7 @@ int printTssKeyList(int ps_type) {
             "The key cannot be found in the persistent storage database.\n"));
         goto close;
     } else if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetRegisteredKeysByUUID failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetRegisteredKeysByUUID failed rc=0x%x\n",
             result);
         goto close;
     }
@@ -468,19 +480,19 @@ int createTssSignKey(
     /* check */
     if ((key_storage_type == OPENPTS_AIK_STORAGE_TYPE_TSS) && (uuid == NULL)) {
         /* TSS */
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
     }
     if (key_storage_type == OPENPTS_AIK_STORAGE_TYPE_BLOB) {
         if (filename == NULL) {
             /* BLOB */
-            ERROR("null input");
+            LOG(LOG_ERR, "null input");
             return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
         } else {
             if (force != 1) {
                 /* check file */
                 if (checkFile(filename) == OPENPTS_FILE_EXISTS) {
-                    ERROR("Blob file already exit. %s", filename);
+                    LOG(LOG_ERR, "Blob file already exit. %s", filename);
                     return TSS_E_KEY_ALREADY_REGISTERED;
                 }
             }
@@ -490,14 +502,14 @@ int createTssSignKey(
     /* Open TSS */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -505,7 +517,7 @@ int createTssSignKey(
     /* get TPM handles */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -517,10 +529,10 @@ int createTssSignKey(
                 SRK_UUID,
                 &hSRK);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
          result);
         if (result == 0x2020) {
-            ERROR("Your key storage of tcsd is damaged or missing. \n");
+            LOG(LOG_ERR, "Your key storage of tcsd is damaged or missing. \n");
         }
         goto close;
     }
@@ -528,7 +540,7 @@ int createTssSignKey(
     /* SRK Policy objects */
     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -550,7 +562,7 @@ int createTssSignKey(
                 srk_auth_len,
                 srk_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -567,7 +579,7 @@ int createTssSignKey(
                     TSS_KEY_AUTHORIZATION | TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING,
                     &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_CreateObject failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -579,9 +591,8 @@ int createTssSignKey(
                     TSS_POLICY_USAGE,
                     &hKeyPolicy);
         if (result != TSS_SUCCESS) {
-            printf
-            ("ERROR: Tspi_Context_CreateObject failed rc=0x%x\n",
-             result);
+            LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
+                result);
             goto close;
         }
 
@@ -591,18 +602,16 @@ int createTssSignKey(
                     strlen(TPMSIGKEY_SECRET),
                     (BYTE *)TPMSIGKEY_SECRET);
         if (result != TSS_SUCCESS) {
-            printf
-            ("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
-             result);
+            LOG(LOG_ERR, "ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                result);
             goto close;
         }
 
         result = Tspi_Policy_AssignToObject(hKeyPolicy, hKey);
 
         if (result != TSS_SUCCESS) {
-            printf
-            ("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
-             result);
+            LOG(LOG_ERR, "ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+                result);
             goto close;
         }
     } else {
@@ -614,7 +623,7 @@ int createTssSignKey(
                     TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING,
                     &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_CreateObject failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -623,10 +632,10 @@ int createTssSignKey(
     /* create Key */
     result = Tspi_Key_CreateKey(hKey, hSRK, 0);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Key_CreateKey failed rc=0x%04x\n",
+        LOG(LOG_ERR, "Tspi_Key_CreateKey failed rc=0x%04x\n",
                result);
         if (result == 0x12) {
-            ERROR("TPM_NOSRK error, take the TPM ownership before initialize ptsc");
+            LOG(LOG_ERR, "TPM_NOSRK error, take the TPM ownership before initialize ptsc");
         }
         goto close;
     }
@@ -638,7 +647,7 @@ int createTssSignKey(
 
         fp = fopen(filename, "w");
         if (fp==NULL) {
-            ERROR("file open fail, key blob file is %s",filename);
+            LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
             result = TSS_E_KEY_NOT_LOADED;
             goto close;
         }
@@ -650,7 +659,7 @@ int createTssSignKey(
                      &keyLength,
                      &keyBlob);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_GetAttribData failed rc=0x%04x\n",
+            LOG(LOG_ERR, "Tspi_GetAttribData failed rc=0x%04x\n",
                    result);
             fclose(fp);
             goto close;
@@ -685,19 +694,19 @@ int createTssSignKey(
                                tss_uuid,
                                &hKey);
                     if (result != TSS_SUCCESS) {
-                        ERROR("Tspi_Context_UnregisterKey failed rc=0x%x\n",
+                        LOG(LOG_ERR, "Tspi_Context_UnregisterKey failed rc=0x%x\n",
                          result);
                     } else {
                         /* try regkey again */
                         goto regkey;
                     }
                 } else {
-                    ERROR("Tspi_Context_RegisterKey failed rc=0x%x\n",
+                    LOG(LOG_ERR, "Tspi_Context_RegisterKey failed rc=0x%x\n",
                      result);
-                    ERROR("       TSS_E_KEY_ALREADY_REGISTERED\n");
+                    LOG(LOG_ERR, "       TSS_E_KEY_ALREADY_REGISTERED\n");
                 }
             } else {
-                ERROR("spi_Context_RegisterKey failed rc=0x%x\n",
+                LOG(LOG_ERR, "spi_Context_RegisterKey failed rc=0x%x\n",
                  result);
                 // 0x3003 TEE_E_BAD_PARAMETOR
             }
@@ -720,7 +729,7 @@ int createTssSignKey(
  * Create AIK
  */
 int createAIK() {
-    TODO("createAIK - TBD\n");
+    LOG(LOG_TODO, "createAIK - TBD\n");
     return TSS_E_FAIL;
 }
 
@@ -737,17 +746,17 @@ int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) {
     /* check BLOB */
     if (key_storage_type == OPENPTS_AIK_STORAGE_TYPE_BLOB) {
         if (filename == NULL) {
-            ERROR("null input");
+            LOG(LOG_ERR, "null input");
             return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
         } else {
             /* check file */
             if (checkFile(filename) != OPENPTS_FILE_EXISTS) {
-                ERROR("Blob file not found. %s", filename);
+                LOG(LOG_ERR, "Blob file not found. %s", filename);
                 return TSS_E_BAD_PARAMETER;
             }
             /* delete file */
             if (remove(filename) != 0) {
-                ERROR("remove key blob is fail. %s", filename);
+                LOG(LOG_ERR, "remove key blob is fail. %s", filename);
                 return TSS_E_FAIL;
             }
             /* OK */
@@ -757,21 +766,21 @@ int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) {
 
     /* check TSS */
     if ((key_storage_type == OPENPTS_AIK_STORAGE_TYPE_TSS) && (uuid == NULL)) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
     }
 
     /* Open TSS */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -787,7 +796,7 @@ int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) {
             tss_uuid,
             &hKey);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_UnregisterKey failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_UnregisterKey failed rc=0x%x\n",
          result);
     }
 
@@ -831,11 +840,11 @@ int getTssPubKey(
 
     /* check */
     if ((key_storage_type == OPENPTS_AIK_STORAGE_TYPE_TSS) && (uuid == NULL)) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
     }
     if ((key_storage_type == OPENPTS_AIK_STORAGE_TYPE_BLOB) && (filename == NULL)) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
     }
 
@@ -851,14 +860,14 @@ int getTssPubKey(
     /* Open TSS */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         goto close;
     }
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -874,11 +883,11 @@ int getTssPubKey(
                 SRK_UUID,
                 &hSRK);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
          result);
         if (result == 0x2020) {
-            ERROR(" TSS_E_PS_KEY_NOT_FOUND.\n");
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
+            LOG(LOG_ERR, " TSS_E_PS_KEY_NOT_FOUND.\n");
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
                 "Please check your system_ps_file setting in /etc/security/tss/tcsd.conf. "
                 "(The default is /var/tss/lib/tpm/system.data)\n"
                 "If system_ps_file size is zero then it does not contain the SRK info\n"));
@@ -891,7 +900,7 @@ int getTssPubKey(
     /* SRK Policy objects */
     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -914,7 +923,7 @@ int getTssPubKey(
                 srk_auth_len,
                 srk_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -930,7 +939,7 @@ int getTssPubKey(
 
         fp = fopen(filename, "r");
         if (fp==NULL) {
-            ERROR("file open fail, key blob file is %s",filename);
+            LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
             result = TSS_E_KEY_NOT_LOADED;
             goto close;
         }
@@ -945,7 +954,7 @@ int getTssPubKey(
                     blob,
                     &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
              result);
             goto close;
         }
@@ -957,12 +966,12 @@ int getTssPubKey(
                     tss_uuid,
                     &hKey);
         if (result == 0x803) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_TPM_LOCKED,
-                        "The TPM is locked. Please use the 'tpm_resetdalock' command to clear the lock\n"
-                        "For the ptscd daemon please set the flag 'tpm.resetdalock=on' in /etc/ptsc.conf\n"));
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_TPM_LOCKED,
+                  "The TPM is locked. Please use the 'tpm_resetdalock' command to clear the lock\n"
+                  "For the ptscd daemon please set the flag 'tpm.resetdalock=on' in /etc/ptsc.conf\n"));
             goto close;
         } else if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
             debugHex("\t\tUUID", (BYTE*)&tss_uuid, 16, "\n");
 
             goto close;
@@ -972,7 +981,7 @@ int getTssPubKey(
     /* Policy Object*/
     result = Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &hKeyPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -986,7 +995,7 @@ int getTssPubKey(
                     strlen(TPMSIGKEY_SECRET),
                     (BYTE *)TPMSIGKEY_SECRET);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1001,7 +1010,7 @@ int getTssPubKey(
                     0,
                     key_auth);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1017,7 +1026,7 @@ int getTssPubKey(
                                 (UINT32 *) pubkey_length,
                                 &buf);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetAttribData failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetAttribData failed rc=0x%x\n",
                result);
         goto free;
     }
@@ -1055,14 +1064,14 @@ int getTpmVersion(TSS_VERSION *version) {
 
     /* check */
     if (version == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_BAD_PARAMETER;  // TSS ERROR_CODE
     }
 
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
@@ -1073,7 +1082,7 @@ int getTpmVersion(TSS_VERSION *version) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         rc = (int)result;
         goto close;
@@ -1082,7 +1091,7 @@ int getTpmVersion(TSS_VERSION *version) {
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         rc = (int)result;
         goto close;
@@ -1098,14 +1107,14 @@ int getTpmVersion(TSS_VERSION *version) {
                 &data_len,
                 &data);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_TPM_GetCapability failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_TPM_GetCapability failed rc=0x%x\n",
                result);
         rc = (int)result;
         goto close;
     }
 
     if (data_len != 4) {
-        ERROR("bad TPM version\n");
+        LOG(LOG_ERR, "bad TPM version\n");
         rc = TSS_E_FAIL;
         goto close;
     }
@@ -1171,7 +1180,7 @@ int quoteTss(
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
@@ -1182,7 +1191,7 @@ int quoteTss(
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1190,7 +1199,7 @@ int quoteTss(
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1206,7 +1215,7 @@ int quoteTss(
                                     &pulRespDataLength, &prgbRespData);
 
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_TPM_GetCapability failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_TPM_GetCapability failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1223,7 +1232,7 @@ int quoteTss(
                 0,
                 &hPcrComposite);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_CreateObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1235,7 +1244,7 @@ int quoteTss(
                         hPcrComposite,
                         i);
             if (result != TSS_SUCCESS) {
-                    ERROR("failed rc=0x%x\n", result);
+                    LOG(LOG_ERR, "failed rc=0x%x\n", result);
                     goto close;
             }
             pcrSelectCount++;
@@ -1244,7 +1253,7 @@ int quoteTss(
 
     /* check PCR */
     if (pcrSelectCount == 0) {
-        ERROR("No PCR is selected for quote\n");
+        LOG(LOG_ERR, "No PCR is selected for quote\n");
         goto close;
     }
 
@@ -1255,11 +1264,11 @@ int quoteTss(
                 SRK_UUID,
                 &hSRK);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
          result);
         if (result == 0x2020) {
-            ERROR(" TSS_E_PS_KEY_NOT_FOUND.\n");
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
+            LOG(LOG_ERR, " TSS_E_PS_KEY_NOT_FOUND.\n");
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
                 "Please check your system_ps_file setting in /etc/tcsd.conf. "
                 "(The default is /var/lib/tpm/system.data)\n"
                 "If system_ps_file size is zero then it does not contains the SRK info\n"));
@@ -1272,7 +1281,7 @@ int quoteTss(
     /* Get SRK Policy objects */
     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1296,7 +1305,7 @@ int quoteTss(
                 srk_auth_len,
                 srk_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1311,7 +1320,7 @@ int quoteTss(
 
         fp = fopen(filename, "r");
         if (fp==NULL) {
-            ERROR("file open fail, key blob file is %s",filename);
+            LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
             result = TSS_E_KEY_NOT_LOADED;
             goto close;
         }
@@ -1327,7 +1336,7 @@ int quoteTss(
                      blob,
                      &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
              result);
             goto close;
         }
@@ -1339,7 +1348,7 @@ int quoteTss(
                     tss_uuid,
                     &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
             debugHex("\t\tUUID", (BYTE*)&tss_uuid, 16, "\n");
 
             goto close;
@@ -1349,7 +1358,7 @@ int quoteTss(
     /* get Policy Object of Sign key */
     result = Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &hKeyPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
               result);
         goto close;
     }
@@ -1363,7 +1372,7 @@ int quoteTss(
                     strlen(TPMSIGKEY_SECRET),
                     (BYTE *)TPMSIGKEY_SECRET);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1378,7 +1387,7 @@ int quoteTss(
                     0,
                     key_auth);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1400,11 +1409,11 @@ int quoteTss(
                             hKey, hPcrComposite, &validation_data);
     if (result != TSS_SUCCESS) {
         if (result == 0x01) {
-            ERROR("Tspi_TPM_Quote failed rc=0x%04x\n",
+            LOG(LOG_ERR, "Tspi_TPM_Quote failed rc=0x%04x\n",
                    result);
-            ERROR("       Authorization faild, needs valid password\n");
+            LOG(LOG_ERR, "       Authorization faild, needs valid password\n");
         } else {
-            ERROR("Tspi_TPM_Quote failed rc=0x%04x\n",
+            LOG(LOG_ERR, "Tspi_TPM_Quote failed rc=0x%04x\n",
                    result);
         }
         goto free;
@@ -1482,13 +1491,11 @@ int quoteTss(
                         hPcrComposite, i,
                         &length, &data);
             if (result != TSS_SUCCESS) {
-                ERROR("Tspi_PcrComposite_GetPcrValue failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_PcrComposite_GetPcrValue failed rc=0x%x\n",
                         result);
                 goto free;
             }
 
-            // fprintf(fp, "pcr.%d=", i);
-            // fprinthex(fp, "", data, length);
             if (length < MAX_DIGEST_SIZE) {
                 memcpy(&pcrs->pcr[i], data, length);
                 if (isDebugFlagSet(DEBUG_FLAG)) {
@@ -1496,7 +1503,7 @@ int quoteTss(
                     debugHex("             : ", data, length, "\n");
                 }
             } else {
-                ERROR("pcr size is too big %d >  %d\n", length, MAX_DIGEST_SIZE);
+                LOG(LOG_ERR, "pcr size is too big %d >  %d\n", length, MAX_DIGEST_SIZE);
             }
 
             Tspi_Context_FreeMemory(hContext, data);
@@ -1575,7 +1582,7 @@ int quote2Tss(
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n",
                result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
@@ -1586,7 +1593,7 @@ int quote2Tss(
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1594,7 +1601,7 @@ int quote2Tss(
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1611,7 +1618,7 @@ int quote2Tss(
                 &pulRespDataLength, &prgbRespData);
 
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_TPM_GetCapability failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_TPM_GetCapability failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1628,7 +1635,7 @@ int quote2Tss(
                 TSS_PCRS_STRUCT_INFO_SHORT,
                 &hPcrComposite);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_CreateObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_CreateObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1641,7 +1648,7 @@ int quote2Tss(
                         i,
                         TSS_PCRS_DIRECTION_RELEASE);
             if (result != TSS_SUCCESS) {
-                    ERROR("failed rc=0x%x\n", result);
+                    LOG(LOG_ERR, "failed rc=0x%x\n", result);
                     goto close;
             }
             pcrSelectCount++;
@@ -1650,7 +1657,7 @@ int quote2Tss(
 
     /* check PCR */
     if (pcrSelectCount == 0) {
-        ERROR("No PCR is selected for quote\n");
+        LOG(LOG_ERR, "No PCR is selected for quote\n");
         goto close;
     }
 
@@ -1661,11 +1668,11 @@ int quote2Tss(
                 SRK_UUID,
                 &hSRK);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (SRK) failed rc=0x%x\n",
          result);
         if (result == 0x2020) {
-            ERROR(" TSS_E_PS_KEY_NOT_FOUND.\n");
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
+            LOG(LOG_ERR, " TSS_E_PS_KEY_NOT_FOUND.\n");
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_CHECK_SETTING,
                 "Please check your system_ps_file setting in /etc/tcsd.conf. "
                 "(The default is /var/lib/tpm/system.data)\n"
                 "If system_ps_file size is zero then it does not contains the SRK info\n"));
@@ -1678,7 +1685,7 @@ int quote2Tss(
     /* Get SRK Policy objects */
     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1701,7 +1708,7 @@ int quote2Tss(
                 srk_auth_len,
                 srk_auth);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Policy_SetSecret failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1716,7 +1723,7 @@ int quote2Tss(
 
         fp = fopen(filename, "r");
         if (fp==NULL) {
-            ERROR("file open fail, key blob file is %s",filename);
+            LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
             result = TSS_E_KEY_NOT_LOADED;
             goto close;
         }
@@ -1733,7 +1740,7 @@ int quote2Tss(
                      blob,
                      &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByBlob (Key) failed rc=0x%x\n",
              result);
             goto close;
         }
@@ -1745,7 +1752,7 @@ int quote2Tss(
                     tss_uuid,
                     &hKey);
         if (result != TSS_SUCCESS) {
-            ERROR("Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
+            LOG(LOG_ERR, "Tspi_Context_LoadKeyByUUID (Key) failed rc=0x%x\n", result);
             debugHex("\t\tUUID", (BYTE*)&tss_uuid, 16, "\n");
 
             goto close;
@@ -1755,7 +1762,7 @@ int quote2Tss(
     /* get Policy Object of Sign key */
     result = Tspi_GetPolicyObject(hKey, TSS_POLICY_USAGE, &hKeyPolicy);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_GetPolicyObject failed rc=0x%x\n",
+        LOG(LOG_ERR, "Tspi_GetPolicyObject failed rc=0x%x\n",
                result);
         goto close;
     }
@@ -1769,7 +1776,7 @@ int quote2Tss(
                     strlen(TPMSIGKEY_SECRET),
                     (BYTE *)TPMSIGKEY_SECRET);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1784,7 +1791,7 @@ int quote2Tss(
                     0,
                     key_auth);
         if (result != TSS_SUCCESS) {
-            printf("ERROR: Tspi_Policy_SetSecret failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_Policy_SetSecret failed rc=0x%x\n",
                    result);
             goto close;
         }
@@ -1805,10 +1812,11 @@ int quote2Tss(
                 &versionInfo);
     if (result != TSS_SUCCESS) {
         if (result == 0x01) {
-            ERROR("Tspi_TPM_Quote failed rc=0x%04x\n", result);
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_AUTH_FAILED, "Authorization failed, needs valid password\n"));
+            LOG(LOG_ERR, "Tspi_TPM_Quote failed rc=0x%04x\n", result);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_AUTH_FAILED,
+                "Authorization failed, needs valid password\n"));
         } else {
-            ERROR("Tspi_TPM_Quote failed rc=0x%04x\n", result);
+            LOG(LOG_ERR, "Tspi_TPM_Quote failed rc=0x%04x\n", result);
         }
         goto free;
     }
@@ -1842,7 +1850,7 @@ int quote2Tss(
                         hPcrComposite, i,
                         &length, &data);
             if (result != TSS_SUCCESS) {
-                ERROR("Tspi_PcrComposite_GetPcrValue failed rc=0x%x\n",
+                LOG(LOG_ERR, "Tspi_PcrComposite_GetPcrValue failed rc=0x%x\n",
                         result);
                 goto free;
             }
@@ -1851,7 +1859,7 @@ int quote2Tss(
             result = Tspi_TPM_PcrRead(
                 hTPM, i, &length, &data);
             if (result != TSS_SUCCESS) {
-                ERROR("Tspi_TPM_PcrRead failed rc=0x%x\n", result);
+                LOG(LOG_ERR, "Tspi_TPM_PcrRead failed rc=0x%x\n", result);
                 goto free;
             }
 #endif
@@ -1863,7 +1871,7 @@ int quote2Tss(
                     debugHex("             : ", data, length, "\n");
                 }
             } else {
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_TSS_PCR_SIZE_TOO_BIG,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_TSS_PCR_SIZE_TOO_BIG,
                     "PCR size is too big %d > %d\n"), length, MAX_DIGEST_SIZE);
             }
 
@@ -1959,18 +1967,18 @@ int getRandom(BYTE *out, int size) {
 
     /* check */
     if (size <= 0) {
-        ERROR("bad size. %d", size);
+        LOG(LOG_ERR, "bad size. %d", size);
         return TSS_E_FAIL;
     }
     if (out == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return TSS_E_FAIL;
     }
 
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n", result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
         }
@@ -1979,14 +1987,14 @@ int getRandom(BYTE *out, int size) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n", result);
         goto close;
     }
 
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -1994,8 +2002,7 @@ int getRandom(BYTE *out, int size) {
     /* get Random*/
     result = Tspi_TPM_GetRandom(hTPM, size, &buf);
     if (result != TSS_SUCCESS) {
-            ERROR
-                ("Tspi_TPM_GetRandom failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_TPM_GetRandom failed rc=0x%x\n",
                  result);
             Tspi_Context_FreeMemory(hContext, NULL);
             goto free;
@@ -2032,7 +2039,7 @@ int extendEvent(TSS_PCR_EVENT* event) {
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n", result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
         }
@@ -2041,14 +2048,14 @@ int extendEvent(TSS_PCR_EVENT* event) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n", result);
         goto close;
     }
 
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
         goto close;
     }
 
@@ -2066,8 +2073,7 @@ int extendEvent(TSS_PCR_EVENT* event) {
                 &pcr_len,
                 &pcr);
     if (result != TSS_SUCCESS) {
-            ERROR
-                ("Tspi_TPM_PcrExtend failed rc=0x%x\n",
+            LOG(LOG_ERR, "Tspi_TPM_PcrExtend failed rc=0x%x\n",
                  result);
             // Tspi_Context_FreeMemory(hContext, NULL);
             goto close;
@@ -2097,7 +2103,7 @@ int readPcr(int pcr_index, BYTE *pcr) {
     /* Connect to TCSD */
     result = Tspi_Context_Create(&hContext);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Create failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Create failed rc=0x%x\n", result);
         if (result == 0x3011) {
             OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_COMMS_FAILURE, "TSS communications failure. Is tcsd running?\n"));
         }
@@ -2106,25 +2112,25 @@ int readPcr(int pcr_index, BYTE *pcr) {
 
     result = Tspi_Context_Connect(hContext, SERVER);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_Connect failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_Connect failed rc=0x%x\n", result);
         goto close;
     }
 
     /* Get TPM handle */
     result = Tspi_Context_GetTpmObject(hContext, &hTPM);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_Context_GetTpmObject failed rc=0x%x\n", result);
         goto close;
     }
 
     result = Tspi_TPM_PcrRead(
         hTPM, pcr_index, &data_len, &data);
     if (result != TSS_SUCCESS) {
-        ERROR("Tspi_TPM_PcrRead failed rc=0x%x\n", result);
+        LOG(LOG_ERR, "Tspi_TPM_PcrRead failed rc=0x%x\n", result);
         goto close;
     }
     if (data_len != SHA1_DIGEST_SIZE) {
-        ERROR("Bad PCR size %d\n", data_len);
+        LOG(LOG_ERR, "Bad PCR size %d\n", data_len);
         result = PTS_INTERNAL_ERROR;
     } else {
         memcpy(pcr, data, SHA1_DIGEST_SIZE);
@@ -2176,15 +2182,15 @@ int validateQuoteData(
 
     /* check */
     if (pcrs == NULL) {
-        ERROR("validateQuoteData - pcrs is NULL\n");
+        LOG(LOG_ERR, "validateQuoteData - pcrs is NULL\n");
         return PTS_INTERNAL_ERROR;
     }
     if (pcrs->pubkey_length == 0) {
-        ERROR("validateQuoteData - pcrs->pubkey_length is ZERO\n");
+        LOG(LOG_ERR, "validateQuoteData - pcrs->pubkey_length is ZERO\n");
         return PTS_INTERNAL_ERROR;
     }
     if (pcrs->pubkey == NULL) {
-        ERROR("validateQuoteData - pcrs->pubkey is NULL\n");
+        LOG(LOG_ERR, "validateQuoteData - pcrs->pubkey is NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -2194,13 +2200,13 @@ int validateQuoteData(
     } else if (validationData->ulDataLength == 52) {
         DEBUG("Quote2\n");
     } else {
-        ERROR("validationData->ulDataLength != 48/52, but %d\n",
+        LOG(LOG_ERR, "validationData->ulDataLength != 48/52, but %d\n",
             validationData->ulDataLength);
         return PTS_INTERNAL_ERROR;
     }
 
     if (validationData->ulExternalDataLength != 20) {
-        ERROR("validationData->ulExternalDataLength != 20, but %d\n",
+        LOG(LOG_ERR, "validationData->ulExternalDataLength != 20, but %d\n",
             validationData->ulExternalDataLength);
         return PTS_INTERNAL_ERROR;
     }
@@ -2247,7 +2253,7 @@ int validateQuoteData(
     // memcpy(&pubkey[1],&pcrs->pubkey[28], 256);
 
 #if 0
-    TODO("\n");
+    LOG(LOG_TODO, "\n");
     printHex("message   :", message, message_length, "\n");
     printHex("hash      :", hash, hash_length, "\n");
     printHex("signature :", signature, signature_length, "\n");
@@ -2306,10 +2312,10 @@ int validateQuoteData(
         UINT32 e;  // unsigned long
         ERR_load_crypto_strings();
         e = ERR_get_error();
-        ERROR("RSA_verify failed, %s\n", ERR_error_string(e, NULL));
-        ERROR("   %s\n", ERR_lib_error_string(e));
-        ERROR("   %s\n", ERR_func_error_string(e));
-        ERROR("   %s\n", ERR_reason_error_string(e));
+        LOG(LOG_ERR, "RSA_verify failed, %s\n", ERR_error_string(e, NULL));
+        LOG(LOG_ERR, "   %s\n", ERR_lib_error_string(e));
+        LOG(LOG_ERR, "   %s\n", ERR_func_error_string(e));
+        LOG(LOG_ERR, "   %s\n", ERR_reason_error_string(e));
         ERR_free_strings();
         return PTS_VERIFY_FAILED;
     }
@@ -2340,16 +2346,16 @@ int validatePcrCompositeV11(
 
     /* check */
     if (validationData == NULL) {
-        ERROR("validationData == NULL\n");
+        LOG(LOG_ERR, "validationData == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
     if (validationData->rgbData == NULL) {
-        ERROR("validationData->rgbData == NULL\n");
+        LOG(LOG_ERR, "validationData->rgbData == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
     if (validationData->ulDataLength != 48) {
-        ERROR("validationData->ulDataLength != 48, but %d\n",
+        LOG(LOG_ERR, "validationData->ulDataLength != 48, but %d\n",
             validationData->ulDataLength);
         return PTS_INTERNAL_ERROR;
     }
@@ -2475,12 +2481,12 @@ int validatePcrCompositeV12(
 
     /* check */
     if (validationData == NULL) {
-        ERROR("validationData == NULL\n");
+        LOG(LOG_ERR, "validationData == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
     if (validationData->rgbData == NULL) {
-        ERROR("validationData->rgbData == NULL\n");
+        LOG(LOG_ERR, "validationData->rgbData == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -2494,7 +2500,7 @@ int validatePcrCompositeV12(
         pcrsel_size = 3;
         composit_hash = &validationData->rgbData[32];
     } else  {
-        ERROR("validationData->ulDataLength != 48 or 52, but %d\n",
+        LOG(LOG_ERR, "validationData->ulDataLength != 48 or 52, but %d\n",
             validationData->ulDataLength);
         return PTS_INTERNAL_ERROR;
     }
index 6a8aba1..cb8e502 100644 (file)
--- a/src/uml.c
+++ b/src/uml.c
@@ -108,7 +108,7 @@ void    uml2sax_endDocument(void * fctx) {
     // TODO(munetoh) ID must be "Start"
     ctx->curr_state = getSubvertex(ctx, "Start");
     if (ctx->curr_state == NULL) {
-        ERROR("Start state is missing\n");
+        LOG(LOG_ERR, "Start state is missing\n");
     }
 
     DEBUG_CAL("endDocument - done\n");
@@ -149,10 +149,8 @@ void    uml2sax_startElement(void* fctx, const xmlChar* name,
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "xmi:type")) {
                         snprintf(subvertexXmiType, sizeof(subvertexXmiType),
                                  "%s", value);
@@ -179,10 +177,8 @@ void    uml2sax_startElement(void* fctx, const xmlChar* name,
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "source")) {
                         snprintf(sourceXmiId, sizeof(sourceXmiId), "%s", value);
                     }
@@ -200,10 +196,8 @@ void    uml2sax_startElement(void* fctx, const xmlChar* name,
         if (atts != NULL) {
             for (i = 0; (atts[i] != NULL); i++) {
                 type = (char *)atts[i++];
-                // printf(", %s='", type);
                 if (atts[i] != NULL) {
                     value= (char *)atts[i];
-                    // printf("%s'", value);
                     if (!strcmp(type, "name")) {
                         snprintf(doActivityName, sizeof(doActivityName),
                                  "%s", value);
@@ -215,8 +209,6 @@ void    uml2sax_startElement(void* fctx, const xmlChar* name,
 
     } else if ((!strcmp((char *)name, "body")) &&
                (ctx->state == UML2SAX_TRANSITION)) {
-        // } else if (!strcmp((char *)name, "body")) {
-        // printf("state %d ",ctx->state);
         ctx->state = UML2SAX_BODY;
     } else if (!strcmp((char *)name, "name")) {
         //
@@ -288,14 +280,10 @@ void  uml2sax_characters(void* fctx, const xmlChar * ch, int len) {
 
     switch (ctx->state) {
     case UML2SAX_SUBVERTEX:
-        // printf("PCR_INDEX  [%s]\n",buf);
-        // sax_pcrIndex = atoi(buf);
         break;
     case UML2SAX_BODY:
         memcpy(charbuf, buf, FSM_BUF_SIZE);
         ctx->state = 0;
-        // DEBUG("Condition  [%s] len=%d\n",charbuf,len);
-        // sax_pcrIndex = atoi(buf);
         break;
     default:
         // DEBUG_SAX("characters[%d]=[%s]\n", len, buf);
index 8d2f956..0abf88e 100644 (file)
@@ -50,7 +50,7 @@
  * usage
  */
 void usage(void) {
-    fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UML2DOT_USAGE,
+    OUTPUT(NLS(MS_OPENPTS, OPENPTS_UML2DOT_USAGE,
             "usage: uml2dot [options] UMLfile \n"
             "\t-o output\tset output file (default is stdout)\n"
             "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
     /* Read UML(XML) file */
 
     if (input_filename == NULL) {
-        printf(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
+        ERROR(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
         usage();
         return -1;
     }
@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
     rc = readUmlModel(ctx, argv[0]);
 
     if (rc != 0) {
-        ERROR("ERROR\n");
+        LOG(LOG_ERR, "ERROR\n");
         goto error;
     }
 
@@ -109,7 +109,7 @@ int main(int argc, char *argv[]) {
     rc = writeDotModel(ctx, output_filename);
 
     if (rc != 0) {
-        ERROR("ERROR\n");
+        LOG(LOG_ERR, "ERROR\n");
         goto error;
     }
 
index 4c1872e..f27c20c 100644 (file)
@@ -82,7 +82,7 @@ OPENPTS_UUID *newOpenptsUuid() {
 
     uuid = xmalloc(sizeof(OPENPTS_UUID));  // BYTE[16]
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(uuid, 0, sizeof(OPENPTS_UUID));
@@ -100,13 +100,13 @@ OPENPTS_UUID *newOpenptsUuid2(PTS_UUID *pts_uuid) {
 
     /* check */
     if (pts_uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     uuid = xmalloc(sizeof(OPENPTS_UUID));  // BYTE[16]
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(uuid, 0, sizeof(OPENPTS_UUID));
@@ -132,13 +132,13 @@ OPENPTS_UUID *newOpenptsUuidFromFile(char * filename) {
 
     /* check */
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     uuid = newOpenptsUuid();
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -148,7 +148,7 @@ OPENPTS_UUID *newOpenptsUuidFromFile(char * filename) {
     /* load the filename */
     rc = readOpenptsUuidFile(uuid);
     if (rc != PTS_SUCCESS) {
-        ERROR("newOpenptsUuidFromFile() - readOpenptsUuidFile() fail rc=%d\n", rc);
+        LOG(LOG_ERR, "newOpenptsUuidFromFile() - readOpenptsUuidFile() fail rc=%d\n", rc);
         freeOpenptsUuid(uuid);
         return NULL;
     }
@@ -162,7 +162,7 @@ OPENPTS_UUID *newOpenptsUuidFromFile(char * filename) {
 void freeOpenptsUuid(OPENPTS_UUID *uuid) {
     /* check */
     if (uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return;
     }
 
@@ -191,7 +191,7 @@ void freeOpenptsUuid(OPENPTS_UUID *uuid) {
 int genOpenptsUuid(OPENPTS_UUID *uuid) {
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -206,17 +206,17 @@ int genOpenptsUuid(OPENPTS_UUID *uuid) {
     } else if (uuid->status == OPENPTS_UUID_FILLED) {
         // TODO Re genenation happen
         uuid->status = OPENPTS_UUID_CHANGED;
-        ERROR("genOpenptsUuid() %s - changed\n", uuid->str);
+        LOG(LOG_ERR, "genOpenptsUuid() %s - changed\n", uuid->str);
     } else if (uuid->status == OPENPTS_UUID_CHANGED) {
         // TODO Re genenation happen
         uuid->status = OPENPTS_UUID_CHANGED;
-        ERROR("genOpenptsUuid() %s - changed again\n", uuid->str);
+        LOG(LOG_ERR, "genOpenptsUuid() %s - changed again\n", uuid->str);
     } else if (uuid->status == OPENPTS_UUID_UUID_ONLY) {
         // TODO Re genenation happen
         uuid->status = OPENPTS_UUID_UUID_ONLY;
-        ERROR("genOpenptsUuid() %s - changed again (no binding to the file)\n", uuid->str);
+        LOG(LOG_ERR, "genOpenptsUuid() %s - changed again (no binding to the file)\n", uuid->str);
     } else {
-        ERROR("genOpenptsUuid() - bad status\n");
+        LOG(LOG_ERR, "genOpenptsUuid() - bad status\n");
     }
 
 
@@ -256,11 +256,11 @@ int readOpenptsUuidFile(OPENPTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (uuid->filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -314,25 +314,25 @@ int readOpenptsUuidFile(OPENPTS_UUID *uuid) {
         /* parse */
         uuid->uuid = getUuidFromString(line);
         if (uuid->uuid  == NULL) {
-            ERROR("readUuidFile() - UUID is NULL, file %s\n", uuid->filename);
+            LOG(LOG_ERR, "readUuidFile() - UUID is NULL, file %s\n", uuid->filename);
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
         uuid->str = getStringOfUuid(uuid->uuid);
         if (uuid->str == NULL) {
-            ERROR("readUuidFile() - STR UUID is NULL, file %s\n", uuid->filename);
+            LOG(LOG_ERR, "readUuidFile() - STR UUID is NULL, file %s\n", uuid->filename);
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
         uuid->time = getDateTimeOfUuid(uuid->uuid);
         if (uuid->time == NULL) {
-            ERROR("readUuidFile() - TIME UUID is NULL, file %s\n", uuid->filename);
+            LOG(LOG_ERR, "readUuidFile() - TIME UUID is NULL, file %s\n", uuid->filename);
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
         uuid->status = OPENPTS_UUID_FILLED;
     } else {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UUID_READ_FAILED, "Failed to read the UUID file\n"));
+        ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_READ_FAILED, "Failed to read the UUID file\n"));
     }
 
  close:
@@ -352,20 +352,20 @@ int writeOpenptsUuidFile(OPENPTS_UUID *uuid, int overwrite) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (uuid->filename == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return PTS_FATAL;
     }
     if ((uuid->status != OPENPTS_UUID_FILLED) && (uuid->status != OPENPTS_UUID_CHANGED)) {
-        ERROR("writeOpenptsUuidFile() - uuid->status = %d (!= FILLED or CHANGED)\n", uuid->status);
+        LOG(LOG_ERR, "writeOpenptsUuidFile() - uuid->status = %d (!= FILLED or CHANGED)\n", uuid->status);
         // 1 => OPENPTS_UUID_FILENAME_ONLY, UUID is missing
         return PTS_INTERNAL_ERROR;
     }
     if (uuid->str == NULL) {
-        ERROR("writeOpenptsUuidFile() - uuid->str == NULL\n");
+        LOG(LOG_ERR, "writeOpenptsUuidFile() - uuid->str == NULL\n");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -373,7 +373,7 @@ int writeOpenptsUuidFile(OPENPTS_UUID *uuid, int overwrite) {
     if (overwrite == 1) {
         /* overwrite */
         if ((fp = fopen(uuid->filename, "w")) == NULL) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
                 "Failed to open UUID file %s\n"), uuid->filename);
             return PTS_INTERNAL_ERROR;
         }
@@ -382,18 +382,18 @@ int writeOpenptsUuidFile(OPENPTS_UUID *uuid, int overwrite) {
         if ((fd = open(uuid->filename, O_CREAT | O_EXCL | O_WRONLY, mode)) == -1) {
             if (errno == EEXIST) {
                 /* exist, keep the current UUID file */
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UUID_FILE_EXISTS,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_FILE_EXISTS,
                     "The UUID file '%s' already exists\n"), uuid->filename);
                 // return PTS_SUCCESS;  // TODO
                 return OPENPTS_FILE_EXISTS;
             } else {
-                fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
+                ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
                     "Failed to open UUID file %s\n"), uuid->filename);
                 return PTS_INTERNAL_ERROR;
             }
         }
         if ((fp = fdopen(fd, "w")) == NULL) {
-            fprintf(stderr,  NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_FILE_OPEN_FAILED,
                 "Failed to open UUID file %s\n"), uuid->filename);
             return PTS_INTERNAL_ERROR;
         }
index 657c465..c971349 100644 (file)
@@ -77,7 +77,7 @@ PTS_UUID *newUuid() {
 
     uuid = xmalloc(sizeof(PTS_UUID));
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -85,7 +85,7 @@ PTS_UUID *newUuid() {
     uuid_create((uuid_p_t)uuid, &status);
 
     if (uuid_s_ok != status) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UUID_FAILED_GEN_NEW,
+        ERROR(NLS(MS_OPENPTS, OPENPTS_UUID_FAILED_GEN_NEW,
             "Failed to generate an UUID: %s\n"), uuid_s_message[status]);
         xfree(uuid);
         return NULL;
@@ -100,7 +100,7 @@ PTS_UUID *newUuid() {
 void freeUuid(PTS_UUID *uuid) {
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -117,13 +117,13 @@ PTS_UUID *getUuidFromString(char *str) {
 
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     uuid = xmalloc(sizeof(PTS_UUID));
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memset(uuid, 0, UUIDSIZE);
@@ -131,7 +131,7 @@ PTS_UUID *getUuidFromString(char *str) {
     /* cast is ok since there are only hex digits (<128) */
     uuid_from_string((unsigned char *)str, (uuid_p_t)uuid, &status);
     if (uuid_s_ok != status) {
-        ERROR("getUuidFromString() - uuid_from_string failed UUID='%s': %s\n",
+        LOG(LOG_ERR, "getUuidFromString() - uuid_from_string failed UUID='%s': %s\n",
             str, uuid_s_message[status]);
         xfree(uuid);
         return NULL;
@@ -150,13 +150,13 @@ char * getStringOfUuid(PTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     str_uuid = xmalloc(UUID_STRLEN + 1);
     if (str_uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -167,7 +167,7 @@ char * getStringOfUuid(PTS_UUID *uuid) {
     uuid_to_string((uuid_p_t)uuid, (unsigned char **)&str_uuid, &status);
 
     if (uuid_s_ok != status) {
-        ERROR("getStringFromUuid() - uuid_to_string failed: %s\n",
+        LOG(LOG_ERR, "getStringFromUuid() - uuid_to_string failed: %s\n",
             uuid_s_message[status]);
         xfree(str_uuid);
         return NULL;
@@ -194,12 +194,12 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return NULL;
     }
 
     if ((uu->clock_seq_hi_and_reserved & 0xc0) != 0x80) {
-        ERROR("getDateTimeOfUuid () - bad UUID variant (0x%02x) found, can't extract timestamp\n",
+        LOG(LOG_ERR, "getDateTimeOfUuid () - bad UUID variant (0x%02x) found, can't extract timestamp\n",
             (uu->clock_seq_hi_and_reserved & 0xc0) >> 4);
         return NULL;
     }
index 51b2853..ef5cec2 100644 (file)
@@ -69,7 +69,7 @@ time_t uuid_time(uuid_t uu, struct timeval *tv) {
     myUUID.clock_seq_hi_and_reserved = uu[8];
 
     if ((myUUID.clock_seq_hi_and_reserved & 0xc0) != 0x80) {
-        ERROR("uuid_time() - bad UUID variant (0x%02x) found, can't extract timestamp\n",
+        LOG(LOG_ERR, "uuid_time() - bad UUID variant (0x%02x) found, can't extract timestamp\n",
             (myUUID.clock_seq_hi_and_reserved & 0xc0) >> 4);
         return (time_t)-1;
     }
@@ -94,7 +94,7 @@ PTS_UUID *newUuid() {
 
     uuid = xmalloc(sizeof(PTS_UUID));  // BYTE[16]
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -110,7 +110,7 @@ PTS_UUID *newUuid() {
 void freeUuid(PTS_UUID *uuid) {
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return;
     }
 
@@ -128,20 +128,20 @@ PTS_UUID *getUuidFromString(char *str) {
 
     /* check */
     if (str == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     rc = uuid_parse(str, uu);
     if (rc != 0) {
-        ERROR("getUuidFromString() - uuid_parse fail, rc=%d, UUID='%s'",
+        LOG(LOG_ERR, "getUuidFromString() - uuid_parse fail, rc=%d, UUID='%s'",
             rc, str);
         return NULL;
     }
 
     uuid = xmalloc(sizeof(PTS_UUID));
     if (uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(uuid, uu, 16);
@@ -158,13 +158,13 @@ char * getStringOfUuid(PTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return NULL;
     }
 
     str_uuid = xmalloc(37);
     if (str_uuid == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
 
@@ -216,7 +216,7 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
 
     /* check */
     if (uuid == NULL) {
-        ERROR("null input\n");
+        LOG(LOG_ERR, "null input\n");
         return NULL;
     }
 
@@ -228,7 +228,7 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
 
     pdt = xmalloc(sizeof(PTS_DateTime));
     if (pdt == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(pdt, &time, (9*4));
@@ -251,7 +251,7 @@ PTS_DateTime * getDateTime() {
 
     pdt = xmalloc(sizeof(PTS_DateTime));
     if (pdt == NULL) {
-        ERROR("no memory");
+        LOG(LOG_ERR, "no memory");
         return NULL;
     }
     memcpy(pdt, &ttm, (9*4));
index 197c0b6..951a8d5 100644 (file)
@@ -68,20 +68,20 @@ void global_lock(int type) {
     // TODO HOME/.openpts/rwlock is hardcoded here
     home = getenv("HOME");
     if (home == NULL) {
-        ERROR("HOME environment variable not defined\n");
+        LOG(LOG_ERR, "HOME environment variable not defined\n");
         exit(1);
     }
 
     snprintf(path, PATH_MAX, "%s/.openpts", home);
     if (mkdir(path, 0700) < 0 && errno != EEXIST) {
-        ERROR("Can't create dir, %s", path);
+        LOG(LOG_ERR, "Can't create dir, %s", path);
         exit(1);
     }
 
     snprintf(path, PATH_MAX, "%s/.openpts/rwlock", home);
     fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
     if (fd < 0) {
-        ERROR("Can't open lock file, %s", path);
+        LOG(LOG_ERR, "Can't open lock file, %s", path);
         exit(1);
     }
 
@@ -94,7 +94,8 @@ void global_lock(int type) {
     if (fcntl(fd, F_SETLK, &fl) < 0) {
         // get PID of the process holding that lock
         fcntl(fd, F_GETLK, &fl);
-        fprintf(stderr, "Openpts configulation is locked by other(pid=%d)\n", fl.l_pid);
+        ERROR(  // TODO NLS
+            "Openpts configulation is locked by other(pid=%d)\n", fl.l_pid);
         exit(1);
     }
 }
@@ -116,7 +117,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
 
     /* check */
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -128,7 +129,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
     if (checkDir(dirpath) == PTS_SUCCESS) {
         struct stat statBuf;
         if (-1 == stat(conf_file, &statBuf) && ENOENT == errno) {
-            ERROR("Found openpts dir '%s', but no config file - will create one.", dirpath);
+            LOG(LOG_ERR, "Found openpts dir '%s', but no config file - will create one.", dirpath);
             createBasicConfig = 1;
         }
         configDirExists = 1;
@@ -136,7 +137,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
         // create and initialize the $HOME/.openpts directory
         rc = mkdir(dirpath, S_IRUSR | S_IWUSR | S_IXUSR);
         if (rc != 0) {
-            ERROR("mkdir on %s failed (errno=%d)", dirpath, errno);
+            LOG(LOG_ERR, "mkdir on %s failed (errno=%d)", dirpath, errno);
             rc=PTS_FATAL;
             goto error;
         }
@@ -154,7 +155,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
         genOpenptsUuid(conf->uuid);
         rc = writeOpenptsUuidFile(conf->uuid, 1);
         if (rc != PTS_SUCCESS) {
-            ERROR("Can't create UUID file, %s", uuid_file);
+            LOG(LOG_ERR, "Can't create UUID file, %s", uuid_file);
             rc=PTS_FATAL;
             goto error;
         }
@@ -162,7 +163,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
         /* write Conf */
         rc = writeOpenptsConf(conf, conf_file);
         if (rc != PTS_SUCCESS) {
-            ERROR("Can't create config file, %s", conf_file);
+            LOG(LOG_ERR, "Can't create config file, %s", conf_file);
             rc=PTS_FATAL;
             goto error;
         }
@@ -172,7 +173,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
     DEBUG("read conf file          : %s\n", conf_file);
     rc = readOpenptsConf(conf, conf_file);
     if (rc != PTS_SUCCESS) {
-        ERROR("readOpenptsConf() failed\n");
+        LOG(LOG_ERR, "readOpenptsConf() failed\n");
     }
 
     return rc;
@@ -181,7 +182,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
     if (configDirExists == 1) {
         /* rollback delete conf dir? */
         // TODO
-        ERROR("Can't configure the openpts(verifier). "
+        LOG(LOG_ERR, "Can't configure the openpts(verifier). "
               "remove the wasted dir, e.g. rm -rf %s)", dirpath);
     }
 
@@ -239,17 +240,17 @@ int verifierHandleCapability(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     verifier_uuid = conf->uuid;
     if (verifier_uuid == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -259,7 +260,7 @@ int verifierHandleCapability(
     }
     ctx->collector_uuid = newOpenptsUuid2(&cap->platform_uuid);
     if (ctx->collector_uuid == NULL) {
-        // ERROR("Bad collector uuid\n");
+        // LOG(LOG_ERR, "Bad collector uuid\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -270,7 +271,7 @@ int verifierHandleCapability(
     }
     ctx->rm_uuid = newOpenptsUuid2(&cap->manifest_uuid);
     if (ctx->rm_uuid == NULL) {
-        // ERROR("Bad RM uuid\n");
+        // LOG(LOG_ERR, "Bad RM uuid\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -282,7 +283,7 @@ int verifierHandleCapability(
     rc = checkDir(collector_dir);
     if (rc != PTS_SUCCESS) {
         /* DIR is missing, unknwon collector */
-        ERROR("verifier() - Unknown collector, UUID= %s dir= %s, rc=%d\n",
+        LOG(LOG_ERR, "verifier() - Unknown collector, UUID= %s dir= %s, rc=%d\n",
             ctx->collector_uuid->str, collector_dir, rc);
         addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_MISSING_CONFIG_2,
             "Missing collector configuration"));
@@ -312,7 +313,7 @@ int verifierHandleCapability(
 
         rc = readTargetConf(target_conf, target_conf->config_file);
         if (rc != PTS_SUCCESS) {
-            ERROR("verifier() - readTargetConf failed, %s\n", target_conf->config_file);
+            LOG(LOG_ERR, "verifier() - readTargetConf failed, %s\n", target_conf->config_file);
             // WORK NEEDED: Please use NLS for i18n
             addReason(ctx, -1, "Missing collector configuration file");
             addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_COLLECTOR_HOSTNAME,
@@ -328,7 +329,7 @@ int verifierHandleCapability(
         target_conf = ctx->target_conf;
         if (memcmp(target_conf->uuid->uuid, ctx->collector_uuid->uuid, 16) != 0) {
             /* Miss, hostname or IP address was changed?  */
-            ERROR("verifier() - Unexpected collector UUID= %s, must be %s\n",
+            LOG(LOG_ERR, "verifier() - Unexpected collector UUID= %s, must be %s\n",
                 ctx->collector_uuid->str, target_conf->uuid->uuid);
             // WORK NEEDED: Please use NLS for i18n
             addReason(ctx, -1, "Collector configuration was changed");
@@ -424,7 +425,7 @@ int verifierHandleCapability(
             /* Save Old RM */
             rc = writeOpenptsUuidFile(target_conf->oldrm_uuid, 1);
             if (rc != PTS_SUCCESS) {
-                ERROR("writeOpenptsUuidFile fail\n");
+                LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
             }
 
             /* Copy NEWRM to RM */
@@ -436,7 +437,7 @@ int verifierHandleCapability(
             /* Save RM */
             rc = writeOpenptsUuidFile(target_conf->rm_uuid, 1);
             if (rc != PTS_SUCCESS) {
-                ERROR("writeOpenptsUuidFile fail\n");
+                LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
             }
 
             /* Delete New RM */
@@ -451,7 +452,7 @@ int verifierHandleCapability(
             (target_conf->oldrm_uuid->uuid != NULL) &&
             (memcmp(target_conf->oldrm_uuid->uuid, ctx->rm_uuid->uuid, 16) == 0)) {
             /* HIT - fallback ? */
-            TODO("Fallback - TBD\n");
+            LOG(LOG_TODO, "Fallback - TBD\n");
             rc = PTS_RULE_NOT_FOUND;  // TODO
             goto close;
         } else {
@@ -460,7 +461,7 @@ int verifierHandleCapability(
             PTS_DateTime *t0;
             PTS_DateTime *t1;
 
-            ERROR("RM changed %s -> %s (not new rm)\n",
+            LOG(LOG_ERR, "RM changed %s -> %s (not new rm)\n",
                 target_conf->rm_uuid->str, ctx->rm_uuid->str);
 
             // TODO DEBUG("RM changed %s -> %s\n", target_conf->rm_uuid->str, rm_uuid->str);
@@ -513,7 +514,7 @@ int verifierHandleCapability(
     rc = checkDir(rm_dir);
     if (rc != PTS_SUCCESS && 0 == *currentRmOutOfDate) {
         /* unknwon RM */
-        ERROR("verifier() - Unknown RM, (RM dir = %s)\n", rm_dir);
+        LOG(LOG_ERR, "verifier() - Unknown RM, (RM dir = %s)\n", rm_dir);
         addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_MISSING_RM,
             "Missing Reference Manifest (RM)"));
         addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_COLLECTOR_HOSTNAME,
@@ -551,7 +552,7 @@ int verifierHandleCapability(
     for (i = 0; i< target_conf->rm_num; i++) {
         struct stat st;
         if (lstat(target_conf->rm_filename[i], &st) == -1) {
-            ERROR("verifier - RM (%s) is missing. Get RM from target. enroll(init) first\n",
+            LOG(LOG_ERR, "verifier - RM (%s) is missing. Get RM from target. enroll(init) first\n",
                 target_conf->rm_filename[i]);
             rc = PTS_INTERNAL_ERROR;
             goto close;
@@ -585,16 +586,16 @@ int verifierHandleRimmSet(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     target_conf = ctx->target_conf;
     if (target_conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -611,14 +612,14 @@ int verifierHandleRimmSet(
         /* Missing rm_basedir => create */
         rc = mkdir(target_conf->rm_basedir, S_IRUSR | S_IWUSR | S_IXUSR);
         if (rc != 0) {
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONF_DIR_CREATE_FAILED,
-                    "Failed to create the configuration directory '%s'\n"), buf);
+            ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONF_DIR_CREATE_FAILED,
+                "Failed to create the configuration directory '%s'\n"), buf);
             rc = PTS_INTERNAL_ERROR;
             goto error;
         }
     } else if ((st.st_mode & S_IFMT) != S_IFDIR) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_RM_DIR_NOT_DIR,
-                "The reference manifest path '%s' is not a directory\n"), buf);
+        ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_RM_DIR_NOT_DIR,
+            "The reference manifest path '%s' is not a directory\n"), buf);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -646,7 +647,7 @@ int verifierHandleRimmSet(
 
         rc = saveToFile(target_conf->rm_filename[i], len, value);
         if (rc != PTS_SUCCESS) {
-            ERROR("enroll - save RM[%d], %s failed\n", i, target_conf->rm_filename[i]);
+            LOG(LOG_ERR, "enroll - save RM[%d], %s failed\n", i, target_conf->rm_filename[i]);
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -660,7 +661,7 @@ int verifierHandleRimmSet(
 
     rc = writeOpenptsUuidFile(target_conf->rm_uuid, 1);  // TODO do not overwite?
     if (rc != PTS_SUCCESS) {
-        ERROR("writeOpenptsUuidFile fail\n");
+        LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
     }
 
   close:
@@ -687,17 +688,18 @@ int  writePolicyConf(OPENPTS_CONTEXT *ctx, char *filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if ((fp = fopen(filename, "w")) == NULL) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_OPEN_FAILED, "Failed to open policy file '%s'\n"), filename);
-        return -1;
+        ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_OPEN_FAILED,
+            "Failed to open policy file '%s'\n"), filename);
+        return PTS_FATAL;
     }
 
     /* top */
@@ -760,16 +762,16 @@ int  writeAideIgnoreList(OPENPTS_CONTEXT *ctx, char *filename) {
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (filename == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
     if ((fp = fopen(filename, "w")) == NULL) {
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_OPEN_FAILED_2,
+        ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_OPEN_FAILED_2,
             "Failed to open AIDE ignore list '%s'\n"), filename);
         return -1;
     }
@@ -777,7 +779,7 @@ int  writeAideIgnoreList(OPENPTS_CONTEXT *ctx, char *filename) {
     /* top */
     ss = getSnapshotFromTable(ctx->ss_table, 10, 1);  // Linux-IMA, TODO define by CONF?
     if (ss == NULL) {
-        ERROR("Snapshot at PCR[10] level 1 is missing\n");
+        LOG(LOG_ERR, "Snapshot at PCR[10] level 1 is missing\n");
     } else {
         ew = ss->start;
 
@@ -791,11 +793,11 @@ int  writeAideIgnoreList(OPENPTS_CONTEXT *ctx, char *filename) {
         rc = hcreate_r(HASH_TABLE_SIZE, &hd);
         if (rc == 0) {
             if (errno == ENOMEM) {
-                ERROR("ENOMEM\n");
+                LOG(LOG_ERR, "ENOMEM\n");
                 cnt = -1;
                 goto error;
             }
-            ERROR("ERROR rc=%d\n", rc);
+            LOG(LOG_ERR, "ERROR rc=%d\n", rc);
             // return -1;
             cnt = -1;
             goto error;
@@ -861,16 +863,16 @@ int verifierHandleIR(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     target_conf = ctx->target_conf;
     if (target_conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     if (value == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -880,14 +882,14 @@ int verifierHandleIR(
         if (rc != PTS_SUCCESS) {
             DEBUG("target_conf->ir_filename, %s\n", target_conf->ir_filename);
             addReason(ctx, -1, "[IMV] failed to save IR, %s)", target_conf->ir_filename);
-            fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_SAVE_IR_FAILED,
+            ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_SAVE_IR_FAILED,
                 "[verifier] failed to save IR\n"));
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
     } else {
         addReason(ctx, -1, "[IMV] failed to send IR)");
-        fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_VERIFIER_SEND_IR_FAILED,
+        ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_SEND_IR_FAILED,
             "[verifier] failed to send IR\n"));
         rc = PTS_INTERNAL_ERROR;
         goto close;
@@ -899,7 +901,7 @@ int verifierHandleIR(
     for (i = 0; i <  target_conf->rm_num; i++) {
         rc = readRmFile(ctx, target_conf->rm_filename[i], i);
         if (rc < 0) {
-            ERROR("readRmFile fail\n");
+            LOG(LOG_ERR, "readRmFile fail\n");
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -910,7 +912,7 @@ int verifierHandleIR(
         DEBUG("Load Policy  -------------------------------- \n");
         rc = loadPolicyFile(ctx, target_conf->policy_filename);
         if (rc < 0) {
-            ERROR("loadPolicyFile fail\n");
+            LOG(LOG_ERR, "loadPolicyFile fail\n");
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -932,7 +934,7 @@ int verifierHandleIR(
 
         rc = saveProperties(ctx, target_conf->prop_filename);
         if (rc != PTS_SUCCESS) {
-            ERROR("saveProperties was failed %s\n", target_conf->prop_filename);
+            LOG(LOG_ERR, "saveProperties was failed %s\n", target_conf->prop_filename);
             goto close;
         }
     } else if (mode == OPENPTS_UPDATE_MODE) {
@@ -947,7 +949,7 @@ int verifierHandleIR(
         }
 #endif
     } else {
-        ERROR("unknown mode %d\n", mode);
+        LOG(LOG_ERR, "unknown mode %d\n", mode);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -993,11 +995,11 @@ int enroll(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_INTERNAL_ERROR;
     }
     if (ctx->conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_INTERNAL_ERROR;
     }
 
@@ -1019,7 +1021,7 @@ int enroll(
         // the target UUID may have been reseted, erase the known one
         unlinkDir(target->dir);
     } else if (ctx->target_conf != NULL) {
-        ERROR("enroll() - target_conf of %s already exist?\n", host);
+        LOG(LOG_ERR, "enroll() - target_conf of %s already exist?\n", host);
         goto out;
     }
 
@@ -1047,7 +1049,7 @@ int enroll(
     /* V->C capability (hello) */
     len = writePtsTlv(ctx, sock, OPENPTS_CAPABILITIES);
     if (len < 0) {
-        ERROR("Failed to send capability message, rc = %d\n", len);
+        LOG(LOG_ERR, "Failed to send capability message, rc = %d\n", len);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1055,19 +1057,19 @@ int enroll(
     /* C->V capability (hello) */
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("Can not get the message from collector\n");
+        LOG(LOG_ERR, "Can not get the message from collector\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
 
     if (read_tlv->type != OPENPTS_CAPABILITIES) {
-        ERROR("Expected OPENPTS_CAPABILITIES reply, instead got type '%d'\n", read_tlv->type);
+        LOG(LOG_ERR, "Expected OPENPTS_CAPABILITIES reply, instead got type '%d'\n", read_tlv->type);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
 
     if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) {  // TODO set name
-        ERROR("UUID length = %d != 36\n", read_tlv->length);
+        LOG(LOG_ERR, "UUID length = %d != 36\n", read_tlv->length);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1163,7 +1165,7 @@ int enroll(
     /* V->C template RIMM req  */
     len = writePtsTlv(ctx, sock, REQUEST_RIMM_SET);
     if (len < 0) {
-        ERROR("template RIMM req was failed\n");
+        LOG(LOG_ERR, "template RIMM req was failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1171,22 +1173,22 @@ int enroll(
     /* C->V template RIMM (RIMM embedded to CTX) */
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("Problem receiving PTS message\n");
+        LOG(LOG_ERR, "Problem receiving PTS message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type == OPENPTS_ERROR) {
-        ERROR("Request RIMM_SET was failed. collector returns error message");
+        LOG(LOG_ERR, "Request RIMM_SET was failed. collector returns error message");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != RIMM_SET) {
-        ERROR("Bad return message, %X != %X", read_tlv->type, RIMM_SET);
+        LOG(LOG_ERR, "Bad return message, %X != %X", read_tlv->type, RIMM_SET);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
 
     rc = verifierHandleRimmSet(ctx, (BYTE*) read_tlv->value);
     if (rc != PTS_SUCCESS) {
-        ERROR("Bad RIMM_SET?");
+        LOG(LOG_ERR, "Bad RIMM_SET?");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1200,7 +1202,7 @@ int enroll(
     len = writePtsTlv(ctx, sock, REQUEST_TPM_PUBKEY);  // ifm.c
 
     if (len < 0) {
-        ERROR("enroll() - REQUEST_TPM_PUBKEY was failed, len=%d\n", len);
+        LOG(LOG_ERR, "enroll() - REQUEST_TPM_PUBKEY was failed, len=%d\n", len);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1208,18 +1210,18 @@ int enroll(
     /* C->V TPM PUBKEY */
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("Problem receiving PTS message\n");
+        LOG(LOG_ERR, "Problem receiving PTS message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type == OPENPTS_ERROR) {
         // TODO Ignore now
-        TODO("Target did not have TPM_PUBKEY");
+        LOG(LOG_TODO, "Target did not have TPM_PUBKEY");
         // WORK NEEDED - Please use NLS for i18n
         addReason(ctx, -1, "Target did not have TPM_PUBKEY\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != TPM_PUBKEY) {
-        ERROR("read_tlv->type != TPM_PUBKEY, but %d", read_tlv->type);
+        LOG(LOG_ERR, "read_tlv->type != TPM_PUBKEY, but %d", read_tlv->type);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1249,12 +1251,12 @@ int enroll(
 
 
 #ifdef CONFIG_AIDE
-    // TODO(munetoh) capability defile validation mode of collector
+    // LOG(LOG_TODO, munetoh) capability defile validation mode of collector
     /* V->C AIDE_DATABASE req  */
     len = writePtsTlv(ctx, sock, REQUEST_AIDE_DATABASE);
 
     if (len < 0) {
-        ERROR("template RIMM req was failed\n");
+        LOG(LOG_ERR, "template RIMM req was failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1262,7 +1264,7 @@ int enroll(
     /* C->V AIDE DATABASE */
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("Problem receiving PTS message\n");
+        LOG(LOG_ERR, "Problem receiving PTS message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != AIDE_DATABASE) {
@@ -1272,7 +1274,7 @@ int enroll(
             target_conf->ima_validation_mode = OPENPTS_VALIDATION_MODE_NONE;
             DEBUG("enroll - AIDE DB is missing. do not validate IMA's IMLs\n");
         } else {
-            ERROR("enroll - RAIDE DB req. returns unknown message type 0x%x", read_tlv->type);
+            LOG(LOG_ERR, "enroll - RAIDE DB req. returns unknown message type 0x%x", read_tlv->type);
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -1284,7 +1286,7 @@ int enroll(
 
             rc = saveToFile(target_conf->aide_database_filename, read_tlv->length, read_tlv->value);
             if (rc < 0) {
-                ERROR("enroll - save AIDE DB failed\n");
+                LOG(LOG_ERR, "enroll - save AIDE DB failed\n");
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1295,7 +1297,7 @@ int enroll(
                     ctx->conf->aide_database_filename,
                     ctx->conf->aide_sqlite_filename);
             if (rc != PTS_SUCCESS) {
-                ERROR("enroll - convert AIDE DB to SQLiteDB was failed\n");
+                LOG(LOG_ERR, "enroll - convert AIDE DB to SQLiteDB was failed\n");
                 rc = PTS_INTERNAL_ERROR;
                 goto close;
             }
@@ -1376,12 +1378,12 @@ int verifier(
 
     /* check */
     if (ctx == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
     conf = ctx->conf;
     if (conf == NULL) {
-        ERROR("null input");
+        LOG(LOG_ERR, "null input");
         return PTS_FATAL;
     }
 
@@ -1393,7 +1395,7 @@ int verifier(
                           &sock);
 
     if (ssh_pid == -1) {
-        ERROR("connection failed (server = %s)\n", host);
+        LOG(LOG_ERR, "connection failed (server = %s)\n", host);
         addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONNECT_FAILED,
             "Connection failed (server = %s)\n"), host);
         rc = PTS_OS_ERROR;
@@ -1405,7 +1407,7 @@ int verifier(
     /* V->C capability (hello) */
     len = writePtsTlv(ctx, sock, OPENPTS_CAPABILITIES);
     if (len < 0) {
-        ERROR("Failed to send capability message\n");
+        LOG(LOG_ERR, "Failed to send capability message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1413,16 +1415,16 @@ int verifier(
     /* C->V capability (hello) */
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("can't connect to target, %s\n", host);
+        LOG(LOG_ERR, "can't connect to target, %s\n", host);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != OPENPTS_CAPABILITIES) {
-        ERROR("Expected OPENPTS_CAPABILITIES reply, instead got type '%d'\n", read_tlv->type);
+        LOG(LOG_ERR, "Expected OPENPTS_CAPABILITIES reply, instead got type '%d'\n", read_tlv->type);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) {
         // TODO PTS_CAPABILITIES_SIZE
-        ERROR("UUID length = %d != 36\n", read_tlv->length);
+        LOG(LOG_ERR, "UUID length = %d != 36\n", read_tlv->length);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1431,7 +1433,7 @@ int verifier(
     rc = verifierHandleCapability(ctx, conf_dir, host, cap,
                                   &notifiedOfPendingRm, &currentRmOutOfDate);
     if (rc != PTS_SUCCESS) {
-        ERROR("Failed to exchange capabilities\n");
+        LOG(LOG_ERR, "Failed to exchange capabilities\n");
         goto close;
     }
 
@@ -1444,7 +1446,7 @@ int verifier(
     /*   send req   */
     len = writePtsTlv(ctx, sock, DH_NONCE_PARAMETERS_REQUEST);
     if (len < 0) {
-        ERROR("Failed to send nonce parameters request\n");
+        LOG(LOG_ERR, "Failed to send nonce parameters request\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1455,11 +1457,11 @@ int verifier(
 
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("[IF-M] DH_NONCE_PARAMETERS_REQUEST was failed, check the collector");
+        LOG(LOG_ERR, "[IF-M] DH_NONCE_PARAMETERS_REQUEST was failed, check the collector");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != DH_NONCE_PARAMETORS_RESPONSE) {
-        ERROR("Expected DH_NONCE_PARAMETORS_RESPONSE reply, but instead got type '%d'\n",
+        LOG(LOG_ERR, "Expected DH_NONCE_PARAMETORS_RESPONSE reply, but instead got type '%d'\n",
             read_tlv->type);
         rc = PTS_INTERNAL_ERROR;
         goto close;
@@ -1475,7 +1477,7 @@ int verifier(
     ctx->nonce->res->hash_alg_set        = (read_tlv->value[6]<<8) | read_tlv->value[7];
 
     if (ctx->nonce->res->nonce_length < MINIMUM_NONCE_LENGTH) {
-        ERROR("Expected minimum nonce length of '%d', instead got '%d'\n",
+        LOG(LOG_ERR, "Expected minimum nonce length of '%d', instead got '%d'\n",
             MINIMUM_NONCE_LENGTH, ctx->nonce->res->nonce_length);
         rc = PTS_INTERNAL_ERROR;
         goto close;
@@ -1483,7 +1485,7 @@ int verifier(
 
     /* set pubkey length */
     if ( 0 != setDhPubkeylength(ctx->nonce) ) {
-        ERROR("setDhPubkeylength failed\n");
+        LOG(LOG_ERR, "setDhPubkeylength failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1505,7 +1507,7 @@ int verifier(
 
     rc = calcDh(ctx->nonce);
     if (rc != 0) {
-        ERROR("calcDh failed\n");
+        LOG(LOG_ERR, "calcDh failed\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1513,7 +1515,7 @@ int verifier(
     /* V->C D-H nonce finish  --------------------------------------------- */
     len = writePtsTlv(ctx, sock, DH_NONCE_FINISH);
     if (len < 0) {
-        ERROR("Failed to send nonce finish message\n");
+        LOG(LOG_ERR, "Failed to send nonce finish message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1521,7 +1523,7 @@ int verifier(
     /* V->C IR req -------------------------------------------------------- */
     len = writePtsTlv(ctx, sock, REQUEST_INTEGRITY_REPORT);
     if (len < 0) {
-        ERROR("Failed to send request integrity report message\n");
+        LOG(LOG_ERR, "Failed to send request integrity report message\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1532,18 +1534,18 @@ int verifier(
 
     read_tlv = readPtsTlv(sock);
     if (read_tlv == NULL) {
-        ERROR("Failed to get integrity report. Please check the collector.\n");
+        LOG(LOG_ERR, "Failed to get integrity report. Please check the collector.\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     } else if (read_tlv->type != INTEGRITY_REPORT) {
-        ERROR("read_tlv->type != INTEGRITY_REPORT, but 0x%X (0x0F:OPENPTS_ERROR)", read_tlv->type);
+        LOG(LOG_ERR, "read_tlv->type != INTEGRITY_REPORT, but 0x%X (0x0F:OPENPTS_ERROR)", read_tlv->type);
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
 
     rc = verifierHandleIR(ctx, read_tlv->length, read_tlv->value, mode, &result);
     if (rc != PTS_SUCCESS) {
-        ERROR("verifierHandleIR fail\n");
+        LOG(LOG_ERR, "verifierHandleIR fail\n");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }
@@ -1559,7 +1561,7 @@ int verifier(
         /* V->C template RIMM req  */
         rc = writePtsTlv(ctx, sock, REQUEST_NEW_RIMM_SET);
         if (rc < 0) {
-            ERROR("writePtsTlv() fail");
+            LOG(LOG_ERR, "writePtsTlv() fail");
             rc = PTS_INTERNAL_ERROR;
             goto close;
         }
@@ -1583,7 +1585,7 @@ int verifier(
     /* V->C VR */
     len = writePtsTlv(ctx, sock, VERIFICATION_RESULT);
     if (len < 0) {
-        ERROR("writePtsTlv() fail");
+        LOG(LOG_ERR, "writePtsTlv() fail");
         rc = PTS_INTERNAL_ERROR;
         goto close;
     }