diff options
| -rw-r--r-- | common/flatpak-run.c | 9 | ||||
| -rw-r--r-- | session-helper/flatpak-session-helper.c | 116 |
2 files changed, 90 insertions, 35 deletions
diff --git a/common/flatpak-run.c b/common/flatpak-run.c index 9880bbe6..3ec22011 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -1921,8 +1921,13 @@ add_monitor_path_args (gboolean use_session_helper, "--symlink", "/run/host/monitor/host.conf", "/etc/host.conf", "--symlink", "/run/host/monitor/hosts", "/etc/hosts", "--symlink", "/run/host/monitor/timezone", "/etc/timezone", - "--symlink", "/run/host/monitor/defaults", "/etc/glib-2.0/settings/defaults", - "--symlink", "/run/host/monitor/locks", "/etc/glib-2.0/settings/locks", + NULL); + + if (g_variant_lookup (session_data, "settings", "s", &monitor_path)) + flatpak_bwrap_add_args (bwrap, + "--ro-bind", monitor_path, "/run/host/settings", + "--symlink", "/run/host/settings/defaults", "/etc/glib-2.0/settings/defaults", + "--symlink", "/run/host/settings/locks", "/etc/glib-2.0/settings/locks", NULL); if (g_variant_lookup (session_data, "pkcs11-socket", "s", &pkcs11_socket_path)) diff --git a/session-helper/flatpak-session-helper.c b/session-helper/flatpak-session-helper.c index ade4509d..b54ef9c7 100644 --- a/session-helper/flatpak-session-helper.c +++ b/session-helper/flatpak-session-helper.c @@ -32,6 +32,7 @@ #include "flatpak-utils-private.h" static char *monitor_dir; +static char *app_dir; static char *p11_kit_server_socket_path; static int p11_kit_server_pid = 0; @@ -67,47 +68,63 @@ pid_data_free (PidData *data) } static void -add_to_keyfile (GKeyFile *keyfile, - DConfClient *client, - const char *dir) +add_key_to_keyfile (GKeyFile *keyfile, + DConfClient *client, + const char *key) +{ + g_autofree char *group = g_path_get_dirname (key); + g_autofree char *k = g_path_get_basename (key); + GVariant *value = dconf_client_read_full (client, key, DCONF_READ_DEFAULT_VALUE, NULL); + + if (value) + { + g_autofree char *val = g_variant_print (value, TRUE); + g_key_file_set_value (keyfile, group + 1, k, val); + } +} + +static void +add_dir_to_keyfile (GKeyFile *keyfile, + DConfClient *client, + const char *dir) { g_auto(GStrv) keys = NULL; int i; - g_autofree char *group = NULL; - - group = g_strdup (dir + 1); - group[strlen (group) - 1] = '\0'; keys = dconf_client_list (client, dir, NULL); for (i = 0; keys[i]; i++) { - if (dconf_is_rel_key (keys[i], NULL)) - { - g_autofree char *k = g_strconcat (dir, keys[i], NULL); - GVariant *value = dconf_client_read_full (client, k, DCONF_READ_DEFAULT_VALUE, NULL); + g_autofree char *k = g_strconcat (dir, keys[i], NULL); + if (dconf_is_dir (k, NULL)) + add_dir_to_keyfile (keyfile, client, k); + else if (dconf_is_key (k, NULL)) + add_key_to_keyfile (keyfile, client, k); + } +} - if (value) - { - g_autofree char *val = NULL; +static char * +path_for_app_id (const char *app_id) +{ + GString *s; + const char *p; - val = g_variant_print (value, TRUE); - g_key_file_set_value (keyfile, group, keys[i], val); - } - } - } + s = g_string_new (""); - for (i = 0; keys[i]; i++) + g_string_append_c (s, '/'); + for (p = app_id; *p; p++) { - if (dconf_is_rel_dir (keys[i], NULL)) - { - g_autofree char *d = g_strconcat (dir, keys[i], NULL); - add_to_keyfile (keyfile, client, d); - } + if (*p == '.') + g_string_append_c (s, '/'); + else + g_string_append_c (s, *p); } + g_string_append_c (s, '/'); + + return g_string_free (s, FALSE); } static void -update_dconf (void) +update_dconf (const char *app_id) { DConfClient *client = NULL; g_autoptr(GKeyFile) keyfile = NULL; @@ -115,13 +132,37 @@ update_dconf (void) g_autoptr(GError) error = NULL; g_auto(GStrv) locks = NULL; g_autofree char *contents = NULL; + g_autofree char *prefix = NULL; + g_autofree char *lc = NULL; + g_autofree char *dir = NULL; + int i; + + prefix = path_for_app_id (app_id); client = dconf_client_new (); keyfile = g_key_file_new (); - add_to_keyfile (keyfile, client, "/"); + add_dir_to_keyfile (keyfile, client, prefix); + + lc = g_ascii_strdown (prefix, -1); - path = g_build_filename (monitor_dir, "defaults", NULL); + if (strcmp (lc, prefix) != 0) + add_dir_to_keyfile (keyfile, client, lc); + + locks = dconf_client_list_locks (client, "/", NULL); + contents = g_strjoinv ("\n", locks); + + for (i = 0; locks[i]; i++) + add_key_to_keyfile (keyfile, client, locks[i]); + + dir = g_build_filename (app_dir, app_id, NULL); + if (g_mkdir_with_parents (dir, 0700) != 0) + { + g_warning ("Can't create %s\n", dir); + return; + } + + path = g_build_filename (dir, "defaults", NULL); if (!g_key_file_save_to_file (keyfile, path, &error)) { g_warning ("Failed to dump dconf database: %s", error->message); @@ -130,17 +171,15 @@ update_dconf (void) } g_clear_pointer (&path, g_free); - - locks = dconf_client_list_locks (client, "/", NULL); - contents = g_strjoinv ("\n", locks); - path = g_build_filename (monitor_dir, "locks", NULL); + path = g_build_filename (dir, "locks", NULL); if (!g_file_set_contents (path, contents, -1, &error)) { g_warning ("Failed to write %s: %s", path, error->message); g_object_unref (client); return; } + g_object_unref (client); } @@ -165,13 +204,14 @@ handle_request_session (FlatpakSessionHelper *object, GVariantBuilder builder; GVariant *parameters; const char *app_id; + g_autofree char *dir = NULL; parameters = g_dbus_method_invocation_get_parameters (invocation); g_variant_get (parameters, "(&s)", &app_id); g_debug ("Handling RequestSession for %s", app_id); - update_dconf (); + update_dconf (app_id); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); @@ -180,6 +220,9 @@ handle_request_session (FlatpakSessionHelper *object, if (p11_kit_server_socket_path) g_variant_builder_add (&builder, "{s@v}", "pkcs11-socket", g_variant_new_variant (g_variant_new_string (p11_kit_server_socket_path))); + dir = g_build_filename (app_dir, app_id, NULL); + g_variant_builder_add (&builder, "{s@v}", "settings", + g_variant_new_variant (g_variant_new_string (dir))); flatpak_session_helper_complete_request_session (object, invocation, g_variant_builder_end (&builder)); @@ -890,6 +933,13 @@ main (int argc, m_hosts = setup_file_monitor ("/etc/hosts"); m_localtime = setup_file_monitor ("/etc/localtime"); + app_dir = g_build_filename (flatpak_dir, "by-app", NULL); + if (g_mkdir_with_parents (app_dir, 0700) != 0) + { + g_print ("Can't create %s\n", app_dir); + exit (1); + } + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; |
