[PATCH] Add polkit authorization variables for removable media

Pawel Wieczorkiewicz pwieczorkiewicz at suse.de
Mon Oct 7 03:41:06 PDT 2013


Add new variables 'drive.removable.bus' and 'drive.removable.media'.
It allows restricting or granting access to removable media based on
its type by polkit authorization rules. It makes possible to grant
access to USB devices, while restrict access to Optical drives.
---
 doc/udisks2-docs.xml   |  8 ++++++++
 src/udisksdaemonutil.c | 26 +++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/udisks2-docs.xml b/doc/udisks2-docs.xml
index acacfe3..8533709 100644
--- a/doc/udisks2-docs.xml
+++ b/doc/udisks2-docs.xml
@@ -248,6 +248,14 @@
                 <entry><parameter>drive.removable</parameter></entry>
                 <entry>If the object is a drive (or a block device that is part of a drive), this is set to the string <quote>true</quote> only if the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive.Removable">Drive:Removable</link> property is <constant>TRUE</constant>.</entry>
               </row>
+              <row>
+                <entry><parameter>drive.removable.bus</parameter></entry>
+                <entry>If the object is a drive (or a block device that is part of a drive), this is set to the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive.ConnectionBus">Drive:ConnectionBus</link> property. This variable is set only if the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive.Removable">Drive:Removable</link> property is <constant>TRUE</constant>.</entry>
+              </row>
+              <row>
+                <entry><parameter>drive.removable.media</parameter></entry>
+                <entry>If the object is a drive (or a block device that is part of a drive), this is set to the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive.MediaCompatibility">Drive:MediaCompatibility</link> property. This variable is set only if the value of the <link linkend="gdbus-property-org-freedesktop-UDisks2-Drive.Removable">Drive:Removable</link> property is <constant>TRUE</constant>.</entry>
+              </row>
 
               <row>
                 <entry><parameter>id.type</parameter></entry>
diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c
index fb50a0f..574bf2c 100644
--- a/src/udisksdaemonutil.c
+++ b/src/udisksdaemonutil.c
@@ -637,7 +637,31 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon          *daemon,
       _safe_polkit_details_insert (details, "drive.model", udisks_drive_get_model (drive));
       _safe_polkit_details_insert (details, "drive.revision", udisks_drive_get_revision (drive));
       if (udisks_drive_get_removable (drive))
-        polkit_details_insert (details, "drive.removable", "true");
+        {
+          const gchar *const *media_compat;
+          GString *media_compat_str;
+          const gchar *sep = ",";
+
+          polkit_details_insert (details, "drive.removable", "true");
+          _safe_polkit_details_insert (details, "drive.removable.bus", udisks_drive_get_connection_bus (drive));
+
+          media_compat_str = g_string_new (NULL);
+          media_compat = udisks_drive_get_media_compatibility (drive);
+          if (media_compat)
+            {
+              guint i;
+
+              for (i = 0; media_compat[i] && strlen(media_compat[i]); i++)
+                {
+                  if (i)
+                    g_string_append (media_compat_str, sep);
+                  g_string_append (media_compat_str, media_compat[i]);
+                }
+            }
+
+          _safe_polkit_details_insert (details, "drive.removable.media", media_compat_str->str);
+          g_string_free (media_compat_str, TRUE);
+        }
     }
 
   if (block != NULL)
-- 
1.8.1.4



More information about the devkit-devel mailing list