Skip to content

Commit bde1f22

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

14 files changed

+185
-102
lines changed

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

+85-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <blockdev/blockdev.h>
3838

3939
#include "udisksdaemon.h"
40+
#include "udisksclient.h"
4041
#include "udisksdaemonutil.h"
4142
#include "udisksstate.h"
4243
#include "udiskslogging.h"
@@ -690,6 +691,74 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
690691
return ret;
691692
}
692693

694+
695+
static gchar *
696+
get_device_display_name(UDisksBlock *block)
697+
{
698+
UDisksClient *client = NULL;
699+
GError *error = NULL;
700+
gchar *display_name = NULL;
701+
gchar *s = NULL;
702+
const gchar *id_label = NULL;
703+
const gchar *id_usage = NULL;
704+
const gchar *id_type = NULL;
705+
706+
if (block == NULL)
707+
goto out;
708+
709+
client = udisks_client_new_sync(NULL, &error);
710+
if (client == NULL)
711+
{
712+
g_printerr ("Error connecting to the udisks daemon: %s\n", error->message);
713+
g_clear_error (&error);
714+
goto out;
715+
}
716+
717+
id_label = udisks_block_get_id_label (block);
718+
id_usage = udisks_block_get_id_usage (block);
719+
id_type = udisks_block_get_id_type (block);
720+
if (id_label != NULL && strlen (id_label) > 0)
721+
{
722+
display_name = g_strdup (id_label);
723+
}
724+
else if (id_usage != NULL && g_strcmp0 (id_usage, "crypto") == 0)
725+
{
726+
s = udisks_client_get_size_for_display (client, udisks_block_get_size (block), FALSE, FALSE);
727+
if (id_type != NULL && g_strcmp0 (id_type, "crypto_unknown") == 0)
728+
{
729+
/* Translators: This is used for possibly encrypted volumes.
730+
* The first %s is the formatted size (e.g. "42.0 MB").
731+
*/
732+
display_name = g_strdup_printf (N_("%s Possibly Encrypted"), s);
733+
}
734+
else
735+
{
736+
/* Translators: This is used for encrypted volumes.
737+
* The first %s is the formatted size (e.g. "42.0 MB").
738+
*/
739+
display_name = g_strdup_printf (N_("%s Encrypted"), s);
740+
}
741+
g_free (s);
742+
}
743+
else
744+
{
745+
guint64 size = udisks_block_get_size (block);
746+
if (size > 0)
747+
{
748+
s = udisks_client_get_size_for_display (client, size, FALSE, FALSE);
749+
/* Translators: This is used for volume with no filesystem label.
750+
* The first %s is the formatted size (e.g. "42.0 MB").
751+
*/
752+
display_name = g_strdup_printf (N_("%s Volume"), s);
753+
g_free (s);
754+
}
755+
}
756+
757+
out:
758+
g_object_unref(client);
759+
return display_name;
760+
}
761+
693762
/**
694763
* udisks_daemon_util_check_authorization_sync:
695764
* @daemon: A #UDisksDaemon.
@@ -716,8 +785,9 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
716785
* can be used in @message but note that not all variables can be used
717786
* in all checks. For example, any check involving a #UDisksDrive or a
718787
* #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
788+
* <quote>$(device.name)</quote> since it will always expand to the name of
789+
* the partition or drive, e.g. <quote>MyUDisks (/dev/sda1)</quote> or
790+
* <quote>INTEL SSDSA2MH080G1GC (/dev/sda1)</quote> or
721791
* the block device file e.g. <quote>/dev/vg_lucifer/lv_root</quote>
722792
* or <quote>/dev/sda1</quote>. However this won't work for operations
723793
* that isn't on a drive or block device, for example calls on the
@@ -774,6 +844,7 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
774844
gboolean auth_no_user_interaction = FALSE;
775845
const gchar *details_device = NULL;
776846
gchar *details_drive = NULL;
847+
gchar *device_display_name = NULL;
777848

778849
authority = udisks_daemon_get_authority (daemon);
779850
if (authority == NULL)
@@ -885,6 +956,14 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
885956

886957
if (block != NULL)
887958
{
959+
gchar *s = NULL;
960+
s = get_device_display_name (block);
961+
if (s)
962+
{
963+
device_display_name = g_strdup_printf ("%s (%s)", s, details_device);
964+
g_free (s);
965+
}
966+
888967
_safe_polkit_details_insert (details, "id.type", udisks_block_get_id_type (block));
889968
_safe_polkit_details_insert (details, "id.usage", udisks_block_get_id_usage (block));
890969
_safe_polkit_details_insert (details, "id.version", udisks_block_get_id_version (block));
@@ -909,6 +988,9 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
909988
polkit_details_insert (details, "device", details_device);
910989
if (details_drive != NULL)
911990
polkit_details_insert (details, "drive", details_drive);
991+
if (device_display_name == NULL)
992+
device_display_name = g_strdup (details_drive);
993+
polkit_details_insert (details, "device.name", device_display_name);
912994

913995
sub_error = NULL;
914996
result = polkit_authority_check_authorization_sync (authority,
@@ -962,6 +1044,7 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
9621044

9631045
out:
9641046
g_free (details_drive);
1047+
g_free (device_display_name);
9651048
g_clear_object (&block_object);
9661049
g_clear_object (&drive_object);
9671050
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)