Skip to content

Commit

Permalink
udiskslinuxblock: check recursively for CryptoBackingDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
GovanifY committed Jan 12, 2025
1 parent 8ffd11c commit 88945a6
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/udiskslinuxblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ udisks_linux_block_new (void)
/* ---------------------------------------------------------------------------------------------------- */

static gchar *
get_sysfs_attr (GUdevDevice *device,
get_sysfs_attr_from_path (const gchar *sysfs_path,
const gchar *attr)
{
gchar *filename = NULL;
gchar *value = NULL;
gboolean ret = FALSE;
GError *error = NULL;

filename = g_strconcat (g_udev_device_get_sysfs_path (device),
filename = g_strconcat (sysfs_path,
"/",
attr,
NULL);
Expand Down Expand Up @@ -1025,46 +1025,49 @@ udisks_linux_block_update (UDisksLinuxBlock *block,
udisks_block_set_crypto_backing_device (iface, "/");
if (g_str_has_prefix (g_udev_device_get_name (device->udev_device), "dm-"))
{
gchar *dm_uuid;
dm_uuid = get_sysfs_attr (device->udev_device, "dm/uuid");
if (dm_uuid != NULL &&
(g_str_has_prefix (dm_uuid, "CRYPT-LUKS") || g_str_has_prefix (dm_uuid, "CRYPT-BITLK") || g_str_has_prefix (dm_uuid, "CRYPT-TCRYPT")))
{
gchar *slave_sysfs_path;
slave_sysfs_path = get_slave_sysfs_path (g_udev_device_get_sysfs_path (device->udev_device));
gchar *slave_sysfs_path = g_strdup (g_udev_device_get_sysfs_path (device->udev_device));
gchar *old_sysfs_path = NULL;

while (slave_sysfs_path)
while (slave_sysfs_path)
{
gchar *dm_uuid = get_sysfs_attr_from_path (slave_sysfs_path,"dm/uuid");
if (dm_uuid != NULL)
{
UDisksLinuxBlockObject *slave_object;
slave_object = find_block_device_by_sysfs_path (object_manager, slave_sysfs_path);
if (slave_object != NULL)
{
UDisksEncrypted *enc;

udisks_block_set_crypto_backing_device (iface,
g_dbus_object_get_object_path (G_DBUS_OBJECT (slave_object)));
old_sysfs_path = slave_sysfs_path;
slave_sysfs_path = get_slave_sysfs_path (old_sysfs_path);
g_free (old_sysfs_path);

/* also set the CleartextDevice property for the parent device */
enc = udisks_object_peek_encrypted (UDISKS_OBJECT (slave_object));
if (enc != NULL)
{
udisks_encrypted_set_cleartext_device (UDISKS_ENCRYPTED (enc),
g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
}

g_object_unref (slave_object);
g_free (slave_sysfs_path);
if (g_str_has_prefix (dm_uuid, "CRYPT-LUKS") || g_str_has_prefix (dm_uuid, "CRYPT-BITLK") || g_str_has_prefix (dm_uuid, "CRYPT-TCRYPT"))
{
/* found crypted device, break here */
g_free (dm_uuid);
break;
}
else
}
}
if (slave_sysfs_path)
{
UDisksLinuxBlockObject *slave_object;
slave_object = find_block_device_by_sysfs_path (object_manager, slave_sysfs_path);
if (slave_object != NULL)
{
UDisksEncrypted *enc;

udisks_block_set_crypto_backing_device (iface,
g_dbus_object_get_object_path (G_DBUS_OBJECT (slave_object)));

/* also set the CleartextDevice property for the parent device */
enc = udisks_object_peek_encrypted (UDISKS_OBJECT (slave_object));
if (enc != NULL)
{
gchar *old_sysfs_path = slave_sysfs_path;
slave_sysfs_path = get_slave_sysfs_path (old_sysfs_path);
g_free (old_sysfs_path);
udisks_encrypted_set_cleartext_device (UDISKS_ENCRYPTED (enc),
g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
}

g_object_unref (slave_object);
g_free (slave_sysfs_path);
}
}
g_free (dm_uuid);
}

/* Sort out preferred device... this is what UI shells should
Expand Down

0 comments on commit 88945a6

Please sign in to comment.