Blame SOURCES/udisks2-Handle-lockdown-option-to-disable-writing.patch

5068ac
From 9fdd59cfda93b508e76770146a8295d0a26b175d Mon Sep 17 00:00:00 2001
5068ac
From: Ondrej Holy <oholy@redhat.com>
5068ac
Date: Tue, 14 May 2019 08:46:48 +0200
5068ac
Subject: [PATCH 1/3] udisks2: Handle lockdown option to disable writing
5068ac
5068ac
Handle the new mount-removable-storage-devices-as-read-only option of
5068ac
org.gnome.desktop.lockdown schema and mount removable devices as read-only
5068ac
if enabled.
5068ac
---
5068ac
 monitor/udisks2/gvfsudisks2volume.c        |  8 +++++
5068ac
 monitor/udisks2/gvfsudisks2volumemonitor.c | 34 ++++++++++++++++++++++
5068ac
 monitor/udisks2/gvfsudisks2volumemonitor.h |  1 +
5068ac
 3 files changed, 43 insertions(+)
5068ac
5068ac
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
5068ac
index a509b5dd..b2545058 100644
5068ac
--- a/monitor/udisks2/gvfsudisks2volume.c
5068ac
+++ b/monitor/udisks2/gvfsudisks2volume.c
5068ac
@@ -1093,6 +1093,7 @@ do_mount (GTask *task)
5068ac
 {
5068ac
   MountData *data = g_task_get_task_data (task);
5068ac
   GVariantBuilder builder;
5068ac
+  GVfsUDisks2Volume *volume = g_task_get_source_object (task);
5068ac
 
5068ac
   g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
5068ac
   if (data->mount_operation == NULL)
5068ac
@@ -1101,6 +1102,13 @@ do_mount (GTask *task)
5068ac
                              "{sv}",
5068ac
                              "auth.no_user_interaction", g_variant_new_boolean (TRUE));
5068ac
     }
5068ac
+  if (gvfs_udisks2_volume_monitor_get_readonly_lockdown (volume->monitor))
5068ac
+    {
5068ac
+      g_variant_builder_add (&builder,
5068ac
+                             "{sv}",
5068ac
+                             "options", g_variant_new_string ("ro"));
5068ac
+
5068ac
+    }
5068ac
   udisks_filesystem_call_mount (data->filesystem_to_mount,
5068ac
                                 g_variant_builder_end (&builder),
5068ac
                                 g_task_get_cancellable (task),
5068ac
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c
5068ac
index 0a5ce96e..37c81fcf 100644
5068ac
--- a/monitor/udisks2/gvfsudisks2volumemonitor.c
5068ac
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.c
5068ac
@@ -65,6 +65,9 @@ struct _GVfsUDisks2VolumeMonitor
5068ac
   /* we keep volumes/mounts for blank and audio discs separate to handle e.g. mixed discs properly */
5068ac
   GList *disc_volumes;
5068ac
   GList *disc_mounts;
5068ac
+
5068ac
+  GSettings *lockdown_settings;
5068ac
+  gboolean readonly_lockdown;
5068ac
 };
5068ac
 
5068ac
 static UDisksClient *get_udisks_client_sync (GError **error);
5068ac
@@ -140,6 +143,8 @@ gvfs_udisks2_volume_monitor_finalize (GObject *object)
5068ac
   g_list_free_full (monitor->disc_volumes, g_object_unref);
5068ac
   g_list_free_full (monitor->disc_mounts, g_object_unref);
5068ac
 
5068ac
+  g_clear_object (&monitor->lockdown_settings);
5068ac
+
5068ac
   G_OBJECT_CLASS (gvfs_udisks2_volume_monitor_parent_class)->finalize (object);
5068ac
 }
5068ac
 
5068ac
@@ -304,6 +309,17 @@ gvfs_udisks2_volume_monitor_constructor (GType                  type,
5068ac
   return ret;
5068ac
 }
5068ac
 
5068ac
+static void
5068ac
+lockdown_settings_changed (GSettings *settings,
5068ac
+                           gchar     *key,
5068ac
+                           gpointer   user_data)
5068ac
+{
5068ac
+  GVfsUDisks2VolumeMonitor *monitor = GVFS_UDISKS2_VOLUME_MONITOR (user_data);
5068ac
+
5068ac
+  monitor->readonly_lockdown = g_settings_get_boolean (settings,
5068ac
+                                                       "mount-removable-storage-devices-as-read-only");
5068ac
+}
5068ac
+
5068ac
 static void
5068ac
 gvfs_udisks2_volume_monitor_init (GVfsUDisks2VolumeMonitor *monitor)
5068ac
 {
5068ac
@@ -325,6 +341,15 @@ gvfs_udisks2_volume_monitor_init (GVfsUDisks2VolumeMonitor *monitor)
5068ac
                     G_CALLBACK (mountpoints_changed),
5068ac
                     monitor);
5068ac
 
5068ac
+  monitor->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
5068ac
+  monitor->readonly_lockdown = g_settings_get_boolean (monitor->lockdown_settings,
5068ac
+                                                       "mount-removable-storage-devices-as-read-only");
5068ac
+  g_signal_connect_object (monitor->lockdown_settings,
5068ac
+                           "changed",
5068ac
+                           G_CALLBACK (lockdown_settings_changed),
5068ac
+                           monitor,
5068ac
+                           0);
5068ac
+
5068ac
   update_all (monitor, FALSE, TRUE);
5068ac
 }
5068ac
 
5068ac
@@ -388,6 +413,15 @@ gvfs_udisks2_volume_monitor_get_gudev_client (GVfsUDisks2VolumeMonitor *monitor)
5068ac
 
5068ac
 /* ---------------------------------------------------------------------------------------------------- */
5068ac
 
5068ac
+gboolean
5068ac
+gvfs_udisks2_volume_monitor_get_readonly_lockdown (GVfsUDisks2VolumeMonitor *monitor)
5068ac
+{
5068ac
+  g_return_val_if_fail (GVFS_IS_UDISKS2_VOLUME_MONITOR (monitor), FALSE);
5068ac
+  return monitor->readonly_lockdown;
5068ac
+}
5068ac
+
5068ac
+/* ---------------------------------------------------------------------------------------------------- */
5068ac
+
5068ac
 void
5068ac
 gvfs_udisks2_volume_monitor_update (GVfsUDisks2VolumeMonitor *monitor)
5068ac
 {
5068ac
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.h b/monitor/udisks2/gvfsudisks2volumemonitor.h
5068ac
index 7f0215dc..751a0236 100644
5068ac
--- a/monitor/udisks2/gvfsudisks2volumemonitor.h
5068ac
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.h
5068ac
@@ -49,6 +49,7 @@ GVolumeMonitor *gvfs_udisks2_volume_monitor_new               (void);
5068ac
 UDisksClient   *gvfs_udisks2_volume_monitor_get_udisks_client (GVfsUDisks2VolumeMonitor *monitor);
5068ac
 void            gvfs_udisks2_volume_monitor_update            (GVfsUDisks2VolumeMonitor *monitor);
5068ac
 GUdevClient    *gvfs_udisks2_volume_monitor_get_gudev_client  (GVfsUDisks2VolumeMonitor *monitor);
5068ac
+gboolean        gvfs_udisks2_volume_monitor_get_readonly_lockdown (GVfsUDisks2VolumeMonitor *monitor);
5068ac
 
5068ac
 G_END_DECLS
5068ac
 
5068ac
-- 
5068ac
2.21.0
5068ac