5c9faf
From d89c71ed2bdb18e9b01891d6b999c44f955778dc Mon Sep 17 00:00:00 2001
5c9faf
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
5c9faf
Date: Wed, 1 Sep 2021 21:12:03 +0200
5c9faf
Subject: [PATCH 1/2] context: Add :unsafe-mode property
5c9faf
5c9faf
We are going to restrict several sensitive D-Bus APIs to a set
5c9faf
of allowed callers (like Settings or portal implementations).
5c9faf
5c9faf
Add an :unsafe-mode property to the context to allow turning off
5c9faf
those restrictions temporarily, in order to not get in the way
5c9faf
of development/debugging.
5c9faf
5c9faf
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943
5c9faf
5c9faf
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1983>
5c9faf
---
5c9faf
 src/backends/meta-backend-private.h |  4 ++
5c9faf
 src/backends/meta-backend.c         | 83 +++++++++++++++++++++++++++++
5c9faf
 2 files changed, 87 insertions(+)
5c9faf
5c9faf
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
5c9faf
index b930462b2..583d4e151 100644
5c9faf
--- a/src/backends/meta-backend-private.h
5c9faf
+++ b/src/backends/meta-backend-private.h
5c9faf
@@ -133,6 +133,10 @@ void meta_backend_foreach_device_monitor (MetaBackend *backend,
5c9faf
                                           GFunc        func,
5c9faf
                                           gpointer     user_data);
5c9faf
 
5c9faf
+gboolean meta_backend_get_unsafe_mode (MetaBackend *backend);
5c9faf
+void meta_backend_set_unsafe_mode (MetaBackend *backend,
5c9faf
+                                   gboolean     enable);
5c9faf
+
5c9faf
 META_EXPORT_TEST
5c9faf
 MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
5c9faf
 MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
5c9faf
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
5c9faf
index ff84bfe6a..18bee2484 100644
5c9faf
--- a/src/backends/meta-backend.c
5c9faf
+++ b/src/backends/meta-backend.c
5c9faf
@@ -88,6 +88,17 @@
5c9faf
 #include "wayland/meta-wayland.h"
5c9faf
 #endif
5c9faf
 
5c9faf
+enum
5c9faf
+{
5c9faf
+  PROP_0,
5c9faf
+
5c9faf
+  PROP_UNSAFE_MODE,
5c9faf
+
5c9faf
+  N_PROPS
5c9faf
+};
5c9faf
+
5c9faf
+static GParamSpec *obj_props[N_PROPS];
5c9faf
+
5c9faf
 enum
5c9faf
 {
5c9faf
   KEYMAP_CHANGED,
5c9faf
@@ -158,6 +169,8 @@ struct _MetaBackendPrivate
5c9faf
 
5c9faf
   gboolean is_pointer_position_initialized;
5c9faf
 
5c9faf
+  gboolean unsafe_mode;
5c9faf
+
5c9faf
   guint device_update_idle_id;
5c9faf
 
5c9faf
   GHashTable *device_monitors;
5c9faf
@@ -814,6 +827,64 @@ upower_vanished (GDBusConnection *connection,
5c9faf
   g_clear_object (&priv->upower_proxy);
5c9faf
 }
5c9faf
 
5c9faf
+gboolean
5c9faf
+meta_backend_get_unsafe_mode (MetaBackend *backend)
5c9faf
+{
5c9faf
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
5c9faf
+
5c9faf
+  return priv->unsafe_mode;
5c9faf
+}
5c9faf
+
5c9faf
+void
5c9faf
+meta_backend_set_unsafe_mode (MetaBackend *backend,
5c9faf
+                              gboolean     enable)
5c9faf
+{
5c9faf
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
5c9faf
+
5c9faf
+  if (priv->unsafe_mode == enable)
5c9faf
+    return;
5c9faf
+
5c9faf
+  priv->unsafe_mode = enable;
5c9faf
+  g_object_notify_by_pspec (G_OBJECT (backend), obj_props[PROP_UNSAFE_MODE]);
5c9faf
+}
5c9faf
+
5c9faf
+static void
5c9faf
+meta_backend_get_property (GObject    *object,
5c9faf
+                           guint       prop_id,
5c9faf
+                           GValue     *value,
5c9faf
+                           GParamSpec *pspec)
5c9faf
+{
5c9faf
+  MetaBackend *backend = META_BACKEND (object);
5c9faf
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
5c9faf
+
5c9faf
+  switch (prop_id)
5c9faf
+    {
5c9faf
+    case PROP_UNSAFE_MODE:
5c9faf
+      g_value_set_boolean (value, priv->unsafe_mode);
5c9faf
+      break;
5c9faf
+    default:
5c9faf
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5c9faf
+    }
5c9faf
+}
5c9faf
+
5c9faf
+static void
5c9faf
+meta_backend_set_property (GObject      *object,
5c9faf
+                           guint         prop_id,
5c9faf
+                           const GValue *value,
5c9faf
+                           GParamSpec   *pspec)
5c9faf
+{
5c9faf
+  MetaBackend *backend = META_BACKEND (object);
5c9faf
+
5c9faf
+  switch (prop_id)
5c9faf
+    {
5c9faf
+    case PROP_UNSAFE_MODE:
5c9faf
+      meta_backend_set_unsafe_mode (backend, g_value_get_boolean (value));
5c9faf
+      break;
5c9faf
+    default:
5c9faf
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5c9faf
+    }
5c9faf
+}
5c9faf
+
5c9faf
 static void
5c9faf
 meta_backend_constructed (GObject *object)
5c9faf
 {
5c9faf
@@ -851,6 +922,8 @@ meta_backend_class_init (MetaBackendClass *klass)
5c9faf
 
5c9faf
   object_class->dispose = meta_backend_dispose;
5c9faf
   object_class->constructed = meta_backend_constructed;
5c9faf
+  object_class->get_property = meta_backend_get_property;
5c9faf
+  object_class->set_property = meta_backend_set_property;
5c9faf
 
5c9faf
   klass->post_init = meta_backend_real_post_init;
5c9faf
   klass->grab_device = meta_backend_real_grab_device;
5c9faf
@@ -907,6 +980,16 @@ meta_backend_class_init (MetaBackendClass *klass)
5c9faf
                   NULL, NULL, NULL,
5c9faf
                   G_TYPE_NONE, 0);
5c9faf
 
5c9faf
+  obj_props[PROP_UNSAFE_MODE] =
5c9faf
+    g_param_spec_boolean ("unsafe-mode",
5c9faf
+                          "unsafe mode",
5c9faf
+                          "Unsafe mode",
5c9faf
+                          FALSE,
5c9faf
+                          G_PARAM_READWRITE |
5c9faf
+                          G_PARAM_EXPLICIT_NOTIFY |
5c9faf
+                          G_PARAM_STATIC_STRINGS);
5c9faf
+  g_object_class_install_properties (object_class, N_PROPS, obj_props);
5c9faf
+
5c9faf
   mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
5c9faf
   stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0;
5c9faf
 }
5c9faf
-- 
5c9faf
2.35.1
5c9faf
5c9faf
5c9faf
From dc69aa57be79fa7f371788c852f6e23cf0d261cb Mon Sep 17 00:00:00 2001
5c9faf
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
5c9faf
Date: Thu, 2 Sep 2021 18:41:16 +0200
5c9faf
Subject: [PATCH 2/2] context: Add (hidden) --unsafe-mode option
5c9faf
5c9faf
When running gnome-shell, it is possible to toggle unsafe-mode in
5c9faf
looking glass. We'll eventually start using the property in mutter
5c9faf
as well, so to make stand-alone debugging easier, also expose it
5c9faf
as a hidden command line option.
5c9faf
5c9faf
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943
5c9faf
5c9faf
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1983>
5c9faf
---
5c9faf
 src/core/main.c | 7 +++++++
5c9faf
 1 file changed, 7 insertions(+)
5c9faf
5c9faf
diff --git a/src/core/main.c b/src/core/main.c
5c9faf
index 0d241f952..991d583a0 100644
5c9faf
--- a/src/core/main.c
5c9faf
+++ b/src/core/main.c
5c9faf
@@ -218,6 +218,7 @@ static char     *opt_wayland_display;
5c9faf
 static gboolean  opt_display_server;
5c9faf
 static gboolean  opt_headless;
5c9faf
 #endif
5c9faf
+static gboolean  opt_unsafe_mode;
5c9faf
 static gboolean  opt_x11;
5c9faf
 
5c9faf
 #ifdef HAVE_NATIVE_BACKEND
5c9faf
@@ -306,6 +307,11 @@ static GOptionEntry meta_options[] = {
5c9faf
     N_("Add persistent virtual monitor (WxH or WxH@R)")
5c9faf
   },
5c9faf
 #endif
5c9faf
+  {
5c9faf
+    "unsafe-mode", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
5c9faf
+    &opt_unsafe_mode,
5c9faf
+    "Run in unsafe mode"
5c9faf
+  },
5c9faf
   {
5c9faf
     "x11", 0, 0, G_OPTION_ARG_NONE,
5c9faf
     &opt_x11,
5c9faf
@@ -865,6 +871,7 @@ meta_init (void)
5c9faf
   add_persistent_virtual_monitors ();
5c9faf
 #endif
5c9faf
 
5c9faf
+  meta_backend_set_unsafe_mode (meta_get_backend(), opt_unsafe_mode);
5c9faf
   meta_set_syncing (opt_sync || (g_getenv ("MUTTER_SYNC") != NULL));
5c9faf
 
5c9faf
   if (opt_replace_wm)
5c9faf
-- 
5c9faf
2.35.1
5c9faf