Blame SOURCES/0006-subman-Handle-subscription-manager-giving-invalid-st.patch

e296c6
From f8ddd2c711cd502c74eb9d45360914fe2e6e1b3f Mon Sep 17 00:00:00 2001
e296c6
From: Ray Strode <rstrode@redhat.com>
e296c6
Date: Thu, 20 Aug 2020 13:34:19 -0400
e296c6
Subject: [PATCH 06/15] subman: Handle subscription-manager giving invalid
e296c6
 status better
e296c6
e296c6
subscription-manager potentially returns status messages that the
e296c6
subman plugin treats as enum values translated in some unknown
e296c6
other language. It could be tied to system locale, or due to a
e296c6
caching bug a previous locale used.
e296c6
e296c6
This commit tries to work around that bug, by instead relying on
e296c6
the GetUUID() method and valid attribute.  If there's no UUID we
e296c6
know the system is unregistered. If there's a UUID but the valid
e296c6
attribute is FALSE we know the system is registered, but hasn't
e296c6
got proper entitlements.
e296c6
---
e296c6
 plugins/subman/gsd-subscription-manager.c | 69 ++++++++++++-----------
e296c6
 1 file changed, 36 insertions(+), 33 deletions(-)
e296c6
e296c6
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
e296c6
index 46f051a5..e2c16056 100644
e296c6
--- a/plugins/subman/gsd-subscription-manager.c
e296c6
+++ b/plugins/subman/gsd-subscription-manager.c
e296c6
@@ -104,77 +104,60 @@ typedef struct
e296c6
 	gchar *starts;
e296c6
 	gchar *ends;
e296c6
 } ProductData;
e296c6
 
e296c6
 static void
e296c6
 product_data_free (ProductData *product)
e296c6
 {
e296c6
 	g_free (product->product_name);
e296c6
 	g_free (product->product_id);
e296c6
 	g_free (product->version);
e296c6
 	g_free (product->arch);
e296c6
 	g_free (product->status);
e296c6
 	g_free (product->starts);
e296c6
 	g_free (product->ends);
e296c6
 	g_free (product);
e296c6
 }
e296c6
 
e296c6
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProductData, product_data_free);
e296c6
 
e296c6
 static gpointer manager_object = NULL;
e296c6
 
e296c6
 GQuark
e296c6
 gsd_subscription_manager_error_quark (void)
e296c6
 {
e296c6
 	static GQuark quark = 0;
e296c6
 	if (!quark)
e296c6
 		quark = g_quark_from_static_string ("gsd_subscription_manager_error");
e296c6
 	return quark;
e296c6
 }
e296c6
 
e296c6
-static GsdSubmanSubscriptionStatus
e296c6
-_client_subscription_status_from_text (const gchar *status_txt)
e296c6
-{
e296c6
-	if (g_strcmp0 (status_txt, "Unknown") == 0)
e296c6
-		return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
e296c6
-	if (g_strcmp0 (status_txt, "Current") == 0)
e296c6
-		return GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
e296c6
-	if (g_strcmp0 (status_txt, "Invalid") == 0)
e296c6
-		return GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
e296c6
-	if (g_strcmp0 (status_txt, "Disabled") == 0)
e296c6
-		return GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
e296c6
-	if (g_strcmp0 (status_txt, "Insufficient") == 0)
e296c6
-		return GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
e296c6
-	g_warning ("Unknown subscription status: %s", status_txt); // 'Current'?
e296c6
-	return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
e296c6
-}
e296c6
-
e296c6
 static GVariant *
e296c6
 _make_installed_products_variant (GPtrArray *installed_products)
e296c6
 {
e296c6
 	GVariantBuilder builder;
e296c6
 	g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
e296c6
 
e296c6
 	for (guint i = 0; i < installed_products->len; i++) {
e296c6
 		ProductData *product = g_ptr_array_index (installed_products, i);
e296c6
 		g_auto(GVariantDict) dict;
e296c6
 
e296c6
 		g_variant_dict_init (&dict, NULL);
e296c6
 
e296c6
 		g_variant_dict_insert (&dict, "product-name", "s", product->product_name);
e296c6
 		g_variant_dict_insert (&dict, "product-id", "s", product->product_id);
e296c6
 		g_variant_dict_insert (&dict, "version", "s", product->version);
e296c6
 		g_variant_dict_insert (&dict, "arch", "s", product->arch);
e296c6
 		g_variant_dict_insert (&dict, "status", "s", product->status);
e296c6
 		g_variant_dict_insert (&dict, "starts", "s", product->starts);
e296c6
 		g_variant_dict_insert (&dict, "ends", "s", product->ends);
e296c6
 
e296c6
 		g_variant_builder_add_value (&builder, g_variant_dict_end (&dict));
e296c6
 	}
e296c6
 
e296c6
 	return g_variant_builder_end (&builder);
e296c6
 }
e296c6
 
e296c6
 static void
e296c6
 _emit_property_changed (GsdSubscriptionManager *manager,
e296c6
 		        const gchar *property_name,
e296c6
 		        GVariant *property_value)
e296c6
@@ -248,94 +231,114 @@ _client_installed_products_update (GsdSubscriptionManager *manager, GError **err
e296c6
 
e296c6
 		if (json_product == NULL)
e296c6
 			continue;
e296c6
 		if (json_array_get_length (json_product) < 8) {
e296c6
 			g_debug ("Unexpected number of array elements in InstalledProducts JSON");
e296c6
 			continue;
e296c6
 		}
e296c6
 
e296c6
 		product->product_name = g_strdup (json_array_get_string_element (json_product, 0));
e296c6
 		product->product_id = g_strdup (json_array_get_string_element (json_product, 1));
e296c6
 		product->version = g_strdup (json_array_get_string_element (json_product, 2));
e296c6
 		product->arch = g_strdup (json_array_get_string_element (json_product, 3));
e296c6
 		product->status = g_strdup (json_array_get_string_element (json_product, 4));
e296c6
 		product->starts = g_strdup (json_array_get_string_element (json_product, 6));
e296c6
 		product->ends = g_strdup (json_array_get_string_element (json_product, 7));
e296c6
 
e296c6
 		g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
e296c6
 	}
e296c6
 
e296c6
 	/* emit notification for g-c-c */
e296c6
 	_emit_property_changed (manager, "InstalledProducts",
e296c6
 			       _make_installed_products_variant (priv->installed_products));
e296c6
 
e296c6
 	return TRUE;
e296c6
 }
e296c6
 
e296c6
 static gboolean
e296c6
 _client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
e296c6
 {
e296c6
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
e296c6
+	g_autoptr(GVariant) uuid = NULL;
e296c6
+	const gchar *uuid_txt = NULL;
e296c6
 	JsonNode *json_root;
e296c6
 	JsonObject *json_obj;
e296c6
 	const gchar *json_txt = NULL;
e296c6
-	const gchar *status_txt = NULL;
e296c6
-	g_autoptr(GVariant) val = NULL;
e296c6
+	g_autoptr(GVariant) status = NULL;
e296c6
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
e296c6
 
e296c6
 	/* save old value */
e296c6
 	priv->subscription_status_last = priv->subscription_status;
e296c6
 
e296c6
-	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
e296c6
-				      "GetStatus",
e296c6
-				      g_variant_new ("(ss)",
e296c6
-						     "", /* assumed as 'now' */
e296c6
-						     "C.UTF-8"),
e296c6
-				      G_DBUS_CALL_FLAGS_NONE,
e296c6
-				      -1, NULL, error);
e296c6
-	if (val == NULL)
e296c6
+	uuid = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONSUMER],
e296c6
+				       "GetUuid",
e296c6
+				       g_variant_new ("(s)",
e296c6
+				                      "C.UTF-8"),
e296c6
+				       G_DBUS_CALL_FLAGS_NONE,
e296c6
+				       -1, NULL, error);
e296c6
+	if (uuid == NULL)
e296c6
 		return FALSE;
e296c6
-	g_variant_get (val, "(&s)", &json_txt);
e296c6
+
e296c6
+	g_variant_get (uuid, "(&s)", &uuid_txt);
e296c6
+
e296c6
+	status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
e296c6
+				         "GetStatus",
e296c6
+				         g_variant_new ("(ss)",
e296c6
+						        "", /* assumed as 'now' */
e296c6
+						        "C.UTF-8"),
e296c6
+				         G_DBUS_CALL_FLAGS_NONE,
e296c6
+				         -1, NULL, error);
e296c6
+	if (status == NULL)
e296c6
+		return FALSE;
e296c6
+	g_variant_get (status, "(&s)", &json_txt);
e296c6
 	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
e296c6
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
e296c6
 		return FALSE;
e296c6
 	json_root = json_parser_get_root (json_parser);
e296c6
 	json_obj = json_node_get_object (json_root);
e296c6
-	if (!json_object_has_member (json_obj, "status")) {
e296c6
+	if (!json_object_has_member (json_obj, "valid")) {
e296c6
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
e296c6
-			     "no Entitlement.GetStatus status in %s", json_txt);
e296c6
+			     "no Entitlement.GetStatus valid in %s", json_txt);
e296c6
 		return FALSE;
e296c6
 	}
e296c6
 
e296c6
-	status_txt = json_object_get_string_member (json_obj, "status");
e296c6
-	g_debug ("Entitlement.GetStatus: %s", status_txt);
e296c6
-	priv->subscription_status = _client_subscription_status_from_text (status_txt);
e296c6
+	gboolean is_valid = json_object_get_boolean_member (json_obj, "valid");
e296c6
+
e296c6
+	if (uuid_txt[0] != '\0') {
e296c6
+		if (is_valid) {
e296c6
+			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
e296c6
+		} else {
e296c6
+			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
e296c6
+		}
e296c6
+	} else {
e296c6
+		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
e296c6
+	}
e296c6
 
e296c6
 	/* emit notification for g-c-c */
e296c6
 	if (priv->subscription_status != priv->subscription_status_last) {
e296c6
 		_emit_property_changed (manager, "SubscriptionStatus",
e296c6
 				       g_variant_new_uint32 (priv->subscription_status));
e296c6
 	}
e296c6
 
e296c6
 	return TRUE;
e296c6
 }
e296c6
 
e296c6
 static gboolean
e296c6
 _client_syspurpose_update (GsdSubscriptionManager *manager, GError **error)
e296c6
 {
e296c6
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
e296c6
 	JsonNode *json_root;
e296c6
 	JsonObject *json_obj;
e296c6
 	const gchar *json_txt = NULL;
e296c6
 	g_autoptr(GVariant) val = NULL;
e296c6
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
e296c6
 
e296c6
 	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_SYSPURPOSE],
e296c6
 				      "GetSyspurpose",
e296c6
 				      g_variant_new ("(s)", "C.UTF-8"),
e296c6
 				      G_DBUS_CALL_FLAGS_NONE,
e296c6
 				      -1, NULL, error);
e296c6
 	if (val == NULL)
e296c6
 		return FALSE;
e296c6
 	g_variant_get (val, "(&s)", &json_txt);
e296c6
 	g_debug ("Syspurpose.GetSyspurpose JSON: %s", json_txt);
e296c6
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
e296c6
-- 
e296c6
2.30.0
e296c6