libpts: Move settings to <ns>.plugins with fallback to libimcv
[strongswan.git] / src / libpts / plugins / imc_swid / imc_swid.c
index a90e5ad..d4aaeff 100644 (file)
@@ -16,8 +16,7 @@
 #include "imc_swid_state.h"
 
 #include "libpts.h"
 #include "imc_swid_state.h"
 
 #include "libpts.h"
-#include "swid/swid_tag.h"
-#include "swid/swid_tag_id.h"
+#include "swid/swid_inventory.h"
 #include "swid/swid_error.h"
 #include "tcg/swid/tcg_swid_attr_req.h"
 #include "tcg/swid/tcg_swid_attr_tag_inv.h"
 #include "swid/swid_error.h"
 #include "tcg/swid/tcg_swid_attr_req.h"
 #include "tcg/swid/tcg_swid_attr_tag_inv.h"
 #include <pen/pen.h>
 #include <utils/debug.h>
 
 #include <pen/pen.h>
 #include <utils/debug.h>
 
-static char strongswan_tag[] =
-       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
-       "<software_identification_tag "
-       "xmlns=\"http://standards.iso.org/iso/19770/-2/2009/schema.xsd\">\n"
-       "<entitlement_required_indicator>true</entitlement_required_indicator>\n"
-       "<product_title>strongSwan</product_title>\n"
-       "<product_version>\n"
-       "  <name>5.1.1dr1</name>\n"
-       "  <numeric>\n"
-       "    <major>5</major>\n"
-       "    <minor>1</minor>\n"
-       "    <build>1</build>\n"
-       "    <review>dr1</review>\n"
-       "  </numeric>\n"
-       "</product_version>\n"
-       "<software_creator>\n"
-       "  <name>strongSwan Project</name>\n"
-       "  <regid>regid.2004-03.org.strongswan</regid>\n"
-       "</software_creator>\n"
-       "<software_licensor>\n"
-       "  <name>strongSwan Project</name>\n"
-       "  <regid>regid.2004-03.org.strongswan</regid>\n"
-       "</software_licensor>\n"
-       "<software_id>\n"
-       "  <unique_id>strongSwan-5-1-1-dr1</unique_id>\n"
-       "  <tag_creator_regid>regid.2004-03.org.strongswan</tag_creator_regid>\n"
-       "</software_id>\n"
-       "<tag_creator>\n"
-       "  <name>strongSwan Project</name>\n"
-       "  <regid>regid.2004-03.org.strongswan</regid>\n"
-       "</tag_creator>\n"
-       "</software_identification_tag>\n";
 
 /* IMC definitions */
 
 
 /* IMC definitions */
 
@@ -187,6 +154,9 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
                tcg_swid_attr_req_t *attr_req;
                u_int8_t flags;
                u_int32_t request_id, eid_epoch;
                tcg_swid_attr_req_t *attr_req;
                u_int8_t flags;
                u_int32_t request_id, eid_epoch;
+               swid_inventory_t *swid_inventory, *targets;
+               char *swid_directory;
+               bool full_tags;
 
                type = attr->get_type(attr);
 
 
                type = attr->get_type(attr);
 
@@ -198,6 +168,7 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
                attr_req = (tcg_swid_attr_req_t*)attr;
                flags = attr_req->get_flags(attr_req);
                request_id = attr_req->get_request_id(attr_req);
                attr_req = (tcg_swid_attr_req_t*)attr;
                flags = attr_req->get_flags(attr_req);
                request_id = attr_req->get_request_id(attr_req);
+               targets = attr_req->get_targets(attr_req);
                eid_epoch = swid_state->get_eid_epoch(swid_state);
 
                if (flags & (TCG_SWID_ATTR_REQ_FLAG_S | TCG_SWID_ATTR_REQ_FLAG_C))
                eid_epoch = swid_state->get_eid_epoch(swid_state);
 
                if (flags & (TCG_SWID_ATTR_REQ_FLAG_S | TCG_SWID_ATTR_REQ_FLAG_C))
@@ -207,29 +178,33 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
                        out_msg->add_attribute(out_msg, attr);
                        break;
                }
                        out_msg->add_attribute(out_msg, attr);
                        break;
                }
+               full_tags = (flags & TCG_SWID_ATTR_REQ_FLAG_R) == 0;
 
 
-               if (flags & TCG_SWID_ATTR_REQ_FLAG_R)
+               swid_directory = lib->settings->get_str(lib->settings,
+                                                               "%s.plugins.imc-swid.swid_directory",
+                                                                SWID_DIRECTORY, lib->ns);
+               swid_inventory = swid_inventory_create(full_tags);
+               if (!swid_inventory->collect(swid_inventory, swid_directory, targets))
                {
                {
-                       swid_tag_id_t *tag_id;
-                       tcg_swid_attr_tag_id_inv_t *attr_cast;
-
-                       attr = tcg_swid_attr_tag_id_inv_create(request_id, eid_epoch, 1);
-                       attr_cast = (tcg_swid_attr_tag_id_inv_t*)attr;
-                       tag_id = swid_tag_id_create(
-                                               chunk_from_str("regid.2004-03.org.strongswan"),
-                                               chunk_from_str("strongSwan-5-1-1-dr1"),
-                                               chunk_empty);
-                       attr_cast->add_tag_id(attr_cast, tag_id);
+                       swid_inventory->destroy(swid_inventory);
+                       attr = swid_error_create(TCG_SWID_ERROR, request_id,
+                                                                        0, "error in SWID tag collection");
+                       out_msg->add_attribute(out_msg, attr);
+                       break;
+               }
+               DBG1(DBG_IMC, "collected %d SWID tag%s%s",
+                        swid_inventory->get_count(swid_inventory), full_tags ? "" : " ID",
+                        swid_inventory->get_count(swid_inventory) == 1 ? "" : "s");
+
+               if (full_tags)
+               {
+                       attr = tcg_swid_attr_tag_inv_create(request_id, eid_epoch, 1,
+                                                                                               swid_inventory);
                }
                else
                {
                }
                else
                {
-                       swid_tag_t *tag;
-                       tcg_swid_attr_tag_inv_t *attr_cast;
-       
-                       attr = tcg_swid_attr_tag_inv_create(request_id, eid_epoch, 1);
-                       attr_cast = (tcg_swid_attr_tag_inv_t*)attr;
-                       tag = swid_tag_create(chunk_from_str(strongswan_tag), chunk_empty);
-                       attr_cast->add_tag(attr_cast, tag);
+                       attr = tcg_swid_attr_tag_id_inv_create(request_id, eid_epoch, 1,
+                                                                                               swid_inventory);
                }
                out_msg->add_attribute(out_msg, attr);
        }
                }
                out_msg->add_attribute(out_msg, attr);
        }