From ee4d3698608ef70a62c346f412806465f65db42a Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Fri, 1 Apr 2022 13:03:20 -0500 Subject: [PATCH] fu-util/fu-tool: Drop the --force on every run --force was there because HSI specification was incomplete. However now we have the ability for plugins to report when not enough data was gathered to make a calculation. So change it to instead only run if enough data was gathered. --- src/fu-tool.c | 40 +++++++++++++++++++++++----------------- src/fu-util.c | 25 +++++++++++++++---------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/fu-tool.c b/src/fu-tool.c index f7d9036b4..73507ad6c 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -2815,35 +2815,41 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error) g_autoptr(GPtrArray) events_array = NULL; g_autofree gchar *str = NULL; - /* not ready yet */ - if ((priv->flags & FWUPD_INSTALL_FLAG_FORCE) == 0) { - g_set_error_literal(error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "The HSI specification is not yet complete. " - "To ignore this warning, use --force"); - return FALSE; - } - if (!fu_util_start_engine(priv, FU_ENGINE_LOAD_FLAG_COLDPLUG | FU_ENGINE_LOAD_FLAG_HWINFO | FU_ENGINE_LOAD_FLAG_REMOTES, error)) return FALSE; - g_print("%s \033[1m%s\033[0m\n", - /* TRANSLATORS: this is a string like 'HSI:2-U' */ - _("Host Security ID:"), - fu_engine_get_host_security_id(priv->engine)); - /* show or hide different elements */ if (priv->show_all) { flags |= FU_SECURITY_ATTR_TO_STRING_FLAG_SHOW_OBSOLETES; flags |= FU_SECURITY_ATTR_TO_STRING_FLAG_SHOW_URLS; } - /* print the "why" */ attrs = fu_engine_get_host_security_attrs(priv->engine); + items = fu_security_attrs_get_all(attrs); + for (guint j = 0; j < items->len; j++) { + FwupdSecurityAttr *attr = g_ptr_array_index(items, j); + + if (!fwupd_security_attr_has_flag(attr, FWUPD_SECURITY_ATTR_FLAG_MISSING_DATA)) + continue; + if (priv->flags & FWUPD_INSTALL_FLAG_FORCE) + continue; + g_set_error_literal(error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "Not enough data was provided to make an HSI calculation. " + "To ignore this warning, use --force."); + return FALSE; + } + + g_print("%s \033[1m%s\033[0m\n", + /* TRANSLATORS: this is a string like 'HSI:2-U' */ + _("Host Security ID:"), + fu_engine_get_host_security_id(priv->engine)); + + /* print the "why" */ if (priv->as_json) { str = fu_security_attrs_to_json_string(attrs, error); if (str == NULL) @@ -2851,7 +2857,7 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error) g_print("%s\n", str); return TRUE; } - items = fu_security_attrs_get_all(attrs); + str = fu_util_security_attrs_to_string(items, flags); g_print("%s\n", str); diff --git a/src/fu-util.c b/src/fu-util.c index 037287e6f..ab3bc6a52 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -3371,21 +3371,26 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error) g_autoptr(GError) error_local = NULL; g_autofree gchar *str = NULL; - /* not ready yet */ - if ((priv->flags & FWUPD_INSTALL_FLAG_FORCE) == 0) { - g_set_error_literal(error, - FWUPD_ERROR, - FWUPD_ERROR_NOT_SUPPORTED, - "The HSI specification is not yet complete. " - "To ignore this warning, use --force"); - return FALSE; - } - /* the "why" */ attrs = fwupd_client_get_host_security_attrs(priv->client, priv->cancellable, error); if (attrs == NULL) return FALSE; + for (guint j = 0; j < attrs->len; j++) { + FwupdSecurityAttr *attr = g_ptr_array_index(attrs, j); + + if (!fwupd_security_attr_has_flag(attr, FWUPD_SECURITY_ATTR_FLAG_MISSING_DATA)) + continue; + if (priv->flags & FWUPD_INSTALL_FLAG_FORCE) + continue; + g_set_error_literal(error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "Not enough data was provided to make an HSI calculation. " + "To ignore this warning, use --force"); + return FALSE; + } + /* the "when" */ events = fwupd_client_get_host_security_events(priv->client, 10,