sw-collector: Moved info class to libimcv
This commit is contained in:
parent
f237bfcb9e
commit
e658fd475a
|
@ -21,9 +21,6 @@ sw-collector.first_time = 0000-00-00T00:00:00Z
|
|||
sw-collector.history =
|
||||
Path pointing to apt history.log file.
|
||||
|
||||
sw-collector.tag_creator.regid = strongswan.org
|
||||
regid of the tagCreator entity.
|
||||
|
||||
sw-collector.rest_api.uri =
|
||||
HTTP URI of the central collector's REST API.
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ libimcv_la_SOURCES = \
|
|||
swid/swid_tag.h swid/swid_tag.c \
|
||||
swid/swid_tag_id.h swid/swid_tag_id.c \
|
||||
swid_gen/swid_gen.h swid_gen/swid_gen.c \
|
||||
swid_gen/swid_gen_info.h swid_gen/swid_gen_info.c \
|
||||
swima/swima_data_model.h swima/swima_data_model.c \
|
||||
swima/swima_record.h swima/swima_record.c \
|
||||
swima/swima_event.h swima/swima_event.c \
|
||||
|
|
|
@ -16,22 +16,22 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sw_collector_info.h"
|
||||
#include "swid_gen_info.h"
|
||||
|
||||
#include <library.h>
|
||||
#include <utils/lexparser.h>
|
||||
|
||||
typedef struct private_sw_collector_info_t private_sw_collector_info_t;
|
||||
typedef struct private_swid_gen_info_t private_swid_gen_info_t;
|
||||
|
||||
/**
|
||||
* Private data of an sw_collector_info_t object.
|
||||
* Private data of an swid_gen_info_t object.
|
||||
*/
|
||||
struct private_sw_collector_info_t {
|
||||
struct private_swid_gen_info_t {
|
||||
|
||||
/**
|
||||
* Public members of sw_collector_info_state_t
|
||||
* Public members of swid_gen_info_state_t
|
||||
*/
|
||||
sw_collector_info_t public;
|
||||
swid_gen_info_t public;
|
||||
|
||||
/**
|
||||
* tagCreator
|
||||
|
@ -74,14 +74,14 @@ static void sanitize_uri(char *uri, char a, char b)
|
|||
}
|
||||
}
|
||||
|
||||
METHOD(sw_collector_info_t, get_os_type, os_type_t,
|
||||
private_sw_collector_info_t *this)
|
||||
METHOD(swid_gen_info_t, get_os_type, os_type_t,
|
||||
private_swid_gen_info_t *this)
|
||||
{
|
||||
return this->os_info->get_type(this->os_info);
|
||||
}
|
||||
|
||||
METHOD(sw_collector_info_t, get_os, char*,
|
||||
private_sw_collector_info_t *this, char **product)
|
||||
METHOD(swid_gen_info_t, get_os, char*,
|
||||
private_swid_gen_info_t *this, char **product)
|
||||
{
|
||||
if (product)
|
||||
{
|
||||
|
@ -90,8 +90,8 @@ METHOD(sw_collector_info_t, get_os, char*,
|
|||
return this->os;
|
||||
}
|
||||
|
||||
METHOD(sw_collector_info_t, create_sw_id, char*,
|
||||
private_sw_collector_info_t *this, char *package, char *version)
|
||||
METHOD(swid_gen_info_t, create_sw_id, char*,
|
||||
private_swid_gen_info_t *this, char *package, char *version)
|
||||
{
|
||||
char *sw_id;
|
||||
|
||||
|
@ -106,8 +106,8 @@ METHOD(sw_collector_info_t, create_sw_id, char*,
|
|||
return sw_id;
|
||||
}
|
||||
|
||||
METHOD(sw_collector_info_t, destroy, void,
|
||||
private_sw_collector_info_t *this)
|
||||
METHOD(swid_gen_info_t, destroy, void,
|
||||
private_swid_gen_info_t *this)
|
||||
{
|
||||
this->os_info->destroy(this->os_info);
|
||||
free(this->os);
|
||||
|
@ -119,10 +119,14 @@ METHOD(sw_collector_info_t, destroy, void,
|
|||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
sw_collector_info_t *sw_collector_info_create(char *tag_creator)
|
||||
swid_gen_info_t *swid_gen_info_create(void)
|
||||
{
|
||||
private_sw_collector_info_t *this;
|
||||
private_swid_gen_info_t *this;
|
||||
chunk_t os_name, os_version, os_arch;
|
||||
char *tag_creator;
|
||||
|
||||
tag_creator = lib->settings->get_str(lib->settings,
|
||||
"libimcv.swid_gen.tag_creator.regid", "strongswan.org");
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
|
@ -16,25 +16,25 @@
|
|||
/**
|
||||
* @defgroup sw_collector sw-collector
|
||||
*
|
||||
* @defgroup sw_collector_info_t sw_collector_info
|
||||
* @defgroup swid_gen_info_t swid_gen_info
|
||||
* @{ @ingroup sw_collector
|
||||
*/
|
||||
|
||||
#ifndef SW_COLLECTOR_INFO_H_
|
||||
#define SW_COLLECTOR_INFO_H_
|
||||
#ifndef SWID_GEN_INFO_H_
|
||||
#define SWID_GEN_INFO_H_
|
||||
|
||||
typedef struct sw_collector_info_t sw_collector_info_t;
|
||||
typedef struct swid_gen_info_t swid_gen_info_t;
|
||||
|
||||
#include "imc/imc_os_info.h"
|
||||
|
||||
struct sw_collector_info_t {
|
||||
struct swid_gen_info_t {
|
||||
|
||||
/**
|
||||
* Get OS type
|
||||
*
|
||||
* @return OS type
|
||||
*/
|
||||
os_type_t (*get_os_type)(sw_collector_info_t *this);
|
||||
os_type_t (*get_os_type)(swid_gen_info_t *this);
|
||||
|
||||
/**
|
||||
* Get OS and product strings
|
||||
|
@ -42,7 +42,7 @@ struct sw_collector_info_t {
|
|||
* @param product Product string 'Name Version Arch'
|
||||
* @return OS string 'Name_Version-Arch'
|
||||
*/
|
||||
char* (*get_os)(sw_collector_info_t *this, char **product);
|
||||
char* (*get_os)(swid_gen_info_t *this, char **product);
|
||||
|
||||
/**
|
||||
* Create software identifier including tagCreator and OS
|
||||
|
@ -51,21 +51,19 @@ struct sw_collector_info_t {
|
|||
* @param version Version string
|
||||
* @return Software Identifier string
|
||||
*/
|
||||
char* (*create_sw_id)(sw_collector_info_t *this, char *package,
|
||||
char *version);
|
||||
char* (*create_sw_id)(swid_gen_info_t *this, char *package,
|
||||
char *version);
|
||||
|
||||
/**
|
||||
* Destroy sw_collector_info_t object
|
||||
* Destroy swid_gen_info_t object
|
||||
*/
|
||||
void (*destroy)(sw_collector_info_t *this);
|
||||
void (*destroy)(swid_gen_info_t *this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an sw_collector_info_t instance
|
||||
*
|
||||
* @param tag_creator Regid of tagCreator
|
||||
* Create an swid_gen_info_t instance
|
||||
*/
|
||||
sw_collector_info_t* sw_collector_info_create(char *tag_creator);
|
||||
swid_gen_info_t* swid_gen_info_create(void);
|
||||
|
||||
#endif /** SW_COLLECTOR_INFO_H_ @}*/
|
||||
#endif /** SWID_GEN_INFO_H_ @}*/
|
|
@ -5,7 +5,6 @@ sw_collector_SOURCES = \
|
|||
sw_collector_db.h sw_collector_db.c \
|
||||
sw_collector_dpkg.h sw_collector_dpkg.c \
|
||||
sw_collector_history.h sw_collector_history.c \
|
||||
sw_collector_info.h sw_collector_info.c \
|
||||
sw_collector_rest_api.h sw_collector_rest_api.c
|
||||
|
||||
sw-collector.o : $(top_builddir)/config.status
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
# include <syslog.h>
|
||||
#endif
|
||||
|
||||
#include "sw_collector_info.h"
|
||||
#include "sw_collector_db.h"
|
||||
#include "sw_collector_history.h"
|
||||
#include "sw_collector_rest_api.h"
|
||||
|
@ -33,7 +32,6 @@
|
|||
#include <utils/debug.h>
|
||||
#include <utils/lexparser.h>
|
||||
|
||||
#include <imv/imv_os_info.h>
|
||||
#include <swid_gen/swid_gen.h>
|
||||
|
||||
/**
|
||||
|
@ -221,26 +219,15 @@ static collector_op_t do_args(int argc, char *argv[], bool *full_tags,
|
|||
/**
|
||||
* Extract software events from apt history log files
|
||||
*/
|
||||
static int extract_history(sw_collector_info_t *info, sw_collector_db_t *db)
|
||||
static int extract_history(sw_collector_db_t *db)
|
||||
{
|
||||
sw_collector_history_t *history = NULL;
|
||||
uint32_t epoch, last_eid, eid = 0;
|
||||
char *history_path, *os, *last_time = NULL, rfc_time[21];
|
||||
char *history_path, *last_time = NULL, rfc_time[21];
|
||||
chunk_t *h, history_chunk, line, cmd;
|
||||
os_type_t os_type;
|
||||
int status = EXIT_FAILURE;
|
||||
bool skip = TRUE;
|
||||
|
||||
/* check if OS supports apg/dpkg history logs */
|
||||
info->get_os(info, &os);
|
||||
os_type = info->get_os_type(info);
|
||||
|
||||
if (os_type != OS_TYPE_DEBIAN && os_type != OS_TYPE_UBUNTU)
|
||||
{
|
||||
DBG1(DBG_IMC, "%.*s not supported", os);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* open history file for reading */
|
||||
history_path = lib->settings->get_str(lib->settings, "%s.history", NULL,
|
||||
lib->ns);
|
||||
|
@ -259,7 +246,11 @@ static int extract_history(sw_collector_info_t *info, sw_collector_db_t *db)
|
|||
history_chunk = *h;
|
||||
|
||||
/* Instantiate history extractor */
|
||||
history = sw_collector_history_create(info, db, 1);
|
||||
history = sw_collector_history_create(db, 1);
|
||||
if (!history)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* retrieve last event in database */
|
||||
if (!db->get_last_event(db, &last_eid, &epoch, &last_time) || !last_eid)
|
||||
|
@ -472,8 +463,8 @@ static int unregistered_identifiers(sw_collector_db_t *db,
|
|||
* Generate ISO 19770-2:2015 SWID tags for [installed|removed|all]
|
||||
* SW identifiers that are not registered centrally
|
||||
*/
|
||||
static int generate_tags(sw_collector_info_t *info, sw_collector_db_t *db,
|
||||
bool full_tags, sw_collector_db_query_t type)
|
||||
static int generate_tags(sw_collector_db_t *db, bool full_tags,
|
||||
sw_collector_db_query_t type)
|
||||
{
|
||||
swid_gen_t * swid_gen;
|
||||
sw_collector_rest_api_t *rest_api;
|
||||
|
@ -547,7 +538,7 @@ end:
|
|||
/**
|
||||
* Append missing architecture suffix to package entries in the database
|
||||
*/
|
||||
static int migrate(sw_collector_info_t *info, sw_collector_db_t *db)
|
||||
static int migrate(sw_collector_db_t *db)
|
||||
{
|
||||
sw_collector_dpkg_t *dpkg;
|
||||
|
||||
|
@ -595,10 +586,9 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
sw_collector_db_t *db = NULL;
|
||||
sw_collector_db_query_t query_type;
|
||||
sw_collector_info_t *info;
|
||||
collector_op_t op;
|
||||
bool full_tags;
|
||||
char *uri, *tag_creator;
|
||||
char *uri;
|
||||
int status = EXIT_FAILURE;
|
||||
|
||||
op = do_args(argc, argv, &full_tags, &query_type);
|
||||
|
@ -638,15 +628,10 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Attach OS info */
|
||||
tag_creator = lib->settings->get_str(lib->settings, "%s.tag_creator.regid",
|
||||
"strongswan.org", lib->ns);
|
||||
info = sw_collector_info_create(tag_creator);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case COLLECTOR_OP_EXTRACT:
|
||||
status = extract_history(info, db);
|
||||
status = extract_history(db);
|
||||
break;
|
||||
case COLLECTOR_OP_LIST:
|
||||
status = list_identifiers(db, query_type);
|
||||
|
@ -655,14 +640,13 @@ int main(int argc, char *argv[])
|
|||
status = unregistered_identifiers(db, query_type);
|
||||
break;
|
||||
case COLLECTOR_OP_GENERATE:
|
||||
status = generate_tags(info, db, full_tags, query_type);
|
||||
status = generate_tags(db, full_tags, query_type);
|
||||
break;
|
||||
case COLLECTOR_OP_MIGRATE:
|
||||
status = migrate(info, db);
|
||||
status = migrate(db);
|
||||
break;
|
||||
}
|
||||
db->destroy(db);
|
||||
info->destroy(info);
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "sw_collector_history.h"
|
||||
#include "sw_collector_dpkg.h"
|
||||
|
||||
#include "swima/swima_event.h"
|
||||
#include <swima/swima_event.h>
|
||||
#include <swid_gen/swid_gen_info.h>
|
||||
|
||||
typedef struct private_sw_collector_history_t private_sw_collector_history_t;
|
||||
|
||||
|
@ -42,7 +43,7 @@ struct private_sw_collector_history_t {
|
|||
/**
|
||||
* Reference to OS info object
|
||||
*/
|
||||
sw_collector_info_t *info;
|
||||
swid_gen_info_t *info;
|
||||
|
||||
/**
|
||||
* Reference to collector database
|
||||
|
@ -67,7 +68,7 @@ struct package_t {
|
|||
/**
|
||||
* Create package_t list item object
|
||||
*/
|
||||
static package_t* create_package(sw_collector_info_t *info, chunk_t package,
|
||||
static package_t* create_package(swid_gen_info_t *info, chunk_t package,
|
||||
chunk_t version, chunk_t old_version)
|
||||
{
|
||||
package_t *this;
|
||||
|
@ -107,7 +108,7 @@ static void free_package(package_t *this)
|
|||
/**
|
||||
* Extract and parse a single package item
|
||||
*/
|
||||
static package_t* extract_package(chunk_t item, sw_collector_info_t *info,
|
||||
static package_t* extract_package(chunk_t item, swid_gen_info_t *info,
|
||||
sw_collector_history_op_t op)
|
||||
{
|
||||
chunk_t package, package_stripped, version, old_version;
|
||||
|
@ -475,17 +476,32 @@ end:
|
|||
METHOD(sw_collector_history_t, destroy, void,
|
||||
private_sw_collector_history_t *this)
|
||||
{
|
||||
this->info->destroy(this->info);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
sw_collector_history_t *sw_collector_history_create(sw_collector_info_t *info,
|
||||
sw_collector_db_t *db,
|
||||
sw_collector_history_t *sw_collector_history_create(sw_collector_db_t *db,
|
||||
uint8_t source)
|
||||
{
|
||||
private_sw_collector_history_t *this;
|
||||
swid_gen_info_t *info;
|
||||
os_type_t os_type;
|
||||
char *os;
|
||||
|
||||
info = swid_gen_info_create();
|
||||
|
||||
/* check if OS supports apg/dpkg history logs */
|
||||
info->get_os(info, &os);
|
||||
os_type = info->get_os_type(info);
|
||||
if (os_type != OS_TYPE_DEBIAN && os_type != OS_TYPE_UBUNTU)
|
||||
{
|
||||
DBG1(DBG_IMC, "%.*s not supported", os);
|
||||
info->destroy(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#ifndef SW_COLLECTOR_HISTORY_H_
|
||||
#define SW_COLLECTOR_HISTORY_H_
|
||||
|
||||
#include "sw_collector_history.h"
|
||||
#include "sw_collector_info.h"
|
||||
#include "sw_collector_db.h"
|
||||
|
||||
#include <library.h>
|
||||
|
@ -84,12 +82,10 @@ struct sw_collector_history_t {
|
|||
/**
|
||||
* Create an sw_collector_history_t instance
|
||||
*
|
||||
* @param info Internal reference to collector info
|
||||
* @param db Internal reference to collector database
|
||||
* @param source Software event source number
|
||||
*/
|
||||
sw_collector_history_t* sw_collector_history_create(sw_collector_info_t *info,
|
||||
sw_collector_db_t *db,
|
||||
sw_collector_history_t* sw_collector_history_create(sw_collector_db_t *db,
|
||||
uint8_t source);
|
||||
|
||||
#endif /** SW_COLLECTOR_HISTORY_H_ @}*/
|
||||
|
|
Loading…
Reference in New Issue