mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-24 08:29:34 -04:00
Automatically start and mount document portal in sandbox
This commit is contained in:
1 parent
4c4c66fc2d
commit
08d05a30a3
5 files changed
+51
-10
No files matched your search
@@ -154,7 +154,7 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError
|
||||
|
||||
xdg_app_context_allow_host_fs (app_context);
|
||||
|
||||
xdg_app_run_add_environment_args (argv_array, NULL, app_id,
|
||||
xdg_app_run_add_environment_args (argv_array, NULL, NULL, app_id,
|
||||
app_context, NULL);
|
||||
|
||||
g_ptr_array_add (argv_array, g_strdup ("-a"));
|
||||
|
||||
@@ -164,6 +164,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
||||
g_autofree char *runtime_ref = NULL;
|
||||
g_autofree char *app_ref = NULL;
|
||||
g_autofree char *path = NULL;
|
||||
g_autofree char *doc_mount_path = NULL;
|
||||
g_autoptr(GKeyFile) metakey = NULL;
|
||||
g_autoptr(GKeyFile) runtime_metakey = NULL;
|
||||
g_autoptr(GPtrArray) argv_array = NULL;
|
||||
@@ -178,6 +179,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
||||
int sync_proxy_pipes[2];
|
||||
g_autoptr(XdgAppContext) arg_context = NULL;
|
||||
g_autoptr(XdgAppContext) app_context = NULL;
|
||||
g_autoptr(GDBusConnection) session_bus = NULL;
|
||||
|
||||
context = g_option_context_new ("APP [args...] - Run an app");
|
||||
|
||||
@@ -300,7 +302,29 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
||||
else
|
||||
g_ptr_array_add (argv_array, g_strdup ("-r"));
|
||||
|
||||
xdg_app_run_add_environment_args (argv_array, dbus_proxy_argv,
|
||||
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
if (session_bus)
|
||||
{
|
||||
g_autoptr (GDBusMessage) reply = NULL;
|
||||
g_autoptr (GDBusMessage) msg = g_dbus_message_new_method_call ("org.freedesktop.portal.Documents",
|
||||
"/org/freedesktop/portal/documents",
|
||||
"org.freedesktop.portal.Documents",
|
||||
"GetMountPoint");
|
||||
g_dbus_message_set_body (msg, g_variant_new ("()"));
|
||||
reply = g_dbus_connection_send_message_with_reply_sync (session_bus, msg,
|
||||
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
|
||||
30000,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if (reply)
|
||||
{
|
||||
g_variant_get (g_dbus_message_get_body (reply),
|
||||
"(^ay)", &doc_mount_path);
|
||||
}
|
||||
}
|
||||
|
||||
xdg_app_run_add_environment_args (argv_array, dbus_proxy_argv, doc_mount_path,
|
||||
app, app_context, app_id_dir);
|
||||
|
||||
g_ptr_array_add (argv_array, g_strdup ("-b"));
|
||||
|
||||
@@ -388,13 +388,6 @@ on_name_acquired (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
if (!xdp_fuse_init (db, &error))
|
||||
{
|
||||
g_printerr ("fuse init failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -544,6 +537,12 @@ main (int argc,
|
||||
|
||||
introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (introspection_bytes, NULL), NULL);
|
||||
|
||||
if (!xdp_fuse_init (db, &error))
|
||||
{
|
||||
g_printerr ("fuse init failed: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
||||
"org.freedesktop.portal.Documents",
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
|
||||
+18
-1
@@ -1065,6 +1065,7 @@ xdg_app_add_bus_filters (GPtrArray *dbus_proxy_argv,
|
||||
void
|
||||
xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
||||
GPtrArray *dbus_proxy_argv,
|
||||
const char *doc_mount_path,
|
||||
const char *app_id,
|
||||
XdgAppContext *context,
|
||||
GFile *app_id_dir)
|
||||
@@ -1103,17 +1104,34 @@ xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
||||
g_debug ("Allowing host-fs access");
|
||||
opts[i++] = 'f';
|
||||
home_access = TRUE;
|
||||
|
||||
if (doc_mount_path)
|
||||
{
|
||||
g_ptr_array_add (argv_array, g_strdup ("-b"));
|
||||
g_ptr_array_add (argv_array, g_strdup_printf ("/run/user/%d/doc=%s", getuid(), doc_mount_path));
|
||||
}
|
||||
}
|
||||
else if (g_hash_table_lookup (context->filesystems, "home"))
|
||||
{
|
||||
g_debug ("Allowing homedir access");
|
||||
opts[i++] = 'H';
|
||||
home_access = TRUE;
|
||||
if (doc_mount_path)
|
||||
{
|
||||
g_ptr_array_add (argv_array, g_strdup ("-b"));
|
||||
g_ptr_array_add (argv_array, g_strdup_printf ("/run/user/%d/doc=%s/in-homedir", getuid(), doc_mount_path));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Enable persistant mapping only if no access to real home dir */
|
||||
|
||||
if (doc_mount_path && app_id)
|
||||
{
|
||||
g_ptr_array_add (argv_array, g_strdup ("-b"));
|
||||
g_ptr_array_add (argv_array, g_strdup_printf ("/run/user/%d/doc=%s/by-app/%s", getuid(), doc_mount_path, app_id));
|
||||
}
|
||||
|
||||
g_hash_table_iter_init (&iter, context->persistent);
|
||||
while (g_hash_table_iter_next (&iter, &key, NULL))
|
||||
{
|
||||
@@ -1126,7 +1144,6 @@ xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
||||
g_ptr_array_add (argv_array, g_strdup ("-B"));
|
||||
g_ptr_array_add (argv_array, g_strdup_printf ("%s=%s", dest, src));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
g_hash_table_iter_init (&iter, context->filesystems);
|
||||
|
||||
@@ -52,6 +52,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppContext, xdg_app_context_free)
|
||||
|
||||
void xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
||||
GPtrArray *dbus_proxy_argv,
|
||||
const char *doc_mount_path,
|
||||
const char *app_id,
|
||||
XdgAppContext *context,
|
||||
GFile *app_id_dir);
|
||||
|
||||
Reference in new issue
Block a user