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

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