From 6dab11a740136bed0baabfa9a2fa03e2dec54dd4 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 24 Jan 2024 09:53:09 +0100 Subject: [PATCH 01/11] Add GetRealPath to document portal --- data/org.freedesktop.portal.Documents.xml | 12 +++++ document-portal/document-portal.c | 63 +++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/data/org.freedesktop.portal.Documents.xml b/data/org.freedesktop.portal.Documents.xml index d5a76372a..d8acd110e 100644 --- a/data/org.freedesktop.portal.Documents.xml +++ b/data/org.freedesktop.portal.Documents.xml @@ -273,5 +273,17 @@ + + + + + + diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index ccbb514bc..4a8306673 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1416,6 +1416,68 @@ portal_list (GDBusMethodInvocation *invocation, return TRUE; } +static gboolean +portal_get_real_path (GDBusMethodInvocation *invocation, + GVariant *parameters, + XdpAppInfo *app_info) +{ + const char *id = NULL; + g_autoptr(PermissionDbEntry) entry = NULL; + + g_variant_get (parameters, "(&s)", &id); + + XDP_AUTOLOCK (db); + + entry = permission_db_lookup (db, id); + + if (!entry) + { + g_dbus_method_invocation_return_error (invocation, + XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT, + "Invalid ID passed"); + return TRUE; + } + + if (!xdp_app_info_is_host (app_info)) + { + g_autofree const char **apps = NULL; + g_autofree const char *app_id = NULL; + static gboolean id_found = FALSE; + int i; + + app_id = xdp_app_info_get_id(app_info); + + apps = permission_db_entry_list_apps (entry); + for (i = 0; apps[i] != NULL; i++) + { + if (g_strcmp0 (app_id, apps[i]) == 0) + { + id_found = TRUE; + break; + } + } + + if (!id_found) + { + g_dbus_method_invocation_return_error (invocation, + XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT, + "Invalid ID passed"); + return TRUE; + } + } + + g_autoptr (GVariant) data = permission_db_entry_get_data (entry); + const char *path; + + g_variant_get (data, "(^&ayttu)", &path, NULL, NULL, NULL); + + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(@s)", + g_variant_new_string (path))); + + return TRUE; +} + static void peer_died_cb (const char *name) { @@ -1445,6 +1507,7 @@ on_bus_acquired (GDBusConnection *connection, g_signal_connect_swapped (dbus_api, "handle-lookup", G_CALLBACK (handle_method), portal_lookup); g_signal_connect_swapped (dbus_api, "handle-info", G_CALLBACK (handle_method), portal_info); g_signal_connect_swapped (dbus_api, "handle-list", G_CALLBACK (handle_method), portal_list); + g_signal_connect_swapped (dbus_api, "handle-get-real-path", G_CALLBACK (handle_method), portal_get_real_path); file_transfer = file_transfer_create (); g_dbus_interface_skeleton_set_flags (file_transfer, From dfe03e60fa56bac87371c3391d2ef5a4c18e3abb Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 29 Jan 2024 16:14:38 +0100 Subject: [PATCH 02/11] Remove static --- document-portal/document-portal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index 4a8306673..9d085b2f8 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1442,7 +1442,7 @@ portal_get_real_path (GDBusMethodInvocation *invocation, { g_autofree const char **apps = NULL; g_autofree const char *app_id = NULL; - static gboolean id_found = FALSE; + gboolean id_found = FALSE; int i; app_id = xdp_app_info_get_id(app_info); From 64ed5b01291e75885d4f1586d9c4db66beef286c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Feb 2024 14:49:05 +0100 Subject: [PATCH 03/11] Do requested changes --- data/org.freedesktop.portal.Documents.xml | 2 ++ document-portal/document-portal.c | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/data/org.freedesktop.portal.Documents.xml b/data/org.freedesktop.portal.Documents.xml index d8acd110e..7909f5431 100644 --- a/data/org.freedesktop.portal.Documents.xml +++ b/data/org.freedesktop.portal.Documents.xml @@ -280,6 +280,8 @@ @path: the path for the file in the host filesystem Gets the filesystem path for a document store entry. + + This call is available inside the sandbox, if the application has the permission for the document. --> diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index 9d085b2f8..a0ea64cc1 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1442,7 +1442,7 @@ portal_get_real_path (GDBusMethodInvocation *invocation, { g_autofree const char **apps = NULL; g_autofree const char *app_id = NULL; - gboolean id_found = FALSE; + gboolean app_found = FALSE; int i; app_id = xdp_app_info_get_id(app_info); @@ -1452,16 +1452,16 @@ portal_get_real_path (GDBusMethodInvocation *invocation, { if (g_strcmp0 (app_id, apps[i]) == 0) { - id_found = TRUE; + app_found = TRUE; break; } } - if (!id_found) + if (!app_found) { g_dbus_method_invocation_return_error (invocation, - XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT, - "Invalid ID passed"); + XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED, + "Not enough permissions"; return TRUE; } } @@ -1494,7 +1494,7 @@ on_bus_acquired (GDBusConnection *connection, dbus_api = xdp_dbus_documents_skeleton_new (); - xdp_dbus_documents_set_version (XDP_DBUS_DOCUMENTS (dbus_api), 4); + xdp_dbus_documents_set_version (XDP_DBUS_DOCUMENTS (dbus_api), 5); g_signal_connect_swapped (dbus_api, "handle-get-mount-point", G_CALLBACK (handle_get_mount_point), NULL); g_signal_connect_swapped (dbus_api, "handle-add", G_CALLBACK (handle_method), portal_add); From 1794b06415b9eeb9aef7a3adadb7a0dff2c56da1 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Feb 2024 14:52:00 +0100 Subject: [PATCH 04/11] Fix typo --- document-portal/document-portal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index a0ea64cc1..48db6344b 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1461,7 +1461,7 @@ portal_get_real_path (GDBusMethodInvocation *invocation, { g_dbus_method_invocation_return_error (invocation, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED, - "Not enough permissions"; + "Not enough permissions"); return TRUE; } } From 6821356cdbff46d9bfae9941026c4481f99321e5 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Feb 2024 14:58:38 +0100 Subject: [PATCH 05/11] try to fix test --- tests/test-doc-portal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-doc-portal.c b/tests/test-doc-portal.c index 8298943a2..0d78355a1 100644 --- a/tests/test-doc-portal.c +++ b/tests/test-doc-portal.c @@ -853,7 +853,7 @@ test_version (void) if (!check_fuse_or_skip_test ()) return; - g_assert_cmpint (xdp_dbus_documents_get_version (documents), ==, 4); + g_assert_cmpint (xdp_dbus_documents_get_version (documents), ==, 5); } int From 797ea01e3f52058e2dc45d8896b961f3b9104f69 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 13 Feb 2024 16:40:17 +0100 Subject: [PATCH 06/11] Add version to docs --- data/org.freedesktop.portal.Documents.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/org.freedesktop.portal.Documents.xml b/data/org.freedesktop.portal.Documents.xml index 7909f5431..485f67368 100644 --- a/data/org.freedesktop.portal.Documents.xml +++ b/data/org.freedesktop.portal.Documents.xml @@ -281,7 +281,9 @@ Gets the filesystem path for a document store entry. - This call is available inside the sandbox, if the application has the permission for the document. + This call is available inside the sandbox, if the application has the permission for the document. + + This method was added in version 5 of this interface. --> From 7aab70ffe72f744c1b7121baa0136c04fed5f6c6 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 14 Feb 2024 12:39:36 +0100 Subject: [PATCH 07/11] Add test --- tests/test-doc-portal.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test-doc-portal.c b/tests/test-doc-portal.c index 0d78355a1..e2d9f0c86 100644 --- a/tests/test-doc-portal.c +++ b/tests/test-doc-portal.c @@ -687,6 +687,42 @@ test_add_named (void) assert_doc_not_exist (id1, basename1, "com.test.App2"); } +static char * +doc_get_real_path (const char *basename) +{ + return g_build_filename (outdir, basename, NULL); +} + +static void +test_get_real_path (void) +{ + g_autofree char *doc_id = NULL; + g_autofree char *real_path = NULL; + const char *basename = "real-path"; + g_autoptr(GVariant) reply = NULL; + GError *error = NULL; + + if (!check_fuse_or_skip_test ()) + return; + + doc_id = export_new_file (basename, "content", FALSE); + + reply = g_dbus_connection_call_sync (session_bus, + "org.freedesktop.portal.Documents", + "/org/freedesktop/portal/documents", + "org.freedesktop.portal.Documents", + "GetRealPath", + g_variant_new ("(s)", doc_id), + G_VARIANT_TYPE ("(s)"), + 0, -1, + NULL, + &error); + + g_assert_no_error (error); + g_variant_get (reply, "(s)", &real_path); + g_assert_cmpstr (real_path, ==, doc_get_real_path(basename)); +} + static void global_setup (void) { @@ -871,6 +907,7 @@ main (int argc, char **argv) g_test_add_func ("/db/recursive_doc", test_recursive_doc); g_test_add_func ("/db/create_docs", test_create_docs); g_test_add_func ("/db/add_named", test_add_named); + g_test_add_func ("/db/get_real_path", test_get_real_path); global_setup (); From 8a4e19e061c4f500c9027cba4fa23e79acc4571b Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 21 Feb 2024 08:18:27 +0100 Subject: [PATCH 08/11] Remove g_autofree --- document-portal/document-portal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index 48db6344b..5c4da560d 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1441,7 +1441,7 @@ portal_get_real_path (GDBusMethodInvocation *invocation, if (!xdp_app_info_is_host (app_info)) { g_autofree const char **apps = NULL; - g_autofree const char *app_id = NULL; + const char *app_id = NULL; gboolean app_found = FALSE; int i; From 341f35c92b368dee658fbf0550a8ddb0671e79c1 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 27 Feb 2024 09:28:21 +0100 Subject: [PATCH 09/11] Update test --- tests/test-doc-portal.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/test-doc-portal.c b/tests/test-doc-portal.c index e2d9f0c86..561f8c159 100644 --- a/tests/test-doc-portal.c +++ b/tests/test-doc-portal.c @@ -687,12 +687,6 @@ test_add_named (void) assert_doc_not_exist (id1, basename1, "com.test.App2"); } -static char * -doc_get_real_path (const char *basename) -{ - return g_build_filename (outdir, basename, NULL); -} - static void test_get_real_path (void) { @@ -720,7 +714,8 @@ test_get_real_path (void) g_assert_no_error (error); g_variant_get (reply, "(s)", &real_path); - g_assert_cmpstr (real_path, ==, doc_get_real_path(basename)); + expected_real_path = g_build_filename (outdir, basename, NULL); + g_assert_cmpstr (real_path, ==, expected_real_path); } static void From 1dd61b909f3b870620e6d6cb41750e1ec640914c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 27 Feb 2024 09:30:23 +0100 Subject: [PATCH 10/11] Another fix --- tests/test-doc-portal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-doc-portal.c b/tests/test-doc-portal.c index 561f8c159..cd3991267 100644 --- a/tests/test-doc-portal.c +++ b/tests/test-doc-portal.c @@ -691,6 +691,7 @@ static void test_get_real_path (void) { g_autofree char *doc_id = NULL; + g_autofree char *expected_real_path = NULL; g_autofree char *real_path = NULL; const char *basename = "real-path"; g_autoptr(GVariant) reply = NULL; From a1a7c8d807d001d5ea783b0c60bd90addf058fd5 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 29 Apr 2024 19:25:52 +0200 Subject: [PATCH 11/11] Use array --- data/org.freedesktop.portal.Documents.xml | 4 +- document-portal/document-portal.c | 48 +++++++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/data/org.freedesktop.portal.Documents.xml b/data/org.freedesktop.portal.Documents.xml index 485f67368..57821f625 100644 --- a/data/org.freedesktop.portal.Documents.xml +++ b/data/org.freedesktop.portal.Documents.xml @@ -286,8 +286,8 @@ This method was added in version 5 of this interface. --> - - + + diff --git a/document-portal/document-portal.c b/document-portal/document-portal.c index 5c4da560d..72c3f4f64 100644 --- a/document-portal/document-portal.c +++ b/document-portal/document-portal.c @@ -1416,16 +1416,13 @@ portal_list (GDBusMethodInvocation *invocation, return TRUE; } -static gboolean -portal_get_real_path (GDBusMethodInvocation *invocation, - GVariant *parameters, - XdpAppInfo *app_info) +const char * +get_real_path_internal (GDBusMethodInvocation *invocation, + XdpAppInfo *app_info, + const char *id) { - const char *id = NULL; g_autoptr(PermissionDbEntry) entry = NULL; - g_variant_get (parameters, "(&s)", &id); - XDP_AUTOLOCK (db); entry = permission_db_lookup (db, id); @@ -1434,8 +1431,8 @@ portal_get_real_path (GDBusMethodInvocation *invocation, { g_dbus_method_invocation_return_error (invocation, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT, - "Invalid ID passed"); - return TRUE; + g_strdup_printf("Invalid ID passed (%s)", id)); + return NULL; } if (!xdp_app_info_is_host (app_info)) @@ -1462,7 +1459,7 @@ portal_get_real_path (GDBusMethodInvocation *invocation, g_dbus_method_invocation_return_error (invocation, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED, "Not enough permissions"); - return TRUE; + return NULL; } } @@ -1471,9 +1468,34 @@ portal_get_real_path (GDBusMethodInvocation *invocation, g_variant_get (data, "(^&ayttu)", &path, NULL, NULL, NULL); - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("(@s)", - g_variant_new_string (path))); + return path; +} + +static gboolean +portal_get_real_path (GDBusMethodInvocation *invocation, + GVariant *parameters, + XdpAppInfo *app_info) +{ + g_autofree const char **id_list = NULL; + const char *path; + int i; + + g_variant_get (parameters, "(^a&s)", &id_list); + + GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aay")); + + for (i = 0; id_list[i]; i++) + { + path = get_real_path_internal(invocation, app_info, id_list[i]); + if (path == NULL) + { + return FALSE; + } + + g_variant_builder_add (&builder, "^ay", path); + } + + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aay)", &builder)); return TRUE; }