diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2017-07-13 12:03:27 +0200 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2017-07-13 12:03:27 +0200 |
commit | cab4cc3a103ddd9f5bcc0c3a481620e64967227e (patch) | |
tree | 1ea37ded3363d9e9aa5d0aee5f49c7f4cb12ea97 /src/libimcv/plugins/imc_swima | |
parent | 5b1dbc3a8da2244e14a6a488647acbfa91ead517 (diff) | |
download | strongswan-cab4cc3a103ddd9f5bcc0c3a481620e64967227e.tar.bz2 strongswan-cab4cc3a103ddd9f5bcc0c3a481620e64967227e.tar.xz |
sw-collector: strip arch suffix from package names
Diffstat (limited to 'src/libimcv/plugins/imc_swima')
5 files changed, 22 insertions, 34 deletions
diff --git a/src/libimcv/plugins/imc_swima/sw_collector/sw-collector.c b/src/libimcv/plugins/imc_swima/sw_collector/sw-collector.c index 2f4df181a..d76f75161 100644 --- a/src/libimcv/plugins/imc_swima/sw_collector/sw-collector.c +++ b/src/libimcv/plugins/imc_swima/sw_collector/sw-collector.c @@ -518,7 +518,7 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db) sw_collector_dpkg_t *dpkg; char *package, *arch, *version; - char package_arch[BUF_LEN]; + char package_filter[BUF_LEN]; int res, count = 0; int status = EXIT_SUCCESS; enumerator_t *enumerator; @@ -532,15 +532,11 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db) enumerator = dpkg->create_sw_enumerator(dpkg); while (enumerator->enumerate(enumerator, &package, &arch, &version)) { - if (streq(arch, "all")) - { - continue; - } - /* Concatenate package and architecture strings */ - snprintf(package_arch, BUF_LEN, "%s:%s", package, arch); + /* Look for package names with architecture suffix */ + snprintf(package_filter, BUF_LEN, "%s:%%", package); - res = db->update_package(db, package, package_arch); + res = db->update_package(db, package_filter, package); if (res < 0) { status = EXIT_FAILURE; @@ -549,7 +545,7 @@ static int migrate(sw_collector_info_t *info, sw_collector_db_t *db) else if (res > 0) { count += res; - DBG2(DBG_IMC, "replaced '%s' by '%s'", package, package_arch); + DBG2(DBG_IMC, "%s: removed arch suffix %d times", package, res); } } enumerator->destroy(enumerator); diff --git a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.c b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.c index 206cbde2f..6f14818e6 100644 --- a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.c +++ b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.c @@ -231,13 +231,13 @@ METHOD(sw_collector_db_t, update_sw_id, bool, } METHOD(sw_collector_db_t, update_package, int, - private_sw_collector_db_t *this, char *package, char *package_new) + private_sw_collector_db_t *this, char *package_filter, char *package) { int count; count = this->db->execute(this->db, NULL, - "UPDATE sw_identifiers SET package = ? " - "WHERE package = ?", DB_TEXT, package_new, DB_TEXT, package); + "UPDATE sw_identifiers SET package = ? WHERE package LIKE ?", + DB_TEXT, package, DB_TEXT, package_filter); if (count < 0) { DBG1(DBG_IMC, "unable to update package name in database"); diff --git a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.h b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.h index 88a13bbdb..7aa41b0c1 100644 --- a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.h +++ b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_db.h @@ -120,12 +120,12 @@ struct sw_collector_db_t { /** * Update the package name * - * @param package Package name to be changed - * @param package_new New package name - * @return TRUE if update successful + * @param package_filter Package name[s] to be changed + * @param package New package name + * @return TRUE if update successful */ - int (*update_package)(sw_collector_db_t *this, char *package, - char *package_new); + int (*update_package)(sw_collector_db_t *this, char *package_filter, + char *package); /** * Enumerate over all collected [installed] software identities diff --git a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_history.c b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_history.c index 0fc6164cd..71f888c46 100644 --- a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_history.c +++ b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_history.c @@ -110,7 +110,7 @@ static void free_package(package_t *this) static package_t* extract_package(chunk_t item, sw_collector_info_t *info, sw_collector_history_op_t op) { - chunk_t package, version, old_version; + chunk_t package, package_stripped, version, old_version; package_t *p; /* extract package name */ @@ -121,6 +121,12 @@ static package_t* extract_package(chunk_t item, sw_collector_info_t *info, } item = chunk_skip(item, 1); + /* strip architecture suffix if present */ + if (extract_token(&package_stripped, ':', &package)) + { + package = package_stripped; + } + /* extract versions */ version = old_version = chunk_empty; @@ -371,7 +377,6 @@ METHOD(sw_collector_history_t, merge_installed_packages, bool, private_sw_collector_history_t *this) { uint32_t sw_id, count = 0; - char package_arch[BUF_LEN]; char *package, *arch, *version, *v1, *name, *n1; bool installed, success = FALSE; sw_collector_dpkg_t *dpkg; @@ -439,13 +444,6 @@ METHOD(sw_collector_history_t, merge_installed_packages, bool, if (!sw_id) { - /* Package name is stored with appended architecture */ - if (!streq(arch, "all")) - { - snprintf(package_arch, BUF_LEN, "%s:%s", package, arch); - package = package_arch; - } - /* new sw identifier - create with state 'installed' */ sw_id = this->db->set_sw_id(this->db, name, package, version, this->source, TRUE); diff --git a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_info.c b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_info.c index 0ac5f0dfb..b04645030 100644 --- a/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_info.c +++ b/src/libimcv/plugins/imc_swima/sw_collector/sw_collector_info.c @@ -93,15 +93,9 @@ METHOD(sw_collector_info_t, get_os, char*, METHOD(sw_collector_info_t, create_sw_id, char*, private_sw_collector_info_t *this, char *package, char *version) { - char *pos, *sw_id; - size_t len; + char *sw_id; - /* Remove architecture from package name */ - pos = strchr(package, ':'); - len = pos ? (pos - package) : strlen(package); - - /* Build software identifier */ - if (asprintf(&sw_id, "%s__%s-%.*s%s%s", this->tag_creator, this->os, len, + if (asprintf(&sw_id, "%s__%s-%s%s%s", this->tag_creator, this->os, package, strlen(version) ? "-" : "", version) == -1) { return NULL; |