[mutter/wip/carlosg/remote-session-checks: 3/3] backends: Make uniform checks on remote desktop input dbus methods



commit c8837a8de564705bfe36629e15cb5a213cd0839e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat May 16 10:46:57 2020 +0200

    backends: Make uniform checks on remote desktop input dbus methods
    
    They all checked that the remote session service talked with the
    correct peer, and some of them did check that there is an associated
    screencast session.
    
    Add a new check for the session being started (as it's state is
    decoupled with screencast session availability) and move all checks
    to a function that is called from all input-oriented DBus methods.
    
    Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1254
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1258

 src/backends/meta-remote-desktop-session.c | 145 ++++++++++-------------------
 1 file changed, 51 insertions(+), 94 deletions(-)
---
diff --git a/src/backends/meta-remote-desktop-session.c b/src/backends/meta-remote-desktop-session.c
index 48b0c2e29..a7f128dfa 100644
--- a/src/backends/meta-remote-desktop-session.c
+++ b/src/backends/meta-remote-desktop-session.c
@@ -253,6 +253,37 @@ check_permission (MetaRemoteDesktopSession *session,
                     g_dbus_method_invocation_get_sender (invocation)) == 0;
 }
 
+static gboolean
+meta_remote_desktop_session_check_can_notify (MetaRemoteDesktopSession *session,
+                                              GDBusMethodInvocation    *invocation)
+{
+  if (!session->started)
+    {
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+                                             G_DBUS_ERROR_FAILED,
+                                             "Session not started");
+      return FALSE;
+    }
+
+  if (!check_permission (session, invocation))
+    {
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+                                             G_DBUS_ERROR_ACCESS_DENIED,
+                                             "Permission denied");
+      return FALSE;
+    }
+
+  if (!session->screen_cast_session)
+    {
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+                                             G_DBUS_ERROR_FAILED,
+                                             "No screen cast active");
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
 static gboolean
 handle_start (MetaDBusRemoteDesktopSession *skeleton,
               GDBusMethodInvocation        *invocation)
@@ -332,13 +363,8 @@ handle_notify_keyboard_keycode (MetaDBusRemoteDesktopSession *skeleton,
   MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
   ClutterKeyState state;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   if (pressed)
     state = CLUTTER_KEY_STATE_PRESSED;
@@ -364,13 +390,8 @@ handle_notify_keyboard_keysym (MetaDBusRemoteDesktopSession *skeleton,
   MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
   ClutterKeyState state;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   if (pressed)
     state = CLUTTER_KEY_STATE_PRESSED;
@@ -418,13 +439,8 @@ handle_notify_pointer_button (MetaDBusRemoteDesktopSession *skeleton,
   uint32_t button;
   ClutterButtonState state;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   button = translate_to_clutter_button (button_code);
 
@@ -454,13 +470,8 @@ handle_notify_pointer_axis (MetaDBusRemoteDesktopSession *skeleton,
   MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
   ClutterScrollFinishFlags finish_flags = CLUTTER_SCROLL_FINISHED_NONE;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   if (flags & META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_FINISH)
     {
@@ -507,13 +518,8 @@ handle_notify_pointer_axis_discrete (MetaDBusRemoteDesktopSession *skeleton,
   ClutterScrollDirection direction;
   int step_count;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   if (axis > 1)
     {
@@ -558,13 +564,8 @@ handle_notify_pointer_motion_relative (MetaDBusRemoteDesktopSession *skeleton,
 {
   MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   clutter_virtual_input_device_notify_relative_motion (session->virtual_pointer,
                                                        CLUTTER_CURRENT_TIME,
@@ -587,21 +588,8 @@ handle_notify_pointer_motion_absolute (MetaDBusRemoteDesktopSession *skeleton,
   MetaScreenCastStream *stream;
   double abs_x, abs_y;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
-
-  if (!session->screen_cast_session)
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_FAILED,
-                                             "No screen cast active");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
                                                 stream_path);
@@ -637,21 +625,8 @@ handle_notify_touch_down (MetaDBusRemoteDesktopSession *skeleton,
   MetaScreenCastStream *stream;
   double abs_x, abs_y;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
-
-  if (!session->screen_cast_session)
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_FAILED,
-                                             "No screen cast active");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
                                                 stream_path);
@@ -688,21 +663,8 @@ handle_notify_touch_motion (MetaDBusRemoteDesktopSession *skeleton,
   MetaScreenCastStream *stream;
   double abs_x, abs_y;
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
-
-  if (!session->screen_cast_session)
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_FAILED,
-                                             "No screen cast active");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
                                                 stream_path);
@@ -734,13 +696,8 @@ handle_notify_touch_up (MetaDBusRemoteDesktopSession *skeleton,
 {
   MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
 
-  if (!check_permission (session, invocation))
-    {
-      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                             G_DBUS_ERROR_ACCESS_DENIED,
-                                             "Permission denied");
-      return TRUE;
-    }
+  if (!meta_remote_desktop_session_check_can_notify (session, invocation))
+    return TRUE;
 
   clutter_virtual_input_device_notify_touch_up (session->virtual_touchscreen,
                                                        CLUTTER_CURRENT_TIME,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]