From 236de075e655c966f8570fc21277240fd7fcf4ca Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 6 Jun 2012 10:54:16 -0400 Subject: [PATCH] Add id.* and partition.* polkit variables These variables can be useful for making authorization decisions. Signed-off-by: David Zeuthen --- doc/udisks2-docs.xml | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/udisksdaemonutil.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/doc/udisks2-docs.xml b/doc/udisks2-docs.xml index 07e8fc3..d891ea6 100644 --- a/doc/udisks2-docs.xml +++ b/doc/udisks2-docs.xml @@ -205,6 +205,7 @@ drive Like device, but if the object is also a drive, this variable includes Vital Product Data about the drive such as the vendor and model identifiers (if available), for example INTEL SSDSA2MH080G1GC (/dev/sda1). Otherwise is just set to the same value as device. If the object is not a block device, this is not set (it is however set if the object is a block device but not a drive). + drive.wwn If the object is a drive, this is set to the World Wide Name (See Drive:WWN). If the object is not a drive, this is not set. @@ -229,6 +230,49 @@ drive.removable If the object is a drive that is considered removable, set to true (See Drive:Removable). If the object is not a drive, this is not set. + + + id.type + If the object is a block device, this property is set to the value of the Block:IdType property. If the object is not a block device, this is not set. + + + id.usage + If the object is a block device, this property is set to the value of the Block:IdUsage property. If the object is not a block device, this is not set. + + + id.version + If the object is a block device, this property is set to the value of the Block:IdVersion property. If the object is not a block device, this is not set. + + + id.label + If the object is a block device, this property is set to the value of the Block:IdLabel property. If the object is not a block device, this is not set. + + + id.uuid + If the object is a block device, this property is set to the value of the Block:IdUUID property. If the object is not a block device, this is not set. + + + + partition.number + If the object is a partition, this property is set to the value of the Partition:Number property. If the object is not a partition, this is not set. + + + partition.type + If the object is a partition, this property is set to the value of the Partition:Type property. If the object is not a partition, this is not set. + + + partition.flags + If the object is a partition, this property is set to the value of the Partition:Flags property. If the object is not a partition, this is not set. + + + partition.name + If the object is a partition, this property is set to the value of the Partition:Name property. If the object is not a partition, this is not set. + + + partition.uuid + If the object is a partition, this property is set to the value of the Partition:UUID property. If the object is not a partition, this is not set. + + diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c index afd7726..89698d4 100644 --- a/src/udisksdaemonutil.c +++ b/src/udisksdaemonutil.c @@ -21,6 +21,8 @@ #include "config.h" #include +#include + #include #include #include @@ -405,10 +407,26 @@ udisks_daemon_util_setup_by_user (UDisksDaemon *daemon, static void _safe_polkit_details_insert (PolkitDetails *details, const gchar *key, const gchar *value) { - if (value != NULL) + if (value != NULL && strlen (value) > 0) polkit_details_insert (details, key, value); } +static void +_safe_polkit_details_insert_int (PolkitDetails *details, const gchar *key, gint value) +{ + gchar buf[32]; + snprintf (buf, sizeof buf, "%d", value); + polkit_details_insert (details, key, buf); +} + +static void +_safe_polkit_details_insert_uint64 (PolkitDetails *details, const gchar *key, guint64 value) +{ + gchar buf[32]; + snprintf (buf, sizeof buf, "0x%08llx", (unsigned long long int) value); + polkit_details_insert (details, key, buf); +} + /** * udisks_daemon_util_check_authorization_sync: * @daemon: A #UDisksDaemon. @@ -461,6 +479,7 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, gboolean ret = FALSE; UDisksBlock *block = NULL; UDisksDrive *drive = NULL; + UDisksPartition *partition = NULL; UDisksObject *block_object = NULL; UDisksObject *drive_object = NULL; gboolean auth_no_user_interaction = FALSE; @@ -493,6 +512,8 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, if (drive_object != NULL) drive = udisks_object_get_drive (drive_object); } + + partition = udisks_object_get_partition (object); } if (block != NULL) @@ -539,6 +560,24 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, polkit_details_insert (details, "drive.removable", "true"); } + if (block != NULL) + { + _safe_polkit_details_insert (details, "id.type", udisks_block_get_id_type (block)); + _safe_polkit_details_insert (details, "id.usage", udisks_block_get_id_usage (block)); + _safe_polkit_details_insert (details, "id.version", udisks_block_get_id_version (block)); + _safe_polkit_details_insert (details, "id.label", udisks_block_get_id_label (block)); + _safe_polkit_details_insert (details, "id.uuid", udisks_block_get_id_uuid (block)); + } + + if (partition != NULL) + { + _safe_polkit_details_insert_int (details, "partition.number", udisks_partition_get_number (partition)); + _safe_polkit_details_insert (details, "partition.type", udisks_partition_get_type_ (partition)); + _safe_polkit_details_insert_uint64 (details, "partition.flags", udisks_partition_get_flags (partition)); + _safe_polkit_details_insert (details, "partition.name", udisks_partition_get_name (partition)); + _safe_polkit_details_insert (details, "partition.uuid", udisks_partition_get_uuid (partition)); + } + /* Fall back to Block:preferred-device */ if (details_drive == NULL && block != NULL) details_drive = udisks_block_dup_preferred_device (block); @@ -592,6 +631,7 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, g_clear_object (&block_object); g_clear_object (&drive_object); g_clear_object (&block); + g_clear_object (&partition); g_clear_object (&drive); g_clear_object (&subject); g_clear_object (&details); -- 2.7.4