37
37
#include <blockdev/blockdev.h>
38
38
39
39
#include "udisksdaemon.h"
40
+ #include "udisksclient.h"
40
41
#include "udisksdaemonutil.h"
41
42
#include "udisksstate.h"
42
43
#include "udiskslogging.h"
@@ -690,6 +691,74 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
690
691
return ret ;
691
692
}
692
693
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
+
693
762
/**
694
763
* udisks_daemon_util_check_authorization_sync:
695
764
* @daemon: A #UDisksDaemon.
@@ -716,8 +785,9 @@ check_authorization_no_polkit (UDisksDaemon *daemon,
716
785
* can be used in @message but note that not all variables can be used
717
786
* in all checks. For example, any check involving a #UDisksDrive or a
718
787
* #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
721
791
* the block device file e.g. <quote>/dev/vg_lucifer/lv_root</quote>
722
792
* or <quote>/dev/sda1</quote>. However this won't work for operations
723
793
* 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 *
774
844
gboolean auth_no_user_interaction = FALSE;
775
845
const gchar * details_device = NULL ;
776
846
gchar * details_drive = NULL ;
847
+ gchar * device_display_name = NULL ;
777
848
778
849
authority = udisks_daemon_get_authority (daemon );
779
850
if (authority == NULL )
@@ -885,6 +956,14 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
885
956
886
957
if (block != NULL )
887
958
{
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
+
888
967
_safe_polkit_details_insert (details , "id.type" , udisks_block_get_id_type (block ));
889
968
_safe_polkit_details_insert (details , "id.usage" , udisks_block_get_id_usage (block ));
890
969
_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 *
909
988
polkit_details_insert (details , "device" , details_device );
910
989
if (details_drive != NULL )
911
990
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 );
912
994
913
995
sub_error = NULL ;
914
996
result = polkit_authority_check_authorization_sync (authority ,
@@ -962,6 +1044,7 @@ udisks_daemon_util_check_authorization_sync_with_error (UDisksDaemon *
962
1044
963
1045
out :
964
1046
g_free (details_drive );
1047
+ g_free (device_display_name );
965
1048
g_clear_object (& block_object );
966
1049
g_clear_object (& drive_object );
967
1050
g_clear_object (& block );
0 commit comments