Blame SOURCES/0010-subman-Add-new-no-installed-products-state.patch

06f198
From d53c27802c69773d63d108f57912035fd3caabf9 Mon Sep 17 00:00:00 2001
06f198
From: Ray Strode <rstrode@redhat.com>
06f198
Date: Sun, 24 Jan 2021 11:24:36 -0500
06f198
Subject: [PATCH 10/15] subman: Add new no-installed-products state
06f198
06f198
It's possible, though unlikley, the system has
06f198
no packages installed from Red Hat supported package sets.
06f198
06f198
This commit adds a new state to track that situation.
06f198
---
06f198
 plugins/subman/gsd-subman-common.c        |  2 ++
06f198
 plugins/subman/gsd-subman-common.h        |  1 +
06f198
 plugins/subman/gsd-subscription-manager.c | 17 +++++++----------
06f198
 3 files changed, 10 insertions(+), 10 deletions(-)
06f198
06f198
diff --git a/plugins/subman/gsd-subman-common.c b/plugins/subman/gsd-subman-common.c
06f198
index e515131e..eef5175d 100644
06f198
--- a/plugins/subman/gsd-subman-common.c
06f198
+++ b/plugins/subman/gsd-subman-common.c
06f198
@@ -5,32 +5,34 @@
06f198
  * This program is free software; you can redistribute it and/or modify
06f198
  * it under the terms of the GNU General Public License as published by
06f198
  * the Free Software Foundation; either version 2 of the License, or
06f198
  * (at your option) any later version.
06f198
  *
06f198
  * This program is distributed in the hope that it will be useful,
06f198
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
06f198
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
06f198
  * GNU General Public License for more details.
06f198
  *
06f198
  * You should have received a copy of the GNU General Public License
06f198
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
06f198
  *
06f198
  */
06f198
 
06f198
 #include "config.h"
06f198
 
06f198
 #include "gsd-subman-common.h"
06f198
 
06f198
 const gchar *
06f198
 gsd_subman_subscription_status_to_string (GsdSubmanSubscriptionStatus status)
06f198
 {
06f198
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID)
06f198
 		return "valid";
06f198
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID)
06f198
 		return "invalid";
06f198
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED)
06f198
 		return "disabled";
06f198
 	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID)
06f198
 		return "partially-valid";
06f198
+	if (status == GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS)
06f198
+		return "no-installed-products";
06f198
 	return "unknown";
06f198
 }
06f198
diff --git a/plugins/subman/gsd-subman-common.h b/plugins/subman/gsd-subman-common.h
06f198
index fccf9f6a..f8a3d9f4 100644
06f198
--- a/plugins/subman/gsd-subman-common.h
06f198
+++ b/plugins/subman/gsd-subman-common.h
06f198
@@ -3,38 +3,39 @@
06f198
  * Copyright (C) 2019 Richard Hughes <rhughes@redhat.com>
06f198
  *
06f198
  * This program is free software; you can redistribute it and/or modify
06f198
  * it under the terms of the GNU General Public License as published by
06f198
  * the Free Software Foundation; either version 2 of the License, or
06f198
  * (at your option) any later version.
06f198
  *
06f198
  * This program is distributed in the hope that it will be useful,
06f198
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
06f198
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
06f198
  * GNU General Public License for more details.
06f198
  *
06f198
  * You should have received a copy of the GNU General Public License
06f198
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
06f198
  *
06f198
  */
06f198
 
06f198
 #ifndef __GSD_SUBMAN_COMMON_H
06f198
 #define __GSD_SUBMAN_COMMON_H
06f198
 
06f198
 #include <glib-object.h>
06f198
 
06f198
 G_BEGIN_DECLS
06f198
 
06f198
 typedef enum {
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN,
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID,
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID,
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED,
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID,
06f198
+	GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS,
06f198
 	GSD_SUBMAN_SUBSCRIPTION_STATUS_LAST
06f198
 } GsdSubmanSubscriptionStatus;
06f198
 
06f198
 const gchar	*gsd_subman_subscription_status_to_string	(GsdSubmanSubscriptionStatus	 status);
06f198
 
06f198
 G_END_DECLS
06f198
 
06f198
 #endif /* __GSD_SUBMAN_COMMON_H */
06f198
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
06f198
index 0838d490..46f8d35c 100644
06f198
--- a/plugins/subman/gsd-subscription-manager.c
06f198
+++ b/plugins/subman/gsd-subscription-manager.c
06f198
@@ -242,60 +242,67 @@ _client_installed_products_update (GsdSubscriptionManager *manager, GError **err
06f198
 		product->version = g_strdup (json_array_get_string_element (json_product, 2));
06f198
 		product->arch = g_strdup (json_array_get_string_element (json_product, 3));
06f198
 		product->status = g_strdup (json_array_get_string_element (json_product, 4));
06f198
 		product->starts = g_strdup (json_array_get_string_element (json_product, 6));
06f198
 		product->ends = g_strdup (json_array_get_string_element (json_product, 7));
06f198
 
06f198
 		g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
06f198
 	}
06f198
 
06f198
 	/* emit notification for g-c-c */
06f198
 	_emit_property_changed (manager, "InstalledProducts",
06f198
 			       _make_installed_products_variant (priv->installed_products));
06f198
 
06f198
 	return TRUE;
06f198
 }
06f198
 
06f198
 static gboolean
06f198
 _client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
06f198
 {
06f198
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
06f198
 	g_autoptr(GVariant) uuid = NULL;
06f198
 	const gchar *uuid_txt = NULL;
06f198
 	JsonNode *json_root;
06f198
 	JsonObject *json_obj;
06f198
 	const gchar *json_txt = NULL;
06f198
 	g_autoptr(GVariant) status = NULL;
06f198
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
06f198
 
06f198
 	/* save old value */
06f198
 	priv->subscription_status_last = priv->subscription_status;
06f198
+	if (!_client_installed_products_update (manager, error))
06f198
+		goto out;
06f198
+
06f198
+	if (priv->installed_products->len == 0) {
06f198
+		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS;
06f198
+		goto out;
06f198
+	}
06f198
 
06f198
 	uuid = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONSUMER],
06f198
 				       "GetUuid",
06f198
 				       g_variant_new ("(s)",
06f198
 				                      "C.UTF-8"),
06f198
 				       G_DBUS_CALL_FLAGS_NONE,
06f198
 				       -1, NULL, error);
06f198
 	if (uuid == NULL)
06f198
 		return FALSE;
06f198
 
06f198
 	g_variant_get (uuid, "(&s)", &uuid_txt);
06f198
 
06f198
 	status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
06f198
 				         "GetStatus",
06f198
 				         g_variant_new ("(ss)",
06f198
 						        "", /* assumed as 'now' */
06f198
 						        "C.UTF-8"),
06f198
 				         G_DBUS_CALL_FLAGS_NONE,
06f198
 				         -1, NULL, error);
06f198
 	if (status == NULL)
06f198
 		return FALSE;
06f198
 	g_variant_get (status, "(&s)", &json_txt);
06f198
 	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
06f198
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
06f198
 		return FALSE;
06f198
 	json_root = json_parser_get_root (json_parser);
06f198
 	json_obj = json_node_get_object (json_root);
06f198
 	if (!json_object_has_member (json_obj, "valid")) {
06f198
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
06f198
 			     "no Entitlement.GetStatus valid in %s", json_txt);
06f198
@@ -563,62 +570,60 @@ _client_register_with_keys (GsdSubscriptionManager *manager,
06f198
 				       NULL);
06f198
 	if (subprocess == NULL) {
06f198
 		g_prefix_error (error, "failed to find pkexec: ");
06f198
 		return FALSE;
06f198
 	}
06f198
 
06f198
 	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
06f198
 		g_prefix_error (error, "failed to run pkexec: ");
06f198
 		return FALSE;
06f198
 	}
06f198
 
06f198
 	rc = g_subprocess_get_exit_status (subprocess);
06f198
 	if (rc != 0) {
06f198
 		if (g_bytes_get_size (stderr_buf) == 0) {
06f198
 			g_set_error_literal (error, G_IO_ERROR, rc,
06f198
 			                     "Failed to run helper without stderr");
06f198
 			return FALSE;
06f198
 		}
06f198
 
06f198
 		g_set_error (error, G_IO_ERROR, rc,
06f198
 			     "%.*s",
06f198
 			     g_bytes_get_size (stderr_buf),
06f198
 			     g_bytes_get_data (stderr_buf, NULL));
06f198
 	}
06f198
 
06f198
 	/* FIXME: also do on error? */
06f198
 	if (!_client_register_stop (manager, error))
06f198
 		return FALSE;
06f198
 	if (!_client_subscription_status_update (manager, error))
06f198
 		return FALSE;
06f198
-	if (!_client_installed_products_update (manager, error))
06f198
-		return FALSE;
06f198
 	_client_maybe__show_notification (manager);
06f198
 
06f198
 	/* success */
06f198
 	return TRUE;
06f198
 }
06f198
 
06f198
 static gboolean
06f198
 _client_register (GsdSubscriptionManager *manager,
06f198
 			 const gchar *hostname,
06f198
 			 const gchar *organisation,
06f198
 			 const gchar *username,
06f198
 			 const gchar *password,
06f198
 			 GError **error)
06f198
 {
06f198
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
06f198
 	g_autoptr(GSubprocess) subprocess = NULL;
06f198
 	g_autoptr(GBytes) stdin_buf = g_bytes_new (password, strlen (password) + 1);
06f198
 	g_autoptr(GBytes) stderr_buf = NULL;
06f198
 	gint rc;
06f198
 
06f198
 	/* fallback */
06f198
 	if (organisation == NULL)
06f198
 		organisation = "";
06f198
 
06f198
 	/* apparently: "we can't send registration credentials over the regular
06f198
 	 * system or session bus since those aren't really locked down..." */
06f198
 	if (!_client_register_start (manager, error))
06f198
 		return FALSE;
06f198
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
06f198
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE,
06f198
@@ -632,62 +637,60 @@ _client_register (GsdSubscriptionManager *manager,
06f198
 				       NULL);
06f198
 	if (subprocess == NULL) {
06f198
 		g_prefix_error (error, "failed to find pkexec: ");
06f198
 		return FALSE;
06f198
 	}
06f198
 
06f198
 	if (!g_subprocess_communicate (subprocess, stdin_buf, NULL, NULL, &stderr_buf, error)) {
06f198
 		g_prefix_error (error, "failed to run pkexec: ");
06f198
 		return FALSE;
06f198
 	}
06f198
 
06f198
 	rc = g_subprocess_get_exit_status (subprocess);
06f198
 	if (rc != 0) {
06f198
 		if (g_bytes_get_size (stderr_buf) == 0) {
06f198
 			g_set_error_literal (error, G_IO_ERROR, rc,
06f198
 			                     "Failed to run helper without stderr");
06f198
 			return FALSE;
06f198
 		}
06f198
 
06f198
 		g_set_error (error, G_IO_ERROR, rc,
06f198
 			     "%.*s",
06f198
 			     g_bytes_get_size (stderr_buf),
06f198
 			     g_bytes_get_data (stderr_buf, NULL));
06f198
 	}
06f198
 
06f198
 	/* FIXME: also do on error? */
06f198
 	if (!_client_register_stop (manager, error))
06f198
 		return FALSE;
06f198
 	if (!_client_subscription_status_update (manager, error))
06f198
 		return FALSE;
06f198
-	if (!_client_installed_products_update (manager, error))
06f198
-		return FALSE;
06f198
 	_client_maybe__show_notification (manager);
06f198
 	return TRUE;
06f198
 }
06f198
 
06f198
 static gboolean
06f198
 _client_unregister (GsdSubscriptionManager *manager, GError **error)
06f198
 {
06f198
 	g_autoptr(GSubprocess) subprocess = NULL;
06f198
 
06f198
 	/* apparently: "we can't send registration credentials over the regular
06f198
 	 * system or session bus since those aren't really locked down..." */
06f198
 	if (!_client_register_start (manager, error))
06f198
 		return FALSE;
06f198
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
06f198
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
06f198
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
06f198
 				       "--kind", "unregister",
06f198
 				       NULL);
06f198
 	if (subprocess == NULL) {
06f198
 		g_prefix_error (error, "failed to find pkexec: ");
06f198
 		return FALSE;
06f198
 	}
06f198
 	if (!_client_subprocess_wait_check (subprocess, error))
06f198
 		return FALSE;
06f198
 	if (!_client_subscription_status_update (manager, error))
06f198
 		return FALSE;
06f198
 	if (!_client_installed_products_update (manager, error))
06f198
 		return FALSE;
06f198
 	_client_maybe__show_notification (manager);
06f198
 	return TRUE;
06f198
@@ -714,64 +717,60 @@ _client_update_config (GsdSubscriptionManager *manager, GError **error)
06f198
 	dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
06f198
 	val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
06f198
 	if (val_server != NULL) {
06f198
 		g_variant_iter_init (&iter, val_server);
06f198
 		while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
06f198
 			g_debug ("%s=%s", key, value);
06f198
 			g_hash_table_insert (priv->config,
06f198
 					     g_steal_pointer (&key),
06f198
 					     g_steal_pointer (&value));
06f198
 		}
06f198
 	}
06f198
 	return TRUE;
06f198
 }
06f198
 
06f198
 static void
06f198
 _subman_proxy_signal_cb (GDBusProxy *proxy,
06f198
 			 const gchar *sender_name,
06f198
 			 const gchar *signal_name,
06f198
 			 GVariant *parameters,
06f198
 			 GsdSubscriptionManager *manager)
06f198
 {
06f198
 	g_autoptr(GError) error = NULL;
06f198
 	if (!_client_syspurpose_update (manager, &error)) {
06f198
 		g_warning ("failed to update syspurpose: %s", error->message);
06f198
 		g_clear_error (&error);
06f198
 	}
06f198
 	if (!_client_subscription_status_update (manager, &error)) {
06f198
 		g_warning ("failed to update subscription status: %s", error->message);
06f198
 		g_clear_error (&error);
06f198
 	}
06f198
-	if (!_client_installed_products_update (manager, &error)) {
06f198
-		g_warning ("failed to update installed products: %s", error->message);
06f198
-		g_clear_error (&error);
06f198
-	}
06f198
 	_client_maybe__show_notification (manager);
06f198
 }
06f198
 
06f198
 static void
06f198
 _client_unload (GsdSubscriptionManager *manager)
06f198
 {
06f198
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
06f198
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++)
06f198
 		g_clear_object (&priv->proxies[i]);
06f198
 	g_hash_table_unref (priv->config);
06f198
 }
06f198
 
06f198
 static const gchar *
06f198
 _rhsm_interface_to_string (_RhsmInterface kind)
06f198
 {
06f198
 	if (kind == _RHSM_INTERFACE_CONFIG)
06f198
 		return "Config";
06f198
 	if (kind == _RHSM_INTERFACE_REGISTER_SERVER)
06f198
 		return "RegisterServer";
06f198
 	if (kind == _RHSM_INTERFACE_ATTACH)
06f198
 		return "Attach";
06f198
 	if (kind == _RHSM_INTERFACE_ENTITLEMENT)
06f198
 		return "Entitlement";
06f198
 	if (kind == _RHSM_INTERFACE_PRODUCTS)
06f198
 		return "Products";
06f198
 	if (kind == _RHSM_INTERFACE_CONSUMER)
06f198
 		return "Consumer";
06f198
 	if (kind == _RHSM_INTERFACE_SYSPURPOSE)
06f198
 		return "Syspurpose";
06f198
 	return NULL;
06f198
@@ -782,62 +781,60 @@ _client_load (GsdSubscriptionManager *manager, GError **error)
06f198
 {
06f198
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
06f198
 
06f198
 	priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
06f198
 
06f198
 	/* connect to all the interfaces on the *different* objects :| */
06f198
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++) {
06f198
 		const gchar *kind = _rhsm_interface_to_string (i);
06f198
 		g_autofree gchar *opath = g_strdup_printf ("/com/redhat/RHSM1/%s", kind);
06f198
 		g_autofree gchar *iface = g_strdup_printf ("com.redhat.RHSM1.%s", kind);
06f198
 		priv->proxies[i] =
06f198
 			g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
06f198
 						       G_DBUS_PROXY_FLAGS_NONE,
06f198
 						       NULL,
06f198
 						       "com.redhat.RHSM1",
06f198
 						       opath, iface,
06f198
 						       NULL,
06f198
 						       error);
06f198
 		if (priv->proxies[i] == NULL)
06f198
 			return FALSE;
06f198
 		/* we want to get notified if the status of the system changes */
06f198
 		g_signal_connect (priv->proxies[i], "g-signal",
06f198
 				  G_CALLBACK (_subman_proxy_signal_cb), manager);
06f198
 	}
06f198
 
06f198
 	/* get initial status */
06f198
 	if (!_client_update_config (manager, error))
06f198
 		return FALSE;
06f198
 	if (!_client_subscription_status_update (manager, error))
06f198
 		return FALSE;
06f198
-	if (!_client_installed_products_update (manager, error))
06f198
-		return FALSE;
06f198
 	if (!_client_syspurpose_update (manager, error))
06f198
 		return FALSE;
06f198
 
06f198
 	/* success */
06f198
 	return TRUE;
06f198
 }
06f198
 
06f198
 gboolean
06f198
 gsd_subscription_manager_start (GsdSubscriptionManager *manager, GError **error)
06f198
 {
06f198
 	gboolean ret;
06f198
 	g_debug ("Starting subscription manager");
06f198
 	gnome_settings_profile_start (NULL);
06f198
 	ret = _client_load (manager, error);
06f198
 	_client_maybe__show_notification (manager);
06f198
 	gnome_settings_profile_end (NULL);
06f198
 	return ret;
06f198
 }
06f198
 
06f198
 void
06f198
 gsd_subscription_manager_stop (GsdSubscriptionManager *manager)
06f198
 {
06f198
 	g_debug ("Stopping subscription manager");
06f198
 	_client_unload (manager);
06f198
 }
06f198
 
06f198
 static void
06f198
 gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass)
06f198
 {
06f198
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
06f198
-- 
06f198
2.30.0
06f198