trivial: Explicitly tag downgrades in the helper

This commit is contained in:
Richard Hughes 2016-06-29 10:10:47 +01:00
parent 4eb527f873
commit db468eef67

View File

@ -467,7 +467,7 @@ typedef struct {
FwupdInstallFlags flags; FwupdInstallFlags flags;
GBytes *blob_fw; GBytes *blob_fw;
GBytes *blob_cab; GBytes *blob_cab;
gint vercmp; gboolean is_downgrade;
FuMainAuthKind auth_kind; FuMainAuthKind auth_kind;
FuMainPrivate *priv; FuMainPrivate *priv;
} FuMainAuthHelper; } FuMainAuthHelper;
@ -770,6 +770,7 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
AsRelease *rel; AsRelease *rel;
const gchar *tmp; const gchar *tmp;
const gchar *version; const gchar *version;
gint vercmp;
guint i; guint i;
/* load store file which also decompresses firmware */ /* load store file which also decompresses firmware */
@ -877,8 +878,8 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
fu_device_get_id (helper->device)); fu_device_get_id (helper->device));
return FALSE; return FALSE;
} }
helper->vercmp = as_utils_vercmp (tmp, version); vercmp = as_utils_vercmp (tmp, version);
if (helper->vercmp == 0 && (helper->flags & FWUPD_INSTALL_FLAG_ALLOW_REINSTALL) == 0) { if (vercmp == 0 && (helper->flags & FWUPD_INSTALL_FLAG_ALLOW_REINSTALL) == 0) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_VERSION_SAME, FWUPD_ERROR_VERSION_SAME,
@ -886,7 +887,8 @@ fu_main_update_helper (FuMainAuthHelper *helper, GError **error)
tmp); tmp);
return FALSE; return FALSE;
} }
if (helper->vercmp > 0 && (helper->flags & FWUPD_INSTALL_FLAG_ALLOW_OLDER) == 0) { helper->is_downgrade = vercmp > 0;
if (helper->is_downgrade && (helper->flags & FWUPD_INSTALL_FLAG_ALLOW_OLDER) == 0) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_VERSION_NEWER, FWUPD_ERROR_VERSION_NEWER,
@ -1008,15 +1010,13 @@ static const gchar *
fu_main_get_action_id_for_device (FuMainAuthHelper *helper) fu_main_get_action_id_for_device (FuMainAuthHelper *helper)
{ {
gboolean is_trusted; gboolean is_trusted;
gboolean is_downgrade;
/* only test the payload */ /* only test the payload */
is_trusted = (helper->trust_flags & FWUPD_TRUST_FLAG_PAYLOAD) > 0; is_trusted = (helper->trust_flags & FWUPD_TRUST_FLAG_PAYLOAD) > 0;
is_downgrade = helper->vercmp > 0;
/* relax authentication checks for removable devices */ /* relax authentication checks for removable devices */
if (!fu_device_has_flag (helper->device, FU_DEVICE_FLAG_INTERNAL)) { if (!fu_device_has_flag (helper->device, FU_DEVICE_FLAG_INTERNAL)) {
if (is_downgrade) if (helper->is_downgrade)
return "org.freedesktop.fwupd.downgrade-hotplug"; return "org.freedesktop.fwupd.downgrade-hotplug";
if (is_trusted) if (is_trusted)
return "org.freedesktop.fwupd.update-hotplug-trusted"; return "org.freedesktop.fwupd.update-hotplug-trusted";
@ -1024,7 +1024,7 @@ fu_main_get_action_id_for_device (FuMainAuthHelper *helper)
} }
/* internal device */ /* internal device */
if (is_downgrade) if (helper->is_downgrade)
return "org.freedesktop.fwupd.downgrade-internal"; return "org.freedesktop.fwupd.downgrade-internal";
if (is_trusted) if (is_trusted)
return "org.freedesktop.fwupd.update-internal-trusted"; return "org.freedesktop.fwupd.update-internal-trusted";