OSDN Git Service

add missing free, and cleanup
authorSeiji Munetoh <munetoh@jp.ibm.com>
Mon, 22 Aug 2011 07:06:13 +0000 (16:06 +0900)
committerSeiji Munetoh <munetoh@jp.ibm.com>
Mon, 22 Aug 2011 07:06:13 +0000 (16:06 +0900)
src/imc.c
src/imv.c

index 6b5572c..c00a955 100644 (file)
--- a/src/imc.c
+++ b/src/imc.c
@@ -26,7 +26,7 @@
  * \brief TCG TNC IF-IMC v1.2 R8
  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
  * @date 2010-05-07
- * cleanup 2011-07-06 SM
+ * cleanup 2011-08-22 SM
  *
  * http://www.trustedcomputinggroup.org/resources/tnc_ifimc_specification
  * http://www.trustedcomputinggroup.org/files/resource_files/8CB977E1-1D09-3519-AD48484530EF6639/TNC_IFIMC_v1_2_r8.pdf
@@ -74,20 +74,18 @@ static TNC_TNCC_SendMessagePointer           sendMessagePtr;
 static OPENPTS_CONFIG *conf = NULL;
 static OPENPTS_CONTEXT *ctx = NULL;
 
-// static char *config_filename = NULL;
-
 int verbose = 0;
 // int verbose = DEBUG_IFM_FLAG;
 // int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG;
 
-#if 1
+
 static TNC_Result sendMessage(
     /*in*/ TNC_IMCID imcID,
     /*in*/ TNC_ConnectionID connectionID,
     /*in*/ TNC_BufferReference message,
     /*in*/ TNC_UInt32 messageLength,
     /*in*/ TNC_MessageType messageType);
-#endif
+
 
 /* List of receive message types */
 static TNC_MessageType messageTypes[] = {
@@ -131,12 +129,13 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
     /* initialize PTS Collector */
     conf = newPtsConfig();
     if (conf == NULL) {
-        ERROR("no memory\n");
+        ERROR("Can not allocate OPENPTS_CONFIG\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
     ctx =  newPtsContext(conf);
     if (ctx == NULL) {
+        ERROR("Can not allocate OPENPTS_CONTEXT\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
@@ -172,7 +171,7 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
     rc = readOpenptsUuidFile(conf->newrm_uuid);
     if (rc != PTS_SUCCESS) {
         DEBUG("conf->str_newrm_uuid      : missing (file:%s)\n", conf->newrm_uuid->filename);
-        // goto free;
+        // May not exist
     } else {
         DEBUG("conf->str_newrm_uuid      : %s (for next boot)\n", conf->newrm_uuid->str);
     }
@@ -203,6 +202,8 @@ TNC_IMC_API TNC_Result TNC_IMC_Initialize(
   error:
     if (ctx != NULL) freePtsContext(ctx);
     ctx = NULL;
+    if (conf != NULL) freePtsConfig(conf);
+    conf = NULL;
 
     return rc;
 }
@@ -216,7 +217,7 @@ TNC_IMC_API TNC_Result TNC_IMC_NotifyConnectionChange(
 /*in*/  TNC_IMCID imcID,
 /*in*/  TNC_ConnectionID connectionID,
 /*in*/  TNC_ConnectionState newState) {
-    DEBUG("TNC_IMC_Initialize\n");
+    DEBUG("TNC_IMC_NotifyConnectionChange\n");
 
     /* check internal status */
     if (!initialized)
@@ -257,11 +258,7 @@ TNC_IMC_API TNC_Result TNC_IMC_BeginHandshake(
     /* connection ID */
     cid = connectionID;
 
-    /* just send hello to verifier */
-
-    // DEBUG_IFM("C    imcID=%d, connectionID=%d - TNC_IMC_BeginHandshake\n", (int)imcID, (int)connectionID);
-
-
+    /* just send OPENPTS_CAPABILITIES to verifier */
     msg = getPtsTlvMessage(ctx, OPENPTS_CAPABILITIES, &len);
 
     DEBUG_IFM("[C->V] OPENPTS_CAPABILITIES[%d]\n", len);
@@ -417,106 +414,6 @@ TNC_IMC_API TNC_Result TNC_IMC_ReceiveMessage(
         return TNC_RESULT_FATAL;
     }
 
-
-
-
-
-#if 0
-    if (messageType == TNCMESSAGENUM(VENDORID, 1)) {
-        /* capability from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != OPENPTS_CAPABILITIES) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send PTS_CAPABILITIES  */
-        char* msg = getPtsTlvMessage(ctx, OPENPTS_CAPABILITIES, &len);
-        rc = sendMessage(imcID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 2));
-        free(msg);
-        DEBUG_IFM("Collector send PTS_CAPABILITIES len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 3)) {
-        /* DH_NONCE_PARAMETERS_REQUEST from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != DH_NONCE_PARAMETERS_REQUEST) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send DH_NONCE_PARAMETORS_RESPONSE  */
-        char* msg = getPtsTlvMessage(ctx, DH_NONCE_PARAMETORS_RESPONSE, &len);
-        rc = sendMessage(imcID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 4));
-        free(msg);
-        DEBUG_IFM("Collector send PTS_CAPABILITIES len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 5)) {
-        /* DH_NONCE_FINISH from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != DH_NONCE_FINISH) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-        /* ack to keep TNC handshake  */
-        // TODO(munetoh) otherwise TNC HS was terminated.
-        char* msg = "ack";
-        rc = sendMessage(imcID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            strlen(msg),
-                            TNCMESSAGENUM(VENDORID, 6));
-        DEBUG_IFM("Collector send PTS_CAPABILITIES len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 7)) {
-        /* REQUEST_TEMPLATE_RIMM_SET_METADATA from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != REQUEST_RIMM_SET) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send DH_NONCE_PARAMETORS_RESPONSE  */
-        char* msg = getPtsTlvMessage(ctx, RIMM_SET, &len);
-        rc = sendMessage(imcID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 8));
-        free(msg);
-        DEBUG_IFM("Collector send TEMPLATE_RIMM_SET_METADATA len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 9)) {
-        /* REQUEST_TEMPLATE_RIMM_SET_METADATA from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != REQUEST_INTEGRITY_REPORT) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send DH_NONCE_PARAMETORS_RESPONSE  */
-        char* msg = getPtsTlvMessage(ctx, INTEGRITY_REPORT, &len);
-        rc = sendMessage(imcID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 10));
-        // free(msg);
-        DEBUG_IFM("Collector send INTEGRITY_REPORT len=%d\n", len);
-        return rc;
-    } else {
-        ERROR("bad msg from verifier\n");
-        return TNC_RESULT_FATAL;
-    }
-#endif
-
     return TNC_RESULT_SUCCESS;
 }
 
@@ -563,7 +460,7 @@ TNC_IMC_API TNC_Result TNC_IMC_Terminate(
     /* connection ID */
     // TODO(munetoh)
 
-    /* PTS */
+    /* Free PTS contexts */
     freePtsContext(ctx);
     freePtsConfig(conf);
 
@@ -709,8 +606,3 @@ TNC_IMC_API TNC_Result TNC_IMC_ProvideBindFunction(
 
     return rc;
 }
-
-
-
-
-
index 8211327..ef4afa9 100644 (file)
--- a/src/imv.c
+++ b/src/imv.c
@@ -26,7 +26,7 @@
  * \brief TCG TNC IF-IMV v1.2 R8
  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
  * @date 2010-05-07
- * cleanup 2011-07-06 SM
+ * cleanup 2011-08-22 SM
  *
  * http://www.trustedcomputinggroup.org/resources/tnc_ifimv_specification
  * http://www.trustedcomputinggroup.org/files/static_page_files/646808C3-1D09-3519-AD2E60765779A42A/TNC_IFIMV_v1_2_r8.pdf
 #include <string.h>
 
 #include <tncifimv.h>
-// #include <libtnc.h>
 
 #include <openpts.h>
 
-
 // ifm.c
 BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len);
 
-
 /* global */
-
 static TNC_IMVID imv_id = -1;
 static int initialized = 0;
 
@@ -72,19 +68,19 @@ int verbose = 0;
 // int verbose = DEBUG_IFM_FLAG;
 // int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG;
 
-#if 1
 static TNC_Result sendMessage(
     /*in*/ TNC_IMVID imvID,
     /*in*/ TNC_ConnectionID connectionID,
     /*in*/ TNC_BufferReference message,
     /*in*/ TNC_UInt32 messageLength,
     /*in*/ TNC_MessageType messageType);
-#endif
+
 static TNC_Result provideRecommendation(
     /*in*/ TNC_IMVID imvID,
     /*in*/ TNC_ConnectionID connectionID,
     /*in*/ TNC_IMV_Action_Recommendation recommendation,
     /*in*/ TNC_IMV_Evaluation_Result evaluation);
+
 static TNC_Result setAttribute(
     /*in*/ TNC_IMVID imvID,
     /*in*/ TNC_ConnectionID connectionID,
@@ -174,18 +170,17 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
     *pOutActualVersion = TNC_IFIMV_VERSION_1;
     imv_id = imvID;
 
-
     /* initialize PTS */
     conf =  newPtsConfig();
     if (conf == NULL) {
-        ERROR("no memory\n");
+        ERROR("Can not allocate OPENPTS_CONFIG\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
 
     ctx =  newPtsContext(conf);
     if (ctx == NULL) {
-        ERROR("no memory\n");
+        ERROR("Can not allocate OPENPTS_CONTEXT\n");
         rc = TNC_RESULT_FATAL;
         goto error;
     }
@@ -233,8 +228,7 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
     DEBUG_IFM("conf->config_dir            : %s\n",
         conf->config_dir);
 
-
-    // IIDB  -- TODO
+    // TODO IIDB
 
     initialized++;
 
@@ -245,11 +239,13 @@ TNC_IMV_API TNC_Result TNC_IMV_Initialize(
   error:
     if (ctx != NULL) freePtsContext(ctx);
     ctx = NULL;
-    // TODO conf = NULL;
+    if (conf != NULL) freePtsConfig(conf);
+    conf = NULL;
 
     return rc;
 }
 
+
 /**
  * TNC_IMV_NotifyConnectionChange (OPTIONAL)
  */
@@ -398,7 +394,6 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             return TNC_RESULT_FATAL;
         }
 
-
         DEBUG_IFM("[C->V] vid=%X, type=%08X, length=%d\n", vid, type, length);
 
         /* message type */
@@ -416,7 +411,6 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
             /* Capability */
             cap =  (OPENPTS_IF_M_Capability *) value;
 
-
             rc = verifierHandleCapability(ctx, conf->config_dir, NULL, cap);
 
             if (rc == PTS_NOT_INITIALIZED) {
@@ -684,113 +678,10 @@ TNC_IMV_API TNC_Result TNC_IMV_ReceiveMessage(
         return TNC_RESULT_FATAL;
     }
 
-#if 0
-        /* capability from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != OPENPTS_CAPABILITIES) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send DH-nonce param req */
-        char* msg = getPtsTlvMessage(ctx, DH_NONCE_PARAMETERS_REQUEST, &len);
-        rc = sendMessage(imvID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 3));
-        free(msg);
-        DEBUG_IFM("Verifier send DH_NONCE_PARAMETERS_REQUEST len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 4)) {
-        /* DH-nonce param res from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != DH_NONCE_PARAMETORS_RESPONSE) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* send DH-nonce param done */
-        char* msg = getPtsTlvMessage(ctx, DH_NONCE_FINISH, &len);
-        rc = sendMessage(imvID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 5));
-        free(msg);
-        DEBUG_IFM("Verifier send DH_NONCE_FINISH len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 6)) {
-        /* send template RIMM req */
-        char* msg = getPtsTlvMessage(ctx, REQUEST_RIMM_SET, &len);
-        rc = sendMessage(imvID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 7));
-        free(msg);
-        DEBUG_IFM("Verifier send REQUEST_TEMPLATE_RIMM_SET_METADATA len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 8)) {
-        /* RIMM from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != RIMM_SET) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* Save RIMM to where? */
-        // TODO(munetoh)
-
-        /* send IR req */
-        char* msg = getPtsTlvMessage(ctx, REQUEST_INTEGRITY_REPORT, &len);
-        rc = sendMessage(imvID,
-                            connectionID,
-                            (TNC_BufferReference)msg,
-                            len,
-                            TNCMESSAGENUM(VENDORID, 9));
-        free(msg);
-        DEBUG_IFM("Verifier send REQUEST_INTEGRITY_REPORT len=%d\n", len);
-        return rc;
-    } else if (messageType == TNCMESSAGENUM(VENDORID, 10)) {
-        /* IR from client  */
-        read_tlv = (PTS_IF_M_Attribute *) messageBuffer;
-        if (read_tlv->type != INTEGRITY_REPORT) {
-            ERROR("bad msg\n");
-            return TNC_RESULT_FATAL;
-        }
-
-        /* Save IR to where? */
-        // TODO(munetoh)
-
-        /* Validate IR */
-        // TODO(munetoh)
-
-        /* Recommendation */
-        setAttribute(imvID,
-                     connectionID,
-                     TNC_ATTRIBUTEID_REASON_LANGUAGE,
-                     2,
-                     (TNC_BufferReference)"en");
-
-        setAttribute(imvID,
-                     connectionID,
-                     TNC_ATTRIBUTEID_REASON_STRING,
-                     7,
-                     (TNC_BufferReference)"testing");  // TODO(munetoh)
-
-        rc = provideRecommendation(
-                    imvID,
-                    connectionID,
-                    TNC_IMV_ACTION_RECOMMENDATION_ISOLATE,
-                    TNC_IMV_EVALUATION_RESULT_NONCOMPLIANT_MAJOR);
-        return rc;
-#endif
-
-
     return TNC_RESULT_SUCCESS;
 }
 
+
 /**
  * from IMV spec.
  *
@@ -907,6 +798,7 @@ TNC_IMV_API TNC_Result TNC_IMV_SolicitRecommendation(
                 evaluation);
 }
 
+
 /**
  * from IMV spec.
  *
@@ -951,6 +843,7 @@ TNC_IMV_API TNC_Result TNC_IMV_BatchEnding(
     return TNC_RESULT_SUCCESS;
 }
 
+
 /**
  * TNC_IMV_Terminate (OPTIONAL)
  */
@@ -998,7 +891,7 @@ static TNC_Result reportMessageTypes(
     return (*reportMessageTypesPtr)(imvID, supportedTypes, typeCount);
 }
 
-#if 1
+
 /**
  * Call TNC_TNCS_SendMessage (MANDATORY) in the TNCS
  */
@@ -1026,7 +919,7 @@ static TNC_Result sendMessage(
                 messageLength,
                 messageType);
 }
-#endif
+
 
 #if 0
 // imv.c:343: error: ‘requestHandshakeRetry’ defined but not used
@@ -1048,6 +941,7 @@ static TNC_Result requestHandshakeRetry(
 }
 #endif
 
+
 /**
  * Call TNC_TNCS_ProvideRecommendation (MANDATORY) in the TNCS
  */
@@ -1071,6 +965,7 @@ static TNC_Result provideRecommendation(
                 evaluation);
 }
 
+
 #if 0
 // imv.c:381: error: ‘getAttribute’ defined but not used
 /**
@@ -1126,8 +1021,6 @@ static TNC_Result setAttribute(
 }
 
 
-
-
 /* Platform-Specific IMV Functions */
 
 /**
@@ -1198,4 +1091,3 @@ TNC_IMV_API TNC_Result TNC_IMV_ProvideBindFunction(
         return TNC_RESULT_FATAL;
     }
 }
-