Blame SOURCES/goa-Add-support-for-certificate-prompts.patch

446bca
From bbc95d6716ac491489f059c68a6dd258e38aee79 Mon Sep 17 00:00:00 2001
446bca
From: Ondrej Holy <oholy@redhat.com>
446bca
Date: Mon, 25 Nov 2019 16:53:31 +0100
446bca
Subject: [PATCH] goa: Add support for certificate prompts
446bca
446bca
Since commit f5ee590e, it is not possible to access Nextcloud/ownCloud
446bca
shares with self-signed (or invalid) certificates. This is because
446bca
the mount operation is handled by GOA volume monitor and the prompt
446bca
to accept certificate is not shown. Let's update the volume monitor
446bca
to handle just passwords and show the prompt to the client.
446bca
446bca
Fixes: https://gitlab.gnome.org/GNOME/gvfs/issues/251
446bca
---
446bca
 monitor/goa/goavolume.c | 98 ++++++++++++++++++++++++++++++++++++++++-
446bca
 1 file changed, 96 insertions(+), 2 deletions(-)
446bca
446bca
diff --git a/monitor/goa/goavolume.c b/monitor/goa/goavolume.c
446bca
index c077dd94..5e9097c6 100644
446bca
--- a/monitor/goa/goavolume.c
446bca
+++ b/monitor/goa/goavolume.c
446bca
@@ -64,6 +64,7 @@ G_DEFINE_TYPE_EXTENDED (GVfsGoaVolume, g_vfs_goa_volume, G_TYPE_OBJECT, 0,
446bca
 typedef struct
446bca
 {
446bca
   GMountOperation *mount_operation;
446bca
+  GMountOperation *mount_operation_orig;
446bca
   gchar *passwd;
446bca
 } MountOp;
446bca
 
446bca
@@ -72,6 +73,13 @@ mount_op_free (MountOp *data)
446bca
 {
446bca
   g_clear_object (&data->mount_operation);
446bca
   g_free (data->passwd);
446bca
+
446bca
+  if (data->mount_operation_orig != NULL)
446bca
+    {
446bca
+      g_signal_handlers_disconnect_by_data (data->mount_operation_orig, data);
446bca
+      g_object_unref (data->mount_operation_orig);
446bca
+    }
446bca
+
446bca
   g_slice_free (MountOp, data);
446bca
 }
446bca
 
446bca
@@ -97,6 +105,88 @@ account_attention_needed_cb (GObject *_object, GParamSpec *pspec, gpointer user_
446bca
 
446bca
 /* ---------------------------------------------------------------------------------------------------- */
446bca
 
446bca
+GType g_vfs_goa_mount_operation_get_type (void) G_GNUC_CONST;
446bca
+
446bca
+typedef struct
446bca
+{
446bca
+  GMountOperation parent_instance;
446bca
+} GVfsGoaMountOperation;
446bca
+
446bca
+typedef struct
446bca
+{
446bca
+  GMountOperationClass parent_class;
446bca
+} GVfsGoaMountOperationClass;
446bca
+
446bca
+static GMountOperation *
446bca
+g_vfs_goa_mount_operation_new (void)
446bca
+{
446bca
+  return G_MOUNT_OPERATION (g_object_new (g_vfs_goa_mount_operation_get_type (), NULL));
446bca
+}
446bca
+
446bca
+G_DEFINE_TYPE (GVfsGoaMountOperation, g_vfs_goa_mount_operation, G_TYPE_MOUNT_OPERATION)
446bca
+
446bca
+static void
446bca
+g_vfs_goa_mount_operation_init (GVfsGoaMountOperation *mount_operation)
446bca
+{
446bca
+}
446bca
+
446bca
+static void
446bca
+g_vfs_goa_mount_operation_ask_question (GMountOperation *op,
446bca
+                                        const char *message,
446bca
+                                        const char *choices[])
446bca
+{
446bca
+  /* This is needed to prevent G_MOUNT_OPERATION_UNHANDLED reply in idle. */
446bca
+}
446bca
+
446bca
+static void
446bca
+g_vfs_goa_mount_operation_class_init (GVfsGoaMountOperationClass *klass)
446bca
+{
446bca
+  GMountOperationClass *mount_op_class;
446bca
+
446bca
+  mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
446bca
+  mount_op_class->ask_question  = g_vfs_goa_mount_operation_ask_question;
446bca
+}
446bca
+
446bca
+/* ---------------------------------------------------------------------------------------------------- */
446bca
+
446bca
+static void
446bca
+ask_question_reply_cb (GMountOperation      *op,
446bca
+                       GMountOperationResult result,
446bca
+                       gpointer              user_data)
446bca
+{
446bca
+  MountOp *data = g_task_get_task_data (user_data);
446bca
+
446bca
+  g_mount_operation_set_choice (data->mount_operation,
446bca
+                                g_mount_operation_get_choice (op));
446bca
+  g_mount_operation_reply (data->mount_operation, result);
446bca
+}
446bca
+
446bca
+static void
446bca
+mount_operation_ask_question_cb (GMountOperation *op,
446bca
+                                 gchar           *message,
446bca
+                                 GStrv            choices,
446bca
+                                 gpointer         user_data)
446bca
+{
446bca
+  MountOp *data = g_task_get_task_data (user_data);
446bca
+
446bca
+  if (data->mount_operation_orig != NULL)
446bca
+    {
446bca
+      g_signal_connect (data->mount_operation_orig,
446bca
+                        "reply",
446bca
+                        G_CALLBACK (ask_question_reply_cb),
446bca
+                        user_data);
446bca
+      g_signal_emit_by_name (data->mount_operation_orig,
446bca
+                             "ask-question",
446bca
+                             message,
446bca
+                             choices);
446bca
+    }
446bca
+  else
446bca
+    {
446bca
+      g_mount_operation_reply (data->mount_operation,
446bca
+                               G_MOUNT_OPERATION_UNHANDLED);
446bca
+    }
446bca
+}
446bca
+
446bca
 static void
446bca
 mount_operation_ask_password_cb (GMountOperation   *op,
446bca
                                  gchar             *message,
446bca
@@ -412,7 +502,7 @@ g_vfs_goa_volume_get_uuid (GVolume *_self)
446bca
 static void
446bca
 g_vfs_goa_volume_mount (GVolume             *_self,
446bca
                         GMountMountFlags     flags,
446bca
-                        GMountOperation     *mount_operation,
446bca
+                        GMountOperation     *mount_operation_orig,
446bca
                         GCancellable        *cancellable,
446bca
                         GAsyncReadyCallback  callback,
446bca
                         gpointer             user_data)
446bca
@@ -423,6 +513,9 @@ g_vfs_goa_volume_mount (GVolume             *_self,
446bca
   GoaAccount *account;
446bca
 
446bca
   data = g_slice_new0 (MountOp);
446bca
+  if (mount_operation_orig != NULL)
446bca
+    data->mount_operation_orig = g_object_ref (mount_operation_orig);
446bca
+
446bca
   task = g_task_new (self, cancellable, callback, user_data);
446bca
   g_task_set_source_tag (task, g_vfs_goa_volume_mount);
446bca
   g_task_set_task_data (task, data, (GDestroyNotify) mount_op_free);
446bca
@@ -431,8 +524,9 @@ g_vfs_goa_volume_mount (GVolume             *_self,
446bca
    * monitor because it is set up to emit MountOpAskPassword on
446bca
    * ask-password.
446bca
    */
446bca
-  data->mount_operation = g_mount_operation_new ();
446bca
+  data->mount_operation = g_vfs_goa_mount_operation_new ();
446bca
   g_signal_connect (data->mount_operation, "ask-password", G_CALLBACK (mount_operation_ask_password_cb), task);
446bca
+  g_signal_connect (data->mount_operation, "ask-question", G_CALLBACK (mount_operation_ask_question_cb), task);
446bca
 
446bca
   account = goa_object_peek_account (self->object);
446bca
   goa_account_call_ensure_credentials (account, cancellable, ensure_credentials_cb, task);
446bca
-- 
446bca
2.28.0
446bca