Blame SOURCES/0004-subman-Drop-userlang-field.patch

6486b0
From df08a65d86626ff135a12d96cff6f48f3f1864ae Mon Sep 17 00:00:00 2001
6486b0
From: Ray Strode <rstrode@redhat.com>
6486b0
Date: Thu, 20 Aug 2020 11:20:47 -0400
6486b0
Subject: [PATCH 04/15] subman: Drop userlang field
6486b0
6486b0
It's currently always erroneously set to empty string.
6486b0
6486b0
This commit drops it, and just uses "C.UTF-8" everywhere,
6486b0
which is what we actually want.
6486b0
---
6486b0
 plugins/subman/gsd-subscription-manager.c | 14 ++++++--------
6486b0
 1 file changed, 6 insertions(+), 8 deletions(-)
6486b0
6486b0
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
6486b0
index a8c18a26..46f051a5 100644
6486b0
--- a/plugins/subman/gsd-subscription-manager.c
6486b0
+++ b/plugins/subman/gsd-subscription-manager.c
6486b0
@@ -45,61 +45,60 @@ static const gchar introspection_xml[] =
6486b0
 "      <arg type='a{sv}' name='options' direction='in'/>"
6486b0
 "    </method>"
6486b0
 "    <method name='Unregister'/>"
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
-	const gchar	*userlang;	/* owned by GLib internally */
6486b0
 	GHashTable	*config; 	/* str:str */
6486b0
 	GPtrArray	*installed_products;
6486b0
 	gchar		*address;
6486b0
 
6486b0
 	GTimer		*timer_last_notified;
6486b0
 	NotifyNotification	*notification_expired;
6486b0
 	NotifyNotification	*notification_registered;
6486b0
 	NotifyNotification	*notification_registration_required;
6486b0
 	GsdSubmanSubscriptionStatus	 subscription_status;
6486b0
 	GsdSubmanSubscriptionStatus	 subscription_status_last;
6486b0
 };
6486b0
 
6486b0
 enum {
6486b0
 	PROP_0,
6486b0
 };
6486b0
 
6486b0
 static void     gsd_subscription_manager_class_init  (GsdSubscriptionManagerClass *klass);
6486b0
 static void     gsd_subscription_manager_init        (GsdSubscriptionManager      *subscription_manager);
6486b0
 static void     gsd_subscription_manager_finalize    (GObject             *object);
6486b0
 
6486b0
 G_DEFINE_TYPE (GsdSubscriptionManager, gsd_subscription_manager, G_TYPE_OBJECT)
6486b0
 
6486b0
 typedef struct
6486b0
 {
6486b0
 	gchar *product_name;
6486b0
 	gchar *product_id;
6486b0
 	gchar *version;
6486b0
 	gchar *arch;
6486b0
 	gchar *status;
6486b0
 	gchar *starts;
6486b0
@@ -197,61 +196,61 @@ _emit_property_changed (GsdSubscriptionManager *manager,
6486b0
 			       property_value);
6486b0
 	g_dbus_connection_emit_signal (priv->connection,
6486b0
 				       NULL,
6486b0
 				       GSD_SUBSCRIPTION_DBUS_PATH,
6486b0
 				       "org.freedesktop.DBus.Properties",
6486b0
 				       "PropertiesChanged",
6486b0
 				       g_variant_new ("(sa{sv}as)",
6486b0
 				       GSD_SUBSCRIPTION_DBUS_INTERFACE,
6486b0
 				       &builder,
6486b0
 				       &invalidated_builder),
6486b0
 				       NULL);
6486b0
 	g_variant_builder_clear (&builder);
6486b0
 	g_variant_builder_clear (&invalidated_builder);
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_installed_products_update (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	JsonNode *json_root;
6486b0
 	JsonArray *json_products_array;
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_PRODUCTS],
6486b0
 				      "ListInstalledProducts",
6486b0
 				      g_variant_new ("(sa{sv}s)",
6486b0
 						     ""   /* filter_string */,
6486b0
 						     NULL /* proxy_options */,
6486b0
-						     priv->userlang),
6486b0
+						     "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 ("Products.ListInstalledProducts 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_products_array = json_node_get_array (json_root);
6486b0
 	if (json_products_array == NULL) {
6486b0
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
6486b0
 			     "no InstalledProducts array in %s", json_txt);
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	g_ptr_array_set_size (priv->installed_products, 0);
6486b0
 
6486b0
 	for (guint i = 0; i < json_array_get_length (json_products_array); i++) {
6486b0
 		JsonArray *json_product = json_array_get_array_element (json_products_array, i);
6486b0
 		g_autoptr(ProductData) product = g_new0 (ProductData, 1);
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
@@ -263,179 +262,179 @@ _client_installed_products_update (GsdSubscriptionManager *manager, GError **err
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
 	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(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
-						     priv->userlang),
6486b0
+						     "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 ("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
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
6486b0
 			     "no Entitlement.GetStatus status 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
 
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)", priv->userlang),
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
 		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
 		g_debug ("Syspurpose.GetSyspurpose: Unknown");
6486b0
 		return TRUE;
6486b0
 	}
6486b0
 	g_debug ("Syspurpose.GetSyspurpose: '%s", json_object_get_string_member (json_obj, "status"));
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_register_start (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	const gchar *address = NULL;
6486b0
 	g_autoptr(GDBusProxy) proxy = NULL;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 
6486b0
 	/* already started */
6486b0
 	if (priv->address != NULL)
6486b0
 		return TRUE;
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
 	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
6486b0
 					       G_DBUS_PROXY_FLAGS_NONE,
6486b0
 					       NULL,
6486b0
 					       "com.redhat.RHSM1",
6486b0
 					       "/com/redhat/RHSM1/RegisterServer",
6486b0
 					       "com.redhat.RHSM1.RegisterServer",
6486b0
 					       NULL, error);
6486b0
 	if (proxy == NULL)
6486b0
 		return FALSE;
6486b0
 	val = g_dbus_proxy_call_sync (proxy, "Start",
6486b0
-				      g_variant_new ("(s)", priv->userlang),
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)", &address);
6486b0
 	g_debug ("RegisterServer.Start: %s", address);
6486b0
 	priv->address = g_strdup (address);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_register_stop (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GDBusProxy) proxy = NULL;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 
6486b0
 	/* already started */
6486b0
 	if (priv->address == NULL)
6486b0
 		return TRUE;
6486b0
 
6486b0
 	/* stop registration server */
6486b0
 	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
6486b0
 					       G_DBUS_PROXY_FLAGS_NONE,
6486b0
 					       NULL,
6486b0
 					       "com.redhat.RHSM1",
6486b0
 					       "/com/redhat/RHSM1/RegisterServer",
6486b0
 					       "com.redhat.RHSM1.RegisterServer",
6486b0
 					       NULL, error);
6486b0
 	if (proxy == NULL)
6486b0
 		return FALSE;
6486b0
 	val = g_dbus_proxy_call_sync (proxy, "Stop",
6486b0
-				      g_variant_new ("(s)", priv->userlang),
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_clear_pointer (&priv->address, g_free);
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_subprocess_wait_check (GSubprocess *subprocess, GError **error)
6486b0
 {
6486b0
 	gint rc;
6486b0
 	if (!g_subprocess_wait (subprocess, NULL, error)) {
6486b0
 		g_prefix_error (error, "failed to run pkexec: ");
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 	rc = g_subprocess_get_exit_status (subprocess);
6486b0
 	if (rc != 0) {
6486b0
 		GInputStream *istream = g_subprocess_get_stderr_pipe (subprocess);
6486b0
 		gchar buf[1024] = { 0x0 };
6486b0
 		gsize sz = 0;
6486b0
 		g_input_stream_read_all (istream, buf, sizeof(buf) - 1, &sz, NULL, NULL);
6486b0
 		if (sz == 0) {
6486b0
 			g_set_error_literal (error, G_IO_ERROR, rc,
6486b0
 					     "Failed to run helper without stderr");
6486b0
 			return FALSE;
6486b0
 		}
6486b0
 		g_set_error_literal (error, G_IO_ERROR, rc, buf);
6486b0
 		return FALSE;
6486b0
 	}
6486b0
@@ -637,61 +636,61 @@ _client_unregister (GsdSubscriptionManager *manager, GError **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_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)", priv->userlang),
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
 }
6486b0
 
6486b0
 static void
6486b0
 _subman_proxy_signal_cb (GDBusProxy *proxy,
6486b0
 			 const gchar *sender_name,
6486b0
 			 const gchar *signal_name,
6486b0
 			 GVariant *parameters,
6486b0
 			 GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_autoptr(GError) error = NULL;
6486b0
 	if (!_client_syspurpose_update (manager, &error)) {
6486b0
 		g_warning ("failed to update syspurpose: %s", error->message);
6486b0
 		g_clear_error (&error);
6486b0
 	}
6486b0
@@ -736,61 +735,60 @@ _rhsm_interface_to_string (_RhsmInterface kind)
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_load (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 
6486b0
 	priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
6486b0
 
6486b0
 	/* connect to all the interfaces on the *different* objects :| */
6486b0
 	for (guint i = 0; i < _RHSM_INTERFACE_LAST; i++) {
6486b0
 		const gchar *kind = _rhsm_interface_to_string (i);
6486b0
 		g_autofree gchar *opath = g_strdup_printf ("/com/redhat/RHSM1/%s", kind);
6486b0
 		g_autofree gchar *iface = g_strdup_printf ("com.redhat.RHSM1.%s", kind);
6486b0
 		priv->proxies[i] =
6486b0
 			g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
6486b0
 						       G_DBUS_PROXY_FLAGS_NONE,
6486b0
 						       NULL,
6486b0
 						       "com.redhat.RHSM1",
6486b0
 						       opath, iface,
6486b0
 						       NULL,
6486b0
 						       error);
6486b0
 		if (priv->proxies[i] == NULL)
6486b0
 			return FALSE;
6486b0
 		/* we want to get notified if the status of the system changes */
6486b0
 		g_signal_connect (priv->proxies[i], "g-signal",
6486b0
 				  G_CALLBACK (_subman_proxy_signal_cb), manager);
6486b0
 	}
6486b0
 
6486b0
 	/* get initial status */
6486b0
-	priv->userlang = "";
6486b0
 	if (!_client_update_config (manager, 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
 	if (!_client_syspurpose_update (manager, error))
6486b0
 		return FALSE;
6486b0
 
6486b0
 	/* success */
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 gboolean
6486b0
 gsd_subscription_manager_start (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	gboolean ret;
6486b0
 	g_debug ("Starting subscription manager");
6486b0
 	gnome_settings_profile_start (NULL);
6486b0
 	ret = _client_load (manager, error);
6486b0
 	_client_maybe__show_notification (manager);
6486b0
 	gnome_settings_profile_end (NULL);
6486b0
 	return ret;
6486b0
 }
6486b0
 
6486b0
 void
6486b0
 gsd_subscription_manager_stop (GsdSubscriptionManager *manager)
6486b0
 {
6486b0
 	g_debug ("Stopping subscription manager");
6486b0
 	_client_unload (manager);
6486b0
-- 
6486b0
2.30.0
6486b0