Skip to content

Commit 5a99e01

Browse files
committed
text: Provide clearer user prompts when requesting authorization.
1 parent 874b4f0 commit 5a99e01

15 files changed

+177
-102
lines changed

doc/udisks2-docs.xml.in.in

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
<entry><parameter>device</parameter></entry>
233233
<entry>If the object is a block device, this property is set to the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Block.PreferredDevice">Block:PreferredDevice</link> property. If set, this is guaranteed to be a device file, for example <quote>/dev/vg_lucifer/lv_root</quote> or <quote>/dev/sda1</quote>. If the object is not a block device, this is not set.</entry>
234234
</row>
235+
<row>
236+
<entry><parameter>device.name</parameter></entry>
237+
<entry>The value of this property is set to the best display name for this device, which may be the device's <link linkend="gdbus-property-org-freedesktop-UDisks2-Block.IdLabel">Block:IdLabel</link>, or the capacity name calculated from the partition size, or the name associated with the encrypted volume. If none of the above information is present, the data assigned to the <parameter>drive</parameter> will be used as the fallback solution.</entry>
238+
</row>
235239
<row>
236240
<entry><parameter>drive</parameter></entry>
237241
<entry>Like the <parameter>device</parameter> variable, 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 <quote>INTEL SSDSA2MH080G1GC (/dev/sda1)</quote>. Otherwise is just set to the same value as <parameter>device</parameter>. 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).</entry>

modules/lsm/lsm_linux_drive_local.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ is_authed (GDBusMethodInvocation *invocation,
275275
UDISKS_OBJECT (block_object),
276276
LSM_POLICY_ACTION_ID,
277277
options,
278-
N_("Authentication is required to change $(drive) LED"),
278+
N_("Authentication is required to change $(device.name) LED"),
279279
invocation))
280280
goto out;
281281

src/udisksdaemonutil.c

+73-2
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,63 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
690690
return ret;
691691
}
692692

693+
694+
static gchar *
695+
get_device_display_name (UDisksBlock *block)
696+
{
697+
gchar *display_name = NULL;
698+
gchar *s = NULL;
699+
const gchar *id_label = NULL;
700+
const gchar *id_usage = NULL;
701+
const gchar *id_type = NULL;
702+
703+
if (block == NULL)
704+
goto out;
705+
706+
id_label = udisks_block_get_id_label (block);
707+
id_usage = udisks_block_get_id_usage (block);
708+
id_type = udisks_block_get_id_type (block);
709+
if (id_label != NULL && strlen (id_label) > 0)
710+
{
711+
display_name = g_strdup (id_label);
712+
}
713+
else if (g_strcmp0 (id_usage, "crypto") == 0)
714+
{
715+
s = udisks_client_get_size_for_display (NULL, udisks_block_get_size (block), FALSE, FALSE);
716+
if (g_strcmp0 (id_type, "crypto_unknown") == 0)
717+
{
718+
/* Translators: This is used for possibly encrypted volumes.
719+
* The first %s is the formatted size (e.g. "42.0 MB").
720+
*/
721+
display_name = g_strdup_printf (N_("%s Possibly Encrypted"), s);
722+
}
723+
else
724+
{
725+
/* Translators: This is used for encrypted volumes.
726+
* The first %s is the formatted size (e.g. "42.0 MB").
727+
*/
728+
display_name = g_strdup_printf (N_("%s Encrypted"), s);
729+
}
730+
g_free (s);
731+
}
732+
else
733+
{
734+
guint64 size = udisks_block_get_size (block);
735+
if (size > 0)
736+
{
737+
s = udisks_client_get_size_for_display (NULL, size, FALSE, FALSE);
738+
/* Translators: This is used for volume with no filesystem label.
739+
* The first %s is the formatted size (e.g. "42.0 MB").
740+
*/
741+
display_name = g_strdup_printf (N_("%s Volume"), s);
742+
g_free (s);
743+
}
744+
}
745+
746+
out:
747+
return display_name;
748+
}
749+
693750
/**
694751
* udisks_daemon_util_check_authorization_sync:
695752
* @daemon: A #UDisksDaemon.
@@ -716,8 +773,9 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
716773
* can be used in @message but note that not all variables can be used
717774
* in all checks. For example, any check involving a #UDisksDrive or a
718775
* #UDisksBlock object can safely include the fragment
719-
* <quote>$(drive)</quote> since it will always expand to the name of
720-
* the drive, e.g. <quote>INTEL SSDSA2MH080G1GC (/dev/sda1)</quote> or
776+
* <quote>$(device.name)</quote> since it will always expand to the name of
777+
* the partition or drive, e.g. <quote>MyUDisks (/dev/sda1)</quote> or
778+
* <quote>INTEL SSDSA2MH080G1GC (/dev/sda1)</quote> or
721779
* the block device file e.g. <quote>/dev/vg_lucifer/lv_root</quote>
722780
* or <quote>/dev/sda1</quote>. However this won't work for operations
723781
* that isn't on a drive or block device, for example calls on the
@@ -774,6 +832,7 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
774832
gboolean auth_no_user_interaction = FALSE;
775833
const gchar *details_device = NULL;
776834
gchar *details_drive = NULL;
835+
gchar *device_display_name = NULL;
777836

778837
authority = udisks_daemon_get_authority (daemon);
779838
if (authority == NULL)
@@ -885,6 +944,14 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
885944

886945
if (block != NULL)
887946
{
947+
gchar *s = NULL;
948+
s = get_device_display_name (block);
949+
if (s)
950+
{
951+
device_display_name = g_strdup_printf ("%s (%s)", s, details_device);
952+
g_free (s);
953+
}
954+
888955
_safe_polkit_details_insert (details, "id.type", udisks_block_get_id_type (block));
889956
_safe_polkit_details_insert (details, "id.usage", udisks_block_get_id_usage (block));
890957
_safe_polkit_details_insert (details, "id.version", udisks_block_get_id_version (block));
@@ -909,6 +976,9 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
909976
polkit_details_insert (details, "device", details_device);
910977
if (details_drive != NULL)
911978
polkit_details_insert (details, "drive", details_drive);
979+
if (device_display_name == NULL)
980+
device_display_name = g_strdup (details_drive);
981+
polkit_details_insert (details, "device.name", device_display_name);
912982

913983
sub_error = NULL;
914984
result = polkit_authority_check_authorization_sync (authority,
@@ -962,6 +1032,7 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
9621032

9631033
out:
9641034
g_free (details_drive);
1035+
g_free (device_display_name);
9651036
g_clear_object (&block_object);
9661037
g_clear_object (&drive_object);
9671038
g_clear_object (&block);

src/udiskslinuxblock.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -2907,10 +2907,10 @@ format_check_auth (UDisksDaemon *daemon,
29072907
* requests erasing a hard disk using the SECURE ERASE UNIT
29082908
* command.
29092909
*
2910-
* Do not translate $(drive), it's a placeholder and
2910+
* Do not translate $(device.name), it's a placeholder and
29112911
* will be replaced by the name of the drive/device in question
29122912
*/
2913-
message = N_("Authentication is required to perform a secure erase of $(drive)");
2913+
message = N_("Authentication is required to perform a secure erase of $(device.name)");
29142914
action_id = "org.freedesktop.udisks2.ata-secure-erase";
29152915
}
29162916
else
@@ -2919,10 +2919,10 @@ format_check_auth (UDisksDaemon *daemon,
29192919
* device. This includes both creating a filesystem or partition
29202920
* table.
29212921
*
2922-
* Do not translate $(drive), it's a placeholder and will
2922+
* Do not translate $(device.name), it's a placeholder and will
29232923
* be replaced by the name of the drive/device in question
29242924
*/
2925-
message = N_("Authentication is required to format $(drive)");
2925+
message = N_("Authentication is required to format $(device.name)");
29262926
action_id = format_extra_args ? "org.freedesktop.udisks2.modify-device-system" :
29272927
"org.freedesktop.udisks2.modify-device";
29282928
if (!udisks_daemon_util_setup_by_user (daemon, object, caller_uid))
@@ -3913,10 +3913,10 @@ handle_open_for_backup (UDisksBlock *block,
39133913
/* Translators: Shown in authentication dialog when creating a
39143914
* disk image file.
39153915
*
3916-
* Do not translate $(drive), it's a placeholder and will
3916+
* Do not translate $(device.name), it's a placeholder and will
39173917
* be replaced by the name of the drive/device in question
39183918
*/
3919-
N_("Authentication is required to open $(drive) for reading"),
3919+
N_("Authentication is required to open $(device.name) for reading"),
39203920
invocation))
39213921
goto out;
39223922

@@ -3984,10 +3984,10 @@ handle_open_for_restore (UDisksBlock *block,
39843984
/* Translators: Shown in authentication dialog when restoring
39853985
* from a disk image file.
39863986
*
3987-
* Do not translate $(drive), it's a placeholder and will
3987+
* Do not translate $(device.name), it's a placeholder and will
39883988
* be replaced by the name of the drive/device in question
39893989
*/
3990-
N_("Authentication is required to open $(drive) for writing"),
3990+
N_("Authentication is required to open $(device.name) for writing"),
39913991
invocation))
39923992
goto out;
39933993

@@ -4058,10 +4058,10 @@ handle_open_for_benchmark (UDisksBlock *block,
40584058
/* Translators: Shown in authentication dialog when an application
40594059
* wants to benchmark a device.
40604060
*
4061-
* Do not translate $(drive), it's a placeholder and will
4061+
* Do not translate $(device.name), it's a placeholder and will
40624062
* be replaced by the name of the drive/device in question
40634063
*/
4064-
N_("Authentication is required to open $(drive) for benchmarking"),
4064+
N_("Authentication is required to open $(device.name) for benchmarking"),
40654065
invocation))
40664066
goto out;
40674067

@@ -4141,10 +4141,10 @@ handle_open_device (UDisksBlock *block,
41414141
/* Translators: Shown in authentication dialog when an application
41424142
* wants to benchmark a device.
41434143
*
4144-
* Do not translate $(drive), it's a placeholder and will
4144+
* Do not translate $(device.name), it's a placeholder and will
41454145
* be replaced by the name of the drive/device in question
41464146
*/
4147-
N_("Authentication is required to open $(drive)."),
4147+
N_("Authentication is required to open $(device.name)."),
41484148
invocation))
41494149
goto out;
41504150

@@ -4198,10 +4198,10 @@ handle_rescan (UDisksBlock *block,
41984198
/* Translators: Shown in authentication dialog when an application
41994199
* wants to rescan a device.
42004200
*
4201-
* Do not translate $(drive), it's a placeholder and will
4201+
* Do not translate $(device.name), it's a placeholder and will
42024202
* be replaced by the name of the drive/device in question
42034203
*/
4204-
message = N_("Authentication is required to rescan $(drive)");
4204+
message = N_("Authentication is required to rescan $(device.name)");
42054205
action_id = "org.freedesktop.udisks2.rescan";
42064206

42074207
if (!udisks_daemon_util_check_authorization_sync (daemon,

src/udiskslinuxdrive.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,10 @@ handle_eject (UDisksDrive *_drive,
11141114
/* Translators: Shown in authentication dialog when the user
11151115
* requests ejecting media from a drive.
11161116
*
1117-
* Do not translate $(drive), it's a placeholder and
1117+
* Do not translate $(device.name), it's a placeholder and
11181118
* will be replaced by the name of the drive/device in question
11191119
*/
1120-
message = N_("Authentication is required to eject $(drive)");
1120+
message = N_("Authentication is required to eject $(device.name)");
11211121
action_id = "org.freedesktop.udisks2.eject-media";
11221122
if (udisks_block_get_hint_system (block))
11231123
{
@@ -1203,10 +1203,10 @@ handle_set_configuration (UDisksDrive *_drive,
12031203
/* Translators: Shown in authentication dialog when the user
12041204
* changes settings for a drive.
12051205
*
1206-
* Do not translate $(drive), it's a placeholder and will be
1206+
* Do not translate $(device.name), it's a placeholder and will be
12071207
* replaced by the name of the drive/device in question
12081208
*/
1209-
message = N_("Authentication is required to configure settings for $(drive)");
1209+
message = N_("Authentication is required to configure settings for $(device.name)");
12101210
action_id = "org.freedesktop.udisks2.modify-drive-settings";
12111211

12121212
/* Check that the user is actually authorized */
@@ -1518,10 +1518,10 @@ handle_power_off (UDisksDrive *_drive,
15181518
/* Translators: Shown in authentication dialog when the user
15191519
* requests ejecting media from a drive.
15201520
*
1521-
* Do not translate $(drive), it's a placeholder and
1521+
* Do not translate $(device.name), it's a placeholder and
15221522
* will be replaced by the name of the drive/device in question
15231523
*/
1524-
message = N_("Authentication is required to power off $(drive)");
1524+
message = N_("Authentication is required to power off $(device.name)");
15251525
action_id = "org.freedesktop.udisks2.power-off-drive";
15261526
if (udisks_block_get_hint_system (block))
15271527
{

0 commit comments

Comments
 (0)