From ead0454bf52466a1dae10bc8afa8fe8075498a46 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 21 Nov 2022 21:21:28 +0100 Subject: [PATCH] RemoteDesktop: Pass the creator's pid when creating a session The portal implementation can use the extra information to decide to which extent the request should be trusted. This can be done by checking the process namespace or its origin in the filesystem. --- ...g.freedesktop.impl.portal.RemoteDesktop.xml | 10 ++++++++++ src/remote-desktop.c | 2 ++ src/xdp-utils.c | 18 ++++++++++++++---- src/xdp-utils.h | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/data/org.freedesktop.impl.portal.RemoteDesktop.xml b/data/org.freedesktop.impl.portal.RemoteDesktop.xml index fb8844b0b..e66bacddb 100644 --- a/data/org.freedesktop.impl.portal.RemoteDesktop.xml +++ b/data/org.freedesktop.impl.portal.RemoteDesktop.xml @@ -39,6 +39,16 @@ org.freedesktop.portal.ScreenCast), but may only be started and stopped with this interface. + The following results get passed via the options argument: + + + pid t + + The process id of the process that is creating the session. + + + + The following results get returned via the #org.freedesktop.portal.Request::Response signal: diff --git a/src/remote-desktop.c b/src/remote-desktop.c index f450d6965..8c278164a 100644 --- a/src/remote-desktop.c +++ b/src/remote-desktop.c @@ -279,6 +279,8 @@ handle_create_session (XdpDbusRemoteDesktop *object, } g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add (&options_builder, "{sv}", + "pid", g_variant_new ("t", xdp_app_info_get_pid (request->app_info))); options = g_variant_builder_end (&options_builder); g_object_set_qdata_full (G_OBJECT (request), diff --git a/src/xdp-utils.c b/src/xdp-utils.c index f4280b344..252143a65 100644 --- a/src/xdp-utils.c +++ b/src/xdp-utils.c @@ -122,6 +122,7 @@ xdp_mkstempat (int dir_fd, struct _XdpAppInfo { volatile gint ref_count; char *id; + pid_t pid; XdpAppInfoKind kind; union @@ -141,11 +142,12 @@ struct _XdpAppInfo { }; static XdpAppInfo * -xdp_app_info_new (XdpAppInfoKind kind) +xdp_app_info_new (XdpAppInfoKind kind, pid_t pid) { XdpAppInfo *app_info = g_new0 (XdpAppInfo, 1); app_info->ref_count = 1; app_info->kind = kind; + app_info->pid = pid; return app_info; } @@ -224,7 +226,7 @@ set_appid_from_pid (XdpAppInfo *app_info, pid_t pid) static XdpAppInfo * xdp_app_info_new_host (pid_t pid) { - XdpAppInfo *app_info = xdp_app_info_new (XDP_APP_INFO_KIND_HOST); + XdpAppInfo *app_info = xdp_app_info_new (XDP_APP_INFO_KIND_HOST, pid); set_appid_from_pid (app_info, pid); return app_info; } @@ -278,6 +280,14 @@ xdp_app_info_get_id (XdpAppInfo *app_info) return app_info->id; } +pid_t +xdp_app_info_get_pid (XdpAppInfo *app_info) +{ + g_return_val_if_fail (app_info != NULL, NULL); + + return app_info->pid; +} + XdpAppInfoKind xdp_app_info_get_kind (XdpAppInfo *app_info) { @@ -673,7 +683,7 @@ parse_app_info_from_flatpak_info (int pid, GError **error) close (info_fd); - app_info = xdp_app_info_new (XDP_APP_INFO_KIND_FLATPAK); + app_info = xdp_app_info_new (XDP_APP_INFO_KIND_FLATPAK, pid); app_info->id = g_steal_pointer (&id); app_info->u.flatpak.keyfile = g_steal_pointer (&metadata); @@ -801,7 +811,7 @@ parse_app_info_from_snap (pid_t pid, GError **error) return NULL; } - app_info = xdp_app_info_new (XDP_APP_INFO_KIND_SNAP); + app_info = xdp_app_info_new (XDP_APP_INFO_KIND_SNAP, pid); app_info->id = g_strconcat ("snap.", snap_name, NULL); app_info->u.snap.keyfile = g_steal_pointer (&metadata); diff --git a/src/xdp-utils.h b/src/xdp-utils.h index f5c5fda62..cba53f628 100644 --- a/src/xdp-utils.h +++ b/src/xdp-utils.h @@ -75,6 +75,7 @@ G_DEFINE_AUTO_CLEANUP_FREE_FUNC(XdpFd, close, -1) XdpAppInfo *xdp_app_info_ref (XdpAppInfo *app_info); void xdp_app_info_unref (XdpAppInfo *app_info); const char *xdp_app_info_get_id (XdpAppInfo *app_info); +pid_t xdp_app_info_get_pid (XdpAppInfo *app_info); char * xdp_app_info_get_instance (XdpAppInfo *app_info); gboolean xdp_app_info_is_host (XdpAppInfo *app_info); XdpAppInfoKind xdp_app_info_get_kind (XdpAppInfo *app_info);