Export the salted machine ID as a daemon property

This commit is contained in:
Richard Hughes 2019-09-21 12:55:37 +01:00
parent a45994cb4a
commit 0917fb6aec
7 changed files with 83 additions and 0 deletions

View File

@ -41,6 +41,7 @@ typedef struct {
guint percentage;
gchar *daemon_version;
gchar *host_product;
gchar *host_machine_id;
GDBusConnection *conn;
GDBusProxy *proxy;
} FwupdClientPrivate;
@ -61,6 +62,7 @@ enum {
PROP_DAEMON_VERSION,
PROP_TAINTED,
PROP_HOST_PRODUCT,
PROP_HOST_MACHINE_ID,
PROP_LAST
};
@ -113,6 +115,15 @@ fwupd_client_set_host_product (FwupdClient *client, const gchar *host_product)
g_object_notify (G_OBJECT (client), "host-product");
}
static void
fwupd_client_set_host_machine_id (FwupdClient *client, const gchar *host_machine_id)
{
FwupdClientPrivate *priv = GET_PRIVATE (client);
g_free (priv->host_machine_id);
priv->host_machine_id = g_strdup (host_machine_id);
g_object_notify (G_OBJECT (client), "host-machine-id");
}
static void
fwupd_client_set_daemon_version (FwupdClient *client, const gchar *daemon_version)
{
@ -172,6 +183,12 @@ fwupd_client_properties_changed_cb (GDBusProxy *proxy,
if (val != NULL)
fwupd_client_set_host_product (client, g_variant_get_string (val, NULL));
}
if (g_variant_dict_contains (dict, "HostMachineId")) {
g_autoptr(GVariant) val = NULL;
val = g_dbus_proxy_get_cached_property (proxy, "HostMachineId");
if (val != NULL)
fwupd_client_set_host_machine_id (client, g_variant_get_string (val, NULL));
}
}
static void
@ -269,6 +286,9 @@ fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **e
val = g_dbus_proxy_get_cached_property (priv->proxy, "HostProduct");
if (val != NULL)
fwupd_client_set_host_product (client, g_variant_get_string (val, NULL));
val = g_dbus_proxy_get_cached_property (priv->proxy, "HostMachineId");
if (val != NULL)
fwupd_client_set_host_machine_id (client, g_variant_get_string (val, NULL));
return TRUE;
}
@ -1189,6 +1209,24 @@ fwupd_client_get_host_product (FwupdClient *client)
return priv->host_product;
}
/**
* fwupd_client_get_host_machine_id:
* @client: A #FwupdClient
*
* Gets the string that represents the host machine ID
*
* Returns: a string, or %NULL for unknown.
*
* Since: 1.3.2
**/
const gchar *
fwupd_client_get_host_machine_id (FwupdClient *client)
{
FwupdClientPrivate *priv = GET_PRIVATE (client);
g_return_val_if_fail (FWUPD_IS_CLIENT (client), FALSE);
return priv->host_machine_id;
}
/**
* fwupd_client_get_status:
* @client: A #FwupdClient
@ -1714,6 +1752,9 @@ fwupd_client_get_property (GObject *object, guint prop_id,
case PROP_HOST_PRODUCT:
g_value_set_string (value, priv->host_product);
break;
case PROP_HOST_MACHINE_ID:
g_value_set_string (value, priv->host_machine_id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1890,6 +1931,16 @@ fwupd_client_class_init (FwupdClientClass *klass)
NULL, G_PARAM_READABLE | G_PARAM_STATIC_NAME);
g_object_class_install_property (object_class, PROP_HOST_PRODUCT, pspec);
/**
* FwupdClient:host-machine-id:
*
* The host machine-id string
*
* Since: 1.3.2
*/
pspec = g_param_spec_string ("host-machine-id", NULL, NULL,
NULL, G_PARAM_READABLE | G_PARAM_STATIC_NAME);
g_object_class_install_property (object_class, PROP_HOST_MACHINE_ID, pspec);
}
static void
@ -1905,6 +1956,7 @@ fwupd_client_finalize (GObject *object)
g_free (priv->daemon_version);
g_free (priv->host_product);
g_free (priv->host_machine_id);
if (priv->conn != NULL)
g_object_unref (priv->conn);
if (priv->proxy != NULL)

View File

@ -128,6 +128,7 @@ gboolean fwupd_client_get_tainted (FwupdClient *client);
guint fwupd_client_get_percentage (FwupdClient *client);
const gchar *fwupd_client_get_daemon_version (FwupdClient *client);
const gchar *fwupd_client_get_host_product (FwupdClient *client);
const gchar *fwupd_client_get_host_machine_id (FwupdClient *client);
GPtrArray *fwupd_client_get_remotes (FwupdClient *client,
GCancellable *cancellable,

View File

@ -382,6 +382,7 @@ LIBFWUPD_1.3.1 {
LIBFWUPD_1.3.2 {
global:
fwupd_client_get_host_machine_id;
fwupd_release_add_issue;
fwupd_release_get_issues;
local: *;

View File

@ -77,6 +77,7 @@ struct _FuEngine
GHashTable *runtime_versions;
GHashTable *compile_versions;
GHashTable *approved_firmware;
gchar *host_machine_id;
gboolean loaded;
};
@ -4160,6 +4161,13 @@ fu_engine_get_host_product (FuEngine *self)
return fu_hwids_get_value (self->hwids, FU_HWIDS_KEY_PRODUCT_NAME);
}
const gchar *
fu_engine_get_host_machine_id (FuEngine *self)
{
g_return_val_if_fail (FU_IS_ENGINE (self), NULL);
return self->host_machine_id;
}
gboolean
fu_engine_load_plugins (FuEngine *self, GError **error)
{
@ -4573,6 +4581,11 @@ fu_engine_load (FuEngine *self, FuEngineLoadFlags flags, GError **error)
if (self->loaded)
return TRUE;
/* cache machine ID so we can use it from a sandboxed app */
self->host_machine_id = fwupd_build_machine_id ("fwupd", error);
if (self->host_machine_id == NULL)
return FALSE;
/* read config file */
if (flags & FU_ENGINE_LOAD_FLAG_READONLY_FS)
config_flags |= FU_CONFIG_LOAD_FLAG_READONLY_FS;
@ -4820,6 +4833,7 @@ fu_engine_finalize (GObject *obj)
if (self->coldplug_id != 0)
g_source_remove (self->coldplug_id);
g_free (self->host_machine_id);
g_object_unref (self->idle);
g_object_unref (self->config);
g_object_unref (self->smbios);

View File

@ -49,6 +49,7 @@ gboolean fu_engine_load_plugins (FuEngine *self,
GError **error);
gboolean fu_engine_get_tainted (FuEngine *self);
const gchar *fu_engine_get_host_product (FuEngine *self);
const gchar *fu_engine_get_host_machine_id (FuEngine *self);
FwupdStatus fu_engine_get_status (FuEngine *self);
XbSilo *fu_engine_get_silo_from_blob (FuEngine *self,
GBytes *blob_cab,

View File

@ -1366,6 +1366,9 @@ fu_main_daemon_get_property (GDBusConnection *connection_, const gchar *sender,
if (g_strcmp0 (property_name, "HostProduct") == 0)
return g_variant_new_string (fu_engine_get_host_product (priv->engine));
if (g_strcmp0 (property_name, "HostMachineId") == 0)
return g_variant_new_string (fu_engine_get_host_machine_id (priv->engine));
/* return an error */
g_set_error (error,
G_DBUS_ERROR,

View File

@ -33,6 +33,17 @@
</doc:doc>
</property>
<!--***********************************************************-->
<property name='HostMachineId' type='s' access='read'>
<doc:doc>
<doc:description>
<doc:para>
The machine ID for the host.
</doc:para>
</doc:description>
</doc:doc>
</property>
<!--***********************************************************-->
<property name='Tainted' type='b' access='read'>
<doc:doc>