Blame SOURCES/0012-subman-Add-DBus-API-to-subscribe-for-updates-on-alre.patch

6486b0
From 3bb3b2b09d34deafadd3cfe3355137afab20cb23 Mon Sep 17 00:00:00 2001
6486b0
From: Ray Strode <rstrode@redhat.com>
6486b0
Date: Sun, 24 Jan 2021 11:27:42 -0500
6486b0
Subject: [PATCH 12/15] subman: Add DBus API to subscribe for updates on
6486b0
 already registered system
6486b0
6486b0
It's possible an admin may have registered their system without
6486b0
attaching any subscriptions to it.
6486b0
6486b0
At the moment, gnome-settings-daemon only provides a way to register
6486b0
and subscribe in one step.
6486b0
6486b0
This commit adds an API to support doing the last half of the process
6486b0
on its own.
6486b0
---
6486b0
 plugins/subman/gsd-subscription-manager.c | 51 +++++++++++++++++++++++
6486b0
 1 file changed, 51 insertions(+)
6486b0
6486b0
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
6486b0
index 1f9ca447..705f8b11 100644
6486b0
--- a/plugins/subman/gsd-subscription-manager.c
6486b0
+++ b/plugins/subman/gsd-subscription-manager.c
6486b0
@@ -19,60 +19,61 @@
6486b0
  */
6486b0
 
6486b0
 #include "config.h"
6486b0
 
6486b0
 #include <glib/gi18n.h>
6486b0
 #include <gio/gunixinputstream.h>
6486b0
 #include <gdk/gdk.h>
6486b0
 #include <gtk/gtk.h>
6486b0
 #include <json-glib/json-glib.h>
6486b0
 #include <libnotify/notify.h>
6486b0
 
6486b0
 #include "gnome-settings-profile.h"
6486b0
 #include "gsd-subman-common.h"
6486b0
 #include "gsd-subscription-manager.h"
6486b0
 
6486b0
 #define GSD_DBUS_NAME "org.gnome.SettingsDaemon"
6486b0
 #define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
6486b0
 #define GSD_DBUS_BASE_INTERFACE "org.gnome.SettingsDaemon"
6486b0
 
6486b0
 #define GSD_SUBSCRIPTION_DBUS_NAME		GSD_DBUS_NAME ".Subscription"
6486b0
 #define GSD_SUBSCRIPTION_DBUS_PATH		GSD_DBUS_PATH "/Subscription"
6486b0
 #define GSD_SUBSCRIPTION_DBUS_INTERFACE		GSD_DBUS_BASE_INTERFACE ".Subscription"
6486b0
 
6486b0
 static const gchar introspection_xml[] =
6486b0
 "<node>"
6486b0
 "  <interface name='org.gnome.SettingsDaemon.Subscription'>"
6486b0
 "    <method name='Register'>"
6486b0
 "      <arg type='a{sv}' name='options' direction='in'/>"
6486b0
 "    </method>"
6486b0
 "    <method name='Unregister'/>"
6486b0
+"    <method name='Attach'/>"
6486b0
 "    <property name='InstalledProducts' type='aa{sv}' access='read'/>"
6486b0
 "    <property name='SubscriptionStatus' type='u' access='read'/>"
6486b0
 "  </interface>"
6486b0
 "</node>";
6486b0
 
6486b0
 #define GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SUBSCRIPTION_MANAGER, GsdSubscriptionManagerPrivate))
6486b0
 
6486b0
 typedef enum {
6486b0
 	_RHSM_INTERFACE_CONFIG,
6486b0
 	_RHSM_INTERFACE_REGISTER_SERVER,
6486b0
 	_RHSM_INTERFACE_ATTACH,
6486b0
 	_RHSM_INTERFACE_ENTITLEMENT,
6486b0
 	_RHSM_INTERFACE_PRODUCTS,
6486b0
 	_RHSM_INTERFACE_CONSUMER,
6486b0
 	_RHSM_INTERFACE_SYSPURPOSE,
6486b0
 	_RHSM_INTERFACE_LAST
6486b0
 } _RhsmInterface;
6486b0
 
6486b0
 struct GsdSubscriptionManagerPrivate
6486b0
 {
6486b0
 	/* D-Bus */
6486b0
 	guint		 name_id;
6486b0
 	GDBusNodeInfo	*introspection_data;
6486b0
 	GDBusConnection	*connection;
6486b0
 	GCancellable	*bus_cancellable;
6486b0
 
6486b0
 	GDBusProxy	*proxies[_RHSM_INTERFACE_LAST];
6486b0
 	GHashTable	*config; 	/* str:str */
6486b0
 	GPtrArray	*installed_products;
6486b0
 	gchar		*address;
6486b0
@@ -669,60 +670,104 @@ _client_register (GsdSubscriptionManager *manager,
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_unregister (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
 
6486b0
 	/* apparently: "we can't send registration credentials over the regular
6486b0
 	 * system or session bus since those aren't really locked down..." */
6486b0
 	if (!_client_register_start (manager, error))
6486b0
 		return FALSE;
6486b0
 	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
 	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
6486b0
 				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
 				       "--kind", "unregister",
6486b0
 				       NULL);
6486b0
 	if (subprocess == NULL) {
6486b0
 		g_prefix_error (error, "failed to find pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	if (!_client_subprocess_wait_check (subprocess, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_subscription_status_update (manager, error))
6486b0
 		return FALSE;
6486b0
 	if (!_client_installed_products_update (manager, error))
6486b0
 		return FALSE;
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
+static gboolean
6486b0
+_client_attach (GsdSubscriptionManager *manager,
6486b0
+		GError **error)
6486b0
+{
6486b0
+	g_autoptr(GSubprocess) subprocess = NULL;
6486b0
+	g_autoptr(GBytes) stderr_buf = NULL;
6486b0
+	gint rc;
6486b0
+
6486b0
+	g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
6486b0
+	subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE,
6486b0
+				       error,
6486b0
+				       "pkexec", LIBEXECDIR "/gsd-subman-helper",
6486b0
+				       "--kind", "auto-attach",
6486b0
+				       NULL);
6486b0
+	if (subprocess == NULL) {
6486b0
+		g_prefix_error (error, "failed to find pkexec: ");
6486b0
+		return FALSE;
6486b0
+	}
6486b0
+
6486b0
+	if (!g_subprocess_communicate (subprocess, NULL, NULL, NULL, &stderr_buf, error)) {
6486b0
+		g_prefix_error (error, "failed to run pkexec: ");
6486b0
+		return FALSE;
6486b0
+	}
6486b0
+
6486b0
+	rc = g_subprocess_get_exit_status (subprocess);
6486b0
+	if (rc != 0) {
6486b0
+		if (g_bytes_get_size (stderr_buf) == 0) {
6486b0
+			g_set_error_literal (error, G_IO_ERROR, rc,
6486b0
+			                     "Failed to run helper without stderr");
6486b0
+			return FALSE;
6486b0
+		}
6486b0
+
6486b0
+		g_set_error (error, G_IO_ERROR, rc,
6486b0
+			     "%.*s",
6486b0
+			     (int) g_bytes_get_size (stderr_buf),
6486b0
+			     (char *) g_bytes_get_data (stderr_buf, NULL));
6486b0
+	}
6486b0
+
6486b0
+	if (!_client_subscription_status_update (manager, error))
6486b0
+		return FALSE;
6486b0
+	_client_maybe__show_notification (manager);
6486b0
+	return TRUE;
6486b0
+}
6486b0
+
6486b0
 static gboolean
6486b0
 _client_update_config (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 	g_autoptr(GVariant) val_server = NULL;
6486b0
 	g_autoptr(GVariantDict) dict = NULL;
6486b0
 	GVariantIter iter;
6486b0
 	gchar *key;
6486b0
 	gchar *value;
6486b0
 
6486b0
 	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONFIG],
6486b0
 				      "GetAll",
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
 	dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
6486b0
 	val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
6486b0
 	if (val_server != NULL) {
6486b0
 		g_variant_iter_init (&iter, val_server);
6486b0
 		while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
6486b0
 			g_debug ("%s=%s", key, value);
6486b0
 			g_hash_table_insert (priv->config,
6486b0
 					     g_steal_pointer (&key),
6486b0
 					     g_steal_pointer (&value));
6486b0
 		}
6486b0
 	}
6486b0
 	return TRUE;
6486b0
@@ -1002,60 +1047,66 @@ handle_method_call (GDBusConnection       *connection,
6486b0
 				g_dbus_method_invocation_return_gerror (invocation, error);
6486b0
 				return;
6486b0
 			}
6486b0
 		} else if (g_strcmp0 (kind, "key") == 0) {
6486b0
 			const gchar *activation_key = NULL;
6486b0
 			g_variant_dict_lookup (dict, "hostname", "&s", &hostname);
6486b0
 			g_variant_dict_lookup (dict, "organisation", "&s", &organisation);
6486b0
 			g_variant_dict_lookup (dict, "activation-key", "&s", &activation_key);
6486b0
 			if (!_client_register_with_keys (manager,
6486b0
 							       hostname,
6486b0
 							       organisation,
6486b0
 							       activation_key,
6486b0
 							       &error)) {
6486b0
 				g_dbus_method_invocation_return_gerror (invocation, error);
6486b0
 				return;
6486b0
 			}
6486b0
 		} else {
6486b0
 			g_dbus_method_invocation_return_error_literal (invocation,
6486b0
 								       G_IO_ERROR, G_IO_ERROR_FAILED,
6486b0
 								       "Invalid kind specified");
6486b0
 
6486b0
 			return;
6486b0
 		}
6486b0
 		g_dbus_method_invocation_return_value (invocation, NULL);
6486b0
 	} else if (g_strcmp0 (method_name, "Unregister") == 0) {
6486b0
 		if (!_client_unregister (manager, &error)) {
6486b0
 			g_dbus_method_invocation_return_gerror (invocation, error);
6486b0
 			return;
6486b0
 		}
6486b0
 		g_dbus_method_invocation_return_value (invocation, NULL);
6486b0
+	} else if (g_strcmp0 (method_name, "Attach") == 0) {
6486b0
+		if (!_client_attach (manager, &error)) {
6486b0
+			g_dbus_method_invocation_return_gerror (invocation, error);
6486b0
+			return;
6486b0
+		}
6486b0
+		g_dbus_method_invocation_return_value (invocation, NULL);
6486b0
 	} else {
6486b0
 		g_assert_not_reached ();
6486b0
 	}
6486b0
 }
6486b0
 
6486b0
 static GVariant *
6486b0
 handle_get_property (GDBusConnection *connection,
6486b0
 		     const gchar *sender,
6486b0
 		     const gchar *object_path,
6486b0
 		     const gchar *interface_name,
6486b0
 		     const gchar *property_name,
6486b0
 		     GError **error, gpointer user_data)
6486b0
 {
6486b0
 	GsdSubscriptionManager *manager = GSD_SUBSCRIPTION_MANAGER (user_data);
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 
6486b0
 	if (g_strcmp0 (interface_name, GSD_SUBSCRIPTION_DBUS_INTERFACE) != 0) {
6486b0
 		g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 			     "No such interface: %s", interface_name);
6486b0
 		return NULL;
6486b0
 	}
6486b0
 
6486b0
 	if (g_strcmp0 (property_name, "SubscriptionStatus") == 0)
6486b0
 		return g_variant_new_uint32 (priv->subscription_status);
6486b0
 
6486b0
 	if (g_strcmp0 (property_name, "InstalledProducts") == 0)
6486b0
 		return _make_installed_products_variant (priv->installed_products);
6486b0
 
6486b0
 	g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
6486b0
 		     "Failed to get property: %s", property_name);
6486b0
-- 
6486b0
2.30.0
6486b0