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