• R/O
  • HTTP
  • SSH
  • HTTPS

openpts: 提交

Repo for OpenPTS version 0.2.X


Commit MetaInfo

修订版12470d822a7130b2968d0dd598ff838c7a244ab3 (tree)
时间2012-01-05 14:40:05
作者Seiji Munetoh <munetoh@jp.i...>
CommiterSeiji Munetoh

Log Message

cleanup

更改概述

差异

--- a/ChangeLog
+++ b/ChangeLog
@@ -7,11 +7,13 @@ openpts (0.2.6) unstable; urgency=low
77 * Locking to ensure only one instance of ptsc and openpts will run at the same time.
88 * Added the doorbell ringer(ptsevt) and the listener (ptsevtd)
99 * Added clear option. e.g. ptsc -e
10- * Improved error handling and messages
10+ * Improved error handling and messages (console and logging)
1111 * Renew validation models (models/*uml), default ptsc.conf
1212 * Added UEFI BIOS validation models
13+ * Refactoring Infineon v1.2 TPM workaround
14+ * Bug fixes
1315
14- -- Seiji Munetoh <munetoh@users.sourceforge.jp> Fri, 16 Dec 2011 12:00:00 +0900
16+ -- Seiji Munetoh <munetoh@users.sourceforge.jp> Thu, 5 Jan 2012 14:40:00 +0900
1517
1618 openpts (0.2.5.1) unstable; urgency=low
1719
--- a/include/openpts.h
+++ b/include/openpts.h
@@ -703,9 +703,9 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fd, int type);
703703
704704
705705 /* collector.c */
706-int collector(
707- OPENPTS_CONFIG *conf,
708- int forground, int debug, const char* dirname);
706+//int collector(
707+// OPENPTS_CONFIG *conf,
708+// int forground, int debug, const char* dirname);
709709
710710 /* verifier.c */
711711 int verifier(
@@ -940,6 +940,7 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir);
940940 int purgeRenewedRm(OPENPTS_CONFIG *conf);
941941 void printRmList(OPENPTS_CONFIG *conf, char *indent);
942942 int getTargetList(OPENPTS_CONFIG *conf, char * config_dir);
943+void printTarget(OPENPTS_TARGET *target_collector, char *indent);
943944 void printTargetList(OPENPTS_CONFIG *conf, char *indent);
944945 char *getTargetConfDir(OPENPTS_CONFIG *conf);
945946 OPENPTS_TARGET *getTargetCollector(OPENPTS_CONFIG *conf);
--- a/include/openpts_log.h
+++ b/include/openpts_log.h
@@ -27,6 +27,7 @@
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @author David Sherwood <davidshe@uk.ibm.com>
2929 * @date 2011-05-05
30+ * cleanup 2012-01-04
3031 *
3132 */
3233
@@ -113,9 +114,7 @@ writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
113114 #define getDebugFlags() (debugBits)
114115 #define addDebugFlags(x) (debugBits |= (x))
115116
116-
117-
118-
117+/* functions */
119118 void writeLog(int priority, const char *format, ...);
120119 void initCatalog(void);
121120 void setLogLocation(int ll, char *filename);
--- a/include/openpts_msg.csv
+++ b/include/openpts_msg.csv
@@ -45,6 +45,7 @@ fsm.c,2446,,OPENPTS_PRINT_FSM_BASE64
4545 rm.c,1751,,OPENPTS_RM_CONF_DIR_MISSING
4646 log.c,368,,OPENPTS_CANNOT_OPEN_LOGFILE
4747 action.c,,,OPENPTS_ACTION_UNKNOWN
48+action.c,,VERBOSE,OPENPTS_ACTION_PROP_CONFLICT
4849 prop.c,,,OPENPTS_PRINT_PROPS
4950 policy.c,,,OPENPTS_POLICY_FILE_OPEN_FAILED
5051 policy.c,,,OPENPTS_POLICY_MISSING
@@ -88,6 +89,8 @@ collector.c,,,OPENPTS_INIT_SUCCESS
8889 collector.c,,,OPENPTS_INIT_FAIL
8990 collector.c,,,OPENPTS_COLLECTOR_SELFTEST_FAILED
9091 collector.c,,,OPENPTS_COLLECTOR_SELFTEST_FAILED_2
92+collector.c,,ERROR,OPENPTS_COLLECTOR_SELFTEST_FAILED_3
93+collector.c,,ERROR,OPENPTS_COLLECTOR_SELFTEST_FAILED_4
9194 collector.c,,,OPENPTS_COLLECTOR_FAILED_READ_FSM
9295 collector.c,,,OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED
9396 collector.c,,,OPENPTS_NEW_RM_UUID
@@ -230,11 +233,17 @@ iml2aide.c,,,OPENPTS_IML2AIDE_DATABASE_2
230233 iml2aide.c,,,OPENPTS_IML2AIDE_IGN_LIST
231234 openpts.c,,,OPENPTS_VERIFY_NEW_UUID_REMOTE
232235 tpm_createkey.c,,,OPENPTS_TPM_CREATEKEY_USAGE
233-
234-
235-
236-
237-
238-
239-
236+verifier.c,,,OPENPTS_VERIFIER_LOCKED
237+openpts.c,,,OPENPTS_TARGET_MISSING
238+openpts.c,,,OPENPTS_INIT_ENROLL_FAIL
239+openpts.c,,,OPENPTS_INIT_VERIFICATION_FAIL
240+target,,,OPENPTS_PRINT_TARGET_LIST_NULL
241+target,,,OPENPTS_TARGET_CONFDIR_MISSING
242+target,,,OPENPTS_TARGET_NULL
243+ptsc.c,,,OPENPTS_COLLECTOR_NOT_INITIALIZED
244+ptsc.c,,,OPENPTS_COLLECTOR_CONFIG_FILE
245+misc.c,,ERROR,OPENPTS_MALLOC_FAIL
246+misc.c,,ERROR,OPENPTS_ABORT
247+tboot2iml.c,,OUTPUT,OPENPTS_TBOOT2IML_USAGE
248+tboot2iml.c,,ERROR,OPENPTS_TBOOT2IML_GRUBPATH_MISSING
240249
--- a/src/action.c
+++ b/src/action.c
@@ -26,7 +26,7 @@
2626 * \brief FSM action
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-06-19
29- * cleanup 2011-07-20 SM
29+ * cleanup 2012-01-05 SM (remains 5 lint errors)
3030 *
3131 * FSM Action (UML2 doActivity)
3232 *
@@ -85,9 +85,20 @@ typedef struct {
8585 */
8686 int resetPCR(OPENPTS_CONTEXT *ctx, char *value) {
8787 int rc;
88- int pcr_index = atoi(value);
88+ int pcr_index;
8989
90- DEBUG_FSM("resetPCR(%d)\n", pcr_index);
90+ /* check */
91+ if (ctx == NULL) {
92+ LOG(LOG_ERR, "null input");
93+ return PTS_FATAL;
94+ }
95+ if (value == NULL) {
96+ LOG(LOG_ERR, "null input");
97+ return PTS_FATAL;
98+ }
99+ pcr_index = atoi(value);
100+
101+ /* reset */
91102 rc = resetTpmPcr(&ctx->tpm, pcr_index);
92103 if (rc != PTS_SUCCESS) {
93104 LOG(LOG_ERR, "reset PCR[%d] was failed, check the model");
@@ -97,6 +108,8 @@ int resetPCR(OPENPTS_CONTEXT *ctx, char *value) {
97108 /* Also, reset the action counter */
98109 ctx->bios_action_count = 0;
99110
111+ DEBUG_FSM("resetPCR(%d)\n", pcr_index);
112+
100113 return PTS_SUCCESS;
101114 }
102115
@@ -118,21 +131,25 @@ int addBIOSAction(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
118131
119132 /* check */
120133 if (eventWrapper == NULL) {
121- // TODO do not care for dummy EW
122- DEBUG("null input\n"); // TODO is this OK?
123- // TODO define RC <-> fsm.c >> INFO:(TODO) fsm.c:986 updateFsm() - rc = 58, call updateFsm() again
134+ // do not care for dummy EW, not a error.
135+ DEBUG("null input");
124136 return PTS_INTERNAL_ERROR;
125137 }
138+ if (ctx == NULL) {
139+ LOG(LOG_ERR, "null input");
140+ return PTS_FATAL;
141+ }
126142
127143 event = eventWrapper->event;
128144 if (event == NULL) {
129- LOG(LOG_ERR, "null input\n");
145+ LOG(LOG_ERR, "null input");
130146 return PTS_FATAL;
131147 }
132148
133149 /* value = eventdata */
134150 value = snmalloc((char *)event->rgbEvent, event->ulEventLength);
135151 if (value == NULL) {
152+ LOG(LOG_ERR, "no memory");
136153 return PTS_FATAL;
137154 }
138155
@@ -141,11 +158,11 @@ int addBIOSAction(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper)
141158 snprintf(name, BUF_SIZE, "bios.pcr.%d.action.%d", event->ulPcrIndex, ctx->bios_action_count);
142159 ctx->bios_action_count++;
143160
161+ setProperty(ctx, name, value);
144162
145163 DEBUG_FSM("[FSM] addBIOSAction() - '%s' = '%s'\n", name, value);
146164
147- setProperty(ctx, name, value);
148-
165+ /* free */
149166 xfree(value);
150167
151168 return PTS_SUCCESS;
@@ -173,21 +190,23 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
173190 UINT32 event_id;
174191 UINT32 event_length;
175192
193+ /* check */
194+ if (ctx == NULL) {
195+ LOG(LOG_ERR, "null input");
196+ return PTS_FATAL;
197+ }
198+
176199 /* event */
177200 if (eventWrapper == NULL) {
178201 LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n");
179202 return PTS_INTERNAL_ERROR; // -1
180203 }
181204 event = eventWrapper->event;
182-
183205 if (event->eventType != 0x06) {
184206 LOG(LOG_ERR, "addBIOSSpecificProperty - bad event type 0x%x !- 0x06\n", event->eventType);
185207 return PTS_INTERNAL_ERROR; // -1
186208 }
187209
188- // DEBUG("event data size = %d\n", event->ulEventLength);
189- // printHex("", event->rgbEvent, event->ulEventLength, "\n");
190-
191210 /* check EventData */
192211 if (event->ulEventLength == 0) {
193212 LOG(LOG_ERR, "addBIOSSpecificProperty - Bad IML, ulEventLength is 0.");
@@ -198,12 +217,10 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
198217 return PTS_FATAL;
199218 }
200219
201-
220+ /* event */
202221 event_id = byte2uint32(&event->rgbEvent[0]);
203222 event_length = byte2uint32(&event->rgbEvent[4]);
204223
205- // DEBUG("event data size = %d, id = 0x%x, len %d,\n", event->ulEventLength, event_id, event_length);
206-
207224 switch (event_id) {
208225 case 0x0001:
209226 {
@@ -229,7 +246,6 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
229246 } else {
230247 setProperty(ctx, "bios.smbios", buf);
231248 }
232- // rc = 0;
233249 xfree(buf);
234250 }
235251 break;
@@ -239,7 +255,7 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
239255 break;
240256 }
241257
242- return PTS_SUCCESS; // -1;
258+ return PTS_SUCCESS;
243259 }
244260
245261
@@ -253,16 +269,21 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
253269 int validateMBR(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
254270 TSS_PCR_EVENT *event;
255271
272+ /* check */
273+ if (ctx == NULL) {
274+ LOG(LOG_ERR, "null input");
275+ return PTS_FATAL;
276+ }
256277 if (eventWrapper == NULL) {
257278 LOG(LOG_ERR, "null input");
258- return PTS_INTERNAL_ERROR; // -1;
279+ return PTS_FATAL;
259280 }
260281
261282 event = eventWrapper->event;
262283
263284 if (event == NULL) {
264285 LOG(LOG_ERR, "event is NULL\n");
265- return PTS_INTERNAL_ERROR; // -1;
286+ return PTS_FATAL; // -1;
266287 }
267288
268289 // TODO
@@ -287,22 +308,25 @@ int validateMBR(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
287308 int validateEltoritoBootImage(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
288309 TSS_PCR_EVENT *event;
289310
290- // DEBUG("validateEltoritoBootImage - NA\n");
291-
311+ /* check */
312+ if (ctx == NULL) {
313+ LOG(LOG_ERR, "null input");
314+ return PTS_FATAL;
315+ }
292316 if (eventWrapper == NULL) {
293317 LOG(LOG_ERR, "eventWrapper is NULL\n");
294- return PTS_INTERNAL_ERROR; // -1;
318+ return PTS_FATAL;
295319 }
296-
297320 event = eventWrapper->event;
298321 if (event == NULL) {
299322 LOG(LOG_ERR, "event is NULL\n");
300- return PTS_INTERNAL_ERROR; // -1;
323+ return PTS_FATAL;
301324 }
302325
326+ /* set prop */
303327 setProperty(ctx, "ipl.eltorito.integrity", "unknown");
304328
305- return PTS_SUCCESS; // -1;
329+ return PTS_SUCCESS;
306330 }
307331
308332 /**
@@ -320,19 +344,19 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap
320344 char *buf;
321345 int buf_len;
322346
323- // DEBUG("setModuleProperty - NA\n");
324-
325347 /* check */
348+ if (ctx == NULL) {
349+ LOG(LOG_ERR, "null input");
350+ return PTS_FATAL;
351+ }
326352 if (eventWrapper == NULL) {
327353 LOG(LOG_ERR, "eventWrapper is NULL\n");
328- return PTS_INTERNAL_ERROR; // -1;
354+ return PTS_FATAL;
329355 }
330-
331356 event = eventWrapper->event;
332-
333357 if (event == NULL) {
334358 LOG(LOG_ERR, "event is NULL\n");
335- return PTS_INTERNAL_ERROR; // -1;
359+ return PTS_FATAL;
336360 }
337361
338362 /* kernel.initrd.digest = PCR => B64 digest */
@@ -342,7 +366,7 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap
342366 &buf_len);
343367 if (buf == NULL) {
344368 LOG(LOG_ERR, "encodeBase64 fail");
345- return PTS_INTERNAL_ERROR;
369+ return PTS_FATAL;
346370 }
347371 setProperty(ctx, "kernel.initrd.digest", buf);
348372 xfree(buf);
@@ -355,6 +379,9 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap
355379 buf[event->ulEventLength] = 0;
356380 setProperty(ctx, "kernel.initrd.filename", buf);
357381 xfree(buf);
382+ } else {
383+ LOG(LOG_ERR, "no memory");
384+ return PTS_FATAL;
358385 }
359386
360387 return PTS_SUCCESS; // -1;
@@ -396,19 +423,20 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP
396423
397424 DEBUG_CAL("setLinuxKernelCmdlineAssertion - start\n");
398425
399- /* input check */
426+ /* check */
427+ if (ctx == NULL) {
428+ LOG(LOG_ERR, "null input");
429+ return PTS_FATAL;
430+ }
400431 if (eventWrapper == NULL) {
401432 LOG(LOG_ERR, "eventWrapper is NULL\n");
402433 return PTS_FATAL;
403434 }
404-
405435 event = eventWrapper->event;
406-
407436 if (event == NULL) {
408437 LOG(LOG_ERR, "event is NULL\n");
409438 return PTS_FATAL;
410439 }
411-
412440 if (event->rgbEvent == NULL) {
413441 LOG(LOG_ERR, "event->rgbEvent is NULL, BAD IML?\n");
414442 return PTS_FATAL;
@@ -420,6 +448,10 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP
420448
421449 /* copy(malloc) strings */
422450 cmdline = snmalloc((char *)event->rgbEvent, event->ulEventLength);
451+ if (cmdline == NULL) {
452+ LOG(LOG_ERR, "snmalloc() fail");
453+ return PTS_FATAL;
454+ }
423455
424456 /* first string = kernel filename */
425457 tp = strtok_r(cmdline, " ", &saveptr);
@@ -443,8 +475,8 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP
443475 "Property %s=%s and %s=%s are conflicted. Drop them from the policy list.",
444476 name, prop->value,
445477 name, value);
446- VERBOSE(2, // TODO NLS
447- "Property %s=%s and %s=%s are conflicted. Drop them from the policy list.",
478+ VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_ACTION_PROP_CONFLICT,
479+ "Property %s=%s and %s=%s are conflicted. Drop them from the policy list."),
448480 name, prop->value,
449481 name, value);
450482 prop->ignore = 1;
@@ -500,19 +532,23 @@ int validateImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventW
500532 SHA_CTX sha_ctx;
501533 BYTE digest[SHA1_DIGEST_SIZE];
502534
503- // DEBUG("validateImaAggregate - NA\n");
504-
505535 /* check */
536+ if (ctx == NULL) {
537+ LOG(LOG_ERR, "null input");
538+ return PTS_FATAL;
539+ }
506540 if (eventWrapper == NULL) {
507541 LOG(LOG_ERR, "null input\n");
508- return PTS_INTERNAL_ERROR; // -1;
542+ return PTS_FATAL;
509543 }
510-
511544 event = eventWrapper->event;
512-
513545 if (event == NULL) {
514546 LOG(LOG_ERR, "event is NULL\n");
515- return PTS_INTERNAL_ERROR; // -1;
547+ return PTS_FATAL;
548+ }
549+ if (event->rgbEvent == NULL) {
550+ LOG(LOG_ERR, "null input\n");
551+ return PTS_FATAL;
516552 }
517553
518554 /* init SHA1 */
@@ -589,18 +625,23 @@ int validateOldImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
589625 SHA_CTX sha_ctx;
590626 BYTE digest[SHA1_DIGEST_SIZE];
591627
592- // DEBUG("validateOldImaAggregate - NA\n");
593-
594628 /* check */
629+ if (ctx == NULL) {
630+ LOG(LOG_ERR, "null input");
631+ return PTS_FATAL;
632+ }
595633 if (eventWrapper == NULL) {
596- LOG(LOG_ERR, "eventWrapper is NULL\n");
597- return PTS_INTERNAL_ERROR; // -1;
634+ LOG(LOG_ERR, "eventWrapper is NULL");
635+ return PTS_FATAL;
598636 }
599-
600637 event = eventWrapper->event;
601638 if (event == NULL) {
602- LOG(LOG_ERR, "event is NULL\n");
603- return PTS_INTERNAL_ERROR; // -1;
639+ LOG(LOG_ERR, "event is NULL");
640+ return PTS_FATAL;
641+ }
642+ if (event->rgbPcrValue == NULL) {
643+ LOG(LOG_ERR, "null input");
644+ return PTS_FATAL;
604645 }
605646
606647 /* init SHA1 */
@@ -636,6 +677,24 @@ int validateOldImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve
636677 int updateImaProperty(OPENPTS_CONTEXT *ctx, char* name, char* b64digest, char *integrity) {
637678 char prop_name[256];
638679
680+ /* check */
681+ if (ctx == NULL) {
682+ LOG(LOG_ERR, "null input");
683+ return PTS_FATAL;
684+ }
685+ if (name == NULL) {
686+ LOG(LOG_ERR, "null input");
687+ return PTS_FATAL;
688+ }
689+ if (b64digest == NULL) {
690+ LOG(LOG_ERR, "null input");
691+ return PTS_FATAL;
692+ }
693+ if (integrity == NULL) {
694+ LOG(LOG_ERR, "null input");
695+ return PTS_FATAL;
696+ }
697+
639698 /* integrity */
640699 snprintf(prop_name, sizeof(prop_name), "ima.%d.integrty", ctx->ima_count);
641700 setProperty(ctx, prop_name, integrity);
@@ -674,6 +733,11 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
674733
675734 DEBUG_CAL("validateImaMeasurement - start\n");
676735
736+ /* check */
737+ if (ctx == NULL) {
738+ LOG(LOG_ERR, "null input");
739+ return PTS_FATAL;
740+ }
677741 if (eventWrapper == NULL) {
678742 /* Just ignore the NULL event */
679743 // TODO(munetoh) Detect LOOP
@@ -688,6 +752,12 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even
688752
689753 #ifdef CONFIG_AIDE
690754 event = eventWrapper->event;
755+ /* check */
756+ if (event == NULL) {
757+ LOG(LOG_ERR, "null input");
758+ return PTS_FATAL;
759+ }
760+
691761 if (ctx->conf->ima_validation_mode == OPENPTS_VALIDATION_MODE_AIDE) {
692762 int rc = 0;
693763 char *name;
@@ -801,6 +871,12 @@ int validateImaMeasurementNG(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
801871 *
802872 */
803873 int resetCounter(OPENPTS_CONTEXT *ctx) {
874+ /* check */
875+ if (ctx == NULL) {
876+ LOG(LOG_ERR, "null input");
877+ return PTS_FATAL;
878+ }
879+
804880 ctx->count = 0;
805881
806882 // DEBUG("[FSM] resetCounter()");
@@ -811,6 +887,12 @@ int resetCounter(OPENPTS_CONTEXT *ctx) {
811887 *
812888 */
813889 int incrementCounter(OPENPTS_CONTEXT *ctx) {
890+ /* check */
891+ if (ctx == NULL) {
892+ LOG(LOG_ERR, "null input");
893+ return PTS_FATAL;
894+ }
895+
814896 ctx->count += 1;
815897
816898 // DEBUG("[FSM] incrementCounter() %d => %d\n", ctx->count -1, ctx->count);
@@ -899,12 +981,21 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
899981
900982 DEBUG_FSM("addIntelTxtTbootProperty - start\n");
901983
984+ /* check */
985+ if (ctx == NULL) {
986+ LOG(LOG_ERR, "null input");
987+ return PTS_FATAL;
988+ }
902989 /* event */
903990 if (eventWrapper == NULL) {
904991 LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n");
905992 return -1;
906993 }
907994 event = eventWrapper->event;
995+ if (event == NULL) {
996+ LOG(LOG_ERR, "null input");
997+ return PTS_FATAL;
998+ }
908999
9091000 switch (event->eventType) {
9101001 case EV_TBOOT_SINIT_V6:
@@ -1029,7 +1120,6 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
10291120 // TODO
10301121 ctx->drtm = 1;
10311122
1032- // setProperty(ctx, "kernel.commandline", "TBD");
10331123 return PTS_SUCCESS;
10341124 }
10351125 #endif
@@ -1042,10 +1132,19 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev
10421132 int saveCounter(OPENPTS_CONTEXT *ctx, char * name) {
10431133 char buf[128]; // TODO
10441134
1135+ /* check */
1136+ if (ctx == NULL) {
1137+ LOG(LOG_ERR, "null input");
1138+ return PTS_FATAL;
1139+ }
1140+ if (name == NULL) {
1141+ LOG(LOG_ERR, "null input");
1142+ return PTS_FATAL;
1143+ }
1144+
10451145 snprintf(buf, sizeof(buf), "%d", ctx->count);
10461146 addProperty(ctx, name, buf);
10471147
1048- // DEBUG("[FSM] saveCounter() %s = %s\n", name, buf);
10491148
10501149 return PTS_SUCCESS;
10511150 }
@@ -1247,7 +1346,7 @@ int doActivity(
12471346 if (eventWrapper == NULL) {
12481347 /* NULL event, skip evaluation */
12491348 DEBUG_FSM("doActivity - eventWrapper is NULL, skip evaluation\n");
1250- // return 1; //OPENPTS_FSM_SUCCESS;
1349+ // check again by each func
12511350 }
12521351
12531352 /* copy */
--- a/src/aide.c
+++ b/src/aide.c
@@ -26,7 +26,7 @@
2626 * \brief AIDE I/F APIs
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-06-13
29- * cleanup 2011-07-06 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * 1) Integrity check with AIDE
3232 *
@@ -98,7 +98,11 @@ AIDE_METADATA * newAideMetadata() {
9898 * TODO(munetoh) sep. all and single
9999 */
100100 void freeAideMetadata(AIDE_METADATA *md) {
101- if (md == NULL) return;
101+ /* check */
102+ if (md == NULL) {
103+ LOG(LOG_ERR, "null input");
104+ return;
105+ }
102106
103107 if (md->next != NULL) {
104108 freeAideMetadata(md->next);
@@ -124,6 +128,16 @@ void freeAideMetadata(AIDE_METADATA *md) {
124128 int addAideMetadata(AIDE_CONTEXT *ctx, AIDE_METADATA *md) {
125129 int rc = 0;
126130
131+ /* check */
132+ if (ctx == NULL) {
133+ LOG(LOG_ERR, "null input");
134+ return PTS_FATAL;
135+ }
136+ if (md == NULL) {
137+ LOG(LOG_ERR, "null input");
138+ return PTS_FATAL;
139+ }
140+
127141 /* update ctx*/
128142 if (ctx->start == NULL) {
129143 /* first metadata */
@@ -158,10 +172,9 @@ AIDE_CONTEXT * newAideContext() {
158172 int rc;
159173 AIDE_CONTEXT *ctx;
160174
161- // DEBUG("newAideContext()\n");
162-
163175 ctx = xmalloc(sizeof(AIDE_CONTEXT));
164176 if (ctx == NULL) {
177+ LOG(LOG_ERR, "no memory");
165178 return NULL;
166179 }
167180 memset(ctx, 0, sizeof(AIDE_CONTEXT));
@@ -179,7 +192,10 @@ AIDE_CONTEXT * newAideContext() {
179192 ctx->aide_md_table_size = 0;
180193
181194 ctx->aide_in_table = xmalloc(sizeof(struct hsearch_data));
182- // TODO ck null
195+ if (ctx->aide_in_table == NULL) {
196+ LOG(LOG_ERR, "no memory");
197+ goto error;
198+ }
183199 memset(ctx->aide_in_table, 0, sizeof(struct hsearch_data));
184200 // 4096 full
185201 rc = hcreate_r(AIDE_HASH_TABLE_SIZE, ctx->aide_in_table); // hash table for ignore name
@@ -201,7 +217,9 @@ AIDE_CONTEXT * newAideContext() {
201217 *
202218 */
203219 void freeAideIgnoreList(AIDE_LIST *list) {
220+ /* check */
204221 if (list == NULL) {
222+ LOG(LOG_ERR, "null input");
205223 return;
206224 }
207225
@@ -325,6 +343,9 @@ int getAideItemIndex(char *buf) {
325343 * load AIDE database from file
326344 *
327345 * filename base64(digest)
346+ * Return
347+ * num of meatdata
348+ * -1 ERROR
328349 *
329350 * caller
330351 * ir.c
@@ -347,8 +368,17 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
347368 int rc;
348369 char *sha1_b64_ptr;
349370
371+ DEBUG_CAL("loadAideDatabaseFile - start, filename=[%s]\n", filename);
350372
351- DEBUG("loadAideDatabaseFile - start, filename=[%s]\n", filename);
373+ /* check */
374+ if (ctx == NULL) {
375+ LOG(LOG_ERR, "null input");
376+ return -1;
377+ }
378+ if (filename == NULL) {
379+ LOG(LOG_ERR, "null input");
380+ return -1;
381+ }
352382
353383 fp = gzopen(filename, "r");
354384 if (fp == NULL) {
@@ -567,7 +597,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) {
567597 close:
568598 gzclose(fp);
569599 DEBUG("loadAideDatabaseFile - has %d entries\n", ctx->metadata_num);
570- DEBUG("loadAideDatabaseFile - done\n");
600+ DEBUG_CAL("loadAideDatabaseFile - done\n");
571601
572602 return ctx->metadata_num;
573603 }
@@ -592,16 +622,25 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) {
592622 ENTRY e; // htable
593623 ENTRY *ep;
594624
595- DEBUG("readAideIgnoreNameFile - start, filename=[%s]\n", filename);
625+ DEBUG_CAL("readAideIgnoreNameFile - start, filename=[%s]\n", filename);
626+
627+ /* check */
628+ if (ctx == NULL) {
629+ LOG(LOG_ERR, "null input");
630+ return PTS_FATAL;
631+ }
632+ if (filename == NULL) {
633+ LOG(LOG_ERR, "null input");
634+ return PTS_FATAL;
635+ }
596636
597637 /* Open file for read */
598638 fp = fopen(filename, "r");
599639 if (fp == NULL) {
600640 DEBUG("%s missing\n", filename);
601- return -1;
641+ return PTS_FATAL;
602642 }
603643
604-
605644 /* parse */
606645 while (fgets(line, BUF_SIZE, fp) != NULL) { // read line
607646 /* ignore comment, null line */
@@ -658,7 +697,7 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) {
658697 error:
659698 fclose(fp);
660699
661- DEBUG("readAideIgnoreNameFile - done, num = %d\n", cnt);
700+ DEBUG_CAL("readAideIgnoreNameFile - done, num = %d\n", cnt);
662701
663702 return rc;
664703 }
@@ -671,9 +710,15 @@ int printAideData(AIDE_CONTEXT *ctx) {
671710 AIDE_METADATA *md;
672711 int i;
673712
674- DEBUG("printAideData - start\n");
713+ DEBUG_CAL("printAideData - start\n");
675714 DEBUG("printAideData - num = %d\n", ctx->metadata_num);
676715
716+ /* check*/
717+ if (ctx == NULL) {
718+ LOG(LOG_ERR, "null input");
719+ return PTS_FATAL;
720+ }
721+
677722 md = ctx->start;
678723
679724 for (i = 0; i < ctx->metadata_num; i++) {
@@ -695,9 +740,9 @@ int printAideData(AIDE_CONTEXT *ctx) {
695740 md = md->next;
696741 }
697742
698- DEBUG("printAideData - end\n");
743+ DEBUG_CAL("printAideData - end\n");
699744
700- return 0;
745+ return PTS_SUCCESS;
701746 }
702747
703748 #if 1
@@ -722,6 +767,7 @@ void copyAideMetadata(AIDE_METADATA *dst, AIDE_METADATA *src) {
722767 }
723768 }
724769
770+#if 0
725771 /**
726772 * check AIDE MD vs given MD (SHA1)
727773 *
@@ -759,20 +805,24 @@ int checkFileByAide(AIDE_CONTEXT *ctx, AIDE_METADATA *metadata) {
759805 DEBUG_FSM("checkFileByAide - MISS\n");
760806 return -2;
761807 }
762-
808+#endif
763809
764810 /**
765811 *
766812 * return
767813 * -1: MISS
768814 * 0: HIT
769- *
815+ * -2: ERROR
770816 */
771817 int checkIgnoreList(AIDE_CONTEXT *ctx, char *name) {
772818 AIDE_LIST *list;
773819 int len;
774820
775821 /* check */
822+ if (ctx == NULL) {
823+ LOG(LOG_ERR, "null input");
824+ return -2;
825+ }
776826 if (name == NULL) {
777827 LOG(LOG_ERR, "checkIgnoreList() - name is null\n");
778828 return -2;
@@ -993,11 +1043,13 @@ AIDE_METADATA *getMetadataFromAideByName(AIDE_CONTEXT *ctx, char *name) {
9931043 AIDE_METADATA *md;
9941044 int i;
9951045
1046+ /* check */
9961047 if (ctx == NULL) {
1048+ LOG(LOG_ERR, "null input");
9971049 return NULL;
9981050 }
999-
10001051 if (name == NULL) {
1052+ LOG(LOG_ERR, "null input");
10011053 return NULL;
10021054 }
10031055
@@ -1043,11 +1095,17 @@ int escapeFilename(char **out, char *in) {
10431095 int len;
10441096 int i, j;
10451097
1098+ /* check */
1099+ if (in == NULL) {
1100+ LOG(LOG_ERR, "null input");
1101+ return -1;
1102+ }
10461103 len = strlen(in);
10471104
10481105 /* rough malloc new buffer */
10491106 buf = xmalloc(len*3);
10501107 if (buf == NULL) {
1108+ LOG(LOG_ERR, "no memory");
10511109 return -1;
10521110 }
10531111
@@ -1130,7 +1188,17 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) {
11301188 char *aide_filename = NULL;
11311189 int len;
11321190
1133- DEBUG("convertImlToAideDbFile %s\n", filename);
1191+ DEBUG_CAL("convertImlToAideDbFile %s\n", filename);
1192+
1193+ /* check */
1194+ if (ctx == NULL) {
1195+ LOG(LOG_ERR, "null input");
1196+ return -1;
1197+ }
1198+ if (filename == NULL) {
1199+ LOG(LOG_ERR, "null input");
1200+ return -1;
1201+ }
11341202
11351203 /* file open for write */
11361204 fp = gzopen(filename, "wb");
@@ -1257,7 +1325,13 @@ int writeReducedAidbDatabase(AIDE_CONTEXT *ctx, char *filename) {
12571325
12581326 DEBUG("writeReducedAidbDatabase %s\n", filename);
12591327
1328+ /* check */
12601329 if (ctx == NULL) {
1330+ LOG(LOG_ERR, "null input");
1331+ return -1;
1332+ }
1333+ if (filename == NULL) {
1334+ LOG(LOG_ERR, "null input");
12611335 return -1;
12621336 }
12631337
@@ -1455,21 +1529,16 @@ int verifyBySQLite(AIDE_CONTEXT *ctx, char * key) {
14551529
14561530 sql = sqlite3_mprintf("SELECT * from sample where digest = '%s'", key);
14571531 sqlite3_get_table(ctx->sqlite_db, sql, &result, &row, &col, &err);
1458- // DEBUG("%2d %d %s\n",row,col, md->hash_key);
14591532
14601533 if (row >= 1) {
14611534 return OPENPTS_RESULT_VALID;
14621535 }
14631536
1464- // LOG(LOG_ERR, "row = %d\n",row);
1465-
14661537 /* free */
14671538 sqlite3_free(sql);
14681539 sqlite3_free(err);
14691540 sqlite3_free_table(result);
14701541
1471-
1472-
14731542 return OPENPTS_RESULT_UNKNOWN;
14741543 }
14751544 #endif // CONFIG_SQLITE
--- a/src/aru.c
+++ b/src/aru.c
@@ -26,7 +26,7 @@
2626 * \brief FSM action for Auto RM Update (ARU)
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2011-01-11
29- * cleanup 2011-01-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * 2011-02-28 SM
3232 * ARU information is stored in conf instead of ctx since this is part of
@@ -190,7 +190,7 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
190190 int update_type;
191191 int data_length;
192192
193- DEBUG("startUpdate() - start\n");
193+ DEBUG_CAL("startUpdate() - start\n");
194194
195195 /* check input */
196196 if (ctx == NULL) {
@@ -237,9 +237,6 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
237237 update = (OPENPTS_UPDATE_CONTEXT *) conf->update;
238238 start = (OPENPTS_EVENT_UPDATE_START *) event->rgbEvent;
239239
240- // DEBUG("StartUpdate\n");
241- // printHex("UpdateEvent ", (BYTE*) start, sizeof(OPENPTS_EVENT_UPDATE_START), "\n");
242-
243240 // Convert the Endian
244241 if (ctx->conf->iml_endian != 0) {
245242 target_pcr_index = b2l(start->target_pcr_index);
@@ -276,20 +273,17 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
276273 update->target_pcr_index = target_pcr_index;
277274 update->target_snapshot_level = target_snapshot_level;
278275
279-
280276 /* setup OPENPTS_UPDATE_SNAPSHOT */
281277 if (update->snapshot
282278 [target_pcr_index]
283279 [target_snapshot_level] == NULL) {
284280 /* 1st update of this PCR/Level */
285- // OPENPTS_UPDATE_SNAPSHOT
286281 /* malloc OPENPTS_UPDATE_SNAPSHOT */
287- // uss = xmalloc(sizeof(OPENPTS_UPDATE_SNAPSHOT));
288282 uss = newUpdateSnapshot();
289283 if (uss == NULL) {
290- return PTS_INTERNAL_ERROR;
284+ LOG(LOG_ERR, "newUpdateSnapshot() fail");
285+ return PTS_FATAL;
291286 }
292- // memset(uss, 0, sizeof(OPENPTS_UPDATE_SNAPSHOT));
293287 } else {
294288 /* already exist => replace */
295289 /* free Old SS */
@@ -310,7 +304,7 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
310304 [target_snapshot_level] = uss;
311305
312306 conf->update_exist = 1;
313- DEBUG("startUpdate() - update exit\n");
307+ DEBUG_CAL("startUpdate() - update exit\n");
314308
315309 return PTS_SUCCESS;
316310 }
@@ -319,9 +313,9 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
319313 * doAction - deputyEvent
320314 */
321315 int deputyEvent(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
316+ int rc = PTS_SUCCESS;
322317 TSS_PCR_EVENT *event;
323318 OPENPTS_UPDATE_CONTEXT *update;
324- int rc = PTS_SUCCESS;
325319 OPENPTS_CONFIG *conf;
326320 OPENPTS_UPDATE_SNAPSHOT *uss;
327321
@@ -394,7 +388,7 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
394388 OPENPTS_EVENT_UPDATE_START *start;
395389 int event_num;
396390
397- DEBUG("endUpdate() - start\n");
391+ DEBUG_CAL("endUpdate() - start\n");
398392
399393 /* check input */
400394 if (ctx == NULL) {
@@ -474,7 +468,6 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
474468 * doAction - updateCollector
475469 */
476470 int updateCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
477- // int rc = PTS_SUCCESS;
478471 TSS_PCR_EVENT *event;
479472 OPENPTS_EVENT_COLLECTOR_UPDATE *update = NULL;
480473 OPENPTS_CONFIG *conf;
@@ -696,7 +689,6 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
696689
697690 /* Move to next level (0->1) */
698691 incActiveSnapshotLevel(ctx->ss_table, target_pcr_index);
699- // goto end;
700692 break;
701693 } else if (rc == OPENPTS_FSM_FINISH_WO_HIT) {
702694 // TRANSIT, Skip update SS chain
@@ -705,7 +697,6 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
705697
706698 /* Move to next level (0->1) */
707699 incActiveSnapshotLevel(ctx->ss_table, target_pcr_index);
708- // goto end;
709700 break;
710701 } else {
711702 LOG(LOG_ERR, "updateFsm rc=%d\n", rc);
@@ -723,12 +714,10 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in
723714 }
724715
725716 ss->event_num++;
726- // update->event_count++;
727717 rc = OPENPTS_FSM_MIGRATE_EVENT;
728718
729719 eventWrapper = eventWrapper->next_pcr;
730720 count++;
731- // TODO count
732721 }
733722 // TODO check count
734723 // TODO cut EW <-> event link
@@ -775,7 +764,16 @@ int extendEvCollectorUpdate(OPENPTS_CONFIG *conf) {
775764
776765 /* malloc eventlog */
777766 collector_update = xmalloc_assert(sizeof(OPENPTS_EVENT_COLLECTOR_UPDATE));
767+ if (collector_update == NULL) {
768+ LOG(LOG_ERR, "no memory\n");
769+ return PTS_FATAL;
770+ }
778771 event = xmalloc_assert(sizeof(TSS_PCR_EVENT));
772+ if (event == NULL) {
773+ LOG(LOG_ERR, "no memory\n");
774+ xfree(collector_update);
775+ return PTS_FATAL;
776+ }
779777
780778 /* fill collector_start */
781779 memcpy(&collector_update->pts_version, &conf->pts_version, 4);
@@ -1182,7 +1180,7 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) {
11821180 if ( -1 == bytesRead ) {
11831181 LOG(LOG_ERR, "Failed to read from fd %d, errno %d\n", fd, errno);
11841182 break;
1185- } else if ( bytesRead == 0) {
1183+ } else if (bytesRead == 0) {
11861184 if (totalBytesRead != len) {
11871185 LOG(LOG_ERR, "Finished reading from file prematurely, still expecting data.");
11881186 return PTS_FATAL;
@@ -1206,7 +1204,7 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) {
12061204 }
12071205 }
12081206
1209- if ( fd != -1) {
1207+ if (fd != -1) {
12101208 close(fd);
12111209 }
12121210
@@ -1582,7 +1580,6 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) {
15821580 if (target_conf_filename != NULL) xfree(target_conf_filename);
15831581 if (target_conf != NULL) freePtsConfig(target_conf);
15841582
1585- // DEBUG("error at verifier\n");
15861583 return rc;
15871584 }
15881585
--- a/src/base64.c
+++ b/src/base64.c
@@ -26,7 +26,7 @@
2626 * \brief Base64 Encode/Decode
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-12-31 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * http://en.wikipedia.org/wiki/Base64
3232 *
@@ -101,7 +101,6 @@ int _sizeofBase64Decode(int len) {
101101 return (len / 4 * 3) + 1;
102102 }
103103
104-
105104 /**
106105 * Encode BYTE[] to Base64 string
107106 * Return
@@ -141,7 +140,6 @@ int _encodeBase64(char *out, unsigned char * in, int len) {
141140 }
142141
143142 /* Trans */
144-
145143 while (1) {
146144 if ( len >= 3 ) {
147145 out[ptr2 ] = transTable[ in[ptr1 ] >>2];
@@ -216,7 +214,6 @@ char *encodeBase64(unsigned char * in, int inlen, int *outlen) {
216214 return out;
217215 }
218216
219-
220217 /**
221218 * trans (do not check the bad input)
222219 */
@@ -247,7 +244,7 @@ int _strippedlength(char * in, int len) {
247244 /* last char */
248245 i = len - 1;
249246
250- while(i > 0) {
247+ while (i > 0) {
251248 if (in[i] == '\n') {
252249 /* skip */
253250 skip++;
@@ -340,7 +337,7 @@ int _decodeBase64(unsigned char *out, char * in, int len) {
340337 (_b64trans(inbuf[2]) >> 2);
341338 out[ptr2+2] = ((_b64trans(inbuf[2])&0x03) << 6) |
342339 _b64trans(inbuf[3]);
343- len2 -= 4; // skip chars has been removed in len2
340+ len2 -= 4; // skip chars has been removed in len2
344341 ptr1 += 4 + skip;
345342 ptr2 += 3;
346343 } else if ( inbuf[1] == '=' ) {
--- a/src/collector.c
+++ b/src/collector.c
@@ -26,13 +26,12 @@
2626 * \brief TCG IF-M collector functions
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2011-01-06
29- * cleanup 2011-07-20 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * move from ptscd.c
3232 *
3333 */
3434
35-
3635 #include <stdio.h>
3736 #include <stdlib.h>
3837 #include <string.h>
@@ -62,6 +61,12 @@ void printFsmInfo(OPENPTS_CONTEXT *ctx, char * indent) {
6261 int i;
6362 OPENPTS_SNAPSHOT *ss;
6463
64+ /* check */
65+ if (ctx == NULL) {
66+ LOG(LOG_ERR, "null input");
67+ return;
68+ }
69+
6570 OUTPUT(NLS(MS_OPENPTS, OPENPTS_FSM_INFO_HEADER, "%sPCR lv FSM files\n"), indent);
6671 OUTPUT("%s-----------------------------------------------------\n", indent);
6772
@@ -100,23 +105,34 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) {
100105 BYTE pcr[SHA1_DIGEST_SIZE];
101106 SHA_CTX sha_ctx;
102107
108+ /* check */
109+ if (conf == NULL) {
110+ LOG(LOG_ERR, "null input");
111+ return PTS_FATAL;
112+ }
103113
104114 /* malloc eventlog */
105115 collector_start = xmalloc_assert(sizeof(OPENPTS_EVENT_COLLECTOR_START));
116+ if (collector_start == NULL) {
117+ LOG(LOG_ERR, "no memory");
118+ return PTS_FATAL;
119+ }
106120 event = xmalloc_assert(sizeof(TSS_PCR_EVENT));
121+ if (event == NULL) {
122+ LOG(LOG_ERR, "no memory");
123+ xfree(collector_start);
124+ return PTS_FATAL;
125+ }
107126
108127 /*fill collector_start */
109128 memcpy(&collector_start->pts_version, &conf->pts_version, 4);
110129 memcpy(&collector_start->collector_uuid, conf->uuid->uuid, 16);
111130 memcpy(&collector_start->manifest_uuid, conf->rm_uuid->uuid, 16);
112131
113-
114132 /* get PCR value*/
115- // memcpy(&collector_start->pcr_value;
116133 readPcr(conf->openpts_pcr_index, pcr);
117134 memcpy(&collector_start->pcr_value, pcr, SHA1_DIGEST_SIZE);
118135
119-
120136 /* calc digest */
121137 SHA1_Init(&sha_ctx);
122138 SHA1_Update(
@@ -126,7 +142,6 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) {
126142 SHA1_Final(pcr, &sha_ctx);
127143
128144 /* fill eventlog */
129- // event->versionInfo // set by TSP?
130145 event->ulPcrIndex = conf->openpts_pcr_index; // set by TSP?
131146 event->eventType = EV_COLLECTOR_START; // openpts_tpm.h
132147 event->ulPcrValueLength = SHA1_DIGEST_SIZE;
@@ -144,8 +159,6 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) {
144159 return PTS_SUCCESS;
145160 }
146161
147-
148-
149162 /**
150163 * initialize ptsc
151164 *
@@ -159,9 +172,9 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) {
159172 *
160173 * Return
161174 * PTS_SUCCESS
162- * PTS_INTERNAL_ERROR
175+ * OPENPTS_IML_MISSING
176+ * PTS_FATAL
163177 */
164-
165178 int init(
166179 OPENPTS_CONFIG *conf,
167180 int prop_count,
@@ -310,7 +323,7 @@ int init(
310323 addReason(ctx, -1,
311324 "[PTSC-INIT] Couldn't read IML file, %s. Check the ptsc configuration, %s.",
312325 conf->runtime_iml_filename, conf->config_file);
313- rc = PTS_INTERNAL_ERROR;
326+ rc = PTS_FATAL;
314327 goto error;
315328 }
316329 }
@@ -328,7 +341,7 @@ int init(
328341 NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MISSING_CONFIG_DIR,
329342 "[PTSC-INIT] Configuration directory is not defined. Check the ptsc configuration file, %s"),
330343 conf->config_file);
331- rc = PTS_INTERNAL_ERROR;
344+ rc = PTS_FATAL;
332345 goto error;
333346 } else {
334347 /* check */
@@ -371,20 +384,21 @@ int init(
371384
372385 /* Generate UUID of this platform */
373386 if (conf->uuid == NULL) {
374- // TODO UUID filename is missing
387+ LOG(LOG_ERR, "conf->uuid == NULL");
375388 addReason(ctx, -1,
376389 NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE,
377- "[PTSC-INIT] Bad configuration file, %s"),
390+ "[PTSC-INIT] Bad configuration file, %s. Check 'uuid.file' option"),
378391 conf->config_file);
379- rc = PTS_INTERNAL_ERROR;
392+ rc = PTS_FATAL;
380393 goto error;
381394 } else if (conf->uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
382395 /* gen new UUID */
383396 rc = genOpenptsUuid(conf->uuid);
384397 if (rc != PTS_SUCCESS) {
398+ LOG(LOG_ERR, "genOpenptsUuid() fail");
385399 addReason(ctx, -1,
386400 "[PTSC-INIT] Generation of UUID was failed");
387- rc = PTS_INTERNAL_ERROR;
401+ rc = PTS_FATAL;
388402 goto error;
389403 }
390404 } else {
@@ -406,18 +420,19 @@ int init(
406420 0,
407421 conf->srk_password_mode);
408422 if (rc == 0x0001) { // 0x0001
423+ DEBUG("createTssSignKey() failed");
409424 addReason(ctx, -1,
410425 NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SIGN_KEY_FAIL,
411426 "[PTSC-INIT] Failed to create the signed key. "
412427 "If you are using the well known SRK secret key (all zeroes) "
413428 "then please try again with the '-z' option\n"));
414- rc = PTS_INTERNAL_ERROR;
429+ rc = PTS_FATAL;
415430 goto error;
416431 } else if (rc != PTS_SUCCESS) {
417- DEBUG("createTssSignKey() failed\n");
432+ DEBUG("createTssSignKey() failed");
418433 addReason(ctx, -1,
419434 "[PTSC-INIT] Could not create the Key (rc = 0x%x).", rc);
420- rc = PTS_INTERNAL_ERROR;
435+ rc = PTS_FATAL;
421436 goto error;
422437 }
423438 OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_PTSCD, "Sign key location: SYSTEM\n"));
@@ -431,18 +446,18 @@ int init(
431446 /* UUID for RM */
432447 if (conf->rm_uuid == NULL) {
433448 // init/set by readPtsConf
434- // LOG(LOG_ERR, "conf->rm_uuid == NULL\n");
449+ LOG(LOG_ERR, "conf->rm_uuid == NULL\n");
435450 addReason(ctx, -1,
436451 "[PTSC-INIT] RM_UUID file is not defined (rm.uuid.file) in the ptsc configulation, %s",
437452 conf->config_file);
438- rc = PTS_INTERNAL_ERROR;
453+ rc = PTS_FATAL;
439454 goto error;
440455 } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
441456 rc = genOpenptsUuid(conf->rm_uuid);
442457 if (rc != PTS_SUCCESS) {
443458 addReason(ctx, -1,
444459 "[PTSC-INIT] Generation of RM UUID was failed");
445- rc = PTS_INTERNAL_ERROR;
460+ rc = PTS_FATAL;
446461 goto error;
447462 }
448463
@@ -455,7 +470,7 @@ int init(
455470 if (rc != PTS_SUCCESS) {
456471 addReason(ctx, -1,
457472 "[PTSC-INIT] Couldn't create Reference Maniferst directory");
458- rc = PTS_INTERNAL_ERROR;
473+ rc = PTS_FATAL;
459474 goto error;
460475 }
461476
@@ -477,7 +492,6 @@ int init(
477492 addReason(ctx, -1,
478493 "[PTSC-INIT] Couldn't create the manifest file, %s",
479494 conf->rm_filename[i]);
480- //printReason(ctx, 0);
481495 rc = PTS_FATAL;
482496 goto error;
483497 }
@@ -501,7 +515,7 @@ int init(
501515 addReason(ctx, -1,
502516 "[PTSC-INIT] Couldn't write the uuid file, '%s'.\n",
503517 conf->uuid->filename);
504- rc = PTS_INTERNAL_ERROR;
518+ rc = PTS_FATAL;
505519 goto error;
506520 }
507521
@@ -511,21 +525,21 @@ int init(
511525 addReason(ctx, -1,
512526 "[PTSC-INIT] Couldn't write the UUID file, %s",
513527 conf->rm_uuid->filename);
514- rc = PTS_INTERNAL_ERROR;
528+ rc = PTS_FATAL;
515529 goto error;
516530 }
517531
532+ LOG(LOG_INFO, "ptsc has successfully initialized!\n");
518533 OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_SUCCESS,
519534 "\nptsc has successfully initialized!\n\n"));
520- LOG(LOG_INFO, "ptsc has successfully initialized!\n");
521535 goto free;
522536
523537 error:
524538 /* initialization was faild */
525- OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_FAIL,
539+ LOG(LOG_INFO, "ptsc initialization was failed\n");
540+ ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_FAIL,
526541 "ptsc initialization was failed\n\n"));
527542 printReason(ctx, 0);
528- LOG(LOG_INFO, "ptsc initialization was failed\n");
529543
530544 free:
531545 /* free */
@@ -534,8 +548,6 @@ int init(
534548 return rc;
535549 }
536550
537-
538-
539551 /**
540552 *
541553 * Selftest
@@ -557,7 +569,7 @@ int init(
557569 * OPENPTS_SELFTEST_RENEWED update/reboot -> success
558570 * OPENPTS_SELFTEST_FALLBACK
559571 * OPENPTS_SELFTEST_FAILED
560- * PTS_INTERNAL_ERROR something wrong:-(
572+ * PTS_FATAL something wrong:-(
561573 */
562574 int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) {
563575 int rc = PTS_INTERNAL_ERROR;
@@ -567,22 +579,24 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
567579 OPENPTS_PROPERTY *prop;
568580 char * ir_filename;
569581
570- DEBUG("selftest() start\n");
582+ DEBUG_CAL("selftest() start\n");
571583
572- /* Step 1 - IR gen */
584+ /* Step 1 - Generate IR --------------------------------------------------*/
573585
574- /* new */
586+ /* new CTX for generation */
575587 ctx = newPtsContext(conf);
576588 if (ctx == NULL) {
577- return PTS_INTERNAL_ERROR;
589+ LOG(LOG_ERR, "newPtsContext() fail. no memory?");
590+ return PTS_FATAL;
578591 }
579592
580593 /* copy properties */
581594 prop = prop_start;
582595 for (i = 0; i < prop_count; i++) {
583596 if (prop == NULL) {
584- LOG(LOG_ERR, "prop == NULL\n");
585- return PTS_INTERNAL_ERROR; // TODO free
597+ LOG(LOG_ERR, "prop == NULL");
598+ rc = PTS_FATAL;
599+ goto free;
586600 }
587601 addProperty(ctx, prop->name, prop->value);
588602 prop = prop->next;
@@ -594,15 +608,25 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
594608 /* set dummy nonce for IR gen */
595609 ctx->nonce->nonce_length = 20;
596610 ctx->nonce->nonce = xmalloc_assert(20);
611+ if (ctx->nonce->nonce == NULL) {
612+ LOG(LOG_ERR, "no memory");
613+ rc = PTS_FATAL;
614+ goto free;
615+ }
597616 memset(ctx->nonce->nonce, 0x5A, 20);
598- // dummy target uuid
617+ /* set dummy target uuid */
599618 ctx->str_uuid = smalloc("SELFTEST");
619+ if (ctx->str_uuid == NULL) {
620+ LOG(LOG_ERR, "no memory");
621+ rc = PTS_FATAL;
622+ goto free;
623+ }
600624
601625 /* gen IR */
602626 rc = genIr(ctx, NULL);
603627 if (rc != PTS_SUCCESS) {
604628 LOG(LOG_ERR, "selftest() - genIR failed\n");
605- rc = PTS_INTERNAL_ERROR;
629+ rc = PTS_FATAL;
606630 goto free;
607631 }
608632
@@ -610,25 +634,27 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
610634 ir_filename = ctx->ir_filename;
611635 ctx->ir_filename = NULL;
612636
613- /* free */
637+ /* free CTX */
614638 freePtsContext(ctx);
639+ ctx = NULL;
615640
616- // DEBUG("selftest() - generate IR file => %s\n", conf->ir_filename);
617- DEBUG("selftest() - generate IR - done\n");
641+ DEBUG("selftest() - generate IR - done (ir file = %s)\n", ir_filename);
618642
619- /* Step 2 - Validate IR */
643+ /* Step 2 - Validate IR --------------------------------------------------*/
620644
621645 /* Keep conf but reset some flags in conf */
622- // conf->aru_count = 0;
623- // conf->enable_aru;
624646 #ifdef CONFIG_AUTO_RM_UPDATE
647+ /* clear ARU */
625648 conf->update_exist = 0;
626649 #endif
627- /* new */
650+ /* new CTX for validation */
628651 ctx = newPtsContext(conf);
629652 if (ctx == NULL) {
630- return PTS_INTERNAL_ERROR;
653+ LOG(LOG_ERR, "newPtsContext() fail. no memory?");
654+ return PTS_FATAL;
631655 }
656+
657+ /* set generated IR */
632658 ctx->ir_filename = ir_filename;
633659
634660 /* setup RMs */
@@ -637,7 +663,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
637663 LOG(LOG_ERR, "selftest() - getRmSetDir() failed\n");
638664 LOG(LOG_TODO, "conf->rm_uuid->filename %s\n", conf->rm_uuid->filename);
639665 LOG(LOG_TODO, "conf->rm_uuid->str %s\n", conf->rm_uuid->str);
640- rc = PTS_INTERNAL_ERROR;
666+ rc = PTS_FATAL;
641667 goto free;
642668 }
643669
@@ -646,7 +672,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
646672 rc = readRmFile(ctx, conf->rm_filename[i], i);
647673 if (rc < 0) {
648674 LOG(LOG_ERR, "readRmFile fail\n");
649- rc = PTS_INTERNAL_ERROR;
675+ rc = PTS_FATAL;
650676 goto free;
651677 }
652678 }
@@ -665,21 +691,19 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
665691 // ctx->conf->iml_mode = 1;
666692 // ctx->conf->ir_without_quote = 1;
667693
668-
669-
670- //result = validateIr(ctx, conf->ir_filename); /* ir.c */
671- // TODO
672694 result = validateIr(ctx); /* ir.c */
673695
674-
675696 /* check RM integrity status */
676697 DEBUG("selftest() - validate IR - done (rc = %d)\n", result);
677- if ((rc != OPENPTS_RESULT_VALID) && isDebugFlagSet(DEBUG_FLAG)) {
698+ if ((result != OPENPTS_RESULT_VALID) && (getVerbosity() > 0)) {
699+ ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_4,
700+ "The self test has failed"));
678701 printReason(ctx, 0);
679702 }
680703
681704 if (result != OPENPTS_RESULT_VALID) {
682- addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED, "[SELFTEST] The self test failed"));
705+ addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED,
706+ "[SELFTEST] The self test failed"));
683707 if ((conf->newrm_uuid != NULL) && (conf->newrm_uuid->uuid != NULL)) {
684708 /* New RM exist (for reboot after the update), Try the new RM */
685709
@@ -705,22 +729,27 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
705729 rc = writeOpenptsUuidFile(conf->rm_uuid, 1);
706730 if (rc != PTS_SUCCESS) {
707731 LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
732+ rc = PTS_FATAL;
733+ goto free;
708734 }
709-
710- // TODO check rc
711735 /* delete newrm_uuid */
712736 rc = remove(conf->newrm_uuid->filename);
713- // TODO check rc
737+ if (rc != 0) {
738+ LOG(LOG_ERR, "remove(%s) fail\n", conf->newrm_uuid->filename);
739+ rc = PTS_FATAL;
740+ goto free;
741+ }
714742 rc = OPENPTS_SELFTEST_RENEWED;
715743 } else {
716744 /* fail */
717- LOG(LOG_ERR, "sleftest fail\n");
745+ LOG(LOG_ERR, "2nd selftest with NEWRM also fail\n");
718746 addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_2,
719747 "[SELFTEST] The self test using both current and new UUIDs has failed"));
720748 printReason(ctx, 0);
721749 rc = OPENPTS_SELFTEST_FAILED;
722750 }
723751 } else {
752+ /* Missing NEWRM */
724753 printReason(ctx, 0);
725754 rc = OPENPTS_SELFTEST_FAILED;
726755 }
@@ -740,11 +769,14 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
740769 /* free */
741770 freePtsContext(ctx);
742771
772+ if (rc == PTS_FATAL) {
773+ ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_3,
774+ "The self test has failed. See log for details."));
775+ }
776+
743777 return rc;
744778 }
745779
746-
747-
748780 /**
749781 * New RM
750782 *
@@ -757,7 +789,6 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start,
757789 * PTS_SUCCESS
758790 * PTS_INTERNAL_ERROR
759791 */
760-
761792 int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) {
762793 int rc = PTS_SUCCESS;
763794 OPENPTS_CONTEXT *ctx;
@@ -767,7 +798,8 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
767798 /* ctx for init */
768799 ctx = newPtsContext(conf);
769800 if (ctx == NULL) {
770- return PTS_INTERNAL_ERROR;
801+ LOG(LOG_ERR, "newPtsContext() fail. no memory?");
802+ return PTS_FATAL;
771803 }
772804
773805 #if 1
@@ -775,8 +807,9 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
775807 prop = prop_start;
776808 for (i = 0; i < prop_count; i++) {
777809 if (prop == NULL) {
778- LOG(LOG_ERR, "prop == NULL\n");
779- return PTS_INTERNAL_ERROR; // TODO free
810+ LOG(LOG_ERR, "prop == NULL");
811+ rc = PTS_FATAL;
812+ goto free;
780813 }
781814 addProperty(ctx, prop->name, prop->value);
782815 prop = prop->next;
@@ -797,7 +830,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
797830 if (rc != PTS_SUCCESS) {
798831 ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_FSM,
799832 "Failed to read the FSM file.\n"));
800- rc = PTS_INTERNAL_ERROR;
833+ rc = PTS_FATAL;
801834 goto free;
802835 }
803836
@@ -806,7 +839,11 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
806839 LOG(LOG_ERR, "conf->rm_uuid == NULL");
807840 } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
808841 rc = genOpenptsUuid(conf->rm_uuid);
809- // TODO
842+ if (rc != PTS_SUCCESS) {
843+ LOG(LOG_ERR, "genOpenptsUuid() fail\n");
844+ rc = PTS_FATAL;
845+ goto free;
846+ }
810847 } else {
811848 DEBUG("init() - use given RM UUID %s\n", conf->rm_uuid->str);
812849 }
@@ -814,7 +851,9 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
814851 /* save/update rm_uuid file */
815852 rc = writeOpenptsUuidFile(conf->rm_uuid, 1); // TODO overwite?
816853 if (rc != PTS_SUCCESS) {
817- LOG(LOG_ERR, "writeOpenptsUuidFile fail\n");
854+ LOG(LOG_ERR, "writeOpenptsUuidFile() fail\n");
855+ rc = PTS_FATAL;
856+ goto free;
818857 }
819858
820859 /* RM set DIR */
@@ -822,6 +861,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
822861 if (rc != PTS_SUCCESS) {
823862 ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED,
824863 "Failed to create the reference manifest set directory\n"));
864+ rc = PTS_FATAL;
825865 goto free;
826866 }
827867
@@ -849,6 +889,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
849889 DEBUG("getBiosImlFile() was failed\n");
850890 LOG(LOG_ERR, "Oops! Something is wrong. Please see the reason below\n");
851891 printReason(ctx, 0);
892+ rc = PTS_FATAL;
852893 goto free;
853894 }
854895
@@ -861,7 +902,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
861902 conf->runtime_iml_type, 0, &count); // TODO endian?
862903 if (rc != PTS_SUCCESS) {
863904 LOG(LOG_ERR, "read IMA IML, %s was failed\n", conf->runtime_iml_filename);
864- rc = PTS_INTERNAL_ERROR;
905+ rc = PTS_FATAL;
865906 goto free;
866907 }
867908 }
@@ -878,29 +919,28 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP
878919 rc = writeRm(ctx, conf->rm_filename[i], i);
879920 if (rc != PTS_SUCCESS) {
880921 LOG(LOG_ERR, "write RM, %s was failed\n", conf->rm_filename[i]);
881- rc = PTS_INTERNAL_ERROR;
922+ rc = PTS_FATAL;
882923 goto free;
883924 }
884925 OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_RM, "level %d Reference Manifest: %s\n"), i, conf->rm_filename[i]);
885926 } else {
886927 LOG(LOG_ERR, "missing RM file for level %d\n", i);
928+ // continue
887929 }
888930 }
889- // OUTPUT("\nptsc is successfully initialized!\n");
890931
891932 free:
892-
893- if ( rc == PTS_INTERNAL_ERROR ) {
894- OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_FAILED, "Failed to generate Reference Manifest\n"));
895- }
896-
897933 /* free */
898934 freePtsContext(ctx);
899935
936+ if ( rc == PTS_FATAL ) {
937+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_FAILED,
938+ "Failed to generate Reference Manifest. See log for details.\n"));
939+ }
940+
900941 return rc;
901942 }
902943
903-
904944 /**
905945 * Print the configuration of PTS collector
906946 *
@@ -973,7 +1013,6 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) {
9731013 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_LIST_RM,
9741014 "List of RM set: %d RM set in config dir\n"), conf->rmsets->rmset_num);
9751015 printRmList(conf, " ");
976- // OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_IR, "Integrity Report: %s\n"), conf->ir_filename);
9771016 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_IR, "Integrity Report dir: %s\n"), conf->ir_dir);
9781017
9791018
@@ -991,7 +1030,6 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) {
9911030
9921031 /* Manifest */
9931032
994-
9951033 /* Servers */
9961034
9971035 free:
@@ -1023,11 +1061,12 @@ int clear(
10231061 return PTS_FATAL;
10241062 }
10251063
1064+ /* msg */
1065+ VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR,
1066+ "Clear PTS collector\n"));
10261067
1027- VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR, "Clear PTS collector\n"));
1028-
1029- /* clear */
1030- if (isatty(STDIN_FILENO) && (force == 0) ) {
1068+ /* Ask */
1069+ if (isatty(STDIN_FILENO) && (force == 0)) {
10311070 char *lineFeed;
10321071 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR,
10331072 "Clear the PTS collector [y/N]:"));
@@ -1049,8 +1088,8 @@ int clear(
10491088 ansIsNo = !force;
10501089 }
10511090
1091+ /* Yes/No */
10521092 if (ansIsYes) {
1053-
10541093 rc = unlinkDir(conf->config_dir);
10551094 if (rc != PTS_SUCCESS) {
10561095 LOG(LOG_ERR, "unlinkDir(%s) fail", conf->config_dir);
@@ -1061,6 +1100,5 @@ int clear(
10611100 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR_NO_DONE, "keep\n"));
10621101 }
10631102
1064-
10651103 return PTS_SUCCESS;
10661104 }
--- a/src/conf.c
+++ b/src/conf.c
@@ -27,61 +27,13 @@
2727 *
2828 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2929 * @date 2010-08-13
30- * cleanup 2011-07-06 SM
31- *
30+ * cleanup 2012-01-04 SM
3231 *
3332 * grep strncmp src/conf.c | gawk '{print $3}'
3433 * grep strncmp src/conf.c | awk '{print " * " $3}' | sed -e "s/\"//g" -e "s/,//g"
3534 *
36- * name default value
37- * ----------------------------------------------------
38- * config.dir
39- * openpts.pcr.index
40- * aide
41- * aide.database.file
42- * aide.ignorelist.file
43- * aide.sqlite.file
44- * autoupdate
45- * bios.iml.file
46- * config.dir
47- * config.dir
48- * hostname
49- * ima.validation.mode
50- * iml.aligned
51- * iml.endian
52- * iml.mode
53- * ir.dir
54- * ir.file
55- * ir.quote
56- * little
57- * model.dir
58- * newrm.uuid.file
59- * oldrm.uuid.file
60- * openpts.pcr.index
61- * pcrs.file
62- * policy.file
63- * port
64- * prop.file
65- * rm.basedir
66- * rm.num
67- * rm.uuid.file
68- * runtime.iml.file
69- * runtime.iml.type
70- * securityfs
71- * selftest
72- * ssh.mode
73- * ssh.port
74- * ssh.username
75- * strncmp
76- * strncmp
77- * target.pubkey
78- * target.uuid
79- * uuid.file
80- * verifier.logging.dir
81- * ------------------------------------------------------------------------
82- * srk.password.mode null/known
83- * ------------------------------------------------------------------------
84- *
35+ * Also update man/man5/ptsc.conf.5
36+ *
8537 */
8638
8739 #include <stdio.h>
@@ -90,7 +42,6 @@
9042 #include <ctype.h>
9143
9244 #include <openpts.h>
93-// #include <log.h>
9445
9546 /**
9647 * new Target list
@@ -109,7 +60,7 @@ OPENPTS_TARGET_LIST *newTargetList(int num) {
10960 }
11061 memset(list, 0, size);
11162
112- list->target_num = num - 1; // set actual number
63+ list->target_num = num - 1; // set actual number
11364
11465 return list;
11566 }
@@ -157,8 +108,6 @@ void freeTargetList(OPENPTS_TARGET_LIST *list) {
157108 OPENPTS_CONFIG * newPtsConfig() {
158109 OPENPTS_CONFIG * conf;
159110
160- // DEBUG("newPtsConfig()\n");
161-
162111 /* config */
163112 conf = (OPENPTS_CONFIG *) xmalloc(sizeof(OPENPTS_CONFIG));
164113 if (conf == NULL) {
@@ -186,7 +135,6 @@ OPENPTS_CONFIG * newPtsConfig() {
186135 */
187136 int freePtsConfig(OPENPTS_CONFIG * conf) {
188137 int i;
189- // DEBUG("freePtsConfig()\n");
190138
191139 /* check */
192140 if (conf == NULL) {
@@ -359,7 +307,6 @@ int freePtsConfig(OPENPTS_CONFIG * conf) {
359307 conf->config_file = NULL;
360308 }
361309
362-//<<<<<<< HEAD
363310 #ifdef CONFIG_AUTO_RM_UPDATE
364311 if (conf->newRmSet != NULL) {
365312 xfree(conf->newRmSet);
@@ -384,14 +331,11 @@ int freePtsConfig(OPENPTS_CONFIG * conf) {
384331 if (conf->compIDs[i].VendorID_Value != NULL) xfree(conf->compIDs[i].VendorID_Value);
385332 }
386333
387-// xfree(conf);
388-//=======
389334 if (conf->aik_storage_filename != NULL) {
390335 free(conf->aik_storage_filename);
391336 }
392337
393338 free(conf);
394-//>>>>>>> 042e40b0979f3e44e75200271e4d1282ce08f72c
395339
396340 return PTS_SUCCESS;
397341 }
@@ -435,7 +379,8 @@ static int readPtsConfig_CompID(
435379 /******************/
436380
437381 if (level >= MAX_RM_NUM) {
438- LOG(LOG_ERR, "readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
382+ LOG(LOG_ERR,
383+ "readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n",
439384 attributeName, level, MAX_RM_NUM);
440385 return PTS_FATAL;
441386 }
@@ -555,12 +500,11 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
555500
556501 /* dir where config file -> config_dir */
557502 if (conf->config_dir != NULL) {
558- // free old one
503+ /* free old one */
559504 xfree(conf->config_dir);
560505 }
561506 conf->config_dir = getFullpathDir(filename2);
562507
563-
564508 /* open */
565509 if ((fp = fopen(filename2, "r")) == NULL) {
566510 DEBUG("readPtsConfig - File %s open was failed\n", filename2);
@@ -587,17 +531,14 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
587531
588532 if (line[0] == '#') {
589533 // comment -> skip
590- } else if ((eq = strstr(line, "=")) != NULL) { /* name=value line*/
534+ } else if ((eq = strstr(line, "=")) != NULL) { /* name=value line */
591535 char *name;
592536 char *value;
593537
594538 name = line;
595539 value = eq + 1;
596-
597540 *eq = 0;
598541
599- // DEBUG("%4d [%s]=[%s]\n",cnt, name, value);
600-
601542 /* config dir
602543 replace the curent setting based on the location of config file
603544 to path set by config file.
@@ -696,7 +637,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
696637 conf->iml_endian = 0;
697638 #else
698639 conf->iml_endian = 2;
699- // DEBUG("convert endian mode\n");
700640 DEBUG("endian mode : convert\n");
701641 #endif
702642 } else {
@@ -744,7 +684,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
744684 // RM config - from 0.2.3
745685 if (!strncmp(name, "rm.basedir", 10)) {
746686 if (conf->rm_basedir != NULL) {
747- // DEBUG("realloc conf->rm_basedir"); // TODO realloc happen
748687 xfree(conf->rm_basedir);
749688 }
750689 conf->rm_basedir = getFullpathName(conf->config_dir, value);
@@ -752,7 +691,9 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
752691 if (!strncmp(name, "rm.num", 6)) {
753692 conf->rm_num = atoi(value);
754693 if (conf->rm_num > MAX_RM_NUM) {
755- LOG(LOG_ERR, "RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n", conf->rm_num, MAX_RM_NUM);
694+ LOG(LOG_ERR,
695+ "RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n",
696+ conf->rm_num, MAX_RM_NUM);
756697 conf->rm_num = MAX_RM_NUM;
757698 }
758699 DEBUG("conf->rm_num : %d\n", conf->rm_num);
@@ -762,35 +703,25 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
762703 /* Depricated - we use a temporary file in /tmp on collector side */
763704 if (!strncmp(name, "ir.file", 7)) {
764705 if (conf->ir_filename != NULL) {
765- // DEBUG("realloc conf->ir_filename"); // TODO realloc happen
766706 xfree(conf->ir_filename);
767707 }
768708 conf->ir_filename = getFullpathName(conf->config_dir, value);
769709 DEBUG("conf->ir_filename : %s\n", conf->ir_filename);
770- // LOG(LOG_ERR, "ir.file is obsolute, please use ir.dir"); /// Collectror TODO
771710 }
772711 /* IR dir (collector side) */
773712 if (!strncmp(name, "ir.dir", 6)) {
774713 if (conf->ir_dir != NULL) {
775- // DEBUG("realloc conf->ir_filename"); // TODO realloc happen
776714 xfree(conf->ir_dir);
777715 }
778716 conf->ir_dir = getFullpathName(conf->config_dir, value);
779717 DEBUG("conf->ir_dir : %s\n", conf->ir_dir);
780- } // BAD else {
781- // /* set this to some sensible default value so that ptsc.c doesn't seg fault */
782- // conf->ir_dir = smalloc("/tmp");
783- //}
784-
718+ }
785719 if (!strncmp(name, "prop.file", 9)) {
786720 if (conf->prop_filename != NULL) {
787- // DEBUG("realloc conf->prop_filename"); // TODO realloc happen
788721 xfree(conf->prop_filename);
789722 }
790723 conf->prop_filename = getFullpathName(conf->config_dir, value);
791724 }
792-
793- // 20100908 Munetoh -> ifm.c
794725 if (!strncmp(name, "ir.quote", 8)) {
795726 if (!strncmp(value, "WITHOUT_QUOTE", 13)) {
796727 conf->ir_without_quote = 1;
@@ -803,6 +734,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
803734 conf->model_dir = getFullpathName(conf->config_dir, value);
804735 }
805736
737+ /* prop (AIX) */
806738 if (!strncmp(name, "iml.ipl.maxcount", 16)) {
807739 conf->iml_maxcount = atoi(value);
808740 DEBUG("conf->iml_maxcount : %d\n", conf->iml_maxcount);
@@ -816,7 +748,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
816748 conf->verifier_logging_dir = getFullpathName(conf->config_dir, value);
817749 }
818750
819-
820751 if (!strncmp(name, "policy.file", 11)) {
821752 if (conf->policy_filename != NULL) {
822753 // DEBUG("realloc conf->policy_filename\n"); // TODO realloc happen
@@ -825,17 +756,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
825756 conf->policy_filename = getFullpathName(conf->config_dir, value);
826757 }
827758
828-#if 0
829- if (!strncmp(name, "config.dir", 10)) {
830- if (conf->config_dir != NULL) {
831- LOG(LOG_TODO, "conf dir %s ->%s\n", conf->config_dir, value);
832- //
833- } else {
834- conf->config_dir = getFullpathName(config_path, value);
835- }
836- }
837-#endif
838-
839759 /* IMA and AIDE */
840760 if (!strncmp(name, "ima.validation.mode", 19)) {
841761 if (!strncmp(value, "aide", 4)) {
@@ -851,7 +771,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
851771 #ifdef CONFIG_AIDE
852772 if (!strncmp(name, "aide.database.file", 18)) {
853773 if (conf->aide_database_filename != NULL) {
854- // DEBUG("realloc conf->aide_database_filename\n"); // TODO realloc happen
855774 xfree(conf->aide_database_filename);
856775 }
857776 conf->aide_database_filename = getFullpathName(conf->config_dir, value);
@@ -863,7 +782,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
863782 #endif
864783 if (!strncmp(name, "aide.ignorelist.file", 20)) {
865784 if (conf->aide_ignorelist_filename != NULL) {
866- // DEBUG("realloc conf->aide_ignorelist_filename\n"); // TODO realloc happen
867785 xfree(conf->aide_ignorelist_filename);
868786 }
869787 conf->aide_ignorelist_filename = getFullpathName(conf->config_dir, value);
@@ -913,7 +831,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
913831 conf->rm_uuid = newOpenptsUuid();
914832 }
915833 if (conf->rm_uuid->filename != NULL) {
916- // DEBUG("realloc conf->rm_uuid->filename"); // TODO realloc happen
917834 xfree(conf->rm_uuid->filename);
918835 }
919836 conf->rm_uuid->filename = getFullpathName(conf->config_dir, value);
@@ -921,11 +838,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
921838 rc = readOpenptsUuidFile(conf->rm_uuid);
922839 if (rc != PTS_SUCCESS) {
923840 /* uuid file is missing */
924- // TODO gen UUID?
925- // DEBUG("no UUID file %s\n", conf->uuid->filename);
926841 conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
927- } else {
928- // DEBUG("read UUID from file %s, UUID=%s\n", conf->uuid->filename, conf->uuid->str);
929842 }
930843 DEBUG("conf->rm_uuid->str : %s\n", conf->rm_uuid->str);
931844 }
@@ -937,7 +850,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
937850 conf->newrm_uuid = newOpenptsUuid();
938851 }
939852 if (conf->newrm_uuid->filename != NULL) {
940- // DEBUG("realloc conf->rm_uuid->filename"); // TODO realloc happen
941853 xfree(conf->newrm_uuid->filename);
942854 }
943855 conf->newrm_uuid->filename = getFullpathName(conf->config_dir, value);
@@ -945,8 +857,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
945857 rc = readOpenptsUuidFile(conf->newrm_uuid);
946858 if (rc != PTS_SUCCESS) {
947859 /* uuid file is missing */
948- // TODO gen UUID?
949- // DEBUG("no UUID file %s\n", conf->uuid->filename);
950860 conf->newrm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
951861 } else {
952862 conf->pts_flag[0] |= OPENPTS_FLAG0_NEWRM_EXIST;
@@ -961,7 +871,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
961871 conf->oldrm_uuid = newOpenptsUuid();
962872 }
963873 if (conf->oldrm_uuid->filename != NULL) {
964- // DEBUG("realloc conf->oldrm_uuid->filename"); // TODO realloc happen
965874 xfree(conf->oldrm_uuid->filename);
966875 }
967876 conf->oldrm_uuid->filename = getFullpathName(conf->config_dir, value);
@@ -969,11 +878,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
969878 rc = readOpenptsUuidFile(conf->oldrm_uuid);
970879 if (rc != PTS_SUCCESS) {
971880 /* uuid file is missing */
972- // TODO gen UUID?
973- // DEBUG("no UUID file %s\n", conf->uuid->filename);
974881 conf->oldrm_uuid->status = OPENPTS_UUID_FILENAME_ONLY;
975- } else {
976- // DEBUG("read UUID from file %s, UUID=%s\n", conf->uuid->filename, conf->uuid->str);
977882 }
978883 DEBUG("conf->oldrm_uuid->str : %s\n", conf->oldrm_uuid->str);
979884 }
@@ -981,7 +886,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
981886 /* */
982887 if (!strncmp(name, "target.uuid", 11)) {
983888 if (conf->target_uuid != NULL) {
984- // DEBUG("realloc conf->target_uuid\n"); // TODO realloc happen
985889 xfree(conf->target_uuid);
986890 }
987891 conf->target_uuid = getUuidFromString(value);
@@ -990,7 +894,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
990894 } else {
991895 // add string too
992896 if (conf->str_target_uuid != NULL) {
993- // DEBUG("realloc conf->str_target_uuid\n"); // TODO realloc happen
994897 xfree(conf->str_target_uuid);
995898 }
996899 conf->str_target_uuid = getStringOfUuid(conf->target_uuid);
@@ -1035,7 +938,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) {
1035938 /* hostname */
1036939 if (!strncmp(name, "hostname", 8)) {
1037940 if (conf->hostname != NULL) {
1038- // DEBUG("realloc conf->hostname\n"); // TODO realloc happen
1039941 xfree(conf->hostname);
1040942 }
1041943 conf->hostname = smalloc_assert(value);
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -26,7 +26,7 @@
2626 * \brief PTS context
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-07-06 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * OpenPTS main context
3232 *
@@ -51,6 +51,7 @@ OPENPTS_CONTEXT * newPtsContext(OPENPTS_CONFIG *conf) {
5151
5252 ctx = (OPENPTS_CONTEXT *) xmalloc(sizeof(OPENPTS_CONTEXT));
5353 if (ctx == NULL) {
54+ LOG(LOG_ERR, "no memory");
5455 return NULL;
5556 }
5657 memset(ctx, 0, sizeof(OPENPTS_CONTEXT));
@@ -64,6 +65,7 @@ OPENPTS_CONTEXT * newPtsContext(OPENPTS_CONFIG *conf) {
6465 /* IF-M nonce */
6566 ctx->nonce = newNonceContext();
6667 if (ctx->nonce == NULL) {
68+ LOG(LOG_ERR, "newNonceContext() fail. no memory");
6769 goto error;
6870 }
6971
@@ -86,9 +88,10 @@ int freePtsContext(OPENPTS_CONTEXT *ctx) {
8688 int i;
8789 DEBUG_CAL("freePtsContext - start\n");
8890
91+ /* check */
8992 if (ctx == NULL) {
90- DEBUG("freePtsContext - NULL\n");
91- return -1;
93+ LOG(LOG_ERR, "null input");
94+ return PTS_FATAL;
9295 }
9396
9497 /* TPM emu - reset */
@@ -229,9 +232,7 @@ char * getAlgString(int type) {
229232 */
230233 int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
231234 int rc = PTS_SUCCESS;
232- OPENPTS_CONFIG *conf;
233235 FILE *fp;
234-
235236 char buf[FSM_BUF_SIZE];
236237 char buf2[FSM_BUF_SIZE];
237238 char *eqp = NULL;
@@ -239,18 +240,30 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
239240 int level;
240241 char *model_filename = NULL;
241242 int len;
242-
243+ OPENPTS_CONFIG *conf;
243244 OPENPTS_FSM_CONTEXT *fsm = NULL;
244245 OPENPTS_SNAPSHOT *ss = NULL;
245246
247+ /* check */
248+ if (ctx == NULL) {
249+ LOG(LOG_ERR, "null input");
250+ return PTS_FATAL;
251+ }
246252 conf = ctx->conf;
253+ if (conf == NULL) {
254+ LOG(LOG_ERR, "null input");
255+ return PTS_FATAL;
256+ }
257+ if (filename == NULL) {
258+ LOG(LOG_ERR, "null input");
259+ return PTS_FATAL;
260+ }
247261
248262 /* new snapshot table */
249263 if (ctx->ss_table == NULL) {
250264 ctx->ss_table = newSnapshotTable();
251265 }
252266
253-
254267 /* Open prop file */
255268 if ((fp = fopen(filename, "r")) == NULL) {
256269 OUTPUT(NLS(MS_OPENPTS, OPENPTS_CONFIG_MISSING, "Cannot open config file '%s'\n"), filename);
@@ -285,7 +298,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
285298 if (strstr(buf, "platform.model.") != NULL) {
286299 LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename);
287300 LOG(LOG_ERR, "change platform.model to rm.model.0\n");
288- OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
301+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file (v0.2.3)\n"));
289302 rc = PTS_FATAL;
290303 goto error;
291304 }
@@ -293,7 +306,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
293306 if (strstr(buf, "runtime.model.") != NULL) {
294307 LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename);
295308 LOG(LOG_ERR, "change runtime.model to rm.model.1\n");
296- OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n"));
309+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file (v0.2.3)\n"));
297310 rc = PTS_FATAL;
298311 goto error;
299312 }
@@ -320,7 +333,6 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) {
320333 "%s/%s",
321334 conf->model_dir, model_filename);
322335 rc = readUmlModel(fsm, buf2);
323- // TODO(munetoh) cehck rc
324336 if (rc != PTS_SUCCESS) {
325337 LOG(LOG_ERR, "addFsmByPropFile - [%s] / [%s] -> [%s] fail rc=%d, pwd = %s\n",
326338 conf->model_dir, model_filename, buf2, rc,
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -26,9 +26,9 @@
2626 * \brief Finite State Machine
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-01-21 SM
30- * refactoring 2011-07-20 SM
31- *
29+ * cleanup 2012-01-05 SM (remains one lint error)
30+ * src/fsm.c:416: Use int16/int64/etc, rather than the C type long [runtime/int] [4]
31+ *
3232 * Input
3333 * FSM Model
3434 * IML
@@ -99,7 +99,6 @@ void freeFsmTransitionChain(OPENPTS_FSM_Transition *fsm_trans) {
9999 * Free OPENPTS_FSM_Subvertex chain
100100 */
101101 void freeFsmSubvertexChain(OPENPTS_FSM_Subvertex *fsm_sub) {
102-
103102 /* check */
104103 if (fsm_sub == NULL) {
105104 LOG(LOG_ERR, "null input");
@@ -119,7 +118,6 @@ void freeFsmSubvertexChain(OPENPTS_FSM_Subvertex *fsm_sub) {
119118 * free FSM context
120119 */
121120 int freeFsmContext(OPENPTS_FSM_CONTEXT *ctx) {
122-
123121 /* check */
124122 if (ctx == NULL) {
125123 LOG(LOG_ERR, "null input");
@@ -161,7 +159,12 @@ void resetFsmSubvertex(OPENPTS_FSM_CONTEXT *ctx) {
161159 return;
162160 }
163161
164- // fsm_sub=NULL;
162+ /* free subvertex chain */
163+ if (ctx->fsm_sub != NULL) {
164+ freeFsmSubvertexChain(ctx->fsm_sub);
165+ ctx->fsm_sub = NULL;
166+ }
167+
165168 ctx->subvertex_num = 0;
166169 }
167170
@@ -175,7 +178,12 @@ void resetFsmTransition(OPENPTS_FSM_CONTEXT *ctx) {
175178 return;
176179 }
177180
178- // fsm_trans=NULL;
181+ /* free transition chain */
182+ if (ctx->fsm_trans != NULL) {
183+ freeFsmTransitionChain(ctx->fsm_trans);
184+ ctx->fsm_trans = NULL;
185+ }
186+
179187 ctx->transition_num = 0;
180188 }
181189
@@ -471,13 +479,11 @@ int getTypeFlag(char * cond, UINT32 *eventtype /* out */) {
471479 if ((loc[0] == '0') && (loc[1] == 'x')) { // 0x HEX
472480 val = strtoll(loc, NULL, 16);
473481 *eventtype = (UINT32)val;
474- // DEBUG("strtol [%s] => %X => %X\n", loc,val,*eventtype);
475482 return rc;
476483 }
477484 }
478485 val = strtoll(loc, NULL, 10);
479486 *eventtype = (UINT32)val;
480- // DEBUG("strtol [%s] => %X => %X\n", loc,val, *eventtype);
481487
482488 return rc;
483489 }
@@ -628,7 +634,7 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
628634
629635 loc = skipWhiteSpace(loc, &len);
630636 if (isEndOfString(loc)) {
631- goto error; //return -1;
637+ goto error;
632638 }
633639
634640 /* operation, "&lt;" ">=" only */
@@ -666,12 +672,12 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
666672 len -=2;
667673 } else {
668674 LOG(LOG_ERR, "unknown operand [%s]", &loc[0]);
669- goto error; //return -1;
675+ goto error;
670676 }
671677
672678 loc = skipWhiteSpace(loc, &len);
673679 if (isEndOfString(loc)) {
674- goto error; //return -1;
680+ goto error;
675681 }
676682
677683 // TODO check the end, this code only support if counter is the last
@@ -680,14 +686,14 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) {
680686 param_len = loc2 - loc;
681687 if (0 == param_len) {
682688 /* we haven't moved along the string - no valid parameter found */
683- goto error; //return -1;
689+ goto error;
684690 }
685691
686692 /* DEBUG_FSM("[%d][%s][%s]\n",len, loc, loc2); */
687693
688694 *flag = xmalloc(param_len + 1);
689695 if (*flag == NULL) {
690- goto error; //return -1;
696+ goto error;
691697 }
692698 memset(*flag, 0, param_len + 1);
693699 memcpy(*flag, loc, param_len);
@@ -788,14 +794,9 @@ int getLastFlag(char * cond) {
788794 }
789795 }
790796
791- // DEBUG("getLastFlag %s #=> %d\n",cond, rc);
792-
793797 return rc;
794798 }
795799
796-
797-
798-
799800 /**
800801 * add FSM transition
801802 *
@@ -1011,9 +1012,6 @@ int updateFsm(
10111012 OPENPTS_PCR_EVENT_WRAPPER *eventWrapper
10121013 ) {
10131014 int rc = OPENPTS_FSM_SUCCESS;
1014- OPENPTS_FSM_Subvertex *curr_state;
1015- OPENPTS_FSM_Transition *trans;
1016- TSS_PCR_EVENT *event;
10171015 int type_check;
10181016 int digest_check;
10191017 int fatal_counter_check;
@@ -1021,7 +1019,10 @@ int updateFsm(
10211019 int dont_care;
10221020 int hit = 0;
10231021 char *hex;
1022+ OPENPTS_FSM_Subvertex *curr_state;
1023+ OPENPTS_FSM_Transition *trans;
10241024 OPENPTS_FSM_Transition *hit_trans = NULL;
1025+ TSS_PCR_EVENT *event;
10251026
10261027 DEBUG_CAL("updateFsm - start\n");
10271028
@@ -1511,12 +1512,10 @@ int updateFsm(
15111512 * called from rm.c
15121513 */
15131514 OPENPTS_FSM_CONTEXT *copyFsm(OPENPTS_FSM_CONTEXT *src_fsm) {
1514- OPENPTS_FSM_CONTEXT * dst_fsm = NULL;
1515-
1515+ OPENPTS_FSM_CONTEXT *dst_fsm = NULL;
15161516 OPENPTS_FSM_Subvertex *src_fsm_sub;
15171517 OPENPTS_FSM_Subvertex *dst_fsm_sub = NULL;
15181518 OPENPTS_FSM_Subvertex *dst_fsm_sub_prev = NULL;
1519-
15201519 OPENPTS_FSM_Transition *src_fsm_trans;
15211520 OPENPTS_FSM_Transition *dst_fsm_trans = NULL;
15221521 OPENPTS_FSM_Transition *dst_fsm_trans_prev = NULL;
@@ -1664,8 +1663,8 @@ int changeTargetSubvertex(
16641663 OPENPTS_FSM_Subvertex *old_sub, // B
16651664 OPENPTS_FSM_Subvertex *new_sub) { // BN
16661665 int rc = 0;
1667- OPENPTS_FSM_Transition *fsm_trans;
16681666 int count = 0;
1667+ OPENPTS_FSM_Transition *fsm_trans;
16691668
16701669 /* check */
16711670 if (fsm_ctx == NULL) {
@@ -1721,8 +1720,8 @@ int changeTransTargetSubvertex(
17211720 OPENPTS_FSM_Subvertex *old_sub, // B
17221721 OPENPTS_FSM_Subvertex *new_sub) { // BN
17231722 int rc = 0;
1724- OPENPTS_FSM_Transition *fsm_trans;
17251723 int count = 0;
1724+ OPENPTS_FSM_Transition *fsm_trans;
17261725
17271726 /* check */
17281727 if (fsm_ctx == NULL) {
@@ -1813,9 +1812,9 @@ int insertFsmNew(
18131812 OPENPTS_FSM_Transition *fsm_trans, // target Trans
18141813 OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) {
18151814 int rc =0;
1816- OPENPTS_FSM_Subvertex *prev_sub; // STRUCT LINK
1817- OPENPTS_FSM_Subvertex *new_sub;
1818- OPENPTS_FSM_Subvertex *dst_sub;
1815+ OPENPTS_FSM_Subvertex *prev_sub; // STRUCT LINK
1816+ OPENPTS_FSM_Subvertex *new_sub;
1817+ OPENPTS_FSM_Subvertex *dst_sub;
18191818 OPENPTS_FSM_Transition *prev_trans; // STRUCT LINK
18201819 OPENPTS_FSM_Transition *new_trans;
18211820 TSS_PCR_EVENT *event;
@@ -1851,7 +1850,6 @@ int insertFsmNew(
18511850 return -1;
18521851 }
18531852
1854-
18551853 /* start */
18561854 if (fsm_trans->source_subvertex == fsm_trans->target_subvertex) {
18571855 /* OK, this is LOOP, */
@@ -1862,7 +1860,6 @@ int insertFsmNew(
18621860 dst_sub = fsm_trans->target_subvertex;
18631861
18641862 /* Add new subvertex, BN (->B) */
1865-
18661863 new_sub = (OPENPTS_FSM_Subvertex *)
18671864 xmalloc(sizeof(OPENPTS_FSM_Subvertex));
18681865 if (new_sub == NULL) {
@@ -2256,6 +2253,7 @@ int writeDotModel(OPENPTS_FSM_CONTEXT *ctx, char * filename) {
22562253 return PTS_FATAL;
22572254 }
22582255
2256+ /* check filename, open */
22592257 if (filename == NULL) {
22602258 fp = stdout;
22612259 } else {
--- a/src/ifm.c
+++ b/src/ifm.c
@@ -26,7 +26,7 @@
2626 * \brief TCG IF-M protocol
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-04-26 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * 2011-06-20 SM - do not use sendfile()
3232 * IF-M did not work with endfile.
@@ -53,7 +53,6 @@
5353 #endif
5454
5555 #include <openpts.h>
56-// #include <log.h>
5756
5857 // TODO
5958 #define MAX_TLV_MESSAGE_LENGTH 5120000
@@ -210,19 +209,12 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) {
210209 goto error;
211210 }
212211
213- // copy buf to PTS_IF_M_Attribute (NBO)
212+ /* copy buf to PTS_IF_M_Attribute (NBO) */
214213 memcpy(read_tlv, head, 12);
215- // Convert NBO to Host byte order
214+ /* Convert NBO to Host byte order */
216215 read_tlv->type = ntohl(read_tlv->type);
217216 read_tlv->length = ntohl(read_tlv->length);
218217
219-#if 0
220- TODO("IF-M type : 0x%02x%02x%02x%02x (NBO)",
221- head[4], head[5], head[6], head[7]);
222- TODO("IF-M length: 0x%02x%02x%02x%02x (NBO) %d",
223- head[8], head[9], head[10], head[11], read_tlv->length);
224-#endif
225-
226218 /* check the length */
227219 if (read_tlv->length > MAX_TLV_MESSAGE_LENGTH) {
228220 LOG(LOG_ERR, "read_tlv->length = %d (0x%X)> %d\n",
@@ -267,7 +259,6 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) {
267259 return read_tlv;
268260
269261 error:
270- // if (read_msg != NULL) free(read_msg);
271262 if (read_tlv != NULL) {
272263 freePtsTlv(read_tlv);
273264 }
@@ -293,10 +284,7 @@ void freePtsTlv(PTS_IF_M_Attribute *tlv) {
293284 }
294285
295286
296-
297-
298-
299-/* TNC, libtnc */
287+/* TNC, libtnc ---------------------------------------------------------------*/
300288
301289 /**
302290 * malloc TLV buffer and fill the header
@@ -425,8 +413,6 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) {
425413 break;
426414 }
427415
428-
429-
430416 /* Collector --> Verifier */
431417 case TPM_PUBKEY:
432418 {
@@ -939,6 +925,3 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fdout, int type) {
939925
940926 return -1;
941927 }
942-
943-
944-
--- a/src/imc.c
+++ b/src/imc.c
@@ -26,7 +26,7 @@
2626 * \brief TCG TNC IF-IMC v1.2 R8
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-05-07
29- * cleanup 2011-12-31 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * http://www.trustedcomputinggroup.org/resources/tnc_ifimc_specification
3232 * http://www.trustedcomputinggroup.org/files/resource_files/8CB977E1-1D09-3519-AD48484530EF6639/TNC_IFIMC_v1_2_r8.pdf
@@ -72,11 +72,6 @@ static TNC_TNCC_SendMessagePointer sendMessagePtr;
7272 static OPENPTS_CONFIG *conf = NULL;
7373 static OPENPTS_CONTEXT *ctx = NULL;
7474
75-// int verbose = 0;
76-// int verbose = DEBUG_IFM_FLAG;
77-// int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG;
78-
79-
8075 static TNC_Result sendMessage(
8176 /*in*/ TNC_IMCID imcID,
8277 /*in*/ TNC_ConnectionID connectionID,
--- a/src/iml.c
+++ b/src/iml.c
@@ -26,7 +26,7 @@
2626 * \brief Load TCG Integrity Measurement Log (IML)
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-07-06 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * get IML/PCRS from filesystem
3232 * get IML/PCRS vis TSS
@@ -47,8 +47,8 @@ void printEventWrapper(OPENPTS_PCR_EVENT_WRAPPER *eventWrapper);
4747 *
4848 * TODO use ctx,
4949 * TODO reset level1 too
50+ * TODO move to snapshot?
5051 */
51-// TODO move to snapshot?
5252 int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) {
5353 int i, j;
5454 OPENPTS_SNAPSHOT *ss;
@@ -81,14 +81,12 @@ int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) {
8181 xfree(eventWrapper);
8282 eventWrapper = eventWrapper_next;
8383 }
84- // if (iml[i].eventList != NULL) xfree(iml[i].eventList);
8584 ss->pcrIndex = i;
8685 ss->event_num = 0;
8786 ss->level = 0;
8887 }
8988
90-
91- return 0; // TODO(munetoh)
89+ return PTS_SUCCESS;
9290 }
9391
9492
@@ -234,11 +232,15 @@ int addEventToSnapshotBhv(
234232 ss = getSnapshotFromTable(ctx->ss_table, index, 1);
235233 if (ss == NULL) {
236234 LOG(LOG_ERR, "getSnapshotFromTable(%d,1) is null", index);
235+ // ctx->conf->config_file != NULL
236+ LOG(LOG_ERR, "index %d\n", index);
237+ LOG(LOG_ERR, "ctx->conf->config_file %s\n", ctx->conf->config_file);
237238 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING,
238239 "[PCR%02d] Snapshot(FSM) is missing for PCR%d. "
239240 "Please check the configuration file '%s'"),
240241 index,
241- index, ctx->conf->config_file);
242+ index,
243+ ctx->conf->config_file);
242244 ctx->ss_table->error[index] = PTS_INTERNAL_ERROR;
243245 return PTS_INTERNAL_ERROR;
244246 }
@@ -253,6 +255,8 @@ int addEventToSnapshotBhv(
253255 } else {
254256 /* FSM is missing */
255257 LOG(LOG_ERR, "getSnapshotFromTable(), FSM is null");
258+ LOG(LOG_ERR, "index %d\n", index);
259+ LOG(LOG_ERR, "ctx->conf->config_file %s\n", ctx->conf->config_file);
256260 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_FSM_MISSING,
257261 "[RM01-PCR%02d] FSM is missing for PCR%d, Level 1. "
258262 "Please check the configuration file '%s'"),
@@ -433,7 +437,6 @@ int addEventToSnapshotBhv(
433437 * PTS_INVALID_SNAPSHOT bad event (FSM fail)
434438 * PTS_INTERNAL_ERROR else
435439 *
436- *
437440 */
438441 int addEventToSnapshotBin(
439442 OPENPTS_CONTEXT * ctx,
@@ -474,7 +477,7 @@ int addEventToSnapshotBin(
474477
475478 /* check next level (1) */
476479 if (ss == NULL) {
477- LOG(LOG_ERR, "addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n",index, active_level);
480+ LOG(LOG_ERR, "addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n", index, active_level);
478481 addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_3, "[PCR%02d] Snapshot(FSM) is missing"),
479482 index);
480483 ctx->ss_table->error[index] = PTS_INTERNAL_ERROR;
@@ -617,7 +620,6 @@ int flashSnapshot(
617620 OPENPTS_SNAPSHOT *ss;
618621 OPENPTS_SNAPSHOT *ss_lv0 = NULL;
619622
620-
621623 DEBUG_CAL("flashSnapshot - start\n");
622624
623625 /* check */
@@ -996,21 +998,18 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) {
996998 int rc = PTS_SUCCESS;
997999 int result;
9981000 int i = 0;
1001+ int endian = 0;
1002+ int aligned = 0;
1003+ int error = 0;
9991004 size_t size;
10001005 FILE *fp = NULL;
10011006 UINT32 pcrIndex;
10021007 UINT32 eventType;
10031008 UINT32 eventLength;
1004- int endian = 0;
1005- int aligned = 0;
1006-
10071009 TSS_PCR_EVENT *event = NULL;
10081010 OPENPTS_PCR_EVENT_WRAPPER *ew_new = NULL;
1009- // OPENPTS_PCR_EVENT_WRAPPER *ew_last = NULL;
1010- int error = 0;
10111011
10121012 DEBUG_CAL("getBiosImlFile - start\n");
1013- // DEBUG("read BIOS IML, file %s\n", filename);
10141013
10151014 /* check */
10161015 if (ctx == NULL) {
--- a/src/iml2aide.c
+++ b/src/iml2aide.c
@@ -26,7 +26,7 @@
2626 * \brief convert IML to AIDE DB
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-08-24
29- * cleanup 2011-07-06 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * create AIDE DB from IML (via securityfs)
3232 *
--- a/src/iml2text.c
+++ b/src/iml2text.c
@@ -24,7 +24,7 @@
2424 * \brief Convert binary IML file to plaintext
2525 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2626 * @date 2010-08-25
27- * cleanup 2011-08-17 SM
27+ * cleanup 2012-01-05 SM
2828 *
2929 * show eventlog (get though TSS)
3030 *
@@ -90,7 +90,6 @@
9090 #include <openssl/sha.h>
9191
9292 #include <openpts.h>
93-// #include <log.h>
9493
9594 #ifdef CONFIG_TBOOT
9695 #include <openpts_tboot.h>
@@ -99,15 +98,9 @@
9998 // Local TCSD
10099 #define SERVER NULL
101100
102-
103101 // PCR
104102 BYTE pcr[24][20];
105103
106-// Verbose Counter
107-// 0 no
108-// -v 1 show event data contents
109-// -v -v 2 DEBUG
110-
111104 char *indent = " ";
112105
113106 // Check the consistence of IML and PCRs
@@ -1047,7 +1040,7 @@ void usage(void) {
10471040 " -V Verify\n"
10481041 " -D DRTM\n"
10491042 " -E Enable endian conversion (BE->LE or LE->BE)\n"
1050- " -P Show pcrs calculated from the IML"
1043+ " -P Show pcrs calculated from the IML"
10511044 " -h Show this help message\n"
10521045 "\n"));
10531046 }
@@ -1296,7 +1289,7 @@ int main(int argc, char *argv[]) {
12961289 }
12971290 }
12981291 /* pcrs */
1299- // PCR-00: 8F BF F3 EC EA 9C 54 C8 D1 C4 2C FE A9 3D 6B F0 1B F3 40 5B
1292+ // PCR-00: 8F BF F3 EC EA 9C 54 C8 D1 C4 2C FE A9 3D 6B F0 1B F3 40 5B
13001293 if (pcrs == 1) {
13011294 for (i = 0; i < 24; i++) {
13021295 fprintf(fp, "PCR-%02d: ", i);
--- a/src/imv.c
+++ b/src/imv.c
@@ -26,7 +26,7 @@
2626 * \brief TCG TNC IF-IMV v1.2 R8
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-05-07
29- * cleanup 2011-08-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * http://www.trustedcomputinggroup.org/resources/tnc_ifimv_specification
3232 * http://www.trustedcomputinggroup.org/files/static_page_files/646808C3-1D09-3519-AD2E60765779A42A/TNC_IFIMV_v1_2_r8.pdf
@@ -51,7 +51,6 @@
5151
5252 #include <tncifimv.h>
5353 #include <openpts.h>
54-// #include <log.h>
5554
5655 // ifm.c
5756 BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len);
@@ -64,10 +63,6 @@ static OPENPTS_CONFIG *conf = NULL;
6463 static OPENPTS_CONTEXT *ctx = NULL;
6564 static int result = OPENPTS_RESULT_UNKNOWN;
6665
67-// int verbose = 0;
68-// int verbose = DEBUG_IFM_FLAG;
69-// int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG;
70-
7166 static TNC_Result sendMessage(
7267 /*in*/ TNC_IMVID imvID,
7368 /*in*/ TNC_ConnectionID connectionID,
@@ -97,16 +92,6 @@ static TNC_TNCS_SetAttributePointer setAttributePtr;
9792 static TNC_TNCS_SendMessagePointer sendMessagePtr;
9893
9994
100-/* List of receive message types */
101-// static TNC_MessageType messageTypes[] = {
102-// TNCMESSAGENUM(TNC_VENDORID_TCG, TNC_SUBTYPE_ANY), // generic
103-// TNCMESSAGENUM(VENDORID, 0),
104-// TNCMESSAGENUM(VENDORID, 2),
105-// TNCMESSAGENUM(VENDORID, 4),
106-// TNCMESSAGENUM(VENDORID, 6),
107-// TNCMESSAGENUM(VENDORID, 8),
108-// TNCMESSAGENUM(VENDORID, 10),
109-// };
11095 static TNC_MessageType messageTypes[] = {
11196 ((TNC_VENDORID_PA_TNC << 8) | TNC_VENDORID_PA_TNC), // TNC generic (Error)
11297 // ((TNC_VENDORID_TCG_PEN << 8) | TNC_SUBTYPE_TCG_PTS), // PTS generic
@@ -114,7 +99,7 @@ static TNC_MessageType messageTypes[] = {
11499 };
115100
116101
117-/* IMV Functions */
102+/* IMV Functions -------------------------------------------------------------*/
118103
119104 /**
120105 * from IMV spec.
--- a/src/ir.c
+++ b/src/ir.c
@@ -26,7 +26,7 @@
2626 * \brief Generate Integrity Report from IML
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-07-06 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * TSS Event Struct -> IR
3232 * IML and PCR may not match, since the read them is not an atmic operation
@@ -44,7 +44,7 @@
4444 *
4545 * TOCTOU?
4646 *
47- *
47+ * TODO refine XML error log
4848 */
4949
5050 #include <sys/stat.h>
@@ -59,8 +59,8 @@
5959 #include <libxml/parser.h>
6060
6161 #include <openpts.h>
62-// #include <log.h>
6362
63+/* XML */
6464 enum {
6565 TEXT_WRITER_START_ELEMENT,
6666 TEXT_WRITER_WRITE_ATTR,
@@ -87,7 +87,7 @@ void displayXmlError(int errorIndex, int rc) {
8787
8888 /* check */
8989 if (errorIndex >= XML_FUNC_END) {
90- LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)",errorIndex, XML_FUNC_END);
90+ LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)", errorIndex, XML_FUNC_END);
9191 return;
9292 }
9393
@@ -114,7 +114,7 @@ int freeAllFsm(OPENPTS_CONTEXT *ctx) {
114114 }
115115
116116 if (ctx->ss_table == NULL) {
117- // DEBUG("resetFsm() - no SS table\n");
117+ /* no SS table, skip */
118118 return PTS_SUCCESS;
119119 }
120120
@@ -286,7 +286,7 @@ int writeComponentID(
286286 rc = xmlTextWriterWriteAttribute(
287287 writer,
288288 BAD_CAST "VersionBuild",
289- BAD_CAST "1250694000000"); // TODO(munetoh)
289+ BAD_CAST "1250694000000"); // TODO(munetoh)
290290 if (rc < 0) {
291291 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
292292 goto error;
@@ -596,7 +596,6 @@ int writeStuffObjects(
596596 * @retval PTS_INTERNAL_ERROR
597597 *
598598 */
599-
600599 int writePcrHash(
601600 xmlTextWriterPtr writer,
602601 int pcrIndex,
@@ -604,7 +603,6 @@ int writePcrHash(
604603 BYTE * startHash,
605604 BYTE * hash,
606605 int algtype) {
607- // int rc = PTS_SUCCESS;
608606 char id[256]; // TODO(munetoh) 11+1+1 = 12?
609607 int rc;
610608
@@ -953,6 +951,7 @@ int writeQuote(
953951 /* Start an element named "QuoteData" as child of Report. */
954952 rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteData");
955953 if (rc < 0) {
954+ LOG(LOG_ERR, "xmlX() fail");
956955 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
957956 return PTS_INTERNAL_ERROR;
958957 }
@@ -960,6 +959,7 @@ int writeQuote(
960959 /* Add an attribute with name "ID" */
961960 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST "TBD");
962961 if (rc < 0) {
962+ LOG(LOG_ERR, "xmlX() fail");
963963 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
964964 return PTS_INTERNAL_ERROR;
965965 }
@@ -967,6 +967,7 @@ int writeQuote(
967967 /* Start an element named "Quote" as child of QuoteData. */
968968 rc = xmlTextWriterStartElement(writer, BAD_CAST "Quote");
969969 if (rc < 0) {
970+ LOG(LOG_ERR, "xmlX() fail");
970971 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
971972 return PTS_INTERNAL_ERROR;
972973 }
@@ -974,6 +975,7 @@ int writeQuote(
974975 /* Start an element named "PcrComposit" as child of Quote. */
975976 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
976977 if (rc < 0) {
978+ LOG(LOG_ERR, "xmlX() fail");
977979 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
978980 return PTS_INTERNAL_ERROR;
979981 }
@@ -1006,6 +1008,7 @@ int writeQuote(
10061008 /* Start an element named "PcrSelection" as child of PcrComposit. */
10071009 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
10081010 if (rc < 0) {
1011+ LOG(LOG_ERR, "xmlX() fail");
10091012 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
10101013 return PTS_INTERNAL_ERROR;
10111014 }
@@ -1014,6 +1017,7 @@ int writeQuote(
10141017 snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
10151018 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
10161019 if (rc < 0) {
1020+ LOG(LOG_ERR, "xmlX() fail");
10171021 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
10181022 return PTS_INTERNAL_ERROR;
10191023 }
@@ -1029,7 +1033,7 @@ int writeQuote(
10291033 }
10301034 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
10311035 if (rc < 0) {
1032- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1036+ LOG(LOG_ERR, "xmlX() fail");
10331037 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
10341038 return PTS_INTERNAL_ERROR;
10351039 }
@@ -1039,7 +1043,7 @@ int writeQuote(
10391043 /* Close the element named "PcrSelection". */
10401044 rc = xmlTextWriterEndElement(writer);
10411045 if (rc < 0) {
1042- // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
1046+ LOG(LOG_ERR, "xmlX() fail");
10431047 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
10441048 return PTS_INTERNAL_ERROR;
10451049 }
@@ -1049,6 +1053,7 @@ int writeQuote(
10491053 /* Write an element named "ValueSize" as child of PcrComposit */
10501054 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
10511055 if (rc < 0) {
1056+ LOG(LOG_ERR, "xmlX() fail");
10521057 displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
10531058 return PTS_INTERNAL_ERROR;
10541059 }
@@ -1060,6 +1065,7 @@ int writeQuote(
10601065 /* Start an element named "PcrValue" as child of PcrComposit. */
10611066 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
10621067 if (rc < 0) {
1068+ LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
10631069 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
10641070 return PTS_INTERNAL_ERROR;
10651071 }
@@ -1068,6 +1074,7 @@ int writeQuote(
10681074 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
10691075 // rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST "0");
10701076 if (rc < 0) {
1077+ LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
10711078 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
10721079 return PTS_INTERNAL_ERROR;
10731080 }
@@ -1079,6 +1086,7 @@ int writeQuote(
10791086 0,
10801087 20); // TODO add length to OPENPTS_PCRS
10811088 if (rc < 0) {
1089+ LOG(LOG_ERR, "xmlTextWriterWriteBase64() fail");
10821090 displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
10831091 return PTS_INTERNAL_ERROR;
10841092 }
@@ -1086,6 +1094,7 @@ int writeQuote(
10861094 /* Close the element named "PcrValue" */
10871095 rc = xmlTextWriterEndElement(writer);
10881096 if (rc < 0) {
1097+ LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
10891098 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
10901099 return PTS_INTERNAL_ERROR;
10911100 }
@@ -1095,6 +1104,7 @@ int writeQuote(
10951104 /* Close the element named "PcrComposit". */
10961105 rc = xmlTextWriterEndElement(writer);
10971106 if (rc < 0) {
1107+ LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
10981108 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
10991109 return PTS_INTERNAL_ERROR;
11001110 }
@@ -1103,6 +1113,7 @@ int writeQuote(
11031113 /* Start an element named "QuoteInfo" as child of Quote. */
11041114 rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteInfo");
11051115 if (rc < 0) {
1116+ LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
11061117 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
11071118 return PTS_INTERNAL_ERROR;
11081119 }
@@ -1111,7 +1122,7 @@ int writeQuote(
11111122 snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMajor);
11121123 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMajor", BAD_CAST tagbuf);
11131124 if (rc < 0) {
1114- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1125+ LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
11151126 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11161127 return PTS_INTERNAL_ERROR;
11171128 }
@@ -1119,7 +1130,7 @@ int writeQuote(
11191130 snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMinor);
11201131 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMinor", BAD_CAST tagbuf);
11211132 if (rc < 0) {
1122- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1133+ LOG(LOG_ERR, "xmlX() fail");
11231134 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11241135 return PTS_INTERNAL_ERROR;
11251136 }
@@ -1127,7 +1138,7 @@ int writeQuote(
11271138 snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMajor);
11281139 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMajor", BAD_CAST tagbuf);
11291140 if (rc < 0) {
1130- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1141+ LOG(LOG_ERR, "xmlX() fail");
11311142 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11321143 return PTS_INTERNAL_ERROR;
11331144 }
@@ -1136,7 +1147,7 @@ int writeQuote(
11361147 snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMinor);
11371148 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMinor", BAD_CAST tagbuf);
11381149 if (rc < 0) {
1139- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1150+ LOG(LOG_ERR, "xmlX() fail");
11401151 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11411152 return PTS_INTERNAL_ERROR;
11421153 }
@@ -1144,7 +1155,7 @@ int writeQuote(
11441155 /* Add an attribute with name "Fixed", int */
11451156 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST "QUOT");
11461157 if (rc < 0) {
1147- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1158+ LOG(LOG_ERR, "xmlX() fail");
11481159 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11491160 return -1;
11501161 }
@@ -1160,6 +1171,7 @@ int writeQuote(
11601171 }
11611172 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DigestValue", BAD_CAST b64buf);
11621173 if (rc < 0) {
1174+ LOG(LOG_ERR, "xmlX() fail");
11631175 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11641176 return PTS_INTERNAL_ERROR;
11651177 }
@@ -1179,7 +1191,7 @@ int writeQuote(
11791191 }
11801192 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
11811193 if (rc < 0) {
1182- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1194+ LOG(LOG_ERR, "xmlX() fail");
11831195 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
11841196 return PTS_INTERNAL_ERROR;
11851197 }
@@ -1189,7 +1201,7 @@ int writeQuote(
11891201 /* Close the element named "QuoteInfo". */
11901202 rc = xmlTextWriterEndElement(writer);
11911203 if (rc < 0) {
1192- // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
1204+ LOG(LOG_ERR, "xmlX() fail");
11931205 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
11941206 return PTS_INTERNAL_ERROR;
11951207 }
@@ -1197,7 +1209,7 @@ int writeQuote(
11971209 /* Close the element named "Quote". */
11981210 rc = xmlTextWriterEndElement(writer);
11991211 if (rc < 0) {
1200- // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n");
1212+ LOG(LOG_ERR, "xmlX() fail");
12011213 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
12021214 return PTS_INTERNAL_ERROR;
12031215 }
@@ -1207,6 +1219,7 @@ int writeQuote(
12071219 /* Start an element named "TpmSignature" as child of QuoteData. */
12081220 rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
12091221 if (rc < 0) {
1222+ LOG(LOG_ERR, "xmlX() fail");
12101223 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
12111224 return PTS_INTERNAL_ERROR;
12121225 }
@@ -1216,6 +1229,7 @@ int writeQuote(
12161229 /* Start an element named "SignatureMethod" as child of TpmSignature. */
12171230 rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
12181231 if (rc < 0) {
1232+ LOG(LOG_ERR, "xmlX() fail");
12191233 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
12201234 return PTS_INTERNAL_ERROR;
12211235 }
@@ -1224,6 +1238,7 @@ int writeQuote(
12241238 BAD_CAST "Algorithm",
12251239 BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO
12261240 if (rc < 0) {
1241+ LOG(LOG_ERR, "xmlX() fail");
12271242 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
12281243 return PTS_INTERNAL_ERROR;
12291244 }
@@ -1381,6 +1396,7 @@ int writeQuote2(
13811396 snprintf(tagbuf, sizeof(tagbuf), "%d", tag);
13821397 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Tag", BAD_CAST tagbuf);
13831398 if (rc < 0) {
1399+ LOG(LOG_ERR, "xmlX() fail");
13841400 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
13851401 return PTS_INTERNAL_ERROR;
13861402 }
@@ -1388,6 +1404,7 @@ int writeQuote2(
13881404 DEBUG("fixed : %s", fixed);
13891405 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST fixed);
13901406 if (rc < 0) {
1407+ LOG(LOG_ERR, "xmlX() fail");
13911408 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
13921409 return PTS_INTERNAL_ERROR;
13931410 }
@@ -1403,7 +1420,7 @@ int writeQuote2(
14031420 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
14041421 free(b64buf);
14051422 if (rc < 0) {
1406- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1423+ LOG(LOG_ERR, "xmlX() fail");
14071424 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
14081425 return PTS_INTERNAL_ERROR;
14091426 }
@@ -1411,7 +1428,7 @@ int writeQuote2(
14111428 /* PcrInfoShort - start */
14121429 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrInfoShort");
14131430 if (rc < 0) {
1414- // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
1431+ LOG(LOG_ERR, "xmlX() fail");
14151432 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
14161433 return PTS_INTERNAL_ERROR;
14171434 }
@@ -1419,7 +1436,7 @@ int writeQuote2(
14191436 /* PcrSelection - start */
14201437 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
14211438 if (rc < 0) {
1422- // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
1439+ LOG(LOG_ERR, "xmlX() fail");
14231440 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
14241441 return PTS_INTERNAL_ERROR;
14251442 }
@@ -1427,7 +1444,7 @@ int writeQuote2(
14271444 snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
14281445 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
14291446 if (rc < 0) {
1430- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1447+ LOG(LOG_ERR, "xmlX() fail");
14311448 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
14321449 return PTS_INTERNAL_ERROR;
14331450 }
@@ -1443,12 +1460,14 @@ int writeQuote2(
14431460 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
14441461 free(b64buf);
14451462 if (rc < 0) {
1463+ LOG(LOG_ERR, "xmlX() fail");
14461464 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
14471465 return PTS_INTERNAL_ERROR;
14481466 }
14491467 /* PcrSelection - end */
14501468 rc = xmlTextWriterEndElement(writer);
14511469 if (rc < 0) {
1470+ LOG(LOG_ERR, "xmlX() fail");
14521471 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
14531472 return PTS_INTERNAL_ERROR;
14541473 }
@@ -1457,6 +1476,7 @@ int writeQuote2(
14571476 /* LocalityAtRelease - element */
14581477 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LocalityAtRelease", "%d", locality);
14591478 if (rc < 0) {
1479+ LOG(LOG_ERR, "xmlX() fail");
14601480 displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
14611481 return PTS_INTERNAL_ERROR;
14621482 }
@@ -1473,6 +1493,7 @@ int writeQuote2(
14731493 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CompositeHash", "%s", b64buf);
14741494 free(b64buf);
14751495 if (rc < 0) {
1496+ LOG(LOG_ERR, "xmlX() fail");
14761497 displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
14771498 return PTS_INTERNAL_ERROR;
14781499 }
@@ -1481,7 +1502,7 @@ int writeQuote2(
14811502 /* PcrComposite - start */
14821503 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
14831504 if (rc < 0) {
1484- // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
1505+ LOG(LOG_ERR, "xmlX() fail");
14851506 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
14861507 return PTS_INTERNAL_ERROR;
14871508 }
@@ -1489,7 +1510,7 @@ int writeQuote2(
14891510 /* PcrSelection - start */
14901511 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
14911512 if (rc < 0) {
1492- // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
1513+ LOG(LOG_ERR, "xmlX() fail");
14931514 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
14941515 return PTS_INTERNAL_ERROR;
14951516 }
@@ -1497,7 +1518,7 @@ int writeQuote2(
14971518 snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
14981519 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
14991520 if (rc < 0) {
1500- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1521+ LOG(LOG_ERR, "xmlX() fail");
15011522 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
15021523 return PTS_INTERNAL_ERROR;
15031524 }
@@ -1513,19 +1534,22 @@ int writeQuote2(
15131534 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
15141535 free(b64buf);
15151536 if (rc < 0) {
1537+ LOG(LOG_ERR, "xmlX() fail");
15161538 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
15171539 return PTS_INTERNAL_ERROR;
15181540 }
15191541 /* PcrSelection - end */
15201542 rc = xmlTextWriterEndElement(writer);
15211543 if (rc < 0) {
1544+ LOG(LOG_ERR, "xmlX() fail");
15221545 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15231546 return PTS_INTERNAL_ERROR;
15241547 }
15251548 /* ValueSize - element */
15261549 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
15271550 if (rc < 0) {
1528- displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
1551+ LOG(LOG_ERR, "xmlX() fail");
1552+ displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
15291553 return PTS_INTERNAL_ERROR;
15301554 }
15311555 /* PcrValue, loop */
@@ -1534,7 +1558,7 @@ int writeQuote2(
15341558 /* PcrValue - start */
15351559 rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
15361560 if (rc < 0) {
1537- // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n");
1561+ LOG(LOG_ERR, "xmlX() fail");
15381562 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
15391563 return PTS_INTERNAL_ERROR;
15401564 }
@@ -1542,7 +1566,7 @@ int writeQuote2(
15421566 snprintf(tagbuf, sizeof(tagbuf), "%d", i);
15431567 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
15441568 if (rc < 0) {
1545- // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n");
1569+ LOG(LOG_ERR, "xmlX() fail");
15461570 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
15471571 return PTS_INTERNAL_ERROR;
15481572 }
@@ -1555,6 +1579,7 @@ int writeQuote2(
15551579 0,
15561580 20); // TODO add length to OPENPTS_PCRS
15571581 if (rc < 0) {
1582+ LOG(LOG_ERR, "xmlX() fail");
15581583 displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
15591584 return PTS_INTERNAL_ERROR;
15601585 }
@@ -1562,6 +1587,7 @@ int writeQuote2(
15621587 /* PcrValue - end */
15631588 rc = xmlTextWriterEndElement(writer);
15641589 if (rc < 0) {
1590+ LOG(LOG_ERR, "xmlX() fail");
15651591 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15661592 return PTS_INTERNAL_ERROR;
15671593 }
@@ -1570,6 +1596,7 @@ int writeQuote2(
15701596 /* PcrComposite - end */
15711597 rc = xmlTextWriterEndElement(writer);
15721598 if (rc < 0) {
1599+ LOG(LOG_ERR, "xmlX() fail");
15731600 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15741601 return PTS_INTERNAL_ERROR;
15751602 }
@@ -1577,6 +1604,7 @@ int writeQuote2(
15771604 /* PcrInfoShort - end */
15781605 rc = xmlTextWriterEndElement(writer);
15791606 if (rc < 0) {
1607+ LOG(LOG_ERR, "xmlX() fail");
15801608 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15811609 return PTS_INTERNAL_ERROR;
15821610 }
@@ -1584,6 +1612,7 @@ int writeQuote2(
15841612 /* QuoteInfo2 - end */
15851613 rc = xmlTextWriterEndElement(writer);
15861614 if (rc < 0) {
1615+ LOG(LOG_ERR, "xmlX() fail");
15871616 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15881617 return PTS_INTERNAL_ERROR;
15891618 }
@@ -1591,6 +1620,7 @@ int writeQuote2(
15911620 /* Quote2 - end */
15921621 rc = xmlTextWriterEndElement(writer);
15931622 if (rc < 0) {
1623+ LOG(LOG_ERR, "xmlX() fail");
15941624 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
15951625 return PTS_INTERNAL_ERROR;
15961626 }
@@ -1600,6 +1630,7 @@ int writeQuote2(
16001630 /* Start an element named "TpmSignature" as child of QuoteData. */
16011631 rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
16021632 if (rc < 0) {
1633+ LOG(LOG_ERR, "xmlX() fail");
16031634 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
16041635 return PTS_INTERNAL_ERROR;
16051636 }
@@ -1609,6 +1640,7 @@ int writeQuote2(
16091640 /* Start an element named "SignatureMethod" as child of TpmSignature. */
16101641 rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
16111642 if (rc < 0) {
1643+ LOG(LOG_ERR, "xmlX() fail");
16121644 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
16131645 return PTS_INTERNAL_ERROR;
16141646 }
@@ -1617,12 +1649,14 @@ int writeQuote2(
16171649 BAD_CAST "Algorithm",
16181650 BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO
16191651 if (rc < 0) {
1652+ LOG(LOG_ERR, "xmlX() fail");
16201653 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
16211654 return PTS_INTERNAL_ERROR;
16221655 }
16231656 /* Close the element named "SignatureMethod". */
16241657 rc = xmlTextWriterEndElement(writer);
16251658 if (rc < 0) {
1659+ LOG(LOG_ERR, "xmlX() fail");
16261660 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
16271661 return PTS_INTERNAL_ERROR;
16281662 }
@@ -1632,6 +1666,7 @@ int writeQuote2(
16321666 /* Start an element named "SignatureValue" as child of TpmSignature. */
16331667 rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureValue");
16341668 if (rc < 0) {
1669+ LOG(LOG_ERR, "xmlX() fail");
16351670 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
16361671 return PTS_INTERNAL_ERROR;
16371672 }
@@ -1642,12 +1677,14 @@ int writeQuote2(
16421677 0,
16431678 ctx->validation_data->ulValidationDataLength);
16441679 if (rc < 0) {
1680+ LOG(LOG_ERR, "xmlX() fail");
16451681 displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
16461682 return PTS_INTERNAL_ERROR;
16471683 }
16481684 /* Close the element named "SignatureValue". */
16491685 rc = xmlTextWriterEndElement(writer);
16501686 if (rc < 0) {
1687+ LOG(LOG_ERR, "xmlX() fail");
16511688 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
16521689 return PTS_INTERNAL_ERROR;
16531690 }
@@ -1655,6 +1692,7 @@ int writeQuote2(
16551692 /* Close the element named "TpmSignature". */
16561693 rc = xmlTextWriterEndElement(writer);
16571694 if (rc < 0) {
1695+ LOG(LOG_ERR, "xmlX() fail");
16581696 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
16591697 return PTS_INTERNAL_ERROR;
16601698 }
@@ -1662,6 +1700,7 @@ int writeQuote2(
16621700 /* Close the element named "QuoteData". */
16631701 rc = xmlTextWriterEndElement(writer);
16641702 if (rc < 0) {
1703+ LOG(LOG_ERR, "xmlX() fail");
16651704 displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
16661705 return PTS_INTERNAL_ERROR;
16671706 }
@@ -1689,8 +1728,8 @@ int writeQuote2(
16891728 int writeIr(
16901729 OPENPTS_CONTEXT *ctx,
16911730 const char *filenameDP, // in (set ctx->conf->ir_filename in normal operation)
1692- int *savedFd) // out
1693-{
1731+ int *savedFd) { // out
1732+
16941733 int rc = PTS_SUCCESS;
16951734 int i;
16961735 int irFd;
@@ -1778,6 +1817,7 @@ int writeIr(
17781817 /* Start the document */
17791818 rc = xmlTextWriterStartDocument(writer, "1.0", XML_ENCODING, "no");
17801819 if (rc < 0) {
1820+ LOG(LOG_ERR, "xmlX() fail");
17811821 displayXmlError(TEXT_WRITER_START_DOC, rc);
17821822 rc = PTS_INTERNAL_ERROR;
17831823 goto freexml;
@@ -1786,6 +1826,7 @@ int writeIr(
17861826 /* Start an element named "Report", the root element of the document. */
17871827 rc = xmlTextWriterStartElement(writer, BAD_CAST "Report");
17881828 if (rc < 0) {
1829+ LOG(LOG_ERR, "xmlX() fail");
17891830 displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
17901831 rc = PTS_INTERNAL_ERROR;
17911832 goto freexml;
@@ -1799,6 +1840,7 @@ int writeIr(
17991840 BAD_CAST "xmlns:core",
18001841 BAD_CAST XMLNS_CORE);
18011842 if (rc < 0) {
1843+ LOG(LOG_ERR, "xmlX() fail");
18021844 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
18031845 rc = PTS_INTERNAL_ERROR;
18041846 goto freexml;
@@ -1809,6 +1851,7 @@ int writeIr(
18091851 BAD_CAST "xmlns:stuff",
18101852 BAD_CAST XMLNS_STUFF);
18111853 if (rc < 0) {
1854+ LOG(LOG_ERR, "xmlX() fail");
18121855 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
18131856 rc = PTS_INTERNAL_ERROR;
18141857 goto freexml;
@@ -1820,6 +1863,7 @@ int writeIr(
18201863 BAD_CAST "xmlns:xsi",
18211864 BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
18221865 if (rc < 0) {
1866+ LOG(LOG_ERR, "xmlX() fail");
18231867 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
18241868 rc = PTS_INTERNAL_ERROR;
18251869 goto freexml;
@@ -1830,6 +1874,7 @@ int writeIr(
18301874 BAD_CAST "xmlns",
18311875 BAD_CAST XMLNS_IR);
18321876 if (rc < 0) {
1877+ LOG(LOG_ERR, "xmlX() fail");
18331878 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
18341879 rc = PTS_INTERNAL_ERROR;
18351880 goto freexml;
@@ -1856,6 +1901,7 @@ int writeIr(
18561901
18571902 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST id);
18581903 if (rc < 0) {
1904+ LOG(LOG_ERR, "xmlX() fail");
18591905 displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
18601906 rc = PTS_INTERNAL_ERROR;
18611907 goto free;
@@ -1973,8 +2019,7 @@ int writeIr(
19732019 filenameDP = ctx->ir_filename;
19742020 }
19752021
1976- //filename = ctx->ir_filename;
1977- DEBUG("Write Integrity Report (IR) : %s\n", filenameDP); //filename);
2022+ DEBUG("Write Integrity Report (IR) : %s\n", filenameDP);
19782023
19792024 /* write to file */
19802025 xmlFreeTextWriter(writer);
@@ -2872,10 +2917,10 @@ void irCharacters(void* ctx, const xmlChar * ch, int len) {
28722917 LOG(LOG_ERR, "null input");
28732918 return;
28742919 }
2875- //if (ch == NULL) {
2876- // LOG(LOG_ERR, "null input");
2877- // return;
2878- //}
2920+ if ((len > 0) && (ch == NULL)) {
2921+ LOG(LOG_ERR, "null input");
2922+ return;
2923+ }
28792924
28802925
28812926 /* copy to buf at ir_ctx, but check length first, ensuring additional space
@@ -3348,12 +3393,9 @@ int genIrFromTss(
33483393 if (ctx->conf->ir_filename != NULL) {
33493394 LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
33503395 }
3351- //ctx->conf->ir_filename = tempnam(NULL, "ir_");
3352- //DEBUG("ctx->conf->ir_filename : %s\n", ctx->conf->ir_filename);
33533396
33543397 /* save IR (new file in tmp dir) */
33553398 rc = writeIr(ctx, NULL, savedFd);
3356- // rc = writeIr(ctx, ctx->ir_filename, savedFd); // ir.c
33573399 if (rc != 0) {
33583400 LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
33593401 return PTS_INTERNAL_ERROR;
--- a/src/ir2text.c
+++ b/src/ir2text.c
@@ -24,7 +24,7 @@
2424 * \brief Convert IR file to plaintext (or binary)
2525 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2626 * @date 2010-12-01
27- * cleanup 2011-01-22 SM
27+ * cleanup 2012-01-05 SM
2828 *
2929 * IR(XML) -> SAX -> ctx->snapshot -> print
3030 *
@@ -61,7 +61,6 @@
6161 #define SHA1_DIGEST_SIZE 20
6262 BYTE pcr[MAX_PCRNUM][SHA1_DIGEST_SIZE];
6363
64-
6564 /* Element tag */
6665 #define IR_SAX_STATE_IDOL 0
6766 #define IR_SAX_STATE_PCR_INDEX 1
@@ -75,7 +74,6 @@ typedef struct {
7574 int sax_state;
7675 int sax_error;
7776 int char_size;
78- // char buf[EVENTDATA_BUF_SIZE]; // TODO(munetoh) fixed buffer
7977 char *buf; /**< buffer for the text element */
8078 /* IML -> FSM */
8179 int event_index;
@@ -520,7 +518,7 @@ void irEndElement(void * context, const xmlChar * name) {
520518 DEBUG("ignore QuoteData\n");
521519 } else {
522520 /* Else? */
523- DEBUG("END ELEMENT [%s] ",name);
521+ DEBUG("END ELEMENT [%s] ", name);
524522 }
525523
526524 ctx->sax_state = IR_SAX_STATE_IDOL;
@@ -722,7 +720,3 @@ int main(int argc, char *argv[]) {
722720 }
723721 return rc;
724722 }
725-
726-
727-
728-
--- a/src/misc.c
+++ b/src/misc.c
@@ -26,8 +26,8 @@
2626 * \brief misc functions
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-09-08
29- * cleanup 2011-07-06 SM
30- *
29+ * cleanup 2012-01-05 SM (remains one lint error)
30+ * src/misc.c:448: If you can, use sizeof(ptr) instead of 3 as the 2nd arg to snprintf. [runtime/printf] [3]
3131 */
3232
3333 #include <stdio.h>
@@ -66,9 +66,8 @@ void *xmalloc(size_t size) {
6666 char *result = malloc(size);
6767 if (NULL == result) {
6868 LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size);
69- // if ( size > 0 ) {
70- // LOG(LOG_ERR, "malloc");
71- // }
69+ ERROR(NLS(MS_OPENPTS, OPENPTS_MALLOC_FAIL,
70+ "No memory\n"));
7271 }
7372 return result;
7473 }
@@ -78,7 +77,8 @@ void *xmalloc_assert(size_t size) {
7877 char *result = malloc(size);
7978 if (NULL == result) {
8079 LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size);
81- OUTPUT("About to return NULL pointer - cannot continue\n");
80+ ERROR(NLS(MS_OPENPTS, OPENPTS_ABORT,
81+ "Abort to return NULL pointer - cannot continue\n"));
8282 exit(1);
8383 }
8484 return result;
@@ -133,7 +133,8 @@ char *smalloc_assert(char *str) {
133133 out = strdup(str);
134134 if (NULL == out) {
135135 LOG(LOG_ERR, "Failed to duplicate string '%s'\n", str);
136- OUTPUT("About to return NULL pointer - cannot continue\n");
136+ ERROR(NLS(MS_OPENPTS, OPENPTS_ABORT,
137+ "Abort to return NULL pointer - cannot continue\n"));
137138 exit(1);
138139 }
139140
@@ -184,7 +185,6 @@ char *snmalloc(char *str, int len) {
184185 * @param len
185186 */
186187 BYTE *snmalloc2(BYTE *buf, int offset, int len) {
187-
188188 /* check */
189189 if (buf == NULL) {
190190 LOG(LOG_ERR, "null input");
@@ -216,6 +216,13 @@ BYTE *snmalloc2(BYTE *buf, int offset, int len) {
216216 * free string buffer
217217 */
218218 void sfree(char *str) {
219+ /* check */
220+ if (str == NULL) {
221+ LOG(LOG_ERR, "null input");
222+ return;
223+ }
224+
225+ /* free*/
219226 xfree(str);
220227 }
221228
@@ -353,7 +360,7 @@ char *getFullpathDir(char *filename) {
353360 }
354361 }
355362
356- fullpath = xmalloc_assert(i+2);
363+ fullpath = xmalloc_assert(i+2); // check/abort
357364 memcpy(fullpath, filename, i+1);
358365 fullpath[i+1] = 0;
359366 return fullpath;
@@ -442,7 +449,7 @@ char *getHexString(BYTE *bin, int size) {
442449 return NULL;
443450 }
444451
445- buf = xmalloc_assert(size * 2 + 1);
452+ buf = xmalloc_assert(size * 2 + 1); // check/abort
446453 ptr = buf;
447454 for (i = 0; i < size; i++) {
448455 // len = snprintf(ptr, sizeof(ptr), "%02x", bin[i]);
--- a/src/nonce.c
+++ b/src/nonce.c
@@ -26,7 +26,7 @@
2626 * \brief calc D-H nonce
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-08-19
29- * cleanup 2011-01-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * PTS IF-M DH-Nonce protocol
3232 *
@@ -233,7 +233,6 @@ int calcExternalDataValue(OPENPTS_NONCE *ctx) {
233233 SHA_CTX sha_ctx;
234234 char c = '1';
235235
236- // DEBUG("calcExternalDataValue\n");
237236 /* check */
238237 if (ctx == NULL) {
239238 LOG(LOG_ERR, "null input");
@@ -279,8 +278,6 @@ int getDhResponce(OPENPTS_NONCE *ctx) {
279278 PTS_IF_M_DH_Nonce_Parameters_Request *req;
280279 PTS_IF_M_DH_Nonce_Parameters_Responce *res;
281280
282- // DEBUG("getDhResponce at Respondor\n");
283-
284281 /* check */
285282 if (ctx == NULL) {
286283 LOG(LOG_ERR, "null input");
@@ -566,10 +563,6 @@ int calcDhFin(OPENPTS_NONCE *ctx) {
566563 BIGNUM *pub_key;
567564 PTS_IF_M_DH_Nonce_Finish *fin;
568565
569- // DEBUG("calcDhFin at Respondor\n");
570- // printHex("fin->dh_initiator_nonce :",fin->dh_initiator_nonce,fin->nonce_length,"\n");
571- // printHex("fin->dh_initiator_public:",fin->dh_initiator_public,ctx->pubkey_length,"\n");
572-
573566 /* check */
574567 if (ctx == NULL) {
575568 LOG(LOG_ERR, "null input");
--- a/src/openpts.c
+++ b/src/openpts.c
@@ -26,12 +26,10 @@
2626 * \brief main of openpts command
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-07-25
29- * cleanup 2011-07-20 SM
29+ * cleanup 2012-01-04 SM
3030 *
3131 * This is verifier and utility to maintain the collector/verifier
3232 *
33- *
34- *
3533 */
3634
3735 #include <stdio.h>
@@ -56,7 +54,6 @@
5654 // verifier.c
5755 void global_lock(int type);
5856 int getDefaultConfigfile(OPENPTS_CONFIG *conf);
59-// log.c
6057
6158 /* Well defined return values that can be interpreted by the GUI */
6259 #define RETVAL_OK_TRUSTED 0
@@ -68,7 +65,6 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf);
6865 #define RETVAL_OK_PENDINGUPDATE 5
6966 #endif
7067
71-
7268 #define LINE "--------------------------------------------------------------------"
7369
7470 // TODO
@@ -115,8 +111,6 @@ void usage(void) {
115111
116112 #define OPENPTS_LOG_FILENAME "~/.openpts/openpts.log"
117113
118-
119-
120114 /**
121115 * main of "openpts" command
122116 *
@@ -129,7 +123,6 @@ int main(int argc, char *argv[]) {
129123 int rc = 0; // temporary return code
130124 int retVal = -1; // main() actual return value
131125 int opt;
132-
133126 OPENPTS_CONFIG *conf = NULL; // conf for openpts
134127 OPENPTS_CONTEXT *ctx = NULL;
135128 char * config_filename = NULL;
@@ -153,11 +146,11 @@ int main(int argc, char *argv[]) {
153146 char *ptsc_path = NULL;
154147 char *ptsc_conf = NULL;
155148
149+ /* Logging/NLS */
156150 initCatalog();
157151 setSyslogCommandName("openpts");
158152
159153 /* args */
160- /* verbose level */
161154 while ((opt = getopt(argc, argv, "givruDVc:dfuyl:p:P:C:h")) != -1) {
162155 switch (opt) {
163156 case 'i':
@@ -180,11 +173,9 @@ int main(int argc, char *argv[]) {
180173 command = DISPLAY;
181174 break;
182175 }
183-
184176 OUTPUT(NLS(MS_OPENPTS, OPENPTS_ONE_COMMAND_ONLY, "Only one command may be given at a time."));
185177 usage();
186178 return -1;
187-
188179 case 'V':
189180 incVerbosity();
190181 break;
@@ -239,11 +230,8 @@ int main(int argc, char *argv[]) {
239230 /* check */
240231 if ((ptsc_path != NULL) && (ptsc_conf != NULL)) {
241232 int len;
242- // char ptsc_command[PATH_MAX];
243- LOG(LOG_INFO, "ptsc debug mode\n");
244- // len = strlen(ptsc_path) + strlen(ptsc_conf) + 13;
245- // snprintf(ptsc_command, PATH_MAX - 1, "%s -m -v -c %s", ptsc_path, ptsc_conf);
246233
234+ LOG(LOG_INFO, "ptsc debug mode\n");
247235 len = strlen(ptsc_path) + strlen(ptsc_conf) + 13;
248236 ptsc_command = xmalloc(len);
249237 snprintf(ptsc_command, len, "%s -m -v -c %s", ptsc_path, ptsc_conf);
@@ -286,8 +274,7 @@ int main(int argc, char *argv[]) {
286274 goto out_free;
287275 }
288276
289- // setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
290-
277+ /* verbose msg */
291278 VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONFIG_FILE,
292279 "Config file : %s\n"), conf->config_file);
293280 VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_VERBOSITY,
@@ -364,17 +351,9 @@ int main(int argc, char *argv[]) {
364351 /* given target (by hostname) */
365352 /* look up */
366353 if (target_collector != NULL) {
367- // WORK NEEDED: Please use NLS for i18n output
368- OUTPUT("hostname : %s\n", target_hostname);
369- OUTPUT("UUID : %s\n", target_collector->str_uuid);
370- OUTPUT("State : %d\n", target_collector->state);
371- OUTPUT("Dir : %s\n", target_collector->dir);
372- OUTPUT("Manifests :\n");
373-
374- getRmList(target_conf, target_conf->config_dir);
375- printRmList(target_conf, "");
354+ printTarget(target_collector, "");
376355 } else {
377- OUTPUT(NLS(MS_OPENPTS, OPENPTS_TARGET_NOT_INITIALIZED,
356+ ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_NOT_INITIALIZED,
378357 "The target %s is not initialized yet. Please enroll with '%s' first\n\n"),
379358 target_hostname, target_hostname);
380359 retVal = RETVAL_NOTENROLLED;
@@ -383,10 +362,12 @@ int main(int argc, char *argv[]) {
383362 } else {
384363 /* all target (simple) */
385364 printTargetList(conf, ""); // target.c
386- goto out_free; // exit
365+ goto out_free;
387366 }
388- } else if ( NULL == target_hostname ) {
367+ } else if (target_hostname == NULL) {
389368 /* Other commands use Remote Access (SSH) */
369+ ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_MISSING,
370+ "Requires the target hostname\n\n")),
390371 usage();
391372 goto out_free;
392373 }
@@ -470,8 +451,8 @@ int main(int argc, char *argv[]) {
470451 DEBUG("conf->config_dir %s\n", conf->config_dir);
471452 rc = enroll(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, force); // verifier.c
472453 if (rc != 0) {
473- ERROR( // TODO NLS
474- "enroll was failed, rc = %d\n", rc);
454+ ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_ENROLL_FAIL,
455+ "enroll was failed, rc = %d\n"), rc);
475456 printReason(ctx, print_pcr_hints);
476457 retVal = RETVAL_NOTENROLLED;
477458 goto out_free;
@@ -481,8 +462,8 @@ int main(int argc, char *argv[]) {
481462 rc = verifier(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, 1); // init
482463 if (rc != OPENPTS_RESULT_VALID) {
483464 LOG(LOG_ERR, "initial verification was failed, rc = %d\n", rc);
484- ERROR( // TODO NLS
485- "initial verification was failed, rc = %d\n", rc);
465+ ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_VERIFICATION_FAIL,
466+ "initial verification was failed, rc = %d\n"), rc);
486467 printReason(ctx, print_pcr_hints);
487468 retVal = RETVAL_NOTTRUSTED;
488469 goto out_free;
--- a/src/policy.c
+++ b/src/policy.c
@@ -26,14 +26,13 @@
2626 * \brief policy
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-06-19
29- * cleanup 2011-01-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * Security Policy
3232 * - load
3333 * - verify
3434 * - print
3535 *
36- *
3736 */
3837
3938
@@ -42,7 +41,6 @@
4241 #include <string.h>
4342
4443 #include <openpts.h>
45-// #include <log.h>
4644
4745 /**
4846 * Free policy chain
@@ -71,15 +69,15 @@ int freePolicyChain(OPENPTS_POLICY *pol) {
7169 * policy number
7270 */
7371 int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
74- FILE *fp;
7572 char buf[BUF_SIZE]; // SMBIOS
7673 char *eq;
7774 char *name;
7875 char *value;
7976 int cnt = 1;
8077 int len;
81- OPENPTS_POLICY *pol;
8278 int line = 0;
79+ FILE *fp;
80+ OPENPTS_POLICY *pol;
8381
8482 /* check */
8583 if (ctx == NULL) {
@@ -99,7 +97,6 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
9997 }
10098
10199 /* parse */
102-
103100 while (fgets(buf, BUF_SIZE, fp) != NULL) { // read line
104101 /* ignore comment, null line */
105102 if (buf[0] == '#') {
@@ -143,7 +140,7 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
143140 }
144141 cnt++;
145142 } else {
146- //
143+ // unknown eq
147144 }
148145 line++;
149146 }
@@ -243,7 +240,6 @@ int checkPolicy(OPENPTS_CONTEXT *ctx) {
243240 /**
244241 * print policy and properties
245242 *
246- *
247243 */
248244 int printPolicy(OPENPTS_CONTEXT *ctx) {
249245 OPENPTS_POLICY *pol;
@@ -308,5 +304,3 @@ int printPolicy(OPENPTS_CONTEXT *ctx) {
308304
309305 return 0;
310306 }
311-
312-
--- a/src/prop.c
+++ b/src/prop.c
@@ -26,7 +26,7 @@
2626 * \brief properties
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-06-19
29- * cleanup 2011-01-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * Security Properties
3232 *
@@ -107,7 +107,7 @@ void freeProperty(OPENPTS_PROPERTY *prop) {
107107 * Free Property Chain
108108 */
109109 int freePropertyChain(OPENPTS_PROPERTY *prop) {
110-
110+ /* check */
111111 if (prop == NULL) {
112112 /* end of chain */
113113 return PTS_SUCCESS;
@@ -164,6 +164,20 @@ int addProperty(OPENPTS_CONTEXT *ctx, char *name, char *value) {
164164 OPENPTS_PROPERTY *end;
165165 OPENPTS_PROPERTY *prop;
166166
167+ /* check */
168+ if (ctx == NULL) {
169+ LOG(LOG_ERR, "null input");
170+ return PTS_FATAL;
171+ }
172+ if (name == NULL) {
173+ LOG(LOG_ERR, "null input");
174+ return PTS_FATAL;
175+ }
176+ if (value == NULL) {
177+ LOG(LOG_ERR, "null input");
178+ return PTS_FATAL;
179+ }
180+
167181 start = ctx->prop_start;
168182 end = ctx->prop_end;
169183
@@ -265,15 +279,15 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
265279 /* check, missing event */
266280 if (eventWrapper == NULL) {
267281 LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n");
268- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
282+ return PTS_FATAL;
269283 }
270284 if (eventWrapper->event == NULL) {
271285 LOG(LOG_ERR, "setEventProperty() - event is NULL\n");
272- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
286+ return PTS_FATAL;
273287 }
274288 if (eventWrapper->event->rgbPcrValue == NULL) {
275289 LOG(LOG_ERR, "setEventProperty() - rgbPcrValue is NULL\n");
276- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
290+ return PTS_FATAL;
277291 }
278292
279293 buf = encodeBase64(
@@ -303,18 +317,18 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_
303317 /* check, missing event */
304318 if (eventWrapper == NULL) {
305319 LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n");
306- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
320+ return PTS_FATAL;
307321 }
308322 event = eventWrapper->event;
309323 if (event == NULL) {
310324 LOG(LOG_ERR, "setEventProperty() - event is NULL\n");
311- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
325+ return PTS_FATAL;
312326 }
313327 if (event->ulEventLength > 0) {
314328 char * str;
315329 if (event->rgbEvent == NULL) {
316330 LOG(LOG_ERR, "setEventProperty() - rgbEvent is NULL\n");
317- return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR;
331+ return PTS_FATAL;
318332 }
319333 /* get String */
320334
@@ -493,7 +507,6 @@ int saveProperties(OPENPTS_CONTEXT *ctx, char * filename) {
493507 }
494508
495509 int addPropertiesFromConfig(OPENPTS_CONFIG *conf, OPENPTS_CONTEXT *ctx) {
496-
497510 /* check */
498511 if (conf == NULL) {
499512 LOG(LOG_ERR, "null input");
--- a/src/ptsc.c
+++ b/src/ptsc.c
@@ -28,7 +28,7 @@
2828 * @author Olivier Valentin <olivier.valentin@us.ibm.com>
2929 * @author Alexandre Ratchov <alexandre.ratchov@bull.net>
3030 * @date 2010-04-04
31- * cleanup 2011-07-06 SM
31+ * cleanup 2012-01-04 SM
3232 *
3333 */
3434
@@ -50,8 +50,6 @@
5050 #include <sys/stat.h> // chmod
5151
5252 #include <openpts.h>
53-// #include <log.h>
54-
5553
5654 int prop_num = 0;
5755 OPENPTS_PROPERTY *start = NULL;
@@ -64,7 +62,7 @@ OPENPTS_PROPERTY *end = NULL;
6462 * TODO for multiple conenction, multiple ctxs are required.
6563 * TODO disable remote connection
6664 */
67-int collector2(OPENPTS_CONFIG *conf) {
65+int collector(OPENPTS_CONFIG *conf) {
6866 int rc;
6967 int terminate = 0;
7068 OPENPTS_CONTEXT *ctx = NULL;
@@ -83,12 +81,10 @@ int collector2(OPENPTS_CONFIG *conf) {
8381 DEBUG("collector() - getNewRmSetDir() was failed - never mind\n");
8482 }
8583
86-
8784 LOG(LOG_INFO, "start collector (System UUID=%s, RM UUID = %s)\n",
8885 conf->uuid->str, conf->rm_uuid->str);
8986
9087 /* Collector <-> Verifier - handshake loop */
91-
9288 ctx = newPtsContext(conf);
9389
9490 addPropertiesFromConfig(conf, ctx);
@@ -127,7 +123,6 @@ int collector2(OPENPTS_CONFIG *conf) {
127123 /* C->V responces */
128124 switch (read_tlv->type) {
129125 case OPENPTS_CAPABILITIES:
130- // TODO define CAPABILITIES structure
131126 DEBUG("IF-M OPENPTS_CAPABILITIES\n");
132127 /* check the UUID */
133128 if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) { // TODO use defined name
@@ -415,6 +410,8 @@ OPENPTS_PROPERTY *getPropertyFromArg(char *arg) {
415410
416411 /**
417412 * lock ptsc
413+ *
414+ * check the log msg
418415 */
419416 void ptsc_lock(void) {
420417 int fd, oldmask, oldgrp = 0;
@@ -442,11 +439,11 @@ void ptsc_lock(void) {
442439
443440 rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &grpent);
444441 if (rc != 0) {
445- // TODO
442+ LOG(LOG_ERR, "getgrnam_r() fail");
446443 exit(1);
447444 }
448445 if (grpent == NULL) {
449- // TODO
446+ LOG(LOG_ERR, "grpent is null");
450447 exit(1);
451448 }
452449 oldgrp = getegid();
@@ -495,11 +492,6 @@ static int preparePriv() {
495492 #endif
496493
497494 /* check GID */
498- // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r
499- // if (ptsc_grp == NULL) {
500- // LOG(LOG_ERR, "Looking up for group (name=%s) fail", PTSC_GROUP_NAME);
501- // return PTS_FATAL;
502- // }
503495 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
504496 if (buf_len < 0) {
505497 buf_len = 4096;
@@ -527,7 +519,6 @@ static int preparePriv() {
527519 if (rc < 0) {
528520 // TODO do not need for IF-M access (read only)
529521 LOG(LOG_INFO, "Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno));
530- // TODO 20110927 FAIL
531522 rc = PTS_FATAL;
532523 goto free;
533524 }
@@ -539,7 +530,7 @@ static int preparePriv() {
539530 }
540531 #endif
541532
542- /* */
533+ /* free */
543534 free:
544535 if (buf != NULL) xfree(buf);
545536
@@ -560,11 +551,6 @@ static int chmodDir(char *dirpath, int flag) {
560551
561552
562553 /* check GID */
563- // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r
564- // if (ptsc_grp == NULL) {
565- // LOG(LOG_ERR, "Looking up for group %s", PTSC_GROUP_NAME);
566- // return PTS_FATAL;
567- // }
568554 buf_len = sysconf(_SC_GETGR_R_SIZE_MAX);
569555 if (buf_len < 0) {
570556 buf_len = 4096;
@@ -636,28 +622,11 @@ int main(int argc, char *argv[]) {
636622 #ifdef CONFIG_AUTO_RM_UPDATE
637623 int remove = 0;
638624 #endif
639- // extern int logLocation;
640- // void setLogLocation(int ll);
641625
642626 /* properties by cmdline */
643627 OPENPTS_PROPERTY *prop;
644628
645-#if 0
646- initCatalog();
647-
648- // TODO chgrp
649- rc = preparePriv();
650- if (rc != PTS_SUCCESS) {
651- LOG(LOG_ERR, "preparePriv fail\n");
652- }
653-
654- conf = newPtsConfig();
655- if (conf == NULL) {
656- LOG(LOG_ERR, "internal error\n"); // TODO(munetoh)
657- return -1;
658- }
659-#endif
660-
629+ /* Logging/NLS */
661630 initCatalog();
662631 setSyslogCommandName("ptsc");
663632
@@ -695,9 +664,6 @@ int main(int argc, char *argv[]) {
695664 /* not everything should go to syslog - on some systems
696665 this could go to a log file - let default behaviour
697666 in log.c decide this */
698- // setLogLocation(OPENPTS_LOG_SYSLOG, NULL);
699- // OK setLogLocation(OPENPTS_LOG_CONSOLE, NULL); // OK
700- // setLogLocation(OPENPTS_LOG_FILE, "/var/log/ptsc.log"); // OK call this before any out
701667 break;
702668 case 'c':
703669 config_filename = optarg;
@@ -746,11 +712,10 @@ int main(int argc, char *argv[]) {
746712 if (command == COMMAND_IFM) {
747713 /* Set IF-M log location, syslog or file(for DEBUG) */
748714 setLogLocation(OPENPTS_LOG_SYSLOG, NULL);
749- // setVerbosity(0); // no console out
750715 } else {
751716 /* Set logging (location,filename) by ENV */
752717 determineLogLocationByEnv();
753- //setLogLocation(OPENPTS_LOG_CONSOLE, NULL);
718+
754719 // TODO chgrp
755720 rc = preparePriv();
756721 if (rc != PTS_SUCCESS) {
@@ -766,7 +731,7 @@ int main(int argc, char *argv[]) {
766731
767732 /* set the DEBUG level, 1,2,3 */
768733 if (getVerbosity() > 2) {
769- setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG );
734+ setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG);
770735 } else if (getVerbosity() > 1) {
771736 setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG);
772737 } else if (getVerbosity() > 0) {
@@ -781,14 +746,16 @@ int main(int argc, char *argv[]) {
781746 /* load config, /etc/ptsc.conf */
782747 if (config_filename == NULL) {
783748 // this goto stdout and bad with "-m"
784- // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), PTSC_CONFIG_FILE);
749+ VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE,
750+ "Config file: %s\n"), PTSC_CONFIG_FILE);
785751 rc = readPtsConfig(conf, PTSC_CONFIG_FILE);
786752 if (rc != PTS_SUCCESS) {
787753 DEBUG("readPtsConfig() failed\n");
788754 goto free;
789755 }
790756 } else {
791- // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), config_filename);
757+ VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE,
758+ "Config file: %s\n"), config_filename);
792759 rc = readPtsConfig(conf, config_filename);
793760 if (rc != PTS_SUCCESS) {
794761 DEBUG("readPtsConfig() failed\n");
@@ -804,8 +771,8 @@ int main(int argc, char *argv[]) {
804771 if (checkFile(conf->uuid->filename) != OPENPTS_FILE_EXISTS) {
805772 // missing
806773 LOG(LOG_ERR, "ptsc is not initialized yet");
807- ERROR( // TODO NLS
808- "ptsc is not initialized yet.\n\n");
774+ ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_NOT_INITIALIZED,
775+ "ptsc is not initialized yet.\n\n"));
809776 goto free;
810777 }
811778 }
@@ -851,7 +818,7 @@ int main(int argc, char *argv[]) {
851818 } else {
852819 rc = readOpenptsUuidFile(conf->rm_uuid);
853820 if (rc != PTS_SUCCESS) {
854- DEBUG("readOpenptsUuidFile(%s) failed\n",conf->rm_uuid->filename);
821+ DEBUG("readOpenptsUuidFile(%s) failed\n", conf->rm_uuid->filename);
855822 OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_RM_UUID,
856823 "Failed to read the Reference Manifest UUID file '%s':\n"
857824 "Please ensure on the target that:\n"
@@ -914,7 +881,6 @@ int main(int argc, char *argv[]) {
914881 case COMMAND_AUTO_UPDATE:
915882 /* update by command, but HUP is better */
916883 VERBOSE(1, "Updating Reference Manifest\n");
917- //addDebugFlags(DEBUG_CAL_FLAG);
918884 /* update RMs */
919885 rc = update(conf, prop_num, start, end, remove);
920886 if (rc != PTS_SUCCESS) {
@@ -1034,7 +1000,7 @@ int main(int argc, char *argv[]) {
10341000 break;
10351001 case COMMAND_IFM:
10361002 /* run colelctor IF-M */
1037- rc = collector2(conf);
1003+ rc = collector(conf);
10381004 break;
10391005 default:
10401006 LOG(LOG_ERR, "bad command\n");
@@ -1044,5 +1010,8 @@ int main(int argc, char *argv[]) {
10441010 free:
10451011 freePtsConfig(conf);
10461012
1013+ if (rc != PTS_SUCCESS) {
1014+ LOG(LOG_ERR, "ptsc exit. rc = %d", rc);
1015+ }
10471016 return rc;
10481017 }
--- a/src/reason.c
+++ b/src/reason.c
@@ -26,7 +26,7 @@
2626 * \brief properties
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-11-26
29- * cleanup 2011-01-22 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * Reason (Remidiation) of validation fail
3232 *
@@ -56,7 +56,7 @@ void freeReason(OPENPTS_REASON *reason) {
5656 xfree(reason->message);
5757 xfree(reason);
5858
59- return; // PTS_SUCCESS;
59+ return;
6060 }
6161
6262 /**
@@ -88,16 +88,13 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
8888 OPENPTS_REASON *reason;
8989 int len;
9090
91- // DEBUG("addReason - [%s]\n", message);
92-
9391 /* check */
9492 if (ctx == NULL) {
9593 LOG(LOG_ERR, "null input");
9694 return PTS_FATAL;
9795 }
9896
99- len = strlen(message);
100-
97+ len = strlen(message);
10198 start = ctx->reason_start;
10299 end = ctx->reason_end;
103100
@@ -132,8 +129,6 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
132129 reason->message[len] = 0;
133130 ctx->reason_count++;
134131
135- // DEBUG("addReason - done %d [%s]\n", ctx->reason_count, reason->message);
136-
137132 return PTS_SUCCESS;
138133 }
139134
@@ -142,10 +137,9 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
142137 */
143138 #define MAX_REASON_SIZE 2048
144139 int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
145- char buf[MAX_REASON_SIZE +1]; // TODO size
146140 int rc;
141+ char buf[MAX_REASON_SIZE +1]; // TODO size
147142 va_list list;
148- va_start(list, format);
149143
150144 /* check */
151145 if (ctx == NULL) {
@@ -153,6 +147,7 @@ int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
153147 return PTS_FATAL;
154148 }
155149
150+ va_start(list, format);
156151 vsnprintf(buf, MAX_REASON_SIZE, format, list);
157152
158153 rc = addReason_old(ctx, pcr, (char *)buf);
@@ -178,7 +173,7 @@ char *reason_pcr_hints[] = {
178173 NULL, /* PCR9 Unused */
179174 "Trusted Execution Database"
180175 };
181-#else // TPM v1.2, PC Linux, TODO add other type of platform?
176+#else // TPM v1.2, PC Linux, TODO add other type of platform?
182177 char *reason_pcr_hints[] = {
183178 "CRTM, BIOS and Platform Extensions",
184179 "Platform Configuration",
@@ -187,7 +182,7 @@ char *reason_pcr_hints[] = {
187182 "IPL Code (usually the MBR)",
188183 "IPL Code Configuration and Data (for use by the IPL code)",
189184 "State Transition and Wake Events",
190- "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.",
185+ "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.",
191186 "OS Kernels (GRUB-IMA)",
192187 NULL, /* PCR9 Unused */
193188 "Applications (LINUX-IMA)", /* PCR10 */
@@ -236,6 +231,3 @@ void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) {
236231 }
237232 }
238233 }
239-
240-
241-// TODO add freeReason()
--- a/src/rm.c
+++ b/src/rm.c
@@ -26,7 +26,7 @@
2626 * \brief Reference Manifest (RM)
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-12-31 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * IML + Model -> RM
3232 *
@@ -233,7 +233,6 @@ int writeCoreValues(xmlTextWriterPtr writer,
233233 int algtype,
234234 char *id,
235235 TSS_PCR_EVENT * event) {
236-
237236 /* check */
238237 if (writer == NULL) {
239238 LOG(LOG_ERR, "null input");
@@ -479,7 +478,6 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) {
479478 */
480479 int writeFsmSubvertex(xmlTextWriterPtr writer,
481480 OPENPTS_FSM_Subvertex * sub) {
482-
483481 DEBUG_CAL("writeFsmSubvertex - start\n");
484482
485483 /* check */
@@ -682,7 +680,6 @@ int writeFsmTransition(xmlTextWriterPtr writer,
682680 </uml:Model>
683681 */
684682 int writeFsmModel(xmlTextWriterPtr writer, OPENPTS_FSM_CONTEXT * fsm) {
685- //int rc =0;
686683 char id[BUF_SIZE];
687684 OPENPTS_FSM_Subvertex *sub;
688685 OPENPTS_FSM_Transition *trans;
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -26,7 +26,7 @@
2626 * \brief parse SMBIOS info
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-08-29
29- * cleanup 2012-01-03 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * SMBIOS Info in BIOS IML -> platform properties
3232 *
@@ -53,7 +53,6 @@
5353 #include <dirent.h>
5454
5555 #include <openpts.h>
56-// #include <log.h>
5756
5857 #define SMBIOS_MAX_SIZE 4096
5958 #define SMBIOS_MAX_HANDLE 0x50
@@ -70,17 +69,16 @@ int genSmbiosFileByDmidecode(char * filename) {
7069
7170 /* must be a root user */
7271 uid = getuid();
73- // DEBUG("UID %d\n",uid);
7472 if (uid != 0) {
7573 DEBUG("must be a root user to run dmidecode\n");
76- return -2;
74+ return PTS_FATAL;
7775 }
7876
7977 /* exec dmidecode */
8078 pid = fork();
8179 if (pid < 0) {
82- LOG(LOG_ERR, "\n");
83- return -1;
80+ LOG(LOG_ERR, "fork() fail");
81+ return PTS_FATAL;
8482 }
8583 if (pid == 0) {
8684 /* child */
@@ -95,17 +93,17 @@ int genSmbiosFileByDmidecode(char * filename) {
9593 if (WIFEXITED(status)) {
9694 /* 1 : OK */
9795 LOG(LOG_TODO, "Exit status %d\n", WEXITSTATUS(status));
98- return 1;
96+ return PTS_SUCCESS; // 1
9997 } else if (WIFSIGNALED(status)) {
10098 LOG(LOG_ERR, "Signal status %d\n", WIFSIGNALED(status));
101- return -1;
99+ return PTS_FATAL;
102100 } else {
103101 LOG(LOG_ERR, "Bad exit");
104- return -1;
102+ return PTS_FATAL;
105103 }
106104 }
107105
108- return 0;
106+ return PTS_SUCCESS;
109107 }
110108
111109
@@ -123,8 +121,16 @@ int readSmbiosFile(char * filename, BYTE **data, int *len) {
123121 BYTE *buf;
124122 int rc = PTS_SUCCESS;
125123
126- buf = xmalloc(SMBIOS_MAX_SIZE); // TODO check the filesize
124+ /* check */
125+ if (filename == NULL) {
126+ LOG(LOG_ERR, "null input");
127+ return PTS_FATAL;
128+ }
129+
130+ // TODO(munetoh) check the file size
131+ buf = xmalloc(SMBIOS_MAX_SIZE);
127132 if (buf == NULL) {
133+ LOG(LOG_ERR, "no memory");
128134 return PTS_FATAL;
129135 }
130136
@@ -134,7 +140,7 @@ int readSmbiosFile(char * filename, BYTE **data, int *len) {
134140 goto error;
135141 }
136142
137- size = fread(buf, 1, SMBIOS_MAX_SIZE, fp); // TODO(munetoh) check the file size
143+ size = fread(buf, 1, SMBIOS_MAX_SIZE, fp);
138144
139145 fclose(fp);
140146
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -26,7 +26,7 @@
2626 * \brief Functions for snapshot
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-11-02
29- * cleanup 2011-01-20 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * divided from IML.c
3232 *
@@ -82,7 +82,6 @@
8282 #include <openssl/sha.h>
8383
8484 #include <openpts.h>
85-// #include <log.h>
8685
8786 /**
8887 * New Snapshot
@@ -94,7 +93,7 @@
9493 OPENPTS_SNAPSHOT * newSnapshot() {
9594 OPENPTS_SNAPSHOT *ss = NULL;
9695
97- ss = (OPENPTS_SNAPSHOT*) xmalloc(sizeof(OPENPTS_SNAPSHOT)); // leaked
96+ ss = (OPENPTS_SNAPSHOT*) xmalloc(sizeof(OPENPTS_SNAPSHOT));
9897 if (ss == NULL) {
9998 LOG(LOG_ERR, "no memory");
10099 return NULL;
@@ -109,14 +108,12 @@ OPENPTS_SNAPSHOT * newSnapshot() {
109108 return ss;
110109 }
111110
112-
113111 /**
114112 * Free Snapshot
115113 *
116114 * return 0:success, -1:error
117115 */
118116 int freeSnapshot(OPENPTS_SNAPSHOT * ss) {
119-
120117 /* check */
121118 if (ss == NULL) {
122119 LOG(LOG_ERR, "null input");
@@ -157,7 +154,7 @@ int freeSnapshot(OPENPTS_SNAPSHOT * ss) {
157154 OPENPTS_SNAPSHOT_TABLE * newSnapshotTable() {
158155 OPENPTS_SNAPSHOT_TABLE *sst = NULL;
159156
160- sst = (OPENPTS_SNAPSHOT_TABLE *) xmalloc(sizeof(OPENPTS_SNAPSHOT_TABLE)); // leaked
157+ sst = (OPENPTS_SNAPSHOT_TABLE *) xmalloc(sizeof(OPENPTS_SNAPSHOT_TABLE));
161158 if (sst == NULL) {
162159 LOG(LOG_ERR, "no memory");
163160 return NULL;
@@ -254,7 +251,7 @@ OPENPTS_SNAPSHOT *getSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_ind
254251
255252 /* check 2 */
256253 if (sst->snapshot[pcr_index][level] == NULL) {
257- // DEBUG("sst->snapshot[%d][%d] is null", pcr_index, level);
254+ /* Missing SS */
258255 return NULL;
259256 }
260257
--- a/src/ssh.c
+++ b/src/ssh.c
@@ -27,7 +27,7 @@
2727 * @author Olivier Valentin <olivier.valentin@us.ibm.com>
2828 * @author Alexandre Ratchov <alexandre.ratchov@bull.net>
2929 * @date 2010-03-31
30- * cleanup 2011-12-31 SM
30+ * cleanup 2012-01-05 SM
3131 *
3232 */
3333
@@ -67,20 +67,19 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file
6767 return -1;
6868 }
6969
70-
7170 /* socket */
7271 if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair) == -1) {
7372 LOG(LOG_ERR, "socketpair() fail");
7473 goto err;
7574 }
7675
76+ /* fork */
7777 if ((pid = fork()) == -1) {
7878 LOG(LOG_ERR, "fork() fail");
7979 goto err_close;
8080 }
81-
8281 if (pid == 0) {
83- // child process
82+ /* child process */
8483 char *arguments[16];
8584 int arg_idx = 0;
8685 char identity_string[PATH_MAX + /* "IdentityFile " */ 13];
@@ -117,13 +116,14 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file
117116 arguments[arg_idx++] = host;
118117 arguments[arg_idx++] = ptsc_command;
119118 #if 0
119+ // TODO
120120 /* Sync verbose level between verifier and collector? */
121- // {
121+ if (verbose_sync) {
122122 int verboseLevel;
123123 for ( verboseLevel = 0; (verboseLevel < getVerbosity()) && (arg_idx < 15); verboseLevel++ ) {
124124 arguments[arg_idx++] = "-v";
125125 }
126- // }
126+ }
127127 #endif
128128 arguments[arg_idx++] = NULL;
129129
--- a/src/target.c
+++ b/src/target.c
@@ -26,7 +26,7 @@
2626 * \brief target(collector)
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2011-06-22
29- * cleanup 2011-10-07 SM
29+ * cleanup 2012-01-04 SM
3030 *
3131 * branch from uuid.c
3232 *
@@ -130,11 +130,8 @@ static int selectUuidDir(const struct dirent *entry) {
130130
131131 /* skip bad dir name - by length */
132132 len = strlen(entry->d_name);
133- // TODO ("UUID dirname len = %d, %s\n",len, entry->d_name);
134133 if (len != 36) return 0;
135134
136- // TODO not enough?, add test cases for the bad dir name
137-
138135 /* Dir HIT */
139136 // TODO check the format
140137 #ifndef __linux__
@@ -187,16 +184,16 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) {
187184
188185 /* move to config dir */
189186 if ((chdir(conf->config_dir)) != 0) {
190- ERROR( // TODO NLS
191- "Accessing config directory %s\n", conf->config_dir);
187+ ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_CONFDIR_MISSING,
188+ "Accessing config directory %s fail\n"), conf->config_dir);
192189 return PTS_INTERNAL_ERROR;
193190 }
194191
195192 /* scan dirs */
196193 dir_num = scandir(".", &dir_list, &selectUuidDir, NULL);
197194 if ( dir_num == -1 ) {
198- ERROR( // TODO NLS
199- "No target data.\n");
195+ ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_NULL,
196+ "No target data.\n"));
200197 return PTS_INTERNAL_ERROR;
201198 }
202199
@@ -269,7 +266,6 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) {
269266 rmset1->dir = tmp_dir;
270267 }
271268 }
272- // printRmList(conf);
273269 }
274270
275271 /* set current_id */
@@ -319,8 +315,6 @@ int rmRmsetDir(char * dir) {
319315 return PTS_FATAL;
320316 }
321317
322-
323- // DEBUG("rm -r %s\n", dir);
324318 snprintf(buf, BUF_SIZE, "rm -r %s\n", dir);
325319 rc = system(buf);
326320 if (rc < 0) {
@@ -363,7 +357,6 @@ int purgeRenewedRm(OPENPTS_CONFIG *conf) {
363357 state = rmset->state;
364358
365359 if (state == OPENPTS_RM_STATE_TRASH) {
366- // INFO(NLS(MS_OPENPTS, OPENPTS_PURGE_RENEWED_RM, " purge %s\n"), rmset->str_uuid);
367360 LOG(LOG_INFO, " purge %s\n", rmset->str_uuid);
368361 rc = rmRmsetDir(rmset->dir);
369362 if (rc != PTS_SUCCESS) {
@@ -750,6 +743,38 @@ static void printTargetInfo_CompID(OPENPTS_CONTEXT *ctx, FILE *fp, int cnt) {
750743 }
751744 #endif
752745
746+/**
747+ * print one target
748+ */
749+void printTarget(
750+ OPENPTS_TARGET *target_collector,
751+ char *indent) {
752+
753+ OPENPTS_CONFIG *target_conf;
754+
755+ /* check */
756+ if (target_collector == NULL) {
757+ LOG(LOG_ERR, "null input");
758+ return;
759+ }
760+ target_conf = (OPENPTS_CONFIG*)target_collector->target_conf;
761+ if (target_conf == NULL) {
762+ LOG(LOG_ERR, "null input");
763+ return;
764+ }
765+
766+ // WORK NEEDED: Please use NLS for i18n output
767+ OUTPUT("%shostname : %s\n", indent, target_conf->hostname);
768+ OUTPUT("%sssh username : %s\n", indent, target_conf->ssh_username);
769+ OUTPUT("%ssh port : %s\n", indent, target_conf->ssh_port);
770+ OUTPUT("%sUUID : %s\n", indent, target_collector->str_uuid);
771+ OUTPUT("%sState : %d\n", indent, target_collector->state);
772+ OUTPUT("%sDir : %s\n", indent, target_collector->dir);
773+ OUTPUT("%sManifests :\n", indent);
774+
775+ getRmList(target_conf, target_conf->config_dir);
776+ printRmList(target_conf, indent);
777+}
753778
754779 /**
755780 * print target list, target par line
@@ -775,8 +800,8 @@ void printTargetList(OPENPTS_CONFIG *conf, char *indent) {
775800 num = conf->target_list->target_num;
776801
777802 if (num == 0) {
778- OUTPUT( // TODO NLS
779- "There is no enrolled target platform.\n");
803+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_PRINT_TARGET_LIST_NULL,
804+ "There is no enrolled target platform.\n"));
780805 return;
781806 }
782807
--- a/src/tboot2iml.c
+++ b/src/tboot2iml.c
@@ -26,9 +26,8 @@
2626 * \brief create pseudo IML of tboot, standalone tool
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2011-03-28
29- * cleanup 2011-07-06 SM
30- * refactoring
31- *
29+ * cleanup 2012-01-05 SM (remains 33 lint errors, ignore)
30+ * src/tboot2iml.c:184: Tab found; better to use spaces [whitespace/tab] [1]
3231 *
3332 * Test
3433 *
@@ -1158,7 +1157,7 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) {
11581157
11591158
11601159 void usage(void) {
1161- OUTPUT( // TODO NLS
1160+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_TBOOT2IML_USAGE,
11621161 "OpenPTS command\n\n"
11631162 "Usage: tboot2iml [options]\n\n"
11641163 "Options:\n"
@@ -1168,7 +1167,7 @@ void usage(void) {
11681167 " -o filename Output to file (default is STDOUT)\n"
11691168 " -v Verbose message\n"
11701169 " -h Help\n"
1171- "\n");
1170+ "\n"));
11721171 }
11731172
11741173 int main(int argc, char *argv[]) {
@@ -1209,8 +1208,8 @@ int main(int argc, char *argv[]) {
12091208
12101209 /* check */
12111210 if ((grub_conf_filename != NULL) && (grub_path == NULL)) {
1212- ERROR( // TODO NLS
1213- "set the root path used by crub.conf\n");
1211+ ERROR(NLS(MS_OPENPTS, OPENPTS_TBOOT2IML_GRUBPATH_MISSING,
1212+ "set the root path used by grub.conf\n"));
12141213 usage();
12151214 goto close;
12161215 }
--- a/src/tpm.c
+++ b/src/tpm.c
@@ -26,7 +26,7 @@
2626 * \brief emulate TPM
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-12-31 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * Emulate TPM to validate IML and PCR
3232 */
@@ -46,8 +46,7 @@
4646
4747 #include <openpts.h>
4848
49-
50-/* TPM functions */
49+/* TPM functions -------------------------------------------------------------*/
5150
5251 /**
5352 * reset TPM
@@ -333,5 +332,3 @@ int getTpmPcrValue(OPENPTS_TPM_CONTEXT *tpm, int index, BYTE *digest) {
333332
334333 return PTS_SUCCESS;
335334 }
336-
337-
--- a/src/tss.c
+++ b/src/tss.c
@@ -27,7 +27,7 @@
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-08-18
2929 * refactoring 2011-02-15 SM
30- * cleanup 2012-01-02 SM
30+ * cleanup 2012-01-05 SM
3131 *
3232 * Create Sign Key
3333 * Create AIK
@@ -87,8 +87,7 @@ int createTssSignKey(
8787 char *filename,
8888 int auth_type,
8989 int force,
90- int srk_password_mode)
91-{
90+ int srk_password_mode) {
9291 /* dummy */
9392 return TSS_SUCCESS;
9493 }
@@ -96,8 +95,7 @@ int createTssSignKey(
9695 int deleteTssKey(
9796 PTS_UUID *uuid,
9897 int key_storage_type,
99- char *filename)
100-{
98+ char *filename) {
10199 /* dummy */
102100 return TSS_SUCCESS;
103101 }
@@ -120,8 +118,7 @@ int getTssPubKey(
120118 int resetdalock,
121119 char *filename,
122120 int auth_type,
123- int *pubkey_length, BYTE **pubkey)
124-{
121+ int *pubkey_length, BYTE **pubkey) {
125122 /* dummy */
126123 return TSS_SUCCESS;
127124 }
@@ -134,8 +131,7 @@ int quoteTss(
134131 int auth_type,
135132 BYTE *nonce,
136133 OPENPTS_PCRS *pcrs,
137- TSS_VALIDATION *validationData)
138-{
134+ TSS_VALIDATION *validationData) {
139135 /* dummy */
140136 return TSS_SUCCESS;
141137 }
@@ -148,8 +144,7 @@ int quote2Tss(
148144 int auth_type,
149145 BYTE *nonce,
150146 OPENPTS_PCRS *pcrs,
151- TSS_VALIDATION *validationData)
152-{
147+ TSS_VALIDATION *validationData) {
153148 /* dummy */
154149 return TSS_SUCCESS;
155150 }
@@ -267,6 +262,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) {
267262
268263 close:
269264 /* Close TSS/TPM */
265+ Tspi_Context_FreeMemory(hContext, NULL);
270266 Tspi_Context_Close(hContext);
271267 return result;
272268 }
@@ -358,6 +354,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) {
358354
359355 close:
360356 /* Close TSS/TPM */
357+ Tspi_Context_FreeMemory(hContext, NULL);
361358 Tspi_Context_Close(hContext);
362359 return result;
363360 }
@@ -374,7 +371,8 @@ int printTssKeyList(int ps_type) {
374371 UINT32 ulKeyHierarchySize;
375372 TSS_UUID SRK_UUID = TSS_UUID_SRK;
376373 int i;
377- TSS_KM_KEYINFO *info = NULL;
374+ TSS_KM_KEYINFO *ppKeyHierarchy = NULL;
375+ TSS_KM_KEYINFO *info;
378376
379377 /* Open TSS */
380378 result = Tspi_Context_Create(&hContext);
@@ -400,7 +398,7 @@ int printTssKeyList(int ps_type) {
400398 (UINT32) ps_type, // TSS_PS_TYPE_SYSTEM,
401399 &SRK_UUID,
402400 &ulKeyHierarchySize,
403- &info);
401+ &ppKeyHierarchy);
404402 if (result == 0x3020) { // TSS_E_PS_KEY_NOTFOUND
405403 OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY_NOTFOUND,
406404 "The key cannot be found in the persistent storage database.\n"));
@@ -411,9 +409,9 @@ int printTssKeyList(int ps_type) {
411409 goto close;
412410 }
413411
412+ info = ppKeyHierarchy; // save for move
414413 OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY_NUM, "Key number: %d\n"), ulKeyHierarchySize);
415414 for (i = 0; i < (int)ulKeyHierarchySize; i++) {
416- //OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY, "Key %d\n"), i);
417415 OUTPUT("id : %d\n", i);
418416 OUTPUT("version : %d %d %d %d\n",
419417 info->versionInfo.bMajor,
@@ -435,8 +433,17 @@ int printTssKeyList(int ps_type) {
435433 info = info + 1;
436434 }
437435
436+ /* free key info */
437+ result = Tspi_Context_FreeMemory(hContext, (BYTE *)ppKeyHierarchy);
438+ if (result != TSS_SUCCESS) {
439+ LOG(LOG_ERR, "Tspi_Context_FreeMemory failed rc=0x%x\n",
440+ result);
441+ // 0x313a TSS_E_INVALID_RESOURCE
442+ }
443+
438444 close:
439445 /* Close TSS/TPM */
446+ Tspi_Context_FreeMemory(hContext, NULL);
440447 Tspi_Context_Close(hContext);
441448
442449 return result;
@@ -459,8 +466,9 @@ int createTssSignKey(
459466 char *filename,
460467 int auth_type,
461468 int force,
462- int srk_password_mode)
463-{
469+ int srk_password_mode) {
470+ int i;
471+ int srk_auth_len = 0;
464472 TSS_RESULT result = 0;
465473 TSS_HCONTEXT hContext;
466474 TSS_HTPM hTPM;
@@ -469,12 +477,10 @@ int createTssSignKey(
469477 TSS_HPOLICY hSRKPolicy;
470478 UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN;
471479 BYTE *srk_auth;
472- int srk_auth_len = 0;
473480 TSS_HKEY hKey;
474481 UINT32 keyLength;
475482 BYTE *keyBlob;
476483 TSS_HPOLICY hKeyPolicy;
477- int i;
478484 TSS_UUID tss_uuid;
479485
480486 /* check */
@@ -646,8 +652,8 @@ int createTssSignKey(
646652 FILE *fp;
647653
648654 fp = fopen(filename, "w");
649- if (fp==NULL) {
650- LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
655+ if (fp == NULL) {
656+ LOG(LOG_ERR, "file open fail, key blob file is %s", filename);
651657 result = TSS_E_KEY_NOT_LOADED;
652658 goto close;
653659 }
@@ -690,7 +696,7 @@ int createTssSignKey(
690696 TSS_HKEY hKey;
691697 result = Tspi_Context_UnregisterKey(
692698 hContext,
693- (UINT32)key_storage_type, //TSS_PS_TYPE_SYSTEM,
699+ (UINT32)key_storage_type, // TSS_PS_TYPE_SYSTEM,
694700 tss_uuid,
695701 &hKey);
696702 if (result != TSS_SUCCESS) {
@@ -718,6 +724,7 @@ int createTssSignKey(
718724
719725 close:
720726 /* Close TSS/TPM */
727+ Tspi_Context_FreeMemory(hContext, NULL);
721728 Tspi_Context_Close(hContext);
722729
723730 return result;
@@ -802,6 +809,7 @@ int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) {
802809
803810 close:
804811 /* Close TSS/TPM */
812+ Tspi_Context_FreeMemory(hContext, NULL);
805813 Tspi_Context_Close(hContext);
806814
807815 return result;
@@ -823,8 +831,8 @@ int getTssPubKey(
823831 int resetdalock,
824832 char *filename,
825833 int auth_type,
826- int *pubkey_length, BYTE **pubkey)
827-{
834+ int *pubkey_length, BYTE **pubkey) {
835+ int srk_auth_len = 0;
828836 TSS_RESULT result = 0;
829837 TSS_HCONTEXT hContext;
830838 TSS_HKEY hKey;
@@ -835,7 +843,6 @@ int getTssPubKey(
835843 TSS_UUID SRK_UUID = TSS_UUID_SRK;
836844 UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN;
837845 BYTE *srk_auth;
838- int srk_auth_len = 0;
839846 TSS_HPOLICY hKeyPolicy;
840847
841848 /* check */
@@ -938,8 +945,8 @@ int getTssPubKey(
938945 int len;
939946
940947 fp = fopen(filename, "r");
941- if (fp==NULL) {
942- LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
948+ if (fp == NULL) {
949+ LOG(LOG_ERR, "file open fail, key blob file is %s", filename);
943950 result = TSS_E_KEY_NOT_LOADED;
944951 goto close;
945952 }
@@ -962,7 +969,7 @@ int getTssPubKey(
962969 /* TSS PS*/
963970 result = Tspi_Context_LoadKeyByUUID(
964971 hContext,
965- (UINT32)key_storage_type, //TSS_PS_TYPE_SYSTEM,
972+ (UINT32)key_storage_type, // TSS_PS_TYPE_SYSTEM,
966973 tss_uuid,
967974 &hKey);
968975 if (result == 0x803) {
@@ -1127,6 +1134,7 @@ int getTpmVersion(TSS_VERSION *version) {
11271134
11281135 /* Close TSS/TPM */
11291136 close:
1137+ Tspi_Context_FreeMemory(hContext, NULL);
11301138 Tspi_Context_Close(hContext);
11311139
11321140 return rc;
@@ -1150,6 +1158,9 @@ int quoteTss(
11501158 OPENPTS_PCRS *pcrs,
11511159 /* Output */
11521160 TSS_VALIDATION *validationData) {
1161+ int i;
1162+ int srk_auth_len = 0;
1163+ int pcrSelectCount = 0;
11531164 TSS_RESULT result;
11541165 TSS_HCONTEXT hContext;
11551166 TSS_HTPM hTPM;
@@ -1158,22 +1169,17 @@ int quoteTss(
11581169 TSS_UUID SRK_UUID = TSS_UUID_SRK;
11591170 UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN;
11601171 BYTE *srk_auth = NULL;
1161- int srk_auth_len = 0;
1162-
11631172 TSS_HKEY hKey;
11641173 TSS_HPOLICY hKeyPolicy;
11651174 TSS_UUID tss_uuid;
11661175 TSS_HPCRS hPcrComposite;
11671176 TSS_VALIDATION validation_data; // local
1168- int i;
11691177 UINT32 ulSubCapLength;
11701178 UINT32 rgbSubCap;
11711179 UINT32 pulRespDataLength;
11721180 BYTE *prgbRespData;
11731181 UINT32 pcrnum;
11741182
1175- int pcrSelectCount = 0;
1176-
11771183 /* UUID */
11781184 memcpy(&tss_uuid, uuid, sizeof(TSS_UUID));
11791185
@@ -1319,8 +1325,8 @@ int quoteTss(
13191325 int len;
13201326
13211327 fp = fopen(filename, "r");
1322- if (fp==NULL) {
1323- LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
1328+ if (fp == NULL) {
1329+ LOG(LOG_ERR, "file open fail, key blob file is %s", filename);
13241330 result = TSS_E_KEY_NOT_LOADED;
13251331 goto close;
13261332 }
@@ -1545,36 +1551,31 @@ int quote2Tss(
15451551 /* PCR selection */
15461552 OPENPTS_PCRS *pcrs,
15471553 /* Output */
1548- TSS_VALIDATION *validationData)
1549-{
1554+ TSS_VALIDATION *validationData) {
1555+ int i;
1556+ int srk_auth_len = 0;
1557+ int pcrSelectCount = 0;
15501558 TSS_RESULT result;
15511559 TSS_HCONTEXT hContext;
15521560 TSS_HTPM hTPM;
15531561 TSS_HKEY hSRK;
15541562 TSS_HPOLICY hSRKPolicy;
15551563 TSS_UUID SRK_UUID = TSS_UUID_SRK;
1556-
15571564 UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN;
15581565 BYTE *srk_auth;
1559- int srk_auth_len = 0;
1560-
15611566 TSS_HKEY hKey;
15621567 TSS_HPOLICY hKeyPolicy;
15631568 TSS_UUID tss_uuid;
15641569 TSS_HPCRS hPcrComposite;
15651570 TSS_VALIDATION validation_data; // local
1566- int i;
15671571 UINT32 ulSubCapLength;
15681572 UINT32 rgbSubCap;
15691573 UINT32 pulRespDataLength;
15701574 BYTE *prgbRespData;
15711575 UINT32 pcrnum;
1572-
15731576 UINT32 versionInfoSize;
15741577 BYTE* versionInfo;
15751578
1576- int pcrSelectCount = 0;
1577-
15781579 /* UUID */
15791580 // uuit_t -> TSS_UUID
15801581 memcpy(&tss_uuid, uuid, sizeof(TSS_UUID));
@@ -1664,7 +1665,7 @@ int quote2Tss(
16641665 /* Get SRK handles */
16651666 result = Tspi_Context_LoadKeyByUUID(
16661667 hContext,
1667- TSS_PS_TYPE_SYSTEM, // SRK in PS_SYSTEM
1668+ TSS_PS_TYPE_SYSTEM, // SRK in PS_SYSTEM
16681669 SRK_UUID,
16691670 &hSRK);
16701671 if (result != TSS_SUCCESS) {
@@ -1722,8 +1723,8 @@ int quote2Tss(
17221723 int len;
17231724
17241725 fp = fopen(filename, "r");
1725- if (fp==NULL) {
1726- LOG(LOG_ERR, "file open fail, key blob file is %s",filename);
1726+ if (fp == NULL) {
1727+ LOG(LOG_ERR, "file open fail, key blob file is %s", filename);
17271728 result = TSS_E_KEY_NOT_LOADED;
17281729 goto close;
17291730 }
@@ -1748,7 +1749,7 @@ int quote2Tss(
17481749 /* load from TSS's PS */
17491750 result = Tspi_Context_LoadKeyByUUID(
17501751 hContext,
1751- key_storage_type, // TSS_PS_TYPE_SYSTEM,
1752+ key_storage_type, // TSS_PS_TYPE_SYSTEM,
17521753 tss_uuid,
17531754 &hKey);
17541755 if (result != TSS_SUCCESS) {
@@ -2084,6 +2085,7 @@ int extendEvent(TSS_PCR_EVENT* event) {
20842085
20852086 close:
20862087 /* Close TSS/TPM */
2088+ Tspi_Context_FreeMemory(hContext, NULL);
20872089 Tspi_Context_Close(hContext);
20882090 return result;
20892091 }
@@ -2138,6 +2140,7 @@ int readPcr(int pcr_index, BYTE *pcr) {
21382140
21392141 close:
21402142 /* Close TSS/TPM */
2143+ Tspi_Context_FreeMemory(hContext, NULL);
21412144 Tspi_Context_Close(hContext);
21422145 return result;
21432146 }
@@ -2163,8 +2166,7 @@ int readPcr(int pcr_index, BYTE *pcr) {
21632166 */
21642167 int validateQuoteData(
21652168 OPENPTS_PCRS *pcrs,
2166- TSS_VALIDATION *validationData)
2167-{
2169+ TSS_VALIDATION *validationData) {
21682170 int rc = PTS_VERIFY_FAILED;
21692171 int message_length;
21702172 BYTE *message;
@@ -2331,18 +2333,17 @@ int validateQuoteData(
23312333 */
23322334 int validatePcrCompositeV11(
23332335 OPENPTS_PCRS *pcrs,
2334- TSS_VALIDATION *validationData)
2335-{
2336+ TSS_VALIDATION *validationData) {
23362337 int rc = PTS_VERIFY_FAILED;
23372338 int i;
23382339 int buf_len;
2340+ int count = 0;
2341+ int value_size;
23392342 BYTE *buf;
23402343 BYTE *ptr;
23412344 SHA_CTX ctx;
23422345 BYTE digest[20];
23432346 UINT16 mask = 0;
2344- int count = 0;
2345- int value_size;
23462347
23472348 /* check */
23482349 if (validationData == NULL) {
@@ -2463,20 +2464,19 @@ int validatePcrCompositeV11(
24632464 */
24642465 int validatePcrCompositeV12(
24652466 OPENPTS_PCRS *pcrs,
2466- TSS_VALIDATION *validationData)
2467-{
2467+ TSS_VALIDATION *validationData) {
24682468 int rc = PTS_VERIFY_FAILED;
24692469 int i;
24702470 int buf_len;
2471+ int count = 0;
2472+ int value_size;
2473+ int pcrsel_size;
2474+ int loc = 0;
24712475 BYTE *buf;
24722476 BYTE *ptr;
24732477 SHA_CTX ctx;
24742478 BYTE digest[20];
24752479 UINT32 mask = 0;
2476- int count = 0;
2477- int value_size;
2478- int pcrsel_size;
2479- int loc = 0;
24802480 BYTE *composit_hash;
24812481
24822482 /* check */
@@ -2607,5 +2607,3 @@ int validatePcrCompositeV12(
26072607
26082608 return rc;
26092609 }
2610-
2611-
--- a/src/uml.c
+++ b/src/uml.c
@@ -26,7 +26,7 @@
2626 * \brief UML2 State Diagram
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29- * cleanup 2011-01-21 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * UML State Diagram (XMI2.1, Eclipse MDT) -> DOT (Graphviz) Utility
3232 */
@@ -47,10 +47,8 @@
4747 #include <tss/tspi.h>
4848
4949 #include <openpts.h>
50-// #include <log.h>
5150
5251 /*
53-
5452 UML
5553 <subvertex xmi:type="uml:State" xmi:id="Kk02PKa3" name="CRTM_START" visibility="public">
5654 <doActivity xmi:type="uml:Activity" xmi:id="_OzCawRyrEd6jytZ7WXwL3w" name="resetPCR(0)"/>
@@ -82,11 +80,16 @@ DOT
8280 /**
8381 * startDocument of SAX parser
8482 */
85-void uml2sax_startDocument(void * fctx) {
83+void uml2sax_startDocument(void * fctx) {
8684 OPENPTS_FSM_CONTEXT *ctx;
8785
8886 DEBUG_CAL("startDocument - start\n");
8987
88+ /* check */
89+ if (fctx == NULL) {
90+ LOG(LOG_ERR, "null input");
91+ return;
92+ }
9093 ctx = (OPENPTS_FSM_CONTEXT *)fctx;
9194 ctx->error = 0;
9295
@@ -99,9 +102,14 @@ void uml2sax_startDocument(void * fctx) {
99102 /**
100103 * endDocument of SAX parser
101104 */
102-void uml2sax_endDocument(void * fctx) {
105+void uml2sax_endDocument(void * fctx) {
103106 OPENPTS_FSM_CONTEXT *ctx;
104107
108+ /* check */
109+ if (fctx == NULL) {
110+ LOG(LOG_ERR, "null input");
111+ return;
112+ }
105113 ctx = (OPENPTS_FSM_CONTEXT *)fctx;
106114
107115 /* set start state */
@@ -127,14 +135,23 @@ char doActivityName[FSM_BUF_SIZE]; /**< move to ctx */
127135 /**
128136 * startElement of SAX parser
129137 */
130-void uml2sax_startElement(void* fctx, const xmlChar* name,
138+void uml2sax_startElement(void* fctx, const xmlChar* name,
131139 const xmlChar** atts) {
132140 OPENPTS_FSM_CONTEXT *ctx;
133141 int i;
134142 char *type;
135143 char *value;
136144
145+ /* check */
146+ if (fctx == NULL) {
147+ LOG(LOG_ERR, "null input");
148+ return;
149+ }
137150 ctx = (OPENPTS_FSM_CONTEXT *)fctx;
151+ if (name == NULL) {
152+ LOG(LOG_ERR, "null input");
153+ return;
154+ }
138155
139156 // DEBUG_SAX("startElement - \n");
140157
@@ -240,7 +257,16 @@ void uml2sax_startElement(void* fctx, const xmlChar* name,
240257 void uml2sax_endElement(void * fctx, const xmlChar * name) {
241258 OPENPTS_FSM_CONTEXT *ctx;
242259
260+ /* check */
261+ if (fctx == NULL) {
262+ LOG(LOG_ERR, "null input");
263+ return;
264+ }
243265 ctx = (OPENPTS_FSM_CONTEXT *)fctx;
266+ if (name == NULL) {
267+ LOG(LOG_ERR, "null input");
268+ return;
269+ }
244270
245271 if (!strcmp((char *)name, "subvertex")) {
246272 addFsmSubvertex(ctx, subvertexXmiType, subvertexXmiId, subvertexName, doActivityName);
@@ -268,7 +294,16 @@ void uml2sax_characters(void* fctx, const xmlChar * ch, int len) {
268294 OPENPTS_FSM_CONTEXT *ctx;
269295 char buf[FSM_BUF_SIZE];
270296
297+ /* check */
298+ if (fctx == NULL) {
299+ LOG(LOG_ERR, "null input");
300+ return;
301+ }
271302 ctx = (OPENPTS_FSM_CONTEXT *)fctx;
303+ if ((len > 0) && (ch == NULL)) {
304+ LOG(LOG_ERR, "null input");
305+ return;
306+ }
272307
273308 if (len < FSM_BUF_SIZE) {
274309 memcpy(buf, ch, len);
@@ -300,15 +335,23 @@ int readUmlModel(OPENPTS_FSM_CONTEXT * ctx, char *umlfile) {
300335 xmlSAXHandler sax_handler;
301336 int rc;
302337
338+ /* check */
339+ if (ctx == NULL) {
340+ LOG(LOG_ERR, "null input");
341+ return PTS_FATAL;
342+ }
343+ if (umlfile == NULL) {
344+ LOG(LOG_ERR, "null input");
345+ return PTS_FATAL;
346+ }
347+
303348 memset(&sax_handler, 0, sizeof(xmlSAXHandler));
304349
305350 sax_handler.startDocument = uml2sax_startDocument;
306- sax_handler.endDocument = uml2sax_endDocument;
307-
308- sax_handler.startElement = uml2sax_startElement;
309- sax_handler.endElement = uml2sax_endElement;
310-
311- sax_handler.characters = uml2sax_characters;
351+ sax_handler.endDocument = uml2sax_endDocument;
352+ sax_handler.startElement = uml2sax_startElement;
353+ sax_handler.endElement = uml2sax_endElement;
354+ sax_handler.characters = uml2sax_characters;
312355
313356 /* read UML */
314357
--- a/src/uml2dot.c
+++ b/src/uml2dot.c
@@ -26,6 +26,7 @@
2626 * \brief Utility, generate dot file from UML2 state siagram
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-01
29+ * cleanup 2012-01-05 SM
2930 *
3031 * UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc)
3132 *
@@ -44,17 +45,16 @@
4445 #include <fcntl.h>
4546
4647 #include <openpts.h>
47-// #include <log.h>
4848
4949 /**
5050 * usage
5151 */
5252 void usage(void) {
5353 OUTPUT(NLS(MS_OPENPTS, OPENPTS_UML2DOT_USAGE,
54- "usage: uml2dot [options] UMLfile \n"
55- "\t-o output\tset output file (default is stdout)\n"
56- "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
57- "\n"));
54+ "usage: uml2dot [options] UMLfile \n"
55+ "\t-o output\tset output file (default is stdout)\n"
56+ "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
57+ "\n"));
5858 }
5959
6060 /**
@@ -67,6 +67,7 @@ int main(int argc, char *argv[]) {
6767 char *input_filename = NULL;
6868 char *output_filename = NULL;
6969
70+ /* logging/NLS */
7071 initCatalog();
7172
7273 while ((c = getopt(argc, argv, "do:h")) != EOF) {
@@ -89,7 +90,6 @@ int main(int argc, char *argv[]) {
8990 input_filename = argv[0];
9091
9192 /* Read UML(XML) file */
92-
9393 if (input_filename == NULL) {
9494 ERROR(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
9595 usage();
@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
114114 }
115115
116116 error:
117-
118117 freeFsmContext(ctx);
119118
120119 return rc;
--- a/src/uuid.c
+++ b/src/uuid.c
@@ -26,7 +26,7 @@
2626 * \brief UUID wrapper (Generic part, OPENPTS_UUID)
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-11-29
29- * cleanup 2011-10-07 SM
29+ * cleanup 2012-01-05 SM
3030 *
3131 * Linux uses libuuid
3232 *
--- a/src/uuid_libc.c
+++ b/src/uuid_libc.c
@@ -50,9 +50,6 @@ void uuid_from_string(unsigned_char_t *string_uuid, uuid_t *uuid,
5050 #endif
5151
5252 #include <openpts.h>
53-#include <log.h>
54-
55-
5653
5754 #if UUIDSIZE < 16
5855 #error Insufficient space in PTS_UUID
@@ -218,5 +215,3 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) {
218215
219216 return pdt;
220217 }
221-
222-
--- a/src/verifier.c
+++ b/src/verifier.c
@@ -26,7 +26,7 @@
2626 * \brief TCG IF-M Verifier
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-04-06
29- * cleanup 2011-07-20 SM
29+ * cleanup 2012-01-04 SM
3030 *
3131 */
3232
@@ -50,7 +50,6 @@
5050
5151 #include <openpts.h>
5252
53-
5453 /**
5554 * Lock (POSIX 1003.1)
5655 * type:
@@ -85,17 +84,16 @@ void global_lock(int type) {
8584 exit(1);
8685 }
8786
88- fl.l_start = 0;
89- fl.l_len = 0;
87+ fl.l_start = 0;
88+ fl.l_len = 0;
9089 fl.l_whence = SEEK_SET;
91- fl.l_type = type;
92- fl.l_pid = getpid();
93- //if (fcntl(fd, F_SETLKW, &fl) < 0) {
90+ fl.l_type = type;
91+ fl.l_pid = getpid();
9492 if (fcntl(fd, F_SETLK, &fl) < 0) {
9593 // get PID of the process holding that lock
9694 fcntl(fd, F_GETLK, &fl);
97- ERROR( // TODO NLS
98- "Openpts configulation is locked by other(pid=%d)\n", fl.l_pid);
95+ ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_LOCKED,
96+ "Openpts configulation is locked by other(pid=%d)\n"), fl.l_pid);
9997 exit(1);
10098 }
10199 }
@@ -138,7 +136,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
138136 rc = mkdir(dirpath, S_IRUSR | S_IWUSR | S_IXUSR);
139137 if (rc != 0) {
140138 LOG(LOG_ERR, "mkdir on %s failed (errno=%d)", dirpath, errno);
141- rc=PTS_FATAL;
139+ rc = PTS_FATAL;
142140 goto error;
143141 }
144142 configDirExists = 1;
@@ -156,7 +154,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
156154 rc = writeOpenptsUuidFile(conf->uuid, 1);
157155 if (rc != PTS_SUCCESS) {
158156 LOG(LOG_ERR, "Can't create UUID file, %s", uuid_file);
159- rc=PTS_FATAL;
157+ rc = PTS_FATAL;
160158 goto error;
161159 }
162160
@@ -164,7 +162,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) {
164162 rc = writeOpenptsConf(conf, conf_file);
165163 if (rc != PTS_SUCCESS) {
166164 LOG(LOG_ERR, "Can't create config file, %s", conf_file);
167- rc=PTS_FATAL;
165+ rc = PTS_FATAL;
168166 goto error;
169167 }
170168 }
@@ -574,8 +572,8 @@ int verifierHandleCapability(
574572 */
575573 int verifierHandleRimmSet(
576574 OPENPTS_CONTEXT *ctx,
577- BYTE *value)
578-{
575+ BYTE *value) {
576+
579577 int rc = PTS_SUCCESS;
580578 OPENPTS_CONFIG *target_conf;
581579 int i;
@@ -716,8 +714,7 @@ int writePolicyConf(OPENPTS_CONTEXT *ctx, char *filename) {
716714 } else if (!strncmp(prop->name, "disable.", 8)) {
717715 /* Indicates a disabled tpm quote - SKIP */
718716 } else if (prop->ignore == 1) {
719- ERROR( // TODO NLS
720- "The property %s is conflicted and excluded from the policy.\n", prop->name);
717+ DEBUG("The property %s is conflicted and excluded from the policy.\n", prop->name);
721718 } else {
722719 fprintf(fp, "%s=%s\n", prop->name, prop->value);
723720 i++;
@@ -1469,7 +1466,6 @@ int verifier(
14691466 rc = PTS_INTERNAL_ERROR;
14701467 goto close;
14711468 }
1472- // DEBUG("new read_tlv %p\n",read_tlv);
14731469
14741470 /* res -> fin */
14751471 ctx->nonce->res->reserved[0] = read_tlv->value[0];
Show on old repository browser